frameboard 0.44.0 → 0.46.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 +2258 -614
- package/dist/client/assets/index-7T-3-XIO.css +2 -0
- package/dist/client/assets/index-DS22rwPq.js +165 -0
- package/dist/client/index.html +2 -2
- package/dist/frame-bridge.js +91 -69
- package/dist/hook.js +2 -2
- package/package.json +1 -1
- package/dist/client/assets/index-Bh7QIOuP.js +0 -181
- package/dist/client/assets/index-vZBQT6hk.css +0 -2
package/dist/cli.js
CHANGED
|
@@ -9586,17 +9586,61 @@ const BATTERY = {
|
|
|
9586
9586
|
radius: 3.5,
|
|
9587
9587
|
cap: 2
|
|
9588
9588
|
};
|
|
9589
|
-
/**
|
|
9590
|
-
|
|
9591
|
-
|
|
9589
|
+
/**
|
|
9590
|
+
* The ways a phone, a tablet, or a foldable is held, upright or turned a
|
|
9591
|
+
* quarter with its island on the left or on the right side.
|
|
9592
|
+
*/
|
|
9593
|
+
const TURNS = [
|
|
9594
|
+
"upright",
|
|
9595
|
+
"left",
|
|
9596
|
+
"right"
|
|
9597
|
+
];
|
|
9598
|
+
/** A layout entry's `turn` as a turn, upright for none or a value no reader knows. */
|
|
9599
|
+
function turnOf(value) {
|
|
9600
|
+
return value === "left" || value === "right" ? value : "upright";
|
|
9601
|
+
}
|
|
9602
|
+
/** Whether a device turns, which a phone, a tablet, and a foldable do and a laptop does not. */
|
|
9603
|
+
function turnsWith(device) {
|
|
9604
|
+
return device === "phone" || device === "tablet" || device === "foldable";
|
|
9605
|
+
}
|
|
9606
|
+
/** A layout entry's `upright` as a size, null for none or a value of another shape. */
|
|
9607
|
+
function uprightOf(value) {
|
|
9608
|
+
if (typeof value !== "object" || value === null) return null;
|
|
9609
|
+
if (!("width" in value) || !("height" in value)) return null;
|
|
9610
|
+
const { width, height } = value;
|
|
9611
|
+
if (typeof width !== "number" || typeof height !== "number") return null;
|
|
9612
|
+
return Number.isInteger(width) && Number.isInteger(height) && width > 0 && height > 0 ? {
|
|
9613
|
+
width,
|
|
9614
|
+
height
|
|
9615
|
+
} : null;
|
|
9592
9616
|
}
|
|
9593
9617
|
/**
|
|
9594
|
-
* The
|
|
9595
|
-
*
|
|
9596
|
-
* box
|
|
9618
|
+
* The width that picks the device for a frame, its kept upright width while
|
|
9619
|
+
* turned, so a turned phone reads as a phone and never as the tablet its
|
|
9620
|
+
* landscape box is wide enough for.
|
|
9597
9621
|
*/
|
|
9598
|
-
function
|
|
9599
|
-
const
|
|
9622
|
+
function uprightWidth(entry) {
|
|
9623
|
+
const upright = uprightOf(entry.upright);
|
|
9624
|
+
return turnOf(entry.turn) !== "upright" && upright ? upright.width : entry.width;
|
|
9625
|
+
}
|
|
9626
|
+
/** Whether a device draws turned, which any device but a laptop does. */
|
|
9627
|
+
function isTurned(device, turn) {
|
|
9628
|
+
return turnsWith(device) && turnOf(turn) !== "upright";
|
|
9629
|
+
}
|
|
9630
|
+
/**
|
|
9631
|
+
* The height the device's status bar takes off the top of a frame's box, 0
|
|
9632
|
+
* for any device but an upright phone, since a turned one hides its bar.
|
|
9633
|
+
*/
|
|
9634
|
+
function topInset(device, turn) {
|
|
9635
|
+
return device === "phone" && !isTurned(device, turn) ? STATUS_BAR.height : 0;
|
|
9636
|
+
}
|
|
9637
|
+
/**
|
|
9638
|
+
* The page's box inside a frame's box, less the status bar while an upright
|
|
9639
|
+
* phone shows. A frame's box keeps the screen's size, and every surface reads
|
|
9640
|
+
* the page through this.
|
|
9641
|
+
*/
|
|
9642
|
+
function pageBox(box, device, turn) {
|
|
9643
|
+
const inset = topInset(device, turn);
|
|
9600
9644
|
return {
|
|
9601
9645
|
x: box.x,
|
|
9602
9646
|
y: box.y + inset,
|
|
@@ -9604,9 +9648,9 @@ function pageBox(box, device) {
|
|
|
9604
9648
|
height: Math.max(0, box.height - inset)
|
|
9605
9649
|
};
|
|
9606
9650
|
}
|
|
9607
|
-
/** The page's corners as a CSS `border-radius`, square on top under
|
|
9608
|
-
function pageCorners(device) {
|
|
9609
|
-
if (device !== "phone") return screenCorners(device);
|
|
9651
|
+
/** The page's corners as a CSS `border-radius`, square on top under an upright phone's status bar. */
|
|
9652
|
+
function pageCorners(device, turn) {
|
|
9653
|
+
if (device !== "phone" || isTurned(device, turn)) return screenCorners(device);
|
|
9610
9654
|
const { screenRadius } = BEZELS.phone;
|
|
9611
9655
|
return `0 0 ${screenRadius}px ${screenRadius}px`;
|
|
9612
9656
|
}
|
|
@@ -9668,23 +9712,44 @@ const FOLDABLE_ISLAND = {
|
|
|
9668
9712
|
height: 30,
|
|
9669
9713
|
top: 14
|
|
9670
9714
|
};
|
|
9671
|
-
/**
|
|
9672
|
-
|
|
9673
|
-
|
|
9715
|
+
/**
|
|
9716
|
+
* Where the island sits on a pose's screen, where a quarter turn puts it: a
|
|
9717
|
+
* turn left lays the top edge down the left side, so a share across the top
|
|
9718
|
+
* reads from the bottom, and a turn right lays it down the right side.
|
|
9719
|
+
*/
|
|
9720
|
+
function islandCenter(pose, turn) {
|
|
9721
|
+
const across = pose === "closed" ? .5 : .75;
|
|
9722
|
+
if (turn === "left") return {
|
|
9723
|
+
edge: "left",
|
|
9724
|
+
along: 1 - across
|
|
9725
|
+
};
|
|
9726
|
+
if (turn === "right") return {
|
|
9727
|
+
edge: "right",
|
|
9728
|
+
along: across
|
|
9729
|
+
};
|
|
9730
|
+
return {
|
|
9731
|
+
edge: "top",
|
|
9732
|
+
along: across
|
|
9733
|
+
};
|
|
9674
9734
|
}
|
|
9675
9735
|
/**
|
|
9676
|
-
* The band drawn
|
|
9677
|
-
* and a shaded fold half open,
|
|
9736
|
+
* The band drawn through the middle of the inner screen, a faint crease open
|
|
9737
|
+
* and a shaded fold half open, running down the screen upright and across it
|
|
9738
|
+
* turned, null on the cover screen, which has no fold.
|
|
9678
9739
|
*/
|
|
9679
|
-
function foldBand(pose) {
|
|
9740
|
+
function foldBand(pose, turn) {
|
|
9680
9741
|
if (pose === "closed") return null;
|
|
9742
|
+
const runs = turn === "upright" ? "down" : "across";
|
|
9743
|
+
const angle = runs === "down" ? "90deg" : "180deg";
|
|
9681
9744
|
if (pose === "open") return {
|
|
9682
9745
|
width: 26,
|
|
9683
|
-
|
|
9746
|
+
runs,
|
|
9747
|
+
background: `linear-gradient(${angle}, transparent, rgba(0,0,0,.05) 35%, rgba(0,0,0,.11) 50%, rgba(255,255,255,.5) 56%, transparent)`
|
|
9684
9748
|
};
|
|
9685
9749
|
return {
|
|
9686
9750
|
width: 150,
|
|
9687
|
-
|
|
9751
|
+
runs,
|
|
9752
|
+
background: `linear-gradient(${angle}, transparent, rgba(0,0,0,.10) 30%, rgba(0,0,0,.34) 49%, rgba(0,0,0,.34) 51%, rgba(0,0,0,.08) 70%, transparent)`
|
|
9688
9753
|
};
|
|
9689
9754
|
}
|
|
9690
9755
|
/**
|
|
@@ -9734,18 +9799,21 @@ function bezelShadow(device, { board = true } = {}) {
|
|
|
9734
9799
|
}
|
|
9735
9800
|
/**
|
|
9736
9801
|
* The box a device's body covers around a frame's box, the box itself with
|
|
9737
|
-
* none. A laptop's base
|
|
9738
|
-
*
|
|
9802
|
+
* none. A laptop's base and a phone's buttons reach past its sides, and a
|
|
9803
|
+
* turned phone's buttons past its top and bottom instead.
|
|
9739
9804
|
*/
|
|
9740
|
-
function bezelBox(box, device) {
|
|
9805
|
+
function bezelBox(box, device, turn) {
|
|
9741
9806
|
if (!device) return { ...box };
|
|
9742
9807
|
const { border, bottom } = BEZELS[device];
|
|
9743
|
-
const
|
|
9808
|
+
const reach = sideReach(device, box.width);
|
|
9809
|
+
const turned = isTurned(device, turn);
|
|
9810
|
+
const side = border + (turned ? 0 : reach);
|
|
9811
|
+
const end = turned ? reach : 0;
|
|
9744
9812
|
return {
|
|
9745
9813
|
x: box.x - side,
|
|
9746
|
-
y: box.y - border,
|
|
9814
|
+
y: box.y - border - end,
|
|
9747
9815
|
width: box.width + 2 * side,
|
|
9748
|
-
height: box.height + border + bottom
|
|
9816
|
+
height: box.height + border + bottom + 2 * end
|
|
9749
9817
|
};
|
|
9750
9818
|
}
|
|
9751
9819
|
// src/shared/frame-widths.ts
|
|
@@ -9784,7 +9852,7 @@ function isSize(value) {
|
|
|
9784
9852
|
*/
|
|
9785
9853
|
function linkedBoxes(box, widths, device) {
|
|
9786
9854
|
const boxes = [];
|
|
9787
|
-
const body = bezelBox(box, device);
|
|
9855
|
+
const body = bezelBox(box, device, "upright");
|
|
9788
9856
|
const lid = device ? BEZELS[device].border : 0;
|
|
9789
9857
|
let x = body.x + body.width - lid;
|
|
9790
9858
|
for (const { width, height } of widths) {
|
|
@@ -9804,7 +9872,7 @@ function linkedBoxes(box, widths, device) {
|
|
|
9804
9872
|
* width it draws, the frame's own with neither. Linked widths draw no device.
|
|
9805
9873
|
*/
|
|
9806
9874
|
function drawnExtent(box, widths, device) {
|
|
9807
|
-
const boxes = [bezelBox(box, device), ...linkedBoxes(box, widths, device)];
|
|
9875
|
+
const boxes = [bezelBox(box, device, "upright"), ...linkedBoxes(box, widths, device)];
|
|
9808
9876
|
const left = Math.min(...boxes.map(({ x }) => x));
|
|
9809
9877
|
const top = Math.min(...boxes.map(({ y }) => y));
|
|
9810
9878
|
const right = Math.max(...boxes.map(({ x, width }) => x + width));
|
|
@@ -9826,7 +9894,7 @@ function xPast(edge, width, device) {
|
|
|
9826
9894
|
y: 0,
|
|
9827
9895
|
width,
|
|
9828
9896
|
height: 0
|
|
9829
|
-
}, device);
|
|
9897
|
+
}, device, "upright");
|
|
9830
9898
|
return edge + 80 - body.x;
|
|
9831
9899
|
}
|
|
9832
9900
|
// src/shared/names.ts
|
|
@@ -10080,6 +10148,8 @@ const layoutEntrySchema = looseObject({
|
|
|
10080
10148
|
foldable: unknown().optional(),
|
|
10081
10149
|
pose: unknown().optional(),
|
|
10082
10150
|
island: unknown().optional(),
|
|
10151
|
+
turn: unknown().optional(),
|
|
10152
|
+
upright: unknown().optional(),
|
|
10083
10153
|
transition: unknown().optional(),
|
|
10084
10154
|
speakerNotes: unknown().optional(),
|
|
10085
10155
|
kit: unknown().optional()
|
|
@@ -24734,7 +24804,7 @@ const STEP = /^(?:from|to|\d+(?:\.\d+)?%)(?:\s*,\s*(?:from|to|\d+(?:\.\d+)?%))*$
|
|
|
24734
24804
|
* it in its own document, a value that could load a file included.
|
|
24735
24805
|
*/
|
|
24736
24806
|
function readTransitionSheet(name, css) {
|
|
24737
|
-
if (!isOwnTransitionName(name)) return refused$
|
|
24807
|
+
if (!isOwnTransitionName(name)) return refused$2([{
|
|
24738
24808
|
message: `${name} is no transition name. Name the file in lowercase kebab case, and not after a built-in transition, none, or page`,
|
|
24739
24809
|
location: null
|
|
24740
24810
|
}]);
|
|
@@ -24744,7 +24814,7 @@ function readTransitionSheet(name, css) {
|
|
|
24744
24814
|
} catch (error) {
|
|
24745
24815
|
if (!(error instanceof CssSyntaxError)) throw error;
|
|
24746
24816
|
const at = offsetOf(css, error.line ?? 1, error.column ?? 1);
|
|
24747
|
-
return refused$
|
|
24817
|
+
return refused$2([{
|
|
24748
24818
|
message: `The stylesheet does not parse: ${error.reason}`,
|
|
24749
24819
|
location: {
|
|
24750
24820
|
line: error.line ?? 1,
|
|
@@ -24771,15 +24841,15 @@ function readTransitionSheet(name, css) {
|
|
|
24771
24841
|
message: "@keyframes enter is missing",
|
|
24772
24842
|
location: null
|
|
24773
24843
|
});
|
|
24774
|
-
if (!enter || problems.length > 0) return refused$
|
|
24844
|
+
if (!enter || problems.length > 0) return refused$2(problems);
|
|
24775
24845
|
const leave = held.get("leave");
|
|
24776
24846
|
return {
|
|
24777
24847
|
ok: true,
|
|
24778
|
-
enter: bodyOf(enter),
|
|
24779
|
-
leave: leave ? bodyOf(leave) : null
|
|
24848
|
+
enter: bodyOf$1(enter),
|
|
24849
|
+
leave: leave ? bodyOf$1(leave) : null
|
|
24780
24850
|
};
|
|
24781
24851
|
}
|
|
24782
|
-
function refused$
|
|
24852
|
+
function refused$2(problems) {
|
|
24783
24853
|
return {
|
|
24784
24854
|
ok: false,
|
|
24785
24855
|
problems
|
|
@@ -24847,7 +24917,7 @@ function problemAt(node, message) {
|
|
|
24847
24917
|
};
|
|
24848
24918
|
}
|
|
24849
24919
|
/** The steps inside a keyframes block, on one line, with its comments dropped. */
|
|
24850
|
-
function bodyOf(block) {
|
|
24920
|
+
function bodyOf$1(block) {
|
|
24851
24921
|
return (block.nodes ?? []).filter((node) => node.type === "rule").map((step) => {
|
|
24852
24922
|
const declarations = step.nodes.filter((child) => child.type === "decl").map((child) => `${child.prop}: ${child.value}${child.important ? " !important" : ""}`);
|
|
24853
24923
|
return `${step.selector.trim()} { ${declarations.join("; ")} }`;
|
|
@@ -25062,7 +25132,9 @@ function placeFrames(frames, names, readTransition = storedTransitionOf) {
|
|
|
25062
25132
|
const shown = showsDevice(entry);
|
|
25063
25133
|
const foldable = entry.foldable === true;
|
|
25064
25134
|
const kept = widthsOf(entry.widths);
|
|
25065
|
-
const
|
|
25135
|
+
const upright = uprightOf(entry.upright);
|
|
25136
|
+
const turn = foldable || upright ? turnOf(entry.turn) : "upright";
|
|
25137
|
+
const named = foldable ? "foldable" : deviceForWidth(uprightWidth(entry));
|
|
25066
25138
|
const device = shown ? named : null;
|
|
25067
25139
|
const transition = readTransition(entry.transition);
|
|
25068
25140
|
const speakerNotes = speakerNotesOf(entry.speakerNotes);
|
|
@@ -25084,6 +25156,11 @@ function placeFrames(frames, names, readTransition = storedTransitionOf) {
|
|
|
25084
25156
|
} : {},
|
|
25085
25157
|
...foldable && kept.length > 0 ? { keptWidths: kept } : {},
|
|
25086
25158
|
...islandOf(entry.island) === "wide" ? { island: "wide" } : {},
|
|
25159
|
+
...turn !== "upright" && foldable ? { turn } : {},
|
|
25160
|
+
...turn !== "upright" && !foldable && upright ? {
|
|
25161
|
+
turn,
|
|
25162
|
+
upright
|
|
25163
|
+
} : {},
|
|
25087
25164
|
...transition ? { transition } : {},
|
|
25088
25165
|
...speakerNotes ? { speakerNotes } : {},
|
|
25089
25166
|
...kit ? { kit } : {},
|
|
@@ -25196,7 +25273,7 @@ async function scanPage(root, project, name, index, transitions) {
|
|
|
25196
25273
|
const placements = placeFrames(frames, names, (value) => transitionOf(value, own));
|
|
25197
25274
|
const stacked = (await Promise.all(names.map(async (frame) => {
|
|
25198
25275
|
const framePath = join(path, `${frame}${FRAME_EXTENSION}`);
|
|
25199
|
-
const { foldable: _named, keptWidths: _kept, ...placement } = placements.get(frame) ?? placeNext([]);
|
|
25276
|
+
const { foldable: _named, keptWidths: _kept, upright: _upright, ...placement } = placements.get(frame) ?? placeNext([]);
|
|
25200
25277
|
return {
|
|
25201
25278
|
ref: `${project}/${name}/${frame}`,
|
|
25202
25279
|
project,
|
|
@@ -25315,7 +25392,7 @@ async function isDirectory(path) {
|
|
|
25315
25392
|
}
|
|
25316
25393
|
}
|
|
25317
25394
|
// package.json
|
|
25318
|
-
var version$1 = "0.
|
|
25395
|
+
var version$1 = "0.46.0";
|
|
25319
25396
|
var dependencies = { "playwright-core": "1.65.0" };
|
|
25320
25397
|
var peerDependencies = { "oxfmt": "0.78.0" };
|
|
25321
25398
|
// src/shared/version.ts
|
|
@@ -25819,6 +25896,11 @@ function resizedPlacement(placement, frameRef, size, options) {
|
|
|
25819
25896
|
ref: frameRef,
|
|
25820
25897
|
widths: options.widths
|
|
25821
25898
|
});
|
|
25899
|
+
if (placement.turn && options.widths && options.widths.length > 0) throw new FrameboardError("usage", `${frameRef} is turned ${placement.turn}, and each extra width is an upright preview, so it shows at no other width. Turn it upright first.`, {
|
|
25900
|
+
ref: frameRef,
|
|
25901
|
+
turn: placement.turn,
|
|
25902
|
+
widths: options.widths
|
|
25903
|
+
});
|
|
25822
25904
|
const scroll = options.scroll ?? placement.scroll;
|
|
25823
25905
|
const width = size.width ?? placement.box.width;
|
|
25824
25906
|
const drops = scroll && placement.hugHeight && size.height === void 0;
|
|
@@ -26102,24 +26184,30 @@ async function setFrameFlag(root, ref, flag, { on, ...options }) {
|
|
|
26102
26184
|
}));
|
|
26103
26185
|
}
|
|
26104
26186
|
/**
|
|
26105
|
-
* Shows or hides a frame's device, names or
|
|
26106
|
-
*
|
|
26107
|
-
*
|
|
26187
|
+
* Shows or hides a frame's device, names, folds, or turns it, never writing
|
|
26188
|
+
* the frame's file. A named foldable's box is its pose's screen, both axes
|
|
26189
|
+
* fixed, sides swapped while turned, and a turned frame stands upright first.
|
|
26108
26190
|
*/
|
|
26109
|
-
async function setFrameDevice(root, ref, show, { foldable: name, pose: fold, island: pick, ...options }) {
|
|
26110
|
-
return updatePlacement(root, ref, options, (
|
|
26111
|
-
const
|
|
26112
|
-
const
|
|
26191
|
+
async function setFrameDevice(root, ref, show, { foldable: name, pose: fold, island: pick, turn, ...options }) {
|
|
26192
|
+
return updatePlacement(root, ref, options, (stood, frameRef) => {
|
|
26193
|
+
const foldable = name ?? stood.foldable === true;
|
|
26194
|
+
const shown = show ?? (name === true || stood.showDevice === true);
|
|
26195
|
+
const unfolded = stood.foldable === true ? unfoldedPlacement(stood, foldable) : stood;
|
|
26196
|
+
if (turn && turn !== "upright") refuseTurn(unfolded, frameRef, turn, {
|
|
26197
|
+
foldable,
|
|
26198
|
+
shown
|
|
26199
|
+
});
|
|
26200
|
+
const placement = stood.foldable === true && foldable ? unfolded : turnedPlacement(unfolded, foldable ? "upright" : turn);
|
|
26201
|
+
const { showDevice: _held, device: _device, foldable: named, pose: stored, keptWidths, island: picked, turn: held, ...rest } = placement;
|
|
26113
26202
|
if (fold && !foldable) throw new FrameboardError("usage", `${frameRef} is not a foldable, so it has no pose. Name it with --foldable first.`, {
|
|
26114
26203
|
ref: frameRef,
|
|
26115
26204
|
pose: fold
|
|
26116
26205
|
});
|
|
26117
|
-
if (pick && (foldable ||
|
|
26206
|
+
if (pick && (foldable || drawnDevice(placement) !== "phone")) throw new FrameboardError("usage", `${frameRef} draws no phone, so it has no island. A frame 320 to 479 px wide that names no foldable draws one.`, {
|
|
26118
26207
|
ref: frameRef,
|
|
26119
26208
|
island: pick
|
|
26120
26209
|
});
|
|
26121
26210
|
const island = pick ?? islandOf(picked);
|
|
26122
|
-
const shown = show ?? (name === true || held === true);
|
|
26123
26211
|
const base = {
|
|
26124
26212
|
...rest,
|
|
26125
26213
|
...shown ? { showDevice: true } : {},
|
|
@@ -26129,6 +26217,7 @@ async function setFrameDevice(root, ref, show, { foldable: name, pose: fold, isl
|
|
|
26129
26217
|
const widths = (keptWidths ?? rest.widths).filter((linked) => linked.width !== placement.box.width);
|
|
26130
26218
|
return {
|
|
26131
26219
|
...base,
|
|
26220
|
+
...held ? { turn: held } : {},
|
|
26132
26221
|
widths
|
|
26133
26222
|
};
|
|
26134
26223
|
}
|
|
@@ -26138,25 +26227,141 @@ async function setFrameDevice(root, ref, show, { foldable: name, pose: fold, isl
|
|
|
26138
26227
|
...undrawn.length > 0 ? { keptWidths: undrawn } : {}
|
|
26139
26228
|
};
|
|
26140
26229
|
const pose = fold ?? stored ?? nearestPose(placement.box.width);
|
|
26141
|
-
|
|
26230
|
+
const facing = turn ?? turnOf(held);
|
|
26231
|
+
const sideways = facing === "upright" ? {} : { turn: facing };
|
|
26232
|
+
if (!fold && !turn && named) return {
|
|
26142
26233
|
...base,
|
|
26143
26234
|
...kept,
|
|
26144
26235
|
foldable,
|
|
26145
|
-
pose
|
|
26236
|
+
pose,
|
|
26237
|
+
...sideways
|
|
26146
26238
|
};
|
|
26239
|
+
const screen = POSE_SIZES[pose];
|
|
26147
26240
|
return {
|
|
26148
26241
|
...base,
|
|
26149
26242
|
...kept,
|
|
26150
26243
|
foldable,
|
|
26151
26244
|
pose,
|
|
26245
|
+
...sideways,
|
|
26152
26246
|
box: {
|
|
26153
26247
|
...placement.box,
|
|
26154
|
-
...
|
|
26248
|
+
...facing === "upright" ? screen : {
|
|
26249
|
+
width: screen.height,
|
|
26250
|
+
height: screen.width
|
|
26251
|
+
}
|
|
26155
26252
|
},
|
|
26156
26253
|
hugWidth: false,
|
|
26157
26254
|
hugHeight: false
|
|
26158
26255
|
};
|
|
26256
|
+
}, fold || turn || name !== void 0 ? pushAlong : void 0);
|
|
26257
|
+
}
|
|
26258
|
+
/**
|
|
26259
|
+
* Shifts each frame on the grown body's rows at or past its old right edge by
|
|
26260
|
+
* the growth, keeping the gap. A shrink pulls none back, since the developer
|
|
26261
|
+
* may have arranged them since, and a bare show or hide never calls this.
|
|
26262
|
+
*/
|
|
26263
|
+
function pushAlong(layout, name, before) {
|
|
26264
|
+
const was = bodyOf(before);
|
|
26265
|
+
const now = bodyOf(layout.placement(name));
|
|
26266
|
+
const edge = was.x + was.width;
|
|
26267
|
+
const growth = now.x + now.width - edge;
|
|
26268
|
+
if (growth <= 0) return;
|
|
26269
|
+
const pushed = layout.names.filter((other) => other !== name && layout.hasEntry(other)).map((other) => ({
|
|
26270
|
+
other,
|
|
26271
|
+
placement: layout.placement(other)
|
|
26272
|
+
})).filter(({ placement }) => {
|
|
26273
|
+
const body = bodyOf(placement);
|
|
26274
|
+
return body.x >= edge && body.y < now.y + now.height && body.y + body.height > now.y;
|
|
26275
|
+
});
|
|
26276
|
+
for (const { other, placement } of pushed) {
|
|
26277
|
+
const { box } = placement;
|
|
26278
|
+
layout.set(other, {
|
|
26279
|
+
...placement,
|
|
26280
|
+
box: {
|
|
26281
|
+
...box,
|
|
26282
|
+
x: box.x + growth
|
|
26283
|
+
}
|
|
26284
|
+
});
|
|
26285
|
+
}
|
|
26286
|
+
}
|
|
26287
|
+
function bodyOf({ box, device, turn }) {
|
|
26288
|
+
return bezelBox(box, device, turn);
|
|
26289
|
+
}
|
|
26290
|
+
/**
|
|
26291
|
+
* A named foldable left as it is while it stays named, and stood upright at
|
|
26292
|
+
* its pose's screen when named off, since no other device reads its turn.
|
|
26293
|
+
*/
|
|
26294
|
+
function unfoldedPlacement(placement, foldable) {
|
|
26295
|
+
if (foldable) return placement;
|
|
26296
|
+
const { turn: held, upright: _upright, ...rest } = placement;
|
|
26297
|
+
if (!held) return rest;
|
|
26298
|
+
const screen = POSE_SIZES[poseOf(placement.pose)];
|
|
26299
|
+
return {
|
|
26300
|
+
...rest,
|
|
26301
|
+
box: {
|
|
26302
|
+
...placement.box,
|
|
26303
|
+
...screen
|
|
26304
|
+
}
|
|
26305
|
+
};
|
|
26306
|
+
}
|
|
26307
|
+
/** The device a frame's width picks, its upright width while turned, shown or not. */
|
|
26308
|
+
function drawnDevice(placement) {
|
|
26309
|
+
return deviceForWidth(placement.upright?.width ?? placement.box.width);
|
|
26310
|
+
}
|
|
26311
|
+
/**
|
|
26312
|
+
* Refuses a quarter turn the board has no drawn answer for: a laptop, a frame
|
|
26313
|
+
* showing no device, and a frame whose extra widths are each an upright
|
|
26314
|
+
* preview of their own. A shown foldable turns in each pose.
|
|
26315
|
+
*/
|
|
26316
|
+
function refuseTurn(placement, frameRef, turn, { foldable, shown }) {
|
|
26317
|
+
const device = drawnDevice(placement);
|
|
26318
|
+
if (!shown || !(foldable || device === "phone" || device === "tablet")) throw new FrameboardError("usage", `${frameRef} draws no phone, tablet, or foldable, so it does not turn. Show the device on a frame 320 to 1023 px wide or a foldable first.`, {
|
|
26319
|
+
ref: frameRef,
|
|
26320
|
+
turn
|
|
26159
26321
|
});
|
|
26322
|
+
if (placement.widths.length > 0) {
|
|
26323
|
+
const widths = placement.widths.map((linked) => linked.width);
|
|
26324
|
+
throw new FrameboardError("usage", `${frameRef} also shows at ${widths.join(", ")} px, each an upright preview, so it does not turn. Clear them with frame resize --no-widths first.`, {
|
|
26325
|
+
ref: frameRef,
|
|
26326
|
+
turn,
|
|
26327
|
+
widths
|
|
26328
|
+
});
|
|
26329
|
+
}
|
|
26330
|
+
}
|
|
26331
|
+
/**
|
|
26332
|
+
* A frame turned to `turn`, keeping its upright size on the first turn. A
|
|
26333
|
+
* fixed or scroll box swaps its sides, and a hugging one, whose height is its
|
|
26334
|
+
* page's, takes the reference height of its upright width wide.
|
|
26335
|
+
*/
|
|
26336
|
+
function turnedPlacement(placement, turn) {
|
|
26337
|
+
if (turn === void 0) return placement;
|
|
26338
|
+
const { turn: held, upright, ...rest } = placement;
|
|
26339
|
+
if (turn === "upright") return upright ? {
|
|
26340
|
+
...rest,
|
|
26341
|
+
box: {
|
|
26342
|
+
...placement.box,
|
|
26343
|
+
...upright
|
|
26344
|
+
}
|
|
26345
|
+
} : rest;
|
|
26346
|
+
if (held) return {
|
|
26347
|
+
...placement,
|
|
26348
|
+
turn
|
|
26349
|
+
};
|
|
26350
|
+
const size = {
|
|
26351
|
+
width: placement.box.width,
|
|
26352
|
+
height: placement.box.height
|
|
26353
|
+
};
|
|
26354
|
+
const hugs = placement.hugHeight && !placement.scroll;
|
|
26355
|
+
return {
|
|
26356
|
+
...rest,
|
|
26357
|
+
turn,
|
|
26358
|
+
upright: size,
|
|
26359
|
+
box: {
|
|
26360
|
+
...placement.box,
|
|
26361
|
+
width: hugs ? referenceHeight(size.width) : size.height,
|
|
26362
|
+
height: size.width
|
|
26363
|
+
}
|
|
26364
|
+
};
|
|
26160
26365
|
}
|
|
26161
26366
|
/**
|
|
26162
26367
|
* Sets or clears a frame's present transition, refusing a name neither built
|
|
@@ -26228,12 +26433,14 @@ async function deleteFrame(root, ref, options) {
|
|
|
26228
26433
|
}, journal);
|
|
26229
26434
|
return { deleted: refOf$1(frame) };
|
|
26230
26435
|
}
|
|
26231
|
-
async function updatePlacement(root, ref, options, change) {
|
|
26436
|
+
async function updatePlacement(root, ref, options, change, settle) {
|
|
26232
26437
|
const frame = await resolveFrameRef(root, ref, options);
|
|
26233
26438
|
const page = pageDir(frame);
|
|
26234
26439
|
await withLayouts([page], async (layouts) => {
|
|
26235
26440
|
const layout = layoutAt(layouts, page);
|
|
26236
|
-
|
|
26441
|
+
const before = layout.placement(frame.name);
|
|
26442
|
+
layout.set(frame.name, change(before, refOf$1(frame)));
|
|
26443
|
+
settle?.(layout, frame.name, before);
|
|
26237
26444
|
}, options.journal);
|
|
26238
26445
|
return frameRecord(root, frame.project, frame.page, frame.name);
|
|
26239
26446
|
}
|
|
@@ -26306,7 +26513,7 @@ var PageLayout = class {
|
|
|
26306
26513
|
* Writes the fixed keys after the entry's own, so unknown keys survive, and a
|
|
26307
26514
|
* flag only once on or already held, so an older entry gains no key.
|
|
26308
26515
|
*/
|
|
26309
|
-
set(name, { box, order, hidden, locked, scroll, widths, showDevice, foldable, pose, keptWidths, island, transition, speakerNotes, kit, hugWidth: hugsWidth, hugHeight: hugsHeight }) {
|
|
26516
|
+
set(name, { box, order, hidden, locked, scroll, widths, showDevice, foldable, pose, keptWidths, island, turn, upright, transition, speakerNotes, kit, hugWidth: hugsWidth, hugHeight: hugsHeight }) {
|
|
26310
26517
|
const hugWidth = hugsWidth && !scroll;
|
|
26311
26518
|
const hugHeight = hugsHeight && !scroll;
|
|
26312
26519
|
const held = this.file.frames[name];
|
|
@@ -26331,6 +26538,14 @@ var PageLayout = class {
|
|
|
26331
26538
|
...foldable ? { foldable } : {},
|
|
26332
26539
|
...foldable && pose && (held?.foldable !== true || poseOf(held.pose) !== pose) ? { pose } : {},
|
|
26333
26540
|
...island ? { island } : {},
|
|
26541
|
+
...turn && upright && !foldable ? {
|
|
26542
|
+
turn,
|
|
26543
|
+
upright: {
|
|
26544
|
+
width: upright.width,
|
|
26545
|
+
height: upright.height
|
|
26546
|
+
}
|
|
26547
|
+
} : {},
|
|
26548
|
+
...turn && foldable ? { turn } : {},
|
|
26334
26549
|
...transition ? { transition: { ...transition } } : {},
|
|
26335
26550
|
...speakerNotes ? { speakerNotes } : {},
|
|
26336
26551
|
...kit ? { kit } : {}
|
|
@@ -26342,6 +26557,11 @@ var PageLayout = class {
|
|
|
26342
26557
|
}
|
|
26343
26558
|
if (!showDevice && held?.showDevice === true) delete entry.showDevice;
|
|
26344
26559
|
if (!island && islandOf(held?.island) === "wide") delete entry.island;
|
|
26560
|
+
if (!turn && turnOf(held?.turn) !== "upright") {
|
|
26561
|
+
delete entry.turn;
|
|
26562
|
+
delete entry.upright;
|
|
26563
|
+
}
|
|
26564
|
+
if (turn && foldable) delete entry.upright;
|
|
26345
26565
|
if (typeof held?.device === "string") delete entry.device;
|
|
26346
26566
|
if (!transition && storedTransitionOf(held?.transition)) delete entry.transition;
|
|
26347
26567
|
if (!speakerNotes && speakerNotesOf(held?.speakerNotes)) delete entry.speakerNotes;
|
|
@@ -31281,6 +31501,149 @@ function cssUrls(css) {
|
|
|
31281
31501
|
});
|
|
31282
31502
|
return urls;
|
|
31283
31503
|
}
|
|
31504
|
+
// src/server/edit/start-tag.ts
|
|
31505
|
+
function isSpace(char) {
|
|
31506
|
+
return char === " " || char === " " || char === "\n" || char === "\f" || char === "\r";
|
|
31507
|
+
}
|
|
31508
|
+
/**
|
|
31509
|
+
* Scans a start tag through the tokenizer states, since parse5 records neither
|
|
31510
|
+
* self-closing nor duplicates, and `<circle id=x/>` is not self-closed.
|
|
31511
|
+
*/
|
|
31512
|
+
function scanStartTag(source, tag) {
|
|
31513
|
+
const names = [];
|
|
31514
|
+
let state = "tagName";
|
|
31515
|
+
let quote = "";
|
|
31516
|
+
let nameStart = 0;
|
|
31517
|
+
let slash;
|
|
31518
|
+
const end = tag.endOffset - 1;
|
|
31519
|
+
for (let at = tag.startOffset + 1; at < end; at += 1) {
|
|
31520
|
+
const char = source[at];
|
|
31521
|
+
slash = void 0;
|
|
31522
|
+
switch (state) {
|
|
31523
|
+
case "tagName":
|
|
31524
|
+
if (isSpace(char)) state = "beforeAttrName";
|
|
31525
|
+
else if (char === "/") {
|
|
31526
|
+
state = "beforeAttrName";
|
|
31527
|
+
slash = at;
|
|
31528
|
+
}
|
|
31529
|
+
break;
|
|
31530
|
+
case "beforeAttrName":
|
|
31531
|
+
if (char === "/") slash = at;
|
|
31532
|
+
else if (!isSpace(char)) {
|
|
31533
|
+
state = "attrName";
|
|
31534
|
+
nameStart = at;
|
|
31535
|
+
}
|
|
31536
|
+
break;
|
|
31537
|
+
case "attrName":
|
|
31538
|
+
if (isSpace(char) || char === "/" || char === "=") {
|
|
31539
|
+
names.push(source.slice(nameStart, at).toLowerCase());
|
|
31540
|
+
if (char === "=") state = "beforeValue";
|
|
31541
|
+
else if (char === "/") {
|
|
31542
|
+
state = "beforeAttrName";
|
|
31543
|
+
slash = at;
|
|
31544
|
+
} else state = "afterAttrName";
|
|
31545
|
+
}
|
|
31546
|
+
break;
|
|
31547
|
+
case "afterAttrName":
|
|
31548
|
+
if (char === "/") {
|
|
31549
|
+
state = "beforeAttrName";
|
|
31550
|
+
slash = at;
|
|
31551
|
+
} else if (char === "=") state = "beforeValue";
|
|
31552
|
+
else if (!isSpace(char)) {
|
|
31553
|
+
state = "attrName";
|
|
31554
|
+
nameStart = at;
|
|
31555
|
+
}
|
|
31556
|
+
break;
|
|
31557
|
+
case "beforeValue":
|
|
31558
|
+
if (char === "\"" || char === "'") {
|
|
31559
|
+
quote = char;
|
|
31560
|
+
state = "quoted";
|
|
31561
|
+
} else if (!isSpace(char)) state = "unquoted";
|
|
31562
|
+
break;
|
|
31563
|
+
case "quoted":
|
|
31564
|
+
if (char === quote) state = "beforeAttrName";
|
|
31565
|
+
break;
|
|
31566
|
+
case "unquoted": if (isSpace(char)) state = "beforeAttrName";
|
|
31567
|
+
}
|
|
31568
|
+
}
|
|
31569
|
+
if (state === "attrName") names.push(source.slice(nameStart, end).toLowerCase());
|
|
31570
|
+
return {
|
|
31571
|
+
slash,
|
|
31572
|
+
names
|
|
31573
|
+
};
|
|
31574
|
+
}
|
|
31575
|
+
// src/server/edit/attribute.ts
|
|
31576
|
+
/** Escapes a value for a double-quoted attribute. */
|
|
31577
|
+
function escapeAttribute$1(value) {
|
|
31578
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
31579
|
+
}
|
|
31580
|
+
function splice(source, start, end, insert) {
|
|
31581
|
+
return source.slice(0, start) + insert + source.slice(end);
|
|
31582
|
+
}
|
|
31583
|
+
/** The value inside one attribute's source span, without its quotes. */
|
|
31584
|
+
function valueSpan(source, span) {
|
|
31585
|
+
const text = source.slice(span.startOffset, span.endOffset);
|
|
31586
|
+
const equals = text.indexOf("=");
|
|
31587
|
+
if (equals === -1) return {
|
|
31588
|
+
start: span.endOffset,
|
|
31589
|
+
end: span.endOffset,
|
|
31590
|
+
quote: void 0,
|
|
31591
|
+
isBare: true
|
|
31592
|
+
};
|
|
31593
|
+
let at = equals + 1;
|
|
31594
|
+
while (/\s/.test(text[at] ?? "")) at += 1;
|
|
31595
|
+
const opener = text[at];
|
|
31596
|
+
const quote = opener === "\"" || opener === "'" ? opener : void 0;
|
|
31597
|
+
return {
|
|
31598
|
+
start: span.startOffset + at + (quote ? 1 : 0),
|
|
31599
|
+
end: span.endOffset - (quote ? 1 : 0),
|
|
31600
|
+
quote,
|
|
31601
|
+
isBare: false
|
|
31602
|
+
};
|
|
31603
|
+
}
|
|
31604
|
+
function attributeSpan(element, name) {
|
|
31605
|
+
return element.sourceCodeLocation?.attrs?.[name];
|
|
31606
|
+
}
|
|
31607
|
+
/** The attribute's value as the file states it, still encoded, or undefined when it is absent. */
|
|
31608
|
+
function rawAttribute(source, element, name) {
|
|
31609
|
+
const span = attributeSpan(element, name);
|
|
31610
|
+
if (!span) return void 0;
|
|
31611
|
+
const value = valueSpan(source, span);
|
|
31612
|
+
return source.slice(value.start, value.end);
|
|
31613
|
+
}
|
|
31614
|
+
/**
|
|
31615
|
+
* Sets one attribute inside its value span, a new one going before the real
|
|
31616
|
+
* self-closing `/`, which only the start-tag scan tells from an unquoted value's.
|
|
31617
|
+
*/
|
|
31618
|
+
function setRawAttribute(source, element, name, raw) {
|
|
31619
|
+
const span = attributeSpan(element, name);
|
|
31620
|
+
if (span) {
|
|
31621
|
+
const value = valueSpan(source, span);
|
|
31622
|
+
if (value.isBare) return splice(source, span.endOffset, span.endOffset, `="${raw}"`);
|
|
31623
|
+
if (value.quote === "'") return splice(source, value.start, value.end, raw.replace(/'/g, "'"));
|
|
31624
|
+
if (value.quote === "\"") return splice(source, value.start, value.end, raw);
|
|
31625
|
+
return splice(source, value.start, value.end, `"${raw.replace(/"/g, """)}"`);
|
|
31626
|
+
}
|
|
31627
|
+
const startTag = element.sourceCodeLocation?.startTag;
|
|
31628
|
+
if (!startTag) return source;
|
|
31629
|
+
const at = scanStartTag(source, startTag).slash ?? startTag.endOffset - 1;
|
|
31630
|
+
return splice(source, at, at, `${/\s/.test(source[at - 1] ?? "") ? "" : " "}${name}="${raw}"${source[at] === "/" ? " " : ""}`);
|
|
31631
|
+
}
|
|
31632
|
+
/**
|
|
31633
|
+
* Removes one attribute and the whitespace run ahead of it. A later duplicate
|
|
31634
|
+
* would come into force once the first is gone, so the first is emptied
|
|
31635
|
+
* instead, and a bare one is left as it is, already empty.
|
|
31636
|
+
*/
|
|
31637
|
+
function removeAttribute(source, element, name) {
|
|
31638
|
+
const span = attributeSpan(element, name);
|
|
31639
|
+
const startTag = element.sourceCodeLocation?.startTag;
|
|
31640
|
+
if (!span || !startTag) return source;
|
|
31641
|
+
const { names } = scanStartTag(source, startTag);
|
|
31642
|
+
if (names.filter((stated) => stated === name).length > 1) return valueSpan(source, span).isBare ? source : setRawAttribute(source, element, name, "");
|
|
31643
|
+
let start = span.startOffset;
|
|
31644
|
+
while (/\s/.test(source[start - 1] ?? "")) start -= 1;
|
|
31645
|
+
return splice(source, start, span.endOffset, "");
|
|
31646
|
+
}
|
|
31284
31647
|
// src/server/board/asset-usage.ts
|
|
31285
31648
|
/**
|
|
31286
31649
|
* A per-project cache of how many frames link each asset, counted from the
|
|
@@ -31361,32 +31724,49 @@ async function framesLinking(root, project, path) {
|
|
|
31361
31724
|
}
|
|
31362
31725
|
/**
|
|
31363
31726
|
* The frame's markup with each load of `from` pointed at `to`, or null when no load in its own file names it.
|
|
31727
|
+
* An element whose load moved takes the new file name while its `data-name` is still the old one, so a name set by hand stays.
|
|
31364
31728
|
* A linked sheet's load, or a URL written through an entity or escape, stays for the link check to report.
|
|
31365
31729
|
*/
|
|
31366
31730
|
function rewriteAssetLinks(source, from, to) {
|
|
31367
31731
|
const framePath = boardPath(source.root, source.path);
|
|
31368
|
-
const
|
|
31732
|
+
const moved = /* @__PURE__ */ new Map();
|
|
31369
31733
|
for (const load of frameLoads(source)) {
|
|
31370
31734
|
if (load.path !== framePath || load.location === null) continue;
|
|
31371
31735
|
if (localTarget(load.url, load.base) !== from) continue;
|
|
31372
31736
|
const { startOffset: start, endOffset: end } = load.location;
|
|
31373
|
-
|
|
31737
|
+
moved.set(`${start}:${end}:${load.url}`, {
|
|
31374
31738
|
start,
|
|
31375
31739
|
end,
|
|
31376
31740
|
url: load.url
|
|
31377
31741
|
});
|
|
31378
31742
|
}
|
|
31743
|
+
const loads = [...moved.values()];
|
|
31744
|
+
const edits = loads.map(({ start, end, url }) => ({
|
|
31745
|
+
start,
|
|
31746
|
+
end,
|
|
31747
|
+
write: (span) => span.replace(urlPattern(url), (_, lead) => `${lead}${renamedUrl(url, basename(to))}`)
|
|
31748
|
+
}));
|
|
31749
|
+
const rewritten = loads.filter(({ start, end, url }) => urlPattern(url).test(source.html.slice(start, end)));
|
|
31750
|
+
edits.push(...nameEdits(source, rewritten, basename(from), basename(to)));
|
|
31379
31751
|
let html = source.html;
|
|
31380
|
-
|
|
31381
|
-
|
|
31382
|
-
|
|
31383
|
-
|
|
31384
|
-
|
|
31385
|
-
|
|
31386
|
-
|
|
31387
|
-
|
|
31388
|
-
|
|
31389
|
-
|
|
31752
|
+
for (const { start, end, write } of edits.sort((a, b) => b.start - a.start)) html = html.slice(0, start) + write(html.slice(start, end)) + html.slice(end);
|
|
31753
|
+
return html === source.html ? null : html;
|
|
31754
|
+
}
|
|
31755
|
+
/** A `data-name` of `oldName` set to `newName` on each element one of `loads` sits in. */
|
|
31756
|
+
function nameEdits(source, loads, oldName, newName) {
|
|
31757
|
+
return source.elements.flatMap((element) => {
|
|
31758
|
+
if (element.attribs["data-name"] !== oldName) return [];
|
|
31759
|
+
const tag = element.sourceCodeLocation;
|
|
31760
|
+
const name = tag?.attrs?.["data-name"];
|
|
31761
|
+
const startTag = tag?.startTag;
|
|
31762
|
+
if (!name || !startTag) return [];
|
|
31763
|
+
if (!loads.some(({ start }) => start >= startTag.startOffset && start < startTag.endOffset)) return [];
|
|
31764
|
+
return [{
|
|
31765
|
+
start: name.startOffset,
|
|
31766
|
+
end: name.endOffset,
|
|
31767
|
+
write: () => `data-name="${escapeAttribute$1(newName)}"`
|
|
31768
|
+
}];
|
|
31769
|
+
});
|
|
31390
31770
|
}
|
|
31391
31771
|
/** The URL as a whole token, so `a.jpg` never matches inside `a.jpg-2.jpg`. */
|
|
31392
31772
|
function urlPattern(url) {
|
|
@@ -31479,7 +31859,11 @@ function isAcceptedUpload(name) {
|
|
|
31479
31859
|
// src/shared/records/sourcing.ts
|
|
31480
31860
|
/** So `house.jpg` carries its license in `house.jpg.license.json` beside it. */
|
|
31481
31861
|
const LICENSE_FILE_SUFFIX = ".license.json";
|
|
31482
|
-
const IMAGE_PROVIDERS = [
|
|
31862
|
+
const IMAGE_PROVIDERS = [
|
|
31863
|
+
"comfyui",
|
|
31864
|
+
"fal",
|
|
31865
|
+
"google"
|
|
31866
|
+
];
|
|
31483
31867
|
/** One image a search found, numbered from 1 in the order the source ranked it. */
|
|
31484
31868
|
const imageResultSchema = object$1({
|
|
31485
31869
|
number: int$1().min(1),
|
|
@@ -31548,8 +31932,7 @@ const modelFindSchema = object$1({
|
|
|
31548
31932
|
}),
|
|
31549
31933
|
results: array$1(modelResultSchema)
|
|
31550
31934
|
});
|
|
31551
|
-
|
|
31552
|
-
const licenseFileSchema = discriminatedUnion("origin", [discriminatedUnion("source", [object$1({
|
|
31935
|
+
const foundLicenseSchema = discriminatedUnion("source", [object$1({
|
|
31553
31936
|
version: literal(1),
|
|
31554
31937
|
origin: literal("found"),
|
|
31555
31938
|
source: literal("openverse"),
|
|
@@ -31584,9 +31967,12 @@ const licenseFileSchema = discriminatedUnion("origin", [discriminatedUnion("sour
|
|
|
31584
31967
|
url: string$1(),
|
|
31585
31968
|
size: _enum$1(MODEL_SIZES),
|
|
31586
31969
|
savedAt: string$1()
|
|
31587
|
-
})])
|
|
31970
|
+
})]);
|
|
31971
|
+
const generatedImageLicenseSchema = object$1({
|
|
31588
31972
|
version: literal(1),
|
|
31589
31973
|
origin: literal("generated"),
|
|
31974
|
+
/** Absent on every image license written so far, which reads as an image. */
|
|
31975
|
+
kind: literal("image").optional(),
|
|
31590
31976
|
provider: _enum$1(IMAGE_PROVIDERS),
|
|
31591
31977
|
model: string$1(),
|
|
31592
31978
|
prompt: string$1(),
|
|
@@ -31594,8 +31980,48 @@ const licenseFileSchema = discriminatedUnion("origin", [discriminatedUnion("sour
|
|
|
31594
31980
|
height: int$1(),
|
|
31595
31981
|
/** The price estimated before the call, in US dollars. */
|
|
31596
31982
|
priceUsd: number(),
|
|
31983
|
+
/** The noise seed a local run drew, so the same image can be made again. */
|
|
31984
|
+
seed: int$1().optional(),
|
|
31985
|
+
/** The workflow file `--workflow` named, absent for the bundled one. */
|
|
31986
|
+
workflow: string$1().optional(),
|
|
31597
31987
|
savedAt: string$1()
|
|
31598
|
-
})
|
|
31988
|
+
});
|
|
31989
|
+
/** The picture a model was made from, so the model keeps the credit the picture carried. */
|
|
31990
|
+
const sourcePictureSchema = object$1({
|
|
31991
|
+
/**
|
|
31992
|
+
* Relative to the project's `assets/` for a project asset, else the file's
|
|
31993
|
+
* name alone, never a path on the machine.
|
|
31994
|
+
*/
|
|
31995
|
+
path: string$1(),
|
|
31996
|
+
inAssets: boolean$1(),
|
|
31997
|
+
/** The picture's own license file's origin and license name, null when it has none. */
|
|
31998
|
+
license: object$1({
|
|
31999
|
+
origin: _enum$1(["found", "generated"]),
|
|
32000
|
+
/** The license a found picture carries, such as `cc0`, null for a generated one. */
|
|
32001
|
+
license: string$1().nullable()
|
|
32002
|
+
}).nullable()
|
|
32003
|
+
});
|
|
32004
|
+
/**
|
|
32005
|
+
* The `<file>.license.json` beside every saved image or model, saying where
|
|
32006
|
+
* it came from. A generated one carries `kind: 'model'` for a model, and no
|
|
32007
|
+
* kind or `kind: 'image'` for an image.
|
|
32008
|
+
*/
|
|
32009
|
+
const licenseFileSchema = discriminatedUnion("origin", [foundLicenseSchema, discriminatedUnion("kind", [generatedImageLicenseSchema, object$1({
|
|
32010
|
+
version: literal(1),
|
|
32011
|
+
origin: literal("generated"),
|
|
32012
|
+
kind: literal("model"),
|
|
32013
|
+
provider: literal("comfyui"),
|
|
32014
|
+
/** The ComfyUI server the model was made on. */
|
|
32015
|
+
server: string$1(),
|
|
32016
|
+
/** The bundled model, or the workflow file's name when `--workflow` named one. */
|
|
32017
|
+
model: string$1(),
|
|
32018
|
+
/** The workflow file `--workflow` named, absent for the bundled one. */
|
|
32019
|
+
workflow: string$1().optional(),
|
|
32020
|
+
picture: sourcePictureSchema,
|
|
32021
|
+
/** The noise seed the run drew, so the same model can be made again. */
|
|
32022
|
+
seed: int$1(),
|
|
32023
|
+
savedAt: string$1()
|
|
32024
|
+
})])]);
|
|
31599
32025
|
/** An image saved into a project's `assets/`, with the license file written beside it. */
|
|
31600
32026
|
const savedImageSchema = object$1({
|
|
31601
32027
|
version: literal(1),
|
|
@@ -31607,6 +32033,18 @@ const savedImageSchema = object$1({
|
|
|
31607
32033
|
});
|
|
31608
32034
|
/** A model saved into a project's `assets/` as one `.glb`, with the license file written beside it. */
|
|
31609
32035
|
const savedModelSchema = savedImageSchema;
|
|
32036
|
+
/** What `model generate` answers, with `saved` null on a dry run. */
|
|
32037
|
+
const modelGenerateSchema = object$1({
|
|
32038
|
+
version: literal(1),
|
|
32039
|
+
provider: literal("comfyui"),
|
|
32040
|
+
/** The ComfyUI server at `FRAMEBOARD_COMFYUI_URL`. */
|
|
32041
|
+
server: string$1(),
|
|
32042
|
+
/** The bundled model, or the workflow file's name when `--workflow` named one. */
|
|
32043
|
+
model: string$1(),
|
|
32044
|
+
picture: sourcePictureSchema,
|
|
32045
|
+
dryRun: boolean$1(),
|
|
32046
|
+
saved: savedModelSchema.nullable()
|
|
32047
|
+
});
|
|
31610
32048
|
/** What `image generate` answers, with `saved` null on a dry run. */
|
|
31611
32049
|
const imageGenerateSchema = object$1({
|
|
31612
32050
|
version: literal(1),
|
|
@@ -31622,8 +32060,6 @@ const imageGenerateSchema = object$1({
|
|
|
31622
32060
|
});
|
|
31623
32061
|
object$1({
|
|
31624
32062
|
version: literal(1),
|
|
31625
|
-
/** Whether the board may generate at all, false while generating from a tab is switched off. */
|
|
31626
|
-
enabled: boolean$1(),
|
|
31627
32063
|
/** The first provider whose key is set, null when none is. */
|
|
31628
32064
|
provider: object$1({
|
|
31629
32065
|
name: _enum$1(IMAGE_PROVIDERS),
|
|
@@ -31637,6 +32073,22 @@ object$1({
|
|
|
31637
32073
|
/** Every provider's key variable, in the order generation tries them. */
|
|
31638
32074
|
keys: array$1(string$1())
|
|
31639
32075
|
});
|
|
32076
|
+
object$1({
|
|
32077
|
+
version: literal(1),
|
|
32078
|
+
/** The ComfyUI server at `FRAMEBOARD_COMFYUI_URL`, or the default address. */
|
|
32079
|
+
url: string$1(),
|
|
32080
|
+
freed: literal(true)
|
|
32081
|
+
});
|
|
32082
|
+
/** A model file a bundled workflow loads, as ComfyUI's `models/<folder>/` should hold it. */
|
|
32083
|
+
const missingModelSchema = object$1({
|
|
32084
|
+
/** The verb whose bundled workflow loads it, `image` for image generate and `model` for model generate. */
|
|
32085
|
+
for: _enum$1(["image", "model"]),
|
|
32086
|
+
folder: string$1(),
|
|
32087
|
+
file: string$1(),
|
|
32088
|
+
bytes: int$1(),
|
|
32089
|
+
/** Where the file downloads from. */
|
|
32090
|
+
url: string$1()
|
|
32091
|
+
});
|
|
31640
32092
|
/** What `image doctor` answers, naming each key as set or unset and never its value. */
|
|
31641
32093
|
const imageDoctorSchema = object$1({
|
|
31642
32094
|
version: literal(1),
|
|
@@ -31648,8 +32100,14 @@ const imageDoctorSchema = object$1({
|
|
|
31648
32100
|
/** The ComfyUI server at `FRAMEBOARD_COMFYUI_URL`, or the default address. */
|
|
31649
32101
|
local: object$1({
|
|
31650
32102
|
url: string$1(),
|
|
31651
|
-
running: boolean$1()
|
|
32103
|
+
running: boolean$1(),
|
|
32104
|
+
/** The ComfyUI version the server reports, null when none answers. */
|
|
32105
|
+
version: string$1().nullable(),
|
|
32106
|
+
/** Each bundled workflow's files the server lacks, image ones first, null when it does not answer. */
|
|
32107
|
+
missing: array$1(missingModelSchema).nullable()
|
|
31652
32108
|
}),
|
|
32109
|
+
/** Commands that would get this machine generating locally, empty when it already can. */
|
|
32110
|
+
setup: array$1(string$1()),
|
|
31653
32111
|
/** Each provider key by its environment variable, true when set and not empty. */
|
|
31654
32112
|
keys: record(string$1(), boolean$1()),
|
|
31655
32113
|
providers: array$1(object$1({
|
|
@@ -32914,149 +33372,6 @@ function clipboardRoutes(root, access, render, clipboard) {
|
|
|
32914
33372
|
});
|
|
32915
33373
|
return app;
|
|
32916
33374
|
}
|
|
32917
|
-
// src/server/edit/start-tag.ts
|
|
32918
|
-
function isSpace(char) {
|
|
32919
|
-
return char === " " || char === " " || char === "\n" || char === "\f" || char === "\r";
|
|
32920
|
-
}
|
|
32921
|
-
/**
|
|
32922
|
-
* Scans a start tag through the tokenizer states, since parse5 records neither
|
|
32923
|
-
* self-closing nor duplicates, and `<circle id=x/>` is not self-closed.
|
|
32924
|
-
*/
|
|
32925
|
-
function scanStartTag(source, tag) {
|
|
32926
|
-
const names = [];
|
|
32927
|
-
let state = "tagName";
|
|
32928
|
-
let quote = "";
|
|
32929
|
-
let nameStart = 0;
|
|
32930
|
-
let slash;
|
|
32931
|
-
const end = tag.endOffset - 1;
|
|
32932
|
-
for (let at = tag.startOffset + 1; at < end; at += 1) {
|
|
32933
|
-
const char = source[at];
|
|
32934
|
-
slash = void 0;
|
|
32935
|
-
switch (state) {
|
|
32936
|
-
case "tagName":
|
|
32937
|
-
if (isSpace(char)) state = "beforeAttrName";
|
|
32938
|
-
else if (char === "/") {
|
|
32939
|
-
state = "beforeAttrName";
|
|
32940
|
-
slash = at;
|
|
32941
|
-
}
|
|
32942
|
-
break;
|
|
32943
|
-
case "beforeAttrName":
|
|
32944
|
-
if (char === "/") slash = at;
|
|
32945
|
-
else if (!isSpace(char)) {
|
|
32946
|
-
state = "attrName";
|
|
32947
|
-
nameStart = at;
|
|
32948
|
-
}
|
|
32949
|
-
break;
|
|
32950
|
-
case "attrName":
|
|
32951
|
-
if (isSpace(char) || char === "/" || char === "=") {
|
|
32952
|
-
names.push(source.slice(nameStart, at).toLowerCase());
|
|
32953
|
-
if (char === "=") state = "beforeValue";
|
|
32954
|
-
else if (char === "/") {
|
|
32955
|
-
state = "beforeAttrName";
|
|
32956
|
-
slash = at;
|
|
32957
|
-
} else state = "afterAttrName";
|
|
32958
|
-
}
|
|
32959
|
-
break;
|
|
32960
|
-
case "afterAttrName":
|
|
32961
|
-
if (char === "/") {
|
|
32962
|
-
state = "beforeAttrName";
|
|
32963
|
-
slash = at;
|
|
32964
|
-
} else if (char === "=") state = "beforeValue";
|
|
32965
|
-
else if (!isSpace(char)) {
|
|
32966
|
-
state = "attrName";
|
|
32967
|
-
nameStart = at;
|
|
32968
|
-
}
|
|
32969
|
-
break;
|
|
32970
|
-
case "beforeValue":
|
|
32971
|
-
if (char === "\"" || char === "'") {
|
|
32972
|
-
quote = char;
|
|
32973
|
-
state = "quoted";
|
|
32974
|
-
} else if (!isSpace(char)) state = "unquoted";
|
|
32975
|
-
break;
|
|
32976
|
-
case "quoted":
|
|
32977
|
-
if (char === quote) state = "beforeAttrName";
|
|
32978
|
-
break;
|
|
32979
|
-
case "unquoted": if (isSpace(char)) state = "beforeAttrName";
|
|
32980
|
-
}
|
|
32981
|
-
}
|
|
32982
|
-
if (state === "attrName") names.push(source.slice(nameStart, end).toLowerCase());
|
|
32983
|
-
return {
|
|
32984
|
-
slash,
|
|
32985
|
-
names
|
|
32986
|
-
};
|
|
32987
|
-
}
|
|
32988
|
-
// src/server/edit/attribute.ts
|
|
32989
|
-
/** Escapes a value for a double-quoted attribute. */
|
|
32990
|
-
function escapeAttribute$1(value) {
|
|
32991
|
-
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
32992
|
-
}
|
|
32993
|
-
function splice(source, start, end, insert) {
|
|
32994
|
-
return source.slice(0, start) + insert + source.slice(end);
|
|
32995
|
-
}
|
|
32996
|
-
/** The value inside one attribute's source span, without its quotes. */
|
|
32997
|
-
function valueSpan(source, span) {
|
|
32998
|
-
const text = source.slice(span.startOffset, span.endOffset);
|
|
32999
|
-
const equals = text.indexOf("=");
|
|
33000
|
-
if (equals === -1) return {
|
|
33001
|
-
start: span.endOffset,
|
|
33002
|
-
end: span.endOffset,
|
|
33003
|
-
quote: void 0,
|
|
33004
|
-
isBare: true
|
|
33005
|
-
};
|
|
33006
|
-
let at = equals + 1;
|
|
33007
|
-
while (/\s/.test(text[at] ?? "")) at += 1;
|
|
33008
|
-
const opener = text[at];
|
|
33009
|
-
const quote = opener === "\"" || opener === "'" ? opener : void 0;
|
|
33010
|
-
return {
|
|
33011
|
-
start: span.startOffset + at + (quote ? 1 : 0),
|
|
33012
|
-
end: span.endOffset - (quote ? 1 : 0),
|
|
33013
|
-
quote,
|
|
33014
|
-
isBare: false
|
|
33015
|
-
};
|
|
33016
|
-
}
|
|
33017
|
-
function attributeSpan(element, name) {
|
|
33018
|
-
return element.sourceCodeLocation?.attrs?.[name];
|
|
33019
|
-
}
|
|
33020
|
-
/** The attribute's value as the file states it, still encoded, or undefined when it is absent. */
|
|
33021
|
-
function rawAttribute(source, element, name) {
|
|
33022
|
-
const span = attributeSpan(element, name);
|
|
33023
|
-
if (!span) return void 0;
|
|
33024
|
-
const value = valueSpan(source, span);
|
|
33025
|
-
return source.slice(value.start, value.end);
|
|
33026
|
-
}
|
|
33027
|
-
/**
|
|
33028
|
-
* Sets one attribute inside its value span, a new one going before the real
|
|
33029
|
-
* self-closing `/`, which only the start-tag scan tells from an unquoted value's.
|
|
33030
|
-
*/
|
|
33031
|
-
function setRawAttribute(source, element, name, raw) {
|
|
33032
|
-
const span = attributeSpan(element, name);
|
|
33033
|
-
if (span) {
|
|
33034
|
-
const value = valueSpan(source, span);
|
|
33035
|
-
if (value.isBare) return splice(source, span.endOffset, span.endOffset, `="${raw}"`);
|
|
33036
|
-
if (value.quote === "'") return splice(source, value.start, value.end, raw.replace(/'/g, "'"));
|
|
33037
|
-
if (value.quote === "\"") return splice(source, value.start, value.end, raw);
|
|
33038
|
-
return splice(source, value.start, value.end, `"${raw.replace(/"/g, """)}"`);
|
|
33039
|
-
}
|
|
33040
|
-
const startTag = element.sourceCodeLocation?.startTag;
|
|
33041
|
-
if (!startTag) return source;
|
|
33042
|
-
const at = scanStartTag(source, startTag).slash ?? startTag.endOffset - 1;
|
|
33043
|
-
return splice(source, at, at, `${/\s/.test(source[at - 1] ?? "") ? "" : " "}${name}="${raw}"${source[at] === "/" ? " " : ""}`);
|
|
33044
|
-
}
|
|
33045
|
-
/**
|
|
33046
|
-
* Removes one attribute and the whitespace run ahead of it. A later duplicate
|
|
33047
|
-
* would come into force once the first is gone, so the first is emptied
|
|
33048
|
-
* instead, and a bare one is left as it is, already empty.
|
|
33049
|
-
*/
|
|
33050
|
-
function removeAttribute(source, element, name) {
|
|
33051
|
-
const span = attributeSpan(element, name);
|
|
33052
|
-
const startTag = element.sourceCodeLocation?.startTag;
|
|
33053
|
-
if (!span || !startTag) return source;
|
|
33054
|
-
const { names } = scanStartTag(source, startTag);
|
|
33055
|
-
if (names.filter((stated) => stated === name).length > 1) return valueSpan(source, span).isBare ? source : setRawAttribute(source, element, name, "");
|
|
33056
|
-
let start = span.startOffset;
|
|
33057
|
-
while (/\s/.test(source[start - 1] ?? "")) start -= 1;
|
|
33058
|
-
return splice(source, start, span.endOffset, "");
|
|
33059
|
-
}
|
|
33060
33375
|
// src/server/edit/element-span.ts
|
|
33061
33376
|
const OTHER$1 = {
|
|
33062
33377
|
before: "after",
|
|
@@ -40813,15 +41128,16 @@ function taken(page, holder) {
|
|
|
40813
41128
|
});
|
|
40814
41129
|
}
|
|
40815
41130
|
// src/server/board/projects.ts
|
|
40816
|
-
/** A new project holding one empty page. */
|
|
40817
|
-
async function addProject(root, name, now = /* @__PURE__ */ new Date(), { journal } = {}) {
|
|
41131
|
+
/** A new project holding one empty page, filed under `group` when one is given. */
|
|
41132
|
+
async function addProject(root, name, now = /* @__PURE__ */ new Date(), { journal, group } = {}) {
|
|
40818
41133
|
assertValidName("project", name);
|
|
40819
41134
|
await assertFree$1(root, name);
|
|
40820
41135
|
await mkdir(join(root, name, START_PAGE), { recursive: true });
|
|
40821
41136
|
await writeRecord(join(root, name, PROJECT_FILE), {
|
|
40822
41137
|
version: 1,
|
|
40823
41138
|
pages: [START_PAGE],
|
|
40824
|
-
createdAt: now.toISOString()
|
|
41139
|
+
createdAt: now.toISOString(),
|
|
41140
|
+
...group?.trim() ? { group: group.trim() } : {}
|
|
40825
41141
|
});
|
|
40826
41142
|
await journal?.created(join(root, name));
|
|
40827
41143
|
return scanProject(root, name);
|
|
@@ -41544,6 +41860,12 @@ var StepJournal = class {
|
|
|
41544
41860
|
}
|
|
41545
41861
|
entry(page, frame, before, after) {
|
|
41546
41862
|
const layout = join(page, LAYOUT_FILE);
|
|
41863
|
+
const last = this.changes.findLastIndex((change) => change.kind === "entry" && change.layout === layout && change.frame === frame);
|
|
41864
|
+
const held = this.changes[last];
|
|
41865
|
+
if (held?.kind === "entry" && this.changes.slice(last + 1).every((change) => change.kind === "entry")) {
|
|
41866
|
+
held.after = after;
|
|
41867
|
+
return;
|
|
41868
|
+
}
|
|
41547
41869
|
this.changes.push({
|
|
41548
41870
|
kind: "entry",
|
|
41549
41871
|
layout,
|
|
@@ -43451,8 +43773,9 @@ async function savedNames(kits) {
|
|
|
43451
43773
|
// src/server/routes/kits.ts
|
|
43452
43774
|
const name$1 = string$1().min(1).max(256);
|
|
43453
43775
|
/**
|
|
43454
|
-
*
|
|
43455
|
-
*
|
|
43776
|
+
* The policy on every kit page and SVG, running the theme script alone by
|
|
43777
|
+
* hash, since a kit file runs on the board's origin, where a frame could embed
|
|
43778
|
+
* one to write as the board, and a sandbox would draw a sample light.
|
|
43456
43779
|
*/
|
|
43457
43780
|
const PREVIEW_POLICY = `script-src 'sha256-${createHash("sha256").update(THEME_SCRIPT).digest("base64")}'`;
|
|
43458
43781
|
const installSchema = object$1({
|
|
@@ -43543,16 +43866,16 @@ function kitRoutes(root, access, history, { tokens, shipped = shippedKitsDir() }
|
|
|
43543
43866
|
const type = file && CONTENT_TYPES$1[extname(file).toLowerCase()];
|
|
43544
43867
|
if (!file || !type) return c.notFound();
|
|
43545
43868
|
const bytes = new Uint8Array(await readFile(file));
|
|
43546
|
-
const
|
|
43547
|
-
const body = isSample ? injectHead(bytes, frameHead([
|
|
43869
|
+
const body = rest.length === 2 && rest[0] === "kit" && extname(file).toLowerCase() === ".html" ? injectHead(bytes, frameHead([
|
|
43548
43870
|
...FACES.map(faceSheetUrl),
|
|
43549
43871
|
`${KITS_URL}/${encodeURIComponent(kitName)}/${TOKEN_FILE}`,
|
|
43550
43872
|
`${KITS_URL}/${encodeURIComponent(kitName)}/${KIT_SHEET}`
|
|
43551
43873
|
], contentHash(bytes))) : bytes;
|
|
43874
|
+
const document = type.startsWith("text/html") || type === "image/svg+xml";
|
|
43552
43875
|
return c.body(body, 200, {
|
|
43553
43876
|
"Content-Type": type,
|
|
43554
43877
|
"Cache-Control": "no-store",
|
|
43555
|
-
...
|
|
43878
|
+
...document ? { "Content-Security-Policy": PREVIEW_POLICY } : {}
|
|
43556
43879
|
});
|
|
43557
43880
|
});
|
|
43558
43881
|
app.onError(answerRefusal);
|
|
@@ -43585,14 +43908,16 @@ const CONTENT_TYPES = {
|
|
|
43585
43908
|
*/
|
|
43586
43909
|
function servedFrames(root, { facesDir, tokens, version, base }) {
|
|
43587
43910
|
const look = { sheets: (project) => tokenSheetPaths(root, project, tokens) };
|
|
43588
|
-
const
|
|
43589
|
-
routes.route("/", lookRoutes({
|
|
43911
|
+
const looks = lookRoutes({
|
|
43590
43912
|
facesDir,
|
|
43591
43913
|
boardSheet: () => boardSheetPath(root, tokens)
|
|
43592
|
-
})
|
|
43914
|
+
});
|
|
43915
|
+
const routes = new Hono();
|
|
43916
|
+
routes.route("/", looks);
|
|
43593
43917
|
routes.route("/", frameRoutes(root, look, version, base));
|
|
43594
43918
|
return {
|
|
43595
43919
|
look,
|
|
43920
|
+
lookRoutes: looks,
|
|
43596
43921
|
routes
|
|
43597
43922
|
};
|
|
43598
43923
|
}
|
|
@@ -44260,7 +44585,7 @@ function imageExtension(mediaType, url) {
|
|
|
44260
44585
|
* failed request, a body past `limit`, or a file that is no image.
|
|
44261
44586
|
*/
|
|
44262
44587
|
async function downloadImage(url, send, limit = DOWNLOAD_LIMIT) {
|
|
44263
|
-
const { bytes, mediaType, status } = await download(url, send, limit);
|
|
44588
|
+
const { bytes, mediaType, status } = await download$1(url, send, limit);
|
|
44264
44589
|
const extension = imageExtension(mediaType, url);
|
|
44265
44590
|
if (extension === null) throw new FrameboardError("source-failed", "The download is not an image a frame shows.", {
|
|
44266
44591
|
url,
|
|
@@ -44276,7 +44601,7 @@ async function downloadImage(url, send, limit = DOWNLOAD_LIMIT) {
|
|
|
44276
44601
|
* Refuses `source-failed` on a failed request or a body past `limit`, with
|
|
44277
44602
|
* the URL and the status in the details.
|
|
44278
44603
|
*/
|
|
44279
|
-
async function download(url, send, limit = DOWNLOAD_LIMIT) {
|
|
44604
|
+
async function download$1(url, send, limit = DOWNLOAD_LIMIT) {
|
|
44280
44605
|
const failed = (message, status) => new FrameboardError("source-failed", message, {
|
|
44281
44606
|
url,
|
|
44282
44607
|
status
|
|
@@ -44376,6 +44701,819 @@ async function saveWithLicense(project, name, bytes, license) {
|
|
|
44376
44701
|
license
|
|
44377
44702
|
};
|
|
44378
44703
|
}
|
|
44704
|
+
const realClock = {
|
|
44705
|
+
now: () => Date.now(),
|
|
44706
|
+
wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
44707
|
+
};
|
|
44708
|
+
/**
|
|
44709
|
+
* A route under the server's address, keeping any path the address carries,
|
|
44710
|
+
* so `http://host/comfy/` reaches `http://host/comfy/prompt`.
|
|
44711
|
+
*/
|
|
44712
|
+
function routeOf(base, route) {
|
|
44713
|
+
return `${base.replace(/\/+$/, "")}/${route}`;
|
|
44714
|
+
}
|
|
44715
|
+
/**
|
|
44716
|
+
* Queues the workflow, waits for it to finish, and reads its first saved
|
|
44717
|
+
* image. Refuses `provider-failed` naming the node ComfyUI refused or failed
|
|
44718
|
+
* in, and on a prompt still unfinished at the clock's timeout.
|
|
44719
|
+
*/
|
|
44720
|
+
async function runWorkflow(base, workflow, send, clock = realClock) {
|
|
44721
|
+
return readImage(base, firstSavedImage(await runPrompt(base, workflow, send, clock)), send);
|
|
44722
|
+
}
|
|
44723
|
+
/**
|
|
44724
|
+
* Queues the workflow, waits for it to finish, and reads the first GLB a save
|
|
44725
|
+
* node wrote, ignoring any later one. Refuses `provider-failed` as
|
|
44726
|
+
* `runWorkflow` does, and when the run saved no GLB.
|
|
44727
|
+
*/
|
|
44728
|
+
async function runModelWorkflow(base, workflow, send, clock = realClock) {
|
|
44729
|
+
const file = firstSavedModel(await runPrompt(base, workflow, send, clock));
|
|
44730
|
+
const answer = await call(send, viewUrl(base, file));
|
|
44731
|
+
if (!answer.ok) throw failed(answer.status, `could not serve ${file.filename}`);
|
|
44732
|
+
return new Uint8Array(await answer.arrayBuffer());
|
|
44733
|
+
}
|
|
44734
|
+
/**
|
|
44735
|
+
* Hands a picture to the server through its own upload, answering the name a
|
|
44736
|
+
* `LoadImage` node reads it by. The server may store it under another name,
|
|
44737
|
+
* so a run takes the answered name rather than the one sent.
|
|
44738
|
+
*/
|
|
44739
|
+
async function uploadImage(base, upload, send) {
|
|
44740
|
+
const form = new FormData();
|
|
44741
|
+
form.append("image", new Blob([upload.bytes.slice()]), upload.name);
|
|
44742
|
+
const answer = await call(send, routeOf(base, "upload/image"), {
|
|
44743
|
+
method: "POST",
|
|
44744
|
+
body: form
|
|
44745
|
+
});
|
|
44746
|
+
if (!answer.ok) throw failed(answer.status, `refused the upload of ${upload.name}`);
|
|
44747
|
+
const body = await answer.json().catch(() => null);
|
|
44748
|
+
const name = field(body, "name");
|
|
44749
|
+
if (typeof name !== "string" || name === "") throw failed(answer.status, "took the upload but answered no name");
|
|
44750
|
+
const subfolder = field(body, "subfolder");
|
|
44751
|
+
return typeof subfolder === "string" && subfolder !== "" ? `${subfolder}/${name}` : name;
|
|
44752
|
+
}
|
|
44753
|
+
/** Queues the workflow and waits for it to finish, answering the outputs its history records. */
|
|
44754
|
+
async function runPrompt(base, workflow, send, clock) {
|
|
44755
|
+
const queued = await call(send, routeOf(base, "prompt"), {
|
|
44756
|
+
method: "POST",
|
|
44757
|
+
headers: { "Content-Type": "application/json" },
|
|
44758
|
+
body: JSON.stringify({ prompt: workflow })
|
|
44759
|
+
});
|
|
44760
|
+
const body = await queued.json().catch(() => null);
|
|
44761
|
+
if (!queued.ok) throw refused$1(queued.status, body);
|
|
44762
|
+
const id = field(body, "prompt_id");
|
|
44763
|
+
if (typeof id !== "string") throw failed(queued.status, "queued the prompt but answered no prompt_id");
|
|
44764
|
+
const timeoutMs = clock.timeoutMs ?? 6e5;
|
|
44765
|
+
const deadline = clock.now() + timeoutMs;
|
|
44766
|
+
for (;;) {
|
|
44767
|
+
const entry = field(await (await call(send, routeOf(base, `history/${id}`))).json().catch(() => null), id);
|
|
44768
|
+
const status = field(entry, "status");
|
|
44769
|
+
if (field(status, "status_str") === "error") throw runFailed(status);
|
|
44770
|
+
if (field(status, "completed") === true) return field(entry, "outputs");
|
|
44771
|
+
if (clock.now() >= deadline) throw failed(null, `prompt ${id} did not finish in ${timeoutMs / 1e3} s, so the queue looks stalled`);
|
|
44772
|
+
await clock.wait(500);
|
|
44773
|
+
}
|
|
44774
|
+
}
|
|
44775
|
+
/** Asks the server to unload every model and free its memory, which the next run loads again. */
|
|
44776
|
+
async function freeMemory(base, send) {
|
|
44777
|
+
const answer = await call(send, routeOf(base, "free"), {
|
|
44778
|
+
method: "POST",
|
|
44779
|
+
headers: { "Content-Type": "application/json" },
|
|
44780
|
+
body: JSON.stringify({
|
|
44781
|
+
unload_models: true,
|
|
44782
|
+
free_memory: true
|
|
44783
|
+
})
|
|
44784
|
+
});
|
|
44785
|
+
if (!answer.ok) throw failed(answer.status, "refused to free its memory");
|
|
44786
|
+
}
|
|
44787
|
+
async function call(send, url, init) {
|
|
44788
|
+
try {
|
|
44789
|
+
return await send(url, init);
|
|
44790
|
+
} catch (error) {
|
|
44791
|
+
throw failed(null, `nothing answered at ${url}: ${String(error)}`);
|
|
44792
|
+
}
|
|
44793
|
+
}
|
|
44794
|
+
/** The first image a save node wrote, skipping the temporary ones a preview node shows. */
|
|
44795
|
+
function firstSavedImage(outputs) {
|
|
44796
|
+
const nodes = typeof outputs === "object" && outputs !== null ? Object.values(outputs) : [];
|
|
44797
|
+
for (const node of nodes) {
|
|
44798
|
+
const images = field(node, "images");
|
|
44799
|
+
for (const image of Array.isArray(images) ? images : []) {
|
|
44800
|
+
const filename = field(image, "filename");
|
|
44801
|
+
if (typeof filename === "string" && field(image, "type") === "output") {
|
|
44802
|
+
const subfolder = field(image, "subfolder");
|
|
44803
|
+
return {
|
|
44804
|
+
filename,
|
|
44805
|
+
subfolder: typeof subfolder === "string" ? subfolder : "",
|
|
44806
|
+
type: "output"
|
|
44807
|
+
};
|
|
44808
|
+
}
|
|
44809
|
+
}
|
|
44810
|
+
}
|
|
44811
|
+
throw failed(200, "the run finished and saved no image");
|
|
44812
|
+
}
|
|
44813
|
+
/** The first GLB a save node wrote, which ComfyUI lists under a node's `3d` output. */
|
|
44814
|
+
function firstSavedModel(outputs) {
|
|
44815
|
+
const nodes = typeof outputs === "object" && outputs !== null ? Object.values(outputs) : [];
|
|
44816
|
+
for (const node of nodes) {
|
|
44817
|
+
const files = field(node, "3d");
|
|
44818
|
+
for (const file of Array.isArray(files) ? files : []) {
|
|
44819
|
+
const filename = field(file, "filename");
|
|
44820
|
+
if (typeof filename === "string" && filename.toLowerCase().endsWith(".glb") && field(file, "type") === "output") {
|
|
44821
|
+
const subfolder = field(file, "subfolder");
|
|
44822
|
+
return {
|
|
44823
|
+
filename,
|
|
44824
|
+
subfolder: typeof subfolder === "string" ? subfolder : "",
|
|
44825
|
+
type: "output"
|
|
44826
|
+
};
|
|
44827
|
+
}
|
|
44828
|
+
}
|
|
44829
|
+
}
|
|
44830
|
+
throw failed(200, "the run finished and saved no GLB");
|
|
44831
|
+
}
|
|
44832
|
+
/** Where `/view` serves a saved file, which it answers as it is unless a `channel` asks for one. */
|
|
44833
|
+
function viewUrl(base, file) {
|
|
44834
|
+
const query = new URLSearchParams({
|
|
44835
|
+
filename: file.filename,
|
|
44836
|
+
subfolder: file.subfolder,
|
|
44837
|
+
type: file.type
|
|
44838
|
+
});
|
|
44839
|
+
return `${routeOf(base, "view")}?${query}`;
|
|
44840
|
+
}
|
|
44841
|
+
async function readImage(base, file, send) {
|
|
44842
|
+
const answer = await call(send, viewUrl(base, file));
|
|
44843
|
+
if (!answer.ok) throw failed(answer.status, `could not serve ${file.filename}`);
|
|
44844
|
+
const extension = imageExtension(answer.headers.get("content-type"), null) ?? imageExtension(null, new URL(file.filename, "file:///").href);
|
|
44845
|
+
if (extension === null) throw failed(answer.status, `${file.filename} is not an image`);
|
|
44846
|
+
return {
|
|
44847
|
+
bytes: new Uint8Array(await answer.arrayBuffer()),
|
|
44848
|
+
extension
|
|
44849
|
+
};
|
|
44850
|
+
}
|
|
44851
|
+
/** The refusal `/prompt` answers, naming the first node it found at fault and why. */
|
|
44852
|
+
function refused$1(status, body) {
|
|
44853
|
+
const nodeErrors = field(body, "node_errors");
|
|
44854
|
+
const [node, fault] = typeof nodeErrors === "object" && nodeErrors !== null ? Object.entries(nodeErrors)[0] ?? [] : [];
|
|
44855
|
+
const message = String(field(field(body, "error"), "message") ?? "refused");
|
|
44856
|
+
if (node === void 0) return failed(status, message);
|
|
44857
|
+
const errors = field(fault, "errors");
|
|
44858
|
+
const first = Array.isArray(errors) ? errors[0] : void 0;
|
|
44859
|
+
const reason = [field(first, "message"), field(first, "details")].filter((each) => typeof each === "string" && each !== "").join(", ");
|
|
44860
|
+
return failed(status, `node ${node} ${String(field(fault, "class_type") ?? "")}: ${reason || message}`, node);
|
|
44861
|
+
}
|
|
44862
|
+
/** The failure a finished run's history records, naming the node it failed in. */
|
|
44863
|
+
function runFailed(status) {
|
|
44864
|
+
const messages = field(status, "messages");
|
|
44865
|
+
const detail = (Array.isArray(messages) ? messages : []).find((each) => Array.isArray(each) && each[0] === "execution_error")?.[1];
|
|
44866
|
+
const node = field(detail, "node_id");
|
|
44867
|
+
return failed(200, `node ${String(node ?? "?")} ${String(field(detail, "node_type") ?? "")}: ${String(field(detail, "exception_message") ?? "the run failed")}`, typeof node === "string" ? node : void 0);
|
|
44868
|
+
}
|
|
44869
|
+
function failed(status, reason, node) {
|
|
44870
|
+
return new FrameboardError("provider-failed", `comfyui ${status === null ? "did not answer" : `answered ${status}`}: ${reason.slice(0, 300)}`, node === void 0 ? {
|
|
44871
|
+
provider: "comfyui",
|
|
44872
|
+
status
|
|
44873
|
+
} : {
|
|
44874
|
+
provider: "comfyui",
|
|
44875
|
+
status,
|
|
44876
|
+
node
|
|
44877
|
+
});
|
|
44878
|
+
}
|
|
44879
|
+
function field(value, key) {
|
|
44880
|
+
return typeof value === "object" && value !== null && key in value ? value[key] : void 0;
|
|
44881
|
+
}
|
|
44882
|
+
// src/server/sourcing/comfyui/flux2-klein.json
|
|
44883
|
+
var flux2_klein_default = {
|
|
44884
|
+
"70": {
|
|
44885
|
+
"class_type": "UNETLoader",
|
|
44886
|
+
"inputs": {
|
|
44887
|
+
"unet_name": "flux-2-klein-4b-fp8.safetensors",
|
|
44888
|
+
"weight_dtype": "default"
|
|
44889
|
+
}
|
|
44890
|
+
},
|
|
44891
|
+
"71": {
|
|
44892
|
+
"class_type": "CLIPLoader",
|
|
44893
|
+
"inputs": {
|
|
44894
|
+
"clip_name": "qwen_3_4b.safetensors",
|
|
44895
|
+
"type": "flux2",
|
|
44896
|
+
"device": "default"
|
|
44897
|
+
}
|
|
44898
|
+
},
|
|
44899
|
+
"72": {
|
|
44900
|
+
"class_type": "VAELoader",
|
|
44901
|
+
"inputs": { "vae_name": "flux2-vae.safetensors" }
|
|
44902
|
+
},
|
|
44903
|
+
"74": {
|
|
44904
|
+
"class_type": "CLIPTextEncode",
|
|
44905
|
+
"inputs": {
|
|
44906
|
+
"text": "{{prompt}}",
|
|
44907
|
+
"clip": ["71", 0]
|
|
44908
|
+
}
|
|
44909
|
+
},
|
|
44910
|
+
"76": {
|
|
44911
|
+
"class_type": "ConditioningZeroOut",
|
|
44912
|
+
"inputs": { "conditioning": ["74", 0] }
|
|
44913
|
+
},
|
|
44914
|
+
"63": {
|
|
44915
|
+
"class_type": "CFGGuider",
|
|
44916
|
+
"inputs": {
|
|
44917
|
+
"model": ["70", 0],
|
|
44918
|
+
"positive": ["74", 0],
|
|
44919
|
+
"negative": ["76", 0],
|
|
44920
|
+
"cfg": 1
|
|
44921
|
+
}
|
|
44922
|
+
},
|
|
44923
|
+
"61": {
|
|
44924
|
+
"class_type": "KSamplerSelect",
|
|
44925
|
+
"inputs": { "sampler_name": "euler" }
|
|
44926
|
+
},
|
|
44927
|
+
"62": {
|
|
44928
|
+
"class_type": "Flux2Scheduler",
|
|
44929
|
+
"inputs": {
|
|
44930
|
+
"steps": 4,
|
|
44931
|
+
"width": "{{width}}",
|
|
44932
|
+
"height": "{{height}}"
|
|
44933
|
+
}
|
|
44934
|
+
},
|
|
44935
|
+
"73": {
|
|
44936
|
+
"class_type": "RandomNoise",
|
|
44937
|
+
"inputs": { "noise_seed": "{{seed}}" }
|
|
44938
|
+
},
|
|
44939
|
+
"66": {
|
|
44940
|
+
"class_type": "EmptyFlux2LatentImage",
|
|
44941
|
+
"inputs": {
|
|
44942
|
+
"width": "{{width}}",
|
|
44943
|
+
"height": "{{height}}",
|
|
44944
|
+
"batch_size": 1
|
|
44945
|
+
}
|
|
44946
|
+
},
|
|
44947
|
+
"64": {
|
|
44948
|
+
"class_type": "SamplerCustomAdvanced",
|
|
44949
|
+
"inputs": {
|
|
44950
|
+
"noise": ["73", 0],
|
|
44951
|
+
"guider": ["63", 0],
|
|
44952
|
+
"sampler": ["61", 0],
|
|
44953
|
+
"sigmas": ["62", 0],
|
|
44954
|
+
"latent_image": ["66", 0]
|
|
44955
|
+
}
|
|
44956
|
+
},
|
|
44957
|
+
"65": {
|
|
44958
|
+
"class_type": "VAEDecode",
|
|
44959
|
+
"inputs": {
|
|
44960
|
+
"samples": ["64", 0],
|
|
44961
|
+
"vae": ["72", 0]
|
|
44962
|
+
}
|
|
44963
|
+
},
|
|
44964
|
+
"9": {
|
|
44965
|
+
"class_type": "SaveImage",
|
|
44966
|
+
"inputs": {
|
|
44967
|
+
"images": ["65", 0],
|
|
44968
|
+
"filename_prefix": "frameboard"
|
|
44969
|
+
}
|
|
44970
|
+
}
|
|
44971
|
+
};
|
|
44972
|
+
// src/server/sourcing/comfyui/pixal3d.json
|
|
44973
|
+
var pixal3d_default = {
|
|
44974
|
+
"3": {
|
|
44975
|
+
"class_type": "KSampler",
|
|
44976
|
+
"inputs": {
|
|
44977
|
+
"seed": "{{seed}}",
|
|
44978
|
+
"steps": 12,
|
|
44979
|
+
"cfg": 7.5,
|
|
44980
|
+
"sampler_name": "euler",
|
|
44981
|
+
"scheduler": "normal",
|
|
44982
|
+
"denoise": 1,
|
|
44983
|
+
"model": ["108", 0],
|
|
44984
|
+
"positive": ["314", 0],
|
|
44985
|
+
"negative": ["315", 0],
|
|
44986
|
+
"latent_image": ["87", 0]
|
|
44987
|
+
}
|
|
44988
|
+
},
|
|
44989
|
+
"4": {
|
|
44990
|
+
"class_type": "VoxelToMesh",
|
|
44991
|
+
"inputs": {
|
|
44992
|
+
"algorithm": "basic",
|
|
44993
|
+
"threshold": .6,
|
|
44994
|
+
"voxel": ["119", 0]
|
|
44995
|
+
}
|
|
44996
|
+
},
|
|
44997
|
+
"12": {
|
|
44998
|
+
"class_type": "KSampler",
|
|
44999
|
+
"inputs": {
|
|
45000
|
+
"seed": "{{seed}}",
|
|
45001
|
+
"steps": 12,
|
|
45002
|
+
"cfg": 1,
|
|
45003
|
+
"sampler_name": "euler",
|
|
45004
|
+
"scheduler": "normal",
|
|
45005
|
+
"denoise": 1,
|
|
45006
|
+
"model": ["318", 0],
|
|
45007
|
+
"positive": ["98", 0],
|
|
45008
|
+
"negative": ["98", 1],
|
|
45009
|
+
"latent_image": ["98", 2]
|
|
45010
|
+
}
|
|
45011
|
+
},
|
|
45012
|
+
"15": {
|
|
45013
|
+
"class_type": "CLIPVisionLoader",
|
|
45014
|
+
"inputs": { "clip_name": "dino_v3_L_naf_fp32.safetensors" }
|
|
45015
|
+
},
|
|
45016
|
+
"18": {
|
|
45017
|
+
"class_type": "KSampler",
|
|
45018
|
+
"inputs": {
|
|
45019
|
+
"seed": "{{seed}}",
|
|
45020
|
+
"steps": 20,
|
|
45021
|
+
"cfg": 7.5,
|
|
45022
|
+
"sampler_name": "euler",
|
|
45023
|
+
"scheduler": "normal",
|
|
45024
|
+
"denoise": 1,
|
|
45025
|
+
"model": ["126", 0],
|
|
45026
|
+
"positive": ["91", 0],
|
|
45027
|
+
"negative": ["91", 1],
|
|
45028
|
+
"latent_image": ["91", 2]
|
|
45029
|
+
}
|
|
45030
|
+
},
|
|
45031
|
+
"23": {
|
|
45032
|
+
"class_type": "KSampler",
|
|
45033
|
+
"inputs": {
|
|
45034
|
+
"seed": "{{seed}}",
|
|
45035
|
+
"steps": 12,
|
|
45036
|
+
"cfg": 7.5,
|
|
45037
|
+
"sampler_name": "euler",
|
|
45038
|
+
"scheduler": "simple",
|
|
45039
|
+
"denoise": 1,
|
|
45040
|
+
"model": ["126", 0],
|
|
45041
|
+
"positive": ["94", 0],
|
|
45042
|
+
"negative": ["94", 1],
|
|
45043
|
+
"latent_image": ["94", 2]
|
|
45044
|
+
}
|
|
45045
|
+
},
|
|
45046
|
+
"40": {
|
|
45047
|
+
"class_type": "UNETLoader",
|
|
45048
|
+
"inputs": {
|
|
45049
|
+
"unet_name": "trellis_2_int8_convrot.safetensors",
|
|
45050
|
+
"weight_dtype": "default"
|
|
45051
|
+
}
|
|
45052
|
+
},
|
|
45053
|
+
"55": {
|
|
45054
|
+
"class_type": "LoadMoGeModel",
|
|
45055
|
+
"inputs": { "model_name": "moge_2_vitl_normal_fp16.safetensors" }
|
|
45056
|
+
},
|
|
45057
|
+
"56": {
|
|
45058
|
+
"class_type": "MoGeInference",
|
|
45059
|
+
"inputs": {
|
|
45060
|
+
"resolution_level": 9,
|
|
45061
|
+
"fov_x_degrees": 0,
|
|
45062
|
+
"batch_size": 4,
|
|
45063
|
+
"force_projection": true,
|
|
45064
|
+
"apply_mask": true,
|
|
45065
|
+
"refine_steps": 3,
|
|
45066
|
+
"moge_model": ["55", 0],
|
|
45067
|
+
"image": ["302", 0]
|
|
45068
|
+
}
|
|
45069
|
+
},
|
|
45070
|
+
"87": {
|
|
45071
|
+
"class_type": "EmptyTrellis2LatentStructure",
|
|
45072
|
+
"inputs": { "batch_size": 1 }
|
|
45073
|
+
},
|
|
45074
|
+
"91": {
|
|
45075
|
+
"class_type": "Trellis2ShapeStage",
|
|
45076
|
+
"inputs": {
|
|
45077
|
+
"positive": ["314", 0],
|
|
45078
|
+
"negative": ["315", 0],
|
|
45079
|
+
"voxel": ["119", 0]
|
|
45080
|
+
}
|
|
45081
|
+
},
|
|
45082
|
+
"92": {
|
|
45083
|
+
"class_type": "VaeDecodeShapeTrellis",
|
|
45084
|
+
"inputs": {
|
|
45085
|
+
"samples": ["23", 0],
|
|
45086
|
+
"vae": ["117", 0]
|
|
45087
|
+
}
|
|
45088
|
+
},
|
|
45089
|
+
"93": {
|
|
45090
|
+
"class_type": "VaeDecodeTextureTrellis",
|
|
45091
|
+
"inputs": {
|
|
45092
|
+
"samples": ["12", 0],
|
|
45093
|
+
"vae": ["118", 0],
|
|
45094
|
+
"shape_subdivides": ["92", 1]
|
|
45095
|
+
}
|
|
45096
|
+
},
|
|
45097
|
+
"94": {
|
|
45098
|
+
"class_type": "Trellis2UpsampleStage",
|
|
45099
|
+
"inputs": {
|
|
45100
|
+
"target_resolution": 1024,
|
|
45101
|
+
"positive": ["91", 0],
|
|
45102
|
+
"negative": ["91", 1],
|
|
45103
|
+
"shape_latent": ["18", 0],
|
|
45104
|
+
"vae": ["117", 0]
|
|
45105
|
+
}
|
|
45106
|
+
},
|
|
45107
|
+
"98": {
|
|
45108
|
+
"class_type": "Trellis2TextureStage",
|
|
45109
|
+
"inputs": {
|
|
45110
|
+
"positive": ["94", 0],
|
|
45111
|
+
"negative": ["94", 1],
|
|
45112
|
+
"shape_latent": ["23", 0]
|
|
45113
|
+
}
|
|
45114
|
+
},
|
|
45115
|
+
"108": {
|
|
45116
|
+
"class_type": "ModelSamplingSD3",
|
|
45117
|
+
"inputs": {
|
|
45118
|
+
"shift": 5,
|
|
45119
|
+
"model": ["125", 0]
|
|
45120
|
+
}
|
|
45121
|
+
},
|
|
45122
|
+
"117": {
|
|
45123
|
+
"class_type": "VAELoader",
|
|
45124
|
+
"inputs": { "vae_name": "trellis_2_shape_vae_bf16.safetensors" }
|
|
45125
|
+
},
|
|
45126
|
+
"118": {
|
|
45127
|
+
"class_type": "VAELoader",
|
|
45128
|
+
"inputs": { "vae_name": "trellis_2_texture_vae_bf16.safetensors" }
|
|
45129
|
+
},
|
|
45130
|
+
"119": {
|
|
45131
|
+
"class_type": "VaeDecodeStructureTrellis2",
|
|
45132
|
+
"inputs": {
|
|
45133
|
+
"resolution": "32",
|
|
45134
|
+
"samples": ["3", 0],
|
|
45135
|
+
"vae": ["117", 0]
|
|
45136
|
+
}
|
|
45137
|
+
},
|
|
45138
|
+
"122": {
|
|
45139
|
+
"class_type": "LoadImage",
|
|
45140
|
+
"inputs": { "image": "{{image}}" }
|
|
45141
|
+
},
|
|
45142
|
+
"125": {
|
|
45143
|
+
"class_type": "RescaleCFG",
|
|
45144
|
+
"inputs": {
|
|
45145
|
+
"multiplier": .7,
|
|
45146
|
+
"model": ["199", 0]
|
|
45147
|
+
}
|
|
45148
|
+
},
|
|
45149
|
+
"126": {
|
|
45150
|
+
"class_type": "RescaleCFG",
|
|
45151
|
+
"inputs": {
|
|
45152
|
+
"multiplier": .5,
|
|
45153
|
+
"model": ["279", 0]
|
|
45154
|
+
}
|
|
45155
|
+
},
|
|
45156
|
+
"147": {
|
|
45157
|
+
"class_type": "BakeTextureFromVoxel",
|
|
45158
|
+
"inputs": {
|
|
45159
|
+
"texture_size": ["288", 0],
|
|
45160
|
+
"mesh": ["196", 0],
|
|
45161
|
+
"voxel_colors": ["93", 0],
|
|
45162
|
+
"reference_mesh": ["92", 0]
|
|
45163
|
+
}
|
|
45164
|
+
},
|
|
45165
|
+
"164": {
|
|
45166
|
+
"class_type": "PreviewImage",
|
|
45167
|
+
"inputs": { "images": ["147", 0] }
|
|
45168
|
+
},
|
|
45169
|
+
"186": {
|
|
45170
|
+
"class_type": "DecimateMesh",
|
|
45171
|
+
"inputs": {
|
|
45172
|
+
"target_face_count": 1e5,
|
|
45173
|
+
"placement_mode": "midpoint",
|
|
45174
|
+
"mesh": ["241", 0]
|
|
45175
|
+
}
|
|
45176
|
+
},
|
|
45177
|
+
"192": {
|
|
45178
|
+
"class_type": "RemoveBackground",
|
|
45179
|
+
"inputs": {
|
|
45180
|
+
"bg_removal_model": ["193", 0],
|
|
45181
|
+
"image": ["122", 0]
|
|
45182
|
+
}
|
|
45183
|
+
},
|
|
45184
|
+
"193": {
|
|
45185
|
+
"class_type": "LoadBackgroundRemovalModel",
|
|
45186
|
+
"inputs": { "bg_removal_name": "birefnet.safetensors" }
|
|
45187
|
+
},
|
|
45188
|
+
"196": {
|
|
45189
|
+
"class_type": "UnwrapMesh",
|
|
45190
|
+
"inputs": {
|
|
45191
|
+
"segmenter": "pec",
|
|
45192
|
+
"resolution": ["288", 0],
|
|
45193
|
+
"padding": 1,
|
|
45194
|
+
"weld_distance": 2e-4,
|
|
45195
|
+
"mesh": ["238", 0]
|
|
45196
|
+
}
|
|
45197
|
+
},
|
|
45198
|
+
"199": {
|
|
45199
|
+
"class_type": "CFGOverride",
|
|
45200
|
+
"inputs": {
|
|
45201
|
+
"cfg": 1,
|
|
45202
|
+
"start_percent": .667,
|
|
45203
|
+
"end_percent": 1,
|
|
45204
|
+
"model": ["318", 0]
|
|
45205
|
+
}
|
|
45206
|
+
},
|
|
45207
|
+
"202": {
|
|
45208
|
+
"class_type": "GetMeshInfo",
|
|
45209
|
+
"inputs": { "mesh": ["92", 0] }
|
|
45210
|
+
},
|
|
45211
|
+
"207": {
|
|
45212
|
+
"class_type": "PreviewImage",
|
|
45213
|
+
"inputs": { "images": ["147", 1] }
|
|
45214
|
+
},
|
|
45215
|
+
"208": {
|
|
45216
|
+
"class_type": "PreviewImage",
|
|
45217
|
+
"inputs": { "images": ["147", 2] }
|
|
45218
|
+
},
|
|
45219
|
+
"210": {
|
|
45220
|
+
"class_type": "ApplyTextureToMesh",
|
|
45221
|
+
"inputs": {
|
|
45222
|
+
"mesh": ["196", 0],
|
|
45223
|
+
"base_color": ["164", 0],
|
|
45224
|
+
"metallic": ["207", 0],
|
|
45225
|
+
"roughness": ["208", 0],
|
|
45226
|
+
"occlusion": ["235", 0],
|
|
45227
|
+
"normal_map": ["226", 0]
|
|
45228
|
+
}
|
|
45229
|
+
},
|
|
45230
|
+
"224": {
|
|
45231
|
+
"class_type": "BakeNormalMapFromMesh",
|
|
45232
|
+
"inputs": {
|
|
45233
|
+
"resolution": 2048,
|
|
45234
|
+
"cage_distance": .05,
|
|
45235
|
+
"ignore_backfaces": true,
|
|
45236
|
+
"low_poly": ["196", 0],
|
|
45237
|
+
"high_poly": ["241", 0]
|
|
45238
|
+
}
|
|
45239
|
+
},
|
|
45240
|
+
"226": {
|
|
45241
|
+
"class_type": "PreviewImage",
|
|
45242
|
+
"inputs": { "images": ["224", 0] }
|
|
45243
|
+
},
|
|
45244
|
+
"233": {
|
|
45245
|
+
"class_type": "BakeAmbientOcclusion",
|
|
45246
|
+
"inputs": {
|
|
45247
|
+
"resolution": 1024,
|
|
45248
|
+
"samples": 64,
|
|
45249
|
+
"max_distance": .71,
|
|
45250
|
+
"strength": 1,
|
|
45251
|
+
"bias": .01,
|
|
45252
|
+
"low_poly": ["196", 0],
|
|
45253
|
+
"high_poly": ["241", 0]
|
|
45254
|
+
}
|
|
45255
|
+
},
|
|
45256
|
+
"235": {
|
|
45257
|
+
"class_type": "PreviewImage",
|
|
45258
|
+
"inputs": { "images": ["233", 0] }
|
|
45259
|
+
},
|
|
45260
|
+
"238": {
|
|
45261
|
+
"class_type": "MeshSmoothNormals",
|
|
45262
|
+
"inputs": {
|
|
45263
|
+
"crease_angle": 180,
|
|
45264
|
+
"mesh": ["186", 0]
|
|
45265
|
+
}
|
|
45266
|
+
},
|
|
45267
|
+
"241": {
|
|
45268
|
+
"class_type": "RemeshMesh",
|
|
45269
|
+
"inputs": {
|
|
45270
|
+
"resolution": 768,
|
|
45271
|
+
"sign_mode": "solid",
|
|
45272
|
+
"sign_mode.fill": 20,
|
|
45273
|
+
"sign_mode.qef": false,
|
|
45274
|
+
"band": 1,
|
|
45275
|
+
"project_back": 0,
|
|
45276
|
+
"fix_poles": false,
|
|
45277
|
+
"smooth_iters": 20,
|
|
45278
|
+
"drop_small_components": .01,
|
|
45279
|
+
"precluster_max_verts": 2e7,
|
|
45280
|
+
"mesh": ["202", 0]
|
|
45281
|
+
}
|
|
45282
|
+
},
|
|
45283
|
+
"242": {
|
|
45284
|
+
"class_type": "MoGeGeometryToFOV",
|
|
45285
|
+
"inputs": {
|
|
45286
|
+
"axis": "horizontal",
|
|
45287
|
+
"unit": "degrees",
|
|
45288
|
+
"moge_geometry": ["56", 0]
|
|
45289
|
+
}
|
|
45290
|
+
},
|
|
45291
|
+
"247": {
|
|
45292
|
+
"class_type": "MeshToFile3D",
|
|
45293
|
+
"inputs": { "mesh": ["4", 0] }
|
|
45294
|
+
},
|
|
45295
|
+
"248": {
|
|
45296
|
+
"class_type": "ComfySwitchNode",
|
|
45297
|
+
"inputs": {
|
|
45298
|
+
"switch": true,
|
|
45299
|
+
"on_false": ["122", 1],
|
|
45300
|
+
"on_true": ["192", 0]
|
|
45301
|
+
}
|
|
45302
|
+
},
|
|
45303
|
+
"252": {
|
|
45304
|
+
"class_type": "PaintMesh",
|
|
45305
|
+
"inputs": {
|
|
45306
|
+
"mesh": ["238", 0],
|
|
45307
|
+
"voxel_colors": ["93", 0]
|
|
45308
|
+
}
|
|
45309
|
+
},
|
|
45310
|
+
"260": {
|
|
45311
|
+
"class_type": "MeshSmoothNormals",
|
|
45312
|
+
"inputs": {
|
|
45313
|
+
"crease_angle": 180,
|
|
45314
|
+
"mesh": ["210", 0]
|
|
45315
|
+
}
|
|
45316
|
+
},
|
|
45317
|
+
"261": {
|
|
45318
|
+
"class_type": "RenderUVAtlas",
|
|
45319
|
+
"inputs": {
|
|
45320
|
+
"resolution": 1024,
|
|
45321
|
+
"mesh": ["196", 0]
|
|
45322
|
+
}
|
|
45323
|
+
},
|
|
45324
|
+
"262": {
|
|
45325
|
+
"class_type": "PreviewImage",
|
|
45326
|
+
"inputs": { "images": ["261", 0] }
|
|
45327
|
+
},
|
|
45328
|
+
"279": {
|
|
45329
|
+
"class_type": "CFGOverride",
|
|
45330
|
+
"inputs": {
|
|
45331
|
+
"cfg": 1,
|
|
45332
|
+
"start_percent": .769,
|
|
45333
|
+
"end_percent": 1,
|
|
45334
|
+
"model": ["318", 0]
|
|
45335
|
+
}
|
|
45336
|
+
},
|
|
45337
|
+
"282": {
|
|
45338
|
+
"class_type": "MeshToFile3D",
|
|
45339
|
+
"inputs": { "mesh": ["252", 0] }
|
|
45340
|
+
},
|
|
45341
|
+
"285": {
|
|
45342
|
+
"class_type": "MeshToFile3D",
|
|
45343
|
+
"inputs": { "mesh": ["260", 0] }
|
|
45344
|
+
},
|
|
45345
|
+
"288": {
|
|
45346
|
+
"class_type": "PrimitiveInt",
|
|
45347
|
+
"inputs": { "value": 2048 }
|
|
45348
|
+
},
|
|
45349
|
+
"298": {
|
|
45350
|
+
"class_type": "Pixal3DConditioning",
|
|
45351
|
+
"inputs": {
|
|
45352
|
+
"camera_angle_x": ["242", 0],
|
|
45353
|
+
"clip_vision_model": ["15", 0],
|
|
45354
|
+
"image": ["302", 0]
|
|
45355
|
+
}
|
|
45356
|
+
},
|
|
45357
|
+
"299": {
|
|
45358
|
+
"class_type": "Trellis2Conditioning",
|
|
45359
|
+
"inputs": {
|
|
45360
|
+
"clip_vision_model": ["15", 0],
|
|
45361
|
+
"image": ["302", 0]
|
|
45362
|
+
}
|
|
45363
|
+
},
|
|
45364
|
+
"302": {
|
|
45365
|
+
"class_type": "PreviewImage",
|
|
45366
|
+
"inputs": { "images": ["312", 0] }
|
|
45367
|
+
},
|
|
45368
|
+
"303": {
|
|
45369
|
+
"class_type": "MaskPreview",
|
|
45370
|
+
"inputs": { "mask": ["248", 0] }
|
|
45371
|
+
},
|
|
45372
|
+
"312": {
|
|
45373
|
+
"class_type": "ImageCropToMask",
|
|
45374
|
+
"inputs": {
|
|
45375
|
+
"width": 1024,
|
|
45376
|
+
"height": 1024,
|
|
45377
|
+
"pad_factor": 1.1,
|
|
45378
|
+
"grow_mask": 0,
|
|
45379
|
+
"background": "#000000",
|
|
45380
|
+
"images": ["122", 0],
|
|
45381
|
+
"masks": ["303", 0]
|
|
45382
|
+
}
|
|
45383
|
+
},
|
|
45384
|
+
"314": {
|
|
45385
|
+
"class_type": "ComfySwitchNode",
|
|
45386
|
+
"inputs": {
|
|
45387
|
+
"switch": ["316", 0],
|
|
45388
|
+
"on_false": ["298", 0],
|
|
45389
|
+
"on_true": ["299", 0]
|
|
45390
|
+
}
|
|
45391
|
+
},
|
|
45392
|
+
"315": {
|
|
45393
|
+
"class_type": "ComfySwitchNode",
|
|
45394
|
+
"inputs": {
|
|
45395
|
+
"switch": ["316", 0],
|
|
45396
|
+
"on_false": ["298", 1],
|
|
45397
|
+
"on_true": ["299", 1]
|
|
45398
|
+
}
|
|
45399
|
+
},
|
|
45400
|
+
"316": {
|
|
45401
|
+
"class_type": "PrimitiveBoolean",
|
|
45402
|
+
"inputs": { "value": false }
|
|
45403
|
+
},
|
|
45404
|
+
"318": {
|
|
45405
|
+
"class_type": "ComfySwitchNode",
|
|
45406
|
+
"inputs": {
|
|
45407
|
+
"switch": ["316", 0],
|
|
45408
|
+
"on_false": ["319", 0],
|
|
45409
|
+
"on_true": ["40", 0]
|
|
45410
|
+
}
|
|
45411
|
+
},
|
|
45412
|
+
"319": {
|
|
45413
|
+
"class_type": "UNETLoader",
|
|
45414
|
+
"inputs": {
|
|
45415
|
+
"unet_name": "pixal3d_int8_convrot.safetensors",
|
|
45416
|
+
"weight_dtype": "default"
|
|
45417
|
+
}
|
|
45418
|
+
},
|
|
45419
|
+
"322": {
|
|
45420
|
+
"class_type": "SaveGLB",
|
|
45421
|
+
"inputs": {
|
|
45422
|
+
"mesh": ["285", 0],
|
|
45423
|
+
"filename_prefix": "3d/frameboard"
|
|
45424
|
+
}
|
|
45425
|
+
}
|
|
45426
|
+
};
|
|
45427
|
+
// src/server/sourcing/comfyui/workflow.ts
|
|
45428
|
+
/** FLUX.2 klein 4B's distilled text-to-image graph, the one a run takes without `--workflow`. */
|
|
45429
|
+
const BUNDLED_WORKFLOW = flux2_klein_default;
|
|
45430
|
+
/**
|
|
45431
|
+
* Pixal3D's image-to-model graph at web size, 100,000 triangles and 2048 px
|
|
45432
|
+
* textures, the one a model run takes without `--workflow`.
|
|
45433
|
+
*/
|
|
45434
|
+
const BUNDLED_MODEL_WORKFLOW = pixal3d_default;
|
|
45435
|
+
const REQUIRED = {
|
|
45436
|
+
image: {
|
|
45437
|
+
name: "{{prompt}}",
|
|
45438
|
+
holds: "the prompt asked",
|
|
45439
|
+
input: "text input"
|
|
45440
|
+
},
|
|
45441
|
+
model: {
|
|
45442
|
+
name: "{{image}}",
|
|
45443
|
+
holds: "the picture given",
|
|
45444
|
+
input: "LoadImage node’s image input"
|
|
45445
|
+
}
|
|
45446
|
+
};
|
|
45447
|
+
const PLACEHOLDER = /\{\{(prompt|image|width|height|seed)\}\}/g;
|
|
45448
|
+
/**
|
|
45449
|
+
* The workflow with each placeholder the values name filled, leaving any other.
|
|
45450
|
+
* A lone number placeholder becomes a number, since ComfyUI refuses a width sent as text.
|
|
45451
|
+
*/
|
|
45452
|
+
function fillWorkflow(workflow, values) {
|
|
45453
|
+
const known = { ...values };
|
|
45454
|
+
const fill = (value) => {
|
|
45455
|
+
if (typeof value === "string") {
|
|
45456
|
+
const whole = /^\{\{(width|height|seed)\}\}$/.exec(value)?.[1];
|
|
45457
|
+
if (whole !== void 0 && whole in known) return known[whole];
|
|
45458
|
+
return value.replace(PLACEHOLDER, (placeholder, name) => name in known ? String(known[name]) : placeholder);
|
|
45459
|
+
}
|
|
45460
|
+
if (Array.isArray(value)) return value.map(fill);
|
|
45461
|
+
if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, each]) => [key, fill(each)]));
|
|
45462
|
+
return value;
|
|
45463
|
+
};
|
|
45464
|
+
return Object.fromEntries(Object.entries(workflow).map(([id, node]) => [id, {
|
|
45465
|
+
...node,
|
|
45466
|
+
inputs: fill(node.inputs)
|
|
45467
|
+
}]));
|
|
45468
|
+
}
|
|
45469
|
+
/**
|
|
45470
|
+
* The value as an API-format workflow carrying the placeholder its kind
|
|
45471
|
+
* requires, `{{prompt}}` for an image and `{{image}}` for a model, refusing
|
|
45472
|
+
* `usage` otherwise, so a run never sends a graph that ignores its input.
|
|
45473
|
+
*/
|
|
45474
|
+
function checkWorkflow(value, name, kind = "image") {
|
|
45475
|
+
const nodes = typeof value === "object" && value !== null && !Array.isArray(value) ? Object.values(value) : [];
|
|
45476
|
+
if (!(nodes.length > 0 && nodes.every((node) => typeof node === "object" && node !== null && "class_type" in node && typeof node.class_type === "string" && "inputs" in node && typeof node.inputs === "object" && node.inputs !== null))) throw new FrameboardError("usage", `${name} is not a ComfyUI workflow in the API format. Export it from ComfyUI with File, Export (API).`, { workflow: name });
|
|
45477
|
+
const required = REQUIRED[kind];
|
|
45478
|
+
if (!JSON.stringify(value).includes(required.name)) throw new FrameboardError("usage", `${name} holds no ${required.name}, so ${required.holds} would never reach it. Put ${required.name} in the ${required.input} that takes it.`, { workflow: name });
|
|
45479
|
+
return value;
|
|
45480
|
+
}
|
|
45481
|
+
/** Reads and checks a workflow file before any request, refusing `usage` for one that is absent, not JSON, or no workflow of its kind. */
|
|
45482
|
+
async function readWorkflow(path, kind = "image") {
|
|
45483
|
+
let text;
|
|
45484
|
+
try {
|
|
45485
|
+
text = await readFile(path, "utf8");
|
|
45486
|
+
} catch {
|
|
45487
|
+
throw new FrameboardError("usage", `No workflow file at ${path}.`, { workflow: path });
|
|
45488
|
+
}
|
|
45489
|
+
let parsed;
|
|
45490
|
+
try {
|
|
45491
|
+
parsed = JSON.parse(text);
|
|
45492
|
+
} catch {
|
|
45493
|
+
throw new FrameboardError("usage", `${path} is not JSON.`, { workflow: path });
|
|
45494
|
+
}
|
|
45495
|
+
return checkWorkflow(parsed, path, kind);
|
|
45496
|
+
}
|
|
45497
|
+
// src/server/sourcing/providers/comfyui.ts
|
|
45498
|
+
/**
|
|
45499
|
+
* A ComfyUI server the developer runs, its "key" the address it listens at.
|
|
45500
|
+
* It charges nothing and runs the bundled FLUX.2 klein 4B workflow unless the
|
|
45501
|
+
* request carries the developer's own.
|
|
45502
|
+
*/
|
|
45503
|
+
const comfyui = {
|
|
45504
|
+
name: "comfyui",
|
|
45505
|
+
model: "flux-2-klein-4b-fp8",
|
|
45506
|
+
keyEnv: "FRAMEBOARD_COMFYUI_URL",
|
|
45507
|
+
sizeFor: (asked) => asked,
|
|
45508
|
+
priceFor: () => 0,
|
|
45509
|
+
generate({ prompt, size, key, seed, workflow }, send) {
|
|
45510
|
+
return runWorkflow(key, fillWorkflow(workflow?.graph ?? BUNDLED_WORKFLOW, {
|
|
45511
|
+
prompt,
|
|
45512
|
+
...size,
|
|
45513
|
+
seed
|
|
45514
|
+
}), send);
|
|
45515
|
+
}
|
|
45516
|
+
};
|
|
44379
45517
|
// src/server/sourcing/providers/provider.ts
|
|
44380
45518
|
/**
|
|
44381
45519
|
* The refusal a provider's failure answers, with its status and its own
|
|
@@ -44609,20 +45747,29 @@ function isRecord$4(value) {
|
|
|
44609
45747
|
return typeof value === "object" && value !== null;
|
|
44610
45748
|
}
|
|
44611
45749
|
// src/server/sourcing/generate.ts
|
|
44612
|
-
/**
|
|
44613
|
-
|
|
45750
|
+
/**
|
|
45751
|
+
* Every provider in the order `image generate` tries them, the developer's
|
|
45752
|
+
* own server first since it charges nothing and setting its URL opts in.
|
|
45753
|
+
*/
|
|
45754
|
+
const PROVIDERS = [
|
|
45755
|
+
comfyui,
|
|
45756
|
+
fal,
|
|
45757
|
+
google
|
|
45758
|
+
];
|
|
44614
45759
|
/** A provider's key, null when unset or empty, so an empty string never reaches a request. */
|
|
44615
45760
|
function keyOf(provider, env) {
|
|
44616
45761
|
const key = env[provider.keyEnv]?.trim();
|
|
44617
45762
|
return key === void 0 || key === "" ? null : key;
|
|
44618
45763
|
}
|
|
44619
45764
|
/**
|
|
44620
|
-
* The provider
|
|
44621
|
-
*
|
|
44622
|
-
*
|
|
45765
|
+
* The provider named, else the first whose key is set, with its size and
|
|
45766
|
+
* price, making no request. A workflow runs on comfyui alone. Refuses
|
|
45767
|
+
* `no-provider` when none is ready, and `usage` for an unknown name or a workflow beside a hosted one.
|
|
44623
45768
|
*/
|
|
44624
|
-
function planGeneration(request, env) {
|
|
44625
|
-
const
|
|
45769
|
+
function planGeneration(request, env, random = Math.random) {
|
|
45770
|
+
const named = request.provider ?? (request.workflow ? comfyui.name : void 0);
|
|
45771
|
+
if (request.workflow && named !== comfyui.name) throw new FrameboardError("usage", `--workflow runs on ${comfyui.name} alone, not --provider ${named}.`, { provider: named });
|
|
45772
|
+
const candidates = named === void 0 ? PROVIDERS : PROVIDERS.filter((each) => each.name === named);
|
|
44626
45773
|
if (candidates.length === 0) throw new FrameboardError("usage", `--provider ${request.provider} is not one of ${IMAGE_PROVIDERS.join(", ")}.`, { providers: [...IMAGE_PROVIDERS] });
|
|
44627
45774
|
for (const provider of candidates) {
|
|
44628
45775
|
const key = keyOf(provider, env);
|
|
@@ -44630,10 +45777,13 @@ function planGeneration(request, env) {
|
|
|
44630
45777
|
const size = provider.sizeFor(request.size);
|
|
44631
45778
|
return {
|
|
44632
45779
|
provider,
|
|
45780
|
+
model: request.workflow ? basename(request.workflow.name) : provider.model,
|
|
44633
45781
|
prompt: request.prompt,
|
|
44634
45782
|
size,
|
|
44635
45783
|
priceUsd: provider.priceFor(size),
|
|
44636
|
-
key
|
|
45784
|
+
key,
|
|
45785
|
+
seed: Math.floor(random() * Number.MAX_SAFE_INTEGER),
|
|
45786
|
+
...request.workflow && { workflow: request.workflow }
|
|
44637
45787
|
};
|
|
44638
45788
|
}
|
|
44639
45789
|
const keys = candidates.map((each) => each.keyEnv);
|
|
@@ -44644,7 +45794,9 @@ function generateImage(plan, send) {
|
|
|
44644
45794
|
return plan.provider.generate({
|
|
44645
45795
|
prompt: plan.prompt,
|
|
44646
45796
|
size: plan.size,
|
|
44647
|
-
key: plan.key
|
|
45797
|
+
key: plan.key,
|
|
45798
|
+
seed: plan.seed,
|
|
45799
|
+
workflow: plan.workflow
|
|
44648
45800
|
}, send);
|
|
44649
45801
|
}
|
|
44650
45802
|
// src/server/sourcing/openverse.ts
|
|
@@ -44764,11 +45916,318 @@ function text$1(value) {
|
|
|
44764
45916
|
function integer$1(value) {
|
|
44765
45917
|
return typeof value === "number" && Number.isSafeInteger(value) ? value : null;
|
|
44766
45918
|
}
|
|
45919
|
+
// src/server/sourcing/pack-glb.ts
|
|
45920
|
+
const GLB_MAGIC = 1179937895;
|
|
45921
|
+
const GLB_VERSION = 2;
|
|
45922
|
+
const JSON_CHUNK = 1313821514;
|
|
45923
|
+
const BIN_CHUNK = 5130562;
|
|
45924
|
+
const CHUNK_HEADER_BYTES = 8;
|
|
45925
|
+
/** The texture formats a glTF viewer reads with no extension named. */
|
|
45926
|
+
const IMAGE_TYPES = {
|
|
45927
|
+
jpg: "image/jpeg",
|
|
45928
|
+
jpeg: "image/jpeg",
|
|
45929
|
+
png: "image/png"
|
|
45930
|
+
};
|
|
45931
|
+
/**
|
|
45932
|
+
* Packs a glTF and the files `files` holds by the URI it names into one GLB
|
|
45933
|
+
* naming no outside file. Refuses `source-failed` for anything it cannot pack
|
|
45934
|
+
* whole rather than writing a file a viewer cannot load.
|
|
45935
|
+
*/
|
|
45936
|
+
function packGlb(gltf, files) {
|
|
45937
|
+
const buffers = listOf(gltf.buffers);
|
|
45938
|
+
if (buffers.length > 1) throw refused(`The glTF names ${buffers.length} buffers, and one packs.`);
|
|
45939
|
+
const parts = [];
|
|
45940
|
+
let length = 0;
|
|
45941
|
+
const append = (bytes) => {
|
|
45942
|
+
const offset = length;
|
|
45943
|
+
parts.push({
|
|
45944
|
+
bytes,
|
|
45945
|
+
offset
|
|
45946
|
+
});
|
|
45947
|
+
length = align(offset + bytes.byteLength);
|
|
45948
|
+
return offset;
|
|
45949
|
+
};
|
|
45950
|
+
const buffer = buffers[0];
|
|
45951
|
+
if (buffer !== void 0) {
|
|
45952
|
+
const declared = buffer.byteLength;
|
|
45953
|
+
if (typeof declared !== "number") throw refused("The glTF buffer states no byteLength.");
|
|
45954
|
+
const bytes = fileFor(buffer.uri, files);
|
|
45955
|
+
if (bytes.byteLength < declared) throw refused(`The buffer holds ${bytes.byteLength} bytes, short of the ${declared} the glTF states.`);
|
|
45956
|
+
append(bytes.subarray(0, declared));
|
|
45957
|
+
}
|
|
45958
|
+
const packedViews = [...listOf(gltf.bufferViews)];
|
|
45959
|
+
const images = listOf(gltf.images).map((image) => {
|
|
45960
|
+
if (image.uri === void 0) return image;
|
|
45961
|
+
const bytes = fileFor(image.uri, files);
|
|
45962
|
+
const mimeType = mimeTypeOf(image);
|
|
45963
|
+
const byteOffset = append(bytes);
|
|
45964
|
+
packedViews.push({
|
|
45965
|
+
buffer: 0,
|
|
45966
|
+
byteOffset,
|
|
45967
|
+
byteLength: bytes.byteLength
|
|
45968
|
+
});
|
|
45969
|
+
const { uri: _uri, ...rest } = image;
|
|
45970
|
+
return {
|
|
45971
|
+
...rest,
|
|
45972
|
+
bufferView: packedViews.length - 1,
|
|
45973
|
+
mimeType
|
|
45974
|
+
};
|
|
45975
|
+
});
|
|
45976
|
+
const json = { ...gltf };
|
|
45977
|
+
delete json.buffers;
|
|
45978
|
+
delete json.bufferViews;
|
|
45979
|
+
if (length > 0) json.buffers = [{ byteLength: length }];
|
|
45980
|
+
if (packedViews.length > 0) json.bufferViews = packedViews;
|
|
45981
|
+
if (gltf.images !== void 0) json.images = images;
|
|
45982
|
+
return container(json, parts, length);
|
|
45983
|
+
}
|
|
45984
|
+
function container(json, parts, binLength) {
|
|
45985
|
+
const text = new TextEncoder().encode(JSON.stringify(json));
|
|
45986
|
+
const jsonLength = align(text.byteLength);
|
|
45987
|
+
const binChunk = binLength === 0 ? 0 : CHUNK_HEADER_BYTES + binLength;
|
|
45988
|
+
const total = 20 + jsonLength + binChunk;
|
|
45989
|
+
const glb = new Uint8Array(total);
|
|
45990
|
+
const view = new DataView(glb.buffer);
|
|
45991
|
+
view.setUint32(0, GLB_MAGIC, true);
|
|
45992
|
+
view.setUint32(4, GLB_VERSION, true);
|
|
45993
|
+
view.setUint32(8, total, true);
|
|
45994
|
+
view.setUint32(12, jsonLength, true);
|
|
45995
|
+
view.setUint32(16, JSON_CHUNK, true);
|
|
45996
|
+
glb.set(text, 20);
|
|
45997
|
+
glb.fill(32, 20 + text.byteLength, 20 + jsonLength);
|
|
45998
|
+
if (binChunk === 0) return glb;
|
|
45999
|
+
const binStart = 20 + jsonLength;
|
|
46000
|
+
view.setUint32(binStart, binLength, true);
|
|
46001
|
+
view.setUint32(binStart + 4, BIN_CHUNK, true);
|
|
46002
|
+
const dataStart = binStart + CHUNK_HEADER_BYTES;
|
|
46003
|
+
for (const part of parts) glb.set(part.bytes, dataStart + part.offset);
|
|
46004
|
+
return glb;
|
|
46005
|
+
}
|
|
46006
|
+
function fileFor(uri, files) {
|
|
46007
|
+
if (typeof uri !== "string" || uri === "") throw refused("The glTF names a buffer or image with no uri.");
|
|
46008
|
+
if (uri.startsWith("data:")) throw refused("The glTF carries a data URI, which this packer does not read.");
|
|
46009
|
+
const bytes = files.get(uri) ?? files.get(safeDecode(uri));
|
|
46010
|
+
if (bytes === void 0) throw refused(`The glTF names ${uri}, which was not downloaded.`);
|
|
46011
|
+
return bytes;
|
|
46012
|
+
}
|
|
46013
|
+
function mimeTypeOf(image) {
|
|
46014
|
+
if (typeof image.mimeType === "string") {
|
|
46015
|
+
if (Object.values(IMAGE_TYPES).includes(image.mimeType)) return image.mimeType;
|
|
46016
|
+
throw refused(`The glTF names a texture of type ${image.mimeType}.`);
|
|
46017
|
+
}
|
|
46018
|
+
const uri = String(image.uri);
|
|
46019
|
+
const extension = uri.slice(uri.lastIndexOf(".") + 1).toLowerCase();
|
|
46020
|
+
const type = IMAGE_TYPES[extension];
|
|
46021
|
+
if (type === void 0) throw refused(`The texture ${uri} is neither JPEG nor PNG.`);
|
|
46022
|
+
return type;
|
|
46023
|
+
}
|
|
46024
|
+
function listOf(value) {
|
|
46025
|
+
return Array.isArray(value) ? value.filter((each) => typeof each === "object" && each !== null) : [];
|
|
46026
|
+
}
|
|
46027
|
+
function safeDecode(uri) {
|
|
46028
|
+
try {
|
|
46029
|
+
return decodeURIComponent(uri);
|
|
46030
|
+
} catch {
|
|
46031
|
+
return uri;
|
|
46032
|
+
}
|
|
46033
|
+
}
|
|
46034
|
+
function align(length) {
|
|
46035
|
+
return Math.ceil(length / 4) * 4;
|
|
46036
|
+
}
|
|
46037
|
+
function refused(message) {
|
|
46038
|
+
return new FrameboardError("source-failed", message, { source: "polyhaven" });
|
|
46039
|
+
}
|
|
46040
|
+
// src/server/sourcing/polyhaven.ts
|
|
46041
|
+
const POLYHAVEN_API = "https://api.polyhaven.com/";
|
|
46042
|
+
/** Named on every listing, which Poly Haven's API terms ask of any surface showing its content. */
|
|
46043
|
+
const POLYHAVEN_SOURCE = {
|
|
46044
|
+
name: "Poly Haven",
|
|
46045
|
+
url: "https://polyhaven.com"
|
|
46046
|
+
};
|
|
46047
|
+
const CC0_URL = "https://creativecommons.org/publicdomain/zero/1.0/";
|
|
46048
|
+
/** Poly Haven's `type` for a model, beside 0 for an HDRI and 1 for a texture. */
|
|
46049
|
+
const MODEL_TYPE = 2;
|
|
46050
|
+
/**
|
|
46051
|
+
* Poly Haven has no search, so this ranks its whole list here: by distinct
|
|
46052
|
+
* query words matching the name, tags, or categories, then download count,
|
|
46053
|
+
* then id, numbered from 1 and empty when no word matches.
|
|
46054
|
+
*/
|
|
46055
|
+
async function searchModels(query, send) {
|
|
46056
|
+
const url = new URL("assets", POLYHAVEN_API);
|
|
46057
|
+
url.searchParams.set("t", "models");
|
|
46058
|
+
const body = await request(url, send);
|
|
46059
|
+
const words = new Set(wordsOf(query));
|
|
46060
|
+
const scored = Object.entries(isRecord$2(body) ? body : {}).map(([id, raw]) => toModel(id, raw)).filter((model) => model !== null).map((model) => {
|
|
46061
|
+
const own = new Set([
|
|
46062
|
+
model.name,
|
|
46063
|
+
...model.tags,
|
|
46064
|
+
...model.categories
|
|
46065
|
+
].flatMap(wordsOf));
|
|
46066
|
+
return {
|
|
46067
|
+
model,
|
|
46068
|
+
score: [...words].filter((word) => own.has(word)).length
|
|
46069
|
+
};
|
|
46070
|
+
}).filter(({ score }) => score > 0);
|
|
46071
|
+
scored.sort((a, b) => b.score - a.score || (b.model.downloadCount ?? 0) - (a.model.downloadCount ?? 0) || a.model.id.localeCompare(b.model.id));
|
|
46072
|
+
return scored.slice(0, 20).map(({ model }, index) => ({
|
|
46073
|
+
number: index + 1,
|
|
46074
|
+
...model
|
|
46075
|
+
}));
|
|
46076
|
+
}
|
|
46077
|
+
/**
|
|
46078
|
+
* One model by its Poly Haven id, refusing `result-not-found` for an id
|
|
46079
|
+
* Poly Haven does not hold or one naming a texture or an HDRI.
|
|
46080
|
+
*/
|
|
46081
|
+
async function modelById(id, send) {
|
|
46082
|
+
const missing = new FrameboardError("result-not-found", `Poly Haven holds no model ${id}.`, { id });
|
|
46083
|
+
const model = toModel(id, await request(new URL(`info/${encodeURIComponent(id)}`, POLYHAVEN_API), send, missing));
|
|
46084
|
+
if (model === null) throw missing;
|
|
46085
|
+
return model;
|
|
46086
|
+
}
|
|
46087
|
+
/**
|
|
46088
|
+
* Downloads every file of one model at `size` into memory and packs them as
|
|
46089
|
+
* one GLB, so a failed download leaves nothing to write. Refuses `usage` with
|
|
46090
|
+
* the sizes offered, and `source-failed` on a failed download or pack.
|
|
46091
|
+
*/
|
|
46092
|
+
async function fetchModel(id, size, send) {
|
|
46093
|
+
const body = await request(new URL(`files/${encodeURIComponent(id)}`, POLYHAVEN_API), send);
|
|
46094
|
+
const gltf = isRecord$2(body) && isRecord$2(body.gltf) ? body.gltf : {};
|
|
46095
|
+
const entryAt = (each) => {
|
|
46096
|
+
const sized = gltf[each];
|
|
46097
|
+
return isRecord$2(sized) && isRecord$2(sized.gltf) ? sized.gltf : null;
|
|
46098
|
+
};
|
|
46099
|
+
const sizes = MODEL_SIZES.filter((each) => entryAt(each) !== null);
|
|
46100
|
+
const entry = entryAt(size);
|
|
46101
|
+
if (sizes.length === 0) throw new FrameboardError("source-failed", `Poly Haven serves ${id} as no glTF, so it cannot be saved as a GLB.`, {
|
|
46102
|
+
source: "polyhaven",
|
|
46103
|
+
id,
|
|
46104
|
+
status: null
|
|
46105
|
+
});
|
|
46106
|
+
if (entry === null) throw new FrameboardError("usage", `Poly Haven serves ${id} at ${sizes.join(", ")}, not ${size}.`, {
|
|
46107
|
+
id,
|
|
46108
|
+
size,
|
|
46109
|
+
sizes
|
|
46110
|
+
});
|
|
46111
|
+
const gltfUrl = text(entry.url);
|
|
46112
|
+
if (gltfUrl === null) throw malformed(id);
|
|
46113
|
+
const includes = Object.entries(isRecord$2(entry.include) ? entry.include : {});
|
|
46114
|
+
const [main, ...files] = await Promise.all([download$1(gltfUrl, send), ...includes.map(([, file]) => {
|
|
46115
|
+
const fileUrl = isRecord$2(file) ? text(file.url) : null;
|
|
46116
|
+
if (fileUrl === null) throw malformed(id);
|
|
46117
|
+
return download$1(fileUrl, send);
|
|
46118
|
+
})]);
|
|
46119
|
+
let json;
|
|
46120
|
+
try {
|
|
46121
|
+
json = JSON.parse(new TextDecoder().decode(main?.bytes));
|
|
46122
|
+
} catch {
|
|
46123
|
+
throw malformed(id);
|
|
46124
|
+
}
|
|
46125
|
+
if (!isRecord$2(json)) throw malformed(id);
|
|
46126
|
+
const byUri = new Map(includes.map(([uri], index) => [uri, files[index]?.bytes ?? /* @__PURE__ */ new Uint8Array()]));
|
|
46127
|
+
return {
|
|
46128
|
+
bytes: packGlb(json, byUri),
|
|
46129
|
+
url: gltfUrl
|
|
46130
|
+
};
|
|
46131
|
+
}
|
|
46132
|
+
/** The license file for a Poly Haven model, `query` null when it was saved by id. */
|
|
46133
|
+
function polyhavenLicense(model, query, packed, savedAt) {
|
|
46134
|
+
return {
|
|
46135
|
+
version: 1,
|
|
46136
|
+
origin: "found",
|
|
46137
|
+
source: "polyhaven",
|
|
46138
|
+
id: model.id,
|
|
46139
|
+
query,
|
|
46140
|
+
title: model.name,
|
|
46141
|
+
authors: model.authors,
|
|
46142
|
+
license: "cc0",
|
|
46143
|
+
licenseUrl: CC0_URL,
|
|
46144
|
+
landingUrl: model.landingUrl,
|
|
46145
|
+
url: packed.url,
|
|
46146
|
+
size: packed.size,
|
|
46147
|
+
savedAt: savedAt.toISOString()
|
|
46148
|
+
};
|
|
46149
|
+
}
|
|
46150
|
+
async function request(url, send, missing) {
|
|
46151
|
+
let response;
|
|
46152
|
+
try {
|
|
46153
|
+
response = await send(url, { headers: { "User-Agent": `frameboard/${version}` } });
|
|
46154
|
+
} catch (error) {
|
|
46155
|
+
throw new FrameboardError("source-failed", `Poly Haven did not answer: ${error instanceof Error ? error.message : String(error)}`, {
|
|
46156
|
+
source: "polyhaven",
|
|
46157
|
+
status: null
|
|
46158
|
+
});
|
|
46159
|
+
}
|
|
46160
|
+
if (response.status === 404 && missing) throw missing;
|
|
46161
|
+
if (!response.ok) throw new FrameboardError("source-failed", `Poly Haven answered ${response.status}.`, {
|
|
46162
|
+
source: "polyhaven",
|
|
46163
|
+
status: response.status
|
|
46164
|
+
});
|
|
46165
|
+
try {
|
|
46166
|
+
return await response.json();
|
|
46167
|
+
} catch {
|
|
46168
|
+
throw new FrameboardError("source-failed", "Poly Haven answered something other than JSON.", {
|
|
46169
|
+
source: "polyhaven",
|
|
46170
|
+
status: response.status
|
|
46171
|
+
});
|
|
46172
|
+
}
|
|
46173
|
+
}
|
|
46174
|
+
/** Poly Haven's snake_case asset as the record's fields, null for anything but a model with a name. */
|
|
46175
|
+
function toModel(id, raw) {
|
|
46176
|
+
if (!isRecord$2(raw) || raw.type !== MODEL_TYPE) return null;
|
|
46177
|
+
const name = text(raw.name);
|
|
46178
|
+
if (name === null) return null;
|
|
46179
|
+
const largest = Array.isArray(raw.max_resolution) ? Math.max(0, ...raw.max_resolution.filter((each) => typeof each === "number")) : 0;
|
|
46180
|
+
const dimensions = Array.isArray(raw.dimensions) ? raw.dimensions.filter((each) => typeof each === "number") : [];
|
|
46181
|
+
return {
|
|
46182
|
+
id,
|
|
46183
|
+
name,
|
|
46184
|
+
authors: isRecord$2(raw.authors) ? Object.keys(raw.authors) : [],
|
|
46185
|
+
categories: texts(raw.categories),
|
|
46186
|
+
tags: texts(raw.tags),
|
|
46187
|
+
license: "cc0",
|
|
46188
|
+
landingUrl: `${POLYHAVEN_SOURCE.url}/a/${encodeURIComponent(id)}`,
|
|
46189
|
+
thumbnail: text(raw.thumbnail_url),
|
|
46190
|
+
polycount: integer(raw.polycount),
|
|
46191
|
+
dimensionsMm: dimensions.length === 3 ? [
|
|
46192
|
+
dimensions[0] ?? 0,
|
|
46193
|
+
dimensions[1] ?? 0,
|
|
46194
|
+
dimensions[2] ?? 0
|
|
46195
|
+
] : null,
|
|
46196
|
+
sizes: MODEL_SIZES.filter((each) => Number.parseInt(each) * 1024 <= largest),
|
|
46197
|
+
downloadCount: integer(raw.download_count)
|
|
46198
|
+
};
|
|
46199
|
+
}
|
|
46200
|
+
function malformed(id) {
|
|
46201
|
+
return new FrameboardError("source-failed", `Poly Haven's file list for ${id} names no glTF to download.`, {
|
|
46202
|
+
source: "polyhaven",
|
|
46203
|
+
status: null
|
|
46204
|
+
});
|
|
46205
|
+
}
|
|
46206
|
+
function wordsOf(value) {
|
|
46207
|
+
return value.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
46208
|
+
}
|
|
46209
|
+
function isRecord$2(value) {
|
|
46210
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46211
|
+
}
|
|
46212
|
+
function text(value) {
|
|
46213
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
46214
|
+
}
|
|
46215
|
+
function texts(value) {
|
|
46216
|
+
return Array.isArray(value) ? value.filter((each) => typeof each === "string") : [];
|
|
46217
|
+
}
|
|
46218
|
+
function integer(value) {
|
|
46219
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? value : null;
|
|
46220
|
+
}
|
|
44767
46221
|
// src/server/routes/sourcing.ts
|
|
44768
46222
|
/** How long a search waits on Openverse before the panel says it did not answer. */
|
|
44769
46223
|
const FIND_TIMEOUT_MS = 15e3;
|
|
44770
46224
|
/** How long each request of a save, its lookup and its download, may take. */
|
|
44771
46225
|
const SAVE_TIMEOUT_MS = 6e4;
|
|
46226
|
+
/**
|
|
46227
|
+
* How long each request of a model save may take, longer than an image's,
|
|
46228
|
+
* since a model's buffer and textures download before packing.
|
|
46229
|
+
*/
|
|
46230
|
+
const MODEL_SAVE_TIMEOUT_MS = 18e4;
|
|
44772
46231
|
/** How long a provider may take, so a provider that never answers frees the button. */
|
|
44773
46232
|
const GENERATE_TIMEOUT_MS = 12e4;
|
|
44774
46233
|
/** The size the panel asks a provider for, the verb's own default. */
|
|
@@ -44782,6 +46241,10 @@ const saveBodySchema = object$1({
|
|
|
44782
46241
|
query: queryLimit,
|
|
44783
46242
|
credited: boolean$1().default(false)
|
|
44784
46243
|
});
|
|
46244
|
+
const modelSaveBodySchema = object$1({
|
|
46245
|
+
id: string$1().min(1).max(200),
|
|
46246
|
+
query: queryLimit
|
|
46247
|
+
});
|
|
44785
46248
|
const generateBodySchema = object$1({ prompt: string$1().trim().min(1).max(2e3) });
|
|
44786
46249
|
const STATUS = {
|
|
44787
46250
|
usage: 400,
|
|
@@ -44798,11 +46261,12 @@ const STATUS = {
|
|
|
44798
46261
|
* the modules `frameboard image` calls. Finding and the provider's price read
|
|
44799
46262
|
* only; saving and generating need a writer. No answer carries a key.
|
|
44800
46263
|
*/
|
|
44801
|
-
function sourcingRoutes(root, access, { send = (input, init) => fetch(input, init), env = process.env
|
|
46264
|
+
function sourcingRoutes(root, access, { send = (input, init) => fetch(input, init), env = process.env } = {}) {
|
|
44802
46265
|
const app = new Hono();
|
|
44803
46266
|
const authorized = requireWriter(access);
|
|
44804
46267
|
const base = "/api/projects/:project/sourcing";
|
|
44805
46268
|
const saving = /* @__PURE__ */ new Map();
|
|
46269
|
+
const savingModel = /* @__PURE__ */ new Map();
|
|
44806
46270
|
let generating = false;
|
|
44807
46271
|
app.onError((error, c) => answer(error, c));
|
|
44808
46272
|
app.get(`${base}/find`, async (c) => {
|
|
@@ -44839,22 +46303,44 @@ function sourcingRoutes(root, access, { send = (input, init) => fetch(input, ini
|
|
|
44839
46303
|
data: await pending
|
|
44840
46304
|
});
|
|
44841
46305
|
});
|
|
46306
|
+
app.get(`${base}/models`, async (c) => {
|
|
46307
|
+
projectOf$1(root, c.req.param("project"));
|
|
46308
|
+
const query = queryLimit.safeParse(c.req.query("q") ?? "");
|
|
46309
|
+
if (!query.success) throw new FrameboardError("usage", "Send ?q=<what the model shows>, up to 200 characters.");
|
|
46310
|
+
const record = {
|
|
46311
|
+
version: 1,
|
|
46312
|
+
query: query.data,
|
|
46313
|
+
source: { ...POLYHAVEN_SOURCE },
|
|
46314
|
+
results: await searchModels(query.data, timed(send, FIND_TIMEOUT_MS))
|
|
46315
|
+
};
|
|
46316
|
+
return c.json({
|
|
46317
|
+
ok: true,
|
|
46318
|
+
data: record
|
|
46319
|
+
});
|
|
46320
|
+
});
|
|
46321
|
+
app.post(`${base}/models/save`, authorized, async (c) => {
|
|
46322
|
+
const project = projectOf$1(root, c.req.param("project"));
|
|
46323
|
+
const body = await parseBody$1(c.req.raw, modelSaveBodySchema);
|
|
46324
|
+
const key = JSON.stringify([project.name, body.id]);
|
|
46325
|
+
let pending = savingModel.get(key);
|
|
46326
|
+
if (pending === void 0) {
|
|
46327
|
+
pending = saveFoundModel(project, body, timed(send, MODEL_SAVE_TIMEOUT_MS)).finally(() => savingModel.delete(key));
|
|
46328
|
+
savingModel.set(key, pending);
|
|
46329
|
+
}
|
|
46330
|
+
return c.json({
|
|
46331
|
+
ok: true,
|
|
46332
|
+
data: await pending
|
|
46333
|
+
});
|
|
46334
|
+
});
|
|
44842
46335
|
app.get(`${base}/provider`, (c) => {
|
|
44843
46336
|
projectOf$1(root, c.req.param("project"));
|
|
44844
46337
|
return c.json({
|
|
44845
46338
|
ok: true,
|
|
44846
|
-
data: offer(env
|
|
46339
|
+
data: offer(env)
|
|
44847
46340
|
});
|
|
44848
46341
|
});
|
|
44849
46342
|
app.post(`${base}/generate`, authorized, async (c) => {
|
|
44850
46343
|
const project = projectOf$1(root, c.req.param("project"));
|
|
44851
|
-
if (!generate) return c.json({
|
|
44852
|
-
ok: false,
|
|
44853
|
-
error: {
|
|
44854
|
-
code: "generate-off",
|
|
44855
|
-
message: "Generating from the board is off in this release. Run `frameboard image generate` instead."
|
|
44856
|
-
}
|
|
44857
|
-
}, 403);
|
|
44858
46344
|
const { prompt } = await parseBody$1(c.req.raw, generateBodySchema);
|
|
44859
46345
|
if (generating) return c.json({
|
|
44860
46346
|
ok: false,
|
|
@@ -44878,6 +46364,7 @@ function sourcingRoutes(root, access, { send = (input, init) => fetch(input, ini
|
|
|
44878
46364
|
prompt,
|
|
44879
46365
|
...plan.size,
|
|
44880
46366
|
priceUsd: plan.priceUsd,
|
|
46367
|
+
...plan.provider.name === "comfyui" && { seed: plan.seed },
|
|
44881
46368
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
44882
46369
|
});
|
|
44883
46370
|
const record = {
|
|
@@ -44904,8 +46391,16 @@ async function saveFound(project, body, send) {
|
|
|
44904
46391
|
const image = await imageById(body.id, { credited: body.credited }, send);
|
|
44905
46392
|
return saveImage(project, savedStem(void 0, body.query), await downloadImage(image.url, send), foundLicense(image, body.query, /* @__PURE__ */ new Date()));
|
|
44906
46393
|
}
|
|
46394
|
+
async function saveFoundModel(project, body, send) {
|
|
46395
|
+
const model = await modelById(body.id, send);
|
|
46396
|
+
const packed = await fetchModel(model.id, "1k", send);
|
|
46397
|
+
return saveModel(project, savedStem(void 0, body.query, "model"), packed.bytes, polyhavenLicense(model, body.query, {
|
|
46398
|
+
url: packed.url,
|
|
46399
|
+
size: "1k"
|
|
46400
|
+
}, /* @__PURE__ */ new Date()));
|
|
46401
|
+
}
|
|
44907
46402
|
/** The provider a generation would run on and its price, naming each key by its variable alone. */
|
|
44908
|
-
function offer(env
|
|
46403
|
+
function offer(env) {
|
|
44909
46404
|
const keys = PROVIDERS.map((provider) => provider.keyEnv);
|
|
44910
46405
|
try {
|
|
44911
46406
|
const plan = planGeneration({
|
|
@@ -44914,7 +46409,6 @@ function offer(env, enabled) {
|
|
|
44914
46409
|
}, env);
|
|
44915
46410
|
return {
|
|
44916
46411
|
version: 1,
|
|
44917
|
-
enabled,
|
|
44918
46412
|
provider: {
|
|
44919
46413
|
name: plan.provider.name,
|
|
44920
46414
|
model: plan.provider.model,
|
|
@@ -44928,7 +46422,6 @@ function offer(env, enabled) {
|
|
|
44928
46422
|
if (!(error instanceof FrameboardError) || error.code !== "no-provider") throw error;
|
|
44929
46423
|
return {
|
|
44930
46424
|
version: 1,
|
|
44931
|
-
enabled,
|
|
44932
46425
|
provider: null,
|
|
44933
46426
|
keys
|
|
44934
46427
|
};
|
|
@@ -45168,7 +46661,7 @@ const BOARD_ROUTE_RULES = [{
|
|
|
45168
46661
|
id: "board-route",
|
|
45169
46662
|
tier: "exact",
|
|
45170
46663
|
severity: "error",
|
|
45171
|
-
description: "A frame's scripts and event handlers name no path under /api/, which on
|
|
46664
|
+
description: "A frame's scripts and event handlers name no path under /api/, which fails from a frame on its own port, apart from the board's server"
|
|
45172
46665
|
}];
|
|
45173
46666
|
const finding$10 = findingFor(BOARD_ROUTE_RULES);
|
|
45174
46667
|
/**
|
|
@@ -45186,7 +46679,7 @@ function checkBoardRoutes(source) {
|
|
|
45186
46679
|
return finding$10("board-route", {
|
|
45187
46680
|
frame: source.ref,
|
|
45188
46681
|
path: boardPath(source.root, code.path),
|
|
45189
|
-
message: `${code.via} names ${match[2]}, a route of the board's own server, which a frame on
|
|
46682
|
+
message: `${code.via} names ${match[2]}, a route of the board's own server, which fails from a frame on its own port. Mock an app's calls with data kept in the script, or list board-route in the project's checks.off if its frames mean to call /api/.`,
|
|
45190
46683
|
location: start === null ? code.at : locate$1(code.file, start, start + match[0].length)
|
|
45191
46684
|
});
|
|
45192
46685
|
}));
|
|
@@ -46289,12 +47782,12 @@ function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
|
|
|
46289
47782
|
x: 0,
|
|
46290
47783
|
y: 0,
|
|
46291
47784
|
...frame.box
|
|
46292
|
-
}, device), scale);
|
|
47785
|
+
}, device, frame.turn), scale);
|
|
46293
47786
|
const open = await browser.get();
|
|
46294
47787
|
const opened = await openFrame(open, {
|
|
46295
47788
|
baseUrl: baseUrl(),
|
|
46296
47789
|
ref: frame.ref,
|
|
46297
|
-
box: pageSize(frame.box, device),
|
|
47790
|
+
box: pageSize(frame.box, device, frame.turn),
|
|
46298
47791
|
theme,
|
|
46299
47792
|
scale
|
|
46300
47793
|
});
|
|
@@ -46302,7 +47795,7 @@ function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
|
|
|
46302
47795
|
let colors = null;
|
|
46303
47796
|
try {
|
|
46304
47797
|
await hideControls(opened.page);
|
|
46305
|
-
if (topInset(device) > 0) colors = await readPageColors(opened.page);
|
|
47798
|
+
if (topInset(device, frame.turn) > 0) colors = await readPageColors(opened.page);
|
|
46306
47799
|
shot = element === void 0 ? await opened.page.screenshot({
|
|
46307
47800
|
animations: "disabled",
|
|
46308
47801
|
caret: "hide"
|
|
@@ -46314,6 +47807,7 @@ function createWarmRenderer({ baseUrl, browser, scale: defaultScale }) {
|
|
|
46314
47807
|
device,
|
|
46315
47808
|
pose: frame.pose,
|
|
46316
47809
|
island: frame.island,
|
|
47810
|
+
turn: frame.turn,
|
|
46317
47811
|
bar: {
|
|
46318
47812
|
colors,
|
|
46319
47813
|
theme
|
|
@@ -46356,17 +47850,17 @@ async function shootElement(page, ref, index, scale) {
|
|
|
46356
47850
|
* A frame's shot drawn inside a device's body, as the board draws it, on a
|
|
46357
47851
|
* page the size of the body, so the PNG holds the body and nothing past it.
|
|
46358
47852
|
*/
|
|
46359
|
-
async function drawBezel(browser, shot, box, { device, pose = "closed", island = "compact", bar }, scale) {
|
|
47853
|
+
async function drawBezel(browser, shot, box, { device, pose = "closed", island = "compact", turn, bar }, scale) {
|
|
46360
47854
|
const outer = bezelBox({
|
|
46361
47855
|
x: 0,
|
|
46362
47856
|
y: 0,
|
|
46363
47857
|
...box
|
|
46364
|
-
}, device);
|
|
47858
|
+
}, device, turn);
|
|
46365
47859
|
const page = pageBox({
|
|
46366
47860
|
x: 0,
|
|
46367
47861
|
y: 0,
|
|
46368
47862
|
...box
|
|
46369
|
-
}, device);
|
|
47863
|
+
}, device, turn);
|
|
46370
47864
|
const laptop = device === "laptop";
|
|
46371
47865
|
const context = await browser.newContext({
|
|
46372
47866
|
viewport: {
|
|
@@ -46377,9 +47871,10 @@ async function drawBezel(browser, shot, box, { device, pose = "closed", island =
|
|
|
46377
47871
|
});
|
|
46378
47872
|
try {
|
|
46379
47873
|
const tab = await context.newPage();
|
|
46380
|
-
const
|
|
47874
|
+
const sideways = turnOf(turn);
|
|
47875
|
+
const marks = device === "phone" ? sideways === "upright" ? statusBarHtml(bar.colors, bar.theme) + phoneMarks(island) : turnedPhoneMarks(island, sideways) : laptop ? laptopMarks(box) : device === "foldable" ? foldableMarks(pose, sideways) : "";
|
|
46381
47876
|
const radius = screenCorners(device);
|
|
46382
|
-
await tab.setContent(`<!doctype html><html><body style="margin:0;background:transparent"><div style="position:absolute;left:${-outer.x}px;top:${-outer.y}px;width:${box.width}px;height:${box.height}px"><img alt="" src="data:image/png;base64,${shot.toString("base64")}" style="position:absolute;left:0;top:${page.y}px;width:${page.width}px;height:${page.height}px;border-radius:${pageCorners(device)}"><div style="position:absolute;inset:0;border-radius:${radius};box-shadow:${bezelShadow(device, { board: false })}">${marks}</div></div></body></html>`, { waitUntil: "load" });
|
|
47877
|
+
await tab.setContent(`<!doctype html><html><body style="margin:0;background:transparent"><div style="position:absolute;left:${-outer.x}px;top:${-outer.y}px;width:${box.width}px;height:${box.height}px"><img alt="" src="data:image/png;base64,${shot.toString("base64")}" style="position:absolute;left:0;top:${page.y}px;width:${page.width}px;height:${page.height}px;border-radius:${pageCorners(device, turn)}"><div style="position:absolute;inset:0;border-radius:${radius};box-shadow:${bezelShadow(device, { board: false })}">${marks}</div></div></body></html>`, { waitUntil: "load" });
|
|
46383
47878
|
return await tab.screenshot({
|
|
46384
47879
|
omitBackground: true,
|
|
46385
47880
|
caret: "hide"
|
|
@@ -46397,7 +47892,7 @@ async function underStatusBar(browser, shot, box, { colors, theme }, scale) {
|
|
|
46397
47892
|
x: 0,
|
|
46398
47893
|
y: 0,
|
|
46399
47894
|
...box
|
|
46400
|
-
}, "phone");
|
|
47895
|
+
}, "phone", "upright");
|
|
46401
47896
|
const context = await browser.newContext({
|
|
46402
47897
|
viewport: box,
|
|
46403
47898
|
deviceScaleFactor: scale
|
|
@@ -46415,12 +47910,12 @@ function readPageColors(page) {
|
|
|
46415
47910
|
return page.evaluate(pageColors);
|
|
46416
47911
|
}
|
|
46417
47912
|
/** The viewport a frame's page opens at, its box less a phone's status bar, at least one pixel tall. */
|
|
46418
|
-
function pageSize(box, device) {
|
|
47913
|
+
function pageSize(box, device, turn) {
|
|
46419
47914
|
const page = pageBox({
|
|
46420
47915
|
x: 0,
|
|
46421
47916
|
y: 0,
|
|
46422
47917
|
...box
|
|
46423
|
-
}, device);
|
|
47918
|
+
}, device, turn);
|
|
46424
47919
|
return {
|
|
46425
47920
|
width: page.width,
|
|
46426
47921
|
height: Math.max(1, page.height)
|
|
@@ -46452,15 +47947,32 @@ function phoneMarks(island) {
|
|
|
46452
47947
|
const { border } = BEZELS.phone;
|
|
46453
47948
|
const buttons = PHONE_BUTTONS.map(({ side, top, height }) => `<span style="position:absolute;${side}:${-border - 4}px;top:${top - border}px;width:4px;height:${height}px;border-radius:2px;background:${BEZEL_COLORS.button}"></span>`).join("");
|
|
46454
47949
|
const shape = phoneIsland(island);
|
|
46455
|
-
|
|
46456
|
-
|
|
47950
|
+
return buttons + `<span style="${pill(shape.width, shape.height, BEZEL_COLORS.island)}top:${shape.top}px;${ISLAND_TEXT}">${islandTimer(island)}</span><span style="${pill(HOME_BAR.width, HOME_BAR.height, BEZEL_COLORS.homeBar)}bottom:${HOME_BAR.bottom}px"></span>`;
|
|
47951
|
+
}
|
|
47952
|
+
const ISLAND_TEXT = `box-sizing:border-box;display:flex;align-items:center;justify-content:space-between;padding:0 11px;color:${BEZEL_COLORS.islandText};font:600 11px/1 ${STATUS_FONT};font-variant-numeric:tabular-nums`;
|
|
47953
|
+
function islandTimer(island) {
|
|
47954
|
+
if (island !== "wide") return "";
|
|
47955
|
+
return `<span style="display:flex;align-items:center;gap:5px"><span style="width:6px;height:6px;border-radius:3px;background:${BEZEL_COLORS.islandLive}"></span>${WIDE_ISLAND_TIMER}</span><span style="display:flex;align-items:flex-end;gap:2px">${WIDE_ISLAND_LEVEL.map((tall) => `<span style="width:2px;height:${tall}px;border-radius:1px;background:${BEZEL_COLORS.islandLive}"></span>`).join("")}</span>`;
|
|
47956
|
+
}
|
|
47957
|
+
/** A turned phone's island on end and its buttons on the long edges, as the board's bezel draws them. */
|
|
47958
|
+
function turnedPhoneMarks(island, turn) {
|
|
47959
|
+
const { border } = BEZELS.phone;
|
|
47960
|
+
const from = turn === "left" ? "left" : "right";
|
|
47961
|
+
const buttons = PHONE_BUTTONS.map(({ side, top, height }) => {
|
|
47962
|
+
return `<span style="position:absolute;${side === "left" === (turn === "left") ? "bottom" : "top"}:${-border - 4}px;${from}:${top - border}px;width:${height}px;height:4px;border-radius:2px;background:${BEZEL_COLORS.button}"></span>`;
|
|
47963
|
+
}).join("");
|
|
47964
|
+
const shape = phoneIsland(island);
|
|
47965
|
+
const center = shape.top + shape.height / 2;
|
|
47966
|
+
return buttons + `<span style="position:absolute;left:${turn === "left" ? `${center}px` : `calc(100% - ${center}px)`};top:50%;transform:translate(-50%,-50%) rotate(${turn === "left" ? -90 : 90}deg);width:${shape.width}px;height:${shape.height}px;border-radius:${shape.height / 2}px;background:${BEZEL_COLORS.island};${ISLAND_TEXT}">${islandTimer(island)}</span><span style="${pill(HOME_BAR.width, HOME_BAR.height, BEZEL_COLORS.homeBar)}bottom:${HOME_BAR.bottom}px"></span>`;
|
|
46457
47967
|
}
|
|
46458
|
-
/** The foldable's fold band, island, and home bar as the board draws them for a pose. */
|
|
46459
|
-
function foldableMarks(pose) {
|
|
46460
|
-
const band = foldBand(pose);
|
|
47968
|
+
/** The foldable's fold band, island, and home bar as the board draws them for a pose and a turn. */
|
|
47969
|
+
function foldableMarks(pose, turn) {
|
|
47970
|
+
const band = foldBand(pose, turn);
|
|
46461
47971
|
const reach = pose === "half" ? -BEZELS.foldable.border : 0;
|
|
46462
|
-
const
|
|
46463
|
-
|
|
47972
|
+
const place = islandCenter(pose, turn);
|
|
47973
|
+
const { width, height, top } = FOLDABLE_ISLAND;
|
|
47974
|
+
const island = place.edge === "top" ? `${pill(width, height, BEZEL_COLORS.island, place.along)}top:${top}px` : `position:absolute;${place.edge}:${top}px;top:${place.along * 100}%;transform:translateY(-50%);width:${height}px;height:${width}px;border-radius:${height / 2}px;background:${BEZEL_COLORS.island}`;
|
|
47975
|
+
return (!band ? "" : band.runs === "down" ? `<span style="position:absolute;left:50%;transform:translateX(-50%);top:${reach}px;bottom:${reach}px;width:${band.width}px;background:${band.background}"></span>` : `<span style="position:absolute;top:50%;transform:translateY(-50%);left:${reach}px;right:${reach}px;height:${band.width}px;background:${band.background}"></span>`) + `<span style="${island}"></span><span style="${pill(HOME_BAR.width, HOME_BAR.height, BEZEL_COLORS.homeBar)}bottom:${HOME_BAR.bottom}px"></span>`;
|
|
46464
47976
|
}
|
|
46465
47977
|
function pill(width, height, color, center = .5) {
|
|
46466
47978
|
return `position:absolute;left:${center * 100}%;transform:translateX(-50%);width:${width}px;height:${height}px;border-radius:${height / 2}px;background:${color};`;
|
|
@@ -46560,7 +48072,7 @@ async function fitFrame(browser, { baseUrl, frame, ...options }) {
|
|
|
46560
48072
|
const measured = await measureContent(browser, {
|
|
46561
48073
|
baseUrl,
|
|
46562
48074
|
ref: frame.ref,
|
|
46563
|
-
box: pageBox(frame.box, frame.device),
|
|
48075
|
+
box: pageBox(frame.box, frame.device, frame.turn),
|
|
46564
48076
|
hugWidth: false
|
|
46565
48077
|
});
|
|
46566
48078
|
const widths = [];
|
|
@@ -46580,7 +48092,7 @@ async function fitFrame(browser, { baseUrl, frame, ...options }) {
|
|
|
46580
48092
|
});
|
|
46581
48093
|
}
|
|
46582
48094
|
return {
|
|
46583
|
-
frame: await fitHeight(options.root, frame.ref, measured.height + topInset(frame.device), {
|
|
48095
|
+
frame: await fitHeight(options.root, frame.ref, measured.height + topInset(frame.device, frame.turn), {
|
|
46584
48096
|
...options,
|
|
46585
48097
|
widths
|
|
46586
48098
|
}),
|
|
@@ -47498,8 +49010,8 @@ function readConfig(root, project) {
|
|
|
47498
49010
|
} catch {
|
|
47499
49011
|
return {};
|
|
47500
49012
|
}
|
|
47501
|
-
const checks = isRecord$
|
|
47502
|
-
if (!isRecord$
|
|
49013
|
+
const checks = isRecord$1(parsed) ? parsed.checks : void 0;
|
|
49014
|
+
if (!isRecord$1(checks)) return {};
|
|
47503
49015
|
const config = {};
|
|
47504
49016
|
if (Array.isArray(checks.allowedFonts) && checks.allowedFonts.every((font) => typeof font === "string")) config.allowedFonts = checks.allowedFonts;
|
|
47505
49017
|
if (typeof checks.noUppercase === "boolean") config.noUppercase = checks.noUppercase;
|
|
@@ -47508,7 +49020,7 @@ function readConfig(root, project) {
|
|
|
47508
49020
|
if (Array.isArray(checks.off) && checks.off.every((rule) => typeof rule === "string")) config.off = checks.off;
|
|
47509
49021
|
return config;
|
|
47510
49022
|
}
|
|
47511
|
-
function isRecord$
|
|
49023
|
+
function isRecord$1(value) {
|
|
47512
49024
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
47513
49025
|
}
|
|
47514
49026
|
// src/server/checks/outranked.ts
|
|
@@ -47885,7 +49397,8 @@ const frameDeviceSchema = object$1({
|
|
|
47885
49397
|
show: boolean$1().optional(),
|
|
47886
49398
|
foldable: boolean$1().optional(),
|
|
47887
49399
|
pose: _enum$1(POSES).optional(),
|
|
47888
|
-
island: _enum$1(ISLANDS).optional()
|
|
49400
|
+
island: _enum$1(ISLANDS).optional(),
|
|
49401
|
+
turn: _enum$1(TURNS).optional()
|
|
47889
49402
|
});
|
|
47890
49403
|
/** More widths than any device list offers, so a body cannot grow without bound. */
|
|
47891
49404
|
const widthList = array$1(int$1().min(1)).max(64);
|
|
@@ -47954,7 +49467,11 @@ const sectionSchema = object$1({
|
|
|
47954
49467
|
page: ref,
|
|
47955
49468
|
section: name
|
|
47956
49469
|
});
|
|
47957
|
-
const projectAddSchema = object$1({
|
|
49470
|
+
const projectAddSchema = object$1({
|
|
49471
|
+
name: name.optional(),
|
|
49472
|
+
/** The home folder the project starts filed in. */
|
|
49473
|
+
group: name.optional()
|
|
49474
|
+
});
|
|
47958
49475
|
const projectSchema = object$1({ ref });
|
|
47959
49476
|
/** More projects than any board holds, so a body cannot grow without bound. */
|
|
47960
49477
|
const projectRefs$1 = array$1(ref).min(1).max(1e3);
|
|
@@ -48270,7 +49787,8 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
48270
49787
|
journal,
|
|
48271
49788
|
foldable: body.foldable,
|
|
48272
49789
|
pose: body.pose,
|
|
48273
|
-
island: body.island
|
|
49790
|
+
island: body.island,
|
|
49791
|
+
turn: body.turn
|
|
48274
49792
|
}), (records) => records.map((record) => record.ref));
|
|
48275
49793
|
return c.json({
|
|
48276
49794
|
ok: true,
|
|
@@ -48475,8 +49993,12 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
48475
49993
|
frames: []
|
|
48476
49994
|
});
|
|
48477
49995
|
app.post("/api/project/add", async (c) => {
|
|
48478
|
-
const
|
|
48479
|
-
const
|
|
49996
|
+
const body = await parseBody$1(c.req.raw, projectAddSchema);
|
|
49997
|
+
const projectName = body.name ?? nextFreeName("untitled", await listProjects(root));
|
|
49998
|
+
const project = await recorded((journal) => addProject(root, projectName, /* @__PURE__ */ new Date(), {
|
|
49999
|
+
journal,
|
|
50000
|
+
group: body.group
|
|
50001
|
+
}), onHome);
|
|
48480
50002
|
return c.json({
|
|
48481
50003
|
ok: true,
|
|
48482
50004
|
data: project
|
|
@@ -48783,7 +50305,7 @@ function boardHostGuard(port) {
|
|
|
48783
50305
|
await next();
|
|
48784
50306
|
};
|
|
48785
50307
|
}
|
|
48786
|
-
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 }) {
|
|
50308
|
+
function createApp({ clientDir, root, port, framePort, actions, tickets, openRoute, renderFrame, renderFilmstrip, clipboard = null, facesDir, tokens, delivery, dispatch, history, selection, checks, thumbnails, measure, frameVersion, settledVersion, assetUsage, preview }) {
|
|
48787
50309
|
const app = new Hono();
|
|
48788
50310
|
const given = tokens ?? null;
|
|
48789
50311
|
app.use("*", async (c, next) => {
|
|
@@ -48820,7 +50342,13 @@ function createApp({ clientDir, root, port, actions, tickets, openRoute, renderF
|
|
|
48820
50342
|
if (checks) app.route("/", checkRoutes(actions.access, checks));
|
|
48821
50343
|
if (thumbnails) app.route("/", thumbnailRoutes(root, thumbnails));
|
|
48822
50344
|
if (preview) app.route("/", previewRoutes(root, actions.access, preview));
|
|
48823
|
-
app.route("/", frames.
|
|
50345
|
+
app.route("/", frames.lookRoutes);
|
|
50346
|
+
app.on(["GET", "HEAD"], "/frames/*", (c) => {
|
|
50347
|
+
const url = new URL(c.req.url);
|
|
50348
|
+
url.port = String(framePort());
|
|
50349
|
+
return c.redirect(url.href, 307);
|
|
50350
|
+
});
|
|
50351
|
+
app.all("/frames/*", (c) => c.notFound());
|
|
48824
50352
|
app.use("*", serveStatic({ root: clientDir }));
|
|
48825
50353
|
app.get("/p/*", serveStatic({
|
|
48826
50354
|
root: clientDir,
|
|
@@ -48868,7 +50396,7 @@ function firstLine(error) {
|
|
|
48868
50396
|
return message.split("\n").find((line) => line.trim() !== "") ?? message;
|
|
48869
50397
|
}
|
|
48870
50398
|
// src/server/capture/host.ts
|
|
48871
|
-
const HOSTNAME$
|
|
50399
|
+
const HOSTNAME$2 = "127.0.0.1";
|
|
48872
50400
|
/**
|
|
48873
50401
|
* Serves frames on a loopback port for a verb with no server running, through
|
|
48874
50402
|
* the server's own routes, so a capture sees what the board shows.
|
|
@@ -48881,7 +50409,7 @@ async function startFrameHost({ root, facesDir }) {
|
|
|
48881
50409
|
const server = await new Promise((resolve, reject) => {
|
|
48882
50410
|
const created = serve({
|
|
48883
50411
|
fetch: app.fetch,
|
|
48884
|
-
hostname: HOSTNAME$
|
|
50412
|
+
hostname: HOSTNAME$2,
|
|
48885
50413
|
port: 0
|
|
48886
50414
|
}, (info) => {
|
|
48887
50415
|
bound = info.port;
|
|
@@ -48890,7 +50418,7 @@ async function startFrameHost({ root, facesDir }) {
|
|
|
48890
50418
|
created.once("error", reject);
|
|
48891
50419
|
});
|
|
48892
50420
|
return {
|
|
48893
|
-
url: `http://${HOSTNAME$
|
|
50421
|
+
url: `http://${HOSTNAME$2}:${bound}`,
|
|
48894
50422
|
close: () => new Promise((done, fail) => {
|
|
48895
50423
|
server.close((error) => error ? fail(error) : done());
|
|
48896
50424
|
server.closeAllConnections();
|
|
@@ -49084,7 +50612,8 @@ async function captureMotionImages(browser, { baseUrl, frame, themes, out, scale
|
|
|
49084
50612
|
frame: {
|
|
49085
50613
|
ref: frame.ref,
|
|
49086
50614
|
box: view,
|
|
49087
|
-
device: viewDevice(frame, view)
|
|
50615
|
+
device: viewDevice(frame, view),
|
|
50616
|
+
turn: frame.turn
|
|
49088
50617
|
},
|
|
49089
50618
|
theme,
|
|
49090
50619
|
scale,
|
|
@@ -49110,6 +50639,7 @@ async function captureMotionImages(browser, { baseUrl, frame, themes, out, scale
|
|
|
49110
50639
|
ref: frame.ref,
|
|
49111
50640
|
view,
|
|
49112
50641
|
device: viewDevice(frame, view),
|
|
50642
|
+
turn: frame.turn,
|
|
49113
50643
|
theme,
|
|
49114
50644
|
scale,
|
|
49115
50645
|
motionTimeoutMs,
|
|
@@ -49151,6 +50681,7 @@ async function renderFilmstrip(browser, { baseUrl, frame, theme, scale = 1, coun
|
|
|
49151
50681
|
ref: frame.ref,
|
|
49152
50682
|
view,
|
|
49153
50683
|
device: frame.device,
|
|
50684
|
+
turn: frame.turn,
|
|
49154
50685
|
theme,
|
|
49155
50686
|
scale,
|
|
49156
50687
|
motionTimeoutMs,
|
|
@@ -49170,19 +50701,19 @@ async function renderFilmstrip(browser, { baseUrl, frame, theme, scale = 1, coun
|
|
|
49170
50701
|
* Opens one frame with its animation clock held, finds its timeline, and
|
|
49171
50702
|
* shoots it at each moment `moments` picks from what it found.
|
|
49172
50703
|
*/
|
|
49173
|
-
async function holdShots(browser, { baseUrl, ref, view, device, theme, scale, motionTimeoutMs, moments }) {
|
|
50704
|
+
async function holdShots(browser, { baseUrl, ref, view, device, turn, theme, scale, motionTimeoutMs, moments }) {
|
|
49174
50705
|
assertScreenshotFits(ref, view, scale);
|
|
49175
50706
|
const opened = await openFrame(browser, {
|
|
49176
50707
|
baseUrl,
|
|
49177
50708
|
ref,
|
|
49178
|
-
box: pageSize(view, device),
|
|
50709
|
+
box: pageSize(view, device, turn),
|
|
49179
50710
|
theme,
|
|
49180
50711
|
scale,
|
|
49181
50712
|
motion: "hold"
|
|
49182
50713
|
});
|
|
49183
50714
|
try {
|
|
49184
50715
|
const motion = await findMotion(opened.page, ref, motionTimeoutMs);
|
|
49185
|
-
const colors = topInset(device) > 0 ? await readPageColors(opened.page) : null;
|
|
50716
|
+
const colors = topInset(device, turn) > 0 ? await readPageColors(opened.page) : null;
|
|
49186
50717
|
const held = [];
|
|
49187
50718
|
for (const moment of moments(motion)) {
|
|
49188
50719
|
const at = await seekMotion(opened.page, motion, moment);
|
|
@@ -49222,7 +50753,7 @@ async function renderFrame(browser, baseUrl, frame, view, theme, scale, scroll)
|
|
|
49222
50753
|
const opened = await openFrame(browser, {
|
|
49223
50754
|
baseUrl,
|
|
49224
50755
|
ref: frame.ref,
|
|
49225
|
-
box: pageSize(box, device),
|
|
50756
|
+
box: pageSize(box, device, frame.turn),
|
|
49226
50757
|
theme,
|
|
49227
50758
|
scale
|
|
49228
50759
|
});
|
|
@@ -49230,7 +50761,7 @@ async function renderFrame(browser, baseUrl, frame, view, theme, scale, scroll)
|
|
|
49230
50761
|
const scrollY = scroll === void 0 ? void 0 : await opened.page.evaluate(scrollAndSettle, scroll);
|
|
49231
50762
|
const shot = await opened.page.screenshot(SCREENSHOT);
|
|
49232
50763
|
return {
|
|
49233
|
-
bytes: topInset(device) > 0 ? await underStatusBar(browser, shot, box, {
|
|
50764
|
+
bytes: topInset(device, frame.turn) > 0 ? await underStatusBar(browser, shot, box, {
|
|
49234
50765
|
colors: await readPageColors(opened.page),
|
|
49235
50766
|
theme
|
|
49236
50767
|
}, scale) : shot,
|
|
@@ -49460,7 +50991,7 @@ async function requestBoard(address, path, init, timeoutMs = REQUEST_TIMEOUT_MS)
|
|
|
49460
50991
|
}
|
|
49461
50992
|
const envelope = await response.json().catch(() => null);
|
|
49462
50993
|
const refusal = envelope?.error;
|
|
49463
|
-
if (!response.ok && isErrorCode(refusal?.code) && typeof refusal?.message === "string") throw new FrameboardError(refusal.code, refusal.message, isRecord
|
|
50994
|
+
if (!response.ok && isErrorCode(refusal?.code) && typeof refusal?.message === "string") throw new FrameboardError(refusal.code, refusal.message, isRecord(refusal.details) ? refusal.details : {});
|
|
49464
50995
|
if (!response.ok || !envelope) throw new FrameboardError("internal", `The frameboard server at ${address.url} refused ${path} with ${response.status}.`, {
|
|
49465
50996
|
url: address.url,
|
|
49466
50997
|
status: response.status
|
|
@@ -49470,7 +51001,7 @@ async function requestBoard(address, path, init, timeoutMs = REQUEST_TIMEOUT_MS)
|
|
|
49470
51001
|
function isErrorCode(code) {
|
|
49471
51002
|
return typeof code === "string" && Object.hasOwn(EXIT_CODES, code);
|
|
49472
51003
|
}
|
|
49473
|
-
function isRecord
|
|
51004
|
+
function isRecord(value) {
|
|
49474
51005
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
49475
51006
|
}
|
|
49476
51007
|
// src/cli/commands/check.ts
|
|
@@ -49648,6 +51179,11 @@ const frameRecordSchema = object$1({
|
|
|
49648
51179
|
pose: _enum$1(POSES).optional(),
|
|
49649
51180
|
/** `wide` while the frame picks the phone's wide island, shown or not, absent for the compact one. */
|
|
49650
51181
|
island: literal("wide").optional(),
|
|
51182
|
+
/**
|
|
51183
|
+
* The way a phone, tablet, or foldable frame is turned, shown or not, absent upright.
|
|
51184
|
+
* A turned frame's box is landscape, and a turned phone draws no status bar.
|
|
51185
|
+
*/
|
|
51186
|
+
turn: _enum$1(["left", "right"]).optional(),
|
|
49651
51187
|
/** The transition the frame arrives with in present mode, over its page's, absent when it holds none. */
|
|
49652
51188
|
transition: transitionRecordSchema.optional(),
|
|
49653
51189
|
/** What the presenter means to say over the slide, plain text with its line breaks, absent when it holds none. */
|
|
@@ -50211,310 +51747,105 @@ const RECORDS = {
|
|
|
50211
51747
|
imageGenerate: imageGenerateSchema,
|
|
50212
51748
|
imageDoctor: imageDoctorSchema,
|
|
50213
51749
|
modelFind: modelFindSchema,
|
|
51750
|
+
modelGenerate: modelGenerateSchema,
|
|
50214
51751
|
savedModel: savedModelSchema
|
|
50215
51752
|
};
|
|
50216
|
-
// src/server/sourcing/
|
|
50217
|
-
|
|
50218
|
-
const
|
|
50219
|
-
|
|
50220
|
-
const
|
|
50221
|
-
|
|
50222
|
-
|
|
50223
|
-
|
|
50224
|
-
|
|
50225
|
-
|
|
50226
|
-
|
|
50227
|
-
|
|
50228
|
-
|
|
50229
|
-
|
|
50230
|
-
|
|
50231
|
-
|
|
50232
|
-
|
|
50233
|
-
|
|
50234
|
-
const
|
|
50235
|
-
if (
|
|
50236
|
-
const
|
|
50237
|
-
|
|
50238
|
-
|
|
50239
|
-
|
|
50240
|
-
|
|
50241
|
-
|
|
50242
|
-
|
|
50243
|
-
|
|
50244
|
-
|
|
50245
|
-
|
|
51753
|
+
// src/server/sourcing/generate-model.ts
|
|
51754
|
+
/** The environment variable naming the ComfyUI server a model is made on. */
|
|
51755
|
+
const COMFYUI_URL_ENV = "FRAMEBOARD_COMFYUI_URL";
|
|
51756
|
+
/** The model the bundled workflow runs, named by its file as the image provider names FLUX.2 klein. */
|
|
51757
|
+
const BUNDLED_MODEL = "pixal3d-int8-convrot";
|
|
51758
|
+
/**
|
|
51759
|
+
* The picture at `path`, read from `cwd`, the project, or its `assets/`, carrying a project asset's license forward.
|
|
51760
|
+
* Refuses `usage` for no file, or a file whose bytes are no PNG, JPEG, WebP, or GIF.
|
|
51761
|
+
*/
|
|
51762
|
+
async function readPicture(path, cwd, project) {
|
|
51763
|
+
const assets = join(project.path, ASSETS_FOLDER);
|
|
51764
|
+
const found = await firstFile(isAbsolute(path) ? [path] : [
|
|
51765
|
+
resolve$1(cwd, path),
|
|
51766
|
+
resolve$1(project.path, path),
|
|
51767
|
+
resolve$1(assets, path)
|
|
51768
|
+
]);
|
|
51769
|
+
if (found === null) throw new FrameboardError("usage", `No picture at ${path}, read from here, the project, or its ${ASSETS_FOLDER}/.`, { picture: path });
|
|
51770
|
+
const bytes = new Uint8Array(await readFile(found));
|
|
51771
|
+
const name = basename(found);
|
|
51772
|
+
if (!isPicture(bytes)) throw new FrameboardError("usage", `${name} is not a PNG, JPEG, WebP, or GIF picture, so there is nothing to make a model from.`, { picture: name });
|
|
51773
|
+
const inAssets = relative(assets, found);
|
|
51774
|
+
return {
|
|
51775
|
+
bytes,
|
|
51776
|
+
name,
|
|
51777
|
+
source: inAssets !== "" && !inAssets.startsWith("..") && !isAbsolute(inAssets) ? {
|
|
51778
|
+
path: inAssets.split(sep).join("/"),
|
|
51779
|
+
inAssets: true,
|
|
51780
|
+
license: await pictureLicense(found)
|
|
51781
|
+
} : {
|
|
51782
|
+
path: name,
|
|
51783
|
+
inAssets: false,
|
|
51784
|
+
license: null
|
|
51785
|
+
}
|
|
50246
51786
|
};
|
|
50247
|
-
const buffer = buffers[0];
|
|
50248
|
-
if (buffer !== void 0) {
|
|
50249
|
-
const declared = buffer.byteLength;
|
|
50250
|
-
if (typeof declared !== "number") throw refused("The glTF buffer states no byteLength.");
|
|
50251
|
-
const bytes = fileFor(buffer.uri, files);
|
|
50252
|
-
if (bytes.byteLength < declared) throw refused(`The buffer holds ${bytes.byteLength} bytes, short of the ${declared} the glTF states.`);
|
|
50253
|
-
append(bytes.subarray(0, declared));
|
|
50254
|
-
}
|
|
50255
|
-
const packedViews = [...listOf(gltf.bufferViews)];
|
|
50256
|
-
const images = listOf(gltf.images).map((image) => {
|
|
50257
|
-
if (image.uri === void 0) return image;
|
|
50258
|
-
const bytes = fileFor(image.uri, files);
|
|
50259
|
-
const mimeType = mimeTypeOf(image);
|
|
50260
|
-
const byteOffset = append(bytes);
|
|
50261
|
-
packedViews.push({
|
|
50262
|
-
buffer: 0,
|
|
50263
|
-
byteOffset,
|
|
50264
|
-
byteLength: bytes.byteLength
|
|
50265
|
-
});
|
|
50266
|
-
const { uri: _uri, ...rest } = image;
|
|
50267
|
-
return {
|
|
50268
|
-
...rest,
|
|
50269
|
-
bufferView: packedViews.length - 1,
|
|
50270
|
-
mimeType
|
|
50271
|
-
};
|
|
50272
|
-
});
|
|
50273
|
-
const json = { ...gltf };
|
|
50274
|
-
delete json.buffers;
|
|
50275
|
-
delete json.bufferViews;
|
|
50276
|
-
if (length > 0) json.buffers = [{ byteLength: length }];
|
|
50277
|
-
if (packedViews.length > 0) json.bufferViews = packedViews;
|
|
50278
|
-
if (gltf.images !== void 0) json.images = images;
|
|
50279
|
-
return container(json, parts, length);
|
|
50280
51787
|
}
|
|
50281
|
-
function container(json, parts, binLength) {
|
|
50282
|
-
const text = new TextEncoder().encode(JSON.stringify(json));
|
|
50283
|
-
const jsonLength = align(text.byteLength);
|
|
50284
|
-
const binChunk = binLength === 0 ? 0 : CHUNK_HEADER_BYTES + binLength;
|
|
50285
|
-
const total = 20 + jsonLength + binChunk;
|
|
50286
|
-
const glb = new Uint8Array(total);
|
|
50287
|
-
const view = new DataView(glb.buffer);
|
|
50288
|
-
view.setUint32(0, GLB_MAGIC, true);
|
|
50289
|
-
view.setUint32(4, GLB_VERSION, true);
|
|
50290
|
-
view.setUint32(8, total, true);
|
|
50291
|
-
view.setUint32(12, jsonLength, true);
|
|
50292
|
-
view.setUint32(16, JSON_CHUNK, true);
|
|
50293
|
-
glb.set(text, 20);
|
|
50294
|
-
glb.fill(32, 20 + text.byteLength, 20 + jsonLength);
|
|
50295
|
-
if (binChunk === 0) return glb;
|
|
50296
|
-
const binStart = 20 + jsonLength;
|
|
50297
|
-
view.setUint32(binStart, binLength, true);
|
|
50298
|
-
view.setUint32(binStart + 4, BIN_CHUNK, true);
|
|
50299
|
-
const dataStart = binStart + CHUNK_HEADER_BYTES;
|
|
50300
|
-
for (const part of parts) glb.set(part.bytes, dataStart + part.offset);
|
|
50301
|
-
return glb;
|
|
50302
|
-
}
|
|
50303
|
-
function fileFor(uri, files) {
|
|
50304
|
-
if (typeof uri !== "string" || uri === "") throw refused("The glTF names a buffer or image with no uri.");
|
|
50305
|
-
if (uri.startsWith("data:")) throw refused("The glTF carries a data URI, which this packer does not read.");
|
|
50306
|
-
const bytes = files.get(uri) ?? files.get(safeDecode(uri));
|
|
50307
|
-
if (bytes === void 0) throw refused(`The glTF names ${uri}, which was not downloaded.`);
|
|
50308
|
-
return bytes;
|
|
50309
|
-
}
|
|
50310
|
-
function mimeTypeOf(image) {
|
|
50311
|
-
if (typeof image.mimeType === "string") {
|
|
50312
|
-
if (Object.values(IMAGE_TYPES).includes(image.mimeType)) return image.mimeType;
|
|
50313
|
-
throw refused(`The glTF names a texture of type ${image.mimeType}.`);
|
|
50314
|
-
}
|
|
50315
|
-
const uri = String(image.uri);
|
|
50316
|
-
const extension = uri.slice(uri.lastIndexOf(".") + 1).toLowerCase();
|
|
50317
|
-
const type = IMAGE_TYPES[extension];
|
|
50318
|
-
if (type === void 0) throw refused(`The texture ${uri} is neither JPEG nor PNG.`);
|
|
50319
|
-
return type;
|
|
50320
|
-
}
|
|
50321
|
-
function listOf(value) {
|
|
50322
|
-
return Array.isArray(value) ? value.filter((each) => typeof each === "object" && each !== null) : [];
|
|
50323
|
-
}
|
|
50324
|
-
function safeDecode(uri) {
|
|
50325
|
-
try {
|
|
50326
|
-
return decodeURIComponent(uri);
|
|
50327
|
-
} catch {
|
|
50328
|
-
return uri;
|
|
50329
|
-
}
|
|
50330
|
-
}
|
|
50331
|
-
function align(length) {
|
|
50332
|
-
return Math.ceil(length / 4) * 4;
|
|
50333
|
-
}
|
|
50334
|
-
function refused(message) {
|
|
50335
|
-
return new FrameboardError("source-failed", message, { source: "polyhaven" });
|
|
50336
|
-
}
|
|
50337
|
-
// src/server/sourcing/polyhaven.ts
|
|
50338
|
-
const POLYHAVEN_API = "https://api.polyhaven.com/";
|
|
50339
|
-
/** Named on every listing, which Poly Haven's API terms ask of any surface showing its content. */
|
|
50340
|
-
const POLYHAVEN_SOURCE = {
|
|
50341
|
-
name: "Poly Haven",
|
|
50342
|
-
url: "https://polyhaven.com"
|
|
50343
|
-
};
|
|
50344
|
-
const CC0_URL = "https://creativecommons.org/publicdomain/zero/1.0/";
|
|
50345
|
-
/** Poly Haven's `type` for a model, beside 0 for an HDRI and 1 for a texture. */
|
|
50346
|
-
const MODEL_TYPE = 2;
|
|
50347
51788
|
/**
|
|
50348
|
-
*
|
|
50349
|
-
*
|
|
50350
|
-
*
|
|
51789
|
+
* The server, model, and seed a generation runs with, making no request.
|
|
51790
|
+
* Refuses `no-provider` naming `FRAMEBOARD_COMFYUI_URL` while it is unset or
|
|
51791
|
+
* empty, since a model runs on the developer's own server alone.
|
|
50351
51792
|
*/
|
|
50352
|
-
|
|
50353
|
-
const
|
|
50354
|
-
|
|
50355
|
-
|
|
50356
|
-
|
|
50357
|
-
|
|
50358
|
-
|
|
50359
|
-
|
|
50360
|
-
|
|
50361
|
-
|
|
50362
|
-
].flatMap(wordsOf));
|
|
50363
|
-
return {
|
|
50364
|
-
model,
|
|
50365
|
-
score: [...words].filter((word) => own.has(word)).length
|
|
50366
|
-
};
|
|
50367
|
-
}).filter(({ score }) => score > 0);
|
|
50368
|
-
scored.sort((a, b) => b.score - a.score || (b.model.downloadCount ?? 0) - (a.model.downloadCount ?? 0) || a.model.id.localeCompare(b.model.id));
|
|
50369
|
-
return scored.slice(0, 20).map(({ model }, index) => ({
|
|
50370
|
-
number: index + 1,
|
|
50371
|
-
...model
|
|
50372
|
-
}));
|
|
50373
|
-
}
|
|
50374
|
-
/**
|
|
50375
|
-
* One model by its Poly Haven id, refusing `result-not-found` for an id
|
|
50376
|
-
* Poly Haven does not hold or one naming a texture or an HDRI.
|
|
50377
|
-
*/
|
|
50378
|
-
async function modelById(id, send) {
|
|
50379
|
-
const missing = new FrameboardError("result-not-found", `Poly Haven holds no model ${id}.`, { id });
|
|
50380
|
-
const model = toModel(id, await request(new URL(`info/${encodeURIComponent(id)}`, POLYHAVEN_API), send, missing));
|
|
50381
|
-
if (model === null) throw missing;
|
|
50382
|
-
return model;
|
|
51793
|
+
function planModelGeneration(request, env, random = Math.random) {
|
|
51794
|
+
const server = env[COMFYUI_URL_ENV]?.trim();
|
|
51795
|
+
if (server === void 0 || server === "") throw new FrameboardError("no-provider", `No ComfyUI server is set. Set ${COMFYUI_URL_ENV} in the environment, and run frameboard image doctor for the files Pixal3D needs.`, { keys: [COMFYUI_URL_ENV] });
|
|
51796
|
+
return {
|
|
51797
|
+
server,
|
|
51798
|
+
model: request.workflow ? basename(request.workflow.name) : BUNDLED_MODEL,
|
|
51799
|
+
picture: request.picture,
|
|
51800
|
+
seed: Math.floor(random() * Number.MAX_SAFE_INTEGER),
|
|
51801
|
+
...request.workflow && { workflow: request.workflow }
|
|
51802
|
+
};
|
|
50383
51803
|
}
|
|
50384
51804
|
/**
|
|
50385
|
-
*
|
|
50386
|
-
* one
|
|
50387
|
-
*
|
|
51805
|
+
* Uploads the picture, runs the workflow on it, and answers the GLB's bytes,
|
|
51806
|
+
* the one point a generation reaches the server. Refuses `provider-failed`
|
|
51807
|
+
* on any failure the client reports.
|
|
50388
51808
|
*/
|
|
50389
|
-
async function
|
|
50390
|
-
const
|
|
50391
|
-
|
|
50392
|
-
|
|
50393
|
-
|
|
50394
|
-
|
|
50395
|
-
|
|
50396
|
-
|
|
50397
|
-
const entry = entryAt(size);
|
|
50398
|
-
if (sizes.length === 0) throw new FrameboardError("source-failed", `Poly Haven serves ${id} as no glTF, so it cannot be saved as a GLB.`, {
|
|
50399
|
-
source: "polyhaven",
|
|
50400
|
-
id,
|
|
50401
|
-
status: null
|
|
50402
|
-
});
|
|
50403
|
-
if (entry === null) throw new FrameboardError("usage", `Poly Haven serves ${id} at ${sizes.join(", ")}, not ${size}.`, {
|
|
50404
|
-
id,
|
|
50405
|
-
size,
|
|
50406
|
-
sizes
|
|
51809
|
+
async function generateModel(plan, send) {
|
|
51810
|
+
const image = await uploadImage(plan.server, {
|
|
51811
|
+
name: plan.picture.name,
|
|
51812
|
+
bytes: plan.picture.bytes
|
|
51813
|
+
}, send);
|
|
51814
|
+
const graph = fillWorkflow(plan.workflow?.graph ?? BUNDLED_MODEL_WORKFLOW, {
|
|
51815
|
+
image,
|
|
51816
|
+
seed: plan.seed
|
|
50407
51817
|
});
|
|
50408
|
-
|
|
50409
|
-
if (gltfUrl === null) throw malformed(id);
|
|
50410
|
-
const includes = Object.entries(isRecord(entry.include) ? entry.include : {});
|
|
50411
|
-
const [main, ...files] = await Promise.all([download(gltfUrl, send), ...includes.map(([, file]) => {
|
|
50412
|
-
const fileUrl = isRecord(file) ? text(file.url) : null;
|
|
50413
|
-
if (fileUrl === null) throw malformed(id);
|
|
50414
|
-
return download(fileUrl, send);
|
|
50415
|
-
})]);
|
|
50416
|
-
let json;
|
|
50417
|
-
try {
|
|
50418
|
-
json = JSON.parse(new TextDecoder().decode(main?.bytes));
|
|
50419
|
-
} catch {
|
|
50420
|
-
throw malformed(id);
|
|
50421
|
-
}
|
|
50422
|
-
if (!isRecord(json)) throw malformed(id);
|
|
50423
|
-
const byUri = new Map(includes.map(([uri], index) => [uri, files[index]?.bytes ?? /* @__PURE__ */ new Uint8Array()]));
|
|
50424
|
-
return {
|
|
50425
|
-
bytes: packGlb(json, byUri),
|
|
50426
|
-
url: gltfUrl
|
|
50427
|
-
};
|
|
51818
|
+
return runModelWorkflow(plan.server, graph, send);
|
|
50428
51819
|
}
|
|
50429
|
-
|
|
50430
|
-
|
|
50431
|
-
return
|
|
50432
|
-
version: 1,
|
|
50433
|
-
origin: "found",
|
|
50434
|
-
source: "polyhaven",
|
|
50435
|
-
id: model.id,
|
|
50436
|
-
query,
|
|
50437
|
-
title: model.name,
|
|
50438
|
-
authors: model.authors,
|
|
50439
|
-
license: "cc0",
|
|
50440
|
-
licenseUrl: CC0_URL,
|
|
50441
|
-
landingUrl: model.landingUrl,
|
|
50442
|
-
url: packed.url,
|
|
50443
|
-
size: packed.size,
|
|
50444
|
-
savedAt: savedAt.toISOString()
|
|
50445
|
-
};
|
|
51820
|
+
async function firstFile(paths) {
|
|
51821
|
+
for (const path of paths) if ((await stat(path).catch(() => null))?.isFile()) return path;
|
|
51822
|
+
return null;
|
|
50446
51823
|
}
|
|
50447
|
-
|
|
50448
|
-
|
|
50449
|
-
|
|
50450
|
-
|
|
50451
|
-
|
|
50452
|
-
|
|
50453
|
-
|
|
50454
|
-
|
|
50455
|
-
|
|
50456
|
-
|
|
50457
|
-
if (response.status === 404 && missing) throw missing;
|
|
50458
|
-
if (!response.ok) throw new FrameboardError("source-failed", `Poly Haven answered ${response.status}.`, {
|
|
50459
|
-
source: "polyhaven",
|
|
50460
|
-
status: response.status
|
|
50461
|
-
});
|
|
51824
|
+
/** True for the leading bytes of a PNG, JPEG, WebP, or GIF, the pictures ComfyUI's LoadImage reads. */
|
|
51825
|
+
function isPicture(bytes) {
|
|
51826
|
+
const starts = (offset, text) => [...text].every((char, at) => bytes[offset + at] === char.charCodeAt(0));
|
|
51827
|
+
return starts(0, "PNG") || bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255 || starts(0, "RIFF") && starts(8, "WEBP") || starts(0, "GIF8");
|
|
51828
|
+
}
|
|
51829
|
+
/** The picture's own license file's origin and license name, null when it has none or one that does not parse. */
|
|
51830
|
+
async function pictureLicense(path) {
|
|
51831
|
+
const text = await readFile(`${path}${LICENSE_FILE_SUFFIX}`, "utf8").catch(() => null);
|
|
51832
|
+
if (text === null) return null;
|
|
51833
|
+
let parsed;
|
|
50462
51834
|
try {
|
|
50463
|
-
|
|
51835
|
+
parsed = JSON.parse(text);
|
|
50464
51836
|
} catch {
|
|
50465
|
-
|
|
50466
|
-
source: "polyhaven",
|
|
50467
|
-
status: response.status
|
|
50468
|
-
});
|
|
51837
|
+
return null;
|
|
50469
51838
|
}
|
|
50470
|
-
|
|
50471
|
-
|
|
50472
|
-
|
|
50473
|
-
|
|
50474
|
-
|
|
50475
|
-
|
|
50476
|
-
|
|
50477
|
-
|
|
50478
|
-
return {
|
|
50479
|
-
id,
|
|
50480
|
-
name,
|
|
50481
|
-
authors: isRecord(raw.authors) ? Object.keys(raw.authors) : [],
|
|
50482
|
-
categories: texts(raw.categories),
|
|
50483
|
-
tags: texts(raw.tags),
|
|
50484
|
-
license: "cc0",
|
|
50485
|
-
landingUrl: `${POLYHAVEN_SOURCE.url}/a/${encodeURIComponent(id)}`,
|
|
50486
|
-
thumbnail: text(raw.thumbnail_url),
|
|
50487
|
-
polycount: integer(raw.polycount),
|
|
50488
|
-
dimensionsMm: dimensions.length === 3 ? [
|
|
50489
|
-
dimensions[0] ?? 0,
|
|
50490
|
-
dimensions[1] ?? 0,
|
|
50491
|
-
dimensions[2] ?? 0
|
|
50492
|
-
] : null,
|
|
50493
|
-
sizes: MODEL_SIZES.filter((each) => Number.parseInt(each) * 1024 <= largest),
|
|
50494
|
-
downloadCount: integer(raw.download_count)
|
|
51839
|
+
const license = licenseFileSchema.safeParse(parsed);
|
|
51840
|
+
if (!license.success) return null;
|
|
51841
|
+
return license.data.origin === "found" ? {
|
|
51842
|
+
origin: "found",
|
|
51843
|
+
license: license.data.license
|
|
51844
|
+
} : {
|
|
51845
|
+
origin: "generated",
|
|
51846
|
+
license: null
|
|
50495
51847
|
};
|
|
50496
51848
|
}
|
|
50497
|
-
function malformed(id) {
|
|
50498
|
-
return new FrameboardError("source-failed", `Poly Haven's file list for ${id} names no glTF to download.`, {
|
|
50499
|
-
source: "polyhaven",
|
|
50500
|
-
status: null
|
|
50501
|
-
});
|
|
50502
|
-
}
|
|
50503
|
-
function wordsOf(value) {
|
|
50504
|
-
return value.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
50505
|
-
}
|
|
50506
|
-
function isRecord(value) {
|
|
50507
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
50508
|
-
}
|
|
50509
|
-
function text(value) {
|
|
50510
|
-
return typeof value === "string" && value !== "" ? value : null;
|
|
50511
|
-
}
|
|
50512
|
-
function texts(value) {
|
|
50513
|
-
return Array.isArray(value) ? value.filter((each) => typeof each === "string") : [];
|
|
50514
|
-
}
|
|
50515
|
-
function integer(value) {
|
|
50516
|
-
return typeof value === "number" && Number.isSafeInteger(value) ? value : null;
|
|
50517
|
-
}
|
|
50518
51849
|
// src/cli/docs/content-format.ts
|
|
50519
51850
|
/** The content format `docs` prints, built from the constants the verbs run on. */
|
|
50520
51851
|
function contentFormat() {
|
|
@@ -50544,6 +51875,7 @@ function contentFormat() {
|
|
|
50544
51875
|
`showDevice true has the board draw the frame inside the device its width names: a phone from 320 to 479 px wide, a tablet from 480 to 1023, and a laptop from 1024 up, with none under 320. The phone's body stands ${BEZELS.phone.border} px past the box on every side, with side buttons 4 px past that, and the tablet's ${BEZELS.tablet.border}, and the laptop's lid ${BEZELS.laptop.border} px past its top and sides, with a chin and a wider base below. A resize redraws the body with no write, and list reports the device the width names as device, absent when off or under 320. It never changes the frame file, its size, or its box. frame add, frame duplicate, and a paste place a frame beside another with its own body, a laptop's base included, 80 px past the other's body. A frame given --x keeps that x, a frame landing in a reserved box keeps that box with no room for a device, and a placed frame stays where it stands when its device turns on. Linked widths draw no device. Any other value of showDevice reads as off and is kept on write. A device string from before showDevice reads as on, and the entry's next write replaces it with showDevice. frame add --device on and frame device <frame-ref> <on|off> set it, taking phone and tablet as on and none as off.`,
|
|
50545
51876
|
`While a phone shows, the board draws a status bar over the top ${STATUS_BAR.height} px of the frame's box, in the page's own fill and text color, and the page starts under it: a frame ${FRAME_SIZES.phone.width} by ${FRAME_SIZES.phone.height} shows a page ${FRAME_SIZES.phone.width} by ${FRAME_SIZES.phone.height - STATUS_BAR.height}. The box in layout.json keeps the screen's size, and the frame file gains no padding. A hugging height measures the page and stores it plus the bar, frame fit does the same, and capture, check, inspect, and present each read the page under the bar. An export draws the bar only with its device included, and lays the page out at the whole box without it. A linked width draws no device and no bar. With the device off, or on any other device, the page is the whole box.`,
|
|
50546
51877
|
`island wide has a phone draw its wide island, the one a call or a timer shows, and absent draws the compact one. It is kept while the device is off and reads as compact on any other device. Any other value reads as compact and is kept on write. frame device <frame-ref> --island wide sets it, --island compact clears it, and both refuse a frame whose width names no phone or that names the foldable.`,
|
|
51878
|
+
`turn left or right turns a phone, a tablet, or a foldable a quarter, with the island on the left side for left and the right for right, and absent stands it upright. A phone's or a tablet's first turn keeps the box's upright width and height in upright, and the upright width still picks the device, so a turned phone reads as a phone however wide its box. A fixed or scroll box swaps its sides, and a hugging one takes the reference height of its upright width, ${FRAME_SIZES.phone.height} px for a phone, and hugs its height at that width. A turned phone draws no status bar, so its page is the whole box, and its buttons stand on its long edges. list reports turn while the frame is turned, shown or not, and never upright. Turning upright restores the kept size, even after a hand resize of the turned box. A turned foldable keeps no upright, since its pose gives its screen: its box is that screen with the sides swapped, ${POSE_SIZES.closed.height} by ${POSE_SIZES.closed.width} closed and ${POSE_SIZES.open.height} by ${POSE_SIZES.open.width} half or open, its island sits where the quarter turn puts it, and its fold runs across the screen. A fold keeps the turn and takes the new pose's swapped screen, upright restores the pose's screen, and --no-foldable stands it upright at that screen. frame device <frame-ref> --turn <upright|left|right> sets it, writing the layout entry alone, and a quarter turn refuses a laptop, a frame showing no device, and a frame holding extra widths, each with usage. A turned frame refuses new extra widths, and naming a turned phone or tablet the foldable stands it upright first. A phone's or a tablet's turn with no readable upright, or a value no reader knows, reads as upright.`,
|
|
50547
51879
|
`foldable true has the frame name the foldable device over the one its width picks, and pose folds it: closed is the cover screen at ${POSE_SIZES.closed.width} by ${POSE_SIZES.closed.height}, and half and open are the inner screen at ${POSE_SIZES.open.width} by ${POSE_SIZES.open.height}, half shading the fold. Naming a foldable or setting a pose sets the box's width and height to that screen and turns both hug flags off, and writes the layout entry alone, never the frame file, so one file shows every pose and its content reflows as on the device. The body stands ${BEZELS.foldable.border} px past the box on every side. A newly named foldable starts in the pose nearest its width, closed up to 678 px wide and open past it. list reports device as foldable while it shows, and pose on every frame naming one, shown or not. With showDevice off the box keeps its pose's size and no body draws. A foldable draws no linked width and refuses a new one, and widths its entry held from before stay in the file undrawn, draw again once --no-foldable un-names it, and clear on frame resize --no-widths. Any other value of foldable reads as width-picked, a pose no reader knows reads as closed, and both are kept on write. An older Frameboard rewriting the entry may drop both keys, leaving a width-picked frame at the pose's size. frame device <frame-ref> --foldable names it and shows it, --pose <closed|half|open> folds it, and --no-foldable hands the pick back to the width at the size it stands.`,
|
|
50548
51880
|
`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.`,
|
|
50549
51881
|
"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.",
|
|
@@ -50576,9 +51908,10 @@ function contentFormat() {
|
|
|
50576
51908
|
],
|
|
50577
51909
|
images: [
|
|
50578
51910
|
`image find searches Openverse under ${DEFAULT_LICENSES.join(", ")} alone, and --credited widens it to ${CREDITED_LICENSES.join(", ")}. It lists up to 20 results numbered from 1 and writes nothing. --save <number> runs the search again and saves that result, and --save <id> saves the Openverse image with that id with no search, refusing result-not-found for an id under a license the flags do not allow. Openverse allows an address 200 anonymous requests a day, so save by id.`,
|
|
50579
|
-
`image generate runs on the provider --provider names, else the first whose key is set, in the order ${PROVIDERS.map((each) => `${each.name} (${each.model}, ${each.keyEnv})`).join(", ")}. A key set to an empty string reads as unset. priceUsd is the estimate before the call, and --dry-run answers it with saved null and makes no request. Without --dry-run the call spends on that key at once, since no verb prompts. No ready provider refuses no-provider with the keys in the details, and a failed call refuses provider-failed with the provider's status and never the key.`,
|
|
51911
|
+
`image generate runs on the provider --provider names, else the first whose key is set, in the order ${PROVIDERS.map((each) => `${each.name} (${each.model}, ${each.keyEnv})`).join(", ")}. A key set to an empty string reads as unset. comfyui's key is the address of a ComfyUI server the developer runs, charging nothing, and it runs the bundled FLUX.2 klein 4B workflow, or with --workflow <file> a workflow exported from ComfyUI in the API format, its {{prompt}} filled with the prompt and any {{width}}, {{height}}, and {{seed}} with typed numbers. --workflow runs on comfyui alone and refuses usage beside another --provider, or for a file holding no {{prompt}}, before any request. Each local run draws a new seed, which the license file records with the workflow named. priceUsd is the estimate before the call, and --dry-run answers it with saved null and makes no request. Without --dry-run the call spends on that key at once, since no verb prompts. No ready provider refuses no-provider with the keys in the details, and a failed call refuses provider-failed with the provider's status and never the key.`,
|
|
50580
51912
|
`A saved image lands in the project's ${ASSETS_FOLDER}/ under the --name stem, else the query or prompt as a lowercase dashed name, taking the first free -2, -3, and onward. Its license file lands beside it as <file>${LICENSE_FILE_SUFFIX}, the licenseFile record, saying where it came from. A download is held whole, at most ${DOWNLOAD_LIMIT / 1024 / 1024} MiB, before anything is written, so a failed one leaves no file, and the Assets tab never draws a license file as its own tile.`,
|
|
50581
|
-
"image doctor reports the GPU nvidia-smi names, whether a ComfyUI server answers at FRAMEBOARD_COMFYUI_URL or the default address, and each key as set or unset, never its value. It installs and spends nothing.",
|
|
51913
|
+
"image doctor reports the GPU nvidia-smi names, whether a ComfyUI server answers at FRAMEBOARD_COMFYUI_URL or the default address with its version, the model files each bundled workflow loads that server lacks, each tagged for image or model to name the verb it serves, and each key as set or unset, never its value. setup lists the commands that would get the machine running both image generate and model generate locally, empty when it already can, so a missing model file leaves image generate working when every image file is present. torch comes from the CUDA index only where nvidia-smi names a GPU, and the start command reserves a tenth of that GPU's memory with --reserve-vram. It installs and spends nothing, so the developer runs each step.",
|
|
51914
|
+
"image free asks that ComfyUI server to unload its models and free their memory, which the model holds between runs so the next one starts warm. Run it once a batch of generations ends, and the next generate loads the model again.",
|
|
50582
51915
|
`A frame links a saved image as ../${ASSETS_FOLDER}/<path>, never by its web address, since a frame loads nothing over the network.`
|
|
50583
51916
|
],
|
|
50584
51917
|
models: [
|
|
@@ -50586,7 +51919,8 @@ function contentFormat() {
|
|
|
50586
51919
|
`The element draws only in a frame whose head loads the viewer, as ${VIEWER_SCRIPT}. Placing a model on the board copies ${VIEWER_FILE} into the project's ${ASSETS_FOLDER}/ once and adds that tag to a head loading no viewer, and removing the last model leaves both. The file ships with the tool at ${shippedViewerPath()}, so copy it to the project's ${ASSETS_FOLDER}/${VIEWER_FILE} before writing the element in a project that holds none. A frame loads nothing over the network, so never link the viewer from a CDN.`,
|
|
50587
51920
|
`Every staging control is an attribute on the element, set with edit --attr. camera-orbit="<theta>deg <phi>deg <radius>" places the camera, across and then down from the top, and defaults to 0deg 75deg auto. The viewer holds the camera inside max-camera-orbit, so state both once the radius passes the model's own framing, as camera-orbit="30deg 70deg 6m" max-camera-orbit="auto auto 6m". orientation="<roll>deg <pitch>deg <yaw>deg" turns the model itself, scale="<x> <y> <z>" sizes it, animation-name picks one of its clips, and autoplay starts it. The board's Model section writes these same attributes, the angle as both orbit attributes in one undo step, and a double-click on a selected model turns it by drag.`,
|
|
50588
51921
|
`check reports missing-file at error for a ${VIEWER_TAG} whose ${MODEL_LOADS.join(", ")} names no file, as it does for the viewer script. capture waits for each model to draw inside the frame's load budget and holds its clip at the start, and --at seeks every clip to that moment, so two captures match. A model that fails to load, or is still loading when the budget ends, never refuses: the image lists it under models with state error or pending.`,
|
|
50589
|
-
`model find searches ${POLYHAVEN_SOURCE.name}'s CC0 models, which ask no credit, and writes nothing. ${POLYHAVEN_SOURCE.name} has no search, so it reads the whole list in one request and ranks it here: by how many distinct query words match a word of the name, the tags, or the categories, then by download count, then by id, listing up to 20 numbered from 1 and none for a query matching nothing. Its results and human output name ${POLYHAVEN_SOURCE.name}, as its terms ask of any surface showing its content. --save <number> runs the search again, and --save <id> saves that ${POLYHAVEN_SOURCE.name} model with no search. A saved model is one .glb packed from the glTF, its buffer, and its textures, at 1k textures unless --size names one of ${MODEL_SIZES.join(", ")}, refusing usage with the sizes it offers for one the model lacks. A larger size weighs more, about 1 MB at 1k and 40 MB at 8k for a stool. Every file is held whole before anything is written, and its license file records the authors and the model's page
|
|
51922
|
+
`model find searches ${POLYHAVEN_SOURCE.name}'s CC0 models, which ask no credit, and writes nothing. ${POLYHAVEN_SOURCE.name} has no search, so it reads the whole list in one request and ranks it here: by how many distinct query words match a word of the name, the tags, or the categories, then by download count, then by id, listing up to 20 numbered from 1 and none for a query matching nothing. Its results and human output name ${POLYHAVEN_SOURCE.name}, as its terms ask of any surface showing its content. --save <number> runs the search again, and --save <id> saves that ${POLYHAVEN_SOURCE.name} model with no search. A saved model is one .glb packed from the glTF, its buffer, and its textures, at 1k textures unless --size names one of ${MODEL_SIZES.join(", ")}, refusing usage with the sizes it offers for one the model lacks. A larger size weighs more, about 1 MB at 1k and 40 MB at 8k for a stool. Every file is held whole before anything is written, and its license file records the authors and the model's page.`,
|
|
51923
|
+
`model generate <picture> makes a model from one PNG, JPEG, WebP, or GIF on the ComfyUI server ${COMFYUI_URL_ENV} names, running the bundled Pixal3D workflow at web size, 100,000 triangles and 2048 px textures, about 17 MB, or with --workflow <file> a workflow exported in the API format, its {{image}} filled with the uploaded picture's name and any {{seed}} with a typed number. The picture is read from here, the project's folder, or its ${ASSETS_FOLDER}/, and refuses usage when it names no file or no picture. A call takes about a minute and prints nothing until it returns. The license file records the server, the model, the workflow, the seed, and the picture: its ${ASSETS_FOLDER}/ path and its own license's origin and license name for a project asset, its file name alone otherwise. --dry-run answers with saved null and makes no request. An unset ${COMFYUI_URL_ENV} refuses no-provider, and a failed run refuses provider-failed naming the node. The model stays loaded between calls until image free unloads it, so run image free after a batch.`
|
|
50590
51924
|
],
|
|
50591
51925
|
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}/.`,
|
|
50592
51926
|
look: [
|
|
@@ -50973,11 +52307,12 @@ const DEVICE_ON = [
|
|
|
50973
52307
|
"tablet"
|
|
50974
52308
|
];
|
|
50975
52309
|
/** What `frame device` did, naming the device the frame draws inside and a foldable's pose. */
|
|
50976
|
-
function deviceHeadline({ ref, box, showDevice, device, pose, island }) {
|
|
52310
|
+
function deviceHeadline({ ref, box, showDevice, device, pose, island, turn }) {
|
|
50977
52311
|
const folded = pose ? `, folded ${pose} at ${box.width} by ${box.height}` : "";
|
|
50978
|
-
|
|
52312
|
+
const turned = turn ? `, turned ${turn} at ${box.width} by ${box.height}` : "";
|
|
52313
|
+
if (!showDevice) return `Hid the device on ${ref}${folded}${turned}`;
|
|
50979
52314
|
if (!device) return `Showed the device on ${ref}, though no device fits its ${box.width} px width`;
|
|
50980
|
-
return `Showed the ${device} on ${ref}${folded}${device === "phone" ? ` with the ${islandOf(island)} island` : ""}`;
|
|
52315
|
+
return `Showed the ${device} on ${ref}${folded}${turned}${device === "phone" ? ` with the ${islandOf(island)} island` : ""}`;
|
|
50981
52316
|
}
|
|
50982
52317
|
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";
|
|
50983
52318
|
const POSITIVE = parseInteger(1);
|
|
@@ -51059,15 +52394,16 @@ function registerFrame(program, context) {
|
|
|
51059
52394
|
human: `Deleted frame ${result.deleted}`
|
|
51060
52395
|
};
|
|
51061
52396
|
});
|
|
51062
|
-
act(verb("device", "Show or hide the device the board draws around a frame, the phone, tablet, or laptop its width names or the foldable the frame names, fold a foldable,
|
|
51063
|
-
if (value === void 0 && foldable === void 0 && pose === void 0 && island === void 0) throw new FrameboardError("usage", "frame device takes on or off, --foldable, --no-foldable, --pose, or --
|
|
52397
|
+
act(verb("device", "Show or hide the device the board draws around a frame, the phone, tablet, or laptop its width names or the foldable the frame names, fold a foldable, pick a phone’s island, and turn a phone, tablet, or foldable, leaving the frame file as it is").addArgument(new Argument("[on|off]", "on to show the device, off to hide it, with phone and tablet taken as on and none as off, and absent to leave it, which --foldable takes as on").choices(Object.keys(DEVICE_SWITCH))).addOption(new Option("--foldable", "name the foldable over the device the width picks, setting the box to the pose nearest its width")).addOption(new Option("--no-foldable", "hand the pick back to the width, leaving the box at its size, or at its pose’s upright screen while turned")).addOption(new Option("--pose <pose>", "fold a foldable, setting its box to 466 by 678 closed and 890 by 626 half or open").choices(POSES)).addOption(new Option("--island <width>", "pick the phone island drawn over a frame 320 to 479 px wide, compact or the wide one a call or a timer shows").choices(ISLANDS)).addOption(new Option("--turn <turn>", "turn a phone, tablet, or foldable a quarter, laying its page out landscape at its upright height wide with no status bar, a foldable at its pose’s screen with the sides swapped through every fold, left with the island on the left and right with it on the right, or upright to restore the size it held").choices(TURNS)), context, async ([ref = "", value], { foldable, pose, island, turn, ...options }) => {
|
|
52398
|
+
if (value === void 0 && foldable === void 0 && pose === void 0 && island === void 0 && turn === void 0) throw new FrameboardError("usage", "frame device takes on or off, --foldable, --no-foldable, --pose, --island, or --turn.");
|
|
51064
52399
|
const show = value !== void 0 && Object.hasOwn(DEVICE_SWITCH, value) ? DEVICE_SWITCH[value] : void 0;
|
|
51065
52400
|
const record = await setFrameDevice(await boardOf(options, io), ref, show, {
|
|
51066
52401
|
...options,
|
|
51067
52402
|
cwd: io.cwd,
|
|
51068
52403
|
foldable,
|
|
51069
52404
|
pose,
|
|
51070
|
-
island
|
|
52405
|
+
island,
|
|
52406
|
+
turn
|
|
51071
52407
|
});
|
|
51072
52408
|
return {
|
|
51073
52409
|
data: record,
|
|
@@ -51111,8 +52447,98 @@ function registerFrame(program, context) {
|
|
|
51111
52447
|
cwd: io.cwd
|
|
51112
52448
|
}), options.off ? `Cleared ${flag} on` : `Set ${flag} on`));
|
|
51113
52449
|
}
|
|
52450
|
+
// src/server/sourcing/doctor.ts
|
|
52451
|
+
/** Where a local ComfyUI server listens unless `FRAMEBOARD_COMFYUI_URL` names another. */
|
|
52452
|
+
const DEFAULT_COMFYUI_URL = "http://127.0.0.1:8188";
|
|
51114
52453
|
/** How long a probe waits, so a machine with nothing listening answers at once. */
|
|
51115
52454
|
const PROBE_TIMEOUT_MS = 1e3;
|
|
52455
|
+
/** The oldest ComfyUI whose native nodes run FLUX.2 klein, the release groundwork 54 ran. */
|
|
52456
|
+
const MIN_COMFYUI_VERSION = "0.46.0";
|
|
52457
|
+
/** The files the bundled image workflow loads, with the size and source each was measured at. */
|
|
52458
|
+
const BUNDLED_MODELS = [
|
|
52459
|
+
{
|
|
52460
|
+
for: "image",
|
|
52461
|
+
folder: "diffusion_models",
|
|
52462
|
+
file: "flux-2-klein-4b-fp8.safetensors",
|
|
52463
|
+
bytes: 4070624520,
|
|
52464
|
+
url: "https://huggingface.co/black-forest-labs/FLUX.2-klein-4b-fp8/resolve/main/flux-2-klein-4b-fp8.safetensors"
|
|
52465
|
+
},
|
|
52466
|
+
{
|
|
52467
|
+
for: "image",
|
|
52468
|
+
folder: "text_encoders",
|
|
52469
|
+
file: "qwen_3_4b.safetensors",
|
|
52470
|
+
bytes: 8044982048,
|
|
52471
|
+
url: "https://huggingface.co/Comfy-Org/z_image_turbo/resolve/main/split_files/text_encoders/qwen_3_4b.safetensors"
|
|
52472
|
+
},
|
|
52473
|
+
{
|
|
52474
|
+
for: "image",
|
|
52475
|
+
folder: "vae",
|
|
52476
|
+
file: "flux2-vae.safetensors",
|
|
52477
|
+
bytes: 336213556,
|
|
52478
|
+
url: "https://huggingface.co/Comfy-Org/flux2-dev/resolve/main/split_files/vae/flux2-vae.safetensors"
|
|
52479
|
+
}
|
|
52480
|
+
];
|
|
52481
|
+
/**
|
|
52482
|
+
* The files the bundled Pixal3D workflow loads, sized as groundwork 54
|
|
52483
|
+
* measured them. TRELLIS.2's model sits behind a switch the workflow leaves
|
|
52484
|
+
* off, and ComfyUI still checks that every loader's file exists.
|
|
52485
|
+
*/
|
|
52486
|
+
const BUNDLED_MODEL_FILES = [
|
|
52487
|
+
{
|
|
52488
|
+
for: "model",
|
|
52489
|
+
folder: "diffusion_models",
|
|
52490
|
+
file: "pixal3d_int8_convrot.safetensors",
|
|
52491
|
+
bytes: 5584555824,
|
|
52492
|
+
url: "https://huggingface.co/Comfy-Org/Pixal3D/resolve/main/diffusion_models/pixal3d_int8_convrot.safetensors"
|
|
52493
|
+
},
|
|
52494
|
+
{
|
|
52495
|
+
for: "model",
|
|
52496
|
+
folder: "diffusion_models",
|
|
52497
|
+
file: "trellis_2_int8_convrot.safetensors",
|
|
52498
|
+
bytes: 5253048192,
|
|
52499
|
+
url: "https://huggingface.co/Comfy-Org/TRELLIS.2/resolve/main/diffusion_models/trellis_2_int8_convrot.safetensors"
|
|
52500
|
+
},
|
|
52501
|
+
{
|
|
52502
|
+
for: "model",
|
|
52503
|
+
folder: "vae",
|
|
52504
|
+
file: "trellis_2_shape_vae_bf16.safetensors",
|
|
52505
|
+
bytes: 1095844024,
|
|
52506
|
+
url: "https://huggingface.co/Comfy-Org/Pixal3D/resolve/main/vae/trellis_2_shape_vae_bf16.safetensors"
|
|
52507
|
+
},
|
|
52508
|
+
{
|
|
52509
|
+
for: "model",
|
|
52510
|
+
folder: "vae",
|
|
52511
|
+
file: "trellis_2_texture_vae_bf16.safetensors",
|
|
52512
|
+
bytes: 948461364,
|
|
52513
|
+
url: "https://huggingface.co/Comfy-Org/Pixal3D/resolve/main/vae/trellis_2_texture_vae_bf16.safetensors"
|
|
52514
|
+
},
|
|
52515
|
+
{
|
|
52516
|
+
for: "model",
|
|
52517
|
+
folder: "clip_vision",
|
|
52518
|
+
file: "dino_v3_L_naf_fp32.safetensors",
|
|
52519
|
+
bytes: 1215214176,
|
|
52520
|
+
url: "https://huggingface.co/Comfy-Org/Pixal3D/resolve/main/clip_vision/dino_v3_L_naf_fp32.safetensors"
|
|
52521
|
+
},
|
|
52522
|
+
{
|
|
52523
|
+
for: "model",
|
|
52524
|
+
folder: "background_removal",
|
|
52525
|
+
file: "birefnet.safetensors",
|
|
52526
|
+
bytes: 444473596,
|
|
52527
|
+
url: "https://huggingface.co/Comfy-Org/BiRefNet/resolve/main/background_removal/birefnet.safetensors"
|
|
52528
|
+
},
|
|
52529
|
+
{
|
|
52530
|
+
for: "model",
|
|
52531
|
+
folder: "geometry_estimation",
|
|
52532
|
+
file: "moge_2_vitl_normal_fp16.safetensors",
|
|
52533
|
+
bytes: 661859924,
|
|
52534
|
+
url: "https://huggingface.co/Comfy-Org/MoGe/resolve/main/geometry_estimation/moge_2_vitl_normal_fp16.safetensors"
|
|
52535
|
+
}
|
|
52536
|
+
];
|
|
52537
|
+
const EVERY_MODEL = [...BUNDLED_MODELS, ...BUNDLED_MODEL_FILES];
|
|
52538
|
+
/** The ComfyUI server `FRAMEBOARD_COMFYUI_URL` names, else the default address. */
|
|
52539
|
+
function comfyuiUrl(env) {
|
|
52540
|
+
return env.FRAMEBOARD_COMFYUI_URL?.trim() || "http://127.0.0.1:8188";
|
|
52541
|
+
}
|
|
51116
52542
|
function runNvidiaSmi(args) {
|
|
51117
52543
|
return new Promise((resolve) => {
|
|
51118
52544
|
execFile("nvidia-smi", args, { timeout: 5e3 }, (error, stdout) => resolve(error ? null : stdout));
|
|
@@ -51123,8 +52549,10 @@ function runNvidiaSmi(args) {
|
|
|
51123
52549
|
* presence and never its value. Installs and spends nothing.
|
|
51124
52550
|
*/
|
|
51125
52551
|
async function diagnose({ env, send, queryGpu }) {
|
|
51126
|
-
const url = env
|
|
51127
|
-
const [gpu,
|
|
52552
|
+
const url = comfyuiUrl(env);
|
|
52553
|
+
const [gpu, version] = await Promise.all([readGpu(queryGpu), probe(url, send)]);
|
|
52554
|
+
const running = version !== void 0;
|
|
52555
|
+
const missing = running ? await missingModels(url, send) : null;
|
|
51128
52556
|
const providers = PROVIDERS.map((provider) => ({
|
|
51129
52557
|
provider: provider.name,
|
|
51130
52558
|
model: provider.model,
|
|
@@ -51136,8 +52564,16 @@ async function diagnose({ env, send, queryGpu }) {
|
|
|
51136
52564
|
gpu,
|
|
51137
52565
|
local: {
|
|
51138
52566
|
url,
|
|
51139
|
-
running
|
|
52567
|
+
running,
|
|
52568
|
+
version: version ?? null,
|
|
52569
|
+
missing
|
|
51140
52570
|
},
|
|
52571
|
+
setup: setupSteps({
|
|
52572
|
+
gpu,
|
|
52573
|
+
version,
|
|
52574
|
+
missing,
|
|
52575
|
+
urlSet: Boolean(env.FRAMEBOARD_COMFYUI_URL?.trim())
|
|
52576
|
+
}),
|
|
51141
52577
|
keys: Object.fromEntries(providers.map((each) => [each.key, each.ready])),
|
|
51142
52578
|
providers,
|
|
51143
52579
|
provider: providers.find((each) => each.ready)?.provider ?? null
|
|
@@ -51152,14 +52588,73 @@ async function readGpu(queryGpu) {
|
|
|
51152
52588
|
memoryMiB
|
|
51153
52589
|
};
|
|
51154
52590
|
}
|
|
51155
|
-
/**
|
|
52591
|
+
/**
|
|
52592
|
+
* The version ComfyUI's `/system_stats` reports, null when it answers with
|
|
52593
|
+
* none, and undefined when nothing answers within the probe timeout.
|
|
52594
|
+
*/
|
|
51156
52595
|
async function probe(url, send) {
|
|
51157
52596
|
try {
|
|
51158
|
-
|
|
52597
|
+
const response = await send(routeOf(url, "system_stats"), { signal: AbortSignal.timeout(PROBE_TIMEOUT_MS) });
|
|
52598
|
+
if (!response.ok) return void 0;
|
|
52599
|
+
const body = await response.json().catch(() => null);
|
|
52600
|
+
const system = typeof body === "object" && body !== null && "system" in body ? body.system : null;
|
|
52601
|
+
return typeof system === "object" && system !== null && "comfyui_version" in system && typeof system.comfyui_version === "string" ? system.comfyui_version : null;
|
|
51159
52602
|
} catch {
|
|
51160
|
-
return
|
|
52603
|
+
return;
|
|
51161
52604
|
}
|
|
51162
52605
|
}
|
|
52606
|
+
/** The bundled workflow's files that the folder listing ComfyUI answers lacks. */
|
|
52607
|
+
async function missingModels(url, send) {
|
|
52608
|
+
const folders = [...new Set(EVERY_MODEL.map((each) => each.folder))];
|
|
52609
|
+
const listed = await Promise.all(folders.map(async (folder) => {
|
|
52610
|
+
try {
|
|
52611
|
+
const response = await send(routeOf(url, `models/${folder}`), { signal: AbortSignal.timeout(PROBE_TIMEOUT_MS) });
|
|
52612
|
+
const body = response.ok ? await response.json() : [];
|
|
52613
|
+
return [folder, Array.isArray(body) ? body : []];
|
|
52614
|
+
} catch {
|
|
52615
|
+
return [folder, []];
|
|
52616
|
+
}
|
|
52617
|
+
}));
|
|
52618
|
+
const held = new Map(listed);
|
|
52619
|
+
return EVERY_MODEL.filter((model) => !held.get(model.folder)?.includes(model.file));
|
|
52620
|
+
}
|
|
52621
|
+
/**
|
|
52622
|
+
* The commands that would get this machine generating locally, empty when
|
|
52623
|
+
* it already can. The doctor prints them and never runs one.
|
|
52624
|
+
*/
|
|
52625
|
+
function setupSteps({ gpu, version, missing, urlSet }) {
|
|
52626
|
+
const nvidia = gpu !== null;
|
|
52627
|
+
const reserve = gpu === null ? "" : ` --reserve-vram ${Math.ceil(.09999999999999998 * gpu.memoryMiB / 1024)}`;
|
|
52628
|
+
const exportUrl = urlSet ? [] : [`export FRAMEBOARD_COMFYUI_URL=${DEFAULT_COMFYUI_URL}`];
|
|
52629
|
+
if (missing === null) return [
|
|
52630
|
+
`git clone https://github.com/Comfy-Org/ComfyUI && cd ComfyUI # v${MIN_COMFYUI_VERSION} or later`,
|
|
52631
|
+
"uv venv --python 3.13 && source .venv/bin/activate",
|
|
52632
|
+
nvidia ? "uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130" : "uv pip install torch torchvision torchaudio",
|
|
52633
|
+
"uv pip install -r requirements.txt",
|
|
52634
|
+
...EVERY_MODEL.map(download),
|
|
52635
|
+
`python main.py --listen 127.0.0.1 --port 8188${reserve}`,
|
|
52636
|
+
...exportUrl
|
|
52637
|
+
];
|
|
52638
|
+
return [
|
|
52639
|
+
...version !== null && version !== void 0 && olderThanMinimum(version) ? [`git pull && uv pip install -r requirements.txt # in the ComfyUI folder, since FLUX.2 klein needs v${MIN_COMFYUI_VERSION} or later`] : [],
|
|
52640
|
+
...missing.map(download),
|
|
52641
|
+
...exportUrl
|
|
52642
|
+
];
|
|
52643
|
+
}
|
|
52644
|
+
function download(model) {
|
|
52645
|
+
const gigabytes = (model.bytes / 1e9).toFixed(2);
|
|
52646
|
+
return `curl -L -o models/${model.folder}/${model.file} ${model.url} # ${gigabytes} GB`;
|
|
52647
|
+
}
|
|
52648
|
+
function olderThanMinimum(version) {
|
|
52649
|
+
const parts = (text) => text.replace(/^v/, "").split(".").map((each) => Number.parseInt(each, 10) || 0);
|
|
52650
|
+
const have = parts(version);
|
|
52651
|
+
const need = parts(MIN_COMFYUI_VERSION);
|
|
52652
|
+
for (let index = 0; index < need.length; index += 1) {
|
|
52653
|
+
const gap = (have[index] ?? 0) - (need[index] ?? 0);
|
|
52654
|
+
if (gap !== 0) return gap < 0;
|
|
52655
|
+
}
|
|
52656
|
+
return false;
|
|
52657
|
+
}
|
|
51163
52658
|
// src/cli/commands/image.ts
|
|
51164
52659
|
function registerImage(program, context) {
|
|
51165
52660
|
const { io } = context;
|
|
@@ -51190,19 +52685,24 @@ function registerImage(program, context) {
|
|
|
51190
52685
|
human: savedLine$1(saved)
|
|
51191
52686
|
};
|
|
51192
52687
|
});
|
|
51193
|
-
act(addVerb(image, "generate", "Generate an image on the first provider whose key is set and save it into the project's assets, spending on that key unless --dry-run", { project: true }).argument("<prompt>", "what the image shows").option("--provider <name>", `run on this provider, one of ${IMAGE_PROVIDERS.join(", ")}, rather than the first ready`).option("--width <px>", "the width asked for", parseInteger(1), 1024).option("--height <px>", "the height asked for", parseInteger(1), 1024).option("--dry-run", "answer the provider, size, and price, and make no request").option("--name <stem>", "the saved file name without its extension, the prompt by default"), context, async ([prompt = ""], options) => {
|
|
52688
|
+
act(addVerb(image, "generate", "Generate an image on the first provider whose key is set and save it into the project's assets, spending on that key unless --dry-run", { project: true }).argument("<prompt>", "what the image shows").option("--provider <name>", `run on this provider, one of ${IMAGE_PROVIDERS.join(", ")}, rather than the first ready`).option("--workflow <file>", "run this ComfyUI workflow in the API format on comfyui, with {{prompt}} and optionally {{width}}, {{height}}, and {{seed}} in it").option("--width <px>", "the width asked for", parseInteger(1), 1024).option("--height <px>", "the height asked for", parseInteger(1), 1024).option("--dry-run", "answer the provider, size, and price, and make no request").option("--name <stem>", "the saved file name without its extension, the prompt by default"), context, async ([prompt = ""], options) => {
|
|
52689
|
+
const workflow = options.workflow === void 0 ? void 0 : {
|
|
52690
|
+
name: options.workflow,
|
|
52691
|
+
graph: await readWorkflow(options.workflow)
|
|
52692
|
+
};
|
|
51194
52693
|
const plan = planGeneration({
|
|
51195
52694
|
prompt,
|
|
51196
52695
|
size: {
|
|
51197
52696
|
width: options.width,
|
|
51198
52697
|
height: options.height
|
|
51199
52698
|
},
|
|
51200
|
-
provider: options.provider
|
|
52699
|
+
provider: options.provider,
|
|
52700
|
+
workflow
|
|
51201
52701
|
}, process.env);
|
|
51202
52702
|
const record = {
|
|
51203
52703
|
version: 1,
|
|
51204
52704
|
provider: plan.provider.name,
|
|
51205
|
-
model: plan.
|
|
52705
|
+
model: plan.model,
|
|
51206
52706
|
prompt,
|
|
51207
52707
|
...plan.size,
|
|
51208
52708
|
priceUsd: plan.priceUsd,
|
|
@@ -51224,6 +52724,8 @@ function registerImage(program, context) {
|
|
|
51224
52724
|
width: record.width,
|
|
51225
52725
|
height: record.height,
|
|
51226
52726
|
priceUsd: record.priceUsd,
|
|
52727
|
+
...plan.provider.name === "comfyui" && { seed: plan.seed },
|
|
52728
|
+
...plan.workflow && { workflow: plan.workflow.name },
|
|
51227
52729
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
51228
52730
|
});
|
|
51229
52731
|
return {
|
|
@@ -51234,7 +52736,7 @@ function registerImage(program, context) {
|
|
|
51234
52736
|
human: `Generated on ${priced}. ${savedLine$1(saved)}`
|
|
51235
52737
|
};
|
|
51236
52738
|
});
|
|
51237
|
-
act(addVerb(image, "doctor", "Report the GPU, a local ComfyUI server, and which provider keys are set, installing nothing"), context, async () => {
|
|
52739
|
+
act(addVerb(image, "doctor", "Report the GPU, a local ComfyUI server's version and missing model files, and which provider keys are set, printing setup steps and installing nothing"), context, async () => {
|
|
51238
52740
|
const report = await diagnose({
|
|
51239
52741
|
env: process.env,
|
|
51240
52742
|
send,
|
|
@@ -51244,12 +52746,30 @@ function registerImage(program, context) {
|
|
|
51244
52746
|
data: report,
|
|
51245
52747
|
human: [
|
|
51246
52748
|
`GPU\t${report.gpu === null ? "none found" : `${report.gpu.name}, ${report.gpu.memoryMiB} MiB`}`,
|
|
51247
|
-
`Local\t${report.local.url} ${report.local.running ?
|
|
52749
|
+
`Local\t${report.local.url} ${report.local.running ? `answers, ComfyUI ${report.local.version ?? "of unknown version"}` : "does not answer"}`,
|
|
52750
|
+
...(report.local.missing ?? []).map((each) => `Missing\tmodels/${each.folder}/${each.file}, ${(each.bytes / 1e9).toFixed(2)} GB, for ${each.for} generate`),
|
|
51248
52751
|
...report.providers.map((each) => `${each.provider}\t${each.key} ${each.ready ? "set" : "unset"}`),
|
|
51249
|
-
`Generate runs on\t${report.provider ?? "nothing, since no key is set"}
|
|
52752
|
+
`Generate runs on\t${report.provider ?? "nothing, since no key is set"}`,
|
|
52753
|
+
...report.setup.length === 0 ? [] : [
|
|
52754
|
+
"",
|
|
52755
|
+
"To generate locally, run these yourself:",
|
|
52756
|
+
...report.setup
|
|
52757
|
+
]
|
|
51250
52758
|
].join("\n")
|
|
51251
52759
|
};
|
|
51252
52760
|
});
|
|
52761
|
+
act(addVerb(image, "free", "Ask the ComfyUI server to unload its models and free their memory, which the next generate loads again"), context, async () => {
|
|
52762
|
+
const url = comfyuiUrl(process.env);
|
|
52763
|
+
await freeMemory(url, send);
|
|
52764
|
+
return {
|
|
52765
|
+
data: {
|
|
52766
|
+
version: 1,
|
|
52767
|
+
url,
|
|
52768
|
+
freed: true
|
|
52769
|
+
},
|
|
52770
|
+
human: `Freed the models ${url} held`
|
|
52771
|
+
};
|
|
52772
|
+
});
|
|
51253
52773
|
/** The result `--save` names: a number reruns the search, anything else is an id. */
|
|
51254
52774
|
async function pick(query, save, search) {
|
|
51255
52775
|
if (!/^\d+$/.test(save)) return {
|
|
@@ -54996,7 +56516,7 @@ async function inspectFrame(browser, { baseUrl, frame, theme, index }) {
|
|
|
54996
56516
|
const opened = await openFrame(browser, {
|
|
54997
56517
|
baseUrl,
|
|
54998
56518
|
ref: frame.ref,
|
|
54999
|
-
box: pageSize(frame.box, frame.device),
|
|
56519
|
+
box: pageSize(frame.box, frame.device, frame.turn),
|
|
55000
56520
|
theme
|
|
55001
56521
|
});
|
|
55002
56522
|
let live;
|
|
@@ -55164,7 +56684,8 @@ const CREDIT = `Models from ${POLYHAVEN_SOURCE.name}, ${POLYHAVEN_SOURCE.url}, C
|
|
|
55164
56684
|
function registerModel(program, context) {
|
|
55165
56685
|
const { io } = context;
|
|
55166
56686
|
const send = io.fetch ?? fetch;
|
|
55167
|
-
|
|
56687
|
+
const model = program.command("model").description("Find a public domain 3D model or make one from a picture, saving it into a project's assets as one GLB with its license");
|
|
56688
|
+
act(addVerb(model, "find", "Search Poly Haven's CC0 models, writing nothing unless --save names a result", { project: true }).argument("<query>", "what the model shows").option("--save <number-or-id>", "save the result with this number, or the Poly Haven model with this id, into the project's assets").option("--size <size>", `the texture size saved, one of ${MODEL_SIZES.join(", ")}, 1k by default`, parseSize).option("--name <stem>", "the saved file name without its extension, the query by default"), context, async ([query = ""], options) => {
|
|
55168
56689
|
if (options.save === void 0) {
|
|
55169
56690
|
for (const flag of ["name", "size"]) if (options[flag] !== void 0) throw new FrameboardError("usage", `--${flag} needs --save.`);
|
|
55170
56691
|
const results = await searchModels(query, send);
|
|
@@ -55192,6 +56713,52 @@ function registerModel(program, context) {
|
|
|
55192
56713
|
human: savedLine(saved)
|
|
55193
56714
|
};
|
|
55194
56715
|
});
|
|
56716
|
+
act(addVerb(model, "generate", "Make a 3D model from a picture on the ComfyUI server at FRAMEBOARD_COMFYUI_URL and save it into the project's assets as one GLB with its license, in about a minute and with no progress line. Refuses no-provider while that address is unset", { project: true }).argument("<picture>", "a PNG, JPEG, WebP, or GIF, read from here, the project's folder, or its assets/").option("--workflow <file>", "run this ComfyUI workflow in the API format, with {{image}} and optionally {{seed}} in it, rather than the bundled Pixal3D one").option("--dry-run", "answer the server, model, and picture, and make no request").option("--name <stem>", "the saved file name without its extension, the picture's by default"), context, async ([path = ""], options) => {
|
|
56717
|
+
const workflow = options.workflow === void 0 ? void 0 : {
|
|
56718
|
+
name: options.workflow,
|
|
56719
|
+
graph: await readWorkflow(options.workflow, "model")
|
|
56720
|
+
};
|
|
56721
|
+
const project = await resolveProject(await boardOf(options, io), options.project);
|
|
56722
|
+
const picture = await readPicture(path, io.cwd, project);
|
|
56723
|
+
const stem = savedStem(options.name, picture.name.replace(/\.[^.]*$/, ""), "model");
|
|
56724
|
+
const plan = planModelGeneration({
|
|
56725
|
+
picture,
|
|
56726
|
+
workflow
|
|
56727
|
+
}, process.env);
|
|
56728
|
+
const record = {
|
|
56729
|
+
version: 1,
|
|
56730
|
+
provider: "comfyui",
|
|
56731
|
+
server: plan.server,
|
|
56732
|
+
model: plan.model,
|
|
56733
|
+
picture: picture.source,
|
|
56734
|
+
dryRun: options.dryRun ?? false,
|
|
56735
|
+
saved: null
|
|
56736
|
+
};
|
|
56737
|
+
const made = `${record.model} on ${record.server} from ${picture.source.path}`;
|
|
56738
|
+
if (record.dryRun) return {
|
|
56739
|
+
data: record,
|
|
56740
|
+
human: `Would generate ${made}`
|
|
56741
|
+
};
|
|
56742
|
+
const saved = await saveModel(project, stem, await generateModel(plan, send), {
|
|
56743
|
+
version: 1,
|
|
56744
|
+
origin: "generated",
|
|
56745
|
+
kind: "model",
|
|
56746
|
+
provider: "comfyui",
|
|
56747
|
+
server: plan.server,
|
|
56748
|
+
model: plan.model,
|
|
56749
|
+
...plan.workflow && { workflow: plan.workflow.name },
|
|
56750
|
+
picture: picture.source,
|
|
56751
|
+
seed: plan.seed,
|
|
56752
|
+
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
56753
|
+
});
|
|
56754
|
+
return {
|
|
56755
|
+
data: {
|
|
56756
|
+
...record,
|
|
56757
|
+
saved
|
|
56758
|
+
},
|
|
56759
|
+
human: `Generated ${made}. Saved assets/${saved.path} into ${saved.project}, its license in assets/${saved.licensePath}`
|
|
56760
|
+
};
|
|
56761
|
+
});
|
|
55195
56762
|
/** The model `--save` names: a number reruns the search, anything else is an id. */
|
|
55196
56763
|
async function pick(query, save) {
|
|
55197
56764
|
if (!/^\d+$/.test(save)) return {
|
|
@@ -55830,11 +57397,12 @@ function terminalCode(modules) {
|
|
|
55830
57397
|
function registerProject(program, context) {
|
|
55831
57398
|
const { io } = context;
|
|
55832
57399
|
const project = program.command("project").description("Manage projects");
|
|
55833
|
-
act(addVerb(project, "add", "Add a project holding one empty page").argument("<name>", "the new project"), context, async ([name = ""], options) => {
|
|
55834
|
-
const
|
|
57400
|
+
act(addVerb(project, "add", "Add a project holding one empty page").argument("<name>", "the new project").option("--group <folder>", "file the project under a home folder, created when no project holds it"), context, async ([name = ""], options) => {
|
|
57401
|
+
const group = options.group === void 0 ? void 0 : validFolder(options.group);
|
|
57402
|
+
const record = await addProject(await boardOf(options, io), name, void 0, { group });
|
|
55835
57403
|
return {
|
|
55836
57404
|
data: record,
|
|
55837
|
-
human: `Added project ${record.name}`
|
|
57405
|
+
human: group ? `Added project ${record.name} under ${group}` : `Added project ${record.name}`
|
|
55838
57406
|
};
|
|
55839
57407
|
});
|
|
55840
57408
|
act(addVerb(project, "rename", "Rename a project").argument("<name>", "the project").argument("<new-name>", "its new name"), context, async ([name = "", newName = ""], options) => {
|
|
@@ -55899,6 +57467,10 @@ function folderOf(folder, clear) {
|
|
|
55899
57467
|
if (clear && folder !== void 0) throw new FrameboardError("usage", "Give a folder or --clear, not both.");
|
|
55900
57468
|
if (clear) return null;
|
|
55901
57469
|
if (folder === void 0) throw new FrameboardError("usage", "Give a folder, or --clear to leave one.");
|
|
57470
|
+
return validFolder(folder);
|
|
57471
|
+
}
|
|
57472
|
+
/** The trimmed folder, refusing a blank or overlong one. */
|
|
57473
|
+
function validFolder(folder) {
|
|
55902
57474
|
const name = folder.trim();
|
|
55903
57475
|
if (name === "" || name.length > MAX_FOLDER) throw new FrameboardError("invalid-name", `A folder name holds 1 to ${MAX_FOLDER} characters.`);
|
|
55904
57476
|
return name;
|
|
@@ -56420,10 +57992,10 @@ const THEMED_RULES = [
|
|
|
56420
57992
|
* face in the board's fallback rather than refusing, after animations finish.
|
|
56421
57993
|
*/
|
|
56422
57994
|
async function checkRendered(browser, { baseUrl, root, frame: shown, config }) {
|
|
56423
|
-
const { device, ...target } = shown;
|
|
57995
|
+
const { device, turn, ...target } = shown;
|
|
56424
57996
|
const frame = {
|
|
56425
57997
|
...target,
|
|
56426
|
-
box: pageSize(target.box, device)
|
|
57998
|
+
box: pageSize(target.box, device, turn)
|
|
56427
57999
|
};
|
|
56428
58000
|
const [project = "", page = "", name = ""] = frame.ref.split("/");
|
|
56429
58001
|
const source = readFrame$1({
|
|
@@ -56583,6 +58155,60 @@ function createClaimsPush(root, { broadcast, inTurn, now = () => /* @__PURE__ */
|
|
|
56583
58155
|
}
|
|
56584
58156
|
};
|
|
56585
58157
|
}
|
|
58158
|
+
// src/server/frame-origin/listener.ts
|
|
58159
|
+
const HOSTNAME$1 = "127.0.0.1";
|
|
58160
|
+
/**
|
|
58161
|
+
* Lets a frame page sit in the board on either loopback name and any port,
|
|
58162
|
+
* which covers the board's own port and Vite's in dev, and no foreign page.
|
|
58163
|
+
*/
|
|
58164
|
+
const FRAME_ANCESTORS = "frame-ancestors 'self' http://127.0.0.1:* http://localhost:*";
|
|
58165
|
+
const LOOPBACK_ORIGIN = /^http:\/\/(127\.0\.0\.1|localhost):\d{1,5}$/;
|
|
58166
|
+
/**
|
|
58167
|
+
* The frames, their assets, and the look on an origin apart from the board's,
|
|
58168
|
+
* so a frame's script carries an `Origin` the board's write guard refuses.
|
|
58169
|
+
* It answers GET and HEAD under the frame and look routes alone.
|
|
58170
|
+
*/
|
|
58171
|
+
function frameOriginApp(port, { root, facesDir, tokens, version }) {
|
|
58172
|
+
const app = new Hono();
|
|
58173
|
+
app.use("*", boardHostGuard(port));
|
|
58174
|
+
app.use("*", async (c, next) => {
|
|
58175
|
+
await next();
|
|
58176
|
+
const type = c.res.headers.get("Content-Type") ?? "";
|
|
58177
|
+
if (type.startsWith("text/html") || type.startsWith("image/svg+xml")) c.res.headers.set("Content-Security-Policy", FRAME_ANCESTORS);
|
|
58178
|
+
const origin = c.req.header("Origin");
|
|
58179
|
+
if (origin !== void 0 && LOOPBACK_ORIGIN.test(origin)) c.res.headers.set("Access-Control-Allow-Origin", origin);
|
|
58180
|
+
c.res.headers.append("Vary", "Origin");
|
|
58181
|
+
});
|
|
58182
|
+
app.route("/", servedFrames(root, {
|
|
58183
|
+
facesDir,
|
|
58184
|
+
tokens: tokens ?? null,
|
|
58185
|
+
version
|
|
58186
|
+
}).routes);
|
|
58187
|
+
return app;
|
|
58188
|
+
}
|
|
58189
|
+
/** Starts the frame listener on a free loopback port. */
|
|
58190
|
+
async function startFrameOrigin(options) {
|
|
58191
|
+
let bound = 0;
|
|
58192
|
+
const app = frameOriginApp(() => bound, options);
|
|
58193
|
+
const server = await new Promise((resolve, reject) => {
|
|
58194
|
+
const created = serve({
|
|
58195
|
+
fetch: app.fetch,
|
|
58196
|
+
hostname: HOSTNAME$1,
|
|
58197
|
+
port: 0
|
|
58198
|
+
}, (info) => {
|
|
58199
|
+
bound = info.port;
|
|
58200
|
+
resolve(created);
|
|
58201
|
+
});
|
|
58202
|
+
created.once("error", reject);
|
|
58203
|
+
});
|
|
58204
|
+
return {
|
|
58205
|
+
port: bound,
|
|
58206
|
+
close: () => new Promise((done, fail) => {
|
|
58207
|
+
server.close((error) => error ? fail(error) : done());
|
|
58208
|
+
server.closeAllConnections();
|
|
58209
|
+
})
|
|
58210
|
+
};
|
|
58211
|
+
}
|
|
56586
58212
|
// node_modules/readdirp/index.js
|
|
56587
58213
|
const EntryTypes = {
|
|
56588
58214
|
FILE_TYPE: "files",
|
|
@@ -60072,7 +61698,7 @@ function checkOne(root, frame, context) {
|
|
|
60072
61698
|
* The live socket every board tab holds. An `inbox` client never counts as a
|
|
60073
61699
|
* tab and needs the bearer token, since a browser page must never register one.
|
|
60074
61700
|
*/
|
|
60075
|
-
function createHub({ tabs, port, access, snapshot, findings, notes, delivery, history, claims, changes, closeTab, dispatch = false }) {
|
|
61701
|
+
function createHub({ tabs, port, access, snapshot, findings, notes, delivery, history, claims, changes, closeTab, dispatch = false, framePort }) {
|
|
60076
61702
|
const server = new import_websocket_server.default({ noServer: true });
|
|
60077
61703
|
const boards = /* @__PURE__ */ new Map();
|
|
60078
61704
|
const inboxes = /* @__PURE__ */ new Map();
|
|
@@ -60107,6 +61733,10 @@ function createHub({ tabs, port, access, snapshot, findings, notes, delivery, hi
|
|
|
60107
61733
|
boards.set(socket, writer);
|
|
60108
61734
|
if (typeof message.tab === "string") tabIds.set(socket, message.tab);
|
|
60109
61735
|
tabs.open(writer);
|
|
61736
|
+
if (framePort) send(socket, {
|
|
61737
|
+
type: "frames",
|
|
61738
|
+
port: framePort()
|
|
61739
|
+
});
|
|
60110
61740
|
snapshot().then(async (board) => {
|
|
60111
61741
|
send(socket, {
|
|
60112
61742
|
type: "board",
|
|
@@ -60283,14 +61913,14 @@ function failureOf(error) {
|
|
|
60283
61913
|
async function measureParts(measure, frame, parts) {
|
|
60284
61914
|
const size = {};
|
|
60285
61915
|
if (parts !== "linked") {
|
|
60286
|
-
const page = pageBox(frame.box, frame.device);
|
|
61916
|
+
const page = pageBox(frame.box, frame.device, frame.turn);
|
|
60287
61917
|
const own = await measure({
|
|
60288
61918
|
...frame,
|
|
60289
61919
|
box: page
|
|
60290
61920
|
});
|
|
60291
61921
|
if (!own.empty) Object.assign(size, {
|
|
60292
61922
|
width: own.width,
|
|
60293
|
-
height: own.height + topInset(frame.device)
|
|
61923
|
+
height: own.height + topInset(frame.device, frame.turn)
|
|
60294
61924
|
});
|
|
60295
61925
|
}
|
|
60296
61926
|
if (parts !== "own" && frame.hugHeight && frame.widths.length > 0) {
|
|
@@ -60895,9 +62525,16 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
60895
62525
|
inTurn(() => tracker.own(step));
|
|
60896
62526
|
});
|
|
60897
62527
|
const selection = createSelectionHolder(() => tabs.writers);
|
|
62528
|
+
const frameOrigin = await startFrameOrigin({
|
|
62529
|
+
root,
|
|
62530
|
+
facesDir,
|
|
62531
|
+
tokens,
|
|
62532
|
+
version: tracker.version
|
|
62533
|
+
});
|
|
60898
62534
|
const hub = createHub({
|
|
60899
62535
|
tabs,
|
|
60900
62536
|
port: boundPort,
|
|
62537
|
+
framePort: () => frameOrigin.port,
|
|
60901
62538
|
access,
|
|
60902
62539
|
snapshot: () => inTurn(async () => {
|
|
60903
62540
|
shown.board = await scanBoard(root);
|
|
@@ -60923,7 +62560,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
60923
62560
|
purpose: "Board PNGs, thumbnails, and browser checks",
|
|
60924
62561
|
launch
|
|
60925
62562
|
}));
|
|
60926
|
-
const baseUrl = () => `http://${HOSTNAME}:${
|
|
62563
|
+
const baseUrl = () => `http://${HOSTNAME}:${frameOrigin.port}`;
|
|
60927
62564
|
const renderFrame = createWarmRenderer({
|
|
60928
62565
|
baseUrl,
|
|
60929
62566
|
browser,
|
|
@@ -60959,7 +62596,8 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
60959
62596
|
box,
|
|
60960
62597
|
scroll: frame.scroll,
|
|
60961
62598
|
hugHeight: frame.hugHeight,
|
|
60962
|
-
device: box.width === frame.box.width ? frame.device : void 0
|
|
62599
|
+
device: box.width === frame.box.width ? frame.device : void 0,
|
|
62600
|
+
turn: frame.turn
|
|
60963
62601
|
},
|
|
60964
62602
|
config: readConfig(root, frame.project)
|
|
60965
62603
|
}));
|
|
@@ -60999,6 +62637,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
60999
62637
|
tokens,
|
|
61000
62638
|
root,
|
|
61001
62639
|
port: boundPort,
|
|
62640
|
+
framePort: () => frameOrigin.port,
|
|
61002
62641
|
tickets,
|
|
61003
62642
|
openRoute,
|
|
61004
62643
|
delivery,
|
|
@@ -61066,6 +62705,9 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
61066
62705
|
resolve(created);
|
|
61067
62706
|
});
|
|
61068
62707
|
created.once("error", reject);
|
|
62708
|
+
}).catch(async (error) => {
|
|
62709
|
+
await frameOrigin.close();
|
|
62710
|
+
throw error;
|
|
61069
62711
|
});
|
|
61070
62712
|
server.on("upgrade", hub.handleUpgrade);
|
|
61071
62713
|
const measuredAtStart = inTurn(async () => {
|
|
@@ -61130,6 +62772,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
61130
62772
|
return {
|
|
61131
62773
|
hostname: HOSTNAME,
|
|
61132
62774
|
port: bound,
|
|
62775
|
+
framePort: frameOrigin.port,
|
|
61133
62776
|
tabs,
|
|
61134
62777
|
watcher,
|
|
61135
62778
|
authorize: (next) => {
|
|
@@ -61150,7 +62793,8 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
61150
62793
|
hub.close(),
|
|
61151
62794
|
browser.close(),
|
|
61152
62795
|
emptyTrash(root),
|
|
61153
|
-
preview.stop()
|
|
62796
|
+
preview.stop(),
|
|
62797
|
+
frameOrigin.close()
|
|
61154
62798
|
]);
|
|
61155
62799
|
await new Promise((done, fail) => {
|
|
61156
62800
|
server.close((error) => error ? fail(error) : done());
|