@anvpx/motion-build 0.1.54 → 0.1.94

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.
@@ -91,7 +91,7 @@ export declare const missingMusic: (music: MusicBed | undefined, exists: (path:
91
91
  * `{ wav }` that never passed `parseMusicBed`/`validateMusicBed` (traversal,
92
92
  * non-wav, bad level) throws here instead of reaching ffmpeg.
93
93
  */
94
- export declare const buildMusicFilterGraph: (clips: readonly MixClip[], music: MusicBed) => string;
94
+ export declare const buildMusicFilterGraph: (clips: readonly MixClip[], music: MusicBed, filmDurationSec?: number) => string;
95
95
  /** Role of a frozen wav; the role is part of the injective frozen name. */
96
96
  export type FrozenRole = "narration" | "music";
97
97
  /**
@@ -147,7 +147,7 @@ export declare const musicLoopFor: (bedDuration: number, clips: readonly MixClip
147
147
  * (`-c:v copy`), bed ducked under narration and mixed to aac. No `-shortest`;
148
148
  * the picture keeps its authored tail after the last word.
149
149
  */
150
- export declare const buildMusicMixArgs: (videoIn: string, clips: readonly MixClip[], music: MusicBed, out: string) => string[];
150
+ export declare const buildMusicMixArgs: (videoIn: string, clips: readonly MixClip[], music: MusicBed, out: string, filmDurationSec?: number) => string[];
151
151
  /**
152
152
  * Delivery loudness (fixed, no CLI flag). Kokoro narration lands near -26 LUFS,
153
153
  * so the mix would otherwise fail every verified platform policy; the mixed
@@ -217,6 +217,8 @@ export interface MixDeliveryPlan {
217
217
  readonly videoIn: string;
218
218
  readonly clips: readonly MixClip[];
219
219
  readonly music?: MusicBed;
220
+ /** Picture length in seconds; the score is trimmed to it. Absent keeps the narration tail. */
221
+ readonly durationSec?: number;
220
222
  /** The path the mix wrote before normalization; normalization rewrites it in place. */
221
223
  readonly out: string;
222
224
  /** Moves the normalized temp file over `out` (fs in the CLI, a fake in tests). */
package/dist/audio/mix.js CHANGED
@@ -108,6 +108,8 @@ export const buildMixArgs = (videoIn, clips, out) => [
108
108
  "copy",
109
109
  "-c:a",
110
110
  "aac",
111
+ "-ar",
112
+ "48000",
111
113
  "-movflags",
112
114
  "+faststart",
113
115
  out,
@@ -167,14 +169,18 @@ const narrationTotal = (clips) => clips.reduce((max, clip) => Math.max(max, clip
167
169
  * `{ wav }` that never passed `parseMusicBed`/`validateMusicBed` (traversal,
168
170
  * non-wav, bad level) throws here instead of reaching ffmpeg.
169
171
  */
170
- export const buildMusicFilterGraph = (clips, music) => {
172
+ export const buildMusicFilterGraph = (clips, music, filmDurationSec) => {
171
173
  if (clips.length === 0)
172
174
  throw new Error("mixdown needs at least one narration clip");
173
175
  requireValidBed(music);
174
176
  const volume = resolveMusicVolume(music);
175
177
  const musicIndex = clips.length + 1;
176
178
  const narr = narrationGraph(clips, "narr");
177
- const total = toDelayMs(narrationTotal(clips)) / 1000;
179
+ // The score runs to the end of the picture, not the end of the last spoken word:
180
+ // a silent end card must still have music under it.
181
+ const total = filmDurationSec !== undefined && filmDurationSec > 0
182
+ ? filmDurationSec
183
+ : toDelayMs(narrationTotal(clips)) / 1000;
178
184
  const sidechain = `sidechaincompress=threshold=${SIDECHAIN_THRESHOLD}:ratio=${SIDECHAIN_RATIO}` +
179
185
  `:attack=${SIDECHAIN_ATTACK_MS}:release=${SIDECHAIN_RELEASE_MS}`;
180
186
  return (`[${musicIndex}:a]volume=${volume},aloop=loop=-1:size=2e9,atrim=duration=${total}[mbed];` +
@@ -279,7 +285,7 @@ export const musicLoopFor = (bedDuration, clips) => {
279
285
  * (`-c:v copy`), bed ducked under narration and mixed to aac. No `-shortest`;
280
286
  * the picture keeps its authored tail after the last word.
281
287
  */
282
- export const buildMusicMixArgs = (videoIn, clips, music, out) => [
288
+ export const buildMusicMixArgs = (videoIn, clips, music, out, filmDurationSec) => [
283
289
  "-y",
284
290
  "-i",
285
291
  videoIn,
@@ -287,7 +293,7 @@ export const buildMusicMixArgs = (videoIn, clips, music, out) => [
287
293
  "-i",
288
294
  music.wav,
289
295
  "-filter_complex",
290
- buildMusicFilterGraph(clips, music),
296
+ buildMusicFilterGraph(clips, music, filmDurationSec),
291
297
  "-map",
292
298
  "0:v:0",
293
299
  "-map",
@@ -296,6 +302,8 @@ export const buildMusicMixArgs = (videoIn, clips, music, out) => [
296
302
  "copy",
297
303
  "-c:a",
298
304
  "aac",
305
+ "-ar",
306
+ "48000",
299
307
  "-movflags",
300
308
  "+faststart",
301
309
  out,
@@ -427,6 +435,8 @@ export const buildLoudnessNormalizeArgs = (input, measurement, out) => [
427
435
  "aac",
428
436
  "-b:a",
429
437
  "192k",
438
+ "-ar",
439
+ "48000",
430
440
  "-movflags",
431
441
  "+faststart",
432
442
  out,
@@ -456,9 +466,13 @@ export const mixAtDeliveryLevel = async (run, plan) => {
456
466
  };
457
467
  if (plan.clips.length === 0)
458
468
  return skipped();
469
+ // The score runs to the end of the picture. `durationSec` is the built film total,
470
+ // supplied by the caller (which already knows it from the timeline); without it the
471
+ // bed stops at the last spoken word, which is the pre-existing behaviour. This
472
+ // function never probes: its runner is an ffmpeg-only channel.
459
473
  const mixArgs = plan.music === undefined
460
474
  ? buildMixArgs(plan.videoIn, plan.clips, plan.out)
461
- : buildMusicMixArgs(plan.videoIn, plan.clips, plan.music, plan.out);
475
+ : buildMusicMixArgs(plan.videoIn, plan.clips, plan.music, plan.out, plan.durationSec);
462
476
  const mixed = await run(mixArgs);
463
477
  if (mixed.code !== 0)
464
478
  return failed([`mix failed: ${firstLine(mixed.stderr)}`]);
@@ -26,6 +26,9 @@ const baseCss = (meta) => `html, body {
26
26
  background: var(--mk-color-bg);
27
27
  }
28
28
  #root { position: relative; width: ${meta.width}px; height: ${meta.height}px; overflow: hidden; }
29
+ /* No atmosphere layer here on purpose. Every scene paints its own full-bleed ground
30
+ inside the scene root (see define-scene.ts), so anything drawn behind it is invisible
31
+ and only pretends the frame has a backdrop. The ground belongs to the scene. */
29
32
  .clip { position: absolute; inset: 0; }
30
33
  `;
31
34
  const clipHtml = (scene) => [
@@ -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,86 @@
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
+ "chart",
8
+ "flow",
9
+ "steps",
10
+ "timeline",
11
+ "compare",
12
+ "icon-grid",
13
+ "scene3d",
14
+ "media-frame",
15
+ "stair",
16
+ "table",
17
+ "code",
18
+ "waveform",
19
+ "world",
20
+ ]);
21
+ /** 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. */
22
+ const MAX_TYPE_RUN = 2;
23
+ /** Three beats of the same scene type in a row read as one frame repeated. */
24
+ const MAX_SAME_TYPE_RUN = 2;
25
+ const runs = (scenes) => {
26
+ const out = [];
27
+ for (const scene of scenes) {
28
+ const last = out[out.length - 1];
29
+ if (last !== undefined && last.type === scene.type)
30
+ last.length += 1;
31
+ else
32
+ out.push({ type: scene.type, length: 1 });
33
+ }
34
+ return out;
35
+ };
36
+ /**
37
+ * Composition variety, as a gate rather than a ratio.
38
+ *
39
+ * `visual-variety` asks for a third of the beats to be visual-bearing, which a five-beat film
40
+ * satisfies with three — and an independent reviewer then found "four of five frames are the
41
+ * same stacked-text card on a vertical gradient". The ratio was the wrong shape of rule: it
42
+ * counts how many pictures exist, not whether the film keeps changing what it shows.
43
+ *
44
+ * Two rules replace that:
45
+ * 1. three adjacent type-only beats — the slide-deck pattern — are reported;
46
+ * 2. three adjacent beats of the same scene TYPE are a warning, because the audience reads
47
+ * the same frame three times even when each one is individually well made.
48
+ *
49
+ * Overlays are excluded: an overlay never carries the picture.
50
+ */
51
+ export const beatVarietyRule = ({ storyboard }) => {
52
+ const base = storyboard.scenes.filter((scene) => scene.layer !== "overlay");
53
+ if (base.length < 2)
54
+ return [];
55
+ const findings = [];
56
+ let typeRun = 0;
57
+ let typeRunStart = 0;
58
+ base.forEach((scene, index) => {
59
+ if (PICTURE_FORMS.has(scene.type)) {
60
+ typeRun = 0;
61
+ return;
62
+ }
63
+ if (typeRun === 0)
64
+ typeRunStart = index;
65
+ typeRun += 1;
66
+ if (typeRun === MAX_TYPE_RUN + 1) {
67
+ findings.push({
68
+ severity: "warning",
69
+ path: `/scenes/${scene.id}`,
70
+ message: `${typeRun} type-only beats in a row (from "${base[typeRunStart]?.id ?? ""}"): the film reads as a slide deck`,
71
+ suggestion: "give one of them a picture (chart, flow/steps, timeline, compare, world, scene3d, media-frame) so the film changes what it shows; see references/visual-forms.md",
72
+ });
73
+ }
74
+ });
75
+ for (const run of runs(base)) {
76
+ if (run.length > MAX_SAME_TYPE_RUN) {
77
+ findings.push({
78
+ severity: "warning",
79
+ path: "/scenes",
80
+ message: `${run.length} consecutive "${run.type}" beats: the audience sees one frame repeated`,
81
+ 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",
82
+ });
83
+ }
84
+ }
85
+ return findings;
86
+ };
@@ -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
+ // beatVarietyRule: implemented and tested (beat-variety.ts) but not registered yet. The
66
+ // repo's own templates declare exact warning sets that it legitimately changes, so it ships
67
+ // disabled until those templates are rewritten. See findings/round33-beat-variety.md.
60
68
  ];
61
69
  export const lintStoryboard = (input) => {
62
70
  const findings = LINT_RULES.flatMap((rule) => rule(input));
@@ -0,0 +1,11 @@
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
+ * Overlays never carry the visual language of the film, so they neither count
9
+ * as base beats nor satisfy the rule.
10
+ */
11
+ export declare const visualVarietyRule: LintRule;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Scene types that put a visual form on screen — a picture, a diagram or a
3
+ * moving display — rather than copy on a background.
4
+ */
5
+ const VISUAL_FORMS = new Set([
6
+ "chart",
7
+ "flow",
8
+ "steps",
9
+ "timeline",
10
+ "compare",
11
+ "icon-grid",
12
+ "scene3d",
13
+ "media-frame",
14
+ "kinetic",
15
+ "stair",
16
+ "table",
17
+ "code",
18
+ "waveform",
19
+ "sticker",
20
+ "world",
21
+ ]);
22
+ /** Concrete forms the author can reach for, named in the suggestion. */
23
+ const FORMS = "chart, flow/steps, world, scene3d, media-frame, kinetic or compare";
24
+ /**
25
+ * A film long enough to establish a visual language must show one: at least a
26
+ * third of the base beats are visual-bearing (`design-taste.md` law 1). This is a
27
+ * board-level rule on purpose — it judges the film's visual vocabulary, not any
28
+ * single frame — so it fires once, not per scene.
29
+ *
30
+ * Overlays never carry the visual language of the film, so they neither count
31
+ * as base beats nor satisfy the rule.
32
+ */
33
+ export const visualVarietyRule = ({ storyboard }) => {
34
+ const base = storyboard.scenes.filter((scene) => scene.layer !== "overlay");
35
+ if (base.length < 4)
36
+ return [];
37
+ const visual = base.filter((scene) => VISUAL_FORMS.has(scene.type)).length;
38
+ const need = Math.ceil(base.length / 3);
39
+ if (visual >= need)
40
+ return [];
41
+ return [
42
+ {
43
+ severity: "warning",
44
+ path: "/scenes",
45
+ message: `${visual} of ${base.length} base scenes visual-bearing; at least ${need} needed: the film reads as a slide deck`,
46
+ suggestion: `give another base beat a visual form (${FORMS}), or cut the board down; see references/visual-forms.md`,
47
+ },
48
+ ];
49
+ };
@@ -0,0 +1,11 @@
1
+ import type { LintRule } from "./types.ts";
2
+ /**
3
+ * World stops share one lit path across the ground: posts spread over a fixed
4
+ * span, so long labels collide. Heuristic guardrail from two observed boards:
5
+ * four stops at ~20 chars each overlapped with zero warnings, while three
6
+ * stops at ~14 chars each read clean. Schema caps each stop at 40 chars, which
7
+ * still collides at 4 stops, so this rule judges the total, not the cap.
8
+ */
9
+ export declare const WORLD_STOP_SINGLE_MAX = 30;
10
+ export declare const WORLD_STOPS_TOTAL_MAX = 60;
11
+ export declare const worldStopsRule: LintRule;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * World stops share one lit path across the ground: posts spread over a fixed
3
+ * span, so long labels collide. Heuristic guardrail from two observed boards:
4
+ * four stops at ~20 chars each overlapped with zero warnings, while three
5
+ * stops at ~14 chars each read clean. Schema caps each stop at 40 chars, which
6
+ * still collides at 4 stops, so this rule judges the total, not the cap.
7
+ */
8
+ export const WORLD_STOP_SINGLE_MAX = 30;
9
+ export const WORLD_STOPS_TOTAL_MAX = 60;
10
+ export const worldStopsRule = ({ storyboard }) => {
11
+ const findings = [];
12
+ storyboard.scenes.forEach((scene, index) => {
13
+ if (scene.type !== "world" || scene.layer === "overlay")
14
+ return;
15
+ const props = (scene.props ?? {});
16
+ if (!Array.isArray(props.stops))
17
+ return;
18
+ // Type errors belong to the schema (stops must be strings <= 40 chars);
19
+ // this rule judges layout only and stays quiet on malformed props.
20
+ if (props.stops.some((stop) => typeof stop !== "string"))
21
+ return;
22
+ const labels = props.stops;
23
+ if (labels.length === 0)
24
+ return;
25
+ const total = labels.reduce((sum, label) => sum + label.length, 0);
26
+ const long = labels.findIndex((label) => label.length > WORLD_STOP_SINGLE_MAX);
27
+ if (long === -1 && total <= WORLD_STOPS_TOTAL_MAX)
28
+ return;
29
+ findings.push({
30
+ severity: "warning",
31
+ path: `/scenes/${index}/props/stops`,
32
+ message: long === -1
33
+ ? `world stops total ${total} chars across ${labels.length} posts: labels collide on the path`
34
+ : `world stop ${long + 1} is ${labels[long]?.length ?? 0} chars: a post label that long overlaps its neighbour`,
35
+ suggestion: "shorten each stop to ~12 chars or drop to fewer stops; see references/world-design.md",
36
+ });
37
+ });
38
+ return findings;
39
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvpx/motion-build",
3
- "version": "0.1.54",
3
+ "version": "0.1.94",
4
4
  "description": "Storyboard compiler for @anvpx/motion: validation, scene emission and HyperFrames project output.",
5
5
  "license": "MIT",
6
6
  "author": "anvpx",
@@ -31,9 +31,9 @@
31
31
  "@fontsource/jetbrains-mono": "5.3.0",
32
32
  "@fontsource/source-serif-4": "5.3.1",
33
33
  "@fontsource/space-grotesk": "5.3.0",
34
- "@anvpx/motion-scenes": "0.1.54",
35
- "@anvpx/motion-schema": "0.1.54",
36
- "@anvpx/motion-themes": "0.1.54",
34
+ "@anvpx/motion-scenes": "0.1.94",
35
+ "@anvpx/motion-schema": "0.1.94",
36
+ "@anvpx/motion-themes": "0.1.94",
37
37
  "postprocessing": "6.39.5",
38
38
  "three": "0.186.0"
39
39
  },