@braccato/core 1.21.5 → 1.22.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 +12 -5
- package/dist/README.md +12 -5
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -1
- package/dist/engine/animationConfig.d.ts +1 -0
- package/dist/engine/animationConfig.js +2 -0
- package/dist/engine/animationTiming.d.ts +1 -0
- package/dist/engine/animationTiming.js +27 -2
- package/dist/engine/instrumentalAnimations.js +2 -2
- package/dist/engine/lineAnimations.js +2 -2
- package/dist/engine/wordAnimations.js +21 -75
- package/dist/inject.d.ts +1 -9
- package/dist/inject.js +2 -10
- package/dist/styles/lyrics.css +8 -28
- package/dist/util.d.ts +2 -0
- package/dist/util.js +4 -0
- package/dist/view.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -388,10 +388,12 @@ start until the next word begins.
|
|
|
388
388
|
|
|
389
389
|
### Browser engine
|
|
390
390
|
|
|
391
|
-
On Firefox the container carries `data-browser-engine="gecko"
|
|
392
|
-
|
|
393
|
-
a
|
|
394
|
-
|
|
391
|
+
On Firefox the container carries `data-browser-engine="gecko"`, and on WebKit (Safari and the other
|
|
392
|
+
WebKit browsers) it carries `data-browser-engine="webkit"`. The renderer's engine-only CSS keys on it,
|
|
393
|
+
and a theme can do the same to target an engine without sniffing the user agent. Each is detected from
|
|
394
|
+
a feature only that engine ships, so forks carry it too. Script reads the same answers from `isGecko()`
|
|
395
|
+
and `isWebKit()` in `@braccato/core/util`; the renderer's Gecko-only script checks `isGecko()` once on
|
|
396
|
+
load.
|
|
395
397
|
|
|
396
398
|
```css
|
|
397
399
|
.blyrics-container[data-browser-engine="gecko"] .blyrics--line {
|
|
@@ -399,6 +401,11 @@ a feature only Gecko ships, so forks of Firefox carry it too. Script reads the s
|
|
|
399
401
|
}
|
|
400
402
|
```
|
|
401
403
|
|
|
404
|
+
WebKit puts the baseline of an inline-block that clips its overflow at the box's bottom edge, where
|
|
405
|
+
Blink and Gecko keep the baseline of its text. Each sweep cell clips its mask boxes, so on WebKit every
|
|
406
|
+
wrapped row of lit text sat lower than the row it covers. There the cells use paint containment instead,
|
|
407
|
+
which clips the same box and keeps the text's baseline.
|
|
408
|
+
|
|
402
409
|
The letter wave uses both. WebRender rounds text moved by a 2D translation to whole device
|
|
403
410
|
pixels, and it only redraws a cached tile once something on it has moved a quarter of a pixel, so the
|
|
404
411
|
wave stepped on Firefox. Lettered words on animating lines get a distant `perspective` there, and each
|
|
@@ -519,7 +526,7 @@ Four leaves import nothing at all, so taking one does not pull the engine into y
|
|
|
519
526
|
- `@braccato/core/constants` for the class names and element ids above
|
|
520
527
|
- `@braccato/core/text` for script detection: `testRtl`, `containsNonLatin`, `detectNonLatinLanguage`
|
|
521
528
|
- `@braccato/core/themeSettings` for `parseThemeConfig`
|
|
522
|
-
- `@braccato/core/util` for pure helpers such as `clamp` and `toMs`, and `isGecko` for engine-specific fixes
|
|
529
|
+
- `@braccato/core/util` for pure helpers such as `clamp` and `toMs`, and `isGecko` and `isWebKit` for engine-specific fixes
|
|
523
530
|
|
|
524
531
|
Two notes on the element entry point. A browser extension's isolated world has no custom element
|
|
525
532
|
registry, so `window.customElements` is null there and importing this file throws where it registers.
|
package/dist/README.md
CHANGED
|
@@ -388,10 +388,12 @@ start until the next word begins.
|
|
|
388
388
|
|
|
389
389
|
### Browser engine
|
|
390
390
|
|
|
391
|
-
On Firefox the container carries `data-browser-engine="gecko"
|
|
392
|
-
|
|
393
|
-
a
|
|
394
|
-
|
|
391
|
+
On Firefox the container carries `data-browser-engine="gecko"`, and on WebKit (Safari and the other
|
|
392
|
+
WebKit browsers) it carries `data-browser-engine="webkit"`. The renderer's engine-only CSS keys on it,
|
|
393
|
+
and a theme can do the same to target an engine without sniffing the user agent. Each is detected from
|
|
394
|
+
a feature only that engine ships, so forks carry it too. Script reads the same answers from `isGecko()`
|
|
395
|
+
and `isWebKit()` in `@braccato/core/util`; the renderer's Gecko-only script checks `isGecko()` once on
|
|
396
|
+
load.
|
|
395
397
|
|
|
396
398
|
```css
|
|
397
399
|
.blyrics-container[data-browser-engine="gecko"] .blyrics--line {
|
|
@@ -399,6 +401,11 @@ a feature only Gecko ships, so forks of Firefox carry it too. Script reads the s
|
|
|
399
401
|
}
|
|
400
402
|
```
|
|
401
403
|
|
|
404
|
+
WebKit puts the baseline of an inline-block that clips its overflow at the box's bottom edge, where
|
|
405
|
+
Blink and Gecko keep the baseline of its text. Each sweep cell clips its mask boxes, so on WebKit every
|
|
406
|
+
wrapped row of lit text sat lower than the row it covers. There the cells use paint containment instead,
|
|
407
|
+
which clips the same box and keeps the text's baseline.
|
|
408
|
+
|
|
402
409
|
The letter wave uses both. WebRender rounds text moved by a 2D translation to whole device
|
|
403
410
|
pixels, and it only redraws a cached tile once something on it has moved a quarter of a pixel, so the
|
|
404
411
|
wave stepped on Firefox. Lettered words on animating lines get a distant `perspective` there, and each
|
|
@@ -519,7 +526,7 @@ Four leaves import nothing at all, so taking one does not pull the engine into y
|
|
|
519
526
|
- `@braccato/core/constants` for the class names and element ids above
|
|
520
527
|
- `@braccato/core/text` for script detection: `testRtl`, `containsNonLatin`, `detectNonLatinLanguage`
|
|
521
528
|
- `@braccato/core/themeSettings` for `parseThemeConfig`
|
|
522
|
-
- `@braccato/core/util` for pure helpers such as `clamp` and `toMs`, and `isGecko` for engine-specific fixes
|
|
529
|
+
- `@braccato/core/util` for pure helpers such as `clamp` and `toMs`, and `isGecko` and `isWebKit` for engine-specific fixes
|
|
523
530
|
|
|
524
531
|
Two notes on the element entry point. A browser extension's isolated world has no custom element
|
|
525
532
|
registry, so `window.customElements` is null there and importing this file throws where it registers.
|
package/dist/constants.d.ts
CHANGED
|
@@ -38,7 +38,6 @@ export declare const SWEEP_CLONE_CLASS: "blyrics-sweep-clone";
|
|
|
38
38
|
export declare const SWEEP_TARGET_CLASS: "blyrics-sweep-target";
|
|
39
39
|
export declare const SWEEP_MASK_CLASS: "blyrics-sweep-mask";
|
|
40
40
|
export declare const SWEEP_TEXT_CLASS: "blyrics-sweep-text";
|
|
41
|
-
export declare const SWEEP_GLOW_CLASS: "blyrics-sweep-glow";
|
|
42
41
|
export declare const HIGHLIGHT_RUN_CLASS: "blyrics-highlight-run";
|
|
43
42
|
export declare const LINE_SYNCED_WORD_CLASS: "blyrics-line-synced-word";
|
|
44
43
|
export declare const BIDI_RUN_CLASS: "blyrics-bidi-run";
|
package/dist/constants.js
CHANGED
|
@@ -43,7 +43,6 @@ export const SWEEP_CLONE_CLASS = "blyrics-sweep-clone";
|
|
|
43
43
|
export const SWEEP_TARGET_CLASS = "blyrics-sweep-target";
|
|
44
44
|
export const SWEEP_MASK_CLASS = "blyrics-sweep-mask";
|
|
45
45
|
export const SWEEP_TEXT_CLASS = "blyrics-sweep-text";
|
|
46
|
-
export const SWEEP_GLOW_CLASS = "blyrics-sweep-glow";
|
|
47
46
|
export const HIGHLIGHT_RUN_CLASS = "blyrics-highlight-run";
|
|
48
47
|
export const LINE_SYNCED_WORD_CLASS = "blyrics-line-synced-word";
|
|
49
48
|
export const BIDI_RUN_CLASS = "blyrics-bidi-run";
|
|
@@ -14,6 +14,7 @@ export function getAnimationSettings(engine, lyricsElement) {
|
|
|
14
14
|
}
|
|
15
15
|
function readAnimationConfig(engine, lyricsElement) {
|
|
16
16
|
const css = createThemeReader(engine, lyricsElement);
|
|
17
|
+
const glowFrom = resolveGlowFilter(engine, lyricsElement, "from", "0.8rem");
|
|
17
18
|
const glowTo = resolveGlowFilter(engine, lyricsElement, "to", "0");
|
|
18
19
|
return {
|
|
19
20
|
enabled: {
|
|
@@ -44,6 +45,7 @@ function readAnimationConfig(engine, lyricsElement) {
|
|
|
44
45
|
swipeEndFrom: css.string("--blyrics-highlight-swipe-end-from", "-0.1"),
|
|
45
46
|
swipeStartTo: css.string("--blyrics-highlight-swipe-start-to", "1.4"),
|
|
46
47
|
swipeEndTo: css.string("--blyrics-highlight-swipe-end-to", "1.5"),
|
|
48
|
+
glowFrom,
|
|
47
49
|
glowTo,
|
|
48
50
|
glowDurationRatio: css.number("--blyrics-highlight-glow-duration-ratio", 1.2),
|
|
49
51
|
glowMinDurationMs: css.durationMs("--blyrics-highlight-glow-min-duration", "1.2s"),
|
|
@@ -14,6 +14,7 @@ export interface DriftSample {
|
|
|
14
14
|
offsetMs: number;
|
|
15
15
|
playState: AnimationPlayState;
|
|
16
16
|
}
|
|
17
|
+
export declare function seekAnimation(engine: AnimationEngineInstance, animation: Animation, timeMs: number): void;
|
|
17
18
|
export declare function followSongClock(engine: AnimationEngineInstance, animation: Animation, track: Omit<SongClockTrack, "appliedTimingOffsetMs"> & {
|
|
18
19
|
appliedTimingOffsetMs?: number;
|
|
19
20
|
}): Animation;
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { positiveModulo, toMs } from "../util.js";
|
|
2
2
|
const songClockTracks = new WeakMap();
|
|
3
|
+
// A current time set before an animation starts holds until its first frame, which a long setup frame delays.
|
|
4
|
+
export function seekAnimation(engine, animation, timeMs) {
|
|
5
|
+
const rate = animation.playbackRate;
|
|
6
|
+
if (!engine.lastTickOptions?.isPlaying || typeof animation.timeline?.currentTime !== "number" || rate === 0) {
|
|
7
|
+
animation.currentTime = timeMs;
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
animation.startTime = timelineNow(animation) - timeMs / rate;
|
|
11
|
+
}
|
|
12
|
+
// A document's timeline counts from its own window's time origin, which differs in another window or frame.
|
|
13
|
+
function timelineNow(animation) {
|
|
14
|
+
const target = animation.effect?.target;
|
|
15
|
+
return target?.ownerDocument.defaultView?.performance.now() ?? performance.now();
|
|
16
|
+
}
|
|
17
|
+
// The timeline's time is held per task and per frame, so a running animation is read against now, the clock it was placed on.
|
|
18
|
+
function liveCurrentTimeMs(animation) {
|
|
19
|
+
const startTimeMs = animation.startTime;
|
|
20
|
+
if (animation.playState === "running" && typeof startTimeMs === "number") {
|
|
21
|
+
return (timelineNow(animation) - startTimeMs) * animation.playbackRate;
|
|
22
|
+
}
|
|
23
|
+
return timingValueToMs(animation.currentTime);
|
|
24
|
+
}
|
|
3
25
|
export function followSongClock(engine, animation, track) {
|
|
4
26
|
songClockTracks.set(animation, {
|
|
5
27
|
...track,
|
|
@@ -20,7 +42,10 @@ export function mirrorHighlightAnimations(part, animations) {
|
|
|
20
42
|
continue;
|
|
21
43
|
const mirror = target.animate(effect.getKeyframes(), effect.getTiming());
|
|
22
44
|
mirror.playbackRate = animation.playbackRate;
|
|
23
|
-
|
|
45
|
+
if (animation.playState === "running" && animation.startTime !== null)
|
|
46
|
+
mirror.startTime = animation.startTime;
|
|
47
|
+
else
|
|
48
|
+
mirror.currentTime = animation.currentTime;
|
|
24
49
|
const track = songClockTracks.get(animation);
|
|
25
50
|
if (track)
|
|
26
51
|
songClockTracks.set(mirror, { ...track, skipDriftSample: true });
|
|
@@ -69,7 +94,7 @@ function driftSample(part, animation, lyricTimeS) {
|
|
|
69
94
|
const track = songClockTracks.get(animation);
|
|
70
95
|
if (!track || track.skipDriftSample || animation.playState === "idle")
|
|
71
96
|
return null;
|
|
72
|
-
const rawActualTimeMs =
|
|
97
|
+
const rawActualTimeMs = liveCurrentTimeMs(animation);
|
|
73
98
|
if (rawActualTimeMs === null)
|
|
74
99
|
return null;
|
|
75
100
|
const expectedTimeMs = normalizedTimeMs(animation, (lyricTimeS - part.time) * 1000 + track.offsetMs, track);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { INSTRUMENTAL_WAVE_PATH_HIGH, INSTRUMENTAL_WAVE_PATH_LOW } from "../instrumental.js";
|
|
2
|
-
import { correctedAnimationTimeMs, correctedWrappedAnimationTimeMs, followSongClock } from "./animationTiming.js";
|
|
2
|
+
import { correctedAnimationTimeMs, correctedWrappedAnimationTimeMs, followSongClock, seekAnimation, } from "./animationTiming.js";
|
|
3
3
|
const FILL_SELECTOR = ".blyrics--instrumental-fill";
|
|
4
4
|
const WAVE_CLIP_SELECTOR = ".blyrics--wave-clip";
|
|
5
5
|
const WAVE_PATH_SELECTOR = ".blyrics--wave-path";
|
|
@@ -15,7 +15,7 @@ export function startInstrumentalAnimations(engine, line, config, lyricTimeS, ap
|
|
|
15
15
|
if (!animation)
|
|
16
16
|
return;
|
|
17
17
|
followSongClock(engine, animation, { appliedTimingOffsetMs, offsetMs: 0, wrapDurationMs });
|
|
18
|
-
animation
|
|
18
|
+
seekAnimation(engine, animation, currentTimeMs);
|
|
19
19
|
};
|
|
20
20
|
const scheduled = (durationMs) => correctedAnimationTimeMs(elapsedMs, appliedTimingOffsetMs, durationMs);
|
|
21
21
|
const fillFadeMs = enabled ? instrumental.fillFadeDurationMs : INSTANT_MS;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { correctedAnimationTimeMs, followSongClock } from "./animationTiming.js";
|
|
1
|
+
import { correctedAnimationTimeMs, followSongClock, seekAnimation } from "./animationTiming.js";
|
|
2
2
|
import { placeContextSweeps } from "./contextSweep.js";
|
|
3
3
|
import { suppressInvisibleWordGlows } from "./glow.js";
|
|
4
4
|
import { startInstrumentalAnimations, startInstrumentalExitAnimations } from "./instrumentalAnimations.js";
|
|
@@ -45,7 +45,7 @@ function startLineEntrance(engine, line, config, lyricTimeS, appliedTimingOffset
|
|
|
45
45
|
});
|
|
46
46
|
followSongClock(engine, entrance, { appliedTimingOffsetMs, offsetMs: 0 });
|
|
47
47
|
const elapsedMs = (lyricTimeS - line.time) * 1000;
|
|
48
|
-
entrance
|
|
48
|
+
seekAnimation(engine, entrance, correctedAnimationTimeMs(elapsedMs, appliedTimingOffsetMs, durationMs));
|
|
49
49
|
line.animations = [entrance];
|
|
50
50
|
}
|
|
51
51
|
function startLineExit(line, config) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { RTL_CLASS } from "../constants.js";
|
|
2
2
|
import { registerThemeSetting } from "../themeSettings.js";
|
|
3
|
-
import { correctedAnimationTimeMs, mirrorHighlightAnimations,
|
|
4
|
-
import { easingLookup } from "./elementMotion.js";
|
|
3
|
+
import { correctedAnimationTimeMs, followSongClock, mirrorHighlightAnimations, seekAnimation } from "./animationTiming.js";
|
|
5
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";
|
|
7
|
-
import {
|
|
6
|
+
import { planCellSweep } from "./sweepPlans.js";
|
|
8
7
|
import { acquireWaveAnimation } from "./wavePool.js";
|
|
9
8
|
const SWIPE_LEAD_RATIO = registerThemeSetting("blyrics-swipe-lead-ratio", 0.1);
|
|
10
9
|
const SWIPE_DURATION_RATIO = registerThemeSetting("blyrics-swipe-duration-ratio", 1.6);
|
|
@@ -13,9 +12,6 @@ const INSTANT_MS = 1;
|
|
|
13
12
|
// The sweep holds a word's reveal in its own layers, so the word's own opacity is all that animates on it.
|
|
14
13
|
const SHOWN = [{ opacity: 1 }, { opacity: 1 }];
|
|
15
14
|
const FADE_IN = [{ opacity: 0 }, { opacity: 1 }];
|
|
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();
|
|
19
15
|
export function startWordAnimations(engine, part, config, lyricTimeS, appliedTimingOffsetMs) {
|
|
20
16
|
resetPartAnimations(part);
|
|
21
17
|
const word = wordTimeline(engine, part, config, lyricTimeS, appliedTimingOffsetMs);
|
|
@@ -26,23 +22,21 @@ export function startWordAnimations(engine, part, config, lyricTimeS, appliedTim
|
|
|
26
22
|
part.animations = [...highlight, ...mirrorHighlightAnimations(part, highlight), ...motion];
|
|
27
23
|
}
|
|
28
24
|
export function startWordExitAnimation(part, config) {
|
|
29
|
-
const glows = part.animations.filter(animation => glowStarted(animation));
|
|
30
|
-
part.animations = part.animations.filter(animation => !glows.includes(animation));
|
|
31
25
|
resetPartAnimations(part);
|
|
32
26
|
const fades = config.enabled.highlightFade;
|
|
33
27
|
const durationMs = fades ? config.highlight.fadeOutDurationMs : INSTANT_MS;
|
|
34
|
-
const
|
|
28
|
+
const glowRest = glowShows(part, config) ? { filter: config.highlight.glowTo } : {};
|
|
29
|
+
const fadeOut = part.highlightElement.animate([
|
|
30
|
+
{ opacity: 1, ...glowRest },
|
|
31
|
+
{ opacity: 0, ...glowRest },
|
|
32
|
+
], {
|
|
35
33
|
duration: durationMs,
|
|
36
34
|
easing: fades ? config.highlight.fadeOutEasing : "linear",
|
|
37
35
|
fill: "none",
|
|
38
36
|
});
|
|
39
|
-
part.animations = [fadeOut, ...mirrorHighlightAnimations(part, [fadeOut])
|
|
37
|
+
part.animations = [fadeOut, ...mirrorHighlightAnimations(part, [fadeOut])];
|
|
40
38
|
fadeOut.addEventListener("finish", () => resetPartAnimations(part), { once: true });
|
|
41
39
|
}
|
|
42
|
-
function glowStarted(animation) {
|
|
43
|
-
const delayMs = glowDelaysMs.get(animation);
|
|
44
|
-
return delayMs !== undefined && Number(animation.currentTime) >= delayMs;
|
|
45
|
-
}
|
|
46
40
|
function wordTimeline(engine, part, config, lyricTimeS, appliedTimingOffsetMs) {
|
|
47
41
|
const durationMs = Math.max(0, part.duration * 1000);
|
|
48
42
|
return {
|
|
@@ -63,7 +57,7 @@ function scheduledTimeMs(word, elapsedMs, durationMs) {
|
|
|
63
57
|
function followSong(word, animation, currentTimeMs, { offsetMs = 0, skipDriftSample = false } = {}) {
|
|
64
58
|
const { appliedTimingOffsetMs } = word;
|
|
65
59
|
followSongClock(word.engine, animation, { appliedTimingOffsetMs, offsetMs, skipDriftSample });
|
|
66
|
-
|
|
60
|
+
seekAnimation(word.engine, animation, currentTimeMs);
|
|
67
61
|
return animation;
|
|
68
62
|
}
|
|
69
63
|
function glowShows(part, config) {
|
|
@@ -71,12 +65,11 @@ function glowShows(part, config) {
|
|
|
71
65
|
}
|
|
72
66
|
function richSyncedHighlight(word) {
|
|
73
67
|
const { part, config } = word;
|
|
74
|
-
const
|
|
75
|
-
const animations = swipes ? swipe(word) : [];
|
|
68
|
+
const animations = config.enabled.highlightSwipe ? swipe(word) : [];
|
|
76
69
|
const show = part.highlightElement.animate(SHOWN, { duration: INSTANT_MS, easing: "linear", fill: "forwards" });
|
|
77
70
|
animations.push(followSong(word, show, scheduledTimeMs(word, word.elapsedMs, INSTANT_MS)));
|
|
78
71
|
if (glowShows(part, config))
|
|
79
|
-
animations.push(
|
|
72
|
+
animations.push(glow(word, word.glowDurationMs));
|
|
80
73
|
return animations;
|
|
81
74
|
}
|
|
82
75
|
function lineSyncedHighlight(word) {
|
|
@@ -90,7 +83,7 @@ function lineSyncedHighlight(word) {
|
|
|
90
83
|
});
|
|
91
84
|
const animations = [followSong(word, fadeIn, scheduledTimeMs(word, word.elapsedMs, durationMs))];
|
|
92
85
|
if (glowShows(part, config))
|
|
93
|
-
animations.push(
|
|
86
|
+
animations.push(glow(word, config.highlight.glowMinDurationMs));
|
|
94
87
|
return animations;
|
|
95
88
|
}
|
|
96
89
|
function swipe(word) {
|
|
@@ -127,57 +120,15 @@ function compositedSwipe(word, cells, currentTimeMs) {
|
|
|
127
120
|
});
|
|
128
121
|
return animations;
|
|
129
122
|
}
|
|
130
|
-
function glow(word, durationMs
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Stands in for a glow whose radius shrinks to nothing: the wide halo crossfades into the tight one
|
|
139
|
-
* while the radius would shrink between them, and the tight one then fades out. The keyframe offsets
|
|
140
|
-
* are in eased progress, since the glow's easing applies to the whole effect. Under a swipe each
|
|
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.
|
|
144
|
-
*/
|
|
145
|
-
function sweepGlow(word, cells, durationMs, followsSwipe) {
|
|
146
|
-
const { engine, config, swipeLeadMs, swipeDurationMs } = word;
|
|
147
|
-
const fades = config.highlight.glowRestingInvisible;
|
|
148
|
-
const easeGlow = easingLookup(engine)(config.highlight.glowEasing);
|
|
149
|
-
const ramp = swipeRamp(config);
|
|
150
|
-
return cells.flatMap((cell, cellIndex) => {
|
|
151
|
-
const span = cell.span ?? { start: cellIndex / cells.length, width: 1 / cells.length };
|
|
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;
|
|
156
|
-
const timing = {
|
|
157
|
-
delay: delayMs,
|
|
158
|
-
duration: durationMs,
|
|
159
|
-
easing: config.highlight.glowEasing,
|
|
160
|
-
fill: fades ? "none" : "forwards",
|
|
161
|
-
};
|
|
162
|
-
const currentTimeMs = scheduledTimeMs(word, word.elapsedMs, delayMs + durationMs);
|
|
163
|
-
const halos = haloKeyframes(fades, peak);
|
|
164
|
-
return cell.glows.map((halo, index) => {
|
|
165
|
-
const fade = halo.glow.animate(index === 0 ? halos.wide : halos.tight, timing);
|
|
166
|
-
glowDelaysMs.set(fade, delayMs);
|
|
167
|
-
return followSong(word, fade, currentTimeMs, { skipDriftSample: true });
|
|
168
|
-
});
|
|
123
|
+
function glow(word, durationMs) {
|
|
124
|
+
const { part, config } = word;
|
|
125
|
+
const keyframes = [{ filter: config.highlight.glowFrom }, { filter: config.highlight.glowTo }];
|
|
126
|
+
const shrink = part.highlightElement.animate(keyframes, {
|
|
127
|
+
duration: durationMs,
|
|
128
|
+
easing: config.highlight.glowEasing,
|
|
129
|
+
fill: config.highlight.glowRestingInvisible ? "none" : "forwards",
|
|
169
130
|
});
|
|
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
|
-
};
|
|
131
|
+
return followSong(word, shrink, scheduledTimeMs(word, word.elapsedMs, durationMs), { skipDriftSample: true });
|
|
181
132
|
}
|
|
182
133
|
function wobble(word) {
|
|
183
134
|
const { wobbleFrom, wobblePeak, wobblePeakOffset, wobblePeakEasing, wobbleSettle, wobbleSettleOffset } = word.config.word;
|
|
@@ -193,19 +144,14 @@ function wobble(word) {
|
|
|
193
144
|
return word.part.wobbleElements.map(element => followSong(word, element.animate(keyframes, timing), currentTimeMs));
|
|
194
145
|
}
|
|
195
146
|
function letterWave(word) {
|
|
196
|
-
const { part
|
|
147
|
+
const { part } = word;
|
|
197
148
|
const letterCount = part.letterElements?.length ?? 0;
|
|
198
149
|
if (letterCount === 0)
|
|
199
150
|
return [];
|
|
200
151
|
const run = planLetterWaveRun(word, letterCount);
|
|
201
|
-
const glowLetterSets = glowShows(part, config)
|
|
202
|
-
? (part.sweep?.flatMap(cell => cell.glows.map(glow => glow.letters)) ?? [])
|
|
203
|
-
: [];
|
|
204
152
|
const animations = [];
|
|
205
153
|
floatLetters(word, run, part.letterElements, true, animations);
|
|
206
154
|
floatLetters(word, run, part.highlightLetterElements, false, animations);
|
|
207
|
-
for (const glowLetters of glowLetterSets)
|
|
208
|
-
floatLetters(word, run, glowLetters, false, animations);
|
|
209
155
|
return animations;
|
|
210
156
|
}
|
|
211
157
|
function planLetterWaveRun(word, letterCount) {
|
package/dist/inject.d.ts
CHANGED
|
@@ -17,24 +17,16 @@ export interface AnimationData {
|
|
|
17
17
|
lyricElement: HTMLElement;
|
|
18
18
|
animations: Animation[];
|
|
19
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
20
|
/**
|
|
26
21
|
* One box of a word's sweep, run by the compositor: the whole word when it is its own inline-block
|
|
27
22
|
* box, or one letter of a word that flows inline. Its mask holds a static soft edge and slides one way
|
|
28
23
|
* while the text inside it slides the other, so the glyphs hold still and only the edge crosses them.
|
|
29
|
-
*
|
|
30
|
-
* crossfaded so the glow tightens as it fades. With nothing animating, the mask rests with the cell
|
|
31
|
-
* fully lit.
|
|
24
|
+
* With nothing animating, the mask rests with the cell fully lit.
|
|
32
25
|
*/
|
|
33
26
|
export interface SweepCell {
|
|
34
27
|
mask: HTMLElement;
|
|
35
28
|
text: HTMLElement;
|
|
36
29
|
letters?: HTMLElement[];
|
|
37
|
-
glows: SweepGlow[];
|
|
38
30
|
/** Where the cell sits along the word, as fractions of the word's width; equal shares if unset. */
|
|
39
31
|
span?: {
|
|
40
32
|
start: number;
|
package/dist/inject.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// into zero duration words, so line synced lyrics reach the DOM the sweep already knows.
|
|
14
14
|
import { releasePart } from "./engine/lineAnimationState.js";
|
|
15
15
|
import { normalizeLanguage } from "./language.js";
|
|
16
|
-
import { BACKGROUND_LINE_CLASS, BACKGROUND_LYRIC_CLASS, BIDI_RUN_CLASS, BIDI_SENSITIVE_CLASS, CONTENT_LINE_CLASS, EXPLICIT_WORD_CLASS, HIGHLIGHT_RUN_CLASS, LETTER_CLASS, LINE_MAIN_CLASS, LINE_SYNCED_WORD_CLASS, LONG_WORD_GROUP_CLASS, ROMANIZED_LYRICS_CLASS, RTL_CLASS, SWEEP_CELL_CLASS,
|
|
16
|
+
import { BACKGROUND_LINE_CLASS, BACKGROUND_LYRIC_CLASS, BIDI_RUN_CLASS, BIDI_SENSITIVE_CLASS, CONTENT_LINE_CLASS, EXPLICIT_WORD_CLASS, HIGHLIGHT_RUN_CLASS, LETTER_CLASS, LINE_MAIN_CLASS, LINE_SYNCED_WORD_CLASS, LONG_WORD_GROUP_CLASS, ROMANIZED_LYRICS_CLASS, RTL_CLASS, SWEEP_CELL_CLASS, SWEEP_MASK_CLASS, SWEEP_TEXT_CLASS, TRANSLATED_LYRICS_CLASS, WORD_CLASS, WORD_GROUP_CLASS, WORD_HIGHLIGHT_CLASS, WORD_HIGHLIGHT_CONTEXT_CLASS, WORD_HIGHLIGHT_LETTERED_CLASS, WORD_HIGHLIGHT_SWEEP_CLASS, WORD_STATE_ATTR, WORD_STATE_UPCOMING, ZERO_DURATION_ANIMATION_CLASS, } from "./constants.js";
|
|
17
17
|
import { letterClusters } from "./letters.js";
|
|
18
18
|
import { getSeekTimeFromClick } from "./seek.js";
|
|
19
19
|
import { isSameText, testJoiningScript, testRtl } from "./text.js";
|
|
@@ -226,7 +226,6 @@ function fillWordText(doc, host, clusters, wrapThreshold, perLetter, preserveJoi
|
|
|
226
226
|
appendLongWordBreaks(doc, host, clusters, wrapThreshold);
|
|
227
227
|
return undefined;
|
|
228
228
|
}
|
|
229
|
-
const SWEEP_GLOW_RADII = ["wide", "tight"];
|
|
230
229
|
export function createSweepCell(doc, host, fill) {
|
|
231
230
|
const mask = doc.createElement("span");
|
|
232
231
|
mask.classList.add(SWEEP_MASK_CLASS);
|
|
@@ -234,16 +233,9 @@ export function createSweepCell(doc, host, fill) {
|
|
|
234
233
|
text.classList.add(SWEEP_TEXT_CLASS);
|
|
235
234
|
mask.appendChild(text);
|
|
236
235
|
const letters = fill(text);
|
|
237
|
-
const glows = SWEEP_GLOW_RADII.map(radius => {
|
|
238
|
-
const glow = doc.createElement("span");
|
|
239
|
-
glow.classList.add(SWEEP_GLOW_CLASS, `${SWEEP_GLOW_CLASS}--${radius}`);
|
|
240
|
-
const glowLetters = fill(glow);
|
|
241
|
-
text.appendChild(glow);
|
|
242
|
-
return { glow, letters: glowLetters };
|
|
243
|
-
});
|
|
244
236
|
host.classList.add(SWEEP_CELL_CLASS);
|
|
245
237
|
host.appendChild(mask);
|
|
246
|
-
return { mask, text, letters
|
|
238
|
+
return { mask, text, letters };
|
|
247
239
|
}
|
|
248
240
|
/** Makes each letter of a word that flows inline its own sweep cell, holding the letter's text. */
|
|
249
241
|
function createLetterSweepCells(doc, letters) {
|
package/dist/styles/lyrics.css
CHANGED
|
@@ -152,9 +152,8 @@
|
|
|
152
152
|
to half a cell past the cell's end (SWEEP_REST in sweepPlans.ts), then a soft edge `fade` cells
|
|
153
153
|
wide, where fade is the swipe's width from its last start stop to its last end stop, in cells. The
|
|
154
154
|
engine slides the mask back to where the swipe begins and the text inside it the other way by the
|
|
155
|
-
same distance, so the glyphs hold still while the edge crosses them.
|
|
156
|
-
|
|
157
|
-
cell lit and its halos whole. */
|
|
155
|
+
same distance, so the glyphs hold still while the edge crosses them. With nothing animating the
|
|
156
|
+
mask rests with the cell lit. */
|
|
158
157
|
.blyrics--word.blyrics-word-highlight.blyrics-word-highlight--sweep {
|
|
159
158
|
color: var(--blyrics-lyric-active-color);
|
|
160
159
|
--blyrics-sweep-angle: 90deg;
|
|
@@ -185,6 +184,12 @@
|
|
|
185
184
|
position: relative;
|
|
186
185
|
}
|
|
187
186
|
|
|
187
|
+
/* WebKit puts a clipped inline-block's baseline at its bottom edge; paint containment clips without that. */
|
|
188
|
+
.blyrics-container[data-browser-engine="webkit"] .blyrics-sweep-cell {
|
|
189
|
+
contain: paint;
|
|
190
|
+
overflow: visible;
|
|
191
|
+
}
|
|
192
|
+
|
|
188
193
|
.blyrics-word-highlight--sweep.blyrics-rtl .blyrics-sweep-cell,
|
|
189
194
|
.blyrics-sweep-window.blyrics-sweep-cell[dir="rtl"] {
|
|
190
195
|
direction: rtl;
|
|
@@ -216,26 +221,6 @@
|
|
|
216
221
|
width: calc(100% / var(--blyrics-sweep-widths));
|
|
217
222
|
}
|
|
218
223
|
|
|
219
|
-
/* A halo is a copy of the text whose own glyphs are clear, under a text shadow that never changes; the
|
|
220
|
-
engine fades it by opacity. */
|
|
221
|
-
.blyrics-sweep-glow {
|
|
222
|
-
--blyrics-sweep-glow-radius: var(--blyrics-highlight-glow-radius-from, 0.8rem);
|
|
223
|
-
color: transparent;
|
|
224
|
-
inset: 0;
|
|
225
|
-
opacity: 0;
|
|
226
|
-
pointer-events: none;
|
|
227
|
-
position: absolute;
|
|
228
|
-
text-shadow: 0 0 var(--blyrics-sweep-glow-radius) var(--blyrics-glow-color);
|
|
229
|
-
user-select: none;
|
|
230
|
-
z-index: -1;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/* The glow shrinks as it fades. The engine crossfades from the wide halo to this one, which sits where
|
|
234
|
-
the radius has shrunk to by the time the wide one is gone. */
|
|
235
|
-
.blyrics-sweep-glow--tight {
|
|
236
|
-
--blyrics-sweep-glow-radius: calc(var(--blyrics-highlight-glow-radius-from, 0.8rem) * 0.4);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
224
|
/* A word that flows inline keeps its text here only for layout; its sweep is drawn by cells placed over
|
|
240
225
|
each box it breaks into, which show the word from copies of its line. */
|
|
241
226
|
.blyrics--word.blyrics-word-highlight.blyrics-word-highlight--context {
|
|
@@ -276,11 +261,6 @@
|
|
|
276
261
|
color: var(--blyrics-lyric-active-color);
|
|
277
262
|
}
|
|
278
263
|
|
|
279
|
-
.blyrics-sweep-glow .blyrics-sweep-clone .blyrics--word.blyrics-sweep-target {
|
|
280
|
-
color: transparent;
|
|
281
|
-
text-shadow: 0 0 var(--blyrics-sweep-glow-radius) var(--blyrics-glow-color);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
264
|
/* text-decoration skips inline-block letters and rides the wave, so draw on the word box instead, from its
|
|
285
265
|
center (fixed against the text at any line-height), with layout-neutral padding so a tight box can hold it. */
|
|
286
266
|
[blyrics-alt-hover] .blyrics--word:hover {
|
package/dist/util.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export declare function positiveModulo(value: number, divisor: number): number;
|
|
|
5
5
|
* spoofed user agents and Firefox forks resolve the same way.
|
|
6
6
|
*/
|
|
7
7
|
export declare function isGecko(): boolean;
|
|
8
|
+
/** Whether the page renders with WebKit (Safari and the other WebKit browsers), detected the same way. */
|
|
9
|
+
export declare function isWebKit(): boolean;
|
|
8
10
|
export declare function roundedMs(value: number): number;
|
|
9
11
|
/**
|
|
10
12
|
* Converts CSS duration value to milliseconds.
|
package/dist/util.js
CHANGED
|
@@ -11,6 +11,10 @@ export function positiveModulo(value, divisor) {
|
|
|
11
11
|
export function isGecko() {
|
|
12
12
|
return typeof CSS !== "undefined" && CSS.supports("-moz-appearance", "none");
|
|
13
13
|
}
|
|
14
|
+
/** Whether the page renders with WebKit (Safari and the other WebKit browsers), detected the same way. */
|
|
15
|
+
export function isWebKit() {
|
|
16
|
+
return typeof CSS !== "undefined" && CSS.supports("-webkit-nbsp-mode", "space");
|
|
17
|
+
}
|
|
14
18
|
export function roundedMs(value) {
|
|
15
19
|
return Math.round(value * 10) / 10;
|
|
16
20
|
}
|
package/dist/view.js
CHANGED
|
@@ -23,7 +23,7 @@ import { refreshInstrumentalImages } from "./imageHighlights.js";
|
|
|
23
23
|
import { createInstrumentalElement } from "./instrumental.js";
|
|
24
24
|
import { applyLyricLanguage, resolveLyricLanguages } from "./language.js";
|
|
25
25
|
import { lyricBuildSettingsKey } from "./themeSettings.js";
|
|
26
|
-
import { isGecko } from "./util.js";
|
|
26
|
+
import { isGecko, isWebKit } from "./util.js";
|
|
27
27
|
const INITIAL_SKIP_SCROLLS = 2;
|
|
28
28
|
const SKIP_SCROLL_DECAY_MS = 2000;
|
|
29
29
|
function buildInstrumentalLine(doc, lyricElement, lyrics, lineIndex) {
|
|
@@ -211,6 +211,8 @@ export function setLyrics(engine, mount, lyrics, options) {
|
|
|
211
211
|
container.className = LYRICS_CLASS;
|
|
212
212
|
if (isGecko())
|
|
213
213
|
container.dataset.browserEngine = "gecko";
|
|
214
|
+
else if (isWebKit())
|
|
215
|
+
container.dataset.browserEngine = "webkit";
|
|
214
216
|
mount.replaceChildren(container);
|
|
215
217
|
const context = buildContext(engine, lyrics, options);
|
|
216
218
|
const lines = [];
|