@braccato/core 1.22.0 → 2.0.0-beta.1

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 (102) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +211 -600
  3. package/js/element.js +234 -0
  4. package/js/renderer.d.ts +157 -0
  5. package/js/renderer.js +535 -0
  6. package/package.json +22 -17
  7. package/pkg/braccato_core_rs.d.ts +236 -0
  8. package/pkg/braccato_core_rs.js +1735 -0
  9. package/pkg/braccato_core_rs_bg.wasm +0 -0
  10. package/pkg/braccato_core_rs_bg.wasm.d.ts +55 -0
  11. package/dist/LICENSE +0 -21
  12. package/dist/README.md +0 -639
  13. package/dist/element.d.ts +0 -168
  14. package/dist/element.js +0 -730
  15. package/dist/engine/animationConfig.d.ts +0 -84
  16. package/dist/engine/animationConfig.js +0 -95
  17. package/dist/engine/animationDrift.d.ts +0 -11
  18. package/dist/engine/animationDrift.js +0 -43
  19. package/dist/engine/animationTiming.d.ts +0 -27
  20. package/dist/engine/animationTiming.js +0 -145
  21. package/dist/engine/autoScroll.d.ts +0 -24
  22. package/dist/engine/autoScroll.js +0 -103
  23. package/dist/engine/clock.d.ts +0 -29
  24. package/dist/engine/clock.js +0 -70
  25. package/dist/engine/contextSweep.d.ts +0 -10
  26. package/dist/engine/contextSweep.js +0 -102
  27. package/dist/engine/cssValues.d.ts +0 -13
  28. package/dist/engine/cssValues.js +0 -47
  29. package/dist/engine/culling.d.ts +0 -6
  30. package/dist/engine/culling.js +0 -76
  31. package/dist/engine/debugOverlay.d.ts +0 -14
  32. package/dist/engine/debugOverlay.js +0 -58
  33. package/dist/engine/decorationSlides.d.ts +0 -6
  34. package/dist/engine/decorationSlides.js +0 -53
  35. package/dist/engine/elementMotion.d.ts +0 -18
  36. package/dist/engine/elementMotion.js +0 -98
  37. package/dist/engine/glow.d.ts +0 -7
  38. package/dist/engine/glow.js +0 -59
  39. package/dist/engine/instance.d.ts +0 -105
  40. package/dist/engine/instance.js +0 -89
  41. package/dist/engine/instrumentalAnimations.d.ts +0 -7
  42. package/dist/engine/instrumentalAnimations.js +0 -59
  43. package/dist/engine/letterPlans.d.ts +0 -31
  44. package/dist/engine/letterPlans.js +0 -62
  45. package/dist/engine/lineAnimationState.d.ts +0 -10
  46. package/dist/engine/lineAnimationState.js +0 -82
  47. package/dist/engine/lineAnimations.d.ts +0 -5
  48. package/dist/engine/lineAnimations.js +0 -63
  49. package/dist/engine/lineLifecycle.d.ts +0 -12
  50. package/dist/engine/lineLifecycle.js +0 -92
  51. package/dist/engine/lineScroll.d.ts +0 -47
  52. package/dist/engine/lineScroll.js +0 -184
  53. package/dist/engine/lineScrollStyle.d.ts +0 -32
  54. package/dist/engine/lineScrollStyle.js +0 -133
  55. package/dist/engine/liveViews.d.ts +0 -3
  56. package/dist/engine/liveViews.js +0 -5
  57. package/dist/engine/motionCurves.d.ts +0 -19
  58. package/dist/engine/motionCurves.js +0 -85
  59. package/dist/engine/motionPreference.d.ts +0 -1
  60. package/dist/engine/motionPreference.js +0 -1
  61. package/dist/engine/passiveScroll.d.ts +0 -10
  62. package/dist/engine/passiveScroll.js +0 -93
  63. package/dist/engine/renderedLines.d.ts +0 -16
  64. package/dist/engine/renderedLines.js +0 -130
  65. package/dist/engine/scrollViewport.d.ts +0 -36
  66. package/dist/engine/scrollViewport.js +0 -104
  67. package/dist/engine/stageMotion.d.ts +0 -7
  68. package/dist/engine/stageMotion.js +0 -319
  69. package/dist/engine/sweepPlans.d.ts +0 -38
  70. package/dist/engine/sweepPlans.js +0 -66
  71. package/dist/engine/tick.d.ts +0 -16
  72. package/dist/engine/tick.js +0 -270
  73. package/dist/engine/timingLogs.d.ts +0 -7
  74. package/dist/engine/timingLogs.js +0 -81
  75. package/dist/engine/userScroll.d.ts +0 -12
  76. package/dist/engine/userScroll.js +0 -62
  77. package/dist/engine/wavePool.d.ts +0 -7
  78. package/dist/engine/wavePool.js +0 -22
  79. package/dist/engine/wordAnimations.d.ts +0 -5
  80. package/dist/engine/wordAnimations.js +0 -206
  81. package/dist/imageHighlights.d.ts +0 -4
  82. package/dist/imageHighlights.js +0 -34
  83. package/dist/index.d.ts +0 -17
  84. package/dist/index.js +0 -12
  85. package/dist/inject.d.ts +0 -98
  86. package/dist/inject.js +0 -591
  87. package/dist/instrumental.d.ts +0 -11
  88. package/dist/instrumental.js +0 -121
  89. package/dist/language.d.ts +0 -9
  90. package/dist/language.js +0 -47
  91. package/dist/letters.d.ts +0 -2
  92. package/dist/letters.js +0 -25
  93. package/dist/renderer.d.ts +0 -29
  94. package/dist/renderer.js +0 -412
  95. package/dist/seek.d.ts +0 -1
  96. package/dist/seek.js +0 -27
  97. package/dist/stage.d.ts +0 -58
  98. package/dist/stage.js +0 -121
  99. package/dist/types.d.ts +0 -236
  100. package/dist/types.js +0 -1
  101. package/dist/view.d.ts +0 -51
  102. package/dist/view.js +0 -398
