@braccato/core 1.20.0 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -37
- package/dist/README.md +40 -37
- package/dist/constants.d.ts +10 -0
- package/dist/constants.js +10 -0
- package/dist/engine/animationConfig.d.ts +83 -0
- package/dist/engine/animationConfig.js +93 -0
- package/dist/engine/animationDrift.d.ts +11 -0
- package/dist/engine/animationDrift.js +43 -0
- package/dist/engine/animationTiming.d.ts +26 -0
- package/dist/engine/animationTiming.js +120 -0
- package/dist/engine/autoScroll.d.ts +24 -0
- package/dist/engine/autoScroll.js +103 -0
- package/dist/engine/clock.d.ts +29 -0
- package/dist/engine/clock.js +70 -0
- package/dist/engine/contextSweep.d.ts +10 -0
- package/dist/engine/contextSweep.js +102 -0
- package/dist/engine/cssValues.d.ts +13 -0
- package/dist/engine/cssValues.js +47 -0
- package/dist/engine/culling.d.ts +6 -0
- package/dist/engine/culling.js +76 -0
- package/dist/engine/debugOverlay.d.ts +14 -0
- package/dist/engine/debugOverlay.js +58 -0
- package/dist/engine/decorationSlides.d.ts +6 -0
- package/dist/engine/decorationSlides.js +53 -0
- package/dist/engine/elementMotion.d.ts +17 -0
- package/dist/engine/elementMotion.js +98 -0
- package/dist/engine/glow.d.ts +7 -0
- package/dist/engine/glow.js +59 -0
- package/dist/engine/instance.d.ts +105 -0
- package/dist/engine/instance.js +89 -0
- package/dist/engine/instrumentalAnimations.d.ts +7 -0
- package/dist/engine/instrumentalAnimations.js +59 -0
- package/dist/engine/letterPlans.d.ts +31 -0
- package/dist/engine/letterPlans.js +62 -0
- package/dist/engine/lineAnimationState.d.ts +10 -0
- package/dist/engine/lineAnimationState.js +82 -0
- package/dist/engine/lineAnimations.d.ts +5 -0
- package/dist/engine/lineAnimations.js +63 -0
- package/dist/engine/lineLifecycle.d.ts +12 -0
- package/dist/engine/lineLifecycle.js +92 -0
- package/dist/engine/lineScroll.d.ts +47 -0
- package/dist/engine/lineScroll.js +184 -0
- package/dist/engine/lineScrollStyle.d.ts +32 -0
- package/dist/engine/lineScrollStyle.js +133 -0
- package/dist/engine/liveViews.d.ts +3 -0
- package/dist/engine/liveViews.js +5 -0
- package/dist/engine/motionCurves.d.ts +19 -0
- package/dist/engine/motionCurves.js +85 -0
- package/dist/engine/motionPreference.d.ts +1 -0
- package/dist/engine/motionPreference.js +1 -0
- package/dist/engine/passiveScroll.d.ts +10 -0
- package/dist/engine/passiveScroll.js +93 -0
- package/dist/engine/renderedLines.d.ts +16 -0
- package/dist/engine/renderedLines.js +130 -0
- package/dist/engine/scrollViewport.d.ts +36 -0
- package/dist/engine/scrollViewport.js +104 -0
- package/dist/engine/stageMotion.d.ts +7 -0
- package/dist/engine/stageMotion.js +319 -0
- package/dist/engine/sweepPlans.d.ts +36 -0
- package/dist/engine/sweepPlans.js +59 -0
- package/dist/engine/tick.d.ts +16 -0
- package/dist/engine/tick.js +270 -0
- package/dist/engine/timingLogs.d.ts +7 -0
- package/dist/engine/timingLogs.js +81 -0
- package/dist/engine/userScroll.d.ts +12 -0
- package/dist/engine/userScroll.js +62 -0
- package/dist/engine/wavePool.d.ts +7 -0
- package/dist/engine/wavePool.js +22 -0
- package/dist/engine/wordAnimations.d.ts +5 -0
- package/dist/engine/wordAnimations.js +238 -0
- package/dist/imageHighlights.d.ts +0 -11
- package/dist/imageHighlights.js +2 -48
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/inject.d.ts +41 -2
- package/dist/inject.js +73 -28
- package/dist/renderer.js +10 -3
- package/dist/styles/image-highlights.css +1 -59
- package/dist/styles/lyrics.css +128 -57
- package/dist/types.d.ts +1 -1
- package/dist/view.d.ts +2 -2
- package/dist/view.js +7 -3
- package/package.json +1 -1
- package/dist/engine.d.ts +0 -471
- package/dist/engine.js +0 -3133
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { registerThemeSetting } from "../themeSettings.js";
|
|
2
|
+
const DEBUG_OVERLAY_ENABLED = registerThemeSetting("blyrics-debug-renderer", false);
|
|
3
|
+
const GUIDE_START_X = 40;
|
|
4
|
+
const GUIDE_END_X = 1000;
|
|
5
|
+
const LAST_SCROLL_COLUMN_X = 160;
|
|
6
|
+
export function isDebugOverlayEnabled() {
|
|
7
|
+
return DEBUG_OVERLAY_ENABLED.getBooleanValue();
|
|
8
|
+
}
|
|
9
|
+
export function drawScrollDebugOverlay(engine, frame) {
|
|
10
|
+
const transform = engine.window.getComputedStyle(frame.lyricsElement).transform;
|
|
11
|
+
const viewTop = frame.scrollTop - new engine.window.DOMMatrix(transform).f;
|
|
12
|
+
const ctx = engine.host.debug?.beginFrame(viewTop);
|
|
13
|
+
if (!ctx)
|
|
14
|
+
return;
|
|
15
|
+
const guide = (color, label, y) => {
|
|
16
|
+
ctx.strokeStyle = color;
|
|
17
|
+
ctx.fillStyle = color;
|
|
18
|
+
ctx.fillText(label, 0, y);
|
|
19
|
+
ctx.beginPath();
|
|
20
|
+
ctx.moveTo(GUIDE_START_X, y);
|
|
21
|
+
ctx.lineTo(GUIDE_END_X, y);
|
|
22
|
+
ctx.stroke();
|
|
23
|
+
};
|
|
24
|
+
guide("green", "visible top", frame.scrollTop);
|
|
25
|
+
guide("blue", "visible bottom", frame.scrollTop + frame.viewportHeight);
|
|
26
|
+
guide("yellow", "target", frame.scrollTop + frame.targetOffset);
|
|
27
|
+
const last = engine.lastScrollDebugContext;
|
|
28
|
+
drawLineColumn(ctx, viewTop, 0, "realtime", frame.followedLines, frame.lineCenters, frame.scrollTimeS, frame);
|
|
29
|
+
drawLineColumn(ctx, viewTop, LAST_SCROLL_COLUMN_X, "last scroll", last.activeElms, last.centers, last.lyricScrollTime, frame);
|
|
30
|
+
}
|
|
31
|
+
function drawLineColumn(ctx, viewTop, x, title, lines, centers, scrollTimeS, { endingThresholdS }) {
|
|
32
|
+
ctx.strokeStyle = "red";
|
|
33
|
+
ctx.fillStyle = "red";
|
|
34
|
+
ctx.fillText(title, x + 2, viewTop + 45);
|
|
35
|
+
ctx.fillText(`scroll time: ${scrollTimeS.toFixed(3)}`, x + 2, viewTop + 60);
|
|
36
|
+
for (const line of lines) {
|
|
37
|
+
const untilStartS = line.time - scrollTimeS;
|
|
38
|
+
const endS = line.time + line.duration;
|
|
39
|
+
const untilEndS = endS - scrollTimeS;
|
|
40
|
+
const color = untilEndS < endingThresholdS ? "gray" : untilStartS > 0 ? "magenta" : "orange";
|
|
41
|
+
ctx.strokeStyle = color;
|
|
42
|
+
ctx.fillStyle = color;
|
|
43
|
+
ctx.beginPath();
|
|
44
|
+
ctx.moveTo(x + 5, line.position);
|
|
45
|
+
ctx.lineTo(x + 5, line.position + line.height);
|
|
46
|
+
ctx.stroke();
|
|
47
|
+
ctx.fillText(`time: start=${line.time.toFixed(2)} end=${endS.toFixed(2)}`, x + 15, line.position);
|
|
48
|
+
ctx.fillText(`till active: ${untilStartS.toFixed(2)}`, x + 15, line.position + 15);
|
|
49
|
+
ctx.fillText(`till end: ${untilEndS.toFixed(2)}`, x + 15, line.position + 30);
|
|
50
|
+
}
|
|
51
|
+
ctx.strokeStyle = "pink";
|
|
52
|
+
ctx.fillStyle = "pink";
|
|
53
|
+
for (const center of centers) {
|
|
54
|
+
ctx.beginPath();
|
|
55
|
+
ctx.arc(x + 5, center, 5, 0, 2 * Math.PI, false);
|
|
56
|
+
ctx.fill();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AnimationEngineInstance } from "./instance.js";
|
|
2
|
+
export declare const DECORATION_MIN_SHIFT_PX = 0.5;
|
|
3
|
+
export declare function slideElementBy(engine: AnimationEngineInstance, element: HTMLElement, dy: number): void;
|
|
4
|
+
export declare function decorationSlideAllowed(engine: AnimationEngineInstance, container: HTMLElement): boolean;
|
|
5
|
+
export declare function lineDecorators(lineElement: HTMLElement): HTMLElement[];
|
|
6
|
+
export declare function captureDecorationSlide(engine: AnimationEngineInstance): (() => void) | null;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ROMANIZED_LYRICS_CLASS, TRANSLATED_LYRICS_CLASS } from "../constants.js";
|
|
2
|
+
import { addElementCurve, timelineNow } from "./elementMotion.js";
|
|
3
|
+
import { REDUCED_MOTION_QUERY } from "./motionPreference.js";
|
|
4
|
+
const DECORATION_SLIDE_MS = 350;
|
|
5
|
+
const DECORATION_SLIDE_EASING = "cubic-bezier(0.25, 1, 0.5, 1)";
|
|
6
|
+
export const DECORATION_MIN_SHIFT_PX = 0.5;
|
|
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
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function decorationSlideAllowed(engine, container) {
|
|
19
|
+
if (engine.window.matchMedia(REDUCED_MOTION_QUERY).matches)
|
|
20
|
+
return false;
|
|
21
|
+
return (engine.window.getComputedStyle(container).getPropertyValue("--blyrics-animate-decoration-entry").trim() !== "0");
|
|
22
|
+
}
|
|
23
|
+
export function lineDecorators(lineElement) {
|
|
24
|
+
return [
|
|
25
|
+
...lineElement.querySelectorAll(`.${ROMANIZED_LYRICS_CLASS}`),
|
|
26
|
+
...lineElement.querySelectorAll(`.${TRANSLATED_LYRICS_CLASS}`),
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
export function captureDecorationSlide(engine) {
|
|
30
|
+
const container = engine.lyricsContainer;
|
|
31
|
+
if (!container || engine.layout === "stage" || !decorationSlideAllowed(engine, container))
|
|
32
|
+
return null;
|
|
33
|
+
const before = engine.lines.map(line => ({
|
|
34
|
+
line,
|
|
35
|
+
position: line.position,
|
|
36
|
+
decorations: new Map(line.decorations),
|
|
37
|
+
}));
|
|
38
|
+
return () => {
|
|
39
|
+
for (const { line, position, decorations } of before) {
|
|
40
|
+
const lineShift = position - line.position;
|
|
41
|
+
if (Math.abs(lineShift) >= DECORATION_MIN_SHIFT_PX)
|
|
42
|
+
slideElementBy(engine, line.lyricElement, lineShift);
|
|
43
|
+
for (const [element, was] of decorations) {
|
|
44
|
+
const now = line.decorations.get(element);
|
|
45
|
+
if (now === undefined)
|
|
46
|
+
continue;
|
|
47
|
+
const ownShift = was - now - lineShift;
|
|
48
|
+
if (Math.abs(ownShift) >= DECORATION_MIN_SHIFT_PX)
|
|
49
|
+
slideElementBy(engine, element, ownShift);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LineData } from "../inject.js";
|
|
2
|
+
import type { AnimationConfig } from "./animationConfig.js";
|
|
3
|
+
import type { AnimationEngineInstance } from "./instance.js";
|
|
4
|
+
export declare function resolveGlowFilter(engine: AnimationEngineInstance, lyricsElement: HTMLElement, end: "from" | "to", defaultRadius: string): string;
|
|
5
|
+
export declare function isGlowRestingInvisible(glowTo: string): boolean;
|
|
6
|
+
export declare function suppressInvisibleWordGlows(engine: AnimationEngineInstance, line: LineData, config: AnimationConfig): void;
|
|
7
|
+
export declare function parseColorAlpha(value: string): number | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { clamp } from "../util.js";
|
|
2
|
+
import { getCSSValue } from "./cssValues.js";
|
|
3
|
+
const HALF_8BIT_ALPHA_STEP = 0.5 / 255;
|
|
4
|
+
// Keep var(--blyrics-glow-color) unresolved so each animated word supplies its color. Reading a composed
|
|
5
|
+
// filter from the container would bake in the container's color.
|
|
6
|
+
export function resolveGlowFilter(engine, lyricsElement, end, defaultRadius) {
|
|
7
|
+
const override = getCSSValue(engine, lyricsElement, `--blyrics-highlight-glow-filter-${end}`, "");
|
|
8
|
+
if (override)
|
|
9
|
+
return override;
|
|
10
|
+
const radius = getCSSValue(engine, lyricsElement, `--blyrics-highlight-glow-radius-${end}`, defaultRadius);
|
|
11
|
+
return `drop-shadow(0 0 ${radius} var(--blyrics-glow-color))`;
|
|
12
|
+
}
|
|
13
|
+
export function isGlowRestingInvisible(glowTo) {
|
|
14
|
+
const value = glowTo.trim();
|
|
15
|
+
if (value === "" || value === "none")
|
|
16
|
+
return true;
|
|
17
|
+
const engineDropShadow = value.match(/^drop-shadow\(\s*0\s+0\s+(\S+)\s+var\(--blyrics-glow-color\)\)$/);
|
|
18
|
+
return engineDropShadow ? Number.parseFloat(engineDropShadow[1]) === 0 : false;
|
|
19
|
+
}
|
|
20
|
+
export function suppressInvisibleWordGlows(engine, line, config) {
|
|
21
|
+
const containerGlowShows = config.highlight.glowContainerAlpha >= HALF_8BIT_ALPHA_STEP;
|
|
22
|
+
if (containerGlowShows) {
|
|
23
|
+
for (const part of line.parts)
|
|
24
|
+
part.glowSuppressed = false;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
for (const part of line.parts) {
|
|
28
|
+
const color = engine.window.getComputedStyle(part.highlightElement).getPropertyValue("--blyrics-glow-color");
|
|
29
|
+
const alpha = parseColorAlpha(color) ?? 1;
|
|
30
|
+
part.glowSuppressed = alpha < HALF_8BIT_ALPHA_STEP;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function parseColorAlpha(value) {
|
|
34
|
+
const color = value.trim().toLowerCase();
|
|
35
|
+
if (color === "")
|
|
36
|
+
return null;
|
|
37
|
+
if (color === "transparent")
|
|
38
|
+
return 0;
|
|
39
|
+
const slashAlpha = color.match(/\/\s*([0-9]*\.?[0-9]+%?)\s*\)\s*$/);
|
|
40
|
+
if (slashAlpha)
|
|
41
|
+
return alphaToken(slashAlpha[1]);
|
|
42
|
+
const commaAlpha = color.match(/^(?:rgba|hsla)\([^)]*,\s*([0-9]*\.?[0-9]+%?)\s*\)$/);
|
|
43
|
+
if (commaAlpha)
|
|
44
|
+
return alphaToken(commaAlpha[1]);
|
|
45
|
+
const hexWithAlpha = color.match(/^#([0-9a-f]{4}|[0-9a-f]{8})$/);
|
|
46
|
+
if (hexWithAlpha) {
|
|
47
|
+
const digits = hexWithAlpha[1];
|
|
48
|
+
const alphaHex = digits.length === 8 ? digits.slice(6) : digits.slice(3).repeat(2);
|
|
49
|
+
return Number.parseInt(alphaHex, 16) / 255;
|
|
50
|
+
}
|
|
51
|
+
const opaqueFunction = /^(?:rgb|hsl|hwb|lab|lch|oklab|oklch|color)\(/.test(color);
|
|
52
|
+
const opaqueHex = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/.test(color);
|
|
53
|
+
const namedColor = /^[a-z]+$/.test(color);
|
|
54
|
+
return opaqueFunction || opaqueHex || namedColor ? 1 : null;
|
|
55
|
+
}
|
|
56
|
+
function alphaToken(token) {
|
|
57
|
+
const value = token.endsWith("%") ? Number.parseFloat(token) / 100 : Number.parseFloat(token);
|
|
58
|
+
return clamp(value, 0, 1);
|
|
59
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { LineData } from "../inject.js";
|
|
2
|
+
import type { LyricsLayout, LyricsRendererHost, LyricSyncType, ResolvedTickOptions } from "../types.js";
|
|
3
|
+
import type { StageBox, StageMetrics } from "../stage.js";
|
|
4
|
+
import { type ScrollInsets } from "./scrollViewport.js";
|
|
5
|
+
import type { ElementMotion } from "./elementMotion.js";
|
|
6
|
+
import type { LineScrollItem, PendingLineScroll, RunningLineScroll } from "./lineScroll.js";
|
|
7
|
+
import type { LineScrollTiming } from "./lineScrollStyle.js";
|
|
8
|
+
import type { AnimationSettings } from "./animationConfig.js";
|
|
9
|
+
/**
|
|
10
|
+
* Everything that belongs to a single rendered lyrics view: one scroll container, one selection,
|
|
11
|
+
* one set of pending scroll work.
|
|
12
|
+
*/
|
|
13
|
+
interface AnimEngineViewState {
|
|
14
|
+
/**
|
|
15
|
+
* The render records this view built, one per lyric line. They hold this view's elements and
|
|
16
|
+
* this view's `Animation` objects, so a second view never shares them.
|
|
17
|
+
*/
|
|
18
|
+
lines: LineData[];
|
|
19
|
+
lyricsContainer: HTMLElement | null;
|
|
20
|
+
syncType: LyricSyncType;
|
|
21
|
+
lyricWidth: number;
|
|
22
|
+
lyricHeight: number;
|
|
23
|
+
skipScrolls: number;
|
|
24
|
+
skipScrollsDecayTimes: number[];
|
|
25
|
+
scrollResumeTime: number;
|
|
26
|
+
scrollPos: number;
|
|
27
|
+
selectedElementIndex: number;
|
|
28
|
+
wasUserScrolling: boolean;
|
|
29
|
+
lastScrollElements: LineData[];
|
|
30
|
+
/** The line a committed scroll kept in view because the active lines overflowed the band. */
|
|
31
|
+
pinnedScrollLine: LineData | null;
|
|
32
|
+
lastScrollDebugContext: {
|
|
33
|
+
activeElms: LineData[];
|
|
34
|
+
centers: number[];
|
|
35
|
+
lyricScrollTime: number;
|
|
36
|
+
};
|
|
37
|
+
passiveScrollAccumulatedTime: number;
|
|
38
|
+
passiveLastWallTime: number;
|
|
39
|
+
/** Where the passive drift last put the scroll, so a scroll that lands anywhere else is the reader's. */
|
|
40
|
+
passiveScrollTop: number | null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `Window` alone types neither `ResizeObserver` nor `DOMMatrix`: both are ambient `var`
|
|
44
|
+
* declarations, so they only appear through `typeof globalThis`.
|
|
45
|
+
*/
|
|
46
|
+
type EngineWindow = Window & typeof globalThis;
|
|
47
|
+
export interface AnimationEngineInstance extends AnimEngineViewState {
|
|
48
|
+
document: Document;
|
|
49
|
+
window: EngineWindow;
|
|
50
|
+
host: LyricsRendererHost;
|
|
51
|
+
cachedTabRendererHeight: number | null;
|
|
52
|
+
cachedScrollInsets: ScrollInsets;
|
|
53
|
+
cachedFooterItem: LineScrollItem | null;
|
|
54
|
+
cachedCreditsItem: LineScrollItem | null;
|
|
55
|
+
creditsFocused: boolean;
|
|
56
|
+
cachedLineScrollTiming: Map<string, LineScrollTiming>;
|
|
57
|
+
tabRendererResizeObserver: ResizeObserver | null;
|
|
58
|
+
observedTabRenderer: HTMLElement | null;
|
|
59
|
+
runningLineScrolls: RunningLineScroll[];
|
|
60
|
+
elementMotions: Map<HTMLElement, ElementMotion>;
|
|
61
|
+
easingTables: Map<string, Float64Array>;
|
|
62
|
+
lineScrollAnimationToken: number;
|
|
63
|
+
pendingLineScroll: PendingLineScroll | null;
|
|
64
|
+
lineScrollElementTokens: WeakMap<HTMLElement, number>;
|
|
65
|
+
visibleWillChangeElements: Set<HTMLElement>;
|
|
66
|
+
culledLineElements: Set<HTMLElement>;
|
|
67
|
+
waveAnimationPool: Animation[];
|
|
68
|
+
lineCullObserver: IntersectionObserver | null;
|
|
69
|
+
cachedDurations: Map<string, number>;
|
|
70
|
+
cachedCSSValues: Map<string, string>;
|
|
71
|
+
cachedAnimationSettings: AnimationSettings | null;
|
|
72
|
+
/**
|
|
73
|
+
* Last value the tick was given. The passive scroll loop runs from an animation frame rather than
|
|
74
|
+
* from a tick, so it has no options object to read.
|
|
75
|
+
*/
|
|
76
|
+
passiveScrollEnabled: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Last options the tick was given, kept before any early return. A click reads its offsets to seek
|
|
79
|
+
* to where a line plays rather than to its unshifted time.
|
|
80
|
+
*/
|
|
81
|
+
lastTickOptions: ResolvedTickOptions | null;
|
|
82
|
+
playbackRate: number;
|
|
83
|
+
passiveRAFId: number | null;
|
|
84
|
+
pendingLyricsUpdateFrame: number | null;
|
|
85
|
+
learnedAnimationTimingOffsetMs: number;
|
|
86
|
+
animationTimingVisibilityLogUntil: number;
|
|
87
|
+
layout: LyricsLayout;
|
|
88
|
+
stageKey: string;
|
|
89
|
+
stageRemeasured: boolean;
|
|
90
|
+
stageHeight: number;
|
|
91
|
+
stageBox: StageBox | null;
|
|
92
|
+
stageMetrics: Map<HTMLElement, StageMetrics>;
|
|
93
|
+
stageY: Map<HTMLElement, number>;
|
|
94
|
+
stageMoves: Map<HTMLElement, Animation>;
|
|
95
|
+
stageFades: Map<HTMLElement, Animation>;
|
|
96
|
+
stageBlurs: Map<HTMLElement, Animation>;
|
|
97
|
+
stageFontSize: number;
|
|
98
|
+
/**
|
|
99
|
+
* Releases everything the instance holds on its window: the reduced motion listener, the tab
|
|
100
|
+
* renderer observer and any frame it still has queued.
|
|
101
|
+
*/
|
|
102
|
+
destroy(): void;
|
|
103
|
+
}
|
|
104
|
+
export declare function createAnimationEngineInstance(engineDocument: Document, engineWindow: EngineWindow, host: LyricsRendererHost, layout?: LyricsLayout): AnimationEngineInstance;
|
|
105
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { NO_SCROLL_INSETS } from "./scrollViewport.js";
|
|
2
|
+
import { REDUCED_MOTION_QUERY } from "./motionPreference.js";
|
|
3
|
+
import { clearStyleCaches } from "./cssValues.js";
|
|
4
|
+
import { liveEngines } from "./liveViews.js";
|
|
5
|
+
import { stopPassiveScrollLoop } from "./passiveScroll.js";
|
|
6
|
+
import { cancelLyricPositionUpdate } from "./tick.js";
|
|
7
|
+
export function createAnimationEngineInstance(engineDocument, engineWindow, host, layout = "scroll") {
|
|
8
|
+
const reducedMotionQuery = engineWindow.matchMedia(REDUCED_MOTION_QUERY);
|
|
9
|
+
const handleReducedMotionChange = () => clearStyleCaches(engine);
|
|
10
|
+
const engine = {
|
|
11
|
+
document: engineDocument,
|
|
12
|
+
window: engineWindow,
|
|
13
|
+
host,
|
|
14
|
+
lines: [],
|
|
15
|
+
lyricsContainer: null,
|
|
16
|
+
syncType: "none",
|
|
17
|
+
lyricWidth: 0,
|
|
18
|
+
lyricHeight: 0,
|
|
19
|
+
skipScrolls: 0,
|
|
20
|
+
skipScrollsDecayTimes: [],
|
|
21
|
+
scrollResumeTime: 0,
|
|
22
|
+
scrollPos: -1,
|
|
23
|
+
selectedElementIndex: 0,
|
|
24
|
+
wasUserScrolling: false,
|
|
25
|
+
lastScrollElements: [],
|
|
26
|
+
pinnedScrollLine: null,
|
|
27
|
+
lastScrollDebugContext: {
|
|
28
|
+
activeElms: [],
|
|
29
|
+
centers: [],
|
|
30
|
+
lyricScrollTime: 0,
|
|
31
|
+
},
|
|
32
|
+
passiveScrollAccumulatedTime: 0,
|
|
33
|
+
passiveLastWallTime: 0,
|
|
34
|
+
passiveScrollTop: null,
|
|
35
|
+
cachedTabRendererHeight: null,
|
|
36
|
+
cachedScrollInsets: NO_SCROLL_INSETS,
|
|
37
|
+
cachedFooterItem: null,
|
|
38
|
+
cachedCreditsItem: null,
|
|
39
|
+
creditsFocused: false,
|
|
40
|
+
cachedLineScrollTiming: new Map(),
|
|
41
|
+
tabRendererResizeObserver: null,
|
|
42
|
+
observedTabRenderer: null,
|
|
43
|
+
runningLineScrolls: [],
|
|
44
|
+
elementMotions: new Map(),
|
|
45
|
+
easingTables: new Map(),
|
|
46
|
+
lineScrollAnimationToken: 0,
|
|
47
|
+
pendingLineScroll: null,
|
|
48
|
+
lineScrollElementTokens: new WeakMap(),
|
|
49
|
+
visibleWillChangeElements: new Set(),
|
|
50
|
+
culledLineElements: new Set(),
|
|
51
|
+
waveAnimationPool: [],
|
|
52
|
+
lineCullObserver: null,
|
|
53
|
+
cachedDurations: new Map(),
|
|
54
|
+
cachedCSSValues: new Map(),
|
|
55
|
+
cachedAnimationSettings: null,
|
|
56
|
+
passiveScrollEnabled: false,
|
|
57
|
+
lastTickOptions: null,
|
|
58
|
+
playbackRate: 1,
|
|
59
|
+
passiveRAFId: null,
|
|
60
|
+
pendingLyricsUpdateFrame: null,
|
|
61
|
+
learnedAnimationTimingOffsetMs: 0,
|
|
62
|
+
animationTimingVisibilityLogUntil: 0,
|
|
63
|
+
layout,
|
|
64
|
+
stageKey: "",
|
|
65
|
+
stageRemeasured: false,
|
|
66
|
+
stageHeight: 0,
|
|
67
|
+
stageBox: null,
|
|
68
|
+
stageMetrics: new Map(),
|
|
69
|
+
stageY: new Map(),
|
|
70
|
+
stageMoves: new Map(),
|
|
71
|
+
stageFades: new Map(),
|
|
72
|
+
stageBlurs: new Map(),
|
|
73
|
+
stageFontSize: 16,
|
|
74
|
+
destroy: () => {
|
|
75
|
+
liveEngines.delete(engine);
|
|
76
|
+
reducedMotionQuery.removeEventListener("change", handleReducedMotionChange);
|
|
77
|
+
engine.tabRendererResizeObserver?.disconnect();
|
|
78
|
+
engine.tabRendererResizeObserver = null;
|
|
79
|
+
engine.observedTabRenderer = null;
|
|
80
|
+
engine.lineCullObserver?.disconnect();
|
|
81
|
+
engine.lineCullObserver = null;
|
|
82
|
+
stopPassiveScrollLoop(engine);
|
|
83
|
+
cancelLyricPositionUpdate(engine);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
reducedMotionQuery.addEventListener("change", handleReducedMotionChange);
|
|
87
|
+
liveEngines.add(engine);
|
|
88
|
+
return engine;
|
|
89
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LineData } from "../inject.js";
|
|
2
|
+
import type { AnimationConfig } from "./animationConfig.js";
|
|
3
|
+
import type { AnimationEngineInstance } from "./instance.js";
|
|
4
|
+
export declare const INSTRUMENTAL_WAVE_PATH_HIGH_FALLBACK = "path(\"M -4 3 Q 1 2 5 3 Q 10 4 14 3 Q 18 2 22 3 Q 26 4 30 3 L 30 4 L -4 4 Z\")";
|
|
5
|
+
export declare const INSTRUMENTAL_WAVE_PATH_LOW_FALLBACK = "path(\"M -4 3 Q 1 4 5 3 Q 10 2 14 3 Q 18 4 22 3 Q 26 2 30 3 L 30 4 L -4 4 Z\")";
|
|
6
|
+
export declare function startInstrumentalAnimations(engine: AnimationEngineInstance, line: LineData, config: AnimationConfig, lyricTimeS: number, appliedTimingOffsetMs: number): void;
|
|
7
|
+
export declare function startInstrumentalExitAnimations(line: LineData, config: AnimationConfig, lyricTimeS: number): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { INSTRUMENTAL_WAVE_PATH_HIGH, INSTRUMENTAL_WAVE_PATH_LOW } from "../instrumental.js";
|
|
2
|
+
import { correctedAnimationTimeMs, correctedWrappedAnimationTimeMs, followSongClock } from "./animationTiming.js";
|
|
3
|
+
const FILL_SELECTOR = ".blyrics--instrumental-fill";
|
|
4
|
+
const WAVE_CLIP_SELECTOR = ".blyrics--wave-clip";
|
|
5
|
+
const WAVE_PATH_SELECTOR = ".blyrics--wave-path";
|
|
6
|
+
const INSTANT_MS = 1;
|
|
7
|
+
export const INSTRUMENTAL_WAVE_PATH_HIGH_FALLBACK = `path("${INSTRUMENTAL_WAVE_PATH_HIGH}")`;
|
|
8
|
+
export const INSTRUMENTAL_WAVE_PATH_LOW_FALLBACK = `path("${INSTRUMENTAL_WAVE_PATH_LOW}")`;
|
|
9
|
+
export function startInstrumentalAnimations(engine, line, config, lyricTimeS, appliedTimingOffsetMs) {
|
|
10
|
+
const elapsedMs = (lyricTimeS - line.time) * 1000;
|
|
11
|
+
const lineDurationMs = Math.max(line.duration * 1000, 1);
|
|
12
|
+
const enabled = config.enabled.instrumental;
|
|
13
|
+
const { instrumental } = config;
|
|
14
|
+
const followSong = (animation, currentTimeMs, wrapDurationMs) => {
|
|
15
|
+
if (!animation)
|
|
16
|
+
return;
|
|
17
|
+
followSongClock(engine, animation, { appliedTimingOffsetMs, offsetMs: 0, wrapDurationMs });
|
|
18
|
+
animation.currentTime = currentTimeMs;
|
|
19
|
+
};
|
|
20
|
+
const scheduled = (durationMs) => correctedAnimationTimeMs(elapsedMs, appliedTimingOffsetMs, durationMs);
|
|
21
|
+
const fillFadeMs = enabled ? instrumental.fillFadeDurationMs : INSTANT_MS;
|
|
22
|
+
const fillFade = animateChild(line, FILL_SELECTOR, [{ opacity: 0 }, { opacity: 1 }], {
|
|
23
|
+
duration: fillFadeMs,
|
|
24
|
+
easing: enabled ? instrumental.fillFadeEasing : "linear",
|
|
25
|
+
fill: "forwards",
|
|
26
|
+
});
|
|
27
|
+
followSong(fillFade, scheduled(fillFadeMs));
|
|
28
|
+
if (!enabled)
|
|
29
|
+
return;
|
|
30
|
+
const travel = (selector, from, to, easing) => animateChild(line, selector, [{ transform: from }, { transform: to }], {
|
|
31
|
+
duration: lineDurationMs,
|
|
32
|
+
easing,
|
|
33
|
+
fill: "both",
|
|
34
|
+
});
|
|
35
|
+
followSong(travel(WAVE_CLIP_SELECTOR, instrumental.fillFrom, instrumental.fillTo, instrumental.fillEasing), scheduled(lineDurationMs));
|
|
36
|
+
followSong(travel(WAVE_PATH_SELECTOR, instrumental.waveFrom, instrumental.waveTo, instrumental.waveEasing), scheduled(lineDurationMs));
|
|
37
|
+
const oscillationMs = instrumental.waveOscillationDurationMs;
|
|
38
|
+
const oscillation = animateChild(line, WAVE_PATH_SELECTOR, [{ d: instrumental.wavePathHigh }, { d: instrumental.wavePathLow, offset: 0.5 }, { d: instrumental.wavePathHigh }], { duration: oscillationMs, easing: instrumental.waveOscillationEasing, iterations: Infinity });
|
|
39
|
+
const wrapMs = Math.max(oscillationMs, 1);
|
|
40
|
+
followSong(oscillation, correctedWrappedAnimationTimeMs(elapsedMs, appliedTimingOffsetMs, wrapMs), oscillationMs);
|
|
41
|
+
}
|
|
42
|
+
export function startInstrumentalExitAnimations(line, config, lyricTimeS) {
|
|
43
|
+
if (lyricTimeS < line.time)
|
|
44
|
+
return;
|
|
45
|
+
const fades = config.enabled.instrumental && config.enabled.highlightFade;
|
|
46
|
+
animateChild(line, FILL_SELECTOR, [{ opacity: 1 }, { opacity: 0 }], {
|
|
47
|
+
duration: fades ? config.highlight.fadeOutDurationMs : INSTANT_MS,
|
|
48
|
+
easing: config.enabled.instrumental ? config.highlight.fadeOutEasing : "linear",
|
|
49
|
+
fill: "none",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function animateChild(line, selector, keyframes, options) {
|
|
53
|
+
const element = line.lyricElement.querySelector(selector);
|
|
54
|
+
if (!element)
|
|
55
|
+
return null;
|
|
56
|
+
const animation = element.animate(keyframes, options);
|
|
57
|
+
line.animations.push(animation);
|
|
58
|
+
return animation;
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AnimationConfig } from "./animationConfig.js";
|
|
2
|
+
export interface SwipeRamp {
|
|
3
|
+
easing: string;
|
|
4
|
+
startFrom: string;
|
|
5
|
+
startTo: string;
|
|
6
|
+
endFrom: string;
|
|
7
|
+
endTo: string;
|
|
8
|
+
}
|
|
9
|
+
export interface LetterSwipeWindow {
|
|
10
|
+
delayMs: number;
|
|
11
|
+
durationMs: number;
|
|
12
|
+
from: {
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
};
|
|
16
|
+
to: {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface LetterWaveTiming {
|
|
22
|
+
delayMs: number;
|
|
23
|
+
durationMs: number;
|
|
24
|
+
}
|
|
25
|
+
export declare const LETTER_WAVE_CREST_OFFSET = 0.4;
|
|
26
|
+
export declare const GECKO_REDRAW: boolean;
|
|
27
|
+
export declare const GECKO_REDRAW_KEYFRAMES: Keyframe[];
|
|
28
|
+
export declare const GECKO_REDRAW_PERIOD_MS = 200;
|
|
29
|
+
export declare function swipeRamp({ highlight }: AnimationConfig): SwipeRamp;
|
|
30
|
+
export declare function linearForwardSwipeWindows(swipe: SwipeRamp, letterCount: number, swipeDurationMs: number): LetterSwipeWindow[] | null;
|
|
31
|
+
export declare function planLetterWave(swipe: SwipeRamp, letterCount: number, wordDurationMs: number, swipeDurationMs: number, swipeLeadMs: number, floatDurationMs: number): LetterWaveTiming[];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { clamp, isGecko } from "../util.js";
|
|
2
|
+
export const LETTER_WAVE_CREST_OFFSET = 0.4;
|
|
3
|
+
// WebRender redraws a cached tile only after a quarter device pixel of movement, so Gecko letters step.
|
|
4
|
+
// An invisible additive opacity ripple changes every frame and forces the redraw.
|
|
5
|
+
export const GECKO_REDRAW = isGecko();
|
|
6
|
+
export const GECKO_REDRAW_KEYFRAMES = [{ opacity: 0 }, { opacity: -0.002 }, { opacity: 0 }];
|
|
7
|
+
export const GECKO_REDRAW_PERIOD_MS = 200;
|
|
8
|
+
export function swipeRamp({ highlight }) {
|
|
9
|
+
return {
|
|
10
|
+
easing: highlight.swipeEasing,
|
|
11
|
+
startFrom: highlight.swipeStartFrom,
|
|
12
|
+
startTo: highlight.swipeStartTo,
|
|
13
|
+
endFrom: highlight.swipeEndFrom,
|
|
14
|
+
endTo: highlight.swipeEndTo,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function linearForwardSwipeWindows(swipe, letterCount, swipeDurationMs) {
|
|
18
|
+
if (swipe.easing !== "linear" || swipeDurationMs <= 0 || letterCount <= 0)
|
|
19
|
+
return null;
|
|
20
|
+
const startFrom = Number.parseFloat(swipe.startFrom);
|
|
21
|
+
const startTo = Number.parseFloat(swipe.startTo);
|
|
22
|
+
const endFrom = Number.parseFloat(swipe.endFrom);
|
|
23
|
+
const endTo = Number.parseFloat(swipe.endTo);
|
|
24
|
+
const finite = [startFrom, startTo, endFrom, endTo].every(Number.isFinite);
|
|
25
|
+
if (!finite || startTo <= startFrom || endTo <= endFrom)
|
|
26
|
+
return null;
|
|
27
|
+
const startAt = (timeMs) => startFrom + ((startTo - startFrom) * timeMs) / swipeDurationMs;
|
|
28
|
+
const endAt = (timeMs) => endFrom + ((endTo - endFrom) * timeMs) / swipeDurationMs;
|
|
29
|
+
const timeWhenEndReaches = (value) => (swipeDurationMs * (value - endFrom)) / (endTo - endFrom);
|
|
30
|
+
const timeWhenStartReaches = (value) => (swipeDurationMs * (value - startFrom)) / (startTo - startFrom);
|
|
31
|
+
const windows = [];
|
|
32
|
+
for (let index = 0; index < letterCount; index++) {
|
|
33
|
+
const beginMs = clamp(timeWhenEndReaches(index / letterCount), 0, swipeDurationMs);
|
|
34
|
+
const finishMs = clamp(timeWhenStartReaches((index + 1) / letterCount), 0, swipeDurationMs);
|
|
35
|
+
windows.push({
|
|
36
|
+
delayMs: beginMs,
|
|
37
|
+
durationMs: Math.max(finishMs - beginMs, 1),
|
|
38
|
+
from: { start: startAt(beginMs), end: endAt(beginMs) },
|
|
39
|
+
to: { start: startAt(finishMs), end: endAt(finishMs) },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return windows;
|
|
43
|
+
}
|
|
44
|
+
export function planLetterWave(swipe, letterCount, wordDurationMs, swipeDurationMs, swipeLeadMs, floatDurationMs) {
|
|
45
|
+
const windows = linearForwardSwipeWindows({ ...swipe, easing: "linear" }, letterCount, swipeDurationMs);
|
|
46
|
+
if (!windows)
|
|
47
|
+
return evenlySpreadWaves(letterCount, wordDurationMs, floatDurationMs);
|
|
48
|
+
const riseMs = floatDurationMs * LETTER_WAVE_CREST_OFFSET;
|
|
49
|
+
return windows.map(window => {
|
|
50
|
+
const touchedMs = window.delayMs - swipeLeadMs;
|
|
51
|
+
const lightingMs = window.durationMs;
|
|
52
|
+
if (lightingMs > riseMs)
|
|
53
|
+
return { delayMs: touchedMs, durationMs: lightingMs / LETTER_WAVE_CREST_OFFSET };
|
|
54
|
+
return { delayMs: touchedMs + lightingMs - riseMs, durationMs: floatDurationMs };
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function evenlySpreadWaves(letterCount, wordDurationMs, floatDurationMs) {
|
|
58
|
+
return Array.from({ length: letterCount }, (_, index) => ({
|
|
59
|
+
delayMs: (wordDurationMs * index) / letterCount,
|
|
60
|
+
durationMs: floatDurationMs,
|
|
61
|
+
}));
|
|
62
|
+
}
|