@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.
- package/.pi/skills/deck3d/SKILL.md +227 -0
- package/.pi/skills/deck3d/examples/deck.json +388 -0
- package/.pi/skills/deck3d/examples/fixture.md +18 -0
- package/.pi/skills/deck3d/examples/snapshot-after.png +0 -0
- package/.pi/skills/deck3d/examples/snapshot-before.png +0 -0
- package/.pi/skills/deck3d/reference/effects.agent.md +78 -0
- package/.pi/skills/deck3d/reference/effects.md +1217 -0
- package/.pi/skills/deck3d/reference/ir-fields.agent.md +30 -0
- package/.pi/skills/deck3d/reference/ir-fields.md +246 -0
- package/README.md +177 -2
- package/assets/LICENSE-Poppins.txt +99 -0
- package/assets/Poppins-Bold.ttf +0 -0
- package/assets/props/LICENSES.txt +4 -0
- package/assets/props/brain.glb +0 -0
- package/assets/props/cloud.glb +0 -0
- package/assets/props/cube.glb +0 -0
- package/assets/props/database.glb +0 -0
- package/assets/props/laptop.glb +0 -0
- package/assets/props/manifest.json +119 -0
- package/assets/props/robot.glb +0 -0
- package/assets/props/server.glb +0 -0
- package/assets/props/shield.glb +0 -0
- package/bin/deck3d +49 -0
- package/dist/cli.js +10228 -0
- package/dist/harvest/harness.js +185718 -0
- package/dist/runtime.js +64597 -0
- package/fixtures/business-2031/build-deck.mjs +60 -0
- package/fixtures/business-2031/build-overrides.mjs +154 -0
- package/fixtures/business-2031/deck.json +4220 -0
- package/fixtures/business-2031/deck.md +470 -0
- package/fixtures/business-2031/fx/closing-mark.js +43 -0
- package/fixtures/business-2031/fx/closing-mark.meta.json +26 -0
- package/fixtures/business-2031/overrides.json +903 -0
- package/fixtures/harvest.md +23 -0
- package/fixtures/strategy-lab.json +891 -0
- package/fixtures/strategy-lab.md +85 -0
- package/package.json +80 -4
- package/scripts/build-cli.mjs +29 -0
- package/scripts/build-harvest.ts +8 -0
- package/scripts/build-runtime.mjs +22 -0
- package/scripts/gen-effects.ts +14 -0
- package/scripts/gen-ir-fields.ts +34 -0
- package/src/check/index.ts +315 -0
- package/src/check/rules.ts +393 -0
- package/src/cli-io.ts +23 -0
- package/src/cli.ts +823 -0
- package/src/fx/accent-cycle.meta.json +26 -0
- package/src/fx/accent-cycle.ts +8 -0
- package/src/fx/agent-depth.meta.json +42 -0
- package/src/fx/agent-depth.ts +62 -0
- package/src/fx/ascii.meta.json +35 -0
- package/src/fx/ascii.ts +4 -0
- package/src/fx/aurora.meta.json +26 -0
- package/src/fx/aurora.ts +18 -0
- package/src/fx/billboards.meta.json +34 -0
- package/src/fx/billboards.ts +67 -0
- package/src/fx/bloom.meta.json +26 -0
- package/src/fx/bloom.ts +4 -0
- package/src/fx/camera-drift.meta.json +26 -0
- package/src/fx/camera-drift.ts +8 -0
- package/src/fx/capital-flows.meta.json +30 -0
- package/src/fx/capital-flows.ts +64 -0
- package/src/fx/catalogue.ts +89 -0
- package/src/fx/chromatic-aberration.meta.json +32 -0
- package/src/fx/chromatic-aberration.ts +4 -0
- package/src/fx/city-grid.meta.json +37 -0
- package/src/fx/city-grid.ts +51 -0
- package/src/fx/clipped-solids.meta.json +49 -0
- package/src/fx/clipped-solids.ts +171 -0
- package/src/fx/cohort-grid.meta.json +48 -0
- package/src/fx/cohort-grid.ts +63 -0
- package/src/fx/compose.ts +114 -0
- package/src/fx/constellation.meta.json +51 -0
- package/src/fx/constellation.ts +103 -0
- package/src/fx/curve-flow.meta.json +40 -0
- package/src/fx/curve-flow.ts +63 -0
- package/src/fx/dashed-flow.meta.json +27 -0
- package/src/fx/dashed-flow.ts +8 -0
- package/src/fx/data-columns.meta.json +30 -0
- package/src/fx/data-columns.ts +18 -0
- package/src/fx/defaults.ts +92 -0
- package/src/fx/depth-of-field.meta.json +40 -0
- package/src/fx/depth-of-field.ts +4 -0
- package/src/fx/dolly.meta.json +26 -0
- package/src/fx/dolly.ts +4 -0
- package/src/fx/dot-screen.meta.json +35 -0
- package/src/fx/dot-screen.ts +4 -0
- package/src/fx/dynamic-instances.meta.json +40 -0
- package/src/fx/dynamic-instances.ts +57 -0
- package/src/fx/emissive.meta.json +26 -0
- package/src/fx/emissive.ts +8 -0
- package/src/fx/extruded-shapes.meta.json +62 -0
- package/src/fx/extruded-shapes.ts +133 -0
- package/src/fx/fab-wafer.meta.json +42 -0
- package/src/fx/fab-wafer.ts +72 -0
- package/src/fx/fade.meta.json +26 -0
- package/src/fx/fade.ts +4 -0
- package/src/fx/film.meta.json +26 -0
- package/src/fx/film.ts +4 -0
- package/src/fx/float.meta.json +26 -0
- package/src/fx/float.ts +8 -0
- package/src/fx/flythrough.meta.json +26 -0
- package/src/fx/flythrough.ts +4 -0
- package/src/fx/fog.meta.json +26 -0
- package/src/fx/fog.ts +8 -0
- package/src/fx/geo-fragments.meta.json +48 -0
- package/src/fx/geo-fragments.ts +59 -0
- package/src/fx/glass.meta.json +26 -0
- package/src/fx/glass.ts +8 -0
- package/src/fx/globe-arcs.meta.json +36 -0
- package/src/fx/globe-arcs.ts +67 -0
- package/src/fx/glow-tube.meta.json +26 -0
- package/src/fx/glow-tube.ts +8 -0
- package/src/fx/glyph-rain.meta.json +30 -0
- package/src/fx/glyph-rain.ts +18 -0
- package/src/fx/god-rays.meta.json +40 -0
- package/src/fx/god-rays.ts +4 -0
- package/src/fx/grid-horizon.meta.json +30 -0
- package/src/fx/grid-horizon.ts +18 -0
- package/src/fx/hex-grid.meta.json +29 -0
- package/src/fx/hex-grid.ts +18 -0
- package/src/fx/holo-fresnel.meta.json +26 -0
- package/src/fx/holo-fresnel.ts +8 -0
- package/src/fx/horizon-gates.meta.json +36 -0
- package/src/fx/horizon-gates.ts +60 -0
- package/src/fx/index.ts +258 -0
- package/src/fx/iridescent.meta.json +26 -0
- package/src/fx/iridescent.ts +8 -0
- package/src/fx/iris.meta.json +26 -0
- package/src/fx/iris.ts +4 -0
- package/src/fx/lightformers.meta.json +26 -0
- package/src/fx/lightformers.ts +8 -0
- package/src/fx/local.ts +200 -0
- package/src/fx/market-tape.meta.json +53 -0
- package/src/fx/market-tape.ts +97 -0
- package/src/fx/matcap.meta.json +26 -0
- package/src/fx/matcap.ts +8 -0
- package/src/fx/meta.schema.json +49 -0
- package/src/fx/metal.meta.json +26 -0
- package/src/fx/metal.ts +8 -0
- package/src/fx/mirror-floor.meta.json +26 -0
- package/src/fx/mirror-floor.ts +8 -0
- package/src/fx/neural-mesh.meta.json +54 -0
- package/src/fx/neural-mesh.ts +110 -0
- package/src/fx/orbit-agents.meta.json +36 -0
- package/src/fx/orbit-agents.ts +63 -0
- package/src/fx/orbit.meta.json +27 -0
- package/src/fx/orbit.ts +8 -0
- package/src/fx/outline.meta.json +43 -0
- package/src/fx/outline.ts +4 -0
- package/src/fx/paper-stack.meta.json +36 -0
- package/src/fx/paper-stack.ts +61 -0
- package/src/fx/particle-stream.meta.json +27 -0
- package/src/fx/particle-stream.ts +8 -0
- package/src/fx/particles.meta.json +26 -0
- package/src/fx/particles.ts +8 -0
- package/src/fx/pixelate.meta.json +28 -0
- package/src/fx/pixelate.ts +4 -0
- package/src/fx/points-on-geometry.meta.json +61 -0
- package/src/fx/points-on-geometry.ts +71 -0
- package/src/fx/proof-gate.meta.json +30 -0
- package/src/fx/proof-gate.ts +67 -0
- package/src/fx/rings.meta.json +27 -0
- package/src/fx/rings.ts +8 -0
- package/src/fx/room-ibl.meta.json +26 -0
- package/src/fx/room-ibl.ts +8 -0
- package/src/fx/sao.meta.json +32 -0
- package/src/fx/sao.ts +4 -0
- package/src/fx/scaffold.ts +172 -0
- package/src/fx/scatter.meta.json +49 -0
- package/src/fx/scatter.ts +74 -0
- package/src/fx/selective-bloom.meta.json +36 -0
- package/src/fx/selective-bloom.ts +4 -0
- package/src/fx/server-racks.meta.json +36 -0
- package/src/fx/server-racks.ts +54 -0
- package/src/fx/shader-particles.meta.json +46 -0
- package/src/fx/shader-particles.ts +75 -0
- package/src/fx/signal-pulse.meta.json +27 -0
- package/src/fx/signal-pulse.ts +8 -0
- package/src/fx/smaa.meta.json +19 -0
- package/src/fx/smaa.ts +4 -0
- package/src/fx/sobel.meta.json +24 -0
- package/src/fx/sobel.ts +4 -0
- package/src/fx/soft-shadows.meta.json +26 -0
- package/src/fx/soft-shadows.ts +8 -0
- package/src/fx/sprites.meta.json +40 -0
- package/src/fx/sprites.ts +57 -0
- package/src/fx/stagger-reveal.meta.json +26 -0
- package/src/fx/stagger-reveal.ts +8 -0
- package/src/fx/starfield.meta.json +32 -0
- package/src/fx/starfield.ts +18 -0
- package/src/fx/swarm.meta.json +27 -0
- package/src/fx/swarm.ts +8 -0
- package/src/fx/tessellate.meta.json +39 -0
- package/src/fx/tessellate.ts +79 -0
- package/src/fx/tokens.meta.json +27 -0
- package/src/fx/tokens.ts +8 -0
- package/src/fx/trail.meta.json +27 -0
- package/src/fx/trail.ts +8 -0
- package/src/fx/trust-ledger.meta.json +30 -0
- package/src/fx/trust-ledger.ts +47 -0
- package/src/fx/types.ts +83 -0
- package/src/fx/util.ts +108 -0
- package/src/fx/vault-glyphs.meta.json +37 -0
- package/src/fx/vault-glyphs.ts +55 -0
- package/src/fx/video-screen.meta.json +57 -0
- package/src/fx/video-screen.ts +99 -0
- package/src/fx/vignette.meta.json +32 -0
- package/src/fx/vignette.ts +4 -0
- package/src/fx/volume-cloud.meta.json +58 -0
- package/src/fx/volume-cloud.ts +87 -0
- package/src/fx/volume-perlin.meta.json +46 -0
- package/src/fx/volume-perlin.ts +82 -0
- package/src/fx/volumetric-spot.meta.json +26 -0
- package/src/fx/volumetric-spot.ts +8 -0
- package/src/fx/wireframe-overlay.meta.json +27 -0
- package/src/fx/wireframe-overlay.ts +8 -0
- package/src/ir/defaults.ts +62 -0
- package/src/ir/field-reference.ts +96 -0
- package/src/ir/hash.ts +34 -0
- package/src/ir/ids.ts +65 -0
- package/src/ir/merge.ts +155 -0
- package/src/ir/schema.json +1211 -0
- package/src/ir/types.ts +333 -0
- package/src/ir/validate.ts +196 -0
- package/src/parse/derive.ts +205 -0
- package/src/parse/harvest/bundle.ts +56 -0
- package/src/parse/harvest/harness.html +22 -0
- package/src/parse/harvest/harness.ts +191 -0
- package/src/parse/harvest/index.ts +169 -0
- package/src/parse/harvest/shapes.ts +75 -0
- package/src/parse/markdown.ts +215 -0
- package/src/props/embed.ts +92 -0
- package/src/props/fetch.ts +97 -0
- package/src/props/generate.ts +152 -0
- package/src/props/key.ts +13 -0
- package/src/props/search.ts +180 -0
- package/src/render/embed-video.ts +80 -0
- package/src/render/font.ts +86 -0
- package/src/render/index.ts +149 -0
- package/src/render/template.html +87 -0
- package/src/runtime/backgrounds.ts +146 -0
- package/src/runtime/builders.ts +808 -0
- package/src/runtime/camera.ts +73 -0
- package/src/runtime/hud.ts +887 -0
- package/src/runtime/index.ts +1168 -0
- package/src/runtime/local-fx.ts +151 -0
- package/src/runtime/materials.ts +136 -0
- package/src/runtime/measure.ts +73 -0
- package/src/runtime/node-geometry.ts +26 -0
- package/src/runtime/palette.ts +111 -0
- package/src/runtime/post.ts +649 -0
- package/src/runtime/props.ts +292 -0
- package/src/runtime/quality.ts +20 -0
- package/src/runtime/rng.ts +8 -0
- package/src/runtime/scene.ts +644 -0
- package/src/runtime/text.ts +174 -0
- package/src/runtime/types.ts +118 -0
- package/src/serve/index.ts +376 -0
- package/src/util/paths.ts +35 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local-effect instantiation (design D1).
|
|
3
|
+
*
|
|
4
|
+
* A module embedded in `window.__DECK_LOCAL_FX` is evaluated with the
|
|
5
|
+
* non-deterministic and I/O globals shadowed to `undefined` and `Math.random`
|
|
6
|
+
* rebound to the deck's seeded generator. This is a DETERMINISM/OFFLINE
|
|
7
|
+
* guardrail, not a security boundary — the author runs their own deck, and
|
|
8
|
+
* `ctx.THREE` loaders still reach the network (which `check` blocks and
|
|
9
|
+
* reports).
|
|
10
|
+
*
|
|
11
|
+
* Every entry point is wrapped: a throw disables that effect for that slide,
|
|
12
|
+
* never the slide.
|
|
13
|
+
*/
|
|
14
|
+
import type { LocalCards } from "../fx/compose.js";
|
|
15
|
+
import type { FxCard, FxContext, FxHandle, FxParams } from "../fx/types.js";
|
|
16
|
+
|
|
17
|
+
/** Identifiers that resolve to `undefined` inside a local module. */
|
|
18
|
+
export const SHADOWED = [
|
|
19
|
+
"window",
|
|
20
|
+
"document",
|
|
21
|
+
"globalThis",
|
|
22
|
+
"self",
|
|
23
|
+
"fetch",
|
|
24
|
+
"XMLHttpRequest",
|
|
25
|
+
"WebSocket",
|
|
26
|
+
"EventSource",
|
|
27
|
+
"Image",
|
|
28
|
+
"Worker",
|
|
29
|
+
"WebAssembly",
|
|
30
|
+
"navigator",
|
|
31
|
+
"location",
|
|
32
|
+
"localStorage",
|
|
33
|
+
"sessionStorage",
|
|
34
|
+
"indexedDB",
|
|
35
|
+
"postMessage",
|
|
36
|
+
"setTimeout",
|
|
37
|
+
"setInterval",
|
|
38
|
+
"requestAnimationFrame",
|
|
39
|
+
"queueMicrotask",
|
|
40
|
+
"Promise",
|
|
41
|
+
"Date",
|
|
42
|
+
"performance",
|
|
43
|
+
"crypto",
|
|
44
|
+
"eval",
|
|
45
|
+
"Function",
|
|
46
|
+
"importScripts",
|
|
47
|
+
] as const;
|
|
48
|
+
|
|
49
|
+
export interface LocalFxError {
|
|
50
|
+
slide: string;
|
|
51
|
+
effectId: string;
|
|
52
|
+
phase: "create" | "tick" | "dispose";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface LocalFxModule {
|
|
56
|
+
card: FxCard;
|
|
57
|
+
src: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type LocalFxRegistry = Record<string, LocalFxModule>;
|
|
61
|
+
|
|
62
|
+
export function localFxRegistry(): LocalFxRegistry {
|
|
63
|
+
return ((window as unknown as { __DECK_LOCAL_FX?: LocalFxRegistry }).__DECK_LOCAL_FX ?? {}) as LocalFxRegistry;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The embedded cards, in the shape `composeEffects` expects. */
|
|
67
|
+
export function localCards(): LocalCards {
|
|
68
|
+
return Object.fromEntries(Object.entries(localFxRegistry()).map(([name, m]) => [name, m.card]));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A frozen `Math` whose `random` is the deck's per-slide seeded stream. */
|
|
72
|
+
function seededMath(rng: () => number): Math {
|
|
73
|
+
const clone = Object.create(Math) as Math & { random: () => number };
|
|
74
|
+
clone.random = rng;
|
|
75
|
+
return Object.freeze(clone);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Build the factory from embedded source. `render` already rewrote the leading
|
|
80
|
+
* `export default function` to `return function`, so the body evaluates to the
|
|
81
|
+
* factory.
|
|
82
|
+
*/
|
|
83
|
+
function compile(src: string, rng: () => number): (ctx: FxContext, params: FxParams) => FxHandle {
|
|
84
|
+
const names = [...SHADOWED, "Math"];
|
|
85
|
+
// No `"use strict"`: `eval` and `Function` are illegal parameter names in
|
|
86
|
+
// strict mode, and binding them to `undefined` is exactly what makes the
|
|
87
|
+
// spec's shadowing list true. Isolation here is a determinism/offline
|
|
88
|
+
// guardrail, not a security boundary (design D1).
|
|
89
|
+
// biome-ignore lint/security/noGlobalEval: deliberate — the local-effect contract is source embedded at render time, pinned by sha256.
|
|
90
|
+
const make = new Function(...names, src) as (...args: unknown[]) => unknown;
|
|
91
|
+
const factory = make(...SHADOWED.map(() => undefined), seededMath(rng));
|
|
92
|
+
if (typeof factory !== "function") throw new TypeError("local effect did not return a factory function");
|
|
93
|
+
return factory as (ctx: FxContext, params: FxParams) => FxHandle;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface LocalHandle {
|
|
97
|
+
object?: unknown;
|
|
98
|
+
tick: (t: number) => void;
|
|
99
|
+
dispose: () => void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Instantiate `local:<name>` for a slide. Returns `undefined` when the module
|
|
104
|
+
* is unknown or its factory threw; the error is pushed onto `errors`.
|
|
105
|
+
*/
|
|
106
|
+
export function createLocalEffect(
|
|
107
|
+
effectId: string,
|
|
108
|
+
module: LocalFxModule | undefined,
|
|
109
|
+
ctx: FxContext,
|
|
110
|
+
params: FxParams,
|
|
111
|
+
errors: LocalFxError[],
|
|
112
|
+
): LocalHandle | undefined {
|
|
113
|
+
const slide = ctx.slide.id;
|
|
114
|
+
const record = (phase: LocalFxError["phase"], err: unknown): void => {
|
|
115
|
+
errors.push({ slide, effectId, phase });
|
|
116
|
+
console.error(`local effect ${effectId} failed in ${phase} on slide ${slide}:`, err);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if (!module) return undefined;
|
|
120
|
+
let handle: FxHandle;
|
|
121
|
+
try {
|
|
122
|
+
handle = compile(module.src, ctx.rng)(ctx, params);
|
|
123
|
+
} catch (err) {
|
|
124
|
+
record("create", err);
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let dead = false;
|
|
129
|
+
return {
|
|
130
|
+
object: handle.object,
|
|
131
|
+
tick: (t: number) => {
|
|
132
|
+
if (dead || !handle.tick) return;
|
|
133
|
+
try {
|
|
134
|
+
handle.tick(t);
|
|
135
|
+
} catch (err) {
|
|
136
|
+
// Once disabled it stays disabled: a throwing tick would otherwise
|
|
137
|
+
// report every frame and drown the report.
|
|
138
|
+
dead = true;
|
|
139
|
+
record("tick", err);
|
|
140
|
+
(handle.object as { parent?: { remove: (o: unknown) => void } } | undefined)?.parent?.remove(handle.object);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
dispose: () => {
|
|
144
|
+
try {
|
|
145
|
+
handle.dispose?.();
|
|
146
|
+
} catch (err) {
|
|
147
|
+
record("dispose", err);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/** PBR material presets (glass / metal / matte), mode- and env-aware. */
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import type { PaletteColors } from "./palette.js";
|
|
4
|
+
import type { SlideConfig } from "./types.js";
|
|
5
|
+
|
|
6
|
+
export type MaterialRole = "accent" | "second";
|
|
7
|
+
|
|
8
|
+
function glassMaterial(col: string, role: MaterialRole, envOn: boolean): THREE.Material {
|
|
9
|
+
if (role === "accent") {
|
|
10
|
+
return new THREE.MeshPhysicalMaterial({
|
|
11
|
+
color: col,
|
|
12
|
+
metalness: 0.9,
|
|
13
|
+
roughness: 0.18,
|
|
14
|
+
envMapIntensity: envOn ? 1.4 : 0,
|
|
15
|
+
emissive: col,
|
|
16
|
+
emissiveIntensity: 0.25,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return new THREE.MeshPhysicalMaterial({
|
|
20
|
+
color: col,
|
|
21
|
+
metalness: 0,
|
|
22
|
+
roughness: 0.05,
|
|
23
|
+
transmission: 0.85,
|
|
24
|
+
thickness: 0.8,
|
|
25
|
+
ior: 1.45,
|
|
26
|
+
envMapIntensity: envOn ? 1.2 : 0,
|
|
27
|
+
clearcoat: 1,
|
|
28
|
+
clearcoatRoughness: 0.05,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function diagramMaterial(P: PaletteColors, role: MaterialRole, cfg: SlideConfig): THREE.Material {
|
|
33
|
+
const col = role === "accent" ? P.accent : P.second;
|
|
34
|
+
const envOn = cfg.envReflections !== false;
|
|
35
|
+
const material = cfg.material ?? "glass";
|
|
36
|
+
if (material === "glass") return glassMaterial(col, role, envOn);
|
|
37
|
+
if (material === "metal") {
|
|
38
|
+
return new THREE.MeshStandardMaterial({
|
|
39
|
+
color: col,
|
|
40
|
+
metalness: 1,
|
|
41
|
+
roughness: role === "accent" ? 0.22 : 0.38,
|
|
42
|
+
envMapIntensity: envOn ? 1.6 : 0,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return new THREE.MeshStandardMaterial({ color: col, metalness: 0.1, roughness: 0.75 });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Relative luminance (WCAG), for picking the contour colour by contrast. */
|
|
49
|
+
function luminance(hex: string): number {
|
|
50
|
+
// Decode from the sRGB bytes: `THREE.Color` already holds LINEAR values under
|
|
51
|
+
// colour management, so reading `.r/.g/.b` and decoding again double-counts.
|
|
52
|
+
const n = new THREE.Color(hex).getHex(THREE.SRGBColorSpace);
|
|
53
|
+
const ch = (v: number) => (v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);
|
|
54
|
+
return 0.2126 * ch(((n >> 16) & 255) / 255) + 0.7152 * ch(((n >> 8) & 255) / 255) + 0.0722 * ch((n & 255) / 255);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Linear-luminance ceiling for the contour.
|
|
59
|
+
*
|
|
60
|
+
* Baseline bloom thresholds at 0.95 (dark) on the COMPOSER input, and three
|
|
61
|
+
* skips in-shader tone mapping whenever it renders to a render target — which
|
|
62
|
+
* post-processing always does. So a pure-white contour reaches the bloom pass
|
|
63
|
+
* at 1.0 whatever the tone mapper would have done to it on screen, and blows
|
|
64
|
+
* out into a halo. Sitting under the threshold is the only thing that holds.
|
|
65
|
+
*/
|
|
66
|
+
export const BLOOM_CEILING = 0.8;
|
|
67
|
+
|
|
68
|
+
function dimBelowBloom(hex: string): string {
|
|
69
|
+
const c = new THREE.Color(hex);
|
|
70
|
+
const lin = 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b;
|
|
71
|
+
if (lin <= BLOOM_CEILING) return hex;
|
|
72
|
+
return `#${c.multiplyScalar(BLOOM_CEILING / lin).getHexString()}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function contrast(a: string, b: string): number {
|
|
76
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
77
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Contour material for extruded title SIDE walls (`titleEdge: "contrast"`).
|
|
82
|
+
*
|
|
83
|
+
* Unlit on purpose. The side walls are near-perpendicular to the camera, which
|
|
84
|
+
* is exactly where a lit material goes black — the contour would disappear in
|
|
85
|
+
* the case the switch exists to fix.
|
|
86
|
+
*
|
|
87
|
+
* Tone-mapped AND held under `BLOOM_CEILING`. A pure-white contour is over the
|
|
88
|
+
* baseline bloom threshold and halos worse than the merged silhouette it
|
|
89
|
+
* fixes; the contrast floor is checked on the DIMMED colour, so the contour
|
|
90
|
+
* that ships is the one that was measured.
|
|
91
|
+
*
|
|
92
|
+
* The colour is the palette's own `text` colour — same hue discipline as the
|
|
93
|
+
* canvas labels. It must clear a contrast floor against BOTH the lit face (or
|
|
94
|
+
* the contour is invisible on the glyph) and the background (or the outer
|
|
95
|
+
* silhouette is invisible). `text` alone is not always enough: in
|
|
96
|
+
* `forest/light` it sits at ratio 1.46 against the accent. Where it falls
|
|
97
|
+
* short, only its LIGHTNESS is pushed away from the face — hue and saturation
|
|
98
|
+
* are left alone, so the contour still reads as the palette's colour.
|
|
99
|
+
*/
|
|
100
|
+
export const EDGE_CONTRAST_FLOOR = 2.2;
|
|
101
|
+
|
|
102
|
+
export function titleEdgeColour(P: PaletteColors): string {
|
|
103
|
+
return dimBelowBloom(rawEdgeColour(P));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function rawEdgeColour(P: PaletteColors): string {
|
|
107
|
+
const base = new THREE.Color(P.text);
|
|
108
|
+
if (contrast(P.text, P.accent) >= EDGE_CONTRAST_FLOOR) return P.text;
|
|
109
|
+
// Push away from the face: lighter when the face is dark, darker when light.
|
|
110
|
+
const up = luminance(P.accent) < 0.35;
|
|
111
|
+
const hsl = base.getHSL({ h: 0, s: 0, l: 0 });
|
|
112
|
+
for (let step = 1; step <= 20; step++) {
|
|
113
|
+
const l = up ? Math.min(0.98, hsl.l + step * 0.05) : Math.max(0.04, hsl.l - step * 0.05);
|
|
114
|
+
const candidate = `#${new THREE.Color().setHSL(hsl.h, hsl.s, l).getHexString()}`;
|
|
115
|
+
if (contrast(candidate, P.accent) >= EDGE_CONTRAST_FLOOR) return candidate;
|
|
116
|
+
if (l >= 0.98 || l <= 0.04) return candidate;
|
|
117
|
+
}
|
|
118
|
+
return P.text;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function titleEdgeMaterial(P: PaletteColors): THREE.Material {
|
|
122
|
+
return new THREE.MeshBasicMaterial({ color: titleEdgeColour(P) });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function titleMaterial(P: PaletteColors, cfg: SlideConfig): THREE.Material {
|
|
126
|
+
return new THREE.MeshPhysicalMaterial({
|
|
127
|
+
color: P.accent,
|
|
128
|
+
metalness: 0.85,
|
|
129
|
+
roughness: 0.2,
|
|
130
|
+
envMapIntensity: cfg.envReflections !== false ? 1.5 : 0,
|
|
131
|
+
clearcoat: 0.6,
|
|
132
|
+
clearcoatRoughness: 0.15,
|
|
133
|
+
emissive: P.accent,
|
|
134
|
+
emissiveIntensity: cfg.mode === "dark" ? 0.05 : 0,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Screen-space projection used by `measure()` (and therefore by every `check`
|
|
3
|
+
* fit/overlap/occlusion rule).
|
|
4
|
+
*
|
|
5
|
+
* The box is taken in the OBJECT'S OWN frame and then transformed, never as a
|
|
6
|
+
* world-axis-aligned `Box3`. A world AABB inflates the moment a slide is turned
|
|
7
|
+
* — on the `orbit`/`helix` rails every slide but the first is — which reported
|
|
8
|
+
* titles up to 1.5x their real size and produced `fit` findings for layouts
|
|
9
|
+
* that were correct. See change: deck3d-cinematic-worlds.
|
|
10
|
+
*/
|
|
11
|
+
import * as THREE from "three";
|
|
12
|
+
|
|
13
|
+
export interface ScreenRect {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
w: number;
|
|
17
|
+
h: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const localBox = new THREE.Box3();
|
|
21
|
+
const childBox = new THREE.Box3();
|
|
22
|
+
const toLocal = new THREE.Matrix4();
|
|
23
|
+
const childToLocal = new THREE.Matrix4();
|
|
24
|
+
const corner = new THREE.Vector3();
|
|
25
|
+
|
|
26
|
+
/** Union of the object's geometry bounds expressed in the object's own frame. */
|
|
27
|
+
function boundsInOwnFrame(object: THREE.Object3D): THREE.Box3 {
|
|
28
|
+
object.updateWorldMatrix(true, true);
|
|
29
|
+
toLocal.copy(object.matrixWorld).invert();
|
|
30
|
+
localBox.makeEmpty();
|
|
31
|
+
object.traverse((child) => {
|
|
32
|
+
const mesh = child as THREE.Mesh;
|
|
33
|
+
const geometry = mesh.geometry;
|
|
34
|
+
if (!geometry) return;
|
|
35
|
+
if (!geometry.boundingBox) geometry.computeBoundingBox();
|
|
36
|
+
if (!geometry.boundingBox) return;
|
|
37
|
+
childBox.copy(geometry.boundingBox);
|
|
38
|
+
childToLocal.multiplyMatrices(toLocal, child.matrixWorld);
|
|
39
|
+
childBox.applyMatrix4(childToLocal);
|
|
40
|
+
localBox.union(childBox);
|
|
41
|
+
});
|
|
42
|
+
return localBox;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function projectRect(
|
|
46
|
+
object: THREE.Object3D,
|
|
47
|
+
camera: THREE.PerspectiveCamera,
|
|
48
|
+
width: number,
|
|
49
|
+
height: number,
|
|
50
|
+
): ScreenRect | null {
|
|
51
|
+
const box = boundsInOwnFrame(object);
|
|
52
|
+
if (box.isEmpty()) return null;
|
|
53
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
54
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
55
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
56
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
57
|
+
for (const x of [box.min.x, box.max.x]) {
|
|
58
|
+
for (const y of [box.min.y, box.max.y]) {
|
|
59
|
+
for (const z of [box.min.z, box.max.z]) {
|
|
60
|
+
// Local corner -> world (the object's own rotation included) -> screen.
|
|
61
|
+
corner.set(x, y, z).applyMatrix4(object.matrixWorld).project(camera);
|
|
62
|
+
const px = (corner.x * 0.5 + 0.5) * width;
|
|
63
|
+
const py = (-corner.y * 0.5 + 0.5) * height;
|
|
64
|
+
minX = Math.min(minX, px);
|
|
65
|
+
minY = Math.min(minY, py);
|
|
66
|
+
maxX = Math.max(maxX, px);
|
|
67
|
+
maxY = Math.max(maxY, py);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (![minX, minY, maxX, maxY].every(Number.isFinite)) return null;
|
|
72
|
+
return { x: minX, y: minY, w: maxX - minX, h: maxY - minY };
|
|
73
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Node shape → three.js primitive (ported from the lab). */
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import type { NodeShape } from "../ir/types.js";
|
|
4
|
+
|
|
5
|
+
export function nodeGeometry(shape: NodeShape, w: number, h: number): THREE.BufferGeometry {
|
|
6
|
+
const dpt = 0.16;
|
|
7
|
+
if (shape === "circle" || shape === "doublecircle") return new THREE.SphereGeometry(h / 2, 32, 32);
|
|
8
|
+
if (shape === "round" || shape === "stadium") {
|
|
9
|
+
const g = new THREE.CapsuleGeometry(h / 2, Math.max(0.01, w - h), 8, 24);
|
|
10
|
+
g.rotateZ(Math.PI / 2);
|
|
11
|
+
return g;
|
|
12
|
+
}
|
|
13
|
+
if (shape === "diamond") {
|
|
14
|
+
const g = new THREE.OctahedronGeometry(h * 0.8, 0);
|
|
15
|
+
g.scale((w / h) * 0.7, 1, 0.35);
|
|
16
|
+
return g;
|
|
17
|
+
}
|
|
18
|
+
if (shape === "hexagon") {
|
|
19
|
+
const g = new THREE.CylinderGeometry(h * 0.6, h * 0.6, dpt, 6);
|
|
20
|
+
g.rotateX(Math.PI / 2);
|
|
21
|
+
g.scale((w / h) * 0.75, 1, 1);
|
|
22
|
+
return g;
|
|
23
|
+
}
|
|
24
|
+
if (shape === "cylinder") return new THREE.CylinderGeometry(w / 2, w / 2, h, 32);
|
|
25
|
+
return new THREE.BoxGeometry(w, h, dpt);
|
|
26
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
/**
|
|
3
|
+
* Palette resolution (ported from the strategy lab). A named palette plus
|
|
4
|
+
* mode yields the five colours; `custom` derives bg/text from the card colour.
|
|
5
|
+
*/
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import type { Mode, Palette } from "../ir/types.js";
|
|
8
|
+
import type { SlideConfig } from "./types.js";
|
|
9
|
+
|
|
10
|
+
export interface PaletteColors {
|
|
11
|
+
accent: string;
|
|
12
|
+
second: string;
|
|
13
|
+
bg: string;
|
|
14
|
+
card: string;
|
|
15
|
+
text: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface PaletteDef {
|
|
19
|
+
accent: string;
|
|
20
|
+
second: string;
|
|
21
|
+
dark: { bg: string; card: string; text: string };
|
|
22
|
+
light: { bg: string; card: string; text: string };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const PALETTES: Record<Exclude<Palette, "custom">, PaletteDef> = {
|
|
26
|
+
blackbelt: {
|
|
27
|
+
accent: "#FF5722",
|
|
28
|
+
second: "#9E9E9E",
|
|
29
|
+
dark: { bg: "#1a1a1c", card: "#3a3a3d", text: "#FFFFFF" },
|
|
30
|
+
light: { bg: "#E8E8EA", card: "#FFFFFF", text: "#2b2b2b" },
|
|
31
|
+
},
|
|
32
|
+
zenit: {
|
|
33
|
+
accent: "#F47A20",
|
|
34
|
+
second: "#4472C4",
|
|
35
|
+
dark: { bg: "#08101e", card: "#1F3A5F", text: "#FFFFFF" },
|
|
36
|
+
light: { bg: "#F3F1EC", card: "#FFFFFF", text: "#1F3A5F" },
|
|
37
|
+
},
|
|
38
|
+
dapp: {
|
|
39
|
+
accent: "#6366F1",
|
|
40
|
+
second: "#22C55E",
|
|
41
|
+
dark: { bg: "#0B1120", card: "#1E293B", text: "#F8FAFC" },
|
|
42
|
+
light: { bg: "#F8FAFC", card: "#FFFFFF", text: "#0F172A" },
|
|
43
|
+
},
|
|
44
|
+
midnight: {
|
|
45
|
+
accent: "#818CF8",
|
|
46
|
+
second: "#94A3B8",
|
|
47
|
+
dark: { bg: "#0F172A", card: "#1E293B", text: "#E2E8F0" },
|
|
48
|
+
light: { bg: "#EEF2FF", card: "#FFFFFF", text: "#1E1B4B" },
|
|
49
|
+
},
|
|
50
|
+
ember: {
|
|
51
|
+
accent: "#F59E0B",
|
|
52
|
+
second: "#A8A29E",
|
|
53
|
+
dark: { bg: "#1C1917", card: "#292524", text: "#FAFAF9" },
|
|
54
|
+
light: { bg: "#FFFBEB", card: "#FFFFFF", text: "#292524" },
|
|
55
|
+
},
|
|
56
|
+
arctic: {
|
|
57
|
+
accent: "#06B6D4",
|
|
58
|
+
second: "#64748B",
|
|
59
|
+
dark: { bg: "#07172B", card: "#133046", text: "#E0F2FE" },
|
|
60
|
+
light: { bg: "#F5FCFF", card: "#FFFFFF", text: "#0C4A6E" },
|
|
61
|
+
},
|
|
62
|
+
forest: {
|
|
63
|
+
accent: "#4D7C0F",
|
|
64
|
+
second: "#A16207",
|
|
65
|
+
dark: { bg: "#0F1A0F", card: "#1F2E1B", text: "#F0FDF4" },
|
|
66
|
+
light: { bg: "#FAF8F0", card: "#FFFFFF", text: "#1A2E05" },
|
|
67
|
+
},
|
|
68
|
+
mono: {
|
|
69
|
+
accent: "#FFFFFF",
|
|
70
|
+
second: "#9CA3AF",
|
|
71
|
+
dark: { bg: "#000000", card: "#262626", text: "#FFFFFF" },
|
|
72
|
+
light: { bg: "#FFFFFF", card: "#F5F5F5", text: "#000000" },
|
|
73
|
+
},
|
|
74
|
+
neon: {
|
|
75
|
+
accent: "#FF2E9A",
|
|
76
|
+
second: "#22D3EE",
|
|
77
|
+
dark: { bg: "#05020A", card: "#1A0B24", text: "#FDF4FF" },
|
|
78
|
+
light: { bg: "#FDF2F8", card: "#FFFFFF", text: "#4A044E" },
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function resolvePalette(cfg: SlideConfig): PaletteColors {
|
|
83
|
+
const palette = cfg.palette ?? "blackbelt";
|
|
84
|
+
const mode: Mode = cfg.mode ?? "dark";
|
|
85
|
+
if (palette === "custom") {
|
|
86
|
+
const card = cfg.colors?.card ?? "#4A4A4A";
|
|
87
|
+
const c = new Color(card);
|
|
88
|
+
const l = c.getHSL({ h: 0, s: 0, l: 0 }).l;
|
|
89
|
+
const bg = c.clone().offsetHSL(0, 0, mode === "dark" ? -0.12 : 0.35);
|
|
90
|
+
return {
|
|
91
|
+
accent: cfg.colors?.accent ?? "#FF5722",
|
|
92
|
+
second: cfg.colors?.secondary ?? "#9E9E9E",
|
|
93
|
+
bg: `#${bg.getHexString()}`,
|
|
94
|
+
card,
|
|
95
|
+
text: l > 0.6 ? "#222222" : "#FFFFFF",
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const p = PALETTES[palette];
|
|
99
|
+
return { accent: p.accent, second: p.second, ...p[mode] };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Blend two palettes channel-wise. Used to MORPH the scene look across a
|
|
104
|
+
* transition when neighbouring slides carry different palettes — snapping the
|
|
105
|
+
* background at t=0 changed the world a full `durationSec` before the camera
|
|
106
|
+
* arrived.
|
|
107
|
+
*/
|
|
108
|
+
export function mixPalette(a: PaletteColors, b: PaletteColors, k: number): PaletteColors {
|
|
109
|
+
const mix = (x: string, y: string): string => `#${new THREE.Color(x).lerp(new THREE.Color(y), k).getHexString()}`;
|
|
110
|
+
return { accent: mix(a.accent, b.accent), second: mix(a.second, b.second), bg: mix(a.bg, b.bg), card: mix(a.card, b.card), text: mix(a.text, b.text) };
|
|
111
|
+
}
|