frameboard 0.8.0 → 0.10.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/README.md +10 -6
- package/dist/cli.js +500 -107
- package/dist/client/assets/index-CrIbj1Es.css +2 -0
- package/dist/client/assets/index-DkaM313M.js +110 -0
- package/dist/client/index.html +2 -2
- package/package.json +3 -3
- package/dist/client/assets/index-C2o-JeD6.css +0 -2
- package/dist/client/assets/index-C6Purk3o.js +0 -111
package/dist/cli.js
CHANGED
|
@@ -7,10 +7,10 @@ import path, { basename, dirname, extname, isAbsolute, join, relative, resolve,
|
|
|
7
7
|
import fs, { copyFileSync, createReadStream, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, stat, statSync, unwatchFile, watch, watchFile, writeFileSync } from "node:fs";
|
|
8
8
|
import process$1, { versions } from "node:process";
|
|
9
9
|
import { isDeepStrictEqual, promisify, stripVTControlCharacters } from "node:util";
|
|
10
|
-
import { fileURLToPath } from "node:url";
|
|
11
10
|
import { constants, copyFile, cp, link, lstat, mkdir, open, readFile, readdir, realpath, rename, rm, stat as stat$1, writeFile } from "node:fs/promises";
|
|
12
11
|
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
13
12
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
14
|
import { STATUS_CODES, ServerResponse, createServer } from "node:http";
|
|
15
15
|
import { Http2ServerRequest, constants as constants$1 } from "node:http2";
|
|
16
16
|
import { Readable } from "node:stream";
|
|
@@ -3046,7 +3046,8 @@ const EXIT_CODES = {
|
|
|
3046
3046
|
"undo-overtaken": 12,
|
|
3047
3047
|
"nothing-to-undo": 12,
|
|
3048
3048
|
"frame-claimed": 4,
|
|
3049
|
-
"claims-invalid": 5
|
|
3049
|
+
"claims-invalid": 5,
|
|
3050
|
+
"client-not-built": 3
|
|
3050
3051
|
};
|
|
3051
3052
|
var FrameboardError = class extends Error {
|
|
3052
3053
|
code;
|
|
@@ -9075,7 +9076,9 @@ const layoutEntrySchema = looseObject({
|
|
|
9075
9076
|
height: int$1().min(1),
|
|
9076
9077
|
order: int$1().min(0),
|
|
9077
9078
|
hidden: boolean$1().optional(),
|
|
9078
|
-
locked: boolean$1().optional()
|
|
9079
|
+
locked: boolean$1().optional(),
|
|
9080
|
+
hugWidth: boolean$1().optional(),
|
|
9081
|
+
hugHeight: boolean$1().optional()
|
|
9079
9082
|
});
|
|
9080
9083
|
const layoutFileSchema = looseObject({
|
|
9081
9084
|
version: literal(1),
|
|
@@ -9177,6 +9180,8 @@ function placeFrames(frames, names) {
|
|
|
9177
9180
|
order: entry.order,
|
|
9178
9181
|
hidden: entry.hidden ?? false,
|
|
9179
9182
|
locked: entry.locked ?? false,
|
|
9183
|
+
hugWidth: entry.hugWidth ?? false,
|
|
9184
|
+
hugHeight: entry.hugHeight ?? false,
|
|
9180
9185
|
placed: true
|
|
9181
9186
|
});
|
|
9182
9187
|
}
|
|
@@ -9205,6 +9210,8 @@ function placeNext(placed) {
|
|
|
9205
9210
|
order,
|
|
9206
9211
|
hidden: false,
|
|
9207
9212
|
locked: false,
|
|
9213
|
+
hugWidth: false,
|
|
9214
|
+
hugHeight: false,
|
|
9208
9215
|
placed: false
|
|
9209
9216
|
};
|
|
9210
9217
|
}
|
|
@@ -9224,9 +9231,9 @@ async function scanProject(root, name) {
|
|
|
9224
9231
|
const { pages: order, createdAt, error } = await readPageOrder(path);
|
|
9225
9232
|
const pages = await Promise.all(order.map((page, index) => scanPage(root, name, page, index)));
|
|
9226
9233
|
const times = await Promise.all([
|
|
9227
|
-
mtimeOf(join(path, PROJECT_FILE)),
|
|
9228
|
-
mtimeOf(path),
|
|
9229
|
-
...pages.flatMap((page) => [mtimeOf(join(page.path, LAYOUT_FILE)), ...page.frames.map((frame) => Date.parse(frame.modifiedAt))])
|
|
9234
|
+
mtimeOf$1(join(path, PROJECT_FILE)),
|
|
9235
|
+
mtimeOf$1(path),
|
|
9236
|
+
...pages.flatMap((page) => [mtimeOf$1(join(page.path, LAYOUT_FILE)), ...page.frames.map((frame) => Date.parse(frame.modifiedAt))])
|
|
9230
9237
|
]);
|
|
9231
9238
|
return {
|
|
9232
9239
|
name,
|
|
@@ -9263,7 +9270,7 @@ async function scanPage(root, project, name, index) {
|
|
|
9263
9270
|
name: frame,
|
|
9264
9271
|
path: framePath,
|
|
9265
9272
|
...placement,
|
|
9266
|
-
modifiedAt: new Date(await mtimeOf(framePath)).toISOString()
|
|
9273
|
+
modifiedAt: new Date(await mtimeOf$1(framePath)).toISOString()
|
|
9267
9274
|
};
|
|
9268
9275
|
}));
|
|
9269
9276
|
return {
|
|
@@ -9279,7 +9286,7 @@ async function scanPage(root, project, name, index) {
|
|
|
9279
9286
|
async function childFolders(dir) {
|
|
9280
9287
|
return (await readdir(dir, { withFileTypes: true })).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name);
|
|
9281
9288
|
}
|
|
9282
|
-
async function mtimeOf(path) {
|
|
9289
|
+
async function mtimeOf$1(path) {
|
|
9283
9290
|
try {
|
|
9284
9291
|
return (await stat$1(path)).mtimeMs;
|
|
9285
9292
|
} catch (error) {
|
|
@@ -9353,12 +9360,28 @@ async function isDirectory(path) {
|
|
|
9353
9360
|
}
|
|
9354
9361
|
//#endregion
|
|
9355
9362
|
//#region package.json
|
|
9356
|
-
var version$1 = "0.
|
|
9363
|
+
var version$1 = "0.10.0";
|
|
9357
9364
|
var dependencies = { "playwright-core": "1.64.1" };
|
|
9358
9365
|
//#endregion
|
|
9359
9366
|
//#region src/shared/version.ts
|
|
9360
9367
|
const version = version$1;
|
|
9361
9368
|
//#endregion
|
|
9369
|
+
//#region src/cli/client-dir.ts
|
|
9370
|
+
/**
|
|
9371
|
+
* The folder the board client is served from. A built run reads the `client`
|
|
9372
|
+
* folder the build put beside the bundle and never looks further. A source run
|
|
9373
|
+
* reads the repository's `dist/client`, which `bun run build` leaves, and
|
|
9374
|
+
* writes nothing since the client changes with every branch. Either folder
|
|
9375
|
+
* without an `index.html` refuses, so a broken package or an interrupted build
|
|
9376
|
+
* never serves 404s. A folder given outright is held to the same test.
|
|
9377
|
+
*/
|
|
9378
|
+
function resolveClientDir(moduleUrl = import.meta.url, given) {
|
|
9379
|
+
const built = !moduleUrl.endsWith(".ts");
|
|
9380
|
+
const dir = given ?? fileURLToPath(new URL(built ? "./client" : "../../dist/client", moduleUrl));
|
|
9381
|
+
if (!existsSync(`${dir}/index.html`)) throw new FrameboardError("client-not-built", built ? `The board client is missing at ${dir}. Reinstall frameboard.` : `The board client is not built at ${dir}. Run bun run build first.`, { clientDir: dir });
|
|
9382
|
+
return dir;
|
|
9383
|
+
}
|
|
9384
|
+
//#endregion
|
|
9362
9385
|
//#region src/shared/records/address.ts
|
|
9363
9386
|
const addressFileSchema = looseObject({
|
|
9364
9387
|
version: literal(1),
|
|
@@ -9601,7 +9624,9 @@ async function framePathParts(root, ref, cwd) {
|
|
|
9601
9624
|
/**
|
|
9602
9625
|
* Places a frame on its page, writing a skeleton file only when none exists.
|
|
9603
9626
|
* A file with no entry keeps its bytes and takes the box `list` showed for it
|
|
9604
|
-
* unless a size or position is given.
|
|
9627
|
+
* unless a size or position is given. Every axis no size names hugs its
|
|
9628
|
+
* content, a preset fixing the width alone, and the box stands in until the
|
|
9629
|
+
* server measures.
|
|
9605
9630
|
*/
|
|
9606
9631
|
async function addFrame(root, ref, options) {
|
|
9607
9632
|
const { journal } = options;
|
|
@@ -9630,7 +9655,8 @@ async function addFrame(root, ref, options) {
|
|
|
9630
9655
|
...size,
|
|
9631
9656
|
x: options.x ?? computed.box.x,
|
|
9632
9657
|
y: options.y ?? computed.box.y
|
|
9633
|
-
}
|
|
9658
|
+
},
|
|
9659
|
+
...hugsOf(options)
|
|
9634
9660
|
});
|
|
9635
9661
|
layout.renumber();
|
|
9636
9662
|
}, journal);
|
|
@@ -9638,9 +9664,11 @@ async function addFrame(root, ref, options) {
|
|
|
9638
9664
|
}
|
|
9639
9665
|
/**
|
|
9640
9666
|
* Copies the frame's file byte for byte, into its own page beside the source
|
|
9641
|
-
* or into `--to` at the source's box, on top of the target page.
|
|
9667
|
+
* or into `--to` at the source's box, on top of the target page. An `offset`
|
|
9668
|
+
* places the copy that far from the source's box instead, as an Alt-drag
|
|
9669
|
+
* drops it.
|
|
9642
9670
|
*/
|
|
9643
|
-
async function duplicateFrame(root, ref, { to, name, journal, ...options }) {
|
|
9671
|
+
async function duplicateFrame(root, ref, { to, name, offset, journal, ...options }) {
|
|
9644
9672
|
const source = await resolveFrameRef(root, ref, options);
|
|
9645
9673
|
const target = to ? await resolvePageRef(root, to, options) : void 0;
|
|
9646
9674
|
const from = pageDir(source);
|
|
@@ -9650,7 +9678,11 @@ async function duplicateFrame(root, ref, { to, name, journal, ...options }) {
|
|
|
9650
9678
|
const targetLayout = layoutAt(layouts, into);
|
|
9651
9679
|
const copyName = freeFrameName(targetLayout.names, source.name, name);
|
|
9652
9680
|
const placement = sourceLayout.placement(source.name);
|
|
9653
|
-
const box =
|
|
9681
|
+
const box = offset ? {
|
|
9682
|
+
...placement.box,
|
|
9683
|
+
x: placement.box.x + offset.x,
|
|
9684
|
+
y: placement.box.y + offset.y
|
|
9685
|
+
} : into === from ? {
|
|
9654
9686
|
...placement.box,
|
|
9655
9687
|
x: placement.box.x + placement.box.width + 80
|
|
9656
9688
|
} : placement.box;
|
|
@@ -9733,10 +9765,55 @@ async function resizeFrame(root, ref, options) {
|
|
|
9733
9765
|
box: {
|
|
9734
9766
|
...placement.box,
|
|
9735
9767
|
...size
|
|
9736
|
-
}
|
|
9768
|
+
},
|
|
9769
|
+
hugWidth: placement.hugWidth && size.width === void 0,
|
|
9770
|
+
hugHeight: placement.hugHeight && size.height === void 0
|
|
9737
9771
|
}));
|
|
9738
9772
|
}
|
|
9739
9773
|
/**
|
|
9774
|
+
* Sets a frame's height to its content's measured height and turns hugging
|
|
9775
|
+
* back on for that axis, the inverse of the resize that fixed it.
|
|
9776
|
+
*/
|
|
9777
|
+
async function fitHeight(root, ref, height, options) {
|
|
9778
|
+
return updatePlacement(root, ref, options, (placement) => ({
|
|
9779
|
+
...placement,
|
|
9780
|
+
box: {
|
|
9781
|
+
...placement.box,
|
|
9782
|
+
height
|
|
9783
|
+
},
|
|
9784
|
+
hugHeight: true
|
|
9785
|
+
}));
|
|
9786
|
+
}
|
|
9787
|
+
/**
|
|
9788
|
+
* Writes the sizes the server measured, on the axes each frame's stored entry
|
|
9789
|
+
* hugs and nowhere else, under the page's lock. It sets no flag and takes no
|
|
9790
|
+
* journal, since the developer never set that size, and answers the names
|
|
9791
|
+
* whose entry changed, none when every size already stands.
|
|
9792
|
+
*/
|
|
9793
|
+
async function setMeasured(root, pageRef, sizes, options) {
|
|
9794
|
+
const page = await resolvePageRef(root, pageRef, options);
|
|
9795
|
+
return withLayouts([page.path], async (layouts) => {
|
|
9796
|
+
const layout = layoutAt(layouts, page.path);
|
|
9797
|
+
const written = [];
|
|
9798
|
+
for (const [name, size] of Object.entries(sizes)) {
|
|
9799
|
+
if (!layout.hasEntry(name) || !layout.names.includes(name)) continue;
|
|
9800
|
+
const placement = layout.placement(name);
|
|
9801
|
+
const box = {
|
|
9802
|
+
...placement.box,
|
|
9803
|
+
width: placement.hugWidth ? size.width : placement.box.width,
|
|
9804
|
+
height: placement.hugHeight ? size.height : placement.box.height
|
|
9805
|
+
};
|
|
9806
|
+
if (sameBox(box, placement.box)) continue;
|
|
9807
|
+
layout.set(name, {
|
|
9808
|
+
...placement,
|
|
9809
|
+
box
|
|
9810
|
+
});
|
|
9811
|
+
written.push(name);
|
|
9812
|
+
}
|
|
9813
|
+
return written;
|
|
9814
|
+
});
|
|
9815
|
+
}
|
|
9816
|
+
/**
|
|
9740
9817
|
* Sets the boxes of several frames on one page under one lock and one write,
|
|
9741
9818
|
* the one path a hand move or resize takes. `expected` holds the boxes the
|
|
9742
9819
|
* client started from, and a frame whose stored box differs from it refuses
|
|
@@ -9753,7 +9830,12 @@ async function setBoxes(root, pageRef, boxes, expected, options) {
|
|
|
9753
9830
|
const placement = layout.placement(name);
|
|
9754
9831
|
if (placement.locked) throw new FrameboardError("frame-locked", `${ref} is locked.`, { ref });
|
|
9755
9832
|
const started = expected[name];
|
|
9756
|
-
|
|
9833
|
+
const box = boxes[name];
|
|
9834
|
+
const kept = box && started ? measuredAxes(placement, box, started) : {};
|
|
9835
|
+
if (!started || !sameBox({
|
|
9836
|
+
...started,
|
|
9837
|
+
...kept
|
|
9838
|
+
}, placement.box)) throw new FrameboardError("stale-layout", `${ref} moved since this edit began, so nothing was written.`, {
|
|
9757
9839
|
ref,
|
|
9758
9840
|
stored: placement.box,
|
|
9759
9841
|
expected: started ?? null
|
|
@@ -9761,16 +9843,37 @@ async function setBoxes(root, pageRef, boxes, expected, options) {
|
|
|
9761
9843
|
return {
|
|
9762
9844
|
name,
|
|
9763
9845
|
placement,
|
|
9764
|
-
box
|
|
9846
|
+
box,
|
|
9847
|
+
kept,
|
|
9848
|
+
started
|
|
9765
9849
|
};
|
|
9766
9850
|
});
|
|
9767
|
-
for (const { name, placement, box } of placements)
|
|
9768
|
-
|
|
9769
|
-
|
|
9770
|
-
|
|
9851
|
+
for (const { name, placement, box, kept, started } of placements) {
|
|
9852
|
+
if (!box || !started) continue;
|
|
9853
|
+
layout.set(name, {
|
|
9854
|
+
...placement,
|
|
9855
|
+
box: {
|
|
9856
|
+
...box,
|
|
9857
|
+
...kept
|
|
9858
|
+
},
|
|
9859
|
+
hugWidth: placement.hugWidth && box.width === started.width,
|
|
9860
|
+
hugHeight: placement.hugHeight && box.height === started.height
|
|
9861
|
+
});
|
|
9862
|
+
}
|
|
9771
9863
|
}, options.journal);
|
|
9772
9864
|
return (await frameRecords(root, page.project, page.name)).filter((frame) => names.includes(frame.name));
|
|
9773
9865
|
}
|
|
9866
|
+
/**
|
|
9867
|
+
* The stored size of each hugging axis a hand write leaves at the size it
|
|
9868
|
+
* started from, since the server may have measured that axis since and a move
|
|
9869
|
+
* never meant to set it.
|
|
9870
|
+
*/
|
|
9871
|
+
function measuredAxes(placement, box, started) {
|
|
9872
|
+
return {
|
|
9873
|
+
...placement.hugWidth && box.width === started.width ? { width: placement.box.width } : {},
|
|
9874
|
+
...placement.hugHeight && box.height === started.height ? { height: placement.box.height } : {}
|
|
9875
|
+
};
|
|
9876
|
+
}
|
|
9774
9877
|
function sameBox(a, b) {
|
|
9775
9878
|
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
9776
9879
|
}
|
|
@@ -9817,6 +9920,13 @@ async function updatePlacement(root, ref, options, change) {
|
|
|
9817
9920
|
}, options.journal);
|
|
9818
9921
|
return frameRecord(root, frame.project, frame.page, frame.name);
|
|
9819
9922
|
}
|
|
9923
|
+
/** Which axes `frame add` leaves hugging: every one no size option names, the height under a preset. */
|
|
9924
|
+
function hugsOf({ size, width, height }) {
|
|
9925
|
+
return {
|
|
9926
|
+
hugWidth: size === void 0 && width === void 0,
|
|
9927
|
+
hugHeight: height === void 0
|
|
9928
|
+
};
|
|
9929
|
+
}
|
|
9820
9930
|
/** The size a verb sets, from a preset or from explicit width and height. */
|
|
9821
9931
|
function sizeOf({ size, width, height }) {
|
|
9822
9932
|
if (size !== void 0 && (width !== void 0 || height !== void 0)) throw new FrameboardError("usage", "Pass --size or --width and --height, not both.", {
|
|
@@ -9874,19 +9984,24 @@ var PageLayout = class {
|
|
|
9874
9984
|
return Math.max(...this.names.map((name) => this.placement(name).order + 1), 0);
|
|
9875
9985
|
}
|
|
9876
9986
|
/**
|
|
9877
|
-
* Writes
|
|
9878
|
-
* the entry already held, so unknown keys survive in place.
|
|
9987
|
+
* Writes the seven fixed keys on the entry it creates or changes, after any
|
|
9988
|
+
* key the entry already held, so unknown keys survive in place. A hug flag
|
|
9989
|
+
* is written on an entry it creates, once it is on, or when the entry holds
|
|
9990
|
+
* it, so a write to an entry from before the flags adds no key.
|
|
9879
9991
|
*/
|
|
9880
|
-
set(name, { box, order, hidden, locked }) {
|
|
9992
|
+
set(name, { box, order, hidden, locked, hugWidth, hugHeight }) {
|
|
9993
|
+
const held = this.file.frames[name];
|
|
9881
9994
|
this.file.frames[name] = {
|
|
9882
|
-
...
|
|
9995
|
+
...held,
|
|
9883
9996
|
x: box.x,
|
|
9884
9997
|
y: box.y,
|
|
9885
9998
|
width: box.width,
|
|
9886
9999
|
height: box.height,
|
|
9887
10000
|
order,
|
|
9888
10001
|
hidden,
|
|
9889
|
-
locked
|
|
10002
|
+
locked,
|
|
10003
|
+
...!held || hugWidth || held.hugWidth !== void 0 ? { hugWidth } : {},
|
|
10004
|
+
...!held || hugHeight || held.hugHeight !== void 0 ? { hugHeight } : {}
|
|
9890
10005
|
};
|
|
9891
10006
|
this.changed = true;
|
|
9892
10007
|
}
|
|
@@ -28494,7 +28609,29 @@ function swapSpan(source, span, side) {
|
|
|
28494
28609
|
* does not keep overriding the value just set. A longhand write leaves its
|
|
28495
28610
|
* shorthand alone, since the longhand comes later and already wins.
|
|
28496
28611
|
*/
|
|
28612
|
+
const BORDER_SIDES = [
|
|
28613
|
+
"top",
|
|
28614
|
+
"right",
|
|
28615
|
+
"bottom",
|
|
28616
|
+
"left"
|
|
28617
|
+
];
|
|
28618
|
+
const BORDER_PARTS = [
|
|
28619
|
+
"color",
|
|
28620
|
+
"style",
|
|
28621
|
+
"width"
|
|
28622
|
+
];
|
|
28497
28623
|
const SHORTHAND_LONGHANDS = {
|
|
28624
|
+
background: [
|
|
28625
|
+
"background-attachment",
|
|
28626
|
+
"background-clip",
|
|
28627
|
+
"background-color",
|
|
28628
|
+
"background-image",
|
|
28629
|
+
"background-origin",
|
|
28630
|
+
"background-position",
|
|
28631
|
+
"background-repeat",
|
|
28632
|
+
"background-size"
|
|
28633
|
+
],
|
|
28634
|
+
border: [...BORDER_PARTS.map((part) => `border-${part}`), ...BORDER_SIDES.flatMap((side) => [`border-${side}`, ...BORDER_PARTS.map((part) => `border-${side}-${part}`)])],
|
|
28498
28635
|
"border-radius": [
|
|
28499
28636
|
"border-top-left-radius",
|
|
28500
28637
|
"border-top-right-radius",
|
|
@@ -28876,7 +29013,9 @@ const STATUS$3 = {
|
|
|
28876
29013
|
"frame-locked": 423,
|
|
28877
29014
|
"layout-invalid": 422,
|
|
28878
29015
|
"project-file-invalid": 422,
|
|
28879
|
-
"
|
|
29016
|
+
"fit-unbounded": 422,
|
|
29017
|
+
"lock-timeout": 503,
|
|
29018
|
+
"browser-not-found": 503
|
|
28880
29019
|
};
|
|
28881
29020
|
/**
|
|
28882
29021
|
* Answers a refusal in the CLI's `{ ok, error }` envelope, for a route
|
|
@@ -34715,11 +34854,13 @@ function setFrameTheme(root, theme) {
|
|
|
34715
34854
|
}
|
|
34716
34855
|
/**
|
|
34717
34856
|
* Where a frame is served in one theme, with `version` naming the reload so
|
|
34718
|
-
* a changed file loads fresh
|
|
34857
|
+
* a changed file loads fresh, and `at` naming a version an agent's write
|
|
34858
|
+
* replaced by its content hash.
|
|
34719
34859
|
*/
|
|
34720
|
-
function frameThemeUrl(ref, theme, version) {
|
|
34860
|
+
function frameThemeUrl(ref, theme, version, at) {
|
|
34721
34861
|
const query = new URLSearchParams({ [THEME_QUERY]: theme });
|
|
34722
34862
|
if (version !== void 0) query.set("v", String(version));
|
|
34863
|
+
if (at !== void 0) query.set("at", at);
|
|
34723
34864
|
return `${frameUrl(ref)}?${query}`;
|
|
34724
34865
|
}
|
|
34725
34866
|
//#endregion
|
|
@@ -34821,17 +34962,28 @@ const CONTENT_TYPES$1 = {
|
|
|
34821
34962
|
*
|
|
34822
34963
|
* A frame served from a page gets the faces and the token sheets spliced
|
|
34823
34964
|
* first into its `head`, in the response alone, and every other file is
|
|
34824
|
-
* served byte for byte.
|
|
34965
|
+
* served byte for byte. A frame path carrying `?at=<hash>` serves the
|
|
34966
|
+
* version `version` holds under that hash in its place, with the same head,
|
|
34967
|
+
* and any other path carrying it answers 404.
|
|
34825
34968
|
*/
|
|
34826
|
-
function frameRoutes(root, look) {
|
|
34969
|
+
function frameRoutes(root, look, version) {
|
|
34827
34970
|
const app = new Hono();
|
|
34828
34971
|
app.get("/frames/*", async (c) => {
|
|
34829
34972
|
const parts = decodeSegments(new URL(c.req.url).pathname.slice(8).split("/"));
|
|
34830
34973
|
const file = parts && await resolveFile(root, parts);
|
|
34831
34974
|
if (!file) return c.notFound();
|
|
34832
|
-
const [project = "", page = ""] = parts;
|
|
34833
|
-
const
|
|
34834
|
-
const
|
|
34975
|
+
const [project = "", page = "", name = ""] = parts;
|
|
34976
|
+
const isFrame = page !== "assets" && parts.length === 3 && extname(file).toLowerCase() === ".html";
|
|
34977
|
+
const at = c.req.query("at");
|
|
34978
|
+
let bytes;
|
|
34979
|
+
if (at === void 0) bytes = new Uint8Array(await readFile(file));
|
|
34980
|
+
else {
|
|
34981
|
+
const ref = `${project}/${page}/${name.slice(0, -5)}`;
|
|
34982
|
+
const held = isFrame ? version?.(ref, at) ?? null : null;
|
|
34983
|
+
if (held === null) return c.notFound();
|
|
34984
|
+
bytes = new TextEncoder().encode(held);
|
|
34985
|
+
}
|
|
34986
|
+
const body = isFrame ? injectHead(bytes, frameHead(sheetUrls(project, look.sheets(project)), contentHash(bytes))) : bytes;
|
|
34835
34987
|
return c.body(body, 200, {
|
|
34836
34988
|
"Content-Type": CONTENT_TYPES$1[extname(file).toLowerCase()] ?? "application/octet-stream",
|
|
34837
34989
|
"Cache-Control": "no-store"
|
|
@@ -34890,16 +35042,17 @@ const CONTENT_TYPES = {
|
|
|
34890
35042
|
* The look routes and the frame routes over `root`, so the board server and
|
|
34891
35043
|
* the capture host serve a frame the same way. `tokens` is a known
|
|
34892
35044
|
* `--tokens` sheet, null for none, or absent to read the one a running
|
|
34893
|
-
* server recorded in the address file on each request.
|
|
35045
|
+
* server recorded in the address file on each request. `version` serves the
|
|
35046
|
+
* frame versions an agent write replaced, absent where nothing holds them.
|
|
34894
35047
|
*/
|
|
34895
|
-
function servedFrames(root, { facesDir, tokens }) {
|
|
35048
|
+
function servedFrames(root, { facesDir, tokens, version }) {
|
|
34896
35049
|
const look = { sheets: (project) => tokenSheetPaths(root, project, tokens) };
|
|
34897
35050
|
const routes = new Hono();
|
|
34898
35051
|
routes.route("/", lookRoutes({
|
|
34899
35052
|
facesDir,
|
|
34900
35053
|
boardSheet: () => boardSheetPath(root, tokens)
|
|
34901
35054
|
}));
|
|
34902
|
-
routes.route("/", frameRoutes(root, look));
|
|
35055
|
+
routes.route("/", frameRoutes(root, look, version));
|
|
34903
35056
|
return {
|
|
34904
35057
|
look,
|
|
34905
35058
|
routes
|
|
@@ -35713,6 +35866,14 @@ const frameAddSchema = object$1({
|
|
|
35713
35866
|
y: coordinate.optional()
|
|
35714
35867
|
});
|
|
35715
35868
|
const framesSchema = object$1({ refs });
|
|
35869
|
+
const frameDuplicateSchema = object$1({
|
|
35870
|
+
refs,
|
|
35871
|
+
offset: object$1({
|
|
35872
|
+
x: coordinate,
|
|
35873
|
+
y: coordinate
|
|
35874
|
+
}).optional()
|
|
35875
|
+
});
|
|
35876
|
+
const frameSchema = object$1({ ref });
|
|
35716
35877
|
const pasteSchema = object$1({
|
|
35717
35878
|
ref,
|
|
35718
35879
|
at: object$1({
|
|
@@ -35735,8 +35896,10 @@ const UNTITLED = "untitled";
|
|
|
35735
35896
|
* Each write reports into its own journal and records one step, so the
|
|
35736
35897
|
* developer can undo it, and names the page the board shows on either side
|
|
35737
35898
|
* of it, so an undo can follow a page it brings back or renames.
|
|
35899
|
+
* `measure` reads a frame's content on the warm browser for a fit, which
|
|
35900
|
+
* refuses `browser-not-found` where none is given.
|
|
35738
35901
|
*/
|
|
35739
|
-
function structureRoutes(root, access, history) {
|
|
35902
|
+
function structureRoutes(root, access, history, measure) {
|
|
35740
35903
|
const app = new Hono();
|
|
35741
35904
|
app.use("/api/page/*", requireWriter(access));
|
|
35742
35905
|
app.use("/api/frame/*", requireWriter(access));
|
|
@@ -35894,10 +36057,11 @@ function structureRoutes(root, access, history) {
|
|
|
35894
36057
|
});
|
|
35895
36058
|
});
|
|
35896
36059
|
app.post("/api/frame/duplicate", async (c) => {
|
|
35897
|
-
const body = await parseBody$1(c.req.raw,
|
|
36060
|
+
const body = await parseBody$1(c.req.raw, frameDuplicateSchema);
|
|
35898
36061
|
const copies = await eachFrame(body.refs, (frame, journal) => duplicateFrame(root, frame, {
|
|
35899
36062
|
cwd,
|
|
35900
|
-
journal
|
|
36063
|
+
journal,
|
|
36064
|
+
offset: body.offset
|
|
35901
36065
|
}), (records) => records.map((record) => record.ref));
|
|
35902
36066
|
return c.json({
|
|
35903
36067
|
ok: true,
|
|
@@ -35940,6 +36104,32 @@ function structureRoutes(root, access, history) {
|
|
|
35940
36104
|
data: frames
|
|
35941
36105
|
});
|
|
35942
36106
|
});
|
|
36107
|
+
/**
|
|
36108
|
+
* Sets one frame's height to its content's own and turns its height
|
|
36109
|
+
* hugging on, as `frame fit` does, refusing a frame whose content sizes
|
|
36110
|
+
* itself off the viewport. The width is reported, never changed.
|
|
36111
|
+
*/
|
|
36112
|
+
app.post("/api/frame/fit", async (c) => {
|
|
36113
|
+
const body = await parseBody$1(c.req.raw, frameSchema);
|
|
36114
|
+
await refuseLocked([body.ref]);
|
|
36115
|
+
await refuseHeldFrames([body.ref]);
|
|
36116
|
+
if (!measure) throw new FrameboardError("browser-not-found", "Fit height needs the board server's browser, and none runs here.");
|
|
36117
|
+
const frame = await readFrame$1(root, body.ref, { cwd });
|
|
36118
|
+
const measured = await measure(frame);
|
|
36119
|
+
const fit = await recorded((journal) => fitHeight(root, frame.ref, measured.height, {
|
|
36120
|
+
cwd,
|
|
36121
|
+
journal
|
|
36122
|
+
}), (record) => onFrames([record.ref]));
|
|
36123
|
+
return c.json({
|
|
36124
|
+
ok: true,
|
|
36125
|
+
data: {
|
|
36126
|
+
frame: fit,
|
|
36127
|
+
contentHeight: measured.height,
|
|
36128
|
+
contentWidth: measured.contentWidth,
|
|
36129
|
+
tooWide: measured.contentWidth > fit.box.width
|
|
36130
|
+
}
|
|
36131
|
+
});
|
|
36132
|
+
});
|
|
35943
36133
|
app.post("/api/frame/delete", async (c) => {
|
|
35944
36134
|
const body = await parseBody$1(c.req.raw, framesSchema);
|
|
35945
36135
|
await refuseLocked(body.refs);
|
|
@@ -36110,7 +36300,7 @@ function boardHostGuard(port) {
|
|
|
36110
36300
|
await next();
|
|
36111
36301
|
};
|
|
36112
36302
|
}
|
|
36113
|
-
function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails }) {
|
|
36303
|
+
function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails, measure, frameVersion }) {
|
|
36114
36304
|
const app = new Hono();
|
|
36115
36305
|
const given = tokens ?? null;
|
|
36116
36306
|
app.use("*", async (c, next) => {
|
|
@@ -36120,7 +36310,8 @@ function createApp({ clientDir, root, port, actions, tickets, renderFrame, faces
|
|
|
36120
36310
|
app.use("*", boardHostGuard(port));
|
|
36121
36311
|
const frames = servedFrames(root, {
|
|
36122
36312
|
facesDir,
|
|
36123
|
-
tokens: given
|
|
36313
|
+
tokens: given,
|
|
36314
|
+
version: frameVersion
|
|
36124
36315
|
});
|
|
36125
36316
|
app.get("/api/health", (c) => c.json({
|
|
36126
36317
|
version,
|
|
@@ -36129,7 +36320,7 @@ function createApp({ clientDir, root, port, actions, tickets, renderFrame, faces
|
|
|
36129
36320
|
}));
|
|
36130
36321
|
app.route("/", accessRoutes(actions.access, tickets));
|
|
36131
36322
|
app.route("/", apiRoutes(root, actions, frames.look, history));
|
|
36132
|
-
app.route("/", structureRoutes(root, actions.access, history));
|
|
36323
|
+
app.route("/", structureRoutes(root, actions.access, history, measure));
|
|
36133
36324
|
app.route("/", historyRoutes(actions.access, history));
|
|
36134
36325
|
app.route("/", notesRoutes(root, actions.access, delivery));
|
|
36135
36326
|
app.route("/", assetsRoutes(root, actions.access));
|
|
@@ -37118,50 +37309,100 @@ function readTextSizes() {
|
|
|
37118
37309
|
}
|
|
37119
37310
|
//#endregion
|
|
37120
37311
|
//#region src/server/capture/fit.ts
|
|
37121
|
-
/**
|
|
37122
|
-
|
|
37123
|
-
|
|
37124
|
-
*
|
|
37125
|
-
*
|
|
37126
|
-
*
|
|
37127
|
-
|
|
37128
|
-
|
|
37129
|
-
|
|
37130
|
-
|
|
37131
|
-
|
|
37132
|
-
|
|
37133
|
-
|
|
37134
|
-
const current = await measure(browser, baseUrl, frame.ref, {
|
|
37135
|
-
width,
|
|
37136
|
-
height
|
|
37137
|
-
});
|
|
37138
|
-
if (short.height !== current.height) throw new FrameboardError("fit-unbounded", `${frame.ref} grows with the viewport, measuring ${short.height} px in a 1 px viewport and ${current.height} px at its ${height} px height, so it has no content height to fit. Size it by hand with frame resize.`, {
|
|
37139
|
-
ref: frame.ref,
|
|
37140
|
-
heights: [short.height, current.height]
|
|
37141
|
-
});
|
|
37142
|
-
return {
|
|
37143
|
-
frame: await resizeFrame(options.root, frame.ref, {
|
|
37144
|
-
...options,
|
|
37145
|
-
height: short.height
|
|
37146
|
-
}),
|
|
37147
|
-
contentHeight: short.height,
|
|
37148
|
-
contentWidth: current.width,
|
|
37149
|
-
tooWide: current.width > width
|
|
37150
|
-
};
|
|
37151
|
-
}
|
|
37152
|
-
async function measure(browser, baseUrl, ref, box) {
|
|
37312
|
+
/** The widest a hugging width grows, past which the layout check reports the content clipped. */
|
|
37313
|
+
const HUG_MAX_WIDTH = FRAME_SIZES.desktop.width;
|
|
37314
|
+
/**
|
|
37315
|
+
* Measures a frame's content the way `frame fit` and the server's hug step
|
|
37316
|
+
* both read it, in one page resized between readings. A hugging width takes
|
|
37317
|
+
* the content's `fit-content` width up to `HUG_MAX_WIDTH`, and the height is
|
|
37318
|
+
* read at that width with a 1 px tall viewport and again at the box's height.
|
|
37319
|
+
* Readings that differ mean the content sizes itself off the viewport, which
|
|
37320
|
+
* has no height of its own to fit, so that refuses `fit-unbounded`. Finite
|
|
37321
|
+
* animations finish before the first reading, so an entrance is read at its
|
|
37322
|
+
* settled size.
|
|
37323
|
+
*/
|
|
37324
|
+
async function measureContent(browser, { baseUrl, ref, box, hugWidth, fonts }) {
|
|
37153
37325
|
const opened = await openFrame(browser, {
|
|
37154
37326
|
baseUrl,
|
|
37155
37327
|
ref,
|
|
37156
37328
|
box,
|
|
37157
|
-
theme: "light"
|
|
37329
|
+
theme: "light",
|
|
37330
|
+
fonts
|
|
37158
37331
|
});
|
|
37159
37332
|
try {
|
|
37160
|
-
|
|
37333
|
+
const { page } = opened;
|
|
37334
|
+
await page.evaluate(finishAnimations);
|
|
37335
|
+
const empty = await page.evaluate(isBodyEmpty);
|
|
37336
|
+
let width = box.width;
|
|
37337
|
+
if (hugWidth && !empty) {
|
|
37338
|
+
await page.setViewportSize({
|
|
37339
|
+
width: HUG_MAX_WIDTH,
|
|
37340
|
+
height: box.height
|
|
37341
|
+
});
|
|
37342
|
+
width = Math.min(HUG_MAX_WIDTH, await page.evaluate(readFitWidth));
|
|
37343
|
+
}
|
|
37344
|
+
const short = await readAt(page, {
|
|
37345
|
+
width,
|
|
37346
|
+
height: 1
|
|
37347
|
+
});
|
|
37348
|
+
const current = await readAt(page, {
|
|
37349
|
+
width,
|
|
37350
|
+
height: box.height
|
|
37351
|
+
});
|
|
37352
|
+
if (short.height !== current.height) throw new FrameboardError("fit-unbounded", `${ref} grows with the viewport, measuring ${short.height} px in a 1 px viewport and ${current.height} px at its ${box.height} px height, so it has no content height to fit. Size it by hand with frame resize.`, {
|
|
37353
|
+
ref,
|
|
37354
|
+
heights: [short.height, current.height]
|
|
37355
|
+
});
|
|
37356
|
+
return {
|
|
37357
|
+
width,
|
|
37358
|
+
height: short.height,
|
|
37359
|
+
contentWidth: current.width,
|
|
37360
|
+
empty
|
|
37361
|
+
};
|
|
37161
37362
|
} finally {
|
|
37162
37363
|
await opened.close();
|
|
37163
37364
|
}
|
|
37164
37365
|
}
|
|
37366
|
+
/**
|
|
37367
|
+
* Sets a frame's height to its content's own height at its layout width and
|
|
37368
|
+
* turns its height hugging on. The width is reported, never changed.
|
|
37369
|
+
*/
|
|
37370
|
+
async function fitFrame(browser, { baseUrl, frame, ...options }) {
|
|
37371
|
+
const measured = await measureContent(browser, {
|
|
37372
|
+
baseUrl,
|
|
37373
|
+
ref: frame.ref,
|
|
37374
|
+
box: frame.box,
|
|
37375
|
+
hugWidth: false
|
|
37376
|
+
});
|
|
37377
|
+
return {
|
|
37378
|
+
frame: await fitHeight(options.root, frame.ref, measured.height, options),
|
|
37379
|
+
contentHeight: measured.height,
|
|
37380
|
+
contentWidth: measured.contentWidth,
|
|
37381
|
+
tooWide: measured.contentWidth > frame.box.width
|
|
37382
|
+
};
|
|
37383
|
+
}
|
|
37384
|
+
async function readAt(page, viewport) {
|
|
37385
|
+
await page.setViewportSize(viewport);
|
|
37386
|
+
return page.evaluate(readContentSize);
|
|
37387
|
+
}
|
|
37388
|
+
function finishAnimations() {
|
|
37389
|
+
for (const animation of document.getAnimations()) {
|
|
37390
|
+
const end = animation.effect?.getComputedTiming().endTime;
|
|
37391
|
+
if (typeof end === "number" && Number.isFinite(end)) animation.finish();
|
|
37392
|
+
}
|
|
37393
|
+
}
|
|
37394
|
+
function isBodyEmpty() {
|
|
37395
|
+
const body = document.body;
|
|
37396
|
+
return body.children.length === 0 && (body.textContent ?? "").trim() === "";
|
|
37397
|
+
}
|
|
37398
|
+
function readFitWidth() {
|
|
37399
|
+
const root = document.documentElement;
|
|
37400
|
+
const before = root.style.width;
|
|
37401
|
+
root.style.width = "fit-content";
|
|
37402
|
+
const width = Math.ceil(root.getBoundingClientRect().width);
|
|
37403
|
+
root.style.width = before;
|
|
37404
|
+
return Math.max(1, width);
|
|
37405
|
+
}
|
|
37165
37406
|
function readContentSize() {
|
|
37166
37407
|
const root = document.documentElement;
|
|
37167
37408
|
const crops = (element) => {
|
|
@@ -37583,6 +37824,9 @@ const frameRecordSchema = object$1({
|
|
|
37583
37824
|
order: number(),
|
|
37584
37825
|
hidden: boolean$1(),
|
|
37585
37826
|
locked: boolean$1(),
|
|
37827
|
+
/** Whether each axis takes its size from the content rather than holding it. */
|
|
37828
|
+
hugWidth: boolean$1(),
|
|
37829
|
+
hugHeight: boolean$1(),
|
|
37586
37830
|
placed: boolean$1(),
|
|
37587
37831
|
modifiedAt: string$1()
|
|
37588
37832
|
});
|
|
@@ -37994,7 +38238,9 @@ function contentFormat() {
|
|
|
37994
38238
|
defaultFrameSize: DEFAULT_FRAME_SIZE,
|
|
37995
38239
|
layout: [
|
|
37996
38240
|
"x and y are integers, width and height integers of at least 1, and order an integer of at least 0, where a higher order draws on top.",
|
|
37997
|
-
"hidden and
|
|
38241
|
+
"hidden, locked, hugWidth, and hugHeight read as false when absent, and an axis whose hug flag is false holds the size its entry states.",
|
|
38242
|
+
`An axis that hugs takes its size from the frame's content: a running serve measures it after each write to the frame file, its width at most ${FRAME_SIZES.desktop.width} px, and writes width and height alone, never a flag. Content sized off the viewport keeps the box it has.`,
|
|
38243
|
+
"frame add with no size hugs both axes, --size or --width fixes the width and hugs the height, and --height fixes the height alone, its box standing in until serve measures. frame resize and a hand resize fix each axis they set, and frame fit sets the height and turns hugHeight on.",
|
|
37998
38244
|
"Frames sort by order, then name, and a write that changes order renumbers the page from 0.",
|
|
37999
38245
|
`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, and frame add persists that box.`,
|
|
38000
38246
|
"An entry with no frame file beside it is ignored on read and kept on write.",
|
|
@@ -38255,7 +38501,7 @@ function registerFrame(program, context) {
|
|
|
38255
38501
|
data: record,
|
|
38256
38502
|
human: `${what} ${record.ref}`
|
|
38257
38503
|
});
|
|
38258
|
-
act(withPosition(withSize(verb("add", "Place a frame, writing a skeleton file when none exists.
|
|
38504
|
+
act(withPosition(withSize(verb("add", "Place a frame past every frame, writing a skeleton file when none exists. Each axis no size names hugs its content, so a preset or --width fixes the width and the height hugs."))), context, async ([ref = ""], options) => done(await addFrame(await boardOf(options, io), ref, {
|
|
38259
38505
|
...options,
|
|
38260
38506
|
cwd: io.cwd
|
|
38261
38507
|
}), "Added"));
|
|
@@ -38267,11 +38513,11 @@ function registerFrame(program, context) {
|
|
|
38267
38513
|
...options,
|
|
38268
38514
|
cwd: io.cwd
|
|
38269
38515
|
}), "Moved to"));
|
|
38270
|
-
act(withSize(verb("resize", "Set a frame size")), context, async ([ref = ""], options) => done(await resizeFrame(await boardOf(options, io), ref, {
|
|
38516
|
+
act(withSize(verb("resize", "Set a frame size, fixing each axis it sets")), context, async ([ref = ""], options) => done(await resizeFrame(await boardOf(options, io), ref, {
|
|
38271
38517
|
...options,
|
|
38272
38518
|
cwd: io.cwd
|
|
38273
38519
|
}), "Resized"));
|
|
38274
|
-
act(verb("fit", "Set a frame height to its content's own height, reporting a width too wide for the frame"), context, async ([ref = ""], options) => {
|
|
38520
|
+
act(verb("fit", "Set a frame height to its content's own height and hug it from then on, reporting a width too wide for the frame"), context, async ([ref = ""], options) => {
|
|
38275
38521
|
const root = await boardOf(options, io);
|
|
38276
38522
|
const refOptions = {
|
|
38277
38523
|
project: options.project,
|
|
@@ -42643,13 +42889,15 @@ const DEPARTED_BATCHES = 4;
|
|
|
42643
42889
|
* agent's, diffed against the source it held. Every caller runs in the
|
|
42644
42890
|
* server's scan turn, since `own` and a batch reading one frame would race.
|
|
42645
42891
|
*/
|
|
42646
|
-
function createChangeTracker(root, { now = () => /* @__PURE__ */ new Date() } = {}) {
|
|
42892
|
+
function createChangeTracker(root, { now = () => /* @__PURE__ */ new Date(), logCap = 200 } = {}) {
|
|
42647
42893
|
const held = /* @__PURE__ */ new Map();
|
|
42648
42894
|
/** Hashes of frames that left the board, with the batch they left in. */
|
|
42649
42895
|
const departed = /* @__PURE__ */ new Map();
|
|
42650
42896
|
const changes = [];
|
|
42651
42897
|
/** Changes a batch found that `own` may still withdraw, by id. */
|
|
42652
42898
|
const pending = /* @__PURE__ */ new Map();
|
|
42899
|
+
/** The sources agent writes replaced, by `versionKey`, in memory alone. */
|
|
42900
|
+
const versions = /* @__PURE__ */ new Map();
|
|
42653
42901
|
let batches = 0;
|
|
42654
42902
|
let nextId = 1;
|
|
42655
42903
|
const read = async (path) => {
|
|
@@ -42717,6 +42965,7 @@ function createChangeTracker(root, { now = () => /* @__PURE__ */ new Date() } =
|
|
|
42717
42965
|
}
|
|
42718
42966
|
const diff = changedElements(before?.source ?? "", file.source);
|
|
42719
42967
|
const claim = claims.find((entry) => entry.frame === ref);
|
|
42968
|
+
if (before) versions.set(versionKey(ref, before.hash), before.source);
|
|
42720
42969
|
found.push({
|
|
42721
42970
|
id: `c${nextId++}`,
|
|
42722
42971
|
frame: ref,
|
|
@@ -42730,7 +42979,8 @@ function createChangeTracker(root, { now = () => /* @__PURE__ */ new Date() } =
|
|
|
42730
42979
|
elements: diff.elements,
|
|
42731
42980
|
removed: diff.removed,
|
|
42732
42981
|
whole: !before || diff.whole,
|
|
42733
|
-
created: !before
|
|
42982
|
+
created: !before,
|
|
42983
|
+
...before ? { before: before.hash } : {}
|
|
42734
42984
|
});
|
|
42735
42985
|
}
|
|
42736
42986
|
for (const change of found) pending.set(change.id, change);
|
|
@@ -42739,12 +42989,18 @@ function createChangeTracker(root, { now = () => /* @__PURE__ */ new Date() } =
|
|
|
42739
42989
|
settle: (held) => {
|
|
42740
42990
|
const kept = held.filter((change) => pending.delete(change.id));
|
|
42741
42991
|
changes.push(...kept);
|
|
42742
|
-
if (changes.length >
|
|
42992
|
+
if (changes.length > logCap) changes.splice(0, changes.length - logCap);
|
|
42993
|
+
const named = new Set([...changes, ...pending.values()].flatMap((change) => change.before ? [versionKey(change.frame, change.before)] : []));
|
|
42994
|
+
for (const key of versions.keys()) if (!named.has(key)) versions.delete(key);
|
|
42743
42995
|
return kept;
|
|
42744
42996
|
},
|
|
42745
|
-
log: () => [...changes]
|
|
42997
|
+
log: () => [...changes],
|
|
42998
|
+
version: (ref, hash) => versions.get(versionKey(ref, hash)) ?? null
|
|
42746
42999
|
};
|
|
42747
43000
|
}
|
|
43001
|
+
function versionKey(ref, hash) {
|
|
43002
|
+
return `${ref}\n${hash}`;
|
|
43003
|
+
}
|
|
42748
43004
|
/** The files and folders a step wrote, being every rewrite, creation, removal, and move. */
|
|
42749
43005
|
function writtenPaths(step) {
|
|
42750
43006
|
return step.changes.flatMap((change) => {
|
|
@@ -42918,8 +43174,8 @@ const UNREADABLE = /* @__PURE__ */ new Set(["layout-invalid", "project-file-inva
|
|
|
42918
43174
|
async function reads(change, side) {
|
|
42919
43175
|
switch (change.kind) {
|
|
42920
43176
|
case "entry": {
|
|
42921
|
-
const
|
|
42922
|
-
return isDeepStrictEqual(
|
|
43177
|
+
const stored = (await readRecord(change.layout, layoutSpec)).frames[change.frame];
|
|
43178
|
+
return isDeepStrictEqual(stored, withMeasured(change[side], stored));
|
|
42923
43179
|
}
|
|
42924
43180
|
case "pages": {
|
|
42925
43181
|
const file = await readRecord(change.file, {
|
|
@@ -42936,6 +43192,20 @@ async function reads(change, side) {
|
|
|
42936
43192
|
case "element": return await exists(change.path) && holdsSpan(await readFile(change.path, "utf8"), change.span, side);
|
|
42937
43193
|
}
|
|
42938
43194
|
}
|
|
43195
|
+
/**
|
|
43196
|
+
* The entry a step holds, taking the stored size on each axis both it and the
|
|
43197
|
+
* stored entry hug, since the server measures that size and the developer
|
|
43198
|
+
* never set it, so a measure after a hand move neither overtakes the step nor
|
|
43199
|
+
* is reverted by it.
|
|
43200
|
+
*/
|
|
43201
|
+
function withMeasured(entry, stored) {
|
|
43202
|
+
if (!entry || !stored) return entry;
|
|
43203
|
+
return {
|
|
43204
|
+
...entry,
|
|
43205
|
+
...entry.hugWidth && stored.hugWidth ? { width: stored.width } : {},
|
|
43206
|
+
...entry.hugHeight && stored.hugHeight ? { height: stored.height } : {}
|
|
43207
|
+
};
|
|
43208
|
+
}
|
|
42939
43209
|
const OTHER = {
|
|
42940
43210
|
before: "after",
|
|
42941
43211
|
after: "before"
|
|
@@ -42950,7 +43220,7 @@ async function restore(change, side) {
|
|
|
42950
43220
|
case "entry": {
|
|
42951
43221
|
const file = await readRecord(change.layout, layoutSpec);
|
|
42952
43222
|
const frames = { ...file.frames };
|
|
42953
|
-
const entry = change[side];
|
|
43223
|
+
const entry = withMeasured(change[side], frames[change.frame]);
|
|
42954
43224
|
if (entry) frames[change.frame] = entry;
|
|
42955
43225
|
else delete frames[change.frame];
|
|
42956
43226
|
await writeRecord(change.layout, {
|
|
@@ -45229,6 +45499,90 @@ function send(socket, message) {
|
|
|
45229
45499
|
if (socket.readyState === socket.OPEN) socket.send(JSON.stringify(message));
|
|
45230
45500
|
}
|
|
45231
45501
|
//#endregion
|
|
45502
|
+
//#region src/server/live/hug.ts
|
|
45503
|
+
/**
|
|
45504
|
+
* The server's hug step. A frame hugs when either flag is on, and its sizes
|
|
45505
|
+
* are written through `setMeasured`, which takes the page's lock, writes
|
|
45506
|
+
* only the axes the stored entry still hugs, and records no undo step. A
|
|
45507
|
+
* frame whose content sizes itself off the viewport, whose body is empty,
|
|
45508
|
+
* or that fails to load keeps its box, and a browser that cannot launch
|
|
45509
|
+
* writes nothing at all.
|
|
45510
|
+
*/
|
|
45511
|
+
function createHug({ root, measure }) {
|
|
45512
|
+
let queue = Promise.resolve();
|
|
45513
|
+
let closed = false;
|
|
45514
|
+
const run = async (board, refs) => {
|
|
45515
|
+
const pages = /* @__PURE__ */ new Map();
|
|
45516
|
+
for (const frame of huggingFrames(board, refs)) {
|
|
45517
|
+
if (closed) return false;
|
|
45518
|
+
let size;
|
|
45519
|
+
try {
|
|
45520
|
+
size = await measure(frame);
|
|
45521
|
+
} catch (error) {
|
|
45522
|
+
if (error instanceof FrameboardError && error.code === "browser-not-found") break;
|
|
45523
|
+
continue;
|
|
45524
|
+
}
|
|
45525
|
+
if (size.empty) continue;
|
|
45526
|
+
const page = `${frame.project}/${frame.page}`;
|
|
45527
|
+
pages.set(page, {
|
|
45528
|
+
...pages.get(page),
|
|
45529
|
+
[frame.name]: size
|
|
45530
|
+
});
|
|
45531
|
+
}
|
|
45532
|
+
let written = false;
|
|
45533
|
+
for (const [page, sizes] of pages) {
|
|
45534
|
+
if (closed) break;
|
|
45535
|
+
try {
|
|
45536
|
+
const names = await setMeasured(root, page, sizes, { cwd: root });
|
|
45537
|
+
written ||= names.length > 0;
|
|
45538
|
+
} catch (error) {
|
|
45539
|
+
if (!(error instanceof FrameboardError)) throw error;
|
|
45540
|
+
}
|
|
45541
|
+
}
|
|
45542
|
+
return written;
|
|
45543
|
+
};
|
|
45544
|
+
return {
|
|
45545
|
+
now: (board, refs) => run(board, refs),
|
|
45546
|
+
later: (board, refs) => {
|
|
45547
|
+
if (closed || huggingFrames(board, refs).length === 0) return;
|
|
45548
|
+
queue = queue.then(() => run(board, refs)).catch(() => {});
|
|
45549
|
+
},
|
|
45550
|
+
close: () => {
|
|
45551
|
+
closed = true;
|
|
45552
|
+
}
|
|
45553
|
+
};
|
|
45554
|
+
}
|
|
45555
|
+
function huggingFrames(board, refs) {
|
|
45556
|
+
const wanted = new Set(refs);
|
|
45557
|
+
return board.projects.flatMap((project) => project.pages).flatMap((page) => page.frames).filter((frame) => wanted.has(frame.ref) && frame.placed && (frame.hugWidth || frame.hugHeight));
|
|
45558
|
+
}
|
|
45559
|
+
/**
|
|
45560
|
+
* The hugging frames whose file was written after their page's `layout.json`,
|
|
45561
|
+
* as one edited while no server ran, which the start sweep measures before
|
|
45562
|
+
* the first board goes out. Every other frame's stored size already holds.
|
|
45563
|
+
*/
|
|
45564
|
+
async function writtenSinceLayout(board) {
|
|
45565
|
+
const pages = board.projects.flatMap((project) => project.pages);
|
|
45566
|
+
return (await Promise.all(pages.map(async (page) => {
|
|
45567
|
+
const hugging = page.frames.filter((frame) => frame.placed && (frame.hugWidth || frame.hugHeight));
|
|
45568
|
+
if (hugging.length === 0) return [];
|
|
45569
|
+
const layout = await mtimeOf(join(page.path, LAYOUT_FILE));
|
|
45570
|
+
return hugging.filter((frame) => Date.parse(frame.modifiedAt) > layout).map((frame) => frame.ref);
|
|
45571
|
+
}))).flat();
|
|
45572
|
+
}
|
|
45573
|
+
async function mtimeOf(path) {
|
|
45574
|
+
try {
|
|
45575
|
+
return (await stat$1(path)).mtimeMs;
|
|
45576
|
+
} catch {
|
|
45577
|
+
return 0;
|
|
45578
|
+
}
|
|
45579
|
+
}
|
|
45580
|
+
/** The frames a batch reloads through their own file, as against an asset or a token sheet. */
|
|
45581
|
+
function ownFileRefs(board, paths) {
|
|
45582
|
+
const written = new Set(paths);
|
|
45583
|
+
return board.projects.flatMap((project) => project.pages).flatMap((page) => page.frames).filter((frame) => written.has(frame.path)).map((frame) => frame.ref);
|
|
45584
|
+
}
|
|
45585
|
+
//#endregion
|
|
45232
45586
|
//#region src/server/live/rendered-findings.ts
|
|
45233
45587
|
/**
|
|
45234
45588
|
* The server's warm checker. Rechecks run one at a time on their own queue,
|
|
@@ -45271,7 +45625,7 @@ function createRenderedFindings({ check, onResult }) {
|
|
|
45271
45625
|
check(frame).then((findings) => {
|
|
45272
45626
|
const recovered = failure !== null;
|
|
45273
45627
|
failure = null;
|
|
45274
|
-
if (current()) onResult(ref, findings);
|
|
45628
|
+
if (findings && current()) onResult(ref, findings);
|
|
45275
45629
|
if (!recovered) return;
|
|
45276
45630
|
for (const [other, record] of known) if (other !== ref && !pending.has(other)) enqueue(other, record);
|
|
45277
45631
|
}).catch((error) => {
|
|
@@ -45592,18 +45946,21 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45592
45946
|
});
|
|
45593
45947
|
await thumbnails.empty();
|
|
45594
45948
|
const rendered = createRenderedFindings({
|
|
45595
|
-
check: async (frame) =>
|
|
45596
|
-
|
|
45597
|
-
|
|
45598
|
-
|
|
45599
|
-
|
|
45600
|
-
|
|
45601
|
-
|
|
45602
|
-
|
|
45603
|
-
|
|
45604
|
-
|
|
45605
|
-
|
|
45606
|
-
|
|
45949
|
+
check: async (frame) => {
|
|
45950
|
+
const list = await checkRendered(await browser.get(), {
|
|
45951
|
+
baseUrl: baseUrl(),
|
|
45952
|
+
frame: {
|
|
45953
|
+
ref: frame.ref,
|
|
45954
|
+
path: boardPath(root, frame.path),
|
|
45955
|
+
box: {
|
|
45956
|
+
width: frame.box.width,
|
|
45957
|
+
height: frame.box.height
|
|
45958
|
+
}
|
|
45959
|
+
},
|
|
45960
|
+
config: readConfig(root, frame.project)
|
|
45961
|
+
});
|
|
45962
|
+
return await modifiedAt(frame.path) === frame.modifiedAt ? list : null;
|
|
45963
|
+
},
|
|
45607
45964
|
onResult: (ref, list) => {
|
|
45608
45965
|
const before = findings.rendered([ref])[ref];
|
|
45609
45966
|
if (JSON.stringify(before) === JSON.stringify(list)) return;
|
|
@@ -45614,6 +45971,17 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45614
45971
|
});
|
|
45615
45972
|
}
|
|
45616
45973
|
});
|
|
45974
|
+
const measure = async (frame) => measureContent(await browser.get(), {
|
|
45975
|
+
baseUrl: baseUrl(),
|
|
45976
|
+
ref: frame.ref,
|
|
45977
|
+
box: frame.box,
|
|
45978
|
+
hugWidth: frame.hugWidth,
|
|
45979
|
+
fonts: "wait"
|
|
45980
|
+
});
|
|
45981
|
+
const hug = createHug({
|
|
45982
|
+
root,
|
|
45983
|
+
measure
|
|
45984
|
+
});
|
|
45617
45985
|
const app = createApp({
|
|
45618
45986
|
clientDir,
|
|
45619
45987
|
facesDir,
|
|
@@ -45626,6 +45994,8 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45626
45994
|
selection,
|
|
45627
45995
|
renderFrame,
|
|
45628
45996
|
thumbnails,
|
|
45997
|
+
measure,
|
|
45998
|
+
frameVersion: tracker.version,
|
|
45629
45999
|
checks: {
|
|
45630
46000
|
refresh: () => inTurn(async () => {
|
|
45631
46001
|
try {
|
|
@@ -45666,10 +46036,13 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45666
46036
|
});
|
|
45667
46037
|
server.on("upgrade", hub.handleUpgrade);
|
|
45668
46038
|
inTurn(async () => {
|
|
45669
|
-
|
|
46039
|
+
let board = await scanBoard(root);
|
|
46040
|
+
const stale = await writtenSinceLayout(board).catch(() => []);
|
|
46041
|
+
if (await hug.now(board, stale).catch(() => false)) board = await scanBoard(root);
|
|
45670
46042
|
await tracker.prime(board);
|
|
45671
46043
|
findings.update(board, "all");
|
|
45672
46044
|
rendered.queue(board, []);
|
|
46045
|
+
hug.later(board, board.projects.flatMap((project) => project.pages.flatMap((page) => page.frames.map((frame) => frame.ref).filter((ref) => !stale.includes(ref)))));
|
|
45673
46046
|
});
|
|
45674
46047
|
claims.push();
|
|
45675
46048
|
const watcher = await watchBoard(root, tokens ? [tokens] : []);
|
|
@@ -45685,6 +46058,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45685
46058
|
tracker,
|
|
45686
46059
|
claims,
|
|
45687
46060
|
thumbnails,
|
|
46061
|
+
hug,
|
|
45688
46062
|
settleLater
|
|
45689
46063
|
}));
|
|
45690
46064
|
});
|
|
@@ -45699,6 +46073,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45699
46073
|
boardUrl,
|
|
45700
46074
|
close: async () => {
|
|
45701
46075
|
rendered.close();
|
|
46076
|
+
hug.close();
|
|
45702
46077
|
claims.close();
|
|
45703
46078
|
for (const timer of settling) clearTimeout(timer);
|
|
45704
46079
|
await Promise.all([
|
|
@@ -45722,10 +46097,13 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
45722
46097
|
* notes or frames it touched, whose queue it offers to delivery. The frames
|
|
45723
46098
|
* an agent changed wait out the grace before the board hears of them.
|
|
45724
46099
|
*/
|
|
45725
|
-
async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, settleLater }) {
|
|
46100
|
+
async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, hug, settleLater }) {
|
|
45726
46101
|
let board;
|
|
46102
|
+
let own;
|
|
45727
46103
|
try {
|
|
45728
46104
|
board = await scanBoard(root);
|
|
46105
|
+
own = ownFileRefs(board, paths);
|
|
46106
|
+
if (await hug.now(board, own).catch(() => false)) board = await scanBoard(root);
|
|
45729
46107
|
} catch {
|
|
45730
46108
|
return;
|
|
45731
46109
|
}
|
|
@@ -45734,6 +46112,7 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
|
|
|
45734
46112
|
data: board
|
|
45735
46113
|
});
|
|
45736
46114
|
const refs = reloadRefs(root, paths, board, tokens);
|
|
46115
|
+
hug.later(board, refs.filter((ref) => !own.includes(ref)));
|
|
45737
46116
|
if (refs.length > 0) {
|
|
45738
46117
|
hub.broadcast({
|
|
45739
46118
|
type: "reload",
|
|
@@ -45757,6 +46136,13 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
|
|
|
45757
46136
|
rendered.queue(board, recheckRefs(root, paths, board, tokens));
|
|
45758
46137
|
await pushNotes(root, paths, hub, delivery);
|
|
45759
46138
|
}
|
|
46139
|
+
async function modifiedAt(path) {
|
|
46140
|
+
try {
|
|
46141
|
+
return new Date((await stat$1(path)).mtimeMs).toISOString();
|
|
46142
|
+
} catch {
|
|
46143
|
+
return null;
|
|
46144
|
+
}
|
|
46145
|
+
}
|
|
45760
46146
|
/**
|
|
45761
46147
|
* A notes write changes its page's notes, and a frame write can lose an
|
|
45762
46148
|
* element note its anchor, so both reread the page. A frame write on a page
|
|
@@ -45799,10 +46185,15 @@ const DEFAULT_PORT = 4173;
|
|
|
45799
46185
|
/** How long a fresh server waits for a writing board tab left open by its predecessor to reconnect. */
|
|
45800
46186
|
const RECONNECT_WAIT_MS = 1e3;
|
|
45801
46187
|
function registerServe(program, context) {
|
|
45802
|
-
const { io
|
|
46188
|
+
const { io } = context;
|
|
45803
46189
|
act(addVerb(program, "serve", "Serve the board in a local browser").option("-p, --port <port>", "port to listen on, falling back to a free one when the default is taken", parsePort, DEFAULT_PORT).option("--no-open", "leave the browser alone").option("--tokens <path>", "a token sheet another tool manages, standing in for the board's tokens.css"), context, async (_args, options, self) => {
|
|
45804
46190
|
const tokens = options.tokens === void 0 ? void 0 : resolve(io.cwd, options.tokens);
|
|
45805
46191
|
if (tokens !== void 0 && !isFile(tokens)) throw new FrameboardError("tokens-not-found", `No token sheet at ${tokens}.`, { tokens });
|
|
46192
|
+
const existing = await resolveBoard({
|
|
46193
|
+
root: options.root,
|
|
46194
|
+
cwd: io.cwd
|
|
46195
|
+
}).catch(() => null);
|
|
46196
|
+
if (existing === null || await findLiveServer(existing) === null) context.clientDir;
|
|
45806
46197
|
const { root, created } = await startBoard({
|
|
45807
46198
|
root: options.root,
|
|
45808
46199
|
cwd: io.cwd
|
|
@@ -45825,7 +46216,7 @@ function registerServe(program, context) {
|
|
|
45825
46216
|
};
|
|
45826
46217
|
}
|
|
45827
46218
|
const server = await startServer({
|
|
45828
|
-
clientDir,
|
|
46219
|
+
clientDir: context.clientDir,
|
|
45829
46220
|
facesDir: context.facesDir,
|
|
45830
46221
|
root,
|
|
45831
46222
|
tokens,
|
|
@@ -45954,7 +46345,6 @@ function resolveFacesDir(moduleUrl = import.meta.url) {
|
|
|
45954
46345
|
}
|
|
45955
46346
|
//#endregion
|
|
45956
46347
|
//#region src/cli/program.ts
|
|
45957
|
-
const CLIENT_DIR = fileURLToPath(new URL("./client", import.meta.url));
|
|
45958
46348
|
function parsePort(value) {
|
|
45959
46349
|
const port = /^\d+$/.test(value) ? Number(value) : NaN;
|
|
45960
46350
|
if (!(port >= 0 && port <= 65535)) throw new InvalidArgumentError("Expected a port between 0 and 65535.");
|
|
@@ -46002,9 +46392,12 @@ function createProgram(context) {
|
|
|
46002
46392
|
writeErr: (text) => json ? void 0 : io.stderr(text)
|
|
46003
46393
|
});
|
|
46004
46394
|
let facesDir;
|
|
46395
|
+
let clientDir;
|
|
46005
46396
|
const faced = {
|
|
46006
46397
|
...context,
|
|
46007
|
-
|
|
46398
|
+
get clientDir() {
|
|
46399
|
+
return clientDir ??= resolveClientDir(import.meta.url, context.clientDir);
|
|
46400
|
+
},
|
|
46008
46401
|
get facesDir() {
|
|
46009
46402
|
return facesDir ??= context.facesDir ?? resolveFacesDir();
|
|
46010
46403
|
}
|