@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,84 +0,0 @@
1
- import type { AnimationEngineInstance } from "./instance.js";
2
- export interface AnimationConfig {
3
- enabled: {
4
- lineScale: boolean;
5
- wordWobble: boolean;
6
- highlightSwipe: boolean;
7
- highlightGlow: boolean;
8
- highlightFade: boolean;
9
- scroll: boolean;
10
- instrumental: boolean;
11
- };
12
- line: {
13
- durationMs: number;
14
- enterEasing: string;
15
- exitEasing: string;
16
- enterFrom: string;
17
- enterTo: string;
18
- exitFrom: string;
19
- exitTo: string;
20
- };
21
- highlight: {
22
- fadeInDurationMs: number;
23
- fadeOutDurationMs: number;
24
- fadeInEasing: string;
25
- fadeOutEasing: string;
26
- swipeEasing: string;
27
- swipeStartFrom: string;
28
- swipeEndFrom: string;
29
- swipeStartTo: string;
30
- swipeEndTo: string;
31
- glowFrom: string;
32
- glowTo: string;
33
- glowDurationRatio: number;
34
- glowMinDurationMs: number;
35
- glowEasing: string;
36
- glowContainerAlpha: number;
37
- glowRestingInvisible: boolean;
38
- };
39
- word: {
40
- wobbleDurationMs: number;
41
- wobbleEasing: string;
42
- wobblePeakEasing: string;
43
- wobbleEndEasing: string;
44
- wobbleFrom: string;
45
- wobblePeak: string;
46
- wobbleSettle: string;
47
- wobbleTo: string;
48
- wobblePeakOffset: number;
49
- wobbleSettleOffset: number;
50
- };
51
- letterWave: {
52
- transform: string;
53
- settle: string;
54
- emphasisScale: string;
55
- durationMs: number;
56
- riseEasing: string;
57
- fallEasing: string;
58
- };
59
- instrumental: {
60
- fillFadeDurationMs: number;
61
- fillFadeEasing: string;
62
- fillFrom: string;
63
- fillTo: string;
64
- fillEasing: string;
65
- waveFrom: string;
66
- waveTo: string;
67
- waveEasing: string;
68
- wavePathHigh: string;
69
- wavePathLow: string;
70
- waveOscillationDurationMs: number;
71
- waveOscillationEasing: string;
72
- };
73
- lineScroll: {
74
- easing: string;
75
- differentialEffects: boolean;
76
- };
77
- }
78
- export interface AnimationSettings {
79
- config: AnimationConfig;
80
- scrollTiming: {
81
- earlyScrollConsiderS: number;
82
- };
83
- }
84
- export declare function getAnimationSettings(engine: AnimationEngineInstance, lyricsElement: HTMLElement): AnimationSettings;
@@ -1,95 +0,0 @@
1
- import { registerThemeSetting } from "../themeSettings.js";
2
- import { REDUCED_MOTION_QUERY } from "./motionPreference.js";
3
- import { createThemeReader } from "./cssValues.js";
4
- import { isGlowRestingInvisible, parseColorAlpha, resolveGlowFilter } from "./glow.js";
5
- import { INSTRUMENTAL_WAVE_PATH_HIGH_FALLBACK, INSTRUMENTAL_WAVE_PATH_LOW_FALLBACK } from "./instrumentalAnimations.js";
6
- const EARLY_SCROLL_CONSIDER = registerThemeSetting("blyrics-early-scroll-consider-s", 0.54);
7
- const DEFAULT_SCROLL_EASING = "cubic-bezier(0.86, 0, 0.2, 1)";
8
- export function getAnimationSettings(engine, lyricsElement) {
9
- engine.cachedAnimationSettings ??= {
10
- config: readAnimationConfig(engine, lyricsElement),
11
- scrollTiming: { earlyScrollConsiderS: Math.max(0, EARLY_SCROLL_CONSIDER.getNumberValue()) },
12
- };
13
- return engine.cachedAnimationSettings;
14
- }
15
- function readAnimationConfig(engine, lyricsElement) {
16
- const css = createThemeReader(engine, lyricsElement);
17
- const glowFrom = resolveGlowFilter(engine, lyricsElement, "from", "0.8rem");
18
- const glowTo = resolveGlowFilter(engine, lyricsElement, "to", "0");
19
- return {
20
- enabled: {
21
- lineScale: css.flag("--blyrics-animate-line-scale", true),
22
- wordWobble: css.flag("--blyrics-animate-word-wobble", true),
23
- highlightSwipe: css.flag("--blyrics-animate-highlight-swipe", true),
24
- highlightGlow: css.flag("--blyrics-animate-highlight-glow", true),
25
- highlightFade: css.flag("--blyrics-animate-highlight-fade", true),
26
- scroll: css.flag("--blyrics-animate-scroll", true),
27
- instrumental: css.flag("--blyrics-animate-instrumental", true),
28
- },
29
- line: {
30
- durationMs: css.durationMs("--blyrics-scale-transition-duration", "0.166s"),
31
- enterEasing: css.string("--blyrics-line-enter-easing", "ease"),
32
- exitEasing: css.string("--blyrics-line-exit-easing", "ease"),
33
- enterFrom: css.string("--blyrics-line-enter-transform-from", "scale(var(--blyrics-scale))"),
34
- enterTo: css.string("--blyrics-line-enter-transform-to", "scale(var(--blyrics-active-scale))"),
35
- exitFrom: css.string("--blyrics-line-exit-transform-from", "scale(var(--blyrics-active-scale))"),
36
- exitTo: css.string("--blyrics-line-exit-transform-to", "scale(var(--blyrics-scale))"),
37
- },
38
- highlight: {
39
- fadeInDurationMs: css.durationMs("--blyrics-lyric-highlight-fade-in-duration", "0.33s"),
40
- fadeOutDurationMs: css.durationMs("--blyrics-lyric-highlight-fade-out-duration", "0.5s"),
41
- fadeInEasing: css.string("--blyrics-lyric-highlight-fade-in-easing", "ease"),
42
- fadeOutEasing: css.string("--blyrics-lyric-highlight-fade-out-easing", "ease"),
43
- swipeEasing: css.string("--blyrics-highlight-swipe-easing", "linear"),
44
- swipeStartFrom: css.string("--blyrics-highlight-swipe-start-from", "-0.2"),
45
- swipeEndFrom: css.string("--blyrics-highlight-swipe-end-from", "-0.1"),
46
- swipeStartTo: css.string("--blyrics-highlight-swipe-start-to", "1.4"),
47
- swipeEndTo: css.string("--blyrics-highlight-swipe-end-to", "1.5"),
48
- glowFrom,
49
- glowTo,
50
- glowDurationRatio: css.number("--blyrics-highlight-glow-duration-ratio", 1.2),
51
- glowMinDurationMs: css.durationMs("--blyrics-highlight-glow-min-duration", "1.2s"),
52
- glowEasing: css.string("--blyrics-highlight-glow-easing", "ease"),
53
- glowContainerAlpha: parseColorAlpha(css.string("--blyrics-glow-color", "")) ?? 1,
54
- glowRestingInvisible: isGlowRestingInvisible(glowTo),
55
- },
56
- word: {
57
- wobbleDurationMs: css.durationMs("--blyrics-wobble-duration", "1s"),
58
- wobbleEasing: css.string("--blyrics-word-wobble-easing", "ease"),
59
- wobblePeakEasing: css.string("--blyrics-word-wobble-peak-easing", "ease-in-out"),
60
- wobbleEndEasing: css.string("--blyrics-word-wobble-end-easing", "ease-out"),
61
- wobbleFrom: css.string("--blyrics-word-wobble-transform-from", "scaleX(1)"),
62
- wobblePeak: css.string("--blyrics-word-wobble-transform-peak", "translateX(0.05em) scaleX(1.025)"),
63
- wobbleSettle: css.string("--blyrics-word-wobble-transform-settle", "translateX(0) scaleX(1)"),
64
- wobbleTo: css.string("--blyrics-word-wobble-transform-to", "scaleX(1)"),
65
- wobblePeakOffset: css.fraction("--blyrics-word-wobble-peak-offset", 0.125),
66
- wobbleSettleOffset: css.fraction("--blyrics-word-wobble-settle-offset", 0.75),
67
- },
68
- letterWave: {
69
- transform: css.string("--blyrics-letter-wave-transform", "translateY(-0.06em)"),
70
- settle: css.string("--blyrics-letter-wave-settle", "translateY(-0.05em)"),
71
- emphasisScale: css.string("--blyrics-letter-wave-emphasis-scale", "1.08"),
72
- durationMs: css.durationMs("--blyrics-letter-wave-duration", "0.9s"),
73
- riseEasing: css.string("--blyrics-letter-wave-rise-easing", "ease-in-out"),
74
- fallEasing: css.string("--blyrics-letter-wave-fall-easing", "ease-in-out"),
75
- },
76
- instrumental: {
77
- fillFadeDurationMs: css.durationMs("--blyrics-instrumental-fill-fade-duration", "150ms"),
78
- fillFadeEasing: css.string("--blyrics-instrumental-fill-fade-easing", "ease"),
79
- fillFrom: css.string("--blyrics-instrumental-fill-transform-from", "translateY(78%)"),
80
- fillTo: css.string("--blyrics-instrumental-fill-transform-to", "translateY(-4%)"),
81
- fillEasing: css.string("--blyrics-instrumental-fill-easing", "linear"),
82
- waveFrom: css.string("--blyrics-instrumental-wave-transform-from", "scaleY(1.2)"),
83
- waveTo: css.string("--blyrics-instrumental-wave-transform-to", "scaleY(0.0001)"),
84
- waveEasing: css.string("--blyrics-instrumental-wave-easing", "ease-in"),
85
- wavePathHigh: css.string("--blyrics-instrumental-wave-path-high", INSTRUMENTAL_WAVE_PATH_HIGH_FALLBACK),
86
- wavePathLow: css.string("--blyrics-instrumental-wave-path-low", INSTRUMENTAL_WAVE_PATH_LOW_FALLBACK),
87
- waveOscillationDurationMs: css.durationMs("--blyrics-instrumental-wave-oscillation-duration", "1.25s"),
88
- waveOscillationEasing: css.string("--blyrics-instrumental-wave-oscillation-easing", "ease-in-out"),
89
- },
90
- lineScroll: {
91
- easing: css.string("--blyrics-lyric-scroll-timing-function", DEFAULT_SCROLL_EASING),
92
- differentialEffects: !engine.window.matchMedia(REDUCED_MOTION_QUERY).matches,
93
- },
94
- };
95
- }
@@ -1,11 +0,0 @@
1
- import type { LineData } from "../inject.js";
2
- import type { AnimationEngineInstance } from "./instance.js";
3
- export interface DriftCheck {
4
- engine: AnimationEngineInstance;
5
- line: LineData;
6
- lineIndex: number;
7
- lyricTimeS: number;
8
- isPlaying: boolean;
9
- now: number;
10
- }
11
- export declare function correctLineDrift({ engine, line, lineIndex, lyricTimeS, isPlaying, now }: DriftCheck): void;
@@ -1,43 +0,0 @@
1
- import { clamp } from "../util.js";
2
- import { largestDriftSample } from "./animationTiming.js";
3
- import { resetLineAnimationState } from "./lineAnimationState.js";
4
- import { logAnimationTiming, shouldLogAnimationTiming } from "./timingLogs.js";
5
- const LEARN_RATE = 0.08;
6
- const LEARN_SAMPLE_LIMIT_MS = 80;
7
- const MAX_LEARNED_OFFSET_MS = 80;
8
- const ACCUMULATION_DECAY = 1.08;
9
- const ACCUMULATION_WEIGHT = 0.4;
10
- const RESET_THRESHOLD_MS = 100;
11
- export function correctLineDrift({ engine, line, lineIndex, lyricTimeS, isPlaying, now }) {
12
- const sample = largestDriftSample(line, lyricTimeS);
13
- line.accumulatedOffsetMs /= ACCUMULATION_DECAY;
14
- if (sample === null)
15
- return;
16
- if (!isUsableForDrift(sample, isPlaying)) {
17
- if (shouldLogAnimationTiming(engine, line, sample, now)) {
18
- logAnimationTiming(engine, "ignored-sample", line, lineIndex, sample, lyricTimeS, line.accumulatedOffsetMs);
19
- }
20
- return;
21
- }
22
- const learnedOffsetMs = learnTimingOffset(engine, sample);
23
- line.accumulatedOffsetMs += sample.offsetMs * ACCUMULATION_WEIGHT;
24
- if (shouldLogAnimationTiming(engine, line, sample, now)) {
25
- const accumulatedMs = line.accumulatedOffsetMs;
26
- logAnimationTiming(engine, "sample", line, lineIndex, sample, lyricTimeS, accumulatedMs, learnedOffsetMs);
27
- }
28
- const drifted = Math.abs(line.accumulatedOffsetMs) > RESET_THRESHOLD_MS;
29
- if (line.isAnimating && isPlaying && drifted) {
30
- logAnimationTiming(engine, "drift-reset", line, lineIndex, sample, lyricTimeS, line.accumulatedOffsetMs);
31
- resetLineAnimationState(line);
32
- }
33
- }
34
- function isUsableForDrift(sample, isPlaying) {
35
- return isPlaying && (sample.playState === "running" || sample.playState === "finished");
36
- }
37
- function learnTimingOffset(engine, sample) {
38
- if (Math.abs(sample.biasOffsetMs) > LEARN_SAMPLE_LIMIT_MS)
39
- return engine.learnedAnimationTimingOffsetMs;
40
- const learned = engine.learnedAnimationTimingOffsetMs;
41
- engine.learnedAnimationTimingOffsetMs = clamp(learned + (sample.biasOffsetMs - learned) * LEARN_RATE, -MAX_LEARNED_OFFSET_MS, MAX_LEARNED_OFFSET_MS);
42
- return engine.learnedAnimationTimingOffsetMs;
43
- }
@@ -1,27 +0,0 @@
1
- import type { LineData, PartData } from "../inject.js";
2
- import type { AnimationEngineInstance } from "./instance.js";
3
- export interface SongClockTrack {
4
- offsetMs: number;
5
- appliedTimingOffsetMs: number;
6
- skipDriftSample?: boolean;
7
- wrapDurationMs?: number;
8
- }
9
- export interface DriftSample {
10
- actualTimeMs: number;
11
- appliedTimingOffsetMs: number;
12
- biasOffsetMs: number;
13
- expectedTimeMs: number;
14
- offsetMs: number;
15
- playState: AnimationPlayState;
16
- }
17
- export declare function seekAnimation(engine: AnimationEngineInstance, animation: Animation, timeMs: number): void;
18
- export declare function followSongClock(engine: AnimationEngineInstance, animation: Animation, track: Omit<SongClockTrack, "appliedTimingOffsetMs"> & {
19
- appliedTimingOffsetMs?: number;
20
- }): Animation;
21
- /** Repeats a word's own animations on the cells of a sweep drawn for it from copies of its line. */
22
- export declare function mirrorHighlightAnimations(part: PartData, animations: Animation[]): Animation[];
23
- export declare function applyPlaybackRateToRunningAnimations(engine: AnimationEngineInstance): void;
24
- export declare function correctedAnimationTimeMs(targetTimeMs: number, appliedTimingOffsetMs: number, maxTimeMs?: number): number;
25
- export declare function correctedWrappedAnimationTimeMs(targetTimeMs: number, appliedTimingOffsetMs: number, wrapDurationMs: number): number;
26
- export declare function correctedScrollTimeS(engine: AnimationEngineInstance, lyricTimeS: number): number;
27
- export declare function largestDriftSample(line: LineData, lyricTimeS: number): DriftSample | null;
@@ -1,145 +0,0 @@
1
- import { positiveModulo, toMs } from "../util.js";
2
- const songClockTracks = new WeakMap();
3
- // A current time set before an animation starts holds until its first frame, which a long setup frame delays.
4
- export function seekAnimation(engine, animation, timeMs) {
5
- const rate = animation.playbackRate;
6
- if (!engine.lastTickOptions?.isPlaying || typeof animation.timeline?.currentTime !== "number" || rate === 0) {
7
- animation.currentTime = timeMs;
8
- return;
9
- }
10
- animation.startTime = timelineNow(animation) - timeMs / rate;
11
- }
12
- // A document's timeline counts from its own window's time origin, which differs in another window or frame.
13
- function timelineNow(animation) {
14
- const target = animation.effect?.target;
15
- return target?.ownerDocument.defaultView?.performance.now() ?? performance.now();
16
- }
17
- // The timeline's time is held per task and per frame, so a running animation is read against now, the clock it was placed on.
18
- function liveCurrentTimeMs(animation) {
19
- const startTimeMs = animation.startTime;
20
- if (animation.playState === "running" && typeof startTimeMs === "number") {
21
- return (timelineNow(animation) - startTimeMs) * animation.playbackRate;
22
- }
23
- return timingValueToMs(animation.currentTime);
24
- }
25
- export function followSongClock(engine, animation, track) {
26
- songClockTracks.set(animation, {
27
- ...track,
28
- appliedTimingOffsetMs: track.appliedTimingOffsetMs ?? engine.learnedAnimationTimingOffsetMs,
29
- });
30
- animation.playbackRate = engine.playbackRate;
31
- return animation;
32
- }
33
- /** Repeats a word's own animations on the cells of a sweep drawn for it from copies of its line. */
34
- export function mirrorHighlightAnimations(part, animations) {
35
- const target = part.sweepContext?.host;
36
- if (!target)
37
- return [];
38
- const mirrors = [];
39
- for (const animation of animations) {
40
- const effect = animation.effect;
41
- if (!effect || effect.target !== part.highlightElement)
42
- continue;
43
- const mirror = target.animate(effect.getKeyframes(), effect.getTiming());
44
- mirror.playbackRate = animation.playbackRate;
45
- if (animation.playState === "running" && animation.startTime !== null)
46
- mirror.startTime = animation.startTime;
47
- else
48
- mirror.currentTime = animation.currentTime;
49
- const track = songClockTracks.get(animation);
50
- if (track)
51
- songClockTracks.set(mirror, { ...track, skipDriftSample: true });
52
- mirrors.push(mirror);
53
- }
54
- return mirrors;
55
- }
56
- export function applyPlaybackRateToRunningAnimations(engine) {
57
- const followRate = (animations) => {
58
- for (const animation of animations) {
59
- if (songClockTracks.has(animation))
60
- animation.playbackRate = engine.playbackRate;
61
- }
62
- };
63
- for (const line of engine.lines) {
64
- followRate(line.animations);
65
- for (const part of line.parts)
66
- followRate(part.animations);
67
- }
68
- }
69
- export function correctedAnimationTimeMs(targetTimeMs, appliedTimingOffsetMs, maxTimeMs) {
70
- const scheduledTimeMs = targetTimeMs - appliedTimingOffsetMs;
71
- return maxTimeMs === undefined ? scheduledTimeMs : Math.min(scheduledTimeMs, maxTimeMs);
72
- }
73
- export function correctedWrappedAnimationTimeMs(targetTimeMs, appliedTimingOffsetMs, wrapDurationMs) {
74
- return positiveModulo(targetTimeMs - appliedTimingOffsetMs, wrapDurationMs);
75
- }
76
- export function correctedScrollTimeS(engine, lyricTimeS) {
77
- return lyricTimeS - engine.learnedAnimationTimingOffsetMs / 1000;
78
- }
79
- export function largestDriftSample(line, lyricTimeS) {
80
- let largest = accumulateLargestDriftSample(line, lyricTimeS, null);
81
- for (const part of line.parts)
82
- largest = accumulateLargestDriftSample(part, lyricTimeS, largest);
83
- return largest;
84
- }
85
- function accumulateLargestDriftSample(part, lyricTimeS, largest) {
86
- for (const animation of part.animations) {
87
- const sample = driftSample(part, animation, lyricTimeS);
88
- if (sample && (!largest || Math.abs(sample.offsetMs) > Math.abs(largest.offsetMs)))
89
- largest = sample;
90
- }
91
- return largest;
92
- }
93
- function driftSample(part, animation, lyricTimeS) {
94
- const track = songClockTracks.get(animation);
95
- if (!track || track.skipDriftSample || animation.playState === "idle")
96
- return null;
97
- const rawActualTimeMs = liveCurrentTimeMs(animation);
98
- if (rawActualTimeMs === null)
99
- return null;
100
- const expectedTimeMs = normalizedTimeMs(animation, (lyricTimeS - part.time) * 1000 + track.offsetMs, track);
101
- const actualTimeMs = normalizedTimeMs(animation, rawActualTimeMs, track);
102
- if (expectedTimeMs === null || actualTimeMs === null)
103
- return null;
104
- const wrapDurationMs = track.wrapDurationMs ?? 0;
105
- const offsetMs = wrapDurationMs > 0 ? wrappedOffsetMs(actualTimeMs, expectedTimeMs, wrapDurationMs) : actualTimeMs - expectedTimeMs;
106
- return {
107
- actualTimeMs,
108
- appliedTimingOffsetMs: track.appliedTimingOffsetMs,
109
- biasOffsetMs: offsetMs + track.appliedTimingOffsetMs,
110
- expectedTimeMs,
111
- offsetMs,
112
- playState: animation.playState,
113
- };
114
- }
115
- function normalizedTimeMs(animation, timeMs, track) {
116
- if (!Number.isFinite(timeMs) || timeMs < 0)
117
- return null;
118
- if (track.wrapDurationMs && track.wrapDurationMs > 0)
119
- return positiveModulo(timeMs, track.wrapDurationMs);
120
- // Clamp to the effect's endTime, including delay/endDelay. Clamping to duration can hide drift in delayed
121
- // letter waves.
122
- const endTimeMs = timingValueToMs(animation.effect?.getComputedTiming().endTime);
123
- return endTimeMs !== null && Number.isFinite(endTimeMs) ? Math.min(timeMs, endTimeMs) : timeMs;
124
- }
125
- function wrappedOffsetMs(actualTimeMs, expectedTimeMs, wrapDurationMs) {
126
- return positiveModulo(actualTimeMs - expectedTimeMs + wrapDurationMs / 2, wrapDurationMs) - wrapDurationMs / 2;
127
- }
128
- function timingValueToMs(value) {
129
- if (typeof value === "number")
130
- return Number.isFinite(value) || value === Number.POSITIVE_INFINITY ? value : null;
131
- if (typeof value === "string") {
132
- const durationMs = toMs(value);
133
- return durationMs > 0 ? durationMs : null;
134
- }
135
- const numeric = value;
136
- if (typeof numeric?.to !== "function")
137
- return null;
138
- try {
139
- const ms = numeric.to("ms").value;
140
- return typeof ms === "number" && Number.isFinite(ms) ? ms : null;
141
- }
142
- catch {
143
- return null;
144
- }
145
- }
@@ -1,24 +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 interface ScrollerReading {
5
- element: HTMLElement;
6
- height: number;
7
- scrollTop: number;
8
- maxScrollTop: number;
9
- }
10
- export interface AutoScrollTick {
11
- engine: AnimationEngineInstance;
12
- lyricsElement: HTMLElement;
13
- scroller: ScrollerReading;
14
- focusedLines: LineData[];
15
- scrollTimeS: number;
16
- config: AnimationConfig;
17
- smoothScroll: boolean;
18
- countEveryUserScroll: boolean;
19
- jumped: boolean;
20
- focusChanged: boolean;
21
- now: number;
22
- }
23
- export declare function followFocusedLines(tick: AutoScrollTick): void;
24
- export declare function lastSungLine(engine: AnimationEngineInstance): LineData | undefined;
@@ -1,103 +0,0 @@
1
- import { USER_SCROLLING_CLASS } from "../constants.js";
2
- import { registerThemeSetting } from "../themeSettings.js";
3
- import { clamp } from "../util.js";
4
- import { updateVisibleLyricWillChange } from "./culling.js";
5
- import { drawScrollDebugOverlay, isDebugOverlayEnabled } from "./debugOverlay.js";
6
- import { commitOrPrepareLineScroll, dropPendingLineScroll, getLineScrollItems, prepareUpcomingLineScroll, SCROLL_PREPARE_LEAD_MS, } from "./lineScroll.js";
7
- import { computeActiveLinesScrollTop, findScrollAnchor, getTargetScrollRatio } from "./scrollViewport.js";
8
- import { decaySkipScrolls, writeEngineScrollTop } from "./userScroll.js";
9
- const LYRIC_ENDING_THRESHOLD_S = registerThemeSetting("blyrics-lyric-ending-threshold-s", 0.5);
10
- const SCROLL_DEADBAND_PX = 2;
11
- export function followFocusedLines(tick) {
12
- const { engine, lyricsElement, now } = tick;
13
- if (isAutoScrolling(engine, now))
14
- scrollToFocusedLines(tick);
15
- if (engine.wasUserScrolling && engine.scrollResumeTime < now) {
16
- engine.host.setResumeAffordanceVisible(false);
17
- lyricsElement.classList.remove(USER_SCROLLING_CLASS);
18
- engine.wasUserScrolling = false;
19
- }
20
- decaySkipScrolls(engine, now, !tick.countEveryUserScroll);
21
- }
22
- function isAutoScrolling(engine, now) {
23
- return engine.scrollResumeTime < now || engine.scrollPos === -1;
24
- }
25
- export function lastSungLine(engine) {
26
- return engine.lines.findLast(line => line.lyricElement.dataset.instrumental !== "true");
27
- }
28
- function scrollToFocusedLines(tick) {
29
- const { engine, lyricsElement, scroller, scrollTimeS, config, smoothScroll, jumped } = tick;
30
- const followedLines = tick.focusedLines.length > 0 ? tick.focusedLines : engine.lines.slice(0, 1);
31
- const leadLine = followedLines.at(-1);
32
- if (!leadLine)
33
- return;
34
- const targetOffset = scroller.height * getTargetScrollRatio(engine, lyricsElement);
35
- const endingThresholdS = LYRIC_ENDING_THRESHOLD_S.getNumberValue();
36
- const sungLines = followedLines.filter(line => line === leadLine || scrollTimeS < line.time + line.duration - endingThresholdS);
37
- const lineCenters = sungLines.map(line => line.position + line.height / 2);
38
- const anchor = findScrollAnchor(sungLines, scrollTimeS);
39
- const target = computeActiveLinesScrollTop(sungLines, anchor, scroller.height, engine.cachedScrollInsets, targetOffset);
40
- const toScrollTop = clamp(creditsAwareScrollTop(engine, target.scrollTop, targetOffset), 0, scroller.maxScrollTop);
41
- if (isDebugOverlayEnabled()) {
42
- drawScrollDebugOverlay(engine, {
43
- lyricsElement,
44
- scrollTop: scroller.scrollTop,
45
- viewportHeight: scroller.height,
46
- targetOffset,
47
- followedLines,
48
- lineCenters,
49
- scrollTimeS,
50
- endingThresholdS,
51
- });
52
- }
53
- const pinned = engine.pinnedScrollLine;
54
- const pinnedLineFinished = pinned !== null &&
55
- pinned !== anchor &&
56
- (!sungLines.includes(pinned) || scrollTimeS >= pinned.time + pinned.duration);
57
- const mustCommit = tick.focusChanged || pinnedLineFinished || engine.wasUserScrolling;
58
- const fromScrollTop = scroller.scrollTop;
59
- const moves = Math.abs(toScrollTop - fromScrollTop) > SCROLL_DEADBAND_PX;
60
- const animatesScroll = smoothScroll && config.enabled.scroll;
61
- const request = () => ({
62
- lines: getLineScrollItems(engine, engine.lines),
63
- activeLine: leadLine,
64
- fromScrollTop,
65
- toScrollTop,
66
- viewportHeight: scroller.height,
67
- config,
68
- continuesEngineScroll: !jumped &&
69
- !engine.wasUserScrolling &&
70
- engine.scrollPos >= 0 &&
71
- Math.abs(fromScrollTop - engine.scrollPos) <= SCROLL_DEADBAND_PX,
72
- });
73
- const msUntilLeadLine = (leadLine.time - scrollTimeS) * 1000;
74
- const leadLineIsNext = msUntilLeadLine > 0 && msUntilLeadLine <= SCROLL_PREPARE_LEAD_MS;
75
- if (animatesScroll && moves && !mustCommit && leadLineIsNext && !engine.lastScrollElements.includes(leadLine)) {
76
- updateVisibleLyricWillChange(engine, engine.lines, fromScrollTop, toScrollTop, scroller.height);
77
- prepareUpcomingLineScroll(engine, request());
78
- }
79
- if (!mustCommit)
80
- return;
81
- engine.lastScrollElements = followedLines;
82
- engine.pinnedScrollLine = target.overflowsBand ? anchor : null;
83
- engine.lastScrollDebugContext = { lyricScrollTime: scrollTimeS, centers: lineCenters, activeElms: followedLines };
84
- if (smoothScroll && moves) {
85
- if (config.enabled.scroll) {
86
- updateVisibleLyricWillChange(engine, engine.lines, fromScrollTop, toScrollTop, scroller.height);
87
- commitOrPrepareLineScroll(engine, request());
88
- }
89
- }
90
- else {
91
- dropPendingLineScroll(engine);
92
- }
93
- writeEngineScrollTop(engine, scroller.element, toScrollTop, tick.now);
94
- }
95
- function creditsAwareScrollTop(engine, scrollTop, targetOffset) {
96
- const credits = engine.cachedCreditsItem;
97
- const lastLine = lastSungLine(engine);
98
- if (!engine.creditsFocused || !credits || !lastLine)
99
- return scrollTop;
100
- const creditsCentered = credits.position + credits.height / 2 - targetOffset;
101
- const lastLineAtTop = lastLine.position - engine.cachedScrollInsets.top;
102
- return Math.min(creditsCentered, lastLineAtTop);
103
- }
@@ -1,29 +0,0 @@
1
- import type { ResolvedTickOptions } from "../types.js";
2
- import type { AnimationEngineInstance } from "./instance.js";
3
- export declare const SMOOTH_PLAYBACK_CLOCK: boolean;
4
- export declare const CLOCK_RESYNC_THRESHOLD_S = 0.06;
5
- export declare const NO_PLAYER_SNAPSHOT = -1;
6
- interface PlaybackClock {
7
- lastTime: number;
8
- lastPlayState: boolean;
9
- lastEventCreationTime: number;
10
- smoothedTime: number;
11
- smoothedAt: number;
12
- }
13
- export declare const playbackClock: PlaybackClock;
14
- /**
15
- * Clears the shared playback history when switching songs.
16
- */
17
- export declare function resetPlaybackClock(): void;
18
- export declare function smoothedPlaybackTime(previousTime: number, previousAt: number, rawTime: number, now: number, playbackRate: number): number;
19
- export interface Playhead {
20
- timeS: number;
21
- isPlaying: boolean;
22
- jumped: boolean;
23
- mediaClockRanBackwards: boolean;
24
- seekedWhilePaused: boolean;
25
- }
26
- export declare function advancePlaybackClock(reportedTimeS: number, { isPlaying, eventCreationTime, followPausedSeeks }: ResolvedTickOptions, playbackRate: number, now: number): Playhead;
27
- export declare function lyricClockShiftS(engine: AnimationEngineInstance, lyricsElement: HTMLElement, options: ResolvedTickOptions): number;
28
- export declare function playerTimeForLyricTime(engine: AnimationEngineInstance, lyricTimeS: number): number;
29
- export {};
@@ -1,70 +0,0 @@
1
- import { isGecko } from "../util.js";
2
- import { getCSSDurationInMs } from "./cssValues.js";
3
- // Gecko has been seen to step media time about every 40 ms, so a read can lag by up to one step (never
4
- // lead), and that lag would reseek lines as drift. A read off by more than a step plus margin is treated as
5
- // a seek or a timer spike.
6
- export const SMOOTH_PLAYBACK_CLOCK = isGecko();
7
- export const CLOCK_RESYNC_THRESHOLD_S = 0.06;
8
- const CLOCK_SLEW_PER_S = 0.1;
9
- export const NO_PLAYER_SNAPSHOT = -1;
10
- export const playbackClock = {
11
- lastTime: 0,
12
- lastPlayState: false,
13
- lastEventCreationTime: NO_PLAYER_SNAPSHOT,
14
- smoothedTime: 0,
15
- smoothedAt: NO_PLAYER_SNAPSHOT,
16
- };
17
- /**
18
- * Clears the shared playback history when switching songs.
19
- */
20
- export function resetPlaybackClock() {
21
- playbackClock.lastTime = 0;
22
- playbackClock.lastPlayState = false;
23
- playbackClock.lastEventCreationTime = NO_PLAYER_SNAPSHOT;
24
- playbackClock.smoothedAt = NO_PLAYER_SNAPSHOT;
25
- }
26
- export function smoothedPlaybackTime(previousTime, previousAt, rawTime, now, playbackRate) {
27
- if (previousAt === NO_PLAYER_SNAPSHOT)
28
- return rawTime;
29
- const elapsedS = Math.max(0, now - previousAt) / 1000;
30
- const predictedTime = previousTime + elapsedS * playbackRate;
31
- const errorS = rawTime - predictedTime;
32
- if (errorS >= 0 || Math.abs(errorS) >= CLOCK_RESYNC_THRESHOLD_S)
33
- return rawTime;
34
- return predictedTime + errorS * Math.min(1, elapsedS * CLOCK_SLEW_PER_S);
35
- }
36
- const TIME_JUMP_THRESHOLD_S = 0.5;
37
- export function advancePlaybackClock(reportedTimeS, { isPlaying, eventCreationTime, followPausedSeeks }, playbackRate, now) {
38
- const snapshotGapS = (eventCreationTime - playbackClock.lastEventCreationTime) / 1000;
39
- const jumped = Math.abs(reportedTimeS - playbackClock.lastTime - snapshotGapS) > TIME_JUMP_THRESHOLD_S;
40
- const readsMediaClockDirectly = eventCreationTime === NO_PLAYER_SNAPSHOT;
41
- const mediaClockRanBackwards = readsMediaClockDirectly && isPlaying && reportedTimeS < playbackClock.lastTime - CLOCK_RESYNC_THRESHOLD_S;
42
- const seekedWhilePaused = followPausedSeeks && !isPlaying && !playbackClock.lastPlayState && reportedTimeS !== playbackClock.lastTime;
43
- playbackClock.lastTime = reportedTimeS;
44
- playbackClock.lastPlayState = isPlaying;
45
- playbackClock.lastEventCreationTime = eventCreationTime;
46
- const snapshotAgeS = isPlaying && !readsMediaClockDirectly ? (now - eventCreationTime) / 1000 : 0;
47
- let timeS = reportedTimeS + snapshotAgeS;
48
- if (SMOOTH_PLAYBACK_CLOCK) {
49
- if (isPlaying && !jumped) {
50
- timeS = smoothedPlaybackTime(playbackClock.smoothedTime, playbackClock.smoothedAt, timeS, now, playbackRate);
51
- }
52
- playbackClock.smoothedTime = timeS;
53
- playbackClock.smoothedAt = isPlaying ? now : NO_PLAYER_SNAPSHOT;
54
- }
55
- return { timeS, isPlaying, jumped, mediaClockRanBackwards, seekedWhilePaused };
56
- }
57
- export function lyricClockShiftS(engine, lyricsElement, options) {
58
- const syncTypeShiftS = engine.syncType === "richsync"
59
- ? getCSSDurationInMs(engine, lyricsElement, "--blyrics-richsync-timing-offset") / 1000 -
60
- options.richsyncOffsetTrim
61
- : getCSSDurationInMs(engine, lyricsElement, "--blyrics-timing-offset") / 1000 - options.lineOffsetTrim;
62
- return syncTypeShiftS - options.globalLyricOffset - options.lyricOffset;
63
- }
64
- export function playerTimeForLyricTime(engine, lyricTimeS) {
65
- const options = engine.lastTickOptions;
66
- const lyricsElement = engine.lyricsContainer;
67
- if (!options || !lyricsElement)
68
- return lyricTimeS;
69
- return Math.max(0, lyricTimeS - lyricClockShiftS(engine, lyricsElement, options));
70
- }
@@ -1,10 +0,0 @@
1
- import { type LineData } from "../inject.js";
2
- import type { AnimationConfig } from "./animationConfig.js";
3
- /**
4
- * Places the sweep cells of a line's inline words over the boxes those words are laid out in. Runs
5
- * when the line starts animating and reads layout first, so the reads land before the line's writes;
6
- * a word laid out as it was last time keeps its cells.
7
- */
8
- export declare function placeContextSweeps(line: LineData, config: AnimationConfig): void;
9
- /** Whether a line started before its inline words could be placed, and has to start over to show them. */
10
- export declare function hasUnplacedContextSweeps(line: LineData): boolean;