frameboard 0.6.0 → 0.8.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 +432 -118
- package/dist/client/assets/index-C6Purk3o.js +111 -0
- package/dist/client/index.html +1 -1
- package/dist/hook.js +48 -1
- package/package.json +2 -2
- package/dist/client/assets/index-Bu_iEvp_.js +0 -111
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import childProcess, { execFile, spawn } from "node:child_process";
|
|
|
4
4
|
import { EventEmitter, once } from "node:events";
|
|
5
5
|
import * as sp from "node:path";
|
|
6
6
|
import path, { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
|
-
import fs, { createReadStream, existsSync, readFileSync, realpathSync, renameSync, rmSync, stat, statSync, unwatchFile, watch, watchFile, writeFileSync } from "node:fs";
|
|
7
|
+
import fs, { copyFileSync, createReadStream, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, stat, statSync, unwatchFile, watch, watchFile, writeFileSync } from "node:fs";
|
|
8
8
|
import process$1, { versions } from "node:process";
|
|
9
9
|
import { isDeepStrictEqual, promisify, stripVTControlCharacters } from "node:util";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
@@ -9319,13 +9319,12 @@ function findBoard(cwd) {
|
|
|
9319
9319
|
}
|
|
9320
9320
|
/**
|
|
9321
9321
|
* The board `serve` shows, started when none exists: at `--root` when given,
|
|
9322
|
-
* else the board the walk finds, else `.frameboard/`
|
|
9323
|
-
* else `.frameboard/` in `cwd`. A board folder holding no project gets one
|
|
9322
|
+
* else the board the walk finds, else `.frameboard/` in `cwd`. A board folder holding no project gets one
|
|
9324
9323
|
* project with one empty page, and one missing only `board.json` gets that
|
|
9325
9324
|
* alone.
|
|
9326
9325
|
*/
|
|
9327
9326
|
async function startBoard({ root, cwd }, now = /* @__PURE__ */ new Date()) {
|
|
9328
|
-
const target = root === void 0 ? findBoard(cwd) ?? join(
|
|
9327
|
+
const target = root === void 0 ? findBoard(cwd) ?? join(cwd, ".frameboard") : resolve(cwd, root);
|
|
9329
9328
|
await mkdir(target, { recursive: true });
|
|
9330
9329
|
if (!existsSync(join(target, "board.json"))) await writeRecord(join(target, BOARD_FILE), { version: 1 });
|
|
9331
9330
|
let created = false;
|
|
@@ -9344,12 +9343,6 @@ async function startBoard({ root, cwd }, now = /* @__PURE__ */ new Date()) {
|
|
|
9344
9343
|
created
|
|
9345
9344
|
};
|
|
9346
9345
|
}
|
|
9347
|
-
function findRepositoryTop(cwd) {
|
|
9348
|
-
for (let dir = resolve(cwd);; dir = dirname(dir)) {
|
|
9349
|
-
if (existsSync(join(dir, ".git"))) return dir;
|
|
9350
|
-
if (dirname(dir) === dir) return null;
|
|
9351
|
-
}
|
|
9352
|
-
}
|
|
9353
9346
|
async function isDirectory(path) {
|
|
9354
9347
|
try {
|
|
9355
9348
|
return (await stat$1(path)).isDirectory();
|
|
@@ -9360,7 +9353,7 @@ async function isDirectory(path) {
|
|
|
9360
9353
|
}
|
|
9361
9354
|
//#endregion
|
|
9362
9355
|
//#region package.json
|
|
9363
|
-
var version$1 = "0.
|
|
9356
|
+
var version$1 = "0.8.0";
|
|
9364
9357
|
var dependencies = { "playwright-core": "1.64.1" };
|
|
9365
9358
|
//#endregion
|
|
9366
9359
|
//#region src/shared/version.ts
|
|
@@ -13449,11 +13442,11 @@ const setCookie = (c, name, value, opt) => {
|
|
|
13449
13442
|
*/
|
|
13450
13443
|
function isWriter(headers, access) {
|
|
13451
13444
|
const bearer = /^Bearer (.+)$/.exec(headers.authorization ?? "")?.[1];
|
|
13452
|
-
if (bearer !== void 0 && matches(bearer, access.token())) return true;
|
|
13445
|
+
if (bearer !== void 0 && matches$1(bearer, access.token())) return true;
|
|
13453
13446
|
const { origin } = headers;
|
|
13454
13447
|
if (origin === void 0 || !isOwnOrigin(origin, access)) return false;
|
|
13455
13448
|
const cookie = readCookie(headers.cookie, access.cookieName);
|
|
13456
|
-
return cookie !== void 0 && matches(cookie, access.key);
|
|
13449
|
+
return cookie !== void 0 && matches$1(cookie, access.key);
|
|
13457
13450
|
}
|
|
13458
13451
|
/** Hono middleware answering 401 in the envelope to anyone who is not a writer. */
|
|
13459
13452
|
function requireWriter(access) {
|
|
@@ -13485,7 +13478,7 @@ function readCookie(header, name) {
|
|
|
13485
13478
|
if (at !== -1 && part.slice(0, at).trim() === name) return part.slice(at + 1).trim();
|
|
13486
13479
|
}
|
|
13487
13480
|
}
|
|
13488
|
-
function matches(given, expected) {
|
|
13481
|
+
function matches$1(given, expected) {
|
|
13489
13482
|
if (expected === null) return false;
|
|
13490
13483
|
const a = Buffer.from(given);
|
|
13491
13484
|
const b = Buffer.from(expected);
|
|
@@ -13497,19 +13490,23 @@ const COOKIE_MAX_AGE_S = 3456e4;
|
|
|
13497
13490
|
/**
|
|
13498
13491
|
* How a tab becomes a writer. A redeem URL carries a single-use ticket that
|
|
13499
13492
|
* trades for the board's cookie, and answers a 303 home either way so a used
|
|
13500
|
-
* ticket still lands on a board that reads.
|
|
13493
|
+
* ticket still lands on a board that reads. A failed redeem lands on
|
|
13494
|
+
* `/?link=expired`, the flag the client's expired-link toast reads.
|
|
13501
13495
|
*/
|
|
13502
13496
|
function accessRoutes(access, tickets) {
|
|
13503
13497
|
const app = new Hono();
|
|
13504
13498
|
app.get("/api/access/redeem", (c) => {
|
|
13505
13499
|
const ticket = c.req.query("ticket");
|
|
13506
|
-
if (ticket !== void 0 && tickets.redeem(ticket))
|
|
13507
|
-
|
|
13508
|
-
|
|
13509
|
-
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13500
|
+
if (ticket !== void 0 && tickets.redeem(ticket)) {
|
|
13501
|
+
setCookie(c, access.cookieName, access.key, {
|
|
13502
|
+
httpOnly: true,
|
|
13503
|
+
sameSite: "Strict",
|
|
13504
|
+
path: "/api",
|
|
13505
|
+
maxAge: COOKIE_MAX_AGE_S
|
|
13506
|
+
});
|
|
13507
|
+
return c.redirect("/", 303);
|
|
13508
|
+
}
|
|
13509
|
+
return c.redirect("/?link=expired", 303);
|
|
13513
13510
|
});
|
|
13514
13511
|
app.post("/api/access/ticket", (c) => {
|
|
13515
13512
|
if (!isWriter({ authorization: c.req.header("authorization") }, access)) return c.json({
|
|
@@ -13520,10 +13517,14 @@ function accessRoutes(access, tickets) {
|
|
|
13520
13517
|
}
|
|
13521
13518
|
}, 401);
|
|
13522
13519
|
const url = new URL("/api/access/redeem", c.req.url);
|
|
13523
|
-
|
|
13520
|
+
const { ticket, expiresAt } = tickets.mint();
|
|
13521
|
+
url.searchParams.set("ticket", ticket);
|
|
13524
13522
|
return c.json({
|
|
13525
13523
|
ok: true,
|
|
13526
|
-
data: {
|
|
13524
|
+
data: {
|
|
13525
|
+
url: url.toString(),
|
|
13526
|
+
expiresAt
|
|
13527
|
+
}
|
|
13527
13528
|
});
|
|
13528
13529
|
});
|
|
13529
13530
|
return app;
|
|
@@ -27437,7 +27438,7 @@ function assetsDirOf(source) {
|
|
|
27437
27438
|
return join(source.projectDir, ASSETS_FOLDER);
|
|
27438
27439
|
}
|
|
27439
27440
|
/** Line and column of a span in `text`, both counted from 1. */
|
|
27440
|
-
function locate(text, startOffset, endOffset) {
|
|
27441
|
+
function locate$1(text, startOffset, endOffset) {
|
|
27441
27442
|
let line = 1;
|
|
27442
27443
|
let lineStart = 0;
|
|
27443
27444
|
for (let index = text.indexOf("\n"); index !== -1 && index < startOffset;) {
|
|
@@ -27538,7 +27539,7 @@ function readThemeColors(source) {
|
|
|
27538
27539
|
const end = sheet.offset + (node.source?.end?.offset ?? 0);
|
|
27539
27540
|
firstColor = {
|
|
27540
27541
|
path: boardPath(source.root, sheet.path),
|
|
27541
|
-
location: locate(text, start, end)
|
|
27542
|
+
location: locate$1(text, start, end)
|
|
27542
27543
|
};
|
|
27543
27544
|
}
|
|
27544
27545
|
});
|
|
@@ -27576,7 +27577,54 @@ function definesTheme(node) {
|
|
|
27576
27577
|
* count, and neither does a `url()` whose file name reads as a color.
|
|
27577
27578
|
*/
|
|
27578
27579
|
function setsLiteralColor(property, value) {
|
|
27579
|
-
|
|
27580
|
+
if (!COLOR_PROPERTIES$1.test(property)) return false;
|
|
27581
|
+
if (SHADOW_PROPERTIES.test(property) && isFaintShadow(value)) return false;
|
|
27582
|
+
return isLiteralColor(value);
|
|
27583
|
+
}
|
|
27584
|
+
const SHADOW_PROPERTIES = /^(box|text)-shadow$/i;
|
|
27585
|
+
const RGB_COLOR = /\brgba?\(([^)]*)\)/gi;
|
|
27586
|
+
const HEX_TOKEN = /#([0-9a-f]{4}|[0-9a-f]{8})\b/gi;
|
|
27587
|
+
/**
|
|
27588
|
+
* Whether every color a shadow names is black or white at or under 0.2
|
|
27589
|
+
* alpha, which reads the same on either theme, so a frame writing one for a
|
|
27590
|
+
* single theme is no finding.
|
|
27591
|
+
*/
|
|
27592
|
+
function isFaintShadow(value) {
|
|
27593
|
+
const own = stripFunctions(value, ["var", "url"]);
|
|
27594
|
+
const colors = [];
|
|
27595
|
+
const rest = own.replace(RGB_COLOR, (_match, args) => {
|
|
27596
|
+
colors.push(isFaintRgb(args));
|
|
27597
|
+
return " ";
|
|
27598
|
+
}).replace(HEX_TOKEN, (_match, digits) => {
|
|
27599
|
+
colors.push(isFaintHex(digits));
|
|
27600
|
+
return " ";
|
|
27601
|
+
});
|
|
27602
|
+
return colors.length > 0 && colors.every(Boolean) && !isLiteralColor(rest);
|
|
27603
|
+
}
|
|
27604
|
+
function isFaintRgb(args) {
|
|
27605
|
+
const parts = args.split(/[\s,/]+/).map((part) => part.trim()).filter(Boolean);
|
|
27606
|
+
const [r, g, b, a] = parts;
|
|
27607
|
+
if (parts.length !== 4 || a === void 0) return false;
|
|
27608
|
+
const alpha = a.endsWith("%") ? Number.parseFloat(a) / 100 : Number.parseFloat(a);
|
|
27609
|
+
return isBlackOrWhite(readChannel(r), readChannel(g), readChannel(b)) && alpha <= .200000001;
|
|
27610
|
+
}
|
|
27611
|
+
function readChannel(part) {
|
|
27612
|
+
if (part === void 0) return void 0;
|
|
27613
|
+
if (part.endsWith("%")) return Number.parseFloat(part) / 100 * 255;
|
|
27614
|
+
return Number.parseFloat(part);
|
|
27615
|
+
}
|
|
27616
|
+
function isFaintHex(digits) {
|
|
27617
|
+
const full = digits.length === 4 ? [...digits].map((digit) => digit + digit).join("") : digits;
|
|
27618
|
+
const [r, g, b, a] = [
|
|
27619
|
+
0,
|
|
27620
|
+
2,
|
|
27621
|
+
4,
|
|
27622
|
+
6
|
|
27623
|
+
].map((at) => Number.parseInt(full.slice(at, at + 2), 16));
|
|
27624
|
+
return isBlackOrWhite(r, g, b) && (a ?? 255) / 255 <= .200000001;
|
|
27625
|
+
}
|
|
27626
|
+
function isBlackOrWhite(r, g, b) {
|
|
27627
|
+
return r === 0 && g === 0 && b === 0 || r === 255 && g === 255 && b === 255;
|
|
27580
27628
|
}
|
|
27581
27629
|
/** Whether a value holds a color of its own, outside any `var()` or `url()`. */
|
|
27582
27630
|
function isLiteralColor(value) {
|
|
@@ -28368,6 +28416,78 @@ function removeAttribute(source, element, name) {
|
|
|
28368
28416
|
return splice(source, start, span.endOffset, "");
|
|
28369
28417
|
}
|
|
28370
28418
|
//#endregion
|
|
28419
|
+
//#region src/server/edit/element-span.ts
|
|
28420
|
+
const OTHER$1 = {
|
|
28421
|
+
before: "after",
|
|
28422
|
+
after: "before"
|
|
28423
|
+
};
|
|
28424
|
+
/** The source range a scope covers on a stated element, or undefined for an implied one. */
|
|
28425
|
+
function rangeOf(element, scope) {
|
|
28426
|
+
const location = element.sourceCodeLocation;
|
|
28427
|
+
if (!location?.startTag) return void 0;
|
|
28428
|
+
return scope === "start-tag" ? [location.startTag.startOffset, location.startTag.endOffset] : [location.startOffset, location.endOffset];
|
|
28429
|
+
}
|
|
28430
|
+
/** The bytes of one element a scope covers, as `ElementSpan` records them. */
|
|
28431
|
+
function spanText(source, element, scope) {
|
|
28432
|
+
const range = rangeOf(element, scope);
|
|
28433
|
+
return range ? source.slice(...range) : "";
|
|
28434
|
+
}
|
|
28435
|
+
function matches(source, element, scope, text) {
|
|
28436
|
+
const range = element && rangeOf(element, scope);
|
|
28437
|
+
return range && source.slice(...range) === text ? range : void 0;
|
|
28438
|
+
}
|
|
28439
|
+
/**
|
|
28440
|
+
* The element reading `span[side]`: the one at the recorded index while the
|
|
28441
|
+
* element count is unchanged, else the one element whose bytes match, else
|
|
28442
|
+
* none, since guessing between two would write over the wrong one.
|
|
28443
|
+
*/
|
|
28444
|
+
function locate(source, tree, span, side) {
|
|
28445
|
+
const text = span[side];
|
|
28446
|
+
if (tree.elements.length === span.count) {
|
|
28447
|
+
const range = matches(source, tree.elements[span.index], span.scope, text);
|
|
28448
|
+
return range && {
|
|
28449
|
+
index: span.index,
|
|
28450
|
+
range
|
|
28451
|
+
};
|
|
28452
|
+
}
|
|
28453
|
+
const found = tree.elements.flatMap((element, index) => {
|
|
28454
|
+
const range = matches(source, element, span.scope, text);
|
|
28455
|
+
return range ? [{
|
|
28456
|
+
index,
|
|
28457
|
+
range
|
|
28458
|
+
}] : [];
|
|
28459
|
+
});
|
|
28460
|
+
return found.length === 1 ? found[0] : void 0;
|
|
28461
|
+
}
|
|
28462
|
+
/** Whether the frame still holds the edited element as `side` of the edit left it. */
|
|
28463
|
+
function holdsSpan(source, span, side) {
|
|
28464
|
+
return locate(source, parseFrame(source), span, side) !== void 0;
|
|
28465
|
+
}
|
|
28466
|
+
/**
|
|
28467
|
+
* Finds the element reading `side` of the span and writes the other side in
|
|
28468
|
+
* its place, leaving every other byte as it stands. Answers undefined when the
|
|
28469
|
+
* element is not found, or when the swap would leave it unfound, as a write
|
|
28470
|
+
* the parser reads across element bounds would.
|
|
28471
|
+
*/
|
|
28472
|
+
function swapSpan(source, span, side) {
|
|
28473
|
+
const tree = parseFrame(source);
|
|
28474
|
+
const found = locate(source, tree, span, side);
|
|
28475
|
+
if (!found) return void 0;
|
|
28476
|
+
const [start, end] = found.range;
|
|
28477
|
+
const html = source.slice(0, start) + span[OTHER$1[side]] + source.slice(end);
|
|
28478
|
+
const moved = {
|
|
28479
|
+
...span,
|
|
28480
|
+
index: found.index,
|
|
28481
|
+
count: tree.elements.length
|
|
28482
|
+
};
|
|
28483
|
+
const written = parseFrame(html);
|
|
28484
|
+
if (written.elements.length !== moved.count || !matches(html, written.elements[moved.index], span.scope, span[OTHER$1[side]])) return;
|
|
28485
|
+
return {
|
|
28486
|
+
html,
|
|
28487
|
+
span: moved
|
|
28488
|
+
};
|
|
28489
|
+
}
|
|
28490
|
+
//#endregion
|
|
28371
28491
|
//#region src/server/edit/style.ts
|
|
28372
28492
|
/**
|
|
28373
28493
|
* The longhands a shorthand write drops, so a later longhand in the attribute
|
|
@@ -28689,7 +28809,19 @@ function applyEdit(source, address, change) {
|
|
|
28689
28809
|
const after = parseFrame(written.html);
|
|
28690
28810
|
const target = after.elements[address.index];
|
|
28691
28811
|
if (!target || !holdsValue(target, normalized) || !changesOnlyTarget(before, after, address.index, normalized)) return refuse("verify-failed", `the edit to <${element.tagName}> would change more than that element, so nothing was written`);
|
|
28692
|
-
|
|
28812
|
+
const scope = normalized.kind === "text" ? "element" : "start-tag";
|
|
28813
|
+
const span = {
|
|
28814
|
+
scope,
|
|
28815
|
+
index: address.index,
|
|
28816
|
+
count: before.elements.length,
|
|
28817
|
+
before: spanText(source, element, scope),
|
|
28818
|
+
after: spanText(written.html, target, scope)
|
|
28819
|
+
};
|
|
28820
|
+
return {
|
|
28821
|
+
ok: true,
|
|
28822
|
+
html: written.html,
|
|
28823
|
+
span
|
|
28824
|
+
};
|
|
28693
28825
|
}
|
|
28694
28826
|
//#endregion
|
|
28695
28827
|
//#region src/server/edit/frame-file.ts
|
|
@@ -28722,7 +28854,8 @@ function editFrameFile(path, address, change) {
|
|
|
28722
28854
|
renameSync(temp, path);
|
|
28723
28855
|
return {
|
|
28724
28856
|
ok: true,
|
|
28725
|
-
hash: contentHash(applied.html)
|
|
28857
|
+
hash: contentHash(applied.html),
|
|
28858
|
+
span: applied.span
|
|
28726
28859
|
};
|
|
28727
28860
|
}
|
|
28728
28861
|
//#endregion
|
|
@@ -28794,9 +28927,9 @@ const editSchema = object$1({
|
|
|
28794
28927
|
/**
|
|
28795
28928
|
* A hand edit of one element, behind `requireWriter`, its body mirroring
|
|
28796
28929
|
* `edit`'s flags with the hash required, since the board always holds the
|
|
28797
|
-
* one it rendered. It writes through `editFrameFile`, records the
|
|
28798
|
-
*
|
|
28799
|
-
* returns answers 409 with its code, `stale-address` among them.
|
|
28930
|
+
* one it rendered. It writes through `editFrameFile`, records the edited
|
|
28931
|
+
* element's span as one step, and answers the `edit` record. Each refusal
|
|
28932
|
+
* the writer returns answers 409 with its code, `stale-address` among them.
|
|
28800
28933
|
*/
|
|
28801
28934
|
function editRoutes(root, access, history) {
|
|
28802
28935
|
const app = new Hono();
|
|
@@ -28805,7 +28938,6 @@ function editRoutes(root, access, history) {
|
|
|
28805
28938
|
const frame = await resolveFrameRef(root, body.ref, { cwd: root });
|
|
28806
28939
|
const ref = `${frame.project}/${frame.page}/${frame.name}`;
|
|
28807
28940
|
await refuseClaimed(root, [ref], /* @__PURE__ */ new Date());
|
|
28808
|
-
const before = readFileSync(frame.path);
|
|
28809
28941
|
const result = editFrameFile(frame.path, {
|
|
28810
28942
|
index: body.index,
|
|
28811
28943
|
hash: body.hash
|
|
@@ -28821,10 +28953,9 @@ function editRoutes(root, access, history) {
|
|
|
28821
28953
|
}
|
|
28822
28954
|
}
|
|
28823
28955
|
}, 409);
|
|
28824
|
-
|
|
28825
|
-
if (contentHash(after) === result.hash && !after.equals(before)) {
|
|
28956
|
+
if (result.span.before !== result.span.after) {
|
|
28826
28957
|
const journal = history.journal();
|
|
28827
|
-
journal.
|
|
28958
|
+
journal.element(frame.path, ref, result.span);
|
|
28828
28959
|
history.record({
|
|
28829
28960
|
id: journal.id,
|
|
28830
28961
|
changes: journal.changes,
|
|
@@ -36472,7 +36603,7 @@ async function writeImages(rendered) {
|
|
|
36472
36603
|
//#endregion
|
|
36473
36604
|
//#region src/cli/commands/capture.ts
|
|
36474
36605
|
function registerCapture(program, context) {
|
|
36475
|
-
const { io
|
|
36606
|
+
const { io } = context;
|
|
36476
36607
|
act(addVerb(program, "capture", "Write PNGs of a frame, or of every visible frame of a page, in light, dark, or both", { project: true }).argument("[frame-ref]", "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file").option("--page <page-ref>", "capture every visible frame of this page, <page> or <project>/<page>, in place of one frame").option("--composite", "with --page, one image of the page with each frame at its layout position").addOption(new Option("--theme <theme>", "the theme to capture").choices([
|
|
36477
36608
|
"light",
|
|
36478
36609
|
"dark",
|
|
@@ -36497,7 +36628,7 @@ function registerCapture(program, context) {
|
|
|
36497
36628
|
const out = await outOf();
|
|
36498
36629
|
const images = await withFrameHost({
|
|
36499
36630
|
root,
|
|
36500
|
-
facesDir
|
|
36631
|
+
facesDir: context.facesDir
|
|
36501
36632
|
}, "capture", (browser, baseUrl) => options.composite ? captureComposite(browser, {
|
|
36502
36633
|
baseUrl,
|
|
36503
36634
|
page: {
|
|
@@ -36523,7 +36654,7 @@ function registerCapture(program, context) {
|
|
|
36523
36654
|
const out = await outOf();
|
|
36524
36655
|
const images = await withFrameHost({
|
|
36525
36656
|
root,
|
|
36526
|
-
facesDir
|
|
36657
|
+
facesDir: context.facesDir
|
|
36527
36658
|
}, "capture", (browser, baseUrl) => captureFrameImages(browser, {
|
|
36528
36659
|
baseUrl,
|
|
36529
36660
|
frames: [frame],
|
|
@@ -36709,7 +36840,7 @@ function sheetLoads(source, sheet) {
|
|
|
36709
36840
|
url,
|
|
36710
36841
|
base: sheetBase(sheet),
|
|
36711
36842
|
path,
|
|
36712
|
-
location: locate(text, sheet.offset + start, sheet.offset + end),
|
|
36843
|
+
location: locate$1(text, sheet.offset + start, sheet.offset + end),
|
|
36713
36844
|
via: kind === "import" ? "@import" : "url()"
|
|
36714
36845
|
}));
|
|
36715
36846
|
}
|
|
@@ -37305,7 +37436,10 @@ function registerCheck(program, context) {
|
|
|
37305
37436
|
findings: [...own.findings, ...browser.findings],
|
|
37306
37437
|
browser: browser.run
|
|
37307
37438
|
};
|
|
37308
|
-
if (result.findings.some((finding) => finding.severity === "error"))
|
|
37439
|
+
if (result.findings.some((finding) => finding.severity === "error")) {
|
|
37440
|
+
if (!options.json) context.io.stdout(`${describe$5(result)}\n`);
|
|
37441
|
+
throw new FrameboardError("check-findings", summarize(result), { ...result });
|
|
37442
|
+
}
|
|
37309
37443
|
return {
|
|
37310
37444
|
data: result,
|
|
37311
37445
|
human: describe$5(result)
|
|
@@ -37317,16 +37451,21 @@ async function run(root, target, options, cwd) {
|
|
|
37317
37451
|
project: options.project,
|
|
37318
37452
|
cwd
|
|
37319
37453
|
};
|
|
37320
|
-
if (target === void 0)
|
|
37321
|
-
const project = await resolveProject(root, options.project);
|
|
37322
|
-
return {
|
|
37323
|
-
result: await checkProject(root, project.name),
|
|
37324
|
-
refs: await projectRefs(root, project.name)
|
|
37325
|
-
};
|
|
37326
|
-
}
|
|
37454
|
+
if (target === void 0) return projectRun(root, (await resolveProject(root, options.project)).name);
|
|
37327
37455
|
const parts = target.split("/");
|
|
37328
37456
|
if (target.endsWith(".html") || parts.length === 3) return frameRun(await resolveFrameRef(root, target, refOptions));
|
|
37329
|
-
if (parts.length === 1)
|
|
37457
|
+
if (parts.length === 1) try {
|
|
37458
|
+
return await pageRun(root, await resolvePageRef(root, target, refOptions));
|
|
37459
|
+
} catch (pageError) {
|
|
37460
|
+
if (options.project !== void 0 || !(pageError instanceof FrameboardError) || !NOT_FRAME.has(pageError.code)) throw pageError;
|
|
37461
|
+
let project;
|
|
37462
|
+
try {
|
|
37463
|
+
project = await resolveProject(root, target);
|
|
37464
|
+
} catch {
|
|
37465
|
+
throw pageError;
|
|
37466
|
+
}
|
|
37467
|
+
return projectRun(root, project.name);
|
|
37468
|
+
}
|
|
37330
37469
|
try {
|
|
37331
37470
|
return frameRun(await resolveFrameRef(root, target, refOptions));
|
|
37332
37471
|
} catch (frameError) {
|
|
@@ -37353,6 +37492,12 @@ async function pageRun(root, { project, page }) {
|
|
|
37353
37492
|
refs: names.map((name) => `${project}/${page}/${name}`)
|
|
37354
37493
|
};
|
|
37355
37494
|
}
|
|
37495
|
+
async function projectRun(root, project) {
|
|
37496
|
+
return {
|
|
37497
|
+
result: await checkProject(root, project),
|
|
37498
|
+
refs: await projectRefs(root, project)
|
|
37499
|
+
};
|
|
37500
|
+
}
|
|
37356
37501
|
async function projectRefs(root, project) {
|
|
37357
37502
|
const refs = [];
|
|
37358
37503
|
for (const page of await listPageFolders(join(root, project))) for (const name of await listFrames(join(root, project, page))) refs.push(`${project}/${page}/${name}`);
|
|
@@ -37383,10 +37528,15 @@ async function browserFindings(root, refs) {
|
|
|
37383
37528
|
return notRunning;
|
|
37384
37529
|
}
|
|
37385
37530
|
}
|
|
37386
|
-
/**
|
|
37387
|
-
function
|
|
37531
|
+
/** The count line alone, such as `Checked 3 frames, 2 findings.` */
|
|
37532
|
+
function summarize({ checked, findings }) {
|
|
37388
37533
|
const frames = `${checked} frame${checked === 1 ? "" : "s"}`;
|
|
37389
|
-
|
|
37534
|
+
return findings.length === 0 ? `Checked ${frames}, no findings.` : `Checked ${frames}, ${findings.length} finding${findings.length === 1 ? "" : "s"}.`;
|
|
37535
|
+
}
|
|
37536
|
+
/** One line per finding, then the count, then why the browser rules did not run. */
|
|
37537
|
+
function describe$5(result) {
|
|
37538
|
+
const { findings, browser } = result;
|
|
37539
|
+
const lines = [...findings.map(formatFinding), summarize(result)];
|
|
37390
37540
|
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.");
|
|
37391
37541
|
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}.`);
|
|
37392
37542
|
return lines.join("\n");
|
|
@@ -37831,7 +37981,7 @@ function contentFormat() {
|
|
|
37831
37981
|
`A page is any folder in a project except ${ASSETS_FOLDER}/ and dot-named ones. Its ${LAYOUT_FILE} holds each frame's box, stacking order, and flags.`,
|
|
37832
37982
|
`A frame is any *${FRAME_EXTENSION} file directly in a page, named by its stem.`,
|
|
37833
37983
|
`A page's notes sit in its ${NOTES_FILE$1}, never in a frame. A note pins to a frame or to one element by index and the frame file's hash, and reads at the frame once the file changes. Read them with notes, answer with notes reply, and close them with notes done.`,
|
|
37834
|
-
`serve
|
|
37984
|
+
`serve reuses a board the walk finds, and otherwise creates ${DEFAULT_BOARD_FOLDER}/ in the working folder with project ${START_PROJECT} and empty page ${START_PAGE}, and records its address in ${RUN_FOLDER}/${ADDRESS_FILE}.`,
|
|
37835
37985
|
`Dot-named folders, *${LOCK_SUFFIX} files, and *${TEMP_SUFFIX} files belong to Frameboard and are never content.`
|
|
37836
37986
|
],
|
|
37837
37987
|
names: {
|
|
@@ -37862,20 +38012,69 @@ function contentFormat() {
|
|
|
37862
38012
|
};
|
|
37863
38013
|
}
|
|
37864
38014
|
//#endregion
|
|
38015
|
+
//#region src/cli/docs/text.ts
|
|
38016
|
+
const INDENT = " ";
|
|
38017
|
+
/**
|
|
38018
|
+
* The human form of `docs`: one heading per section the JSON carries, with
|
|
38019
|
+
* the record schemas named rather than printed, since `--json` holds them whole.
|
|
38020
|
+
*/
|
|
38021
|
+
function renderDocs(docs) {
|
|
38022
|
+
return [
|
|
38023
|
+
`frameboard ${docs.version}`,
|
|
38024
|
+
section("Verbs", docs.verbs.flatMap(verbLines)),
|
|
38025
|
+
section("Exit codes", table(Object.entries(docs.exitCodes))),
|
|
38026
|
+
section("Records", [`${INDENT}${Object.keys(docs.records).join(", ")}`, `${INDENT}Run frameboard docs --json for each record's JSON schema.`]),
|
|
38027
|
+
section("Content format", formatLines(docs.contentFormat)),
|
|
38028
|
+
section("Check rules", docs.checks.rules.map((rule) => `${INDENT}${rule.id} ${rule.tier}${rule.configKey ? `, on with checks.${rule.configKey}` : ""}. ${rule.description}`))
|
|
38029
|
+
].join("\n\n");
|
|
38030
|
+
}
|
|
38031
|
+
function section(heading, lines) {
|
|
38032
|
+
return [heading, ...lines].join("\n");
|
|
38033
|
+
}
|
|
38034
|
+
function verbLines(verb) {
|
|
38035
|
+
const usage = verb.arguments.map((argument) => argument.required ? `<${argument.name}>` : `[${argument.name}]`).join(" ");
|
|
38036
|
+
return [`frameboard ${verb.name}${usage ? ` ${usage}` : ""} ${verb.description}`, ...verb.options.map((option) => {
|
|
38037
|
+
const extras = [option.choices ? `one of ${option.choices.join(", ")}` : "", option.default === void 0 ? "" : `default ${JSON.stringify(option.default)}`].filter(Boolean);
|
|
38038
|
+
return `${INDENT}${option.flags} ${option.description}${extras.length ? ` (${extras.join(", ")})` : ""}`;
|
|
38039
|
+
})];
|
|
38040
|
+
}
|
|
38041
|
+
function table(rows) {
|
|
38042
|
+
const width = Math.max(...rows.map(([name]) => name.length));
|
|
38043
|
+
return rows.map(([name, value]) => `${INDENT}${name.padEnd(width)} ${value}`);
|
|
38044
|
+
}
|
|
38045
|
+
function formatLines(format) {
|
|
38046
|
+
const sizes = Object.entries(format.frameSizes).map(([name, size]) => `${name} ${size.width} × ${size.height}`);
|
|
38047
|
+
return [
|
|
38048
|
+
"Folders",
|
|
38049
|
+
...format.folders.map((line) => `${INDENT}${line}`),
|
|
38050
|
+
"Names",
|
|
38051
|
+
`${INDENT}Match ${format.names.pattern}, at most ${format.names.maxLength} characters. Reserved page names: ${format.names.reservedPageNames.join(", ")}.`,
|
|
38052
|
+
`${INDENT}${format.names.collision}`,
|
|
38053
|
+
"Frame sizes",
|
|
38054
|
+
`${INDENT}${sizes.join(", ")}, defaulting to ${format.defaultFrameSize}`,
|
|
38055
|
+
"Layout",
|
|
38056
|
+
...format.layout.map((line) => `${INDENT}${line}`),
|
|
38057
|
+
"Assets",
|
|
38058
|
+
`${INDENT}${format.assets}`,
|
|
38059
|
+
"Look",
|
|
38060
|
+
...format.look.map((line) => `${INDENT}${line}`)
|
|
38061
|
+
];
|
|
38062
|
+
}
|
|
38063
|
+
//#endregion
|
|
37865
38064
|
//#region src/cli/commands/docs.ts
|
|
37866
38065
|
function registerDocs(program, context) {
|
|
37867
38066
|
act(addVerb(program, "docs", "Print the verbs, exit codes, record shapes, content format, and check rules"), context, async () => {
|
|
37868
|
-
const
|
|
38067
|
+
const data = {
|
|
38068
|
+
version,
|
|
38069
|
+
verbs: describeVerbs(program),
|
|
38070
|
+
exitCodes: EXIT_CODES,
|
|
38071
|
+
records: Object.fromEntries(Object.entries(RECORDS).map(([name, schema]) => [name, toJSONSchema(schema, { io: "input" })])),
|
|
38072
|
+
contentFormat: contentFormat(),
|
|
38073
|
+
checks: { rules: RULES }
|
|
38074
|
+
};
|
|
37869
38075
|
return {
|
|
37870
|
-
data
|
|
37871
|
-
|
|
37872
|
-
verbs,
|
|
37873
|
-
exitCodes: EXIT_CODES,
|
|
37874
|
-
records: Object.fromEntries(Object.entries(RECORDS).map(([name, schema]) => [name, toJSONSchema(schema, { io: "input" })])),
|
|
37875
|
-
contentFormat: contentFormat(),
|
|
37876
|
-
checks: { rules: RULES }
|
|
37877
|
-
},
|
|
37878
|
-
human: verbs.map((verb) => `frameboard ${verb.name} ${verb.description}`).join("\n")
|
|
38076
|
+
data,
|
|
38077
|
+
human: renderDocs(data)
|
|
37879
38078
|
};
|
|
37880
38079
|
});
|
|
37881
38080
|
}
|
|
@@ -38047,7 +38246,7 @@ function describe$4(claims, now) {
|
|
|
38047
38246
|
const FRAME_REF = "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file";
|
|
38048
38247
|
const ANY_INTEGER = parseInteger(Number.MIN_SAFE_INTEGER);
|
|
38049
38248
|
function registerFrame(program, context) {
|
|
38050
|
-
const { io
|
|
38249
|
+
const { io } = context;
|
|
38051
38250
|
const frame = program.command("frame").description("Manage frames");
|
|
38052
38251
|
const verb = (name, description) => addVerb(frame, name, description, { project: true }).argument("<frame-ref>", FRAME_REF);
|
|
38053
38252
|
const withSize = (command) => command.addOption(new Option("--size <preset>", "a size preset").choices(Object.keys(FRAME_SIZES))).option("--width <n>", "width in px", parseInteger(1)).option("--height <n>", "height in px", parseInteger(1));
|
|
@@ -38081,7 +38280,7 @@ function registerFrame(program, context) {
|
|
|
38081
38280
|
const frame = await readFrame$1(root, ref, refOptions);
|
|
38082
38281
|
const result = await withFrameHost({
|
|
38083
38282
|
root,
|
|
38084
|
-
facesDir
|
|
38283
|
+
facesDir: context.facesDir
|
|
38085
38284
|
}, "frame fit", (browser, baseUrl) => fitFrame(browser, {
|
|
38086
38285
|
...refOptions,
|
|
38087
38286
|
root,
|
|
@@ -41906,7 +42105,7 @@ function readLiveElements() {
|
|
|
41906
42105
|
//#endregion
|
|
41907
42106
|
//#region src/cli/commands/inspect.ts
|
|
41908
42107
|
function registerInspect(program, context) {
|
|
41909
|
-
const { io
|
|
42108
|
+
const { io } = context;
|
|
41910
42109
|
act(addVerb(program, "inspect", "Report each rendered element of a frame with its index, box, and computed color and type, the index being the address 'edit' takes", { project: true }).argument("<frame-ref>", "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file").addOption(new Option("--theme <theme>", "the theme to read").choices(["light", "dark"]).default("light")).option("--index <n>", "report this element alone", parseInteger(0)), context, async ([ref = ""], options) => {
|
|
41911
42110
|
const root = await boardOf(options, io);
|
|
41912
42111
|
const frame = await readFrame$1(root, ref, {
|
|
@@ -41915,7 +42114,7 @@ function registerInspect(program, context) {
|
|
|
41915
42114
|
});
|
|
41916
42115
|
const data = await withFrameHost({
|
|
41917
42116
|
root,
|
|
41918
|
-
facesDir
|
|
42117
|
+
facesDir: context.facesDir
|
|
41919
42118
|
}, "inspect", (browser, baseUrl) => inspectFrame(browser, {
|
|
41920
42119
|
baseUrl,
|
|
41921
42120
|
frame,
|
|
@@ -41993,8 +42192,8 @@ function registerNotes(program, context) {
|
|
|
41993
42192
|
human: describe$1(listed)
|
|
41994
42193
|
};
|
|
41995
42194
|
});
|
|
41996
|
-
act(addVerb(notes, "reply", "Answer a note in its thread on the board").argument("<id>", "the note id, n_ and 8 hex characters").argument("<text>", "the reply"), context, async ([id = "", text = ""], options) => {
|
|
41997
|
-
const found = await
|
|
42195
|
+
act(addVerb(notes, "reply", "Answer a note in its thread on the board", { project: true }).argument("<id>", "the note id, n_ and 8 hex characters").argument("<text>", "the reply"), context, async ([id = "", text = ""], options) => {
|
|
42196
|
+
const found = await noteIn(await boardOf(options, io), id, options.project);
|
|
41998
42197
|
const replyId = newNoteId();
|
|
41999
42198
|
const reply = (await updateNotes(found.path, (current) => addReply(current, id, {
|
|
42000
42199
|
text,
|
|
@@ -42010,8 +42209,8 @@ function registerNotes(program, context) {
|
|
|
42010
42209
|
human: `Replied to ${reply?.thread ?? id} on ${found.project}/${found.page}/${found.note.frame}`
|
|
42011
42210
|
};
|
|
42012
42211
|
});
|
|
42013
|
-
act(addVerb(notes, "done", "Close a note, hiding its marker on the board").argument("<id>", "the note id, n_ and 8 hex characters"), context, async ([id = ""], options) => {
|
|
42014
|
-
const found = await
|
|
42212
|
+
act(addVerb(notes, "done", "Close a note, hiding its marker on the board", { project: true }).argument("<id>", "the note id, n_ and 8 hex characters"), context, async ([id = ""], options) => {
|
|
42213
|
+
const found = await noteIn(await boardOf(options, io), id, options.project);
|
|
42015
42214
|
const file = await updateNotes(found.path, (current) => setState(current, id, "done", /* @__PURE__ */ new Date()));
|
|
42016
42215
|
const rootId = found.note.thread ?? found.note.id;
|
|
42017
42216
|
return {
|
|
@@ -42020,6 +42219,16 @@ function registerNotes(program, context) {
|
|
|
42020
42219
|
};
|
|
42021
42220
|
});
|
|
42022
42221
|
}
|
|
42222
|
+
/** The note an id names, refused as missing when `--project` names another project than the one holding it. */
|
|
42223
|
+
async function noteIn(root, id, project) {
|
|
42224
|
+
const scope = project === void 0 ? void 0 : await resolveProject(root, project);
|
|
42225
|
+
const found = await findNote(root, id);
|
|
42226
|
+
if (scope && found.project !== scope.name) throw new FrameboardError("note-not-found", `No note ${id} in project ${scope.name}. It sits in ${found.project}.`, {
|
|
42227
|
+
id,
|
|
42228
|
+
project: scope.name
|
|
42229
|
+
});
|
|
42230
|
+
return found;
|
|
42231
|
+
}
|
|
42023
42232
|
/** The pages a listing reads: the one `--page` or `--frame` names, else every page in scope. */
|
|
42024
42233
|
async function pagesIn(root, options, frame, cwd) {
|
|
42025
42234
|
const page = frame ?? (options.page ? await resolvePageRef(root, options.page, {
|
|
@@ -42050,6 +42259,27 @@ function describe$1(notes) {
|
|
|
42050
42259
|
}).join("\n");
|
|
42051
42260
|
}
|
|
42052
42261
|
//#endregion
|
|
42262
|
+
//#region src/cli/commands/open.ts
|
|
42263
|
+
function registerOpen(program, context) {
|
|
42264
|
+
const { io } = context;
|
|
42265
|
+
act(addVerb(program, "open", "Open a board tab that can edit, through a single-use link to the running server").option("--no-open", "leave the browser alone and print the link"), context, async (_args, options) => {
|
|
42266
|
+
const root = await boardOf(options, io);
|
|
42267
|
+
const live = await findLiveServer(root);
|
|
42268
|
+
if (!live) throw new FrameboardError("server-not-running", `No frameboard server is running for ${root}. Run frameboard serve first.`, { root });
|
|
42269
|
+
const { url: writeUrl, expiresAt } = await postToBoard(live, "/api/access/ticket", {});
|
|
42270
|
+
if (options.open) io.openUrl(writeUrl);
|
|
42271
|
+
return {
|
|
42272
|
+
data: {
|
|
42273
|
+
url: live.url,
|
|
42274
|
+
writeUrl,
|
|
42275
|
+
expiresAt,
|
|
42276
|
+
opened: options.open
|
|
42277
|
+
},
|
|
42278
|
+
human: options.open ? `Opened a board tab that can edit ${live.url}` : `Open ${writeUrl} before ${expiresAt} to edit the board. The link works once.`
|
|
42279
|
+
};
|
|
42280
|
+
});
|
|
42281
|
+
}
|
|
42282
|
+
//#endregion
|
|
42053
42283
|
//#region src/cli/commands/page.ts
|
|
42054
42284
|
const PAGE_REF = "a page ref, <page> or <project>/<page>";
|
|
42055
42285
|
const INDEX = "position in the page order, 0 first, clamped";
|
|
@@ -42231,8 +42461,12 @@ function createTickets(now = Date.now) {
|
|
|
42231
42461
|
mint: () => {
|
|
42232
42462
|
for (const [ticket, expiry] of expiries) if (expiry <= now()) expiries.delete(ticket);
|
|
42233
42463
|
const ticket = randomBytes(16).toString("hex");
|
|
42234
|
-
|
|
42235
|
-
|
|
42464
|
+
const expiry = now() + TICKET_TTL_MS;
|
|
42465
|
+
expiries.set(ticket, expiry);
|
|
42466
|
+
return {
|
|
42467
|
+
ticket,
|
|
42468
|
+
expiresAt: new Date(expiry).toISOString()
|
|
42469
|
+
};
|
|
42236
42470
|
},
|
|
42237
42471
|
redeem: (ticket) => {
|
|
42238
42472
|
const expiry = expiries.get(ticket);
|
|
@@ -42514,7 +42748,7 @@ function createChangeTracker(root, { now = () => /* @__PURE__ */ new Date() } =
|
|
|
42514
42748
|
/** The files and folders a step wrote, being every rewrite, creation, removal, and move. */
|
|
42515
42749
|
function writtenPaths(step) {
|
|
42516
42750
|
return step.changes.flatMap((change) => {
|
|
42517
|
-
if (change.kind === "
|
|
42751
|
+
if (change.kind === "element" || change.kind === "path") return [change.path];
|
|
42518
42752
|
if (change.kind === "moved") return [change.from, change.to];
|
|
42519
42753
|
return [];
|
|
42520
42754
|
});
|
|
@@ -42699,14 +42933,18 @@ async function reads(change, side) {
|
|
|
42699
42933
|
return await exists(present) && !await exists(absent);
|
|
42700
42934
|
}
|
|
42701
42935
|
case "path": return change.present === side ? await exists(change.path) && await hashPath(change.path) === change.hash : !await exists(change.path) && await exists(change.slot);
|
|
42702
|
-
case "
|
|
42936
|
+
case "element": return await exists(change.path) && holdsSpan(await readFile(change.path, "utf8"), change.span, side);
|
|
42703
42937
|
}
|
|
42704
42938
|
}
|
|
42705
42939
|
const OTHER = {
|
|
42706
42940
|
before: "after",
|
|
42707
42941
|
after: "before"
|
|
42708
42942
|
};
|
|
42709
|
-
/**
|
|
42943
|
+
/**
|
|
42944
|
+
* Writes `side` of a change back, under the record's lock, once `holds` read
|
|
42945
|
+
* the other side. A hand edit's change answers the frame's content hash as it
|
|
42946
|
+
* left it, and every other kind answers undefined.
|
|
42947
|
+
*/
|
|
42710
42948
|
async function restore(change, side) {
|
|
42711
42949
|
switch (change.kind) {
|
|
42712
42950
|
case "entry": {
|
|
@@ -42740,22 +42978,41 @@ async function restore(change, side) {
|
|
|
42740
42978
|
if (change.present === side) await rename(change.slot, change.path);
|
|
42741
42979
|
else await takeOut(change.path, change.slot);
|
|
42742
42980
|
return;
|
|
42743
|
-
case "
|
|
42981
|
+
case "element": return swapElement(change, side);
|
|
42744
42982
|
}
|
|
42745
42983
|
}
|
|
42746
42984
|
/**
|
|
42747
|
-
*
|
|
42748
|
-
* reading the file again just before the rename
|
|
42749
|
-
*
|
|
42985
|
+
* Swaps the edited element to `side` through a temporary file and a rename,
|
|
42986
|
+
* reading the file again just before the rename. A write landing before that
|
|
42987
|
+
* read is not overwritten: the swap is made once more from the fresh bytes,
|
|
42988
|
+
* and refused once they change again or no longer hold the element. Bytes
|
|
42989
|
+
* that fail a UTF-8 round trip are refused too, since decoding would rewrite
|
|
42990
|
+
* each invalid byte outside the element. The change keeps the index the
|
|
42991
|
+
* element was found at, so a redo lands on it.
|
|
42750
42992
|
*/
|
|
42751
|
-
async function
|
|
42993
|
+
async function swapElement(change, side) {
|
|
42752
42994
|
const temp = join(dirname(change.path), `.${basename(change.path)}.${process.pid}.tmp`);
|
|
42753
|
-
await
|
|
42754
|
-
|
|
42755
|
-
|
|
42756
|
-
|
|
42995
|
+
let source = await readText(change.path);
|
|
42996
|
+
for (let attempt = 0; source !== void 0 && attempt < 2; attempt += 1) {
|
|
42997
|
+
const swapped = swapSpan(source, change.span, OTHER[side]);
|
|
42998
|
+
if (!swapped) break;
|
|
42999
|
+
await writeFile(temp, swapped.html);
|
|
43000
|
+
const now = await readText(change.path);
|
|
43001
|
+
if (now === source) {
|
|
43002
|
+
await rename(temp, change.path);
|
|
43003
|
+
change.span = swapped.span;
|
|
43004
|
+
return contentHash(swapped.html);
|
|
43005
|
+
}
|
|
43006
|
+
source = now;
|
|
42757
43007
|
}
|
|
42758
|
-
await
|
|
43008
|
+
await rm(temp, { force: true });
|
|
43009
|
+
throw new FrameboardError("undo-overtaken", `An agent changed ${basename(change.path, FRAME_EXTENSION)} after your edit, so that step was dropped.`, { change: change.kind });
|
|
43010
|
+
}
|
|
43011
|
+
/** A frame file's text, or undefined when its bytes do not survive a UTF-8 round trip. */
|
|
43012
|
+
async function readText(path) {
|
|
43013
|
+
const bytes = await readFile(path);
|
|
43014
|
+
const text = bytes.toString("utf8");
|
|
43015
|
+
return Buffer.from(text, "utf8").equals(bytes) ? text : void 0;
|
|
42759
43016
|
}
|
|
42760
43017
|
/**
|
|
42761
43018
|
* The journal one board write reports into, building the changes of one
|
|
@@ -42796,18 +43053,13 @@ var StepJournal = class {
|
|
|
42796
43053
|
to
|
|
42797
43054
|
});
|
|
42798
43055
|
}
|
|
42799
|
-
/**
|
|
42800
|
-
|
|
43056
|
+
/** The element a hand edit rewrote in a frame file, which this journal does not write. */
|
|
43057
|
+
element(path, ref, span) {
|
|
42801
43058
|
this.changes.push({
|
|
42802
|
-
kind: "
|
|
43059
|
+
kind: "element",
|
|
42803
43060
|
path,
|
|
42804
43061
|
ref,
|
|
42805
|
-
|
|
42806
|
-
after,
|
|
42807
|
-
hashes: {
|
|
42808
|
-
before: contentHash(before),
|
|
42809
|
-
after: contentHash(after)
|
|
42810
|
-
}
|
|
43062
|
+
span
|
|
42811
43063
|
});
|
|
42812
43064
|
}
|
|
42813
43065
|
async created(path) {
|
|
@@ -42953,12 +43205,16 @@ var History = class {
|
|
|
42953
43205
|
const step = from.pop();
|
|
42954
43206
|
if (!step) throw empty();
|
|
42955
43207
|
const was = to === "before" ? "after" : "before";
|
|
43208
|
+
const hashes = {};
|
|
42956
43209
|
const locks = step.changes.flatMap(lockPaths).filter((path) => existsSync(dirname(path)));
|
|
42957
43210
|
try {
|
|
42958
43211
|
await withLocks(locks, async () => {
|
|
42959
43212
|
for (const change of step.changes) if (!await holds(change, was)) throw new FrameboardError("undo-overtaken", `An agent changed ${nameOf(change)} after your edit, so that step was dropped.`, { change: change.kind });
|
|
42960
43213
|
const ordered = to === "before" ? [...step.changes].reverse() : step.changes;
|
|
42961
|
-
for (const change of ordered)
|
|
43214
|
+
for (const change of ordered) {
|
|
43215
|
+
const hash = await restore(change, to);
|
|
43216
|
+
if (hash !== void 0 && "ref" in change) hashes[change.ref] = hash;
|
|
43217
|
+
}
|
|
42962
43218
|
});
|
|
42963
43219
|
} catch (error) {
|
|
42964
43220
|
if (!(error instanceof FrameboardError && error.code === "undo-overtaken")) from.push(step);
|
|
@@ -42972,7 +43228,6 @@ var History = class {
|
|
|
42972
43228
|
page: step.page?.[to] ?? null,
|
|
42973
43229
|
frames: step.frames
|
|
42974
43230
|
};
|
|
42975
|
-
const hashes = Object.fromEntries(step.changes.flatMap((change) => change.kind === "content" ? [[change.ref, change.hashes[to]]] : []));
|
|
42976
43231
|
return Object.keys(hashes).length > 0 ? {
|
|
42977
43232
|
...answer,
|
|
42978
43233
|
hashes
|
|
@@ -45253,7 +45508,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45253
45508
|
cookieName: cookieName(root),
|
|
45254
45509
|
isOwnOrigin: (host) => isBoardHost(host, bound)
|
|
45255
45510
|
};
|
|
45256
|
-
const boardUrl = () => `http://${HOSTNAME}:${bound}/api/access/redeem?ticket=${tickets.mint()}`;
|
|
45511
|
+
const boardUrl = () => `http://${HOSTNAME}:${bound}/api/access/redeem?ticket=${tickets.mint().ticket}`;
|
|
45257
45512
|
let scanning = Promise.resolve();
|
|
45258
45513
|
const inTurn = (task) => {
|
|
45259
45514
|
const run = scanning.then(task);
|
|
@@ -45544,7 +45799,7 @@ const DEFAULT_PORT = 4173;
|
|
|
45544
45799
|
/** How long a fresh server waits for a writing board tab left open by its predecessor to reconnect. */
|
|
45545
45800
|
const RECONNECT_WAIT_MS = 1e3;
|
|
45546
45801
|
function registerServe(program, context) {
|
|
45547
|
-
const { io, clientDir
|
|
45802
|
+
const { io, clientDir } = context;
|
|
45548
45803
|
act(addVerb(program, "serve", "Serve the board in a local browser").option("-p, --port <port>", "port to listen on, falling back to a free one when the default is taken", parsePort, DEFAULT_PORT).option("--no-open", "leave the browser alone").option("--tokens <path>", "a token sheet another tool manages, standing in for the board's tokens.css"), context, async (_args, options, self) => {
|
|
45549
45804
|
const tokens = options.tokens === void 0 ? void 0 : resolve(io.cwd, options.tokens);
|
|
45550
45805
|
if (tokens !== void 0 && !isFile(tokens)) throw new FrameboardError("tokens-not-found", `No token sheet at ${tokens}.`, { tokens });
|
|
@@ -45571,7 +45826,7 @@ function registerServe(program, context) {
|
|
|
45571
45826
|
}
|
|
45572
45827
|
const server = await startServer({
|
|
45573
45828
|
clientDir,
|
|
45574
|
-
facesDir,
|
|
45829
|
+
facesDir: context.facesDir,
|
|
45575
45830
|
root,
|
|
45576
45831
|
tokens,
|
|
45577
45832
|
port: options.port,
|
|
@@ -45637,9 +45892,69 @@ function registerShow(program, context) {
|
|
|
45637
45892
|
});
|
|
45638
45893
|
}
|
|
45639
45894
|
//#endregion
|
|
45895
|
+
//#region src/server/look/write-faces.ts
|
|
45896
|
+
const require$1 = createRequire(import.meta.url);
|
|
45897
|
+
/** Whether `dir` holds a sheet for every face. */
|
|
45898
|
+
function hasFaces(dir) {
|
|
45899
|
+
return FACES.every((face) => existsSync(join(dir, face.folder, "index.css")));
|
|
45900
|
+
}
|
|
45901
|
+
/**
|
|
45902
|
+
* Copies each face every frame imports from its package into `outDir`,
|
|
45903
|
+
* replacing what was there. The faces fill a sibling folder first and rename
|
|
45904
|
+
* into place, so `outDir` holds every file or does not exist, and an
|
|
45905
|
+
* interrupted write leaves no half-filled face behind. Each sheet is
|
|
45906
|
+
* rewritten to declare the plain family a frame names, such as Geist, rather
|
|
45907
|
+
* than the package's own, such as Geist Variable. With `keepComplete`, a
|
|
45908
|
+
* folder that filled in meanwhile, as from a parallel run, stays as it is.
|
|
45909
|
+
*/
|
|
45910
|
+
function writeFaces(outDir, { keepComplete = false } = {}) {
|
|
45911
|
+
const staging = `${outDir}.${process.pid}.tmp`;
|
|
45912
|
+
rmSync(staging, {
|
|
45913
|
+
recursive: true,
|
|
45914
|
+
force: true
|
|
45915
|
+
});
|
|
45916
|
+
try {
|
|
45917
|
+
for (const face of FACES) {
|
|
45918
|
+
const from = dirname(require$1.resolve(`${face.package}/package.json`));
|
|
45919
|
+
const to = join(staging, face.folder);
|
|
45920
|
+
mkdirSync(join(to, "files"), { recursive: true });
|
|
45921
|
+
const sheet = readFileSync(join(from, "index.css"), "utf8");
|
|
45922
|
+
writeFileSync(join(to, "index.css"), sheet.replaceAll(`'${face.packageFamily}'`, `'${face.family}'`));
|
|
45923
|
+
copyFileSync(join(from, "LICENSE"), join(to, "LICENSE"));
|
|
45924
|
+
for (const file of readdirSync(join(from, "files"))) if (file.endsWith(".woff2")) copyFileSync(join(from, "files", file), join(to, "files", file));
|
|
45925
|
+
}
|
|
45926
|
+
if (keepComplete && hasFaces(outDir)) return;
|
|
45927
|
+
rmSync(outDir, {
|
|
45928
|
+
recursive: true,
|
|
45929
|
+
force: true
|
|
45930
|
+
});
|
|
45931
|
+
mkdirSync(dirname(outDir), { recursive: true });
|
|
45932
|
+
renameSync(staging, outDir);
|
|
45933
|
+
} finally {
|
|
45934
|
+
rmSync(staging, {
|
|
45935
|
+
recursive: true,
|
|
45936
|
+
force: true
|
|
45937
|
+
});
|
|
45938
|
+
}
|
|
45939
|
+
}
|
|
45940
|
+
//#endregion
|
|
45941
|
+
//#region src/cli/faces-dir.ts
|
|
45942
|
+
/**
|
|
45943
|
+
* The folder the faces are served from. A built run reads the `faces` folder
|
|
45944
|
+
* the build put beside the bundle and never looks further, so a bundle missing
|
|
45945
|
+
* it fails loudly. A source run writes the faces once into the package's
|
|
45946
|
+
* `node_modules/.cache` from the installed packages, and completes a cache
|
|
45947
|
+
* missing any face.
|
|
45948
|
+
*/
|
|
45949
|
+
function resolveFacesDir(moduleUrl = import.meta.url) {
|
|
45950
|
+
if (!moduleUrl.endsWith(".ts")) return fileURLToPath(new URL("./faces", moduleUrl));
|
|
45951
|
+
const cache = fileURLToPath(new URL("../../node_modules/.cache/frameboard/faces", moduleUrl));
|
|
45952
|
+
if (!hasFaces(cache)) writeFaces(cache, { keepComplete: true });
|
|
45953
|
+
return cache;
|
|
45954
|
+
}
|
|
45955
|
+
//#endregion
|
|
45640
45956
|
//#region src/cli/program.ts
|
|
45641
45957
|
const CLIENT_DIR = fileURLToPath(new URL("./client", import.meta.url));
|
|
45642
|
-
const FACES_DIR = fileURLToPath(new URL("./faces", import.meta.url));
|
|
45643
45958
|
function parsePort(value) {
|
|
45644
45959
|
const port = /^\d+$/.test(value) ? Number(value) : NaN;
|
|
45645
45960
|
if (!(port >= 0 && port <= 65535)) throw new InvalidArgumentError("Expected a port between 0 and 65535.");
|
|
@@ -45655,7 +45970,7 @@ function parseInteger(min) {
|
|
|
45655
45970
|
}
|
|
45656
45971
|
/** Adds a verb with `--json` and `--root`, and `--project` when it acts inside a project. */
|
|
45657
45972
|
function addVerb(parent, name, description, { project = false } = {}) {
|
|
45658
|
-
const command = parent.command(name).description(description).option("--json", "print one JSON document on stdout").option("--root <path>", "the board folder, found from the working folder when absent");
|
|
45973
|
+
const command = parent.command(name).description(description).option("--json", "print one JSON document on stdout").option("--root <path>", "the board folder itself, holding board.json, found from the working folder when absent");
|
|
45659
45974
|
if (project) command.option("--project <name>", "the project, defaulting to the board's only one");
|
|
45660
45975
|
return command;
|
|
45661
45976
|
}
|
|
@@ -45686,34 +46001,29 @@ function createProgram(context) {
|
|
|
45686
46001
|
writeOut: io.stdout,
|
|
45687
46002
|
writeErr: (text) => json ? void 0 : io.stderr(text)
|
|
45688
46003
|
});
|
|
45689
|
-
|
|
45690
|
-
|
|
46004
|
+
let facesDir;
|
|
46005
|
+
const faced = {
|
|
45691
46006
|
...context,
|
|
45692
46007
|
clientDir: context.clientDir ?? CLIENT_DIR,
|
|
45693
|
-
facesDir
|
|
45694
|
-
|
|
46008
|
+
get facesDir() {
|
|
46009
|
+
return facesDir ??= context.facesDir ?? resolveFacesDir();
|
|
46010
|
+
}
|
|
46011
|
+
};
|
|
46012
|
+
registerServe(program, faced);
|
|
45695
46013
|
registerShow(program, context);
|
|
46014
|
+
registerOpen(program, context);
|
|
45696
46015
|
registerSelection(program, context);
|
|
45697
46016
|
registerList(program, context);
|
|
45698
46017
|
registerProject(program, context);
|
|
45699
46018
|
registerPage(program, context);
|
|
45700
|
-
registerFrame(program,
|
|
45701
|
-
...context,
|
|
45702
|
-
facesDir
|
|
45703
|
-
});
|
|
46019
|
+
registerFrame(program, faced);
|
|
45704
46020
|
registerEdit(program, context);
|
|
45705
46021
|
registerCheck(program, context);
|
|
45706
46022
|
registerNotes(program, context);
|
|
45707
46023
|
registerInbox(program, context);
|
|
45708
46024
|
registerEditing(program, context);
|
|
45709
|
-
registerCapture(program,
|
|
45710
|
-
|
|
45711
|
-
facesDir
|
|
45712
|
-
});
|
|
45713
|
-
registerInspect(program, {
|
|
45714
|
-
...context,
|
|
45715
|
-
facesDir
|
|
45716
|
-
});
|
|
46025
|
+
registerCapture(program, faced);
|
|
46026
|
+
registerInspect(program, faced);
|
|
45717
46027
|
registerDocs(program, context);
|
|
45718
46028
|
return program;
|
|
45719
46029
|
}
|
|
@@ -45798,6 +46108,10 @@ function missingCommand(group) {
|
|
|
45798
46108
|
//#region src/cli/index.ts
|
|
45799
46109
|
const controller = new AbortController();
|
|
45800
46110
|
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
|
|
46111
|
+
process.stdout.on("error", (error) => {
|
|
46112
|
+
if (error.code === "EPIPE") process.exit(0);
|
|
46113
|
+
throw error;
|
|
46114
|
+
});
|
|
45801
46115
|
process.exitCode = await runCli(process.argv.slice(2), {
|
|
45802
46116
|
stdout: (text) => process.stdout.write(text),
|
|
45803
46117
|
stderr: (text) => process.stderr.write(text),
|