@braccato/core 1.19.1 → 1.20.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 (70) hide show
  1. package/dist/engine/animationConfig.d.ts +88 -0
  2. package/dist/engine/animationConfig.js +98 -0
  3. package/dist/engine/animationDrift.d.ts +11 -0
  4. package/dist/engine/animationDrift.js +43 -0
  5. package/dist/engine/animationTiming.d.ts +25 -0
  6. package/dist/engine/animationTiming.js +119 -0
  7. package/dist/engine/autoScroll.d.ts +24 -0
  8. package/dist/engine/autoScroll.js +103 -0
  9. package/dist/engine/clock.d.ts +29 -0
  10. package/dist/engine/clock.js +70 -0
  11. package/dist/engine/cssValues.d.ts +13 -0
  12. package/dist/engine/cssValues.js +47 -0
  13. package/dist/engine/culling.d.ts +6 -0
  14. package/dist/engine/culling.js +67 -0
  15. package/dist/engine/debugOverlay.d.ts +14 -0
  16. package/dist/engine/debugOverlay.js +58 -0
  17. package/dist/engine/decorationSlides.d.ts +6 -0
  18. package/dist/engine/decorationSlides.js +44 -0
  19. package/dist/engine/glow.d.ts +7 -0
  20. package/dist/engine/glow.js +59 -0
  21. package/dist/engine/highlightKeyframes.d.ts +8 -0
  22. package/dist/engine/highlightKeyframes.js +37 -0
  23. package/dist/engine/instance.d.ts +102 -0
  24. package/dist/engine/instance.js +87 -0
  25. package/dist/engine/instrumentalAnimations.d.ts +7 -0
  26. package/dist/engine/instrumentalAnimations.js +59 -0
  27. package/dist/engine/letterPlans.d.ts +42 -0
  28. package/dist/engine/letterPlans.js +103 -0
  29. package/dist/engine/lineAnimationState.d.ts +10 -0
  30. package/dist/engine/lineAnimationState.js +85 -0
  31. package/dist/engine/lineAnimations.d.ts +5 -0
  32. package/dist/engine/lineAnimations.js +82 -0
  33. package/dist/engine/lineLifecycle.d.ts +12 -0
  34. package/dist/engine/lineLifecycle.js +92 -0
  35. package/dist/engine/lineScroll.d.ts +48 -0
  36. package/dist/engine/lineScroll.js +174 -0
  37. package/dist/engine/lineScrollStyle.d.ts +27 -0
  38. package/dist/engine/lineScrollStyle.js +119 -0
  39. package/dist/engine/liveViews.d.ts +3 -0
  40. package/dist/engine/liveViews.js +5 -0
  41. package/dist/engine/motionPreference.d.ts +1 -0
  42. package/dist/engine/motionPreference.js +1 -0
  43. package/dist/engine/passiveScroll.d.ts +10 -0
  44. package/dist/engine/passiveScroll.js +93 -0
  45. package/dist/engine/renderedLines.d.ts +17 -0
  46. package/dist/engine/renderedLines.js +137 -0
  47. package/dist/engine/scrollViewport.d.ts +36 -0
  48. package/dist/engine/scrollViewport.js +104 -0
  49. package/dist/engine/stageMotion.d.ts +7 -0
  50. package/dist/engine/stageMotion.js +319 -0
  51. package/dist/engine/tick.d.ts +13 -0
  52. package/dist/engine/tick.js +246 -0
  53. package/dist/engine/timingLogs.d.ts +7 -0
  54. package/dist/engine/timingLogs.js +81 -0
  55. package/dist/engine/userScroll.d.ts +12 -0
  56. package/dist/engine/userScroll.js +62 -0
  57. package/dist/engine/wavePool.d.ts +8 -0
  58. package/dist/engine/wavePool.js +22 -0
  59. package/dist/engine/wordAnimations.d.ts +9 -0
  60. package/dist/engine/wordAnimations.js +216 -0
  61. package/dist/index.d.ts +3 -2
  62. package/dist/index.js +2 -1
  63. package/dist/inject.js +40 -22
  64. package/dist/renderer.js +8 -2
  65. package/dist/types.d.ts +1 -1
  66. package/dist/view.d.ts +2 -2
  67. package/dist/view.js +7 -3
  68. package/package.json +2 -2
  69. package/dist/engine.d.ts +0 -471
  70. package/dist/engine.js +0 -3133
