@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.
Files changed (80) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +3 -1
  3. package/dist/anchor-DVV732zR.mjs +33 -0
  4. package/dist/anchor-check-BE5VVN6Q.mjs +135 -0
  5. package/dist/{bake-DQtnDB8-.mjs → bake-D8byeRzB.mjs} +1 -1
  6. package/dist/{boards-BRLnoTC3.mjs → board-tree-DRioF94d.mjs} +21 -277
  7. package/dist/boards-CGg6piKF.mjs +342 -0
  8. package/dist/{boards-Dv-Ipd8G.mjs → boards-Csxj2WJn.mjs} +23 -9
  9. package/dist/{build-_ndp_dXn.mjs → build-BHoWLvSj.mjs} +63 -37
  10. package/dist/cli.mjs +31 -17
  11. package/dist/{collab-mAiNZlDj.mjs → collab-gqNdScUE.mjs} +39 -9
  12. package/dist/{comments-DZyobpxG.mjs → comments-Zoch254k.mjs} +19 -1
  13. package/dist/{comments-BlqyZh3D.mjs → comments-pTLlhjh4.mjs} +150 -20
  14. package/dist/{config-BUKprFAp.mjs → config-cKgZBRj0.mjs} +1 -1
  15. package/dist/{context-CdkNiKdJ.mjs → context-D2ugHqwO.mjs} +17 -123
  16. package/dist/{daemon-BvMPdQ3k.mjs → daemon-Cl8KXGW4.mjs} +146 -64
  17. package/dist/{dev-Cf-4eqaC.mjs → dev-DJdgow47.mjs} +23 -11
  18. package/dist/{events-B3LBn74P.mjs → events-DnK_AnrW.mjs} +13 -15
  19. package/dist/imports-WBSnnHLb.mjs +143 -0
  20. package/dist/{init-hfZV7TwY.mjs → init-DO4DhUt_.mjs} +28 -6
  21. package/dist/link-C-qUIuKU.mjs +160 -0
  22. package/dist/{board-status-BZSzc9Hp.mjs → manifest-DnAte_fB.mjs} +537 -13
  23. package/dist/marks-DFuintmJ.mjs +50 -0
  24. package/dist/marks-koRsbHfe.mjs +397 -0
  25. package/dist/{marver-id-gate-B_idGdHm.mjs → marver-id-gate-DGANtVyC.mjs} +2 -2
  26. package/dist/perf-CCisg-ny.mjs +49 -0
  27. package/dist/perf-QJIWtTw1.mjs +68 -0
  28. package/dist/{plugin-DoXql0ZZ.mjs → plugin-CTyhjwoJ.mjs} +469 -82
  29. package/dist/{poster-XBmUvQiL.mjs → poster-D0cbV7hi.mjs} +1 -1
  30. package/dist/{profile-CrZohD6g.mjs → profile-Do0nGkXO.mjs} +1 -1
  31. package/dist/{publish-bakes-KKTHWqq3.mjs → publish-bakes--l8ot2eQ.mjs} +9 -9
  32. package/dist/{serve-z5qtj_wJ.mjs → serve-wv2QWdxB.mjs} +6 -6
  33. package/dist/{share-BD-wcDQq.mjs → share-ScamJcks.mjs} +1 -1
  34. package/dist/{shot-DOD8v6fJ.mjs → shot-CckrGW-J.mjs} +19 -11
  35. package/dist/{shot-Dh6fV1Lm.mjs → shot-jdO_B6Qw.mjs} +1 -1
  36. package/dist/{summary-C7CAypbB.mjs → summary-CrW88e3q.mjs} +1 -1
  37. package/dist/{sync-DoA1vf4u.mjs → sync-C3035OnJ.mjs} +18 -8
  38. package/dist/{work-ClFFq0Qh.mjs → work-CpJn1gwY.mjs} +8 -4
  39. package/dist/{work-ayuL_9Kk.mjs → work-GE88wb_3.mjs} +4 -4
  40. package/docs/boards-and-folders.md +70 -4
  41. package/docs/live-jam.md +12 -4
  42. package/package.json +1 -1
  43. package/src/client/frame-host/bridge.js +2 -1
  44. package/src/client/frame-host/inspect.js +195 -84
  45. package/src/client/frame-host/main.tsx +7 -2
  46. package/src/client/frame-host/registry.ts +5 -5
  47. package/src/client/shell/App.tsx +98 -30
  48. package/src/client/shell/BoardList.tsx +74 -16
  49. package/src/client/shell/Comments.tsx +79 -34
  50. package/src/client/shell/ContextMenu.tsx +5 -2
  51. package/src/client/shell/LockedApp.tsx +45 -12
  52. package/src/client/shell/Play.tsx +35 -32
  53. package/src/client/shell/Toolbar.tsx +3 -1
  54. package/src/client/shell/canvas/Canvas.tsx +2 -0
  55. package/src/client/shell/canvas/FrameNode.tsx +15 -5
  56. package/src/client/shell/canvas/sleep.ts +4 -3
  57. package/src/client/shell/canvas/updates.ts +55 -0
  58. package/src/client/shell/comments-store.ts +48 -17
  59. package/src/client/shell/goto.ts +11 -14
  60. package/src/client/shell/hash.ts +12 -5
  61. package/src/client/shell/icons.tsx +1 -2
  62. package/src/client/shell/legacy-links.ts +67 -0
  63. package/src/client/shell/marks-ui.tsx +117 -0
  64. package/src/client/shell/pin-layout.ts +37 -0
  65. package/src/client/shell/store.ts +377 -67
  66. package/src/client/shell/styles.css +32 -8
  67. package/src/client/stage/main.tsx +19 -2
  68. package/src/shared/anchor.ts +57 -0
  69. package/src/shared/board-tree.ts +27 -10
  70. package/src/shared/events.ts +19 -10
  71. package/src/shared/marks.ts +70 -0
  72. package/templates/AGENTS-embedded.md +34 -15
  73. package/templates/AGENTS-studio.md +34 -15
  74. package/templates/instructions/boards.md +9 -5
  75. package/templates/instructions/iterate.md +20 -10
  76. package/templates/instructions/jam.md +13 -4
  77. package/templates/instructions/publish.md +2 -1
  78. package/templates/instructions/reference/deck-story.md +2 -2
  79. package/dist/link-BodAbIQz.mjs +0 -132
  80. package/dist/manifest-TpfDWldB.mjs +0 -528
