@anvpx/motion-build 0.1.56 → 0.1.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/audio/mix.d.ts +29 -11
  2. package/dist/audio/mix.js +79 -17
  3. package/dist/build.d.ts +15 -1
  4. package/dist/build.js +85 -16
  5. package/dist/emit/boot.d.ts +17 -2
  6. package/dist/emit/boot.js +31 -4
  7. package/dist/emit/boot.template.js +4 -4
  8. package/dist/emit/index-html.js +3 -0
  9. package/dist/emit/interaction-runtime.d.ts +11 -0
  10. package/dist/emit/interaction-runtime.js +121 -0
  11. package/dist/emit/vendor.d.ts +23 -0
  12. package/dist/emit/vendor.js +12 -5
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.js +2 -0
  15. package/dist/lint/beat-variety.d.ts +17 -0
  16. package/dist/lint/beat-variety.js +92 -0
  17. package/dist/lint/custom-source.d.ts +6 -0
  18. package/dist/lint/custom-source.js +201 -6
  19. package/dist/lint/index.d.ts +4 -1
  20. package/dist/lint/index.js +9 -1
  21. package/dist/lint/visual-variety.d.ts +16 -0
  22. package/dist/lint/visual-variety.js +72 -0
  23. package/dist/lint/world-stops.d.ts +11 -0
  24. package/dist/lint/world-stops.js +39 -0
  25. package/dist/templates/catalog-quality.d.ts +70 -0
  26. package/dist/templates/catalog-quality.js +221 -0
  27. package/dist/templates/index.d.ts +2 -1
  28. package/dist/templates/index.js +2 -1
  29. package/dist/templates/search.d.ts +11 -0
  30. package/dist/templates/search.js +12 -0
  31. package/dist/templates/validate.d.ts +2 -1
  32. package/dist/templates/validate.js +6 -23
  33. package/dist/validate-full.js +38 -45
  34. package/dist/validate-interaction.d.ts +7 -0
  35. package/dist/validate-interaction.js +32 -0
  36. package/dist/video/grain.d.ts +47 -0
  37. package/dist/video/grain.js +121 -0
  38. package/package.json +4 -4
