frameboard 0.29.0 → 0.31.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 +1694 -394
- package/dist/client/assets/index-1aGUdRZT.css +2 -0
- package/dist/client/assets/index-DhTjSlhC.js +114 -0
- package/dist/client/index.html +2 -2
- package/dist/hook.js +8 -3
- package/package.json +1 -1
- package/dist/client/assets/index-8yCp4izw.js +0 -114
- package/dist/client/assets/index-BdhtWf_I.css +0 -2
package/dist/cli.js
CHANGED
|
@@ -3033,6 +3033,7 @@ const EXIT_CODES = {
|
|
|
3033
3033
|
"browser-not-found": 9,
|
|
3034
3034
|
"font-missing": 10,
|
|
3035
3035
|
"fit-unbounded": 10,
|
|
3036
|
+
"fit-scroll": 10,
|
|
3036
3037
|
"capture-too-large": 10,
|
|
3037
3038
|
"frame-locked": 11,
|
|
3038
3039
|
"stale-layout": 11,
|
|
@@ -3054,7 +3055,8 @@ const EXIT_CODES = {
|
|
|
3054
3055
|
"format-refused": 10,
|
|
3055
3056
|
"formatter-not-found": 9,
|
|
3056
3057
|
"references-stale": 14,
|
|
3057
|
-
"page-file-load": 10
|
|
3058
|
+
"page-file-load": 10,
|
|
3059
|
+
"image-missing": 10
|
|
3058
3060
|
};
|
|
3059
3061
|
var FrameboardError = class extends Error {
|
|
3060
3062
|
code;
|
|
@@ -8734,6 +8736,14 @@ function object$1(shape, params) {
|
|
|
8734
8736
|
};
|
|
8735
8737
|
return new ZodObject(def);
|
|
8736
8738
|
}
|
|
8739
|
+
function strictObject(shape, params) {
|
|
8740
|
+
return new ZodObject({
|
|
8741
|
+
type: "object",
|
|
8742
|
+
shape,
|
|
8743
|
+
catchall: never(),
|
|
8744
|
+
...normalizeParams(params)
|
|
8745
|
+
});
|
|
8746
|
+
}
|
|
8737
8747
|
function looseObject(shape, params) {
|
|
8738
8748
|
return new ZodObject({
|
|
8739
8749
|
type: "object",
|
|
@@ -9041,6 +9051,25 @@ const FRAME_SIZES = {
|
|
|
9041
9051
|
}
|
|
9042
9052
|
};
|
|
9043
9053
|
/**
|
|
9054
|
+
* The widths each preset reads as, inclusive, so a 393 phone is a phone. The
|
|
9055
|
+
* preset's own width is the default a preview takes from outside its range.
|
|
9056
|
+
* They sit apart from `FRAME_SIZES`, whose entries spread into a frame's box.
|
|
9057
|
+
*/
|
|
9058
|
+
const PRESET_RANGES = {
|
|
9059
|
+
phone: {
|
|
9060
|
+
min: 320,
|
|
9061
|
+
max: 479
|
|
9062
|
+
},
|
|
9063
|
+
tablet: {
|
|
9064
|
+
min: 480,
|
|
9065
|
+
max: 1023
|
|
9066
|
+
},
|
|
9067
|
+
desktop: {
|
|
9068
|
+
min: 1024,
|
|
9069
|
+
max: Number.POSITIVE_INFINITY
|
|
9070
|
+
}
|
|
9071
|
+
};
|
|
9072
|
+
/**
|
|
9044
9073
|
* The devices the Frame tool and `--size` offer beside the three presets.
|
|
9045
9074
|
* The iPad Pro 11 and a 1440 desktop are the tablet and desktop presets, so
|
|
9046
9075
|
* neither repeats here.
|
|
@@ -9150,6 +9179,78 @@ function frameSizeOf(name) {
|
|
|
9150
9179
|
height
|
|
9151
9180
|
};
|
|
9152
9181
|
}
|
|
9182
|
+
/** The preset whose range holds a width, or none below the phone range. */
|
|
9183
|
+
function presetAt(width) {
|
|
9184
|
+
return Object.keys(PRESET_RANGES).filter(isFrameSizePreset).find((preset) => {
|
|
9185
|
+
const { min, max } = PRESET_RANGES[preset];
|
|
9186
|
+
return width >= min && width <= max;
|
|
9187
|
+
});
|
|
9188
|
+
}
|
|
9189
|
+
/**
|
|
9190
|
+
* The viewport height a frame's content is read at, being the height of the
|
|
9191
|
+
* preset whose range holds the width, or the desktop height below every
|
|
9192
|
+
* range. Reading at the box's own height lets content sized off the viewport
|
|
9193
|
+
* grow by that height on every fit.
|
|
9194
|
+
*/
|
|
9195
|
+
function referenceHeight(width) {
|
|
9196
|
+
return FRAME_SIZES[presetAt(width) ?? "desktop"].height;
|
|
9197
|
+
}
|
|
9198
|
+
// src/shared/frame-widths.ts
|
|
9199
|
+
/**
|
|
9200
|
+
* A layout entry's `widths` value as a clean list. Anything but an array of
|
|
9201
|
+
* objects each holding a positive integer `width` and `height`, with no width
|
|
9202
|
+
* repeated, reads as none, so a value no reader understands never refuses the
|
|
9203
|
+
* page's layout.
|
|
9204
|
+
*/
|
|
9205
|
+
function widthsOf(value) {
|
|
9206
|
+
if (!Array.isArray(value)) return [];
|
|
9207
|
+
const widths = [];
|
|
9208
|
+
for (const item of value) {
|
|
9209
|
+
if (typeof item !== "object" || item === null) return [];
|
|
9210
|
+
const { width, height } = item;
|
|
9211
|
+
if (!isSize(width) || !isSize(height)) return [];
|
|
9212
|
+
if (widths.some((linked) => linked.width === width)) return [];
|
|
9213
|
+
widths.push({
|
|
9214
|
+
width,
|
|
9215
|
+
height
|
|
9216
|
+
});
|
|
9217
|
+
}
|
|
9218
|
+
return widths;
|
|
9219
|
+
}
|
|
9220
|
+
function isSize(value) {
|
|
9221
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 1;
|
|
9222
|
+
}
|
|
9223
|
+
/**
|
|
9224
|
+
* Where each linked width draws: in a row at the frame's `y`, the first
|
|
9225
|
+
* `FRAME_GAP` past the frame's right edge and each next one past the last.
|
|
9226
|
+
*/
|
|
9227
|
+
function linkedBoxes(box, widths) {
|
|
9228
|
+
const boxes = [];
|
|
9229
|
+
let x = box.x + box.width;
|
|
9230
|
+
for (const { width, height } of widths) {
|
|
9231
|
+
x += 80;
|
|
9232
|
+
boxes.push({
|
|
9233
|
+
x,
|
|
9234
|
+
y: box.y,
|
|
9235
|
+
width,
|
|
9236
|
+
height
|
|
9237
|
+
});
|
|
9238
|
+
x += width;
|
|
9239
|
+
}
|
|
9240
|
+
return boxes;
|
|
9241
|
+
}
|
|
9242
|
+
/** The box holding a frame and every linked width it draws, the frame's own with none. */
|
|
9243
|
+
function drawnExtent(box, widths) {
|
|
9244
|
+
const boxes = linkedBoxes(box, widths);
|
|
9245
|
+
const last = boxes.at(-1);
|
|
9246
|
+
if (!last) return { ...box };
|
|
9247
|
+
return {
|
|
9248
|
+
x: box.x,
|
|
9249
|
+
y: box.y,
|
|
9250
|
+
width: last.x + last.width - box.x,
|
|
9251
|
+
height: Math.max(box.height, ...boxes.map(({ height }) => height))
|
|
9252
|
+
};
|
|
9253
|
+
}
|
|
9153
9254
|
// src/shared/records/board.ts
|
|
9154
9255
|
const boardFileSchema = looseObject({ version: literal(1) });
|
|
9155
9256
|
/** A project's own check rules, absent meaning the built-in rules alone. */
|
|
@@ -9157,7 +9258,9 @@ const projectChecksSchema = looseObject({
|
|
|
9157
9258
|
allowedFonts: array$1(string$1()).optional(),
|
|
9158
9259
|
noUppercase: boolean$1().optional(),
|
|
9159
9260
|
/** The smallest text size in pixels the `min-font-size` rule allows. */
|
|
9160
|
-
minFontSize: number().positive().optional()
|
|
9261
|
+
minFontSize: number().positive().optional(),
|
|
9262
|
+
/** The lowest text contrast ratio the `min-contrast` rule allows, 4.5 being WCAG's. */
|
|
9263
|
+
minContrast: number().min(1).optional()
|
|
9161
9264
|
});
|
|
9162
9265
|
const projectFileSchema = looseObject({
|
|
9163
9266
|
version: literal(1),
|
|
@@ -9176,7 +9279,12 @@ const layoutEntrySchema = looseObject({
|
|
|
9176
9279
|
hidden: boolean$1().optional(),
|
|
9177
9280
|
locked: boolean$1().optional(),
|
|
9178
9281
|
hugWidth: boolean$1().optional(),
|
|
9179
|
-
hugHeight: boolean$1().optional()
|
|
9282
|
+
hugHeight: boolean$1().optional(),
|
|
9283
|
+
scroll: boolean$1().optional(),
|
|
9284
|
+
widths: union([array$1(looseObject({
|
|
9285
|
+
width: int$1().min(1),
|
|
9286
|
+
height: int$1().min(1)
|
|
9287
|
+
})), unknown()]).optional()
|
|
9180
9288
|
});
|
|
9181
9289
|
/** A named box grouping the frames whose center it holds, which it never lists. */
|
|
9182
9290
|
const sectionEntrySchema = looseObject({
|
|
@@ -9306,6 +9414,7 @@ function placeFrames(frames, names) {
|
|
|
9306
9414
|
unplaced.push(name);
|
|
9307
9415
|
continue;
|
|
9308
9416
|
}
|
|
9417
|
+
const scroll = entry.scroll ?? false;
|
|
9309
9418
|
placements.set(name, {
|
|
9310
9419
|
box: {
|
|
9311
9420
|
x: entry.x,
|
|
@@ -9316,8 +9425,10 @@ function placeFrames(frames, names) {
|
|
|
9316
9425
|
order: entry.order,
|
|
9317
9426
|
hidden: entry.hidden ?? false,
|
|
9318
9427
|
locked: entry.locked ?? false,
|
|
9319
|
-
hugWidth: entry.hugWidth ?? false,
|
|
9320
|
-
hugHeight: entry.hugHeight ?? false,
|
|
9428
|
+
hugWidth: !scroll && (entry.hugWidth ?? false),
|
|
9429
|
+
hugHeight: !scroll && (entry.hugHeight ?? false),
|
|
9430
|
+
scroll,
|
|
9431
|
+
widths: widthsOf(entry.widths),
|
|
9321
9432
|
placed: true
|
|
9322
9433
|
});
|
|
9323
9434
|
}
|
|
@@ -9331,12 +9442,15 @@ function placeFrames(frames, names) {
|
|
|
9331
9442
|
}
|
|
9332
9443
|
/**
|
|
9333
9444
|
* Where a frame with no layout entry sits: desktop size at `y` 0, 80 past the
|
|
9334
|
-
* right edge of every frame already placed, on top of all of them. The board
|
|
9445
|
+
* right edge of every frame already placed and the linked widths it draws, on top of all of them. The board
|
|
9335
9446
|
* draws what the scanner returns, and `frame add` persists the same box for
|
|
9336
9447
|
* the first unplaced file, placing any other past the placed frames alone.
|
|
9337
9448
|
*/
|
|
9338
9449
|
function placeNext(placed) {
|
|
9339
|
-
const right = Math.max(...placed.map(({ box }) =>
|
|
9450
|
+
const right = Math.max(...placed.map(({ box, widths }) => {
|
|
9451
|
+
const extent = drawnExtent(box, widths);
|
|
9452
|
+
return extent.x + extent.width + 80;
|
|
9453
|
+
}), 0);
|
|
9340
9454
|
const order = Math.max(...placed.map((placement) => placement.order + 1), 0);
|
|
9341
9455
|
return {
|
|
9342
9456
|
box: {
|
|
@@ -9349,6 +9463,8 @@ function placeNext(placed) {
|
|
|
9349
9463
|
locked: false,
|
|
9350
9464
|
hugWidth: false,
|
|
9351
9465
|
hugHeight: false,
|
|
9466
|
+
scroll: false,
|
|
9467
|
+
widths: [],
|
|
9352
9468
|
placed: false
|
|
9353
9469
|
};
|
|
9354
9470
|
}
|
|
@@ -9517,7 +9633,7 @@ async function isDirectory(path) {
|
|
|
9517
9633
|
}
|
|
9518
9634
|
}
|
|
9519
9635
|
// package.json
|
|
9520
|
-
var version$1 = "0.
|
|
9636
|
+
var version$1 = "0.31.0";
|
|
9521
9637
|
var dependencies = { "playwright-core": "1.65.0" };
|
|
9522
9638
|
var peerDependencies = { "oxfmt": "0.77.0" };
|
|
9523
9639
|
// src/shared/version.ts
|
|
@@ -9646,6 +9762,205 @@ function nextFreeName(base, taken) {
|
|
|
9646
9762
|
if (!lowered.has(candidate.toLowerCase())) return candidate;
|
|
9647
9763
|
}
|
|
9648
9764
|
}
|
|
9765
|
+
// src/shared/records/claims.ts
|
|
9766
|
+
/**
|
|
9767
|
+
* Where a reserved frame will land, and which axes take their size from the
|
|
9768
|
+
* content once it does, as `frame add` would place it.
|
|
9769
|
+
*/
|
|
9770
|
+
const claimBoxSchema = object$1({
|
|
9771
|
+
x: number(),
|
|
9772
|
+
y: number(),
|
|
9773
|
+
width: number(),
|
|
9774
|
+
height: number(),
|
|
9775
|
+
hugWidth: boolean$1().optional(),
|
|
9776
|
+
hugHeight: boolean$1().optional()
|
|
9777
|
+
});
|
|
9778
|
+
/** One session's hold on a frame while its agent rewrites it. */
|
|
9779
|
+
const claimSchema = looseObject({
|
|
9780
|
+
/** The canonical frame ref, `<project>/<page>/<frame>`. */
|
|
9781
|
+
frame: string$1(),
|
|
9782
|
+
/** The session holding it, the id `inbox` and a note's `to` use. */
|
|
9783
|
+
session: string$1(),
|
|
9784
|
+
/** The agent's name, such as `claude`, whose first letter the board shows. */
|
|
9785
|
+
agent: string$1(),
|
|
9786
|
+
/** The listener's tag form, `<agent> · <project folder>`. */
|
|
9787
|
+
tag: string$1(),
|
|
9788
|
+
/** When the session first claimed it, kept across renewals. */
|
|
9789
|
+
claimedAt: string$1(),
|
|
9790
|
+
/** When it lapses unless the session claims it again. */
|
|
9791
|
+
expiresAt: string$1(),
|
|
9792
|
+
/** A reservation's box, held until the frame's file lands in the layout. */
|
|
9793
|
+
box: claimBoxSchema.optional(),
|
|
9794
|
+
/** The id one `editing --new` call stamps on each frame it reserves, which renew together. */
|
|
9795
|
+
set: string$1().optional(),
|
|
9796
|
+
/** When the session last claimed a reserved frame plainly, so the latest in a set reads as drawing. */
|
|
9797
|
+
drawingAt: string$1().optional()
|
|
9798
|
+
});
|
|
9799
|
+
/**
|
|
9800
|
+
* Whether a write naming `ref` reaches the frame a claim holds, being the
|
|
9801
|
+
* frame itself, its page, or its project, so a page ref never matches a
|
|
9802
|
+
* sibling page whose name only starts the same.
|
|
9803
|
+
*/
|
|
9804
|
+
function claimCovers(ref, frame) {
|
|
9805
|
+
return frame === ref || frame.startsWith(`${ref}/`);
|
|
9806
|
+
}
|
|
9807
|
+
/** `.run/claims.json`. */
|
|
9808
|
+
const claimsFileSchema = looseObject({
|
|
9809
|
+
version: literal(1),
|
|
9810
|
+
claims: array$1(claimSchema)
|
|
9811
|
+
});
|
|
9812
|
+
// src/server/claims/store.ts
|
|
9813
|
+
/** How long a claim holds after its last claim or renewal. */
|
|
9814
|
+
const CLAIM_TTL_MS = 3e5;
|
|
9815
|
+
const claimsSpec = {
|
|
9816
|
+
schema: claimsFileSchema,
|
|
9817
|
+
invalidCode: "claims-invalid",
|
|
9818
|
+
empty: () => ({
|
|
9819
|
+
version: 1,
|
|
9820
|
+
claims: []
|
|
9821
|
+
})
|
|
9822
|
+
};
|
|
9823
|
+
function claimsPath(root) {
|
|
9824
|
+
return join(root, RUN_FOLDER, CLAIMS_FILE);
|
|
9825
|
+
}
|
|
9826
|
+
function claimedError(holder, frame) {
|
|
9827
|
+
return new FrameboardError("frame-claimed", `${holder.tag} is editing ${frame} until ${holder.expiresAt}.`, {
|
|
9828
|
+
frame: holder.frame,
|
|
9829
|
+
session: holder.session,
|
|
9830
|
+
tag: holder.tag,
|
|
9831
|
+
expiresAt: holder.expiresAt
|
|
9832
|
+
});
|
|
9833
|
+
}
|
|
9834
|
+
function isLive(claim, now) {
|
|
9835
|
+
return Date.parse(claim.expiresAt) > now.getTime();
|
|
9836
|
+
}
|
|
9837
|
+
/** The claims still live at `now`, refusing a file that does not parse. */
|
|
9838
|
+
async function readClaims(root, now) {
|
|
9839
|
+
return (await readRecord(claimsPath(root), claimsSpec)).claims.filter((claim) => isLive(claim, now));
|
|
9840
|
+
}
|
|
9841
|
+
/**
|
|
9842
|
+
* The box a live reservation holds for a frame, else undefined, a claims
|
|
9843
|
+
* file that does not parse reading as holding none.
|
|
9844
|
+
*/
|
|
9845
|
+
async function reservedBox(root, frame, now = /* @__PURE__ */ new Date()) {
|
|
9846
|
+
try {
|
|
9847
|
+
return (await readClaims(root, now)).find((each) => each.frame === frame && each.box)?.box;
|
|
9848
|
+
} catch (error) {
|
|
9849
|
+
if (error instanceof FrameboardError) return void 0;
|
|
9850
|
+
throw error;
|
|
9851
|
+
}
|
|
9852
|
+
}
|
|
9853
|
+
/**
|
|
9854
|
+
* Claims a frame for a session, or renews the session's own claim keeping
|
|
9855
|
+
* `claimedAt`. A frame another session holds live refuses `frame-claimed`.
|
|
9856
|
+
*/
|
|
9857
|
+
async function claim(root, fields, now) {
|
|
9858
|
+
await ensureRunFolder(root);
|
|
9859
|
+
return (await updateRecord(claimsPath(root), claimsSpec, (file) => {
|
|
9860
|
+
const live = file.claims.filter((each) => isLive(each, now));
|
|
9861
|
+
const current = live.find((each) => each.frame === fields.frame);
|
|
9862
|
+
if (current && current.session !== fields.session) throw claimedError(current, fields.frame);
|
|
9863
|
+
const expiresAt = new Date(now.getTime() + CLAIM_TTL_MS).toISOString();
|
|
9864
|
+
const held = {
|
|
9865
|
+
...fields,
|
|
9866
|
+
...setOf(current),
|
|
9867
|
+
claimedAt: current?.claimedAt ?? now.toISOString(),
|
|
9868
|
+
expiresAt,
|
|
9869
|
+
...current?.box ? { drawingAt: now.toISOString() } : {}
|
|
9870
|
+
};
|
|
9871
|
+
const set = current?.set;
|
|
9872
|
+
const renewed = live.map((each) => {
|
|
9873
|
+
if (each === current) return held;
|
|
9874
|
+
return set !== void 0 && each.set === set && each.session === fields.session ? {
|
|
9875
|
+
...each,
|
|
9876
|
+
expiresAt
|
|
9877
|
+
} : each;
|
|
9878
|
+
});
|
|
9879
|
+
return {
|
|
9880
|
+
...file,
|
|
9881
|
+
claims: current ? renewed : [...renewed, held]
|
|
9882
|
+
};
|
|
9883
|
+
})).claims.find((each) => each.frame === fields.frame);
|
|
9884
|
+
}
|
|
9885
|
+
/** The reservation a renewal carries over from the claim it renews. */
|
|
9886
|
+
function setOf(current) {
|
|
9887
|
+
if (!current) return {};
|
|
9888
|
+
const { box, set, drawingAt } = current;
|
|
9889
|
+
return {
|
|
9890
|
+
...box ? { box } : {},
|
|
9891
|
+
...set === void 0 ? {} : { set },
|
|
9892
|
+
...drawingAt === void 0 ? {} : { drawingAt }
|
|
9893
|
+
};
|
|
9894
|
+
}
|
|
9895
|
+
/**
|
|
9896
|
+
* Reserves every frame named as one set, each a claim carrying its box and
|
|
9897
|
+
* the set's id, in one write. A frame another session holds live refuses
|
|
9898
|
+
* `frame-claimed` before any is written, and the session's own claim on a
|
|
9899
|
+
* named frame is replaced.
|
|
9900
|
+
*/
|
|
9901
|
+
async function reserve(root, holder, reservations, now) {
|
|
9902
|
+
await ensureRunFolder(root);
|
|
9903
|
+
const set = randomUUID();
|
|
9904
|
+
const claimedAt = now.toISOString();
|
|
9905
|
+
const expiresAt = new Date(now.getTime() + CLAIM_TTL_MS).toISOString();
|
|
9906
|
+
const made = reservations.map(({ frame, box }) => ({
|
|
9907
|
+
frame,
|
|
9908
|
+
...holder,
|
|
9909
|
+
claimedAt,
|
|
9910
|
+
expiresAt,
|
|
9911
|
+
box,
|
|
9912
|
+
set
|
|
9913
|
+
}));
|
|
9914
|
+
const names = new Set(made.map((each) => each.frame));
|
|
9915
|
+
await updateRecord(claimsPath(root), claimsSpec, (file) => {
|
|
9916
|
+
const live = file.claims.filter((each) => isLive(each, now));
|
|
9917
|
+
const taken = live.find((each) => names.has(each.frame) && each.session !== holder.session);
|
|
9918
|
+
if (taken) throw claimedError(taken, taken.frame);
|
|
9919
|
+
return {
|
|
9920
|
+
...file,
|
|
9921
|
+
claims: [...live.filter((each) => !names.has(each.frame)), ...made]
|
|
9922
|
+
};
|
|
9923
|
+
});
|
|
9924
|
+
return made;
|
|
9925
|
+
}
|
|
9926
|
+
/**
|
|
9927
|
+
* Drops the live reservation on a frame whoever holds it, refusing a claim
|
|
9928
|
+
* with no box so an agent's claim on an existing frame is never broken.
|
|
9929
|
+
* Answers the dropped claim, or undefined when the frame holds none.
|
|
9930
|
+
*/
|
|
9931
|
+
async function releaseReservation(root, frame, now) {
|
|
9932
|
+
let dropped;
|
|
9933
|
+
await ensureRunFolder(root);
|
|
9934
|
+
await updateRecord(claimsPath(root), claimsSpec, (file) => {
|
|
9935
|
+
const live = file.claims.filter((each) => isLive(each, now));
|
|
9936
|
+
dropped = live.find((each) => each.frame === frame && each.box);
|
|
9937
|
+
return {
|
|
9938
|
+
...file,
|
|
9939
|
+
claims: live.filter((each) => each !== dropped)
|
|
9940
|
+
};
|
|
9941
|
+
});
|
|
9942
|
+
return dropped;
|
|
9943
|
+
}
|
|
9944
|
+
/**
|
|
9945
|
+
* Drops a session's claim on one frame, or every claim it holds when no
|
|
9946
|
+
* frame is named, returning what it dropped.
|
|
9947
|
+
*/
|
|
9948
|
+
async function release$1(root, session, frame, now) {
|
|
9949
|
+
const dropped = [];
|
|
9950
|
+
await ensureRunFolder(root);
|
|
9951
|
+
await updateRecord(claimsPath(root), claimsSpec, (file) => {
|
|
9952
|
+
const kept = [];
|
|
9953
|
+
for (const each of file.claims) {
|
|
9954
|
+
if (!isLive(each, now)) continue;
|
|
9955
|
+
(each.session === session && (frame === void 0 || each.frame === frame) ? dropped : kept).push(each);
|
|
9956
|
+
}
|
|
9957
|
+
return {
|
|
9958
|
+
...file,
|
|
9959
|
+
claims: kept
|
|
9960
|
+
};
|
|
9961
|
+
});
|
|
9962
|
+
return dropped;
|
|
9963
|
+
}
|
|
9649
9964
|
// src/server/board/refs.ts
|
|
9650
9965
|
/**
|
|
9651
9966
|
* The project a verb acts on: the one named, else the board's only project.
|
|
@@ -9778,7 +10093,8 @@ async function framePathParts(root, ref, cwd) {
|
|
|
9778
10093
|
* as `placeNext` puts it, ignoring the page's other unplaced files, unless a
|
|
9779
10094
|
* size or position is given. Every axis no size names hugs its
|
|
9780
10095
|
* content, a preset fixing the width alone, and the box stands in until the
|
|
9781
|
-
* server measures.
|
|
10096
|
+
* server measures. A scroll frame hugs neither axis, and with no height named
|
|
10097
|
+
* takes the reference height of its width.
|
|
9782
10098
|
*/
|
|
9783
10099
|
async function addFrame(root, ref, options) {
|
|
9784
10100
|
const { journal } = options;
|
|
@@ -9786,16 +10102,35 @@ async function addFrame(root, ref, options) {
|
|
|
9786
10102
|
...options,
|
|
9787
10103
|
allowMissing: true
|
|
9788
10104
|
});
|
|
9789
|
-
const size = sizeOf(options);
|
|
9790
10105
|
const page = pageDir(frame);
|
|
10106
|
+
const reserved = options.x === void 0 && options.y === void 0 ? await reservedBox(root, refOf$1(frame)) : void 0;
|
|
10107
|
+
const sized = options.size !== void 0 || options.width !== void 0 || options.height !== void 0;
|
|
10108
|
+
const size = reserved && !sized ? {
|
|
10109
|
+
width: reserved.width,
|
|
10110
|
+
height: reserved.height
|
|
10111
|
+
} : sizeOf(options);
|
|
10112
|
+
const scroll = options.scroll ?? false;
|
|
10113
|
+
const hugs = scroll ? {
|
|
10114
|
+
hugWidth: false,
|
|
10115
|
+
hugHeight: false
|
|
10116
|
+
} : reserved && !sized ? {
|
|
10117
|
+
hugWidth: reserved.hugWidth ?? false,
|
|
10118
|
+
hugHeight: reserved.hugHeight ?? false
|
|
10119
|
+
} : hugsOf(options);
|
|
9791
10120
|
await withLayouts([page], async (layouts) => {
|
|
9792
10121
|
const layout = layoutAt(layouts, page);
|
|
9793
10122
|
const exists = existsSync(frame.path);
|
|
9794
|
-
if (exists && layout.hasEntry(frame.name)) throw new FrameboardError("name-taken", `${frame.project}/${frame.page}/${frame.name} is already a placed frame.`, { ref: refOf(frame) });
|
|
10123
|
+
if (exists && layout.hasEntry(frame.name)) throw new FrameboardError("name-taken", `${frame.project}/${frame.page}/${frame.name} is already a placed frame.`, { ref: refOf$1(frame) });
|
|
9795
10124
|
const names = exists ? layout.names : [...layout.names, frame.name].sort();
|
|
9796
10125
|
const slot = names.filter((name) => name === frame.name || layout.hasEntry(name));
|
|
9797
10126
|
const computed = placeFrames(layout.file.frames, slot).get(frame.name);
|
|
9798
10127
|
if (!computed) throw new Error(`No placement computed for ${frame.name}.`);
|
|
10128
|
+
const width = size.width ?? computed.box.width;
|
|
10129
|
+
const widths = linkedWidths(refOf$1(frame), options.widths, {
|
|
10130
|
+
width,
|
|
10131
|
+
hugWidth: hugs.hugWidth,
|
|
10132
|
+
held: []
|
|
10133
|
+
});
|
|
9799
10134
|
if (!exists) {
|
|
9800
10135
|
await writeFile(frame.path, skeleton(frame.name), { flag: "wx" });
|
|
9801
10136
|
await journal?.created(frame.path);
|
|
@@ -9806,10 +10141,13 @@ async function addFrame(root, ref, options) {
|
|
|
9806
10141
|
box: {
|
|
9807
10142
|
...computed.box,
|
|
9808
10143
|
...size,
|
|
9809
|
-
|
|
9810
|
-
|
|
10144
|
+
...scroll && size.height === void 0 ? { height: referenceHeight(width) } : {},
|
|
10145
|
+
x: options.x ?? reserved?.x ?? computed.box.x,
|
|
10146
|
+
y: options.y ?? reserved?.y ?? computed.box.y
|
|
9811
10147
|
},
|
|
9812
|
-
...
|
|
10148
|
+
...hugs,
|
|
10149
|
+
scroll,
|
|
10150
|
+
widths
|
|
9813
10151
|
});
|
|
9814
10152
|
layout.renumber();
|
|
9815
10153
|
}, journal);
|
|
@@ -9837,7 +10175,7 @@ async function duplicateFrame(root, ref, { to, name, offset, journal, ...options
|
|
|
9837
10175
|
y: placement.box.y + offset.y
|
|
9838
10176
|
} : into === from ? {
|
|
9839
10177
|
...placement.box,
|
|
9840
|
-
x: placement
|
|
10178
|
+
x: pastExtent(placement)
|
|
9841
10179
|
} : placement.box;
|
|
9842
10180
|
const copyPath = join(into, `${copyName}${FRAME_EXTENSION}`);
|
|
9843
10181
|
await copyFile(source.path, copyPath, constants.COPYFILE_EXCL);
|
|
@@ -9910,32 +10248,100 @@ async function renameFrame(root, ref, newName, options) {
|
|
|
9910
10248
|
name: newName
|
|
9911
10249
|
});
|
|
9912
10250
|
}
|
|
10251
|
+
/**
|
|
10252
|
+
* Sets the size each option names and fixes those axes. `scroll` on fixes
|
|
10253
|
+
* both, dropping a hugging height no option names to the reference height of
|
|
10254
|
+
* the width, since a frame kept at its content's full height has nothing to
|
|
10255
|
+
* scroll. `scroll` off clears the key and keeps the box as it stands.
|
|
10256
|
+
*/
|
|
9913
10257
|
async function resizeFrame(root, ref, options) {
|
|
9914
10258
|
const size = sizeOf(options);
|
|
9915
|
-
if (Object.keys(size).length === 0) throw new FrameboardError("usage", "Pass --size, --width, or --
|
|
9916
|
-
return updatePlacement(root, ref, options, (placement) =>
|
|
9917
|
-
|
|
9918
|
-
box
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
|
|
9922
|
-
|
|
9923
|
-
|
|
10259
|
+
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
|
+
const scroll = options.scroll ?? placement.scroll;
|
|
10262
|
+
const width = size.width ?? placement.box.width;
|
|
10263
|
+
const drops = scroll && placement.hugHeight && size.height === void 0;
|
|
10264
|
+
const hugWidth = !scroll && placement.hugWidth && size.width === void 0;
|
|
10265
|
+
const widths = linkedWidths(frameRef, options.widths ?? placement.widths.map((linked) => linked.width), {
|
|
10266
|
+
width,
|
|
10267
|
+
hugWidth,
|
|
10268
|
+
held: placement.widths
|
|
10269
|
+
});
|
|
10270
|
+
return {
|
|
10271
|
+
...placement,
|
|
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
|
+
};
|
|
10285
|
+
});
|
|
10286
|
+
}
|
|
10287
|
+
/**
|
|
10288
|
+
* The linked widths a verb writes, keeping the height each one already held
|
|
10289
|
+
* and giving a new one the reference height of its width, which a hugging
|
|
10290
|
+
* frame's measure replaces. A repeated width, the frame's own width, or a
|
|
10291
|
+
* frame hugging its width refuses `usage`.
|
|
10292
|
+
*/
|
|
10293
|
+
function linkedWidths(ref, requested, { width, hugWidth, held }) {
|
|
10294
|
+
if (!requested || requested.length === 0) return [];
|
|
10295
|
+
if (hugWidth) throw new FrameboardError("usage", `${ref} hugs its width, so it has no width to show beside others. Fix it with --size or --width first.`, {
|
|
10296
|
+
ref,
|
|
10297
|
+
widths: requested
|
|
10298
|
+
});
|
|
10299
|
+
const repeated = requested.find((linked, index) => requested.indexOf(linked) !== index);
|
|
10300
|
+
if (repeated !== void 0) throw new FrameboardError("usage", `--widths lists ${repeated} twice, so pass each width once.`, {
|
|
10301
|
+
ref,
|
|
10302
|
+
widths: requested
|
|
10303
|
+
});
|
|
10304
|
+
if (requested.includes(width)) throw new FrameboardError("usage", `${ref} is ${width} px wide already, so --widths lists the other widths alone.`, {
|
|
10305
|
+
ref,
|
|
10306
|
+
width,
|
|
10307
|
+
widths: requested
|
|
10308
|
+
});
|
|
10309
|
+
return requested.map((linked) => ({
|
|
10310
|
+
width: linked,
|
|
10311
|
+
height: held.find((each) => each.width === linked)?.height ?? referenceHeight(linked)
|
|
9924
10312
|
}));
|
|
9925
10313
|
}
|
|
10314
|
+
/** The x a copy placed beside a frame takes, past the row of linked widths it draws. */
|
|
10315
|
+
function pastExtent({ box, widths }) {
|
|
10316
|
+
const extent = drawnExtent(box, widths);
|
|
10317
|
+
return extent.x + extent.width + 80;
|
|
10318
|
+
}
|
|
9926
10319
|
/**
|
|
9927
10320
|
* Sets a frame's height to its content's measured height and turns hugging
|
|
9928
|
-
* back on for that axis, the inverse of the resize that fixed it
|
|
10321
|
+
* back on for that axis, the inverse of the resize that fixed it, writing
|
|
10322
|
+
* each linked width's measured height beside it while the entry lists it. A
|
|
10323
|
+
* scroll frame refuses `fit-scroll`, since its height is fixed on purpose.
|
|
9929
10324
|
*/
|
|
9930
10325
|
async function fitHeight(root, ref, height, options) {
|
|
9931
|
-
return updatePlacement(root, ref, options, (placement) =>
|
|
9932
|
-
|
|
9933
|
-
|
|
9934
|
-
...placement
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
9938
|
-
|
|
10326
|
+
return updatePlacement(root, ref, options, (placement) => {
|
|
10327
|
+
if (placement.scroll) throw fitScrollError(ref);
|
|
10328
|
+
return {
|
|
10329
|
+
...placement,
|
|
10330
|
+
box: {
|
|
10331
|
+
...placement.box,
|
|
10332
|
+
height
|
|
10333
|
+
},
|
|
10334
|
+
hugHeight: true,
|
|
10335
|
+
widths: placement.widths.map((linked) => ({
|
|
10336
|
+
...linked,
|
|
10337
|
+
height: options.widths?.find((each) => each.width === linked.width)?.height ?? linked.height
|
|
10338
|
+
}))
|
|
10339
|
+
};
|
|
10340
|
+
});
|
|
10341
|
+
}
|
|
10342
|
+
/** The refusal a fit of a scroll frame answers, before or after measuring. */
|
|
10343
|
+
function fitScrollError(ref) {
|
|
10344
|
+
return new FrameboardError("fit-scroll", `${ref} holds scroll, which fixes its height so the page scrolls past it, so it has no height to fit. Clear it with frame resize --no-scroll first.`, { ref });
|
|
9939
10345
|
}
|
|
9940
10346
|
/**
|
|
9941
10347
|
* Writes the sizes the server measured, on the axes each frame's stored entry
|
|
@@ -9953,13 +10359,18 @@ async function setMeasured(root, pageRef, sizes, options) {
|
|
|
9953
10359
|
const placement = layout.placement(name);
|
|
9954
10360
|
const box = {
|
|
9955
10361
|
...placement.box,
|
|
9956
|
-
width: placement.hugWidth ? size.width : placement.box.width,
|
|
9957
|
-
height: placement.hugHeight ? size.height : placement.box.height
|
|
10362
|
+
width: placement.hugWidth && size.width !== void 0 ? size.width : placement.box.width,
|
|
10363
|
+
height: placement.hugHeight && size.height !== void 0 ? size.height : placement.box.height
|
|
9958
10364
|
};
|
|
9959
|
-
|
|
10365
|
+
const widths = placement.widths.map((linked) => ({
|
|
10366
|
+
...linked,
|
|
10367
|
+
height: placement.hugHeight ? size.widths?.find((each) => each.width === linked.width)?.height ?? linked.height : linked.height
|
|
10368
|
+
}));
|
|
10369
|
+
if (sameBox(box, placement.box) && isDeepStrictEqual(widths, placement.widths)) continue;
|
|
9960
10370
|
layout.set(name, {
|
|
9961
10371
|
...placement,
|
|
9962
|
-
box
|
|
10372
|
+
box,
|
|
10373
|
+
widths
|
|
9963
10374
|
});
|
|
9964
10375
|
written.push(name);
|
|
9965
10376
|
}
|
|
@@ -10036,7 +10447,8 @@ async function setBoxes(root, pageRef, boxes, expected, options) {
|
|
|
10036
10447
|
...kept
|
|
10037
10448
|
},
|
|
10038
10449
|
hugWidth: placement.hugWidth && box.width === started.width,
|
|
10039
|
-
hugHeight: placement.hugHeight && box.height === started.height
|
|
10450
|
+
hugHeight: placement.hugHeight && box.height === started.height,
|
|
10451
|
+
widths: placement.widths.filter((linked) => linked.width !== (kept.width ?? box.width))
|
|
10040
10452
|
});
|
|
10041
10453
|
}
|
|
10042
10454
|
}, options.journal);
|
|
@@ -10096,18 +10508,19 @@ async function deleteFrame(root, ref, options) {
|
|
|
10096
10508
|
else await rm(frame.path);
|
|
10097
10509
|
layout.remove(frame.name);
|
|
10098
10510
|
}, journal);
|
|
10099
|
-
return { deleted: refOf(frame) };
|
|
10511
|
+
return { deleted: refOf$1(frame) };
|
|
10100
10512
|
}
|
|
10101
10513
|
async function updatePlacement(root, ref, options, change) {
|
|
10102
10514
|
const frame = await resolveFrameRef(root, ref, options);
|
|
10103
10515
|
const page = pageDir(frame);
|
|
10104
10516
|
await withLayouts([page], async (layouts) => {
|
|
10105
10517
|
const layout = layoutAt(layouts, page);
|
|
10106
|
-
layout.set(frame.name, change(layout.placement(frame.name)));
|
|
10518
|
+
layout.set(frame.name, change(layout.placement(frame.name), refOf$1(frame)));
|
|
10107
10519
|
}, options.journal);
|
|
10108
10520
|
return frameRecord(root, frame.project, frame.page, frame.name);
|
|
10109
10521
|
}
|
|
10110
10522
|
/** Which axes `frame add` leaves hugging: every one no size option names, the height under a preset. */
|
|
10523
|
+
/** Which axes a frame placed with these options sizes from its content. */
|
|
10111
10524
|
function hugsOf({ size, width, height }) {
|
|
10112
10525
|
return {
|
|
10113
10526
|
hugWidth: size === void 0 && width === void 0,
|
|
@@ -10174,11 +10587,17 @@ var PageLayout = class {
|
|
|
10174
10587
|
* Writes the seven fixed keys on the entry it creates or changes, after any
|
|
10175
10588
|
* key the entry already held, so unknown keys survive in place. A hug flag
|
|
10176
10589
|
* is written on an entry it creates, once it is on, or when the entry holds
|
|
10177
|
-
* it, so a write to an entry from before the flags adds no key.
|
|
10178
|
-
|
|
10179
|
-
|
|
10590
|
+
* it, so a write to an entry from before the flags adds no key. `scroll` is
|
|
10591
|
+
* written once it is on or when the entry holds it, and a scroll entry
|
|
10592
|
+
* writes both hug flags false, since it fixes both axes. `widths` is
|
|
10593
|
+
* written while it lists one and removed once it lists none, and a held
|
|
10594
|
+
* value no reader understands is left as it stands.
|
|
10595
|
+
*/
|
|
10596
|
+
set(name, { box, order, hidden, locked, scroll, widths, hugWidth: hugsWidth, hugHeight: hugsHeight }) {
|
|
10597
|
+
const hugWidth = hugsWidth && !scroll;
|
|
10598
|
+
const hugHeight = hugsHeight && !scroll;
|
|
10180
10599
|
const held = this.file.frames[name];
|
|
10181
|
-
|
|
10600
|
+
const entry = {
|
|
10182
10601
|
...held,
|
|
10183
10602
|
x: box.x,
|
|
10184
10603
|
y: box.y,
|
|
@@ -10188,8 +10607,15 @@ var PageLayout = class {
|
|
|
10188
10607
|
hidden,
|
|
10189
10608
|
locked,
|
|
10190
10609
|
...!held || hugWidth || held.hugWidth !== void 0 ? { hugWidth } : {},
|
|
10191
|
-
...!held || hugHeight || held.hugHeight !== void 0 ? { hugHeight } : {}
|
|
10192
|
-
|
|
10610
|
+
...!held || hugHeight || held.hugHeight !== void 0 ? { hugHeight } : {},
|
|
10611
|
+
...scroll || held?.scroll !== void 0 ? { scroll } : {},
|
|
10612
|
+
...widths.length > 0 ? { widths: widths.map(({ width, height }) => ({
|
|
10613
|
+
width,
|
|
10614
|
+
height
|
|
10615
|
+
})) } : {}
|
|
10616
|
+
};
|
|
10617
|
+
if (widths.length === 0 && widthsOf(held?.widths).length > 0) delete entry.widths;
|
|
10618
|
+
this.file.frames[name] = entry;
|
|
10193
10619
|
this.changed = true;
|
|
10194
10620
|
}
|
|
10195
10621
|
remove(name) {
|
|
@@ -10309,7 +10735,7 @@ async function frameRecords(root, project, page) {
|
|
|
10309
10735
|
function pageDir(frame) {
|
|
10310
10736
|
return join(frame.root, frame.project, frame.page);
|
|
10311
10737
|
}
|
|
10312
|
-
function refOf(frame) {
|
|
10738
|
+
function refOf$1(frame) {
|
|
10313
10739
|
return `${frame.project}/${frame.page}/${frame.name}`;
|
|
10314
10740
|
}
|
|
10315
10741
|
// node_modules/@hono/node-server/dist/index.mjs
|
|
@@ -22146,102 +22572,6 @@ function framesNamed(root, paths) {
|
|
|
22146
22572
|
}
|
|
22147
22573
|
return refs;
|
|
22148
22574
|
}
|
|
22149
|
-
// src/shared/records/claims.ts
|
|
22150
|
-
/** One session's hold on a frame while its agent rewrites it. */
|
|
22151
|
-
const claimSchema = looseObject({
|
|
22152
|
-
/** The canonical frame ref, `<project>/<page>/<frame>`. */
|
|
22153
|
-
frame: string$1(),
|
|
22154
|
-
/** The session holding it, the id `inbox` and a note's `to` use. */
|
|
22155
|
-
session: string$1(),
|
|
22156
|
-
/** The agent's name, such as `claude`, whose first letter the board shows. */
|
|
22157
|
-
agent: string$1(),
|
|
22158
|
-
/** The listener's tag form, `<agent> · <project folder>`. */
|
|
22159
|
-
tag: string$1(),
|
|
22160
|
-
/** When the session first claimed it, kept across renewals. */
|
|
22161
|
-
claimedAt: string$1(),
|
|
22162
|
-
/** When it lapses unless the session claims it again. */
|
|
22163
|
-
expiresAt: string$1()
|
|
22164
|
-
});
|
|
22165
|
-
/**
|
|
22166
|
-
* Whether a write naming `ref` reaches the frame a claim holds, being the
|
|
22167
|
-
* frame itself, its page, or its project, so a page ref never matches a
|
|
22168
|
-
* sibling page whose name only starts the same.
|
|
22169
|
-
*/
|
|
22170
|
-
function claimCovers(ref, frame) {
|
|
22171
|
-
return frame === ref || frame.startsWith(`${ref}/`);
|
|
22172
|
-
}
|
|
22173
|
-
/** `.run/claims.json`. */
|
|
22174
|
-
const claimsFileSchema = looseObject({
|
|
22175
|
-
version: literal(1),
|
|
22176
|
-
claims: array$1(claimSchema)
|
|
22177
|
-
});
|
|
22178
|
-
// src/server/claims/store.ts
|
|
22179
|
-
/** How long a claim holds after its last claim or renewal. */
|
|
22180
|
-
const CLAIM_TTL_MS = 3e5;
|
|
22181
|
-
const claimsSpec = {
|
|
22182
|
-
schema: claimsFileSchema,
|
|
22183
|
-
invalidCode: "claims-invalid",
|
|
22184
|
-
empty: () => ({
|
|
22185
|
-
version: 1,
|
|
22186
|
-
claims: []
|
|
22187
|
-
})
|
|
22188
|
-
};
|
|
22189
|
-
function claimsPath(root) {
|
|
22190
|
-
return join(root, RUN_FOLDER, CLAIMS_FILE);
|
|
22191
|
-
}
|
|
22192
|
-
function isLive(claim, now) {
|
|
22193
|
-
return Date.parse(claim.expiresAt) > now.getTime();
|
|
22194
|
-
}
|
|
22195
|
-
/** The claims still live at `now`, refusing a file that does not parse. */
|
|
22196
|
-
async function readClaims(root, now) {
|
|
22197
|
-
return (await readRecord(claimsPath(root), claimsSpec)).claims.filter((claim) => isLive(claim, now));
|
|
22198
|
-
}
|
|
22199
|
-
/**
|
|
22200
|
-
* Claims a frame for a session, or renews the session's own claim keeping
|
|
22201
|
-
* `claimedAt`. A frame another session holds live refuses `frame-claimed`.
|
|
22202
|
-
*/
|
|
22203
|
-
async function claim(root, fields, now) {
|
|
22204
|
-
await ensureRunFolder(root);
|
|
22205
|
-
return (await updateRecord(claimsPath(root), claimsSpec, (file) => {
|
|
22206
|
-
const live = file.claims.filter((each) => isLive(each, now));
|
|
22207
|
-
const current = live.find((each) => each.frame === fields.frame);
|
|
22208
|
-
if (current && current.session !== fields.session) throw new FrameboardError("frame-claimed", `${current.tag} is editing ${fields.frame} until ${current.expiresAt}.`, {
|
|
22209
|
-
frame: current.frame,
|
|
22210
|
-
session: current.session,
|
|
22211
|
-
tag: current.tag,
|
|
22212
|
-
expiresAt: current.expiresAt
|
|
22213
|
-
});
|
|
22214
|
-
const held = {
|
|
22215
|
-
...fields,
|
|
22216
|
-
claimedAt: current?.claimedAt ?? now.toISOString(),
|
|
22217
|
-
expiresAt: new Date(now.getTime() + CLAIM_TTL_MS).toISOString()
|
|
22218
|
-
};
|
|
22219
|
-
return {
|
|
22220
|
-
...file,
|
|
22221
|
-
claims: [...live.filter((each) => each !== current), held]
|
|
22222
|
-
};
|
|
22223
|
-
})).claims.at(-1);
|
|
22224
|
-
}
|
|
22225
|
-
/**
|
|
22226
|
-
* Drops a session's claim on one frame, or every claim it holds when no
|
|
22227
|
-
* frame is named, returning what it dropped.
|
|
22228
|
-
*/
|
|
22229
|
-
async function release$1(root, session, frame, now) {
|
|
22230
|
-
const dropped = [];
|
|
22231
|
-
await ensureRunFolder(root);
|
|
22232
|
-
await updateRecord(claimsPath(root), claimsSpec, (file) => {
|
|
22233
|
-
const kept = [];
|
|
22234
|
-
for (const each of file.claims) {
|
|
22235
|
-
if (!isLive(each, now)) continue;
|
|
22236
|
-
(each.session === session && (frame === void 0 || each.frame === frame) ? dropped : kept).push(each);
|
|
22237
|
-
}
|
|
22238
|
-
return {
|
|
22239
|
-
...file,
|
|
22240
|
-
claims: kept
|
|
22241
|
-
};
|
|
22242
|
-
});
|
|
22243
|
-
return dropped;
|
|
22244
|
-
}
|
|
22245
22575
|
// src/server/claims/gate.ts
|
|
22246
22576
|
/**
|
|
22247
22577
|
* Refuses `frame-claimed` when another session holds a frame the hand write
|
|
@@ -28878,9 +29208,13 @@ function findingFor(docs) {
|
|
|
28878
29208
|
};
|
|
28879
29209
|
};
|
|
28880
29210
|
}
|
|
28881
|
-
/**
|
|
29211
|
+
/**
|
|
29212
|
+
* One finding as `path:line:column rule message`, as `check` and the hook
|
|
29213
|
+
* print it, the path taking `@<width>` for one read at a linked width.
|
|
29214
|
+
*/
|
|
28882
29215
|
function formatFinding(finding) {
|
|
28883
|
-
|
|
29216
|
+
const path = finding.width === void 0 ? finding.path : `${finding.path}@${finding.width}`;
|
|
29217
|
+
return `${finding.location ? `${path}:${finding.location.line}:${finding.location.column}` : path} ${finding.rule} ${finding.message}`;
|
|
28884
29218
|
}
|
|
28885
29219
|
// src/server/checks/theme.ts
|
|
28886
29220
|
const THEME_RULES = [{
|
|
@@ -28889,7 +29223,7 @@ const THEME_RULES = [{
|
|
|
28889
29223
|
severity: "error",
|
|
28890
29224
|
description: "A frame setting literal colors defines the other theme too, through a [data-theme] selector, a prefers-color-scheme query, or light-dark()"
|
|
28891
29225
|
}];
|
|
28892
|
-
const finding$
|
|
29226
|
+
const finding$11 = findingFor(THEME_RULES);
|
|
28893
29227
|
const COLOR_PROPERTIES$2 = /^(color|background(-color|-image)?|border(-(top|right|bottom|left|block|inline)(-(start|end))?)?(-color)?|outline(-color)?|fill|stroke|box-shadow|text-shadow|caret-color|accent-color|text-decoration(-color)?|column-rule(-color)?)$/i;
|
|
28894
29228
|
const COLOR_FUNCTION = /\b(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\(/i;
|
|
28895
29229
|
const HEX_COLOR = /#[0-9a-f]{3,8}\b/i;
|
|
@@ -28899,7 +29233,7 @@ function checkTheme(source) {
|
|
|
28899
29233
|
const { firstColor, bothThemes } = readThemeColors(source);
|
|
28900
29234
|
if (!firstColor || bothThemes) return [];
|
|
28901
29235
|
const { path, location } = firstColor;
|
|
28902
|
-
return [finding$
|
|
29236
|
+
return [finding$11("theme", {
|
|
28903
29237
|
frame: source.ref,
|
|
28904
29238
|
path,
|
|
28905
29239
|
message: "The frame sets its own colors for one theme alone. Define the other through [data-theme] or prefers-color-scheme, or take the colors from token variables.",
|
|
@@ -29398,12 +29732,13 @@ const ASSET_KINDS = [
|
|
|
29398
29732
|
"script",
|
|
29399
29733
|
"other"
|
|
29400
29734
|
];
|
|
29401
|
-
/** The kinds a frame shows as an `<img
|
|
29735
|
+
/** The kinds a frame shows as an `<img>`, a `<video>`, or an `<audio>`, which the board places by hand. */
|
|
29402
29736
|
const PLACEABLE_KINDS = [
|
|
29403
29737
|
"image",
|
|
29404
29738
|
"gif",
|
|
29405
29739
|
"svg",
|
|
29406
|
-
"video"
|
|
29740
|
+
"video",
|
|
29741
|
+
"audio"
|
|
29407
29742
|
];
|
|
29408
29743
|
function isPlaceableKind(kind) {
|
|
29409
29744
|
return PLACEABLE_KINDS.includes(kind);
|
|
@@ -29420,6 +29755,7 @@ const ACCEPTED = {
|
|
|
29420
29755
|
mp4: "video",
|
|
29421
29756
|
webm: "video",
|
|
29422
29757
|
mov: "video",
|
|
29758
|
+
m4v: "video",
|
|
29423
29759
|
mp3: "audio",
|
|
29424
29760
|
wav: "audio",
|
|
29425
29761
|
ogg: "audio",
|
|
@@ -29501,7 +29837,7 @@ async function walk(folder, prefix, real, into) {
|
|
|
29501
29837
|
* can show it, confined as `listAssets` is: a path naming a dot-named
|
|
29502
29838
|
* segment, a `..`, or any file whose real path leaves the folder is
|
|
29503
29839
|
* `asset-missing`, as is one that is not there. A file that is there but is
|
|
29504
|
-
* no image, GIF, SVG, or
|
|
29840
|
+
* no image, GIF, SVG, video, or audio is `asset-not-placeable`.
|
|
29505
29841
|
*/
|
|
29506
29842
|
async function resolveAsset(projectDir, path) {
|
|
29507
29843
|
const missing = {
|
|
@@ -29524,7 +29860,7 @@ async function resolveAsset(projectDir, path) {
|
|
|
29524
29860
|
if (!isPlaceableKind(kind)) return {
|
|
29525
29861
|
ok: false,
|
|
29526
29862
|
code: "asset-not-placeable",
|
|
29527
|
-
message: `assets/${path} is not an image, GIF, SVG, or
|
|
29863
|
+
message: `assets/${path} is not an image, GIF, SVG, video, or audio, so a frame cannot show it`
|
|
29528
29864
|
};
|
|
29529
29865
|
return {
|
|
29530
29866
|
ok: true,
|
|
@@ -29713,6 +30049,78 @@ function checkRoutes(access, checks) {
|
|
|
29713
30049
|
});
|
|
29714
30050
|
return app;
|
|
29715
30051
|
}
|
|
30052
|
+
// src/server/routes/envelope.ts
|
|
30053
|
+
/** The status each refusal of a structure or history write answers with. */
|
|
30054
|
+
const STATUS$4 = {
|
|
30055
|
+
usage: 400,
|
|
30056
|
+
"invalid-name": 400,
|
|
30057
|
+
"project-required": 400,
|
|
30058
|
+
"project-not-found": 404,
|
|
30059
|
+
"page-not-found": 404,
|
|
30060
|
+
"frame-not-found": 404,
|
|
30061
|
+
"section-not-found": 404,
|
|
30062
|
+
"name-taken": 409,
|
|
30063
|
+
"stale-layout": 409,
|
|
30064
|
+
"frame-claimed": 409,
|
|
30065
|
+
"undo-overtaken": 409,
|
|
30066
|
+
"nothing-to-undo": 409,
|
|
30067
|
+
"tokens-exist": 409,
|
|
30068
|
+
"stale-tokens": 409,
|
|
30069
|
+
"invalid-edit": 409,
|
|
30070
|
+
"frame-locked": 423,
|
|
30071
|
+
"layout-invalid": 422,
|
|
30072
|
+
"project-file-invalid": 422,
|
|
30073
|
+
"fit-unbounded": 422,
|
|
30074
|
+
"fit-scroll": 422,
|
|
30075
|
+
"claims-invalid": 422,
|
|
30076
|
+
"lock-timeout": 503,
|
|
30077
|
+
"browser-not-found": 503
|
|
30078
|
+
};
|
|
30079
|
+
/**
|
|
30080
|
+
* Answers a refusal in the CLI's `{ ok, error }` envelope, for a route
|
|
30081
|
+
* module's `onError`. Anything else is a fault and goes on to Hono.
|
|
30082
|
+
*/
|
|
30083
|
+
function answerRefusal(error, c) {
|
|
30084
|
+
if (!(error instanceof FrameboardError)) throw error;
|
|
30085
|
+
return c.json({
|
|
30086
|
+
ok: false,
|
|
30087
|
+
error: {
|
|
30088
|
+
code: error.code,
|
|
30089
|
+
message: error.message,
|
|
30090
|
+
details: error.details
|
|
30091
|
+
}
|
|
30092
|
+
}, STATUS$4[error.code] ?? 500);
|
|
30093
|
+
}
|
|
30094
|
+
/** The request's JSON body as the schema reads it, or `usage` naming what failed. */
|
|
30095
|
+
async function parseBody$1(request, schema) {
|
|
30096
|
+
const parsed = schema.safeParse(await request.json().catch(() => null));
|
|
30097
|
+
if (!parsed.success) throw new FrameboardError("usage", `The body ${parsed.error.message}`);
|
|
30098
|
+
return parsed.data;
|
|
30099
|
+
}
|
|
30100
|
+
// src/server/routes/claims.ts
|
|
30101
|
+
const ReleaseBody = object$1({ frame: string$1().min(1) });
|
|
30102
|
+
/**
|
|
30103
|
+
* `POST /api/claims/release` with `{ frame }`, the canonical ref a claim
|
|
30104
|
+
* names, dropping the live reservation on that frame whichever session holds
|
|
30105
|
+
* it. It sits behind `requireWriter`, and a frame holding no reservation,
|
|
30106
|
+
* including one an agent holds an editing claim on, refuses
|
|
30107
|
+
* `frame-not-found` and is left as it was.
|
|
30108
|
+
*/
|
|
30109
|
+
function claimsRoutes(root, access) {
|
|
30110
|
+
const app = new Hono();
|
|
30111
|
+
app.onError(answerRefusal);
|
|
30112
|
+
app.use("/api/claims/release", requireWriter(access));
|
|
30113
|
+
app.post("/api/claims/release", async (c) => {
|
|
30114
|
+
const { frame } = await parseBody$1(c.req.raw, ReleaseBody);
|
|
30115
|
+
const released = await releaseReservation(root, frame, /* @__PURE__ */ new Date());
|
|
30116
|
+
if (!released) throw new FrameboardError("frame-not-found", `No reservation holds ${frame}.`, { frame });
|
|
30117
|
+
return c.json({
|
|
30118
|
+
ok: true,
|
|
30119
|
+
data: { released }
|
|
30120
|
+
});
|
|
30121
|
+
});
|
|
30122
|
+
return app;
|
|
30123
|
+
}
|
|
29716
30124
|
// src/server/clipboard/wsl.ts
|
|
29717
30125
|
/** The folder under Windows' temp folder each copy writes into. */
|
|
29718
30126
|
const CLIP_FOLDER = "frameboard-clip";
|
|
@@ -29722,33 +30130,42 @@ const WINDOWS_RESERVED = /[<>:"/\\|?*]/g;
|
|
|
29722
30130
|
* The Windows clipboard reached from WSL. The images land in Windows' temp
|
|
29723
30131
|
* folder, since a file drop list names Windows paths and a pasting app reads
|
|
29724
30132
|
* the files after the copy returns. Each copy clears the last one's folder,
|
|
29725
|
-
* the only time a pasted list is known to be done with.
|
|
30133
|
+
* the only time a pasted list is known to be done with. Copies run one at a
|
|
30134
|
+
* time, since a copy clearing the folder while another is still setting the
|
|
30135
|
+
* clipboard deletes the files that copy is about to name.
|
|
29726
30136
|
*/
|
|
29727
30137
|
function wslClipboard(run) {
|
|
30138
|
+
let previous = Promise.resolve();
|
|
29728
30139
|
return {
|
|
29729
30140
|
backend: "wsl",
|
|
29730
|
-
write:
|
|
29731
|
-
const
|
|
29732
|
-
|
|
29733
|
-
|
|
29734
|
-
|
|
29735
|
-
|
|
29736
|
-
|
|
29737
|
-
|
|
29738
|
-
|
|
29739
|
-
|
|
29740
|
-
|
|
29741
|
-
|
|
29742
|
-
|
|
29743
|
-
|
|
29744
|
-
|
|
29745
|
-
|
|
29746
|
-
|
|
29747
|
-
|
|
29748
|
-
|
|
29749
|
-
|
|
29750
|
-
|
|
29751
|
-
|
|
30141
|
+
write: (files) => {
|
|
30142
|
+
const copy = previous.then(() => writeCopy(run, files));
|
|
30143
|
+
previous = copy.catch(() => void 0);
|
|
30144
|
+
return copy;
|
|
30145
|
+
}
|
|
30146
|
+
};
|
|
30147
|
+
}
|
|
30148
|
+
/** Writes one copy's images into a fresh folder and sets them on the clipboard. */
|
|
30149
|
+
async function writeCopy(run, files) {
|
|
30150
|
+
const windowsDir = `${(await run("powershell.exe", [
|
|
30151
|
+
"-NoProfile",
|
|
30152
|
+
"-Command",
|
|
30153
|
+
"[IO.Path]::GetTempPath()"
|
|
30154
|
+
])).trim().replace(/\\$/, "")}\\${CLIP_FOLDER}\\${randomUUID()}`;
|
|
30155
|
+
const linuxDir = (await run("wslpath", [windowsDir])).trim();
|
|
30156
|
+
await rm(join(linuxDir, ".."), {
|
|
30157
|
+
recursive: true,
|
|
30158
|
+
force: true
|
|
30159
|
+
});
|
|
30160
|
+
await mkdir(linuxDir, { recursive: true });
|
|
30161
|
+
const names = fileNames(files);
|
|
30162
|
+
await Promise.all(files.map((file, index) => writeFile(join(linuxDir, names[index] ?? ""), file.bytes)));
|
|
30163
|
+
await run("powershell.exe", [
|
|
30164
|
+
"-NoProfile",
|
|
30165
|
+
"-STA",
|
|
30166
|
+
"-Command",
|
|
30167
|
+
`Set-Clipboard -Path ${pathList(windowsDir, names)}`
|
|
30168
|
+
]);
|
|
29752
30169
|
}
|
|
29753
30170
|
/** Each file's name made safe for Windows and unique in the folder, as `hero.png`, `hero-2.png`. */
|
|
29754
30171
|
function fileNames(files) {
|
|
@@ -29793,52 +30210,6 @@ function processHost() {
|
|
|
29793
30210
|
onPath: (command) => (process.env.PATH ?? "").split(delimiter).some((dir) => dir !== "" && existsSync(join(dir, command)))
|
|
29794
30211
|
};
|
|
29795
30212
|
}
|
|
29796
|
-
// src/server/routes/envelope.ts
|
|
29797
|
-
/** The status each refusal of a structure or history write answers with. */
|
|
29798
|
-
const STATUS$4 = {
|
|
29799
|
-
usage: 400,
|
|
29800
|
-
"invalid-name": 400,
|
|
29801
|
-
"project-required": 400,
|
|
29802
|
-
"project-not-found": 404,
|
|
29803
|
-
"page-not-found": 404,
|
|
29804
|
-
"frame-not-found": 404,
|
|
29805
|
-
"section-not-found": 404,
|
|
29806
|
-
"name-taken": 409,
|
|
29807
|
-
"stale-layout": 409,
|
|
29808
|
-
"frame-claimed": 409,
|
|
29809
|
-
"undo-overtaken": 409,
|
|
29810
|
-
"nothing-to-undo": 409,
|
|
29811
|
-
"tokens-exist": 409,
|
|
29812
|
-
"stale-tokens": 409,
|
|
29813
|
-
"invalid-edit": 409,
|
|
29814
|
-
"frame-locked": 423,
|
|
29815
|
-
"layout-invalid": 422,
|
|
29816
|
-
"project-file-invalid": 422,
|
|
29817
|
-
"fit-unbounded": 422,
|
|
29818
|
-
"lock-timeout": 503,
|
|
29819
|
-
"browser-not-found": 503
|
|
29820
|
-
};
|
|
29821
|
-
/**
|
|
29822
|
-
* Answers a refusal in the CLI's `{ ok, error }` envelope, for a route
|
|
29823
|
-
* module's `onError`. Anything else is a fault and goes on to Hono.
|
|
29824
|
-
*/
|
|
29825
|
-
function answerRefusal(error, c) {
|
|
29826
|
-
if (!(error instanceof FrameboardError)) throw error;
|
|
29827
|
-
return c.json({
|
|
29828
|
-
ok: false,
|
|
29829
|
-
error: {
|
|
29830
|
-
code: error.code,
|
|
29831
|
-
message: error.message,
|
|
29832
|
-
details: error.details
|
|
29833
|
-
}
|
|
29834
|
-
}, STATUS$4[error.code] ?? 500);
|
|
29835
|
-
}
|
|
29836
|
-
/** The request's JSON body as the schema reads it, or `usage` naming what failed. */
|
|
29837
|
-
async function parseBody$1(request, schema) {
|
|
29838
|
-
const parsed = schema.safeParse(await request.json().catch(() => null));
|
|
29839
|
-
if (!parsed.success) throw new FrameboardError("usage", `The body ${parsed.error.message}`);
|
|
29840
|
-
return parsed.data;
|
|
29841
|
-
}
|
|
29842
30213
|
// src/server/routes/clipboard.ts
|
|
29843
30214
|
const STATUS$3 = {
|
|
29844
30215
|
usage: 400,
|
|
@@ -29847,6 +30218,7 @@ const STATUS$3 = {
|
|
|
29847
30218
|
"page-not-found": 404,
|
|
29848
30219
|
"frame-not-found": 404,
|
|
29849
30220
|
"font-missing": 422,
|
|
30221
|
+
"image-missing": 422,
|
|
29850
30222
|
"capture-too-large": 422,
|
|
29851
30223
|
"clipboard-unsupported": 501,
|
|
29852
30224
|
"browser-not-found": 503
|
|
@@ -30431,8 +30803,10 @@ function checkChange(change) {
|
|
|
30431
30803
|
}
|
|
30432
30804
|
return;
|
|
30433
30805
|
}
|
|
30434
|
-
|
|
30435
|
-
|
|
30806
|
+
if ("value" in change) {
|
|
30807
|
+
const invalid = checkValue(change.value);
|
|
30808
|
+
if (invalid) return invalid;
|
|
30809
|
+
}
|
|
30436
30810
|
if (change.kind === "attribute") {
|
|
30437
30811
|
if (!ATTRIBUTE_NAME.test(change.name)) return refuse$2("invalid-edit", `${change.name} is not an attribute name`);
|
|
30438
30812
|
if (change.name.toLowerCase() === "style") return refuse$2("invalid-edit", "style is edited one declaration at a time, as a style edit");
|
|
@@ -30459,10 +30833,16 @@ function write(source, element, change) {
|
|
|
30459
30833
|
const written = setText(source, element, change.value);
|
|
30460
30834
|
return written.ok ? written : refuse$2("not-text-only", written.detail);
|
|
30461
30835
|
}
|
|
30462
|
-
if (change.kind === "attribute")
|
|
30463
|
-
|
|
30464
|
-
|
|
30465
|
-
|
|
30836
|
+
if (change.kind === "attribute") {
|
|
30837
|
+
if ("remove" in change) return {
|
|
30838
|
+
ok: true,
|
|
30839
|
+
html: removeAttribute(source, element, change.name)
|
|
30840
|
+
};
|
|
30841
|
+
return {
|
|
30842
|
+
ok: true,
|
|
30843
|
+
html: setRawAttribute(source, element, change.name, escapeAttribute$1(change.value))
|
|
30844
|
+
};
|
|
30845
|
+
}
|
|
30466
30846
|
const declarations = change.kind === "styles" ? change.declarations : [change];
|
|
30467
30847
|
let style = rawAttribute(source, element, "style") ?? "";
|
|
30468
30848
|
for (const { property, value } of declarations) {
|
|
@@ -30510,7 +30890,10 @@ function textOf$1(element) {
|
|
|
30510
30890
|
/** Whether the target holds the value the change asked for. */
|
|
30511
30891
|
function holdsValue(element, change) {
|
|
30512
30892
|
if (change.kind === "text") return textOf$1(element) === change.value;
|
|
30513
|
-
if (change.kind === "attribute")
|
|
30893
|
+
if (change.kind === "attribute") {
|
|
30894
|
+
const stated = element.attrs.find((attribute) => isNamed(attribute, change.name));
|
|
30895
|
+
return "remove" in change ? stated === void 0 : stated?.value === change.value;
|
|
30896
|
+
}
|
|
30514
30897
|
const style = element.attrs.find((attribute) => attribute.name === "style")?.value ?? "";
|
|
30515
30898
|
return (change.kind === "styles" ? change.declarations : [change]).every(({ property, value }) => {
|
|
30516
30899
|
const declared = declaredValues(style, property);
|
|
@@ -35990,9 +36373,12 @@ const FACES = [
|
|
|
35990
36373
|
];
|
|
35991
36374
|
/** Where the server serves the faces folder. */
|
|
35992
36375
|
const FACES_URL = "/frameboard/faces";
|
|
35993
|
-
/**
|
|
36376
|
+
/**
|
|
36377
|
+
* The sheet a frame imports to get one face, under the running release so
|
|
36378
|
+
* the server can answer it as cached for good.
|
|
36379
|
+
*/
|
|
35994
36380
|
function faceSheetUrl(face) {
|
|
35995
|
-
return `${FACES_URL}/${face.folder}/index.css`;
|
|
36381
|
+
return `${FACES_URL}/v${version}/${face.folder}/index.css`;
|
|
35996
36382
|
}
|
|
35997
36383
|
/** The stack naming a face then its fallback, as `'Geist Mono', monospace`. */
|
|
35998
36384
|
function faceStack(face) {
|
|
@@ -36132,8 +36518,13 @@ function elementMarkup(element, paint, font) {
|
|
|
36132
36518
|
case "divider": return `<hr data-name="Divider" style="align-self: stretch; margin: 0; border: 0; ${element.vertical ? "border-left" : "border-top"}: 1px solid ${line}">`;
|
|
36133
36519
|
case "asset": {
|
|
36134
36520
|
const name = attribute(element.path.split("/").at(-1) ?? element.path);
|
|
36521
|
+
const src = assetLink(element.path);
|
|
36522
|
+
if (element.tag === "audio") {
|
|
36523
|
+
if (!Number.isInteger(element.width)) throw new Error(`Unexpected audio width ${element.width}`);
|
|
36524
|
+
return `<audio data-name="${name}" src="${src}" controls style="width: ${element.width}px"></audio>`;
|
|
36525
|
+
}
|
|
36135
36526
|
const style = `${size(element)}; object-fit: cover`;
|
|
36136
|
-
return element.video ? `<video data-name="${name}" src="${
|
|
36527
|
+
return element.tag === "video" ? `<video data-name="${name}" src="${src}" autoplay muted loop playsinline style="${style}"></video>` : `<img data-name="${name}" src="${src}" alt="" style="${style}">`;
|
|
36137
36528
|
}
|
|
36138
36529
|
}
|
|
36139
36530
|
}
|
|
@@ -38873,17 +39264,22 @@ const side = int$1().min(1).max(1e4);
|
|
|
38873
39264
|
const offset = number().min(-1e5).max(1e5);
|
|
38874
39265
|
/** How many elements one batch names, well past any selection a hand makes. */
|
|
38875
39266
|
const BATCH = 1024;
|
|
38876
|
-
const changeSchema =
|
|
39267
|
+
const changeSchema = union([
|
|
38877
39268
|
object$1({
|
|
38878
39269
|
kind: literal("style"),
|
|
38879
39270
|
property: name$1,
|
|
38880
39271
|
value
|
|
38881
39272
|
}),
|
|
38882
|
-
|
|
39273
|
+
strictObject({
|
|
38883
39274
|
kind: literal("attribute"),
|
|
38884
39275
|
name: name$1,
|
|
38885
39276
|
value
|
|
38886
39277
|
}),
|
|
39278
|
+
strictObject({
|
|
39279
|
+
kind: literal("attribute"),
|
|
39280
|
+
name: name$1,
|
|
39281
|
+
remove: literal(true)
|
|
39282
|
+
}),
|
|
38887
39283
|
object$1({
|
|
38888
39284
|
kind: literal("text"),
|
|
38889
39285
|
value
|
|
@@ -39027,7 +39423,8 @@ const recolorSchema = object$1({
|
|
|
39027
39423
|
* An asset names a file under the project's `assets/` and the size it
|
|
39028
39424
|
* shows at, and the server picks its tag from the file's kind. A file
|
|
39029
39425
|
* outside that folder or not there answers 409 `asset-missing`, and one that
|
|
39030
|
-
* is no image, GIF, SVG, or
|
|
39426
|
+
* is no image, GIF, SVG, video, or audio `asset-not-placeable`, each writing
|
|
39427
|
+
* nothing.
|
|
39031
39428
|
*
|
|
39032
39429
|
* The remove takes out the element at `index`, with what it holds, from the
|
|
39033
39430
|
* bytes `hash` names, and records it as one step whose undo puts it back
|
|
@@ -39172,7 +39569,7 @@ function editRoutes(root, access, history, version, sheets) {
|
|
|
39172
39569
|
}, 409);
|
|
39173
39570
|
element = {
|
|
39174
39571
|
...body.element,
|
|
39175
|
-
|
|
39572
|
+
tag: asset.kind === "video" || asset.kind === "audio" ? asset.kind : "img"
|
|
39176
39573
|
};
|
|
39177
39574
|
}
|
|
39178
39575
|
const { at } = body;
|
|
@@ -39954,8 +40351,12 @@ const CONTENT_TYPES$1 = {
|
|
|
39954
40351
|
".otf": "font/otf",
|
|
39955
40352
|
".mp4": "video/mp4",
|
|
39956
40353
|
".webm": "video/webm",
|
|
40354
|
+
".mov": "video/quicktime",
|
|
40355
|
+
".m4v": "video/x-m4v",
|
|
39957
40356
|
".mp3": "audio/mpeg",
|
|
39958
|
-
".wav": "audio/wav"
|
|
40357
|
+
".wav": "audio/wav",
|
|
40358
|
+
".ogg": "audio/ogg",
|
|
40359
|
+
".m4a": "audio/mp4"
|
|
39959
40360
|
};
|
|
39960
40361
|
/**
|
|
39961
40362
|
* Serves `/frames/<project>/<page>/<file>` and `/frames/<project>/assets/<path>`
|
|
@@ -39968,8 +40369,10 @@ const CONTENT_TYPES$1 = {
|
|
|
39968
40369
|
* caller what exists.
|
|
39969
40370
|
*
|
|
39970
40371
|
* A frame served from a page gets the faces and the token sheets spliced
|
|
39971
|
-
* first into its `head`, in the response alone, and
|
|
39972
|
-
* served byte for byte
|
|
40372
|
+
* first into its `head`, in the response alone, and is never cached. Every
|
|
40373
|
+
* other file is served byte for byte under a validator the browser checks on
|
|
40374
|
+
* each use, so an edit shows on the next load and an unchanged file answers
|
|
40375
|
+
* 304 with no body. A frame path carrying `?at=<hash>` serves the
|
|
39973
40376
|
* version `version` holds under that hash in its place, with the same head,
|
|
39974
40377
|
* and any other path carrying it answers 404.
|
|
39975
40378
|
*/
|
|
@@ -40005,6 +40408,21 @@ function frameRoutes(root, look, version) {
|
|
|
40005
40408
|
return c.body(stream, 206, headers);
|
|
40006
40409
|
}
|
|
40007
40410
|
}
|
|
40411
|
+
if (!isFrame && at === void 0) {
|
|
40412
|
+
const tag = weakTag(await stat(file, { bigint: true }));
|
|
40413
|
+
const revalidate = {
|
|
40414
|
+
ETag: tag,
|
|
40415
|
+
"Cache-Control": "no-cache"
|
|
40416
|
+
};
|
|
40417
|
+
if (matchesTag(c.req.header("If-None-Match"), tag)) return c.body(null, 304, revalidate);
|
|
40418
|
+
const headers = {
|
|
40419
|
+
"Content-Type": contentType,
|
|
40420
|
+
"Accept-Ranges": "bytes",
|
|
40421
|
+
...revalidate
|
|
40422
|
+
};
|
|
40423
|
+
if (c.req.method === "HEAD") return c.body(null, 200, headers);
|
|
40424
|
+
return c.body(new Uint8Array(await readFile(file)), 200, headers);
|
|
40425
|
+
}
|
|
40008
40426
|
let bytes;
|
|
40009
40427
|
if (at === void 0) bytes = new Uint8Array(await readFile(file));
|
|
40010
40428
|
else {
|
|
@@ -40013,16 +40431,30 @@ function frameRoutes(root, look, version) {
|
|
|
40013
40431
|
if (held === null) return c.notFound();
|
|
40014
40432
|
bytes = new TextEncoder().encode(held);
|
|
40015
40433
|
}
|
|
40016
|
-
const body =
|
|
40434
|
+
const body = injectHead(bytes, frameHead(sheetUrls(project, look.sheets(project)), contentHash(bytes)));
|
|
40017
40435
|
return c.body(body, 200, {
|
|
40018
40436
|
"Content-Type": contentType,
|
|
40019
|
-
"Cache-Control": "no-store"
|
|
40020
|
-
...isFrame ? {} : { "Accept-Ranges": "bytes" }
|
|
40437
|
+
"Cache-Control": "no-store"
|
|
40021
40438
|
});
|
|
40022
40439
|
});
|
|
40023
40440
|
return app;
|
|
40024
40441
|
}
|
|
40025
40442
|
/**
|
|
40443
|
+
* A weak validator from a file's size and nanosecond mtime, so a check costs
|
|
40444
|
+
* one stat rather than a read of every byte. A same-size rewrite inside one
|
|
40445
|
+
* timestamp tick keeps its tag, which a coarse mount makes likelier.
|
|
40446
|
+
*/
|
|
40447
|
+
function weakTag({ size, mtimeNs }) {
|
|
40448
|
+
return `W/"${size.toString(16)}-${mtimeNs.toString(16)}"`;
|
|
40449
|
+
}
|
|
40450
|
+
/** Whether an `If-None-Match` header names `tag`, compared weakly per RFC 9110. */
|
|
40451
|
+
function matchesTag(header, tag) {
|
|
40452
|
+
if (header === void 0) return false;
|
|
40453
|
+
if (header.trim() === "*") return true;
|
|
40454
|
+
const opaque = tag.replace(/^W\//, "");
|
|
40455
|
+
return header.split(",").some((listed) => listed.trim().replace(/^W\//, "") === opaque);
|
|
40456
|
+
}
|
|
40457
|
+
/**
|
|
40026
40458
|
* The inclusive bytes a single `bytes=` range names within `size`,
|
|
40027
40459
|
* `'unsatisfiable'` for a valid range that names none of them, or null for a
|
|
40028
40460
|
* header to ignore, which RFC 9110 allows for any range a server does not
|
|
@@ -40093,6 +40525,10 @@ function isRecord$1(name) {
|
|
|
40093
40525
|
return name === "layout.json" || name === NOTES_FILE$1;
|
|
40094
40526
|
}
|
|
40095
40527
|
// src/server/routes/look.ts
|
|
40528
|
+
/** The answer for faces under the running release, whose bytes a release fixes. */
|
|
40529
|
+
const IMMUTABLE = "public, max-age=31536000, immutable";
|
|
40530
|
+
/** A release segment as `faceSheetUrl` writes one, such as `v0.29.0`. */
|
|
40531
|
+
const RELEASE_SEGMENT = /^v\d+\.\d+\.\d+/;
|
|
40096
40532
|
const CONTENT_TYPES = {
|
|
40097
40533
|
".css": "text/css; charset=utf-8",
|
|
40098
40534
|
".woff2": "font/woff2"
|
|
@@ -40120,8 +40556,13 @@ function servedFrames(root, { facesDir, tokens, version }) {
|
|
|
40120
40556
|
/**
|
|
40121
40557
|
* Serves what every frame imports from outside the board: the faces under
|
|
40122
40558
|
* `/frameboard/faces/*` and the board sheet at `/frameboard/tokens.css`.
|
|
40123
|
-
*
|
|
40124
|
-
*
|
|
40559
|
+
* The board sheet is never cached, so a changed sheet reaches a frame on its
|
|
40560
|
+
* reload. The faces under the running release's segment, as
|
|
40561
|
+
* `/frameboard/faces/v0.29.0/geist/index.css`, are cached for good, since
|
|
40562
|
+
* only a release changes them, and any other release segment answers 404 so
|
|
40563
|
+
* a stale URL never caches today's bytes. The bare faces path stays
|
|
40564
|
+
* uncached for anything naming it. A dot-named or escaping path answers 404,
|
|
40565
|
+
* as the frame route does.
|
|
40125
40566
|
*/
|
|
40126
40567
|
function lookRoutes({ facesDir, boardSheet }) {
|
|
40127
40568
|
const app = new Hono();
|
|
@@ -40135,13 +40576,16 @@ function lookRoutes({ facesDir, boardSheet }) {
|
|
|
40135
40576
|
});
|
|
40136
40577
|
});
|
|
40137
40578
|
app.get(`${FACES_URL}/*`, async (c) => {
|
|
40138
|
-
const
|
|
40579
|
+
const segments = new URL(c.req.url).pathname.slice(18).split("/");
|
|
40580
|
+
const release = RELEASE_SEGMENT.test(segments[0] ?? "");
|
|
40581
|
+
if (release && segments[0] !== `v${version}`) return c.notFound();
|
|
40582
|
+
const file = await resolveFace(facesDir, release ? segments.slice(1) : segments);
|
|
40139
40583
|
const type = file && CONTENT_TYPES[extname(file)];
|
|
40140
40584
|
const bytes = type ? await readOrNull(file) : null;
|
|
40141
40585
|
if (!type || !bytes) return c.notFound();
|
|
40142
40586
|
return c.body(bytes, 200, {
|
|
40143
40587
|
"Content-Type": type,
|
|
40144
|
-
"Cache-Control": "no-store"
|
|
40588
|
+
"Cache-Control": release ? IMMUTABLE : "no-store"
|
|
40145
40589
|
});
|
|
40146
40590
|
});
|
|
40147
40591
|
return app;
|
|
@@ -40547,6 +40991,7 @@ const STATUS = {
|
|
|
40547
40991
|
"page-not-found": 404,
|
|
40548
40992
|
"frame-not-found": 404,
|
|
40549
40993
|
"font-missing": 422,
|
|
40994
|
+
"image-missing": 422,
|
|
40550
40995
|
"capture-too-large": 422,
|
|
40551
40996
|
"browser-not-found": 503
|
|
40552
40997
|
};
|
|
@@ -40636,7 +41081,7 @@ async function pasteFrames(root, pageRef, held, options) {
|
|
|
40636
41081
|
};
|
|
40637
41082
|
return frame.page === target.path ? {
|
|
40638
41083
|
...box,
|
|
40639
|
-
x:
|
|
41084
|
+
x: pastExtent(frame.placement)
|
|
40640
41085
|
} : box;
|
|
40641
41086
|
};
|
|
40642
41087
|
const names = await withLayouts([target.path], async (layouts) => {
|
|
@@ -41015,6 +41460,11 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
41015
41460
|
}, (results) => onFrames(touched(results)));
|
|
41016
41461
|
app.post("/api/frame/add", async (c) => {
|
|
41017
41462
|
const body = await parseBody$1(c.req.raw, frameAddSchema);
|
|
41463
|
+
const target = await resolveFrameRef(root, body.ref, {
|
|
41464
|
+
cwd,
|
|
41465
|
+
allowMissing: true
|
|
41466
|
+
});
|
|
41467
|
+
await refuseHeld([`${target.project}/${target.page}/${target.name}`]);
|
|
41018
41468
|
const frame = await recorded((journal) => addFrame(root, body.ref, {
|
|
41019
41469
|
...body,
|
|
41020
41470
|
cwd,
|
|
@@ -41040,7 +41490,7 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
41040
41490
|
app.post("/api/frame/rename", async (c) => {
|
|
41041
41491
|
const body = await parseBody$1(c.req.raw, renameSchema);
|
|
41042
41492
|
const source = await readFrame$1(root, body.ref, { cwd });
|
|
41043
|
-
await refuseHeld([source.ref]);
|
|
41493
|
+
await refuseHeld([source.ref, `${source.project}/${source.page}/${body.name}`]);
|
|
41044
41494
|
const frame = await recorded((journal) => renameFrame(root, body.ref, body.name, {
|
|
41045
41495
|
cwd,
|
|
41046
41496
|
journal
|
|
@@ -41091,10 +41541,23 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
41091
41541
|
await refuseHeldFrames([body.ref]);
|
|
41092
41542
|
if (!measure) throw new FrameboardError("browser-not-found", "Fit height needs the board server's browser, and none runs here.");
|
|
41093
41543
|
const frame = await readFrame$1(root, body.ref, { cwd });
|
|
41544
|
+
if (frame.scroll) throw fitScrollError(frame.ref);
|
|
41094
41545
|
const measured = await measure(frame);
|
|
41546
|
+
const widths = [];
|
|
41547
|
+
for (const { width } of frame.widths) {
|
|
41548
|
+
const linked = await measure(frame, {
|
|
41549
|
+
width,
|
|
41550
|
+
height: referenceHeight(width)
|
|
41551
|
+
});
|
|
41552
|
+
widths.push({
|
|
41553
|
+
width,
|
|
41554
|
+
height: linked.height
|
|
41555
|
+
});
|
|
41556
|
+
}
|
|
41095
41557
|
const fit = await recorded((journal) => fitHeight(root, frame.ref, measured.height, {
|
|
41096
41558
|
cwd,
|
|
41097
|
-
journal
|
|
41559
|
+
journal,
|
|
41560
|
+
widths
|
|
41098
41561
|
}), (record) => onFrames([record.ref]));
|
|
41099
41562
|
return c.json({
|
|
41100
41563
|
ok: true,
|
|
@@ -41523,6 +41986,7 @@ function createApp({ clientDir, root, port, actions, tickets, openRoute, renderF
|
|
|
41523
41986
|
app.route("/", assetsRoutes(root, actions.access, { usage: assetUsage }));
|
|
41524
41987
|
app.route("/", elementsRoutes(root, actions.access, selection, given));
|
|
41525
41988
|
app.route("/", findRoutes(root));
|
|
41989
|
+
app.route("/", claimsRoutes(root, actions.access));
|
|
41526
41990
|
app.route("/", tokenRoutes(root, actions.access, history, frames.look));
|
|
41527
41991
|
app.route("/", editRoutes(root, actions.access, history, settledVersion, frames.look.sheets));
|
|
41528
41992
|
app.route("/", pngRoutes(root, renderFrame));
|
|
@@ -41628,6 +42092,38 @@ async function withFrameHost(board, purpose, run) {
|
|
|
41628
42092
|
await host.close();
|
|
41629
42093
|
}
|
|
41630
42094
|
}
|
|
42095
|
+
// src/server/capture/animation-settle.ts
|
|
42096
|
+
/**
|
|
42097
|
+
* Waits, within `timeoutMs`, until every running animation and transition
|
|
42098
|
+
* with a finite end has finished, reading again after each round so one that
|
|
42099
|
+
* another starts is awaited too. An infinite animation is never awaited, and
|
|
42100
|
+
* running out of time returns rather than refusing, since a long or
|
|
42101
|
+
* restarting animation is a design and not a failure.
|
|
42102
|
+
*
|
|
42103
|
+
* It sees only what `document.getAnimations()` lists, so a scene a script
|
|
42104
|
+
* steps on a timer stays out of reach.
|
|
42105
|
+
*/
|
|
42106
|
+
async function settleAnimations(page, timeoutMs) {
|
|
42107
|
+
if (timeoutMs <= 0) return;
|
|
42108
|
+
await page.evaluate(waitForAnimations, timeoutMs);
|
|
42109
|
+
}
|
|
42110
|
+
async function waitForAnimations(timeoutMs) {
|
|
42111
|
+
const end = performance.now() + timeoutMs;
|
|
42112
|
+
const nextFrame = () => new Promise((done) => requestAnimationFrame(() => done()));
|
|
42113
|
+
const finiteRunning = () => document.getAnimations().filter((animation) => {
|
|
42114
|
+
if (animation.playState !== "running") return false;
|
|
42115
|
+
const endTime = animation.effect?.getComputedTiming().endTime;
|
|
42116
|
+
return typeof endTime === "number" && Number.isFinite(endTime);
|
|
42117
|
+
});
|
|
42118
|
+
await nextFrame();
|
|
42119
|
+
for (;;) {
|
|
42120
|
+
const running = finiteRunning();
|
|
42121
|
+
const left = end - performance.now();
|
|
42122
|
+
if (running.length === 0 || left <= 0) return;
|
|
42123
|
+
await Promise.race([Promise.all(running.map((animation) => animation.finished.catch(() => {}))), new Promise((done) => setTimeout(done, left))]);
|
|
42124
|
+
await nextFrame();
|
|
42125
|
+
}
|
|
42126
|
+
}
|
|
41631
42127
|
// src/server/capture/fonts.ts
|
|
41632
42128
|
/**
|
|
41633
42129
|
* Families the browser maps to a face itself, so no frame has to supply one.
|
|
@@ -41777,18 +42273,94 @@ async function platformFamilies(page, domIndexes) {
|
|
|
41777
42273
|
await session.detach();
|
|
41778
42274
|
}
|
|
41779
42275
|
}
|
|
42276
|
+
// src/server/capture/image-loads.ts
|
|
42277
|
+
/**
|
|
42278
|
+
* Waits, within `timeoutMs`, until every `<img>` in the frame has loaded and
|
|
42279
|
+
* decoded, so an image marked `decoding="async"` never shoots as an empty
|
|
42280
|
+
* box. A lazy image is made eager in the loaded page first, never in the
|
|
42281
|
+
* file, so one below the box loads too.
|
|
42282
|
+
*
|
|
42283
|
+
* Under `require` an image that errored or is still loading when the time
|
|
42284
|
+
* runs out refuses `image-missing`. Under `wait` the frame opens with it as
|
|
42285
|
+
* the board shows it.
|
|
42286
|
+
*
|
|
42287
|
+
* `stalled` reads a page whose load event never fired, refusing only for an
|
|
42288
|
+
* image that failed or whose request is still open. A loaded image still
|
|
42289
|
+
* decoding cannot have held the load, so something else, such as a
|
|
42290
|
+
* stylesheet or an iframe, did.
|
|
42291
|
+
*/
|
|
42292
|
+
async function settleImages(page, ref, mode, timeoutMs, { stalled = false } = {}) {
|
|
42293
|
+
const unsettled = await page.evaluate(waitForImages, Math.max(0, timeoutMs));
|
|
42294
|
+
const [first] = stalled ? unsettled.filter((image) => image.heldLoad || image.state === "error") : unsettled;
|
|
42295
|
+
if (mode === "wait" || first === void 0) return;
|
|
42296
|
+
const why = first.state === "error" ? "failed to load" : "was still loading when the frame's load budget ran out";
|
|
42297
|
+
throw new FrameboardError("image-missing", `${ref} shows the image ${first.src} at element ${first.index}, and it ${why}. Point it at a file the frame can load, such as one in the project's assets/.`, {
|
|
42298
|
+
ref,
|
|
42299
|
+
src: first.src,
|
|
42300
|
+
element: first.index
|
|
42301
|
+
});
|
|
42302
|
+
}
|
|
42303
|
+
async function waitForImages(timeoutMs) {
|
|
42304
|
+
const images = [];
|
|
42305
|
+
let index = 0;
|
|
42306
|
+
for (const element of document.querySelectorAll("*")) {
|
|
42307
|
+
if (element.closest("[data-frameboard]")) continue;
|
|
42308
|
+
const own = index;
|
|
42309
|
+
index += 1;
|
|
42310
|
+
if (!(element instanceof HTMLImageElement)) continue;
|
|
42311
|
+
if (!element.getAttribute("src") && !element.getAttribute("srcset")) continue;
|
|
42312
|
+
const lazy = element.loading === "lazy";
|
|
42313
|
+
if (lazy) element.loading = "eager";
|
|
42314
|
+
images.push({
|
|
42315
|
+
index: own,
|
|
42316
|
+
img: element,
|
|
42317
|
+
lazy
|
|
42318
|
+
});
|
|
42319
|
+
}
|
|
42320
|
+
if (images.length === 0) return [];
|
|
42321
|
+
const settle = async (img) => {
|
|
42322
|
+
if (!img.complete) await new Promise((done) => {
|
|
42323
|
+
img.addEventListener("load", done, { once: true });
|
|
42324
|
+
img.addEventListener("error", done, { once: true });
|
|
42325
|
+
});
|
|
42326
|
+
return img.decode().then(() => "ok", () => "error");
|
|
42327
|
+
};
|
|
42328
|
+
const outcomes = images.map(({ img }) => ({
|
|
42329
|
+
state: "pending",
|
|
42330
|
+
done: settle(img)
|
|
42331
|
+
}));
|
|
42332
|
+
for (const outcome of outcomes) outcome.done.then((state) => {
|
|
42333
|
+
outcome.state = state;
|
|
42334
|
+
});
|
|
42335
|
+
await Promise.race([Promise.all(outcomes.map((outcome) => outcome.done)), new Promise((done) => setTimeout(done, timeoutMs))]);
|
|
42336
|
+
const unsettled = [];
|
|
42337
|
+
images.forEach(({ index: own, img, lazy }, at) => {
|
|
42338
|
+
const state = outcomes[at]?.state;
|
|
42339
|
+
if (state === void 0 || state === "ok") return;
|
|
42340
|
+
unsettled.push({
|
|
42341
|
+
index: own,
|
|
42342
|
+
src: img.getAttribute("src") || img.currentSrc,
|
|
42343
|
+
state,
|
|
42344
|
+
heldLoad: !lazy && !img.complete
|
|
42345
|
+
});
|
|
42346
|
+
});
|
|
42347
|
+
return unsettled;
|
|
42348
|
+
}
|
|
41780
42349
|
// src/server/capture/render.ts
|
|
41781
|
-
/** How long a frame has to load before its capture fails. */
|
|
42350
|
+
/** How long a frame has to load, its faces and images included, before its capture fails. */
|
|
41782
42351
|
const LOAD_TIMEOUT_MS = 1e4;
|
|
41783
42352
|
/** Chromium's screenshot surface stops at this many pixels on either side. */
|
|
41784
42353
|
const MAX_COMPOSITE_SIDE = 16384;
|
|
41785
42354
|
/**
|
|
41786
42355
|
* Loads a frame in its own browser context at its layout size, in the theme
|
|
41787
|
-
* asked for, and resolves once it has loaded
|
|
41788
|
-
* Under `fonts: 'require'`,
|
|
41789
|
-
* `font-missing
|
|
41790
|
-
|
|
41791
|
-
|
|
42356
|
+
* asked for, and resolves once it has loaded, its faces have settled, and its
|
|
42357
|
+
* images have decoded, all inside one load budget. Under `fonts: 'require'`,
|
|
42358
|
+
* the default, a missing face refuses `font-missing`, an image that failed or
|
|
42359
|
+
* outran the budget refuses `image-missing`, and either closes the context.
|
|
42360
|
+
* 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.
|
|
42362
|
+
*/
|
|
42363
|
+
async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts = "require", timeoutMs = LOAD_TIMEOUT_MS }) {
|
|
41792
42364
|
const context = await browser.newContext({
|
|
41793
42365
|
viewport: {
|
|
41794
42366
|
width: box.width,
|
|
@@ -41798,11 +42370,22 @@ async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts =
|
|
|
41798
42370
|
colorScheme: theme
|
|
41799
42371
|
});
|
|
41800
42372
|
const close = () => context.close();
|
|
42373
|
+
const deadline = Date.now() + timeoutMs;
|
|
41801
42374
|
try {
|
|
41802
42375
|
const page = await context.newPage();
|
|
41803
|
-
await page.goto(new URL(frameThemeUrl(ref, theme), baseUrl).href, {
|
|
42376
|
+
await page.goto(new URL(frameThemeUrl(ref, theme), baseUrl).href, {
|
|
42377
|
+
timeout: timeoutMs,
|
|
42378
|
+
waitUntil: "domcontentloaded"
|
|
42379
|
+
});
|
|
42380
|
+
const stalled = await page.waitForLoadState("load", { timeout: deadline - Date.now() }).then(() => null, (error) => error);
|
|
42381
|
+
if (stalled !== null) {
|
|
42382
|
+
await settleImages(page, ref, fonts, 0, { stalled: true });
|
|
42383
|
+
throw stalled;
|
|
42384
|
+
}
|
|
41804
42385
|
await page.evaluate(() => document.fonts.ready.then(() => void 0));
|
|
41805
42386
|
if (fonts === "require") await assertFontsPresent(page, ref);
|
|
42387
|
+
await settleImages(page, ref, fonts, deadline - Date.now());
|
|
42388
|
+
if (fonts === "require") await settleAnimations(page, deadline - Date.now());
|
|
41806
42389
|
return {
|
|
41807
42390
|
page,
|
|
41808
42391
|
close
|
|
@@ -41890,14 +42473,18 @@ const SCREENSHOT = {
|
|
|
41890
42473
|
};
|
|
41891
42474
|
/**
|
|
41892
42475
|
* The file name of one image, `<name>.<theme>.png` at 1x so a path an agent
|
|
41893
|
-
* saved stays true, and `<name>.<theme>@<n>x.png` at any other scale.
|
|
42476
|
+
* saved stays true, and `<name>.<theme>@<n>x.png` at any other scale. A shot
|
|
42477
|
+
* scrolled down takes `.scroll-<px>` after the name, the offset asked for,
|
|
42478
|
+
* and a linked width takes `@<width>` ahead of both.
|
|
41894
42479
|
*/
|
|
41895
|
-
function imageName(name, theme, scale) {
|
|
41896
|
-
|
|
42480
|
+
function imageName(name, theme, scale, scroll, width) {
|
|
42481
|
+
const named = width === void 0 ? name : `${name}@${width}`;
|
|
42482
|
+
const stem = scroll === void 0 ? named : `${named}.scroll-${scroll}`;
|
|
42483
|
+
return scale === 1 ? `${stem}.${theme}.png` : `${stem}.${theme}@${scale}x.png`;
|
|
41897
42484
|
}
|
|
41898
42485
|
/** Where one frame's capture in one theme lands under `out`. */
|
|
41899
|
-
function frameImagePath(out, frame, theme, scale = 1) {
|
|
41900
|
-
return join(out, frame.project, frame.page, imageName(frame.name, theme, scale));
|
|
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));
|
|
41901
42488
|
}
|
|
41902
42489
|
/** Where a page's composite in one theme lands under `out`. */
|
|
41903
42490
|
function compositeImagePath(out, page, theme, scale = 1) {
|
|
@@ -41906,13 +42493,15 @@ function compositeImagePath(out, page, theme, scale = 1) {
|
|
|
41906
42493
|
/**
|
|
41907
42494
|
* The composite's size and the shift placing each frame in it, so the
|
|
41908
42495
|
* leftmost and topmost frames sit one margin in and one margin is left past
|
|
41909
|
-
* the far edges
|
|
42496
|
+
* the far edges, each frame's linked widths included. Refuses
|
|
42497
|
+
* `capture-too-large` past Chromium's screenshot limit.
|
|
41910
42498
|
*/
|
|
41911
42499
|
function compositeBounds(page, frames, scale = 1) {
|
|
41912
|
-
const
|
|
41913
|
-
const
|
|
41914
|
-
const
|
|
41915
|
-
const
|
|
42500
|
+
const extents = frames.map(({ box, widths }) => drawnExtent(box, widths ?? []));
|
|
42501
|
+
const left = Math.min(...extents.map((box) => box.x));
|
|
42502
|
+
const top = Math.min(...extents.map((box) => box.y));
|
|
42503
|
+
const right = Math.max(...extents.map((box) => box.x + box.width));
|
|
42504
|
+
const bottom = Math.max(...extents.map((box) => box.y + box.height));
|
|
41916
42505
|
const width = right - left + 80;
|
|
41917
42506
|
const height = bottom - top + 80;
|
|
41918
42507
|
if (width * scale > 16384 || height * scale > 16384) {
|
|
@@ -41933,23 +42522,39 @@ function compositeBounds(page, frames, scale = 1) {
|
|
|
41933
42522
|
};
|
|
41934
42523
|
}
|
|
41935
42524
|
/**
|
|
41936
|
-
* Captures each frame in each theme at its layout size times `scale`, one PNG
|
|
41937
|
-
*
|
|
41938
|
-
*
|
|
42525
|
+
* Captures each frame in each theme at its layout size times `scale`, one PNG
|
|
42526
|
+
* apiece, and again at each linked width it lists, at the height that width
|
|
42527
|
+
* holds. Every image renders before any is written, so a refusal on one frame
|
|
42528
|
+
* leaves no half-written set an agent could read as current. A `scroll`
|
|
42529
|
+
* offset shoots each view that far down, clamped to the page's end. `width`
|
|
42530
|
+
* shoots each frame at that one width alone, its own or a linked one.
|
|
41939
42531
|
*/
|
|
41940
|
-
async function captureFrameImages(browser, { baseUrl, frames, themes, out, scale = 1 }) {
|
|
42532
|
+
async function captureFrameImages(browser, { baseUrl, frames, themes, out, scale = 1, scroll, width }) {
|
|
41941
42533
|
const rendered = [];
|
|
41942
|
-
for (const frame of frames) for (const theme of themes)
|
|
41943
|
-
|
|
41944
|
-
|
|
41945
|
-
|
|
41946
|
-
|
|
41947
|
-
|
|
41948
|
-
|
|
41949
|
-
|
|
41950
|
-
|
|
42534
|
+
for (const frame of frames) for (const view of viewsOf(frame, width)) for (const theme of themes) {
|
|
42535
|
+
const shot = await renderFrame(browser, baseUrl, frame, view, theme, scale, scroll);
|
|
42536
|
+
const linked = view.width === frame.box.width ? void 0 : view.width;
|
|
42537
|
+
rendered.push({
|
|
42538
|
+
ref: frame.ref,
|
|
42539
|
+
theme,
|
|
42540
|
+
path: frameImagePath(out, frame, theme, scale, scroll, linked),
|
|
42541
|
+
width: view.width,
|
|
42542
|
+
height: view.height,
|
|
42543
|
+
scale,
|
|
42544
|
+
...shot.scrollY === void 0 ? {} : { scrollY: shot.scrollY },
|
|
42545
|
+
bytes: shot.bytes
|
|
42546
|
+
});
|
|
42547
|
+
}
|
|
41951
42548
|
return writeImages(rendered);
|
|
41952
42549
|
}
|
|
42550
|
+
/** The boxes a frame shows at, its own first, or the one `width` names. */
|
|
42551
|
+
function viewsOf(frame, width) {
|
|
42552
|
+
const views = [{
|
|
42553
|
+
width: frame.box.width,
|
|
42554
|
+
height: frame.box.height
|
|
42555
|
+
}, ...frame.widths];
|
|
42556
|
+
return width === void 0 ? views : views.filter((view) => view.width === width);
|
|
42557
|
+
}
|
|
41953
42558
|
/**
|
|
41954
42559
|
* Captures one image of a page per theme, every frame at its layout box on
|
|
41955
42560
|
* the theme's canvas color. Each frame renders as it does alone, font check
|
|
@@ -41960,9 +42565,9 @@ async function captureComposite(browser, { baseUrl, page, frames, themes, out, s
|
|
|
41960
42565
|
const rendered = [];
|
|
41961
42566
|
for (const theme of themes) {
|
|
41962
42567
|
const tiles = [];
|
|
41963
|
-
for (const frame of frames) {
|
|
41964
|
-
const bytes = await renderFrame(browser, baseUrl, frame, theme, scale);
|
|
41965
|
-
tiles.push(`<img src="data:image/png;base64,${bytes.toString("base64")}" style="position:absolute;left:${
|
|
42568
|
+
for (const frame of frames) for (const box of [frame.box, ...linkedBoxes(frame.box, frame.widths)]) {
|
|
42569
|
+
const { bytes } = await renderFrame(browser, baseUrl, frame, box, theme, scale);
|
|
42570
|
+
tiles.push(`<img src="data:image/png;base64,${bytes.toString("base64")}" style="position:absolute;left:${box.x + bounds.dx}px;top:${box.y + bounds.dy}px;width:${box.width}px;height:${box.height}px">`);
|
|
41966
42571
|
}
|
|
41967
42572
|
rendered.push({
|
|
41968
42573
|
ref: page.ref,
|
|
@@ -41976,10 +42581,10 @@ async function captureComposite(browser, { baseUrl, page, frames, themes, out, s
|
|
|
41976
42581
|
}
|
|
41977
42582
|
return writeImages(rendered);
|
|
41978
42583
|
}
|
|
41979
|
-
async function renderFrame(browser, baseUrl, frame, theme, scale) {
|
|
42584
|
+
async function renderFrame(browser, baseUrl, frame, view, theme, scale, scroll) {
|
|
41980
42585
|
const box = {
|
|
41981
|
-
width:
|
|
41982
|
-
height:
|
|
42586
|
+
width: view.width,
|
|
42587
|
+
height: view.height
|
|
41983
42588
|
};
|
|
41984
42589
|
assertScreenshotFits(frame.ref, box, scale);
|
|
41985
42590
|
const opened = await openFrame(browser, {
|
|
@@ -41990,11 +42595,24 @@ async function renderFrame(browser, baseUrl, frame, theme, scale) {
|
|
|
41990
42595
|
scale
|
|
41991
42596
|
});
|
|
41992
42597
|
try {
|
|
41993
|
-
|
|
42598
|
+
const scrollY = scroll === void 0 ? void 0 : await opened.page.evaluate(scrollAndSettle, scroll);
|
|
42599
|
+
return {
|
|
42600
|
+
bytes: await opened.page.screenshot(SCREENSHOT),
|
|
42601
|
+
scrollY
|
|
42602
|
+
};
|
|
41994
42603
|
} finally {
|
|
41995
42604
|
await opened.close();
|
|
41996
42605
|
}
|
|
41997
42606
|
}
|
|
42607
|
+
function scrollAndSettle(top) {
|
|
42608
|
+
window.scrollTo({
|
|
42609
|
+
top,
|
|
42610
|
+
behavior: "instant"
|
|
42611
|
+
});
|
|
42612
|
+
return new Promise((resolve) => {
|
|
42613
|
+
requestAnimationFrame(() => requestAnimationFrame(() => resolve(Math.round(window.scrollY))));
|
|
42614
|
+
});
|
|
42615
|
+
}
|
|
41998
42616
|
async function renderComposite(browser, { width, height }, theme, tiles, scale) {
|
|
41999
42617
|
const context = await browser.newContext({
|
|
42000
42618
|
viewport: {
|
|
@@ -42027,9 +42645,10 @@ function registerCapture(program, context) {
|
|
|
42027
42645
|
"light",
|
|
42028
42646
|
"dark",
|
|
42029
42647
|
"both"
|
|
42030
|
-
]).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("--out <dir>", "the folder images land in, defaulting to the board's .run/captures/"), context, async ([ref], options) => {
|
|
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) => {
|
|
42031
42649
|
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.");
|
|
42032
42650
|
if (options.composite && options.page === void 0) throw new FrameboardError("usage", "--composite needs --page.");
|
|
42651
|
+
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.");
|
|
42033
42652
|
const root = await boardOf(options, io);
|
|
42034
42653
|
const refOptions = {
|
|
42035
42654
|
project: options.project,
|
|
@@ -42068,10 +42687,11 @@ function registerCapture(program, context) {
|
|
|
42068
42687
|
}));
|
|
42069
42688
|
return {
|
|
42070
42689
|
data: { images },
|
|
42071
|
-
human: describe$
|
|
42690
|
+
human: describe$7(images)
|
|
42072
42691
|
};
|
|
42073
42692
|
}
|
|
42074
42693
|
const frame = await readFrame$1(root, ref ?? "", refOptions);
|
|
42694
|
+
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 });
|
|
42075
42695
|
const out = await outOf();
|
|
42076
42696
|
const images = await withFrameHost({
|
|
42077
42697
|
root,
|
|
@@ -42081,11 +42701,12 @@ function registerCapture(program, context) {
|
|
|
42081
42701
|
frames: [frame],
|
|
42082
42702
|
themes,
|
|
42083
42703
|
out,
|
|
42084
|
-
scale: options.scale
|
|
42704
|
+
scale: options.scale,
|
|
42705
|
+
scroll: options.scroll
|
|
42085
42706
|
}));
|
|
42086
42707
|
return {
|
|
42087
42708
|
data: { images },
|
|
42088
|
-
human: describe$
|
|
42709
|
+
human: describe$7(images)
|
|
42089
42710
|
};
|
|
42090
42711
|
});
|
|
42091
42712
|
}
|
|
@@ -42098,7 +42719,7 @@ async function pageOf(root, ref, options) {
|
|
|
42098
42719
|
const { pages } = await readPageOrder(join(root, resolved.project));
|
|
42099
42720
|
return scanPage(root, resolved.project, resolved.page, pages.indexOf(resolved.page));
|
|
42100
42721
|
}
|
|
42101
|
-
function describe$
|
|
42722
|
+
function describe$7(images) {
|
|
42102
42723
|
return images.map((image) => `Wrote ${image.path}`).join("\n");
|
|
42103
42724
|
}
|
|
42104
42725
|
// src/server/checks/custom-properties.ts
|
|
@@ -42108,7 +42729,7 @@ const CUSTOM_PROPERTY_RULES = [{
|
|
|
42108
42729
|
severity: "warning",
|
|
42109
42730
|
description: "A var() with no fallback names a custom property no token sheet, frame sheet, style attribute, or script write declares"
|
|
42110
42731
|
}];
|
|
42111
|
-
const finding$
|
|
42732
|
+
const finding$10 = findingFor(CUSTOM_PROPERTY_RULES);
|
|
42112
42733
|
/** A `var()` naming its property, with no fallback after a comma. */
|
|
42113
42734
|
const BARE_VAR = /var\(\s*(--[\w-]+)\s*\)/g;
|
|
42114
42735
|
/**
|
|
@@ -42167,7 +42788,7 @@ function checkUnknownTokens(source, tokens) {
|
|
|
42167
42788
|
if (element.name !== "script") continue;
|
|
42168
42789
|
for (const name of scriptWrites(scriptText(element, source))) declared.add(name);
|
|
42169
42790
|
}
|
|
42170
|
-
return uses.filter((use) => !declared.has(use.name)).map((use) => finding$
|
|
42791
|
+
return uses.filter((use) => !declared.has(use.name)).map((use) => finding$10("unknown-token", {
|
|
42171
42792
|
frame: source.ref,
|
|
42172
42793
|
path: use.path,
|
|
42173
42794
|
message: `var(${use.name}) names a custom property nothing declares, so the declaration resolves to nothing. Use a token the project's tokens.css declares, or give it a fallback, such as var(${use.name}, red). If a script sets it at runtime under a name the check cannot read, the fallback is the way out.`,
|
|
@@ -42241,7 +42862,7 @@ const FONT_RULES = [
|
|
|
42241
42862
|
description: "Every text element's first family is one of the project's allowed fonts"
|
|
42242
42863
|
}
|
|
42243
42864
|
];
|
|
42244
|
-
const finding$
|
|
42865
|
+
const finding$9 = findingFor(FONT_RULES);
|
|
42245
42866
|
const GENERIC_FAMILIES = /* @__PURE__ */ new Set([
|
|
42246
42867
|
"serif",
|
|
42247
42868
|
"sans-serif",
|
|
@@ -42284,7 +42905,7 @@ function checkFonts(source, cascade, config) {
|
|
|
42284
42905
|
else if (allowed && !allowed.includes(family.toLowerCase())) push(unlisted, family, element);
|
|
42285
42906
|
}
|
|
42286
42907
|
const path = boardPath(source.root, source.path);
|
|
42287
|
-
const at = (rule, elements, message) => finding$
|
|
42908
|
+
const at = (rule, elements, message) => finding$9(rule, {
|
|
42288
42909
|
frame: source.ref,
|
|
42289
42910
|
path,
|
|
42290
42911
|
message: `${message} ${described(elements)}`,
|
|
@@ -42334,7 +42955,7 @@ const LINK_RULES = [
|
|
|
42334
42955
|
description: "Every local file a frame loads exists"
|
|
42335
42956
|
}
|
|
42336
42957
|
];
|
|
42337
|
-
const finding$
|
|
42958
|
+
const finding$8 = findingFor(LINK_RULES);
|
|
42338
42959
|
/**
|
|
42339
42960
|
* The attributes that load a resource, by element. An `a href` navigates
|
|
42340
42961
|
* rather than loads, so it is left out.
|
|
@@ -42410,16 +43031,16 @@ function judge(source, load) {
|
|
|
42410
43031
|
path: load.path,
|
|
42411
43032
|
location: load.location
|
|
42412
43033
|
};
|
|
42413
|
-
if (hasScheme(url)) return [finding$
|
|
43034
|
+
if (hasScheme(url)) return [finding$8("network", {
|
|
42414
43035
|
...fields,
|
|
42415
43036
|
message: `${load.via} loads ${url} over the network. Save the file into the page folder or the project's assets/ and link it there.`
|
|
42416
43037
|
})];
|
|
42417
43038
|
const target = localTarget(url, load.base);
|
|
42418
|
-
if (target === null || !allowed(source, target)) return [finding$
|
|
43039
|
+
if (target === null || !allowed(source, target)) return [finding$8("outside-link", {
|
|
42419
43040
|
...fields,
|
|
42420
43041
|
message: `${load.via} loads ${url}, outside this page's folder and the project's assets/. Move the file into one of them.`
|
|
42421
43042
|
})];
|
|
42422
|
-
if (!existsSync(target)) return [finding$
|
|
43043
|
+
if (!existsSync(target)) return [finding$8("missing-file", {
|
|
42423
43044
|
...fields,
|
|
42424
43045
|
message: `${load.via} loads ${url}, which does not exist.`
|
|
42425
43046
|
})];
|
|
@@ -42508,7 +43129,7 @@ const STRUCTURE_RULES = [
|
|
|
42508
43129
|
description: "The browser rebuilds the tree the file writes, adding an element it never opens, closing one it never closed, or moving one out of a table"
|
|
42509
43130
|
}
|
|
42510
43131
|
];
|
|
42511
|
-
const finding$
|
|
43132
|
+
const finding$7 = findingFor(STRUCTURE_RULES);
|
|
42512
43133
|
/**
|
|
42513
43134
|
* Elements a parser may imply with no start tag in a valid file. A `tbody`
|
|
42514
43135
|
* is `table-tbody`'s to report.
|
|
@@ -42571,12 +43192,12 @@ const MALFORMED = {
|
|
|
42571
43192
|
function checkNaming(target, path) {
|
|
42572
43193
|
const ref = `${target.project}/${target.page}/${target.name}`;
|
|
42573
43194
|
const findings = [];
|
|
42574
|
-
if (!isValidName(target.page) || isReservedPageName(target.page)) findings.push(finding$
|
|
43195
|
+
if (!isValidName(target.page) || isReservedPageName(target.page)) findings.push(finding$7("naming", {
|
|
42575
43196
|
frame: ref,
|
|
42576
43197
|
path,
|
|
42577
43198
|
message: `Page name ${target.page} is not valid. Use letters, digits, dots, dashes, and underscores, opening with a letter or digit.`
|
|
42578
43199
|
}));
|
|
42579
|
-
if (!isValidName(target.name)) findings.push(finding$
|
|
43200
|
+
if (!isValidName(target.name)) findings.push(finding$7("naming", {
|
|
42580
43201
|
frame: ref,
|
|
42581
43202
|
path,
|
|
42582
43203
|
message: `Frame name ${target.name} is not valid. Use letters, digits, dots, dashes, and underscores, opening with a letter or digit.`
|
|
@@ -42585,7 +43206,7 @@ function checkNaming(target, path) {
|
|
|
42585
43206
|
}
|
|
42586
43207
|
/** `dot-folder`, over a project's folder names. */
|
|
42587
43208
|
function checkDotFolders(root, projectDir, folders) {
|
|
42588
|
-
return folders.filter((name) => name.startsWith(".")).map((name) => finding$
|
|
43209
|
+
return folders.filter((name) => name.startsWith(".")).map((name) => finding$7("dot-folder", {
|
|
42589
43210
|
frame: null,
|
|
42590
43211
|
path: boardPath(root, `${projectDir}/${name}`),
|
|
42591
43212
|
message: `Folder ${name} opens with a dot, so the board never shows it. Rename it or move it out of the project.`
|
|
@@ -42597,13 +43218,13 @@ function checkMarkup(source) {
|
|
|
42597
43218
|
const findings = [];
|
|
42598
43219
|
const head = source.elements.find((element) => element.name === "head");
|
|
42599
43220
|
const body = source.elements.find((element) => element.name === "body");
|
|
42600
|
-
if (head && startTagLocation(head) && !(body && startTagLocation(body))) findings.push(finding$
|
|
43221
|
+
if (head && startTagLocation(head) && !(body && startTagLocation(body))) findings.push(finding$7("head-body", {
|
|
42601
43222
|
frame: source.ref,
|
|
42602
43223
|
path,
|
|
42603
43224
|
message: "The frame states <head> and no <body>. Wrap the visible content in <body>.",
|
|
42604
43225
|
location: startTagLocation(head)
|
|
42605
43226
|
}));
|
|
42606
|
-
for (const table of source.elements.filter(isTable)) if (table.children.some((child) => child.type === "tag" && child.name === "tbody" && !child.sourceCodeLocation?.startTag)) findings.push(finding$
|
|
43227
|
+
for (const table of source.elements.filter(isTable)) if (table.children.some((child) => child.type === "tag" && child.name === "tbody" && !child.sourceCodeLocation?.startTag)) findings.push(finding$7("table-tbody", {
|
|
42607
43228
|
frame: source.ref,
|
|
42608
43229
|
path,
|
|
42609
43230
|
message: "This table holds rows with no <tbody>, so the browser adds one the file does not hold. State the <tbody>.",
|
|
@@ -42630,7 +43251,7 @@ function checkMalformedTags(source) {
|
|
|
42630
43251
|
if (reported.has(tag)) continue;
|
|
42631
43252
|
reported.add(tag);
|
|
42632
43253
|
}
|
|
42633
|
-
findings.push(finding$
|
|
43254
|
+
findings.push(finding$7("malformed-tag", {
|
|
42634
43255
|
frame: source.ref,
|
|
42635
43256
|
path,
|
|
42636
43257
|
message: `${tag ? `<${tag.name}> raises ${error.code}` : error.code}. ${message}`,
|
|
@@ -42648,7 +43269,7 @@ function checkMalformedTags(source) {
|
|
|
42648
43269
|
function checkNesting(source) {
|
|
42649
43270
|
const path = boardPath(source.root, source.path);
|
|
42650
43271
|
const findings = [];
|
|
42651
|
-
const report = (message, location) => findings.push(finding$
|
|
43272
|
+
const report = (message, location) => findings.push(finding$7("nesting", {
|
|
42652
43273
|
frame: source.ref,
|
|
42653
43274
|
path,
|
|
42654
43275
|
message,
|
|
@@ -42711,14 +43332,14 @@ const UPPERCASE_RULES = [{
|
|
|
42711
43332
|
configKey: "noUppercase",
|
|
42712
43333
|
description: "No text is set in capitals, through text-transform: uppercase or a word of more than three capital letters"
|
|
42713
43334
|
}];
|
|
42714
|
-
const finding$
|
|
43335
|
+
const finding$6 = findingFor(UPPERCASE_RULES);
|
|
42715
43336
|
const CAPITALS = /(?<![\p{L}\p{N}])\p{Lu}{4,}(?![\p{L}\p{N}])/u;
|
|
42716
43337
|
/** `uppercase`, which runs only when the project sets `noUppercase`. */
|
|
42717
43338
|
function checkUppercase(source, cascade) {
|
|
42718
43339
|
const capitalized = textElements(source).filter((element) => cascade.textTransform(element) === "uppercase" || ownText(element).some((text) => CAPITALS.test(text)));
|
|
42719
43340
|
const first = capitalized[0];
|
|
42720
43341
|
if (!first) return [];
|
|
42721
|
-
return [finding$
|
|
43342
|
+
return [finding$6("uppercase", {
|
|
42722
43343
|
frame: source.ref,
|
|
42723
43344
|
path: boardPath(source.root, source.path),
|
|
42724
43345
|
message: `Text is set in capitals, which the project does not allow. Write it in sentence case. ${described(capitalized)}`,
|
|
@@ -42770,7 +43391,7 @@ function readProjectContext(root, project, boardSheet) {
|
|
|
42770
43391
|
* The project's `checks` config, read by hand rather than through the
|
|
42771
43392
|
* project record's schema, which the hook cannot afford to load. A file that
|
|
42772
43393
|
* does not read, or a key of the wrong type, leaves that rule off. The
|
|
42773
|
-
* server's browser checker reads it too, for `minFontSize`.
|
|
43394
|
+
* server's browser checker reads it too, for `minFontSize` and `minContrast`.
|
|
42774
43395
|
*/
|
|
42775
43396
|
function readConfig(root, project) {
|
|
42776
43397
|
let parsed;
|
|
@@ -42785,11 +43406,204 @@ function readConfig(root, project) {
|
|
|
42785
43406
|
if (Array.isArray(checks.allowedFonts) && checks.allowedFonts.every((font) => typeof font === "string")) config.allowedFonts = checks.allowedFonts;
|
|
42786
43407
|
if (typeof checks.noUppercase === "boolean") config.noUppercase = checks.noUppercase;
|
|
42787
43408
|
if (typeof checks.minFontSize === "number" && checks.minFontSize > 0) config.minFontSize = checks.minFontSize;
|
|
43409
|
+
if (typeof checks.minContrast === "number" && checks.minContrast >= 1) config.minContrast = checks.minContrast;
|
|
42788
43410
|
return config;
|
|
42789
43411
|
}
|
|
42790
43412
|
function isRecord(value) {
|
|
42791
43413
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
42792
43414
|
}
|
|
43415
|
+
// src/server/checks/browser/contrast.ts
|
|
43416
|
+
const CONTRAST_RULES = [{
|
|
43417
|
+
id: "min-contrast",
|
|
43418
|
+
tier: "browser",
|
|
43419
|
+
severity: "warning",
|
|
43420
|
+
configKey: "minContrast",
|
|
43421
|
+
description: "Text contrasts with the solid color behind it at a lower ratio than the project sets, 4.5 being WCAG's, with large text held to two thirds of it. Text over an image, a gradient, or an effect is not measured."
|
|
43422
|
+
}];
|
|
43423
|
+
const finding$5 = findingFor(CONTRAST_RULES);
|
|
43424
|
+
/** WCAG's large text is 18 pt, or 14 pt bold, which hold 3:1 against 4.5:1. */
|
|
43425
|
+
const LARGE_SHARE = 2 / 3;
|
|
43426
|
+
/**
|
|
43427
|
+
* Reports text whose contrast with the solid color behind it falls under
|
|
43428
|
+
* `minContrast`, naming the element furthest under and how many more fall
|
|
43429
|
+
* under, at most one finding per frame.
|
|
43430
|
+
*/
|
|
43431
|
+
async function checkContrast(page, target, minContrast) {
|
|
43432
|
+
const under = (await page.evaluate(readContrasts)).map((text) => ({
|
|
43433
|
+
...text,
|
|
43434
|
+
minimum: text.large ? minContrast * LARGE_SHARE : minContrast
|
|
43435
|
+
})).filter((text) => text.ratio < text.minimum);
|
|
43436
|
+
if (under.length === 0) return [];
|
|
43437
|
+
const worst = under.reduce((least, text) => text.ratio / text.minimum < least.ratio / least.minimum ? text : least);
|
|
43438
|
+
const others = under.length - 1;
|
|
43439
|
+
const rest = others === 0 ? "" : `, and ${others} more ${others === 1 ? "element is" : "elements are"} under it`;
|
|
43440
|
+
const minimum = worst.large ? `${formatRatio(worst.minimum)}:1 minimum for large text` : `${formatRatio(worst.minimum)}:1 minimum`;
|
|
43441
|
+
return [finding$5("min-contrast", {
|
|
43442
|
+
frame: target.ref,
|
|
43443
|
+
path: target.path,
|
|
43444
|
+
message: `${target.ref} sets text in <${worst.tag}> at element ${worst.index} at ${floorRatio(worst.ratio)}:1, ${worst.foreground} on ${worst.background}, under the project's ${minimum}${rest}.`
|
|
43445
|
+
})];
|
|
43446
|
+
}
|
|
43447
|
+
/** Floors to two places, so a ratio just under the minimum never prints as it. */
|
|
43448
|
+
function floorRatio(ratio) {
|
|
43449
|
+
return (Math.floor(ratio * 100) / 100).toFixed(2);
|
|
43450
|
+
}
|
|
43451
|
+
function formatRatio(ratio) {
|
|
43452
|
+
return String(Math.round(ratio * 100) / 100);
|
|
43453
|
+
}
|
|
43454
|
+
function readContrasts() {
|
|
43455
|
+
const notText = /* @__PURE__ */ new Set([
|
|
43456
|
+
"HTML",
|
|
43457
|
+
"HEAD",
|
|
43458
|
+
"TITLE",
|
|
43459
|
+
"SCRIPT",
|
|
43460
|
+
"STYLE",
|
|
43461
|
+
"NOSCRIPT",
|
|
43462
|
+
"TEMPLATE"
|
|
43463
|
+
]);
|
|
43464
|
+
const opaqueTags = /* @__PURE__ */ new Set([
|
|
43465
|
+
"IMG",
|
|
43466
|
+
"VIDEO",
|
|
43467
|
+
"CANVAS",
|
|
43468
|
+
"IFRAME",
|
|
43469
|
+
"OBJECT",
|
|
43470
|
+
"EMBED",
|
|
43471
|
+
"PICTURE"
|
|
43472
|
+
]);
|
|
43473
|
+
const candidates = [];
|
|
43474
|
+
let index = 0;
|
|
43475
|
+
for (const element of document.querySelectorAll("*")) {
|
|
43476
|
+
if (element.closest("[data-frameboard]")) continue;
|
|
43477
|
+
const own = index;
|
|
43478
|
+
index += 1;
|
|
43479
|
+
if (notText.has(element.tagName.toUpperCase())) continue;
|
|
43480
|
+
const text = [...element.childNodes].find((node) => node.nodeType === Node.TEXT_NODE && Boolean(node.textContent?.trim()));
|
|
43481
|
+
if (text) candidates.push({
|
|
43482
|
+
element,
|
|
43483
|
+
index: own,
|
|
43484
|
+
text
|
|
43485
|
+
});
|
|
43486
|
+
}
|
|
43487
|
+
const canvas = document.createElement("canvas");
|
|
43488
|
+
canvas.width = 1;
|
|
43489
|
+
canvas.height = 1;
|
|
43490
|
+
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
43491
|
+
if (!context) return [];
|
|
43492
|
+
const toRgba = (color) => {
|
|
43493
|
+
context.clearRect(0, 0, 1, 1);
|
|
43494
|
+
context.fillStyle = "#000";
|
|
43495
|
+
context.fillStyle = color;
|
|
43496
|
+
context.fillRect(0, 0, 1, 1);
|
|
43497
|
+
const [r = 0, g = 0, b = 0, a = 0] = context.getImageData(0, 0, 1, 1).data;
|
|
43498
|
+
const written = /^rgba\(.*,\s*([\d.]+)()\)$/.exec(color) ?? /\/\s*([\d.]+)(%?)\s*\)$/.exec(color);
|
|
43499
|
+
return [
|
|
43500
|
+
r,
|
|
43501
|
+
g,
|
|
43502
|
+
b,
|
|
43503
|
+
written?.[1] ? Number.parseFloat(written[1]) / (written[2] ? 100 : 1) : a / 255
|
|
43504
|
+
];
|
|
43505
|
+
};
|
|
43506
|
+
const over = (top, below) => {
|
|
43507
|
+
const [r, g, b, a] = top;
|
|
43508
|
+
return [
|
|
43509
|
+
r * a + below[0] * (1 - a),
|
|
43510
|
+
g * a + below[1] * (1 - a),
|
|
43511
|
+
b * a + below[2] * (1 - a),
|
|
43512
|
+
1
|
|
43513
|
+
];
|
|
43514
|
+
};
|
|
43515
|
+
const luminance = ([r, g, b]) => {
|
|
43516
|
+
const channel = (value) => {
|
|
43517
|
+
const s = value / 255;
|
|
43518
|
+
return s <= .04045 ? s / 12.92 : ((s + .055) / 1.055) ** 2.4;
|
|
43519
|
+
};
|
|
43520
|
+
return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
|
|
43521
|
+
};
|
|
43522
|
+
const hex = (color) => `#${color.slice(0, 3).map((value) => Math.round(value).toString(16).padStart(2, "0")).join("")}`;
|
|
43523
|
+
const opacityOf = (element) => {
|
|
43524
|
+
let opacity = 1;
|
|
43525
|
+
for (let at = element; at; at = at.parentElement) opacity *= Number.parseFloat(getComputedStyle(at).opacity);
|
|
43526
|
+
return opacity;
|
|
43527
|
+
};
|
|
43528
|
+
const paintsEffect = (style) => style.backgroundImage !== "none" || style.filter !== "none" || style.backdropFilter !== "none" || style.mixBlendMode !== "normal";
|
|
43529
|
+
const probe = document.createElement("div");
|
|
43530
|
+
probe.style.backgroundColor = "Canvas";
|
|
43531
|
+
document.documentElement.append(probe);
|
|
43532
|
+
const canvasColor = toRgba(getComputedStyle(probe).backgroundColor);
|
|
43533
|
+
probe.remove();
|
|
43534
|
+
const html = document.documentElement;
|
|
43535
|
+
const htmlStyle = getComputedStyle(html);
|
|
43536
|
+
const body = document.body;
|
|
43537
|
+
const bodyStyle = body ? getComputedStyle(body) : null;
|
|
43538
|
+
const bodyPropagates = toRgba(htmlStyle.backgroundColor)[3] === 0 && htmlStyle.backgroundImage === "none";
|
|
43539
|
+
const rootStyle = bodyPropagates && bodyStyle ? bodyStyle : htmlStyle;
|
|
43540
|
+
const rootUnmeasurable = paintsEffect(rootStyle);
|
|
43541
|
+
const root = over(toRgba(rootStyle.backgroundColor), canvasColor);
|
|
43542
|
+
const running = document.getAnimations().filter((animation) => animation.playState === "running").flatMap((animation) => {
|
|
43543
|
+
const effect = animation.effect;
|
|
43544
|
+
return effect instanceof KeyframeEffect && effect.target ? [effect.target] : [];
|
|
43545
|
+
});
|
|
43546
|
+
const hits = document.createElement("style");
|
|
43547
|
+
hits.textContent = "* { pointer-events: auto !important; }";
|
|
43548
|
+
document.head.append(hits);
|
|
43549
|
+
const found = [];
|
|
43550
|
+
try {
|
|
43551
|
+
for (const { element, index: own, text } of candidates) {
|
|
43552
|
+
const style = getComputedStyle(element);
|
|
43553
|
+
if (style.visibility !== "visible") continue;
|
|
43554
|
+
const range = document.createRange();
|
|
43555
|
+
range.selectNodeContents(text);
|
|
43556
|
+
const rect = range.getBoundingClientRect();
|
|
43557
|
+
if (rect.width <= 1 || rect.height <= 1) continue;
|
|
43558
|
+
if (running.some((target) => target.contains(element))) continue;
|
|
43559
|
+
let clipped = false;
|
|
43560
|
+
for (let at = element; at; at = at.parentElement) if (getComputedStyle(at).backgroundClip === "text") clipped = true;
|
|
43561
|
+
if (clipped) continue;
|
|
43562
|
+
const stack = document.elementsFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
|
|
43563
|
+
const from = stack.indexOf(element);
|
|
43564
|
+
if (from === -1) continue;
|
|
43565
|
+
const layers = [];
|
|
43566
|
+
let measurable = true;
|
|
43567
|
+
let opaque = false;
|
|
43568
|
+
for (const layer of stack.slice(from)) {
|
|
43569
|
+
if (layer === html || bodyPropagates && layer === body) continue;
|
|
43570
|
+
const layerStyle = getComputedStyle(layer);
|
|
43571
|
+
if (opaqueTags.has(layer.tagName.toUpperCase()) || layer instanceof SVGElement || paintsEffect(layerStyle)) {
|
|
43572
|
+
measurable = false;
|
|
43573
|
+
break;
|
|
43574
|
+
}
|
|
43575
|
+
const color = toRgba(layerStyle.backgroundColor);
|
|
43576
|
+
color[3] *= opacityOf(layer);
|
|
43577
|
+
if (color[3] === 0) continue;
|
|
43578
|
+
layers.push(color);
|
|
43579
|
+
if (color[3] >= 1) {
|
|
43580
|
+
opaque = true;
|
|
43581
|
+
break;
|
|
43582
|
+
}
|
|
43583
|
+
}
|
|
43584
|
+
if (!measurable || !opaque && rootUnmeasurable) continue;
|
|
43585
|
+
const background = layers.reduceRight((below, layer) => over(layer, below), root);
|
|
43586
|
+
const fill = toRgba(style.webkitTextFillColor || style.color);
|
|
43587
|
+
fill[3] *= opacityOf(element);
|
|
43588
|
+
const foreground = over(fill, background);
|
|
43589
|
+
const lighter = Math.max(luminance(foreground), luminance(background));
|
|
43590
|
+
const darker = Math.min(luminance(foreground), luminance(background));
|
|
43591
|
+
const size = Number.parseFloat(style.fontSize);
|
|
43592
|
+
const weight = Number.parseFloat(style.fontWeight);
|
|
43593
|
+
found.push({
|
|
43594
|
+
index: own,
|
|
43595
|
+
tag: element.tagName.toLowerCase(),
|
|
43596
|
+
ratio: (lighter + .05) / (darker + .05),
|
|
43597
|
+
large: size >= 24 || size >= 18.66 && weight >= 700,
|
|
43598
|
+
foreground: hex(foreground),
|
|
43599
|
+
background: hex(background)
|
|
43600
|
+
});
|
|
43601
|
+
}
|
|
43602
|
+
} finally {
|
|
43603
|
+
hits.remove();
|
|
43604
|
+
}
|
|
43605
|
+
return found;
|
|
43606
|
+
}
|
|
42793
43607
|
// src/server/checks/browser/declarations.ts
|
|
42794
43608
|
const DECLARATION_RULES = [{
|
|
42795
43609
|
id: "dropped-declaration",
|
|
@@ -42797,7 +43611,7 @@ const DECLARATION_RULES = [{
|
|
|
42797
43611
|
severity: "warning",
|
|
42798
43612
|
description: "A declaration the page's own CSS parser drops, being a misspelled property, a value it cannot read, or a sheet that stops parsing"
|
|
42799
43613
|
}];
|
|
42800
|
-
const finding$
|
|
43614
|
+
const finding$4 = findingFor(DECLARATION_RULES);
|
|
42801
43615
|
/**
|
|
42802
43616
|
* At-rules whose blocks hold descriptors rather than properties, which
|
|
42803
43617
|
* `CSS.supports` cannot answer, and `@supports`, whose block is a
|
|
@@ -42822,7 +43636,7 @@ async function checkDeclarations(page, source) {
|
|
|
42822
43636
|
const path = boardPath(source.root, sheet.path);
|
|
42823
43637
|
const text = sheet.origin === "style" ? source.html : sheet.css;
|
|
42824
43638
|
const { root, errors } = parseSheet$1(sheet.css);
|
|
42825
|
-
for (const error of errors) findings.push(finding$
|
|
43639
|
+
for (const error of errors) findings.push(finding$4("dropped-declaration", {
|
|
42826
43640
|
frame: source.ref,
|
|
42827
43641
|
path,
|
|
42828
43642
|
message: breakMessage(error),
|
|
@@ -42861,7 +43675,7 @@ async function checkDeclarations(page, source) {
|
|
|
42861
43675
|
const supported = await page.evaluate((pairs) => pairs.map(([property, value]) => CSS.supports(property, value)), written.map((each) => [each.property, each.value]));
|
|
42862
43676
|
written.forEach((each, index) => {
|
|
42863
43677
|
if (supported[index]) return;
|
|
42864
|
-
findings.push(finding$
|
|
43678
|
+
findings.push(finding$4("dropped-declaration", {
|
|
42865
43679
|
frame: source.ref,
|
|
42866
43680
|
path: each.path,
|
|
42867
43681
|
message: `The browser drops ${each.property}: ${each.value}, since it reads no such property or no such value for it. Check the spelling of both, and the unit of a length, such as 12px.`,
|
|
@@ -42901,7 +43715,7 @@ const FONT_SIZE_RULES = [{
|
|
|
42901
43715
|
configKey: "minFontSize",
|
|
42902
43716
|
description: "Text renders smaller than the project sets as its minimum size in pixels"
|
|
42903
43717
|
}];
|
|
42904
|
-
const finding$
|
|
43718
|
+
const finding$3 = findingFor(FONT_SIZE_RULES);
|
|
42905
43719
|
/**
|
|
42906
43720
|
* Reports text under `minFontSize` pixels, naming the smallest element and
|
|
42907
43721
|
* how many more fall under, at most one finding per frame.
|
|
@@ -42912,7 +43726,7 @@ async function checkFontSize(page, target, minFontSize) {
|
|
|
42912
43726
|
const smallest = under.reduce((least, text) => text.size < least.size ? text : least);
|
|
42913
43727
|
const others = under.length - 1;
|
|
42914
43728
|
const rest = others === 0 ? "" : `, and ${others} more ${others === 1 ? "element is" : "elements are"} under it`;
|
|
42915
|
-
return [finding$
|
|
43729
|
+
return [finding$3("min-font-size", {
|
|
42916
43730
|
frame: target.ref,
|
|
42917
43731
|
path: target.path,
|
|
42918
43732
|
message: `${target.ref} sets text at ${smallest.size} px in <${smallest.tag}> at element ${smallest.index}, under the project's ${minFontSize} px minimum${rest}.`
|
|
@@ -42951,17 +43765,23 @@ const HUG_MAX_WIDTH = FRAME_SIZES.desktop.width;
|
|
|
42951
43765
|
* Measures a frame's content the way `frame fit` and the server's hug step
|
|
42952
43766
|
* both read it, in one page resized between readings. A hugging width takes
|
|
42953
43767
|
* the content's `fit-content` width up to `HUG_MAX_WIDTH`, and the height is
|
|
42954
|
-
* read at that width with a 1 px tall viewport and again at the
|
|
43768
|
+
* read at that width with a 1 px tall viewport and again at the reference
|
|
43769
|
+
* height of the box's width, never the box's own height, so content sized off
|
|
43770
|
+
* the window height reads one height however tall the frame already is.
|
|
42955
43771
|
* Readings that differ mean the content sizes itself off the viewport, which
|
|
42956
43772
|
* has no height of its own to fit, so that refuses `fit-unbounded`. Finite
|
|
42957
43773
|
* animations finish before the first reading, so an entrance is read at its
|
|
42958
43774
|
* settled size.
|
|
42959
43775
|
*/
|
|
42960
43776
|
async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
|
|
43777
|
+
const reference = referenceHeight(box.width);
|
|
42961
43778
|
const opened = await openFrame(browser, {
|
|
42962
43779
|
baseUrl,
|
|
42963
43780
|
ref,
|
|
42964
|
-
box
|
|
43781
|
+
box: {
|
|
43782
|
+
width: box.width,
|
|
43783
|
+
height: reference
|
|
43784
|
+
},
|
|
42965
43785
|
theme: "light",
|
|
42966
43786
|
fonts
|
|
42967
43787
|
});
|
|
@@ -42973,8 +43793,9 @@ async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
|
|
|
42973
43793
|
if (hugWidth && !empty) {
|
|
42974
43794
|
await page.setViewportSize({
|
|
42975
43795
|
width: HUG_MAX_WIDTH,
|
|
42976
|
-
height:
|
|
43796
|
+
height: reference
|
|
42977
43797
|
});
|
|
43798
|
+
await settleResize(page);
|
|
42978
43799
|
width = Math.min(HUG_MAX_WIDTH, await page.evaluate(readFitWidth));
|
|
42979
43800
|
}
|
|
42980
43801
|
const short = await readAt(page, {
|
|
@@ -42983,9 +43804,9 @@ async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
|
|
|
42983
43804
|
});
|
|
42984
43805
|
const current = await readAt(page, {
|
|
42985
43806
|
width,
|
|
42986
|
-
height:
|
|
43807
|
+
height: reference
|
|
42987
43808
|
});
|
|
42988
|
-
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 ${
|
|
43809
|
+
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 ${reference} px reference height, so it has no content height to fit. Size it by hand with frame resize.`, {
|
|
42989
43810
|
ref,
|
|
42990
43811
|
heights: [short.height, current.height]
|
|
42991
43812
|
});
|
|
@@ -43001,7 +43822,9 @@ async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
|
|
|
43001
43822
|
}
|
|
43002
43823
|
/**
|
|
43003
43824
|
* Sets a frame's height to its content's own height at its layout width and
|
|
43004
|
-
* turns its height hugging on
|
|
43825
|
+
* turns its height hugging on, measuring each linked width at its own width
|
|
43826
|
+
* and writing its height beside the frame's. The width is reported, never
|
|
43827
|
+
* changed.
|
|
43005
43828
|
*/
|
|
43006
43829
|
async function fitFrame(browser, { baseUrl, frame, ...options }) {
|
|
43007
43830
|
const measured = await measureContent(browser, {
|
|
@@ -43010,8 +43833,27 @@ async function fitFrame(browser, { baseUrl, frame, ...options }) {
|
|
|
43010
43833
|
box: frame.box,
|
|
43011
43834
|
hugWidth: false
|
|
43012
43835
|
});
|
|
43836
|
+
const widths = [];
|
|
43837
|
+
for (const { width } of frame.widths) {
|
|
43838
|
+
const linked = await measureContent(browser, {
|
|
43839
|
+
baseUrl,
|
|
43840
|
+
ref: frame.ref,
|
|
43841
|
+
box: {
|
|
43842
|
+
width,
|
|
43843
|
+
height: referenceHeight(width)
|
|
43844
|
+
},
|
|
43845
|
+
hugWidth: false
|
|
43846
|
+
});
|
|
43847
|
+
widths.push({
|
|
43848
|
+
width,
|
|
43849
|
+
height: linked.height
|
|
43850
|
+
});
|
|
43851
|
+
}
|
|
43013
43852
|
return {
|
|
43014
|
-
frame: await fitHeight(options.root, frame.ref, measured.height,
|
|
43853
|
+
frame: await fitHeight(options.root, frame.ref, measured.height, {
|
|
43854
|
+
...options,
|
|
43855
|
+
widths
|
|
43856
|
+
}),
|
|
43015
43857
|
contentHeight: measured.height,
|
|
43016
43858
|
contentWidth: measured.contentWidth,
|
|
43017
43859
|
tooWide: measured.contentWidth > frame.box.width
|
|
@@ -43019,8 +43861,19 @@ async function fitFrame(browser, { baseUrl, frame, ...options }) {
|
|
|
43019
43861
|
}
|
|
43020
43862
|
async function readAt(page, viewport) {
|
|
43021
43863
|
await page.setViewportSize(viewport);
|
|
43864
|
+
await settleResize(page);
|
|
43022
43865
|
return page.evaluate(readContentSize);
|
|
43023
43866
|
}
|
|
43867
|
+
/**
|
|
43868
|
+
* Waits two animation frames after a viewport resize, so a page's `resize`
|
|
43869
|
+
* listener has run and its layout settled before the next reading. A reading
|
|
43870
|
+
* taken straight after the resize sees the layout from before it.
|
|
43871
|
+
*/
|
|
43872
|
+
async function settleResize(page) {
|
|
43873
|
+
await page.evaluate(() => new Promise((resolve) => {
|
|
43874
|
+
requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
|
|
43875
|
+
}));
|
|
43876
|
+
}
|
|
43024
43877
|
function finishAnimations() {
|
|
43025
43878
|
for (const animation of document.getAnimations()) {
|
|
43026
43879
|
const end = animation.effect?.getComputedTiming().endTime;
|
|
@@ -43130,7 +43983,7 @@ const LAYOUT_RULES = [
|
|
|
43130
43983
|
description: "Content sizes itself off the viewport height rather than holding a height of its own, a warning since a full-height screen does it on purpose"
|
|
43131
43984
|
}
|
|
43132
43985
|
];
|
|
43133
|
-
const finding$
|
|
43986
|
+
const finding$2 = findingFor(LAYOUT_RULES);
|
|
43134
43987
|
/**
|
|
43135
43988
|
* The slack a reading takes before it counts, so a subpixel edge rounding up
|
|
43136
43989
|
* is never a finding. One pixel matches what the groundwork spike measured.
|
|
@@ -43139,7 +43992,9 @@ const SLACK_PX = 1;
|
|
|
43139
43992
|
/**
|
|
43140
43993
|
* Runs the three layout rules on a frame open at its own box, at most one
|
|
43141
43994
|
* finding each. `viewport` reads a second time with the viewport twice as
|
|
43142
|
-
* tall, then puts the box back.
|
|
43995
|
+
* tall, then puts the box back. Each resize settles before the next read, so
|
|
43996
|
+
* a script sizing content on `resize` reads as the CSS case does, and the
|
|
43997
|
+
* rules after this one see the page back at its box.
|
|
43143
43998
|
*/
|
|
43144
43999
|
async function checkLayout(page, target) {
|
|
43145
44000
|
const { width, height } = target.box;
|
|
@@ -43150,18 +44005,20 @@ async function checkLayout(page, target) {
|
|
|
43150
44005
|
height: height * 2
|
|
43151
44006
|
});
|
|
43152
44007
|
try {
|
|
44008
|
+
await settleResize(page);
|
|
43153
44009
|
const tall = await page.evaluate(readContentSize);
|
|
43154
44010
|
const atTall = await page.evaluate(readLayout);
|
|
43155
44011
|
return [
|
|
43156
44012
|
clipped(target, atBox),
|
|
43157
44013
|
scrollbar(target, atBox),
|
|
43158
|
-
viewport(target, content.height, tall.height, atBox, atTall)
|
|
44014
|
+
target.scroll ? null : viewport(target, content.height, tall.height, atBox, atTall)
|
|
43159
44015
|
].filter((found) => found !== null);
|
|
43160
44016
|
} finally {
|
|
43161
44017
|
await page.setViewportSize({
|
|
43162
44018
|
width,
|
|
43163
44019
|
height
|
|
43164
44020
|
});
|
|
44021
|
+
await settleResize(page);
|
|
43165
44022
|
}
|
|
43166
44023
|
}
|
|
43167
44024
|
function clipped(target, read) {
|
|
@@ -43169,19 +44026,19 @@ function clipped(target, read) {
|
|
|
43169
44026
|
const shown = read.boxes.filter((box) => !box.cropped);
|
|
43170
44027
|
const bottom = Math.max(read.root.bottom, ...shown.map((box) => box.bottom));
|
|
43171
44028
|
const right = Math.max(read.root.right, ...shown.map((box) => box.right));
|
|
43172
|
-
const tall = bottom > height + SLACK_PX;
|
|
44029
|
+
const tall = !target.scroll && bottom > height + SLACK_PX;
|
|
43173
44030
|
const wide = right > width + SLACK_PX;
|
|
43174
44031
|
if (!tall && !wide) return null;
|
|
43175
44032
|
const past = shown.filter((box) => tall && box.bottom > height + SLACK_PX || wide && box.right > width + SLACK_PX);
|
|
43176
44033
|
const reach = [tall ? `${bottom} px tall in its ${height} px height` : null, wide ? `${right} px wide in its ${width} px width` : null].filter((part) => part !== null).join(" and ");
|
|
43177
|
-
return finding$
|
|
44034
|
+
return finding$2("clipped", {
|
|
43178
44035
|
frame: target.ref,
|
|
43179
44036
|
path: target.path,
|
|
43180
44037
|
message: `${target.ref} is ${reach}, so the board cuts it off${offenders(past, "past the box")}. ${clippedAdvice(tall, wide, width)}`
|
|
43181
44038
|
});
|
|
43182
44039
|
}
|
|
43183
44040
|
function clippedAdvice(tall, wide, width) {
|
|
43184
|
-
if (!wide) return "Run frame fit, or shorten the content.";
|
|
44041
|
+
if (!wide) return "Run frame fit, run frame resize --scroll for a page meant to scroll, or shorten the content.";
|
|
43185
44042
|
if (!tall) return `Reflow or shorten the content to fit its ${width} px width, since frame fit sets the height alone.`;
|
|
43186
44043
|
return `Run frame fit for the height, and reflow or shorten the content to fit its ${width} px width.`;
|
|
43187
44044
|
}
|
|
@@ -43190,7 +44047,7 @@ function scrollbar(target, read) {
|
|
|
43190
44047
|
const [first] = scrolling;
|
|
43191
44048
|
if (!first) return null;
|
|
43192
44049
|
const by = Math.max(first.overflowX, first.overflowY);
|
|
43193
|
-
return finding$
|
|
44050
|
+
return finding$2("scrollbar", {
|
|
43194
44051
|
frame: target.ref,
|
|
43195
44052
|
path: target.path,
|
|
43196
44053
|
message: `${target.ref} scrolls inside ${element(first)}, whose content is ${by} px past its box${more(scrolling.length - 1, "scrolls", "scroll")}. Size it to its content, or set overflow to hidden.`
|
|
@@ -43200,7 +44057,7 @@ function viewport(target, atBox, atTall, boxRead, tallRead) {
|
|
|
43200
44057
|
if (atTall <= atBox + SLACK_PX) return null;
|
|
43201
44058
|
const before = new Map(boxRead.boxes.map((box) => [box.index, box.height]));
|
|
43202
44059
|
const grown = tallRead.boxes.filter((box) => box.height > (before.get(box.index) ?? box.height) + SLACK_PX);
|
|
43203
|
-
return finding$
|
|
44060
|
+
return finding$2("viewport", {
|
|
43204
44061
|
frame: target.ref,
|
|
43205
44062
|
path: target.path,
|
|
43206
44063
|
message: `${target.ref} grows with the viewport, measuring ${atBox} px at its ${target.box.height} px height and ${atTall} px at twice that${offenders(grown, "growing")}. Give it a height of its own unless it is a full-height screen on purpose.`
|
|
@@ -43325,6 +44182,92 @@ function readLayout() {
|
|
|
43325
44182
|
scrollers
|
|
43326
44183
|
};
|
|
43327
44184
|
}
|
|
44185
|
+
// src/server/checks/browser/scroll-effect.ts
|
|
44186
|
+
const SCROLL_EFFECT_RULES = [{
|
|
44187
|
+
id: "scroll-effect",
|
|
44188
|
+
tier: "browser",
|
|
44189
|
+
severity: "warning",
|
|
44190
|
+
description: "A frame whose height hugs its content holds an effect driven by scrolling, being position: sticky, a window or document scroll listener, or a scroll or view timeline, which never runs since the frame never scrolls"
|
|
44191
|
+
}];
|
|
44192
|
+
const finding$1 = findingFor(SCROLL_EFFECT_RULES);
|
|
44193
|
+
/**
|
|
44194
|
+
* `scroll-effect`, at most one finding, on a frame that hugs its height and
|
|
44195
|
+
* holds no `scroll` key, naming the first trigger found. A listener counts
|
|
44196
|
+
* only on the window or the document, since those are the objects the
|
|
44197
|
+
* DevTools protocol is asked about, so one on an inner scroll container or an
|
|
44198
|
+
* observer driving the effect goes unseen and costs a hint, never an error.
|
|
44199
|
+
*/
|
|
44200
|
+
async function checkScrollEffect(page, target) {
|
|
44201
|
+
if (target.scroll || !target.hugHeight) return [];
|
|
44202
|
+
const trigger = await page.evaluate(readScrollStyles) ?? await readListener(page);
|
|
44203
|
+
if (!trigger) return [];
|
|
44204
|
+
return [finding$1("scroll-effect", {
|
|
44205
|
+
frame: target.ref,
|
|
44206
|
+
path: target.path,
|
|
44207
|
+
message: `${target.ref} ${describe$6(trigger)}, which needs the frame to scroll, but its height hugs the content so it never does. Run frame resize --scroll to hold a screen height and scroll past it.`
|
|
44208
|
+
})];
|
|
44209
|
+
}
|
|
44210
|
+
function describe$6(trigger) {
|
|
44211
|
+
switch (trigger.kind) {
|
|
44212
|
+
case "sticky": return `holds position: sticky on <${trigger.tag}> at element ${trigger.index}`;
|
|
44213
|
+
case "timeline": return `runs an animation on a scroll or view timeline from <${trigger.tag}> at element ${trigger.index}`;
|
|
44214
|
+
case "listener": return `listens for scroll on the ${trigger.target}`;
|
|
44215
|
+
}
|
|
44216
|
+
}
|
|
44217
|
+
async function readListener(page) {
|
|
44218
|
+
const session = await page.context().newCDPSession(page);
|
|
44219
|
+
try {
|
|
44220
|
+
for (const name of ["window", "document"]) {
|
|
44221
|
+
const { result } = await session.send("Runtime.evaluate", { expression: name });
|
|
44222
|
+
if (!result.objectId) continue;
|
|
44223
|
+
const { listeners } = await session.send("DOMDebugger.getEventListeners", { objectId: result.objectId });
|
|
44224
|
+
if (listeners.some((listener) => listener.type === "scroll")) return {
|
|
44225
|
+
kind: "listener",
|
|
44226
|
+
target: name
|
|
44227
|
+
};
|
|
44228
|
+
}
|
|
44229
|
+
return null;
|
|
44230
|
+
} finally {
|
|
44231
|
+
await session.detach();
|
|
44232
|
+
}
|
|
44233
|
+
}
|
|
44234
|
+
function readScrollStyles() {
|
|
44235
|
+
const isScrollTimeline = (timeline) => {
|
|
44236
|
+
const name = timeline?.constructor.name;
|
|
44237
|
+
return name === "ScrollTimeline" || name === "ViewTimeline";
|
|
44238
|
+
};
|
|
44239
|
+
const insideScroller = (element) => {
|
|
44240
|
+
for (let parent = element.parentElement; parent && parent !== document.body && parent !== document.documentElement; parent = parent.parentElement) {
|
|
44241
|
+
const { overflowX, overflowY } = getComputedStyle(parent);
|
|
44242
|
+
if (overflowX !== "visible" || overflowY !== "visible") return true;
|
|
44243
|
+
}
|
|
44244
|
+
return false;
|
|
44245
|
+
};
|
|
44246
|
+
let index = 0;
|
|
44247
|
+
for (const node of document.querySelectorAll("*")) {
|
|
44248
|
+
if (node.closest("[data-frameboard]")) continue;
|
|
44249
|
+
const own = index;
|
|
44250
|
+
index += 1;
|
|
44251
|
+
const style = getComputedStyle(node);
|
|
44252
|
+
const tag = node.tagName.toLowerCase();
|
|
44253
|
+
if (style.position === "sticky" && !insideScroller(node)) return {
|
|
44254
|
+
kind: "sticky",
|
|
44255
|
+
index: own,
|
|
44256
|
+
tag
|
|
44257
|
+
};
|
|
44258
|
+
const timeline = style.getPropertyValue("animation-timeline");
|
|
44259
|
+
if (/\b(scroll|view)\(/.test(timeline)) return {
|
|
44260
|
+
kind: "timeline",
|
|
44261
|
+
index: own,
|
|
44262
|
+
tag
|
|
44263
|
+
};
|
|
44264
|
+
}
|
|
44265
|
+
return document.getAnimations().some((animation) => isScrollTimeline(animation.timeline)) ? {
|
|
44266
|
+
kind: "timeline",
|
|
44267
|
+
index: 0,
|
|
44268
|
+
tag: "html"
|
|
44269
|
+
} : null;
|
|
44270
|
+
}
|
|
43328
44271
|
// src/server/checks/outranked.ts
|
|
43329
44272
|
const OUTRANKED_RULES = [{
|
|
43330
44273
|
id: "outranked",
|
|
@@ -43547,7 +44490,9 @@ const RULES = [
|
|
|
43547
44490
|
...OUTRANKED_RULES,
|
|
43548
44491
|
...LAYOUT_RULES,
|
|
43549
44492
|
...FONT_SIZE_RULES,
|
|
43550
|
-
...
|
|
44493
|
+
...CONTRAST_RULES,
|
|
44494
|
+
...DECLARATION_RULES,
|
|
44495
|
+
...SCROLL_EFFECT_RULES
|
|
43551
44496
|
];
|
|
43552
44497
|
/** Checks every frame on one page. */
|
|
43553
44498
|
async function checkPage(root, project, page) {
|
|
@@ -43793,6 +44738,13 @@ const frameRecordSchema = object$1({
|
|
|
43793
44738
|
/** Whether each axis takes its size from the content rather than holding it. */
|
|
43794
44739
|
hugWidth: boolean$1(),
|
|
43795
44740
|
hugHeight: boolean$1(),
|
|
44741
|
+
/** Whether the frame holds a fixed screen height and scrolls past it, fixing both axes. */
|
|
44742
|
+
scroll: boolean$1(),
|
|
44743
|
+
/** The extra widths the frame also shows at, beside it in a row, none when it lists none. */
|
|
44744
|
+
widths: array$1(object$1({
|
|
44745
|
+
width: number(),
|
|
44746
|
+
height: number()
|
|
44747
|
+
})),
|
|
43796
44748
|
placed: boolean$1(),
|
|
43797
44749
|
modifiedAt: string$1()
|
|
43798
44750
|
});
|
|
@@ -43847,7 +44799,9 @@ const captureResultSchema = object$1({ images: array$1(object$1({
|
|
|
43847
44799
|
width: int$1().min(1),
|
|
43848
44800
|
height: int$1().min(1),
|
|
43849
44801
|
/** Device pixels per CSS pixel, so the file is `width * scale` wide. */
|
|
43850
|
-
scale: int$1().min(1).max(3)
|
|
44802
|
+
scale: int$1().min(1).max(3),
|
|
44803
|
+
/** How far down a `--scroll` shot reached, absent on a shot taken at the top. */
|
|
44804
|
+
scrollY: int$1().min(0).optional()
|
|
43851
44805
|
})) });
|
|
43852
44806
|
/** What `frame fit` returns: the frame as resized, the height it measured, and its width against the layout's. */
|
|
43853
44807
|
const fitResultSchema = object$1({
|
|
@@ -44015,7 +44969,9 @@ const findingSchema = /* @__PURE__ */ object({
|
|
|
44015
44969
|
/** Board-relative, with forward slashes. */
|
|
44016
44970
|
path: /* @__PURE__ */ string(),
|
|
44017
44971
|
message: /* @__PURE__ */ string(),
|
|
44018
|
-
location: /* @__PURE__ */ nullable(findingLocationSchema)
|
|
44972
|
+
location: /* @__PURE__ */ nullable(findingLocationSchema),
|
|
44973
|
+
/** The linked width a browser finding was read at, absent at the frame's own. */
|
|
44974
|
+
width: /* @__PURE__ */ optional(int().check(/* @__PURE__ */ _gte(1)))
|
|
44019
44975
|
});
|
|
44020
44976
|
/**
|
|
44021
44977
|
* Whether the browser rules ran, so a reader can tell no browser findings
|
|
@@ -44284,7 +45240,9 @@ function contentFormat() {
|
|
|
44284
45240
|
defaultFrameSize: DEFAULT_FRAME_SIZE,
|
|
44285
45241
|
layout: [
|
|
44286
45242
|
"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.",
|
|
44287
|
-
"hidden, locked, hugWidth, and
|
|
45243
|
+
"hidden, locked, hugWidth, hugHeight, and scroll read as false when absent, and an axis whose hug flag is false holds the size its entry states.",
|
|
45244
|
+
`scroll marks a frame that holds a fixed screen height and scrolls past it, such as a page with a sticky section. It fixes both axes, so either hug flag beside it reads as false, frame fit refuses it, and serve never measures it. frame add --scroll sets it, taking the height given or else the preset height of the width (${FRAME_SIZES.desktop.height} px at ${FRAME_SIZES.desktop.width}). frame resize --scroll sets it on a placed frame, dropping a hugging height to that preset height unless a height is given and keeping a fixed height as it stands, so resize a frame fixed past a screen with --height too. frame resize --no-scroll clears it, keeping the box.`,
|
|
45245
|
+
`widths lists the extra widths one frame file also shows at, as { width, height } objects, each drawn 80 px past the last in a row beside the frame at its y, so a responsive page is one file rather than a copy per width. Each width follows the frame's own height mode: it hugs its content at that width while hugHeight is on, and otherwise holds its height, the preset height of its width when first set and on frame resize --scroll. A value of any other shape reads as none. frame add --widths 834,390 and frame resize --widths set it, refusing a repeated width, the frame's own width, or a frame hugging its width, and frame resize --no-widths clears it. capture writes <frame>@<width>.<theme>.png beside <frame>.<theme>.png, check reports a browser finding at a linked width with that width and prints it as <path>@<width>, and a frames.json value of <project>/<page>/<frame>@<width> syncs that width's images.`,
|
|
44288
45246
|
`An axis that hugs takes its size from the frame's content: a running serve measures it after each write to the frame file and when frame add places a file already written, 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.`,
|
|
44289
45247
|
"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.",
|
|
44290
45248
|
"Frames sort by order, then name, and a write that changes order renumbers the page from 0.",
|
|
@@ -44410,8 +45368,9 @@ function changeOf(options) {
|
|
|
44410
45368
|
if ([
|
|
44411
45369
|
options.style,
|
|
44412
45370
|
options.attr,
|
|
45371
|
+
options.dropAttr,
|
|
44413
45372
|
options.text
|
|
44414
|
-
].filter((value) => value !== void 0).length !== 1) throw new FrameboardError("usage", "Give exactly one of --style, --attr, or --text.");
|
|
45373
|
+
].filter((value) => value !== void 0).length !== 1) throw new FrameboardError("usage", "Give exactly one of --style, --attr, --drop-attr, or --text.");
|
|
44415
45374
|
if (options.style !== void 0) {
|
|
44416
45375
|
const [property, value] = pair("--style", options.style);
|
|
44417
45376
|
return {
|
|
@@ -44428,6 +45387,11 @@ function changeOf(options) {
|
|
|
44428
45387
|
value
|
|
44429
45388
|
};
|
|
44430
45389
|
}
|
|
45390
|
+
if (options.dropAttr !== void 0) return {
|
|
45391
|
+
kind: "attribute",
|
|
45392
|
+
name: options.dropAttr,
|
|
45393
|
+
remove: true
|
|
45394
|
+
};
|
|
44431
45395
|
return {
|
|
44432
45396
|
kind: "text",
|
|
44433
45397
|
value: options.text ?? ""
|
|
@@ -44435,7 +45399,7 @@ function changeOf(options) {
|
|
|
44435
45399
|
}
|
|
44436
45400
|
function registerEdit(program, context) {
|
|
44437
45401
|
const { io } = context;
|
|
44438
|
-
act(addVerb(program, "edit", "Set one inline style declaration, attribute, or text on one element of a frame, leaving every other byte", { project: true }).argument("<frame-ref>", "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file").requiredOption("--index <n>", "the element's index in document order", parseInteger(0)).option("--hash <hex>", "the frame hash the index was read from, refused once the file differs", parseHash).option("--style <property=value>", "set one declaration, or drop it with an empty value").option("--attr <name=value>", "set one attribute").option("--text <value>", "replace the text of an element holding text alone"), context, async ([ref = ""], options) => {
|
|
45402
|
+
act(addVerb(program, "edit", "Set one inline style declaration, attribute, or text, or drop one attribute, on one element of a frame, leaving every other byte", { project: true }).argument("<frame-ref>", "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file").requiredOption("--index <n>", "the element's index in document order", parseInteger(0)).option("--hash <hex>", "the frame hash the index was read from, refused once the file differs", parseHash).option("--style <property=value>", "set one declaration, or drop it with an empty value").option("--attr <name=value>", "set one attribute").option("--drop-attr <name>", "remove one attribute, such as a boolean muted, which --attr can only set").option("--text <value>", "replace the text of an element holding text alone"), context, async ([ref = ""], options) => {
|
|
44439
45403
|
const change = changeOf(options);
|
|
44440
45404
|
const root = await boardOf(options, io);
|
|
44441
45405
|
const frame = await resolveFrameRef(root, ref, {
|
|
@@ -44484,14 +45448,29 @@ function tagFor(agent, session, cwd) {
|
|
|
44484
45448
|
return folder ? `${agent} · ${folder}` : session.slice(0, 6);
|
|
44485
45449
|
}
|
|
44486
45450
|
// src/cli/commands/editing.ts
|
|
45451
|
+
const ANY_INTEGER$1 = parseInteger(Number.MIN_SAFE_INTEGER);
|
|
44487
45452
|
function registerEditing(program, context) {
|
|
44488
45453
|
const { io } = context;
|
|
44489
|
-
act(addVerb(program, "editing", "Claim a frame before rewriting it, so the board shows it and another session is told it is taken. Bare, list the live claims", { project: true }).argument("[frame-
|
|
45454
|
+
act(addVerb(program, "editing", "Claim a frame before rewriting it, so the board shows it and another session is told it is taken. With --new, reserve frames not written yet, so the board shows where each will land. Bare, list the live claims", { project: true }).argument("[frame-refs...]", "the frame to claim or release, or with --new every frame to reserve").option("--release", "drop this session's claim on the frame, or every claim it holds").option("--new", "reserve each frame named, none of which may exist yet, as one set that renews together").addOption(new Option("--size <preset>", "with --new, a size preset or device for every frame").choices(FRAME_SIZE_NAMES)).option("--width <n>", "with --new, width in px", parseInteger(1)).option("--height <n>", "with --new, height in px", parseInteger(1)).option("--x <n>", "with --new, board x of the first frame in px", ANY_INTEGER$1).option("--y <n>", "with --new, board y of the row in px", ANY_INTEGER$1).option("--session <id>", `the session holding the claim, defaulting to ${SESSION_ENV}`).option("--agent <name>", "the agent the board names, by its first letter", DEFAULT_AGENT), context, async (refs, options) => {
|
|
44490
45455
|
const root = await boardOf(options, io);
|
|
44491
45456
|
const now = /* @__PURE__ */ new Date();
|
|
45457
|
+
if (options.new) {
|
|
45458
|
+
const session = sessionOf(options.session);
|
|
45459
|
+
const claims = await reserve(root, {
|
|
45460
|
+
session,
|
|
45461
|
+
agent: options.agent,
|
|
45462
|
+
tag: tagFor(options.agent, session, io.cwd)
|
|
45463
|
+
}, await reservationsOf(root, refs, options, io.cwd, now), now);
|
|
45464
|
+
return {
|
|
45465
|
+
data: { claims },
|
|
45466
|
+
human: `Reserved ${claims.map((each) => each.frame).join(", ")}. Claim any of them again within five minutes to keep the set.`
|
|
45467
|
+
};
|
|
45468
|
+
}
|
|
45469
|
+
if (refs.length > 1) throw new FrameboardError("usage", `editing claims one frame at a time. Pass --new to reserve ${refs.length} frames not written yet.`, { refs });
|
|
45470
|
+
const [ref] = refs;
|
|
44492
45471
|
if (options.release) {
|
|
44493
45472
|
const session = sessionOf(options.session);
|
|
44494
|
-
const released = await release$1(root, session, ref ? await
|
|
45473
|
+
const released = await release$1(root, session, ref ? await claimable(root, ref, resolving(options, io.cwd), now) : void 0, now);
|
|
44495
45474
|
return {
|
|
44496
45475
|
data: { released },
|
|
44497
45476
|
human: released.length === 0 ? `${session} held no claim to release` : `Released ${released.map((each) => each.frame).join(", ")}`
|
|
@@ -44499,7 +45478,7 @@ function registerEditing(program, context) {
|
|
|
44499
45478
|
}
|
|
44500
45479
|
if (ref) {
|
|
44501
45480
|
const session = sessionOf(options.session);
|
|
44502
|
-
const frame = await
|
|
45481
|
+
const frame = await claimable(root, ref, resolving(options, io.cwd), now);
|
|
44503
45482
|
const held = await claim(root, {
|
|
44504
45483
|
frame,
|
|
44505
45484
|
session,
|
|
@@ -44518,24 +45497,98 @@ function registerEditing(program, context) {
|
|
|
44518
45497
|
};
|
|
44519
45498
|
});
|
|
44520
45499
|
}
|
|
44521
|
-
|
|
44522
|
-
|
|
44523
|
-
const frame = await resolveFrameRef(root, ref, {
|
|
45500
|
+
function resolving(options, cwd) {
|
|
45501
|
+
return {
|
|
44524
45502
|
project: options.project,
|
|
44525
45503
|
cwd
|
|
45504
|
+
};
|
|
45505
|
+
}
|
|
45506
|
+
/**
|
|
45507
|
+
* The ref a plain claim names: an existing frame, or one a live reservation
|
|
45508
|
+
* holds before its file is written, which the agent claims as it turns to
|
|
45509
|
+
* draw it. Any other missing frame refuses `frame-not-found` as before.
|
|
45510
|
+
*/
|
|
45511
|
+
async function claimable(root, ref, options, now) {
|
|
45512
|
+
const frame = await resolveFrameRef(root, ref, {
|
|
45513
|
+
...options,
|
|
45514
|
+
allowMissing: true
|
|
44526
45515
|
});
|
|
45516
|
+
const canonical = refOf(frame);
|
|
45517
|
+
if (existsSync(frame.path)) return canonical;
|
|
45518
|
+
if ((await readClaims(root, now)).some((each) => each.frame === canonical && each.box)) return canonical;
|
|
45519
|
+
throw new FrameboardError("frame-not-found", `No frame ${frame.name} in ${frame.project}/${frame.page}.`, { ref });
|
|
45520
|
+
}
|
|
45521
|
+
/** `<project>/<page>/<frame>`, the one form a claim names a frame by. */
|
|
45522
|
+
function refOf(frame) {
|
|
44527
45523
|
return `${frame.project}/${frame.page}/${frame.name}`;
|
|
44528
45524
|
}
|
|
45525
|
+
/**
|
|
45526
|
+
* The box each named frame will land in, in one row per page in the order
|
|
45527
|
+
* named, past every frame and live reservation already on that page unless
|
|
45528
|
+
* `--x` or `--y` sets the row. A frame that exists already refuses
|
|
45529
|
+
* `name-taken` before anything is reserved.
|
|
45530
|
+
*/
|
|
45531
|
+
async function reservationsOf(root, refs, options, cwd, now) {
|
|
45532
|
+
if (refs.length === 0) throw new FrameboardError("usage", "Name at least one frame to reserve with --new.");
|
|
45533
|
+
const frames = await Promise.all(refs.map((ref) => resolveFrameRef(root, ref, {
|
|
45534
|
+
...resolving(options, cwd),
|
|
45535
|
+
allowMissing: true
|
|
45536
|
+
})));
|
|
45537
|
+
const existing = frames.filter((frame) => existsSync(frame.path));
|
|
45538
|
+
if (existing.length > 0) throw new FrameboardError("name-taken", `${existing.map(refOf).join(", ")} already exists, so claim it with editing <ref> rather than reserving it.`, { refs: existing.map(refOf) });
|
|
45539
|
+
const named = frames.map(refOf);
|
|
45540
|
+
const repeated = named.find((ref, index) => named.indexOf(ref) !== index);
|
|
45541
|
+
if (repeated) throw new FrameboardError("usage", `${repeated} is named twice.`, { ref: repeated });
|
|
45542
|
+
const size = {
|
|
45543
|
+
...FRAME_SIZES[DEFAULT_FRAME_SIZE],
|
|
45544
|
+
...sizeOf(options)
|
|
45545
|
+
};
|
|
45546
|
+
const hugs = hugsOf(options);
|
|
45547
|
+
const live = await readClaims(root, now);
|
|
45548
|
+
const nextX = /* @__PURE__ */ new Map();
|
|
45549
|
+
const reservations = [];
|
|
45550
|
+
for (const frame of frames) {
|
|
45551
|
+
const page = `${frame.project}/${frame.page}`;
|
|
45552
|
+
const x = nextX.get(page) ?? options.x ?? await rightOf(root, frame, live);
|
|
45553
|
+
nextX.set(page, x + size.width + 80);
|
|
45554
|
+
reservations.push({
|
|
45555
|
+
frame: refOf(frame),
|
|
45556
|
+
box: {
|
|
45557
|
+
x,
|
|
45558
|
+
y: options.y ?? 0,
|
|
45559
|
+
...size,
|
|
45560
|
+
...hugs
|
|
45561
|
+
}
|
|
45562
|
+
});
|
|
45563
|
+
}
|
|
45564
|
+
return reservations;
|
|
45565
|
+
}
|
|
45566
|
+
/** Where a new row starts on a frame's page, past its frames' drawn rows and reserved boxes. */
|
|
45567
|
+
async function rightOf(root, frame, live) {
|
|
45568
|
+
const page = await scanPage(root, frame.project, frame.page, 0);
|
|
45569
|
+
const prefix = `${frame.project}/${frame.page}/`;
|
|
45570
|
+
const boxes = [...page.frames.map((each) => drawnExtent(each.box, each.widths)), ...live.flatMap((each) => each.box && each.frame.startsWith(prefix) ? [each.box] : [])];
|
|
45571
|
+
return Math.max(...boxes.map((box) => box.x + box.width + 80), 0);
|
|
45572
|
+
}
|
|
44529
45573
|
function describe$4(claims, now) {
|
|
44530
45574
|
if (claims.length === 0) return "No frame is claimed";
|
|
44531
45575
|
return claims.map((each) => {
|
|
44532
45576
|
const seconds = Math.round((now.getTime() - Date.parse(each.claimedAt)) / 1e3);
|
|
44533
|
-
|
|
45577
|
+
const state = each.box ? "reserved" : "editing";
|
|
45578
|
+
return `${each.frame} ${each.tag} ${state} ${seconds}s ${each.session}`;
|
|
44534
45579
|
}).join("\n");
|
|
44535
45580
|
}
|
|
44536
45581
|
// src/cli/commands/frame.ts
|
|
44537
45582
|
const FRAME_REF = "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file";
|
|
44538
45583
|
const ANY_INTEGER = parseInteger(Number.MIN_SAFE_INTEGER);
|
|
45584
|
+
const WIDTHS_HELP = "the extra widths the frame also shows at, a comma list such as 834,390, each drawn beside it and hugging or holding its height as the frame does";
|
|
45585
|
+
const POSITIVE = parseInteger(1);
|
|
45586
|
+
/** A comma list of positive integers, each checked as `--width` checks one. */
|
|
45587
|
+
function parseWidths(value) {
|
|
45588
|
+
return value.split(",").map((part) => POSITIVE(part.trim()));
|
|
45589
|
+
}
|
|
45590
|
+
const SCROLL_HELP = "hold a fixed screen height and scroll past it, fixing both axes, at the reference height of the width when no height is given";
|
|
45591
|
+
const RESIZE_SCROLL_HELP = "hold a fixed screen height and scroll past it, fixing both axes, dropping a hugging height to the reference height of the width and keeping a fixed one";
|
|
44539
45592
|
function registerFrame(program, context) {
|
|
44540
45593
|
const { io } = context;
|
|
44541
45594
|
const frame = program.command("frame").description("Manage frames");
|
|
@@ -44546,7 +45599,7 @@ function registerFrame(program, context) {
|
|
|
44546
45599
|
data: record,
|
|
44547
45600
|
human: `${what} ${record.ref}`
|
|
44548
45601
|
});
|
|
44549
|
-
act(withPosition(withSize(verb("add", "Place a frame past every frame, as written when its file exists and with a skeleton file only when none does, so write the file first to show no empty box. 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, {
|
|
45602
|
+
act(withPosition(withSize(verb("add", "Place a frame past every frame, as written when its file exists and with a skeleton file only when none does, so write the file first to show no empty box. Each axis no size names hugs its content, so a preset or --width fixes the width and the height hugs.").option("--scroll", SCROLL_HELP).option("--widths <list>", WIDTHS_HELP, parseWidths))), context, async ([ref = ""], options) => done(await addFrame(await boardOf(options, io), ref, {
|
|
44550
45603
|
...options,
|
|
44551
45604
|
cwd: io.cwd
|
|
44552
45605
|
}), "Added"));
|
|
@@ -44558,7 +45611,7 @@ function registerFrame(program, context) {
|
|
|
44558
45611
|
...options,
|
|
44559
45612
|
cwd: io.cwd
|
|
44560
45613
|
}), "Moved to"));
|
|
44561
|
-
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, {
|
|
45614
|
+
act(withSize(verb("resize", "Set a frame size, fixing each axis it sets").option("--scroll", RESIZE_SCROLL_HELP).option("--no-scroll", "clear scroll, keeping the box as it stands").option("--widths <list>", WIDTHS_HELP, parseWidths).option("--no-widths", "clear the extra widths")), context, async ([ref = ""], options) => done(await resizeFrame(await boardOf(options, io), ref, {
|
|
44562
45615
|
...options,
|
|
44563
45616
|
cwd: io.cwd
|
|
44564
45617
|
}), "Resized"));
|
|
@@ -44569,6 +45622,7 @@ function registerFrame(program, context) {
|
|
|
44569
45622
|
cwd: io.cwd
|
|
44570
45623
|
};
|
|
44571
45624
|
const frame = await readFrame$1(root, ref, refOptions);
|
|
45625
|
+
if (frame.scroll) throw fitScrollError(frame.ref);
|
|
44572
45626
|
const result = await withFrameHost({
|
|
44573
45627
|
root,
|
|
44574
45628
|
facesDir: context.facesDir
|
|
@@ -48651,6 +49705,22 @@ function registerProject(program, context) {
|
|
|
48651
49705
|
human: `Deleted project ${result.deleted}`
|
|
48652
49706
|
};
|
|
48653
49707
|
});
|
|
49708
|
+
act(addVerb(project, "group", "File a project under a home folder, or take it out of one with --clear").argument("<name>", "the project").argument("[folder]", "the home folder, created when no project holds it").option("--clear", "take the project out of its folder"), context, async ([name = "", folder], options) => {
|
|
49709
|
+
const group = folderOf(folder, options.clear === true);
|
|
49710
|
+
const record = await fileOne(await boardOf(options, io), name, { group });
|
|
49711
|
+
return {
|
|
49712
|
+
data: record,
|
|
49713
|
+
human: group ? `Filed project ${record.name} under ${group}` : `Took project ${record.name} out of its folder`
|
|
49714
|
+
};
|
|
49715
|
+
});
|
|
49716
|
+
act(addVerb(project, "archive", "Move a project into home's Archived section, or back out with --restore").argument("<name>", "the project").option("--restore", "bring the project back out of the archive"), context, async ([name = ""], options) => {
|
|
49717
|
+
const archived = options.restore !== true;
|
|
49718
|
+
const record = await fileOne(await boardOf(options, io), name, { archived });
|
|
49719
|
+
return {
|
|
49720
|
+
data: record,
|
|
49721
|
+
human: archived ? `Archived project ${record.name}` : `Restored project ${record.name}`
|
|
49722
|
+
};
|
|
49723
|
+
});
|
|
48654
49724
|
act(addVerb(project, "tokens", "Write a starter tokens.css into a project no token sheet reaches, refusing tokens-exist where a board, --tokens, or project sheet does").argument("<name>", "the project").addOption(new Option("--accent <preset>", "the accent, light and dark").choices(Object.keys(STARTER_ACCENTS)).default(DEFAULT_LOOK.accent)).addOption(new Option("--font <face>", "the text face").choices(Object.keys(STARTER_FONTS)).default(DEFAULT_LOOK.font)), context, async ([name = ""], options) => {
|
|
48655
49725
|
const record = await writeStarterSheet(await boardOf(options, io), name, {
|
|
48656
49726
|
accent: options.accent,
|
|
@@ -48662,6 +49732,26 @@ function registerProject(program, context) {
|
|
|
48662
49732
|
};
|
|
48663
49733
|
});
|
|
48664
49734
|
}
|
|
49735
|
+
/** Files one project, answering its record as `fileProjects` leaves it. */
|
|
49736
|
+
async function fileOne(root, name, filing) {
|
|
49737
|
+
const [record] = await fileProjects(root, [name], filing);
|
|
49738
|
+
if (!record) throw new FrameboardError("internal", "No project filed.");
|
|
49739
|
+
return record;
|
|
49740
|
+
}
|
|
49741
|
+
/**
|
|
49742
|
+
* The folder a `group` call names, or null for `--clear`. A blank folder is
|
|
49743
|
+
* refused here, since the writer reads one as a clear.
|
|
49744
|
+
*/
|
|
49745
|
+
function folderOf(folder, clear) {
|
|
49746
|
+
if (clear && folder !== void 0) throw new FrameboardError("usage", "Give a folder or --clear, not both.");
|
|
49747
|
+
if (clear) return null;
|
|
49748
|
+
if (folder === void 0) throw new FrameboardError("usage", "Give a folder, or --clear to leave one.");
|
|
49749
|
+
const name = folder.trim();
|
|
49750
|
+
if (name === "" || name.length > MAX_FOLDER) throw new FrameboardError("invalid-name", `A folder name holds 1 to ${MAX_FOLDER} characters.`);
|
|
49751
|
+
return name;
|
|
49752
|
+
}
|
|
49753
|
+
/** The longest folder name the board's own filing route accepts. */
|
|
49754
|
+
const MAX_FOLDER = 256;
|
|
48665
49755
|
// src/server/references/assets.ts
|
|
48666
49756
|
/**
|
|
48667
49757
|
* The files a frame loads inside its project's `assets/`, by their path there,
|
|
@@ -48719,7 +49809,7 @@ const OPTIONS = {
|
|
|
48719
49809
|
* write and `--check` both build through it, so they compare the same bytes.
|
|
48720
49810
|
*/
|
|
48721
49811
|
async function toReference(source, reference, folder) {
|
|
48722
|
-
const result = await (await importFormat(folder))(`${reference}.html`, withProjectAssets(source), OPTIONS);
|
|
49812
|
+
const result = await (await importFormat(folder))(`${reference}.html`, withProjectAssets(source, reference), OPTIONS);
|
|
48723
49813
|
const [error] = result.errors;
|
|
48724
49814
|
if (error) {
|
|
48725
49815
|
const [reason] = error.message.split("\n");
|
|
@@ -48730,14 +49820,17 @@ async function toReference(source, reference, folder) {
|
|
|
48730
49820
|
/**
|
|
48731
49821
|
* Rewrites the frame's text only at the spans its loads occupy, so text naming
|
|
48732
49822
|
* `../assets/` that loads nothing, such as a `<code>` sample, keeps its bytes.
|
|
49823
|
+
* The link climbs one folder per folder the reference sits in, to the folder's
|
|
49824
|
+
* `assets/`.
|
|
48733
49825
|
*/
|
|
48734
|
-
function withProjectAssets(source) {
|
|
49826
|
+
function withProjectAssets(source, reference) {
|
|
49827
|
+
const assets = `${"../".repeat(reference.split("/").length - 1)}assets/${source.project}/`;
|
|
48735
49828
|
const framePath = boardPath(source.root, source.path);
|
|
48736
49829
|
const spans = /* @__PURE__ */ new Map();
|
|
48737
49830
|
for (const { path, location } of frameLoads(source)) if (path === framePath && location) spans.set(location.startOffset, location.endOffset);
|
|
48738
49831
|
let html = source.html;
|
|
48739
49832
|
for (const [start, end] of [...spans].sort(([a], [b]) => b - a)) {
|
|
48740
|
-
const span = html.slice(start, end).replace(BOARD_ASSETS,
|
|
49833
|
+
const span = html.slice(start, end).replace(BOARD_ASSETS, assets);
|
|
48741
49834
|
html = `${html.slice(0, start)}${span}${html.slice(end)}`;
|
|
48742
49835
|
}
|
|
48743
49836
|
return html;
|
|
@@ -48765,12 +49858,15 @@ async function importFormat(folder) {
|
|
|
48765
49858
|
}
|
|
48766
49859
|
}
|
|
48767
49860
|
// src/server/references/frame-map.ts
|
|
48768
|
-
const
|
|
48769
|
-
const
|
|
49861
|
+
const SEGMENT = "[a-z0-9]+(-[a-z0-9]+)*";
|
|
49862
|
+
const REFERENCE = new RegExp(`^${SEGMENT}(/${SEGMENT}){1,2}$`);
|
|
49863
|
+
const BOARD_REF = /^[^/\s]+\/[^/\s]+\/[^/\s@]+(@[1-9]\d*)?$/;
|
|
48770
49864
|
/**
|
|
48771
|
-
* Reads `frames.json`, mapping each reference, `<group>/<name
|
|
48772
|
-
* board frame `<project>/<page>/<frame>`
|
|
48773
|
-
*
|
|
49865
|
+
* Reads `frames.json`, mapping each reference, `<group>/<name>` or
|
|
49866
|
+
* `<group>/<section>/<name>`, to the board frame `<project>/<page>/<frame>`
|
|
49867
|
+
* it is captured from, or `<project>/<page>/<frame>@<width>` to capture it at
|
|
49868
|
+
* one of its widths. An entry in any other shape refuses rather than filing
|
|
49869
|
+
* into the wrong folder.
|
|
48774
49870
|
*/
|
|
48775
49871
|
function parseFrameMap(json) {
|
|
48776
49872
|
const parsed = parseJson(json);
|
|
@@ -48779,8 +49875,8 @@ function parseFrameMap(json) {
|
|
|
48779
49875
|
if (Object.keys(frames).length === 0) throw new FrameboardError("frame-map-invalid", "frames.json maps no frames, so a sync would remove every reference.");
|
|
48780
49876
|
const map = /* @__PURE__ */ new Map();
|
|
48781
49877
|
for (const [reference, ref] of Object.entries(frames)) {
|
|
48782
|
-
if (!REFERENCE.test(reference)) throw new FrameboardError("frame-map-invalid", `frames.json entry "${reference}" needs a kebab-case <group>/<name>.`, { reference });
|
|
48783
|
-
if (typeof ref !== "string" || !BOARD_REF.test(ref)) throw new FrameboardError("frame-map-invalid", `frames.json entry "${reference}" needs a board frame as <project>/<page>/<frame>.`, { reference });
|
|
49878
|
+
if (!REFERENCE.test(reference)) throw new FrameboardError("frame-map-invalid", `frames.json entry "${reference}" needs a kebab-case <group>/<name> or <group>/<section>/<name>.`, { reference });
|
|
49879
|
+
if (typeof ref !== "string" || !BOARD_REF.test(ref)) throw new FrameboardError("frame-map-invalid", `frames.json entry "${reference}" needs a board frame as <project>/<page>/<frame> or <project>/<page>/<frame>@<width>.`, { reference });
|
|
48784
49880
|
map.set(reference, ref);
|
|
48785
49881
|
}
|
|
48786
49882
|
return map;
|
|
@@ -48792,7 +49888,23 @@ function parseJson(json) {
|
|
|
48792
49888
|
throw new FrameboardError("frame-map-invalid", "frames.json does not parse as JSON.", {}, { cause: error });
|
|
48793
49889
|
}
|
|
48794
49890
|
}
|
|
48795
|
-
/**
|
|
49891
|
+
/** A mapped value as the board frame it names and the width it asks for, if any. */
|
|
49892
|
+
function mappedTarget(value) {
|
|
49893
|
+
const at = value.lastIndexOf("@");
|
|
49894
|
+
if (at === -1) return { ref: value };
|
|
49895
|
+
return {
|
|
49896
|
+
ref: value.slice(0, at),
|
|
49897
|
+
width: Number(value.slice(at + 1))
|
|
49898
|
+
};
|
|
49899
|
+
}
|
|
49900
|
+
/** Every value a map may name for one frame: its ref, and its ref at each width it shows at. */
|
|
49901
|
+
function frameTargets(frame) {
|
|
49902
|
+
return [frame.ref, ...[frame.box, ...frame.widths].map(({ width }) => `${frame.ref}@${width}`)];
|
|
49903
|
+
}
|
|
49904
|
+
/**
|
|
49905
|
+
* The mapped values the board does not hold, being a frame it lacks or a
|
|
49906
|
+
* width the frame does not show at, read against `frameTargets`.
|
|
49907
|
+
*/
|
|
48796
49908
|
function missingFrames(map, board) {
|
|
48797
49909
|
return [...map.values()].filter((ref) => !board.has(ref));
|
|
48798
49910
|
}
|
|
@@ -48839,8 +49951,8 @@ async function buildOutput({ root, folder, facesDir }) {
|
|
|
48839
49951
|
const map = parseFrameMap(await readFile(join(folder, "frames.json"), "utf8"));
|
|
48840
49952
|
const frames = await mappedFrames(root, map);
|
|
48841
49953
|
const output = /* @__PURE__ */ new Map();
|
|
48842
|
-
await Promise.all([...map].map(async ([reference,
|
|
48843
|
-
const { project, page, name } = frameOf(frames, ref);
|
|
49954
|
+
await Promise.all([...map].map(async ([reference, value]) => {
|
|
49955
|
+
const { project, page, name } = frameOf(frames, mappedTarget(value).ref);
|
|
48844
49956
|
const source = readFrame({
|
|
48845
49957
|
root,
|
|
48846
49958
|
project,
|
|
@@ -48850,18 +49962,35 @@ async function buildOutput({ root, folder, facesDir }) {
|
|
|
48850
49962
|
output.set(`${reference}.html`, await toReference(source, reference, folder));
|
|
48851
49963
|
for (const asset of frameAssets(source)) output.set(join("assets", project, asset), await readFile(join(assetsDirOf(source), asset)));
|
|
48852
49964
|
}));
|
|
49965
|
+
const targets = new Map([...map.values()].map((value) => {
|
|
49966
|
+
const { ref, width } = mappedTarget(value);
|
|
49967
|
+
const frame = frameOf(frames, ref);
|
|
49968
|
+
return [`${ref}@${width ?? frame.box.width}`, {
|
|
49969
|
+
frame,
|
|
49970
|
+
width
|
|
49971
|
+
}];
|
|
49972
|
+
}));
|
|
48853
49973
|
const captures = await mkdtemp(join(tmpdir(), "frameboard-references-"));
|
|
48854
49974
|
try {
|
|
48855
49975
|
const images = await withFrameHost({
|
|
48856
49976
|
root,
|
|
48857
49977
|
facesDir
|
|
48858
|
-
}, "references sync", (browser, baseUrl) =>
|
|
48859
|
-
|
|
48860
|
-
|
|
48861
|
-
|
|
48862
|
-
|
|
48863
|
-
|
|
48864
|
-
|
|
49978
|
+
}, "references sync", async (browser, baseUrl) => {
|
|
49979
|
+
const shot = [];
|
|
49980
|
+
for (const { frame, width } of targets.values()) shot.push(...await captureFrameImages(browser, {
|
|
49981
|
+
baseUrl,
|
|
49982
|
+
frames: [frame],
|
|
49983
|
+
themes: THEMES,
|
|
49984
|
+
out: captures,
|
|
49985
|
+
width: width ?? frame.box.width
|
|
49986
|
+
}));
|
|
49987
|
+
return shot;
|
|
49988
|
+
});
|
|
49989
|
+
for (const [reference, value] of map) {
|
|
49990
|
+
const { ref, width } = mappedTarget(value);
|
|
49991
|
+
const wanted = width ?? frameOf(frames, ref).box.width;
|
|
49992
|
+
for (const image of images.filter((image) => image.ref === ref && image.width === wanted)) output.set(`${reference}-${image.theme}.png`, await readFile(image.path));
|
|
49993
|
+
}
|
|
48865
49994
|
} finally {
|
|
48866
49995
|
await rm(captures, {
|
|
48867
49996
|
recursive: true,
|
|
@@ -48874,9 +50003,12 @@ async function buildOutput({ root, folder, facesDir }) {
|
|
|
48874
50003
|
async function mappedFrames(root, map) {
|
|
48875
50004
|
const { projects } = await scanBoard(root);
|
|
48876
50005
|
const board = new Map(projects.flatMap((project) => project.pages).flatMap((page) => page.frames).map((frame) => [frame.ref, frame]));
|
|
48877
|
-
const missing = missingFrames(map, new Set(board.
|
|
50006
|
+
const missing = missingFrames(map, new Set([...board.values()].flatMap(frameTargets)));
|
|
48878
50007
|
if (missing.length > 0) throw new FrameboardError("frame-not-found", `No board frame for: ${missing.join(", ")}. Nothing written.`, { missing });
|
|
48879
|
-
return new Map([...map.values()].map((
|
|
50008
|
+
return new Map([...map.values()].map((value) => {
|
|
50009
|
+
const { ref } = mappedTarget(value);
|
|
50010
|
+
return [ref, frameOf(board, ref)];
|
|
50011
|
+
}));
|
|
48880
50012
|
}
|
|
48881
50013
|
function frameOf(frames, ref) {
|
|
48882
50014
|
const frame = frames.get(ref);
|
|
@@ -49171,16 +50303,23 @@ function createThumbnailStore({ root, run, render, onRendered }) {
|
|
|
49171
50303
|
[
|
|
49172
50304
|
...LAYOUT_RULES,
|
|
49173
50305
|
...FONT_SIZE_RULES,
|
|
49174
|
-
...
|
|
50306
|
+
...CONTRAST_RULES,
|
|
50307
|
+
...DECLARATION_RULES,
|
|
50308
|
+
...SCROLL_EFFECT_RULES
|
|
49175
50309
|
];
|
|
49176
50310
|
/** The rules that read one theme's page and land one finding at most. */
|
|
49177
|
-
const THEMED_RULES = [
|
|
50311
|
+
const THEMED_RULES = [
|
|
50312
|
+
...LAYOUT_RULES,
|
|
50313
|
+
...FONT_SIZE_RULES,
|
|
50314
|
+
...CONTRAST_RULES
|
|
50315
|
+
];
|
|
49178
50316
|
/**
|
|
49179
50317
|
* Runs every browser rule on one frame at its layout size, in light and in
|
|
49180
50318
|
* dark, and merges the two. A rule tripping in one theme alone names that
|
|
49181
50319
|
* theme in its message. A missing face is measured in the fallback the board
|
|
49182
50320
|
* shows rather than refused, since the board shows it too. The declaration
|
|
49183
|
-
*
|
|
50321
|
+
* and scroll-effect rules read no theme, so they run on the first theme's
|
|
50322
|
+
* page alone.
|
|
49184
50323
|
*/
|
|
49185
50324
|
async function checkRendered(browser, { baseUrl, root, frame, config }) {
|
|
49186
50325
|
const [project = "", page = "", name = ""] = frame.ref.split("/");
|
|
@@ -49191,7 +50330,7 @@ async function checkRendered(browser, { baseUrl, root, frame, config }) {
|
|
|
49191
50330
|
name
|
|
49192
50331
|
});
|
|
49193
50332
|
const byTheme = /* @__PURE__ */ new Map();
|
|
49194
|
-
let
|
|
50333
|
+
let unthemed = [];
|
|
49195
50334
|
for (const theme of THEMES) {
|
|
49196
50335
|
const opened = await openFrame(browser, {
|
|
49197
50336
|
baseUrl,
|
|
@@ -49201,13 +50340,17 @@ async function checkRendered(browser, { baseUrl, root, frame, config }) {
|
|
|
49201
50340
|
fonts: "wait"
|
|
49202
50341
|
});
|
|
49203
50342
|
try {
|
|
49204
|
-
byTheme.set(theme, [
|
|
49205
|
-
|
|
50343
|
+
byTheme.set(theme, [
|
|
50344
|
+
...await checkLayout(opened.page, frame),
|
|
50345
|
+
...config.minFontSize === void 0 ? [] : await checkFontSize(opened.page, frame, config.minFontSize),
|
|
50346
|
+
...config.minContrast === void 0 ? [] : await checkContrast(opened.page, frame, config.minContrast)
|
|
50347
|
+
]);
|
|
50348
|
+
if (theme === THEMES[0]) unthemed = [...await checkDeclarations(opened.page, source), ...await checkScrollEffect(opened.page, frame)];
|
|
49206
50349
|
} finally {
|
|
49207
50350
|
await opened.close();
|
|
49208
50351
|
}
|
|
49209
50352
|
}
|
|
49210
|
-
return [...mergeThemes(byTheme), ...
|
|
50353
|
+
return [...mergeThemes(byTheme), ...unthemed];
|
|
49211
50354
|
}
|
|
49212
50355
|
/**
|
|
49213
50356
|
* One finding per rule across themes, in rule order. A rule both themes trip
|
|
@@ -49232,6 +50375,72 @@ function mergeThemes(byTheme) {
|
|
|
49232
50375
|
}
|
|
49233
50376
|
return merged;
|
|
49234
50377
|
}
|
|
50378
|
+
// src/server/claims/land.ts
|
|
50379
|
+
/**
|
|
50380
|
+
* Moves each reserved frame whose file now exists from its claim into the
|
|
50381
|
+
* layout: an entry at the claim's box on top of its page, unless the page
|
|
50382
|
+
* already holds one, then the claim drops its box and holds the frame as any
|
|
50383
|
+
* editing claim does. Answers the refs it landed, and none when the claims
|
|
50384
|
+
* file does not parse.
|
|
50385
|
+
*/
|
|
50386
|
+
async function landReserved(root, now) {
|
|
50387
|
+
let claims;
|
|
50388
|
+
try {
|
|
50389
|
+
claims = await readClaims(root, now);
|
|
50390
|
+
} catch (error) {
|
|
50391
|
+
if (error instanceof FrameboardError) return [];
|
|
50392
|
+
throw error;
|
|
50393
|
+
}
|
|
50394
|
+
const due = claims.flatMap((claim) => {
|
|
50395
|
+
const { box } = claim;
|
|
50396
|
+
const [project, page, name] = claim.frame.split("/");
|
|
50397
|
+
if (!box || !project || !page || !name) return [];
|
|
50398
|
+
const dir = join(root, project, page);
|
|
50399
|
+
return existsSync(join(dir, `${name}.html`)) ? [{
|
|
50400
|
+
claim: {
|
|
50401
|
+
...claim,
|
|
50402
|
+
box
|
|
50403
|
+
},
|
|
50404
|
+
page: dir,
|
|
50405
|
+
name
|
|
50406
|
+
}] : [];
|
|
50407
|
+
});
|
|
50408
|
+
if (due.length === 0) return [];
|
|
50409
|
+
await withLayouts(due.map((each) => each.page), async (layouts) => {
|
|
50410
|
+
for (const { claim, page, name } of due) {
|
|
50411
|
+
const layout = layoutAt(layouts, page);
|
|
50412
|
+
if (layout.hasEntry(name) || !layout.names.includes(name)) continue;
|
|
50413
|
+
const { x, y, width, height, hugWidth, hugHeight } = claim.box;
|
|
50414
|
+
layout.set(name, {
|
|
50415
|
+
box: {
|
|
50416
|
+
x,
|
|
50417
|
+
y,
|
|
50418
|
+
width,
|
|
50419
|
+
height
|
|
50420
|
+
},
|
|
50421
|
+
order: layout.placement(name).order,
|
|
50422
|
+
hidden: false,
|
|
50423
|
+
locked: false,
|
|
50424
|
+
hugWidth: hugWidth ?? false,
|
|
50425
|
+
hugHeight: hugHeight ?? false,
|
|
50426
|
+
scroll: false,
|
|
50427
|
+
widths: [],
|
|
50428
|
+
placed: true
|
|
50429
|
+
});
|
|
50430
|
+
layout.renumber();
|
|
50431
|
+
}
|
|
50432
|
+
});
|
|
50433
|
+
const landed = new Set(due.map((each) => each.claim.frame));
|
|
50434
|
+
await updateRecord(claimsPath(root), claimsSpec, (file) => ({
|
|
50435
|
+
...file,
|
|
50436
|
+
claims: file.claims.map((each) => {
|
|
50437
|
+
if (!landed.has(each.frame) || !each.box) return each;
|
|
50438
|
+
const { box: _box, ...rest } = each;
|
|
50439
|
+
return rest;
|
|
50440
|
+
})
|
|
50441
|
+
}));
|
|
50442
|
+
return [...landed];
|
|
50443
|
+
}
|
|
49235
50444
|
// src/server/claims/push.ts
|
|
49236
50445
|
/** setTimeout's longest delay, past which it fires at once. */
|
|
49237
50446
|
const MAX_DELAY_MS = 2 ** 31 - 1;
|
|
@@ -52597,6 +53806,23 @@ function placedRefs(previous, next, paths) {
|
|
|
52597
53806
|
const before = new Set(previous.projects.flatMap((project) => project.pages.flatMap((page) => page.frames.filter((frame) => frame.placed).map((frame) => frame.ref))));
|
|
52598
53807
|
return next.projects.flatMap((project) => project.pages.filter((page) => !written || written.has(join(page.path, "layout.json"))).flatMap((page) => page.frames.filter((frame) => frame.placed && (frame.hugWidth || frame.hugHeight) && !before.has(frame.ref)).map((frame) => frame.ref)));
|
|
52599
53808
|
}
|
|
53809
|
+
/**
|
|
53810
|
+
* The frames hugging their height whose list of linked widths differs
|
|
53811
|
+
* between two scans, as a `frame resize --widths` leaves one. That write
|
|
53812
|
+
* touches `layout.json` alone, which reloads nothing, so a width it adds is
|
|
53813
|
+
* measured here or holds its stand-in height until the frame file is next
|
|
53814
|
+
* written. A frame absent from `previous` is `placedRefs`'s to name.
|
|
53815
|
+
*/
|
|
53816
|
+
function relistedRefs(previous, next) {
|
|
53817
|
+
const before = new Map(previous.projects.flatMap((project) => project.pages.flatMap((page) => page.frames.map((frame) => [frame.ref, listed(frame)]))));
|
|
53818
|
+
return next.projects.flatMap((project) => project.pages.flatMap((page) => page.frames.filter((frame) => {
|
|
53819
|
+
const was = before.get(frame.ref);
|
|
53820
|
+
return frame.placed && frame.hugHeight && frame.widths.length > 0 && was !== void 0 && was !== listed(frame);
|
|
53821
|
+
}).map((frame) => frame.ref)));
|
|
53822
|
+
}
|
|
53823
|
+
function listed(frame) {
|
|
53824
|
+
return frame.widths.map(({ width }) => width).join(",");
|
|
53825
|
+
}
|
|
52600
53826
|
// src/server/live/findings.ts
|
|
52601
53827
|
/**
|
|
52602
53828
|
* The board's check findings, held between batches so a hello needs no
|
|
@@ -52850,20 +54076,20 @@ function send(socket, message) {
|
|
|
52850
54076
|
function createHug({ root, measure }) {
|
|
52851
54077
|
let queue = Promise.resolve();
|
|
52852
54078
|
let closed = false;
|
|
52853
|
-
const run = async (board, refs) => {
|
|
54079
|
+
const run = async (board, refs, parts) => {
|
|
52854
54080
|
const pages = /* @__PURE__ */ new Map();
|
|
52855
54081
|
let stale = false;
|
|
52856
|
-
for (const frame of huggingFrames(board, refs)) {
|
|
54082
|
+
for (const frame of huggingFrames(board, refs, parts)) {
|
|
52857
54083
|
if (closed) return false;
|
|
52858
54084
|
let size;
|
|
52859
54085
|
try {
|
|
52860
|
-
size = await measure
|
|
54086
|
+
size = await measureParts(measure, frame, parts);
|
|
52861
54087
|
} catch (error) {
|
|
52862
54088
|
if (error instanceof FrameboardError && error.code === "browser-not-found") break;
|
|
52863
54089
|
continue;
|
|
52864
54090
|
}
|
|
52865
|
-
if (size.
|
|
52866
|
-
stale ||= frame.hugWidth && size.width !== frame.box.width || frame.hugHeight && size.height !== frame.box.height;
|
|
54091
|
+
if (Object.keys(size).length === 0) continue;
|
|
54092
|
+
stale ||= frame.hugWidth && size.width !== void 0 && size.width !== frame.box.width || frame.hugHeight && size.height !== void 0 && size.height !== frame.box.height;
|
|
52867
54093
|
const page = `${frame.project}/${frame.page}`;
|
|
52868
54094
|
pages.set(page, [...pages.get(page) ?? [], {
|
|
52869
54095
|
frame,
|
|
@@ -52885,20 +54111,55 @@ function createHug({ root, measure }) {
|
|
|
52885
54111
|
}
|
|
52886
54112
|
return written || stale;
|
|
52887
54113
|
};
|
|
54114
|
+
const enqueue = (board, refs, parts) => {
|
|
54115
|
+
if (closed || huggingFrames(board, refs, parts).length === 0) return;
|
|
54116
|
+
queue = queue.then(() => run(board, refs, parts)).catch(() => {});
|
|
54117
|
+
};
|
|
52888
54118
|
return {
|
|
52889
|
-
now: (board, refs) =>
|
|
52890
|
-
|
|
52891
|
-
|
|
52892
|
-
|
|
54119
|
+
now: async (board, refs) => {
|
|
54120
|
+
const stale = await run(board, refs, "own");
|
|
54121
|
+
enqueue(board, refs, "linked");
|
|
54122
|
+
return stale;
|
|
52893
54123
|
},
|
|
54124
|
+
later: (board, refs) => enqueue(board, refs, "all"),
|
|
52894
54125
|
close: () => {
|
|
52895
54126
|
closed = true;
|
|
52896
54127
|
}
|
|
52897
54128
|
};
|
|
52898
54129
|
}
|
|
52899
|
-
|
|
54130
|
+
/**
|
|
54131
|
+
* Reads the parts a run asks for, a linked width only on a frame hugging its
|
|
54132
|
+
* height. An empty body at the frame's own box, or at every linked width,
|
|
54133
|
+
* reads nothing for that part, so the box it stands in for holds.
|
|
54134
|
+
*/
|
|
54135
|
+
async function measureParts(measure, frame, parts) {
|
|
54136
|
+
const size = {};
|
|
54137
|
+
if (parts !== "linked") {
|
|
54138
|
+
const own = await measure(frame);
|
|
54139
|
+
if (!own.empty) Object.assign(size, {
|
|
54140
|
+
width: own.width,
|
|
54141
|
+
height: own.height
|
|
54142
|
+
});
|
|
54143
|
+
}
|
|
54144
|
+
if (parts !== "own" && frame.hugHeight && frame.widths.length > 0) {
|
|
54145
|
+
const widths = [];
|
|
54146
|
+
for (const { width } of frame.widths) {
|
|
54147
|
+
const linked = await measure(frame, {
|
|
54148
|
+
width,
|
|
54149
|
+
height: referenceHeight(width)
|
|
54150
|
+
});
|
|
54151
|
+
if (!linked.empty) widths.push({
|
|
54152
|
+
width,
|
|
54153
|
+
height: linked.height
|
|
54154
|
+
});
|
|
54155
|
+
}
|
|
54156
|
+
if (widths.length > 0) size.widths = widths;
|
|
54157
|
+
}
|
|
54158
|
+
return size;
|
|
54159
|
+
}
|
|
54160
|
+
function huggingFrames(board, refs, parts) {
|
|
52900
54161
|
const wanted = new Set(refs);
|
|
52901
|
-
return board.projects.flatMap((project) => project.pages).flatMap((page) => page.frames).filter((frame) => wanted.has(frame.ref) && frame.placed && (frame.hugWidth || frame.hugHeight));
|
|
54162
|
+
return board.projects.flatMap((project) => project.pages).flatMap((page) => page.frames).filter((frame) => wanted.has(frame.ref) && frame.placed && (parts === "linked" ? frame.hugHeight && frame.widths.length > 0 : frame.hugWidth || frame.hugHeight));
|
|
52902
54163
|
}
|
|
52903
54164
|
/**
|
|
52904
54165
|
* The hugging frames whose file was written after their page's `layout.json`,
|
|
@@ -52931,6 +54192,41 @@ function ownFileRefs(board, paths) {
|
|
|
52931
54192
|
}
|
|
52932
54193
|
// src/server/live/rendered-findings.ts
|
|
52933
54194
|
/**
|
|
54195
|
+
* Runs `check` at the frame's own box, then at each linked width it lists,
|
|
54196
|
+
* tagging each finding read at a linked width with that width. A linked
|
|
54197
|
+
* finding the own box already reported, being the same rule and message at
|
|
54198
|
+
* the same place, is left out, since it is no fault of that width. A null
|
|
54199
|
+
* reading at any box answers null for the frame.
|
|
54200
|
+
*/
|
|
54201
|
+
async function acrossWidths(frame, check) {
|
|
54202
|
+
const own = await check({
|
|
54203
|
+
width: frame.box.width,
|
|
54204
|
+
height: frame.box.height
|
|
54205
|
+
});
|
|
54206
|
+
if (own === null) return null;
|
|
54207
|
+
const seen = new Set(own.map(sameness));
|
|
54208
|
+
const findings = [...own];
|
|
54209
|
+
for (const { width, height } of frame.widths) {
|
|
54210
|
+
const linked = await check({
|
|
54211
|
+
width,
|
|
54212
|
+
height
|
|
54213
|
+
});
|
|
54214
|
+
if (linked === null) return null;
|
|
54215
|
+
for (const finding of linked) if (!seen.has(sameness(finding))) findings.push({
|
|
54216
|
+
...finding,
|
|
54217
|
+
width
|
|
54218
|
+
});
|
|
54219
|
+
}
|
|
54220
|
+
return findings;
|
|
54221
|
+
}
|
|
54222
|
+
function sameness(finding) {
|
|
54223
|
+
return JSON.stringify([
|
|
54224
|
+
finding.rule,
|
|
54225
|
+
finding.message,
|
|
54226
|
+
finding.location
|
|
54227
|
+
]);
|
|
54228
|
+
}
|
|
54229
|
+
/**
|
|
52934
54230
|
* The server's warm checker. Rechecks run one at a time on their own queue,
|
|
52935
54231
|
* so a PNG never waits behind them, and a ref queued again before its result
|
|
52936
54232
|
* lands drops that result, so the board never shows findings from an older
|
|
@@ -53000,7 +54296,7 @@ function createRenderedFindings({ check, onResult }) {
|
|
|
53000
54296
|
known = frames;
|
|
53001
54297
|
const due = new Set(refs);
|
|
53002
54298
|
for (const [ref, frame] of frames) {
|
|
53003
|
-
const from = `${frame.box.width}x${
|
|
54299
|
+
const from = `${[frame.box, ...frame.widths].map(({ width, height }) => `${width}x${height}`).join(",")}@${frame.modifiedAt}`;
|
|
53004
54300
|
if (seen.get(ref) !== from) due.add(ref);
|
|
53005
54301
|
seen.set(ref, from);
|
|
53006
54302
|
}
|
|
@@ -53347,19 +54643,19 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
53347
54643
|
await thumbnails.empty();
|
|
53348
54644
|
const rendered = createRenderedFindings({
|
|
53349
54645
|
check: async (frame) => {
|
|
53350
|
-
const list = await checkRendered(await browser.get(), {
|
|
54646
|
+
const list = await acrossWidths(frame, async (box) => checkRendered(await browser.get(), {
|
|
53351
54647
|
baseUrl: baseUrl(),
|
|
53352
54648
|
root,
|
|
53353
54649
|
frame: {
|
|
53354
54650
|
ref: frame.ref,
|
|
53355
54651
|
path: boardPath(root, frame.path),
|
|
53356
|
-
box
|
|
53357
|
-
|
|
53358
|
-
|
|
53359
|
-
}
|
|
54652
|
+
box,
|
|
54653
|
+
scroll: frame.scroll,
|
|
54654
|
+
hugHeight: frame.hugHeight
|
|
53360
54655
|
},
|
|
53361
54656
|
config: readConfig(root, frame.project)
|
|
53362
|
-
});
|
|
54657
|
+
}));
|
|
54658
|
+
if (list === null) return null;
|
|
53363
54659
|
return await modifiedAt(frame.path) === frame.modifiedAt ? list : null;
|
|
53364
54660
|
},
|
|
53365
54661
|
onResult: (ref, list) => {
|
|
@@ -53372,11 +54668,11 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
53372
54668
|
});
|
|
53373
54669
|
}
|
|
53374
54670
|
});
|
|
53375
|
-
const measure = async (frame) => measureContent(await browser.get(), {
|
|
54671
|
+
const measure = async (frame, box) => measureContent(await browser.get(), {
|
|
53376
54672
|
baseUrl: baseUrl(),
|
|
53377
54673
|
ref: frame.ref,
|
|
53378
|
-
box: frame.box,
|
|
53379
|
-
hugWidth: frame.hugWidth,
|
|
54674
|
+
box: box ?? frame.box,
|
|
54675
|
+
hugWidth: box === void 0 && frame.hugWidth,
|
|
53380
54676
|
fonts: "wait"
|
|
53381
54677
|
});
|
|
53382
54678
|
const hug = createHug({
|
|
@@ -53458,6 +54754,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
53458
54754
|
});
|
|
53459
54755
|
server.on("upgrade", hub.handleUpgrade);
|
|
53460
54756
|
inTurn(async () => {
|
|
54757
|
+
await landReserved(root, /* @__PURE__ */ new Date()).catch(() => []);
|
|
53461
54758
|
let board = await scanBoard(root);
|
|
53462
54759
|
const stale = await writtenSinceLayout(board).catch(() => []);
|
|
53463
54760
|
if (await hug.now(board, stale).catch(() => false)) board = await scanBoard(root);
|
|
@@ -53531,12 +54828,15 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
|
|
|
53531
54828
|
let board;
|
|
53532
54829
|
let own;
|
|
53533
54830
|
let placed;
|
|
54831
|
+
let relisted = [];
|
|
53534
54832
|
try {
|
|
54833
|
+
await landReserved(root, /* @__PURE__ */ new Date()).catch(() => []);
|
|
53535
54834
|
board = await scanBoard(root);
|
|
53536
54835
|
const previous = scanned.board;
|
|
53537
54836
|
scanned.board = board;
|
|
53538
54837
|
own = ownFileRefs(board, paths);
|
|
53539
54838
|
placed = previous ? placedRefs(previous, board, paths).filter((ref) => !own.includes(ref)) : [];
|
|
54839
|
+
relisted = previous ? relistedRefs(previous, board) : [];
|
|
53540
54840
|
if (await hug.now(board, [...own, ...placed]).catch(() => false)) {
|
|
53541
54841
|
const measured = board;
|
|
53542
54842
|
board = await scanBoard(root);
|
|
@@ -53557,7 +54857,7 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
|
|
|
53557
54857
|
const last = shown.board;
|
|
53558
54858
|
shown.board = board;
|
|
53559
54859
|
const refs = reloadRefs(root, paths, board, tokens);
|
|
53560
|
-
hug.later(board, refs.filter((ref) => !own.includes(ref) && !placed.includes(ref)));
|
|
54860
|
+
hug.later(board, [.../* @__PURE__ */ new Set([...refs, ...relisted])].filter((ref) => !own.includes(ref) && !placed.includes(ref)));
|
|
53561
54861
|
if (refs.length > 0) {
|
|
53562
54862
|
const reloads = unmovedRefs(refs, board, moved(), last);
|
|
53563
54863
|
if (reloads.length > 0) hub.broadcast({
|