@braccato/core 1.20.1 → 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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.d.ts +11 -1
- package/dist/engine/culling.js +97 -24
- 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 +7 -3
- package/dist/engine/instance.js +6 -4
- package/dist/engine/letterPlans.d.ts +0 -11
- package/dist/engine/letterPlans.js +0 -41
- package/dist/engine/lineAnimationState.js +1 -4
- 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 +10 -19
- 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 +40 -10
- 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 +6 -5
- package/package.json +1 -1
- package/dist/engine/highlightKeyframes.d.ts +0 -8
- package/dist/engine/highlightKeyframes.js +0 -37
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const TOLERANCE_PX = 0.1;
|
|
2
|
+
const LONGEST_STOP_SPAN_MS = 100;
|
|
3
|
+
const SHORTEST_STOP_SPAN_MS = 1;
|
|
4
|
+
export function curveEndMs(curve) {
|
|
5
|
+
return curve.startMs + curve.durationMs;
|
|
6
|
+
}
|
|
7
|
+
export function isRunningAt(curve, timeMs) {
|
|
8
|
+
return curve.startMs <= timeMs && timeMs < curveEndMs(curve);
|
|
9
|
+
}
|
|
10
|
+
export function offsetAt(curves, timeMs, easingOf) {
|
|
11
|
+
return curves
|
|
12
|
+
.filter(curve => isRunningAt(curve, timeMs))
|
|
13
|
+
.reduce((sum, curve) => sum + easedOffset(curve, easingOf(curve.easing), timeMs), 0);
|
|
14
|
+
}
|
|
15
|
+
export function bakeMotion(curves, nowMs, easingOf) {
|
|
16
|
+
if (curves.length === 1)
|
|
17
|
+
return exactly(curves[0]);
|
|
18
|
+
const endsMs = [...new Set(curves.map(curveEndMs))].sort((a, b) => a - b);
|
|
19
|
+
const stops = [];
|
|
20
|
+
let fromMs = nowMs;
|
|
21
|
+
for (const toMs of endsMs) {
|
|
22
|
+
const running = curves
|
|
23
|
+
.filter(curve => curve.startMs <= fromMs && curveEndMs(curve) >= toMs)
|
|
24
|
+
.map(curve => ({ curve, easing: easingOf(curve.easing) }));
|
|
25
|
+
const path = timeMs => {
|
|
26
|
+
let offsetPx = 0;
|
|
27
|
+
for (const { curve, easing } of running)
|
|
28
|
+
offsetPx += easedOffset(curve, easing, timeMs);
|
|
29
|
+
return offsetPx;
|
|
30
|
+
};
|
|
31
|
+
const fromPx = path(fromMs);
|
|
32
|
+
if (stops.at(-1)?.offsetPx !== fromPx)
|
|
33
|
+
stops.push({ timeMs: fromMs, offsetPx: fromPx });
|
|
34
|
+
const spans = Math.ceil((toMs - fromMs) / LONGEST_STOP_SPAN_MS);
|
|
35
|
+
for (let span = 1; span <= spans; span++) {
|
|
36
|
+
const spanEndMs = fromMs + ((toMs - fromMs) * span) / spans;
|
|
37
|
+
appendStops(path, stops[stops.length - 1], { timeMs: spanEndMs, offsetPx: path(spanEndMs) }, stops);
|
|
38
|
+
}
|
|
39
|
+
fromMs = toMs;
|
|
40
|
+
}
|
|
41
|
+
const durationMs = endsMs[endsMs.length - 1] - nowMs;
|
|
42
|
+
const fullScalePx = Math.max(...stops.map(stop => Math.abs(stop.offsetPx))) || 1;
|
|
43
|
+
const easing = `linear(${stops
|
|
44
|
+
.map(({ timeMs, offsetPx }) => `${rounded(offsetPx / fullScalePx)} ${rounded((100 * (timeMs - nowMs)) / durationMs)}%`)
|
|
45
|
+
.join(", ")})`;
|
|
46
|
+
return {
|
|
47
|
+
keyframes: [
|
|
48
|
+
{ translate: translateOf(0), easing },
|
|
49
|
+
{ translate: translateOf(fullScalePx), easing: "linear" },
|
|
50
|
+
],
|
|
51
|
+
startMs: nowMs,
|
|
52
|
+
durationMs,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function appendStops(path, from, to, stops) {
|
|
56
|
+
const middleMs = (from.timeMs + to.timeMs) / 2;
|
|
57
|
+
const middle = { timeMs: middleMs, offsetPx: path(middleMs) };
|
|
58
|
+
const chordPx = (from.offsetPx + to.offsetPx) / 2;
|
|
59
|
+
if (Math.abs(middle.offsetPx - chordPx) <= TOLERANCE_PX || to.timeMs - from.timeMs <= SHORTEST_STOP_SPAN_MS) {
|
|
60
|
+
stops.push(to);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
appendStops(path, from, middle, stops);
|
|
64
|
+
appendStops(path, middle, to, stops);
|
|
65
|
+
}
|
|
66
|
+
function exactly(curve) {
|
|
67
|
+
return {
|
|
68
|
+
keyframes: [
|
|
69
|
+
{ translate: translateOf(curve.fromPx), easing: curve.easing },
|
|
70
|
+
{ translate: translateOf(curve.toPx), easing: curve.endEasing },
|
|
71
|
+
],
|
|
72
|
+
startMs: curve.startMs,
|
|
73
|
+
durationMs: curve.durationMs,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function easedOffset(curve, easing, timeMs) {
|
|
77
|
+
const progress = curve.durationMs > 0 ? Math.min(1, (timeMs - curve.startMs) / curve.durationMs) : 1;
|
|
78
|
+
return curve.fromPx + (curve.toPx - curve.fromPx) * easing(progress);
|
|
79
|
+
}
|
|
80
|
+
function translateOf(offsetPx) {
|
|
81
|
+
return `0px ${Math.round(offsetPx * 1000) / 1000}px`;
|
|
82
|
+
}
|
|
83
|
+
function rounded(value) {
|
|
84
|
+
return Math.round(value * 1e6) / 1e6;
|
|
85
|
+
}
|
|
@@ -4,14 +4,13 @@ import type { AnimationEngineInstance } from "./instance.js";
|
|
|
4
4
|
type LinePlacement = {
|
|
5
5
|
position: number;
|
|
6
6
|
height: number;
|
|
7
|
-
|
|
7
|
+
motionOffset: number;
|
|
8
8
|
};
|
|
9
9
|
export declare function clearOnScreenLyrics(engine: AnimationEngineInstance): boolean;
|
|
10
10
|
export declare function hasRenderedLines(engine: AnimationEngineInstance): boolean;
|
|
11
11
|
export declare function getRenderedLines(engine: AnimationEngineInstance): LineData[];
|
|
12
12
|
export declare function getRenderedSyncType(engine: AnimationEngineInstance): LyricSyncType;
|
|
13
13
|
export declare function clearLyrics(engine: AnimationEngineInstance): void;
|
|
14
|
-
export declare function lineScrollOffset(engine: AnimationEngineInstance, element: HTMLElement): number;
|
|
15
14
|
export declare function replaceRenderedLines(engine: AnimationEngineInstance, lines: LineData[], dropped: readonly LineData[], previousOf: ReadonlyMap<LineData, LineData>): void;
|
|
16
15
|
export declare function settleSwappedLines(engine: AnimationEngineInstance, before: ReadonlyMap<LineData, LinePlacement>, scrollTopBefore: number): void;
|
|
17
16
|
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ANIMATING_CLASS, CURRENT_LYRICS_CLASS } from "../constants.js";
|
|
2
|
-
import {
|
|
2
|
+
import { clearVisibleLyricWillChange, stopLineCulling } 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,11 +26,9 @@ 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
|
-
engine
|
|
31
|
-
engine.lineCullObserver = null;
|
|
32
|
-
clearOffscreenLineCulling(engine);
|
|
31
|
+
stopLineCulling(engine);
|
|
33
32
|
for (const line of engine.lines) {
|
|
34
33
|
resetLineAnimationState(line);
|
|
35
34
|
line.isSelected = false;
|
|
@@ -51,21 +50,13 @@ export function clearLyrics(engine) {
|
|
|
51
50
|
engine.waveAnimationPool.length = 0;
|
|
52
51
|
resetStage(engine);
|
|
53
52
|
}
|
|
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
53
|
export function replaceRenderedLines(engine, lines, dropped, previousOf) {
|
|
59
54
|
for (const [line, previous] of previousOf)
|
|
60
55
|
carrySelection(line, previous);
|
|
61
56
|
dropPendingLineScroll(engine);
|
|
62
57
|
const droppedElements = new Set(dropped.map(line => line.lyricElement));
|
|
63
|
-
for (const
|
|
64
|
-
|
|
65
|
-
continue;
|
|
66
|
-
record.animation.cancel();
|
|
67
|
-
removeLineScrollAnimation(engine, record);
|
|
68
|
-
}
|
|
58
|
+
for (const element of droppedElements)
|
|
59
|
+
stopElementMotion(engine, element);
|
|
69
60
|
for (const line of dropped) {
|
|
70
61
|
resetLineAnimationState(line);
|
|
71
62
|
line.isSelected = false;
|
|
@@ -116,9 +107,9 @@ export function settleSwappedLines(engine, before, scrollTopBefore) {
|
|
|
116
107
|
const was = before.get(line);
|
|
117
108
|
if (was === undefined || !isMeasured(was.position) || !isMeasured(line.position))
|
|
118
109
|
continue;
|
|
119
|
-
const onScreenShift = was.position + was.
|
|
110
|
+
const onScreenShift = was.position + was.motionOffset - line.position + appliedShift;
|
|
120
111
|
if (Math.abs(onScreenShift) >= DECORATION_MIN_SHIFT_PX)
|
|
121
|
-
slideElementBy(line.lyricElement, onScreenShift);
|
|
112
|
+
slideElementBy(engine, line.lyricElement, onScreenShift);
|
|
122
113
|
}
|
|
123
114
|
}
|
|
124
115
|
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
|
@@ -5,10 +5,11 @@ 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,
|
|
8
|
+
import { clearOffscreenLineCulling, clearVisibleLyricWillChange, setupLineCulling, updateLineCulling, 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";
|
|
@@ -100,9 +101,15 @@ function renderSyncedLyrics(engine, lyricsElement, playhead, options, now) {
|
|
|
100
101
|
clearVisibleLyricWillChange(engine);
|
|
101
102
|
return;
|
|
102
103
|
}
|
|
103
|
-
if (scroller
|
|
104
|
+
if (scroller) {
|
|
104
105
|
const pendingScrollTop = engine.pendingLineScroll?.toScrollTop ?? scroller.scrollTop;
|
|
105
|
-
|
|
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
113
|
}
|
|
107
114
|
else {
|
|
108
115
|
stopLineScrolling(engine);
|
|
@@ -144,7 +151,7 @@ function readScrollerBeforeWrites(engine) {
|
|
|
144
151
|
function stopLineScrolling(engine) {
|
|
145
152
|
dropPendingLineScroll(engine);
|
|
146
153
|
clearVisibleLyricWillChange(engine);
|
|
147
|
-
|
|
154
|
+
clearLineScrolls(engine);
|
|
148
155
|
}
|
|
149
156
|
function focusLines(engine, scrollTimeS, earlyScrollConsiderS) {
|
|
150
157
|
const lines = engine.lines;
|
|
@@ -185,31 +192,49 @@ function updateCreditsFocus(engine, lyricsElement, scrollTimeS) {
|
|
|
185
192
|
delete lyricsElement.dataset.creditsFocused;
|
|
186
193
|
return true;
|
|
187
194
|
}
|
|
195
|
+
/** Returns whether it stopped lines that only a tick starts again; see `restartContextSweeps`. */
|
|
188
196
|
export function relayout(engine, linesAreRendered) {
|
|
189
197
|
if (engine.layout === "stage") {
|
|
190
198
|
if (!linesAreRendered || !engine.lyricsContainer)
|
|
191
|
-
return;
|
|
199
|
+
return false;
|
|
192
200
|
engine.cachedCreditsItem = measureTrailingItem(engine.lyricsContainer, CREDITS_CLASS);
|
|
193
201
|
measureStage(engine);
|
|
194
|
-
return;
|
|
202
|
+
return restartContextSweeps(engine);
|
|
195
203
|
}
|
|
196
204
|
applyScrollPadding(engine);
|
|
197
205
|
const scrollElement = engine.host.getScrollElement();
|
|
198
206
|
if (scrollElement)
|
|
199
207
|
measureScrollViewport(engine, scrollElement);
|
|
200
208
|
if (!linesAreRendered)
|
|
201
|
-
return;
|
|
209
|
+
return false;
|
|
202
210
|
const lyricsElement = engine.lyricsContainer;
|
|
203
211
|
if (!lyricsElement)
|
|
204
|
-
return;
|
|
212
|
+
return false;
|
|
205
213
|
engine.lyricWidth = lyricsElement.clientWidth;
|
|
206
214
|
engine.lyricHeight = lyricsElement.clientHeight;
|
|
207
215
|
measureLinePositions(engine, lyricsElement);
|
|
216
|
+
const restarted = restartContextSweeps(engine);
|
|
208
217
|
engine.cachedCreditsItem = measureTrailingItem(lyricsElement, CREDITS_CLASS);
|
|
209
218
|
engine.cachedFooterItem = measureTrailingItem(lyricsElement, FOOTER_CLASS);
|
|
210
|
-
|
|
219
|
+
setupLineCulling(engine);
|
|
211
220
|
requestRescroll(engine);
|
|
212
221
|
engine.host.debug?.resize();
|
|
222
|
+
return restarted;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* A word drawn by sweep cells placed over its boxes needs them placed again once the layout moves.
|
|
226
|
+
* Stopping its line lets the next tick start it over at the same moment, which places them afresh.
|
|
227
|
+
* A paused view gets no next tick on its own, so whoever relayouts has to tick once it returns true.
|
|
228
|
+
*/
|
|
229
|
+
function restartContextSweeps(engine) {
|
|
230
|
+
let restarted = false;
|
|
231
|
+
for (const line of engine.lines) {
|
|
232
|
+
if (line.isAnimating && line.parts.some(part => part.sweepContext)) {
|
|
233
|
+
resetLineAnimationState(line);
|
|
234
|
+
restarted = true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return restarted;
|
|
213
238
|
}
|
|
214
239
|
function measureLinePositions(engine, lyricsElement) {
|
|
215
240
|
clearOffscreenLineCulling(engine);
|
|
@@ -230,6 +255,11 @@ export function retickFromPlaybackClock(engine, buildTickOptions) {
|
|
|
230
255
|
const options = buildTickOptions(playbackClock.lastEventCreationTime, playbackClock.lastPlayState);
|
|
231
256
|
return tickView(engine, playbackClock.lastTime, resolveTickOptions(options));
|
|
232
257
|
}
|
|
258
|
+
/** Ticks again at the time and with the options of the last tick, for a view that is not ticking itself. */
|
|
259
|
+
export function retickAtLastTime(engine) {
|
|
260
|
+
if (engine.lastTickOptions)
|
|
261
|
+
tickView(engine, playbackClock.lastTime, engine.lastTickOptions);
|
|
262
|
+
}
|
|
233
263
|
export function scheduleLyricPositionUpdate(engine, isViewRendering, retick) {
|
|
234
264
|
if (engine.pendingLyricsUpdateFrame !== null)
|
|
235
265
|
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;
|