@@ -0,0 +1,121 @@
1
+ /**
2
+ * ADR-0013 runtime, emitted into boot.js only for `mk publish --interactive`.
3
+ *
4
+ * It is the schema's `stateAt` reducer as shipped to the browser: same total order, same
5
+ * transitions, same clamp. `boot.interaction.test.ts` pins this copy to
6
+ * `@anvpx/motion-schema` over every action, a permuted transcript and a grid of film times,
7
+ * so the live page and the rendered film cannot fold differently. It is a TypeScript module
8
+ * (not an asset) so `tsc -b` emits it into `dist` with boot.js — no runtime file to copy, no
9
+ * path that can go missing. No clock, randomness, DOM or pointer input.
10
+ */
11
+ export const INTERACTION_RUNTIME = `const MK_ACTIONS = [
12
+ "hover",
13
+ "press",
14
+ "release",
15
+ "click",
16
+ "type",
17
+ "focus",
18
+ "blur",
19
+ "scroll",
20
+ "advance",
21
+ ];
22
+
23
+ /** The wrapper's transcript in the schema's total order; one container, never rebound. */
24
+ const interactionState = {
25
+ events: [],
26
+ memo: { t: null, state: new Map() },
27
+ };
28
+
29
+ const interactionCompare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
30
+
31
+ const interactionCompareValue = (a, b) =>
32
+ a === b ? 0 : a === null ? -1 : b === null ? 1 : interactionCompare(a, b);
33
+
34
+ const interactionByEvent = (a, b) =>
35
+ interactionCompare(a.at, b.at) ||
36
+ interactionCompare(a.scene, b.scene) ||
37
+ interactionCompare(a.target, b.target) ||
38
+ interactionCompare(MK_ACTIONS.indexOf(a.action), MK_ACTIONS.indexOf(b.action)) ||
39
+ interactionCompareValue(a.value, b.value);
40
+
41
+ const interactionEmpty = () => ({
42
+ pressed: false,
43
+ hovered: false,
44
+ focused: false,
45
+ typed: null,
46
+ scroll: 0,
47
+ activations: 0,
48
+ });
49
+
50
+ const interactionScroll = (value) => {
51
+ const parsed = Number(value);
52
+ return Number.isFinite(parsed) ? Math.min(1, Math.max(0, parsed)) : 0;
53
+ };
54
+
55
+ /** One event onto one target's state; \`advance\` is transport and leaves the target alone. */
56
+ const interactionNext = (state, action, value) => {
57
+ if (action === "hover") return Object.assign({}, state, { hovered: true });
58
+ if (action === "press") return Object.assign({}, state, { pressed: true });
59
+ if (action === "release") return Object.assign({}, state, { pressed: false });
60
+ if (action === "click") return Object.assign({}, state, { activations: state.activations + 1 });
61
+ if (action === "type") return Object.assign({}, state, { typed: value });
62
+ if (action === "focus") return Object.assign({}, state, { focused: true });
63
+ if (action === "blur") return Object.assign({}, state, { focused: false });
64
+ if (action === "scroll") return Object.assign({}, state, { scroll: interactionScroll(value) });
65
+ return state;
66
+ };
67
+
68
+ /** \`stateAt\` for the live page: every event with \`at <= t\`, keyed \`"<scene>:<target>"\`. */
69
+ const interactionAt = (t) => {
70
+ if (interactionState.memo.t === t) return interactionState.memo.state;
71
+ const state = new Map();
72
+ for (const event of interactionState.events) {
73
+ if (!(event.at <= t)) continue;
74
+ const key = event.scene + ":" + event.target;
75
+ state.set(
76
+ key,
77
+ interactionNext(state.get(key) || interactionEmpty(), event.action, event.value),
78
+ );
79
+ }
80
+ interactionState.memo = { t, state };
81
+ return state;
82
+ };
83
+
84
+ /** The wrapper posts the whole transcript with input; sort once per change, not per seek. */
85
+ const setInteractionTranscript = (events) => {
86
+ interactionState.events = events.slice().sort(interactionByEvent);
87
+ interactionState.memo = { t: null, state: new Map() };
88
+ };
89
+
90
+ /**
91
+ * Paints the folded state onto one scene's declared targets. The scene emits a
92
+ * [data-mk-target] mark only when its props declare that id, so a board without targets
93
+ * has no elements to address. Film time is the caller's absolute t; the key is
94
+ * "<scene>:<target>", the same key the reducer stores.
95
+ */
96
+ const interactionApplyTargets = (root, sceneId, t) => {
97
+ if (!root || typeof root.querySelectorAll !== "function") return;
98
+ const state = interactionAt(t);
99
+ for (const el of root.querySelectorAll("[data-mk-target]")) {
100
+ const target = state.get(sceneId + ":" + el.getAttribute("data-mk-target"));
101
+ const flag = (name, on) => {
102
+ if (on) el.setAttribute("data-mk-" + name, "");
103
+ else el.removeAttribute("data-mk-" + name);
104
+ };
105
+ flag("pressed", target ? target.pressed : false);
106
+ flag("hovered", target ? target.hovered : false);
107
+ flag("focused", target ? target.focused : false);
108
+ if (target && target.typed !== null) el.setAttribute("data-mk-typed", target.typed);
109
+ else el.removeAttribute("data-mk-typed");
110
+ const scroll = target ? target.scroll : 0;
111
+ el.setAttribute("data-mk-scroll", String(scroll));
112
+ el.setAttribute("data-mk-activations", String(target ? target.activations : 0));
113
+ if (el.style && typeof el.style.setProperty === "function") {
114
+ el.style.setProperty("--mk-target-scroll", String(scroll));
115
+ }
116
+ const slot =
117
+ typeof el.querySelector === "function" ? el.querySelector("[data-mk-typed-slot]") : null;
118
+ if (slot) slot.textContent = target && target.typed !== null ? target.typed : "";
119
+ }
120
+ };
121
+ `;
@@ -1,4 +1,27 @@
1
1
  import type { VendorLib } from "@anvpx/motion-schema";
