@blackbelt-technology/pi-dashboard-deck3d 0.0.0-stage → 0.9.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 (260) hide show
  1. package/.pi/skills/deck3d/SKILL.md +227 -0
  2. package/.pi/skills/deck3d/examples/deck.json +388 -0
  3. package/.pi/skills/deck3d/examples/fixture.md +18 -0
  4. package/.pi/skills/deck3d/examples/snapshot-after.png +0 -0
  5. package/.pi/skills/deck3d/examples/snapshot-before.png +0 -0
  6. package/.pi/skills/deck3d/reference/effects.agent.md +78 -0
  7. package/.pi/skills/deck3d/reference/effects.md +1217 -0
  8. package/.pi/skills/deck3d/reference/ir-fields.agent.md +30 -0
  9. package/.pi/skills/deck3d/reference/ir-fields.md +246 -0
  10. package/README.md +177 -2
  11. package/assets/LICENSE-Poppins.txt +99 -0
  12. package/assets/Poppins-Bold.ttf +0 -0
  13. package/assets/props/LICENSES.txt +4 -0
  14. package/assets/props/brain.glb +0 -0
  15. package/assets/props/cloud.glb +0 -0
  16. package/assets/props/cube.glb +0 -0
  17. package/assets/props/database.glb +0 -0
  18. package/assets/props/laptop.glb +0 -0
  19. package/assets/props/manifest.json +119 -0
  20. package/assets/props/robot.glb +0 -0
  21. package/assets/props/server.glb +0 -0
  22. package/assets/props/shield.glb +0 -0
  23. package/bin/deck3d +49 -0
  24. package/dist/cli.js +10228 -0
  25. package/dist/harvest/harness.js +185718 -0
  26. package/dist/runtime.js +64597 -0
  27. package/fixtures/business-2031/build-deck.mjs +60 -0
  28. package/fixtures/business-2031/build-overrides.mjs +154 -0
  29. package/fixtures/business-2031/deck.json +4220 -0
  30. package/fixtures/business-2031/deck.md +470 -0
  31. package/fixtures/business-2031/fx/closing-mark.js +43 -0
  32. package/fixtures/business-2031/fx/closing-mark.meta.json +26 -0
  33. package/fixtures/business-2031/overrides.json +903 -0
  34. package/fixtures/harvest.md +23 -0
  35. package/fixtures/strategy-lab.json +891 -0
  36. package/fixtures/strategy-lab.md +85 -0
  37. package/package.json +80 -4
  38. package/scripts/build-cli.mjs +29 -0
  39. package/scripts/build-harvest.ts +8 -0
  40. package/scripts/build-runtime.mjs +22 -0
  41. package/scripts/gen-effects.ts +14 -0
  42. package/scripts/gen-ir-fields.ts +34 -0
  43. package/src/check/index.ts +315 -0
  44. package/src/check/rules.ts +393 -0
  45. package/src/cli-io.ts +23 -0
  46. package/src/cli.ts +823 -0
  47. package/src/fx/accent-cycle.meta.json +26 -0
  48. package/src/fx/accent-cycle.ts +8 -0
  49. package/src/fx/agent-depth.meta.json +42 -0
  50. package/src/fx/agent-depth.ts +62 -0
  51. package/src/fx/ascii.meta.json +35 -0
  52. package/src/fx/ascii.ts +4 -0
  53. package/src/fx/aurora.meta.json +26 -0
  54. package/src/fx/aurora.ts +18 -0
  55. package/src/fx/billboards.meta.json +34 -0
  56. package/src/fx/billboards.ts +67 -0
  57. package/src/fx/bloom.meta.json +26 -0
  58. package/src/fx/bloom.ts +4 -0
  59. package/src/fx/camera-drift.meta.json +26 -0
  60. package/src/fx/camera-drift.ts +8 -0
  61. package/src/fx/capital-flows.meta.json +30 -0
  62. package/src/fx/capital-flows.ts +64 -0
  63. package/src/fx/catalogue.ts +89 -0
  64. package/src/fx/chromatic-aberration.meta.json +32 -0
  65. package/src/fx/chromatic-aberration.ts +4 -0
  66. package/src/fx/city-grid.meta.json +37 -0
  67. package/src/fx/city-grid.ts +51 -0
  68. package/src/fx/clipped-solids.meta.json +49 -0
  69. package/src/fx/clipped-solids.ts +171 -0
  70. package/src/fx/cohort-grid.meta.json +48 -0
  71. package/src/fx/cohort-grid.ts +63 -0
  72. package/src/fx/compose.ts +114 -0
  73. package/src/fx/constellation.meta.json +51 -0
  74. package/src/fx/constellation.ts +103 -0
  75. package/src/fx/curve-flow.meta.json +40 -0
  76. package/src/fx/curve-flow.ts +63 -0
  77. package/src/fx/dashed-flow.meta.json +27 -0
  78. package/src/fx/dashed-flow.ts +8 -0
  79. package/src/fx/data-columns.meta.json +30 -0
  80. package/src/fx/data-columns.ts +18 -0
  81. package/src/fx/defaults.ts +92 -0
  82. package/src/fx/depth-of-field.meta.json +40 -0
  83. package/src/fx/depth-of-field.ts +4 -0
  84. package/src/fx/dolly.meta.json +26 -0
  85. package/src/fx/dolly.ts +4 -0
  86. package/src/fx/dot-screen.meta.json +35 -0
  87. package/src/fx/dot-screen.ts +4 -0
  88. package/src/fx/dynamic-instances.meta.json +40 -0
  89. package/src/fx/dynamic-instances.ts +57 -0
  90. package/src/fx/emissive.meta.json +26 -0
  91. package/src/fx/emissive.ts +8 -0
  92. package/src/fx/extruded-shapes.meta.json +62 -0
  93. package/src/fx/extruded-shapes.ts +133 -0
  94. package/src/fx/fab-wafer.meta.json +42 -0
  95. package/src/fx/fab-wafer.ts +72 -0
  96. package/src/fx/fade.meta.json +26 -0
  97. package/src/fx/fade.ts +4 -0
  98. package/src/fx/film.meta.json +26 -0
  99. package/src/fx/film.ts +4 -0
  100. package/src/fx/float.meta.json +26 -0
  101. package/src/fx/float.ts +8 -0
  102. package/src/fx/flythrough.meta.json +26 -0
  103. package/src/fx/flythrough.ts +4 -0
  104. package/src/fx/fog.meta.json +26 -0
  105. package/src/fx/fog.ts +8 -0
  106. package/src/fx/geo-fragments.meta.json +48 -0
  107. package/src/fx/geo-fragments.ts +59 -0
  108. package/src/fx/glass.meta.json +26 -0
  109. package/src/fx/glass.ts +8 -0
  110. package/src/fx/globe-arcs.meta.json +36 -0
  111. package/src/fx/globe-arcs.ts +67 -0
  112. package/src/fx/glow-tube.meta.json +26 -0
  113. package/src/fx/glow-tube.ts +8 -0
  114. package/src/fx/glyph-rain.meta.json +30 -0
  115. package/src/fx/glyph-rain.ts +18 -0
  116. package/src/fx/god-rays.meta.json +40 -0
  117. package/src/fx/god-rays.ts +4 -0
  118. package/src/fx/grid-horizon.meta.json +30 -0
  119. package/src/fx/grid-horizon.ts +18 -0
  120. package/src/fx/hex-grid.meta.json +29 -0
  121. package/src/fx/hex-grid.ts +18 -0
  122. package/src/fx/holo-fresnel.meta.json +26 -0
  123. package/src/fx/holo-fresnel.ts +8 -0
  124. package/src/fx/horizon-gates.meta.json +36 -0
  125. package/src/fx/horizon-gates.ts +60 -0
  126. package/src/fx/index.ts +258 -0
  127. package/src/fx/iridescent.meta.json +26 -0
  128. package/src/fx/iridescent.ts +8 -0
  129. package/src/fx/iris.meta.json +26 -0
  130. package/src/fx/iris.ts +4 -0
  131. package/src/fx/lightformers.meta.json +26 -0
  132. package/src/fx/lightformers.ts +8 -0
  133. package/src/fx/local.ts +200 -0
  134. package/src/fx/market-tape.meta.json +53 -0
  135. package/src/fx/market-tape.ts +97 -0
  136. package/src/fx/matcap.meta.json +26 -0
  137. package/src/fx/matcap.ts +8 -0
  138. package/src/fx/meta.schema.json +49 -0
  139. package/src/fx/metal.meta.json +26 -0
  140. package/src/fx/metal.ts +8 -0
  141. package/src/fx/mirror-floor.meta.json +26 -0
  142. package/src/fx/mirror-floor.ts +8 -0
  143. package/src/fx/neural-mesh.meta.json +54 -0
  144. package/src/fx/neural-mesh.ts +110 -0
  145. package/src/fx/orbit-agents.meta.json +36 -0
  146. package/src/fx/orbit-agents.ts +63 -0
  147. package/src/fx/orbit.meta.json +27 -0
  148. package/src/fx/orbit.ts +8 -0
  149. package/src/fx/outline.meta.json +43 -0
  150. package/src/fx/outline.ts +4 -0
  151. package/src/fx/paper-stack.meta.json +36 -0
  152. package/src/fx/paper-stack.ts +61 -0
  153. package/src/fx/particle-stream.meta.json +27 -0
  154. package/src/fx/particle-stream.ts +8 -0
  155. package/src/fx/particles.meta.json +26 -0
  156. package/src/fx/particles.ts +8 -0
  157. package/src/fx/pixelate.meta.json +28 -0
  158. package/src/fx/pixelate.ts +4 -0
  159. package/src/fx/points-on-geometry.meta.json +61 -0
  160. package/src/fx/points-on-geometry.ts +71 -0
  161. package/src/fx/proof-gate.meta.json +30 -0
  162. package/src/fx/proof-gate.ts +67 -0
  163. package/src/fx/rings.meta.json +27 -0
  164. package/src/fx/rings.ts +8 -0
  165. package/src/fx/room-ibl.meta.json +26 -0
  166. package/src/fx/room-ibl.ts +8 -0
  167. package/src/fx/sao.meta.json +32 -0
  168. package/src/fx/sao.ts +4 -0
  169. package/src/fx/scaffold.ts +172 -0
  170. package/src/fx/scatter.meta.json +49 -0
  171. package/src/fx/scatter.ts +74 -0
  172. package/src/fx/selective-bloom.meta.json +36 -0
  173. package/src/fx/selective-bloom.ts +4 -0
  174. package/src/fx/server-racks.meta.json +36 -0
  175. package/src/fx/server-racks.ts +54 -0
  176. package/src/fx/shader-particles.meta.json +46 -0
  177. package/src/fx/shader-particles.ts +75 -0
  178. package/src/fx/signal-pulse.meta.json +27 -0
  179. package/src/fx/signal-pulse.ts +8 -0
  180. package/src/fx/smaa.meta.json +19 -0
  181. package/src/fx/smaa.ts +4 -0
  182. package/src/fx/sobel.meta.json +24 -0
  183. package/src/fx/sobel.ts +4 -0
  184. package/src/fx/soft-shadows.meta.json +26 -0
  185. package/src/fx/soft-shadows.ts +8 -0
  186. package/src/fx/sprites.meta.json +40 -0
  187. package/src/fx/sprites.ts +57 -0
  188. package/src/fx/stagger-reveal.meta.json +26 -0
  189. package/src/fx/stagger-reveal.ts +8 -0
  190. package/src/fx/starfield.meta.json +32 -0
  191. package/src/fx/starfield.ts +18 -0
  192. package/src/fx/swarm.meta.json +27 -0
  193. package/src/fx/swarm.ts +8 -0
  194. package/src/fx/tessellate.meta.json +39 -0
  195. package/src/fx/tessellate.ts +79 -0
  196. package/src/fx/tokens.meta.json +27 -0
  197. package/src/fx/tokens.ts +8 -0
  198. package/src/fx/trail.meta.json +27 -0
  199. package/src/fx/trail.ts +8 -0
  200. package/src/fx/trust-ledger.meta.json +30 -0
  201. package/src/fx/trust-ledger.ts +47 -0
  202. package/src/fx/types.ts +83 -0
  203. package/src/fx/util.ts +108 -0
  204. package/src/fx/vault-glyphs.meta.json +37 -0
  205. package/src/fx/vault-glyphs.ts +55 -0
  206. package/src/fx/video-screen.meta.json +57 -0
  207. package/src/fx/video-screen.ts +99 -0
  208. package/src/fx/vignette.meta.json +32 -0
  209. package/src/fx/vignette.ts +4 -0
  210. package/src/fx/volume-cloud.meta.json +58 -0
  211. package/src/fx/volume-cloud.ts +87 -0
  212. package/src/fx/volume-perlin.meta.json +46 -0
  213. package/src/fx/volume-perlin.ts +82 -0
  214. package/src/fx/volumetric-spot.meta.json +26 -0
  215. package/src/fx/volumetric-spot.ts +8 -0
  216. package/src/fx/wireframe-overlay.meta.json +27 -0
  217. package/src/fx/wireframe-overlay.ts +8 -0
  218. package/src/ir/defaults.ts +62 -0
  219. package/src/ir/field-reference.ts +96 -0
  220. package/src/ir/hash.ts +34 -0
  221. package/src/ir/ids.ts +65 -0
  222. package/src/ir/merge.ts +155 -0
  223. package/src/ir/schema.json +1211 -0
  224. package/src/ir/types.ts +333 -0
  225. package/src/ir/validate.ts +196 -0
  226. package/src/parse/derive.ts +205 -0
  227. package/src/parse/harvest/bundle.ts +56 -0
  228. package/src/parse/harvest/harness.html +22 -0
  229. package/src/parse/harvest/harness.ts +191 -0
  230. package/src/parse/harvest/index.ts +169 -0
  231. package/src/parse/harvest/shapes.ts +75 -0
  232. package/src/parse/markdown.ts +215 -0
  233. package/src/props/embed.ts +92 -0
  234. package/src/props/fetch.ts +97 -0
  235. package/src/props/generate.ts +152 -0
  236. package/src/props/key.ts +13 -0
  237. package/src/props/search.ts +180 -0
  238. package/src/render/embed-video.ts +80 -0
  239. package/src/render/font.ts +86 -0
  240. package/src/render/index.ts +149 -0
  241. package/src/render/template.html +87 -0
  242. package/src/runtime/backgrounds.ts +146 -0
  243. package/src/runtime/builders.ts +808 -0
  244. package/src/runtime/camera.ts +73 -0
  245. package/src/runtime/hud.ts +887 -0
  246. package/src/runtime/index.ts +1168 -0
  247. package/src/runtime/local-fx.ts +151 -0
  248. package/src/runtime/materials.ts +136 -0
  249. package/src/runtime/measure.ts +73 -0
  250. package/src/runtime/node-geometry.ts +26 -0
  251. package/src/runtime/palette.ts +111 -0
  252. package/src/runtime/post.ts +649 -0
  253. package/src/runtime/props.ts +292 -0
  254. package/src/runtime/quality.ts +20 -0
  255. package/src/runtime/rng.ts +8 -0
  256. package/src/runtime/scene.ts +644 -0
  257. package/src/runtime/text.ts +174 -0
  258. package/src/runtime/types.ts +118 -0
  259. package/src/serve/index.ts +376 -0
  260. package/src/util/paths.ts +35 -0
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Pure mappings from mermaid's semantic model to the Deck IR enums.
3
+ *
4
+ * Kept browser-free so both the harvest harness (bundled by esbuild) and the
5
+ * unit tests can import them. Mermaid's `vertex.type`, edge `stroke` and
6
+ * sequence message `type` numbers are the pinned scheme (see design D2).
7
+ */
8
+ import type { EdgeKind, NodeShape } from "../../ir/types.js";
9
+
10
+ /** Mermaid `vertex.type` → IR `NodeShape`. Unknown shapes fall back to `rect`. */
11
+ export function mapNodeShape(mermaidType: string | undefined): NodeShape {
12
+ switch (mermaidType) {
13
+ case "square":
14
+ case "rect":
15
+ case "rect_left_inv_arrow":
16
+ case "lean_right":
17
+ case "lean_left":
18
+ case "trapezoid":
19
+ case "inv_trapezoid":
20
+ case "subroutine":
21
+ case "data_rect":
22
+ case "fork":
23
+ case "join":
24
+ return "rect";
25
+ case "round":
26
+ return "round";
27
+ case "stadium":
28
+ return "stadium";
29
+ case "circle":
30
+ return "circle";
31
+ case "doublecircle":
32
+ return "doublecircle";
33
+ case "diamond":
34
+ case "question":
35
+ return "diamond";
36
+ case "hexagon":
37
+ return "hexagon";
38
+ case "cylinder":
39
+ case "cyl":
40
+ return "cylinder";
41
+ default:
42
+ return "rect";
43
+ }
44
+ }
45
+
46
+ /** Mermaid edge `stroke` → IR `EdgeKind`. */
47
+ export function mapEdgeKind(stroke: string | undefined): EdgeKind {
48
+ if (stroke === "thick") return "thick";
49
+ if (stroke === "dotted") return "dotted";
50
+ return "normal";
51
+ }
52
+
53
+ /**
54
+ * Mermaid sequence message `type` → IR `kind`, or `undefined` for entries that
55
+ * are not drawable messages (notes, activations, loops, …). The numeric map is
56
+ * the pinned v11 scheme.
57
+ */
58
+ export function mapMessageKind(mermaidType: number | undefined): "solid" | "dotted" | undefined {
59
+ switch (mermaidType) {
60
+ case 0:
61
+ case 3:
62
+ case 5:
63
+ case 24:
64
+ case 33:
65
+ return "solid";
66
+ case 1:
67
+ case 4:
68
+ case 6:
69
+ case 25:
70
+ case 34:
71
+ return "dotted";
72
+ default:
73
+ return undefined;
74
+ }
75
+ }
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Markdown deck grammar (spec: deck3d-skill "Markdown slide grammar").
3
+ *
4
+ * --- front matter --- deck-level defaults
5
+ * # Title starts a slide (a doc with no `#` is ONE slide `slide`)
6
+ * first paragraph subtitle
7
+ * - item bullet
8
+ * ```mermaid … ``` diagram source (harvested later)
9
+ * <!-- deck3d: {...} --> per-slide inline override (wins over deck.json)
10
+ */
11
+ import { assignSlideIds, parseHeading } from "../ir/ids.js";
12
+ import type { Defaults, SlideOverride } from "../ir/types.js";
13
+
14
+ export interface ParsedSlide {
15
+ index: number;
16
+ id: string;
17
+ title: string;
18
+ pin?: string;
19
+ subtitle?: string;
20
+ bullets: string[];
21
+ mermaid?: string;
22
+ inlineOverrides?: SlideOverride;
23
+ }
24
+
25
+ export interface ParsedDeck {
26
+ defaults: Defaults;
27
+ slides: ParsedSlide[];
28
+ }
29
+
30
+ export class MarkdownParseError extends Error {
31
+ constructor(
32
+ message: string,
33
+ readonly slideId: string,
34
+ ) {
35
+ super(message);
36
+ this.name = "MarkdownParseError";
37
+ }
38
+ }
39
+
40
+ const OVERRIDE_RE = /^<!--\s*deck3d:\s*([\s\S]*?)\s*-->\s*$/;
41
+ const BULLET_RE = /^\s*[-*]\s+(.*)$/;
42
+
43
+ interface RawSlide {
44
+ heading: string;
45
+ body: string[];
46
+ }
47
+
48
+ function splitFrontMatter(source: string): { frontMatter: string | undefined; body: string } {
49
+ if (!source.startsWith("---")) return { frontMatter: undefined, body: source };
50
+ const end = source.indexOf("\n---", 3);
51
+ if (end === -1) return { frontMatter: undefined, body: source };
52
+ const lineEnd = source.indexOf("\n", end + 1);
53
+ const frontMatter = source.slice(source.indexOf("\n", 3) + 1, end);
54
+ const body = lineEnd === -1 ? "" : source.slice(lineEnd + 1);
55
+ return { frontMatter, body };
56
+ }
57
+
58
+ function parseScalar(raw: string): unknown {
59
+ const t = raw.trim();
60
+ if (t === "true") return true;
61
+ if (t === "false") return false;
62
+ if (t === "null" || t === "~") return null;
63
+ if (/^-?\d+(\.\d+)?$/.test(t)) return Number(t);
64
+ if ((t.startsWith("{") && t.endsWith("}")) || (t.startsWith("[") && t.endsWith("]"))) {
65
+ try {
66
+ return JSON.parse(t);
67
+ } catch {
68
+ return t;
69
+ }
70
+ }
71
+ if ((t.startsWith('"') && t.endsWith('"')) || (t.startsWith("'") && t.endsWith("'"))) return t.slice(1, -1);
72
+ return t;
73
+ }
74
+
75
+ function parseFrontMatter(frontMatter: string | undefined): Defaults {
76
+ const defaults: Record<string, unknown> = {};
77
+ if (!frontMatter) return defaults;
78
+ for (const line of frontMatter.split("\n")) {
79
+ const trimmed = line.trim();
80
+ if (!trimmed || trimmed.startsWith("#")) continue;
81
+ const idx = trimmed.indexOf(":");
82
+ if (idx <= 0) continue;
83
+ defaults[trimmed.slice(0, idx).trim()] = parseScalar(trimmed.slice(idx + 1));
84
+ }
85
+ return defaults as Defaults;
86
+ }
87
+
88
+ function splitSlides(body: string): RawSlide[] {
89
+ const lines = body.split(/\r?\n/);
90
+ const slides: RawSlide[] = [];
91
+ let current: RawSlide | undefined;
92
+ let pending: string[] = [];
93
+ let inFence = false;
94
+ for (const line of lines) {
95
+ if (line.trim().startsWith("```")) inFence = !inFence;
96
+ if (!inFence && /^#\s+/.test(line)) {
97
+ if (!current && pending.some((l) => l.trim())) slides.push({ heading: "", body: pending });
98
+ pending = [];
99
+ current = { heading: line.replace(/^#\s+/, ""), body: [] };
100
+ slides.push(current);
101
+ continue;
102
+ }
103
+ if (!current) {
104
+ // Content before the first heading (or a zero-heading doc).
105
+ pending.push(line);
106
+ continue;
107
+ }
108
+ current.body.push(line);
109
+ }
110
+ if (slides.length === 0) slides.push({ heading: "", body: pending });
111
+ return slides;
112
+ }
113
+
114
+ function extractMermaid(body: string[]): string | undefined {
115
+ const blocks: string[] = [];
116
+ let inMermaid = false;
117
+ let buf: string[] = [];
118
+ for (const line of body) {
119
+ const fence = /^```(\w*)\s*$/.exec(line.trim());
120
+ if (fence && fence[1] === "mermaid") {
121
+ inMermaid = true;
122
+ buf = [];
123
+ continue;
124
+ }
125
+ if (inMermaid && line.trim().startsWith("```")) {
126
+ inMermaid = false;
127
+ blocks.push(buf.join("\n"));
128
+ continue;
129
+ }
130
+ if (inMermaid) buf.push(line);
131
+ }
132
+ // A slide has at most one diagram (the first mermaid block).
133
+ return blocks[0];
134
+ }
135
+
136
+ export function parseMarkdown(source: string): ParsedDeck {
137
+ const { frontMatter, body } = splitFrontMatter(source);
138
+ const defaults = parseFrontMatter(frontMatter);
139
+ const raws = splitSlides(body);
140
+ const ids = assignSlideIds(raws.map((r) => parseHeading(r.heading)));
141
+
142
+ const slides: ParsedSlide[] = raws.map((raw, i) => {
143
+ const heading = parseHeading(raw.heading);
144
+ const id = ids[i];
145
+ const content = stripNonContent(raw.body);
146
+ const subtitle = extractSubtitle(content);
147
+ const bullets = extractBullets(content);
148
+ const inlineOverrides = extractInlineOverride(content, id);
149
+ const mermaid = extractMermaid(raw.body);
150
+ const slide: ParsedSlide = { index: i + 1, id, title: heading.title, bullets };
151
+ if (heading.pin) slide.pin = heading.pin;
152
+ if (subtitle) slide.subtitle = subtitle;
153
+ if (mermaid) slide.mermaid = mermaid;
154
+ if (inlineOverrides) slide.inlineOverrides = inlineOverrides;
155
+ return slide;
156
+ });
157
+
158
+ return { defaults, slides };
159
+ }
160
+
161
+ /** Lines that contribute to subtitle/bullets (drops fences and comments). */
162
+ function stripNonContent(body: string[]): string[] {
163
+ const out: string[] = [];
164
+ let inFence = false;
165
+ for (const line of body) {
166
+ if (line.trim().startsWith("```")) {
167
+ inFence = !inFence;
168
+ continue;
169
+ }
170
+ if (inFence) continue;
171
+ if (line.trim().startsWith("<!--") && !OVERRIDE_RE.test(line.trim())) continue;
172
+ out.push(line);
173
+ }
174
+ return out;
175
+ }
176
+
177
+ function extractSubtitle(content: string[]): string | undefined {
178
+ const para: string[] = [];
179
+ for (const line of content) {
180
+ const t = line.trim();
181
+ if (!t) {
182
+ if (para.length) break;
183
+ continue;
184
+ }
185
+ if (BULLET_RE.test(line)) break;
186
+ if (/^#/.test(t)) continue;
187
+ para.push(t);
188
+ }
189
+ return para.length ? para.join(" ") : undefined;
190
+ }
191
+
192
+ function extractBullets(content: string[]): string[] {
193
+ const bullets: string[] = [];
194
+ for (const line of content) {
195
+ const m = BULLET_RE.exec(line);
196
+ if (m) bullets.push(m[1].trim());
197
+ }
198
+ return bullets;
199
+ }
200
+
201
+ function extractInlineOverride(content: string[], slideId: string): SlideOverride | undefined {
202
+ for (const line of content) {
203
+ const m = OVERRIDE_RE.exec(line.trim());
204
+ if (!m) continue;
205
+ try {
206
+ return JSON.parse(m[1]) as SlideOverride;
207
+ } catch (err) {
208
+ throw new MarkdownParseError(
209
+ `slide "${slideId}": invalid inline JSON in <!-- deck3d -->: ${(err as Error).message}`,
210
+ slideId,
211
+ );
212
+ }
213
+ }
214
+ return undefined;
215
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Prop embedding + automatic credits (design D7).
3
+ *
4
+ * `loadProps` resolves every *placeable* `overrides.props[]` entry from the
5
+ * `.deck3d/props/<source>-<id>.glb` cache beside the deck, verifies its pinned
6
+ * sha256, and returns a `{ key: base64 }` map for the runtime. Any missing or
7
+ * tampered cache file is a hard failure naming the prop and the fetch remedy —
8
+ * the caller writes no HTML.
9
+ *
10
+ * A prop is *placeable* only when its role can be rendered: the slide exists
11
+ * and, for `node:<id>`, the node exists on that slide. A dangling node role is
12
+ * a validate warning (kept, inert), so its cache file is not required and the
13
+ * prop is absent from the embedded map (E29).
14
+ *
15
+ * `creditsSlide` derives the attribution slide for any prop whose licence is
16
+ * not CC0 and not `generated`; it is appended to the *merged* view at render
17
+ * time, so `deck.json` never contains it.
18
+ */
19
+ import { existsSync, readFileSync } from "node:fs";
20
+ import { dirname, join } from "node:path";
21
+ import { applyOverrides } from "../ir/merge.js";
22
+ import type { DeckIR, MergedDeck, PropOverride, Slide } from "../ir/types.js";
23
+ import { sha256 } from "./fetch.js";
24
+ import { propKey } from "./key.js";
25
+
26
+ export class PropEmbedError extends Error {
27
+ constructor(message: string) {
28
+ super(message);
29
+ this.name = "PropEmbedError";
30
+ }
31
+ }
32
+
33
+ /** `generated` and CC0 props need no attribution; everything else does. */
34
+ export function requiresAttribution(licence: string): boolean {
35
+ const l = licence.trim().toLowerCase();
36
+ return l !== "generated" && !l.startsWith("cc0");
37
+ }
38
+
39
+ /** Props whose role resolves on the merged deck (dangling node roles are inert). */
40
+ export function activeProps(deck: MergedDeck): PropOverride[] {
41
+ return (deck.props ?? []).filter((prop) => {
42
+ const slide = deck.slides.find((s) => s.id === prop.slide);
43
+ if (!slide) return false;
44
+ if (!prop.role.startsWith("node:")) return true;
45
+ const nodeId = prop.role.slice("node:".length);
46
+ return Boolean(slide.diagram.nodes?.some((n) => n.id === nodeId));
47
+ });
48
+ }
49
+
50
+ /** Last slide of the deck: the attribution list, or `null` when none is owed. */
51
+ export function creditsSlide(props: PropOverride[], index: number): Slide | null {
52
+ const cited = props.filter((p) => requiresAttribution(p.licence));
53
+ if (!cited.length) return null;
54
+ return {
55
+ index,
56
+ id: "credits",
57
+ kind: "credits",
58
+ title: "Credits",
59
+ subtitle: "Model attribution",
60
+ bullets: cited.map((p) => {
61
+ const base = `${p.id} — ${p.author} (${p.source}, ${p.licence})`;
62
+ return p.restyle === "palette" ? `${base}, modified: restyled` : base;
63
+ }),
64
+ scene: "tokens",
65
+ diagram: { kind: "none" },
66
+ };
67
+ }
68
+
69
+ /** `{ "<source>-<id>": base64 }` for every placeable prop; throws on a bad cache. */
70
+ export function loadProps(ir: DeckIR, jsonFile: string): Record<string, string> {
71
+ const deck = applyOverrides(ir);
72
+ const dir = join(dirname(jsonFile), ".deck3d", "props");
73
+ const out: Record<string, string> = {};
74
+ for (const prop of activeProps(deck)) {
75
+ const key = propKey(prop);
76
+ const file = join(dir, `${key}.glb`);
77
+ if (!existsSync(file)) {
78
+ throw new PropEmbedError(
79
+ `prop '${prop.id}' is not cached (${file}) — run \`deck3d props fetch ${prop.source} ${prop.id}\``,
80
+ );
81
+ }
82
+ const bytes = new Uint8Array(readFileSync(file));
83
+ const hash = sha256(bytes);
84
+ if (hash !== prop.sha256) {
85
+ throw new PropEmbedError(
86
+ `prop '${prop.id}' sha256 ${hash} ≠ pinned ${prop.sha256} — re-run \`deck3d props fetch ${prop.source} ${prop.id}\``,
87
+ );
88
+ }
89
+ out[key] = Buffer.from(bytes).toString("base64");
90
+ }
91
+ return out;
92
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Prop fetch — download a candidate to the `.deck3d/props/` cache beside the
3
+ * deck, verify it is glTF/GLB, enforce a size cap, and pin its sha256.
4
+ * Self-containment: a `.gltf` with any external buffer URI is rejected.
5
+ */
6
+ import { createHash } from "node:crypto";
7
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { propKey } from "./key.js";
10
+ import { type PropCandidate, vendoredPath } from "./search.js";
11
+
12
+ export const DEFAULT_PROP_SIZE_CAP = 8 * 1024 * 1024;
13
+ export const DEFAULT_PROP_HTTP_TIMEOUT_MS = 10_000;
14
+
15
+ export class PropFetchError extends Error {
16
+ constructor(message: string) {
17
+ super(message);
18
+ this.name = "PropFetchError";
19
+ }
20
+ }
21
+
22
+ export function sha256(bytes: Uint8Array): string {
23
+ return createHash("sha256").update(bytes).digest("hex");
24
+ }
25
+
26
+ function isGlb(bytes: Uint8Array): boolean {
27
+ return bytes.length >= 4 && bytes[0] === 0x67 && bytes[1] === 0x6c && bytes[2] === 0x54 && bytes[3] === 0x46;
28
+ }
29
+
30
+ /**
31
+ * Validate glTF/GLB self-containment; throws `PropFetchError`.
32
+ *
33
+ * Both `buffers[].uri` (geometry) and `images[].uri` (textures) must be absent
34
+ * or a `data:` URI — any other reference breaks the offline-open guarantee (an
35
+ * external side-car is never embedded) and the content hash's meaning.
36
+ */
37
+ function assertGltf(bytes: Uint8Array): void {
38
+ if (isGlb(bytes)) return;
39
+ let json: { buffers?: Array<{ uri?: string }>; images?: Array<{ uri?: string }> };
40
+ try {
41
+ json = JSON.parse(new TextDecoder().decode(bytes)) as typeof json;
42
+ } catch {
43
+ throw new PropFetchError("not a glTF/GLB");
44
+ }
45
+ const external = [...(json.buffers ?? []), ...(json.images ?? [])]
46
+ .map((r) => r.uri)
47
+ .filter((u): u is string => typeof u === "string" && !u.startsWith("data:"));
48
+ if (external.length) throw new PropFetchError(`glTF has an external URI (self-containment): ${external[0]}`);
49
+ }
50
+
51
+ async function download(candidate: PropCandidate, timeoutMs: number): Promise<Uint8Array> {
52
+ if (candidate.source === "vendored") return new Uint8Array(readFileSync(vendoredPath(candidate.id)));
53
+ if (!candidate.downloadUrl) throw new PropFetchError(`no download URL for ${candidate.id}`);
54
+ const controller = new AbortController();
55
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
56
+ try {
57
+ const res = await fetch(candidate.downloadUrl, { signal: controller.signal });
58
+ if (!res.ok) throw new PropFetchError(`download failed (HTTP ${res.status}) for ${candidate.id}`);
59
+ return new Uint8Array(await res.arrayBuffer());
60
+ } finally {
61
+ clearTimeout(timer);
62
+ }
63
+ }
64
+
65
+ export interface FetchPropOptions {
66
+ destDir: string;
67
+ sizeCap?: number;
68
+ /** Expected sha256 (from the override); a mismatch fails. */
69
+ sha256?: string;
70
+ timeoutMs?: number;
71
+ }
72
+
73
+ export interface FetchResult {
74
+ path: string;
75
+ sha256: string;
76
+ bytes: number;
77
+ }
78
+
79
+ export async function fetchProp(candidate: PropCandidate, opts: FetchPropOptions): Promise<FetchResult> {
80
+ const cap = opts.sizeCap ?? DEFAULT_PROP_SIZE_CAP;
81
+ const timeoutMs = opts.timeoutMs ?? Number(process.env.DECK3D_HTTP_TIMEOUT_MS ?? DEFAULT_PROP_HTTP_TIMEOUT_MS);
82
+ const bytes = await download(candidate, timeoutMs);
83
+ if (bytes.length > cap) throw new PropFetchError(`${candidate.source}-${candidate.id}: ${bytes.length} bytes > cap ${cap}`);
84
+ assertGltf(bytes);
85
+ const hash = sha256(bytes);
86
+ if (opts.sha256 && opts.sha256 !== hash) throw new PropFetchError(`${candidate.source}-${candidate.id}: sha256 ${hash} ≠ pinned ${opts.sha256}`);
87
+
88
+ const dest = join(opts.destDir, `${propKey(candidate)}.glb`);
89
+ if (existsSync(dest)) {
90
+ const existing = sha256(readFileSync(dest));
91
+ if (existing !== hash) throw new PropFetchError(`${candidate.source}-${candidate.id}: cached hash ${existing} ≠ fetched ${hash}`);
92
+ } else {
93
+ mkdirSync(opts.destDir, { recursive: true });
94
+ writeFileSync(dest, bytes);
95
+ }
96
+ return { path: dest, sha256: hash, bytes: bytes.length };
97
+ }
@@ -0,0 +1,152 @@
1
+ /**
2
+ * `props generate` — geometry-only GLB via the free Hunyuan3D-2 HF Space
3
+ * (design D7). Python is an *optional* dependency: `parse`/`render`/`build`
4
+ * never touch it. Missing `python3`/`gradio_client` fails with the install hint
5
+ * and writes no cache file.
6
+ *
7
+ * The spawn is injectable so a unit test can simulate a missing client (X8).
8
+ */
9
+ import { spawnSync } from "node:child_process";
10
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
11
+ import { join } from "node:path";
12
+ import type { PropOverride } from "../ir/types.js";
13
+ import { sha256 } from "./fetch.js";
14
+ import { propKey } from "./key.js";
15
+
16
+ export const GENERATE_HINT = "pip install gradio_client";
17
+ export const HUNYUAN_SPACE = "tencent/Hunyuan3D-2";
18
+ export const HUNYUAN_API = "/shape_generation";
19
+
20
+ export class GenerateError extends Error {
21
+ constructor(message: string) {
22
+ super(message);
23
+ this.name = "GenerateError";
24
+ }
25
+ }
26
+
27
+ export interface SpawnResult {
28
+ status: number | null;
29
+ stdout: string;
30
+ stderr: string;
31
+ error?: Error;
32
+ }
33
+
34
+ /** Injectable spawn signature (defaults to `spawnSync`). */
35
+ export type SpawnFn = (command: string, args: string[], options: { encoding: "utf8" }) => SpawnResult;
36
+
37
+ export const PYTHON_SCRIPT = `import sys
38
+ from gradio_client import Client, handle_file
39
+ client = Client("${HUNYUAN_SPACE}")
40
+ result = client.predict(handle_file(sys.argv[1]), api_name="${HUNYUAN_API}")
41
+ first = result[0]
42
+ print(first["value"] if isinstance(first, dict) else first)
43
+ `;
44
+
45
+ function lastLine(text: string | undefined): string {
46
+ const lines = (text ?? "").split("\n").map((l) => l.trim()).filter(Boolean);
47
+ return lines[lines.length - 1] ?? "";
48
+ }
49
+
50
+ export interface GenerateOptions {
51
+ fromImage: string;
52
+ name: string;
53
+ /** Cache directory — `.deck3d/props/` beside the deck. */
54
+ destDir: string;
55
+ spawn?: SpawnFn;
56
+ python?: string;
57
+ }
58
+
59
+ export interface GenerateResult {
60
+ path: string;
61
+ sha256: string;
62
+ bytes: number;
63
+ /** Ready-to-paste `overrides.props[]` entry. */
64
+ entry: PropOverride;
65
+ }
66
+
67
+ export async function generateProp(opts: GenerateOptions): Promise<GenerateResult> {
68
+ const spawn = opts.spawn ?? (spawnSync as unknown as SpawnFn);
69
+ const python = opts.python ?? "python3";
70
+ const run = spawn(python, ["-c", PYTHON_SCRIPT, opts.fromImage], { encoding: "utf8" });
71
+ if (run.error) {
72
+ throw new GenerateError(`python3 is unavailable (${run.error.message}) — install Python 3 and run \`${GENERATE_HINT}\``);
73
+ }
74
+ const combined = `${run.stdout ?? ""}\n${run.stderr ?? ""}`;
75
+ if (run.status !== 0) {
76
+ if (/gradio_client/i.test(combined) || /ModuleNotFoundError|No module named/i.test(combined)) {
77
+ throw new GenerateError(`gradio_client is missing — run \`${GENERATE_HINT}\``);
78
+ }
79
+ throw new GenerateError(`generation failed (exit ${run.status ?? "signal"}): ${lastLine(run.stderr)}`);
80
+ }
81
+ const produced = lastLine(run.stdout);
82
+ if (!produced || !existsSync(produced)) {
83
+ throw new GenerateError("generation produced no GLB (service quota-limited or returned no file)");
84
+ }
85
+ const bytes = new Uint8Array(readFileSync(produced));
86
+ if (bytes.length < 4 || bytes[0] !== 0x67 || bytes[1] !== 0x6c || bytes[2] !== 0x54 || bytes[3] !== 0x46) {
87
+ throw new GenerateError(`${produced} is not a GLB`);
88
+ }
89
+ const key = propKey({ source: "generated", id: opts.name });
90
+ mkdirSync(opts.destDir, { recursive: true });
91
+ const dest = join(opts.destDir, `${key}.glb`);
92
+ writeFileSync(dest, bytes);
93
+ const hash = sha256(bytes);
94
+ return {
95
+ path: dest,
96
+ sha256: hash,
97
+ bytes: bytes.length,
98
+ entry: {
99
+ source: "generated",
100
+ id: opts.name,
101
+ licence: "generated",
102
+ author: "generated",
103
+ sha256: hash,
104
+ slide: "<slide-id>",
105
+ role: "illustration",
106
+ restyle: "palette",
107
+ },
108
+ };
109
+ }
110
+
111
+ /** Default free text-to-image endpoint; override with `DECK3D_T2I_URL`. */
112
+ export const DEFAULT_T2I_URL = "https://image.pollinations.ai/prompt/{prompt}";
113
+
114
+ export interface TextToImageOptions {
115
+ prompt: string;
116
+ name: string;
117
+ destDir: string;
118
+ url?: string;
119
+ timeoutMs?: number;
120
+ fetchImpl?: typeof fetch;
121
+ }
122
+
123
+ /**
124
+ * Text → PNG hop in front of the existing `--from-image` path. Network happens
125
+ * at AUTHORING time only; the render never depends on it.
126
+ */
127
+ export async function textToImage(opts: TextToImageOptions): Promise<string> {
128
+ const template = opts.url ?? process.env.DECK3D_T2I_URL ?? DEFAULT_T2I_URL;
129
+ const url = template.includes("{prompt}")
130
+ ? template.replace("{prompt}", encodeURIComponent(opts.prompt))
131
+ : `${template}${template.includes("?") ? "&" : "?"}prompt=${encodeURIComponent(opts.prompt)}`;
132
+
133
+ const doFetch = opts.fetchImpl ?? fetch;
134
+ const controller = new AbortController();
135
+ const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 30_000);
136
+ try {
137
+ const res = await doFetch(url, { signal: controller.signal });
138
+ if (!res.ok) throw new GenerateError(`text-to-image endpoint ${url} returned HTTP ${res.status}`);
139
+ const bytes = new Uint8Array(await res.arrayBuffer());
140
+ if (bytes.length < 8) throw new GenerateError(`text-to-image endpoint ${url} returned no image`);
141
+ mkdirSync(opts.destDir, { recursive: true });
142
+ const dest = join(opts.destDir, `${propKey({ source: "generated", id: opts.name })}.png`);
143
+ writeFileSync(dest, bytes);
144
+ return dest;
145
+ } catch (err) {
146
+ if (err instanceof GenerateError) throw err;
147
+ const reason = (err as Error).name === "AbortError" ? "timed out" : (err as Error).message;
148
+ throw new GenerateError(`text-to-image endpoint ${url} failed (${reason})`);
149
+ } finally {
150
+ clearTimeout(timer);
151
+ }
152
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Prop cache key — `<source>-<id>`, slug-only (never URL-derived), shared by
3
+ * fetch, embed, generate and the browser runtime so all four agree on the file
4
+ * name and the `window.__DECK_PROPS` map key. No Node imports (bundled into the
5
+ * runtime).
6
+ */
7
+ export function propSlug(value: string): string {
8
+ return value.replace(/[^a-z0-9-]/gi, "-").replace(/-+/g, "-");
9
+ }
10
+
11
+ export function propKey(prop: { source: string; id: string }): string {
12
+ return `${propSlug(prop.source)}-${propSlug(prop.id)}`;
13
+ }