frameboard 0.11.0 → 0.13.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
@@ -3027,6 +3027,7 @@ const EXIT_CODES = {
3027
3027
  "verify-failed": 7,
3028
3028
  "invalid-utf8": 7,
3029
3029
  "stale-address": 7,
3030
+ "invalid-container": 7,
3030
3031
  "check-findings": 8,
3031
3032
  "browser-not-found": 9,
3032
3033
  "font-missing": 10,
@@ -9329,7 +9330,7 @@ async function isDirectory(path) {
9329
9330
  }
9330
9331
  }
9331
9332
  // package.json
9332
- var version$1 = "0.11.0";
9333
+ var version$1 = "0.13.0";
9333
9334
  var dependencies = { "playwright-core": "1.64.1" };
9334
9335
  // src/shared/version.ts
9335
9336
  const version = version$1;
@@ -19509,7 +19510,7 @@ import_postcss.default.atRule;
19509
19510
  import_postcss.default.rule;
19510
19511
  import_postcss.default.decl;
19511
19512
  import_postcss.default.root;
19512
- import_postcss.default.CssSyntaxError;
19513
+ const CssSyntaxError = import_postcss.default.CssSyntaxError;
19513
19514
  import_postcss.default.Declaration;
19514
19515
  import_postcss.default.Container;
19515
19516
  import_postcss.default.Processor;
@@ -27330,9 +27331,21 @@ function readFrame(target) {
27330
27331
  const pageDir = join(projectDir, target.page);
27331
27332
  const path = join(pageDir, `${target.name}${FRAME_EXTENSION}`);
27332
27333
  const html = readFileSync(path, "utf8");
27334
+ const parseErrors = [];
27333
27335
  const document = parse$3(html.replace(/^/, " "), {
27334
27336
  treeAdapter: adapter,
27335
- sourceCodeLocationInfo: true
27337
+ sourceCodeLocationInfo: true,
27338
+ onParseError: (error) => {
27339
+ parseErrors.push({
27340
+ code: error.code,
27341
+ location: {
27342
+ line: error.startLine,
27343
+ column: error.startCol,
27344
+ startOffset: error.startOffset,
27345
+ endOffset: error.endOffset
27346
+ }
27347
+ });
27348
+ }
27336
27349
  });
27337
27350
  const elements = [];
27338
27351
  const sheets = [];
@@ -27373,7 +27386,8 @@ function readFrame(target) {
27373
27386
  html,
27374
27387
  document,
27375
27388
  elements,
27376
- sheets
27389
+ sheets,
27390
+ parseErrors
27377
27391
  };
27378
27392
  }
27379
27393
  /**
@@ -27402,6 +27416,59 @@ function withImports(sheet, imported) {
27402
27416
  });
27403
27417
  return [...before, sheet];
27404
27418
  }
27419
+ /**
27420
+ * Parses `css` past every break postcss refuses, so a rule reads every
27421
+ * declaration a browser keeps. An unknown word, such as a declaration
27422
+ * missing its colon, is blanked out to its `;` or `}`, as a browser drops
27423
+ * that one declaration, with newlines kept so every offset holds. Any other
27424
+ * break, such as an unclosed block or string, cuts the sheet there, and the
27425
+ * cut's own leftovers are not breaks in the file, so none is recorded.
27426
+ */
27427
+ function parseSheet(css) {
27428
+ let text = css;
27429
+ const errors = [];
27430
+ let cut = false;
27431
+ for (;;) try {
27432
+ return {
27433
+ root: postcss_default.parse(text),
27434
+ errors
27435
+ };
27436
+ } catch (error) {
27437
+ if (!(error instanceof CssSyntaxError)) throw error;
27438
+ if (!cut) errors.push(error);
27439
+ const at = offsetOf(text, error.line ?? 1, error.column ?? 1);
27440
+ const span = cut ? null : unknownWordSpan(text, at, error);
27441
+ if (span) {
27442
+ const [start, end] = span;
27443
+ text = `${text.slice(0, start)}${text.slice(start, end).replace(/[^\n]/g, " ")}${text.slice(end)}`;
27444
+ } else {
27445
+ cut = true;
27446
+ text = at < text.length ? text.slice(0, at) : "";
27447
+ }
27448
+ }
27449
+ }
27450
+ /**
27451
+ * The declaration an unknown word sits in, from the `;` or `{` before it
27452
+ * through the `;` after it or up to a `}`, or null for any other break. The
27453
+ * span always holds the word, so each pass blanks at least one character.
27454
+ */
27455
+ function unknownWordSpan(text, at, error) {
27456
+ if (!error.reason.startsWith("Unknown word")) return null;
27457
+ const start = Math.max(text.lastIndexOf(";", at - 1), text.lastIndexOf("{", at - 1)) + 1;
27458
+ const next = text.slice(at).search(/[;}]/);
27459
+ const end = next === -1 ? text.length : at + next + (text[at + next] === ";" ? 1 : 0);
27460
+ return end > at && /\S/.test(text[at] ?? "") ? [start, end] : null;
27461
+ }
27462
+ /** The offset of a 1-based line and column in `text`. */
27463
+ function offsetOf(text, line, column) {
27464
+ let offset = 0;
27465
+ for (let at = 1; at < line; at++) {
27466
+ const next = text.indexOf("\n", offset);
27467
+ if (next === -1) return text.length;
27468
+ offset = next + 1;
27469
+ }
27470
+ return Math.min(offset + column - 1, text.length);
27471
+ }
27405
27472
  /** The URL an `@import` rule's parameters name, quoted or through `url()`. */
