@braccato/core 1.21.4 → 1.21.6

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.
@@ -38,7 +38,6 @@ export declare const SWEEP_CLONE_CLASS: "blyrics-sweep-clone";
38
38
  export declare const SWEEP_TARGET_CLASS: "blyrics-sweep-target";
39
39
  export declare const SWEEP_MASK_CLASS: "blyrics-sweep-mask";
40
40
  export declare const SWEEP_TEXT_CLASS: "blyrics-sweep-text";
41
- export declare const SWEEP_GLOW_CLASS: "blyrics-sweep-glow";
42
41
  export declare const HIGHLIGHT_RUN_CLASS: "blyrics-highlight-run";
43
42
  export declare const LINE_SYNCED_WORD_CLASS: "blyrics-line-synced-word";
44
43
  export declare const BIDI_RUN_CLASS: "blyrics-bidi-run";
package/dist/constants.js CHANGED
@@ -43,7 +43,6 @@ export const SWEEP_CLONE_CLASS = "blyrics-sweep-clone";
43
43
  export const SWEEP_TARGET_CLASS = "blyrics-sweep-target";
44
44
  export const SWEEP_MASK_CLASS = "blyrics-sweep-mask";
45
45
  export const SWEEP_TEXT_CLASS = "blyrics-sweep-text";
46
- export const SWEEP_GLOW_CLASS = "blyrics-sweep-glow";
47
46
  export const HIGHLIGHT_RUN_CLASS = "blyrics-highlight-run";
48
47
  export const LINE_SYNCED_WORD_CLASS = "blyrics-line-synced-word";
49
48
  export const BIDI_RUN_CLASS = "blyrics-bidi-run";
