@blackbelt-technology/pi-dashboard-deck3d 0.0.0-stage → 0.8.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,180 @@
1
+ /**
2
+ * Prop search — LLM picks from a candidate table; code only searches.
3
+ *
4
+ * Sources: the vendored CC0 subset under `assets/props/` (offline, searched
5
+ * first) and Poly Pizza (optional, `POLY_PIZZA_KEY`).
6
+ */
7
+ import { readFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { pkgRoot } from "../util/paths.js";
10
+
11
+ const ROOT = pkgRoot();
12
+
13
+ export type PropSource = "vendored" | "poly-pizza" | "generated";
14
+
15
+ export interface PropCandidate {
16
+ source: PropSource;
17
+ id: string;
18
+ name: string;
19
+ tags: string[];
20
+ tris: number;
21
+ bytes: number;
22
+ licence: string;
23
+ author: string;
24
+ downloadUrl?: string;
25
+ }
26
+
27
+ interface ManifestItem {
28
+ id: string;
29
+ name: string;
30
+ tags: string[];
31
+ file: string;
32
+ bytes: number;
33
+ tris: number;
34
+ licence: string;
35
+ author: string;
36
+ }
37
+
38
+ interface Manifest {
39
+ items: ManifestItem[];
40
+ }
41
+
42
+ export const DEFAULT_HTTP_TIMEOUT_MS = 10_000;
43
+ export const POLY_PIZZA_ENDPOINT = "https://api.poly.pizza/v1.1/search";
44
+
45
+ export function vendoredManifest(): Manifest {
46
+ return JSON.parse(readFileSync(join(ROOT, "assets", "props", "manifest.json"), "utf8")) as Manifest;
47
+ }
48
+
49
+ /** Vendored candidates matching `query` (empty query → all), id-sorted. */
50
+ export function vendoredCandidates(query: string): PropCandidate[] {
51
+ const q = query.trim().toLowerCase();
52
+ return vendoredManifest()
53
+ .items.filter((it) => !q || it.name.toLowerCase().includes(q) || it.tags.some((t) => t.toLowerCase().includes(q)))
54
+ .map((it) => ({
55
+ source: "vendored" as const,
56
+ id: it.id,
57
+ name: it.name,
58
+ tags: it.tags,
59
+ tris: it.tris,
60
+ bytes: it.bytes,
61
+ licence: it.licence,
62
+ author: it.author,
63
+ }))
64
+ .sort((a, b) => a.id.localeCompare(b.id));
65
+ }
66
+
67
+ /** Absolute path of a vendored model. */
68
+ export function vendoredPath(id: string): string {
69
+ return join(ROOT, "assets", "props", `${id}.glb`);
70
+ }
71
+
72
+ export interface PolySearchResult {
73
+ candidates: PropCandidate[];
74
+ notice?: string;
75
+ }
76
+
77
+ interface PolyResponse {
78
+ results?: Array<Record<string, unknown>>;
79
+ }
80
+
81
+ /** Parse a Poly Pizza API response into candidate rows (defensive). */
82
+ export function parsePolyResponse(body: PolyResponse): PropCandidate[] {
83
+ return (body.results ?? [])
84
+ .map((r) => {
85
+ const id = String(r.id ?? r.Id ?? r.uid ?? "");
86
+ const tags = Array.isArray(r.Tags) ? (r.Tags as unknown[]).map(String) : [];
87
+ return {
88
+ source: "poly-pizza" as const,
89
+ id,
90
+ name: String(r.name ?? r.Name ?? id),
91
+ tags,
92
+ tris: Number(r.TriCount ?? r.tris ?? 0) || 0,
93
+ bytes: Number(r.DownloadSize ?? r.bytes ?? 0) || 0,
94
+ licence: String(r.Licence ?? r.licence ?? "CC0-1.0"),
95
+ author: String(r.Designer ?? r.author ?? "Poly Pizza"),
96
+ downloadUrl: String(r.Download ?? r.downloadUrl ?? ""),
97
+ };
98
+ })
99
+ .filter((c) => c.id && c.downloadUrl);
100
+ }
101
+
102
+ /**
103
+ * Query Poly Pizza. Unset key / unreachable / timeout → vendored-only with a
104
+ * one-line notice (never throws).
105
+ */
106
+ export async function searchPolyPizza(query: string, opts: { timeoutMs?: number; key?: string; endpoint?: string } = {}): Promise<PolySearchResult> {
107
+ const key = opts.key ?? process.env.POLY_PIZZA_KEY;
108
+ if (!key) return { candidates: [], notice: "online source skipped (no POLY_PIZZA_KEY)" };
109
+ const timeoutMs = opts.timeoutMs ?? Number(process.env.DECK3D_HTTP_TIMEOUT_MS ?? DEFAULT_HTTP_TIMEOUT_MS);
110
+ const controller = new AbortController();
111
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
112
+ try {
113
+ const url = `${opts.endpoint ?? process.env.POLY_PIZZA_ENDPOINT ?? POLY_PIZZA_ENDPOINT}?${new URLSearchParams({ query, limit: "20" }).toString()}`;
114
+ const res = await fetch(url, { headers: { "x-auth-token": key }, signal: controller.signal });
115
+ if (!res.ok) return { candidates: [], notice: `online source skipped (HTTP ${res.status})` };
116
+ return { candidates: parsePolyResponse((await res.json()) as PolyResponse) };
117
+ } catch (err) {
118
+ const reason = (err as Error).name === "AbortError" ? "timeout" : "unreachable";
119
+ return { candidates: [], notice: `online source skipped (${reason})` };
120
+ } finally {
121
+ clearTimeout(timer);
122
+ }
123
+ }
124
+
125
+ export interface SearchResult {
126
+ candidates: PropCandidate[];
127
+ notices: string[];
128
+ }
129
+
130
+ /** Vendored first, then optional online source. Writes no files. */
131
+ export async function searchProps(query: string, opts: { timeoutMs?: number; key?: string; endpoint?: string } = {}): Promise<SearchResult> {
132
+ const vendored = vendoredCandidates(query);
133
+ const notices: string[] = [];
134
+ const online = await searchPolyPizza(query, opts);
135
+ if (online.notice) notices.push(online.notice);
136
+ return { candidates: [...vendored, ...online.candidates], notices };
137
+ }
138
+
139
+ /**
140
+ * Ambient props are instanced many times in the background, so they must be
141
+ * silhouette-friendly and cheap. The cap is on triangles, inclusive.
142
+ */
143
+ export const AMBIENT_MAX_TRIS = 2000;
144
+
145
+ /** Entry template printed beside an `--role ambient` candidate. */
146
+ export interface AmbientTemplate {
147
+ source: PropSource;
148
+ id: string;
149
+ licence: string;
150
+ author: string;
151
+ sha256: string;
152
+ slide: string;
153
+ role: "ambient";
154
+ count: number;
155
+ anim: "float";
156
+ restyle: "palette";
157
+ size: number;
158
+ }
159
+
160
+ export function ambientTemplate(candidate: PropCandidate): AmbientTemplate {
161
+ return {
162
+ source: candidate.source,
163
+ id: candidate.id,
164
+ licence: candidate.licence,
165
+ author: candidate.author,
166
+ // Filled in by `props fetch`, which is what pins the bytes.
167
+ sha256: "<sha256 from props fetch>",
168
+ slide: "<slide-id>",
169
+ role: "ambient",
170
+ count: 12,
171
+ anim: "float",
172
+ restyle: "palette",
173
+ size: 0.6,
174
+ };
175
+ }
176
+
177
+ /** Candidates a background instance can afford. */
178
+ export function ambientCandidates(candidates: PropCandidate[]): PropCandidate[] {
179
+ return candidates.filter((c) => c.tris <= AMBIENT_MAX_TRIS);
180
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Inline video clips referenced by effect params into the deck IR as `data:`
3
+ * URLs, so a deck with a video layer can still be ONE portable file.
4
+ *
5
+ * Why this exists at all: a clip must be SAME-ORIGIN or the browser taints the
6
+ * canvas and `texImage2D` refuses it. `deck3d serve` solves that with an asset
7
+ * route; a deck mailed as a single `.html` has no server, and a `file://`
8
+ * sibling is cross-origin. A `data:` URL is same-origin by definition.
9
+ *
10
+ * The cost is honest and large: base64 is ~33% bigger than the source bytes,
11
+ * so this is opt-in (`--embed-video`) rather than the default.
12
+ */
13
+ import { existsSync, readFileSync, statSync } from "node:fs";
14
+ import { dirname, extname, isAbsolute, resolve } from "node:path";
15
+ import type { DeckIR, EffectRef } from "../ir/types.js";
16
+
17
+ const MEDIA_TYPES: Record<string, string> = {
18
+ ".mp4": "video/mp4",
19
+ ".webm": "video/webm",
20
+ ".ogv": "video/ogg",
21
+ };
22
+
23
+ /** A clip already inlined, or fetched at runtime — nothing to embed. */
24
+ function isInlineOrRemote(src: string): boolean {
25
+ return /^(data:|https?:|blob:)/i.test(src);
26
+ }
27
+
28
+ export interface EmbedVideoResult {
29
+ ir: DeckIR;
30
+ /** `<slide>/<effect>` → embedded byte count, for the CLI's report. */
31
+ embedded: Record<string, number>;
32
+ warnings: string[];
33
+ }
34
+
35
+ /**
36
+ * Rewrite every effect `src` that names a local clip into a `data:` URL.
37
+ *
38
+ * Returns a COPY: the on-disk IR keeps its readable relative paths, and only
39
+ * the rendered HTML carries the bytes.
40
+ */
41
+ export function embedVideo(ir: DeckIR, jsonPath: string): EmbedVideoResult {
42
+ const deckDir = dirname(resolve(jsonPath));
43
+ const embedded: Record<string, number> = {};
44
+ const warnings: string[] = [];
45
+ const copy = JSON.parse(JSON.stringify(ir)) as DeckIR;
46
+
47
+ /** Resolve one clip to a `data:` URL, or explain why it cannot be embedded. */
48
+ const inline = (src: string): { url: string; size: number } | { error: string } => {
49
+ // Never read outside the deck directory: the same confinement the serve
50
+ // asset route enforces.
51
+ const target = isAbsolute(src) ? resolve(src) : resolve(deckDir, src);
52
+ if (!target.startsWith(`${deckDir}/`)) return { error: `refusing to embed '${src}' from outside the deck directory` };
53
+ if (!existsSync(target)) return { error: `clip not found: ${src}` };
54
+ const type = MEDIA_TYPES[extname(target).toLowerCase()];
55
+ if (!type) return { error: `not an embeddable clip: ${src}` };
56
+ const bytes = readFileSync(target);
57
+ return { url: `data:${type};base64,${bytes.toString("base64")}`, size: statSync(target).size };
58
+ };
59
+
60
+ const visit = (refs: EffectRef[] | undefined, where: string): void => {
61
+ for (const ref of refs ?? []) {
62
+ const src = ref.params?.src;
63
+ if (typeof src !== "string" || !src || isInlineOrRemote(src)) continue;
64
+ const result = inline(src);
65
+ if ("error" in result) {
66
+ warnings.push(`${where}: ${result.error}`);
67
+ continue;
68
+ }
69
+ ref.params = { ...ref.params, src: result.url };
70
+ embedded[where] = result.size;
71
+ }
72
+ };
73
+
74
+ visit(copy.overrides?.effects, "overrides.effects");
75
+ for (const slide of copy.slides) visit(slide.effects, `slides.${slide.id}`);
76
+ for (const [id, ov] of Object.entries(copy.overrides?.slides ?? {})) {
77
+ visit((ov as { effects?: EffectRef[] }).effects, `overrides.slides.${id}`);
78
+ }
79
+ return { ir: copy, embedded, warnings };
80
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Font subsetting — the embedded Poppins is reduced to the glyphs the merged IR
3
+ * actually renders (titles, bullets, labels, override-added strings), so text
4
+ * added through `overrides` always has glyphs and the HTML stays small.
5
+ *
6
+ * Determinism: opentype.js stamps `head.created`/`head.modified` with the
7
+ * current time on write, so both are zeroed afterwards. Same glyph set ⇒
8
+ * byte-identical subset.
9
+ */
10
+
11
+ import type { Font, Glyph } from "opentype.js";
12
+ import opentype from "opentype.js";
13
+ import type { MergedDeck } from "../ir/types.js";
14
+
15
+ /** Every string the runtime can render, across all slides. */
16
+ export function glyphText(merged: MergedDeck): string {
17
+ const out: string[] = [];
18
+ for (const s of merged.slides) {
19
+ out.push(s.title);
20
+ if (s.subtitle) out.push(s.subtitle);
21
+ out.push(...s.bullets);
22
+ out.push(...diagramText(s));
23
+ }
24
+ return out.join("");
25
+ }
26
+
27
+ function diagramText(slide: MergedDeck["slides"][number]): string[] {
28
+ const d = slide.diagram;
29
+ const out: string[] = [];
30
+ for (const n of d.nodes ?? []) out.push(n.label);
31
+ for (const e of d.edges ?? []) if (e.label) out.push(e.label);
32
+ for (const a of d.actors ?? []) out.push(a.label);
33
+ for (const m of d.messages ?? []) out.push(m.text);
34
+ for (const g of d.groups ?? []) out.push(g.title);
35
+ return out;
36
+ }
37
+
38
+ /** Build a TTF containing only `text`'s code points (plus `.notdef`/space). */
39
+ export function subsetFont(font: Font, text: string): ArrayBuffer {
40
+ const wanted = new Set<number>([32]);
41
+ for (const ch of text) wanted.add(ch.codePointAt(0) ?? 0);
42
+ const glyphs: Glyph[] = [];
43
+ const seen = new Set<number>();
44
+ const notdef = font.glyphs.get(0);
45
+ glyphs.push(new opentype.Glyph({ name: notdef.name ?? ".notdef", unicode: 0, advanceWidth: notdef.advanceWidth, path: notdef.path }));
46
+ seen.add(0);
47
+ for (const code of wanted) {
48
+ const g = font.charToGlyph(String.fromCodePoint(code));
49
+ if (!g || g.index === 0 || seen.has(g.index)) continue;
50
+ seen.add(g.index);
51
+ glyphs.push(new opentype.Glyph({ name: g.name ?? undefined, unicode: code, advanceWidth: g.advanceWidth, path: g.path }));
52
+ }
53
+ const subset = new opentype.Font({
54
+ familyName: font.names.fontFamily?.en ?? "Poppins",
55
+ styleName: font.names.fontSubfamily?.en ?? "Bold",
56
+ unitsPerEm: font.unitsPerEm,
57
+ ascender: font.ascender,
58
+ descender: font.descender,
59
+ glyphs,
60
+ });
61
+ return freezeHead(subset.toArrayBuffer());
62
+ }
63
+
64
+ /** Zero `head.created`/`head.modified` so the bytes do not depend on the clock. */
65
+ export function freezeHead(buffer: ArrayBuffer): ArrayBuffer {
66
+ const view = new DataView(buffer);
67
+ const numTables = view.getUint16(4);
68
+ for (let i = 0; i < numTables; i++) {
69
+ const rec = 12 + i * 16;
70
+ const tag = String.fromCharCode(view.getUint8(rec), view.getUint8(rec + 1), view.getUint8(rec + 2), view.getUint8(rec + 3));
71
+ if (tag !== "head") continue;
72
+ const headOffset = view.getUint32(rec + 8);
73
+ // The `head` table's directory checksum is computed over its clock-stamped
74
+ // dates, so zero it alongside them (the dates and checkSumAdjustment too),
75
+ // otherwise the bytes differ across calls.
76
+ for (let b = 0; b < 4; b++) view.setUint8(rec + 4 + b, 0);
77
+ // head: version(4) fontRevision(4) checkSumAdjustment(4) magicNumber(4) flags(2)
78
+ // unitsPerEm(2) → created at +20 (8 B) and modified at +28 (8 B).
79
+ // opentype computes checkSumAdjustment from the (clock-stamped) dates, so it
80
+ // is zeroed too — otherwise the bytes differ across calls.
81
+ for (let b = 0; b < 4; b++) view.setUint8(headOffset + 8 + b, 0);
82
+ for (let b = 0; b < 16; b++) view.setUint8(headOffset + 20 + b, 0);
83
+ break;
84
+ }
85
+ return buffer;
86
+ }
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Renderer — `deck.html` = fixed template + inlined esbuild runtime + inlined
3
+ * canonical-IR JSON + base64 Poppins TTF (design D3).
4
+ *
5
+ * Determinism: the runtime bundle is built once at package build (fixed
6
+ * options, no hashes), the IR is serialised with sorted keys, the font is the
7
+ * vendored constant. Same inputs ⇒ byte-identical output. No dates, no random.
8
+ */
9
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
10
+ import { dirname, join } from "node:path";
11
+ import opentype from "opentype.js";
12
+ import { canonicalJson } from "../ir/hash.js";
13
+ import { localRefs, resolveLocalEffect, toFactorySource } from "../fx/local.js";
14
+ import { applyOverrides } from "../ir/merge.js";
15
+ import type { DeckIR } from "../ir/types.js";
16
+ import { activeProps, creditsSlide } from "../props/embed.js";
17
+ import { pkgRoot } from "../util/paths.js";
18
+ import { glyphText, subsetFont } from "./font.js";
19
+
20
+ /** Package root — correct both unbundled (src) and bundled (`dist/cli.js`). */
21
+ const ROOT = pkgRoot();
22
+
23
+ export const RUNTIME_PATH = join(ROOT, "dist", "runtime.js");
24
+ export const TEMPLATE_PATH = join(ROOT, "src", "render", "template.html");
25
+ export const FONT_PATH = join(ROOT, "assets", "Poppins-Bold.ttf");
26
+
27
+ export function runtimeSource(path = RUNTIME_PATH): string {
28
+ return readFileSync(path, "utf8");
29
+ }
30
+
31
+ /** The runtime bundle, built on demand when `dist/runtime.js` is absent (dev/CI). */
32
+ export async function ensureRuntime(): Promise<string> {
33
+ if (existsSync(RUNTIME_PATH)) return runtimeSource();
34
+ const esbuild = await import("esbuild");
35
+ const result = await esbuild.build({
36
+ entryPoints: [join(ROOT, "src", "runtime", "index.ts")],
37
+ bundle: true,
38
+ format: "iife",
39
+ platform: "browser",
40
+ target: "es2022",
41
+ write: false,
42
+ legalComments: "none",
43
+ logLevel: "silent",
44
+ });
45
+ const code = result.outputFiles[0].text;
46
+ mkdirSync(dirname(RUNTIME_PATH), { recursive: true });
47
+ writeFileSync(RUNTIME_PATH, code);
48
+ return code;
49
+ }
50
+
51
+ export function fontBase64(path = FONT_PATH): string {
52
+ return readFileSync(path).toString("base64");
53
+ }
54
+
55
+ /** Full TTF parsed, then subset to `text` and base64-encoded (deterministic). */
56
+ export function subsetFontBase64(text: string, path = FONT_PATH): string {
57
+ const bytes = new Uint8Array(readFileSync(path));
58
+ const font = opentype.parse(bytes.buffer);
59
+ return Buffer.from(subsetFont(font, text)).toString("base64");
60
+ }
61
+
62
+ /** Dotted leaf paths of an override object (`camera.distance`, `mode`). */
63
+ function leafPaths(obj: unknown, prefix = ""): string[] {
64
+ if (obj === null || typeof obj !== "object" || Array.isArray(obj)) return prefix ? [prefix.slice(0, -1)] : [];
65
+ return Object.entries(obj).flatMap(([k, v]) => leafPaths(v, `${prefix}${k}.`));
66
+ }
67
+
68
+ /** Which merged values came from `overrides`, for the configurator's markers. */
69
+ function overriddenKeys(ir: DeckIR): { deck: string[]; slides: Record<string, string[]> } {
70
+ const slides: Record<string, string[]> = {};
71
+ for (const [id, entry] of Object.entries(ir.overrides.slides ?? {})) slides[id] = leafPaths(entry);
72
+ return { deck: leafPaths(ir.overrides.deck ?? {}), slides };
73
+ }
74
+
75
+ /** JSON safe to inline in a `<script>`: sorted keys, `<`/U+2028/U+2029 escaped. */
76
+ export function jsonForScript(value: unknown): string {
77
+ return canonicalJson(value)
78
+ .replace(/</g, "\\u003c")
79
+ .replace(/\u2028/g, "\\u2028")
80
+ .replace(/\u2029/g, "\\u2029");
81
+ }
82
+
83
+ export interface RenderOptions {
84
+ title?: string;
85
+ runtime?: string;
86
+ font?: string;
87
+ template?: string;
88
+ /** Base64 GLB bytes keyed `<source>-<id>` (from `loadProps`). */
89
+ props?: Record<string, string>;
90
+ /** Local effect sources + cards keyed by `<name>` (from `loadLocalEffects`). */
91
+ localFx?: Record<string, { card: unknown; src: string }>;
92
+ }
93
+
94
+ /**
95
+ * Resolve every `local:` reference to `{ card, src }`, re-checking hash, card
96
+ * and lint. Throws on the first failure: `render` must not write HTML around a
97
+ * module whose bytes no longer match the pin.
98
+ */
99
+ export function loadLocalEffects(ir: DeckIR, jsonPath: string): Record<string, { card: unknown; src: string }> {
100
+ const deckDir = dirname(jsonPath);
101
+ const out: Record<string, { card: unknown; src: string }> = {};
102
+ for (const { ref, path } of localRefs(ir.overrides)) {
103
+ const { effect, issues } = resolveLocalEffect(ref, deckDir);
104
+ if (!effect) throw new Error(`${path}${issues[0]?.suffix ?? ""}: ${issues[0]?.message ?? "unresolved local effect"}`);
105
+ out[effect.name] = { card: effect.card, src: toFactorySource(effect.src) };
106
+ }
107
+ return out;
108
+ }
109
+
110
+ /**
111
+ * Replace every template token in ONE pass over the original template, so a
112
+ * substituted value that itself contains a later token is never rescanned
113
+ * (e.g. a slide documenting deck3d's own `__FONT__` placeholder).
114
+ */
115
+ function substituteTokens(template: string, values: Record<string, string>): string {
116
+ return template.replace(/__(?:DECK_LOCAL_FX|DECK_PROPS|DECK|FONT|RUNTIME|TITLE)__/g, (token) => values[token] ?? token);
117
+ }
118
+
119
+ /** Deck IR → self-contained `deck.html` string. */
120
+ export function renderDeck(ir: DeckIR, opts: RenderOptions = {}): string {
121
+ const merged = applyOverrides(ir);
122
+ merged.overriddenKeys = overriddenKeys(ir);
123
+ // The panel keys its stored state per deck; without this every deck would
124
+ // share one `deck3d:` entry.
125
+ if (ir.meta.derivedHash) merged.derivedHash = ir.meta.derivedHash;
126
+ // Only placeable props are embedded; a dangling `node:<id>` role is inert.
127
+ const props = activeProps(merged);
128
+ merged.props = props;
129
+ const credits = creditsSlide(props, merged.slides.length);
130
+ if (credits) merged.slides.push(credits);
131
+ const template = opts.template ?? readFileSync(TEMPLATE_PATH, "utf8");
132
+ const runtime = opts.runtime ?? runtimeSource();
133
+ const font = opts.font ?? subsetFontBase64(glyphText(merged));
134
+ const title = opts.title ?? merged.slides[0]?.title ?? "deck3d";
135
+ const deckJson = jsonForScript(merged);
136
+ const propsJson = jsonForScript(opts.props ?? {});
137
+ // `jsonForScript` escapes `<`, so a `</script>` inside a module source cannot
138
+ // terminate the block it is embedded in.
139
+ const localFxJson = jsonForScript(opts.localFx ?? {});
140
+
141
+ return substituteTokens(template, {
142
+ __DECK__: deckJson,
143
+ __DECK_PROPS__: propsJson,
144
+ __DECK_LOCAL_FX__: localFxJson,
145
+ __FONT__: font,
146
+ __RUNTIME__: runtime.replace(/<\/script/gi, "<\\/script"),
147
+ __TITLE__: title.replace(/</g, "&lt;"),
148
+ });
149
+ }
@@ -0,0 +1,87 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>__TITLE__</title>
7
+ <style>
8
+ @font-face {
9
+ font-family: "Poppins";
10
+ font-weight: 700;
11
+ font-style: normal;
12
+ src: url(data:font/ttf;base64,__FONT__) format("truetype");
13
+ }
14
+ html, body { margin: 0; height: 100%; overflow: hidden; background: #000; }
15
+ canvas { display: block; }
16
+
17
+ /* Configurator (design D4). Hidden by default: a deck that is never
18
+ configured must render exactly as it did before the panel existed. */
19
+ #deck3d-hud-toggle {
20
+ position: fixed; right: 12px; bottom: 12px; z-index: 10;
21
+ width: 34px; height: 34px; border-radius: 17px;
22
+ border: 1px solid rgba(255,255,255,.25); background: rgba(20,20,22,.55);
23
+ color: #fff; font: 16px/1 system-ui, sans-serif; cursor: pointer;
24
+ opacity: .35; transition: opacity .15s;
25
+ }
26
+ #deck3d-hud-toggle:hover, #deck3d-hud-toggle:focus { opacity: 1; }
27
+ /* `ascii` post mode: the canvas is hidden and this grid is drawn from its pixels each frame. */
28
+ .deck3d-ascii {
29
+ position: fixed; inset: 0; margin: 0; z-index: 5; overflow: hidden; pointer-events: none;
30
+ font-family: ui-monospace, Menlo, Consolas, monospace; white-space: pre; letter-spacing: 0;
31
+ }
32
+ #deck3d-hud {
33
+ display: none; position: fixed; right: 12px; bottom: 56px; z-index: 11;
34
+ width: 286px; max-height: 78vh; overflow: auto;
35
+ padding: 12px 14px; border-radius: 10px;
36
+ border: 1px solid rgba(255,255,255,.18); background: rgba(16,16,18,.92);
37
+ color: #f2f2f2; font: 12px/1.5 system-ui, sans-serif;
38
+ }
39
+ .deck3d-hud-payload { margin-top: 8px; display: grid; gap: 6px; }
40
+ .deck3d-hud-payload textarea { width: 100%; box-sizing: border-box; font: 11px/1.4 ui-monospace, monospace;
41
+ color: #e5e7eb; background: #0b0f19; border: 1px solid #2a3344; border-radius: 4px; padding: 6px; resize: vertical; }
42
+ #deck3d-hud-counter { font-weight: 700; margin-bottom: 8px; }
43
+ .deck3d-hud-scopes { display: flex; gap: 6px; margin-bottom: 10px; }
44
+ .deck3d-hud-scopes button {
45
+ flex: 1; padding: 4px 6px; border-radius: 6px; cursor: pointer;
46
+ border: 1px solid rgba(255,255,255,.2); background: transparent; color: inherit; font: inherit;
47
+ }
48
+ .deck3d-hud-scopes button.active { background: rgba(255,255,255,.16); }
49
+ .deck3d-hud-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 5px 0; }
50
+ .deck3d-hud-row select, .deck3d-hud-row input { width: 108px; font: inherit; }
51
+ .deck3d-hud-row input[type=checkbox] { width: auto; }
52
+ .deck3d-hud-row input[type=color] { width: 108px; height: 22px; padding: 0; background: none; border: 1px solid rgba(255,255,255,.2); }
53
+ .deck3d-hud-block { border-top: 1px solid rgba(255,255,255,.12); padding: 6px 0; }
54
+ .deck3d-hud-block > summary {
55
+ cursor: pointer; font-weight: 600; letter-spacing: .02em; padding: 2px 0;
56
+ list-style: none; display: flex; align-items: center; gap: 6px;
57
+ }
58
+ .deck3d-hud-block > summary::-webkit-details-marker { display: none; }
59
+ .deck3d-hud-block > summary::before { content: "\25B8"; opacity: .6; transition: transform .12s; }
60
+ .deck3d-hud-block[open] > summary::before { transform: rotate(90deg); }
61
+ .deck3d-hud-effects { margin: 6px 0; }
62
+ .deck3d-hud-effect { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
63
+ /* One effect = one slot: kind picker, stepper over that kind, remove. */
64
+ .deck3d-hud-slot { margin: 5px 0; padding: 4px 0; border-top: 1px solid rgba(255,255,255,.08); }
65
+ .deck3d-hud-slot-head { display: grid; grid-template-columns: 76px 20px 1fr 20px 20px; align-items: center; gap: 4px; }
66
+ .deck3d-hud-slot-head button { padding: 1px 0; line-height: 1; }
67
+ .deck3d-hud-slot[data-inherited] { opacity: .55; }
68
+ .deck3d-hud-effects button[data-add-slot] { width: 100%; margin-top: 5px; }
69
+ .deck3d-hud-effects select[data-add-effect] { width: 100%; margin-top: 5px; }
70
+ /* Per-effect knobs, indented under the effect they belong to. */
71
+ .deck3d-hud-fxparams { margin: 0 0 7px 18px; padding-left: 7px; border-left: 1px solid rgba(255,255,255,.14); }
72
+ .deck3d-hud-fxparam { display: grid; grid-template-columns: 62px 1fr 30px; align-items: center; gap: 5px; margin: 2px 0; font-size: 11px; opacity: .85; }
73
+ .deck3d-hud-fxparam span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
74
+ .deck3d-hud-fxparam input[type=range] { width: 100%; }
75
+ .deck3d-hud-fxparam em { font-style: normal; text-align: right; opacity: .65; font-variant-numeric: tabular-nums; }
76
+ .deck3d-hud-note { margin: 8px 0; opacity: .7; font-size: 11px; }
77
+ #deck3d-hud-export { width: 100%; padding: 6px; border-radius: 6px; cursor: pointer;
78
+ border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1); color: inherit; font: inherit; }
79
+ </style>
80
+ </head>
81
+ <body>
82
+ <button id="deck3d-hud-toggle" type="button" aria-label="Configurator">⚙</button>
83
+ <aside id="deck3d-hud" aria-label="Deck configurator"></aside>
84
+ <script>window.__DECK=__DECK__;window.__DECK_FONT="__FONT__";window.__DECK_PROPS=__DECK_PROPS__;window.__DECK_LOCAL_FX=__DECK_LOCAL_FX__;</script>
85
+ <script>__RUNTIME__</script>
86
+ </body>
87
+ </html>