frameboard 0.42.0 → 0.44.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 +2388 -1155
- package/dist/client/assets/index-Bh7QIOuP.js +181 -0
- package/dist/client/assets/index-vZBQT6hk.css +2 -0
- package/dist/client/index.html +2 -2
- package/dist/frame-bridge.js +72 -72
- package/package.json +1 -1
- package/dist/client/assets/index-Broai9D9.js +0 -181
- package/dist/client/assets/index-E0z1fVUW.css +0 -2
package/dist/cli.js
CHANGED
|
@@ -3065,7 +3065,9 @@ const EXIT_CODES = {
|
|
|
3065
3065
|
"result-not-found": 3,
|
|
3066
3066
|
"no-provider": 3,
|
|
3067
3067
|
"source-failed": 13,
|
|
3068
|
-
"provider-failed": 13
|
|
3068
|
+
"provider-failed": 13,
|
|
3069
|
+
"asset-not-found": 3,
|
|
3070
|
+
"asset-held": 4
|
|
3069
3071
|
};
|
|
3070
3072
|
var FrameboardError = class extends Error {
|
|
3071
3073
|
code;
|
|
@@ -4327,7 +4329,7 @@ function datetime$1(args) {
|
|
|
4327
4329
|
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
4328
4330
|
}
|
|
4329
4331
|
const anyString = /^[\s\S]{0,}$/;
|
|
4330
|
-
const integer$
|
|
4332
|
+
const integer$2 = /^-?\d+$/;
|
|
4331
4333
|
const number$1 = /^-?\d+(?:\.\d+)?$/;
|
|
4332
4334
|
const boolean$2 = /^(?:true|false)$/i;
|
|
4333
4335
|
const lowercase = /^[^A-Z]*$/;
|
|
@@ -5726,6 +5728,114 @@ function handleIntersectionResults(result, left, right) {
|
|
|
5726
5728
|
result.value = merged.data;
|
|
5727
5729
|
return result;
|
|
5728
5730
|
}
|
|
5731
|
+
const $ZodTuple = /*@__PURE__*/ $constructor("$ZodTuple", (inst, def) => {
|
|
5732
|
+
$ZodType.init(inst, def);
|
|
5733
|
+
const items = def.items;
|
|
5734
|
+
const memo = globalConfig.memoizer;
|
|
5735
|
+
memo?.attach(inst);
|
|
5736
|
+
inst._zod.parse = (payload, ctx) => {
|
|
5737
|
+
const input = payload.value;
|
|
5738
|
+
if (!Array.isArray(input)) {
|
|
5739
|
+
payload.issues.push({
|
|
5740
|
+
input,
|
|
5741
|
+
inst,
|
|
5742
|
+
expected: "tuple",
|
|
5743
|
+
code: "invalid_type"
|
|
5744
|
+
});
|
|
5745
|
+
return payload;
|
|
5746
|
+
}
|
|
5747
|
+
payload.value = memo ? memo.alloc(inst, payload, [], ctx) : [];
|
|
5748
|
+
const proms = [];
|
|
5749
|
+
const optinStart = getTupleOptStart(items, "optin");
|
|
5750
|
+
const optoutStart = getTupleOptStart(items, "optout");
|
|
5751
|
+
if (!def.rest) {
|
|
5752
|
+
if (input.length < optinStart) {
|
|
5753
|
+
payload.issues.push({
|
|
5754
|
+
code: "too_small",
|
|
5755
|
+
minimum: optinStart,
|
|
5756
|
+
inclusive: true,
|
|
5757
|
+
input,
|
|
5758
|
+
inst,
|
|
5759
|
+
origin: "array"
|
|
5760
|
+
});
|
|
5761
|
+
return payload;
|
|
5762
|
+
}
|
|
5763
|
+
if (input.length > items.length) payload.issues.push({
|
|
5764
|
+
code: "too_big",
|
|
5765
|
+
maximum: items.length,
|
|
5766
|
+
inclusive: true,
|
|
5767
|
+
input,
|
|
5768
|
+
inst,
|
|
5769
|
+
origin: "array"
|
|
5770
|
+
});
|
|
5771
|
+
}
|
|
5772
|
+
const itemResults = new Array(items.length);
|
|
5773
|
+
const abortEarly = def.rest ? ctx?.abortEarly : void 0;
|
|
5774
|
+
let itemAborted = false;
|
|
5775
|
+
for (let i = 0; i < items.length; i++) {
|
|
5776
|
+
const r = items[i]._zod.run({
|
|
5777
|
+
value: input[i],
|
|
5778
|
+
issues: []
|
|
5779
|
+
}, ctx);
|
|
5780
|
+
if (r instanceof Promise) proms.push(r.then((rr) => {
|
|
5781
|
+
itemResults[i] = rr;
|
|
5782
|
+
}));
|
|
5783
|
+
else {
|
|
5784
|
+
itemResults[i] = r;
|
|
5785
|
+
if (abortEarly && !itemAborted && r.issues.length) itemAborted = aborted(r);
|
|
5786
|
+
}
|
|
5787
|
+
}
|
|
5788
|
+
if (def.rest && !itemAborted) {
|
|
5789
|
+
let i = items.length - 1;
|
|
5790
|
+
const rest = input.slice(items.length);
|
|
5791
|
+
let seen = payload.issues.length;
|
|
5792
|
+
for (const el of rest) {
|
|
5793
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
5794
|
+
if (aborted(payload, seen)) break;
|
|
5795
|
+
seen = payload.issues.length;
|
|
5796
|
+
}
|
|
5797
|
+
i++;
|
|
5798
|
+
const result = def.rest._zod.run({
|
|
5799
|
+
value: el,
|
|
5800
|
+
issues: []
|
|
5801
|
+
}, ctx);
|
|
5802
|
+
if (result instanceof Promise) proms.push(result.then((r) => handleTupleResult(r, payload, i)));
|
|
5803
|
+
else handleTupleResult(result, payload, i);
|
|
5804
|
+
}
|
|
5805
|
+
}
|
|
5806
|
+
if (proms.length) return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input, optoutStart));
|
|
5807
|
+
return handleTupleResults(itemResults, payload, items, input, optoutStart);
|
|
5808
|
+
};
|
|
5809
|
+
});
|
|
5810
|
+
function getTupleOptStart(items, key) {
|
|
5811
|
+
for (let i = items.length - 1; i >= 0; i--) if (!(key === "optin" ? items[i]._zod.optin !== void 0 : items[i]._zod.optout === "optional")) return i + 1;
|
|
5812
|
+
return 0;
|
|
5813
|
+
}
|
|
5814
|
+
function handleTupleResult(result, final, index) {
|
|
5815
|
+
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
|
|
5816
|
+
final.value[index] = result.value;
|
|
5817
|
+
}
|
|
5818
|
+
function handleTupleResults(itemResults, final, items, input, optoutStart) {
|
|
5819
|
+
for (let i = 0; i < items.length; i++) {
|
|
5820
|
+
const r = itemResults[i];
|
|
5821
|
+
const isPresent = i < input.length;
|
|
5822
|
+
if (!isPresent && i >= optoutStart && items[i]._zod.optin === "optional") {
|
|
5823
|
+
final.value.length = i;
|
|
5824
|
+
break;
|
|
5825
|
+
}
|
|
5826
|
+
if (r.issues.length) {
|
|
5827
|
+
if (!isPresent && i >= optoutStart) {
|
|
5828
|
+
final.value.length = i;
|
|
5829
|
+
break;
|
|
5830
|
+
}
|
|
5831
|
+
final.issues.push(...prefixIssues(i, r.issues));
|
|
5832
|
+
}
|
|
5833
|
+
final.value[i] = r.value;
|
|
5834
|
+
}
|
|
5835
|
+
for (let i = final.value.length - 1; i >= input.length; i--) if (items[i]._zod.optout === "optional" && final.value[i] === void 0) final.value.length = i;
|
|
5836
|
+
else break;
|
|
5837
|
+
return final;
|
|
5838
|
+
}
|
|
5729
5839
|
const $ZodRecord = /*@__PURE__*/ $constructor("$ZodRecord", (inst, def) => {
|
|
5730
5840
|
$ZodType.init(inst, def);
|
|
5731
5841
|
const memo = globalConfig.memoizer;
|
|
@@ -7887,7 +7997,7 @@ function stringifyKeyNames(bySchema, json, visited) {
|
|
|
7887
7997
|
else if (typeof rest.const === "number") rest.const = String(rest.const);
|
|
7888
7998
|
if (!numericType) return rest;
|
|
7889
7999
|
rest.type = "string";
|
|
7890
|
-
if (!values) rest.pattern = (types.includes("number") ? number$1 : integer$
|
|
8000
|
+
if (!values) rest.pattern = (types.includes("number") ? number$1 : integer$2).source;
|
|
7891
8001
|
return rest;
|
|
7892
8002
|
}
|
|
7893
8003
|
/** Every record of one conversion, so the carriers are found in a single pass rather than once per record. */
|
|
@@ -8180,7 +8290,7 @@ const decode = /* @__PURE__ */ _decode(ZodRealError);
|
|
|
8180
8290
|
const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
|
|
8181
8291
|
const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
|
|
8182
8292
|
const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
|
|
8183
|
-
const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
8293
|
+
const safeDecode$1 = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
8184
8294
|
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
8185
8295
|
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
8186
8296
|
// node_modules/zod/v4/classic/schemas.js
|
|
@@ -8341,7 +8451,7 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
|
|
|
8341
8451
|
return safeEncode(this, data, params);
|
|
8342
8452
|
},
|
|
8343
8453
|
safeDecode(data, params) {
|
|
8344
|
-
return safeDecode(this, data, params);
|
|
8454
|
+
return safeDecode$1(this, data, params);
|
|
8345
8455
|
},
|
|
8346
8456
|
async safeEncodeAsync(data, params) {
|
|
8347
8457
|
return safeEncodeAsync(this, data, params);
|
|
@@ -8839,6 +8949,39 @@ function intersection(left, right) {
|
|
|
8839
8949
|
right
|
|
8840
8950
|
});
|
|
8841
8951
|
}
|
|
8952
|
+
const ZodTuple = /*@__PURE__*/ $constructor("ZodTuple", (inst, def) => {
|
|
8953
|
+
_ensureDefaultMemoizer();
|
|
8954
|
+
$ZodTuple.init(inst, def);
|
|
8955
|
+
ZodType.init(inst, def);
|
|
8956
|
+
inst._zod.processJSONSchema = (ctx, json, params) => tupleProcessor(inst, ctx, json, params);
|
|
8957
|
+
}, {
|
|
8958
|
+
rest(rest) {
|
|
8959
|
+
return this.clone({
|
|
8960
|
+
...this._zod.def,
|
|
8961
|
+
rest
|
|
8962
|
+
});
|
|
8963
|
+
},
|
|
8964
|
+
partial() {
|
|
8965
|
+
const def = this._zod.def;
|
|
8966
|
+
if (def.checks?.length) throw new Error(".partial() cannot be used on tuple schemas containing refinements");
|
|
8967
|
+
return this.clone({
|
|
8968
|
+
...def,
|
|
8969
|
+
items: def.items.map((item) => new ZodOptional({
|
|
8970
|
+
type: "optional",
|
|
8971
|
+
innerType: item
|
|
8972
|
+
}))
|
|
8973
|
+
});
|
|
8974
|
+
}
|
|
8975
|
+
});
|
|
8976
|
+
function tuple(items, _paramsOrRest, _params) {
|
|
8977
|
+
const hasRest = _paramsOrRest instanceof $ZodType;
|
|
8978
|
+
return new ZodTuple({
|
|
8979
|
+
type: "tuple",
|
|
8980
|
+
items,
|
|
8981
|
+
rest: hasRest ? _paramsOrRest : null,
|
|
8982
|
+
...normalizeParams(hasRest ? _params : _paramsOrRest)
|
|
8983
|
+
});
|
|
8984
|
+
}
|
|
8842
8985
|
const ZodRecord = /*@__PURE__*/ $constructor("ZodRecord", (inst, def) => {
|
|
8843
8986
|
_ensureDefaultMemoizer();
|
|
8844
8987
|
$ZodRecord.init(inst, def);
|
|
@@ -9084,220 +9227,6 @@ function superRefine(fn, params) {
|
|
|
9084
9227
|
function datetime(params) {
|
|
9085
9228
|
return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
|
|
9086
9229
|
}
|
|
9087
|
-
// src/shared/frame-device.ts
|
|
9088
|
-
/**
|
|
9089
|
-
* The devices the board can draw around a frame. A frame's width picks the
|
|
9090
|
-
* first three, and a frame names a foldable.
|
|
9091
|
-
*/
|
|
9092
|
-
const DEVICES = [
|
|
9093
|
-
"phone",
|
|
9094
|
-
"tablet",
|
|
9095
|
-
"laptop",
|
|
9096
|
-
"foldable"
|
|
9097
|
-
];
|
|
9098
|
-
/** The laptop lid's chin below the screen, past the border its sides hold. */
|
|
9099
|
-
const LAPTOP_CHIN = 28;
|
|
9100
|
-
/** The laptop's base below the chin, reaching past the lid on each side by its share of the lid's width. */
|
|
9101
|
-
const LAPTOP_BASE = {
|
|
9102
|
-
height: 14,
|
|
9103
|
-
reach: .06,
|
|
9104
|
-
radius: 10
|
|
9105
|
-
};
|
|
9106
|
-
/**
|
|
9107
|
-
* Bezels measured off a current Pro phone and 13-inch tablet, the laptop
|
|
9108
|
-
* scaled off the picked mock, and the foldable's body less its glass. The
|
|
9109
|
-
* tablet's and the foldable's screen radii are guesses no source gives.
|
|
9110
|
-
*/
|
|
9111
|
-
const BEZELS = {
|
|
9112
|
-
phone: {
|
|
9113
|
-
border: 16,
|
|
9114
|
-
bottom: 16,
|
|
9115
|
-
screenRadius: 62,
|
|
9116
|
-
bodyRadius: 78
|
|
9117
|
-
},
|
|
9118
|
-
tablet: {
|
|
9119
|
-
border: 44,
|
|
9120
|
-
bottom: 44,
|
|
9121
|
-
screenRadius: 18,
|
|
9122
|
-
bodyRadius: 62
|
|
9123
|
-
},
|
|
9124
|
-
laptop: {
|
|
9125
|
-
border: 20,
|
|
9126
|
-
bottom: LAPTOP_CHIN + LAPTOP_BASE.height,
|
|
9127
|
-
screenRadius: 10,
|
|
9128
|
-
bodyRadius: 30
|
|
9129
|
-
},
|
|
9130
|
-
foldable: {
|
|
9131
|
-
border: 20,
|
|
9132
|
-
bottom: 20,
|
|
9133
|
-
screenRadius: 48,
|
|
9134
|
-
bodyRadius: 68
|
|
9135
|
-
}
|
|
9136
|
-
};
|
|
9137
|
-
/**
|
|
9138
|
-
* A device's screen corners as a CSS `border-radius`, which the body and every
|
|
9139
|
-
* box drawn on its screen share. A laptop's screen meets its chin, so only
|
|
9140
|
-
* its top corners round.
|
|
9141
|
-
*/
|
|
9142
|
-
function screenCorners(device) {
|
|
9143
|
-
const { screenRadius } = BEZELS[device];
|
|
9144
|
-
return device === "laptop" ? `${screenRadius}px ${screenRadius}px 0 0` : `${screenRadius}px`;
|
|
9145
|
-
}
|
|
9146
|
-
/**
|
|
9147
|
-
* The narrowest width each device draws around, widest first, so a frame
|
|
9148
|
-
* takes the first one it reaches. Under the phone's width no device fits.
|
|
9149
|
-
*/
|
|
9150
|
-
const DEVICE_WIDTHS = [
|
|
9151
|
-
["laptop", 1024],
|
|
9152
|
-
["tablet", 480],
|
|
9153
|
-
["phone", 320]
|
|
9154
|
-
];
|
|
9155
|
-
/** The device a frame this wide draws inside, null under 320 where none fits. */
|
|
9156
|
-
function deviceForWidth(width) {
|
|
9157
|
-
return DEVICE_WIDTHS.find(([, least]) => width >= least)?.[0] ?? null;
|
|
9158
|
-
}
|
|
9159
|
-
/**
|
|
9160
|
-
* The body's colors, fixed in both themes, since the board draws hardware
|
|
9161
|
-
* rather than chrome: the body, the hairline around it, and the island.
|
|
9162
|
-
*/
|
|
9163
|
-
const BEZEL_COLORS = {
|
|
9164
|
-
body: "#17181b",
|
|
9165
|
-
base: "#2c2e33",
|
|
9166
|
-
edge: "#45484f",
|
|
9167
|
-
island: "#050506",
|
|
9168
|
-
homeBar: "rgba(128, 128, 128, 0.6)"
|
|
9169
|
-
};
|
|
9170
|
-
/**
|
|
9171
|
-
* The phone's island, a generic pill standing in for a size no source gives,
|
|
9172
|
-
* and the home bar, each centered on the screen and drawn over the frame.
|
|
9173
|
-
*/
|
|
9174
|
-
const PHONE_ISLAND = {
|
|
9175
|
-
width: 81,
|
|
9176
|
-
height: 30,
|
|
9177
|
-
top: 14
|
|
9178
|
-
};
|
|
9179
|
-
const HOME_BAR = {
|
|
9180
|
-
width: 140,
|
|
9181
|
-
height: 5,
|
|
9182
|
-
bottom: 8
|
|
9183
|
-
};
|
|
9184
|
-
/** The ways a foldable is held, each a screen the frame's box takes the size of. */
|
|
9185
|
-
const POSES = [
|
|
9186
|
-
"closed",
|
|
9187
|
-
"half",
|
|
9188
|
-
"open"
|
|
9189
|
-
];
|
|
9190
|
-
/**
|
|
9191
|
-
* Each pose's screen in points, the cover display closed and the inner one
|
|
9192
|
-
* half open and open. The published pixel counts at three pixels to a point,
|
|
9193
|
-
* a scale no source states for this device.
|
|
9194
|
-
*/
|
|
9195
|
-
const POSE_SIZES = {
|
|
9196
|
-
closed: {
|
|
9197
|
-
width: 466,
|
|
9198
|
-
height: 678
|
|
9199
|
-
},
|
|
9200
|
-
half: {
|
|
9201
|
-
width: 890,
|
|
9202
|
-
height: 626
|
|
9203
|
-
},
|
|
9204
|
-
open: {
|
|
9205
|
-
width: 890,
|
|
9206
|
-
height: 626
|
|
9207
|
-
}
|
|
9208
|
-
};
|
|
9209
|
-
/** A layout entry's `pose` as a pose, closed for none or a value no reader knows. */
|
|
9210
|
-
function poseOf(value) {
|
|
9211
|
-
return POSES.find((pose) => pose === value) ?? "closed";
|
|
9212
|
-
}
|
|
9213
|
-
/** The pose a frame this wide starts in, closed or open, whichever moves its box least. */
|
|
9214
|
-
function nearestPose(width) {
|
|
9215
|
-
return Math.abs(width - POSE_SIZES.closed.width) <= Math.abs(width - POSE_SIZES.open.width) ? "closed" : "open";
|
|
9216
|
-
}
|
|
9217
|
-
/**
|
|
9218
|
-
* The foldable's island, a generic pill, centered on the cover screen and on
|
|
9219
|
-
* the right half of the inner one, a place no source gives.
|
|
9220
|
-
*/
|
|
9221
|
-
const FOLDABLE_ISLAND = {
|
|
9222
|
-
width: 100,
|
|
9223
|
-
height: 30,
|
|
9224
|
-
top: 14
|
|
9225
|
-
};
|
|
9226
|
-
/** Where the island's center sits across a pose's screen, as a share of its width. */
|
|
9227
|
-
function islandCenter(pose) {
|
|
9228
|
-
return pose === "closed" ? .5 : .75;
|
|
9229
|
-
}
|
|
9230
|
-
/**
|
|
9231
|
-
* The band drawn down the middle of the inner screen, a faint crease open
|
|
9232
|
-
* and a shaded fold half open, null on the cover screen, which has no fold.
|
|
9233
|
-
*/
|
|
9234
|
-
function foldBand(pose) {
|
|
9235
|
-
if (pose === "closed") return null;
|
|
9236
|
-
if (pose === "open") return {
|
|
9237
|
-
width: 26,
|
|
9238
|
-
background: "linear-gradient(90deg, transparent, rgba(0,0,0,.05) 35%, rgba(0,0,0,.11) 50%, rgba(255,255,255,.5) 56%, transparent)"
|
|
9239
|
-
};
|
|
9240
|
-
return {
|
|
9241
|
-
width: 150,
|
|
9242
|
-
background: "linear-gradient(90deg, transparent, rgba(0,0,0,.10) 30%, rgba(0,0,0,.34) 49%, rgba(0,0,0,.34) 51%, rgba(0,0,0,.08) 70%, transparent)"
|
|
9243
|
-
};
|
|
9244
|
-
}
|
|
9245
|
-
/**
|
|
9246
|
-
* The laptop's chin and base, each a box from the frame's top left, which
|
|
9247
|
-
* the board and the PNG draw as positioned boxes, since one spread around
|
|
9248
|
-
* the screen cannot draw a body wider below than above.
|
|
9249
|
-
*/
|
|
9250
|
-
function laptopParts({ width, height }) {
|
|
9251
|
-
const { border } = BEZELS.laptop;
|
|
9252
|
-
const lid = width + 2 * border;
|
|
9253
|
-
const reach = baseReach(width);
|
|
9254
|
-
return {
|
|
9255
|
-
chin: {
|
|
9256
|
-
x: -border,
|
|
9257
|
-
y: height,
|
|
9258
|
-
width: lid,
|
|
9259
|
-
height: LAPTOP_CHIN
|
|
9260
|
-
},
|
|
9261
|
-
base: {
|
|
9262
|
-
x: -border - reach,
|
|
9263
|
-
y: height + LAPTOP_CHIN,
|
|
9264
|
-
width: lid + 2 * reach,
|
|
9265
|
-
height: LAPTOP_BASE.height
|
|
9266
|
-
}
|
|
9267
|
-
};
|
|
9268
|
-
}
|
|
9269
|
-
function baseReach(width) {
|
|
9270
|
-
return Math.round((width + 2 * BEZELS.laptop.border) * LAPTOP_BASE.reach);
|
|
9271
|
-
}
|
|
9272
|
-
/**
|
|
9273
|
-
* The `box-shadow` drawing a device's body, with a hairline on the board so a
|
|
9274
|
-
* dark body reads on a dark canvas, and no drop shadow in an export.
|
|
9275
|
-
*/
|
|
9276
|
-
function bezelShadow(device, { board = true } = {}) {
|
|
9277
|
-
const { border } = BEZELS[device];
|
|
9278
|
-
if (!board) return [`0 0 0 ${border - 1}px ${BEZEL_COLORS.body}`, `0 0 0 ${border}px ${BEZEL_COLORS.edge}`].join(", ");
|
|
9279
|
-
return [
|
|
9280
|
-
`0 0 0 ${border}px ${BEZEL_COLORS.body}`,
|
|
9281
|
-
`0 0 0 calc(${border}px + 1px / var(--zoom, 1)) ${BEZEL_COLORS.edge}`,
|
|
9282
|
-
`0 ${border}px ${border * 3}px rgba(0, 0, 0, 0.3)`
|
|
9283
|
-
].join(", ");
|
|
9284
|
-
}
|
|
9285
|
-
/**
|
|
9286
|
-
* The box a device's body covers around a frame's box, the box itself with
|
|
9287
|
-
* none. A laptop's base reaches past its lid, so its sides grow by more
|
|
9288
|
-
* than its top.
|
|
9289
|
-
*/
|
|
9290
|
-
function bezelBox(box, device) {
|
|
9291
|
-
if (!device) return { ...box };
|
|
9292
|
-
const { border, bottom } = BEZELS[device];
|
|
9293
|
-
const side = device === "laptop" ? border + baseReach(box.width) : border;
|
|
9294
|
-
return {
|
|
9295
|
-
x: box.x - side,
|
|
9296
|
-
y: box.y - border,
|
|
9297
|
-
width: box.width + 2 * side,
|
|
9298
|
-
height: box.height + border + bottom
|
|
9299
|
-
};
|
|
9300
|
-
}
|
|
9301
9230
|
// src/shared/frame-sizes.ts
|
|
9302
9231
|
/** The current iPhone, iPad Air portrait, and a common laptop viewport. */
|
|
9303
9232
|
const FRAME_SIZES = {
|
|
@@ -9478,6 +9407,347 @@ function presetAt(width) {
|
|
|
9478
9407
|
function referenceHeight(width) {
|
|
9479
9408
|
return FRAME_SIZES[presetAt(width) ?? "desktop"].height;
|
|
9480
9409
|
}
|
|
9410
|
+
// src/shared/frame-device.ts
|
|
9411
|
+
/**
|
|
9412
|
+
* The devices the board can draw around a frame. A frame's width picks the
|
|
9413
|
+
* first three, and a frame names a foldable.
|
|
9414
|
+
*/
|
|
9415
|
+
const DEVICES = [
|
|
9416
|
+
"phone",
|
|
9417
|
+
"tablet",
|
|
9418
|
+
"laptop",
|
|
9419
|
+
"foldable"
|
|
9420
|
+
];
|
|
9421
|
+
/** The laptop lid's chin below the screen, past the border its sides hold. */
|
|
9422
|
+
const LAPTOP_CHIN = 28;
|
|
9423
|
+
/** The laptop's base below the chin, reaching past the lid on each side by its share of the lid's width. */
|
|
9424
|
+
const LAPTOP_BASE = {
|
|
9425
|
+
height: 14,
|
|
9426
|
+
reach: .06,
|
|
9427
|
+
radius: 10
|
|
9428
|
+
};
|
|
9429
|
+
/**
|
|
9430
|
+
* Bezels measured off a current Pro phone and 13-inch tablet, the laptop
|
|
9431
|
+
* scaled off the picked mock, and the foldable's body less its glass. The
|
|
9432
|
+
* tablet's and the foldable's screen radii are guesses no source gives.
|
|
9433
|
+
*/
|
|
9434
|
+
const BEZELS = {
|
|
9435
|
+
phone: {
|
|
9436
|
+
border: 16,
|
|
9437
|
+
bottom: 16,
|
|
9438
|
+
screenRadius: 62,
|
|
9439
|
+
bodyRadius: 78
|
|
9440
|
+
},
|
|
9441
|
+
tablet: {
|
|
9442
|
+
border: 44,
|
|
9443
|
+
bottom: 44,
|
|
9444
|
+
screenRadius: 18,
|
|
9445
|
+
bodyRadius: 62
|
|
9446
|
+
},
|
|
9447
|
+
laptop: {
|
|
9448
|
+
border: 20,
|
|
9449
|
+
bottom: LAPTOP_CHIN + LAPTOP_BASE.height,
|
|
9450
|
+
screenRadius: 10,
|
|
9451
|
+
bodyRadius: 30
|
|
9452
|
+
},
|
|
9453
|
+
foldable: {
|
|
9454
|
+
border: 20,
|
|
9455
|
+
bottom: 20,
|
|
9456
|
+
screenRadius: 48,
|
|
9457
|
+
bodyRadius: 68
|
|
9458
|
+
}
|
|
9459
|
+
};
|
|
9460
|
+
/**
|
|
9461
|
+
* A device's screen corners as a CSS `border-radius`, which the body and every
|
|
9462
|
+
* box drawn on its screen share. A laptop's screen meets its chin, so only
|
|
9463
|
+
* its top corners round.
|
|
9464
|
+
*/
|
|
9465
|
+
function screenCorners(device) {
|
|
9466
|
+
const { screenRadius } = BEZELS[device];
|
|
9467
|
+
return device === "laptop" ? `${screenRadius}px ${screenRadius}px 0 0` : `${screenRadius}px`;
|
|
9468
|
+
}
|
|
9469
|
+
/**
|
|
9470
|
+
* The narrowest width each device draws around, widest first, so a frame
|
|
9471
|
+
* takes the first one it reaches. Under the phone's width no device fits.
|
|
9472
|
+
*/
|
|
9473
|
+
const DEVICE_WIDTHS = [
|
|
9474
|
+
["laptop", 1024],
|
|
9475
|
+
["tablet", 480],
|
|
9476
|
+
["phone", 320]
|
|
9477
|
+
];
|
|
9478
|
+
/** The device a frame this wide draws inside, null under 320 where none fits. */
|
|
9479
|
+
function deviceForWidth(width) {
|
|
9480
|
+
return DEVICE_WIDTHS.find(([, least]) => width >= least)?.[0] ?? null;
|
|
9481
|
+
}
|
|
9482
|
+
/**
|
|
9483
|
+
* The body's colors, fixed in both themes, since the board draws hardware
|
|
9484
|
+
* rather than chrome: the body, the hairline around it, and the island.
|
|
9485
|
+
*/
|
|
9486
|
+
const BEZEL_COLORS = {
|
|
9487
|
+
body: "#17181b",
|
|
9488
|
+
base: "#2c2e33",
|
|
9489
|
+
edge: "#45484f",
|
|
9490
|
+
island: "#050506",
|
|
9491
|
+
homeBar: "rgba(128, 128, 128, 0.6)",
|
|
9492
|
+
button: "#2a2c31",
|
|
9493
|
+
islandText: "#ffffff",
|
|
9494
|
+
islandLive: "#34c759"
|
|
9495
|
+
};
|
|
9496
|
+
/**
|
|
9497
|
+
* The phone's island, a generic pill standing in for a size no source gives,
|
|
9498
|
+
* and the home bar, each centered on the screen and drawn over the frame.
|
|
9499
|
+
*/
|
|
9500
|
+
const PHONE_ISLAND = {
|
|
9501
|
+
width: 81,
|
|
9502
|
+
height: 30,
|
|
9503
|
+
top: 14
|
|
9504
|
+
};
|
|
9505
|
+
const HOME_BAR = {
|
|
9506
|
+
width: 140,
|
|
9507
|
+
height: 5,
|
|
9508
|
+
bottom: 8
|
|
9509
|
+
};
|
|
9510
|
+
/** The island's two widths, the compact pill and the wide one a call or a timer shows. */
|
|
9511
|
+
const ISLANDS = ["compact", "wide"];
|
|
9512
|
+
/** A layout entry's `island` as an island, compact for none or a value no reader knows. */
|
|
9513
|
+
function islandOf(value) {
|
|
9514
|
+
return value === "wide" ? "wide" : "compact";
|
|
9515
|
+
}
|
|
9516
|
+
/** The wide island's width, scaled off the picked mock's ratio to the compact one. */
|
|
9517
|
+
const WIDE_ISLAND_WIDTH = 126;
|
|
9518
|
+
/** The phone's island at its picked width, the wide one holding a timer. */
|
|
9519
|
+
function phoneIsland(island) {
|
|
9520
|
+
return island === "wide" ? {
|
|
9521
|
+
...PHONE_ISLAND,
|
|
9522
|
+
width: WIDE_ISLAND_WIDTH
|
|
9523
|
+
} : { ...PHONE_ISLAND };
|
|
9524
|
+
}
|
|
9525
|
+
/** What the wide island shows, a running timer no frame sets, and the heights of the level bars beside it. */
|
|
9526
|
+
const WIDE_ISLAND_TIMER = "0:42";
|
|
9527
|
+
const WIDE_ISLAND_LEVEL = [
|
|
9528
|
+
5,
|
|
9529
|
+
9,
|
|
9530
|
+
7
|
|
9531
|
+
];
|
|
9532
|
+
/**
|
|
9533
|
+
* The phone's side buttons, each from the body's top edge, scaled off the
|
|
9534
|
+
* picked mock: the action button and two volume buttons on the left, and
|
|
9535
|
+
* the side button on the right.
|
|
9536
|
+
*/
|
|
9537
|
+
const PHONE_BUTTONS = [
|
|
9538
|
+
{
|
|
9539
|
+
side: "left",
|
|
9540
|
+
top: 142,
|
|
9541
|
+
height: 33
|
|
9542
|
+
},
|
|
9543
|
+
{
|
|
9544
|
+
side: "left",
|
|
9545
|
+
top: 195,
|
|
9546
|
+
height: 59
|
|
9547
|
+
},
|
|
9548
|
+
{
|
|
9549
|
+
side: "left",
|
|
9550
|
+
top: 266,
|
|
9551
|
+
height: 59
|
|
9552
|
+
},
|
|
9553
|
+
{
|
|
9554
|
+
side: "right",
|
|
9555
|
+
top: 222,
|
|
9556
|
+
height: 95
|
|
9557
|
+
}
|
|
9558
|
+
];
|
|
9559
|
+
/**
|
|
9560
|
+
* The phone's status bar, ending 10 below the island so a page under it
|
|
9561
|
+
* clears the island, its time and marks in the island's band `side` in from
|
|
9562
|
+
* each edge, past the screen's corner arc.
|
|
9563
|
+
*/
|
|
9564
|
+
const STATUS_BAR = {
|
|
9565
|
+
height: PHONE_ISLAND.top + PHONE_ISLAND.height + 10,
|
|
9566
|
+
band: {
|
|
9567
|
+
top: PHONE_ISLAND.top,
|
|
9568
|
+
height: PHONE_ISLAND.height
|
|
9569
|
+
},
|
|
9570
|
+
side: 40,
|
|
9571
|
+
time: "9:41",
|
|
9572
|
+
font: 16
|
|
9573
|
+
};
|
|
9574
|
+
/** The face the status bar and the wide island draw in, a system face every surface holds. */
|
|
9575
|
+
const STATUS_FONT = "system-ui, -apple-system, sans-serif";
|
|
9576
|
+
/** The status bar's signal bars, shortest first, and its battery, each in points. */
|
|
9577
|
+
const SIGNAL_BARS = [
|
|
9578
|
+
4,
|
|
9579
|
+
6.5,
|
|
9580
|
+
9,
|
|
9581
|
+
11.5
|
|
9582
|
+
];
|
|
9583
|
+
const BATTERY = {
|
|
9584
|
+
width: 25,
|
|
9585
|
+
height: 12,
|
|
9586
|
+
radius: 3.5,
|
|
9587
|
+
cap: 2
|
|
9588
|
+
};
|
|
9589
|
+
/** The height the device's status bar takes off the top of a frame's box, 0 for any device but the phone. */
|
|
9590
|
+
function topInset(device) {
|
|
9591
|
+
return device === "phone" ? STATUS_BAR.height : 0;
|
|
9592
|
+
}
|
|
9593
|
+
/**
|
|
9594
|
+
* The page's box inside a frame's box, the box less the status bar while a
|
|
9595
|
+
* phone shows and the box itself on every other device or none. A frame's
|
|
9596
|
+
* box keeps the screen's size, and every surface reads the page through this.
|
|
9597
|
+
*/
|
|
9598
|
+
function pageBox(box, device) {
|
|
9599
|
+
const inset = topInset(device);
|
|
9600
|
+
return {
|
|
9601
|
+
x: box.x,
|
|
9602
|
+
y: box.y + inset,
|
|
9603
|
+
width: box.width,
|
|
9604
|
+
height: Math.max(0, box.height - inset)
|
|
9605
|
+
};
|
|
9606
|
+
}
|
|
9607
|
+
/** The page's corners as a CSS `border-radius`, square on top under a phone's status bar. */
|
|
9608
|
+
function pageCorners(device) {
|
|
9609
|
+
if (device !== "phone") return screenCorners(device);
|
|
9610
|
+
const { screenRadius } = BEZELS.phone;
|
|
9611
|
+
return `0 0 ${screenRadius}px ${screenRadius}px`;
|
|
9612
|
+
}
|
|
9613
|
+
/**
|
|
9614
|
+
* The fill a page shows at its top and its text color, read off its root and
|
|
9615
|
+
* then its body as the browser paints the canvas. Self-contained, so a
|
|
9616
|
+
* browser runs it in the page by its source alone.
|
|
9617
|
+
*/
|
|
9618
|
+
function pageColors(doc = document) {
|
|
9619
|
+
const view = doc.defaultView;
|
|
9620
|
+
const read = (element) => element && view ? view.getComputedStyle(element) : null;
|
|
9621
|
+
const root = read(doc.documentElement);
|
|
9622
|
+
const body = read(doc.body);
|
|
9623
|
+
const painted = (color) => color !== void 0 && color !== "transparent" && !/^rgba\(.*,\s*0\)$/.test(color);
|
|
9624
|
+
return {
|
|
9625
|
+
fill: [root?.backgroundColor, body?.backgroundColor].find(painted) ?? null,
|
|
9626
|
+
ink: body?.color ?? root?.color ?? "CanvasText"
|
|
9627
|
+
};
|
|
9628
|
+
}
|
|
9629
|
+
/** The ways a foldable is held, each a screen the frame's box takes the size of. */
|
|
9630
|
+
const POSES = [
|
|
9631
|
+
"closed",
|
|
9632
|
+
"half",
|
|
9633
|
+
"open"
|
|
9634
|
+
];
|
|
9635
|
+
/**
|
|
9636
|
+
* Each pose's screen in points, the cover display closed and the inner one
|
|
9637
|
+
* half open and open. The published pixel counts at three pixels to a point,
|
|
9638
|
+
* a scale no source states for this device.
|
|
9639
|
+
*/
|
|
9640
|
+
const POSE_SIZES = {
|
|
9641
|
+
closed: {
|
|
9642
|
+
width: 466,
|
|
9643
|
+
height: 678
|
|
9644
|
+
},
|
|
9645
|
+
half: {
|
|
9646
|
+
width: 890,
|
|
9647
|
+
height: 626
|
|
9648
|
+
},
|
|
9649
|
+
open: {
|
|
9650
|
+
width: 890,
|
|
9651
|
+
height: 626
|
|
9652
|
+
}
|
|
9653
|
+
};
|
|
9654
|
+
/** A layout entry's `pose` as a pose, closed for none or a value no reader knows. */
|
|
9655
|
+
function poseOf(value) {
|
|
9656
|
+
return POSES.find((pose) => pose === value) ?? "closed";
|
|
9657
|
+
}
|
|
9658
|
+
/** The pose a frame this wide starts in, closed or open, whichever moves its box least. */
|
|
9659
|
+
function nearestPose(width) {
|
|
9660
|
+
return Math.abs(width - POSE_SIZES.closed.width) <= Math.abs(width - POSE_SIZES.open.width) ? "closed" : "open";
|
|
9661
|
+
}
|
|
9662
|
+
/**
|
|
9663
|
+
* The foldable's island, a generic pill, centered on the cover screen and on
|
|
9664
|
+
* the right half of the inner one, a place no source gives.
|
|
9665
|
+
*/
|
|
9666
|
+
const FOLDABLE_ISLAND = {
|
|
9667
|
+
width: 100,
|
|
9668
|
+
height: 30,
|
|
9669
|
+
top: 14
|
|
9670
|
+
};
|
|
9671
|
+
/** Where the island's center sits across a pose's screen, as a share of its width. */
|
|
9672
|
+
function islandCenter(pose) {
|
|
9673
|
+
return pose === "closed" ? .5 : .75;
|
|
9674
|
+
}
|
|
9675
|
+
/**
|
|
9676
|
+
* The band drawn down the middle of the inner screen, a faint crease open
|
|
9677
|
+
* and a shaded fold half open, null on the cover screen, which has no fold.
|
|
9678
|
+
*/
|
|
9679
|
+
function foldBand(pose) {
|
|
9680
|
+
if (pose === "closed") return null;
|
|
9681
|
+
if (pose === "open") return {
|
|
9682
|
+
width: 26,
|
|
9683
|
+
background: "linear-gradient(90deg, transparent, rgba(0,0,0,.05) 35%, rgba(0,0,0,.11) 50%, rgba(255,255,255,.5) 56%, transparent)"
|
|
9684
|
+
};
|
|
9685
|
+
return {
|
|
9686
|
+
width: 150,
|
|
9687
|
+
background: "linear-gradient(90deg, transparent, rgba(0,0,0,.10) 30%, rgba(0,0,0,.34) 49%, rgba(0,0,0,.34) 51%, rgba(0,0,0,.08) 70%, transparent)"
|
|
9688
|
+
};
|
|
9689
|
+
}
|
|
9690
|
+
/**
|
|
9691
|
+
* The laptop's chin and base, each a box from the frame's top left, which
|
|
9692
|
+
* the board and the PNG draw as positioned boxes, since one spread around
|
|
9693
|
+
* the screen cannot draw a body wider below than above.
|
|
9694
|
+
*/
|
|
9695
|
+
function laptopParts({ width, height }) {
|
|
9696
|
+
const { border } = BEZELS.laptop;
|
|
9697
|
+
const lid = width + 2 * border;
|
|
9698
|
+
const reach = baseReach(width);
|
|
9699
|
+
return {
|
|
9700
|
+
chin: {
|
|
9701
|
+
x: -border,
|
|
9702
|
+
y: height,
|
|
9703
|
+
width: lid,
|
|
9704
|
+
height: LAPTOP_CHIN
|
|
9705
|
+
},
|
|
9706
|
+
base: {
|
|
9707
|
+
x: -border - reach,
|
|
9708
|
+
y: height + LAPTOP_CHIN,
|
|
9709
|
+
width: lid + 2 * reach,
|
|
9710
|
+
height: LAPTOP_BASE.height
|
|
9711
|
+
}
|
|
9712
|
+
};
|
|
9713
|
+
}
|
|
9714
|
+
/** How far a device's parts stand past its body's sides, a laptop's base or a phone's buttons. */
|
|
9715
|
+
function sideReach(device, width) {
|
|
9716
|
+
if (device === "laptop") return baseReach(width);
|
|
9717
|
+
return device === "phone" ? 4 : 0;
|
|
9718
|
+
}
|
|
9719
|
+
function baseReach(width) {
|
|
9720
|
+
return Math.round((width + 2 * BEZELS.laptop.border) * LAPTOP_BASE.reach);
|
|
9721
|
+
}
|
|
9722
|
+
/**
|
|
9723
|
+
* The `box-shadow` drawing a device's body, with a hairline on the board so a
|
|
9724
|
+
* dark body reads on a dark canvas, and no drop shadow in an export.
|
|
9725
|
+
*/
|
|
9726
|
+
function bezelShadow(device, { board = true } = {}) {
|
|
9727
|
+
const { border } = BEZELS[device];
|
|
9728
|
+
if (!board) return [`0 0 0 ${border - 1}px ${BEZEL_COLORS.body}`, `0 0 0 ${border}px ${BEZEL_COLORS.edge}`].join(", ");
|
|
9729
|
+
return [
|
|
9730
|
+
`0 0 0 ${border}px ${BEZEL_COLORS.body}`,
|
|
9731
|
+
`0 0 0 calc(${border}px + 1px / var(--zoom, 1)) ${BEZEL_COLORS.edge}`,
|
|
9732
|
+
`0 ${border}px ${border * 3}px rgba(0, 0, 0, 0.3)`
|
|
9733
|
+
].join(", ");
|
|
9734
|
+
}
|
|
9735
|
+
/**
|
|
9736
|
+
* The box a device's body covers around a frame's box, the box itself with
|
|
9737
|
+
* none. A laptop's base reaches past its lid and a phone's buttons past its
|
|
9738
|
+
* sides, so their sides grow by more than their top.
|
|
9739
|
+
*/
|
|
9740
|
+
function bezelBox(box, device) {
|
|
9741
|
+
if (!device) return { ...box };
|
|
9742
|
+
const { border, bottom } = BEZELS[device];
|
|
9743
|
+
const side = border + sideReach(device, box.width);
|
|
9744
|
+
return {
|
|
9745
|
+
x: box.x - side,
|
|
9746
|
+
y: box.y - border,
|
|
9747
|
+
width: box.width + 2 * side,
|
|
9748
|
+
height: box.height + border + bottom
|
|
9749
|
+
};
|
|
9750
|
+
}
|
|
9481
9751
|
// src/shared/frame-widths.ts
|
|
9482
9752
|
/**
|
|
9483
9753
|
* A layout entry's `widths` as a clean list, anything malformed reading as
|
|
@@ -9809,6 +10079,7 @@ const layoutEntrySchema = looseObject({
|
|
|
9809
10079
|
device: unknown().optional(),
|
|
9810
10080
|
foldable: unknown().optional(),
|
|
9811
10081
|
pose: unknown().optional(),
|
|
10082
|
+
island: unknown().optional(),
|
|
9812
10083
|
transition: unknown().optional(),
|
|
9813
10084
|
speakerNotes: unknown().optional(),
|
|
9814
10085
|
kit: unknown().optional()
|
|
@@ -24463,7 +24734,7 @@ const STEP = /^(?:from|to|\d+(?:\.\d+)?%)(?:\s*,\s*(?:from|to|\d+(?:\.\d+)?%))*$
|
|
|
24463
24734
|
* it in its own document, a value that could load a file included.
|
|
24464
24735
|
*/
|
|
24465
24736
|
function readTransitionSheet(name, css) {
|
|
24466
|
-
if (!isOwnTransitionName(name)) return refused([{
|
|
24737
|
+
if (!isOwnTransitionName(name)) return refused$1([{
|
|
24467
24738
|
message: `${name} is no transition name. Name the file in lowercase kebab case, and not after a built-in transition, none, or page`,
|
|
24468
24739
|
location: null
|
|
24469
24740
|
}]);
|
|
@@ -24473,7 +24744,7 @@ function readTransitionSheet(name, css) {
|
|
|
24473
24744
|
} catch (error) {
|
|
24474
24745
|
if (!(error instanceof CssSyntaxError)) throw error;
|
|
24475
24746
|
const at = offsetOf(css, error.line ?? 1, error.column ?? 1);
|
|
24476
|
-
return refused([{
|
|
24747
|
+
return refused$1([{
|
|
24477
24748
|
message: `The stylesheet does not parse: ${error.reason}`,
|
|
24478
24749
|
location: {
|
|
24479
24750
|
line: error.line ?? 1,
|
|
@@ -24500,7 +24771,7 @@ function readTransitionSheet(name, css) {
|
|
|
24500
24771
|
message: "@keyframes enter is missing",
|
|
24501
24772
|
location: null
|
|
24502
24773
|
});
|
|
24503
|
-
if (!enter || problems.length > 0) return refused(problems);
|
|
24774
|
+
if (!enter || problems.length > 0) return refused$1(problems);
|
|
24504
24775
|
const leave = held.get("leave");
|
|
24505
24776
|
return {
|
|
24506
24777
|
ok: true,
|
|
@@ -24508,7 +24779,7 @@ function readTransitionSheet(name, css) {
|
|
|
24508
24779
|
leave: leave ? bodyOf(leave) : null
|
|
24509
24780
|
};
|
|
24510
24781
|
}
|
|
24511
|
-
function refused(problems) {
|
|
24782
|
+
function refused$1(problems) {
|
|
24512
24783
|
return {
|
|
24513
24784
|
ok: false,
|
|
24514
24785
|
problems
|
|
@@ -24812,6 +25083,7 @@ function placeFrames(frames, names, readTransition = storedTransitionOf) {
|
|
|
24812
25083
|
pose: poseOf(entry.pose)
|
|
24813
25084
|
} : {},
|
|
24814
25085
|
...foldable && kept.length > 0 ? { keptWidths: kept } : {},
|
|
25086
|
+
...islandOf(entry.island) === "wide" ? { island: "wide" } : {},
|
|
24815
25087
|
...transition ? { transition } : {},
|
|
24816
25088
|
...speakerNotes ? { speakerNotes } : {},
|
|
24817
25089
|
...kit ? { kit } : {},
|
|
@@ -25043,7 +25315,7 @@ async function isDirectory(path) {
|
|
|
25043
25315
|
}
|
|
25044
25316
|
}
|
|
25045
25317
|
// package.json
|
|
25046
|
-
var version$1 = "0.
|
|
25318
|
+
var version$1 = "0.44.0";
|
|
25047
25319
|
var dependencies = { "playwright-core": "1.65.0" };
|
|
25048
25320
|
var peerDependencies = { "oxfmt": "0.78.0" };
|
|
25049
25321
|
// src/shared/version.ts
|
|
@@ -25834,18 +26106,24 @@ async function setFrameFlag(root, ref, flag, { on, ...options }) {
|
|
|
25834
26106
|
* it, never writing the frame's file. Naming a foldable shows it and, as a
|
|
25835
26107
|
* pose does, sets the box to that pose's screen, fixed on both axes.
|
|
25836
26108
|
*/
|
|
25837
|
-
async function setFrameDevice(root, ref, show, { foldable: name, pose: fold, ...options }) {
|
|
26109
|
+
async function setFrameDevice(root, ref, show, { foldable: name, pose: fold, island: pick, ...options }) {
|
|
25838
26110
|
return updatePlacement(root, ref, options, (placement, frameRef) => {
|
|
25839
|
-
const { showDevice: held, device: _device, foldable: named, pose: stored, keptWidths, ...rest } = placement;
|
|
26111
|
+
const { showDevice: held, device: _device, foldable: named, pose: stored, keptWidths, island: picked, ...rest } = placement;
|
|
25840
26112
|
const foldable = name ?? named === true;
|
|
25841
26113
|
if (fold && !foldable) throw new FrameboardError("usage", `${frameRef} is not a foldable, so it has no pose. Name it with --foldable first.`, {
|
|
25842
26114
|
ref: frameRef,
|
|
25843
26115
|
pose: fold
|
|
25844
26116
|
});
|
|
26117
|
+
if (pick && (foldable || deviceForWidth(placement.box.width) !== "phone")) throw new FrameboardError("usage", `${frameRef} draws no phone, so it has no island. A frame 320 to 479 px wide that names no foldable draws one.`, {
|
|
26118
|
+
ref: frameRef,
|
|
26119
|
+
island: pick
|
|
26120
|
+
});
|
|
26121
|
+
const island = pick ?? islandOf(picked);
|
|
25845
26122
|
const shown = show ?? (name === true || held === true);
|
|
25846
26123
|
const base = {
|
|
25847
26124
|
...rest,
|
|
25848
|
-
...shown ? { showDevice: true } : {}
|
|
26125
|
+
...shown ? { showDevice: true } : {},
|
|
26126
|
+
...island === "wide" ? { island } : {}
|
|
25849
26127
|
};
|
|
25850
26128
|
if (!foldable) {
|
|
25851
26129
|
const widths = (keptWidths ?? rest.widths).filter((linked) => linked.width !== placement.box.width);
|
|
@@ -26028,7 +26306,7 @@ var PageLayout = class {
|
|
|
26028
26306
|
* Writes the fixed keys after the entry's own, so unknown keys survive, and a
|
|
26029
26307
|
* flag only once on or already held, so an older entry gains no key.
|
|
26030
26308
|
*/
|
|
26031
|
-
set(name, { box, order, hidden, locked, scroll, widths, showDevice, foldable, pose, keptWidths, transition, speakerNotes, kit, hugWidth: hugsWidth, hugHeight: hugsHeight }) {
|
|
26309
|
+
set(name, { box, order, hidden, locked, scroll, widths, showDevice, foldable, pose, keptWidths, island, transition, speakerNotes, kit, hugWidth: hugsWidth, hugHeight: hugsHeight }) {
|
|
26032
26310
|
const hugWidth = hugsWidth && !scroll;
|
|
26033
26311
|
const hugHeight = hugsHeight && !scroll;
|
|
26034
26312
|
const held = this.file.frames[name];
|
|
@@ -26052,6 +26330,7 @@ var PageLayout = class {
|
|
|
26052
26330
|
...showDevice ? { showDevice } : {},
|
|
26053
26331
|
...foldable ? { foldable } : {},
|
|
26054
26332
|
...foldable && pose && (held?.foldable !== true || poseOf(held.pose) !== pose) ? { pose } : {},
|
|
26333
|
+
...island ? { island } : {},
|
|
26055
26334
|
...transition ? { transition: { ...transition } } : {},
|
|
26056
26335
|
...speakerNotes ? { speakerNotes } : {},
|
|
26057
26336
|
...kit ? { kit } : {}
|
|
@@ -26062,6 +26341,7 @@ var PageLayout = class {
|
|
|
26062
26341
|
delete entry.pose;
|
|
26063
26342
|
}
|
|
26064
26343
|
if (!showDevice && held?.showDevice === true) delete entry.showDevice;
|
|
26344
|
+
if (!island && islandOf(held?.island) === "wide") delete entry.island;
|
|
26065
26345
|
if (typeof held?.device === "string") delete entry.device;
|
|
26066
26346
|
if (!transition && storedTransitionOf(held?.transition)) delete entry.transition;
|
|
26067
26347
|
if (!speakerNotes && speakerNotesOf(held?.speakerNotes)) delete entry.speakerNotes;
|
|
@@ -30834,6 +31114,293 @@ const bodyLimit = (options) => {
|
|
|
30834
31114
|
return next();
|
|
30835
31115
|
};
|
|
30836
31116
|
};
|
|
31117
|
+
// src/server/checks/links.ts
|
|
31118
|
+
const LINK_RULES = [
|
|
31119
|
+
{
|
|
31120
|
+
id: "outside-link",
|
|
31121
|
+
tier: "exact",
|
|
31122
|
+
severity: "error",
|
|
31123
|
+
description: "A frame loads files from its own page folder and its project's assets/ folder alone, never from a sibling page or the server root"
|
|
31124
|
+
},
|
|
31125
|
+
{
|
|
31126
|
+
id: "network",
|
|
31127
|
+
tier: "exact",
|
|
31128
|
+
severity: "error",
|
|
31129
|
+
description: "A frame loads nothing over the network, while a navigation link passes"
|
|
31130
|
+
},
|
|
31131
|
+
{
|
|
31132
|
+
id: "missing-file",
|
|
31133
|
+
tier: "exact",
|
|
31134
|
+
severity: "error",
|
|
31135
|
+
description: "Every local file a frame loads exists"
|
|
31136
|
+
}
|
|
31137
|
+
];
|
|
31138
|
+
const finding$12 = findingFor(LINK_RULES);
|
|
31139
|
+
/** The attributes a `<model-viewer>` loads a file through, which `docs` states beside the rule. */
|
|
31140
|
+
const MODEL_LOADS = [
|
|
31141
|
+
"src",
|
|
31142
|
+
"poster",
|
|
31143
|
+
"environment-image",
|
|
31144
|
+
"skybox-image"
|
|
31145
|
+
];
|
|
31146
|
+
/**
|
|
31147
|
+
* The attributes that load a resource, by element. An `a href` navigates
|
|
31148
|
+
* rather than loads, so it is left out.
|
|
31149
|
+
*/
|
|
31150
|
+
const RESOURCE_ATTRIBUTES = {
|
|
31151
|
+
link: ["href"],
|
|
31152
|
+
script: ["src"],
|
|
31153
|
+
img: ["src", "srcset"],
|
|
31154
|
+
source: ["src", "srcset"],
|
|
31155
|
+
video: ["src", "poster"],
|
|
31156
|
+
audio: ["src"],
|
|
31157
|
+
track: ["src"],
|
|
31158
|
+
iframe: ["src"],
|
|
31159
|
+
embed: ["src"],
|
|
31160
|
+
object: ["data"],
|
|
31161
|
+
input: ["src"],
|
|
31162
|
+
image: ["href", "xlink:href"],
|
|
31163
|
+
use: ["href", "xlink:href"],
|
|
31164
|
+
"model-viewer": [...MODEL_LOADS]
|
|
31165
|
+
};
|
|
31166
|
+
/** The lighting a viewer builds itself, which `environment-image` names in place of a file. */
|
|
31167
|
+
const BUILT_IN_ENVIRONMENTS = /* @__PURE__ */ new Set(["neutral", "legacy"]);
|
|
31168
|
+
/** `outside-link`, `network`, and `missing-file` over every load a frame makes. */
|
|
31169
|
+
function checkLinks(source) {
|
|
31170
|
+
return frameLoads(source).flatMap((load) => judge(source, load));
|
|
31171
|
+
}
|
|
31172
|
+
/**
|
|
31173
|
+
* Every resource a frame loads, from its elements' attributes and inline
|
|
31174
|
+
* styles and from each sheet it renders with, unjudged. The link check and the
|
|
31175
|
+
* asset usage count read this one list, so they never disagree on a load.
|
|
31176
|
+
*/
|
|
31177
|
+
function frameLoads(source) {
|
|
31178
|
+
const framePath = boardPath(source.root, source.path);
|
|
31179
|
+
const loads = [];
|
|
31180
|
+
for (const element of source.elements) {
|
|
31181
|
+
for (const name of RESOURCE_ATTRIBUTES[element.name] ?? []) {
|
|
31182
|
+
const value = element.attribs[name];
|
|
31183
|
+
if (value === void 0) continue;
|
|
31184
|
+
if (name === "environment-image" && BUILT_IN_ENVIRONMENTS.has(value)) continue;
|
|
31185
|
+
const urls = name === "srcset" ? srcsetUrls(value) : [value];
|
|
31186
|
+
for (const url of urls) loads.push({
|
|
31187
|
+
url,
|
|
31188
|
+
base: source.pageDir,
|
|
31189
|
+
path: framePath,
|
|
31190
|
+
location: attributeLocation(element, name),
|
|
31191
|
+
via: `<${element.name} ${name}>`
|
|
31192
|
+
});
|
|
31193
|
+
}
|
|
31194
|
+
const style = element.attribs.style;
|
|
31195
|
+
if (style !== void 0) for (const { url } of cssUrls(`x{${style}}`)) loads.push({
|
|
31196
|
+
url,
|
|
31197
|
+
base: source.pageDir,
|
|
31198
|
+
path: framePath,
|
|
31199
|
+
location: attributeLocation(element, "style"),
|
|
31200
|
+
via: `a style attribute's url()`
|
|
31201
|
+
});
|
|
31202
|
+
}
|
|
31203
|
+
for (const sheet of source.sheets) loads.push(...sheetLoads(source, sheet));
|
|
31204
|
+
return loads;
|
|
31205
|
+
}
|
|
31206
|
+
function sheetLoads(source, sheet) {
|
|
31207
|
+
const path = boardPath(source.root, sheet.path);
|
|
31208
|
+
const text = sheet.origin === "style" ? source.html : sheet.css;
|
|
31209
|
+
return cssUrls(sheet.css).map(({ url, start, end, kind }) => ({
|
|
31210
|
+
url,
|
|
31211
|
+
base: sheetBase(sheet),
|
|
31212
|
+
path,
|
|
31213
|
+
location: locate$1(text, sheet.offset + start, sheet.offset + end),
|
|
31214
|
+
via: kind === "import" ? "@import" : "url()"
|
|
31215
|
+
}));
|
|
31216
|
+
}
|
|
31217
|
+
function judge(source, load) {
|
|
31218
|
+
const url = load.url.trim();
|
|
31219
|
+
if (url === "" || url.startsWith("#") || /^(data|blob|about):/i.test(url)) return [];
|
|
31220
|
+
const fields = {
|
|
31221
|
+
frame: source.ref,
|
|
31222
|
+
path: load.path,
|
|
31223
|
+
location: load.location
|
|
31224
|
+
};
|
|
31225
|
+
if (hasScheme(url)) return [finding$12("network", {
|
|
31226
|
+
...fields,
|
|
31227
|
+
message: `${load.via} loads ${url} over the network. Save the file into the page folder or the project's assets/ and link it there.`
|
|
31228
|
+
})];
|
|
31229
|
+
const target = localTarget(url, load.base);
|
|
31230
|
+
if (target === null || !allowed(source, target)) return [finding$12("outside-link", {
|
|
31231
|
+
...fields,
|
|
31232
|
+
message: `${load.via} loads ${url}, outside this page's folder and the project's assets/. Move the file into one of them.`
|
|
31233
|
+
})];
|
|
31234
|
+
if (!existsSync(target)) return [finding$12("missing-file", {
|
|
31235
|
+
...fields,
|
|
31236
|
+
message: `${load.via} loads ${url}, which does not exist.`
|
|
31237
|
+
})];
|
|
31238
|
+
return [];
|
|
31239
|
+
}
|
|
31240
|
+
/**
|
|
31241
|
+
* Inside the page folder or the project's `assets/`, both by path and, for a
|
|
31242
|
+
* file that exists, by realpath, so a symlink out of the project is caught.
|
|
31243
|
+
*/
|
|
31244
|
+
function allowed(source, target) {
|
|
31245
|
+
const assets = assetsDirOf(source);
|
|
31246
|
+
if (!isInside(source.pageDir, target) && !isInside(assets, target)) return false;
|
|
31247
|
+
if (!existsSync(target)) return true;
|
|
31248
|
+
const real = realpathSync(target);
|
|
31249
|
+
const projectDir = realpathSync(source.projectDir);
|
|
31250
|
+
return isInside(realpathSync(source.pageDir), real) || isInside(join(projectDir, "assets"), real);
|
|
31251
|
+
}
|
|
31252
|
+
function srcsetUrls(value) {
|
|
31253
|
+
return value.split(",").map((candidate) => candidate.trim().split(/\s+/)[0] ?? "").filter((url) => url !== "");
|
|
31254
|
+
}
|
|
31255
|
+
/** Every `url()` and `@import` in a sheet. A sheet that does not parse loads nothing. */
|
|
31256
|
+
function cssUrls(css) {
|
|
31257
|
+
const urls = [];
|
|
31258
|
+
let root;
|
|
31259
|
+
try {
|
|
31260
|
+
root = postcss_default.parse(css);
|
|
31261
|
+
} catch {
|
|
31262
|
+
return urls;
|
|
31263
|
+
}
|
|
31264
|
+
root.walk((node) => {
|
|
31265
|
+
const start = node.source?.start?.offset ?? 0;
|
|
31266
|
+
const end = node.source?.end?.offset ?? start;
|
|
31267
|
+
if (node.type === "atrule" && node.name.toLowerCase() === "import") {
|
|
31268
|
+
const url = importUrl(node.params);
|
|
31269
|
+
if (url !== null) urls.push({
|
|
31270
|
+
url,
|
|
31271
|
+
start,
|
|
31272
|
+
end,
|
|
31273
|
+
kind: "import"
|
|
31274
|
+
});
|
|
31275
|
+
} else if (node.type === "decl") for (const match of node.value.matchAll(/url\(\s*(['"]?)(.*?)\1\s*\)/gi)) urls.push({
|
|
31276
|
+
url: match[2] ?? "",
|
|
31277
|
+
start,
|
|
31278
|
+
end,
|
|
31279
|
+
kind: "url"
|
|
31280
|
+
});
|
|
31281
|
+
});
|
|
31282
|
+
return urls;
|
|
31283
|
+
}
|
|
31284
|
+
// src/server/board/asset-usage.ts
|
|
31285
|
+
/**
|
|
31286
|
+
* A per-project cache of how many frames link each asset, counted from the
|
|
31287
|
+
* same loads the link check judges. A frame counts once per file, and only a
|
|
31288
|
+
* link resolving inside the project's `assets/` counts.
|
|
31289
|
+
*/
|
|
31290
|
+
function createAssetUsage(root) {
|
|
31291
|
+
const cache = /* @__PURE__ */ new Map();
|
|
31292
|
+
return {
|
|
31293
|
+
counts: (project) => {
|
|
31294
|
+
const cached = cache.get(project);
|
|
31295
|
+
if (cached) return cached;
|
|
31296
|
+
const built = countProject(root, project);
|
|
31297
|
+
cache.set(project, built);
|
|
31298
|
+
built.catch(() => {
|
|
31299
|
+
if (cache.get(project) === built) cache.delete(project);
|
|
31300
|
+
});
|
|
31301
|
+
return built;
|
|
31302
|
+
},
|
|
31303
|
+
drop: (paths) => {
|
|
31304
|
+
for (const path of paths) {
|
|
31305
|
+
const inside = relative(root, path);
|
|
31306
|
+
if (inside === "") {
|
|
31307
|
+
cache.clear();
|
|
31308
|
+
return;
|
|
31309
|
+
}
|
|
31310
|
+
if (inside.startsWith("..")) continue;
|
|
31311
|
+
const project = inside.split(sep)[0];
|
|
31312
|
+
if (project) cache.delete(project);
|
|
31313
|
+
}
|
|
31314
|
+
}
|
|
31315
|
+
};
|
|
31316
|
+
}
|
|
31317
|
+
async function countProject(root, project) {
|
|
31318
|
+
const projectDir = join(root, project);
|
|
31319
|
+
const counts = /* @__PURE__ */ new Map();
|
|
31320
|
+
for (const page of await listPageFolders(projectDir)) for (const name of await listFrames(join(projectDir, page))) for (const path of linkedAssets(root, project, page, name)) counts.set(path, (counts.get(path) ?? 0) + 1);
|
|
31321
|
+
return counts;
|
|
31322
|
+
}
|
|
31323
|
+
/**
|
|
31324
|
+
* The asset paths one frame links, each once, read from its file as it stands
|
|
31325
|
+
* rather than from a cached count. A frame gone between the listing and the
|
|
31326
|
+
* read links none.
|
|
31327
|
+
*/
|
|
31328
|
+
function linkedAssets(root, project, page, name) {
|
|
31329
|
+
const linked = /* @__PURE__ */ new Set();
|
|
31330
|
+
let source;
|
|
31331
|
+
try {
|
|
31332
|
+
source = readFrame$1({
|
|
31333
|
+
root,
|
|
31334
|
+
project,
|
|
31335
|
+
page,
|
|
31336
|
+
name
|
|
31337
|
+
});
|
|
31338
|
+
} catch {
|
|
31339
|
+
return linked;
|
|
31340
|
+
}
|
|
31341
|
+
const assets = assetsDirOf(source);
|
|
31342
|
+
for (const load of frameLoads(source)) {
|
|
31343
|
+
const target = localTarget(load.url, load.base);
|
|
31344
|
+
if (target === null || target === assets || !isInside(assets, target)) continue;
|
|
31345
|
+
linked.add(relative(assets, target).split(sep).join("/"));
|
|
31346
|
+
}
|
|
31347
|
+
return linked;
|
|
31348
|
+
}
|
|
31349
|
+
// src/server/board/asset-links.ts
|
|
31350
|
+
/** Every frame in the project linking the file at `path` under its `assets/`. */
|
|
31351
|
+
async function framesLinking(root, project, path) {
|
|
31352
|
+
const projectDir = join(root, project);
|
|
31353
|
+
const frames = [];
|
|
31354
|
+
for (const page of await listPageFolders(projectDir)) for (const name of await listFrames(join(projectDir, page))) if (linkedAssets(root, project, page, name).has(path)) frames.push({
|
|
31355
|
+
root,
|
|
31356
|
+
project,
|
|
31357
|
+
page,
|
|
31358
|
+
name
|
|
31359
|
+
});
|
|
31360
|
+
return frames;
|
|
31361
|
+
}
|
|
31362
|
+
/**
|
|
31363
|
+
* The frame's markup with each load of `from` pointed at `to`, or null when no load in its own file names it.
|
|
31364
|
+
* A linked sheet's load, or a URL written through an entity or escape, stays for the link check to report.
|
|
31365
|
+
*/
|
|
31366
|
+
function rewriteAssetLinks(source, from, to) {
|
|
31367
|
+
const framePath = boardPath(source.root, source.path);
|
|
31368
|
+
const edits = /* @__PURE__ */ new Map();
|
|
31369
|
+
for (const load of frameLoads(source)) {
|
|
31370
|
+
if (load.path !== framePath || load.location === null) continue;
|
|
31371
|
+
if (localTarget(load.url, load.base) !== from) continue;
|
|
31372
|
+
const { startOffset: start, endOffset: end } = load.location;
|
|
31373
|
+
edits.set(`${start}:${end}:${load.url}`, {
|
|
31374
|
+
start,
|
|
31375
|
+
end,
|
|
31376
|
+
url: load.url
|
|
31377
|
+
});
|
|
31378
|
+
}
|
|
31379
|
+
let html = source.html;
|
|
31380
|
+
let changed = false;
|
|
31381
|
+
const ordered = [...edits.values()].sort((a, b) => b.start - a.start);
|
|
31382
|
+
for (const { start, end, url } of ordered) {
|
|
31383
|
+
const written = html.slice(start, end).replace(urlPattern(url), (_, lead) => {
|
|
31384
|
+
changed = true;
|
|
31385
|
+
return `${lead}${renamedUrl(url, basename(to))}`;
|
|
31386
|
+
});
|
|
31387
|
+
html = html.slice(0, start) + written + html.slice(end);
|
|
31388
|
+
}
|
|
31389
|
+
return changed ? html : null;
|
|
31390
|
+
}
|
|
31391
|
+
/** The URL as a whole token, so `a.jpg` never matches inside `a.jpg-2.jpg`. */
|
|
31392
|
+
function urlPattern(url) {
|
|
31393
|
+
const escaped = url.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
31394
|
+
return new RegExp(`(^|["'(\\s,=])${escaped}(?=$|["')\\s,])`, "g");
|
|
31395
|
+
}
|
|
31396
|
+
/** The URL with its last path segment swapped for `name`, keeping its query and fragment. */
|
|
31397
|
+
function renamedUrl(url, name) {
|
|
31398
|
+
const cut = url.search(/[?#]/);
|
|
31399
|
+
const path = cut === -1 ? url : url.slice(0, cut);
|
|
31400
|
+
const rest = cut === -1 ? "" : url.slice(cut);
|
|
31401
|
+
const slash = path.lastIndexOf("/");
|
|
31402
|
+
return `${path.slice(0, slash + 1)}${encodeURIComponent(name)}${rest}`;
|
|
31403
|
+
}
|
|
30837
31404
|
// src/shared/asset-kinds.ts
|
|
30838
31405
|
const ASSET_KINDS = [
|
|
30839
31406
|
"image",
|
|
@@ -30938,8 +31505,51 @@ const imageFindSchema = object$1({
|
|
|
30938
31505
|
licenses: array$1(string$1()),
|
|
30939
31506
|
results: array$1(imageResultSchema)
|
|
30940
31507
|
});
|
|
30941
|
-
/** The
|
|
30942
|
-
const
|
|
31508
|
+
/** The texture sizes Poly Haven serves a model at, smallest first. */
|
|
31509
|
+
const MODEL_SIZES = [
|
|
31510
|
+
"1k",
|
|
31511
|
+
"2k",
|
|
31512
|
+
"4k",
|
|
31513
|
+
"8k",
|
|
31514
|
+
"16k"
|
|
31515
|
+
];
|
|
31516
|
+
/** One Poly Haven model a search found, numbered from 1 in the order the ranking put it. */
|
|
31517
|
+
const modelResultSchema = object$1({
|
|
31518
|
+
number: int$1().min(1),
|
|
31519
|
+
/** Poly Haven's own id, which `--save` takes in place of the number. */
|
|
31520
|
+
id: string$1(),
|
|
31521
|
+
name: string$1(),
|
|
31522
|
+
authors: array$1(string$1()),
|
|
31523
|
+
categories: array$1(string$1()),
|
|
31524
|
+
tags: array$1(string$1()),
|
|
31525
|
+
license: literal("cc0"),
|
|
31526
|
+
/** The model's page on polyhaven.com. */
|
|
31527
|
+
landingUrl: string$1(),
|
|
31528
|
+
thumbnail: string$1().nullable(),
|
|
31529
|
+
polycount: int$1().nullable(),
|
|
31530
|
+
/** Poly Haven's x, y, and z extent in millimetres, z pointing up. */
|
|
31531
|
+
dimensionsMm: tuple([
|
|
31532
|
+
number(),
|
|
31533
|
+
number(),
|
|
31534
|
+
number()
|
|
31535
|
+
]).nullable(),
|
|
31536
|
+
/** The texture sizes `--size` may ask for, smallest first. */
|
|
31537
|
+
sizes: array$1(_enum$1(MODEL_SIZES)),
|
|
31538
|
+
downloadCount: int$1().nullable()
|
|
31539
|
+
});
|
|
31540
|
+
/** What `model find` answers without `--save`, writing nothing. */
|
|
31541
|
+
const modelFindSchema = object$1({
|
|
31542
|
+
version: literal(1),
|
|
31543
|
+
query: string$1(),
|
|
31544
|
+
/** Who serves the results, which every surface listing them names. */
|
|
31545
|
+
source: object$1({
|
|
31546
|
+
name: literal("Poly Haven"),
|
|
31547
|
+
url: string$1()
|
|
31548
|
+
}),
|
|
31549
|
+
results: array$1(modelResultSchema)
|
|
31550
|
+
});
|
|
31551
|
+
/** The `<file>.license.json` beside every saved image or model, saying where it came from. */
|
|
31552
|
+
const licenseFileSchema = discriminatedUnion("origin", [discriminatedUnion("source", [object$1({
|
|
30943
31553
|
version: literal(1),
|
|
30944
31554
|
origin: literal("found"),
|
|
30945
31555
|
source: literal("openverse"),
|
|
@@ -30958,6 +31568,23 @@ const licenseFileSchema = discriminatedUnion("origin", [object$1({
|
|
|
30958
31568
|
/** ISO 8601. */
|
|
30959
31569
|
savedAt: string$1()
|
|
30960
31570
|
}), object$1({
|
|
31571
|
+
version: literal(1),
|
|
31572
|
+
origin: literal("found"),
|
|
31573
|
+
source: literal("polyhaven"),
|
|
31574
|
+
id: string$1(),
|
|
31575
|
+
/** The search that found it, null when it was saved by id. */
|
|
31576
|
+
query: string$1().nullable(),
|
|
31577
|
+
title: string$1(),
|
|
31578
|
+
/** Recorded though CC0 asks no credit, since where a file came from outlives that question. */
|
|
31579
|
+
authors: array$1(string$1()),
|
|
31580
|
+
license: literal("cc0"),
|
|
31581
|
+
licenseUrl: string$1(),
|
|
31582
|
+
landingUrl: string$1(),
|
|
31583
|
+
/** The glTF the GLB was packed from. */
|
|
31584
|
+
url: string$1(),
|
|
31585
|
+
size: _enum$1(MODEL_SIZES),
|
|
31586
|
+
savedAt: string$1()
|
|
31587
|
+
})]), object$1({
|
|
30961
31588
|
version: literal(1),
|
|
30962
31589
|
origin: literal("generated"),
|
|
30963
31590
|
provider: _enum$1(IMAGE_PROVIDERS),
|
|
@@ -30978,6 +31605,8 @@ const savedImageSchema = object$1({
|
|
|
30978
31605
|
licensePath: string$1(),
|
|
30979
31606
|
license: licenseFileSchema
|
|
30980
31607
|
});
|
|
31608
|
+
/** A model saved into a project's `assets/` as one `.glb`, with the license file written beside it. */
|
|
31609
|
+
const savedModelSchema = savedImageSchema;
|
|
30981
31610
|
/** What `image generate` answers, with `saved` null on a dry run. */
|
|
30982
31611
|
const imageGenerateSchema = object$1({
|
|
30983
31612
|
version: literal(1),
|
|
@@ -31090,22 +31719,11 @@ async function walk(folder, prefix, real, into) {
|
|
|
31090
31719
|
* folder reads `asset-missing` and an unshowable file `asset-not-placeable`.
|
|
31091
31720
|
*/
|
|
31092
31721
|
async function resolveAsset(projectDir, path) {
|
|
31093
|
-
|
|
31722
|
+
if (await confinedAsset(projectDir, path) === null) return {
|
|
31094
31723
|
ok: false,
|
|
31095
31724
|
code: "asset-missing",
|
|
31096
31725
|
message: `assets/${path} is not a file in the project's assets folder`
|
|
31097
31726
|
};
|
|
31098
|
-
const segments = path.split("/");
|
|
31099
|
-
if (segments.some((segment) => segment === "" || segment.startsWith(".") || isScratch(segment))) return missing;
|
|
31100
|
-
const folder = join(projectDir, ASSETS_FOLDER);
|
|
31101
|
-
try {
|
|
31102
|
-
const real = await realpath(folder);
|
|
31103
|
-
const target = await realpath(join(folder, ...segments));
|
|
31104
|
-
if (!target.startsWith(real + sep) || !(await stat(target)).isFile()) return missing;
|
|
31105
|
-
} catch (error) {
|
|
31106
|
-
if (isCode(error, "ENOENT") || isCode(error, "ENOTDIR")) return missing;
|
|
31107
|
-
throw error;
|
|
31108
|
-
}
|
|
31109
31727
|
const kind = assetKind(path);
|
|
31110
31728
|
if (!isPlaceableKind(kind)) return {
|
|
31111
31729
|
ok: false,
|
|
@@ -31117,10 +31735,165 @@ async function resolveAsset(projectDir, path) {
|
|
|
31117
31735
|
kind
|
|
31118
31736
|
};
|
|
31119
31737
|
}
|
|
31738
|
+
/**
|
|
31739
|
+
* The absolute path of a file under the project's `assets/`, or null for a
|
|
31740
|
+
* path naming a dot, lock, or temp segment, or whose real path leaves the
|
|
31741
|
+
* folder or is not a file.
|
|
31742
|
+
*/
|
|
31743
|
+
async function confinedAsset(projectDir, path) {
|
|
31744
|
+
const segments = path.split("/");
|
|
31745
|
+
if (segments.some((segment) => segment === "" || segment.startsWith(".") || isScratch(segment))) return null;
|
|
31746
|
+
const folder = join(projectDir, ASSETS_FOLDER);
|
|
31747
|
+
const file = join(folder, ...segments);
|
|
31748
|
+
try {
|
|
31749
|
+
const real = await realpath(folder);
|
|
31750
|
+
const target = await realpath(file);
|
|
31751
|
+
if (!target.startsWith(real + sep) || !(await stat(target)).isFile()) return null;
|
|
31752
|
+
} catch (error) {
|
|
31753
|
+
if (isCode(error, "ENOENT") || isCode(error, "ENOTDIR")) return null;
|
|
31754
|
+
throw error;
|
|
31755
|
+
}
|
|
31756
|
+
return file;
|
|
31757
|
+
}
|
|
31758
|
+
/**
|
|
31759
|
+
* A file a hand write may change, refusing `asset-not-found` for one
|
|
31760
|
+
* `confinedAsset` refuses, a license file, or a kit's file, which the Theme
|
|
31761
|
+
* tab owns.
|
|
31762
|
+
*/
|
|
31763
|
+
async function writableAsset(projectDir, path) {
|
|
31764
|
+
const file = path.split("/")[0] === "kits" || path.endsWith(".license.json") ? null : await confinedAsset(projectDir, path);
|
|
31765
|
+
if (file === null) throw new FrameboardError("asset-not-found", `assets/${path} is not a file in the project's assets folder.`, { path });
|
|
31766
|
+
return file;
|
|
31767
|
+
}
|
|
31768
|
+
/** The license file beside an asset, when it has one. */
|
|
31769
|
+
function licenseOf(file) {
|
|
31770
|
+
const license = `${file}${LICENSE_FILE_SUFFIX}`;
|
|
31771
|
+
return existsSync(license) ? license : null;
|
|
31772
|
+
}
|
|
31773
|
+
/**
|
|
31774
|
+
* Deletes an asset and its license file, each taken out through the journal
|
|
31775
|
+
* where one is given, so an undo brings both back.
|
|
31776
|
+
*/
|
|
31777
|
+
async function removeAsset(projectDir, path, { journal } = {}) {
|
|
31778
|
+
const file = await writableAsset(projectDir, path);
|
|
31779
|
+
for (const each of [file, licenseOf(file)]) {
|
|
31780
|
+
if (each === null) continue;
|
|
31781
|
+
if (journal) await journal.removed(each);
|
|
31782
|
+
else await rm(each);
|
|
31783
|
+
}
|
|
31784
|
+
return {
|
|
31785
|
+
path,
|
|
31786
|
+
frames: []
|
|
31787
|
+
};
|
|
31788
|
+
}
|
|
31120
31789
|
function isScratch(name) {
|
|
31121
31790
|
return name.endsWith(".lock") || name.endsWith(".tmp");
|
|
31122
31791
|
}
|
|
31123
31792
|
/**
|
|
31793
|
+
* Writes an upload's bytes under an asset's path and takes its license out, since it named the old bytes.
|
|
31794
|
+
* Refuses `asset-type-refused` for an upload a drop refuses or of another kind, which frames would change under.
|
|
31795
|
+
*/
|
|
31796
|
+
async function replaceAsset(projectDir, path, upload, { journal } = {}) {
|
|
31797
|
+
const file = await writableAsset(projectDir, path);
|
|
31798
|
+
const refusal = uploadRefusal(upload) ?? (assetKind(upload.name) === assetKind(path) ? null : `${upload.name} is not the same kind of file as ${path}, so it cannot replace it.`);
|
|
31799
|
+
if (refusal !== null) throw new FrameboardError("asset-type-refused", refusal, { path });
|
|
31800
|
+
const temp = join(dirname(file), `${randomBytes(6).toString("hex")}${TEMP_SUFFIX}`);
|
|
31801
|
+
await writeFile(temp, upload.bytes, { flag: "wx" });
|
|
31802
|
+
try {
|
|
31803
|
+
const license = licenseOf(file);
|
|
31804
|
+
if (journal) {
|
|
31805
|
+
await journal.replaced(file, temp);
|
|
31806
|
+
if (license !== null) await journal.removed(license);
|
|
31807
|
+
} else {
|
|
31808
|
+
await rename(temp, file);
|
|
31809
|
+
if (license !== null) await rm(license);
|
|
31810
|
+
}
|
|
31811
|
+
} finally {
|
|
31812
|
+
await rm(temp, { force: true });
|
|
31813
|
+
}
|
|
31814
|
+
return {
|
|
31815
|
+
path,
|
|
31816
|
+
frames: []
|
|
31817
|
+
};
|
|
31818
|
+
}
|
|
31819
|
+
/**
|
|
31820
|
+
* Renames an asset and its license and repoints every linking frame, writing nothing until the gate passes,
|
|
31821
|
+
* and puts written frames back when a later write fails, so no project is left half renamed.
|
|
31822
|
+
* Refuses `invalid-name` off the name rule or for a new extension, and `name-taken` for a name held in any case.
|
|
31823
|
+
*/
|
|
31824
|
+
async function renameAsset(root, project, path, name, { journal, gate = async () => {} } = {}) {
|
|
31825
|
+
const file = await writableAsset(join(root, project), path);
|
|
31826
|
+
const folder = dirname(file);
|
|
31827
|
+
const from = basename(file);
|
|
31828
|
+
const renamed = [...path.split("/").slice(0, -1), name].join("/");
|
|
31829
|
+
if (name === from) return {
|
|
31830
|
+
path,
|
|
31831
|
+
frames: []
|
|
31832
|
+
};
|
|
31833
|
+
if (!isValidName(name) || isScratch(name) || name.endsWith(".license.json") || extensionOf(name) !== extensionOf(from)) throw new FrameboardError("invalid-name", `${name} is not a name ${from} can take. Use letters, digits, dots, dashes, and underscores, keep the .${extensionOf(from)} ending, and stay within 64 characters.`, {
|
|
31834
|
+
path,
|
|
31835
|
+
name
|
|
31836
|
+
});
|
|
31837
|
+
const taken = (await readdir(folder)).find((entry) => entry !== from && entry !== `${from}.license.json` && (namesCollide(entry, name) || namesCollide(entry, `${name}.license.json`)));
|
|
31838
|
+
if (taken !== void 0) throw new FrameboardError("name-taken", `assets/${[...path.split("/").slice(0, -1), taken].join("/")} already exists. Pick another name.`, {
|
|
31839
|
+
path,
|
|
31840
|
+
name
|
|
31841
|
+
});
|
|
31842
|
+
const frames = await framesLinking(root, project, path);
|
|
31843
|
+
const ref = ({ page, name: frame }) => `${project}/${page}/${frame}`;
|
|
31844
|
+
await gate(frames.map(ref));
|
|
31845
|
+
const target = join(folder, name);
|
|
31846
|
+
const rewrites = frames.flatMap((frame) => {
|
|
31847
|
+
const source = readFrame$1(frame);
|
|
31848
|
+
if (!Buffer.from(source.html, "utf8").equals(readFileSync(source.path))) throw new FrameboardError("invalid-utf8", `${ref(frame)} is not UTF-8, so the rename cannot point its links at ${name}. Nothing was renamed.`, { frame: ref(frame) });
|
|
31849
|
+
const after = rewriteAssetLinks(source, file, target);
|
|
31850
|
+
return after === null ? [] : [{
|
|
31851
|
+
path: source.path,
|
|
31852
|
+
ref: ref(frame),
|
|
31853
|
+
before: source.html,
|
|
31854
|
+
after
|
|
31855
|
+
}];
|
|
31856
|
+
});
|
|
31857
|
+
const written = [];
|
|
31858
|
+
const license = licenseOf(file);
|
|
31859
|
+
try {
|
|
31860
|
+
for (const rewrite of rewrites) {
|
|
31861
|
+
await writeFrameWhole(rewrite.path, rewrite.before, rewrite.after);
|
|
31862
|
+
written.push(rewrite);
|
|
31863
|
+
}
|
|
31864
|
+
if (journal) {
|
|
31865
|
+
for (const each of written) journal.rewritten(each.path, each.ref, each.before, each.after);
|
|
31866
|
+
await journal.moved(file, target);
|
|
31867
|
+
if (license !== null) await journal.moved(license, `${target}${LICENSE_FILE_SUFFIX}`);
|
|
31868
|
+
} else {
|
|
31869
|
+
await rename(file, target);
|
|
31870
|
+
if (license !== null) await rename(license, `${target}${LICENSE_FILE_SUFFIX}`);
|
|
31871
|
+
}
|
|
31872
|
+
} catch (error) {
|
|
31873
|
+
for (const each of written.toReversed()) await writeFrameWhole(each.path, each.after, each.before).catch(() => {});
|
|
31874
|
+
throw error;
|
|
31875
|
+
}
|
|
31876
|
+
return {
|
|
31877
|
+
path: renamed,
|
|
31878
|
+
frames: written.map((each) => each.ref)
|
|
31879
|
+
};
|
|
31880
|
+
}
|
|
31881
|
+
/**
|
|
31882
|
+
* Writes a frame file whole through a temp file, refusing with
|
|
31883
|
+
* `stale-address` when the file no longer holds `before`, so an agent's
|
|
31884
|
+
* write that landed since is never overwritten.
|
|
31885
|
+
*/
|
|
31886
|
+
async function writeFrameWhole(path, before, after) {
|
|
31887
|
+
const temp = join(dirname(path), `.${basename(path)}.${randomBytes(6).toString("hex")}${TEMP_SUFFIX}`);
|
|
31888
|
+
await writeFile(temp, after);
|
|
31889
|
+
try {
|
|
31890
|
+
if (await readFile(path, "utf8") !== before) throw new FrameboardError("stale-address", `An agent changed ${basename(path)} while the rename read it, so nothing was renamed. Try again.`, { path });
|
|
31891
|
+
await rename(temp, path);
|
|
31892
|
+
} finally {
|
|
31893
|
+
await rm(temp, { force: true });
|
|
31894
|
+
}
|
|
31895
|
+
}
|
|
31896
|
+
/**
|
|
31124
31897
|
* Writes each upload under the first free name, hard-linking a temp file so a
|
|
31125
31898
|
* name an agent took in between is never overwritten.
|
|
31126
31899
|
*/
|
|
@@ -31217,17 +31990,609 @@ function splitName(name) {
|
|
|
31217
31990
|
extension
|
|
31218
31991
|
};
|
|
31219
31992
|
}
|
|
31993
|
+
/** The files in a project's `assets/` by path, empty when the folder is missing. */
|
|
31994
|
+
const assetListSchema = object$1({ files: array$1(object$1({
|
|
31995
|
+
/** Relative to the project's `assets/`, with `/` between segments. */
|
|
31996
|
+
path: string$1(),
|
|
31997
|
+
kind: _enum$1(ASSET_KINDS),
|
|
31998
|
+
/** Bytes. */
|
|
31999
|
+
size: number().int().nonnegative(),
|
|
32000
|
+
/** How many frames link the file, each counted once, absent where the server counts none. */
|
|
32001
|
+
frames: number().int().nonnegative().optional()
|
|
32002
|
+
})) });
|
|
32003
|
+
const assetAddResultSchema = object$1({
|
|
32004
|
+
/** Each landed file with the name it was dropped as and the name it took. */
|
|
32005
|
+
added: array$1(object$1({
|
|
32006
|
+
name: string$1(),
|
|
32007
|
+
path: string$1()
|
|
32008
|
+
})),
|
|
32009
|
+
/** Each file left out, by its dropped name, with the error code that says why. */
|
|
32010
|
+
refused: array$1(object$1({
|
|
32011
|
+
name: string$1(),
|
|
32012
|
+
code: string$1(),
|
|
32013
|
+
message: string$1()
|
|
32014
|
+
}))
|
|
32015
|
+
});
|
|
32016
|
+
/** A rename's body: the file's new name in its own folder, keeping its extension. */
|
|
32017
|
+
const assetRenameSchema = object$1({ name: string$1().min(1) });
|
|
32018
|
+
/** A hand asset write's answer: the file's path after it, and each frame ref it rewrote. */
|
|
32019
|
+
const assetWriteResultSchema = object$1({
|
|
32020
|
+
path: string$1(),
|
|
32021
|
+
frames: array$1(string$1())
|
|
32022
|
+
});
|
|
32023
|
+
const assetFramesSchema = object$1({
|
|
32024
|
+
path: string$1(),
|
|
32025
|
+
frames: array$1(string$1())
|
|
32026
|
+
});
|
|
32027
|
+
object$1({ transitions: array$1(object$1({
|
|
32028
|
+
name: string$1(),
|
|
32029
|
+
css: string$1()
|
|
32030
|
+
})) });
|
|
32031
|
+
// src/server/routes/envelope.ts
|
|
32032
|
+
/** The status each refusal of a structure or history write answers with. */
|
|
32033
|
+
const STATUS$5 = {
|
|
32034
|
+
usage: 400,
|
|
32035
|
+
"invalid-name": 400,
|
|
32036
|
+
"project-required": 400,
|
|
32037
|
+
"project-not-found": 404,
|
|
32038
|
+
"page-not-found": 404,
|
|
32039
|
+
"frame-not-found": 404,
|
|
32040
|
+
"section-not-found": 404,
|
|
32041
|
+
"asset-not-found": 404,
|
|
32042
|
+
"name-taken": 409,
|
|
32043
|
+
"stale-layout": 409,
|
|
32044
|
+
"stale-address": 409,
|
|
32045
|
+
"invalid-utf8": 422,
|
|
32046
|
+
"frame-claimed": 409,
|
|
32047
|
+
"asset-held": 409,
|
|
32048
|
+
"asset-type-refused": 400,
|
|
32049
|
+
"undo-overtaken": 409,
|
|
32050
|
+
"nothing-to-undo": 409,
|
|
32051
|
+
"tokens-exist": 409,
|
|
32052
|
+
"stale-tokens": 409,
|
|
32053
|
+
"invalid-edit": 409,
|
|
32054
|
+
"frame-locked": 423,
|
|
32055
|
+
"layout-invalid": 422,
|
|
32056
|
+
"project-file-invalid": 422,
|
|
32057
|
+
"fit-unbounded": 422,
|
|
32058
|
+
"fit-scroll": 422,
|
|
32059
|
+
"claims-invalid": 422,
|
|
32060
|
+
"lock-timeout": 503,
|
|
32061
|
+
"browser-not-found": 503
|
|
32062
|
+
};
|
|
32063
|
+
/**
|
|
32064
|
+
* Answers a refusal in the CLI's `{ ok, error }` envelope, for a route
|
|
32065
|
+
* module's `onError`. Anything else is a fault and goes on to Hono.
|
|
32066
|
+
*/
|
|
32067
|
+
function answerRefusal(error, c) {
|
|
32068
|
+
if (!(error instanceof FrameboardError)) throw error;
|
|
32069
|
+
return c.json({
|
|
32070
|
+
ok: false,
|
|
32071
|
+
error: {
|
|
32072
|
+
code: error.code,
|
|
32073
|
+
message: error.message,
|
|
32074
|
+
details: error.details
|
|
32075
|
+
}
|
|
32076
|
+
}, STATUS$5[error.code] ?? 500);
|
|
32077
|
+
}
|
|
32078
|
+
/** The request's JSON body as the schema reads it, or `usage` naming what failed. */
|
|
32079
|
+
async function parseBody$1(request, schema) {
|
|
32080
|
+
const parsed = schema.safeParse(await request.json().catch(() => null));
|
|
32081
|
+
if (!parsed.success) throw new FrameboardError("usage", `The body ${parsed.error.message}`);
|
|
32082
|
+
return parsed.data;
|
|
32083
|
+
}
|
|
32084
|
+
// src/server/checks/tokens.ts
|
|
32085
|
+
/**
|
|
32086
|
+
* Where a project's token sheets sit, the address file read by plain
|
|
32087
|
+
* `JSON.parse`, since the write hook cannot afford its schema.
|
|
32088
|
+
*/
|
|
32089
|
+
function tokenSheetPaths(root, project, tokens) {
|
|
32090
|
+
const own = join(root, project, TOKEN_FILE);
|
|
32091
|
+
return {
|
|
32092
|
+
board: boardSheetPath(root, tokens),
|
|
32093
|
+
project: existsSync(own) ? own : null
|
|
32094
|
+
};
|
|
32095
|
+
}
|
|
32096
|
+
/** The board's token sheet alone, resolved the way `tokenSheetPaths` resolves it. */
|
|
32097
|
+
function boardSheetPath(root, tokens = recordedTokens(root)) {
|
|
32098
|
+
const board = tokens ?? join(root, "tokens.css");
|
|
32099
|
+
return existsSync(board) ? board : null;
|
|
32100
|
+
}
|
|
32101
|
+
/** The `--tokens` path the board's running server recorded, or null. */
|
|
32102
|
+
function recordedTokens(root) {
|
|
32103
|
+
try {
|
|
32104
|
+
const parsed = JSON.parse(readFileSync(join(root, RUN_FOLDER, ADDRESS_FILE), "utf8"));
|
|
32105
|
+
const tokens = typeof parsed === "object" && parsed !== null && "tokens" in parsed ? parsed.tokens : void 0;
|
|
32106
|
+
return typeof tokens === "string" ? tokens : null;
|
|
32107
|
+
} catch {
|
|
32108
|
+
return null;
|
|
32109
|
+
}
|
|
32110
|
+
}
|
|
32111
|
+
/**
|
|
32112
|
+
* The kit a frame's layout entry names, null for none or a layout that does
|
|
32113
|
+
* not read, parsed plainly as the address file is.
|
|
32114
|
+
*/
|
|
32115
|
+
function frameKit({ root, project, page, name }) {
|
|
32116
|
+
try {
|
|
32117
|
+
return kitOf(keyOf$1(keyOf$1(keyOf$1(JSON.parse(readFileSync(join(root, project, page, LAYOUT_FILE), "utf8")), "frames"), name), "kit"));
|
|
32118
|
+
} catch {
|
|
32119
|
+
return null;
|
|
32120
|
+
}
|
|
32121
|
+
}
|
|
32122
|
+
/** An object's own key, undefined for a value holding none. */
|
|
32123
|
+
function keyOf$1(value, key) {
|
|
32124
|
+
return typeof value === "object" && value !== null && Object.hasOwn(value, key) ? value[key] : void 0;
|
|
32125
|
+
}
|
|
32126
|
+
/**
|
|
32127
|
+
* The kit sheets a frame draws with, as paths under its project in cascade
|
|
32128
|
+
* order: a project-wide kit's where `assets/kit/` holds `kit.json`, then the
|
|
32129
|
+
* tokens and stylesheet of the kit the frame names, each that exists.
|
|
32130
|
+
*/
|
|
32131
|
+
function kitSheetFiles(root, project, kit) {
|
|
32132
|
+
const wide = [ASSETS_FOLDER, "kit"];
|
|
32133
|
+
const named = kitOf(kit);
|
|
32134
|
+
return [...existsSync(join(root, project, ...wide, "kit.json")) ? [[...wide, KIT_SHEET]] : [], ...named ? [TOKEN_FILE, KIT_SHEET].map((file) => [
|
|
32135
|
+
ASSETS_FOLDER,
|
|
32136
|
+
PROJECT_KITS,
|
|
32137
|
+
named,
|
|
32138
|
+
file
|
|
32139
|
+
]) : []].filter((file) => existsSync(join(root, project, ...file))).map((file) => file.join("/"));
|
|
32140
|
+
}
|
|
32141
|
+
/**
|
|
32142
|
+
* The sheets the frame route imports ahead of a frame, being the board's
|
|
32143
|
+
* tokens, the project's, then its kit sheets, which the cascade reads ahead
|
|
32144
|
+
* of the frame's own. `kit` is the kit the frame names, null for a plain one.
|
|
32145
|
+
*/
|
|
32146
|
+
function tokenSheets(root, project, tokens, kit = null) {
|
|
32147
|
+
return readSheets(root, project, tokenSheetPaths(root, project, tokens), kit);
|
|
32148
|
+
}
|
|
32149
|
+
/** `tokenSheets` for a caller already holding the project's sheet paths. */
|
|
32150
|
+
function readSheets(root, project, paths, kit) {
|
|
32151
|
+
const kitSheets = kitSheetFiles(root, project, kit).map((file) => join(root, project, file));
|
|
32152
|
+
return [
|
|
32153
|
+
paths.board,
|
|
32154
|
+
paths.project,
|
|
32155
|
+
...kitSheets
|
|
32156
|
+
].filter((path) => path !== null).map((path) => ({
|
|
32157
|
+
css: readFileSync(path, "utf8"),
|
|
32158
|
+
origin: "token",
|
|
32159
|
+
path,
|
|
32160
|
+
offset: 0
|
|
32161
|
+
}));
|
|
32162
|
+
}
|
|
32163
|
+
// src/shared/board-urls.ts
|
|
32164
|
+
/** Where the server serves a frame's file, with each name encoded as its own segment. */
|
|
32165
|
+
function frameUrl(ref) {
|
|
32166
|
+
const [project = "", page = "", frame = ""] = ref.split("/");
|
|
32167
|
+
return `/frames/${encodeURIComponent(project)}/${encodeURIComponent(page)}/${encodeURIComponent(frame)}.html`;
|
|
32168
|
+
}
|
|
32169
|
+
/** The board route showing one page of a project. */
|
|
32170
|
+
function boardUrl(project, page) {
|
|
32171
|
+
return `/p/${encodeURIComponent(project)}/${encodeURIComponent(page)}`;
|
|
32172
|
+
}
|
|
32173
|
+
// src/shared/theme.ts
|
|
32174
|
+
const THEMES = ["light", "dark"];
|
|
32175
|
+
/** The query a frame is served with, which its injected script sets `data-theme` from. */
|
|
32176
|
+
const THEME_QUERY = "theme";
|
|
32177
|
+
/**
|
|
32178
|
+
* The attribute on every element the frame route injects. A reader counting
|
|
32179
|
+
* a live frame's elements skips the ones carrying it, so the live index
|
|
32180
|
+
* matches the file's.
|
|
32181
|
+
*/
|
|
32182
|
+
const LOOK_MARKER = "data-frameboard";
|
|
32183
|
+
/**
|
|
32184
|
+
* The attribute on the injected style holding the SHA-256 hex of the bytes
|
|
32185
|
+
* the route served, so a live frame names the exact file an edit addresses.
|
|
32186
|
+
*/
|
|
32187
|
+
const RENDERED_HASH = "data-hash";
|
|
32188
|
+
function isTheme$1(value) {
|
|
32189
|
+
return value === "light" || value === "dark";
|
|
32190
|
+
}
|
|
32191
|
+
/**
|
|
32192
|
+
* Shows a frame's root in `theme`, using nothing outside its own body, since
|
|
32193
|
+
* the frame route embeds its source.
|
|
32194
|
+
*/
|
|
32195
|
+
function setFrameTheme(root, theme) {
|
|
32196
|
+
root.setAttribute("data-theme", theme);
|
|
32197
|
+
root.style.colorScheme = theme;
|
|
32198
|
+
root.classList.toggle("dark", theme === "dark");
|
|
32199
|
+
root.classList.toggle("light", theme === "light");
|
|
32200
|
+
}
|
|
32201
|
+
/**
|
|
32202
|
+
* Where a frame is served in one theme, with `version` naming the reload so
|
|
32203
|
+
* a changed file loads fresh, and `at` naming a version an agent's write
|
|
32204
|
+
* replaced by its content hash.
|
|
32205
|
+
*/
|
|
32206
|
+
function frameThemeUrl(ref, theme, version, at) {
|
|
32207
|
+
const query = new URLSearchParams({ [THEME_QUERY]: theme });
|
|
32208
|
+
if (version !== void 0) query.set("v", String(version));
|
|
32209
|
+
if (at !== void 0) query.set("at", at);
|
|
32210
|
+
return `${frameUrl(ref)}?${query}`;
|
|
32211
|
+
}
|
|
32212
|
+
// src/server/look/inject.ts
|
|
32213
|
+
const BOM = [
|
|
32214
|
+
239,
|
|
32215
|
+
187,
|
|
32216
|
+
191
|
|
32217
|
+
];
|
|
32218
|
+
/**
|
|
32219
|
+
* Shows the frame's root in the theme the frame was served with, through the
|
|
32220
|
+
* same `setFrameTheme` the board calls on a theme change, then removes
|
|
32221
|
+
* itself, so the one injected element a live frame keeps is the stylesheet.
|
|
32222
|
+
*/
|
|
32223
|
+
const THEME_SCRIPT = `(function(s,t){if(t==='light'||t==='dark')(${setFrameTheme.toString()})(document.documentElement,t);s.remove()})(document.currentScript,new URLSearchParams(location.search).get(${JSON.stringify(THEME_QUERY)}))`;
|
|
32224
|
+
/** Where the look route serves the frame bridge's script, under the running release. */
|
|
32225
|
+
const BRIDGE_URL = `/frameboard/bridge/v${version}/frame-bridge.js`;
|
|
32226
|
+
/**
|
|
32227
|
+
* The frame route's injected `head`, one stylesheet carrying `hash` as its one
|
|
32228
|
+
* other attribute, since another element would shift every live index. Given
|
|
32229
|
+
* no `bridge`, as a kit preview's policy allows none, it loads no bridge.
|
|
32230
|
+
*/
|
|
32231
|
+
function frameHead(sheets, hash, bridge) {
|
|
32232
|
+
const imports = sheets.map((url) => `@import url(${JSON.stringify(url)});`);
|
|
32233
|
+
const script = bridge === void 0 ? "" : `<script ${LOOK_MARKER} src=${JSON.stringify(bridge)}><\/script>`;
|
|
32234
|
+
return `<style ${LOOK_MARKER} ${RENDERED_HASH}="${hash}">${imports.join("")}</style><script ${LOOK_MARKER}>${THEME_SCRIPT}<\/script>${script}`;
|
|
32235
|
+
}
|
|
32236
|
+
/**
|
|
32237
|
+
* Splices `head` where the browser starts its `head`, keeping every byte of
|
|
32238
|
+
* the file around it.
|
|
32239
|
+
*/
|
|
32240
|
+
function injectHead(bytes, head) {
|
|
32241
|
+
const offset = headOffset(bytes);
|
|
32242
|
+
const inserted = new TextEncoder().encode(head);
|
|
32243
|
+
const out = new Uint8Array(bytes.length + inserted.length);
|
|
32244
|
+
out.set(bytes.subarray(0, offset));
|
|
32245
|
+
out.set(inserted, offset);
|
|
32246
|
+
out.set(bytes.subarray(offset), offset + inserted.length);
|
|
32247
|
+
return out;
|
|
32248
|
+
}
|
|
32249
|
+
/**
|
|
32250
|
+
* The splice offset, decoded as Latin-1 so parse5's offsets are byte offsets.
|
|
32251
|
+
*/
|
|
32252
|
+
function headOffset(bytes) {
|
|
32253
|
+
const bom = BOM.every((byte, index) => bytes[index] === byte);
|
|
32254
|
+
const text = Buffer.from(bytes).toString("latin1");
|
|
32255
|
+
const document = parse$3(bom ? ` ${text.slice(3)}` : text, { sourceCodeLocationInfo: true });
|
|
32256
|
+
const html = document.childNodes.find(isElement);
|
|
32257
|
+
const stated = (html?.childNodes.find((node) => isElement(node) && node.tagName === "head"))?.sourceCodeLocation?.startTag ?? html?.sourceCodeLocation?.startTag;
|
|
32258
|
+
if (stated) return stated.endOffset;
|
|
32259
|
+
return document.childNodes.find((node) => node.nodeName === "#documentType")?.sourceCodeLocation?.endOffset ?? (bom ? BOM.length : 0);
|
|
32260
|
+
}
|
|
32261
|
+
function isElement(node) {
|
|
32262
|
+
return "tagName" in node;
|
|
32263
|
+
}
|
|
32264
|
+
// src/shared/faces.ts
|
|
32265
|
+
const FACES = [
|
|
32266
|
+
{
|
|
32267
|
+
family: "Geist",
|
|
32268
|
+
package: "@fontsource-variable/geist",
|
|
32269
|
+
packageFamily: "Geist Variable",
|
|
32270
|
+
folder: "geist",
|
|
32271
|
+
weights: {
|
|
32272
|
+
min: 100,
|
|
32273
|
+
max: 900
|
|
32274
|
+
},
|
|
32275
|
+
fallback: "sans-serif",
|
|
32276
|
+
startsLook: true
|
|
32277
|
+
},
|
|
32278
|
+
{
|
|
32279
|
+
family: "Geist Mono",
|
|
32280
|
+
package: "@fontsource-variable/geist-mono",
|
|
32281
|
+
packageFamily: "Geist Mono Variable",
|
|
32282
|
+
folder: "geist-mono",
|
|
32283
|
+
weights: {
|
|
32284
|
+
min: 100,
|
|
32285
|
+
max: 900
|
|
32286
|
+
},
|
|
32287
|
+
fallback: "monospace",
|
|
32288
|
+
startsLook: true
|
|
32289
|
+
},
|
|
32290
|
+
{
|
|
32291
|
+
family: "Inter",
|
|
32292
|
+
package: "@fontsource-variable/inter",
|
|
32293
|
+
packageFamily: "Inter Variable",
|
|
32294
|
+
folder: "inter",
|
|
32295
|
+
weights: {
|
|
32296
|
+
min: 100,
|
|
32297
|
+
max: 900
|
|
32298
|
+
},
|
|
32299
|
+
fallback: "sans-serif",
|
|
32300
|
+
startsLook: true
|
|
32301
|
+
},
|
|
32302
|
+
{
|
|
32303
|
+
family: "Source Serif 4",
|
|
32304
|
+
package: "@fontsource-variable/source-serif-4",
|
|
32305
|
+
packageFamily: "Source Serif 4 Variable",
|
|
32306
|
+
folder: "source-serif-4",
|
|
32307
|
+
weights: {
|
|
32308
|
+
min: 200,
|
|
32309
|
+
max: 900
|
|
32310
|
+
},
|
|
32311
|
+
fallback: "serif",
|
|
32312
|
+
startsLook: true
|
|
32313
|
+
},
|
|
32314
|
+
{
|
|
32315
|
+
family: "Caveat",
|
|
32316
|
+
package: "@fontsource-variable/caveat",
|
|
32317
|
+
packageFamily: "Caveat Variable",
|
|
32318
|
+
folder: "caveat",
|
|
32319
|
+
weights: {
|
|
32320
|
+
min: 400,
|
|
32321
|
+
max: 700
|
|
32322
|
+
},
|
|
32323
|
+
fallback: "cursive",
|
|
32324
|
+
startsLook: false
|
|
32325
|
+
}
|
|
32326
|
+
];
|
|
32327
|
+
/** Where the server serves the faces folder. */
|
|
32328
|
+
const FACES_URL = "/frameboard/faces";
|
|
32329
|
+
/**
|
|
32330
|
+
* The sheet a frame imports to get one face, under the running release so
|
|
32331
|
+
* the server can answer it as cached for good.
|
|
32332
|
+
*/
|
|
32333
|
+
function faceSheetUrl(face) {
|
|
32334
|
+
return `${FACES_URL}/v${version}/${face.folder}/index.css`;
|
|
32335
|
+
}
|
|
32336
|
+
/** The stack naming a face then its fallback, as `'Geist Mono', monospace`. */
|
|
32337
|
+
function faceStack(face) {
|
|
32338
|
+
return `${/\s/.test(face.family) ? `'${face.family}'` : face.family}, ${face.fallback}`;
|
|
32339
|
+
}
|
|
32340
|
+
// src/server/routes/frames.ts
|
|
32341
|
+
const NOTES_FILE$2 = "notes.json";
|
|
32342
|
+
/** Where the look route serves the board's token sheet, whichever file stands in for it. */
|
|
32343
|
+
const BOARD_SHEET_URL = "/frameboard/tokens.css";
|
|
32344
|
+
const CONTENT_TYPES$2 = {
|
|
32345
|
+
".html": "text/html; charset=utf-8",
|
|
32346
|
+
".css": "text/css; charset=utf-8",
|
|
32347
|
+
".js": "text/javascript; charset=utf-8",
|
|
32348
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
32349
|
+
".json": "application/json; charset=utf-8",
|
|
32350
|
+
".txt": "text/plain; charset=utf-8",
|
|
32351
|
+
".svg": "image/svg+xml",
|
|
32352
|
+
".png": "image/png",
|
|
32353
|
+
".jpg": "image/jpeg",
|
|
32354
|
+
".jpeg": "image/jpeg",
|
|
32355
|
+
".gif": "image/gif",
|
|
32356
|
+
".webp": "image/webp",
|
|
32357
|
+
".avif": "image/avif",
|
|
32358
|
+
".ico": "image/x-icon",
|
|
32359
|
+
".woff": "font/woff",
|
|
32360
|
+
".woff2": "font/woff2",
|
|
32361
|
+
".ttf": "font/ttf",
|
|
32362
|
+
".otf": "font/otf",
|
|
32363
|
+
".mp4": "video/mp4",
|
|
32364
|
+
".webm": "video/webm",
|
|
32365
|
+
".mov": "video/quicktime",
|
|
32366
|
+
".m4v": "video/x-m4v",
|
|
32367
|
+
".mp3": "audio/mpeg",
|
|
32368
|
+
".wav": "audio/wav",
|
|
32369
|
+
".ogg": "audio/ogg",
|
|
32370
|
+
".m4a": "audio/mp4",
|
|
32371
|
+
".glb": "model/gltf-binary",
|
|
32372
|
+
".gltf": "model/gltf+json"
|
|
32373
|
+
};
|
|
32374
|
+
/**
|
|
32375
|
+
* Serves the board's frames so relative links resolve unrewritten, its own
|
|
32376
|
+
* handler since it must refuse records, dot-named, and escaping paths, all as
|
|
32377
|
+
* 404 so nothing tells a caller what exists.
|
|
32378
|
+
*/
|
|
32379
|
+
function frameRoutes(root, look, version, base = "") {
|
|
32380
|
+
const app = new Hono();
|
|
32381
|
+
app.get("/frames/*", async (c) => {
|
|
32382
|
+
const parts = decodeSegments(new URL(c.req.url).pathname.slice(8).split("/"));
|
|
32383
|
+
const file = parts && await resolveFile(root, parts);
|
|
32384
|
+
if (!file) return c.notFound();
|
|
32385
|
+
const [project = "", page = "", name = ""] = parts;
|
|
32386
|
+
const isFrame = page !== "assets" && parts.length === 3 && extname(file).toLowerCase() === ".html";
|
|
32387
|
+
const contentType = CONTENT_TYPES$2[extname(file).toLowerCase()] ?? "application/octet-stream";
|
|
32388
|
+
const at = c.req.query("at");
|
|
32389
|
+
const rangeHeader = c.req.header("Range");
|
|
32390
|
+
if (!isFrame && at === void 0 && rangeHeader !== void 0) {
|
|
32391
|
+
const { size } = await stat(file);
|
|
32392
|
+
const range = parseRange(rangeHeader, size);
|
|
32393
|
+
if (range === "unsatisfiable") return c.body(null, 416, {
|
|
32394
|
+
"Content-Range": `bytes */${size}`,
|
|
32395
|
+
"Accept-Ranges": "bytes",
|
|
32396
|
+
"Cache-Control": "no-store"
|
|
32397
|
+
});
|
|
32398
|
+
if (range) {
|
|
32399
|
+
const headers = {
|
|
32400
|
+
"Content-Type": contentType,
|
|
32401
|
+
"Content-Length": String(range.end - range.start + 1),
|
|
32402
|
+
"Content-Range": `bytes ${range.start}-${range.end}/${size}`,
|
|
32403
|
+
"Accept-Ranges": "bytes",
|
|
32404
|
+
"Cache-Control": "no-store"
|
|
32405
|
+
};
|
|
32406
|
+
if (c.req.method === "HEAD") return c.body(null, 206, headers);
|
|
32407
|
+
const stream = Readable.toWeb(createReadStream(file, range));
|
|
32408
|
+
return c.body(stream, 206, headers);
|
|
32409
|
+
}
|
|
32410
|
+
}
|
|
32411
|
+
if (!isFrame && at === void 0) {
|
|
32412
|
+
const tag = weakTag(await stat(file, { bigint: true }));
|
|
32413
|
+
const revalidate = {
|
|
32414
|
+
ETag: tag,
|
|
32415
|
+
"Cache-Control": "no-cache"
|
|
32416
|
+
};
|
|
32417
|
+
if (matchesTag(c.req.header("If-None-Match"), tag)) return c.body(null, 304, revalidate);
|
|
32418
|
+
const headers = {
|
|
32419
|
+
"Content-Type": contentType,
|
|
32420
|
+
"Accept-Ranges": "bytes",
|
|
32421
|
+
...revalidate
|
|
32422
|
+
};
|
|
32423
|
+
if (c.req.method === "HEAD") return c.body(null, 200, headers);
|
|
32424
|
+
return c.body(new Uint8Array(await readFile(file)), 200, headers);
|
|
32425
|
+
}
|
|
32426
|
+
let bytes;
|
|
32427
|
+
if (at === void 0) bytes = new Uint8Array(await readFile(file));
|
|
32428
|
+
else {
|
|
32429
|
+
const ref = `${project}/${page}/${name.slice(0, -5)}`;
|
|
32430
|
+
const held = isFrame ? version?.(ref, at) ?? null : null;
|
|
32431
|
+
if (held === null) return c.notFound();
|
|
32432
|
+
bytes = new TextEncoder().encode(held);
|
|
32433
|
+
}
|
|
32434
|
+
const kit = isFrame ? frameKit({
|
|
32435
|
+
root,
|
|
32436
|
+
project,
|
|
32437
|
+
page,
|
|
32438
|
+
name: name.slice(0, -5)
|
|
32439
|
+
}) : null;
|
|
32440
|
+
const body = injectHead(bytes, frameHead(sheetUrls(project, look.sheets(project), kitSheetFiles(root, project, kit)).map((url) => `${base}${url}`), contentHash(bytes), `${base}${BRIDGE_URL}`));
|
|
32441
|
+
return c.body(body, 200, {
|
|
32442
|
+
"Content-Type": contentType,
|
|
32443
|
+
"Cache-Control": "no-store"
|
|
32444
|
+
});
|
|
32445
|
+
});
|
|
32446
|
+
return app;
|
|
32447
|
+
}
|
|
32448
|
+
/**
|
|
32449
|
+
* A weak validator from a file's size and nanosecond mtime, so a check costs
|
|
32450
|
+
* one stat rather than a read of every byte. A same-size rewrite inside one
|
|
32451
|
+
* timestamp tick keeps its tag, which a coarse mount makes likelier.
|
|
32452
|
+
*/
|
|
32453
|
+
function weakTag({ size, mtimeNs }) {
|
|
32454
|
+
return `W/"${size.toString(16)}-${mtimeNs.toString(16)}"`;
|
|
32455
|
+
}
|
|
32456
|
+
/** Whether an `If-None-Match` header names `tag`, compared weakly per RFC 9110. */
|
|
32457
|
+
function matchesTag(header, tag) {
|
|
32458
|
+
if (header === void 0) return false;
|
|
32459
|
+
if (header.trim() === "*") return true;
|
|
32460
|
+
const opaque = tag.replace(/^W\//, "");
|
|
32461
|
+
return header.split(",").some((listed) => listed.trim().replace(/^W\//, "") === opaque);
|
|
32462
|
+
}
|
|
32463
|
+
/**
|
|
32464
|
+
* The bytes a single range names, null for a header to ignore, which RFC 9110
|
|
32465
|
+
* allows for an unsupported range such as a multi-range.
|
|
32466
|
+
*/
|
|
32467
|
+
function parseRange(header, size) {
|
|
32468
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
32469
|
+
if (!match) return null;
|
|
32470
|
+
const [, first = "", last = ""] = match;
|
|
32471
|
+
if (first === "") {
|
|
32472
|
+
if (last === "") return null;
|
|
32473
|
+
const suffix = Number(last);
|
|
32474
|
+
if (suffix === 0) return "unsatisfiable";
|
|
32475
|
+
if (size === 0) return null;
|
|
32476
|
+
return {
|
|
32477
|
+
start: Math.max(0, size - suffix),
|
|
32478
|
+
end: size - 1
|
|
32479
|
+
};
|
|
32480
|
+
}
|
|
32481
|
+
const start = Number(first);
|
|
32482
|
+
const end = last === "" ? size - 1 : Number(last);
|
|
32483
|
+
if (last !== "" && end < start) return null;
|
|
32484
|
+
if (start >= size) return "unsatisfiable";
|
|
32485
|
+
return {
|
|
32486
|
+
start,
|
|
32487
|
+
end: Math.min(end, size - 1)
|
|
32488
|
+
};
|
|
32489
|
+
}
|
|
32490
|
+
/**
|
|
32491
|
+
* The sheets a frame imports, being every face, then the board's tokens, then
|
|
32492
|
+
* the project's, then its kit sheets, which read the tokens and still lose to
|
|
32493
|
+
* the frame's own sheets. `kitFiles` come as `kitSheetFiles` answers them.
|
|
32494
|
+
*/
|
|
32495
|
+
function sheetUrls(project, sheets, kitFiles) {
|
|
32496
|
+
const folder = `/frames/${encodeURIComponent(project)}`;
|
|
32497
|
+
return [
|
|
32498
|
+
...FACES.map(faceSheetUrl),
|
|
32499
|
+
...sheets.board ? [BOARD_SHEET_URL] : [],
|
|
32500
|
+
...sheets.project ? [`${folder}/${TOKEN_FILE}`] : [],
|
|
32501
|
+
...kitFiles.map((file) => `${folder}/${file.split("/").map(encodeURIComponent).join("/")}`)
|
|
32502
|
+
];
|
|
32503
|
+
}
|
|
32504
|
+
function decodeSegments(segments) {
|
|
32505
|
+
const decoded = [];
|
|
32506
|
+
for (const segment of segments) {
|
|
32507
|
+
let name;
|
|
32508
|
+
try {
|
|
32509
|
+
name = decodeURIComponent(segment);
|
|
32510
|
+
} catch {
|
|
32511
|
+
return null;
|
|
32512
|
+
}
|
|
32513
|
+
if (name === "" || name.startsWith(".") || /[/\\\0]/.test(name)) return null;
|
|
32514
|
+
decoded.push(name);
|
|
32515
|
+
}
|
|
32516
|
+
return decoded;
|
|
32517
|
+
}
|
|
32518
|
+
/** The realpath of the file a request names, or null when it is refused or missing. */
|
|
32519
|
+
async function resolveFile(root, [project, page, ...rest]) {
|
|
32520
|
+
if (!project || !page) return null;
|
|
32521
|
+
const projectSheet = rest.length === 0 && page === "tokens.css";
|
|
32522
|
+
if (rest.length === 0 && !projectSheet) return null;
|
|
32523
|
+
if (page !== "assets" && !projectSheet && (rest.length > 1 || isRecord$6(rest[0] ?? ""))) return null;
|
|
32524
|
+
try {
|
|
32525
|
+
const projectDir = await realpath(join(root, project));
|
|
32526
|
+
if (!projectDir.startsWith(root + sep)) return null;
|
|
32527
|
+
const file = await realpath(join(projectDir, page, ...rest));
|
|
32528
|
+
if (!file.startsWith(projectDir + sep)) return null;
|
|
32529
|
+
if (!servableInProject(relative(projectDir, file).split(sep))) return null;
|
|
32530
|
+
return (await stat(file)).isFile() ? file : null;
|
|
32531
|
+
} catch {
|
|
32532
|
+
return null;
|
|
32533
|
+
}
|
|
32534
|
+
}
|
|
32535
|
+
/**
|
|
32536
|
+
* Whether the route may serve a file, read off its real path, so a symlink to
|
|
32537
|
+
* a record or a dot-named path is refused.
|
|
32538
|
+
*/
|
|
32539
|
+
function servableInProject(segments) {
|
|
32540
|
+
if (segments.some((segment) => segment.startsWith("."))) return false;
|
|
32541
|
+
const [first = "", name = ""] = segments;
|
|
32542
|
+
if (segments.length === 1) return first === TOKEN_FILE;
|
|
32543
|
+
return first === "assets" || !isRecord$6(name);
|
|
32544
|
+
}
|
|
32545
|
+
function isRecord$6(name) {
|
|
32546
|
+
return name === "layout.json" || name === NOTES_FILE$2;
|
|
32547
|
+
}
|
|
31220
32548
|
// src/server/routes/assets.ts
|
|
31221
32549
|
/** The most a drop may carry, multipart overhead included. */
|
|
31222
32550
|
const ASSET_BODY_LIMIT = 67108864;
|
|
31223
32551
|
/**
|
|
31224
32552
|
* A project's `assets/` routes, the drop held in memory, so the body limit is
|
|
31225
|
-
* its only bound.
|
|
32553
|
+
* its only bound. A rename, replace, or delete names its file after
|
|
32554
|
+
* `assets/` in the URL, each segment encoded, and records one undo step.
|
|
31226
32555
|
*/
|
|
31227
|
-
function assetsRoutes(root, access, { limit = ASSET_BODY_LIMIT, usage } = {}) {
|
|
32556
|
+
function assetsRoutes(root, access, history, { limit = ASSET_BODY_LIMIT, usage } = {}) {
|
|
31228
32557
|
const app = new Hono();
|
|
31229
32558
|
const authorized = requireWriter(access);
|
|
31230
32559
|
const path = "/api/projects/:project/assets";
|
|
32560
|
+
const file = `${path}/*`;
|
|
32561
|
+
const limited = bodyLimit({
|
|
32562
|
+
maxSize: limit,
|
|
32563
|
+
onError: (c) => c.json({
|
|
32564
|
+
ok: false,
|
|
32565
|
+
error: {
|
|
32566
|
+
code: "asset-too-large",
|
|
32567
|
+
message: `A drop may carry ${limit / 1024 / 1024} MiB at most. Nothing was written.`
|
|
32568
|
+
}
|
|
32569
|
+
}, 413)
|
|
32570
|
+
});
|
|
32571
|
+
/** The project folder and the file's path under `assets/`, refusing a missing project or a path segment that leaves the folder. */
|
|
32572
|
+
const target = (url, project) => {
|
|
32573
|
+
const projectDir = projectFolder(root, project);
|
|
32574
|
+
if (projectDir === null) throw new FrameboardError("project-not-found", `No project named ${project} in this board.`);
|
|
32575
|
+
const prefix = `/api/projects/${encodeURIComponent(project)}/assets/`;
|
|
32576
|
+
const raw = new URL(url).pathname;
|
|
32577
|
+
const segments = raw.startsWith(prefix) ? decodeSegments(raw.slice(prefix.length).split("/")) : null;
|
|
32578
|
+
if (segments === null || segments.length === 0) throw new FrameboardError("asset-not-found", "Name a file in the project's assets folder.");
|
|
32579
|
+
return {
|
|
32580
|
+
projectDir,
|
|
32581
|
+
asset: segments.join("/")
|
|
32582
|
+
};
|
|
32583
|
+
};
|
|
32584
|
+
/** Runs one write with a fresh journal and records it as a step that moves no page. */
|
|
32585
|
+
const recorded = async (write) => {
|
|
32586
|
+
const journal = history.journal();
|
|
32587
|
+
const result = await write(journal);
|
|
32588
|
+
history.record({
|
|
32589
|
+
id: journal.id,
|
|
32590
|
+
changes: journal.changes,
|
|
32591
|
+
page: null,
|
|
32592
|
+
frames: result.frames
|
|
32593
|
+
});
|
|
32594
|
+
return result;
|
|
32595
|
+
};
|
|
31231
32596
|
app.get(path, async (c) => {
|
|
31232
32597
|
const projectDir = projectFolder(root, c.req.param("project"));
|
|
31233
32598
|
if (projectDir === null) return c.json(notFound$1(c.req.param("project")), 404);
|
|
@@ -31253,16 +32618,7 @@ function assetsRoutes(root, access, { limit = ASSET_BODY_LIMIT, usage } = {}) {
|
|
|
31253
32618
|
data
|
|
31254
32619
|
});
|
|
31255
32620
|
});
|
|
31256
|
-
app.post(path, authorized,
|
|
31257
|
-
maxSize: limit,
|
|
31258
|
-
onError: (c) => c.json({
|
|
31259
|
-
ok: false,
|
|
31260
|
-
error: {
|
|
31261
|
-
code: "asset-too-large",
|
|
31262
|
-
message: `A drop may carry ${limit / 1024 / 1024} MiB at most. Nothing was written.`
|
|
31263
|
-
}
|
|
31264
|
-
}, 413)
|
|
31265
|
-
}), async (c) => {
|
|
32621
|
+
app.post(path, authorized, limited, async (c) => {
|
|
31266
32622
|
const projectDir = projectFolder(root, c.req.param("project"));
|
|
31267
32623
|
if (projectDir === null) return c.json(notFound$1(c.req.param("project")), 404);
|
|
31268
32624
|
const sent = [(await c.req.parseBody({ all: true }).catch(() => ({}))).files].flat().filter((v) => v instanceof File);
|
|
@@ -31282,8 +32638,66 @@ function assetsRoutes(root, access, { limit = ASSET_BODY_LIMIT, usage } = {}) {
|
|
|
31282
32638
|
data: await addAssets(projectDir, uploads)
|
|
31283
32639
|
});
|
|
31284
32640
|
});
|
|
32641
|
+
app.get(file, async (c) => {
|
|
32642
|
+
const project = c.req.param("project");
|
|
32643
|
+
const { asset } = target(c.req.url, project);
|
|
32644
|
+
const data = {
|
|
32645
|
+
path: asset,
|
|
32646
|
+
frames: (await framesLinking(root, project, asset)).map(({ page, name }) => `${project}/${page}/${name}`)
|
|
32647
|
+
};
|
|
32648
|
+
return c.json({
|
|
32649
|
+
ok: true,
|
|
32650
|
+
data
|
|
32651
|
+
});
|
|
32652
|
+
});
|
|
32653
|
+
app.delete(file, authorized, async (c) => {
|
|
32654
|
+
const { projectDir, asset } = target(c.req.url, c.req.param("project"));
|
|
32655
|
+
const data = await recorded((journal) => removeAsset(projectDir, asset, { journal }));
|
|
32656
|
+
return c.json({
|
|
32657
|
+
ok: true,
|
|
32658
|
+
data
|
|
32659
|
+
});
|
|
32660
|
+
});
|
|
32661
|
+
app.patch(file, authorized, async (c) => {
|
|
32662
|
+
const project = c.req.param("project");
|
|
32663
|
+
const { asset } = target(c.req.url, project);
|
|
32664
|
+
const { name } = await parseBody$1(c.req.raw, assetRenameSchema);
|
|
32665
|
+
const data = await recorded((journal) => renameAsset(root, project, asset, name, {
|
|
32666
|
+
journal,
|
|
32667
|
+
gate: (refs) => refuseHeld(root, asset, refs)
|
|
32668
|
+
}));
|
|
32669
|
+
return c.json({
|
|
32670
|
+
ok: true,
|
|
32671
|
+
data
|
|
32672
|
+
});
|
|
32673
|
+
});
|
|
32674
|
+
app.put(file, authorized, limited, async (c) => {
|
|
32675
|
+
const { projectDir, asset } = target(c.req.url, c.req.param("project"));
|
|
32676
|
+
const sent = (await c.req.parseBody().catch(() => ({}))).file;
|
|
32677
|
+
if (!(sent instanceof File)) throw new FrameboardError("usage", "Send multipart/form-data with one file in the \"file\" field.");
|
|
32678
|
+
const upload = {
|
|
32679
|
+
name: sent.name,
|
|
32680
|
+
bytes: new Uint8Array(await sent.arrayBuffer())
|
|
32681
|
+
};
|
|
32682
|
+
const data = await recorded((journal) => replaceAsset(projectDir, asset, upload, { journal }));
|
|
32683
|
+
return c.json({
|
|
32684
|
+
ok: true,
|
|
32685
|
+
data
|
|
32686
|
+
});
|
|
32687
|
+
});
|
|
32688
|
+
app.onError(answerRefusal);
|
|
31285
32689
|
return app;
|
|
31286
32690
|
}
|
|
32691
|
+
/** Refuses `asset-held` naming the session, when another session holds a frame the rename would rewrite. */
|
|
32692
|
+
async function refuseHeld(root, asset, refs) {
|
|
32693
|
+
try {
|
|
32694
|
+
await refuseClaimed(root, refs, /* @__PURE__ */ new Date());
|
|
32695
|
+
} catch (error) {
|
|
32696
|
+
if (!(error instanceof FrameboardError) || error.code !== "frame-claimed") throw error;
|
|
32697
|
+
const { tag, frame } = error.details;
|
|
32698
|
+
throw new FrameboardError("asset-held", `${String(tag)} is editing ${String(frame)}, which links assets/${asset}, so it was not renamed. Try again once it finishes.`, error.details);
|
|
32699
|
+
}
|
|
32700
|
+
}
|
|
31287
32701
|
function projectFolder(root, project) {
|
|
31288
32702
|
const folder = join(root, project);
|
|
31289
32703
|
return isValidName(project) && existsSync(folder) ? folder : null;
|
|
@@ -31334,54 +32748,6 @@ function checkRoutes(access, checks) {
|
|
|
31334
32748
|
});
|
|
31335
32749
|
return app;
|
|
31336
32750
|
}
|
|
31337
|
-
// src/server/routes/envelope.ts
|
|
31338
|
-
/** The status each refusal of a structure or history write answers with. */
|
|
31339
|
-
const STATUS$5 = {
|
|
31340
|
-
usage: 400,
|
|
31341
|
-
"invalid-name": 400,
|
|
31342
|
-
"project-required": 400,
|
|
31343
|
-
"project-not-found": 404,
|
|
31344
|
-
"page-not-found": 404,
|
|
31345
|
-
"frame-not-found": 404,
|
|
31346
|
-
"section-not-found": 404,
|
|
31347
|
-
"name-taken": 409,
|
|
31348
|
-
"stale-layout": 409,
|
|
31349
|
-
"frame-claimed": 409,
|
|
31350
|
-
"undo-overtaken": 409,
|
|
31351
|
-
"nothing-to-undo": 409,
|
|
31352
|
-
"tokens-exist": 409,
|
|
31353
|
-
"stale-tokens": 409,
|
|
31354
|
-
"invalid-edit": 409,
|
|
31355
|
-
"frame-locked": 423,
|
|
31356
|
-
"layout-invalid": 422,
|
|
31357
|
-
"project-file-invalid": 422,
|
|
31358
|
-
"fit-unbounded": 422,
|
|
31359
|
-
"fit-scroll": 422,
|
|
31360
|
-
"claims-invalid": 422,
|
|
31361
|
-
"lock-timeout": 503,
|
|
31362
|
-
"browser-not-found": 503
|
|
31363
|
-
};
|
|
31364
|
-
/**
|
|
31365
|
-
* Answers a refusal in the CLI's `{ ok, error }` envelope, for a route
|
|
31366
|
-
* module's `onError`. Anything else is a fault and goes on to Hono.
|
|
31367
|
-
*/
|
|
31368
|
-
function answerRefusal(error, c) {
|
|
31369
|
-
if (!(error instanceof FrameboardError)) throw error;
|
|
31370
|
-
return c.json({
|
|
31371
|
-
ok: false,
|
|
31372
|
-
error: {
|
|
31373
|
-
code: error.code,
|
|
31374
|
-
message: error.message,
|
|
31375
|
-
details: error.details
|
|
31376
|
-
}
|
|
31377
|
-
}, STATUS$5[error.code] ?? 500);
|
|
31378
|
-
}
|
|
31379
|
-
/** The request's JSON body as the schema reads it, or `usage` naming what failed. */
|
|
31380
|
-
async function parseBody$1(request, schema) {
|
|
31381
|
-
const parsed = schema.safeParse(await request.json().catch(() => null));
|
|
31382
|
-
if (!parsed.success) throw new FrameboardError("usage", `The body ${parsed.error.message}`);
|
|
31383
|
-
return parsed.data;
|
|
31384
|
-
}
|
|
31385
32751
|
// src/server/routes/claims.ts
|
|
31386
32752
|
const ReleaseBody = object$1({ frame: string$1().min(1) });
|
|
31387
32753
|
/**
|
|
@@ -31548,85 +32914,6 @@ function clipboardRoutes(root, access, render, clipboard) {
|
|
|
31548
32914
|
});
|
|
31549
32915
|
return app;
|
|
31550
32916
|
}
|
|
31551
|
-
// src/server/checks/tokens.ts
|
|
31552
|
-
/**
|
|
31553
|
-
* Where a project's token sheets sit, the address file read by plain
|
|
31554
|
-
* `JSON.parse`, since the write hook cannot afford its schema.
|
|
31555
|
-
*/
|
|
31556
|
-
function tokenSheetPaths(root, project, tokens) {
|
|
31557
|
-
const own = join(root, project, TOKEN_FILE);
|
|
31558
|
-
return {
|
|
31559
|
-
board: boardSheetPath(root, tokens),
|
|
31560
|
-
project: existsSync(own) ? own : null
|
|
31561
|
-
};
|
|
31562
|
-
}
|
|
31563
|
-
/** The board's token sheet alone, resolved the way `tokenSheetPaths` resolves it. */
|
|
31564
|
-
function boardSheetPath(root, tokens = recordedTokens(root)) {
|
|
31565
|
-
const board = tokens ?? join(root, "tokens.css");
|
|
31566
|
-
return existsSync(board) ? board : null;
|
|
31567
|
-
}
|
|
31568
|
-
/** The `--tokens` path the board's running server recorded, or null. */
|
|
31569
|
-
function recordedTokens(root) {
|
|
31570
|
-
try {
|
|
31571
|
-
const parsed = JSON.parse(readFileSync(join(root, RUN_FOLDER, ADDRESS_FILE), "utf8"));
|
|
31572
|
-
const tokens = typeof parsed === "object" && parsed !== null && "tokens" in parsed ? parsed.tokens : void 0;
|
|
31573
|
-
return typeof tokens === "string" ? tokens : null;
|
|
31574
|
-
} catch {
|
|
31575
|
-
return null;
|
|
31576
|
-
}
|
|
31577
|
-
}
|
|
31578
|
-
/**
|
|
31579
|
-
* The kit a frame's layout entry names, null for none or a layout that does
|
|
31580
|
-
* not read, parsed plainly as the address file is.
|
|
31581
|
-
*/
|
|
31582
|
-
function frameKit({ root, project, page, name }) {
|
|
31583
|
-
try {
|
|
31584
|
-
return kitOf(keyOf$1(keyOf$1(keyOf$1(JSON.parse(readFileSync(join(root, project, page, LAYOUT_FILE), "utf8")), "frames"), name), "kit"));
|
|
31585
|
-
} catch {
|
|
31586
|
-
return null;
|
|
31587
|
-
}
|
|
31588
|
-
}
|
|
31589
|
-
/** An object's own key, undefined for a value holding none. */
|
|
31590
|
-
function keyOf$1(value, key) {
|
|
31591
|
-
return typeof value === "object" && value !== null && Object.hasOwn(value, key) ? value[key] : void 0;
|
|
31592
|
-
}
|
|
31593
|
-
/**
|
|
31594
|
-
* The kit sheets a frame draws with, as paths under its project in cascade
|
|
31595
|
-
* order: a project-wide kit's where `assets/kit/` holds `kit.json`, then the
|
|
31596
|
-
* tokens and stylesheet of the kit the frame names, each that exists.
|
|
31597
|
-
*/
|
|
31598
|
-
function kitSheetFiles(root, project, kit) {
|
|
31599
|
-
const wide = [ASSETS_FOLDER, "kit"];
|
|
31600
|
-
const named = kitOf(kit);
|
|
31601
|
-
return [...existsSync(join(root, project, ...wide, "kit.json")) ? [[...wide, KIT_SHEET]] : [], ...named ? [TOKEN_FILE, KIT_SHEET].map((file) => [
|
|
31602
|
-
ASSETS_FOLDER,
|
|
31603
|
-
PROJECT_KITS,
|
|
31604
|
-
named,
|
|
31605
|
-
file
|
|
31606
|
-
]) : []].filter((file) => existsSync(join(root, project, ...file))).map((file) => file.join("/"));
|
|
31607
|
-
}
|
|
31608
|
-
/**
|
|
31609
|
-
* The sheets the frame route imports ahead of a frame, being the board's
|
|
31610
|
-
* tokens, the project's, then its kit sheets, which the cascade reads ahead
|
|
31611
|
-
* of the frame's own. `kit` is the kit the frame names, null for a plain one.
|
|
31612
|
-
*/
|
|
31613
|
-
function tokenSheets(root, project, tokens, kit = null) {
|
|
31614
|
-
return readSheets(root, project, tokenSheetPaths(root, project, tokens), kit);
|
|
31615
|
-
}
|
|
31616
|
-
/** `tokenSheets` for a caller already holding the project's sheet paths. */
|
|
31617
|
-
function readSheets(root, project, paths, kit) {
|
|
31618
|
-
const kitSheets = kitSheetFiles(root, project, kit).map((file) => join(root, project, file));
|
|
31619
|
-
return [
|
|
31620
|
-
paths.board,
|
|
31621
|
-
paths.project,
|
|
31622
|
-
...kitSheets
|
|
31623
|
-
].filter((path) => path !== null).map((path) => ({
|
|
31624
|
-
css: readFileSync(path, "utf8"),
|
|
31625
|
-
origin: "token",
|
|
31626
|
-
path,
|
|
31627
|
-
offset: 0
|
|
31628
|
-
}));
|
|
31629
|
-
}
|
|
31630
32917
|
// src/server/edit/start-tag.ts
|
|
31631
32918
|
function isSpace(char) {
|
|
31632
32919
|
return char === " " || char === " " || char === "\n" || char === "\f" || char === "\r";
|
|
@@ -37819,82 +39106,6 @@ function attribute$1(element, name) {
|
|
|
37819
39106
|
const VIEWER_TAG = "model-viewer";
|
|
37820
39107
|
/** The viewer's script as a project's `assets/` holds it, copied in with the first model placed. */
|
|
37821
39108
|
const VIEWER_FILE = "model-viewer.min.js";
|
|
37822
|
-
// src/shared/faces.ts
|
|
37823
|
-
const FACES = [
|
|
37824
|
-
{
|
|
37825
|
-
family: "Geist",
|
|
37826
|
-
package: "@fontsource-variable/geist",
|
|
37827
|
-
packageFamily: "Geist Variable",
|
|
37828
|
-
folder: "geist",
|
|
37829
|
-
weights: {
|
|
37830
|
-
min: 100,
|
|
37831
|
-
max: 900
|
|
37832
|
-
},
|
|
37833
|
-
fallback: "sans-serif",
|
|
37834
|
-
startsLook: true
|
|
37835
|
-
},
|
|
37836
|
-
{
|
|
37837
|
-
family: "Geist Mono",
|
|
37838
|
-
package: "@fontsource-variable/geist-mono",
|
|
37839
|
-
packageFamily: "Geist Mono Variable",
|
|
37840
|
-
folder: "geist-mono",
|
|
37841
|
-
weights: {
|
|
37842
|
-
min: 100,
|
|
37843
|
-
max: 900
|
|
37844
|
-
},
|
|
37845
|
-
fallback: "monospace",
|
|
37846
|
-
startsLook: true
|
|
37847
|
-
},
|
|
37848
|
-
{
|
|
37849
|
-
family: "Inter",
|
|
37850
|
-
package: "@fontsource-variable/inter",
|
|
37851
|
-
packageFamily: "Inter Variable",
|
|
37852
|
-
folder: "inter",
|
|
37853
|
-
weights: {
|
|
37854
|
-
min: 100,
|
|
37855
|
-
max: 900
|
|
37856
|
-
},
|
|
37857
|
-
fallback: "sans-serif",
|
|
37858
|
-
startsLook: true
|
|
37859
|
-
},
|
|
37860
|
-
{
|
|
37861
|
-
family: "Source Serif 4",
|
|
37862
|
-
package: "@fontsource-variable/source-serif-4",
|
|
37863
|
-
packageFamily: "Source Serif 4 Variable",
|
|
37864
|
-
folder: "source-serif-4",
|
|
37865
|
-
weights: {
|
|
37866
|
-
min: 200,
|
|
37867
|
-
max: 900
|
|
37868
|
-
},
|
|
37869
|
-
fallback: "serif",
|
|
37870
|
-
startsLook: true
|
|
37871
|
-
},
|
|
37872
|
-
{
|
|
37873
|
-
family: "Caveat",
|
|
37874
|
-
package: "@fontsource-variable/caveat",
|
|
37875
|
-
packageFamily: "Caveat Variable",
|
|
37876
|
-
folder: "caveat",
|
|
37877
|
-
weights: {
|
|
37878
|
-
min: 400,
|
|
37879
|
-
max: 700
|
|
37880
|
-
},
|
|
37881
|
-
fallback: "cursive",
|
|
37882
|
-
startsLook: false
|
|
37883
|
-
}
|
|
37884
|
-
];
|
|
37885
|
-
/** Where the server serves the faces folder. */
|
|
37886
|
-
const FACES_URL = "/frameboard/faces";
|
|
37887
|
-
/**
|
|
37888
|
-
* The sheet a frame imports to get one face, under the running release so
|
|
37889
|
-
* the server can answer it as cached for good.
|
|
37890
|
-
*/
|
|
37891
|
-
function faceSheetUrl(face) {
|
|
37892
|
-
return `${FACES_URL}/v${version}/${face.folder}/index.css`;
|
|
37893
|
-
}
|
|
37894
|
-
/** The stack naming a face then its fallback, as `'Geist Mono', monospace`. */
|
|
37895
|
-
function faceStack(face) {
|
|
37896
|
-
return `${/\s/.test(face.family) ? `'${face.family}'` : face.family}, ${face.fallback}`;
|
|
37897
|
-
}
|
|
37898
39109
|
// src/shared/starter-tokens.ts
|
|
37899
39110
|
/**
|
|
37900
39111
|
* The looks a new project can start from, each accent paired by hand with a
|
|
@@ -40109,6 +41320,8 @@ async function reads(change, side) {
|
|
|
40109
41320
|
return await exists(present) && !await exists(absent);
|
|
40110
41321
|
}
|
|
40111
41322
|
case "path": return change.present === side ? await exists(change.path) && await hashPath(change.path) === change.hash : !await exists(change.path) && await exists(change.slot);
|
|
41323
|
+
case "replaced": return await exists(change.path) && await exists(change.slot) && await hashPath(change.path) === change.hashes[side];
|
|
41324
|
+
case "rewritten": return await exists(change.path) && await readText(change.path) === change[side];
|
|
40112
41325
|
case "element": return await exists(change.path) && holdsSpan(await readFile(change.path, "utf8"), change.span, side);
|
|
40113
41326
|
case "inserted": return await exists(change.path) && holdsInserted(await readFile(change.path, "utf8"), change.span, side === change.present ? "after" : "before");
|
|
40114
41327
|
case "deleted": return await exists(change.path) && chainDeleted(await readFile(change.path, "utf8"), change, OTHER[side]) !== void 0;
|
|
@@ -40200,6 +41413,13 @@ async function restore(change, side) {
|
|
|
40200
41413
|
if (change.present === side) await rename(change.slot, change.path);
|
|
40201
41414
|
else await takeOut(change.path, change.slot);
|
|
40202
41415
|
return;
|
|
41416
|
+
case "replaced":
|
|
41417
|
+
await swapWithSlot(change.path, change.slot);
|
|
41418
|
+
return;
|
|
41419
|
+
case "rewritten": return rewriteFrame(change, (source) => source === change[OTHER[side]] ? {
|
|
41420
|
+
html: change[side],
|
|
41421
|
+
keep: () => {}
|
|
41422
|
+
} : void 0);
|
|
40203
41423
|
case "element": return rewriteFrame(change, (source) => {
|
|
40204
41424
|
const swapped = swapSpan(source, change.span, OTHER[side]);
|
|
40205
41425
|
return swapped && {
|
|
@@ -40239,6 +41459,13 @@ async function restore(change, side) {
|
|
|
40239
41459
|
case "token": return rewriteToken(change, side);
|
|
40240
41460
|
}
|
|
40241
41461
|
}
|
|
41462
|
+
/** Trades the file's bytes for the ones its slot holds, keeping the others in the slot. */
|
|
41463
|
+
async function swapWithSlot(path, slot) {
|
|
41464
|
+
const aside = `${slot}.swap`;
|
|
41465
|
+
await rename(path, aside);
|
|
41466
|
+
await rename(slot, path);
|
|
41467
|
+
await rename(aside, slot);
|
|
41468
|
+
}
|
|
40242
41469
|
/**
|
|
40243
41470
|
* The frame with a delete's chain restored or taken out again, undefined when
|
|
40244
41471
|
* any one's bytes or gap no longer read.
|
|
@@ -40378,6 +41605,16 @@ var StepJournal = class {
|
|
|
40378
41605
|
span
|
|
40379
41606
|
});
|
|
40380
41607
|
}
|
|
41608
|
+
/** A frame file a hand write rewrote whole on each side, which this journal does not write. */
|
|
41609
|
+
rewritten(path, ref, before, after) {
|
|
41610
|
+
this.changes.push({
|
|
41611
|
+
kind: "rewritten",
|
|
41612
|
+
path,
|
|
41613
|
+
ref,
|
|
41614
|
+
before,
|
|
41615
|
+
after
|
|
41616
|
+
});
|
|
41617
|
+
}
|
|
40381
41618
|
/** The element a placement tool wrote into a frame file, which this journal does not write. */
|
|
40382
41619
|
inserted(path, ref, span) {
|
|
40383
41620
|
this.changes.push({
|
|
@@ -40435,6 +41672,23 @@ var StepJournal = class {
|
|
|
40435
41672
|
slot: this.#slot()
|
|
40436
41673
|
});
|
|
40437
41674
|
}
|
|
41675
|
+
/** Puts the file at `from` in place of `path`, keeping the bytes it replaced in a trash slot. */
|
|
41676
|
+
async replaced(path, from) {
|
|
41677
|
+
const before = await hashPath(path);
|
|
41678
|
+
const after = await hashPath(from);
|
|
41679
|
+
const slot = this.#slot();
|
|
41680
|
+
await takeOut(path, slot);
|
|
41681
|
+
await rename(from, path);
|
|
41682
|
+
this.changes.push({
|
|
41683
|
+
kind: "replaced",
|
|
41684
|
+
path,
|
|
41685
|
+
slot,
|
|
41686
|
+
hashes: {
|
|
41687
|
+
before,
|
|
41688
|
+
after
|
|
41689
|
+
}
|
|
41690
|
+
});
|
|
41691
|
+
}
|
|
40438
41692
|
async removed(path) {
|
|
40439
41693
|
const hash = await hashPath(path);
|
|
40440
41694
|
const slot = this.#slot();
|
|
@@ -40700,7 +41954,7 @@ function flatten(text) {
|
|
|
40700
41954
|
return text.replace(/\s+/g, " ").replace(/[\u0000-\u001f\u007f-\u009f]/g, "").trim();
|
|
40701
41955
|
}
|
|
40702
41956
|
// src/server/notes/store.ts
|
|
40703
|
-
const NOTES_FILE$
|
|
41957
|
+
const NOTES_FILE$1 = "notes.json";
|
|
40704
41958
|
const notesSpec = {
|
|
40705
41959
|
schema: notesFileSchema,
|
|
40706
41960
|
invalidCode: "notes-invalid",
|
|
@@ -40714,7 +41968,7 @@ function newNoteId() {
|
|
|
40714
41968
|
return `n_${randomBytes(4).toString("hex")}`;
|
|
40715
41969
|
}
|
|
40716
41970
|
function notesPath(root, project, page) {
|
|
40717
|
-
return join(root, project, page, NOTES_FILE$
|
|
41971
|
+
return join(root, project, page, NOTES_FILE$1);
|
|
40718
41972
|
}
|
|
40719
41973
|
function readNotes(path) {
|
|
40720
41974
|
return readRecord(path, notesSpec);
|
|
@@ -42194,315 +43448,6 @@ async function savedNames(kits) {
|
|
|
42194
43448
|
return [];
|
|
42195
43449
|
}
|
|
42196
43450
|
}
|
|
42197
|
-
// src/shared/board-urls.ts
|
|
42198
|
-
/** Where the server serves a frame's file, with each name encoded as its own segment. */
|
|
42199
|
-
function frameUrl(ref) {
|
|
42200
|
-
const [project = "", page = "", frame = ""] = ref.split("/");
|
|
42201
|
-
return `/frames/${encodeURIComponent(project)}/${encodeURIComponent(page)}/${encodeURIComponent(frame)}.html`;
|
|
42202
|
-
}
|
|
42203
|
-
/** The board route showing one page of a project. */
|
|
42204
|
-
function boardUrl(project, page) {
|
|
42205
|
-
return `/p/${encodeURIComponent(project)}/${encodeURIComponent(page)}`;
|
|
42206
|
-
}
|
|
42207
|
-
// src/shared/theme.ts
|
|
42208
|
-
const THEMES = ["light", "dark"];
|
|
42209
|
-
/** The query a frame is served with, which its injected script sets `data-theme` from. */
|
|
42210
|
-
const THEME_QUERY = "theme";
|
|
42211
|
-
/**
|
|
42212
|
-
* The attribute on every element the frame route injects. A reader counting
|
|
42213
|
-
* a live frame's elements skips the ones carrying it, so the live index
|
|
42214
|
-
* matches the file's.
|
|
42215
|
-
*/
|
|
42216
|
-
const LOOK_MARKER = "data-frameboard";
|
|
42217
|
-
/**
|
|
42218
|
-
* The attribute on the injected style holding the SHA-256 hex of the bytes
|
|
42219
|
-
* the route served, so a live frame names the exact file an edit addresses.
|
|
42220
|
-
*/
|
|
42221
|
-
const RENDERED_HASH = "data-hash";
|
|
42222
|
-
function isTheme$1(value) {
|
|
42223
|
-
return value === "light" || value === "dark";
|
|
42224
|
-
}
|
|
42225
|
-
/**
|
|
42226
|
-
* Shows a frame's root in `theme`, using nothing outside its own body, since
|
|
42227
|
-
* the frame route embeds its source.
|
|
42228
|
-
*/
|
|
42229
|
-
function setFrameTheme(root, theme) {
|
|
42230
|
-
root.setAttribute("data-theme", theme);
|
|
42231
|
-
root.style.colorScheme = theme;
|
|
42232
|
-
root.classList.toggle("dark", theme === "dark");
|
|
42233
|
-
root.classList.toggle("light", theme === "light");
|
|
42234
|
-
}
|
|
42235
|
-
/**
|
|
42236
|
-
* Where a frame is served in one theme, with `version` naming the reload so
|
|
42237
|
-
* a changed file loads fresh, and `at` naming a version an agent's write
|
|
42238
|
-
* replaced by its content hash.
|
|
42239
|
-
*/
|
|
42240
|
-
function frameThemeUrl(ref, theme, version, at) {
|
|
42241
|
-
const query = new URLSearchParams({ [THEME_QUERY]: theme });
|
|
42242
|
-
if (version !== void 0) query.set("v", String(version));
|
|
42243
|
-
if (at !== void 0) query.set("at", at);
|
|
42244
|
-
return `${frameUrl(ref)}?${query}`;
|
|
42245
|
-
}
|
|
42246
|
-
// src/server/look/inject.ts
|
|
42247
|
-
const BOM = [
|
|
42248
|
-
239,
|
|
42249
|
-
187,
|
|
42250
|
-
191
|
|
42251
|
-
];
|
|
42252
|
-
/**
|
|
42253
|
-
* Shows the frame's root in the theme the frame was served with, through the
|
|
42254
|
-
* same `setFrameTheme` the board calls on a theme change, then removes
|
|
42255
|
-
* itself, so the one injected element a live frame keeps is the stylesheet.
|
|
42256
|
-
*/
|
|
42257
|
-
const THEME_SCRIPT = `(function(s,t){if(t==='light'||t==='dark')(${setFrameTheme.toString()})(document.documentElement,t);s.remove()})(document.currentScript,new URLSearchParams(location.search).get(${JSON.stringify(THEME_QUERY)}))`;
|
|
42258
|
-
/** Where the look route serves the frame bridge's script, under the running release. */
|
|
42259
|
-
const BRIDGE_URL = `/frameboard/bridge/v${version}/frame-bridge.js`;
|
|
42260
|
-
/**
|
|
42261
|
-
* The frame route's injected `head`, one stylesheet carrying `hash` as its one
|
|
42262
|
-
* other attribute, since another element would shift every live index. Given
|
|
42263
|
-
* no `bridge`, as a kit preview's policy allows none, it loads no bridge.
|
|
42264
|
-
*/
|
|
42265
|
-
function frameHead(sheets, hash, bridge) {
|
|
42266
|
-
const imports = sheets.map((url) => `@import url(${JSON.stringify(url)});`);
|
|
42267
|
-
const script = bridge === void 0 ? "" : `<script ${LOOK_MARKER} src=${JSON.stringify(bridge)}><\/script>`;
|
|
42268
|
-
return `<style ${LOOK_MARKER} ${RENDERED_HASH}="${hash}">${imports.join("")}</style><script ${LOOK_MARKER}>${THEME_SCRIPT}<\/script>${script}`;
|
|
42269
|
-
}
|
|
42270
|
-
/**
|
|
42271
|
-
* Splices `head` where the browser starts its `head`, keeping every byte of
|
|
42272
|
-
* the file around it.
|
|
42273
|
-
*/
|
|
42274
|
-
function injectHead(bytes, head) {
|
|
42275
|
-
const offset = headOffset(bytes);
|
|
42276
|
-
const inserted = new TextEncoder().encode(head);
|
|
42277
|
-
const out = new Uint8Array(bytes.length + inserted.length);
|
|
42278
|
-
out.set(bytes.subarray(0, offset));
|
|
42279
|
-
out.set(inserted, offset);
|
|
42280
|
-
out.set(bytes.subarray(offset), offset + inserted.length);
|
|
42281
|
-
return out;
|
|
42282
|
-
}
|
|
42283
|
-
/**
|
|
42284
|
-
* The splice offset, decoded as Latin-1 so parse5's offsets are byte offsets.
|
|
42285
|
-
*/
|
|
42286
|
-
function headOffset(bytes) {
|
|
42287
|
-
const bom = BOM.every((byte, index) => bytes[index] === byte);
|
|
42288
|
-
const text = Buffer.from(bytes).toString("latin1");
|
|
42289
|
-
const document = parse$3(bom ? ` ${text.slice(3)}` : text, { sourceCodeLocationInfo: true });
|
|
42290
|
-
const html = document.childNodes.find(isElement);
|
|
42291
|
-
const stated = (html?.childNodes.find((node) => isElement(node) && node.tagName === "head"))?.sourceCodeLocation?.startTag ?? html?.sourceCodeLocation?.startTag;
|
|
42292
|
-
if (stated) return stated.endOffset;
|
|
42293
|
-
return document.childNodes.find((node) => node.nodeName === "#documentType")?.sourceCodeLocation?.endOffset ?? (bom ? BOM.length : 0);
|
|
42294
|
-
}
|
|
42295
|
-
function isElement(node) {
|
|
42296
|
-
return "tagName" in node;
|
|
42297
|
-
}
|
|
42298
|
-
// src/server/routes/frames.ts
|
|
42299
|
-
const NOTES_FILE$1 = "notes.json";
|
|
42300
|
-
/** Where the look route serves the board's token sheet, whichever file stands in for it. */
|
|
42301
|
-
const BOARD_SHEET_URL = "/frameboard/tokens.css";
|
|
42302
|
-
const CONTENT_TYPES$2 = {
|
|
42303
|
-
".html": "text/html; charset=utf-8",
|
|
42304
|
-
".css": "text/css; charset=utf-8",
|
|
42305
|
-
".js": "text/javascript; charset=utf-8",
|
|
42306
|
-
".mjs": "text/javascript; charset=utf-8",
|
|
42307
|
-
".json": "application/json; charset=utf-8",
|
|
42308
|
-
".txt": "text/plain; charset=utf-8",
|
|
42309
|
-
".svg": "image/svg+xml",
|
|
42310
|
-
".png": "image/png",
|
|
42311
|
-
".jpg": "image/jpeg",
|
|
42312
|
-
".jpeg": "image/jpeg",
|
|
42313
|
-
".gif": "image/gif",
|
|
42314
|
-
".webp": "image/webp",
|
|
42315
|
-
".avif": "image/avif",
|
|
42316
|
-
".ico": "image/x-icon",
|
|
42317
|
-
".woff": "font/woff",
|
|
42318
|
-
".woff2": "font/woff2",
|
|
42319
|
-
".ttf": "font/ttf",
|
|
42320
|
-
".otf": "font/otf",
|
|
42321
|
-
".mp4": "video/mp4",
|
|
42322
|
-
".webm": "video/webm",
|
|
42323
|
-
".mov": "video/quicktime",
|
|
42324
|
-
".m4v": "video/x-m4v",
|
|
42325
|
-
".mp3": "audio/mpeg",
|
|
42326
|
-
".wav": "audio/wav",
|
|
42327
|
-
".ogg": "audio/ogg",
|
|
42328
|
-
".m4a": "audio/mp4",
|
|
42329
|
-
".glb": "model/gltf-binary",
|
|
42330
|
-
".gltf": "model/gltf+json"
|
|
42331
|
-
};
|
|
42332
|
-
/**
|
|
42333
|
-
* Serves the board's frames so relative links resolve unrewritten, its own
|
|
42334
|
-
* handler since it must refuse records, dot-named, and escaping paths, all as
|
|
42335
|
-
* 404 so nothing tells a caller what exists.
|
|
42336
|
-
*/
|
|
42337
|
-
function frameRoutes(root, look, version, base = "") {
|
|
42338
|
-
const app = new Hono();
|
|
42339
|
-
app.get("/frames/*", async (c) => {
|
|
42340
|
-
const parts = decodeSegments(new URL(c.req.url).pathname.slice(8).split("/"));
|
|
42341
|
-
const file = parts && await resolveFile(root, parts);
|
|
42342
|
-
if (!file) return c.notFound();
|
|
42343
|
-
const [project = "", page = "", name = ""] = parts;
|
|
42344
|
-
const isFrame = page !== "assets" && parts.length === 3 && extname(file).toLowerCase() === ".html";
|
|
42345
|
-
const contentType = CONTENT_TYPES$2[extname(file).toLowerCase()] ?? "application/octet-stream";
|
|
42346
|
-
const at = c.req.query("at");
|
|
42347
|
-
const rangeHeader = c.req.header("Range");
|
|
42348
|
-
if (!isFrame && at === void 0 && rangeHeader !== void 0) {
|
|
42349
|
-
const { size } = await stat(file);
|
|
42350
|
-
const range = parseRange(rangeHeader, size);
|
|
42351
|
-
if (range === "unsatisfiable") return c.body(null, 416, {
|
|
42352
|
-
"Content-Range": `bytes */${size}`,
|
|
42353
|
-
"Accept-Ranges": "bytes",
|
|
42354
|
-
"Cache-Control": "no-store"
|
|
42355
|
-
});
|
|
42356
|
-
if (range) {
|
|
42357
|
-
const headers = {
|
|
42358
|
-
"Content-Type": contentType,
|
|
42359
|
-
"Content-Length": String(range.end - range.start + 1),
|
|
42360
|
-
"Content-Range": `bytes ${range.start}-${range.end}/${size}`,
|
|
42361
|
-
"Accept-Ranges": "bytes",
|
|
42362
|
-
"Cache-Control": "no-store"
|
|
42363
|
-
};
|
|
42364
|
-
if (c.req.method === "HEAD") return c.body(null, 206, headers);
|
|
42365
|
-
const stream = Readable.toWeb(createReadStream(file, range));
|
|
42366
|
-
return c.body(stream, 206, headers);
|
|
42367
|
-
}
|
|
42368
|
-
}
|
|
42369
|
-
if (!isFrame && at === void 0) {
|
|
42370
|
-
const tag = weakTag(await stat(file, { bigint: true }));
|
|
42371
|
-
const revalidate = {
|
|
42372
|
-
ETag: tag,
|
|
42373
|
-
"Cache-Control": "no-cache"
|
|
42374
|
-
};
|
|
42375
|
-
if (matchesTag(c.req.header("If-None-Match"), tag)) return c.body(null, 304, revalidate);
|
|
42376
|
-
const headers = {
|
|
42377
|
-
"Content-Type": contentType,
|
|
42378
|
-
"Accept-Ranges": "bytes",
|
|
42379
|
-
...revalidate
|
|
42380
|
-
};
|
|
42381
|
-
if (c.req.method === "HEAD") return c.body(null, 200, headers);
|
|
42382
|
-
return c.body(new Uint8Array(await readFile(file)), 200, headers);
|
|
42383
|
-
}
|
|
42384
|
-
let bytes;
|
|
42385
|
-
if (at === void 0) bytes = new Uint8Array(await readFile(file));
|
|
42386
|
-
else {
|
|
42387
|
-
const ref = `${project}/${page}/${name.slice(0, -5)}`;
|
|
42388
|
-
const held = isFrame ? version?.(ref, at) ?? null : null;
|
|
42389
|
-
if (held === null) return c.notFound();
|
|
42390
|
-
bytes = new TextEncoder().encode(held);
|
|
42391
|
-
}
|
|
42392
|
-
const kit = isFrame ? frameKit({
|
|
42393
|
-
root,
|
|
42394
|
-
project,
|
|
42395
|
-
page,
|
|
42396
|
-
name: name.slice(0, -5)
|
|
42397
|
-
}) : null;
|
|
42398
|
-
const body = injectHead(bytes, frameHead(sheetUrls(project, look.sheets(project), kitSheetFiles(root, project, kit)).map((url) => `${base}${url}`), contentHash(bytes), `${base}${BRIDGE_URL}`));
|
|
42399
|
-
return c.body(body, 200, {
|
|
42400
|
-
"Content-Type": contentType,
|
|
42401
|
-
"Cache-Control": "no-store"
|
|
42402
|
-
});
|
|
42403
|
-
});
|
|
42404
|
-
return app;
|
|
42405
|
-
}
|
|
42406
|
-
/**
|
|
42407
|
-
* A weak validator from a file's size and nanosecond mtime, so a check costs
|
|
42408
|
-
* one stat rather than a read of every byte. A same-size rewrite inside one
|
|
42409
|
-
* timestamp tick keeps its tag, which a coarse mount makes likelier.
|
|
42410
|
-
*/
|
|
42411
|
-
function weakTag({ size, mtimeNs }) {
|
|
42412
|
-
return `W/"${size.toString(16)}-${mtimeNs.toString(16)}"`;
|
|
42413
|
-
}
|
|
42414
|
-
/** Whether an `If-None-Match` header names `tag`, compared weakly per RFC 9110. */
|
|
42415
|
-
function matchesTag(header, tag) {
|
|
42416
|
-
if (header === void 0) return false;
|
|
42417
|
-
if (header.trim() === "*") return true;
|
|
42418
|
-
const opaque = tag.replace(/^W\//, "");
|
|
42419
|
-
return header.split(",").some((listed) => listed.trim().replace(/^W\//, "") === opaque);
|
|
42420
|
-
}
|
|
42421
|
-
/**
|
|
42422
|
-
* The bytes a single range names, null for a header to ignore, which RFC 9110
|
|
42423
|
-
* allows for an unsupported range such as a multi-range.
|
|
42424
|
-
*/
|
|
42425
|
-
function parseRange(header, size) {
|
|
42426
|
-
const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
42427
|
-
if (!match) return null;
|
|
42428
|
-
const [, first = "", last = ""] = match;
|
|
42429
|
-
if (first === "") {
|
|
42430
|
-
if (last === "") return null;
|
|
42431
|
-
const suffix = Number(last);
|
|
42432
|
-
if (suffix === 0) return "unsatisfiable";
|
|
42433
|
-
if (size === 0) return null;
|
|
42434
|
-
return {
|
|
42435
|
-
start: Math.max(0, size - suffix),
|
|
42436
|
-
end: size - 1
|
|
42437
|
-
};
|
|
42438
|
-
}
|
|
42439
|
-
const start = Number(first);
|
|
42440
|
-
const end = last === "" ? size - 1 : Number(last);
|
|
42441
|
-
if (last !== "" && end < start) return null;
|
|
42442
|
-
if (start >= size) return "unsatisfiable";
|
|
42443
|
-
return {
|
|
42444
|
-
start,
|
|
42445
|
-
end: Math.min(end, size - 1)
|
|
42446
|
-
};
|
|
42447
|
-
}
|
|
42448
|
-
/**
|
|
42449
|
-
* The sheets a frame imports, being every face, then the board's tokens, then
|
|
42450
|
-
* the project's, then its kit sheets, which read the tokens and still lose to
|
|
42451
|
-
* the frame's own sheets. `kitFiles` come as `kitSheetFiles` answers them.
|
|
42452
|
-
*/
|
|
42453
|
-
function sheetUrls(project, sheets, kitFiles) {
|
|
42454
|
-
const folder = `/frames/${encodeURIComponent(project)}`;
|
|
42455
|
-
return [
|
|
42456
|
-
...FACES.map(faceSheetUrl),
|
|
42457
|
-
...sheets.board ? [BOARD_SHEET_URL] : [],
|
|
42458
|
-
...sheets.project ? [`${folder}/${TOKEN_FILE}`] : [],
|
|
42459
|
-
...kitFiles.map((file) => `${folder}/${file.split("/").map(encodeURIComponent).join("/")}`)
|
|
42460
|
-
];
|
|
42461
|
-
}
|
|
42462
|
-
function decodeSegments(segments) {
|
|
42463
|
-
const decoded = [];
|
|
42464
|
-
for (const segment of segments) {
|
|
42465
|
-
let name;
|
|
42466
|
-
try {
|
|
42467
|
-
name = decodeURIComponent(segment);
|
|
42468
|
-
} catch {
|
|
42469
|
-
return null;
|
|
42470
|
-
}
|
|
42471
|
-
if (name === "" || name.startsWith(".") || /[/\\\0]/.test(name)) return null;
|
|
42472
|
-
decoded.push(name);
|
|
42473
|
-
}
|
|
42474
|
-
return decoded;
|
|
42475
|
-
}
|
|
42476
|
-
/** The realpath of the file a request names, or null when it is refused or missing. */
|
|
42477
|
-
async function resolveFile(root, [project, page, ...rest]) {
|
|
42478
|
-
if (!project || !page) return null;
|
|
42479
|
-
const projectSheet = rest.length === 0 && page === "tokens.css";
|
|
42480
|
-
if (rest.length === 0 && !projectSheet) return null;
|
|
42481
|
-
if (page !== "assets" && !projectSheet && (rest.length > 1 || isRecord$4(rest[0] ?? ""))) return null;
|
|
42482
|
-
try {
|
|
42483
|
-
const projectDir = await realpath(join(root, project));
|
|
42484
|
-
if (!projectDir.startsWith(root + sep)) return null;
|
|
42485
|
-
const file = await realpath(join(projectDir, page, ...rest));
|
|
42486
|
-
if (!file.startsWith(projectDir + sep)) return null;
|
|
42487
|
-
if (!servableInProject(relative(projectDir, file).split(sep))) return null;
|
|
42488
|
-
return (await stat(file)).isFile() ? file : null;
|
|
42489
|
-
} catch {
|
|
42490
|
-
return null;
|
|
42491
|
-
}
|
|
42492
|
-
}
|
|
42493
|
-
/**
|
|
42494
|
-
* Whether the route may serve a file, read off its real path, so a symlink to
|
|
42495
|
-
* a record or a dot-named path is refused.
|
|
42496
|
-
*/
|
|
42497
|
-
function servableInProject(segments) {
|
|
42498
|
-
if (segments.some((segment) => segment.startsWith("."))) return false;
|
|
42499
|
-
const [first = "", name = ""] = segments;
|
|
42500
|
-
if (segments.length === 1) return first === TOKEN_FILE;
|
|
42501
|
-
return first === "assets" || !isRecord$4(name);
|
|
42502
|
-
}
|
|
42503
|
-
function isRecord$4(name) {
|
|
42504
|
-
return name === "layout.json" || name === NOTES_FILE$1;
|
|
42505
|
-
}
|
|
42506
43451
|
// src/server/routes/kits.ts
|
|
42507
43452
|
const name$1 = string$1().min(1).max(256);
|
|
42508
43453
|
/**
|
|
@@ -42883,7 +43828,7 @@ const STATUS$2 = {
|
|
|
42883
43828
|
"dispatch-failed": 502,
|
|
42884
43829
|
"lock-timeout": 503
|
|
42885
43830
|
};
|
|
42886
|
-
const text$
|
|
43831
|
+
const text$2 = string$1().trim().min(1).max(1e5);
|
|
42887
43832
|
const session = string$1().min(1).max(256);
|
|
42888
43833
|
/** Page-relative paths an upload answered, each checked against the page on write. */
|
|
42889
43834
|
const images = array$1(string$1().max(256)).max(32).optional();
|
|
@@ -42896,7 +43841,7 @@ const oneAddressee = {
|
|
|
42896
43841
|
const pinSchema = object$1({
|
|
42897
43842
|
/** The frame ref, `<project>/<page>/<frame>`. */
|
|
42898
43843
|
frame: string$1().min(1).max(1024),
|
|
42899
|
-
text: text$
|
|
43844
|
+
text: text$2,
|
|
42900
43845
|
images,
|
|
42901
43846
|
/** The element's index, given with the `modifiedAt` the board rendered it at. */
|
|
42902
43847
|
element: int$1().min(0).optional(),
|
|
@@ -42905,7 +43850,7 @@ const pinSchema = object$1({
|
|
|
42905
43850
|
dispatch
|
|
42906
43851
|
}).refine(oneAddressee.check, oneAddressee.message);
|
|
42907
43852
|
const replySchema = object$1({
|
|
42908
|
-
text: text$
|
|
43853
|
+
text: text$2,
|
|
42909
43854
|
images,
|
|
42910
43855
|
to: session.optional(),
|
|
42911
43856
|
dispatch
|
|
@@ -43288,7 +44233,7 @@ function previewRoutes(root, access, slot, { address = networkAddress } = {}) {
|
|
|
43288
44233
|
// src/server/sourcing/save.ts
|
|
43289
44234
|
/** The most bytes one download takes, so a runaway response never fills memory. */
|
|
43290
44235
|
const DOWNLOAD_LIMIT = 67108864;
|
|
43291
|
-
const IMAGE_TYPES = {
|
|
44236
|
+
const IMAGE_TYPES$1 = {
|
|
43292
44237
|
"image/jpeg": "jpg",
|
|
43293
44238
|
"image/png": "png",
|
|
43294
44239
|
"image/webp": "webp",
|
|
@@ -43302,7 +44247,7 @@ const IMAGE_TYPES = {
|
|
|
43302
44247
|
*/
|
|
43303
44248
|
function imageExtension(mediaType, url) {
|
|
43304
44249
|
const type = mediaType?.split(";")[0]?.trim().toLowerCase() ?? "";
|
|
43305
|
-
const fromType = IMAGE_TYPES[type];
|
|
44250
|
+
const fromType = IMAGE_TYPES$1[type];
|
|
43306
44251
|
if (fromType !== void 0) return fromType;
|
|
43307
44252
|
if (url === null) return null;
|
|
43308
44253
|
const name = new URL(url).pathname.split("/").at(-1) ?? "";
|
|
@@ -43315,6 +44260,23 @@ function imageExtension(mediaType, url) {
|
|
|
43315
44260
|
* failed request, a body past `limit`, or a file that is no image.
|
|
43316
44261
|
*/
|
|
43317
44262
|
async function downloadImage(url, send, limit = DOWNLOAD_LIMIT) {
|
|
44263
|
+
const { bytes, mediaType, status } = await download(url, send, limit);
|
|
44264
|
+
const extension = imageExtension(mediaType, url);
|
|
44265
|
+
if (extension === null) throw new FrameboardError("source-failed", "The download is not an image a frame shows.", {
|
|
44266
|
+
url,
|
|
44267
|
+
status
|
|
44268
|
+
});
|
|
44269
|
+
return {
|
|
44270
|
+
bytes,
|
|
44271
|
+
extension
|
|
44272
|
+
};
|
|
44273
|
+
}
|
|
44274
|
+
/**
|
|
44275
|
+
* Downloads one file whole into memory, carrying the Frameboard user agent.
|
|
44276
|
+
* Refuses `source-failed` on a failed request or a body past `limit`, with
|
|
44277
|
+
* the URL and the status in the details.
|
|
44278
|
+
*/
|
|
44279
|
+
async function download(url, send, limit = DOWNLOAD_LIMIT) {
|
|
43318
44280
|
const failed = (message, status) => new FrameboardError("source-failed", message, {
|
|
43319
44281
|
url,
|
|
43320
44282
|
status
|
|
@@ -43323,22 +44285,19 @@ async function downloadImage(url, send, limit = DOWNLOAD_LIMIT) {
|
|
|
43323
44285
|
try {
|
|
43324
44286
|
response = await send(url, { headers: { "User-Agent": `frameboard/${version}` } });
|
|
43325
44287
|
} catch (error) {
|
|
43326
|
-
throw failed(
|
|
44288
|
+
throw failed(`${url} did not download: ${error instanceof Error ? error.message : String(error)}`, null);
|
|
43327
44289
|
}
|
|
43328
|
-
if (!response.ok) throw failed(`The
|
|
43329
|
-
const extension = imageExtension(response.headers.get("content-type"), url);
|
|
43330
|
-
if (extension === null) throw failed("The download is not an image a frame shows.", response.status);
|
|
43331
|
-
let bytes;
|
|
44290
|
+
if (!response.ok) throw failed(`The host of ${url} answered ${response.status}.`, response.status);
|
|
43332
44291
|
try {
|
|
43333
|
-
|
|
44292
|
+
return {
|
|
44293
|
+
bytes: await readCapped(response, limit),
|
|
44294
|
+
mediaType: response.headers.get("content-type"),
|
|
44295
|
+
status: response.status
|
|
44296
|
+
};
|
|
43334
44297
|
} catch (error) {
|
|
43335
44298
|
if (error instanceof FrameboardError) throw error;
|
|
43336
|
-
throw failed(
|
|
44299
|
+
throw failed(`${url} stopped downloading: ${error instanceof Error ? error.message : String(error)}`, response.status);
|
|
43337
44300
|
}
|
|
43338
|
-
return {
|
|
43339
|
-
bytes,
|
|
43340
|
-
extension
|
|
43341
|
-
};
|
|
43342
44301
|
}
|
|
43343
44302
|
/** Reads the body chunk by chunk and stops once it passes `limit`, whatever length the host declared. */
|
|
43344
44303
|
async function readCapped(response, limit) {
|
|
@@ -43364,15 +44323,15 @@ async function readCapped(response, limit) {
|
|
|
43364
44323
|
return bytes;
|
|
43365
44324
|
}
|
|
43366
44325
|
function tooLarge(limit) {
|
|
43367
|
-
return new FrameboardError("source-failed", `The
|
|
44326
|
+
return new FrameboardError("source-failed", `The download is past ${limit / 1024 / 1024} MiB.`, { limit });
|
|
43368
44327
|
}
|
|
43369
44328
|
/**
|
|
43370
44329
|
* The stem a saved file takes: `--name` when given, else the query or prompt
|
|
43371
|
-
* as a lowercase dashed name, else `
|
|
43372
|
-
* `--name` breaking the board name rule.
|
|
44330
|
+
* as a lowercase dashed name, else `fallback`. Refuses `invalid-name` for
|
|
44331
|
+
* a `--name` breaking the board name rule.
|
|
43373
44332
|
*/
|
|
43374
|
-
function savedStem(name, text) {
|
|
43375
|
-
if (name === void 0) return folderName(text) ||
|
|
44333
|
+
function savedStem(name, text, fallback = "image") {
|
|
44334
|
+
if (name === void 0) return folderName(text) || fallback;
|
|
43376
44335
|
if (!isValidName(name)) throw new FrameboardError("invalid-name", `--name ${name} breaks the board's name rule, ${NAME_PATTERN.source}.`, { name });
|
|
43377
44336
|
return name;
|
|
43378
44337
|
}
|
|
@@ -43381,13 +44340,24 @@ function savedStem(name, text) {
|
|
|
43381
44340
|
* from the stem, then its license file as `<landed name>.license.json`. A
|
|
43382
44341
|
* license file that fails to land takes the image back out.
|
|
43383
44342
|
*/
|
|
43384
|
-
|
|
44343
|
+
function saveImage(project, stem, image, license) {
|
|
44344
|
+
return saveWithLicense(project, `${stem}.${image.extension}`, image.bytes, license);
|
|
44345
|
+
}
|
|
44346
|
+
/**
|
|
44347
|
+
* Writes a packed model into the project's `assets/` as `<stem>.glb`, or the
|
|
44348
|
+
* first free name from it, with its license file beside it as `saveImage`
|
|
44349
|
+
* writes an image's.
|
|
44350
|
+
*/
|
|
44351
|
+
function saveModel(project, stem, glb, license) {
|
|
44352
|
+
return saveWithLicense(project, `${stem}.glb`, glb, license);
|
|
44353
|
+
}
|
|
44354
|
+
async function saveWithLicense(project, name, bytes, license) {
|
|
43385
44355
|
const { added, refused } = await addAssets(project.path, [{
|
|
43386
|
-
name
|
|
43387
|
-
bytes
|
|
44356
|
+
name,
|
|
44357
|
+
bytes
|
|
43388
44358
|
}]);
|
|
43389
44359
|
const landed = added[0];
|
|
43390
|
-
if (landed === void 0) throw new FrameboardError("asset-type-refused", refused[0]?.message ??
|
|
44360
|
+
if (landed === void 0) throw new FrameboardError("asset-type-refused", refused[0]?.message ?? `${name} was refused.`);
|
|
43391
44361
|
const folder = join(project.path, ASSETS_FOLDER);
|
|
43392
44362
|
const licensePath = `${landed.path}${LICENSE_FILE_SUFFIX}`;
|
|
43393
44363
|
const temp = join(folder, `${randomBytes(6).toString("hex")}${TEMP_SUFFIX}`);
|
|
@@ -43618,11 +44588,11 @@ const google = {
|
|
|
43618
44588
|
};
|
|
43619
44589
|
/** The first image the interaction output, from `output_image` or else its model output steps. */
|
|
43620
44590
|
function imageOf(body) {
|
|
43621
|
-
if (!isRecord$
|
|
44591
|
+
if (!isRecord$4(body)) return null;
|
|
43622
44592
|
const blocks = [body.output_image];
|
|
43623
|
-
for (const step of Array.isArray(body.steps) ? body.steps : []) if (isRecord$
|
|
44593
|
+
for (const step of Array.isArray(body.steps) ? body.steps : []) if (isRecord$4(step) && step.type === "model_output") blocks.push(...Array.isArray(step.content) ? step.content : []);
|
|
43624
44594
|
for (const block of blocks) {
|
|
43625
|
-
if (!isRecord$
|
|
44595
|
+
if (!isRecord$4(block) || typeof block.data !== "string") continue;
|
|
43626
44596
|
if (block.type !== void 0 && block.type !== "image") continue;
|
|
43627
44597
|
return {
|
|
43628
44598
|
data: block.data,
|
|
@@ -43632,10 +44602,10 @@ function imageOf(body) {
|
|
|
43632
44602
|
return null;
|
|
43633
44603
|
}
|
|
43634
44604
|
function messageOf(body) {
|
|
43635
|
-
if (isRecord$
|
|
44605
|
+
if (isRecord$4(body) && isRecord$4(body.error)) return typeof body.error.message === "string" ? body.error.message : "the request was refused";
|
|
43636
44606
|
return "the request was refused";
|
|
43637
44607
|
}
|
|
43638
|
-
function isRecord$
|
|
44608
|
+
function isRecord$4(value) {
|
|
43639
44609
|
return typeof value === "object" && value !== null;
|
|
43640
44610
|
}
|
|
43641
44611
|
// src/server/sourcing/generate.ts
|
|
@@ -43696,8 +44666,8 @@ async function searchImages(query, options, send) {
|
|
|
43696
44666
|
url.searchParams.set("q", query);
|
|
43697
44667
|
url.searchParams.set("license", licensesFor(options).join(","));
|
|
43698
44668
|
url.searchParams.set("page_size", String(20));
|
|
43699
|
-
const body = await request(url, send);
|
|
43700
|
-
return (isRecord$
|
|
44669
|
+
const body = await request$1(url, send);
|
|
44670
|
+
return (isRecord$3(body) && Array.isArray(body.results) ? body.results : []).map(toImage).filter((image) => image !== null).map((image, index) => ({
|
|
43701
44671
|
number: index + 1,
|
|
43702
44672
|
...image
|
|
43703
44673
|
}));
|
|
@@ -43708,7 +44678,7 @@ async function searchImages(query, options, send) {
|
|
|
43708
44678
|
*/
|
|
43709
44679
|
async function imageById(id, options, send) {
|
|
43710
44680
|
const missing = (reason) => new FrameboardError("result-not-found", reason, { id });
|
|
43711
|
-
const image = toImage(await request(new URL(`${encodeURIComponent(id)}/`, OPENVERSE_API), send, missing));
|
|
44681
|
+
const image = toImage(await request$1(new URL(`${encodeURIComponent(id)}/`, OPENVERSE_API), send, missing));
|
|
43712
44682
|
if (image === null) throw missing(`Openverse holds no image ${id}.`);
|
|
43713
44683
|
const allowed = licensesFor(options);
|
|
43714
44684
|
if (!allowed.includes(image.license)) throw new FrameboardError("result-not-found", `Openverse image ${id} is under ${image.license}, outside ${allowed.join(", ")}. Pass --credited to allow a license that asks for credit.`, {
|
|
@@ -43738,7 +44708,7 @@ function foundLicense(image, query, savedAt) {
|
|
|
43738
44708
|
savedAt: savedAt.toISOString()
|
|
43739
44709
|
};
|
|
43740
44710
|
}
|
|
43741
|
-
async function request(url, send, missing) {
|
|
44711
|
+
async function request$1(url, send, missing) {
|
|
43742
44712
|
let response;
|
|
43743
44713
|
try {
|
|
43744
44714
|
response = await send(url, { headers: { "User-Agent": `frameboard/${version}` } });
|
|
@@ -43764,34 +44734,34 @@ async function request(url, send, missing) {
|
|
|
43764
44734
|
}
|
|
43765
44735
|
/** Openverse's snake_case result as the record's fields, null when it lacks an id, a license, or a URL. */
|
|
43766
44736
|
function toImage(raw) {
|
|
43767
|
-
if (!isRecord$
|
|
43768
|
-
const id = text(raw.id);
|
|
43769
|
-
const license = text(raw.license);
|
|
43770
|
-
const url = text(raw.url);
|
|
44737
|
+
if (!isRecord$3(raw)) return null;
|
|
44738
|
+
const id = text$1(raw.id);
|
|
44739
|
+
const license = text$1(raw.license);
|
|
44740
|
+
const url = text$1(raw.url);
|
|
43771
44741
|
if (id === null || license === null || url === null) return null;
|
|
43772
44742
|
return {
|
|
43773
44743
|
id,
|
|
43774
|
-
title: text(raw.title),
|
|
43775
|
-
creator: text(raw.creator),
|
|
43776
|
-
creatorUrl: text(raw.creator_url),
|
|
44744
|
+
title: text$1(raw.title),
|
|
44745
|
+
creator: text$1(raw.creator),
|
|
44746
|
+
creatorUrl: text$1(raw.creator_url),
|
|
43777
44747
|
license,
|
|
43778
|
-
licenseVersion: text(raw.license_version),
|
|
43779
|
-
licenseUrl: text(raw.license_url),
|
|
43780
|
-
attribution: text(raw.attribution),
|
|
43781
|
-
landingUrl: text(raw.foreign_landing_url),
|
|
44748
|
+
licenseVersion: text$1(raw.license_version),
|
|
44749
|
+
licenseUrl: text$1(raw.license_url),
|
|
44750
|
+
attribution: text$1(raw.attribution),
|
|
44751
|
+
landingUrl: text$1(raw.foreign_landing_url),
|
|
43782
44752
|
url,
|
|
43783
|
-
thumbnail: text(raw.thumbnail),
|
|
43784
|
-
width: integer(raw.width),
|
|
43785
|
-
height: integer(raw.height)
|
|
44753
|
+
thumbnail: text$1(raw.thumbnail),
|
|
44754
|
+
width: integer$1(raw.width),
|
|
44755
|
+
height: integer$1(raw.height)
|
|
43786
44756
|
};
|
|
43787
44757
|
}
|
|
43788
|
-
function isRecord$
|
|
44758
|
+
function isRecord$3(value) {
|
|
43789
44759
|
return typeof value === "object" && value !== null;
|
|
43790
44760
|
}
|
|
43791
|
-
function text(value) {
|
|
44761
|
+
function text$1(value) {
|
|
43792
44762
|
return typeof value === "string" && value !== "" ? value : null;
|
|
43793
44763
|
}
|
|
43794
|
-
function integer(value) {
|
|
44764
|
+
function integer$1(value) {
|
|
43795
44765
|
return typeof value === "number" && Number.isSafeInteger(value) ? value : null;
|
|
43796
44766
|
}
|
|
43797
44767
|
// src/server/routes/sourcing.ts
|
|
@@ -44159,7 +45129,7 @@ const BINDING_RULES = [{
|
|
|
44159
45129
|
severity: "warning",
|
|
44160
45130
|
description: "A control's data-binds names a selector matching an element in its frame, then a custom property opening with \"--\""
|
|
44161
45131
|
}];
|
|
44162
|
-
const finding$
|
|
45132
|
+
const finding$11 = findingFor(BINDING_RULES);
|
|
44163
45133
|
/**
|
|
44164
45134
|
* `binding-target`, one finding per control whose `data-binds` tunes nothing,
|
|
44165
45135
|
* a warning since the frame still renders.
|
|
@@ -44171,7 +45141,7 @@ function checkBindings(source) {
|
|
|
44171
45141
|
if (value === void 0) return [];
|
|
44172
45142
|
const problem = problemOf(value, source);
|
|
44173
45143
|
if (problem === null) return [];
|
|
44174
|
-
return [finding$
|
|
45144
|
+
return [finding$11("binding-target", {
|
|
44175
45145
|
frame: source.ref,
|
|
44176
45146
|
path,
|
|
44177
45147
|
location: attributeLocation(element, BINDS_ATTRIBUTE),
|
|
@@ -44200,7 +45170,7 @@ const BOARD_ROUTE_RULES = [{
|
|
|
44200
45170
|
severity: "error",
|
|
44201
45171
|
description: "A frame's scripts and event handlers name no path under /api/, which on the board's origin reaches the board's own server"
|
|
44202
45172
|
}];
|
|
44203
|
-
const finding$
|
|
45173
|
+
const finding$10 = findingFor(BOARD_ROUTE_RULES);
|
|
44204
45174
|
/**
|
|
44205
45175
|
* A quoted `/api/` path, so prose in a comment does not match, while a path
|
|
44206
45176
|
* built at runtime passes, since the rule catches mistakes, not deliberate calls.
|
|
@@ -44213,7 +45183,7 @@ const BOARD_ROUTE = /(['"`])((?:(?:[a-z][a-z0-9+.-]*:)?\/\/[^/'"`\s]*)?\/api\/[^
|
|
|
44213
45183
|
function checkBoardRoutes(source) {
|
|
44214
45184
|
return frameCode(source).flatMap((code) => [...code.text.matchAll(BOARD_ROUTE)].map((match) => {
|
|
44215
45185
|
const start = code.offset === null ? null : code.offset + match.index;
|
|
44216
|
-
return finding$
|
|
45186
|
+
return finding$10("board-route", {
|
|
44217
45187
|
frame: source.ref,
|
|
44218
45188
|
path: boardPath(source.root, code.path),
|
|
44219
45189
|
message: `${code.via} names ${match[2]}, a route of the board's own server, which a frame on the board's origin reaches. Mock an app's calls with data kept in the script, or list board-route in the project's checks.off if its frames mean to call /api/.`,
|
|
@@ -44267,7 +45237,7 @@ const CONTRAST_RULES = [{
|
|
|
44267
45237
|
configKey: "minContrast",
|
|
44268
45238
|
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."
|
|
44269
45239
|
}];
|
|
44270
|
-
const finding$
|
|
45240
|
+
const finding$9 = findingFor(CONTRAST_RULES);
|
|
44271
45241
|
/** WCAG's large text is 18 pt, or 14 pt bold, which hold 3:1 against 4.5:1. */
|
|
44272
45242
|
const LARGE_SHARE = 2 / 3;
|
|
44273
45243
|
/**
|
|
@@ -44285,7 +45255,7 @@ async function checkContrast(page, target, minContrast) {
|
|
|
44285
45255
|
const others = under.length - 1;
|
|
44286
45256
|
const rest = others === 0 ? "" : `, and ${others} more ${others === 1 ? "element is" : "elements are"} under it`;
|
|
44287
45257
|
const minimum = worst.large ? `${formatRatio(worst.minimum)}:1 minimum for large text` : `${formatRatio(worst.minimum)}:1 minimum`;
|
|
44288
|
-
return [finding$
|
|
45258
|
+
return [finding$9("min-contrast", {
|
|
44289
45259
|
frame: target.ref,
|
|
44290
45260
|
path: target.path,
|
|
44291
45261
|
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}.`
|
|
@@ -44458,7 +45428,7 @@ const DECLARATION_RULES = [{
|
|
|
44458
45428
|
severity: "warning",
|
|
44459
45429
|
description: "A declaration the page's own CSS parser drops, being a misspelled property, a value it cannot read, or a sheet that stops parsing"
|
|
44460
45430
|
}];
|
|
44461
|
-
const finding$
|
|
45431
|
+
const finding$8 = findingFor(DECLARATION_RULES);
|
|
44462
45432
|
/**
|
|
44463
45433
|
* At-rules whose blocks hold descriptors rather than properties, which
|
|
44464
45434
|
* `CSS.supports` cannot answer, and `@supports`, whose block is a
|
|
@@ -44480,7 +45450,7 @@ async function checkDeclarations(page, source) {
|
|
|
44480
45450
|
const path = boardPath(source.root, sheet.path);
|
|
44481
45451
|
const text = sheet.origin === "style" ? source.html : sheet.css;
|
|
44482
45452
|
const { root, errors } = parseSheet$1(sheet.css);
|
|
44483
|
-
for (const error of errors) findings.push(finding$
|
|
45453
|
+
for (const error of errors) findings.push(finding$8("dropped-declaration", {
|
|
44484
45454
|
frame: source.ref,
|
|
44485
45455
|
path,
|
|
44486
45456
|
message: breakMessage(error),
|
|
@@ -44519,7 +45489,7 @@ async function checkDeclarations(page, source) {
|
|
|
44519
45489
|
const supported = await page.evaluate((pairs) => pairs.map(([property, value]) => CSS.supports(property, value)), written.map((each) => [each.property, each.value]));
|
|
44520
45490
|
written.forEach((each, index) => {
|
|
44521
45491
|
if (supported[index]) return;
|
|
44522
|
-
findings.push(finding$
|
|
45492
|
+
findings.push(finding$8("dropped-declaration", {
|
|
44523
45493
|
frame: source.ref,
|
|
44524
45494
|
path: each.path,
|
|
44525
45495
|
message: `The browser drops ${each.property}: ${each.value}, since it reads no such property or no such value for it. Check the spelling of both, and the unit of a length, such as 12px.`,
|
|
@@ -44559,7 +45529,7 @@ const FONT_SIZE_RULES = [{
|
|
|
44559
45529
|
configKey: "minFontSize",
|
|
44560
45530
|
description: "Text renders smaller than the project sets as its minimum size in pixels"
|
|
44561
45531
|
}];
|
|
44562
|
-
const finding$
|
|
45532
|
+
const finding$7 = findingFor(FONT_SIZE_RULES);
|
|
44563
45533
|
/**
|
|
44564
45534
|
* Reports text under `minFontSize` pixels, naming the smallest element and
|
|
44565
45535
|
* how many more fall under, at most one finding per frame.
|
|
@@ -44570,7 +45540,7 @@ async function checkFontSize(page, target, minFontSize) {
|
|
|
44570
45540
|
const smallest = under.reduce((least, text) => text.size < least.size ? text : least);
|
|
44571
45541
|
const others = under.length - 1;
|
|
44572
45542
|
const rest = others === 0 ? "" : `, and ${others} more ${others === 1 ? "element is" : "elements are"} under it`;
|
|
44573
|
-
return [finding$
|
|
45543
|
+
return [finding$7("min-font-size", {
|
|
44574
45544
|
frame: target.ref,
|
|
44575
45545
|
path: target.path,
|
|
44576
45546
|
message: `${target.ref} sets text at ${smallest.size} px in <${smallest.tag}> at element ${smallest.index}, under the project's ${minFontSize} px minimum${rest}.`
|
|
@@ -45324,13 +46294,15 @@ function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
|
|
|
45324
46294
|
const opened = await openFrame(open, {
|
|
45325
46295
|
baseUrl: baseUrl(),
|
|
45326
46296
|
ref: frame.ref,
|
|
45327
|
-
box: frame.box,
|
|
46297
|
+
box: pageSize(frame.box, device),
|
|
45328
46298
|
theme,
|
|
45329
46299
|
scale
|
|
45330
46300
|
});
|
|
45331
46301
|
let shot;
|
|
46302
|
+
let colors = null;
|
|
45332
46303
|
try {
|
|
45333
46304
|
await hideControls(opened.page);
|
|
46305
|
+
if (topInset(device) > 0) colors = await readPageColors(opened.page);
|
|
45334
46306
|
shot = element === void 0 ? await opened.page.screenshot({
|
|
45335
46307
|
animations: "disabled",
|
|
45336
46308
|
caret: "hide"
|
|
@@ -45340,7 +46312,12 @@ function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
|
|
|
45340
46312
|
}
|
|
45341
46313
|
return device ? drawBezel(open, shot, frame.box, {
|
|
45342
46314
|
device,
|
|
45343
|
-
pose: frame.pose
|
|
46315
|
+
pose: frame.pose,
|
|
46316
|
+
island: frame.island,
|
|
46317
|
+
bar: {
|
|
46318
|
+
colors,
|
|
46319
|
+
theme
|
|
46320
|
+
}
|
|
45344
46321
|
}, scale) : shot;
|
|
45345
46322
|
});
|
|
45346
46323
|
queue = run.catch(() => {});
|
|
@@ -45379,12 +46356,17 @@ async function shootElement(page, ref, index, scale) {
|
|
|
45379
46356
|
* A frame's shot drawn inside a device's body, as the board draws it, on a
|
|
45380
46357
|
* page the size of the body, so the PNG holds the body and nothing past it.
|
|
45381
46358
|
*/
|
|
45382
|
-
async function drawBezel(browser, shot, box, { device, pose = "closed" }, scale) {
|
|
46359
|
+
async function drawBezel(browser, shot, box, { device, pose = "closed", island = "compact", bar }, scale) {
|
|
45383
46360
|
const outer = bezelBox({
|
|
45384
46361
|
x: 0,
|
|
45385
46362
|
y: 0,
|
|
45386
46363
|
...box
|
|
45387
46364
|
}, device);
|
|
46365
|
+
const page = pageBox({
|
|
46366
|
+
x: 0,
|
|
46367
|
+
y: 0,
|
|
46368
|
+
...box
|
|
46369
|
+
}, device);
|
|
45388
46370
|
const laptop = device === "laptop";
|
|
45389
46371
|
const context = await browser.newContext({
|
|
45390
46372
|
viewport: {
|
|
@@ -45394,11 +46376,11 @@ async function drawBezel(browser, shot, box, { device, pose = "closed" }, scale)
|
|
|
45394
46376
|
deviceScaleFactor: scale
|
|
45395
46377
|
});
|
|
45396
46378
|
try {
|
|
45397
|
-
const
|
|
45398
|
-
const marks = device === "phone" ?
|
|
46379
|
+
const tab = await context.newPage();
|
|
46380
|
+
const marks = device === "phone" ? statusBarHtml(bar.colors, bar.theme) + phoneMarks(island) : laptop ? laptopMarks(box) : device === "foldable" ? foldableMarks(pose) : "";
|
|
45399
46381
|
const radius = screenCorners(device);
|
|
45400
|
-
await
|
|
45401
|
-
return await
|
|
46382
|
+
await tab.setContent(`<!doctype html><html><body style="margin:0;background:transparent"><div style="position:absolute;left:${-outer.x}px;top:${-outer.y}px;width:${box.width}px;height:${box.height}px"><img alt="" src="data:image/png;base64,${shot.toString("base64")}" style="position:absolute;left:0;top:${page.y}px;width:${page.width}px;height:${page.height}px;border-radius:${pageCorners(device)}"><div style="position:absolute;inset:0;border-radius:${radius};box-shadow:${bezelShadow(device, { board: false })}">${marks}</div></div></body></html>`, { waitUntil: "load" });
|
|
46383
|
+
return await tab.screenshot({
|
|
45402
46384
|
omitBackground: true,
|
|
45403
46385
|
caret: "hide"
|
|
45404
46386
|
});
|
|
@@ -45407,6 +46389,56 @@ async function drawBezel(browser, shot, box, { device, pose = "closed" }, scale)
|
|
|
45407
46389
|
}
|
|
45408
46390
|
}
|
|
45409
46391
|
/**
|
|
46392
|
+
* A phone frame's shot of its page set under the status bar, at the frame's
|
|
46393
|
+
* box with no body, so a capture holds the screen the board draws.
|
|
46394
|
+
*/
|
|
46395
|
+
async function underStatusBar(browser, shot, box, { colors, theme }, scale) {
|
|
46396
|
+
const page = pageBox({
|
|
46397
|
+
x: 0,
|
|
46398
|
+
y: 0,
|
|
46399
|
+
...box
|
|
46400
|
+
}, "phone");
|
|
46401
|
+
const context = await browser.newContext({
|
|
46402
|
+
viewport: box,
|
|
46403
|
+
deviceScaleFactor: scale
|
|
46404
|
+
});
|
|
46405
|
+
try {
|
|
46406
|
+
const tab = await context.newPage();
|
|
46407
|
+
await tab.setContent(`<!doctype html><html><body style="margin:0;position:relative;width:${box.width}px;height:${box.height}px"><img alt="" src="data:image/png;base64,${shot.toString("base64")}" style="position:absolute;left:0;top:${page.y}px;width:${page.width}px;height:${page.height}px">` + statusBarHtml(colors, theme, { rounded: false }) + `</body></html>`, { waitUntil: "load" });
|
|
46408
|
+
return await tab.screenshot({ caret: "hide" });
|
|
46409
|
+
} finally {
|
|
46410
|
+
await context.close();
|
|
46411
|
+
}
|
|
46412
|
+
}
|
|
46413
|
+
/** A loaded page's fill and text color, which the browser reads off its own document. */
|
|
46414
|
+
function readPageColors(page) {
|
|
46415
|
+
return page.evaluate(pageColors);
|
|
46416
|
+
}
|
|
46417
|
+
/** The viewport a frame's page opens at, its box less a phone's status bar, at least one pixel tall. */
|
|
46418
|
+
function pageSize(box, device) {
|
|
46419
|
+
const page = pageBox({
|
|
46420
|
+
x: 0,
|
|
46421
|
+
y: 0,
|
|
46422
|
+
...box
|
|
46423
|
+
}, device);
|
|
46424
|
+
return {
|
|
46425
|
+
width: page.width,
|
|
46426
|
+
height: Math.max(1, page.height)
|
|
46427
|
+
};
|
|
46428
|
+
}
|
|
46429
|
+
/**
|
|
46430
|
+
* The phone's status bar as the board draws it, in the page's fill and text
|
|
46431
|
+
* color or its theme's own, its top corners rounded to the screen inside a
|
|
46432
|
+
* body and square on a frame's bare box.
|
|
46433
|
+
*/
|
|
46434
|
+
function statusBarHtml(colors, theme, { rounded = true } = {}) {
|
|
46435
|
+
const { screenRadius } = BEZELS.phone;
|
|
46436
|
+
const corners = rounded ? `${screenRadius}px ${screenRadius}px 0 0` : "0";
|
|
46437
|
+
const signal = SIGNAL_BARS.map((tall) => `<span style="width:3px;height:${tall}px;border-radius:1px;background:currentColor"></span>`).join("");
|
|
46438
|
+
const battery = `<span style="display:flex;align-items:center"><span style="box-sizing:border-box;display:flex;align-items:center;width:${BATTERY.width}px;height:${BATTERY.height}px;border:1px solid currentColor;border-radius:${BATTERY.radius}px;padding:1.5px;opacity:.9"><span style="width:80%;height:100%;border-radius:2px;background:currentColor"></span></span><span style="width:${BATTERY.cap}px;height:4px;margin-left:1px;border-radius:0 1px 1px 0;background:currentColor;opacity:.6"></span></span>`;
|
|
46439
|
+
return `<div style="position:absolute;left:0;right:0;top:0;height:${STATUS_BAR.height}px;border-radius:${corners};color-scheme:${theme};background:${colors?.fill ?? "Canvas"};color:${colors?.ink ?? "CanvasText"}"><div style="position:absolute;left:0;right:0;top:${STATUS_BAR.band.top}px;height:${STATUS_BAR.band.height}px;box-sizing:border-box;display:flex;align-items:center;justify-content:space-between;padding:0 ${STATUS_BAR.side}px;font:600 ${STATUS_BAR.font}px/1 ${STATUS_FONT};font-variant-numeric:tabular-nums"><span>${STATUS_BAR.time}</span><span style="display:flex;align-items:center;gap:6px"><span style="display:flex;align-items:flex-end;gap:2px">${signal}</span>${battery}</span></div></div>`;
|
|
46440
|
+
}
|
|
46441
|
+
/**
|
|
45410
46442
|
* The laptop's chin and base as the board draws them, past the screen's
|
|
45411
46443
|
* bottom, with the body's edge as its last pixel rather than past it.
|
|
45412
46444
|
*/
|
|
@@ -45415,6 +46447,14 @@ function laptopMarks(box) {
|
|
|
45415
46447
|
const edge = `1px solid ${BEZEL_COLORS.edge}`;
|
|
45416
46448
|
return `<span style="position:absolute;box-sizing:border-box;left:${chin.x}px;top:${chin.y}px;width:${chin.width}px;height:${chin.height}px;background:${BEZEL_COLORS.body};border-left:${edge};border-right:${edge}"></span><span style="position:absolute;box-sizing:border-box;left:${base.x}px;top:${base.y}px;width:${base.width}px;height:${base.height}px;background:${BEZEL_COLORS.base};border:${edge};border-radius:0 0 ${LAPTOP_BASE.radius}px ${LAPTOP_BASE.radius}px"></span>`;
|
|
45417
46449
|
}
|
|
46450
|
+
/** The phone's buttons, island, and home bar as the board draws them. */
|
|
46451
|
+
function phoneMarks(island) {
|
|
46452
|
+
const { border } = BEZELS.phone;
|
|
46453
|
+
const buttons = PHONE_BUTTONS.map(({ side, top, height }) => `<span style="position:absolute;${side}:${-border - 4}px;top:${top - border}px;width:4px;height:${height}px;border-radius:2px;background:${BEZEL_COLORS.button}"></span>`).join("");
|
|
46454
|
+
const shape = phoneIsland(island);
|
|
46455
|
+
const timer = island === "wide" ? `<span style="display:flex;align-items:center;gap:5px"><span style="width:6px;height:6px;border-radius:3px;background:${BEZEL_COLORS.islandLive}"></span>${WIDE_ISLAND_TIMER}</span><span style="display:flex;align-items:flex-end;gap:2px">${WIDE_ISLAND_LEVEL.map((tall) => `<span style="width:2px;height:${tall}px;border-radius:1px;background:${BEZEL_COLORS.islandLive}"></span>`).join("")}</span>` : "";
|
|
46456
|
+
return buttons + `<span style="${pill(shape.width, shape.height, BEZEL_COLORS.island)}top:${shape.top}px;box-sizing:border-box;display:flex;align-items:center;justify-content:space-between;padding:0 11px;color:${BEZEL_COLORS.islandText};font:600 11px/1 ${STATUS_FONT};font-variant-numeric:tabular-nums">${timer}</span><span style="${pill(HOME_BAR.width, HOME_BAR.height, BEZEL_COLORS.homeBar)}bottom:${HOME_BAR.bottom}px"></span>`;
|
|
46457
|
+
}
|
|
45418
46458
|
/** The foldable's fold band, island, and home bar as the board draws them for a pose. */
|
|
45419
46459
|
function foldableMarks(pose) {
|
|
45420
46460
|
const band = foldBand(pose);
|
|
@@ -45520,7 +46560,7 @@ async function fitFrame(browser, { baseUrl, frame, ...options }) {
|
|
|
45520
46560
|
const measured = await measureContent(browser, {
|
|
45521
46561
|
baseUrl,
|
|
45522
46562
|
ref: frame.ref,
|
|
45523
|
-
box: frame.box,
|
|
46563
|
+
box: pageBox(frame.box, frame.device),
|
|
45524
46564
|
hugWidth: false
|
|
45525
46565
|
});
|
|
45526
46566
|
const widths = [];
|
|
@@ -45540,7 +46580,7 @@ async function fitFrame(browser, { baseUrl, frame, ...options }) {
|
|
|
45540
46580
|
});
|
|
45541
46581
|
}
|
|
45542
46582
|
return {
|
|
45543
|
-
frame: await fitHeight(options.root, frame.ref, measured.height, {
|
|
46583
|
+
frame: await fitHeight(options.root, frame.ref, measured.height + topInset(frame.device), {
|
|
45544
46584
|
...options,
|
|
45545
46585
|
widths
|
|
45546
46586
|
}),
|
|
@@ -45677,7 +46717,7 @@ const LAYOUT_RULES = [
|
|
|
45677
46717
|
description: "Content sizes itself off the viewport height rather than holding a height of its own, a warning since a full-height screen does it on purpose"
|
|
45678
46718
|
}
|
|
45679
46719
|
];
|
|
45680
|
-
const finding$
|
|
46720
|
+
const finding$6 = findingFor(LAYOUT_RULES);
|
|
45681
46721
|
/**
|
|
45682
46722
|
* The slack a reading takes before it counts, so a subpixel edge rounding up
|
|
45683
46723
|
* is never a finding. One pixel matches what the groundwork spike measured.
|
|
@@ -45722,7 +46762,7 @@ function clipped(target, read) {
|
|
|
45722
46762
|
if (!tall && !wide) return null;
|
|
45723
46763
|
const past = shown.filter((box) => tall && box.bottom > height + SLACK_PX || wide && box.right > width + SLACK_PX);
|
|
45724
46764
|
const reach = [tall ? `${bottom} px tall in its ${height} px height` : null, wide ? `${right} px wide in its ${width} px width` : null].filter((part) => part !== null).join(" and ");
|
|
45725
|
-
return finding$
|
|
46765
|
+
return finding$6("clipped", {
|
|
45726
46766
|
frame: target.ref,
|
|
45727
46767
|
path: target.path,
|
|
45728
46768
|
message: `${target.ref} is ${reach}, so the board cuts it off${offenders(past, "past the box")}. ${clippedAdvice(tall, wide, width)}`
|
|
@@ -45738,7 +46778,7 @@ function scrollbar(target, read) {
|
|
|
45738
46778
|
const [first] = scrolling;
|
|
45739
46779
|
if (!first) return null;
|
|
45740
46780
|
const by = Math.max(first.overflowX, first.overflowY);
|
|
45741
|
-
return finding$
|
|
46781
|
+
return finding$6("scrollbar", {
|
|
45742
46782
|
frame: target.ref,
|
|
45743
46783
|
path: target.path,
|
|
45744
46784
|
message: `${target.ref} scrolls inside ${element(first)}, whose content is ${by} px past its box${more(scrolling.length - 1, "scrolls", "scroll")}. Size it to its content, or set overflow to hidden.`
|
|
@@ -45748,7 +46788,7 @@ function viewport(target, atBox, atTall, boxRead, tallRead) {
|
|
|
45748
46788
|
if (atTall <= atBox + SLACK_PX) return null;
|
|
45749
46789
|
const before = new Map(boxRead.boxes.map((box) => [box.index, box.height]));
|
|
45750
46790
|
const grown = tallRead.boxes.filter((box) => box.height > (before.get(box.index) ?? box.height) + SLACK_PX);
|
|
45751
|
-
return finding$
|
|
46791
|
+
return finding$6("viewport", {
|
|
45752
46792
|
frame: target.ref,
|
|
45753
46793
|
path: target.path,
|
|
45754
46794
|
message: `${target.ref} grows with the viewport, measuring ${atBox} px at its ${target.box.height} px height and ${atTall} px at twice that${offenders(grown, "growing")}. Give it a height of its own unless it is a full-height screen on purpose.`
|
|
@@ -45880,7 +46920,7 @@ const SCROLL_EFFECT_RULES = [{
|
|
|
45880
46920
|
severity: "warning",
|
|
45881
46921
|
description: "A frame whose height hugs its content holds an effect driven by scrolling, being position: sticky, a window or document scroll listener, or a scroll or view timeline, which never runs since the frame never scrolls"
|
|
45882
46922
|
}];
|
|
45883
|
-
const finding$
|
|
46923
|
+
const finding$5 = findingFor(SCROLL_EFFECT_RULES);
|
|
45884
46924
|
/**
|
|
45885
46925
|
* `scroll-effect`, at most one finding on a hugging frame, counting listeners
|
|
45886
46926
|
* on the window or document alone, so a missed one costs a hint, never an error.
|
|
@@ -45889,7 +46929,7 @@ async function checkScrollEffect(page, target) {
|
|
|
45889
46929
|
if (target.scroll || !target.hugHeight) return [];
|
|
45890
46930
|
const trigger = await page.evaluate(readScrollStyles) ?? await readListener(page);
|
|
45891
46931
|
if (!trigger) return [];
|
|
45892
|
-
return [finding$
|
|
46932
|
+
return [finding$5("scroll-effect", {
|
|
45893
46933
|
frame: target.ref,
|
|
45894
46934
|
path: target.path,
|
|
45895
46935
|
message: `${target.ref} ${describe$7(trigger)}, which needs the frame to scroll, but its height hugs the content so it never does. Run frame resize --scroll to hold a screen height and scroll past it.`
|
|
@@ -45963,7 +47003,7 @@ const CUSTOM_PROPERTY_RULES = [{
|
|
|
45963
47003
|
severity: "warning",
|
|
45964
47004
|
description: "A var() with no fallback names a custom property no token sheet, frame sheet, style attribute, or script write declares"
|
|
45965
47005
|
}];
|
|
45966
|
-
const finding$
|
|
47006
|
+
const finding$4 = findingFor(CUSTOM_PROPERTY_RULES);
|
|
45967
47007
|
/** A `var()` naming its property, with no fallback after a comma. */
|
|
45968
47008
|
const BARE_VAR = /var\(\s*(--[\w-]+)\s*\)/g;
|
|
45969
47009
|
/**
|
|
@@ -46015,7 +47055,7 @@ function checkUnknownTokens(source, tokens) {
|
|
|
46015
47055
|
if (element.name !== "script") continue;
|
|
46016
47056
|
for (const name of scriptWrites(scriptText(element, source))) declared.add(name);
|
|
46017
47057
|
}
|
|
46018
|
-
return uses.filter((use) => !declared.has(use.name)).map((use) => finding$
|
|
47058
|
+
return uses.filter((use) => !declared.has(use.name)).map((use) => finding$4("unknown-token", {
|
|
46019
47059
|
frame: source.ref,
|
|
46020
47060
|
path: use.path,
|
|
46021
47061
|
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.`,
|
|
@@ -46070,7 +47110,7 @@ const FONT_RULES = [
|
|
|
46070
47110
|
description: "Every text element's first family is one of the project's allowed fonts"
|
|
46071
47111
|
}
|
|
46072
47112
|
];
|
|
46073
|
-
const finding$
|
|
47113
|
+
const finding$3 = findingFor(FONT_RULES);
|
|
46074
47114
|
const GENERIC_FAMILIES = /* @__PURE__ */ new Set([
|
|
46075
47115
|
"serif",
|
|
46076
47116
|
"sans-serif",
|
|
@@ -46113,7 +47153,7 @@ function checkFonts(source, cascade, config) {
|
|
|
46113
47153
|
else if (allowed && !allowed.includes(family.toLowerCase())) push(unlisted, family, element);
|
|
46114
47154
|
}
|
|
46115
47155
|
const path = boardPath(source.root, source.path);
|
|
46116
|
-
const at = (rule, elements, message) => finding$
|
|
47156
|
+
const at = (rule, elements, message) => finding$3(rule, {
|
|
46117
47157
|
frame: source.ref,
|
|
46118
47158
|
path,
|
|
46119
47159
|
message: `${message} ${described(elements)}`,
|
|
@@ -46142,173 +47182,6 @@ function push(map, key, element) {
|
|
|
46142
47182
|
if (list) list.push(element);
|
|
46143
47183
|
else map.set(key, [element]);
|
|
46144
47184
|
}
|
|
46145
|
-
// src/server/checks/links.ts
|
|
46146
|
-
const LINK_RULES = [
|
|
46147
|
-
{
|
|
46148
|
-
id: "outside-link",
|
|
46149
|
-
tier: "exact",
|
|
46150
|
-
severity: "error",
|
|
46151
|
-
description: "A frame loads files from its own page folder and its project's assets/ folder alone, never from a sibling page or the server root"
|
|
46152
|
-
},
|
|
46153
|
-
{
|
|
46154
|
-
id: "network",
|
|
46155
|
-
tier: "exact",
|
|
46156
|
-
severity: "error",
|
|
46157
|
-
description: "A frame loads nothing over the network, while a navigation link passes"
|
|
46158
|
-
},
|
|
46159
|
-
{
|
|
46160
|
-
id: "missing-file",
|
|
46161
|
-
tier: "exact",
|
|
46162
|
-
severity: "error",
|
|
46163
|
-
description: "Every local file a frame loads exists"
|
|
46164
|
-
}
|
|
46165
|
-
];
|
|
46166
|
-
const finding$3 = findingFor(LINK_RULES);
|
|
46167
|
-
/** The attributes a `<model-viewer>` loads a file through, which `docs` states beside the rule. */
|
|
46168
|
-
const MODEL_LOADS = [
|
|
46169
|
-
"src",
|
|
46170
|
-
"poster",
|
|
46171
|
-
"environment-image",
|
|
46172
|
-
"skybox-image"
|
|
46173
|
-
];
|
|
46174
|
-
/**
|
|
46175
|
-
* The attributes that load a resource, by element. An `a href` navigates
|
|
46176
|
-
* rather than loads, so it is left out.
|
|
46177
|
-
*/
|
|
46178
|
-
const RESOURCE_ATTRIBUTES = {
|
|
46179
|
-
link: ["href"],
|
|
46180
|
-
script: ["src"],
|
|
46181
|
-
img: ["src", "srcset"],
|
|
46182
|
-
source: ["src", "srcset"],
|
|
46183
|
-
video: ["src", "poster"],
|
|
46184
|
-
audio: ["src"],
|
|
46185
|
-
track: ["src"],
|
|
46186
|
-
iframe: ["src"],
|
|
46187
|
-
embed: ["src"],
|
|
46188
|
-
object: ["data"],
|
|
46189
|
-
input: ["src"],
|
|
46190
|
-
image: ["href", "xlink:href"],
|
|
46191
|
-
use: ["href", "xlink:href"],
|
|
46192
|
-
"model-viewer": [...MODEL_LOADS]
|
|
46193
|
-
};
|
|
46194
|
-
/** The lighting a viewer builds itself, which `environment-image` names in place of a file. */
|
|
46195
|
-
const BUILT_IN_ENVIRONMENTS = /* @__PURE__ */ new Set(["neutral", "legacy"]);
|
|
46196
|
-
/** `outside-link`, `network`, and `missing-file` over every load a frame makes. */
|
|
46197
|
-
function checkLinks(source) {
|
|
46198
|
-
return frameLoads(source).flatMap((load) => judge(source, load));
|
|
46199
|
-
}
|
|
46200
|
-
/**
|
|
46201
|
-
* Every resource a frame loads, from its elements' attributes and inline
|
|
46202
|
-
* styles and from each sheet it renders with, unjudged. The link check and the
|
|
46203
|
-
* asset usage count read this one list, so they never disagree on a load.
|
|
46204
|
-
*/
|
|
46205
|
-
function frameLoads(source) {
|
|
46206
|
-
const framePath = boardPath(source.root, source.path);
|
|
46207
|
-
const loads = [];
|
|
46208
|
-
for (const element of source.elements) {
|
|
46209
|
-
for (const name of RESOURCE_ATTRIBUTES[element.name] ?? []) {
|
|
46210
|
-
const value = element.attribs[name];
|
|
46211
|
-
if (value === void 0) continue;
|
|
46212
|
-
if (name === "environment-image" && BUILT_IN_ENVIRONMENTS.has(value)) continue;
|
|
46213
|
-
const urls = name === "srcset" ? srcsetUrls(value) : [value];
|
|
46214
|
-
for (const url of urls) loads.push({
|
|
46215
|
-
url,
|
|
46216
|
-
base: source.pageDir,
|
|
46217
|
-
path: framePath,
|
|
46218
|
-
location: attributeLocation(element, name),
|
|
46219
|
-
via: `<${element.name} ${name}>`
|
|
46220
|
-
});
|
|
46221
|
-
}
|
|
46222
|
-
const style = element.attribs.style;
|
|
46223
|
-
if (style !== void 0) for (const { url } of cssUrls(`x{${style}}`)) loads.push({
|
|
46224
|
-
url,
|
|
46225
|
-
base: source.pageDir,
|
|
46226
|
-
path: framePath,
|
|
46227
|
-
location: attributeLocation(element, "style"),
|
|
46228
|
-
via: `a style attribute's url()`
|
|
46229
|
-
});
|
|
46230
|
-
}
|
|
46231
|
-
for (const sheet of source.sheets) loads.push(...sheetLoads(source, sheet));
|
|
46232
|
-
return loads;
|
|
46233
|
-
}
|
|
46234
|
-
function sheetLoads(source, sheet) {
|
|
46235
|
-
const path = boardPath(source.root, sheet.path);
|
|
46236
|
-
const text = sheet.origin === "style" ? source.html : sheet.css;
|
|
46237
|
-
return cssUrls(sheet.css).map(({ url, start, end, kind }) => ({
|
|
46238
|
-
url,
|
|
46239
|
-
base: sheetBase(sheet),
|
|
46240
|
-
path,
|
|
46241
|
-
location: locate$1(text, sheet.offset + start, sheet.offset + end),
|
|
46242
|
-
via: kind === "import" ? "@import" : "url()"
|
|
46243
|
-
}));
|
|
46244
|
-
}
|
|
46245
|
-
function judge(source, load) {
|
|
46246
|
-
const url = load.url.trim();
|
|
46247
|
-
if (url === "" || url.startsWith("#") || /^(data|blob|about):/i.test(url)) return [];
|
|
46248
|
-
const fields = {
|
|
46249
|
-
frame: source.ref,
|
|
46250
|
-
path: load.path,
|
|
46251
|
-
location: load.location
|
|
46252
|
-
};
|
|
46253
|
-
if (hasScheme(url)) return [finding$3("network", {
|
|
46254
|
-
...fields,
|
|
46255
|
-
message: `${load.via} loads ${url} over the network. Save the file into the page folder or the project's assets/ and link it there.`
|
|
46256
|
-
})];
|
|
46257
|
-
const target = localTarget(url, load.base);
|
|
46258
|
-
if (target === null || !allowed(source, target)) return [finding$3("outside-link", {
|
|
46259
|
-
...fields,
|
|
46260
|
-
message: `${load.via} loads ${url}, outside this page's folder and the project's assets/. Move the file into one of them.`
|
|
46261
|
-
})];
|
|
46262
|
-
if (!existsSync(target)) return [finding$3("missing-file", {
|
|
46263
|
-
...fields,
|
|
46264
|
-
message: `${load.via} loads ${url}, which does not exist.`
|
|
46265
|
-
})];
|
|
46266
|
-
return [];
|
|
46267
|
-
}
|
|
46268
|
-
/**
|
|
46269
|
-
* Inside the page folder or the project's `assets/`, both by path and, for a
|
|
46270
|
-
* file that exists, by realpath, so a symlink out of the project is caught.
|
|
46271
|
-
*/
|
|
46272
|
-
function allowed(source, target) {
|
|
46273
|
-
const assets = assetsDirOf(source);
|
|
46274
|
-
if (!isInside(source.pageDir, target) && !isInside(assets, target)) return false;
|
|
46275
|
-
if (!existsSync(target)) return true;
|
|
46276
|
-
const real = realpathSync(target);
|
|
46277
|
-
const projectDir = realpathSync(source.projectDir);
|
|
46278
|
-
return isInside(realpathSync(source.pageDir), real) || isInside(join(projectDir, "assets"), real);
|
|
46279
|
-
}
|
|
46280
|
-
function srcsetUrls(value) {
|
|
46281
|
-
return value.split(",").map((candidate) => candidate.trim().split(/\s+/)[0] ?? "").filter((url) => url !== "");
|
|
46282
|
-
}
|
|
46283
|
-
/** Every `url()` and `@import` in a sheet. A sheet that does not parse loads nothing. */
|
|
46284
|
-
function cssUrls(css) {
|
|
46285
|
-
const urls = [];
|
|
46286
|
-
let root;
|
|
46287
|
-
try {
|
|
46288
|
-
root = postcss_default.parse(css);
|
|
46289
|
-
} catch {
|
|
46290
|
-
return urls;
|
|
46291
|
-
}
|
|
46292
|
-
root.walk((node) => {
|
|
46293
|
-
const start = node.source?.start?.offset ?? 0;
|
|
46294
|
-
const end = node.source?.end?.offset ?? start;
|
|
46295
|
-
if (node.type === "atrule" && node.name.toLowerCase() === "import") {
|
|
46296
|
-
const url = importUrl(node.params);
|
|
46297
|
-
if (url !== null) urls.push({
|
|
46298
|
-
url,
|
|
46299
|
-
start,
|
|
46300
|
-
end,
|
|
46301
|
-
kind: "import"
|
|
46302
|
-
});
|
|
46303
|
-
} else if (node.type === "decl") for (const match of node.value.matchAll(/url\(\s*(['"]?)(.*?)\1\s*\)/gi)) urls.push({
|
|
46304
|
-
url: match[2] ?? "",
|
|
46305
|
-
start,
|
|
46306
|
-
end,
|
|
46307
|
-
kind: "url"
|
|
46308
|
-
});
|
|
46309
|
-
});
|
|
46310
|
-
return urls;
|
|
46311
|
-
}
|
|
46312
47185
|
// src/server/checks/structure.ts
|
|
46313
47186
|
const STRUCTURE_RULES = [
|
|
46314
47187
|
{
|
|
@@ -46625,8 +47498,8 @@ function readConfig(root, project) {
|
|
|
46625
47498
|
} catch {
|
|
46626
47499
|
return {};
|
|
46627
47500
|
}
|
|
46628
|
-
const checks = isRecord$
|
|
46629
|
-
if (!isRecord$
|
|
47501
|
+
const checks = isRecord$2(parsed) ? parsed.checks : void 0;
|
|
47502
|
+
if (!isRecord$2(checks)) return {};
|
|
46630
47503
|
const config = {};
|
|
46631
47504
|
if (Array.isArray(checks.allowedFonts) && checks.allowedFonts.every((font) => typeof font === "string")) config.allowedFonts = checks.allowedFonts;
|
|
46632
47505
|
if (typeof checks.noUppercase === "boolean") config.noUppercase = checks.noUppercase;
|
|
@@ -46635,7 +47508,7 @@ function readConfig(root, project) {
|
|
|
46635
47508
|
if (Array.isArray(checks.off) && checks.off.every((rule) => typeof rule === "string")) config.off = checks.off;
|
|
46636
47509
|
return config;
|
|
46637
47510
|
}
|
|
46638
|
-
function isRecord$
|
|
47511
|
+
function isRecord$2(value) {
|
|
46639
47512
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46640
47513
|
}
|
|
46641
47514
|
// src/server/checks/outranked.ts
|
|
@@ -47011,7 +47884,8 @@ const frameDeviceSchema = object$1({
|
|
|
47011
47884
|
/** Absent leaves the device as it stands, but for naming a foldable, which shows it. */
|
|
47012
47885
|
show: boolean$1().optional(),
|
|
47013
47886
|
foldable: boolean$1().optional(),
|
|
47014
|
-
pose: _enum$1(POSES).optional()
|
|
47887
|
+
pose: _enum$1(POSES).optional(),
|
|
47888
|
+
island: _enum$1(ISLANDS).optional()
|
|
47015
47889
|
});
|
|
47016
47890
|
/** More widths than any device list offers, so a body cannot grow without bound. */
|
|
47017
47891
|
const widthList = array$1(int$1().min(1)).max(64);
|
|
@@ -47388,14 +48262,15 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
47388
48262
|
data: frames
|
|
47389
48263
|
});
|
|
47390
48264
|
});
|
|
47391
|
-
/** Shows or hides each frame's device, names the foldable,
|
|
48265
|
+
/** Shows or hides each frame's device, names the foldable, folds it, or picks a phone's island, in one step, leaving every frame file alone. */
|
|
47392
48266
|
app.post("/api/frame/device", async (c) => {
|
|
47393
48267
|
const body = await parseBody$1(c.req.raw, frameDeviceSchema);
|
|
47394
48268
|
const frames = await eachFrame(body.refs, (frame, journal) => setFrameDevice(root, frame, body.show, {
|
|
47395
48269
|
cwd,
|
|
47396
48270
|
journal,
|
|
47397
48271
|
foldable: body.foldable,
|
|
47398
|
-
pose: body.pose
|
|
48272
|
+
pose: body.pose,
|
|
48273
|
+
island: body.island
|
|
47399
48274
|
}), (records) => records.map((record) => record.ref));
|
|
47400
48275
|
return c.json({
|
|
47401
48276
|
ok: true,
|
|
@@ -47932,7 +48807,7 @@ function createApp({ clientDir, root, port, actions, tickets, openRoute, renderF
|
|
|
47932
48807
|
app.route("/", structureRoutes(root, actions.access, history, measure, given));
|
|
47933
48808
|
app.route("/", historyRoutes(actions.access, history));
|
|
47934
48809
|
app.route("/", notesRoutes(root, actions.access, delivery, dispatch));
|
|
47935
|
-
app.route("/", assetsRoutes(root, actions.access, { usage: assetUsage }));
|
|
48810
|
+
app.route("/", assetsRoutes(root, actions.access, history, { usage: assetUsage }));
|
|
47936
48811
|
app.route("/", sourcingRoutes(root, actions.access));
|
|
47937
48812
|
app.route("/", elementsRoutes(root, actions.access, selection, given));
|
|
47938
48813
|
app.route("/", findRoutes(root));
|
|
@@ -48208,7 +49083,8 @@ async function captureMotionImages(browser, { baseUrl, frame, themes, out, scale
|
|
|
48208
49083
|
baseUrl,
|
|
48209
49084
|
frame: {
|
|
48210
49085
|
ref: frame.ref,
|
|
48211
|
-
box: view
|
|
49086
|
+
box: view,
|
|
49087
|
+
device: viewDevice(frame, view)
|
|
48212
49088
|
},
|
|
48213
49089
|
theme,
|
|
48214
49090
|
scale,
|
|
@@ -48233,6 +49109,7 @@ async function captureMotionImages(browser, { baseUrl, frame, themes, out, scale
|
|
|
48233
49109
|
baseUrl,
|
|
48234
49110
|
ref: frame.ref,
|
|
48235
49111
|
view,
|
|
49112
|
+
device: viewDevice(frame, view),
|
|
48236
49113
|
theme,
|
|
48237
49114
|
scale,
|
|
48238
49115
|
motionTimeoutMs,
|
|
@@ -48273,6 +49150,7 @@ async function renderFilmstrip(browser, { baseUrl, frame, theme, scale = 1, coun
|
|
|
48273
49150
|
baseUrl,
|
|
48274
49151
|
ref: frame.ref,
|
|
48275
49152
|
view,
|
|
49153
|
+
device: frame.device,
|
|
48276
49154
|
theme,
|
|
48277
49155
|
scale,
|
|
48278
49156
|
motionTimeoutMs,
|
|
@@ -48292,24 +49170,29 @@ async function renderFilmstrip(browser, { baseUrl, frame, theme, scale = 1, coun
|
|
|
48292
49170
|
* Opens one frame with its animation clock held, finds its timeline, and
|
|
48293
49171
|
* shoots it at each moment `moments` picks from what it found.
|
|
48294
49172
|
*/
|
|
48295
|
-
async function holdShots(browser, { baseUrl, ref, view, theme, scale, motionTimeoutMs, moments }) {
|
|
49173
|
+
async function holdShots(browser, { baseUrl, ref, view, device, theme, scale, motionTimeoutMs, moments }) {
|
|
48296
49174
|
assertScreenshotFits(ref, view, scale);
|
|
48297
49175
|
const opened = await openFrame(browser, {
|
|
48298
49176
|
baseUrl,
|
|
48299
49177
|
ref,
|
|
48300
|
-
box: view,
|
|
49178
|
+
box: pageSize(view, device),
|
|
48301
49179
|
theme,
|
|
48302
49180
|
scale,
|
|
48303
49181
|
motion: "hold"
|
|
48304
49182
|
});
|
|
48305
49183
|
try {
|
|
48306
49184
|
const motion = await findMotion(opened.page, ref, motionTimeoutMs);
|
|
49185
|
+
const colors = topInset(device) > 0 ? await readPageColors(opened.page) : null;
|
|
48307
49186
|
const held = [];
|
|
48308
49187
|
for (const moment of moments(motion)) {
|
|
48309
49188
|
const at = await seekMotion(opened.page, motion, moment);
|
|
49189
|
+
const shot = await opened.page.screenshot(HELD_SCREENSHOT);
|
|
48310
49190
|
held.push({
|
|
48311
49191
|
held: at,
|
|
48312
|
-
bytes: await
|
|
49192
|
+
bytes: colors ? await underStatusBar(browser, shot, view, {
|
|
49193
|
+
colors,
|
|
49194
|
+
theme
|
|
49195
|
+
}, scale) : shot
|
|
48313
49196
|
});
|
|
48314
49197
|
}
|
|
48315
49198
|
return {
|
|
@@ -48322,23 +49205,35 @@ async function holdShots(browser, { baseUrl, ref, view, theme, scale, motionTime
|
|
|
48322
49205
|
await opened.close();
|
|
48323
49206
|
}
|
|
48324
49207
|
}
|
|
49208
|
+
/**
|
|
49209
|
+
* The device a view draws its page under: the frame's own while the view
|
|
49210
|
+
* is the frame's own box, and none at a linked width, which draws no device.
|
|
49211
|
+
*/
|
|
49212
|
+
function viewDevice(frame, view) {
|
|
49213
|
+
return view.width === frame.box.width ? frame.device : void 0;
|
|
49214
|
+
}
|
|
48325
49215
|
async function renderFrame(browser, baseUrl, frame, view, theme, scale, scroll) {
|
|
48326
49216
|
const box = {
|
|
48327
49217
|
width: view.width,
|
|
48328
49218
|
height: view.height
|
|
48329
49219
|
};
|
|
48330
49220
|
assertScreenshotFits(frame.ref, box, scale);
|
|
49221
|
+
const device = viewDevice(frame, view);
|
|
48331
49222
|
const opened = await openFrame(browser, {
|
|
48332
49223
|
baseUrl,
|
|
48333
49224
|
ref: frame.ref,
|
|
48334
|
-
box,
|
|
49225
|
+
box: pageSize(box, device),
|
|
48335
49226
|
theme,
|
|
48336
49227
|
scale
|
|
48337
49228
|
});
|
|
48338
49229
|
try {
|
|
48339
49230
|
const scrollY = scroll === void 0 ? void 0 : await opened.page.evaluate(scrollAndSettle, scroll);
|
|
49231
|
+
const shot = await opened.page.screenshot(SCREENSHOT);
|
|
48340
49232
|
return {
|
|
48341
|
-
bytes: await
|
|
49233
|
+
bytes: topInset(device) > 0 ? await underStatusBar(browser, shot, box, {
|
|
49234
|
+
colors: await readPageColors(opened.page),
|
|
49235
|
+
theme
|
|
49236
|
+
}, scale) : shot,
|
|
48342
49237
|
scrollY,
|
|
48343
49238
|
videos: opened.videos,
|
|
48344
49239
|
models: opened.models
|
|
@@ -48565,7 +49460,7 @@ async function requestBoard(address, path, init, timeoutMs = REQUEST_TIMEOUT_MS)
|
|
|
48565
49460
|
}
|
|
48566
49461
|
const envelope = await response.json().catch(() => null);
|
|
48567
49462
|
const refusal = envelope?.error;
|
|
48568
|
-
if (!response.ok && isErrorCode(refusal?.code) && typeof refusal?.message === "string") throw new FrameboardError(refusal.code, refusal.message, isRecord(refusal.details) ? refusal.details : {});
|
|
49463
|
+
if (!response.ok && isErrorCode(refusal?.code) && typeof refusal?.message === "string") throw new FrameboardError(refusal.code, refusal.message, isRecord$1(refusal.details) ? refusal.details : {});
|
|
48569
49464
|
if (!response.ok || !envelope) throw new FrameboardError("internal", `The frameboard server at ${address.url} refused ${path} with ${response.status}.`, {
|
|
48570
49465
|
url: address.url,
|
|
48571
49466
|
status: response.status
|
|
@@ -48575,7 +49470,7 @@ async function requestBoard(address, path, init, timeoutMs = REQUEST_TIMEOUT_MS)
|
|
|
48575
49470
|
function isErrorCode(code) {
|
|
48576
49471
|
return typeof code === "string" && Object.hasOwn(EXIT_CODES, code);
|
|
48577
49472
|
}
|
|
48578
|
-
function isRecord(value) {
|
|
49473
|
+
function isRecord$1(value) {
|
|
48579
49474
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
48580
49475
|
}
|
|
48581
49476
|
// src/cli/commands/check.ts
|
|
@@ -48705,33 +49600,6 @@ function describe$5(result, { count = true } = {}) {
|
|
|
48705
49600
|
else if (browser?.reason === "browser-not-found") lines.push(`Browser rules did not run, since the board server could not launch Playwright's headless shell. Install it with ${installCommands().npx}.`);
|
|
48706
49601
|
return lines.join("\n");
|
|
48707
49602
|
}
|
|
48708
|
-
/** The files in a project's `assets/` by path, empty when the folder is missing. */
|
|
48709
|
-
const assetListSchema = object$1({ files: array$1(object$1({
|
|
48710
|
-
/** Relative to the project's `assets/`, with `/` between segments. */
|
|
48711
|
-
path: string$1(),
|
|
48712
|
-
kind: _enum$1(ASSET_KINDS),
|
|
48713
|
-
/** Bytes. */
|
|
48714
|
-
size: number().int().nonnegative(),
|
|
48715
|
-
/** How many frames link the file, each counted once, absent where the server counts none. */
|
|
48716
|
-
frames: number().int().nonnegative().optional()
|
|
48717
|
-
})) });
|
|
48718
|
-
const assetAddResultSchema = object$1({
|
|
48719
|
-
/** Each landed file with the name it was dropped as and the name it took. */
|
|
48720
|
-
added: array$1(object$1({
|
|
48721
|
-
name: string$1(),
|
|
48722
|
-
path: string$1()
|
|
48723
|
-
})),
|
|
48724
|
-
/** Each file left out, by its dropped name, with the error code that says why. */
|
|
48725
|
-
refused: array$1(object$1({
|
|
48726
|
-
name: string$1(),
|
|
48727
|
-
code: string$1(),
|
|
48728
|
-
message: string$1()
|
|
48729
|
-
}))
|
|
48730
|
-
});
|
|
48731
|
-
object$1({ transitions: array$1(object$1({
|
|
48732
|
-
name: string$1(),
|
|
48733
|
-
css: string$1()
|
|
48734
|
-
})) });
|
|
48735
49603
|
// src/shared/records/list.ts
|
|
48736
49604
|
const recordErrorSchema = object$1({
|
|
48737
49605
|
path: string$1(),
|
|
@@ -48778,6 +49646,8 @@ const frameRecordSchema = object$1({
|
|
|
48778
49646
|
device: _enum$1(DEVICES).optional(),
|
|
48779
49647
|
/** The pose a frame naming the foldable is folded to, shown or not, absent on every other frame. */
|
|
48780
49648
|
pose: _enum$1(POSES).optional(),
|
|
49649
|
+
/** `wide` while the frame picks the phone's wide island, shown or not, absent for the compact one. */
|
|
49650
|
+
island: literal("wide").optional(),
|
|
48781
49651
|
/** The transition the frame arrives with in present mode, over its page's, absent when it holds none. */
|
|
48782
49652
|
transition: transitionRecordSchema.optional(),
|
|
48783
49653
|
/** What the presenter means to say over the slide, plain text with its line breaks, absent when it holds none. */
|
|
@@ -49325,6 +50195,9 @@ const RECORDS = {
|
|
|
49325
50195
|
claim: claimSchema,
|
|
49326
50196
|
assetList: assetListSchema,
|
|
49327
50197
|
assetAdd: assetAddResultSchema,
|
|
50198
|
+
assetRename: assetRenameSchema,
|
|
50199
|
+
assetWrite: assetWriteResultSchema,
|
|
50200
|
+
assetFrames: assetFramesSchema,
|
|
49328
50201
|
elements: elementTreeSchema,
|
|
49329
50202
|
selection: selectionResultSchema,
|
|
49330
50203
|
find: findResultSchema,
|
|
@@ -49336,8 +50209,312 @@ const RECORDS = {
|
|
|
49336
50209
|
savedImage: savedImageSchema,
|
|
49337
50210
|
licenseFile: licenseFileSchema,
|
|
49338
50211
|
imageGenerate: imageGenerateSchema,
|
|
49339
|
-
imageDoctor: imageDoctorSchema
|
|
50212
|
+
imageDoctor: imageDoctorSchema,
|
|
50213
|
+
modelFind: modelFindSchema,
|
|
50214
|
+
savedModel: savedModelSchema
|
|
50215
|
+
};
|
|
50216
|
+
// src/server/sourcing/pack-glb.ts
|
|
50217
|
+
const GLB_MAGIC = 1179937895;
|
|
50218
|
+
const GLB_VERSION = 2;
|
|
50219
|
+
const JSON_CHUNK = 1313821514;
|
|
50220
|
+
const BIN_CHUNK = 5130562;
|
|
50221
|
+
const CHUNK_HEADER_BYTES = 8;
|
|
50222
|
+
/** The texture formats a glTF viewer reads with no extension named. */
|
|
50223
|
+
const IMAGE_TYPES = {
|
|
50224
|
+
jpg: "image/jpeg",
|
|
50225
|
+
jpeg: "image/jpeg",
|
|
50226
|
+
png: "image/png"
|
|
50227
|
+
};
|
|
50228
|
+
/**
|
|
50229
|
+
* Packs a glTF and the files `files` holds by the URI it names into one GLB
|
|
50230
|
+
* naming no outside file. Refuses `source-failed` for anything it cannot pack
|
|
50231
|
+
* whole rather than writing a file a viewer cannot load.
|
|
50232
|
+
*/
|
|
50233
|
+
function packGlb(gltf, files) {
|
|
50234
|
+
const buffers = listOf(gltf.buffers);
|
|
50235
|
+
if (buffers.length > 1) throw refused(`The glTF names ${buffers.length} buffers, and one packs.`);
|
|
50236
|
+
const parts = [];
|
|
50237
|
+
let length = 0;
|
|
50238
|
+
const append = (bytes) => {
|
|
50239
|
+
const offset = length;
|
|
50240
|
+
parts.push({
|
|
50241
|
+
bytes,
|
|
50242
|
+
offset
|
|
50243
|
+
});
|
|
50244
|
+
length = align(offset + bytes.byteLength);
|
|
50245
|
+
return offset;
|
|
50246
|
+
};
|
|
50247
|
+
const buffer = buffers[0];
|
|
50248
|
+
if (buffer !== void 0) {
|
|
50249
|
+
const declared = buffer.byteLength;
|
|
50250
|
+
if (typeof declared !== "number") throw refused("The glTF buffer states no byteLength.");
|
|
50251
|
+
const bytes = fileFor(buffer.uri, files);
|
|
50252
|
+
if (bytes.byteLength < declared) throw refused(`The buffer holds ${bytes.byteLength} bytes, short of the ${declared} the glTF states.`);
|
|
50253
|
+
append(bytes.subarray(0, declared));
|
|
50254
|
+
}
|
|
50255
|
+
const packedViews = [...listOf(gltf.bufferViews)];
|
|
50256
|
+
const images = listOf(gltf.images).map((image) => {
|
|
50257
|
+
if (image.uri === void 0) return image;
|
|
50258
|
+
const bytes = fileFor(image.uri, files);
|
|
50259
|
+
const mimeType = mimeTypeOf(image);
|
|
50260
|
+
const byteOffset = append(bytes);
|
|
50261
|
+
packedViews.push({
|
|
50262
|
+
buffer: 0,
|
|
50263
|
+
byteOffset,
|
|
50264
|
+
byteLength: bytes.byteLength
|
|
50265
|
+
});
|
|
50266
|
+
const { uri: _uri, ...rest } = image;
|
|
50267
|
+
return {
|
|
50268
|
+
...rest,
|
|
50269
|
+
bufferView: packedViews.length - 1,
|
|
50270
|
+
mimeType
|
|
50271
|
+
};
|
|
50272
|
+
});
|
|
50273
|
+
const json = { ...gltf };
|
|
50274
|
+
delete json.buffers;
|
|
50275
|
+
delete json.bufferViews;
|
|
50276
|
+
if (length > 0) json.buffers = [{ byteLength: length }];
|
|
50277
|
+
if (packedViews.length > 0) json.bufferViews = packedViews;
|
|
50278
|
+
if (gltf.images !== void 0) json.images = images;
|
|
50279
|
+
return container(json, parts, length);
|
|
50280
|
+
}
|
|
50281
|
+
function container(json, parts, binLength) {
|
|
50282
|
+
const text = new TextEncoder().encode(JSON.stringify(json));
|
|
50283
|
+
const jsonLength = align(text.byteLength);
|
|
50284
|
+
const binChunk = binLength === 0 ? 0 : CHUNK_HEADER_BYTES + binLength;
|
|
50285
|
+
const total = 20 + jsonLength + binChunk;
|
|
50286
|
+
const glb = new Uint8Array(total);
|
|
50287
|
+
const view = new DataView(glb.buffer);
|
|
50288
|
+
view.setUint32(0, GLB_MAGIC, true);
|
|
50289
|
+
view.setUint32(4, GLB_VERSION, true);
|
|
50290
|
+
view.setUint32(8, total, true);
|
|
50291
|
+
view.setUint32(12, jsonLength, true);
|
|
50292
|
+
view.setUint32(16, JSON_CHUNK, true);
|
|
50293
|
+
glb.set(text, 20);
|
|
50294
|
+
glb.fill(32, 20 + text.byteLength, 20 + jsonLength);
|
|
50295
|
+
if (binChunk === 0) return glb;
|
|
50296
|
+
const binStart = 20 + jsonLength;
|
|
50297
|
+
view.setUint32(binStart, binLength, true);
|
|
50298
|
+
view.setUint32(binStart + 4, BIN_CHUNK, true);
|
|
50299
|
+
const dataStart = binStart + CHUNK_HEADER_BYTES;
|
|
50300
|
+
for (const part of parts) glb.set(part.bytes, dataStart + part.offset);
|
|
50301
|
+
return glb;
|
|
50302
|
+
}
|
|
50303
|
+
function fileFor(uri, files) {
|
|
50304
|
+
if (typeof uri !== "string" || uri === "") throw refused("The glTF names a buffer or image with no uri.");
|
|
50305
|
+
if (uri.startsWith("data:")) throw refused("The glTF carries a data URI, which this packer does not read.");
|
|
50306
|
+
const bytes = files.get(uri) ?? files.get(safeDecode(uri));
|
|
50307
|
+
if (bytes === void 0) throw refused(`The glTF names ${uri}, which was not downloaded.`);
|
|
50308
|
+
return bytes;
|
|
50309
|
+
}
|
|
50310
|
+
function mimeTypeOf(image) {
|
|
50311
|
+
if (typeof image.mimeType === "string") {
|
|
50312
|
+
if (Object.values(IMAGE_TYPES).includes(image.mimeType)) return image.mimeType;
|
|
50313
|
+
throw refused(`The glTF names a texture of type ${image.mimeType}.`);
|
|
50314
|
+
}
|
|
50315
|
+
const uri = String(image.uri);
|
|
50316
|
+
const extension = uri.slice(uri.lastIndexOf(".") + 1).toLowerCase();
|
|
50317
|
+
const type = IMAGE_TYPES[extension];
|
|
50318
|
+
if (type === void 0) throw refused(`The texture ${uri} is neither JPEG nor PNG.`);
|
|
50319
|
+
return type;
|
|
50320
|
+
}
|
|
50321
|
+
function listOf(value) {
|
|
50322
|
+
return Array.isArray(value) ? value.filter((each) => typeof each === "object" && each !== null) : [];
|
|
50323
|
+
}
|
|
50324
|
+
function safeDecode(uri) {
|
|
50325
|
+
try {
|
|
50326
|
+
return decodeURIComponent(uri);
|
|
50327
|
+
} catch {
|
|
50328
|
+
return uri;
|
|
50329
|
+
}
|
|
50330
|
+
}
|
|
50331
|
+
function align(length) {
|
|
50332
|
+
return Math.ceil(length / 4) * 4;
|
|
50333
|
+
}
|
|
50334
|
+
function refused(message) {
|
|
50335
|
+
return new FrameboardError("source-failed", message, { source: "polyhaven" });
|
|
50336
|
+
}
|
|
50337
|
+
// src/server/sourcing/polyhaven.ts
|
|
50338
|
+
const POLYHAVEN_API = "https://api.polyhaven.com/";
|
|
50339
|
+
/** Named on every listing, which Poly Haven's API terms ask of any surface showing its content. */
|
|
50340
|
+
const POLYHAVEN_SOURCE = {
|
|
50341
|
+
name: "Poly Haven",
|
|
50342
|
+
url: "https://polyhaven.com"
|
|
49340
50343
|
};
|
|
50344
|
+
const CC0_URL = "https://creativecommons.org/publicdomain/zero/1.0/";
|
|
50345
|
+
/** Poly Haven's `type` for a model, beside 0 for an HDRI and 1 for a texture. */
|
|
50346
|
+
const MODEL_TYPE = 2;
|
|
50347
|
+
/**
|
|
50348
|
+
* Poly Haven has no search, so this ranks its whole list here: by distinct
|
|
50349
|
+
* query words matching the name, tags, or categories, then download count,
|
|
50350
|
+
* then id, numbered from 1 and empty when no word matches.
|
|
50351
|
+
*/
|
|
50352
|
+
async function searchModels(query, send) {
|
|
50353
|
+
const url = new URL("assets", POLYHAVEN_API);
|
|
50354
|
+
url.searchParams.set("t", "models");
|
|
50355
|
+
const body = await request(url, send);
|
|
50356
|
+
const words = new Set(wordsOf(query));
|
|
50357
|
+
const scored = Object.entries(isRecord(body) ? body : {}).map(([id, raw]) => toModel(id, raw)).filter((model) => model !== null).map((model) => {
|
|
50358
|
+
const own = new Set([
|
|
50359
|
+
model.name,
|
|
50360
|
+
...model.tags,
|
|
50361
|
+
...model.categories
|
|
50362
|
+
].flatMap(wordsOf));
|
|
50363
|
+
return {
|
|
50364
|
+
model,
|
|
50365
|
+
score: [...words].filter((word) => own.has(word)).length
|
|
50366
|
+
};
|
|
50367
|
+
}).filter(({ score }) => score > 0);
|
|
50368
|
+
scored.sort((a, b) => b.score - a.score || (b.model.downloadCount ?? 0) - (a.model.downloadCount ?? 0) || a.model.id.localeCompare(b.model.id));
|
|
50369
|
+
return scored.slice(0, 20).map(({ model }, index) => ({
|
|
50370
|
+
number: index + 1,
|
|
50371
|
+
...model
|
|
50372
|
+
}));
|
|
50373
|
+
}
|
|
50374
|
+
/**
|
|
50375
|
+
* One model by its Poly Haven id, refusing `result-not-found` for an id
|
|
50376
|
+
* Poly Haven does not hold or one naming a texture or an HDRI.
|
|
50377
|
+
*/
|
|
50378
|
+
async function modelById(id, send) {
|
|
50379
|
+
const missing = new FrameboardError("result-not-found", `Poly Haven holds no model ${id}.`, { id });
|
|
50380
|
+
const model = toModel(id, await request(new URL(`info/${encodeURIComponent(id)}`, POLYHAVEN_API), send, missing));
|
|
50381
|
+
if (model === null) throw missing;
|
|
50382
|
+
return model;
|
|
50383
|
+
}
|
|
50384
|
+
/**
|
|
50385
|
+
* Downloads every file of one model at `size` into memory and packs them as
|
|
50386
|
+
* one GLB, so a failed download leaves nothing to write. Refuses `usage` with
|
|
50387
|
+
* the sizes offered, and `source-failed` on a failed download or pack.
|
|
50388
|
+
*/
|
|
50389
|
+
async function fetchModel(id, size, send) {
|
|
50390
|
+
const body = await request(new URL(`files/${encodeURIComponent(id)}`, POLYHAVEN_API), send);
|
|
50391
|
+
const gltf = isRecord(body) && isRecord(body.gltf) ? body.gltf : {};
|
|
50392
|
+
const entryAt = (each) => {
|
|
50393
|
+
const sized = gltf[each];
|
|
50394
|
+
return isRecord(sized) && isRecord(sized.gltf) ? sized.gltf : null;
|
|
50395
|
+
};
|
|
50396
|
+
const sizes = MODEL_SIZES.filter((each) => entryAt(each) !== null);
|
|
50397
|
+
const entry = entryAt(size);
|
|
50398
|
+
if (sizes.length === 0) throw new FrameboardError("source-failed", `Poly Haven serves ${id} as no glTF, so it cannot be saved as a GLB.`, {
|
|
50399
|
+
source: "polyhaven",
|
|
50400
|
+
id,
|
|
50401
|
+
status: null
|
|
50402
|
+
});
|
|
50403
|
+
if (entry === null) throw new FrameboardError("usage", `Poly Haven serves ${id} at ${sizes.join(", ")}, not ${size}.`, {
|
|
50404
|
+
id,
|
|
50405
|
+
size,
|
|
50406
|
+
sizes
|
|
50407
|
+
});
|
|
50408
|
+
const gltfUrl = text(entry.url);
|
|
50409
|
+
if (gltfUrl === null) throw malformed(id);
|
|
50410
|
+
const includes = Object.entries(isRecord(entry.include) ? entry.include : {});
|
|
50411
|
+
const [main, ...files] = await Promise.all([download(gltfUrl, send), ...includes.map(([, file]) => {
|
|
50412
|
+
const fileUrl = isRecord(file) ? text(file.url) : null;
|
|
50413
|
+
if (fileUrl === null) throw malformed(id);
|
|
50414
|
+
return download(fileUrl, send);
|
|
50415
|
+
})]);
|
|
50416
|
+
let json;
|
|
50417
|
+
try {
|
|
50418
|
+
json = JSON.parse(new TextDecoder().decode(main?.bytes));
|
|
50419
|
+
} catch {
|
|
50420
|
+
throw malformed(id);
|
|
50421
|
+
}
|
|
50422
|
+
if (!isRecord(json)) throw malformed(id);
|
|
50423
|
+
const byUri = new Map(includes.map(([uri], index) => [uri, files[index]?.bytes ?? /* @__PURE__ */ new Uint8Array()]));
|
|
50424
|
+
return {
|
|
50425
|
+
bytes: packGlb(json, byUri),
|
|
50426
|
+
url: gltfUrl
|
|
50427
|
+
};
|
|
50428
|
+
}
|
|
50429
|
+
/** The license file for a Poly Haven model, `query` null when it was saved by id. */
|
|
50430
|
+
function polyhavenLicense(model, query, packed, savedAt) {
|
|
50431
|
+
return {
|
|
50432
|
+
version: 1,
|
|
50433
|
+
origin: "found",
|
|
50434
|
+
source: "polyhaven",
|
|
50435
|
+
id: model.id,
|
|
50436
|
+
query,
|
|
50437
|
+
title: model.name,
|
|
50438
|
+
authors: model.authors,
|
|
50439
|
+
license: "cc0",
|
|
50440
|
+
licenseUrl: CC0_URL,
|
|
50441
|
+
landingUrl: model.landingUrl,
|
|
50442
|
+
url: packed.url,
|
|
50443
|
+
size: packed.size,
|
|
50444
|
+
savedAt: savedAt.toISOString()
|
|
50445
|
+
};
|
|
50446
|
+
}
|
|
50447
|
+
async function request(url, send, missing) {
|
|
50448
|
+
let response;
|
|
50449
|
+
try {
|
|
50450
|
+
response = await send(url, { headers: { "User-Agent": `frameboard/${version}` } });
|
|
50451
|
+
} catch (error) {
|
|
50452
|
+
throw new FrameboardError("source-failed", `Poly Haven did not answer: ${error instanceof Error ? error.message : String(error)}`, {
|
|
50453
|
+
source: "polyhaven",
|
|
50454
|
+
status: null
|
|
50455
|
+
});
|
|
50456
|
+
}
|
|
50457
|
+
if (response.status === 404 && missing) throw missing;
|
|
50458
|
+
if (!response.ok) throw new FrameboardError("source-failed", `Poly Haven answered ${response.status}.`, {
|
|
50459
|
+
source: "polyhaven",
|
|
50460
|
+
status: response.status
|
|
50461
|
+
});
|
|
50462
|
+
try {
|
|
50463
|
+
return await response.json();
|
|
50464
|
+
} catch {
|
|
50465
|
+
throw new FrameboardError("source-failed", "Poly Haven answered something other than JSON.", {
|
|
50466
|
+
source: "polyhaven",
|
|
50467
|
+
status: response.status
|
|
50468
|
+
});
|
|
50469
|
+
}
|
|
50470
|
+
}
|
|
50471
|
+
/** Poly Haven's snake_case asset as the record's fields, null for anything but a model with a name. */
|
|
50472
|
+
function toModel(id, raw) {
|
|
50473
|
+
if (!isRecord(raw) || raw.type !== MODEL_TYPE) return null;
|
|
50474
|
+
const name = text(raw.name);
|
|
50475
|
+
if (name === null) return null;
|
|
50476
|
+
const largest = Array.isArray(raw.max_resolution) ? Math.max(0, ...raw.max_resolution.filter((each) => typeof each === "number")) : 0;
|
|
50477
|
+
const dimensions = Array.isArray(raw.dimensions) ? raw.dimensions.filter((each) => typeof each === "number") : [];
|
|
50478
|
+
return {
|
|
50479
|
+
id,
|
|
50480
|
+
name,
|
|
50481
|
+
authors: isRecord(raw.authors) ? Object.keys(raw.authors) : [],
|
|
50482
|
+
categories: texts(raw.categories),
|
|
50483
|
+
tags: texts(raw.tags),
|
|
50484
|
+
license: "cc0",
|
|
50485
|
+
landingUrl: `${POLYHAVEN_SOURCE.url}/a/${encodeURIComponent(id)}`,
|
|
50486
|
+
thumbnail: text(raw.thumbnail_url),
|
|
50487
|
+
polycount: integer(raw.polycount),
|
|
50488
|
+
dimensionsMm: dimensions.length === 3 ? [
|
|
50489
|
+
dimensions[0] ?? 0,
|
|
50490
|
+
dimensions[1] ?? 0,
|
|
50491
|
+
dimensions[2] ?? 0
|
|
50492
|
+
] : null,
|
|
50493
|
+
sizes: MODEL_SIZES.filter((each) => Number.parseInt(each) * 1024 <= largest),
|
|
50494
|
+
downloadCount: integer(raw.download_count)
|
|
50495
|
+
};
|
|
50496
|
+
}
|
|
50497
|
+
function malformed(id) {
|
|
50498
|
+
return new FrameboardError("source-failed", `Poly Haven's file list for ${id} names no glTF to download.`, {
|
|
50499
|
+
source: "polyhaven",
|
|
50500
|
+
status: null
|
|
50501
|
+
});
|
|
50502
|
+
}
|
|
50503
|
+
function wordsOf(value) {
|
|
50504
|
+
return value.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
50505
|
+
}
|
|
50506
|
+
function isRecord(value) {
|
|
50507
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
50508
|
+
}
|
|
50509
|
+
function text(value) {
|
|
50510
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
50511
|
+
}
|
|
50512
|
+
function texts(value) {
|
|
50513
|
+
return Array.isArray(value) ? value.filter((each) => typeof each === "string") : [];
|
|
50514
|
+
}
|
|
50515
|
+
function integer(value) {
|
|
50516
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? value : null;
|
|
50517
|
+
}
|
|
49341
50518
|
// src/cli/docs/content-format.ts
|
|
49342
50519
|
/** The content format `docs` prints, built from the constants the verbs run on. */
|
|
49343
50520
|
function contentFormat() {
|
|
@@ -49347,7 +50524,7 @@ function contentFormat() {
|
|
|
49347
50524
|
`A project is any folder in the board whose name does not open with a dot. Its ${PROJECT_FILE} lists page names in display order, and pages it does not list follow by name.`,
|
|
49348
50525
|
`A page is any folder in a project except ${ASSETS_FOLDER}/ and dot-named ones. Its ${LAYOUT_FILE} holds each frame's box, stacking order, and flags.`,
|
|
49349
50526
|
`A frame is any *${FRAME_EXTENSION} file directly in a page, named by its stem.`,
|
|
49350
|
-
`A page's notes sit in its ${NOTES_FILE$
|
|
50527
|
+
`A page's notes sit in its ${NOTES_FILE$1}, never in a frame. A note pins to a frame or to one element by index and the frame file's hash, and reads at the frame once the file changes. Read them with notes, answer with notes reply, and close them with notes done. A note's images sit in its page's ${NOTES_FOLDER}/ folder, and its images field lists them relative to the page.`,
|
|
49351
50528
|
`serve reuses a board the walk finds, and otherwise creates ${DEFAULT_BOARD_FOLDER}/ in the working folder with project ${START_PROJECT} and empty page ${START_PAGE}, and records its address in ${RUN_FOLDER}/${ADDRESS_FILE}.`,
|
|
49352
50529
|
`Dot-named folders, *${LOCK_SUFFIX} files, and *${TEMP_SUFFIX} files belong to Frameboard and are never content.`
|
|
49353
50530
|
],
|
|
@@ -49364,7 +50541,9 @@ function contentFormat() {
|
|
|
49364
50541
|
"hidden, locked, hugWidth, hugHeight, and scroll read as false when absent, and an axis whose hug flag is false holds the size its entry states.",
|
|
49365
50542
|
`scroll marks a frame that holds a fixed screen height and scrolls past it, such as a page with a sticky section. It fixes both axes, so either hug flag beside it reads as false, frame fit refuses it, and serve never measures it. frame add --scroll sets it, taking the height given or else the preset height of the width (${FRAME_SIZES.desktop.height} px at ${FRAME_SIZES.desktop.width}). frame resize --scroll sets it on a placed frame, dropping a hugging height to that preset height unless a height is given and keeping a fixed height as it stands, so resize a frame fixed past a screen with --height too. frame resize --no-scroll clears it, keeping the box.`,
|
|
49366
50543
|
`widths lists the extra widths one frame file also shows at, as { width, height } objects, each drawn 80 px past the last in a row beside the frame at its y, so a responsive page is one file rather than a copy per width. Each width follows the frame's own height mode: it hugs its content at that width while hugHeight is on, and otherwise holds its height, the preset height of its width when first set and on frame resize --scroll. A value of any other shape reads as none. frame add --widths 834,390 and frame resize --widths set it, refusing a repeated width, the frame's own width, or a frame hugging its width, and frame resize --no-widths clears it. capture writes <frame>@<width>.<theme>.png beside <frame>.<theme>.png, check reports a browser finding at a linked width with that width and prints it as <path>@<width>, and a frames.json value of <project>/<page>/<frame>@<width> syncs that width's images.`,
|
|
49367
|
-
`showDevice true has the board draw the frame inside the device its width names: a phone from 320 to 479 px wide, a tablet from 480 to 1023, and a laptop from 1024 up, with none under 320. The phone's body stands ${BEZELS.phone.border} px past the box on every side and the tablet's ${BEZELS.tablet.border}, and the laptop's lid ${BEZELS.laptop.border} px past its top and sides, with a chin and a wider base below. A resize redraws the body with no write, and list reports the device the width names as device, absent when off or under 320. It never changes the frame file, its size, or its box. frame add, frame duplicate, and a paste place a frame beside another with its own body, a laptop's base included, 80 px past the other's body. A frame given --x keeps that x, a frame landing in a reserved box keeps that box with no room for a device, and a placed frame stays where it stands when its device turns on. Linked widths draw no device. Any other value of showDevice reads as off and is kept on write. A device string from before showDevice reads as on, and the entry's next write replaces it with showDevice. frame add --device on and frame device <frame-ref> <on|off> set it, taking phone and tablet as on and none as off.`,
|
|
50544
|
+
`showDevice true has the board draw the frame inside the device its width names: a phone from 320 to 479 px wide, a tablet from 480 to 1023, and a laptop from 1024 up, with none under 320. The phone's body stands ${BEZELS.phone.border} px past the box on every side, with side buttons 4 px past that, and the tablet's ${BEZELS.tablet.border}, and the laptop's lid ${BEZELS.laptop.border} px past its top and sides, with a chin and a wider base below. A resize redraws the body with no write, and list reports the device the width names as device, absent when off or under 320. It never changes the frame file, its size, or its box. frame add, frame duplicate, and a paste place a frame beside another with its own body, a laptop's base included, 80 px past the other's body. A frame given --x keeps that x, a frame landing in a reserved box keeps that box with no room for a device, and a placed frame stays where it stands when its device turns on. Linked widths draw no device. Any other value of showDevice reads as off and is kept on write. A device string from before showDevice reads as on, and the entry's next write replaces it with showDevice. frame add --device on and frame device <frame-ref> <on|off> set it, taking phone and tablet as on and none as off.`,
|
|
50545
|
+
`While a phone shows, the board draws a status bar over the top ${STATUS_BAR.height} px of the frame's box, in the page's own fill and text color, and the page starts under it: a frame ${FRAME_SIZES.phone.width} by ${FRAME_SIZES.phone.height} shows a page ${FRAME_SIZES.phone.width} by ${FRAME_SIZES.phone.height - STATUS_BAR.height}. The box in layout.json keeps the screen's size, and the frame file gains no padding. A hugging height measures the page and stores it plus the bar, frame fit does the same, and capture, check, inspect, and present each read the page under the bar. An export draws the bar only with its device included, and lays the page out at the whole box without it. A linked width draws no device and no bar. With the device off, or on any other device, the page is the whole box.`,
|
|
50546
|
+
`island wide has a phone draw its wide island, the one a call or a timer shows, and absent draws the compact one. It is kept while the device is off and reads as compact on any other device. Any other value reads as compact and is kept on write. frame device <frame-ref> --island wide sets it, --island compact clears it, and both refuse a frame whose width names no phone or that names the foldable.`,
|
|
49368
50547
|
`foldable true has the frame name the foldable device over the one its width picks, and pose folds it: closed is the cover screen at ${POSE_SIZES.closed.width} by ${POSE_SIZES.closed.height}, and half and open are the inner screen at ${POSE_SIZES.open.width} by ${POSE_SIZES.open.height}, half shading the fold. Naming a foldable or setting a pose sets the box's width and height to that screen and turns both hug flags off, and writes the layout entry alone, never the frame file, so one file shows every pose and its content reflows as on the device. The body stands ${BEZELS.foldable.border} px past the box on every side. A newly named foldable starts in the pose nearest its width, closed up to 678 px wide and open past it. list reports device as foldable while it shows, and pose on every frame naming one, shown or not. With showDevice off the box keeps its pose's size and no body draws. A foldable draws no linked width and refuses a new one, and widths its entry held from before stay in the file undrawn, draw again once --no-foldable un-names it, and clear on frame resize --no-widths. Any other value of foldable reads as width-picked, a pose no reader knows reads as closed, and both are kept on write. An older Frameboard rewriting the entry may drop both keys, leaving a width-picked frame at the pose's size. frame device <frame-ref> --foldable names it and shows it, --pose <closed|half|open> folds it, and --no-foldable hands the pick back to the width at the size it stands.`,
|
|
49369
50548
|
`An axis that hugs takes its size from the frame's content: a running serve measures it after each write to the frame file and when frame add places a file already written, its width at most ${FRAME_SIZES.desktop.width} px, and writes width and height alone, never a flag. Content sized off the viewport keeps the box it has.`,
|
|
49370
50549
|
"frame add with no size hugs both axes, --size or --width fixes the width and hugs the height, and --height fixes the height alone, its box standing in until serve measures. frame resize and a hand resize fix each axis they set, and frame fit sets the height and turns hugHeight on.",
|
|
@@ -49378,7 +50557,7 @@ function contentFormat() {
|
|
|
49378
50557
|
present: [
|
|
49379
50558
|
`A page's slide transition sits on the present key of its ${LAYOUT_FILE} as { transition: { name, direction, ms } }, and a frame's entry may hold its own transition, which wins as that slide arrives. name is one of ${TRANSITIONS.join(", ")}, or one of the project's own. direction is one of ${DIRECTIONS.join(", ")}, taken by ${DIRECTED.join(" and ")} alone and defaulting to left. ms runs ${TRANSITION_MS.min} to ${TRANSITION_MS.max}, a frame's taking its page's when absent and the page's defaulting to 500. Any other value reads as none and is kept on write. The board draws a transition itself and never writes it into a frame file.`,
|
|
49380
50559
|
`A project adds its own transition as a stylesheet at ${ASSETS_FOLDER}/${TRANSITIONS_FOLDER}/<name>${TRANSITION_FILE_EXTENSION}, set by <name> as a built-in is. The name is lowercase kebab case and never a built-in name, none, or page. The file holds @keyframes enter, which the arriving slide plays, optionally @keyframes leave, which the leaving slide plays or else holds still, and nothing else: no other rule or at-rule, and no url(), quoted string, or backslash escape in a value. The board plays those two keyframes over the transition's ms and never loads the file itself. It takes --ms and no direction, so a second file covers a second direction. A file breaking any of this is refused whole, reported by check and the write hook as transition-file, left out of list --json's transitions on its project, and a page or frame naming it cuts. Turning transition-file off silences the finding and the file stays refused.`,
|
|
49381
|
-
`A frame's entry may hold speakerNotes, what the presenter means to say over the slide: plain text up to ${SPEAKER_NOTES_MAX} characters with its line breaks kept and no markup read. It lives on the entry alone and never enters the frame file, so a rewrite of the file keeps it, and a duplicate or a move to another page carries it. list --json reports it on the frame, absent when it holds none, and any value other than text reads as none and is kept on write. frame speaker-notes <frame-ref> prints it, frame speaker-notes <frame-ref> <text> sets it, refusing usage past the limit rather than cutting it, and --clear or blank text removes it.
|
|
50560
|
+
`A frame's entry may hold speakerNotes, what the presenter means to say over the slide: plain text up to ${SPEAKER_NOTES_MAX} characters with its line breaks kept and no markup read. It lives on the entry alone and never enters the frame file, so a rewrite of the file keeps it, and a duplicate or a move to another page carries it. list --json reports it on the frame, absent when it holds none, and any value other than text reads as none and is kept on write. frame speaker-notes <frame-ref> prints it, frame speaker-notes <frame-ref> <text> sets it, refusing usage past the limit rather than cutting it, and --clear or blank text removes it. The board shows it in a strip under each slide while the Slides tab's Notes button shows notes, and the presenter view's window shows it beside the slide, while the slide the audience sees never does.`,
|
|
49382
50561
|
"page transition <page-ref> <name> sets the page's, and none clears it so slides cut. frame transition <frame-ref> <name> sets a frame's, and page clears it so the frame takes its page's. Both take --ms and --direction, refuse usage on a name that is neither built in nor the project's own with the known names in the error's details, and write only layout.json.",
|
|
49383
50562
|
`A step is an element present mode holds back until a press reveals it, marked by three attributes on that element and nothing else. ${STEP_ATTRIBUTES.step}="<n>" is a positive integer, and steps show in number order with equal numbers together and gaps closed. ${STEP_ATTRIBUTES.effect} is one of ${STEP_EFFECTS.join(", ")}, defaulting to appear. ${STEP_ATTRIBUTES.start} is one of ${STEP_STARTS.join(", ")}, defaulting to click, where with shows the step beside the one before it and after shows it once that one finishes. Set them with edit --attr. Edit, Play, capture, and an exported PNG show every step.`
|
|
49384
50563
|
],
|
|
@@ -49406,7 +50585,8 @@ function contentFormat() {
|
|
|
49406
50585
|
`A frame shows a 3D model through one <${VIEWER_TAG} src="../${ASSETS_FOLDER}/<file>.glb" alt=""> element, sized by its own width and height as an image is. It reads .glb and .gltf alone, and a .gltf carries its buffers and images inside itself. A drop refuses ${FOREIGN_MODELS.join(", ")}, so export any of those from Blender through File, Export, glTF 2.0 as a glTF Binary (.glb).`,
|
|
49407
50586
|
`The element draws only in a frame whose head loads the viewer, as ${VIEWER_SCRIPT}. Placing a model on the board copies ${VIEWER_FILE} into the project's ${ASSETS_FOLDER}/ once and adds that tag to a head loading no viewer, and removing the last model leaves both. The file ships with the tool at ${shippedViewerPath()}, so copy it to the project's ${ASSETS_FOLDER}/${VIEWER_FILE} before writing the element in a project that holds none. A frame loads nothing over the network, so never link the viewer from a CDN.`,
|
|
49408
50587
|
`Every staging control is an attribute on the element, set with edit --attr. camera-orbit="<theta>deg <phi>deg <radius>" places the camera, across and then down from the top, and defaults to 0deg 75deg auto. The viewer holds the camera inside max-camera-orbit, so state both once the radius passes the model's own framing, as camera-orbit="30deg 70deg 6m" max-camera-orbit="auto auto 6m". orientation="<roll>deg <pitch>deg <yaw>deg" turns the model itself, scale="<x> <y> <z>" sizes it, animation-name picks one of its clips, and autoplay starts it. The board's Model section writes these same attributes, the angle as both orbit attributes in one undo step, and a double-click on a selected model turns it by drag.`,
|
|
49409
|
-
`check reports missing-file at error for a ${VIEWER_TAG} whose ${MODEL_LOADS.join(", ")} names no file, as it does for the viewer script. capture waits for each model to draw inside the frame's load budget and holds its clip at the start, and --at seeks every clip to that moment, so two captures match. A model that fails to load, or is still loading when the budget ends, never refuses: the image lists it under models with state error or pending
|
|
50588
|
+
`check reports missing-file at error for a ${VIEWER_TAG} whose ${MODEL_LOADS.join(", ")} names no file, as it does for the viewer script. capture waits for each model to draw inside the frame's load budget and holds its clip at the start, and --at seeks every clip to that moment, so two captures match. A model that fails to load, or is still loading when the budget ends, never refuses: the image lists it under models with state error or pending.`,
|
|
50589
|
+
`model find searches ${POLYHAVEN_SOURCE.name}'s CC0 models, which ask no credit, and writes nothing. ${POLYHAVEN_SOURCE.name} has no search, so it reads the whole list in one request and ranks it here: by how many distinct query words match a word of the name, the tags, or the categories, then by download count, then by id, listing up to 20 numbered from 1 and none for a query matching nothing. Its results and human output name ${POLYHAVEN_SOURCE.name}, as its terms ask of any surface showing its content. --save <number> runs the search again, and --save <id> saves that ${POLYHAVEN_SOURCE.name} model with no search. A saved model is one .glb packed from the glTF, its buffer, and its textures, at 1k textures unless --size names one of ${MODEL_SIZES.join(", ")}, refusing usage with the sizes it offers for one the model lacks. A larger size weighs more, about 1 MB at 1k and 40 MB at 8k for a stool. Every file is held whole before anything is written, and its license file records the authors and the model's page.`
|
|
49410
50590
|
],
|
|
49411
50591
|
assets: `A frame links files in its own page folder or in its project's ${ASSETS_FOLDER}/ folder. frame duplicate and frame move carry the ${FRAME_EXTENSION} file alone, so keep files shared between frames or pages in ${ASSETS_FOLDER}/.`,
|
|
49412
50592
|
look: [
|
|
@@ -49793,11 +50973,11 @@ const DEVICE_ON = [
|
|
|
49793
50973
|
"tablet"
|
|
49794
50974
|
];
|
|
49795
50975
|
/** What `frame device` did, naming the device the frame draws inside and a foldable's pose. */
|
|
49796
|
-
function deviceHeadline({ ref, box, showDevice, device, pose }) {
|
|
50976
|
+
function deviceHeadline({ ref, box, showDevice, device, pose, island }) {
|
|
49797
50977
|
const folded = pose ? `, folded ${pose} at ${box.width} by ${box.height}` : "";
|
|
49798
50978
|
if (!showDevice) return `Hid the device on ${ref}${folded}`;
|
|
49799
50979
|
if (!device) return `Showed the device on ${ref}, though no device fits its ${box.width} px width`;
|
|
49800
|
-
return `Showed the ${device} on ${ref}${folded}`;
|
|
50980
|
+
return `Showed the ${device} on ${ref}${folded}${device === "phone" ? ` with the ${islandOf(island)} island` : ""}`;
|
|
49801
50981
|
}
|
|
49802
50982
|
const WIDTHS_HELP = "the extra widths the frame also shows at, a comma list such as 834,390, each drawn beside it and hugging or holding its height as the frame does";
|
|
49803
50983
|
const POSITIVE = parseInteger(1);
|
|
@@ -49879,14 +51059,15 @@ function registerFrame(program, context) {
|
|
|
49879
51059
|
human: `Deleted frame ${result.deleted}`
|
|
49880
51060
|
};
|
|
49881
51061
|
});
|
|
49882
|
-
act(verb("device", "Show or hide the device the board draws around a frame, the phone, tablet, or laptop its width names or the foldable the frame names,
|
|
49883
|
-
if (value === void 0 && foldable === void 0 && pose === void 0) throw new FrameboardError("usage", "frame device takes on or off, --foldable, --no-foldable, or --
|
|
51062
|
+
act(verb("device", "Show or hide the device the board draws around a frame, the phone, tablet, or laptop its width names or the foldable the frame names, fold a foldable, and pick a phone’s island, leaving the frame file as it is").addArgument(new Argument("[on|off]", "on to show the device, off to hide it, with phone and tablet taken as on and none as off, and absent to leave it, which --foldable takes as on").choices(Object.keys(DEVICE_SWITCH))).addOption(new Option("--foldable", "name the foldable over the device the width picks, setting the box to the pose nearest its width")).addOption(new Option("--no-foldable", "hand the pick back to the width, leaving the box at its size")).addOption(new Option("--pose <pose>", "fold a foldable, setting its box to 466 by 678 closed and 890 by 626 half or open").choices(POSES)).addOption(new Option("--island <width>", "pick the phone island drawn over a frame 320 to 479 px wide, compact or the wide one a call or a timer shows").choices(ISLANDS)), context, async ([ref = "", value], { foldable, pose, island, ...options }) => {
|
|
51063
|
+
if (value === void 0 && foldable === void 0 && pose === void 0 && island === void 0) throw new FrameboardError("usage", "frame device takes on or off, --foldable, --no-foldable, --pose, or --island.");
|
|
49884
51064
|
const show = value !== void 0 && Object.hasOwn(DEVICE_SWITCH, value) ? DEVICE_SWITCH[value] : void 0;
|
|
49885
51065
|
const record = await setFrameDevice(await boardOf(options, io), ref, show, {
|
|
49886
51066
|
...options,
|
|
49887
51067
|
cwd: io.cwd,
|
|
49888
51068
|
foldable,
|
|
49889
|
-
pose
|
|
51069
|
+
pose,
|
|
51070
|
+
island
|
|
49890
51071
|
});
|
|
49891
51072
|
return {
|
|
49892
51073
|
data: record,
|
|
@@ -50006,7 +51187,7 @@ function registerImage(program, context) {
|
|
|
50006
51187
|
const saved = await saveImage(project, stem, await downloadImage(chosen.image.url, send), foundLicense(chosen.image, chosen.query, /* @__PURE__ */ new Date()));
|
|
50007
51188
|
return {
|
|
50008
51189
|
data: saved,
|
|
50009
|
-
human: savedLine(saved)
|
|
51190
|
+
human: savedLine$1(saved)
|
|
50010
51191
|
};
|
|
50011
51192
|
});
|
|
50012
51193
|
act(addVerb(image, "generate", "Generate an image on the first provider whose key is set and save it into the project's assets, spending on that key unless --dry-run", { project: true }).argument("<prompt>", "what the image shows").option("--provider <name>", `run on this provider, one of ${IMAGE_PROVIDERS.join(", ")}, rather than the first ready`).option("--width <px>", "the width asked for", parseInteger(1), 1024).option("--height <px>", "the height asked for", parseInteger(1), 1024).option("--dry-run", "answer the provider, size, and price, and make no request").option("--name <stem>", "the saved file name without its extension, the prompt by default"), context, async ([prompt = ""], options) => {
|
|
@@ -50050,7 +51231,7 @@ function registerImage(program, context) {
|
|
|
50050
51231
|
...record,
|
|
50051
51232
|
saved
|
|
50052
51233
|
},
|
|
50053
|
-
human: `Generated on ${priced}. ${savedLine(saved)}`
|
|
51234
|
+
human: `Generated on ${priced}. ${savedLine$1(saved)}`
|
|
50054
51235
|
};
|
|
50055
51236
|
});
|
|
50056
51237
|
act(addVerb(image, "doctor", "Report the GPU, a local ComfyUI server, and which provider keys are set, installing nothing"), context, async () => {
|
|
@@ -50088,7 +51269,7 @@ function registerImage(program, context) {
|
|
|
50088
51269
|
};
|
|
50089
51270
|
}
|
|
50090
51271
|
}
|
|
50091
|
-
function savedLine(saved) {
|
|
51272
|
+
function savedLine$1(saved) {
|
|
50092
51273
|
return `Saved assets/${saved.path} into ${saved.project}, its license in assets/${saved.licensePath}`;
|
|
50093
51274
|
}
|
|
50094
51275
|
// node_modules/ws/lib/constants.js
|
|
@@ -53815,7 +54996,7 @@ async function inspectFrame(browser, { baseUrl, frame, theme, index }) {
|
|
|
53815
54996
|
const opened = await openFrame(browser, {
|
|
53816
54997
|
baseUrl,
|
|
53817
54998
|
ref: frame.ref,
|
|
53818
|
-
box: frame.box,
|
|
54999
|
+
box: pageSize(frame.box, frame.device),
|
|
53819
55000
|
theme
|
|
53820
55001
|
});
|
|
53821
55002
|
let live;
|
|
@@ -53978,6 +55159,66 @@ function describe$2({ root, projects }) {
|
|
|
53978
55159
|
}
|
|
53979
55160
|
return lines.join("\n");
|
|
53980
55161
|
}
|
|
55162
|
+
// src/cli/commands/model.ts
|
|
55163
|
+
const CREDIT = `Models from ${POLYHAVEN_SOURCE.name}, ${POLYHAVEN_SOURCE.url}, CC0`;
|
|
55164
|
+
function registerModel(program, context) {
|
|
55165
|
+
const { io } = context;
|
|
55166
|
+
const send = io.fetch ?? fetch;
|
|
55167
|
+
act(addVerb(program.command("model").description("Find a public domain 3D model and save it into a project's assets as one GLB with its license"), "find", "Search Poly Haven's CC0 models, writing nothing unless --save names a result", { project: true }).argument("<query>", "what the model shows").option("--save <number-or-id>", "save the result with this number, or the Poly Haven model with this id, into the project's assets").option("--size <size>", `the texture size saved, one of ${MODEL_SIZES.join(", ")}, 1k by default`, parseSize).option("--name <stem>", "the saved file name without its extension, the query by default"), context, async ([query = ""], options) => {
|
|
55168
|
+
if (options.save === void 0) {
|
|
55169
|
+
for (const flag of ["name", "size"]) if (options[flag] !== void 0) throw new FrameboardError("usage", `--${flag} needs --save.`);
|
|
55170
|
+
const results = await searchModels(query, send);
|
|
55171
|
+
return {
|
|
55172
|
+
data: {
|
|
55173
|
+
version: 1,
|
|
55174
|
+
query,
|
|
55175
|
+
source: { ...POLYHAVEN_SOURCE },
|
|
55176
|
+
results
|
|
55177
|
+
},
|
|
55178
|
+
human: results.length === 0 ? `No ${POLYHAVEN_SOURCE.name} model matches ${query}` : [...results.map((each) => `${each.number}\t${each.sizes.at(-1) ?? "-"}\t${each.name}\t${each.id}`), CREDIT].join("\n")
|
|
55179
|
+
};
|
|
55180
|
+
}
|
|
55181
|
+
const stem = savedStem(options.name, query, "model");
|
|
55182
|
+
const project = await resolveProject(await boardOf(options, io), options.project);
|
|
55183
|
+
const size = options.size ?? "1k";
|
|
55184
|
+
const chosen = await pick(query, options.save);
|
|
55185
|
+
const packed = await fetchModel(chosen.model.id, size, send);
|
|
55186
|
+
const saved = await saveModel(project, stem, packed.bytes, polyhavenLicense(chosen.model, chosen.query, {
|
|
55187
|
+
url: packed.url,
|
|
55188
|
+
size
|
|
55189
|
+
}, /* @__PURE__ */ new Date()));
|
|
55190
|
+
return {
|
|
55191
|
+
data: saved,
|
|
55192
|
+
human: savedLine(saved)
|
|
55193
|
+
};
|
|
55194
|
+
});
|
|
55195
|
+
/** The model `--save` names: a number reruns the search, anything else is an id. */
|
|
55196
|
+
async function pick(query, save) {
|
|
55197
|
+
if (!/^\d+$/.test(save)) return {
|
|
55198
|
+
model: await modelById(save, send),
|
|
55199
|
+
query: null
|
|
55200
|
+
};
|
|
55201
|
+
const number = Number(save);
|
|
55202
|
+
const results = await searchModels(query, send);
|
|
55203
|
+
const found = results.find((each) => each.number === number);
|
|
55204
|
+
if (found === void 0) throw new FrameboardError("result-not-found", `The search for ${query} found ${results.length} results, so there is no result ${number}.`, {
|
|
55205
|
+
number,
|
|
55206
|
+
results: results.length
|
|
55207
|
+
});
|
|
55208
|
+
return {
|
|
55209
|
+
model: found,
|
|
55210
|
+
query
|
|
55211
|
+
};
|
|
55212
|
+
}
|
|
55213
|
+
}
|
|
55214
|
+
function parseSize(value) {
|
|
55215
|
+
const size = MODEL_SIZES.find((each) => each === value);
|
|
55216
|
+
if (size === void 0) throw new InvalidArgumentError(`Expected one of ${MODEL_SIZES.join(", ")}.`);
|
|
55217
|
+
return size;
|
|
55218
|
+
}
|
|
55219
|
+
function savedLine(saved) {
|
|
55220
|
+
return `Saved assets/${saved.path} into ${saved.project} from ${POLYHAVEN_SOURCE.name}, its license in assets/${saved.licensePath}`;
|
|
55221
|
+
}
|
|
53981
55222
|
// src/cli/commands/notes.ts
|
|
53982
55223
|
function registerNotes(program, context) {
|
|
53983
55224
|
const { io } = context;
|
|
@@ -55096,67 +56337,6 @@ function createTickets(now = Date.now) {
|
|
|
55096
56337
|
}
|
|
55097
56338
|
};
|
|
55098
56339
|
}
|
|
55099
|
-
// src/server/board/asset-usage.ts
|
|
55100
|
-
/**
|
|
55101
|
-
* A per-project cache of how many frames link each asset, counted from the
|
|
55102
|
-
* same loads the link check judges. A frame counts once per file, and only a
|
|
55103
|
-
* link resolving inside the project's `assets/` counts.
|
|
55104
|
-
*/
|
|
55105
|
-
function createAssetUsage(root) {
|
|
55106
|
-
const cache = /* @__PURE__ */ new Map();
|
|
55107
|
-
return {
|
|
55108
|
-
counts: (project) => {
|
|
55109
|
-
const cached = cache.get(project);
|
|
55110
|
-
if (cached) return cached;
|
|
55111
|
-
const built = countProject(root, project);
|
|
55112
|
-
cache.set(project, built);
|
|
55113
|
-
built.catch(() => {
|
|
55114
|
-
if (cache.get(project) === built) cache.delete(project);
|
|
55115
|
-
});
|
|
55116
|
-
return built;
|
|
55117
|
-
},
|
|
55118
|
-
drop: (paths) => {
|
|
55119
|
-
for (const path of paths) {
|
|
55120
|
-
const inside = relative(root, path);
|
|
55121
|
-
if (inside === "") {
|
|
55122
|
-
cache.clear();
|
|
55123
|
-
return;
|
|
55124
|
-
}
|
|
55125
|
-
if (inside.startsWith("..")) continue;
|
|
55126
|
-
const project = inside.split(sep)[0];
|
|
55127
|
-
if (project) cache.delete(project);
|
|
55128
|
-
}
|
|
55129
|
-
}
|
|
55130
|
-
};
|
|
55131
|
-
}
|
|
55132
|
-
async function countProject(root, project) {
|
|
55133
|
-
const projectDir = join(root, project);
|
|
55134
|
-
const counts = /* @__PURE__ */ new Map();
|
|
55135
|
-
for (const page of await listPageFolders(projectDir)) for (const name of await listFrames(join(projectDir, page))) for (const path of linkedAssets(root, project, page, name)) counts.set(path, (counts.get(path) ?? 0) + 1);
|
|
55136
|
-
return counts;
|
|
55137
|
-
}
|
|
55138
|
-
/** The asset paths one frame links, each once. A frame gone between the listing and the read links none. */
|
|
55139
|
-
function linkedAssets(root, project, page, name) {
|
|
55140
|
-
const linked = /* @__PURE__ */ new Set();
|
|
55141
|
-
let source;
|
|
55142
|
-
try {
|
|
55143
|
-
source = readFrame$1({
|
|
55144
|
-
root,
|
|
55145
|
-
project,
|
|
55146
|
-
page,
|
|
55147
|
-
name
|
|
55148
|
-
});
|
|
55149
|
-
} catch {
|
|
55150
|
-
return linked;
|
|
55151
|
-
}
|
|
55152
|
-
const assets = assetsDirOf(source);
|
|
55153
|
-
for (const load of frameLoads(source)) {
|
|
55154
|
-
const target = localTarget(load.url, load.base);
|
|
55155
|
-
if (target === null || target === assets || !isInside(assets, target)) continue;
|
|
55156
|
-
linked.add(relative(assets, target).split(sep).join("/"));
|
|
55157
|
-
}
|
|
55158
|
-
return linked;
|
|
55159
|
-
}
|
|
55160
56340
|
// src/server/capture/thumbnails.ts
|
|
55161
56341
|
const THUMBNAILS_FOLDER = "thumbnails";
|
|
55162
56342
|
/**
|
|
@@ -55239,7 +56419,12 @@ const THEMED_RULES = [
|
|
|
55239
56419
|
* Runs every browser rule in both themes and merges them, measuring a missing
|
|
55240
56420
|
* face in the board's fallback rather than refusing, after animations finish.
|
|
55241
56421
|
*/
|
|
55242
|
-
async function checkRendered(browser, { baseUrl, root, frame, config }) {
|
|
56422
|
+
async function checkRendered(browser, { baseUrl, root, frame: shown, config }) {
|
|
56423
|
+
const { device, ...target } = shown;
|
|
56424
|
+
const frame = {
|
|
56425
|
+
...target,
|
|
56426
|
+
box: pageSize(target.box, device)
|
|
56427
|
+
};
|
|
55243
56428
|
const [project = "", page = "", name = ""] = frame.ref.split("/");
|
|
55244
56429
|
const source = readFrame$1({
|
|
55245
56430
|
root,
|
|
@@ -58649,27 +59834,41 @@ function isIgnored(root, path) {
|
|
|
58649
59834
|
* reloading nothing, since moving a frame must not restart it.
|
|
58650
59835
|
*/
|
|
58651
59836
|
function reloadRefs(root, paths, board, tokens = null) {
|
|
58652
|
-
const { refs, everyFrame } = reloadCauses(root, paths, tokens);
|
|
59837
|
+
const { refs, everyFrame, media } = reloadCauses(root, paths, tokens);
|
|
58653
59838
|
const named = [];
|
|
58654
|
-
for (const project of board.projects)
|
|
59839
|
+
for (const project of board.projects) {
|
|
59840
|
+
const changed = media.get(project.name);
|
|
59841
|
+
for (const page of project.pages) for (const frame of page.frames) if (everyFrame || refs.has(frame.ref) || refs.has(`${page.ref}/*`) || refs.has(`${project.name}/*`) || changed !== void 0 && links(root, frame, changed)) named.push(frame.ref);
|
|
59842
|
+
}
|
|
58655
59843
|
return named;
|
|
58656
59844
|
}
|
|
59845
|
+
/** Whether the frame's file, read as it stands, loads any of the changed asset paths. */
|
|
59846
|
+
function links(root, frame, changed) {
|
|
59847
|
+
for (const path of linkedAssets(root, frame.project, frame.page, frame.name)) if (changed.has(path)) return true;
|
|
59848
|
+
return false;
|
|
59849
|
+
}
|
|
58657
59850
|
/**
|
|
58658
59851
|
* The frames `reloadRefs` names through their own file alone, with no token
|
|
58659
59852
|
* sheet, asset, or other page-folder file in the batch reaching them, in
|
|
58660
59853
|
* board order. Only these reload into bytes a hash of that one file names.
|
|
58661
59854
|
*/
|
|
58662
59855
|
function ownReloadRefs(root, paths, board, tokens = null) {
|
|
58663
|
-
const { refs, everyFrame } = reloadCauses(root, paths, tokens);
|
|
59856
|
+
const { refs, everyFrame, media } = reloadCauses(root, paths, tokens);
|
|
58664
59857
|
if (everyFrame) return [];
|
|
58665
|
-
return board.projects.flatMap((project) =>
|
|
59858
|
+
return board.projects.flatMap((project) => {
|
|
59859
|
+
if (refs.has(`${project.name}/*`)) return [];
|
|
59860
|
+
const changed = media.get(project.name);
|
|
59861
|
+
return project.pages.flatMap((page) => refs.has(`${page.ref}/*`) ? [] : page.frames.filter((frame) => refs.has(frame.ref) && (changed === void 0 || !links(root, frame, changed))).map((frame) => frame.ref));
|
|
59862
|
+
});
|
|
58666
59863
|
}
|
|
58667
59864
|
/**
|
|
58668
59865
|
* What a batch's paths reach: frame refs, `<page>/*` and `<project>/*`
|
|
58669
|
-
* wildcards,
|
|
59866
|
+
* wildcards, whether a board-wide sheet reaches every frame, and per project
|
|
59867
|
+
* the placeable media under `assets/` that reach only the frames loading them.
|
|
58670
59868
|
*/
|
|
58671
59869
|
function reloadCauses(root, paths, tokens) {
|
|
58672
59870
|
const refs = /* @__PURE__ */ new Set();
|
|
59871
|
+
const media = /* @__PURE__ */ new Map();
|
|
58673
59872
|
let everyFrame = false;
|
|
58674
59873
|
for (const path of paths) {
|
|
58675
59874
|
const [project, folder, ...rest] = relative(root, path).split(sep);
|
|
@@ -58682,8 +59881,17 @@ function reloadCauses(root, paths, tokens) {
|
|
|
58682
59881
|
continue;
|
|
58683
59882
|
}
|
|
58684
59883
|
if (!project || !folder || rest.length === 0) continue;
|
|
58685
|
-
if (folder === "assets")
|
|
58686
|
-
|
|
59884
|
+
if (folder === "assets") {
|
|
59885
|
+
const name = rest.at(-1) ?? "";
|
|
59886
|
+
if (name.endsWith(".license.json")) continue;
|
|
59887
|
+
if (rest[0] === "kits" || rest[0] === "kit" || !isPlaceableKind(assetKind(name))) {
|
|
59888
|
+
refs.add(`${project}/*`);
|
|
59889
|
+
continue;
|
|
59890
|
+
}
|
|
59891
|
+
const changed = media.get(project) ?? /* @__PURE__ */ new Set();
|
|
59892
|
+
changed.add(rest.join("/"));
|
|
59893
|
+
media.set(project, changed);
|
|
59894
|
+
} else if (rest.length === 1) {
|
|
58687
59895
|
const name = rest[0] ?? "";
|
|
58688
59896
|
if (name === "layout.json" || name === NOTES_FILE) continue;
|
|
58689
59897
|
const frame = frameNameOf(name);
|
|
@@ -58692,7 +59900,8 @@ function reloadCauses(root, paths, tokens) {
|
|
|
58692
59900
|
}
|
|
58693
59901
|
return {
|
|
58694
59902
|
refs,
|
|
58695
|
-
everyFrame
|
|
59903
|
+
everyFrame,
|
|
59904
|
+
media
|
|
58696
59905
|
};
|
|
58697
59906
|
}
|
|
58698
59907
|
/**
|
|
@@ -58721,11 +59930,13 @@ function frameNameOf(name) {
|
|
|
58721
59930
|
}
|
|
58722
59931
|
/**
|
|
58723
59932
|
* Hugging frames newly placed, measured without a reload, since placing writes
|
|
58724
|
-
* `layout.json` alone, which reloads nothing.
|
|
59933
|
+
* `layout.json` alone, which reloads nothing. `unmeasured` names frames
|
|
59934
|
+
* `previous` holds placed that no batch measured, read as unplaced.
|
|
58725
59935
|
*/
|
|
58726
|
-
function placedRefs(previous, next, paths) {
|
|
59936
|
+
function placedRefs(previous, next, paths, unmeasured = []) {
|
|
58727
59937
|
const written = paths && new Set(paths);
|
|
58728
|
-
const
|
|
59938
|
+
const pending = new Set(unmeasured);
|
|
59939
|
+
const before = new Set(previous.projects.flatMap((project) => project.pages.flatMap((page) => page.frames.filter((frame) => frame.placed && !pending.has(frame.ref)).map((frame) => frame.ref))));
|
|
58729
59940
|
return next.projects.flatMap((project) => project.pages.filter((page) => !written || written.has(join(page.path, "layout.json"))).flatMap((page) => page.frames.filter((frame) => frame.placed && (frame.hugWidth || frame.hugHeight) && !before.has(frame.ref)).map((frame) => frame.ref)));
|
|
58730
59941
|
}
|
|
58731
59942
|
/**
|
|
@@ -58998,9 +60209,10 @@ function send(socket, message) {
|
|
|
58998
60209
|
// src/server/live/hug.ts
|
|
58999
60210
|
/**
|
|
59000
60211
|
* The server's hug step, writing through `setMeasured`, with an unbounded,
|
|
59001
|
-
* empty, or failing frame keeping its box.
|
|
60212
|
+
* empty, or failing frame keeping its box. A failing one is reported through
|
|
60213
|
+
* `report`, the server's log unless a test stands in, since nothing retries it.
|
|
59002
60214
|
*/
|
|
59003
|
-
function createHug({ root, measure }) {
|
|
60215
|
+
function createHug({ root, measure, report = (line) => console.error(line) }) {
|
|
59004
60216
|
let queue = Promise.resolve();
|
|
59005
60217
|
let closed = false;
|
|
59006
60218
|
const run = async (board, refs, parts) => {
|
|
@@ -59012,6 +60224,7 @@ function createHug({ root, measure }) {
|
|
|
59012
60224
|
try {
|
|
59013
60225
|
size = await measureParts(measure, frame, parts);
|
|
59014
60226
|
} catch (error) {
|
|
60227
|
+
report(`frameboard: ${frame.ref} keeps its box, since its measure failed: ${failureOf(error)}`);
|
|
59015
60228
|
if (error instanceof FrameboardError && error.code === "browser-not-found") break;
|
|
59016
60229
|
continue;
|
|
59017
60230
|
}
|
|
@@ -59055,6 +60268,14 @@ function createHug({ root, measure }) {
|
|
|
59055
60268
|
};
|
|
59056
60269
|
}
|
|
59057
60270
|
/**
|
|
60271
|
+
* A board error's code and message, or another error's first line, since a
|
|
60272
|
+
* browser error goes on to its call log.
|
|
60273
|
+
*/
|
|
60274
|
+
function failureOf(error) {
|
|
60275
|
+
if (error instanceof FrameboardError) return `${error.code}: ${error.message}`;
|
|
60276
|
+
return (error instanceof Error ? error.message : String(error)).split("\n", 1)[0] ?? "";
|
|
60277
|
+
}
|
|
60278
|
+
/**
|
|
59058
60279
|
* Reads the parts a run asks for, a linked width only on a frame hugging its
|
|
59059
60280
|
* height. An empty body at the frame's own box, or at every linked width,
|
|
59060
60281
|
* reads nothing for that part, so the box it stands in for holds.
|
|
@@ -59062,10 +60283,14 @@ function createHug({ root, measure }) {
|
|
|
59062
60283
|
async function measureParts(measure, frame, parts) {
|
|
59063
60284
|
const size = {};
|
|
59064
60285
|
if (parts !== "linked") {
|
|
59065
|
-
const
|
|
60286
|
+
const page = pageBox(frame.box, frame.device);
|
|
60287
|
+
const own = await measure({
|
|
60288
|
+
...frame,
|
|
60289
|
+
box: page
|
|
60290
|
+
});
|
|
59066
60291
|
if (!own.empty) Object.assign(size, {
|
|
59067
60292
|
width: own.width,
|
|
59068
|
-
height: own.height
|
|
60293
|
+
height: own.height + topInset(frame.device)
|
|
59069
60294
|
});
|
|
59070
60295
|
}
|
|
59071
60296
|
if (parts !== "own" && frame.hugHeight && frame.widths.length > 0) {
|
|
@@ -59638,7 +60863,10 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
59638
60863
|
settling.set(timer, release);
|
|
59639
60864
|
};
|
|
59640
60865
|
const shown = { board: null };
|
|
59641
|
-
const scanned = {
|
|
60866
|
+
const scanned = {
|
|
60867
|
+
board: null,
|
|
60868
|
+
unmeasured: []
|
|
60869
|
+
};
|
|
59642
60870
|
let moved = [];
|
|
59643
60871
|
const recentlyMoved = () => {
|
|
59644
60872
|
moved = moved.filter(({ at }) => Date.now() - at < MOVED_MS);
|
|
@@ -59730,7 +60958,8 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
59730
60958
|
path: boardPath(root, frame.path),
|
|
59731
60959
|
box,
|
|
59732
60960
|
scroll: frame.scroll,
|
|
59733
|
-
hugHeight: frame.hugHeight
|
|
60961
|
+
hugHeight: frame.hugHeight,
|
|
60962
|
+
device: box.width === frame.box.width ? frame.device : void 0
|
|
59734
60963
|
},
|
|
59735
60964
|
config: readConfig(root, frame.project)
|
|
59736
60965
|
}));
|
|
@@ -59860,6 +61089,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
59860
61089
|
let latest = scanned.board ?? board;
|
|
59861
61090
|
if (trails) {
|
|
59862
61091
|
latest = await scanBoard(root);
|
|
61092
|
+
scanned.unmeasured = placedRefs(scanned.board ?? board, latest, void 0, scanned.unmeasured);
|
|
59863
61093
|
scanned.board = latest;
|
|
59864
61094
|
hub.broadcast({
|
|
59865
61095
|
type: "board",
|
|
@@ -59950,10 +61180,12 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
|
|
|
59950
61180
|
try {
|
|
59951
61181
|
await landReserved(root, /* @__PURE__ */ new Date()).catch(() => []);
|
|
59952
61182
|
board = await scanBoard(root);
|
|
59953
|
-
const previous = scanned
|
|
59954
|
-
scanned.board = board;
|
|
61183
|
+
const { board: previous, unmeasured } = scanned;
|
|
59955
61184
|
own = ownFileRefs(board, paths);
|
|
59956
|
-
placed = previous ? placedRefs(previous, board, paths).filter((ref) => !own.includes(ref)) : [];
|
|
61185
|
+
placed = previous ? placedRefs(previous, board, paths, unmeasured).filter((ref) => !own.includes(ref)) : [];
|
|
61186
|
+
const measuring = /* @__PURE__ */ new Set([...own, ...placed]);
|
|
61187
|
+
scanned.board = board;
|
|
61188
|
+
scanned.unmeasured = previous ? placedRefs(previous, board, void 0, unmeasured).filter((ref) => !measuring.has(ref)) : [];
|
|
59957
61189
|
relisted = previous ? relistedRefs(previous, board) : [];
|
|
59958
61190
|
rekitted = previous ? rekittedRefs(previous, board) : [];
|
|
59959
61191
|
if (await hug.now(board, [...own, ...placed]).catch(() => false)) {
|
|
@@ -60083,7 +61315,7 @@ async function pushNotes(root, paths, hub, delivery) {
|
|
|
60083
61315
|
const parts = relative(root, path).split(sep);
|
|
60084
61316
|
const [project, page, file] = parts;
|
|
60085
61317
|
if (parts.length !== 3 || !project || !page || !file) continue;
|
|
60086
|
-
const notes = file === NOTES_FILE$
|
|
61318
|
+
const notes = file === NOTES_FILE$1;
|
|
60087
61319
|
if (!notes && !file.endsWith(".html")) continue;
|
|
60088
61320
|
const key = `${project}/${page}`;
|
|
60089
61321
|
pages.set(key, {
|
|
@@ -60415,6 +61647,7 @@ function createProgram(context) {
|
|
|
60415
61647
|
registerProject(program, context);
|
|
60416
61648
|
registerKit(program, context);
|
|
60417
61649
|
registerImage(program, context);
|
|
61650
|
+
registerModel(program, context);
|
|
60418
61651
|
registerPage(program, context);
|
|
60419
61652
|
registerFrame(program, faced);
|
|
60420
61653
|
registerEdit(program, context);
|