@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.
- package/dist/audio/mix.d.ts +29 -11
- package/dist/audio/mix.js +79 -17
- package/dist/build.d.ts +15 -1
- package/dist/build.js +85 -16
- package/dist/emit/boot.d.ts +17 -2
- package/dist/emit/boot.js +31 -4
- package/dist/emit/boot.template.js +4 -4
- package/dist/emit/index-html.js +3 -0
- package/dist/emit/interaction-runtime.d.ts +11 -0
- package/dist/emit/interaction-runtime.js +121 -0
- package/dist/emit/vendor.d.ts +23 -0
- package/dist/emit/vendor.js +12 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lint/beat-variety.d.ts +17 -0
- package/dist/lint/beat-variety.js +92 -0
- package/dist/lint/custom-source.d.ts +6 -0
- package/dist/lint/custom-source.js +201 -6
- package/dist/lint/index.d.ts +4 -1
- package/dist/lint/index.js +9 -1
- package/dist/lint/visual-variety.d.ts +16 -0
- package/dist/lint/visual-variety.js +72 -0
- package/dist/lint/world-stops.d.ts +11 -0
- package/dist/lint/world-stops.js +39 -0
- package/dist/templates/catalog-quality.d.ts +70 -0
- package/dist/templates/catalog-quality.js +221 -0
- package/dist/templates/index.d.ts +2 -1
- package/dist/templates/index.js +2 -1
- package/dist/templates/search.d.ts +11 -0
- package/dist/templates/search.js +12 -0
- package/dist/templates/validate.d.ts +2 -1
- package/dist/templates/validate.js +6 -23
- package/dist/validate-full.js +38 -45
- package/dist/validate-interaction.d.ts +7 -0
- package/dist/validate-interaction.js +32 -0
- package/dist/video/grain.d.ts +47 -0
- package/dist/video/grain.js +121 -0
- package/package.json +4 -4
package/dist/audio/mix.d.ts
CHANGED
|
@@ -78,6 +78,8 @@ export declare const resolveMusicVolume: (music: MusicBed) => number;
|
|
|
78
78
|
* An absent bed (`undefined`) means narration-only — never a silent fallback.
|
|
79
79
|
*/
|
|
80
80
|
export declare const missingMusic: (music: MusicBed | undefined, exists: (path: string) => boolean) => string[];
|
|
81
|
+
/** Final fade on music-only output: with no speech tail, a cut waveform is audible. */
|
|
82
|
+
export declare const MUSIC_ONLY_FADE_SEC = 0.1;
|
|
81
83
|
/**
|
|
82
84
|
* Deterministic `-filter_complex` graph ducking a user CC0 bed under narration.
|
|
83
85
|
* Narration mixes onto `[narr]` (same rules as {@link buildFilterGraph}), splits
|
|
@@ -90,8 +92,15 @@ export declare const missingMusic: (music: MusicBed | undefined, exists: (path:
|
|
|
90
92
|
* The bed is re-validated through the schema single source first: a raw
|
|
91
93
|
* `{ wav }` that never passed `parseMusicBed`/`validateMusicBed` (traversal,
|
|
92
94
|
* non-wav, bad level) throws here instead of reaching ffmpeg.
|
|
95
|
+
*
|
|
96
|
+
* An explicitly absent narration (`clips: []`) with a valid bed is a real
|
|
97
|
+
* music-only mix, not a silent film: the bed loops to the supplied picture
|
|
98
|
+
* length and fades out over its last {@link MUSIC_ONLY_FADE_SEC} (clamped to
|
|
99
|
+
* half a shorter picture). Nothing is keyed and no speech track is invented,
|
|
100
|
+
* so a sidechain keyed on silence never enters the graph. Without a picture
|
|
101
|
+
* length there is no trim authority at all, so that case fails closed.
|
|
93
102
|
*/
|
|
94
|
-
export declare const buildMusicFilterGraph: (clips: readonly MixClip[], music: MusicBed) => string;
|
|
103
|
+
export declare const buildMusicFilterGraph: (clips: readonly MixClip[], music: MusicBed, filmDurationSec?: number) => string;
|
|
95
104
|
/** Role of a frozen wav; the role is part of the injective frozen name. */
|
|
96
105
|
export type FrozenRole = "narration" | "music";
|
|
97
106
|
/**
|
|
@@ -147,7 +156,7 @@ export declare const musicLoopFor: (bedDuration: number, clips: readonly MixClip
|
|
|
147
156
|
* (`-c:v copy`), bed ducked under narration and mixed to aac. No `-shortest`;
|
|
148
157
|
* the picture keeps its authored tail after the last word.
|
|
149
158
|
*/
|
|
150
|
-
export declare const buildMusicMixArgs: (videoIn: string, clips: readonly MixClip[], music: MusicBed, out: string) => string[];
|
|
159
|
+
export declare const buildMusicMixArgs: (videoIn: string, clips: readonly MixClip[], music: MusicBed, out: string, filmDurationSec?: number) => string[];
|
|
151
160
|
/**
|
|
152
161
|
* Delivery loudness (fixed, no CLI flag). Kokoro narration lands near -26 LUFS,
|
|
153
162
|
* so the mix would otherwise fail every verified platform policy; the mixed
|
|
@@ -217,6 +226,11 @@ export interface MixDeliveryPlan {
|
|
|
217
226
|
readonly videoIn: string;
|
|
218
227
|
readonly clips: readonly MixClip[];
|
|
219
228
|
readonly music?: MusicBed;
|
|
229
|
+
/**
|
|
230
|
+
* Picture length in seconds; the score is trimmed to it. Absent keeps the
|
|
231
|
+
* narration tail, so it is required when there is no narration to size the bed.
|
|
232
|
+
*/
|
|
233
|
+
readonly durationSec?: number;
|
|
220
234
|
/** The path the mix wrote before normalization; normalization rewrites it in place. */
|
|
221
235
|
readonly out: string;
|
|
222
236
|
/** Moves the normalized temp file over `out` (fs in the CLI, a fake in tests). */
|
|
@@ -232,14 +246,18 @@ export interface MixDelivery {
|
|
|
232
246
|
/**
|
|
233
247
|
* Mixes to `plan.out`, then normalizes that same file to delivery level.
|
|
234
248
|
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* pass
|
|
249
|
+
* A film with no sound input at all stays silent (no clips and no bed → no
|
|
250
|
+
* ffmpeg at all). A bed with explicitly absent narration is a music-only mix:
|
|
251
|
+
* it runs to `plan.durationSec`, fades out at the picture end, and fails closed
|
|
252
|
+
* when that picture length is missing (nothing else sizes the bed).
|
|
253
|
+
*
|
|
254
|
+
* An already-levelled mix skips pass 2, so normalizing twice never moves the
|
|
255
|
+
* level. One linear gain cannot always reach the target under the peak ceiling
|
|
256
|
+
* (loudnorm then runs its dynamic fallback and can land ~0.8 LU short), so the
|
|
257
|
+
* level is re-measured after each pass and one corrective pass may follow: the
|
|
258
|
+
* delivered file sits inside the 0.5 LU guard whenever the material allows it,
|
|
259
|
+
* which is what keeps a second normalizing run a no-op. Unmeasurable audio is
|
|
260
|
+
* left exactly as the mix produced it and reported in `problems`; a failed mix
|
|
261
|
+
* or a failed loudnorm pass fails delivery.
|
|
244
262
|
*/
|
|
245
263
|
export declare const mixAtDeliveryLevel: (run: MixRunner, plan: MixDeliveryPlan) => Promise<MixDelivery>;
|
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,
|
|
@@ -152,6 +154,24 @@ const requireValidBed = (music) => {
|
|
|
152
154
|
throw new Error(`invalid music bed: ${parsed.hint}`);
|
|
153
155
|
}
|
|
154
156
|
};
|
|
157
|
+
/** Final fade on music-only output: with no speech tail, a cut waveform is audible. */
|
|
158
|
+
export const MUSIC_ONLY_FADE_SEC = 0.1;
|
|
159
|
+
/** Named once: the graph builder and the delivery plan report the same refusal. */
|
|
160
|
+
const MUSIC_ONLY_NEEDS_PICTURE = "music-only mix needs the picture duration: no narration sizes the bed";
|
|
161
|
+
/**
|
|
162
|
+
* Deterministic seconds inside a filter arg: microsecond rounding, so the same
|
|
163
|
+
* duration always yields the same bytes and never a float tail.
|
|
164
|
+
*/
|
|
165
|
+
const filterSeconds = (value) => String(Number(value.toFixed(6)));
|
|
166
|
+
/**
|
|
167
|
+
* Final fade window for a bed of `pictureSec` seconds: {@link MUSIC_ONLY_FADE_SEC},
|
|
168
|
+
* clamped to half the picture so a sub-200 ms fixture still fades from a real
|
|
169
|
+
* sample instead of starting before the bed does.
|
|
170
|
+
*/
|
|
171
|
+
const musicOnlyFade = (pictureSec) => {
|
|
172
|
+
const seconds = Math.min(MUSIC_ONLY_FADE_SEC, pictureSec / 2);
|
|
173
|
+
return { startSec: pictureSec - seconds, seconds };
|
|
174
|
+
};
|
|
155
175
|
/** Timeline length covered by narration; the bed loops (`aloop`) then trims to it. */
|
|
156
176
|
const narrationTotal = (clips) => clips.reduce((max, clip) => Math.max(max, clip.start + clip.duration), 0);
|
|
157
177
|
/**
|
|
@@ -166,15 +186,31 @@ const narrationTotal = (clips) => clips.reduce((max, clip) => Math.max(max, clip
|
|
|
166
186
|
* The bed is re-validated through the schema single source first: a raw
|
|
167
187
|
* `{ wav }` that never passed `parseMusicBed`/`validateMusicBed` (traversal,
|
|
168
188
|
* non-wav, bad level) throws here instead of reaching ffmpeg.
|
|
189
|
+
*
|
|
190
|
+
* An explicitly absent narration (`clips: []`) with a valid bed is a real
|
|
191
|
+
* music-only mix, not a silent film: the bed loops to the supplied picture
|
|
192
|
+
* length and fades out over its last {@link MUSIC_ONLY_FADE_SEC} (clamped to
|
|
193
|
+
* half a shorter picture). Nothing is keyed and no speech track is invented,
|
|
194
|
+
* so a sidechain keyed on silence never enters the graph. Without a picture
|
|
195
|
+
* length there is no trim authority at all, so that case fails closed.
|
|
169
196
|
*/
|
|
170
|
-
export const buildMusicFilterGraph = (clips, music) => {
|
|
171
|
-
if (clips.length === 0)
|
|
172
|
-
throw new Error("mixdown needs at least one narration clip");
|
|
197
|
+
export const buildMusicFilterGraph = (clips, music, filmDurationSec) => {
|
|
173
198
|
requireValidBed(music);
|
|
174
199
|
const volume = resolveMusicVolume(music);
|
|
175
200
|
const musicIndex = clips.length + 1;
|
|
201
|
+
// The score runs to the end of the picture, not the end of the last spoken word:
|
|
202
|
+
// a silent end card must still have music under it.
|
|
203
|
+
const pictureSec = filmDurationSec !== undefined && filmDurationSec > 0 ? filmDurationSec : undefined;
|
|
204
|
+
if (clips.length === 0) {
|
|
205
|
+
if (pictureSec === undefined)
|
|
206
|
+
throw new Error(MUSIC_ONLY_NEEDS_PICTURE);
|
|
207
|
+
const fade = musicOnlyFade(pictureSec);
|
|
208
|
+
return (`[${musicIndex}:a]volume=${volume},aloop=loop=-1:size=2e9,atrim=duration=${filterSeconds(pictureSec)},` +
|
|
209
|
+
`afade=t=out:st=${filterSeconds(fade.startSec)}:d=${filterSeconds(fade.seconds)}[mbed];` +
|
|
210
|
+
`[mbed]${AUDIO_LIMITER}[aout]`);
|
|
211
|
+
}
|
|
176
212
|
const narr = narrationGraph(clips, "narr");
|
|
177
|
-
const total = toDelayMs(narrationTotal(clips)) / 1000;
|
|
213
|
+
const total = pictureSec ?? toDelayMs(narrationTotal(clips)) / 1000;
|
|
178
214
|
const sidechain = `sidechaincompress=threshold=${SIDECHAIN_THRESHOLD}:ratio=${SIDECHAIN_RATIO}` +
|
|
179
215
|
`:attack=${SIDECHAIN_ATTACK_MS}:release=${SIDECHAIN_RELEASE_MS}`;
|
|
180
216
|
return (`[${musicIndex}:a]volume=${volume},aloop=loop=-1:size=2e9,atrim=duration=${total}[mbed];` +
|
|
@@ -279,7 +315,7 @@ export const musicLoopFor = (bedDuration, clips) => {
|
|
|
279
315
|
* (`-c:v copy`), bed ducked under narration and mixed to aac. No `-shortest`;
|
|
280
316
|
* the picture keeps its authored tail after the last word.
|
|
281
317
|
*/
|
|
282
|
-
export const buildMusicMixArgs = (videoIn, clips, music, out) => [
|
|
318
|
+
export const buildMusicMixArgs = (videoIn, clips, music, out, filmDurationSec) => [
|
|
283
319
|
"-y",
|
|
284
320
|
"-i",
|
|
285
321
|
videoIn,
|
|
@@ -287,7 +323,7 @@ export const buildMusicMixArgs = (videoIn, clips, music, out) => [
|
|
|
287
323
|
"-i",
|
|
288
324
|
music.wav,
|
|
289
325
|
"-filter_complex",
|
|
290
|
-
buildMusicFilterGraph(clips, music),
|
|
326
|
+
buildMusicFilterGraph(clips, music, filmDurationSec),
|
|
291
327
|
"-map",
|
|
292
328
|
"0:v:0",
|
|
293
329
|
"-map",
|
|
@@ -296,6 +332,8 @@ export const buildMusicMixArgs = (videoIn, clips, music, out) => [
|
|
|
296
332
|
"copy",
|
|
297
333
|
"-c:a",
|
|
298
334
|
"aac",
|
|
335
|
+
"-ar",
|
|
336
|
+
"48000",
|
|
299
337
|
"-movflags",
|
|
300
338
|
"+faststart",
|
|
301
339
|
out,
|
|
@@ -427,23 +465,38 @@ export const buildLoudnessNormalizeArgs = (input, measurement, out) => [
|
|
|
427
465
|
"aac",
|
|
428
466
|
"-b:a",
|
|
429
467
|
"192k",
|
|
468
|
+
"-ar",
|
|
469
|
+
"48000",
|
|
430
470
|
"-movflags",
|
|
431
471
|
"+faststart",
|
|
432
472
|
out,
|
|
433
473
|
];
|
|
434
474
|
const firstLine = (text) => text.split(/\r?\n/).find((line) => line.trim() !== "") ?? "";
|
|
475
|
+
/** True for a usable picture length: finite and positive (a real trim authority). */
|
|
476
|
+
const hasPictureDuration = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
477
|
+
const soundInputFor = (plan) => {
|
|
478
|
+
if (plan.clips.length > 0)
|
|
479
|
+
return "mix";
|
|
480
|
+
if (plan.music === undefined)
|
|
481
|
+
return "silent";
|
|
482
|
+
return hasPictureDuration(plan.durationSec) ? "mix" : "unsized";
|
|
483
|
+
};
|
|
435
484
|
/**
|
|
436
485
|
* Mixes to `plan.out`, then normalizes that same file to delivery level.
|
|
437
486
|
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
* pass
|
|
487
|
+
* A film with no sound input at all stays silent (no clips and no bed → no
|
|
488
|
+
* ffmpeg at all). A bed with explicitly absent narration is a music-only mix:
|
|
489
|
+
* it runs to `plan.durationSec`, fades out at the picture end, and fails closed
|
|
490
|
+
* when that picture length is missing (nothing else sizes the bed).
|
|
491
|
+
*
|
|
492
|
+
* An already-levelled mix skips pass 2, so normalizing twice never moves the
|
|
493
|
+
* level. One linear gain cannot always reach the target under the peak ceiling
|
|
494
|
+
* (loudnorm then runs its dynamic fallback and can land ~0.8 LU short), so the
|
|
495
|
+
* level is re-measured after each pass and one corrective pass may follow: the
|
|
496
|
+
* delivered file sits inside the 0.5 LU guard whenever the material allows it,
|
|
497
|
+
* which is what keeps a second normalizing run a no-op. Unmeasurable audio is
|
|
498
|
+
* left exactly as the mix produced it and reported in `problems`; a failed mix
|
|
499
|
+
* or a failed loudnorm pass fails delivery.
|
|
447
500
|
*/
|
|
448
501
|
export const mixAtDeliveryLevel = async (run, plan) => {
|
|
449
502
|
const skipped = (problems = [], measurement = null) => ({ ok: true, out: plan.out, normalized: false, measurement, problems });
|
|
@@ -454,11 +507,20 @@ export const mixAtDeliveryLevel = async (run, plan) => {
|
|
|
454
507
|
? parseLoudnessMeasurement(`${probed.stdout}\n${probed.stderr}`)
|
|
455
508
|
: undefined;
|
|
456
509
|
};
|
|
457
|
-
|
|
510
|
+
// Sound-input policy: a film with no sound source at all stays silent (no ffmpeg,
|
|
511
|
+
// no invented track), while music-only is only mixable with a picture length.
|
|
512
|
+
const sound = soundInputFor(plan);
|
|
513
|
+
if (sound === "silent")
|
|
458
514
|
return skipped();
|
|
515
|
+
if (sound === "unsized")
|
|
516
|
+
return failed([MUSIC_ONLY_NEEDS_PICTURE]);
|
|
517
|
+
// The score runs to the end of the picture. `durationSec` is the built film total,
|
|
518
|
+
// supplied by the caller (which already knows it from the timeline); without it the
|
|
519
|
+
// bed stops at the last spoken word, which is the pre-existing behaviour. This
|
|
520
|
+
// function never probes: its runner is an ffmpeg-only channel.
|
|
459
521
|
const mixArgs = plan.music === undefined
|
|
460
522
|
? buildMixArgs(plan.videoIn, plan.clips, plan.out)
|
|
461
|
-
: buildMusicMixArgs(plan.videoIn, plan.clips, plan.music, plan.out);
|
|
523
|
+
: buildMusicMixArgs(plan.videoIn, plan.clips, plan.music, plan.out, plan.durationSec);
|
|
462
524
|
const mixed = await run(mixArgs);
|
|
463
525
|
if (mixed.code !== 0)
|
|
464
526
|
return failed([`mix failed: ${firstLine(mixed.stderr)}`]);
|
package/dist/build.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CustomSceneSource } from "@anvpx/motion-scenes";
|
|
2
|
-
import type { AssetLedger, AssetRow, ResolvedTheme, TimingManifest, ValidationError } from "@anvpx/motion-schema";
|
|
2
|
+
import type { AssetLedger, AssetRow, Interaction, ResolvedTheme, TimingManifest, ValidationError } from "@anvpx/motion-schema";
|
|
3
3
|
import { type AudioManifestRef } from "./audio/mix.ts";
|
|
4
4
|
import { type CacheStats } from "./cache.ts";
|
|
5
5
|
import { type LintFinding, type PlatformMarginLookup } from "./lint/index.ts";
|
|
@@ -44,6 +44,20 @@ export interface BuildOptions {
|
|
|
44
44
|
* a source here fails the build instead of emitting an empty scene.
|
|
45
45
|
*/
|
|
46
46
|
readonly customScenes?: Readonly<Record<string, CustomSceneSource>>;
|
|
47
|
+
/**
|
|
48
|
+
* Parsed interaction transcript for this project (ADR-0013). The caller reads
|
|
49
|
+
* `interaction.json` beside the storyboard; absent means an ordinary, unchanged build.
|
|
50
|
+
* Present: validated against the board, written into the project and folded into each
|
|
51
|
+
* scene's emit context through `stateAt`. This alone leaves boot.js unchanged; pass
|
|
52
|
+
* `interactive: true` (as the CLI does for render/still) to seed it for playback.
|
|
53
|
+
*/
|
|
54
|
+
readonly interaction?: Interaction;
|
|
55
|
+
/**
|
|
56
|
+
* ADR-0013 slice 2b: emit boot.js with the runtime `ctx.interaction.at(t)` accessor and
|
|
57
|
+
* accept folded state on `hf-seek`. Used by `mk publish --interactive`; absent means the
|
|
58
|
+
* ordinary boot bytes, byte-for-byte unchanged.
|
|
59
|
+
*/
|
|
60
|
+
readonly interactive?: boolean;
|
|
47
61
|
}
|
|
48
62
|
export type BuildResult = {
|
|
49
63
|
readonly ok: true;
|
package/dist/build.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
-
import { CUSTOM_SCENE_TYPE, collectIcons, emitCustomScene, getScene, iconLedgerRows, LUCIDE_LICENCE_TEXT, runtimeFiles, sceneWords, } from "@anvpx/motion-scenes";
|
|
4
|
-
import { canonicalJson } from "@anvpx/motion-schema";
|
|
5
|
-
import { bundledThemeDocs, resolveGrades, resolveTheme, toCssVars, toGradeCssVars, } from "@anvpx/motion-themes";
|
|
3
|
+
import { CUSTOM_SCENE_TYPE, collectIcons, emitCustomScene, getScene, iconLedgerRows, LUCIDE_LICENCE_TEXT, runtimeFiles, scanVendorImports, sceneWords, } from "@anvpx/motion-scenes";
|
|
4
|
+
import { canonicalJson, stateAt } from "@anvpx/motion-schema";
|
|
5
|
+
import { bundledThemeDocs, resolveGrades, resolveTheme, themeAccessibility, toCssVars, toGradeCssVars, } from "@anvpx/motion-themes";
|
|
6
6
|
import { copyAssets, createAssetCollector, sha256Of } from "./assets.js";
|
|
7
7
|
import { clipsFromManifest, missingClips } from "./audio/mix.js";
|
|
8
8
|
import { createCachePlan, emitCached } from "./cache.js";
|
|
@@ -11,18 +11,20 @@ import { assertInertFragment } from "./emit/fragment-guard.js";
|
|
|
11
11
|
import { renderIndexHtml } from "./emit/index-html.js";
|
|
12
12
|
import { renderImportMap, vendorFiles, vendorLibs } from "./emit/vendor.js";
|
|
13
13
|
import { bundleFonts, fontFamiliesFor } from "./fonts.js";
|
|
14
|
+
import { collectCustomFindings } from "./lint/custom-source.js";
|
|
14
15
|
import { lintStoryboard, } from "./lint/index.js";
|
|
15
16
|
import { createManifest, renderManifest, } from "./manifest.js";
|
|
16
17
|
import { GRADE_REVIEW_PATH, renderGradeReview } from "./review/review.js";
|
|
17
18
|
import { resolveTimeline } from "./timing.js";
|
|
18
19
|
import { validateStoryboardFull } from "./validate-full.js";
|
|
20
|
+
import { validateInteraction } from "./validate-interaction.js";
|
|
19
21
|
import { readVersions } from "./versions.js";
|
|
20
22
|
const fail = (path, message) => ({
|
|
21
23
|
ok: false,
|
|
22
24
|
errors: [{ path, message }],
|
|
23
25
|
});
|
|
24
26
|
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
25
|
-
const
|
|
27
|
+
const resolveThemeOf = (name, docs) => {
|
|
26
28
|
try {
|
|
27
29
|
return { ok: true, value: resolveTheme(name, { ...bundledThemeDocs(), ...docs }) };
|
|
28
30
|
}
|
|
@@ -30,9 +32,38 @@ const themeOf = (name, docs) => {
|
|
|
30
32
|
return fail("/meta/theme", messageOf(error));
|
|
31
33
|
}
|
|
32
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Resolves a theme and runs the shared accessibility authority on it. Text AA failures
|
|
37
|
+
* become errors at `/meta/theme`; spacing and non-strict chart findings are warnings,
|
|
38
|
+
* so an existing project theme still builds while it is being improved.
|
|
39
|
+
*/
|
|
40
|
+
const themeOf = (name, docs) => {
|
|
41
|
+
const resolved = resolveThemeOf(name, docs);
|
|
42
|
+
if (!resolved.ok)
|
|
43
|
+
return { ...resolved, warnings: [] };
|
|
44
|
+
const doc = docs?.[name];
|
|
45
|
+
// Built-in themes are already gated by the template validator. Only user project
|
|
46
|
+
// themes need the runtime check, so their findings do not dilute built-in lint.
|
|
47
|
+
if (doc === undefined)
|
|
48
|
+
return { ok: true, value: resolved.value, warnings: [] };
|
|
49
|
+
const report = themeAccessibility(resolved.value, doc);
|
|
50
|
+
const errors = report.errors.map((issue) => ({
|
|
51
|
+
path: "/meta/theme",
|
|
52
|
+
message: issue.message,
|
|
53
|
+
...(issue.suggestion === undefined ? {} : { suggestion: issue.suggestion }),
|
|
54
|
+
}));
|
|
55
|
+
const warnings = report.warnings.map((issue) => ({
|
|
56
|
+
severity: "warning",
|
|
57
|
+
path: "/meta/theme",
|
|
58
|
+
message: issue.message,
|
|
59
|
+
}));
|
|
60
|
+
return errors.length > 0
|
|
61
|
+
? { ok: false, errors, warnings }
|
|
62
|
+
: { ok: true, value: resolved.value, warnings };
|
|
63
|
+
};
|
|
33
64
|
/** A theme by name, or undefined when it is unknown (callers that only lint skip theme rules). */
|
|
34
65
|
export const tryResolveTheme = (name, docs) => {
|
|
35
|
-
const found =
|
|
66
|
+
const found = resolveThemeOf(name, docs);
|
|
36
67
|
return found.ok ? found.value : undefined;
|
|
37
68
|
};
|
|
38
69
|
/** Base scenes in order, then overlays in declared order (later in the page = higher z-order). */
|
|
@@ -51,7 +82,7 @@ const insetsOf = (board, platforms) => {
|
|
|
51
82
|
const insets = platform === undefined ? undefined : platforms?.(platform)?.safeZones;
|
|
52
83
|
return insets === undefined ? {} : { insets };
|
|
53
84
|
};
|
|
54
|
-
const contextOf = (board, placed, total, theme, assets, platforms) => ({
|
|
85
|
+
const contextOf = (board, placed, total, theme, assets, platforms, interaction) => ({
|
|
55
86
|
theme,
|
|
56
87
|
...insetsOf(board, platforms),
|
|
57
88
|
fps: board.meta.fps,
|
|
@@ -59,6 +90,11 @@ const contextOf = (board, placed, total, theme, assets, platforms) => ({
|
|
|
59
90
|
height: board.meta.height,
|
|
60
91
|
duration: placed.duration,
|
|
61
92
|
timeline: { start: placed.start, total },
|
|
93
|
+
// One accessor per project; `stateAt` folds the same events at whatever film time a
|
|
94
|
+
// scene asks for. No clock, randomness or DOM — the map is a pure function of `t`.
|
|
95
|
+
...(interaction === undefined
|
|
96
|
+
? {}
|
|
97
|
+
: { interaction: { at: (t) => stateAt(interaction.events, t) } }),
|
|
62
98
|
assetResolver: assets.resolver,
|
|
63
99
|
});
|
|
64
100
|
/** Runs an emit and appends the icon names it drew to `icons`. */
|
|
@@ -72,6 +108,23 @@ const emitScene = (entry, { placed, final }, ctx, plan, customScenes) => {
|
|
|
72
108
|
if (entry.type === CUSTOM_SCENE_TYPE && source === undefined) {
|
|
73
109
|
return fail(`/scenes/${placed.index}`, `custom scene "${entry.id}" has no source; keep its directory beside the storyboard and set props.dir`);
|
|
74
110
|
}
|
|
111
|
+
// The declared vendor list is a declaration, not the authority: the script's own bare
|
|
112
|
+
// imports are. Union both and fail closed on a specifier nothing vendors, so a library
|
|
113
|
+
// consumer cannot emit a page whose import the scanner would have rejected in the CLI.
|
|
114
|
+
const scan = source === undefined ? undefined : scanVendorImports(source.js);
|
|
115
|
+
const unknown = scan?.unknown ?? [];
|
|
116
|
+
if (unknown.length > 0) {
|
|
117
|
+
return {
|
|
118
|
+
ok: false,
|
|
119
|
+
errors: [
|
|
120
|
+
{
|
|
121
|
+
path: `/scenes/${placed.index}`,
|
|
122
|
+
message: `custom scene "${entry.id}" imports ${unknown.map((name) => `"${name}"`).join(", ")}, which the emitted page cannot resolve`,
|
|
123
|
+
suggestion: "import three or postprocessing, or use a relative path (./, ../) inside the scene",
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
75
128
|
try {
|
|
76
129
|
const icons = [];
|
|
77
130
|
const emit = (context) => source === undefined
|
|
@@ -97,7 +150,9 @@ const emitScene = (entry, { placed, final }, ctx, plan, customScenes) => {
|
|
|
97
150
|
boot: { timed: placed, final, config },
|
|
98
151
|
files,
|
|
99
152
|
icons,
|
|
100
|
-
vendor: source === undefined
|
|
153
|
+
vendor: source === undefined
|
|
154
|
+
? (getScene(entry.type).vendor ?? [])
|
|
155
|
+
: vendorLibs([...(source.vendor ?? []), ...(scan?.libs ?? [])]),
|
|
101
156
|
},
|
|
102
157
|
};
|
|
103
158
|
}
|
|
@@ -105,14 +160,14 @@ const emitScene = (entry, { placed, final }, ctx, plan, customScenes) => {
|
|
|
105
160
|
return fail(`/scenes/${placed.index}`, messageOf(error));
|
|
106
161
|
}
|
|
107
162
|
};
|
|
108
|
-
const emitAll = (board, timeline, theme, assets, plan, platforms, customScenes) => {
|
|
163
|
+
const emitAll = (board, timeline, theme, assets, plan, platforms, customScenes, interaction) => {
|
|
109
164
|
const emitted = [];
|
|
110
165
|
const errors = [];
|
|
111
166
|
for (const placement of placementsOf(timeline)) {
|
|
112
167
|
const entry = board.scenes[placement.placed.index];
|
|
113
168
|
if (!entry)
|
|
114
169
|
continue;
|
|
115
|
-
const ctx = contextOf(board, placement.placed, timeline.total, theme, assets, platforms);
|
|
170
|
+
const ctx = contextOf(board, placement.placed, timeline.total, theme, assets, platforms, interaction);
|
|
116
171
|
const result = emitScene(entry, placement, ctx, plan, customScenes);
|
|
117
172
|
if (result.ok)
|
|
118
173
|
emitted.push(result.value);
|
|
@@ -121,7 +176,7 @@ const emitAll = (board, timeline, theme, assets, plan, platforms, customScenes)
|
|
|
121
176
|
}
|
|
122
177
|
return errors.length > 0 ? { ok: false, errors } : { ok: true, value: emitted };
|
|
123
178
|
};
|
|
124
|
-
const assemble = (board, timeline, theme, emitted, assetFiles, fonts) => {
|
|
179
|
+
const assemble = (board, timeline, theme, emitted, assetFiles, fonts, interactive, interaction) => {
|
|
125
180
|
const files = new Map();
|
|
126
181
|
const themeCss = toCssVars(theme);
|
|
127
182
|
const grades = resolveGrades();
|
|
@@ -134,7 +189,7 @@ const assemble = (board, timeline, theme, emitted, assetFiles, fonts) => {
|
|
|
134
189
|
scenes: emitted.map((scene) => scene.page),
|
|
135
190
|
importMap: renderImportMap(libs),
|
|
136
191
|
}));
|
|
137
|
-
files.set("boot.js", renderBoot(emitted.map((scene) => scene.boot), board.meta.fps));
|
|
192
|
+
files.set("boot.js", renderBoot(emitted.map((scene) => scene.boot), board.meta.fps, interactive, interaction?.events));
|
|
138
193
|
for (const [path, text] of runtimeFiles())
|
|
139
194
|
files.set(path, text);
|
|
140
195
|
for (const [path, bytes] of vendorFiles(libs))
|
|
@@ -193,6 +248,11 @@ const compile = (options) => {
|
|
|
193
248
|
if (!valid.ok)
|
|
194
249
|
return valid;
|
|
195
250
|
const board = valid.value;
|
|
251
|
+
if (options.interaction !== undefined) {
|
|
252
|
+
const interactionErrors = validateInteraction(board, options.interaction);
|
|
253
|
+
if (interactionErrors.length > 0)
|
|
254
|
+
return { ok: false, errors: interactionErrors };
|
|
255
|
+
}
|
|
196
256
|
const theme = themeOf(board.meta.theme, options.themes);
|
|
197
257
|
if (!theme.ok)
|
|
198
258
|
return theme;
|
|
@@ -203,11 +263,16 @@ const compile = (options) => {
|
|
|
203
263
|
if (!audio.ok)
|
|
204
264
|
return audio;
|
|
205
265
|
const lint = runLint(options, board, timeline.value, theme.value);
|
|
206
|
-
|
|
207
|
-
|
|
266
|
+
const customFindings = collectCustomFindings(board.scenes.filter((scene) => scene.type === CUSTOM_SCENE_TYPE).map((scene) => scene.id), options.customScenes);
|
|
267
|
+
const errors = new Map();
|
|
268
|
+
for (const error of [...toErrors(lint.errors), ...toErrors(customFindings)]) {
|
|
269
|
+
errors.set(`${error.path}\u0000${error.message}`, error);
|
|
270
|
+
}
|
|
271
|
+
if (errors.size > 0)
|
|
272
|
+
return { ok: false, errors: [...errors.values()] };
|
|
208
273
|
const assets = createAssetCollector(options.assetsDir !== undefined);
|
|
209
274
|
const plan = cachePlanOf(options.cacheDir, theme.value, options.assetsDir, options.sharedCacheDir);
|
|
210
|
-
const emitted = emitAll(board, timeline.value, theme.value, assets, plan, options.platforms, options.customScenes);
|
|
275
|
+
const emitted = emitAll(board, timeline.value, theme.value, assets, plan, options.platforms, options.customScenes, options.interaction);
|
|
211
276
|
if (!emitted.ok)
|
|
212
277
|
return emitted;
|
|
213
278
|
const copied = copyAssets(assets.refs(), options.assetsDir, options.ledger);
|
|
@@ -217,7 +282,11 @@ const compile = (options) => {
|
|
|
217
282
|
const fonts = bundleFonts(fontFamiliesFor(theme.value.fonts));
|
|
218
283
|
const icons = [...new Set(emitted.value.flatMap((scene) => scene.icons))].sort();
|
|
219
284
|
const licences = [...fonts.licences, ...iconLedgerRows(icons), ...copied.licences];
|
|
220
|
-
const files = assemble(board, timeline.value, theme.value, emitted.value, assetFiles, fonts.files);
|
|
285
|
+
const files = assemble(board, timeline.value, theme.value, emitted.value, assetFiles, fonts.files, options.interactive === true, options.interactive === true ? options.interaction : undefined);
|
|
286
|
+
// Canonical bytes: the transcript is diffable and joins the manifest's approval identity.
|
|
287
|
+
if (options.interaction !== undefined) {
|
|
288
|
+
files.set("interaction.json", canonicalJson(options.interaction));
|
|
289
|
+
}
|
|
221
290
|
if (icons.length > 0)
|
|
222
291
|
files.set("LICENSE-lucide.txt", LUCIDE_LICENCE_TEXT);
|
|
223
292
|
files.set("licences.json", `${JSON.stringify(licences, null, 2)}
|
|
@@ -236,7 +305,7 @@ const compile = (options) => {
|
|
|
236
305
|
files,
|
|
237
306
|
manifest,
|
|
238
307
|
licences,
|
|
239
|
-
warnings: lint.warnings,
|
|
308
|
+
warnings: [...theme.warnings, ...lint.warnings],
|
|
240
309
|
...(plan ? { cache: plan.stats } : {}),
|
|
241
310
|
},
|
|
242
311
|
};
|
package/dist/emit/boot.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InteractionEvent } from "@anvpx/motion-schema";
|
|
1
2
|
import type { TimedScene } from "../timing.ts";
|
|
2
3
|
export interface BootScene {
|
|
3
4
|
readonly timed: Pick<TimedScene, "id" | "start" | "duration" | "overlap"> & {
|
|
@@ -12,5 +13,19 @@ export interface BootScene {
|
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
export declare const clipId: (sceneId: string) => string;
|
|
15
|
-
/**
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The single boot.js: mounts every scene and wires one `hf-seek` listener.
|
|
18
|
+
*
|
|
19
|
+
* ADR-0013 slice 2b: when `interaction` is set, that same listener also accepts the
|
|
20
|
+
* wrapper's interaction transcript in `event.detail.transcript`, and every scene reaches
|
|
21
|
+
* folded state through the slice-2a accessor `ctx.interaction.at(t)`. The fold is the
|
|
22
|
+
* schema's `stateAt` (pinned by `boot.test.ts`), so state is a pure function of film time.
|
|
23
|
+
* The composition still renders only on `hf-seek` — no pointer, key or message listener is
|
|
24
|
+
* added. Without the flag the emitted bytes are exactly as before, so an ordinary build
|
|
25
|
+
* (and `mk publish` without `--interactive`) is unchanged.
|
|
26
|
+
*
|
|
27
|
+
* ADR-0013 slice 2c: `transcript` seeds the same runtime before the scenes mount, which is
|
|
28
|
+
* how `mk render --interaction` hands a recorded transcript to the composition. The seeded
|
|
29
|
+
* array is data, folded by the same reducer; no listener is added.
|
|
30
|
+
*/
|
|
31
|
+
export declare const renderBoot: (scenes: readonly BootScene[], fps: number, interaction?: boolean, transcript?: readonly InteractionEvent[]) => string;
|
package/dist/emit/boot.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
+
import { INTERACTION_RUNTIME } from "./interaction-runtime.js";
|
|
2
3
|
import { safeJson } from "./safe-json.js";
|
|
3
4
|
const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
4
|
-
const
|
|
5
|
+
const readTemplate = (name) => readFileSync(new URL(name, import.meta.url), "utf8").replaceAll("\r\n", "\n");
|
|
6
|
+
const template = () => readTemplate("./boot.template.js");
|
|
5
7
|
export const clipId = (sceneId) => `clip-${sceneId}`;
|
|
6
8
|
const importLines = (scenes) => {
|
|
7
9
|
const names = scenes.map((_, index) => `scene${index}`);
|
|
@@ -26,7 +28,32 @@ const configJson = (scenes, fps) => safeJson({
|
|
|
26
28
|
config,
|
|
27
29
|
})),
|
|
28
30
|
});
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The single boot.js: mounts every scene and wires one `hf-seek` listener.
|
|
33
|
+
*
|
|
34
|
+
* ADR-0013 slice 2b: when `interaction` is set, that same listener also accepts the
|
|
35
|
+
* wrapper's interaction transcript in `event.detail.transcript`, and every scene reaches
|
|
36
|
+
* folded state through the slice-2a accessor `ctx.interaction.at(t)`. The fold is the
|
|
37
|
+
* schema's `stateAt` (pinned by `boot.test.ts`), so state is a pure function of film time.
|
|
38
|
+
* The composition still renders only on `hf-seek` — no pointer, key or message listener is
|
|
39
|
+
* added. Without the flag the emitted bytes are exactly as before, so an ordinary build
|
|
40
|
+
* (and `mk publish` without `--interactive`) is unchanged.
|
|
41
|
+
*
|
|
42
|
+
* ADR-0013 slice 2c: `transcript` seeds the same runtime before the scenes mount, which is
|
|
43
|
+
* how `mk render --interaction` hands a recorded transcript to the composition. The seeded
|
|
44
|
+
* array is data, folded by the same reducer; no listener is added.
|
|
45
|
+
*/
|
|
46
|
+
export const renderBoot = (scenes, fps, interaction = false, transcript) => template()
|
|
31
47
|
.replace("/*@imports*/", () => importLines(scenes))
|
|
32
|
-
.replace("/*@config*/ null", () => configJson(scenes, fps))
|
|
48
|
+
.replace("/*@config*/ null", () => configJson(scenes, fps))
|
|
49
|
+
.replace("/*@interaction-decl*/", () => interaction
|
|
50
|
+
? `${INTERACTION_RUNTIME}${transcript === undefined ? "" : `\nsetInteractionTranscript(${safeJson(transcript)});`}\n`
|
|
51
|
+
: "")
|
|
52
|
+
.replace(" /*@interaction-ctx*/", () => interaction ? ", interaction: { at: interactionAt }" : "")
|
|
53
|
+
.replace("/*@interaction-targets*/ ", () => interaction
|
|
54
|
+
? // The clip id is the only carrier of the scene id in CONFIG; `clipId` prefixes it.
|
|
55
|
+
`interactionApplyTargets(clip.firstElementChild, scene.clipId.slice(5), t), `
|
|
56
|
+
: "")
|
|
57
|
+
.replace("/*@interaction-seek*/ ", () => interaction
|
|
58
|
+
? "if (event.detail.transcript) setInteractionTranscript(event.detail.transcript);\n "
|
|
59
|
+
: "");
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*@imports*/
|
|
3
3
|
window.__timelines = window.__timelines || {};
|
|
4
4
|
const CONFIG = /*@config*/ null;
|
|
5
|
-
|
|
5
|
+
/*@interaction-decl*/
|
|
6
6
|
const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
7
7
|
|
|
8
8
|
const ease = (p) => 1 - (1 - p) ** 3;
|
|
@@ -30,7 +30,7 @@ const stateAt = (t, scene) => {
|
|
|
30
30
|
|
|
31
31
|
const mounts = CONFIG.scenes.map((scene, index) => {
|
|
32
32
|
const clip = document.getElementById(scene.clipId);
|
|
33
|
-
const ctx = { fps: CONFIG.fps, duration: scene.duration };
|
|
33
|
+
const ctx = { fps: CONFIG.fps, duration: scene.duration /*@interaction-ctx*/ };
|
|
34
34
|
const runtime = FACTORIES[index](clip.firstElementChild, scene.config, ctx);
|
|
35
35
|
return { scene, clip, runtime };
|
|
36
36
|
});
|
|
@@ -75,11 +75,11 @@ const apply = (t) =>
|
|
|
75
75
|
}
|
|
76
76
|
const clipPath = clipOf(t, scene);
|
|
77
77
|
if (clipPath !== null) clip.style.clipPath = clipPath;
|
|
78
|
-
return runtime.seek(state.local);
|
|
78
|
+
return /*@interaction-targets*/ runtime.seek(state.local);
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
window.addEventListener("hf-seek", (event) => {
|
|
82
|
-
event.detail.waitUntil(Promise.all([ready, ...apply(event.detail.time)]));
|
|
82
|
+
/*@interaction-seek*/ event.detail.waitUntil(Promise.all([ready, ...apply(event.detail.time)]));
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
apply(0);
|
package/dist/emit/index-html.js
CHANGED
|
@@ -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,11 @@
|
|
|
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 declare const INTERACTION_RUNTIME = "const MK_ACTIONS = [\n \"hover\",\n \"press\",\n \"release\",\n \"click\",\n \"type\",\n \"focus\",\n \"blur\",\n \"scroll\",\n \"advance\",\n];\n\n/** The wrapper's transcript in the schema's total order; one container, never rebound. */\nconst interactionState = {\n events: [],\n memo: { t: null, state: new Map() },\n};\n\nconst interactionCompare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);\n\nconst interactionCompareValue = (a, b) =>\n a === b ? 0 : a === null ? -1 : b === null ? 1 : interactionCompare(a, b);\n\nconst interactionByEvent = (a, b) =>\n interactionCompare(a.at, b.at) ||\n interactionCompare(a.scene, b.scene) ||\n interactionCompare(a.target, b.target) ||\n interactionCompare(MK_ACTIONS.indexOf(a.action), MK_ACTIONS.indexOf(b.action)) ||\n interactionCompareValue(a.value, b.value);\n\nconst interactionEmpty = () => ({\n pressed: false,\n hovered: false,\n focused: false,\n typed: null,\n scroll: 0,\n activations: 0,\n});\n\nconst interactionScroll = (value) => {\n const parsed = Number(value);\n return Number.isFinite(parsed) ? Math.min(1, Math.max(0, parsed)) : 0;\n};\n\n/** One event onto one target's state; `advance` is transport and leaves the target alone. */\nconst interactionNext = (state, action, value) => {\n if (action === \"hover\") return Object.assign({}, state, { hovered: true });\n if (action === \"press\") return Object.assign({}, state, { pressed: true });\n if (action === \"release\") return Object.assign({}, state, { pressed: false });\n if (action === \"click\") return Object.assign({}, state, { activations: state.activations + 1 });\n if (action === \"type\") return Object.assign({}, state, { typed: value });\n if (action === \"focus\") return Object.assign({}, state, { focused: true });\n if (action === \"blur\") return Object.assign({}, state, { focused: false });\n if (action === \"scroll\") return Object.assign({}, state, { scroll: interactionScroll(value) });\n return state;\n};\n\n/** `stateAt` for the live page: every event with `at <= t`, keyed `\"<scene>:<target>\"`. */\nconst interactionAt = (t) => {\n if (interactionState.memo.t === t) return interactionState.memo.state;\n const state = new Map();\n for (const event of interactionState.events) {\n if (!(event.at <= t)) continue;\n const key = event.scene + \":\" + event.target;\n state.set(\n key,\n interactionNext(state.get(key) || interactionEmpty(), event.action, event.value),\n );\n }\n interactionState.memo = { t, state };\n return state;\n};\n\n/** The wrapper posts the whole transcript with input; sort once per change, not per seek. */\nconst setInteractionTranscript = (events) => {\n interactionState.events = events.slice().sort(interactionByEvent);\n interactionState.memo = { t: null, state: new Map() };\n};\n\n/**\n * Paints the folded state onto one scene's declared targets. The scene emits a\n * [data-mk-target] mark only when its props declare that id, so a board without targets\n * has no elements to address. Film time is the caller's absolute t; the key is\n * \"<scene>:<target>\", the same key the reducer stores.\n */\nconst interactionApplyTargets = (root, sceneId, t) => {\n if (!root || typeof root.querySelectorAll !== \"function\") return;\n const state = interactionAt(t);\n for (const el of root.querySelectorAll(\"[data-mk-target]\")) {\n const target = state.get(sceneId + \":\" + el.getAttribute(\"data-mk-target\"));\n const flag = (name, on) => {\n if (on) el.setAttribute(\"data-mk-\" + name, \"\");\n else el.removeAttribute(\"data-mk-\" + name);\n };\n flag(\"pressed\", target ? target.pressed : false);\n flag(\"hovered\", target ? target.hovered : false);\n flag(\"focused\", target ? target.focused : false);\n if (target && target.typed !== null) el.setAttribute(\"data-mk-typed\", target.typed);\n else el.removeAttribute(\"data-mk-typed\");\n const scroll = target ? target.scroll : 0;\n el.setAttribute(\"data-mk-scroll\", String(scroll));\n el.setAttribute(\"data-mk-activations\", String(target ? target.activations : 0));\n if (el.style && typeof el.style.setProperty === \"function\") {\n el.style.setProperty(\"--mk-target-scroll\", String(scroll));\n }\n const slot =\n typeof el.querySelector === \"function\" ? el.querySelector(\"[data-mk-typed-slot]\") : null;\n if (slot) slot.textContent = target && target.typed !== null ? target.typed : \"\";\n }\n};\n";
|