2
+ /**
3
+ * A browser library copied verbatim into the emitted project (ADR-0006). No bundler, no CDN: the
4
+ * package's own ESM entry is written under `vendor/` and an import map points the bare specifier at
5
+ * it, so `import ... from "three"` in a scene script resolves offline under `script-src 'self'`.
6
+ */
7
+ export interface VendorSpec {
8
+ /** The bare specifier a scene script writes. */
9
+ readonly specifier: VendorLib;
10
+ /** Package name resolved from this module; its directory is where the files are read. */
11
+ readonly pkg: string;
12
+ /** Source file -> path under `vendor/`, keeping relative imports between entries intact. */
13
+ readonly files: readonly (readonly [source: string, dest: string])[];
14
+ /** Import-map target for `specifier`. */
15
+ readonly target: string;
16
+ }
17
+ /**
18
+ * The spec table is the single enumeration the build copies from, keyed by the schema's
19
+ * `VendorLib` union so a new member cannot compile without a spec. The census test
20
+ * (`vendor-parity.test.ts`) also holds it equal to the scanner's allow-list.
21
+ */
22
+ export declare const SPECS: Record<VendorLib, VendorSpec>;
23
+ /** Every vendored specifier, in spec-table order; the census uses it as one of the enumerations. */
24
+ export declare const vendorSpecifiers: () => readonly VendorLib[];
2
25
  /** Vendor libraries named by scenes, deduplicated and in a stable order. */
3
26
  export declare const vendorLibs: (used: readonly VendorLib[]) => readonly VendorLib[];
4
27
  /** `vendor/…` path -> bytes, for every library in `libs`. Empty when nothing is vendored. */
