@marver-design/marver 0.23.1 → 0.25.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/CHANGELOG.md +66 -0
- package/README.md +3 -1
- package/dist/anchor-DVV732zR.mjs +33 -0
- package/dist/anchor-check-BE5VVN6Q.mjs +135 -0
- package/dist/{bake-DQtnDB8-.mjs → bake-D8byeRzB.mjs} +1 -1
- package/dist/{boards-BRLnoTC3.mjs → board-tree-DRioF94d.mjs} +21 -277
- package/dist/boards-CGg6piKF.mjs +342 -0
- package/dist/{boards-Dv-Ipd8G.mjs → boards-Csxj2WJn.mjs} +23 -9
- package/dist/{build-_ndp_dXn.mjs → build-BHoWLvSj.mjs} +63 -37
- package/dist/cli.mjs +31 -17
- package/dist/{collab-mAiNZlDj.mjs → collab-gqNdScUE.mjs} +39 -9
- package/dist/{comments-DZyobpxG.mjs → comments-Zoch254k.mjs} +19 -1
- package/dist/{comments-BlqyZh3D.mjs → comments-pTLlhjh4.mjs} +150 -20
- package/dist/{config-BUKprFAp.mjs → config-cKgZBRj0.mjs} +1 -1
- package/dist/{context-CdkNiKdJ.mjs → context-D2ugHqwO.mjs} +17 -123
- package/dist/{daemon-BvMPdQ3k.mjs → daemon-Cl8KXGW4.mjs} +146 -64
- package/dist/{dev-Cf-4eqaC.mjs → dev-DJdgow47.mjs} +23 -11
- package/dist/{events-B3LBn74P.mjs → events-DnK_AnrW.mjs} +13 -15
- package/dist/imports-WBSnnHLb.mjs +143 -0
- package/dist/{init-hfZV7TwY.mjs → init-DO4DhUt_.mjs} +28 -6
- package/dist/link-C-qUIuKU.mjs +160 -0
- package/dist/{board-status-BZSzc9Hp.mjs → manifest-DnAte_fB.mjs} +537 -13
- package/dist/marks-DFuintmJ.mjs +50 -0
- package/dist/marks-koRsbHfe.mjs +397 -0
- package/dist/{marver-id-gate-B_idGdHm.mjs → marver-id-gate-DGANtVyC.mjs} +2 -2
- package/dist/perf-CCisg-ny.mjs +49 -0
- package/dist/perf-QJIWtTw1.mjs +68 -0
- package/dist/{plugin-DoXql0ZZ.mjs → plugin-CTyhjwoJ.mjs} +469 -82
- package/dist/{poster-XBmUvQiL.mjs → poster-D0cbV7hi.mjs} +1 -1
- package/dist/{profile-CrZohD6g.mjs → profile-Do0nGkXO.mjs} +1 -1
- package/dist/{publish-bakes-KKTHWqq3.mjs → publish-bakes--l8ot2eQ.mjs} +9 -9
- package/dist/{serve-z5qtj_wJ.mjs → serve-wv2QWdxB.mjs} +6 -6
- package/dist/{share-BD-wcDQq.mjs → share-ScamJcks.mjs} +1 -1
- package/dist/{shot-DOD8v6fJ.mjs → shot-CckrGW-J.mjs} +19 -11
- package/dist/{shot-Dh6fV1Lm.mjs → shot-jdO_B6Qw.mjs} +1 -1
- package/dist/{summary-C7CAypbB.mjs → summary-CrW88e3q.mjs} +1 -1
- package/dist/{sync-DoA1vf4u.mjs → sync-C3035OnJ.mjs} +18 -8
- package/dist/{work-ClFFq0Qh.mjs → work-CpJn1gwY.mjs} +8 -4
- package/dist/{work-ayuL_9Kk.mjs → work-GE88wb_3.mjs} +4 -4
- package/docs/boards-and-folders.md +70 -4
- package/docs/live-jam.md +12 -4
- package/package.json +1 -1
- package/src/client/frame-host/bridge.js +2 -1
- package/src/client/frame-host/inspect.js +195 -84
- package/src/client/frame-host/main.tsx +7 -2
- package/src/client/frame-host/registry.ts +5 -5
- package/src/client/shell/App.tsx +98 -30
- package/src/client/shell/BoardList.tsx +74 -16
- package/src/client/shell/Comments.tsx +79 -34
- package/src/client/shell/ContextMenu.tsx +5 -2
- package/src/client/shell/LockedApp.tsx +45 -12
- package/src/client/shell/Play.tsx +35 -32
- package/src/client/shell/Toolbar.tsx +3 -1
- package/src/client/shell/canvas/Canvas.tsx +2 -0
- package/src/client/shell/canvas/FrameNode.tsx +15 -5
- package/src/client/shell/canvas/sleep.ts +4 -3
- package/src/client/shell/canvas/updates.ts +55 -0
- package/src/client/shell/comments-store.ts +48 -17
- package/src/client/shell/goto.ts +11 -14
- package/src/client/shell/hash.ts +12 -5
- package/src/client/shell/icons.tsx +1 -2
- package/src/client/shell/legacy-links.ts +67 -0
- package/src/client/shell/marks-ui.tsx +117 -0
- package/src/client/shell/pin-layout.ts +37 -0
- package/src/client/shell/store.ts +377 -67
- package/src/client/shell/styles.css +32 -8
- package/src/client/stage/main.tsx +19 -2
- package/src/shared/anchor.ts +57 -0
- package/src/shared/board-tree.ts +27 -10
- package/src/shared/events.ts +19 -10
- package/src/shared/marks.ts +70 -0
- package/templates/AGENTS-embedded.md +34 -15
- package/templates/AGENTS-studio.md +34 -15
- package/templates/instructions/boards.md +9 -5
- package/templates/instructions/iterate.md +20 -10
- package/templates/instructions/jam.md +13 -4
- package/templates/instructions/publish.md +2 -1
- package/templates/instructions/reference/deck-story.md +2 -2
- package/dist/link-BodAbIQz.mjs +0 -132
- package/dist/manifest-TpfDWldB.mjs +0 -528
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { a as ROUTE, i as PKG, r as NAME } from "./cli.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { n as
|
|
6
|
-
import {
|
|
7
|
-
import { n as
|
|
8
|
-
import {
|
|
3
|
+
import { c as nodeExists, d as readMembership, f as readRegistry, h as hash, i as checkBoardsDir, l as parseBoard, m as withRegistryLock, o as isRegularFile, r as boardFields, s as listBoardFiles, t as AUTHOR_FIELDS, u as pinFrames } from "./boards-CGg6piKF.mjs";
|
|
4
|
+
import { A as settableStatuses, D as readStatusWord, E as readReason, O as readType, T as readCapability, _ as wireKids, a as buildTree, c as folderMap, g as validateWire, h as readTitle, k as resolveType, m as readDescription, n as BOARD_NAME, r as FOLDERS_FILE, t as ALL_SCENES, x as HAS_STATUS } from "./board-tree-DRioF94d.mjs";
|
|
5
|
+
import { c as setSceneTitle, d as annotateBoards, f as planNames, m as readContextFacts, n as isNoteFile, o as rendersDoc, p as planWithStage, r as layoutDocSource, s as scanFrames, t as affectedFrameIds, u as writeManifest } from "./manifest-DnAte_fB.mjs";
|
|
6
|
+
import { r as boardsChanged } from "./work-GE88wb_3.mjs";
|
|
7
|
+
import { n as localProfile, t as isConnected } from "./profile-Do0nGkXO.mjs";
|
|
8
|
+
import { n as loadConfig } from "./config-cKgZBRj0.mjs";
|
|
9
|
+
import { a as observe, n as docRevs, r as initMarks, s as recordChanged, t as docRev } from "./marks-koRsbHfe.mjs";
|
|
10
|
+
import { t as logReload } from "./perf-CCisg-ny.mjs";
|
|
9
11
|
import { closeSync, copyFileSync, existsSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, watch, writeFileSync } from "node:fs";
|
|
10
|
-
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
12
|
+
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
11
13
|
import { fileURLToPath } from "node:url";
|
|
12
14
|
import { randomBytes } from "node:crypto";
|
|
13
15
|
//#region src/shared/frames.ts
|
|
@@ -15,6 +17,130 @@ import { randomBytes } from "node:crypto";
|
|
|
15
17
|
* only an app frame does (#4). Empty counts as not content-only: the warning still helps there. */
|
|
16
18
|
const contentOnly = (frames) => frames.length > 0 && frames.every((f) => !!f.intent);
|
|
17
19
|
//#endregion
|
|
20
|
+
//#region src/server/updates.ts
|
|
21
|
+
/**
|
|
22
|
+
* Calm updates, the dev server's half (spec 26 Part 2). Frame documents take no updates from Vite:
|
|
23
|
+
* Fast Refresh is off under design/ (dev.ts) and the frame host's registry accepts every update and
|
|
24
|
+
* ignores it. Marver decides which frames an edit touched, before Vite's update collapses into that
|
|
25
|
+
* shared registry, and the shell reloads exactly those - a few at a time, on screen first.
|
|
26
|
+
*
|
|
27
|
+
* Which frames, two answers united:
|
|
28
|
+
* - by path: the edited file mapped directly - a frame, or a wrapper the frame host puts around
|
|
29
|
+
* frames (providers -> every TSX frame, a _layout or _fixtures file -> every TSX frame below it),
|
|
30
|
+
* which also covers a wrapper just created, before Vite has a module for it;
|
|
31
|
+
* - by graph: the edit's modules walked up their importers to frame modules, exact for every loaded
|
|
32
|
+
* document, the wrapper mapping applied wherever the walk reaches a wrapper.
|
|
33
|
+
* A walk that passes a module accepting its own updates (an app component under src/**, a stylesheet)
|
|
34
|
+
* has been applied in place: the frames past it are touched (marked) but not reloaded.
|
|
35
|
+
*
|
|
36
|
+
* Every other `full-reload` Vite or Tailwind sends is dropped and becomes reloads of the frames it
|
|
37
|
+
* names (or every frame, when it names none) - the shell never reloads for a design edit. The one
|
|
38
|
+
* that passes is the dependency optimiser's: module URLs changed, every document must reload.
|
|
39
|
+
*/
|
|
40
|
+
const safeReal = (p) => {
|
|
41
|
+
try {
|
|
42
|
+
return realpathSync(p);
|
|
43
|
+
} catch {
|
|
44
|
+
return p;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/** The frames an edit reaches: `doc` must reload to show it; `touched` saw it applied in place. */
|
|
48
|
+
function framesFor(root, manifest, file, modules, skipFirst = false) {
|
|
49
|
+
const real = safeReal(root);
|
|
50
|
+
const byFile = new Map(manifest.frames.flatMap((f) => [[join(root, f.file), f], [join(real, f.file), f]]));
|
|
51
|
+
const doc = /* @__PURE__ */ new Set(), touched = /* @__PURE__ */ new Set();
|
|
52
|
+
const wrapper = (f) => /(^|[/\\])(providers\.(tsx|jsx)|_layout\.(tsx|jsx)|_fixtures\.(ts|tsx|js|jsx|json))$/.test(f);
|
|
53
|
+
const add = (ids, inPlace) => {
|
|
54
|
+
for (const id of ids) (inPlace ? touched : doc).add(id);
|
|
55
|
+
};
|
|
56
|
+
add(affectedFrameIds(file, root, manifest) ?? [], false);
|
|
57
|
+
const seen = /* @__PURE__ */ new Map();
|
|
58
|
+
const queue = [];
|
|
59
|
+
for (const m of modules) {
|
|
60
|
+
if (skipFirst) {
|
|
61
|
+
for (const up of m.importers) queue.push([up, false]);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
queue.push([m, false]);
|
|
65
|
+
}
|
|
66
|
+
while (queue.length) {
|
|
67
|
+
const [m, inPlace] = queue.shift();
|
|
68
|
+
const had = seen.get(m);
|
|
69
|
+
if (had === false || had === inPlace) continue;
|
|
70
|
+
seen.set(m, inPlace);
|
|
71
|
+
const f = m.file ? byFile.get(m.file) : void 0;
|
|
72
|
+
if (f) (inPlace ? touched : doc).add(f.id);
|
|
73
|
+
if (m.file && wrapper(m.file)) add(affectedFrameIds(m.file, root, manifest) ?? [], inPlace);
|
|
74
|
+
const accepts = m.isSelfAccepting === true;
|
|
75
|
+
for (const up of m.importers) queue.push([up, inPlace || accepts]);
|
|
76
|
+
}
|
|
77
|
+
for (const id of doc) touched.delete(id);
|
|
78
|
+
return {
|
|
79
|
+
file,
|
|
80
|
+
doc: [...doc],
|
|
81
|
+
touched: [...touched]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** The hook that runs last on every hot update of the client environment. */
|
|
85
|
+
function updatesPlugin(root, manifest, hooks, landed) {
|
|
86
|
+
return {
|
|
87
|
+
name: "marver:updates",
|
|
88
|
+
hotUpdate: {
|
|
89
|
+
order: "post",
|
|
90
|
+
handler(opts) {
|
|
91
|
+
landed(opts.file);
|
|
92
|
+
if (this.environment.name !== "client") return;
|
|
93
|
+
const h = hooks();
|
|
94
|
+
if (!h) return;
|
|
95
|
+
const t = framesFor(root, manifest(), opts.file, opts.modules);
|
|
96
|
+
if (t.doc.length || t.touched.length) h.onFrames(t, "update");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** Wraps the client's hot channel: the reload guard and refused refreshes. */
|
|
102
|
+
function guardUpdates(server, root, manifest, hooks) {
|
|
103
|
+
const env = server.environments.client;
|
|
104
|
+
const wrap = (ch) => {
|
|
105
|
+
const send = ch.send.bind(ch);
|
|
106
|
+
ch.send = (...a) => {
|
|
107
|
+
const p = a[0];
|
|
108
|
+
if (typeof p === "object" && p?.type === "full-reload") {
|
|
109
|
+
const passed = p.path === "*" && !p.triggeredBy;
|
|
110
|
+
hooks.onReload({
|
|
111
|
+
triggeredBy: p.triggeredBy,
|
|
112
|
+
path: p.path
|
|
113
|
+
}, passed);
|
|
114
|
+
if (!passed) {
|
|
115
|
+
const by = p.triggeredBy ?? (p.path && p.path !== "*" ? join(root, p.path.replace(/^\//, "")) : void 0);
|
|
116
|
+
const mods = by ? env.moduleGraph.getModulesByFile(by) : void 0;
|
|
117
|
+
const all = manifest().frames.map((f) => f.id);
|
|
118
|
+
const t = by ? framesFor(root, manifest(), by, mods ?? []) : {
|
|
119
|
+
file: "",
|
|
120
|
+
doc: all,
|
|
121
|
+
touched: [],
|
|
122
|
+
unattributed: true
|
|
123
|
+
};
|
|
124
|
+
if (t.doc.length || t.touched.length) hooks.onFrames(t, "reload");
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
send(...a);
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
wrap(env.hot);
|
|
132
|
+
if (server.ws !== env.hot) wrap(server.ws);
|
|
133
|
+
const refused = /* @__PURE__ */ new Map();
|
|
134
|
+
env.hot.on("vite:invalidate", (payload) => {
|
|
135
|
+
const mod = payload?.path ? env.moduleGraph.urlToModuleMap.get(payload.path) : void 0;
|
|
136
|
+
if (!mod?.file) return;
|
|
137
|
+
if (refused.get(mod.url) === mod.lastHMRTimestamp) return;
|
|
138
|
+
refused.set(mod.url, mod.lastHMRTimestamp);
|
|
139
|
+
const t = framesFor(root, manifest(), mod.file, [mod], true);
|
|
140
|
+
if (t.doc.length || t.touched.length) hooks.onFrames(t, "invalidate");
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
18
144
|
//#region src/server/sizes.ts
|
|
19
145
|
/**
|
|
20
146
|
* Content-frame heights - `design/boards/_sizes.json`, committed.
|
|
@@ -237,6 +363,15 @@ function contained(target, base) {
|
|
|
237
363
|
}
|
|
238
364
|
}
|
|
239
365
|
function apiMiddleware(root, opts = {}) {
|
|
366
|
+
const devManifest = () => {
|
|
367
|
+
if (opts.manifest) return opts.manifest();
|
|
368
|
+
try {
|
|
369
|
+
return JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
|
|
370
|
+
} catch {
|
|
371
|
+
return scanFrames(root);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
const devFrames = () => devManifest().frames;
|
|
240
375
|
const boardsDir = join(root, "design", "boards");
|
|
241
376
|
const foldersPath = join(boardsDir, FOLDERS_FILE);
|
|
242
377
|
const boardPath = (name) => {
|
|
@@ -459,6 +594,30 @@ function apiMiddleware(root, opts = {}) {
|
|
|
459
594
|
return null;
|
|
460
595
|
}
|
|
461
596
|
};
|
|
597
|
+
if (path === "perf/reload" && req.method === "POST") {
|
|
598
|
+
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
599
|
+
const raw = await readBody(req);
|
|
600
|
+
if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
|
|
601
|
+
let b;
|
|
602
|
+
try {
|
|
603
|
+
b = JSON.parse(raw);
|
|
604
|
+
} catch {
|
|
605
|
+
return json(res, 400, { error: "malformed JSON" });
|
|
606
|
+
}
|
|
607
|
+
const str = (v) => typeof v === "string" ? v.slice(0, 200) : void 0;
|
|
608
|
+
const num = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v) : void 0;
|
|
609
|
+
if (!str(b?.kind)) return json(res, 400, { error: "kind required" });
|
|
610
|
+
(await import("./perf-CCisg-ny.mjs").then((n) => n.n)).logReload(root, {
|
|
611
|
+
kind: str(b.kind),
|
|
612
|
+
tab: str(b.tab),
|
|
613
|
+
node: str(b.node),
|
|
614
|
+
frame: str(b.frame),
|
|
615
|
+
cause: str(b.cause),
|
|
616
|
+
shown: str(b.shown),
|
|
617
|
+
ms: num(b.ms)
|
|
618
|
+
});
|
|
619
|
+
return json(res, 200, { ok: true });
|
|
620
|
+
}
|
|
462
621
|
if (path === "sizes" && req.method === "GET") {
|
|
463
622
|
const frames = readManifestFrames();
|
|
464
623
|
if (!frames) return json(res, 200, {
|
|
@@ -519,6 +678,30 @@ function apiMiddleware(root, opts = {}) {
|
|
|
519
678
|
sha256: reg.sha256
|
|
520
679
|
});
|
|
521
680
|
}
|
|
681
|
+
if (path === "membership" && req.method === "GET") {
|
|
682
|
+
const de = dirError();
|
|
683
|
+
if (de) return json(res, 422, { error: de });
|
|
684
|
+
return json(res, 200, readMembership(root, scanFrames(root).frames.map((f) => f.id)));
|
|
685
|
+
}
|
|
686
|
+
if (path === "boards/pin" && req.method === "POST") {
|
|
687
|
+
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
688
|
+
const raw = await readBody(req);
|
|
689
|
+
if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
|
|
690
|
+
let parsed;
|
|
691
|
+
try {
|
|
692
|
+
parsed = JSON.parse(raw);
|
|
693
|
+
} catch {
|
|
694
|
+
return json(res, 400, { error: "malformed JSON" });
|
|
695
|
+
}
|
|
696
|
+
const live = scanFrames(root).frames.map((f) => f.id);
|
|
697
|
+
const frames = Array.isArray(parsed?.frames) ? parsed.frames.filter((f) => typeof f === "string" && live.includes(f)) : [];
|
|
698
|
+
if (!validName(parsed?.board) || !frames.length) return json(res, 400, { error: "a board and frames on this canvas" });
|
|
699
|
+
try {
|
|
700
|
+
return json(res, 200, pinFrames(root, parsed.board, frames, live));
|
|
701
|
+
} catch (err) {
|
|
702
|
+
return json(res, 409, { error: err.message });
|
|
703
|
+
}
|
|
704
|
+
}
|
|
522
705
|
if (path === "boards/rename" && req.method === "POST") {
|
|
523
706
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
524
707
|
const raw = await readBody(req);
|
|
@@ -788,6 +971,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
788
971
|
});
|
|
789
972
|
}
|
|
790
973
|
if (req.method === "PUT") {
|
|
974
|
+
if (boardMatch[1] === "all-scenes") return json(res, 400, { error: `"${ALL_SCENES}" is a reserved name` });
|
|
791
975
|
const raw = await readBody(req);
|
|
792
976
|
if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
|
|
793
977
|
let body;
|
|
@@ -825,7 +1009,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
825
1009
|
}
|
|
826
1010
|
}
|
|
827
1011
|
if (path === "shot" && req.method === "GET") {
|
|
828
|
-
const { readDevInfo } = await import("./work-
|
|
1012
|
+
const { readDevInfo } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
|
|
829
1013
|
const token = readDevInfo(root)?.token;
|
|
830
1014
|
if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
|
|
831
1015
|
const frameId = url.searchParams.get("frame") ?? "";
|
|
@@ -841,7 +1025,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
841
1025
|
};
|
|
842
1026
|
const asPng = url.searchParams.get("format") === "png";
|
|
843
1027
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
844
|
-
const { shootFrame } = await import("./shot-
|
|
1028
|
+
const { shootFrame } = await import("./shot-CckrGW-J.mjs");
|
|
845
1029
|
const r = await shootFrame({
|
|
846
1030
|
root,
|
|
847
1031
|
viewports: opts.viewports ?? {},
|
|
@@ -874,7 +1058,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
874
1058
|
return res.end(png);
|
|
875
1059
|
}
|
|
876
1060
|
if (path === "shots" && req.method === "POST") {
|
|
877
|
-
const { readDevInfo } = await import("./work-
|
|
1061
|
+
const { readDevInfo } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
|
|
878
1062
|
const token = readDevInfo(root)?.token;
|
|
879
1063
|
if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
|
|
880
1064
|
const raw = await readBody(req);
|
|
@@ -891,7 +1075,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
891
1075
|
if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
|
|
892
1076
|
const scale = body.scale === void 0 ? void 0 : body.scale;
|
|
893
1077
|
if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) return json(res, 400, { error: "invalid scale" });
|
|
894
|
-
const { resolveFrames, shootBatch } = await import("./shot-
|
|
1078
|
+
const { resolveFrames, shootBatch } = await import("./shot-CckrGW-J.mjs");
|
|
895
1079
|
const sel = resolveFrames(root, body);
|
|
896
1080
|
if (!sel.ok) return json(res, sel.status, { error: sel.error });
|
|
897
1081
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
@@ -908,6 +1092,40 @@ function apiMiddleware(root, opts = {}) {
|
|
|
908
1092
|
return json(res, 503, { error: err.message });
|
|
909
1093
|
}
|
|
910
1094
|
}
|
|
1095
|
+
if (path === "anchor" && req.method === "POST") {
|
|
1096
|
+
const { readDevInfo } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
|
|
1097
|
+
const token = readDevInfo(root)?.token;
|
|
1098
|
+
if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
|
|
1099
|
+
const raw = await readBody(req);
|
|
1100
|
+
if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
|
|
1101
|
+
let b;
|
|
1102
|
+
try {
|
|
1103
|
+
b = JSON.parse(raw);
|
|
1104
|
+
} catch {
|
|
1105
|
+
return json(res, 400, { error: "malformed JSON" });
|
|
1106
|
+
}
|
|
1107
|
+
const { readTarget } = await import("./anchor-DVV732zR.mjs");
|
|
1108
|
+
const target = readTarget(b ?? {});
|
|
1109
|
+
if (typeof target === "string") return json(res, 400, { error: target });
|
|
1110
|
+
const others = Array.isArray(b.others) ? b.others.filter((o) => typeof o?.key === "string").slice(0, 200) : [];
|
|
1111
|
+
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
1112
|
+
const { checkAnchor, CheckInputError } = await import("./anchor-check-BE5VVN6Q.mjs");
|
|
1113
|
+
try {
|
|
1114
|
+
return json(res, 200, await checkAnchor({
|
|
1115
|
+
root,
|
|
1116
|
+
viewports: opts.viewports ?? {},
|
|
1117
|
+
origin,
|
|
1118
|
+
frameId: String(b.frame ?? ""),
|
|
1119
|
+
target,
|
|
1120
|
+
others,
|
|
1121
|
+
viewport: typeof b.viewport === "string" ? b.viewport : void 0,
|
|
1122
|
+
theme: typeof b.theme === "string" ? b.theme : void 0
|
|
1123
|
+
}));
|
|
1124
|
+
} catch (err) {
|
|
1125
|
+
if (err instanceof CheckInputError) return json(res, 400, { error: err.message });
|
|
1126
|
+
throw err;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
911
1129
|
if (path === "bakes" && req.method === "POST") {
|
|
912
1130
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
913
1131
|
const raw = await readBody(req);
|
|
@@ -919,13 +1137,14 @@ function apiMiddleware(root, opts = {}) {
|
|
|
919
1137
|
return json(res, 400, { error: "malformed JSON" });
|
|
920
1138
|
}
|
|
921
1139
|
if (!body || typeof body !== "object" || !Array.isArray(body.asks) || !body.asks.length || body.asks.length > 200) return json(res, 400, { error: "asks must list 1-200 frames" });
|
|
922
|
-
const { bakeBatch, ASK_MAX } = await import("./bake-
|
|
1140
|
+
const { bakeBatch, ASK_MAX } = await import("./bake-D8byeRzB.mjs");
|
|
923
1141
|
let manifest = {};
|
|
924
1142
|
try {
|
|
925
1143
|
manifest = JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
|
|
926
1144
|
} catch {}
|
|
927
1145
|
const frames = new Map((manifest.frames ?? []).map((f) => [f.id, f]));
|
|
928
1146
|
const asks = [];
|
|
1147
|
+
const docs = [];
|
|
929
1148
|
for (const a of body.asks) {
|
|
930
1149
|
const frame = typeof a?.frame === "string" ? a.frame : "";
|
|
931
1150
|
const theme = typeof a?.theme === "string" && /^[a-z0-9-]{1,32}$/i.test(a.theme) ? a.theme : "";
|
|
@@ -937,34 +1156,52 @@ function apiMiddleware(root, opts = {}) {
|
|
|
937
1156
|
w,
|
|
938
1157
|
h
|
|
939
1158
|
});
|
|
1159
|
+
docs.push(typeof a?.doc === "string" ? a.doc : void 0);
|
|
940
1160
|
}
|
|
1161
|
+
const { docRev } = await import("./marks-koRsbHfe.mjs").then((n) => n.i);
|
|
1162
|
+
const all = devManifest().frames;
|
|
1163
|
+
const pending = opts.settled ? !opts.settled() : false;
|
|
1164
|
+
const behind = docs.map((d, i) => d !== void 0 && (pending || d !== docRev(root, all, asks[i].frame)));
|
|
941
1165
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
942
1166
|
const { ROUTE } = await import("./cli.mjs").then((n) => n.t);
|
|
943
1167
|
const gen = opts.bakeGen?.() ?? 0;
|
|
1168
|
+
const baked = await bakeBatch({
|
|
1169
|
+
root,
|
|
1170
|
+
gen,
|
|
1171
|
+
asks: asks.filter((_, i) => !behind[i]),
|
|
1172
|
+
live: () => opts.bakeGen?.() ?? 0,
|
|
1173
|
+
log: (a) => {
|
|
1174
|
+
if (a.ok) console.log(` bake: ${a.frame} ${a.theme} ${a.w}x${a.h} - ${a.targets.length} effects, ${a.rejected} stay live, ${a.ms} ms`);
|
|
1175
|
+
else console.log(` bake: ${a.frame} ${a.theme} ${a.w}x${a.h} - stays live: ${a.error}`);
|
|
1176
|
+
},
|
|
1177
|
+
urlFor: (ask) => {
|
|
1178
|
+
const f = frames.get(ask.frame);
|
|
1179
|
+
return f.kind === "html" ? `${origin}/${f.file}?theme=${encodeURIComponent(ask.theme)}` : `${origin}${ROUTE}/frame/?id=${encodeURIComponent(ask.frame)}&theme=${encodeURIComponent(ask.theme)}`;
|
|
1180
|
+
},
|
|
1181
|
+
urlBase: `${ROUTE}/bakes`
|
|
1182
|
+
});
|
|
1183
|
+
const after = docs.map((d, i) => d !== void 0 && (!!opts.settled && !opts.settled() || d !== docRev(root, devManifest().frames, asks[i].frame)));
|
|
1184
|
+
let k = 0;
|
|
944
1185
|
return json(res, 200, {
|
|
945
1186
|
gen,
|
|
946
|
-
answers:
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
const f = frames.get(ask.frame);
|
|
957
|
-
return f.kind === "html" ? `${origin}/${f.file}?theme=${encodeURIComponent(ask.theme)}` : `${origin}${ROUTE}/frame/?id=${encodeURIComponent(ask.frame)}&theme=${encodeURIComponent(ask.theme)}`;
|
|
958
|
-
},
|
|
959
|
-
urlBase: `${ROUTE}/bakes`
|
|
1187
|
+
answers: asks.map((a, i) => {
|
|
1188
|
+
const r = behind[i] ? null : baked[k++];
|
|
1189
|
+
return {
|
|
1190
|
+
...r && !after[i] ? r : {
|
|
1191
|
+
...a,
|
|
1192
|
+
ok: false,
|
|
1193
|
+
error: "the document is behind its frame"
|
|
1194
|
+
},
|
|
1195
|
+
...docs[i] ? { doc: docs[i] } : {}
|
|
1196
|
+
};
|
|
960
1197
|
})
|
|
961
1198
|
});
|
|
962
1199
|
}
|
|
963
1200
|
if (path === "poster" && req.method === "GET") {
|
|
964
1201
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
965
1202
|
const src = url.searchParams.get("src") ?? "";
|
|
966
|
-
const { ensurePoster, isLocalClip } = await import("./poster-
|
|
967
|
-
const { isLocalAssetRef } = await import("./build-
|
|
1203
|
+
const { ensurePoster, isLocalClip } = await import("./poster-D0cbV7hi.mjs");
|
|
1204
|
+
const { isLocalAssetRef } = await import("./build-BHoWLvSj.mjs");
|
|
968
1205
|
if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
|
|
969
1206
|
const r = await ensurePoster(join(root, "design", "assets"), src);
|
|
970
1207
|
if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
|
|
@@ -991,7 +1228,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
991
1228
|
}
|
|
992
1229
|
const dir = join(root, "design", ".local");
|
|
993
1230
|
mkdirSync(dir, { recursive: true });
|
|
994
|
-
const { validAvatar } = await import("./collab-
|
|
1231
|
+
const { validAvatar } = await import("./collab-gqNdScUE.mjs");
|
|
995
1232
|
let cur = {};
|
|
996
1233
|
try {
|
|
997
1234
|
cur = JSON.parse(readFileSync(join(dir, "profile.json"), "utf8"));
|
|
@@ -1005,15 +1242,36 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1005
1242
|
atomicWrite(join(dir, "profile.json"), JSON.stringify(prof, null, 2) + "\n");
|
|
1006
1243
|
return json(res, 200, { user: localProfile(root) });
|
|
1007
1244
|
}
|
|
1245
|
+
if (path === "marks" || path === "marks/seen") {
|
|
1246
|
+
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
1247
|
+
const { readMarks, markSeen } = await import("./marks-koRsbHfe.mjs").then((n) => n.i);
|
|
1248
|
+
const manifest = devManifest();
|
|
1249
|
+
if (path === "marks" && req.method === "GET") return json(res, 200, readMarks(root, manifest));
|
|
1250
|
+
if (path === "marks/seen" && req.method === "POST") {
|
|
1251
|
+
const raw = await readBody(req);
|
|
1252
|
+
if (raw == null) return json(res, 400, { error: "body too large" });
|
|
1253
|
+
let b;
|
|
1254
|
+
try {
|
|
1255
|
+
b = JSON.parse(raw);
|
|
1256
|
+
} catch {
|
|
1257
|
+
return json(res, 400, { error: "malformed JSON" });
|
|
1258
|
+
}
|
|
1259
|
+
if (!b?.frames || typeof b.frames !== "object" || Array.isArray(b.frames)) return json(res, 400, { error: "frames: { id: revision } required" });
|
|
1260
|
+
if (!markSeen(root, manifest.frames, b.epoch, b.frames)) return json(res, 409, { error: "the marks started over - read them again" });
|
|
1261
|
+
opts.notify?.("sh:marks");
|
|
1262
|
+
return json(res, 200, { ok: true });
|
|
1263
|
+
}
|
|
1264
|
+
return json(res, 405, { error: "method not allowed" });
|
|
1265
|
+
}
|
|
1008
1266
|
if (path === "work") {
|
|
1009
|
-
const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-
|
|
1267
|
+
const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
|
|
1010
1268
|
const tokenOk = () => {
|
|
1011
1269
|
const t = readDevInfo(root)?.token;
|
|
1012
1270
|
return !!t && req.headers["x-mv-work"] === t;
|
|
1013
1271
|
};
|
|
1014
1272
|
if (req.method === "GET") {
|
|
1015
1273
|
if (!ownerGated(req) && !tokenOk()) return json(res, 403, { error: "forbidden" });
|
|
1016
|
-
const { boardsShowing, activityClock } = await import("./work-
|
|
1274
|
+
const { boardsShowing, activityClock } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
|
|
1017
1275
|
const frames = workActivity.active();
|
|
1018
1276
|
return json(res, 200, {
|
|
1019
1277
|
frames,
|
|
@@ -1034,13 +1292,22 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1034
1292
|
const frames = Array.isArray(b.frames) ? b.frames.filter((f) => typeof f === "string" && f) : [];
|
|
1035
1293
|
const on = b.on !== false;
|
|
1036
1294
|
if (!on && b.all === true) {
|
|
1295
|
+
const done = workActivity.active().filter((f) => workActivity.has(f, "cli"));
|
|
1296
|
+
if (done.length) {
|
|
1297
|
+
(await import("./marks-koRsbHfe.mjs").then((n) => n.i)).recordChanged(root, devFrames(), done, { doc: false });
|
|
1298
|
+
opts.notify?.("sh:marks");
|
|
1299
|
+
}
|
|
1037
1300
|
workActivity.clearAll("cli");
|
|
1038
1301
|
return json(res, 200, { frames: workActivity.active() });
|
|
1039
1302
|
}
|
|
1040
1303
|
if (!frames.length) return json(res, 400, { error: "frames required" });
|
|
1041
1304
|
const ttl = Math.min(Math.max(Number(b.ttlMs) || WORK_TTL_DEFAULT, 1e4), WORK_TTL_MAX);
|
|
1042
1305
|
for (const f of frames) on ? workActivity.mark(f, ttl, "cli") : workActivity.clear(f, "cli");
|
|
1043
|
-
if (!on)
|
|
1306
|
+
if (!on) {
|
|
1307
|
+
(await import("./marks-koRsbHfe.mjs").then((n) => n.i)).recordChanged(root, devFrames(), frames, { doc: false });
|
|
1308
|
+
opts.notify?.("sh:marks");
|
|
1309
|
+
return json(res, 200, { frames: workActivity.active() });
|
|
1310
|
+
}
|
|
1044
1311
|
let behind = [];
|
|
1045
1312
|
let contextPresent = false;
|
|
1046
1313
|
try {
|
|
@@ -1072,7 +1339,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1072
1339
|
}
|
|
1073
1340
|
}
|
|
1074
1341
|
if (path === "boards.rights" && req.method === "GET") {
|
|
1075
|
-
const { listBoards } = await import("./comments-
|
|
1342
|
+
const { listBoards } = await import("./comments-Zoch254k.mjs").then((n) => n.n);
|
|
1076
1343
|
return json(res, 200, {
|
|
1077
1344
|
local: true,
|
|
1078
1345
|
stored: listBoards(join(root, "design", "comments"))
|
|
@@ -1080,7 +1347,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1080
1347
|
}
|
|
1081
1348
|
const cm = /^comments\/([a-z0-9][a-z0-9-]*)$/.exec(path);
|
|
1082
1349
|
if (cm) {
|
|
1083
|
-
const { appendEvents, readLog } = await import("./comments-
|
|
1350
|
+
const { appendEvents, readLog } = await import("./comments-Zoch254k.mjs").then((n) => n.n);
|
|
1084
1351
|
const dir = join(root, "design", "comments");
|
|
1085
1352
|
if (req.method === "GET") return json(res, 200, { events: readLog(dir, cm[1]) });
|
|
1086
1353
|
if (req.method === "POST") {
|
|
@@ -1116,7 +1383,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1116
1383
|
}
|
|
1117
1384
|
}
|
|
1118
1385
|
if (path === "sync" && req.method === "POST") {
|
|
1119
|
-
const { loadCollab, syncOnce } = await import("./sync-
|
|
1386
|
+
const { loadCollab, syncOnce } = await import("./sync-C3035OnJ.mjs").then((n) => n.o);
|
|
1120
1387
|
const collab = loadCollab(root);
|
|
1121
1388
|
if (!collab) return json(res, 200, { connected: false });
|
|
1122
1389
|
try {
|
|
@@ -1145,7 +1412,7 @@ function backgroundPush(root) {
|
|
|
1145
1412
|
pushTimer = setTimeout(async () => {
|
|
1146
1413
|
pushTimer = null;
|
|
1147
1414
|
try {
|
|
1148
|
-
const { loadCollab, syncOnce } = await import("./sync-
|
|
1415
|
+
const { loadCollab, syncOnce } = await import("./sync-C3035OnJ.mjs").then((n) => n.o);
|
|
1149
1416
|
const collab = loadCollab(root);
|
|
1150
1417
|
if (collab) await syncOnce(root, collab);
|
|
1151
1418
|
} catch {}
|
|
@@ -1153,12 +1420,7 @@ function backgroundPush(root) {
|
|
|
1153
1420
|
}
|
|
1154
1421
|
//#endregion
|
|
1155
1422
|
//#region src/server/routes.ts
|
|
1156
|
-
|
|
1157
|
-
* Serves the package's own pages. transformIndexHtml does not map URLs - we do (spec §3).
|
|
1158
|
-
* Entry html files carry an {{ENTRY}} placeholder replaced with an /@fs/ absolute path,
|
|
1159
|
-
* because a relative ./main.tsx would resolve against the URL, not the package dir.
|
|
1160
|
-
*/
|
|
1161
|
-
function routesMiddleware(server, clientDir) {
|
|
1423
|
+
function routesMiddleware(server, clientDir, stamps) {
|
|
1162
1424
|
const page = (dir) => {
|
|
1163
1425
|
const html = readFileSync(join(clientDir, dir, "index.html"), "utf8");
|
|
1164
1426
|
const entry = "/@fs/" + join(clientDir, dir, "main.tsx").split("\\").join("/");
|
|
@@ -1170,7 +1432,8 @@ function routesMiddleware(server, clientDir) {
|
|
|
1170
1432
|
webmanifest: "application/manifest+json"
|
|
1171
1433
|
};
|
|
1172
1434
|
return async (req, res, next) => {
|
|
1173
|
-
const
|
|
1435
|
+
const url = new URL(req.url ?? "/", "http://x");
|
|
1436
|
+
const path = url.pathname;
|
|
1174
1437
|
let dir = null;
|
|
1175
1438
|
if (path === "/" || path === "/index.html") dir = "shell";
|
|
1176
1439
|
else if (path === `/__mv/frame/` || path === `/__mv/frame/index.html`) dir = "frame-host";
|
|
@@ -1210,7 +1473,9 @@ function routesMiddleware(server, clientDir) {
|
|
|
1210
1473
|
}
|
|
1211
1474
|
if (!dir) return next();
|
|
1212
1475
|
try {
|
|
1213
|
-
const
|
|
1476
|
+
const stamp = dir === "frame-host" ? stamps?.doc(url.searchParams.get("id") ?? "") : dir === "stage" ? JSON.stringify(stamps?.docs() ?? null) : void 0;
|
|
1477
|
+
let html = await server.transformIndexHtml(req.url ?? "/", page(dir));
|
|
1478
|
+
if (stamp) html = html.replace("<head>", `<head><meta name="mv-doc" content="${stamp.replace(/[&"<>]/g, (c) => `&#${c.charCodeAt(0)};`)}">`);
|
|
1214
1479
|
res.setHeader("content-type", "text/html");
|
|
1215
1480
|
res.setHeader("cache-control", "no-store");
|
|
1216
1481
|
res.end(html);
|
|
@@ -1312,11 +1577,102 @@ function marverPlugin(ctx) {
|
|
|
1312
1577
|
if (!devServer || !pendingInv.size) return;
|
|
1313
1578
|
const frameIds = [...pendingInv];
|
|
1314
1579
|
pendingInv.clear();
|
|
1580
|
+
const docs = docRevs(root, manifest.frames);
|
|
1315
1581
|
devServer.ws.send("sh:frame-invalidated", {
|
|
1316
1582
|
frameIds,
|
|
1317
|
-
revision: `${bootId}:${++invRev}
|
|
1583
|
+
revision: `${bootId}:${++invRev}`,
|
|
1584
|
+
epoch: docs?.epoch,
|
|
1585
|
+
docs: docs ? Object.fromEntries(frameIds.map((id) => [id, docs.doc[id] ?? 0])) : void 0
|
|
1318
1586
|
});
|
|
1319
1587
|
}, 120);
|
|
1588
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
1589
|
+
const late = /* @__PURE__ */ new Map();
|
|
1590
|
+
const envs = () => Object.keys(devServer?.environments ?? { client: 1 }).length;
|
|
1591
|
+
const waiting = [];
|
|
1592
|
+
const settled = () => inFlight.size === 0;
|
|
1593
|
+
const whenSettled = (fn) => {
|
|
1594
|
+
if (settled()) fn();
|
|
1595
|
+
else waiting.push(fn);
|
|
1596
|
+
};
|
|
1597
|
+
const drain = () => {
|
|
1598
|
+
if (settled()) for (const fn of waiting.splice(0)) try {
|
|
1599
|
+
fn();
|
|
1600
|
+
} catch (e) {
|
|
1601
|
+
console.warn(`[marver] ${e.message}`);
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
const done = (file) => {
|
|
1605
|
+
const f = inFlight.get(file);
|
|
1606
|
+
if (!f) return;
|
|
1607
|
+
if (--f.events > 0) return;
|
|
1608
|
+
clearTimeout(f.timer);
|
|
1609
|
+
inFlight.delete(file);
|
|
1610
|
+
drain();
|
|
1611
|
+
};
|
|
1612
|
+
const flying = (file) => {
|
|
1613
|
+
const f = inFlight.get(file) ?? {
|
|
1614
|
+
events: 0,
|
|
1615
|
+
hits: 0,
|
|
1616
|
+
timer: void 0
|
|
1617
|
+
};
|
|
1618
|
+
f.events++;
|
|
1619
|
+
clearTimeout(f.timer);
|
|
1620
|
+
f.timer = setTimeout(() => {
|
|
1621
|
+
for (const env of Object.values(devServer?.environments ?? {})) env.moduleGraph.invalidateAll();
|
|
1622
|
+
late.set(file, (late.get(file) ?? 0) + f.events * envs() - f.hits);
|
|
1623
|
+
inFlight.delete(file);
|
|
1624
|
+
drain();
|
|
1625
|
+
}, 1e4);
|
|
1626
|
+
inFlight.set(file, f);
|
|
1627
|
+
};
|
|
1628
|
+
const landed = (file) => {
|
|
1629
|
+
const owed = late.get(file);
|
|
1630
|
+
if (owed) {
|
|
1631
|
+
if (owed > 1) late.set(file, owed - 1);
|
|
1632
|
+
else late.delete(file);
|
|
1633
|
+
return;
|
|
1634
|
+
}
|
|
1635
|
+
const f = inFlight.get(file);
|
|
1636
|
+
if (!f) return;
|
|
1637
|
+
if (++f.hits < envs()) return;
|
|
1638
|
+
f.hits = 0;
|
|
1639
|
+
setTimeout(() => done(file), 0);
|
|
1640
|
+
};
|
|
1641
|
+
const observeMarks = () => observed(observe(root, manifest.frames));
|
|
1642
|
+
const observeLater = () => whenSettled(() => {
|
|
1643
|
+
if (observeMarks()) devServer?.ws.send("sh:marks", {});
|
|
1644
|
+
});
|
|
1645
|
+
const hooks = {
|
|
1646
|
+
onFrames: (t, cause) => {
|
|
1647
|
+
setTimeout(() => whenSettled(() => record(t, cause)), 0);
|
|
1648
|
+
},
|
|
1649
|
+
onReload(p, passed) {
|
|
1650
|
+
logReload(root, {
|
|
1651
|
+
kind: "full-reload",
|
|
1652
|
+
passed,
|
|
1653
|
+
triggeredBy: p.triggeredBy ?? null,
|
|
1654
|
+
path: p.path ?? null
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
function record(t, cause) {
|
|
1659
|
+
const seen = observe(root, manifest.frames, t.file ? { file: t.file } : {});
|
|
1660
|
+
const doc = t.unattributed ? [] : t.doc.filter((id) => !seen.doc.includes(id));
|
|
1661
|
+
const touched = t.touched.filter((id) => !seen.doc.includes(id) && !seen.note.includes(id) && !doc.includes(id));
|
|
1662
|
+
if (doc.length) recordChanged(root, manifest.frames, doc, { doc: true });
|
|
1663
|
+
if (touched.length) recordChanged(root, manifest.frames, touched, { doc: false });
|
|
1664
|
+
const reload = [.../* @__PURE__ */ new Set([...seen.doc, ...t.doc])];
|
|
1665
|
+
for (const id of reload) pendingInv.add(id);
|
|
1666
|
+
flushInv();
|
|
1667
|
+
if (reload.length || touched.length || seen.note.length) devServer?.ws.send("sh:marks", {});
|
|
1668
|
+
logReload(root, {
|
|
1669
|
+
kind: "update",
|
|
1670
|
+
cause,
|
|
1671
|
+
file: t.file ? relative(root, t.file).split(sep).join("/") : null,
|
|
1672
|
+
reload,
|
|
1673
|
+
inPlace: t.touched
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1320
1676
|
/** No theme is only a problem for app frames: a canvas made of content frames alone (Doc, Md,
|
|
1321
1677
|
* Diagram ship their own styling) needs none (#4). The shell decides its banner from the live
|
|
1322
1678
|
* manifest; the config carries only whether a theme exists. */
|
|
@@ -1329,8 +1685,11 @@ function marverPlugin(ctx) {
|
|
|
1329
1685
|
if (ctx.detectedThemeCss && existsSync(join(root, ctx.detectedThemeCss))) return join(root, ctx.detectedThemeCss);
|
|
1330
1686
|
return null;
|
|
1331
1687
|
};
|
|
1332
|
-
return {
|
|
1688
|
+
return [{
|
|
1333
1689
|
name: "marver",
|
|
1690
|
+
watchChange(id) {
|
|
1691
|
+
if (devServer) flying(id);
|
|
1692
|
+
},
|
|
1334
1693
|
enforce: "pre",
|
|
1335
1694
|
resolveId(id) {
|
|
1336
1695
|
if (id === VIRTUAL_THEME) return themeFile() ?? "\0virtual:sh-theme.css";
|
|
@@ -1369,43 +1728,40 @@ function marverPlugin(ctx) {
|
|
|
1369
1728
|
transformIndexHtml: {
|
|
1370
1729
|
order: "pre",
|
|
1371
1730
|
handler(html, hctx) {
|
|
1372
|
-
|
|
1731
|
+
const path = (hctx.originalUrl ?? hctx.path ?? "").split("?")[0];
|
|
1732
|
+
if (!path.startsWith("/design/")) return;
|
|
1373
1733
|
const bridge = "/@fs/" + join(clientDir, "frame-host", "bridge.js").split("\\").join("/") + "?html=1";
|
|
1734
|
+
const frame = manifest.frames.find((f) => "/" + f.file === path);
|
|
1735
|
+
const stamp = frame ? docRev(root, manifest.frames, frame.id) : "";
|
|
1374
1736
|
return {
|
|
1375
1737
|
html,
|
|
1376
|
-
tags: [
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1738
|
+
tags: [
|
|
1739
|
+
{
|
|
1740
|
+
tag: "script",
|
|
1741
|
+
attrs: { type: "module" },
|
|
1742
|
+
children: `import '${VIRTUAL_THEME}'`,
|
|
1743
|
+
injectTo: "head-prepend"
|
|
1744
|
+
},
|
|
1745
|
+
{
|
|
1746
|
+
tag: "script",
|
|
1747
|
+
attrs: {
|
|
1748
|
+
type: "module",
|
|
1749
|
+
src: bridge
|
|
1750
|
+
},
|
|
1751
|
+
injectTo: "head-prepend"
|
|
1386
1752
|
},
|
|
1387
|
-
|
|
1388
|
-
|
|
1753
|
+
...stamp ? [{
|
|
1754
|
+
tag: "meta",
|
|
1755
|
+
attrs: {
|
|
1756
|
+
name: "mv-doc",
|
|
1757
|
+
content: stamp
|
|
1758
|
+
},
|
|
1759
|
+
injectTo: "head-prepend"
|
|
1760
|
+
}] : []
|
|
1761
|
+
]
|
|
1389
1762
|
};
|
|
1390
1763
|
}
|
|
1391
1764
|
},
|
|
1392
|
-
/**
|
|
1393
|
-
* Frame add/unlink is OUR event (sh:manifest → shell appends/flags nodes); Vite's default for
|
|
1394
|
-
* an out-of-graph file is a full-reload broadcast to every client, shell included. Suppress it.
|
|
1395
|
-
* Edits to loaded frames keep normal HMR (modules present + file exists → pass through).
|
|
1396
|
-
*/
|
|
1397
|
-
handleHotUpdate(hctx) {
|
|
1398
|
-
const affected = affectedFrameIds(hctx.file, root, manifest);
|
|
1399
|
-
if (affected === null) {
|
|
1400
|
-
if ([join(root, "design", "scenes"), join(root, "design", "components")].some((w) => hctx.file.startsWith(w)) && !existsSync(hctx.file)) return [];
|
|
1401
|
-
return;
|
|
1402
|
-
}
|
|
1403
|
-
if (affected.length) {
|
|
1404
|
-
for (const id of affected) pendingInv.add(id);
|
|
1405
|
-
flushInv();
|
|
1406
|
-
}
|
|
1407
|
-
return [];
|
|
1408
|
-
},
|
|
1409
1765
|
configureServer(server) {
|
|
1410
1766
|
let bakeGen = Date.now();
|
|
1411
1767
|
server.middlewares.use((req, res, next) => {
|
|
@@ -1435,18 +1791,36 @@ function marverPlugin(ctx) {
|
|
|
1435
1791
|
if (!a || typeof a === "string") return null;
|
|
1436
1792
|
return `http://${a.family === "IPv6" ? a.address === "::" ? "[::1]" : `[${a.address}]` : a.address === "0.0.0.0" ? "127.0.0.1" : a.address}:${a.port}`;
|
|
1437
1793
|
};
|
|
1794
|
+
initMarks(root, manifest.frames);
|
|
1438
1795
|
server.middlewares.use(apiMiddleware(root, {
|
|
1439
1796
|
viewports: config.viewports,
|
|
1440
1797
|
origin: listeningOrigin,
|
|
1441
|
-
bakeGen: () => bakeGen
|
|
1798
|
+
bakeGen: () => bakeGen,
|
|
1799
|
+
notify: (event) => server.ws.send(event, {}),
|
|
1800
|
+
manifest: () => manifest,
|
|
1801
|
+
settled
|
|
1802
|
+
}));
|
|
1803
|
+
server.middlewares.use(routesMiddleware(server, clientDir, {
|
|
1804
|
+
doc: (id) => docRev(root, manifest.frames, id),
|
|
1805
|
+
docs: () => docRevs(root, manifest.frames)
|
|
1442
1806
|
}));
|
|
1443
|
-
server.middlewares.use(routesMiddleware(server, clientDir));
|
|
1444
1807
|
devServer = server;
|
|
1808
|
+
guardUpdates(server, root, () => manifest, hooks);
|
|
1445
1809
|
let framesKey = JSON.stringify(manifest.frames);
|
|
1446
1810
|
let scenesKey = JSON.stringify(manifest.scenes);
|
|
1811
|
+
let unplacedKey = "";
|
|
1812
|
+
const sayUnplaced = () => {
|
|
1813
|
+
const { unplaced } = readMembership(root, manifest.frames.map((f) => f.id));
|
|
1814
|
+
const key = unplaced.join(",");
|
|
1815
|
+
if (key && key !== unplacedKey) console.log(`[${NAME}] not on a board (${unplaced.length}): ${unplaced.join(", ")} - every frame goes on the board it belongs to: npx ${NAME} boards pin <board> <scene/frame ...>`);
|
|
1816
|
+
unplacedKey = key;
|
|
1817
|
+
};
|
|
1818
|
+
sayUnplaced();
|
|
1447
1819
|
const regen = debounce(() => {
|
|
1448
1820
|
manifest = scanFrames(root, projectInfo());
|
|
1821
|
+
sayUnplaced();
|
|
1449
1822
|
const changed = writeManifest(root, manifest);
|
|
1823
|
+
observeLater();
|
|
1450
1824
|
const key = JSON.stringify(manifest.frames), sKey = JSON.stringify(manifest.scenes);
|
|
1451
1825
|
if (changed && key !== framesKey) server.ws.send("sh:manifest", manifest);
|
|
1452
1826
|
else if (changed && sKey !== scenesKey) server.ws.send("sh:scenes", { scenes: manifest.scenes });
|
|
@@ -1484,7 +1858,7 @@ function marverPlugin(ctx) {
|
|
|
1484
1858
|
};
|
|
1485
1859
|
const prune = () => setTimeout(async () => {
|
|
1486
1860
|
try {
|
|
1487
|
-
(await import("./bake-
|
|
1861
|
+
(await import("./bake-D8byeRzB.mjs")).pruneBakes(root, bakeGen);
|
|
1488
1862
|
} catch {}
|
|
1489
1863
|
}, 500);
|
|
1490
1864
|
prune();
|
|
@@ -1517,6 +1891,14 @@ function marverPlugin(ctx) {
|
|
|
1517
1891
|
server.watcher.on("unlink", restatus);
|
|
1518
1892
|
server.watcher.on("change", restatus);
|
|
1519
1893
|
server.watcher.on("change", (f) => inScope(f) && (/\.(tsx|jsx)$/.test(f) || f.endsWith("_brief.md") || isNoteFile(f)) && regen());
|
|
1894
|
+
const marksChanged = debounce(observeLater, 300);
|
|
1895
|
+
for (const ev of [
|
|
1896
|
+
"add",
|
|
1897
|
+
"change",
|
|
1898
|
+
"unlink"
|
|
1899
|
+
]) server.watcher.on(ev, (f) => {
|
|
1900
|
+
if (!f.startsWith(localDir) && !f.startsWith(boardsDirGen)) marksChanged();
|
|
1901
|
+
});
|
|
1520
1902
|
const configFile = join(root, "design", "config.ts");
|
|
1521
1903
|
server.watcher.on("change", (f) => {
|
|
1522
1904
|
if (f !== configFile) return;
|
|
@@ -1542,9 +1924,10 @@ function marverPlugin(ctx) {
|
|
|
1542
1924
|
if (!checkBoardsDir(root, boardsDir)) {
|
|
1543
1925
|
for (const b of listBoardFiles(boardsDir).boards) if (b.error) reportBad(`${b.name}.json`, b.content, b.error);
|
|
1544
1926
|
}
|
|
1927
|
+
if (nodeExists(join(boardsDir, `all-scenes.json`))) console.log(`[${NAME}] design/boards/${ALL_SCENES}.json is left over from the All Scenes board, gone since 0.25 - nothing reads it any more; delete it when you like (its threads stay in design/comments/)`);
|
|
1545
1928
|
let listTimer;
|
|
1546
1929
|
const watcher = watch(boardsDir, (_event, file) => {
|
|
1547
|
-
if (!file || !file.endsWith(".json") || file === "_sizes.json") return;
|
|
1930
|
+
if (!file || !file.endsWith(".json") || file === "_sizes.json" || file === `all-scenes.json`) return;
|
|
1548
1931
|
clearTimeout(listTimer);
|
|
1549
1932
|
listTimer = setTimeout(() => {
|
|
1550
1933
|
server.ws.send("sh:boards", {});
|
|
@@ -1655,7 +2038,7 @@ function marverPlugin(ctx) {
|
|
|
1655
2038
|
});
|
|
1656
2039
|
return;
|
|
1657
2040
|
}
|
|
1658
|
-
const { shootFrame, shootBatch, resolveFrames } = await import("./shot-
|
|
2041
|
+
const { shootFrame, shootBatch, resolveFrames } = await import("./shot-CckrGW-J.mjs");
|
|
1659
2042
|
if (ways[0] === "frame") {
|
|
1660
2043
|
if (typeof spec.frame !== "string") {
|
|
1661
2044
|
write({
|
|
@@ -1723,7 +2106,11 @@ function marverPlugin(ctx) {
|
|
|
1723
2106
|
});
|
|
1724
2107
|
} catch {}
|
|
1725
2108
|
}
|
|
1726
|
-
};
|
|
2109
|
+
}, updatesPlugin(root, () => manifest, () => devServer && hooks, landed)];
|
|
2110
|
+
}
|
|
2111
|
+
/** The marks look at the frames on disk; true when they recorded something. */
|
|
2112
|
+
function observed(r) {
|
|
2113
|
+
return r.doc.length + r.note.length > 0;
|
|
1727
2114
|
}
|
|
1728
2115
|
function debounce(fn, ms) {
|
|
1729
2116
|
let t;
|