27406
27473
  function importUrl(params) {
27407
27474
  return /^\s*(?:url\(\s*)?(['"]?)([^'")\s]+)\1/i.exec(params)?.[2] ?? null;
@@ -28445,6 +28512,42 @@ function locate(source, tree, span, side) {
28445
28512
  });
28446
28513
  return found.length === 1 ? found[0] : void 0;
28447
28514
  }
28515
+ /**
28516
+ * Finds again in `source` the element `index` named in `was`, the source an
28517
+ * edit was made from, by the bytes its scope covers there, the way an undo
28518
+ * finds its element. The index holds while every byte through the whole
28519
+ * element is unchanged, its text included, since a start tag alone reads the
28520
+ * same on two swapped siblings. Otherwise the bytes must read once in `was` and once in
28521
+ * `source`, since a sibling sharing them could be the one left after a swap
28522
+ * or a removal. Answers undefined when those bytes changed, read twice, or
28523
+ * name no stated element, since writing on a guess would land over the
28524
+ * agent's work.
28525
+ */
28526
+ function relocate(was, index, scope, source) {
28527
+ const old = parseFrame(was);
28528
+ const element = old.elements[index];
28529
+ const range = element && rangeOf(element, scope);
28530
+ if (!range) return void 0;
28531
+ const text = was.slice(...range);
28532
+ const tree = parseFrame(source);
28533
+ const end = rangeOf(element, "element")?.[1] ?? range[1];
28534
+ if (source.slice(0, end) === was.slice(0, end)) {
28535
+ const held = matches(source, tree.elements[index], scope, text);
28536
+ if (held) return {
28537
+ index,
28538
+ range: held
28539
+ };
28540
+ }
28541
+ const once = (from, elements) => elements.flatMap((candidate, at) => {
28542
+ const found = matches(from, candidate, scope, text);
28543
+ return found ? [{
28544
+ index: at,
28545
+ range: found
28546
+ }] : [];
28547
+ });
28548
+ const found = once(source, tree.elements);
28549
+ return once(was, old.elements).length === 1 && found.length === 1 ? found[0] : void 0;
28550
+ }
28448
28551
  /** Whether the frame still holds the edited element as `side` of the edit left it. */
28449
28552
  function holdsSpan(source, span, side) {
28450
28553
  return locate(source, parseFrame(source), span, side) !== void 0;
@@ -28729,6 +28832,10 @@ function resolve$1(tree, index) {
28729
28832
  if (!element.sourceCodeLocation?.startTag) return refuse$1("address-mismatch", `<${element.tagName}> at ${index} is implied, not stated in the file`);
28730
28833
  return element;
28731
28834
  }
28835
+ /** Which bytes of the element a change reads and writes, as `SpanScope` splits them. */
28836
+ function scopeOf(change) {
28837
+ return change.kind === "text" ? "element" : "start-tag";
28838
+ }
28732
28839
  /** The attribute name an edit writes, or undefined for a text edit. */
28733
28840
  function editedAttribute(change) {
28734
28841
  if (change.kind === "style") return "style";
@@ -28814,7 +28921,7 @@ function applyEdit(source, address, change) {
28814
28921
  const after = parseFrame(written.html);
28815
28922
  const target = after.elements[address.index];
28816
28923
  if (!target || !holdsValue(target, normalized) || !changesOnlyTarget(before, after, address.index, normalized)) return refuse$1("verify-failed", `the edit to <${element.tagName}> would change more than that element, so nothing was written`);
28817
- const scope = normalized.kind === "text" ? "element" : "start-tag";
28924
+ const scope = scopeOf(normalized);
28818
28925
  const span = {
28819
28926
  scope,
28820
28927
  index: address.index,
@@ -28828,39 +28935,312 @@ function applyEdit(source, address, change) {
28828
28935
  span
28829
28936
  };
28830
28937
  }
28938
+ // src/server/edit/insert.ts
28939
+ const SHAPE_SIZE = "100px";
28940
+ const FILL_TOKENS = [
28941
+ "--muted",
28942
+ "--secondary",
28943
+ "--accent"
28944
+ ];
28945
+ const LINE_TOKEN = "--border";
28946
+ /** Raw on purpose, so the check names it once the project sets no color token. */
28947
+ const RAW_GREY = "#d9d9d9";
28948
+ const PAINT_VALUE = /^(?:var\(--[\w-]+\)|#[0-9a-f]{6})$/i;
28949
+ /** Elements no new element can sit inside, by what the parser does with one there. */
28950
+ const CLOSED = /* @__PURE__ */ new Set([
28951
+ "area",
28952
+ "base",
28953
+ "br",
28954
+ "col",
28955
+ "embed",
28956
+ "hr",
28957
+ "img",
28958
+ "input",
28959
+ "link",
28960
+ "meta",
28961
+ "source",
28962
+ "track",
28963
+ "wbr",
28964
+ "script",
28965
+ "style",
28966
+ "template",
28967
+ "textarea",
28968
+ "title",
28969
+ "noscript",
28970
+ "iframe",
28971
+ "html",
28972
+ "head"
28973
+ ]);
28974
+ /**
28975
+ * A shape's fill, being the first of the muted, secondary, and accent tokens
28976
+ * the project sets, else its first color token, and its line, being the
28977
+ * border token else that first color token. With no color token at all, both
28978
+ * are a raw grey.
28979
+ */
28980
+ function shapePaint(tokens) {
28981
+ const names = new Set(tokens.map((row) => row.name));
28982
+ const firstColor = tokens.find((row) => row.group === "color")?.name;
28983
+ const paint = (name) => name === void 0 ? RAW_GREY : `var(${name})`;
28984
+ return {
28985
+ fill: paint(FILL_TOKENS.find((name) => names.has(name)) ?? firstColor),
28986
+ line: paint(names.has(LINE_TOKEN) ? LINE_TOKEN : firstColor)
28987
+ };
28988
+ }
28989
+ /** Every byte an insert of `element` writes, with its `data-name` and default size. */
28990
+ function elementMarkup(element, paint) {
28991
+ const { fill, line } = paint;
28992
+ if (!PAINT_VALUE.test(fill) || !PAINT_VALUE.test(line)) throw new Error(`Unexpected shape paint ${fill} ${line}`);
28993
+ const box = `width: ${SHAPE_SIZE}; height: ${SHAPE_SIZE}; background: ${fill}`;
28994
+ switch (element.kind) {
28995
+ case "text": return "<p data-name=\"Text\">Text</p>";
28996
+ case "rectangle": return `<div data-name="Rectangle" style="${box}"></div>`;
28997
+ case "ellipse": return `<div data-name="Ellipse" style="${box}; border-radius: 50%"></div>`;
28998
+ case "divider": return `<hr data-name="Divider" style="align-self: stretch; margin: 0; border: 0; ${element.vertical ? "border-left" : "border-top"}: 1px solid ${line}">`;
28999
+ }
29000
+ }
29001
+ function startTag(source, element) {
29002
+ return spanText(source, element, "start-tag");
29003
+ }
29004
+ function children(element) {
29005
+ return element.childNodes.filter(hasTag);
29006
+ }
29007
+ /** The source offset the gap sits at, or a refusal when the file states none. */
29008
+ function gapOffset(tree, placement) {
29009
+ if (tree.unstated) return refuse$1("address-mismatch", `the browser builds a <${tree.unstated.tagName}> the file does not state, so indices after it disagree`);
29010
+ const { elements } = tree;
29011
+ const parent = Number.isInteger(placement.parent) ? elements[placement.parent] : void 0;
29012
+ if (!parent) return refuse$1("invalid-address", `the frame holds elements 0 to ${elements.length - 1}, so ${placement.parent} names none`);
29013
+ if (parent.namespaceURI !== NS.HTML || CLOSED.has(parent.tagName)) return refuse$1("invalid-container", `<${parent.tagName}> cannot hold a placed element`);
29014
+ if (placement.before !== null) {
29015
+ const child = elements[placement.before];
29016
+ const at = child?.sourceCodeLocation;
29017
+ if (!child || child.parentNode !== parent || !at?.startTag) return refuse$1("invalid-address", `${placement.before} names no stated child of the <${parent.tagName}> at ${placement.parent}`);
29018
+ return {
29019
+ parent,
29020
+ offset: at.startOffset
29021
+ };
29022
+ }
29023
+ const at = parent.sourceCodeLocation;
29024
+ if (at?.endTag) return {
29025
+ parent,
29026
+ offset: at.endTag.startOffset
29027
+ };
29028
+ const offset = parent.childNodes.findLast((node) => node.sourceCodeLocation)?.sourceCodeLocation?.endOffset ?? at?.startTag?.endOffset;
29029
+ if (offset === void 0) return refuse$1("address-mismatch", `the <${parent.tagName}> at ${placement.parent} states no place to put an element`);
29030
+ return {
29031
+ parent,
29032
+ offset
29033
+ };
29034
+ }
29035
+ /**
29036
+ * Writes `markup` into the gap and leaves every other byte as it was. The
29037
+ * output is parsed again and refused as `verify-failed` unless its tree is
29038
+ * the input's with that one element added under the parent, so a tag the
29039
+ * parser would move, as a `<div>` closing a `<p>`, is refused rather than
29040
+ * written somewhere else.
29041
+ */
29042
+ function insertElement(source, placement, markup) {
29043
+ const before = parseFrame(source);
29044
+ const gap = gapOffset(before, placement);
29045
+ if ("ok" in gap) return gap;
29046
+ const { parent, offset } = gap;
29047
+ const written = source.slice(0, offset) + markup + source.slice(offset);
29048
+ const after = parseFrame(written);
29049
+ const index = after.elements.findIndex((element) => element.sourceCodeLocation?.startOffset === offset);
29050
+ const added = after.elements[index];
29051
+ if (!added || after.elements.length !== before.elements.length + 1 || added.parentNode !== after.elements[placement.parent] || spanText(written, added, "element") !== markup || !addsOnly(before, after, added)) return refuse$1("verify-failed", `a <${added?.tagName ?? "new element"}> there would change more than the <${parent.tagName}> it goes in, so nothing was written`);
29052
+ const next = children(parent).find((child) => child.sourceCodeLocation?.startOffset === offset);
29053
+ return {
29054
+ ok: true,
29055
+ html: written,
29056
+ index,
29057
+ span: {
29058
+ markup,
29059
+ index,
29060
+ count: after.elements.length,
29061
+ placement,
29062
+ parent: {
29063
+ tagName: parent.tagName,
29064
+ tag: startTag(source, parent)
29065
+ },
29066
+ next: next ? startTag(source, next) : null
29067
+ }
29068
+ };
29069
+ }
29070
+ /** Whether `after` is `before` with `added` alone added, compared once it is taken out. */
29071
+ function addsOnly(before, after, added) {
29072
+ const parent = added.parentNode;
29073
+ parent.childNodes = parent.childNodes.filter((node) => node !== added);
29074
+ return serialize(before.document) === serialize(after.document);
29075
+ }
29076
+ /**
29077
+ * The inserted element as it stands: the one at the recorded index while the
29078
+ * element count is unchanged, else the one element whose bytes match, else
29079
+ * none, since taking out one of two would guess.
29080
+ */
29081
+ function locateInserted(source, tree, span) {
29082
+ const reads = (element) => element !== void 0 && spanText(source, element, "element") === span.markup;
29083
+ if (tree.elements.length === span.count) return reads(tree.elements[span.index]) ? span.index : void 0;
29084
+ const found = tree.elements.flatMap((element, index) => reads(element) ? [index] : []);
29085
+ return found.length === 1 ? found[0] : void 0;
29086
+ }
29087
+ /** The gap the span goes back into, read off its anchors where the frame now stands. */
29088
+ function locateGap(source, tree, span) {
29089
+ const reads = (element) => element !== void 0 && element.tagName === span.parent.tagName && startTag(source, element) === span.parent.tag;
29090
+ const candidates = tree.elements.length === span.count - 1 && reads(tree.elements[span.placement.parent]) ? [span.placement.parent] : tree.elements.flatMap((element, index) => reads(element) ? [index] : []);
29091
+ const parentIndex = candidates.length === 1 ? candidates[0] : void 0;
29092
+ const parent = parentIndex === void 0 ? void 0 : tree.elements[parentIndex];
29093
+ if (parentIndex === void 0 || !parent) return void 0;
29094
+ if (span.next === null) return {
29095
+ parent: parentIndex,
29096
+ before: null
29097
+ };
29098
+ const next = children(parent).filter((child) => startTag(source, child) === span.next);
29099
+ const [sibling] = next;
29100
+ return next.length === 1 && sibling ? {
29101
+ parent: parentIndex,
29102
+ before: tree.elements.indexOf(sibling)
29103
+ } : void 0;
29104
+ }
29105
+ /** Whether the frame stands as `side` of the insert left it, with the element or with its gap. */
29106
+ function holdsInserted(source, span, side) {
29107
+ const tree = parseFrame(source);
29108
+ return side === "after" ? locateInserted(source, tree, span) !== void 0 : locateGap(source, tree, span) !== void 0;
29109
+ }
29110
+ /**
29111
+ * Takes the inserted element out by its bytes and answers the span as the
29112
+ * frame then stands, so a redo finds its gap. Answers undefined when the
29113
+ * element is not found, or when taking it out would change more than it.
29114
+ */
29115
+ function removeInserted(source, span) {
29116
+ const tree = parseFrame(source);
29117
+ const index = locateInserted(source, tree, span);
29118
+ const element = index === void 0 ? void 0 : tree.elements[index];
29119
+ const at = element?.sourceCodeLocation;
29120
+ const parent = element?.parentNode;
29121
+ if (index === void 0 || !at || !parent || !hasTag(parent)) return void 0;
29122
+ const removed = source.slice(0, at.startOffset) + source.slice(at.endOffset);
29123
+ const next = children(parent)[children(parent).indexOf(element) + 1];
29124
+ const back = insertElement(removed, {
29125
+ parent: tree.elements.indexOf(parent),
29126
+ before: next ? index : null
29127
+ }, span.markup);
29128
+ if (!back.ok || back.html !== source) return void 0;
29129
+ return {
29130
+ html: removed,
29131
+ span: back.span
29132
+ };
29133
+ }
29134
+ /**
29135
+ * Writes the element back into its gap, found by the parent's and the next
29136
+ * sibling's start tags, and answers the span as it now stands. Answers
29137
+ * undefined when the gap is not found or the write is refused.
29138
+ */
29139
+ function restoreInserted(source, span) {
29140
+ const placement = locateGap(source, parseFrame(source), span);
29141
+ if (!placement) return void 0;
29142
+ const inserted = insertElement(source, placement, span.markup);
29143
+ return inserted.ok ? {
29144
+ html: inserted.html,
29145
+ span: inserted.span
29146
+ } : void 0;
29147
+ }
28831
29148
  // src/server/edit/frame-file.ts
28832
29149
  function stale(path) {
28833
29150
  return refuse$1("stale-address", `${basename(path)} changed after this edit was made, so nothing was written`);
28834
29151
  }
29152
+ function collided(path, was, index, source) {
29153
+ const old = parseFrame(was).elements;
29154
+ const element = old[index];
29155
+ if (!element) return stale(path);
29156
+ return {
29157
+ ...refuse$1("stale-address", `the agent changed this <${element.tagName}> in ${basename(path)} while your edit waited, so nothing was written`),
29158
+ moved: parseFrame(source).elements.length !== old.length
29159
+ };
29160
+ }
28835
29161
  /**
28836
29162
  * Edits one element of a frame file and replaces the file through a
28837
29163
  * temporary file and a rename. A file whose bytes do not survive a UTF-8
28838
29164
  * round trip is refused, since decoding would rewrite every invalid byte. An
28839
- * address carrying a hash the file no longer has is refused as stale, and the
28840
- * file is read again just before the rename so a write landing meanwhile is
28841
- * refused rather than overwritten. No lock is taken, since an agent's raw
28842
- * write never takes one and the hash is what protects a hand edit.
29165
+ * address carrying a hash the file no longer has is found again through
29166
+ * `sourceAt`, by the bytes the edit reads, and refused as stale when no source
29167
+ * is kept or those bytes changed. The file is read again just before the
29168
+ * rename so a write landing meanwhile is refused rather than overwritten. No
29169
+ * lock is taken, since an agent's raw write never takes one and the hash is
29170
+ * what protects a hand edit.
29171
+ */
29172
+ function editFrameFile(path, address, change, sourceAt) {
29173
+ const read = readSource(path);
29174
+ if (!read.ok) return read;
29175
+ const { source, hash } = read;
29176
+ let index = address.index;
29177
+ if (address.hash !== void 0 && address.hash !== hash) {
29178
+ const was = sourceAt?.(address.hash);
29179
+ if (!was) return stale(path);
29180
+ const found = relocate(was, address.index, scopeOf(change), source);
29181
+ if (!found) return collided(path, was, address.index, source);
29182
+ index = found.index;
29183
+ }
29184
+ const applied = applyEdit(source, { index }, change);
29185
+ if (!applied.ok) return applied;
29186
+ if (!replaceFile(path, hash, applied.html)) return stale(path);
29187
+ return {
29188
+ ok: true,
29189
+ hash: contentHash(applied.html),
29190
+ from: hash,
29191
+ index,
29192
+ span: applied.span
29193
+ };
29194
+ }
29195
+ /**
29196
+ * Writes one new element into a frame file the way `editFrameFile` writes an
29197
+ * edit, through a temporary file and a rename after reading the file again.
29198
+ * A hash the file no longer has is refused as stale with no search, since the
29199
+ * gap's indices name nothing once the file moved, which also lands a retried
29200
+ * insert at most once.
28843
29201
  */
28844
- function editFrameFile(path, address, change) {
29202
+ function insertFrameFile(path, hash, placement, markup) {
29203
+ const read = readSource(path);
29204
+ if (!read.ok) return read;
29205
+ if (read.hash !== hash) return stale(path);
29206
+ const inserted = insertElement(read.source, placement, markup);
29207
+ if (!inserted.ok) return inserted;
29208
+ if (!replaceFile(path, hash, inserted.html)) return stale(path);
29209
+ return {
29210
+ ok: true,
29211
+ hash: contentHash(inserted.html),
29212
+ index: inserted.index,
29213
+ span: inserted.span
29214
+ };
29215
+ }
29216
+ /**
29217
+ * A frame file's text and hash. Bytes that do not survive a UTF-8 round trip
29218
+ * are refused, since decoding would rewrite every invalid byte.
29219
+ */
29220
+ function readSource(path) {
28845
29221
  const bytes = readFileSync(path);
28846
29222
  const source = bytes.toString("utf8");
28847
29223
  if (!Buffer.from(source, "utf8").equals(bytes)) return refuse$1("invalid-utf8", `${basename(path)} is not valid UTF-8, so writing it back would change bytes outside the edit`);
28848
- const hash = contentHash(bytes);
28849
- if (address.hash !== void 0 && address.hash !== hash) return stale(path);
28850
- const applied = applyEdit(source, address, change);
28851
- if (!applied.ok) return applied;
29224
+ return {
29225
+ ok: true,
29226
+ source,
29227
+ hash: contentHash(bytes)
29228
+ };
29229
+ }
29230
+ /**
29231
+ * Replaces the file with `html` while it still holds the bytes `hash` names,
29232
+ * read again just before the rename. Answers false, leaving the newer bytes,
29233
+ * when a write landed meanwhile.
29234
+ */
29235
+ function replaceFile(path, hash, html) {
28852
29236
  const temp = join(dirname(path), `.${basename(path)}.${process.pid}.tmp`);
28853
- writeFileSync(temp, applied.html);
29237
+ writeFileSync(temp, html);
28854
29238
  if (contentHash(readFileSync(path)) !== hash) {
28855
29239
  rmSync(temp, { force: true });
28856
- return stale(path);
29240
+ return false;
28857
29241
  }
28858
29242
  renameSync(temp, path);
28859
- return {
28860
- ok: true,
28861
- hash: contentHash(applied.html),
28862
- span: applied.span
28863
- };
29243
+ return true;
28864
29244
  }
28865
29245
  // src/server/routes/envelope.ts
28866
29246
  /** The status each refusal of a structure or history write answers with. */
@@ -28929,24 +29309,52 @@ const editSchema = object$1({
28929
29309
  })
28930
29310
  ])
28931
29311
  });
29312
+ const insertSchema = object$1({
29313
+ ref: string$1().min(1).max(1024),
29314
+ hash: string$1().regex(/^[0-9a-f]{64}$/),
29315
+ parent: int$1().min(0),
29316
+ before: int$1().min(0).nullable(),
29317
+ element: discriminatedUnion("kind", [
29318
+ object$1({ kind: literal("text") }),
29319
+ object$1({ kind: literal("rectangle") }),
29320
+ object$1({ kind: literal("ellipse") }),
29321
+ object$1({
29322
+ kind: literal("divider"),
29323
+ vertical: boolean$1()
29324
+ })
29325
+ ])
29326
+ });
28932
29327
  /**
28933
- * A hand edit of one element, behind `requireWriter`, its body mirroring
29328
+ * A hand edit of one element and a placed element, each behind
29329
+ * `requireWriter` and refused on a frame another session holds.
29330
+ *
29331
+ * The edit's body mirrors
28934
29332
  * `edit`'s flags with the hash required, since the board always holds the
28935
- * one it rendered. It writes through `editFrameFile`, records the edited
28936
- * element's span as one step, and answers the `edit` record. Each refusal
28937
- * the writer returns answers 409 with its code, `stale-address` among them.
28938
- */
28939
- function editRoutes(root, access, history) {
29333
+ * one it rendered. It writes through `editFrameFile`, which finds the element
29334
+ * again in a frame an agent wrote since from the source `version` kept, and
29335
+ * records the edited element's span as one step. It answers the `edit`
29336
+ * record with the index written and the hash written over. Each refusal the
29337
+ * writer returns answers 409 with its code, `stale-address` among them.
29338
+ *
29339
+ * The insert takes an element kind, never markup, and writes that kind's one
29340
+ * tag into the gap `parent` and `before` name, painted from the project's
29341
+ * tokens through `sheets`, and records it as one step. It answers the frame,
29342
+ * the new element's index, and the hash written. A hash the file no longer
29343
+ * has answers 409 `stale-address` with nothing written, since the gap's
29344
+ * indices name nothing past an agent's write, and a retried insert lands once.
29345
+ */
29346
+ function editRoutes(root, access, history, version, sheets) {
28940
29347
  const app = new Hono();
28941
29348
  app.post("/api/frames/edit", requireWriter(access), async (c) => {
28942
29349
  const body = await parseBody$1(c.req.raw, editSchema);
28943
29350
  const frame = await resolveFrameRef(root, body.ref, { cwd: root });
28944
29351
  const ref = `${frame.project}/${frame.page}/${frame.name}`;
28945
29352
  await refuseClaimed(root, [ref], /* @__PURE__ */ new Date());
29353
+ const was = contentHash(await readFile(frame.path)) !== body.hash ? await version?.(ref, body.hash) ?? null : null;
28946
29354
  const result = editFrameFile(frame.path, {
28947
29355
  index: body.index,
28948
29356
  hash: body.hash
28949
- }, body.change);
29357
+ }, body.change, (hash) => hash === body.hash ? was : null);
28950
29358
  if (!result.ok) return c.json({
28951
29359
  ok: false,
28952
29360
  error: {
@@ -28954,7 +29362,8 @@ function editRoutes(root, access, history) {
28954
29362
  message: result.detail,
28955
29363
  details: {
28956
29364
  ref,
28957
- index: body.index
29365
+ index: body.index,
29366
+ ..."moved" in result ? { moved: result.moved } : {}
28958
29367
  }
28959
29368
  }
28960
29369
  }, 409);
@@ -28970,7 +29379,47 @@ function editRoutes(root, access, history) {
28970
29379
  }
28971
29380
  const data = {
28972
29381
  ref,
28973
- index: body.index,
29382
+ index: result.index,
29383
+ hash: result.hash,
29384
+ from: result.from
29385
+ };
29386
+ return c.json({
29387
+ ok: true,
29388
+ data
29389
+ });
29390
+ });
29391
+ app.post("/api/frames/insert", requireWriter(access), async (c) => {
29392
+ const body = await parseBody$1(c.req.raw, insertSchema);
29393
+ const frame = await resolveFrameRef(root, body.ref, { cwd: root });
29394
+ const ref = `${frame.project}/${frame.page}/${frame.name}`;
29395
+ await refuseClaimed(root, [ref], /* @__PURE__ */ new Date());
29396
+ const tokens = sheets ? readTokenTable(root, sheets(frame.project)).tokens : [];
29397
+ const result = insertFrameFile(frame.path, body.hash, {
29398
+ parent: body.parent,
29399
+ before: body.before
29400
+ }, elementMarkup(body.element, shapePaint(tokens)));
29401
+ if (!result.ok) return c.json({
29402
+ ok: false,
29403
+ error: {
29404
+ code: result.reason,
29405
+ message: result.detail,
29406
+ details: {
29407
+ ref,
29408
+ parent: body.parent
29409
+ }
29410
+ }
29411
+ }, 409);
29412
+ const journal = history.journal();
29413
+ journal.inserted(frame.path, ref, result.span);
29414
+ history.record({
29415
+ id: journal.id,
29416
+ changes: journal.changes,
29417
+ page: null,
29418
+ frames: [ref]
29419
+ });
29420
+ const data = {
29421
+ ref,
29422
+ index: result.index,
28974
29423
  hash: result.hash
28975
29424
  };
28976
29425
  return c.json({
@@ -29024,63 +29473,6 @@ function tokenSheets(root, project, tokens) {
29024
29473
  offset: 0
29025
29474
  }));
29026
29475
  }
29027
- // src/server/edit/elements.ts
29028
- /** How long a text-only element's text may run as its name. */
29029
- const NAME_LENGTH = 40;
29030
- /**
29031
- * A frame's elements under `body` in index order, each with its parent and
29032
- * name, read from the same parse and the same index `edit` addresses. A
29033
- * frame where the browser builds an element the file does not state is
29034
- * refused, since every index after it would name another element.
29035
- */
29036
- function elementTree(source) {
29037
- const tree = parseFrame(source);
29038
- if (tree.unstated) return refuse$1("address-mismatch", `the browser builds a <${tree.unstated.tagName}> the file does not state, so indices after it disagree`);
29039
- const index = new Map(tree.elements.map((element, at) => [element, at]));
29040
- const body = tree.elements.find((element) => element.tagName === "body");
29041
- const listed = [];
29042
- const inBody = /* @__PURE__ */ new Set();
29043
- for (const [at, element] of tree.elements.entries()) {
29044
- const parent = element.parentNode;
29045
- if (!body || !parent || !hasTag(parent)) continue;
29046
- if (parent !== body && !inBody.has(parent)) continue;
29047
- inBody.add(element);
29048
- listed.push({
29049
- index: at,
29050
- parent: parent === body ? null : index.get(parent) ?? null,
29051
- tag: element.tagName,
29052
- name: elementName(element),
29053
- textOnly: ownText$2(element) !== null
29054
- });
29055
- }
29056
- return listed;
29057
- }
29058
- /**
29059
- * What an element is called in the layers rows, the inspector, and the
29060
- * `selection` verb: its `data-name`, else a text-only element's text, else
29061
- * an `img`'s `alt`, else its tag. `id` and `aria-label` already mean
29062
- * something to a frame's CSS, scripts, and readers, so neither names it.
29063
- */
29064
- function elementName(element) {
29065
- const named = attribute(element, "data-name")?.trim();
29066
- if (named) return named;
29067
- const text = ownText$2(element);
29068
- if (text !== null) return text.slice(0, NAME_LENGTH);
29069
- return (element.tagName === "img" ? attribute(element, "alt")?.trim() : "") || element.tagName;
29070
- }
29071
- /** The whitespace-collapsed text of an element holding text alone, else null. */
29072
- function ownText$2(element) {
29073
- const texts = element.childNodes.filter(isText);
29074
- if (texts.length === 0 || texts.length !== element.childNodes.length) return null;
29075
- const text = texts.map((node) => node.value).join("").replace(/\s+/g, " ").trim();
29076
- return text === "" ? null : text;
29077
- }
29078
- function isText(node) {
29079
- return node.nodeName === "#text";
29080
- }
29081
- function attribute(element, name) {
29082
- return element.attrs.find((attr) => attr.name === name)?.value;
29083
- }
29084
29476
  // node_modules/@bramus/specificity/dist/index.js
29085
29477
  var Jn = Object.create;
29086
29478
  var te = Object.defineProperty;
@@ -33856,7 +34248,8 @@ const READ = /* @__PURE__ */ new Set([
33856
34248
  const SHORTHANDS = {
33857
34249
  font: ["font-family"],
33858
34250
  background: ["background-color"],
33859
- border: ["border-color", "border-width"]
34251
+ border: ["border-color", "border-width"],
34252
+ "flex-flow": ["flex-direction", "flex-wrap"]
33860
34253
  };
33861
34254
  /** The properties an element takes from its parent when no rule sets them. */
33862
34255
  const INHERITED = /* @__PURE__ */ new Set([
@@ -34166,6 +34559,92 @@ function shorthandFamily(value) {
34166
34559
  const family = tokens.slice(familyAt).join(" ");
34167
34560
  return family === "" ? null : family;
34168
34561
  }
34562
+ // src/server/edit/elements.ts
34563
+ /** How long a text-only element's text may run as its name. */
34564
+ const NAME_LENGTH = 40;
34565
+ /** What the layout read takes from the cascade, with the shorthand that sets the direction. */
34566
+ const LAYOUT_PROPERTIES = /* @__PURE__ */ new Set([
34567
+ "display",
34568
+ "flex-direction",
34569
+ "flex-flow"
34570
+ ]);
34571
+ /**
34572
+ * A frame's elements under `body` in index order, each with its parent and
34573
+ * name, read from the same parse and the same index `edit` addresses. A
34574
+ * frame where the browser builds an element the file does not state is
34575
+ * refused, since every index after it would name another element.
34576
+ * `layouts` is `elementLayouts`'s read by the same index, and an element it
34577
+ * does not reach reads as `block`.
34578
+ */
34579
+ function elementTree(source, layouts = []) {
34580
+ const tree = parseFrame(source);
34581
+ if (tree.unstated) return refuse$1("address-mismatch", `the browser builds a <${tree.unstated.tagName}> the file does not state, so indices after it disagree`);
34582
+ const index = new Map(tree.elements.map((element, at) => [element, at]));
34583
+ const body = tree.elements.find((element) => element.tagName === "body");
34584
+ const listed = [];
34585
+ const inBody = /* @__PURE__ */ new Set();
34586
+ for (const [at, element] of tree.elements.entries()) {
34587
+ const parent = element.parentNode;
34588
+ if (!body || !parent || !hasTag(parent)) continue;
34589
+ if (parent !== body && !inBody.has(parent)) continue;
34590
+ inBody.add(element);
34591
+ listed.push({
34592
+ index: at,
34593
+ parent: parent === body ? null : index.get(parent) ?? null,
34594
+ tag: element.tagName,
34595
+ name: elementName(element),
34596
+ textOnly: ownText$2(element) !== null,
34597
+ layout: layouts[at] ?? "block"
34598
+ });
34599
+ }
34600
+ return listed;
34601
+ }
34602
+ /**
34603
+ * Every element's layout by the edit index, read from the static cascade
34604
+ * over the token sheets and the frame's own, as `frameStyles` reads colors,
34605
+ * so a culled frame with no iframe still answers. Every media query counts
34606
+ * as applying, so a frame that flips its direction at a breakpoint reads as
34607
+ * whichever rule wins statically.
34608
+ */
34609
+ function elementLayouts(source, tokens) {
34610
+ const cascade = buildCascade(source, tokens, { properties: LAYOUT_PROPERTIES });
34611
+ return source.elements.map((element) => layoutOf(cascade, element));
34612
+ }
34613
+ function layoutOf(cascade, element) {
34614
+ const display = words(cascade.specified(element, "display")?.value);
34615
+ if (display.includes("grid") || display.includes("inline-grid")) return "grid";
34616
+ if (!display.includes("flex") && !display.includes("inline-flex")) return "block";
34617
+ return words(cascade.specified(element, "flex-direction")?.value).some((word) => word.startsWith("column")) ? "column" : "row";
34618
+ }
34619
+ function words(value) {
34620
+ return value?.trim().toLowerCase().split(/\s+/) ?? [];
34621
+ }
34622
+ /**
34623
+ * What an element is called in the layers rows, the inspector, and the
34624
+ * `selection` verb: its `data-name`, else a text-only element's text, else
34625
+ * an `img`'s `alt`, else its tag. `id` and `aria-label` already mean
34626
+ * something to a frame's CSS, scripts, and readers, so neither names it.
34627
+ */
34628
+ function elementName(element) {
34629
+ const named = attribute(element, "data-name")?.trim();
34630
+ if (named) return named;
34631
+ const text = ownText$2(element);
34632
+ if (text !== null) return text.slice(0, NAME_LENGTH);
34633
+ return (element.tagName === "img" ? attribute(element, "alt")?.trim() : "") || element.tagName;
34634
+ }
34635
+ /** The whitespace-collapsed text of an element holding text alone, else null. */
34636
+ function ownText$2(element) {
34637
+ const texts = element.childNodes.filter(isText);
34638
+ if (texts.length === 0 || texts.length !== element.childNodes.length) return null;
34639
+ const text = texts.map((node) => node.value).join("").replace(/\s+/g, " ").trim();
34640
+ return text === "" ? null : text;
34641
+ }
34642
+ function isText(node) {
34643
+ return node.nodeName === "#text";
34644
+ }
34645
+ function attribute(element, name) {
34646
+ return element.attrs.find((attr) => attr.name === name)?.value;
34647
+ }
34169
34648
  // src/server/look/colors.ts
34170
34649
  /** What the inspector reads, with the shorthands that set it. */
34171
34650
  const PROPERTIES = /* @__PURE__ */ new Set([
@@ -34366,7 +34845,8 @@ const STATUS$2 = {
34366
34845
  };
34367
34846
  /**
34368
34847
  * A frame's element tree, read from the file rather than a live iframe so a
34369
- * culled frame lists the indices `edit` addresses, and the selection the
34848
+ * culled frame lists the indices `edit` addresses, with each element's
34849
+ * layout read from the static cascade over `tokens`, and the selection the
34370
34850
  * writing tab last reported, which `POST /api/selection` takes behind
34371
34851
  * `requireWriter` and `GET /api/selection` answers as the `selection` record.
34372
34852
  * `GET /api/frames/styles` answers a frame's or an element's colors from the
@@ -34378,7 +34858,8 @@ function elementsRoutes(root, access, selection, tokens = null) {
34378
34858
  const readTree = async (ref) => {
34379
34859
  const frame = await resolveFrameRef(root, ref, { cwd: root });
34380
34860
  const bytes = await readFile(frame.path);
34381
- const elements = elementTree(bytes.toString("utf8"));
34861
+ const layouts = elementLayouts(readFrame(frame), tokenSheets(root, frame.project, tokens));
34862
+ const elements = elementTree(bytes.toString("utf8"), layouts);
34382
34863
  if (!Array.isArray(elements)) throw new FrameboardError(elements.reason, elements.detail, { ref });
34383
34864
  return {
34384
34865
  ref: `${frame.project}/${frame.page}/${frame.name}`,
@@ -36241,7 +36722,7 @@ function boardHostGuard(port) {
36241
36722
  await next();
36242
36723
  };
36243
36724
  }
36244
- function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails, measure, frameVersion }) {
36725
+ function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails, measure, frameVersion, settledVersion }) {
36245
36726
  const app = new Hono();
36246
36727
  const given = tokens ?? null;
36247
36728
  app.use("*", async (c, next) => {
@@ -36267,7 +36748,7 @@ function createApp({ clientDir, root, port, actions, tickets, renderFrame, faces
36267
36748
  app.route("/", assetsRoutes(root, actions.access));
36268
36749
  app.route("/", elementsRoutes(root, actions.access, selection, given));
36269
36750
  app.route("/", findRoutes(root));
36270
- app.route("/", editRoutes(root, actions.access, history));
36751
+ app.route("/", editRoutes(root, actions.access, history, settledVersion, frames.look.sheets));
36271
36752
  app.route("/", pngRoutes(root, renderFrame));
36272
36753
  if (checks) app.route("/", checkRoutes(actions.access, checks));
36273
36754
  if (thumbnails) app.route("/", thumbnailRoutes(root, thumbnails));
@@ -36802,6 +37283,71 @@ async function pageOf(root, ref, options) {
36802
37283
  function describe$6(images) {
36803
37284
  return images.map((image) => `Wrote ${image.path}`).join("\n");
36804
37285
  }
37286
+ // src/server/checks/custom-properties.ts
37287
+ const CUSTOM_PROPERTY_RULES = [{
37288
+ id: "unknown-token",
37289
+ tier: "exact",
37290
+ description: "A var() with no fallback names a custom property no token sheet, frame sheet, or style attribute declares"
37291
+ }];
37292
+ /** A `var()` naming its property, with no fallback after a comma. */
37293
+ const BARE_VAR = /var\(\s*(--[\w-]+)\s*\)/g;
37294
+ /**
37295
+ * `unknown-token`, one finding per bare `var()` in the frame's own sheets
37296
+ * and style attributes whose name nothing declares. A token sheet's own
37297
+ * references are the board's to answer for, so only its declarations count.
37298
+ * A property a script sets reads as unknown, which a fallback silences.
37299
+ */
37300
+ function checkUnknownTokens(source, tokens) {
37301
+ const declared = /* @__PURE__ */ new Set();
37302
+ const uses = [];
37303
+ for (const sheet of [...tokens, ...source.sheets]) {
37304
+ const { root } = parseSheet(sheet.css);
37305
+ root.walkAtRules(/^property$/i, (rule) => {
37306
+ declared.add(rule.params.trim());
37307
+ });
37308
+ const text = sheet.origin === "style" ? source.html : sheet.css;
37309
+ root.walkDecls((node) => {
37310
+ if (node.prop.startsWith("--")) declared.add(node.prop);
37311
+ if (sheet.origin === "token") return;
37312
+ for (const name of bareVars(node.value)) uses.push({
37313
+ name,
37314
+ path: boardPath(source.root, sheet.path),
37315
+ location: locate$1(text, sheet.offset + (node.source?.start?.offset ?? 0), sheet.offset + (node.source?.end?.offset ?? 0))
37316
+ });
37317
+ });
37318
+ }
37319
+ const framePath = boardPath(source.root, source.path);
37320
+ for (const element of source.elements) {
37321
+ const style = element.attribs.style;
37322
+ if (!style) continue;
37323
+ const root = parseOrNull(`x{${style}}`);
37324
+ if (!root) continue;
37325
+ root.walkDecls((node) => {
37326
+ if (node.prop.startsWith("--")) declared.add(node.prop);
37327
+ for (const name of bareVars(node.value)) uses.push({
37328
+ name,
37329
+ path: framePath,
37330
+ location: attributeLocation(element, "style")
37331
+ });
37332
+ });
37333
+ }
37334
+ return uses.filter((use) => !declared.has(use.name)).map((use) => finding("unknown-token", {
37335
+ frame: source.ref,
37336
+ path: use.path,
37337
+ message: `var(${use.name}) names a custom property nothing declares, so the declaration resolves to nothing. Use a token the project's tokens.css declares, or give it a fallback, such as var(${use.name}, red).`,
37338
+ location: use.location
37339
+ }));
37340
+ }
37341
+ function bareVars(value) {
37342
+ return [...new Set([...value.matchAll(BARE_VAR)].map((match) => match[1] ?? ""))];
37343
+ }
37344
+ function parseOrNull(css) {
37345
+ try {
37346
+ return postcss_default.parse(css);
37347
+ } catch {
37348
+ return null;
37349
+ }
37350
+ }
36805
37351
  // src/server/checks/fonts.ts
36806
37352
  const FONT_RULES = [
36807
37353
  {
@@ -37057,8 +37603,76 @@ const STRUCTURE_RULES = [
37057
37603
  id: "table-tbody",
37058
37604
  tier: "exact",
37059
37605
  description: "A table holding rows states its <tbody>, since the browser adds one the file does not hold"
37606
+ },
37607
+ {
37608
+ id: "malformed-tag",
37609
+ tier: "exact",
37610
+ description: "A tag or attribute the HTML tokenizer cannot read as written, such as a quote ending an attribute early, which the browser recovers from silently"
37611
+ },
37612
+ {
37613
+ id: "nesting",
37614
+ tier: "exact",
37615
+ description: "The browser rebuilds the tree the file writes, adding an element it never opens, closing one it never closed, or moving one out of a table"
37060
37616
  }
37061
37617
  ];
37618
+ /**
37619
+ * Elements a parser may imply with no start tag in a valid file. A `tbody`
37620
+ * is `table-tbody`'s to report.
37621
+ */
37622
+ const IMPLIED = /* @__PURE__ */ new Set([
37623
+ "html",
37624
+ "head",
37625
+ "body",
37626
+ "tbody",
37627
+ "colgroup"
37628
+ ]);
37629
+ /** HTML elements whose end tag a valid file may leave out, void ones included. */
37630
+ const OPTIONAL_END = /* @__PURE__ */ new Set([
37631
+ "html",
37632
+ "head",
37633
+ "body",
37634
+ "li",
37635
+ "dt",
37636
+ "dd",
37637
+ "p",
37638
+ "rt",
37639
+ "rp",
37640
+ "optgroup",
37641
+ "option",
37642
+ "colgroup",
37643
+ "caption",
37644
+ "thead",
37645
+ "tbody",
37646
+ "tfoot",
37647
+ "tr",
37648
+ "td",
37649
+ "th",
37650
+ "area",
37651
+ "base",
37652
+ "br",
37653
+ "col",
37654
+ "embed",
37655
+ "hr",
37656
+ "img",
37657
+ "input",
37658
+ "link",
37659
+ "meta",
37660
+ "source",
37661
+ "track",
37662
+ "wbr",
37663
+ "param",
37664
+ "keygen"
37665
+ ]);
37666
+ const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
37667
+ /** What `malformed-tag` tells the agent for each tokenizer code it reports. */
37668
+ const MALFORMED = {
37669
+ "missing-whitespace-between-attributes": "An attribute value ends early, so the browser reads the rest as stray attributes. Use single quotes inside a double-quoted value, such as font-family:Geist,'DejaVu Sans'.",
37670
+ "unexpected-character-in-attribute-name": "An attribute name holds a quote, <, or =, most often the rest of a value a quote inside it ended early. Use single quotes inside a double-quoted value.",
37671
+ "unexpected-equals-sign-before-attribute-name": "An = stands where an attribute name should, so the browser reads it as the name. Remove it or name the attribute.",
37672
+ "duplicate-attribute": "This tag states one attribute twice, and the browser drops the second. Keep one.",
37673
+ "eof-in-tag": "The file ends inside a tag, so the browser drops the tag. Close it.",
37674
+ "unexpected-character-in-unquoted-attribute-value": "An unquoted attribute value holds a quote, <, =, or backtick. Quote the value."
37675
+ };
37062
37676
  /** `naming`, read from the frame's path alone. */
37063
37677
  function checkNaming(target, path) {
37064
37678
  const ref = `${target.project}/${target.page}/${target.name}`;
@@ -37103,6 +37717,95 @@ function checkMarkup(source) {
37103
37717
  }));
37104
37718
  return findings;
37105
37719
  }
37720
+ /**
37721
+ * `malformed-tag`, one finding per start tag the tokenizer refused, at its
37722
+ * first error, since one stray quote raises several codes in one tag.
37723
+ */
37724
+ function checkMalformedTags(source) {
37725
+ const path = boardPath(source.root, source.path);
37726
+ const reported = /* @__PURE__ */ new Set();
37727
+ const findings = [];
37728
+ for (const error of source.parseErrors) {
37729
+ const message = MALFORMED[error.code];
37730
+ if (message === void 0) continue;
37731
+ const tag = source.elements.find((element) => {
37732
+ const start = element.sourceCodeLocation?.startTag;
37733
+ return start !== void 0 && start.startOffset <= error.location.startOffset && error.location.startOffset < start.endOffset;
37734
+ });
37735
+ if (tag) {
37736
+ if (reported.has(tag)) continue;
37737
+ reported.add(tag);
37738
+ }
37739
+ findings.push(finding("malformed-tag", {
37740
+ frame: source.ref,
37741
+ path,
37742
+ message: `${tag ? `<${tag.name}> raises ${error.code}` : error.code}. ${message}`,
37743
+ location: error.location
37744
+ }));
37745
+ }
37746
+ return findings;
37747
+ }
37748
+ /**
37749
+ * `nesting`, one finding per element the parser rebuilt: one it implied with
37750
+ * no start tag, an HTML element whose end tag never matched, and one moved
37751
+ * ahead of a sibling the file writes first, which is a table's foster
37752
+ * parenting. Foreign elements are left to close themselves.
37753
+ */
37754
+ function checkNesting(source) {
37755
+ const path = boardPath(source.root, source.path);
37756
+ const findings = [];
37757
+ const report = (message, location) => findings.push(finding("nesting", {
37758
+ frame: source.ref,
37759
+ path,
37760
+ message,
37761
+ location
37762
+ }));
37763
+ const fostered = fosteredElements(source.elements);
37764
+ for (const element of source.elements) {
37765
+ const location = element.sourceCodeLocation;
37766
+ if (!location?.startTag) {
37767
+ if (IMPLIED.has(element.name)) continue;
37768
+ const hint = element.name === "p" ? " A <p> holds text alone, so a block such as <div> inside it closes it early. Use a <div> for the outer box." : "";
37769
+ report(`The browser adds a <${element.name}> the file never opens, from a </${element.name}> with nothing open to close or a tag closed out of order.${hint}`, strayEndTag(source.html, element));
37770
+ } else if (!location.endTag && element.namespace === HTML_NAMESPACE && !OPTIONAL_END.has(element.name)) report(`<${element.name}> never meets its own end tag, so the browser closes it where the file did not. Close it inside its parent, and check it holds nothing it cannot, such as an <a> inside an <a>.`, startTagLocation(element));
37771
+ else if (fostered.has(element)) report(`The browser moves this <${element.name}> out ahead of its table, since a table holds its rows and cells alone. Put it inside a <td>, or outside the table.`, startTagLocation(element));
37772
+ }
37773
+ return findings;
37774
+ }
37775
+ /** Elements placed ahead of a later sibling the file writes before them. */
37776
+ function fosteredElements(elements) {
37777
+ const parents = new Set(elements.map((element) => element.parent));
37778
+ const fostered = /* @__PURE__ */ new Set();
37779
+ for (const parent of parents) {
37780
+ if (!parent) continue;
37781
+ let earliest = Number.POSITIVE_INFINITY;
37782
+ for (let index = parent.children.length - 1; index >= 0; index--) {
37783
+ const child = parent.children[index];
37784
+ if (child?.type !== "tag" || !child.sourceCodeLocation?.startTag) continue;
37785
+ const start = child.sourceCodeLocation.startOffset;
37786
+ if (start > earliest) fostered.add(child);
37787
+ earliest = Math.min(earliest, start);
37788
+ }
37789
+ }
37790
+ return fostered;
37791
+ }
37792
+ /**
37793
+ * Where the end tag a start-tagless element came from sits: the first one
37794
+ * of its name after whatever precedes the element in the file.
37795
+ */
37796
+ function strayEndTag(html, element) {
37797
+ let from = 0;
37798
+ for (let previous = element.prev; previous; previous = previous.prev) {
37799
+ const end = previous.endIndex;
37800
+ if (typeof end === "number") {
37801
+ from = end;
37802
+ break;
37803
+ }
37804
+ }
37805
+ const tag = `</${element.name}`;
37806
+ const start = html.toLowerCase().indexOf(tag, from);
37807
+ return start === -1 ? null : locate$1(html, start, start + tag.length + 1);
37808
+ }
37106
37809
  function isTable(element) {
37107
37810
  return element.name === "table";
37108
37811
  }
@@ -37147,9 +37850,12 @@ function checkFrameIn(target, { config, tokens }) {
37147
37850
  return [
37148
37851
  ...checkNaming(target, boardPath(target.root, source.path)),
37149
37852
  ...checkMarkup(source),
37853
+ ...checkMalformedTags(source),
37854
+ ...checkNesting(source),
37150
37855
  ...checkLinks(source),
37151
37856
  ...checkFonts(source, cascade, config),
37152
37857
  ...checkTheme(source),
37858
+ ...checkUnknownTokens(source, tokens),
37153
37859
  ...config.noUppercase ? checkUppercase(source, cascade) : []
37154
37860
  ];
37155
37861
  }
@@ -37188,6 +37894,98 @@ function readConfig(root, project) {
37188
37894
  function isRecord(value) {
37189
37895
  return typeof value === "object" && value !== null && !Array.isArray(value);
37190
37896
  }
37897
+ // src/server/checks/browser/declarations.ts
37898
+ const DECLARATION_RULES = [{
37899
+ id: "dropped-declaration",
37900
+ tier: "browser",
37901
+ description: "A declaration the page's own CSS parser drops, being a misspelled property, a value it cannot read, or a sheet that stops parsing"
37902
+ }];
37903
+ /**
37904
+ * At-rules whose blocks hold descriptors rather than properties, which
37905
+ * `CSS.supports` cannot answer, and `@supports`, whose block is a
37906
+ * deliberate guess.
37907
+ */
37908
+ const SKIPPED_BLOCKS = /^(font-face|property|page|counter-style|font-palette-values|supports)$/i;
37909
+ /** Prefixes for engines the board never renders in. */
37910
+ const FOREIGN_PREFIX = /^-(moz|ms|o)-/i;
37911
+ /**
37912
+ * `dropped-declaration`, one finding per declaration in the frame's own
37913
+ * sheets and style attributes that the open page's `CSS.supports` refuses,
37914
+ * and one per sheet postcss cannot parse, at the break it stops on, checking
37915
+ * the declarations ahead of the break. Theme
37916
+ * plays no part, so a caller runs it on one theme's page.
37917
+ */
37918
+ async function checkDeclarations(page, source) {
37919
+ const findings = [];
37920
+ const written = [];
37921
+ for (const sheet of source.sheets) {
37922
+ const path = boardPath(source.root, sheet.path);
37923
+ const text = sheet.origin === "style" ? source.html : sheet.css;
37924
+ const { root, errors } = parseSheet(sheet.css);
37925
+ for (const error of errors) findings.push(finding("dropped-declaration", {
37926
+ frame: source.ref,
37927
+ path,
37928
+ message: breakMessage(error),
37929
+ location: syntaxLocation(text, sheet, error)
37930
+ }));
37931
+ root.walkDecls((node) => {
37932
+ if (!checkable(node)) return;
37933
+ written.push({
37934
+ property: node.prop,
37935
+ value: node.value,
37936
+ path,
37937
+ location: locate$1(text, sheet.offset + (node.source?.start?.offset ?? 0), sheet.offset + (node.source?.end?.offset ?? 0))
37938
+ });
37939
+ });
37940
+ }
37941
+ const framePath = boardPath(source.root, source.path);
37942
+ for (const element of source.elements) {
37943
+ const style = element.attribs.style;
37944
+ if (!style) continue;
37945
+ let root;
37946
+ try {
37947
+ root = postcss_default.parse(`x{${style}}`);
37948
+ } catch {
37949
+ continue;
37950
+ }
37951
+ root.walkDecls((node) => {
37952
+ if (!checkable(node)) return;
37953
+ written.push({
37954
+ property: node.prop,
37955
+ value: node.value,
37956
+ path: framePath,
37957
+ location: attributeLocation(element, "style")
37958
+ });
37959
+ });
37960
+ }
37961
+ const supported = await page.evaluate((pairs) => pairs.map(([property, value]) => CSS.supports(property, value)), written.map((each) => [each.property, each.value]));
37962
+ written.forEach((each, index) => {
37963
+ if (supported[index]) return;
37964
+ findings.push(finding("dropped-declaration", {
37965
+ frame: source.ref,
37966
+ path: each.path,
37967
+ message: `The browser drops ${each.property}: ${each.value}, since it reads no such property or no such value for it. Check the spelling of both, and the unit of a length, such as 12px.`,
37968
+ location: each.location
37969
+ }));
37970
+ });
37971
+ return findings;
37972
+ }
37973
+ function checkable(node) {
37974
+ if (node.prop.startsWith("--") || FOREIGN_PREFIX.test(node.prop)) return false;
37975
+ for (let parent = node.parent; parent; parent = parent.parent) if (parent.type === "atrule" && SKIPPED_BLOCKS.test(parent.name)) return false;
37976
+ return true;
37977
+ }
37978
+ /** What to tell the agent about a break, by the cure its kind takes. */
37979
+ function breakMessage(error) {
37980
+ if (error.reason.startsWith("Unknown word")) return `The browser drops this declaration, since it reads no property and value in it (${error.reason}). Check for a missing colon between the two.`;
37981
+ return `The sheet stops parsing here: ${error.reason}. The browser drops the declarations the break swallows, so close the rule, the string, or the comment.`;
37982
+ }
37983
+ /** Where postcss stopped, as an offset into the file the sheet sits in. */
37984
+ function syntaxLocation(text, sheet, error) {
37985
+ if (error.line === void 0 || error.column === void 0) return null;
37986
+ const start = sheet.offset + offsetOf(sheet.css, error.line, error.column);
37987
+ return locate$1(text, start, start + 1);
37988
+ }
37191
37989
  // src/server/checks/browser/font-size.ts
37192
37990
  const FONT_SIZE_RULES = [{
37193
37991
  id: "min-font-size",
@@ -37416,9 +38214,14 @@ function clipped(target, read) {
37416
38214
  return finding("clipped", {
37417
38215
  frame: target.ref,
37418
38216
  path: target.path,
37419
- message: `${target.ref} is ${reach}, so the board cuts it off${offenders(past, "past the box")}. Run frame fit, or shorten the content.`
38217
+ message: `${target.ref} is ${reach}, so the board cuts it off${offenders(past, "past the box")}. ${clippedAdvice(tall, wide, width)}`
37420
38218
  });
37421
38219
  }
38220
+ function clippedAdvice(tall, wide, width) {
38221
+ if (!wide) return "Run frame fit, or shorten the content.";
38222
+ if (!tall) return `Reflow or shorten the content to fit its ${width} px width, since frame fit sets the height alone.`;
38223
+ return `Run frame fit for the height, and reflow or shorten the content to fit its ${width} px width.`;
38224
+ }
37422
38225
  function scrollbar(target, read) {
37423
38226
  const scrolling = read.scrollers.filter((scroller) => scroller.overflowX > SLACK_PX || scroller.overflowY > SLACK_PX);
37424
38227
  const [first] = scrolling;
@@ -37509,9 +38312,11 @@ const RULES = [
37509
38312
  ...LINK_RULES,
37510
38313
  ...FONT_RULES,
37511
38314
  ...THEME_RULES,
38315
+ ...CUSTOM_PROPERTY_RULES,
37512
38316
  ...UPPERCASE_RULES,
37513
38317
  ...LAYOUT_RULES,
37514
- ...FONT_SIZE_RULES
38318
+ ...FONT_SIZE_RULES,
38319
+ ...DECLARATION_RULES
37515
38320
  ];
37516
38321
  /** Checks every frame on one page. */
37517
38322
  async function checkPage(root, project, page) {
@@ -37603,7 +38408,7 @@ function registerCheck(program, context) {
37603
38408
  browser: browser.run
37604
38409
  };
37605
38410
  if (result.findings.some((finding) => finding.severity === "error")) {
37606
- if (!options.json) context.io.stdout(`${describe$5(result)}\n`);
38411
+ if (!options.json) context.io.stdout(`${describe$5(result, { count: false })}\n`);
37607
38412
  throw new FrameboardError("check-findings", summarize(result), { ...result });
37608
38413
  }
37609
38414
  return {
@@ -37699,10 +38504,14 @@ function summarize({ checked, findings }) {
37699
38504
  const frames = `${checked} frame${checked === 1 ? "" : "s"}`;
37700
38505
  return findings.length === 0 ? `Checked ${frames}, no findings.` : `Checked ${frames}, ${findings.length} finding${findings.length === 1 ? "" : "s"}.`;
37701
38506
  }
37702
- /** One line per finding, then the count, then why the browser rules did not run. */
37703
- function describe$5(result) {
38507
+ /**
38508
+ * One line per finding, then the count unless the caller prints it elsewhere,
38509
+ * then why the browser rules did not run.
38510
+ */
38511
+ function describe$5(result, { count = true } = {}) {
37704
38512
  const { findings, browser } = result;
37705
- const lines = [...findings.map(formatFinding), summarize(result)];
38513
+ const lines = findings.map(formatFinding);
38514
+ if (count) lines.push(summarize(result));
37706
38515
  if (browser?.reason === "server-not-running") lines.push("Browser rules did not run, since no board server is running. Run frameboard serve, then check again.");
37707
38516
  else if (browser?.reason === "browser-not-found") lines.push(`Browser rules did not run, since the board server could not launch Playwright's headless shell. Install it with ${installCommands().npx}.`);
37708
38517
  return lines.join("\n");
@@ -37969,13 +38778,33 @@ const checkResultSchema = /* @__PURE__ */ object({
37969
38778
  browser: /* @__PURE__ */ optional(browserRunSchema)
37970
38779
  });
37971
38780
  // src/shared/records/edit.ts
38781
+ const hash = string$1().regex(/^[0-9a-f]{64}$/);
37972
38782
  /** What `edit` returns: the frame it wrote, the element, and the hash the next edit is made from. */
37973
38783
  const editResultSchema = object$1({
37974
38784
  ref: string$1(),
38785
+ /** The element's index in the file as written, which moves once the edit was found again by its bytes. */
37975
38786
  index: int$1().min(0),
37976
- hash: string$1().regex(/^[0-9a-f]{64}$/)
38787
+ hash,
38788
+ /** The hash the edit was written over, which differs from the one sent once the edit was found again. */
38789
+ from: hash.optional()
38790
+ });
38791
+ object$1({
38792
+ ref: string$1(),
38793
+ index: int$1().min(0),
38794
+ hash
37977
38795
  });
37978
38796
  // src/shared/records/elements.ts
38797
+ /**
38798
+ * How an element lays out what it holds, read from the frame's static
38799
+ * cascade: a flex by its main axis, a grid, or `block` for anything else,
38800
+ * including a flex or grid set through an unresolved `var()`.
38801
+ */
38802
+ const layoutSchema = _enum$1([
38803
+ "row",
38804
+ "column",
38805
+ "grid",
38806
+ "block"
38807
+ ]);
37979
38808
  /** One element under a frame's `body`, addressed by the index `edit --index` takes. */
37980
38809
  const treeElementSchema = object$1({
37981
38810
  index: int$1().min(0),
@@ -37985,7 +38814,9 @@ const treeElementSchema = object$1({
37985
38814
  /** `data-name`, else a text-only element's text cut to 40 characters, else an `img`'s `alt`, else the tag. */
37986
38815
  name: string$1(),
37987
38816
  /** True when the element holds text and nothing else. */
37988
- textOnly: boolean$1()
38817
+ textOnly: boolean$1(),
38818
+ /** Its layout, which a culled frame's Layers rows draw from without an iframe. */
38819
+ layout: layoutSchema
37989
38820
  });
37990
38821
  /** What `GET /api/frames/elements` answers: a frame's elements under `body` in index order, and the hash they were read from. */
37991
38822
  const elementTreeSchema = object$1({
@@ -38320,8 +39151,9 @@ function registerEdit(program, context) {
38320
39151
  return {
38321
39152
  data: {
38322
39153
  ref: frameRef,
38323
- index: options.index,
38324
- hash: result.hash
39154
+ index: result.index,
39155
+ hash: result.hash,
39156
+ from: result.from
38325
39157
  },
38326
39158
  human: `Edited element ${options.index} of ${frameRef}, now at hash ${result.hash}`
38327
39159
  };
@@ -42895,7 +43727,7 @@ function versionKey(ref, hash) {
42895
43727
  /** The files and folders a step wrote, being every rewrite, creation, removal, and move. */
42896
43728
  function writtenPaths(step) {
42897
43729
  return step.changes.flatMap((change) => {
42898
- if (change.kind === "element" || change.kind === "path") return [change.path];
43730
+ if (change.kind === "element" || change.kind === "inserted" || change.kind === "path") return [change.path];
42899
43731
  if (change.kind === "moved") return [change.from, change.to];
42900
43732
  return [];
42901
43733
  });
@@ -42925,17 +43757,30 @@ function framesNamed(root, paths) {
42925
43757
  }
42926
43758
  return refs;
42927
43759
  }
42928
- // src/server/checks/browser/rendered.ts
42929
- /** Every browser rule, in the order `docs` lists them. */
42930
- const BROWSER_RULES = [...LAYOUT_RULES, ...FONT_SIZE_RULES];
43760
+ [
43761
+ ...LAYOUT_RULES,
43762
+ ...FONT_SIZE_RULES,
43763
+ ...DECLARATION_RULES
43764
+ ];
43765
+ /** The rules that read one theme's page and land one finding at most. */
43766
+ const THEMED_RULES = [...LAYOUT_RULES, ...FONT_SIZE_RULES];
42931
43767
  /**
42932
43768
  * Runs every browser rule on one frame at its layout size, in light and in
42933
43769
  * dark, and merges the two. A rule tripping in one theme alone names that
42934
43770
  * theme in its message. A missing face is measured in the fallback the board
42935
- * shows rather than refused, since the board shows it too.
43771
+ * shows rather than refused, since the board shows it too. The declaration
43772
+ * rule reads no theme, so it runs on the first theme's page alone.
42936
43773
  */
42937
- async function checkRendered(browser, { baseUrl, frame, config }) {
43774
+ async function checkRendered(browser, { baseUrl, root, frame, config }) {
43775
+ const [project = "", page = "", name = ""] = frame.ref.split("/");
43776
+ const source = readFrame({
43777
+ root,
43778
+ project,
43779
+ page,
43780
+ name
43781
+ });
42938
43782
  const byTheme = /* @__PURE__ */ new Map();
43783
+ let declarations = [];
42939
43784
  for (const theme of THEMES) {
42940
43785
  const opened = await openFrame(browser, {
42941
43786
  baseUrl,
@@ -42946,11 +43791,12 @@ async function checkRendered(browser, { baseUrl, frame, config }) {
42946
43791
  });
42947
43792
  try {
42948
43793
  byTheme.set(theme, [...await checkLayout(opened.page, frame), ...config.minFontSize === void 0 ? [] : await checkFontSize(opened.page, frame, config.minFontSize)]);
43794
+ if (theme === THEMES[0]) declarations = await checkDeclarations(opened.page, source);
42949
43795
  } finally {
42950
43796
  await opened.close();
42951
43797
  }
42952
43798
  }
42953
- return mergeThemes(byTheme);
43799
+ return [...mergeThemes(byTheme), ...declarations];
42954
43800
  }
42955
43801
  /**
42956
43802
  * One finding per rule across themes, in rule order. A rule both themes trip
@@ -42958,7 +43804,7 @@ async function checkRendered(browser, { baseUrl, frame, config }) {
42958
43804
  */
42959
43805
  function mergeThemes(byTheme) {
42960
43806
  const merged = [];
42961
- for (const rule of BROWSER_RULES) {
43807
+ for (const rule of THEMED_RULES) {
42962
43808
  const tripped = THEMES.flatMap((theme) => {
42963
43809
  const found = byTheme.get(theme)?.find((each) => each.rule === rule.id);
42964
43810
  return found ? [{
@@ -43077,6 +43923,7 @@ async function reads(change, side) {
43077
43923
  }
43078
43924
  case "path": return change.present === side ? await exists(change.path) && await hashPath(change.path) === change.hash : !await exists(change.path) && await exists(change.slot);
43079
43925
  case "element": return await exists(change.path) && holdsSpan(await readFile(change.path, "utf8"), change.span, side);
43926
+ case "inserted": return await exists(change.path) && holdsInserted(await readFile(change.path, "utf8"), change.span, side);
43080
43927
  }
43081
43928
  }
43082
43929
  /**
@@ -43135,30 +43982,47 @@ async function restore(change, side) {
43135
43982
  if (change.present === side) await rename(change.slot, change.path);
43136
43983
  else await takeOut(change.path, change.slot);
43137
43984
  return;
43138
- case "element": return swapElement(change, side);
43985
+ case "element": return rewriteFrame(change, (source) => {
43986
+ const swapped = swapSpan(source, change.span, OTHER[side]);
43987
+ return swapped && {
43988
+ html: swapped.html,
43989
+ keep: () => {
43990
+ change.span = swapped.span;
43991
+ }
43992
+ };
43993
+ });
43994
+ case "inserted": return rewriteFrame(change, (source) => {
43995
+ const written = side === "before" ? removeInserted(source, change.span) : restoreInserted(source, change.span);
43996
+ return written && {
43997
+ html: written.html,
43998
+ keep: () => {
43999
+ change.span = written.span;
44000
+ }
44001
+ };
44002
+ });
43139
44003
  }
43140
44004
  }
43141
44005
  /**
43142
- * Swaps the edited element to `side` through a temporary file and a rename,
43143
- * reading the file again just before the rename. A write landing before that
43144
- * read is not overwritten: the swap is made once more from the fresh bytes,
43145
- * and refused once they change again or no longer hold the element. Bytes
43146
- * that fail a UTF-8 round trip are refused too, since decoding would rewrite
43147
- * each invalid byte outside the element. The change keeps the index the
43148
- * element was found at, so a redo lands on it.
44006
+ * Writes a hand edit's element to the other side through a temporary file and
44007
+ * a rename, reading the file again just before the rename. A write landing
44008
+ * before that read is not overwritten: the rewrite is made once more from the
44009
+ * fresh bytes, and refused once they change again or no longer hold the
44010
+ * element. Bytes that fail a UTF-8 round trip are refused too, since decoding
44011
+ * would rewrite each invalid byte outside the element. The change keeps where
44012
+ * the element was found, through `keep`, so the next side lands on it.
43149
44013
  */
43150
- async function swapElement(change, side) {
44014
+ async function rewriteFrame(change, rewrite) {
43151
44015
  const temp = join(dirname(change.path), `.${basename(change.path)}.${process.pid}.tmp`);
43152
44016
  let source = await readText(change.path);
43153
44017
  for (let attempt = 0; source !== void 0 && attempt < 2; attempt += 1) {
43154
- const swapped = swapSpan(source, change.span, OTHER[side]);
43155
- if (!swapped) break;
43156
- await writeFile(temp, swapped.html);
44018
+ const written = rewrite(source);
44019
+ if (!written) break;
44020
+ await writeFile(temp, written.html);
43157
44021
  const now = await readText(change.path);
43158
44022
  if (now === source) {
43159
44023
  await rename(temp, change.path);
43160
- change.span = swapped.span;
43161
- return contentHash(swapped.html);
44024
+ written.keep();
44025
+ return contentHash(written.html);
43162
44026
  }
43163
44027
  source = now;
43164
44028
  }
@@ -43219,6 +44083,15 @@ var StepJournal = class {
43219
44083
  span
43220
44084
  });
43221
44085
  }
44086
+ /** The element a placement tool wrote into a frame file, which this journal does not write. */
44087
+ inserted(path, ref, span) {
44088
+ this.changes.push({
44089
+ kind: "inserted",
44090
+ path,
44091
+ ref,
44092
+ span
44093
+ });
44094
+ }
43222
44095
  async created(path) {
43223
44096
  this.changes.push({
43224
44097
  kind: "path",
@@ -46933,6 +47806,7 @@ function createHug({ root, measure }) {
46933
47806
  let closed = false;
46934
47807
  const run = async (board, refs) => {
46935
47808
  const pages = /* @__PURE__ */ new Map();
47809
+ let stale = false;
46936
47810
  for (const frame of huggingFrames(board, refs)) {
46937
47811
  if (closed) return false;
46938
47812
  let size;
@@ -46943,6 +47817,7 @@ function createHug({ root, measure }) {
46943
47817
  continue;
46944
47818
  }
46945
47819
  if (size.empty) continue;
47820
+ stale ||= frame.hugWidth && size.width !== frame.box.width || frame.hugHeight && size.height !== frame.box.height;
46946
47821
  const page = `${frame.project}/${frame.page}`;
46947
47822
  pages.set(page, {
46948
47823
  ...pages.get(page),
@@ -46959,7 +47834,7 @@ function createHug({ root, measure }) {
46959
47834
  if (!(error instanceof FrameboardError)) throw error;
46960
47835
  }
46961
47836
  }
46962
- return written;
47837
+ return written || stale;
46963
47838
  };
46964
47839
  return {
46965
47840
  now: (board, refs) => run(board, refs),
@@ -47365,6 +48240,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
47365
48240
  check: async (frame) => {
47366
48241
  const list = await checkRendered(await browser.get(), {
47367
48242
  baseUrl: baseUrl(),
48243
+ root,
47368
48244
  frame: {
47369
48245
  ref: frame.ref,
47370
48246
  path: boardPath(root, frame.path),
@@ -47412,6 +48288,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
47412
48288
  thumbnails,
47413
48289
  measure,
47414
48290
  frameVersion: tracker.version,
48291
+ settledVersion: (ref, hash) => inTurn(async () => tracker.version(ref, hash)),
47415
48292
  checks: {
47416
48293
  refresh: () => inTurn(async () => {
47417
48294
  try {