frameboard 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/dist/cli.js +893 -63
- package/dist/client/assets/index-C-i2pm1f.js +110 -0
- package/dist/client/assets/index-eTwqW6cj.css +2 -0
- package/dist/client/index.html +2 -2
- package/dist/hook.js +279 -3
- package/package.json +1 -1
- package/dist/client/assets/index-BnWs9VE-.css +0 -2
- package/dist/client/assets/index-WjNoYPck.js +0 -110
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.
|
|
9333
|
+
var version$1 = "0.12.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
|
|
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
|
|
28840
|
-
*
|
|
28841
|
-
*
|
|
28842
|
-
*
|
|
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.
|
|
29201
|
+
*/
|
|
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.
|
|
28843
29219
|
*/
|
|
28844
|
-
function
|
|
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
|
-
|
|
28849
|
-
|
|
28850
|
-
|
|
28851
|
-
|
|
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,
|
|
29237
|
+
writeFileSync(temp, html);
|
|
28854
29238
|
if (contentHash(readFileSync(path)) !== hash) {
|
|
28855
29239
|
rmSync(temp, { force: true });
|
|
28856
|
-
return
|
|
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
|
|
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`,
|
|
28936
|
-
*
|
|
28937
|
-
* the
|
|
28938
|
-
|
|
28939
|
-
|
|
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:
|
|
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({
|
|
@@ -36241,7 +36690,7 @@ function boardHostGuard(port) {
|
|
|
36241
36690
|
await next();
|
|
36242
36691
|
};
|
|
36243
36692
|
}
|
|
36244
|
-
function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails, measure, frameVersion }) {
|
|
36693
|
+
function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails, measure, frameVersion, settledVersion }) {
|
|
36245
36694
|
const app = new Hono();
|
|
36246
36695
|
const given = tokens ?? null;
|
|
36247
36696
|
app.use("*", async (c, next) => {
|
|
@@ -36267,7 +36716,7 @@ function createApp({ clientDir, root, port, actions, tickets, renderFrame, faces
|
|
|
36267
36716
|
app.route("/", assetsRoutes(root, actions.access));
|
|
36268
36717
|
app.route("/", elementsRoutes(root, actions.access, selection, given));
|
|
36269
36718
|
app.route("/", findRoutes(root));
|
|
36270
|
-
app.route("/", editRoutes(root, actions.access, history));
|
|
36719
|
+
app.route("/", editRoutes(root, actions.access, history, settledVersion, frames.look.sheets));
|
|
36271
36720
|
app.route("/", pngRoutes(root, renderFrame));
|
|
36272
36721
|
if (checks) app.route("/", checkRoutes(actions.access, checks));
|
|
36273
36722
|
if (thumbnails) app.route("/", thumbnailRoutes(root, thumbnails));
|
|
@@ -36802,6 +37251,71 @@ async function pageOf(root, ref, options) {
|
|
|
36802
37251
|
function describe$6(images) {
|
|
36803
37252
|
return images.map((image) => `Wrote ${image.path}`).join("\n");
|
|
36804
37253
|
}
|
|
37254
|
+
// src/server/checks/custom-properties.ts
|
|
37255
|
+
const CUSTOM_PROPERTY_RULES = [{
|
|
37256
|
+
id: "unknown-token",
|
|
37257
|
+
tier: "exact",
|
|
37258
|
+
description: "A var() with no fallback names a custom property no token sheet, frame sheet, or style attribute declares"
|
|
37259
|
+
}];
|
|
37260
|
+
/** A `var()` naming its property, with no fallback after a comma. */
|
|
37261
|
+
const BARE_VAR = /var\(\s*(--[\w-]+)\s*\)/g;
|
|
37262
|
+
/**
|
|
37263
|
+
* `unknown-token`, one finding per bare `var()` in the frame's own sheets
|
|
37264
|
+
* and style attributes whose name nothing declares. A token sheet's own
|
|
37265
|
+
* references are the board's to answer for, so only its declarations count.
|
|
37266
|
+
* A property a script sets reads as unknown, which a fallback silences.
|
|
37267
|
+
*/
|
|
37268
|
+
function checkUnknownTokens(source, tokens) {
|
|
37269
|
+
const declared = /* @__PURE__ */ new Set();
|
|
37270
|
+
const uses = [];
|
|
37271
|
+
for (const sheet of [...tokens, ...source.sheets]) {
|
|
37272
|
+
const { root } = parseSheet(sheet.css);
|
|
37273
|
+
root.walkAtRules(/^property$/i, (rule) => {
|
|
37274
|
+
declared.add(rule.params.trim());
|
|
37275
|
+
});
|
|
37276
|
+
const text = sheet.origin === "style" ? source.html : sheet.css;
|
|
37277
|
+
root.walkDecls((node) => {
|
|
37278
|
+
if (node.prop.startsWith("--")) declared.add(node.prop);
|
|
37279
|
+
if (sheet.origin === "token") return;
|
|
37280
|
+
for (const name of bareVars(node.value)) uses.push({
|
|
37281
|
+
name,
|
|
37282
|
+
path: boardPath(source.root, sheet.path),
|
|
37283
|
+
location: locate$1(text, sheet.offset + (node.source?.start?.offset ?? 0), sheet.offset + (node.source?.end?.offset ?? 0))
|
|
37284
|
+
});
|
|
37285
|
+
});
|
|
37286
|
+
}
|
|
37287
|
+
const framePath = boardPath(source.root, source.path);
|
|
37288
|
+
for (const element of source.elements) {
|
|
37289
|
+
const style = element.attribs.style;
|
|
37290
|
+
if (!style) continue;
|
|
37291
|
+
const root = parseOrNull(`x{${style}}`);
|
|
37292
|
+
if (!root) continue;
|
|
37293
|
+
root.walkDecls((node) => {
|
|
37294
|
+
if (node.prop.startsWith("--")) declared.add(node.prop);
|
|
37295
|
+
for (const name of bareVars(node.value)) uses.push({
|
|
37296
|
+
name,
|
|
37297
|
+
path: framePath,
|
|
37298
|
+
location: attributeLocation(element, "style")
|
|
37299
|
+
});
|
|
37300
|
+
});
|
|
37301
|
+
}
|
|
37302
|
+
return uses.filter((use) => !declared.has(use.name)).map((use) => finding("unknown-token", {
|
|
37303
|
+
frame: source.ref,
|
|
37304
|
+
path: use.path,
|
|
37305
|
+
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).`,
|
|
37306
|
+
location: use.location
|
|
37307
|
+
}));
|
|
37308
|
+
}
|
|
37309
|
+
function bareVars(value) {
|
|
37310
|
+
return [...new Set([...value.matchAll(BARE_VAR)].map((match) => match[1] ?? ""))];
|
|
37311
|
+
}
|
|
37312
|
+
function parseOrNull(css) {
|
|
37313
|
+
try {
|
|
37314
|
+
return postcss_default.parse(css);
|
|
37315
|
+
} catch {
|
|
37316
|
+
return null;
|
|
37317
|
+
}
|
|
37318
|
+
}
|
|
36805
37319
|
// src/server/checks/fonts.ts
|
|
36806
37320
|
const FONT_RULES = [
|
|
36807
37321
|
{
|
|
@@ -37057,8 +37571,76 @@ const STRUCTURE_RULES = [
|
|
|
37057
37571
|
id: "table-tbody",
|
|
37058
37572
|
tier: "exact",
|
|
37059
37573
|
description: "A table holding rows states its <tbody>, since the browser adds one the file does not hold"
|
|
37574
|
+
},
|
|
37575
|
+
{
|
|
37576
|
+
id: "malformed-tag",
|
|
37577
|
+
tier: "exact",
|
|
37578
|
+
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"
|
|
37579
|
+
},
|
|
37580
|
+
{
|
|
37581
|
+
id: "nesting",
|
|
37582
|
+
tier: "exact",
|
|
37583
|
+
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
37584
|
}
|
|
37061
37585
|
];
|
|
37586
|
+
/**
|
|
37587
|
+
* Elements a parser may imply with no start tag in a valid file. A `tbody`
|
|
37588
|
+
* is `table-tbody`'s to report.
|
|
37589
|
+
*/
|
|
37590
|
+
const IMPLIED = /* @__PURE__ */ new Set([
|
|
37591
|
+
"html",
|
|
37592
|
+
"head",
|
|
37593
|
+
"body",
|
|
37594
|
+
"tbody",
|
|
37595
|
+
"colgroup"
|
|
37596
|
+
]);
|
|
37597
|
+
/** HTML elements whose end tag a valid file may leave out, void ones included. */
|
|
37598
|
+
const OPTIONAL_END = /* @__PURE__ */ new Set([
|
|
37599
|
+
"html",
|
|
37600
|
+
"head",
|
|
37601
|
+
"body",
|
|
37602
|
+
"li",
|
|
37603
|
+
"dt",
|
|
37604
|
+
"dd",
|
|
37605
|
+
"p",
|
|
37606
|
+
"rt",
|
|
37607
|
+
"rp",
|
|
37608
|
+
"optgroup",
|
|
37609
|
+
"option",
|
|
37610
|
+
"colgroup",
|
|
37611
|
+
"caption",
|
|
37612
|
+
"thead",
|
|
37613
|
+
"tbody",
|
|
37614
|
+
"tfoot",
|
|
37615
|
+
"tr",
|
|
37616
|
+
"td",
|
|
37617
|
+
"th",
|
|
37618
|
+
"area",
|
|
37619
|
+
"base",
|
|
37620
|
+
"br",
|
|
37621
|
+
"col",
|
|
37622
|
+
"embed",
|
|
37623
|
+
"hr",
|
|
37624
|
+
"img",
|
|
37625
|
+
"input",
|
|
37626
|
+
"link",
|
|
37627
|
+
"meta",
|
|
37628
|
+
"source",
|
|
37629
|
+
"track",
|
|
37630
|
+
"wbr",
|
|
37631
|
+
"param",
|
|
37632
|
+
"keygen"
|
|
37633
|
+
]);
|
|
37634
|
+
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
37635
|
+
/** What `malformed-tag` tells the agent for each tokenizer code it reports. */
|
|
37636
|
+
const MALFORMED = {
|
|
37637
|
+
"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'.",
|
|
37638
|
+
"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.",
|
|
37639
|
+
"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.",
|
|
37640
|
+
"duplicate-attribute": "This tag states one attribute twice, and the browser drops the second. Keep one.",
|
|
37641
|
+
"eof-in-tag": "The file ends inside a tag, so the browser drops the tag. Close it.",
|
|
37642
|
+
"unexpected-character-in-unquoted-attribute-value": "An unquoted attribute value holds a quote, <, =, or backtick. Quote the value."
|
|
37643
|
+
};
|
|
37062
37644
|
/** `naming`, read from the frame's path alone. */
|
|
37063
37645
|
function checkNaming(target, path) {
|
|
37064
37646
|
const ref = `${target.project}/${target.page}/${target.name}`;
|
|
@@ -37103,6 +37685,95 @@ function checkMarkup(source) {
|
|
|
37103
37685
|
}));
|
|
37104
37686
|
return findings;
|
|
37105
37687
|
}
|
|
37688
|
+
/**
|
|
37689
|
+
* `malformed-tag`, one finding per start tag the tokenizer refused, at its
|
|
37690
|
+
* first error, since one stray quote raises several codes in one tag.
|
|
37691
|
+
*/
|
|
37692
|
+
function checkMalformedTags(source) {
|
|
37693
|
+
const path = boardPath(source.root, source.path);
|
|
37694
|
+
const reported = /* @__PURE__ */ new Set();
|
|
37695
|
+
const findings = [];
|
|
37696
|
+
for (const error of source.parseErrors) {
|
|
37697
|
+
const message = MALFORMED[error.code];
|
|
37698
|
+
if (message === void 0) continue;
|
|
37699
|
+
const tag = source.elements.find((element) => {
|
|
37700
|
+
const start = element.sourceCodeLocation?.startTag;
|
|
37701
|
+
return start !== void 0 && start.startOffset <= error.location.startOffset && error.location.startOffset < start.endOffset;
|
|
37702
|
+
});
|
|
37703
|
+
if (tag) {
|
|
37704
|
+
if (reported.has(tag)) continue;
|
|
37705
|
+
reported.add(tag);
|
|
37706
|
+
}
|
|
37707
|
+
findings.push(finding("malformed-tag", {
|
|
37708
|
+
frame: source.ref,
|
|
37709
|
+
path,
|
|
37710
|
+
message: `${tag ? `<${tag.name}> raises ${error.code}` : error.code}. ${message}`,
|
|
37711
|
+
location: error.location
|
|
37712
|
+
}));
|
|
37713
|
+
}
|
|
37714
|
+
return findings;
|
|
37715
|
+
}
|
|
37716
|
+
/**
|
|
37717
|
+
* `nesting`, one finding per element the parser rebuilt: one it implied with
|
|
37718
|
+
* no start tag, an HTML element whose end tag never matched, and one moved
|
|
37719
|
+
* ahead of a sibling the file writes first, which is a table's foster
|
|
37720
|
+
* parenting. Foreign elements are left to close themselves.
|
|
37721
|
+
*/
|
|
37722
|
+
function checkNesting(source) {
|
|
37723
|
+
const path = boardPath(source.root, source.path);
|
|
37724
|
+
const findings = [];
|
|
37725
|
+
const report = (message, location) => findings.push(finding("nesting", {
|
|
37726
|
+
frame: source.ref,
|
|
37727
|
+
path,
|
|
37728
|
+
message,
|
|
37729
|
+
location
|
|
37730
|
+
}));
|
|
37731
|
+
const fostered = fosteredElements(source.elements);
|
|
37732
|
+
for (const element of source.elements) {
|
|
37733
|
+
const location = element.sourceCodeLocation;
|
|
37734
|
+
if (!location?.startTag) {
|
|
37735
|
+
if (IMPLIED.has(element.name)) continue;
|
|
37736
|
+
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." : "";
|
|
37737
|
+
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));
|
|
37738
|
+
} 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));
|
|
37739
|
+
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));
|
|
37740
|
+
}
|
|
37741
|
+
return findings;
|
|
37742
|
+
}
|
|
37743
|
+
/** Elements placed ahead of a later sibling the file writes before them. */
|
|
37744
|
+
function fosteredElements(elements) {
|
|
37745
|
+
const parents = new Set(elements.map((element) => element.parent));
|
|
37746
|
+
const fostered = /* @__PURE__ */ new Set();
|
|
37747
|
+
for (const parent of parents) {
|
|
37748
|
+
if (!parent) continue;
|
|
37749
|
+
let earliest = Number.POSITIVE_INFINITY;
|
|
37750
|
+
for (let index = parent.children.length - 1; index >= 0; index--) {
|
|
37751
|
+
const child = parent.children[index];
|
|
37752
|
+
if (child?.type !== "tag" || !child.sourceCodeLocation?.startTag) continue;
|
|
37753
|
+
const start = child.sourceCodeLocation.startOffset;
|
|
37754
|
+
if (start > earliest) fostered.add(child);
|
|
37755
|
+
earliest = Math.min(earliest, start);
|
|
37756
|
+
}
|
|
37757
|
+
}
|
|
37758
|
+
return fostered;
|
|
37759
|
+
}
|
|
37760
|
+
/**
|
|
37761
|
+
* Where the end tag a start-tagless element came from sits: the first one
|
|
37762
|
+
* of its name after whatever precedes the element in the file.
|
|
37763
|
+
*/
|
|
37764
|
+
function strayEndTag(html, element) {
|
|
37765
|
+
let from = 0;
|
|
37766
|
+
for (let previous = element.prev; previous; previous = previous.prev) {
|
|
37767
|
+
const end = previous.endIndex;
|
|
37768
|
+
if (typeof end === "number") {
|
|
37769
|
+
from = end;
|
|
37770
|
+
break;
|
|
37771
|
+
}
|
|
37772
|
+
}
|
|
37773
|
+
const tag = `</${element.name}`;
|
|
37774
|
+
const start = html.toLowerCase().indexOf(tag, from);
|
|
37775
|
+
return start === -1 ? null : locate$1(html, start, start + tag.length + 1);
|
|
37776
|
+
}
|
|
37106
37777
|
function isTable(element) {
|
|
37107
37778
|
return element.name === "table";
|
|
37108
37779
|
}
|
|
@@ -37147,9 +37818,12 @@ function checkFrameIn(target, { config, tokens }) {
|
|
|
37147
37818
|
return [
|
|
37148
37819
|
...checkNaming(target, boardPath(target.root, source.path)),
|
|
37149
37820
|
...checkMarkup(source),
|
|
37821
|
+
...checkMalformedTags(source),
|
|
37822
|
+
...checkNesting(source),
|
|
37150
37823
|
...checkLinks(source),
|
|
37151
37824
|
...checkFonts(source, cascade, config),
|
|
37152
37825
|
...checkTheme(source),
|
|
37826
|
+
...checkUnknownTokens(source, tokens),
|
|
37153
37827
|
...config.noUppercase ? checkUppercase(source, cascade) : []
|
|
37154
37828
|
];
|
|
37155
37829
|
}
|
|
@@ -37188,6 +37862,98 @@ function readConfig(root, project) {
|
|
|
37188
37862
|
function isRecord(value) {
|
|
37189
37863
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37190
37864
|
}
|
|
37865
|
+
// src/server/checks/browser/declarations.ts
|
|
37866
|
+
const DECLARATION_RULES = [{
|
|
37867
|
+
id: "dropped-declaration",
|
|
37868
|
+
tier: "browser",
|
|
37869
|
+
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"
|
|
37870
|
+
}];
|
|
37871
|
+
/**
|
|
37872
|
+
* At-rules whose blocks hold descriptors rather than properties, which
|
|
37873
|
+
* `CSS.supports` cannot answer, and `@supports`, whose block is a
|
|
37874
|
+
* deliberate guess.
|
|
37875
|
+
*/
|
|
37876
|
+
const SKIPPED_BLOCKS = /^(font-face|property|page|counter-style|font-palette-values|supports)$/i;
|
|
37877
|
+
/** Prefixes for engines the board never renders in. */
|
|
37878
|
+
const FOREIGN_PREFIX = /^-(moz|ms|o)-/i;
|
|
37879
|
+
/**
|
|
37880
|
+
* `dropped-declaration`, one finding per declaration in the frame's own
|
|
37881
|
+
* sheets and style attributes that the open page's `CSS.supports` refuses,
|
|
37882
|
+
* and one per sheet postcss cannot parse, at the break it stops on, checking
|
|
37883
|
+
* the declarations ahead of the break. Theme
|
|
37884
|
+
* plays no part, so a caller runs it on one theme's page.
|
|
37885
|
+
*/
|
|
37886
|
+
async function checkDeclarations(page, source) {
|
|
37887
|
+
const findings = [];
|
|
37888
|
+
const written = [];
|
|
37889
|
+
for (const sheet of source.sheets) {
|
|
37890
|
+
const path = boardPath(source.root, sheet.path);
|
|
37891
|
+
const text = sheet.origin === "style" ? source.html : sheet.css;
|
|
37892
|
+
const { root, errors } = parseSheet(sheet.css);
|
|
37893
|
+
for (const error of errors) findings.push(finding("dropped-declaration", {
|
|
37894
|
+
frame: source.ref,
|
|
37895
|
+
path,
|
|
37896
|
+
message: breakMessage(error),
|
|
37897
|
+
location: syntaxLocation(text, sheet, error)
|
|
37898
|
+
}));
|
|
37899
|
+
root.walkDecls((node) => {
|
|
37900
|
+
if (!checkable(node)) return;
|
|
37901
|
+
written.push({
|
|
37902
|
+
property: node.prop,
|
|
37903
|
+
value: node.value,
|
|
37904
|
+
path,
|
|
37905
|
+
location: locate$1(text, sheet.offset + (node.source?.start?.offset ?? 0), sheet.offset + (node.source?.end?.offset ?? 0))
|
|
37906
|
+
});
|
|
37907
|
+
});
|
|
37908
|
+
}
|
|
37909
|
+
const framePath = boardPath(source.root, source.path);
|
|
37910
|
+
for (const element of source.elements) {
|
|
37911
|
+
const style = element.attribs.style;
|
|
37912
|
+
if (!style) continue;
|
|
37913
|
+
let root;
|
|
37914
|
+
try {
|
|
37915
|
+
root = postcss_default.parse(`x{${style}}`);
|
|
37916
|
+
} catch {
|
|
37917
|
+
continue;
|
|
37918
|
+
}
|
|
37919
|
+
root.walkDecls((node) => {
|
|
37920
|
+
if (!checkable(node)) return;
|
|
37921
|
+
written.push({
|
|
37922
|
+
property: node.prop,
|
|
37923
|
+
value: node.value,
|
|
37924
|
+
path: framePath,
|
|
37925
|
+
location: attributeLocation(element, "style")
|
|
37926
|
+
});
|
|
37927
|
+
});
|
|
37928
|
+
}
|
|
37929
|
+
const supported = await page.evaluate((pairs) => pairs.map(([property, value]) => CSS.supports(property, value)), written.map((each) => [each.property, each.value]));
|
|
37930
|
+
written.forEach((each, index) => {
|
|
37931
|
+
if (supported[index]) return;
|
|
37932
|
+
findings.push(finding("dropped-declaration", {
|
|
37933
|
+
frame: source.ref,
|
|
37934
|
+
path: each.path,
|
|
37935
|
+
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.`,
|
|
37936
|
+
location: each.location
|
|
37937
|
+
}));
|
|
37938
|
+
});
|
|
37939
|
+
return findings;
|
|
37940
|
+
}
|
|
37941
|
+
function checkable(node) {
|
|
37942
|
+
if (node.prop.startsWith("--") || FOREIGN_PREFIX.test(node.prop)) return false;
|
|
37943
|
+
for (let parent = node.parent; parent; parent = parent.parent) if (parent.type === "atrule" && SKIPPED_BLOCKS.test(parent.name)) return false;
|
|
37944
|
+
return true;
|
|
37945
|
+
}
|
|
37946
|
+
/** What to tell the agent about a break, by the cure its kind takes. */
|
|
37947
|
+
function breakMessage(error) {
|
|
37948
|
+
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.`;
|
|
37949
|
+
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.`;
|
|
37950
|
+
}
|
|
37951
|
+
/** Where postcss stopped, as an offset into the file the sheet sits in. */
|
|
37952
|
+
function syntaxLocation(text, sheet, error) {
|
|
37953
|
+
if (error.line === void 0 || error.column === void 0) return null;
|
|
37954
|
+
const start = sheet.offset + offsetOf(sheet.css, error.line, error.column);
|
|
37955
|
+
return locate$1(text, start, start + 1);
|
|
37956
|
+
}
|
|
37191
37957
|
// src/server/checks/browser/font-size.ts
|
|
37192
37958
|
const FONT_SIZE_RULES = [{
|
|
37193
37959
|
id: "min-font-size",
|
|
@@ -37416,9 +38182,14 @@ function clipped(target, read) {
|
|
|
37416
38182
|
return finding("clipped", {
|
|
37417
38183
|
frame: target.ref,
|
|
37418
38184
|
path: target.path,
|
|
37419
|
-
message: `${target.ref} is ${reach}, so the board cuts it off${offenders(past, "past the box")}.
|
|
38185
|
+
message: `${target.ref} is ${reach}, so the board cuts it off${offenders(past, "past the box")}. ${clippedAdvice(tall, wide, width)}`
|
|
37420
38186
|
});
|
|
37421
38187
|
}
|
|
38188
|
+
function clippedAdvice(tall, wide, width) {
|
|
38189
|
+
if (!wide) return "Run frame fit, or shorten the content.";
|
|
38190
|
+
if (!tall) return `Reflow or shorten the content to fit its ${width} px width, since frame fit sets the height alone.`;
|
|
38191
|
+
return `Run frame fit for the height, and reflow or shorten the content to fit its ${width} px width.`;
|
|
38192
|
+
}
|
|
37422
38193
|
function scrollbar(target, read) {
|
|
37423
38194
|
const scrolling = read.scrollers.filter((scroller) => scroller.overflowX > SLACK_PX || scroller.overflowY > SLACK_PX);
|
|
37424
38195
|
const [first] = scrolling;
|
|
@@ -37509,9 +38280,11 @@ const RULES = [
|
|
|
37509
38280
|
...LINK_RULES,
|
|
37510
38281
|
...FONT_RULES,
|
|
37511
38282
|
...THEME_RULES,
|
|
38283
|
+
...CUSTOM_PROPERTY_RULES,
|
|
37512
38284
|
...UPPERCASE_RULES,
|
|
37513
38285
|
...LAYOUT_RULES,
|
|
37514
|
-
...FONT_SIZE_RULES
|
|
38286
|
+
...FONT_SIZE_RULES,
|
|
38287
|
+
...DECLARATION_RULES
|
|
37515
38288
|
];
|
|
37516
38289
|
/** Checks every frame on one page. */
|
|
37517
38290
|
async function checkPage(root, project, page) {
|
|
@@ -37603,7 +38376,7 @@ function registerCheck(program, context) {
|
|
|
37603
38376
|
browser: browser.run
|
|
37604
38377
|
};
|
|
37605
38378
|
if (result.findings.some((finding) => finding.severity === "error")) {
|
|
37606
|
-
if (!options.json) context.io.stdout(`${describe$5(result)}\n`);
|
|
38379
|
+
if (!options.json) context.io.stdout(`${describe$5(result, { count: false })}\n`);
|
|
37607
38380
|
throw new FrameboardError("check-findings", summarize(result), { ...result });
|
|
37608
38381
|
}
|
|
37609
38382
|
return {
|
|
@@ -37699,10 +38472,14 @@ function summarize({ checked, findings }) {
|
|
|
37699
38472
|
const frames = `${checked} frame${checked === 1 ? "" : "s"}`;
|
|
37700
38473
|
return findings.length === 0 ? `Checked ${frames}, no findings.` : `Checked ${frames}, ${findings.length} finding${findings.length === 1 ? "" : "s"}.`;
|
|
37701
38474
|
}
|
|
37702
|
-
/**
|
|
37703
|
-
|
|
38475
|
+
/**
|
|
38476
|
+
* One line per finding, then the count unless the caller prints it elsewhere,
|
|
38477
|
+
* then why the browser rules did not run.
|
|
38478
|
+
*/
|
|
38479
|
+
function describe$5(result, { count = true } = {}) {
|
|
37704
38480
|
const { findings, browser } = result;
|
|
37705
|
-
const lines =
|
|
38481
|
+
const lines = findings.map(formatFinding);
|
|
38482
|
+
if (count) lines.push(summarize(result));
|
|
37706
38483
|
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
38484
|
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
38485
|
return lines.join("\n");
|
|
@@ -37969,11 +38746,20 @@ const checkResultSchema = /* @__PURE__ */ object({
|
|
|
37969
38746
|
browser: /* @__PURE__ */ optional(browserRunSchema)
|
|
37970
38747
|
});
|
|
37971
38748
|
// src/shared/records/edit.ts
|
|
38749
|
+
const hash = string$1().regex(/^[0-9a-f]{64}$/);
|
|
37972
38750
|
/** What `edit` returns: the frame it wrote, the element, and the hash the next edit is made from. */
|
|
37973
38751
|
const editResultSchema = object$1({
|
|
37974
38752
|
ref: string$1(),
|
|
38753
|
+
/** The element's index in the file as written, which moves once the edit was found again by its bytes. */
|
|
37975
38754
|
index: int$1().min(0),
|
|
37976
|
-
hash
|
|
38755
|
+
hash,
|
|
38756
|
+
/** The hash the edit was written over, which differs from the one sent once the edit was found again. */
|
|
38757
|
+
from: hash.optional()
|
|
38758
|
+
});
|
|
38759
|
+
object$1({
|
|
38760
|
+
ref: string$1(),
|
|
38761
|
+
index: int$1().min(0),
|
|
38762
|
+
hash
|
|
37977
38763
|
});
|
|
37978
38764
|
// src/shared/records/elements.ts
|
|
37979
38765
|
/** One element under a frame's `body`, addressed by the index `edit --index` takes. */
|
|
@@ -38320,8 +39106,9 @@ function registerEdit(program, context) {
|
|
|
38320
39106
|
return {
|
|
38321
39107
|
data: {
|
|
38322
39108
|
ref: frameRef,
|
|
38323
|
-
index:
|
|
38324
|
-
hash: result.hash
|
|
39109
|
+
index: result.index,
|
|
39110
|
+
hash: result.hash,
|
|
39111
|
+
from: result.from
|
|
38325
39112
|
},
|
|
38326
39113
|
human: `Edited element ${options.index} of ${frameRef}, now at hash ${result.hash}`
|
|
38327
39114
|
};
|
|
@@ -42895,7 +43682,7 @@ function versionKey(ref, hash) {
|
|
|
42895
43682
|
/** The files and folders a step wrote, being every rewrite, creation, removal, and move. */
|
|
42896
43683
|
function writtenPaths(step) {
|
|
42897
43684
|
return step.changes.flatMap((change) => {
|
|
42898
|
-
if (change.kind === "element" || change.kind === "path") return [change.path];
|
|
43685
|
+
if (change.kind === "element" || change.kind === "inserted" || change.kind === "path") return [change.path];
|
|
42899
43686
|
if (change.kind === "moved") return [change.from, change.to];
|
|
42900
43687
|
return [];
|
|
42901
43688
|
});
|
|
@@ -42925,17 +43712,30 @@ function framesNamed(root, paths) {
|
|
|
42925
43712
|
}
|
|
42926
43713
|
return refs;
|
|
42927
43714
|
}
|
|
42928
|
-
|
|
42929
|
-
|
|
42930
|
-
|
|
43715
|
+
[
|
|
43716
|
+
...LAYOUT_RULES,
|
|
43717
|
+
...FONT_SIZE_RULES,
|
|
43718
|
+
...DECLARATION_RULES
|
|
43719
|
+
];
|
|
43720
|
+
/** The rules that read one theme's page and land one finding at most. */
|
|
43721
|
+
const THEMED_RULES = [...LAYOUT_RULES, ...FONT_SIZE_RULES];
|
|
42931
43722
|
/**
|
|
42932
43723
|
* Runs every browser rule on one frame at its layout size, in light and in
|
|
42933
43724
|
* dark, and merges the two. A rule tripping in one theme alone names that
|
|
42934
43725
|
* 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.
|
|
43726
|
+
* shows rather than refused, since the board shows it too. The declaration
|
|
43727
|
+
* rule reads no theme, so it runs on the first theme's page alone.
|
|
42936
43728
|
*/
|
|
42937
|
-
async function checkRendered(browser, { baseUrl, frame, config }) {
|
|
43729
|
+
async function checkRendered(browser, { baseUrl, root, frame, config }) {
|
|
43730
|
+
const [project = "", page = "", name = ""] = frame.ref.split("/");
|
|
43731
|
+
const source = readFrame({
|
|
43732
|
+
root,
|
|
43733
|
+
project,
|
|
43734
|
+
page,
|
|
43735
|
+
name
|
|
43736
|
+
});
|
|
42938
43737
|
const byTheme = /* @__PURE__ */ new Map();
|
|
43738
|
+
let declarations = [];
|
|
42939
43739
|
for (const theme of THEMES) {
|
|
42940
43740
|
const opened = await openFrame(browser, {
|
|
42941
43741
|
baseUrl,
|
|
@@ -42946,11 +43746,12 @@ async function checkRendered(browser, { baseUrl, frame, config }) {
|
|
|
42946
43746
|
});
|
|
42947
43747
|
try {
|
|
42948
43748
|
byTheme.set(theme, [...await checkLayout(opened.page, frame), ...config.minFontSize === void 0 ? [] : await checkFontSize(opened.page, frame, config.minFontSize)]);
|
|
43749
|
+
if (theme === THEMES[0]) declarations = await checkDeclarations(opened.page, source);
|
|
42949
43750
|
} finally {
|
|
42950
43751
|
await opened.close();
|
|
42951
43752
|
}
|
|
42952
43753
|
}
|
|
42953
|
-
return mergeThemes(byTheme);
|
|
43754
|
+
return [...mergeThemes(byTheme), ...declarations];
|
|
42954
43755
|
}
|
|
42955
43756
|
/**
|
|
42956
43757
|
* One finding per rule across themes, in rule order. A rule both themes trip
|
|
@@ -42958,7 +43759,7 @@ async function checkRendered(browser, { baseUrl, frame, config }) {
|
|
|
42958
43759
|
*/
|
|
42959
43760
|
function mergeThemes(byTheme) {
|
|
42960
43761
|
const merged = [];
|
|
42961
|
-
for (const rule of
|
|
43762
|
+
for (const rule of THEMED_RULES) {
|
|
42962
43763
|
const tripped = THEMES.flatMap((theme) => {
|
|
42963
43764
|
const found = byTheme.get(theme)?.find((each) => each.rule === rule.id);
|
|
42964
43765
|
return found ? [{
|
|
@@ -43077,6 +43878,7 @@ async function reads(change, side) {
|
|
|
43077
43878
|
}
|
|
43078
43879
|
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
43880
|
case "element": return await exists(change.path) && holdsSpan(await readFile(change.path, "utf8"), change.span, side);
|
|
43881
|
+
case "inserted": return await exists(change.path) && holdsInserted(await readFile(change.path, "utf8"), change.span, side);
|
|
43080
43882
|
}
|
|
43081
43883
|
}
|
|
43082
43884
|
/**
|
|
@@ -43135,30 +43937,47 @@ async function restore(change, side) {
|
|
|
43135
43937
|
if (change.present === side) await rename(change.slot, change.path);
|
|
43136
43938
|
else await takeOut(change.path, change.slot);
|
|
43137
43939
|
return;
|
|
43138
|
-
case "element": return
|
|
43940
|
+
case "element": return rewriteFrame(change, (source) => {
|
|
43941
|
+
const swapped = swapSpan(source, change.span, OTHER[side]);
|
|
43942
|
+
return swapped && {
|
|
43943
|
+
html: swapped.html,
|
|
43944
|
+
keep: () => {
|
|
43945
|
+
change.span = swapped.span;
|
|
43946
|
+
}
|
|
43947
|
+
};
|
|
43948
|
+
});
|
|
43949
|
+
case "inserted": return rewriteFrame(change, (source) => {
|
|
43950
|
+
const written = side === "before" ? removeInserted(source, change.span) : restoreInserted(source, change.span);
|
|
43951
|
+
return written && {
|
|
43952
|
+
html: written.html,
|
|
43953
|
+
keep: () => {
|
|
43954
|
+
change.span = written.span;
|
|
43955
|
+
}
|
|
43956
|
+
};
|
|
43957
|
+
});
|
|
43139
43958
|
}
|
|
43140
43959
|
}
|
|
43141
43960
|
/**
|
|
43142
|
-
*
|
|
43143
|
-
* reading the file again just before the rename. A write landing
|
|
43144
|
-
* read is not overwritten: the
|
|
43145
|
-
* and refused once they change again or no longer hold the
|
|
43146
|
-
* that fail a UTF-8 round trip are refused too, since decoding
|
|
43147
|
-
* each invalid byte outside the element. The change keeps
|
|
43148
|
-
* element was found
|
|
43961
|
+
* Writes a hand edit's element to the other side through a temporary file and
|
|
43962
|
+
* a rename, reading the file again just before the rename. A write landing
|
|
43963
|
+
* before that read is not overwritten: the rewrite is made once more from the
|
|
43964
|
+
* fresh bytes, and refused once they change again or no longer hold the
|
|
43965
|
+
* element. Bytes that fail a UTF-8 round trip are refused too, since decoding
|
|
43966
|
+
* would rewrite each invalid byte outside the element. The change keeps where
|
|
43967
|
+
* the element was found, through `keep`, so the next side lands on it.
|
|
43149
43968
|
*/
|
|
43150
|
-
async function
|
|
43969
|
+
async function rewriteFrame(change, rewrite) {
|
|
43151
43970
|
const temp = join(dirname(change.path), `.${basename(change.path)}.${process.pid}.tmp`);
|
|
43152
43971
|
let source = await readText(change.path);
|
|
43153
43972
|
for (let attempt = 0; source !== void 0 && attempt < 2; attempt += 1) {
|
|
43154
|
-
const
|
|
43155
|
-
if (!
|
|
43156
|
-
await writeFile(temp,
|
|
43973
|
+
const written = rewrite(source);
|
|
43974
|
+
if (!written) break;
|
|
43975
|
+
await writeFile(temp, written.html);
|
|
43157
43976
|
const now = await readText(change.path);
|
|
43158
43977
|
if (now === source) {
|
|
43159
43978
|
await rename(temp, change.path);
|
|
43160
|
-
|
|
43161
|
-
return contentHash(
|
|
43979
|
+
written.keep();
|
|
43980
|
+
return contentHash(written.html);
|
|
43162
43981
|
}
|
|
43163
43982
|
source = now;
|
|
43164
43983
|
}
|
|
@@ -43219,6 +44038,15 @@ var StepJournal = class {
|
|
|
43219
44038
|
span
|
|
43220
44039
|
});
|
|
43221
44040
|
}
|
|
44041
|
+
/** The element a placement tool wrote into a frame file, which this journal does not write. */
|
|
44042
|
+
inserted(path, ref, span) {
|
|
44043
|
+
this.changes.push({
|
|
44044
|
+
kind: "inserted",
|
|
44045
|
+
path,
|
|
44046
|
+
ref,
|
|
44047
|
+
span
|
|
44048
|
+
});
|
|
44049
|
+
}
|
|
43222
44050
|
async created(path) {
|
|
43223
44051
|
this.changes.push({
|
|
43224
44052
|
kind: "path",
|
|
@@ -47365,6 +48193,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
47365
48193
|
check: async (frame) => {
|
|
47366
48194
|
const list = await checkRendered(await browser.get(), {
|
|
47367
48195
|
baseUrl: baseUrl(),
|
|
48196
|
+
root,
|
|
47368
48197
|
frame: {
|
|
47369
48198
|
ref: frame.ref,
|
|
47370
48199
|
path: boardPath(root, frame.path),
|
|
@@ -47412,6 +48241,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
47412
48241
|
thumbnails,
|
|
47413
48242
|
measure,
|
|
47414
48243
|
frameVersion: tracker.version,
|
|
48244
|
+
settledVersion: (ref, hash) => inTurn(async () => tracker.version(ref, hash)),
|
|
47415
48245
|
checks: {
|
|
47416
48246
|
refresh: () => inTurn(async () => {
|
|
47417
48247
|
try {
|