@braccato/core 1.21.3 → 1.21.4
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnimationEngineInstance } from "./instance.js";
|
|
2
|
-
import { type MotionCurve } from "./motionCurves.js";
|
|
2
|
+
import { type EasingLookup, type MotionCurve } from "./motionCurves.js";
|
|
3
3
|
export type MotionKind = "scroll" | "slide";
|
|
4
4
|
export interface ElementCurve extends MotionCurve {
|
|
5
5
|
kind: MotionKind;
|
|
@@ -15,3 +15,4 @@ export declare function removeElementCurves(engine: AnimationEngineInstance, ele
|
|
|
15
15
|
export declare function stopElementMotion(engine: AnimationEngineInstance, element: HTMLElement): void;
|
|
16
16
|
export declare function stopAllElementMotion(engine: AnimationEngineInstance): void;
|
|
17
17
|
export declare function elementMotionOffsetPx(engine: AnimationEngineInstance, element: HTMLElement): number;
|
|
18
|
+
export declare function easingLookup(engine: AnimationEngineInstance): EasingLookup;
|
|
@@ -61,7 +61,7 @@ function playCurves(engine, element, curves, nowMs) {
|
|
|
61
61
|
animation.addEventListener("finish", settle, { once: true });
|
|
62
62
|
animation.addEventListener("cancel", settle, { once: true });
|
|
63
63
|
}
|
|
64
|
-
function easingLookup(engine) {
|
|
64
|
+
export function easingLookup(engine) {
|
|
65
65
|
return easing => {
|
|
66
66
|
let table = engine.easingTables.get(easing);
|
|
67
67
|
if (!table) {
|
|
@@ -24,6 +24,8 @@ export declare function cellFade(swipe: SwipeRamp, span: CellSpan): number;
|
|
|
24
24
|
* the cell's halo would show behind the edge before any of its text is lit, so its glow waits.
|
|
25
25
|
*/
|
|
26
26
|
export declare function cellReachedAt(swipe: SwipeRamp, span: CellSpan): number;
|
|
27
|
+
/** How far through the swipe, in eased progress, its start stop reaches the end of a cell. */
|
|
28
|
+
export declare function cellLitAt(swipe: SwipeRamp, span: CellSpan): number;
|
|
27
29
|
/**
|
|
28
30
|
* Plans one cell of a sweep. In the cell's own widths the start stop runs from
|
|
29
31
|
* `(startFrom - span.start) / span.width` to `(startTo - span.start) / span.width`, and the cell only
|
|
@@ -25,8 +25,15 @@ export function cellFade(swipe, span) {
|
|
|
25
25
|
* the cell's halo would show behind the edge before any of its text is lit, so its glow waits.
|
|
26
26
|
*/
|
|
27
27
|
export function cellReachedAt(swipe, span) {
|
|
28
|
+
return startStopReaches(swipe, span.start);
|
|
29
|
+
}
|
|
30
|
+
/** How far through the swipe, in eased progress, its start stop reaches the end of a cell. */
|
|
31
|
+
export function cellLitAt(swipe, span) {
|
|
32
|
+
return startStopReaches(swipe, span.start + span.width);
|
|
33
|
+
}
|
|
34
|
+
function startStopReaches(swipe, position) {
|
|
28
35
|
const stops = swipeStops(swipe);
|
|
29
|
-
return stops ? clamp((
|
|
36
|
+
return stops ? clamp((position - stops.startFrom) / (stops.startTo - stops.startFrom), 0, 1) : 0;
|
|
30
37
|
}
|
|
31
38
|
/**
|
|
32
39
|
* Plans one cell of a sweep. In the cell's own widths the start stop runs from
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RTL_CLASS } from "../constants.js";
|
|
2
2
|
import { registerThemeSetting } from "../themeSettings.js";
|
|
3
3
|
import { correctedAnimationTimeMs, mirrorHighlightAnimations, followSongClock } from "./animationTiming.js";
|
|
4
|
+
import { easingLookup } from "./elementMotion.js";
|
|
4
5
|
import { GECKO_REDRAW, GECKO_REDRAW_KEYFRAMES, GECKO_REDRAW_PERIOD_MS, LETTER_WAVE_CREST_OFFSET, planLetterWave, swipeRamp, } from "./letterPlans.js";
|
|
5
6
|
import { resetPartAnimations } from "./lineAnimationState.js";
|
|
6
|
-
import { cellReachedAt, planCellSweep } from "./sweepPlans.js";
|
|
7
|
+
import { cellLitAt, cellReachedAt, planCellSweep } from "./sweepPlans.js";
|
|
7
8
|
import { acquireWaveAnimation } from "./wavePool.js";
|
|
8
9
|
const SWIPE_LEAD_RATIO = registerThemeSetting("blyrics-swipe-lead-ratio", 0.1);
|
|
9
10
|
const SWIPE_DURATION_RATIO = registerThemeSetting("blyrics-swipe-duration-ratio", 1.6);
|
|
@@ -13,6 +14,8 @@ const INSTANT_MS = 1;
|
|
|
13
14
|
const SHOWN = [{ opacity: 1 }, { opacity: 1 }];
|
|
14
15
|
const FADE_IN = [{ opacity: 0 }, { opacity: 1 }];
|
|
15
16
|
const FADE_OUT = [{ opacity: 1 }, { opacity: 0 }];
|
|
17
|
+
// A line's exit leaves the started ones running so a glow fades out under the text instead of cutting off.
|
|
18
|
+
const glowDelaysMs = new WeakMap();
|
|
16
19
|
export function startWordAnimations(engine, part, config, lyricTimeS, appliedTimingOffsetMs) {
|
|
17
20
|
resetPartAnimations(part);
|
|
18
21
|
const word = wordTimeline(engine, part, config, lyricTimeS, appliedTimingOffsetMs);
|
|
@@ -23,6 +26,8 @@ export function startWordAnimations(engine, part, config, lyricTimeS, appliedTim
|
|
|
23
26
|
part.animations = [...highlight, ...mirrorHighlightAnimations(part, highlight), ...motion];
|
|
24
27
|
}
|
|
25
28
|
export function startWordExitAnimation(part, config) {
|
|
29
|
+
const glows = part.animations.filter(animation => glowStarted(animation));
|
|
30
|
+
part.animations = part.animations.filter(animation => !glows.includes(animation));
|
|
26
31
|
resetPartAnimations(part);
|
|
27
32
|
const fades = config.enabled.highlightFade;
|
|
28
33
|
const durationMs = fades ? config.highlight.fadeOutDurationMs : INSTANT_MS;
|
|
@@ -31,9 +36,13 @@ export function startWordExitAnimation(part, config) {
|
|
|
31
36
|
easing: fades ? config.highlight.fadeOutEasing : "linear",
|
|
32
37
|
fill: "none",
|
|
33
38
|
});
|
|
34
|
-
part.animations = [fadeOut, ...mirrorHighlightAnimations(part, [fadeOut])];
|
|
39
|
+
part.animations = [fadeOut, ...mirrorHighlightAnimations(part, [fadeOut]), ...glows];
|
|
35
40
|
fadeOut.addEventListener("finish", () => resetPartAnimations(part), { once: true });
|
|
36
41
|
}
|
|
42
|
+
function glowStarted(animation) {
|
|
43
|
+
const delayMs = glowDelaysMs.get(animation);
|
|
44
|
+
return delayMs !== undefined && Number(animation.currentTime) >= delayMs;
|
|
45
|
+
}
|
|
37
46
|
function wordTimeline(engine, part, config, lyricTimeS, appliedTimingOffsetMs) {
|
|
38
47
|
const durationMs = Math.max(0, part.duration * 1000);
|
|
39
48
|
return {
|
|
@@ -123,27 +132,27 @@ function glow(word, durationMs, followsSwipe) {
|
|
|
123
132
|
}
|
|
124
133
|
// Where the shrinking radius reaches the tight halo's, as a fraction of the glow's eased progress.
|
|
125
134
|
const TIGHT_GLOW_AT = 0.6;
|
|
135
|
+
// The latest a halo may finish rising, so the crossfade after it keeps room to run.
|
|
136
|
+
const LATEST_GLOW_PEAK = TIGHT_GLOW_AT / 2;
|
|
126
137
|
/**
|
|
127
138
|
* Stands in for a glow whose radius shrinks to nothing: the wide halo crossfades into the tight one
|
|
128
139
|
* while the radius would shrink between them, and the tight one then fades out. The keyframe offsets
|
|
129
140
|
* 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
|
|
131
|
-
*
|
|
141
|
+
* cell's glow starts when the edge reaches it and rises while the edge crosses it, the way a glow
|
|
142
|
+
* drawn from the lit text grows with it. Both are exact for a linear swipe and taken as linear for
|
|
143
|
+
* any other.
|
|
132
144
|
*/
|
|
133
145
|
function sweepGlow(word, cells, durationMs, followsSwipe) {
|
|
134
|
-
const { config, swipeLeadMs, swipeDurationMs } = word;
|
|
146
|
+
const { engine, config, swipeLeadMs, swipeDurationMs } = word;
|
|
135
147
|
const fades = config.highlight.glowRestingInvisible;
|
|
136
|
-
const
|
|
137
|
-
|
|
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 }];
|
|
148
|
+
const easeGlow = easingLookup(engine)(config.highlight.glowEasing);
|
|
149
|
+
const ramp = swipeRamp(config);
|
|
142
150
|
return cells.flatMap((cell, cellIndex) => {
|
|
143
151
|
const span = cell.span ?? { start: cellIndex / cells.length, width: 1 / cells.length };
|
|
144
|
-
const delayMs = followsSwipe
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
const delayMs = followsSwipe ? Math.max(0, cellReachedAt(ramp, span) * swipeDurationMs - swipeLeadMs) : 0;
|
|
153
|
+
const litMs = followsSwipe ? cellLitAt(ramp, span) * swipeDurationMs - swipeLeadMs : delayMs;
|
|
154
|
+
const riseMs = Math.max(0, litMs - delayMs);
|
|
155
|
+
const peak = durationMs > 0 ? Math.min(easeGlow(riseMs / durationMs), LATEST_GLOW_PEAK) : 0;
|
|
147
156
|
const timing = {
|
|
148
157
|
delay: delayMs,
|
|
149
158
|
duration: durationMs,
|
|
@@ -151,12 +160,25 @@ function sweepGlow(word, cells, durationMs, followsSwipe) {
|
|
|
151
160
|
fill: fades ? "none" : "forwards",
|
|
152
161
|
};
|
|
153
162
|
const currentTimeMs = scheduledTimeMs(word, word.elapsedMs, delayMs + durationMs);
|
|
163
|
+
const halos = haloKeyframes(fades, peak);
|
|
154
164
|
return cell.glows.map((halo, index) => {
|
|
155
|
-
const fade = halo.glow.animate(index === 0 ? wide : tight, timing);
|
|
165
|
+
const fade = halo.glow.animate(index === 0 ? halos.wide : halos.tight, timing);
|
|
166
|
+
glowDelaysMs.set(fade, delayMs);
|
|
156
167
|
return followSong(word, fade, currentTimeMs, { skipDriftSample: true });
|
|
157
168
|
});
|
|
158
169
|
});
|
|
159
170
|
}
|
|
171
|
+
function haloKeyframes(fades, peak) {
|
|
172
|
+
const rises = peak > 0;
|
|
173
|
+
const wideRise = rises ? [{ opacity: 0 }, { opacity: 1, offset: peak }] : [{ opacity: 1 }];
|
|
174
|
+
const tightWait = rises ? [{ opacity: 0 }, { opacity: 0, offset: peak }] : [{ opacity: 0 }];
|
|
175
|
+
if (!fades)
|
|
176
|
+
return { wide: [...wideRise, { opacity: 1 }], tight: [{ opacity: 0 }, { opacity: 0 }] };
|
|
177
|
+
return {
|
|
178
|
+
wide: [...wideRise, { opacity: 0, offset: TIGHT_GLOW_AT }, { opacity: 0 }],
|
|
179
|
+
tight: [...tightWait, { opacity: 1, offset: TIGHT_GLOW_AT }, { opacity: 0 }],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
160
182
|
function wobble(word) {
|
|
161
183
|
const { wobbleFrom, wobblePeak, wobblePeakOffset, wobblePeakEasing, wobbleSettle, wobbleSettleOffset } = word.config.word;
|
|
162
184
|
const { wobbleTo, wobbleEndEasing, wobbleDurationMs, wobbleEasing } = word.config.word;
|