@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
@@ -1,34 +1,12 @@
1
- import { CUSTOM_SCENE_TYPE, getScene, sceneRegistry, sceneTypes } from "@anvpx/motion-scenes";
2
- import { toJsonPointer, validateStoryboard, } from "@anvpx/motion-schema";
1
+ import { CUSTOM_SCENE_TYPE, classifySceneDir, getScene, sceneRegistry, sceneTypes, } from "@anvpx/motion-scenes";
2
+ import { TargetDeclSchema, toJsonPointer, toValidationError, validateStoryboard, } from "@anvpx/motion-schema";
3
3
  const WORD_LIMIT = /^scene has \d+ words/;
4
- const valueAt = (root, path) => path.reduce((node, key) => (typeof node === "object" && node !== null ? Reflect.get(node, key) : undefined), root);
5
- const withSuggestion = (base, suggestion) => suggestion === undefined ? base : { ...base, suggestion };
6
- const describeIssue = (issue, props) => {
7
- if (issue.code === "invalid_value") {
8
- const received = JSON.stringify(valueAt(props, issue.path));
9
- return { message: `${received} invalid`, suggestion: `use one of: ${issue.values.join("|")}` };
10
- }
11
- if (issue.code === "unrecognized_keys") {
12
- const keys = issue.keys.join(", ");
13
- return {
14
- message: `unknown key(s): ${keys}`,
15
- suggestion: `remove ${keys} (check spelling against the catalog)`,
16
- };
17
- }
18
- if (WORD_LIMIT.test(issue.message)) {
19
- return { message: issue.message, suggestion: "shorten the text or split into two scenes" };
20
- }
21
- return { message: issue.message };
22
- };
4
+ const WORD_LIMIT_HINT = "shorten the text or split into two scenes";
23
5
  const propErrors = (entry, index) => {
24
6
  const parsed = getScene(entry.type).configSchema.safeParse(entry.props);
25
7
  if (parsed.success)
26
8
  return [];
27
- return parsed.error.issues.map((issue) => {
28
- const { message, suggestion } = describeIssue(issue, entry.props);
29
- const path = toJsonPointer(["scenes", index, "props", ...issue.path]);
30
- return withSuggestion({ path, message }, suggestion);
31
- });
9
+ return parsed.error.issues.map((issue) => toValidationError(issue, entry.props, WORD_LIMIT.test(issue.message) ? WORD_LIMIT_HINT : undefined, ["scenes", index, "props"]));
32
10
  };
33
11
  const overlayTypes = () => [...sceneRegistry.values()].filter((plugin) => plugin.layer === "overlay").map((p) => p.type);
34
12
  /** An overlay entry needs an overlay plugin and the other way round. */
@@ -54,15 +32,30 @@ const layerErrors = (entry, index) => {
54
32
  }
55
33
  return [];
56
34
  };
57
- const ABSOLUTE_DIR = /^(?:[a-zA-Z]:|[\\/]|~)/;
58
- const ESCAPING_DIR = /(^|[\\/])\.\.([\\/]|$)/;
59
35
  /**
60
- * `custom` props: the relative directory holding the scene's three files, and the declared
61
- * `elements` count — how many labelled marks the plate draws. The count is declared because an
62
- * authored scene's copy lives in its own files, so no validator can see it; the density rule
63
- * needs the number to judge a plate at all.
36
+ * `custom` props: the relative directory holding the scene's three files, the declared
37
+ * `elements` count — how many labelled marks the plate draws — and the optional `targets` an
38
+ * interaction transcript may address. The count is declared because an authored scene's copy
39
+ * lives in its own files, so no validator can see it; the density rule needs the number to
40
+ * judge a plate at all.
64
41
  */
65
- const CUSTOM_PROP_KEYS = new Set(["dir", "elements"]);
42
+ const CUSTOM_PROP_KEYS = new Set(["dir", "elements", "targets"]);
43
+ /** Transcript targets must be declared as `{ id, role }` with slug ids. */
44
+ const targetsOf = (props, index) => {
45
+ const targets = props.targets;
46
+ if (targets === undefined ||
47
+ (Array.isArray(targets) &&
48
+ targets.every((target) => TargetDeclSchema.safeParse(target).success))) {
49
+ return [];
50
+ }
51
+ return [
52
+ {
53
+ path: toJsonPointer(["scenes", index, "props", "targets"]),
54
+ message: "targets must be an array of { id, role } with slug ids",
55
+ suggestion: 'for example: [{ "id": "cta", "role": "button" }]',
56
+ },
57
+ ];
58
+ };
66
59
  const customErrors = (entry, index) => {
67
60
  const props = entry.props;
68
61
  const unknown = Object.keys(props).filter((key) => !CUSTOM_PROP_KEYS.has(key));
@@ -86,6 +79,9 @@ const customErrors = (entry, index) => {
86
79
  },
87
80
  ];
