frameboard 0.19.0 → 0.20.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 +520 -66
- package/dist/client/assets/index-BKwPJ6Ti.css +2 -0
- package/dist/client/assets/index-DPN95MNk.js +110 -0
- package/dist/client/index.html +2 -2
- package/package.json +2 -2
- package/dist/client/assets/index-BLJKIo7I.js +0 -110
- package/dist/client/assets/index-i1YrbWko.css +0 -2
package/dist/cli.js
CHANGED
|
@@ -3045,7 +3045,8 @@ const EXIT_CODES = {
|
|
|
3045
3045
|
"client-not-built": 3,
|
|
3046
3046
|
"tokens-exist": 4,
|
|
3047
3047
|
"dispatch-unavailable": 3,
|
|
3048
|
-
"dispatch-failed": 13
|
|
3048
|
+
"dispatch-failed": 13,
|
|
3049
|
+
"section-not-found": 3
|
|
3049
3050
|
};
|
|
3050
3051
|
var FrameboardError = class extends Error {
|
|
3051
3052
|
code;
|
|
@@ -9092,6 +9093,20 @@ const DEVICE_SIZES = [
|
|
|
9092
9093
|
group: "desktop",
|
|
9093
9094
|
width: 1920,
|
|
9094
9095
|
height: 1080
|
|
9096
|
+
},
|
|
9097
|
+
{
|
|
9098
|
+
name: "slide-16-9",
|
|
9099
|
+
label: "Slide 16:9",
|
|
9100
|
+
group: "slide",
|
|
9101
|
+
width: 1920,
|
|
9102
|
+
height: 1080
|
|
9103
|
+
},
|
|
9104
|
+
{
|
|
9105
|
+
name: "slide-4-3",
|
|
9106
|
+
label: "Slide 4:3",
|
|
9107
|
+
group: "slide",
|
|
9108
|
+
width: 1024,
|
|
9109
|
+
height: 768
|
|
9095
9110
|
}
|
|
9096
9111
|
];
|
|
9097
9112
|
/** Every size name, the three presets first, then the devices. */
|
|
@@ -9139,10 +9154,38 @@ const layoutEntrySchema = looseObject({
|
|
|
9139
9154
|
hugWidth: boolean$1().optional(),
|
|
9140
9155
|
hugHeight: boolean$1().optional()
|
|
9141
9156
|
});
|
|
9157
|
+
/** A named box grouping the frames whose center it holds, which it never lists. */
|
|
9158
|
+
const sectionEntrySchema = looseObject({
|
|
9159
|
+
x: int$1(),
|
|
9160
|
+
y: int$1(),
|
|
9161
|
+
width: int$1().min(1),
|
|
9162
|
+
height: int$1().min(1),
|
|
9163
|
+
order: int$1().min(0)
|
|
9164
|
+
});
|
|
9142
9165
|
const layoutFileSchema = looseObject({
|
|
9143
9166
|
version: literal(1),
|
|
9144
|
-
frames: record(string$1(), layoutEntrySchema)
|
|
9167
|
+
frames: record(string$1(), layoutEntrySchema),
|
|
9168
|
+
sections: record(string$1(), sectionEntrySchema).optional()
|
|
9145
9169
|
});
|
|
9170
|
+
// src/shared/sections.ts
|
|
9171
|
+
/**
|
|
9172
|
+
* Each frame's section, by name, keyed by frame name. A frame belongs to the
|
|
9173
|
+
* topmost section holding its center, the left and top edges inside and the
|
|
9174
|
+
* right and bottom outside, so two sections sharing an edge never both claim
|
|
9175
|
+
* it. Membership is read off geometry and never stored, so no frame writer
|
|
9176
|
+
* keeps a member list in step.
|
|
9177
|
+
*/
|
|
9178
|
+
function membersOf(sections, frames) {
|
|
9179
|
+
const topFirst = [...sections].sort((a, b) => b.order - a.order || (a.name < b.name ? 1 : -1));
|
|
9180
|
+
const members = /* @__PURE__ */ new Map();
|
|
9181
|
+
for (const frame of frames) {
|
|
9182
|
+
const cx = frame.box.x + frame.box.width / 2;
|
|
9183
|
+
const cy = frame.box.y + frame.box.height / 2;
|
|
9184
|
+
const holder = topFirst.find(({ box }) => cx >= box.x && cx < box.x + box.width && cy >= box.y && cy < box.y + box.height);
|
|
9185
|
+
if (holder) members.set(frame.name, holder.name);
|
|
9186
|
+
}
|
|
9187
|
+
return members;
|
|
9188
|
+
}
|
|
9146
9189
|
// src/server/board/scan.ts
|
|
9147
9190
|
const LAYOUT_FILE = "layout.json";
|
|
9148
9191
|
const layoutSpec = {
|
|
@@ -9307,9 +9350,12 @@ async function scanPage(root, project, name, index) {
|
|
|
9307
9350
|
const path = join(root, project, name);
|
|
9308
9351
|
const layoutPath = join(path, LAYOUT_FILE);
|
|
9309
9352
|
let frames = {};
|
|
9353
|
+
let sections = {};
|
|
9310
9354
|
let layoutError = null;
|
|
9311
9355
|
try {
|
|
9312
|
-
|
|
9356
|
+
const file = await readRecord(layoutPath, layoutSpec);
|
|
9357
|
+
frames = file.frames;
|
|
9358
|
+
sections = file.sections ?? {};
|
|
9313
9359
|
} catch (error) {
|
|
9314
9360
|
if (!(error instanceof FrameboardError)) throw error;
|
|
9315
9361
|
layoutError = {
|
|
@@ -9319,7 +9365,7 @@ async function scanPage(root, project, name, index) {
|
|
|
9319
9365
|
}
|
|
9320
9366
|
const names = await listFrames(path);
|
|
9321
9367
|
const placements = placeFrames(frames, names);
|
|
9322
|
-
const
|
|
9368
|
+
const stacked = (await Promise.all(names.map(async (frame) => {
|
|
9323
9369
|
const framePath = join(path, `${frame}${FRAME_EXTENSION}`);
|
|
9324
9370
|
const placement = placements.get(frame) ?? placeNext([]);
|
|
9325
9371
|
return {
|
|
@@ -9331,7 +9377,7 @@ async function scanPage(root, project, name, index) {
|
|
|
9331
9377
|
...placement,
|
|
9332
9378
|
modifiedAt: new Date(await mtimeOf$1(framePath)).toISOString()
|
|
9333
9379
|
};
|
|
9334
|
-
}));
|
|
9380
|
+
}))).sort(byStacking);
|
|
9335
9381
|
return {
|
|
9336
9382
|
ref: `${project}/${name}`,
|
|
9337
9383
|
project,
|
|
@@ -9339,9 +9385,28 @@ async function scanPage(root, project, name, index) {
|
|
|
9339
9385
|
path,
|
|
9340
9386
|
index,
|
|
9341
9387
|
layoutError,
|
|
9342
|
-
frames:
|
|
9388
|
+
frames: stacked,
|
|
9389
|
+
sections: sectionRecords(sections, stacked)
|
|
9343
9390
|
};
|
|
9344
9391
|
}
|
|
9392
|
+
/** The page's sections bottom first, each naming its members in stacking order. */
|
|
9393
|
+
function sectionRecords(entries, frames) {
|
|
9394
|
+
const sections = Object.entries(entries).map(([name, { x, y, width, height, order }]) => ({
|
|
9395
|
+
name,
|
|
9396
|
+
box: {
|
|
9397
|
+
x,
|
|
9398
|
+
y,
|
|
9399
|
+
width,
|
|
9400
|
+
height
|
|
9401
|
+
},
|
|
9402
|
+
order
|
|
9403
|
+
}));
|
|
9404
|
+
const members = membersOf(sections, frames);
|
|
9405
|
+
return sections.sort(byStacking).map((section) => ({
|
|
9406
|
+
...section,
|
|
9407
|
+
frames: frames.filter((frame) => members.get(frame.name) === section.name).map((frame) => frame.name)
|
|
9408
|
+
}));
|
|
9409
|
+
}
|
|
9345
9410
|
async function childFolders(dir) {
|
|
9346
9411
|
return (await readdir(dir, { withFileTypes: true })).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name);
|
|
9347
9412
|
}
|
|
@@ -9415,7 +9480,7 @@ async function isDirectory(path) {
|
|
|
9415
9480
|
}
|
|
9416
9481
|
}
|
|
9417
9482
|
// package.json
|
|
9418
|
-
var version$1 = "0.
|
|
9483
|
+
var version$1 = "0.20.0";
|
|
9419
9484
|
var dependencies = { "playwright-core": "1.64.1" };
|
|
9420
9485
|
// src/shared/version.ts
|
|
9421
9486
|
const version = version$1;
|
|
@@ -9867,13 +9932,35 @@ async function setMeasured(root, pageRef, sizes, options) {
|
|
|
9867
9932
|
* Sets the boxes of several frames on one page under one lock and one write,
|
|
9868
9933
|
* the one path a hand move or resize takes. `expected` holds the boxes the
|
|
9869
9934
|
* client started from, and a frame whose stored box differs from it refuses
|
|
9870
|
-
* the whole write, so a hand edit never silently undoes an agent's.
|
|
9935
|
+
* the whole write, so a hand edit never silently undoes an agent's. A section
|
|
9936
|
+
* move carries its box in `sections` beside its members' boxes, so the box
|
|
9937
|
+
* and the frames move as one step or not at all.
|
|
9871
9938
|
*/
|
|
9872
9939
|
async function setBoxes(root, pageRef, boxes, expected, options) {
|
|
9873
9940
|
const page = await resolvePageRef(root, pageRef, options);
|
|
9874
9941
|
const names = Object.keys(boxes);
|
|
9875
9942
|
await withLayouts([page.path], async (layouts) => {
|
|
9876
9943
|
const layout = layoutAt(layouts, page.path);
|
|
9944
|
+
const sections = Object.entries(options.sections ?? {}).map(([name, box]) => {
|
|
9945
|
+
const ref = `${page.project}/${page.name}`;
|
|
9946
|
+
const entry = layout.section(name);
|
|
9947
|
+
if (!entry) throw new FrameboardError("section-not-found", `No section ${name} on ${ref}.`, {
|
|
9948
|
+
page: ref,
|
|
9949
|
+
name
|
|
9950
|
+
});
|
|
9951
|
+
const started = options.expectedSections?.[name];
|
|
9952
|
+
if (!started || !sameBox(started, entry)) throw new FrameboardError("stale-layout", `Section ${name} moved since this edit began, so nothing was written.`, {
|
|
9953
|
+
page: ref,
|
|
9954
|
+
name,
|
|
9955
|
+
stored: boxOf(entry),
|
|
9956
|
+
expected: started ?? null
|
|
9957
|
+
});
|
|
9958
|
+
return {
|
|
9959
|
+
name,
|
|
9960
|
+
entry,
|
|
9961
|
+
box
|
|
9962
|
+
};
|
|
9963
|
+
});
|
|
9877
9964
|
const placements = names.map((name) => {
|
|
9878
9965
|
const ref = `${page.project}/${page.name}/${name}`;
|
|
9879
9966
|
if (!layout.names.includes(name)) throw new FrameboardError("frame-not-found", `No frame ${ref}.`, { ref });
|
|
@@ -9898,6 +9985,10 @@ async function setBoxes(root, pageRef, boxes, expected, options) {
|
|
|
9898
9985
|
started
|
|
9899
9986
|
};
|
|
9900
9987
|
});
|
|
9988
|
+
for (const { name, entry, box } of sections) layout.setSection(name, {
|
|
9989
|
+
...entry,
|
|
9990
|
+
...box
|
|
9991
|
+
});
|
|
9901
9992
|
for (const { name, placement, box, kept, started } of placements) {
|
|
9902
9993
|
if (!box || !started) continue;
|
|
9903
9994
|
layout.set(name, {
|
|
@@ -9924,6 +10015,14 @@ function measuredAxes(placement, box, started) {
|
|
|
9924
10015
|
...placement.hugHeight && box.height === started.height ? { height: placement.box.height } : {}
|
|
9925
10016
|
};
|
|
9926
10017
|
}
|
|
10018
|
+
function boxOf({ x, y, width, height }) {
|
|
10019
|
+
return {
|
|
10020
|
+
x,
|
|
10021
|
+
y,
|
|
10022
|
+
width,
|
|
10023
|
+
height
|
|
10024
|
+
};
|
|
10025
|
+
}
|
|
9927
10026
|
function sameBox(a, b) {
|
|
9928
10027
|
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
9929
10028
|
}
|
|
@@ -10059,6 +10158,34 @@ var PageLayout = class {
|
|
|
10059
10158
|
delete this.file.frames[name];
|
|
10060
10159
|
this.changed = true;
|
|
10061
10160
|
}
|
|
10161
|
+
sectionNames() {
|
|
10162
|
+
return Object.keys(this.file.sections ?? {});
|
|
10163
|
+
}
|
|
10164
|
+
section(name) {
|
|
10165
|
+
const sections = this.file.sections ?? {};
|
|
10166
|
+
return Object.hasOwn(sections, name) ? sections[name] : void 0;
|
|
10167
|
+
}
|
|
10168
|
+
/** Writes the five fixed keys after any the entry already held, so unknown keys survive. */
|
|
10169
|
+
setSection(name, entry) {
|
|
10170
|
+
const sections = this.file.sections ??= {};
|
|
10171
|
+
const { x, y, width, height, order } = entry;
|
|
10172
|
+
sections[name] = {
|
|
10173
|
+
...sections[name],
|
|
10174
|
+
x,
|
|
10175
|
+
y,
|
|
10176
|
+
width,
|
|
10177
|
+
height,
|
|
10178
|
+
order
|
|
10179
|
+
};
|
|
10180
|
+
this.changed = true;
|
|
10181
|
+
}
|
|
10182
|
+
removeSection(name) {
|
|
10183
|
+
if (this.file.sections) delete this.file.sections[name];
|
|
10184
|
+
this.changed = true;
|
|
10185
|
+
}
|
|
10186
|
+
topSectionOrder() {
|
|
10187
|
+
return Math.max(...this.sectionNames().map((name) => (this.section(name)?.order ?? 0) + 1), 0);
|
|
10188
|
+
}
|
|
10062
10189
|
/** Renumbers the page's placed frames densely from 0, touching only entries whose order moves. */
|
|
10063
10190
|
renumber() {
|
|
10064
10191
|
const placed = this.stack().filter((name) => this.hasEntry(name));
|
|
@@ -10103,6 +10230,13 @@ function reportEntries(journal, page, before, after) {
|
|
|
10103
10230
|
const to = after.frames[frame];
|
|
10104
10231
|
if (!isDeepStrictEqual(from, to)) journal.entry(page, frame, from, to);
|
|
10105
10232
|
}
|
|
10233
|
+
const wasSections = before?.sections ?? {};
|
|
10234
|
+
const nowSections = after.sections ?? {};
|
|
10235
|
+
for (const section of /* @__PURE__ */ new Set([...Object.keys(wasSections), ...Object.keys(nowSections)])) {
|
|
10236
|
+
const from = wasSections[section];
|
|
10237
|
+
const to = nowSections[section];
|
|
10238
|
+
if (!isDeepStrictEqual(from, to)) journal.section(page, section, from, to);
|
|
10239
|
+
}
|
|
10106
10240
|
}
|
|
10107
10241
|
function layoutAt(layouts, page) {
|
|
10108
10242
|
const layout = layouts.get(page);
|
|
@@ -27937,7 +28071,9 @@ const boxesSchema = record(string$1().min(1).max(256), boxSchema).refine((boxes)
|
|
|
27937
28071
|
const boxesBodySchema = object$1({
|
|
27938
28072
|
page: string$1().min(1).max(1024),
|
|
27939
28073
|
boxes: boxesSchema,
|
|
27940
|
-
expected: boxesSchema
|
|
28074
|
+
expected: boxesSchema,
|
|
28075
|
+
sections: boxesSchema.optional(),
|
|
28076
|
+
expectedSections: boxesSchema.optional()
|
|
27941
28077
|
});
|
|
27942
28078
|
const STATUS$4 = {
|
|
27943
28079
|
usage: 400,
|
|
@@ -27946,6 +28082,7 @@ const STATUS$4 = {
|
|
|
27946
28082
|
"project-not-found": 404,
|
|
27947
28083
|
"page-not-found": 404,
|
|
27948
28084
|
"frame-not-found": 404,
|
|
28085
|
+
"section-not-found": 404,
|
|
27949
28086
|
"stale-layout": 409,
|
|
27950
28087
|
"frame-claimed": 409,
|
|
27951
28088
|
"frame-locked": 423,
|
|
@@ -28010,17 +28147,19 @@ function apiRoutes(root, actions, look, history) {
|
|
|
28010
28147
|
ok: false,
|
|
28011
28148
|
error: {
|
|
28012
28149
|
code: "usage",
|
|
28013
|
-
message: "Send { \"page\": \"<page ref>\", \"boxes\": { <frame>: box }, \"expected\": { <frame>: box } }."
|
|
28150
|
+
message: "Send { \"page\": \"<page ref>\", \"boxes\": { <frame>: box }, \"expected\": { <frame>: box } }, with \"sections\" and \"expectedSections\" by section name to move a section."
|
|
28014
28151
|
}
|
|
28015
28152
|
}, 400);
|
|
28016
|
-
const { page, boxes, expected } = body.data;
|
|
28153
|
+
const { page, boxes, expected, sections, expectedSections } = body.data;
|
|
28017
28154
|
try {
|
|
28018
28155
|
const target = await resolvePageRef(root, page, { cwd: root });
|
|
28019
28156
|
await refuseClaimed(root, Object.keys(boxes).map((name) => `${target.project}/${target.name}/${name}`), /* @__PURE__ */ new Date());
|
|
28020
28157
|
const journal = history?.journal();
|
|
28021
28158
|
const frames = await setBoxes(root, page, boxes, expected, {
|
|
28022
28159
|
cwd: root,
|
|
28023
|
-
journal
|
|
28160
|
+
journal,
|
|
28161
|
+
sections,
|
|
28162
|
+
expectedSections
|
|
28024
28163
|
});
|
|
28025
28164
|
if (history && journal) history.record({
|
|
28026
28165
|
id: journal.id,
|
|
@@ -28122,6 +28261,16 @@ const ASSET_KINDS = [
|
|
|
28122
28261
|
"script",
|
|
28123
28262
|
"other"
|
|
28124
28263
|
];
|
|
28264
|
+
/** The kinds a frame shows as an `<img>` or a `<video>`, which the board places by hand. */
|
|
28265
|
+
const PLACEABLE_KINDS = [
|
|
28266
|
+
"image",
|
|
28267
|
+
"gif",
|
|
28268
|
+
"svg",
|
|
28269
|
+
"video"
|
|
28270
|
+
];
|
|
28271
|
+
function isPlaceableKind(kind) {
|
|
28272
|
+
return PLACEABLE_KINDS.includes(kind);
|
|
28273
|
+
}
|
|
28125
28274
|
/** The extensions a drop accepts, each with the kind its tile draws. */
|
|
28126
28275
|
const ACCEPTED = {
|
|
28127
28276
|
png: "image",
|
|
@@ -28210,6 +28359,41 @@ async function walk(folder, prefix, real, into) {
|
|
|
28210
28359
|
});
|
|
28211
28360
|
}
|
|
28212
28361
|
}
|
|
28362
|
+
/**
|
|
28363
|
+
* The kind of the file at `path` under a project's `assets/`, when a frame
|
|
28364
|
+
* can show it, confined as `listAssets` is: a path naming a dot-named
|
|
28365
|
+
* segment, a `..`, or any file whose real path leaves the folder is
|
|
28366
|
+
* `asset-missing`, as is one that is not there. A file that is there but is
|
|
28367
|
+
* no image, GIF, SVG, or video is `asset-not-placeable`.
|
|
28368
|
+
*/
|
|
28369
|
+
async function resolveAsset(projectDir, path) {
|
|
28370
|
+
const missing = {
|
|
28371
|
+
ok: false,
|
|
28372
|
+
code: "asset-missing",
|
|
28373
|
+
message: `assets/${path} is not a file in the project's assets folder`
|
|
28374
|
+
};
|
|
28375
|
+
const segments = path.split("/");
|
|
28376
|
+
if (segments.some((segment) => segment === "" || segment.startsWith(".") || isScratch(segment))) return missing;
|
|
28377
|
+
const folder = join(projectDir, ASSETS_FOLDER);
|
|
28378
|
+
try {
|
|
28379
|
+
const real = await realpath(folder);
|
|
28380
|
+
const target = await realpath(join(folder, ...segments));
|
|
28381
|
+
if (!target.startsWith(real + sep) || !(await stat(target)).isFile()) return missing;
|
|
28382
|
+
} catch (error) {
|
|
28383
|
+
if (isCode(error, "ENOENT") || isCode(error, "ENOTDIR")) return missing;
|
|
28384
|
+
throw error;
|
|
28385
|
+
}
|
|
28386
|
+
const kind = assetKind(path);
|
|
28387
|
+
if (!isPlaceableKind(kind)) return {
|
|
28388
|
+
ok: false,
|
|
28389
|
+
code: "asset-not-placeable",
|
|
28390
|
+
message: `assets/${path} is not an image, GIF, SVG, or video, so a frame cannot show it`
|
|
28391
|
+
};
|
|
28392
|
+
return {
|
|
28393
|
+
ok: true,
|
|
28394
|
+
kind
|
|
28395
|
+
};
|
|
28396
|
+
}
|
|
28213
28397
|
function isScratch(name) {
|
|
28214
28398
|
return name.endsWith(".lock") || name.endsWith(".tmp");
|
|
28215
28399
|
}
|
|
@@ -28297,7 +28481,7 @@ function assetsRoutes(root, access, limit = ASSET_BODY_LIMIT) {
|
|
|
28297
28481
|
const path = "/api/projects/:project/assets";
|
|
28298
28482
|
app.get(path, async (c) => {
|
|
28299
28483
|
const projectDir = projectFolder(root, c.req.param("project"));
|
|
28300
|
-
if (projectDir === null) return c.json(notFound(c.req.param("project")), 404);
|
|
28484
|
+
if (projectDir === null) return c.json(notFound$1(c.req.param("project")), 404);
|
|
28301
28485
|
return c.json({
|
|
28302
28486
|
ok: true,
|
|
28303
28487
|
data: { files: await listAssets(projectDir) }
|
|
@@ -28314,7 +28498,7 @@ function assetsRoutes(root, access, limit = ASSET_BODY_LIMIT) {
|
|
|
28314
28498
|
}, 413)
|
|
28315
28499
|
}), async (c) => {
|
|
28316
28500
|
const projectDir = projectFolder(root, c.req.param("project"));
|
|
28317
|
-
if (projectDir === null) return c.json(notFound(c.req.param("project")), 404);
|
|
28501
|
+
if (projectDir === null) return c.json(notFound$1(c.req.param("project")), 404);
|
|
28318
28502
|
const sent = [(await c.req.parseBody({ all: true }).catch(() => ({}))).files].flat().filter((v) => v instanceof File);
|
|
28319
28503
|
if (sent.length === 0) return c.json({
|
|
28320
28504
|
ok: false,
|
|
@@ -28338,7 +28522,7 @@ function projectFolder(root, project) {
|
|
|
28338
28522
|
const folder = join(root, project);
|
|
28339
28523
|
return isValidName(project) && existsSync(folder) ? folder : null;
|
|
28340
28524
|
}
|
|
28341
|
-
function notFound(project) {
|
|
28525
|
+
function notFound$1(project) {
|
|
28342
28526
|
return {
|
|
28343
28527
|
ok: false,
|
|
28344
28528
|
error: {
|
|
@@ -29265,17 +29449,34 @@ function textFont(tokens) {
|
|
|
29265
29449
|
function elementMarkup(element, paint, font) {
|
|
29266
29450
|
const { fill, line } = paint;
|
|
29267
29451
|
if (!PAINT_VALUE.test(fill) || !PAINT_VALUE.test(line)) throw new Error(`Unexpected shape paint ${fill} ${line}`);
|
|
29268
|
-
const
|
|
29452
|
+
const size = ({ width = SHAPE_SIZE, height = SHAPE_SIZE }) => {
|
|
29269
29453
|
if (!Number.isInteger(width) || !Number.isInteger(height)) throw new Error(`Unexpected shape size ${width} ${height}`);
|
|
29270
|
-
return `width: ${width}px; height: ${height}px
|
|
29454
|
+
return `width: ${width}px; height: ${height}px`;
|
|
29271
29455
|
};
|
|
29456
|
+
const box = (shape) => `${size(shape)}; background: ${fill}`;
|
|
29272
29457
|
switch (element.kind) {
|
|
29273
29458
|
case "text": return `<p data-name="Text" style="font-family: ${font}">Text</p>`;
|
|
29274
29459
|
case "rectangle": return `<div data-name="Rectangle" style="${box(element)}"></div>`;
|
|
29275
29460
|
case "ellipse": return `<div data-name="Ellipse" style="${box(element)}; border-radius: 50%"></div>`;
|
|
29276
29461
|
case "divider": return `<hr data-name="Divider" style="align-self: stretch; margin: 0; border: 0; ${element.vertical ? "border-left" : "border-top"}: 1px solid ${line}">`;
|
|
29462
|
+
case "asset": {
|
|
29463
|
+
const name = attribute$1(element.path.split("/").at(-1) ?? element.path);
|
|
29464
|
+
const style = `${size(element)}; object-fit: cover`;
|
|
29465
|
+
return element.video ? `<video data-name="${name}" src="${assetLink(element.path)}" autoplay muted loop playsinline style="${style}"></video>` : `<img data-name="${name}" src="${assetLink(element.path)}" alt="" style="${style}">`;
|
|
29466
|
+
}
|
|
29277
29467
|
}
|
|
29278
29468
|
}
|
|
29469
|
+
/**
|
|
29470
|
+
* The path a frame at `<project>/<page>/<frame>.html` links a project asset
|
|
29471
|
+
* by, each segment encoded, as the Assets tab's `linkPath` copies it.
|
|
29472
|
+
*/
|
|
29473
|
+
function assetLink(path) {
|
|
29474
|
+
return `../assets/${path.split("/").map(encodeURIComponent).join("/")}`;
|
|
29475
|
+
}
|
|
29476
|
+
/** `text` as a double-quoted attribute value holds it. */
|
|
29477
|
+
function attribute$1(text) {
|
|
29478
|
+
return text.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<");
|
|
29479
|
+
}
|
|
29279
29480
|
function startTag(source, element) {
|
|
29280
29481
|
return spanText(source, element, "start-tag");
|
|
29281
29482
|
}
|
|
@@ -29695,6 +29896,7 @@ const STATUS$3 = {
|
|
|
29695
29896
|
"project-not-found": 404,
|
|
29696
29897
|
"page-not-found": 404,
|
|
29697
29898
|
"frame-not-found": 404,
|
|
29899
|
+
"section-not-found": 404,
|
|
29698
29900
|
"name-taken": 409,
|
|
29699
29901
|
"stale-layout": 409,
|
|
29700
29902
|
"frame-claimed": 409,
|
|
@@ -29782,6 +29984,12 @@ const insertSchema = object$1({
|
|
|
29782
29984
|
object$1({
|
|
29783
29985
|
kind: literal("divider"),
|
|
29784
29986
|
vertical: boolean$1()
|
|
29987
|
+
}),
|
|
29988
|
+
object$1({
|
|
29989
|
+
kind: literal("asset"),
|
|
29990
|
+
path: string$1().min(1).max(1024),
|
|
29991
|
+
width: side,
|
|
29992
|
+
height: side
|
|
29785
29993
|
})
|
|
29786
29994
|
])
|
|
29787
29995
|
});
|
|
@@ -29817,6 +30025,10 @@ const moveSchema$1 = object$1({
|
|
|
29817
30025
|
* has answers 409 `stale-address` with nothing written, since the gap's
|
|
29818
30026
|
* indices name nothing past an agent's write, and a retried insert lands once.
|
|
29819
30027
|
* A rectangle or an ellipse takes an optional width and height a drag drew.
|
|
30028
|
+
* An asset names a file under the project's `assets/` and the size it
|
|
30029
|
+
* shows at, and the server picks its tag from the file's kind. A file
|
|
30030
|
+
* outside that folder or not there answers 409 `asset-missing`, and one that
|
|
30031
|
+
* is no image, GIF, SVG, or video `asset-not-placeable`, each writing nothing.
|
|
29820
30032
|
*
|
|
29821
30033
|
* The remove takes out the element at `index`, with what it holds, from the
|
|
29822
30034
|
* bytes `hash` names, and records it as one step whose undo puts it back
|
|
@@ -29880,10 +30092,30 @@ function editRoutes(root, access, history, version, sheets) {
|
|
|
29880
30092
|
const ref = `${frame.project}/${frame.page}/${frame.name}`;
|
|
29881
30093
|
await refuseClaimed(root, [ref], /* @__PURE__ */ new Date());
|
|
29882
30094
|
const tokens = sheets ? readTokenTable(root, sheets(frame.project)).tokens : [];
|
|
30095
|
+
let element;
|
|
30096
|
+
if (body.element.kind !== "asset") element = body.element;
|
|
30097
|
+
else {
|
|
30098
|
+
const asset = await resolveAsset(join(root, frame.project), body.element.path);
|
|
30099
|
+
if (!asset.ok) return c.json({
|
|
30100
|
+
ok: false,
|
|
30101
|
+
error: {
|
|
30102
|
+
code: asset.code,
|
|
30103
|
+
message: asset.message,
|
|
30104
|
+
details: {
|
|
30105
|
+
ref,
|
|
30106
|
+
path: body.element.path
|
|
30107
|
+
}
|
|
30108
|
+
}
|
|
30109
|
+
}, 409);
|
|
30110
|
+
element = {
|
|
30111
|
+
...body.element,
|
|
30112
|
+
video: asset.kind === "video"
|
|
30113
|
+
};
|
|
30114
|
+
}
|
|
29883
30115
|
const result = insertFrameFile(frame.path, body.hash, {
|
|
29884
30116
|
parent: body.parent,
|
|
29885
30117
|
before: body.before
|
|
29886
|
-
}, elementMarkup(
|
|
30118
|
+
}, elementMarkup(element, shapePaint(tokens), textFont(tokens)));
|
|
29887
30119
|
if (!result.ok) return c.json({
|
|
29888
30120
|
ok: false,
|
|
29889
30121
|
error: {
|
|
@@ -36706,11 +36938,15 @@ const STATUS = {
|
|
|
36706
36938
|
"page-not-found": 404,
|
|
36707
36939
|
"frame-not-found": 404,
|
|
36708
36940
|
"font-missing": 422,
|
|
36941
|
+
"capture-too-large": 422,
|
|
36709
36942
|
"browser-not-found": 503
|
|
36710
36943
|
};
|
|
36944
|
+
/** The route's scale when none is asked for, matching Copy as PNG. */
|
|
36945
|
+
const DEFAULT_SCALE = 2;
|
|
36711
36946
|
/**
|
|
36712
|
-
* `GET /api/frames/png?ref=<frame-ref>&theme=<light|dark>`, a
|
|
36713
|
-
* at
|
|
36947
|
+
* `GET /api/frames/png?ref=<frame-ref>&theme=<light|dark>&scale=<1|2|3>`, a
|
|
36948
|
+
* frame rendered at `scale` times its layout size, twice when no scale is
|
|
36949
|
+
* given. It takes no token, since the image shows only
|
|
36714
36950
|
* what the frame route already serves, and a refusal answers the CLI's
|
|
36715
36951
|
* `{ ok, error }` envelope.
|
|
36716
36952
|
*/
|
|
@@ -36720,11 +36956,13 @@ function pngRoutes(root, render) {
|
|
|
36720
36956
|
try {
|
|
36721
36957
|
const ref = c.req.query("ref") ?? "";
|
|
36722
36958
|
const theme = c.req.query("theme") ?? "";
|
|
36723
|
-
|
|
36959
|
+
const scale = parseScale$1(c.req.query("scale"));
|
|
36960
|
+
if (ref === "" || !isTheme(theme) || scale === null) throw new FrameboardError("usage", "Ask for /api/frames/png?ref=<frame-ref>&theme=<light|dark>&scale=<1|2|3>.", {
|
|
36724
36961
|
ref,
|
|
36725
|
-
theme
|
|
36962
|
+
theme,
|
|
36963
|
+
scale: c.req.query("scale") ?? null
|
|
36726
36964
|
});
|
|
36727
|
-
const bytes = await render(await readFrame$1(root, ref, { cwd: root }), theme);
|
|
36965
|
+
const bytes = await render(await readFrame$1(root, ref, { cwd: root }), theme, scale);
|
|
36728
36966
|
return c.body(new Uint8Array(bytes), 200, {
|
|
36729
36967
|
"Content-Type": "image/png",
|
|
36730
36968
|
"Cache-Control": "no-store"
|
|
@@ -36746,6 +36984,11 @@ function pngRoutes(root, render) {
|
|
|
36746
36984
|
function isTheme(value) {
|
|
36747
36985
|
return value === "light" || value === "dark";
|
|
36748
36986
|
}
|
|
36987
|
+
function parseScale$1(value) {
|
|
36988
|
+
if (value === void 0) return DEFAULT_SCALE;
|
|
36989
|
+
if (value === "1" || value === "2" || value === "3") return Number(value);
|
|
36990
|
+
return null;
|
|
36991
|
+
}
|
|
36749
36992
|
// src/server/board/pages.ts
|
|
36750
36993
|
/** Notes and their images belong to the page they were pinned on, so a copy starts without them. */
|
|
36751
36994
|
const NOT_COPIED = /* @__PURE__ */ new Set(["notes.json", ".notes"]);
|
|
@@ -36943,7 +37186,7 @@ async function pasteFrames(root, pageRef, held, options) {
|
|
|
36943
37186
|
/** A new project holding one empty page. */
|
|
36944
37187
|
async function addProject(root, name, now = /* @__PURE__ */ new Date(), { journal } = {}) {
|
|
36945
37188
|
assertValidName("project", name);
|
|
36946
|
-
await assertFree(root, name);
|
|
37189
|
+
await assertFree$1(root, name);
|
|
36947
37190
|
await mkdir(join(root, name, START_PAGE), { recursive: true });
|
|
36948
37191
|
await writeRecord(join(root, name, PROJECT_FILE), {
|
|
36949
37192
|
version: 1,
|
|
@@ -36956,7 +37199,7 @@ async function addProject(root, name, now = /* @__PURE__ */ new Date(), { journa
|
|
|
36956
37199
|
async function renameProject(root, name, newName, { journal } = {}) {
|
|
36957
37200
|
const project = await resolveProject(root, name);
|
|
36958
37201
|
assertValidName("project", newName);
|
|
36959
|
-
await assertFree(root, newName, project.name);
|
|
37202
|
+
await assertFree$1(root, newName, project.name);
|
|
36960
37203
|
const renamed = join(root, newName);
|
|
36961
37204
|
if (journal) await journal.moved(project.path, renamed);
|
|
36962
37205
|
else await rename(project.path, renamed);
|
|
@@ -36997,13 +37240,82 @@ async function deleteProject(root, name, { journal } = {}) {
|
|
|
36997
37240
|
return { deleted: project.name };
|
|
36998
37241
|
}
|
|
36999
37242
|
/** Throws `name-taken` when another project holds `name` in any case. */
|
|
37000
|
-
async function assertFree(root, name, self) {
|
|
37243
|
+
async function assertFree$1(root, name, self) {
|
|
37001
37244
|
const taken = matchName((await listProjects(root)).filter((project) => project !== self), name);
|
|
37002
37245
|
if (taken) throw new FrameboardError("name-taken", `The board already has a project ${taken}.`, {
|
|
37003
37246
|
name,
|
|
37004
37247
|
taken
|
|
37005
37248
|
});
|
|
37006
37249
|
}
|
|
37250
|
+
// src/server/board/sections.ts
|
|
37251
|
+
/** The name a section takes when the developer gives none, `-2` and on once taken. */
|
|
37252
|
+
const DEFAULT_NAME = "section";
|
|
37253
|
+
/**
|
|
37254
|
+
* Writes a named box on top of the page's sections. It writes no frame entry,
|
|
37255
|
+
* since a frame belongs to whichever section holds its center.
|
|
37256
|
+
*/
|
|
37257
|
+
async function addSection(root, pageRef, { name, box, journal, ...options }) {
|
|
37258
|
+
const page = await resolvePageRef(root, pageRef, options);
|
|
37259
|
+
return sectionRecord(root, page, await withLayouts([page.path], async (layouts) => {
|
|
37260
|
+
const layout = layoutAt(layouts, page.path);
|
|
37261
|
+
const taken = layout.sectionNames();
|
|
37262
|
+
const free = name === void 0 ? nextFreeName(DEFAULT_NAME, taken) : name;
|
|
37263
|
+
if (name !== void 0) assertFree(taken, name);
|
|
37264
|
+
layout.setSection(free, {
|
|
37265
|
+
...box,
|
|
37266
|
+
order: layout.topSectionOrder()
|
|
37267
|
+
});
|
|
37268
|
+
return free;
|
|
37269
|
+
}, journal));
|
|
37270
|
+
}
|
|
37271
|
+
async function renameSection(root, pageRef, name, newName, { journal, ...options }) {
|
|
37272
|
+
const page = await resolvePageRef(root, pageRef, options);
|
|
37273
|
+
await withLayouts([page.path], async (layouts) => {
|
|
37274
|
+
const layout = layoutAt(layouts, page.path);
|
|
37275
|
+
const entry = layout.section(name);
|
|
37276
|
+
if (!entry) throw notFound(page, name);
|
|
37277
|
+
if (newName === name) return;
|
|
37278
|
+
assertFree(layout.sectionNames().filter((held) => held !== name), newName);
|
|
37279
|
+
layout.removeSection(name);
|
|
37280
|
+
layout.file.sections = {
|
|
37281
|
+
...layout.file.sections,
|
|
37282
|
+
[newName]: entry
|
|
37283
|
+
};
|
|
37284
|
+
layout.setSection(newName, entry);
|
|
37285
|
+
}, journal);
|
|
37286
|
+
return sectionRecord(root, page, newName);
|
|
37287
|
+
}
|
|
37288
|
+
/** Removes the box alone, leaving every frame it held where it stands. */
|
|
37289
|
+
async function deleteSection(root, pageRef, name, { journal, ...options }) {
|
|
37290
|
+
const page = await resolvePageRef(root, pageRef, options);
|
|
37291
|
+
await withLayouts([page.path], async (layouts) => {
|
|
37292
|
+
const layout = layoutAt(layouts, page.path);
|
|
37293
|
+
if (!layout.section(name)) throw notFound(page, name);
|
|
37294
|
+
layout.removeSection(name);
|
|
37295
|
+
}, journal);
|
|
37296
|
+
return { deleted: name };
|
|
37297
|
+
}
|
|
37298
|
+
function assertFree(taken, name) {
|
|
37299
|
+
assertValidName("section", name);
|
|
37300
|
+
const holder = matchName(taken, name);
|
|
37301
|
+
if (holder) throw new FrameboardError("name-taken", `The page already has a section ${holder}.`, {
|
|
37302
|
+
name,
|
|
37303
|
+
taken: holder
|
|
37304
|
+
});
|
|
37305
|
+
}
|
|
37306
|
+
function notFound(page, name) {
|
|
37307
|
+
const ref = `${page.project}/${page.name}`;
|
|
37308
|
+
return new FrameboardError("section-not-found", `No section ${name} on ${ref}.`, {
|
|
37309
|
+
page: ref,
|
|
37310
|
+
name
|
|
37311
|
+
});
|
|
37312
|
+
}
|
|
37313
|
+
async function sectionRecord(root, page, name) {
|
|
37314
|
+
const { pages } = await readPageOrder(join(root, page.project));
|
|
37315
|
+
const section = (await scanPage(root, page.project, page.name, pages.indexOf(page.name))).sections.find((candidate) => candidate.name === name);
|
|
37316
|
+
if (!section) throw new Error(`Section ${name} vanished from ${page.name}.`);
|
|
37317
|
+
return section;
|
|
37318
|
+
}
|
|
37007
37319
|
// src/server/look/starter.ts
|
|
37008
37320
|
/**
|
|
37009
37321
|
* Writes a starter `tokens.css` into a project that renders with no token
|
|
@@ -37089,6 +37401,26 @@ const frameFlagSchema = object$1({
|
|
|
37089
37401
|
flag: _enum$1(["hidden", "locked"]),
|
|
37090
37402
|
on: boolean$1()
|
|
37091
37403
|
});
|
|
37404
|
+
const sectionBox = object$1({
|
|
37405
|
+
x: coordinate,
|
|
37406
|
+
y: coordinate,
|
|
37407
|
+
width: int$1().min(1),
|
|
37408
|
+
height: int$1().min(1)
|
|
37409
|
+
});
|
|
37410
|
+
const sectionAddSchema = object$1({
|
|
37411
|
+
page: ref,
|
|
37412
|
+
name: name.optional(),
|
|
37413
|
+
box: sectionBox
|
|
37414
|
+
});
|
|
37415
|
+
const sectionRenameSchema = object$1({
|
|
37416
|
+
page: ref,
|
|
37417
|
+
section: name,
|
|
37418
|
+
name
|
|
37419
|
+
});
|
|
37420
|
+
const sectionSchema = object$1({
|
|
37421
|
+
page: ref,
|
|
37422
|
+
section: name
|
|
37423
|
+
});
|
|
37092
37424
|
const projectAddSchema = object$1({ name: name.optional() });
|
|
37093
37425
|
const projectSchema = object$1({ ref });
|
|
37094
37426
|
const projectTokensSchema = object$1({
|
|
@@ -37112,6 +37444,7 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
37112
37444
|
app.use("/api/frame/*", requireWriter(access));
|
|
37113
37445
|
app.use("/api/clipboard/*", requireWriter(access));
|
|
37114
37446
|
app.use("/api/project/*", requireWriter(access));
|
|
37447
|
+
app.use("/api/section/*", requireWriter(access));
|
|
37115
37448
|
const cwd = root;
|
|
37116
37449
|
/** Runs one verb with a fresh journal and records what it reported. */
|
|
37117
37450
|
const recorded = async (write, describe) => {
|
|
@@ -37403,6 +37736,41 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
37403
37736
|
data: frames
|
|
37404
37737
|
});
|
|
37405
37738
|
});
|
|
37739
|
+
app.post("/api/section/add", async (c) => {
|
|
37740
|
+
const body = await parseBody$1(c.req.raw, sectionAddSchema);
|
|
37741
|
+
const section = await recorded((journal) => addSection(root, body.page, {
|
|
37742
|
+
cwd,
|
|
37743
|
+
name: body.name,
|
|
37744
|
+
box: body.box,
|
|
37745
|
+
journal
|
|
37746
|
+
}), () => onFrames([]));
|
|
37747
|
+
return c.json({
|
|
37748
|
+
ok: true,
|
|
37749
|
+
data: section
|
|
37750
|
+
});
|
|
37751
|
+
});
|
|
37752
|
+
app.post("/api/section/rename", async (c) => {
|
|
37753
|
+
const body = await parseBody$1(c.req.raw, sectionRenameSchema);
|
|
37754
|
+
const section = await recorded((journal) => renameSection(root, body.page, body.section, body.name, {
|
|
37755
|
+
cwd,
|
|
37756
|
+
journal
|
|
37757
|
+
}), () => onFrames([]));
|
|
37758
|
+
return c.json({
|
|
37759
|
+
ok: true,
|
|
37760
|
+
data: section
|
|
37761
|
+
});
|
|
37762
|
+
});
|
|
37763
|
+
app.post("/api/section/delete", async (c) => {
|
|
37764
|
+
const body = await parseBody$1(c.req.raw, sectionSchema);
|
|
37765
|
+
const result = await recorded((journal) => deleteSection(root, body.page, body.section, {
|
|
37766
|
+
cwd,
|
|
37767
|
+
journal
|
|
37768
|
+
}), () => onFrames([]));
|
|
37769
|
+
return c.json({
|
|
37770
|
+
ok: true,
|
|
37771
|
+
data: result
|
|
37772
|
+
});
|
|
37773
|
+
});
|
|
37406
37774
|
/** A project write leaves the board on home, so it follows no page or frame. */
|
|
37407
37775
|
const onHome = async () => ({
|
|
37408
37776
|
page: null,
|
|
@@ -37832,6 +38200,8 @@ async function platformFamilies(page, domIndexes) {
|
|
|
37832
38200
|
// src/server/capture/render.ts
|
|
37833
38201
|
/** How long a frame has to load before its capture fails. */
|
|
37834
38202
|
const LOAD_TIMEOUT_MS = 1e4;
|
|
38203
|
+
/** Chromium's screenshot surface stops at this many pixels on either side. */
|
|
38204
|
+
const MAX_COMPOSITE_SIDE = 16384;
|
|
37835
38205
|
/**
|
|
37836
38206
|
* Loads a frame in its own browser context at its layout size, in the theme
|
|
37837
38207
|
* asked for, and resolves once it has loaded and its faces have settled.
|
|
@@ -37863,6 +38233,22 @@ async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts =
|
|
|
37863
38233
|
}
|
|
37864
38234
|
}
|
|
37865
38235
|
/**
|
|
38236
|
+
* Refuses `capture-too-large` for a frame whose screenshot at `scale` would
|
|
38237
|
+
* pass Chromium's surface on either side, which would otherwise come back
|
|
38238
|
+
* cropped or blank rather than failing.
|
|
38239
|
+
*/
|
|
38240
|
+
function assertScreenshotFits(ref, box, scale) {
|
|
38241
|
+
const width = Math.ceil(box.width * scale);
|
|
38242
|
+
const height = Math.ceil(box.height * scale);
|
|
38243
|
+
if (width > 16384 || height > 16384) throw new FrameboardError("capture-too-large", `${ref} at ${scale}x would be ${width} by ${height} px, past the ${MAX_COMPOSITE_SIDE} px a browser screenshot holds. Pick a smaller scale.`, {
|
|
38244
|
+
ref,
|
|
38245
|
+
width,
|
|
38246
|
+
height,
|
|
38247
|
+
scale,
|
|
38248
|
+
max: MAX_COMPOSITE_SIDE
|
|
38249
|
+
});
|
|
38250
|
+
}
|
|
38251
|
+
/**
|
|
37866
38252
|
* One browser kept warm for a server and shared by everything rendering on
|
|
37867
38253
|
* it, so the server holds one Chromium. A launch that fails is not kept, so a
|
|
37868
38254
|
* browser installed later is found on the next call, and every call after
|
|
@@ -37893,10 +38279,11 @@ function createWarmBrowser(launch) {
|
|
|
37893
38279
|
* queue is the renderer's own, so a PNG never waits behind another consumer
|
|
37894
38280
|
* of the browser, such as a thumbnail.
|
|
37895
38281
|
*/
|
|
37896
|
-
function createWarmRenderer({ baseUrl, browser, scale }) {
|
|
38282
|
+
function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
|
|
37897
38283
|
let queue = Promise.resolve();
|
|
37898
|
-
return (frame, theme) => {
|
|
38284
|
+
return (frame, theme, scale = defaultScale) => {
|
|
37899
38285
|
const run = queue.then(async () => {
|
|
38286
|
+
assertScreenshotFits(frame.ref, frame.box, scale);
|
|
37900
38287
|
const opened = await openFrame(await browser.get(), {
|
|
37901
38288
|
baseUrl: baseUrl(),
|
|
37902
38289
|
ref: frame.ref,
|
|
@@ -37917,38 +38304,47 @@ function createWarmRenderer({ baseUrl, browser, scale }) {
|
|
|
37917
38304
|
return run;
|
|
37918
38305
|
};
|
|
37919
38306
|
}
|
|
37920
|
-
/** Chromium's screenshot surface stops at this many pixels on either side. */
|
|
37921
|
-
const MAX_COMPOSITE_SIDE = 16384;
|
|
37922
38307
|
const SCREENSHOT = {
|
|
37923
38308
|
animations: "disabled",
|
|
37924
38309
|
caret: "hide"
|
|
37925
38310
|
};
|
|
38311
|
+
/**
|
|
38312
|
+
* The file name of one image, `<name>.<theme>.png` at 1x so a path an agent
|
|
38313
|
+
* saved stays true, and `<name>.<theme>@<n>x.png` at any other scale.
|
|
38314
|
+
*/
|
|
38315
|
+
function imageName(name, theme, scale) {
|
|
38316
|
+
return scale === 1 ? `${name}.${theme}.png` : `${name}.${theme}@${scale}x.png`;
|
|
38317
|
+
}
|
|
37926
38318
|
/** Where one frame's capture in one theme lands under `out`. */
|
|
37927
|
-
function frameImagePath(out, frame, theme) {
|
|
37928
|
-
return join(out, frame.project, frame.page,
|
|
38319
|
+
function frameImagePath(out, frame, theme, scale = 1) {
|
|
38320
|
+
return join(out, frame.project, frame.page, imageName(frame.name, theme, scale));
|
|
37929
38321
|
}
|
|
37930
38322
|
/** Where a page's composite in one theme lands under `out`. */
|
|
37931
|
-
function compositeImagePath(out, page, theme) {
|
|
37932
|
-
return join(out, page.project,
|
|
38323
|
+
function compositeImagePath(out, page, theme, scale = 1) {
|
|
38324
|
+
return join(out, page.project, imageName(page.name, theme, scale));
|
|
37933
38325
|
}
|
|
37934
38326
|
/**
|
|
37935
38327
|
* The composite's size and the shift placing each frame in it, so the
|
|
37936
38328
|
* leftmost and topmost frames sit one margin in and one margin is left past
|
|
37937
38329
|
* the far edges. Refuses `capture-too-large` past Chromium's screenshot limit.
|
|
37938
38330
|
*/
|
|
37939
|
-
function compositeBounds(page, frames) {
|
|
38331
|
+
function compositeBounds(page, frames, scale = 1) {
|
|
37940
38332
|
const left = Math.min(...frames.map(({ box }) => box.x));
|
|
37941
38333
|
const top = Math.min(...frames.map(({ box }) => box.y));
|
|
37942
38334
|
const right = Math.max(...frames.map(({ box }) => box.x + box.width));
|
|
37943
38335
|
const bottom = Math.max(...frames.map(({ box }) => box.y + box.height));
|
|
37944
38336
|
const width = right - left + 80;
|
|
37945
38337
|
const height = bottom - top + 80;
|
|
37946
|
-
if (width > 16384 || height > 16384)
|
|
37947
|
-
|
|
37948
|
-
width,
|
|
37949
|
-
|
|
37950
|
-
|
|
37951
|
-
|
|
38338
|
+
if (width * scale > 16384 || height * scale > 16384) {
|
|
38339
|
+
const at = scale === 1 ? "" : ` at ${scale}x`;
|
|
38340
|
+
throw new FrameboardError("capture-too-large", `A composite of ${page.ref}${at} would be ${width * scale} by ${height * scale} px, past the ${MAX_COMPOSITE_SIDE} px a browser screenshot holds. Capture its frames one by one instead.`, {
|
|
38341
|
+
ref: page.ref,
|
|
38342
|
+
width,
|
|
38343
|
+
height,
|
|
38344
|
+
scale,
|
|
38345
|
+
max: MAX_COMPOSITE_SIDE
|
|
38346
|
+
});
|
|
38347
|
+
}
|
|
37952
38348
|
return {
|
|
37953
38349
|
width,
|
|
37954
38350
|
height,
|
|
@@ -37957,19 +38353,20 @@ function compositeBounds(page, frames) {
|
|
|
37957
38353
|
};
|
|
37958
38354
|
}
|
|
37959
38355
|
/**
|
|
37960
|
-
* Captures each frame in each theme at its layout size
|
|
38356
|
+
* Captures each frame in each theme at its layout size times `scale`, one PNG apiece. Every
|
|
37961
38357
|
* image renders before any is written, so a refusal on one frame leaves no
|
|
37962
38358
|
* half-written set an agent could read as current.
|
|
37963
38359
|
*/
|
|
37964
|
-
async function captureFrameImages(browser, { baseUrl, frames, themes, out }) {
|
|
38360
|
+
async function captureFrameImages(browser, { baseUrl, frames, themes, out, scale = 1 }) {
|
|
37965
38361
|
const rendered = [];
|
|
37966
38362
|
for (const frame of frames) for (const theme of themes) rendered.push({
|
|
37967
38363
|
ref: frame.ref,
|
|
37968
38364
|
theme,
|
|
37969
|
-
path: frameImagePath(out, frame, theme),
|
|
38365
|
+
path: frameImagePath(out, frame, theme, scale),
|
|
37970
38366
|
width: frame.box.width,
|
|
37971
38367
|
height: frame.box.height,
|
|
37972
|
-
|
|
38368
|
+
scale,
|
|
38369
|
+
bytes: await renderFrame(browser, baseUrl, frame, theme, scale)
|
|
37973
38370
|
});
|
|
37974
38371
|
return writeImages(rendered);
|
|
37975
38372
|
}
|
|
@@ -37978,35 +38375,39 @@ async function captureFrameImages(browser, { baseUrl, frames, themes, out }) {
|
|
|
37978
38375
|
* the theme's canvas color. Each frame renders as it does alone, font check
|
|
37979
38376
|
* included, and the composite is written only once every theme rendered.
|
|
37980
38377
|
*/
|
|
37981
|
-
async function captureComposite(browser, { baseUrl, page, frames, themes, out }) {
|
|
37982
|
-
const bounds = compositeBounds(page, frames);
|
|
38378
|
+
async function captureComposite(browser, { baseUrl, page, frames, themes, out, scale = 1 }) {
|
|
38379
|
+
const bounds = compositeBounds(page, frames, scale);
|
|
37983
38380
|
const rendered = [];
|
|
37984
38381
|
for (const theme of themes) {
|
|
37985
38382
|
const tiles = [];
|
|
37986
38383
|
for (const frame of frames) {
|
|
37987
|
-
const bytes = await renderFrame(browser, baseUrl, frame, theme);
|
|
38384
|
+
const bytes = await renderFrame(browser, baseUrl, frame, theme, scale);
|
|
37988
38385
|
tiles.push(`<img src="data:image/png;base64,${bytes.toString("base64")}" style="position:absolute;left:${frame.box.x + bounds.dx}px;top:${frame.box.y + bounds.dy}px;width:${frame.box.width}px;height:${frame.box.height}px">`);
|
|
37989
38386
|
}
|
|
37990
38387
|
rendered.push({
|
|
37991
38388
|
ref: page.ref,
|
|
37992
38389
|
theme,
|
|
37993
|
-
path: compositeImagePath(out, page, theme),
|
|
38390
|
+
path: compositeImagePath(out, page, theme, scale),
|
|
37994
38391
|
width: bounds.width,
|
|
37995
38392
|
height: bounds.height,
|
|
37996
|
-
|
|
38393
|
+
scale,
|
|
38394
|
+
bytes: await renderComposite(browser, bounds, theme, tiles, scale)
|
|
37997
38395
|
});
|
|
37998
38396
|
}
|
|
37999
38397
|
return writeImages(rendered);
|
|
38000
38398
|
}
|
|
38001
|
-
async function renderFrame(browser, baseUrl, frame, theme) {
|
|
38399
|
+
async function renderFrame(browser, baseUrl, frame, theme, scale) {
|
|
38400
|
+
const box = {
|
|
38401
|
+
width: frame.box.width,
|
|
38402
|
+
height: frame.box.height
|
|
38403
|
+
};
|
|
38404
|
+
assertScreenshotFits(frame.ref, box, scale);
|
|
38002
38405
|
const opened = await openFrame(browser, {
|
|
38003
38406
|
baseUrl,
|
|
38004
38407
|
ref: frame.ref,
|
|
38005
|
-
box
|
|
38006
|
-
|
|
38007
|
-
|
|
38008
|
-
},
|
|
38009
|
-
theme
|
|
38408
|
+
box,
|
|
38409
|
+
theme,
|
|
38410
|
+
scale
|
|
38010
38411
|
});
|
|
38011
38412
|
try {
|
|
38012
38413
|
return await opened.page.screenshot(SCREENSHOT);
|
|
@@ -38014,12 +38415,13 @@ async function renderFrame(browser, baseUrl, frame, theme) {
|
|
|
38014
38415
|
await opened.close();
|
|
38015
38416
|
}
|
|
38016
38417
|
}
|
|
38017
|
-
async function renderComposite(browser, { width, height }, theme, tiles) {
|
|
38418
|
+
async function renderComposite(browser, { width, height }, theme, tiles, scale) {
|
|
38018
38419
|
const context = await browser.newContext({
|
|
38019
38420
|
viewport: {
|
|
38020
38421
|
width,
|
|
38021
38422
|
height
|
|
38022
38423
|
},
|
|
38424
|
+
deviceScaleFactor: scale,
|
|
38023
38425
|
colorScheme: theme
|
|
38024
38426
|
});
|
|
38025
38427
|
try {
|
|
@@ -38045,7 +38447,7 @@ function registerCapture(program, context) {
|
|
|
38045
38447
|
"light",
|
|
38046
38448
|
"dark",
|
|
38047
38449
|
"both"
|
|
38048
|
-
]).default("both")).option("--out <dir>", "the folder images land in, defaulting to the board's .run/captures/"), context, async ([ref], options) => {
|
|
38450
|
+
]).default("both")).addOption(new Option("--scale <n>", "device pixels per CSS pixel, adding @<n>x to the file name past 1").default(1).argParser(parseScale)).option("--out <dir>", "the folder images land in, defaulting to the board's .run/captures/"), context, async ([ref], options) => {
|
|
38049
38451
|
if (ref === void 0 === (options.page === void 0)) throw new FrameboardError("usage", "Pass a frame ref or --page <page-ref>, exactly one of the two.");
|
|
38050
38452
|
if (options.composite && options.page === void 0) throw new FrameboardError("usage", "--composite needs --page.");
|
|
38051
38453
|
const root = await boardOf(options, io);
|
|
@@ -38075,12 +38477,14 @@ function registerCapture(program, context) {
|
|
|
38075
38477
|
},
|
|
38076
38478
|
frames,
|
|
38077
38479
|
themes,
|
|
38078
|
-
out
|
|
38480
|
+
out,
|
|
38481
|
+
scale: options.scale
|
|
38079
38482
|
}) : captureFrameImages(browser, {
|
|
38080
38483
|
baseUrl,
|
|
38081
38484
|
frames,
|
|
38082
38485
|
themes,
|
|
38083
|
-
out
|
|
38486
|
+
out,
|
|
38487
|
+
scale: options.scale
|
|
38084
38488
|
}));
|
|
38085
38489
|
return {
|
|
38086
38490
|
data: { images },
|
|
@@ -38096,7 +38500,8 @@ function registerCapture(program, context) {
|
|
|
38096
38500
|
baseUrl,
|
|
38097
38501
|
frames: [frame],
|
|
38098
38502
|
themes,
|
|
38099
|
-
out
|
|
38503
|
+
out,
|
|
38504
|
+
scale: options.scale
|
|
38100
38505
|
}));
|
|
38101
38506
|
return {
|
|
38102
38507
|
data: { images },
|
|
@@ -38104,6 +38509,10 @@ function registerCapture(program, context) {
|
|
|
38104
38509
|
};
|
|
38105
38510
|
});
|
|
38106
38511
|
}
|
|
38512
|
+
function parseScale(value) {
|
|
38513
|
+
if (value !== "1" && value !== "2" && value !== "3") throw new InvalidArgumentError("Expected 1, 2, or 3.");
|
|
38514
|
+
return Number(value);
|
|
38515
|
+
}
|
|
38107
38516
|
async function pageOf(root, ref, options) {
|
|
38108
38517
|
const resolved = await resolvePageRef(root, ref, options);
|
|
38109
38518
|
const { pages } = await readPageOrder(join(root, resolved.project));
|
|
@@ -39470,6 +39879,18 @@ const frameRecordSchema = object$1({
|
|
|
39470
39879
|
placed: boolean$1(),
|
|
39471
39880
|
modifiedAt: string$1()
|
|
39472
39881
|
});
|
|
39882
|
+
const sectionRecordSchema = object$1({
|
|
39883
|
+
name: string$1(),
|
|
39884
|
+
box: object$1({
|
|
39885
|
+
x: number(),
|
|
39886
|
+
y: number(),
|
|
39887
|
+
width: number(),
|
|
39888
|
+
height: number()
|
|
39889
|
+
}),
|
|
39890
|
+
order: number(),
|
|
39891
|
+
/** The frames whose center the section holds, bottom of the stack first. */
|
|
39892
|
+
frames: array$1(string$1())
|
|
39893
|
+
});
|
|
39473
39894
|
const pageRecordSchema = object$1({
|
|
39474
39895
|
ref: string$1(),
|
|
39475
39896
|
project: string$1(),
|
|
@@ -39477,7 +39898,9 @@ const pageRecordSchema = object$1({
|
|
|
39477
39898
|
path: string$1(),
|
|
39478
39899
|
index: number(),
|
|
39479
39900
|
layoutError: recordErrorSchema,
|
|
39480
|
-
frames: array$1(frameRecordSchema)
|
|
39901
|
+
frames: array$1(frameRecordSchema),
|
|
39902
|
+
/** Bottom first, as frames are. */
|
|
39903
|
+
sections: array$1(sectionRecordSchema)
|
|
39481
39904
|
});
|
|
39482
39905
|
const projectRecordSchema = object$1({
|
|
39483
39906
|
name: string$1(),
|
|
@@ -39499,8 +39922,11 @@ const captureResultSchema = object$1({ images: array$1(object$1({
|
|
|
39499
39922
|
ref: string$1(),
|
|
39500
39923
|
theme: themeSchema$1,
|
|
39501
39924
|
path: string$1(),
|
|
39925
|
+
/** The layout box in CSS pixels, whatever the scale. */
|
|
39502
39926
|
width: int$1().min(1),
|
|
39503
|
-
height: int$1().min(1)
|
|
39927
|
+
height: int$1().min(1),
|
|
39928
|
+
/** Device pixels per CSS pixel, so the file is `width * scale` wide. */
|
|
39929
|
+
scale: int$1().min(1).max(3)
|
|
39504
39930
|
})) });
|
|
39505
39931
|
/** What `frame fit` returns: the frame as resized, the height it measured, and its width against the layout's. */
|
|
39506
39932
|
const fitResultSchema = object$1({
|
|
@@ -39911,7 +40337,8 @@ function contentFormat() {
|
|
|
39911
40337
|
`A frame file with no entry is unplaced: it reads at desktop size, y 0, 80 px past the right edge of every frame placed before it in name order. frame add places it 80 px past the placed frames alone, so the first unplaced file keeps that box and any later one moves left.`,
|
|
39912
40338
|
"An entry with no frame file beside it is ignored on read and kept on write.",
|
|
39913
40339
|
`A ${LAYOUT_FILE} that does not parse is reported by list and refused by every verb writing that page, never overwritten.`,
|
|
39914
|
-
`Moving or resizing a frame writes ${LAYOUT_FILE} alone and never the frame file
|
|
40340
|
+
`Moving or resizing a frame writes ${LAYOUT_FILE} alone and never the frame file.`,
|
|
40341
|
+
"sections, when present, maps a section name to its x, y, width, height, and order. A frame belongs to the topmost section holding its center, left and top edges inside, and is never listed in it, so list --json names each section's frames and an agent moving a frame out of the box takes it out of the section. The developer writes sections by hand on the board."
|
|
39915
40342
|
],
|
|
39916
40343
|
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}/.`,
|
|
39917
40344
|
look: [
|
|
@@ -44807,7 +45234,7 @@ async function emptyTrash(root) {
|
|
|
44807
45234
|
// src/server/history/changes.ts
|
|
44808
45235
|
/** The records a change writes, whose locks are held while it is checked and written. */
|
|
44809
45236
|
function lockPaths(change) {
|
|
44810
|
-
if (change.kind === "entry") return [change.layout];
|
|
45237
|
+
if (change.kind === "entry" || change.kind === "section") return [change.layout];
|
|
44811
45238
|
if (change.kind === "pages") return [change.file];
|
|
44812
45239
|
return [];
|
|
44813
45240
|
}
|
|
@@ -44832,6 +45259,10 @@ async function reads(change, side) {
|
|
|
44832
45259
|
const stored = (await readRecord(change.layout, layoutSpec)).frames[change.frame];
|
|
44833
45260
|
return isDeepStrictEqual(stored, withMeasured(change[side], stored));
|
|
44834
45261
|
}
|
|
45262
|
+
case "section": {
|
|
45263
|
+
const file = await readRecord(change.layout, layoutSpec);
|
|
45264
|
+
return isDeepStrictEqual(file.sections?.[change.section], change[side]);
|
|
45265
|
+
}
|
|
44835
45266
|
case "pages": {
|
|
44836
45267
|
const file = await readRecord(change.file, {
|
|
44837
45268
|
...projectSpec,
|
|
@@ -44886,6 +45317,18 @@ async function restore(change, side) {
|
|
|
44886
45317
|
});
|
|
44887
45318
|
return;
|
|
44888
45319
|
}
|
|
45320
|
+
case "section": {
|
|
45321
|
+
const file = await readRecord(change.layout, layoutSpec);
|
|
45322
|
+
const sections = { ...file.sections };
|
|
45323
|
+
const entry = change[side];
|
|
45324
|
+
if (entry) sections[change.section] = entry;
|
|
45325
|
+
else delete sections[change.section];
|
|
45326
|
+
await writeRecord(change.layout, {
|
|
45327
|
+
...file,
|
|
45328
|
+
sections
|
|
45329
|
+
});
|
|
45330
|
+
return;
|
|
45331
|
+
}
|
|
44889
45332
|
case "pages": {
|
|
44890
45333
|
const file = await readRecord(change.file, {
|
|
44891
45334
|
...projectSpec,
|
|
@@ -44989,6 +45432,16 @@ var StepJournal = class {
|
|
|
44989
45432
|
after
|
|
44990
45433
|
});
|
|
44991
45434
|
}
|
|
45435
|
+
section(page, section, before, after) {
|
|
45436
|
+
const layout = join(page, LAYOUT_FILE);
|
|
45437
|
+
this.changes.push({
|
|
45438
|
+
kind: "section",
|
|
45439
|
+
layout,
|
|
45440
|
+
section,
|
|
45441
|
+
before,
|
|
45442
|
+
after
|
|
45443
|
+
});
|
|
45444
|
+
}
|
|
44992
45445
|
pages(project, before, after) {
|
|
44993
45446
|
const file = join(project, PROJECT_FILE);
|
|
44994
45447
|
this.changes.push({
|
|
@@ -45221,9 +45674,10 @@ var History = class {
|
|
|
45221
45674
|
return run;
|
|
45222
45675
|
}
|
|
45223
45676
|
};
|
|
45224
|
-
/** What a refusal names as overtaken, being a frame, a page, or the page order. */
|
|
45677
|
+
/** What a refusal names as overtaken, being a frame, a section, a page, or the page order. */
|
|
45225
45678
|
function nameOf(change) {
|
|
45226
45679
|
if (change.kind === "entry") return change.frame;
|
|
45680
|
+
if (change.kind === "section") return `section ${change.section}`;
|
|
45227
45681
|
if (change.kind === "pages") return "the page order";
|
|
45228
45682
|
const path = change.kind === "moved" ? change.to : change.path;
|
|
45229
45683
|
return basename(path, FRAME_EXTENSION);
|