@braccato/core 1.21.6 → 2.0.0-beta.0

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 (105) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +202 -600
  3. package/dist/styles/lyrics.css +6 -0
  4. package/dist/util.d.ts +2 -0
  5. package/dist/util.js +4 -0
  6. package/js/element.js +234 -0
  7. package/js/renderer.d.ts +157 -0
  8. package/js/renderer.js +535 -0
  9. package/package.json +22 -17
  10. package/pkg/braccato_core_rs.d.ts +236 -0
  11. package/pkg/braccato_core_rs.js +1735 -0
  12. package/pkg/braccato_core_rs_bg.wasm +0 -0
  13. package/pkg/braccato_core_rs_bg.wasm.d.ts +55 -0
  14. package/dist/LICENSE +0 -21
  15. package/dist/README.md +0 -632
  16. package/dist/element.d.ts +0 -168
  17. package/dist/element.js +0 -730
  18. package/dist/engine/animationConfig.d.ts +0 -84
  19. package/dist/engine/animationConfig.js +0 -95
  20. package/dist/engine/animationDrift.d.ts +0 -11
  21. package/dist/engine/animationDrift.js +0 -43
  22. package/dist/engine/animationTiming.d.ts +0 -27
  23. package/dist/engine/animationTiming.js +0 -145
  24. package/dist/engine/autoScroll.d.ts +0 -24
  25. package/dist/engine/autoScroll.js +0 -103
  26. package/dist/engine/clock.d.ts +0 -29
  27. package/dist/engine/clock.js +0 -70
  28. package/dist/engine/contextSweep.d.ts +0 -10
  29. package/dist/engine/contextSweep.js +0 -102
  30. package/dist/engine/cssValues.d.ts +0 -13
  31. package/dist/engine/cssValues.js +0 -47
  32. package/dist/engine/culling.d.ts +0 -6
  33. package/dist/engine/culling.js +0 -76
  34. package/dist/engine/debugOverlay.d.ts +0 -14
  35. package/dist/engine/debugOverlay.js +0 -58
  36. package/dist/engine/decorationSlides.d.ts +0 -6
  37. package/dist/engine/decorationSlides.js +0 -53
  38. package/dist/engine/elementMotion.d.ts +0 -18
  39. package/dist/engine/elementMotion.js +0 -98
  40. package/dist/engine/glow.d.ts +0 -7
  41. package/dist/engine/glow.js +0 -59
  42. package/dist/engine/instance.d.ts +0 -105
  43. package/dist/engine/instance.js +0 -89
  44. package/dist/engine/instrumentalAnimations.d.ts +0 -7
  45. package/dist/engine/instrumentalAnimations.js +0 -59
  46. package/dist/engine/letterPlans.d.ts +0 -31
  47. package/dist/engine/letterPlans.js +0 -62
  48. package/dist/engine/lineAnimationState.d.ts +0 -10
  49. package/dist/engine/lineAnimationState.js +0 -82
  50. package/dist/engine/lineAnimations.d.ts +0 -5
  51. package/dist/engine/lineAnimations.js +0 -63
  52. package/dist/engine/lineLifecycle.d.ts +0 -12
  53. package/dist/engine/lineLifecycle.js +0 -92
  54. package/dist/engine/lineScroll.d.ts +0 -47
  55. package/dist/engine/lineScroll.js +0 -184
  56. package/dist/engine/lineScrollStyle.d.ts +0 -32
  57. package/dist/engine/lineScrollStyle.js +0 -133
  58. package/dist/engine/liveViews.d.ts +0 -3
  59. package/dist/engine/liveViews.js +0 -5
  60. package/dist/engine/motionCurves.d.ts +0 -19
  61. package/dist/engine/motionCurves.js +0 -85
  62. package/dist/engine/motionPreference.d.ts +0 -1
  63. package/dist/engine/motionPreference.js +0 -1
  64. package/dist/engine/passiveScroll.d.ts +0 -10
  65. package/dist/engine/passiveScroll.js +0 -93
  66. package/dist/engine/renderedLines.d.ts +0 -16
  67. package/dist/engine/renderedLines.js +0 -130
  68. package/dist/engine/scrollViewport.d.ts +0 -36
  69. package/dist/engine/scrollViewport.js +0 -104
  70. package/dist/engine/stageMotion.d.ts +0 -7
  71. package/dist/engine/stageMotion.js +0 -319
  72. package/dist/engine/sweepPlans.d.ts +0 -38
  73. package/dist/engine/sweepPlans.js +0 -66
  74. package/dist/engine/tick.d.ts +0 -16
  75. package/dist/engine/tick.js +0 -270
  76. package/dist/engine/timingLogs.d.ts +0 -7
  77. package/dist/engine/timingLogs.js +0 -81
  78. package/dist/engine/userScroll.d.ts +0 -12
  79. package/dist/engine/userScroll.js +0 -62
  80. package/dist/engine/wavePool.d.ts +0 -7
  81. package/dist/engine/wavePool.js +0 -22
  82. package/dist/engine/wordAnimations.d.ts +0 -5
  83. package/dist/engine/wordAnimations.js +0 -206
  84. package/dist/imageHighlights.d.ts +0 -4
  85. package/dist/imageHighlights.js +0 -34
  86. package/dist/index.d.ts +0 -17
  87. package/dist/index.js +0 -12
  88. package/dist/inject.d.ts +0 -98
  89. package/dist/inject.js +0 -591
  90. package/dist/instrumental.d.ts +0 -11
  91. package/dist/instrumental.js +0 -121
  92. package/dist/language.d.ts +0 -9
  93. package/dist/language.js +0 -47
  94. package/dist/letters.d.ts +0 -2
  95. package/dist/letters.js +0 -25
  96. package/dist/renderer.d.ts +0 -29
  97. package/dist/renderer.js +0 -412
  98. package/dist/seek.d.ts +0 -1
  99. package/dist/seek.js +0 -27
  100. package/dist/stage.d.ts +0 -58
  101. package/dist/stage.js +0 -121
  102. package/dist/types.d.ts +0 -236
  103. package/dist/types.js +0 -1
  104. package/dist/view.d.ts +0 -51
  105. package/dist/view.js +0 -396
