frameboard 0.29.0 → 0.30.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 +958 -238
- package/dist/client/assets/index-DLAfZ8l-.js +114 -0
- package/dist/client/assets/index-c8ObdNHS.css +2 -0
- package/dist/client/index.html +2 -2
- package/dist/hook.js +2 -1
- 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
|
@@ -3054,7 +3054,8 @@ const EXIT_CODES = {
|
|
|
3054
3054
|
"format-refused": 10,
|
|
3055
3055
|
"formatter-not-found": 9,
|
|
3056
3056
|
"references-stale": 14,
|
|
3057
|
-
"page-file-load": 10
|
|
3057
|
+
"page-file-load": 10,
|
|
3058
|
+
"image-missing": 10
|
|
3058
3059
|
};
|
|
3059
3060
|
var FrameboardError = class extends Error {
|
|
3060
3061
|
code;
|
|
@@ -8734,6 +8735,14 @@ function object$1(shape, params) {
|
|
|
8734
8735
|
};
|
|
8735
8736
|
return new ZodObject(def);
|
|
8736
8737
|
}
|
|
8738
|
+
function strictObject(shape, params) {
|
|
8739
|
+
return new ZodObject({
|
|
8740
|
+
type: "object",
|
|
8741
|
+
shape,
|
|
8742
|
+
catchall: never(),
|
|
8743
|
+
...normalizeParams(params)
|
|
8744
|
+
});
|
|
8745
|
+
}
|
|
8737
8746
|
function looseObject(shape, params) {
|
|
8738
8747
|
return new ZodObject({
|
|
8739
8748
|
type: "object",
|
|
@@ -9157,7 +9166,9 @@ const projectChecksSchema = looseObject({
|
|
|
9157
9166
|
allowedFonts: array$1(string$1()).optional(),
|
|
9158
9167
|
noUppercase: boolean$1().optional(),
|
|
9159
9168
|
/** The smallest text size in pixels the `min-font-size` rule allows. */
|
|
9160
|
-
minFontSize: number().positive().optional()
|
|
9169
|
+
minFontSize: number().positive().optional(),
|
|
9170
|
+
/** The lowest text contrast ratio the `min-contrast` rule allows, 4.5 being WCAG's. */
|
|
9171
|
+
minContrast: number().min(1).optional()
|
|
9161
9172
|
});
|
|
9162
9173
|
const projectFileSchema = looseObject({
|
|
9163
9174
|
version: literal(1),
|
|
@@ -9517,7 +9528,7 @@ async function isDirectory(path) {
|
|
|
9517
9528
|
}
|
|
9518
9529
|
}
|
|
9519
9530
|
// package.json
|
|
9520
|
-
var version$1 = "0.
|
|
9531
|
+
var version$1 = "0.30.0";
|
|
9521
9532
|
var dependencies = { "playwright-core": "1.65.0" };
|
|
9522
9533
|
var peerDependencies = { "oxfmt": "0.77.0" };
|
|
9523
9534
|
// src/shared/version.ts
|
|
@@ -9646,6 +9657,205 @@ function nextFreeName(base, taken) {
|
|
|
9646
9657
|
if (!lowered.has(candidate.toLowerCase())) return candidate;
|
|
9647
9658
|
}
|
|
9648
9659
|
}
|
|
9660
|
+
// src/shared/records/claims.ts
|
|
9661
|
+
/**
|
|
9662
|
+
* Where a reserved frame will land, and which axes take their size from the
|
|
9663
|
+
* content once it does, as `frame add` would place it.
|
|
9664
|
+
*/
|
|
9665
|
+
const claimBoxSchema = object$1({
|
|
9666
|
+
x: number(),
|
|
9667
|
+
y: number(),
|
|
9668
|
+
width: number(),
|
|
9669
|
+
height: number(),
|
|
9670
|
+
hugWidth: boolean$1().optional(),
|
|
9671
|
+
hugHeight: boolean$1().optional()
|
|
9672
|
+
});
|
|
9673
|
+
/** One session's hold on a frame while its agent rewrites it. */
|
|
9674
|
+
const claimSchema = looseObject({
|
|
9675
|
+
/** The canonical frame ref, `<project>/<page>/<frame>`. */
|
|
9676
|
+
frame: string$1(),
|
|
9677
|
+
/** The session holding it, the id `inbox` and a note's `to` use. */
|
|
9678
|
+
session: string$1(),
|
|
9679
|
+
/** The agent's name, such as `claude`, whose first letter the board shows. */
|
|
9680
|
+
agent: string$1(),
|
|
9681
|
+
/** The listener's tag form, `<agent> · <project folder>`. */
|
|
9682
|
+
tag: string$1(),
|
|
9683
|
+
/** When the session first claimed it, kept across renewals. */
|
|
9684
|
+
claimedAt: string$1(),
|
|
9685
|
+
/** When it lapses unless the session claims it again. */
|
|
9686
|
+
expiresAt: string$1(),
|
|
9687
|
+
/** A reservation's box, held until the frame's file lands in the layout. */
|
|
9688
|
+
box: claimBoxSchema.optional(),
|
|
9689
|
+
/** The id one `editing --new` call stamps on each frame it reserves, which renew together. */
|
|
9690
|
+
set: string$1().optional(),
|
|
9691
|
+
/** When the session last claimed a reserved frame plainly, so the latest in a set reads as drawing. */
|
|
9692
|
+
drawingAt: string$1().optional()
|
|
9693
|
+
});
|
|
9694
|
+
/**
|
|
9695
|
+
* Whether a write naming `ref` reaches the frame a claim holds, being the
|
|
9696
|
+
* frame itself, its page, or its project, so a page ref never matches a
|
|
9697
|
+
* sibling page whose name only starts the same.
|
|
9698
|
+
*/
|
|
9699
|
+
function claimCovers(ref, frame) {
|
|
9700
|
+
return frame === ref || frame.startsWith(`${ref}/`);
|
|
9701
|
+
}
|
|
9702
|
+
/** `.run/claims.json`. */
|
|
9703
|
+
const claimsFileSchema = looseObject({
|
|
9704
|
+
version: literal(1),
|
|
9705
|
+
claims: array$1(claimSchema)
|
|
9706
|
+
});
|
|
9707
|
+
// src/server/claims/store.ts
|
|
9708
|
+
/** How long a claim holds after its last claim or renewal. */
|
|
9709
|
+
const CLAIM_TTL_MS = 3e5;
|
|
9710
|
+
const claimsSpec = {
|
|
9711
|
+
schema: claimsFileSchema,
|
|
9712
|
+
invalidCode: "claims-invalid",
|
|
9713
|
+
empty: () => ({
|
|
9714
|
+
version: 1,
|
|
9715
|
+
claims: []
|
|
9716
|
+
})
|
|
9717
|
+
};
|
|
9718
|
+
function claimsPath(root) {
|
|
9719
|
+
return join(root, RUN_FOLDER, CLAIMS_FILE);
|
|
9720
|
+
}
|
|
9721
|
+
function claimedError(holder, frame) {
|
|
9722
|
+
return new FrameboardError("frame-claimed", `${holder.tag} is editing ${frame} until ${holder.expiresAt}.`, {
|
|
9723
|
+
frame: holder.frame,
|
|
9724
|
+
session: holder.session,
|
|
9725
|
+
tag: holder.tag,
|
|
9726
|
+
expiresAt: holder.expiresAt
|
|
9727
|
+
});
|
|
9728
|
+
}
|
|
9729
|
+
function isLive(claim, now) {
|
|
9730
|
+
return Date.parse(claim.expiresAt) > now.getTime();
|
|
9731
|
+
}
|
|
9732
|
+
/** The claims still live at `now`, refusing a file that does not parse. */
|
|
9733
|
+
async function readClaims(root, now) {
|
|
9734
|
+
return (await readRecord(claimsPath(root), claimsSpec)).claims.filter((claim) => isLive(claim, now));
|
|
9735
|
+
}
|
|
9736
|
+
/**
|
|
9737
|
+
* The box a live reservation holds for a frame, else undefined, a claims
|
|
9738
|
+
* file that does not parse reading as holding none.
|
|
9739
|
+
*/
|
|
9740
|
+
async function reservedBox(root, frame, now = /* @__PURE__ */ new Date()) {
|
|
9741
|
+
try {
|
|
9742
|
+
return (await readClaims(root, now)).find((each) => each.frame === frame && each.box)?.box;
|
|
9743
|
+
} catch (error) {
|
|
9744
|
+
if (error instanceof FrameboardError) return void 0;
|
|
9745
|
+
throw error;
|
|
9746
|
+
}
|
|
9747
|
+
}
|
|
9748
|
+
/**
|
|
9749
|
+
* Claims a frame for a session, or renews the session's own claim keeping
|
|
9750
|
+
* `claimedAt`. A frame another session holds live refuses `frame-claimed`.
|
|
9751
|
+
*/
|
|
9752
|
+
async function claim(root, fields, now) {
|
|
9753
|
+
await ensureRunFolder(root);
|
|
9754
|
+
return (await updateRecord(claimsPath(root), claimsSpec, (file) => {
|
|
9755
|
+
const live = file.claims.filter((each) => isLive(each, now));
|
|
9756
|
+
const current = live.find((each) => each.frame === fields.frame);
|
|
9757
|
+
if (current && current.session !== fields.session) throw claimedError(current, fields.frame);
|
|
9758
|
+
const expiresAt = new Date(now.getTime() + CLAIM_TTL_MS).toISOString();
|
|
9759
|
+
const held = {
|
|
9760
|
+
...fields,
|
|
9761
|
+
...setOf(current),
|
|
9762
|
+
claimedAt: current?.claimedAt ?? now.toISOString(),
|
|
9763
|
+
expiresAt,
|
|
9764
|
+
...current?.box ? { drawingAt: now.toISOString() } : {}
|
|
9765
|
+
};
|
|
9766
|
+
const set = current?.set;
|
|
9767
|
+
const renewed = live.map((each) => {
|
|
9768
|
+
if (each === current) return held;
|
|
9769
|
+
return set !== void 0 && each.set === set && each.session === fields.session ? {
|
|
9770
|
+
...each,
|
|
9771
|
+
expiresAt
|
|
9772
|
+
} : each;
|
|
9773
|
+
});
|
|
9774
|
+
return {
|
|
9775
|
+
...file,
|
|
9776
|
+
claims: current ? renewed : [...renewed, held]
|
|
9777
|
+
};
|
|
9778
|
+
})).claims.find((each) => each.frame === fields.frame);
|
|
9779
|
+
}
|
|
9780
|
+
/** The reservation a renewal carries over from the claim it renews. */
|
|
9781
|
+
function setOf(current) {
|
|
9782
|
+
if (!current) return {};
|
|
9783
|
+
const { box, set, drawingAt } = current;
|
|
9784
|
+
return {
|
|
9785
|
+
...box ? { box } : {},
|
|
9786
|
+
...set === void 0 ? {} : { set },
|
|
9787
|
+
...drawingAt === void 0 ? {} : { drawingAt }
|
|
9788
|
+
};
|
|
9789
|
+
}
|
|
9790
|
+
/**
|
|
9791
|
+
* Reserves every frame named as one set, each a claim carrying its box and
|
|
9792
|
+
* the set's id, in one write. A frame another session holds live refuses
|
|
9793
|
+
* `frame-claimed` before any is written, and the session's own claim on a
|
|
9794
|
+
* named frame is replaced.
|
|
9795
|
+
*/
|
|
9796
|
+
async function reserve(root, holder, reservations, now) {
|
|
9797
|
+
await ensureRunFolder(root);
|
|
9798
|
+
const set = randomUUID();
|
|
9799
|
+
const claimedAt = now.toISOString();
|
|
9800
|
+
const expiresAt = new Date(now.getTime() + CLAIM_TTL_MS).toISOString();
|
|
9801
|
+
const made = reservations.map(({ frame, box }) => ({
|
|
9802
|
+
frame,
|
|
9803
|
+
...holder,
|
|
9804
|
+
claimedAt,
|
|
9805
|
+
expiresAt,
|
|
9806
|
+
box,
|
|
9807
|
+
set
|
|
9808
|
+
}));
|
|
9809
|
+
const names = new Set(made.map((each) => each.frame));
|
|
9810
|
+
await updateRecord(claimsPath(root), claimsSpec, (file) => {
|
|
9811
|
+
const live = file.claims.filter((each) => isLive(each, now));
|
|
9812
|
+
const taken = live.find((each) => names.has(each.frame) && each.session !== holder.session);
|
|
9813
|
+
if (taken) throw claimedError(taken, taken.frame);
|
|
9814
|
+
return {
|
|
9815
|
+
...file,
|
|
9816
|
+
claims: [...live.filter((each) => !names.has(each.frame)), ...made]
|
|
9817
|
+
};
|
|
9818
|
+
});
|
|
9819
|
+
return made;
|
|
9820
|
+
}
|
|
9821
|
+
/**
|
|
9822
|
+
* Drops the live reservation on a frame whoever holds it, refusing a claim
|
|
9823
|
+
* with no box so an agent's claim on an existing frame is never broken.
|
|
9824
|
+
* Answers the dropped claim, or undefined when the frame holds none.
|
|
9825
|
+
*/
|
|
9826
|
+
async function releaseReservation(root, frame, now) {
|
|
9827
|
+
let dropped;
|
|
9828
|
+
await ensureRunFolder(root);
|
|
9829
|
+
await updateRecord(claimsPath(root), claimsSpec, (file) => {
|
|
9830
|
+
const live = file.claims.filter((each) => isLive(each, now));
|
|
9831
|
+
dropped = live.find((each) => each.frame === frame && each.box);
|
|
9832
|
+
return {
|
|
9833
|
+
...file,
|
|
9834
|
+
claims: live.filter((each) => each !== dropped)
|
|
9835
|
+
};
|
|
9836
|
+
});
|
|
9837
|
+
return dropped;
|
|
9838
|
+
}
|
|
9839
|
+
/**
|
|
9840
|
+
* Drops a session's claim on one frame, or every claim it holds when no
|
|
9841
|
+
* frame is named, returning what it dropped.
|
|
9842
|
+
*/
|
|
9843
|
+
async function release$1(root, session, frame, now) {
|
|
9844
|
+
const dropped = [];
|
|
9845
|
+
await ensureRunFolder(root);
|
|
9846
|
+
await updateRecord(claimsPath(root), claimsSpec, (file) => {
|
|
9847
|
+
const kept = [];
|
|
9848
|
+
for (const each of file.claims) {
|
|
9849
|
+
if (!isLive(each, now)) continue;
|
|
9850
|
+
(each.session === session && (frame === void 0 || each.frame === frame) ? dropped : kept).push(each);
|
|
9851
|
+
}
|
|
9852
|
+
return {
|
|
9853
|
+
...file,
|
|
9854
|
+
claims: kept
|
|
9855
|
+
};
|
|
9856
|
+
});
|
|
9857
|
+
return dropped;
|
|
9858
|
+
}
|
|
9649
9859
|
// src/server/board/refs.ts
|
|
9650
9860
|
/**
|
|
9651
9861
|
* The project a verb acts on: the one named, else the board's only project.
|
|
@@ -9786,12 +9996,21 @@ async function addFrame(root, ref, options) {
|
|
|
9786
9996
|
...options,
|
|
9787
9997
|
allowMissing: true
|
|
9788
9998
|
});
|
|
9789
|
-
const size = sizeOf(options);
|
|
9790
9999
|
const page = pageDir(frame);
|
|
10000
|
+
const reserved = options.x === void 0 && options.y === void 0 ? await reservedBox(root, refOf$1(frame)) : void 0;
|
|
10001
|
+
const sized = options.size !== void 0 || options.width !== void 0 || options.height !== void 0;
|
|
10002
|
+
const size = reserved && !sized ? {
|
|
10003
|
+
width: reserved.width,
|
|
10004
|
+
height: reserved.height
|
|
10005
|
+
} : sizeOf(options);
|
|
10006
|
+
const hugs = reserved && !sized ? {
|
|
10007
|
+
hugWidth: reserved.hugWidth ?? false,
|
|
10008
|
+
hugHeight: reserved.hugHeight ?? false
|
|
10009
|
+
} : hugsOf(options);
|
|
9791
10010
|
await withLayouts([page], async (layouts) => {
|
|
9792
10011
|
const layout = layoutAt(layouts, page);
|
|
9793
10012
|
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) });
|
|
10013
|
+
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
10014
|
const names = exists ? layout.names : [...layout.names, frame.name].sort();
|
|
9796
10015
|
const slot = names.filter((name) => name === frame.name || layout.hasEntry(name));
|
|
9797
10016
|
const computed = placeFrames(layout.file.frames, slot).get(frame.name);
|
|
@@ -9806,10 +10025,10 @@ async function addFrame(root, ref, options) {
|
|
|
9806
10025
|
box: {
|
|
9807
10026
|
...computed.box,
|
|
9808
10027
|
...size,
|
|
9809
|
-
x: options.x ?? computed.box.x,
|
|
9810
|
-
y: options.y ?? computed.box.y
|
|
10028
|
+
x: options.x ?? reserved?.x ?? computed.box.x,
|
|
10029
|
+
y: options.y ?? reserved?.y ?? computed.box.y
|
|
9811
10030
|
},
|
|
9812
|
-
...
|
|
10031
|
+
...hugs
|
|
9813
10032
|
});
|
|
9814
10033
|
layout.renumber();
|
|
9815
10034
|
}, journal);
|
|
@@ -10096,7 +10315,7 @@ async function deleteFrame(root, ref, options) {
|
|
|
10096
10315
|
else await rm(frame.path);
|
|
10097
10316
|
layout.remove(frame.name);
|
|
10098
10317
|
}, journal);
|
|
10099
|
-
return { deleted: refOf(frame) };
|
|
10318
|
+
return { deleted: refOf$1(frame) };
|
|
10100
10319
|
}
|
|
10101
10320
|
async function updatePlacement(root, ref, options, change) {
|
|
10102
10321
|
const frame = await resolveFrameRef(root, ref, options);
|
|
@@ -10108,6 +10327,7 @@ async function updatePlacement(root, ref, options, change) {
|
|
|
10108
10327
|
return frameRecord(root, frame.project, frame.page, frame.name);
|
|
10109
10328
|
}
|
|
10110
10329
|
/** Which axes `frame add` leaves hugging: every one no size option names, the height under a preset. */
|
|
10330
|
+
/** Which axes a frame placed with these options sizes from its content. */
|
|
10111
10331
|
function hugsOf({ size, width, height }) {
|
|
10112
10332
|
return {
|
|
10113
10333
|
hugWidth: size === void 0 && width === void 0,
|
|
@@ -10309,7 +10529,7 @@ async function frameRecords(root, project, page) {
|
|
|
10309
10529
|
function pageDir(frame) {
|
|
10310
10530
|
return join(frame.root, frame.project, frame.page);
|
|
10311
10531
|
}
|
|
10312
|
-
function refOf(frame) {
|
|
10532
|
+
function refOf$1(frame) {
|
|
10313
10533
|
return `${frame.project}/${frame.page}/${frame.name}`;
|
|
10314
10534
|
}
|
|
10315
10535
|
// node_modules/@hono/node-server/dist/index.mjs
|
|
@@ -22146,102 +22366,6 @@ function framesNamed(root, paths) {
|
|
|
22146
22366
|
}
|
|
22147
22367
|
return refs;
|
|
22148
22368
|
}
|
|
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
22369
|
// src/server/claims/gate.ts
|
|
22246
22370
|
/**
|
|
22247
22371
|
* Refuses `frame-claimed` when another session holds a frame the hand write
|
|
@@ -28889,7 +29013,7 @@ const THEME_RULES = [{
|
|
|
28889
29013
|
severity: "error",
|
|
28890
29014
|
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
29015
|
}];
|
|
28892
|
-
const finding$
|
|
29016
|
+
const finding$10 = findingFor(THEME_RULES);
|
|
28893
29017
|
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
29018
|
const COLOR_FUNCTION = /\b(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\(/i;
|
|
28895
29019
|
const HEX_COLOR = /#[0-9a-f]{3,8}\b/i;
|
|
@@ -28899,7 +29023,7 @@ function checkTheme(source) {
|
|
|
28899
29023
|
const { firstColor, bothThemes } = readThemeColors(source);
|
|
28900
29024
|
if (!firstColor || bothThemes) return [];
|
|
28901
29025
|
const { path, location } = firstColor;
|
|
28902
|
-
return [finding$
|
|
29026
|
+
return [finding$10("theme", {
|
|
28903
29027
|
frame: source.ref,
|
|
28904
29028
|
path,
|
|
28905
29029
|
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 +29522,13 @@ const ASSET_KINDS = [
|
|
|
29398
29522
|
"script",
|
|
29399
29523
|
"other"
|
|
29400
29524
|
];
|
|
29401
|
-
/** The kinds a frame shows as an `<img
|
|
29525
|
+
/** The kinds a frame shows as an `<img>`, a `<video>`, or an `<audio>`, which the board places by hand. */
|
|
29402
29526
|
const PLACEABLE_KINDS = [
|
|
29403
29527
|
"image",
|
|
29404
29528
|
"gif",
|
|
29405
29529
|
"svg",
|
|
29406
|
-
"video"
|
|
29530
|
+
"video",
|
|
29531
|
+
"audio"
|
|
29407
29532
|
];
|
|
29408
29533
|
function isPlaceableKind(kind) {
|
|
29409
29534
|
return PLACEABLE_KINDS.includes(kind);
|
|
@@ -29420,6 +29545,7 @@ const ACCEPTED = {
|
|
|
29420
29545
|
mp4: "video",
|
|
29421
29546
|
webm: "video",
|
|
29422
29547
|
mov: "video",
|
|
29548
|
+
m4v: "video",
|
|
29423
29549
|
mp3: "audio",
|
|
29424
29550
|
wav: "audio",
|
|
29425
29551
|
ogg: "audio",
|
|
@@ -29501,7 +29627,7 @@ async function walk(folder, prefix, real, into) {
|
|
|
29501
29627
|
* can show it, confined as `listAssets` is: a path naming a dot-named
|
|
29502
29628
|
* segment, a `..`, or any file whose real path leaves the folder is
|
|
29503
29629
|
* `asset-missing`, as is one that is not there. A file that is there but is
|
|
29504
|
-
* no image, GIF, SVG, or
|
|
29630
|
+
* no image, GIF, SVG, video, or audio is `asset-not-placeable`.
|
|
29505
29631
|
*/
|
|
29506
29632
|
async function resolveAsset(projectDir, path) {
|
|
29507
29633
|
const missing = {
|
|
@@ -29524,7 +29650,7 @@ async function resolveAsset(projectDir, path) {
|
|
|
29524
29650
|
if (!isPlaceableKind(kind)) return {
|
|
29525
29651
|
ok: false,
|
|
29526
29652
|
code: "asset-not-placeable",
|
|
29527
|
-
message: `assets/${path} is not an image, GIF, SVG, or
|
|
29653
|
+
message: `assets/${path} is not an image, GIF, SVG, video, or audio, so a frame cannot show it`
|
|
29528
29654
|
};
|
|
29529
29655
|
return {
|
|
29530
29656
|
ok: true,
|
|
@@ -29713,6 +29839,77 @@ function checkRoutes(access, checks) {
|
|
|
29713
29839
|
});
|
|
29714
29840
|
return app;
|
|
29715
29841
|
}
|
|
29842
|
+
// src/server/routes/envelope.ts
|
|
29843
|
+
/** The status each refusal of a structure or history write answers with. */
|
|
29844
|
+
const STATUS$4 = {
|
|
29845
|
+
usage: 400,
|
|
29846
|
+
"invalid-name": 400,
|
|
29847
|
+
"project-required": 400,
|
|
29848
|
+
"project-not-found": 404,
|
|
29849
|
+
"page-not-found": 404,
|
|
29850
|
+
"frame-not-found": 404,
|
|
29851
|
+
"section-not-found": 404,
|
|
29852
|
+
"name-taken": 409,
|
|
29853
|
+
"stale-layout": 409,
|
|
29854
|
+
"frame-claimed": 409,
|
|
29855
|
+
"undo-overtaken": 409,
|
|
29856
|
+
"nothing-to-undo": 409,
|
|
29857
|
+
"tokens-exist": 409,
|
|
29858
|
+
"stale-tokens": 409,
|
|
29859
|
+
"invalid-edit": 409,
|
|
29860
|
+
"frame-locked": 423,
|
|
29861
|
+
"layout-invalid": 422,
|
|
29862
|
+
"project-file-invalid": 422,
|
|
29863
|
+
"fit-unbounded": 422,
|
|
29864
|
+
"claims-invalid": 422,
|
|
29865
|
+
"lock-timeout": 503,
|
|
29866
|
+
"browser-not-found": 503
|
|
29867
|
+
};
|
|
29868
|
+
/**
|
|
29869
|
+
* Answers a refusal in the CLI's `{ ok, error }` envelope, for a route
|
|
29870
|
+
* module's `onError`. Anything else is a fault and goes on to Hono.
|
|
29871
|
+
*/
|
|
29872
|
+
function answerRefusal(error, c) {
|
|
29873
|
+
if (!(error instanceof FrameboardError)) throw error;
|
|
29874
|
+
return c.json({
|
|
29875
|
+
ok: false,
|
|
29876
|
+
error: {
|
|
29877
|
+
code: error.code,
|
|
29878
|
+
message: error.message,
|
|
29879
|
+
details: error.details
|
|
29880
|
+
}
|
|
29881
|
+
}, STATUS$4[error.code] ?? 500);
|
|
29882
|
+
}
|
|
29883
|
+
/** The request's JSON body as the schema reads it, or `usage` naming what failed. */
|
|
29884
|
+
async function parseBody$1(request, schema) {
|
|
29885
|
+
const parsed = schema.safeParse(await request.json().catch(() => null));
|
|
29886
|
+
if (!parsed.success) throw new FrameboardError("usage", `The body ${parsed.error.message}`);
|
|
29887
|
+
return parsed.data;
|
|
29888
|
+
}
|
|
29889
|
+
// src/server/routes/claims.ts
|
|
29890
|
+
const ReleaseBody = object$1({ frame: string$1().min(1) });
|
|
29891
|
+
/**
|
|
29892
|
+
* `POST /api/claims/release` with `{ frame }`, the canonical ref a claim
|
|
29893
|
+
* names, dropping the live reservation on that frame whichever session holds
|
|
29894
|
+
* it. It sits behind `requireWriter`, and a frame holding no reservation,
|
|
29895
|
+
* including one an agent holds an editing claim on, refuses
|
|
29896
|
+
* `frame-not-found` and is left as it was.
|
|
29897
|
+
*/
|
|
29898
|
+
function claimsRoutes(root, access) {
|
|
29899
|
+
const app = new Hono();
|
|
29900
|
+
app.onError(answerRefusal);
|
|
29901
|
+
app.use("/api/claims/release", requireWriter(access));
|
|
29902
|
+
app.post("/api/claims/release", async (c) => {
|
|
29903
|
+
const { frame } = await parseBody$1(c.req.raw, ReleaseBody);
|
|
29904
|
+
const released = await releaseReservation(root, frame, /* @__PURE__ */ new Date());
|
|
29905
|
+
if (!released) throw new FrameboardError("frame-not-found", `No reservation holds ${frame}.`, { frame });
|
|
29906
|
+
return c.json({
|
|
29907
|
+
ok: true,
|
|
29908
|
+
data: { released }
|
|
29909
|
+
});
|
|
29910
|
+
});
|
|
29911
|
+
return app;
|
|
29912
|
+
}
|
|
29716
29913
|
// src/server/clipboard/wsl.ts
|
|
29717
29914
|
/** The folder under Windows' temp folder each copy writes into. */
|
|
29718
29915
|
const CLIP_FOLDER = "frameboard-clip";
|
|
@@ -29722,33 +29919,42 @@ const WINDOWS_RESERVED = /[<>:"/\\|?*]/g;
|
|
|
29722
29919
|
* The Windows clipboard reached from WSL. The images land in Windows' temp
|
|
29723
29920
|
* folder, since a file drop list names Windows paths and a pasting app reads
|
|
29724
29921
|
* 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.
|
|
29922
|
+
* the only time a pasted list is known to be done with. Copies run one at a
|
|
29923
|
+
* time, since a copy clearing the folder while another is still setting the
|
|
29924
|
+
* clipboard deletes the files that copy is about to name.
|
|
29726
29925
|
*/
|
|
29727
29926
|
function wslClipboard(run) {
|
|
29927
|
+
let previous = Promise.resolve();
|
|
29728
29928
|
return {
|
|
29729
29929
|
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
|
-
|
|
29930
|
+
write: (files) => {
|
|
29931
|
+
const copy = previous.then(() => writeCopy(run, files));
|
|
29932
|
+
previous = copy.catch(() => void 0);
|
|
29933
|
+
return copy;
|
|
29934
|
+
}
|
|
29935
|
+
};
|
|
29936
|
+
}
|
|
29937
|
+
/** Writes one copy's images into a fresh folder and sets them on the clipboard. */
|
|
29938
|
+
async function writeCopy(run, files) {
|
|
29939
|
+
const windowsDir = `${(await run("powershell.exe", [
|
|
29940
|
+
"-NoProfile",
|
|
29941
|
+
"-Command",
|
|
29942
|
+
"[IO.Path]::GetTempPath()"
|
|
29943
|
+
])).trim().replace(/\\$/, "")}\\${CLIP_FOLDER}\\${randomUUID()}`;
|
|
29944
|
+
const linuxDir = (await run("wslpath", [windowsDir])).trim();
|
|
29945
|
+
await rm(join(linuxDir, ".."), {
|
|
29946
|
+
recursive: true,
|
|
29947
|
+
force: true
|
|
29948
|
+
});
|
|
29949
|
+
await mkdir(linuxDir, { recursive: true });
|
|
29950
|
+
const names = fileNames(files);
|
|
29951
|
+
await Promise.all(files.map((file, index) => writeFile(join(linuxDir, names[index] ?? ""), file.bytes)));
|
|
29952
|
+
await run("powershell.exe", [
|
|
29953
|
+
"-NoProfile",
|
|
29954
|
+
"-STA",
|
|
29955
|
+
"-Command",
|
|
29956
|
+
`Set-Clipboard -Path ${pathList(windowsDir, names)}`
|
|
29957
|
+
]);
|
|
29752
29958
|
}
|
|
29753
29959
|
/** Each file's name made safe for Windows and unique in the folder, as `hero.png`, `hero-2.png`. */
|
|
29754
29960
|
function fileNames(files) {
|
|
@@ -29793,52 +29999,6 @@ function processHost() {
|
|
|
29793
29999
|
onPath: (command) => (process.env.PATH ?? "").split(delimiter).some((dir) => dir !== "" && existsSync(join(dir, command)))
|
|
29794
30000
|
};
|
|
29795
30001
|
}
|
|
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
30002
|
// src/server/routes/clipboard.ts
|
|
29843
30003
|
const STATUS$3 = {
|
|
29844
30004
|
usage: 400,
|
|
@@ -29847,6 +30007,7 @@ const STATUS$3 = {
|
|
|
29847
30007
|
"page-not-found": 404,
|
|
29848
30008
|
"frame-not-found": 404,
|
|
29849
30009
|
"font-missing": 422,
|
|
30010
|
+
"image-missing": 422,
|
|
29850
30011
|
"capture-too-large": 422,
|
|
29851
30012
|
"clipboard-unsupported": 501,
|
|
29852
30013
|
"browser-not-found": 503
|
|
@@ -30431,8 +30592,10 @@ function checkChange(change) {
|
|
|
30431
30592
|
}
|
|
30432
30593
|
return;
|
|
30433
30594
|
}
|
|
30434
|
-
|
|
30435
|
-
|
|
30595
|
+
if ("value" in change) {
|
|
30596
|
+
const invalid = checkValue(change.value);
|
|
30597
|
+
if (invalid) return invalid;
|
|
30598
|
+
}
|
|
30436
30599
|
if (change.kind === "attribute") {
|
|
30437
30600
|
if (!ATTRIBUTE_NAME.test(change.name)) return refuse$2("invalid-edit", `${change.name} is not an attribute name`);
|
|
30438
30601
|
if (change.name.toLowerCase() === "style") return refuse$2("invalid-edit", "style is edited one declaration at a time, as a style edit");
|
|
@@ -30459,10 +30622,16 @@ function write(source, element, change) {
|
|
|
30459
30622
|
const written = setText(source, element, change.value);
|
|
30460
30623
|
return written.ok ? written : refuse$2("not-text-only", written.detail);
|
|
30461
30624
|
}
|
|
30462
|
-
if (change.kind === "attribute")
|
|
30463
|
-
|
|
30464
|
-
|
|
30465
|
-
|
|
30625
|
+
if (change.kind === "attribute") {
|
|
30626
|
+
if ("remove" in change) return {
|
|
30627
|
+
ok: true,
|
|
30628
|
+
html: removeAttribute(source, element, change.name)
|
|
30629
|
+
};
|
|
30630
|
+
return {
|
|
30631
|
+
ok: true,
|
|
30632
|
+
html: setRawAttribute(source, element, change.name, escapeAttribute$1(change.value))
|
|
30633
|
+
};
|
|
30634
|
+
}
|
|
30466
30635
|
const declarations = change.kind === "styles" ? change.declarations : [change];
|
|
30467
30636
|
let style = rawAttribute(source, element, "style") ?? "";
|
|
30468
30637
|
for (const { property, value } of declarations) {
|
|
@@ -30510,7 +30679,10 @@ function textOf$1(element) {
|
|
|
30510
30679
|
/** Whether the target holds the value the change asked for. */
|
|
30511
30680
|
function holdsValue(element, change) {
|
|
30512
30681
|
if (change.kind === "text") return textOf$1(element) === change.value;
|
|
30513
|
-
if (change.kind === "attribute")
|
|
30682
|
+
if (change.kind === "attribute") {
|
|
30683
|
+
const stated = element.attrs.find((attribute) => isNamed(attribute, change.name));
|
|
30684
|
+
return "remove" in change ? stated === void 0 : stated?.value === change.value;
|
|
30685
|
+
}
|
|
30514
30686
|
const style = element.attrs.find((attribute) => attribute.name === "style")?.value ?? "";
|
|
30515
30687
|
return (change.kind === "styles" ? change.declarations : [change]).every(({ property, value }) => {
|
|
30516
30688
|
const declared = declaredValues(style, property);
|
|
@@ -35990,9 +36162,12 @@ const FACES = [
|
|
|
35990
36162
|
];
|
|
35991
36163
|
/** Where the server serves the faces folder. */
|
|
35992
36164
|
const FACES_URL = "/frameboard/faces";
|
|
35993
|
-
/**
|
|
36165
|
+
/**
|
|
36166
|
+
* The sheet a frame imports to get one face, under the running release so
|
|
36167
|
+
* the server can answer it as cached for good.
|
|
36168
|
+
*/
|
|
35994
36169
|
function faceSheetUrl(face) {
|
|
35995
|
-
return `${FACES_URL}/${face.folder}/index.css`;
|
|
36170
|
+
return `${FACES_URL}/v${version}/${face.folder}/index.css`;
|
|
35996
36171
|
}
|
|
35997
36172
|
/** The stack naming a face then its fallback, as `'Geist Mono', monospace`. */
|
|
35998
36173
|
function faceStack(face) {
|
|
@@ -36132,8 +36307,13 @@ function elementMarkup(element, paint, font) {
|
|
|
36132
36307
|
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
36308
|
case "asset": {
|
|
36134
36309
|
const name = attribute(element.path.split("/").at(-1) ?? element.path);
|
|
36310
|
+
const src = assetLink(element.path);
|
|
36311
|
+
if (element.tag === "audio") {
|
|
36312
|
+
if (!Number.isInteger(element.width)) throw new Error(`Unexpected audio width ${element.width}`);
|
|
36313
|
+
return `<audio data-name="${name}" src="${src}" controls style="width: ${element.width}px"></audio>`;
|
|
36314
|
+
}
|
|
36135
36315
|
const style = `${size(element)}; object-fit: cover`;
|
|
36136
|
-
return element.video ? `<video data-name="${name}" src="${
|
|
36316
|
+
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
36317
|
}
|
|
36138
36318
|
}
|
|
36139
36319
|
}
|
|
@@ -38873,17 +39053,22 @@ const side = int$1().min(1).max(1e4);
|
|
|
38873
39053
|
const offset = number().min(-1e5).max(1e5);
|
|
38874
39054
|
/** How many elements one batch names, well past any selection a hand makes. */
|
|
38875
39055
|
const BATCH = 1024;
|
|
38876
|
-
const changeSchema =
|
|
39056
|
+
const changeSchema = union([
|
|
38877
39057
|
object$1({
|
|
38878
39058
|
kind: literal("style"),
|
|
38879
39059
|
property: name$1,
|
|
38880
39060
|
value
|
|
38881
39061
|
}),
|
|
38882
|
-
|
|
39062
|
+
strictObject({
|
|
38883
39063
|
kind: literal("attribute"),
|
|
38884
39064
|
name: name$1,
|
|
38885
39065
|
value
|
|
38886
39066
|
}),
|
|
39067
|
+
strictObject({
|
|
39068
|
+
kind: literal("attribute"),
|
|
39069
|
+
name: name$1,
|
|
39070
|
+
remove: literal(true)
|
|
39071
|
+
}),
|
|
38887
39072
|
object$1({
|
|
38888
39073
|
kind: literal("text"),
|
|
38889
39074
|
value
|
|
@@ -39027,7 +39212,8 @@ const recolorSchema = object$1({
|
|
|
39027
39212
|
* An asset names a file under the project's `assets/` and the size it
|
|
39028
39213
|
* shows at, and the server picks its tag from the file's kind. A file
|
|
39029
39214
|
* outside that folder or not there answers 409 `asset-missing`, and one that
|
|
39030
|
-
* is no image, GIF, SVG, or
|
|
39215
|
+
* is no image, GIF, SVG, video, or audio `asset-not-placeable`, each writing
|
|
39216
|
+
* nothing.
|
|
39031
39217
|
*
|
|
39032
39218
|
* The remove takes out the element at `index`, with what it holds, from the
|
|
39033
39219
|
* bytes `hash` names, and records it as one step whose undo puts it back
|
|
@@ -39172,7 +39358,7 @@ function editRoutes(root, access, history, version, sheets) {
|
|
|
39172
39358
|
}, 409);
|
|
39173
39359
|
element = {
|
|
39174
39360
|
...body.element,
|
|
39175
|
-
|
|
39361
|
+
tag: asset.kind === "video" || asset.kind === "audio" ? asset.kind : "img"
|
|
39176
39362
|
};
|
|
39177
39363
|
}
|
|
39178
39364
|
const { at } = body;
|
|
@@ -39954,8 +40140,12 @@ const CONTENT_TYPES$1 = {
|
|
|
39954
40140
|
".otf": "font/otf",
|
|
39955
40141
|
".mp4": "video/mp4",
|
|
39956
40142
|
".webm": "video/webm",
|
|
40143
|
+
".mov": "video/quicktime",
|
|
40144
|
+
".m4v": "video/x-m4v",
|
|
39957
40145
|
".mp3": "audio/mpeg",
|
|
39958
|
-
".wav": "audio/wav"
|
|
40146
|
+
".wav": "audio/wav",
|
|
40147
|
+
".ogg": "audio/ogg",
|
|
40148
|
+
".m4a": "audio/mp4"
|
|
39959
40149
|
};
|
|
39960
40150
|
/**
|
|
39961
40151
|
* Serves `/frames/<project>/<page>/<file>` and `/frames/<project>/assets/<path>`
|
|
@@ -40093,6 +40283,10 @@ function isRecord$1(name) {
|
|
|
40093
40283
|
return name === "layout.json" || name === NOTES_FILE$1;
|
|
40094
40284
|
}
|
|
40095
40285
|
// src/server/routes/look.ts
|
|
40286
|
+
/** The answer for faces under the running release, whose bytes a release fixes. */
|
|
40287
|
+
const IMMUTABLE = "public, max-age=31536000, immutable";
|
|
40288
|
+
/** A release segment as `faceSheetUrl` writes one, such as `v0.29.0`. */
|
|
40289
|
+
const RELEASE_SEGMENT = /^v\d+\.\d+\.\d+/;
|
|
40096
40290
|
const CONTENT_TYPES = {
|
|
40097
40291
|
".css": "text/css; charset=utf-8",
|
|
40098
40292
|
".woff2": "font/woff2"
|
|
@@ -40120,8 +40314,13 @@ function servedFrames(root, { facesDir, tokens, version }) {
|
|
|
40120
40314
|
/**
|
|
40121
40315
|
* Serves what every frame imports from outside the board: the faces under
|
|
40122
40316
|
* `/frameboard/faces/*` and the board sheet at `/frameboard/tokens.css`.
|
|
40123
|
-
*
|
|
40124
|
-
*
|
|
40317
|
+
* The board sheet is never cached, so a changed sheet reaches a frame on its
|
|
40318
|
+
* reload. The faces under the running release's segment, as
|
|
40319
|
+
* `/frameboard/faces/v0.29.0/geist/index.css`, are cached for good, since
|
|
40320
|
+
* only a release changes them, and any other release segment answers 404 so
|
|
40321
|
+
* a stale URL never caches today's bytes. The bare faces path stays
|
|
40322
|
+
* uncached for anything naming it. A dot-named or escaping path answers 404,
|
|
40323
|
+
* as the frame route does.
|
|
40125
40324
|
*/
|
|
40126
40325
|
function lookRoutes({ facesDir, boardSheet }) {
|
|
40127
40326
|
const app = new Hono();
|
|
@@ -40135,13 +40334,16 @@ function lookRoutes({ facesDir, boardSheet }) {
|
|
|
40135
40334
|
});
|
|
40136
40335
|
});
|
|
40137
40336
|
app.get(`${FACES_URL}/*`, async (c) => {
|
|
40138
|
-
const
|
|
40337
|
+
const segments = new URL(c.req.url).pathname.slice(18).split("/");
|
|
40338
|
+
const release = RELEASE_SEGMENT.test(segments[0] ?? "");
|
|
40339
|
+
if (release && segments[0] !== `v${version}`) return c.notFound();
|
|
40340
|
+
const file = await resolveFace(facesDir, release ? segments.slice(1) : segments);
|
|
40139
40341
|
const type = file && CONTENT_TYPES[extname(file)];
|
|
40140
40342
|
const bytes = type ? await readOrNull(file) : null;
|
|
40141
40343
|
if (!type || !bytes) return c.notFound();
|
|
40142
40344
|
return c.body(bytes, 200, {
|
|
40143
40345
|
"Content-Type": type,
|
|
40144
|
-
"Cache-Control": "no-store"
|
|
40346
|
+
"Cache-Control": release ? IMMUTABLE : "no-store"
|
|
40145
40347
|
});
|
|
40146
40348
|
});
|
|
40147
40349
|
return app;
|
|
@@ -40547,6 +40749,7 @@ const STATUS = {
|
|
|
40547
40749
|
"page-not-found": 404,
|
|
40548
40750
|
"frame-not-found": 404,
|
|
40549
40751
|
"font-missing": 422,
|
|
40752
|
+
"image-missing": 422,
|
|
40550
40753
|
"capture-too-large": 422,
|
|
40551
40754
|
"browser-not-found": 503
|
|
40552
40755
|
};
|
|
@@ -41015,6 +41218,11 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
41015
41218
|
}, (results) => onFrames(touched(results)));
|
|
41016
41219
|
app.post("/api/frame/add", async (c) => {
|
|
41017
41220
|
const body = await parseBody$1(c.req.raw, frameAddSchema);
|
|
41221
|
+
const target = await resolveFrameRef(root, body.ref, {
|
|
41222
|
+
cwd,
|
|
41223
|
+
allowMissing: true
|
|
41224
|
+
});
|
|
41225
|
+
await refuseHeld([`${target.project}/${target.page}/${target.name}`]);
|
|
41018
41226
|
const frame = await recorded((journal) => addFrame(root, body.ref, {
|
|
41019
41227
|
...body,
|
|
41020
41228
|
cwd,
|
|
@@ -41040,7 +41248,7 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
41040
41248
|
app.post("/api/frame/rename", async (c) => {
|
|
41041
41249
|
const body = await parseBody$1(c.req.raw, renameSchema);
|
|
41042
41250
|
const source = await readFrame$1(root, body.ref, { cwd });
|
|
41043
|
-
await refuseHeld([source.ref]);
|
|
41251
|
+
await refuseHeld([source.ref, `${source.project}/${source.page}/${body.name}`]);
|
|
41044
41252
|
const frame = await recorded((journal) => renameFrame(root, body.ref, body.name, {
|
|
41045
41253
|
cwd,
|
|
41046
41254
|
journal
|
|
@@ -41523,6 +41731,7 @@ function createApp({ clientDir, root, port, actions, tickets, openRoute, renderF
|
|
|
41523
41731
|
app.route("/", assetsRoutes(root, actions.access, { usage: assetUsage }));
|
|
41524
41732
|
app.route("/", elementsRoutes(root, actions.access, selection, given));
|
|
41525
41733
|
app.route("/", findRoutes(root));
|
|
41734
|
+
app.route("/", claimsRoutes(root, actions.access));
|
|
41526
41735
|
app.route("/", tokenRoutes(root, actions.access, history, frames.look));
|
|
41527
41736
|
app.route("/", editRoutes(root, actions.access, history, settledVersion, frames.look.sheets));
|
|
41528
41737
|
app.route("/", pngRoutes(root, renderFrame));
|
|
@@ -41628,6 +41837,38 @@ async function withFrameHost(board, purpose, run) {
|
|
|
41628
41837
|
await host.close();
|
|
41629
41838
|
}
|
|
41630
41839
|
}
|
|
41840
|
+
// src/server/capture/animation-settle.ts
|
|
41841
|
+
/**
|
|
41842
|
+
* Waits, within `timeoutMs`, until every running animation and transition
|
|
41843
|
+
* with a finite end has finished, reading again after each round so one that
|
|
41844
|
+
* another starts is awaited too. An infinite animation is never awaited, and
|
|
41845
|
+
* running out of time returns rather than refusing, since a long or
|
|
41846
|
+
* restarting animation is a design and not a failure.
|
|
41847
|
+
*
|
|
41848
|
+
* It sees only what `document.getAnimations()` lists, so a scene a script
|
|
41849
|
+
* steps on a timer stays out of reach.
|
|
41850
|
+
*/
|
|
41851
|
+
async function settleAnimations(page, timeoutMs) {
|
|
41852
|
+
if (timeoutMs <= 0) return;
|
|
41853
|
+
await page.evaluate(waitForAnimations, timeoutMs);
|
|
41854
|
+
}
|
|
41855
|
+
async function waitForAnimations(timeoutMs) {
|
|
41856
|
+
const end = performance.now() + timeoutMs;
|
|
41857
|
+
const nextFrame = () => new Promise((done) => requestAnimationFrame(() => done()));
|
|
41858
|
+
const finiteRunning = () => document.getAnimations().filter((animation) => {
|
|
41859
|
+
if (animation.playState !== "running") return false;
|
|
41860
|
+
const endTime = animation.effect?.getComputedTiming().endTime;
|
|
41861
|
+
return typeof endTime === "number" && Number.isFinite(endTime);
|
|
41862
|
+
});
|
|
41863
|
+
await nextFrame();
|
|
41864
|
+
for (;;) {
|
|
41865
|
+
const running = finiteRunning();
|
|
41866
|
+
const left = end - performance.now();
|
|
41867
|
+
if (running.length === 0 || left <= 0) return;
|
|
41868
|
+
await Promise.race([Promise.all(running.map((animation) => animation.finished.catch(() => {}))), new Promise((done) => setTimeout(done, left))]);
|
|
41869
|
+
await nextFrame();
|
|
41870
|
+
}
|
|
41871
|
+
}
|
|
41631
41872
|
// src/server/capture/fonts.ts
|
|
41632
41873
|
/**
|
|
41633
41874
|
* Families the browser maps to a face itself, so no frame has to supply one.
|
|
@@ -41777,18 +42018,94 @@ async function platformFamilies(page, domIndexes) {
|
|
|
41777
42018
|
await session.detach();
|
|
41778
42019
|
}
|
|
41779
42020
|
}
|
|
42021
|
+
// src/server/capture/image-loads.ts
|
|
42022
|
+
/**
|
|
42023
|
+
* Waits, within `timeoutMs`, until every `<img>` in the frame has loaded and
|
|
42024
|
+
* decoded, so an image marked `decoding="async"` never shoots as an empty
|
|
42025
|
+
* box. A lazy image is made eager in the loaded page first, never in the
|
|
42026
|
+
* file, so one below the box loads too.
|
|
42027
|
+
*
|
|
42028
|
+
* Under `require` an image that errored or is still loading when the time
|
|
42029
|
+
* runs out refuses `image-missing`. Under `wait` the frame opens with it as
|
|
42030
|
+
* the board shows it.
|
|
42031
|
+
*
|
|
42032
|
+
* `stalled` reads a page whose load event never fired, refusing only for an
|
|
42033
|
+
* image that failed or whose request is still open. A loaded image still
|
|
42034
|
+
* decoding cannot have held the load, so something else, such as a
|
|
42035
|
+
* stylesheet or an iframe, did.
|
|
42036
|
+
*/
|
|
42037
|
+
async function settleImages(page, ref, mode, timeoutMs, { stalled = false } = {}) {
|
|
42038
|
+
const unsettled = await page.evaluate(waitForImages, Math.max(0, timeoutMs));
|
|
42039
|
+
const [first] = stalled ? unsettled.filter((image) => image.heldLoad || image.state === "error") : unsettled;
|
|
42040
|
+
if (mode === "wait" || first === void 0) return;
|
|
42041
|
+
const why = first.state === "error" ? "failed to load" : "was still loading when the frame's load budget ran out";
|
|
42042
|
+
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/.`, {
|
|
42043
|
+
ref,
|
|
42044
|
+
src: first.src,
|
|
42045
|
+
element: first.index
|
|
42046
|
+
});
|
|
42047
|
+
}
|
|
42048
|
+
async function waitForImages(timeoutMs) {
|
|
42049
|
+
const images = [];
|
|
42050
|
+
let index = 0;
|
|
42051
|
+
for (const element of document.querySelectorAll("*")) {
|
|
42052
|
+
if (element.closest("[data-frameboard]")) continue;
|
|
42053
|
+
const own = index;
|
|
42054
|
+
index += 1;
|
|
42055
|
+
if (!(element instanceof HTMLImageElement)) continue;
|
|
42056
|
+
if (!element.getAttribute("src") && !element.getAttribute("srcset")) continue;
|
|
42057
|
+
const lazy = element.loading === "lazy";
|
|
42058
|
+
if (lazy) element.loading = "eager";
|
|
42059
|
+
images.push({
|
|
42060
|
+
index: own,
|
|
42061
|
+
img: element,
|
|
42062
|
+
lazy
|
|
42063
|
+
});
|
|
42064
|
+
}
|
|
42065
|
+
if (images.length === 0) return [];
|
|
42066
|
+
const settle = async (img) => {
|
|
42067
|
+
if (!img.complete) await new Promise((done) => {
|
|
42068
|
+
img.addEventListener("load", done, { once: true });
|
|
42069
|
+
img.addEventListener("error", done, { once: true });
|
|
42070
|
+
});
|
|
42071
|
+
return img.decode().then(() => "ok", () => "error");
|
|
42072
|
+
};
|
|
42073
|
+
const outcomes = images.map(({ img }) => ({
|
|
42074
|
+
state: "pending",
|
|
42075
|
+
done: settle(img)
|
|
42076
|
+
}));
|
|
42077
|
+
for (const outcome of outcomes) outcome.done.then((state) => {
|
|
42078
|
+
outcome.state = state;
|
|
42079
|
+
});
|
|
42080
|
+
await Promise.race([Promise.all(outcomes.map((outcome) => outcome.done)), new Promise((done) => setTimeout(done, timeoutMs))]);
|
|
42081
|
+
const unsettled = [];
|
|
42082
|
+
images.forEach(({ index: own, img, lazy }, at) => {
|
|
42083
|
+
const state = outcomes[at]?.state;
|
|
42084
|
+
if (state === void 0 || state === "ok") return;
|
|
42085
|
+
unsettled.push({
|
|
42086
|
+
index: own,
|
|
42087
|
+
src: img.getAttribute("src") || img.currentSrc,
|
|
42088
|
+
state,
|
|
42089
|
+
heldLoad: !lazy && !img.complete
|
|
42090
|
+
});
|
|
42091
|
+
});
|
|
42092
|
+
return unsettled;
|
|
42093
|
+
}
|
|
41780
42094
|
// src/server/capture/render.ts
|
|
41781
|
-
/** How long a frame has to load before its capture fails. */
|
|
42095
|
+
/** How long a frame has to load, its faces and images included, before its capture fails. */
|
|
41782
42096
|
const LOAD_TIMEOUT_MS = 1e4;
|
|
41783
42097
|
/** Chromium's screenshot surface stops at this many pixels on either side. */
|
|
41784
42098
|
const MAX_COMPOSITE_SIDE = 16384;
|
|
41785
42099
|
/**
|
|
41786
42100
|
* 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
|
-
|
|
42101
|
+
* asked for, and resolves once it has loaded, its faces have settled, and its
|
|
42102
|
+
* images have decoded, all inside one load budget. Under `fonts: 'require'`,
|
|
42103
|
+
* the default, a missing face refuses `font-missing`, an image that failed or
|
|
42104
|
+
* outran the budget refuses `image-missing`, and either closes the context.
|
|
42105
|
+
* It then waits, on what is left of the budget, for running animations with
|
|
42106
|
+
* a finite end to finish, and never refuses for one.
|
|
42107
|
+
*/
|
|
42108
|
+
async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts = "require", timeoutMs = LOAD_TIMEOUT_MS }) {
|
|
41792
42109
|
const context = await browser.newContext({
|
|
41793
42110
|
viewport: {
|
|
41794
42111
|
width: box.width,
|
|
@@ -41798,11 +42115,22 @@ async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts =
|
|
|
41798
42115
|
colorScheme: theme
|
|
41799
42116
|
});
|
|
41800
42117
|
const close = () => context.close();
|
|
42118
|
+
const deadline = Date.now() + timeoutMs;
|
|
41801
42119
|
try {
|
|
41802
42120
|
const page = await context.newPage();
|
|
41803
|
-
await page.goto(new URL(frameThemeUrl(ref, theme), baseUrl).href, {
|
|
42121
|
+
await page.goto(new URL(frameThemeUrl(ref, theme), baseUrl).href, {
|
|
42122
|
+
timeout: timeoutMs,
|
|
42123
|
+
waitUntil: "domcontentloaded"
|
|
42124
|
+
});
|
|
42125
|
+
const stalled = await page.waitForLoadState("load", { timeout: deadline - Date.now() }).then(() => null, (error) => error);
|
|
42126
|
+
if (stalled !== null) {
|
|
42127
|
+
await settleImages(page, ref, fonts, 0, { stalled: true });
|
|
42128
|
+
throw stalled;
|
|
42129
|
+
}
|
|
41804
42130
|
await page.evaluate(() => document.fonts.ready.then(() => void 0));
|
|
41805
42131
|
if (fonts === "require") await assertFontsPresent(page, ref);
|
|
42132
|
+
await settleImages(page, ref, fonts, deadline - Date.now());
|
|
42133
|
+
if (fonts === "require") await settleAnimations(page, deadline - Date.now());
|
|
41806
42134
|
return {
|
|
41807
42135
|
page,
|
|
41808
42136
|
close
|
|
@@ -42108,7 +42436,7 @@ const CUSTOM_PROPERTY_RULES = [{
|
|
|
42108
42436
|
severity: "warning",
|
|
42109
42437
|
description: "A var() with no fallback names a custom property no token sheet, frame sheet, style attribute, or script write declares"
|
|
42110
42438
|
}];
|
|
42111
|
-
const finding$
|
|
42439
|
+
const finding$9 = findingFor(CUSTOM_PROPERTY_RULES);
|
|
42112
42440
|
/** A `var()` naming its property, with no fallback after a comma. */
|
|
42113
42441
|
const BARE_VAR = /var\(\s*(--[\w-]+)\s*\)/g;
|
|
42114
42442
|
/**
|
|
@@ -42167,7 +42495,7 @@ function checkUnknownTokens(source, tokens) {
|
|
|
42167
42495
|
if (element.name !== "script") continue;
|
|
42168
42496
|
for (const name of scriptWrites(scriptText(element, source))) declared.add(name);
|
|
42169
42497
|
}
|
|
42170
|
-
return uses.filter((use) => !declared.has(use.name)).map((use) => finding$
|
|
42498
|
+
return uses.filter((use) => !declared.has(use.name)).map((use) => finding$9("unknown-token", {
|
|
42171
42499
|
frame: source.ref,
|
|
42172
42500
|
path: use.path,
|
|
42173
42501
|
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 +42569,7 @@ const FONT_RULES = [
|
|
|
42241
42569
|
description: "Every text element's first family is one of the project's allowed fonts"
|
|
42242
42570
|
}
|
|
42243
42571
|
];
|
|
42244
|
-
const finding$
|
|
42572
|
+
const finding$8 = findingFor(FONT_RULES);
|
|
42245
42573
|
const GENERIC_FAMILIES = /* @__PURE__ */ new Set([
|
|
42246
42574
|
"serif",
|
|
42247
42575
|
"sans-serif",
|
|
@@ -42284,7 +42612,7 @@ function checkFonts(source, cascade, config) {
|
|
|
42284
42612
|
else if (allowed && !allowed.includes(family.toLowerCase())) push(unlisted, family, element);
|
|
42285
42613
|
}
|
|
42286
42614
|
const path = boardPath(source.root, source.path);
|
|
42287
|
-
const at = (rule, elements, message) => finding$
|
|
42615
|
+
const at = (rule, elements, message) => finding$8(rule, {
|
|
42288
42616
|
frame: source.ref,
|
|
42289
42617
|
path,
|
|
42290
42618
|
message: `${message} ${described(elements)}`,
|
|
@@ -42334,7 +42662,7 @@ const LINK_RULES = [
|
|
|
42334
42662
|
description: "Every local file a frame loads exists"
|
|
42335
42663
|
}
|
|
42336
42664
|
];
|
|
42337
|
-
const finding$
|
|
42665
|
+
const finding$7 = findingFor(LINK_RULES);
|
|
42338
42666
|
/**
|
|
42339
42667
|
* The attributes that load a resource, by element. An `a href` navigates
|
|
42340
42668
|
* rather than loads, so it is left out.
|
|
@@ -42410,16 +42738,16 @@ function judge(source, load) {
|
|
|
42410
42738
|
path: load.path,
|
|
42411
42739
|
location: load.location
|
|
42412
42740
|
};
|
|
42413
|
-
if (hasScheme(url)) return [finding$
|
|
42741
|
+
if (hasScheme(url)) return [finding$7("network", {
|
|
42414
42742
|
...fields,
|
|
42415
42743
|
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
42744
|
})];
|
|
42417
42745
|
const target = localTarget(url, load.base);
|
|
42418
|
-
if (target === null || !allowed(source, target)) return [finding$
|
|
42746
|
+
if (target === null || !allowed(source, target)) return [finding$7("outside-link", {
|
|
42419
42747
|
...fields,
|
|
42420
42748
|
message: `${load.via} loads ${url}, outside this page's folder and the project's assets/. Move the file into one of them.`
|
|
42421
42749
|
})];
|
|
42422
|
-
if (!existsSync(target)) return [finding$
|
|
42750
|
+
if (!existsSync(target)) return [finding$7("missing-file", {
|
|
42423
42751
|
...fields,
|
|
42424
42752
|
message: `${load.via} loads ${url}, which does not exist.`
|
|
42425
42753
|
})];
|
|
@@ -42508,7 +42836,7 @@ const STRUCTURE_RULES = [
|
|
|
42508
42836
|
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
42837
|
}
|
|
42510
42838
|
];
|
|
42511
|
-
const finding$
|
|
42839
|
+
const finding$6 = findingFor(STRUCTURE_RULES);
|
|
42512
42840
|
/**
|
|
42513
42841
|
* Elements a parser may imply with no start tag in a valid file. A `tbody`
|
|
42514
42842
|
* is `table-tbody`'s to report.
|
|
@@ -42571,12 +42899,12 @@ const MALFORMED = {
|
|
|
42571
42899
|
function checkNaming(target, path) {
|
|
42572
42900
|
const ref = `${target.project}/${target.page}/${target.name}`;
|
|
42573
42901
|
const findings = [];
|
|
42574
|
-
if (!isValidName(target.page) || isReservedPageName(target.page)) findings.push(finding$
|
|
42902
|
+
if (!isValidName(target.page) || isReservedPageName(target.page)) findings.push(finding$6("naming", {
|
|
42575
42903
|
frame: ref,
|
|
42576
42904
|
path,
|
|
42577
42905
|
message: `Page name ${target.page} is not valid. Use letters, digits, dots, dashes, and underscores, opening with a letter or digit.`
|
|
42578
42906
|
}));
|
|
42579
|
-
if (!isValidName(target.name)) findings.push(finding$
|
|
42907
|
+
if (!isValidName(target.name)) findings.push(finding$6("naming", {
|
|
42580
42908
|
frame: ref,
|
|
42581
42909
|
path,
|
|
42582
42910
|
message: `Frame name ${target.name} is not valid. Use letters, digits, dots, dashes, and underscores, opening with a letter or digit.`
|
|
@@ -42585,7 +42913,7 @@ function checkNaming(target, path) {
|
|
|
42585
42913
|
}
|
|
42586
42914
|
/** `dot-folder`, over a project's folder names. */
|
|
42587
42915
|
function checkDotFolders(root, projectDir, folders) {
|
|
42588
|
-
return folders.filter((name) => name.startsWith(".")).map((name) => finding$
|
|
42916
|
+
return folders.filter((name) => name.startsWith(".")).map((name) => finding$6("dot-folder", {
|
|
42589
42917
|
frame: null,
|
|
42590
42918
|
path: boardPath(root, `${projectDir}/${name}`),
|
|
42591
42919
|
message: `Folder ${name} opens with a dot, so the board never shows it. Rename it or move it out of the project.`
|
|
@@ -42597,13 +42925,13 @@ function checkMarkup(source) {
|
|
|
42597
42925
|
const findings = [];
|
|
42598
42926
|
const head = source.elements.find((element) => element.name === "head");
|
|
42599
42927
|
const body = source.elements.find((element) => element.name === "body");
|
|
42600
|
-
if (head && startTagLocation(head) && !(body && startTagLocation(body))) findings.push(finding$
|
|
42928
|
+
if (head && startTagLocation(head) && !(body && startTagLocation(body))) findings.push(finding$6("head-body", {
|
|
42601
42929
|
frame: source.ref,
|
|
42602
42930
|
path,
|
|
42603
42931
|
message: "The frame states <head> and no <body>. Wrap the visible content in <body>.",
|
|
42604
42932
|
location: startTagLocation(head)
|
|
42605
42933
|
}));
|
|
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$
|
|
42934
|
+
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$6("table-tbody", {
|
|
42607
42935
|
frame: source.ref,
|
|
42608
42936
|
path,
|
|
42609
42937
|
message: "This table holds rows with no <tbody>, so the browser adds one the file does not hold. State the <tbody>.",
|
|
@@ -42630,7 +42958,7 @@ function checkMalformedTags(source) {
|
|
|
42630
42958
|
if (reported.has(tag)) continue;
|
|
42631
42959
|
reported.add(tag);
|
|
42632
42960
|
}
|
|
42633
|
-
findings.push(finding$
|
|
42961
|
+
findings.push(finding$6("malformed-tag", {
|
|
42634
42962
|
frame: source.ref,
|
|
42635
42963
|
path,
|
|
42636
42964
|
message: `${tag ? `<${tag.name}> raises ${error.code}` : error.code}. ${message}`,
|
|
@@ -42648,7 +42976,7 @@ function checkMalformedTags(source) {
|
|
|
42648
42976
|
function checkNesting(source) {
|
|
42649
42977
|
const path = boardPath(source.root, source.path);
|
|
42650
42978
|
const findings = [];
|
|
42651
|
-
const report = (message, location) => findings.push(finding$
|
|
42979
|
+
const report = (message, location) => findings.push(finding$6("nesting", {
|
|
42652
42980
|
frame: source.ref,
|
|
42653
42981
|
path,
|
|
42654
42982
|
message,
|
|
@@ -42711,14 +43039,14 @@ const UPPERCASE_RULES = [{
|
|
|
42711
43039
|
configKey: "noUppercase",
|
|
42712
43040
|
description: "No text is set in capitals, through text-transform: uppercase or a word of more than three capital letters"
|
|
42713
43041
|
}];
|
|
42714
|
-
const finding$
|
|
43042
|
+
const finding$5 = findingFor(UPPERCASE_RULES);
|
|
42715
43043
|
const CAPITALS = /(?<![\p{L}\p{N}])\p{Lu}{4,}(?![\p{L}\p{N}])/u;
|
|
42716
43044
|
/** `uppercase`, which runs only when the project sets `noUppercase`. */
|
|
42717
43045
|
function checkUppercase(source, cascade) {
|
|
42718
43046
|
const capitalized = textElements(source).filter((element) => cascade.textTransform(element) === "uppercase" || ownText(element).some((text) => CAPITALS.test(text)));
|
|
42719
43047
|
const first = capitalized[0];
|
|
42720
43048
|
if (!first) return [];
|
|
42721
|
-
return [finding$
|
|
43049
|
+
return [finding$5("uppercase", {
|
|
42722
43050
|
frame: source.ref,
|
|
42723
43051
|
path: boardPath(source.root, source.path),
|
|
42724
43052
|
message: `Text is set in capitals, which the project does not allow. Write it in sentence case. ${described(capitalized)}`,
|
|
@@ -42770,7 +43098,7 @@ function readProjectContext(root, project, boardSheet) {
|
|
|
42770
43098
|
* The project's `checks` config, read by hand rather than through the
|
|
42771
43099
|
* project record's schema, which the hook cannot afford to load. A file that
|
|
42772
43100
|
* 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`.
|
|
43101
|
+
* server's browser checker reads it too, for `minFontSize` and `minContrast`.
|
|
42774
43102
|
*/
|
|
42775
43103
|
function readConfig(root, project) {
|
|
42776
43104
|
let parsed;
|
|
@@ -42785,11 +43113,204 @@ function readConfig(root, project) {
|
|
|
42785
43113
|
if (Array.isArray(checks.allowedFonts) && checks.allowedFonts.every((font) => typeof font === "string")) config.allowedFonts = checks.allowedFonts;
|
|
42786
43114
|
if (typeof checks.noUppercase === "boolean") config.noUppercase = checks.noUppercase;
|
|
42787
43115
|
if (typeof checks.minFontSize === "number" && checks.minFontSize > 0) config.minFontSize = checks.minFontSize;
|
|
43116
|
+
if (typeof checks.minContrast === "number" && checks.minContrast >= 1) config.minContrast = checks.minContrast;
|
|
42788
43117
|
return config;
|
|
42789
43118
|
}
|
|
42790
43119
|
function isRecord(value) {
|
|
42791
43120
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
42792
43121
|
}
|
|
43122
|
+
// src/server/checks/browser/contrast.ts
|
|
43123
|
+
const CONTRAST_RULES = [{
|
|
43124
|
+
id: "min-contrast",
|
|
43125
|
+
tier: "browser",
|
|
43126
|
+
severity: "warning",
|
|
43127
|
+
configKey: "minContrast",
|
|
43128
|
+
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."
|
|
43129
|
+
}];
|
|
43130
|
+
const finding$4 = findingFor(CONTRAST_RULES);
|
|
43131
|
+
/** WCAG's large text is 18 pt, or 14 pt bold, which hold 3:1 against 4.5:1. */
|
|
43132
|
+
const LARGE_SHARE = 2 / 3;
|
|
43133
|
+
/**
|
|
43134
|
+
* Reports text whose contrast with the solid color behind it falls under
|
|
43135
|
+
* `minContrast`, naming the element furthest under and how many more fall
|
|
43136
|
+
* under, at most one finding per frame.
|
|
43137
|
+
*/
|
|
43138
|
+
async function checkContrast(page, target, minContrast) {
|
|
43139
|
+
const under = (await page.evaluate(readContrasts)).map((text) => ({
|
|
43140
|
+
...text,
|
|
43141
|
+
minimum: text.large ? minContrast * LARGE_SHARE : minContrast
|
|
43142
|
+
})).filter((text) => text.ratio < text.minimum);
|
|
43143
|
+
if (under.length === 0) return [];
|
|
43144
|
+
const worst = under.reduce((least, text) => text.ratio / text.minimum < least.ratio / least.minimum ? text : least);
|
|
43145
|
+
const others = under.length - 1;
|
|
43146
|
+
const rest = others === 0 ? "" : `, and ${others} more ${others === 1 ? "element is" : "elements are"} under it`;
|
|
43147
|
+
const minimum = worst.large ? `${formatRatio(worst.minimum)}:1 minimum for large text` : `${formatRatio(worst.minimum)}:1 minimum`;
|
|
43148
|
+
return [finding$4("min-contrast", {
|
|
43149
|
+
frame: target.ref,
|
|
43150
|
+
path: target.path,
|
|
43151
|
+
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}.`
|
|
43152
|
+
})];
|
|
43153
|
+
}
|
|
43154
|
+
/** Floors to two places, so a ratio just under the minimum never prints as it. */
|
|
43155
|
+
function floorRatio(ratio) {
|
|
43156
|
+
return (Math.floor(ratio * 100) / 100).toFixed(2);
|
|
43157
|
+
}
|
|
43158
|
+
function formatRatio(ratio) {
|
|
43159
|
+
return String(Math.round(ratio * 100) / 100);
|
|
43160
|
+
}
|
|
43161
|
+
function readContrasts() {
|
|
43162
|
+
const notText = /* @__PURE__ */ new Set([
|
|
43163
|
+
"HTML",
|
|
43164
|
+
"HEAD",
|
|
43165
|
+
"TITLE",
|
|
43166
|
+
"SCRIPT",
|
|
43167
|
+
"STYLE",
|
|
43168
|
+
"NOSCRIPT",
|
|
43169
|
+
"TEMPLATE"
|
|
43170
|
+
]);
|
|
43171
|
+
const opaqueTags = /* @__PURE__ */ new Set([
|
|
43172
|
+
"IMG",
|
|
43173
|
+
"VIDEO",
|
|
43174
|
+
"CANVAS",
|
|
43175
|
+
"IFRAME",
|
|
43176
|
+
"OBJECT",
|
|
43177
|
+
"EMBED",
|
|
43178
|
+
"PICTURE"
|
|
43179
|
+
]);
|
|
43180
|
+
const candidates = [];
|
|
43181
|
+
let index = 0;
|
|
43182
|
+
for (const element of document.querySelectorAll("*")) {
|
|
43183
|
+
if (element.closest("[data-frameboard]")) continue;
|
|
43184
|
+
const own = index;
|
|
43185
|
+
index += 1;
|
|
43186
|
+
if (notText.has(element.tagName.toUpperCase())) continue;
|
|
43187
|
+
const text = [...element.childNodes].find((node) => node.nodeType === Node.TEXT_NODE && Boolean(node.textContent?.trim()));
|
|
43188
|
+
if (text) candidates.push({
|
|
43189
|
+
element,
|
|
43190
|
+
index: own,
|
|
43191
|
+
text
|
|
43192
|
+
});
|
|
43193
|
+
}
|
|
43194
|
+
const canvas = document.createElement("canvas");
|
|
43195
|
+
canvas.width = 1;
|
|
43196
|
+
canvas.height = 1;
|
|
43197
|
+
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
43198
|
+
if (!context) return [];
|
|
43199
|
+
const toRgba = (color) => {
|
|
43200
|
+
context.clearRect(0, 0, 1, 1);
|
|
43201
|
+
context.fillStyle = "#000";
|
|
43202
|
+
context.fillStyle = color;
|
|
43203
|
+
context.fillRect(0, 0, 1, 1);
|
|
43204
|
+
const [r = 0, g = 0, b = 0, a = 0] = context.getImageData(0, 0, 1, 1).data;
|
|
43205
|
+
const written = /^rgba\(.*,\s*([\d.]+)()\)$/.exec(color) ?? /\/\s*([\d.]+)(%?)\s*\)$/.exec(color);
|
|
43206
|
+
return [
|
|
43207
|
+
r,
|
|
43208
|
+
g,
|
|
43209
|
+
b,
|
|
43210
|
+
written?.[1] ? Number.parseFloat(written[1]) / (written[2] ? 100 : 1) : a / 255
|
|
43211
|
+
];
|
|
43212
|
+
};
|
|
43213
|
+
const over = (top, below) => {
|
|
43214
|
+
const [r, g, b, a] = top;
|
|
43215
|
+
return [
|
|
43216
|
+
r * a + below[0] * (1 - a),
|
|
43217
|
+
g * a + below[1] * (1 - a),
|
|
43218
|
+
b * a + below[2] * (1 - a),
|
|
43219
|
+
1
|
|
43220
|
+
];
|
|
43221
|
+
};
|
|
43222
|
+
const luminance = ([r, g, b]) => {
|
|
43223
|
+
const channel = (value) => {
|
|
43224
|
+
const s = value / 255;
|
|
43225
|
+
return s <= .04045 ? s / 12.92 : ((s + .055) / 1.055) ** 2.4;
|
|
43226
|
+
};
|
|
43227
|
+
return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
|
|
43228
|
+
};
|
|
43229
|
+
const hex = (color) => `#${color.slice(0, 3).map((value) => Math.round(value).toString(16).padStart(2, "0")).join("")}`;
|
|
43230
|
+
const opacityOf = (element) => {
|
|
43231
|
+
let opacity = 1;
|
|
43232
|
+
for (let at = element; at; at = at.parentElement) opacity *= Number.parseFloat(getComputedStyle(at).opacity);
|
|
43233
|
+
return opacity;
|
|
43234
|
+
};
|
|
43235
|
+
const paintsEffect = (style) => style.backgroundImage !== "none" || style.filter !== "none" || style.backdropFilter !== "none" || style.mixBlendMode !== "normal";
|
|
43236
|
+
const probe = document.createElement("div");
|
|
43237
|
+
probe.style.backgroundColor = "Canvas";
|
|
43238
|
+
document.documentElement.append(probe);
|
|
43239
|
+
const canvasColor = toRgba(getComputedStyle(probe).backgroundColor);
|
|
43240
|
+
probe.remove();
|
|
43241
|
+
const html = document.documentElement;
|
|
43242
|
+
const htmlStyle = getComputedStyle(html);
|
|
43243
|
+
const body = document.body;
|
|
43244
|
+
const bodyStyle = body ? getComputedStyle(body) : null;
|
|
43245
|
+
const bodyPropagates = toRgba(htmlStyle.backgroundColor)[3] === 0 && htmlStyle.backgroundImage === "none";
|
|
43246
|
+
const rootStyle = bodyPropagates && bodyStyle ? bodyStyle : htmlStyle;
|
|
43247
|
+
const rootUnmeasurable = paintsEffect(rootStyle);
|
|
43248
|
+
const root = over(toRgba(rootStyle.backgroundColor), canvasColor);
|
|
43249
|
+
const running = document.getAnimations().filter((animation) => animation.playState === "running").flatMap((animation) => {
|
|
43250
|
+
const effect = animation.effect;
|
|
43251
|
+
return effect instanceof KeyframeEffect && effect.target ? [effect.target] : [];
|
|
43252
|
+
});
|
|
43253
|
+
const hits = document.createElement("style");
|
|
43254
|
+
hits.textContent = "* { pointer-events: auto !important; }";
|
|
43255
|
+
document.head.append(hits);
|
|
43256
|
+
const found = [];
|
|
43257
|
+
try {
|
|
43258
|
+
for (const { element, index: own, text } of candidates) {
|
|
43259
|
+
const style = getComputedStyle(element);
|
|
43260
|
+
if (style.visibility !== "visible") continue;
|
|
43261
|
+
const range = document.createRange();
|
|
43262
|
+
range.selectNodeContents(text);
|
|
43263
|
+
const rect = range.getBoundingClientRect();
|
|
43264
|
+
if (rect.width <= 1 || rect.height <= 1) continue;
|
|
43265
|
+
if (running.some((target) => target.contains(element))) continue;
|
|
43266
|
+
let clipped = false;
|
|
43267
|
+
for (let at = element; at; at = at.parentElement) if (getComputedStyle(at).backgroundClip === "text") clipped = true;
|
|
43268
|
+
if (clipped) continue;
|
|
43269
|
+
const stack = document.elementsFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
|
|
43270
|
+
const from = stack.indexOf(element);
|
|
43271
|
+
if (from === -1) continue;
|
|
43272
|
+
const layers = [];
|
|
43273
|
+
let measurable = true;
|
|
43274
|
+
let opaque = false;
|
|
43275
|
+
for (const layer of stack.slice(from)) {
|
|
43276
|
+
if (layer === html || bodyPropagates && layer === body) continue;
|
|
43277
|
+
const layerStyle = getComputedStyle(layer);
|
|
43278
|
+
if (opaqueTags.has(layer.tagName.toUpperCase()) || layer instanceof SVGElement || paintsEffect(layerStyle)) {
|
|
43279
|
+
measurable = false;
|
|
43280
|
+
break;
|
|
43281
|
+
}
|
|
43282
|
+
const color = toRgba(layerStyle.backgroundColor);
|
|
43283
|
+
color[3] *= opacityOf(layer);
|
|
43284
|
+
if (color[3] === 0) continue;
|
|
43285
|
+
layers.push(color);
|
|
43286
|
+
if (color[3] >= 1) {
|
|
43287
|
+
opaque = true;
|
|
43288
|
+
break;
|
|
43289
|
+
}
|
|
43290
|
+
}
|
|
43291
|
+
if (!measurable || !opaque && rootUnmeasurable) continue;
|
|
43292
|
+
const background = layers.reduceRight((below, layer) => over(layer, below), root);
|
|
43293
|
+
const fill = toRgba(style.webkitTextFillColor || style.color);
|
|
43294
|
+
fill[3] *= opacityOf(element);
|
|
43295
|
+
const foreground = over(fill, background);
|
|
43296
|
+
const lighter = Math.max(luminance(foreground), luminance(background));
|
|
43297
|
+
const darker = Math.min(luminance(foreground), luminance(background));
|
|
43298
|
+
const size = Number.parseFloat(style.fontSize);
|
|
43299
|
+
const weight = Number.parseFloat(style.fontWeight);
|
|
43300
|
+
found.push({
|
|
43301
|
+
index: own,
|
|
43302
|
+
tag: element.tagName.toLowerCase(),
|
|
43303
|
+
ratio: (lighter + .05) / (darker + .05),
|
|
43304
|
+
large: size >= 24 || size >= 18.66 && weight >= 700,
|
|
43305
|
+
foreground: hex(foreground),
|
|
43306
|
+
background: hex(background)
|
|
43307
|
+
});
|
|
43308
|
+
}
|
|
43309
|
+
} finally {
|
|
43310
|
+
hits.remove();
|
|
43311
|
+
}
|
|
43312
|
+
return found;
|
|
43313
|
+
}
|
|
42793
43314
|
// src/server/checks/browser/declarations.ts
|
|
42794
43315
|
const DECLARATION_RULES = [{
|
|
42795
43316
|
id: "dropped-declaration",
|
|
@@ -43547,6 +44068,7 @@ const RULES = [
|
|
|
43547
44068
|
...OUTRANKED_RULES,
|
|
43548
44069
|
...LAYOUT_RULES,
|
|
43549
44070
|
...FONT_SIZE_RULES,
|
|
44071
|
+
...CONTRAST_RULES,
|
|
43550
44072
|
...DECLARATION_RULES
|
|
43551
44073
|
];
|
|
43552
44074
|
/** Checks every frame on one page. */
|
|
@@ -44410,8 +44932,9 @@ function changeOf(options) {
|
|
|
44410
44932
|
if ([
|
|
44411
44933
|
options.style,
|
|
44412
44934
|
options.attr,
|
|
44935
|
+
options.dropAttr,
|
|
44413
44936
|
options.text
|
|
44414
|
-
].filter((value) => value !== void 0).length !== 1) throw new FrameboardError("usage", "Give exactly one of --style, --attr, or --text.");
|
|
44937
|
+
].filter((value) => value !== void 0).length !== 1) throw new FrameboardError("usage", "Give exactly one of --style, --attr, --drop-attr, or --text.");
|
|
44415
44938
|
if (options.style !== void 0) {
|
|
44416
44939
|
const [property, value] = pair("--style", options.style);
|
|
44417
44940
|
return {
|
|
@@ -44428,6 +44951,11 @@ function changeOf(options) {
|
|
|
44428
44951
|
value
|
|
44429
44952
|
};
|
|
44430
44953
|
}
|
|
44954
|
+
if (options.dropAttr !== void 0) return {
|
|
44955
|
+
kind: "attribute",
|
|
44956
|
+
name: options.dropAttr,
|
|
44957
|
+
remove: true
|
|
44958
|
+
};
|
|
44431
44959
|
return {
|
|
44432
44960
|
kind: "text",
|
|
44433
44961
|
value: options.text ?? ""
|
|
@@ -44435,7 +44963,7 @@ function changeOf(options) {
|
|
|
44435
44963
|
}
|
|
44436
44964
|
function registerEdit(program, context) {
|
|
44437
44965
|
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) => {
|
|
44966
|
+
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
44967
|
const change = changeOf(options);
|
|
44440
44968
|
const root = await boardOf(options, io);
|
|
44441
44969
|
const frame = await resolveFrameRef(root, ref, {
|
|
@@ -44484,14 +45012,29 @@ function tagFor(agent, session, cwd) {
|
|
|
44484
45012
|
return folder ? `${agent} · ${folder}` : session.slice(0, 6);
|
|
44485
45013
|
}
|
|
44486
45014
|
// src/cli/commands/editing.ts
|
|
45015
|
+
const ANY_INTEGER$1 = parseInteger(Number.MIN_SAFE_INTEGER);
|
|
44487
45016
|
function registerEditing(program, context) {
|
|
44488
45017
|
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-
|
|
45018
|
+
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
45019
|
const root = await boardOf(options, io);
|
|
44491
45020
|
const now = /* @__PURE__ */ new Date();
|
|
45021
|
+
if (options.new) {
|
|
45022
|
+
const session = sessionOf(options.session);
|
|
45023
|
+
const claims = await reserve(root, {
|
|
45024
|
+
session,
|
|
45025
|
+
agent: options.agent,
|
|
45026
|
+
tag: tagFor(options.agent, session, io.cwd)
|
|
45027
|
+
}, await reservationsOf(root, refs, options, io.cwd, now), now);
|
|
45028
|
+
return {
|
|
45029
|
+
data: { claims },
|
|
45030
|
+
human: `Reserved ${claims.map((each) => each.frame).join(", ")}. Claim any of them again within five minutes to keep the set.`
|
|
45031
|
+
};
|
|
45032
|
+
}
|
|
45033
|
+
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 });
|
|
45034
|
+
const [ref] = refs;
|
|
44492
45035
|
if (options.release) {
|
|
44493
45036
|
const session = sessionOf(options.session);
|
|
44494
|
-
const released = await release$1(root, session, ref ? await
|
|
45037
|
+
const released = await release$1(root, session, ref ? await claimable(root, ref, resolving(options, io.cwd), now) : void 0, now);
|
|
44495
45038
|
return {
|
|
44496
45039
|
data: { released },
|
|
44497
45040
|
human: released.length === 0 ? `${session} held no claim to release` : `Released ${released.map((each) => each.frame).join(", ")}`
|
|
@@ -44499,7 +45042,7 @@ function registerEditing(program, context) {
|
|
|
44499
45042
|
}
|
|
44500
45043
|
if (ref) {
|
|
44501
45044
|
const session = sessionOf(options.session);
|
|
44502
|
-
const frame = await
|
|
45045
|
+
const frame = await claimable(root, ref, resolving(options, io.cwd), now);
|
|
44503
45046
|
const held = await claim(root, {
|
|
44504
45047
|
frame,
|
|
44505
45048
|
session,
|
|
@@ -44518,19 +45061,85 @@ function registerEditing(program, context) {
|
|
|
44518
45061
|
};
|
|
44519
45062
|
});
|
|
44520
45063
|
}
|
|
44521
|
-
|
|
44522
|
-
|
|
44523
|
-
const frame = await resolveFrameRef(root, ref, {
|
|
45064
|
+
function resolving(options, cwd) {
|
|
45065
|
+
return {
|
|
44524
45066
|
project: options.project,
|
|
44525
45067
|
cwd
|
|
45068
|
+
};
|
|
45069
|
+
}
|
|
45070
|
+
/**
|
|
45071
|
+
* The ref a plain claim names: an existing frame, or one a live reservation
|
|
45072
|
+
* holds before its file is written, which the agent claims as it turns to
|
|
45073
|
+
* draw it. Any other missing frame refuses `frame-not-found` as before.
|
|
45074
|
+
*/
|
|
45075
|
+
async function claimable(root, ref, options, now) {
|
|
45076
|
+
const frame = await resolveFrameRef(root, ref, {
|
|
45077
|
+
...options,
|
|
45078
|
+
allowMissing: true
|
|
44526
45079
|
});
|
|
45080
|
+
const canonical = refOf(frame);
|
|
45081
|
+
if (existsSync(frame.path)) return canonical;
|
|
45082
|
+
if ((await readClaims(root, now)).some((each) => each.frame === canonical && each.box)) return canonical;
|
|
45083
|
+
throw new FrameboardError("frame-not-found", `No frame ${frame.name} in ${frame.project}/${frame.page}.`, { ref });
|
|
45084
|
+
}
|
|
45085
|
+
/** `<project>/<page>/<frame>`, the one form a claim names a frame by. */
|
|
45086
|
+
function refOf(frame) {
|
|
44527
45087
|
return `${frame.project}/${frame.page}/${frame.name}`;
|
|
44528
45088
|
}
|
|
45089
|
+
/**
|
|
45090
|
+
* The box each named frame will land in, in one row per page in the order
|
|
45091
|
+
* named, past every frame and live reservation already on that page unless
|
|
45092
|
+
* `--x` or `--y` sets the row. A frame that exists already refuses
|
|
45093
|
+
* `name-taken` before anything is reserved.
|
|
45094
|
+
*/
|
|
45095
|
+
async function reservationsOf(root, refs, options, cwd, now) {
|
|
45096
|
+
if (refs.length === 0) throw new FrameboardError("usage", "Name at least one frame to reserve with --new.");
|
|
45097
|
+
const frames = await Promise.all(refs.map((ref) => resolveFrameRef(root, ref, {
|
|
45098
|
+
...resolving(options, cwd),
|
|
45099
|
+
allowMissing: true
|
|
45100
|
+
})));
|
|
45101
|
+
const existing = frames.filter((frame) => existsSync(frame.path));
|
|
45102
|
+
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) });
|
|
45103
|
+
const named = frames.map(refOf);
|
|
45104
|
+
const repeated = named.find((ref, index) => named.indexOf(ref) !== index);
|
|
45105
|
+
if (repeated) throw new FrameboardError("usage", `${repeated} is named twice.`, { ref: repeated });
|
|
45106
|
+
const size = {
|
|
45107
|
+
...FRAME_SIZES[DEFAULT_FRAME_SIZE],
|
|
45108
|
+
...sizeOf(options)
|
|
45109
|
+
};
|
|
45110
|
+
const hugs = hugsOf(options);
|
|
45111
|
+
const live = await readClaims(root, now);
|
|
45112
|
+
const nextX = /* @__PURE__ */ new Map();
|
|
45113
|
+
const reservations = [];
|
|
45114
|
+
for (const frame of frames) {
|
|
45115
|
+
const page = `${frame.project}/${frame.page}`;
|
|
45116
|
+
const x = nextX.get(page) ?? options.x ?? await rightOf(root, frame, live);
|
|
45117
|
+
nextX.set(page, x + size.width + 80);
|
|
45118
|
+
reservations.push({
|
|
45119
|
+
frame: refOf(frame),
|
|
45120
|
+
box: {
|
|
45121
|
+
x,
|
|
45122
|
+
y: options.y ?? 0,
|
|
45123
|
+
...size,
|
|
45124
|
+
...hugs
|
|
45125
|
+
}
|
|
45126
|
+
});
|
|
45127
|
+
}
|
|
45128
|
+
return reservations;
|
|
45129
|
+
}
|
|
45130
|
+
/** Where a new row starts on a frame's page, past its frames and reserved boxes. */
|
|
45131
|
+
async function rightOf(root, frame, live) {
|
|
45132
|
+
const page = await scanPage(root, frame.project, frame.page, 0);
|
|
45133
|
+
const prefix = `${frame.project}/${frame.page}/`;
|
|
45134
|
+
const boxes = [...page.frames.map((each) => each.box), ...live.flatMap((each) => each.box && each.frame.startsWith(prefix) ? [each.box] : [])];
|
|
45135
|
+
return Math.max(...boxes.map((box) => box.x + box.width + 80), 0);
|
|
45136
|
+
}
|
|
44529
45137
|
function describe$4(claims, now) {
|
|
44530
45138
|
if (claims.length === 0) return "No frame is claimed";
|
|
44531
45139
|
return claims.map((each) => {
|
|
44532
45140
|
const seconds = Math.round((now.getTime() - Date.parse(each.claimedAt)) / 1e3);
|
|
44533
|
-
|
|
45141
|
+
const state = each.box ? "reserved" : "editing";
|
|
45142
|
+
return `${each.frame} ${each.tag} ${state} ${seconds}s ${each.session}`;
|
|
44534
45143
|
}).join("\n");
|
|
44535
45144
|
}
|
|
44536
45145
|
// src/cli/commands/frame.ts
|
|
@@ -48651,6 +49260,22 @@ function registerProject(program, context) {
|
|
|
48651
49260
|
human: `Deleted project ${result.deleted}`
|
|
48652
49261
|
};
|
|
48653
49262
|
});
|
|
49263
|
+
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) => {
|
|
49264
|
+
const group = folderOf(folder, options.clear === true);
|
|
49265
|
+
const record = await fileOne(await boardOf(options, io), name, { group });
|
|
49266
|
+
return {
|
|
49267
|
+
data: record,
|
|
49268
|
+
human: group ? `Filed project ${record.name} under ${group}` : `Took project ${record.name} out of its folder`
|
|
49269
|
+
};
|
|
49270
|
+
});
|
|
49271
|
+
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) => {
|
|
49272
|
+
const archived = options.restore !== true;
|
|
49273
|
+
const record = await fileOne(await boardOf(options, io), name, { archived });
|
|
49274
|
+
return {
|
|
49275
|
+
data: record,
|
|
49276
|
+
human: archived ? `Archived project ${record.name}` : `Restored project ${record.name}`
|
|
49277
|
+
};
|
|
49278
|
+
});
|
|
48654
49279
|
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
49280
|
const record = await writeStarterSheet(await boardOf(options, io), name, {
|
|
48656
49281
|
accent: options.accent,
|
|
@@ -48662,6 +49287,26 @@ function registerProject(program, context) {
|
|
|
48662
49287
|
};
|
|
48663
49288
|
});
|
|
48664
49289
|
}
|
|
49290
|
+
/** Files one project, answering its record as `fileProjects` leaves it. */
|
|
49291
|
+
async function fileOne(root, name, filing) {
|
|
49292
|
+
const [record] = await fileProjects(root, [name], filing);
|
|
49293
|
+
if (!record) throw new FrameboardError("internal", "No project filed.");
|
|
49294
|
+
return record;
|
|
49295
|
+
}
|
|
49296
|
+
/**
|
|
49297
|
+
* The folder a `group` call names, or null for `--clear`. A blank folder is
|
|
49298
|
+
* refused here, since the writer reads one as a clear.
|
|
49299
|
+
*/
|
|
49300
|
+
function folderOf(folder, clear) {
|
|
49301
|
+
if (clear && folder !== void 0) throw new FrameboardError("usage", "Give a folder or --clear, not both.");
|
|
49302
|
+
if (clear) return null;
|
|
49303
|
+
if (folder === void 0) throw new FrameboardError("usage", "Give a folder, or --clear to leave one.");
|
|
49304
|
+
const name = folder.trim();
|
|
49305
|
+
if (name === "" || name.length > MAX_FOLDER) throw new FrameboardError("invalid-name", `A folder name holds 1 to ${MAX_FOLDER} characters.`);
|
|
49306
|
+
return name;
|
|
49307
|
+
}
|
|
49308
|
+
/** The longest folder name the board's own filing route accepts. */
|
|
49309
|
+
const MAX_FOLDER = 256;
|
|
48665
49310
|
// src/server/references/assets.ts
|
|
48666
49311
|
/**
|
|
48667
49312
|
* The files a frame loads inside its project's `assets/`, by their path there,
|
|
@@ -49171,10 +49816,15 @@ function createThumbnailStore({ root, run, render, onRendered }) {
|
|
|
49171
49816
|
[
|
|
49172
49817
|
...LAYOUT_RULES,
|
|
49173
49818
|
...FONT_SIZE_RULES,
|
|
49819
|
+
...CONTRAST_RULES,
|
|
49174
49820
|
...DECLARATION_RULES
|
|
49175
49821
|
];
|
|
49176
49822
|
/** The rules that read one theme's page and land one finding at most. */
|
|
49177
|
-
const THEMED_RULES = [
|
|
49823
|
+
const THEMED_RULES = [
|
|
49824
|
+
...LAYOUT_RULES,
|
|
49825
|
+
...FONT_SIZE_RULES,
|
|
49826
|
+
...CONTRAST_RULES
|
|
49827
|
+
];
|
|
49178
49828
|
/**
|
|
49179
49829
|
* Runs every browser rule on one frame at its layout size, in light and in
|
|
49180
49830
|
* dark, and merges the two. A rule tripping in one theme alone names that
|
|
@@ -49201,7 +49851,11 @@ async function checkRendered(browser, { baseUrl, root, frame, config }) {
|
|
|
49201
49851
|
fonts: "wait"
|
|
49202
49852
|
});
|
|
49203
49853
|
try {
|
|
49204
|
-
byTheme.set(theme, [
|
|
49854
|
+
byTheme.set(theme, [
|
|
49855
|
+
...await checkLayout(opened.page, frame),
|
|
49856
|
+
...config.minFontSize === void 0 ? [] : await checkFontSize(opened.page, frame, config.minFontSize),
|
|
49857
|
+
...config.minContrast === void 0 ? [] : await checkContrast(opened.page, frame, config.minContrast)
|
|
49858
|
+
]);
|
|
49205
49859
|
if (theme === THEMES[0]) declarations = await checkDeclarations(opened.page, source);
|
|
49206
49860
|
} finally {
|
|
49207
49861
|
await opened.close();
|
|
@@ -49232,6 +49886,70 @@ function mergeThemes(byTheme) {
|
|
|
49232
49886
|
}
|
|
49233
49887
|
return merged;
|
|
49234
49888
|
}
|
|
49889
|
+
// src/server/claims/land.ts
|
|
49890
|
+
/**
|
|
49891
|
+
* Moves each reserved frame whose file now exists from its claim into the
|
|
49892
|
+
* layout: an entry at the claim's box on top of its page, unless the page
|
|
49893
|
+
* already holds one, then the claim drops its box and holds the frame as any
|
|
49894
|
+
* editing claim does. Answers the refs it landed, and none when the claims
|
|
49895
|
+
* file does not parse.
|
|
49896
|
+
*/
|
|
49897
|
+
async function landReserved(root, now) {
|
|
49898
|
+
let claims;
|
|
49899
|
+
try {
|
|
49900
|
+
claims = await readClaims(root, now);
|
|
49901
|
+
} catch (error) {
|
|
49902
|
+
if (error instanceof FrameboardError) return [];
|
|
49903
|
+
throw error;
|
|
49904
|
+
}
|
|
49905
|
+
const due = claims.flatMap((claim) => {
|
|
49906
|
+
const { box } = claim;
|
|
49907
|
+
const [project, page, name] = claim.frame.split("/");
|
|
49908
|
+
if (!box || !project || !page || !name) return [];
|
|
49909
|
+
const dir = join(root, project, page);
|
|
49910
|
+
return existsSync(join(dir, `${name}.html`)) ? [{
|
|
49911
|
+
claim: {
|
|
49912
|
+
...claim,
|
|
49913
|
+
box
|
|
49914
|
+
},
|
|
49915
|
+
page: dir,
|
|
49916
|
+
name
|
|
49917
|
+
}] : [];
|
|
49918
|
+
});
|
|
49919
|
+
if (due.length === 0) return [];
|
|
49920
|
+
await withLayouts(due.map((each) => each.page), async (layouts) => {
|
|
49921
|
+
for (const { claim, page, name } of due) {
|
|
49922
|
+
const layout = layoutAt(layouts, page);
|
|
49923
|
+
if (layout.hasEntry(name) || !layout.names.includes(name)) continue;
|
|
49924
|
+
const { x, y, width, height, hugWidth, hugHeight } = claim.box;
|
|
49925
|
+
layout.set(name, {
|
|
49926
|
+
box: {
|
|
49927
|
+
x,
|
|
49928
|
+
y,
|
|
49929
|
+
width,
|
|
49930
|
+
height
|
|
49931
|
+
},
|
|
49932
|
+
order: layout.placement(name).order,
|
|
49933
|
+
hidden: false,
|
|
49934
|
+
locked: false,
|
|
49935
|
+
hugWidth: hugWidth ?? false,
|
|
49936
|
+
hugHeight: hugHeight ?? false,
|
|
49937
|
+
placed: true
|
|
49938
|
+
});
|
|
49939
|
+
layout.renumber();
|
|
49940
|
+
}
|
|
49941
|
+
});
|
|
49942
|
+
const landed = new Set(due.map((each) => each.claim.frame));
|
|
49943
|
+
await updateRecord(claimsPath(root), claimsSpec, (file) => ({
|
|
49944
|
+
...file,
|
|
49945
|
+
claims: file.claims.map((each) => {
|
|
49946
|
+
if (!landed.has(each.frame) || !each.box) return each;
|
|
49947
|
+
const { box: _box, ...rest } = each;
|
|
49948
|
+
return rest;
|
|
49949
|
+
})
|
|
49950
|
+
}));
|
|
49951
|
+
return [...landed];
|
|
49952
|
+
}
|
|
49235
49953
|
// src/server/claims/push.ts
|
|
49236
49954
|
/** setTimeout's longest delay, past which it fires at once. */
|
|
49237
49955
|
const MAX_DELAY_MS = 2 ** 31 - 1;
|
|
@@ -53458,6 +54176,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
53458
54176
|
});
|
|
53459
54177
|
server.on("upgrade", hub.handleUpgrade);
|
|
53460
54178
|
inTurn(async () => {
|
|
54179
|
+
await landReserved(root, /* @__PURE__ */ new Date()).catch(() => []);
|
|
53461
54180
|
let board = await scanBoard(root);
|
|
53462
54181
|
const stale = await writtenSinceLayout(board).catch(() => []);
|
|
53463
54182
|
if (await hug.now(board, stale).catch(() => false)) board = await scanBoard(root);
|
|
@@ -53532,6 +54251,7 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
|
|
|
53532
54251
|
let own;
|
|
53533
54252
|
let placed;
|
|
53534
54253
|
try {
|
|
54254
|
+
await landReserved(root, /* @__PURE__ */ new Date()).catch(() => []);
|
|
53535
54255
|
board = await scanBoard(root);
|
|
53536
54256
|
const previous = scanned.board;
|
|
53537
54257
|
scanned.board = board;
|