@braccato/core 1.20.1 → 1.21.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.
- package/README.md +40 -37
- package/dist/README.md +40 -37
- package/dist/constants.d.ts +10 -0
- package/dist/constants.js +10 -0
- package/dist/engine/animationConfig.d.ts +0 -5
- package/dist/engine/animationConfig.js +0 -5
- package/dist/engine/animationTiming.d.ts +2 -1
- package/dist/engine/animationTiming.js +3 -2
- package/dist/engine/contextSweep.d.ts +10 -0
- package/dist/engine/contextSweep.js +102 -0
- package/dist/engine/culling.js +9 -0
- package/dist/engine/decorationSlides.d.ts +1 -1
- package/dist/engine/decorationSlides.js +13 -4
- package/dist/engine/elementMotion.d.ts +17 -0
- package/dist/engine/elementMotion.js +98 -0
- package/dist/engine/glow.js +1 -1
- package/dist/engine/instance.d.ts +5 -2
- package/dist/engine/instance.js +3 -1
- package/dist/engine/letterPlans.d.ts +0 -11
- package/dist/engine/letterPlans.js +0 -41
- package/dist/engine/lineAnimationState.js +0 -3
- package/dist/engine/lineAnimations.d.ts +1 -1
- package/dist/engine/lineAnimations.js +5 -24
- package/dist/engine/lineLifecycle.js +1 -1
- package/dist/engine/lineScroll.d.ts +5 -6
- package/dist/engine/lineScroll.js +36 -26
- package/dist/engine/lineScrollStyle.d.ts +8 -3
- package/dist/engine/lineScrollStyle.js +18 -4
- package/dist/engine/motionCurves.d.ts +19 -0
- package/dist/engine/motionCurves.js +85 -0
- package/dist/engine/renderedLines.d.ts +1 -2
- package/dist/engine/renderedLines.js +8 -15
- package/dist/engine/sweepPlans.d.ts +36 -0
- package/dist/engine/sweepPlans.js +59 -0
- package/dist/engine/tick.d.ts +4 -1
- package/dist/engine/tick.js +30 -6
- package/dist/engine/wavePool.d.ts +0 -1
- package/dist/engine/wordAnimations.d.ts +1 -5
- package/dist/engine/wordAnimations.js +88 -66
- package/dist/imageHighlights.d.ts +0 -11
- package/dist/imageHighlights.js +2 -48
- package/dist/inject.d.ts +41 -2
- package/dist/inject.js +72 -27
- package/dist/renderer.js +3 -2
- package/dist/styles/image-highlights.css +1 -59
- package/dist/styles/lyrics.css +128 -57
- package/dist/view.d.ts +1 -1
- package/dist/view.js +4 -3
- package/package.json +1 -1
- package/dist/engine/highlightKeyframes.d.ts +0 -8
- package/dist/engine/highlightKeyframes.js +0 -37
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ANIMATING_CLASS, CURRENT_LYRICS_CLASS } from "../constants.js";
|
|
2
2
|
import { clearOffscreenLineCulling, clearVisibleLyricWillChange } from "./culling.js";
|
|
3
3
|
import { DECORATION_MIN_SHIFT_PX, decorationSlideAllowed, slideElementBy } from "./decorationSlides.js";
|
|
4
|
+
import { stopAllElementMotion, stopElementMotion } from "./elementMotion.js";
|
|
4
5
|
import { resetLineAnimationState, togglePartClass } from "./lineAnimationState.js";
|
|
5
|
-
import {
|
|
6
|
+
import { dropPendingLineScroll } from "./lineScroll.js";
|
|
6
7
|
import { stopPassiveScrollLoop } from "./passiveScroll.js";
|
|
7
|
-
import {
|
|
8
|
+
import { replaceStageElements, resetStage } from "./stageMotion.js";
|
|
8
9
|
import { noteEngineScrollEvent } from "./userScroll.js";
|
|
9
10
|
export function clearOnScreenLyrics(engine) {
|
|
10
11
|
if (!engine.lyricsContainer)
|
|
@@ -25,7 +26,7 @@ export function getRenderedSyncType(engine) {
|
|
|
25
26
|
export function clearLyrics(engine) {
|
|
26
27
|
engine.scrollPos = -1;
|
|
27
28
|
dropPendingLineScroll(engine);
|
|
28
|
-
|
|
29
|
+
stopAllElementMotion(engine);
|
|
29
30
|
clearVisibleLyricWillChange(engine);
|
|
30
31
|
engine.lineCullObserver?.disconnect();
|
|
31
32
|
engine.lineCullObserver = null;
|
|
@@ -51,21 +52,13 @@ export function clearLyrics(engine) {
|
|
|
51
52
|
engine.waveAnimationPool.length = 0;
|
|
52
53
|
resetStage(engine);
|
|
53
54
|
}
|
|
54
|
-
export function lineScrollOffset(engine, element) {
|
|
55
|
-
const scrolling = engine.lineScrollAnimations.some(record => record.lineElement === element);
|
|
56
|
-
return scrolling ? currentTranslateY(engine, element, 0) : 0;
|
|
57
|
-
}
|
|
58
55
|
export function replaceRenderedLines(engine, lines, dropped, previousOf) {
|
|
59
56
|
for (const [line, previous] of previousOf)
|
|
60
57
|
carrySelection(line, previous);
|
|
61
58
|
dropPendingLineScroll(engine);
|
|
62
59
|
const droppedElements = new Set(dropped.map(line => line.lyricElement));
|
|
63
|
-
for (const
|
|
64
|
-
|
|
65
|
-
continue;
|
|
66
|
-
record.animation.cancel();
|
|
67
|
-
removeLineScrollAnimation(engine, record);
|
|
68
|
-
}
|
|
60
|
+
for (const element of droppedElements)
|
|
61
|
+
stopElementMotion(engine, element);
|
|
69
62
|
for (const line of dropped) {
|
|
70
63
|
resetLineAnimationState(line);
|
|
71
64
|
line.isSelected = false;
|
|
@@ -116,9 +109,9 @@ export function settleSwappedLines(engine, before, scrollTopBefore) {
|
|
|
116
109
|
const was = before.get(line);
|
|
117
110
|
if (was === undefined || !isMeasured(was.position) || !isMeasured(line.position))
|
|
118
111
|
continue;
|
|
119
|
-
const onScreenShift = was.position + was.
|
|
112
|
+
const onScreenShift = was.position + was.motionOffset - line.position + appliedShift;
|
|
120
113
|
if (Math.abs(onScreenShift) >= DECORATION_MIN_SHIFT_PX)
|
|
121
|
-
slideElementBy(line.lyricElement, onScreenShift);
|
|
114
|
+
slideElementBy(engine, line.lyricElement, onScreenShift);
|
|
122
115
|
}
|
|
123
116
|
}
|
|
124
117
|
function followedLine(engine, before, scrollTopBefore, now) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SwipeRamp } from "./letterPlans.js";
|
|
2
|
+
/** Keyframes for a sweep cell's mask and for the text inside it, offsets in eased swipe progress. */
|
|
3
|
+
export interface CellSweep {
|
|
4
|
+
mask: Keyframe[];
|
|
5
|
+
text: Keyframe[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Where a cell's mask edge rests, in the cell's widths: half a cell past its end, so the halos inside
|
|
9
|
+
* the mask show whole once the cell is lit. `.blyrics-sweep-mask` in lyrics.css places its edge there.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SWEEP_REST = 1.5;
|
|
12
|
+
/** A cell's place along its word, as fractions of the word's width. */
|
|
13
|
+
export interface CellSpan {
|
|
14
|
+
start: number;
|
|
15
|
+
width: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The swipe's soft edge in a cell's own widths. `.blyrics-sweep-mask` reads the same value as
|
|
19
|
+
* `--blyrics-sweep-fade`, so the two must agree.
|
|
20
|
+
*/
|
|
21
|
+
export declare function cellFade(swipe: SwipeRamp, span: CellSpan): number;
|
|
22
|
+
/**
|
|
23
|
+
* How far through the swipe, in eased progress, its start stop reaches the start of a cell. Until then
|
|
24
|
+
* the cell's halo would show behind the edge before any of its text is lit, so its glow waits.
|
|
25
|
+
*/
|
|
26
|
+
export declare function cellReachedAt(swipe: SwipeRamp, span: CellSpan): number;
|
|
27
|
+
/**
|
|
28
|
+
* Plans one cell of a sweep. In the cell's own widths the start stop runs from
|
|
29
|
+
* `(startFrom - span.start) / span.width` to `(startTo - span.start) / span.width`, and the cell only
|
|
30
|
+
* changes while that is between `-fade` (nothing lit yet) and `SWEEP_REST` (lit, with room for its
|
|
31
|
+
* halo), so the motion is clamped there. `.blyrics-sweep-mask` in lyrics.css is `3 + fade` cells wide,
|
|
32
|
+
* starting a cell before the cell, with its soft edge from `SWEEP_REST` to `fade` cells further. The
|
|
33
|
+
* start stop moves linearly in eased progress, so keyframes at the clamp points with the swipe's
|
|
34
|
+
* easing on the whole effect follow it exactly.
|
|
35
|
+
*/
|
|
36
|
+
export declare function planCellSweep(swipe: SwipeRamp, span: CellSpan, rtl: boolean): CellSweep | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
const stops = swipeStops(swipe);
|
|
29
|
+
return stops ? clamp((span.start - stops.startFrom) / (stops.startTo - stops.startFrom), 0, 1) : 0;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Plans one cell of a sweep. In the cell's own widths the start stop runs from
|
|
33
|
+
* `(startFrom - span.start) / span.width` to `(startTo - span.start) / span.width`, and the cell only
|
|
34
|
+
* changes while that is between `-fade` (nothing lit yet) and `SWEEP_REST` (lit, with room for its
|
|
35
|
+
* halo), so the motion is clamped there. `.blyrics-sweep-mask` in lyrics.css is `3 + fade` cells wide,
|
|
36
|
+
* starting a cell before the cell, with its soft edge from `SWEEP_REST` to `fade` cells further. The
|
|
37
|
+
* start stop moves linearly in eased progress, so keyframes at the clamp points with the swipe's
|
|
38
|
+
* easing on the whole effect follow it exactly.
|
|
39
|
+
*/
|
|
40
|
+
export function planCellSweep(swipe, span, rtl) {
|
|
41
|
+
const stops = swipeStops(swipe);
|
|
42
|
+
if (!stops || span.width <= 0)
|
|
43
|
+
return null;
|
|
44
|
+
const fade = stops.fade / span.width;
|
|
45
|
+
const maskWidths = 3 + fade;
|
|
46
|
+
const sign = rtl ? -1 : 1;
|
|
47
|
+
const startAt = (progress) => (stops.startFrom + (stops.startTo - stops.startFrom) * progress - span.start) / span.width;
|
|
48
|
+
const progressAt = (start) => (start * span.width + span.start - stops.startFrom) / (stops.startTo - stops.startFrom);
|
|
49
|
+
const offsets = [0, progressAt(-fade), progressAt(SWEEP_REST), 1].map(offset => clamp(offset, 0, 1));
|
|
50
|
+
const unique = offsets.filter((offset, position) => offsets.indexOf(offset) === position);
|
|
51
|
+
const mask = [];
|
|
52
|
+
const text = [];
|
|
53
|
+
for (const offset of unique) {
|
|
54
|
+
const behind = sign * (clamp(startAt(offset), -fade, SWEEP_REST) - SWEEP_REST);
|
|
55
|
+
mask.push({ offset, translate: `${(behind * 100) / maskWidths}% 0` });
|
|
56
|
+
text.push({ offset, translate: `${-behind * 100}% 0` });
|
|
57
|
+
}
|
|
58
|
+
return { mask, text };
|
|
59
|
+
}
|
package/dist/engine/tick.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ import type { AnimationEngineInstance } from "./instance.js";
|
|
|
7
7
|
export type AnimationTickStatus = "ok" | "lyrics-missing";
|
|
8
8
|
export declare function resolveTickOptions(options: TickOptions): ResolvedTickOptions;
|
|
9
9
|
export declare function tickView(engine: AnimationEngineInstance, reportedTimeS: number, options: ResolvedTickOptions): AnimationTickStatus;
|
|
10
|
-
|
|
10
|
+
/** Returns whether it stopped lines that only a tick starts again; see `restartContextSweeps`. */
|
|
11
|
+
export declare function relayout(engine: AnimationEngineInstance, linesAreRendered: boolean): boolean;
|
|
11
12
|
export declare function cancelLyricPositionUpdate(engine: AnimationEngineInstance): void;
|
|
12
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;
|
|
13
16
|
export declare function scheduleLyricPositionUpdate(engine: AnimationEngineInstance, isViewRendering: () => boolean, retick: () => void): void;
|
package/dist/engine/tick.js
CHANGED
|
@@ -7,8 +7,9 @@ import { advancePlaybackClock, lyricClockShiftS, NO_PLAYER_SNAPSHOT, playbackClo
|
|
|
7
7
|
import { getCSSDurationInMs } from "./cssValues.js";
|
|
8
8
|
import { clearOffscreenLineCulling, clearVisibleLyricWillChange, setupLineCullObserver, updateVisibleLyricWillChange, } from "./culling.js";
|
|
9
9
|
import { captureDecorationSlide, lineDecorators } from "./decorationSlides.js";
|
|
10
|
+
import { resetLineAnimationState } from "./lineAnimationState.js";
|
|
10
11
|
import { driveLineAnimations } from "./lineLifecycle.js";
|
|
11
|
-
import {
|
|
12
|
+
import { clearLineScrolls, dropPendingLineScroll, measureTrailingItem } from "./lineScroll.js";
|
|
12
13
|
import { hasNoLyricsPlaceholder, hasUnsyncedLyrics, startPassiveScrollLoop, stopPassiveScrollLoop, } from "./passiveScroll.js";
|
|
13
14
|
import { applyScrollPadding, measureScrollViewport, setupTabRendererObserver } from "./scrollViewport.js";
|
|
14
15
|
import { applyStage, measureStage } from "./stageMotion.js";
|
|
@@ -144,7 +145,7 @@ function readScrollerBeforeWrites(engine) {
|
|
|
144
145
|
function stopLineScrolling(engine) {
|
|
145
146
|
dropPendingLineScroll(engine);
|
|
146
147
|
clearVisibleLyricWillChange(engine);
|
|
147
|
-
|
|
148
|
+
clearLineScrolls(engine);
|
|
148
149
|
}
|
|
149
150
|
function focusLines(engine, scrollTimeS, earlyScrollConsiderS) {
|
|
150
151
|
const lines = engine.lines;
|
|
@@ -185,31 +186,49 @@ function updateCreditsFocus(engine, lyricsElement, scrollTimeS) {
|
|
|
185
186
|
delete lyricsElement.dataset.creditsFocused;
|
|
186
187
|
return true;
|
|
187
188
|
}
|
|
189
|
+
/** Returns whether it stopped lines that only a tick starts again; see `restartContextSweeps`. */
|
|
188
190
|
export function relayout(engine, linesAreRendered) {
|
|
189
191
|
if (engine.layout === "stage") {
|
|
190
192
|
if (!linesAreRendered || !engine.lyricsContainer)
|
|
191
|
-
return;
|
|
193
|
+
return false;
|
|
192
194
|
engine.cachedCreditsItem = measureTrailingItem(engine.lyricsContainer, CREDITS_CLASS);
|
|
193
195
|
measureStage(engine);
|
|
194
|
-
return;
|
|
196
|
+
return restartContextSweeps(engine);
|
|
195
197
|
}
|
|
196
198
|
applyScrollPadding(engine);
|
|
197
199
|
const scrollElement = engine.host.getScrollElement();
|
|
198
200
|
if (scrollElement)
|
|
199
201
|
measureScrollViewport(engine, scrollElement);
|
|
200
202
|
if (!linesAreRendered)
|
|
201
|
-
return;
|
|
203
|
+
return false;
|
|
202
204
|
const lyricsElement = engine.lyricsContainer;
|
|
203
205
|
if (!lyricsElement)
|
|
204
|
-
return;
|
|
206
|
+
return false;
|
|
205
207
|
engine.lyricWidth = lyricsElement.clientWidth;
|
|
206
208
|
engine.lyricHeight = lyricsElement.clientHeight;
|
|
207
209
|
measureLinePositions(engine, lyricsElement);
|
|
210
|
+
const restarted = restartContextSweeps(engine);
|
|
208
211
|
engine.cachedCreditsItem = measureTrailingItem(lyricsElement, CREDITS_CLASS);
|
|
209
212
|
engine.cachedFooterItem = measureTrailingItem(lyricsElement, FOOTER_CLASS);
|
|
210
213
|
setupLineCullObserver(engine);
|
|
211
214
|
requestRescroll(engine);
|
|
212
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;
|
|
213
232
|
}
|
|
214
233
|
function measureLinePositions(engine, lyricsElement) {
|
|
215
234
|
clearOffscreenLineCulling(engine);
|
|
@@ -230,6 +249,11 @@ export function retickFromPlaybackClock(engine, buildTickOptions) {
|
|
|
230
249
|
const options = buildTickOptions(playbackClock.lastEventCreationTime, playbackClock.lastPlayState);
|
|
231
250
|
return tickView(engine, playbackClock.lastTime, resolveTickOptions(options));
|
|
232
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
|
+
}
|
|
233
257
|
export function scheduleLyricPositionUpdate(engine, isViewRendering, retick) {
|
|
234
258
|
if (engine.pendingLyricsUpdateFrame !== null)
|
|
235
259
|
return;
|
|
@@ -3,6 +3,5 @@ export declare const waveAnimationPools: WeakMap<Animation, Animation[]>;
|
|
|
3
3
|
export declare function acquireWaveAnimation(engine: AnimationEngineInstance, letterElement: HTMLElement, keyframes: Keyframe[], keyframeSignature: string, timing: {
|
|
4
4
|
duration: number;
|
|
5
5
|
delay: number;
|
|
6
|
-
endDelay: number;
|
|
7
6
|
fill: FillMode;
|
|
8
7
|
}): Animation;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { PartData } from "../inject.js";
|
|
2
2
|
import type { AnimationConfig } from "./animationConfig.js";
|
|
3
3
|
import type { AnimationEngineInstance } from "./instance.js";
|
|
4
|
-
export interface HeldPaint {
|
|
5
|
-
target: HTMLElement;
|
|
6
|
-
frame: Keyframe;
|
|
7
|
-
}
|
|
8
4
|
export declare function startWordAnimations(engine: AnimationEngineInstance, part: PartData, config: AnimationConfig, lyricTimeS: number, appliedTimingOffsetMs: number): void;
|
|
9
|
-
export declare function startWordExitAnimation(part: PartData, config: AnimationConfig
|
|
5
|
+
export declare function startWordExitAnimation(part: PartData, config: AnimationConfig): void;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { RTL_CLASS } from "../constants.js";
|
|
2
2
|
import { registerThemeSetting } from "../themeSettings.js";
|
|
3
|
-
import { correctedAnimationTimeMs,
|
|
4
|
-
import {
|
|
5
|
-
import { GECKO_REDRAW, GECKO_REDRAW_KEYFRAMES, GECKO_REDRAW_PERIOD_MS, LETTER_WAVE_CREST_OFFSET, planLetterMaskSweep, planLetterWave, swipeRamp, } from "./letterPlans.js";
|
|
3
|
+
import { correctedAnimationTimeMs, mirrorHighlightAnimations, followSongClock } from "./animationTiming.js";
|
|
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";
|
|
6
|
+
import { cellReachedAt, planCellSweep } from "./sweepPlans.js";
|
|
7
7
|
import { acquireWaveAnimation } from "./wavePool.js";
|
|
8
8
|
const SWIPE_LEAD_RATIO = registerThemeSetting("blyrics-swipe-lead-ratio", 0.1);
|
|
9
9
|
const SWIPE_DURATION_RATIO = registerThemeSetting("blyrics-swipe-duration-ratio", 1.6);
|
|
10
10
|
const LINE_SYNCED_WORD_CLASS = "blyrics-line-synced-word";
|
|
11
11
|
const INSTANT_MS = 1;
|
|
12
|
+
// The sweep holds a word's reveal in its own layers, so the word's own opacity is all that animates on it.
|
|
13
|
+
const SHOWN = [{ opacity: 1 }, { opacity: 1 }];
|
|
14
|
+
const FADE_IN = [{ opacity: 0 }, { opacity: 1 }];
|
|
15
|
+
const FADE_OUT = [{ opacity: 1 }, { opacity: 0 }];
|
|
12
16
|
export function startWordAnimations(engine, part, config, lyricTimeS, appliedTimingOffsetMs) {
|
|
13
17
|
resetPartAnimations(part);
|
|
14
18
|
const word = wordTimeline(engine, part, config, lyricTimeS, appliedTimingOffsetMs);
|
|
@@ -16,20 +20,18 @@ export function startWordAnimations(engine, part, config, lyricTimeS, appliedTim
|
|
|
16
20
|
? lineSyncedHighlight(word)
|
|
17
21
|
: richSyncedHighlight(word);
|
|
18
22
|
const motion = config.enabled.wordWobble ? [...wobble(word), ...letterWave(word)] : [];
|
|
19
|
-
part.animations = [...highlight, ...
|
|
23
|
+
part.animations = [...highlight, ...mirrorHighlightAnimations(part, highlight), ...motion];
|
|
20
24
|
}
|
|
21
|
-
export function startWordExitAnimation(part, config
|
|
25
|
+
export function startWordExitAnimation(part, config) {
|
|
22
26
|
resetPartAnimations(part);
|
|
23
27
|
const fades = config.enabled.highlightFade;
|
|
24
28
|
const durationMs = fades ? config.highlight.fadeOutDurationMs : INSTANT_MS;
|
|
25
|
-
const fadeOut = part.highlightElement.animate(
|
|
29
|
+
const fadeOut = part.highlightElement.animate(FADE_OUT, {
|
|
26
30
|
duration: durationMs,
|
|
27
31
|
easing: fades ? config.highlight.fadeOutEasing : "linear",
|
|
28
32
|
fill: "none",
|
|
29
33
|
});
|
|
30
|
-
|
|
31
|
-
const holds = heldPaint.map(({ target, frame }) => target.animate([frame, frame], { duration: durationMs, fill: "none" }));
|
|
32
|
-
part.animations = [fadeOut, ...mirrors, ...holds];
|
|
34
|
+
part.animations = [fadeOut, ...mirrorHighlightAnimations(part, [fadeOut])];
|
|
33
35
|
fadeOut.addEventListener("finish", () => resetPartAnimations(part), { once: true });
|
|
34
36
|
}
|
|
35
37
|
function wordTimeline(engine, part, config, lyricTimeS, appliedTimingOffsetMs) {
|
|
@@ -60,78 +62,100 @@ function glowShows(part, config) {
|
|
|
60
62
|
}
|
|
61
63
|
function richSyncedHighlight(word) {
|
|
62
64
|
const { part, config } = word;
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const show = part.highlightElement.animate(
|
|
65
|
+
const swipes = config.enabled.highlightSwipe;
|
|
66
|
+
const animations = swipes ? swipe(word) : [];
|
|
67
|
+
const show = part.highlightElement.animate(SHOWN, { duration: INSTANT_MS, easing: "linear", fill: "forwards" });
|
|
66
68
|
animations.push(followSong(word, show, scheduledTimeMs(word, word.elapsedMs, INSTANT_MS)));
|
|
67
69
|
if (glowShows(part, config))
|
|
68
|
-
animations.push(glow(word, word.glowDurationMs));
|
|
70
|
+
animations.push(...glow(word, word.glowDurationMs, swipes));
|
|
69
71
|
return animations;
|
|
70
72
|
}
|
|
71
73
|
function lineSyncedHighlight(word) {
|
|
72
74
|
const { part, config } = word;
|
|
73
75
|
const fades = config.enabled.highlightFade;
|
|
74
76
|
const durationMs = fades ? config.highlight.fadeInDurationMs : INSTANT_MS;
|
|
75
|
-
const fadeIn = part.highlightElement.animate(
|
|
77
|
+
const fadeIn = part.highlightElement.animate(FADE_IN, {
|
|
76
78
|
duration: durationMs,
|
|
77
79
|
easing: fades ? config.highlight.fadeInEasing : "linear",
|
|
78
80
|
fill: "forwards",
|
|
79
81
|
});
|
|
80
82
|
const animations = [followSong(word, fadeIn, scheduledTimeMs(word, word.elapsedMs, durationMs))];
|
|
81
83
|
if (glowShows(part, config))
|
|
82
|
-
animations.push(glow(word, config.highlight.glowMinDurationMs));
|
|
84
|
+
animations.push(...glow(word, config.highlight.glowMinDurationMs, false));
|
|
83
85
|
return animations;
|
|
84
86
|
}
|
|
85
87
|
function swipe(word) {
|
|
86
|
-
const { part,
|
|
88
|
+
const { part, swipeLeadMs, swipeDurationMs } = word;
|
|
87
89
|
const currentTimeMs = scheduledTimeMs(word, word.elapsedMs + swipeLeadMs, swipeDurationMs);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
90
|
+
return part.sweep ? compositedSwipe(word, part.sweep, currentTimeMs) : [];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Slides each cell's mask from where the swipe begins back to its resting place and its text the other
|
|
94
|
+
* way. Filled backwards because the resting pose is the lit one. Only the first mask's animation feeds
|
|
95
|
+
* the drift check; the others carry the same timing and would repeat it.
|
|
96
|
+
*/
|
|
97
|
+
function compositedSwipe(word, cells, currentTimeMs) {
|
|
98
|
+
const { part, config, swipeLeadMs, swipeDurationMs } = word;
|
|
97
99
|
const rtl = part.highlightElement.classList.contains(RTL_CLASS);
|
|
98
|
-
const
|
|
100
|
+
const timing = {
|
|
101
|
+
duration: swipeDurationMs,
|
|
102
|
+
easing: config.highlight.swipeEasing,
|
|
103
|
+
fill: "both",
|
|
104
|
+
};
|
|
99
105
|
const animations = [];
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
}));
|
|
106
|
+
cells.forEach((cell, index) => {
|
|
107
|
+
const span = cell.span ?? { start: index / cells.length, width: 1 / cells.length };
|
|
108
|
+
const plan = planCellSweep(swipeRamp(config), span, rtl);
|
|
109
|
+
if (!plan)
|
|
110
|
+
return;
|
|
111
|
+
for (const [element, keyframes] of [
|
|
112
|
+
[cell.mask, plan.mask],
|
|
113
|
+
[cell.text, plan.text],
|
|
114
|
+
]) {
|
|
115
|
+
const slide = element.animate(keyframes, timing);
|
|
116
|
+
animations.push(followSong(word, slide, currentTimeMs, { offsetMs: swipeLeadMs, skipDriftSample: animations.length > 0 }));
|
|
121
117
|
}
|
|
122
118
|
});
|
|
123
119
|
return animations;
|
|
124
120
|
}
|
|
125
|
-
function glow(word, durationMs) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
121
|
+
function glow(word, durationMs, followsSwipe) {
|
|
122
|
+
return word.part.sweep ? sweepGlow(word, word.part.sweep, durationMs, followsSwipe) : [];
|
|
123
|
+
}
|
|
124
|
+
// Where the shrinking radius reaches the tight halo's, as a fraction of the glow's eased progress.
|
|
125
|
+
const TIGHT_GLOW_AT = 0.6;
|
|
126
|
+
/**
|
|
127
|
+
* Stands in for a glow whose radius shrinks to nothing: the wide halo crossfades into the tight one
|
|
128
|
+
* while the radius would shrink between them, and the tight one then fades out. The keyframe offsets
|
|
129
|
+
* are in eased progress, since the glow's easing applies to the whole effect. Under a swipe each
|
|
130
|
+
* cell's glow starts when the edge reaches it, so a halo never shows ahead of its lit text. The wait
|
|
131
|
+
* is exact for a linear swipe and taken as linear for any other.
|
|
132
|
+
*/
|
|
133
|
+
function sweepGlow(word, cells, durationMs, followsSwipe) {
|
|
134
|
+
const { config, swipeLeadMs, swipeDurationMs } = word;
|
|
135
|
+
const fades = config.highlight.glowRestingInvisible;
|
|
136
|
+
const wide = fades
|
|
137
|
+
? [{ opacity: 1 }, { opacity: 0, offset: TIGHT_GLOW_AT }, { opacity: 0 }]
|
|
138
|
+
: [{ opacity: 1 }, { opacity: 1 }];
|
|
139
|
+
const tight = fades
|
|
140
|
+
? [{ opacity: 0 }, { opacity: 1, offset: TIGHT_GLOW_AT }, { opacity: 0 }]
|
|
141
|
+
: [{ opacity: 0 }, { opacity: 0 }];
|
|
142
|
+
return cells.flatMap((cell, cellIndex) => {
|
|
143
|
+
const span = cell.span ?? { start: cellIndex / cells.length, width: 1 / cells.length };
|
|
144
|
+
const delayMs = followsSwipe
|
|
145
|
+
? Math.max(0, cellReachedAt(swipeRamp(config), span) * swipeDurationMs - swipeLeadMs)
|
|
146
|
+
: 0;
|
|
147
|
+
const timing = {
|
|
148
|
+
delay: delayMs,
|
|
149
|
+
duration: durationMs,
|
|
150
|
+
easing: config.highlight.glowEasing,
|
|
151
|
+
fill: fades ? "none" : "forwards",
|
|
152
|
+
};
|
|
153
|
+
const currentTimeMs = scheduledTimeMs(word, word.elapsedMs, delayMs + durationMs);
|
|
154
|
+
return cell.glows.map((halo, index) => {
|
|
155
|
+
const fade = halo.glow.animate(index === 0 ? wide : tight, timing);
|
|
156
|
+
return followSong(word, fade, currentTimeMs, { skipDriftSample: true });
|
|
157
|
+
});
|
|
133
158
|
});
|
|
134
|
-
return followSong(word, animation, scheduledTimeMs(word, word.elapsedMs, durationMs));
|
|
135
159
|
}
|
|
136
160
|
function wobble(word) {
|
|
137
161
|
const { wobbleFrom, wobblePeak, wobblePeakOffset, wobblePeakEasing, wobbleSettle, wobbleSettleOffset } = word.config.word;
|
|
@@ -152,13 +176,14 @@ function letterWave(word) {
|
|
|
152
176
|
if (letterCount === 0)
|
|
153
177
|
return [];
|
|
154
178
|
const run = planLetterWaveRun(word, letterCount);
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
179
|
+
const glowLetterSets = glowShows(part, config)
|
|
180
|
+
? (part.sweep?.flatMap(cell => cell.glows.map(glow => glow.letters)) ?? [])
|
|
181
|
+
: [];
|
|
158
182
|
const animations = [];
|
|
159
|
-
floatLetters(word, run, part.letterElements,
|
|
160
|
-
floatLetters(word, run, part.highlightLetterElements,
|
|
161
|
-
|
|
183
|
+
floatLetters(word, run, part.letterElements, true, animations);
|
|
184
|
+
floatLetters(word, run, part.highlightLetterElements, false, animations);
|
|
185
|
+
for (const glowLetters of glowLetterSets)
|
|
186
|
+
floatLetters(word, run, glowLetters, false, animations);
|
|
162
187
|
return animations;
|
|
163
188
|
}
|
|
164
189
|
function planLetterWaveRun(word, letterCount) {
|
|
@@ -189,16 +214,13 @@ function planLetterWaveRun(word, letterCount) {
|
|
|
189
214
|
startAtMs: scheduledTimeMs(word, word.elapsedMs + headStartMs, headStartMs + lastWaveEndMs),
|
|
190
215
|
};
|
|
191
216
|
}
|
|
192
|
-
function floatLetters(word, run, letters,
|
|
217
|
+
function floatLetters(word, run, letters, isBaseText, animations) {
|
|
193
218
|
letters?.forEach((letterElement, index) => {
|
|
194
219
|
const wave = run.waves[index];
|
|
195
220
|
const delayMs = wave.delayMs + run.headStartMs;
|
|
196
|
-
if (delayMs >= endMs)
|
|
197
|
-
return;
|
|
198
221
|
const float = acquireWaveAnimation(word.engine, letterElement, run.keyframes, run.signature, {
|
|
199
222
|
duration: wave.durationMs,
|
|
200
223
|
delay: delayMs,
|
|
201
|
-
endDelay: Math.min(0, endMs - delayMs - wave.durationMs),
|
|
202
224
|
fill: "forwards",
|
|
203
225
|
});
|
|
204
226
|
const skipDriftSample = !isBaseText || index !== run.lastEndingWaveIndex;
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import type { PartData } from "./inject.js";
|
|
2
1
|
export declare const imageHighlights: import("./themeSettings.js").Setting;
|
|
3
|
-
export interface ImageHighlightLayers {
|
|
4
|
-
glow: HTMLElement;
|
|
5
|
-
glowLetters: HTMLElement[];
|
|
6
|
-
/** A separate inline layout host, only for runs that can fragment. */
|
|
7
|
-
highlight?: HTMLElement;
|
|
8
|
-
}
|
|
9
|
-
export declare function wrapImageHighlight(highlight: HTMLElement): ImageHighlightLayers | undefined;
|
|
10
|
-
/** Keep bidi ordering and inline fragments in the browser's normal text layout. An
|
|
11
|
-
* absolutely positioned copy inside an inline word cannot reproduce those fragments. */
|
|
12
|
-
export declare function alignImageGlowRun(run: HTMLElement, parts: PartData[]): void;
|
|
13
2
|
/** A single CSS url(), not gradients or an arbitrary list of background layers. */
|
|
14
3
|
export declare function imageURL(value: string): string | null;
|
|
15
4
|
export declare function refreshInstrumentalImages(container: HTMLElement | null, view: Window): void;
|
package/dist/imageHighlights.js
CHANGED
|
@@ -1,53 +1,7 @@
|
|
|
1
|
-
// Optional image paint, independent of HDR: a theme supplies the image and
|
|
2
|
-
//
|
|
3
|
-
// cannot be cut off by the karaoke mask. Both copies are driven by the engine's own animations.
|
|
1
|
+
// Optional image paint for the instrumental note, independent of HDR: a theme supplies the image and
|
|
2
|
+
// its dynamic range.
|
|
4
3
|
import { registerThemeSetting } from "./themeSettings.js";
|
|
5
4
|
export const imageHighlights = registerThemeSetting("blyrics-image-highlights", false, true);
|
|
6
|
-
export function wrapImageHighlight(highlight) {
|
|
7
|
-
if (!imageHighlights.getBooleanValue())
|
|
8
|
-
return;
|
|
9
|
-
const doc = highlight.ownerDocument;
|
|
10
|
-
const paint = doc.createElement("span");
|
|
11
|
-
paint.classList.add("blyrics-image-fill");
|
|
12
|
-
while (highlight.firstChild)
|
|
13
|
-
paint.appendChild(highlight.firstChild);
|
|
14
|
-
const glow = doc.createElement("span");
|
|
15
|
-
glow.classList.add("blyrics-image-glow");
|
|
16
|
-
glow.setAttribute("aria-hidden", "true");
|
|
17
|
-
glow.appendChild(paint.cloneNode(true));
|
|
18
|
-
highlight.classList.add("blyrics-image-highlight");
|
|
19
|
-
highlight.appendChild(glow);
|
|
20
|
-
highlight.appendChild(paint);
|
|
21
|
-
return { glow, glowLetters: Array.from(glow.querySelectorAll(".blyrics--letter")) };
|
|
22
|
-
}
|
|
23
|
-
/** Keep bidi ordering and inline fragments in the browser's normal text layout. An
|
|
24
|
-
* absolutely positioned copy inside an inline word cannot reproduce those fragments. */
|
|
25
|
-
export function alignImageGlowRun(run, parts) {
|
|
26
|
-
if (!imageHighlights.getBooleanValue())
|
|
27
|
-
return;
|
|
28
|
-
if (!run.parentElement?.classList.contains("blyrics-bidi-sensitive") &&
|
|
29
|
-
!run.querySelector(".blyrics-word-group-long"))
|
|
30
|
-
return;
|
|
31
|
-
const originals = Array.from(run.querySelectorAll(".blyrics-word-highlight"));
|
|
32
|
-
const byHighlight = new Map(parts.map(part => [part.highlightElement, part]));
|
|
33
|
-
const glowRun = run.cloneNode(true);
|
|
34
|
-
glowRun.classList.add("blyrics-image-glow-run");
|
|
35
|
-
const copies = glowRun.querySelectorAll(".blyrics-word-highlight");
|
|
36
|
-
originals.forEach((original, index) => {
|
|
37
|
-
const part = byHighlight.get(original);
|
|
38
|
-
if (!part?.imageLayers)
|
|
39
|
-
return;
|
|
40
|
-
const copy = copies[index];
|
|
41
|
-
copy.replaceChildren(part.imageLayers.glow);
|
|
42
|
-
part.imageLayers.highlight = copy;
|
|
43
|
-
// Non-fragmented groups in a mixed run can still wobble. Give their glow the
|
|
44
|
-
// identical group transform, rather than letting it drift from the sharp copy.
|
|
45
|
-
const group = original.parentElement;
|
|
46
|
-
if (group && part.wobbleElements.includes(group) && copy.parentElement)
|
|
47
|
-
part.wobbleElements.push(copy.parentElement);
|
|
48
|
-
});
|
|
49
|
-
run.parentElement.insertBefore(glowRun, run);
|
|
50
|
-
}
|
|
51
5
|
/** A single CSS url(), not gradients or an arbitrary list of background layers. */
|
|
52
6
|
export function imageURL(value) {
|
|
53
7
|
const match = /^url\(\s*(?:"([^"]*)"|'([^']*)'|([^\s'"()]+))\s*\)$/i.exec(value.trim());
|
package/dist/inject.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type ImageHighlightLayers } from "./imageHighlights.js";
|
|
2
1
|
import { type WordState } from "./constants.js";
|
|
3
2
|
import type { Lyric, LyricPart, LyricSyncType } from "./types.js";
|
|
4
3
|
export declare let disableRichsync: import("./themeSettings.js").Setting;
|
|
@@ -18,9 +17,46 @@ export interface AnimationData {
|
|
|
18
17
|
lyricElement: HTMLElement;
|
|
19
18
|
animations: Animation[];
|
|
20
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
|
+
/**
|
|
26
|
+
* One box of a word's sweep, run by the compositor: the whole word when it is its own inline-block
|
|
27
|
+
* box, or one letter of a word that flows inline. Its mask holds a static soft edge and slides one way
|
|
28
|
+
* 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.
|
|
32
|
+
*/
|
|
33
|
+
export interface SweepCell {
|
|
34
|
+
mask: HTMLElement;
|
|
35
|
+
text: HTMLElement;
|
|
36
|
+
letters?: HTMLElement[];
|
|
37
|
+
glows: SweepGlow[];
|
|
38
|
+
/** Where the cell sits along the word, as fractions of the word's width; equal shares if unset. */
|
|
39
|
+
span?: {
|
|
40
|
+
start: number;
|
|
41
|
+
width: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The sweep of a word that flows inline without letters: a word in a bidi-sensitive row or a long
|
|
46
|
+
* group whose script joins or whose letters are not split. Such a word can break across lines and
|
|
47
|
+
* shape with its neighbours, so no box of its own can hold the sweep. The engine places a cell over
|
|
48
|
+
* each box the word breaks into, drawing the word from a copy of its line, once the line is laid out.
|
|
49
|
+
*/
|
|
50
|
+
export interface SweepContext {
|
|
51
|
+
host?: HTMLElement;
|
|
52
|
+
placedAt?: string;
|
|
53
|
+
unplaced?: boolean;
|
|
54
|
+
}
|
|
21
55
|
export interface PartData extends AnimationData {
|
|
22
56
|
highlightElement: HTMLElement;
|
|
23
|
-
|
|
57
|
+
/** The sweep's cells in reading order. */
|
|
58
|
+
sweep?: SweepCell[];
|
|
59
|
+
sweepContext?: SweepContext;
|
|
24
60
|
letterElements?: HTMLElement[];
|
|
25
61
|
highlightLetterElements?: HTMLElement[];
|
|
26
62
|
wobbleElements: HTMLElement[];
|
|
@@ -41,6 +77,9 @@ export type LineData = {
|
|
|
41
77
|
} & AnimationData;
|
|
42
78
|
export declare function newLineData(lyricElement: HTMLElement, startTimeMs: number, durationMs: number): LineData;
|
|
43
79
|
export declare function applyDirection(element: HTMLElement, text: string): void;
|
|
80
|
+
/** Puts a copy of the cell's text into an element, returning its letters if the word is split. */
|
|
81
|
+
export type FillSweepText = (into: HTMLElement) => HTMLElement[] | undefined;
|
|
82
|
+
export declare function createSweepCell(doc: Document, host: HTMLElement, fill: FillSweepText): SweepCell;
|
|
44
83
|
export declare function createLyricsLine(doc: Document, parts: LyricPart[], line: LineData, lyricElement: HTMLElement, options?: {
|
|
45
84
|
splitBackgroundLine: boolean;
|
|
46
85
|
}): HTMLElement;
|