@marver-design/marver 0.24.0 → 0.25.1
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 +56 -0
- package/README.md +1 -1
- package/dist/anchor-DVV732zR.mjs +33 -0
- package/dist/anchor-check-DGZnYviN.mjs +135 -0
- package/dist/{bake-ZhXq-X9f.mjs → bake-BpxMZfij.mjs} +45 -6
- 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-ckcinlWH.mjs → build-DKaGhoVN.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-Dx1hCVOT.mjs → comments-pTLlhjh4.mjs} +150 -20
- package/dist/{config-BUKprFAp.mjs → config-cKgZBRj0.mjs} +1 -1
- package/dist/{context-BncTXjLB.mjs → context-D2ugHqwO.mjs} +17 -123
- package/dist/{daemon-CQv73-jM.mjs → daemon-Cl8KXGW4.mjs} +146 -64
- package/dist/{dev-gv4NS6Fk.mjs → dev-Diqx1Rt8.mjs} +23 -11
- package/dist/{events-B3LBn74P.mjs → events-DnK_AnrW.mjs} +13 -15
- package/dist/imports-WBSnnHLb.mjs +143 -0
- package/dist/{init--3Moc4J7.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-Sa08E7wO.mjs → plugin-dTF5reck.mjs} +425 -207
- package/dist/{poster-B2QPvKOq.mjs → poster-D-zjYpgk.mjs} +1 -1
- package/dist/{profile-CrZohD6g.mjs → profile-Do0nGkXO.mjs} +1 -1
- package/dist/{publish-bakes-BJR3huhu.mjs → publish-bakes-C_9VZ-Mq.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-Cw96h5Kk.mjs → shot-CUlmkqFX.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-CBUfsOOT.mjs → work-CpJn1gwY.mjs} +8 -4
- package/dist/{work-ayuL_9Kk.mjs → work-GE88wb_3.mjs} +4 -4
- package/docs/boards-and-folders.md +62 -21
- package/docs/live-jam.md +10 -5
- 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 +66 -22
- package/src/client/shell/BoardList.tsx +54 -11
- 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 -34
- package/src/client/shell/Toolbar.tsx +3 -1
- package/src/client/shell/canvas/Canvas.tsx +1 -1
- package/src/client/shell/canvas/FrameNode.tsx +10 -5
- package/src/client/shell/canvas/sleep.ts +23 -4
- package/src/client/shell/canvas/updates.ts +55 -0
- package/src/client/shell/comments-store.ts +48 -19
- 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 +17 -19
- package/src/client/shell/pin-layout.ts +37 -0
- package/src/client/shell/store.ts +312 -92
- package/src/client/shell/styles.css +10 -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 +17 -12
- 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-vXjxMHTG.mjs +0 -132
- package/dist/manifest-cyG3kbhk.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 {
|
|
9
|
-
import {
|
|
10
|
-
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";
|
|
11
|
+
import { closeSync, copyFileSync, existsSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, watch, writeFileSync } from "node:fs";
|
|
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,126 +17,129 @@ 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
|
|
18
|
-
//#region src/server/
|
|
20
|
+
//#region src/server/updates.ts
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
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.
|
|
22
26
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
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.
|
|
29
39
|
*/
|
|
30
|
-
|
|
31
|
-
markSeen: () => markSeen,
|
|
32
|
-
readMarks: () => readMarks,
|
|
33
|
-
readSeen: () => readSeen,
|
|
34
|
-
recordChanged: () => recordChanged
|
|
35
|
-
});
|
|
36
|
-
const dir = (root) => join(root, "design", ".local");
|
|
37
|
-
const read = (file) => {
|
|
40
|
+
const safeReal = (p) => {
|
|
38
41
|
try {
|
|
39
|
-
return
|
|
42
|
+
return realpathSync(p);
|
|
40
43
|
} catch {
|
|
41
|
-
return
|
|
44
|
+
return p;
|
|
42
45
|
}
|
|
43
46
|
};
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const stamps = (o) => o && typeof o === "object" ? Object.fromEntries(Object.entries(o).filter(([, v]) => typeof v === "number" && Number.isFinite(v))) : {};
|
|
53
|
-
function readSeen(root) {
|
|
54
|
-
const f = read(join(dir(root), "seen.json"));
|
|
55
|
-
const strs = (v) => Array.isArray(v) ? v.filter((i) => typeof i === "string") : null;
|
|
56
|
-
if (f && typeof f.baseline === "number") return {
|
|
57
|
-
version: 1,
|
|
58
|
-
baseline: f.baseline,
|
|
59
|
-
ids: strs(f.ids),
|
|
60
|
-
notes: strs(f.notes) ?? [],
|
|
61
|
-
frames: stamps(f.frames)
|
|
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);
|
|
62
55
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/** You saw these frames at these change stamps. Never lowers a stamp; drops ids the canvas no longer has. */
|
|
73
|
-
function markSeen(root, seen, known) {
|
|
74
|
-
const s = readSeen(root);
|
|
75
|
-
for (const [id, at] of Object.entries(stamps(seen))) if (known.has(id)) s.frames[id] = Math.max(s.frames[id] ?? 0, at);
|
|
76
|
-
for (const id of Object.keys(s.frames)) if (!known.has(id)) delete s.frames[id];
|
|
77
|
-
write(root, "seen.json", s);
|
|
78
|
-
}
|
|
79
|
-
const readChanges = (root) => stamps(read(join(dir(root), "changes.json"))?.frames);
|
|
80
|
-
/** These frames changed now, whatever their files say (`work done`, or a frame new under its id). */
|
|
81
|
-
function recordChanged(root, ids, known) {
|
|
82
|
-
const c = readChanges(root), now = Date.now();
|
|
83
|
-
for (const id of ids) c[id] = now;
|
|
84
|
-
if (known) {
|
|
85
|
-
for (const id of Object.keys(c)) if (!known.has(id)) delete c[id];
|
|
86
|
-
}
|
|
87
|
-
write(root, "changes.json", {
|
|
88
|
-
version: 1,
|
|
89
|
-
frames: c
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
const mtime = (abs) => {
|
|
93
|
-
try {
|
|
94
|
-
return statSync(abs).mtimeMs;
|
|
95
|
-
} catch {
|
|
96
|
-
return 0;
|
|
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]);
|
|
97
65
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const noteGone = had ? (seen.notes ?? []).filter((id) => known.has(id) && !noteAt[id]) : [];
|
|
109
|
-
const removed = had ? [...had].some((id) => !known.has(id)) : false;
|
|
110
|
-
if (added.length || noteGone.length || removed) recordChanged(root, [...added, ...noteGone], known);
|
|
111
|
-
if (!had || had.size !== all.length || added.length || noteGone.length || notes.length !== (seen.notes ?? []).length) {
|
|
112
|
-
const frames = Object.fromEntries(Object.entries(seen.frames).filter(([id]) => known.has(id)));
|
|
113
|
-
write(root, "seen.json", {
|
|
114
|
-
...seen,
|
|
115
|
-
ids: all,
|
|
116
|
-
notes,
|
|
117
|
-
frames
|
|
118
|
-
});
|
|
119
|
-
seen.frames = frames;
|
|
120
|
-
}
|
|
121
|
-
const done = readChanges(root);
|
|
122
|
-
const changed = {};
|
|
123
|
-
for (const f of manifest.frames) changed[f.id] = Math.max(mtime(join(root, f.file)), noteAt[f.id], done[f.id] ?? 0);
|
|
124
|
-
const boards = { "all-scenes": all };
|
|
125
|
-
const boardsDir = join(root, "design", "boards");
|
|
126
|
-
if (existsSync(boardsDir) && !checkBoardsDir(root, boardsDir)) for (const b of listBoardFiles(boardsDir).boards) {
|
|
127
|
-
const j = b.json;
|
|
128
|
-
if (!j || b.name === "all-scenes") continue;
|
|
129
|
-
boards[b.name] = j.auto === true ? all : Array.isArray(j.nodes) ? j.nodes.map((n) => n?.frame).filter((f) => typeof f === "string" && known.has(f)) : [];
|
|
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]);
|
|
130
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) {
|
|
131
86
|
return {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
+
}
|
|
136
99
|
};
|
|
137
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
|
+
}
|
|
138
143
|
//#endregion
|
|
139
144
|
//#region src/server/sizes.ts
|
|
140
145
|
/**
|
|
@@ -358,6 +363,15 @@ function contained(target, base) {
|
|
|
358
363
|
}
|
|
359
364
|
}
|
|
360
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;
|
|
361
375
|
const boardsDir = join(root, "design", "boards");
|
|
362
376
|
const foldersPath = join(boardsDir, FOLDERS_FILE);
|
|
363
377
|
const boardPath = (name) => {
|
|
@@ -580,6 +594,30 @@ function apiMiddleware(root, opts = {}) {
|
|
|
580
594
|
return null;
|
|
581
595
|
}
|
|
582
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
|
+
}
|
|
583
621
|
if (path === "sizes" && req.method === "GET") {
|
|
584
622
|
const frames = readManifestFrames();
|
|
585
623
|
if (!frames) return json(res, 200, {
|
|
@@ -640,6 +678,30 @@ function apiMiddleware(root, opts = {}) {
|
|
|
640
678
|
sha256: reg.sha256
|
|
641
679
|
});
|
|
642
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
|
+
}
|
|
643
705
|
if (path === "boards/rename" && req.method === "POST") {
|
|
644
706
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
645
707
|
const raw = await readBody(req);
|
|
@@ -909,6 +971,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
909
971
|
});
|
|
910
972
|
}
|
|
911
973
|
if (req.method === "PUT") {
|
|
974
|
+
if (boardMatch[1] === "all-scenes") return json(res, 400, { error: `"${ALL_SCENES}" is a reserved name` });
|
|
912
975
|
const raw = await readBody(req);
|
|
913
976
|
if (raw == null) return json(res, 400, { error: "body too large or unreadable" });
|
|
914
977
|
let body;
|
|
@@ -946,7 +1009,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
946
1009
|
}
|
|
947
1010
|
}
|
|
948
1011
|
if (path === "shot" && req.method === "GET") {
|
|
949
|
-
const { readDevInfo } = await import("./work-
|
|
1012
|
+
const { readDevInfo } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
|
|
950
1013
|
const token = readDevInfo(root)?.token;
|
|
951
1014
|
if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
|
|
952
1015
|
const frameId = url.searchParams.get("frame") ?? "";
|
|
@@ -962,7 +1025,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
962
1025
|
};
|
|
963
1026
|
const asPng = url.searchParams.get("format") === "png";
|
|
964
1027
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
965
|
-
const { shootFrame } = await import("./shot-
|
|
1028
|
+
const { shootFrame } = await import("./shot-CUlmkqFX.mjs");
|
|
966
1029
|
const r = await shootFrame({
|
|
967
1030
|
root,
|
|
968
1031
|
viewports: opts.viewports ?? {},
|
|
@@ -995,7 +1058,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
995
1058
|
return res.end(png);
|
|
996
1059
|
}
|
|
997
1060
|
if (path === "shots" && req.method === "POST") {
|
|
998
|
-
const { readDevInfo } = await import("./work-
|
|
1061
|
+
const { readDevInfo } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
|
|
999
1062
|
const token = readDevInfo(root)?.token;
|
|
1000
1063
|
if (!ownerGated(req) && !(token && req.headers["x-mv-work"] === token)) return json(res, 403, { error: "forbidden" });
|
|
1001
1064
|
const raw = await readBody(req);
|
|
@@ -1012,7 +1075,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1012
1075
|
if (typeof theme !== "string" || !/^[a-z0-9-]+$/i.test(theme)) return json(res, 400, { error: "invalid theme" });
|
|
1013
1076
|
const scale = body.scale === void 0 ? void 0 : body.scale;
|
|
1014
1077
|
if (scale !== void 0 && !(Number.isInteger(scale) && scale >= 1 && scale <= 4)) return json(res, 400, { error: "invalid scale" });
|
|
1015
|
-
const { resolveFrames, shootBatch } = await import("./shot-
|
|
1078
|
+
const { resolveFrames, shootBatch } = await import("./shot-CUlmkqFX.mjs");
|
|
1016
1079
|
const sel = resolveFrames(root, body);
|
|
1017
1080
|
if (!sel.ok) return json(res, sel.status, { error: sel.error });
|
|
1018
1081
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
@@ -1029,6 +1092,40 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1029
1092
|
return json(res, 503, { error: err.message });
|
|
1030
1093
|
}
|
|
1031
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-DGZnYviN.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
|
+
}
|
|
1032
1129
|
if (path === "bakes" && req.method === "POST") {
|
|
1033
1130
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
1034
1131
|
const raw = await readBody(req);
|
|
@@ -1040,13 +1137,14 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1040
1137
|
return json(res, 400, { error: "malformed JSON" });
|
|
1041
1138
|
}
|
|
1042
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" });
|
|
1043
|
-
const { bakeBatch, ASK_MAX } = await import("./bake-
|
|
1140
|
+
const { bakeBatch, ASK_MAX } = await import("./bake-BpxMZfij.mjs");
|
|
1044
1141
|
let manifest = {};
|
|
1045
1142
|
try {
|
|
1046
1143
|
manifest = JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
|
|
1047
1144
|
} catch {}
|
|
1048
1145
|
const frames = new Map((manifest.frames ?? []).map((f) => [f.id, f]));
|
|
1049
1146
|
const asks = [];
|
|
1147
|
+
const docs = [];
|
|
1050
1148
|
for (const a of body.asks) {
|
|
1051
1149
|
const frame = typeof a?.frame === "string" ? a.frame : "";
|
|
1052
1150
|
const theme = typeof a?.theme === "string" && /^[a-z0-9-]{1,32}$/i.test(a.theme) ? a.theme : "";
|
|
@@ -1058,34 +1156,53 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1058
1156
|
w,
|
|
1059
1157
|
h
|
|
1060
1158
|
});
|
|
1159
|
+
docs.push(typeof a?.doc === "string" ? a.doc : void 0);
|
|
1061
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)));
|
|
1062
1165
|
const origin = opts.origin?.() ?? `http://${req.headers.host ?? "localhost"}`;
|
|
1063
1166
|
const { ROUTE } = await import("./cli.mjs").then((n) => n.t);
|
|
1064
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
|
+
waitMs: 2500
|
|
1183
|
+
});
|
|
1184
|
+
const after = docs.map((d, i) => d !== void 0 && (!!opts.settled && !opts.settled() || d !== docRev(root, devManifest().frames, asks[i].frame)));
|
|
1185
|
+
let k = 0;
|
|
1065
1186
|
return json(res, 200, {
|
|
1066
1187
|
gen,
|
|
1067
|
-
answers:
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
const f = frames.get(ask.frame);
|
|
1078
|
-
return f.kind === "html" ? `${origin}/${f.file}?theme=${encodeURIComponent(ask.theme)}` : `${origin}${ROUTE}/frame/?id=${encodeURIComponent(ask.frame)}&theme=${encodeURIComponent(ask.theme)}`;
|
|
1079
|
-
},
|
|
1080
|
-
urlBase: `${ROUTE}/bakes`
|
|
1188
|
+
answers: asks.map((a, i) => {
|
|
1189
|
+
const r = behind[i] ? null : baked[k++];
|
|
1190
|
+
return {
|
|
1191
|
+
...r && !after[i] ? r : {
|
|
1192
|
+
...a,
|
|
1193
|
+
ok: false,
|
|
1194
|
+
error: "the document is behind its frame"
|
|
1195
|
+
},
|
|
1196
|
+
...docs[i] ? { doc: docs[i] } : {}
|
|
1197
|
+
};
|
|
1081
1198
|
})
|
|
1082
1199
|
});
|
|
1083
1200
|
}
|
|
1084
1201
|
if (path === "poster" && req.method === "GET") {
|
|
1085
1202
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
1086
1203
|
const src = url.searchParams.get("src") ?? "";
|
|
1087
|
-
const { ensurePoster, isLocalClip } = await import("./poster-
|
|
1088
|
-
const { isLocalAssetRef } = await import("./build-
|
|
1204
|
+
const { ensurePoster, isLocalClip } = await import("./poster-D-zjYpgk.mjs");
|
|
1205
|
+
const { isLocalAssetRef } = await import("./build-DKaGhoVN.mjs");
|
|
1089
1206
|
if (!isLocalAssetRef(src) || !isLocalClip(src)) return json(res, 400, { error: "src must be a clip under design/assets/" });
|
|
1090
1207
|
const r = await ensurePoster(join(root, "design", "assets"), src);
|
|
1091
1208
|
if (!r.ok) return json(res, r.error.includes("does not exist") ? 404 : 503, { error: r.error });
|
|
@@ -1112,7 +1229,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1112
1229
|
}
|
|
1113
1230
|
const dir = join(root, "design", ".local");
|
|
1114
1231
|
mkdirSync(dir, { recursive: true });
|
|
1115
|
-
const { validAvatar } = await import("./collab-
|
|
1232
|
+
const { validAvatar } = await import("./collab-gqNdScUE.mjs");
|
|
1116
1233
|
let cur = {};
|
|
1117
1234
|
try {
|
|
1118
1235
|
cur = JSON.parse(readFileSync(join(dir, "profile.json"), "utf8"));
|
|
@@ -1128,13 +1245,8 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1128
1245
|
}
|
|
1129
1246
|
if (path === "marks" || path === "marks/seen") {
|
|
1130
1247
|
if (!ownerGated(req)) return json(res, 403, { error: "forbidden" });
|
|
1131
|
-
const { readMarks, markSeen } = await
|
|
1132
|
-
|
|
1133
|
-
try {
|
|
1134
|
-
manifest = JSON.parse(readFileSync(join(root, "design", "manifest.json"), "utf8"));
|
|
1135
|
-
} catch {
|
|
1136
|
-
manifest = scanFrames(root);
|
|
1137
|
-
}
|
|
1248
|
+
const { readMarks, markSeen } = await import("./marks-koRsbHfe.mjs").then((n) => n.i);
|
|
1249
|
+
const manifest = devManifest();
|
|
1138
1250
|
if (path === "marks" && req.method === "GET") return json(res, 200, readMarks(root, manifest));
|
|
1139
1251
|
if (path === "marks/seen" && req.method === "POST") {
|
|
1140
1252
|
const raw = await readBody(req);
|
|
@@ -1145,22 +1257,22 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1145
1257
|
} catch {
|
|
1146
1258
|
return json(res, 400, { error: "malformed JSON" });
|
|
1147
1259
|
}
|
|
1148
|
-
if (!b?.frames || typeof b.frames !== "object" || Array.isArray(b.frames)) return json(res, 400, { error: "frames: { id:
|
|
1149
|
-
markSeen(root,
|
|
1260
|
+
if (!b?.frames || typeof b.frames !== "object" || Array.isArray(b.frames)) return json(res, 400, { error: "frames: { id: revision } required" });
|
|
1261
|
+
if (!markSeen(root, manifest.frames, b.epoch, b.frames)) return json(res, 409, { error: "the marks started over - read them again" });
|
|
1150
1262
|
opts.notify?.("sh:marks");
|
|
1151
1263
|
return json(res, 200, { ok: true });
|
|
1152
1264
|
}
|
|
1153
1265
|
return json(res, 405, { error: "method not allowed" });
|
|
1154
1266
|
}
|
|
1155
1267
|
if (path === "work") {
|
|
1156
|
-
const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-
|
|
1268
|
+
const { workActivity, readDevInfo, WORK_TTL_DEFAULT, WORK_TTL_MAX } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
|
|
1157
1269
|
const tokenOk = () => {
|
|
1158
1270
|
const t = readDevInfo(root)?.token;
|
|
1159
1271
|
return !!t && req.headers["x-mv-work"] === t;
|
|
1160
1272
|
};
|
|
1161
1273
|
if (req.method === "GET") {
|
|
1162
1274
|
if (!ownerGated(req) && !tokenOk()) return json(res, 403, { error: "forbidden" });
|
|
1163
|
-
const { boardsShowing, activityClock } = await import("./work-
|
|
1275
|
+
const { boardsShowing, activityClock } = await import("./work-GE88wb_3.mjs").then((n) => n.o);
|
|
1164
1276
|
const frames = workActivity.active();
|
|
1165
1277
|
return json(res, 200, {
|
|
1166
1278
|
frames,
|
|
@@ -1183,7 +1295,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1183
1295
|
if (!on && b.all === true) {
|
|
1184
1296
|
const done = workActivity.active().filter((f) => workActivity.has(f, "cli"));
|
|
1185
1297
|
if (done.length) {
|
|
1186
|
-
(await
|
|
1298
|
+
(await import("./marks-koRsbHfe.mjs").then((n) => n.i)).recordChanged(root, devFrames(), done, { doc: false });
|
|
1187
1299
|
opts.notify?.("sh:marks");
|
|
1188
1300
|
}
|
|
1189
1301
|
workActivity.clearAll("cli");
|
|
@@ -1193,7 +1305,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1193
1305
|
const ttl = Math.min(Math.max(Number(b.ttlMs) || WORK_TTL_DEFAULT, 1e4), WORK_TTL_MAX);
|
|
1194
1306
|
for (const f of frames) on ? workActivity.mark(f, ttl, "cli") : workActivity.clear(f, "cli");
|
|
1195
1307
|
if (!on) {
|
|
1196
|
-
(await
|
|
1308
|
+
(await import("./marks-koRsbHfe.mjs").then((n) => n.i)).recordChanged(root, devFrames(), frames, { doc: false });
|
|
1197
1309
|
opts.notify?.("sh:marks");
|
|
1198
1310
|
return json(res, 200, { frames: workActivity.active() });
|
|
1199
1311
|
}
|
|
@@ -1228,7 +1340,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1228
1340
|
}
|
|
1229
1341
|
}
|
|
1230
1342
|
if (path === "boards.rights" && req.method === "GET") {
|
|
1231
|
-
const { listBoards } = await import("./comments-
|
|
1343
|
+
const { listBoards } = await import("./comments-Zoch254k.mjs").then((n) => n.n);
|
|
1232
1344
|
return json(res, 200, {
|
|
1233
1345
|
local: true,
|
|
1234
1346
|
stored: listBoards(join(root, "design", "comments"))
|
|
@@ -1236,7 +1348,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1236
1348
|
}
|
|
1237
1349
|
const cm = /^comments\/([a-z0-9][a-z0-9-]*)$/.exec(path);
|
|
1238
1350
|
if (cm) {
|
|
1239
|
-
const { appendEvents, readLog } = await import("./comments-
|
|
1351
|
+
const { appendEvents, readLog } = await import("./comments-Zoch254k.mjs").then((n) => n.n);
|
|
1240
1352
|
const dir = join(root, "design", "comments");
|
|
1241
1353
|
if (req.method === "GET") return json(res, 200, { events: readLog(dir, cm[1]) });
|
|
1242
1354
|
if (req.method === "POST") {
|
|
@@ -1272,7 +1384,7 @@ function apiMiddleware(root, opts = {}) {
|
|
|
1272
1384
|
}
|
|
1273
1385
|
}
|
|
1274
1386
|
if (path === "sync" && req.method === "POST") {
|
|
1275
|
-
const { loadCollab, syncOnce } = await import("./sync-
|
|
1387
|
+
const { loadCollab, syncOnce } = await import("./sync-C3035OnJ.mjs").then((n) => n.o);
|
|
1276
1388
|
const collab = loadCollab(root);
|
|
1277
1389
|
if (!collab) return json(res, 200, { connected: false });
|
|
1278
1390
|
try {
|
|
@@ -1301,7 +1413,7 @@ function backgroundPush(root) {
|
|
|
1301
1413
|
pushTimer = setTimeout(async () => {
|
|
1302
1414
|
pushTimer = null;
|
|
1303
1415
|
try {
|
|
1304
|
-
const { loadCollab, syncOnce } = await import("./sync-
|
|
1416
|
+
const { loadCollab, syncOnce } = await import("./sync-C3035OnJ.mjs").then((n) => n.o);
|
|
1305
1417
|
const collab = loadCollab(root);
|
|
1306
1418
|
if (collab) await syncOnce(root, collab);
|
|
1307
1419
|
} catch {}
|
|
@@ -1309,12 +1421,7 @@ function backgroundPush(root) {
|
|
|
1309
1421
|
}
|
|
1310
1422
|
//#endregion
|
|
1311
1423
|
//#region src/server/routes.ts
|
|
1312
|
-
|
|
1313
|
-
* Serves the package's own pages. transformIndexHtml does not map URLs - we do (spec §3).
|
|
1314
|
-
* Entry html files carry an {{ENTRY}} placeholder replaced with an /@fs/ absolute path,
|
|
1315
|
-
* because a relative ./main.tsx would resolve against the URL, not the package dir.
|
|
1316
|
-
*/
|
|
1317
|
-
function routesMiddleware(server, clientDir) {
|
|
1424
|
+
function routesMiddleware(server, clientDir, stamps) {
|
|
1318
1425
|
const page = (dir) => {
|
|
1319
1426
|
const html = readFileSync(join(clientDir, dir, "index.html"), "utf8");
|
|
1320
1427
|
const entry = "/@fs/" + join(clientDir, dir, "main.tsx").split("\\").join("/");
|
|
@@ -1326,7 +1433,8 @@ function routesMiddleware(server, clientDir) {
|
|
|
1326
1433
|
webmanifest: "application/manifest+json"
|
|
1327
1434
|
};
|
|
1328
1435
|
return async (req, res, next) => {
|
|
1329
|
-
const
|
|
1436
|
+
const url = new URL(req.url ?? "/", "http://x");
|
|
1437
|
+
const path = url.pathname;
|
|
1330
1438
|
let dir = null;
|
|
1331
1439
|
if (path === "/" || path === "/index.html") dir = "shell";
|
|
1332
1440
|
else if (path === `/__mv/frame/` || path === `/__mv/frame/index.html`) dir = "frame-host";
|
|
@@ -1366,7 +1474,9 @@ function routesMiddleware(server, clientDir) {
|
|
|
1366
1474
|
}
|
|
1367
1475
|
if (!dir) return next();
|
|
1368
1476
|
try {
|
|
1369
|
-
const
|
|
1477
|
+
const stamp = dir === "frame-host" ? stamps?.doc(url.searchParams.get("id") ?? "") : dir === "stage" ? JSON.stringify(stamps?.docs() ?? null) : void 0;
|
|
1478
|
+
let html = await server.transformIndexHtml(req.url ?? "/", page(dir));
|
|
1479
|
+
if (stamp) html = html.replace("<head>", `<head><meta name="mv-doc" content="${stamp.replace(/[&"<>]/g, (c) => `&#${c.charCodeAt(0)};`)}">`);
|
|
1370
1480
|
res.setHeader("content-type", "text/html");
|
|
1371
1481
|
res.setHeader("cache-control", "no-store");
|
|
1372
1482
|
res.end(html);
|
|
@@ -1468,11 +1578,102 @@ function marverPlugin(ctx) {
|
|
|
1468
1578
|
if (!devServer || !pendingInv.size) return;
|
|
1469
1579
|
const frameIds = [...pendingInv];
|
|
1470
1580
|
pendingInv.clear();
|
|
1581
|
+
const docs = docRevs(root, manifest.frames);
|
|
1471
1582
|
devServer.ws.send("sh:frame-invalidated", {
|
|
1472
1583
|
frameIds,
|
|
1473
|
-
revision: `${bootId}:${++invRev}
|
|
1584
|
+
revision: `${bootId}:${++invRev}`,
|
|
1585
|
+
epoch: docs?.epoch,
|
|
1586
|
+
docs: docs ? Object.fromEntries(frameIds.map((id) => [id, docs.doc[id] ?? 0])) : void 0
|
|
1474
1587
|
});
|
|
1475
1588
|
}, 120);
|
|
1589
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
1590
|
+
const late = /* @__PURE__ */ new Map();
|
|
1591
|
+
const envs = () => Object.keys(devServer?.environments ?? { client: 1 }).length;
|
|
1592
|
+
const waiting = [];
|
|
1593
|
+
const settled = () => inFlight.size === 0;
|
|
1594
|
+
const whenSettled = (fn) => {
|
|
1595
|
+
if (settled()) fn();
|
|
1596
|
+
else waiting.push(fn);
|
|
1597
|
+
};
|
|
1598
|
+
const drain = () => {
|
|
1599
|
+
if (settled()) for (const fn of waiting.splice(0)) try {
|
|
1600
|
+
fn();
|
|
1601
|
+
} catch (e) {
|
|
1602
|
+
console.warn(`[marver] ${e.message}`);
|
|
1603
|
+
}
|
|
1604
|
+
};
|
|
1605
|
+
const done = (file) => {
|
|
1606
|
+
const f = inFlight.get(file);
|
|
1607
|
+
if (!f) return;
|
|
1608
|
+
if (--f.events > 0) return;
|
|
1609
|
+
clearTimeout(f.timer);
|
|
1610
|
+
inFlight.delete(file);
|
|
1611
|
+
drain();
|
|
1612
|
+
};
|
|
1613
|
+
const flying = (file) => {
|
|
1614
|
+
const f = inFlight.get(file) ?? {
|
|
1615
|
+
events: 0,
|
|
1616
|
+
hits: 0,
|
|
1617
|
+
timer: void 0
|
|
1618
|
+
};
|
|
1619
|
+
f.events++;
|
|
1620
|
+
clearTimeout(f.timer);
|
|
1621
|
+
f.timer = setTimeout(() => {
|
|
1622
|
+
for (const env of Object.values(devServer?.environments ?? {})) env.moduleGraph.invalidateAll();
|
|
1623
|
+
late.set(file, (late.get(file) ?? 0) + f.events * envs() - f.hits);
|
|
1624
|
+
inFlight.delete(file);
|
|
1625
|
+
drain();
|
|
1626
|
+
}, 1e4);
|
|
1627
|
+
inFlight.set(file, f);
|
|
1628
|
+
};
|
|
1629
|
+
const landed = (file) => {
|
|
1630
|
+
const owed = late.get(file);
|
|
1631
|
+
if (owed) {
|
|
1632
|
+
if (owed > 1) late.set(file, owed - 1);
|
|
1633
|
+
else late.delete(file);
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
const f = inFlight.get(file);
|
|
1637
|
+
if (!f) return;
|
|
1638
|
+
if (++f.hits < envs()) return;
|
|
1639
|
+
f.hits = 0;
|
|
1640
|
+
setTimeout(() => done(file), 0);
|
|
1641
|
+
};
|
|
1642
|
+
const observeMarks = () => observed(observe(root, manifest.frames));
|
|
1643
|
+
const observeLater = () => whenSettled(() => {
|
|
1644
|
+
if (observeMarks()) devServer?.ws.send("sh:marks", {});
|
|
1645
|
+
});
|
|
1646
|
+
const hooks = {
|
|
1647
|
+
onFrames: (t, cause) => {
|
|
1648
|
+
setTimeout(() => whenSettled(() => record(t, cause)), 0);
|
|
1649
|
+
},
|
|
1650
|
+
onReload(p, passed) {
|
|
1651
|
+
logReload(root, {
|
|
1652
|
+
kind: "full-reload",
|
|
1653
|
+
passed,
|
|
1654
|
+
triggeredBy: p.triggeredBy ?? null,
|
|
1655
|
+
path: p.path ?? null
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
function record(t, cause) {
|
|
1660
|
+
const seen = observe(root, manifest.frames, t.file ? { file: t.file } : {});
|
|
1661
|
+
const doc = t.unattributed ? [] : t.doc.filter((id) => !seen.doc.includes(id));
|
|
1662
|
+
const touched = t.touched.filter((id) => !seen.doc.includes(id) && !seen.note.includes(id) && !doc.includes(id));
|
|
1663
|
+
if (doc.length) recordChanged(root, manifest.frames, doc, { doc: true });
|
|
1664
|
+
if (touched.length) recordChanged(root, manifest.frames, touched, { doc: false });
|
|
1665
|
+
const reload = [.../* @__PURE__ */ new Set([...seen.doc, ...t.doc])];
|
|
1666
|
+
for (const id of reload) pendingInv.add(id);
|
|
1667
|
+
flushInv();
|
|
1668
|
+
if (reload.length || touched.length || seen.note.length) devServer?.ws.send("sh:marks", {});
|
|
1669
|
+
logReload(root, {
|
|
1670
|
+
kind: "update",
|
|
1671
|
+
cause,
|
|
1672
|
+
file: t.file ? relative(root, t.file).split(sep).join("/") : null,
|
|
1673
|
+
reload,
|
|
1674
|
+
inPlace: t.touched
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1476
1677
|
/** No theme is only a problem for app frames: a canvas made of content frames alone (Doc, Md,
|
|
1477
1678
|
* Diagram ship their own styling) needs none (#4). The shell decides its banner from the live
|
|
1478
1679
|
* manifest; the config carries only whether a theme exists. */
|
|
@@ -1485,8 +1686,11 @@ function marverPlugin(ctx) {
|
|
|
1485
1686
|
if (ctx.detectedThemeCss && existsSync(join(root, ctx.detectedThemeCss))) return join(root, ctx.detectedThemeCss);
|
|
1486
1687
|
return null;
|
|
1487
1688
|
};
|
|
1488
|
-
return {
|
|
1689
|
+
return [{
|
|
1489
1690
|
name: "marver",
|
|
1691
|
+
watchChange(id) {
|
|
1692
|
+
if (devServer) flying(id);
|
|
1693
|
+
},
|
|
1490
1694
|
enforce: "pre",
|
|
1491
1695
|
resolveId(id) {
|
|
1492
1696
|
if (id === VIRTUAL_THEME) return themeFile() ?? "\0virtual:sh-theme.css";
|
|
@@ -1525,43 +1729,40 @@ function marverPlugin(ctx) {
|
|
|
1525
1729
|
transformIndexHtml: {
|
|
1526
1730
|
order: "pre",
|
|
1527
1731
|
handler(html, hctx) {
|
|
1528
|
-
|
|
1732
|
+
const path = (hctx.originalUrl ?? hctx.path ?? "").split("?")[0];
|
|
1733
|
+
if (!path.startsWith("/design/")) return;
|
|
1529
1734
|
const bridge = "/@fs/" + join(clientDir, "frame-host", "bridge.js").split("\\").join("/") + "?html=1";
|
|
1735
|
+
const frame = manifest.frames.find((f) => "/" + f.file === path);
|
|
1736
|
+
const stamp = frame ? docRev(root, manifest.frames, frame.id) : "";
|
|
1530
1737
|
return {
|
|
1531
1738
|
html,
|
|
1532
|
-
tags: [
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1739
|
+
tags: [
|
|
1740
|
+
{
|
|
1741
|
+
tag: "script",
|
|
1742
|
+
attrs: { type: "module" },
|
|
1743
|
+
children: `import '${VIRTUAL_THEME}'`,
|
|
1744
|
+
injectTo: "head-prepend"
|
|
1745
|
+
},
|
|
1746
|
+
{
|
|
1747
|
+
tag: "script",
|
|
1748
|
+
attrs: {
|
|
1749
|
+
type: "module",
|
|
1750
|
+
src: bridge
|
|
1751
|
+
},
|
|
1752
|
+
injectTo: "head-prepend"
|
|
1542
1753
|
},
|
|
1543
|
-
|
|
1544
|
-
|
|
1754
|
+
...stamp ? [{
|
|
1755
|
+
tag: "meta",
|
|
1756
|
+
attrs: {
|
|
1757
|
+
name: "mv-doc",
|
|
1758
|
+
content: stamp
|
|
1759
|
+
},
|
|
1760
|
+
injectTo: "head-prepend"
|
|
1761
|
+
}] : []
|
|
1762
|
+
]
|
|
1545
1763
|
};
|
|
1546
1764
|
}
|
|
1547
1765
|
},
|
|
1548
|
-
/**
|
|
1549
|
-
* Frame add/unlink is OUR event (sh:manifest → shell appends/flags nodes); Vite's default for
|
|
1550
|
-
* an out-of-graph file is a full-reload broadcast to every client, shell included. Suppress it.
|
|
1551
|
-
* Edits to loaded frames keep normal HMR (modules present + file exists → pass through).
|
|
1552
|
-
*/
|
|
1553
|
-
handleHotUpdate(hctx) {
|
|
1554
|
-
const affected = affectedFrameIds(hctx.file, root, manifest);
|
|
1555
|
-
if (affected === null) {
|
|
1556
|
-
if ([join(root, "design", "scenes"), join(root, "design", "components")].some((w) => hctx.file.startsWith(w)) && !existsSync(hctx.file)) return [];
|
|
1557
|
-
return;
|
|
1558
|
-
}
|
|
1559
|
-
if (affected.length) {
|
|
1560
|
-
for (const id of affected) pendingInv.add(id);
|
|
1561
|
-
flushInv();
|
|
1562
|
-
}
|
|
1563
|
-
return [];
|
|
1564
|
-
},
|
|
1565
1766
|
configureServer(server) {
|
|
1566
1767
|
let bakeGen = Date.now();
|
|
1567
1768
|
server.middlewares.use((req, res, next) => {
|
|
@@ -1591,19 +1792,36 @@ function marverPlugin(ctx) {
|
|
|
1591
1792
|
if (!a || typeof a === "string") return null;
|
|
1592
1793
|
return `http://${a.family === "IPv6" ? a.address === "::" ? "[::1]" : `[${a.address}]` : a.address === "0.0.0.0" ? "127.0.0.1" : a.address}:${a.port}`;
|
|
1593
1794
|
};
|
|
1795
|
+
initMarks(root, manifest.frames);
|
|
1594
1796
|
server.middlewares.use(apiMiddleware(root, {
|
|
1595
1797
|
viewports: config.viewports,
|
|
1596
1798
|
origin: listeningOrigin,
|
|
1597
1799
|
bakeGen: () => bakeGen,
|
|
1598
|
-
notify: (event) => server.ws.send(event, {})
|
|
1800
|
+
notify: (event) => server.ws.send(event, {}),
|
|
1801
|
+
manifest: () => manifest,
|
|
1802
|
+
settled
|
|
1803
|
+
}));
|
|
1804
|
+
server.middlewares.use(routesMiddleware(server, clientDir, {
|
|
1805
|
+
doc: (id) => docRev(root, manifest.frames, id),
|
|
1806
|
+
docs: () => docRevs(root, manifest.frames)
|
|
1599
1807
|
}));
|
|
1600
|
-
server.middlewares.use(routesMiddleware(server, clientDir));
|
|
1601
1808
|
devServer = server;
|
|
1809
|
+
guardUpdates(server, root, () => manifest, hooks);
|
|
1602
1810
|
let framesKey = JSON.stringify(manifest.frames);
|
|
1603
1811
|
let scenesKey = JSON.stringify(manifest.scenes);
|
|
1812
|
+
let unplacedKey = "";
|
|
1813
|
+
const sayUnplaced = () => {
|
|
1814
|
+
const { unplaced } = readMembership(root, manifest.frames.map((f) => f.id));
|
|
1815
|
+
const key = unplaced.join(",");
|
|
1816
|
+
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 ...>`);
|
|
1817
|
+
unplacedKey = key;
|
|
1818
|
+
};
|
|
1819
|
+
sayUnplaced();
|
|
1604
1820
|
const regen = debounce(() => {
|
|
1605
1821
|
manifest = scanFrames(root, projectInfo());
|
|
1822
|
+
sayUnplaced();
|
|
1606
1823
|
const changed = writeManifest(root, manifest);
|
|
1824
|
+
observeLater();
|
|
1607
1825
|
const key = JSON.stringify(manifest.frames), sKey = JSON.stringify(manifest.scenes);
|
|
1608
1826
|
if (changed && key !== framesKey) server.ws.send("sh:manifest", manifest);
|
|
1609
1827
|
else if (changed && sKey !== scenesKey) server.ws.send("sh:scenes", { scenes: manifest.scenes });
|
|
@@ -1641,7 +1859,7 @@ function marverPlugin(ctx) {
|
|
|
1641
1859
|
};
|
|
1642
1860
|
const prune = () => setTimeout(async () => {
|
|
1643
1861
|
try {
|
|
1644
|
-
(await import("./bake-
|
|
1862
|
+
(await import("./bake-BpxMZfij.mjs")).pruneBakes(root, bakeGen);
|
|
1645
1863
|
} catch {}
|
|
1646
1864
|
}, 500);
|
|
1647
1865
|
prune();
|
|
@@ -1674,18 +1892,13 @@ function marverPlugin(ctx) {
|
|
|
1674
1892
|
server.watcher.on("unlink", restatus);
|
|
1675
1893
|
server.watcher.on("change", restatus);
|
|
1676
1894
|
server.watcher.on("change", (f) => inScope(f) && (/\.(tsx|jsx)$/.test(f) || f.endsWith("_brief.md") || isNoteFile(f)) && regen());
|
|
1677
|
-
const marksChanged = debounce(
|
|
1895
|
+
const marksChanged = debounce(observeLater, 300);
|
|
1678
1896
|
for (const ev of [
|
|
1679
1897
|
"add",
|
|
1680
1898
|
"change",
|
|
1681
1899
|
"unlink"
|
|
1682
1900
|
]) server.watcher.on(ev, (f) => {
|
|
1683
|
-
if (
|
|
1684
|
-
});
|
|
1685
|
-
server.watcher.on("unlink", (f) => {
|
|
1686
|
-
if (!inScope(f) || !isNoteFile(f)) return;
|
|
1687
|
-
const fr = manifest.frames.find((x) => noteFileFor(join(root, x.file)) === f);
|
|
1688
|
-
if (fr) recordChanged(root, [fr.id]);
|
|
1901
|
+
if (!f.startsWith(localDir) && !f.startsWith(boardsDirGen)) marksChanged();
|
|
1689
1902
|
});
|
|
1690
1903
|
const configFile = join(root, "design", "config.ts");
|
|
1691
1904
|
server.watcher.on("change", (f) => {
|
|
@@ -1712,9 +1925,10 @@ function marverPlugin(ctx) {
|
|
|
1712
1925
|
if (!checkBoardsDir(root, boardsDir)) {
|
|
1713
1926
|
for (const b of listBoardFiles(boardsDir).boards) if (b.error) reportBad(`${b.name}.json`, b.content, b.error);
|
|
1714
1927
|
}
|
|
1928
|
+
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/)`);
|
|
1715
1929
|
let listTimer;
|
|
1716
1930
|
const watcher = watch(boardsDir, (_event, file) => {
|
|
1717
|
-
if (!file || !file.endsWith(".json") || file === "_sizes.json") return;
|
|
1931
|
+
if (!file || !file.endsWith(".json") || file === "_sizes.json" || file === `all-scenes.json`) return;
|
|
1718
1932
|
clearTimeout(listTimer);
|
|
1719
1933
|
listTimer = setTimeout(() => {
|
|
1720
1934
|
server.ws.send("sh:boards", {});
|
|
@@ -1825,7 +2039,7 @@ function marverPlugin(ctx) {
|
|
|
1825
2039
|
});
|
|
1826
2040
|
return;
|
|
1827
2041
|
}
|
|
1828
|
-
const { shootFrame, shootBatch, resolveFrames } = await import("./shot-
|
|
2042
|
+
const { shootFrame, shootBatch, resolveFrames } = await import("./shot-CUlmkqFX.mjs");
|
|
1829
2043
|
if (ways[0] === "frame") {
|
|
1830
2044
|
if (typeof spec.frame !== "string") {
|
|
1831
2045
|
write({
|
|
@@ -1893,7 +2107,11 @@ function marverPlugin(ctx) {
|
|
|
1893
2107
|
});
|
|
1894
2108
|
} catch {}
|
|
1895
2109
|
}
|
|
1896
|
-
};
|
|
2110
|
+
}, updatesPlugin(root, () => manifest, () => devServer && hooks, landed)];
|
|
2111
|
+
}
|
|
2112
|
+
/** The marks look at the frames on disk; true when they recorded something. */
|
|
2113
|
+
function observed(r) {
|
|
2114
|
+
return r.doc.length + r.note.length > 0;
|
|
1897
2115
|
}
|
|
1898
2116
|
function debounce(fn, ms) {
|
|
1899
2117
|
let t;
|