frameboard 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +693 -133
- package/dist/client/assets/index-B3-XL1cU.js +115 -0
- package/dist/client/assets/index-D_ZnMRyk.css +2 -0
- package/dist/client/index.html +2 -2
- package/package.json +1 -1
- package/dist/client/assets/index-1aGUdRZT.css +0 -2
- package/dist/client/assets/index-DhTjSlhC.js +0 -114
package/dist/cli.js
CHANGED
|
@@ -3056,7 +3056,9 @@ const EXIT_CODES = {
|
|
|
3056
3056
|
"formatter-not-found": 9,
|
|
3057
3057
|
"references-stale": 14,
|
|
3058
3058
|
"page-file-load": 10,
|
|
3059
|
-
"image-missing": 10
|
|
3059
|
+
"image-missing": 10,
|
|
3060
|
+
"motion-missing": 10,
|
|
3061
|
+
"motion-unbounded": 10
|
|
3060
3062
|
};
|
|
3061
3063
|
var FrameboardError = class extends Error {
|
|
3062
3064
|
code;
|
|
@@ -3179,10 +3181,7 @@ async function acquire(lock, timeoutMs) {
|
|
|
3179
3181
|
if (!isCode(error, "EEXIST")) throw error;
|
|
3180
3182
|
}
|
|
3181
3183
|
const stale = await staleContent(lock);
|
|
3182
|
-
if (stale !== null)
|
|
3183
|
-
await breakLock(lock, stale);
|
|
3184
|
-
continue;
|
|
3185
|
-
}
|
|
3184
|
+
if (stale !== null && await breakLock(lock, stale)) continue;
|
|
3186
3185
|
if (Date.now() >= deadline) throw new FrameboardError("lock-timeout", `Another writer held ${lock} for more than ${timeoutMs} ms.`, { path: lock });
|
|
3187
3186
|
await setTimeout$1(LOCK_POLL_MS);
|
|
3188
3187
|
}
|
|
@@ -3205,26 +3204,72 @@ async function staleContent(lock) {
|
|
|
3205
3204
|
return Number.isInteger(pid) && !isAlive(pid) ? text : null;
|
|
3206
3205
|
}
|
|
3207
3206
|
/**
|
|
3208
|
-
* Breaks a stale lock
|
|
3209
|
-
* lock
|
|
3210
|
-
*
|
|
3207
|
+
* Breaks a stale lock under a guard, so one writer at a time re-reads the
|
|
3208
|
+
* lock and retires it only while it still holds the content judged stale.
|
|
3209
|
+
* Without the guard, a second breaker could rename aside the lock a first
|
|
3210
|
+
* one had just taken, and put it back after its owner released it, leaving
|
|
3211
|
+
* a lock nobody holds. A guard a crashed breaker left behind ages out like a
|
|
3212
|
+
* lock. False while another breaker holds the guard, so the caller waits.
|
|
3211
3213
|
*/
|
|
3212
3214
|
async function breakLock(lock, judged) {
|
|
3213
|
-
const
|
|
3215
|
+
const guard = `${lock.slice(0, -5)}.break${LOCK_SUFFIX}`;
|
|
3216
|
+
const nonce = randomBytes(8).toString("hex");
|
|
3217
|
+
try {
|
|
3218
|
+
const handle = await open(guard, "wx");
|
|
3219
|
+
await handle.writeFile(nonce);
|
|
3220
|
+
await handle.close();
|
|
3221
|
+
} catch (error) {
|
|
3222
|
+
if (!isCode(error, "EEXIST")) throw error;
|
|
3223
|
+
await clearAgedGuard(guard);
|
|
3224
|
+
return false;
|
|
3225
|
+
}
|
|
3226
|
+
try {
|
|
3227
|
+
if (await readOrNull$1(lock) === judged) await retire(lock, judged);
|
|
3228
|
+
return true;
|
|
3229
|
+
} finally {
|
|
3230
|
+
if (await readOrNull$1(guard) === nonce) await rm(guard, { force: true });
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
async function clearAgedGuard(guard) {
|
|
3234
|
+
let text;
|
|
3235
|
+
let modifiedAt;
|
|
3214
3236
|
try {
|
|
3215
|
-
await
|
|
3237
|
+
[text, {mtimeMs: modifiedAt}] = await Promise.all([readFile(guard, "utf8"), stat(guard)]);
|
|
3216
3238
|
} catch (error) {
|
|
3217
3239
|
if (isCode(error, "ENOENT")) return;
|
|
3218
3240
|
throw error;
|
|
3219
3241
|
}
|
|
3242
|
+
if (Date.now() - modifiedAt > LOCK_STALE_MS) await retire(guard, text);
|
|
3243
|
+
}
|
|
3244
|
+
/**
|
|
3245
|
+
* Removes a file by renaming it aside, so of two writers retiring it only
|
|
3246
|
+
* the first rename wins. A rename that caught a newer file, written since
|
|
3247
|
+
* the content was judged, puts that file back.
|
|
3248
|
+
*/
|
|
3249
|
+
async function retire(path, judged) {
|
|
3250
|
+
const aside = `${path.slice(0, -5)}.${randomBytes(4).toString("hex")}.broken${LOCK_SUFFIX}`;
|
|
3220
3251
|
try {
|
|
3221
|
-
|
|
3252
|
+
await rename(path, aside);
|
|
3253
|
+
} catch (error) {
|
|
3254
|
+
if (isCode(error, "ENOENT")) return;
|
|
3255
|
+
throw error;
|
|
3256
|
+
}
|
|
3257
|
+
try {
|
|
3258
|
+
if (await readFile(aside, "utf8") !== judged) await link(aside, path).catch((error) => {
|
|
3222
3259
|
if (!isCode(error, "EEXIST")) throw error;
|
|
3223
3260
|
});
|
|
3224
3261
|
} finally {
|
|
3225
3262
|
await rm(aside, { force: true });
|
|
3226
3263
|
}
|
|
3227
3264
|
}
|
|
3265
|
+
async function readOrNull$1(path) {
|
|
3266
|
+
try {
|
|
3267
|
+
return await readFile(path, "utf8");
|
|
3268
|
+
} catch (error) {
|
|
3269
|
+
if (isCode(error, "ENOENT")) return null;
|
|
3270
|
+
throw error;
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3228
3273
|
/** Removes the lock only while it still holds this writer's nonce. */
|
|
3229
3274
|
async function release$2(lock, nonce) {
|
|
3230
3275
|
try {
|
|
@@ -9158,6 +9203,20 @@ const DEVICE_SIZES = [
|
|
|
9158
9203
|
group: "social",
|
|
9159
9204
|
width: 1200,
|
|
9160
9205
|
height: 627
|
|
9206
|
+
},
|
|
9207
|
+
{
|
|
9208
|
+
name: "video-landscape",
|
|
9209
|
+
label: "Video landscape",
|
|
9210
|
+
group: "video",
|
|
9211
|
+
width: 1920,
|
|
9212
|
+
height: 1080
|
|
9213
|
+
},
|
|
9214
|
+
{
|
|
9215
|
+
name: "video-portrait",
|
|
9216
|
+
label: "Video portrait",
|
|
9217
|
+
group: "video",
|
|
9218
|
+
width: 1080,
|
|
9219
|
+
height: 1920
|
|
9161
9220
|
}
|
|
9162
9221
|
];
|
|
9163
9222
|
/** Every size name, the three presets first, then the devices. */
|
|
@@ -9633,7 +9692,7 @@ async function isDirectory(path) {
|
|
|
9633
9692
|
}
|
|
9634
9693
|
}
|
|
9635
9694
|
// package.json
|
|
9636
|
-
var version$1 = "0.
|
|
9695
|
+
var version$1 = "0.32.0";
|
|
9637
9696
|
var dependencies = { "playwright-core": "1.65.0" };
|
|
9638
9697
|
var peerDependencies = { "oxfmt": "0.77.0" };
|
|
9639
9698
|
// src/shared/version.ts
|
|
@@ -10257,32 +10316,34 @@ async function renameFrame(root, ref, newName, options) {
|
|
|
10257
10316
|
async function resizeFrame(root, ref, options) {
|
|
10258
10317
|
const size = sizeOf(options);
|
|
10259
10318
|
if (Object.keys(size).length === 0 && options.scroll === void 0 && options.widths === void 0) throw new FrameboardError("usage", "Pass --size, --width, --height, --scroll, --no-scroll, --widths, or --no-widths to resize a frame.");
|
|
10260
|
-
return updatePlacement(root, ref, options, (placement, frameRef) =>
|
|
10261
|
-
|
|
10262
|
-
|
|
10263
|
-
|
|
10264
|
-
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
box: {
|
|
10273
|
-
...placement.box,
|
|
10274
|
-
...size,
|
|
10275
|
-
...drops ? { height: referenceHeight(width) } : {}
|
|
10276
|
-
},
|
|
10277
|
-
hugWidth,
|
|
10278
|
-
hugHeight: !scroll && placement.hugHeight && size.height === void 0,
|
|
10279
|
-
scroll,
|
|
10280
|
-
widths: scroll && placement.hugHeight ? widths.map((linked) => ({
|
|
10281
|
-
...linked,
|
|
10282
|
-
height: referenceHeight(linked.width)
|
|
10283
|
-
})) : widths
|
|
10284
|
-
};
|
|
10319
|
+
return updatePlacement(root, ref, options, (placement, frameRef) => resizedPlacement(placement, frameRef, size, options));
|
|
10320
|
+
}
|
|
10321
|
+
/** The placement `resizeFrame` writes, for the size it read off its options. */
|
|
10322
|
+
function resizedPlacement(placement, frameRef, size, options) {
|
|
10323
|
+
const scroll = options.scroll ?? placement.scroll;
|
|
10324
|
+
const width = size.width ?? placement.box.width;
|
|
10325
|
+
const drops = scroll && placement.hugHeight && size.height === void 0;
|
|
10326
|
+
const hugWidth = !scroll && placement.hugWidth && size.width === void 0;
|
|
10327
|
+
const widths = linkedWidths(frameRef, options.widths ?? placement.widths.map((linked) => linked.width), {
|
|
10328
|
+
width,
|
|
10329
|
+
hugWidth,
|
|
10330
|
+
held: placement.widths
|
|
10285
10331
|
});
|
|
10332
|
+
return {
|
|
10333
|
+
...placement,
|
|
10334
|
+
box: {
|
|
10335
|
+
...placement.box,
|
|
10336
|
+
...size,
|
|
10337
|
+
...drops ? { height: referenceHeight(width) } : {}
|
|
10338
|
+
},
|
|
10339
|
+
hugWidth,
|
|
10340
|
+
hugHeight: !scroll && placement.hugHeight && size.height === void 0,
|
|
10341
|
+
scroll,
|
|
10342
|
+
widths: scroll && placement.hugHeight ? widths.map((linked) => ({
|
|
10343
|
+
...linked,
|
|
10344
|
+
height: referenceHeight(linked.width)
|
|
10345
|
+
})) : widths
|
|
10346
|
+
};
|
|
10286
10347
|
}
|
|
10287
10348
|
/**
|
|
10288
10349
|
* The linked widths a verb writes, keeping the height each one already held
|
|
@@ -10325,18 +10386,73 @@ function pastExtent({ box, widths }) {
|
|
|
10325
10386
|
async function fitHeight(root, ref, height, options) {
|
|
10326
10387
|
return updatePlacement(root, ref, options, (placement) => {
|
|
10327
10388
|
if (placement.scroll) throw fitScrollError(ref);
|
|
10328
|
-
return
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
|
|
10389
|
+
return fittedPlacement(placement, height, options.widths);
|
|
10390
|
+
});
|
|
10391
|
+
}
|
|
10392
|
+
/** A placement hugging its measured height, each listed linked width taking its own. */
|
|
10393
|
+
function fittedPlacement(placement, height, widths) {
|
|
10394
|
+
return {
|
|
10395
|
+
...placement,
|
|
10396
|
+
box: {
|
|
10397
|
+
...placement.box,
|
|
10398
|
+
height
|
|
10399
|
+
},
|
|
10400
|
+
hugHeight: true,
|
|
10401
|
+
widths: placement.widths.map((linked) => ({
|
|
10402
|
+
...linked,
|
|
10403
|
+
height: widths?.find((each) => each.width === linked.width)?.height ?? linked.height
|
|
10404
|
+
}))
|
|
10405
|
+
};
|
|
10406
|
+
}
|
|
10407
|
+
/**
|
|
10408
|
+
* Sets how each frame holds its height in one write under one lock, all of
|
|
10409
|
+
* them or none. `fixed` keeps the box and clears hugging and scroll. `fit`
|
|
10410
|
+
* takes the measured height and hugs it, clearing scroll. `scroll` fixes both
|
|
10411
|
+
* axes as `frame resize --scroll` does. Every frame is checked before any is
|
|
10412
|
+
* set: one moved or sized since its `expected` refuses `stale-layout`, leaving
|
|
10413
|
+
* out an axis the frame hugs, since the server measures that one, and a `fit`
|
|
10414
|
+
* without `measured` refuses `usage`.
|
|
10415
|
+
*/
|
|
10416
|
+
async function setHeightModes(root, targets, mode, options) {
|
|
10417
|
+
const frames = await Promise.all(targets.map(async (target) => ({
|
|
10418
|
+
target,
|
|
10419
|
+
frame: await resolveFrameRef(root, target.ref, options)
|
|
10420
|
+
})));
|
|
10421
|
+
await withLayouts(frames.map(({ frame }) => pageDir(frame)), async (layouts) => {
|
|
10422
|
+
const next = frames.map(({ target, frame }) => {
|
|
10423
|
+
const layout = layoutAt(layouts, pageDir(frame));
|
|
10424
|
+
const placement = layout.placement(frame.name);
|
|
10425
|
+
const frameRef = refOf$1(frame);
|
|
10426
|
+
refuseStale(frameRef, placement, target.expected);
|
|
10427
|
+
return {
|
|
10428
|
+
layout,
|
|
10429
|
+
name: frame.name,
|
|
10430
|
+
placement: heightPlacement(placement, frameRef, mode, target.measured)
|
|
10431
|
+
};
|
|
10432
|
+
});
|
|
10433
|
+
for (const { layout, name, placement } of next) layout.set(name, placement);
|
|
10434
|
+
}, options.journal);
|
|
10435
|
+
return Promise.all(frames.map(({ frame }) => frameRecord(root, frame.project, frame.page, frame.name)));
|
|
10436
|
+
}
|
|
10437
|
+
function heightPlacement(placement, frameRef, mode, measured) {
|
|
10438
|
+
if (mode === "scroll") return resizedPlacement(placement, frameRef, {}, { scroll: true });
|
|
10439
|
+
if (mode === "fixed") return {
|
|
10440
|
+
...placement,
|
|
10441
|
+
hugHeight: false,
|
|
10442
|
+
scroll: false
|
|
10443
|
+
};
|
|
10444
|
+
if (!measured) throw new FrameboardError("usage", `Fitting ${frameRef} needs its measured height.`, { ref: frameRef });
|
|
10445
|
+
return {
|
|
10446
|
+
...fittedPlacement(placement, measured.height, measured.widths),
|
|
10447
|
+
scroll: false
|
|
10448
|
+
};
|
|
10449
|
+
}
|
|
10450
|
+
function refuseStale(ref, placement, expected) {
|
|
10451
|
+
const { box } = placement;
|
|
10452
|
+
if (!(box.x === expected.x && box.y === expected.y && (placement.hugWidth || box.width === expected.width) && (placement.hugHeight || box.height === expected.height))) throw new FrameboardError("stale-layout", `${ref} moved since this edit began, so nothing was written.`, {
|
|
10453
|
+
ref,
|
|
10454
|
+
stored: boxOf(box),
|
|
10455
|
+
expected
|
|
10340
10456
|
});
|
|
10341
10457
|
}
|
|
10342
10458
|
/** The refusal a fit of a scroll frame answers, before or after measuring. */
|
|
@@ -40993,6 +41109,8 @@ const STATUS = {
|
|
|
40993
41109
|
"font-missing": 422,
|
|
40994
41110
|
"image-missing": 422,
|
|
40995
41111
|
"capture-too-large": 422,
|
|
41112
|
+
"motion-missing": 422,
|
|
41113
|
+
"motion-unbounded": 422,
|
|
40996
41114
|
"browser-not-found": 503
|
|
40997
41115
|
};
|
|
40998
41116
|
/** The route's scale when none is asked for, matching Copy as PNG. */
|
|
@@ -41000,23 +41118,28 @@ const DEFAULT_SCALE = 2;
|
|
|
41000
41118
|
/**
|
|
41001
41119
|
* `GET /api/frames/png?ref=<frame-ref>&theme=<light|dark>&scale=<1|2|3>`, a
|
|
41002
41120
|
* frame rendered at `scale` times its layout size, twice when no scale is
|
|
41003
|
-
* given.
|
|
41004
|
-
*
|
|
41005
|
-
* `
|
|
41121
|
+
* given. An added `filmstrip=<n>` of 2 or more renders `n` moments of its
|
|
41122
|
+
* timeline in one row instead, refusing a frame with no timeline as
|
|
41123
|
+
* `motion-missing` and one that never ends as `motion-unbounded`. It takes
|
|
41124
|
+
* no token, since the image shows only what the frame route already serves,
|
|
41125
|
+
* and a refusal answers the CLI's `{ ok, error }` envelope.
|
|
41006
41126
|
*/
|
|
41007
|
-
function pngRoutes(root, render) {
|
|
41127
|
+
function pngRoutes(root, render, renderFilmstrip) {
|
|
41008
41128
|
const app = new Hono();
|
|
41009
41129
|
app.get("/api/frames/png", async (c) => {
|
|
41010
41130
|
try {
|
|
41011
41131
|
const ref = c.req.query("ref") ?? "";
|
|
41012
41132
|
const theme = c.req.query("theme") ?? "";
|
|
41013
41133
|
const scale = parseScale$1(c.req.query("scale"));
|
|
41014
|
-
|
|
41134
|
+
const filmstrip = parseFilmstrip(c.req.query("filmstrip"));
|
|
41135
|
+
if (ref === "" || !isTheme(theme) || scale === null || filmstrip === null) throw new FrameboardError("usage", "Ask for /api/frames/png?ref=<frame-ref>&theme=<light|dark>&scale=<1|2|3>, adding &filmstrip=<n> of 2 or more for a filmstrip.", {
|
|
41015
41136
|
ref,
|
|
41016
41137
|
theme,
|
|
41017
|
-
scale: c.req.query("scale") ?? null
|
|
41138
|
+
scale: c.req.query("scale") ?? null,
|
|
41139
|
+
filmstrip: c.req.query("filmstrip") ?? null
|
|
41018
41140
|
});
|
|
41019
|
-
const
|
|
41141
|
+
const frame = await readFrame$1(root, ref, { cwd: root });
|
|
41142
|
+
const bytes = filmstrip === void 0 ? await render(frame, theme, scale) : await renderFilmstrip(frame, theme, scale, filmstrip);
|
|
41020
41143
|
return c.body(new Uint8Array(bytes), 200, {
|
|
41021
41144
|
"Content-Type": "image/png",
|
|
41022
41145
|
"Cache-Control": "no-store"
|
|
@@ -41043,6 +41166,12 @@ function parseScale$1(value) {
|
|
|
41043
41166
|
if (value === "1" || value === "2" || value === "3") return Number(value);
|
|
41044
41167
|
return null;
|
|
41045
41168
|
}
|
|
41169
|
+
function parseFilmstrip(value) {
|
|
41170
|
+
if (value === void 0) return void 0;
|
|
41171
|
+
if (!/^[1-9][0-9]*$/.test(value)) return null;
|
|
41172
|
+
const count = Number(value);
|
|
41173
|
+
return count >= 2 ? count : null;
|
|
41174
|
+
}
|
|
41046
41175
|
// src/server/board/paste.ts
|
|
41047
41176
|
/** Reads each frame's file and placement under its page's lock, in the order given. */
|
|
41048
41177
|
async function holdFrames(root, refs, options) {
|
|
@@ -41248,7 +41377,20 @@ const frameDuplicateSchema = object$1({
|
|
|
41248
41377
|
y: coordinate
|
|
41249
41378
|
}).optional()
|
|
41250
41379
|
});
|
|
41251
|
-
const
|
|
41380
|
+
const frameHeightSchema = object$1({
|
|
41381
|
+
refs,
|
|
41382
|
+
mode: _enum$1([
|
|
41383
|
+
"fixed",
|
|
41384
|
+
"fit",
|
|
41385
|
+
"scroll"
|
|
41386
|
+
]),
|
|
41387
|
+
expected: record(ref, object$1({
|
|
41388
|
+
x: coordinate,
|
|
41389
|
+
y: coordinate,
|
|
41390
|
+
width: int$1().min(1),
|
|
41391
|
+
height: int$1().min(1)
|
|
41392
|
+
})).refine((boxes) => Object.keys(boxes).length <= 1e3)
|
|
41393
|
+
});
|
|
41252
41394
|
const pasteSchema = object$1({
|
|
41253
41395
|
ref,
|
|
41254
41396
|
at: object$1({
|
|
@@ -41531,42 +41673,54 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
41531
41673
|
});
|
|
41532
41674
|
});
|
|
41533
41675
|
/**
|
|
41534
|
-
* Sets
|
|
41535
|
-
*
|
|
41536
|
-
*
|
|
41676
|
+
* Sets how each frame holds its height, `fixed`, `fit`, or `scroll`, in one
|
|
41677
|
+
* step. `expected` holds each frame's box as the caller saw it, keyed by the
|
|
41678
|
+
* ref the body names, and a frame changed since refuses `stale-layout`
|
|
41679
|
+
* before any frame is written. A locked or claimed frame refuses the whole
|
|
41680
|
+
* write, and `fit` measures each frame and its linked widths on the warm
|
|
41681
|
+
* browser first, refusing `browser-not-found` where none runs.
|
|
41537
41682
|
*/
|
|
41538
|
-
app.post("/api/frame/
|
|
41539
|
-
const body = await parseBody$1(c.req.raw,
|
|
41540
|
-
|
|
41541
|
-
|
|
41542
|
-
|
|
41543
|
-
|
|
41544
|
-
|
|
41545
|
-
|
|
41546
|
-
|
|
41547
|
-
|
|
41548
|
-
|
|
41549
|
-
|
|
41550
|
-
|
|
41551
|
-
|
|
41552
|
-
|
|
41553
|
-
|
|
41554
|
-
|
|
41555
|
-
|
|
41683
|
+
app.post("/api/frame/height", async (c) => {
|
|
41684
|
+
const body = await parseBody$1(c.req.raw, frameHeightSchema);
|
|
41685
|
+
const targets = body.refs.map((ref) => {
|
|
41686
|
+
const expected = body.expected[ref];
|
|
41687
|
+
if (!expected) throw new FrameboardError("usage", `The body gives ${ref} no expected box.`, { ref });
|
|
41688
|
+
return {
|
|
41689
|
+
ref,
|
|
41690
|
+
expected
|
|
41691
|
+
};
|
|
41692
|
+
});
|
|
41693
|
+
await refuseLocked(body.refs);
|
|
41694
|
+
await refuseHeldFrames(body.refs);
|
|
41695
|
+
if (body.mode === "fit") {
|
|
41696
|
+
if (!measure) throw new FrameboardError("browser-not-found", "Fit height needs the board server's browser, and none runs here.");
|
|
41697
|
+
for (const target of targets) {
|
|
41698
|
+
const frame = await readFrame$1(root, target.ref, { cwd });
|
|
41699
|
+
const content = await measure(frame);
|
|
41700
|
+
const widths = [];
|
|
41701
|
+
for (const { width } of frame.widths) {
|
|
41702
|
+
const linked = await measure(frame, {
|
|
41703
|
+
width,
|
|
41704
|
+
height: referenceHeight(width)
|
|
41705
|
+
});
|
|
41706
|
+
widths.push({
|
|
41707
|
+
width,
|
|
41708
|
+
height: linked.height
|
|
41709
|
+
});
|
|
41710
|
+
}
|
|
41711
|
+
target.measured = {
|
|
41712
|
+
height: content.height,
|
|
41713
|
+
widths
|
|
41714
|
+
};
|
|
41715
|
+
}
|
|
41556
41716
|
}
|
|
41557
|
-
const
|
|
41717
|
+
const frames = await recorded((journal) => setHeightModes(root, targets, body.mode, {
|
|
41558
41718
|
cwd,
|
|
41559
|
-
journal
|
|
41560
|
-
|
|
41561
|
-
}), (record) => onFrames([record.ref]));
|
|
41719
|
+
journal
|
|
41720
|
+
}), (records) => onFrames(records.map((record) => record.ref)));
|
|
41562
41721
|
return c.json({
|
|
41563
41722
|
ok: true,
|
|
41564
|
-
data:
|
|
41565
|
-
frame: fit,
|
|
41566
|
-
contentHeight: measured.height,
|
|
41567
|
-
contentWidth: measured.contentWidth,
|
|
41568
|
-
tooWide: measured.contentWidth > fit.box.width
|
|
41569
|
-
}
|
|
41723
|
+
data: frames
|
|
41570
41724
|
});
|
|
41571
41725
|
});
|
|
41572
41726
|
app.post("/api/frame/delete", async (c) => {
|
|
@@ -41959,7 +42113,7 @@ function boardHostGuard(port) {
|
|
|
41959
42113
|
await next();
|
|
41960
42114
|
};
|
|
41961
42115
|
}
|
|
41962
|
-
function createApp({ clientDir, root, port, actions, tickets, openRoute, renderFrame, clipboard = null, facesDir, tokens, delivery, dispatch, history, selection, checks, thumbnails, measure, frameVersion, settledVersion, assetUsage }) {
|
|
42116
|
+
function createApp({ clientDir, root, port, actions, tickets, openRoute, renderFrame, renderFilmstrip, clipboard = null, facesDir, tokens, delivery, dispatch, history, selection, checks, thumbnails, measure, frameVersion, settledVersion, assetUsage }) {
|
|
41963
42117
|
const app = new Hono();
|
|
41964
42118
|
const given = tokens ?? null;
|
|
41965
42119
|
app.use("*", async (c, next) => {
|
|
@@ -41989,7 +42143,7 @@ function createApp({ clientDir, root, port, actions, tickets, openRoute, renderF
|
|
|
41989
42143
|
app.route("/", claimsRoutes(root, actions.access));
|
|
41990
42144
|
app.route("/", tokenRoutes(root, actions.access, history, frames.look));
|
|
41991
42145
|
app.route("/", editRoutes(root, actions.access, history, settledVersion, frames.look.sheets));
|
|
41992
|
-
app.route("/", pngRoutes(root, renderFrame));
|
|
42146
|
+
app.route("/", pngRoutes(root, renderFrame, renderFilmstrip));
|
|
41993
42147
|
app.route("/", clipboardRoutes(root, actions.access, renderFrame, clipboard));
|
|
41994
42148
|
if (checks) app.route("/", checkRoutes(actions.access, checks));
|
|
41995
42149
|
if (thumbnails) app.route("/", thumbnailRoutes(root, thumbnails));
|
|
@@ -42092,6 +42246,13 @@ async function withFrameHost(board, purpose, run) {
|
|
|
42092
42246
|
await host.close();
|
|
42093
42247
|
}
|
|
42094
42248
|
}
|
|
42249
|
+
// src/shared/capture-limits.ts
|
|
42250
|
+
/** Chromium's screenshot surface stops at this many pixels on either side. */
|
|
42251
|
+
const MAX_COMPOSITE_SIDE = 16384;
|
|
42252
|
+
/** A filmstrip's width in CSS pixels: `count` copies of the frame in a row, one margin around and between them. */
|
|
42253
|
+
function filmstripWidth(frameWidth, count) {
|
|
42254
|
+
return count * frameWidth + (count + 1) * 40;
|
|
42255
|
+
}
|
|
42095
42256
|
// src/server/capture/animation-settle.ts
|
|
42096
42257
|
/**
|
|
42097
42258
|
* Waits, within `timeoutMs`, until every running animation and transition
|
|
@@ -42346,11 +42507,134 @@ async function waitForImages(timeoutMs) {
|
|
|
42346
42507
|
});
|
|
42347
42508
|
return unsettled;
|
|
42348
42509
|
}
|
|
42510
|
+
// src/shared/motion.ts
|
|
42511
|
+
/**
|
|
42512
|
+
* Finds the timeline a page's motion runs on, taking `__hf` alone when
|
|
42513
|
+
* present, else every `__timelines` entry, else the page's animations, and
|
|
42514
|
+
* resolves null when none registers within `timeoutMs`.
|
|
42515
|
+
*
|
|
42516
|
+
* Capture evaluates this in a page by its source text and the board calls it
|
|
42517
|
+
* on an iframe's window, so it reads nothing outside its own body and takes
|
|
42518
|
+
* its clock, frames, and document from `view`, never the caller's realm.
|
|
42519
|
+
*/
|
|
42520
|
+
async function readMotionIn(view, timeoutMs) {
|
|
42521
|
+
const end = view.performance.now() + timeoutMs;
|
|
42522
|
+
const nextFrame = () => new Promise((done) => view.requestAnimationFrame(() => done()));
|
|
42523
|
+
const seconds = (value) => typeof value === "number" && Number.isFinite(value) ? Math.round(value * 1e3) : null;
|
|
42524
|
+
const read = () => {
|
|
42525
|
+
const hf = view.__hf;
|
|
42526
|
+
const hfDuration = seconds(hf?.duration);
|
|
42527
|
+
if (typeof hf?.seek === "function" && hfDuration !== null && hfDuration > 0) return {
|
|
42528
|
+
source: "hf",
|
|
42529
|
+
duration: hfDuration
|
|
42530
|
+
};
|
|
42531
|
+
const registry = view.__timelines;
|
|
42532
|
+
const timelines = Object.values(registry ?? {}).filter((timeline) => typeof timeline?.seek === "function");
|
|
42533
|
+
if (timelines.length > 0) {
|
|
42534
|
+
const finite = timelines.map((timeline) => seconds(typeof timeline.duration === "function" ? timeline.duration.call(timeline) : timeline.duration)).filter((length) => length !== null);
|
|
42535
|
+
return {
|
|
42536
|
+
source: "timelines",
|
|
42537
|
+
duration: finite.length === 0 ? null : Math.max(...finite)
|
|
42538
|
+
};
|
|
42539
|
+
}
|
|
42540
|
+
const animations = view.document.getAnimations();
|
|
42541
|
+
if (animations.length > 0) {
|
|
42542
|
+
const ends = animations.map((animation) => animation.effect?.getComputedTiming().endTime).filter((endTime) => typeof endTime === "number" && Number.isFinite(endTime));
|
|
42543
|
+
return {
|
|
42544
|
+
source: "css",
|
|
42545
|
+
duration: ends.length === 0 ? null : Math.round(Math.max(...ends))
|
|
42546
|
+
};
|
|
42547
|
+
}
|
|
42548
|
+
return null;
|
|
42549
|
+
};
|
|
42550
|
+
await nextFrame();
|
|
42551
|
+
for (;;) {
|
|
42552
|
+
const motion = read();
|
|
42553
|
+
if (motion !== null || view.performance.now() >= end) return motion;
|
|
42554
|
+
await nextFrame();
|
|
42555
|
+
}
|
|
42556
|
+
}
|
|
42557
|
+
/**
|
|
42558
|
+
* Holds the page at `ms`, clamped to the timeline's end, and resolves with
|
|
42559
|
+
* the moment it holds once a frame has painted it. HyperFrames and GSAP take
|
|
42560
|
+
* seconds, and the conversion happens here alone. Self-contained for the
|
|
42561
|
+
* same reason as `readMotionIn`.
|
|
42562
|
+
*/
|
|
42563
|
+
async function holdMotionIn(view, { motion, ms }) {
|
|
42564
|
+
const at = motion.duration === null ? ms : Math.min(Math.max(ms, 0), motion.duration);
|
|
42565
|
+
if (motion.source === "hf") await view.__hf.seek(at / 1e3);
|
|
42566
|
+
else if (motion.source === "timelines") {
|
|
42567
|
+
const registry = view.__timelines;
|
|
42568
|
+
for (const timeline of Object.values(registry)) {
|
|
42569
|
+
if (typeof timeline?.seek !== "function") continue;
|
|
42570
|
+
timeline.pause?.();
|
|
42571
|
+
await timeline.seek(at / 1e3);
|
|
42572
|
+
}
|
|
42573
|
+
} else for (const animation of view.document.getAnimations()) {
|
|
42574
|
+
animation.pause();
|
|
42575
|
+
animation.currentTime = at;
|
|
42576
|
+
}
|
|
42577
|
+
await new Promise((done) => view.requestAnimationFrame(() => view.requestAnimationFrame(() => done())));
|
|
42578
|
+
return at;
|
|
42579
|
+
}
|
|
42580
|
+
/**
|
|
42581
|
+
* `count` moments spaced evenly from 0 to the timeline's end inclusive.
|
|
42582
|
+
* Refuses `motion-unbounded` when every animation repeats forever, since no
|
|
42583
|
+
* end exists to space them across.
|
|
42584
|
+
*/
|
|
42585
|
+
function filmstripMoments(ref, motion, count) {
|
|
42586
|
+
const { duration } = motion;
|
|
42587
|
+
if (duration === null) throw new FrameboardError("motion-unbounded", `${ref} only runs animations that repeat forever, so a filmstrip has no end to space its moments across. Name the moments with --at instead.`, {
|
|
42588
|
+
ref,
|
|
42589
|
+
source: motion.source
|
|
42590
|
+
});
|
|
42591
|
+
return Array.from({ length: count }, (_, index) => Math.round(duration * index / (count - 1)));
|
|
42592
|
+
}
|
|
42593
|
+
// src/server/capture/seek.ts
|
|
42594
|
+
/**
|
|
42595
|
+
* Stops the page's animation clock, through the DevTools Animation domain,
|
|
42596
|
+
* before the page loads. A CSS animation with no fill that ended during the
|
|
42597
|
+
* load would otherwise drop out of `document.getAnimations()` before the seek
|
|
42598
|
+
* reads it. Script timelines run on their own clocks and keep running.
|
|
42599
|
+
*/
|
|
42600
|
+
async function holdAnimationClock(page) {
|
|
42601
|
+
const session = await page.context().newCDPSession(page);
|
|
42602
|
+
await session.send("Animation.enable");
|
|
42603
|
+
await session.send("Animation.setPlaybackRate", { playbackRate: 0 });
|
|
42604
|
+
}
|
|
42605
|
+
/**
|
|
42606
|
+
* Finds the timeline a frame's motion runs on, taking `window.__hf` alone
|
|
42607
|
+
* when present, else every `window.__timelines` entry, else the page's
|
|
42608
|
+
* animations. A script loading its timeline late gets until `timeoutMs` to
|
|
42609
|
+
* register one, and a frame showing none by then refuses `motion-missing`,
|
|
42610
|
+
* since a scene stepped by a script timer cannot be held at a moment.
|
|
42611
|
+
*/
|
|
42612
|
+
async function findMotion(page, ref, timeoutMs) {
|
|
42613
|
+
const found = await page.evaluate(inPage(readMotionIn, timeoutMs));
|
|
42614
|
+
if (found === null) throw new FrameboardError("motion-missing", `${ref} shows no animation, transition, window.__hf, or window.__timelines to seek, so it has no moment to capture. A scene a script steps on a timer cannot be held still.`, { ref });
|
|
42615
|
+
return found;
|
|
42616
|
+
}
|
|
42617
|
+
/**
|
|
42618
|
+
* Holds the frame at `ms`, clamped to the timeline's end, and resolves with
|
|
42619
|
+
* the moment it holds once a frame has painted it.
|
|
42620
|
+
*/
|
|
42621
|
+
function seekMotion(page, motion, ms) {
|
|
42622
|
+
return page.evaluate(inPage(holdMotionIn, {
|
|
42623
|
+
motion,
|
|
42624
|
+
ms
|
|
42625
|
+
}));
|
|
42626
|
+
}
|
|
42627
|
+
/**
|
|
42628
|
+
* The expression calling a shared window function on the page's own
|
|
42629
|
+
* `window`, by its source text, since Playwright sends a page only text and
|
|
42630
|
+
* the board imports the same function to call on an iframe's window.
|
|
42631
|
+
*/
|
|
42632
|
+
function inPage(run, arg) {
|
|
42633
|
+
return `(${run.toString()})(window, ${JSON.stringify(arg)})`;
|
|
42634
|
+
}
|
|
42349
42635
|
// src/server/capture/render.ts
|
|
42350
42636
|
/** How long a frame has to load, its faces and images included, before its capture fails. */
|
|
42351
42637
|
const LOAD_TIMEOUT_MS = 1e4;
|
|
42352
|
-
/** Chromium's screenshot surface stops at this many pixels on either side. */
|
|
42353
|
-
const MAX_COMPOSITE_SIDE = 16384;
|
|
42354
42638
|
/**
|
|
42355
42639
|
* Loads a frame in its own browser context at its layout size, in the theme
|
|
42356
42640
|
* asked for, and resolves once it has loaded, its faces have settled, and its
|
|
@@ -42358,9 +42642,9 @@ const MAX_COMPOSITE_SIDE = 16384;
|
|
|
42358
42642
|
* the default, a missing face refuses `font-missing`, an image that failed or
|
|
42359
42643
|
* outran the budget refuses `image-missing`, and either closes the context.
|
|
42360
42644
|
* It then waits, on what is left of the budget, for running animations with
|
|
42361
|
-
* a finite end to finish, and never refuses for one
|
|
42645
|
+
* a finite end to finish, and never refuses for one, unless `motion` is `hold`.
|
|
42362
42646
|
*/
|
|
42363
|
-
async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts = "require", timeoutMs = LOAD_TIMEOUT_MS }) {
|
|
42647
|
+
async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts = "require", timeoutMs = LOAD_TIMEOUT_MS, motion = "settle" }) {
|
|
42364
42648
|
const context = await browser.newContext({
|
|
42365
42649
|
viewport: {
|
|
42366
42650
|
width: box.width,
|
|
@@ -42373,6 +42657,7 @@ async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts =
|
|
|
42373
42657
|
const deadline = Date.now() + timeoutMs;
|
|
42374
42658
|
try {
|
|
42375
42659
|
const page = await context.newPage();
|
|
42660
|
+
if (motion === "hold") await holdAnimationClock(page);
|
|
42376
42661
|
await page.goto(new URL(frameThemeUrl(ref, theme), baseUrl).href, {
|
|
42377
42662
|
timeout: timeoutMs,
|
|
42378
42663
|
waitUntil: "domcontentloaded"
|
|
@@ -42385,7 +42670,7 @@ async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts =
|
|
|
42385
42670
|
await page.evaluate(() => document.fonts.ready.then(() => void 0));
|
|
42386
42671
|
if (fonts === "require") await assertFontsPresent(page, ref);
|
|
42387
42672
|
await settleImages(page, ref, fonts, deadline - Date.now());
|
|
42388
|
-
if (fonts === "require") await settleAnimations(page, deadline - Date.now());
|
|
42673
|
+
if (fonts === "require" && motion === "settle") await settleAnimations(page, deadline - Date.now());
|
|
42389
42674
|
return {
|
|
42390
42675
|
page,
|
|
42391
42676
|
close
|
|
@@ -42467,24 +42752,32 @@ function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
|
|
|
42467
42752
|
return run;
|
|
42468
42753
|
};
|
|
42469
42754
|
}
|
|
42755
|
+
// src/server/capture/images.ts
|
|
42470
42756
|
const SCREENSHOT = {
|
|
42471
42757
|
animations: "disabled",
|
|
42472
42758
|
caret: "hide"
|
|
42473
42759
|
};
|
|
42760
|
+
const HELD_SCREENSHOT = {
|
|
42761
|
+
animations: "allow",
|
|
42762
|
+
caret: "hide"
|
|
42763
|
+
};
|
|
42474
42764
|
/**
|
|
42475
42765
|
* The file name of one image, `<name>.<theme>.png` at 1x so a path an agent
|
|
42476
42766
|
* saved stays true, and `<name>.<theme>@<n>x.png` at any other scale. A shot
|
|
42477
42767
|
* scrolled down takes `.scroll-<px>` after the name, the offset asked for,
|
|
42478
|
-
* and a linked width takes `@<width>` ahead of both.
|
|
42768
|
+
* and a linked width takes `@<width>` ahead of both. A timed shot takes
|
|
42769
|
+
* `.at-<ms>`, the moment asked for, and a filmstrip `.filmstrip-<n>`, each
|
|
42770
|
+
* after the width.
|
|
42479
42771
|
*/
|
|
42480
|
-
function imageName(name, theme, scale, scroll, width) {
|
|
42772
|
+
function imageName(name, theme, scale, scroll, width, moment) {
|
|
42481
42773
|
const named = width === void 0 ? name : `${name}@${width}`;
|
|
42482
|
-
const
|
|
42774
|
+
const scrolled = scroll === void 0 ? named : `${named}.scroll-${scroll}`;
|
|
42775
|
+
const stem = moment === void 0 ? scrolled : "at" in moment ? `${scrolled}.at-${moment.at}` : `${scrolled}.filmstrip-${moment.filmstrip}`;
|
|
42483
42776
|
return scale === 1 ? `${stem}.${theme}.png` : `${stem}.${theme}@${scale}x.png`;
|
|
42484
42777
|
}
|
|
42485
42778
|
/** Where one frame's capture in one theme lands under `out`. */
|
|
42486
|
-
function frameImagePath(out, frame, theme, scale = 1, scroll, width) {
|
|
42487
|
-
return join(out, frame.project, frame.page, imageName(frame.name, theme, scale, scroll, width));
|
|
42779
|
+
function frameImagePath(out, frame, theme, scale = 1, scroll, width, moment) {
|
|
42780
|
+
return join(out, frame.project, frame.page, imageName(frame.name, theme, scale, scroll, width, moment));
|
|
42488
42781
|
}
|
|
42489
42782
|
/** Where a page's composite in one theme lands under `out`. */
|
|
42490
42783
|
function compositeImagePath(out, page, theme, scale = 1) {
|
|
@@ -42522,6 +42815,26 @@ function compositeBounds(page, frames, scale = 1) {
|
|
|
42522
42815
|
};
|
|
42523
42816
|
}
|
|
42524
42817
|
/**
|
|
42818
|
+
* A filmstrip's size: `count` copies of the frame's box in one row, one
|
|
42819
|
+
* margin around and between them. Refuses `capture-too-large` past
|
|
42820
|
+
* Chromium's screenshot limit.
|
|
42821
|
+
*/
|
|
42822
|
+
function filmstripBounds(ref, box, count, scale = 1) {
|
|
42823
|
+
const width = filmstripWidth(box.width, count);
|
|
42824
|
+
const height = box.height + 80;
|
|
42825
|
+
if (width * scale > 16384 || height * scale > 16384) throw new FrameboardError("capture-too-large", `A filmstrip of ${count} frames of ${ref}${scale === 1 ? "" : ` at ${scale}x`} would be ${width * scale} by ${height * scale} px, past the ${MAX_COMPOSITE_SIDE} px a browser screenshot holds. Ask for fewer frames or a smaller scale.`, {
|
|
42826
|
+
ref,
|
|
42827
|
+
width,
|
|
42828
|
+
height,
|
|
42829
|
+
scale,
|
|
42830
|
+
max: MAX_COMPOSITE_SIDE
|
|
42831
|
+
});
|
|
42832
|
+
return {
|
|
42833
|
+
width,
|
|
42834
|
+
height
|
|
42835
|
+
};
|
|
42836
|
+
}
|
|
42837
|
+
/**
|
|
42525
42838
|
* Captures each frame in each theme at its layout size times `scale`, one PNG
|
|
42526
42839
|
* apiece, and again at each linked width it lists, at the height that width
|
|
42527
42840
|
* holds. Every image renders before any is written, so a refusal on one frame
|
|
@@ -42581,6 +42894,136 @@ async function captureComposite(browser, { baseUrl, page, frames, themes, out, s
|
|
|
42581
42894
|
}
|
|
42582
42895
|
return writeImages(rendered);
|
|
42583
42896
|
}
|
|
42897
|
+
/**
|
|
42898
|
+
* Captures one frame held at set moments of its timeline, in each theme and
|
|
42899
|
+
* at each width it shows at, or the one `width` names. `timing.at` writes one
|
|
42900
|
+
* PNG per moment, and `timing.filmstrip` one PNG per view and theme holding that many
|
|
42901
|
+
* moments spaced from 0 to the timeline's end. A frame with no seekable
|
|
42902
|
+
* timeline refuses `motion-missing`, and a filmstrip of one that never ends
|
|
42903
|
+
* `motion-unbounded`. Every image renders before any is written.
|
|
42904
|
+
*/
|
|
42905
|
+
async function captureMotionImages(browser, { baseUrl, frame, themes, out, scale = 1, width, timing, motionTimeoutMs = LOAD_TIMEOUT_MS }) {
|
|
42906
|
+
const rendered = [];
|
|
42907
|
+
let found = null;
|
|
42908
|
+
for (const view of viewsOf(frame, width)) {
|
|
42909
|
+
const linked = view.width === frame.box.width ? void 0 : view.width;
|
|
42910
|
+
for (const theme of themes) {
|
|
42911
|
+
if ("filmstrip" in timing) {
|
|
42912
|
+
const strip = await renderFilmstrip(browser, {
|
|
42913
|
+
baseUrl,
|
|
42914
|
+
frame: {
|
|
42915
|
+
ref: frame.ref,
|
|
42916
|
+
box: view
|
|
42917
|
+
},
|
|
42918
|
+
theme,
|
|
42919
|
+
scale,
|
|
42920
|
+
count: timing.filmstrip,
|
|
42921
|
+
motionTimeoutMs
|
|
42922
|
+
});
|
|
42923
|
+
found ??= strip.motion;
|
|
42924
|
+
rendered.push({
|
|
42925
|
+
ref: frame.ref,
|
|
42926
|
+
theme,
|
|
42927
|
+
path: frameImagePath(out, frame, theme, scale, void 0, linked, { filmstrip: strip.moments.length }),
|
|
42928
|
+
width: strip.width,
|
|
42929
|
+
height: strip.height,
|
|
42930
|
+
scale,
|
|
42931
|
+
moments: strip.moments,
|
|
42932
|
+
bytes: strip.bytes
|
|
42933
|
+
});
|
|
42934
|
+
continue;
|
|
42935
|
+
}
|
|
42936
|
+
const shots = await holdShots(browser, {
|
|
42937
|
+
baseUrl,
|
|
42938
|
+
ref: frame.ref,
|
|
42939
|
+
view,
|
|
42940
|
+
theme,
|
|
42941
|
+
scale,
|
|
42942
|
+
motionTimeoutMs,
|
|
42943
|
+
moments: () => timing.at
|
|
42944
|
+
});
|
|
42945
|
+
found ??= shots.motion;
|
|
42946
|
+
shots.held.forEach(({ held, bytes }, index) => {
|
|
42947
|
+
rendered.push({
|
|
42948
|
+
ref: frame.ref,
|
|
42949
|
+
theme,
|
|
42950
|
+
path: frameImagePath(out, frame, theme, scale, void 0, linked, { at: timing.at[index] ?? held }),
|
|
42951
|
+
width: view.width,
|
|
42952
|
+
height: view.height,
|
|
42953
|
+
scale,
|
|
42954
|
+
at: held,
|
|
42955
|
+
bytes
|
|
42956
|
+
});
|
|
42957
|
+
});
|
|
42958
|
+
}
|
|
42959
|
+
}
|
|
42960
|
+
return {
|
|
42961
|
+
images: await writeImages(rendered),
|
|
42962
|
+
motion: found
|
|
42963
|
+
};
|
|
42964
|
+
}
|
|
42965
|
+
/**
|
|
42966
|
+
* One frame's filmstrip in one theme: `count` moments spaced from 0 to the
|
|
42967
|
+
* timeline's end, held one by one and laid in a row on the theme's canvas
|
|
42968
|
+
* color. Refuses `motion-missing` for a frame with no seekable timeline and
|
|
42969
|
+
* `motion-unbounded` for one that never ends, and `capture-too-large` before
|
|
42970
|
+
* opening the frame for a strip past the screenshot limit.
|
|
42971
|
+
*/
|
|
42972
|
+
async function renderFilmstrip(browser, { baseUrl, frame, theme, scale = 1, count, motionTimeoutMs = LOAD_TIMEOUT_MS }) {
|
|
42973
|
+
const view = {
|
|
42974
|
+
width: frame.box.width,
|
|
42975
|
+
height: frame.box.height
|
|
42976
|
+
};
|
|
42977
|
+
const strip = filmstripBounds(frame.ref, view, count, scale);
|
|
42978
|
+
const { motion, held } = await holdShots(browser, {
|
|
42979
|
+
baseUrl,
|
|
42980
|
+
ref: frame.ref,
|
|
42981
|
+
view,
|
|
42982
|
+
theme,
|
|
42983
|
+
scale,
|
|
42984
|
+
motionTimeoutMs,
|
|
42985
|
+
moments: (found) => filmstripMoments(frame.ref, found, count)
|
|
42986
|
+
});
|
|
42987
|
+
return {
|
|
42988
|
+
bytes: await renderComposite(browser, strip, theme, held.map(({ bytes }, index) => `<img src="data:image/png;base64,${bytes.toString("base64")}" style="position:absolute;left:${40 + index * (view.width + 40)}px;top:40px;width:${view.width}px;height:${view.height}px">`), scale),
|
|
42989
|
+
width: strip.width,
|
|
42990
|
+
height: strip.height,
|
|
42991
|
+
moments: held.map((shot) => shot.held),
|
|
42992
|
+
motion
|
|
42993
|
+
};
|
|
42994
|
+
}
|
|
42995
|
+
/**
|
|
42996
|
+
* Opens one frame with its animation clock held, finds its timeline, and
|
|
42997
|
+
* shoots it at each moment `moments` picks from what it found.
|
|
42998
|
+
*/
|
|
42999
|
+
async function holdShots(browser, { baseUrl, ref, view, theme, scale, motionTimeoutMs, moments }) {
|
|
43000
|
+
assertScreenshotFits(ref, view, scale);
|
|
43001
|
+
const opened = await openFrame(browser, {
|
|
43002
|
+
baseUrl,
|
|
43003
|
+
ref,
|
|
43004
|
+
box: view,
|
|
43005
|
+
theme,
|
|
43006
|
+
scale,
|
|
43007
|
+
motion: "hold"
|
|
43008
|
+
});
|
|
43009
|
+
try {
|
|
43010
|
+
const motion = await findMotion(opened.page, ref, motionTimeoutMs);
|
|
43011
|
+
const held = [];
|
|
43012
|
+
for (const moment of moments(motion)) {
|
|
43013
|
+
const at = await seekMotion(opened.page, motion, moment);
|
|
43014
|
+
held.push({
|
|
43015
|
+
held: at,
|
|
43016
|
+
bytes: await opened.page.screenshot(HELD_SCREENSHOT)
|
|
43017
|
+
});
|
|
43018
|
+
}
|
|
43019
|
+
return {
|
|
43020
|
+
motion,
|
|
43021
|
+
held
|
|
43022
|
+
};
|
|
43023
|
+
} finally {
|
|
43024
|
+
await opened.close();
|
|
43025
|
+
}
|
|
43026
|
+
}
|
|
42584
43027
|
async function renderFrame(browser, baseUrl, frame, view, theme, scale, scroll) {
|
|
42585
43028
|
const box = {
|
|
42586
43029
|
width: view.width,
|
|
@@ -42638,6 +43081,27 @@ async function writeImages(rendered) {
|
|
|
42638
43081
|
}));
|
|
42639
43082
|
return rendered.map(({ bytes: _bytes, ...image }) => image);
|
|
42640
43083
|
}
|
|
43084
|
+
/**
|
|
43085
|
+
* Renders filmstrips on a server's warm browser one at a time. The queue is
|
|
43086
|
+
* its own, so Copy as PNG and a plain export never wait behind a strip of
|
|
43087
|
+
* many moments.
|
|
43088
|
+
*/
|
|
43089
|
+
function createWarmFilmstripRenderer({ baseUrl, browser }) {
|
|
43090
|
+
let queue = Promise.resolve();
|
|
43091
|
+
return (frame, theme, scale, count) => {
|
|
43092
|
+
const run = queue.then(async () => {
|
|
43093
|
+
return (await renderFilmstrip(await browser.get(), {
|
|
43094
|
+
baseUrl: baseUrl(),
|
|
43095
|
+
frame,
|
|
43096
|
+
theme,
|
|
43097
|
+
scale,
|
|
43098
|
+
count
|
|
43099
|
+
})).bytes;
|
|
43100
|
+
});
|
|
43101
|
+
queue = run.catch(() => {});
|
|
43102
|
+
return run;
|
|
43103
|
+
};
|
|
43104
|
+
}
|
|
42641
43105
|
// src/cli/commands/capture.ts
|
|
42642
43106
|
function registerCapture(program, context) {
|
|
42643
43107
|
const { io } = context;
|
|
@@ -42645,10 +43109,14 @@ function registerCapture(program, context) {
|
|
|
42645
43109
|
"light",
|
|
42646
43110
|
"dark",
|
|
42647
43111
|
"both"
|
|
42648
|
-
]).default("both")).addOption(new Option("--scale <n>", "device pixels per CSS pixel, adding @<n>x to the file name past 1").default(1).argParser(parseScale)).option("--scroll <px>", "shoot a scroll frame this far down, clamped to the end of its page, adding .scroll-<px> to the file name", parseInteger(0)).option("--out <dir>", "the folder images land in, defaulting to the board's .run/captures/"), context, async ([ref], options) => {
|
|
43112
|
+
]).default("both")).addOption(new Option("--scale <n>", "device pixels per CSS pixel, adding @<n>x to the file name past 1").default(1).argParser(parseScale)).option("--scroll <px>", "shoot a scroll frame this far down, clamped to the end of its page, adding .scroll-<px> to the file name", parseInteger(0)).option("--at <ms,...>", "hold the frame at each of these moments of its timeline, in ms, one image apiece, adding .at-<ms> to the file name", parseMoments).option("--filmstrip <n>", "one image of n moments spaced from the start of the timeline to its end, adding .filmstrip-<n> to the file name", parseInteger(2)).option("--out <dir>", "the folder images land in, defaulting to the board's .run/captures/"), context, async ([ref], options) => {
|
|
42649
43113
|
if (ref === void 0 === (options.page === void 0)) throw new FrameboardError("usage", "Pass a frame ref or --page <page-ref>, exactly one of the two.");
|
|
42650
43114
|
if (options.composite && options.page === void 0) throw new FrameboardError("usage", "--composite needs --page.");
|
|
42651
43115
|
if (options.scroll !== void 0 && options.page !== void 0) throw new FrameboardError("usage", "--scroll shoots one frame, so pass a frame ref rather than --page.");
|
|
43116
|
+
const timing = options.at !== void 0 ? { at: options.at } : options.filmstrip !== void 0 ? { filmstrip: options.filmstrip } : void 0;
|
|
43117
|
+
if (options.at !== void 0 && options.filmstrip !== void 0) throw new FrameboardError("usage", "Pass --at or --filmstrip, not both.");
|
|
43118
|
+
if (timing !== void 0 && options.page !== void 0) throw new FrameboardError("usage", "--at and --filmstrip seek one frame, so pass a frame ref rather than --page.");
|
|
43119
|
+
if (timing !== void 0 && options.scroll !== void 0) throw new FrameboardError("usage", "--at and --filmstrip shoot the frame at the top, so drop --scroll.");
|
|
42652
43120
|
const root = await boardOf(options, io);
|
|
42653
43121
|
const refOptions = {
|
|
42654
43122
|
project: options.project,
|
|
@@ -42693,6 +43161,26 @@ function registerCapture(program, context) {
|
|
|
42693
43161
|
const frame = await readFrame$1(root, ref ?? "", refOptions);
|
|
42694
43162
|
if (options.scroll !== void 0 && !frame.scroll) throw new FrameboardError("usage", `${frame.ref} holds no scroll key, so it has nothing to scroll. Set it with frame resize --scroll first.`, { ref: frame.ref });
|
|
42695
43163
|
const out = await outOf();
|
|
43164
|
+
if (timing !== void 0) {
|
|
43165
|
+
const { images, motion } = await withFrameHost({
|
|
43166
|
+
root,
|
|
43167
|
+
facesDir: context.facesDir
|
|
43168
|
+
}, "capture", (browser, baseUrl) => captureMotionImages(browser, {
|
|
43169
|
+
baseUrl,
|
|
43170
|
+
frame,
|
|
43171
|
+
themes,
|
|
43172
|
+
out,
|
|
43173
|
+
scale: options.scale,
|
|
43174
|
+
timing
|
|
43175
|
+
}));
|
|
43176
|
+
return {
|
|
43177
|
+
data: {
|
|
43178
|
+
images,
|
|
43179
|
+
...motion === null ? {} : { motion }
|
|
43180
|
+
},
|
|
43181
|
+
human: describe$7(images)
|
|
43182
|
+
};
|
|
43183
|
+
}
|
|
42696
43184
|
const images = await withFrameHost({
|
|
42697
43185
|
root,
|
|
42698
43186
|
facesDir: context.facesDir
|
|
@@ -42714,6 +43202,11 @@ function parseScale(value) {
|
|
|
42714
43202
|
if (value !== "1" && value !== "2" && value !== "3") throw new InvalidArgumentError("Expected 1, 2, or 3.");
|
|
42715
43203
|
return Number(value);
|
|
42716
43204
|
}
|
|
43205
|
+
function parseMoments(value) {
|
|
43206
|
+
const moments = value.split(",").map((part) => part.trim());
|
|
43207
|
+
if (!moments.every((part) => /^\d+$/.test(part) && Number.isSafeInteger(Number(part)))) throw new InvalidArgumentError("Expected whole milliseconds, comma separated, such as 0,500,1000.");
|
|
43208
|
+
return [...new Set(moments.map(Number))];
|
|
43209
|
+
}
|
|
42717
43210
|
async function pageOf(root, ref, options) {
|
|
42718
43211
|
const resolved = await resolvePageRef(root, ref, options);
|
|
42719
43212
|
const { pages } = await readPageOrder(join(root, resolved.project));
|
|
@@ -43769,7 +44262,10 @@ const HUG_MAX_WIDTH = FRAME_SIZES.desktop.width;
|
|
|
43769
44262
|
* height of the box's width, never the box's own height, so content sized off
|
|
43770
44263
|
* the window height reads one height however tall the frame already is.
|
|
43771
44264
|
* Readings that differ mean the content sizes itself off the viewport, which
|
|
43772
|
-
* has no height of its own to fit, so that refuses `fit-unbounded`.
|
|
44265
|
+
* has no height of its own to fit, so that refuses `fit-unbounded`. A fresh
|
|
44266
|
+
* page then loads at the width and height it would answer, and content
|
|
44267
|
+
* drawing another height there, as a block sized once off the window height,
|
|
44268
|
+
* refuses the same way. Finite
|
|
43773
44269
|
* animations finish before the first reading, so an entrance is read at its
|
|
43774
44270
|
* settled size.
|
|
43775
44271
|
*/
|
|
@@ -43785,6 +44281,7 @@ async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
|
|
|
43785
44281
|
theme: "light",
|
|
43786
44282
|
fonts
|
|
43787
44283
|
});
|
|
44284
|
+
let size;
|
|
43788
44285
|
try {
|
|
43789
44286
|
const { page } = opened;
|
|
43790
44287
|
await page.evaluate(finishAnimations);
|
|
@@ -43810,7 +44307,7 @@ async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
|
|
|
43810
44307
|
ref,
|
|
43811
44308
|
heights: [short.height, current.height]
|
|
43812
44309
|
});
|
|
43813
|
-
|
|
44310
|
+
size = {
|
|
43814
44311
|
width,
|
|
43815
44312
|
height: short.height,
|
|
43816
44313
|
contentWidth: current.width,
|
|
@@ -43819,6 +44316,39 @@ async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
|
|
|
43819
44316
|
} finally {
|
|
43820
44317
|
await opened.close();
|
|
43821
44318
|
}
|
|
44319
|
+
if (size.empty || size.width === box.width && size.height === reference) return size;
|
|
44320
|
+
const confirmed = await readFreshAt(browser, {
|
|
44321
|
+
baseUrl,
|
|
44322
|
+
ref,
|
|
44323
|
+
box: {
|
|
44324
|
+
width: size.width,
|
|
44325
|
+
height: size.height
|
|
44326
|
+
}
|
|
44327
|
+
});
|
|
44328
|
+
if (confirmed.height !== size.height) throw new FrameboardError("fit-unbounded", `${ref} measures ${size.height} px but draws ${confirmed.height} px when opened at that height, so it sizes itself off the viewport it loads in, as a block set once from innerHeight does, and has no content height to fit. Size it by hand with frame resize, or with frame resize --scroll if it is meant to scroll.`, {
|
|
44329
|
+
ref,
|
|
44330
|
+
heights: [size.height, confirmed.height]
|
|
44331
|
+
});
|
|
44332
|
+
return size;
|
|
44333
|
+
}
|
|
44334
|
+
/**
|
|
44335
|
+
* Reads a frame's content in a page loaded fresh at `box`, animations
|
|
44336
|
+
* finished. It loads under `fonts: 'wait'` whatever the first open took, since
|
|
44337
|
+
* that open already refused a missing face or image, and `require` would wait
|
|
44338
|
+
* out a long entrance a second time on the load budget.
|
|
44339
|
+
*/
|
|
44340
|
+
async function readFreshAt(browser, options) {
|
|
44341
|
+
const opened = await openFrame(browser, {
|
|
44342
|
+
...options,
|
|
44343
|
+
theme: "light",
|
|
44344
|
+
fonts: "wait"
|
|
44345
|
+
});
|
|
44346
|
+
try {
|
|
44347
|
+
await opened.page.evaluate(finishAnimations);
|
|
44348
|
+
return await opened.page.evaluate(readContentSize);
|
|
44349
|
+
} finally {
|
|
44350
|
+
await opened.close();
|
|
44351
|
+
}
|
|
43822
44352
|
}
|
|
43823
44353
|
/**
|
|
43824
44354
|
* Sets a frame's height to its content's own height at its layout width and
|
|
@@ -44791,18 +45321,34 @@ const listResultSchema = object$1({
|
|
|
44791
45321
|
// src/shared/records/capture.ts
|
|
44792
45322
|
const themeSchema$1 = _enum$1(["light", "dark"]);
|
|
44793
45323
|
/** What `capture` returns: every PNG it wrote, one per frame and theme, or one per theme for a composite. */
|
|
44794
|
-
const captureResultSchema = object$1({
|
|
44795
|
-
|
|
44796
|
-
|
|
44797
|
-
|
|
44798
|
-
|
|
44799
|
-
|
|
44800
|
-
|
|
44801
|
-
|
|
44802
|
-
|
|
44803
|
-
|
|
44804
|
-
|
|
44805
|
-
|
|
45324
|
+
const captureResultSchema = object$1({
|
|
45325
|
+
images: array$1(object$1({
|
|
45326
|
+
ref: string$1(),
|
|
45327
|
+
theme: themeSchema$1,
|
|
45328
|
+
path: string$1(),
|
|
45329
|
+
/** The layout box in CSS pixels, whatever the scale. */
|
|
45330
|
+
width: int$1().min(1),
|
|
45331
|
+
height: int$1().min(1),
|
|
45332
|
+
/** Device pixels per CSS pixel, so the file is `width * scale` wide. */
|
|
45333
|
+
scale: int$1().min(1).max(3),
|
|
45334
|
+
/** How far down a `--scroll` shot reached, absent on a shot taken at the top. */
|
|
45335
|
+
scrollY: int$1().min(0).optional(),
|
|
45336
|
+
/** The moment in ms an `--at` shot holds, clamped to the timeline's end. */
|
|
45337
|
+
at: int$1().min(0).optional(),
|
|
45338
|
+
/** The moment in ms each `--filmstrip` frame holds, left to right. */
|
|
45339
|
+
moments: array$1(int$1().min(0)).optional()
|
|
45340
|
+
})),
|
|
45341
|
+
/** The timeline an `--at` or `--filmstrip` capture seeked, absent on any other. */
|
|
45342
|
+
motion: object$1({
|
|
45343
|
+
source: _enum$1([
|
|
45344
|
+
"hf",
|
|
45345
|
+
"timelines",
|
|
45346
|
+
"css"
|
|
45347
|
+
]),
|
|
45348
|
+
/** Its length in ms, or null when every animation repeats forever. */
|
|
45349
|
+
duration: int$1().min(0).nullable()
|
|
45350
|
+
}).optional()
|
|
45351
|
+
});
|
|
44806
45352
|
/** What `frame fit` returns: the frame as resized, the height it measured, and its width against the layout's. */
|
|
44807
45353
|
const fitResultSchema = object$1({
|
|
44808
45354
|
frame: frameRecordSchema,
|
|
@@ -54513,6 +55059,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
54513
55059
|
scanning = run.catch(() => {});
|
|
54514
55060
|
return run;
|
|
54515
55061
|
};
|
|
55062
|
+
let closing;
|
|
54516
55063
|
const findings = createBoardFindings(root, tokens ?? null);
|
|
54517
55064
|
const delivery = createDelivery({
|
|
54518
55065
|
pending: (session) => queuedFor(root, session),
|
|
@@ -54626,6 +55173,10 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
54626
55173
|
browser,
|
|
54627
55174
|
scale: 2
|
|
54628
55175
|
});
|
|
55176
|
+
const renderFilmstrip = createWarmFilmstripRenderer({
|
|
55177
|
+
baseUrl,
|
|
55178
|
+
browser
|
|
55179
|
+
});
|
|
54629
55180
|
const thumbnails = createThumbnailStore({
|
|
54630
55181
|
root,
|
|
54631
55182
|
run: randomUUID().slice(0, 8),
|
|
@@ -54693,6 +55244,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
54693
55244
|
history,
|
|
54694
55245
|
selection,
|
|
54695
55246
|
renderFrame,
|
|
55247
|
+
renderFilmstrip,
|
|
54696
55248
|
clipboard: clipboardFiles(),
|
|
54697
55249
|
thumbnails,
|
|
54698
55250
|
measure,
|
|
@@ -54795,24 +55347,32 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
54795
55347
|
token = next;
|
|
54796
55348
|
},
|
|
54797
55349
|
boardUrl,
|
|
54798
|
-
close:
|
|
54799
|
-
|
|
54800
|
-
|
|
54801
|
-
|
|
54802
|
-
|
|
54803
|
-
|
|
54804
|
-
|
|
54805
|
-
|
|
54806
|
-
|
|
54807
|
-
|
|
54808
|
-
|
|
54809
|
-
|
|
54810
|
-
|
|
54811
|
-
|
|
54812
|
-
|
|
54813
|
-
|
|
54814
|
-
|
|
54815
|
-
|
|
55350
|
+
close: () => {
|
|
55351
|
+
closing ??= (async () => {
|
|
55352
|
+
rendered.close();
|
|
55353
|
+
hug.close();
|
|
55354
|
+
claims.close();
|
|
55355
|
+
for (const [timer, release] of settling) {
|
|
55356
|
+
clearTimeout(timer);
|
|
55357
|
+
release();
|
|
55358
|
+
}
|
|
55359
|
+
await Promise.all([
|
|
55360
|
+
watcher.close(),
|
|
55361
|
+
hub.close(),
|
|
55362
|
+
browser.close(),
|
|
55363
|
+
emptyTrash(root)
|
|
55364
|
+
]);
|
|
55365
|
+
await new Promise((done, fail) => {
|
|
55366
|
+
server.close((error) => error ? fail(error) : done());
|
|
55367
|
+
server.closeAllConnections();
|
|
55368
|
+
});
|
|
55369
|
+
let tail;
|
|
55370
|
+
do {
|
|
55371
|
+
tail = scanning;
|
|
55372
|
+
await tail;
|
|
55373
|
+
} while (tail !== scanning);
|
|
55374
|
+
})();
|
|
55375
|
+
return closing;
|
|
54816
55376
|
}
|
|
54817
55377
|
};
|
|
54818
55378
|
}
|