frameboard 0.32.0 → 0.34.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 +1542 -97
- package/dist/client/assets/index-Bw5nMnAO.css +2 -0
- package/dist/client/assets/index-CDrU_o7Y.js +178 -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,18 +9387,117 @@ 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));
|
|
9400
|
+
return {
|
|
9401
|
+
x: left,
|
|
9402
|
+
y: top,
|
|
9403
|
+
width: right - left,
|
|
9404
|
+
height: bottom - top
|
|
9405
|
+
};
|
|
9406
|
+
}
|
|
9407
|
+
// src/shared/present-transition.ts
|
|
9408
|
+
/**
|
|
9409
|
+
* The transitions present mode draws between slides, in the order the
|
|
9410
|
+
* inspector lists them. The list is the board's own and a project adds
|
|
9411
|
+
* none yet, so a name outside it reads as no transition.
|
|
9412
|
+
*/
|
|
9413
|
+
const TRANSITIONS = [
|
|
9414
|
+
"none",
|
|
9415
|
+
"fade",
|
|
9416
|
+
"slide",
|
|
9417
|
+
"push",
|
|
9418
|
+
"zoom",
|
|
9419
|
+
"flip",
|
|
9420
|
+
"dissolve"
|
|
9421
|
+
];
|
|
9422
|
+
const TRANSITION_LABELS = {
|
|
9423
|
+
none: "None",
|
|
9424
|
+
fade: "Fade",
|
|
9425
|
+
slide: "Slide",
|
|
9426
|
+
push: "Push",
|
|
9427
|
+
zoom: "Zoom",
|
|
9428
|
+
flip: "Flip",
|
|
9429
|
+
dissolve: "Dissolve"
|
|
9430
|
+
};
|
|
9431
|
+
/** The way a directed transition moves the incoming slide, as a slide tool's effect options name it. */
|
|
9432
|
+
const DIRECTIONS = [
|
|
9433
|
+
"left",
|
|
9434
|
+
"right",
|
|
9435
|
+
"up",
|
|
9436
|
+
"down"
|
|
9437
|
+
];
|
|
9438
|
+
/** The transitions that take a direction. The rest ignore one. */
|
|
9439
|
+
const DIRECTED = ["slide", "push"];
|
|
9440
|
+
/** The shortest and longest transition a record holds, so a typo never freezes a talk. */
|
|
9441
|
+
const TRANSITION_MS = {
|
|
9442
|
+
min: 100,
|
|
9443
|
+
max: 5e3
|
|
9444
|
+
};
|
|
9445
|
+
function takesDirection(name) {
|
|
9446
|
+
return DIRECTED.includes(name);
|
|
9447
|
+
}
|
|
9448
|
+
function transitionNameOf(value) {
|
|
9449
|
+
return TRANSITIONS.find((name) => name === value) ?? null;
|
|
9450
|
+
}
|
|
9451
|
+
/**
|
|
9452
|
+
* A stored transition as a reader takes it, or null for anything but an
|
|
9453
|
+
* object naming a known transition. A direction or a duration no reader
|
|
9454
|
+
* understands reads as absent, so it falls to the default rather than
|
|
9455
|
+
* hiding the transition.
|
|
9456
|
+
*/
|
|
9457
|
+
function transitionOf(value) {
|
|
9458
|
+
if (typeof value !== "object" || value === null) return null;
|
|
9459
|
+
const held = value;
|
|
9460
|
+
const name = transitionNameOf(held.name);
|
|
9461
|
+
if (!name) return null;
|
|
9462
|
+
const direction = DIRECTIONS.find((candidate) => candidate === held.direction);
|
|
9463
|
+
const ms = msOf(held.ms);
|
|
9306
9464
|
return {
|
|
9307
|
-
|
|
9308
|
-
|
|
9309
|
-
|
|
9310
|
-
height: Math.max(box.height, ...boxes.map(({ height }) => height))
|
|
9465
|
+
name,
|
|
9466
|
+
...direction ? { direction } : {},
|
|
9467
|
+
...ms === void 0 ? {} : { ms }
|
|
9311
9468
|
};
|
|
9312
9469
|
}
|
|
9470
|
+
function msOf(value) {
|
|
9471
|
+
if (typeof value !== "number" || !Number.isInteger(value)) return void 0;
|
|
9472
|
+
if (value < TRANSITION_MS.min || value > TRANSITION_MS.max) return void 0;
|
|
9473
|
+
return value;
|
|
9474
|
+
}
|
|
9475
|
+
/**
|
|
9476
|
+
* The attributes marking an element as a step of its slide. Present mode
|
|
9477
|
+
* alone reads them, so the file shows every step everywhere else.
|
|
9478
|
+
*/
|
|
9479
|
+
const STEP_ATTRIBUTES = {
|
|
9480
|
+
step: "data-step",
|
|
9481
|
+
effect: "data-step-effect",
|
|
9482
|
+
start: "data-step-start"
|
|
9483
|
+
};
|
|
9484
|
+
/** The entrances a step takes, a slide tool's first five. */
|
|
9485
|
+
const STEP_EFFECTS = [
|
|
9486
|
+
"appear",
|
|
9487
|
+
"fade",
|
|
9488
|
+
"fly",
|
|
9489
|
+
"wipe",
|
|
9490
|
+
"zoom"
|
|
9491
|
+
];
|
|
9492
|
+
/**
|
|
9493
|
+
* When a step shows: on its own press, with the step before it, or right
|
|
9494
|
+
* after the step before it finishes.
|
|
9495
|
+
*/
|
|
9496
|
+
const STEP_STARTS = [
|
|
9497
|
+
"click",
|
|
9498
|
+
"with",
|
|
9499
|
+
"after"
|
|
9500
|
+
];
|
|
9313
9501
|
// src/shared/records/board.ts
|
|
9314
9502
|
const boardFileSchema = looseObject({ version: literal(1) });
|
|
9315
9503
|
/** A project's own check rules, absent meaning the built-in rules alone. */
|
|
@@ -9343,7 +9531,9 @@ const layoutEntrySchema = looseObject({
|
|
|
9343
9531
|
widths: union([array$1(looseObject({
|
|
9344
9532
|
width: int$1().min(1),
|
|
9345
9533
|
height: int$1().min(1)
|
|
9346
|
-
})), unknown()]).optional()
|
|
9534
|
+
})), unknown()]).optional(),
|
|
9535
|
+
device: unknown().optional(),
|
|
9536
|
+
transition: unknown().optional()
|
|
9347
9537
|
});
|
|
9348
9538
|
/** A named box grouping the frames whose center it holds, which it never lists. */
|
|
9349
9539
|
const sectionEntrySchema = looseObject({
|
|
@@ -9356,7 +9546,8 @@ const sectionEntrySchema = looseObject({
|
|
|
9356
9546
|
const layoutFileSchema = looseObject({
|
|
9357
9547
|
version: literal(1),
|
|
9358
9548
|
frames: record(string$1(), layoutEntrySchema),
|
|
9359
|
-
sections: record(string$1(), sectionEntrySchema).optional()
|
|
9549
|
+
sections: record(string$1(), sectionEntrySchema).optional(),
|
|
9550
|
+
present: unknown().optional()
|
|
9360
9551
|
});
|
|
9361
9552
|
// src/shared/sections.ts
|
|
9362
9553
|
/**
|
|
@@ -9474,6 +9665,8 @@ function placeFrames(frames, names) {
|
|
|
9474
9665
|
continue;
|
|
9475
9666
|
}
|
|
9476
9667
|
const scroll = entry.scroll ?? false;
|
|
9668
|
+
const device = deviceOf(entry.device);
|
|
9669
|
+
const transition = transitionOf(entry.transition);
|
|
9477
9670
|
placements.set(name, {
|
|
9478
9671
|
box: {
|
|
9479
9672
|
x: entry.x,
|
|
@@ -9488,6 +9681,8 @@ function placeFrames(frames, names) {
|
|
|
9488
9681
|
hugHeight: !scroll && (entry.hugHeight ?? false),
|
|
9489
9682
|
scroll,
|
|
9490
9683
|
widths: widthsOf(entry.widths),
|
|
9684
|
+
...device ? { device } : {},
|
|
9685
|
+
...transition ? { transition } : {},
|
|
9491
9686
|
placed: true
|
|
9492
9687
|
});
|
|
9493
9688
|
}
|
|
@@ -9506,8 +9701,8 @@ function placeFrames(frames, names) {
|
|
|
9506
9701
|
* the first unplaced file, placing any other past the placed frames alone.
|
|
9507
9702
|
*/
|
|
9508
9703
|
function placeNext(placed) {
|
|
9509
|
-
const right = Math.max(...placed.map(({ box, widths }) => {
|
|
9510
|
-
const extent = drawnExtent(box, widths);
|
|
9704
|
+
const right = Math.max(...placed.map(({ box, widths, device }) => {
|
|
9705
|
+
const extent = drawnExtent(box, widths, device);
|
|
9511
9706
|
return extent.x + extent.width + 80;
|
|
9512
9707
|
}), 0);
|
|
9513
9708
|
const order = Math.max(...placed.map((placement) => placement.order + 1), 0);
|
|
@@ -9564,10 +9759,12 @@ async function scanPage(root, project, name, index) {
|
|
|
9564
9759
|
let frames = {};
|
|
9565
9760
|
let sections = {};
|
|
9566
9761
|
let layoutError = null;
|
|
9762
|
+
let transition = null;
|
|
9567
9763
|
try {
|
|
9568
9764
|
const file = await readRecord(layoutPath, layoutSpec);
|
|
9569
9765
|
frames = file.frames;
|
|
9570
9766
|
sections = file.sections ?? {};
|
|
9767
|
+
transition = pageTransitionOf(file);
|
|
9571
9768
|
} catch (error) {
|
|
9572
9769
|
if (!(error instanceof FrameboardError)) throw error;
|
|
9573
9770
|
layoutError = {
|
|
@@ -9597,10 +9794,17 @@ async function scanPage(root, project, name, index) {
|
|
|
9597
9794
|
path,
|
|
9598
9795
|
index,
|
|
9599
9796
|
layoutError,
|
|
9797
|
+
...transition ? { transition } : {},
|
|
9600
9798
|
frames: stacked,
|
|
9601
9799
|
sections: sectionRecords(sections, stacked)
|
|
9602
9800
|
};
|
|
9603
9801
|
}
|
|
9802
|
+
/** The transition a layout's `present` key holds, null for none or one no reader knows. */
|
|
9803
|
+
function pageTransitionOf(file) {
|
|
9804
|
+
const present = file.present;
|
|
9805
|
+
if (typeof present !== "object" || present === null) return null;
|
|
9806
|
+
return transitionOf(present.transition);
|
|
9807
|
+
}
|
|
9604
9808
|
/** The page's sections bottom first, each naming its members in stacking order. */
|
|
9605
9809
|
function sectionRecords(entries, frames) {
|
|
9606
9810
|
const sections = Object.entries(entries).map(([name, { x, y, width, height, order }]) => ({
|
|
@@ -9692,7 +9896,7 @@ async function isDirectory(path) {
|
|
|
9692
9896
|
}
|
|
9693
9897
|
}
|
|
9694
9898
|
// package.json
|
|
9695
|
-
var version$1 = "0.
|
|
9899
|
+
var version$1 = "0.34.0";
|
|
9696
9900
|
var dependencies = { "playwright-core": "1.65.0" };
|
|
9697
9901
|
var peerDependencies = { "oxfmt": "0.77.0" };
|
|
9698
9902
|
// src/shared/version.ts
|
|
@@ -10206,7 +10410,8 @@ async function addFrame(root, ref, options) {
|
|
|
10206
10410
|
},
|
|
10207
10411
|
...hugs,
|
|
10208
10412
|
scroll,
|
|
10209
|
-
widths
|
|
10413
|
+
widths,
|
|
10414
|
+
...options.device ? { device: options.device } : {}
|
|
10210
10415
|
});
|
|
10211
10416
|
layout.renumber();
|
|
10212
10417
|
}, journal);
|
|
@@ -10372,9 +10577,9 @@ function linkedWidths(ref, requested, { width, hugWidth, held }) {
|
|
|
10372
10577
|
height: held.find((each) => each.width === linked)?.height ?? referenceHeight(linked)
|
|
10373
10578
|
}));
|
|
10374
10579
|
}
|
|
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);
|
|
10580
|
+
/** The x a copy placed beside a frame takes, past its device and the row of linked widths it draws. */
|
|
10581
|
+
function pastExtent({ box, widths, device }) {
|
|
10582
|
+
const extent = drawnExtent(box, widths, device);
|
|
10378
10583
|
return extent.x + extent.width + 80;
|
|
10379
10584
|
}
|
|
10380
10585
|
/**
|
|
@@ -10408,7 +10613,8 @@ function fittedPlacement(placement, height, widths) {
|
|
|
10408
10613
|
* Sets how each frame holds its height in one write under one lock, all of
|
|
10409
10614
|
* them or none. `fixed` keeps the box and clears hugging and scroll. `fit`
|
|
10410
10615
|
* takes the measured height and hugs it, clearing scroll. `scroll` fixes both
|
|
10411
|
-
* axes as `frame resize --scroll` does
|
|
10616
|
+
* axes as `frame resize --scroll` does, at the target's `height` when it
|
|
10617
|
+
* gives one. Every frame is checked before any is
|
|
10412
10618
|
* set: one moved or sized since its `expected` refuses `stale-layout`, leaving
|
|
10413
10619
|
* out an axis the frame hugs, since the server measures that one, and a `fit`
|
|
10414
10620
|
* without `measured` refuses `usage`.
|
|
@@ -10427,15 +10633,15 @@ async function setHeightModes(root, targets, mode, options) {
|
|
|
10427
10633
|
return {
|
|
10428
10634
|
layout,
|
|
10429
10635
|
name: frame.name,
|
|
10430
|
-
placement: heightPlacement(placement, frameRef, mode, target
|
|
10636
|
+
placement: heightPlacement(placement, frameRef, mode, target)
|
|
10431
10637
|
};
|
|
10432
10638
|
});
|
|
10433
10639
|
for (const { layout, name, placement } of next) layout.set(name, placement);
|
|
10434
10640
|
}, options.journal);
|
|
10435
10641
|
return Promise.all(frames.map(({ frame }) => frameRecord(root, frame.project, frame.page, frame.name)));
|
|
10436
10642
|
}
|
|
10437
|
-
function heightPlacement(placement, frameRef, mode, measured) {
|
|
10438
|
-
if (mode === "scroll") return resizedPlacement(placement, frameRef, {}, { scroll: true });
|
|
10643
|
+
function heightPlacement(placement, frameRef, mode, { measured, height }) {
|
|
10644
|
+
if (mode === "scroll") return resizedPlacement(placement, frameRef, height === void 0 ? {} : { height }, { scroll: true });
|
|
10439
10645
|
if (mode === "fixed") return {
|
|
10440
10646
|
...placement,
|
|
10441
10647
|
hugHeight: false,
|
|
@@ -10614,6 +10820,34 @@ async function setFrameFlag(root, ref, flag, { on, ...options }) {
|
|
|
10614
10820
|
[flag]: on
|
|
10615
10821
|
}));
|
|
10616
10822
|
}
|
|
10823
|
+
/**
|
|
10824
|
+
* Sets the device the board draws around a frame, or clears it with null.
|
|
10825
|
+
* The frame's file and box are left as they stand, since the bezel wraps
|
|
10826
|
+
* whatever size the frame is.
|
|
10827
|
+
*/
|
|
10828
|
+
async function setFrameDevice(root, ref, device, options) {
|
|
10829
|
+
return updatePlacement(root, ref, options, (placement) => {
|
|
10830
|
+
const { device: _held, ...rest } = placement;
|
|
10831
|
+
return device ? {
|
|
10832
|
+
...rest,
|
|
10833
|
+
device
|
|
10834
|
+
} : rest;
|
|
10835
|
+
});
|
|
10836
|
+
}
|
|
10837
|
+
/**
|
|
10838
|
+
* Sets the transition a frame arrives with in present mode, over its page's,
|
|
10839
|
+
* or clears it with null so the frame takes its page's. The frame's file and
|
|
10840
|
+
* box are left as they stand.
|
|
10841
|
+
*/
|
|
10842
|
+
async function setFrameTransition(root, ref, transition, options) {
|
|
10843
|
+
return updatePlacement(root, ref, options, (placement) => {
|
|
10844
|
+
const { transition: _held, ...rest } = placement;
|
|
10845
|
+
return transition ? {
|
|
10846
|
+
...rest,
|
|
10847
|
+
transition
|
|
10848
|
+
} : rest;
|
|
10849
|
+
});
|
|
10850
|
+
}
|
|
10617
10851
|
async function deleteFrame(root, ref, options) {
|
|
10618
10852
|
const { journal } = options;
|
|
10619
10853
|
const frame = await resolveFrameRef(root, ref, options);
|
|
@@ -10707,9 +10941,12 @@ var PageLayout = class {
|
|
|
10707
10941
|
* written once it is on or when the entry holds it, and a scroll entry
|
|
10708
10942
|
* writes both hug flags false, since it fixes both axes. `widths` is
|
|
10709
10943
|
* written while it lists one and removed once it lists none, and a held
|
|
10710
|
-
* value no reader understands is left as it stands.
|
|
10944
|
+
* value no reader understands is left as it stands. `device` is written
|
|
10945
|
+
* while the frame holds one and removed once it is cleared, leaving a held
|
|
10946
|
+
* value no reader understands as `widths` does. `transition` is written
|
|
10947
|
+
* the same way as `device`.
|
|
10711
10948
|
*/
|
|
10712
|
-
set(name, { box, order, hidden, locked, scroll, widths, hugWidth: hugsWidth, hugHeight: hugsHeight }) {
|
|
10949
|
+
set(name, { box, order, hidden, locked, scroll, widths, device, transition, hugWidth: hugsWidth, hugHeight: hugsHeight }) {
|
|
10713
10950
|
const hugWidth = hugsWidth && !scroll;
|
|
10714
10951
|
const hugHeight = hugsHeight && !scroll;
|
|
10715
10952
|
const held = this.file.frames[name];
|
|
@@ -10728,12 +10965,29 @@ var PageLayout = class {
|
|
|
10728
10965
|
...widths.length > 0 ? { widths: widths.map(({ width, height }) => ({
|
|
10729
10966
|
width,
|
|
10730
10967
|
height
|
|
10731
|
-
})) } : {}
|
|
10968
|
+
})) } : {},
|
|
10969
|
+
...device ? { device } : {},
|
|
10970
|
+
...transition ? { transition: { ...transition } } : {}
|
|
10732
10971
|
};
|
|
10733
10972
|
if (widths.length === 0 && widthsOf(held?.widths).length > 0) delete entry.widths;
|
|
10973
|
+
if (!device && deviceOf(held?.device)) delete entry.device;
|
|
10974
|
+
if (!transition && transitionOf(held?.transition)) delete entry.transition;
|
|
10734
10975
|
this.file.frames[name] = entry;
|
|
10735
10976
|
this.changed = true;
|
|
10736
10977
|
}
|
|
10978
|
+
/**
|
|
10979
|
+
* Sets the page's transition on the `present` key, or clears it with null,
|
|
10980
|
+
* keeping any other key `present` holds and dropping `present` once empty.
|
|
10981
|
+
*/
|
|
10982
|
+
setTransition(transition) {
|
|
10983
|
+
const held = this.file.present;
|
|
10984
|
+
const present = typeof held === "object" && held !== null && !Array.isArray(held) ? { ...held } : {};
|
|
10985
|
+
if (transition) present.transition = { ...transition };
|
|
10986
|
+
else delete present.transition;
|
|
10987
|
+
if (Object.keys(present).length > 0) this.file.present = present;
|
|
10988
|
+
else delete this.file.present;
|
|
10989
|
+
this.changed = true;
|
|
10990
|
+
}
|
|
10737
10991
|
remove(name) {
|
|
10738
10992
|
delete this.file.frames[name];
|
|
10739
10993
|
this.changed = true;
|
|
@@ -10817,6 +11071,7 @@ function reportEntries(journal, page, before, after) {
|
|
|
10817
11071
|
const to = nowSections[section];
|
|
10818
11072
|
if (!isDeepStrictEqual(from, to)) journal.section(page, section, from, to);
|
|
10819
11073
|
}
|
|
11074
|
+
if (!isDeepStrictEqual(before?.present, after.present)) journal.present(page, before?.present, after.present);
|
|
10820
11075
|
}
|
|
10821
11076
|
function layoutAt(layouts, page) {
|
|
10822
11077
|
const layout = layouts.get(page);
|
|
@@ -30632,12 +30887,12 @@ function swapSpan(source, span, side) {
|
|
|
30632
30887
|
if (!found) return void 0;
|
|
30633
30888
|
const [start, end] = found.range;
|
|
30634
30889
|
const html = source.slice(0, start) + span[OTHER$1[side]] + source.slice(end);
|
|
30890
|
+
const written = parseFrame(html);
|
|
30635
30891
|
const moved = {
|
|
30636
30892
|
...span,
|
|
30637
30893
|
index: found.index,
|
|
30638
|
-
count: tree.elements.length
|
|
30894
|
+
count: span.scope === "element" ? written.elements.length : tree.elements.length
|
|
30639
30895
|
};
|
|
30640
|
-
const written = parseFrame(html);
|
|
30641
30896
|
if (written.elements.length !== moved.count || !matches(html, written.elements[moved.index], span.scope, span[OTHER$1[side]])) return;
|
|
30642
30897
|
return {
|
|
30643
30898
|
html,
|
|
@@ -36561,15 +36816,7 @@ function starterSheet({ accent, font }) {
|
|
|
36561
36816
|
}
|
|
36562
36817
|
// src/server/edit/insert.ts
|
|
36563
36818
|
const SHAPE_SIZE = 100;
|
|
36564
|
-
const FILL_TOKENS = [
|
|
36565
|
-
"--muted",
|
|
36566
|
-
"--secondary",
|
|
36567
|
-
"--accent"
|
|
36568
|
-
];
|
|
36569
|
-
const LINE_TOKEN = "--border";
|
|
36570
36819
|
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
36820
|
const PAINT_VALUE = /^(?:var\(--[\w-]+\)|#[0-9a-f]{6})$/i;
|
|
36574
36821
|
/** Elements no new element can sit inside, by what the parser does with one there. */
|
|
36575
36822
|
const CLOSED = /* @__PURE__ */ new Set([
|
|
@@ -36597,21 +36844,6 @@ const CLOSED = /* @__PURE__ */ new Set([
|
|
|
36597
36844
|
"head"
|
|
36598
36845
|
]);
|
|
36599
36846
|
/**
|
|
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
36847
|
* The family placed text sets, being the project's text font token, else
|
|
36616
36848
|
* Geist, so a frame with no font of its own still passes `default-font`.
|
|
36617
36849
|
*/
|
|
@@ -36658,7 +36890,7 @@ function attribute(text) {
|
|
|
36658
36890
|
function startTag(source, element) {
|
|
36659
36891
|
return spanText(source, element, "start-tag");
|
|
36660
36892
|
}
|
|
36661
|
-
function children(element) {
|
|
36893
|
+
function children$1(element) {
|
|
36662
36894
|
return element.childNodes.filter(hasTag);
|
|
36663
36895
|
}
|
|
36664
36896
|
/** The source offset the gap sits at, or a refusal when the file states none. */
|
|
@@ -36712,7 +36944,7 @@ function insertElement(source, placement, markup, lead = "") {
|
|
|
36712
36944
|
const index = after.elements.findIndex((element) => element.sourceCodeLocation?.startOffset === offset);
|
|
36713
36945
|
const added = after.elements[index];
|
|
36714
36946
|
if (!added || after.elements.length !== before.elements.length + 1 + descendants(added) || added.parentNode !== after.elements[placement.parent] || spanText(written, added, "element") !== markup || !addsOnly(before, after, added)) return refuse$2("verify-failed", `a <${added?.tagName ?? "new element"}> there would change more than the <${parent.tagName}> it goes in, so nothing was written`);
|
|
36715
|
-
const next = children(parent).find((child) => child.sourceCodeLocation?.startOffset === gap.offset);
|
|
36947
|
+
const next = children$1(parent).find((child) => child.sourceCodeLocation?.startOffset === gap.offset);
|
|
36716
36948
|
return {
|
|
36717
36949
|
ok: true,
|
|
36718
36950
|
html: written,
|
|
@@ -36733,7 +36965,7 @@ function insertElement(source, placement, markup, lead = "") {
|
|
|
36733
36965
|
}
|
|
36734
36966
|
/** How many elements `element` holds, at any depth. */
|
|
36735
36967
|
function descendants(element) {
|
|
36736
|
-
return children(element).reduce((count, child) => count + 1 + descendants(child), 0);
|
|
36968
|
+
return children$1(element).reduce((count, child) => count + 1 + descendants(child), 0);
|
|
36737
36969
|
}
|
|
36738
36970
|
/** Whether `after` is `before` with `added` alone added, compared once it is taken out. */
|
|
36739
36971
|
function addsOnly(before, after, added) {
|
|
@@ -36769,7 +37001,7 @@ function locateGap(source, tree, span) {
|
|
|
36769
37001
|
parent: parentIndex,
|
|
36770
37002
|
before: span.placement.before
|
|
36771
37003
|
};
|
|
36772
|
-
const next = children(parent).filter((child) => startTag(source, child) === span.next);
|
|
37004
|
+
const next = children$1(parent).filter((child) => startTag(source, child) === span.next);
|
|
36773
37005
|
const [sibling] = next;
|
|
36774
37006
|
return next.length === 1 && sibling ? {
|
|
36775
37007
|
parent: parentIndex,
|
|
@@ -36808,7 +37040,7 @@ function takeOut$1(source, tree, index) {
|
|
|
36808
37040
|
const parent = element?.parentNode;
|
|
36809
37041
|
if (!element || !at?.startTag || !parent || !hasTag(parent)) return void 0;
|
|
36810
37042
|
const removed = source.slice(0, at.startOffset) + source.slice(at.endOffset);
|
|
36811
|
-
const next = children(parent)[children(parent).indexOf(element) + 1];
|
|
37043
|
+
const next = children$1(parent)[children$1(parent).indexOf(element) + 1];
|
|
36812
37044
|
const placement = {
|
|
36813
37045
|
parent: tree.elements.indexOf(parent),
|
|
36814
37046
|
before: next ? index : null
|
|
@@ -36842,7 +37074,7 @@ function removeElement(source, index) {
|
|
|
36842
37074
|
const parent = element.parentNode;
|
|
36843
37075
|
if (!at || !parent || !hasTag(parent)) return refuse$2("address-mismatch", `the <${element.tagName}> at ${index} is not stated in the file`);
|
|
36844
37076
|
const removed = source.slice(0, at.startOffset) + source.slice(at.endOffset);
|
|
36845
|
-
const next = children(parent)[children(parent).indexOf(element) + 1];
|
|
37077
|
+
const next = children$1(parent)[children$1(parent).indexOf(element) + 1];
|
|
36846
37078
|
const back = insertElement(removed, {
|
|
36847
37079
|
parent: tree.elements.indexOf(parent),
|
|
36848
37080
|
before: next ? index : null
|
|
@@ -36938,7 +37170,7 @@ function isStatic(facts) {
|
|
|
36938
37170
|
const position = facts?.position?.trim().toLowerCase();
|
|
36939
37171
|
return position === void 0 || position === "static";
|
|
36940
37172
|
}
|
|
36941
|
-
function px(value) {
|
|
37173
|
+
function px$1(value) {
|
|
36942
37174
|
return `${Math.round(value * 100) / 100}px`;
|
|
36943
37175
|
}
|
|
36944
37176
|
/**
|
|
@@ -37014,15 +37246,15 @@ function placeElement(source, index, spot, facts, drop = []) {
|
|
|
37014
37246
|
},
|
|
37015
37247
|
{
|
|
37016
37248
|
property: "left",
|
|
37017
|
-
value: px(spot.left)
|
|
37249
|
+
value: px$1(spot.left)
|
|
37018
37250
|
},
|
|
37019
37251
|
{
|
|
37020
37252
|
property: "top",
|
|
37021
|
-
value: px(spot.top)
|
|
37253
|
+
value: px$1(spot.top)
|
|
37022
37254
|
},
|
|
37023
37255
|
...sized.map((axis) => ({
|
|
37024
37256
|
property: axis,
|
|
37025
|
-
value: px(spot[axis] ?? 0)
|
|
37257
|
+
value: px$1(spot[axis] ?? 0)
|
|
37026
37258
|
}))
|
|
37027
37259
|
] : [
|
|
37028
37260
|
{
|
|
@@ -37535,6 +37767,107 @@ function within(element, root) {
|
|
|
37535
37767
|
}
|
|
37536
37768
|
return false;
|
|
37537
37769
|
}
|
|
37770
|
+
// src/server/edit/wrap.ts
|
|
37771
|
+
/** The wrappers a container cannot sit in, or be made from. */
|
|
37772
|
+
const ROOTS = /* @__PURE__ */ new Set([
|
|
37773
|
+
"html",
|
|
37774
|
+
"head",
|
|
37775
|
+
"body"
|
|
37776
|
+
]);
|
|
37777
|
+
function px(value) {
|
|
37778
|
+
return `${Math.round(value * 100) / 100}px`;
|
|
37779
|
+
}
|
|
37780
|
+
function children(element) {
|
|
37781
|
+
return element.childNodes.filter(hasTag);
|
|
37782
|
+
}
|
|
37783
|
+
function subtree(element) {
|
|
37784
|
+
return children(element).reduce((count, child) => count + subtree(child), 1);
|
|
37785
|
+
}
|
|
37786
|
+
function isFree(facts) {
|
|
37787
|
+
const position = facts?.position?.trim().toLowerCase();
|
|
37788
|
+
return position === "absolute" || position === "fixed";
|
|
37789
|
+
}
|
|
37790
|
+
/**
|
|
37791
|
+
* Wraps the sibling elements `indexes` names in one new `div` laid out as
|
|
37792
|
+
* `flow`, written at the first one's place, with every one moved into it in
|
|
37793
|
+
* document order. A free member leaves the flow it is wrapped in otherwise,
|
|
37794
|
+
* so each puts back `position`, `left`, and `top` as back in flow does, and
|
|
37795
|
+
* the container takes `spot` instead, placed freely where the group sat, or
|
|
37796
|
+
* sits in the flow when `spot` is null. `facts` is the static cascade read
|
|
37797
|
+
* by the same index. Elements that are not siblings, the document's own
|
|
37798
|
+
* wrappers, and a parent the file does not state are refused, and the
|
|
37799
|
+
* output is parsed again and refused as `verify-failed` unless only the
|
|
37800
|
+
* parent's contents changed, holding the container and its members.
|
|
37801
|
+
*/
|
|
37802
|
+
function wrapElements(source, indexes, flow, spot, facts) {
|
|
37803
|
+
const tree = parseFrame(source);
|
|
37804
|
+
const named = [...new Set(indexes)].toSorted((a, b) => a - b);
|
|
37805
|
+
const members = named.map((index) => Number.isInteger(index) ? tree.elements[index] : void 0);
|
|
37806
|
+
const [first] = members;
|
|
37807
|
+
const parent = first?.parentNode;
|
|
37808
|
+
if (named.length !== indexes.length || named.length === 0 || !first || !parent || !hasTag(parent) || members.some((member) => !member?.sourceCodeLocation?.startTag || ROOTS.has(member.tagName) || member.parentNode !== parent)) return refuse$2("invalid-address", "a wrap takes stated sibling elements of one parent, each named once");
|
|
37809
|
+
const stated = parent.sourceCodeLocation;
|
|
37810
|
+
if (parent.tagName === "html" || !stated?.startTag) return refuse$2("invalid-container", `the <${parent.tagName}> holding them is not stated in the file, so nothing was written`);
|
|
37811
|
+
const parentIndex = tree.elements.indexOf(parent);
|
|
37812
|
+
let html = source;
|
|
37813
|
+
for (const index of named) {
|
|
37814
|
+
if (!isFree(facts[index])) continue;
|
|
37815
|
+
const placed = placeElement(html, index, null, facts);
|
|
37816
|
+
if (!placed.ok) return placed;
|
|
37817
|
+
html = placed.html;
|
|
37818
|
+
}
|
|
37819
|
+
const flowed = parseFrame(html);
|
|
37820
|
+
const ranges = named.map((index) => flowed.elements[index]).map((member) => {
|
|
37821
|
+
const location = member?.sourceCodeLocation;
|
|
37822
|
+
return location ? [location.startOffset, location.endOffset] : null;
|
|
37823
|
+
});
|
|
37824
|
+
const [start] = ranges;
|
|
37825
|
+
if (!start || ranges.some((range) => !range)) return refuse$2("verify-failed", "a member lost its place in the file, so nothing was written");
|
|
37826
|
+
const indent = /\n[ \t]*$/.exec(html.slice(0, start[0]))?.[0] ?? "";
|
|
37827
|
+
const inner = indent === "" ? "" : `${indent} `;
|
|
37828
|
+
const container = `<div style="${[
|
|
37829
|
+
"display: flex",
|
|
37830
|
+
`flex-direction: ${flow.direction}`,
|
|
37831
|
+
`gap: ${px(flow.gap)}`,
|
|
37832
|
+
...spot ? [
|
|
37833
|
+
"position: absolute",
|
|
37834
|
+
`left: ${px(spot.left)}`,
|
|
37835
|
+
`top: ${px(spot.top)}`
|
|
37836
|
+
] : []
|
|
37837
|
+
].join("; ")}">${ranges.map((range) => `${inner}${html.slice(range?.[0], range?.[1])}`).join("")}${indent}</div>`;
|
|
37838
|
+
let wrapped = html;
|
|
37839
|
+
for (const range of ranges.slice(1).toReversed()) {
|
|
37840
|
+
if (!range) continue;
|
|
37841
|
+
const lead = /\s*$/.exec(wrapped.slice(0, range[0]))?.[0].length ?? 0;
|
|
37842
|
+
wrapped = wrapped.slice(0, range[0] - lead) + wrapped.slice(range[1]);
|
|
37843
|
+
}
|
|
37844
|
+
wrapped = wrapped.slice(0, start[0]) + container + wrapped.slice(start[1]);
|
|
37845
|
+
const order = [...tree.elements.slice(0, named[0]), ...members.flatMap((member) => member ? tree.elements.slice(tree.elements.indexOf(member), tree.elements.indexOf(member) + subtree(member)) : [])];
|
|
37846
|
+
const moved = new Set(order);
|
|
37847
|
+
order.push(...tree.elements.filter((element) => !moved.has(element)));
|
|
37848
|
+
const at = new Map(order.map((element, place) => [tree.elements.indexOf(element), place < (named[0] ?? 0) ? place : place + 1]));
|
|
37849
|
+
const index = named[0] ?? 0;
|
|
37850
|
+
const written = parseFrame(wrapped);
|
|
37851
|
+
const box = written.elements[index];
|
|
37852
|
+
const after = written.elements[parentIndex];
|
|
37853
|
+
const end = stated.endOffset;
|
|
37854
|
+
const unchanged = written.elements.length === tree.elements.length + 1 && box?.tagName === "div" && box.parentNode === after && children(box).map(({ tagName }) => tagName).join() === members.map((member) => member?.tagName).join() && wrapped.slice(0, stated.startTag.endOffset) === source.slice(0, stated.startTag.endOffset) && wrapped.slice(wrapped.length - (source.length - end)) === source.slice(end);
|
|
37855
|
+
if (!after || !unchanged) return refuse$2("verify-failed", "the wrap would change more than its parent’s contents, so nothing was written");
|
|
37856
|
+
return {
|
|
37857
|
+
ok: true,
|
|
37858
|
+
html: wrapped,
|
|
37859
|
+
index,
|
|
37860
|
+
members: indexes.map((named) => at.get(named) ?? named),
|
|
37861
|
+
span: {
|
|
37862
|
+
scope: "element",
|
|
37863
|
+
index: parentIndex,
|
|
37864
|
+
count: written.elements.length,
|
|
37865
|
+
before: spanText(source, parent, "element"),
|
|
37866
|
+
after: spanText(wrapped, after, "element")
|
|
37867
|
+
},
|
|
37868
|
+
remap: (old) => at.get(old) ?? null
|
|
37869
|
+
};
|
|
37870
|
+
}
|
|
37538
37871
|
// src/server/edit/frame-file.ts
|
|
37539
37872
|
const identity = (index) => index;
|
|
37540
37873
|
function stale$1(path) {
|
|
@@ -37588,8 +37921,11 @@ function editFrameFile(path, address, change, sourceAt) {
|
|
|
37588
37921
|
* Edits several elements of a frame file as one write, each found again and
|
|
37589
37922
|
* verified as `editFrameFile` does one, in the order sent through the bytes
|
|
37590
37923
|
* the one before it left. Any refusal writes nothing, so a batch never lands
|
|
37591
|
-
* in part
|
|
37592
|
-
* put both spans back.
|
|
37924
|
+
* in part. Naming one element twice is refused, since one undo could not
|
|
37925
|
+
* put both spans back, except for a text change beside one style change.
|
|
37926
|
+
* That pair answers one span over the whole element, both changes in it,
|
|
37927
|
+
* since an undo checks every span against the bytes as they stand and the
|
|
37928
|
+
* text's own span no longer reads once the style wrote its start tag.
|
|
37593
37929
|
*/
|
|
37594
37930
|
function editFrameFileAll(path, hash, edits, sourceAt) {
|
|
37595
37931
|
const read = readSource(path);
|
|
@@ -37607,7 +37943,7 @@ function editFrameFileAll(path, hash, edits, sourceAt) {
|
|
|
37607
37943
|
if (!found) return collided(path, was, index, source);
|
|
37608
37944
|
indexes.push(found.index);
|
|
37609
37945
|
}
|
|
37610
|
-
if (
|
|
37946
|
+
if (!namedOnceEach(indexes, edits)) return refuse$2("invalid-edit", "a batch names one element twice");
|
|
37611
37947
|
let html = source;
|
|
37612
37948
|
const spans = [];
|
|
37613
37949
|
for (const [at, { change }] of edits.entries()) {
|
|
@@ -37622,11 +37958,46 @@ function editFrameFileAll(path, hash, edits, sourceAt) {
|
|
|
37622
37958
|
hash: contentHash(html),
|
|
37623
37959
|
from: read.hash,
|
|
37624
37960
|
indexes,
|
|
37625
|
-
spans,
|
|
37961
|
+
spans: mergedTwice(source, html, indexes, spans),
|
|
37626
37962
|
remap: identity
|
|
37627
37963
|
};
|
|
37628
37964
|
}
|
|
37629
37965
|
/**
|
|
37966
|
+
* The spans of a batch with the two of an element named twice put together
|
|
37967
|
+
* as one over the whole element, from its bytes in `source` to its bytes in
|
|
37968
|
+
* `html`, at the place the first of the two held.
|
|
37969
|
+
*/
|
|
37970
|
+
function mergedTwice(source, html, indexes, spans) {
|
|
37971
|
+
const twice = indexes.filter((index, at) => indexes.indexOf(index) !== at);
|
|
37972
|
+
if (twice.length === 0) return [...spans];
|
|
37973
|
+
const was = parseFrame(source).elements;
|
|
37974
|
+
const now = parseFrame(html).elements;
|
|
37975
|
+
return spans.flatMap((span, at) => {
|
|
37976
|
+
const index = indexes[at] ?? -1;
|
|
37977
|
+
if (!twice.includes(index)) return [span];
|
|
37978
|
+
if (indexes.indexOf(index) !== at) return [];
|
|
37979
|
+
const before = was[index];
|
|
37980
|
+
const after = now[index];
|
|
37981
|
+
if (!before || !after) return [span];
|
|
37982
|
+
return [{
|
|
37983
|
+
scope: "element",
|
|
37984
|
+
index,
|
|
37985
|
+
count: now.length,
|
|
37986
|
+
before: spanText(source, before, "element"),
|
|
37987
|
+
after: spanText(html, after, "element")
|
|
37988
|
+
}];
|
|
37989
|
+
});
|
|
37990
|
+
}
|
|
37991
|
+
/**
|
|
37992
|
+
* Whether each element a batch names is named once, or twice only as one
|
|
37993
|
+
* `text` change and one `style` or `styles` change.
|
|
37994
|
+
*/
|
|
37995
|
+
function namedOnceEach(indexes, edits) {
|
|
37996
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
37997
|
+
for (const [at, index] of indexes.entries()) kinds.set(index, [...kinds.get(index) ?? [], edits[at]?.change.kind ?? ""]);
|
|
37998
|
+
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"));
|
|
37999
|
+
}
|
|
38000
|
+
/**
|
|
37630
38001
|
* Writes one new element into a frame file the way `editFrameFile` writes an
|
|
37631
38002
|
* edit, through a temporary file and a rename after reading the file again.
|
|
37632
38003
|
* A hash the file no longer has is refused as stale with no search, since the
|
|
@@ -37796,6 +38167,28 @@ function placeFrameFileAll(path, hash, places, factsOf) {
|
|
|
37796
38167
|
};
|
|
37797
38168
|
}
|
|
37798
38169
|
/**
|
|
38170
|
+
* Wraps sibling elements of a frame file in one flow container, written as
|
|
38171
|
+
* `moveFrameFile` writes and refused as stale on a hash the file no longer
|
|
38172
|
+
* has, since the indices name nothing once the file moved. `facts` is the
|
|
38173
|
+
* static cascade read from the bytes `hash` names.
|
|
38174
|
+
*/
|
|
38175
|
+
function wrapFrameFile(path, hash, indexes, flow, spot, facts) {
|
|
38176
|
+
const read = readSource(path);
|
|
38177
|
+
if (!read.ok) return read;
|
|
38178
|
+
if (read.hash !== hash) return stale$1(path);
|
|
38179
|
+
const wrapped = wrapElements(read.source, indexes, flow, spot, facts);
|
|
38180
|
+
if (!wrapped.ok) return wrapped;
|
|
38181
|
+
if (!replaceFile(path, hash, wrapped.html)) return stale$1(path);
|
|
38182
|
+
return {
|
|
38183
|
+
ok: true,
|
|
38184
|
+
hash: contentHash(wrapped.html),
|
|
38185
|
+
index: wrapped.index,
|
|
38186
|
+
members: wrapped.members,
|
|
38187
|
+
span: wrapped.span,
|
|
38188
|
+
remap: wrapped.remap
|
|
38189
|
+
};
|
|
38190
|
+
}
|
|
38191
|
+
/**
|
|
37799
38192
|
* Replaces a raw color with a token across the subtree `root` names, or the
|
|
37800
38193
|
* frame's body when undefined, written as `placeFrameFile` writes and refused
|
|
37801
38194
|
* as stale on a hash the file no longer has, so a retried replace lands once.
|
|
@@ -37985,6 +38378,17 @@ async function movePage(root, ref, { index, ...options }) {
|
|
|
37985
38378
|
const page = await resolvePageRef(root, ref, options);
|
|
37986
38379
|
return recordOf(root, page, await reorder(root, page, async (order) => insert(order.filter((name) => name !== page.name), page.name, index), options.journal));
|
|
37987
38380
|
}
|
|
38381
|
+
/**
|
|
38382
|
+
* Sets the transition present mode draws between the page's slides, or
|
|
38383
|
+
* clears it with null, writing only the `present` key of its `layout.json`
|
|
38384
|
+
* and leaving every frame file as it stands.
|
|
38385
|
+
*/
|
|
38386
|
+
async function setPageTransition(root, ref, transition, { journal, ...options }) {
|
|
38387
|
+
const page = await resolvePageRef(root, ref, options);
|
|
38388
|
+
await withLayouts([page.path], async (layouts) => layoutAt(layouts, page.path).setTransition(transition), journal);
|
|
38389
|
+
const { pages } = await readPageOrder(join(root, page.project));
|
|
38390
|
+
return scanPage(root, page.project, page.name, pages.indexOf(page.name));
|
|
38391
|
+
}
|
|
37988
38392
|
async function deletePage(root, ref, { journal, ...options }) {
|
|
37989
38393
|
const page = await resolvePageRef(root, ref, options);
|
|
37990
38394
|
await reorder(root, page, async (order) => {
|
|
@@ -38455,7 +38859,7 @@ async function emptyTrash(root) {
|
|
|
38455
38859
|
// src/server/history/changes.ts
|
|
38456
38860
|
/** The records a change writes, whose locks are held while it is checked and written. */
|
|
38457
38861
|
function lockPaths(change) {
|
|
38458
|
-
if (change.kind === "entry" || change.kind === "section") return [change.layout];
|
|
38862
|
+
if (change.kind === "entry" || change.kind === "section" || change.kind === "present") return [change.layout];
|
|
38459
38863
|
if (change.kind === "pages" || change.kind === "project") return [change.file];
|
|
38460
38864
|
return [];
|
|
38461
38865
|
}
|
|
@@ -38484,6 +38888,10 @@ async function reads(change, side) {
|
|
|
38484
38888
|
const file = await readRecord(change.layout, layoutSpec);
|
|
38485
38889
|
return isDeepStrictEqual(file.sections?.[change.section], change[side]);
|
|
38486
38890
|
}
|
|
38891
|
+
case "present": {
|
|
38892
|
+
const file = await readRecord(change.layout, layoutSpec);
|
|
38893
|
+
return isDeepStrictEqual(file.present, change[side]);
|
|
38894
|
+
}
|
|
38487
38895
|
case "pages": {
|
|
38488
38896
|
const file = await readRecord(change.file, {
|
|
38489
38897
|
...projectSpec,
|
|
@@ -38556,6 +38964,15 @@ async function restore(change, side) {
|
|
|
38556
38964
|
});
|
|
38557
38965
|
return;
|
|
38558
38966
|
}
|
|
38967
|
+
case "present": {
|
|
38968
|
+
const { present: _held, ...file } = await readRecord(change.layout, layoutSpec);
|
|
38969
|
+
const present = change[side];
|
|
38970
|
+
await writeRecord(change.layout, present === void 0 ? file : {
|
|
38971
|
+
...file,
|
|
38972
|
+
present
|
|
38973
|
+
});
|
|
38974
|
+
return;
|
|
38975
|
+
}
|
|
38559
38976
|
case "pages": {
|
|
38560
38977
|
const file = await readRecord(change.file, {
|
|
38561
38978
|
...projectSpec,
|
|
@@ -38725,6 +39142,15 @@ var StepJournal = class {
|
|
|
38725
39142
|
after
|
|
38726
39143
|
});
|
|
38727
39144
|
}
|
|
39145
|
+
present(page, before, after) {
|
|
39146
|
+
const layout = join(page, LAYOUT_FILE);
|
|
39147
|
+
this.changes.push({
|
|
39148
|
+
kind: "present",
|
|
39149
|
+
layout,
|
|
39150
|
+
before,
|
|
39151
|
+
after
|
|
39152
|
+
});
|
|
39153
|
+
}
|
|
38728
39154
|
pages(project, before, after) {
|
|
38729
39155
|
const file = join(project, PROJECT_FILE);
|
|
38730
39156
|
this.changes.push({
|
|
@@ -38986,11 +39412,12 @@ var History = class {
|
|
|
38986
39412
|
return run;
|
|
38987
39413
|
}
|
|
38988
39414
|
};
|
|
38989
|
-
/** What a refusal names as overtaken, being a frame, a section, a page, the page order, or a filed project. */
|
|
39415
|
+
/** What a refusal names as overtaken, being a frame, a section, a page, the slide transition, the page order, or a filed project. */
|
|
38990
39416
|
function nameOf(change) {
|
|
38991
39417
|
if (change.kind === "entry") return change.frame;
|
|
38992
39418
|
if (change.kind === "section") return `section ${change.section}`;
|
|
38993
39419
|
if (change.kind === "pages") return "the page order";
|
|
39420
|
+
if (change.kind === "present") return "the slide transition";
|
|
38994
39421
|
if (change.kind === "project") return basename(dirname(change.file));
|
|
38995
39422
|
if (change.kind === "token") return change.name;
|
|
38996
39423
|
const path = change.kind === "moved" ? change.to : change.path;
|
|
@@ -39366,11 +39793,42 @@ object$1({
|
|
|
39366
39793
|
sized: array$1(placedSizeSchema)
|
|
39367
39794
|
})).optional()
|
|
39368
39795
|
});
|
|
39796
|
+
object$1({
|
|
39797
|
+
ref: string$1(),
|
|
39798
|
+
index: int$1().min(0),
|
|
39799
|
+
members: array$1(int$1().min(0)),
|
|
39800
|
+
hash
|
|
39801
|
+
});
|
|
39369
39802
|
object$1({
|
|
39370
39803
|
ref: string$1(),
|
|
39371
39804
|
hash,
|
|
39372
39805
|
count: int$1().min(0)
|
|
39373
39806
|
});
|
|
39807
|
+
// src/shared/shape-paint.ts
|
|
39808
|
+
const FILL_TOKENS = [
|
|
39809
|
+
"--muted",
|
|
39810
|
+
"--secondary",
|
|
39811
|
+
"--accent"
|
|
39812
|
+
];
|
|
39813
|
+
const LINE_TOKEN = "--border";
|
|
39814
|
+
/** Raw on purpose, so the check names it once the project sets no color token. */
|
|
39815
|
+
const RAW_GREY = "#d9d9d9";
|
|
39816
|
+
/**
|
|
39817
|
+
* A shape's fill, being the first of the muted, secondary, and accent tokens
|
|
39818
|
+
* the project sets, else its first color token, and its line, being the
|
|
39819
|
+
* border token else that first color token. With no color token at all, both
|
|
39820
|
+
* are a raw grey. The server writes it on a placed shape, and the board
|
|
39821
|
+
* draws a dragged shape's preview in it.
|
|
39822
|
+
*/
|
|
39823
|
+
function shapePaint(tokens) {
|
|
39824
|
+
const names = new Set(tokens.map((row) => row.name));
|
|
39825
|
+
const firstColor = tokens.find((row) => row.group === "color")?.name;
|
|
39826
|
+
const paint = (name) => name === void 0 ? RAW_GREY : `var(${name})`;
|
|
39827
|
+
return {
|
|
39828
|
+
fill: paint(FILL_TOKENS.find((name) => names.has(name)) ?? firstColor),
|
|
39829
|
+
line: paint(names.has(LINE_TOKEN) ? LINE_TOKEN : firstColor)
|
|
39830
|
+
};
|
|
39831
|
+
}
|
|
39374
39832
|
// src/server/routes/edit.ts
|
|
39375
39833
|
const value = string$1().max(1e4);
|
|
39376
39834
|
const name$1 = string$1().min(1).max(256);
|
|
@@ -39496,6 +39954,21 @@ const placeSchema = union([object$1({
|
|
|
39496
39954
|
...spotFields
|
|
39497
39955
|
})).min(1).max(BATCH)
|
|
39498
39956
|
})]);
|
|
39957
|
+
const wrapSchema = object$1({
|
|
39958
|
+
ref: string$1().min(1).max(1024),
|
|
39959
|
+
hash: string$1().regex(/^[0-9a-f]{64}$/),
|
|
39960
|
+
/** The sibling elements to wrap, by their index in the bytes `hash` names. */
|
|
39961
|
+
indexes: array$1(int$1().min(0)).min(1).max(BATCH),
|
|
39962
|
+
flow: object$1({
|
|
39963
|
+
direction: _enum$1(["row", "column"]),
|
|
39964
|
+
gap: number().min(0).max(1e4)
|
|
39965
|
+
}),
|
|
39966
|
+
/** Where the container sits when every member was placed freely, null to sit in the flow. */
|
|
39967
|
+
spot: object$1({
|
|
39968
|
+
left: offset,
|
|
39969
|
+
top: offset
|
|
39970
|
+
}).nullable()
|
|
39971
|
+
});
|
|
39499
39972
|
const recolorSchema = object$1({
|
|
39500
39973
|
ref: string$1().min(1).max(1024),
|
|
39501
39974
|
hash: string$1().regex(/^[0-9a-f]{64}$/),
|
|
@@ -39928,6 +40401,45 @@ function editRoutes(root, access, history, version, sheets) {
|
|
|
39928
40401
|
data
|
|
39929
40402
|
});
|
|
39930
40403
|
});
|
|
40404
|
+
app.post("/api/frames/wrap", requireWriter(access), async (c) => {
|
|
40405
|
+
const body = await parseBody$1(c.req.raw, wrapSchema);
|
|
40406
|
+
const frame = await resolveFrameRef(root, body.ref, { cwd: root });
|
|
40407
|
+
const ref = `${frame.project}/${frame.page}/${frame.name}`;
|
|
40408
|
+
await refuseClaimed(root, [ref], /* @__PURE__ */ new Date());
|
|
40409
|
+
const source = readFrame(frame);
|
|
40410
|
+
const facts = contentHash(source.html) === body.hash ? elementPlaceFacts(source, tokenSheets(frame.project)) : [];
|
|
40411
|
+
const result = wrapFrameFile(frame.path, body.hash, body.indexes, body.flow, body.spot, facts);
|
|
40412
|
+
if (!result.ok) return c.json({
|
|
40413
|
+
ok: false,
|
|
40414
|
+
error: {
|
|
40415
|
+
code: result.reason,
|
|
40416
|
+
message: result.detail,
|
|
40417
|
+
details: {
|
|
40418
|
+
ref,
|
|
40419
|
+
indexes: body.indexes
|
|
40420
|
+
}
|
|
40421
|
+
}
|
|
40422
|
+
}, 409);
|
|
40423
|
+
const journal = history.journal();
|
|
40424
|
+
journal.element(frame.path, ref, result.span);
|
|
40425
|
+
history.record({
|
|
40426
|
+
id: journal.id,
|
|
40427
|
+
changes: journal.changes,
|
|
40428
|
+
page: null,
|
|
40429
|
+
frames: [ref]
|
|
40430
|
+
});
|
|
40431
|
+
await follow(frame, body.hash, result.hash, result.remap);
|
|
40432
|
+
const data = {
|
|
40433
|
+
ref,
|
|
40434
|
+
index: result.index,
|
|
40435
|
+
members: [...result.members],
|
|
40436
|
+
hash: result.hash
|
|
40437
|
+
};
|
|
40438
|
+
return c.json({
|
|
40439
|
+
ok: true,
|
|
40440
|
+
data
|
|
40441
|
+
});
|
|
40442
|
+
});
|
|
39931
40443
|
app.post("/api/frames/recolor", requireWriter(access), async (c) => {
|
|
39932
40444
|
const body = await parseBody$1(c.req.raw, recolorSchema);
|
|
39933
40445
|
const frame = await resolveFrameRef(root, body.ref, { cwd: root });
|
|
@@ -40490,9 +41002,11 @@ const CONTENT_TYPES$1 = {
|
|
|
40490
41002
|
* each use, so an edit shows on the next load and an unchanged file answers
|
|
40491
41003
|
* 304 with no body. A frame path carrying `?at=<hash>` serves the
|
|
40492
41004
|
* version `version` holds under that hash in its place, with the same head,
|
|
40493
|
-
* and any other path carrying it answers 404.
|
|
41005
|
+
* and any other path carrying it answers 404. `base` prefixes the sheet URLs
|
|
41006
|
+
* the head imports, for a listener serving these routes under a path of its
|
|
41007
|
+
* own, since the head names them from the server's root.
|
|
40494
41008
|
*/
|
|
40495
|
-
function frameRoutes(root, look, version) {
|
|
41009
|
+
function frameRoutes(root, look, version, base = "") {
|
|
40496
41010
|
const app = new Hono();
|
|
40497
41011
|
app.get("/frames/*", async (c) => {
|
|
40498
41012
|
const parts = decodeSegments(new URL(c.req.url).pathname.slice(8).split("/"));
|
|
@@ -40547,7 +41061,7 @@ function frameRoutes(root, look, version) {
|
|
|
40547
41061
|
if (held === null) return c.notFound();
|
|
40548
41062
|
bytes = new TextEncoder().encode(held);
|
|
40549
41063
|
}
|
|
40550
|
-
const body = injectHead(bytes, frameHead(sheetUrls(project, look.sheets(project)), contentHash(bytes)));
|
|
41064
|
+
const body = injectHead(bytes, frameHead(sheetUrls(project, look.sheets(project)).map((url) => `${base}${url}`), contentHash(bytes)));
|
|
40551
41065
|
return c.body(body, 200, {
|
|
40552
41066
|
"Content-Type": contentType,
|
|
40553
41067
|
"Cache-Control": "no-store"
|
|
@@ -40626,18 +41140,31 @@ async function resolveFile(root, [project, page, ...rest]) {
|
|
|
40626
41140
|
if (!project || !page) return null;
|
|
40627
41141
|
const projectSheet = rest.length === 0 && page === "tokens.css";
|
|
40628
41142
|
if (rest.length === 0 && !projectSheet) return null;
|
|
40629
|
-
if (page !== "assets" && !projectSheet && (rest.length > 1 || isRecord$
|
|
41143
|
+
if (page !== "assets" && !projectSheet && (rest.length > 1 || isRecord$2(rest[0] ?? ""))) return null;
|
|
40630
41144
|
try {
|
|
40631
41145
|
const projectDir = await realpath(join(root, project));
|
|
40632
41146
|
if (!projectDir.startsWith(root + sep)) return null;
|
|
40633
41147
|
const file = await realpath(join(projectDir, page, ...rest));
|
|
40634
41148
|
if (!file.startsWith(projectDir + sep)) return null;
|
|
41149
|
+
if (!servableInProject(relative(projectDir, file).split(sep))) return null;
|
|
40635
41150
|
return (await stat(file)).isFile() ? file : null;
|
|
40636
41151
|
} catch {
|
|
40637
41152
|
return null;
|
|
40638
41153
|
}
|
|
40639
41154
|
}
|
|
40640
|
-
|
|
41155
|
+
/**
|
|
41156
|
+
* Whether a file the request reached is one the route may serve, read off
|
|
41157
|
+
* where it really sits in its project rather than the name asked for, so a
|
|
41158
|
+
* symlink in `assets/` naming a record or a dot-named path is refused as the
|
|
41159
|
+
* name itself would be.
|
|
41160
|
+
*/
|
|
41161
|
+
function servableInProject(segments) {
|
|
41162
|
+
if (segments.some((segment) => segment.startsWith("."))) return false;
|
|
41163
|
+
const [first = "", name = ""] = segments;
|
|
41164
|
+
if (segments.length === 1) return first === TOKEN_FILE;
|
|
41165
|
+
return first === "assets" || !isRecord$2(name);
|
|
41166
|
+
}
|
|
41167
|
+
function isRecord$2(name) {
|
|
40641
41168
|
return name === "layout.json" || name === NOTES_FILE$1;
|
|
40642
41169
|
}
|
|
40643
41170
|
// src/server/routes/look.ts
|
|
@@ -40655,15 +41182,17 @@ const CONTENT_TYPES = {
|
|
|
40655
41182
|
* `--tokens` sheet, null for none, or absent to read the one a running
|
|
40656
41183
|
* server recorded in the address file on each request. `version` serves the
|
|
40657
41184
|
* frame versions an agent write replaced, absent where nothing holds them.
|
|
41185
|
+
* `base` prefixes the sheet URLs a served frame imports, for a listener that
|
|
41186
|
+
* serves these routes under a path of its own.
|
|
40658
41187
|
*/
|
|
40659
|
-
function servedFrames(root, { facesDir, tokens, version }) {
|
|
41188
|
+
function servedFrames(root, { facesDir, tokens, version, base }) {
|
|
40660
41189
|
const look = { sheets: (project) => tokenSheetPaths(root, project, tokens) };
|
|
40661
41190
|
const routes = new Hono();
|
|
40662
41191
|
routes.route("/", lookRoutes({
|
|
40663
41192
|
facesDir,
|
|
40664
41193
|
boardSheet: () => boardSheetPath(root, tokens)
|
|
40665
41194
|
}));
|
|
40666
|
-
routes.route("/", frameRoutes(root, look, version));
|
|
41195
|
+
routes.route("/", frameRoutes(root, look, version, base));
|
|
40667
41196
|
return {
|
|
40668
41197
|
look,
|
|
40669
41198
|
routes
|
|
@@ -41120,9 +41649,12 @@ const DEFAULT_SCALE = 2;
|
|
|
41120
41649
|
* frame rendered at `scale` times its layout size, twice when no scale is
|
|
41121
41650
|
* given. An added `filmstrip=<n>` of 2 or more renders `n` moments of its
|
|
41122
41651
|
* 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
|
-
*
|
|
41652
|
+
* `motion-missing` and one that never ends as `motion-unbounded`. An added
|
|
41653
|
+
* `device=1` draws a frame holding a device inside its body, and leaves a
|
|
41654
|
+
* frame holding none as it is. A filmstrip draws no device, so the two
|
|
41655
|
+
* together refuse as `usage`. It takes no token, since the image shows only
|
|
41656
|
+
* what the frame route already serves, and a refusal answers the CLI's
|
|
41657
|
+
* `{ ok, error }` envelope.
|
|
41126
41658
|
*/
|
|
41127
41659
|
function pngRoutes(root, render, renderFilmstrip) {
|
|
41128
41660
|
const app = new Hono();
|
|
@@ -41132,14 +41664,19 @@ function pngRoutes(root, render, renderFilmstrip) {
|
|
|
41132
41664
|
const theme = c.req.query("theme") ?? "";
|
|
41133
41665
|
const scale = parseScale$1(c.req.query("scale"));
|
|
41134
41666
|
const filmstrip = parseFilmstrip(c.req.query("filmstrip"));
|
|
41135
|
-
|
|
41667
|
+
const device = parseDevice(c.req.query("device"));
|
|
41668
|
+
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
41669
|
ref,
|
|
41137
41670
|
theme,
|
|
41138
41671
|
scale: c.req.query("scale") ?? null,
|
|
41139
|
-
filmstrip: c.req.query("filmstrip") ?? null
|
|
41672
|
+
filmstrip: c.req.query("filmstrip") ?? null,
|
|
41673
|
+
device: c.req.query("device") ?? null
|
|
41140
41674
|
});
|
|
41141
|
-
const frame = await readFrame$1(root, ref, { cwd: root });
|
|
41142
|
-
const bytes = filmstrip === void 0 ? await render(
|
|
41675
|
+
const { device: held, ...frame } = await readFrame$1(root, ref, { cwd: root });
|
|
41676
|
+
const bytes = filmstrip === void 0 ? await render(device && held ? {
|
|
41677
|
+
...frame,
|
|
41678
|
+
device: held
|
|
41679
|
+
} : frame, theme, scale) : await renderFilmstrip(frame, theme, scale, filmstrip);
|
|
41143
41680
|
return c.body(new Uint8Array(bytes), 200, {
|
|
41144
41681
|
"Content-Type": "image/png",
|
|
41145
41682
|
"Cache-Control": "no-store"
|
|
@@ -41166,12 +41703,115 @@ function parseScale$1(value) {
|
|
|
41166
41703
|
if (value === "1" || value === "2" || value === "3") return Number(value);
|
|
41167
41704
|
return null;
|
|
41168
41705
|
}
|
|
41706
|
+
function parseDevice(value) {
|
|
41707
|
+
if (value === void 0) return false;
|
|
41708
|
+
return value === "1" ? true : null;
|
|
41709
|
+
}
|
|
41169
41710
|
function parseFilmstrip(value) {
|
|
41170
41711
|
if (value === void 0) return void 0;
|
|
41171
41712
|
if (!/^[1-9][0-9]*$/.test(value)) return null;
|
|
41172
41713
|
const count = Number(value);
|
|
41173
41714
|
return count >= 2 ? count : null;
|
|
41174
41715
|
}
|
|
41716
|
+
// src/server/preview/address.ts
|
|
41717
|
+
/**
|
|
41718
|
+
* The private IPv4 ranges a home or office network hands out, in the order a
|
|
41719
|
+
* phone is likeliest to share: Wi-Fi routers mostly give 192.168, and 172.16
|
|
41720
|
+
* to 172.31 is where container and VM bridges sit.
|
|
41721
|
+
*/
|
|
41722
|
+
const PRIVATE_RANGES = [
|
|
41723
|
+
([a, b]) => a === 192 && b === 168,
|
|
41724
|
+
([a]) => a === 10,
|
|
41725
|
+
([a, b = 0]) => a === 172 && b >= 16 && b <= 31
|
|
41726
|
+
];
|
|
41727
|
+
/**
|
|
41728
|
+
* This machine's IPv4 address on a local network, the one a phone on the same
|
|
41729
|
+
* Wi-Fi can reach, or null when the machine has none. A loopback, a
|
|
41730
|
+
* link-local, or a public address is never picked.
|
|
41731
|
+
*/
|
|
41732
|
+
function networkAddress(interfaces = networkInterfaces()) {
|
|
41733
|
+
const candidates = Object.values(interfaces).flatMap((infos) => infos ?? []).filter((info) => info.family === "IPv4" && !info.internal).map((info) => info.address);
|
|
41734
|
+
for (const inRange of PRIVATE_RANGES) {
|
|
41735
|
+
const found = candidates.find((address) => inRange(address.split(".").map(Number)));
|
|
41736
|
+
if (found !== void 0) return found;
|
|
41737
|
+
}
|
|
41738
|
+
return null;
|
|
41739
|
+
}
|
|
41740
|
+
/** The link a phone opens, landing on one frame of the project the listener serves. */
|
|
41741
|
+
function previewLink({ address, port, token, project, page, frame }) {
|
|
41742
|
+
return `http://${address}:${port}/v/${token}/frames/${[
|
|
41743
|
+
project,
|
|
41744
|
+
page,
|
|
41745
|
+
`${frame}${FRAME_EXTENSION}`
|
|
41746
|
+
].map(encodeURIComponent).join("/")}`;
|
|
41747
|
+
}
|
|
41748
|
+
// src/server/routes/preview.ts
|
|
41749
|
+
/** The port a phone link asks for first, which a machine's one-time route forwards. */
|
|
41750
|
+
const PREVIEW_PORT = 4400;
|
|
41751
|
+
const StartBody = object$1({
|
|
41752
|
+
ref: string$1().min(1),
|
|
41753
|
+
port: number().int().min(0).max(65535).optional()
|
|
41754
|
+
});
|
|
41755
|
+
const StopBody = object$1({ token: string$1().min(1).optional() });
|
|
41756
|
+
/**
|
|
41757
|
+
* `POST /api/preview` with `{ ref, port? }` starts the phone listener for the
|
|
41758
|
+
* frame's project and answers the link landing on that frame, ending any
|
|
41759
|
+
* link already open. `DELETE /api/preview` with `{ token? }` ends it, or only
|
|
41760
|
+
* the listener holding `token`. Both sit behind `requireWriter`, since a
|
|
41761
|
+
* start opens a port to the local network. A machine with no local network
|
|
41762
|
+
* address refuses `no-network-address` and starts nothing.
|
|
41763
|
+
*/
|
|
41764
|
+
function previewRoutes(root, access, slot, { address = networkAddress } = {}) {
|
|
41765
|
+
const app = new Hono();
|
|
41766
|
+
app.onError((error, c) => {
|
|
41767
|
+
if (error instanceof FrameboardError && error.code === "no-network-address") return c.json({
|
|
41768
|
+
ok: false,
|
|
41769
|
+
error: {
|
|
41770
|
+
code: error.code,
|
|
41771
|
+
message: error.message,
|
|
41772
|
+
details: {}
|
|
41773
|
+
}
|
|
41774
|
+
}, 503);
|
|
41775
|
+
return answerRefusal(error, c);
|
|
41776
|
+
});
|
|
41777
|
+
app.use("/api/preview", requireWriter(access));
|
|
41778
|
+
app.post("/api/preview", async (c) => {
|
|
41779
|
+
const { ref, port = PREVIEW_PORT } = await parseBody$1(c.req.raw, StartBody);
|
|
41780
|
+
const frame = await resolveFrameRef(root, ref, { cwd: root });
|
|
41781
|
+
const host = address();
|
|
41782
|
+
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.");
|
|
41783
|
+
const listener = await slot.start(frame.project, host, port);
|
|
41784
|
+
return c.json({
|
|
41785
|
+
ok: true,
|
|
41786
|
+
data: {
|
|
41787
|
+
url: previewLink({
|
|
41788
|
+
address: host,
|
|
41789
|
+
port: listener.port,
|
|
41790
|
+
token: listener.token,
|
|
41791
|
+
project: frame.project,
|
|
41792
|
+
page: frame.page,
|
|
41793
|
+
frame: frame.name
|
|
41794
|
+
}),
|
|
41795
|
+
address: host,
|
|
41796
|
+
port: listener.port,
|
|
41797
|
+
token: listener.token,
|
|
41798
|
+
project: frame.project,
|
|
41799
|
+
ref: `${frame.project}/${frame.page}/${frame.name}`
|
|
41800
|
+
}
|
|
41801
|
+
});
|
|
41802
|
+
});
|
|
41803
|
+
app.delete("/api/preview", async (c) => {
|
|
41804
|
+
const body = await c.req.json().catch(() => ({}));
|
|
41805
|
+
const parsed = StopBody.safeParse(body);
|
|
41806
|
+
if (!parsed.success) throw new FrameboardError("usage", `The body ${parsed.error.message}`);
|
|
41807
|
+
const stopped = await slot.stop(parsed.data.token);
|
|
41808
|
+
return c.json({
|
|
41809
|
+
ok: true,
|
|
41810
|
+
data: { stopped }
|
|
41811
|
+
});
|
|
41812
|
+
});
|
|
41813
|
+
return app;
|
|
41814
|
+
}
|
|
41175
41815
|
// src/server/board/paste.ts
|
|
41176
41816
|
/** Reads each frame's file and placement under its page's lock, in the order given. */
|
|
41177
41817
|
async function holdFrames(root, refs, options) {
|
|
@@ -41389,7 +42029,8 @@ const frameHeightSchema = object$1({
|
|
|
41389
42029
|
y: coordinate,
|
|
41390
42030
|
width: int$1().min(1),
|
|
41391
42031
|
height: int$1().min(1)
|
|
41392
|
-
})).refine((boxes) => Object.keys(boxes).length <= 1e3)
|
|
42032
|
+
})).refine((boxes) => Object.keys(boxes).length <= 1e3),
|
|
42033
|
+
heights: record(ref, int$1().min(1)).refine((heights) => Object.keys(heights).length <= 1e3).optional()
|
|
41393
42034
|
});
|
|
41394
42035
|
const pasteSchema = object$1({
|
|
41395
42036
|
ref,
|
|
@@ -41398,6 +42039,25 @@ const pasteSchema = object$1({
|
|
|
41398
42039
|
y: coordinate
|
|
41399
42040
|
}).optional()
|
|
41400
42041
|
});
|
|
42042
|
+
const frameDeviceSchema = object$1({
|
|
42043
|
+
refs,
|
|
42044
|
+
device: _enum$1(DEVICES).nullable()
|
|
42045
|
+
});
|
|
42046
|
+
const transition = object$1({
|
|
42047
|
+
name: _enum$1(TRANSITIONS),
|
|
42048
|
+
direction: _enum$1(DIRECTIONS).optional(),
|
|
42049
|
+
ms: int$1().min(TRANSITION_MS.min).max(TRANSITION_MS.max).optional()
|
|
42050
|
+
});
|
|
42051
|
+
/** Null clears the page's transition, so its slides cut. */
|
|
42052
|
+
const pageTransitionSchema = object$1({
|
|
42053
|
+
ref,
|
|
42054
|
+
transition: transition.nullable()
|
|
42055
|
+
});
|
|
42056
|
+
/** Null clears each frame's override, so it takes its page's. */
|
|
42057
|
+
const frameTransitionSchema = object$1({
|
|
42058
|
+
refs,
|
|
42059
|
+
transition: transition.nullable()
|
|
42060
|
+
});
|
|
41401
42061
|
const frameFlagSchema = object$1({
|
|
41402
42062
|
refs,
|
|
41403
42063
|
flag: _enum$1(["hidden", "locked"]),
|
|
@@ -41562,6 +42222,21 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
41562
42222
|
data: page
|
|
41563
42223
|
});
|
|
41564
42224
|
});
|
|
42225
|
+
/** Sets or clears a page's slide transition as one step, leaving every frame file alone. */
|
|
42226
|
+
app.post("/api/page/transition", async (c) => {
|
|
42227
|
+
const body = await parseBody$1(c.req.raw, pageTransitionSchema);
|
|
42228
|
+
const page = await recorded((journal) => setPageTransition(root, body.ref, body.transition, {
|
|
42229
|
+
cwd,
|
|
42230
|
+
journal
|
|
42231
|
+
}), async () => ({
|
|
42232
|
+
page: null,
|
|
42233
|
+
frames: []
|
|
42234
|
+
}));
|
|
42235
|
+
return c.json({
|
|
42236
|
+
ok: true,
|
|
42237
|
+
data: page
|
|
42238
|
+
});
|
|
42239
|
+
});
|
|
41565
42240
|
app.post("/api/page/delete", async (c) => {
|
|
41566
42241
|
const body = await parseBody$1(c.req.raw, deleteSchema);
|
|
41567
42242
|
const source = await resolvePageRef(root, body.ref, { cwd });
|
|
@@ -41672,22 +42347,54 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
41672
42347
|
data: frames
|
|
41673
42348
|
});
|
|
41674
42349
|
});
|
|
42350
|
+
/** Sets or clears the device drawn around each frame, in one step, leaving every frame file alone. */
|
|
42351
|
+
app.post("/api/frame/device", async (c) => {
|
|
42352
|
+
const body = await parseBody$1(c.req.raw, frameDeviceSchema);
|
|
42353
|
+
const frames = await eachFrame(body.refs, (frame, journal) => setFrameDevice(root, frame, body.device, {
|
|
42354
|
+
cwd,
|
|
42355
|
+
journal
|
|
42356
|
+
}), (records) => records.map((record) => record.ref));
|
|
42357
|
+
return c.json({
|
|
42358
|
+
ok: true,
|
|
42359
|
+
data: frames
|
|
42360
|
+
});
|
|
42361
|
+
});
|
|
42362
|
+
/** Sets or clears each frame's transition override, in one step, leaving every frame file alone. */
|
|
42363
|
+
app.post("/api/frame/transition", async (c) => {
|
|
42364
|
+
const body = await parseBody$1(c.req.raw, frameTransitionSchema);
|
|
42365
|
+
const frames = await eachFrame(body.refs, (frame, journal) => setFrameTransition(root, frame, body.transition, {
|
|
42366
|
+
cwd,
|
|
42367
|
+
journal
|
|
42368
|
+
}), (records) => records.map((record) => record.ref));
|
|
42369
|
+
return c.json({
|
|
42370
|
+
ok: true,
|
|
42371
|
+
data: frames
|
|
42372
|
+
});
|
|
42373
|
+
});
|
|
41675
42374
|
/**
|
|
41676
42375
|
* Sets how each frame holds its height, `fixed`, `fit`, or `scroll`, in one
|
|
41677
42376
|
* step. `expected` holds each frame's box as the caller saw it, keyed by the
|
|
41678
42377
|
* ref the body names, and a frame changed since refuses `stale-layout`
|
|
41679
|
-
* before any frame is written.
|
|
42378
|
+
* before any frame is written. `heights` gives a `scroll` write the screen
|
|
42379
|
+
* height each named frame takes, and refuses `usage` with any other mode. A
|
|
42380
|
+
* locked or claimed frame refuses the whole
|
|
41680
42381
|
* write, and `fit` measures each frame and its linked widths on the warm
|
|
41681
42382
|
* browser first, refusing `browser-not-found` where none runs.
|
|
41682
42383
|
*/
|
|
41683
42384
|
app.post("/api/frame/height", async (c) => {
|
|
41684
42385
|
const body = await parseBody$1(c.req.raw, frameHeightSchema);
|
|
42386
|
+
if (body.heights && body.mode !== "scroll") throw new FrameboardError("usage", `The body gives heights to a ${body.mode} write, which takes them only with scroll.`);
|
|
41685
42387
|
const targets = body.refs.map((ref) => {
|
|
41686
42388
|
const expected = body.expected[ref];
|
|
41687
42389
|
if (!expected) throw new FrameboardError("usage", `The body gives ${ref} no expected box.`, { ref });
|
|
41688
|
-
|
|
42390
|
+
const height = body.heights?.[ref];
|
|
42391
|
+
return height === void 0 ? {
|
|
41689
42392
|
ref,
|
|
41690
42393
|
expected
|
|
42394
|
+
} : {
|
|
42395
|
+
ref,
|
|
42396
|
+
expected,
|
|
42397
|
+
height
|
|
41691
42398
|
};
|
|
41692
42399
|
});
|
|
41693
42400
|
await refuseLocked(body.refs);
|
|
@@ -42113,7 +42820,7 @@ function boardHostGuard(port) {
|
|
|
42113
42820
|
await next();
|
|
42114
42821
|
};
|
|
42115
42822
|
}
|
|
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 }) {
|
|
42823
|
+
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
42824
|
const app = new Hono();
|
|
42118
42825
|
const given = tokens ?? null;
|
|
42119
42826
|
app.use("*", async (c, next) => {
|
|
@@ -42147,6 +42854,7 @@ function createApp({ clientDir, root, port, actions, tickets, openRoute, renderF
|
|
|
42147
42854
|
app.route("/", clipboardRoutes(root, actions.access, renderFrame, clipboard));
|
|
42148
42855
|
if (checks) app.route("/", checkRoutes(actions.access, checks));
|
|
42149
42856
|
if (thumbnails) app.route("/", thumbnailRoutes(root, thumbnails));
|
|
42857
|
+
if (preview) app.route("/", previewRoutes(root, actions.access, preview));
|
|
42150
42858
|
app.route("/", frames.routes);
|
|
42151
42859
|
app.use("*", serveStatic({ root: clientDir }));
|
|
42152
42860
|
app.get("/p/*", serveStatic({
|
|
@@ -42731,27 +43439,67 @@ function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
|
|
|
42731
43439
|
let queue = Promise.resolve();
|
|
42732
43440
|
return (frame, theme, scale = defaultScale) => {
|
|
42733
43441
|
const run = queue.then(async () => {
|
|
42734
|
-
assertScreenshotFits(frame.ref,
|
|
42735
|
-
|
|
43442
|
+
assertScreenshotFits(frame.ref, bezelBox({
|
|
43443
|
+
x: 0,
|
|
43444
|
+
y: 0,
|
|
43445
|
+
...frame.box
|
|
43446
|
+
}, frame.device), scale);
|
|
43447
|
+
const open = await browser.get();
|
|
43448
|
+
const opened = await openFrame(open, {
|
|
42736
43449
|
baseUrl: baseUrl(),
|
|
42737
43450
|
ref: frame.ref,
|
|
42738
43451
|
box: frame.box,
|
|
42739
43452
|
theme,
|
|
42740
43453
|
scale
|
|
42741
43454
|
});
|
|
43455
|
+
let shot;
|
|
42742
43456
|
try {
|
|
42743
|
-
|
|
43457
|
+
shot = await opened.page.screenshot({
|
|
42744
43458
|
animations: "disabled",
|
|
42745
43459
|
caret: "hide"
|
|
42746
43460
|
});
|
|
42747
43461
|
} finally {
|
|
42748
43462
|
await opened.close();
|
|
42749
43463
|
}
|
|
43464
|
+
return frame.device ? drawBezel(open, shot, frame.box, frame.device, scale) : shot;
|
|
42750
43465
|
});
|
|
42751
43466
|
queue = run.catch(() => {});
|
|
42752
43467
|
return run;
|
|
42753
43468
|
};
|
|
42754
43469
|
}
|
|
43470
|
+
/**
|
|
43471
|
+
* A frame's shot drawn inside a device's body, as the board draws it, on a
|
|
43472
|
+
* page the size of the body, so the PNG holds the body and nothing past it.
|
|
43473
|
+
*/
|
|
43474
|
+
async function drawBezel(browser, shot, box, device, scale) {
|
|
43475
|
+
const { border, screenRadius } = BEZELS[device];
|
|
43476
|
+
const outer = bezelBox({
|
|
43477
|
+
x: 0,
|
|
43478
|
+
y: 0,
|
|
43479
|
+
...box
|
|
43480
|
+
}, device);
|
|
43481
|
+
const context = await browser.newContext({
|
|
43482
|
+
viewport: {
|
|
43483
|
+
width: outer.width,
|
|
43484
|
+
height: outer.height
|
|
43485
|
+
},
|
|
43486
|
+
deviceScaleFactor: scale
|
|
43487
|
+
});
|
|
43488
|
+
try {
|
|
43489
|
+
const page = await context.newPage();
|
|
43490
|
+
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>` : "";
|
|
43491
|
+
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" });
|
|
43492
|
+
return await page.screenshot({
|
|
43493
|
+
omitBackground: true,
|
|
43494
|
+
caret: "hide"
|
|
43495
|
+
});
|
|
43496
|
+
} finally {
|
|
43497
|
+
await context.close();
|
|
43498
|
+
}
|
|
43499
|
+
}
|
|
43500
|
+
function pill(width, height, color) {
|
|
43501
|
+
return `position:absolute;left:50%;transform:translateX(-50%);width:${width}px;height:${height}px;border-radius:${height / 2}px;background:${color};`;
|
|
43502
|
+
}
|
|
42755
43503
|
// src/server/capture/images.ts
|
|
42756
43504
|
const SCREENSHOT = {
|
|
42757
43505
|
animations: "disabled",
|
|
@@ -42790,7 +43538,7 @@ function compositeImagePath(out, page, theme, scale = 1) {
|
|
|
42790
43538
|
* `capture-too-large` past Chromium's screenshot limit.
|
|
42791
43539
|
*/
|
|
42792
43540
|
function compositeBounds(page, frames, scale = 1) {
|
|
42793
|
-
const extents = frames.map(({ box, widths }) => drawnExtent(box, widths ?? []));
|
|
43541
|
+
const extents = frames.map(({ box, widths, device }) => drawnExtent(box, widths ?? [], device));
|
|
42794
43542
|
const left = Math.min(...extents.map((box) => box.x));
|
|
42795
43543
|
const top = Math.min(...extents.map((box) => box.y));
|
|
42796
43544
|
const right = Math.max(...extents.map((box) => box.x + box.width));
|
|
@@ -43893,8 +44641,8 @@ function readConfig(root, project) {
|
|
|
43893
44641
|
} catch {
|
|
43894
44642
|
return {};
|
|
43895
44643
|
}
|
|
43896
|
-
const checks = isRecord(parsed) ? parsed.checks : void 0;
|
|
43897
|
-
if (!isRecord(checks)) return {};
|
|
44644
|
+
const checks = isRecord$1(parsed) ? parsed.checks : void 0;
|
|
44645
|
+
if (!isRecord$1(checks)) return {};
|
|
43898
44646
|
const config = {};
|
|
43899
44647
|
if (Array.isArray(checks.allowedFonts) && checks.allowedFonts.every((font) => typeof font === "string")) config.allowedFonts = checks.allowedFonts;
|
|
43900
44648
|
if (typeof checks.noUppercase === "boolean") config.noUppercase = checks.noUppercase;
|
|
@@ -43902,7 +44650,7 @@ function readConfig(root, project) {
|
|
|
43902
44650
|
if (typeof checks.minContrast === "number" && checks.minContrast >= 1) config.minContrast = checks.minContrast;
|
|
43903
44651
|
return config;
|
|
43904
44652
|
}
|
|
43905
|
-
function isRecord(value) {
|
|
44653
|
+
function isRecord$1(value) {
|
|
43906
44654
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43907
44655
|
}
|
|
43908
44656
|
// src/server/checks/browser/contrast.ts
|
|
@@ -45074,6 +45822,17 @@ function postToBoard(address, path, body, { timeoutMs = REQUEST_TIMEOUT_MS } = {
|
|
|
45074
45822
|
body: JSON.stringify(body)
|
|
45075
45823
|
}, timeoutMs);
|
|
45076
45824
|
}
|
|
45825
|
+
/** Deletes through a running board server's write route with the address file's token. */
|
|
45826
|
+
function deleteFromBoard(address, path, body) {
|
|
45827
|
+
return requestBoard(address, path, {
|
|
45828
|
+
method: "DELETE",
|
|
45829
|
+
headers: {
|
|
45830
|
+
authorization: `Bearer ${address.token}`,
|
|
45831
|
+
"content-type": "application/json"
|
|
45832
|
+
},
|
|
45833
|
+
body: JSON.stringify(body)
|
|
45834
|
+
});
|
|
45835
|
+
}
|
|
45077
45836
|
/** Reads a running board server's route, resolving the `data` of its envelope. */
|
|
45078
45837
|
function getFromBoard(address, path) {
|
|
45079
45838
|
return requestBoard(address, path, { method: "GET" });
|
|
@@ -45089,12 +45848,20 @@ async function requestBoard(address, path, init, timeoutMs = REQUEST_TIMEOUT_MS)
|
|
|
45089
45848
|
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
45849
|
}
|
|
45091
45850
|
const envelope = await response.json().catch(() => null);
|
|
45851
|
+
const refusal = envelope?.error;
|
|
45852
|
+
if (!response.ok && isErrorCode(refusal?.code) && typeof refusal?.message === "string") throw new FrameboardError(refusal.code, refusal.message, isRecord(refusal.details) ? refusal.details : {});
|
|
45092
45853
|
if (!response.ok || !envelope) throw new FrameboardError("internal", `The frameboard server at ${address.url} refused ${path} with ${response.status}.`, {
|
|
45093
45854
|
url: address.url,
|
|
45094
45855
|
status: response.status
|
|
45095
45856
|
});
|
|
45096
45857
|
return envelope.data;
|
|
45097
45858
|
}
|
|
45859
|
+
function isErrorCode(code) {
|
|
45860
|
+
return typeof code === "string" && Object.hasOwn(EXIT_CODES, code);
|
|
45861
|
+
}
|
|
45862
|
+
function isRecord(value) {
|
|
45863
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45864
|
+
}
|
|
45098
45865
|
// src/cli/commands/check.ts
|
|
45099
45866
|
const BROWSER_TIMEOUT_MS = 12e4;
|
|
45100
45867
|
const NOT_FRAME = /* @__PURE__ */ new Set([
|
|
@@ -45250,6 +46017,12 @@ const recordErrorSchema = object$1({
|
|
|
45250
46017
|
path: string$1(),
|
|
45251
46018
|
message: string$1()
|
|
45252
46019
|
}).nullable();
|
|
46020
|
+
/** A transition as present mode reads it, `direction` and `ms` absent at their default. */
|
|
46021
|
+
const transitionRecordSchema = object$1({
|
|
46022
|
+
name: _enum$1(TRANSITIONS),
|
|
46023
|
+
direction: _enum$1(DIRECTIONS).optional(),
|
|
46024
|
+
ms: int$1().optional()
|
|
46025
|
+
});
|
|
45253
46026
|
const frameRecordSchema = object$1({
|
|
45254
46027
|
ref: string$1(),
|
|
45255
46028
|
project: string$1(),
|
|
@@ -45275,6 +46048,10 @@ const frameRecordSchema = object$1({
|
|
|
45275
46048
|
width: number(),
|
|
45276
46049
|
height: number()
|
|
45277
46050
|
})),
|
|
46051
|
+
/** The device the board draws around the frame, absent when it has none. */
|
|
46052
|
+
device: _enum$1(DEVICES).optional(),
|
|
46053
|
+
/** The transition the frame arrives with in present mode, over its page's, absent when it holds none. */
|
|
46054
|
+
transition: transitionRecordSchema.optional(),
|
|
45278
46055
|
placed: boolean$1(),
|
|
45279
46056
|
modifiedAt: string$1()
|
|
45280
46057
|
});
|
|
@@ -45297,6 +46074,8 @@ const pageRecordSchema = object$1({
|
|
|
45297
46074
|
path: string$1(),
|
|
45298
46075
|
index: number(),
|
|
45299
46076
|
layoutError: recordErrorSchema,
|
|
46077
|
+
/** The transition present mode draws between the page's slides, absent when it holds none. */
|
|
46078
|
+
transition: transitionRecordSchema.optional(),
|
|
45300
46079
|
frames: array$1(frameRecordSchema),
|
|
45301
46080
|
/** Bottom first, as frames are. */
|
|
45302
46081
|
sections: array$1(sectionRecordSchema)
|
|
@@ -45687,6 +46466,27 @@ const inspectResultSchema = object$1({
|
|
|
45687
46466
|
editable: boolean$1(),
|
|
45688
46467
|
elements: array$1(inspectedElementSchema)
|
|
45689
46468
|
});
|
|
46469
|
+
// src/shared/records/preview.ts
|
|
46470
|
+
/**
|
|
46471
|
+
* What `preview` returns on a start: the link a phone on the same network
|
|
46472
|
+
* opens, landing on one frame, which serves that frame's whole project read
|
|
46473
|
+
* only. The link ends when another start replaces it, when `preview --stop`
|
|
46474
|
+
* runs, when the board card showing it closes, or when the board stops.
|
|
46475
|
+
*/
|
|
46476
|
+
const previewStartSchema = object$1({
|
|
46477
|
+
url: string$1(),
|
|
46478
|
+
/** This machine's address on the local network, which the link names. */
|
|
46479
|
+
address: string$1(),
|
|
46480
|
+
/** The port the listener bound on every interface, the one asked for unless it was taken. */
|
|
46481
|
+
port: int$1(),
|
|
46482
|
+
/** The secret in the link's path, new on every start. */
|
|
46483
|
+
token: string$1(),
|
|
46484
|
+
project: string$1(),
|
|
46485
|
+
/** The frame the link lands on, `<project>/<page>/<frame>`. */
|
|
46486
|
+
ref: string$1()
|
|
46487
|
+
});
|
|
46488
|
+
/** What `preview --stop` returns: whether a link was running to end. */
|
|
46489
|
+
const previewStopSchema = object$1({ stopped: boolean$1() });
|
|
45690
46490
|
// src/shared/records/references.ts
|
|
45691
46491
|
/** What `references sync` returns, each path relative to the folder and sorted. */
|
|
45692
46492
|
const referencesSyncSchema = object$1({
|
|
@@ -45761,7 +46561,9 @@ const RECORDS = {
|
|
|
45761
46561
|
selection: selectionResultSchema,
|
|
45762
46562
|
find: findResultSchema,
|
|
45763
46563
|
referencesSync: referencesSyncSchema,
|
|
45764
|
-
referencesCheck: referencesCheckSchema
|
|
46564
|
+
referencesCheck: referencesCheckSchema,
|
|
46565
|
+
previewStart: previewStartSchema,
|
|
46566
|
+
previewStop: previewStopSchema
|
|
45765
46567
|
};
|
|
45766
46568
|
// src/cli/docs/content-format.ts
|
|
45767
46569
|
/** The content format `docs` prints, built from the constants the verbs run on. */
|
|
@@ -45789,6 +46591,7 @@ function contentFormat() {
|
|
|
45789
46591
|
"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
46592
|
`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
46593
|
`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.`,
|
|
46594
|
+
`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
46595
|
`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
46596
|
"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
46597
|
"Frames sort by order, then name, and a write that changes order renumbers the page from 0.",
|
|
@@ -45798,6 +46601,11 @@ function contentFormat() {
|
|
|
45798
46601
|
`Moving or resizing a frame writes ${LAYOUT_FILE} alone and never the frame file.`,
|
|
45799
46602
|
"sections, when present, maps a section name to its x, y, width, height, and order. A frame belongs to the topmost section holding its center, left and top edges inside, and is never listed in it, so list --json names each section's frames and an agent moving a frame out of the box takes it out of the section. The developer writes sections by hand on the board."
|
|
45800
46603
|
],
|
|
46604
|
+
present: [
|
|
46605
|
+
`A page's slide transition sits on the present key of its ${LAYOUT_FILE} as { transition: { name, direction, ms } }, and a frame's entry may hold its own transition, which wins as that slide arrives. name is one of ${TRANSITIONS.join(", ")}. direction is one of ${DIRECTIONS.join(", ")}, taken by ${DIRECTED.join(" and ")} alone and defaulting to left. ms runs ${TRANSITION_MS.min} to ${TRANSITION_MS.max}, a frame's taking its page's when absent and the page's defaulting to 500. Any other value reads as none and is kept on write. The board draws a transition itself and never writes it into a frame file.`,
|
|
46606
|
+
"page transition <page-ref> <name> sets the page's, and none clears it so slides cut. frame transition <frame-ref> <name> sets a frame's, and page clears it so the frame takes its page's. Both take --ms and --direction and write only layout.json.",
|
|
46607
|
+
`A step is an element present mode holds back until a press reveals it, marked by three attributes on that element and nothing else. ${STEP_ATTRIBUTES.step}="<n>" is a positive integer, and steps show in number order with equal numbers together and gaps closed. ${STEP_ATTRIBUTES.effect} is one of ${STEP_EFFECTS.join(", ")}, defaulting to appear. ${STEP_ATTRIBUTES.start} is one of ${STEP_STARTS.join(", ")}, defaulting to click, where with shows the step beside the one before it and after shows it once that one finishes. Set them with edit --attr. Edit, Play, capture, and an exported PNG show every step.`
|
|
46608
|
+
],
|
|
45801
46609
|
assets: `A frame links files in its own page folder or in its project's ${ASSETS_FOLDER}/ folder. frame duplicate and frame move carry the ${FRAME_EXTENSION} file alone, so keep files shared between frames or pages in ${ASSETS_FOLDER}/.`,
|
|
45802
46610
|
look: [
|
|
45803
46611
|
`The board's ${TOKEN_FILE} holds the design tokens every project shares, and a project's own ${TOKEN_FILE} overrides it. serve --tokens <path> stands in for the board's sheet, resolved against the working folder and recorded as tokens in ${RUN_FOLDER}/${ADDRESS_FILE} while that server runs.`,
|
|
@@ -45851,6 +46659,8 @@ function formatLines(format) {
|
|
|
45851
46659
|
`${INDENT}${sizes.join(", ")}, defaulting to ${format.defaultFrameSize}`,
|
|
45852
46660
|
"Layout",
|
|
45853
46661
|
...format.layout.map((line) => `${INDENT}${line}`),
|
|
46662
|
+
"Present",
|
|
46663
|
+
...format.present.map((line) => `${INDENT}${line}`),
|
|
45854
46664
|
"Assets",
|
|
45855
46665
|
`${INDENT}${format.assets}`,
|
|
45856
46666
|
"Look",
|
|
@@ -46113,7 +46923,7 @@ async function reservationsOf(root, refs, options, cwd, now) {
|
|
|
46113
46923
|
async function rightOf(root, frame, live) {
|
|
46114
46924
|
const page = await scanPage(root, frame.project, frame.page, 0);
|
|
46115
46925
|
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] : [])];
|
|
46926
|
+
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
46927
|
return Math.max(...boxes.map((box) => box.x + box.width + 80), 0);
|
|
46118
46928
|
}
|
|
46119
46929
|
function describe$4(claims, now) {
|
|
@@ -46124,9 +46934,31 @@ function describe$4(claims, now) {
|
|
|
46124
46934
|
return `${each.frame} ${each.tag} ${state} ${seconds}s ${each.session}`;
|
|
46125
46935
|
}).join("\n");
|
|
46126
46936
|
}
|
|
46937
|
+
// src/cli/commands/transition-flags.ts
|
|
46938
|
+
/** Adds `--ms` and `--direction`, which `page transition` and `frame transition` share. */
|
|
46939
|
+
function withTransitionFlags(command) {
|
|
46940
|
+
return command.option("--ms <n>", `the transition's length, ${TRANSITION_MS.min} to ${TRANSITION_MS.max}, defaulting to the page's or 500`, parseInteger(TRANSITION_MS.min)).addOption(new Option("--direction <direction>", `the way ${DIRECTED.join(" and ")} move the incoming slide, defaulting to left`).choices(DIRECTIONS));
|
|
46941
|
+
}
|
|
46942
|
+
/**
|
|
46943
|
+
* The transition a verb stores, refusing `usage` before anything is written
|
|
46944
|
+
* on a duration past the ceiling or a direction on a transition taking none.
|
|
46945
|
+
*/
|
|
46946
|
+
function transitionFrom(name, { ms, direction }) {
|
|
46947
|
+
if (ms !== void 0 && ms > TRANSITION_MS.max) throw new FrameboardError("usage", `--ms takes at most ${TRANSITION_MS.max}.`, { ms });
|
|
46948
|
+
if (direction !== void 0 && !takesDirection(name)) throw new FrameboardError("usage", `${name} takes no direction. Only ${DIRECTED.join(" and ")} do.`, {
|
|
46949
|
+
transition: name,
|
|
46950
|
+
direction
|
|
46951
|
+
});
|
|
46952
|
+
return {
|
|
46953
|
+
name,
|
|
46954
|
+
...direction ? { direction } : {},
|
|
46955
|
+
...ms === void 0 ? {} : { ms }
|
|
46956
|
+
};
|
|
46957
|
+
}
|
|
46127
46958
|
// src/cli/commands/frame.ts
|
|
46128
46959
|
const FRAME_REF = "a frame ref, <page>/<frame> or <project>/<page>/<frame>, or a path to its .html file";
|
|
46129
46960
|
const ANY_INTEGER = parseInteger(Number.MIN_SAFE_INTEGER);
|
|
46961
|
+
const DEVICE_HELP = "the device the board draws around the frame, leaving the frame file and its size as they are";
|
|
46130
46962
|
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
46963
|
const POSITIVE = parseInteger(1);
|
|
46132
46964
|
/** A comma list of positive integers, each checked as `--width` checks one. */
|
|
@@ -46134,6 +46966,11 @@ function parseWidths(value) {
|
|
|
46134
46966
|
return value.split(",").map((part) => POSITIVE(part.trim()));
|
|
46135
46967
|
}
|
|
46136
46968
|
const SCROLL_HELP = "hold a fixed screen height and scroll past it, fixing both axes, at the reference height of the width when no height is given";
|
|
46969
|
+
/** The override `frame transition` stores, null for `page`, which clears it. */
|
|
46970
|
+
function transitionOrPage(name, flags) {
|
|
46971
|
+
const chosen = transitionNameOf(name);
|
|
46972
|
+
return chosen ? transitionFrom(chosen, flags) : null;
|
|
46973
|
+
}
|
|
46137
46974
|
const RESIZE_SCROLL_HELP = "hold a fixed screen height and scroll past it, fixing both axes, dropping a hugging height to the reference height of the width and keeping a fixed one";
|
|
46138
46975
|
function registerFrame(program, context) {
|
|
46139
46976
|
const { io } = context;
|
|
@@ -46145,7 +46982,7 @@ function registerFrame(program, context) {
|
|
|
46145
46982
|
data: record,
|
|
46146
46983
|
human: `${what} ${record.ref}`
|
|
46147
46984
|
});
|
|
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, {
|
|
46985
|
+
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
46986
|
...options,
|
|
46150
46987
|
cwd: io.cwd
|
|
46151
46988
|
}), "Added"));
|
|
@@ -46202,6 +47039,20 @@ function registerFrame(program, context) {
|
|
|
46202
47039
|
human: `Deleted frame ${result.deleted}`
|
|
46203
47040
|
};
|
|
46204
47041
|
});
|
|
47042
|
+
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) => {
|
|
47043
|
+
const record = await setFrameDevice(await boardOf(options, io), ref, deviceOf(device), {
|
|
47044
|
+
...options,
|
|
47045
|
+
cwd: io.cwd
|
|
47046
|
+
});
|
|
47047
|
+
return done(record, record.device ? `Set ${record.device} on` : "Cleared the device on");
|
|
47048
|
+
});
|
|
47049
|
+
act(withTransitionFlags(verb("transition", "Set the transition present mode draws as this slide arrives, over its page’s, or clear it with page so it takes the page’s, writing only layout.json").addArgument(new Argument("<transition>", "the transition, page to take the page’s").choices([...TRANSITIONS, "page"]))), context, async ([ref = "", name = ""], options) => {
|
|
47050
|
+
const record = await setFrameTransition(await boardOf(options, io), ref, transitionOrPage(name, options), {
|
|
47051
|
+
...options,
|
|
47052
|
+
cwd: io.cwd
|
|
47053
|
+
});
|
|
47054
|
+
return done(record, record.transition ? `Set ${TRANSITION_LABELS[record.transition.name]} on` : "Cleared the transition on");
|
|
47055
|
+
});
|
|
46205
47056
|
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
47057
|
...options,
|
|
46207
47058
|
on: !options.off,
|
|
@@ -50215,6 +51066,17 @@ function registerPage(program, context) {
|
|
|
50215
51066
|
human: `Moved ${record.ref} to ${record.index}`
|
|
50216
51067
|
};
|
|
50217
51068
|
});
|
|
51069
|
+
act(withTransitionFlags(verb("transition", "Set the transition present mode draws between the page’s slides, or clear it with none so they cut, writing only layout.json").addArgument(new Argument("<transition>", "the transition, none to clear it").choices(TRANSITIONS))), context, async ([ref = "", name = ""], options) => {
|
|
51070
|
+
const chosen = transitionNameOf(name) ?? "none";
|
|
51071
|
+
const record = await setPageTransition(await boardOf(options, io), ref, chosen === "none" ? null : transitionFrom(chosen, options), {
|
|
51072
|
+
...options,
|
|
51073
|
+
cwd: io.cwd
|
|
51074
|
+
});
|
|
51075
|
+
return {
|
|
51076
|
+
data: record,
|
|
51077
|
+
human: record.transition ? `Set ${TRANSITION_LABELS[record.transition.name]} on ${record.ref}` : `Cleared the transition on ${record.ref}`
|
|
51078
|
+
};
|
|
51079
|
+
});
|
|
50218
51080
|
act(verb("delete", "Delete a page and its frames"), context, async ([ref = ""], options) => {
|
|
50219
51081
|
const result = await deletePage(await boardOf(options, io), ref, {
|
|
50220
51082
|
...options,
|
|
@@ -50226,6 +51088,428 @@ function registerPage(program, context) {
|
|
|
50226
51088
|
};
|
|
50227
51089
|
});
|
|
50228
51090
|
}
|
|
51091
|
+
// src/shared/qr.ts
|
|
51092
|
+
/** Error correction codewords per block at level M, indexed by version. */
|
|
51093
|
+
const ECC_PER_BLOCK = [
|
|
51094
|
+
-1,
|
|
51095
|
+
10,
|
|
51096
|
+
16,
|
|
51097
|
+
26,
|
|
51098
|
+
18,
|
|
51099
|
+
24,
|
|
51100
|
+
16,
|
|
51101
|
+
18,
|
|
51102
|
+
22,
|
|
51103
|
+
22,
|
|
51104
|
+
26,
|
|
51105
|
+
30,
|
|
51106
|
+
22,
|
|
51107
|
+
22,
|
|
51108
|
+
24,
|
|
51109
|
+
24,
|
|
51110
|
+
28,
|
|
51111
|
+
28,
|
|
51112
|
+
26,
|
|
51113
|
+
26,
|
|
51114
|
+
26,
|
|
51115
|
+
26,
|
|
51116
|
+
28,
|
|
51117
|
+
28,
|
|
51118
|
+
28,
|
|
51119
|
+
28,
|
|
51120
|
+
28,
|
|
51121
|
+
28,
|
|
51122
|
+
28,
|
|
51123
|
+
28,
|
|
51124
|
+
28,
|
|
51125
|
+
28,
|
|
51126
|
+
28,
|
|
51127
|
+
28,
|
|
51128
|
+
28,
|
|
51129
|
+
28,
|
|
51130
|
+
28,
|
|
51131
|
+
28,
|
|
51132
|
+
28,
|
|
51133
|
+
28,
|
|
51134
|
+
28
|
|
51135
|
+
];
|
|
51136
|
+
/** Error correction blocks at level M, indexed by version. */
|
|
51137
|
+
const BLOCKS = [
|
|
51138
|
+
-1,
|
|
51139
|
+
1,
|
|
51140
|
+
1,
|
|
51141
|
+
1,
|
|
51142
|
+
2,
|
|
51143
|
+
2,
|
|
51144
|
+
4,
|
|
51145
|
+
4,
|
|
51146
|
+
4,
|
|
51147
|
+
5,
|
|
51148
|
+
5,
|
|
51149
|
+
5,
|
|
51150
|
+
8,
|
|
51151
|
+
9,
|
|
51152
|
+
9,
|
|
51153
|
+
10,
|
|
51154
|
+
10,
|
|
51155
|
+
11,
|
|
51156
|
+
13,
|
|
51157
|
+
14,
|
|
51158
|
+
16,
|
|
51159
|
+
17,
|
|
51160
|
+
17,
|
|
51161
|
+
18,
|
|
51162
|
+
20,
|
|
51163
|
+
21,
|
|
51164
|
+
23,
|
|
51165
|
+
25,
|
|
51166
|
+
26,
|
|
51167
|
+
28,
|
|
51168
|
+
29,
|
|
51169
|
+
31,
|
|
51170
|
+
33,
|
|
51171
|
+
35,
|
|
51172
|
+
37,
|
|
51173
|
+
38,
|
|
51174
|
+
40,
|
|
51175
|
+
43,
|
|
51176
|
+
45,
|
|
51177
|
+
47,
|
|
51178
|
+
49
|
|
51179
|
+
];
|
|
51180
|
+
const MAX_VERSION = 40;
|
|
51181
|
+
/**
|
|
51182
|
+
* The modules of the smallest code holding `text` as UTF-8, with its mask
|
|
51183
|
+
* picked by the standard's penalty score. A text past what version 40 holds
|
|
51184
|
+
* throws, which no link reaches.
|
|
51185
|
+
*/
|
|
51186
|
+
function qrModules(text) {
|
|
51187
|
+
const data = new TextEncoder().encode(text);
|
|
51188
|
+
const version = smallestVersion(data.length);
|
|
51189
|
+
const codewords = addErrorCorrection(dataCodewords(data, version), version);
|
|
51190
|
+
const grid = new Grid(version * 4 + 17);
|
|
51191
|
+
drawFunctionPatterns(grid, version);
|
|
51192
|
+
drawCodewords(grid, codewords);
|
|
51193
|
+
let best = null;
|
|
51194
|
+
for (let mask = 0; mask < 8; mask++) {
|
|
51195
|
+
const masked = grid.copy();
|
|
51196
|
+
applyMask(masked, mask);
|
|
51197
|
+
drawFormatBits(masked, mask);
|
|
51198
|
+
const penalty = penaltyScore(masked.modules);
|
|
51199
|
+
if (!best || penalty < best.penalty) best = {
|
|
51200
|
+
penalty,
|
|
51201
|
+
modules: masked.modules
|
|
51202
|
+
};
|
|
51203
|
+
}
|
|
51204
|
+
return best?.modules ?? [];
|
|
51205
|
+
}
|
|
51206
|
+
var Grid = class Grid {
|
|
51207
|
+
size;
|
|
51208
|
+
modules;
|
|
51209
|
+
reserved;
|
|
51210
|
+
constructor(size, modules, reserved) {
|
|
51211
|
+
this.size = size;
|
|
51212
|
+
this.modules = modules ?? Array.from({ length: size }, () => Array(size).fill(false));
|
|
51213
|
+
this.reserved = reserved ?? Array.from({ length: size }, () => Array(size).fill(false));
|
|
51214
|
+
}
|
|
51215
|
+
/** Sets a function module, which no data bit or mask touches. */
|
|
51216
|
+
setFunction(x, y, dark) {
|
|
51217
|
+
this.set(x, y, dark);
|
|
51218
|
+
const row = this.reserved[y];
|
|
51219
|
+
if (row) row[x] = true;
|
|
51220
|
+
}
|
|
51221
|
+
set(x, y, dark) {
|
|
51222
|
+
const row = this.modules[y];
|
|
51223
|
+
if (row) row[x] = dark;
|
|
51224
|
+
}
|
|
51225
|
+
get(x, y) {
|
|
51226
|
+
return this.modules[y]?.[x] ?? false;
|
|
51227
|
+
}
|
|
51228
|
+
isReserved(x, y) {
|
|
51229
|
+
return this.reserved[y]?.[x] ?? false;
|
|
51230
|
+
}
|
|
51231
|
+
copy() {
|
|
51232
|
+
return new Grid(this.size, this.modules.map((row) => [...row]), this.reserved);
|
|
51233
|
+
}
|
|
51234
|
+
};
|
|
51235
|
+
/** The data codewords a version holds at level M. */
|
|
51236
|
+
function dataCapacity(version) {
|
|
51237
|
+
return Math.floor(rawModules(version) / 8) - (ECC_PER_BLOCK[version] ?? 0) * (BLOCKS[version] ?? 0);
|
|
51238
|
+
}
|
|
51239
|
+
/** The modules left for codewords once the function patterns are drawn. */
|
|
51240
|
+
function rawModules(version) {
|
|
51241
|
+
let result = (16 * version + 128) * version + 64;
|
|
51242
|
+
if (version >= 2) {
|
|
51243
|
+
const align = Math.floor(version / 7) + 2;
|
|
51244
|
+
result -= (25 * align - 10) * align - 55;
|
|
51245
|
+
if (version >= 7) result -= 36;
|
|
51246
|
+
}
|
|
51247
|
+
return result;
|
|
51248
|
+
}
|
|
51249
|
+
function smallestVersion(bytes) {
|
|
51250
|
+
for (let version = 1; version <= MAX_VERSION; version++) if (4 + (version <= 9 ? 8 : 16) + bytes * 8 <= dataCapacity(version) * 8) return version;
|
|
51251
|
+
throw new Error(`A QR code holds no text of ${bytes} bytes`);
|
|
51252
|
+
}
|
|
51253
|
+
/** Mode, count, bytes, terminator, then the alternating pad bytes. */
|
|
51254
|
+
function dataCodewords(data, version) {
|
|
51255
|
+
const bits = [];
|
|
51256
|
+
const push = (value, length) => {
|
|
51257
|
+
for (let i = length - 1; i >= 0; i--) bits.push(value >>> i & 1);
|
|
51258
|
+
};
|
|
51259
|
+
push(4, 4);
|
|
51260
|
+
push(data.length, version <= 9 ? 8 : 16);
|
|
51261
|
+
for (const byte of data) push(byte, 8);
|
|
51262
|
+
const capacity = dataCapacity(version) * 8;
|
|
51263
|
+
push(0, Math.min(4, capacity - bits.length));
|
|
51264
|
+
push(0, (8 - bits.length % 8) % 8);
|
|
51265
|
+
for (let pad = 236; bits.length < capacity; pad ^= 253) push(pad, 8);
|
|
51266
|
+
const codewords = [];
|
|
51267
|
+
for (let i = 0; i < bits.length; i += 8) codewords.push(bits.slice(i, i + 8).reduce((byte, bit) => byte << 1 | bit, 0));
|
|
51268
|
+
return codewords;
|
|
51269
|
+
}
|
|
51270
|
+
/** Splits the data into blocks, appends each block's ECC, and interleaves them. */
|
|
51271
|
+
function addErrorCorrection(data, version) {
|
|
51272
|
+
const blockCount = BLOCKS[version] ?? 1;
|
|
51273
|
+
const eccLength = ECC_PER_BLOCK[version] ?? 0;
|
|
51274
|
+
const raw = Math.floor(rawModules(version) / 8);
|
|
51275
|
+
const shortBlocks = blockCount - raw % blockCount;
|
|
51276
|
+
const shortLength = Math.floor(raw / blockCount);
|
|
51277
|
+
const divisor = reedSolomonDivisor(eccLength);
|
|
51278
|
+
const blocks = [];
|
|
51279
|
+
for (let i = 0, at = 0; i < blockCount; i++) {
|
|
51280
|
+
const length = shortLength - eccLength + (i < shortBlocks ? 0 : 1);
|
|
51281
|
+
const block = data.slice(at, at + length);
|
|
51282
|
+
at += length;
|
|
51283
|
+
const ecc = reedSolomonRemainder(block, divisor);
|
|
51284
|
+
if (i < shortBlocks) block.push(-1);
|
|
51285
|
+
blocks.push([...block, ...ecc]);
|
|
51286
|
+
}
|
|
51287
|
+
const result = [];
|
|
51288
|
+
for (let i = 0; i < (blocks[0]?.length ?? 0); i++) blocks.forEach((block, index) => {
|
|
51289
|
+
if (!(i === shortLength - eccLength && index < shortBlocks)) result.push(block[i] ?? 0);
|
|
51290
|
+
});
|
|
51291
|
+
return result;
|
|
51292
|
+
}
|
|
51293
|
+
function reedSolomonDivisor(degree) {
|
|
51294
|
+
const result = Array(degree).fill(0);
|
|
51295
|
+
result[degree - 1] = 1;
|
|
51296
|
+
let root = 1;
|
|
51297
|
+
for (let i = 0; i < degree; i++) {
|
|
51298
|
+
for (let j = 0; j < degree; j++) {
|
|
51299
|
+
result[j] = multiply(result[j] ?? 0, root);
|
|
51300
|
+
if (j + 1 < degree) result[j] = (result[j] ?? 0) ^ (result[j + 1] ?? 0);
|
|
51301
|
+
}
|
|
51302
|
+
root = multiply(root, 2);
|
|
51303
|
+
}
|
|
51304
|
+
return result;
|
|
51305
|
+
}
|
|
51306
|
+
function reedSolomonRemainder(data, divisor) {
|
|
51307
|
+
const result = divisor.map(() => 0);
|
|
51308
|
+
for (const byte of data) {
|
|
51309
|
+
const factor = byte ^ (result.shift() ?? 0);
|
|
51310
|
+
result.push(0);
|
|
51311
|
+
divisor.forEach((coefficient, i) => {
|
|
51312
|
+
result[i] = (result[i] ?? 0) ^ multiply(coefficient, factor);
|
|
51313
|
+
});
|
|
51314
|
+
}
|
|
51315
|
+
return result;
|
|
51316
|
+
}
|
|
51317
|
+
/** Multiplication in GF(2^8) modulo the QR polynomial 0x11D. */
|
|
51318
|
+
function multiply(x, y) {
|
|
51319
|
+
let z = 0;
|
|
51320
|
+
for (let i = 7; i >= 0; i--) {
|
|
51321
|
+
z = z << 1 ^ (z >>> 7) * 285;
|
|
51322
|
+
z ^= (y >>> i & 1) * x;
|
|
51323
|
+
}
|
|
51324
|
+
return z;
|
|
51325
|
+
}
|
|
51326
|
+
function drawFunctionPatterns(grid, version) {
|
|
51327
|
+
const { size } = grid;
|
|
51328
|
+
for (let i = 0; i < size; i++) {
|
|
51329
|
+
grid.setFunction(6, i, i % 2 === 0);
|
|
51330
|
+
grid.setFunction(i, 6, i % 2 === 0);
|
|
51331
|
+
}
|
|
51332
|
+
drawFinder(grid, 3, 3);
|
|
51333
|
+
drawFinder(grid, size - 4, 3);
|
|
51334
|
+
drawFinder(grid, 3, size - 4);
|
|
51335
|
+
const positions = alignmentPositions(version, size);
|
|
51336
|
+
const last = positions.length - 1;
|
|
51337
|
+
positions.forEach((x, i) => {
|
|
51338
|
+
positions.forEach((y, j) => {
|
|
51339
|
+
if (!(i === 0 && j === 0 || i === 0 && j === last || i === last && j === 0)) drawAlignment(grid, x, y);
|
|
51340
|
+
});
|
|
51341
|
+
});
|
|
51342
|
+
drawFormatBits(grid, 0);
|
|
51343
|
+
drawVersionBits(grid, version);
|
|
51344
|
+
}
|
|
51345
|
+
function drawFinder(grid, cx, cy) {
|
|
51346
|
+
for (let dy = -4; dy <= 4; dy++) for (let dx = -4; dx <= 4; dx++) {
|
|
51347
|
+
const x = cx + dx;
|
|
51348
|
+
const y = cy + dy;
|
|
51349
|
+
if (x < 0 || y < 0 || x >= grid.size || y >= grid.size) continue;
|
|
51350
|
+
const distance = Math.max(Math.abs(dx), Math.abs(dy));
|
|
51351
|
+
grid.setFunction(x, y, distance !== 2 && distance !== 4);
|
|
51352
|
+
}
|
|
51353
|
+
}
|
|
51354
|
+
function drawAlignment(grid, cx, cy) {
|
|
51355
|
+
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);
|
|
51356
|
+
}
|
|
51357
|
+
function alignmentPositions(version, size) {
|
|
51358
|
+
if (version === 1) return [];
|
|
51359
|
+
const count = Math.floor(version / 7) + 2;
|
|
51360
|
+
const step = Math.floor((version * 8 + count * 3 + 5) / (count * 4 - 4)) * 2;
|
|
51361
|
+
const result = [6];
|
|
51362
|
+
for (let position = size - 7; result.length < count; position -= step) result.splice(1, 0, position);
|
|
51363
|
+
return result;
|
|
51364
|
+
}
|
|
51365
|
+
function drawFormatBits(grid, mask) {
|
|
51366
|
+
const data = 0 | mask;
|
|
51367
|
+
let remainder = data;
|
|
51368
|
+
for (let i = 0; i < 10; i++) remainder = remainder << 1 ^ (remainder >>> 9) * 1335;
|
|
51369
|
+
const bits = (data << 10 | remainder) ^ 21522;
|
|
51370
|
+
const bit = (i) => (bits >>> i & 1) !== 0;
|
|
51371
|
+
const { size } = grid;
|
|
51372
|
+
for (let i = 0; i <= 5; i++) grid.setFunction(8, i, bit(i));
|
|
51373
|
+
grid.setFunction(8, 7, bit(6));
|
|
51374
|
+
grid.setFunction(8, 8, bit(7));
|
|
51375
|
+
grid.setFunction(7, 8, bit(8));
|
|
51376
|
+
for (let i = 9; i < 15; i++) grid.setFunction(14 - i, 8, bit(i));
|
|
51377
|
+
for (let i = 0; i < 8; i++) grid.setFunction(size - 1 - i, 8, bit(i));
|
|
51378
|
+
for (let i = 8; i < 15; i++) grid.setFunction(8, size - 15 + i, bit(i));
|
|
51379
|
+
grid.setFunction(8, size - 8, true);
|
|
51380
|
+
}
|
|
51381
|
+
function drawVersionBits(grid, version) {
|
|
51382
|
+
if (version < 7) return;
|
|
51383
|
+
let remainder = version;
|
|
51384
|
+
for (let i = 0; i < 12; i++) remainder = remainder << 1 ^ (remainder >>> 11) * 7973;
|
|
51385
|
+
const bits = version << 12 | remainder;
|
|
51386
|
+
for (let i = 0; i < 18; i++) {
|
|
51387
|
+
const dark = (bits >>> i & 1) !== 0;
|
|
51388
|
+
const a = grid.size - 11 + i % 3;
|
|
51389
|
+
const b = Math.floor(i / 3);
|
|
51390
|
+
grid.setFunction(a, b, dark);
|
|
51391
|
+
grid.setFunction(b, a, dark);
|
|
51392
|
+
}
|
|
51393
|
+
}
|
|
51394
|
+
/** Places the codewords in the two-column zigzag from the bottom right. */
|
|
51395
|
+
function drawCodewords(grid, codewords) {
|
|
51396
|
+
const { size } = grid;
|
|
51397
|
+
let i = 0;
|
|
51398
|
+
for (let right = size - 1; right >= 1; right -= 2) {
|
|
51399
|
+
if (right === 6) right = 5;
|
|
51400
|
+
for (let vertical = 0; vertical < size; vertical++) for (let j = 0; j < 2; j++) {
|
|
51401
|
+
const x = right - j;
|
|
51402
|
+
const y = (right + 1 & 2) === 0 ? size - 1 - vertical : vertical;
|
|
51403
|
+
if (grid.isReserved(x, y) || i >= codewords.length * 8) continue;
|
|
51404
|
+
grid.set(x, y, ((codewords[i >>> 3] ?? 0) >>> 7 - (i & 7) & 1) !== 0);
|
|
51405
|
+
i++;
|
|
51406
|
+
}
|
|
51407
|
+
}
|
|
51408
|
+
}
|
|
51409
|
+
const MASKS = [
|
|
51410
|
+
(x, y) => (x + y) % 2 === 0,
|
|
51411
|
+
(_x, y) => y % 2 === 0,
|
|
51412
|
+
(x) => x % 3 === 0,
|
|
51413
|
+
(x, y) => (x + y) % 3 === 0,
|
|
51414
|
+
(x, y) => (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0,
|
|
51415
|
+
(x, y) => x * y % 2 + x * y % 3 === 0,
|
|
51416
|
+
(x, y) => (x * y % 2 + x * y % 3) % 2 === 0,
|
|
51417
|
+
(x, y) => ((x + y) % 2 + x * y % 3) % 2 === 0
|
|
51418
|
+
];
|
|
51419
|
+
function applyMask(grid, mask) {
|
|
51420
|
+
const flips = MASKS[mask];
|
|
51421
|
+
if (!flips) return;
|
|
51422
|
+
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));
|
|
51423
|
+
}
|
|
51424
|
+
/**
|
|
51425
|
+
* The standard's four penalty rules, summed, lower being easier to scan. The
|
|
51426
|
+
* standard leaves the finder-like rule's edges open, so it is counted inside
|
|
51427
|
+
* the line, as the `qrcode` package does, which keeps both picking one mask.
|
|
51428
|
+
*/
|
|
51429
|
+
function penaltyScore(modules) {
|
|
51430
|
+
const size = modules.length;
|
|
51431
|
+
const at = (x, y) => modules[y]?.[x] ?? false;
|
|
51432
|
+
let result = 0;
|
|
51433
|
+
for (const horizontal of [true, false]) for (let a = 0; a < size; a++) {
|
|
51434
|
+
let run = 0;
|
|
51435
|
+
let previous = null;
|
|
51436
|
+
let window = 0;
|
|
51437
|
+
for (let b = 0; b < size; b++) {
|
|
51438
|
+
const dark = horizontal ? at(b, a) : at(a, b);
|
|
51439
|
+
if (dark === previous) run++;
|
|
51440
|
+
else {
|
|
51441
|
+
if (run >= 5) result += run - 2;
|
|
51442
|
+
run = 1;
|
|
51443
|
+
previous = dark;
|
|
51444
|
+
}
|
|
51445
|
+
window = window << 1 & 2047 | (dark ? 1 : 0);
|
|
51446
|
+
if (b >= 10 && (window === 1488 || window === 93)) result += 40;
|
|
51447
|
+
}
|
|
51448
|
+
if (run >= 5) result += run - 2;
|
|
51449
|
+
}
|
|
51450
|
+
for (let y = 0; y < size - 1; y++) for (let x = 0; x < size - 1; x++) {
|
|
51451
|
+
const dark = at(x, y);
|
|
51452
|
+
if (dark === at(x + 1, y) && dark === at(x, y + 1) && dark === at(x + 1, y + 1)) result += 3;
|
|
51453
|
+
}
|
|
51454
|
+
const dark = modules.flat().filter(Boolean).length;
|
|
51455
|
+
return result + Math.abs(Math.ceil(dark * 100 / (size * size) / 5) - 10) * 10;
|
|
51456
|
+
}
|
|
51457
|
+
// src/cli/commands/preview.ts
|
|
51458
|
+
/** The light modules a scanner wants around a code, at least four by the standard. */
|
|
51459
|
+
const QUIET_ZONE = 4;
|
|
51460
|
+
function registerPreview(program, context) {
|
|
51461
|
+
const { io } = context;
|
|
51462
|
+
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) => {
|
|
51463
|
+
const [ref] = args;
|
|
51464
|
+
const root = await boardOf(options, io);
|
|
51465
|
+
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.");
|
|
51466
|
+
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.");
|
|
51467
|
+
const frame = ref === void 0 ? null : await resolveFrameRef(root, ref, {
|
|
51468
|
+
project: options.project,
|
|
51469
|
+
cwd: io.cwd
|
|
51470
|
+
});
|
|
51471
|
+
const live = await findLiveServer(root);
|
|
51472
|
+
if (!live) throw new FrameboardError("server-not-running", `No frameboard server is running for ${root}. Run frameboard serve first.`, { root });
|
|
51473
|
+
if (frame === null) {
|
|
51474
|
+
const data = await deleteFromBoard(live, "/api/preview", {});
|
|
51475
|
+
return {
|
|
51476
|
+
data,
|
|
51477
|
+
human: data.stopped ? "Ended the phone link" : "No phone link was open"
|
|
51478
|
+
};
|
|
51479
|
+
}
|
|
51480
|
+
const data = await postToBoard(live, "/api/preview", {
|
|
51481
|
+
ref: `${frame.project}/${frame.page}/${frame.name}`,
|
|
51482
|
+
...options.port === void 0 ? {} : { port: options.port }
|
|
51483
|
+
});
|
|
51484
|
+
return {
|
|
51485
|
+
data,
|
|
51486
|
+
human: [
|
|
51487
|
+
terminalCode(qrModules(data.url)),
|
|
51488
|
+
data.url,
|
|
51489
|
+
`Scan on the same Wi-Fi. It opens ${data.project} read only until the board stops or frameboard preview --stop runs.`
|
|
51490
|
+
].join("\n")
|
|
51491
|
+
};
|
|
51492
|
+
});
|
|
51493
|
+
}
|
|
51494
|
+
/**
|
|
51495
|
+
* The code drawn two rows to a line in half blocks, black on a forced white
|
|
51496
|
+
* ground, so it scans on a dark terminal as on a light one.
|
|
51497
|
+
*/
|
|
51498
|
+
function terminalCode(modules) {
|
|
51499
|
+
const size = modules.length + 8;
|
|
51500
|
+
const dark = (x, y) => modules[y - QUIET_ZONE]?.[x - QUIET_ZONE] ?? false;
|
|
51501
|
+
const lines = [];
|
|
51502
|
+
for (let y = 0; y < size; y += 2) {
|
|
51503
|
+
let line = "";
|
|
51504
|
+
for (let x = 0; x < size; x++) {
|
|
51505
|
+
const top = dark(x, y);
|
|
51506
|
+
const bottom = dark(x, y + 1);
|
|
51507
|
+
line += top && bottom ? "█" : top ? "▀" : bottom ? "▄" : " ";
|
|
51508
|
+
}
|
|
51509
|
+
lines.push(`\x1b[30;47m${line}\x1b[0m`);
|
|
51510
|
+
}
|
|
51511
|
+
return lines.join("\n");
|
|
51512
|
+
}
|
|
50229
51513
|
// src/cli/commands/project.ts
|
|
50230
51514
|
function registerProject(program, context) {
|
|
50231
51515
|
const { io } = context;
|
|
@@ -54973,6 +56257,159 @@ function createDelivery({ pending, markDelivered, onListeners, now }) {
|
|
|
54973
56257
|
listeners
|
|
54974
56258
|
};
|
|
54975
56259
|
}
|
|
56260
|
+
// src/server/preview/listener.ts
|
|
56261
|
+
/** Where every phone link starts, ahead of its token. */
|
|
56262
|
+
const LINK_PREFIX = "/v/";
|
|
56263
|
+
/** The bytes of a link's token, 96 bits, which keeps the code small. */
|
|
56264
|
+
const TOKEN_BYTES = 12;
|
|
56265
|
+
/**
|
|
56266
|
+
* The phone link's read-only app: GET and HEAD under `/v/<token>/` for one
|
|
56267
|
+
* project's frames and assets at `frames/<project>/...` and the faces and
|
|
56268
|
+
* board sheet at `frameboard/...`, each answered by the board's own frame and
|
|
56269
|
+
* look routes, so their refusals of board records, dot-named paths, and
|
|
56270
|
+
* escaping paths hold here unrestated. Anything else answers 404, so nothing
|
|
56271
|
+
* tells a caller what exists. It carries no Host check, since a phone names
|
|
56272
|
+
* the machine's address, and the token is what keeps other pages out.
|
|
56273
|
+
*/
|
|
56274
|
+
function previewApp(token, options) {
|
|
56275
|
+
const base = `${LINK_PREFIX}${token}`;
|
|
56276
|
+
const served = servedFrames(options.root, {
|
|
56277
|
+
facesDir: options.facesDir,
|
|
56278
|
+
tokens: options.tokens ?? null,
|
|
56279
|
+
base
|
|
56280
|
+
}).routes;
|
|
56281
|
+
const app = new Hono();
|
|
56282
|
+
app.use("*", async (c, next) => {
|
|
56283
|
+
await next();
|
|
56284
|
+
c.res = withHeader(c.res, "Referrer-Policy", "no-referrer");
|
|
56285
|
+
});
|
|
56286
|
+
app.all("*", async (c) => {
|
|
56287
|
+
const method = c.req.method;
|
|
56288
|
+
if (method !== "GET" && method !== "HEAD") return c.notFound();
|
|
56289
|
+
const url = new URL(c.req.url);
|
|
56290
|
+
const inner = innerPath(url.pathname, token, options.project);
|
|
56291
|
+
if (inner === null) return c.notFound();
|
|
56292
|
+
const headers = new Headers();
|
|
56293
|
+
for (const name of ["range", "if-none-match"]) {
|
|
56294
|
+
const value = c.req.header(name);
|
|
56295
|
+
if (value !== void 0) headers.set(name, value);
|
|
56296
|
+
}
|
|
56297
|
+
const theme = url.searchParams.get("theme");
|
|
56298
|
+
const query = theme === null ? "" : `?${new URLSearchParams({ theme })}`;
|
|
56299
|
+
return served.fetch(new Request(`http://preview${inner}${query}`, {
|
|
56300
|
+
method,
|
|
56301
|
+
headers
|
|
56302
|
+
}));
|
|
56303
|
+
});
|
|
56304
|
+
return app;
|
|
56305
|
+
}
|
|
56306
|
+
/**
|
|
56307
|
+
* The board path a phone path stands for, or null when it names another
|
|
56308
|
+
* token, another project, or anything outside the frames and the look.
|
|
56309
|
+
*/
|
|
56310
|
+
function innerPath(pathname, token, project) {
|
|
56311
|
+
if (!pathname.startsWith(LINK_PREFIX)) return null;
|
|
56312
|
+
const [given = "", ...rest] = pathname.slice(3).split("/");
|
|
56313
|
+
if (!sameToken(given, token)) return null;
|
|
56314
|
+
const inner = `/${rest.join("/")}`;
|
|
56315
|
+
if (inner === "/frameboard/tokens.css" || inner.startsWith(`/frameboard/faces/`)) return inner;
|
|
56316
|
+
const [area, named, ...within] = rest;
|
|
56317
|
+
if (area !== "frames" || within.length === 0) return null;
|
|
56318
|
+
let decoded;
|
|
56319
|
+
try {
|
|
56320
|
+
decoded = decodeURIComponent(named ?? "");
|
|
56321
|
+
} catch {
|
|
56322
|
+
return null;
|
|
56323
|
+
}
|
|
56324
|
+
return decoded === project ? inner : null;
|
|
56325
|
+
}
|
|
56326
|
+
/** The response with one header set, copied first since a forwarded one may be immutable. */
|
|
56327
|
+
function withHeader(response, name, value) {
|
|
56328
|
+
const headers = new Headers(response.headers);
|
|
56329
|
+
headers.set(name, value);
|
|
56330
|
+
return new Response(response.body, {
|
|
56331
|
+
status: response.status,
|
|
56332
|
+
statusText: response.statusText,
|
|
56333
|
+
headers
|
|
56334
|
+
});
|
|
56335
|
+
}
|
|
56336
|
+
function sameToken(given, token) {
|
|
56337
|
+
const a = Buffer.from(given);
|
|
56338
|
+
const b = Buffer.from(token);
|
|
56339
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
56340
|
+
}
|
|
56341
|
+
/**
|
|
56342
|
+
* Starts the phone listener on `host`, the machine's local network address,
|
|
56343
|
+
* at `port`, or on a free port when that one is taken, with a fresh token.
|
|
56344
|
+
* Binding the one address rather than every interface keeps the listener off
|
|
56345
|
+
* any other network the machine sits on. The board's own listener is
|
|
56346
|
+
* untouched, staying on loopback behind its Host check.
|
|
56347
|
+
*/
|
|
56348
|
+
async function startPreviewListener(options) {
|
|
56349
|
+
const token = randomBytes(TOKEN_BYTES).toString("base64url");
|
|
56350
|
+
const app = previewApp(token, options);
|
|
56351
|
+
let server;
|
|
56352
|
+
try {
|
|
56353
|
+
server = await bind(app, options.host, options.port);
|
|
56354
|
+
} catch (error) {
|
|
56355
|
+
if (!(error.code === "EADDRINUSE") || options.port === 0) throw error;
|
|
56356
|
+
server = await bind(app, options.host, 0);
|
|
56357
|
+
}
|
|
56358
|
+
const { port } = server.address();
|
|
56359
|
+
return {
|
|
56360
|
+
token,
|
|
56361
|
+
host: options.host,
|
|
56362
|
+
port,
|
|
56363
|
+
project: options.project,
|
|
56364
|
+
close: () => new Promise((resolve) => {
|
|
56365
|
+
server.close(() => resolve());
|
|
56366
|
+
server.closeAllConnections();
|
|
56367
|
+
})
|
|
56368
|
+
};
|
|
56369
|
+
}
|
|
56370
|
+
function bind(app, hostname, port) {
|
|
56371
|
+
return new Promise((resolve, reject) => {
|
|
56372
|
+
const created = serve({
|
|
56373
|
+
fetch: app.fetch,
|
|
56374
|
+
hostname,
|
|
56375
|
+
port
|
|
56376
|
+
}, () => resolve(created));
|
|
56377
|
+
created.once("error", reject);
|
|
56378
|
+
});
|
|
56379
|
+
}
|
|
56380
|
+
/**
|
|
56381
|
+
* Holds the board's phone listener, running each start and stop in turn so
|
|
56382
|
+
* two never race to bind. The board ends it with `stop()` as it closes.
|
|
56383
|
+
*/
|
|
56384
|
+
function createPreviewSlot(options) {
|
|
56385
|
+
let running = null;
|
|
56386
|
+
let turn = Promise.resolve();
|
|
56387
|
+
const inTurn = (work) => {
|
|
56388
|
+
const next = turn.then(work, work);
|
|
56389
|
+
turn = next.catch(() => void 0);
|
|
56390
|
+
return next;
|
|
56391
|
+
};
|
|
56392
|
+
const end = async (token) => {
|
|
56393
|
+
if (!running || token !== void 0 && running.token !== token) return false;
|
|
56394
|
+
const ending = running;
|
|
56395
|
+
running = null;
|
|
56396
|
+
await ending.close();
|
|
56397
|
+
return true;
|
|
56398
|
+
};
|
|
56399
|
+
return {
|
|
56400
|
+
start: (project, host, port) => inTurn(async () => {
|
|
56401
|
+
await end();
|
|
56402
|
+
running = await startPreviewListener({
|
|
56403
|
+
...options,
|
|
56404
|
+
project,
|
|
56405
|
+
host,
|
|
56406
|
+
port
|
|
56407
|
+
});
|
|
56408
|
+
return running;
|
|
56409
|
+
}),
|
|
56410
|
+
stop: (token) => inTurn(() => end(token))
|
|
56411
|
+
};
|
|
56412
|
+
}
|
|
54976
56413
|
// src/server/start.ts
|
|
54977
56414
|
const HOSTNAME = "127.0.0.1";
|
|
54978
56415
|
/**
|
|
@@ -55231,6 +56668,11 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
55231
56668
|
measure
|
|
55232
56669
|
});
|
|
55233
56670
|
const assetUsage = createAssetUsage(root);
|
|
56671
|
+
const preview = createPreviewSlot({
|
|
56672
|
+
root,
|
|
56673
|
+
facesDir,
|
|
56674
|
+
tokens
|
|
56675
|
+
});
|
|
55234
56676
|
const app = createApp({
|
|
55235
56677
|
clientDir,
|
|
55236
56678
|
facesDir,
|
|
@@ -55246,6 +56688,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
55246
56688
|
renderFrame,
|
|
55247
56689
|
renderFilmstrip,
|
|
55248
56690
|
clipboard: clipboardFiles(),
|
|
56691
|
+
preview,
|
|
55249
56692
|
thumbnails,
|
|
55250
56693
|
measure,
|
|
55251
56694
|
frameVersion: tracker.version,
|
|
@@ -55360,7 +56803,8 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
55360
56803
|
watcher.close(),
|
|
55361
56804
|
hub.close(),
|
|
55362
56805
|
browser.close(),
|
|
55363
|
-
emptyTrash(root)
|
|
56806
|
+
emptyTrash(root),
|
|
56807
|
+
preview.stop()
|
|
55364
56808
|
]);
|
|
55365
56809
|
await new Promise((done, fail) => {
|
|
55366
56810
|
server.close((error) => error ? fail(error) : done());
|
|
@@ -55809,6 +57253,7 @@ function createProgram(context) {
|
|
|
55809
57253
|
registerServe(program, faced);
|
|
55810
57254
|
registerShow(program, context);
|
|
55811
57255
|
registerOpen(program, context);
|
|
57256
|
+
registerPreview(program, context);
|
|
55812
57257
|
registerSelection(program, context);
|
|
55813
57258
|
registerList(program, context);
|
|
55814
57259
|
registerProject(program, context);
|