88
81
  }
82
+ const targetErrors = targetsOf(props, index);
83
+ if (targetErrors.length > 0)
84
+ return targetErrors;
89
85
  const dir = props.dir;
90
86
  if (typeof dir !== "string" || dir.trim() === "") {
91
87
  return [
@@ -96,25 +92,22 @@ const customErrors = (entry, index) => {
96
92
  },
97
93
  ];
98
94
  }
99
- if (ABSOLUTE_DIR.test(dir)) {
100
- return [
101
- {
95
+ const verdict = classifySceneDir(dir);
96
+ if (verdict.inside)
97
+ return [];
98
+ return [
99
+ verdict.reason === "absolute"
100
+ ? {
102
101
  path: toJsonPointer(["scenes", index, "props", "dir"]),
103
102
  message: "props.dir must be relative",
104
103
  suggestion: "use a path inside the storyboard's directory",
105
- },
106
- ];
107
- }
108
- if (ESCAPING_DIR.test(dir)) {
109
- return [
110
- {
104
+ }
105
+ : {
111
106
  path: toJsonPointer(["scenes", index, "props", "dir"]),
112
107
  message: "props.dir escapes the storyboard directory",
113
108
  suggestion: "keep the scene beside the storyboard",
114
109
  },
115
- ];
116
- }
117
- return [];
110
+ ];
118
111
  };