@@ -0,0 +1,62 @@
1
+ import { USER_SCROLLING_CLASS } from "../constants.js";
2
+ import { dropPendingLineScroll } from "./lineScroll.js";
3
+ import { forEveryLiveView } from "./liveViews.js";
4
+ import { isPassiveDriftScroll } from "./passiveScroll.js";
5
+ const PAUSING_LYRICS_SCROLL_LOG = "Pausing Lyrics Autoscroll Due to User Scroll";
6
+ const USER_SCROLL_RESUME_DELAY_MS = 25000;
7
+ const UNSYNCED_USER_SCROLL_RESUME_DELAY_MS = 5000;
8
+ const ENGINE_SCROLL_EVENT_WINDOW_MS = 2000;
9
+ export function resetScrollResume(engine) {
10
+ engine.scrollResumeTime = 0;
11
+ }
12
+ /**
13
+ * Resume autoscroll immediately for every live view.
14
+ */
15
+ export function resumeAllAutoscroll() {
16
+ forEveryLiveView(resetScrollResume);
17
+ }
18
+ export function noteUserScroll(engine, lyricsAreUnsynced) {
19
+ if (lyricsAreUnsynced) {
20
+ if (isPassiveDriftScroll(engine))
21
+ return;
22
+ }
23
+ else if (engine.skipScrolls > 0) {
24
+ engine.skipScrolls--;
25
+ engine.skipScrollsDecayTimes.shift();
26
+ return;
27
+ }
28
+ dropPendingLineScroll(engine);
29
+ if (engine.host.isLoaderActive())
30
+ return;
31
+ const now = Date.now();
32
+ if (engine.scrollResumeTime < now)
33
+ engine.host.log(PAUSING_LYRICS_SCROLL_LOG);
34
+ engine.scrollResumeTime =
35
+ now + (lyricsAreUnsynced ? UNSYNCED_USER_SCROLL_RESUME_DELAY_MS : USER_SCROLL_RESUME_DELAY_MS);
36
+ engine.wasUserScrolling = true;
37
+ engine.host.setResumeAffordanceVisible(true);
38
+ engine.lyricsContainer?.classList.add(USER_SCROLLING_CLASS);
39
+ }
40
+ export function hasContainerResized(engine, width, height) {
41
+ return width !== engine.lyricWidth || height !== engine.lyricHeight;
42
+ }
43
+ export function writeEngineScrollTop(engine, scroller, scrollTop, now) {
44
+ engine.scrollPos = scrollTop;
45
+ const scrollTopBeforeWrite = scroller.scrollTop;
46
+ scroller.scrollTop = scrollTop;
47
+ if (scroller.scrollTop !== scrollTopBeforeWrite)
48
+ noteEngineScrollEvent(engine, now);
49
+ }
50
+ export function noteEngineScrollEvent(engine, now) {
51
+ engine.skipScrolls += 1;
52
+ engine.skipScrollsDecayTimes.push(now + ENGINE_SCROLL_EVENT_WINDOW_MS);
53
+ }
54
+ export function requestRescroll(engine) {
55
+ engine.wasUserScrolling = true;
56
+ }
57
+ export function decaySkipScrolls(engine, now, keepsReserve) {
58
+ const firstLive = engine.skipScrollsDecayTimes.findIndex(time => time > now);
59
+ const expiredCount = firstLive === -1 ? engine.skipScrollsDecayTimes.length : firstLive;
60
+ engine.skipScrollsDecayTimes = engine.skipScrollsDecayTimes.slice(expiredCount);
61
+ engine.skipScrolls = Math.max(keepsReserve ? 1 : 0, engine.skipScrolls - expiredCount);
62
+ }
@@ -0,0 +1,8 @@
1
+ import type { AnimationEngineInstance } from "./instance.js";
2
+ export declare const waveAnimationPools: WeakMap<Animation, Animation[]>;
3
+ export declare function acquireWaveAnimation(engine: AnimationEngineInstance, letterElement: HTMLElement, keyframes: Keyframe[], keyframeSignature: string, timing: {
4
+ duration: number;
5
+ delay: number;
6
+ endDelay: number;
7
+ fill: FillMode;
8
+ }): Animation;
@@ -0,0 +1,22 @@
1
+ export const waveAnimationPools = new WeakMap();
2
+ const pooledWaveKeyframeSignatures = new WeakMap();
3
+ export function acquireWaveAnimation(engine, letterElement, keyframes, keyframeSignature, timing) {
4
+ const pool = engine.waveAnimationPool;
5
+ const pooled = pool[pool.length - 1];
6
+ const effect = pooled?.effect;
7
+ if (pooled && effect && typeof effect.setKeyframes === "function") {
8
+ pool.pop();
9
+ effect.target = letterElement;
10
+ if (pooledWaveKeyframeSignatures.get(pooled) !== keyframeSignature) {
11
+ effect.setKeyframes(keyframes);
12
+ pooledWaveKeyframeSignatures.set(pooled, keyframeSignature);
13
+ }
14
+ effect.updateTiming(timing);
15
+ pooled.play();
16
+ return pooled;
17
+ }
18
+ const animation = letterElement.animate(keyframes, timing);
19
+ waveAnimationPools.set(animation, pool);
20
+ pooledWaveKeyframeSignatures.set(animation, keyframeSignature);
21
+ return animation;
22
+ }
@@ -0,0 +1,9 @@
1
+ import type { PartData } from "../inject.js";
2
+ import type { AnimationConfig } from "./animationConfig.js";
3
+ import type { AnimationEngineInstance } from "./instance.js";
4
+ export interface HeldPaint {
5
+ target: HTMLElement;
6
+ frame: Keyframe;
7
+ }
8
+ export declare function startWordAnimations(engine: AnimationEngineInstance, part: PartData, config: AnimationConfig, lyricTimeS: number, appliedTimingOffsetMs: number): void;
9
+ export declare function startWordExitAnimation(part: PartData, config: AnimationConfig, heldPaint?: HeldPaint[]): void;
@@ -0,0 +1,216 @@
1
+ import { RTL_CLASS } from "../constants.js";
2
+ import { registerThemeSetting } from "../themeSettings.js";
3
+ import { correctedAnimationTimeMs, mirrorImageHighlightAnimations, followSongClock } from "./animationTiming.js";
4
+ import { fadeInFullySweptKeyframes, fadeOutKeyframes, glowKeyframes, shownFullySweptKeyframes, shownKeyframes, swipeKeyframes, } from "./highlightKeyframes.js";
5
+ import { GECKO_REDRAW, GECKO_REDRAW_KEYFRAMES, GECKO_REDRAW_PERIOD_MS, LETTER_WAVE_CREST_OFFSET, planLetterMaskSweep, planLetterWave, swipeRamp, } from "./letterPlans.js";
6
+ import { resetPartAnimations } from "./lineAnimationState.js";
7
+ import { acquireWaveAnimation } from "./wavePool.js";
8
+ const SWIPE_LEAD_RATIO = registerThemeSetting("blyrics-swipe-lead-ratio", 0.1);
9
+ const SWIPE_DURATION_RATIO = registerThemeSetting("blyrics-swipe-duration-ratio", 1.6);
10
+ const LINE_SYNCED_WORD_CLASS = "blyrics-line-synced-word";
11
+ const INSTANT_MS = 1;
12
+ export function startWordAnimations(engine, part, config, lyricTimeS, appliedTimingOffsetMs) {
13
+ resetPartAnimations(part);
14
+ const word = wordTimeline(engine, part, config, lyricTimeS, appliedTimingOffsetMs);
15
+ const highlight = part.lyricElement.classList.contains(LINE_SYNCED_WORD_CLASS)
16
+ ? lineSyncedHighlight(word)
17
+ : richSyncedHighlight(word);
18
+ const motion = config.enabled.wordWobble ? [...wobble(word), ...letterWave(word)] : [];
19
+ part.animations = [...highlight, ...mirrorImageHighlightAnimations(part, highlight), ...motion];
20
+ }
21
+ export function startWordExitAnimation(part, config, heldPaint = []) {
22
+ resetPartAnimations(part);
23
+ const fades = config.enabled.highlightFade;
24
+ const durationMs = fades ? config.highlight.fadeOutDurationMs : INSTANT_MS;
25
+ const fadeOut = part.highlightElement.animate(fadeOutKeyframes(config, part), {
26
+ duration: durationMs,
27
+ easing: fades ? config.highlight.fadeOutEasing : "linear",
28
+ fill: "none",
29
+ });
30
+ const mirrors = mirrorImageHighlightAnimations(part, [fadeOut]);
31
+ const holds = heldPaint.map(({ target, frame }) => target.animate([frame, frame], { duration: durationMs, fill: "none" }));
32
+ part.animations = [fadeOut, ...mirrors, ...holds];
33
+ fadeOut.addEventListener("finish", () => resetPartAnimations(part), { once: true });
34
+ }
35
+ function wordTimeline(engine, part, config, lyricTimeS, appliedTimingOffsetMs) {
36
+ const durationMs = Math.max(0, part.duration * 1000);
37
+ return {
38
+ engine,
39
+ part,
40
+ config,
41
+ appliedTimingOffsetMs,
42
+ elapsedMs: (lyricTimeS - part.time) * 1000,
43
+ durationMs,
44
+ swipeLeadMs: durationMs * SWIPE_LEAD_RATIO.getNumberValue(),
45
+ swipeDurationMs: durationMs * SWIPE_DURATION_RATIO.getNumberValue(),
46
+ glowDurationMs: Math.max(durationMs * config.highlight.glowDurationRatio, config.highlight.glowMinDurationMs),
47
+ };
48
+ }
49
+ function scheduledTimeMs(word, elapsedMs, durationMs) {
50
+ return correctedAnimationTimeMs(elapsedMs, word.appliedTimingOffsetMs, durationMs);
51
+ }
52
+ function followSong(word, animation, currentTimeMs, { offsetMs = 0, skipDriftSample = false } = {}) {
53
+ const { appliedTimingOffsetMs } = word;
54
+ followSongClock(word.engine, animation, { appliedTimingOffsetMs, offsetMs, skipDriftSample });
55
+ animation.currentTime = currentTimeMs;
56
+ return animation;
57
+ }
58
+ function glowShows(part, config) {
59
+ return config.enabled.highlightGlow && !part.glowSuppressed;
60
+ }
61
+ function richSyncedHighlight(word) {
62
+ const { part, config } = word;
63
+ const animations = config.enabled.highlightSwipe ? swipe(word) : [];
64
+ const shown = config.enabled.highlightSwipe ? shownKeyframes() : shownFullySweptKeyframes(config);
65
+ const show = part.highlightElement.animate(shown, { duration: INSTANT_MS, easing: "linear", fill: "forwards" });
66
+ animations.push(followSong(word, show, scheduledTimeMs(word, word.elapsedMs, INSTANT_MS)));
67
+ if (glowShows(part, config))
68
+ animations.push(glow(word, word.glowDurationMs));
69
+ return animations;
70
+ }
71
+ function lineSyncedHighlight(word) {
72
+ const { part, config } = word;
73
+ const fades = config.enabled.highlightFade;
74
+ const durationMs = fades ? config.highlight.fadeInDurationMs : INSTANT_MS;
75
+ const fadeIn = part.highlightElement.animate(fadeInFullySweptKeyframes(config), {
76
+ duration: durationMs,
77
+ easing: fades ? config.highlight.fadeInEasing : "linear",
78
+ fill: "forwards",
79
+ });
80
+ const animations = [followSong(word, fadeIn, scheduledTimeMs(word, word.elapsedMs, durationMs))];
81
+ if (glowShows(part, config))
82
+ animations.push(glow(word, config.highlight.glowMinDurationMs));
83
+ return animations;
84
+ }
85
+ function swipe(word) {
86
+ const { part, config, swipeLeadMs, swipeDurationMs } = word;
87
+ const currentTimeMs = scheduledTimeMs(word, word.elapsedMs + swipeLeadMs, swipeDurationMs);
88
+ const letters = part.highlightLetterElements;
89
+ if (!letters || letters.length === 0) {
90
+ const gradient = part.highlightElement.animate(swipeKeyframes(config), {
91
+ duration: swipeDurationMs,
92
+ easing: config.highlight.swipeEasing,
93
+ fill: "forwards",
94
+ });
95
+ return [followSong(word, gradient, currentTimeMs, { offsetMs: swipeLeadMs })];
96
+ }
97
+ const rtl = part.highlightElement.classList.contains(RTL_CLASS);
98
+ const sweeps = planLetterMaskSweep(swipeRamp(config), letters.length, swipeDurationMs, rtl);
99
+ const animations = [];
100
+ sweeps.forEach((sweep, index) => {
101
+ const keyframes = sweep.keyframes.map(frame => ({
102
+ offset: frame.offset,
103
+ maskPosition: frame.maskPosition,
104
+ WebkitMaskPosition: frame.maskPosition,
105
+ }));
106
+ const timing = {
107
+ duration: sweep.durationMs,
108
+ delay: sweep.delayMs,
109
+ easing: sweep.easing,
110
+ fill: "both",
111
+ };
112
+ const endsLast = index === sweeps.length - 1;
113
+ const letterSweep = letters[index].animate(keyframes, timing);
114
+ animations.push(followSong(word, letterSweep, currentTimeMs, { offsetMs: swipeLeadMs, skipDriftSample: !endsLast }));
115
+ const glowLetter = part.imageLayers?.glowLetters[index];
116
+ if (glowLetter) {
117
+ animations.push(followSong(word, glowLetter.animate(keyframes, timing), currentTimeMs, {
118
+ offsetMs: swipeLeadMs,
119
+ skipDriftSample: true,
120
+ }));
121
+ }
122
+ });
123
+ return animations;
124
+ }
125
+ function glow(word, durationMs) {
126
+ const { part, config } = word;
127
+ const holdsGlow = Boolean(part.imageLayers) || !config.highlight.glowRestingInvisible;
128
+ const target = part.imageLayers?.glow ?? part.highlightElement;
129
+ const animation = target.animate(glowKeyframes(config, part), {
130
+ duration: durationMs,
131
+ easing: config.highlight.glowEasing,
132
+ fill: holdsGlow ? "forwards" : "none",
133
+ });
134
+ return followSong(word, animation, scheduledTimeMs(word, word.elapsedMs, durationMs));
135
+ }
136
+ function wobble(word) {
137
+ const { wobbleFrom, wobblePeak, wobblePeakOffset, wobblePeakEasing, wobbleSettle, wobbleSettleOffset } = word.config.word;
138
+ const { wobbleTo, wobbleEndEasing, wobbleDurationMs, wobbleEasing } = word.config.word;
139
+ const keyframes = [
140
+ { transform: wobbleFrom },
141
+ { transform: wobblePeak, offset: wobblePeakOffset, easing: wobblePeakEasing },
142
+ { transform: wobbleSettle, offset: Math.max(wobblePeakOffset, wobbleSettleOffset) },
143
+ { transform: wobbleTo, easing: wobbleEndEasing },
144
+ ];
145
+ const timing = { duration: wobbleDurationMs, easing: wobbleEasing, fill: "forwards" };
146
+ const currentTimeMs = scheduledTimeMs(word, word.elapsedMs, wobbleDurationMs);
147
+ return word.part.wobbleElements.map(element => followSong(word, element.animate(keyframes, timing), currentTimeMs));
148
+ }
149
+ function letterWave(word) {
150
+ const { part, config } = word;
151
+ const letterCount = part.letterElements?.length ?? 0;
152
+ if (letterCount === 0)
153
+ return [];
154
+ const run = planLetterWaveRun(word, letterCount);
155
+ const glowLetters = glowShows(part, config) ? part.imageLayers?.glowLetters : undefined;
156
+ const glowFadesOut = Number.parseFloat(config.highlight.imageGlowOpacityTo) === 0;
157
+ const glowEndMs = glowFadesOut ? run.headStartMs + word.glowDurationMs : Infinity;
158
+ const animations = [];
159
+ floatLetters(word, run, part.letterElements, Infinity, true, animations);
160
+ floatLetters(word, run, part.highlightLetterElements, Infinity, false, animations);
161
+ floatLetters(word, run, glowLetters, glowEndMs, false, animations);
162
+ return animations;
163
+ }
164
+ function planLetterWaveRun(word, letterCount) {
165
+ const { config } = word;
166
+ const emphasise = word.part.lyricElement.dataset.longWord === "true";
167
+ const emphasisPeak = emphasise ? ` scale(${config.letterWave.emphasisScale})` : "";
168
+ const emphasisRest = emphasise ? " scale(1)" : "";
169
+ const keyframes = [
170
+ { transform: `translateY(0)${emphasisRest}`, easing: config.letterWave.riseEasing },
171
+ {
172
+ transform: `${config.letterWave.transform}${emphasisPeak}`,
173
+ offset: LETTER_WAVE_CREST_OFFSET,
174
+ easing: config.letterWave.fallEasing,
175
+ },
176
+ { transform: `${config.letterWave.settle}${emphasisRest}` },
177
+ ];
178
+ const waves = planLetterWave(swipeRamp(config), letterCount, word.durationMs, word.swipeDurationMs, word.swipeLeadMs, config.letterWave.durationMs);
179
+ // Carry early starts in the clock offset; negative delays make finished waves appear late to drift sampling.
180
+ const headStartMs = Math.max(0, -Math.min(...waves.map(wave => wave.delayMs)));
181
+ const waveEndsMs = waves.map(wave => wave.delayMs + wave.durationMs);
182
+ const lastWaveEndMs = Math.max(...waveEndsMs);
183
+ return {
184
+ waves,
185
+ keyframes,
186
+ signature: JSON.stringify(keyframes),
187
+ headStartMs,
188
+ lastEndingWaveIndex: waveEndsMs.lastIndexOf(lastWaveEndMs),
189
+ startAtMs: scheduledTimeMs(word, word.elapsedMs + headStartMs, headStartMs + lastWaveEndMs),
190
+ };
191
+ }
192
+ function floatLetters(word, run, letters, endMs, isBaseText, animations) {
193
+ letters?.forEach((letterElement, index) => {
194
+ const wave = run.waves[index];
195
+ const delayMs = wave.delayMs + run.headStartMs;
196
+ if (delayMs >= endMs)
197
+ return;
198
+ const float = acquireWaveAnimation(word.engine, letterElement, run.keyframes, run.signature, {
199
+ duration: wave.durationMs,
200
+ delay: delayMs,
201
+ endDelay: Math.min(0, endMs - delayMs - wave.durationMs),
202
+ fill: "forwards",
203
+ });
204
+ const skipDriftSample = !isBaseText || index !== run.lastEndingWaveIndex;
205
+ animations.push(followSong(word, float, run.startAtMs, { offsetMs: run.headStartMs, skipDriftSample }));
206
+ if (!GECKO_REDRAW || !isBaseText)
207
+ return;
208
+ const redraw = letterElement.animate(GECKO_REDRAW_KEYFRAMES, {
209
+ duration: GECKO_REDRAW_PERIOD_MS,
210
+ iterations: wave.durationMs / GECKO_REDRAW_PERIOD_MS,
211
+ delay: delayMs,
212
+ composite: "add",
213
+ });
214
+ animations.push(followSong(word, redraw, run.startAtMs, { offsetMs: run.headStartMs, skipDriftSample: true }));
215
+ });
216
+ }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- export { resetPlaybackClock, resumeAllAutoscroll } from "./engine.js";
1
+ export { resetPlaybackClock } from "./engine/clock.js";
2
+ export { resumeAllAutoscroll } from "./engine/userScroll.js";
2
3
  export { injectRomanization, injectTranslation, type LineData, removeRomanization, removeTranslation, } from "./inject.js";