@@ -28,6 +28,7 @@ export interface AnimationConfig {
28
28
  swipeEndFrom: string;
29
29
  swipeStartTo: string;
30
30
  swipeEndTo: string;
31
+ glowFrom: string;
31
32
  glowTo: string;
32
33
  glowDurationRatio: number;
33
34
  glowMinDurationMs: number;
@@ -14,6 +14,7 @@ export function getAnimationSettings(engine, lyricsElement) {
14
14
  }
15
15
  function readAnimationConfig(engine, lyricsElement) {
16
16
  const css = createThemeReader(engine, lyricsElement);
17
+ const glowFrom = resolveGlowFilter(engine, lyricsElement, "from", "0.8rem");
17
18
  const glowTo = resolveGlowFilter(engine, lyricsElement, "to", "0");
18
19
  return {
19
20
  enabled: {
@@ -44,6 +45,7 @@ function readAnimationConfig(engine, lyricsElement) {
44
45
  swipeEndFrom: css.string("--blyrics-highlight-swipe-end-from", "-0.1"),
45
46
  swipeStartTo: css.string("--blyrics-highlight-swipe-start-to", "1.4"),
46
47
  swipeEndTo: css.string("--blyrics-highlight-swipe-end-to", "1.5"),
48
+ glowFrom,
47
49
  glowTo,
48
50
  glowDurationRatio: css.number("--blyrics-highlight-glow-duration-ratio", 1.2),
49
51
  glowMinDurationMs: css.durationMs("--blyrics-highlight-glow-min-duration", "1.2s"),
@@ -14,6 +14,7 @@ export interface DriftSample {
14
14
  offsetMs: number;
15
15
  playState: AnimationPlayState;
16
16
  }
17
+ export declare function seekAnimation(engine: AnimationEngineInstance, animation: Animation, timeMs: number): void;
17
18
  export declare function followSongClock(engine: AnimationEngineInstance, animation: Animation, track: Omit<SongClockTrack, "appliedTimingOffsetMs"> & {
18
19
  appliedTimingOffsetMs?: number;
19
20
  }): Animation;
@@ -1,5 +1,27 @@
1
1
  import { positiveModulo, toMs } from "../util.js";
2
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
+ }
3
25
  export function followSongClock(engine, animation, track) {
4
26
  songClockTracks.set(animation, {
5
27
  ...track,
@@ -20,7 +42,10 @@ export function mirrorHighlightAnimations(part, animations) {
20
42
  continue;
21
43
  const mirror = target.animate(effect.getKeyframes(), effect.getTiming());
22
44
  mirror.playbackRate = animation.playbackRate;
23
- mirror.currentTime = animation.currentTime;
45
+ if (animation.playState === "running" && animation.startTime !== null)
46
+ mirror.startTime = animation.startTime;
47
+ else
48
+ mirror.currentTime = animation.currentTime;
24
49
  const track = songClockTracks.get(animation);
25
50
  if (track)
26
51
  songClockTracks.set(mirror, { ...track, skipDriftSample: true });
@@ -69,7 +94,7 @@ function driftSample(part, animation, lyricTimeS) {
69
94
  const track = songClockTracks.get(animation);
70
95
  if (!track || track.skipDriftSample || animation.playState === "idle")
71
96
  return null;
72
- const rawActualTimeMs = timingValueToMs(animation.currentTime);
97
+ const rawActualTimeMs = liveCurrentTimeMs(animation);
73
98
  if (rawActualTimeMs === null)
74
99
  return null;
75
100
  const expectedTimeMs = normalizedTimeMs(animation, (lyricTimeS - part.time) * 1000 + track.offsetMs, track);
@@ -1,16 +1,6 @@
1
1
  import type { AnimationEngineInstance } from "./instance.js";
2
2
  import { type LineScrollItem } from "./lineScroll.js";
3
- export interface LineCulling {
4
- scroller: HTMLElement;
5
- contentOffset: number;
6
- followReaderScroll: () => void;
7
- startObserver: IntersectionObserver | null;
8
- ready: boolean;
9
- }
10
- export declare function setupLineCulling(engine: AnimationEngineInstance): void;
11
- export declare function stopLineCulling(engine: AnimationEngineInstance): void;
12
- export declare function updateLineCulling(engine: AnimationEngineInstance, fromScrollTop: number, toScrollTop: number, viewportHeight: number): void;
13
- export declare function measureContentOffset(scroller: HTMLElement, container: HTMLElement): number;
3
+ export declare function setupLineCullObserver(engine: AnimationEngineInstance): void;
14
4
  export declare function clearOffscreenLineCulling(engine: AnimationEngineInstance): void;
15
5
  export declare function updateVisibleLyricWillChange(engine: AnimationEngineInstance, lines: LineScrollItem[], fromScrollTop: number, toScrollTop: number, viewportHeight: number): void;
16
6
  export declare function clearVisibleLyricWillChange(engine: AnimationEngineInstance): void;
@@ -1,106 +1,41 @@
1
1
  import { hasUnplacedContextSweeps } from "./contextSweep.js";
2
2
  import { resetLineAnimationState } from "./lineAnimationState.js";
3
3
  import { isLineVisibleDuringScroll, LINE_SCROLL_WILL_CHANGE_VALUE } from "./lineScroll.js";
4
- // A skipped line keeps the height it last rendered at, so none is skipped before two rendering updates
5
- // have laid every line out. An intersection observation is delivered as its own task after one has, so starting
6
- // from it never adds a resize observation to a rendering update that is already delivering them.
7
- const RENDERING_UPDATES_BEFORE_SKIPPING = 2;
8
- export function setupLineCulling(engine) {
9
- stopLineCulling(engine);
10
- const container = engine.lyricsContainer;
11
- if (engine.layout === "stage" || !container || engine.lines.length === 0)
12
- return;
13
- const scroller = engine.host.getScrollElement();
14
- if (!scroller?.isConnected)
4
+ // Use screen intersections because transformed scrolling decouples layout coordinates from visibility.
5
+ const ONE_VIEWPORT_OVERSCAN = "100% 0px 100% 0px";
6
+ export function setupLineCullObserver(engine) {
7
+ engine.lineCullObserver?.disconnect();
8
+ engine.lineCullObserver = null;
9
+ clearOffscreenLineCulling(engine);
10
+ const Observer = engine.window.IntersectionObserver;
11
+ if (engine.layout === "stage" || typeof Observer !== "function" || engine.lines.length === 0)
15
12
  return;
16
13
  // The engine owns scrollTop; Firefox's scroll anchoring would answer cull height shifts with a scroll the
17
14
  // engine reads as the user's.
18
- scroller.style.setProperty("overflow-anchor", "none");
15
+ engine.host.getScrollElement()?.style.setProperty("overflow-anchor", "none");
19
16
  pinCulledLineHeights(engine);
20
- const culling = {
21
- scroller,
22
- contentOffset: measureContentOffset(scroller, container),
23
- followReaderScroll: () => cullAroundScroller(engine, culling),
24
- startObserver: null,
25
- ready: false,
26
- };
27
- engine.lineCulling = culling;
28
- scroller.addEventListener("scroll", culling.followReaderScroll, { passive: true });
29
- startCullingAfterRenderingUpdates(engine, culling, container, RENDERING_UPDATES_BEFORE_SKIPPING);
30
- for (const line of engine.lines) {
31
- if (!engine.culledLineElements.has(line.lyricElement))
32
- restartUnplacedLine(line);
33
- }
34
- }
35
- export function stopLineCulling(engine) {
36
- const culling = engine.lineCulling;
37
- if (culling) {
38
- culling.scroller.removeEventListener("scroll", culling.followReaderScroll);
39
- culling.startObserver?.disconnect();
40
- }
41
- engine.lineCulling = null;
42
- clearOffscreenLineCulling(engine);
43
- }
44
- function cullAroundScroller(engine, culling) {
45
- if (!culling.scroller.isConnected)
46
- return;
47
- const scrollTop = culling.scroller.scrollTop;
48
- const viewportHeight = engine.cachedTabRendererHeight ?? culling.scroller.clientHeight;
49
- updateLineCulling(engine, scrollTop, engine.pendingLineScroll?.toScrollTop ?? scrollTop, viewportHeight);
50
- }
51
- // A line scroll's transforms stay between the two scroll positions; one viewport either side is the margin.
52
- export function updateLineCulling(engine, fromScrollTop, toScrollTop, viewportHeight) {
53
- const culling = engine.lineCulling;
54
- if (!culling?.ready)
55
- return;
56
- const top = Math.min(fromScrollTop, toScrollTop) - viewportHeight - culling.contentOffset;
57
- const bottom = Math.max(fromScrollTop, toScrollTop) + 2 * viewportHeight - culling.contentOffset;
58
- for (const line of engine.lines) {
59
- const element = line.lyricElement;
60
- const rendered = !isMeasured(line) || (line.position + line.height >= top && line.position <= bottom);
61
- if (rendered) {
62
- if (!engine.culledLineElements.delete(element))
63
- continue;
64
- uncullLine(element);
65
- restartUnplacedLine(line);
66
- }
67
- else if (!engine.culledLineElements.has(element)) {
68
- cullLine(element);
69
- engine.culledLineElements.add(element);
70
- }
71
- }
72
- }
73
- function startCullingAfterRenderingUpdates(engine, culling, container, updates) {
74
- const Observer = engine.window.IntersectionObserver;
75
- if (typeof Observer !== "function")
76
- return;
77
- const observer = new Observer(() => {
78
- observer.disconnect();
79
- culling.startObserver = null;
80
- if (engine.lineCulling !== culling)
81
- return;
82
- if (updates > 1) {
83
- startCullingAfterRenderingUpdates(engine, culling, container, updates - 1);
84
- return;
17
+ const observer = new Observer(entries => {
18
+ for (const entry of entries) {
19
+ const element = entry.target;
20
+ if (entry.isIntersecting) {
21
+ if (engine.culledLineElements.delete(element))
22
+ uncullLine(element);
23
+ restartUnplacedLine(engine, element);
24
+ }
25
+ else if (!engine.culledLineElements.has(element)) {
26
+ cullLine(element);
27
+ engine.culledLineElements.add(element);
28
+ }
85
29
  }
86
- culling.ready = true;
87
- cullAroundScroller(engine, culling);
88
- });
89
- culling.startObserver = observer;
90
- observer.observe(container);
91
- }
92
- function isMeasured(line) {
93
- return line.position >= 0 && line.height >= 0;
94
- }
95
- // The document's scrolling element moves with the page, so its content starts at the viewport's top edge.
96
- export function measureContentOffset(scroller, container) {
97
- const scrollsDocument = scroller === scroller.ownerDocument?.scrollingElement;
98
- const scrollerTop = scrollsDocument ? 0 : scroller.getBoundingClientRect().y + scroller.clientTop;
99
- return container.getBoundingClientRect().y - scrollerTop + scroller.scrollTop;
30
+ }, { root: null, rootMargin: ONE_VIEWPORT_OVERSCAN, threshold: 0 });
31
+ for (const line of engine.lines)
32
+ observer.observe(line.lyricElement);
33
+ engine.lineCullObserver = observer;
100
34
  }
101
35
  /** A line that started while it was skipped starts over now that its words have boxes to place on. */
102
- function restartUnplacedLine(line) {
103
- if (hasUnplacedContextSweeps(line))
36
+ function restartUnplacedLine(engine, element) {
37
+ const line = engine.lines.find(candidate => candidate.lyricElement === element);
38
+ if (line && hasUnplacedContextSweeps(line))
104
39
  resetLineAnimationState(line);
105
40
  }
106
41
  export function clearOffscreenLineCulling(engine) {
@@ -6,7 +6,6 @@ import type { ElementMotion } from "./elementMotion.js";
6
6
  import type { LineScrollItem, PendingLineScroll, RunningLineScroll } from "./lineScroll.js";
7
7
  import type { LineScrollTiming } from "./lineScrollStyle.js";
8
8
  import type { AnimationSettings } from "./animationConfig.js";
9
- import { type LineCulling } from "./culling.js";
10
9
  /**
11
10
  * Everything that belongs to a single rendered lyrics view: one scroll container, one selection,
12
11
  * one set of pending scroll work.
@@ -66,7 +65,7 @@ export interface AnimationEngineInstance extends AnimEngineViewState {
66
65
  visibleWillChangeElements: Set<HTMLElement>;
67
66
  culledLineElements: Set<HTMLElement>;
68
67
  waveAnimationPool: Animation[];
69
- lineCulling: LineCulling | null;
68
+ lineCullObserver: IntersectionObserver | null;
70
69
  cachedDurations: Map<string, number>;
71
70
  cachedCSSValues: Map<string, string>;
72
71
  cachedAnimationSettings: AnimationSettings | null;
@@ -1,7 +1,6 @@
1
1
  import { NO_SCROLL_INSETS } from "./scrollViewport.js";
2
2
  import { REDUCED_MOTION_QUERY } from "./motionPreference.js";
3
3
  import { clearStyleCaches } from "./cssValues.js";
4
- import { stopLineCulling } from "./culling.js";
5
4
  import { liveEngines } from "./liveViews.js";
6
5
  import { stopPassiveScrollLoop } from "./passiveScroll.js";
7
6
  import { cancelLyricPositionUpdate } from "./tick.js";
@@ -50,7 +49,7 @@ export function createAnimationEngineInstance(engineDocument, engineWindow, host
50
49
  visibleWillChangeElements: new Set(),
51
50
  culledLineElements: new Set(),
52
51
  waveAnimationPool: [],
53
- lineCulling: null,
52
+ lineCullObserver: null,
54
53
  cachedDurations: new Map(),
55
54
  cachedCSSValues: new Map(),
56
55
  cachedAnimationSettings: null,
@@ -78,7 +77,8 @@ export function createAnimationEngineInstance(engineDocument, engineWindow, host
78
77
  engine.tabRendererResizeObserver?.disconnect();
79
78
  engine.tabRendererResizeObserver = null;
80
79
  engine.observedTabRenderer = null;
81
- stopLineCulling(engine);
80
+ engine.lineCullObserver?.disconnect();
81
+ engine.lineCullObserver = null;
82
82
  stopPassiveScrollLoop(engine);
83
83
  cancelLyricPositionUpdate(engine);
84
84
  },
@@ -1,5 +1,5 @@
1
1
  import { INSTRUMENTAL_WAVE_PATH_HIGH, INSTRUMENTAL_WAVE_PATH_LOW } from "../instrumental.js";
2
- import { correctedAnimationTimeMs, correctedWrappedAnimationTimeMs, followSongClock } from "./animationTiming.js";
2
+ import { correctedAnimationTimeMs, correctedWrappedAnimationTimeMs, followSongClock, seekAnimation, } from "./animationTiming.js";
3
3
  const FILL_SELECTOR = ".blyrics--instrumental-fill";
4
4
  const WAVE_CLIP_SELECTOR = ".blyrics--wave-clip";
5
5
  const WAVE_PATH_SELECTOR = ".blyrics--wave-path";
@@ -15,7 +15,7 @@ export function startInstrumentalAnimations(engine, line, config, lyricTimeS, ap
15
15
  if (!animation)
16
16
  return;
17
17
  followSongClock(engine, animation, { appliedTimingOffsetMs, offsetMs: 0, wrapDurationMs });
18
- animation.currentTime = currentTimeMs;
18
+ seekAnimation(engine, animation, currentTimeMs);
19
19
  };
20
20
  const scheduled = (durationMs) => correctedAnimationTimeMs(elapsedMs, appliedTimingOffsetMs, durationMs);
21
21
  const fillFadeMs = enabled ? instrumental.fillFadeDurationMs : INSTANT_MS;
@@ -1,4 +1,4 @@
1
- import { correctedAnimationTimeMs, followSongClock } from "./animationTiming.js";
1
+ import { correctedAnimationTimeMs, followSongClock, seekAnimation } from "./animationTiming.js";
2
2
  import { placeContextSweeps } from "./contextSweep.js";
3
3
  import { suppressInvisibleWordGlows } from "./glow.js";
4
4
  import { startInstrumentalAnimations, startInstrumentalExitAnimations } from "./instrumentalAnimations.js";
@@ -45,7 +45,7 @@ function startLineEntrance(engine, line, config, lyricTimeS, appliedTimingOffset
45
45
  });
46
46
  followSongClock(engine, entrance, { appliedTimingOffsetMs, offsetMs: 0 });
47
47
  const elapsedMs = (lyricTimeS - line.time) * 1000;
48
- entrance.currentTime = correctedAnimationTimeMs(elapsedMs, appliedTimingOffsetMs, durationMs);
48
+ seekAnimation(engine, entrance, correctedAnimationTimeMs(elapsedMs, appliedTimingOffsetMs, durationMs));
49
49
  line.animations = [entrance];
50
50
  }
51
51
  function startLineExit(line, config) {
@@ -1,5 +1,5 @@
1
1
  import { ANIMATING_CLASS, CURRENT_LYRICS_CLASS } from "../constants.js";
2
- import { clearVisibleLyricWillChange, stopLineCulling } from "./culling.js";
2
+ import { clearOffscreenLineCulling, clearVisibleLyricWillChange } from "./culling.js";
3
3
  import { DECORATION_MIN_SHIFT_PX, decorationSlideAllowed, slideElementBy } from "./decorationSlides.js";
4
4
  import { stopAllElementMotion, stopElementMotion } from "./elementMotion.js";
5
5
  import { resetLineAnimationState, togglePartClass } from "./lineAnimationState.js";
@@ -28,7 +28,9 @@ export function clearLyrics(engine) {
28
28
  dropPendingLineScroll(engine);
29
29
  stopAllElementMotion(engine);
30
30
  clearVisibleLyricWillChange(engine);
31
- stopLineCulling(engine);
31
+ engine.lineCullObserver?.disconnect();
32
+ engine.lineCullObserver = null;
33
+ clearOffscreenLineCulling(engine);
32
34
  for (const line of engine.lines) {
33
35
  resetLineAnimationState(line);
34
36
  line.isSelected = false;
@@ -5,7 +5,7 @@ import { applyPlaybackRateToRunningAnimations, correctedScrollTimeS } from "./an
5
5
  import { followFocusedLines, lastSungLine } from "./autoScroll.js";
6
6
  import { advancePlaybackClock, lyricClockShiftS, NO_PLAYER_SNAPSHOT, playbackClock } from "./clock.js";
7
7
  import { getCSSDurationInMs } from "./cssValues.js";
8
- import { clearOffscreenLineCulling, clearVisibleLyricWillChange, setupLineCulling, updateLineCulling, updateVisibleLyricWillChange, } from "./culling.js";
8
+ import { clearOffscreenLineCulling, clearVisibleLyricWillChange, setupLineCullObserver, updateVisibleLyricWillChange, } from "./culling.js";
9
9
  import { captureDecorationSlide, lineDecorators } from "./decorationSlides.js";
10
10
  import { resetLineAnimationState } from "./lineAnimationState.js";
11
11
  import { driveLineAnimations } from "./lineLifecycle.js";
@@ -101,15 +101,9 @@ function renderSyncedLyrics(engine, lyricsElement, playhead, options, now) {
101
101
  clearVisibleLyricWillChange(engine);
102
102
  return;
103
103
  }
104
- if (scroller) {
104
+ if (scroller && config.enabled.scroll) {
105
105
  const pendingScrollTop = engine.pendingLineScroll?.toScrollTop ?? scroller.scrollTop;
106
- updateLineCulling(engine, scroller.scrollTop, pendingScrollTop, scroller.height);
107
- if (config.enabled.scroll) {
108
- updateVisibleLyricWillChange(engine, engine.lines, scroller.scrollTop, pendingScrollTop, scroller.height);
109
- }
110
- else {
111
- stopLineScrolling(engine);
112
- }
106
+ updateVisibleLyricWillChange(engine, engine.lines, scroller.scrollTop, pendingScrollTop, scroller.height);
113
107
  }
114
108
  else {
115
109
  stopLineScrolling(engine);
@@ -216,7 +210,7 @@ export function relayout(engine, linesAreRendered) {
216
210
  const restarted = restartContextSweeps(engine);
217
211
  engine.cachedCreditsItem = measureTrailingItem(lyricsElement, CREDITS_CLASS);
218
212
  engine.cachedFooterItem = measureTrailingItem(lyricsElement, FOOTER_CLASS);
219
- setupLineCulling(engine);
213
+ setupLineCullObserver(engine);
220
214
  requestRescroll(engine);
221
215
  engine.host.debug?.resize();
222
216
  return restarted;
@@ -1,10 +1,9 @@
1
1
  import { RTL_CLASS } from "../constants.js";
2
2
  import { registerThemeSetting } from "../themeSettings.js";
3
- import { correctedAnimationTimeMs, mirrorHighlightAnimations, followSongClock } from "./animationTiming.js";
4
- import { easingLookup } from "./elementMotion.js";
3
+ import { correctedAnimationTimeMs, followSongClock, mirrorHighlightAnimations, seekAnimation } from "./animationTiming.js";
5
4
  import { GECKO_REDRAW, GECKO_REDRAW_KEYFRAMES, GECKO_REDRAW_PERIOD_MS, LETTER_WAVE_CREST_OFFSET, planLetterWave, swipeRamp, } from "./letterPlans.js";
6
5
  import { resetPartAnimations } from "./lineAnimationState.js";
7
- import { cellLitAt, cellReachedAt, planCellSweep } from "./sweepPlans.js";
6
+ import { planCellSweep } from "./sweepPlans.js";
8
7
  import { acquireWaveAnimation } from "./wavePool.js";
9
8
  const SWIPE_LEAD_RATIO = registerThemeSetting("blyrics-swipe-lead-ratio", 0.1);
10
9
  const SWIPE_DURATION_RATIO = registerThemeSetting("blyrics-swipe-duration-ratio", 1.6);
@@ -13,9 +12,6 @@ const INSTANT_MS = 1;
13
12
  // The sweep holds a word's reveal in its own layers, so the word's own opacity is all that animates on it.
14
13
  const SHOWN = [{ opacity: 1 }, { opacity: 1 }];
15
14
  const FADE_IN = [{ opacity: 0 }, { opacity: 1 }];
16
- const FADE_OUT = [{ opacity: 1 }, { opacity: 0 }];
17
- // A line's exit leaves the started ones running so a glow fades out under the text instead of cutting off.
18
- const glowDelaysMs = new WeakMap();
19
15
  export function startWordAnimations(engine, part, config, lyricTimeS, appliedTimingOffsetMs) {
20
16
  resetPartAnimations(part);
21
17
  const word = wordTimeline(engine, part, config, lyricTimeS, appliedTimingOffsetMs);
@@ -26,23 +22,21 @@ export function startWordAnimations(engine, part, config, lyricTimeS, appliedTim
26
22
  part.animations = [...highlight, ...mirrorHighlightAnimations(part, highlight), ...motion];
27
23
  }
28
24
  export function startWordExitAnimation(part, config) {
29
- const glows = part.animations.filter(animation => glowStarted(animation));
30
- part.animations = part.animations.filter(animation => !glows.includes(animation));
31
25
  resetPartAnimations(part);
32
26
  const fades = config.enabled.highlightFade;
33
27
  const durationMs = fades ? config.highlight.fadeOutDurationMs : INSTANT_MS;
34
- const fadeOut = part.highlightElement.animate(FADE_OUT, {
28
+ const glowRest = glowShows(part, config) ? { filter: config.highlight.glowTo } : {};
29
+ const fadeOut = part.highlightElement.animate([
30
+ { opacity: 1, ...glowRest },
31
+ { opacity: 0, ...glowRest },
32
+ ], {
35
33
  duration: durationMs,
36
34
  easing: fades ? config.highlight.fadeOutEasing : "linear",
37
35
  fill: "none",
38
36
  });
39
- part.animations = [fadeOut, ...mirrorHighlightAnimations(part, [fadeOut]), ...glows];
37
+ part.animations = [fadeOut, ...mirrorHighlightAnimations(part, [fadeOut])];
40
38
  fadeOut.addEventListener("finish", () => resetPartAnimations(part), { once: true });
41
39
  }
42
- function glowStarted(animation) {
43
- const delayMs = glowDelaysMs.get(animation);
44
- return delayMs !== undefined && Number(animation.currentTime) >= delayMs;
45
- }
46
40
  function wordTimeline(engine, part, config, lyricTimeS, appliedTimingOffsetMs) {
47
41
  const durationMs = Math.max(0, part.duration * 1000);
48
42
  return {
@@ -63,7 +57,7 @@ function scheduledTimeMs(word, elapsedMs, durationMs) {
63
57
  function followSong(word, animation, currentTimeMs, { offsetMs = 0, skipDriftSample = false } = {}) {
64
58
  const { appliedTimingOffsetMs } = word;
65
59
  followSongClock(word.engine, animation, { appliedTimingOffsetMs, offsetMs, skipDriftSample });
66
- animation.currentTime = currentTimeMs;
60
+ seekAnimation(word.engine, animation, currentTimeMs);
67
61
  return animation;
68
62
  }
69
63
  function glowShows(part, config) {
@@ -71,12 +65,11 @@ function glowShows(part, config) {
71
65
  }
72
66
  function richSyncedHighlight(word) {
73
67
  const { part, config } = word;
74
- const swipes = config.enabled.highlightSwipe;
75
- const animations = swipes ? swipe(word) : [];
68
+ const animations = config.enabled.highlightSwipe ? swipe(word) : [];
76
69
  const show = part.highlightElement.animate(SHOWN, { duration: INSTANT_MS, easing: "linear", fill: "forwards" });
77
70
  animations.push(followSong(word, show, scheduledTimeMs(word, word.elapsedMs, INSTANT_MS)));
78
71
  if (glowShows(part, config))
79
- animations.push(...glow(word, word.glowDurationMs, swipes));
72
+ animations.push(glow(word, word.glowDurationMs));
80
73
  return animations;
81
74
  }
82
75
  function lineSyncedHighlight(word) {
@@ -90,7 +83,7 @@ function lineSyncedHighlight(word) {
90
83
  });
91
84
  const animations = [followSong(word, fadeIn, scheduledTimeMs(word, word.elapsedMs, durationMs))];
92
85
  if (glowShows(part, config))
93
- animations.push(...glow(word, config.highlight.glowMinDurationMs, false));
86
+ animations.push(glow(word, config.highlight.glowMinDurationMs));
94
87
  return animations;
95
88
  }
96
89
  function swipe(word) {
@@ -127,57 +120,15 @@ function compositedSwipe(word, cells, currentTimeMs) {
127
120
  });
128
121
  return animations;
129
122
  }
130
- function glow(word, durationMs, followsSwipe) {
131
- return word.part.sweep ? sweepGlow(word, word.part.sweep, durationMs, followsSwipe) : [];
132
- }
133
- // Where the shrinking radius reaches the tight halo's, as a fraction of the glow's eased progress.
134
- const TIGHT_GLOW_AT = 0.6;
135
- // The latest a halo may finish rising, so the crossfade after it keeps room to run.
136
- const LATEST_GLOW_PEAK = TIGHT_GLOW_AT / 2;
137
- /**
138
- * Stands in for a glow whose radius shrinks to nothing: the wide halo crossfades into the tight one
139
- * while the radius would shrink between them, and the tight one then fades out. The keyframe offsets
140
- * are in eased progress, since the glow's easing applies to the whole effect. Under a swipe each
141
- * cell's glow starts when the edge reaches it and rises while the edge crosses it, the way a glow
142
- * drawn from the lit text grows with it. Both are exact for a linear swipe and taken as linear for
143
- * any other.
144
- */
145
- function sweepGlow(word, cells, durationMs, followsSwipe) {
146
- const { engine, config, swipeLeadMs, swipeDurationMs } = word;
147
- const fades = config.highlight.glowRestingInvisible;
148
- const easeGlow = easingLookup(engine)(config.highlight.glowEasing);
149
- const ramp = swipeRamp(config);
150
- return cells.flatMap((cell, cellIndex) => {
151
- const span = cell.span ?? { start: cellIndex / cells.length, width: 1 / cells.length };
152
- const delayMs = followsSwipe ? Math.max(0, cellReachedAt(ramp, span) * swipeDurationMs - swipeLeadMs) : 0;
153
- const litMs = followsSwipe ? cellLitAt(ramp, span) * swipeDurationMs - swipeLeadMs : delayMs;
154
- const riseMs = Math.max(0, litMs - delayMs);
155
- const peak = durationMs > 0 ? Math.min(easeGlow(riseMs / durationMs), LATEST_GLOW_PEAK) : 0;
156
- const timing = {
157
- delay: delayMs,
158
- duration: durationMs,
159
- easing: config.highlight.glowEasing,
160
- fill: fades ? "none" : "forwards",
161
- };
162
- const currentTimeMs = scheduledTimeMs(word, word.elapsedMs, delayMs + durationMs);
163
- const halos = haloKeyframes(fades, peak);
164
- return cell.glows.map((halo, index) => {
165
- const fade = halo.glow.animate(index === 0 ? halos.wide : halos.tight, timing);
166
- glowDelaysMs.set(fade, delayMs);
167
- return followSong(word, fade, currentTimeMs, { skipDriftSample: true });
168
- });
123
+ function glow(word, durationMs) {
124
+ const { part, config } = word;
125
+ const keyframes = [{ filter: config.highlight.glowFrom }, { filter: config.highlight.glowTo }];
126
+ const shrink = part.highlightElement.animate(keyframes, {
127
+ duration: durationMs,
128
+ easing: config.highlight.glowEasing,
129
+ fill: config.highlight.glowRestingInvisible ? "none" : "forwards",
169
130
  });
170
- }
171
- function haloKeyframes(fades, peak) {
172
- const rises = peak > 0;
173
- const wideRise = rises ? [{ opacity: 0 }, { opacity: 1, offset: peak }] : [{ opacity: 1 }];
174
- const tightWait = rises ? [{ opacity: 0 }, { opacity: 0, offset: peak }] : [{ opacity: 0 }];
175
- if (!fades)
176
- return { wide: [...wideRise, { opacity: 1 }], tight: [{ opacity: 0 }, { opacity: 0 }] };
177
- return {
178
- wide: [...wideRise, { opacity: 0, offset: TIGHT_GLOW_AT }, { opacity: 0 }],
179
- tight: [...tightWait, { opacity: 1, offset: TIGHT_GLOW_AT }, { opacity: 0 }],
180
- };
131
+ return followSong(word, shrink, scheduledTimeMs(word, word.elapsedMs, durationMs), { skipDriftSample: true });
181
132
  }
182
133
  function wobble(word) {
183
134
  const { wobbleFrom, wobblePeak, wobblePeakOffset, wobblePeakEasing, wobbleSettle, wobbleSettleOffset } = word.config.word;
@@ -193,19 +144,14 @@ function wobble(word) {
193
144
  return word.part.wobbleElements.map(element => followSong(word, element.animate(keyframes, timing), currentTimeMs));
194
145
  }
195
146
  function letterWave(word) {
196
- const { part, config } = word;
147
+ const { part } = word;
197
148
  const letterCount = part.letterElements?.length ?? 0;
198
149
  if (letterCount === 0)
199
150
  return [];
200
151
  const run = planLetterWaveRun(word, letterCount);
201
- const glowLetterSets = glowShows(part, config)
202
- ? (part.sweep?.flatMap(cell => cell.glows.map(glow => glow.letters)) ?? [])
203
- : [];
204
152
  const animations = [];
205
153
  floatLetters(word, run, part.letterElements, true, animations);
206
154
  floatLetters(word, run, part.highlightLetterElements, false, animations);
207
- for (const glowLetters of glowLetterSets)
208
- floatLetters(word, run, glowLetters, false, animations);
209
155
  return animations;
210
156
  }
211
157
  function planLetterWaveRun(word, letterCount) {
package/dist/inject.d.ts CHANGED
@@ -17,24 +17,16 @@ export interface AnimationData {
17
17
  lyricElement: HTMLElement;
18
18
  animations: Animation[];
19
19
  }
20
- /** A copy of the word under a text shadow that never changes, faded in and out by opacity. */
21
- export interface SweepGlow {
22
- glow: HTMLElement;
23
- letters?: HTMLElement[];
24
- }
25
20
  /**
26
21
  * One box of a word's sweep, run by the compositor: the whole word when it is its own inline-block
27
22
  * box, or one letter of a word that flows inline. Its mask holds a static soft edge and slides one way
28
23
  * while the text inside it slides the other, so the glyphs hold still and only the edge crosses them.
29
- * The glow is a pair of halos at two radii inside the same text, so the edge reveals them with it,
30
- * crossfaded so the glow tightens as it fades. With nothing animating, the mask rests with the cell
31
- * fully lit.
24
+ * With nothing animating, the mask rests with the cell fully lit.
32
25
  */
33
26
  export interface SweepCell {
34
27
  mask: HTMLElement;
35
28
  text: HTMLElement;
36
29
  letters?: HTMLElement[];
37
- glows: SweepGlow[];
38
30
  /** Where the cell sits along the word, as fractions of the word's width; equal shares if unset. */
39
31
  span?: {
40
32
  start: number;
package/dist/inject.js CHANGED
@@ -13,7 +13,7 @@
13
13
  // into zero duration words, so line synced lyrics reach the DOM the sweep already knows.
14
14
  import { releasePart } from "./engine/lineAnimationState.js";
15
15
  import { normalizeLanguage } from "./language.js";
16
- 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, SWEEP_CELL_CLASS, SWEEP_GLOW_CLASS, SWEEP_MASK_CLASS, SWEEP_TEXT_CLASS, TRANSLATED_LYRICS_CLASS, WORD_CLASS, WORD_GROUP_CLASS, WORD_HIGHLIGHT_CLASS, WORD_HIGHLIGHT_CONTEXT_CLASS, WORD_HIGHLIGHT_LETTERED_CLASS, WORD_HIGHLIGHT_SWEEP_CLASS, WORD_STATE_ATTR, WORD_STATE_UPCOMING, ZERO_DURATION_ANIMATION_CLASS, } from "./constants.js";
16
+ 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, SWEEP_CELL_CLASS, SWEEP_MASK_CLASS, SWEEP_TEXT_CLASS, TRANSLATED_LYRICS_CLASS, WORD_CLASS, WORD_GROUP_CLASS, WORD_HIGHLIGHT_CLASS, WORD_HIGHLIGHT_CONTEXT_CLASS, WORD_HIGHLIGHT_LETTERED_CLASS, WORD_HIGHLIGHT_SWEEP_CLASS, WORD_STATE_ATTR, WORD_STATE_UPCOMING, ZERO_DURATION_ANIMATION_CLASS, } from "./constants.js";
17
17
  import { letterClusters } from "./letters.js";
18
18
  import { getSeekTimeFromClick } from "./seek.js";
19
19
  import { isSameText, testJoiningScript, testRtl } from "./text.js";
@@ -226,7 +226,6 @@ function fillWordText(doc, host, clusters, wrapThreshold, perLetter, preserveJoi
226
226
  appendLongWordBreaks(doc, host, clusters, wrapThreshold);
227
227
  return undefined;
228
228
  }
229
- const SWEEP_GLOW_RADII = ["wide", "tight"];
230
229
  export function createSweepCell(doc, host, fill) {
231
230
  const mask = doc.createElement("span");
232
231
  mask.classList.add(SWEEP_MASK_CLASS);
@@ -234,16 +233,9 @@ export function createSweepCell(doc, host, fill) {
234
233
  text.classList.add(SWEEP_TEXT_CLASS);
235
234
  mask.appendChild(text);
236
235
  const letters = fill(text);
237
- const glows = SWEEP_GLOW_RADII.map(radius => {
238
- const glow = doc.createElement("span");
239
- glow.classList.add(SWEEP_GLOW_CLASS, `${SWEEP_GLOW_CLASS}--${radius}`);
240
- const glowLetters = fill(glow);
241
- text.appendChild(glow);
242
- return { glow, letters: glowLetters };
243
- });
244
236
  host.classList.add(SWEEP_CELL_CLASS);
245
237
  host.appendChild(mask);
246
- return { mask, text, letters, glows };
238
+ return { mask, text, letters };
247
239
  }
248
240
  /** Makes each letter of a word that flows inline its own sweep cell, holding the letter's text. */
249
241
  function createLetterSweepCells(doc, letters) {
@@ -152,9 +152,8 @@
152
152
  to half a cell past the cell's end (SWEEP_REST in sweepPlans.ts), then a soft edge `fade` cells
153
153
  wide, where fade is the swipe's width from its last start stop to its last end stop, in cells. The
154
154
  engine slides the mask back to where the swipe begins and the text inside it the other way by the
155
- same distance, so the glyphs hold still while the edge crosses them. The glow's two halos sit in
156
- that same text, so the edge reveals them with it. With nothing animating the mask rests with the
157
- cell lit and its halos whole. */
155
+ same distance, so the glyphs hold still while the edge crosses them. With nothing animating the
156
+ mask rests with the cell lit. */
158
157
  .blyrics--word.blyrics-word-highlight.blyrics-word-highlight--sweep {
159
158
  color: var(--blyrics-lyric-active-color);
160
159
  --blyrics-sweep-angle: 90deg;
@@ -216,26 +215,6 @@
216
215
  width: calc(100% / var(--blyrics-sweep-widths));
217
216
  }
218
217
 
219
- /* A halo is a copy of the text whose own glyphs are clear, under a text shadow that never changes; the
220
- engine fades it by opacity. */
221
- .blyrics-sweep-glow {
222
- --blyrics-sweep-glow-radius: var(--blyrics-highlight-glow-radius-from, 0.8rem);
223
- color: transparent;
224
- inset: 0;
225
- opacity: 0;
226
- pointer-events: none;
227
- position: absolute;
228
- text-shadow: 0 0 var(--blyrics-sweep-glow-radius) var(--blyrics-glow-color);
229
- user-select: none;
230
- z-index: -1;
231
- }
232
-
233
- /* The glow shrinks as it fades. The engine crossfades from the wide halo to this one, which sits where
234
- the radius has shrunk to by the time the wide one is gone. */
235
- .blyrics-sweep-glow--tight {
236
- --blyrics-sweep-glow-radius: calc(var(--blyrics-highlight-glow-radius-from, 0.8rem) * 0.4);
237
- }
238
-
239
218
  /* A word that flows inline keeps its text here only for layout; its sweep is drawn by cells placed over
240
219
  each box it breaks into, which show the word from copies of its line. */
241
220
  .blyrics--word.blyrics-word-highlight.blyrics-word-highlight--context {
@@ -276,11 +255,6 @@
276
255
  color: var(--blyrics-lyric-active-color);
277
256
  }
278
257
 
279
- .blyrics-sweep-glow .blyrics-sweep-clone .blyrics--word.blyrics-sweep-target {
280
- color: transparent;
281
- text-shadow: 0 0 var(--blyrics-sweep-glow-radius) var(--blyrics-glow-color);
282
- }
283
-
284
258
  /* text-decoration skips inline-block letters and rides the wave, so draw on the word box instead, from its
285
259
  center (fixed against the text at any line-height), with layout-neutral padding so a tight box can hold it. */
286
260
  [blyrics-alt-hover] .blyrics--word:hover {
package/dist/view.js CHANGED
@@ -17,7 +17,7 @@ import {} from "./engine/instance.js";
17
17
  import { elementMotionOffsetPx } from "./engine/elementMotion.js";
18
18
  import { replaceRenderedLines } from "./engine/renderedLines.js";
19
19
  import { playerTimeForLyricTime } from "./engine/clock.js";
20
- import { setupLineCulling } from "./engine/culling.js";
20
+ import { setupLineCullObserver } from "./engine/culling.js";
21
21
  import { addSeekHandler, applyDirection, buildLineSyncedParts, createLyricsLine, deriveSyncType, disableRichsync, findNearestAgent, hideCredits, isNearestLyricRtl, moveDecorations, newLineData, } from "./inject.js";
22
22
  import { refreshInstrumentalImages } from "./imageHighlights.js";
23
23
  import { createInstrumentalElement } from "./instrumental.js";
@@ -231,7 +231,7 @@ export function setLyrics(engine, mount, lyrics, options) {
231
231
  // sizes it by.
232
232
  engine.lyricWidth = container.clientWidth;
233
233
  engine.lyricHeight = container.clientHeight;
234
- setupLineCulling(engine);
234
+ setupLineCullObserver(engine);
235
235
  }
236
236
  /**
237
237
  * Pairs each new line with an old one that builds the same, keeping their order, so a kept element is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braccato/core",
3
- "version": "1.21.4",
3
+ "version": "1.21.6",
4
4
  "description": "Synchronized lyrics renderer with word-by-word animations",
5
5
  "type": "module",
6
6
  "license": "MIT",