frameboard 0.32.0 → 0.33.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 +1052 -75
- package/dist/client/assets/index-BCp8Pf26.css +2 -0
- package/dist/client/assets/index-BYey1Kmq.js +123 -0
- package/dist/client/index.html +2 -2
- package/package.json +1 -1
- package/dist/client/assets/index-B3-XL1cU.js +0 -115
- package/dist/client/assets/index-D_ZnMRyk.css +0 -2
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ import { fileURLToPath, pathToFileURL } 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";
|
|
17
|
-
import { homedir, release, tmpdir, type } from "node:os";
|
|
17
|
+
import { homedir, networkInterfaces, release, tmpdir, type } from "node:os";
|
|
18
18
|
// \0rolldown/runtime.js
|
|
19
19
|
var __create = Object.create;
|
|
20
20
|
var __defProp = Object.defineProperty;
|
|
@@ -3058,7 +3058,8 @@ const EXIT_CODES = {
|
|
|
3058
3058
|
"page-file-load": 10,
|
|
3059
3059
|
"image-missing": 10,
|
|
3060
3060
|
"motion-missing": 10,
|
|
3061
|
-
"motion-unbounded": 10
|
|
3061
|
+
"motion-unbounded": 10,
|
|
3062
|
+
"no-network-address": 3
|
|
3062
3063
|
};
|
|
3063
3064
|
var FrameboardError = class extends Error {
|
|
3064
3065
|
code;
|
|
@@ -9079,6 +9080,87 @@ function superRefine(fn, params) {
|
|
|
9079
9080
|
function datetime(params) {
|
|
9080
9081
|
return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
|
|
9081
9082
|
}
|
|
9083
|
+
// src/shared/frame-device.ts
|
|
9084
|
+
/** The devices the board can draw around a frame. */
|
|
9085
|
+
const DEVICES = ["phone", "tablet"];
|
|
9086
|
+
/**
|
|
9087
|
+
* The phone's border is a current Pro's body less its display, 71.9 mm
|
|
9088
|
+
* across holding 1206 pixels at 460 ppi, which is 16 points a side. The
|
|
9089
|
+
* tablet's is a 13-inch Pro's, 215.5 mm across holding 2064 pixels at 264
|
|
9090
|
+
* ppi, which is 44. The tablet's screen radius is a guess no source backs.
|
|
9091
|
+
*/
|
|
9092
|
+
const BEZELS = {
|
|
9093
|
+
phone: {
|
|
9094
|
+
border: 16,
|
|
9095
|
+
screenRadius: 62,
|
|
9096
|
+
bodyRadius: 78
|
|
9097
|
+
},
|
|
9098
|
+
tablet: {
|
|
9099
|
+
border: 44,
|
|
9100
|
+
screenRadius: 18,
|
|
9101
|
+
bodyRadius: 62
|
|
9102
|
+
}
|
|
9103
|
+
};
|
|
9104
|
+
/**
|
|
9105
|
+
* The body's colors, fixed in both themes, since the board draws hardware
|
|
9106
|
+
* rather than chrome: the body, the hairline around it, and the island.
|
|
9107
|
+
*/
|
|
9108
|
+
const BEZEL_COLORS = {
|
|
9109
|
+
body: "#17181b",
|
|
9110
|
+
edge: "#45484f",
|
|
9111
|
+
island: "#050506",
|
|
9112
|
+
homeBar: "rgba(128, 128, 128, 0.6)"
|
|
9113
|
+
};
|
|
9114
|
+
/**
|
|
9115
|
+
* The phone's island, a generic pill standing in for a size no source gives,
|
|
9116
|
+
* and the home bar, each centered on the screen and drawn over the frame.
|
|
9117
|
+
*/
|
|
9118
|
+
const PHONE_ISLAND = {
|
|
9119
|
+
width: 81,
|
|
9120
|
+
height: 30,
|
|
9121
|
+
top: 14
|
|
9122
|
+
};
|
|
9123
|
+
const HOME_BAR = {
|
|
9124
|
+
width: 140,
|
|
9125
|
+
height: 5,
|
|
9126
|
+
bottom: 8
|
|
9127
|
+
};
|
|
9128
|
+
/**
|
|
9129
|
+
* The CSS `box-shadow` drawing a device's body: a spread the border wide
|
|
9130
|
+
* around a box rounded to the screen radius, which also covers the frame's
|
|
9131
|
+
* corners past that radius, so the body's outer radius is the screen's plus
|
|
9132
|
+
* the border. On the board a hairline edge one screen pixel wide rings it at
|
|
9133
|
+
* any zoom, so a dark body still reads on a dark canvas, under a drop shadow.
|
|
9134
|
+
* The export keeps the body to the border, its last pixel the edge, and
|
|
9135
|
+
* leaves out the drop shadow, which would fall past the PNG's edge.
|
|
9136
|
+
*/
|
|
9137
|
+
function bezelShadow(device, { board = true } = {}) {
|
|
9138
|
+
const { border } = BEZELS[device];
|
|
9139
|
+
if (!board) return [`0 0 0 ${border - 1}px ${BEZEL_COLORS.body}`, `0 0 0 ${border}px ${BEZEL_COLORS.edge}`].join(", ");
|
|
9140
|
+
return [
|
|
9141
|
+
`0 0 0 ${border}px ${BEZEL_COLORS.body}`,
|
|
9142
|
+
`0 0 0 calc(${border}px + 1px / var(--zoom, 1)) ${BEZEL_COLORS.edge}`,
|
|
9143
|
+
`0 ${border}px ${border * 3}px rgba(0, 0, 0, 0.3)`
|
|
9144
|
+
].join(", ");
|
|
9145
|
+
}
|
|
9146
|
+
/**
|
|
9147
|
+
* A layout entry's `device` value, or null for anything but a known device,
|
|
9148
|
+
* so a value no reader understands reads as a frame with no device.
|
|
9149
|
+
*/
|
|
9150
|
+
function deviceOf(value) {
|
|
9151
|
+
return DEVICES.find((device) => device === value) ?? null;
|
|
9152
|
+
}
|
|
9153
|
+
/** The box a device's body covers around a frame's box, the box itself with none. */
|
|
9154
|
+
function bezelBox(box, device) {
|
|
9155
|
+
if (!device) return { ...box };
|
|
9156
|
+
const { border } = BEZELS[device];
|
|
9157
|
+
return {
|
|
9158
|
+
x: box.x - border,
|
|
9159
|
+
y: box.y - border,
|
|
9160
|
+
width: box.width + 2 * border,
|
|
9161
|
+
height: box.height + 2 * border
|
|
9162
|
+
};
|
|
9163
|
+
}
|
|
9082
9164
|
// src/shared/frame-sizes.ts
|
|
9083
9165
|
/** The current iPhone, iPad Air portrait, and a common laptop viewport. */
|
|
9084
9166
|
const FRAME_SIZES = {
|
|
@@ -9134,6 +9216,13 @@ const DEVICE_SIZES = [
|
|
|
9134
9216
|
width: 393,
|
|
9135
9217
|
height: 852
|
|
9136
9218
|
},
|
|
9219
|
+
{
|
|
9220
|
+
name: "iphone-18-pro",
|
|
9221
|
+
label: "iPhone 18 Pro",
|
|
9222
|
+
group: "phone",
|
|
9223
|
+
width: 402,
|
|
9224
|
+
height: 874
|
|
9225
|
+
},
|
|
9137
9226
|
{
|
|
9138
9227
|
name: "android",
|
|
9139
9228
|
label: "Android",
|
|
@@ -9298,16 +9387,21 @@ function linkedBoxes(box, widths) {
|
|
|
9298
9387
|
}
|
|
9299
9388
|
return boxes;
|
|
9300
9389
|
}
|
|
9301
|
-
/**
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9390
|
+
/**
|
|
9391
|
+
* The box holding a frame, the device body drawn around it, and every linked
|
|
9392
|
+
* width it draws, the frame's own with neither. Linked widths draw no device.
|
|
9393
|
+
*/
|
|
9394
|
+
function drawnExtent(box, widths, device) {
|
|
9395
|
+
const boxes = [bezelBox(box, device), ...linkedBoxes(box, widths)];
|
|
9396
|
+
const left = Math.min(...boxes.map(({ x }) => x));
|
|
9397
|
+
const top = Math.min(...boxes.map(({ y }) => y));
|
|
9398
|
+
const right = Math.max(...boxes.map(({ x, width }) => x + width));
|
|
9399
|
+
const bottom = Math.max(...boxes.map(({ y, height }) => y + height));
|
|
9306
9400
|
return {
|
|
9307
|
-
x:
|
|
9308
|
-
y:
|
|
9309
|
-
width:
|
|
9310
|
-
height:
|
|
9401
|
+
x: left,
|
|
9402
|
+
y: top,
|
|
9403
|
+
width: right - left,
|
|
9404
|
+
height: bottom - top
|
|
9311
9405
|
};
|
|
9312
9406
|
}
|
|
9313
9407
|
// src/shared/records/board.ts
|
|
@@ -9343,7 +9437,8 @@ const layoutEntrySchema = looseObject({
|
|
|
9343
9437
|
widths: union([array$1(looseObject({
|
|
9344
9438
|
width: int$1().min(1),
|
|
9345
9439
|
height: int$1().min(1)
|
|
9346
|
-
})), unknown()]).optional()
|
|
9440
|
+
})), unknown()]).optional(),
|
|
9441
|
+
device: unknown().optional()
|
|
9347
9442
|
});
|
|
9348
9443
|
/** A named box grouping the frames whose center it holds, which it never lists. */
|
|
9349
9444
|
const sectionEntrySchema = looseObject({
|
|
@@ -9474,6 +9569,7 @@ function placeFrames(frames, names) {
|
|
|
9474
9569
|
continue;
|
|
9475
9570
|
}
|
|
9476
9571
|
const scroll = entry.scroll ?? false;
|
|
9572
|
+
const device = deviceOf(entry.device);
|
|
9477
9573
|
placements.set(name, {
|
|
9478
9574
|
box: {
|
|
9479
9575
|
x: entry.x,
|
|
@@ -9488,6 +9584,7 @@ function placeFrames(frames, names) {
|
|
|
9488
9584
|
hugHeight: !scroll && (entry.hugHeight ?? false),
|
|
9489
9585
|
scroll,
|
|
9490
9586
|
widths: widthsOf(entry.widths),
|
|
9587
|
+
...device ? { device } : {},
|
|
9491
9588
|
placed: true
|
|
9492
9589
|
});
|
|
9493
9590
|
}
|
|
@@ -9506,8 +9603,8 @@ function placeFrames(frames, names) {
|
|
|
9506
9603
|
* the first unplaced file, placing any other past the placed frames alone.
|
|
9507
9604
|
*/
|
|
9508
9605
|
function placeNext(placed) {
|
|
9509
|
-
const right = Math.max(...placed.map(({ box, widths }) => {
|
|
9510
|
-
const extent = drawnExtent(box, widths);
|
|
9606
|
+
const right = Math.max(...placed.map(({ box, widths, device }) => {
|
|
9607
|
+
const extent = drawnExtent(box, widths, device);
|
|
9511
9608
|
return extent.x + extent.width + 80;
|
|
9512
9609
|
}), 0);
|
|
9513
9610
|
const order = Math.max(...placed.map((placement) => placement.order + 1), 0);
|
|
@@ -9692,7 +9789,7 @@ async function isDirectory(path) {
|
|
|
9692
9789
|
}
|
|
9693
9790
|
}
|
|
9694
9791
|
// package.json
|
|
9695
|
-
var version$1 = "0.
|
|
9792
|
+
var version$1 = "0.33.0";
|
|
9696
9793
|
var dependencies = { "playwright-core": "1.65.0" };
|
|
9697
9794
|
var peerDependencies = { "oxfmt": "0.77.0" };
|
|
9698
9795
|
// src/shared/version.ts
|
|
@@ -10206,7 +10303,8 @@ async function addFrame(root, ref, options) {
|
|
|
10206
10303
|
},
|
|
10207
10304
|
...hugs,
|
|
10208
10305
|
scroll,
|
|
10209
|
-
widths
|
|
10306
|
+
widths,
|
|
10307
|
+
...options.device ? { device: options.device } : {}
|
|
10210
10308
|
});
|
|
10211
10309
|
layout.renumber();
|
|
10212
10310
|
}, journal);
|
|
@@ -10372,9 +10470,9 @@ function linkedWidths(ref, requested, { width, hugWidth, held }) {
|
|
|
10372
10470
|
height: held.find((each) => each.width === linked)?.height ?? referenceHeight(linked)
|
|
10373
10471
|
}));
|
|
10374
10472
|
}
|
|
10375
|
-
/** The x a copy placed beside a frame takes, past the row of linked widths it draws. */
|
|
10376
|
-
function pastExtent({ box, widths }) {
|
|
10377
|
-
const extent = drawnExtent(box, widths);
|
|
10473
|
+
/** The x a copy placed beside a frame takes, past its device and the row of linked widths it draws. */
|
|
10474
|
+
function pastExtent({ box, widths, device }) {
|
|
10475
|
+
const extent = drawnExtent(box, widths, device);
|
|
10378
10476
|
return extent.x + extent.width + 80;
|
|
10379
10477
|
}
|
|
10380
10478
|
/**
|
|
@@ -10614,6 +10712,20 @@ async function setFrameFlag(root, ref, flag, { on, ...options }) {
|
|
|
10614
10712
|
[flag]: on
|
|
10615
10713
|
}));
|
|
10616
10714
|
}
|
|
10715
|
+
/**
|
|
10716
|
+
* Sets the device the board draws around a frame, or clears it with null.
|
|
10717
|
+
* The frame's file and box are left as they stand, since the bezel wraps
|
|
10718
|
+
* whatever size the frame is.
|
|
10719
|
+
*/
|
|
10720
|
+
async function setFrameDevice(root, ref, device, options) {
|
|
10721
|
+
return updatePlacement(root, ref, options, (placement) => {
|
|
10722
|
+
const { device: _held, ...rest } = placement;
|
|
10723
|
+
return device ? {
|
|
10724
|
+
...rest,
|
|
10725
|
+
device
|
|
10726
|
+
} : rest;
|
|
10727
|
+
});
|
|
10728
|
+
}
|
|
10617
10729
|
async function deleteFrame(root, ref, options) {
|
|
10618
10730
|
const { journal } = options;
|
|
10619
10731
|
const frame = await resolveFrameRef(root, ref, options);
|
|
@@ -10707,9 +10819,11 @@ var PageLayout = class {
|
|
|
10707
10819
|
* written once it is on or when the entry holds it, and a scroll entry
|
|
10708
10820
|
* writes both hug flags false, since it fixes both axes. `widths` is
|
|
10709
10821
|
* written while it lists one and removed once it lists none, and a held
|
|
10710
|
-
* value no reader understands is left as it stands.
|
|
10822
|
+
* value no reader understands is left as it stands. `device` is written
|
|
10823
|
+
* while the frame holds one and removed once it is cleared, leaving a held
|
|
10824
|
+
* value no reader understands as `widths` does.
|
|
10711
10825
|
*/
|
|
10712
|
-
set(name, { box, order, hidden, locked, scroll, widths, hugWidth: hugsWidth, hugHeight: hugsHeight }) {
|
|
10826
|
+
set(name, { box, order, hidden, locked, scroll, widths, device, hugWidth: hugsWidth, hugHeight: hugsHeight }) {
|
|
10713
10827
|
const hugWidth = hugsWidth && !scroll;
|
|
10714
10828
|
const hugHeight = hugsHeight && !scroll;
|
|
10715
10829
|
const held = this.file.frames[name];
|
|
@@ -10728,9 +10842,11 @@ var PageLayout = class {
|
|
|
10728
10842
|
...widths.length > 0 ? { widths: widths.map(({ width, height }) => ({
|
|
10729
10843
|
width,
|
|
10730
10844
|
height
|
|
10731
|
-
})) } : {}
|
|
10845
|
+
})) } : {},
|
|
10846
|
+
...device ? { device } : {}
|
|
10732
10847
|
};
|
|
10733
10848
|
if (widths.length === 0 && widthsOf(held?.widths).length > 0) delete entry.widths;
|
|
10849
|
+
if (!device && deviceOf(held?.device)) delete entry.device;
|
|
10734
10850
|
this.file.frames[name] = entry;
|
|
10735
10851
|
this.changed = true;
|
|
10736
10852
|
}
|
|
@@ -36561,15 +36677,7 @@ function starterSheet({ accent, font }) {
|
|
|
36561
36677
|
}
|
|
36562
36678
|
// src/server/edit/insert.ts
|
|
36563
36679
|
const SHAPE_SIZE = 100;
|
|
36564
|
-
const FILL_TOKENS = [
|
|
36565
|
-
"--muted",
|
|
36566
|
-
"--secondary",
|
|
36567
|
-
"--accent"
|
|
36568
|
-
];
|
|
36569
|
-
const LINE_TOKEN = "--border";
|
|
36570
36680
|
const TEXT_FONT_TOKEN = "--font-text";
|
|
36571
|
-
/** Raw on purpose, so the check names it once the project sets no color token. */
|
|
36572
|
-
const RAW_GREY = "#d9d9d9";
|
|
36573
36681
|
const PAINT_VALUE = /^(?:var\(--[\w-]+\)|#[0-9a-f]{6})$/i;
|
|
36574
36682
|
/** Elements no new element can sit inside, by what the parser does with one there. */
|
|
36575
36683
|
const CLOSED = /* @__PURE__ */ new Set([
|
|
@@ -36597,21 +36705,6 @@ const CLOSED = /* @__PURE__ */ new Set([
|
|
|
36597
36705
|
"head"
|
|
36598
36706
|
]);
|
|
36599
36707
|
/**
|
|
36600
|
-
* A shape's fill, being the first of the muted, secondary, and accent tokens
|
|
36601
|
-
* the project sets, else its first color token, and its line, being the
|
|
36602
|
-
* border token else that first color token. With no color token at all, both
|
|
36603
|
-
* are a raw grey.
|
|
36604
|
-
*/
|
|
36605
|
-
function shapePaint(tokens) {
|
|
36606
|
-
const names = new Set(tokens.map((row) => row.name));
|
|
36607
|
-
const firstColor = tokens.find((row) => row.group === "color")?.name;
|
|
36608
|
-
const paint = (name) => name === void 0 ? RAW_GREY : `var(${name})`;
|
|
36609
|
-
return {
|
|
36610
|
-
fill: paint(FILL_TOKENS.find((name) => names.has(name)) ?? firstColor),
|
|
36611
|
-
line: paint(names.has(LINE_TOKEN) ? LINE_TOKEN : firstColor)
|
|
36612
|
-
};
|
|
36613
|
-
}
|
|
36614
|
-
/**
|
|
36615
36708
|
* The family placed text sets, being the project's text font token, else
|
|
36616
36709
|
* Geist, so a frame with no font of its own still passes `default-font`.
|
|
36617
36710
|
*/
|
|
@@ -37588,8 +37681,11 @@ function editFrameFile(path, address, change, sourceAt) {
|
|
|
37588
37681
|
* Edits several elements of a frame file as one write, each found again and
|
|
37589
37682
|
* verified as `editFrameFile` does one, in the order sent through the bytes
|
|
37590
37683
|
* the one before it left. Any refusal writes nothing, so a batch never lands
|
|
37591
|
-
* in part
|
|
37592
|
-
* put both spans back.
|
|
37684
|
+
* in part. Naming one element twice is refused, since one undo could not
|
|
37685
|
+
* put both spans back, except for a text change beside one style change.
|
|
37686
|
+
* That pair answers one span over the whole element, both changes in it,
|
|
37687
|
+
* since an undo checks every span against the bytes as they stand and the
|
|
37688
|
+
* text's own span no longer reads once the style wrote its start tag.
|
|
37593
37689
|
*/
|
|
37594
37690
|
function editFrameFileAll(path, hash, edits, sourceAt) {
|
|
37595
37691
|
const read = readSource(path);
|
|
@@ -37607,7 +37703,7 @@ function editFrameFileAll(path, hash, edits, sourceAt) {
|
|
|
37607
37703
|
if (!found) return collided(path, was, index, source);
|
|
37608
37704
|
indexes.push(found.index);
|
|
37609
37705
|
}
|
|
37610
|
-
if (
|
|
37706
|
+
if (!namedOnceEach(indexes, edits)) return refuse$2("invalid-edit", "a batch names one element twice");
|
|
37611
37707
|
let html = source;
|
|
37612
37708
|
const spans = [];
|
|
37613
37709
|
for (const [at, { change }] of edits.entries()) {
|
|
@@ -37622,11 +37718,46 @@ function editFrameFileAll(path, hash, edits, sourceAt) {
|
|
|
37622
37718
|
hash: contentHash(html),
|
|
37623
37719
|
from: read.hash,
|
|
37624
37720
|
indexes,
|
|
37625
|
-
spans,
|
|
37721
|
+
spans: mergedTwice(source, html, indexes, spans),
|
|
37626
37722
|
remap: identity
|
|
37627
37723
|
};
|
|
37628
37724
|
}
|
|
37629
37725
|
/**
|
|
37726
|
+
* The spans of a batch with the two of an element named twice put together
|
|
37727
|
+
* as one over the whole element, from its bytes in `source` to its bytes in
|
|
37728
|
+
* `html`, at the place the first of the two held.
|
|
37729
|
+
*/
|
|
37730
|
+
function mergedTwice(source, html, indexes, spans) {
|
|
37731
|
+
const twice = indexes.filter((index, at) => indexes.indexOf(index) !== at);
|
|
37732
|
+
if (twice.length === 0) return [...spans];
|
|
37733
|
+
const was = parseFrame(source).elements;
|
|
37734
|
+
const now = parseFrame(html).elements;
|
|
37735
|
+
return spans.flatMap((span, at) => {
|
|
37736
|
+
const index = indexes[at] ?? -1;
|
|
37737
|
+
if (!twice.includes(index)) return [span];
|
|
37738
|
+
if (indexes.indexOf(index) !== at) return [];
|
|
37739
|
+
const before = was[index];
|
|
37740
|
+
const after = now[index];
|
|
37741
|
+
if (!before || !after) return [span];
|
|
37742
|
+
return [{
|
|
37743
|
+
scope: "element",
|
|
37744
|
+
index,
|
|
37745
|
+
count: now.length,
|
|
37746
|
+
before: spanText(source, before, "element"),
|
|
37747
|
+
after: spanText(html, after, "element")
|
|
37748
|
+
}];
|
|
37749
|
+
});
|
|
37750
|
+
}
|
|
37751
|
+
/**
|
|
37752
|
+
* Whether each element a batch names is named once, or twice only as one
|
|
37753
|
+
* `text` change and one `style` or `styles` change.
|
|
37754
|
+
*/
|
|
37755
|
+
function namedOnceEach(indexes, edits) {
|
|
37756
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
37757
|
+
for (const [at, index] of indexes.entries()) kinds.set(index, [...kinds.get(index) ?? [], edits[at]?.change.kind ?? ""]);
|
|
37758
|
+
return [...kinds.values()].every((named) => named.length === 1 || named.length === 2 && named.filter((kind) => kind === "text").length === 1 && named.some((kind) => kind === "style" || kind === "styles"));
|
|
37759
|
+
}
|
|
37760
|
+
/**
|
|
37630
37761
|
* Writes one new element into a frame file the way `editFrameFile` writes an
|
|
37631
37762
|
* edit, through a temporary file and a rename after reading the file again.
|
|
37632
37763
|
* A hash the file no longer has is refused as stale with no search, since the
|
|
@@ -39371,6 +39502,31 @@ object$1({
|
|
|
39371
39502
|
hash,
|
|
39372
39503
|
count: int$1().min(0)
|
|
39373
39504
|
});
|
|
39505
|
+
// src/shared/shape-paint.ts
|
|
39506
|
+
const FILL_TOKENS = [
|
|
39507
|
+
"--muted",
|
|
39508
|
+
"--secondary",
|
|
39509
|
+
"--accent"
|
|
39510
|
+
];
|
|
39511
|
+
const LINE_TOKEN = "--border";
|
|
39512
|
+
/** Raw on purpose, so the check names it once the project sets no color token. */
|
|
39513
|
+
const RAW_GREY = "#d9d9d9";
|
|
39514
|
+
/**
|
|
39515
|
+
* A shape's fill, being the first of the muted, secondary, and accent tokens
|
|
39516
|
+
* the project sets, else its first color token, and its line, being the
|
|
39517
|
+
* border token else that first color token. With no color token at all, both
|
|
39518
|
+
* are a raw grey. The server writes it on a placed shape, and the board
|
|
39519
|
+
* draws a dragged shape's preview in it.
|
|
39520
|
+
*/
|
|
39521
|
+
function shapePaint(tokens) {
|
|
39522
|
+
const names = new Set(tokens.map((row) => row.name));
|
|
39523
|
+
const firstColor = tokens.find((row) => row.group === "color")?.name;
|
|
39524
|
+
const paint = (name) => name === void 0 ? RAW_GREY : `var(${name})`;
|
|
39525
|
+
return {
|
|
39526
|
+
fill: paint(FILL_TOKENS.find((name) => names.has(name)) ?? firstColor),
|
|
39527
|
+
line: paint(names.has(LINE_TOKEN) ? LINE_TOKEN : firstColor)
|
|
39528
|
+
};
|
|
39529
|
+
}
|
|
39374
39530
|
// src/server/routes/edit.ts
|
|
39375
39531
|
const value = string$1().max(1e4);
|
|
39376
39532
|
const name$1 = string$1().min(1).max(256);
|
|
@@ -40490,9 +40646,11 @@ const CONTENT_TYPES$1 = {
|
|
|
40490
40646
|
* each use, so an edit shows on the next load and an unchanged file answers
|
|
40491
40647
|
* 304 with no body. A frame path carrying `?at=<hash>` serves the
|
|
40492
40648
|
* version `version` holds under that hash in its place, with the same head,
|
|
40493
|
-
* and any other path carrying it answers 404.
|
|
40649
|
+
* and any other path carrying it answers 404. `base` prefixes the sheet URLs
|
|
40650
|
+
* the head imports, for a listener serving these routes under a path of its
|
|
40651
|
+
* own, since the head names them from the server's root.
|
|
40494
40652
|
*/
|
|
40495
|
-
function frameRoutes(root, look, version) {
|
|
40653
|
+
function frameRoutes(root, look, version, base = "") {
|
|
40496
40654
|
const app = new Hono();
|
|
40497
40655
|
app.get("/frames/*", async (c) => {
|
|
40498
40656
|
const parts = decodeSegments(new URL(c.req.url).pathname.slice(8).split("/"));
|
|
@@ -40547,7 +40705,7 @@ function frameRoutes(root, look, version) {
|
|
|
40547
40705
|
if (held === null) return c.notFound();
|
|
40548
40706
|
bytes = new TextEncoder().encode(held);
|
|
40549
40707
|
}
|
|
40550
|
-
const body = injectHead(bytes, frameHead(sheetUrls(project, look.sheets(project)), contentHash(bytes)));
|
|
40708
|
+
const body = injectHead(bytes, frameHead(sheetUrls(project, look.sheets(project)).map((url) => `${base}${url}`), contentHash(bytes)));
|
|
40551
40709
|
return c.body(body, 200, {
|
|
40552
40710
|
"Content-Type": contentType,
|
|
40553
40711
|
"Cache-Control": "no-store"
|
|
@@ -40626,18 +40784,31 @@ async function resolveFile(root, [project, page, ...rest]) {
|
|
|
40626
40784
|
if (!project || !page) return null;
|
|
40627
40785
|
const projectSheet = rest.length === 0 && page === "tokens.css";
|
|
40628
40786
|
if (rest.length === 0 && !projectSheet) return null;
|
|
40629
|
-
if (page !== "assets" && !projectSheet && (rest.length > 1 || isRecord$
|
|
40787
|
+
if (page !== "assets" && !projectSheet && (rest.length > 1 || isRecord$2(rest[0] ?? ""))) return null;
|
|
40630
40788
|
try {
|
|
40631
40789
|
const projectDir = await realpath(join(root, project));
|
|
40632
40790
|
if (!projectDir.startsWith(root + sep)) return null;
|
|
40633
40791
|
const file = await realpath(join(projectDir, page, ...rest));
|
|
40634
40792
|
if (!file.startsWith(projectDir + sep)) return null;
|
|
40793
|
+
if (!servableInProject(relative(projectDir, file).split(sep))) return null;
|
|
40635
40794
|
return (await stat(file)).isFile() ? file : null;
|
|
40636
40795
|
} catch {
|
|
40637
40796
|
return null;
|
|
40638
40797
|
}
|
|
40639
40798
|
}
|
|
40640
|
-
|
|
40799
|
+
/**
|
|
40800
|
+
* Whether a file the request reached is one the route may serve, read off
|
|
40801
|
+
* where it really sits in its project rather than the name asked for, so a
|
|
40802
|
+
* symlink in `assets/` naming a record or a dot-named path is refused as the
|
|
40803
|
+
* name itself would be.
|
|
40804
|
+
*/
|
|
40805
|
+
function servableInProject(segments) {
|
|
40806
|
+
if (segments.some((segment) => segment.startsWith("."))) return false;
|
|
40807
|
+
const [first = "", name = ""] = segments;
|
|
40808
|
+
if (segments.length === 1) return first === TOKEN_FILE;
|
|
40809
|
+
return first === "assets" || !isRecord$2(name);
|
|
40810
|
+
}
|
|
40811
|
+
function isRecord$2(name) {
|
|
40641
40812
|
return name === "layout.json" || name === NOTES_FILE$1;
|
|
40642
40813
|
}
|
|
40643
40814
|
// src/server/routes/look.ts
|
|
@@ -40655,15 +40826,17 @@ const CONTENT_TYPES = {
|
|
|
40655
40826
|
* `--tokens` sheet, null for none, or absent to read the one a running
|
|
40656
40827
|
* server recorded in the address file on each request. `version` serves the
|
|
40657
40828
|
* frame versions an agent write replaced, absent where nothing holds them.
|
|
40829
|
+
* `base` prefixes the sheet URLs a served frame imports, for a listener that
|
|
40830
|
+
* serves these routes under a path of its own.
|
|
40658
40831
|
*/
|
|
40659
|
-
function servedFrames(root, { facesDir, tokens, version }) {
|
|
40832
|
+
function servedFrames(root, { facesDir, tokens, version, base }) {
|
|
40660
40833
|
const look = { sheets: (project) => tokenSheetPaths(root, project, tokens) };
|
|
40661
40834
|
const routes = new Hono();
|
|
40662
40835
|
routes.route("/", lookRoutes({
|
|
40663
40836
|
facesDir,
|
|
40664
40837
|
boardSheet: () => boardSheetPath(root, tokens)
|
|
40665
40838
|
}));
|
|
40666
|
-
routes.route("/", frameRoutes(root, look, version));
|
|
40839
|
+
routes.route("/", frameRoutes(root, look, version, base));
|
|
40667
40840
|
return {
|
|
40668
40841
|
look,
|
|
40669
40842
|
routes
|
|
@@ -41120,9 +41293,12 @@ const DEFAULT_SCALE = 2;
|
|
|
41120
41293
|
* frame rendered at `scale` times its layout size, twice when no scale is
|
|
41121
41294
|
* given. An added `filmstrip=<n>` of 2 or more renders `n` moments of its
|
|
41122
41295
|
* timeline in one row instead, refusing a frame with no timeline as
|
|
41123
|
-
* `motion-missing` and one that never ends as `motion-unbounded`.
|
|
41124
|
-
*
|
|
41125
|
-
*
|
|
41296
|
+
* `motion-missing` and one that never ends as `motion-unbounded`. An added
|
|
41297
|
+
* `device=1` draws a frame holding a device inside its body, and leaves a
|
|
41298
|
+
* frame holding none as it is. A filmstrip draws no device, so the two
|
|
41299
|
+
* together refuse as `usage`. It takes no token, since the image shows only
|
|
41300
|
+
* what the frame route already serves, and a refusal answers the CLI's
|
|
41301
|
+
* `{ ok, error }` envelope.
|
|
41126
41302
|
*/
|
|
41127
41303
|
function pngRoutes(root, render, renderFilmstrip) {
|
|
41128
41304
|
const app = new Hono();
|
|
@@ -41132,14 +41308,19 @@ function pngRoutes(root, render, renderFilmstrip) {
|
|
|
41132
41308
|
const theme = c.req.query("theme") ?? "";
|
|
41133
41309
|
const scale = parseScale$1(c.req.query("scale"));
|
|
41134
41310
|
const filmstrip = parseFilmstrip(c.req.query("filmstrip"));
|
|
41135
|
-
|
|
41311
|
+
const device = parseDevice(c.req.query("device"));
|
|
41312
|
+
if (ref === "" || !isTheme(theme) || scale === null || filmstrip === null || device === null || device && filmstrip !== void 0) throw new FrameboardError("usage", "Ask for /api/frames/png?ref=<frame-ref>&theme=<light|dark>&scale=<1|2|3>, adding either &filmstrip=<n> of 2 or more for a filmstrip or &device=1 for the frame inside its device.", {
|
|
41136
41313
|
ref,
|
|
41137
41314
|
theme,
|
|
41138
41315
|
scale: c.req.query("scale") ?? null,
|
|
41139
|
-
filmstrip: c.req.query("filmstrip") ?? null
|
|
41316
|
+
filmstrip: c.req.query("filmstrip") ?? null,
|
|
41317
|
+
device: c.req.query("device") ?? null
|
|
41140
41318
|
});
|
|
41141
|
-
const frame = await readFrame$1(root, ref, { cwd: root });
|
|
41142
|
-
const bytes = filmstrip === void 0 ? await render(
|
|
41319
|
+
const { device: held, ...frame } = await readFrame$1(root, ref, { cwd: root });
|
|
41320
|
+
const bytes = filmstrip === void 0 ? await render(device && held ? {
|
|
41321
|
+
...frame,
|
|
41322
|
+
device: held
|
|
41323
|
+
} : frame, theme, scale) : await renderFilmstrip(frame, theme, scale, filmstrip);
|
|
41143
41324
|
return c.body(new Uint8Array(bytes), 200, {
|
|
41144
41325
|
"Content-Type": "image/png",
|
|
41145
41326
|
"Cache-Control": "no-store"
|
|
@@ -41166,12 +41347,115 @@ function parseScale$1(value) {
|
|
|
41166
41347
|
if (value === "1" || value === "2" || value === "3") return Number(value);
|
|
41167
41348
|
return null;
|
|
41168
41349
|
}
|
|
41350
|
+
function parseDevice(value) {
|
|
41351
|
+
if (value === void 0) return false;
|
|
41352
|
+
return value === "1" ? true : null;
|
|
41353
|
+
}
|
|
41169
41354
|
function parseFilmstrip(value) {
|
|
41170
41355
|
if (value === void 0) return void 0;
|
|
41171
41356
|
if (!/^[1-9][0-9]*$/.test(value)) return null;
|
|
41172
41357
|
const count = Number(value);
|
|
41173
41358
|
return count >= 2 ? count : null;
|
|
41174
41359
|
}
|
|
41360
|
+
// src/server/preview/address.ts
|
|
41361
|
+
/**
|
|
41362
|
+
* The private IPv4 ranges a home or office network hands out, in the order a
|
|
41363
|
+
* phone is likeliest to share: Wi-Fi routers mostly give 192.168, and 172.16
|
|
41364
|
+
* to 172.31 is where container and VM bridges sit.
|
|
41365
|
+
*/
|
|
41366
|
+
const PRIVATE_RANGES = [
|
|
41367
|
+
([a, b]) => a === 192 && b === 168,
|
|
41368
|
+
([a]) => a === 10,
|
|
41369
|
+
([a, b = 0]) => a === 172 && b >= 16 && b <= 31
|
|
41370
|
+
];
|
|
41371
|
+
/**
|
|
41372
|
+
* This machine's IPv4 address on a local network, the one a phone on the same
|
|
41373
|
+
* Wi-Fi can reach, or null when the machine has none. A loopback, a
|
|
41374
|
+
* link-local, or a public address is never picked.
|
|
41375
|
+
*/
|
|
41376
|
+
function networkAddress(interfaces = networkInterfaces()) {
|
|
41377
|
+
const candidates = Object.values(interfaces).flatMap((infos) => infos ?? []).filter((info) => info.family === "IPv4" && !info.internal).map((info) => info.address);
|
|
41378
|
+
for (const inRange of PRIVATE_RANGES) {
|
|
41379
|
+
const found = candidates.find((address) => inRange(address.split(".").map(Number)));
|
|
41380
|
+
if (found !== void 0) return found;
|
|
41381
|
+
}
|
|
41382
|
+
return null;
|
|
41383
|
+
}
|
|
41384
|
+
/** The link a phone opens, landing on one frame of the project the listener serves. */
|
|
41385
|
+
function previewLink({ address, port, token, project, page, frame }) {
|
|
41386
|
+
return `http://${address}:${port}/v/${token}/frames/${[
|
|
41387
|
+
project,
|
|
41388
|
+
page,
|
|
41389
|
+
`${frame}${FRAME_EXTENSION}`
|
|
41390
|
+
].map(encodeURIComponent).join("/")}`;
|
|
41391
|
+
}
|
|
41392
|
+
// src/server/routes/preview.ts
|
|
41393
|
+
/** The port a phone link asks for first, which a machine's one-time route forwards. */
|
|
41394
|
+
const PREVIEW_PORT = 4400;
|
|
41395
|
+
const StartBody = object$1({
|
|
41396
|
+
ref: string$1().min(1),
|
|
41397
|
+
port: number().int().min(0).max(65535).optional()
|
|
41398
|
+
});
|
|
41399
|
+
const StopBody = object$1({ token: string$1().min(1).optional() });
|
|
41400
|
+
/**
|
|
41401
|
+
* `POST /api/preview` with `{ ref, port? }` starts the phone listener for the
|
|
41402
|
+
* frame's project and answers the link landing on that frame, ending any
|
|
41403
|
+
* link already open. `DELETE /api/preview` with `{ token? }` ends it, or only
|
|
41404
|
+
* the listener holding `token`. Both sit behind `requireWriter`, since a
|
|
41405
|
+
* start opens a port to the local network. A machine with no local network
|
|
41406
|
+
* address refuses `no-network-address` and starts nothing.
|
|
41407
|
+
*/
|
|
41408
|
+
function previewRoutes(root, access, slot, { address = networkAddress } = {}) {
|
|
41409
|
+
const app = new Hono();
|
|
41410
|
+
app.onError((error, c) => {
|
|
41411
|
+
if (error instanceof FrameboardError && error.code === "no-network-address") return c.json({
|
|
41412
|
+
ok: false,
|
|
41413
|
+
error: {
|
|
41414
|
+
code: error.code,
|
|
41415
|
+
message: error.message,
|
|
41416
|
+
details: {}
|
|
41417
|
+
}
|
|
41418
|
+
}, 503);
|
|
41419
|
+
return answerRefusal(error, c);
|
|
41420
|
+
});
|
|
41421
|
+
app.use("/api/preview", requireWriter(access));
|
|
41422
|
+
app.post("/api/preview", async (c) => {
|
|
41423
|
+
const { ref, port = PREVIEW_PORT } = await parseBody$1(c.req.raw, StartBody);
|
|
41424
|
+
const frame = await resolveFrameRef(root, ref, { cwd: root });
|
|
41425
|
+
const host = address();
|
|
41426
|
+
if (host === null) throw new FrameboardError("no-network-address", "This machine has no address on a local network, so a phone cannot reach it. Join the Wi-Fi the phone is on and try again.");
|
|
41427
|
+
const listener = await slot.start(frame.project, host, port);
|
|
41428
|
+
return c.json({
|
|
41429
|
+
ok: true,
|
|
41430
|
+
data: {
|
|
41431
|
+
url: previewLink({
|
|
41432
|
+
address: host,
|
|
41433
|
+
port: listener.port,
|
|
41434
|
+
token: listener.token,
|
|
41435
|
+
project: frame.project,
|
|
41436
|
+
page: frame.page,
|
|
41437
|
+
frame: frame.name
|
|
41438
|
+
}),
|
|
41439
|
+
address: host,
|
|
41440
|
+
port: listener.port,
|
|
41441
|
+
token: listener.token,
|
|
41442
|
+
project: frame.project,
|
|
41443
|
+
ref: `${frame.project}/${frame.page}/${frame.name}`
|
|
41444
|
+
}
|
|
41445
|
+
});
|
|
41446
|
+
});
|
|
41447
|
+
app.delete("/api/preview", async (c) => {
|
|
41448
|
+
const body = await c.req.json().catch(() => ({}));
|
|
41449
|
+
const parsed = StopBody.safeParse(body);
|
|
41450
|
+
if (!parsed.success) throw new FrameboardError("usage", `The body ${parsed.error.message}`);
|
|
41451
|
+
const stopped = await slot.stop(parsed.data.token);
|
|
41452
|
+
return c.json({
|
|
41453
|
+
ok: true,
|
|
41454
|
+
data: { stopped }
|
|
41455
|
+
});
|
|
41456
|
+
});
|
|
41457
|
+
return app;
|
|
41458
|
+
}
|
|
41175
41459
|
// src/server/board/paste.ts
|
|
41176
41460
|
/** Reads each frame's file and placement under its page's lock, in the order given. */
|
|
41177
41461
|
async function holdFrames(root, refs, options) {
|
|
@@ -41398,6 +41682,10 @@ const pasteSchema = object$1({
|
|
|
41398
41682
|
y: coordinate
|
|
41399
41683
|
}).optional()
|
|
41400
41684
|
});
|
|
41685
|
+
const frameDeviceSchema = object$1({
|
|
41686
|
+
refs,
|
|
41687
|
+
device: _enum$1(DEVICES).nullable()
|
|
41688
|
+
});
|
|
41401
41689
|
const frameFlagSchema = object$1({
|
|
41402
41690
|
refs,
|
|
41403
41691
|
flag: _enum$1(["hidden", "locked"]),
|
|
@@ -41672,6 +41960,18 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
41672
41960
|
data: frames
|
|
41673
41961
|
});
|
|
41674
41962
|
});
|
|
41963
|
+
/** Sets or clears the device drawn around each frame, in one step, leaving every frame file alone. */
|
|
41964
|
+
app.post("/api/frame/device", async (c) => {
|
|
41965
|
+
const body = await parseBody$1(c.req.raw, frameDeviceSchema);
|
|
41966
|
+
const frames = await eachFrame(body.refs, (frame, journal) => setFrameDevice(root, frame, body.device, {
|
|
41967
|
+
cwd,
|
|
41968
|
+
journal
|
|
41969
|
+
}), (records) => records.map((record) => record.ref));
|
|
41970
|
+
return c.json({
|
|
41971
|
+
ok: true,
|
|
41972
|
+
data: frames
|
|
41973
|
+
});
|
|
41974
|
+
});
|
|
41675
41975
|
/**
|
|
41676
41976
|
* Sets how each frame holds its height, `fixed`, `fit`, or `scroll`, in one
|
|
41677
41977
|
* step. `expected` holds each frame's box as the caller saw it, keyed by the
|
|
@@ -42113,7 +42413,7 @@ function boardHostGuard(port) {
|
|
|
42113
42413
|
await next();
|
|
42114
42414
|
};
|
|
42115
42415
|
}
|
|
42116
|
-
function createApp({ clientDir, root, port, actions, tickets, openRoute, renderFrame, renderFilmstrip, clipboard = null, facesDir, tokens, delivery, dispatch, history, selection, checks, thumbnails, measure, frameVersion, settledVersion, assetUsage }) {
|
|
42416
|
+
function createApp({ clientDir, root, port, actions, tickets, openRoute, renderFrame, renderFilmstrip, clipboard = null, facesDir, tokens, delivery, dispatch, history, selection, checks, thumbnails, measure, frameVersion, settledVersion, assetUsage, preview }) {
|
|
42117
42417
|
const app = new Hono();
|
|
42118
42418
|
const given = tokens ?? null;
|
|
42119
42419
|
app.use("*", async (c, next) => {
|
|
@@ -42147,6 +42447,7 @@ function createApp({ clientDir, root, port, actions, tickets, openRoute, renderF
|
|
|
42147
42447
|
app.route("/", clipboardRoutes(root, actions.access, renderFrame, clipboard));
|
|
42148
42448
|
if (checks) app.route("/", checkRoutes(actions.access, checks));
|
|
42149
42449
|
if (thumbnails) app.route("/", thumbnailRoutes(root, thumbnails));
|
|
42450
|
+
if (preview) app.route("/", previewRoutes(root, actions.access, preview));
|
|
42150
42451
|
app.route("/", frames.routes);
|
|
42151
42452
|
app.use("*", serveStatic({ root: clientDir }));
|
|
42152
42453
|
app.get("/p/*", serveStatic({
|
|
@@ -42731,27 +43032,67 @@ function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
|
|
|
42731
43032
|
let queue = Promise.resolve();
|
|
42732
43033
|
return (frame, theme, scale = defaultScale) => {
|
|
42733
43034
|
const run = queue.then(async () => {
|
|
42734
|
-
assertScreenshotFits(frame.ref,
|
|
42735
|
-
|
|
43035
|
+
assertScreenshotFits(frame.ref, bezelBox({
|
|
43036
|
+
x: 0,
|
|
43037
|
+
y: 0,
|
|
43038
|
+
...frame.box
|
|
43039
|
+
}, frame.device), scale);
|
|
43040
|
+
const open = await browser.get();
|
|
43041
|
+
const opened = await openFrame(open, {
|
|
42736
43042
|
baseUrl: baseUrl(),
|
|
42737
43043
|
ref: frame.ref,
|
|
42738
43044
|
box: frame.box,
|
|
42739
43045
|
theme,
|
|
42740
43046
|
scale
|
|
42741
43047
|
});
|
|
43048
|
+
let shot;
|
|
42742
43049
|
try {
|
|
42743
|
-
|
|
43050
|
+
shot = await opened.page.screenshot({
|
|
42744
43051
|
animations: "disabled",
|
|
42745
43052
|
caret: "hide"
|
|
42746
43053
|
});
|
|
42747
43054
|
} finally {
|
|
42748
43055
|
await opened.close();
|
|
42749
43056
|
}
|
|
43057
|
+
return frame.device ? drawBezel(open, shot, frame.box, frame.device, scale) : shot;
|
|
42750
43058
|
});
|
|
42751
43059
|
queue = run.catch(() => {});
|
|
42752
43060
|
return run;
|
|
42753
43061
|
};
|
|
42754
43062
|
}
|
|
43063
|
+
/**
|
|
43064
|
+
* A frame's shot drawn inside a device's body, as the board draws it, on a
|
|
43065
|
+
* page the size of the body, so the PNG holds the body and nothing past it.
|
|
43066
|
+
*/
|
|
43067
|
+
async function drawBezel(browser, shot, box, device, scale) {
|
|
43068
|
+
const { border, screenRadius } = BEZELS[device];
|
|
43069
|
+
const outer = bezelBox({
|
|
43070
|
+
x: 0,
|
|
43071
|
+
y: 0,
|
|
43072
|
+
...box
|
|
43073
|
+
}, device);
|
|
43074
|
+
const context = await browser.newContext({
|
|
43075
|
+
viewport: {
|
|
43076
|
+
width: outer.width,
|
|
43077
|
+
height: outer.height
|
|
43078
|
+
},
|
|
43079
|
+
deviceScaleFactor: scale
|
|
43080
|
+
});
|
|
43081
|
+
try {
|
|
43082
|
+
const page = await context.newPage();
|
|
43083
|
+
const marks = device === "phone" ? `<span style="${pill(PHONE_ISLAND.width, PHONE_ISLAND.height, BEZEL_COLORS.island)}top:${PHONE_ISLAND.top}px"></span><span style="${pill(HOME_BAR.width, HOME_BAR.height, BEZEL_COLORS.homeBar)}bottom:${HOME_BAR.bottom}px"></span>` : "";
|
|
43084
|
+
await page.setContent(`<!doctype html><html><body style="margin:0;background:transparent"><div style="position:absolute;left:${border}px;top:${border}px;width:${box.width}px;height:${box.height}px"><img alt="" src="data:image/png;base64,${shot.toString("base64")}" style="display:block;width:100%;height:100%"><div style="position:absolute;inset:0;border-radius:${screenRadius}px;box-shadow:${bezelShadow(device, { board: false })}">${marks}</div></div></body></html>`, { waitUntil: "load" });
|
|
43085
|
+
return await page.screenshot({
|
|
43086
|
+
omitBackground: true,
|
|
43087
|
+
caret: "hide"
|
|
43088
|
+
});
|
|
43089
|
+
} finally {
|
|
43090
|
+
await context.close();
|
|
43091
|
+
}
|
|
43092
|
+
}
|
|
43093
|
+
function pill(width, height, color) {
|
|
43094
|
+
return `position:absolute;left:50%;transform:translateX(-50%);width:${width}px;height:${height}px;border-radius:${height / 2}px;background:${color};`;
|
|
43095
|
+
}
|
|
42755
43096
|
// src/server/capture/images.ts
|
|
42756
43097
|
const SCREENSHOT = {
|
|
42757
43098
|
animations: "disabled",
|
|
@@ -42790,7 +43131,7 @@ function compositeImagePath(out, page, theme, scale = 1) {
|
|
|
42790
43131
|
* `capture-too-large` past Chromium's screenshot limit.
|
|
42791
43132
|
*/
|
|
42792
43133
|
function compositeBounds(page, frames, scale = 1) {
|
|
42793
|
-
const extents = frames.map(({ box, widths }) => drawnExtent(box, widths ?? []));
|
|
43134
|
+
const extents = frames.map(({ box, widths, device }) => drawnExtent(box, widths ?? [], device));
|
|
42794
43135
|
const left = Math.min(...extents.map((box) => box.x));
|
|
42795
43136
|
const top = Math.min(...extents.map((box) => box.y));
|
|
42796
43137
|
const right = Math.max(...extents.map((box) => box.x + box.width));
|
|
@@ -43893,8 +44234,8 @@ function readConfig(root, project) {
|
|
|
43893
44234
|
} catch {
|
|
43894
44235
|
return {};
|
|
43895
44236
|
}
|
|
43896
|
-
const checks = isRecord(parsed) ? parsed.checks : void 0;
|
|
43897
|
-
if (!isRecord(checks)) return {};
|
|
44237
|
+
const checks = isRecord$1(parsed) ? parsed.checks : void 0;
|
|
44238
|
+
if (!isRecord$1(checks)) return {};
|
|
43898
44239
|
const config = {};
|
|
43899
44240
|
if (Array.isArray(checks.allowedFonts) && checks.allowedFonts.every((font) => typeof font === "string")) config.allowedFonts = checks.allowedFonts;
|
|
43900
44241
|
if (typeof checks.noUppercase === "boolean") config.noUppercase = checks.noUppercase;
|
|
@@ -43902,7 +44243,7 @@ function readConfig(root, project) {
|
|
|
43902
44243
|
if (typeof checks.minContrast === "number" && checks.minContrast >= 1) config.minContrast = checks.minContrast;
|
|
43903
44244
|
return config;
|
|
43904
44245
|
}
|
|
43905
|
-
function isRecord(value) {
|
|
44246
|
+
function isRecord$1(value) {
|
|
43906
44247
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43907
44248
|
}
|
|
43908
44249
|
// src/server/checks/browser/contrast.ts
|
|
@@ -45074,6 +45415,17 @@ function postToBoard(address, path, body, { timeoutMs = REQUEST_TIMEOUT_MS } = {
|
|
|
45074
45415
|
body: JSON.stringify(body)
|
|
45075
45416
|
}, timeoutMs);
|
|
45076
45417
|
}
|
|
45418
|
+
/** Deletes through a running board server's write route with the address file's token. */
|
|
45419
|
+
function deleteFromBoard(address, path, body) {
|
|
45420
|
+
return requestBoard(address, path, {
|
|
45421
|
+
method: "DELETE",
|
|
45422
|
+
headers: {
|
|
45423
|
+
authorization: `Bearer ${address.token}`,
|
|
45424
|
+
"content-type": "application/json"
|
|
45425
|
+
},
|
|
45426
|
+
body: JSON.stringify(body)
|
|
45427
|
+
});
|
|
45428
|
+
}
|
|
45077
45429
|
/** Reads a running board server's route, resolving the `data` of its envelope. */
|
|
45078
45430
|
function getFromBoard(address, path) {
|
|
45079
45431
|
return requestBoard(address, path, { method: "GET" });
|
|
@@ -45089,12 +45441,20 @@ async function requestBoard(address, path, init, timeoutMs = REQUEST_TIMEOUT_MS)
|
|
|
45089
45441
|
throw new FrameboardError("server-not-running", `The frameboard server at ${address.url} did not answer. Run frameboard serve to restart it.`, { url: address.url }, { cause: error });
|
|
45090
45442
|
}
|
|
45091
45443
|
const envelope = await response.json().catch(() => null);
|
|
45444
|
+
const refusal = envelope?.error;
|
|
45445
|
+
if (!response.ok && isErrorCode(refusal?.code) && typeof refusal?.message === "string") throw new FrameboardError(refusal.code, refusal.message, isRecord(refusal.details) ? refusal.details : {});
|
|
45092
45446
|
if (!response.ok || !envelope) throw new FrameboardError("internal", `The frameboard server at ${address.url} refused ${path} with ${response.status}.`, {
|
|
45093
45447
|
url: address.url,
|
|
45094
45448
|
status: response.status
|
|
45095
45449
|
});
|
|
45096
45450
|
return envelope.data;
|
|
45097
45451
|
}
|
|
45452
|
+
function isErrorCode(code) {
|
|
45453
|
+
return typeof code === "string" && Object.hasOwn(EXIT_CODES, code);
|
|
45454
|
+
}
|
|
45455
|
+
function isRecord(value) {
|
|
45456
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45457
|
+
}
|
|
45098
45458
|
// src/cli/commands/check.ts
|
|
45099
45459
|
const BROWSER_TIMEOUT_MS = 12e4;
|
|
45100
45460
|
const NOT_FRAME = /* @__PURE__ */ new Set([
|
|
@@ -45275,6 +45635,8 @@ const frameRecordSchema = object$1({
|
|
|
45275
45635
|
width: number(),
|
|
45276
45636
|
height: number()
|
|
45277
45637
|
})),
|
|
45638
|
+
/** The device the board draws around the frame, absent when it has none. */
|
|
45639
|
+
device: _enum$1(DEVICES).optional(),
|
|
45278
45640
|
placed: boolean$1(),
|
|
45279
45641
|
modifiedAt: string$1()
|
|
45280
45642
|
});
|
|
@@ -45687,6 +46049,27 @@ const inspectResultSchema = object$1({
|
|
|
45687
46049
|
editable: boolean$1(),
|
|
45688
46050
|
elements: array$1(inspectedElementSchema)
|
|
45689
46051
|
});
|
|
46052
|
+
// src/shared/records/preview.ts
|
|
46053
|
+
/**
|
|
46054
|
+
* What `preview` returns on a start: the link a phone on the same network
|
|
46055
|
+
* opens, landing on one frame, which serves that frame's whole project read
|
|
46056
|
+
* only. The link ends when another start replaces it, when `preview --stop`
|
|
46057
|
+
* runs, when the board card showing it closes, or when the board stops.
|
|
46058
|
+
*/
|
|
46059
|
+
const previewStartSchema = object$1({
|
|
46060
|
+
url: string$1(),
|
|
46061
|
+
/** This machine's address on the local network, which the link names. */
|
|
46062
|
+
address: string$1(),
|
|
46063
|
+
/** The port the listener bound on every interface, the one asked for unless it was taken. */
|
|
46064
|
+
port: int$1(),
|
|
46065
|
+
/** The secret in the link's path, new on every start. */
|
|
46066
|
+
token: string$1(),
|
|
46067
|
+
project: string$1(),
|
|
46068
|
+
/** The frame the link lands on, `<project>/<page>/<frame>`. */
|
|
46069
|
+
ref: string$1()
|
|
46070
|
+
});
|
|
46071
|
+
/** What `preview --stop` returns: whether a link was running to end. */
|
|
46072
|
+
const previewStopSchema = object$1({ stopped: boolean$1() });
|
|
45690
46073
|
// src/shared/records/references.ts
|
|
45691
46074
|
/** What `references sync` returns, each path relative to the folder and sorted. */
|
|
45692
46075
|
const referencesSyncSchema = object$1({
|
|
@@ -45761,7 +46144,9 @@ const RECORDS = {
|
|
|
45761
46144
|
selection: selectionResultSchema,
|
|
45762
46145
|
find: findResultSchema,
|
|
45763
46146
|
referencesSync: referencesSyncSchema,
|
|
45764
|
-
referencesCheck: referencesCheckSchema
|
|
46147
|
+
referencesCheck: referencesCheckSchema,
|
|
46148
|
+
previewStart: previewStartSchema,
|
|
46149
|
+
previewStop: previewStopSchema
|
|
45765
46150
|
};
|
|
45766
46151
|
// src/cli/docs/content-format.ts
|
|
45767
46152
|
/** The content format `docs` prints, built from the constants the verbs run on. */
|
|
@@ -45789,6 +46174,7 @@ function contentFormat() {
|
|
|
45789
46174
|
"hidden, locked, hugWidth, hugHeight, and scroll read as false when absent, and an axis whose hug flag is false holds the size its entry states.",
|
|
45790
46175
|
`scroll marks a frame that holds a fixed screen height and scrolls past it, such as a page with a sticky section. It fixes both axes, so either hug flag beside it reads as false, frame fit refuses it, and serve never measures it. frame add --scroll sets it, taking the height given or else the preset height of the width (${FRAME_SIZES.desktop.height} px at ${FRAME_SIZES.desktop.width}). frame resize --scroll sets it on a placed frame, dropping a hugging height to that preset height unless a height is given and keeping a fixed height as it stands, so resize a frame fixed past a screen with --height too. frame resize --no-scroll clears it, keeping the box.`,
|
|
45791
46176
|
`widths lists the extra widths one frame file also shows at, as { width, height } objects, each drawn 80 px past the last in a row beside the frame at its y, so a responsive page is one file rather than a copy per width. Each width follows the frame's own height mode: it hugs its content at that width while hugHeight is on, and otherwise holds its height, the preset height of its width when first set and on frame resize --scroll. A value of any other shape reads as none. frame add --widths 834,390 and frame resize --widths set it, refusing a repeated width, the frame's own width, or a frame hugging its width, and frame resize --no-widths clears it. capture writes <frame>@<width>.<theme>.png beside <frame>.<theme>.png, check reports a browser finding at a linked width with that width and prints it as <path>@<width>, and a frames.json value of <project>/<page>/<frame>@<width> syncs that width's images.`,
|
|
46177
|
+
`device names the device the board draws around the frame, phone or tablet, as a body ${BEZELS.phone.border} or ${BEZELS.tablet.border} px past the box on every side. It never changes the frame file or its size, the body wraps whatever box the frame holds, and a frame placed beside one lands 80 px past the body. Linked widths draw no device. Any other value reads as none and is kept on write. frame add --device and frame device <frame-ref> <phone|tablet|none> set it, and none clears it.`,
|
|
45792
46178
|
`An axis that hugs takes its size from the frame's content: a running serve measures it after each write to the frame file and when frame add places a file already written, its width at most ${FRAME_SIZES.desktop.width} px, and writes width and height alone, never a flag. Content sized off the viewport keeps the box it has.`,
|
|
45793
46179
|
"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.",
|
|
45794
46180
|
"Frames sort by order, then name, and a write that changes order renumbers the page from 0.",
|
|
@@ -46113,7 +46499,7 @@ async function reservationsOf(root, refs, options, cwd, now) {
|
|
|
46113
46499
|
async function rightOf(root, frame, live) {
|
|
46114
46500
|
const page = await scanPage(root, frame.project, frame.page, 0);
|
|
46115
46501
|
const prefix = `${frame.project}/${frame.page}/`;
|
|
46116
|
-
const boxes = [...page.frames.map((each) => drawnExtent(each.box, each.widths)), ...live.flatMap((each) => each.box && each.frame.startsWith(prefix) ? [each.box] : [])];
|
|
46502
|
+
const boxes = [...page.frames.map((each) => drawnExtent(each.box, each.widths, each.device)), ...live.flatMap((each) => each.box && each.frame.startsWith(prefix) ? [each.box] : [])];
|
|
46117
46503
|
return Math.max(...boxes.map((box) => box.x + box.width + 80), 0);
|
|
46118
46504
|
}
|
|
46119
46505
|
function describe$4(claims, now) {
|
|
@@ -46127,6 +46513,7 @@ function describe$4(claims, now) {
|
|
|
46127
46513
|
// src/cli/commands/frame.ts
|
|
46128
46514
|
const FRAME_REF = "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file";
|
|
46129
46515
|
const ANY_INTEGER = parseInteger(Number.MIN_SAFE_INTEGER);
|
|
46516
|
+
const DEVICE_HELP = "the device the board draws around the frame, leaving the frame file and its size as they are";
|
|
46130
46517
|
const WIDTHS_HELP = "the extra widths the frame also shows at, a comma list such as 834,390, each drawn beside it and hugging or holding its height as the frame does";
|
|
46131
46518
|
const POSITIVE = parseInteger(1);
|
|
46132
46519
|
/** A comma list of positive integers, each checked as `--width` checks one. */
|
|
@@ -46145,7 +46532,7 @@ function registerFrame(program, context) {
|
|
|
46145
46532
|
data: record,
|
|
46146
46533
|
human: `${what} ${record.ref}`
|
|
46147
46534
|
});
|
|
46148
|
-
act(withPosition(withSize(verb("add", "Place a frame past every frame, as written when its file exists and with a skeleton file only when none does, so write the file first to show no empty box. Each axis no size names hugs its content, so a preset or --width fixes the width and the height hugs.").option("--scroll", SCROLL_HELP).option("--widths <list>", WIDTHS_HELP, parseWidths))), context, async ([ref = ""], options) => done(await addFrame(await boardOf(options, io), ref, {
|
|
46535
|
+
act(withPosition(withSize(verb("add", "Place a frame past every frame, as written when its file exists and with a skeleton file only when none does, so write the file first to show no empty box. Each axis no size names hugs its content, so a preset or --width fixes the width and the height hugs.").option("--scroll", SCROLL_HELP).option("--widths <list>", WIDTHS_HELP, parseWidths).addOption(new Option("--device <device>", DEVICE_HELP).choices(DEVICES)))), context, async ([ref = ""], options) => done(await addFrame(await boardOf(options, io), ref, {
|
|
46149
46536
|
...options,
|
|
46150
46537
|
cwd: io.cwd
|
|
46151
46538
|
}), "Added"));
|
|
@@ -46202,6 +46589,13 @@ function registerFrame(program, context) {
|
|
|
46202
46589
|
human: `Deleted frame ${result.deleted}`
|
|
46203
46590
|
};
|
|
46204
46591
|
});
|
|
46592
|
+
act(verb("device", "Set the device the board draws around a frame, or clear it with none, leaving the frame file and its size as they are").addArgument(new Argument("<device>", "the device, or none to clear it").choices([...DEVICES, "none"])), context, async ([ref = "", device = ""], options) => {
|
|
46593
|
+
const record = await setFrameDevice(await boardOf(options, io), ref, deviceOf(device), {
|
|
46594
|
+
...options,
|
|
46595
|
+
cwd: io.cwd
|
|
46596
|
+
});
|
|
46597
|
+
return done(record, record.device ? `Set ${record.device} on` : "Cleared the device on");
|
|
46598
|
+
});
|
|
46205
46599
|
for (const [name, flag] of [["hide", "hidden"], ["lock", "locked"]]) act(verb(name, `Set a frame ${flag}, or clear it with --off`).option("--off", `clear ${flag}`), context, async ([ref = ""], options) => done(await setFrameFlag(await boardOf(options, io), ref, flag, {
|
|
46206
46600
|
...options,
|
|
46207
46601
|
on: !options.off,
|
|
@@ -50226,6 +50620,428 @@ function registerPage(program, context) {
|
|
|
50226
50620
|
};
|
|
50227
50621
|
});
|
|
50228
50622
|
}
|
|
50623
|
+
// src/shared/qr.ts
|
|
50624
|
+
/** Error correction codewords per block at level M, indexed by version. */
|
|
50625
|
+
const ECC_PER_BLOCK = [
|
|
50626
|
+
-1,
|
|
50627
|
+
10,
|
|
50628
|
+
16,
|
|
50629
|
+
26,
|
|
50630
|
+
18,
|
|
50631
|
+
24,
|
|
50632
|
+
16,
|
|
50633
|
+
18,
|
|
50634
|
+
22,
|
|
50635
|
+
22,
|
|
50636
|
+
26,
|
|
50637
|
+
30,
|
|
50638
|
+
22,
|
|
50639
|
+
22,
|
|
50640
|
+
24,
|
|
50641
|
+
24,
|
|
50642
|
+
28,
|
|
50643
|
+
28,
|
|
50644
|
+
26,
|
|
50645
|
+
26,
|
|
50646
|
+
26,
|
|
50647
|
+
26,
|
|
50648
|
+
28,
|
|
50649
|
+
28,
|
|
50650
|
+
28,
|
|
50651
|
+
28,
|
|
50652
|
+
28,
|
|
50653
|
+
28,
|
|
50654
|
+
28,
|
|
50655
|
+
28,
|
|
50656
|
+
28,
|
|
50657
|
+
28,
|
|
50658
|
+
28,
|
|
50659
|
+
28,
|
|
50660
|
+
28,
|
|
50661
|
+
28,
|
|
50662
|
+
28,
|
|
50663
|
+
28,
|
|
50664
|
+
28,
|
|
50665
|
+
28,
|
|
50666
|
+
28
|
|
50667
|
+
];
|
|
50668
|
+
/** Error correction blocks at level M, indexed by version. */
|
|
50669
|
+
const BLOCKS = [
|
|
50670
|
+
-1,
|
|
50671
|
+
1,
|
|
50672
|
+
1,
|
|
50673
|
+
1,
|
|
50674
|
+
2,
|
|
50675
|
+
2,
|
|
50676
|
+
4,
|
|
50677
|
+
4,
|
|
50678
|
+
4,
|
|
50679
|
+
5,
|
|
50680
|
+
5,
|
|
50681
|
+
5,
|
|
50682
|
+
8,
|
|
50683
|
+
9,
|
|
50684
|
+
9,
|
|
50685
|
+
10,
|
|
50686
|
+
10,
|
|
50687
|
+
11,
|
|
50688
|
+
13,
|
|
50689
|
+
14,
|
|
50690
|
+
16,
|
|
50691
|
+
17,
|
|
50692
|
+
17,
|
|
50693
|
+
18,
|
|
50694
|
+
20,
|
|
50695
|
+
21,
|
|
50696
|
+
23,
|
|
50697
|
+
25,
|
|
50698
|
+
26,
|
|
50699
|
+
28,
|
|
50700
|
+
29,
|
|
50701
|
+
31,
|
|
50702
|
+
33,
|
|
50703
|
+
35,
|
|
50704
|
+
37,
|
|
50705
|
+
38,
|
|
50706
|
+
40,
|
|
50707
|
+
43,
|
|
50708
|
+
45,
|
|
50709
|
+
47,
|
|
50710
|
+
49
|
|
50711
|
+
];
|
|
50712
|
+
const MAX_VERSION = 40;
|
|
50713
|
+
/**
|
|
50714
|
+
* The modules of the smallest code holding `text` as UTF-8, with its mask
|
|
50715
|
+
* picked by the standard's penalty score. A text past what version 40 holds
|
|
50716
|
+
* throws, which no link reaches.
|
|
50717
|
+
*/
|
|
50718
|
+
function qrModules(text) {
|
|
50719
|
+
const data = new TextEncoder().encode(text);
|
|
50720
|
+
const version = smallestVersion(data.length);
|
|
50721
|
+
const codewords = addErrorCorrection(dataCodewords(data, version), version);
|
|
50722
|
+
const grid = new Grid(version * 4 + 17);
|
|
50723
|
+
drawFunctionPatterns(grid, version);
|
|
50724
|
+
drawCodewords(grid, codewords);
|
|
50725
|
+
let best = null;
|
|
50726
|
+
for (let mask = 0; mask < 8; mask++) {
|
|
50727
|
+
const masked = grid.copy();
|
|
50728
|
+
applyMask(masked, mask);
|
|
50729
|
+
drawFormatBits(masked, mask);
|
|
50730
|
+
const penalty = penaltyScore(masked.modules);
|
|
50731
|
+
if (!best || penalty < best.penalty) best = {
|
|
50732
|
+
penalty,
|
|
50733
|
+
modules: masked.modules
|
|
50734
|
+
};
|
|
50735
|
+
}
|
|
50736
|
+
return best?.modules ?? [];
|
|
50737
|
+
}
|
|
50738
|
+
var Grid = class Grid {
|
|
50739
|
+
size;
|
|
50740
|
+
modules;
|
|
50741
|
+
reserved;
|
|
50742
|
+
constructor(size, modules, reserved) {
|
|
50743
|
+
this.size = size;
|
|
50744
|
+
this.modules = modules ?? Array.from({ length: size }, () => Array(size).fill(false));
|
|
50745
|
+
this.reserved = reserved ?? Array.from({ length: size }, () => Array(size).fill(false));
|
|
50746
|
+
}
|
|
50747
|
+
/** Sets a function module, which no data bit or mask touches. */
|
|
50748
|
+
setFunction(x, y, dark) {
|
|
50749
|
+
this.set(x, y, dark);
|
|
50750
|
+
const row = this.reserved[y];
|
|
50751
|
+
if (row) row[x] = true;
|
|
50752
|
+
}
|
|
50753
|
+
set(x, y, dark) {
|
|
50754
|
+
const row = this.modules[y];
|
|
50755
|
+
if (row) row[x] = dark;
|
|
50756
|
+
}
|
|
50757
|
+
get(x, y) {
|
|
50758
|
+
return this.modules[y]?.[x] ?? false;
|
|
50759
|
+
}
|
|
50760
|
+
isReserved(x, y) {
|
|
50761
|
+
return this.reserved[y]?.[x] ?? false;
|
|
50762
|
+
}
|
|
50763
|
+
copy() {
|
|
50764
|
+
return new Grid(this.size, this.modules.map((row) => [...row]), this.reserved);
|
|
50765
|
+
}
|
|
50766
|
+
};
|
|
50767
|
+
/** The data codewords a version holds at level M. */
|
|
50768
|
+
function dataCapacity(version) {
|
|
50769
|
+
return Math.floor(rawModules(version) / 8) - (ECC_PER_BLOCK[version] ?? 0) * (BLOCKS[version] ?? 0);
|
|
50770
|
+
}
|
|
50771
|
+
/** The modules left for codewords once the function patterns are drawn. */
|
|
50772
|
+
function rawModules(version) {
|
|
50773
|
+
let result = (16 * version + 128) * version + 64;
|
|
50774
|
+
if (version >= 2) {
|
|
50775
|
+
const align = Math.floor(version / 7) + 2;
|
|
50776
|
+
result -= (25 * align - 10) * align - 55;
|
|
50777
|
+
if (version >= 7) result -= 36;
|
|
50778
|
+
}
|
|
50779
|
+
return result;
|
|
50780
|
+
}
|
|
50781
|
+
function smallestVersion(bytes) {
|
|
50782
|
+
for (let version = 1; version <= MAX_VERSION; version++) if (4 + (version <= 9 ? 8 : 16) + bytes * 8 <= dataCapacity(version) * 8) return version;
|
|
50783
|
+
throw new Error(`A QR code holds no text of ${bytes} bytes`);
|
|
50784
|
+
}
|
|
50785
|
+
/** Mode, count, bytes, terminator, then the alternating pad bytes. */
|
|
50786
|
+
function dataCodewords(data, version) {
|
|
50787
|
+
const bits = [];
|
|
50788
|
+
const push = (value, length) => {
|
|
50789
|
+
for (let i = length - 1; i >= 0; i--) bits.push(value >>> i & 1);
|
|
50790
|
+
};
|
|
50791
|
+
push(4, 4);
|
|
50792
|
+
push(data.length, version <= 9 ? 8 : 16);
|
|
50793
|
+
for (const byte of data) push(byte, 8);
|
|
50794
|
+
const capacity = dataCapacity(version) * 8;
|
|
50795
|
+
push(0, Math.min(4, capacity - bits.length));
|
|
50796
|
+
push(0, (8 - bits.length % 8) % 8);
|
|
50797
|
+
for (let pad = 236; bits.length < capacity; pad ^= 253) push(pad, 8);
|
|
50798
|
+
const codewords = [];
|
|
50799
|
+
for (let i = 0; i < bits.length; i += 8) codewords.push(bits.slice(i, i + 8).reduce((byte, bit) => byte << 1 | bit, 0));
|
|
50800
|
+
return codewords;
|
|
50801
|
+
}
|
|
50802
|
+
/** Splits the data into blocks, appends each block's ECC, and interleaves them. */
|
|
50803
|
+
function addErrorCorrection(data, version) {
|
|
50804
|
+
const blockCount = BLOCKS[version] ?? 1;
|
|
50805
|
+
const eccLength = ECC_PER_BLOCK[version] ?? 0;
|
|
50806
|
+
const raw = Math.floor(rawModules(version) / 8);
|
|
50807
|
+
const shortBlocks = blockCount - raw % blockCount;
|
|
50808
|
+
const shortLength = Math.floor(raw / blockCount);
|
|
50809
|
+
const divisor = reedSolomonDivisor(eccLength);
|
|
50810
|
+
const blocks = [];
|
|
50811
|
+
for (let i = 0, at = 0; i < blockCount; i++) {
|
|
50812
|
+
const length = shortLength - eccLength + (i < shortBlocks ? 0 : 1);
|
|
50813
|
+
const block = data.slice(at, at + length);
|
|
50814
|
+
at += length;
|
|
50815
|
+
const ecc = reedSolomonRemainder(block, divisor);
|
|
50816
|
+
if (i < shortBlocks) block.push(-1);
|
|
50817
|
+
blocks.push([...block, ...ecc]);
|
|
50818
|
+
}
|
|
50819
|
+
const result = [];
|
|
50820
|
+
for (let i = 0; i < (blocks[0]?.length ?? 0); i++) blocks.forEach((block, index) => {
|
|
50821
|
+
if (!(i === shortLength - eccLength && index < shortBlocks)) result.push(block[i] ?? 0);
|
|
50822
|
+
});
|
|
50823
|
+
return result;
|
|
50824
|
+
}
|
|
50825
|
+
function reedSolomonDivisor(degree) {
|
|
50826
|
+
const result = Array(degree).fill(0);
|
|
50827
|
+
result[degree - 1] = 1;
|
|
50828
|
+
let root = 1;
|
|
50829
|
+
for (let i = 0; i < degree; i++) {
|
|
50830
|
+
for (let j = 0; j < degree; j++) {
|
|
50831
|
+
result[j] = multiply(result[j] ?? 0, root);
|
|
50832
|
+
if (j + 1 < degree) result[j] = (result[j] ?? 0) ^ (result[j + 1] ?? 0);
|
|
50833
|
+
}
|
|
50834
|
+
root = multiply(root, 2);
|
|
50835
|
+
}
|
|
50836
|
+
return result;
|
|
50837
|
+
}
|
|
50838
|
+
function reedSolomonRemainder(data, divisor) {
|
|
50839
|
+
const result = divisor.map(() => 0);
|
|
50840
|
+
for (const byte of data) {
|
|
50841
|
+
const factor = byte ^ (result.shift() ?? 0);
|
|
50842
|
+
result.push(0);
|
|
50843
|
+
divisor.forEach((coefficient, i) => {
|
|
50844
|
+
result[i] = (result[i] ?? 0) ^ multiply(coefficient, factor);
|
|
50845
|
+
});
|
|
50846
|
+
}
|
|
50847
|
+
return result;
|
|
50848
|
+
}
|
|
50849
|
+
/** Multiplication in GF(2^8) modulo the QR polynomial 0x11D. */
|
|
50850
|
+
function multiply(x, y) {
|
|
50851
|
+
let z = 0;
|
|
50852
|
+
for (let i = 7; i >= 0; i--) {
|
|
50853
|
+
z = z << 1 ^ (z >>> 7) * 285;
|
|
50854
|
+
z ^= (y >>> i & 1) * x;
|
|
50855
|
+
}
|
|
50856
|
+
return z;
|
|
50857
|
+
}
|
|
50858
|
+
function drawFunctionPatterns(grid, version) {
|
|
50859
|
+
const { size } = grid;
|
|
50860
|
+
for (let i = 0; i < size; i++) {
|
|
50861
|
+
grid.setFunction(6, i, i % 2 === 0);
|
|
50862
|
+
grid.setFunction(i, 6, i % 2 === 0);
|
|
50863
|
+
}
|
|
50864
|
+
drawFinder(grid, 3, 3);
|
|
50865
|
+
drawFinder(grid, size - 4, 3);
|
|
50866
|
+
drawFinder(grid, 3, size - 4);
|
|
50867
|
+
const positions = alignmentPositions(version, size);
|
|
50868
|
+
const last = positions.length - 1;
|
|
50869
|
+
positions.forEach((x, i) => {
|
|
50870
|
+
positions.forEach((y, j) => {
|
|
50871
|
+
if (!(i === 0 && j === 0 || i === 0 && j === last || i === last && j === 0)) drawAlignment(grid, x, y);
|
|
50872
|
+
});
|
|
50873
|
+
});
|
|
50874
|
+
drawFormatBits(grid, 0);
|
|
50875
|
+
drawVersionBits(grid, version);
|
|
50876
|
+
}
|
|
50877
|
+
function drawFinder(grid, cx, cy) {
|
|
50878
|
+
for (let dy = -4; dy <= 4; dy++) for (let dx = -4; dx <= 4; dx++) {
|
|
50879
|
+
const x = cx + dx;
|
|
50880
|
+
const y = cy + dy;
|
|
50881
|
+
if (x < 0 || y < 0 || x >= grid.size || y >= grid.size) continue;
|
|
50882
|
+
const distance = Math.max(Math.abs(dx), Math.abs(dy));
|
|
50883
|
+
grid.setFunction(x, y, distance !== 2 && distance !== 4);
|
|
50884
|
+
}
|
|
50885
|
+
}
|
|
50886
|
+
function drawAlignment(grid, cx, cy) {
|
|
50887
|
+
for (let dy = -2; dy <= 2; dy++) for (let dx = -2; dx <= 2; dx++) grid.setFunction(cx + dx, cy + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);
|
|
50888
|
+
}
|
|
50889
|
+
function alignmentPositions(version, size) {
|
|
50890
|
+
if (version === 1) return [];
|
|
50891
|
+
const count = Math.floor(version / 7) + 2;
|
|
50892
|
+
const step = Math.floor((version * 8 + count * 3 + 5) / (count * 4 - 4)) * 2;
|
|
50893
|
+
const result = [6];
|
|
50894
|
+
for (let position = size - 7; result.length < count; position -= step) result.splice(1, 0, position);
|
|
50895
|
+
return result;
|
|
50896
|
+
}
|
|
50897
|
+
function drawFormatBits(grid, mask) {
|
|
50898
|
+
const data = 0 | mask;
|
|
50899
|
+
let remainder = data;
|
|
50900
|
+
for (let i = 0; i < 10; i++) remainder = remainder << 1 ^ (remainder >>> 9) * 1335;
|
|
50901
|
+
const bits = (data << 10 | remainder) ^ 21522;
|
|
50902
|
+
const bit = (i) => (bits >>> i & 1) !== 0;
|
|
50903
|
+
const { size } = grid;
|
|
50904
|
+
for (let i = 0; i <= 5; i++) grid.setFunction(8, i, bit(i));
|
|
50905
|
+
grid.setFunction(8, 7, bit(6));
|
|
50906
|
+
grid.setFunction(8, 8, bit(7));
|
|
50907
|
+
grid.setFunction(7, 8, bit(8));
|
|
50908
|
+
for (let i = 9; i < 15; i++) grid.setFunction(14 - i, 8, bit(i));
|
|
50909
|
+
for (let i = 0; i < 8; i++) grid.setFunction(size - 1 - i, 8, bit(i));
|
|
50910
|
+
for (let i = 8; i < 15; i++) grid.setFunction(8, size - 15 + i, bit(i));
|
|
50911
|
+
grid.setFunction(8, size - 8, true);
|
|
50912
|
+
}
|
|
50913
|
+
function drawVersionBits(grid, version) {
|
|
50914
|
+
if (version < 7) return;
|
|
50915
|
+
let remainder = version;
|
|
50916
|
+
for (let i = 0; i < 12; i++) remainder = remainder << 1 ^ (remainder >>> 11) * 7973;
|
|
50917
|
+
const bits = version << 12 | remainder;
|
|
50918
|
+
for (let i = 0; i < 18; i++) {
|
|
50919
|
+
const dark = (bits >>> i & 1) !== 0;
|
|
50920
|
+
const a = grid.size - 11 + i % 3;
|
|
50921
|
+
const b = Math.floor(i / 3);
|
|
50922
|
+
grid.setFunction(a, b, dark);
|
|
50923
|
+
grid.setFunction(b, a, dark);
|
|
50924
|
+
}
|
|
50925
|
+
}
|
|
50926
|
+
/** Places the codewords in the two-column zigzag from the bottom right. */
|
|
50927
|
+
function drawCodewords(grid, codewords) {
|
|
50928
|
+
const { size } = grid;
|
|
50929
|
+
let i = 0;
|
|
50930
|
+
for (let right = size - 1; right >= 1; right -= 2) {
|
|
50931
|
+
if (right === 6) right = 5;
|
|
50932
|
+
for (let vertical = 0; vertical < size; vertical++) for (let j = 0; j < 2; j++) {
|
|
50933
|
+
const x = right - j;
|
|
50934
|
+
const y = (right + 1 & 2) === 0 ? size - 1 - vertical : vertical;
|
|
50935
|
+
if (grid.isReserved(x, y) || i >= codewords.length * 8) continue;
|
|
50936
|
+
grid.set(x, y, ((codewords[i >>> 3] ?? 0) >>> 7 - (i & 7) & 1) !== 0);
|
|
50937
|
+
i++;
|
|
50938
|
+
}
|
|
50939
|
+
}
|
|
50940
|
+
}
|
|
50941
|
+
const MASKS = [
|
|
50942
|
+
(x, y) => (x + y) % 2 === 0,
|
|
50943
|
+
(_x, y) => y % 2 === 0,
|
|
50944
|
+
(x) => x % 3 === 0,
|
|
50945
|
+
(x, y) => (x + y) % 3 === 0,
|
|
50946
|
+
(x, y) => (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0,
|
|
50947
|
+
(x, y) => x * y % 2 + x * y % 3 === 0,
|
|
50948
|
+
(x, y) => (x * y % 2 + x * y % 3) % 2 === 0,
|
|
50949
|
+
(x, y) => ((x + y) % 2 + x * y % 3) % 2 === 0
|
|
50950
|
+
];
|
|
50951
|
+
function applyMask(grid, mask) {
|
|
50952
|
+
const flips = MASKS[mask];
|
|
50953
|
+
if (!flips) return;
|
|
50954
|
+
for (let y = 0; y < grid.size; y++) for (let x = 0; x < grid.size; x++) if (!grid.isReserved(x, y) && flips(x, y)) grid.set(x, y, !grid.get(x, y));
|
|
50955
|
+
}
|
|
50956
|
+
/**
|
|
50957
|
+
* The standard's four penalty rules, summed, lower being easier to scan. The
|
|
50958
|
+
* standard leaves the finder-like rule's edges open, so it is counted inside
|
|
50959
|
+
* the line, as the `qrcode` package does, which keeps both picking one mask.
|
|
50960
|
+
*/
|
|
50961
|
+
function penaltyScore(modules) {
|
|
50962
|
+
const size = modules.length;
|
|
50963
|
+
const at = (x, y) => modules[y]?.[x] ?? false;
|
|
50964
|
+
let result = 0;
|
|
50965
|
+
for (const horizontal of [true, false]) for (let a = 0; a < size; a++) {
|
|
50966
|
+
let run = 0;
|
|
50967
|
+
let previous = null;
|
|
50968
|
+
let window = 0;
|
|
50969
|
+
for (let b = 0; b < size; b++) {
|
|
50970
|
+
const dark = horizontal ? at(b, a) : at(a, b);
|
|
50971
|
+
if (dark === previous) run++;
|
|
50972
|
+
else {
|
|
50973
|
+
if (run >= 5) result += run - 2;
|
|
50974
|
+
run = 1;
|
|
50975
|
+
previous = dark;
|
|
50976
|
+
}
|
|
50977
|
+
window = window << 1 & 2047 | (dark ? 1 : 0);
|
|
50978
|
+
if (b >= 10 && (window === 1488 || window === 93)) result += 40;
|
|
50979
|
+
}
|
|
50980
|
+
if (run >= 5) result += run - 2;
|
|
50981
|
+
}
|
|
50982
|
+
for (let y = 0; y < size - 1; y++) for (let x = 0; x < size - 1; x++) {
|
|
50983
|
+
const dark = at(x, y);
|
|
50984
|
+
if (dark === at(x + 1, y) && dark === at(x, y + 1) && dark === at(x + 1, y + 1)) result += 3;
|
|
50985
|
+
}
|
|
50986
|
+
const dark = modules.flat().filter(Boolean).length;
|
|
50987
|
+
return result + Math.abs(Math.ceil(dark * 100 / (size * size) / 5) - 10) * 10;
|
|
50988
|
+
}
|
|
50989
|
+
// src/cli/commands/preview.ts
|
|
50990
|
+
/** The light modules a scanner wants around a code, at least four by the standard. */
|
|
50991
|
+
const QUIET_ZONE = 4;
|
|
50992
|
+
function registerPreview(program, context) {
|
|
50993
|
+
const { io } = context;
|
|
50994
|
+
act(addVerb(program, "preview", "Open a frame's project on a phone on the same network, read only, through a link and a code the running board serves", { project: true }).argument("[frame-ref]", "the frame the link lands on, <page>/<frame>, <project>/<page>/<frame>, or a path to its .html file").option("--port <n>", `the port the link asks for first, taking a free one when it is taken (default: ${PREVIEW_PORT})`, parsePort).option("--stop", "end the open link, so no phone reaches the board"), context, async (args, options) => {
|
|
50995
|
+
const [ref] = args;
|
|
50996
|
+
const root = await boardOf(options, io);
|
|
50997
|
+
if (options.stop && ref !== void 0) throw new FrameboardError("usage", "Pass a frame ref to open a link, or --stop to end one, not both.");
|
|
50998
|
+
if (!options.stop && ref === void 0) throw new FrameboardError("usage", "Name the frame the link lands on, or pass --stop to end the open link.");
|
|
50999
|
+
const frame = ref === void 0 ? null : await resolveFrameRef(root, ref, {
|
|
51000
|
+
project: options.project,
|
|
51001
|
+
cwd: io.cwd
|
|
51002
|
+
});
|
|
51003
|
+
const live = await findLiveServer(root);
|
|
51004
|
+
if (!live) throw new FrameboardError("server-not-running", `No frameboard server is running for ${root}. Run frameboard serve first.`, { root });
|
|
51005
|
+
if (frame === null) {
|
|
51006
|
+
const data = await deleteFromBoard(live, "/api/preview", {});
|
|
51007
|
+
return {
|
|
51008
|
+
data,
|
|
51009
|
+
human: data.stopped ? "Ended the phone link" : "No phone link was open"
|
|
51010
|
+
};
|
|
51011
|
+
}
|
|
51012
|
+
const data = await postToBoard(live, "/api/preview", {
|
|
51013
|
+
ref: `${frame.project}/${frame.page}/${frame.name}`,
|
|
51014
|
+
...options.port === void 0 ? {} : { port: options.port }
|
|
51015
|
+
});
|
|
51016
|
+
return {
|
|
51017
|
+
data,
|
|
51018
|
+
human: [
|
|
51019
|
+
terminalCode(qrModules(data.url)),
|
|
51020
|
+
data.url,
|
|
51021
|
+
`Scan on the same Wi-Fi. It opens ${data.project} read only until the board stops or frameboard preview --stop runs.`
|
|
51022
|
+
].join("\n")
|
|
51023
|
+
};
|
|
51024
|
+
});
|
|
51025
|
+
}
|
|
51026
|
+
/**
|
|
51027
|
+
* The code drawn two rows to a line in half blocks, black on a forced white
|
|
51028
|
+
* ground, so it scans on a dark terminal as on a light one.
|
|
51029
|
+
*/
|
|
51030
|
+
function terminalCode(modules) {
|
|
51031
|
+
const size = modules.length + 8;
|
|
51032
|
+
const dark = (x, y) => modules[y - QUIET_ZONE]?.[x - QUIET_ZONE] ?? false;
|
|
51033
|
+
const lines = [];
|
|
51034
|
+
for (let y = 0; y < size; y += 2) {
|
|
51035
|
+
let line = "";
|
|
51036
|
+
for (let x = 0; x < size; x++) {
|
|
51037
|
+
const top = dark(x, y);
|
|
51038
|
+
const bottom = dark(x, y + 1);
|
|
51039
|
+
line += top && bottom ? "█" : top ? "▀" : bottom ? "▄" : " ";
|
|
51040
|
+
}
|
|
51041
|
+
lines.push(`\x1b[30;47m${line}\x1b[0m`);
|
|
51042
|
+
}
|
|
51043
|
+
return lines.join("\n");
|
|
51044
|
+
}
|
|
50229
51045
|
// src/cli/commands/project.ts
|
|
50230
51046
|
function registerProject(program, context) {
|
|
50231
51047
|
const { io } = context;
|
|
@@ -54973,6 +55789,159 @@ function createDelivery({ pending, markDelivered, onListeners, now }) {
|
|
|
54973
55789
|
listeners
|
|
54974
55790
|
};
|
|
54975
55791
|
}
|
|
55792
|
+
// src/server/preview/listener.ts
|
|
55793
|
+
/** Where every phone link starts, ahead of its token. */
|
|
55794
|
+
const LINK_PREFIX = "/v/";
|
|
55795
|
+
/** The bytes of a link's token, 96 bits, which keeps the code small. */
|
|
55796
|
+
const TOKEN_BYTES = 12;
|
|
55797
|
+
/**
|
|
55798
|
+
* The phone link's read-only app: GET and HEAD under `/v/<token>/` for one
|
|
55799
|
+
* project's frames and assets at `frames/<project>/...` and the faces and
|
|
55800
|
+
* board sheet at `frameboard/...`, each answered by the board's own frame and
|
|
55801
|
+
* look routes, so their refusals of board records, dot-named paths, and
|
|
55802
|
+
* escaping paths hold here unrestated. Anything else answers 404, so nothing
|
|
55803
|
+
* tells a caller what exists. It carries no Host check, since a phone names
|
|
55804
|
+
* the machine's address, and the token is what keeps other pages out.
|
|
55805
|
+
*/
|
|
55806
|
+
function previewApp(token, options) {
|
|
55807
|
+
const base = `${LINK_PREFIX}${token}`;
|
|
55808
|
+
const served = servedFrames(options.root, {
|
|
55809
|
+
facesDir: options.facesDir,
|
|
55810
|
+
tokens: options.tokens ?? null,
|
|
55811
|
+
base
|
|
55812
|
+
}).routes;
|
|
55813
|
+
const app = new Hono();
|
|
55814
|
+
app.use("*", async (c, next) => {
|
|
55815
|
+
await next();
|
|
55816
|
+
c.res = withHeader(c.res, "Referrer-Policy", "no-referrer");
|
|
55817
|
+
});
|
|
55818
|
+
app.all("*", async (c) => {
|
|
55819
|
+
const method = c.req.method;
|
|
55820
|
+
if (method !== "GET" && method !== "HEAD") return c.notFound();
|
|
55821
|
+
const url = new URL(c.req.url);
|
|
55822
|
+
const inner = innerPath(url.pathname, token, options.project);
|
|
55823
|
+
if (inner === null) return c.notFound();
|
|
55824
|
+
const headers = new Headers();
|
|
55825
|
+
for (const name of ["range", "if-none-match"]) {
|
|
55826
|
+
const value = c.req.header(name);
|
|
55827
|
+
if (value !== void 0) headers.set(name, value);
|
|
55828
|
+
}
|
|
55829
|
+
const theme = url.searchParams.get("theme");
|
|
55830
|
+
const query = theme === null ? "" : `?${new URLSearchParams({ theme })}`;
|
|
55831
|
+
return served.fetch(new Request(`http://preview${inner}${query}`, {
|
|
55832
|
+
method,
|
|
55833
|
+
headers
|
|
55834
|
+
}));
|
|
55835
|
+
});
|
|
55836
|
+
return app;
|
|
55837
|
+
}
|
|
55838
|
+
/**
|
|
55839
|
+
* The board path a phone path stands for, or null when it names another
|
|
55840
|
+
* token, another project, or anything outside the frames and the look.
|
|
55841
|
+
*/
|
|
55842
|
+
function innerPath(pathname, token, project) {
|
|
55843
|
+
if (!pathname.startsWith(LINK_PREFIX)) return null;
|
|
55844
|
+
const [given = "", ...rest] = pathname.slice(3).split("/");
|
|
55845
|
+
if (!sameToken(given, token)) return null;
|
|
55846
|
+
const inner = `/${rest.join("/")}`;
|
|
55847
|
+
if (inner === "/frameboard/tokens.css" || inner.startsWith(`/frameboard/faces/`)) return inner;
|
|
55848
|
+
const [area, named, ...within] = rest;
|
|
55849
|
+
if (area !== "frames" || within.length === 0) return null;
|
|
55850
|
+
let decoded;
|
|
55851
|
+
try {
|
|
55852
|
+
decoded = decodeURIComponent(named ?? "");
|
|
55853
|
+
} catch {
|
|
55854
|
+
return null;
|
|
55855
|
+
}
|
|
55856
|
+
return decoded === project ? inner : null;
|
|
55857
|
+
}
|
|
55858
|
+
/** The response with one header set, copied first since a forwarded one may be immutable. */
|
|
55859
|
+
function withHeader(response, name, value) {
|
|
55860
|
+
const headers = new Headers(response.headers);
|
|
55861
|
+
headers.set(name, value);
|
|
55862
|
+
return new Response(response.body, {
|
|
55863
|
+
status: response.status,
|
|
55864
|
+
statusText: response.statusText,
|
|
55865
|
+
headers
|
|
55866
|
+
});
|
|
55867
|
+
}
|
|
55868
|
+
function sameToken(given, token) {
|
|
55869
|
+
const a = Buffer.from(given);
|
|
55870
|
+
const b = Buffer.from(token);
|
|
55871
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
55872
|
+
}
|
|
55873
|
+
/**
|
|
55874
|
+
* Starts the phone listener on `host`, the machine's local network address,
|
|
55875
|
+
* at `port`, or on a free port when that one is taken, with a fresh token.
|
|
55876
|
+
* Binding the one address rather than every interface keeps the listener off
|
|
55877
|
+
* any other network the machine sits on. The board's own listener is
|
|
55878
|
+
* untouched, staying on loopback behind its Host check.
|
|
55879
|
+
*/
|
|
55880
|
+
async function startPreviewListener(options) {
|
|
55881
|
+
const token = randomBytes(TOKEN_BYTES).toString("base64url");
|
|
55882
|
+
const app = previewApp(token, options);
|
|
55883
|
+
let server;
|
|
55884
|
+
try {
|
|
55885
|
+
server = await bind(app, options.host, options.port);
|
|
55886
|
+
} catch (error) {
|
|
55887
|
+
if (!(error.code === "EADDRINUSE") || options.port === 0) throw error;
|
|
55888
|
+
server = await bind(app, options.host, 0);
|
|
55889
|
+
}
|
|
55890
|
+
const { port } = server.address();
|
|
55891
|
+
return {
|
|
55892
|
+
token,
|
|
55893
|
+
host: options.host,
|
|
55894
|
+
port,
|
|
55895
|
+
project: options.project,
|
|
55896
|
+
close: () => new Promise((resolve) => {
|
|
55897
|
+
server.close(() => resolve());
|
|
55898
|
+
server.closeAllConnections();
|
|
55899
|
+
})
|
|
55900
|
+
};
|
|
55901
|
+
}
|
|
55902
|
+
function bind(app, hostname, port) {
|
|
55903
|
+
return new Promise((resolve, reject) => {
|
|
55904
|
+
const created = serve({
|
|
55905
|
+
fetch: app.fetch,
|
|
55906
|
+
hostname,
|
|
55907
|
+
port
|
|
55908
|
+
}, () => resolve(created));
|
|
55909
|
+
created.once("error", reject);
|
|
55910
|
+
});
|
|
55911
|
+
}
|
|
55912
|
+
/**
|
|
55913
|
+
* Holds the board's phone listener, running each start and stop in turn so
|
|
55914
|
+
* two never race to bind. The board ends it with `stop()` as it closes.
|
|
55915
|
+
*/
|
|
55916
|
+
function createPreviewSlot(options) {
|
|
55917
|
+
let running = null;
|
|
55918
|
+
let turn = Promise.resolve();
|
|
55919
|
+
const inTurn = (work) => {
|
|
55920
|
+
const next = turn.then(work, work);
|
|
55921
|
+
turn = next.catch(() => void 0);
|
|
55922
|
+
return next;
|
|
55923
|
+
};
|
|
55924
|
+
const end = async (token) => {
|
|
55925
|
+
if (!running || token !== void 0 && running.token !== token) return false;
|
|
55926
|
+
const ending = running;
|
|
55927
|
+
running = null;
|
|
55928
|
+
await ending.close();
|
|
55929
|
+
return true;
|
|
55930
|
+
};
|
|
55931
|
+
return {
|
|
55932
|
+
start: (project, host, port) => inTurn(async () => {
|
|
55933
|
+
await end();
|
|
55934
|
+
running = await startPreviewListener({
|
|
55935
|
+
...options,
|
|
55936
|
+
project,
|
|
55937
|
+
host,
|
|
55938
|
+
port
|
|
55939
|
+
});
|
|
55940
|
+
return running;
|
|
55941
|
+
}),
|
|
55942
|
+
stop: (token) => inTurn(() => end(token))
|
|
55943
|
+
};
|
|
55944
|
+
}
|
|
54976
55945
|
// src/server/start.ts
|
|
54977
55946
|
const HOSTNAME = "127.0.0.1";
|
|
54978
55947
|
/**
|
|
@@ -55231,6 +56200,11 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
55231
56200
|
measure
|
|
55232
56201
|
});
|
|
55233
56202
|
const assetUsage = createAssetUsage(root);
|
|
56203
|
+
const preview = createPreviewSlot({
|
|
56204
|
+
root,
|
|
56205
|
+
facesDir,
|
|
56206
|
+
tokens
|
|
56207
|
+
});
|
|
55234
56208
|
const app = createApp({
|
|
55235
56209
|
clientDir,
|
|
55236
56210
|
facesDir,
|
|
@@ -55246,6 +56220,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
55246
56220
|
renderFrame,
|
|
55247
56221
|
renderFilmstrip,
|
|
55248
56222
|
clipboard: clipboardFiles(),
|
|
56223
|
+
preview,
|
|
55249
56224
|
thumbnails,
|
|
55250
56225
|
measure,
|
|
55251
56226
|
frameVersion: tracker.version,
|
|
@@ -55360,7 +56335,8 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
55360
56335
|
watcher.close(),
|
|
55361
56336
|
hub.close(),
|
|
55362
56337
|
browser.close(),
|
|
55363
|
-
emptyTrash(root)
|
|
56338
|
+
emptyTrash(root),
|
|
56339
|
+
preview.stop()
|
|
55364
56340
|
]);
|
|
55365
56341
|
await new Promise((done, fail) => {
|
|
55366
56342
|
server.close((error) => error ? fail(error) : done());
|
|
@@ -55809,6 +56785,7 @@ function createProgram(context) {
|
|
|
55809
56785
|
registerServe(program, faced);
|
|
55810
56786
|
registerShow(program, context);
|
|
55811
56787
|
registerOpen(program, context);
|
|
56788
|
+
registerPreview(program, context);
|
|
55812
56789
|
registerSelection(program, context);
|
|
55813
56790
|
registerList(program, context);
|
|
55814
56791
|
registerProject(program, context);
|