frameboard 0.7.0 → 0.9.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 +11 -7
- package/dist/cli.js +812 -202
- package/dist/client/assets/index-BfkmVXtx.js +110 -0
- package/dist/client/assets/index-DENn9skn.css +2 -0
- package/dist/client/index.html +2 -2
- package/package.json +1 -1
- package/dist/client/assets/index-BCuzf8pa.js +0 -111
- package/dist/client/assets/index-C2o-JeD6.css +0 -2
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";
|
|
@@ -9075,7 +9075,9 @@ const layoutEntrySchema = looseObject({
|
|
|
9075
9075
|
height: int$1().min(1),
|
|
9076
9076
|
order: int$1().min(0),
|
|
9077
9077
|
hidden: boolean$1().optional(),
|
|
9078
|
-
locked: boolean$1().optional()
|
|
9078
|
+
locked: boolean$1().optional(),
|
|
9079
|
+
hugWidth: boolean$1().optional(),
|
|
9080
|
+
hugHeight: boolean$1().optional()
|
|
9079
9081
|
});
|
|
9080
9082
|
const layoutFileSchema = looseObject({
|
|
9081
9083
|
version: literal(1),
|
|
@@ -9177,6 +9179,8 @@ function placeFrames(frames, names) {
|
|
|
9177
9179
|
order: entry.order,
|
|
9178
9180
|
hidden: entry.hidden ?? false,
|
|
9179
9181
|
locked: entry.locked ?? false,
|
|
9182
|
+
hugWidth: entry.hugWidth ?? false,
|
|
9183
|
+
hugHeight: entry.hugHeight ?? false,
|
|
9180
9184
|
placed: true
|
|
9181
9185
|
});
|
|
9182
9186
|
}
|
|
@@ -9205,6 +9209,8 @@ function placeNext(placed) {
|
|
|
9205
9209
|
order,
|
|
9206
9210
|
hidden: false,
|
|
9207
9211
|
locked: false,
|
|
9212
|
+
hugWidth: false,
|
|
9213
|
+
hugHeight: false,
|
|
9208
9214
|
placed: false
|
|
9209
9215
|
};
|
|
9210
9216
|
}
|
|
@@ -9224,9 +9230,9 @@ async function scanProject(root, name) {
|
|
|
9224
9230
|
const { pages: order, createdAt, error } = await readPageOrder(path);
|
|
9225
9231
|
const pages = await Promise.all(order.map((page, index) => scanPage(root, name, page, index)));
|
|
9226
9232
|
const times = await Promise.all([
|
|
9227
|
-
mtimeOf(join(path, PROJECT_FILE)),
|
|
9228
|
-
mtimeOf(path),
|
|
9229
|
-
...pages.flatMap((page) => [mtimeOf(join(page.path, LAYOUT_FILE)), ...page.frames.map((frame) => Date.parse(frame.modifiedAt))])
|
|
9233
|
+
mtimeOf$1(join(path, PROJECT_FILE)),
|
|
9234
|
+
mtimeOf$1(path),
|
|
9235
|
+
...pages.flatMap((page) => [mtimeOf$1(join(page.path, LAYOUT_FILE)), ...page.frames.map((frame) => Date.parse(frame.modifiedAt))])
|
|
9230
9236
|
]);
|
|
9231
9237
|
return {
|
|
9232
9238
|
name,
|
|
@@ -9263,7 +9269,7 @@ async function scanPage(root, project, name, index) {
|
|
|
9263
9269
|
name: frame,
|
|
9264
9270
|
path: framePath,
|
|
9265
9271
|
...placement,
|
|
9266
|
-
modifiedAt: new Date(await mtimeOf(framePath)).toISOString()
|
|
9272
|
+
modifiedAt: new Date(await mtimeOf$1(framePath)).toISOString()
|
|
9267
9273
|
};
|
|
9268
9274
|
}));
|
|
9269
9275
|
return {
|
|
@@ -9279,7 +9285,7 @@ async function scanPage(root, project, name, index) {
|
|
|
9279
9285
|
async function childFolders(dir) {
|
|
9280
9286
|
return (await readdir(dir, { withFileTypes: true })).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name);
|
|
9281
9287
|
}
|
|
9282
|
-
async function mtimeOf(path) {
|
|
9288
|
+
async function mtimeOf$1(path) {
|
|
9283
9289
|
try {
|
|
9284
9290
|
return (await stat$1(path)).mtimeMs;
|
|
9285
9291
|
} catch (error) {
|
|
@@ -9319,13 +9325,12 @@ function findBoard(cwd) {
|
|
|
9319
9325
|
}
|
|
9320
9326
|
/**
|
|
9321
9327
|
* 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
|
|
9328
|
+
* else the board the walk finds, else `.frameboard/` in `cwd`. A board folder holding no project gets one
|
|
9324
9329
|
* project with one empty page, and one missing only `board.json` gets that
|
|
9325
9330
|
* alone.
|
|
9326
9331
|
*/
|
|
9327
9332
|
async function startBoard({ root, cwd }, now = /* @__PURE__ */ new Date()) {
|
|
9328
|
-
const target = root === void 0 ? findBoard(cwd) ?? join(
|
|
9333
|
+
const target = root === void 0 ? findBoard(cwd) ?? join(cwd, ".frameboard") : resolve(cwd, root);
|
|
9329
9334
|
await mkdir(target, { recursive: true });
|
|
9330
9335
|
if (!existsSync(join(target, "board.json"))) await writeRecord(join(target, BOARD_FILE), { version: 1 });
|
|
9331
9336
|
let created = false;
|
|
@@ -9344,12 +9349,6 @@ async function startBoard({ root, cwd }, now = /* @__PURE__ */ new Date()) {
|
|
|
9344
9349
|
created
|
|
9345
9350
|
};
|
|
9346
9351
|
}
|
|
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
9352
|
async function isDirectory(path) {
|
|
9354
9353
|
try {
|
|
9355
9354
|
return (await stat$1(path)).isDirectory();
|
|
@@ -9360,7 +9359,7 @@ async function isDirectory(path) {
|
|
|
9360
9359
|
}
|
|
9361
9360
|
//#endregion
|
|
9362
9361
|
//#region package.json
|
|
9363
|
-
var version$1 = "0.
|
|
9362
|
+
var version$1 = "0.9.0";
|
|
9364
9363
|
var dependencies = { "playwright-core": "1.64.1" };
|
|
9365
9364
|
//#endregion
|
|
9366
9365
|
//#region src/shared/version.ts
|
|
@@ -9608,7 +9607,9 @@ async function framePathParts(root, ref, cwd) {
|
|
|
9608
9607
|
/**
|
|
9609
9608
|
* Places a frame on its page, writing a skeleton file only when none exists.
|
|
9610
9609
|
* A file with no entry keeps its bytes and takes the box `list` showed for it
|
|
9611
|
-
* unless a size or position is given.
|
|
9610
|
+
* unless a size or position is given. Every axis no size names hugs its
|
|
9611
|
+
* content, a preset fixing the width alone, and the box stands in until the
|
|
9612
|
+
* server measures.
|
|
9612
9613
|
*/
|
|
9613
9614
|
async function addFrame(root, ref, options) {
|
|
9614
9615
|
const { journal } = options;
|
|
@@ -9637,7 +9638,8 @@ async function addFrame(root, ref, options) {
|
|
|
9637
9638
|
...size,
|
|
9638
9639
|
x: options.x ?? computed.box.x,
|
|
9639
9640
|
y: options.y ?? computed.box.y
|
|
9640
|
-
}
|
|
9641
|
+
},
|
|
9642
|
+
...hugsOf(options)
|
|
9641
9643
|
});
|
|
9642
9644
|
layout.renumber();
|
|
9643
9645
|
}, journal);
|
|
@@ -9645,9 +9647,11 @@ async function addFrame(root, ref, options) {
|
|
|
9645
9647
|
}
|
|
9646
9648
|
/**
|
|
9647
9649
|
* Copies the frame's file byte for byte, into its own page beside the source
|
|
9648
|
-
* or into `--to` at the source's box, on top of the target page.
|
|
9650
|
+
* or into `--to` at the source's box, on top of the target page. An `offset`
|
|
9651
|
+
* places the copy that far from the source's box instead, as an Alt-drag
|
|
9652
|
+
* drops it.
|
|
9649
9653
|
*/
|
|
9650
|
-
async function duplicateFrame(root, ref, { to, name, journal, ...options }) {
|
|
9654
|
+
async function duplicateFrame(root, ref, { to, name, offset, journal, ...options }) {
|
|
9651
9655
|
const source = await resolveFrameRef(root, ref, options);
|
|
9652
9656
|
const target = to ? await resolvePageRef(root, to, options) : void 0;
|
|
9653
9657
|
const from = pageDir(source);
|
|
@@ -9657,7 +9661,11 @@ async function duplicateFrame(root, ref, { to, name, journal, ...options }) {
|
|
|
9657
9661
|
const targetLayout = layoutAt(layouts, into);
|
|
9658
9662
|
const copyName = freeFrameName(targetLayout.names, source.name, name);
|
|
9659
9663
|
const placement = sourceLayout.placement(source.name);
|
|
9660
|
-
const box =
|
|
9664
|
+
const box = offset ? {
|
|
9665
|
+
...placement.box,
|
|
9666
|
+
x: placement.box.x + offset.x,
|
|
9667
|
+
y: placement.box.y + offset.y
|
|
9668
|
+
} : into === from ? {
|
|
9661
9669
|
...placement.box,
|
|
9662
9670
|
x: placement.box.x + placement.box.width + 80
|
|
9663
9671
|
} : placement.box;
|
|
@@ -9740,10 +9748,55 @@ async function resizeFrame(root, ref, options) {
|
|
|
9740
9748
|
box: {
|
|
9741
9749
|
...placement.box,
|
|
9742
9750
|
...size
|
|
9743
|
-
}
|
|
9751
|
+
},
|
|
9752
|
+
hugWidth: placement.hugWidth && size.width === void 0,
|
|
9753
|
+
hugHeight: placement.hugHeight && size.height === void 0
|
|
9754
|
+
}));
|
|
9755
|
+
}
|
|
9756
|
+
/**
|
|
9757
|
+
* Sets a frame's height to its content's measured height and turns hugging
|
|
9758
|
+
* back on for that axis, the inverse of the resize that fixed it.
|
|
9759
|
+
*/
|
|
9760
|
+
async function fitHeight(root, ref, height, options) {
|
|
9761
|
+
return updatePlacement(root, ref, options, (placement) => ({
|
|
9762
|
+
...placement,
|
|
9763
|
+
box: {
|
|
9764
|
+
...placement.box,
|
|
9765
|
+
height
|
|
9766
|
+
},
|
|
9767
|
+
hugHeight: true
|
|
9744
9768
|
}));
|
|
9745
9769
|
}
|
|
9746
9770
|
/**
|
|
9771
|
+
* Writes the sizes the server measured, on the axes each frame's stored entry
|
|
9772
|
+
* hugs and nowhere else, under the page's lock. It sets no flag and takes no
|
|
9773
|
+
* journal, since the developer never set that size, and answers the names
|
|
9774
|
+
* whose entry changed, none when every size already stands.
|
|
9775
|
+
*/
|
|
9776
|
+
async function setMeasured(root, pageRef, sizes, options) {
|
|
9777
|
+
const page = await resolvePageRef(root, pageRef, options);
|
|
9778
|
+
return withLayouts([page.path], async (layouts) => {
|
|
9779
|
+
const layout = layoutAt(layouts, page.path);
|
|
9780
|
+
const written = [];
|
|
9781
|
+
for (const [name, size] of Object.entries(sizes)) {
|
|
9782
|
+
if (!layout.hasEntry(name) || !layout.names.includes(name)) continue;
|
|
9783
|
+
const placement = layout.placement(name);
|
|
9784
|
+
const box = {
|
|
9785
|
+
...placement.box,
|
|
9786
|
+
width: placement.hugWidth ? size.width : placement.box.width,
|
|
9787
|
+
height: placement.hugHeight ? size.height : placement.box.height
|
|
9788
|
+
};
|
|
9789
|
+
if (sameBox(box, placement.box)) continue;
|
|
9790
|
+
layout.set(name, {
|
|
9791
|
+
...placement,
|
|
9792
|
+
box
|
|
9793
|
+
});
|
|
9794
|
+
written.push(name);
|
|
9795
|
+
}
|
|
9796
|
+
return written;
|
|
9797
|
+
});
|
|
9798
|
+
}
|
|
9799
|
+
/**
|
|
9747
9800
|
* Sets the boxes of several frames on one page under one lock and one write,
|
|
9748
9801
|
* the one path a hand move or resize takes. `expected` holds the boxes the
|
|
9749
9802
|
* client started from, and a frame whose stored box differs from it refuses
|
|
@@ -9760,7 +9813,12 @@ async function setBoxes(root, pageRef, boxes, expected, options) {
|
|
|
9760
9813
|
const placement = layout.placement(name);
|
|
9761
9814
|
if (placement.locked) throw new FrameboardError("frame-locked", `${ref} is locked.`, { ref });
|
|
9762
9815
|
const started = expected[name];
|
|
9763
|
-
|
|
9816
|
+
const box = boxes[name];
|
|
9817
|
+
const kept = box && started ? measuredAxes(placement, box, started) : {};
|
|
9818
|
+
if (!started || !sameBox({
|
|
9819
|
+
...started,
|
|
9820
|
+
...kept
|
|
9821
|
+
}, placement.box)) throw new FrameboardError("stale-layout", `${ref} moved since this edit began, so nothing was written.`, {
|
|
9764
9822
|
ref,
|
|
9765
9823
|
stored: placement.box,
|
|
9766
9824
|
expected: started ?? null
|
|
@@ -9768,16 +9826,37 @@ async function setBoxes(root, pageRef, boxes, expected, options) {
|
|
|
9768
9826
|
return {
|
|
9769
9827
|
name,
|
|
9770
9828
|
placement,
|
|
9771
|
-
box
|
|
9829
|
+
box,
|
|
9830
|
+
kept,
|
|
9831
|
+
started
|
|
9772
9832
|
};
|
|
9773
9833
|
});
|
|
9774
|
-
for (const { name, placement, box } of placements)
|
|
9775
|
-
|
|
9776
|
-
|
|
9777
|
-
|
|
9834
|
+
for (const { name, placement, box, kept, started } of placements) {
|
|
9835
|
+
if (!box || !started) continue;
|
|
9836
|
+
layout.set(name, {
|
|
9837
|
+
...placement,
|
|
9838
|
+
box: {
|
|
9839
|
+
...box,
|
|
9840
|
+
...kept
|
|
9841
|
+
},
|
|
9842
|
+
hugWidth: placement.hugWidth && box.width === started.width,
|
|
9843
|
+
hugHeight: placement.hugHeight && box.height === started.height
|
|
9844
|
+
});
|
|
9845
|
+
}
|
|
9778
9846
|
}, options.journal);
|
|
9779
9847
|
return (await frameRecords(root, page.project, page.name)).filter((frame) => names.includes(frame.name));
|
|
9780
9848
|
}
|
|
9849
|
+
/**
|
|
9850
|
+
* The stored size of each hugging axis a hand write leaves at the size it
|
|
9851
|
+
* started from, since the server may have measured that axis since and a move
|
|
9852
|
+
* never meant to set it.
|
|
9853
|
+
*/
|
|
9854
|
+
function measuredAxes(placement, box, started) {
|
|
9855
|
+
return {
|
|
9856
|
+
...placement.hugWidth && box.width === started.width ? { width: placement.box.width } : {},
|
|
9857
|
+
...placement.hugHeight && box.height === started.height ? { height: placement.box.height } : {}
|
|
9858
|
+
};
|
|
9859
|
+
}
|
|
9781
9860
|
function sameBox(a, b) {
|
|
9782
9861
|
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
9783
9862
|
}
|
|
@@ -9824,6 +9903,13 @@ async function updatePlacement(root, ref, options, change) {
|
|
|
9824
9903
|
}, options.journal);
|
|
9825
9904
|
return frameRecord(root, frame.project, frame.page, frame.name);
|
|
9826
9905
|
}
|
|
9906
|
+
/** Which axes `frame add` leaves hugging: every one no size option names, the height under a preset. */
|
|
9907
|
+
function hugsOf({ size, width, height }) {
|
|
9908
|
+
return {
|
|
9909
|
+
hugWidth: size === void 0 && width === void 0,
|
|
9910
|
+
hugHeight: height === void 0
|
|
9911
|
+
};
|
|
9912
|
+
}
|
|
9827
9913
|
/** The size a verb sets, from a preset or from explicit width and height. */
|
|
9828
9914
|
function sizeOf({ size, width, height }) {
|
|
9829
9915
|
if (size !== void 0 && (width !== void 0 || height !== void 0)) throw new FrameboardError("usage", "Pass --size or --width and --height, not both.", {
|
|
@@ -9881,19 +9967,24 @@ var PageLayout = class {
|
|
|
9881
9967
|
return Math.max(...this.names.map((name) => this.placement(name).order + 1), 0);
|
|
9882
9968
|
}
|
|
9883
9969
|
/**
|
|
9884
|
-
* Writes
|
|
9885
|
-
* the entry already held, so unknown keys survive in place.
|
|
9970
|
+
* Writes the seven fixed keys on the entry it creates or changes, after any
|
|
9971
|
+
* key the entry already held, so unknown keys survive in place. A hug flag
|
|
9972
|
+
* is written on an entry it creates, once it is on, or when the entry holds
|
|
9973
|
+
* it, so a write to an entry from before the flags adds no key.
|
|
9886
9974
|
*/
|
|
9887
|
-
set(name, { box, order, hidden, locked }) {
|
|
9975
|
+
set(name, { box, order, hidden, locked, hugWidth, hugHeight }) {
|
|
9976
|
+
const held = this.file.frames[name];
|
|
9888
9977
|
this.file.frames[name] = {
|
|
9889
|
-
...
|
|
9978
|
+
...held,
|
|
9890
9979
|
x: box.x,
|
|
9891
9980
|
y: box.y,
|
|
9892
9981
|
width: box.width,
|
|
9893
9982
|
height: box.height,
|
|
9894
9983
|
order,
|
|
9895
9984
|
hidden,
|
|
9896
|
-
locked
|
|
9985
|
+
locked,
|
|
9986
|
+
...!held || hugWidth || held.hugWidth !== void 0 ? { hugWidth } : {},
|
|
9987
|
+
...!held || hugHeight || held.hugHeight !== void 0 ? { hugHeight } : {}
|
|
9897
9988
|
};
|
|
9898
9989
|
this.changed = true;
|
|
9899
9990
|
}
|
|
@@ -13449,11 +13540,11 @@ const setCookie = (c, name, value, opt) => {
|
|
|
13449
13540
|
*/
|
|
13450
13541
|
function isWriter(headers, access) {
|
|
13451
13542
|
const bearer = /^Bearer (.+)$/.exec(headers.authorization ?? "")?.[1];
|
|
13452
|
-
if (bearer !== void 0 && matches(bearer, access.token())) return true;
|
|
13543
|
+
if (bearer !== void 0 && matches$1(bearer, access.token())) return true;
|
|
13453
13544
|
const { origin } = headers;
|
|
13454
13545
|
if (origin === void 0 || !isOwnOrigin(origin, access)) return false;
|
|
13455
13546
|
const cookie = readCookie(headers.cookie, access.cookieName);
|
|
13456
|
-
return cookie !== void 0 && matches(cookie, access.key);
|
|
13547
|
+
return cookie !== void 0 && matches$1(cookie, access.key);
|
|
13457
13548
|
}
|
|
13458
13549
|
/** Hono middleware answering 401 in the envelope to anyone who is not a writer. */
|
|
13459
13550
|
function requireWriter(access) {
|
|
@@ -13485,7 +13576,7 @@ function readCookie(header, name) {
|
|
|
13485
13576
|
if (at !== -1 && part.slice(0, at).trim() === name) return part.slice(at + 1).trim();
|
|
13486
13577
|
}
|
|
13487
13578
|
}
|
|
13488
|
-
function matches(given, expected) {
|
|
13579
|
+
function matches$1(given, expected) {
|
|
13489
13580
|
if (expected === null) return false;
|
|
13490
13581
|
const a = Buffer.from(given);
|
|
13491
13582
|
const b = Buffer.from(expected);
|
|
@@ -13497,19 +13588,23 @@ const COOKIE_MAX_AGE_S = 3456e4;
|
|
|
13497
13588
|
/**
|
|
13498
13589
|
* How a tab becomes a writer. A redeem URL carries a single-use ticket that
|
|
13499
13590
|
* 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.
|
|
13591
|
+
* ticket still lands on a board that reads. A failed redeem lands on
|
|
13592
|
+
* `/?link=expired`, the flag the client's expired-link toast reads.
|
|
13501
13593
|
*/
|
|
13502
13594
|
function accessRoutes(access, tickets) {
|
|
13503
13595
|
const app = new Hono();
|
|
13504
13596
|
app.get("/api/access/redeem", (c) => {
|
|
13505
13597
|
const ticket = c.req.query("ticket");
|
|
13506
|
-
if (ticket !== void 0 && tickets.redeem(ticket))
|
|
13507
|
-
|
|
13508
|
-
|
|
13509
|
-
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13598
|
+
if (ticket !== void 0 && tickets.redeem(ticket)) {
|
|
13599
|
+
setCookie(c, access.cookieName, access.key, {
|
|
13600
|
+
httpOnly: true,
|
|
13601
|
+
sameSite: "Strict",
|
|
13602
|
+
path: "/api",
|
|
13603
|
+
maxAge: COOKIE_MAX_AGE_S
|
|
13604
|
+
});
|
|
13605
|
+
return c.redirect("/", 303);
|
|
13606
|
+
}
|
|
13607
|
+
return c.redirect("/?link=expired", 303);
|
|
13513
13608
|
});
|
|
13514
13609
|
app.post("/api/access/ticket", (c) => {
|
|
13515
13610
|
if (!isWriter({ authorization: c.req.header("authorization") }, access)) return c.json({
|
|
@@ -13520,10 +13615,14 @@ function accessRoutes(access, tickets) {
|
|
|
13520
13615
|
}
|
|
13521
13616
|
}, 401);
|
|
13522
13617
|
const url = new URL("/api/access/redeem", c.req.url);
|
|
13523
|
-
|
|
13618
|
+
const { ticket, expiresAt } = tickets.mint();
|
|
13619
|
+
url.searchParams.set("ticket", ticket);
|
|
13524
13620
|
return c.json({
|
|
13525
13621
|
ok: true,
|
|
13526
|
-
data: {
|
|
13622
|
+
data: {
|
|
13623
|
+
url: url.toString(),
|
|
13624
|
+
expiresAt
|
|
13625
|
+
}
|
|
13527
13626
|
});
|
|
13528
13627
|
});
|
|
13529
13628
|
return app;
|
|
@@ -27437,7 +27536,7 @@ function assetsDirOf(source) {
|
|
|
27437
27536
|
return join(source.projectDir, ASSETS_FOLDER);
|
|
27438
27537
|
}
|
|
27439
27538
|
/** Line and column of a span in `text`, both counted from 1. */
|
|
27440
|
-
function locate(text, startOffset, endOffset) {
|
|
27539
|
+
function locate$1(text, startOffset, endOffset) {
|
|
27441
27540
|
let line = 1;
|
|
27442
27541
|
let lineStart = 0;
|
|
27443
27542
|
for (let index = text.indexOf("\n"); index !== -1 && index < startOffset;) {
|
|
@@ -27538,7 +27637,7 @@ function readThemeColors(source) {
|
|
|
27538
27637
|
const end = sheet.offset + (node.source?.end?.offset ?? 0);
|
|
27539
27638
|
firstColor = {
|
|
27540
27639
|
path: boardPath(source.root, sheet.path),
|
|
27541
|
-
location: locate(text, start, end)
|
|
27640
|
+
location: locate$1(text, start, end)
|
|
27542
27641
|
};
|
|
27543
27642
|
}
|
|
27544
27643
|
});
|
|
@@ -28415,13 +28514,107 @@ function removeAttribute(source, element, name) {
|
|
|
28415
28514
|
return splice(source, start, span.endOffset, "");
|
|
28416
28515
|
}
|
|
28417
28516
|
//#endregion
|
|
28517
|
+
//#region src/server/edit/element-span.ts
|
|
28518
|
+
const OTHER$1 = {
|
|
28519
|
+
before: "after",
|
|
28520
|
+
after: "before"
|
|
28521
|
+
};
|
|
28522
|
+
/** The source range a scope covers on a stated element, or undefined for an implied one. */
|
|
28523
|
+
function rangeOf(element, scope) {
|
|
28524
|
+
const location = element.sourceCodeLocation;
|
|
28525
|
+
if (!location?.startTag) return void 0;
|
|
28526
|
+
return scope === "start-tag" ? [location.startTag.startOffset, location.startTag.endOffset] : [location.startOffset, location.endOffset];
|
|
28527
|
+
}
|
|
28528
|
+
/** The bytes of one element a scope covers, as `ElementSpan` records them. */
|
|
28529
|
+
function spanText(source, element, scope) {
|
|
28530
|
+
const range = rangeOf(element, scope);
|
|
28531
|
+
return range ? source.slice(...range) : "";
|
|
28532
|
+
}
|
|
28533
|
+
function matches(source, element, scope, text) {
|
|
28534
|
+
const range = element && rangeOf(element, scope);
|
|
28535
|
+
return range && source.slice(...range) === text ? range : void 0;
|
|
28536
|
+
}
|
|
28537
|
+
/**
|
|
28538
|
+
* The element reading `span[side]`: the one at the recorded index while the
|
|
28539
|
+
* element count is unchanged, else the one element whose bytes match, else
|
|
28540
|
+
* none, since guessing between two would write over the wrong one.
|
|
28541
|
+
*/
|
|
28542
|
+
function locate(source, tree, span, side) {
|
|
28543
|
+
const text = span[side];
|
|
28544
|
+
if (tree.elements.length === span.count) {
|
|
28545
|
+
const range = matches(source, tree.elements[span.index], span.scope, text);
|
|
28546
|
+
return range && {
|
|
28547
|
+
index: span.index,
|
|
28548
|
+
range
|
|
28549
|
+
};
|
|
28550
|
+
}
|
|
28551
|
+
const found = tree.elements.flatMap((element, index) => {
|
|
28552
|
+
const range = matches(source, element, span.scope, text);
|
|
28553
|
+
return range ? [{
|
|
28554
|
+
index,
|
|
28555
|
+
range
|
|
28556
|
+
}] : [];
|
|
28557
|
+
});
|
|
28558
|
+
return found.length === 1 ? found[0] : void 0;
|
|
28559
|
+
}
|
|
28560
|
+
/** Whether the frame still holds the edited element as `side` of the edit left it. */
|
|
28561
|
+
function holdsSpan(source, span, side) {
|
|
28562
|
+
return locate(source, parseFrame(source), span, side) !== void 0;
|
|
28563
|
+
}
|
|
28564
|
+
/**
|
|
28565
|
+
* Finds the element reading `side` of the span and writes the other side in
|
|
28566
|
+
* its place, leaving every other byte as it stands. Answers undefined when the
|
|
28567
|
+
* element is not found, or when the swap would leave it unfound, as a write
|
|
28568
|
+
* the parser reads across element bounds would.
|
|
28569
|
+
*/
|
|
28570
|
+
function swapSpan(source, span, side) {
|
|
28571
|
+
const tree = parseFrame(source);
|
|
28572
|
+
const found = locate(source, tree, span, side);
|
|
28573
|
+
if (!found) return void 0;
|
|
28574
|
+
const [start, end] = found.range;
|
|
28575
|
+
const html = source.slice(0, start) + span[OTHER$1[side]] + source.slice(end);
|
|
28576
|
+
const moved = {
|
|
28577
|
+
...span,
|
|
28578
|
+
index: found.index,
|
|
28579
|
+
count: tree.elements.length
|
|
28580
|
+
};
|
|
28581
|
+
const written = parseFrame(html);
|
|
28582
|
+
if (written.elements.length !== moved.count || !matches(html, written.elements[moved.index], span.scope, span[OTHER$1[side]])) return;
|
|
28583
|
+
return {
|
|
28584
|
+
html,
|
|
28585
|
+
span: moved
|
|
28586
|
+
};
|
|
28587
|
+
}
|
|
28588
|
+
//#endregion
|
|
28418
28589
|
//#region src/server/edit/style.ts
|
|
28419
28590
|
/**
|
|
28420
28591
|
* The longhands a shorthand write drops, so a later longhand in the attribute
|
|
28421
28592
|
* does not keep overriding the value just set. A longhand write leaves its
|
|
28422
28593
|
* shorthand alone, since the longhand comes later and already wins.
|
|
28423
28594
|
*/
|
|
28595
|
+
const BORDER_SIDES = [
|
|
28596
|
+
"top",
|
|
28597
|
+
"right",
|
|
28598
|
+
"bottom",
|
|
28599
|
+
"left"
|
|
28600
|
+
];
|
|
28601
|
+
const BORDER_PARTS = [
|
|
28602
|
+
"color",
|
|
28603
|
+
"style",
|
|
28604
|
+
"width"
|
|
28605
|
+
];
|
|
28424
28606
|
const SHORTHAND_LONGHANDS = {
|
|
28607
|
+
background: [
|
|
28608
|
+
"background-attachment",
|
|
28609
|
+
"background-clip",
|
|
28610
|
+
"background-color",
|
|
28611
|
+
"background-image",
|
|
28612
|
+
"background-origin",
|
|
28613
|
+
"background-position",
|
|
28614
|
+
"background-repeat",
|
|
28615
|
+
"background-size"
|
|
28616
|
+
],
|
|
28617
|
+
border: [...BORDER_PARTS.map((part) => `border-${part}`), ...BORDER_SIDES.flatMap((side) => [`border-${side}`, ...BORDER_PARTS.map((part) => `border-${side}-${part}`)])],
|
|
28425
28618
|
"border-radius": [
|
|
28426
28619
|
"border-top-left-radius",
|
|
28427
28620
|
"border-top-right-radius",
|
|
@@ -28736,7 +28929,19 @@ function applyEdit(source, address, change) {
|
|
|
28736
28929
|
const after = parseFrame(written.html);
|
|
28737
28930
|
const target = after.elements[address.index];
|
|
28738
28931
|
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`);
|
|
28739
|
-
|
|
28932
|
+
const scope = normalized.kind === "text" ? "element" : "start-tag";
|
|
28933
|
+
const span = {
|
|
28934
|
+
scope,
|
|
28935
|
+
index: address.index,
|
|
28936
|
+
count: before.elements.length,
|
|
28937
|
+
before: spanText(source, element, scope),
|
|
28938
|
+
after: spanText(written.html, target, scope)
|
|
28939
|
+
};
|
|
28940
|
+
return {
|
|
28941
|
+
ok: true,
|
|
28942
|
+
html: written.html,
|
|
28943
|
+
span
|
|
28944
|
+
};
|
|
28740
28945
|
}
|
|
28741
28946
|
//#endregion
|
|
28742
28947
|
//#region src/server/edit/frame-file.ts
|
|
@@ -28769,7 +28974,8 @@ function editFrameFile(path, address, change) {
|
|
|
28769
28974
|
renameSync(temp, path);
|
|
28770
28975
|
return {
|
|
28771
28976
|
ok: true,
|
|
28772
|
-
hash: contentHash(applied.html)
|
|
28977
|
+
hash: contentHash(applied.html),
|
|
28978
|
+
span: applied.span
|
|
28773
28979
|
};
|
|
28774
28980
|
}
|
|
28775
28981
|
//#endregion
|
|
@@ -28790,7 +28996,9 @@ const STATUS$3 = {
|
|
|
28790
28996
|
"frame-locked": 423,
|
|
28791
28997
|
"layout-invalid": 422,
|
|
28792
28998
|
"project-file-invalid": 422,
|
|
28793
|
-
"
|
|
28999
|
+
"fit-unbounded": 422,
|
|
29000
|
+
"lock-timeout": 503,
|
|
29001
|
+
"browser-not-found": 503
|
|
28794
29002
|
};
|
|
28795
29003
|
/**
|
|
28796
29004
|
* Answers a refusal in the CLI's `{ ok, error }` envelope, for a route
|
|
@@ -28841,9 +29049,9 @@ const editSchema = object$1({
|
|
|
28841
29049
|
/**
|
|
28842
29050
|
* A hand edit of one element, behind `requireWriter`, its body mirroring
|
|
28843
29051
|
* `edit`'s flags with the hash required, since the board always holds the
|
|
28844
|
-
* one it rendered. It writes through `editFrameFile`, records the
|
|
28845
|
-
*
|
|
28846
|
-
* returns answers 409 with its code, `stale-address` among them.
|
|
29052
|
+
* one it rendered. It writes through `editFrameFile`, records the edited
|
|
29053
|
+
* element's span as one step, and answers the `edit` record. Each refusal
|
|
29054
|
+
* the writer returns answers 409 with its code, `stale-address` among them.
|
|
28847
29055
|
*/
|
|
28848
29056
|
function editRoutes(root, access, history) {
|
|
28849
29057
|
const app = new Hono();
|
|
@@ -28852,7 +29060,6 @@ function editRoutes(root, access, history) {
|
|
|
28852
29060
|
const frame = await resolveFrameRef(root, body.ref, { cwd: root });
|
|
28853
29061
|
const ref = `${frame.project}/${frame.page}/${frame.name}`;
|
|
28854
29062
|
await refuseClaimed(root, [ref], /* @__PURE__ */ new Date());
|
|
28855
|
-
const before = readFileSync(frame.path);
|
|
28856
29063
|
const result = editFrameFile(frame.path, {
|
|
28857
29064
|
index: body.index,
|
|
28858
29065
|
hash: body.hash
|
|
@@ -28868,10 +29075,9 @@ function editRoutes(root, access, history) {
|
|
|
28868
29075
|
}
|
|
28869
29076
|
}
|
|
28870
29077
|
}, 409);
|
|
28871
|
-
|
|
28872
|
-
if (contentHash(after) === result.hash && !after.equals(before)) {
|
|
29078
|
+
if (result.span.before !== result.span.after) {
|
|
28873
29079
|
const journal = history.journal();
|
|
28874
|
-
journal.
|
|
29080
|
+
journal.element(frame.path, ref, result.span);
|
|
28875
29081
|
history.record({
|
|
28876
29082
|
id: journal.id,
|
|
28877
29083
|
changes: journal.changes,
|
|
@@ -35629,6 +35835,14 @@ const frameAddSchema = object$1({
|
|
|
35629
35835
|
y: coordinate.optional()
|
|
35630
35836
|
});
|
|
35631
35837
|
const framesSchema = object$1({ refs });
|
|
35838
|
+
const frameDuplicateSchema = object$1({
|
|
35839
|
+
refs,
|
|
35840
|
+
offset: object$1({
|
|
35841
|
+
x: coordinate,
|
|
35842
|
+
y: coordinate
|
|
35843
|
+
}).optional()
|
|
35844
|
+
});
|
|
35845
|
+
const frameSchema = object$1({ ref });
|
|
35632
35846
|
const pasteSchema = object$1({
|
|
35633
35847
|
ref,
|
|
35634
35848
|
at: object$1({
|
|
@@ -35651,8 +35865,10 @@ const UNTITLED = "untitled";
|
|
|
35651
35865
|
* Each write reports into its own journal and records one step, so the
|
|
35652
35866
|
* developer can undo it, and names the page the board shows on either side
|
|
35653
35867
|
* of it, so an undo can follow a page it brings back or renames.
|
|
35868
|
+
* `measure` reads a frame's content on the warm browser for a fit, which
|
|
35869
|
+
* refuses `browser-not-found` where none is given.
|
|
35654
35870
|
*/
|
|
35655
|
-
function structureRoutes(root, access, history) {
|
|
35871
|
+
function structureRoutes(root, access, history, measure) {
|
|
35656
35872
|
const app = new Hono();
|
|
35657
35873
|
app.use("/api/page/*", requireWriter(access));
|
|
35658
35874
|
app.use("/api/frame/*", requireWriter(access));
|
|
@@ -35810,10 +36026,11 @@ function structureRoutes(root, access, history) {
|
|
|
35810
36026
|
});
|
|
35811
36027
|
});
|
|
35812
36028
|
app.post("/api/frame/duplicate", async (c) => {
|
|
35813
|
-
const body = await parseBody$1(c.req.raw,
|
|
36029
|
+
const body = await parseBody$1(c.req.raw, frameDuplicateSchema);
|
|
35814
36030
|
const copies = await eachFrame(body.refs, (frame, journal) => duplicateFrame(root, frame, {
|
|
35815
36031
|
cwd,
|
|
35816
|
-
journal
|
|
36032
|
+
journal,
|
|
36033
|
+
offset: body.offset
|
|
35817
36034
|
}), (records) => records.map((record) => record.ref));
|
|
35818
36035
|
return c.json({
|
|
35819
36036
|
ok: true,
|
|
@@ -35856,6 +36073,32 @@ function structureRoutes(root, access, history) {
|
|
|
35856
36073
|
data: frames
|
|
35857
36074
|
});
|
|
35858
36075
|
});
|
|
36076
|
+
/**
|
|
36077
|
+
* Sets one frame's height to its content's own and turns its height
|
|
36078
|
+
* hugging on, as `frame fit` does, refusing a frame whose content sizes
|
|
36079
|
+
* itself off the viewport. The width is reported, never changed.
|
|
36080
|
+
*/
|
|
36081
|
+
app.post("/api/frame/fit", async (c) => {
|
|
36082
|
+
const body = await parseBody$1(c.req.raw, frameSchema);
|
|
36083
|
+
await refuseLocked([body.ref]);
|
|
36084
|
+
await refuseHeldFrames([body.ref]);
|
|
36085
|
+
if (!measure) throw new FrameboardError("browser-not-found", "Fit height needs the board server's browser, and none runs here.");
|
|
36086
|
+
const frame = await readFrame$1(root, body.ref, { cwd });
|
|
36087
|
+
const measured = await measure(frame);
|
|
36088
|
+
const fit = await recorded((journal) => fitHeight(root, frame.ref, measured.height, {
|
|
36089
|
+
cwd,
|
|
36090
|
+
journal
|
|
36091
|
+
}), (record) => onFrames([record.ref]));
|
|
36092
|
+
return c.json({
|
|
36093
|
+
ok: true,
|
|
36094
|
+
data: {
|
|
36095
|
+
frame: fit,
|
|
36096
|
+
contentHeight: measured.height,
|
|
36097
|
+
contentWidth: measured.contentWidth,
|
|
36098
|
+
tooWide: measured.contentWidth > fit.box.width
|
|
36099
|
+
}
|
|
36100
|
+
});
|
|
36101
|
+
});
|
|
35859
36102
|
app.post("/api/frame/delete", async (c) => {
|
|
35860
36103
|
const body = await parseBody$1(c.req.raw, framesSchema);
|
|
35861
36104
|
await refuseLocked(body.refs);
|
|
@@ -36026,7 +36269,7 @@ function boardHostGuard(port) {
|
|
|
36026
36269
|
await next();
|
|
36027
36270
|
};
|
|
36028
36271
|
}
|
|
36029
|
-
function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails }) {
|
|
36272
|
+
function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails, measure }) {
|
|
36030
36273
|
const app = new Hono();
|
|
36031
36274
|
const given = tokens ?? null;
|
|
36032
36275
|
app.use("*", async (c, next) => {
|
|
@@ -36045,7 +36288,7 @@ function createApp({ clientDir, root, port, actions, tickets, renderFrame, faces
|
|
|
36045
36288
|
}));
|
|
36046
36289
|
app.route("/", accessRoutes(actions.access, tickets));
|
|
36047
36290
|
app.route("/", apiRoutes(root, actions, frames.look, history));
|
|
36048
|
-
app.route("/", structureRoutes(root, actions.access, history));
|
|
36291
|
+
app.route("/", structureRoutes(root, actions.access, history, measure));
|
|
36049
36292
|
app.route("/", historyRoutes(actions.access, history));
|
|
36050
36293
|
app.route("/", notesRoutes(root, actions.access, delivery));
|
|
36051
36294
|
app.route("/", assetsRoutes(root, actions.access));
|
|
@@ -36519,7 +36762,7 @@ async function writeImages(rendered) {
|
|
|
36519
36762
|
//#endregion
|
|
36520
36763
|
//#region src/cli/commands/capture.ts
|
|
36521
36764
|
function registerCapture(program, context) {
|
|
36522
|
-
const { io
|
|
36765
|
+
const { io } = context;
|
|
36523
36766
|
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([
|
|
36524
36767
|
"light",
|
|
36525
36768
|
"dark",
|
|
@@ -36544,7 +36787,7 @@ function registerCapture(program, context) {
|
|
|
36544
36787
|
const out = await outOf();
|
|
36545
36788
|
const images = await withFrameHost({
|
|
36546
36789
|
root,
|
|
36547
|
-
facesDir
|
|
36790
|
+
facesDir: context.facesDir
|
|
36548
36791
|
}, "capture", (browser, baseUrl) => options.composite ? captureComposite(browser, {
|
|
36549
36792
|
baseUrl,
|
|
36550
36793
|
page: {
|
|
@@ -36570,7 +36813,7 @@ function registerCapture(program, context) {
|
|
|
36570
36813
|
const out = await outOf();
|
|
36571
36814
|
const images = await withFrameHost({
|
|
36572
36815
|
root,
|
|
36573
|
-
facesDir
|
|
36816
|
+
facesDir: context.facesDir
|
|
36574
36817
|
}, "capture", (browser, baseUrl) => captureFrameImages(browser, {
|
|
36575
36818
|
baseUrl,
|
|
36576
36819
|
frames: [frame],
|
|
@@ -36756,7 +36999,7 @@ function sheetLoads(source, sheet) {
|
|
|
36756
36999
|
url,
|
|
36757
37000
|
base: sheetBase(sheet),
|
|
36758
37001
|
path,
|
|
36759
|
-
location: locate(text, sheet.offset + start, sheet.offset + end),
|
|
37002
|
+
location: locate$1(text, sheet.offset + start, sheet.offset + end),
|
|
36760
37003
|
via: kind === "import" ? "@import" : "url()"
|
|
36761
37004
|
}));
|
|
36762
37005
|
}
|
|
@@ -37034,50 +37277,100 @@ function readTextSizes() {
|
|
|
37034
37277
|
}
|
|
37035
37278
|
//#endregion
|
|
37036
37279
|
//#region src/server/capture/fit.ts
|
|
37037
|
-
/**
|
|
37038
|
-
|
|
37039
|
-
|
|
37040
|
-
*
|
|
37041
|
-
*
|
|
37042
|
-
*
|
|
37043
|
-
|
|
37044
|
-
|
|
37045
|
-
|
|
37046
|
-
|
|
37047
|
-
|
|
37048
|
-
|
|
37049
|
-
|
|
37050
|
-
const current = await measure(browser, baseUrl, frame.ref, {
|
|
37051
|
-
width,
|
|
37052
|
-
height
|
|
37053
|
-
});
|
|
37054
|
-
if (short.height !== current.height) throw new FrameboardError("fit-unbounded", `${frame.ref} grows with the viewport, measuring ${short.height} px in a 1 px viewport and ${current.height} px at its ${height} px height, so it has no content height to fit. Size it by hand with frame resize.`, {
|
|
37055
|
-
ref: frame.ref,
|
|
37056
|
-
heights: [short.height, current.height]
|
|
37057
|
-
});
|
|
37058
|
-
return {
|
|
37059
|
-
frame: await resizeFrame(options.root, frame.ref, {
|
|
37060
|
-
...options,
|
|
37061
|
-
height: short.height
|
|
37062
|
-
}),
|
|
37063
|
-
contentHeight: short.height,
|
|
37064
|
-
contentWidth: current.width,
|
|
37065
|
-
tooWide: current.width > width
|
|
37066
|
-
};
|
|
37067
|
-
}
|
|
37068
|
-
async function measure(browser, baseUrl, ref, box) {
|
|
37280
|
+
/** The widest a hugging width grows, past which the layout check reports the content clipped. */
|
|
37281
|
+
const HUG_MAX_WIDTH = FRAME_SIZES.desktop.width;
|
|
37282
|
+
/**
|
|
37283
|
+
* Measures a frame's content the way `frame fit` and the server's hug step
|
|
37284
|
+
* both read it, in one page resized between readings. A hugging width takes
|
|
37285
|
+
* the content's `fit-content` width up to `HUG_MAX_WIDTH`, and the height is
|
|
37286
|
+
* read at that width with a 1 px tall viewport and again at the box's height.
|
|
37287
|
+
* Readings that differ mean the content sizes itself off the viewport, which
|
|
37288
|
+
* has no height of its own to fit, so that refuses `fit-unbounded`. Finite
|
|
37289
|
+
* animations finish before the first reading, so an entrance is read at its
|
|
37290
|
+
* settled size.
|
|
37291
|
+
*/
|
|
37292
|
+
async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
|
|
37069
37293
|
const opened = await openFrame(browser, {
|
|
37070
37294
|
baseUrl,
|
|
37071
37295
|
ref,
|
|
37072
37296
|
box,
|
|
37073
|
-
theme: "light"
|
|
37297
|
+
theme: "light",
|
|
37298
|
+
fonts
|
|
37074
37299
|
});
|
|
37075
37300
|
try {
|
|
37076
|
-
|
|
37301
|
+
const { page } = opened;
|
|
37302
|
+
await page.evaluate(finishAnimations);
|
|
37303
|
+
const empty = await page.evaluate(isBodyEmpty);
|
|
37304
|
+
let width = box.width;
|
|
37305
|
+
if (hugWidth && !empty) {
|
|
37306
|
+
await page.setViewportSize({
|
|
37307
|
+
width: HUG_MAX_WIDTH,
|
|
37308
|
+
height: box.height
|
|
37309
|
+
});
|
|
37310
|
+
width = Math.min(HUG_MAX_WIDTH, await page.evaluate(readFitWidth));
|
|
37311
|
+
}
|
|
37312
|
+
const short = await readAt(page, {
|
|
37313
|
+
width,
|
|
37314
|
+
height: 1
|
|
37315
|
+
});
|
|
37316
|
+
const current = await readAt(page, {
|
|
37317
|
+
width,
|
|
37318
|
+
height: box.height
|
|
37319
|
+
});
|
|
37320
|
+
if (short.height !== current.height) throw new FrameboardError("fit-unbounded", `${ref} grows with the viewport, measuring ${short.height} px in a 1 px viewport and ${current.height} px at its ${box.height} px height, so it has no content height to fit. Size it by hand with frame resize.`, {
|
|
37321
|
+
ref,
|
|
37322
|
+
heights: [short.height, current.height]
|
|
37323
|
+
});
|
|
37324
|
+
return {
|
|
37325
|
+
width,
|
|
37326
|
+
height: short.height,
|
|
37327
|
+
contentWidth: current.width,
|
|
37328
|
+
empty
|
|
37329
|
+
};
|
|
37077
37330
|
} finally {
|
|
37078
37331
|
await opened.close();
|
|
37079
37332
|
}
|
|
37080
37333
|
}
|
|
37334
|
+
/**
|
|
37335
|
+
* Sets a frame's height to its content's own height at its layout width and
|
|
37336
|
+
* turns its height hugging on. The width is reported, never changed.
|
|
37337
|
+
*/
|
|
37338
|
+
async function fitFrame(browser, { baseUrl, frame, ...options }) {
|
|
37339
|
+
const measured = await measureContent(browser, {
|
|
37340
|
+
baseUrl,
|
|
37341
|
+
ref: frame.ref,
|
|
37342
|
+
box: frame.box,
|
|
37343
|
+
hugWidth: false
|
|
37344
|
+
});
|
|
37345
|
+
return {
|
|
37346
|
+
frame: await fitHeight(options.root, frame.ref, measured.height, options),
|
|
37347
|
+
contentHeight: measured.height,
|
|
37348
|
+
contentWidth: measured.contentWidth,
|
|
37349
|
+
tooWide: measured.contentWidth > frame.box.width
|
|
37350
|
+
};
|
|
37351
|
+
}
|
|
37352
|
+
async function readAt(page, viewport) {
|
|
37353
|
+
await page.setViewportSize(viewport);
|
|
37354
|
+
return page.evaluate(readContentSize);
|
|
37355
|
+
}
|
|
37356
|
+
function finishAnimations() {
|
|
37357
|
+
for (const animation of document.getAnimations()) {
|
|
37358
|
+
const end = animation.effect?.getComputedTiming().endTime;
|
|
37359
|
+
if (typeof end === "number" && Number.isFinite(end)) animation.finish();
|
|
37360
|
+
}
|
|
37361
|
+
}
|
|
37362
|
+
function isBodyEmpty() {
|
|
37363
|
+
const body = document.body;
|
|
37364
|
+
return body.children.length === 0 && (body.textContent ?? "").trim() === "";
|
|
37365
|
+
}
|
|
37366
|
+
function readFitWidth() {
|
|
37367
|
+
const root = document.documentElement;
|
|
37368
|
+
const before = root.style.width;
|
|
37369
|
+
root.style.width = "fit-content";
|
|
37370
|
+
const width = Math.ceil(root.getBoundingClientRect().width);
|
|
37371
|
+
root.style.width = before;
|
|
37372
|
+
return Math.max(1, width);
|
|
37373
|
+
}
|
|
37081
37374
|
function readContentSize() {
|
|
37082
37375
|
const root = document.documentElement;
|
|
37083
37376
|
const crops = (element) => {
|
|
@@ -37352,7 +37645,10 @@ function registerCheck(program, context) {
|
|
|
37352
37645
|
findings: [...own.findings, ...browser.findings],
|
|
37353
37646
|
browser: browser.run
|
|
37354
37647
|
};
|
|
37355
|
-
if (result.findings.some((finding) => finding.severity === "error"))
|
|
37648
|
+
if (result.findings.some((finding) => finding.severity === "error")) {
|
|
37649
|
+
if (!options.json) context.io.stdout(`${describe$5(result)}\n`);
|
|
37650
|
+
throw new FrameboardError("check-findings", summarize(result), { ...result });
|
|
37651
|
+
}
|
|
37356
37652
|
return {
|
|
37357
37653
|
data: result,
|
|
37358
37654
|
human: describe$5(result)
|
|
@@ -37364,16 +37660,21 @@ async function run(root, target, options, cwd) {
|
|
|
37364
37660
|
project: options.project,
|
|
37365
37661
|
cwd
|
|
37366
37662
|
};
|
|
37367
|
-
if (target === void 0)
|
|
37368
|
-
const project = await resolveProject(root, options.project);
|
|
37369
|
-
return {
|
|
37370
|
-
result: await checkProject(root, project.name),
|
|
37371
|
-
refs: await projectRefs(root, project.name)
|
|
37372
|
-
};
|
|
37373
|
-
}
|
|
37663
|
+
if (target === void 0) return projectRun(root, (await resolveProject(root, options.project)).name);
|
|
37374
37664
|
const parts = target.split("/");
|
|
37375
37665
|
if (target.endsWith(".html") || parts.length === 3) return frameRun(await resolveFrameRef(root, target, refOptions));
|
|
37376
|
-
if (parts.length === 1)
|
|
37666
|
+
if (parts.length === 1) try {
|
|
37667
|
+
return await pageRun(root, await resolvePageRef(root, target, refOptions));
|
|
37668
|
+
} catch (pageError) {
|
|
37669
|
+
if (options.project !== void 0 || !(pageError instanceof FrameboardError) || !NOT_FRAME.has(pageError.code)) throw pageError;
|
|
37670
|
+
let project;
|
|
37671
|
+
try {
|
|
37672
|
+
project = await resolveProject(root, target);
|
|
37673
|
+
} catch {
|
|
37674
|
+
throw pageError;
|
|
37675
|
+
}
|
|
37676
|
+
return projectRun(root, project.name);
|
|
37677
|
+
}
|
|
37377
37678
|
try {
|
|
37378
37679
|
return frameRun(await resolveFrameRef(root, target, refOptions));
|
|
37379
37680
|
} catch (frameError) {
|
|
@@ -37400,6 +37701,12 @@ async function pageRun(root, { project, page }) {
|
|
|
37400
37701
|
refs: names.map((name) => `${project}/${page}/${name}`)
|
|
37401
37702
|
};
|
|
37402
37703
|
}
|
|
37704
|
+
async function projectRun(root, project) {
|
|
37705
|
+
return {
|
|
37706
|
+
result: await checkProject(root, project),
|
|
37707
|
+
refs: await projectRefs(root, project)
|
|
37708
|
+
};
|
|
37709
|
+
}
|
|
37403
37710
|
async function projectRefs(root, project) {
|
|
37404
37711
|
const refs = [];
|
|
37405
37712
|
for (const page of await listPageFolders(join(root, project))) for (const name of await listFrames(join(root, project, page))) refs.push(`${project}/${page}/${name}`);
|
|
@@ -37430,10 +37737,15 @@ async function browserFindings(root, refs) {
|
|
|
37430
37737
|
return notRunning;
|
|
37431
37738
|
}
|
|
37432
37739
|
}
|
|
37433
|
-
/**
|
|
37434
|
-
function
|
|
37740
|
+
/** The count line alone, such as `Checked 3 frames, 2 findings.` */
|
|
37741
|
+
function summarize({ checked, findings }) {
|
|
37435
37742
|
const frames = `${checked} frame${checked === 1 ? "" : "s"}`;
|
|
37436
|
-
|
|
37743
|
+
return findings.length === 0 ? `Checked ${frames}, no findings.` : `Checked ${frames}, ${findings.length} finding${findings.length === 1 ? "" : "s"}.`;
|
|
37744
|
+
}
|
|
37745
|
+
/** One line per finding, then the count, then why the browser rules did not run. */
|
|
37746
|
+
function describe$5(result) {
|
|
37747
|
+
const { findings, browser } = result;
|
|
37748
|
+
const lines = [...findings.map(formatFinding), summarize(result)];
|
|
37437
37749
|
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.");
|
|
37438
37750
|
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}.`);
|
|
37439
37751
|
return lines.join("\n");
|
|
@@ -37480,6 +37792,9 @@ const frameRecordSchema = object$1({
|
|
|
37480
37792
|
order: number(),
|
|
37481
37793
|
hidden: boolean$1(),
|
|
37482
37794
|
locked: boolean$1(),
|
|
37795
|
+
/** Whether each axis takes its size from the content rather than holding it. */
|
|
37796
|
+
hugWidth: boolean$1(),
|
|
37797
|
+
hugHeight: boolean$1(),
|
|
37483
37798
|
placed: boolean$1(),
|
|
37484
37799
|
modifiedAt: string$1()
|
|
37485
37800
|
});
|
|
@@ -37878,7 +38193,7 @@ function contentFormat() {
|
|
|
37878
38193
|
`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.`,
|
|
37879
38194
|
`A frame is any *${FRAME_EXTENSION} file directly in a page, named by its stem.`,
|
|
37880
38195
|
`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.`,
|
|
37881
|
-
`serve
|
|
38196
|
+
`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}.`,
|
|
37882
38197
|
`Dot-named folders, *${LOCK_SUFFIX} files, and *${TEMP_SUFFIX} files belong to Frameboard and are never content.`
|
|
37883
38198
|
],
|
|
37884
38199
|
names: {
|
|
@@ -37891,7 +38206,9 @@ function contentFormat() {
|
|
|
37891
38206
|
defaultFrameSize: DEFAULT_FRAME_SIZE,
|
|
37892
38207
|
layout: [
|
|
37893
38208
|
"x and y are integers, width and height integers of at least 1, and order an integer of at least 0, where a higher order draws on top.",
|
|
37894
|
-
"hidden and
|
|
38209
|
+
"hidden, locked, hugWidth, and hugHeight read as false when absent, and an axis whose hug flag is false holds the size its entry states.",
|
|
38210
|
+
`An axis that hugs takes its size from the frame's content: a running serve measures it after each write to the frame file, its width at most ${FRAME_SIZES.desktop.width} px, and writes width and height alone, never a flag. Content sized off the viewport keeps the box it has.`,
|
|
38211
|
+
"frame add with no size hugs both axes, --size or --width fixes the width and hugs the height, and --height fixes the height alone, its box standing in until serve measures. frame resize and a hand resize fix each axis they set, and frame fit sets the height and turns hugHeight on.",
|
|
37895
38212
|
"Frames sort by order, then name, and a write that changes order renumbers the page from 0.",
|
|
37896
38213
|
`A frame file with no entry is unplaced: it reads at desktop size, y 0, 80 px past the right edge of every frame placed before it in name order, and frame add persists that box.`,
|
|
37897
38214
|
"An entry with no frame file beside it is ignored on read and kept on write.",
|
|
@@ -37909,20 +38226,69 @@ function contentFormat() {
|
|
|
37909
38226
|
};
|
|
37910
38227
|
}
|
|
37911
38228
|
//#endregion
|
|
38229
|
+
//#region src/cli/docs/text.ts
|
|
38230
|
+
const INDENT = " ";
|
|
38231
|
+
/**
|
|
38232
|
+
* The human form of `docs`: one heading per section the JSON carries, with
|
|
38233
|
+
* the record schemas named rather than printed, since `--json` holds them whole.
|
|
38234
|
+
*/
|
|
38235
|
+
function renderDocs(docs) {
|
|
38236
|
+
return [
|
|
38237
|
+
`frameboard ${docs.version}`,
|
|
38238
|
+
section("Verbs", docs.verbs.flatMap(verbLines)),
|
|
38239
|
+
section("Exit codes", table(Object.entries(docs.exitCodes))),
|
|
38240
|
+
section("Records", [`${INDENT}${Object.keys(docs.records).join(", ")}`, `${INDENT}Run frameboard docs --json for each record's JSON schema.`]),
|
|
38241
|
+
section("Content format", formatLines(docs.contentFormat)),
|
|
38242
|
+
section("Check rules", docs.checks.rules.map((rule) => `${INDENT}${rule.id} ${rule.tier}${rule.configKey ? `, on with checks.${rule.configKey}` : ""}. ${rule.description}`))
|
|
38243
|
+
].join("\n\n");
|
|
38244
|
+
}
|
|
38245
|
+
function section(heading, lines) {
|
|
38246
|
+
return [heading, ...lines].join("\n");
|
|
38247
|
+
}
|
|
38248
|
+
function verbLines(verb) {
|
|
38249
|
+
const usage = verb.arguments.map((argument) => argument.required ? `<${argument.name}>` : `[${argument.name}]`).join(" ");
|
|
38250
|
+
return [`frameboard ${verb.name}${usage ? ` ${usage}` : ""} ${verb.description}`, ...verb.options.map((option) => {
|
|
38251
|
+
const extras = [option.choices ? `one of ${option.choices.join(", ")}` : "", option.default === void 0 ? "" : `default ${JSON.stringify(option.default)}`].filter(Boolean);
|
|
38252
|
+
return `${INDENT}${option.flags} ${option.description}${extras.length ? ` (${extras.join(", ")})` : ""}`;
|
|
38253
|
+
})];
|
|
38254
|
+
}
|
|
38255
|
+
function table(rows) {
|
|
38256
|
+
const width = Math.max(...rows.map(([name]) => name.length));
|
|
38257
|
+
return rows.map(([name, value]) => `${INDENT}${name.padEnd(width)} ${value}`);
|
|
38258
|
+
}
|
|
38259
|
+
function formatLines(format) {
|
|
38260
|
+
const sizes = Object.entries(format.frameSizes).map(([name, size]) => `${name} ${size.width} × ${size.height}`);
|
|
38261
|
+
return [
|
|
38262
|
+
"Folders",
|
|
38263
|
+
...format.folders.map((line) => `${INDENT}${line}`),
|
|
38264
|
+
"Names",
|
|
38265
|
+
`${INDENT}Match ${format.names.pattern}, at most ${format.names.maxLength} characters. Reserved page names: ${format.names.reservedPageNames.join(", ")}.`,
|
|
38266
|
+
`${INDENT}${format.names.collision}`,
|
|
38267
|
+
"Frame sizes",
|
|
38268
|
+
`${INDENT}${sizes.join(", ")}, defaulting to ${format.defaultFrameSize}`,
|
|
38269
|
+
"Layout",
|
|
38270
|
+
...format.layout.map((line) => `${INDENT}${line}`),
|
|
38271
|
+
"Assets",
|
|
38272
|
+
`${INDENT}${format.assets}`,
|
|
38273
|
+
"Look",
|
|
38274
|
+
...format.look.map((line) => `${INDENT}${line}`)
|
|
38275
|
+
];
|
|
38276
|
+
}
|
|
38277
|
+
//#endregion
|
|
37912
38278
|
//#region src/cli/commands/docs.ts
|
|
37913
38279
|
function registerDocs(program, context) {
|
|
37914
38280
|
act(addVerb(program, "docs", "Print the verbs, exit codes, record shapes, content format, and check rules"), context, async () => {
|
|
37915
|
-
const
|
|
38281
|
+
const data = {
|
|
38282
|
+
version,
|
|
38283
|
+
verbs: describeVerbs(program),
|
|
38284
|
+
exitCodes: EXIT_CODES,
|
|
38285
|
+
records: Object.fromEntries(Object.entries(RECORDS).map(([name, schema]) => [name, toJSONSchema(schema, { io: "input" })])),
|
|
38286
|
+
contentFormat: contentFormat(),
|
|
38287
|
+
checks: { rules: RULES }
|
|
38288
|
+
};
|
|
37916
38289
|
return {
|
|
37917
|
-
data
|
|
37918
|
-
|
|
37919
|
-
verbs,
|
|
37920
|
-
exitCodes: EXIT_CODES,
|
|
37921
|
-
records: Object.fromEntries(Object.entries(RECORDS).map(([name, schema]) => [name, toJSONSchema(schema, { io: "input" })])),
|
|
37922
|
-
contentFormat: contentFormat(),
|
|
37923
|
-
checks: { rules: RULES }
|
|
37924
|
-
},
|
|
37925
|
-
human: verbs.map((verb) => `frameboard ${verb.name} ${verb.description}`).join("\n")
|
|
38290
|
+
data,
|
|
38291
|
+
human: renderDocs(data)
|
|
37926
38292
|
};
|
|
37927
38293
|
});
|
|
37928
38294
|
}
|
|
@@ -38094,7 +38460,7 @@ function describe$4(claims, now) {
|
|
|
38094
38460
|
const FRAME_REF = "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file";
|
|
38095
38461
|
const ANY_INTEGER = parseInteger(Number.MIN_SAFE_INTEGER);
|
|
38096
38462
|
function registerFrame(program, context) {
|
|
38097
|
-
const { io
|
|
38463
|
+
const { io } = context;
|
|
38098
38464
|
const frame = program.command("frame").description("Manage frames");
|
|
38099
38465
|
const verb = (name, description) => addVerb(frame, name, description, { project: true }).argument("<frame-ref>", FRAME_REF);
|
|
38100
38466
|
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));
|
|
@@ -38103,7 +38469,7 @@ function registerFrame(program, context) {
|
|
|
38103
38469
|
data: record,
|
|
38104
38470
|
human: `${what} ${record.ref}`
|
|
38105
38471
|
});
|
|
38106
|
-
act(withPosition(withSize(verb("add", "Place a frame, writing a skeleton file when none exists.
|
|
38472
|
+
act(withPosition(withSize(verb("add", "Place a frame past every frame, writing a skeleton file when none exists. Each axis no size names hugs its content, so a preset or --width fixes the width and the height hugs."))), context, async ([ref = ""], options) => done(await addFrame(await boardOf(options, io), ref, {
|
|
38107
38473
|
...options,
|
|
38108
38474
|
cwd: io.cwd
|
|
38109
38475
|
}), "Added"));
|
|
@@ -38115,11 +38481,11 @@ function registerFrame(program, context) {
|
|
|
38115
38481
|
...options,
|
|
38116
38482
|
cwd: io.cwd
|
|
38117
38483
|
}), "Moved to"));
|
|
38118
|
-
act(withSize(verb("resize", "Set a frame size")), context, async ([ref = ""], options) => done(await resizeFrame(await boardOf(options, io), ref, {
|
|
38484
|
+
act(withSize(verb("resize", "Set a frame size, fixing each axis it sets")), context, async ([ref = ""], options) => done(await resizeFrame(await boardOf(options, io), ref, {
|
|
38119
38485
|
...options,
|
|
38120
38486
|
cwd: io.cwd
|
|
38121
38487
|
}), "Resized"));
|
|
38122
|
-
act(verb("fit", "Set a frame height to its content's own height, reporting a width too wide for the frame"), context, async ([ref = ""], options) => {
|
|
38488
|
+
act(verb("fit", "Set a frame height to its content's own height and hug it from then on, reporting a width too wide for the frame"), context, async ([ref = ""], options) => {
|
|
38123
38489
|
const root = await boardOf(options, io);
|
|
38124
38490
|
const refOptions = {
|
|
38125
38491
|
project: options.project,
|
|
@@ -38128,7 +38494,7 @@ function registerFrame(program, context) {
|
|
|
38128
38494
|
const frame = await readFrame$1(root, ref, refOptions);
|
|
38129
38495
|
const result = await withFrameHost({
|
|
38130
38496
|
root,
|
|
38131
|
-
facesDir
|
|
38497
|
+
facesDir: context.facesDir
|
|
38132
38498
|
}, "frame fit", (browser, baseUrl) => fitFrame(browser, {
|
|
38133
38499
|
...refOptions,
|
|
38134
38500
|
root,
|
|
@@ -41953,7 +42319,7 @@ function readLiveElements() {
|
|
|
41953
42319
|
//#endregion
|
|
41954
42320
|
//#region src/cli/commands/inspect.ts
|
|
41955
42321
|
function registerInspect(program, context) {
|
|
41956
|
-
const { io
|
|
42322
|
+
const { io } = context;
|
|
41957
42323
|
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) => {
|
|
41958
42324
|
const root = await boardOf(options, io);
|
|
41959
42325
|
const frame = await readFrame$1(root, ref, {
|
|
@@ -41962,7 +42328,7 @@ function registerInspect(program, context) {
|
|
|
41962
42328
|
});
|
|
41963
42329
|
const data = await withFrameHost({
|
|
41964
42330
|
root,
|
|
41965
|
-
facesDir
|
|
42331
|
+
facesDir: context.facesDir
|
|
41966
42332
|
}, "inspect", (browser, baseUrl) => inspectFrame(browser, {
|
|
41967
42333
|
baseUrl,
|
|
41968
42334
|
frame,
|
|
@@ -42040,8 +42406,8 @@ function registerNotes(program, context) {
|
|
|
42040
42406
|
human: describe$1(listed)
|
|
42041
42407
|
};
|
|
42042
42408
|
});
|
|
42043
|
-
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) => {
|
|
42044
|
-
const found = await
|
|
42409
|
+
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) => {
|
|
42410
|
+
const found = await noteIn(await boardOf(options, io), id, options.project);
|
|
42045
42411
|
const replyId = newNoteId();
|
|
42046
42412
|
const reply = (await updateNotes(found.path, (current) => addReply(current, id, {
|
|
42047
42413
|
text,
|
|
@@ -42057,8 +42423,8 @@ function registerNotes(program, context) {
|
|
|
42057
42423
|
human: `Replied to ${reply?.thread ?? id} on ${found.project}/${found.page}/${found.note.frame}`
|
|
42058
42424
|
};
|
|
42059
42425
|
});
|
|
42060
|
-
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) => {
|
|
42061
|
-
const found = await
|
|
42426
|
+
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) => {
|
|
42427
|
+
const found = await noteIn(await boardOf(options, io), id, options.project);
|
|
42062
42428
|
const file = await updateNotes(found.path, (current) => setState(current, id, "done", /* @__PURE__ */ new Date()));
|
|
42063
42429
|
const rootId = found.note.thread ?? found.note.id;
|
|
42064
42430
|
return {
|
|
@@ -42067,6 +42433,16 @@ function registerNotes(program, context) {
|
|
|
42067
42433
|
};
|
|
42068
42434
|
});
|
|
42069
42435
|
}
|
|
42436
|
+
/** The note an id names, refused as missing when `--project` names another project than the one holding it. */
|
|
42437
|
+
async function noteIn(root, id, project) {
|
|
42438
|
+
const scope = project === void 0 ? void 0 : await resolveProject(root, project);
|
|
42439
|
+
const found = await findNote(root, id);
|
|
42440
|
+
if (scope && found.project !== scope.name) throw new FrameboardError("note-not-found", `No note ${id} in project ${scope.name}. It sits in ${found.project}.`, {
|
|
42441
|
+
id,
|
|
42442
|
+
project: scope.name
|
|
42443
|
+
});
|
|
42444
|
+
return found;
|
|
42445
|
+
}
|
|
42070
42446
|
/** The pages a listing reads: the one `--page` or `--frame` names, else every page in scope. */
|
|
42071
42447
|
async function pagesIn(root, options, frame, cwd) {
|
|
42072
42448
|
const page = frame ?? (options.page ? await resolvePageRef(root, options.page, {
|
|
@@ -42097,6 +42473,27 @@ function describe$1(notes) {
|
|
|
42097
42473
|
}).join("\n");
|
|
42098
42474
|
}
|
|
42099
42475
|
//#endregion
|
|
42476
|
+
//#region src/cli/commands/open.ts
|
|
42477
|
+
function registerOpen(program, context) {
|
|
42478
|
+
const { io } = context;
|
|
42479
|
+
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) => {
|
|
42480
|
+
const root = await boardOf(options, io);
|
|
42481
|
+
const live = await findLiveServer(root);
|
|
42482
|
+
if (!live) throw new FrameboardError("server-not-running", `No frameboard server is running for ${root}. Run frameboard serve first.`, { root });
|
|
42483
|
+
const { url: writeUrl, expiresAt } = await postToBoard(live, "/api/access/ticket", {});
|
|
42484
|
+
if (options.open) io.openUrl(writeUrl);
|
|
42485
|
+
return {
|
|
42486
|
+
data: {
|
|
42487
|
+
url: live.url,
|
|
42488
|
+
writeUrl,
|
|
42489
|
+
expiresAt,
|
|
42490
|
+
opened: options.open
|
|
42491
|
+
},
|
|
42492
|
+
human: options.open ? `Opened a board tab that can edit ${live.url}` : `Open ${writeUrl} before ${expiresAt} to edit the board. The link works once.`
|
|
42493
|
+
};
|
|
42494
|
+
});
|
|
42495
|
+
}
|
|
42496
|
+
//#endregion
|
|
42100
42497
|
//#region src/cli/commands/page.ts
|
|
42101
42498
|
const PAGE_REF = "a page ref, <page> or <project>/<page>";
|
|
42102
42499
|
const INDEX = "position in the page order, 0 first, clamped";
|
|
@@ -42278,8 +42675,12 @@ function createTickets(now = Date.now) {
|
|
|
42278
42675
|
mint: () => {
|
|
42279
42676
|
for (const [ticket, expiry] of expiries) if (expiry <= now()) expiries.delete(ticket);
|
|
42280
42677
|
const ticket = randomBytes(16).toString("hex");
|
|
42281
|
-
|
|
42282
|
-
|
|
42678
|
+
const expiry = now() + TICKET_TTL_MS;
|
|
42679
|
+
expiries.set(ticket, expiry);
|
|
42680
|
+
return {
|
|
42681
|
+
ticket,
|
|
42682
|
+
expiresAt: new Date(expiry).toISOString()
|
|
42683
|
+
};
|
|
42283
42684
|
},
|
|
42284
42685
|
redeem: (ticket) => {
|
|
42285
42686
|
const expiry = expiries.get(ticket);
|
|
@@ -42561,7 +42962,7 @@ function createChangeTracker(root, { now = () => /* @__PURE__ */ new Date() } =
|
|
|
42561
42962
|
/** The files and folders a step wrote, being every rewrite, creation, removal, and move. */
|
|
42562
42963
|
function writtenPaths(step) {
|
|
42563
42964
|
return step.changes.flatMap((change) => {
|
|
42564
|
-
if (change.kind === "
|
|
42965
|
+
if (change.kind === "element" || change.kind === "path") return [change.path];
|
|
42565
42966
|
if (change.kind === "moved") return [change.from, change.to];
|
|
42566
42967
|
return [];
|
|
42567
42968
|
});
|
|
@@ -42731,8 +43132,8 @@ const UNREADABLE = /* @__PURE__ */ new Set(["layout-invalid", "project-file-inva
|
|
|
42731
43132
|
async function reads(change, side) {
|
|
42732
43133
|
switch (change.kind) {
|
|
42733
43134
|
case "entry": {
|
|
42734
|
-
const
|
|
42735
|
-
return isDeepStrictEqual(
|
|
43135
|
+
const stored = (await readRecord(change.layout, layoutSpec)).frames[change.frame];
|
|
43136
|
+
return isDeepStrictEqual(stored, withMeasured(change[side], stored));
|
|
42736
43137
|
}
|
|
42737
43138
|
case "pages": {
|
|
42738
43139
|
const file = await readRecord(change.file, {
|
|
@@ -42746,20 +43147,38 @@ async function reads(change, side) {
|
|
|
42746
43147
|
return await exists(present) && !await exists(absent);
|
|
42747
43148
|
}
|
|
42748
43149
|
case "path": return change.present === side ? await exists(change.path) && await hashPath(change.path) === change.hash : !await exists(change.path) && await exists(change.slot);
|
|
42749
|
-
case "
|
|
43150
|
+
case "element": return await exists(change.path) && holdsSpan(await readFile(change.path, "utf8"), change.span, side);
|
|
42750
43151
|
}
|
|
42751
43152
|
}
|
|
43153
|
+
/**
|
|
43154
|
+
* The entry a step holds, taking the stored size on each axis both it and the
|
|
43155
|
+
* stored entry hug, since the server measures that size and the developer
|
|
43156
|
+
* never set it, so a measure after a hand move neither overtakes the step nor
|
|
43157
|
+
* is reverted by it.
|
|
43158
|
+
*/
|
|
43159
|
+
function withMeasured(entry, stored) {
|
|
43160
|
+
if (!entry || !stored) return entry;
|
|
43161
|
+
return {
|
|
43162
|
+
...entry,
|
|
43163
|
+
...entry.hugWidth && stored.hugWidth ? { width: stored.width } : {},
|
|
43164
|
+
...entry.hugHeight && stored.hugHeight ? { height: stored.height } : {}
|
|
43165
|
+
};
|
|
43166
|
+
}
|
|
42752
43167
|
const OTHER = {
|
|
42753
43168
|
before: "after",
|
|
42754
43169
|
after: "before"
|
|
42755
43170
|
};
|
|
42756
|
-
/**
|
|
43171
|
+
/**
|
|
43172
|
+
* Writes `side` of a change back, under the record's lock, once `holds` read
|
|
43173
|
+
* the other side. A hand edit's change answers the frame's content hash as it
|
|
43174
|
+
* left it, and every other kind answers undefined.
|
|
43175
|
+
*/
|
|
42757
43176
|
async function restore(change, side) {
|
|
42758
43177
|
switch (change.kind) {
|
|
42759
43178
|
case "entry": {
|
|
42760
43179
|
const file = await readRecord(change.layout, layoutSpec);
|
|
42761
43180
|
const frames = { ...file.frames };
|
|
42762
|
-
const entry = change[side];
|
|
43181
|
+
const entry = withMeasured(change[side], frames[change.frame]);
|
|
42763
43182
|
if (entry) frames[change.frame] = entry;
|
|
42764
43183
|
else delete frames[change.frame];
|
|
42765
43184
|
await writeRecord(change.layout, {
|
|
@@ -42787,22 +43206,41 @@ async function restore(change, side) {
|
|
|
42787
43206
|
if (change.present === side) await rename(change.slot, change.path);
|
|
42788
43207
|
else await takeOut(change.path, change.slot);
|
|
42789
43208
|
return;
|
|
42790
|
-
case "
|
|
43209
|
+
case "element": return swapElement(change, side);
|
|
42791
43210
|
}
|
|
42792
43211
|
}
|
|
42793
43212
|
/**
|
|
42794
|
-
*
|
|
42795
|
-
* reading the file again just before the rename
|
|
42796
|
-
*
|
|
43213
|
+
* Swaps the edited element to `side` through a temporary file and a rename,
|
|
43214
|
+
* reading the file again just before the rename. A write landing before that
|
|
43215
|
+
* read is not overwritten: the swap is made once more from the fresh bytes,
|
|
43216
|
+
* and refused once they change again or no longer hold the element. Bytes
|
|
43217
|
+
* that fail a UTF-8 round trip are refused too, since decoding would rewrite
|
|
43218
|
+
* each invalid byte outside the element. The change keeps the index the
|
|
43219
|
+
* element was found at, so a redo lands on it.
|
|
42797
43220
|
*/
|
|
42798
|
-
async function
|
|
43221
|
+
async function swapElement(change, side) {
|
|
42799
43222
|
const temp = join(dirname(change.path), `.${basename(change.path)}.${process.pid}.tmp`);
|
|
42800
|
-
await
|
|
42801
|
-
|
|
42802
|
-
|
|
42803
|
-
|
|
43223
|
+
let source = await readText(change.path);
|
|
43224
|
+
for (let attempt = 0; source !== void 0 && attempt < 2; attempt += 1) {
|
|
43225
|
+
const swapped = swapSpan(source, change.span, OTHER[side]);
|
|
43226
|
+
if (!swapped) break;
|
|
43227
|
+
await writeFile(temp, swapped.html);
|
|
43228
|
+
const now = await readText(change.path);
|
|
43229
|
+
if (now === source) {
|
|
43230
|
+
await rename(temp, change.path);
|
|
43231
|
+
change.span = swapped.span;
|
|
43232
|
+
return contentHash(swapped.html);
|
|
43233
|
+
}
|
|
43234
|
+
source = now;
|
|
42804
43235
|
}
|
|
42805
|
-
await
|
|
43236
|
+
await rm(temp, { force: true });
|
|
43237
|
+
throw new FrameboardError("undo-overtaken", `An agent changed ${basename(change.path, FRAME_EXTENSION)} after your edit, so that step was dropped.`, { change: change.kind });
|
|
43238
|
+
}
|
|
43239
|
+
/** A frame file's text, or undefined when its bytes do not survive a UTF-8 round trip. */
|
|
43240
|
+
async function readText(path) {
|
|
43241
|
+
const bytes = await readFile(path);
|
|
43242
|
+
const text = bytes.toString("utf8");
|
|
43243
|
+
return Buffer.from(text, "utf8").equals(bytes) ? text : void 0;
|
|
42806
43244
|
}
|
|
42807
43245
|
/**
|
|
42808
43246
|
* The journal one board write reports into, building the changes of one
|
|
@@ -42843,18 +43281,13 @@ var StepJournal = class {
|
|
|
42843
43281
|
to
|
|
42844
43282
|
});
|
|
42845
43283
|
}
|
|
42846
|
-
/**
|
|
42847
|
-
|
|
43284
|
+
/** The element a hand edit rewrote in a frame file, which this journal does not write. */
|
|
43285
|
+
element(path, ref, span) {
|
|
42848
43286
|
this.changes.push({
|
|
42849
|
-
kind: "
|
|
43287
|
+
kind: "element",
|
|
42850
43288
|
path,
|
|
42851
43289
|
ref,
|
|
42852
|
-
|
|
42853
|
-
after,
|
|
42854
|
-
hashes: {
|
|
42855
|
-
before: contentHash(before),
|
|
42856
|
-
after: contentHash(after)
|
|
42857
|
-
}
|
|
43290
|
+
span
|
|
42858
43291
|
});
|
|
42859
43292
|
}
|
|
42860
43293
|
async created(path) {
|
|
@@ -43000,12 +43433,16 @@ var History = class {
|
|
|
43000
43433
|
const step = from.pop();
|
|
43001
43434
|
if (!step) throw empty();
|
|
43002
43435
|
const was = to === "before" ? "after" : "before";
|
|
43436
|
+
const hashes = {};
|
|
43003
43437
|
const locks = step.changes.flatMap(lockPaths).filter((path) => existsSync(dirname(path)));
|
|
43004
43438
|
try {
|
|
43005
43439
|
await withLocks(locks, async () => {
|
|
43006
43440
|
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 });
|
|
43007
43441
|
const ordered = to === "before" ? [...step.changes].reverse() : step.changes;
|
|
43008
|
-
for (const change of ordered)
|
|
43442
|
+
for (const change of ordered) {
|
|
43443
|
+
const hash = await restore(change, to);
|
|
43444
|
+
if (hash !== void 0 && "ref" in change) hashes[change.ref] = hash;
|
|
43445
|
+
}
|
|
43009
43446
|
});
|
|
43010
43447
|
} catch (error) {
|
|
43011
43448
|
if (!(error instanceof FrameboardError && error.code === "undo-overtaken")) from.push(step);
|
|
@@ -43019,7 +43456,6 @@ var History = class {
|
|
|
43019
43456
|
page: step.page?.[to] ?? null,
|
|
43020
43457
|
frames: step.frames
|
|
43021
43458
|
};
|
|
43022
|
-
const hashes = Object.fromEntries(step.changes.flatMap((change) => change.kind === "content" ? [[change.ref, change.hashes[to]]] : []));
|
|
43023
43459
|
return Object.keys(hashes).length > 0 ? {
|
|
43024
43460
|
...answer,
|
|
43025
43461
|
hashes
|
|
@@ -45021,6 +45457,90 @@ function send(socket, message) {
|
|
|
45021
45457
|
if (socket.readyState === socket.OPEN) socket.send(JSON.stringify(message));
|
|
45022
45458
|
}
|
|
45023
45459
|
//#endregion
|
|
45460
|
+
//#region src/server/live/hug.ts
|
|
45461
|
+
/**
|
|
45462
|
+
* The server's hug step. A frame hugs when either flag is on, and its sizes
|
|
45463
|
+
* are written through `setMeasured`, which takes the page's lock, writes
|
|
45464
|
+
* only the axes the stored entry still hugs, and records no undo step. A
|
|
45465
|
+
* frame whose content sizes itself off the viewport, whose body is empty,
|
|
45466
|
+
* or that fails to load keeps its box, and a browser that cannot launch
|
|
45467
|
+
* writes nothing at all.
|
|
45468
|
+
*/
|
|
45469
|
+
function createHug({ root, measure }) {
|
|
45470
|
+
let queue = Promise.resolve();
|
|
45471
|
+
let closed = false;
|
|
45472
|
+
const run = async (board, refs) => {
|
|
45473
|
+
const pages = /* @__PURE__ */ new Map();
|
|
45474
|
+
for (const frame of huggingFrames(board, refs)) {
|
|
45475
|
+
if (closed) return false;
|
|
45476
|
+
let size;
|
|
45477
|
+
try {
|
|
45478
|
+
size = await measure(frame);
|
|
45479
|
+
} catch (error) {
|
|
45480
|
+
if (error instanceof FrameboardError && error.code === "browser-not-found") break;
|
|
45481
|
+
continue;
|
|
45482
|
+
}
|
|
45483
|
+
if (size.empty) continue;
|
|
45484
|
+
const page = `${frame.project}/${frame.page}`;
|
|
45485
|
+
pages.set(page, {
|
|
45486
|
+
...pages.get(page),
|
|
45487
|
+
[frame.name]: size
|
|
45488
|
+
});
|
|
45489
|
+
}
|
|
45490
|
+
let written = false;
|
|
45491
|
+
for (const [page, sizes] of pages) {
|
|
45492
|
+
if (closed) break;
|
|
45493
|
+
try {
|
|
45494
|
+
const names = await setMeasured(root, page, sizes, { cwd: root });
|
|
45495
|
+
written ||= names.length > 0;
|
|
45496
|
+
} catch (error) {
|
|
45497
|
+
if (!(error instanceof FrameboardError)) throw error;
|
|
45498
|
+
}
|
|
45499
|
+
}
|
|
45500
|
+
return written;
|
|
45501
|
+
};
|
|
45502
|
+
return {
|
|
45503
|
+
now: (board, refs) => run(board, refs),
|
|
45504
|
+
later: (board, refs) => {
|
|
45505
|
+
if (closed || huggingFrames(board, refs).length === 0) return;
|
|
45506
|
+
queue = queue.then(() => run(board, refs)).catch(() => {});
|
|
45507
|
+
},
|
|
45508
|
+
close: () => {
|
|
45509
|
+
closed = true;
|
|
45510
|
+
}
|
|
45511
|
+
};
|
|
45512
|
+
}
|
|
45513
|
+
function huggingFrames(board, refs) {
|
|
45514
|
+
const wanted = new Set(refs);
|
|
45515
|
+
return board.projects.flatMap((project) => project.pages).flatMap((page) => page.frames).filter((frame) => wanted.has(frame.ref) && frame.placed && (frame.hugWidth || frame.hugHeight));
|
|
45516
|
+
}
|
|
45517
|
+
/**
|
|
45518
|
+
* The hugging frames whose file was written after their page's `layout.json`,
|
|
45519
|
+
* as one edited while no server ran, which the start sweep measures before
|
|
45520
|
+
* the first board goes out. Every other frame's stored size already holds.
|
|
45521
|
+
*/
|
|
45522
|
+
async function writtenSinceLayout(board) {
|
|
45523
|
+
const pages = board.projects.flatMap((project) => project.pages);
|
|
45524
|
+
return (await Promise.all(pages.map(async (page) => {
|
|
45525
|
+
const hugging = page.frames.filter((frame) => frame.placed && (frame.hugWidth || frame.hugHeight));
|
|
45526
|
+
if (hugging.length === 0) return [];
|
|
45527
|
+
const layout = await mtimeOf(join(page.path, LAYOUT_FILE));
|
|
45528
|
+
return hugging.filter((frame) => Date.parse(frame.modifiedAt) > layout).map((frame) => frame.ref);
|
|
45529
|
+
}))).flat();
|
|
45530
|
+
}
|
|
45531
|
+
async function mtimeOf(path) {
|
|
45532
|
+
try {
|
|
45533
|
+
return (await stat$1(path)).mtimeMs;
|
|
45534
|
+
} catch {
|
|
45535
|
+
return 0;
|
|
45536
|
+
}
|
|
45537
|
+
}
|
|
45538
|
+
/** The frames a batch reloads through their own file, as against an asset or a token sheet. */
|
|
45539
|
+
function ownFileRefs(board, paths) {
|
|
45540
|
+
const written = new Set(paths);
|
|
45541
|
+
return board.projects.flatMap((project) => project.pages).flatMap((page) => page.frames).filter((frame) => written.has(frame.path)).map((frame) => frame.ref);
|
|
45542
|
+
}
|
|
45543
|
+
//#endregion
|
|
45024
45544
|
//#region src/server/live/rendered-findings.ts
|
|
45025
45545
|
/**
|
|
45026
45546
|
* The server's warm checker. Rechecks run one at a time on their own queue,
|
|
@@ -45063,7 +45583,7 @@ function createRenderedFindings({ check, onResult }) {
|
|
|
45063
45583
|
check(frame).then((findings) => {
|
|
45064
45584
|
const recovered = failure !== null;
|
|
45065
45585
|
failure = null;
|
|
45066
|
-
if (current()) onResult(ref, findings);
|
|
45586
|
+
if (findings && current()) onResult(ref, findings);
|
|
45067
45587
|
if (!recovered) return;
|
|
45068
45588
|
for (const [other, record] of known) if (other !== ref && !pending.has(other)) enqueue(other, record);
|
|
45069
45589
|
}).catch((error) => {
|
|
@@ -45300,7 +45820,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45300
45820
|
cookieName: cookieName(root),
|
|
45301
45821
|
isOwnOrigin: (host) => isBoardHost(host, bound)
|
|
45302
45822
|
};
|
|
45303
|
-
const boardUrl = () => `http://${HOSTNAME}:${bound}/api/access/redeem?ticket=${tickets.mint()}`;
|
|
45823
|
+
const boardUrl = () => `http://${HOSTNAME}:${bound}/api/access/redeem?ticket=${tickets.mint().ticket}`;
|
|
45304
45824
|
let scanning = Promise.resolve();
|
|
45305
45825
|
const inTurn = (task) => {
|
|
45306
45826
|
const run = scanning.then(task);
|
|
@@ -45384,18 +45904,21 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45384
45904
|
});
|
|
45385
45905
|
await thumbnails.empty();
|
|
45386
45906
|
const rendered = createRenderedFindings({
|
|
45387
|
-
check: async (frame) =>
|
|
45388
|
-
|
|
45389
|
-
|
|
45390
|
-
|
|
45391
|
-
|
|
45392
|
-
|
|
45393
|
-
|
|
45394
|
-
|
|
45395
|
-
|
|
45396
|
-
|
|
45397
|
-
|
|
45398
|
-
|
|
45907
|
+
check: async (frame) => {
|
|
45908
|
+
const list = await checkRendered(await browser.get(), {
|
|
45909
|
+
baseUrl: baseUrl(),
|
|
45910
|
+
frame: {
|
|
45911
|
+
ref: frame.ref,
|
|
45912
|
+
path: boardPath(root, frame.path),
|
|
45913
|
+
box: {
|
|
45914
|
+
width: frame.box.width,
|
|
45915
|
+
height: frame.box.height
|
|
45916
|
+
}
|
|
45917
|
+
},
|
|
45918
|
+
config: readConfig(root, frame.project)
|
|
45919
|
+
});
|
|
45920
|
+
return await modifiedAt(frame.path) === frame.modifiedAt ? list : null;
|
|
45921
|
+
},
|
|
45399
45922
|
onResult: (ref, list) => {
|
|
45400
45923
|
const before = findings.rendered([ref])[ref];
|
|
45401
45924
|
if (JSON.stringify(before) === JSON.stringify(list)) return;
|
|
@@ -45406,6 +45929,17 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45406
45929
|
});
|
|
45407
45930
|
}
|
|
45408
45931
|
});
|
|
45932
|
+
const measure = async (frame) => measureContent(await browser.get(), {
|
|
45933
|
+
baseUrl: baseUrl(),
|
|
45934
|
+
ref: frame.ref,
|
|
45935
|
+
box: frame.box,
|
|
45936
|
+
hugWidth: frame.hugWidth,
|
|
45937
|
+
fonts: "wait"
|
|
45938
|
+
});
|
|
45939
|
+
const hug = createHug({
|
|
45940
|
+
root,
|
|
45941
|
+
measure
|
|
45942
|
+
});
|
|
45409
45943
|
const app = createApp({
|
|
45410
45944
|
clientDir,
|
|
45411
45945
|
facesDir,
|
|
@@ -45418,6 +45952,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45418
45952
|
selection,
|
|
45419
45953
|
renderFrame,
|
|
45420
45954
|
thumbnails,
|
|
45955
|
+
measure,
|
|
45421
45956
|
checks: {
|
|
45422
45957
|
refresh: () => inTurn(async () => {
|
|
45423
45958
|
try {
|
|
@@ -45458,10 +45993,13 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45458
45993
|
});
|
|
45459
45994
|
server.on("upgrade", hub.handleUpgrade);
|
|
45460
45995
|
inTurn(async () => {
|
|
45461
|
-
|
|
45996
|
+
let board = await scanBoard(root);
|
|
45997
|
+
const stale = await writtenSinceLayout(board).catch(() => []);
|
|
45998
|
+
if (await hug.now(board, stale).catch(() => false)) board = await scanBoard(root);
|
|
45462
45999
|
await tracker.prime(board);
|
|
45463
46000
|
findings.update(board, "all");
|
|
45464
46001
|
rendered.queue(board, []);
|
|
46002
|
+
hug.later(board, board.projects.flatMap((project) => project.pages.flatMap((page) => page.frames.map((frame) => frame.ref).filter((ref) => !stale.includes(ref)))));
|
|
45465
46003
|
});
|
|
45466
46004
|
claims.push();
|
|
45467
46005
|
const watcher = await watchBoard(root, tokens ? [tokens] : []);
|
|
@@ -45477,6 +46015,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45477
46015
|
tracker,
|
|
45478
46016
|
claims,
|
|
45479
46017
|
thumbnails,
|
|
46018
|
+
hug,
|
|
45480
46019
|
settleLater
|
|
45481
46020
|
}));
|
|
45482
46021
|
});
|
|
@@ -45491,6 +46030,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45491
46030
|
boardUrl,
|
|
45492
46031
|
close: async () => {
|
|
45493
46032
|
rendered.close();
|
|
46033
|
+
hug.close();
|
|
45494
46034
|
claims.close();
|
|
45495
46035
|
for (const timer of settling) clearTimeout(timer);
|
|
45496
46036
|
await Promise.all([
|
|
@@ -45514,10 +46054,13 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45514
46054
|
* notes or frames it touched, whose queue it offers to delivery. The frames
|
|
45515
46055
|
* an agent changed wait out the grace before the board hears of them.
|
|
45516
46056
|
*/
|
|
45517
|
-
async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, settleLater }) {
|
|
46057
|
+
async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, hug, settleLater }) {
|
|
45518
46058
|
let board;
|
|
46059
|
+
let own;
|
|
45519
46060
|
try {
|
|
45520
46061
|
board = await scanBoard(root);
|
|
46062
|
+
own = ownFileRefs(board, paths);
|
|
46063
|
+
if (await hug.now(board, own).catch(() => false)) board = await scanBoard(root);
|
|
45521
46064
|
} catch {
|
|
45522
46065
|
return;
|
|
45523
46066
|
}
|
|
@@ -45526,6 +46069,7 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
|
|
|
45526
46069
|
data: board
|
|
45527
46070
|
});
|
|
45528
46071
|
const refs = reloadRefs(root, paths, board, tokens);
|
|
46072
|
+
hug.later(board, refs.filter((ref) => !own.includes(ref)));
|
|
45529
46073
|
if (refs.length > 0) {
|
|
45530
46074
|
hub.broadcast({
|
|
45531
46075
|
type: "reload",
|
|
@@ -45549,6 +46093,13 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
|
|
|
45549
46093
|
rendered.queue(board, recheckRefs(root, paths, board, tokens));
|
|
45550
46094
|
await pushNotes(root, paths, hub, delivery);
|
|
45551
46095
|
}
|
|
46096
|
+
async function modifiedAt(path) {
|
|
46097
|
+
try {
|
|
46098
|
+
return new Date((await stat$1(path)).mtimeMs).toISOString();
|
|
46099
|
+
} catch {
|
|
46100
|
+
return null;
|
|
46101
|
+
}
|
|
46102
|
+
}
|
|
45552
46103
|
/**
|
|
45553
46104
|
* A notes write changes its page's notes, and a frame write can lose an
|
|
45554
46105
|
* element note its anchor, so both reread the page. A frame write on a page
|
|
@@ -45591,7 +46142,7 @@ const DEFAULT_PORT = 4173;
|
|
|
45591
46142
|
/** How long a fresh server waits for a writing board tab left open by its predecessor to reconnect. */
|
|
45592
46143
|
const RECONNECT_WAIT_MS = 1e3;
|
|
45593
46144
|
function registerServe(program, context) {
|
|
45594
|
-
const { io, clientDir
|
|
46145
|
+
const { io, clientDir } = context;
|
|
45595
46146
|
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) => {
|
|
45596
46147
|
const tokens = options.tokens === void 0 ? void 0 : resolve(io.cwd, options.tokens);
|
|
45597
46148
|
if (tokens !== void 0 && !isFile(tokens)) throw new FrameboardError("tokens-not-found", `No token sheet at ${tokens}.`, { tokens });
|
|
@@ -45618,7 +46169,7 @@ function registerServe(program, context) {
|
|
|
45618
46169
|
}
|
|
45619
46170
|
const server = await startServer({
|
|
45620
46171
|
clientDir,
|
|
45621
|
-
facesDir,
|
|
46172
|
+
facesDir: context.facesDir,
|
|
45622
46173
|
root,
|
|
45623
46174
|
tokens,
|
|
45624
46175
|
port: options.port,
|
|
@@ -45684,9 +46235,69 @@ function registerShow(program, context) {
|
|
|
45684
46235
|
});
|
|
45685
46236
|
}
|
|
45686
46237
|
//#endregion
|
|
46238
|
+
//#region src/server/look/write-faces.ts
|
|
46239
|
+
const require$1 = createRequire(import.meta.url);
|
|
46240
|
+
/** Whether `dir` holds a sheet for every face. */
|
|
46241
|
+
function hasFaces(dir) {
|
|
46242
|
+
return FACES.every((face) => existsSync(join(dir, face.folder, "index.css")));
|
|
46243
|
+
}
|
|
46244
|
+
/**
|
|
46245
|
+
* Copies each face every frame imports from its package into `outDir`,
|
|
46246
|
+
* replacing what was there. The faces fill a sibling folder first and rename
|
|
46247
|
+
* into place, so `outDir` holds every file or does not exist, and an
|
|
46248
|
+
* interrupted write leaves no half-filled face behind. Each sheet is
|
|
46249
|
+
* rewritten to declare the plain family a frame names, such as Geist, rather
|
|
46250
|
+
* than the package's own, such as Geist Variable. With `keepComplete`, a
|
|
46251
|
+
* folder that filled in meanwhile, as from a parallel run, stays as it is.
|
|
46252
|
+
*/
|
|
46253
|
+
function writeFaces(outDir, { keepComplete = false } = {}) {
|
|
46254
|
+
const staging = `${outDir}.${process.pid}.tmp`;
|
|
46255
|
+
rmSync(staging, {
|
|
46256
|
+
recursive: true,
|
|
46257
|
+
force: true
|
|
46258
|
+
});
|
|
46259
|
+
try {
|
|
46260
|
+
for (const face of FACES) {
|
|
46261
|
+
const from = dirname(require$1.resolve(`${face.package}/package.json`));
|
|
46262
|
+
const to = join(staging, face.folder);
|
|
46263
|
+
mkdirSync(join(to, "files"), { recursive: true });
|
|
46264
|
+
const sheet = readFileSync(join(from, "index.css"), "utf8");
|
|
46265
|
+
writeFileSync(join(to, "index.css"), sheet.replaceAll(`'${face.packageFamily}'`, `'${face.family}'`));
|
|
46266
|
+
copyFileSync(join(from, "LICENSE"), join(to, "LICENSE"));
|
|
46267
|
+
for (const file of readdirSync(join(from, "files"))) if (file.endsWith(".woff2")) copyFileSync(join(from, "files", file), join(to, "files", file));
|
|
46268
|
+
}
|
|
46269
|
+
if (keepComplete && hasFaces(outDir)) return;
|
|
46270
|
+
rmSync(outDir, {
|
|
46271
|
+
recursive: true,
|
|
46272
|
+
force: true
|
|
46273
|
+
});
|
|
46274
|
+
mkdirSync(dirname(outDir), { recursive: true });
|
|
46275
|
+
renameSync(staging, outDir);
|
|
46276
|
+
} finally {
|
|
46277
|
+
rmSync(staging, {
|
|
46278
|
+
recursive: true,
|
|
46279
|
+
force: true
|
|
46280
|
+
});
|
|
46281
|
+
}
|
|
46282
|
+
}
|
|
46283
|
+
//#endregion
|
|
46284
|
+
//#region src/cli/faces-dir.ts
|
|
46285
|
+
/**
|
|
46286
|
+
* The folder the faces are served from. A built run reads the `faces` folder
|
|
46287
|
+
* the build put beside the bundle and never looks further, so a bundle missing
|
|
46288
|
+
* it fails loudly. A source run writes the faces once into the package's
|
|
46289
|
+
* `node_modules/.cache` from the installed packages, and completes a cache
|
|
46290
|
+
* missing any face.
|
|
46291
|
+
*/
|
|
46292
|
+
function resolveFacesDir(moduleUrl = import.meta.url) {
|
|
46293
|
+
if (!moduleUrl.endsWith(".ts")) return fileURLToPath(new URL("./faces", moduleUrl));
|
|
46294
|
+
const cache = fileURLToPath(new URL("../../node_modules/.cache/frameboard/faces", moduleUrl));
|
|
46295
|
+
if (!hasFaces(cache)) writeFaces(cache, { keepComplete: true });
|
|
46296
|
+
return cache;
|
|
46297
|
+
}
|
|
46298
|
+
//#endregion
|
|
45687
46299
|
//#region src/cli/program.ts
|
|
45688
46300
|
const CLIENT_DIR = fileURLToPath(new URL("./client", import.meta.url));
|
|
45689
|
-
const FACES_DIR = fileURLToPath(new URL("./faces", import.meta.url));
|
|
45690
46301
|
function parsePort(value) {
|
|
45691
46302
|
const port = /^\d+$/.test(value) ? Number(value) : NaN;
|
|
45692
46303
|
if (!(port >= 0 && port <= 65535)) throw new InvalidArgumentError("Expected a port between 0 and 65535.");
|
|
@@ -45702,7 +46313,7 @@ function parseInteger(min) {
|
|
|
45702
46313
|
}
|
|
45703
46314
|
/** Adds a verb with `--json` and `--root`, and `--project` when it acts inside a project. */
|
|
45704
46315
|
function addVerb(parent, name, description, { project = false } = {}) {
|
|
45705
|
-
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");
|
|
46316
|
+
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");
|
|
45706
46317
|
if (project) command.option("--project <name>", "the project, defaulting to the board's only one");
|
|
45707
46318
|
return command;
|
|
45708
46319
|
}
|
|
@@ -45733,34 +46344,29 @@ function createProgram(context) {
|
|
|
45733
46344
|
writeOut: io.stdout,
|
|
45734
46345
|
writeErr: (text) => json ? void 0 : io.stderr(text)
|
|
45735
46346
|
});
|
|
45736
|
-
|
|
45737
|
-
|
|
46347
|
+
let facesDir;
|
|
46348
|
+
const faced = {
|
|
45738
46349
|
...context,
|
|
45739
46350
|
clientDir: context.clientDir ?? CLIENT_DIR,
|
|
45740
|
-
facesDir
|
|
45741
|
-
|
|
46351
|
+
get facesDir() {
|
|
46352
|
+
return facesDir ??= context.facesDir ?? resolveFacesDir();
|
|
46353
|
+
}
|
|
46354
|
+
};
|
|
46355
|
+
registerServe(program, faced);
|
|
45742
46356
|
registerShow(program, context);
|
|
46357
|
+
registerOpen(program, context);
|
|
45743
46358
|
registerSelection(program, context);
|
|
45744
46359
|
registerList(program, context);
|
|
45745
46360
|
registerProject(program, context);
|
|
45746
46361
|
registerPage(program, context);
|
|
45747
|
-
registerFrame(program,
|
|
45748
|
-
...context,
|
|
45749
|
-
facesDir
|
|
45750
|
-
});
|
|
46362
|
+
registerFrame(program, faced);
|
|
45751
46363
|
registerEdit(program, context);
|
|
45752
46364
|
registerCheck(program, context);
|
|
45753
46365
|
registerNotes(program, context);
|
|
45754
46366
|
registerInbox(program, context);
|
|
45755
46367
|
registerEditing(program, context);
|
|
45756
|
-
registerCapture(program,
|
|
45757
|
-
|
|
45758
|
-
facesDir
|
|
45759
|
-
});
|
|
45760
|
-
registerInspect(program, {
|
|
45761
|
-
...context,
|
|
45762
|
-
facesDir
|
|
45763
|
-
});
|
|
46368
|
+
registerCapture(program, faced);
|
|
46369
|
+
registerInspect(program, faced);
|
|
45764
46370
|
registerDocs(program, context);
|
|
45765
46371
|
return program;
|
|
45766
46372
|
}
|
|
@@ -45845,6 +46451,10 @@ function missingCommand(group) {
|
|
|
45845
46451
|
//#region src/cli/index.ts
|
|
45846
46452
|
const controller = new AbortController();
|
|
45847
46453
|
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
|
|
46454
|
+
process.stdout.on("error", (error) => {
|
|
46455
|
+
if (error.code === "EPIPE") process.exit(0);
|
|
46456
|
+
throw error;
|
|
46457
|
+
});
|
|
45848
46458
|
process.exitCode = await runCli(process.argv.slice(2), {
|
|
45849
46459
|
stdout: (text) => process.stdout.write(text),
|
|
45850
46460
|
stderr: (text) => process.stderr.write(text),
|