3
4
  export { createLyricsRenderer } from "./renderer.js";
4
5
  export type { Lyric, LyricsRenderer, LyricsRendererHost, TickOptions } from "./types.js";
5
6
  /** @public */
6
- export type { AnimationTickStatus } from "./engine.js";
7
+ export type { AnimationTickStatus } from "./engine/tick.js";
7
8
  /** @public */
8
9
  export type { PartData } from "./inject.js";
9
10
  /** @public */
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@
6
6
  // `createLyricsRenderer` is the way in. The four values beside it are what one instance cannot
7
7
  // answer for on its own: the song level operations address every live view at once, and the
8
8
  // injection helpers decorate lines that are already built.
9
- export { resetPlaybackClock, resumeAllAutoscroll } from "./engine.js";
9
+ export { resetPlaybackClock } from "./engine/clock.js";
10
+ export { resumeAllAutoscroll } from "./engine/userScroll.js";
10
11
  export { injectRomanization, injectTranslation, removeRomanization, removeTranslation, } from "./inject.js";
11
12
  export { createLyricsRenderer } from "./renderer.js";
package/dist/inject.js CHANGED
@@ -11,7 +11,7 @@
11
11
  // animates is one word, so every part is split on whitespace with its timing pro-rated across the
12
12
  // split by character count. A line that arrives with no timed parts at all is rebuilt the same way
