frameboard 0.18.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 +557 -72
- 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/dist/hook.js +9 -4
- package/package.json +2 -2
- package/dist/client/assets/index-B6qJtt6n.css +0 -2
- package/dist/client/assets/index-CO9c0yBA.js +0 -110
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: {
|
|
@@ -34935,7 +35167,7 @@ function buildCascade(source, tokens, { properties = READ } = {}) {
|
|
|
34935
35167
|
}
|
|
34936
35168
|
return null;
|
|
34937
35169
|
};
|
|
34938
|
-
const resolveVars = (value, element, depth = 0) => {
|
|
35170
|
+
const resolveVars = (value, element, keep = /* @__PURE__ */ new Set(), depth = 0) => {
|
|
34939
35171
|
if (depth > 16) return null;
|
|
34940
35172
|
let resolved = "";
|
|
34941
35173
|
let rest = value;
|
|
@@ -34944,8 +35176,12 @@ function buildCascade(source, tokens, { properties = READ } = {}) {
|
|
|
34944
35176
|
if (end === -1) return null;
|
|
34945
35177
|
const [name = "", ...fallbackParts] = splitTopLevel(rest.slice(start + 4, end), ",");
|
|
34946
35178
|
const fallback = fallbackParts.length > 0 ? fallbackParts.join(",") : null;
|
|
34947
|
-
|
|
34948
|
-
|
|
35179
|
+
let replacement;
|
|
35180
|
+
if (keep.has(name.trim())) replacement = rest.slice(start, end + 1);
|
|
35181
|
+
else {
|
|
35182
|
+
const custom = inherited(element, name.trim());
|
|
35183
|
+
replacement = custom === null ? fallback === null ? null : resolveVars(fallback, element, keep, depth + 1) : resolveVars(custom.value.trim(), custom.element, keep, depth + 1);
|
|
35184
|
+
}
|
|
34949
35185
|
if (replacement === null) return null;
|
|
34950
35186
|
resolved += rest.slice(0, start) + replacement;
|
|
34951
35187
|
rest = rest.slice(end + 1);
|
|
@@ -34982,7 +35218,8 @@ function buildCascade(source, tokens, { properties = READ } = {}) {
|
|
|
34982
35218
|
userAgent: false,
|
|
34983
35219
|
shorthand: declaration.property !== property
|
|
34984
35220
|
};
|
|
34985
|
-
}
|
|
35221
|
+
},
|
|
35222
|
+
resolve: (value, element, keep) => resolveVars(value, element, keep)
|
|
34986
35223
|
};
|
|
34987
35224
|
}
|
|
34988
35225
|
/** A rule styles elements unless it sits in a non-styling at-rule or inside another rule. */
|
|
@@ -35288,19 +35525,33 @@ const MIX = /^color-mix\(\s*in\s+srgb\s*,\s*var\(\s*(--[\w-]+)\s*(?:,[^)]*)?\)\s
|
|
|
35288
35525
|
const HEX_ALPHA = /^#([0-9a-f]{6})([0-9a-f]{2})$/i;
|
|
35289
35526
|
/**
|
|
35290
35527
|
* A frame's colors as its source states them, read through the static
|
|
35291
|
-
* cascade the checks use, so `var(
|
|
35528
|
+
* cascade the checks use, so a `var()` over a name a token sheet declares
|
|
35529
|
+
* is named exactly, one over a name only the frame declares answers the
|
|
35530
|
+
* value it resolves to, and a raw
|
|
35292
35531
|
* value is answered raw rather than matched to a token that happens to
|
|
35293
35532
|
* share its value. `index` is the edit address's, naming the selected
|
|
35294
35533
|
* element, whose subtree the colors then cover in place of the frame's.
|
|
35295
35534
|
*/
|
|
35296
35535
|
function frameStyles(source, tokens, index) {
|
|
35297
35536
|
const cascade = buildCascade(source, tokens, { properties: PROPERTIES });
|
|
35537
|
+
const tokenNames = declaredNames(tokens);
|
|
35298
35538
|
const target = index === void 0 ? void 0 : source.elements[index];
|
|
35539
|
+
const named = (written, element) => {
|
|
35540
|
+
const value = styleValue(written);
|
|
35541
|
+
if (!value.token || tokenNames.has(value.token)) return value;
|
|
35542
|
+
const resolved = cascade.resolve(`var(${value.token})`, element, tokenNames);
|
|
35543
|
+
if (resolved === null) return value;
|
|
35544
|
+
const raw = styleValue(resolved);
|
|
35545
|
+
return {
|
|
35546
|
+
...raw,
|
|
35547
|
+
percent: Math.round(raw.percent * value.percent / 100)
|
|
35548
|
+
};
|
|
35549
|
+
};
|
|
35299
35550
|
const read = (element, property) => {
|
|
35300
35551
|
const found = cascade.specified(element, property);
|
|
35301
35552
|
if (!found) return null;
|
|
35302
35553
|
const part = found.shorthand ? shorthandPart(found.value, property) : found.value;
|
|
35303
|
-
return part === null ? null :
|
|
35554
|
+
return part === null ? null : named(part, found.element);
|
|
35304
35555
|
};
|
|
35305
35556
|
const family = (element) => {
|
|
35306
35557
|
const found = cascade.specified(element, "font-family");
|
|
@@ -35356,6 +35607,18 @@ function styleValue(written) {
|
|
|
35356
35607
|
percent: 100
|
|
35357
35608
|
};
|
|
35358
35609
|
}
|
|
35610
|
+
/** The custom properties the token sheets declare, which alone are tokens. */
|
|
35611
|
+
function declaredNames(sheets) {
|
|
35612
|
+
const names = /* @__PURE__ */ new Set();
|
|
35613
|
+
for (const sheet of sheets) try {
|
|
35614
|
+
postcss_default.parse(sheet.css).walkDecls(/^--/, (node) => {
|
|
35615
|
+
names.add(node.prop);
|
|
35616
|
+
});
|
|
35617
|
+
} catch {
|
|
35618
|
+
continue;
|
|
35619
|
+
}
|
|
35620
|
+
return names;
|
|
35621
|
+
}
|
|
35359
35622
|
/**
|
|
35360
35623
|
* The part of a `border` or `background` shorthand that sets `property`:
|
|
35361
35624
|
* the last part that reads as a color for a color, since a color comes last
|
|
@@ -36675,11 +36938,15 @@ const STATUS = {
|
|
|
36675
36938
|
"page-not-found": 404,
|
|
36676
36939
|
"frame-not-found": 404,
|
|
36677
36940
|
"font-missing": 422,
|
|
36941
|
+
"capture-too-large": 422,
|
|
36678
36942
|
"browser-not-found": 503
|
|
36679
36943
|
};
|
|
36944
|
+
/** The route's scale when none is asked for, matching Copy as PNG. */
|
|
36945
|
+
const DEFAULT_SCALE = 2;
|
|
36680
36946
|
/**
|
|
36681
|
-
* `GET /api/frames/png?ref=<frame-ref>&theme=<light|dark>`, a
|
|
36682
|
-
* 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
|
|
36683
36950
|
* what the frame route already serves, and a refusal answers the CLI's
|
|
36684
36951
|
* `{ ok, error }` envelope.
|
|
36685
36952
|
*/
|
|
@@ -36689,11 +36956,13 @@ function pngRoutes(root, render) {
|
|
|
36689
36956
|
try {
|
|
36690
36957
|
const ref = c.req.query("ref") ?? "";
|
|
36691
36958
|
const theme = c.req.query("theme") ?? "";
|
|
36692
|
-
|
|
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>.", {
|
|
36693
36961
|
ref,
|
|
36694
|
-
theme
|
|
36962
|
+
theme,
|
|
36963
|
+
scale: c.req.query("scale") ?? null
|
|
36695
36964
|
});
|
|
36696
|
-
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);
|
|
36697
36966
|
return c.body(new Uint8Array(bytes), 200, {
|
|
36698
36967
|
"Content-Type": "image/png",
|
|
36699
36968
|
"Cache-Control": "no-store"
|
|
@@ -36715,6 +36984,11 @@ function pngRoutes(root, render) {
|
|
|
36715
36984
|
function isTheme(value) {
|
|
36716
36985
|
return value === "light" || value === "dark";
|
|
36717
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
|
+
}
|
|
36718
36992
|
// src/server/board/pages.ts
|
|
36719
36993
|
/** Notes and their images belong to the page they were pinned on, so a copy starts without them. */
|
|
36720
36994
|
const NOT_COPIED = /* @__PURE__ */ new Set(["notes.json", ".notes"]);
|
|
@@ -36912,7 +37186,7 @@ async function pasteFrames(root, pageRef, held, options) {
|
|
|
36912
37186
|
/** A new project holding one empty page. */
|
|
36913
37187
|
async function addProject(root, name, now = /* @__PURE__ */ new Date(), { journal } = {}) {
|
|
36914
37188
|
assertValidName("project", name);
|
|
36915
|
-
await assertFree(root, name);
|
|
37189
|
+
await assertFree$1(root, name);
|
|
36916
37190
|
await mkdir(join(root, name, START_PAGE), { recursive: true });
|
|
36917
37191
|
await writeRecord(join(root, name, PROJECT_FILE), {
|
|
36918
37192
|
version: 1,
|
|
@@ -36925,7 +37199,7 @@ async function addProject(root, name, now = /* @__PURE__ */ new Date(), { journa
|
|
|
36925
37199
|
async function renameProject(root, name, newName, { journal } = {}) {
|
|
36926
37200
|
const project = await resolveProject(root, name);
|
|
36927
37201
|
assertValidName("project", newName);
|
|
36928
|
-
await assertFree(root, newName, project.name);
|
|
37202
|
+
await assertFree$1(root, newName, project.name);
|
|
36929
37203
|
const renamed = join(root, newName);
|
|
36930
37204
|
if (journal) await journal.moved(project.path, renamed);
|
|
36931
37205
|
else await rename(project.path, renamed);
|
|
@@ -36966,13 +37240,82 @@ async function deleteProject(root, name, { journal } = {}) {
|
|
|
36966
37240
|
return { deleted: project.name };
|
|
36967
37241
|
}
|
|
36968
37242
|
/** Throws `name-taken` when another project holds `name` in any case. */
|
|
36969
|
-
async function assertFree(root, name, self) {
|
|
37243
|
+
async function assertFree$1(root, name, self) {
|
|
36970
37244
|
const taken = matchName((await listProjects(root)).filter((project) => project !== self), name);
|
|
36971
37245
|
if (taken) throw new FrameboardError("name-taken", `The board already has a project ${taken}.`, {
|
|
36972
37246
|
name,
|
|
36973
37247
|
taken
|
|
36974
37248
|
});
|
|
36975
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
|
+
}
|
|
36976
37319
|
// src/server/look/starter.ts
|
|
36977
37320
|
/**
|
|
36978
37321
|
* Writes a starter `tokens.css` into a project that renders with no token
|
|
@@ -37058,6 +37401,26 @@ const frameFlagSchema = object$1({
|
|
|
37058
37401
|
flag: _enum$1(["hidden", "locked"]),
|
|
37059
37402
|
on: boolean$1()
|
|
37060
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
|
+
});
|
|
37061
37424
|
const projectAddSchema = object$1({ name: name.optional() });
|
|
37062
37425
|
const projectSchema = object$1({ ref });
|
|
37063
37426
|
const projectTokensSchema = object$1({
|
|
@@ -37081,6 +37444,7 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
37081
37444
|
app.use("/api/frame/*", requireWriter(access));
|
|
37082
37445
|
app.use("/api/clipboard/*", requireWriter(access));
|
|
37083
37446
|
app.use("/api/project/*", requireWriter(access));
|
|
37447
|
+
app.use("/api/section/*", requireWriter(access));
|
|
37084
37448
|
const cwd = root;
|
|
37085
37449
|
/** Runs one verb with a fresh journal and records what it reported. */
|
|
37086
37450
|
const recorded = async (write, describe) => {
|
|
@@ -37372,6 +37736,41 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
37372
37736
|
data: frames
|
|
37373
37737
|
});
|
|
37374
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
|
+
});
|
|
37375
37774
|
/** A project write leaves the board on home, so it follows no page or frame. */
|
|
37376
37775
|
const onHome = async () => ({
|
|
37377
37776
|
page: null,
|
|
@@ -37801,6 +38200,8 @@ async function platformFamilies(page, domIndexes) {
|
|
|
37801
38200
|
// src/server/capture/render.ts
|
|
37802
38201
|
/** How long a frame has to load before its capture fails. */
|
|
37803
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;
|
|
37804
38205
|
/**
|
|
37805
38206
|
* Loads a frame in its own browser context at its layout size, in the theme
|
|
37806
38207
|
* asked for, and resolves once it has loaded and its faces have settled.
|
|
@@ -37832,6 +38233,22 @@ async function openFrame(browser, { baseUrl, ref, box, theme, scale = 1, fonts =
|
|
|
37832
38233
|
}
|
|
37833
38234
|
}
|
|
37834
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
|
+
/**
|
|
37835
38252
|
* One browser kept warm for a server and shared by everything rendering on
|
|
37836
38253
|
* it, so the server holds one Chromium. A launch that fails is not kept, so a
|
|
37837
38254
|
* browser installed later is found on the next call, and every call after
|
|
@@ -37862,10 +38279,11 @@ function createWarmBrowser(launch) {
|
|
|
37862
38279
|
* queue is the renderer's own, so a PNG never waits behind another consumer
|
|
37863
38280
|
* of the browser, such as a thumbnail.
|
|
37864
38281
|
*/
|
|
37865
|
-
function createWarmRenderer({ baseUrl, browser, scale }) {
|
|
38282
|
+
function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
|
|
37866
38283
|
let queue = Promise.resolve();
|
|
37867
|
-
return (frame, theme) => {
|
|
38284
|
+
return (frame, theme, scale = defaultScale) => {
|
|
37868
38285
|
const run = queue.then(async () => {
|
|
38286
|
+
assertScreenshotFits(frame.ref, frame.box, scale);
|
|
37869
38287
|
const opened = await openFrame(await browser.get(), {
|
|
37870
38288
|
baseUrl: baseUrl(),
|
|
37871
38289
|
ref: frame.ref,
|
|
@@ -37886,38 +38304,47 @@ function createWarmRenderer({ baseUrl, browser, scale }) {
|
|
|
37886
38304
|
return run;
|
|
37887
38305
|
};
|
|
37888
38306
|
}
|
|
37889
|
-
/** Chromium's screenshot surface stops at this many pixels on either side. */
|
|
37890
|
-
const MAX_COMPOSITE_SIDE = 16384;
|
|
37891
38307
|
const SCREENSHOT = {
|
|
37892
38308
|
animations: "disabled",
|
|
37893
38309
|
caret: "hide"
|
|
37894
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
|
+
}
|
|
37895
38318
|
/** Where one frame's capture in one theme lands under `out`. */
|
|
37896
|
-
function frameImagePath(out, frame, theme) {
|
|
37897
|
-
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));
|
|
37898
38321
|
}
|
|
37899
38322
|
/** Where a page's composite in one theme lands under `out`. */
|
|
37900
|
-
function compositeImagePath(out, page, theme) {
|
|
37901
|
-
return join(out, page.project,
|
|
38323
|
+
function compositeImagePath(out, page, theme, scale = 1) {
|
|
38324
|
+
return join(out, page.project, imageName(page.name, theme, scale));
|
|
37902
38325
|
}
|
|
37903
38326
|
/**
|
|
37904
38327
|
* The composite's size and the shift placing each frame in it, so the
|
|
37905
38328
|
* leftmost and topmost frames sit one margin in and one margin is left past
|
|
37906
38329
|
* the far edges. Refuses `capture-too-large` past Chromium's screenshot limit.
|
|
37907
38330
|
*/
|
|
37908
|
-
function compositeBounds(page, frames) {
|
|
38331
|
+
function compositeBounds(page, frames, scale = 1) {
|
|
37909
38332
|
const left = Math.min(...frames.map(({ box }) => box.x));
|
|
37910
38333
|
const top = Math.min(...frames.map(({ box }) => box.y));
|
|
37911
38334
|
const right = Math.max(...frames.map(({ box }) => box.x + box.width));
|
|
37912
38335
|
const bottom = Math.max(...frames.map(({ box }) => box.y + box.height));
|
|
37913
38336
|
const width = right - left + 80;
|
|
37914
38337
|
const height = bottom - top + 80;
|
|
37915
|
-
if (width > 16384 || height > 16384)
|
|
37916
|
-
|
|
37917
|
-
width,
|
|
37918
|
-
|
|
37919
|
-
|
|
37920
|
-
|
|
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
|
+
}
|
|
37921
38348
|
return {
|
|
37922
38349
|
width,
|
|
37923
38350
|
height,
|
|
@@ -37926,19 +38353,20 @@ function compositeBounds(page, frames) {
|
|
|
37926
38353
|
};
|
|
37927
38354
|
}
|
|
37928
38355
|
/**
|
|
37929
|
-
* 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
|
|
37930
38357
|
* image renders before any is written, so a refusal on one frame leaves no
|
|
37931
38358
|
* half-written set an agent could read as current.
|
|
37932
38359
|
*/
|
|
37933
|
-
async function captureFrameImages(browser, { baseUrl, frames, themes, out }) {
|
|
38360
|
+
async function captureFrameImages(browser, { baseUrl, frames, themes, out, scale = 1 }) {
|
|
37934
38361
|
const rendered = [];
|
|
37935
38362
|
for (const frame of frames) for (const theme of themes) rendered.push({
|
|
37936
38363
|
ref: frame.ref,
|
|
37937
38364
|
theme,
|
|
37938
|
-
path: frameImagePath(out, frame, theme),
|
|
38365
|
+
path: frameImagePath(out, frame, theme, scale),
|
|
37939
38366
|
width: frame.box.width,
|
|
37940
38367
|
height: frame.box.height,
|
|
37941
|
-
|
|
38368
|
+
scale,
|
|
38369
|
+
bytes: await renderFrame(browser, baseUrl, frame, theme, scale)
|
|
37942
38370
|
});
|
|
37943
38371
|
return writeImages(rendered);
|
|
37944
38372
|
}
|
|
@@ -37947,35 +38375,39 @@ async function captureFrameImages(browser, { baseUrl, frames, themes, out }) {
|
|
|
37947
38375
|
* the theme's canvas color. Each frame renders as it does alone, font check
|
|
37948
38376
|
* included, and the composite is written only once every theme rendered.
|
|
37949
38377
|
*/
|
|
37950
|
-
async function captureComposite(browser, { baseUrl, page, frames, themes, out }) {
|
|
37951
|
-
const bounds = compositeBounds(page, frames);
|
|
38378
|
+
async function captureComposite(browser, { baseUrl, page, frames, themes, out, scale = 1 }) {
|
|
38379
|
+
const bounds = compositeBounds(page, frames, scale);
|
|
37952
38380
|
const rendered = [];
|
|
37953
38381
|
for (const theme of themes) {
|
|
37954
38382
|
const tiles = [];
|
|
37955
38383
|
for (const frame of frames) {
|
|
37956
|
-
const bytes = await renderFrame(browser, baseUrl, frame, theme);
|
|
38384
|
+
const bytes = await renderFrame(browser, baseUrl, frame, theme, scale);
|
|
37957
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">`);
|
|
37958
38386
|
}
|
|
37959
38387
|
rendered.push({
|
|
37960
38388
|
ref: page.ref,
|
|
37961
38389
|
theme,
|
|
37962
|
-
path: compositeImagePath(out, page, theme),
|
|
38390
|
+
path: compositeImagePath(out, page, theme, scale),
|
|
37963
38391
|
width: bounds.width,
|
|
37964
38392
|
height: bounds.height,
|
|
37965
|
-
|
|
38393
|
+
scale,
|
|
38394
|
+
bytes: await renderComposite(browser, bounds, theme, tiles, scale)
|
|
37966
38395
|
});
|
|
37967
38396
|
}
|
|
37968
38397
|
return writeImages(rendered);
|
|
37969
38398
|
}
|
|
37970
|
-
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);
|
|
37971
38405
|
const opened = await openFrame(browser, {
|
|
37972
38406
|
baseUrl,
|
|
37973
38407
|
ref: frame.ref,
|
|
37974
|
-
box
|
|
37975
|
-
|
|
37976
|
-
|
|
37977
|
-
},
|
|
37978
|
-
theme
|
|
38408
|
+
box,
|
|
38409
|
+
theme,
|
|
38410
|
+
scale
|
|
37979
38411
|
});
|
|
37980
38412
|
try {
|
|
37981
38413
|
return await opened.page.screenshot(SCREENSHOT);
|
|
@@ -37983,12 +38415,13 @@ async function renderFrame(browser, baseUrl, frame, theme) {
|
|
|
37983
38415
|
await opened.close();
|
|
37984
38416
|
}
|
|
37985
38417
|
}
|
|
37986
|
-
async function renderComposite(browser, { width, height }, theme, tiles) {
|
|
38418
|
+
async function renderComposite(browser, { width, height }, theme, tiles, scale) {
|
|
37987
38419
|
const context = await browser.newContext({
|
|
37988
38420
|
viewport: {
|
|
37989
38421
|
width,
|
|
37990
38422
|
height
|
|
37991
38423
|
},
|
|
38424
|
+
deviceScaleFactor: scale,
|
|
37992
38425
|
colorScheme: theme
|
|
37993
38426
|
});
|
|
37994
38427
|
try {
|
|
@@ -38014,7 +38447,7 @@ function registerCapture(program, context) {
|
|
|
38014
38447
|
"light",
|
|
38015
38448
|
"dark",
|
|
38016
38449
|
"both"
|
|
38017
|
-
]).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) => {
|
|
38018
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.");
|
|
38019
38452
|
if (options.composite && options.page === void 0) throw new FrameboardError("usage", "--composite needs --page.");
|
|
38020
38453
|
const root = await boardOf(options, io);
|
|
@@ -38044,12 +38477,14 @@ function registerCapture(program, context) {
|
|
|
38044
38477
|
},
|
|
38045
38478
|
frames,
|
|
38046
38479
|
themes,
|
|
38047
|
-
out
|
|
38480
|
+
out,
|
|
38481
|
+
scale: options.scale
|
|
38048
38482
|
}) : captureFrameImages(browser, {
|
|
38049
38483
|
baseUrl,
|
|
38050
38484
|
frames,
|
|
38051
38485
|
themes,
|
|
38052
|
-
out
|
|
38486
|
+
out,
|
|
38487
|
+
scale: options.scale
|
|
38053
38488
|
}));
|
|
38054
38489
|
return {
|
|
38055
38490
|
data: { images },
|
|
@@ -38065,7 +38500,8 @@ function registerCapture(program, context) {
|
|
|
38065
38500
|
baseUrl,
|
|
38066
38501
|
frames: [frame],
|
|
38067
38502
|
themes,
|
|
38068
|
-
out
|
|
38503
|
+
out,
|
|
38504
|
+
scale: options.scale
|
|
38069
38505
|
}));
|
|
38070
38506
|
return {
|
|
38071
38507
|
data: { images },
|
|
@@ -38073,6 +38509,10 @@ function registerCapture(program, context) {
|
|
|
38073
38509
|
};
|
|
38074
38510
|
});
|
|
38075
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
|
+
}
|
|
38076
38516
|
async function pageOf(root, ref, options) {
|
|
38077
38517
|
const resolved = await resolvePageRef(root, ref, options);
|
|
38078
38518
|
const { pages } = await readPageOrder(join(root, resolved.project));
|
|
@@ -39439,6 +39879,18 @@ const frameRecordSchema = object$1({
|
|
|
39439
39879
|
placed: boolean$1(),
|
|
39440
39880
|
modifiedAt: string$1()
|
|
39441
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
|
+
});
|
|
39442
39894
|
const pageRecordSchema = object$1({
|
|
39443
39895
|
ref: string$1(),
|
|
39444
39896
|
project: string$1(),
|
|
@@ -39446,7 +39898,9 @@ const pageRecordSchema = object$1({
|
|
|
39446
39898
|
path: string$1(),
|
|
39447
39899
|
index: number(),
|
|
39448
39900
|
layoutError: recordErrorSchema,
|
|
39449
|
-
frames: array$1(frameRecordSchema)
|
|
39901
|
+
frames: array$1(frameRecordSchema),
|
|
39902
|
+
/** Bottom first, as frames are. */
|
|
39903
|
+
sections: array$1(sectionRecordSchema)
|
|
39450
39904
|
});
|
|
39451
39905
|
const projectRecordSchema = object$1({
|
|
39452
39906
|
name: string$1(),
|
|
@@ -39468,8 +39922,11 @@ const captureResultSchema = object$1({ images: array$1(object$1({
|
|
|
39468
39922
|
ref: string$1(),
|
|
39469
39923
|
theme: themeSchema$1,
|
|
39470
39924
|
path: string$1(),
|
|
39925
|
+
/** The layout box in CSS pixels, whatever the scale. */
|
|
39471
39926
|
width: int$1().min(1),
|
|
39472
|
-
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)
|
|
39473
39930
|
})) });
|
|
39474
39931
|
/** What `frame fit` returns: the frame as resized, the height it measured, and its width against the layout's. */
|
|
39475
39932
|
const fitResultSchema = object$1({
|
|
@@ -39880,7 +40337,8 @@ function contentFormat() {
|
|
|
39880
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.`,
|
|
39881
40338
|
"An entry with no frame file beside it is ignored on read and kept on write.",
|
|
39882
40339
|
`A ${LAYOUT_FILE} that does not parse is reported by list and refused by every verb writing that page, never overwritten.`,
|
|
39883
|
-
`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."
|
|
39884
40342
|
],
|
|
39885
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}/.`,
|
|
39886
40344
|
look: [
|
|
@@ -44776,7 +45234,7 @@ async function emptyTrash(root) {
|
|
|
44776
45234
|
// src/server/history/changes.ts
|
|
44777
45235
|
/** The records a change writes, whose locks are held while it is checked and written. */
|
|
44778
45236
|
function lockPaths(change) {
|
|
44779
|
-
if (change.kind === "entry") return [change.layout];
|
|
45237
|
+
if (change.kind === "entry" || change.kind === "section") return [change.layout];
|
|
44780
45238
|
if (change.kind === "pages") return [change.file];
|
|
44781
45239
|
return [];
|
|
44782
45240
|
}
|
|
@@ -44801,6 +45259,10 @@ async function reads(change, side) {
|
|
|
44801
45259
|
const stored = (await readRecord(change.layout, layoutSpec)).frames[change.frame];
|
|
44802
45260
|
return isDeepStrictEqual(stored, withMeasured(change[side], stored));
|
|
44803
45261
|
}
|
|
45262
|
+
case "section": {
|
|
45263
|
+
const file = await readRecord(change.layout, layoutSpec);
|
|
45264
|
+
return isDeepStrictEqual(file.sections?.[change.section], change[side]);
|
|
45265
|
+
}
|
|
44804
45266
|
case "pages": {
|
|
44805
45267
|
const file = await readRecord(change.file, {
|
|
44806
45268
|
...projectSpec,
|
|
@@ -44855,6 +45317,18 @@ async function restore(change, side) {
|
|
|
44855
45317
|
});
|
|
44856
45318
|
return;
|
|
44857
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
|
+
}
|
|
44858
45332
|
case "pages": {
|
|
44859
45333
|
const file = await readRecord(change.file, {
|
|
44860
45334
|
...projectSpec,
|
|
@@ -44958,6 +45432,16 @@ var StepJournal = class {
|
|
|
44958
45432
|
after
|
|
44959
45433
|
});
|
|
44960
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
|
+
}
|
|
44961
45445
|
pages(project, before, after) {
|
|
44962
45446
|
const file = join(project, PROJECT_FILE);
|
|
44963
45447
|
this.changes.push({
|
|
@@ -45190,9 +45674,10 @@ var History = class {
|
|
|
45190
45674
|
return run;
|
|
45191
45675
|
}
|
|
45192
45676
|
};
|
|
45193
|
-
/** 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. */
|
|
45194
45678
|
function nameOf(change) {
|
|
45195
45679
|
if (change.kind === "entry") return change.frame;
|
|
45680
|
+
if (change.kind === "section") return `section ${change.section}`;
|
|
45196
45681
|
if (change.kind === "pages") return "the page order";
|
|
45197
45682
|
const path = change.kind === "moved" ? change.to : change.path;
|
|
45198
45683
|
return basename(path, FRAME_EXTENSION);
|