frameboard 0.38.0 → 0.39.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/dist/cli.js CHANGED
@@ -4,15 +4,15 @@ import childProcess, { execFile, spawn } from "node:child_process";
4
4
  import { EventEmitter, once } from "node:events";
5
5
  import * as sp from "node:path";
6
6
  import path, { basename, delimiter, dirname, extname, isAbsolute, join, relative, resolve as resolve$1, sep } from "node:path";
7
- import fs$1, { copyFileSync, createReadStream, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, watch as watch$1, writeFileSync } from "node:fs";
7
+ import fs$1, { constants, copyFileSync, createReadStream, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, watch as watch$1, writeFileSync } from "node:fs";
8
8
  import process$1, { versions } from "node:process";
9
9
  import { isDeepStrictEqual, promisify, stripVTControlCharacters } from "node:util";
10
- import { constants, copyFile, cp, link, lstat, mkdir, mkdtemp, open as open$1, readFile, readdir, readlink, realpath, rename, rm, rmdir, stat, utimes, writeFile } from "node:fs/promises";
10
+ import { constants as constants$1, copyFile, cp, link, lstat, mkdir, mkdtemp, open as open$1, readFile, readdir, readlink, realpath, rename, rm, rmdir, stat, utimes, writeFile } from "node:fs/promises";
11
11
  import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
12
12
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
13
13
  import { fileURLToPath, pathToFileURL } from "node:url";
14
14
  import { STATUS_CODES, ServerResponse, createServer } from "node:http";
15
- import { Http2ServerRequest, constants as constants$1 } from "node:http2";
15
+ import { Http2ServerRequest, constants as constants$2 } from "node:http2";
16
16
  import { Readable } from "node:stream";
17
17
  import { homedir, networkInterfaces, release as release$2, tmpdir, type } from "node:os";
18
18
  // \0rolldown/runtime.js
@@ -3059,7 +3059,9 @@ const EXIT_CODES = {
3059
3059
  "image-missing": 10,
3060
3060
  "motion-missing": 10,
3061
3061
  "motion-unbounded": 10,
3062
- "no-network-address": 3
3062
+ "no-network-address": 3,
3063
+ "kit-not-found": 3,
3064
+ "kit-invalid": 5
3063
3065
  };