@@ -1,528 +0,0 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { i as PKG, n as CONTENT_WIDTH } from "./cli.mjs";
3
- import { L as hash, a as checkRealDirs, b as readDescription, g as folderEntries, h as flatten, i as checkBoardsDir, m as buildTree, r as boardFields, s as listBoardFiles, u as readRegistry, x as readTitle, y as isBoardName } from "./boards-BRLnoTC3.mjs";
4
- import { t as annotateBoards } from "./board-status-BZSzc9Hp.mjs";
5
- import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
6
- import { join, relative, sep } from "node:path";
7
- import { randomBytes } from "node:crypto";
8
- //#region src/server/manifest.ts
9
- var manifest_exports = /* @__PURE__ */ __exportAll({
10
- NOTE_MAX: () => NOTE_MAX,
11
- affectedFrameIds: () => affectedFrameIds,
12
- codeOnly: () => codeOnly,
13
- contentScan: () => contentScan,
14
- contentWidthOf: () => contentWidthOf,
15
- docTags: () => docTags,
16
- extractMeta: () => extractMeta,
17
- frontMatter: () => frontMatter,
18
- isNoteFile: () => isNoteFile,
19
- layoutDocSource: () => layoutDocSource,
20
- noteFileFor: () => noteFileFor,
21
- readNote: () => readNote,
22
- rendersDoc: () => rendersDoc,
23
- scanFrames: () => scanFrames,
24
- sceneBrief: () => sceneBrief,
25
- sceneNote: () => sceneNote,
26
- setSceneTitle: () => setSceneTitle,
27
- statusBoards: () => statusBoards,
28
- tagPattern: () => tagPattern,
29
- toFrameId: () => toFrameId,
30
- writeManifest: () => writeManifest
31
- });
32
- const FRAME_EXT = /\.(tsx|jsx|html)$/;
33
- const RESERVED_SCENES = /* @__PURE__ */ new Set(["components", "screens"]);
34
- /** Sticky notes (spec 18): the longest note the manifest carries - a note is an aside, not a spec. */
35
- const NOTE_MAX = 2e4;
36
- /** The note file beside a frame file: `cart.tsx` -> `cart.note.md`; a scene's is `_note.md`. */
37
- const noteFileFor = (frameFile) => frameFile.replace(FRAME_EXT, ".note.md");
38
- /** Is this path a note file - the dev watcher's "regenerate on change" predicate. */
39
- const isNoteFile = (file) => /(^|[\\/])(_note|[^\\/]+\.note)\.md$/.test(file);
40
- /** A note's text: BOM stripped, trimmed, capped at NOTE_MAX. Undefined when the file is missing,
41
- * empty, or not a regular file (a symlink is never followed - the `_brief.md` rule). */
42
- function readNote(abs) {
43
- try {
44
- if (!lstatSync(abs).isFile()) return void 0;
45
- const text = readFileSync(abs, "utf8").replace(/^/, "").trim();
46
- return text ? text.slice(0, NOTE_MAX) : void 0;
47
- } catch {
48
- return;
49
- }
50
- }
51
- /** Extract `export const meta = {...}` with literal string values only. Anything else is silently omitted. */
52
- function extractMeta(src) {
53
- const m = /export\s+const\s+meta\s*=\s*\{([\s\S]*?)\}/.exec(src);
54
- if (!m) return {};
55
- const body = m[1];
56
- const pick = (key) => {
57
- const r = new RegExp(`(?:^|[{,])\\s*${key}\\s*:\\s*(?:'([^'\\n]*)'|"([^"\\n]*)"|\`([^\`\\n]*)\`)\\s*(?=[,}\\n]|$)`).exec(body);
58
- return r ? r[1] ?? r[2] ?? r[3] : void 0;
59
- };
60
- const pickBool = (key) => {
61
- const r = new RegExp(`(?:^|[{,])\\s*${key}\\s*:\\s*(true|false)\\b`).exec(body);
62
- return r ? r[1] === "true" : void 0;
63
- };
64
- const out = {};
65
- const title = pick("title");
66
- if (title) out.title = title;
67
- const viewport = pick("viewport");
68
- if (viewport) out.viewport = viewport;
69
- const theme = pick("theme");
70
- if (theme) out.theme = theme;
71
- const of = pick("of");
72
- if (of) out.of = of;
73
- const variant = pick("variant");
74
- if (variant) out.variant = variant;
75
- const intent = pick("intent");
76
- if (intent) out.intent = intent;
77
- const slide = pickBool("slide");
78
- if (slide !== void 0) out.slide = slide;
79
- const description = readDescription(pick("description"));
80
- if (description) out.description = description;
81
- return out;
82
- }
83
- /** Content-frame detection: LEXICAL by convention - the frame file itself imports
84
- * PKG/content (an import specifier scan, so "<Diagram" inside a string in a UI frame can
85
- * never misbadge it; barrels/re-exports are not detected - meta.intent is the taught path
86
- * and always works) AND renders a DOCUMENT primitive: Doc, Md, Diagram or Img (reference
87
- * imagery - a moodboard is Rows of Img). The import alone is not enough - Chart, Video, Row,
88
- * Col and Space are shared blocks a UI screen or a slide uses too, and a dashboard with one
89
- * <Chart> is still a screen (device height, no document measuring), never a spec. Returns
90
- * the inferred intent + natural width, or null for UI frames. */
91
- const CONTENT_IMPORT = new RegExp(`from\\s+['"]${PKG}/content['"]`);
92
- /** The JSX names a Doc renders under in this source: `Doc`, an alias (`import { Doc as Page }`),
93
- * a namespace's member (`import * as C` -> `C.Doc`). Read from the code only (codeOnly). */
94
- function docTags(code) {
95
- const tags = ["Doc"];
96
- for (const m of code.matchAll(/\bDoc\s+as\s+([A-Za-z_$][\w$]*)/g)) tags.push(m[1]);
97
- for (const m of code.matchAll(/import\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from/g)) tags.push(`${m[1]}.Doc`);
98
- return tags;
99
- }
100
- const tagPattern = (tag) => tag.replace(/[.$]/g, "\\$&");
101
- /** Does this source render a `<Doc>` - the one primitive that measures (content/index.tsx)? Lexical
102
- * on the code (comments and strings blanked), through an aliased or namespace import too. */
103
- function rendersDoc(src) {
104
- const code = codeOnly(src);
105
- return docTags(code).some((t) => new RegExp(`<${tagPattern(t)}[\\s>/]`).test(code));
106
- }
107
- /** The source of the nearest `_layout.tsx|jsx` around a frame that renders a Doc - the frame host
108
- * wraps a frame in every `_layout` from its directory up to `scenes/` or `components/` - or null.
109
- * `file` is the frame's path from the root; `memo` caches per directory across one scan. */
110
- function layoutDocSource(root, file, memo) {
111
- const parts = file.split("/").slice(0, -1);
112
- if (parts.includes("..")) return null;
113
- for (let i = parts.length; i >= 2; i--) {
114
- const dir = parts.slice(0, i).join("/");
115
- let found = memo.get(dir);
116
- if (found === void 0) {
117
- found = null;
118
- for (const ext of ["tsx", "jsx"]) try {
119
- const src = readFileSync(join(root, dir, `_layout.${ext}`), "utf8");
120
- if (rendersDoc(src)) {
121
- found = src;
122
- break;
123
- }
124
- } catch {}
125
- memo.set(dir, found);
126
- }
127
- if (found !== null) return found;
128
- }
129
- return null;
130
- }
131
- const contentWidthOf = (src) => docTags(codeOnly(src)).some((t) => new RegExp(`<${tagPattern(t)}\\b[^>]*\\blayout\\s*=\\s*["']wide["']`).test(src)) ? CONTENT_WIDTH.wide : CONTENT_WIDTH.document;
132
- /** The source with comments, template literals and CODE-shaped strings blanked (a JSX
133
- * expression string `{'<Diagram>'}`, an attribute value), so a tag name quoted in an example
134
- * or a comment never counts as a rendered element. Prose is left alone: JSX text has
135
- * apostrophes ("it's"), and a blanket quote match would swallow real tags between two of them. */
136
- const codeOnly = (src) => src.replace(/`(?:[^`\\]|\\[\s\S])*`/g, "``").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1").replace(/\{\s*(?:"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')\s*\}/g, "{\"\"}").replace(/([=(,:[{?+|&!]|\breturn)\s*(?:"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')/g, "$1\"\"").replace(/([=(,:[{?+|&!]|\breturn)\s*\/(?:[^/\\\n[]|\\.|\[(?:[^\]\\\n]|\\.)*\])+\/[gimsuy]*/g, "$1/re/");
137
- function contentScan(src) {
138
- if (!CONTENT_IMPORT.test(src)) return null;
139
- const code = codeOnly(src);
140
- const count = (re) => (code.match(re) ?? []).length;
141
- const docs = count(/<Doc[\s>/]/g);
142
- const diagrams = count(/<Diagram[\s>/]/g);
143
- const imgs = count(/<Img[\s>/]/g);
144
- const mds = count(/<Md[\s>/]/g);
145
- if (docs + diagrams + mds + imgs === 0) return null;
146
- return {
147
- intent: diagrams > 0 ? "diagram" : imgs > mds ? "moodboard" : "spec",
148
- width: contentWidthOf(src)
149
- };
150
- }
151
- /** id = path relative to design/, extension dropped, `scenes/` prefix dropped. Always `/`-separated. */
152
- function toFrameId(designRelPath) {
153
- const noExt = designRelPath.split(sep).join("/").replace(FRAME_EXT, "");
154
- return noExt.startsWith("scenes/") ? noExt.slice(7) : noExt;
155
- }
156
- /**
157
- * A7: which frames does a changed `design/**` file affect? Manifest + directory conventions,
158
- * NOT a module-graph walk (deterministic, cheap, may over-reload but never misses a
159
- * conventionally-affected frame). Returns:
160
- * null -> uncontrolled: leave to default Vite HMR (src/** deps, theme.css, config, assets)
161
- * [] -> controlled but affects no current frame (e.g. a layout in an empty dir)
162
- * [ids] -> controlled: the shell drives a rev-stamped reload of these frames
163
- */
164
- function affectedFrameIds(absFile, root, manifest) {
165
- const design = join(root, "design");
166
- if (absFile !== design && !absFile.startsWith(design + sep)) return null;
167
- const rel = relative(design, absFile).split(sep).join("/");
168
- const name = rel.split("/").pop() ?? rel;
169
- const designRel = `design/${rel}`;
170
- const tsxFrames = manifest.frames.filter((f) => f.kind === "tsx");
171
- if (name === "theme.css") return null;
172
- if (rel === "providers.tsx" || rel === "providers.jsx") return tsxFrames.map((f) => f.id);
173
- if (/(^|\/)(_layout\.(tsx|jsx)|_fixtures\.(ts|tsx|js|jsx|json))$/.test(rel)) {
174
- const prefix = `design/${rel.slice(0, rel.length - name.length)}`;
175
- return tsxFrames.filter((f) => f.file.startsWith(prefix)).map((f) => f.id);
176
- }
177
- const direct = manifest.frames.find((f) => f.file === designRel);
178
- if (direct) return [direct.id];
179
- return null;
180
- }
181
- function walk(dir, out = []) {
182
- if (!existsSync(dir)) return out;
183
- for (const e of readdirSync(dir, { withFileTypes: true })) {
184
- if (e.name.startsWith(".")) continue;
185
- const p = join(dir, e.name);
186
- if (e.isDirectory()) walk(p, out);
187
- else out.push(p);
188
- }
189
- return out;
190
- }
191
- /** The YAML front matter at the top of a markdown file, read flat: `key: value` scalars,
192
- * quoted (JSON-style double quotes, or single quotes with '' for one) or bare. `end` is the
193
- * line the body starts at (0 = no block; an unclosed block swallows the file). */
194
- function frontMatter(lines) {
195
- const fields = {};
196
- if (lines[0]?.trim() !== "---") return {
197
- fields,
198
- end: 0
199
- };
200
- let close = lines.findIndex((l, i) => i > 0 && l.trim() === "---");
201
- if (close < 0) close = lines.length;
202
- for (const l of lines.slice(1, close)) {
203
- const m = /^([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(l.trim());
204
- if (!m) continue;
205
- let v = m[2].trim();
206
- if (v.startsWith("\"")) try {
207
- v = String(JSON.parse(v));
208
- } catch {
209
- v = v.replace(/^"|"$/g, "");
210
- }
211
- else if (v.length >= 2 && v.startsWith("'") && v.endsWith("'")) v = v.slice(1, -1).replace(/''/g, "'");
212
- fields[m[1]] = v;
213
- }
214
- return {
215
- fields,
216
- end: Math.min(close + 1, lines.length)
217
- };
218
- }
219
- /** A scene's title is `title` in its `_brief.md` front matter; its description is the first
220
- * non-blank line after the block (a leading `#` stripped) - no new file. */
221
- function sceneBrief(root, scene) {
222
- if (!scene) return {};
223
- const rel = `design/scenes/${scene}/_brief.md`;
224
- const abs = join(root, ...rel.split("/"));
225
- if (!existsSync(abs)) return {};
226
- let title, description;
227
- try {
228
- const lines = readFileSync(abs, "utf8").replace(/^\uFEFF/, "").split(/\r?\n/);
229
- const fm = frontMatter(lines);
230
- title = readTitle(fm.fields.title);
231
- const line = lines.slice(fm.end).map((l) => l.trim()).find((l) => l);
232
- description = readDescription(line?.replace(/^#+\s*/, ""));
233
- } catch {}
234
- return {
235
- brief: rel,
236
- ...title ? { title } : {},
237
- ...description ? { description } : {}
238
- };
239
- }
240
- /** A scene's sticky note: `design/scenes/<scene>/_note.md` (spec 18). */
241
- function sceneNote(root, scene) {
242
- return scene ? readNote(join(root, "design", "scenes", scene, "_note.md")) : void 0;
243
- }
244
- /** Write a scene's title into its brief's front matter - only that line changes; the body,
245
- * every other field and the file's own line endings are kept. No brief yet = a front-matter-only
246
- * brief. An empty title removes the line, and the file when nothing else is in it. The write
247
- * is atomic (temp + rename); a symlinked scene directory or brief, or a front matter block
248
- * that never closes, is refused untouched - the brief is the agent's document, never rewritten
249
- * from a guess. Returns the error, or null. */
250
- function setSceneTitle(root, scene, title) {
251
- const design = join(root, "design"), scenes = join(design, "scenes"), dir = join(scenes, scene);
252
- const de = checkRealDirs(root, [
253
- [design, "design"],
254
- [scenes, "design/scenes"],
255
- [dir, `design/scenes/${scene}`]
256
- ]);
257
- if (de) return de;
258
- try {
259
- if (!lstatSync(dir).isDirectory()) return `"${scene}" is not a scene directory`;
260
- } catch {
261
- return `scene "${scene}" does not exist`;
262
- }
263
- const file = join(dir, "_brief.md");
264
- let had = false;
265
- try {
266
- if (!lstatSync(file).isFile()) return `design/scenes/${scene}/_brief.md is not a regular file - refusing to write it`;
267
- had = true;
268
- } catch {}
269
- const text = had ? readFileSync(file, "utf8") : "";
270
- const bom = text.startsWith("") ? "" : "";
271
- const raw = text.slice(bom.length);
272
- const eol = raw.includes("\r\n") ? "\r\n" : "\n";
273
- const lines = raw.split(/\r?\n/);
274
- const fm = frontMatter(lines);
275
- if (fm.end === lines.length && lines[0]?.trim() === "---" && !lines.slice(1).some((l) => l.trim() === "---")) return `design/scenes/${scene}/_brief.md: the front matter never closes - fix the file`;
276
- const line = title ? [`title: ${JSON.stringify(title)}`] : [];
277
- let out;
278
- if (fm.end === 0) {
279
- if (!title) return null;
280
- out = [
281
- "---",
282
- ...line,
283
- "---",
284
- ...raw.trim() ? ["", ...lines] : [""]
285
- ];
286
- } else {
287
- const close = Math.max(1, fm.end - 1);
288
- const kept = lines.slice(1, close).filter((l) => !/^title\s*:/.test(l.trim()));
289
- const body = lines.slice(fm.end);
290
- out = kept.length || title ? [
291
- "---",
292
- ...line,
293
- ...kept,
294
- "---",
295
- ...body
296
- ] : body;
297
- }
298
- if (!out.join("").trim()) {
299
- if (had) rmSync(file);
300
- return null;
301
- }
302
- const tmp = join(dir, `.brief-${randomBytes(6).toString("hex")}.tmp`);
303
- try {
304
- writeFileSync(tmp, bom + out.join(eol));
305
- renameSync(tmp, file);
306
- } catch (err) {
307
- rmSync(tmp, { force: true });
308
- throw err;
309
- }
310
- return null;
311
- }
312
- /** The sidebar as files say it is, for the manifest: folders in reading order (a sub-folder
313
- * after its parent, with `parent`), boards in reading order with the folder they sit in
314
- * directly and their description. A boards dir we may not read (symlink)
315
- * or a malformed registry yields nothing here - the API and the build say why; the
316
- * orientation file must never fail to write. */
317
- function scanBoards(root) {
318
- const dir = join(root, "design", "boards");
319
- if (checkBoardsDir(root, dir)) return {};
320
- const reg = readRegistry(dir);
321
- if (reg.state === "malformed") return {};
322
- const files = listBoardFiles(dir).boards;
323
- const rows = files.map((b) => ({
324
- name: b.name,
325
- ...boardFields(b.json, isBoardName)
326
- }));
327
- const tree = buildTree(rows, reg.folders);
328
- const entries = folderEntries(tree);
329
- const folderOf = /* @__PURE__ */ new Map();
330
- for (const { folder } of entries) for (const k of folder.items) if (k.kind === "board") folderOf.set(k.name, folder.name);
331
- const folders = entries.map(({ folder: it, parent }) => ({
332
- name: it.name,
333
- ...parent ? { parent } : {},
334
- ...it.title ? { title: it.title } : {},
335
- ...it.description ? { description: it.description } : {},
336
- ...it.type ? { type: it.type } : {}
337
- }));
338
- const notes = annotateBoards(root, files, reg.folders, (n) => folderOf.get(n) ?? null);
339
- const boards = flatten(tree).map((name) => {
340
- const r = rows.find((x) => x.name === name);
341
- const n = notes.get(name);
342
- const st = n?.status;
343
- return {
344
- name,
345
- ...folderOf.has(name) ? { folder: folderOf.get(name) } : {},
346
- ...r?.title ? { title: r.title } : {},
347
- ...r?.description ? { description: r.description } : {},
348
- ...n && n.type !== "plain" ? { type: n.type } : {},
349
- ...st ? { status: {
350
- status: st.status,
351
- ...st.fill ? { fill: st.fill } : {},
352
- ...st.reason ? { reason: st.reason } : {},
353
- audience: st.audience
354
- } } : {}
355
- };
356
- });
357
- return {
358
- ...folders.length ? { folders } : {},
359
- ...boards.length ? { boards } : {}
360
- };
361
- }
362
- /** The boards that wear a status (feature and project, by their resolved type) - for the dev
363
- * server's word at boot when there is no context/ to read it from. */
364
- const statusBoards = (root) => (scanBoards(root).boards ?? []).filter((b) => b.type === "feature" || b.type === "project").map((b) => b.name);
365
- function scanFrames(root, project) {
366
- const design = join(root, "design");
367
- const frames = [];
368
- const layoutDocs = /* @__PURE__ */ new Map();
369
- for (const base of ["scenes", "components"]) for (const abs of walk(join(design, base))) {
370
- const name = abs.split(sep).pop();
371
- const rel = relative(design, abs).split(sep).join("/");
372
- const folders = rel.split("/").slice(base === "scenes" ? 2 : 1, -1);
373
- if (!FRAME_EXT.test(name) || name.startsWith("_") || folders.some((s) => s.startsWith("_"))) continue;
374
- const id = toFrameId(rel);
375
- const scene = id.includes("/") ? id.split("/")[0] : "";
376
- if (base === "scenes" && RESERVED_SCENES.has(scene)) {
377
- console.error(`[marver] scene "${scene}" is a reserved name - "${rel}" skipped. Rename the scene.`);
378
- continue;
379
- }
380
- const kind = name.endsWith(".html") ? "html" : "tsx";
381
- const entry = {
382
- id,
383
- file: `design/${rel}`,
384
- kind,
385
- scene
386
- };
387
- const note = readNote(noteFileFor(abs));
388
- if (note) entry.note = note;
389
- if (kind === "tsx") {
390
- const src = readFileSync(abs, "utf8");
391
- const meta = extractMeta(src);
392
- if (meta.title) entry.title = meta.title;
393
- if (meta.viewport) entry.viewport = meta.viewport;
394
- if (meta.theme) entry.theme = meta.theme;
395
- if (meta.of) entry.variantGroup = meta.of;
396
- if (meta.variant) entry.variant = meta.variant;
397
- if (meta.slide) entry.slide = true;
398
- if (meta.description) entry.description = meta.description;
399
- const content = contentScan(src);
400
- if (content || meta.intent) {
401
- entry.intent = meta.intent ?? content.intent;
402
- const layout = rendersDoc(src) ? null : layoutDocSource(root, entry.file, layoutDocs);
403
- entry.contentWidth = layout !== null ? contentWidthOf(layout) : content?.width ?? contentWidthOf(src);
404
- }
405
- }
406
- frames.push(entry);
407
- }
408
- const extRank = (file) => file.endsWith(".tsx") ? 0 : file.endsWith(".jsx") ? 1 : 2;
409
- frames.sort((a, b) => a.id.localeCompare(b.id) || extRank(a.file) - extRank(b.file) || a.file.localeCompare(b.file));
410
- const seen = /* @__PURE__ */ new Map();
411
- const deduped = frames.filter((f) => {
412
- const prev = seen.get(f.id);
413
- if (prev) {
414
- console.error(`[marver] duplicate frame id "${f.id}" (${prev} vs ${f.file}) - keeping ${prev}.`);
415
- return false;
416
- }
417
- seen.set(f.id, f.file);
418
- return true;
419
- });
420
- frames.length = 0;
421
- frames.push(...deduped);
422
- inferVariantGroups(frames);
423
- const sceneCounts = /* @__PURE__ */ new Map();
424
- for (const f of frames) sceneCounts.set(f.scene, (sceneCounts.get(f.scene) ?? 0) + 1);
425
- const scenesDir = join(design, "scenes");
426
- if (existsSync(scenesDir)) {
427
- for (const e of readdirSync(scenesDir, { withFileTypes: true })) if (e.isDirectory() && !e.name.startsWith(".") && !RESERVED_SCENES.has(e.name) && !sceneCounts.has(e.name) && existsSync(join(scenesDir, e.name, "_brief.md"))) sceneCounts.set(e.name, 0);
428
- }
429
- const scenes = [...sceneCounts.entries()].map(([name, n]) => {
430
- const note = sceneNote(root, name);
431
- return {
432
- name,
433
- frames: n,
434
- ...sceneBrief(root, name),
435
- ...note ? { note } : {}
436
- };
437
- }).sort((a, b) => a.name.localeCompare(b.name));
438
- return {
439
- ...project && (project.name || project.description) ? { project: {
440
- ...project.name ? { name: project.name } : {},
441
- ...project.description ? { description: project.description } : {}
442
- } } : {},
443
- ...scanBoards(root),
444
- scenes,
445
- frames
446
- };
447
- }
448
- /** Variant groups. A group = 2+ frames in one DIRECTORY whose basenames
449
- * are letter-prefixed (`a-terminal`), or frames declaring `meta.of`. Group id = the
450
- * directory's id prefix (or meta.of); variant key = the letter (or meta.variant).
451
- * Nested directories scope alternatives inside a busy scene (checkout/payment/a-card).
452
- * States (empty.tsx, error.tsx) never letter-prefix, so they never misgroup.
453
- * Mutates entries in place: only frames whose group materializes keep the fields. */
454
- function inferVariantGroups(frames) {
455
- const dirOf = (id) => {
456
- const i = id.lastIndexOf("/");
457
- return i >= 0 ? id.slice(0, i) : "";
458
- };
459
- const candidates = /* @__PURE__ */ new Map();
460
- for (const f of frames) {
461
- if (f.kind !== "tsx") {
462
- delete f.variantGroup;
463
- delete f.variant;
464
- continue;
465
- }
466
- let group = f.variantGroup;
467
- let key = f.variant;
468
- if (!group) {
469
- const base = f.id.slice(f.id.lastIndexOf("/") + 1);
470
- const m = /^([a-z])-.+$/.exec(base);
471
- if (!m) continue;
472
- group = dirOf(f.id);
473
- if (!group) continue;
474
- key = key ?? m[1];
475
- } else if (!key) {
476
- const m = /^([a-z])-.+$/.exec(f.id.slice(f.id.lastIndexOf("/") + 1));
477
- if (!m) {
478
- console.warn(`[marver] ${f.file} declares of:"${group}" but no variant key (add meta.variant or a letter prefix) - not grouped.`);
479
- delete f.variantGroup;
480
- delete f.variant;
481
- continue;
482
- }
483
- key = m[1];
484
- }
485
- f.variantGroup = group;
486
- f.variant = key;
487
- candidates.set(group, [...candidates.get(group) ?? [], f]);
488
- }
489
- for (const [group, members] of candidates) {
490
- if (new Set(members.map((m) => dirOf(m.id))).size > 1) {
491
- console.warn(`[marver] group "${group}" spans directories - variants must be siblings; not grouped.`);
492
- for (const m of members) {
493
- delete m.variantGroup;
494
- delete m.variant;
495
- }
496
- continue;
497
- }
498
- const seen = /* @__PURE__ */ new Set();
499
- const kept = [];
500
- for (const m of members.sort((a, b) => (a.variant ?? "").localeCompare(b.variant ?? ""))) {
501
- if (seen.has(m.variant)) {
502
- console.warn(`[marver] duplicate variant "${m.variant}" in group "${group}" (${m.file}) - not grouped.`);
503
- delete m.variantGroup;
504
- delete m.variant;
505
- continue;
506
- }
507
- seen.add(m.variant);
508
- kept.push(m);
509
- }
510
- if (kept.length < 2) for (const m of kept) {
511
- delete m.variantGroup;
512
- delete m.variant;
513
- }
514
- }
515
- for (const f of frames) if (f.variant && !f.variantGroup) delete f.variant;
516
- }
517
- /** Write design/manifest.json only when content changed. Returns the manifest either way. */
518
- function writeManifest(root, manifest) {
519
- const file = join(root, "design", "manifest.json");
520
- const next = JSON.stringify(manifest, null, 2) + "\n";
521
- const prev = existsSync(file) ? readFileSync(file, "utf8") : "";
522
- if (hash(prev) === hash(next)) return false;
523
- mkdirSync(join(root, "design"), { recursive: true });
524
- writeFileSync(file, next);
525
- return true;
526
- }
527
- //#endregion
528
- export { rendersDoc as a, toFrameId as c, manifest_exports as i, writeManifest as l, isNoteFile as n, scanFrames as o, layoutDocSource as r, setSceneTitle as s, affectedFrameIds as t };