@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,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `check` rules — pure functions over `__deck3d.measure()` output (design D8).
|
|
3
|
+
*
|
|
4
|
+
* Geometric rules (fit/legibility/overlap/occlusion) are exact for a given IR +
|
|
5
|
+
* viewport; contrast needs rendered pixels and is warn-only (GPU-dependent), so
|
|
6
|
+
* it is excluded from the report byte-equality guarantee.
|
|
7
|
+
*/
|
|
8
|
+
export type Severity = "error" | "warn";
|
|
9
|
+
export type RuleName =
|
|
10
|
+
| "fit"
|
|
11
|
+
| "legibility"
|
|
12
|
+
| "overlap"
|
|
13
|
+
| "occlusion"
|
|
14
|
+
| "contrast"
|
|
15
|
+
| "skipped"
|
|
16
|
+
| "budget"
|
|
17
|
+
| "local-fx-error"
|
|
18
|
+
| "fx-content-layer"
|
|
19
|
+
| "local-fx-network"
|
|
20
|
+
| "style-defaults";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Rules whose presence depends on rendered pixels or on request timing, so
|
|
24
|
+
* they are excluded from the report byte-equality guarantee. Severity is
|
|
25
|
+
* unaffected — a `local-fx-network` finding still fails the deck.
|
|
26
|
+
*/
|
|
27
|
+
export const NON_DETERMINISTIC_RULES: readonly RuleName[] = ["contrast", "local-fx-network"];
|
|
28
|
+
|
|
29
|
+
export interface Rect {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
w: number;
|
|
33
|
+
h: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Measurement {
|
|
37
|
+
kind: string;
|
|
38
|
+
id: string;
|
|
39
|
+
text: string;
|
|
40
|
+
rect: Rect;
|
|
41
|
+
capHeight: number;
|
|
42
|
+
/** Owner id of the first raycast hit between camera and label centre. */
|
|
43
|
+
hit?: string | null;
|
|
44
|
+
/** Label fill colour (canvas labels only). */
|
|
45
|
+
color?: string | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface SlideRef {
|
|
49
|
+
id: string;
|
|
50
|
+
index: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface Finding {
|
|
54
|
+
severity: Severity;
|
|
55
|
+
rule: RuleName;
|
|
56
|
+
slide: string;
|
|
57
|
+
slideIndex: number;
|
|
58
|
+
id?: string;
|
|
59
|
+
text?: string;
|
|
60
|
+
/** `local-fx-error` only: the failing effect reference. */
|
|
61
|
+
effectId?: string;
|
|
62
|
+
/** `local-fx-error` only: which entry point threw. */
|
|
63
|
+
phase?: "create" | "tick" | "dispose";
|
|
64
|
+
/** `local-fx-network` only: the host the deck tried to reach. */
|
|
65
|
+
host?: string;
|
|
66
|
+
/** Human-measured value, e.g. `1844px`. */
|
|
67
|
+
measured: string;
|
|
68
|
+
/** Human threshold, e.g. `1843px`. */
|
|
69
|
+
threshold: string;
|
|
70
|
+
/** One-line detail, e.g. `right 1844px > 1843px`. */
|
|
71
|
+
detail: string;
|
|
72
|
+
/** Suggested `overrides` key (must resolve in schema.json). */
|
|
73
|
+
suggest: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const px = (n: number): string => `${Math.round(n)}px`;
|
|
77
|
+
|
|
78
|
+
function isText(m: Measurement): boolean {
|
|
79
|
+
return (m.kind === "label" || m.kind === "title") && m.text.length > 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Overrides grammar key for a slide-level knob. */
|
|
83
|
+
export function slideKnob(slideId: string, knob: string): string {
|
|
84
|
+
return `overrides.slides["${slideId}"].${knob}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function nodeKnob(slideId: string, nodeId: string, knob: string): string {
|
|
88
|
+
return `overrides.nodes["${slideId}/${nodeId}"].${knob}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Union of all content rects inside the safe area (default 4 % margin). */
|
|
92
|
+
export function fitFindings(measurements: Measurement[], viewport: { w: number; h: number }, slide: SlideRef, margin = 0.04): Finding[] {
|
|
93
|
+
const usable = measurements.filter(
|
|
94
|
+
(m) => m.rect.w > 0 && m.rect.h > 0 && Number.isFinite(m.rect.x) && Number.isFinite(m.rect.y) && Number.isFinite(m.rect.w) && Number.isFinite(m.rect.h),
|
|
95
|
+
);
|
|
96
|
+
if (!usable.length) return [];
|
|
97
|
+
const left = viewport.w * margin;
|
|
98
|
+
const right = viewport.w * (1 - margin);
|
|
99
|
+
const top = viewport.h * margin;
|
|
100
|
+
const bottom = viewport.h * (1 - margin);
|
|
101
|
+
const minX = Math.min(...usable.map((m) => m.rect.x));
|
|
102
|
+
const maxX = Math.max(...usable.map((m) => m.rect.x + m.rect.w));
|
|
103
|
+
const minY = Math.min(...usable.map((m) => m.rect.y));
|
|
104
|
+
const maxY = Math.max(...usable.map((m) => m.rect.y + m.rect.h));
|
|
105
|
+
const out: Finding[] = [];
|
|
106
|
+
const add = (detail: string, measured: number, threshold: number): void => {
|
|
107
|
+
out.push({
|
|
108
|
+
severity: "error",
|
|
109
|
+
rule: "fit",
|
|
110
|
+
slide: slide.id,
|
|
111
|
+
slideIndex: slide.index,
|
|
112
|
+
measured: px(measured),
|
|
113
|
+
threshold: px(threshold),
|
|
114
|
+
detail,
|
|
115
|
+
suggest: slideKnob(slide.id, "diagram.scale"),
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
if (minX < left) add(`left ${px(minX)} < ${px(left)}`, minX, left);
|
|
119
|
+
if (maxX > right) add(`right ${px(maxX)} > ${px(right)}`, maxX, right);
|
|
120
|
+
if (minY < top) add(`top ${px(minY)} < ${px(top)}`, minY, top);
|
|
121
|
+
if (maxY > bottom) add(`bottom ${px(maxY)} > ${px(bottom)}`, maxY, bottom);
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Every label cap height ≥ `minPx` scaled by viewport height (14 px at 1080). */
|
|
126
|
+
export function legibilityFindings(measurements: Measurement[], viewportH: number, slide: SlideRef, minPx = 14): Finding[] {
|
|
127
|
+
const threshold = (minPx * viewportH) / 1080;
|
|
128
|
+
return measurements
|
|
129
|
+
.filter((m) => isText(m) && m.capHeight < threshold)
|
|
130
|
+
.map((m) => ({
|
|
131
|
+
severity: "warn" as const,
|
|
132
|
+
rule: "legibility" as const,
|
|
133
|
+
slide: slide.id,
|
|
134
|
+
slideIndex: slide.index,
|
|
135
|
+
id: m.id,
|
|
136
|
+
text: m.text,
|
|
137
|
+
measured: `${m.capHeight.toFixed(2)}px`,
|
|
138
|
+
threshold: `${threshold.toFixed(2)}px`,
|
|
139
|
+
detail: `${m.capHeight.toFixed(2)}px < ${threshold.toFixed(2)}px`,
|
|
140
|
+
suggest: slideKnob(slide.id, "labels.size"),
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function iou(a: Rect, b: Rect): number {
|
|
145
|
+
const x1 = Math.max(a.x, b.x);
|
|
146
|
+
const y1 = Math.max(a.y, b.y);
|
|
147
|
+
const x2 = Math.min(a.x + a.w, b.x + b.w);
|
|
148
|
+
const y2 = Math.min(a.y + a.h, b.y + b.h);
|
|
149
|
+
const inter = Math.max(0, x2 - x1) * Math.max(0, y2 - y1);
|
|
150
|
+
const union = a.w * a.h + b.w * b.h - inter;
|
|
151
|
+
return union <= 0 ? 0 : inter / union;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** No two label rects intersect with IoU strictly above `maxIou`. */
|
|
155
|
+
export function overlapFindings(measurements: Measurement[], slide: SlideRef, maxIou = 0.1): Finding[] {
|
|
156
|
+
const labels = measurements.filter(isText);
|
|
157
|
+
const out: Finding[] = [];
|
|
158
|
+
for (let i = 0; i < labels.length; i++) {
|
|
159
|
+
for (let j = i + 1; j < labels.length; j++) {
|
|
160
|
+
const value = iou(labels[i].rect, labels[j].rect);
|
|
161
|
+
if (value <= maxIou + 1e-9) continue;
|
|
162
|
+
out.push({
|
|
163
|
+
severity: "error",
|
|
164
|
+
rule: "overlap",
|
|
165
|
+
slide: slide.id,
|
|
166
|
+
slideIndex: slide.index,
|
|
167
|
+
id: labels[i].id,
|
|
168
|
+
text: `${labels[i].id} ∩ ${labels[j].id}`,
|
|
169
|
+
measured: value.toFixed(3),
|
|
170
|
+
threshold: maxIou.toFixed(1),
|
|
171
|
+
detail: `overlap ${labels[i].id} ∩ ${labels[j].id} IoU ${value.toFixed(3)} > ${maxIou}`,
|
|
172
|
+
suggest: nodeKnob(slide.id, labels[i].id, "position"),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** No label may be occluded by an object other than itself or its own node. */
|
|
180
|
+
export function occlusionFindings(measurements: Measurement[], slide: SlideRef): Finding[] {
|
|
181
|
+
return measurements
|
|
182
|
+
.filter((m) => isText(m) && m.hit != null && m.hit !== m.id)
|
|
183
|
+
.map((m) => ({
|
|
184
|
+
severity: "error" as const,
|
|
185
|
+
rule: "occlusion" as const,
|
|
186
|
+
slide: slide.id,
|
|
187
|
+
slideIndex: slide.index,
|
|
188
|
+
id: m.id,
|
|
189
|
+
text: m.text,
|
|
190
|
+
measured: String(m.hit),
|
|
191
|
+
threshold: m.id,
|
|
192
|
+
detail: `label ${m.id} occluded by ${m.hit}`,
|
|
193
|
+
suggest: slideKnob(slide.id, "camera.distance"),
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** WCAG relative luminance of a `#rrggbb` colour. */
|
|
198
|
+
export function luminanceFromHex(hex: string): number {
|
|
199
|
+
const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
|
|
200
|
+
if (!m) return 0;
|
|
201
|
+
const n = Number.parseInt(m[1], 16);
|
|
202
|
+
const channel = (v: number): number => {
|
|
203
|
+
const s = v / 255;
|
|
204
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
205
|
+
};
|
|
206
|
+
return 0.2126 * channel((n >> 16) & 0xff) + 0.7152 * channel((n >> 8) & 0xff) + 0.0722 * channel(n & 0xff);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function contrastRatio(a: number, b: number): number {
|
|
210
|
+
const hi = Math.max(a, b);
|
|
211
|
+
const lo = Math.min(a, b);
|
|
212
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Contrast of label text vs the mean luminance of the pixels behind it. */
|
|
216
|
+
export function contrastFindings(
|
|
217
|
+
measurements: Array<Measurement & { bgLuminance?: number }>,
|
|
218
|
+
slide: SlideRef,
|
|
219
|
+
min = 3,
|
|
220
|
+
): Finding[] {
|
|
221
|
+
return measurements
|
|
222
|
+
.filter((m): m is Measurement & { bgLuminance: number } => isText(m) && Boolean(m.color) && m.bgLuminance != null)
|
|
223
|
+
.map((m) => ({ m, ratio: contrastRatio(luminanceFromHex(m.color as string), m.bgLuminance) }))
|
|
224
|
+
.filter(({ ratio }) => ratio < min)
|
|
225
|
+
.map(({ m, ratio }) => ({
|
|
226
|
+
severity: "warn" as const,
|
|
227
|
+
rule: "contrast" as const,
|
|
228
|
+
slide: slide.id,
|
|
229
|
+
slideIndex: slide.index,
|
|
230
|
+
id: m.id,
|
|
231
|
+
text: m.text,
|
|
232
|
+
measured: ratio.toFixed(1),
|
|
233
|
+
threshold: min.toFixed(1),
|
|
234
|
+
detail: `contrast ${ratio.toFixed(1)}:1 < ${min}:1`,
|
|
235
|
+
suggest: slideKnob(slide.id, "mode"),
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function formatFinding(f: Finding): string {
|
|
240
|
+
return `${f.severity} ${f.rule} slide ${f.slideIndex} ${f.detail}`;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Mode-incompatible / skipped effects become warn findings in the report. */
|
|
244
|
+
export function skippedFindings(skipped: string[], slide: SlideRef): Finding[] {
|
|
245
|
+
return skipped.map((entry) => ({
|
|
246
|
+
severity: "warn" as const,
|
|
247
|
+
rule: "skipped" as const,
|
|
248
|
+
slide: slide.id,
|
|
249
|
+
slideIndex: slide.index,
|
|
250
|
+
measured: entry.split(":")[0],
|
|
251
|
+
threshold: "mode",
|
|
252
|
+
detail: `skipped ${entry}`,
|
|
253
|
+
suggest: slideKnob(slide.id, "mode"),
|
|
254
|
+
}));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Summed effect cost vs the quality-tier budget, reported by the runtime. */
|
|
258
|
+
export interface BudgetInfo {
|
|
259
|
+
sum: number;
|
|
260
|
+
limit: number;
|
|
261
|
+
/** Present when over budget: the render CLI's exact `warn budget …` line. */
|
|
262
|
+
warning?: string;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Over-budget effects become a warn finding (`warn budget slide <n> <sum> > <budget>`). */
|
|
266
|
+
export function budgetFindings(budget: BudgetInfo | undefined | null, slide: SlideRef): Finding[] {
|
|
267
|
+
if (!budget || budget.sum <= budget.limit) return [];
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
severity: "warn" as const,
|
|
271
|
+
rule: "budget" as const,
|
|
272
|
+
slide: slide.id,
|
|
273
|
+
slideIndex: slide.index,
|
|
274
|
+
measured: String(budget.sum),
|
|
275
|
+
threshold: String(budget.limit),
|
|
276
|
+
detail: `${budget.sum} > ${budget.limit}`,
|
|
277
|
+
suggest: slideKnob(slide.id, "quality"),
|
|
278
|
+
},
|
|
279
|
+
];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Drop findings a slide's merged `check.ignore` suppresses: an entry matches
|
|
284
|
+
* either the finding's `rule` (e.g. `contrast`) or its object `id`.
|
|
285
|
+
*/
|
|
286
|
+
export function filterIgnored(findings: Finding[], ignore: string[] | undefined): Finding[] {
|
|
287
|
+
if (!ignore?.length) return findings;
|
|
288
|
+
return findings.filter((f) => !(ignore.includes(f.rule) || (f.id != null && ignore.includes(f.id))));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** A local effect that threw. No message text: the report must stay byte-stable. */
|
|
292
|
+
export function localFxErrorFindings(
|
|
293
|
+
errors: Array<{ slide: string; effectId: string; phase: "create" | "tick" | "dispose" }>,
|
|
294
|
+
slide: SlideRef,
|
|
295
|
+
): Finding[] {
|
|
296
|
+
return errors
|
|
297
|
+
.filter((e) => e.slide === slide.id)
|
|
298
|
+
.map((e) => ({
|
|
299
|
+
severity: "error" as const,
|
|
300
|
+
rule: "local-fx-error" as const,
|
|
301
|
+
slide: slide.id,
|
|
302
|
+
slideIndex: slide.index,
|
|
303
|
+
effectId: e.effectId,
|
|
304
|
+
phase: e.phase,
|
|
305
|
+
measured: e.phase,
|
|
306
|
+
threshold: "no throw",
|
|
307
|
+
detail: `${e.effectId} threw in ${e.phase}`,
|
|
308
|
+
suggest: slideKnob(slide.id, "effects"),
|
|
309
|
+
}));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* A backdrop object that escaped onto the content layer. Backgrounds and
|
|
314
|
+
* `local:` effects render in a depth-isolated pass behind the slide, so they
|
|
315
|
+
* cannot cover the text — unless a module `add()`s children after creation,
|
|
316
|
+
* which lands them on the content layer. Those children CAN slice the card.
|
|
317
|
+
*/
|
|
318
|
+
export function backdropLeakFindings(leaks: string[], slide: SlideRef): Finding[] {
|
|
319
|
+
return [...leaks].sort().map((effectId) => ({
|
|
320
|
+
severity: "error" as const,
|
|
321
|
+
rule: "fx-content-layer" as const,
|
|
322
|
+
slide: slide.id,
|
|
323
|
+
slideIndex: slide.index,
|
|
324
|
+
effectId,
|
|
325
|
+
measured: "content layer",
|
|
326
|
+
threshold: "backdrop layer",
|
|
327
|
+
detail: `${effectId} put geometry on the content layer; it can cover slide text`,
|
|
328
|
+
suggest: slideKnob(slide.id, "effects"),
|
|
329
|
+
}));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* A request the deck attempted to a non-local scheme. Slide-level (no per-effect
|
|
334
|
+
* attribution): `check` knows which slide it was measuring, not which effect
|
|
335
|
+
* asked. Deduplicated and sorted so the list is stable for a given run.
|
|
336
|
+
*/
|
|
337
|
+
export function localFxNetworkFindings(hits: Array<{ slide: string; host: string }>, slides: SlideRef[]): Finding[] {
|
|
338
|
+
const index = new Map(slides.map((s) => [s.id, s.index]));
|
|
339
|
+
const unique = [...new Map(hits.map((h) => [`${h.slide}\u0000${h.host}`, h])).values()].sort(
|
|
340
|
+
(a, b) => a.slide.localeCompare(b.slide) || a.host.localeCompare(b.host),
|
|
341
|
+
);
|
|
342
|
+
return unique.map((h) => ({
|
|
343
|
+
severity: "error" as const,
|
|
344
|
+
rule: "local-fx-network" as const,
|
|
345
|
+
slide: h.slide,
|
|
346
|
+
slideIndex: index.get(h.slide) ?? 0,
|
|
347
|
+
host: h.host,
|
|
348
|
+
measured: h.host,
|
|
349
|
+
threshold: "no network",
|
|
350
|
+
detail: `deck requested ${h.host} (decks must open offline)`,
|
|
351
|
+
suggest: slideKnob(h.slide, "effects"),
|
|
352
|
+
}));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** Enough of a merged slide to decide whether it is still on parse defaults. */
|
|
356
|
+
export interface StyleSlide {
|
|
357
|
+
id: string;
|
|
358
|
+
title: string;
|
|
359
|
+
bullets: string[];
|
|
360
|
+
diagram: { kind: string };
|
|
361
|
+
effects?: Array<{ id: string }>;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* `style-defaults` (D7): the slide runs exactly what `parse` chose — default
|
|
366
|
+
* effects, the default diagram kind, and no prop aimed at it. A `check: clean`
|
|
367
|
+
* deck can still be visually bare; this is what surfaces that.
|
|
368
|
+
*/
|
|
369
|
+
export function styleFindings(
|
|
370
|
+
slides: StyleSlide[],
|
|
371
|
+
propSlides: ReadonlySet<string>,
|
|
372
|
+
defaults: (slide: StyleSlide) => string[],
|
|
373
|
+
derivedKind: (slide: StyleSlide) => string,
|
|
374
|
+
): Finding[] {
|
|
375
|
+
return slides.flatMap((slide, i) => {
|
|
376
|
+
const effects = (slide.effects ?? []).map((e) => e.id);
|
|
377
|
+
const onDefaultEffects = effects.join("\u0000") === defaults(slide).join("\u0000");
|
|
378
|
+
const onDefaultKind = slide.diagram.kind === derivedKind(slide);
|
|
379
|
+
if (!onDefaultEffects || !onDefaultKind || propSlides.has(slide.id)) return [];
|
|
380
|
+
return [
|
|
381
|
+
{
|
|
382
|
+
severity: "warn" as const,
|
|
383
|
+
rule: "style-defaults" as const,
|
|
384
|
+
slide: slide.id,
|
|
385
|
+
slideIndex: i + 1,
|
|
386
|
+
measured: "parse defaults",
|
|
387
|
+
threshold: "an authored choice",
|
|
388
|
+
detail: `slide ${slide.id} runs only parse defaults (effects ${effects.join(", ") || "none"}, diagram ${slide.diagram.kind})`,
|
|
389
|
+
suggest: slideKnob(slide.id, "effects"),
|
|
390
|
+
},
|
|
391
|
+
];
|
|
392
|
+
});
|
|
393
|
+
}
|
package/src/cli-io.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's I/O seam, in its own module so other modules can depend on the
|
|
3
|
+
* TYPES without depending on `cli.ts` itself.
|
|
4
|
+
*
|
|
5
|
+
* This exists to break a real import cycle, not to satisfy a linter: `cli.ts`
|
|
6
|
+
* loads `serve/index.ts` to run the `serve` command, and `serve` used to import
|
|
7
|
+
* `run` straight back from `cli.ts`. When `cli.ts` was the process ENTRY its
|
|
8
|
+
* top-level `await run(...)` was still pending, so the cycle's dynamic import
|
|
9
|
+
* could never resolve and the process exited 13 ("unsettled top-level await").
|
|
10
|
+
* See `serve/__tests__/serve.test.ts` #S10, which pins that behaviour.
|
|
11
|
+
*
|
|
12
|
+
* Dependencies point one way now: `cli.ts` → `serve/index.ts` → `cli-io.ts`.
|
|
13
|
+
* `serve` receives the runner it needs through `ServeOptions.run`.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Where a command writes its output. Tests substitute collectors for both. */
|
|
17
|
+
export interface CliIO {
|
|
18
|
+
stdout: (line: string) => void;
|
|
19
|
+
stderr: (line: string) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The CLI entry point's shape: argv (without node/script) → exit code. */
|
|
23
|
+
export type CliRun = (argv: string[], io: CliIO) => Promise<number>;
|