13
13
  // into zero duration words, so line synced lyrics reach the DOM the sweep already knows.
14
- import { releasePart } from "./engine.js";
14
+ import { releasePart } from "./engine/lineAnimationState.js";
15
15
  import { alignImageGlowRun, wrapImageHighlight } from "./imageHighlights.js";
16
16
  import { normalizeLanguage } from "./language.js";
17
17
  import { BACKGROUND_LINE_CLASS, BACKGROUND_LYRIC_CLASS, BIDI_RUN_CLASS, BIDI_SENSITIVE_CLASS, CONTENT_LINE_CLASS, EXPLICIT_WORD_CLASS, HIGHLIGHT_RUN_CLASS, LETTER_CLASS, LINE_MAIN_CLASS, LINE_SYNCED_WORD_CLASS, LONG_WORD_GROUP_CLASS, ROMANIZED_LYRICS_CLASS, RTL_CLASS, TRANSLATED_LYRICS_CLASS, WORD_CLASS, WORD_GROUP_CLASS, WORD_HIGHLIGHT_CLASS, WORD_HIGHLIGHT_LETTERED_CLASS, WORD_STATE_ATTR, WORD_STATE_UPCOMING, ZERO_DURATION_ANIMATION_CLASS, } from "./constants.js";
@@ -140,6 +140,7 @@ function splitPartIntoTokens(part) {
140
140
  part: {
141
141
  words: chunk,
142
142
  isBackground: part.isBackground,
143
+ backgroundGroup: part.backgroundGroup,
143
144
  explicit: part.explicit,
144
145
  },
145
146
  });