@@ -1,8 +1,13 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
- const SPECS = [
5
- {
4
+ /**
5
+ * The spec table is the single enumeration the build copies from, keyed by the schema's
6
+ * `VendorLib` union so a new member cannot compile without a spec. The census test
7
+ * (`vendor-parity.test.ts`) also holds it equal to the scanner's allow-list.
8
+ */
9
+ export const SPECS = {
10
+ three: {
6
11
  specifier: "three",
7
12
  pkg: "three",
8
13
  // three.module.js re-exports the core build, so both files are required.
@@ -12,16 +17,18 @@ const SPECS = [
12
17
  ],
13
18
  target: "vendor/three.module.js",
14
19
  },
15
- {
20
+ postprocessing: {
16
21
  specifier: "postprocessing",
17
22
  pkg: "postprocessing",
18
23
  // Imports `three` by bare specifier; the import map resolves it to the copy above.
19
24
  files: [["index.js", "postprocessing.js"]],
20
25
  target: "vendor/postprocessing.js",
21
26
  },
22
- ];
27
+ };
28
+ /** Every vendored specifier, in spec-table order; the census uses it as one of the enumerations. */
29
+ export const vendorSpecifiers = () => Object.keys(SPECS);
23
30
  const specOf = (lib) => {
24
- const spec = SPECS.find((candidate) => candidate.specifier === lib);
31
+ const spec = SPECS[lib];
25
32
  if (spec === undefined)
26
33
  throw new Error(`unknown vendor library "${lib}"`);
27
34
  return spec;
package/dist/index.d.ts CHANGED
@@ -16,4 +16,6 @@ export { createRenderManifest, type RenderManifest, type RenderManifestInput, re
16
16
  export * from "./templates/index.ts";
17
17
  export { autoDuration, placementsFromTimeline, resolveTimeline, type ScenePlacement, type TimedScene, type Timeline, } from "./timing.ts";
18
18
  export { validateStoryboardFull } from "./validate-full.ts";
19
+ export { validateInteraction } from "./validate-interaction.ts";
19
20
  export { type FindingLevel, type MediaExpectation, type VerifyFinding, type VerifyInput, type VerifyReport, type VerifyStatus, verifyMedia, } from "./verify.ts";
21
+ export { buildGrainArgs, GRAIN_DESCRIPTOR, GRAIN_FILTER, GRAIN_SEED, GRAIN_STRENGTH, GRAIN_TEMP, grainEnergy, } from "./video/grain.ts";
package/dist/index.js CHANGED
@@ -16,4 +16,6 @@ export { createRenderManifest, renderRenderManifest, } from "./render-manifest.j
16
16
  export * from "./templates/index.js";
17
17
  export { autoDuration, placementsFromTimeline, resolveTimeline, } from "./timing.js";
18
18
  export { validateStoryboardFull } from "./validate-full.js";
19
+ export { validateInteraction } from "./validate-interaction.js";
19
20
  export { verifyMedia, } from "./verify.js";
21
+ export { buildGrainArgs, GRAIN_DESCRIPTOR, GRAIN_FILTER, GRAIN_SEED, GRAIN_STRENGTH, GRAIN_TEMP, grainEnergy, } from "./video/grain.js";
@@ -0,0 +1,17 @@
1
+ import type { LintRule } from "./types.ts";
2
+ /**
3
+ * Composition variety, as a gate rather than a ratio.
4
+ *
5
+ * `visual-variety` asks for a third of the beats to be visual-bearing, which a five-beat film
6
+ * satisfies with three — and an independent reviewer then found "four of five frames are the
7
+ * same stacked-text card on a vertical gradient". The ratio was the wrong shape of rule: it
8
+ * counts how many pictures exist, not whether the film keeps changing what it shows.
9
+ *
10
+ * Two rules replace that:
11
+ * 1. three adjacent type-only beats — the slide-deck pattern — are reported;
12
+ * 2. three adjacent beats of the same scene TYPE are a warning, because the audience reads
13
+ * the same frame three times even when each one is individually well made.
14
+ *
15
+ * Overlays are excluded: an overlay never carries the picture.
16
+ */
17
+ export declare const beatVarietyRule: LintRule;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Scene types that put a PICTURE on screen. `poster`, `title`, `quote`, `stat` and friends are
3
+ * type on a ground: they are legitimate beats, but they are not pictures, and a run of them is
4
+ * a slide deck however good each frame is.
5
+ */
6
+ const PICTURE_FORMS = new Set([
7
+ "scene3d",
8
+ "media-frame",
9
+ "kinetic",
10
+ "stair",
11
+ "code",
12
+ "waveform",
13
+ "sticker",
14
+ "world",
15
+ "custom",
16
+ // Diagrams stay in this set: a chart, timeline or compare visibly changes the frame, unlike
17
+ // the poster/title/quote/stat type-on-a-ground cards this rule actually measures. They are
18
+ // deliberately excluded from visual-variety's moving-picture count instead.
19
+ "chart",
20
+ "flow",
21
+ "steps",
22
+ "timeline",
23
+ "compare",
24
+ "table",
25
+ "icon-grid",
26
+ ]);
27
+ /** Three type-only beats in a row is a deck; two is a warning. Calibrated against the repo''s own templates: erroring at two broke 30 test files, which means the shipped boards use pairs deliberately. */
28
+ const MAX_TYPE_RUN = 2;
29
+ /** Three beats of the same scene type in a row read as one frame repeated. */
30
+ const MAX_SAME_TYPE_RUN = 2;
31
+ const runs = (scenes) => {
32
+ const out = [];
33
+ for (const scene of scenes) {
34
+ const last = out[out.length - 1];
35
+ if (last !== undefined && last.type === scene.type)
36
+ last.length += 1;
37
+ else
38
+ out.push({ type: scene.type, length: 1 });
39
+ }
40
+ return out;
41
+ };
42
+ /**
43
+ * Composition variety, as a gate rather than a ratio.
44
+ *
45
+ * `visual-variety` asks for a third of the beats to be visual-bearing, which a five-beat film
46
+ * satisfies with three — and an independent reviewer then found "four of five frames are the
47
+ * same stacked-text card on a vertical gradient". The ratio was the wrong shape of rule: it
48
+ * counts how many pictures exist, not whether the film keeps changing what it shows.
49
+ *
50
+ * Two rules replace that:
51
+ * 1. three adjacent type-only beats — the slide-deck pattern — are reported;
52
+ * 2. three adjacent beats of the same scene TYPE are a warning, because the audience reads
53
+ * the same frame three times even when each one is individually well made.
54
+ *
55
+ * Overlays are excluded: an overlay never carries the picture.
56
+ */
57
+ export const beatVarietyRule = ({ storyboard }) => {
58
+ const base = storyboard.scenes.filter((scene) => scene.layer !== "overlay");
59
+ if (base.length < 2)
60
+ return [];
61
+ const findings = [];
62
+ let typeRun = 0;
63
+ let typeRunStart = 0;
64
+ base.forEach((scene, index) => {
65
+ if (PICTURE_FORMS.has(scene.type)) {
66
+ typeRun = 0;
67
+ return;
68
+ }
69
+ if (typeRun === 0)
70
+ typeRunStart = index;
71
+ typeRun += 1;
72
+ if (typeRun === MAX_TYPE_RUN + 1) {
73
+ findings.push({
74
+ severity: "warning",
75
+ path: `/scenes/${scene.id}`,
76
+ message: `${typeRun} type-only beats in a row (from "${base[typeRunStart]?.id ?? ""}"): the film reads as a slide deck`,
77
+ suggestion: "give one of them a moving picture (world, scene3d, media-frame, kinetic or an authored custom scene) so the film changes what it shows; see references/visual-forms.md",
78
+ });
79
+ }
80
+ });
81
+ for (const run of runs(base)) {
82
+ if (run.length > MAX_SAME_TYPE_RUN) {
83
+ findings.push({
84
+ severity: "warning",
85
+ path: "/scenes",
86
+ message: `${run.length} consecutive "${run.type}" beats: the audience sees one frame repeated`,
87
+ suggestion: "vary the scene type across the run, or make the repetition deliberate by changing the world, the camera move or the layout each time",
88
+ });
89
+ }
90
+ }
91
+ return findings;
92
+ };
@@ -10,3 +10,9 @@ export interface CustomSourceInput {
10
10
  * pointing at the first offending line. Pure, so the CLI can run it before a build.
11
11
  */
12
12
  export declare const lintCustomSource: (input: CustomSourceInput, dir: string) => LintFinding[];
13
+ /**
14
+ * Every authored scene in the build, gathered at the emit seam so library consumers
15
+ * get the same lint gate the CLI's read-time check gives. `ids` keeps sources that are
16
+ * not part of this storyboard out of the report.
17
+ */
18
+ export declare const collectCustomFindings: (ids: readonly string[], sources: Readonly<Record<string, CustomSourceInput>> | undefined) => LintFinding[];
@@ -53,6 +53,12 @@ const PROBES = [
53
53
  message: "window is reserved by the renderer",
54
54
  suggestion: "use the root element and the props you were given",
55
55
  },
56
+ {
57
+ file: "scene.js",
58
+ pattern: /\bwindow\b/,
59
+ message: "window is reserved by the renderer",
60
+ suggestion: "use the root element and the props you were given",
61
+ },
56
62
  {
57
63
  file: "style.css",
58
64
  pattern: /(^|[\s;{])animation(?:-name)?\s*:/,
@@ -92,7 +98,173 @@ const PROBES = [
92
98
  ];
93
99
  /** Blanks a span while preserving newlines, so reported line numbers stay true. */
94
100
  const blank = (text) => text.replace(/[^\n]/g, " ");
95
- const stripJs = (source) => source.replace(/\/\*[\s\S]*?\*\//g, blank).replace(/\/\/[^\n]*/g, blank);
101
+ /**
102
+ * Rewrites indirect global access into the direct form the probes already know:
103
+ * `globalThis['Date']['now']()` becomes `Date.now()`, `self.Math.random()` becomes
104
+ * `Math.random()`, and `globalThis['window']` becomes a bare `window` reference.
105
+ * Runs on the RAW source, before tokenizing, so computed keys are still readable.
106
+ */
107
+ const normaliseGlobals = (source) => source
108
+ .replace(/\b(?:globalThis|self)\s*\[\s*(['"])([A-Za-z_$][\w$]*)\1\s*\]/g, "$2")
109
+ .replace(/\b(?:globalThis|self)\s*\.\s*([A-Za-z_$][\w$]*)/g, "$1")
110
+ .replace(/\b(Date|Math|performance)\s*\[\s*(['"])(now|random)\2\s*\]/g, "$1.$3");
111
+ const isNewline = (ch) => ch === "\n" || ch === "\r";
112
+ const top = (state) => state.stack[state.stack.length - 1];
113
+ const emitBlank = (state, ch) => {
114
+ state.out.push(isNewline(ch) ? ch : " ");
115
+ };
116
+ /** Blanks a `\` and its escaped character, preserving a newline if escaped. */
117
+ const blankEscape = (state, at) => {
118
+ state.out.push(" ");
119
+ if (at + 1 >= state.source.length)
120
+ return 1;
121
+ emitBlank(state, state.source[at + 1]);
122
+ return 2;
123
+ };
124
+ const stepLineComment = (state, i) => {
125
+ const ch = state.source[i];
126
+ if (isNewline(ch))
127
+ state.stack.pop();
128
+ emitBlank(state, ch);
129
+ return 1;
130
+ };
131
+ const stepBlockComment = (state, i) => {
132
+ const ch = state.source[i];
133
+ const next = state.source[i + 1];
134
+ if (ch === "*" && next === "/") {
135
+ state.out.push(" ");
136
+ state.stack.pop();
137
+ return 2;
138
+ }
139
+ emitBlank(state, ch);
140
+ return 1;
141
+ };
142
+ const stepQuoted = (state, i, quote) => {
143
+ const ch = state.source[i];
144
+ if (ch === "\\")
145
+ return blankEscape(state, i);
146
+ if (ch === quote) {
147
+ state.out.push(quote);
148
+ state.stack.pop();
149
+ return 1;
150
+ }
151
+ emitBlank(state, ch);
152
+ return 1;
153
+ };
154
+ const stepTemplate = (state, i) => {
155
+ const ch = state.source[i];
156
+ const next = state.source[i + 1];
157
+ if (ch === "`") {
158
+ state.out.push("`");
159
+ state.stack.pop();
160
+ return 1;
161
+ }
162
+ if (ch === "\\")
163
+ return blankEscape(state, i);
164
+ if (ch === "$" && next === "{") {
165
+ state.out.push(" ");
166
+ state.stack.push({ kind: "code", interpolation: true, braceDepth: 0 });
167
+ return 2;
168
+ }
169
+ emitBlank(state, ch);
170
+ return 1;
171
+ };
172
+ /** Tracks braces inside a `${...}` so nested blocks don't close it early. */
173
+ const stepBraces = (state, frame, ch) => {
174
+ if (ch === "{") {
175
+ frame.braceDepth += 1;
176
+ state.out.push(ch);
177
+ return;
178
+ }
179
+ if (ch === "}") {
180
+ if (frame.braceDepth === 0)
181
+ state.stack.pop(); // back to the template frame
182
+ else
183
+ frame.braceDepth -= 1;
184
+ state.out.push(ch);
185
+ return;
186
+ }
187
+ state.out.push(ch);
188
+ };
189
+ const stepCode = (state, frame, i) => {
190
+ const ch = state.source[i];
191
+ const next = state.source[i + 1];
192
+ if (ch === "'") {
193
+ state.out.push("'");
194
+ state.stack.push({ kind: "single" });
195
+ return 1;
196
+ }
197
+ if (ch === '"') {
198
+ state.out.push('"');
199
+ state.stack.push({ kind: "double" });
200
+ return 1;
201
+ }
202
+ if (ch === "`") {
203
+ state.out.push("`");
204
+ state.stack.push({ kind: "template" });
205
+ return 1;
206
+ }
207
+ if (ch === "/" && next === "/") {
208
+ state.out.push(" ");
209
+ state.stack.push({ kind: "line-comment" });
210
+ return 2;
211
+ }
212
+ if (ch === "/" && next === "*") {
213
+ state.out.push(" ");
214
+ state.stack.push({ kind: "block-comment" });
215
+ return 2;
216
+ }
217
+ if (frame.interpolation) {
218
+ stepBraces(state, frame, ch);
219
+ return 1;
220
+ }
221
+ state.out.push(ch);
222
+ return 1;
223
+ };
224
+ /**
225
+ * Single string-aware pass over JS source. Returns a stream the same length as
226
+ * the input (so reported line numbers stay true) where comment text and string
227
+ * CONTENT are blanked while quotes/delimiters, newlines and every character of
228
+ * real code are kept searchable by the probes.
229
+ *
230
+ * Unlike the old `stripStrings(stripJs(raw))` chain, a `//` or `/*` inside a
231
+ * string or template literal is never mistaken for a comment opener, so it
232
+ * cannot blank the rest of the line or leave a dangling quote that swallows
233
+ * later code. Template interpolation is re-entered as code so real calls in it
234
+ * remain visible.
235
+ */
236
+ const codeStream = (source) => {
237
+ const state = {
238
+ source,
239
+ out: [],
240
+ stack: [{ kind: "code", interpolation: false, braceDepth: 0 }],
241
+ };
242
+ let i = 0;
243
+ while (i < source.length) {
244
+ const frame = top(state);
245
+ switch (frame.kind) {
246
+ case "line-comment":
247
+ i += stepLineComment(state, i);
248
+ break;
249
+ case "block-comment":
250
+ i += stepBlockComment(state, i);
251
+ break;
252
+ case "single":
253
+ i += stepQuoted(state, i, "'");
254
+ break;
255
+ case "double":
256
+ i += stepQuoted(state, i, '"');
257
+ break;
258
+ case "template":
259
+ i += stepTemplate(state, i);
260
+ break;
261
+ case "code":
262
+ i += stepCode(state, frame, i);
263
+ break;
264
+ }
265
+ }
266
+ return state.out.join("");
267
+ };
96
268
  const stripCss = (source) => source.replace(/\/\*[\s\S]*?\*\//g, blank);
97
269
  const stripHtml = (source) => source.replace(/<!--[\s\S]*?-->/g, blank);
98
270
  const sourceOf = (input, file) => {
@@ -100,7 +272,10 @@ const sourceOf = (input, file) => {
100
272
  if (raw === undefined)
101
273
  return undefined;
102
274
  // Comments describe the rules ("no window.") and must not trip them.
103
- return file === "scene.js" ? stripJs(raw) : file === "style.css" ? stripCss(raw) : stripHtml(raw);
275
+ if (file !== "scene.js") {
276
+ return file === "style.css" ? stripCss(raw) : stripHtml(raw);
277
+ }
278
+ return codeStream(normaliseGlobals(raw));
104
279
  };
105
280
  /** First offending line of one file, as a finding path of `<dir>/<file>:<line>`. */
106
281
  const scan = (input, probe, dir) => {
@@ -124,7 +299,27 @@ const scan = (input, probe, dir) => {
124
299
  * Determinism and safety lint for an authored scene: one finding per rule and file,
125
300
  * pointing at the first offending line. Pure, so the CLI can run it before a build.
126
301
  */
127
- export const lintCustomSource = (input, dir) => PROBES.flatMap((probe) => {
128
- const finding = scan(input, probe, dir);
129
- return finding === undefined ? [] : [finding];
130
- });
302
+ export const lintCustomSource = (input, dir) => {
303
+ const seen = new Set();
304
+ return PROBES.flatMap((probe) => {
305
+ const finding = scan(input, probe, dir);
306
+ return finding === undefined ? [] : [finding];
307
+ }).filter((finding) => {
308
+ const key = `${finding.path}\u0000${finding.message}`;
309
+ if (seen.has(key))
310
+ return false;
311
+ seen.add(key);
312
+ return true;
313
+ });
314
+ };
315
+ /**
316
+ * Every authored scene in the build, gathered at the emit seam so library consumers
317
+ * get the same lint gate the CLI's read-time check gives. `ids` keeps sources that are
318
+ * not part of this storyboard out of the report.
319
+ */
320
+ export const collectCustomFindings = (ids, sources) => sources === undefined
321
+ ? []
322
+ : ids.flatMap((id) => {
323
+ const source = sources[id];
324
+ return source === undefined ? [] : lintCustomSource(source, `scenes/${id}`);
325
+ });
@@ -1,3 +1,4 @@
1
+ import { beatVarietyRule } from "./beat-variety.ts";
1
2
  import { contentDensityRule } from "./content-density.ts";
2
3
  import { contentOverflowRule } from "./content-overflow.ts";
3
4
  import { fadeDeckRule } from "./fade-deck.ts";
@@ -18,9 +19,11 @@ import { transitionImplementedRule } from "./transition-implemented.ts";
18
19
  import { transitionLengthRule } from "./transition-length.ts";
19
20
  import { duplicatedEmphasisRule, lineLengthRule, offGridSpacingRule, typeDensityRule } from "./type-grid.ts";
20
21
  import type { LintInput, LintResult, LintRule } from "./types.ts";
22
+ import { visualVarietyRule } from "./visual-variety.ts";
21
23
  import { wordsOnScreenRule } from "./words-on-screen.ts";
24
+ import { worldStopsRule } from "./world-stops.ts";
22
25
  export type { LintFinding, LintInput, LintResult, LintRule, PlatformMarginLookup, PlatformMargins, } from "./types.ts";
23
- export { contentDensityRule, contentOverflowRule, duplicatedEmphasisRule, fadeDeckRule, flatMotionRule, flowEdgeLabelRule, flowTextSizeRule, flowWordBreakRule, holdAfterAccentRule, hookFirstRule, linearEaseRule, lineLengthRule, longHoldRule, minHoldRule, narrationPaceRule, offGridSpacingRule, overlayFitRule, overlayStackRule, overlayTargetRule, plateOverCaptionRule, readingTimeRule, safeZone9x16Rule, spanNeedsTwoBodiesRule, textFloorRule, transitionEaseMismatchRule, transitionImplementedRule, transitionLengthRule, typeDensityRule, unsupportedMotionRule, wordsOnScreenRule, };
26
+ export { beatVarietyRule, contentDensityRule, contentOverflowRule, duplicatedEmphasisRule, fadeDeckRule, flatMotionRule, flowEdgeLabelRule, flowTextSizeRule, flowWordBreakRule, holdAfterAccentRule, hookFirstRule, linearEaseRule, lineLengthRule, longHoldRule, minHoldRule, narrationPaceRule, offGridSpacingRule, overlayFitRule, overlayStackRule, overlayTargetRule, plateOverCaptionRule, readingTimeRule, safeZone9x16Rule, spanNeedsTwoBodiesRule, textFloorRule, transitionEaseMismatchRule, transitionImplementedRule, transitionLengthRule, typeDensityRule, unsupportedMotionRule, visualVarietyRule, wordsOnScreenRule, worldStopsRule, };
24
27
  /**
25
28
  * All rules, in report order. Contrast lives in theme tokens.
26
29
  * Craft rules (motion-craft, type-grid) run after the timing and layout
@@ -1,3 +1,4 @@
1
+ import { beatVarietyRule } from "./beat-variety.js";
1
2
  import { contentDensityRule } from "./content-density.js";
2
3
  import { contentOverflowRule } from "./content-overflow.js";
3
4
  import { fadeDeckRule } from "./fade-deck.js";
@@ -18,8 +19,10 @@ import { textFloorRule } from "./text-floor.js";
18
19
  import { transitionImplementedRule } from "./transition-implemented.js";
19
20
  import { transitionLengthRule } from "./transition-length.js";
20
21
  import { duplicatedEmphasisRule, lineLengthRule, offGridSpacingRule, typeDensityRule, } from "./type-grid.js";
22
+ import { visualVarietyRule } from "./visual-variety.js";
21
23
  import { wordsOnScreenRule } from "./words-on-screen.js";
22
- export { contentDensityRule, contentOverflowRule, duplicatedEmphasisRule, fadeDeckRule, flatMotionRule, flowEdgeLabelRule, flowTextSizeRule, flowWordBreakRule, holdAfterAccentRule, hookFirstRule, linearEaseRule, lineLengthRule, longHoldRule, minHoldRule, narrationPaceRule, offGridSpacingRule, overlayFitRule, overlayStackRule, overlayTargetRule, plateOverCaptionRule, readingTimeRule, safeZone9x16Rule, spanNeedsTwoBodiesRule, textFloorRule, transitionEaseMismatchRule, transitionImplementedRule, transitionLengthRule, typeDensityRule, unsupportedMotionRule, wordsOnScreenRule, };
24
+ import { worldStopsRule } from "./world-stops.js";
25
+ export { beatVarietyRule, contentDensityRule, contentOverflowRule, duplicatedEmphasisRule, fadeDeckRule, flatMotionRule, flowEdgeLabelRule, flowTextSizeRule, flowWordBreakRule, holdAfterAccentRule, hookFirstRule, linearEaseRule, lineLengthRule, longHoldRule, minHoldRule, narrationPaceRule, offGridSpacingRule, overlayFitRule, overlayStackRule, overlayTargetRule, plateOverCaptionRule, readingTimeRule, safeZone9x16Rule, spanNeedsTwoBodiesRule, textFloorRule, transitionEaseMismatchRule, transitionImplementedRule, transitionLengthRule, typeDensityRule, unsupportedMotionRule, visualVarietyRule, wordsOnScreenRule, worldStopsRule, };
23
26
  /**
24
27
  * All rules, in report order. Contrast lives in theme tokens.
25
28
  * Craft rules (motion-craft, type-grid) run after the timing and layout
@@ -57,6 +60,11 @@ export const LINT_RULES = [
57
60
  lineLengthRule,
58
61
  offGridSpacingRule,
59
62
  duplicatedEmphasisRule,
63
+ visualVarietyRule,
64
+ worldStopsRule,
65
+ // Registered after the shipped blueprints were rewritten to keep every same-family run <= 2;
66
+ // the shipped boards now produce no beat-variety warnings.
67
+ beatVarietyRule,
60
68
  ];
61
69
  export const lintStoryboard = (input) => {
62
70
  const findings = LINT_RULES.flatMap((rule) => rule(input));
@@ -0,0 +1,16 @@
1
+ import type { LintRule } from "./types.ts";
2
+ /**
3
+ * A film long enough to establish a visual language must show one: at least a
4
+ * third of the base beats are visual-bearing (`design-taste.md` law 1). This is a
5
+ * board-level rule on purpose — it judges the film's visual vocabulary, not any
6
+ * single frame — so it fires once, not per scene.
7
+ *
8
+ * Two findings share this rule (never both for one board):
9
+ * - an all-diagram board gets the world-first default: slides are an explicit
10
+ * brief request, not the fallback for a film with no picture in it;
11
+ * - any other shortfall keeps the moving-picture floor message.
12
+ *
13
+ * Overlays never carry the visual language of the film, so they neither count
14
+ * as base beats nor satisfy the rule.
15
+ */
16
+ export declare const visualVarietyRule: LintRule;