@@ -1,105 +0,0 @@
1
- import type { LineData } from "../inject.js";
2
- import type { LyricsLayout, LyricsRendererHost, LyricSyncType, ResolvedTickOptions } from "../types.js";
3
- import type { StageBox, StageMetrics } from "../stage.js";
4
- import { type ScrollInsets } from "./scrollViewport.js";
5
- import type { ElementMotion } from "./elementMotion.js";
6
- import type { LineScrollItem, PendingLineScroll, RunningLineScroll } from "./lineScroll.js";
7
- import type { LineScrollTiming } from "./lineScrollStyle.js";
8
- import type { AnimationSettings } from "./animationConfig.js";
9
- /**
10
- * Everything that belongs to a single rendered lyrics view: one scroll container, one selection,
11
- * one set of pending scroll work.
12
- */
13
- interface AnimEngineViewState {
14
- /**
15
- * The render records this view built, one per lyric line. They hold this view's elements and
16
- * this view's `Animation` objects, so a second view never shares them.
17
- */
18
- lines: LineData[];
19
- lyricsContainer: HTMLElement | null;
20
- syncType: LyricSyncType;
21
- lyricWidth: number;
22
- lyricHeight: number;
23
- skipScrolls: number;
24
- skipScrollsDecayTimes: number[];
25
- scrollResumeTime: number;
26
- scrollPos: number;
27
- selectedElementIndex: number;
28
- wasUserScrolling: boolean;
29
- lastScrollElements: LineData[];
30
- /** The line a committed scroll kept in view because the active lines overflowed the band. */
31
- pinnedScrollLine: LineData | null;
32
- lastScrollDebugContext: {
33
- activeElms: LineData[];
34
- centers: number[];
35
- lyricScrollTime: number;
36
- };
37
- passiveScrollAccumulatedTime: number;
38
- passiveLastWallTime: number;
39
- /** Where the passive drift last put the scroll, so a scroll that lands anywhere else is the reader's. */
40
- passiveScrollTop: number | null;
41
- }
42
- /**
43
- * `Window` alone types neither `ResizeObserver` nor `DOMMatrix`: both are ambient `var`
44
- * declarations, so they only appear through `typeof globalThis`.
45
- */
46
- type EngineWindow = Window & typeof globalThis;
47
- export interface AnimationEngineInstance extends AnimEngineViewState {
48
- document: Document;
49
- window: EngineWindow;
50
- host: LyricsRendererHost;
51
- cachedTabRendererHeight: number | null;
52
- cachedScrollInsets: ScrollInsets;
53
- cachedFooterItem: LineScrollItem | null;
54
- cachedCreditsItem: LineScrollItem | null;
55
- creditsFocused: boolean;
56
- cachedLineScrollTiming: Map<string, LineScrollTiming>;
57
- tabRendererResizeObserver: ResizeObserver | null;
58
- observedTabRenderer: HTMLElement | null;
59
- runningLineScrolls: RunningLineScroll[];
60
- elementMotions: Map<HTMLElement, ElementMotion>;
61
- easingTables: Map<string, Float64Array>;
62
- lineScrollAnimationToken: number;
63
- pendingLineScroll: PendingLineScroll | null;
64
- lineScrollElementTokens: WeakMap<HTMLElement, number>;
65
- visibleWillChangeElements: Set<HTMLElement>;
66
- culledLineElements: Set<HTMLElement>;
67
- waveAnimationPool: Animation[];
68
- lineCullObserver: IntersectionObserver | null;
69
- cachedDurations: Map<string, number>;
70
- cachedCSSValues: Map<string, string>;
71
- cachedAnimationSettings: AnimationSettings | null;
72
- /**
73
- * Last value the tick was given. The passive scroll loop runs from an animation frame rather than
74
- * from a tick, so it has no options object to read.
75
- */
76
- passiveScrollEnabled: boolean;
77
- /**
78
- * Last options the tick was given, kept before any early return. A click reads its offsets to seek
79
- * to where a line plays rather than to its unshifted time.
80
- */
81
- lastTickOptions: ResolvedTickOptions | null;
82
- playbackRate: number;
83
- passiveRAFId: number | null;
84
- pendingLyricsUpdateFrame: number | null;
85
- learnedAnimationTimingOffsetMs: number;
86
- animationTimingVisibilityLogUntil: number;
87
- layout: LyricsLayout;
88
- stageKey: string;
89
- stageRemeasured: boolean;
90
- stageHeight: number;
91
- stageBox: StageBox | null;
92
- stageMetrics: Map<HTMLElement, StageMetrics>;
93
- stageY: Map<HTMLElement, number>;
94
- stageMoves: Map<HTMLElement, Animation>;
95
- stageFades: Map<HTMLElement, Animation>;
96
- stageBlurs: Map<HTMLElement, Animation>;
97
- stageFontSize: number;
98
- /**
99
- * Releases everything the instance holds on its window: the reduced motion listener, the tab
100
- * renderer observer and any frame it still has queued.
101
- */
102
- destroy(): void;
103
- }
104
- export declare function createAnimationEngineInstance(engineDocument: Document, engineWindow: EngineWindow, host: LyricsRendererHost, layout?: LyricsLayout): AnimationEngineInstance;
105
- export {};
@@ -1,89 +0,0 @@
1
- import { NO_SCROLL_INSETS } from "./scrollViewport.js";
2
- import { REDUCED_MOTION_QUERY } from "./motionPreference.js";
3
- import { clearStyleCaches } from "./cssValues.js";
4
- import { liveEngines } from "./liveViews.js";
5
- import { stopPassiveScrollLoop } from "./passiveScroll.js";
6
- import { cancelLyricPositionUpdate } from "./tick.js";
7
- export function createAnimationEngineInstance(engineDocument, engineWindow, host, layout = "scroll") {
8
- const reducedMotionQuery = engineWindow.matchMedia(REDUCED_MOTION_QUERY);
9
- const handleReducedMotionChange = () => clearStyleCaches(engine);
10
- const engine = {
11
- document: engineDocument,
12
- window: engineWindow,
13
- host,
14
- lines: [],
15
- lyricsContainer: null,
16
- syncType: "none",
17
- lyricWidth: 0,
18
- lyricHeight: 0,
19
- skipScrolls: 0,
20
- skipScrollsDecayTimes: [],
21
- scrollResumeTime: 0,
22
- scrollPos: -1,
23
- selectedElementIndex: 0,
24
- wasUserScrolling: false,
25
- lastScrollElements: [],
26
- pinnedScrollLine: null,
27
- lastScrollDebugContext: {
28
- activeElms: [],
29
- centers: [],
30
- lyricScrollTime: 0,
31
- },
32
- passiveScrollAccumulatedTime: 0,
33
- passiveLastWallTime: 0,
34
- passiveScrollTop: null,
35
- cachedTabRendererHeight: null,
36
- cachedScrollInsets: NO_SCROLL_INSETS,
37
- cachedFooterItem: null,
38
- cachedCreditsItem: null,
39
- creditsFocused: false,
40
- cachedLineScrollTiming: new Map(),
41
- tabRendererResizeObserver: null,
42
- observedTabRenderer: null,
43
- runningLineScrolls: [],
44
- elementMotions: new Map(),
45
- easingTables: new Map(),
46
- lineScrollAnimationToken: 0,
47
- pendingLineScroll: null,
48
- lineScrollElementTokens: new WeakMap(),
49
- visibleWillChangeElements: new Set(),
50
- culledLineElements: new Set(),
51
- waveAnimationPool: [],
52
- lineCullObserver: null,
53
- cachedDurations: new Map(),
54
- cachedCSSValues: new Map(),
55
- cachedAnimationSettings: null,
56
- passiveScrollEnabled: false,
57
- lastTickOptions: null,
58
- playbackRate: 1,
59
- passiveRAFId: null,
60
- pendingLyricsUpdateFrame: null,
61
- learnedAnimationTimingOffsetMs: 0,
62
- animationTimingVisibilityLogUntil: 0,
63
- layout,
64
- stageKey: "",
65
- stageRemeasured: false,
66
- stageHeight: 0,
67
- stageBox: null,
68
- stageMetrics: new Map(),
69
- stageY: new Map(),
70
- stageMoves: new Map(),
71
- stageFades: new Map(),
72
- stageBlurs: new Map(),
73
- stageFontSize: 16,
74
- destroy: () => {
75
- liveEngines.delete(engine);
76
- reducedMotionQuery.removeEventListener("change", handleReducedMotionChange);
77
- engine.tabRendererResizeObserver?.disconnect();
78
- engine.tabRendererResizeObserver = null;
79
- engine.observedTabRenderer = null;
80
- engine.lineCullObserver?.disconnect();
81
- engine.lineCullObserver = null;
82
- stopPassiveScrollLoop(engine);
83
- cancelLyricPositionUpdate(engine);
84
- },
85
- };
86
- reducedMotionQuery.addEventListener("change", handleReducedMotionChange);
87
- liveEngines.add(engine);
88
- return engine;
89
- }
@@ -1,7 +0,0 @@
1
- import type { LineData } from "../inject.js";
2
- import type { AnimationConfig } from "./animationConfig.js";
3
- import type { AnimationEngineInstance } from "./instance.js";
4
- export declare const INSTRUMENTAL_WAVE_PATH_HIGH_FALLBACK = "path(\"M -4 3 Q 1 2 5 3 Q 10 4 14 3 Q 18 2 22 3 Q 26 4 30 3 L 30 4 L -4 4 Z\")";
5
- export declare const INSTRUMENTAL_WAVE_PATH_LOW_FALLBACK = "path(\"M -4 3 Q 1 4 5 3 Q 10 2 14 3 Q 18 4 22 3 Q 26 2 30 3 L 30 4 L -4 4 Z\")";
6
- export declare function startInstrumentalAnimations(engine: AnimationEngineInstance, line: LineData, config: AnimationConfig, lyricTimeS: number, appliedTimingOffsetMs: number): void;
7
- export declare function startInstrumentalExitAnimations(line: LineData, config: AnimationConfig, lyricTimeS: number): void;
@@ -1,59 +0,0 @@
1
- import { INSTRUMENTAL_WAVE_PATH_HIGH, INSTRUMENTAL_WAVE_PATH_LOW } from "../instrumental.js";
2
- import { correctedAnimationTimeMs, correctedWrappedAnimationTimeMs, followSongClock, seekAnimation, } from "./animationTiming.js";
3
- const FILL_SELECTOR = ".blyrics--instrumental-fill";
4
- const WAVE_CLIP_SELECTOR = ".blyrics--wave-clip";
5
- const WAVE_PATH_SELECTOR = ".blyrics--wave-path";
6
- const INSTANT_MS = 1;
7
- export const INSTRUMENTAL_WAVE_PATH_HIGH_FALLBACK = `path("${INSTRUMENTAL_WAVE_PATH_HIGH}")`;
8
- export const INSTRUMENTAL_WAVE_PATH_LOW_FALLBACK = `path("${INSTRUMENTAL_WAVE_PATH_LOW}")`;
9
- export function startInstrumentalAnimations(engine, line, config, lyricTimeS, appliedTimingOffsetMs) {
10
- const elapsedMs = (lyricTimeS - line.time) * 1000;
11
- const lineDurationMs = Math.max(line.duration * 1000, 1);
12
- const enabled = config.enabled.instrumental;
13
- const { instrumental } = config;
14
- const followSong = (animation, currentTimeMs, wrapDurationMs) => {
15
- if (!animation)
16
- return;
17
- followSongClock(engine, animation, { appliedTimingOffsetMs, offsetMs: 0, wrapDurationMs });
18
- seekAnimation(engine, animation, currentTimeMs);
19
- };
20
- const scheduled = (durationMs) => correctedAnimationTimeMs(elapsedMs, appliedTimingOffsetMs, durationMs);
21
- const fillFadeMs = enabled ? instrumental.fillFadeDurationMs : INSTANT_MS;
22
- const fillFade = animateChild(line, FILL_SELECTOR, [{ opacity: 0 }, { opacity: 1 }], {
23
- duration: fillFadeMs,
24
- easing: enabled ? instrumental.fillFadeEasing : "linear",
25
- fill: "forwards",
26
- });
27
- followSong(fillFade, scheduled(fillFadeMs));
28
- if (!enabled)
29
- return;
30
- const travel = (selector, from, to, easing) => animateChild(line, selector, [{ transform: from }, { transform: to }], {
31
- duration: lineDurationMs,
32
- easing,
33
- fill: "both",
34
- });
35
- followSong(travel(WAVE_CLIP_SELECTOR, instrumental.fillFrom, instrumental.fillTo, instrumental.fillEasing), scheduled(lineDurationMs));
36
- followSong(travel(WAVE_PATH_SELECTOR, instrumental.waveFrom, instrumental.waveTo, instrumental.waveEasing), scheduled(lineDurationMs));
37
- const oscillationMs = instrumental.waveOscillationDurationMs;
38
- const oscillation = animateChild(line, WAVE_PATH_SELECTOR, [{ d: instrumental.wavePathHigh }, { d: instrumental.wavePathLow, offset: 0.5 }, { d: instrumental.wavePathHigh }], { duration: oscillationMs, easing: instrumental.waveOscillationEasing, iterations: Infinity });
39
- const wrapMs = Math.max(oscillationMs, 1);
40
- followSong(oscillation, correctedWrappedAnimationTimeMs(elapsedMs, appliedTimingOffsetMs, wrapMs), oscillationMs);
41
- }
42
- export function startInstrumentalExitAnimations(line, config, lyricTimeS) {
43
- if (lyricTimeS < line.time)
44
- return;
45
- const fades = config.enabled.instrumental && config.enabled.highlightFade;
46
- animateChild(line, FILL_SELECTOR, [{ opacity: 1 }, { opacity: 0 }], {
47
- duration: fades ? config.highlight.fadeOutDurationMs : INSTANT_MS,
48
- easing: config.enabled.instrumental ? config.highlight.fadeOutEasing : "linear",
49
- fill: "none",
50
- });
51
- }
52
- function animateChild(line, selector, keyframes, options) {
53
- const element = line.lyricElement.querySelector(selector);
54
- if (!element)
55
- return null;
56
- const animation = element.animate(keyframes, options);
57
- line.animations.push(animation);
58
- return animation;
59
- }
@@ -1,31 +0,0 @@
1
- import type { AnimationConfig } from "./animationConfig.js";
2
- export interface SwipeRamp {
3
- easing: string;
4
- startFrom: string;
5
- startTo: string;
6
- endFrom: string;
7
- endTo: string;
8
- }
9
- export interface LetterSwipeWindow {
10
- delayMs: number;
11
- durationMs: number;
12
- from: {
13
- start: number;
14
- end: number;
15
- };
16
- to: {
17
- start: number;
18
- end: number;
19
- };
20
- }
21
- export interface LetterWaveTiming {
22
- delayMs: number;
23
- durationMs: number;
24
- }
25
- export declare const LETTER_WAVE_CREST_OFFSET = 0.4;
26
- export declare const GECKO_REDRAW: boolean;
27
- export declare const GECKO_REDRAW_KEYFRAMES: Keyframe[];
28
- export declare const GECKO_REDRAW_PERIOD_MS = 200;
29
- export declare function swipeRamp({ highlight }: AnimationConfig): SwipeRamp;
30
- export declare function linearForwardSwipeWindows(swipe: SwipeRamp, letterCount: number, swipeDurationMs: number): LetterSwipeWindow[] | null;
31
- export declare function planLetterWave(swipe: SwipeRamp, letterCount: number, wordDurationMs: number, swipeDurationMs: number, swipeLeadMs: number, floatDurationMs: number): LetterWaveTiming[];
@@ -1,62 +0,0 @@
1
- import { clamp, isGecko } from "../util.js";
2
- export const LETTER_WAVE_CREST_OFFSET = 0.4;
3
- // WebRender redraws a cached tile only after a quarter device pixel of movement, so Gecko letters step.
4
- // An invisible additive opacity ripple changes every frame and forces the redraw.
5
- export const GECKO_REDRAW = isGecko();
6
- export const GECKO_REDRAW_KEYFRAMES = [{ opacity: 0 }, { opacity: -0.002 }, { opacity: 0 }];
7
- export const GECKO_REDRAW_PERIOD_MS = 200;
8
- export function swipeRamp({ highlight }) {
9
- return {
10
- easing: highlight.swipeEasing,
11
- startFrom: highlight.swipeStartFrom,
12
- startTo: highlight.swipeStartTo,
13
- endFrom: highlight.swipeEndFrom,
14
- endTo: highlight.swipeEndTo,
15
- };
16
- }
17
- export function linearForwardSwipeWindows(swipe, letterCount, swipeDurationMs) {
18
- if (swipe.easing !== "linear" || swipeDurationMs <= 0 || letterCount <= 0)
19
- return null;
20
- const startFrom = Number.parseFloat(swipe.startFrom);
21
- const startTo = Number.parseFloat(swipe.startTo);
22
- const endFrom = Number.parseFloat(swipe.endFrom);
23
- const endTo = Number.parseFloat(swipe.endTo);
24
- const finite = [startFrom, startTo, endFrom, endTo].every(Number.isFinite);
25
- if (!finite || startTo <= startFrom || endTo <= endFrom)
26
- return null;
27
- const startAt = (timeMs) => startFrom + ((startTo - startFrom) * timeMs) / swipeDurationMs;
28
- const endAt = (timeMs) => endFrom + ((endTo - endFrom) * timeMs) / swipeDurationMs;
29
- const timeWhenEndReaches = (value) => (swipeDurationMs * (value - endFrom)) / (endTo - endFrom);
30
- const timeWhenStartReaches = (value) => (swipeDurationMs * (value - startFrom)) / (startTo - startFrom);
31
- const windows = [];
32
- for (let index = 0; index < letterCount; index++) {
33
- const beginMs = clamp(timeWhenEndReaches(index / letterCount), 0, swipeDurationMs);
34
- const finishMs = clamp(timeWhenStartReaches((index + 1) / letterCount), 0, swipeDurationMs);
35
- windows.push({
36
- delayMs: beginMs,
37
- durationMs: Math.max(finishMs - beginMs, 1),
38
- from: { start: startAt(beginMs), end: endAt(beginMs) },
39
- to: { start: startAt(finishMs), end: endAt(finishMs) },
40
- });
41
- }
42
- return windows;
43
- }
44
- export function planLetterWave(swipe, letterCount, wordDurationMs, swipeDurationMs, swipeLeadMs, floatDurationMs) {
45
- const windows = linearForwardSwipeWindows({ ...swipe, easing: "linear" }, letterCount, swipeDurationMs);
46
- if (!windows)
47
- return evenlySpreadWaves(letterCount, wordDurationMs, floatDurationMs);
48
- const riseMs = floatDurationMs * LETTER_WAVE_CREST_OFFSET;
49
- return windows.map(window => {
50
- const touchedMs = window.delayMs - swipeLeadMs;
51
- const lightingMs = window.durationMs;
52
- if (lightingMs > riseMs)
53
- return { delayMs: touchedMs, durationMs: lightingMs / LETTER_WAVE_CREST_OFFSET };
54
- return { delayMs: touchedMs + lightingMs - riseMs, durationMs: floatDurationMs };
55
- });
56
- }
57
- function evenlySpreadWaves(letterCount, wordDurationMs, floatDurationMs) {
58
- return Array.from({ length: letterCount }, (_, index) => ({
59
- delayMs: (wordDurationMs * index) / letterCount,
60
- durationMs: floatDurationMs,
61
- }));
62
- }
@@ -1,10 +0,0 @@
1
- import type { AnimationData, LineData, PartData } from "../inject.js";
2
- export declare function releasePart(part: PartData): void;
3
- export declare function resetPartAnimations(part: AnimationData): void;
4
- export declare function hasLineAnimations(lineData: LineData): boolean;
5
- export declare function markLineAnimationsStopped(lineData: LineData): void;
6
- export declare function resetLineAnimationState(lineData: LineData): void;
7
- export declare function togglePartClass(part: LineData | PartData, className: string, force: boolean): void;
8
- export declare function setAnimationsPlayState(lineData: LineData, isPlaying: boolean): void;
9
- export declare function clearLineStateClasses(lineData: LineData): void;
10
- export declare function updateWordStates(lineData: LineData, currentTime: number): void;
@@ -1,82 +0,0 @@
1
- import { ANIMATING_CLASS, PAUSED_CLASS, WORD_STATE_ACTIVE, WORD_STATE_ATTR, WORD_STATE_PAST, WORD_STATE_UPCOMING, } from "../constants.js";
2
- import { waveAnimationPools } from "./wavePool.js";
3
- export function releasePart(part) {
4
- resetPartAnimations(part);
5
- togglePartClass(part, PAUSED_CLASS, false);
6
- togglePartClass(part, ANIMATING_CLASS, false);
7
- part.wordState = WORD_STATE_UPCOMING;
8
- part.lyricElement.setAttribute(WORD_STATE_ATTR, WORD_STATE_UPCOMING);
9
- part.highlightElement.setAttribute(WORD_STATE_ATTR, WORD_STATE_UPCOMING);
10
- }
11
- export function resetPartAnimations(part) {
12
- for (const animation of part.animations) {
13
- animation.cancel();
14
- const pool = waveAnimationPools.get(animation);
15
- if (pool)
16
- pool.push(animation);
17
- }
18
- part.animations = [];
19
- }
20
- function resetLineAnimations(lineData) {
21
- resetPartAnimations(lineData);
22
- for (const part of lineData.parts)
23
- resetPartAnimations(part);
24
- }
25
- export function hasLineAnimations(lineData) {
26
- return lineData.animations.length > 0 || lineData.parts.some(part => part.animations.length > 0);
27
- }
28
- export function markLineAnimationsStopped(lineData) {
29
- lineData.isAnimating = false;
30
- lineData.isAnimationPlayStatePlaying = false;
31
- lineData.accumulatedOffsetMs = 0;
32
- }
33
- export function resetLineAnimationState(lineData) {
34
- resetLineAnimations(lineData);
35
- markLineAnimationsStopped(lineData);
36
- }
37
- export function togglePartClass(part, className, force) {
38
- part.lyricElement.classList.toggle(className, force);
39
- if ("highlightElement" in part) {
40
- part.highlightElement.classList.toggle(className, force);
41
- }
42
- }
43
- export function setAnimationsPlayState(lineData, isPlaying) {
44
- const children = [lineData, ...lineData.parts];
45
- for (const part of children) {
46
- togglePartClass(part, PAUSED_CLASS, !isPlaying);
47
- for (const animation of part.animations) {
48
- if (isPlaying) {
49
- animation.play();
50
- }
51
- else {
52
- animation.pause();
53
- }
54
- }
55
- }
56
- }
57
- export function clearLineStateClasses(lineData) {
58
- lineData.lyricElement.classList.remove(ANIMATING_CLASS);
59
- for (const part of [lineData, ...lineData.parts]) {
60
- togglePartClass(part, PAUSED_CLASS, false);
61
- }
62
- }
63
- export function updateWordStates(lineData, currentTime) {
64
- const parts = lineData.parts;
65
- const lineEndTime = lineData.time + lineData.duration;
66
- for (let i = 0; i < parts.length; i++) {
67
- const part = parts[i];
68
- const endTime = part.duration > 0 ? part.time + part.duration : (parts[i + 1]?.time ?? lineEndTime);
69
- let state = WORD_STATE_PAST;
70
- if (currentTime < part.time) {
71
- state = WORD_STATE_UPCOMING;
72
- }
73
- else if (currentTime < endTime) {
74
- state = WORD_STATE_ACTIVE;
75
- }
76
- if (part.wordState === state)
77
- continue;
78
- part.wordState = state;
79
- part.lyricElement.setAttribute(WORD_STATE_ATTR, state);
80
- part.highlightElement.setAttribute(WORD_STATE_ATTR, state);
81
- }
82
- }
@@ -1,5 +0,0 @@
1
- import type { LineData } from "../inject.js";
2
- import type { AnimationConfig } from "./animationConfig.js";
3
- import type { AnimationEngineInstance } from "./instance.js";
4
- export declare function startLineAnimations(engine: AnimationEngineInstance, line: LineData, config: AnimationConfig, lyricTimeS: number): void;
5
- export declare function startLineExitAnimations(line: LineData, config: AnimationConfig, lyricTimeS: number): void;
@@ -1,63 +0,0 @@
1
- import { correctedAnimationTimeMs, followSongClock, seekAnimation } from "./animationTiming.js";
2
- import { placeContextSweeps } from "./contextSweep.js";
3
- import { suppressInvisibleWordGlows } from "./glow.js";
4
- import { startInstrumentalAnimations, startInstrumentalExitAnimations } from "./instrumentalAnimations.js";
5
- import { resetPartAnimations } from "./lineAnimationState.js";
6
- import { startWordAnimations, startWordExitAnimation } from "./wordAnimations.js";
7
- export function startLineAnimations(engine, line, config, lyricTimeS) {
8
- const appliedTimingOffsetMs = engine.learnedAnimationTimingOffsetMs;
9
- if (!isInstrumental(line))
10
- placeContextSweeps(line, config);
11
- startLineEntrance(engine, line, config, lyricTimeS, appliedTimingOffsetMs);
12
- if (isInstrumental(line)) {
13
- startInstrumentalAnimations(engine, line, config, lyricTimeS, appliedTimingOffsetMs);
14
- return;
15
- }
16
- suppressInvisibleWordGlows(engine, line, config);
17
- for (const part of line.parts)
18
- startWordAnimations(engine, part, config, lyricTimeS, appliedTimingOffsetMs);
19
- }
20
- export function startLineExitAnimations(line, config, lyricTimeS) {
21
- startLineExit(line, config);
22
- if (isInstrumental(line)) {
23
- startInstrumentalExitAnimations(line, config, lyricTimeS);
24
- return;
25
- }
26
- for (const part of line.parts) {
27
- if (lyricTimeS >= part.time)
28
- startWordExitAnimation(part, config);
29
- else
30
- resetPartAnimations(part);
31
- }
32
- }
33
- function isInstrumental(line) {
34
- return line.lyricElement.dataset.instrumental === "true";
35
- }
36
- function startLineEntrance(engine, line, config, lyricTimeS, appliedTimingOffsetMs) {
37
- resetPartAnimations(line);
38
- if (!config.enabled.lineScale)
39
- return;
40
- const { enterFrom, enterTo, enterEasing, durationMs } = config.line;
41
- const entrance = line.lyricElement.animate([{ transform: enterFrom }, { transform: enterTo }], {
42
- duration: durationMs,
43
- easing: enterEasing,
44
- fill: "forwards",
45
- });
46
- followSongClock(engine, entrance, { appliedTimingOffsetMs, offsetMs: 0 });
47
- const elapsedMs = (lyricTimeS - line.time) * 1000;
48
- seekAnimation(engine, entrance, correctedAnimationTimeMs(elapsedMs, appliedTimingOffsetMs, durationMs));
49
- line.animations = [entrance];
50
- }
51
- function startLineExit(line, config) {
52
- resetPartAnimations(line);
53
- if (!config.enabled.lineScale)
54
- return;
55
- const { exitFrom, exitTo, exitEasing, durationMs } = config.line;
56
- const exit = line.lyricElement.animate([{ transform: exitFrom }, { transform: exitTo }], {
57
- duration: durationMs,
58
- easing: exitEasing,
59
- fill: "none",
60
- });
61
- line.animations = [exit];
62
- exit.addEventListener("finish", () => resetPartAnimations(line), { once: true });
63
- }
@@ -1,12 +0,0 @@
1
- import type { AnimationConfig } from "./animationConfig.js";
2
- import type { Playhead } from "./clock.js";
3
- import type { AnimationEngineInstance } from "./instance.js";
4
- interface LineTick {
5
- engine: AnimationEngineInstance;
6
- lyricTimeS: number;
7
- playhead: Playhead;
8
- config: AnimationConfig;
9
- now: number;
10
- }
11
- export declare function driveLineAnimations(tick: LineTick): void;
12
- export {};
@@ -1,92 +0,0 @@
1
- import { ANIMATING_CLASS } from "../constants.js";
2
- import { correctLineDrift } from "./animationDrift.js";
3
- import { startLineAnimations, startLineExitAnimations } from "./lineAnimations.js";
4
- import { clearLineStateClasses, hasLineAnimations, markLineAnimationsStopped, resetLineAnimationState, setAnimationsPlayState, updateWordStates, } from "./lineAnimationState.js";
5
- import { logAnimationCleanup } from "./timingLogs.js";
6
- const ANIMATION_PREPARE_AHEAD_S = 2;
7
- const LINE_END_GRACE_S = 0.05;
8
- const STALE_ANIMATION_GRACE_S = 0.05;
9
- export function driveLineAnimations(tick) {
10
- const { engine, lyricTimeS, playhead } = tick;
11
- const lines = engine.lines;
12
- const prepareAheadS = playhead.isPlaying ? ANIMATION_PREPARE_AHEAD_S : 0;
13
- const linesToStart = [];
14
- for (let index = 0; index < lines.length; index++) {
15
- const line = lines[index];
16
- const nextLineStartS = lines[index + 1]?.time ?? Infinity;
17
- const animationEndS = Math.max(nextLineStartS, line.time + line.duration + LINE_END_GRACE_S);
18
- if (lyricTimeS + prepareAheadS >= line.time && lyricTimeS < animationEndS) {
19
- updateLineAnimationState(tick, line, index);
20
- if (!line.isAnimating)
21
- linesToStart.push(line);
22
- }
23
- else {
24
- retireLine(tick, line, index, animationEndS);
25
- }
26
- }
27
- for (const line of linesToStart)
28
- startLine(tick, line);
29
- }
30
- function updateLineAnimationState(tick, line, index) {
31
- const { lyricTimeS, playhead } = tick;
32
- if (!line.isSelected) {
33
- line.isSelected = true;
34
- line.lyricElement.classList.add(ANIMATING_CLASS);
35
- }
36
- if (line.isAnimationPlayStatePlaying !== playhead.isPlaying) {
37
- line.isAnimationPlayStatePlaying = playhead.isPlaying;
38
- setAnimationsPlayState(line, playhead.isPlaying);
39
- if (playhead.isPlaying)
40
- line.isAnimating = false;
41
- }
42
- const playbackDiscontinuity = (playhead.jumped && playhead.isPlaying) || playhead.mediaClockRanBackwards || playhead.seekedWhilePaused;
43
- if (playbackDiscontinuity && line.isAnimating)
44
- resetLineAnimationState(line);
45
- updateWordStates(line, lyricTimeS);
46
- correctLineDrift({
47
- engine: tick.engine,
48
- line,
49
- lineIndex: index,
50
- lyricTimeS,
51
- isPlaying: playhead.isPlaying,
52
- now: tick.now,
53
- });
54
- }
55
- function retireLine({ engine, lyricTimeS, playhead, config }, line, index, animationEndS) {
56
- const staleAfterS = animationEndS + config.highlight.fadeOutDurationMs / 1000 + STALE_ANIMATION_GRACE_S;
57
- const isStale = lyricTimeS > staleAfterS;
58
- const wasSelected = line.isSelected;
59
- if (wasSelected) {
60
- if (playhead.isPlaying || playhead.jumped || playhead.seekedWhilePaused) {
61
- if (isStale) {
62
- logAnimationCleanup(engine, "selected-stale-reset", line, index, lyricTimeS, staleAfterS);
63
- resetLineAnimationState(line);
64
- }
65
- else {
66
- startLineExitAnimations(line, config, lyricTimeS);
67
- markLineAnimationsStopped(line);
68
- }
69
- }
70
- else {
71
- setAnimationsPlayState(line, false);
72
- line.isAnimationPlayStatePlaying = false;
73
- }
74
- line.isSelected = false;
75
- clearLineStateClasses(line);
76
- }
77
- else if (hasLineAnimations(line) && (playhead.jumped || isStale)) {
78
- logAnimationCleanup(engine, playhead.jumped ? "time-jump-reset" : "stale-reset", line, index, lyricTimeS, staleAfterS);
79
- resetLineAnimationState(line);
80
- }
81
- if (wasSelected || playhead.jumped)
82
- updateWordStates(line, lyricTimeS);
83
- }
84
- function startLine({ engine, lyricTimeS, playhead, config, now }, line) {
85
- startLineAnimations(engine, line, config, lyricTimeS);
86
- line.isAnimating = true;
87
- line.lastAnimSetupAt = now;
88
- line.isAnimationPlayStatePlaying = playhead.isPlaying;
89
- line.accumulatedOffsetMs = 0;
90
- if (!playhead.isPlaying)
91
- setAnimationsPlayState(line, false);
92
- }