@@ -1,66 +0,0 @@
1
- import { clamp } from "../util.js";
2
- function swipeStops(swipe) {
3
- const startFrom = Number.parseFloat(swipe.startFrom);
4
- const startTo = Number.parseFloat(swipe.startTo);
5
- const fade = Number.parseFloat(swipe.endTo) - startTo;
6
- if (![startFrom, startTo, fade].every(Number.isFinite) || startTo <= startFrom)
7
- return null;
8
- return { startFrom, startTo, fade: Math.max(fade, 0) };
9
- }
10
- /**
11
- * Where a cell's mask edge rests, in the cell's widths: half a cell past its end, so the halos inside
12
- * the mask show whole once the cell is lit. `.blyrics-sweep-mask` in lyrics.css places its edge there.
13
- */
14
- export const SWEEP_REST = 1.5;
15
- /**
16
- * The swipe's soft edge in a cell's own widths. `.blyrics-sweep-mask` reads the same value as
17
- * `--blyrics-sweep-fade`, so the two must agree.
18
- */
19
- export function cellFade(swipe, span) {
20
- const stops = swipeStops(swipe);
21
- return stops && span.width > 0 ? stops.fade / span.width : 0;
22
- }
23
- /**
24
- * How far through the swipe, in eased progress, its start stop reaches the start of a cell. Until then
25
- * the cell's halo would show behind the edge before any of its text is lit, so its glow waits.
26
- */
27
- export function cellReachedAt(swipe, span) {
28
- return startStopReaches(swipe, span.start);
29
- }
30
- /** How far through the swipe, in eased progress, its start stop reaches the end of a cell. */
31
- export function cellLitAt(swipe, span) {
32
- return startStopReaches(swipe, span.start + span.width);
33
- }
34
- function startStopReaches(swipe, position) {
35
- const stops = swipeStops(swipe);
36
- return stops ? clamp((position - stops.startFrom) / (stops.startTo - stops.startFrom), 0, 1) : 0;
37
- }
38
- /**
39
- * Plans one cell of a sweep. In the cell's own widths the start stop runs from
40
- * `(startFrom - span.start) / span.width` to `(startTo - span.start) / span.width`, and the cell only
41
- * changes while that is between `-fade` (nothing lit yet) and `SWEEP_REST` (lit, with room for its
42
- * halo), so the motion is clamped there. `.blyrics-sweep-mask` in lyrics.css is `3 + fade` cells wide,
43
- * starting a cell before the cell, with its soft edge from `SWEEP_REST` to `fade` cells further. The
44
- * start stop moves linearly in eased progress, so keyframes at the clamp points with the swipe's
45
- * easing on the whole effect follow it exactly.
46
- */
47
- export function planCellSweep(swipe, span, rtl) {
48
- const stops = swipeStops(swipe);
49
- if (!stops || span.width <= 0)
50
- return null;
51
- const fade = stops.fade / span.width;
52
- const maskWidths = 3 + fade;
53
- const sign = rtl ? -1 : 1;
54
- const startAt = (progress) => (stops.startFrom + (stops.startTo - stops.startFrom) * progress - span.start) / span.width;
55
- const progressAt = (start) => (start * span.width + span.start - stops.startFrom) / (stops.startTo - stops.startFrom);
56
- const offsets = [0, progressAt(-fade), progressAt(SWEEP_REST), 1].map(offset => clamp(offset, 0, 1));
57
- const unique = offsets.filter((offset, position) => offsets.indexOf(offset) === position);
58
- const mask = [];
59
- const text = [];
60
- for (const offset of unique) {
61
- const behind = sign * (clamp(startAt(offset), -fade, SWEEP_REST) - SWEEP_REST);
62
- mask.push({ offset, translate: `${(behind * 100) / maskWidths}% 0` });
63
- text.push({ offset, translate: `${-behind * 100}% 0` });
64
- }
65
- return { mask, text };
66
- }
@@ -1,16 +0,0 @@
1
- import type { ResolvedTickOptions, TickOptions } from "../types.js";
2
- import type { AnimationEngineInstance } from "./instance.js";
3
- /**
4
- * "lyrics-missing" means this instance has nothing left to render. Whether that ends ticking is the
5
- * driver's call, not the instance's: one instance running dry must not silence another.
6
- */
7
- export type AnimationTickStatus = "ok" | "lyrics-missing";
8
- export declare function resolveTickOptions(options: TickOptions): ResolvedTickOptions;
9
- export declare function tickView(engine: AnimationEngineInstance, reportedTimeS: number, options: ResolvedTickOptions): AnimationTickStatus;
10
- /** Returns whether it stopped lines that only a tick starts again; see `restartContextSweeps`. */
11
- export declare function relayout(engine: AnimationEngineInstance, linesAreRendered: boolean): boolean;
12
- export declare function cancelLyricPositionUpdate(engine: AnimationEngineInstance): void;
13
- export declare function retickFromPlaybackClock(engine: AnimationEngineInstance, buildTickOptions: (eventCreationTime: number, isPlaying: boolean) => TickOptions): AnimationTickStatus;
14
- /** Ticks again at the time and with the options of the last tick, for a view that is not ticking itself. */
15
- export declare function retickAtLastTime(engine: AnimationEngineInstance): void;
16
- export declare function scheduleLyricPositionUpdate(engine: AnimationEngineInstance, isViewRendering: () => boolean, retick: () => void): void;
@@ -1,270 +0,0 @@
1
- import { CREDITS_CLASS, CURRENT_LYRICS_CLASS, FOOTER_CLASS } from "../constants.js";
2
- import { getRelativeLayoutBounds } from "../util.js";
3
- import { getAnimationSettings } from "./animationConfig.js";
4
- import { applyPlaybackRateToRunningAnimations, correctedScrollTimeS } from "./animationTiming.js";
5
- import { followFocusedLines, lastSungLine } from "./autoScroll.js";
6
- import { advancePlaybackClock, lyricClockShiftS, NO_PLAYER_SNAPSHOT, playbackClock } from "./clock.js";
7
- import { getCSSDurationInMs } from "./cssValues.js";
8
- import { clearOffscreenLineCulling, clearVisibleLyricWillChange, setupLineCullObserver, updateVisibleLyricWillChange, } from "./culling.js";
9
- import { captureDecorationSlide, lineDecorators } from "./decorationSlides.js";
10
- import { resetLineAnimationState } from "./lineAnimationState.js";
11
- import { driveLineAnimations } from "./lineLifecycle.js";
12
- import { clearLineScrolls, dropPendingLineScroll, measureTrailingItem } from "./lineScroll.js";
13
- import { hasNoLyricsPlaceholder, hasUnsyncedLyrics, startPassiveScrollLoop, stopPassiveScrollLoop, } from "./passiveScroll.js";
14
- import { applyScrollPadding, measureScrollViewport, setupTabRendererObserver } from "./scrollViewport.js";
15
- import { applyStage, measureStage } from "./stageMotion.js";
16
- import { requestRescroll } from "./userScroll.js";
17
- const NO_LYRICS_ELEMENT_LOG = "No lyrics element found on the page, skipping lyrics injection";
18
- const TICK_ERROR_LOG = "Error in lyrics tick:";
19
- export function resolveTickOptions(options) {
20
- return {
21
- isPlaying: options.isPlaying,
22
- eventCreationTime: options.eventCreationTime ?? NO_PLAYER_SNAPSHOT,
23
- smoothScroll: options.smoothScroll ?? true,
24
- globalLyricOffset: options.globalLyricOffset ?? 0,
25
- lyricOffset: options.lyricOffset ?? 0,
26
- richsyncOffsetTrim: options.richsyncOffsetTrim ?? 0,
27
- lineOffsetTrim: options.lineOffsetTrim ?? 0,
28
- passiveScrollEnabled: options.passiveScrollEnabled ?? false,
29
- playbackRate: usablePlaybackRate(options.playbackRate),
30
- followPausedSeeks: options.followPausedSeeks ?? false,
31
- countEveryUserScroll: options.countEveryUserScroll ?? false,
32
- };
33
- }
34
- function usablePlaybackRate(rate) {
35
- return rate !== undefined && Number.isFinite(rate) && rate > 0 ? rate : 1;
36
- }
37
- export function tickView(engine, reportedTimeS, options) {
38
- rememberTickOptions(engine, options);
39
- if (reportedTimeS === 0 && !options.isPlaying)
40
- return "ok";
41
- if (hasNoLyricsPlaceholder(engine)) {
42
- stopPassiveScrollLoop(engine);
43
- return "ok";
44
- }
45
- if (hasUnsyncedLyrics(engine)) {
46
- followUnsyncedLyrics(engine, options);
47
- return "ok";
48
- }
49
- const now = Date.now();
50
- const playhead = advancePlaybackClock(reportedTimeS, options, engine.playbackRate, now);
51
- if (playhead.jumped)
52
- dropPendingLineScroll(engine);
53
- if (!engine.host.isViewVisible()) {
54
- clearVisibleLyricWillChange(engine);
55
- return "ok";
56
- }
57
- if (engine.host.syncAdState())
58
- return "ok";
59
- const lyricsElement = engine.lyricsContainer;
60
- if (!lyricsElement) {
61
- engine.host.log(NO_LYRICS_ELEMENT_LOG);
62
- return "lyrics-missing";
63
- }
64
- try {
65
- renderSyncedLyrics(engine, lyricsElement, playhead, options, now);
66
- }
67
- catch (error) {
68
- if (!isUndefinedAccessError(error))
69
- engine.host.log(TICK_ERROR_LOG, error);
70
- }
71
- return "ok";
72
- }
73
- function rememberTickOptions(engine, options) {
74
- engine.lastTickOptions = options;
75
- engine.passiveScrollEnabled = options.passiveScrollEnabled;
76
- if (engine.playbackRate === options.playbackRate)
77
- return;
78
- engine.playbackRate = options.playbackRate;
79
- applyPlaybackRateToRunningAnimations(engine);
80
- }
81
- function followUnsyncedLyrics(engine, { isPlaying, passiveScrollEnabled }) {
82
- if (engine.layout === "stage")
83
- return;
84
- if (isPlaying && !playbackClock.lastPlayState)
85
- engine.scrollResumeTime = 0;
86
- playbackClock.lastPlayState = isPlaying;
87
- if (passiveScrollEnabled)
88
- startPassiveScrollLoop(engine);
89
- }
90
- function isUndefinedAccessError(error) {
91
- return error.message?.includes("undefined") ?? false;
92
- }
93
- function renderSyncedLyrics(engine, lyricsElement, playhead, options, now) {
94
- const lyricTimeS = playhead.timeS + lyricClockShiftS(engine, lyricsElement, options);
95
- const scrollTimeS = correctedScrollTimeS(engine, lyricTimeS) +
96
- getCSSDurationInMs(engine, lyricsElement, "--blyrics-scroll-timing-offset") / 1000;
97
- const { config, scrollTiming } = getAnimationSettings(engine, lyricsElement);
98
- const isStage = engine.layout === "stage";
99
- const scroller = isStage ? null : readScrollerBeforeWrites(engine);
100
- if (!isStage && !scroller) {
101
- clearVisibleLyricWillChange(engine);
102
- return;
103
- }
104
- if (scroller && config.enabled.scroll) {
105
- const pendingScrollTop = engine.pendingLineScroll?.toScrollTop ?? scroller.scrollTop;
106
- updateVisibleLyricWillChange(engine, engine.lines, scroller.scrollTop, pendingScrollTop, scroller.height);
107
- }
108
- else {
109
- stopLineScrolling(engine);
110
- }
111
- const focus = focusLines(engine, scrollTimeS, scrollTiming.earlyScrollConsiderS);
112
- driveLineAnimations({ engine, lyricTimeS, playhead, config, now });
113
- const creditsFocusChanged = updateCreditsFocus(engine, lyricsElement, scrollTimeS);
114
- if (!scroller) {
115
- applyStage(engine, lyricTimeS, playhead.jumped);
116
- return;
117
- }
118
- followFocusedLines({
119
- engine,
120
- lyricsElement,
121
- scroller,
122
- focusedLines: focus.lines,
123
- scrollTimeS,
124
- config,
125
- smoothScroll: options.smoothScroll,
126
- countEveryUserScroll: options.countEveryUserScroll,
127
- jumped: playhead.jumped,
128
- focusChanged: playhead.jumped || focus.reachedUncommittedLine || creditsFocusChanged,
129
- now,
130
- });
131
- }
132
- function readScrollerBeforeWrites(engine) {
133
- const element = engine.host.getScrollElement();
134
- if (!element)
135
- return null;
136
- if (element !== engine.observedTabRenderer)
137
- setupTabRendererObserver(engine, element);
138
- return {
139
- element,
140
- height: engine.cachedTabRendererHeight ?? element.getBoundingClientRect().height,
141
- scrollTop: element.scrollTop,
142
- maxScrollTop: Math.max(0, element.scrollHeight - element.clientHeight),
143
- };
144
- }
145
- function stopLineScrolling(engine) {
146
- dropPendingLineScroll(engine);
147
- clearVisibleLyricWillChange(engine);
148
- clearLineScrolls(engine);
149
- }
150
- function focusLines(engine, scrollTimeS, earlyScrollConsiderS) {
151
- const lines = engine.lines;
152
- const focused = [];
153
- let reachedUncommittedLine = false;
154
- for (let index = 0; index < lines.length; index++) {
155
- const line = lines[index];
156
- const nextLineStartS = lines[index + 1]?.time ?? Infinity;
157
- const inFocus = scrollTimeS >= line.time - earlyScrollConsiderS &&
158
- (scrollTimeS < nextLineStartS || scrollTimeS < line.time + line.duration);
159
- setLineCurrent(line, inFocus);
160
- if (!inFocus)
161
- continue;
162
- focused.push(line);
163
- engine.selectedElementIndex = index;
164
- if (scrollTimeS >= line.time && !engine.lastScrollElements.includes(line))
165
- reachedUncommittedLine = true;
166
- }
167
- return { lines: focused, reachedUncommittedLine };
168
- }
169
- function setLineCurrent(line, current) {
170
- if (line.isScrolled === current)
171
- return;
172
- line.isScrolled = current;
173
- line.lyricElement.classList.toggle(CURRENT_LYRICS_CLASS, current);
174
- }
175
- function updateCreditsFocus(engine, lyricsElement, scrollTimeS) {
176
- const lastLine = lastSungLine(engine);
177
- const focused = lastLine !== undefined &&
178
- (engine.cachedCreditsItem?.height ?? 0) > 0 &&
179
- scrollTimeS >= lastLine.time + lastLine.duration;
180
- if (focused === engine.creditsFocused)
181
- return false;
182
- engine.creditsFocused = focused;
183
- if (focused)
184
- lyricsElement.dataset.creditsFocused = "true";
185
- else
186
- delete lyricsElement.dataset.creditsFocused;
187
- return true;
188
- }
189
- /** Returns whether it stopped lines that only a tick starts again; see `restartContextSweeps`. */
190
- export function relayout(engine, linesAreRendered) {
191
- if (engine.layout === "stage") {
192
- if (!linesAreRendered || !engine.lyricsContainer)
193
- return false;
194
- engine.cachedCreditsItem = measureTrailingItem(engine.lyricsContainer, CREDITS_CLASS);
195
- measureStage(engine);
196
- return restartContextSweeps(engine);
197
- }
198
- applyScrollPadding(engine);
199
- const scrollElement = engine.host.getScrollElement();
200
- if (scrollElement)
201
- measureScrollViewport(engine, scrollElement);
202
- if (!linesAreRendered)
203
- return false;
204
- const lyricsElement = engine.lyricsContainer;
205
- if (!lyricsElement)
206
- return false;
207
- engine.lyricWidth = lyricsElement.clientWidth;
208
- engine.lyricHeight = lyricsElement.clientHeight;
209
- measureLinePositions(engine, lyricsElement);
210
- const restarted = restartContextSweeps(engine);
211
- engine.cachedCreditsItem = measureTrailingItem(lyricsElement, CREDITS_CLASS);
212
- engine.cachedFooterItem = measureTrailingItem(lyricsElement, FOOTER_CLASS);
213
- setupLineCullObserver(engine);
214
- requestRescroll(engine);
215
- engine.host.debug?.resize();
216
- return restarted;
217
- }
218
- /**
219
- * A word drawn by sweep cells placed over its boxes needs them placed again once the layout moves.
220
- * Stopping its line lets the next tick start it over at the same moment, which places them afresh.
221
- * A paused view gets no next tick on its own, so whoever relayouts has to tick once it returns true.
222
- */
223
- function restartContextSweeps(engine) {
224
- let restarted = false;
225
- for (const line of engine.lines) {
226
- if (line.isAnimating && line.parts.some(part => part.sweepContext)) {
227
- resetLineAnimationState(line);
228
- restarted = true;
229
- }
230
- }
231
- return restarted;
232
- }
233
- function measureLinePositions(engine, lyricsElement) {
234
- clearOffscreenLineCulling(engine);
235
- for (const line of engine.lines) {
236
- const bounds = getRelativeLayoutBounds(lyricsElement, line.lyricElement);
237
- line.position = bounds.y;
238
- line.height = bounds.height;
239
- line.decorations = new Map(lineDecorators(line.lyricElement).map(element => [element, getRelativeLayoutBounds(lyricsElement, element).y]));
240
- }
241
- }
242
- export function cancelLyricPositionUpdate(engine) {
243
- if (engine.pendingLyricsUpdateFrame === null)
244
- return;
245
- engine.window.cancelAnimationFrame(engine.pendingLyricsUpdateFrame);
246
- engine.pendingLyricsUpdateFrame = null;
247
- }
248
- export function retickFromPlaybackClock(engine, buildTickOptions) {
249
- const options = buildTickOptions(playbackClock.lastEventCreationTime, playbackClock.lastPlayState);
250
- return tickView(engine, playbackClock.lastTime, resolveTickOptions(options));
251
- }
252
- /** Ticks again at the time and with the options of the last tick, for a view that is not ticking itself. */
253
- export function retickAtLastTime(engine) {
254
- if (engine.lastTickOptions)
255
- tickView(engine, playbackClock.lastTime, engine.lastTickOptions);
256
- }
257
- export function scheduleLyricPositionUpdate(engine, isViewRendering, retick) {
258
- if (engine.pendingLyricsUpdateFrame !== null)
259
- return;
260
- dropPendingLineScroll(engine);
261
- engine.pendingLyricsUpdateFrame = engine.window.requestAnimationFrame(() => {
262
- engine.pendingLyricsUpdateFrame = null;
263
- const isRendering = isViewRendering();
264
- const playSlide = isRendering ? captureDecorationSlide(engine) : null;
265
- relayout(engine, isRendering);
266
- playSlide?.();
267
- if (isRendering)
268
- retick();
269
- });
270
- }
@@ -1,7 +0,0 @@
1
- import type { LineData } from "../inject.js";
2
- import type { DriftSample } from "./animationTiming.js";
3
- import type { AnimationEngineInstance } from "./instance.js";
4
- export declare function shouldLogAnimationTiming(engine: AnimationEngineInstance, line: LineData, sample: DriftSample, now: number): boolean;
5
- export declare function logAnimationTiming(engine: AnimationEngineInstance, reason: string, line: LineData, lineIndex: number, sample: DriftSample, lyricTimeS: number, accumulatedOffsetMs: number, learnedOffsetMs?: number): void;
6
- export declare function logAnimationCleanup(engine: AnimationEngineInstance, reason: string, line: LineData, lineIndex: number, lyricTimeS: number, staleAfterS: number): void;
7
- export declare function noteVisibilityChange(engine: AnimationEngineInstance): void;
@@ -1,81 +0,0 @@
1
- import { registerThemeSetting } from "../themeSettings.js";
2
- import { roundedMs } from "../util.js";
3
- const TIMING_LOGS_ENABLED = registerThemeSetting("blyrics-debug-animation-timing", false);
4
- const VISIBILITY_LOG_WINDOW_MS = 3000;
5
- const PER_LINE_LOG_INTERVAL_MS = 750;
6
- const LOGGED_OFFSET_THRESHOLD_MS = 30;
7
- const lastLogTimes = new WeakMap();
8
- export function shouldLogAnimationTiming(engine, line, sample, now) {
9
- if (!TIMING_LOGS_ENABLED.getBooleanValue())
10
- return false;
11
- const inVisibilityWindow = now < engine.animationTimingVisibilityLogUntil;
12
- if (!inVisibilityWindow && Math.abs(sample.offsetMs) < LOGGED_OFFSET_THRESHOLD_MS)
13
- return false;
14
- if (now - (lastLogTimes.get(line) ?? 0) < PER_LINE_LOG_INTERVAL_MS)
15
- return false;
16
- lastLogTimes.set(line, now);
17
- return true;
18
- }
19
- export function logAnimationTiming(engine, reason, line, lineIndex, sample, lyricTimeS, accumulatedOffsetMs, learnedOffsetMs = engine.learnedAnimationTimingOffsetMs) {
20
- if (!TIMING_LOGS_ENABLED.getBooleanValue())
21
- return;
22
- engine.host.log("WAAPI timing", {
23
- reason,
24
- lineIndex,
25
- lineTimeS: roundedSeconds(line.time),
26
- mediaTimeS: roundedSeconds(lyricTimeS),
27
- actualTimeMs: roundedMs(sample.actualTimeMs),
28
- expectedTimeMs: roundedMs(sample.expectedTimeMs),
29
- offsetMs: roundedMs(sample.offsetMs),
30
- learnedOffsetMs: roundedMs(learnedOffsetMs),
31
- appliedTimingOffsetMs: roundedMs(sample.appliedTimingOffsetMs),
32
- biasOffsetMs: roundedMs(sample.biasOffsetMs),
33
- residualOffsetMs: roundedMs(sample.offsetMs),
34
- accumulatedOffsetMs: roundedMs(accumulatedOffsetMs),
35
- playState: sample.playState,
36
- text: linePreview(line),
37
- });
38
- }
39
- export function logAnimationCleanup(engine, reason, line, lineIndex, lyricTimeS, staleAfterS) {
40
- if (!TIMING_LOGS_ENABLED.getBooleanValue())
41
- return;
42
- engine.host.log("Animation cleanup", {
43
- reason,
44
- lineIndex,
45
- lineTimeS: roundedSeconds(line.time),
46
- mediaTimeS: roundedSeconds(lyricTimeS),
47
- staleAnimationEndTimeS: roundedSeconds(staleAfterS),
48
- runningAnimationCount: countAnimations(line),
49
- text: linePreview(line),
50
- });
51
- }
52
- export function noteVisibilityChange(engine) {
53
- if (!TIMING_LOGS_ENABLED.getBooleanValue() || !engine.lyricsContainer)
54
- return;
55
- const visibilityState = engine.document.visibilityState;
56
- const runningAnimationCount = engine.lines.reduce((count, line) => count + countAnimations(line), 0);
57
- if (visibilityState !== "visible") {
58
- engine.host.log("Visibility changed; WAAPI animations left intact", {
59
- visibilityState,
60
- runningAnimationCount,
61
- resetSkipped: true,
62
- });
63
- return;
64
- }
65
- engine.animationTimingVisibilityLogUntil = Date.now() + VISIBILITY_LOG_WINDOW_MS;
66
- engine.host.log("Visibility changed; keeping WAAPI animations for timing verification", {
67
- visibilityState,
68
- runningAnimationCount,
69
- resetSkipped: true,
70
- timingLogWindowMs: VISIBILITY_LOG_WINDOW_MS,
71
- });
72
- }
73
- function countAnimations(line) {
74
- return line.parts.reduce((count, part) => count + part.animations.length, line.animations.length);
75
- }
76
- function roundedSeconds(timeS) {
77
- return roundedMs(timeS * 1000) / 1000;
78
- }
79
- function linePreview(line) {
80
- return line.lyricElement.textContent?.trim().replace(/\s+/g, " ").slice(0, 80) ?? "";
81
- }
@@ -1,12 +0,0 @@
1
- import type { AnimationEngineInstance } from "./instance.js";
2
- export declare function resetScrollResume(engine: AnimationEngineInstance): void;
3
- /**
4
- * Resume autoscroll immediately for every live view.
5
- */
6
- export declare function resumeAllAutoscroll(): void;
7
- export declare function noteUserScroll(engine: AnimationEngineInstance, lyricsAreUnsynced: boolean): void;
8
- export declare function hasContainerResized(engine: AnimationEngineInstance, width: number, height: number): boolean;
9
- export declare function writeEngineScrollTop(engine: AnimationEngineInstance, scroller: HTMLElement, scrollTop: number, now: number): void;
10
- export declare function noteEngineScrollEvent(engine: AnimationEngineInstance, now: number): void;
11
- export declare function requestRescroll(engine: AnimationEngineInstance): void;
12
- export declare function decaySkipScrolls(engine: AnimationEngineInstance, now: number, keepsReserve: boolean): void;
@@ -1,62 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- fill: FillMode;
7
- }): Animation;
@@ -1,22 +0,0 @@
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
- }
@@ -1,5 +0,0 @@
1
- import type { PartData } from "../inject.js";
2
- import type { AnimationConfig } from "./animationConfig.js";
3
- import type { AnimationEngineInstance } from "./instance.js";
4
- export declare function startWordAnimations(engine: AnimationEngineInstance, part: PartData, config: AnimationConfig, lyricTimeS: number, appliedTimingOffsetMs: number): void;
5
- export declare function startWordExitAnimation(part: PartData, config: AnimationConfig): void;