@blackbelt-technology/pi-dashboard-deck3d 0.0.0-stage → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,887 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On-deck configurator (design D4).
|
|
3
|
+
*
|
|
4
|
+
* A DOM overlay, hidden by default, that drives the live scene and exports an
|
|
5
|
+
* `overrides.json` in the D1 grammar. It NEVER mutates `window.__DECK`: the
|
|
6
|
+
* embedded IR stays the record of what was rendered, and the panel's state
|
|
7
|
+
* lives in memory plus `localStorage["deck3d:" + derivedHash]`.
|
|
8
|
+
*/
|
|
9
|
+
import type { BuiltDiagramKind, CardOffset, Defaults, EffectRef, Layout, Material, Mode, Palette, Quality, Rail, TitleEdge } from "../ir/types.js";
|
|
10
|
+
|
|
11
|
+
export interface HudSlide {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
effects: EffectRef[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface HudHost {
|
|
18
|
+
slides: HudSlide[];
|
|
19
|
+
/** Every effect the deck can instantiate (corpus + embedded `local:` cards). */
|
|
20
|
+
catalogue: Array<{ id: string; kind: string }>;
|
|
21
|
+
/** Deck-level effect ids, PREPENDED to every slide — shown as inherited slots. */
|
|
22
|
+
deckEffects: string[];
|
|
23
|
+
/** Deck defaults as embedded (read-only). */
|
|
24
|
+
defaults: Defaults;
|
|
25
|
+
/** Keys already overridden, for the `●` markers. */
|
|
26
|
+
overridden: { deck: Set<string>; slides: Record<string, Set<string>> };
|
|
27
|
+
derivedHash: string;
|
|
28
|
+
current: () => number;
|
|
29
|
+
gotoSlide: (index1Based: number) => void;
|
|
30
|
+
/** Re-apply look/camera/label knobs for the current slide. */
|
|
31
|
+
applySlide: (patch: SlidePatch) => void;
|
|
32
|
+
/** Same, for EVERY slide — a deck-scope value is not a property of one slide. */
|
|
33
|
+
applyDeck: (patchFor: (slideId: string) => SlidePatch) => void;
|
|
34
|
+
/** Recompose the current slide's effects from this list. */
|
|
35
|
+
applyEffects: (ids: string[]) => void;
|
|
36
|
+
/** Declared knobs of the current slide's effects, with values in force. */
|
|
37
|
+
effectParams: () => Array<{ id: string; schema: Record<string, unknown>; values: Record<string, unknown> }>;
|
|
38
|
+
/** Rebuild one effect of the current slide under edited params. */
|
|
39
|
+
applyEffectParams: (id: string, patch: Record<string, unknown>) => void;
|
|
40
|
+
/** Stage params for any slide WITHOUT rebuilding — used to restore on boot. */
|
|
41
|
+
seedEffectParams: (slideId: string, id: string, patch: Record<string, unknown>) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SlidePatch {
|
|
45
|
+
mode?: Mode;
|
|
46
|
+
palette?: Palette;
|
|
47
|
+
quality?: Quality;
|
|
48
|
+
material?: Material;
|
|
49
|
+
transition?: string;
|
|
50
|
+
durationSec?: number;
|
|
51
|
+
backgroundIntensity?: number;
|
|
52
|
+
bloom?: boolean;
|
|
53
|
+
rimLight?: boolean;
|
|
54
|
+
fog?: boolean;
|
|
55
|
+
mirrorFloor?: boolean;
|
|
56
|
+
floor?: "mirror" | "water";
|
|
57
|
+
reflectBackdrop?: boolean;
|
|
58
|
+
floorMatte?: number;
|
|
59
|
+
floorReflectivity?: number;
|
|
60
|
+
softShadows?: boolean;
|
|
61
|
+
envReflections?: boolean;
|
|
62
|
+
depthRelief?: number;
|
|
63
|
+
extrudeDepth?: number;
|
|
64
|
+
titleEdge?: TitleEdge;
|
|
65
|
+
colors?: { card?: string; accent?: string; secondary?: string };
|
|
66
|
+
layout?: Layout;
|
|
67
|
+
/** Deck-level: moves EVERY anchor, so the runtime re-anchors the whole rail. */
|
|
68
|
+
rail?: Rail;
|
|
69
|
+
spacing?: number;
|
|
70
|
+
cardOffset?: CardOffset;
|
|
71
|
+
/** Slide-level lane: layered onto a COPY of the slide, never onto `__DECK`. */
|
|
72
|
+
scene?: string;
|
|
73
|
+
diagram?: { kind?: BuiltDiagramKind; scale?: number; offset?: { x?: number; y?: number } };
|
|
74
|
+
camera?: { distance?: number };
|
|
75
|
+
labels?: { size?: number };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type Scope = "deck" | "slide";
|
|
79
|
+
|
|
80
|
+
/** Panel state, mirrored to local storage. Only what the user actually changed. */
|
|
81
|
+
export interface HudState {
|
|
82
|
+
deck: Record<string, unknown>;
|
|
83
|
+
slides: Record<string, Record<string, unknown>>;
|
|
84
|
+
autoplaySec: number;
|
|
85
|
+
/** Block title → open. Persisted so the panel reopens where it was left. */
|
|
86
|
+
open: Record<string, boolean>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const PALETTES: Palette[] = ["blackbelt", "zenit", "dapp", "midnight", "ember", "arctic", "forest", "mono", "neon", "custom"];
|
|
90
|
+
const MODES: Mode[] = ["dark", "light"];
|
|
91
|
+
const QUALITIES: Quality[] = ["low", "medium", "high"];
|
|
92
|
+
const MATERIALS: Material[] = ["glass", "metal", "matte"];
|
|
93
|
+
const LAYOUTS: Layout[] = ["split", "split-reverse"];
|
|
94
|
+
const RAILS: Rail[] = ["line", "orbit", "tunnel", "helix", "grid"];
|
|
95
|
+
const DIAGRAM_KINDS: BuiltDiagramKind[] = ["none", "brain", "loop", "swarm", "bars", "funnel", "timeline-rail", "globe", "orbit-cluster", "stack"];
|
|
96
|
+
const TRANSITIONS = ["dolly", "fade", "iris", "flythrough", "cut"];
|
|
97
|
+
|
|
98
|
+
/** How one control is rendered. `enum` carries its own option list. */
|
|
99
|
+
type ControlSpec =
|
|
100
|
+
| { path: string; kind: "enum"; options: readonly string[] }
|
|
101
|
+
| { path: string; kind: "number"; step?: string }
|
|
102
|
+
| { path: string; kind: "range"; min: string; max: string; step: string; fallback: string }
|
|
103
|
+
| { path: string; kind: "bool" }
|
|
104
|
+
| { path: string; kind: "colour" }
|
|
105
|
+
| { path: string; kind: "autoplay" }
|
|
106
|
+
| { path: string; kind: "effects" };
|
|
107
|
+
|
|
108
|
+
interface Block {
|
|
109
|
+
title: string;
|
|
110
|
+
/** Which scope(s) the control belongs to; a block with none is omitted. */
|
|
111
|
+
deck: ControlSpec[];
|
|
112
|
+
slide: ControlSpec[];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const enumC = (path: string, options: readonly string[]): ControlSpec => ({ path, kind: "enum", options });
|
|
116
|
+
const numC = (path: string, step?: string): ControlSpec => ({ path, kind: "number", step });
|
|
117
|
+
/**
|
|
118
|
+
* A bounded knob the presenter DRAGS; `numC` is a typed box with no range.
|
|
119
|
+
* `fallback` is the SCHEMA default, shown when the deck never set the key /
|
|
120
|
+
* falling back to `min` made the panel claim 0 while the frame ran at 1.
|
|
121
|
+
*/
|
|
122
|
+
const rangeC = (path: string, min: string, max: string, step: string, fallback: string): ControlSpec => ({ path, kind: "range", min, max, step, fallback });
|
|
123
|
+
const boolC = (path: string): ControlSpec => ({ path, kind: "bool" });
|
|
124
|
+
const colourC = (path: string): ControlSpec => ({ path, kind: "colour" });
|
|
125
|
+
|
|
126
|
+
const LOOK: ControlSpec[] = [
|
|
127
|
+
enumC("mode", MODES),
|
|
128
|
+
enumC("palette", PALETTES),
|
|
129
|
+
colourC("colors.card"),
|
|
130
|
+
colourC("colors.accent"),
|
|
131
|
+
colourC("colors.secondary"),
|
|
132
|
+
enumC("material", MATERIALS),
|
|
133
|
+
];
|
|
134
|
+
const LIGHTING: ControlSpec[] = [
|
|
135
|
+
boolC("bloom"),
|
|
136
|
+
boolC("rimLight"),
|
|
137
|
+
boolC("fog"),
|
|
138
|
+
boolC("mirrorFloor"),
|
|
139
|
+
enumC("floor", ["mirror", "water"]),
|
|
140
|
+
boolC("reflectBackdrop"),
|
|
141
|
+
rangeC("floorReflectivity", "0", "1", "0.05", "1"),
|
|
142
|
+
rangeC("floorMatte", "0", "1", "0.05", "0"),
|
|
143
|
+
boolC("softShadows"),
|
|
144
|
+
boolC("envReflections"),
|
|
145
|
+
numC("backgroundIntensity", "0.05"),
|
|
146
|
+
];
|
|
147
|
+
const TITLE_EDGES: TitleEdge[] = ["none", "contrast"];
|
|
148
|
+
const CAMERA: ControlSpec[] = [
|
|
149
|
+
numC("camera.distance"),
|
|
150
|
+
numC("labels.size", "0.02"),
|
|
151
|
+
numC("depthRelief"),
|
|
152
|
+
numC("extrudeDepth", "0.02"),
|
|
153
|
+
enumC("titleEdge", TITLE_EDGES),
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The panel's control plane. Order is the render order; a block whose list for
|
|
158
|
+
* the active scope is empty is not rendered at all, so deck scope never shows a
|
|
159
|
+
* `diagram.*` row and slide scope never shows `spacing`.
|
|
160
|
+
*/
|
|
161
|
+
const BLOCKS: Block[] = [
|
|
162
|
+
{ title: "Look", deck: LOOK, slide: LOOK },
|
|
163
|
+
{ title: "Lighting & FX", deck: LIGHTING, slide: LIGHTING },
|
|
164
|
+
{ title: "Camera & labels", deck: CAMERA, slide: CAMERA },
|
|
165
|
+
{
|
|
166
|
+
title: "Layout",
|
|
167
|
+
// `rail`/`spacing` describe the rail the slides hang on — deck-wide by
|
|
168
|
+
// definition. `diagram.*`/`cardOffset` tune one slide's composition.
|
|
169
|
+
deck: [enumC("layout", LAYOUTS), enumC("rail", RAILS), numC("spacing", "5")],
|
|
170
|
+
slide: [
|
|
171
|
+
enumC("layout", LAYOUTS),
|
|
172
|
+
enumC("diagram.kind", DIAGRAM_KINDS),
|
|
173
|
+
numC("diagram.scale", "0.05"),
|
|
174
|
+
numC("diagram.offset.x"),
|
|
175
|
+
numC("diagram.offset.y"),
|
|
176
|
+
numC("cardOffset.x"),
|
|
177
|
+
numC("cardOffset.y"),
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
title: "Motion",
|
|
182
|
+
deck: [enumC("transition", TRANSITIONS), numC("durationSec"), { path: "autoplay", kind: "autoplay" }],
|
|
183
|
+
// `durationSec` is per-slide overridable since #F43; `autoplay` is a panel
|
|
184
|
+
// concept (not IR), so it stays deck-only.
|
|
185
|
+
slide: [enumC("transition", TRANSITIONS), numC("durationSec")],
|
|
186
|
+
},
|
|
187
|
+
{ title: "Quality", deck: [enumC("quality", QUALITIES)], slide: [enumC("quality", QUALITIES)] },
|
|
188
|
+
{ title: "Effects", deck: [{ path: "effects", kind: "effects" }], slide: [{ path: "effects", kind: "effects" }] },
|
|
189
|
+
];
|
|
190
|
+
|
|
191
|
+
export const AUTOPLAY_MIN = 1;
|
|
192
|
+
export const AUTOPLAY_MAX = 600;
|
|
193
|
+
|
|
194
|
+
/** `1`–`600` integer seconds, or `0` for off. Anything else is rejected. */
|
|
195
|
+
export function parseAutoplay(raw: string): number | undefined {
|
|
196
|
+
if (raw.trim() === "") return undefined;
|
|
197
|
+
if (!/^\d+$/.test(raw.trim())) return undefined;
|
|
198
|
+
const n = Number(raw.trim());
|
|
199
|
+
if (n === 0) return 0;
|
|
200
|
+
return n >= AUTOPLAY_MIN && n <= AUTOPLAY_MAX ? n : undefined;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function storageKey(hash: string): string {
|
|
204
|
+
return `deck3d:${hash}`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Only the first block starts open; the rest are one click away. */
|
|
208
|
+
function defaultOpen(): Record<string, boolean> {
|
|
209
|
+
return Object.fromEntries(BLOCKS.map((b, i) => [b.title, i === 0]));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function loadState(hash: string): HudState {
|
|
213
|
+
const empty: HudState = { deck: {}, slides: {}, autoplaySec: 0, open: defaultOpen() };
|
|
214
|
+
try {
|
|
215
|
+
const raw = localStorage.getItem(storageKey(hash));
|
|
216
|
+
if (!raw) return empty;
|
|
217
|
+
const parsed = JSON.parse(raw) as Partial<HudState>;
|
|
218
|
+
return {
|
|
219
|
+
deck: parsed.deck ?? {},
|
|
220
|
+
slides: parsed.slides ?? {},
|
|
221
|
+
autoplaySec: parsed.autoplaySec ?? 0,
|
|
222
|
+
open: { ...defaultOpen(), ...(parsed.open ?? {}) },
|
|
223
|
+
};
|
|
224
|
+
} catch {
|
|
225
|
+
return empty;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function saveState(hash: string, state: HudState): void {
|
|
230
|
+
try {
|
|
231
|
+
localStorage.setItem(storageKey(hash), JSON.stringify(state));
|
|
232
|
+
} catch {
|
|
233
|
+
// Storage may be unavailable (private mode, file:// with strict settings).
|
|
234
|
+
// The panel still works for the session; persistence is a convenience.
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Dotted path get on a plain object (`camera.distance`). */
|
|
239
|
+
function at(obj: Record<string, unknown> | undefined, path: string): unknown {
|
|
240
|
+
let node: unknown = obj;
|
|
241
|
+
for (const part of path.split(".")) {
|
|
242
|
+
if (node === undefined || node === null || typeof node !== "object") return undefined;
|
|
243
|
+
node = (node as Record<string, unknown>)[part];
|
|
244
|
+
}
|
|
245
|
+
return node;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Dotted path set, creating intermediate objects (`camera.distance`). */
|
|
249
|
+
function setAt(obj: Record<string, unknown>, path: string, value: unknown): void {
|
|
250
|
+
const parts = path.split(".");
|
|
251
|
+
let node = obj;
|
|
252
|
+
for (const part of parts.slice(0, -1)) {
|
|
253
|
+
if (typeof node[part] !== "object" || node[part] === null) node[part] = {};
|
|
254
|
+
node = node[part] as Record<string, unknown>;
|
|
255
|
+
}
|
|
256
|
+
node[parts.at(-1) as string] = value;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function el<K extends keyof HTMLElementTagNameMap>(tag: K, attrs: Record<string, string> = {}): HTMLElementTagNameMap[K] {
|
|
260
|
+
const node = document.createElement(tag);
|
|
261
|
+
for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, v);
|
|
262
|
+
return node;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The control's current effective value: panel state, else the embedded IR. */
|
|
266
|
+
function effectiveValue(state: HudState, scope: Scope, slideId: string, path: string, defaults: Defaults): unknown {
|
|
267
|
+
const staged = scope === "deck" ? at(state.deck, path) : at(state.slides[slideId], path);
|
|
268
|
+
return staged ?? at(defaults as unknown as Record<string, unknown>, path);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface Hud {
|
|
272
|
+
toggle: () => void;
|
|
273
|
+
close: () => void;
|
|
274
|
+
isOpen: () => boolean;
|
|
275
|
+
/** True while a panel input holds focus (navigation must stand down). */
|
|
276
|
+
hasFocus: () => boolean;
|
|
277
|
+
/** True when the event happened inside the panel (no slide advance). */
|
|
278
|
+
contains: (target: EventTarget | null) => boolean;
|
|
279
|
+
/** Re-render the panel for the current slide. */
|
|
280
|
+
refresh: () => void;
|
|
281
|
+
state: () => HudState;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Build the panel. Returns handles the runtime uses to keep navigation and the
|
|
286
|
+
* panel from fighting each other.
|
|
287
|
+
*/
|
|
288
|
+
export function createHud(host: HudHost): Hud {
|
|
289
|
+
const rootEl = document.getElementById("deck3d-hud");
|
|
290
|
+
const gearEl = document.getElementById("deck3d-hud-toggle");
|
|
291
|
+
if (!rootEl || !gearEl) {
|
|
292
|
+
const noop = (): void => {};
|
|
293
|
+
return { toggle: noop, close: noop, isOpen: () => false, hasFocus: () => false, contains: () => false, refresh: noop, state: () => ({ deck: {}, slides: {}, autoplaySec: 0, open: {} }) };
|
|
294
|
+
}
|
|
295
|
+
const root = rootEl;
|
|
296
|
+
const gear = gearEl;
|
|
297
|
+
|
|
298
|
+
const state = loadState(host.derivedHash);
|
|
299
|
+
let scope: Scope = "deck";
|
|
300
|
+
let open = false;
|
|
301
|
+
let autoplayTimer: number | undefined;
|
|
302
|
+
|
|
303
|
+
const body = el("div", { id: "deck3d-hud-body" });
|
|
304
|
+
root.appendChild(body);
|
|
305
|
+
|
|
306
|
+
function persist(): void {
|
|
307
|
+
saveState(host.derivedHash, state);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function stage(path: string, value: unknown): void {
|
|
311
|
+
const slideId = host.slides[host.current() - 1]?.id ?? "";
|
|
312
|
+
if (scope === "deck") setAt(state.deck, path, value);
|
|
313
|
+
else {
|
|
314
|
+
state.slides[slideId] = state.slides[slideId] ?? {};
|
|
315
|
+
setAt(state.slides[slideId], path, value);
|
|
316
|
+
}
|
|
317
|
+
persist();
|
|
318
|
+
if (scope === "deck") host.applyDeck((id) => ({ ...(state.deck as SlidePatch), ...(state.slides[id] as SlidePatch | undefined) }));
|
|
319
|
+
else host.applySlide(patchForCurrent());
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Deck-scope staged values with the current slide's staged values on top. */
|
|
323
|
+
function patchForCurrent(): SlidePatch {
|
|
324
|
+
const slideId = host.slides[host.current() - 1]?.id ?? "";
|
|
325
|
+
return { ...(state.deck as SlidePatch), ...(state.slides[slideId] as SlidePatch | undefined) };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function isOverridden(path: string, slideId: string): boolean {
|
|
329
|
+
return scope === "deck" ? host.overridden.deck.has(path) : (host.overridden.slides[slideId]?.has(path) ?? false);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function addRow(parent: HTMLElement, label: string, control: HTMLElement, marked: boolean): void {
|
|
333
|
+
const row = el("label", { class: "deck3d-hud-row" });
|
|
334
|
+
const name = el("span");
|
|
335
|
+
name.textContent = marked ? `● ${label}` : label;
|
|
336
|
+
row.append(name, control);
|
|
337
|
+
parent.appendChild(row);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function checkbox(path: string, slideId: string): HTMLInputElement {
|
|
341
|
+
const node = el("input", { type: "checkbox", "data-path": path });
|
|
342
|
+
// Every boolean knob in the IR defaults to ON when absent.
|
|
343
|
+
node.checked = (effectiveValue(state, scope, slideId, path, host.defaults) ?? true) !== false;
|
|
344
|
+
node.addEventListener("change", () => stage(path, node.checked));
|
|
345
|
+
return node;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function colour(path: string, slideId: string): HTMLInputElement {
|
|
349
|
+
const current = effectiveValue(state, scope, slideId, path, host.defaults);
|
|
350
|
+
const node = el("input", { type: "color", "data-path": path });
|
|
351
|
+
node.value = typeof current === "string" && /^#[0-9a-f]{6}$/i.test(current) ? current : "#000000";
|
|
352
|
+
// `colors` only takes effect under `palette: custom`; staging the colour
|
|
353
|
+
// without the palette would look like a dead control.
|
|
354
|
+
node.addEventListener("change", () => {
|
|
355
|
+
stage("palette", "custom");
|
|
356
|
+
stage(path, node.value);
|
|
357
|
+
});
|
|
358
|
+
return node;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** One collapsible block; returns null when it has nothing for this scope. */
|
|
362
|
+
function renderBlock(block: Block, slideId: string): HTMLElement | null {
|
|
363
|
+
const controls = scope === "deck" ? block.deck : block.slide;
|
|
364
|
+
if (!controls.length) return null;
|
|
365
|
+
const details = el("details", { class: "deck3d-hud-block", "data-block": block.title });
|
|
366
|
+
if (state.open[block.title]) details.setAttribute("open", "");
|
|
367
|
+
const summary = el("summary");
|
|
368
|
+
summary.textContent = block.title;
|
|
369
|
+
details.appendChild(summary);
|
|
370
|
+
details.addEventListener("toggle", () => {
|
|
371
|
+
state.open[block.title] = details.hasAttribute("open");
|
|
372
|
+
persist();
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
for (const spec of controls) {
|
|
376
|
+
const marked = isOverridden(spec.path, slideId);
|
|
377
|
+
if (spec.kind === "enum") addRow(details, spec.path, select(spec.path, spec.options, slideId), marked);
|
|
378
|
+
else if (spec.kind === "number") addRow(details, spec.path, number(spec.path, slideId, spec.step ?? "0.1"), marked);
|
|
379
|
+
else if (spec.kind === "range") addRow(details, spec.path, range(spec.path, slideId, spec), marked);
|
|
380
|
+
else if (spec.kind === "bool") addRow(details, spec.path, checkbox(spec.path, slideId), marked);
|
|
381
|
+
else if (spec.kind === "colour") addRow(details, spec.path, colour(spec.path, slideId), marked);
|
|
382
|
+
else if (spec.kind === "autoplay") addRow(details, "autoplay (s)", autoplayField(), false);
|
|
383
|
+
else details.appendChild(effectSlots(slideId));
|
|
384
|
+
}
|
|
385
|
+
return details;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function select(path: string, options: readonly string[], slideId: string): HTMLSelectElement {
|
|
389
|
+
const node = el("select", { "data-path": path });
|
|
390
|
+
for (const option of options) {
|
|
391
|
+
const opt = el("option", { value: option });
|
|
392
|
+
opt.textContent = option;
|
|
393
|
+
node.appendChild(opt);
|
|
394
|
+
}
|
|
395
|
+
node.value = String(effectiveValue(state, scope, slideId, path, host.defaults) ?? options[0]);
|
|
396
|
+
node.addEventListener("change", () => stage(path, node.value));
|
|
397
|
+
return node;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Bounded slider. Stages on `input` (not `change`) so the frame follows the
|
|
402
|
+
* thumb while it is dragged / that live preview is the whole point of a
|
|
403
|
+
* slider over a number box.
|
|
404
|
+
*/
|
|
405
|
+
function range(path: string, slideId: string, spec: { min: string; max: string; step: string; fallback: string }): HTMLInputElement {
|
|
406
|
+
const node = el("input", { type: "range", min: spec.min, max: spec.max, step: spec.step, "data-path": path });
|
|
407
|
+
const value = effectiveValue(state, scope, slideId, path, host.defaults);
|
|
408
|
+
node.value = String(value ?? spec.fallback);
|
|
409
|
+
node.addEventListener("input", () => {
|
|
410
|
+
const n = Number(node.value);
|
|
411
|
+
if (Number.isFinite(n)) stage(path, n);
|
|
412
|
+
});
|
|
413
|
+
return node;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function number(path: string, slideId: string, step = "0.1"): HTMLInputElement {
|
|
417
|
+
const node = el("input", { type: "number", step, "data-path": path });
|
|
418
|
+
const value = effectiveValue(state, scope, slideId, path, host.defaults);
|
|
419
|
+
node.value = value === undefined ? "" : String(value);
|
|
420
|
+
node.addEventListener("change", () => {
|
|
421
|
+
const n = Number(node.value);
|
|
422
|
+
if (Number.isFinite(n)) stage(path, n);
|
|
423
|
+
});
|
|
424
|
+
return node;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Commit an effect list for the active scope: staged, persisted, applied. */
|
|
428
|
+
function commitEffects(slideId: string, next: string[]): void {
|
|
429
|
+
if (scope === "deck") state.deck.effects = next;
|
|
430
|
+
else {
|
|
431
|
+
state.slides[slideId] = state.slides[slideId] ?? {};
|
|
432
|
+
state.slides[slideId].effects = next;
|
|
433
|
+
}
|
|
434
|
+
persist();
|
|
435
|
+
host.applyEffects(next);
|
|
436
|
+
// The list itself changed shape — rows and the picker's options with it.
|
|
437
|
+
render();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** Effect ids of one kind, sorted — the stepper's ring. */
|
|
441
|
+
function idsOfKind(kind: string): string[] {
|
|
442
|
+
return host.catalogue
|
|
443
|
+
.filter((c) => c.kind === kind)
|
|
444
|
+
.map((c) => c.id)
|
|
445
|
+
.sort();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** Kinds the catalogue actually carries (background, post, light, …). */
|
|
449
|
+
function kinds(): string[] {
|
|
450
|
+
return [...new Set(host.catalogue.map((c) => c.kind))].sort();
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function kindOf(id: string): string {
|
|
454
|
+
return host.catalogue.find((c) => c.id === id)?.kind ?? "background";
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* ONE effect, as a slot: kind picker, a stepper over that kind, the effect's
|
|
459
|
+
* declared params, and a remove. Replaces the flat checklist, which could
|
|
460
|
+
* not say what KIND a row was and made a 79-effect corpus one long dropdown.
|
|
461
|
+
*
|
|
462
|
+
* A slot whose id comes from the deck-level list is INHERITED at slide scope
|
|
463
|
+
* (`applyOverrides` prepends that list to every slide): shown, but read-only
|
|
464
|
+
* here, because editing it belongs to deck scope.
|
|
465
|
+
*/
|
|
466
|
+
function slotRow(slideId: string, active: string[], index: number, inherited: boolean): HTMLElement {
|
|
467
|
+
const id = active[index];
|
|
468
|
+
const row = el("div", inherited ? { class: "deck3d-hud-slot", "data-inherited": "" } : { class: "deck3d-hud-slot" });
|
|
469
|
+
const head = el("div", { class: "deck3d-hud-slot-head" });
|
|
470
|
+
|
|
471
|
+
const replace = (next: string) => commitEffects(slideId, active.map((other, i) => (i === index ? next : other)));
|
|
472
|
+
|
|
473
|
+
const kindSel = el("select", { "data-slot-kind": "" }) as HTMLSelectElement;
|
|
474
|
+
for (const kind of kinds()) {
|
|
475
|
+
const option = el("option", { value: kind });
|
|
476
|
+
option.textContent = kind;
|
|
477
|
+
kindSel.appendChild(option);
|
|
478
|
+
}
|
|
479
|
+
kindSel.value = kindOf(id);
|
|
480
|
+
kindSel.addEventListener("change", () => {
|
|
481
|
+
const first = idsOfKind(kindSel.value)[0];
|
|
482
|
+
if (first) replace(first);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
const ring = idsOfKind(kindOf(id));
|
|
486
|
+
const step = (delta: number) => {
|
|
487
|
+
if (!ring.length) return;
|
|
488
|
+
const at = ring.indexOf(id);
|
|
489
|
+
replace(ring[(at + delta + ring.length) % ring.length]);
|
|
490
|
+
};
|
|
491
|
+
const prev = el("button", { type: "button", "data-slot-prev": "" });
|
|
492
|
+
prev.textContent = "\u25c0";
|
|
493
|
+
prev.addEventListener("click", () => step(-1));
|
|
494
|
+
const next = el("button", { type: "button", "data-slot-next": "" });
|
|
495
|
+
next.textContent = "\u25b6";
|
|
496
|
+
next.addEventListener("click", () => step(1));
|
|
497
|
+
|
|
498
|
+
const effectSel = el("select", { "data-slot-effect": "" }) as HTMLSelectElement;
|
|
499
|
+
for (const option of ring) {
|
|
500
|
+
const node = el("option", { value: option });
|
|
501
|
+
node.textContent = option;
|
|
502
|
+
effectSel.appendChild(node);
|
|
503
|
+
}
|
|
504
|
+
effectSel.value = id;
|
|
505
|
+
effectSel.addEventListener("change", () => replace(effectSel.value));
|
|
506
|
+
|
|
507
|
+
const remove = el("button", { type: "button", "data-slot-remove": "" });
|
|
508
|
+
remove.textContent = "\u2715";
|
|
509
|
+
remove.addEventListener("click", () => commitEffects(slideId, active.filter((_, i) => i !== index)));
|
|
510
|
+
|
|
511
|
+
for (const control of [kindSel, prev, effectSel, next, remove]) {
|
|
512
|
+
if (inherited) (control as HTMLSelectElement | HTMLButtonElement).disabled = true;
|
|
513
|
+
head.appendChild(control);
|
|
514
|
+
}
|
|
515
|
+
row.appendChild(head);
|
|
516
|
+
const knobs = paramRows(slideId, id);
|
|
517
|
+
if (knobs) row.appendChild(knobs);
|
|
518
|
+
return row;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function effectSlots(slideId: string): HTMLElement {
|
|
522
|
+
const list = el("div", { class: "deck3d-hud-effects" });
|
|
523
|
+
const composed = host.slides[host.current() - 1]?.effects ?? [];
|
|
524
|
+
const staged = (scope === "deck" ? state.deck.effects : state.slides[slideId]?.effects) as string[] | undefined;
|
|
525
|
+
const active = staged ?? composed.map((e) => e.id);
|
|
526
|
+
const fromDeck = new Set(host.deckEffects);
|
|
527
|
+
for (let i = 0; i < active.length; i++) {
|
|
528
|
+
list.appendChild(slotRow(slideId, active, i, scope === "slide" && fromDeck.has(active[i])));
|
|
529
|
+
}
|
|
530
|
+
list.appendChild(addSlotButton(slideId, active));
|
|
531
|
+
return list;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Appends a slot seeded with the first unused effect of the commonest kind. */
|
|
535
|
+
function addSlotButton(slideId: string, active: string[]): HTMLElement {
|
|
536
|
+
const button = el("button", { type: "button", "data-add-slot": "" });
|
|
537
|
+
button.textContent = "+ add slot";
|
|
538
|
+
button.addEventListener("click", () => {
|
|
539
|
+
const taken = new Set(active);
|
|
540
|
+
const seed = idsOfKind("background").find((id) => !taken.has(id)) ?? host.catalogue.map((c) => c.id).find((id) => !taken.has(id));
|
|
541
|
+
if (seed) commitEffects(slideId, [...active, seed]);
|
|
542
|
+
});
|
|
543
|
+
return button;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Controls for ONE effect, generated from the params it declares in its
|
|
548
|
+
* card. Every effect — corpus or `local:` — gets a panel by declaring
|
|
549
|
+
* params, so a new effect never needs panel code here.
|
|
550
|
+
*/
|
|
551
|
+
function paramRows(slideId: string, effectId: string): HTMLElement | null {
|
|
552
|
+
const decl = host.effectParams().find((e) => e.id === effectId);
|
|
553
|
+
if (!decl) return null;
|
|
554
|
+
const box = el("div", { class: "deck3d-hud-fxparams" });
|
|
555
|
+
for (const [key, rawSpec] of Object.entries(decl.schema)) {
|
|
556
|
+
const spec = rawSpec as { type?: string; minimum?: number; maximum?: number; default?: unknown; enum?: string[] };
|
|
557
|
+
const current = decl.values[key] ?? spec.default;
|
|
558
|
+
const line = el("label", { class: "deck3d-hud-fxparam" });
|
|
559
|
+
const tag = el("span");
|
|
560
|
+
tag.textContent = key;
|
|
561
|
+
let input: HTMLInputElement | HTMLSelectElement;
|
|
562
|
+
if (spec.enum) {
|
|
563
|
+
input = el("select", { "data-fxparam": `${effectId}.${key}` });
|
|
564
|
+
for (const option of spec.enum) {
|
|
565
|
+
const opt = el("option", { value: option });
|
|
566
|
+
opt.textContent = option;
|
|
567
|
+
input.appendChild(opt);
|
|
568
|
+
}
|
|
569
|
+
input.value = String(current ?? spec.enum[0]);
|
|
570
|
+
input.addEventListener("change", () => commitParam(slideId, effectId, key, (input as HTMLSelectElement).value));
|
|
571
|
+
} else if (spec.type === "boolean") {
|
|
572
|
+
input = el("input", { type: "checkbox", "data-fxparam": `${effectId}.${key}` });
|
|
573
|
+
(input as HTMLInputElement).checked = current === true;
|
|
574
|
+
input.addEventListener("change", () => commitParam(slideId, effectId, key, (input as HTMLInputElement).checked));
|
|
575
|
+
} else {
|
|
576
|
+
// A declared range gets a slider; an open-ended number gets a field.
|
|
577
|
+
const ranged = typeof spec.minimum === "number" && typeof spec.maximum === "number";
|
|
578
|
+
input = el("input", {
|
|
579
|
+
type: ranged ? "range" : "number",
|
|
580
|
+
step: "0.05",
|
|
581
|
+
"data-fxparam": `${effectId}.${key}`,
|
|
582
|
+
...(ranged ? { min: String(spec.minimum), max: String(spec.maximum) } : {}),
|
|
583
|
+
});
|
|
584
|
+
(input as HTMLInputElement).value = String(current ?? 1);
|
|
585
|
+
const readout = el("em");
|
|
586
|
+
readout.textContent = String(current ?? 1);
|
|
587
|
+
input.addEventListener("input", () => {
|
|
588
|
+
const n = Number((input as HTMLInputElement).value);
|
|
589
|
+
if (!Number.isFinite(n)) return;
|
|
590
|
+
readout.textContent = String(n);
|
|
591
|
+
commitParam(slideId, effectId, key, n);
|
|
592
|
+
});
|
|
593
|
+
line.append(tag, input, readout);
|
|
594
|
+
box.appendChild(line);
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
line.append(tag, input);
|
|
598
|
+
box.appendChild(line);
|
|
599
|
+
}
|
|
600
|
+
return box.childElementCount > 0 ? box : null;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** Stage a param edit for export AND apply it live. */
|
|
604
|
+
function commitParam(slideId: string, effectId: string, key: string, value: unknown): void {
|
|
605
|
+
const bucket = scope === "deck" ? (state.deck as Record<string, unknown>) : ((state.slides[slideId] = state.slides[slideId] ?? {}) as Record<string, unknown>);
|
|
606
|
+
const params = (bucket.effectParams ?? {}) as Record<string, Record<string, unknown>>;
|
|
607
|
+
params[effectId] = { ...(params[effectId] ?? {}), [key]: value };
|
|
608
|
+
bucket.effectParams = params;
|
|
609
|
+
persist();
|
|
610
|
+
host.applyEffectParams(effectId, { [key]: value });
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function autoplayField(): HTMLInputElement {
|
|
614
|
+
const node = el("input", { type: "text", id: "deck3d-hud-autoplay" });
|
|
615
|
+
node.value = String(state.autoplaySec);
|
|
616
|
+
node.addEventListener("change", () => {
|
|
617
|
+
const parsed = parseAutoplay(node.value);
|
|
618
|
+
if (parsed === undefined) {
|
|
619
|
+
// Reject: restore the last accepted value rather than half-applying.
|
|
620
|
+
node.value = String(state.autoplaySec);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
state.autoplaySec = parsed;
|
|
624
|
+
persist();
|
|
625
|
+
restartAutoplay();
|
|
626
|
+
});
|
|
627
|
+
return node;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function restartAutoplay(): void {
|
|
631
|
+
if (autoplayTimer !== undefined) window.clearInterval(autoplayTimer);
|
|
632
|
+
autoplayTimer = undefined;
|
|
633
|
+
if (state.autoplaySec <= 0) return;
|
|
634
|
+
autoplayTimer = window.setInterval(() => {
|
|
635
|
+
const next = host.current() + 1;
|
|
636
|
+
host.gotoSlide(next > host.slides.length ? 1 : next);
|
|
637
|
+
}, state.autoplaySec * 1000);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Effect refs for an export. A tuned effect must carry its `params`, and
|
|
642
|
+
* params alone (no checklist edit) still pin the composed list — the
|
|
643
|
+
* runtime keys edits by effect id, so the ids have to be written out.
|
|
644
|
+
*/
|
|
645
|
+
function effectRefs(
|
|
646
|
+
ids: string[] | undefined,
|
|
647
|
+
params: Record<string, Record<string, unknown>> | undefined,
|
|
648
|
+
): Array<Record<string, unknown>> | null {
|
|
649
|
+
const list = ids ?? (params ? Object.keys(params) : undefined);
|
|
650
|
+
if (!list) return null;
|
|
651
|
+
return list.map((id) => (params?.[id] ? { id, params: params[id] } : { id }));
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function buildPayload(): Record<string, unknown> {
|
|
655
|
+
const payload: Record<string, unknown> = {};
|
|
656
|
+
const deck = { ...state.deck };
|
|
657
|
+
const deckEffects = deck.effects as string[] | undefined;
|
|
658
|
+
const deckParams = deck.effectParams as Record<string, Record<string, unknown>> | undefined;
|
|
659
|
+
delete deck.effects;
|
|
660
|
+
delete deck.effectParams;
|
|
661
|
+
if (Object.keys(deck).length) payload.deck = deck;
|
|
662
|
+
const deckRefs = effectRefs(deckEffects, deckParams);
|
|
663
|
+
if (deckRefs) payload.effects = deckRefs;
|
|
664
|
+
|
|
665
|
+
const slides: Record<string, unknown> = {};
|
|
666
|
+
for (const [id, staged] of Object.entries(state.slides)) {
|
|
667
|
+
const entry = { ...staged } as Record<string, unknown>;
|
|
668
|
+
const effects = entry.effects as string[] | undefined;
|
|
669
|
+
const params = entry.effectParams as Record<string, Record<string, unknown>> | undefined;
|
|
670
|
+
delete entry.effects;
|
|
671
|
+
delete entry.effectParams;
|
|
672
|
+
const refs = effectRefs(effects, params);
|
|
673
|
+
if (refs) entry.effects = refs;
|
|
674
|
+
if (Object.keys(entry).length) slides[id] = entry;
|
|
675
|
+
}
|
|
676
|
+
if (Object.keys(slides).length) payload.slides = slides;
|
|
677
|
+
return payload;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function exportOverrides(): void {
|
|
681
|
+
const payload = buildPayload();
|
|
682
|
+
const text = `${JSON.stringify(payload, null, 2)}\n`;
|
|
683
|
+
|
|
684
|
+
// A blob download is silently DROPPED in a sandboxed iframe without
|
|
685
|
+
// `allow-downloads` (the dashboard's live-server viewer is one): no bar, no
|
|
686
|
+
// badge, no error. So the text is always surfaced in-panel as well, and the
|
|
687
|
+
// download is treated as the optimistic path rather than the only one.
|
|
688
|
+
try {
|
|
689
|
+
const blob = new Blob([text], { type: "application/json" });
|
|
690
|
+
const url = URL.createObjectURL(blob);
|
|
691
|
+
const a = el("a", { href: url, download: "overrides.json" });
|
|
692
|
+
document.body.appendChild(a);
|
|
693
|
+
a.click();
|
|
694
|
+
a.remove();
|
|
695
|
+
setTimeout(() => URL.revokeObjectURL(url), 10_000);
|
|
696
|
+
} catch {
|
|
697
|
+
// Ignored: the in-panel copy below is the guaranteed path.
|
|
698
|
+
}
|
|
699
|
+
showPayload(text);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Served by `deck3d serve`: the payload goes straight to disk over loopback,
|
|
704
|
+
* so the author never depends on a download the frame may drop.
|
|
705
|
+
*/
|
|
706
|
+
async function postPayload(route: string, button: HTMLButtonElement): Promise<void> {
|
|
707
|
+
const label = button.textContent ?? "";
|
|
708
|
+
try {
|
|
709
|
+
const res = await fetch(route, {
|
|
710
|
+
method: "POST",
|
|
711
|
+
headers: { "content-type": "application/json" },
|
|
712
|
+
body: JSON.stringify(buildPayload()),
|
|
713
|
+
});
|
|
714
|
+
const body = (await res.json()) as { ok?: boolean; wrote?: string; error?: string };
|
|
715
|
+
button.textContent = res.ok ? `Wrote ${body.wrote}` : "Rejected";
|
|
716
|
+
if (!res.ok) showMessage(body.error ?? "rejected");
|
|
717
|
+
} catch (err) {
|
|
718
|
+
button.textContent = "Failed";
|
|
719
|
+
showMessage((err as Error).message);
|
|
720
|
+
}
|
|
721
|
+
setTimeout(() => {
|
|
722
|
+
button.textContent = label;
|
|
723
|
+
}, 2000);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function showMessage(message: string): void {
|
|
727
|
+
document.getElementById("deck3d-hud-payload")?.remove();
|
|
728
|
+
const box = el("div", { id: "deck3d-hud-payload", class: "deck3d-hud-note" });
|
|
729
|
+
box.textContent = message;
|
|
730
|
+
body.appendChild(box);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/** Always-available fallback: the JSON, selectable, with a copy button. */
|
|
734
|
+
function showPayload(text: string): void {
|
|
735
|
+
document.getElementById("deck3d-hud-payload")?.remove();
|
|
736
|
+
const box = el("div", { id: "deck3d-hud-payload", class: "deck3d-hud-payload" });
|
|
737
|
+
const area = el("textarea", { readonly: "readonly", rows: "8", spellcheck: "false" }) as HTMLTextAreaElement;
|
|
738
|
+
area.value = text;
|
|
739
|
+
const copy = el("button", { type: "button" });
|
|
740
|
+
copy.textContent = "Copy";
|
|
741
|
+
copy.addEventListener("click", () => {
|
|
742
|
+
area.select();
|
|
743
|
+
const done = (ok: boolean): void => {
|
|
744
|
+
copy.textContent = ok ? "Copied" : "Press ⌘C";
|
|
745
|
+
setTimeout(() => {
|
|
746
|
+
copy.textContent = "Copy";
|
|
747
|
+
}, 1500);
|
|
748
|
+
};
|
|
749
|
+
// `navigator.clipboard` needs a secure context AND is blocked in an
|
|
750
|
+
// opaque-origin frame; `execCommand` still works there.
|
|
751
|
+
navigator.clipboard?.writeText(text).then(
|
|
752
|
+
() => done(true),
|
|
753
|
+
() => done(document.execCommand("copy")),
|
|
754
|
+
) ?? done(document.execCommand("copy"));
|
|
755
|
+
});
|
|
756
|
+
const hint = el("div", { class: "deck3d-hud-note" });
|
|
757
|
+
hint.textContent = "Save as overrides.json, then: deck3d overrides apply deck.json overrides.json";
|
|
758
|
+
box.append(area, copy, hint);
|
|
759
|
+
body.appendChild(box);
|
|
760
|
+
area.focus();
|
|
761
|
+
area.select();
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function render(): void {
|
|
765
|
+
body.replaceChildren();
|
|
766
|
+
const index = host.current();
|
|
767
|
+
const slideId = host.slides[index - 1]?.id ?? "";
|
|
768
|
+
|
|
769
|
+
const counter = el("div", { id: "deck3d-hud-counter" });
|
|
770
|
+
counter.textContent = `${index} / ${host.slides.length}`;
|
|
771
|
+
body.appendChild(counter);
|
|
772
|
+
|
|
773
|
+
const scopes = el("div", { class: "deck3d-hud-scopes" });
|
|
774
|
+
for (const s of ["deck", "slide"] as const) {
|
|
775
|
+
const button = el("button", { type: "button", "data-scope": s });
|
|
776
|
+
button.textContent = s === "deck" ? "Deck" : "This slide";
|
|
777
|
+
button.className = scope === s ? "active" : "";
|
|
778
|
+
button.addEventListener("click", () => {
|
|
779
|
+
scope = s;
|
|
780
|
+
render();
|
|
781
|
+
});
|
|
782
|
+
scopes.appendChild(button);
|
|
783
|
+
}
|
|
784
|
+
body.appendChild(scopes);
|
|
785
|
+
|
|
786
|
+
for (const block of BLOCKS) {
|
|
787
|
+
const node = renderBlock(block, slideId);
|
|
788
|
+
if (node) body.appendChild(node);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// Under `deck3d serve` the panel writes to disk; standalone it can only
|
|
792
|
+
// hand the author the text.
|
|
793
|
+
const served = (window as { __deck3dServe?: boolean }).__deck3dServe === true;
|
|
794
|
+
|
|
795
|
+
// `serve --check` pushes findings out of band; show this slide's.
|
|
796
|
+
const findings = ((window as { __deck3dFindings?: Record<string, string[]> }).__deck3dFindings ?? {})[slideId] ?? [];
|
|
797
|
+
if (findings.length) {
|
|
798
|
+
const box = el("div", { id: "deck3d-hud-findings", class: "deck3d-hud-note" });
|
|
799
|
+
box.textContent = `check: ${findings.join(" · ")}`;
|
|
800
|
+
body.appendChild(box);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
const notice = el("div", { class: "deck3d-hud-note" });
|
|
804
|
+
notice.textContent = served
|
|
805
|
+
? "Save writes overrides.json beside the deck. Apply merges into deck.json and rebuilds. Markdown inline overrides win over the file, and a saved effects list pins that scope's effects."
|
|
806
|
+
: "Tuning here is remembered in this browser only. Export writes overrides.json; make it permanent with `deck3d overrides apply deck.json overrides.json`, then rebuild. Markdown inline overrides win over this file, and an exported effects list pins that scope's effects.";
|
|
807
|
+
body.appendChild(notice);
|
|
808
|
+
|
|
809
|
+
if (served) {
|
|
810
|
+
const save = el("button", { type: "button", id: "deck3d-hud-save" });
|
|
811
|
+
save.textContent = "Save overrides.json";
|
|
812
|
+
save.addEventListener("click", () => void postPayload("/__overrides", save));
|
|
813
|
+
body.appendChild(save);
|
|
814
|
+
|
|
815
|
+
const apply = el("button", { type: "button", id: "deck3d-hud-apply" });
|
|
816
|
+
apply.textContent = "Apply to deck.json";
|
|
817
|
+
apply.addEventListener("click", () => void postPayload("/__apply", apply));
|
|
818
|
+
body.appendChild(apply);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
const exportButton = el("button", { type: "button", id: "deck3d-hud-export" });
|
|
822
|
+
exportButton.textContent = "Export overrides.json";
|
|
823
|
+
exportButton.addEventListener("click", exportOverrides);
|
|
824
|
+
body.appendChild(exportButton);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
function setOpen(next: boolean): void {
|
|
828
|
+
open = next;
|
|
829
|
+
root.style.display = open ? "block" : "none";
|
|
830
|
+
if (open) render();
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
gear.addEventListener("click", (e) => {
|
|
834
|
+
e.stopPropagation();
|
|
835
|
+
setOpen(!open);
|
|
836
|
+
});
|
|
837
|
+
root.addEventListener("click", (e) => e.stopPropagation());
|
|
838
|
+
root.addEventListener("pointerup", (e) => e.stopPropagation());
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Persisted state was restored into the CONTROLS only, so a reload showed the
|
|
842
|
+
* panel reading e.g. "blackbelt" over a scene rendering the deck default.
|
|
843
|
+
* Replay it into the scene too, once, at boot.
|
|
844
|
+
*/
|
|
845
|
+
function restoreToScene(): void {
|
|
846
|
+
const slideIds = host.slides.map((s) => s.id);
|
|
847
|
+
let staged = Object.keys(state.deck).length > 0;
|
|
848
|
+
for (const id of slideIds) {
|
|
849
|
+
const entry = state.slides[id] as Record<string, unknown> | undefined;
|
|
850
|
+
if (entry && Object.keys(entry).length) staged = true;
|
|
851
|
+
}
|
|
852
|
+
if (!staged) return;
|
|
853
|
+
|
|
854
|
+
// Seed effect params first: `applyDeck` rebuilds slides, and the factories
|
|
855
|
+
// read the staged params during that rebuild.
|
|
856
|
+
const seed = (slideId: string, bucket: Record<string, unknown> | undefined): void => {
|
|
857
|
+
const params = bucket?.effectParams as Record<string, Record<string, unknown>> | undefined;
|
|
858
|
+
for (const [effectId, patch] of Object.entries(params ?? {})) host.seedEffectParams(slideId, effectId, patch);
|
|
859
|
+
};
|
|
860
|
+
for (const id of slideIds) {
|
|
861
|
+
seed(id, state.deck as Record<string, unknown>);
|
|
862
|
+
seed(id, state.slides[id] as Record<string, unknown> | undefined);
|
|
863
|
+
}
|
|
864
|
+
host.applyDeck((id) => ({ ...(state.deck as SlidePatch), ...(state.slides[id] as SlidePatch | undefined) }));
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// Findings arrive after the reload, by contract — repaint when they land.
|
|
868
|
+
window.addEventListener("deck3d-findings", () => {
|
|
869
|
+
if (open) render();
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
setOpen(false);
|
|
873
|
+
restoreToScene();
|
|
874
|
+
restartAutoplay();
|
|
875
|
+
|
|
876
|
+
return {
|
|
877
|
+
toggle: () => setOpen(!open),
|
|
878
|
+
close: () => setOpen(false),
|
|
879
|
+
isOpen: () => open,
|
|
880
|
+
hasFocus: () => root.contains(document.activeElement),
|
|
881
|
+
contains: (target) => target instanceof Node && (root.contains(target) || gear.contains(target)),
|
|
882
|
+
refresh: () => {
|
|
883
|
+
if (open) render();
|
|
884
|
+
},
|
|
885
|
+
state: () => state,
|
|
886
|
+
};
|
|
887
|
+
}
|