@@ -166,7 +167,7 @@ function splitPartIntoTokens(part) {
166
167
  function normalizeParts(parts) {
167
168
  return parts.flatMap(splitPartIntoTokens);
168
169
  }
169
- function groupTokensByWord(tokens) {
170
+ function groupTokensByWord(tokens, splitBackgroundGroups) {
170
171
  const groups = [];
171
172
  let current = null;
172
173
  const flush = () => {
@@ -182,9 +183,10 @@ function groupTokensByWord(tokens) {
182
183
  continue;
183
184
  }
184
185
  const isBackground = token.part?.isBackground === true;
185
- if (!current || current.isBackground !== isBackground) {
186
+ const backgroundGroup = splitBackgroundGroups ? token.part?.backgroundGroup : undefined;
187
+ if (!current || current.isBackground !== isBackground || current.backgroundGroup !== backgroundGroup) {
186
188
  flush();
187
- current = { text: "", isBackground, tokens: [] };
189
+ current = { text: "", isBackground, backgroundGroup, tokens: [] };
188
190
  }
189
191
  current.text += token.text;
190
192
  current.tokens.push(token);
@@ -331,24 +333,36 @@ export function createLyricsLine(doc, parts, line, lyricElement, options = { spl
331
333
  .map(part => part.words)
332
334
  .join("")
333
335
  : lineText;
334
- const backgroundText = parts
335
- .filter(part => part.isBackground === true)
336
+ const backgroundTextOf = (group) => parts
337
+ .filter(part => part.isBackground === true && (part.backgroundGroup ?? 0) === group)
336
338
  .map(part => part.words)
337
339
  .join("");
338
340
  const main = createContentLine(doc, LINE_MAIN_CLASS, mainText);
339
341
  const mainRun = createBidiRun(doc, mainText);
340
342
  const mainHighlightRun = createHighlightRun(doc, mainText);
341
- const groupedTokens = groupTokensByWord(normalizeParts(parts));
342
- const backgroundLine = createContentLine(doc, BACKGROUND_LINE_CLASS, backgroundText);
343
- const backgroundRun = createBidiRun(doc, backgroundText);
344
- const backgroundHighlightRun = createHighlightRun(doc, backgroundText);
345
- let hasBackground = false;
343
+ const groupedTokens = groupTokensByWord(normalizeParts(parts), options.splitBackgroundLine);
344
+ const backgroundRows = new Map();
345
+ const backgroundRowOf = (group) => {
346
+ let row = backgroundRows.get(group);
347
+ if (!row) {
348
+ const text = backgroundTextOf(group);
349
+ row = {
350
+ line: createContentLine(doc, BACKGROUND_LINE_CLASS, text),
351
+ run: createBidiRun(doc, text),
352
+ highlightRun: createHighlightRun(doc, text),
353
+ used: false,
354
+ };
355
+ row.line.appendChild(row.highlightRun);
356
+ row.line.appendChild(row.run);
357
+ backgroundRows.set(group, row);
358
+ }
359
+ return row;
360
+ };
361
+ backgroundRowOf(0);
346
362
  let pendingForegroundSpace = "";
347
363
  let pendingBackgroundSpace = "";
348
364
  main.appendChild(mainHighlightRun);
349
365
  main.appendChild(mainRun);
350
- backgroundLine.appendChild(backgroundHighlightRun);
351
- backgroundLine.appendChild(backgroundRun);
352
366
  for (const item of groupedTokens) {
353
367
  if ("kind" in item) {
354
368
  // Is a RenderToken, not a WordGroup, only whitespace should enter this path
@@ -357,8 +371,9 @@ export function createLyricsLine(doc, parts, line, lyricElement, options = { spl
357
371
  }
358
372
  else {
359
373
  const shouldUseBackgroundLine = options.splitBackgroundLine && item.isBackground;
360
- const target = shouldUseBackgroundLine ? backgroundRun : mainRun;
361
- const highlightRun = shouldUseBackgroundLine ? backgroundHighlightRun : mainHighlightRun;
374
+ const backgroundRow = shouldUseBackgroundLine ? backgroundRowOf(item.backgroundGroup ?? 0) : null;
375
+ const target = backgroundRow ? backgroundRow.run : mainRun;
376
+ const highlightRun = backgroundRow ? backgroundRow.highlightRun : mainHighlightRun;
362
377
  const pendingSpace = shouldUseBackgroundLine ? pendingBackgroundSpace : pendingForegroundSpace;
363
378
  if (target.childNodes.length > 0 && pendingSpace.length > 0) {
364
379
  target.appendChild(createSpaceNode(doc, pendingSpace, shouldUseBackgroundLine));
@@ -367,8 +382,8 @@ export function createLyricsLine(doc, parts, line, lyricElement, options = { spl
367
382
  const { lyricGroup, highlightGroup } = createWordGroup(doc, item, line);
368
383
  target.appendChild(lyricGroup);
369
384
  highlightRun.appendChild(highlightGroup);
370
- if (shouldUseBackgroundLine) {
371
- hasBackground = true;
385
+ if (backgroundRow) {
386
+ backgroundRow.used = true;
372
387
  pendingBackgroundSpace = "";
373
388
  }
374
389
  else {
@@ -376,13 +391,16 @@ export function createLyricsLine(doc, parts, line, lyricElement, options = { spl
376
391
  }
377
392
  }
378
393
  }
394
+ const usedBackgroundRows = [...backgroundRows]
395
+ .filter(([, row]) => row.used)
396
+ .sort(([a], [b]) => a - b)
397
+ .map(([, row]) => row);
379
398
  alignImageGlowRun(mainHighlightRun, line.parts);
380
- if (hasBackground)
381
- alignImageGlowRun(backgroundHighlightRun, line.parts);
399
+ for (const row of usedBackgroundRows)
400
+ alignImageGlowRun(row.highlightRun, line.parts);
382
401
  lyricElement.appendChild(main);
383
- if (hasBackground) {
384
- lyricElement.appendChild(backgroundLine);
385
- }
402
+ for (const row of usedBackgroundRows)
403
+ lyricElement.appendChild(row.line);
386
404
  return main;
387
405
  }
388
406
  export function buildLineSyncedParts(item) {
package/dist/renderer.js CHANGED
@@ -11,7 +11,13 @@
11
11
  // diagnostic overlay supplies the sink, and one that says nothing draws nothing.
12
12
  import { imageHighlights, refreshInstrumentalImages } from "./imageHighlights.js";
13
13
  import { CUSTOM_THEME_STYLE_ID } from "./constants.js";
14
- import { clearLyrics, clearOnScreenLyrics as clearEngineOnScreenLyrics, clearStyleCaches as clearEngineStyleCaches, createAnimationEngineInstance, getRenderedLines, getRenderedSyncType, hasUnsyncedLyrics, noteContainerResize, noteUserScroll as noteEngineUserScroll, noteVisibilityChange as noteEngineVisibilityChange, relayout, resetScrollResume, resolveTickOptions, settleSwappedLines, retickFromPlaybackClock as retickEngineFromPlaybackClock, scheduleLyricPositionUpdate as scheduleEngineLyricPositionUpdate, tickView, } from "./engine.js";
14
+ import { clearLyrics, clearOnScreenLyrics as clearEngineOnScreenLyrics, getRenderedLines, getRenderedSyncType, settleSwappedLines, } from "./engine/renderedLines.js";
15
+ import { clearStyleCaches as clearEngineStyleCaches } from "./engine/cssValues.js";
16
+ import { createAnimationEngineInstance } from "./engine/instance.js";
17
+ import { hasUnsyncedLyrics } from "./engine/passiveScroll.js";
18
+ import { hasContainerResized, noteUserScroll as noteEngineUserScroll, resetScrollResume } from "./engine/userScroll.js";
19
+ import { noteVisibilityChange as noteEngineVisibilityChange } from "./engine/timingLogs.js";
20
+ import { relayout, resolveTickOptions, retickFromPlaybackClock as retickEngineFromPlaybackClock, scheduleLyricPositionUpdate as scheduleEngineLyricPositionUpdate, tickView, } from "./engine/tick.js";
15
21
  import { parseThemeConfig, setThemeSettings } from "./themeSettings.js";
16
22
  import { applyLyricLanguage, normalizeLanguage, resolveLyricLanguages } from "./language.js";
17
23
  import { setLyrics as buildLyricsView, swapLyrics as swapLyricsView } from "./view.js";
@@ -199,7 +205,7 @@ export function createLyricsRenderer(rendererOptions) {
199
205
  const target = entries[entries.length - 1]?.target;
200
206
  if (!target)
201
207
  return;
202
- if (noteContainerResize(engine, target.clientWidth, target.clientHeight))
208
+ if (hasContainerResized(engine, target.clientWidth, target.clientHeight))
203
209
  measure();
204
210
  });
205
211
  observer.observe(container);
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Lyric, LyricPart, LyricSyncType } from "@braccato/types";
2
- import type { AnimationTickStatus } from "./engine.js";
2
+ import type { AnimationTickStatus } from "./engine/tick.js";
3
3
  import type { LineData } from "./inject.js";
4
4
  import type { StageBox } from "./stage.js";
5
5
  import type { SetLyricsOptions } from "./view.js";
package/dist/view.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type AnimationEngineInstance } from "./engine.js";
1
+ import { type AnimationEngineInstance } from "./engine/instance.js";
2
2
  import { type LineData } from "./inject.js";
3
3
  import type { Lyric } from "./types.js";
4
4
  export interface SetLyricsOptions {
@@ -38,7 +38,7 @@ export declare function setLyrics(engine: AnimationEngineInstance, mount: HTMLEl
38
38
  export type SwapPositions = Map<LineData, {
39
39
  position: number;
40
40
  height: number;
41
- offset: number;
41
+ scrollAnimationOffset: number;
42
42
  }>;
43
43
  /**
44
44
  * Swaps these lyrics into the view already on screen, rebuilding only the lines that differ, and
package/dist/view.js CHANGED
@@ -13,7 +13,10 @@
13
13
  // lines is where those values are first knowable: the container, the records, the sync type, the
14
14
  // size they were measured at, and the scrolls to swallow before the view has settled.
15
15
  import { CREDITS_CLASS, CREDITS_NAMES_CLASS, CREDITS_TEXT_CLASS, LINE_CLASS, LYRICS_CLASS, RTL_CLASS, } from "./constants.js";
16
- import { lineScrollOffset, playerTimeForLyricTime, replaceRenderedLines, setupLineCullObserver, } from "./engine.js";
16
+ import {} from "./engine/instance.js";
17
+ import { lineScrollOffset, replaceRenderedLines } from "./engine/renderedLines.js";
18
+ import { playerTimeForLyricTime } from "./engine/clock.js";
19
+ import { setupLineCullObserver } from "./engine/culling.js";
17
20
  import { addSeekHandler, applyDirection, buildLineSyncedParts, createLyricsLine, deriveSyncType, disableRichsync, findNearestAgent, hideCredits, isNearestLyricRtl, moveDecorations, newLineData, } from "./inject.js";
18
21
  import { refreshInstrumentalImages } from "./imageHighlights.js";
19
22
  import { createInstrumentalElement } from "./instrumental.js";
@@ -114,6 +117,7 @@ function lineSignature(lyrics, lineIndex) {
114
117
  part.durationMs,
115
118
  part.words,
116
119
  part.isBackground === true,
120
+ part.backgroundGroup ?? null,
117
121
  part.explicit === true,
118
122
  ]);
119
123
  // An instrumental line takes its side and direction from the lines around it.
@@ -350,7 +354,7 @@ export function swapLyrics(engine, mount, lyrics, options) {
350
354
  line.lyricElement.dataset.lineNumber = String(lineIndex);
351
355
  applyLyricLanguage(line.lyricElement, context.languages[lineIndex]);
352
356
  lines.push(line);
353
- positions.set(line, { position: line.position, height: line.height, offset: 0 });
357
+ positions.set(line, { position: line.position, height: line.height, scrollAnimationOffset: 0 });
354
358
  continue;
355
359
  }
356
360
  if (unmatchedOld.length === 0) {
@@ -365,7 +369,7 @@ export function swapLyrics(engine, mount, lyrics, options) {
365
369
  position: standsFor.position,
366
370
  height: standsFor.height,
367
371
  // A kept line finishes its own line scroll; this one starts where the line it replaced was.
368
- offset: lineScrollOffset(engine, standsFor.lyricElement),
372
+ scrollAnimationOffset: lineScrollOffset(engine, standsFor.lyricElement),
369
373
  });
370
374
  if (decorationKeys.get(standsFor) === decorationKeys.get(line))
371
375
  moveDecorations(standsFor, line);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braccato/core",
3
- "version": "1.19.1",
3
+ "version": "1.20.1",
4
4
  "description": "Synchronized lyrics renderer with word-by-word animations",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -57,7 +57,7 @@
57
57
  "access": "public"
58
58
  },
59
59
  "dependencies": {
60
- "@braccato/types": "^1.0.0"
60
+ "@braccato/types": "^1.1.0"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsx ../../tooling/build-package.ts",