@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
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { ROMANIZED_LYRICS_CLASS, TRANSLATED_LYRICS_CLASS } from "../constants.js";
|
|
2
|
+
import { addElementCurve, timelineNow } from "./elementMotion.js";
|
|
2
3
|
import { REDUCED_MOTION_QUERY } from "./motionPreference.js";
|
|
3
4
|
const DECORATION_SLIDE_MS = 350;
|
|
4
5
|
const DECORATION_SLIDE_EASING = "cubic-bezier(0.25, 1, 0.5, 1)";
|
|
5
6
|
export const DECORATION_MIN_SHIFT_PX = 0.5;
|
|
6
|
-
export function slideElementBy(element, dy) {
|
|
7
|
-
|
|
7
|
+
export function slideElementBy(engine, element, dy) {
|
|
8
|
+
addElementCurve(engine, element, {
|
|
9
|
+
kind: "slide",
|
|
10
|
+
startMs: timelineNow(engine),
|
|
11
|
+
durationMs: DECORATION_SLIDE_MS,
|
|
12
|
+
fromPx: dy,
|
|
13
|
+
toPx: 0,
|
|
14
|
+
easing: DECORATION_SLIDE_EASING,
|
|
15
|
+
endEasing: "linear",
|
|
16
|
+
});
|
|
8
17
|
}
|
|
9
18
|
export function decorationSlideAllowed(engine, container) {
|
|
10
19
|
if (engine.window.matchMedia(REDUCED_MOTION_QUERY).matches)
|
|
@@ -30,14 +39,14 @@ export function captureDecorationSlide(engine) {
|
|
|
30
39
|
for (const { line, position, decorations } of before) {
|
|
31
40
|
const lineShift = position - line.position;
|
|
32
41
|
if (Math.abs(lineShift) >= DECORATION_MIN_SHIFT_PX)
|
|
33
|
-
slideElementBy(line.lyricElement, lineShift);
|
|
42
|
+
slideElementBy(engine, line.lyricElement, lineShift);
|
|
34
43
|
for (const [element, was] of decorations) {
|
|
35
44
|
const now = line.decorations.get(element);
|
|
36
45
|
if (now === undefined)
|
|
37
46
|
continue;
|
|
38
47
|
const ownShift = was - now - lineShift;
|
|
39
48
|
if (Math.abs(ownShift) >= DECORATION_MIN_SHIFT_PX)
|
|
40
|
-
slideElementBy(element, ownShift);
|
|
49
|
+
slideElementBy(engine, element, ownShift);
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
52
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AnimationEngineInstance } from "./instance.js";
|
|
2
|
+
import { type MotionCurve } from "./motionCurves.js";
|
|
3
|
+
export type MotionKind = "scroll" | "slide";
|
|
4
|
+
export interface ElementCurve extends MotionCurve {
|
|
5
|
+
kind: MotionKind;
|
|
6
|
+
onEnd?: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface ElementMotion {
|
|
9
|
+
animation: Animation;
|
|
10
|
+
curves: ElementCurve[];
|
|
11
|
+
}
|
|
12
|
+
export declare function timelineNow(engine: AnimationEngineInstance): number;
|
|
13
|
+
export declare function addElementCurve(engine: AnimationEngineInstance, element: HTMLElement, curve: ElementCurve): void;
|
|
14
|
+
export declare function removeElementCurves(engine: AnimationEngineInstance, element: HTMLElement, kind: MotionKind): void;
|
|
15
|
+
export declare function stopElementMotion(engine: AnimationEngineInstance, element: HTMLElement): void;
|
|
16
|
+
export declare function stopAllElementMotion(engine: AnimationEngineInstance): void;
|
|
17
|
+
export declare function elementMotionOffsetPx(engine: AnimationEngineInstance, element: HTMLElement): number;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { bakeMotion, curveEndMs, offsetAt } from "./motionCurves.js";
|
|
2
|
+
const EASING_TABLE_STEPS = 128;
|
|
3
|
+
export function timelineNow(engine) {
|
|
4
|
+
const timelineTime = engine.document.timeline?.currentTime;
|
|
5
|
+
return typeof timelineTime === "number" ? timelineTime : Date.now();
|
|
6
|
+
}
|
|
7
|
+
export function addElementCurve(engine, element, curve) {
|
|
8
|
+
const nowMs = timelineNow(engine);
|
|
9
|
+
playCurves(engine, element, [...runningCurves(engine, element, nowMs), curve], nowMs);
|
|
10
|
+
}
|
|
11
|
+
export function removeElementCurves(engine, element, kind) {
|
|
12
|
+
const nowMs = timelineNow(engine);
|
|
13
|
+
const running = runningCurves(engine, element, nowMs);
|
|
14
|
+
if (!running.some(curve => curve.kind === kind))
|
|
15
|
+
return;
|
|
16
|
+
playCurves(engine, element, running.filter(curve => curve.kind !== kind), nowMs);
|
|
17
|
+
}
|
|
18
|
+
export function stopElementMotion(engine, element) {
|
|
19
|
+
const motion = engine.elementMotions.get(element);
|
|
20
|
+
if (!motion)
|
|
21
|
+
return;
|
|
22
|
+
engine.elementMotions.delete(element);
|
|
23
|
+
motion.animation.cancel();
|
|
24
|
+
for (const curve of motion.curves)
|
|
25
|
+
curve.onEnd?.();
|
|
26
|
+
}
|
|
27
|
+
export function stopAllElementMotion(engine) {
|
|
28
|
+
for (const element of [...engine.elementMotions.keys()])
|
|
29
|
+
stopElementMotion(engine, element);
|
|
30
|
+
}
|
|
31
|
+
export function elementMotionOffsetPx(engine, element) {
|
|
32
|
+
const motion = engine.elementMotions.get(element);
|
|
33
|
+
return motion ? offsetAt(motion.curves, timelineNow(engine), easingLookup(engine)) : 0;
|
|
34
|
+
}
|
|
35
|
+
function runningCurves(engine, element, nowMs) {
|
|
36
|
+
return (engine.elementMotions.get(element)?.curves ?? []).filter(curve => curveEndMs(curve) > nowMs);
|
|
37
|
+
}
|
|
38
|
+
function playCurves(engine, element, curves, nowMs) {
|
|
39
|
+
const previous = engine.elementMotions.get(element);
|
|
40
|
+
for (const curve of previous?.curves ?? [])
|
|
41
|
+
if (!curves.includes(curve))
|
|
42
|
+
curve.onEnd?.();
|
|
43
|
+
if (curves.length === 0) {
|
|
44
|
+
engine.elementMotions.delete(element);
|
|
45
|
+
previous?.animation.cancel();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const baked = bakeMotion(curves, nowMs, easingLookup(engine));
|
|
49
|
+
const animation = element.animate(baked.keyframes, { duration: baked.durationMs, easing: "linear", fill: "none" });
|
|
50
|
+
animation.startTime = baked.startMs;
|
|
51
|
+
const motion = { animation, curves };
|
|
52
|
+
engine.elementMotions.set(element, motion);
|
|
53
|
+
previous?.animation.cancel();
|
|
54
|
+
const settle = () => {
|
|
55
|
+
if (engine.elementMotions.get(element) !== motion)
|
|
56
|
+
return;
|
|
57
|
+
engine.elementMotions.delete(element);
|
|
58
|
+
for (const curve of curves)
|
|
59
|
+
curve.onEnd?.();
|
|
60
|
+
};
|
|
61
|
+
animation.addEventListener("finish", settle, { once: true });
|
|
62
|
+
animation.addEventListener("cancel", settle, { once: true });
|
|
63
|
+
}
|
|
64
|
+
function easingLookup(engine) {
|
|
65
|
+
return easing => {
|
|
66
|
+
let table = engine.easingTables.get(easing);
|
|
67
|
+
if (!table) {
|
|
68
|
+
table = sampleEasing(engine, easing);
|
|
69
|
+
engine.easingTables.set(easing, table);
|
|
70
|
+
}
|
|
71
|
+
return tableEasing(table);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function tableEasing(table) {
|
|
75
|
+
return progress => {
|
|
76
|
+
const position = Math.min(Math.max(progress, 0), 1) * EASING_TABLE_STEPS;
|
|
77
|
+
const step = Math.min(Math.floor(position), EASING_TABLE_STEPS - 1);
|
|
78
|
+
return table[step] + (table[step + 1] - table[step]) * (position - step);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function sampleEasing(engine, easing) {
|
|
82
|
+
const table = Float64Array.from({ length: EASING_TABLE_STEPS + 1 }, (_, step) => step / EASING_TABLE_STEPS);
|
|
83
|
+
const { KeyframeEffect: Effect, Animation: Player } = engine.window;
|
|
84
|
+
if (typeof Effect !== "function" || typeof Player !== "function")
|
|
85
|
+
return table;
|
|
86
|
+
try {
|
|
87
|
+
const effect = new Effect(null, null, { duration: EASING_TABLE_STEPS, easing, fill: "both" });
|
|
88
|
+
const player = new Player(effect, null);
|
|
89
|
+
for (let step = 0; step <= EASING_TABLE_STEPS; step++) {
|
|
90
|
+
player.currentTime = step;
|
|
91
|
+
table[step] = effect.getComputedTiming().progress ?? table[step];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
engine.host.log("Line motion easing could not be sampled, so it is treated as linear", easing, error);
|
|
96
|
+
}
|
|
97
|
+
return table;
|
|
98
|
+
}
|
package/dist/engine/glow.js
CHANGED
|
@@ -19,7 +19,7 @@ export function isGlowRestingInvisible(glowTo) {
|
|
|
19
19
|
}
|
|
20
20
|
export function suppressInvisibleWordGlows(engine, line, config) {
|
|
21
21
|
const containerGlowShows = config.highlight.glowContainerAlpha >= HALF_8BIT_ALPHA_STEP;
|
|
22
|
-
if (containerGlowShows
|
|
22
|
+
if (containerGlowShows) {
|
|
23
23
|
for (const part of line.parts)
|
|
24
24
|
part.glowSuppressed = false;
|
|
25
25
|
return;
|
|
@@ -2,9 +2,11 @@ import type { LineData } from "../inject.js";
|
|
|
2
2
|
import type { LyricsLayout, LyricsRendererHost, LyricSyncType, ResolvedTickOptions } from "../types.js";
|
|
3
3
|
import type { StageBox, StageMetrics } from "../stage.js";
|
|
4
4
|
import { type ScrollInsets } from "./scrollViewport.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ElementMotion } from "./elementMotion.js";
|
|
6
|
+
import type { LineScrollItem, PendingLineScroll, RunningLineScroll } from "./lineScroll.js";
|
|
6
7
|
import type { LineScrollTiming } from "./lineScrollStyle.js";
|
|
7
8
|
import type { AnimationSettings } from "./animationConfig.js";
|
|
9
|
+
import { type LineCulling } from "./culling.js";
|
|
8
10
|
/**
|
|
9
11
|
* Everything that belongs to a single rendered lyrics view: one scroll container, one selection,
|
|
10
12
|
* one set of pending scroll work.
|
|
@@ -55,14 +57,16 @@ export interface AnimationEngineInstance extends AnimEngineViewState {
|
|
|
55
57
|
cachedLineScrollTiming: Map<string, LineScrollTiming>;
|
|
56
58
|
tabRendererResizeObserver: ResizeObserver | null;
|
|
57
59
|
observedTabRenderer: HTMLElement | null;
|
|
58
|
-
|
|
60
|
+
runningLineScrolls: RunningLineScroll[];
|
|
61
|
+
elementMotions: Map<HTMLElement, ElementMotion>;
|
|
62
|
+
easingTables: Map<string, Float64Array>;
|
|
59
63
|
lineScrollAnimationToken: number;
|
|
60
64
|
pendingLineScroll: PendingLineScroll | null;
|
|
61
65
|
lineScrollElementTokens: WeakMap<HTMLElement, number>;
|
|
62
66
|
visibleWillChangeElements: Set<HTMLElement>;
|
|
63
67
|
culledLineElements: Set<HTMLElement>;
|
|
64
68
|
waveAnimationPool: Animation[];
|
|
65
|
-
|
|
69
|
+
lineCulling: LineCulling | null;
|
|
66
70
|
cachedDurations: Map<string, number>;
|
|
67
71
|
cachedCSSValues: Map<string, string>;
|
|
68
72
|
cachedAnimationSettings: AnimationSettings | null;
|
package/dist/engine/instance.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NO_SCROLL_INSETS } from "./scrollViewport.js";
|
|
2
2
|
import { REDUCED_MOTION_QUERY } from "./motionPreference.js";
|
|
3
3
|
import { clearStyleCaches } from "./cssValues.js";
|
|
4
|
+
import { stopLineCulling } from "./culling.js";
|
|
4
5
|
import { liveEngines } from "./liveViews.js";
|
|
5
6
|
import { stopPassiveScrollLoop } from "./passiveScroll.js";
|
|
6
7
|
import { cancelLyricPositionUpdate } from "./tick.js";
|
|
@@ -40,14 +41,16 @@ export function createAnimationEngineInstance(engineDocument, engineWindow, host
|
|
|
40
41
|
cachedLineScrollTiming: new Map(),
|
|
41
42
|
tabRendererResizeObserver: null,
|
|
42
43
|
observedTabRenderer: null,
|
|
43
|
-
|
|
44
|
+
runningLineScrolls: [],
|
|
45
|
+
elementMotions: new Map(),
|
|
46
|
+
easingTables: new Map(),
|
|
44
47
|
lineScrollAnimationToken: 0,
|
|
45
48
|
pendingLineScroll: null,
|
|
46
49
|
lineScrollElementTokens: new WeakMap(),
|
|
47
50
|
visibleWillChangeElements: new Set(),
|
|
48
51
|
culledLineElements: new Set(),
|
|
49
52
|
waveAnimationPool: [],
|
|
50
|
-
|
|
53
|
+
lineCulling: null,
|
|
51
54
|
cachedDurations: new Map(),
|
|
52
55
|
cachedCSSValues: new Map(),
|
|
53
56
|
cachedAnimationSettings: null,
|
|
@@ -75,8 +78,7 @@ export function createAnimationEngineInstance(engineDocument, engineWindow, host
|
|
|
75
78
|
engine.tabRendererResizeObserver?.disconnect();
|
|
76
79
|
engine.tabRendererResizeObserver = null;
|
|
77
80
|
engine.observedTabRenderer = null;
|
|
78
|
-
engine
|
|
79
|
-
engine.lineCullObserver = null;
|
|
81
|
+
stopLineCulling(engine);
|
|
80
82
|
stopPassiveScrollLoop(engine);
|
|
81
83
|
cancelLyricPositionUpdate(engine);
|
|
82
84
|
},
|
|
@@ -18,16 +18,6 @@ export interface LetterSwipeWindow {
|
|
|
18
18
|
end: number;
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
export interface LetterMaskKeyframe {
|
|
22
|
-
offset: number;
|
|
23
|
-
maskPosition: string;
|
|
24
|
-
}
|
|
25
|
-
export interface LetterMaskSweep {
|
|
26
|
-
keyframes: LetterMaskKeyframe[];
|
|
27
|
-
delayMs: number;
|
|
28
|
-
durationMs: number;
|
|
29
|
-
easing: string;
|
|
30
|
-
}
|
|
31
21
|
export interface LetterWaveTiming {
|
|
32
22
|
delayMs: number;
|
|
33
23
|
durationMs: number;
|
|
@@ -38,5 +28,4 @@ export declare const GECKO_REDRAW_KEYFRAMES: Keyframe[];
|
|
|
38
28
|
export declare const GECKO_REDRAW_PERIOD_MS = 200;
|
|
39
29
|
export declare function swipeRamp({ highlight }: AnimationConfig): SwipeRamp;
|
|
40
30
|
export declare function linearForwardSwipeWindows(swipe: SwipeRamp, letterCount: number, swipeDurationMs: number): LetterSwipeWindow[] | null;
|
|
41
|
-
export declare function planLetterMaskSweep(swipe: SwipeRamp, letterCount: number, swipeDurationMs: number, rtl: boolean): LetterMaskSweep[];
|
|
42
31
|
export declare function planLetterWave(swipe: SwipeRamp, letterCount: number, wordDurationMs: number, swipeDurationMs: number, swipeLeadMs: number, floatDurationMs: number): LetterWaveTiming[];
|
|
@@ -41,47 +41,6 @@ export function linearForwardSwipeWindows(swipe, letterCount, swipeDurationMs) {
|
|
|
41
41
|
}
|
|
42
42
|
return windows;
|
|
43
43
|
}
|
|
44
|
-
export function planLetterMaskSweep(swipe, letterCount, swipeDurationMs, rtl) {
|
|
45
|
-
const windows = linearForwardSwipeWindows({ ...swipe, easing: "linear" }, letterCount, swipeDurationMs);
|
|
46
|
-
if (!windows)
|
|
47
|
-
return [];
|
|
48
|
-
const maskSpan = letterCount + 2;
|
|
49
|
-
const maskPositionAt = (start, index) => {
|
|
50
|
-
const position = (0.5 * maskSpan - (start * letterCount - index)) / (maskSpan - 1);
|
|
51
|
-
return `${(rtl ? 1 - position : position) * 100}% 0%`;
|
|
52
|
-
};
|
|
53
|
-
const durationMs = swipeDurationMs > 0 ? swipeDurationMs : 1;
|
|
54
|
-
return windows.map((window, index) => {
|
|
55
|
-
const from = maskPositionAt(window.from.start, index);
|
|
56
|
-
const to = maskPositionAt(window.to.start, index);
|
|
57
|
-
return swipe.easing === "linear"
|
|
58
|
-
? windowedSweep(window, from, to)
|
|
59
|
-
: wholeSwipeSweep(window, from, to, durationMs, swipe.easing);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function windowedSweep(window, from, to) {
|
|
63
|
-
return {
|
|
64
|
-
keyframes: [
|
|
65
|
-
{ offset: 0, maskPosition: from },
|
|
66
|
-
{ offset: 1, maskPosition: to },
|
|
67
|
-
],
|
|
68
|
-
delayMs: window.delayMs,
|
|
69
|
-
durationMs: window.durationMs,
|
|
70
|
-
easing: "linear",
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function wholeSwipeSweep(window, from, to, swipeDurationMs, easing) {
|
|
74
|
-
const revealStart = clamp(window.delayMs / swipeDurationMs, 0, 1);
|
|
75
|
-
const revealEnd = clamp((window.delayMs + window.durationMs) / swipeDurationMs, 0, 1);
|
|
76
|
-
const keyframes = [{ offset: 0, maskPosition: from }];
|
|
77
|
-
if (revealStart > 0)
|
|
78
|
-
keyframes.push({ offset: revealStart, maskPosition: from });
|
|
79
|
-
if (revealEnd > revealStart)
|
|
80
|
-
keyframes.push({ offset: revealEnd, maskPosition: to });
|
|
81
|
-
if (revealEnd < 1)
|
|
82
|
-
keyframes.push({ offset: 1, maskPosition: to });
|
|
83
|
-
return { keyframes, delayMs: 0, durationMs: swipeDurationMs, easing };
|
|
84
|
-
}
|
|
85
44
|
export function planLetterWave(swipe, letterCount, wordDurationMs, swipeDurationMs, swipeLeadMs, floatDurationMs) {
|
|
86
45
|
const windows = linearForwardSwipeWindows({ ...swipe, easing: "linear" }, letterCount, swipeDurationMs);
|
|
87
46
|
if (!windows)
|
|
@@ -7,7 +7,6 @@ export function releasePart(part) {
|
|
|
7
7
|
part.wordState = WORD_STATE_UPCOMING;
|
|
8
8
|
part.lyricElement.setAttribute(WORD_STATE_ATTR, WORD_STATE_UPCOMING);
|
|
9
9
|
part.highlightElement.setAttribute(WORD_STATE_ATTR, WORD_STATE_UPCOMING);
|
|
10
|
-
part.imageLayers?.highlight?.setAttribute(WORD_STATE_ATTR, WORD_STATE_UPCOMING);
|
|
11
10
|
}
|
|
12
11
|
export function resetPartAnimations(part) {
|
|
13
12
|
for (const animation of part.animations) {
|
|
@@ -24,7 +23,7 @@ function resetLineAnimations(lineData) {
|
|
|
24
23
|
resetPartAnimations(part);
|
|
25
24
|
}
|
|
26
25
|
export function hasLineAnimations(lineData) {
|
|
27
|
-
return
|
|
26
|
+
return lineData.animations.length > 0 || lineData.parts.some(part => part.animations.length > 0);
|
|
28
27
|
}
|
|
29
28
|
export function markLineAnimationsStopped(lineData) {
|
|
30
29
|
lineData.isAnimating = false;
|
|
@@ -39,7 +38,6 @@ export function togglePartClass(part, className, force) {
|
|
|
39
38
|
part.lyricElement.classList.toggle(className, force);
|
|
40
39
|
if ("highlightElement" in part) {
|
|
41
40
|
part.highlightElement.classList.toggle(className, force);
|
|
42
|
-
part.imageLayers?.highlight?.classList.toggle(className, force);
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
export function setAnimationsPlayState(lineData, isPlaying) {
|
|
@@ -80,6 +78,5 @@ export function updateWordStates(lineData, currentTime) {
|
|
|
80
78
|
part.wordState = state;
|
|
81
79
|
part.lyricElement.setAttribute(WORD_STATE_ATTR, state);
|
|
82
80
|
part.highlightElement.setAttribute(WORD_STATE_ATTR, state);
|
|
83
|
-
part.imageLayers?.highlight?.setAttribute(WORD_STATE_ATTR, state);
|
|
84
81
|
}
|
|
85
82
|
}
|
|
@@ -2,4 +2,4 @@ import type { LineData } from "../inject.js";
|
|
|
2
2
|
import type { AnimationConfig } from "./animationConfig.js";
|
|
3
3
|
import type { AnimationEngineInstance } from "./instance.js";
|
|
4
4
|
export declare function startLineAnimations(engine: AnimationEngineInstance, line: LineData, config: AnimationConfig, lyricTimeS: number): void;
|
|
5
|
-
export declare function startLineExitAnimations(
|
|
5
|
+
export declare function startLineExitAnimations(line: LineData, config: AnimationConfig, lyricTimeS: number): void;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { correctedAnimationTimeMs, followSongClock } from "./animationTiming.js";
|
|
2
|
+
import { placeContextSweeps } from "./contextSweep.js";
|
|
2
3
|
import { suppressInvisibleWordGlows } from "./glow.js";
|
|
3
4
|
import { startInstrumentalAnimations, startInstrumentalExitAnimations } from "./instrumentalAnimations.js";
|
|
4
5
|
import { resetPartAnimations } from "./lineAnimationState.js";
|
|
5
6
|
import { startWordAnimations, startWordExitAnimation } from "./wordAnimations.js";
|
|
6
7
|
export function startLineAnimations(engine, line, config, lyricTimeS) {
|
|
7
8
|
const appliedTimingOffsetMs = engine.learnedAnimationTimingOffsetMs;
|
|
9
|
+
if (!isInstrumental(line))
|
|
10
|
+
placeContextSweeps(line, config);
|
|
8
11
|
startLineEntrance(engine, line, config, lyricTimeS, appliedTimingOffsetMs);
|
|
9
12
|
if (isInstrumental(line)) {
|
|
10
13
|
startInstrumentalAnimations(engine, line, config, lyricTimeS, appliedTimingOffsetMs);
|
|
@@ -14,8 +17,7 @@ export function startLineAnimations(engine, line, config, lyricTimeS) {
|
|
|
14
17
|
for (const part of line.parts)
|
|
15
18
|
startWordAnimations(engine, part, config, lyricTimeS, appliedTimingOffsetMs);
|
|
16
19
|
}
|
|
17
|
-
export function startLineExitAnimations(
|
|
18
|
-
const heldPaint = readImagePaintBeforeWrites(engine, line, lyricTimeS);
|
|
20
|
+
export function startLineExitAnimations(line, config, lyricTimeS) {
|
|
19
21
|
startLineExit(line, config);
|
|
20
22
|
if (isInstrumental(line)) {
|
|
21
23
|
startInstrumentalExitAnimations(line, config, lyricTimeS);
|
|
@@ -23,7 +25,7 @@ export function startLineExitAnimations(engine, line, config, lyricTimeS) {
|
|
|
23
25
|
}
|
|
24
26
|
for (const part of line.parts) {
|
|
25
27
|
if (lyricTimeS >= part.time)
|
|
26
|
-
startWordExitAnimation(part, config
|
|
28
|
+
startWordExitAnimation(part, config);
|
|
27
29
|
else
|
|
28
30
|
resetPartAnimations(part);
|
|
29
31
|
}
|
|
@@ -59,24 +61,3 @@ function startLineExit(line, config) {
|
|
|
59
61
|
line.animations = [exit];
|
|
60
62
|
exit.addEventListener("finish", () => resetPartAnimations(line), { once: true });
|
|
61
63
|
}
|
|
62
|
-
function readImagePaintBeforeWrites(engine, line, lyricTimeS) {
|
|
63
|
-
const heldPaint = new Map();
|
|
64
|
-
const styleOf = (element) => engine.window.getComputedStyle(element);
|
|
65
|
-
for (const part of line.parts) {
|
|
66
|
-
if (!part.imageLayers || lyricTimeS < part.time)
|
|
67
|
-
continue;
|
|
68
|
-
const glowStyle = styleOf(part.imageLayers.glow);
|
|
69
|
-
const paint = [
|
|
70
|
-
{ target: part.imageLayers.glow, frame: { opacity: glowStyle.opacity, filter: glowStyle.filter } },
|
|
71
|
-
];
|
|
72
|
-
for (const target of part.letterElements ?? []) {
|
|
73
|
-
paint.push({ target, frame: { transform: styleOf(target).transform } });
|
|
74
|
-
}
|
|
75
|
-
for (const target of [...(part.highlightLetterElements ?? []), ...part.imageLayers.glowLetters]) {
|
|
76
|
-
const letterStyle = styleOf(target);
|
|
77
|
-
paint.push({ target, frame: { maskPosition: letterStyle.maskPosition, transform: letterStyle.transform } });
|
|
78
|
-
}
|
|
79
|
-
heldPaint.set(part, paint);
|
|
80
|
-
}
|
|
81
|
-
return heldPaint;
|
|
82
|
-
}
|
|
@@ -63,7 +63,7 @@ function retireLine({ engine, lyricTimeS, playhead, config }, line, index, anima
|
|
|
63
63
|
resetLineAnimationState(line);
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
|
-
startLineExitAnimations(
|
|
66
|
+
startLineExitAnimations(line, config, lyricTimeS);
|
|
67
67
|
markLineAnimationsStopped(line);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -9,10 +9,10 @@ export interface LineScrollItem {
|
|
|
9
9
|
height: number;
|
|
10
10
|
position: number;
|
|
11
11
|
}
|
|
12
|
-
export interface
|
|
13
|
-
animation: Animation;
|
|
12
|
+
export interface RunningLineScroll {
|
|
14
13
|
lineElement: HTMLElement;
|
|
15
14
|
token: number;
|
|
15
|
+
durationMs: number;
|
|
16
16
|
}
|
|
17
17
|
export interface LineScrollRequest {
|
|
18
18
|
lines: LineScrollItem[];
|
|
@@ -28,8 +28,8 @@ interface PlannedLineScroll extends StyledScrollLine {
|
|
|
28
28
|
durationMs: number;
|
|
29
29
|
startEasing: string;
|
|
30
30
|
endEasing: string;
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
startPx: number;
|
|
32
|
+
endPx: number;
|
|
33
33
|
}
|
|
34
34
|
export interface PendingLineScroll {
|
|
35
35
|
plan: PlannedLineScroll[];
|
|
@@ -40,8 +40,7 @@ export interface PendingLineScroll {
|
|
|
40
40
|
export declare function commitOrPrepareLineScroll(engine: AnimationEngineInstance, request: LineScrollRequest): void;
|
|
41
41
|
export declare function prepareUpcomingLineScroll(engine: AnimationEngineInstance, request: LineScrollRequest): void;
|
|
42
42
|
export declare function dropPendingLineScroll(engine: AnimationEngineInstance): void;
|
|
43
|
-
export declare function
|
|
44
|
-
export declare function clearLineScrollAnimations(engine: AnimationEngineInstance): void;
|
|
43
|
+
export declare function clearLineScrolls(engine: AnimationEngineInstance): void;
|
|
45
44
|
export declare function isLineVisibleDuringScroll(line: LineScrollItem, fromScrollTop: number, toScrollTop: number, viewportHeight: number): boolean;
|
|
46
45
|
export declare function getLineScrollItems(engine: AnimationEngineInstance, lines: LineData[]): LineScrollItem[];
|
|
47
46
|
export declare function measureTrailingItem(lyricsElement: HTMLElement, className: string): LineScrollItem | null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getRelativeLayoutBounds } from "../util.js";
|
|
2
|
+
import { addElementCurve, removeElementCurves, timelineNow } from "./elementMotion.js";
|
|
2
3
|
import { clearScrollVariables, resolveScrollTimings, resolveThemedTranslates, themeOverridesScrollTranslate, writeScrollVariables, } from "./lineScrollStyle.js";
|
|
3
4
|
export const SCROLL_PREPARE_LEAD_MS = 120;
|
|
4
5
|
export const LINE_SCROLL_WILL_CHANGE_VALUE = "transform, translate";
|
|
@@ -56,7 +57,15 @@ function planLineScroll(engine, request) {
|
|
|
56
57
|
const side = scrollSide(relativeIndex, deltaPx);
|
|
57
58
|
const timingKey = `${side}|${Math.abs(relativeIndex)}`;
|
|
58
59
|
const cachedTiming = engine.cachedLineScrollTiming.get(timingKey);
|
|
59
|
-
targets.push({
|
|
60
|
+
targets.push({
|
|
61
|
+
lineElement,
|
|
62
|
+
side,
|
|
63
|
+
heightPx: line.height,
|
|
64
|
+
token: claimLine(engine, lineElement),
|
|
65
|
+
relativeIndex,
|
|
66
|
+
timingKey,
|
|
67
|
+
cachedTiming,
|
|
68
|
+
});
|
|
60
69
|
if (translateThemed || !cachedTiming) {
|
|
61
70
|
writeScrollVariables(lineElement, { index, activeIndex, relativeIndex, side, deltaPx });
|
|
62
71
|
}
|
|
@@ -76,8 +85,8 @@ function planLineScroll(engine, request) {
|
|
|
76
85
|
: activeDurationMs + (timing.durationMs - activeDurationMs) * staggerScale,
|
|
77
86
|
startEasing: timing.startEasing,
|
|
78
87
|
endEasing: timing.endEasing,
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
startPx: translates?.start[index] ?? deltaPx,
|
|
89
|
+
endPx: translates?.end[index] ?? 0,
|
|
81
90
|
};
|
|
82
91
|
});
|
|
83
92
|
}
|
|
@@ -111,14 +120,22 @@ function staggerScaleKeepingLinesApart(lines, activeIndex, distancePx, continues
|
|
|
111
120
|
return Math.min(1, stepPx / distancePx);
|
|
112
121
|
}
|
|
113
122
|
function startLineScroll(engine, plan) {
|
|
123
|
+
const startMs = timelineNow(engine);
|
|
114
124
|
for (const line of plan) {
|
|
115
125
|
if (!line.lineElement.isConnected || !ownsLine(engine, line.lineElement, line.token))
|
|
116
126
|
continue;
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
127
|
+
const scroll = { lineElement: line.lineElement, token: line.token, durationMs: line.durationMs };
|
|
128
|
+
engine.runningLineScrolls.push(scroll);
|
|
129
|
+
addElementCurve(engine, line.lineElement, {
|
|
130
|
+
kind: "scroll",
|
|
131
|
+
startMs,
|
|
132
|
+
durationMs: line.durationMs,
|
|
133
|
+
fromPx: line.startPx,
|
|
134
|
+
toPx: line.endPx,
|
|
135
|
+
easing: line.startEasing,
|
|
136
|
+
endEasing: line.endEasing,
|
|
137
|
+
onEnd: () => endLineScroll(engine, scroll),
|
|
138
|
+
});
|
|
122
139
|
}
|
|
123
140
|
}
|
|
124
141
|
function claimLine(engine, lineElement) {
|
|
@@ -135,25 +152,18 @@ function releaseLine(engine, lineElement, token) {
|
|
|
135
152
|
clearScrollVariables(lineElement);
|
|
136
153
|
engine.lineScrollElementTokens.delete(lineElement);
|
|
137
154
|
}
|
|
138
|
-
function
|
|
139
|
-
const
|
|
140
|
-
engine.lineScrollAnimations.push(record);
|
|
141
|
-
animation.addEventListener("finish", () => removeLineScrollAnimation(engine, record), { once: true });
|
|
142
|
-
animation.addEventListener("cancel", () => removeLineScrollAnimation(engine, record), { once: true });
|
|
143
|
-
}
|
|
144
|
-
export function removeLineScrollAnimation(engine, record) {
|
|
145
|
-
const index = engine.lineScrollAnimations.indexOf(record);
|
|
155
|
+
function endLineScroll(engine, scroll) {
|
|
156
|
+
const index = engine.runningLineScrolls.indexOf(scroll);
|
|
146
157
|
if (index !== -1)
|
|
147
|
-
engine.
|
|
148
|
-
releaseLine(engine,
|
|
149
|
-
}
|
|
150
|
-
export function
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
158
|
+
engine.runningLineScrolls.splice(index, 1);
|
|
159
|
+
releaseLine(engine, scroll.lineElement, scroll.token);
|
|
160
|
+
}
|
|
161
|
+
export function clearLineScrolls(engine) {
|
|
162
|
+
const scrolledElements = new Set(engine.runningLineScrolls.map(scroll => scroll.lineElement));
|
|
163
|
+
for (const element of scrolledElements)
|
|
164
|
+
removeElementCurves(engine, element, "scroll");
|
|
165
|
+
for (const scroll of [...engine.runningLineScrolls])
|
|
166
|
+
endLineScroll(engine, scroll);
|
|
157
167
|
}
|
|
158
168
|
export function isLineVisibleDuringScroll(line, fromScrollTop, toScrollTop, viewportHeight) {
|
|
159
169
|
const visibleTop = Math.min(fromScrollTop, toScrollTop);
|
|
@@ -10,6 +10,9 @@ export interface StyledScrollLine {
|
|
|
10
10
|
lineElement: HTMLElement;
|
|
11
11
|
side: LineScrollSide;
|
|
12
12
|
}
|
|
13
|
+
interface SizedScrollLine extends StyledScrollLine {
|
|
14
|
+
heightPx: number;
|
|
15
|
+
}
|
|
13
16
|
export interface ScrollVariables {
|
|
14
17
|
index: number;
|
|
15
18
|
activeIndex: number;
|
|
@@ -21,7 +24,9 @@ export declare function themeOverridesScrollTranslate(): boolean;
|
|
|
21
24
|
export declare function writeScrollVariables(lineElement: HTMLElement, variables: ScrollVariables): void;
|
|
22
25
|
export declare function clearScrollVariables(lineElement: HTMLElement): void;
|
|
23
26
|
export declare function resolveScrollTimings(engine: AnimationEngineInstance, lines: StyledScrollLine[], { lineScroll }: AnimationConfig): LineScrollTiming[];
|
|
24
|
-
export declare function resolveThemedTranslates(engine: AnimationEngineInstance, lines:
|
|
25
|
-
start:
|
|
26
|
-
end:
|
|
27
|
+
export declare function resolveThemedTranslates(engine: AnimationEngineInstance, lines: SizedScrollLine[], { lineScroll }: AnimationConfig): {
|
|
28
|
+
start: (number | null)[];
|
|
29
|
+
end: (number | null)[];
|
|
27
30
|
};
|
|
31
|
+
export declare function translateYPx(translate: string, heightPx: number): number | null;
|
|
32
|
+
export {};
|
|
@@ -93,12 +93,26 @@ export function resolveThemedTranslates(engine, lines, { lineScroll }) {
|
|
|
93
93
|
const translatesAt = (keyframe) => batchProbeComputedStyle(engine, lines, "translate", line => {
|
|
94
94
|
const fallback = keyframe === "start" ? "var(--blyrics-line-scroll-delta-px, 0px)" : "0px";
|
|
95
95
|
return `0 ${scrollVariable(`translate-y-${keyframe}`, line.side, lineScroll.differentialEffects, fallback)}`;
|
|
96
|
-
}, style =>
|
|
96
|
+
}, style => style.translate).map((translate, index) => translateYPx(translate, lines[index].heightPx));
|
|
97
97
|
return { start: translatesAt("start"), end: translatesAt("end") };
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
const
|
|
101
|
-
|
|
99
|
+
export function translateYPx(translate, heightPx) {
|
|
100
|
+
const value = translate.trim();
|
|
101
|
+
if (value === "" || value === "none")
|
|
102
|
+
return 0;
|
|
103
|
+
const [, y = "0px"] = value.match(/calc\([^)]*\)|\S+/g) ?? [];
|
|
104
|
+
const terms = y
|
|
105
|
+
.replace(/^calc\((.*)\)$/, "$1")
|
|
106
|
+
.replace(/\s+-\s+/g, " + -")
|
|
107
|
+
.split(/\s+\+\s+/);
|
|
108
|
+
let px = 0;
|
|
109
|
+
for (const term of terms) {
|
|
110
|
+
const length = term.trim().match(/^(-?[\d.]+(?:e-?\d+)?)(px|%)?$/);
|
|
111
|
+
if (!length || (length[2] === undefined && Number(length[1]) !== 0))
|
|
112
|
+
return null;
|
|
113
|
+
px += length[2] === "%" ? (Number(length[1]) * heightPx) / 100 : Number(length[1]);
|
|
114
|
+
}
|
|
115
|
+
return px;
|
|
102
116
|
}
|
|
103
117
|
function batchProbeComputedStyle(engine, lines, property, probeValue, readValue) {
|
|
104
118
|
const previous = lines.map(({ lineElement }) => ({
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface MotionCurve {
|
|
2
|
+
startMs: number;
|
|
3
|
+
durationMs: number;
|
|
4
|
+
fromPx: number;
|
|
5
|
+
toPx: number;
|
|
6
|
+
easing: string;
|
|
7
|
+
endEasing: string;
|
|
8
|
+
}
|
|
9
|
+
export type Easing = (progress: number) => number;
|
|
10
|
+
export type EasingLookup = (easing: string) => Easing;
|
|
11
|
+
export interface BakedMotion {
|
|
12
|
+
keyframes: Keyframe[];
|
|
13
|
+
startMs: number;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function curveEndMs(curve: MotionCurve): number;
|
|
17
|
+
export declare function isRunningAt(curve: MotionCurve, timeMs: number): boolean;
|
|
18
|
+
export declare function offsetAt(curves: readonly MotionCurve[], timeMs: number, easingOf: EasingLookup): number;
|
|
19
|
+
export declare function bakeMotion(curves: readonly MotionCurve[], nowMs: number, easingOf: EasingLookup): BakedMotion;
|