3064
3066
  var FrameboardError = class extends Error {
3065
3067
  code;
@@ -3104,10 +3106,8 @@ const LOCK_POLL_MS = 25;
3104
3106
  const LOCK_SUFFIX = ".lock";
3105
3107
  const TEMP_SUFFIX = ".tmp";
3106
3108
  /**
3107
- * Reads and validates one record. The value returned is the parsed JSON itself
3108
- * rather than the schema's output, so key order and unknown keys survive a
3109
- * write back. Every schema here reads through `looseObject` with no defaults,
3110
- * so the two hold the same data.
3109
+ * Reads and validates one record, returning the parsed JSON rather than the
3110
+ * schema's output, so key order and unknown keys survive a write back.
3111
3111
  */
3112
3112
  async function readRecord(path, spec) {
3113
3113
  let text;
@@ -3208,12 +3208,8 @@ async function staleContent(lock) {
3208
3208
  return Number.isInteger(pid) && !isAlive(pid) ? text : null;
3209
3209
  }
3210
3210
  /**
3211
- * Breaks a stale lock under a guard, so one writer at a time re-reads the
3212
- * lock and retires it only while it still holds the content judged stale.
3213
- * Without the guard, a second breaker could rename aside the lock a first
3214
- * one had just taken, and put it back after its owner released it, leaving
3215
- * a lock nobody holds. A guard a crashed breaker left behind ages out like a
3216
- * lock. False while another breaker holds the guard, so the caller waits.
3211
+ * Breaks a stale lock under a guard, since a second breaker could otherwise
3212
+ * restore a lock its owner released, leaving one nobody holds.
3217
3213
  */
3218
3214
  async function breakLock(lock, judged) {
3219
3215
  const guard = `${lock.slice(0, -5)}.break${LOCK_SUFFIX}`;
@@ -9099,12 +9095,8 @@ const LAPTOP_BASE = {
9099
9095
  radius: 10
9100
9096
  };
9101
9097
  /**
9102
- * The phone's border is a current Pro's body less its display, 71.9 mm
9103
- * across holding 1206 pixels at 460 ppi, which is 16 points a side. The
9104
- * tablet's is a 13-inch Pro's, 215.5 mm across holding 2064 pixels at 264
9105
- * ppi, which is 44. The tablet's screen radius is a guess no source backs.
9106
- * The laptop's lid, chin, and base are scaled off the picked mock rather
9107
- * than any maker's, and its screen rounds its top corners alone.
9098
+ * Bezels measured off a current Pro phone and 13-inch tablet, the tablet's
9099
+ * screen radius a guess, and the laptop scaled off the picked mock.
9108
9100
  */
9109
9101
  const BEZELS = {
9110
9102
  phone: {
@@ -9192,13 +9184,8 @@ function baseReach(width) {
9192
9184
  return Math.round((width + 2 * BEZELS.laptop.border) * LAPTOP_BASE.reach);
9193
9185
  }
9194
9186
  /**
9195
- * The CSS `box-shadow` drawing a device's body: a spread the border wide
9196
- * around a box rounded to the screen radius, which also covers the frame's
9197
- * corners past that radius, so the body's outer radius is the screen's plus
9198
- * the border. On the board a hairline edge one screen pixel wide rings it at
9199
- * any zoom, so a dark body still reads on a dark canvas, under a drop shadow.
9200
- * The export keeps the body to the border, its last pixel the edge, and
9201
- * leaves out the drop shadow, which would fall past the PNG's edge.
9187
+ * The `box-shadow` drawing a device's body, with a hairline on the board so a
9188
+ * dark body reads on a dark canvas, and no drop shadow in an export.
9202
9189
  */
9203
9190
  function bezelShadow(device, { board = true } = {}) {
9204
9191
  const { border } = BEZELS[device];
@@ -9399,20 +9386,16 @@ function presetAt(width) {
9399
9386
  });
9400
9387
  }
9401
9388
  /**
9402
- * The viewport height a frame's content is read at, being the height of the
9403
- * preset whose range holds the width, or the desktop height below every
9404
- * range. Reading at the box's own height lets content sized off the viewport
9405
- * grow by that height on every fit.
9389
+ * The viewport height content is read at, never the box's own, which would let
9390
+ * viewport-sized content grow on every fit.
9406
9391
  */
9407
9392
  function referenceHeight(width) {
9408
9393
  return FRAME_SIZES[presetAt(width) ?? "desktop"].height;
9409
9394
  }
9410
9395
  // src/shared/frame-widths.ts
9411
9396
  /**
9412
- * A layout entry's `widths` value as a clean list. Anything but an array of
9413
- * objects each holding a positive integer `width` and `height`, with no width
9414
- * repeated, reads as none, so a value no reader understands never refuses the
9415
- * page's layout.
9397
+ * A layout entry's `widths` as a clean list, anything malformed reading as
9398
+ * none, so it never refuses the page's layout.
9416
9399
  */
9417
9400
  function widthsOf(value) {
9418
9401
  if (!Array.isArray(value)) return [];
@@ -9433,10 +9416,8 @@ function isSize(value) {
9433
9416
  return typeof value === "number" && Number.isInteger(value) && value >= 1;
9434
9417
  }
9435
9418
  /**
9436
- * Where each linked width draws: in a row at the frame's `y`, the first
9437
- * `FRAME_GAP` past the frame's right edge and each next one past the last.
9438
- * A laptop's base reaches past its lid below the screen, where a linked width
9439
- * taller than the frame would meet it, so the row moves out by that reach.
9419
+ * Where each linked width draws, in a row past the frame, moved out by a
9420
+ * laptop base's reach so a taller width never meets it.
9440
9421
  */
9441
9422
  function linkedBoxes(box, widths, device) {
9442
9423
  const boxes = [];
@@ -9472,12 +9453,23 @@ function drawnExtent(box, widths, device) {
9472
9453
  height: bottom - top
9473
9454
  };
9474
9455
  }
9456
+ /**
9457
+ * The x a frame of this width takes so its device body, or the frame itself
9458
+ * with none, stands the gap past an edge.
9459
+ */
9460
+ function xPast(edge, width, device) {
9461
+ const body = bezelBox({
9462
+ x: 0,
9463
+ y: 0,
9464
+ width,
9465
+ height: 0
9466
+ }, device);
9467
+ return edge + 80 - body.x;
9468
+ }
9475
9469
  // src/shared/present-transition.ts
9476
9470
  /**
9477
- * The transitions present mode draws between slides, in the order the
9478
- * inspector lists them. The list is the board's own. A project adds its
9479
- * own as stylesheets under `assets/transitions/`, each named by its stem,
9480
- * and a name in neither reads as no transition.
9471
+ * The board's own present transitions in inspector order, beside a project's
9472
+ * own under `assets/transitions/`.
9481
9473
  */
9482
9474
  const TRANSITIONS = [
9483
9475
  "none",
@@ -9536,10 +9528,8 @@ function isOwnTransitionName(name) {
9536
9528
  return name.length <= OWN_NAME_MAX_LENGTH && OWN_NAME_PATTERN.test(name) && name !== "page" && transitionNameOf(name) === null;
9537
9529
  }
9538
9530
  /**
9539
- * The name the board gives one of a project's keyframes in its own document.
9540
- * It carries the project, with every character outside letters, digits, and
9541
- * dashes spelled as its code, so two projects holding the same file never
9542
- * share a name. An own name holds no doubled dash, which keeps the pair apart.
9531
+ * A project keyframe's name in the board's document, carrying the project
9532
+ * escaped, so two projects holding the same file never share a name.
9543
9533
  */
9544
9534
  function ownKeyframesName(project, name, role) {
9545
9535
  return `fb-own-${project.replace(/[^A-Za-z0-9-]/g, (character) => `_${character.codePointAt(0)?.toString(16)}_`)}--${name}-${role}`;
@@ -9548,20 +9538,15 @@ function transitionNameOf(value) {
9548
9538
  return TRANSITIONS.find((name) => name === value) ?? null;
9549
9539
  }
9550
9540
  /**
9551
- * A stored transition as a reader takes it, or null for anything but an
9552
- * object naming a built-in transition or one of `own`, the names the
9553
- * project holds. A direction or a duration no reader understands reads as
9554
- * absent, so it falls to the default rather than hiding the transition, and
9555
- * so does a direction on a transition taking none of the project's own.
9541
+ * A stored transition as a reader takes it, an unknown direction or duration
9542
+ * falling to the default rather than hiding the transition.
9556
9543
  */
9557
9544
  function transitionOf(value, own = []) {
9558
9545
  return readTransition(value, (name) => own.includes(name));
9559
9546
  }
9560
9547
  /**
9561
- * A stored transition as a writer keeps it: `transitionOf`, counting any
9562
- * name shaped like a project's own whether or not its file is there. A
9563
- * layout write never drops an entry's transition because its file is
9564
- * missing or refused for now.
9548
+ * A stored transition as a writer keeps it, so a layout write never drops one
9549
+ * whose file is missing or refused for now.
9565
9550
  */
9566
9551
  function storedTransitionOf(value) {
9567
9552
  return readTransition(value, isOwnTransitionName);
@@ -9668,10 +9653,7 @@ const layoutFileSchema = looseObject({
9668
9653
  });
9669
9654
  // src/shared/sections.ts
9670
9655
  /**
9671
- * Each frame's section, by name, keyed by frame name. A frame belongs to the
9672
- * topmost section holding its center, the left and top edges inside and the
9673
- * right and bottom outside, so two sections sharing an edge never both claim
9674
- * it. Membership is read off geometry and never stored, so no frame writer
9656
+ * Each frame's section, read off geometry and never stored, so no frame writer
9675
9657
  * keeps a member list in step.
9676
9658
  */
9677
9659
  function membersOf(sections, frames) {
@@ -23914,12 +23896,8 @@ function withImports(sheet, imported) {
23914
23896
  return [...before, sheet];
23915
23897
  }
23916
23898
  /**
23917
- * Parses `css` past every break postcss refuses, so a rule reads every
23918
- * declaration a browser keeps. An unknown word, such as a declaration
23919
- * missing its colon, is blanked out to its `;` or `}`, as a browser drops
23920
- * that one declaration, with newlines kept so every offset holds. Any other
23921
- * break, such as an unclosed block or string, cuts the sheet there, and the
23922
- * cut's own leftovers are not breaks in the file, so none is recorded.
23899
+ * Parses `css` past every postcss break, blanking an unknown word as a browser
23900
+ * drops that declaration, offsets kept, and cutting the sheet at any other break.
23923
23901
  */
23924
23902
  function parseSheet$1(css) {
23925
23903
  let text = css;
@@ -24094,10 +24072,8 @@ function findingFor(docs) {
24094
24072
  };
24095
24073
  }
24096
24074
  /**
24097
- * `findings` without those of a rule `off` names, which a project's
24098
- * `checks.off` lists. Every path that reports a finding returns through it,
24099
- * so the board, `check`, and the hook agree on what is off. An id no rule
24100
- * declares matches no finding and drops nothing.
24075
+ * `findings` without the rules `checks.off` names, every reporting path
24076
+ * returning through it so the board, `check`, and the hook agree.
24101
24077
  */
24102
24078
  function withoutOff(findings, off) {
24103
24079
  if (!off || off.length === 0) return findings;
@@ -24118,18 +24094,12 @@ const TRANSITION_FILE_RULES = [{
24118
24094
  severity: "error",
24119
24095
  description: `A stylesheet under ${ASSETS_FOLDER}/${TRANSITIONS_FOLDER}/ is named in lowercase kebab case and holds @keyframes enter, optionally @keyframes leave, and nothing else, with no url(), quoted string, or escape. The board refuses a file breaking it whole, whether or not the rule is on`
24120
24096
  }];
24121
- const finding$13 = findingFor(TRANSITION_FILE_RULES);
24097
+ const finding$14 = findingFor(TRANSITION_FILE_RULES);
24122
24098
  /** A keyframe step: `from`, `to`, or a percentage, alone or in a comma list. */
24123
24099
  const STEP = /^(?:from|to|\d+(?:\.\d+)?%)(?:\s*,\s*(?:from|to|\d+(?:\.\d+)?%))*$/i;
24124
24100
  /**
24125
- * Reads one transition sheet named `name`, its file's stem. The board plays
24126
- * what this returns in its own document, so the sheet is refused whole on
24127
- * any stray rather than read past it: a name the board does not take, a
24128
- * break postcss refuses, anything at the top level but a comment and the
24129
- * `enter` and `leave` keyframes, anything in a keyframes block but steps of
24130
- * declarations, and a value that could load a file. A value loads one
24131
- * through `url()`, through a quoted string such as `image-set()` takes, or
24132
- * through an escape spelling either, so all three are refused.
24101
+ * Reads one transition sheet, refused whole on any stray, since the board plays
24102
+ * it in its own document, a value that could load a file included.
24133
24103
  */
24134
24104
  function readTransitionSheet(name, css) {
24135
24105
  if (!isOwnTransitionName(name)) return refused([{
@@ -24263,7 +24233,7 @@ function transitionPath(project, name) {
24263
24233
  function checkTransitionSheet({ project, name }, css) {
24264
24234
  const reading = readTransitionSheet(name, css);
24265
24235
  if (reading.ok) return [];
24266
- return reading.problems.map(({ message, location }) => finding$13("transition-file", {
24236
+ return reading.problems.map(({ message, location }) => finding$14("transition-file", {
24267
24237
  frame: null,
24268
24238
  path: transitionPath(project, name),
24269
24239
  message,
@@ -24271,11 +24241,8 @@ function checkTransitionSheet({ project, name }, css) {
24271
24241
  }));
24272
24242
  }
24273
24243
  /**
24274
- * Every stylesheet directly under a project's `assets/transitions/` by
24275
- * name, each named by its stem whether or not the board takes that name, so
24276
- * a misnamed file is reported rather than skipped. A dot-named file, a
24277
- * folder, a link, and a file of another type are no transition. A folder
24278
- * that does not exist lists none.
24244
+ * Every stylesheet in `assets/transitions/` by stem, a misnamed file listed so
24245
+ * it is reported rather than skipped.
24279
24246
  */
24280
24247
  async function transitionFiles(projectDir) {
24281
24248
  const folder = join(projectDir, ASSETS_FOLDER, TRANSITIONS_FOLDER);
@@ -24366,11 +24333,8 @@ async function listFrames(pageDir) {
24366
24333
  return (await readdir(pageDir, { withFileTypes: true })).filter((entry) => entry.isFile() && entry.name.endsWith(".html") && !entry.name.startsWith(".")).map((entry) => entry.name.slice(0, -5)).sort(byName);
24367
24334
  }
24368
24335
  /**
24369
- * The page order a reader shows: listed pages that exist in that order, then
24370
- * unlisted ones by name. A file that fails to read orders every page by name.
24371
- * The creation time, title, folder, archive flag, and turned-off rules come from the
24372
- * same read, each read as absent when the file holds none or holds one of
24373
- * another type.
24336
+ * The page order, listed pages first, then unlisted by name, all by name for
24337
+ * an unreadable file, each other key absent when of another type.
24374
24338
  */
24375
24339
  async function readPageOrder(projectDir) {
24376
24340
  const folders = await listPageFolders(projectDir);
@@ -24445,10 +24409,8 @@ function emptyProject() {
24445
24409
  };
24446
24410
  }
24447
24411
  /**
24448
- * Every frame's placement, placed ones from their entry and unplaced ones by
24449
- * `placeNext`. Entries with no frame file beside them are left out.
24450
- * `readTransition` reads an entry's override, a writer keeping any stored
24451
- * one and the scanner passing only those the project holds.
24412
+ * Every frame's placement, unplaced ones by `placeNext`, leaving out entries
24413
+ * with no frame file.
24452
24414
  */
24453
24415
  function placeFrames(frames, names, readTransition = storedTransitionOf) {
24454
24416
  const placements = /* @__PURE__ */ new Map();
@@ -24497,15 +24459,17 @@ function showsDevice(entry) {
24497
24459
  return entry?.showDevice === true || typeof entry?.device === "string";
24498
24460
  }
24499
24461
  /**
24500
- * Where a frame with no layout entry sits: desktop size at `y` 0, 80 past the
24501
- * right edge of every frame already placed and the linked widths it draws, on top of all of them. The board
24502
- * draws what the scanner returns, and `frame add` persists the same box for
24503
- * the first unplaced file, placing any other past the placed frames alone.
24462
+ * Where an unplaced frame sits, desktop size with its body 80 past the right
24463
+ * edge of every placed frame and its linked widths, the box `frame add`
24464
+ * persists. The body is the one the frame will draw, none for a bare file.
24504
24465
  */
24505
- function placeNext(placed) {
24466
+ function placeNext(placed, body = {
24467
+ width: FRAME_SIZES[DEFAULT_FRAME_SIZE].width,
24468
+ device: null
24469
+ }) {
24506
24470
  const right = Math.max(...placed.map(({ box, widths, device }) => {
24507
24471
  const extent = drawnExtent(box, widths, device);
24508
- return extent.x + extent.width + 80;
24472
+ return xPast(extent.x + extent.width, body.width, body.device);
24509
24473
  }), 0);
24510
24474
  const order = Math.max(...placed.map((placement) => placement.order + 1), 0);
24511
24475
  return {
@@ -24653,10 +24617,8 @@ function byName(a, b) {
24653
24617
  }
24654
24618
  // src/server/board/root.ts
24655
24619
  /**
24656
- * The board a verb acts on, as an absolute realpath. `--root` names it
24657
- * outright, marker or not. Otherwise the walk up from `cwd` takes the first
24658
- * folder holding `board.json` or `.frameboard/board.json`, and stops after
24659
- * the first folder holding `.git`.
24620
+ * The board a verb acts on, `--root` outright, else the first folder up from
24621
+ * `cwd` holding a board marker, stopping after the first holding `.git`.
24660
24622
  */
24661
24623
  async function resolveBoard({ root, cwd }) {
24662
24624
  if (root !== void 0) {
@@ -24676,10 +24638,8 @@ function findBoard(cwd) {
24676
24638
  }
24677
24639
  }
24678
24640
  /**
24679
- * The board `serve` shows, started when none exists: at `--root` when given,
24680
- * else the board the walk finds, else `.frameboard/` in `cwd`. A board folder holding no project gets one
24681
- * project with one empty page, and one missing only `board.json` gets that
24682
- * alone.
24641
+ * The board `serve` shows, started when none exists, else `.frameboard/` in
24642
+ * `cwd`, an empty board folder getting one project with one empty page.
24683
24643
  */
24684
24644
  async function startBoard({ root, cwd }, now = /* @__PURE__ */ new Date()) {
24685
24645
  const target = root === void 0 ? findBoard(cwd) ?? join(cwd, ".frameboard") : resolve$1(cwd, root);
@@ -24710,19 +24670,15 @@ async function isDirectory(path) {
24710
24670
  }
24711
24671
  }
24712
24672
  // package.json
24713
- var version$1 = "0.38.0";
24673
+ var version$1 = "0.39.0";
24714
24674
  var dependencies = { "playwright-core": "1.65.0" };
24715
24675
  var peerDependencies = { "oxfmt": "0.78.0" };
24716
24676
  // src/shared/version.ts
24717
24677
  const version = version$1;
24718
24678
  // src/cli/client-dir.ts
24719
24679
  /**
24720
- * The folder the board client is served from. A built run reads the `client`
24721
- * folder the build put beside the bundle and never looks further. A source run
24722
- * reads the repository's `dist/client`, which `bun run build` leaves, and
24723
- * writes nothing since the client changes with every branch. Either folder
24724
- * without an `index.html` refuses, so a broken package or an interrupted build
24725
- * never serves 404s. A folder given outright is held to the same test.
24680
+ * The client folder, refused without an `index.html`, so a broken package or
24681
+ * an interrupted build never serves 404s.
24726
24682
  */
24727
24683
  function resolveClientDir(moduleUrl = import.meta.url, given) {
24728
24684
  const built = !moduleUrl.endsWith(".ts");
@@ -24840,11 +24796,8 @@ function nextFreeName(base, taken) {
24840
24796
  }
24841
24797
  }
24842
24798
  /**
24843
- * The folder a project in `current` lands in once titled `title`: the name
24844
- * made from the title, the next free one when another of `taken` holds it,
24845
- * and `current` itself when the title names no folder or names the one it
24846
- * is in. A taken name near the length limit is cut back until a free one
24847
- * fits, its suffix included, so the folder always stays a valid name.
24799
+ * The folder a retitled project lands in, cut back near the length limit so
24800
+ * the folder always stays a valid name.
24848
24801
  */
24849
24802
  function titledFolder(current, title, taken) {
24850
24803
  const folder = folderName(title);
@@ -24996,10 +24949,8 @@ function setOf(current) {
24996
24949
  };
24997
24950
  }
24998
24951
  /**
24999
- * Reserves every frame named as one set, each a claim carrying its box and
25000
- * the set's id, in one write. A frame another session holds live refuses
25001
- * `frame-claimed` before any is written, and the session's own claim on a
25002
- * named frame is replaced.
24952
+ * Reserves the frames as one set in one write, refusing all on another live
24953
+ * session's claim and replacing the session's own.
25003
24954
  */
25004
24955
  async function reserve(root, holder, reservations, now) {
25005
24956
  await ensureRunFolder(root);
@@ -25191,13 +25142,9 @@ async function framePathParts(root, ref, cwd) {
25191
25142
  }
25192
25143
  // src/server/board/frames.ts
25193
25144
  /**
25194
- * Places a frame on its page, writing a skeleton file only when none exists.
25195
- * A file with no entry keeps its bytes and lands 80 past the placed frames,
25196
- * as `placeNext` puts it, ignoring the page's other unplaced files, unless a
25197
- * size or position is given. Every axis no size names hugs its
25198
- * content, a preset fixing the width alone, and the box stands in until the
25199
- * server measures. A scroll frame hugs neither axis, and with no height named
25200
- * takes the reference height of its width.
25145
+ * Places a frame, writing a skeleton only when no file exists. Every axis no
25146
+ * size names hugs, the box standing in until the server measures, and a scroll
25147
+ * frame hugs neither axis.
25201
25148
  */
25202
25149
  async function addFrame(root, ref, options) {
25203
25150
  const { journal } = options;
@@ -25226,10 +25173,13 @@ async function addFrame(root, ref, options) {
25226
25173
  if (exists && layout.hasEntry(frame.name)) throw new FrameboardError("name-taken", `${frame.project}/${frame.page}/${frame.name} is already a placed frame.`, { ref: refOf$1(frame) });
25227
25174
  if (exists && options.body !== void 0) throw new FrameboardError("name-taken", `${frame.project}/${frame.page}/${frame.name} already has a file, so nothing was written into it.`, { ref: refOf$1(frame) });
25228
25175
  const names = exists ? layout.names : [...layout.names, frame.name].sort();
25229
- const slot = names.filter((name) => name === frame.name || layout.hasEntry(name));
25230
- const computed = placeFrames(layout.file.frames, slot).get(frame.name);
25231
- if (!computed) throw new Error(`No placement computed for ${frame.name}.`);
25232
- const width = size.width ?? computed.box.width;
25176
+ const placed = placeFrames(layout.file.frames, names.filter((name) => layout.hasEntry(name)));
25177
+ const stale = placed.get(frame.name);
25178
+ const width = size.width ?? stale?.box.width ?? FRAME_SIZES["desktop"].width;
25179
+ const computed = stale ?? placeNext([...placed.values()], {
25180
+ width,
25181
+ device: options.showDevice ? deviceForWidth(width) : null
25182
+ });
25233
25183
  const widths = linkedWidths(refOf$1(frame), options.widths, {
25234
25184
  width,
25235
25185
  hugWidth: hugs.hugWidth,
@@ -25259,10 +25209,8 @@ async function addFrame(root, ref, options) {
25259
25209
  return frameRecord(root, frame.project, frame.page, frame.name);
25260
25210
  }
25261
25211
  /**
25262
- * Copies the frame's file byte for byte, into its own page beside the source
25263
- * or into `--to` at the source's box, on top of the target page. An `offset`
25264
- * places the copy that far from the source's box instead, as an Alt-drag
25265
- * drops it.
25212
+ * Copies the frame byte for byte beside its source or into `--to`, an `offset`
25213
+ * placing it that far away, as an Alt-drag drops it.
25266
25214
  */
25267
25215
  async function duplicateFrame(root, ref, { to, name, offset, journal, ...options }) {
25268
25216
  const source = await resolveFrameRef(root, ref, options);
@@ -25283,7 +25231,7 @@ async function duplicateFrame(root, ref, { to, name, offset, journal, ...options
25283
25231
  x: pastExtent(placement)
25284
25232
  } : placement.box;
25285
25233
  const copyPath = join(into, `${copyName}${FRAME_EXTENSION}`);
25286
- await copyFile(source.path, copyPath, constants.COPYFILE_EXCL);
25234
+ await copyFile(source.path, copyPath, constants$1.COPYFILE_EXCL);
25287
25235
  await journal?.created(copyPath);
25288
25236
  targetLayout.names = [...targetLayout.names, copyName].sort();
25289
25237
  targetLayout.set(copyName, {
@@ -25354,10 +25302,8 @@ async function renameFrame(root, ref, newName, options) {
25354
25302
  });
25355
25303
  }
25356
25304
  /**
25357
- * Sets the size each option names and fixes those axes. `scroll` on fixes
25358
- * both, dropping a hugging height no option names to the reference height of
25359
- * the width, since a frame kept at its content's full height has nothing to
25360
- * scroll. `scroll` off clears the key and keeps the box as it stands.
25305
+ * Fixes the axes the options size. `scroll` drops a hugging height to the
25306
+ * width's reference height, since a full-height frame has nothing to scroll.
25361
25307
  */
25362
25308
  async function resizeFrame(root, ref, options) {
25363
25309
  const size = sizeOf(options);
@@ -25365,11 +25311,8 @@ async function resizeFrame(root, ref, options) {
25365
25311
  return updatePlacement(root, ref, options, (placement, frameRef) => resizedPlacement(placement, frameRef, size, options));
25366
25312
  }
25367
25313
  /**
25368
- * Sets the whole list of widths each frame also shows at, every frame in one
25369
- * write under one lock. A frame whose stored list differs from its `expected`
25370
- * refuses `stale-layout` before any frame is written, so a list an agent
25371
- * changed since the caller drew it is never overwritten. The list itself is
25372
- * refused as `resizeFrame --widths` refuses it.
25314
+ * Sets each frame's whole width list in one write, refusing `stale-layout`
25315
+ * before any write when a stored list moved off its `expected`.
25373
25316
  */
25374
25317
  async function setLinkedWidths(root, targets, widths, options) {
25375
25318
  const frames = await Promise.all(targets.map(async (target) => ({
@@ -25425,10 +25368,8 @@ function resizedPlacement(placement, frameRef, size, options) {
25425
25368
  };
25426
25369
  }
25427
25370
  /**
25428
- * The linked widths a verb writes, keeping the height each one already held
25429
- * and giving a new one the reference height of its width, which a hugging
25430
- * frame's measure replaces. A repeated width, the frame's own width, or a
25431
- * frame hugging its width refuses `usage`.
25371
+ * The linked widths a verb writes, a new one taking its reference height until
25372
+ * measured, refusing a repeat, the own width, or a width-hugging frame.
25432
25373
  */
25433
25374
  function linkedWidths(ref, requested, { width, hugWidth, held }) {
25434
25375
  if (!requested || requested.length === 0) return [];
@@ -25451,16 +25392,14 @@ function linkedWidths(ref, requested, { width, hugWidth, held }) {
25451
25392
  height: held.find((each) => each.width === linked)?.height ?? referenceHeight(linked)
25452
25393
  }));
25453
25394
  }
25454
- /** The x a copy placed beside a frame takes, past its device and the row of linked widths it draws. */
25395
+ /** The x a copy placed beside a frame takes, its own body clear of the frame's device and linked widths. */
25455
25396
  function pastExtent({ box, widths, device }) {
25456
25397
  const extent = drawnExtent(box, widths, device);
25457
- return extent.x + extent.width + 80;
25398
+ return xPast(extent.x + extent.width, box.width, device);
25458
25399
  }
25459
25400
  /**
25460
- * Sets a frame's height to its content's measured height and turns hugging
25461
- * back on for that axis, the inverse of the resize that fixed it, writing
25462
- * each linked width's measured height beside it while the entry lists it. A
25463
- * scroll frame refuses `fit-scroll`, since its height is fixed on purpose.
25401
+ * Sets the measured height and hugs it, the inverse of a fixing resize, and
25402
+ * refuses `fit-scroll` on a scroll frame, whose height is fixed on purpose.
25464
25403
  */
25465
25404
  async function fitHeight(root, ref, height, options) {
25466
25405
  return updatePlacement(root, ref, options, (placement) => {
@@ -25484,14 +25423,9 @@ function fittedPlacement(placement, height, widths) {
25484
25423
  };
25485
25424
  }
25486
25425
  /**
25487
- * Sets how each frame holds its height in one write under one lock, all of
25488
- * them or none. `fixed` keeps the box and clears hugging and scroll. `fit`
25489
- * takes the measured height and hugs it, clearing scroll. `scroll` fixes both
25490
- * axes as `frame resize --scroll` does, at the target's `height` when it
25491
- * gives one. Every frame is checked before any is
25492
- * set: one moved or sized since its `expected` refuses `stale-layout`, leaving
25493
- * out an axis the frame hugs, since the server measures that one, and a `fit`
25494
- * without `measured` refuses `usage`.
25426
+ * Sets each frame's height mode in one write, all or none. Every frame is
25427
+ * checked first against its `expected`, leaving out a hugged axis, since the
25428
+ * server measures that one.
25495
25429
  */
25496
25430
  async function setHeightModes(root, targets, mode, options) {
25497
25431
  const frames = await Promise.all(targets.map(async (target) => ({
@@ -25540,10 +25474,8 @@ function fitScrollError(ref) {
25540
25474
  return new FrameboardError("fit-scroll", `${ref} holds scroll, which fixes its height so the page scrolls past it, so it has no height to fit. Clear it with frame resize --no-scroll first.`, { ref });
25541
25475
  }
25542
25476
  /**
25543
- * Writes the sizes the server measured, on the axes each frame's stored entry
25544
- * hugs and nowhere else, under the page's lock. It sets no flag and takes no
25545
- * journal, since the developer never set that size, and answers the names
25546
- * whose entry changed, none when every size already stands.
25477
+ * Writes measured sizes on hugged axes alone, with no flag and no journal,
25478
+ * since the developer never set them.
25547
25479
  */
25548
25480
  async function setMeasured(root, pageRef, sizes, options) {
25549
25481
  const page = await resolvePageRef(root, pageRef, options);
@@ -25574,12 +25506,8 @@ async function setMeasured(root, pageRef, sizes, options) {
25574
25506
  });
25575
25507
  }
25576
25508
  /**
25577
- * Sets the boxes of several frames on one page under one lock and one write,
25578
- * the one path a hand move or resize takes. `expected` holds the boxes the
25579
- * client started from, and a frame whose stored box differs from it refuses
25580
- * the whole write, so a hand edit never silently undoes an agent's. A section
25581
- * move carries its box in `sections` beside its members' boxes, so the box
25582
- * and the frames move as one step or not at all.
25509
+ * Sets frame boxes in one write, the hand path. A box moved off its `expected`
25510
+ * refuses the whole write, so a hand edit never silently undoes an agent's.
25583
25511
  */
25584
25512
  async function setBoxes(root, pageRef, boxes, expected, options) {
25585
25513
  const page = await resolvePageRef(root, pageRef, options);
@@ -25709,10 +25637,8 @@ async function setFrameDevice(root, ref, show, options) {
25709
25637
  });
25710
25638
  }
25711
25639
  /**
25712
- * Sets the transition a frame arrives with in present mode, over its page's,
25713
- * or clears it with null so the frame takes its page's. The frame's file and
25714
- * box are left as they stand. A name that is neither built in nor the
25715
- * project's own refuses `usage` and writes nothing.
25640
+ * Sets or clears a frame's present transition, refusing a name neither built
25641
+ * in nor the project's own.
25716
25642
  */
25717
25643
  async function setFrameTransition(root, ref, transition, options) {
25718
25644
  const frame = await resolveFrameRef(root, ref, options);
@@ -25769,9 +25695,7 @@ function sizeOf({ size, width, height }) {
25769
25695
  }
25770
25696
  /**
25771
25697
  * The skeleton states `head` with `body`, so the browser builds neither and
25772
- * every element address in the file holds. A `body` markup is written edge to
25773
- * edge, in a column with no margin, so no line box adds a gap under a media
25774
- * element and the content is exactly the markup's size.
25698
+ * every address holds, and a body column has no margin, so media fits exactly.
25775
25699
  */
25776
25700
  function skeleton(name, body) {
25777
25701
  return `<!doctype html>
@@ -25813,14 +25737,8 @@ var PageLayout = class {
25813
25737
  return Math.max(...this.names.map((name) => this.placement(name).order + 1), 0);
25814
25738
  }
25815
25739
  /**
25816
- * Writes the seven fixed keys on the entry it creates or changes, after any
25817
- * key the entry already held, so unknown keys survive in place. A hug flag
25818
- * is written once it is on or when the entry holds it, so an entry from
25819
- * before the flags gains no key, and a scroll entry writes both hug flags
25820
- * false, since it fixes both axes. `scroll` follows the same rule. `widths`,
25821
- * `showDevice`, and `transition` are written while the frame holds one and
25822
- * removed once cleared, leaving a held value no reader understands as is.
25823
- * A `device` name from before `showDevice` is replaced by it on any write.
25740
+ * Writes the fixed keys after the entry's own, so unknown keys survive, and a
25741
+ * flag only once on or already held, so an older entry gains no key.
25824
25742
  */
25825
25743
  set(name, { box, order, hidden, locked, scroll, widths, showDevice, transition, hugWidth: hugsWidth, hugHeight: hugsHeight }) {
25826
25744
  const hugWidth = hugsWidth && !scroll;
@@ -25910,10 +25828,8 @@ var PageLayout = class {
25910
25828
  }
25911
25829
  };
25912
25830
  /**
25913
- * Runs one frame change under the lock of every page it touches, taken in
25914
- * path order. Every layout is read and validated before `run` moves a file,
25915
- * and only the layouts it changed are written, reporting each entry that
25916
- * differs to the journal.
25831
+ * Runs one frame change under every touched page's lock in path order,
25832
+ * validating every layout before `run` moves a file.
25917
25833
  */
25918
25834
  async function withLayouts(pages, run, journal) {
25919
25835
  const unique = [...new Set(pages)];
@@ -26795,7 +26711,7 @@ const drainIncoming = (incoming) => {
26795
26711
  incomingWithDrainState[incomingDraining] = true;
26796
26712
  if (incoming instanceof Http2ServerRequest) {
26797
26713
  try {
26798
- incoming.stream?.close?.(constants$1.NGHTTP2_NO_ERROR);
26714
+ incoming.stream?.close?.(constants$2.NGHTTP2_NO_ERROR);
26799
26715
  } catch {}
26800
26716
  return;
26801
26717
  }
@@ -29545,10 +29461,8 @@ const setCookie = (c, name, value, opt) => {
29545
29461
  };
29546
29462
  // src/server/access/guard.ts
29547
29463
  /**
29548
- * True for the address token as a bearer, or for the board's cookie carrying
29549
- * the key when `Origin` names the board itself. Cookies and SameSite both
29550
- * ignore the port, so the cookie alone would let a page on another local port
29551
- * write, and a request with no `Origin` is refused rather than trusted.
29464
+ * True for the token as a bearer, or for the key cookie with the board's own
29465
+ * `Origin`, since cookies ignore the port and another local port would write.
29552
29466
  */
29553
29467
  function isWriter(headers, access) {
29554
29468
  const bearer = /^Bearer (.+)$/.exec(headers.authorization ?? "")?.[1];
@@ -29597,15 +29511,8 @@ function matches$1(given, expected) {
29597
29511
  // src/server/routes/access.ts
29598
29512
  const COOKIE_MAX_AGE_S = 3456e4;
29599
29513
  /**
29600
- * How a tab becomes a writer. A redeem URL carries a single-use ticket that
29601
- * trades for the board's cookie, and answers a 303 home either way so a used
29602
- * ticket still lands on a board that reads. A failed redeem lands on
29603
- * `/?link=expired`, the flag the client's expired-link toast reads.
29604
- *
29605
- * With `openRoute`, `GET /api/access/open` mints a ticket per request and
29606
- * redirects through redeem, so a browser with no shell, such as a recorder's,
29607
- * lands on a writing board. It is off unless `serve` is asked for it, since it
29608
- * makes any local browser navigating to it a writer.
29514
+ * How a tab becomes a writer, a used ticket still landing on a reading board.
29515
+ * `openRoute` stays off unless asked, since it makes any local browser a writer.
29609
29516
  */
29610
29517
  function accessRoutes(access, tickets, { openRoute = false } = {}) {
29611
29518
  const app = new Hono();
@@ -29734,11 +29641,8 @@ function hasTag(node) {
29734
29641
  return "tagName" in node;
29735
29642
  }
29736
29643
  /**
29737
- * Parses a frame the way the browser builds it, with source offsets into the
29738
- * given string. A browser's decoder drops a leading BOM before the tokenizer,
29739
- * while parse5 would read it as text and imply the wrappers, stripping the
29740
- * file's own of their locations. A space is ignored the same way and keeps
29741
- * every offset.
29644
+ * Parses a frame as the browser builds it, a leading BOM read as a space,
29645
+ * since parse5 would imply wrappers where the browser drops it.
29742
29646
  */
29743
29647
  function parseFrame(source) {
29744
29648
  const document = parse$3(source.replace(/^\uFEFF/, " "), { sourceCodeLocationInfo: true });
@@ -29761,10 +29665,8 @@ function parseFrame(source) {
29761
29665
  /** Past this many changed elements, one glow over the frame reads better than many. */
29762
29666
  const MOST_ELEMENTS = 8;
29763
29667
  /**
29764
- * Which elements of `after` an agent changed against `before`, matching both
29765
- * in index order by tag, attributes, and own text with a longest common
29766
- * subsequence. An unmatched element inside another unmatched one is left out,
29767
- * so an inserted card glows once and not with each child.
29668
+ * The elements an agent changed, matched by a longest common subsequence,
29669
+ * leaving out an unmatched child of an unmatched parent so a card glows once.
29768
29670
  */
29769
29671
  function changedElements(before, after) {
29770
29672
  const old = parseFrame(before);
@@ -29870,11 +29772,8 @@ function changesFolder(root) {
29870
29772
  return join(root, RUN_FOLDER, "changes");
29871
29773
  }
29872
29774
  /**
29873
- * The log a previous server saved, its newest `cap` changes kept. A missing
29874
- * file, a parse failure, or a shape this build does not know reads as an
29875
- * empty log, since a newer or older build may have written it and a start
29876
- * never refuses over it. A version file that is gone leaves its change in
29877
- * the log with nothing to compare against.
29775
+ * The saved log's newest `cap` changes, any unreadable shape reading as empty,
29776
+ * since another build may have written it and a start never refuses over it.
29878
29777
  */
29879
29778
  async function loadChanges(root, cap) {
29880
29779
  const folder = changesFolder(root);
@@ -29938,11 +29837,8 @@ function versionPath(folder, hash) {
29938
29837
  */
29939
29838
  const DEPARTED_BATCHES = 4;
29940
29839
  /**
29941
- * Tells an agent's frame writes from the board's own. It holds each frame's
29942
- * source by ref, so a batch whose file matches what it holds is a write the
29943
- * history already told it of, or no write at all, and one that differs is an
29944
- * agent's, diffed against the source it held. Every caller runs in the
29945
- * server's scan turn, since `own` and a batch reading one frame would race.
29840
+ * Tells an agent's writes from the board's own by each frame's held source.
29841
+ * Every caller runs in the scan turn, since `own` and a batch would race.
29946
29842
  */
29947
29843
  function createChangeTracker(root, { now = () => /* @__PURE__ */ new Date(), logCap = 200 } = {}) {
29948
29844
  const held = /* @__PURE__ */ new Map();
@@ -30127,11 +30023,8 @@ function framesNamed(root, paths) {
30127
30023
  }
30128
30024
  // src/server/claims/gate.ts
30129
30025
  /**
30130
- * Refuses `frame-claimed` when another session holds a frame the hand write
30131
- * would change. Each ref is a frame, page, or project ref, and a page or
30132
- * project ref matches every claim under it. The claims are read without the
30133
- * lock, so a claim landing between this read and the write lets that one
30134
- * write through, where the file hash still guards the agent's own write.
30026
+ * Refuses `frame-claimed` for a frame another session holds, read without the
30027
+ * lock, since the file hash still guards an agent's write that lands between.
30135
30028
  */
30136
30029
  async function refuseClaimed(root, refs, now) {
30137
30030
  if (refs.length === 0) return;
@@ -30151,7 +30044,7 @@ const THEME_RULES = [{
30151
30044
  severity: "error",
30152
30045
  description: "A frame setting literal colors defines the other theme too, through a [data-theme] selector, a prefers-color-scheme query, or light-dark()"
30153
30046
  }];
30154
- const finding$12 = findingFor(THEME_RULES);
30047
+ const finding$13 = findingFor(THEME_RULES);
30155
30048
  const COLOR_PROPERTIES$2 = /^(color|background(-color|-image)?|border(-(top|right|bottom|left|block|inline)(-(start|end))?)?(-color)?|outline(-color)?|fill|stroke|box-shadow|text-shadow|caret-color|accent-color|text-decoration(-color)?|column-rule(-color)?)$/i;
30156
30049
  const COLOR_FUNCTION = /\b(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\(/i;
30157
30050
  const HEX_COLOR = /#[0-9a-f]{3,8}\b/i;
@@ -30161,7 +30054,7 @@ function checkTheme(source) {
30161
30054
  const { firstColor, bothThemes } = readThemeColors(source);
30162
30055
  if (!firstColor || bothThemes) return [];
30163
30056
  const { path, location } = firstColor;
30164
- return [finding$12("theme", {
30057
+ return [finding$13("theme", {
30165
30058
  frame: source.ref,
30166
30059
  path,
30167
30060
  message: "The frame sets its own colors for one theme alone. Define the other through [data-theme] or prefers-color-scheme, or take the colors from token variables.",
@@ -30307,13 +30200,8 @@ const LIGHT_SELECTORS = /* @__PURE__ */ new Set([
30307
30200
  ]);
30308
30201
  const BASE_SELECTOR = ":root";
30309
30202
  /**
30310
- * Reads a project's token sheets into one row per custom property, with its
30311
- * light and dark values after the project sheet overrides the board's. A
30312
- * declaration under a dark selector or a dark `prefers-color-scheme` query is
30313
- * dark, one under a light selector is light, and one under plain `:root`
30314
- * fills whichever side its sheet sets no value for. A property set under no
30315
- * recognized selector is left out. A sheet that does not parse is named with
30316
- * its error and adds no rows.
30203
+ * One row per custom property with light and dark values after overrides, a
30204
+ * plain `:root` filling whichever side its sheet leaves unset.
30317
30205
  */
30318
30206
  function readTokenTable(root, paths) {
30319
30207
  const sheets = [];
@@ -30760,11 +30648,8 @@ async function walk(folder, prefix, real, into) {
30760
30648
  }
30761
30649
  }
30762
30650
  /**
30763
- * The kind of the file at `path` under a project's `assets/`, when a frame
30764
- * can show it, confined as `listAssets` is: a path naming a dot-named
30765
- * segment, a `..`, or any file whose real path leaves the folder is
30766
- * `asset-missing`, as is one that is not there. A file that is there but is
30767
- * no image, GIF, SVG, video, or audio is `asset-not-placeable`.
30651
+ * A placeable asset's kind, confined as `listAssets` is, so a path leaving the
30652
+ * folder reads `asset-missing` and an unshowable file `asset-not-placeable`.
30768
30653
  */
30769
30654
  async function resolveAsset(projectDir, path) {
30770
30655
  const missing = {
@@ -30798,11 +30683,8 @@ function isScratch(name) {
30798
30683
  return name.endsWith(".lock") || name.endsWith(".tmp");
30799
30684
  }
30800
30685
  /**
30801
- * Writes each upload to the top level of `assets/` under the first free name,
30802
- * creating the folder on a first drop. A file whose extension is not accepted
30803
- * is refused by name and the rest still land. The bytes go to a temp file and
30804
- * are hard-linked to the target, so a name an agent took in between is never
30805
- * overwritten and the next name is tried.
30686
+ * Writes each upload under the first free name, hard-linking a temp file so a
30687
+ * name an agent took in between is never overwritten.
30806
30688
  */
30807
30689
  async function addAssets(projectDir, uploads) {
30808
30690
  const folder = join(projectDir, ASSETS_FOLDER);
@@ -30854,10 +30736,8 @@ async function takenStems(folder, extension) {
30854
30736
  return (await readdir(folder)).filter((name) => name.toLowerCase().endsWith(suffix)).map((name) => name.slice(0, -suffix.length));
30855
30737
  }
30856
30738
  /**
30857
- * The board's name rule applied to a dropped name: runs of other characters
30858
- * become `-`, a leading dot, dash, or underscore is dropped, and a stem that
30859
- * empties out becomes `file`. The extension is lowercased and the whole name
30860
- * kept within the name cap.
30739
+ * The board's name rule for a dropped name, an emptied stem becoming `file`
30740
+ * and the whole name kept within the cap.
30861
30741
  */
30862
30742
  function splitName(name) {
30863
30743
  const extension = extensionOf(name);
@@ -30871,10 +30751,8 @@ function splitName(name) {
30871
30751
  /** The most a drop may carry, multipart overhead included. */
30872
30752
  const ASSET_BODY_LIMIT = 67108864;
30873
30753
  /**
30874
- * A project's `assets/` folder over the board's JSON envelope: the listing the
30875
- * Assets tab draws, the drop that writes into it, and the keyframes of the
30876
- * project's own transitions. The drop needs a writer and is held in memory,
30877
- * so the body limit is its only bound. Both reads answer any caller.
30754
+ * A project's `assets/` routes, the drop held in memory, so the body limit is
30755
+ * its only bound.
30878
30756
  */
30879
30757
  function assetsRoutes(root, access, { limit = ASSET_BODY_LIMIT, usage } = {}) {
30880
30758
  const app = new Hono();
@@ -30892,10 +30770,6 @@ function assetsRoutes(root, access, { limit = ASSET_BODY_LIMIT, usage } = {}) {
30892
30770
  })) : files }
30893
30771
  });
30894
30772
  });
30895
- /**
30896
- * The keyframes present mode may play for the project's own transitions.
30897
- * It answers what the reader kept, renamed, and never a file's own bytes.
30898
- */
30899
30773
  app.get("/api/projects/:project/transitions", async (c) => {
30900
30774
  const project = c.req.param("project");
30901
30775
  const projectDir = projectFolder(root, project);
@@ -30956,12 +30830,8 @@ function notFound$1(project) {
30956
30830
  // src/server/routes/checks.ts
30957
30831
  const bodySchema = object$1({ refs: array$1(string$1().min(1).max(1024)).max(1e5) });
30958
30832
  /**
30959
- * `POST /api/checks` with `{ refs }`, behind `requireWriter`, which `check`
30960
- * calls for the browser findings a static run cannot reach. It rescans the
30961
- * board, waits until no recheck of those frames is pending, then answers the
30962
- * change and browser findings the server holds for them. A warm browser that
30963
- * does not launch answers `browser.ran: false` with `browser-not-found` and
30964
- * the change findings alone.
30833
+ * `POST /api/checks`, which `check` calls for the browser findings a static run
30834
+ * cannot reach, answering once no recheck of the frames is pending.
30965
30835
  */
30966
30836
  function checkRoutes(access, checks) {
30967
30837
  const app = new Hono();
@@ -31045,11 +30915,8 @@ async function parseBody$1(request, schema) {
31045
30915
  // src/server/routes/claims.ts
31046
30916
  const ReleaseBody = object$1({ frame: string$1().min(1) });
31047
30917
  /**
31048
- * `POST /api/claims/release` with `{ frame }`, the canonical ref a claim
31049
- * names, dropping the live reservation on that frame whichever session holds
31050
- * it. It sits behind `requireWriter`, and a frame holding no reservation,
31051
- * including one an agent holds an editing claim on, refuses
31052
- * `frame-not-found` and is left as it was.
30918
+ * `POST /api/claims/release`, dropping a frame's reservation whichever session
30919
+ * holds it, and never an editing claim.
31053
30920
  */
31054
30921
  function claimsRoutes(root, access) {
31055
30922
  const app = new Hono();
@@ -31072,12 +30939,8 @@ const CLIP_FOLDER = "frameboard-clip";
31072
30939
  /** Characters a Windows file name cannot hold. */
31073
30940
  const WINDOWS_RESERVED = /[<>:"/\\|?*]/g;
31074
30941
  /**
31075
- * The Windows clipboard reached from WSL. The images land in Windows' temp
31076
- * folder, since a file drop list names Windows paths and a pasting app reads
31077
- * the files after the copy returns. Each copy clears the last one's folder,
31078
- * the only time a pasted list is known to be done with. Copies run one at a
31079
- * time, since a copy clearing the folder while another is still setting the
31080
- * clipboard deletes the files that copy is about to name.
30942
+ * The Windows clipboard from WSL, images in Windows' temp folder, which each
30943
+ * copy clears, so copies run one at a time to keep a pending copy's files.
31081
30944
  */
31082
30945
  function wslClipboard(run) {
31083
30946
  let previous = Promise.resolve();
@@ -31176,12 +31039,8 @@ const CopyBody = object$1({
31176
31039
  themes: record(string$1(), _enum$1(["light", "dark"])).optional()
31177
31040
  });
31178
31041
  /**
31179
- * `POST /api/frames/clipboard` with `{ refs, theme, themes? }`, rendering each
31180
- * frame at twice its layout size in `themes[ref]` where given and `theme`
31181
- * otherwise, and putting the images on the OS clipboard as one file list. A
31182
- * `themes` key naming no ref in `refs` is ignored. It sits behind
31183
- * `requireWriter`, since it replaces whatever the developer held, and a
31184
- * system with no backend refuses before any render.
31042
+ * `POST /api/frames/clipboard`, putting 2x renders on the OS clipboard behind
31043
+ * `requireWriter`, since it replaces whatever the developer held.
31185
31044
  */
31186
31045
  function clipboardRoutes(root, access, render, clipboard) {
31187
31046
  const app = new Hono();
@@ -31224,10 +31083,8 @@ function isSpace(char) {
31224
31083
  return char === " " || char === " " || char === "\n" || char === "\f" || char === "\r";
31225
31084
  }
31226
31085
  /**
31227
- * Scans one start tag through the tokenizer's start-tag states, since parse5
31228
- * records neither the self-closing flag nor a duplicated attribute. A `/`
31229
- * ending an unquoted value is part of the value, so `<circle id=x/>` is not
31230
- * self-closed, and only following the states tells the two apart.
31086
+ * Scans a start tag through the tokenizer states, since parse5 records neither
31087
+ * self-closing nor duplicates, and `<circle id=x/>` is not self-closed.
31231
31088
  */
31232
31089
  function scanStartTag(source, tag) {
31233
31090
  const names = [];
@@ -31332,10 +31189,8 @@ function rawAttribute(source, element, name) {
31332
31189
  return source.slice(value.start, value.end);
31333
31190
  }
31334
31191
  /**
31335
- * Sets one attribute to a raw value already escaped for double quotes,
31336
- * splicing only inside its value span. An absent attribute goes in before the
31337
- * tag's `>`, or before its real self-closing `/`, which only the start-tag
31338
- * scan tells apart from a `/` ending an unquoted value.
31192
+ * Sets one attribute inside its value span, a new one going before the real
31193
+ * self-closing `/`, which only the start-tag scan tells from an unquoted value's.
31339
31194
  */
31340
31195
  function setRawAttribute(source, element, name, raw) {
31341
31196
  const span = attributeSpan(element, name);
@@ -31410,15 +31265,9 @@ function locate(source, tree, span, side) {
31410
31265
  return found.length === 1 ? found[0] : void 0;
31411
31266
  }
31412
31267
  /**
31413
- * Finds again in `source` the element `index` named in `was`, the source an
31414
- * edit was made from, by the bytes its scope covers there, the way an undo
31415
- * finds its element. The index holds while every byte through the whole
31416
- * element is unchanged, its text included, since a start tag alone reads the
31417
- * same on two swapped siblings. Otherwise the bytes must read once in `was` and once in
31418
- * `source`, since a sibling sharing them could be the one left after a swap
31419
- * or a removal. Answers undefined when those bytes changed, read twice, or
31420
- * name no stated element, since writing on a guess would land over the
31421
- * agent's work.
31268
+ * Finds an element again by its bytes, the index holding while the whole
31269
+ * element is unchanged, else the bytes reading once on each side, since a
31270
+ * guess would land over the agent's work.
31422
31271
  */
31423
31272
  function relocate(was, index, scope, source) {
31424
31273
  const old = parseFrame(was);
@@ -31450,10 +31299,8 @@ function holdsSpan(source, span, side) {
31450
31299
  return locate(source, parseFrame(source), span, side) !== void 0;
31451
31300
  }
31452
31301
  /**
31453
- * Finds the element reading `side` of the span and writes the other side in
31454
- * its place, leaving every other byte as it stands. Answers undefined when the
31455
- * element is not found, or when the swap would leave it unfound, as a write
31456
- * the parser reads across element bounds would.
31302
+ * Swaps one side of the span for the other, undefined when the element is not
31303
+ * found or the swap would leave it unfound.
31457
31304
  */
31458
31305
  function swapSpan(source, span, side) {
31459
31306
  const tree = parseFrame(source);
@@ -36347,6 +36194,43 @@ function compile(selector, options, context) {
36347
36194
  function _compileUnsafe(selector, options, context) {
36348
36195
  return compileToken(typeof selector === "string" ? parse$2(selector) : selector, convertOptionFormats(options), context);
36349
36196
  }
36197
+ function getSelectorFunction(searchFunction) {
36198
+ return function select(query, elements, options) {
36199
+ const convertedOptions = convertOptionFormats(options);
36200
+ if (typeof query !== "function") query = _compileUnsafe(query, convertedOptions, elements);
36201
+ const filteredElements = prepareContext(elements, convertedOptions.adapter, query.shouldTestNextSiblings);
36202
+ return searchFunction(query, filteredElements, convertedOptions);
36203
+ };
36204
+ }
36205
+ /**
36206
+ * Normalize a query context and optionally include next siblings.
36207
+ * @param elements Elements to test against sibling-dependent selectors.
36208
+ * @param adapter Adapter implementation used for DOM operations.
36209
+ * @param shouldTestNextSiblings Whether sibling combinators should include following siblings.
36210
+ */
36211
+ function prepareContext(elements, adapter, shouldTestNextSiblings = false) {
36212
+ if (shouldTestNextSiblings) elements = appendNextSiblings(elements, adapter);
36213
+ return Array.isArray(elements) ? adapter.removeSubsets(elements) : adapter.getChildren(elements);
36214
+ }
36215
+ function appendNextSiblings(element, adapter) {
36216
+ const elements = Array.isArray(element) ? [...element] : [element];
36217
+ const elementsLength = elements.length;
36218
+ for (let index = 0; index < elementsLength; index++) {
36219
+ const nextSiblings = getNextSiblings(elements[index], adapter);
36220
+ elements.push(...nextSiblings);
36221
+ }
36222
+ return elements;
36223
+ }
36224
+ /**
36225
+ * @template Node The generic Node type for the DOM adapter being used.
36226
+ * @template ElementNode The Node type for elements for the DOM adapter being used.
36227
+ * @param elems Elements to query. If it is an element, its children will be queried.
36228
+ * @param query can be either a CSS selector string or a compiled query function.
36229
+ * @param [options] options for querying the document.
36230
+ * @see compile for supported selector queries.
36231
+ * @returns the first match, or null if there was no match.
36232
+ */
36233
+ const selectOne = getSelectorFunction((query, elements, options) => query === falseFunc || !elements || elements.length === 0 ? null : findOne(query, elements, options));
36350
36234
  // src/server/checks/cascade.ts
36351
36235
  /** The properties the selector rules read, with every custom property. */
36352
36236
  const READ = /* @__PURE__ */ new Set([
@@ -36384,10 +36268,8 @@ const NOT_STYLING = /* @__PURE__ */ new Set([
36384
36268
  "font-palette-values"
36385
36269
  ]);
36386
36270
  /**
36387
- * The browser's own `font-family` for elements an author rule has not
36388
- * reached: monospace for code, and the system control font for form
36389
- * controls, which do not inherit the page's font. Null stands for that
36390
- * control font, which no stylesheet names.
36271
+ * The browser's own `font-family` before author rules, null standing for the
36272
+ * form control font, which no stylesheet names.
36391
36273
  */
36392
36274
  const USER_AGENT_FAMILIES = {
36393
36275
  code: "monospace",
@@ -36410,11 +36292,8 @@ const CSS_WIDE = /* @__PURE__ */ new Set([
36410
36292
  "revert-layer"
36411
36293
  ]);
36412
36294
  /**
36413
- * Builds the cascade for one frame over its token sheets and then its own,
36414
- * so a frame rule wins a tie with a token rule as injection order makes it
36415
- * win in the browser. Weighs `!important`, inline styles, and specificity
36416
- * through `@bramus/specificity`, and takes every rule inside a media query
36417
- * as applying, since a frame renders at one viewport the check cannot see.
36295
+ * Builds a frame's cascade over its token sheets then its own, as injection
36296
+ * order wins ties, every media query applying, since the viewport is unseen.
36418
36297
  */
36419
36298
  function buildCascade(source, tokens, { properties = READ } = {}) {
36420
36299
  const reads = (property) => property.startsWith("--") || properties.has(property.toLowerCase());
@@ -36706,11 +36585,8 @@ const NOT_COLOR = /* @__PURE__ */ new Set([
36706
36585
  "content-box"
36707
36586
  ]);
36708
36587
  /**
36709
- * The part of a `border` or `background` shorthand that sets `property`:
36710
- * the last part that reads as a color for a color, since a color comes last
36711
- * in a border, and the first length for a width. Null when none does. An
36712
- * `!important` ends the parts, so a raw attribute value reads as the parsed
36713
- * one does, and `start` lets a writer replace the part in place.
36588
+ * The shorthand part setting `property`, the last color or the first length,
36589
+ * with `start` letting a writer replace it in place.
36714
36590
  */
36715
36591
  function shorthandPart(value, property) {
36716
36592
  const parts = [];
@@ -36773,10 +36649,8 @@ function shorthandFamily(value) {
36773
36649
  }
36774
36650
  // src/server/edit/style.ts
36775
36651
  /**
36776
- * The longhands a shorthand write drops, so a later longhand in the attribute
36777
- * does not keep overriding the value just set. A longhand write leaves its
36778
- * shorthand alone, since the longhand comes later and already wins, except
36779
- * where `PART_SHORTHANDS` rewrites the shorthand's own part instead.
36652
+ * The longhands a shorthand write drops, so a later one cannot keep overriding
36653
+ * the value just set.
36780
36654
  */
36781
36655
  const BORDER_SIDES = [
36782
36656
  "top",
@@ -36838,12 +36712,8 @@ function referenceEnd(style, at) {
36838
36712
  return CHARACTER_REFERENCE.test(style) ? CHARACTER_REFERENCE.lastIndex : void 0;
36839
36713
  }
36840
36714
  /**
36841
- * Splits a raw, still-encoded style value at each semicolon outside
36842
- * parentheses, quotes, and comments, keeping every segment's own spacing so
36843
- * an untouched one is written back as it was. A character reference's own
36844
- * semicolon never splits, a quote written as one is still a quote to CSS once
36845
- * decoded, and a backslash escapes the character after it, so `'a\'` leaves
36846
- * the quote open.
36715
+ * Splits a raw style at top-level semicolons, keeping each segment's spacing,
36716
+ * never at a character reference's own `;`.
36847
36717
  */
36848
36718
  function declarations(style) {
36849
36719
  const segments = [];
@@ -36910,13 +36780,8 @@ function shorthandValue(style, property) {
36910
36780
  return value === void 0 ? void 0 : shorthandPart(value, property)?.text;
36911
36781
  }
36912
36782
  /**
36913
- * Sets one declaration in a raw style value, or drops it on an empty value.
36914
- * The first declaration of the property is replaced in place and any later one
36915
- * dropped, so nothing further in the attribute overrides the edit, and a
36916
- * shorthand also drops its longhands. A paint longhand over a shorthand
36917
- * holding its part rewrites that part instead. The value arrives already escaped for
36918
- * the attribute. An empty style means none is left. A style ending inside an
36919
- * open quote or comment refuses, since an appended declaration would land in it.
36783
+ * Sets or drops one declaration, dropping later ones so nothing overrides the
36784
+ * edit, and refusing a style ending inside an open quote or comment.
36920
36785
  */
36921
36786
  function setDeclaration(style, property, value) {
36922
36787
  const parsed = declarations(style);
@@ -36959,13 +36824,8 @@ function setDeclaration(style, property, value) {
36959
36824
  };
36960
36825
  }
36961
36826
  /**
36962
- * The segments with `value` in place of the part of the last shorthand that
36963
- * sets `property`, so a paint edit over `border: 1px solid var(--primary)`
36964
- * leaves no token behind it as dead text. A declaration of the property ahead
36965
- * of the shorthand is already overridden by it, so it drops. Null when the
36966
- * property has no such shorthand, a later declaration sets the part on any
36967
- * side and would keep winning there, its value holds no such part, or a
36968
- * comment sits in it.
36827
+ * The segments with `value` in the last shorthand's part, so a paint edit
36828
+ * leaves no dead token behind, null when a later declaration would still win.
36969
36829
  */
36970
36830
  function withShorthandPart(segments, property, value) {
36971
36831
  const shorthand = PART_SHORTHANDS[property];
@@ -36996,11 +36856,8 @@ function setsPart(declared, property) {
36996
36856
  return side[1] === void 0 || `border-${side[1]}` === property;
36997
36857
  }
36998
36858
  /**
36999
- * Rewrites each declaration's value in a raw style through `rewrite`, which
37000
- * takes the property and the value with its spacing and answers the value to
37001
- * keep, so every byte it leaves alone is written back as it was. A
37002
- * declaration carrying a comment is kept as written, since its `:` may sit
37003
- * inside the comment. Null for a style ending inside an open quote or comment.
36859
+ * Rewrites each declaration's value, keeping one with a comment as written,
36860
+ * since its `:` may sit inside the comment.
37004
36861
  */
37005
36862
  function rewriteValues(style, rewrite) {
37006
36863
  const parsed = declarations(style);
@@ -37039,10 +36896,8 @@ function escapeText(value) {
37039
36896
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
37040
36897
  }
37041
36898
  /**
37042
- * Replaces the text of an element holding text alone. The source between its
37043
- * tags must be exactly its one text node, or nothing, since misnested markup
37044
- * such as `<b>1<p>2</b>` leaves the element's end tag past markup the tree
37045
- * builder gave to another element.
36899
+ * Replaces a text-only element's text, refusing unless its source is exactly
36900
+ * one text node, since misnesting can put its end tag past another's markup.
37046
36901
  */
37047
36902
  function setText(source, element, value) {
37048
36903
  const tag = element.tagName;
@@ -37168,10 +37023,8 @@ function isNamed(attribute, name) {
37168
37023
  return (attribute.prefix ? `${attribute.prefix}:${attribute.name}` : attribute.name).toLowerCase() === name;
37169
37024
  }
37170
37025
  /**
37171
- * Whether the output's tree is the input's with only the target changed. The
37172
- * target's edited attribute, or its text, is copied across from the output,
37173
- * so the comparison covers every other node, and the caller's own check
37174
- * covers the value itself.
37026
+ * Whether only the target changed, its edited part copied across so the
37027
+ * comparison covers every other node.
37175
37028
  */
37176
37029
  function changesOnlyTarget(before, after, index, change) {
37177
37030
  if (after.elements.length !== before.elements.length) return false;
@@ -37207,11 +37060,8 @@ function holdsValue(element, change) {
37207
37060
  });
37208
37061
  }
37209
37062
  /**
37210
- * Applies one change to the element the address names and leaves every other
37211
- * byte of the source as it was, a `styles` change writing each declaration in
37212
- * turn into the one style attribute. The output is parsed again and refused as
37213
- * `verify-failed` unless its tree is the input's with that one change, so an
37214
- * input the guards never met is refused rather than written corrupted.
37063
+ * Applies one change, keeping every other byte, and re-parses the output,
37064
+ * refusing `verify-failed` rather than write a corrupted file.
37215
37065
  */
37216
37066
  function applyEdit(source, address, change) {
37217
37067
  const normalized = change.kind === "style" ? {
@@ -37268,14 +37118,8 @@ const PLACE_PROPERTIES = /* @__PURE__ */ new Set([
37268
37118
  "height"
37269
37119
  ]);
37270
37120
  /**
37271
- * A frame's elements under `body` in index order, each with its parent and
37272
- * name, read from the same parse and the same index `edit` addresses. A
37273
- * frame where the browser builds an element the file does not state is
37274
- * refused, since every index after it would name another element.
37275
- * `layouts` is `elementLayouts`'s read by the same index, and an element it
37276
- * does not reach reads as `block`. `rounds` is `elementRounds`'s read, which
37277
- * marks an element round only while it holds nothing. `facts` is
37278
- * `elementPlaceFacts`'s read, and an element it does not reach reads unplaced.
37121
+ * A frame's elements under `body` by `edit` index, refused where the browser
37122
+ * builds an unstated element, since every later index would name another.
37279
37123
  */
37280
37124
  function elementTree(source, layouts = [], rounds = [], facts = []) {
37281
37125
  const tree = parseFrame(source);
@@ -37303,11 +37147,8 @@ function elementTree(source, layouts = [], rounds = [], facts = []) {
37303
37147
  return listed;
37304
37148
  }
37305
37149
  /**
37306
- * Every element's layout by the edit index, read from the static cascade
37307
- * over the token sheets and the frame's own, as `frameStyles` reads colors,
37308
- * so a culled frame with no iframe still answers. Every media query counts
37309
- * as applying, so a frame that flips its direction at a breakpoint reads as
37310
- * whichever rule wins statically.
37150
+ * Every element's layout from the static cascade, so a culled frame answers,
37151
+ * every media query applying.
37311
37152
  */
37312
37153
  function elementLayouts(source, tokens) {
37313
37154
  const cascade = buildCascade(source, tokens, { properties: LAYOUT_PROPERTIES });
@@ -37325,10 +37166,8 @@ function elementRounds(source, tokens) {
37325
37166
  });
37326
37167
  }
37327
37168
  /**
37328
- * Each element's `position` and whether a rule sizes its width and height,
37329
- * read from the same static cascade by the edit index, which a placement
37330
- * reads to choose the tags it writes. A sheet a load cannot read is missed,
37331
- * so a parent it positions reads as static.
37169
+ * Each element's `position` and rule sizing, for a placement, missing a sheet
37170
+ * a load cannot read, so a parent it positions reads static.
37332
37171
  */
37333
37172
  function elementPlaceFacts(source, tokens) {
37334
37173
  const cascade = buildCascade(source, tokens, { properties: PLACE_PROPERTIES });
@@ -37357,10 +37196,8 @@ function words(value) {
37357
37196
  return value?.trim().toLowerCase().split(/\s+/) ?? [];
37358
37197
  }
37359
37198
  /**
37360
- * What an element is called in the layers rows, the inspector, and the
37361
- * `selection` verb: its `data-name`, else a text-only element's text, else
37362
- * an `img`'s `alt`, else its tag. `id` and `aria-label` already mean
37363
- * something to a frame's CSS, scripts, and readers, so neither names it.
37199
+ * An element's name, never its `id` or `aria-label`, which already mean
37200
+ * something to the frame's CSS, scripts, and readers.
37364
37201
  */
37365
37202
  function elementName(element) {
37366
37203
  const named = attribute$1(element, "data-name")?.trim();
@@ -37629,15 +37466,9 @@ function gapOffset(tree, placement) {
37629
37466
  };
37630
37467
  }
37631
37468
  /**
37632
- * Writes `markup` into the gap and leaves every other byte as it was. The
37633
- * output is parsed again and refused as `verify-failed` unless its tree is
37634
- * the input's with that one element added under the parent, so a tag the
37635
- * parser would move, as a `<div>` closing a `<p>`, is refused rather than
37636
- * written somewhere else.
37637
- *
37638
- * A `lead` lands the element that many bytes ahead of the gap, once they
37639
- * read as given, so an element put back lands where it stood and not past
37640
- * the whitespace that followed it.
37469
+ * Writes `markup` into the gap, refusing `verify-failed` for a tag the parser
37470
+ * would move. A `lead` lands a restored element where it stood, ahead of the
37471
+ * whitespace that followed it.
37641
37472
  */
37642
37473
  function insertElement(source, placement, markup, lead = "") {
37643
37474
  const before = parseFrame(source);
@@ -37736,10 +37567,8 @@ function removeInserted(source, span) {
37736
37567
  return index === void 0 ? void 0 : takeOut$1(source, tree, index);
37737
37568
  }
37738
37569
  /**
37739
- * Takes the element at `index` out with its descendants and answers the span
37740
- * that puts it back, holding the bytes that stood between it and its gap.
37741
- * Answers undefined when the element is not stated, or when putting it back
37742
- * would not give `source` again, since the removal then reached past it.
37570
+ * Takes an element out and answers the span that puts it back, undefined when
37571
+ * putting it back would not give `source` again.
37743
37572
  */
37744
37573
  function takeOut$1(source, tree, index) {
37745
37574
  const element = tree.elements[index];
@@ -37763,14 +37592,8 @@ function takeOut$1(source, tree, index) {
37763
37592
  };
37764
37593
  }
37765
37594
  /**
37766
- * Takes out the element at `index`, with everything it holds, and answers
37767
- * the span `restoreInserted` puts it back by, so a delete is an insert run
37768
- * backwards. Only an element under `body` is taken, and the removal is
37769
- * refused as `verify-failed` unless the result parses as the source with
37770
- * that element alone gone, and its bytes go back as that one element.
37771
- * Putting it back lands it
37772
- * before the same sibling, so the whitespace around it may sit on its other
37773
- * side.
37595
+ * Takes an element out, answering the span `restoreInserted` uses, so a delete
37596
+ * is an insert run backwards, refused `verify-failed` unless only it went.
37774
37597
  */
37775
37598
  function removeElement(source, index) {
37776
37599
  const tree = parseFrame(source);
@@ -37815,12 +37638,8 @@ function restoreInserted(source, span) {
37815
37638
  } : void 0;
37816
37639
  }
37817
37640
  /**
37818
- * Takes the element at `index` out by its bytes and writes them into the gap
37819
- * `placement` names, both read in the frame as it stands, leaving every other
37820
- * byte. A gap in the element or under it is refused as `invalid-container`,
37821
- * since the element would be written inside itself, and the gap it already
37822
- * sits in as `invalid-address`. Each half is checked as `insertElement`
37823
- * checks a placement, so a move the parser would rebuild is refused whole.
37641
+ * Moves an element's bytes into another gap, refusing a gap inside itself, and
37642
+ * checking each half as `insertElement` does, so a rebuilt move is refused whole.
37824
37643
  */
37825
37644
  function moveElement(source, index, placement) {
37826
37645
  const tree = parseFrame(source);
@@ -37849,9 +37668,7 @@ function moveElement(source, index, placement) {
37849
37668
  };
37850
37669
  }
37851
37670
  /**
37852
- * Writes the moved element back to `side` of the move, taking it out of the
37853
- * other gap by its bytes and into this one by its anchors, and answers the
37854
- * span as the frame then stands. Answers undefined when either half is not
37671
+ * Writes the moved element back to `side`, undefined when either half is not
37855
37672
  * found, so a step the frame no longer allows is refused rather than guessed.
37856
37673
  */
37857
37674
  function relocateMoved(source, span, side) {
@@ -37909,16 +37726,9 @@ function reanchored(parent, skip, facts) {
37909
37726
  return walk(parent);
37910
37727
  }
37911
37728
  /**
37912
- * Places the element at `index` at a pixel spot as `position: absolute` with
37913
- * `left` and `top`, or puts it back in the flow when `spot` is null, which
37914
- * drops `left`, `top`, and the sizes `drop` names, and drops `position` from
37915
- * the style attribute, or writes `position: static` where only a rule places
37916
- * it, since dropping nothing would leave it placed. A
37917
- * static parent other than `body` takes `position: relative` first, so the
37918
- * spot counts from it, and is refused as `reanchors-descendant` when another
37919
- * absolute element under it anchors above it now. `facts` is the static
37920
- * cascade's read by the same index. Each tag is written by `applyEdit`,
37921
- * which verifies that only that element changed.
37729
+ * Places an element absolutely, or back in the flow, writing `position: static`
37730
+ * where only a rule places it. A static parent becomes relative, refused when
37731
+ * that would reanchor another absolute descendant.
37922
37732
  */
37923
37733
  function placeElement(source, index, spot, facts, drop = []) {
37924
37734
  const tree = parseFrame(source);
@@ -38014,11 +37824,8 @@ const HUGGING = /* @__PURE__ */ new Set([
38014
37824
  /** `align-items` and `align-self` values a child stretches across the cross axis under. */
38015
37825
  const STRETCHING = /* @__PURE__ */ new Set(["normal", "stretch"]);
38016
37826
  /**
38017
- * The selected element's flow from a cascade built over `FLOW_PROPERTIES`:
38018
- * the rule that makes it a container, so a shared one can be named, and
38019
- * Fixed, Hug, or Fill per axis. Fill reads only under a flex parent, along
38020
- * the main axis from a growing `flex`, across it from a stretch with no
38021
- * declared size, as Figma offers Fill only inside auto layout.
37827
+ * The selected element's flow and sizing per axis, Fill reading only under a
37828
+ * flex parent, as Figma offers it only inside auto layout.
38022
37829
  */
38023
37830
  function flowOf(cascade, element) {
38024
37831
  const rule = layoutOf(cascade, element) !== "block" ? cascade.specified(element, "display")?.rule ?? null : null;
@@ -38132,13 +37939,8 @@ const VAR = /^var\(\s*(--[\w-]+)\s*(?:,.*)?\)$/is;
38132
37939
  const MIX = /^color-mix\(\s*in\s+srgb\s*,\s*var\(\s*(--[\w-]+)\s*(?:,[^)]*)?\)\s+([\d.]+)%\s*,\s*transparent\s*\)$/is;
38133
37940
  const HEX_ALPHA = /^#([0-9a-f]{6})([0-9a-f]{2})$/i;
38134
37941
  /**
38135
- * A frame's colors as its source states them, read through the static
38136
- * cascade the checks use, so a `var()` over a name a token sheet declares
38137
- * is named exactly, one over a name only the frame declares answers the
38138
- * value it resolves to, and a raw
38139
- * value is answered raw rather than matched to a token that happens to
38140
- * share its value. `index` is the edit address's, naming the selected
38141
- * element, whose subtree the colors then cover in place of the frame's.
37942
+ * A frame's colors as its source states them, a raw value answered raw rather
37943
+ * than matched to a token sharing its value.
38142
37944
  */
38143
37945
  function frameStyles(source, tokens, index) {
38144
37946
  const cascade = buildCascade(source, tokens, { properties: PROPERTIES });
@@ -38227,10 +38029,8 @@ const SHORT_HEX = /^#([0-9a-f]{3,4})$/i;
38227
38029
  const LONG_HEX = /^#([0-9a-f]{6})$/i;
38228
38030
  const RGB = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)\s*(?:[,/]\s*([\d.]+%?)\s*)?\)$/i;
38229
38031
  /**
38230
- * One color however the source writes it, so `#4F46E5`, `#4f46e5`, and
38231
- * `rgb(79, 70, 229)` group as one Selection colors row and one color
38232
- * replace reaches each. A token keys by its name, and an alpha
38233
- * a raw value carries joins its percent.
38032
+ * One key per color however it is written, so its spellings group as one row
38033
+ * and one replace reaches each.
38234
38034
  */
38235
38035
  function colorKey(value) {
38236
38036
  if (value.token) return `${value.token}:${value.percent}`;
@@ -38303,15 +38103,9 @@ const COLOR_PROPERTIES = /* @__PURE__ */ new Set([
38303
38103
  "border"
38304
38104
  ]);
38305
38105
  /**
38306
- * Writes the token in place of every inline declaration of `from` on the
38307
- * element `root` names and its descendants, or on the frame's `body` and its
38308
- * descendants when `root` is undefined. Only the color part of a `border` or
38309
- * `background` shorthand changes, a value below 100 percent keeps its
38310
- * percent as a `color-mix()` over the token, and a value a `<style>` rule
38311
- * sets is never touched. The output is parsed again and refused as
38312
- * `verify-failed` unless each changed element differs only in its style, by
38313
- * exactly the swap, so a write never lands in part. An empty `spans` means
38314
- * nothing in the subtree states the color inline.
38106
+ * Swaps the token in for every inline `from` in a subtree, keeping alpha as a
38107
+ * `color-mix()` and never touching a `<style>` rule, refusing `verify-failed`
38108
+ * unless only the styles changed.
38315
38109
  */
38316
38110
  function recolorElements(source, root, recolor) {
38317
38111
  const before = parseFrame(source);
@@ -38397,10 +38191,8 @@ function replaceParts(value, replace) {
38397
38191
  return start < 0 ? out : out + value.slice(start);
38398
38192
  }
38399
38193
  /**
38400
- * Whether the output's tree is the input's with each changed element's style
38401
- * swapped and nothing else, its decoded style being exactly the swap of the
38402
- * one it had. The changed styles are copied across before the trees are
38403
- * compared, so the comparison covers every other node.
38194
+ * Whether only the changed styles moved, each exactly the swap, copied across
38195
+ * so the comparison covers every other node.
38404
38196
  */
38405
38197
  function changesOnlyStyles(before, after, changes, swap) {
38406
38198
  if (after.elements.length !== before.elements.length) return false;
@@ -38450,16 +38242,9 @@ function isFree(facts) {
38450
38242
  return position === "absolute" || position === "fixed";
38451
38243
  }
38452
38244
  /**
38453
- * Wraps the sibling elements `indexes` names in one new `div` laid out as
38454
- * `flow`, written at the first one's place, with every one moved into it in
38455
- * document order. A free member leaves the flow it is wrapped in otherwise,
38456
- * so each puts back `position`, `left`, and `top` as back in flow does, and
38457
- * the container takes `spot` instead, placed freely where the group sat, or
38458
- * sits in the flow when `spot` is null. `facts` is the static cascade read
38459
- * by the same index. Elements that are not siblings, the document's own
38460
- * wrappers, and a parent the file does not state are refused, and the
38461
- * output is parsed again and refused as `verify-failed` unless only the
38462
- * parent's contents changed, holding the container and its members.
38245
+ * Wraps siblings in one new flow `div` at the first one's place, free members
38246
+ * going back in flow while the container takes `spot`, refusing `verify-failed`
38247
+ * unless only the parent's contents changed.
38463
38248
  */
38464
38249
  function wrapElements(source, indexes, flow, spot, facts) {
38465
38250
  const tree = parseFrame(source);
@@ -38546,15 +38331,9 @@ function collided(path, was, index, source) {
38546
38331
  };
38547
38332
  }
38548
38333
  /**
38549
- * Edits one element of a frame file and replaces the file through a
38550
- * temporary file and a rename. A file whose bytes do not survive a UTF-8
38551
- * round trip is refused, since decoding would rewrite every invalid byte. An
38552
- * address carrying a hash the file no longer has is found again through
38553
- * `sourceAt`, by the bytes the edit reads, and refused as stale when no source
38554
- * is kept or those bytes changed. The file is read again just before the
38555
- * rename so a write landing meanwhile is refused rather than overwritten. No
38556
- * lock is taken, since an agent's raw write never takes one and the hash is
38557
- * what protects a hand edit.
38334
+ * Edits one element through a temp file and a rename, re-reading just before
38335
+ * the rename so a write landing meanwhile is refused. No lock is taken, since
38336
+ * an agent's raw write never takes one and the hash protects a hand edit.
38558
38337
  */
38559
38338
  function editFrameFile(path, address, change, sourceAt) {
38560
38339
  const read = readSource(path);
@@ -38581,14 +38360,9 @@ function editFrameFile(path, address, change, sourceAt) {
38581
38360
  };
38582
38361
  }
38583
38362
  /**
38584
- * Edits several elements of a frame file as one write, each found again and
38585
- * verified as `editFrameFile` does one, in the order sent through the bytes
38586
- * the one before it left. Any refusal writes nothing, so a batch never lands
38587
- * in part. Naming one element twice is refused, since one undo could not
38588
- * put both spans back, except for a text change beside one style change.
38589
- * That pair answers one span over the whole element, both changes in it,
38590
- * since an undo checks every span against the bytes as they stand and the
38591
- * text's own span no longer reads once the style wrote its start tag.
38363
+ * Edits several elements as one write, all or none. One element named twice is
38364
+ * refused, since one undo could not put both spans back, except a text and a
38365
+ * style change, which answer one span over the whole element.
38592
38366
  */
38593
38367
  function editFrameFileAll(path, hash, edits, sourceAt) {
38594
38368
  const read = readSource(path);
@@ -38661,14 +38435,9 @@ function namedOnceEach(indexes, edits) {
38661
38435
  return [...kinds.values()].every((named) => named.length === 1 || named.length === 2 && named.filter((kind) => kind === "text").length === 1 && named.some((kind) => kind === "style" || kind === "styles"));
38662
38436
  }
38663
38437
  /**
38664
- * Writes one new element into a frame file the way `editFrameFile` writes an
38665
- * edit, through a temporary file and a rename after reading the file again.
38666
- * A hash the file no longer has is refused as stale with no search, since the
38667
- * gap's indices name nothing once the file moved, which also lands a retried
38668
- * insert at most once. Given `place`, the element is placed out of the flow
38669
- * in the same write. Its span carries the placed bytes and `parent` the start
38670
- * tag a static parent took, so one undo takes the element out after the
38671
- * parent's tag goes back, and a redo finds the gap as it first stood.
38438
+ * Writes one new element as `editFrameFile` writes, refusing a moved hash with
38439
+ * no search, since the gap's indices name nothing once the file moved, so a
38440
+ * retried insert lands at most once.
38672
38441
  */
38673
38442
  function insertFrameFile(path, hash, placement, markup, place) {
38674
38443
  const read = readSource(path);
@@ -38714,10 +38483,8 @@ function removeFrameFile(path, hash, index) {
38714
38483
  };
38715
38484
  }
38716
38485
  /**
38717
- * Takes several elements out of a frame file as one write, refused as
38718
- * `removeFrameFile` refuses one. Each goes last in the file first, so the
38719
- * indices ahead of it hold, and one inside another named element goes with
38720
- * that one rather than on its own.
38486
+ * Takes several elements out as one write, last in the file first, so the
38487
+ * indices ahead of each hold, a nested named element going with its outer one.
38721
38488
  */
38722
38489
  function removeFrameFileAll(path, hash, indexes) {
38723
38490
  const read = readSource(path);
@@ -38773,11 +38540,8 @@ function moveFrameFile(path, hash, index, placement) {
38773
38540
  };
38774
38541
  }
38775
38542
  /**
38776
- * Places one element of a frame file at a spot, or puts it back in the flow
38777
- * dropping the sizes `drop` names,
38778
- * written as `moveFrameFile` writes and refused as stale on a hash the file
38779
- * no longer has. `facts` is the static cascade read from the bytes `hash`
38780
- * names, so a parent's position is never read from another version.
38543
+ * Places one element at a spot or back in the flow, `facts` read from the
38544
+ * bytes `hash` names, so a parent's position never comes from another version.
38781
38545
  */
38782
38546
  function placeFrameFile(path, hash, index, spot, facts, drop = []) {
38783
38547
  const read = readSource(path);
@@ -38795,12 +38559,8 @@ function placeFrameFile(path, hash, index, spot, facts, drop = []) {
38795
38559
  };
38796
38560
  }
38797
38561
  /**
38798
- * Places several elements of a frame file as one write, refused whole as
38799
- * `placeFrameFile` refuses one. They go in file order, so a parent placed too
38800
- * is positioned ahead of its child, which then writes no second span on its
38801
- * tag that would strand the undo. `factsOf` reads the static cascade of the
38802
- * bytes the one before left, so siblings share the parent the first one made
38803
- * relative rather than writing it twice.
38562
+ * Places several elements as one write in file order, so a placed parent comes
38563
+ * first and no second span strands the undo.
38804
38564
  */
38805
38565
  function placeFrameFileAll(path, hash, places, factsOf) {
38806
38566
  const read = readSource(path);
@@ -38827,10 +38587,8 @@ function placeFrameFileAll(path, hash, places, factsOf) {
38827
38587
  };
38828
38588
  }
38829
38589
  /**
38830
- * Wraps sibling elements of a frame file in one flow container, written as
38831
- * `moveFrameFile` writes and refused as stale on a hash the file no longer
38832
- * has, since the indices name nothing once the file moved. `facts` is the
38833
- * static cascade read from the bytes `hash` names.
38590
+ * Wraps siblings in one flow container, refused as stale on a moved hash, since
38591
+ * the indices name nothing once the file moved.
38834
38592
  */
38835
38593
  function wrapFrameFile(path, hash, indexes, flow, spot, facts) {
38836
38594
  const read = readSource(path);
@@ -38849,10 +38607,9 @@ function wrapFrameFile(path, hash, indexes, flow, spot, facts) {
38849
38607
  };
38850
38608
  }
38851
38609
  /**
38852
- * Replaces a raw color with a token across the subtree `root` names, or the
38853
- * frame's body when undefined, written as `placeFrameFile` writes and refused
38854
- * as stale on a hash the file no longer has, so a retried replace lands once.
38855
- * A subtree stating the color nowhere inline writes nothing.
38610
+ * Replaces a raw color with a token across a subtree, refused as stale on a
38611
+ * moved hash, so a retried replace lands once, and writing nothing when no
38612
+ * inline color is stated.
38856
38613
  */
38857
38614
  function recolorFrameFile(path, hash, root, recolor) {
38858
38615
  const read = readSource(path);
@@ -39039,10 +38796,8 @@ async function movePage(root, ref, { index, ...options }) {
39039
38796
  return recordOf(root, page, await reorder(root, page, async (order) => insert(order.filter((name) => name !== page.name), page.name, index), options.journal));
39040
38797
  }
39041
38798
  /**
39042
- * Sets the transition present mode draws between the page's slides, or
39043
- * clears it with null, writing only the `present` key of its `layout.json`
39044
- * and leaving every frame file as it stands. A name that is neither built
39045
- * in nor the project's own refuses `usage` and writes nothing.
38799
+ * Sets or clears a page's present transition, writing only the `present` key
38800
+ * and refusing a name neither built in nor the project's own.
39046
38801
  */
39047
38802
  async function setPageTransition(root, ref, transition, { journal, ...options }) {
39048
38803
  const page = await resolvePageRef(root, ref, options);
@@ -39064,11 +38819,8 @@ async function deletePage(root, ref, { journal, ...options }) {
39064
38819
  return { deleted: `${page.project}/${page.name}` };
39065
38820
  }
39066
38821
  /**
39067
- * Runs one page change under the project file's lock, returning the page's
39068
- * name after it and the order written. The file is read and
39069
- * validated before `change` touches a folder, and written back holding exactly
39070
- * the page folders on disk, in the order `change` returns, which the journal
39071
- * is told of when it differs from the order the file held.
38822
+ * Runs one page change under the project file's lock, validating before
38823
+ * `change` touches a folder, then writing exactly the page folders on disk.
39072
38824
  */
39073
38825
  async function reorder(root, page, change, journal) {
39074
38826
  const projectDir = join(root, page.project);
@@ -39152,14 +38904,9 @@ async function renameProject(root, name, newName, { journal } = {}) {
39152
38904
  return scanProject(root, newName);
39153
38905
  }
39154
38906
  /**
39155
- * Sets the name a person reads for the project, which may hold any
39156
- * characters, and moves the folder to the name made from it, the next free
39157
- * one when another project holds it. A title naming no folder, such as one in
39158
- * a script a name cannot hold, or one naming the folder it is in, keeps the
39159
- * folder. A blank title takes the key out, so readers show the folder again.
39160
- * The title goes in first under the old folder and the move follows, which
39161
- * the board's undo reverses in turn. The times are put back as a filing's
39162
- * are, since a title draws nothing.
38907
+ * Sets a project's title and moves its folder to the name made from it. The
38908
+ * title goes in under the old folder before the move, so undo reverses them in
38909
+ * turn.
39163
38910
  */
39164
38911
  async function retitleProject(root, name, title, { journal } = {}) {
39165
38912
  const project = await resolveProject(root, name);
@@ -39226,11 +38973,8 @@ async function deleteProject(root, name, { journal } = {}) {
39226
38973
  return { deleted: project.name };
39227
38974
  }
39228
38975
  /**
39229
- * Files every named project at once, each `project.json` read and merged
39230
- * under its lock so pages, checks, and unknown keys stay as written. A file
39231
- * that does not parse refuses the whole filing before any is written. The
39232
- * file's and folder's times are put back, since a filing is not an edit to
39233
- * the project and must not move it in home's Edited sort.
38976
+ * Files projects at once under each file's lock, refusing all on an unparsed
38977
+ * file, and puts the times back, since a filing must not move the Edited sort.
39234
38978
  */
39235
38979
  async function fileProjects(root, names, filing, { journal } = {}) {
39236
38980
  const projects = await Promise.all(names.map((name) => resolveProject(root, name)));
@@ -39284,13 +39028,8 @@ function isSameFiling(a, b) {
39284
39028
  return a.group === b.group && a.archived === b.archived && a.title === b.title && isDeepStrictEqual(a.off, b.off);
39285
39029
  }
39286
39030
  /**
39287
- * Turns one check rule off for the project, or back on, by adding or removing
39288
- * its id in `checks.off` of `project.json` under the file's lock, so every
39289
- * other key stays as written. A rule already as asked writes nothing, and an
39290
- * `off` that is not a list of ids reads as none and is replaced by the first
39291
- * rule turned off. A `checks` that is not an object refuses as
39292
- * `project-file-invalid`, since no rule could be written beside it. The times
39293
- * are put back as a filing's are, since a rule switch draws nothing.
39031
+ * Turns a rule off or on in `checks.off` under the file's lock, refusing a
39032
+ * `checks` that is no object, and puts the times back as a filing does.
39294
39033
  */
39295
39034
  async function setProjectRule(root, name, rule, off, { journal } = {}) {
39296
39035
  const project = await resolveProject(root, name);
@@ -39317,11 +39056,8 @@ async function setProjectRule(root, name, rule, off, { journal } = {}) {
39317
39056
  }));
39318
39057
  }
39319
39058
  /**
39320
- * `file` with its `checks.off` set to `off`, or without the key for
39321
- * undefined, every other check kept in place. A `checks` this empties goes
39322
- * too, so turning a rule off and on leaves no empty object behind. A file
39323
- * holding no `off` to take out comes back as it is, so a `checks` of another
39324
- * type, or an empty one, survives the undo of a write that never touched it.
39059
+ * `file` with `checks.off` set or removed, dropping a `checks` it empties so
39060
+ * off and on leaves no empty object.
39325
39061
  */
39326
39062
  function withOff(file, off) {
39327
39063
  if (off === void 0 && !(isRecord$3(file.checks) && file.checks.off !== void 0)) return file;
@@ -39344,14 +39080,9 @@ function isRecord$3(value) {
39344
39080
  return typeof value === "object" && value !== null && !Array.isArray(value);
39345
39081
  }
39346
39082
  /**
39347
- * Runs `run`, a section holding the lock of each project file it writes, and
39348
- * puts back the times that file and its folder held, which the scanner reads
39349
- * as the project's last edit. `land` names where a file stands once `run`
39350
- * is done, for a run that moves its folder, and the times go back there. `run` calls `keep` under the lock before each
39351
- * write, so the file's time is read after any writer that held the lock first.
39352
- * The folder's time is read before the lock, since taking and dropping the
39353
- * lock moves it, and goes back only where the file kept its time until `keep`,
39354
- * so a writer that ran in between keeps the Edited time it earned.
39083
+ * Runs `run` and puts back the times the scanner reads as the last edit. The
39084
+ * folder's time is read before the lock, which moves it, and restored only if
39085
+ * no writer ran in between, so that writer keeps its Edited time.
39355
39086
  */
39356
39087
  async function keepingTimes(files, run, land = (file) => file) {
39357
39088
  const before = new Map(await Promise.all(files.map(async (file) => [file, {
@@ -39387,15 +39118,9 @@ async function assertFree$1(root, name, self) {
39387
39118
  const NAME = /^--[\w-]+$/;
39388
39119
  const UNSAFE_VALUE = /[;{}\n\r]|\/\*/;
39389
39120
  /**
39390
- * The project or board sheet with `edit` applied, every byte outside the
39391
- * token's declarations left as it stood. `board` is the token's declarations
39392
- * in the board sheet under it, none when `css` is the board sheet itself. A
39393
- * one-theme edit keeps the other theme rendering as it did,
39394
- * pinning its old value under that theme's rule when the new declaration
39395
- * would reach it, since a project `:root` ties a board dark rule on
39396
- * specificity and wins by coming later. Refuses `invalid-edit` for a name or
39397
- * value that is not one declaration, a reset of a token the board does not
39398
- * set, and a sheet that does not parse.
39121
+ * The sheet with `edit` applied, keeping every other byte. A one-theme edit
39122
+ * pins the other theme's old value, since a project `:root` ties a board dark
39123
+ * rule on specificity and wins by coming later.
39399
39124
  */
39400
39125
  function editTokenCss(css, board, edit) {
39401
39126
  if (!NAME.test(edit.name)) refuse$1(`${edit.name} is not a custom property.`);
@@ -39431,9 +39156,7 @@ function editTokenCss(css, board, edit) {
39431
39156
  }
39432
39157
  /**
39433
39158
  * The sheet with the token's declarations made exactly `sides`, as undo
39434
- * restores them. A side present replaces the last declaration on that side,
39435
- * or is added to that side's rule, and a side absent takes out every
39436
- * declaration on it, dropping a rule it leaves empty.
39159
+ * restores them, dropping a rule it leaves empty.
39437
39160
  */
39438
39161
  function setTokenSides(css, name, sides) {
39439
39162
  return writeSides(parseSheet(css), name, sides);
@@ -39443,11 +39166,8 @@ function tokenSides(css, name) {
39443
39166
  return sidesIn(parseSheet(css), name);
39444
39167
  }
39445
39168
  /**
39446
- * Writes the token sheet at `path` through a temporary file and a rename,
39447
- * reading the sheet again just before the rename and leaving it as it is
39448
- * when its hash is no longer `hash`. A null `hash` means the sheet did not
39449
- * exist, so it is created only while none does. Takes no lock, since an
39450
- * agent's raw write never takes one.
39169
+ * Writes the sheet through a rename unless its hash moved, a null `hash`
39170
+ * creating it only while none exists. No lock, as an agent's write takes none.
39451
39171
  */
39452
39172
  function writeTokenSheet(path, hash, css) {
39453
39173
  if (hash === null) try {
@@ -39567,12 +39287,8 @@ const NEW_SELECTOR = {
39567
39287
  dark: "[data-theme='dark']"
39568
39288
  };
39569
39289
  /**
39570
- * The top-level rule a new declaration on `side` goes into: the last such
39571
- * rule outside any at-rule, else a new one. A new `:root` or light rule goes
39572
- * ahead of every other rule, so a dark rule that ties it on specificity
39573
- * still comes later and wins in dark, and a new dark rule goes last. With
39574
- * `before`, the token's first dark declaration, a rule must come ahead of
39575
- * it, and a new one goes just before it when none does.
39290
+ * The rule a new declaration on `side` goes into, a new light rule going first
39291
+ * so a tying dark rule still comes later and wins in dark.
39576
39292
  */
39577
39293
  function ruleFor(root, side, before) {
39578
39294
  const last = root.nodes.filter((node) => node.type === "rule" && sideOf(node) === side && (!before || root.index(node) < root.index(before))).at(-1);
@@ -39630,10 +39346,8 @@ function lockPaths(change) {
39630
39346
  return [];
39631
39347
  }
39632
39348
  /**
39633
- * Whether the board still stands as `side` of the change left it, read
39634
- * under the record's lock. A change that no longer holds was overtaken, and
39635
- * so was one whose record an agent left unreadable, since writing it back
39636
- * would overwrite that file and keeping the step would block every older one.
39349
+ * Whether the board still stands as `side` left it, an unreadable record
39350
+ * counting as overtaken, since writing it back would overwrite the agent's file.
39637
39351
  */
39638
39352
  async function holds(change, side) {
39639
39353
  try {
@@ -39682,10 +39396,8 @@ async function reads(change, side) {
39682
39396
  }
39683
39397
  }
39684
39398
  /**
39685
- * The entry a step holds, taking the stored size on each axis both it and the
39686
- * stored entry hug, since the server measures that size and the developer
39687
- * never set it, so a measure after a hand move neither overtakes the step nor
39688
- * is reverted by it.
39399
+ * The step's entry with the stored size on hugged axes, so a measure after a
39400
+ * hand move neither overtakes the step nor is reverted by it.
39689
39401
  */
39690
39402
  function withMeasured(entry, stored) {
39691
39403
  if (!entry || !stored) return entry;
@@ -39807,10 +39519,8 @@ async function restore(change, side) {
39807
39519
  }
39808
39520
  }
39809
39521
  /**
39810
- * The frame with a delete's elements back, `before` restoring them in the
39811
- * reverse of the order taken out, or out again, `after` taking them in that
39812
- * order, undefined when any one's bytes or gap no longer read. Answers the
39813
- * spans as the frame then stands, in the order taken out.
39522
+ * The frame with a delete's chain restored or taken out again, undefined when
39523
+ * any one's bytes or gap no longer read.
39814
39524
  */
39815
39525
  function chainDeleted(source, { spans }, side) {
39816
39526
  const restoring = side === "before";
@@ -39845,13 +39555,8 @@ async function rewriteToken(change, side) {
39845
39555
  if (writeTokenSheet(change.path, contentHash(css), written) === "stale") throw new FrameboardError("undo-overtaken", `An agent changed ${change.name} after your edit, so that step was dropped.`, { change: change.kind });
39846
39556
  }
39847
39557
  /**
39848
- * Writes a hand edit's element to the other side through a temporary file and
39849
- * a rename, reading the file again just before the rename. A write landing
39850
- * before that read is not overwritten: the rewrite is made once more from the
39851
- * fresh bytes, and refused once they change again or no longer hold the
39852
- * element. Bytes that fail a UTF-8 round trip are refused too, since decoding
39853
- * would rewrite each invalid byte outside the element. The change keeps where
39854
- * the element was found, through `keep`, so the next side lands on it.
39558
+ * Writes an element's other side through a rename, redoing it once from fresh
39559
+ * bytes when a write lands first, and refusing bytes that fail a UTF-8 round trip.
39855
39560
  */
39856
39561
  async function rewriteFrame(change, rewrite) {
39857
39562
  const temp = join(dirname(change.path), `.${basename(change.path)}.${process.pid}.tmp`);
@@ -40064,11 +39769,8 @@ async function exists(path) {
40064
39769
  }
40065
39770
  const OPEN = async () => {};
40066
39771
  /**
40067
- * The developer's undo and redo stacks, in memory, holding the board's own
40068
- * writes and never an agent's. Undo and redo run one at a time, each
40069
- * checking every change of a step under its records' locks before writing
40070
- * any, and refusing with `undo-overtaken` and dropping the step when an
40071
- * agent has since changed one.
39772
+ * The developer's in-memory undo and redo stacks, checking a whole step before
39773
+ * writing any, and dropping it with `undo-overtaken` once an agent changed one.
40072
39774
  */
40073
39775
  var History = class {
40074
39776
  root;
@@ -40103,10 +39805,8 @@ var History = class {
40103
39805
  this.onWrite(step, "after");
40104
39806
  }
40105
39807
  /**
40106
- * The refs the top undo or redo step would write, without popping it, so a
40107
- * route can refuse a claimed frame before the step is taken. These are the
40108
- * step's frames, and the page or project folder and frame file each move
40109
- * or removal names, since a page or project step names no frames.
39808
+ * The refs the top step would write, without popping it, so a route can refuse
39809
+ * a claimed frame before the step is taken.
40110
39810
  */
40111
39811
  peek(side) {
40112
39812
  const step = (side === "undo" ? this.#undo : this.#redo).at(-1);
@@ -40187,10 +39887,8 @@ var History = class {
40187
39887
  }
40188
39888
  };
40189
39889
  /**
40190
- * The change as the board stands at `side`, reading a project file where the
40191
- * moves `later` in its step left it on the after side, since a retitle writes
40192
- * the file under the old folder and then moves the folder. Restoring keeps the
40193
- * recorded path, since the moves are undone first and redone last.
39890
+ * The change as the board stands at `side`, following later folder moves,
39891
+ * since a retitle writes the file before moving its folder.
40194
39892
  */
40195
39893
  function standingAt(change, later, side) {
40196
39894
  if (side === "before" || change.kind !== "project") return change;
@@ -40265,11 +39963,8 @@ async function hashOf(path) {
40265
39963
  }
40266
39964
  }
40267
39965
  /**
40268
- * The one line a follower prints per note. It opens with `frameboard note`,
40269
- * which the skill tells the agent to act on, and names the verbs that answer
40270
- * it. Text is collapsed onto one line, stripped of control characters so it
40271
- * cannot drive the terminal, and cut at 200 characters. Image paths sit
40272
- * between the text and the hints, so the prefix and the hints never move.
39966
+ * The one line a follower prints per note, opening on `frameboard note`, with
39967
+ * control characters stripped so the text cannot drive the terminal.
40273
39968
  */
40274
39969
  function noteLine({ id, ref, element, text, images = [] }) {
40275
39970
  const where = element === null ? ref : `${ref} element ${element}`;
@@ -40430,13 +40125,8 @@ function removeNote(file, id) {
40430
40125
  };
40431
40126
  }
40432
40127
  /**
40433
- * Carries each note anchored on `frame` across a write the board made from
40434
- * the bytes `before` names to the bytes `after` names, recording the index
40435
- * `remap` gives its element. A note not resolving at `before`, or whose
40436
- * element the write took out, is left as it is, so it falls back to the
40437
- * frame. Each anchor keeps the last `HISTORY_CAP` hashes, since no undo
40438
- * reaches further. Writes nothing when no note follows, and leaves a notes
40439
- * file that does not parse, since the frame write already landed.
40128
+ * Carries each note's anchor across a board write, an unresolved one falling
40129
+ * back to the frame, keeping `HISTORY_CAP` hashes, since no undo reaches further.
40440
40130
  */
40441
40131
  async function followEdit(path, frame, before, after, remap) {
40442
40132
  let file;
@@ -40607,11 +40297,8 @@ const LINE_TOKEN = "--border";
40607
40297
  /** Raw on purpose, so the check names it once the project sets no color token. */
40608
40298
  const RAW_GREY = "#d9d9d9";
40609
40299
  /**
40610
- * A shape's fill, being the first of the muted, secondary, and accent tokens
40611
- * the project sets, else its first color token, and its line, being the
40612
- * border token else that first color token. With no color token at all, both
40613
- * are a raw grey. The server writes it on a placed shape, and the board
40614
- * draws a dragged shape's preview in it.
40300
+ * A shape's fill and line from the project's tokens, shared so the server's
40301
+ * placed shape and the board's drag preview match.
40615
40302
  */
40616
40303
  function shapePaint(tokens) {
40617
40304
  const names = new Set(tokens.map((row) => row.name));
@@ -40624,7 +40311,7 @@ function shapePaint(tokens) {
40624
40311
  }
40625
40312
  // src/server/routes/edit.ts
40626
40313
  const value = string$1().max(1e4);
40627
- const name$1 = string$1().min(1).max(256);
40314
+ const name$2 = string$1().min(1).max(256);
40628
40315
  /** A dragged shape's side in CSS pixels. */
40629
40316
  const side = int$1().min(1).max(1e4);
40630
40317
  /** A spot in CSS pixels, bounded well past any frame. */
@@ -40634,17 +40321,17 @@ const BATCH = 1024;
40634
40321
  const changeSchema = union([
40635
40322
  object$1({
40636
40323
  kind: literal("style"),
40637
- property: name$1,
40324
+ property: name$2,
40638
40325
  value
40639
40326
  }),
40640
40327
  strictObject({
40641
40328
  kind: literal("attribute"),
40642
- name: name$1,
40329
+ name: name$2,
40643
40330
  value
40644
40331
  }),
40645
40332
  strictObject({
40646
40333
  kind: literal("attribute"),
40647
- name: name$1,
40334
+ name: name$2,
40648
40335
  remove: literal(true)
40649
40336
  }),
40650
40337
  object$1({
@@ -40654,7 +40341,7 @@ const changeSchema = union([
40654
40341
  object$1({
40655
40342
  kind: literal("styles"),
40656
40343
  declarations: array$1(object$1({
40657
- property: name$1,
40344
+ property: name$2,
40658
40345
  value
40659
40346
  })).max(16)
40660
40347
  })
@@ -40776,16 +40463,8 @@ const recolorSchema = object$1({
40776
40463
  to: string$1().regex(/^--[\w-]+$/)
40777
40464
  });
40778
40465
  /**
40779
- * A hand edit of one element, a placed element, and a deleted one, each behind
40780
- * `requireWriter` and refused on a frame another session holds.
40781
- *
40782
- * Every write names the frame by the `hash` the board rendered and goes through
40783
- * `editFrameFile`, which finds the element again in a frame an agent wrote
40784
- * since and records the span as one undoable step. A refusal answers 409 with
40785
- * its code, such as `stale-address`, and writes nothing. A batch field
40786
- * (`edits`, `indexes`, `places`) writes each item as one step and is refused
40787
- * whole on any refusal. An insert takes an element kind, never markup, and a
40788
- * recolor rewrites inline colors only. Each write remaps pinned notes.
40466
+ * The hand element writes, each naming the rendered `hash` and recording one
40467
+ * undo step, a batch refused whole. An insert takes a kind, never markup.
40789
40468
  */
40790
40469
  function editRoutes(root, access, history, version, sheets) {
40791
40470
  const app = new Hono();
@@ -41242,13 +40921,31 @@ function editRoutes(root, access, history, version, sheets) {
41242
40921
  app.onError(answerRefusal);
41243
40922
  return app;
41244
40923
  }
40924
+ // src/shared/kits.ts
40925
+ /**
40926
+ * The names a design kit's folder of plain files is laid out by, installed so
40927
+ * the frame route imports `assets/kit/` after the token sheets.
40928
+ */
40929
+ const KIT_FILE = "kit.json";
40930
+ const KIT_SHEET = "kit.css";
40931
+ const KIT_NOTE = "kit.md";
40932
+ /** The dot folder in a board holding the kits saved from its projects, which home never lists as a project. */
40933
+ const KITS_FOLDER = ".kits";
40934
+ /**
40935
+ * Where the board serves a kit's files, under `/frameboard/`, since a bare
40936
+ * `/kits` would shadow the client's module folder under the dev server.
40937
+ */
40938
+ const KITS_URL = "/frameboard/kits";
40939
+ /** The kits the tool ships, in the order a picker shows them. */
40940
+ const SHIPPED_KITS = [
40941
+ "clean",
40942
+ "sketch",
40943
+ "wireframe"
40944
+ ];
41245
40945
  // src/server/checks/tokens.ts
41246
40946
  /**
41247
- * Where a project's token sheets sit. The board sheet is the one `serve
41248
- * --tokens` recorded in the address file, else the board folder's own, and
41249
- * `tokens` stands in for the address file where the caller already knows it.
41250
- * The address file is read with a plain `JSON.parse` rather than its schema,
41251
- * which the write hook cannot afford to load.
40947
+ * Where a project's token sheets sit, the address file read by plain
40948
+ * `JSON.parse`, since the write hook cannot afford its schema.
41252
40949
  */
41253
40950
  function tokenSheetPaths(root, project, tokens) {
41254
40951
  const own = join(root, project, TOKEN_FILE);
@@ -41273,12 +40970,18 @@ function recordedTokens(root) {
41273
40970
  }
41274
40971
  }
41275
40972
  /**
41276
- * The token sheets a project's frames render with, board-wide first and then
41277
- * the project's own, which the cascade reads ahead of each frame's sheets.
40973
+ * The sheets the frame route imports ahead of a project's frames, being the
40974
+ * board's tokens, then the project's, then an installed kit's stylesheet,
40975
+ * which the cascade reads ahead of each frame's own sheets.
41278
40976
  */
41279
40977
  function tokenSheets(root, project, tokens) {
41280
40978
  const paths = tokenSheetPaths(root, project, tokens);
41281
- return [paths.board, paths.project].filter((path) => path !== null).map((path) => ({
40979
+ const kit = join(root, project, ASSETS_FOLDER, "kit", KIT_SHEET);
40980
+ return [
40981
+ paths.board,
40982
+ paths.project,
40983
+ existsSync(kit) ? kit : null
40984
+ ].filter((path) => path !== null).map((path) => ({
41282
40985
  css: readFileSync(path, "utf8"),
41283
40986
  origin: "token",
41284
40987
  path,
@@ -41334,13 +41037,8 @@ const STATUS$2 = {
41334
41037
  "address-mismatch": 422
41335
41038
  };
41336
41039
  /**
41337
- * A frame's element tree, read from the file rather than a live iframe so a
41338
- * culled frame lists the indices `edit` addresses, with each element's
41339
- * layout read from the static cascade over `tokens`, and the selection the
41340
- * writing tab last reported, which `POST /api/selection` takes behind
41341
- * `requireWriter` and `GET /api/selection` answers as the `selection` record.
41342
- * `GET /api/frames/styles` answers a frame's or an element's colors from the
41343
- * static cascade over `tokens`, the server's `--tokens` sheet when it has one.
41040
+ * The element tree, read from the file so a culled frame lists the indices
41041
+ * `edit` addresses, the reported selection, and the static colors.
41344
41042
  */
41345
41043
  function elementsRoutes(root, access, selection, tokens = null) {
41346
41044
  const app = new Hono();
@@ -41358,10 +41056,6 @@ function elementsRoutes(root, access, selection, tokens = null) {
41358
41056
  elements
41359
41057
  };
41360
41058
  };
41361
- /**
41362
- * The reported element with its tag and name, or null once the file has
41363
- * changed past the hash the tab read, since the index may now name another.
41364
- */
41365
41059
  const named = async (element) => {
41366
41060
  const tree = await readTree(element.ref);
41367
41061
  const row = tree.elements.find(({ index }) => index === element.index);
@@ -41445,11 +41139,8 @@ const SNIPPET_LENGTH = 80;
41445
41139
  /** Elements whose text is code rather than copy. */
41446
41140
  const NOT_COPY = /* @__PURE__ */ new Set(["script", "style"]);
41447
41141
  /**
41448
- * Every hit for `query` across the shown frames of a project, in page order
41449
- * and then stacking order, matching case-insensitively against each frame's
41450
- * name, each element's name by the layers rule, and each element's own text.
41451
- * An element named by its own text hits as text alone, so it is not listed
41452
- * twice, and a frame `elementTree` refuses hits by its name alone.
41142
+ * Every case-insensitive hit across a project's shown frames, an element named
41143
+ * by its text hitting as text alone so it is listed once.
41453
41144
  */
41454
41145
  async function findInProject(root, project, query) {
41455
41146
  const { name } = await resolveProject(root, project);
@@ -41563,10 +41254,8 @@ function findRoutes(root) {
41563
41254
  }
41564
41255
  // src/server/routes/history.ts
41565
41256
  /**
41566
- * Undo and redo of the board's own writes, behind `requireWriter`. Each
41567
- * answers the page to show and the frames the step touched, and refuses with
41568
- * `undo-overtaken` when an agent changed what the step would write, or
41569
- * `frame-claimed`, keeping the step, while another session holds what it names.
41257
+ * Undo and redo of the board's own writes, keeping the step on
41258
+ * `frame-claimed` while another session holds what it names.
41570
41259
  */
41571
41260
  function historyRoutes(access, history) {
41572
41261
  const app = new Hono();
@@ -41583,6 +41272,305 @@ function historyRoutes(access, history) {
41583
41272
  app.onError(answerRefusal);
41584
41273
  return app;
41585
41274
  }
41275
+ // src/server/kits/list.ts
41276
+ const kitFileSchema = looseObject({
41277
+ version: literal(1),
41278
+ title: string$1().min(1).max(256),
41279
+ description: string$1().max(256),
41280
+ /** The frame in the kit's page a preview card renders. */
41281
+ preview: string$1().regex(NAME_PATTERN).optional()
41282
+ });
41283
+ /**
41284
+ * The folder the shipped kits are read from. A built run reads the `kits`
41285
+ * folder the build put beside the bundle, and a source run reads them where
41286
+ * they are written, beside this module.
41287
+ */
41288
+ function shippedKitsDir(moduleUrl = import.meta.url) {
41289
+ return fileURLToPath(new URL(moduleUrl.endsWith(".ts") ? "./shipped" : "./kits", moduleUrl));
41290
+ }
41291
+ /** Where a board keeps the kits saved from its projects. */
41292
+ function boardKitsDir(root) {
41293
+ return join(root, KITS_FOLDER);
41294
+ }
41295
+ /**
41296
+ * Every installable kit, shipped first, leaving out a board kit that does not
41297
+ * read or shares a shipped kit's name.
41298
+ */
41299
+ async function listKits(root, shipped = shippedKitsDir()) {
41300
+ const found = [...SHIPPED_KITS.map((name) => ({
41301
+ name,
41302
+ source: "shipped",
41303
+ path: join(shipped, name)
41304
+ })), ...(await boardKitNames(root)).filter((name) => !isShipped(name)).map((name) => ({
41305
+ name,
41306
+ source: "board",
41307
+ path: join(boardKitsDir(root), name)
41308
+ }))];
41309
+ return (await Promise.all(found.map((kit) => kit.source === "board" ? readKit(kit).catch(unreadable) : readKit(kit)))).filter((kit) => kit !== null);
41310
+ }
41311
+ /**
41312
+ * Leaves out a saved kit that does not read, such as a hand-edited
41313
+ * `kit.json` or a sample layout saved unvalidated, so one bad kit in the
41314
+ * board's folder never hides the rest. Any other failure still throws.
41315
+ */
41316
+ function unreadable(error) {
41317
+ if (error instanceof FrameboardError) return null;
41318
+ throw error;
41319
+ }
41320
+ /**
41321
+ * The kit `name` answers to, the shipped one before the board's own.
41322
+ * Refuses `kit-not-found` for a name neither holds.
41323
+ */
41324
+ function findKit(root, name, shipped = shippedKitsDir()) {
41325
+ if (isValidName(name)) {
41326
+ if (isShipped(name)) return {
41327
+ name,
41328
+ source: "shipped",
41329
+ path: join(shipped, name)
41330
+ };
41331
+ const saved = join(boardKitsDir(root), name);
41332
+ if (existsSync(join(saved, "kit.json"))) return {
41333
+ name,
41334
+ source: "board",
41335
+ path: saved
41336
+ };
41337
+ }
41338
+ throw new FrameboardError("kit-not-found", `No kit is named ${name}. Run \`frameboard kit list\` for the kits this board can install.`, { kit: name });
41339
+ }
41340
+ /**
41341
+ * Reads a kit's `kit.json` and its preview frame's size. Refuses
41342
+ * `kit-invalid` for a `kit.json` that does not read or a kit with no token
41343
+ * sheet, since installing one would leave a project with no look.
41344
+ */
41345
+ async function readKit(kit) {
41346
+ const file = await readKitFile(kit);
41347
+ return {
41348
+ name: kit.name,
41349
+ title: file.title,
41350
+ description: file.description,
41351
+ source: kit.source,
41352
+ preview: await previewOf(kit.path, file.preview)
41353
+ };
41354
+ }
41355
+ /**
41356
+ * Reads the `kit.json` of the kit folder at `kit.path`, refusing
41357
+ * `kit-invalid` as `readKit` does, for a caller holding a folder that is
41358
+ * neither shipped nor saved.
41359
+ */
41360
+ async function readKitFile(kit) {
41361
+ const file = await readRecord(join(kit.path, KIT_FILE), {
41362
+ schema: kitFileSchema,
41363
+ invalidCode: "kit-invalid"
41364
+ }).catch((error) => {
41365
+ if (!isCode(error, "ENOENT")) throw error;
41366
+ throw new FrameboardError("kit-invalid", `The kit at ${kit.path} has no ${KIT_FILE}.`, {
41367
+ kit: kit.name,
41368
+ path: kit.path
41369
+ });
41370
+ });
41371
+ if (!existsSync(join(kit.path, "tokens.css"))) throw new FrameboardError("kit-invalid", `The kit at ${kit.path} has no ${TOKEN_FILE}.`, {
41372
+ kit: kit.name,
41373
+ path: kit.path
41374
+ });
41375
+ return file;
41376
+ }
41377
+ /** The preview frame and its laid-out size, null where the kit names none or its page does not hold it. */
41378
+ async function previewOf(kitPath, frame) {
41379
+ const page = join(kitPath, "kit");
41380
+ if (frame === void 0 || !existsSync(join(page, `${frame}.html`))) return null;
41381
+ const box = (await readRecord(join(page, "layout.json"), layoutSpec)).frames[frame];
41382
+ return box ? {
41383
+ frame,
41384
+ width: box.width,
41385
+ height: box.height
41386
+ } : null;
41387
+ }
41388
+ function isShipped(name) {
41389
+ return SHIPPED_KITS.includes(name);
41390
+ }
41391
+ /** The folders in the board's kits folder holding a `kit.json`, by name. */
41392
+ async function boardKitNames(root) {
41393
+ let entries;
41394
+ try {
41395
+ entries = await readdir(boardKitsDir(root), { withFileTypes: true });
41396
+ } catch {
41397
+ return [];
41398
+ }
41399
+ return entries.filter((entry) => entry.isDirectory() && isValidName(entry.name) && existsSync(join(boardKitsDir(root), entry.name, "kit.json"))).map((entry) => entry.name).sort();
41400
+ }
41401
+ // src/server/kits/install.ts
41402
+ /**
41403
+ * Takes the project's own look out, being its `tokens.css`, its `kit` page,
41404
+ * and its `assets/kit/`, each that exists, through the journal where one is
41405
+ * given so an undo brings them back, and answers the paths taken.
41406
+ */
41407
+ async function takeOutLook(root, ref, { journal } = {}) {
41408
+ const project = await resolveProject(root, ref);
41409
+ const taken = [];
41410
+ for (const old of lookPaths(project.path)) {
41411
+ if (!existsSync(old)) continue;
41412
+ if (journal) await journal.removed(old);
41413
+ else await rm(old, { recursive: true });
41414
+ taken.push(old);
41415
+ }
41416
+ return taken;
41417
+ }
41418
+ /** The project's sheet, kit page, and kit files, the paths an install writes. */
41419
+ function lookPaths(projectPath) {
41420
+ return [
41421
+ join(projectPath, TOKEN_FILE),
41422
+ join(projectPath, "kit"),
41423
+ join(projectPath, ASSETS_FOLDER, "kit")
41424
+ ];
41425
+ }
41426
+ /**
41427
+ * Installs a kit into a project, refusing without `replace` where a sheet
41428
+ * already reaches it, so a kit never writes under a chosen look, and writing
41429
+ * nothing on any refusal.
41430
+ */
41431
+ async function installKit(root, ref, kit, { tokens, journal, replace = false } = {}) {
41432
+ const project = await resolveProject(root, ref);
41433
+ const sheet = join(project.path, TOKEN_FILE);
41434
+ const assets = join(project.path, ASSETS_FOLDER);
41435
+ const kitAssets = join(assets, "kit");
41436
+ const page = join(project.path, "kit");
41437
+ if (!replace) {
41438
+ const sheets = tokenSheetPaths(root, project.name, tokens);
41439
+ const existing = sheets.project ?? sheets.board;
41440
+ if (existing) refuseSheet(project.name, existing);
41441
+ for (const taken of [page, kitAssets]) if (existsSync(taken)) throw new FrameboardError("name-taken", `${project.name} already holds ${relative(project.path, taken)}, so no kit was installed.`, {
41442
+ project: project.name,
41443
+ path: taken
41444
+ });
41445
+ }
41446
+ await readKitFile(kit);
41447
+ if (replace) await takeOutLook(root, project.name, { journal });
41448
+ try {
41449
+ await copyFile(join(kit.path, TOKEN_FILE), sheet, constants.COPYFILE_EXCL);
41450
+ } catch (error) {
41451
+ if (isCode(error, "EEXIST")) refuseSheet(project.name, sheet);
41452
+ throw error;
41453
+ }
41454
+ await journal?.created(sheet);
41455
+ const written = [sheet];
41456
+ const assetsMade = !existsSync(assets);
41457
+ await mkdir(assets, { recursive: true });
41458
+ await cp(kit.path, kitAssets, {
41459
+ recursive: true,
41460
+ errorOnExist: true,
41461
+ force: false,
41462
+ filter: (path) => isKitAsset(kit.path, path)
41463
+ });
41464
+ await journal?.created(assetsMade ? assets : kitAssets);
41465
+ written.push(kitAssets);
41466
+ const samples = join(kit.path, "kit");
41467
+ if (existsSync(samples)) {
41468
+ await cp(samples, page, {
41469
+ recursive: true,
41470
+ errorOnExist: true,
41471
+ force: false,
41472
+ filter: (path) => isCopied(basename(path))
41473
+ });
41474
+ await journal?.created(page);
41475
+ written.push(page);
41476
+ }
41477
+ return {
41478
+ project: project.name,
41479
+ kit: kit.name,
41480
+ written
41481
+ };
41482
+ }
41483
+ /** Whether a path in the kit folder goes under `assets/kit/`, being anything but the token sheet and the sample page. */
41484
+ function isKitAsset(kitPath, path) {
41485
+ const inside = relative(kitPath, path);
41486
+ if (inside === "") return true;
41487
+ const [top = "", ...rest] = inside.split("/");
41488
+ if (rest.length === 0 && (top === "tokens.css" || top === "kit")) return false;
41489
+ return !top.startsWith(".") && isCopied(basename(path));
41490
+ }
41491
+ function refuseSheet(project, sheet) {
41492
+ throw new FrameboardError("tokens-exist", `${project} already renders with the token sheet ${sheet}, so no kit was installed.`, {
41493
+ project,
41494
+ sheet
41495
+ });
41496
+ }
41497
+ // src/server/kits/save.ts
41498
+ /**
41499
+ * Saves a project's look as a board kit, never overwriting a taken name, and
41500
+ * renamed into place, so a refusal or a failure leaves no half-written kit.
41501
+ */
41502
+ async function saveKit(root, ref, name, { tokens, journal } = {}) {
41503
+ assertValidName("kit", name);
41504
+ const project = await resolveProject(root, ref);
41505
+ const kits = boardKitsDir(root);
41506
+ const holder = matchName([...SHIPPED_KITS, ...await savedNames(kits)], name);
41507
+ if (holder) throw new FrameboardError("name-taken", `A kit named ${holder} already exists, so ${project.name} was not saved over it.`, { kit: holder });
41508
+ const sheets = tokenSheetPaths(root, project.name, tokens);
41509
+ const sheet = sheets.project ?? sheets.board;
41510
+ if (!sheet) throw new FrameboardError("tokens-not-found", `No token sheet reaches ${project.name}, so it has no look to save as a kit.`, { project: project.name });
41511
+ const path = join(kits, name);
41512
+ const staging = join(kits, `.${name}.${process.pid}.tmp`);
41513
+ await mkdir(staging, { recursive: true });
41514
+ try {
41515
+ const assets = join(project.path, ASSETS_FOLDER, "kit");
41516
+ if (existsSync(assets)) await cp(assets, staging, {
41517
+ recursive: true,
41518
+ filter: (from) => isCopied(basename(from))
41519
+ });
41520
+ await copyFile(sheet, join(staging, TOKEN_FILE));
41521
+ const samples = join(project.path, "kit");
41522
+ const frames = existsSync(samples) ? await listFrames(samples) : [];
41523
+ if (existsSync(samples)) await cp(samples, join(staging, "kit"), {
41524
+ recursive: true,
41525
+ filter: (from) => isCopied(basename(from))
41526
+ });
41527
+ const named = await installedPreview(join(staging, KIT_FILE));
41528
+ const preview = frames.find((frame) => frame === named) ?? frames[0];
41529
+ await writeFile(join(staging, KIT_FILE), `${JSON.stringify({
41530
+ version: 1,
41531
+ title: name,
41532
+ description: `Saved from ${project.name}`,
41533
+ ...preview ? { preview } : {}
41534
+ }, null, 2)}\n`);
41535
+ if (!existsSync(join(staging, "kit.md"))) await writeFile(join(staging, KIT_NOTE), stubNote(name, project.name));
41536
+ await rename(staging, path);
41537
+ } finally {
41538
+ await rm(staging, {
41539
+ recursive: true,
41540
+ force: true
41541
+ });
41542
+ }
41543
+ await journal?.created(path);
41544
+ return {
41545
+ project: project.name,
41546
+ kit: name,
41547
+ path
41548
+ };
41549
+ }
41550
+ /** The note a kit saved from a project without one carries, for the developer to fill in. */
41551
+ function stubNote(kit, project) {
41552
+ return `# ${kit}
41553
+
41554
+ Saved from the ${project} project. Describe what an agent drawing in this look reaches for, and what it keeps to.
41555
+ `;
41556
+ }
41557
+ /** The preview the `kit.json` an install left under `assets/kit/` names, if any. */
41558
+ async function installedPreview(path) {
41559
+ try {
41560
+ const parsed = JSON.parse(await readFile(path, "utf8"));
41561
+ const preview = typeof parsed === "object" && parsed !== null && "preview" in parsed ? parsed.preview : void 0;
41562
+ return typeof preview === "string" ? preview : void 0;
41563
+ } catch {
41564
+ return;
41565
+ }
41566
+ }
41567
+ async function savedNames(kits) {
41568
+ try {
41569
+ return (await readdir(kits)).filter((entry) => !entry.startsWith("."));
41570
+ } catch {
41571
+ return [];
41572
+ }
41573
+ }
41586
41574
  // src/shared/board-urls.ts
41587
41575
  /** Where the server serves a frame's file, with each name encoded as its own segment. */
41588
41576
  function frameUrl(ref) {
@@ -41612,10 +41600,8 @@ function isTheme$1(value) {
41612
41600
  return value === "light" || value === "dark";
41613
41601
  }
41614
41602
  /**
41615
- * Shows a frame's root in `theme`: `data-theme`, `color-scheme`, and the
41616
- * `.dark` or `.light` class, the selectors a token sheet reads. The frame
41617
- * route embeds this function's source in the script it injects, so it uses
41618
- * nothing from outside its own body.
41603
+ * Shows a frame's root in `theme`, using nothing outside its own body, since
41604
+ * the frame route embeds its source.
41619
41605
  */
41620
41606
  function setFrameTheme(root, theme) {
41621
41607
  root.setAttribute("data-theme", theme);
@@ -41647,22 +41633,16 @@ const BOM = [
41647
41633
  */
41648
41634
  const THEME_SCRIPT = `(function(s,t){if(t==='light'||t==='dark')(${setFrameTheme.toString()})(document.documentElement,t);s.remove()})(document.currentScript,new URLSearchParams(location.search).get(${JSON.stringify(THEME_QUERY)}))`;
41649
41635
  /**
41650
- * What the frame route puts first in a frame's `head`: one marked stylesheet
41651
- * importing `sheets` in the order given, so a later sheet overrides an
41652
- * earlier one and the frame's own sheets override them all, then the theme
41653
- * script. The stylesheet carries `hash`, the content hash of the bytes
41654
- * served, as its one other attribute, since a further injected element
41655
- * would shift every live index that forgets to skip it.
41636
+ * The frame route's injected `head`, one stylesheet carrying `hash` as its one
41637
+ * other attribute, since another element would shift every live index.
41656
41638
  */
41657
41639
  function frameHead(sheets, hash) {
41658
41640
  const imports = sheets.map((url) => `@import url(${JSON.stringify(url)});`);
41659
41641
  return `<style ${LOOK_MARKER} ${RENDERED_HASH}="${hash}">${imports.join("")}</style><script ${LOOK_MARKER}>${THEME_SCRIPT}<\/script>`;
41660
41642
  }
41661
41643
  /**
41662
- * Splices `head` into a frame's bytes where the browser starts its `head`:
41663
- * after a stated `head` start tag, else after a stated `html` start tag,
41664
- * else after the doctype, else at the start past any BOM. Every byte of the
41665
- * file stays as it was around the splice.
41644
+ * Splices `head` where the browser starts its `head`, keeping every byte of
41645
+ * the file around it.
41666
41646
  */
41667
41647
  function injectHead(bytes, head) {
41668
41648
  const offset = headOffset(bytes);
@@ -41674,10 +41654,7 @@ function injectHead(bytes, head) {
41674
41654
  return out;
41675
41655
  }
41676
41656
  /**
41677
- * The byte offset `injectHead` splices at. The bytes are decoded as Latin-1,
41678
- * one character per byte, so parse5's offsets are byte offsets, and markup
41679
- * is ASCII in either decoding. A BOM decodes as three spaces, which the
41680
- * parser skips the way a browser drops the BOM.
41657
+ * The splice offset, decoded as Latin-1 so parse5's offsets are byte offsets.
41681
41658
  */
41682
41659
  function headOffset(bytes) {
41683
41660
  const bom = BOM.every((byte, index) => bytes[index] === byte);
@@ -41695,7 +41672,7 @@ function isElement(node) {
41695
41672
  const NOTES_FILE$1 = "notes.json";
41696
41673
  /** Where the look route serves the board's token sheet, whichever file stands in for it. */
41697
41674
  const BOARD_SHEET_URL = "/frameboard/tokens.css";
41698
- const CONTENT_TYPES$1 = {
41675
+ const CONTENT_TYPES$2 = {
41699
41676
  ".html": "text/html; charset=utf-8",
41700
41677
  ".css": "text/css; charset=utf-8",
41701
41678
  ".js": "text/javascript; charset=utf-8",
@@ -41724,15 +41701,9 @@ const CONTENT_TYPES$1 = {
41724
41701
  ".m4a": "audio/mp4"
41725
41702
  };
41726
41703
  /**
41727
- * Serves `/frames/<project>/<page>/<file>`, `/frames/<project>/assets/<path>`,
41728
- * and `/frames/<project>/tokens.css` from the board, so a frame's relative
41729
- * links resolve with no rewriting. It is a handler of its own rather than
41730
- * static serving, since it must refuse board records, dot-named paths, and any
41731
- * path whose realpath leaves its project. Every refusal answers 404, so
41732
- * nothing tells a caller what exists. A frame gets the faces and token sheets
41733
- * spliced into its `head`, in the response alone and never cached. Any other
41734
- * file is served byte for byte under a validator, and `?at=<hash>` serves the
41735
- * version `version` holds. `base` prefixes the head's sheet URLs.
41704
+ * Serves the board's frames so relative links resolve unrewritten, its own
41705
+ * handler since it must refuse records, dot-named, and escaping paths, all as
41706
+ * 404 so nothing tells a caller what exists.
41736
41707
  */
41737
41708
  function frameRoutes(root, look, version, base = "") {
41738
41709
  const app = new Hono();
@@ -41742,7 +41713,7 @@ function frameRoutes(root, look, version, base = "") {
41742
41713
  if (!file) return c.notFound();
41743
41714
  const [project = "", page = "", name = ""] = parts;
41744
41715
  const isFrame = page !== "assets" && parts.length === 3 && extname(file).toLowerCase() === ".html";
41745
- const contentType = CONTENT_TYPES$1[extname(file).toLowerCase()] ?? "application/octet-stream";
41716
+ const contentType = CONTENT_TYPES$2[extname(file).toLowerCase()] ?? "application/octet-stream";
41746
41717
  const at = c.req.query("at");
41747
41718
  const rangeHeader = c.req.header("Range");
41748
41719
  if (!isFrame && at === void 0 && rangeHeader !== void 0) {
@@ -41789,7 +41760,7 @@ function frameRoutes(root, look, version, base = "") {
41789
41760
  if (held === null) return c.notFound();
41790
41761
  bytes = new TextEncoder().encode(held);
41791
41762
  }
41792
- const body = injectHead(bytes, frameHead(sheetUrls(project, look.sheets(project)).map((url) => `${base}${url}`), contentHash(bytes)));
41763
+ const body = injectHead(bytes, frameHead(sheetUrls(project, look.sheets(project), hasKit(root, project)).map((url) => `${base}${url}`), contentHash(bytes)));
41793
41764
  return c.body(body, 200, {
41794
41765
  "Content-Type": contentType,
41795
41766
  "Cache-Control": "no-store"
@@ -41813,10 +41784,8 @@ function matchesTag(header, tag) {
41813
41784
  return header.split(",").some((listed) => listed.trim().replace(/^W\//, "") === opaque);
41814
41785
  }
41815
41786
  /**
41816
- * The inclusive bytes a single `bytes=` range names within `size`,
41817
- * `'unsatisfiable'` for a valid range that names none of them, or null for a
41818
- * header to ignore, which RFC 9110 allows for any range a server does not
41819
- * support, a multi-range among them.
41787
+ * The bytes a single range names, null for a header to ignore, which RFC 9110
41788
+ * allows for an unsupported range such as a multi-range.
41820
41789
  */
41821
41790
  function parseRange(header, size) {
41822
41791
  const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
@@ -41841,14 +41810,24 @@ function parseRange(header, size) {
41841
41810
  end: Math.min(end, size - 1)
41842
41811
  };
41843
41812
  }
41844
- /** The sheets a frame imports, being every face, then the board's tokens, then the project's. */
41845
- function sheetUrls(project, sheets) {
41813
+ /**
41814
+ * The sheets a frame imports, being every face, then the board's tokens, then
41815
+ * the project's, then an installed kit's stylesheet, which reads the tokens
41816
+ * and still loses to the frame's own sheets.
41817
+ */
41818
+ function sheetUrls(project, sheets, kit) {
41819
+ const folder = `/frames/${encodeURIComponent(project)}`;
41846
41820
  return [
41847
41821
  ...FACES.map(faceSheetUrl),
41848
41822
  ...sheets.board ? [BOARD_SHEET_URL] : [],
41849
- ...sheets.project ? [`/frames/${encodeURIComponent(project)}/${TOKEN_FILE}`] : []
41823
+ ...sheets.project ? [`${folder}/${TOKEN_FILE}`] : [],
41824
+ ...kit ? [`${folder}/${ASSETS_FOLDER}/kit/${KIT_SHEET}`] : []
41850
41825
  ];
41851
41826
  }
41827
+ /** Whether a kit is installed in the project, read per request so an install reaches the next load. */
41828
+ function hasKit(root, project) {
41829
+ return existsSync(join(root, project, ASSETS_FOLDER, "kit", KIT_SHEET));
41830
+ }
41852
41831
  function decodeSegments(segments) {
41853
41832
  const decoded = [];
41854
41833
  for (const segment of segments) {
@@ -41881,10 +41860,8 @@ async function resolveFile(root, [project, page, ...rest]) {
41881
41860
  }
41882
41861
  }
41883
41862
  /**
41884
- * Whether a file the request reached is one the route may serve, read off
41885
- * where it really sits in its project rather than the name asked for, so a
41886
- * symlink in `assets/` naming a record or a dot-named path is refused as the
41887
- * name itself would be.
41863
+ * Whether the route may serve a file, read off its real path, so a symlink to
41864
+ * a record or a dot-named path is refused.
41888
41865
  */
41889
41866
  function servableInProject(segments) {
41890
41867
  if (segments.some((segment) => segment.startsWith("."))) return false;
@@ -41895,6 +41872,122 @@ function servableInProject(segments) {
41895
41872
  function isRecord$2(name) {
41896
41873
  return name === "layout.json" || name === NOTES_FILE$1;
41897
41874
  }
41875
+ // src/server/routes/kits.ts
41876
+ const name$1 = string$1().min(1).max(256);
41877
+ /**
41878
+ * A preview card's policy, running the theme script alone by hash, since a
41879
+ * saved kit's sample runs on the board's origin, and a sandbox would draw it light.
41880
+ */
41881
+ const PREVIEW_POLICY = `script-src 'sha256-${createHash("sha256").update(THEME_SCRIPT).digest("base64")}'`;
41882
+ const installSchema = object$1({
41883
+ project: name$1,
41884
+ kit: name$1,
41885
+ /** Installs over a look already there, which an undo brings back. */
41886
+ replace: boolean$1().default(false)
41887
+ });
41888
+ const saveSchema = object$1({
41889
+ project: name$1,
41890
+ name: name$1
41891
+ });
41892
+ const CONTENT_TYPES$1 = {
41893
+ ".html": "text/html; charset=utf-8",
41894
+ ".css": "text/css; charset=utf-8",
41895
+ ".svg": "image/svg+xml",
41896
+ ".png": "image/png",
41897
+ ".jpg": "image/jpeg",
41898
+ ".jpeg": "image/jpeg",
41899
+ ".webp": "image/webp",
41900
+ ".woff2": "font/woff2"
41901
+ };
41902
+ /**
41903
+ * The kit routes, each write one undo step, and a kit's files served read only
41904
+ * so a preview card renders it before any project holds it.
41905
+ */
41906
+ function kitRoutes(root, access, history, { tokens, shipped = shippedKitsDir() }) {
41907
+ const app = new Hono();
41908
+ /** Runs one write with a fresh journal and records it as a step that moves no page. */
41909
+ const recorded = async (write) => {
41910
+ const journal = history.journal();
41911
+ const result = await write(journal);
41912
+ history.record({
41913
+ id: journal.id,
41914
+ changes: journal.changes,
41915
+ page: null,
41916
+ frames: []
41917
+ });
41918
+ return result;
41919
+ };
41920
+ app.get("/api/kits", async (c) => c.json({
41921
+ ok: true,
41922
+ data: await listKits(root, shipped)
41923
+ }));
41924
+ app.post("/api/kits/install", requireWriter(access), async (c) => {
41925
+ const body = await parseBody$1(c.req.raw, installSchema);
41926
+ const kit = findKit(root, body.kit, shipped);
41927
+ if (body.replace) {
41928
+ await readKitFile(kit);
41929
+ await recorded((journal) => takeOutLook(root, body.project, { journal }));
41930
+ }
41931
+ const installed = await recorded((journal) => installKit(root, body.project, kit, {
41932
+ tokens,
41933
+ journal,
41934
+ replace: body.replace
41935
+ }));
41936
+ return c.json({
41937
+ ok: true,
41938
+ data: installed
41939
+ });
41940
+ });
41941
+ app.post("/api/kits/save", requireWriter(access), async (c) => {
41942
+ const body = await parseBody$1(c.req.raw, saveSchema);
41943
+ const saved = await recorded((journal) => saveKit(root, body.project, body.name, {
41944
+ tokens,
41945
+ journal
41946
+ }));
41947
+ return c.json({
41948
+ ok: true,
41949
+ data: saved
41950
+ });
41951
+ });
41952
+ app.get(`${KITS_URL}/*`, async (c) => {
41953
+ const [kitName, ...rest] = decodeSegments(new URL(c.req.url).pathname.slice(17).split("/")) ?? [];
41954
+ if (!kitName || rest.length === 0) return c.notFound();
41955
+ let kitPath;
41956
+ try {
41957
+ kitPath = findKit(root, kitName, shipped).path;
41958
+ } catch {
41959
+ return c.notFound();
41960
+ }
41961
+ const file = await resolveInside(kitPath, rest);
41962
+ const type = file && CONTENT_TYPES$1[extname(file).toLowerCase()];
41963
+ if (!file || !type) return c.notFound();
41964
+ const bytes = new Uint8Array(await readFile(file));
41965
+ const isSample = rest.length === 2 && rest[0] === "kit" && extname(file).toLowerCase() === ".html";
41966
+ const body = isSample ? injectHead(bytes, frameHead([
41967
+ ...FACES.map(faceSheetUrl),
41968
+ `${KITS_URL}/${encodeURIComponent(kitName)}/${TOKEN_FILE}`,
41969
+ `${KITS_URL}/${encodeURIComponent(kitName)}/${KIT_SHEET}`
41970
+ ], contentHash(bytes))) : bytes;
41971
+ return c.body(body, 200, {
41972
+ "Content-Type": type,
41973
+ "Cache-Control": "no-store",
41974
+ ...isSample ? { "Content-Security-Policy": PREVIEW_POLICY } : {}
41975
+ });
41976
+ });
41977
+ app.onError(answerRefusal);
41978
+ return app;
41979
+ }
41980
+ /** The realpath of a file inside the kit folder, or null for a missing file or one that leaves it. */
41981
+ async function resolveInside(kitPath, segments) {
41982
+ try {
41983
+ const dir = await realpath(kitPath);
41984
+ const file = await realpath(join(dir, ...segments));
41985
+ if (!file.startsWith(dir + sep)) return null;
41986
+ return (await stat(file)).isFile() ? file : null;
41987
+ } catch {
41988
+ return null;
41989
+ }
41990
+ }
41898
41991
  // src/server/routes/look.ts
41899
41992
  /** The answer for faces under the running release, whose bytes a release fixes. */
41900
41993
  const IMMUTABLE = "public, max-age=31536000, immutable";
@@ -41905,13 +41998,8 @@ const CONTENT_TYPES = {
41905
41998
  ".woff2": "font/woff2"
41906
41999
  };
41907
42000
  /**
41908
- * The look routes and the frame routes over `root`, so the board server and
41909
- * the capture host serve a frame the same way. `tokens` is a known
41910
- * `--tokens` sheet, null for none, or absent to read the one a running
41911
- * server recorded in the address file on each request. `version` serves the
41912
- * frame versions an agent write replaced, absent where nothing holds them.
41913
- * `base` prefixes the sheet URLs a served frame imports, for a listener that
41914
- * serves these routes under a path of its own.
42001
+ * The look and frame routes, so the board server and the capture host serve a
42002
+ * frame the same way.
41915
42003
  */
41916
42004
  function servedFrames(root, { facesDir, tokens, version, base }) {
41917
42005
  const look = { sheets: (project) => tokenSheetPaths(root, project, tokens) };
@@ -41927,15 +42015,9 @@ function servedFrames(root, { facesDir, tokens, version, base }) {
41927
42015
  };
41928
42016
  }
41929
42017
  /**
41930
- * Serves what every frame imports from outside the board: the faces under
41931
- * `/frameboard/faces/*` and the board sheet at `/frameboard/tokens.css`.
41932
- * The board sheet is never cached, so a changed sheet reaches a frame on its
41933
- * reload. The faces under the running release's segment, as
41934
- * `/frameboard/faces/v0.29.0/geist/index.css`, are cached for good, since
41935
- * only a release changes them, and any other release segment answers 404 so
41936
- * a stale URL never caches today's bytes. The bare faces path stays
41937
- * uncached for anything naming it. A dot-named or escaping path answers 404,
41938
- * as the frame route does.
42018
+ * Serves the faces and board sheet, the sheet never cached and faces cached
42019
+ * for good under the release's segment, another release answering 404 so a
42020
+ * stale URL never caches today's bytes.
41939
42021
  */
41940
42022
  function lookRoutes({ facesDir, boardSheet }) {
41941
42023
  const app = new Hono();
@@ -41988,18 +42070,13 @@ async function readOrNull(path) {
41988
42070
  const DISPATCH_ENV = "FRAMEBOARD_DISPATCH";
41989
42071
  const DISPATCH_LOG = "dispatch.log";
41990
42072
  /**
41991
- * How long a command has to fail before it counts as started. A command that
41992
- * backgrounds its session and exits 0, as `claude --bg` does, counts at once.
41993
- * `claude --bg` refusing an untrusted folder exits 1 near 700 ms, so the
41994
- * window sits well past that.
42073
+ * How long a command has to fail before it counts as started, well past the
42074
+ * 700 ms `claude --bg` takes to refuse an untrusted folder.
41995
42075
  */
41996
42076
  const START_WINDOW_MS = 2e3;
41997
42077
  /**
41998
- * Starts a session for a note by running the developer's command detached,
41999
- * its output appended to `.run/dispatch.log`. The note reaches the command as
42000
- * environment variables alone, never spliced into the command string, so its
42001
- * text is data to the shell. Resolves once the command exits 0 or outlives
42002
- * the window, and refuses `dispatch-failed` when it exits otherwise inside it.
42078
+ * Starts a session for a note by running the developer's command detached, the
42079
+ * note reaching it as environment variables alone, so its text is data to the shell.
42003
42080
  */
42004
42081
  function createDispatcher({ command, cwd, root, env, windowMs = START_WINDOW_MS }) {
42005
42082
  return async ({ session, id, line }) => {
@@ -42165,14 +42242,8 @@ const sendSchema = object$1({
42165
42242
  dispatch
42166
42243
  }).refine((body) => body.to === void 0 !== (body.dispatch === void 0), { message: "names a session to send to or asks to start one" });
42167
42244
  /**
42168
- * The board's note writes, each behind `requireWriter`: pin a note, reply in
42169
- * its thread, send it to a listening session, and mark it done. Each answers
42170
- * the CLI's `{ ok, data }` envelope, and a refusal its `{ ok, error }`. Pin,
42171
- * reply, and send take `dispatch: true` in place of `to`, which starts a
42172
- * session through `dispatch` and marks the thread's root delivered to it, and
42173
- * a failed start takes back the message the request added. Images go up first
42174
- * to `/api/notes/images`, and `/api/note-images/...` reads one back with no
42175
- * writer check, since an `<img>` sends no `Origin`.
42245
+ * The board's note writes, a failed dispatch taking back the message it added,
42246
+ * and image reads taking no writer check, since an `<img>` sends no `Origin`.
42176
42247
  */
42177
42248
  function notesRoutes(root, access, delivery, dispatch, imageLimit = ASSET_BODY_LIMIT) {
42178
42249
  const app = new Hono();
@@ -42188,10 +42259,6 @@ function notesRoutes(root, access, delivery, dispatch, imageLimit = ASSET_BODY_L
42188
42259
  if (!dispatch) throw new FrameboardError("dispatch-unavailable", `No session can be started, since serve was started without ${DISPATCH_ENV}.`);
42189
42260
  return dispatch;
42190
42261
  };
42191
- /**
42192
- * Starts a session on a thread already on disk, then hands the root to it
42193
- * as delivered, answering the note `answer` names.
42194
- */
42195
42262
  const startSession = async (run, place, rootId, added, answer) => {
42196
42263
  const minted = randomUUID();
42197
42264
  try {
@@ -42365,15 +42432,8 @@ const STATUS = {
42365
42432
  /** The route's scale when none is asked for, matching Copy as PNG. */
42366
42433
  const DEFAULT_SCALE = 2;
42367
42434
  /**
42368
- * `GET /api/frames/png?ref=<frame-ref>&theme=<light|dark>&scale=<1|2|3>`, a
42369
- * frame rendered at `scale` times its layout size, twice when none is given.
42370
- * Three additions each change what is drawn and exclude each other, each
42371
- * refusing as `usage`: `filmstrip=<n>` renders `n` moments of the timeline in
42372
- * one row, `device=1` draws a frame's device inside its body, and
42373
- * `element=<index>&hash=<hash>` renders that one element alone on a
42374
- * transparent ground, refusing a moved file as 409 `stale-address`. It takes
42375
- * no token, since the image shows only what the frame route already serves,
42376
- * and a refusal answers the CLI's `{ ok, error }` envelope.
42435
+ * `GET /api/frames/png`, its filmstrip, device, and element options exclusive,
42436
+ * taking no token, since the image shows only what the frame route serves.
42377
42437
  */
42378
42438
  function pngRoutes(root, render, renderFilmstrip) {
42379
42439
  const app = new Hono();
@@ -42498,12 +42558,8 @@ const StartBody = object$1({
42498
42558
  });
42499
42559
  const StopBody = object$1({ token: string$1().min(1).optional() });
42500
42560
  /**
42501
- * `POST /api/preview` with `{ ref, port? }` starts the phone listener for the
42502
- * frame's project and answers the link landing on that frame, ending any
42503
- * link already open. `DELETE /api/preview` with `{ token? }` ends it, or only
42504
- * the listener holding `token`. Both sit behind `requireWriter`, since a
42505
- * start opens a port to the local network. A machine with no local network
42506
- * address refuses `no-network-address` and starts nothing.
42561
+ * Starts and ends the phone listener behind `requireWriter`, since a start
42562
+ * opens a port to the local network.
42507
42563
  */
42508
42564
  function previewRoutes(root, access, slot, { address = networkAddress } = {}) {
42509
42565
  const app = new Hono();
@@ -42575,10 +42631,8 @@ async function holdFrames(root, refs, options) {
42575
42631
  })));
42576
42632
  }
42577
42633
  /**
42578
- * Writes held frames onto a page as new files on top of its stack, each
42579
- * taking the next free name so nothing on the page is overwritten. Without
42580
- * `at`, a frame keeps its box on another page and lands beside its source
42581
- * on its own, the way `duplicateFrame` places a copy.
42634
+ * Writes held frames onto a page under free names, so nothing is overwritten,
42635
+ * placed as `duplicateFrame` places a copy without `at`.
42582
42636
  */
42583
42637
  async function pasteFrames(root, pageRef, held, options) {
42584
42638
  const { journal, at } = options;
@@ -42689,6 +42743,78 @@ async function sectionRecord(root, page, name) {
42689
42743
  if (!section) throw new Error(`Section ${name} vanished from ${page.name}.`);
42690
42744
  return section;
42691
42745
  }
42746
+ // src/shared/bindings.ts
42747
+ /**
42748
+ * The drawn controls contract, `data-binds="<selector> <--custom-property>"`
42749
+ * on an input, so the frame holds no script and a kept value is plain CSS.
42750
+ */
42751
+ const BINDS_ATTRIBUTE = "data-binds";
42752
+ const UNIT_ATTRIBUTE = "data-unit";
42753
+ /**
42754
+ * A `data-binds` value read as its last word, the property, after a
42755
+ * selector that may itself hold spaces, as `.card img --blur` does. Null
42756
+ * when it holds fewer than two words.
42757
+ */
42758
+ function parseBinds(value) {
42759
+ const words = value.trim().split(/\s+/);
42760
+ const property = words.pop();
42761
+ const selector = words.join(" ");
42762
+ if (!property || selector === "") return null;
42763
+ return {
42764
+ selector,
42765
+ property
42766
+ };
42767
+ }
42768
+ /** Whether a property is a custom property, the one kind a control may set. */
42769
+ function isCustomProperty(property) {
42770
+ return /^--./.test(property);
42771
+ }
42772
+ /**
42773
+ * Hides every control wherever a frame leaves the canvas, so the design ships
42774
+ * as if the controls were never drawn.
42775
+ */
42776
+ const HIDE_CONTROLS_CSS = `[${BINDS_ATTRIBUTE}], label:has([${BINDS_ATTRIBUTE}]), :not(html, body):has(> [${BINDS_ATTRIBUTE}], > label > [${BINDS_ATTRIBUTE}]):not(:has(> :not([${BINDS_ATTRIBUTE}], label))) { display: none !important }`;
42777
+ // src/server/checks/bindings.ts
42778
+ const BINDING_RULES = [{
42779
+ id: "binding-target",
42780
+ tier: "exact",
42781
+ severity: "warning",
42782
+ description: "A control's data-binds names a selector matching an element in its frame, then a custom property opening with \"--\""
42783
+ }];
42784
+ const finding$12 = findingFor(BINDING_RULES);
42785
+ /**
42786
+ * `binding-target`, one finding per control whose `data-binds` tunes nothing,
42787
+ * a warning since the frame still renders.
42788
+ */
42789
+ function checkBindings(source) {
42790
+ const path = boardPath(source.root, source.path);
42791
+ return source.elements.flatMap((element) => {
42792
+ const value = element.attribs[BINDS_ATTRIBUTE];
42793
+ if (value === void 0) return [];
42794
+ const problem = problemOf(value, source);
42795
+ if (problem === null) return [];
42796
+ return [finding$12("binding-target", {
42797
+ frame: source.ref,
42798
+ path,
42799
+ location: attributeLocation(element, BINDS_ATTRIBUTE),
42800
+ message: `${BINDS_ATTRIBUTE}="${value}" ${problem}`
42801
+ })];
42802
+ });
42803
+ }
42804
+ function problemOf(value, source) {
42805
+ const binding = parseBinds(value);
42806
+ if (binding === null) return "needs a selector and then a custom property, as \"#photo --brightness\".";
42807
+ const { selector, property } = binding;
42808
+ if (!isCustomProperty(property)) return `sets ${property}, which is not a custom property. Name one opening with "--" that the target's CSS reads.`;
42809
+ let target;
42810
+ try {
42811
+ target = selectOne(selector, source.document);
42812
+ } catch {
42813
+ return `names ${selector}, which does not parse as a selector. Point it at the element the control tunes.`;
42814
+ }
42815
+ if (target === null) return `matches no element. Point it at the element the control tunes, or remove it.`;
42816
+ return null;
42817
+ }
42692
42818
  // src/server/checks/board-routes.ts
42693
42819
  const BOARD_ROUTE_RULES = [{
42694
42820
  id: "board-route",
@@ -42698,10 +42824,8 @@ const BOARD_ROUTE_RULES = [{
42698
42824
  }];
42699
42825
  const finding$11 = findingFor(BOARD_ROUTE_RULES);
42700
42826
  /**
42701
- * A quoted string or template literal opening on `/api/`, bare or after a
42702
- * scheme and host, so a URL in code matches and prose in a comment does not.
42703
- * A path the script builds at runtime, such as `'/ap' + 'i/'`, passes, since
42704
- * the rule catches a mistake rather than a deliberate call.
42827
+ * A quoted `/api/` path, so prose in a comment does not match, while a path
42828
+ * built at runtime passes, since the rule catches mistakes, not deliberate calls.
42705
42829
  */
42706
42830
  const BOARD_ROUTE = /(['"`])((?:(?:[a-z][a-z0-9+.-]*:)?\/\/[^/'"`\s]*)?\/api\/[^'"`\n]*)\1/gi;
42707
42831
  /**
@@ -42968,11 +43092,8 @@ const FOREIGN_PREFIX = /^-(moz|ms|o)-/i;
42968
43092
  /** The one engine prefix the board renders, which a build tool writes beside the standard property as a fallback. */
42969
43093
  const FALLBACK_PREFIX = /^-webkit-/i;
42970
43094
  /**
42971
- * `dropped-declaration`, one finding per declaration in the frame's own
42972
- * sheets and style attributes that the open page's `CSS.supports` refuses,
42973
- * and one per sheet postcss cannot parse, at the break it stops on, checking
42974
- * the declarations ahead of the break. Theme
42975
- * plays no part, so a caller runs it on one theme's page.
43095
+ * `dropped-declaration`, one finding per declaration `CSS.supports` refuses and
43096
+ * per unparsable sheet, run on one theme's page since theme plays no part.
42976
43097
  */
42977
43098
  async function checkDeclarations(page, source) {
42978
43099
  const findings = [];
@@ -43112,14 +43233,9 @@ function filmstripWidth(frameWidth, count) {
43112
43233
  }
43113
43234
  // src/server/capture/animation-settle.ts
43114
43235
  /**
43115
- * Waits, within `timeoutMs`, until every running animation and transition
43116
- * with a finite end has finished, reading again after each round so one that
43117
- * another starts is awaited too. An infinite animation is never awaited, and
43118
- * running out of time returns rather than refusing, since a long or
43119
- * restarting animation is a design and not a failure.
43120
- *
43121
- * It sees only what `document.getAnimations()` lists, so a scene a script
43122
- * steps on a timer stays out of reach.
43236
+ * Waits out every finite animation, returning rather than refusing at the
43237
+ * limit, since a long animation is a design, and seeing only what
43238
+ * `document.getAnimations()` lists.
43123
43239
  */
43124
43240
  async function settleAnimations(page, timeoutMs) {
43125
43241
  if (timeoutMs <= 0) return;
@@ -43144,11 +43260,8 @@ async function waitForAnimations(timeoutMs) {
43144
43260
  }
43145
43261
  // src/server/capture/element-shot.ts
43146
43262
  /**
43147
- * Leaves one element of a loaded frame showing alone on a transparent
43148
- * ground, and answers its box in page coordinates, which can run past the
43149
- * frame's. `index` is the element's `edit` index, the one `inspect` reports.
43150
- * An index naming no element, or one with no layout box or a box of no
43151
- * width or height, refuses `invalid-address`. The page stays that way, so it is shot once and closed.
43263
+ * Leaves one element showing alone on a transparent ground, answering its box,
43264
+ * which can run past the frame's, so the page is shot once and closed.
43152
43265
  */
43153
43266
  async function isolateElement(page, ref, index) {
43154
43267
  const isolated = await page.evaluate(hideAllBut, index);
@@ -43233,13 +43346,8 @@ function parseFontFamilies(fontFamily) {
43233
43346
  return families.filter((family) => family !== "");
43234
43347
  }
43235
43348
  /**
43236
- * The family a text element asks for, being the first in its stack, or null
43237
- * when that one is generic or is the browser's own default. Later families
43238
- * are fallbacks the author chose, so they are never looked for.
43239
- *
43240
- * The default is what a frame declaring no font computes to, such as "Times
43241
- * New Roman" in the Linux headless shell, where it is not installed. A frame
43242
- * naming that family on purpose is skipped too, since a computed style cannot
43349
+ * The first family in a stack, null when generic or the browser's default,
43350
+ * which a frame naming it on purpose also hits, since a computed style cannot
43243
43351
  * tell the two apart.
43244
43352
  */
43245
43353
  function requestedFamily(fontFamily, defaultFamily) {
@@ -43345,13 +43453,9 @@ async function platformFamilies(page, domIndexes) {
43345
43453
  }
43346
43454
  // src/server/capture/image-loads.ts
43347
43455
  /**
43348
- * Waits, within `timeoutMs`, until every `<img>` in the frame has loaded and
43349
- * decoded, so an image marked `decoding="async"` never shoots as an empty
43350
- * box. A lazy image is made eager in the loaded page first, never in the
43351
- * file. Under `require` an image that errored or is still loading at the
43352
- * deadline refuses `image-missing`, and under `wait` the frame opens as the
43353
- * board shows it. `stalled` reads a page whose load event never fired, and
43354
- * refuses only for an image that failed or whose request is still open.
43456
+ * Waits until every `<img>` decodes, so an async image never shoots empty,
43457
+ * making lazy ones eager in the page alone. Under `require` a failed or
43458
+ * unfinished image refuses `image-missing`.
43355
43459
  */
43356
43460
  async function settleImages(page, ref, mode, timeoutMs, { stalled = false } = {}) {
43357
43461
  const unsettled = await page.evaluate(waitForImages, Math.max(0, timeoutMs));
@@ -43412,13 +43516,8 @@ async function waitForImages(timeoutMs) {
43412
43516
  }
43413
43517
  // src/shared/motion.ts
43414
43518
  /**
43415
- * Finds the timeline a page's motion runs on, taking `__hf` alone when
43416
- * present, else every `__timelines` entry, else the page's animations, and
43417
- * resolves null when none registers within `timeoutMs`.
43418
- *
43419
- * Capture evaluates this in a page by its source text and the board calls it
43420
- * on an iframe's window, so it reads nothing outside its own body and takes
43421
- * its clock, frames, and document from `view`, never the caller's realm.
43519
+ * Finds a page's motion timeline. Capture evaluates it by source text, so it
43520
+ * reads nothing outside its own body and takes everything from `view`.
43422
43521
  */
43423
43522
  async function readMotionIn(view, timeoutMs) {
43424
43523
  const end = view.performance.now() + timeoutMs;
@@ -43458,10 +43557,8 @@ async function readMotionIn(view, timeoutMs) {
43458
43557
  }
43459
43558
  }
43460
43559
  /**
43461
- * Holds the page at `ms`, clamped to the timeline's end, and resolves with
43462
- * the moment it holds once a frame has painted it. HyperFrames and GSAP take
43463
- * seconds, and the conversion happens here alone. Self-contained for the
43464
- * same reason as `readMotionIn`.
43560
+ * Holds the page at `ms` once painted, converting to the seconds HyperFrames
43561
+ * and GSAP take here alone, self-contained as `readMotionIn` is.
43465
43562
  */
43466
43563
  async function holdMotionIn(view, { motion, ms }) {
43467
43564
  const at = motion.duration === null ? ms : Math.min(Math.max(ms, 0), motion.duration);
@@ -43495,10 +43592,8 @@ function filmstripMoments(ref, motion, count) {
43495
43592
  }
43496
43593
  // src/server/capture/seek.ts
43497
43594
  /**
43498
- * Stops the page's animation clock, through the DevTools Animation domain,
43499
- * before the page loads. A CSS animation with no fill that ended during the
43500
- * load would otherwise drop out of `document.getAnimations()` before the seek
43501
- * reads it. Script timelines run on their own clocks and keep running.
43595
+ * Stops the animation clock before load, since an unfilled CSS animation
43596
+ * ending mid-load would drop out of `getAnimations()` before the seek.
43502
43597
  */
43503
43598
  async function holdAnimationClock(page) {
43504
43599
  const session = await page.context().newCDPSession(page);
@@ -43506,11 +43601,8 @@ async function holdAnimationClock(page) {
43506
43601
  await session.send("Animation.setPlaybackRate", { playbackRate: 0 });
43507
43602
  }
43508
43603
  /**
43509
- * Finds the timeline a frame's motion runs on, taking `window.__hf` alone
43510
- * when present, else every `window.__timelines` entry, else the page's
43511
- * animations. A script loading its timeline late gets until `timeoutMs` to
43512
- * register one, and a frame showing none by then refuses `motion-missing`,
43513
- * since a scene stepped by a script timer cannot be held at a moment.
43604
+ * Finds the frame's timeline, refusing `motion-missing` when none registers by
43605
+ * `timeoutMs`, since a script-timer scene cannot be held at a moment.
43514
43606
  */
43515
43607
  async function findMotion(page, ref, timeoutMs) {
43516
43608
  const found = await page.evaluate(inPage(readMotionIn, timeoutMs));
@@ -43537,14 +43629,9 @@ function inPage(run, arg) {
43537
43629
  }
43538
43630
  // src/server/capture/video-loads.ts
43539
43631
  /**
43540
- * Waits, within `timeoutMs`, until every `<video>` in the frame holds a
43541
- * picture, and holds each one still on it, so two captures of one frame match.
43542
- * A video with a poster that loads rests on the poster, and any other on its
43543
- * first frame, paused. Autoplay is dropped and a `preload="none"` video is
43544
- * made to load in the loaded page, never in the file.
43545
- *
43546
- * Returns the videos with no picture when the time ran out and never refuses,
43547
- * since a clip the capture browser cannot decode is no fault of the frame.
43632
+ * Holds every `<video>` still on its poster or first frame, so two captures
43633
+ * match, returning rather than refusing the ones with no picture, since an
43634
+ * undecodable clip is no fault of the frame.
43548
43635
  */
43549
43636
  async function settleVideos(page, timeoutMs) {
43550
43637
  return page.evaluate(waitForVideos, Math.max(0, timeoutMs));
@@ -43641,15 +43728,9 @@ async function waitForVideos(timeoutMs) {
43641
43728
  /** How long a frame has to load, its faces and images included, before its capture fails. */
43642
43729
  const LOAD_TIMEOUT_MS = 1e4;
43643
43730
  /**
43644
- * Loads a frame in its own browser context at its layout size, in the theme
43645
- * asked for, and resolves once it has loaded, its faces have settled, and its
43646
- * images have decoded, all inside one load budget. Under `fonts: 'require'`,
43647
- * the default, a missing face refuses `font-missing`, an image that failed or
43648
- * outran the budget refuses `image-missing`, and either closes the context.
43649
- * Each video is then held on its poster or first frame, and one with no
43650
- * picture by the end of the budget is returned rather than refused.
43651
- * It then waits, on what is left of the budget, for running animations with
43652
- * a finite end to finish, and never refuses for one, unless `motion` is `hold`.
43731
+ * Loads a frame within one budget for faces, images, and videos, then settles
43732
+ * finite animations. A missing face or image refuses, while an unloaded video
43733
+ * is returned rather than refused.
43653
43734
  */
43654
43735
  async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts = "require", timeoutMs = LOAD_TIMEOUT_MS, motion = "settle" }) {
43655
43736
  const context = await browser.newContext({
@@ -43706,10 +43787,8 @@ function assertScreenshotFits(ref, box, scale) {
43706
43787
  });
43707
43788
  }
43708
43789
  /**
43709
- * One browser kept warm for a server and shared by everything rendering on
43710
- * it, so the server holds one Chromium. A launch that fails is not kept, so a
43711
- * browser installed later is found on the next call, and every call after
43712
- * `close` refuses.
43790
+ * One warm browser shared by everything rendering, a failed launch not kept so
43791
+ * a browser installed later is found on the next call.
43713
43792
  */
43714
43793
  function createWarmBrowser(launch) {
43715
43794
  let browser = null;
@@ -43757,6 +43836,7 @@ function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
43757
43836
  });
43758
43837
  let shot;
43759
43838
  try {
43839
+ await hideControls(opened.page);
43760
43840
  shot = element === void 0 ? await opened.page.screenshot({
43761
43841
  animations: "disabled",
43762
43842
  caret: "hide"
@@ -43770,6 +43850,22 @@ function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
43770
43850
  return run;
43771
43851
  };
43772
43852
  }
43853
+ /**
43854
+ * Hides every drawn control, so an export or a thumbnail shows the design
43855
+ * alone. The style is marked as the board's own, so an element export's
43856
+ * index still counts the file's elements.
43857
+ */
43858
+ async function hideControls(page) {
43859
+ await page.evaluate(({ css, marker }) => {
43860
+ const style = document.createElement("style");
43861
+ style.setAttribute(marker, "");
43862
+ style.textContent = css;
43863
+ document.head.append(style);
43864
+ }, {
43865
+ css: HIDE_CONTROLS_CSS,
43866
+ marker: LOOK_MARKER
43867
+ });
43868
+ }
43773
43869
  /** One element's shot alone on a transparent ground, at its whole box. */
43774
43870
  async function shootElement(page, ref, index, scale) {
43775
43871
  const box = await isolateElement(page, ref, index);
@@ -43830,14 +43926,9 @@ function pill(width, height, color) {
43830
43926
  /** The widest a hugging width grows, past which the layout check reports the content clipped. */
43831
43927
  const HUG_MAX_WIDTH = FRAME_SIZES.desktop.width;
43832
43928
  /**
43833
- * Measures a frame's content the way `frame fit` and the server's hug step
43834
- * both read it, in one page resized between readings. A hugging width takes
43835
- * the content's `fit-content` width up to `HUG_MAX_WIDTH`, and the height is
43836
- * read at that width with a 1 px tall viewport and again at the reference
43837
- * height, never the box's own, so content sized off the window height reads
43838
- * one height however tall the frame already is. Readings that differ, or a
43839
- * fresh page drawing another height, mean the content sizes itself off the
43840
- * viewport and refuse `fit-unbounded`. Finite animations finish first.
43929
+ * Measures content as `frame fit` and the hug step read it, the height at a
43930
+ * 1 px viewport and at the reference height, never the box's own. Readings that
43931
+ * differ mean the content sizes off the viewport and refuse `fit-unbounded`.
43841
43932
  */
43842
43933
  async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
43843
43934
  const reference = referenceHeight(box.width);
@@ -43902,10 +43993,8 @@ async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
43902
43993
  return size;
43903
43994
  }
43904
43995
  /**
43905
- * Reads a frame's content in a page loaded fresh at `box`, animations
43906
- * finished. It loads under `fonts: 'wait'` whatever the first open took, since
43907
- * that open already refused a missing face or image, and `require` would wait
43908
- * out a long entrance a second time on the load budget.
43996
+ * Reads content in a fresh page at `box` under `fonts: 'wait'`, since the
43997
+ * first open already refused a missing face and `require` would wait twice.
43909
43998
  */
43910
43999
  async function readFreshAt(browser, options) {
43911
44000
  const opened = await openFrame(browser, {
@@ -43921,10 +44010,8 @@ async function readFreshAt(browser, options) {
43921
44010
  }
43922
44011
  }
43923
44012
  /**
43924
- * Sets a frame's height to its content's own height at its layout width and
43925
- * turns its height hugging on, measuring each linked width at its own width
43926
- * and writing its height beside the frame's. The width is reported, never
43927
- * changed.
44013
+ * Sets a frame's height to its content's and hugs it, measuring each linked
44014
+ * width too, reporting the width and never changing it.
43928
44015
  */
43929
44016
  async function fitFrame(browser, { baseUrl, frame, ...options }) {
43930
44017
  const measured = await measureContent(browser, {
@@ -44094,11 +44181,8 @@ const finding$7 = findingFor(LAYOUT_RULES);
44094
44181
  */
44095
44182
  const SLACK_PX = 1;
44096
44183
  /**
44097
- * Runs the three layout rules on a frame open at its own box, at most one
44098
- * finding each. `viewport` reads a second time with the viewport twice as
44099
- * tall, then puts the box back. Each resize settles before the next read, so
44100
- * a script sizing content on `resize` reads as the CSS case does, and the
44101
- * rules after this one see the page back at its box.
44184
+ * Runs the three layout rules, `viewport` re-reading at twice the height, each
44185
+ * resize settling first so a `resize` script reads as the CSS case does.
44102
44186
  */
44103
44187
  async function checkLayout(page, target) {
44104
44188
  const { width, height } = target.box;
@@ -44295,11 +44379,8 @@ const SCROLL_EFFECT_RULES = [{
44295
44379
  }];
44296
44380
  const finding$6 = findingFor(SCROLL_EFFECT_RULES);
44297
44381
  /**
44298
- * `scroll-effect`, at most one finding, on a frame that hugs its height and
44299
- * holds no `scroll` key, naming the first trigger found. A listener counts
44300
- * only on the window or the document, since those are the objects the
44301
- * DevTools protocol is asked about, so one on an inner scroll container or an
44302
- * observer driving the effect goes unseen and costs a hint, never an error.
44382
+ * `scroll-effect`, at most one finding on a hugging frame, counting listeners
44383
+ * on the window or document alone, so a missed one costs a hint, never an error.
44303
44384
  */
44304
44385
  async function checkScrollEffect(page, target) {
44305
44386
  if (target.scroll || !target.hugHeight) return [];
@@ -44383,21 +44464,14 @@ const finding$5 = findingFor(CUSTOM_PROPERTY_RULES);
44383
44464
  /** A `var()` naming its property, with no fallback after a comma. */
44384
44465
  const BARE_VAR = /var\(\s*(--[\w-]+)\s*\)/g;
44385
44466
  /**
44386
- * The two ways a script writes a custom property by a name it spells out:
44387
- * `setProperty('--name', …)`, and a `--name:` declaration in a string it
44388
- * hands a style attribute or `cssText`. A read such as `getPropertyValue`
44389
- * matches neither, so it still reports.
44467
+ * The two ways a script writes a spelled-out custom property, so a read such
44468
+ * as `getPropertyValue` still reports.
44390
44469
  */
44391
44470
  const SCRIPT_WRITES = [/\.setProperty\(\s*(['"`])(--[\w-]+)\1/g, /(?<![\w-])(--[\w-]+)\s*:/g];
44392
44471
  /**
44393
- * `unknown-token`, one finding per bare `var()` in the frame's own sheets
44394
- * and style attributes whose name nothing declares. A token sheet's own
44395
- * references are the board's to answer for, so only its declarations count.
44396
- * A name a `<script>` writes counts as declared, read off its text since the
44397
- * check never runs it, so a name the script builds at runtime still reports.
44398
- * A linked sheet's rule matching no element in the frame stays quiet, since a
44399
- * site sheet styles other pages. The frame's own `<style>` keeps reporting,
44400
- * since its theme and state rules match elements no static tree marks.
44472
+ * `unknown-token`, per bare `var()` nothing declares, a script's spelled-out
44473
+ * writes counting as declared. A linked sheet's unmatched rule stays quiet,
44474
+ * since a site sheet styles other pages.
44401
44475
  */
44402
44476
  function checkUnknownTokens(source, tokens) {
44403
44477
  const declared = /* @__PURE__ */ new Set();
@@ -44892,10 +44966,8 @@ function checkMalformedTags(source) {
44892
44966
  return findings;
44893
44967
  }
44894
44968
  /**
44895
- * `nesting`, one finding per element the parser rebuilt: one it implied with
44896
- * no start tag, an HTML element whose end tag never matched, and one moved
44897
- * ahead of a sibling the file writes first, which is a table's foster
44898
- * parenting. Foreign elements are left to close themselves.
44969
+ * `nesting`, one finding per element the parser rebuilt, leaving foreign
44970
+ * elements to close themselves.
44899
44971
  */
44900
44972
  function checkNesting(source) {
44901
44973
  const path = boardPath(source.root, source.path);
@@ -45002,6 +45074,7 @@ function checkFrameIn(target, { config, tokens }) {
45002
45074
  ...checkNesting(source),
45003
45075
  ...checkLinks(source),
45004
45076
  ...checkBoardRoutes(source),
45077
+ ...checkBindings(source),
45005
45078
  ...checkFonts(source, cascade, config),
45006
45079
  ...checkTheme(source),
45007
45080
  ...checkUnknownTokens(source, tokens),
@@ -45020,11 +45093,8 @@ function readProjectContext(root, project, boardSheet) {
45020
45093
  };
45021
45094
  }
45022
45095
  /**
45023
- * The project's `checks` config, read by hand rather than through the
45024
- * project record's schema, which the hook cannot afford to load. A file that
45025
- * does not read, or a key of the wrong type, leaves that rule off, and an
45026
- * `off` that is not a list of ids turns nothing off. The server's browser
45027
- * checker reads it too, for `minFontSize`, `minContrast`, and `off`.
45096
+ * The project's `checks` config, read by hand since the hook cannot afford the
45097
+ * schema, a bad key leaving its rule off.
45028
45098
  */
45029
45099
  function readConfig(root, project) {
45030
45100
  let parsed;
@@ -45121,12 +45191,8 @@ const SHORTHANDS = {
45121
45191
  ]
45122
45192
  };
45123
45193
  /**
45124
- * `outranked`, over two versions of one frame: `before`, the bytes an agent's
45125
- * write replaced, and `after`, the frame as that write left it. It names each
45126
- * element whose style attribute declares, unchanged since `before`, a property
45127
- * a rule the write changed in the frame's own `<style>` blocks also sets, since
45128
- * a normal inline declaration beats every normal rule. Linked and token sheets
45129
- * change through files of their own, so they are left out.
45194
+ * `outranked`, naming each element whose unchanged inline style beats a rule an
45195
+ * agent's write changed in the frame's own `<style>`.
45130
45196
  */
45131
45197
  function checkOutranked(before, after) {
45132
45198
  const changed = changedDeclarations(before, after);
@@ -45262,6 +45328,7 @@ const RULES = [
45262
45328
  ...STRUCTURE_RULES,
45263
45329
  ...LINK_RULES,
45264
45330
  ...BOARD_ROUTE_RULES,
45331
+ ...BINDING_RULES,
45265
45332
  ...FONT_RULES,
45266
45333
  ...THEME_RULES,
45267
45334
  ...CUSTOM_PROPERTY_RULES,
@@ -45320,10 +45387,8 @@ async function checkPages(root, project, pages, context) {
45320
45387
  }
45321
45388
  // src/server/look/starter.ts
45322
45389
  /**
45323
- * Writes a starter `tokens.css` into a project that renders with no token
45324
- * sheet at all. Refuses `tokens-exist` when a board, `--tokens`, or project
45325
- * sheet already reaches the project, since a starter sheet over one would
45326
- * override a look somebody chose.
45390
+ * Writes a starter `tokens.css`, refusing `tokens-exist` where any sheet
45391
+ * already reaches the project, since it would override a chosen look.
45327
45392
  */
45328
45393
  async function writeStarterSheet(root, ref, look, { tokens, journal } = {}) {
45329
45394
  const project = await resolveProject(root, ref);
@@ -45507,10 +45572,8 @@ const projectTokensSchema = object$1({
45507
45572
  font: _enum$1(Object.keys(STARTER_FONTS)).default(DEFAULT_LOOK.font)
45508
45573
  });
45509
45574
  /**
45510
- * The bytes a new frame holds for the asset at `path`, as an insert writes
45511
- * them, at the size the frame is added at. An audio takes the width alone, so
45512
- * its frame hugs the player's height, and every other kind refuses `usage`
45513
- * without both sides.
45575
+ * A new frame's bytes for an asset, an audio taking the width alone so its
45576
+ * frame hugs the player's height.
45514
45577
  */
45515
45578
  function mediaMarkup(ref, path, kind, { width, height }) {
45516
45579
  const tag = kind === "video" || kind === "audio" ? kind : "img";
@@ -45527,14 +45590,8 @@ function mediaMarkup(ref, path, kind, { width, height }) {
45527
45590
  }, shapePaint([]), "");
45528
45591
  }
45529
45592
  /**
45530
- * The board's structure writes, each behind `requireWriter`, its body
45531
- * mirroring the CLI verb's flags and its answer the record the CLI prints.
45532
- * Each write reports into its own journal and records one step, so the
45533
- * developer can undo it, and names the page the board shows on either side
45534
- * of it, so an undo can follow a page it brings back or renames.
45535
- * `measure` reads a frame's content on the warm browser for a fit, which
45536
- * refuses `browser-not-found` where none is given. `tokens` is the
45537
- * `--tokens` sheet the server was given, which a starter sheet never goes under.
45593
+ * The board's structure writes, mirroring the CLI verbs, each one undo step
45594
+ * naming the page on either side, so an undo can follow a page it brings back.
45538
45595
  */
45539
45596
  function structureRoutes(root, access, history, measure, tokens = null) {
45540
45597
  const app = new Hono();
@@ -45555,12 +45612,6 @@ function structureRoutes(root, access, history, measure, tokens = null) {
45555
45612
  });
45556
45613
  return result;
45557
45614
  };
45558
- /**
45559
- * Refuses a write that would rename, move, or remove a frame another
45560
- * session holds, before anything is written. Writes that leave every
45561
- * existing frame file and box alone, being an add, a duplicate, a flag, a
45562
- * copy, a paste, and a move of a page or frame in its order, go at once.
45563
- */
45564
45615
  const refuseHeld = (refs) => refuseClaimed(root, refs, /* @__PURE__ */ new Date());
45565
45616
  /** `refuseHeld` for frames as the body names them, read back to their canonical refs. */
45566
45617
  const refuseHeldFrames = async (frames) => {
@@ -45804,13 +45855,6 @@ function structureRoutes(root, access, history, measure, tokens = null) {
45804
45855
  data: frames
45805
45856
  });
45806
45857
  });
45807
- /**
45808
- * Sets the widths each frame also shows at, in one step, leaving every
45809
- * frame file alone. A frame whose stored list differs from its `expected`
45810
- * refuses `stale-layout` before any frame is written, so a hand write never
45811
- * drops a width an agent added since the board drew it. The compare and
45812
- * the write share one layout lock. A locked frame refuses the whole write.
45813
- */
45814
45858
  app.post("/api/frame/widths", async (c) => {
45815
45859
  const body = await parseBody$1(c.req.raw, frameWidthsSchema);
45816
45860
  const targets = body.refs.map((ref) => {
@@ -45843,16 +45887,6 @@ function structureRoutes(root, access, history, measure, tokens = null) {
45843
45887
  data: frames
45844
45888
  });
45845
45889
  });
45846
- /**
45847
- * Sets how each frame holds its height, `fixed`, `fit`, or `scroll`, in one
45848
- * step. `expected` holds each frame's box as the caller saw it, keyed by the
45849
- * ref the body names, and a frame changed since refuses `stale-layout`
45850
- * before any frame is written. `heights` gives a `scroll` write the screen
45851
- * height each named frame takes, and refuses `usage` with any other mode. A
45852
- * locked or claimed frame refuses the whole
45853
- * write, and `fit` measures each frame and its linked widths on the warm
45854
- * browser first, refusing `browser-not-found` where none runs.
45855
- */
45856
45890
  app.post("/api/frame/height", async (c) => {
45857
45891
  const body = await parseBody$1(c.req.raw, frameHeightSchema);
45858
45892
  if (body.heights && body.mode !== "scroll") throw new FrameboardError("usage", `The body gives heights to a ${body.mode} write, which takes them only with scroll.`);
@@ -45915,11 +45949,6 @@ function structureRoutes(root, access, history, measure, tokens = null) {
45915
45949
  data: deleted
45916
45950
  });
45917
45951
  });
45918
- /**
45919
- * The frames the developer last copied or cut, held as bytes and boxes in
45920
- * memory, so a paste never depends on the source surviving and a restart
45921
- * empties it.
45922
- */
45923
45952
  let clipboard = [];
45924
45953
  app.post("/api/clipboard/copy", async (c) => {
45925
45954
  clipboard = await holdFrames(root, (await parseBody$1(c.req.raw, framesSchema)).refs, { cwd });
@@ -46070,11 +46099,6 @@ function structureRoutes(root, access, history, measure, tokens = null) {
46070
46099
  data: projects
46071
46100
  });
46072
46101
  });
46073
- /**
46074
- * Turns one check rule off for the project, or back on, as one undo step.
46075
- * It waits on no claim, since it writes `project.json` alone and under its
46076
- * lock. Turning off a rule no check declares answers `usage`.
46077
- */
46078
46102
  app.post("/api/project/rule", async (c) => {
46079
46103
  const body = await parseBody$1(c.req.raw, projectRuleSchema);
46080
46104
  const rules = await recorded((journal) => setProjectRule(root, body.project, body.rule, body.off, { journal }), onHome);
@@ -46112,10 +46136,8 @@ function structureRoutes(root, access, history, measure, tokens = null) {
46112
46136
  }
46113
46137
  // src/shared/card-frames.ts
46114
46138
  /**
46115
- * The frames a project card draws: the visible frames of the first page
46116
- * holding one, so a first page that is empty or all hidden passes to the
46117
- * next. The thumbnail route stamps these, the home view asks for them, and
46118
- * the card's skeleton draws them, so all three read this one pick.
46139
+ * The frames a project card draws, from the first page holding a visible one,
46140
+ * shared so the route, home, and the skeleton read one pick.
46119
46141
  */
46120
46142
  function cardFrames(project) {
46121
46143
  for (const page of project.pages) {
@@ -46126,11 +46148,8 @@ function cardFrames(project) {
46126
46148
  }
46127
46149
  // src/server/routes/thumbnails.ts
46128
46150
  /**
46129
- * `GET /api/thumbnails?theme=` answers `{ stamps }`, the stamp of each
46130
- * frame a project card draws whose capture in that theme is current, and queues a render of the rest, so the home view asks once and
46131
- * hears each landing over the live socket. `GET /api/thumbnails/png` serves
46132
- * one capture at `?ref=&theme=&v=<stamp>`, cached for good since a changed
46133
- * frame takes a new stamp. Both only read, so they take no writer guard.
46151
+ * The thumbnail routes, queueing stale renders so home hears each landing on
46152
+ * the socket, and caching a capture for good, since a change takes a new stamp.
46134
46153
  */
46135
46154
  function thumbnailRoutes(root, store) {
46136
46155
  const app = new Hono();
@@ -46193,14 +46212,8 @@ const editSchema = union([object$1({
46193
46212
  reset: literal(true)
46194
46213
  })]);
46195
46214
  /**
46196
- * The Theme tab's token write, behind `requireWriter`. `POST /api/tokens/edit`
46197
- * sets one token the project's sheets list on one theme or both in the sheet
46198
- * `sheet` names. `project`, the default, writes the project's `tokens.css`,
46199
- * and a reset there takes its override back to the board's value. `board`
46200
- * writes the board's sheet for a token it already sets. A stale `hash` answers
46201
- * 409 `stale-tokens` and an invalid edit 409 `invalid-edit`, each writing
46202
- * nothing. A landed edit records one step and answers the token's values and
46203
- * the hash written.
46215
+ * The Theme tab's token write into the sheet `sheet` names, one undo step,
46216
+ * writing nothing on a stale `hash` or an invalid edit.
46204
46217
  */
46205
46218
  function tokenRoutes(root, access, history, look) {
46206
46219
  const app = new Hono();
@@ -46343,6 +46356,7 @@ function createApp({ clientDir, root, port, actions, tickets, openRoute, renderF
46343
46356
  app.route("/", findRoutes(root));
46344
46357
  app.route("/", claimsRoutes(root, actions.access));
46345
46358
  app.route("/", tokenRoutes(root, actions.access, history, frames.look));
46359
+ app.route("/", kitRoutes(root, actions.access, history, { tokens: given }));
46346
46360
  app.route("/", editRoutes(root, actions.access, history, settledVersion, frames.look.sheets));
46347
46361
  app.route("/", pngRoutes(root, renderFrame, renderFilmstrip));
46348
46362
  app.route("/", clipboardRoutes(root, actions.access, renderFrame, clipboard));
@@ -46372,12 +46386,9 @@ function installCommands() {
46372
46386
  };
46373
46387
  }
46374
46388
  /**
46375
- * Launches Playwright's pinned headless shell, the one browser capture uses.
46376
- * An installed Chrome or Edge is never a fallback, since a branded build of
46377
- * another version rasterizes text differently, so the same frame would
46378
- * capture differently by machine. Without the shell it refuses
46379
- * `browser-not-found` and downloads nothing, since a verb never fetches a
46380
- * browser unasked. `purpose` names what needed the browser in the refusal.
46389
+ * Launches the pinned headless shell, never an installed Chrome, which
46390
+ * rasterizes text differently, and refuses `browser-not-found` rather than
46391
+ * download one unasked.
46381
46392
  */
46382
46393
  async function launchCaptureBrowser({ purpose, launch = launchShell }) {
46383
46394
  try {
@@ -46402,10 +46413,8 @@ function firstLine(error) {
46402
46413
  // src/server/capture/host.ts
46403
46414
  const HOSTNAME$1 = "127.0.0.1";
46404
46415
  /**
46405
- * Serves the board's frames on a loopback port of its own, for a verb that
46406
- * renders with no board server running. It mounts the same look and frame
46407
- * routes the server does, so a capture sees the bytes and the look the board
46408
- * shows, reading a running server's `--tokens` sheet from the address file.
46416
+ * Serves frames on a loopback port for a verb with no server running, through
46417
+ * the server's own routes, so a capture sees what the board shows.
46409
46418
  */
46410
46419
  async function startFrameHost({ root, facesDir }) {
46411
46420
  let bound = 0;
@@ -46468,12 +46477,8 @@ const HELD_SCREENSHOT = {
46468
46477
  caret: "hide"
46469
46478
  };
46470
46479
  /**
46471
- * The file name of one image, `<name>.<theme>.png` at 1x so a path an agent
46472
- * saved stays true, and `<name>.<theme>@<n>x.png` at any other scale. A shot
46473
- * scrolled down takes `.scroll-<px>` after the name, the offset asked for,
46474
- * and a linked width takes `@<width>` ahead of both. A timed shot takes
46475
- * `.at-<ms>`, the moment asked for, and a filmstrip `.filmstrip-<n>`, each
46476
- * after the width.
46480
+ * One image's file name, unscaled at 1x so a path an agent saved stays true,
46481
+ * with width, scroll, moment, and filmstrip suffixes.
46477
46482
  */
46478
46483
  function imageName(name, theme, scale, scroll, width, moment) {
46479
46484
  const named = width === void 0 ? name : `${name}@${width}`;
@@ -46490,9 +46495,7 @@ function compositeImagePath(out, page, theme, scale = 1) {
46490
46495
  return join(out, page.project, imageName(page.name, theme, scale));
46491
46496
  }
46492
46497
  /**
46493
- * The composite's size and the shift placing each frame in it, so the
46494
- * leftmost and topmost frames sit one margin in and one margin is left past
46495
- * the far edges, each frame's linked widths included. Refuses
46498
+ * The composite's size and each frame's shift, one margin on every side, and
46496
46499
  * `capture-too-large` past Chromium's screenshot limit.
46497
46500
  */
46498
46501
  function compositeBounds(page, frames, scale = 1) {
@@ -46541,12 +46544,8 @@ function filmstripBounds(ref, box, count, scale = 1) {
46541
46544
  };
46542
46545
  }
46543
46546
  /**
46544
- * Captures each frame in each theme at its layout size times `scale`, one PNG
46545
- * apiece, and again at each linked width it lists, at the height that width
46546
- * holds. Every image renders before any is written, so a refusal on one frame
46547
- * leaves no half-written set an agent could read as current. A `scroll`
46548
- * offset shoots each view that far down, clamped to the page's end. `width`
46549
- * shoots each frame at that one width alone, its own or a linked one.
46547
+ * Captures each frame per theme and linked width, rendering every image before
46548
+ * writing any, so a refusal leaves no half-written set an agent reads as current.
46550
46549
  */
46551
46550
  async function captureFrameImages(browser, { baseUrl, frames, themes, out, scale = 1, scroll, width }) {
46552
46551
  const rendered = [];
@@ -46605,12 +46604,8 @@ async function captureComposite(browser, { baseUrl, page, frames, themes, out, s
46605
46604
  return writeImages(rendered);
46606
46605
  }
46607
46606
  /**
46608
- * Captures one frame held at set moments of its timeline, in each theme and
46609
- * at each width it shows at, or the one `width` names. `timing.at` writes one
46610
- * PNG per moment, and `timing.filmstrip` one PNG per view and theme holding that many
46611
- * moments spaced from 0 to the timeline's end. A frame with no seekable
46612
- * timeline refuses `motion-missing`, and a filmstrip of one that never ends
46613
- * `motion-unbounded`. Every image renders before any is written.
46607
+ * Captures a frame held at moments of its timeline, per theme and width,
46608
+ * rendering every image before writing any.
46614
46609
  */
46615
46610
  async function captureMotionImages(browser, { baseUrl, frame, themes, out, scale = 1, width, timing, motionTimeoutMs = LOAD_TIMEOUT_MS }) {
46616
46611
  const rendered = [];
@@ -46675,10 +46670,7 @@ async function captureMotionImages(browser, { baseUrl, frame, themes, out, scale
46675
46670
  };
46676
46671
  }
46677
46672
  /**
46678
- * One frame's filmstrip in one theme: `count` moments spaced from 0 to the
46679
- * timeline's end, held one by one and laid in a row on the theme's canvas
46680
- * color. Refuses `motion-missing` for a frame with no seekable timeline and
46681
- * `motion-unbounded` for one that never ends, and `capture-too-large` before
46673
+ * One frame's filmstrip in one theme, refusing `capture-too-large` before
46682
46674
  * opening the frame for a strip past the screenshot limit.
46683
46675
  */
46684
46676
  async function renderFilmstrip(browser, { baseUrl, frame, theme, scale = 1, count, motionTimeoutMs = LOAD_TIMEOUT_MS }) {
@@ -47542,10 +47534,8 @@ const elementStylesSchema = object$1({
47542
47534
  flow: elementFlowSchema.optional()
47543
47535
  });
47544
47536
  /**
47545
- * One color a frame or a subtree uses. `uses` holds the edit-address index of
47546
- * each element whose color, background, or border is this one, inherited or
47547
- * not, ascending and valid for the read's `hash`. It never names `body`, which
47548
- * the board selects as the frame, or an element that draws no box, such as `br`.
47537
+ * One color a frame uses, `uses` never naming `body`, which the board selects
47538
+ * as the frame, or an element that draws no box.
47549
47539
  */
47550
47540
  const usedColorSchema = styleValueSchema.extend({ uses: array$1(int$1().min(0)).optional() });
47551
47541
  object$1({
@@ -47619,10 +47609,8 @@ const inspectResultSchema = object$1({
47619
47609
  });
47620
47610
  // src/shared/records/preview.ts
47621
47611
  /**
47622
- * What `preview` returns on a start: the link a phone on the same network
47623
- * opens, landing on one frame, which serves that frame's whole project read
47624
- * only. The link ends when another start replaces it, when `preview --stop`
47625
- * runs, when the board card showing it closes, or when the board stops.
47612
+ * What `preview` returns on a start, a phone link serving the frame's whole
47613
+ * project read only until stopped or replaced.
47626
47614
  */
47627
47615
  const previewStartSchema = object$1({
47628
47616
  url: string$1(),
@@ -47743,7 +47731,7 @@ function contentFormat() {
47743
47731
  "hidden, locked, hugWidth, hugHeight, and scroll read as false when absent, and an axis whose hug flag is false holds the size its entry states.",
47744
47732
  `scroll marks a frame that holds a fixed screen height and scrolls past it, such as a page with a sticky section. It fixes both axes, so either hug flag beside it reads as false, frame fit refuses it, and serve never measures it. frame add --scroll sets it, taking the height given or else the preset height of the width (${FRAME_SIZES.desktop.height} px at ${FRAME_SIZES.desktop.width}). frame resize --scroll sets it on a placed frame, dropping a hugging height to that preset height unless a height is given and keeping a fixed height as it stands, so resize a frame fixed past a screen with --height too. frame resize --no-scroll clears it, keeping the box.`,
47745
47733
  `widths lists the extra widths one frame file also shows at, as { width, height } objects, each drawn 80 px past the last in a row beside the frame at its y, so a responsive page is one file rather than a copy per width. Each width follows the frame's own height mode: it hugs its content at that width while hugHeight is on, and otherwise holds its height, the preset height of its width when first set and on frame resize --scroll. A value of any other shape reads as none. frame add --widths 834,390 and frame resize --widths set it, refusing a repeated width, the frame's own width, or a frame hugging its width, and frame resize --no-widths clears it. capture writes <frame>@<width>.<theme>.png beside <frame>.<theme>.png, check reports a browser finding at a linked width with that width and prints it as <path>@<width>, and a frames.json value of <project>/<page>/<frame>@<width> syncs that width's images.`,
47746
- `showDevice true has the board draw the frame inside the device its width names: a phone from 320 to 479 px wide, a tablet from 480 to 1023, and a laptop from 1024 up, with none under 320. The phone's body stands ${BEZELS.phone.border} px past the box on every side and the tablet's ${BEZELS.tablet.border}, and the laptop's lid ${BEZELS.laptop.border} px past its top and sides, with a chin and a wider base below. A resize redraws the body with no write, and list reports the device the width names as device, absent when off or under 320. It never changes the frame file or its size, and a frame placed beside one lands 80 px past the body. Linked widths draw no device. Any other value of showDevice reads as off and is kept on write. A device string from before showDevice reads as on, and the entry's next write replaces it with showDevice. frame add --device on and frame device <frame-ref> <on|off> set it, taking phone and tablet as on and none as off.`,
47734
+ `showDevice true has the board draw the frame inside the device its width names: a phone from 320 to 479 px wide, a tablet from 480 to 1023, and a laptop from 1024 up, with none under 320. The phone's body stands ${BEZELS.phone.border} px past the box on every side and the tablet's ${BEZELS.tablet.border}, and the laptop's lid ${BEZELS.laptop.border} px past its top and sides, with a chin and a wider base below. A resize redraws the body with no write, and list reports the device the width names as device, absent when off or under 320. It never changes the frame file, its size, or its box. frame add, frame duplicate, and a paste place a frame beside another with its own body, a laptop's base included, 80 px past the other's body. A frame given --x keeps that x, a frame landing in a reserved box keeps that box with no room for a device, and a placed frame stays where it stands when its device turns on. Linked widths draw no device. Any other value of showDevice reads as off and is kept on write. A device string from before showDevice reads as on, and the entry's next write replaces it with showDevice. frame add --device on and frame device <frame-ref> <on|off> set it, taking phone and tablet as on and none as off.`,
47747
47735
  `An axis that hugs takes its size from the frame's content: a running serve measures it after each write to the frame file and when frame add places a file already written, its width at most ${FRAME_SIZES.desktop.width} px, and writes width and height alone, never a flag. Content sized off the viewport keeps the box it has.`,
47748
47736
  "frame add with no size hugs both axes, --size or --width fixes the width and hugs the height, and --height fixes the height alone, its box standing in until serve measures. frame resize and a hand resize fix each axis they set, and frame fit sets the height and turns hugHeight on.",
47749
47737
  "Frames sort by order, then name, and a write that changes order renumbers the page from 0.",
@@ -47759,10 +47747,21 @@ function contentFormat() {
47759
47747
  "page transition <page-ref> <name> sets the page's, and none clears it so slides cut. frame transition <frame-ref> <name> sets a frame's, and page clears it so the frame takes its page's. Both take --ms and --direction, refuse usage on a name that is neither built in nor the project's own with the known names in the error's details, and write only layout.json.",
47760
47748
  `A step is an element present mode holds back until a press reveals it, marked by three attributes on that element and nothing else. ${STEP_ATTRIBUTES.step}="<n>" is a positive integer, and steps show in number order with equal numbers together and gaps closed. ${STEP_ATTRIBUTES.effect} is one of ${STEP_EFFECTS.join(", ")}, defaulting to appear. ${STEP_ATTRIBUTES.start} is one of ${STEP_STARTS.join(", ")}, defaulting to click, where with shows the step beside the one before it and after shows it once that one finishes. Set them with edit --attr. Edit, Play, capture, and an exported PNG show every step.`
47761
47749
  ],
47750
+ controls: [
47751
+ `A control is an ordinary range or number input in a frame carrying ${BINDS_ATTRIBUTE}="<selector> <--property>" and ${UNIT_ATTRIBUTE}="<unit>". The selector names the element it tunes and may hold spaces, the last word is a custom property the target's own CSS reads through var(), and the unit follows the control's value, so a value of 130 under ${UNIT_ATTRIBUTE}="%" sets 130%. The frame holds no script for it.`,
47752
+ "In Play, moving a control sets its property inline on the target at once and writes nothing. Keep values writes each moved control's value attribute and one style attribute per target holding its properties, as one undo step. Reset, or leaving the frame or Play without keeping, puts the file's values back.",
47753
+ "An export, a thumbnail, a presented slide, and the phone link hide every control, a label holding one, and a container holding only controls and their labels. The canvas and capture show them.",
47754
+ `check reports binding-target at warning when a ${BINDS_ATTRIBUTE} misses its selector or property, sets a property that is not custom, or matches no element, as after a rewrite renames the target's id.`
47755
+ ],
47756
+ kits: [
47757
+ `A kit is a folder of plain files: ${KIT_FILE} naming it, ${TOKEN_FILE} with a light and a dark block, ${KIT_SHEET} of component styles, ${KIT_NOTE} saying what to reach for, and a kit page of sample frames. The tool ships ${SHIPPED_KITS.join(", ")}, and a board keeps the kits saved from its projects in ${KITS_FOLDER}/.`,
47758
+ `kit add copies the kit's ${TOKEN_FILE} as the project's, its kit page as the project's kit page, and every other file into ${ASSETS_FOLDER}/kit/. It refuses tokens-exist where a board, --tokens, or project sheet already reaches the project, and name-taken where the project holds a kit page or ${ASSETS_FOLDER}/kit/, unless --replace is given. kit save refuses name-taken for a name a shipped or saved kit holds, and tokens-not-found for a project no sheet reaches.`,
47759
+ `The server imports ${ASSETS_FOLDER}/kit/${KIT_SHEET} into each frame after the project sheet, and check reads it with the token sheets. Read ${ASSETS_FOLDER}/kit/${KIT_NOTE} and the kit page before drawing in a project that holds one.`
47760
+ ],
47762
47761
  assets: `A frame links files in its own page folder or in its project's ${ASSETS_FOLDER}/ folder. frame duplicate and frame move carry the ${FRAME_EXTENSION} file alone, so keep files shared between frames or pages in ${ASSETS_FOLDER}/.`,
47763
47762
  look: [
47764
47763
  `The board's ${TOKEN_FILE} holds the design tokens every project shares, and a project's own ${TOKEN_FILE} overrides it. serve --tokens <path> stands in for the board's sheet, resolved against the working folder and recorded as tokens in ${RUN_FOLDER}/${ADDRESS_FILE} while that server runs.`,
47765
- `The server puts one <style ${LOOK_MARKER}> first in each frame's head, importing the faces, then the board sheet, then the project sheet, so a frame's own sheets win. The file on disk never changes, and a count of a live frame's elements skips elements carrying ${LOOK_MARKER}.`,
47764
+ `The server puts one <style ${LOOK_MARKER}> first in each frame's head, importing the faces, then the board sheet, then the project sheet, then an installed kit's stylesheet, so a frame's own sheets win. The file on disk never changes, and a count of a live frame's elements skips elements carrying ${LOOK_MARKER}.`,
47766
47765
  `Every frame can use the families ${FACES.map((face) => face.family).join(", ")} with no link of its own. A project adds other faces in its ${ASSETS_FOLDER}/ folder.`,
47767
47766
  "The board sets data-theme and color-scheme to light or dark on each frame's root, with the class dark or light, so define both themes through [data-theme], .dark, prefers-color-scheme, or light-dark(), or take every color from token variables. Never paste a token sheet into a frame.",
47768
47767
  `A change to a token sheet reloads every frame it reaches.`,
@@ -47814,6 +47813,8 @@ function formatLines(format) {
47814
47813
  ...format.layout.map((line) => `${INDENT}${line}`),
47815
47814
  "Present",
47816
47815
  ...format.present.map((line) => `${INDENT}${line}`),
47816
+ "Controls",
47817
+ ...format.controls.map((line) => `${INDENT}${line}`),
47817
47818
  "Assets",
47818
47819
  `${INDENT}${format.assets}`,
47819
47820
  "Look",
@@ -48033,10 +48034,8 @@ function refOf(frame) {
48033
48034
  return `${frame.project}/${frame.page}/${frame.name}`;
48034
48035
  }
48035
48036
  /**
48036
- * The box each named frame will land in, in one row per page in the order
48037
- * named, past every frame and live reservation already on that page unless
48038
- * `--x` or `--y` sets the row. A frame that exists already refuses
48039
- * `name-taken` before anything is reserved.
48037
+ * Each named frame's box, one row per page past every frame and reservation,
48038
+ * refusing `name-taken` before anything is reserved.
48040
48039
  */
48041
48040
  async function reservationsOf(root, refs, options, cwd, now) {
48042
48041
  if (refs.length === 0) throw new FrameboardError("usage", "Name at least one frame to reserve with --new.");
@@ -51855,10 +51854,8 @@ var wrapper_default = import_websocket.default;
51855
51854
  /** The socket path on the board's server. */
51856
51855
  const LIVE_PATH = "/api/live";
51857
51856
  /**
51858
- * Follows a session's inbox on the board's live socket until aborted. It
51859
- * waits quietly for a board and a running server, upgrades with the address
51860
- * token as a bearer, and prints each note before acking it, so a follower
51861
- * killed between the two prints the note again rather than losing it.
51857
+ * Follows a session's inbox, printing each note before acking it, so a
51858
+ * follower killed between the two prints it again rather than losing it.
51862
51859
  */
51863
51860
  async function follow({ findRoot, session, tag, print, signal, retryMs = 500 }) {
51864
51861
  while (!signal.aborted) {
@@ -51963,10 +51960,8 @@ function renderedOnly(live) {
51963
51960
  }] : []);
51964
51961
  }
51965
51962
  /**
51966
- * Loads a frame the way `capture` does and reports each rendered element with
51967
- * its `edit` index, box, and computed color and type. The file is read before
51968
- * and after the load, and a hash that moved refuses `stale-address`. A live
51969
- * order that differs from the file's refuses `address-mismatch`.
51963
+ * Reports each rendered element under its `edit` index, refusing
51964
+ * `stale-address` when the file moved during the load.
51970
51965
  */
51971
51966
  async function inspectFrame(browser, { baseUrl, frame, theme, index }) {
51972
51967
  const bytes = readFileSync(frame.path);
@@ -52068,6 +52063,38 @@ function describe$3(result) {
52068
52063
  const note = result.editable ? "" : "\nThe browser builds an element the file does not state, so edit refuses every index here.";
52069
52064
  return `${result.ref} in ${result.theme}, hash ${result.hash}\n${lines.join("\n")}${note}`;
52070
52065
  }
52066
+ // src/cli/commands/kit.ts
52067
+ function registerKit(program, context) {
52068
+ const { io } = context;
52069
+ const kit = program.command("kit").description("Install a design kit's tokens, styles, and sample frames into a project, or save a project's look as one");
52070
+ act(addVerb(kit, "list", "List the kits a project can install, the shipped ones first and then the board’s own"), context, async (_args, options) => {
52071
+ const kits = await listKits(await boardOf(options, io));
52072
+ return {
52073
+ data: kits,
52074
+ human: kits.map((each) => `${each.name}\t${each.description}`).join("\n")
52075
+ };
52076
+ });
52077
+ act(addVerb(kit, "add", "Install a kit into a project no token sheet reaches, refusing tokens-exist where a board, --tokens, or project sheet does unless --replace is given").argument("<project>", "the project").argument("[kit]", "a kit `kit list` names").option("--from <folder>", "install the kit in this folder instead").option("--replace", "install over the project's own sheet, kit page, and kit files, or over a board sheet"), context, async ([project = "", name], options) => {
52078
+ if (name === void 0 === (options.from === void 0)) throw new FrameboardError("usage", "Name a kit or pass --from <folder>, not both.");
52079
+ const root = await boardOf(options, io);
52080
+ const folder = options.from === void 0 ? null : resolve$1(io.cwd, options.from);
52081
+ const record = await installKit(root, project, folder === null ? findKit(root, name ?? "") : {
52082
+ name: basename(folder),
52083
+ path: folder
52084
+ }, { replace: options.replace ?? false });
52085
+ return {
52086
+ data: record,
52087
+ human: `Installed ${record.kit} into ${record.project}`
52088
+ };
52089
+ });
52090
+ act(addVerb(kit, "save", "Save a project's tokens, kit files, and kit page as a kit the board's projects can install").argument("<project>", "the project").argument("<name>", "the new kit"), context, async ([project = "", name = ""], options) => {
52091
+ const record = await saveKit(await boardOf(options, io), project, name);
52092
+ return {
52093
+ data: record,
52094
+ human: `Saved ${record.project} as the kit ${record.kit}`
52095
+ };
52096
+ });
52097
+ }
52071
52098
  // src/cli/commands/list.ts
52072
52099
  function registerList(program, context) {
52073
52100
  act(addVerb(program, "list", "List projects, pages, and frames", { project: true }), context, async (_args, options) => {
@@ -52786,11 +52813,8 @@ function folderOf(folder, clear) {
52786
52813
  const MAX_FOLDER = 256;
52787
52814
  // src/server/references/assets.ts
52788
52815
  /**
52789
- * The files a frame loads inside its project's `assets/`, by their path there,
52790
- * sorted and each once. A load naming no file is left to the link check's
52791
- * `missing-file`, so it copies nothing here. A file in the frame's page folder
52792
- * refuses `page-file-load`, since the link check allows it and a reference
52793
- * folder holds nothing it could resolve to, so it would land broken.
52816
+ * The asset files a frame loads, refusing a page-folder load, since a reference
52817
+ * folder holds nothing it could resolve to.
52794
52818
  */
52795
52819
  function frameAssets(source) {
52796
52820
  const assets = assetsDirOf(source);
@@ -52835,10 +52859,8 @@ const OPTIONS = {
52835
52859
  sortPackageJson: false
52836
52860
  };
52837
52861
  /**
52838
- * What the folder holds of a board frame: its asset links moved to its
52839
- * project's subtree, so two projects never collide, formatted so a reference
52840
- * diffs line by line while the board file stays as the agent wrote it. The
52841
- * write and `--check` both build through it, so they compare the same bytes.
52862
+ * A frame as the reference folder holds it, built by the write and `--check`
52863
+ * alike so they compare the same bytes.
52842
52864
  */
52843
52865
  async function toReference(source, reference, folder) {
52844
52866
  const result = await (await importFormat(folder))(`${reference}.html`, withProjectAssets(source, reference), OPTIONS);
@@ -52850,10 +52872,8 @@ async function toReference(source, reference, folder) {
52850
52872
  return result.code;
52851
52873
  }
52852
52874
  /**
52853
- * Rewrites the frame's text only at the spans its loads occupy, so text naming
52854
- * `../assets/` that loads nothing, such as a `<code>` sample, keeps its bytes.
52855
- * The link climbs one folder per folder the reference sits in, to the folder's
52856
- * `assets/`.
52875
+ * Rewrites only the spans loads occupy, so text naming `../assets/` that loads
52876
+ * nothing keeps its bytes.
52857
52877
  */
52858
52878
  function withProjectAssets(source, reference) {
52859
52879
  const assets = `${"../".repeat(reference.split("/").length - 1)}assets/${source.project}/`;
@@ -52894,11 +52914,8 @@ const SEGMENT = "[a-z0-9]+(-[a-z0-9]+)*";
52894
52914
  const REFERENCE = new RegExp(`^${SEGMENT}(/${SEGMENT}){1,2}$`);
52895
52915
  const BOARD_REF = /^[^/\s]+\/[^/\s]+\/[^/\s@]+(@[1-9]\d*)?$/;
52896
52916
  /**
52897
- * Reads `frames.json`, mapping each reference, `<group>/<name>` or
52898
- * `<group>/<section>/<name>`, to the board frame `<project>/<page>/<frame>`
52899
- * it is captured from, or `<project>/<page>/<frame>@<width>` to capture it at
52900
- * one of its widths. An entry in any other shape refuses rather than filing
52901
- * into the wrong folder.
52917
+ * Reads `frames.json`, refusing an entry of any other shape rather than filing
52918
+ * it into the wrong folder.
52902
52919
  */
52903
52920
  function parseFrameMap(json) {
52904
52921
  const parsed = parseJson(json);
@@ -53290,13 +53307,8 @@ function linkedAssets(root, project, page, name) {
53290
53307
  // src/server/capture/thumbnails.ts
53291
53308
  const THUMBNAILS_FOLDER = "thumbnails";
53292
53309
  /**
53293
- * The home view's frame captures, one per frame and theme under
53294
- * `.run/thumbnails/<project>/<page>/<frame>.<theme>.png`. A stamp names the
53295
- * server run, how often the frame changed, and its size, so a capture of a
53296
- * changed or resized frame, or one a previous server served, is never
53297
- * answered as current. A failed render is remembered against its stamp, so a
53298
- * frame refusing `font-missing`, or a board with no headless shell, costs one
53299
- * render until the frame changes.
53310
+ * Home's frame captures, stamped by server run, change count, and size, so a
53311
+ * stale capture is never current, and a failed render costs one try per stamp.
53300
53312
  */
53301
53313
  function createThumbnailStore({ root, run, render, onRendered }) {
53302
53314
  const folder = join(root, RUN_FOLDER, THUMBNAILS_FOLDER);
@@ -53371,13 +53383,8 @@ const THEMED_RULES = [
53371
53383
  ...CONTRAST_RULES
53372
53384
  ];
53373
53385
  /**
53374
- * Runs every browser rule on one frame at its layout size, in light and in
53375
- * dark, and merges the two. A rule tripping in one theme alone names that
53376
- * theme in its message. A missing face is measured in the fallback the board
53377
- * shows rather than refused, since the board shows it too. Finite animations
53378
- * finish before any rule reads, so an entrance is measured at rest. The declaration
53379
- * and scroll-effect rules read no theme, so they run on the first theme's
53380
- * page alone. A rule the project turned off lands no finding.
53386
+ * Runs every browser rule in both themes and merges them, measuring a missing
53387
+ * face in the board's fallback rather than refusing, after animations finish.
53381
53388
  */
53382
53389
  async function checkRendered(browser, { baseUrl, root, frame, config }) {
53383
53390
  const [project = "", page = "", name = ""] = frame.ref.split("/");
@@ -53437,11 +53444,8 @@ function mergeThemes(byTheme) {
53437
53444
  }
53438
53445
  // src/server/claims/land.ts
53439
53446
  /**
53440
- * Moves each reserved frame whose file now exists from its claim into the
53441
- * layout: an entry at the claim's box on top of its page, unless the page
53442
- * already holds one, then the claim drops its box and holds the frame as any
53443
- * editing claim does. Answers the refs it landed, and none when the claims
53444
- * file does not parse.
53447
+ * Lands each reserved frame whose file now exists at its claim's box, which
53448
+ * the claim then drops, answering none for an unparsable claims file.
53445
53449
  */
53446
53450
  async function landReserved(root, now) {
53447
53451
  let claims;
@@ -56706,11 +56710,8 @@ const CEILING_MS = 250;
56706
56710
  */
56707
56711
  const WARM_UP_MS = 100;
56708
56712
  /**
56709
- * Watches the board folder and reports changes in batches, so a burst of
56710
- * writes from one agent turn costs one rescan. Resolves once the watch is
56711
- * warm, so a write after it is always seen. Each of `files` outside the
56712
- * board, such as a `--tokens` sheet, is watched too and lands in the same
56713
- * batches.
56713
+ * Watches the board in batches, so one agent turn costs one rescan, resolving
56714
+ * once warm, so a later write is always seen.
56714
56715
  */
56715
56716
  async function watchBoard(root, files = []) {
56716
56717
  const listeners = /* @__PURE__ */ new Set();
@@ -56791,13 +56792,8 @@ function isIgnored(root, path) {
56791
56792
  return parts.some((part) => part.startsWith(".")) || name.endsWith(".lock") || name.endsWith(".tmp");
56792
56793
  }
56793
56794
  /**
56794
- * The frames a batch changed what they render: a frame's own file, or a temp
56795
- * file it is saved through, reloads that frame, any other file in a page folder reloads the page's frames since
56796
- * any of them may link it, and an asset or the project's token sheet reloads
56797
- * the whole project. The board's token sheet, or the `tokens` sheet standing
56798
- * in for it, reloads every frame. A layout or notes file reloads nothing,
56799
- * since moving a frame must not restart it.
56800
- * Only frames in `board` are named, in board order.
56795
+ * The frames a batch changed what they render, a layout or notes file
56796
+ * reloading nothing, since moving a frame must not restart it.
56801
56797
  */
56802
56798
  function reloadRefs(root, paths, board, tokens = null) {
56803
56799
  const { refs, everyFrame } = reloadCauses(root, paths, tokens);
@@ -56847,11 +56843,8 @@ function reloadCauses(root, paths, tokens) {
56847
56843
  };
56848
56844
  }
56849
56845
  /**
56850
- * `refs` less each frame that only moved with a folder the board renamed,
56851
- * being one under a moved folder whose file carries the stamp `last`, the
56852
- * board sent before the move, showed at its old path. It renders what the
56853
- * tab already shows, so a reload would restart it for nothing, while a file
56854
- * written before or after the move that `last` never showed still reloads.
56846
+ * `refs` less frames that only moved with a renamed folder and still match
56847
+ * `last`, since a reload would restart them for nothing.
56855
56848
  */
56856
56849
  function unmovedRefs(refs, board, moved, last) {
56857
56850
  if (moved.length === 0 || !last) return refs;
@@ -56874,13 +56867,8 @@ function frameNameOf(name) {
56874
56867
  return temp > 0 ? name.slice(0, temp) : null;
56875
56868
  }
56876
56869
  /**
56877
- * The hugging frames `next` holds placed that `previous` held unplaced or
56878
- * not at all, on a page whose `layout.json` is among `paths`, as one an
56879
- * agent wrote and then placed. Placing writes `layout.json` alone, which
56880
- * reloads nothing, so these are measured without a reload. A frame that only
56881
- * moved was placed in both, and one a folder rename carried has a new ref
56882
- * but a batch naming the folder alone, so both are left out. Given no
56883
- * `paths`, as for two scans of one batch, every page is read.
56870
+ * Hugging frames newly placed, measured without a reload, since placing writes
56871
+ * `layout.json` alone, which reloads nothing.
56884
56872
  */
56885
56873
  function placedRefs(previous, next, paths) {
56886
56874
  const written = paths && new Set(paths);
@@ -56888,11 +56876,8 @@ function placedRefs(previous, next, paths) {
56888
56876
  return next.projects.flatMap((project) => project.pages.filter((page) => !written || written.has(join(page.path, "layout.json"))).flatMap((page) => page.frames.filter((frame) => frame.placed && (frame.hugWidth || frame.hugHeight) && !before.has(frame.ref)).map((frame) => frame.ref)));
56889
56877
  }
56890
56878
  /**
56891
- * The frames hugging their height whose list of linked widths differs
56892
- * between two scans, as a `frame resize --widths` leaves one. That write
56893
- * touches `layout.json` alone, which reloads nothing, so a width it adds is
56894
- * measured here or holds its stand-in height until the frame file is next
56895
- * written. A frame absent from `previous` is `placedRefs`'s to name.
56879
+ * Height-hugging frames whose linked widths changed, measured here, since
56880
+ * that write reloads nothing.
56896
56881
  */
56897
56882
  function relistedRefs(previous, next) {
56898
56883
  const before = new Map(previous.projects.flatMap((project) => project.pages.flatMap((page) => page.frames.map((frame) => [frame.ref, listed(frame)]))));
@@ -56906,16 +56891,9 @@ function listed(frame) {
56906
56891
  }
56907
56892
  // src/server/live/findings.ts
56908
56893
  /**
56909
- * The board's check findings, held between batches so a hello needs no
56910
- * check. Each frame's list is its static findings, then those its last agent
56911
- * write raised against the bytes it replaced, then the browser findings the
56912
- * server's warm checker last landed for it. `tokens` is the
56913
- * server's `--tokens` sheet, null for none.
56914
- *
56915
- * The change and browser findings are held as they landed and read without
56916
- * the rules their project's `checks.off` named at its last recheck, so one
56917
- * leaves when its rule is turned off and comes back when it is turned on,
56918
- * with no write to the frame between.
56894
+ * The board's findings, held between batches so a hello needs no check, and
56895
+ * filtered by `checks.off` at read, so a rule turned back on returns its
56896
+ * findings with no write to the frame.
56919
56897
  */
56920
56898
  function createBoardFindings(root, tokens = null) {
56921
56899
  const held = /* @__PURE__ */ new Map();
@@ -56976,10 +56954,8 @@ function createBoardFindings(root, tokens = null) {
56976
56954
  };
56977
56955
  }
56978
56956
  /**
56979
- * The frames a batch changed the findings of: every frame whose rendered
56980
- * inputs changed, token sheets among them, plus every frame a project's
56981
- * check config reaches, which the reload rule leaves alone since it renders
56982
- * nothing.
56957
+ * The frames a batch changed the findings of, adding those a check config
56958
+ * reaches, which the reload rule leaves alone since it renders nothing.
56983
56959
  */
56984
56960
  function recheckRefs(root, paths, board, tokens = null) {
56985
56961
  const refs = new Set(reloadRefs(root, paths, board, tokens));
@@ -57018,11 +56994,8 @@ function checkOne(root, frame, context) {
57018
56994
  }
57019
56995
  // src/server/live/hub.ts
57020
56996
  /**
57021
- * The live socket every board tab holds. A client opens with a hello naming
57022
- * its role, and only a `board` client counts as an open tab and receives the
57023
- * board's messages. An `inbox` client is a session's follower, kept apart so
57024
- * it never counts as a tab, and taken only from a socket upgraded with the
57025
- * address token as a bearer, since a browser page must never register one.
56997
+ * The live socket every board tab holds. An `inbox` client never counts as a
56998
+ * tab and needs the bearer token, since a browser page must never register one.
57026
56999
  */
57027
57000
  function createHub({ tabs, port, access, snapshot, findings, notes, delivery, history, claims, changes, closeTab, dispatch = false }) {
57028
57001
  const server = new import_websocket_server.default({ noServer: true });
@@ -57160,12 +57133,8 @@ function send(socket, message) {
57160
57133
  }
57161
57134
  // src/server/live/hug.ts
57162
57135
  /**
57163
- * The server's hug step. A frame hugs when either flag is on, and its sizes
57164
- * are written through `setMeasured`, which takes the page's lock, writes
57165
- * only the axes the stored entry still hugs, and records no undo step. A
57166
- * frame whose content sizes itself off the viewport, whose body is empty,
57167
- * or that fails to load keeps its box, and a browser that cannot launch
57168
- * writes nothing at all.
57136
+ * The server's hug step, writing through `setMeasured`, with an unbounded,
57137
+ * empty, or failing frame keeping its box.
57169
57138
  */
57170
57139
  function createHug({ root, measure }) {
57171
57140
  let queue = Promise.resolve();
@@ -57257,7 +57226,7 @@ function huggingFrames(board, refs, parts) {
57257
57226
  }
57258
57227
  /**
57259
57228
  * The hugging frames whose file was written after their page's `layout.json`,
57260
- * as one edited while no server ran, which the start sweep measures before
57229
+ * as one edited while no server ran, which the start sweep measures after
57261
57230
  * the first board goes out. Every other frame's stored size already holds.
57262
57231
  */
57263
57232
  async function writtenSinceLayout(board) {
@@ -57286,11 +57255,8 @@ function ownFileRefs(board, paths) {
57286
57255
  }
57287
57256
  // src/server/live/rendered-findings.ts
57288
57257
  /**
57289
- * Runs `check` at the frame's own box, then at each linked width it lists,
57290
- * tagging each finding read at a linked width with that width. A linked
57291
- * finding the own box already reported, being the same rule and message at
57292
- * the same place, is left out, since it is no fault of that width. A null
57293
- * reading at any box answers null for the frame.
57258
+ * Runs `check` at the own box and each linked width, leaving out a linked
57259
+ * finding the own box already reported, since it is no fault of that width.
57294
57260
  */
57295
57261
  async function acrossWidths(frame, check) {
57296
57262
  const own = await check({
@@ -57321,13 +57287,8 @@ function sameness(finding) {
57321
57287
  ]);
57322
57288
  }
57323
57289
  /**
57324
- * The server's warm checker. Rechecks run one at a time on their own queue,
57325
- * so a PNG never waits behind them, and a ref queued again before its result
57326
- * lands drops that result, so the board never shows findings from an older
57327
- * file. `onResult` receives each landed frame's browser findings, an empty
57328
- * list for a frame whose recheck failed, so no finding outlives its file.
57329
- * The first recheck to run after a browser could not launch queues every
57330
- * frame again, since the ones checked meanwhile landed nothing.
57290
+ * The warm checker, on its own queue so a PNG never waits, dropping a result
57291
+ * a requeue made stale, so no finding outlives its file.
57331
57292
  */
57332
57293
  function createRenderedFindings({ check, onResult }) {
57333
57294
  const seen = /* @__PURE__ */ new Map();
@@ -57440,11 +57401,8 @@ function createSelectionHolder(tabs) {
57440
57401
  }
57441
57402
  // src/server/notes/delivery.ts
57442
57403
  /**
57443
- * The listener registry and the queue. A note stays `queued` on disk until a
57444
- * follower acks it, so a follower that drops before its ack gets it again on
57445
- * reconnect, and an acked note is never sent again. A session's flushes and
57446
- * acks run one at a time, since a flush that read the file before an ack
57447
- * landed would otherwise send the acked note again.
57404
+ * The listener registry and queue, a note staying `queued` until acked, with
57405
+ * a session's flushes and acks serialized so an acked note is never resent.
57448
57406
  */
57449
57407
  function createDelivery({ pending, markDelivered, onListeners, now }) {
57450
57408
  const sessions = /* @__PURE__ */ new Map();
@@ -57527,13 +57485,9 @@ const LINK_PREFIX = "/v/";
57527
57485
  /** The bytes of a link's token, 96 bits, which keeps the code small. */
57528
57486
  const TOKEN_BYTES = 12;
57529
57487
  /**
57530
- * The phone link's read-only app: GET and HEAD under `/v/<token>/` for one
57531
- * project's frames and assets at `frames/<project>/...` and the faces and
57532
- * board sheet at `frameboard/...`, each answered by the board's own frame and
57533
- * look routes, so their refusals of board records, dot-named paths, and
57534
- * escaping paths hold here unrestated. Anything else answers 404, so nothing
57535
- * tells a caller what exists. It carries no Host check, since a phone names
57536
- * the machine's address, and the token is what keeps other pages out.
57488
+ * The phone link's read-only app through the board's own routes, anything else
57489
+ * 404, and no Host check, since a phone names the machine's address and the
57490
+ * token keeps other pages out.
57537
57491
  */
57538
57492
  function previewApp(token, options) {
57539
57493
  const base = `${LINK_PREFIX}${token}`;
@@ -57560,10 +57514,11 @@ function previewApp(token, options) {
57560
57514
  }
57561
57515
  const theme = url.searchParams.get("theme");
57562
57516
  const query = theme === null ? "" : `?${new URLSearchParams({ theme })}`;
57563
- return served.fetch(new Request(`http://preview${inner}${query}`, {
57517
+ const answer = await served.fetch(new Request(`http://preview${inner}${query}`, {
57564
57518
  method,
57565
57519
  headers
57566
57520
  }));
57521
+ return method === "GET" ? withControlsHidden(answer) : answer;
57567
57522
  });
57568
57523
  return app;
57569
57524
  }
@@ -57587,6 +57542,21 @@ function innerPath(pathname, token, project) {
57587
57542
  }
57588
57543
  return decoded === project ? inner : null;
57589
57544
  }
57545
+ /**
57546
+ * A served frame with its drawn controls hidden, since the phone link shows
57547
+ * the design alone. Any answer other than a whole page passes as it is.
57548
+ */
57549
+ async function withControlsHidden(response) {
57550
+ if (!(response.status === 200 && (response.headers.get("Content-Type") ?? "").startsWith("text/html"))) return response;
57551
+ const bytes = new Uint8Array(await response.arrayBuffer());
57552
+ const headers = new Headers(response.headers);
57553
+ headers.delete("Content-Length");
57554
+ return new Response(injectHead(bytes, `<style ${LOOK_MARKER}>${HIDE_CONTROLS_CSS}</style>`), {
57555
+ status: response.status,
57556
+ statusText: response.statusText,
57557
+ headers
57558
+ });
57559
+ }
57590
57560
  /** The response with one header set, copied first since a forwarded one may be immutable. */
57591
57561
  function withHeader(response, name, value) {
57592
57562
  const headers = new Headers(response.headers);
@@ -57603,11 +57573,8 @@ function sameToken(given, token) {
57603
57573
  return a.length === b.length && timingSafeEqual(a, b);
57604
57574
  }
57605
57575
  /**
57606
- * Starts the phone listener on `host`, the machine's local network address,
57607
- * at `port`, or on a free port when that one is taken, with a fresh token.
57608
- * Binding the one address rather than every interface keeps the listener off
57609
- * any other network the machine sits on. The board's own listener is
57610
- * untouched, staying on loopback behind its Host check.
57576
+ * Starts the phone listener with a fresh token on the one local address, never
57577
+ * every interface, so it stays off any other network the machine sits on.
57611
57578
  */
57612
57579
  async function startPreviewListener(options) {
57613
57580
  const token = randomBytes(TOKEN_BYTES).toString("base64url");
@@ -57677,10 +57644,8 @@ function createPreviewSlot(options) {
57677
57644
  // src/server/start.ts
57678
57645
  const HOSTNAME = "127.0.0.1";
57679
57646
  /**
57680
- * How long a batch's changes wait before the board hears of them, so a hand
57681
- * write of many frames, whose first files can reach a batch at its 250 ms
57682
- * ceiling before the history records the step, is withdrawn as the board's
57683
- * own rather than marked.
57647
+ * How long a batch's changes wait, so a large hand write reaching a batch
57648
+ * before history records the step is withdrawn rather than marked.
57684
57649
  */
57685
57650
  const OWN_GRACE_MS = 1e3;
57686
57651
  /**
@@ -57689,10 +57654,8 @@ const OWN_GRACE_MS = 1e3;
57689
57654
  */
57690
57655
  const MOVED_MS = 1e4;
57691
57656
  /**
57692
- * The board tabs holding a live connection to this server, counting apart the
57693
- * ones that can write. The route a tab connects through calls `open` and
57694
- * `close`, and `serve` waits on a writer before deciding to open a tab of its
57695
- * own, since a tab typed in by hand reads the board but cannot change it.
57657
+ * The live board tabs, counting writers apart, since `serve` waits on a
57658
+ * writer and a hand-typed tab cannot change the board.
57696
57659
  */
57697
57660
  var BoardTabs = class {
57698
57661
  #count = 0;
@@ -58012,17 +57975,42 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
58012
57975
  created.once("error", reject);
58013
57976
  });
58014
57977
  server.on("upgrade", hub.handleUpgrade);
58015
- inTurn(async () => {
57978
+ const measuredAtStart = inTurn(async () => {
58016
57979
  await landReserved(root, /* @__PURE__ */ new Date()).catch(() => []);
58017
- let board = await scanBoard(root);
57980
+ const board = await scanBoard(root);
58018
57981
  const stale = await writtenSinceLayout(board).catch(() => []);
58019
- if (await hug.now(board, stale).catch(() => false)) board = await scanBoard(root);
58020
57982
  scanned.board = board;
58021
57983
  await tracker.prime(board);
58022
57984
  findings.update(board, "all");
58023
- rendered.queue(board, []);
58024
- hug.later(board, board.projects.flatMap((project) => project.pages.flatMap((page) => page.frames.map((frame) => frame.ref).filter((ref) => !stale.includes(ref)))));
58025
- });
57985
+ if (stale.length === 0) rendered.queue(board, []);
57986
+ hug.later(board, frameRefs(board).filter((ref) => !stale.includes(ref)));
57987
+ return {
57988
+ board,
57989
+ stale
57990
+ };
57991
+ }).then(async ({ board, stale }) => {
57992
+ if (stale.length === 0) return;
57993
+ const trails = await hug.now(board, stale).catch(() => false);
57994
+ await inTurn(async () => {
57995
+ if (closing) return;
57996
+ let latest = scanned.board ?? board;
57997
+ if (trails) {
57998
+ latest = await scanBoard(root);
57999
+ scanned.board = latest;
58000
+ hub.broadcast({
58001
+ type: "board",
58002
+ data: latest
58003
+ });
58004
+ shown.board = latest;
58005
+ const changed = findings.update(latest, framePaths(latest).filter(([ref]) => stale.includes(ref)).map(([, path]) => path));
58006
+ if (Object.keys(changed).length > 0) hub.broadcast({
58007
+ type: "findings",
58008
+ findings: changed
58009
+ });
58010
+ }
58011
+ rendered.queue(latest, []);
58012
+ });
58013
+ }).catch(() => {});
58026
58014
  claims.push();
58027
58015
  const watcher = await watchBoard(root, tokens ? [tokens] : []);
58028
58016
  watcher.onBatch(assetUsage.drop);
@@ -58074,6 +58062,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
58074
58062
  server.close((error) => error ? fail(error) : done());
58075
58063
  server.closeAllConnections();
58076
58064
  });
58065
+ await measuredAtStart;
58077
58066
  let tail;
58078
58067
  do {
58079
58068
  tail = scanning;
@@ -58085,12 +58074,8 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
58085
58074
  };
58086
58075
  }
58087
58076
  /**
58088
- * One rescan per batch: the whole board to every tab, then the frames to
58089
- * reload, marking their thumbnails stale in both themes without rendering
58090
- * any, then the findings of every frame the batch rechecked, queueing the
58091
- * same frames for the browser checker, then the notes of every page whose
58092
- * notes or frames it touched, whose queue it offers to delivery. The frames
58093
- * an agent changed wait out the grace before the board hears of them.
58077
+ * One rescan per batch, pushing the board, then reloads, then findings, then
58078
+ * notes, an agent's changes waiting out the grace before the board hears.
58094
58079
  */
58095
58080
  async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, hug, settleLater, moved, shown, scanned }) {
58096
58081
  let board;
@@ -58154,6 +58139,12 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
58154
58139
  rendered.queue(board, recheckRefs(root, paths, board, tokens));
58155
58140
  await pushNotes(root, paths, hub, delivery);
58156
58141
  }
58142
+ function frameRefs(board) {
58143
+ return framePaths(board).map(([ref]) => ref);
58144
+ }
58145
+ function framePaths(board) {
58146
+ return board.projects.flatMap((project) => project.pages).flatMap((page) => page.frames).map((frame) => [frame.ref, frame.path]);
58147
+ }
58157
58148
  /**
58158
58149
  * The content hash of each named frame's file as it stands now, which is
58159
58150
  * what its reload will render. A file that cannot be read is left out, so
@@ -58172,14 +58163,9 @@ async function ownFileHashes(board, refs) {
58172
58163
  return Object.fromEntries(read.flat());
58173
58164
  }
58174
58165
  /**
58175
- * Runs `outranked` over each settled agent write against the bytes it
58176
- * replaced, holding the result in place of the frame's previous write's, and
58177
- * returns the merged lists to send. A write raising nothing keeps a held
58178
- * warning while it still holds against the bytes that raised it, so a later
58179
- * edit elsewhere in the frame never clears it before `check` reports it.
58180
- * `raised` holds those bytes by ref. A created frame holds none. A frame
58181
- * rewritten since is left to the write that rewrote it, and a removed one to
58182
- * the batch that drops it.
58166
+ * Runs `outranked` over each settled agent write, keeping a warning while it
58167
+ * still holds against the bytes that raised it, so a later edit elsewhere never
58168
+ * clears it before `check` reports it.
58183
58169
  */
58184
58170
  function changeFindings(root, changes, tracker, findings, raised) {
58185
58171
  const sent = {};
@@ -58377,10 +58363,8 @@ function registerShow(program, context) {
58377
58363
  });
58378
58364
  }
58379
58365
  /**
58380
- * Each argument's canonical frame refs in the order given, a page standing
58381
- * for its frames in board order, and a frame named twice kept at its first
58382
- * place. An argument naming no frame and no page refuses the whole show
58383
- * with the frame's error, so nothing is posted.
58366
+ * Each argument's frame refs in order, a page standing for its frames, and any
58367
+ * unresolved argument refusing the whole show, so nothing is posted.
58384
58368
  */
58385
58369
  async function framesOf(root, args, options, cwd) {
58386
58370
  const scope = {
@@ -58424,15 +58408,9 @@ function referencedFiles(sheet) {
58424
58408
  return [...new Set(names)];
58425
58409
  }
58426
58410
  /**
58427
- * Copies each face every frame imports from its package into `outDir`,
58428
- * replacing what was there. Only the files a package sheet references are
58429
- * copied, and a reference to a file the package lacks throws. The faces fill
58430
- * a sibling folder first and rename into place, so `outDir` holds every file or does not exist, and an
58431
- * interrupted write leaves no half-filled face behind. Each sheet is
58432
- * rewritten to declare the plain family a frame names, such as Geist, rather
58433
- * than the package's own, such as Geist Variable. With `keepComplete`, a
58434
- * complete folder already there, as from a parallel run, stays as it is, so
58435
- * several processes can fill one cold folder at once.
58411
+ * Copies the frame faces into `outDir` through a sibling folder renamed into
58412
+ * place, so an interrupted write leaves no half-filled face, each sheet
58413
+ * declaring the plain family a frame names.
58436
58414
  */
58437
58415
  function writeFaces(outDir, { keepComplete = false, faces = FACES } = {}) {
58438
58416
  const staging = `${outDir}.${process.pid}.tmp`;
@@ -58469,10 +58447,8 @@ function writeFaces(outDir, { keepComplete = false, faces = FACES } = {}) {
58469
58447
  }
58470
58448
  const PLACE_ATTEMPTS = 3;
58471
58449
  /**
58472
- * Renames `staging` into `outDir` unless a complete folder is already there,
58473
- * as when another process filled a cold cache first. Only an incomplete
58474
- * folder is removed before the next attempt, since a reader may hold the path
58475
- * of a complete one.
58450
+ * Renames `staging` in unless a complete folder is there, removing only an
58451
+ * incomplete one, since a reader may hold a complete one's path.
58476
58452
  */
58477
58453
  function placeKeepingComplete(staging, outDir) {
58478
58454
  for (let attempt = 0; attempt < PLACE_ATTEMPTS; attempt++) {
@@ -58497,11 +58473,8 @@ function isOccupied(error) {
58497
58473
  }
58498
58474
  // src/cli/faces-dir.ts
58499
58475
  /**
58500
- * The folder the faces are served from. A built run reads the `faces` folder
58501
- * the build put beside the bundle and never looks further, so a bundle missing
58502
- * it fails loudly. A source run writes the faces once into the package's
58503
- * `node_modules/.cache` from the installed packages, and completes a cache
58504
- * missing any face.
58476
+ * The faces folder, a built run never looking past its bundle so a missing
58477
+ * folder fails loudly, and a source run filling `node_modules/.cache`.
58505
58478
  */
58506
58479
  function resolveFacesDir(moduleUrl = import.meta.url) {
58507
58480
  if (!moduleUrl.endsWith(".ts")) return fileURLToPath(new URL("./faces", moduleUrl));
@@ -58574,6 +58547,7 @@ function createProgram(context) {
58574
58547
  registerSelection(program, context);
58575
58548
  registerList(program, context);
58576
58549
  registerProject(program, context);
58550
+ registerKit(program, context);
58577
58551
  registerPage(program, context);
58578
58552
  registerFrame(program, faced);
58579
58553
  registerEdit(program, context);
@@ -58590,10 +58564,8 @@ function createProgram(context) {
58590
58564
  }
58591
58565
  // src/cli/run.ts
58592
58566
  /**
58593
- * Runs one command line and returns its exit code. Under `--json` stdout
58594
- * carries exactly one envelope, whether the command succeeded, failed, or
58595
- * never parsed. Without it, a failure prints `frameboard: <message>` to
58596
- * stderr, apart from commander's own parse errors, which it prints itself.
58567
+ * Runs one command line, under `--json` printing exactly one envelope whether
58568
+ * the command succeeded, failed, or never parsed.
58597
58569
  */
58598
58570
  async function runCli(argv, io, { clientDir } = {}) {
58599
58571
  const json = argv.includes("--json");