119
112
  const sceneErrors = (entry, index) => {
120
113
  if (entry.type === CUSTOM_SCENE_TYPE) {
@@ -0,0 +1,7 @@
1
+ import { type Interaction, type Storyboard, type ValidationError } from "@anvpx/motion-schema";
2
+ /**
3
+ * A transcript may only address what the storyboard actually contains (ADR-0013 §4).
4
+ * This is validated when a transcript is present — never a new lint rule — and reports
5
+ * transcript-relative JSON pointers so a recorder can point at the offending event.
6
+ */
7
+ export declare const validateInteraction: (board: Storyboard, interaction: Interaction) => readonly ValidationError[];
@@ -0,0 +1,32 @@
1
+ import { declaredTargetIds, toJsonPointer, } from "@anvpx/motion-schema";
2
+ /**
3
+ * A transcript may only address what the storyboard actually contains (ADR-0013 §4).
4
+ * This is validated when a transcript is present — never a new lint rule — and reports
5
+ * transcript-relative JSON pointers so a recorder can point at the offending event.
6
+ */
7
+ export const validateInteraction = (board, interaction) => {
8
+ const errors = [];
9
+ const sceneIds = board.scenes.map((scene) => scene.id);
10
+ interaction.events.forEach((event, index) => {
11
+ const sceneIndex = sceneIds.indexOf(event.scene);
12
+ if (sceneIndex < 0) {
13
+ errors.push({
14
+ path: toJsonPointer(["events", index, "scene"]),
15
+ message: `scene "${event.scene}" is not in the storyboard`,
16
+ suggestion: `use one of: ${sceneIds.join("|")}`,
17
+ });
18
+ return;
19
+ }
20
+ const targets = declaredTargetIds(board.scenes[sceneIndex]?.props);
21
+ if (!targets.includes(event.target)) {
22
+ errors.push({
23
+ path: toJsonPointer(["events", index, "target"]),
24
+ message: `target "${event.target}" is not declared by scene "${event.scene}"`,
25
+ suggestion: targets.length === 0
26
+ ? `declare "${event.target}" in that scene's props.targets`
27
+ : `declare it in props.targets, or use one of: ${targets.join("|")}`,
28
+ });
29
+ }
30
+ });
31
+ return errors;
32
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Deterministic raster grain that survives the H.264 delivery chain.
3
+ *
4
+ * HyperFrames writes the master picture; this module builds the ffmpeg argv for a
5
+ * single re-encode that bakes fixed-seed film grain into the pixels. It is a pure
6
+ * function of its inputs: no clock, no randomness, no environment. The mix and
7
+ * loudnorm steps copy the video stream, so grain applied here is present in the
8
+ * delivered mp4 unchanged.
9
+ */
10
+ /** Fixed seed — the same frame always receives the same grain. */
11
+ export declare const GRAIN_SEED = 1337;
12
+ /** Subtle paper-tooth amplitude (noise `alls`): low enough not to read as TV snow. */
13
+ export declare const GRAIN_STRENGTH = 7;
14
+ /** The exact noise filter: uniform form with a per-frame temporal reseed, fixed seed. */
15
+ export declare const GRAIN_FILTER = "noise=alls=7:allf=t+u:all_seed=1337";
16
+ /** Stable descriptor recorded in the render manifest (a code constant, not input). */
17
+ export declare const GRAIN_DESCRIPTOR = "noise:alls=7:allf=t+u:seed=1337";
18
+ /** Intermediate written by the grain pass before it replaces the master. */
19
+ export declare const GRAIN_TEMP = "final-grain.mp4";
20
+ /** The optional delivery lens. `off` is the default and keeps today's exact bytes. */
21
+ export declare const LENS_OFF = "off";
22
+ export declare const LENS_FILM_HALO = "film-halo";
23
+ export type Lens = typeof LENS_OFF | typeof LENS_FILM_HALO;
24
+ export declare const DEFAULT_LENS: Lens;
25
+ /** The single frozen §5.1 filter_complex; the fixed noise filter is its last node. */
26
+ export declare const FILM_HALO_FILTER: string;
27
+ /** Manifest descriptor extended with the active lens: `off` stays byte-identical. */
28
+ export declare function grainDescriptor(lens?: Lens): string;
29
+ /**
30
+ * Builds the deterministic grain argv. Frame rate, frame count, duration, codec
31
+ * family and pixel format are preserved so `mk verify` / finalExpectation still
32
+ * pass. The encode is lossless (CRF 0): a lossy re-encode reconstructs the static
33
+ * fixed-seed grain with a different quantisation phase at each H.264 I-frame,
34
+ * reseeding the whole field by +/-1 LSB (the G-08 frame-500 pop). CRF 0 keeps
35
+ * I-frames and P-frames bit-identical; the tradeoff is a larger delivered mp4.
36
+ *
37
+ * `lens=off` (the default) is today's exact `-vf noise=` argv. `film-halo`
38
+ * replaces that single filter with the frozen §5.1 `filter_complex` inside this
39
+ * same ffmpeg invocation — one renderer, one encode, one source of truth.
40
+ */
41
+ export declare function buildGrainArgs(input: string, output: string, fps: string | number, lens?: Lens): string[];
42
+ /**
43
+ * High-pass energy of an 8-bit gray plane: mean squared deviation of each
44
+ * interior pixel from the average of its horizontal neighbours. A flat field is
45
+ * ~0; added grain raises it. Pure over the buffer — no I/O, no randomness.
46
+ */
47
+ export declare function grainEnergy(gray: Uint8Array, width: number): number;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Deterministic raster grain that survives the H.264 delivery chain.
3
+ *
4
+ * HyperFrames writes the master picture; this module builds the ffmpeg argv for a
5
+ * single re-encode that bakes fixed-seed film grain into the pixels. It is a pure
6
+ * function of its inputs: no clock, no randomness, no environment. The mix and
7
+ * loudnorm steps copy the video stream, so grain applied here is present in the
8
+ * delivered mp4 unchanged.
9
+ */
10
+ /** Fixed seed — the same frame always receives the same grain. */
11
+ export const GRAIN_SEED = 1337;
12
+ /** Subtle paper-tooth amplitude (noise `alls`): low enough not to read as TV snow. */
13
+ export const GRAIN_STRENGTH = 7;
14
+ /** The exact noise filter: uniform form with a per-frame temporal reseed, fixed seed. */
15
+ export const GRAIN_FILTER = `noise=alls=${GRAIN_STRENGTH}:allf=t+u:all_seed=${GRAIN_SEED}`;
16
+ /** Stable descriptor recorded in the render manifest (a code constant, not input). */
17
+ export const GRAIN_DESCRIPTOR = `noise:alls=${GRAIN_STRENGTH}:allf=t+u:seed=${GRAIN_SEED}`;
18
+ /** Intermediate written by the grain pass before it replaces the master. */
19
+ export const GRAIN_TEMP = "final-grain.mp4";
20
+ /** The optional delivery lens. `off` is the default and keeps today's exact bytes. */
21
+ export const LENS_OFF = "off";
22
+ export const LENS_FILM_HALO = "film-halo";
23
+ export const DEFAULT_LENS = LENS_OFF;
24
+ /*
25
+ * VISUAL-R1 §5.1 frozen highlight-halation graph. These stages are fixed constants,
26
+ * not tuned parameters: choosing one named preset before any render prevents
27
+ * post-hoc look-shopping. The same fixed-seed grain filter runs in both A/B arms.
28
+ */
29
+ const HALO_SPLIT = "[0:v]split=2[base][halo]";
30
+ const HALO_MASK = `lutyuv=y='if(lt(val,168),0,(val-168)*255/87)'`;
31
+ const HALO_SPREAD = "gblur=sigma=14:steps=4";
32
+ const HALO_TINT = "colorchannelmixer=rr=1:gg=0.42:bb=0.22";
33
+ const HALO_REJOIN = "blend=all_mode=screen:all_opacity=0.22";
34
+ const HALO_FORMAT_IN = "format=yuv444p";
35
+ const HALO_FORMAT_OUT = "format=yuv420p";
36
+ /** The single frozen §5.1 filter_complex; the fixed noise filter is its last node. */
37
+ export const FILM_HALO_FILTER = [
38
+ HALO_SPLIT,
39
+ `[halo]${HALO_MASK},${HALO_SPREAD},${HALO_TINT},${HALO_FORMAT_IN}[haloPlate]`,
40
+ `[base]${HALO_FORMAT_IN}[basePlate]`,
41
+ `[basePlate][haloPlate]${HALO_REJOIN},${HALO_FORMAT_OUT}[blended]`,
42
+ `[blended]${GRAIN_FILTER}[out]`,
43
+ ].join(";");
44
+ /** Manifest descriptor extended with the active lens: `off` stays byte-identical. */
45
+ export function grainDescriptor(lens = DEFAULT_LENS) {
46
+ return lens === LENS_OFF ? GRAIN_DESCRIPTOR : `${GRAIN_DESCRIPTOR}:lens=${lens}`;
47
+ }
48
+ /**
49
+ * Builds the deterministic grain argv. Frame rate, frame count, duration, codec
50
+ * family and pixel format are preserved so `mk verify` / finalExpectation still
51
+ * pass. The encode is lossless (CRF 0): a lossy re-encode reconstructs the static
52
+ * fixed-seed grain with a different quantisation phase at each H.264 I-frame,
53
+ * reseeding the whole field by +/-1 LSB (the G-08 frame-500 pop). CRF 0 keeps
54
+ * I-frames and P-frames bit-identical; the tradeoff is a larger delivered mp4.
55
+ *
56
+ * `lens=off` (the default) is today's exact `-vf noise=` argv. `film-halo`
57
+ * replaces that single filter with the frozen §5.1 `filter_complex` inside this
58
+ * same ffmpeg invocation — one renderer, one encode, one source of truth.
59
+ */
60
+ export function buildGrainArgs(input, output, fps, lens = DEFAULT_LENS) {
61
+ // `fps` is retained in the signature for call-site stability, but is intentionally
62
+ // not emitted: passthrough preserves the master's frame rate and timestamps exactly.
63
+ void fps;
64
+ const filter = lens === LENS_FILM_HALO
65
+ ? ["-filter_complex", FILM_HALO_FILTER, "-map", "[out]"]
66
+ : ["-vf", GRAIN_FILTER];
67
+ return [
68
+ "-y",
69
+ "-i",
70
+ input,
71
+ ...filter,
72
+ "-c:v",
73
+ "libx264",
74
+ "-preset",
75
+ "slow",
76
+ "-crf",
77
+ "0",
78
+ "-pix_fmt",
79
+ "yuv420p",
80
+ "-color_primaries",
81
+ "bt709",
82
+ "-color_trc",
83
+ "bt709",
84
+ "-colorspace",
85
+ "bt709",
86
+ // No -r here: ffmpeg 7 rejects -r together with a non-CFR -fps_mode.
87
+ // passthrough keeps the source's exact CFR timestamps, so fps needs no restatement.
88
+ "-fps_mode",
89
+ "passthrough",
90
+ "-threads",
91
+ "1",
92
+ "-movflags",
93
+ "+faststart",
94
+ "-an",
95
+ output,
96
+ ];
97
+ }
98
+ /**
99
+ * High-pass energy of an 8-bit gray plane: mean squared deviation of each
100
+ * interior pixel from the average of its horizontal neighbours. A flat field is
101
+ * ~0; added grain raises it. Pure over the buffer — no I/O, no randomness.
102
+ */
103
+ export function grainEnergy(gray, width) {
104
+ const height = Math.floor(gray.length / width);
105
+ if (width < 3 || height < 1)
106
+ return 0;
107
+ let energy = 0;
108
+ let count = 0;
109
+ for (let y = 0; y < height; y += 1) {
110
+ const row = y * width;
111
+ for (let x = 1; x < width - 1; x += 1) {
112
+ const center = gray[row + x] ?? 0;
113
+ const left = gray[row + x - 1] ?? 0;
114
+ const right = gray[row + x + 1] ?? 0;
115
+ const highPass = center - (left + right) / 2;
116
+ energy += highPass * highPass;
117
+ count += 1;
118
+ }
119
+ }
120
+ return count === 0 ? 0 : energy / count;
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvpx/motion-build",
3
- "version": "0.1.56",
3
+ "version": "0.1.95",
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.56",
35
- "@anvpx/motion-schema": "0.1.56",
36
- "@anvpx/motion-themes": "0.1.56",
34
+ "@anvpx/motion-scenes": "0.1.95",
35
+ "@anvpx/motion-schema": "0.1.95",
36
+ "@anvpx/motion-themes": "0.1.95",
37
37
  "postprocessing": "6.39.5",
38
38
  "three": "0.186.0"
39
39
  },