@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,46 @@
1
+ {
2
+ "id": "volume-perlin",
3
+ "kind": "background",
4
+ "tags": {
5
+ "mood": [
6
+ "sculptural",
7
+ "atmospheric"
8
+ ],
9
+ "content": [
10
+ "rock",
11
+ "asteroid",
12
+ "noise"
13
+ ]
14
+ },
15
+ "cost": 4,
16
+ "modes": "both",
17
+ "params": {
18
+ "threshold": {
19
+ "type": "number",
20
+ "default": 0.45,
21
+ "minimum": 0.2,
22
+ "maximum": 0.9
23
+ },
24
+ "scale": {
25
+ "type": "number",
26
+ "default": 9,
27
+ "minimum": 3,
28
+ "maximum": 20
29
+ },
30
+ "x": {
31
+ "type": "number",
32
+ "default": 5,
33
+ "minimum": -12,
34
+ "maximum": 12
35
+ },
36
+ "spin": {
37
+ "type": "number",
38
+ "default": 1,
39
+ "minimum": 0,
40
+ "maximum": 3
41
+ }
42
+ },
43
+ "conflicts": [],
44
+ "source": "https://threejs.org/examples/#webgl_volume_perlin",
45
+ "licence": "MIT"
46
+ }
@@ -0,0 +1,82 @@
1
+ import type { FxContext, FxFactory, FxHandle, FxParams } from "./types.js";
2
+ import { noiseVolume, num } from "./util.js";
3
+
4
+ const VERT = [
5
+ "in vec3 position; uniform mat4 modelMatrix, modelViewMatrix, projectionMatrix; uniform vec3 cameraPos;",
6
+ "out vec3 vOrigin; out vec3 vDirection;",
7
+ "void main(){ vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);",
8
+ " vOrigin = vec3(inverse(modelMatrix) * vec4(cameraPos, 1.0)).xyz; vDirection = position - vOrigin;",
9
+ " gl_Position = projectionMatrix * mvPosition; }",
10
+ ].join("\n");
11
+
12
+ const FRAG = [
13
+ "precision highp float; precision highp sampler3D;",
14
+ "uniform mat4 modelViewMatrix, projectionMatrix; in vec3 vOrigin; in vec3 vDirection; out vec4 color;",
15
+ "uniform sampler3D map; uniform vec3 tint; uniform float threshold, steps;",
16
+ "vec2 hitBox(vec3 orig, vec3 dir){ const vec3 box_min = vec3(-0.5); const vec3 box_max = vec3(0.5);",
17
+ " vec3 inv_dir = 1.0 / dir; vec3 tmin_tmp = (box_min - orig) * inv_dir; vec3 tmax_tmp = (box_max - orig) * inv_dir;",
18
+ " vec3 tmin = min(tmin_tmp, tmax_tmp); vec3 tmax = max(tmin_tmp, tmax_tmp);",
19
+ " return vec2(max(tmin.x, max(tmin.y, tmin.z)), min(tmax.x, min(tmax.y, tmax.z))); }",
20
+ "float sample1(vec3 p){ return texture(map, p).r; }",
21
+ "#define epsilon .0001",
22
+ "vec3 normal(vec3 coord){ if (coord.x < epsilon) return vec3(1.0, 0.0, 0.0); if (coord.y < epsilon) return vec3(0.0, 1.0, 0.0); if (coord.z < epsilon) return vec3(0.0, 0.0, 1.0);",
23
+ " if (coord.x > 1.0 - epsilon) return vec3(-1.0, 0.0, 0.0); if (coord.y > 1.0 - epsilon) return vec3(0.0, -1.0, 0.0); if (coord.z > 1.0 - epsilon) return vec3(0.0, 0.0, -1.0);",
24
+ " float step = 0.01; float x = sample1(coord + vec3(-step, 0.0, 0.0)) - sample1(coord + vec3(step, 0.0, 0.0));",
25
+ " float y = sample1(coord + vec3(0.0, -step, 0.0)) - sample1(coord + vec3(0.0, step, 0.0));",
26
+ " float z = sample1(coord + vec3(0.0, 0.0, -step)) - sample1(coord + vec3(0.0, 0.0, step)); return normalize(vec3(x, y, z)); }",
27
+ "void main(){ vec3 rayDir = normalize(vDirection); vec2 bounds = hitBox(vOrigin, rayDir); if (bounds.x > bounds.y) discard;",
28
+ " bounds.x = max(bounds.x, 0.0); vec3 p = vOrigin + bounds.x * rayDir; vec3 inc = 1.0 / abs(rayDir);",
29
+ " float delta = min(inc.x, min(inc.y, inc.z)) / steps;",
30
+ " for (float t = bounds.x; t < bounds.y; t += delta) { float d = sample1(p + 0.5);",
31
+ " if (d > threshold) { vec3 n = normal(p + 0.5); float l = 0.35 + 0.65 * max(0.0, dot(n, normalize(vec3(0.6, 0.8, 0.5))));",
32
+ " color = vec4(tint * l, 1.0); break; } p += rayDir * delta; }",
33
+ " if (color.a == 0.0) discard; }",
34
+ ].join("\n");
35
+
36
+ /**
37
+ * Raymarched isosurface of a seeded noise volume (three `webgl_volume_perlin`):
38
+ * a slowly turning rock of light. Steps scale with the tier.
39
+ */
40
+ export const create: FxFactory = (ctx: FxContext, params: FxParams): FxHandle => {
41
+ const { THREE, palette, rng, quality } = ctx;
42
+ const size = quality.particles >= 1500 ? 64 : quality.particles >= 900 ? 48 : 32;
43
+ const steps = quality.particles >= 1500 ? 160 : quality.particles >= 900 ? 100 : 60;
44
+ const tex = noiseVolume(THREE, rng, size, 0.05, 2);
45
+ const geo = new THREE.BoxGeometry(1, 1, 1);
46
+ const mat = new THREE.RawShaderMaterial({
47
+ glslVersion: THREE.GLSL3,
48
+ uniforms: {
49
+ map: { value: tex },
50
+ cameraPos: { value: new THREE.Vector3() },
51
+ tint: { value: new THREE.Color(palette.accent) },
52
+ threshold: { value: num(params, "threshold", 0.45) },
53
+ steps: { value: steps },
54
+ },
55
+ vertexShader: VERT,
56
+ fragmentShader: FRAG,
57
+ side: THREE.BackSide,
58
+ });
59
+ const mesh = new THREE.Mesh(geo, mat);
60
+ mesh.scale.setScalar(num(params, "scale", 9));
61
+ mesh.position.set(num(params, "x", 5), 0, -7);
62
+ const spin = num(params, "spin", 1);
63
+ const holder = new THREE.Group();
64
+ holder.add(mesh);
65
+ holder.userData.count = steps;
66
+ const cam = new THREE.Vector3();
67
+ mesh.onBeforeRender = (_r, _s, camera) => {
68
+ mat.uniforms.cameraPos.value.copy(camera.getWorldPosition(cam));
69
+ };
70
+ return {
71
+ object: holder,
72
+ tick: (t) => {
73
+ mesh.rotation.y = t * 0.08 * spin;
74
+ mesh.rotation.x = Math.sin(t * 0.06 * spin) * 0.3;
75
+ },
76
+ dispose: () => {
77
+ tex.dispose();
78
+ geo.dispose();
79
+ mat.dispose();
80
+ },
81
+ };
82
+ };
@@ -0,0 +1,26 @@
1
+ {
2
+ "id": "volumetric-spot",
3
+ "kind": "light",
4
+ "tags": {
5
+ "mood": [
6
+ "dramatic",
7
+ "cinematic"
8
+ ],
9
+ "content": [
10
+ "staging"
11
+ ]
12
+ },
13
+ "cost": 3,
14
+ "modes": "dark",
15
+ "params": {
16
+ "intensity": {
17
+ "type": "number",
18
+ "default": 1,
19
+ "minimum": 0,
20
+ "maximum": 2
21
+ }
22
+ },
23
+ "conflicts": [],
24
+ "source": "https://threejs.org/examples/",
25
+ "licence": "MIT"
26
+ }
@@ -0,0 +1,8 @@
1
+ import type { FxContext, FxFactory, FxHandle, FxParams } from "./types.js";
2
+
3
+ /** Permissive port of a three.js example. */
4
+ export const create: FxFactory = (ctx: FxContext, params: FxParams): FxHandle => {
5
+ const light = new ctx.THREE.PointLight(ctx.palette.accent, 1, 30);
6
+ void params;
7
+ return { object: light, dispose: () => light.dispose?.() };
8
+ };
@@ -0,0 +1,27 @@
1
+ {
2
+ "id": "wireframe-overlay",
3
+ "kind": "material",
4
+ "tags": {
5
+ "mood": [
6
+ "technical",
7
+ "retro"
8
+ ],
9
+ "content": [
10
+ "surface",
11
+ "infrastructure"
12
+ ]
13
+ },
14
+ "cost": 2,
15
+ "modes": "both",
16
+ "params": {
17
+ "intensity": {
18
+ "type": "number",
19
+ "default": 1,
20
+ "minimum": 0,
21
+ "maximum": 2
22
+ }
23
+ },
24
+ "conflicts": [],
25
+ "source": "https://threejs.org/examples/",
26
+ "licence": "MIT"
27
+ }
@@ -0,0 +1,8 @@
1
+ import type { FxContext, FxFactory, FxHandle, FxParams } from "./types.js";
2
+
3
+ /** Permissive port of a three.js example. */
4
+ export const create: FxFactory = (ctx: FxContext, params: FxParams): FxHandle => {
5
+ const mat = new ctx.THREE.MeshStandardMaterial({ color: ctx.palette.accent, metalness: 0.8, roughness: 0.3 });
6
+ void params;
7
+ return { material: mat, dispose: () => mat.dispose() };
8
+ };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Canonical deck-level defaults. Mirrors the `default` keywords in
3
+ * `schema.json`; `parse` merges front-matter over this so a bare deck is fully
4
+ * specified and `derivedHash` is stable.
5
+ */
6
+ import type { Defaults } from "./types.js";
7
+
8
+ export const DECK_DEFAULTS: Required<
9
+ Pick<
10
+ Defaults,
11
+ | "mode"
12
+ | "palette"
13
+ | "material"
14
+ | "envReflections"
15
+ | "mirrorFloor"
16
+ | "softShadows"
17
+ | "bloom"
18
+ | "rimLight"
19
+ | "fog"
20
+ | "backgroundIntensity"
21
+ | "transition"
22
+ | "durationSec"
23
+ | "depthRelief"
24
+ | "quality"
25
+ | "extrudeDepth"
26
+ | "titleEdge"
27
+ | "camera"
28
+ | "labels"
29
+ | "check"
30
+ >
31
+ > = {
32
+ mode: "dark",
33
+ palette: "blackbelt",
34
+ material: "glass",
35
+ envReflections: true,
36
+ mirrorFloor: true,
37
+ softShadows: true,
38
+ bloom: true,
39
+ rimLight: true,
40
+ fog: true,
41
+ backgroundIntensity: 0.7,
42
+ transition: "dolly",
43
+ durationSec: 1.4,
44
+ depthRelief: 0.7,
45
+ quality: "high",
46
+ extrudeDepth: 0.18,
47
+ titleEdge: "none",
48
+ camera: { distance: 9 },
49
+ labels: { size: 0.28 },
50
+ check: { ignore: [] },
51
+ };
52
+
53
+ /** Merge front-matter (or override) defaults over the canonical defaults. */
54
+ export function resolveDefaults(partial: Defaults | undefined): Defaults {
55
+ return {
56
+ ...DECK_DEFAULTS,
57
+ ...partial,
58
+ camera: { ...DECK_DEFAULTS.camera, ...partial?.camera },
59
+ labels: { ...DECK_DEFAULTS.labels, ...partial?.labels },
60
+ check: { ...DECK_DEFAULTS.check, ...partial?.check },
61
+ };
62
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Generate the LLM's IR knob reference (`reference/ir-fields.md`) from the
3
+ * schema's own `description`/`type`/`default` keywords — one source of truth,
4
+ * so the field reference can never drift from what `validate` enforces.
5
+ */
6
+ import { readFileSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ import { pkgRoot } from "../util/paths.js";
9
+
10
+ export interface SchemaNode {
11
+ $ref?: string;
12
+ type?: string;
13
+ description?: string;
14
+ default?: unknown;
15
+ enum?: unknown[];
16
+ properties?: Record<string, SchemaNode>;
17
+ items?: SchemaNode;
18
+ additionalProperties?: SchemaNode | boolean;
19
+ }
20
+
21
+ export interface FieldRow {
22
+ path: string;
23
+ type: string;
24
+ default: string;
25
+ description: string;
26
+ }
27
+
28
+ export function loadSchema(): { properties: Record<string, SchemaNode>; definitions: Record<string, SchemaNode> } {
29
+ const path = join(pkgRoot(), "src", "ir", "schema.json");
30
+ return JSON.parse(readFileSync(path, "utf8")) as {
31
+ properties: Record<string, SchemaNode>;
32
+ definitions: Record<string, SchemaNode>;
33
+ };
34
+ }
35
+
36
+ function resolve(node: SchemaNode, defs: Record<string, SchemaNode>): SchemaNode {
37
+ if (node.$ref) {
38
+ const name = node.$ref.replace("#/definitions/", "");
39
+ return { ...defs[name], ...node, $ref: undefined };
40
+ }
41
+ return node;
42
+ }
43
+
44
+ function typeLabel(node: SchemaNode): string {
45
+ if (node.enum) return node.enum.map((v) => String(v)).join(" | ");
46
+ if (node.type === "array") return "array";
47
+ return node.type ?? "any";
48
+ }
49
+
50
+ function defaultLabel(node: SchemaNode): string {
51
+ if (node.default === undefined) return "";
52
+ return `\`${JSON.stringify(node.default)}\``;
53
+ }
54
+
55
+ function escapeCell(s: string): string {
56
+ return s.replace(/\\/g, "\\\\").replace(/\|/g, "\\|").replace(/\n+/g, " ").trim();
57
+ }
58
+
59
+ /** Every named property + dynamic-key segment in the schema, pre-order. */
60
+ export function collectFieldPaths(schema = loadSchema()): FieldRow[] {
61
+ const defs = schema.definitions;
62
+ const rows: FieldRow[] = [];
63
+ const visitObject = (n: SchemaNode, path: string): void => {
64
+ for (const [key, child] of Object.entries(n.properties ?? {})) visit(child, path ? `${path}.${key}` : key);
65
+ if (n.additionalProperties && typeof n.additionalProperties === "object") {
66
+ visit(n.additionalProperties, `${path}["<key>"]`);
67
+ }
68
+ };
69
+ const visit = (node: SchemaNode, path: string): void => {
70
+ const n = resolve(node, defs);
71
+ rows.push({ path, type: typeLabel(n), default: defaultLabel(n), description: n.description ?? "" });
72
+ if (n.type === "object") visitObject(n, path);
73
+ else if (n.type === "array" && n.items) visit(n.items, `${path}[]`);
74
+ };
75
+ for (const [key, child] of Object.entries(schema.properties)) visit(child, key);
76
+ return rows;
77
+ }
78
+
79
+ export function renderIrFieldsMd(schema = loadSchema()): string {
80
+ const rows = collectFieldPaths(schema);
81
+ const lines = [
82
+ "# Deck IR field reference",
83
+ "",
84
+ "> Generated from `src/ir/schema.json` by `scripts/gen-ir-fields.ts` (`npm run build`). Do not edit by hand.",
85
+ "",
86
+ "`defaults` and `slides[]` are **derived** — regenerated by `parse`; edit them and the change is lost on re-parse. `overrides` is the only region you may write.",
87
+ "",
88
+ "| Path | Type | Default | Effect |",
89
+ "|------|------|---------|--------|",
90
+ ];
91
+ for (const row of rows) {
92
+ lines.push(`| \`${row.path}\` | ${escapeCell(row.type)} | ${row.default} | ${escapeCell(row.description)} |`);
93
+ }
94
+ lines.push("");
95
+ return lines.join("\n");
96
+ }
package/src/ir/hash.ts ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Canonical JSON + sha256 helpers.
3
+ *
4
+ * `derivedHash` is computed over the derived fields only (`defaults` + `slides`),
5
+ * excluding `overrides` (user-written) and `meta` (provenance). This is what
6
+ * lets `validate` detect an edit made outside `overrides` without the markdown.
7
+ */
8
+ import { createHash } from "node:crypto";
9
+
10
+ /** Recursively sort object keys so serialisation is order-independent. */
11
+ function sortKeys(value: unknown): unknown {
12
+ if (Array.isArray(value)) return value.map(sortKeys);
13
+ if (value !== null && typeof value === "object") {
14
+ const src = value as Record<string, unknown>;
15
+ const out: Record<string, unknown> = {};
16
+ for (const key of Object.keys(src).sort()) out[key] = sortKeys(src[key]);
17
+ return out;
18
+ }
19
+ return value;
20
+ }
21
+
22
+ /** Deterministic JSON: object keys sorted, no incidental whitespace. */
23
+ export function canonicalJson(value: unknown): string {
24
+ return JSON.stringify(sortKeys(value));
25
+ }
26
+
27
+ export function sha256Hex(input: string | Uint8Array): string {
28
+ return createHash("sha256").update(input).digest("hex");
29
+ }
30
+
31
+ /** Hash of the derived region of an IR. */
32
+ export function computeDerivedHash(ir: { defaults: unknown; slides: unknown }): string {
33
+ return sha256Hex(canonicalJson({ defaults: ir.defaults, slides: ir.slides }));
34
+ }
package/src/ir/ids.ts ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Stable id derivation. Ids must come from author-written source (slide titles,
3
+ * mermaid node names, message order) — never from render-time counters — so a
4
+ * re-parse is byte-identical and overrides survive.
5
+ */
6
+
7
+ export const SLIDE_ID_PATTERN = /^(?!deck3d-)[a-z0-9-]+$/;
8
+
9
+ /** Latin-1/Latin-Extended fold: strip combining marks (`ő` → `o`, `ű` → `u`). */
10
+ export function foldAscii(input: string): string {
11
+ return input.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
12
+ }
13
+
14
+ /**
15
+ * Slugify a title into an id: ASCII-folded, lowercased, non-alphanumerics
16
+ * collapsed to `-`. An empty result becomes `slide` (design D1).
17
+ */
18
+ export function slugify(input: string): string {
19
+ const base = foldAscii(input)
20
+ .toLowerCase()
21
+ .replace(/[^a-z0-9]+/g, "-")
22
+ .replace(/^-+|-+$/g, "");
23
+ const id = base || "slide";
24
+ // `deck3d-` is reserved for generated slides (e.g. the credits slide).
25
+ return id.startsWith("deck3d-") ? `s-${id}` : id;
26
+ }
27
+
28
+ /** Split `# Title {#pin}` into its display title and optional pinned id. */
29
+ export function parseHeading(raw: string): { title: string; pin?: string } {
30
+ const m = /^(.*?)\s*\{#([a-z0-9-]+)\}\s*$/.exec(raw.trim());
31
+ if (m) return { title: m[1].trim(), pin: slugify(m[2]) };
32
+ return { title: raw.trim() };
33
+ }
34
+
35
+ /** Assign slide ids in order, adding `-<ordinal>` on collision (design D1). */
36
+ export function assignSlideIds(entries: Array<{ title: string; pin?: string }>): string[] {
37
+ const used = new Set<string>();
38
+ const counts = new Map<string, number>();
39
+ return entries.map((e) => {
40
+ let id = e.pin ?? slugify(e.title);
41
+ if (used.has(id)) {
42
+ const base = id;
43
+ let n = counts.get(base) ?? 1;
44
+ let candidate: string;
45
+ do {
46
+ n += 1;
47
+ candidate = `${base}-${n}`;
48
+ } while (used.has(candidate));
49
+ counts.set(base, n);
50
+ id = candidate;
51
+ }
52
+ used.add(id);
53
+ return id;
54
+ });
55
+ }
56
+
57
+ /** `<from>-><to>#<k>` with `k` the ordinal among parallel edges in source order. */
58
+ export function edgeId(from: string, to: string, ordinal: number): string {
59
+ return `${from}->${to}#${ordinal}`;
60
+ }
61
+
62
+ /** `m<index>` message id. */
63
+ export function messageId(index: number): string {
64
+ return `m${index}`;
65
+ }
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Override merge — the single grammar in `overrides` (design D1).
3
+ *
4
+ * objects deep-merge over derived values
5
+ * arrays replace wholesale
6
+ * `diagram.data` replaces wholesale (named exception — labels and values
7
+ * must not mix provenance)
8
+ *
9
+ * Persisted `slides[]` is never mutated: `applyOverrides` returns a fresh
10
+ * merged view for the renderer, so re-parse always regenerates derived fields.
11
+ */
12
+ import type {
13
+ DeckIR,
14
+ Defaults,
15
+ DiagramEdge,
16
+ MergedDeck,
17
+ MergedNode,
18
+ MergedSlide,
19
+ NodeOverride,
20
+ } from "./types.js";
21
+
22
+ type Json = Record<string, unknown>;
23
+
24
+ function isPlainObject(v: unknown): v is Json {
25
+ return v !== null && typeof v === "object" && !Array.isArray(v);
26
+ }
27
+
28
+ /** `diagram.data` is the one object key that replaces instead of deep-merging. */
29
+ function isAtomic(parentKey: string | undefined, key: string): boolean {
30
+ return key === "data" && parentKey === "diagram";
31
+ }
32
+
33
+ /** Deep merge: objects merge recursively, arrays, scalars and `diagram.data` replace. */
34
+ export function deepMerge(base: unknown, override: unknown, parentKey?: string): unknown {
35
+ if (!isPlainObject(base) || !isPlainObject(override)) return clone(override);
36
+ const out: Json = { ...base };
37
+ for (const [key, value] of Object.entries(override)) {
38
+ if (value === undefined) continue;
39
+ const mergeable = isPlainObject(value) && isPlainObject(base[key]) && !isAtomic(parentKey, key);
40
+ out[key] = mergeable ? deepMerge(base[key], value, key) : clone(value);
41
+ }
42
+ return out;
43
+ }
44
+
45
+ export function clone<T>(value: T): T {
46
+ if (Array.isArray(value)) return value.map((v) => clone(v)) as unknown as T;
47
+ if (isPlainObject(value)) {
48
+ const out: Json = {};
49
+ for (const [k, v] of Object.entries(value)) out[k] = clone(v);
50
+ return out as unknown as T;
51
+ }
52
+ return value;
53
+ }
54
+
55
+ /** Fold `<slideId>/<id>` overrides for one slide into its merged nodes. */
56
+ function mergeNodeOverrides(nodes: MergedNode[] | undefined, slideId: string, map: Record<string, NodeOverride> | undefined): MergedNode[] | undefined {
57
+ if (!nodes) return nodes;
58
+ if (!map) return clone(nodes);
59
+ const prefix = `${slideId}/`;
60
+ return nodes.map((node) => {
61
+ const ov = map[prefix + node.id];
62
+ if (!ov) return clone(node);
63
+ const merged: MergedNode = clone(node);
64
+ if (ov.shape !== undefined) merged.shape = ov.shape;
65
+ if (ov.label !== undefined) merged.label = ov.label;
66
+ if (ov.position !== undefined) merged.position = clone(ov.position);
67
+ if (ov.size !== undefined) merged.size = clone(ov.size);
68
+ if (ov.material !== undefined) merged.material = ov.material;
69
+ return merged;
70
+ });
71
+ }
72
+
73
+ export function applyOverrides(ir: DeckIR): MergedDeck {
74
+ const defaults = (ir.overrides.deck ? deepMerge(ir.defaults, ir.overrides.deck) : clone(ir.defaults)) as Defaults;
75
+ const slides: MergedSlide[] = ir.slides.map((slide) => {
76
+ const slideOv = ir.overrides.slides?.[slide.id];
77
+ const base = slideOv ? (deepMerge(slide, slideOv) as MergedSlide) : (clone(slide) as MergedSlide);
78
+ base.diagram = base.diagram ?? { kind: "none" };
79
+ if (base.diagram.kind === "flowchart") {
80
+ base.diagram.nodes = mergeNodeOverrides(base.diagram.nodes as MergedNode[] | undefined, slide.id, ir.overrides.nodes);
81
+ base.diagram.edges = mergeEdgeKinds(base.diagram.edges, slide.id, ir.overrides.edges);
82
+ }
83
+ // Effective effects: deck-level list first, then this slide's own list
84
+ // (a slide `effects` override replaces the derived list). Arrays replace —
85
+ // the objects are never merged.
86
+ base.effects = [...clone(ir.overrides.effects ?? []), ...clone(base.effects ?? [])];
87
+ return base;
88
+ });
89
+ return { defaults, slides, effects: clone(ir.overrides.effects ?? []), props: clone(ir.overrides.props ?? []) };
90
+ }
91
+
92
+ function mergeEdgeKinds(edges: DiagramEdge[] | undefined, slideId: string, map: Record<string, { kind?: DiagramEdge["kind"] }> | undefined): DiagramEdge[] | undefined {
93
+ if (!edges) return edges;
94
+ if (!map) return clone(edges);
95
+ const prefix = `${slideId}/`;
96
+ return edges.map((edge) => {
97
+ const ov = map[prefix + edge.id];
98
+ if (!ov?.kind) return clone(edge);
99
+ const merged = clone(edge);
100
+ merged.kind = ov.kind;
101
+ return merged;
102
+ });
103
+ }
104
+
105
+ export interface OrphanOverride {
106
+ kind: "slide" | "node" | "edge";
107
+ /** Raw override key (slide id, or `<slideId>/<id>`). */
108
+ key: string;
109
+ id: string;
110
+ }
111
+
112
+ /** Override entries whose target no longer exists. Kept, inert, warned about. */
113
+ export function findOrphanOverrides(ir: DeckIR): OrphanOverride[] {
114
+ const orphans: OrphanOverride[] = [];
115
+ const slideIds = new Set(ir.slides.map((s) => s.id));
116
+ for (const id of Object.keys(ir.overrides.slides ?? {})) {
117
+ if (!slideIds.has(id)) orphans.push({ kind: "slide", key: id, id });
118
+ }
119
+ collectOrphans(ir.overrides.nodes, indexElementIds(ir, "nodes"), "node", orphans);
120
+ collectOrphans(ir.overrides.edges, indexElementIds(ir, "edges"), "edge", orphans);
121
+ return orphans;
122
+ }
123
+
124
+ function indexElementIds(ir: DeckIR, which: "nodes" | "edges"): Map<string, Set<string>> {
125
+ const index = new Map<string, Set<string>>();
126
+ for (const slide of ir.slides) {
127
+ const elements = which === "nodes" ? slide.diagram.nodes : slide.diagram.edges;
128
+ index.set(slide.id, new Set((elements ?? []).map((e) => e.id)));
129
+ }
130
+ return index;
131
+ }
132
+
133
+ function collectOrphans(
134
+ map: Record<string, unknown> | undefined,
135
+ index: Map<string, Set<string>>,
136
+ kind: "node" | "edge",
137
+ out: OrphanOverride[],
138
+ ): void {
139
+ for (const key of Object.keys(map ?? {})) {
140
+ const [slideId, id] = splitKey(key);
141
+ if (!slideId || !id || !index.get(slideId)?.has(id)) out.push({ kind, key, id: id ?? key });
142
+ }
143
+ }
144
+
145
+ function splitKey(key: string): [string | undefined, string | undefined] {
146
+ const idx = key.indexOf("/");
147
+ if (idx <= 0 || idx === key.length - 1) return [undefined, undefined];
148
+ return [key.slice(0, idx), key.slice(idx + 1)];
149
+ }
150
+
151
+ /** `overrides.nodes["arch/Z"]` spelling used by warnings. */
152
+ export function orphanOverridePath(orphan: OrphanOverride): string {
153
+ const plural = orphan.kind === "slide" ? "slides" : orphan.kind === "node" ? "nodes" : "edges";
154
+ return `overrides.${plural}["${orphan.key}"]`;
155
+ }