@braccato/core 1.22.0 → 2.0.0-beta.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/LICENSE +1 -1
- package/README.md +211 -600
- package/js/element.js +234 -0
- package/js/renderer.d.ts +157 -0
- package/js/renderer.js +535 -0
- package/package.json +22 -17
- package/pkg/braccato_core_rs.d.ts +236 -0
- package/pkg/braccato_core_rs.js +1735 -0
- package/pkg/braccato_core_rs_bg.wasm +0 -0
- package/pkg/braccato_core_rs_bg.wasm.d.ts +55 -0
- package/dist/LICENSE +0 -21
- package/dist/README.md +0 -639
- package/dist/element.d.ts +0 -168
- package/dist/element.js +0 -730
- package/dist/engine/animationConfig.d.ts +0 -84
- package/dist/engine/animationConfig.js +0 -95
- package/dist/engine/animationDrift.d.ts +0 -11
- package/dist/engine/animationDrift.js +0 -43
- package/dist/engine/animationTiming.d.ts +0 -27
- package/dist/engine/animationTiming.js +0 -145
- package/dist/engine/autoScroll.d.ts +0 -24
- package/dist/engine/autoScroll.js +0 -103
- package/dist/engine/clock.d.ts +0 -29
- package/dist/engine/clock.js +0 -70
- package/dist/engine/contextSweep.d.ts +0 -10
- package/dist/engine/contextSweep.js +0 -102
- package/dist/engine/cssValues.d.ts +0 -13
- package/dist/engine/cssValues.js +0 -47
- package/dist/engine/culling.d.ts +0 -6
- package/dist/engine/culling.js +0 -76
- package/dist/engine/debugOverlay.d.ts +0 -14
- package/dist/engine/debugOverlay.js +0 -58
- package/dist/engine/decorationSlides.d.ts +0 -6
- package/dist/engine/decorationSlides.js +0 -53
- package/dist/engine/elementMotion.d.ts +0 -18
- package/dist/engine/elementMotion.js +0 -98
- package/dist/engine/glow.d.ts +0 -7
- package/dist/engine/glow.js +0 -59
- package/dist/engine/instance.d.ts +0 -105
- package/dist/engine/instance.js +0 -89
- package/dist/engine/instrumentalAnimations.d.ts +0 -7
- package/dist/engine/instrumentalAnimations.js +0 -59
- package/dist/engine/letterPlans.d.ts +0 -31
- package/dist/engine/letterPlans.js +0 -62
- package/dist/engine/lineAnimationState.d.ts +0 -10
- package/dist/engine/lineAnimationState.js +0 -82
- package/dist/engine/lineAnimations.d.ts +0 -5
- package/dist/engine/lineAnimations.js +0 -63
- package/dist/engine/lineLifecycle.d.ts +0 -12
- package/dist/engine/lineLifecycle.js +0 -92
- package/dist/engine/lineScroll.d.ts +0 -47
- package/dist/engine/lineScroll.js +0 -184
- package/dist/engine/lineScrollStyle.d.ts +0 -32
- package/dist/engine/lineScrollStyle.js +0 -133
- package/dist/engine/liveViews.d.ts +0 -3
- package/dist/engine/liveViews.js +0 -5
- package/dist/engine/motionCurves.d.ts +0 -19
- package/dist/engine/motionCurves.js +0 -85
- package/dist/engine/motionPreference.d.ts +0 -1
- package/dist/engine/motionPreference.js +0 -1
- package/dist/engine/passiveScroll.d.ts +0 -10
- package/dist/engine/passiveScroll.js +0 -93
- package/dist/engine/renderedLines.d.ts +0 -16
- package/dist/engine/renderedLines.js +0 -130
- package/dist/engine/scrollViewport.d.ts +0 -36
- package/dist/engine/scrollViewport.js +0 -104
- package/dist/engine/stageMotion.d.ts +0 -7
- package/dist/engine/stageMotion.js +0 -319
- package/dist/engine/sweepPlans.d.ts +0 -38
- package/dist/engine/sweepPlans.js +0 -66
- package/dist/engine/tick.d.ts +0 -16
- package/dist/engine/tick.js +0 -270
- package/dist/engine/timingLogs.d.ts +0 -7
- package/dist/engine/timingLogs.js +0 -81
- package/dist/engine/userScroll.d.ts +0 -12
- package/dist/engine/userScroll.js +0 -62
- package/dist/engine/wavePool.d.ts +0 -7
- package/dist/engine/wavePool.js +0 -22
- package/dist/engine/wordAnimations.d.ts +0 -5
- package/dist/engine/wordAnimations.js +0 -206
- package/dist/imageHighlights.d.ts +0 -4
- package/dist/imageHighlights.js +0 -34
- package/dist/index.d.ts +0 -17
- package/dist/index.js +0 -12
- package/dist/inject.d.ts +0 -98
- package/dist/inject.js +0 -591
- package/dist/instrumental.d.ts +0 -11
- package/dist/instrumental.js +0 -121
- package/dist/language.d.ts +0 -9
- package/dist/language.js +0 -47
- package/dist/letters.d.ts +0 -2
- package/dist/letters.js +0 -25
- package/dist/renderer.d.ts +0 -29
- package/dist/renderer.js +0 -412
- package/dist/seek.d.ts +0 -1
- package/dist/seek.js +0 -27
- package/dist/stage.d.ts +0 -58
- package/dist/stage.js +0 -121
- package/dist/types.d.ts +0 -236
- package/dist/types.js +0 -1
- package/dist/view.d.ts +0 -51
- package/dist/view.js +0 -398
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { BIDI_RUN_CLASS, HIGHLIGHT_RUN_CLASS, RTL_CLASS, SWEEP_CLONE_CLASS, SWEEP_CONTEXT_CLASS, SWEEP_TARGET_CLASS, SWEEP_WINDOW_CLASS, WORD_CLASS, } from "../constants.js";
|
|
2
|
-
import { createSweepCell } from "../inject.js";
|
|
3
|
-
import { swipeRamp } from "./letterPlans.js";
|
|
4
|
-
import { cellFade } from "./sweepPlans.js";
|
|
5
|
-
/**
|
|
6
|
-
* Places the sweep cells of a line's inline words over the boxes those words are laid out in. Runs
|
|
7
|
-
* when the line starts animating and reads layout first, so the reads land before the line's writes;
|
|
8
|
-
* a word laid out as it was last time keeps its cells.
|
|
9
|
-
*/
|
|
10
|
-
export function placeContextSweeps(line, config) {
|
|
11
|
-
for (const part of line.parts)
|
|
12
|
-
if (part.sweepContext)
|
|
13
|
-
part.sweepContext.unplaced = true;
|
|
14
|
-
const placements = line.parts.flatMap(part => (part.sweepContext ? [measure(part)] : []));
|
|
15
|
-
for (const placement of placements)
|
|
16
|
-
if (placement)
|
|
17
|
-
place(placement, config);
|
|
18
|
-
}
|
|
19
|
-
// The cells sit outside the word, so they are handed the colours a theme may set on the word itself.
|
|
20
|
-
const WORD_COLORS = ["--blyrics-lyric-active-color", "--blyrics-glow-color"];
|
|
21
|
-
function measure(part) {
|
|
22
|
-
const word = part.lyricElement;
|
|
23
|
-
const run = word.closest(`.${BIDI_RUN_CLASS}:not(.${HIGHLIGHT_RUN_CLASS})`);
|
|
24
|
-
const contentLine = run?.parentElement;
|
|
25
|
-
if (!run || !contentLine || !part.sweepContext || typeof word.getClientRects !== "function")
|
|
26
|
-
return null;
|
|
27
|
-
const lineRect = contentLine.getBoundingClientRect();
|
|
28
|
-
// The line may be mid-scale, so boxes are read on screen and scaled back to the line's own pixels.
|
|
29
|
-
const scale = contentLine.offsetWidth > 0 ? lineRect.width / contentLine.offsetWidth : 1;
|
|
30
|
-
const local = (rect) => ({
|
|
31
|
-
x: (rect.left - lineRect.left) / scale,
|
|
32
|
-
y: (rect.top - lineRect.top) / scale,
|
|
33
|
-
width: rect.width / scale,
|
|
34
|
-
height: rect.height / scale,
|
|
35
|
-
});
|
|
36
|
-
const runBox = local(run.getBoundingClientRect());
|
|
37
|
-
const fragments = Array.from(word.getClientRects(), local).filter(box => box.width > 0);
|
|
38
|
-
// A line the browser skipped laying out has no boxes yet; it is placed once it comes into view.
|
|
39
|
-
if (fragments.length === 0)
|
|
40
|
-
return null;
|
|
41
|
-
const style = word.ownerDocument.defaultView?.getComputedStyle(part.highlightElement);
|
|
42
|
-
const colors = WORD_COLORS.map((name) => [name, style?.getPropertyValue(name).trim() ?? ""]);
|
|
43
|
-
const key = JSON.stringify([[runBox, fragments].flat().map(box => Object.values(box).map(Math.round)), colors]);
|
|
44
|
-
return { part, context: part.sweepContext, contentLine, run, runBox, fragments, colors, key };
|
|
45
|
-
}
|
|
46
|
-
/** Whether a line started before its inline words could be placed, and has to start over to show them. */
|
|
47
|
-
export function hasUnplacedContextSweeps(line) {
|
|
48
|
-
return line.isAnimating && line.parts.some(part => part.sweepContext?.unplaced);
|
|
49
|
-
}
|
|
50
|
-
function place({ part, context, contentLine, run, runBox, fragments, colors, key }, config) {
|
|
51
|
-
const placedAt = key + JSON.stringify(swipeRamp(config));
|
|
52
|
-
if (context.placedAt === placedAt && context.host?.isConnected) {
|
|
53
|
-
context.unplaced = false;
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
context.host?.remove();
|
|
57
|
-
const doc = contentLine.ownerDocument;
|
|
58
|
-
const host = doc.createElement("span");
|
|
59
|
-
host.classList.add(SWEEP_CONTEXT_CLASS);
|
|
60
|
-
host.setAttribute("aria-hidden", "true");
|
|
61
|
-
for (const [name, value] of colors)
|
|
62
|
-
if (value)
|
|
63
|
-
host.style.setProperty(name, value);
|
|
64
|
-
const wordIndex = Array.from(run.querySelectorAll(`.${WORD_CLASS}`)).indexOf(part.lyricElement);
|
|
65
|
-
const lineCopy = run.cloneNode(true);
|
|
66
|
-
lineCopy.classList.add(SWEEP_CLONE_CLASS);
|
|
67
|
-
lineCopy.querySelectorAll(`.${WORD_CLASS}`)[wordIndex]?.classList.add(SWEEP_TARGET_CLASS);
|
|
68
|
-
const wordWidth = fragments.reduce((sum, box) => sum + box.width, 0);
|
|
69
|
-
const direction = part.lyricElement.classList.contains(RTL_CLASS) ? "rtl" : "ltr";
|
|
70
|
-
let start = 0;
|
|
71
|
-
const cells = fragments.map(box => {
|
|
72
|
-
const window = doc.createElement("span");
|
|
73
|
-
window.classList.add(SWEEP_WINDOW_CLASS);
|
|
74
|
-
window.dir = direction;
|
|
75
|
-
Object.assign(window.style, {
|
|
76
|
-
left: `${box.x}px`,
|
|
77
|
-
top: `${box.y}px`,
|
|
78
|
-
width: `${box.width}px`,
|
|
79
|
-
height: `${box.height}px`,
|
|
80
|
-
});
|
|
81
|
-
const span = { start: start / wordWidth, width: box.width / wordWidth };
|
|
82
|
-
start += box.width;
|
|
83
|
-
window.style.setProperty("--blyrics-sweep-fade", String(cellFade(swipeRamp(config), span)));
|
|
84
|
-
const cell = createSweepCell(doc, window, into => {
|
|
85
|
-
const copy = lineCopy.cloneNode(true);
|
|
86
|
-
Object.assign(copy.style, {
|
|
87
|
-
left: `${runBox.x - box.x}px`,
|
|
88
|
-
top: `${runBox.y - box.y}px`,
|
|
89
|
-
width: `${runBox.width}px`,
|
|
90
|
-
});
|
|
91
|
-
into.appendChild(copy);
|
|
92
|
-
return undefined;
|
|
93
|
-
});
|
|
94
|
-
host.appendChild(window);
|
|
95
|
-
return { ...cell, span };
|
|
96
|
-
});
|
|
97
|
-
contentLine.appendChild(host);
|
|
98
|
-
context.host = host;
|
|
99
|
-
context.placedAt = placedAt;
|
|
100
|
-
context.unplaced = false;
|
|
101
|
-
part.sweep = cells.length > 0 ? cells : undefined;
|
|
102
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AnimationEngineInstance } from "./instance.js";
|
|
2
|
-
export interface ThemeReader {
|
|
3
|
-
string(property: string, fallback: string): string;
|
|
4
|
-
durationMs(property: string, fallback: string): number;
|
|
5
|
-
number(property: string, fallback: number): number;
|
|
6
|
-
fraction(property: string, fallback: number): number;
|
|
7
|
-
flag(property: string, fallback: boolean): boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare function clearStyleCaches(engine: AnimationEngineInstance): void;
|
|
10
|
-
export declare function getCSSValue(engine: AnimationEngineInstance, lyricsElement: HTMLElement, property: string, fallback: string): string;
|
|
11
|
-
export declare function getCSSDurationInMs(engine: AnimationEngineInstance, lyricsElement: HTMLElement, property: string): number;
|
|
12
|
-
export declare function getCSSNumber(engine: AnimationEngineInstance, lyricsElement: HTMLElement, property: string, fallback: number): number;
|
|
13
|
-
export declare function createThemeReader(engine: AnimationEngineInstance, lyricsElement: HTMLElement): ThemeReader;
|
package/dist/engine/cssValues.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { clamp, toMs } from "../util.js";
|
|
2
|
-
import { dropPendingLineScroll } from "./lineScroll.js";
|
|
3
|
-
export function clearStyleCaches(engine) {
|
|
4
|
-
dropPendingLineScroll(engine);
|
|
5
|
-
engine.cachedDurations.clear();
|
|
6
|
-
engine.cachedCSSValues.clear();
|
|
7
|
-
engine.cachedAnimationSettings = null;
|
|
8
|
-
engine.cachedLineScrollTiming.clear();
|
|
9
|
-
}
|
|
10
|
-
// Property-only caching assumes every lookup for this engine uses its lyrics container.
|
|
11
|
-
export function getCSSValue(engine, lyricsElement, property, fallback) {
|
|
12
|
-
let value = engine.cachedCSSValues.get(property);
|
|
13
|
-
if (value === undefined) {
|
|
14
|
-
value = engine.window.getComputedStyle(lyricsElement).getPropertyValue(property).trim() || fallback;
|
|
15
|
-
engine.cachedCSSValues.set(property, value);
|
|
16
|
-
}
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
export function getCSSDurationInMs(engine, lyricsElement, property) {
|
|
20
|
-
let duration = engine.cachedDurations.get(property);
|
|
21
|
-
if (duration === undefined) {
|
|
22
|
-
duration = toMs(getCSSValue(engine, lyricsElement, property, "0ms"));
|
|
23
|
-
engine.cachedDurations.set(property, duration);
|
|
24
|
-
}
|
|
25
|
-
return duration;
|
|
26
|
-
}
|
|
27
|
-
export function getCSSNumber(engine, lyricsElement, property, fallback) {
|
|
28
|
-
const value = Number.parseFloat(getCSSValue(engine, lyricsElement, property, `${fallback}`));
|
|
29
|
-
return Number.isFinite(value) ? value : fallback;
|
|
30
|
-
}
|
|
31
|
-
export function createThemeReader(engine, lyricsElement) {
|
|
32
|
-
const string = (property, fallback) => getCSSValue(engine, lyricsElement, property, fallback);
|
|
33
|
-
const number = (property, fallback) => getCSSNumber(engine, lyricsElement, property, fallback);
|
|
34
|
-
return {
|
|
35
|
-
string,
|
|
36
|
-
number,
|
|
37
|
-
durationMs: (property, fallback) => Math.max(toMs(string(property, fallback)), 1),
|
|
38
|
-
fraction: (property, fallback) => clamp(number(property, fallback), 0, 1),
|
|
39
|
-
flag: (property, fallback) => {
|
|
40
|
-
const value = string(property, fallback ? "1" : "0").toLowerCase();
|
|
41
|
-
if (value === "false" || value === "off" || value === "none")
|
|
42
|
-
return false;
|
|
43
|
-
const numeric = Number.parseFloat(value);
|
|
44
|
-
return Number.isFinite(numeric) ? numeric > 0 : fallback;
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
}
|
package/dist/engine/culling.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { AnimationEngineInstance } from "./instance.js";
|
|
2
|
-
import { type LineScrollItem } from "./lineScroll.js";
|
|
3
|
-
export declare function setupLineCullObserver(engine: AnimationEngineInstance): void;
|
|
4
|
-
export declare function clearOffscreenLineCulling(engine: AnimationEngineInstance): void;
|
|
5
|
-
export declare function updateVisibleLyricWillChange(engine: AnimationEngineInstance, lines: LineScrollItem[], fromScrollTop: number, toScrollTop: number, viewportHeight: number): void;
|
|
6
|
-
export declare function clearVisibleLyricWillChange(engine: AnimationEngineInstance): void;
|
package/dist/engine/culling.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { hasUnplacedContextSweeps } from "./contextSweep.js";
|
|
2
|
-
import { resetLineAnimationState } from "./lineAnimationState.js";
|
|
3
|
-
import { isLineVisibleDuringScroll, LINE_SCROLL_WILL_CHANGE_VALUE } from "./lineScroll.js";
|
|
4
|
-
// Use screen intersections because transformed scrolling decouples layout coordinates from visibility.
|
|
5
|
-
const ONE_VIEWPORT_OVERSCAN = "100% 0px 100% 0px";
|
|
6
|
-
export function setupLineCullObserver(engine) {
|
|
7
|
-
engine.lineCullObserver?.disconnect();
|
|
8
|
-
engine.lineCullObserver = null;
|
|
9
|
-
clearOffscreenLineCulling(engine);
|
|
10
|
-
const Observer = engine.window.IntersectionObserver;
|
|
11
|
-
if (engine.layout === "stage" || typeof Observer !== "function" || engine.lines.length === 0)
|
|
12
|
-
return;
|
|
13
|
-
// The engine owns scrollTop; Firefox's scroll anchoring would answer cull height shifts with a scroll the
|
|
14
|
-
// engine reads as the user's.
|
|
15
|
-
engine.host.getScrollElement()?.style.setProperty("overflow-anchor", "none");
|
|
16
|
-
pinCulledLineHeights(engine);
|
|
17
|
-
const observer = new Observer(entries => {
|
|
18
|
-
for (const entry of entries) {
|
|
19
|
-
const element = entry.target;
|
|
20
|
-
if (entry.isIntersecting) {
|
|
21
|
-
if (engine.culledLineElements.delete(element))
|
|
22
|
-
uncullLine(element);
|
|
23
|
-
restartUnplacedLine(engine, element);
|
|
24
|
-
}
|
|
25
|
-
else if (!engine.culledLineElements.has(element)) {
|
|
26
|
-
cullLine(element);
|
|
27
|
-
engine.culledLineElements.add(element);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}, { root: null, rootMargin: ONE_VIEWPORT_OVERSCAN, threshold: 0 });
|
|
31
|
-
for (const line of engine.lines)
|
|
32
|
-
observer.observe(line.lyricElement);
|
|
33
|
-
engine.lineCullObserver = observer;
|
|
34
|
-
}
|
|
35
|
-
/** A line that started while it was skipped starts over now that its words have boxes to place on. */
|
|
36
|
-
function restartUnplacedLine(engine, element) {
|
|
37
|
-
const line = engine.lines.find(candidate => candidate.lyricElement === element);
|
|
38
|
-
if (line && hasUnplacedContextSweeps(line))
|
|
39
|
-
resetLineAnimationState(line);
|
|
40
|
-
}
|
|
41
|
-
export function clearOffscreenLineCulling(engine) {
|
|
42
|
-
for (const element of engine.culledLineElements)
|
|
43
|
-
uncullLine(element);
|
|
44
|
-
engine.culledLineElements = new Set();
|
|
45
|
-
}
|
|
46
|
-
function pinCulledLineHeights(engine) {
|
|
47
|
-
const renderedHeights = engine.lines.map(line => line.lyricElement.offsetHeight);
|
|
48
|
-
engine.lines.forEach((line, index) => {
|
|
49
|
-
line.lyricElement.style.setProperty("contain-intrinsic-block-size", `auto ${renderedHeights[index]}px`);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function cullLine(element) {
|
|
53
|
-
element.style.setProperty("content-visibility", "auto");
|
|
54
|
-
}
|
|
55
|
-
function uncullLine(element) {
|
|
56
|
-
element.style.removeProperty("content-visibility");
|
|
57
|
-
}
|
|
58
|
-
export function updateVisibleLyricWillChange(engine, lines, fromScrollTop, toScrollTop, viewportHeight) {
|
|
59
|
-
const visibleElements = new Set();
|
|
60
|
-
for (const line of lines) {
|
|
61
|
-
if (!isLineVisibleDuringScroll(line, fromScrollTop, toScrollTop, viewportHeight))
|
|
62
|
-
continue;
|
|
63
|
-
line.lyricElement.style.setProperty("will-change", LINE_SCROLL_WILL_CHANGE_VALUE);
|
|
64
|
-
visibleElements.add(line.lyricElement);
|
|
65
|
-
}
|
|
66
|
-
for (const element of engine.visibleWillChangeElements) {
|
|
67
|
-
if (!visibleElements.has(element))
|
|
68
|
-
element.style.removeProperty("will-change");
|
|
69
|
-
}
|
|
70
|
-
engine.visibleWillChangeElements = visibleElements;
|
|
71
|
-
}
|
|
72
|
-
export function clearVisibleLyricWillChange(engine) {
|
|
73
|
-
for (const element of engine.visibleWillChangeElements)
|
|
74
|
-
element.style.removeProperty("will-change");
|
|
75
|
-
engine.visibleWillChangeElements = new Set();
|
|
76
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { LineData } from "../inject.js";
|
|
2
|
-
import type { AnimationEngineInstance } from "./instance.js";
|
|
3
|
-
export interface ScrollDebugFrame {
|
|
4
|
-
lyricsElement: HTMLElement;
|
|
5
|
-
scrollTop: number;
|
|
6
|
-
viewportHeight: number;
|
|
7
|
-
targetOffset: number;
|
|
8
|
-
followedLines: LineData[];
|
|
9
|
-
lineCenters: number[];
|
|
10
|
-
scrollTimeS: number;
|
|
11
|
-
endingThresholdS: number;
|
|
12
|
-
}
|
|
13
|
-
export declare function isDebugOverlayEnabled(): boolean;
|
|
14
|
-
export declare function drawScrollDebugOverlay(engine: AnimationEngineInstance, frame: ScrollDebugFrame): void;
|
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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;
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AnimationEngineInstance } from "./instance.js";
|
|
2
|
-
import { type EasingLookup, 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;
|
|
18
|
-
export declare function easingLookup(engine: AnimationEngineInstance): EasingLookup;
|
|
@@ -1,98 +0,0 @@
|
|
|
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
|
-
export 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.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
package/dist/engine/glow.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
}
|