@braccato/core 1.22.0 → 2.0.0-beta.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/LICENSE +1 -1
- package/README.md +202 -607
- 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
package/dist/seek.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { LYRICS_CLASS, WORD_CLASS } from "./constants.js";
|
|
2
|
-
export function getSeekTimeFromClick(event, lyricElement) {
|
|
3
|
-
const target = event.target;
|
|
4
|
-
const container = lyricElement.closest(`.${LYRICS_CLASS}`);
|
|
5
|
-
const isRichsync = container?.dataset.sync === "richsync";
|
|
6
|
-
if (!isRichsync || !event.altKey) {
|
|
7
|
-
return parseFloat(lyricElement.dataset.time || "0");
|
|
8
|
-
}
|
|
9
|
-
let wordElement = target.closest(`.${WORD_CLASS}`);
|
|
10
|
-
if (!wordElement) {
|
|
11
|
-
const words = lyricElement.querySelectorAll(`.${WORD_CLASS}`);
|
|
12
|
-
let closestDist = Infinity;
|
|
13
|
-
words.forEach(word => {
|
|
14
|
-
const rect = word.getBoundingClientRect();
|
|
15
|
-
const centerX = rect.left + rect.width / 2;
|
|
16
|
-
const centerY = rect.top + rect.height / 2;
|
|
17
|
-
const dist = Math.hypot(event.clientX - centerX, event.clientY - centerY);
|
|
18
|
-
if (dist < closestDist) {
|
|
19
|
-
closestDist = dist;
|
|
20
|
-
wordElement = word;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
if (!wordElement)
|
|
25
|
-
return null;
|
|
26
|
-
return parseFloat(wordElement.dataset.time || "0");
|
|
27
|
-
}
|
package/dist/stage.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export type StageItemKind = "line" | "blank" | "instrumental" | "credits";
|
|
2
|
-
export type StageRole = "current" | "previous" | "queued" | "gone";
|
|
3
|
-
export interface StageItem {
|
|
4
|
-
kind: StageItemKind;
|
|
5
|
-
/** Seconds. */
|
|
6
|
-
start: number;
|
|
7
|
-
/** Seconds. The credits hold the stage until the song ends, so theirs is infinite. */
|
|
8
|
-
end: number;
|
|
9
|
-
}
|
|
10
|
-
export declare const STAGE_LEAD_S = 0.5;
|
|
11
|
-
export declare const STAGE_HANDOFF_S = 0.12;
|
|
12
|
-
export declare const STAGE_OVERLAP_S = 0.15;
|
|
13
|
-
export declare function overlapsPrevious(items: readonly StageItem[], index: number): boolean;
|
|
14
|
-
export declare function stageEnterTimes(items: readonly StageItem[]): number[];
|
|
15
|
-
export declare function planStage(items: readonly StageItem[], timeS: number): StageRole[];
|
|
16
|
-
export interface StageMetrics {
|
|
17
|
-
height: number;
|
|
18
|
-
left: number;
|
|
19
|
-
width: number;
|
|
20
|
-
/** Where the item scales from horizontally: 0 left, 0.5 centre, 1 right. */
|
|
21
|
-
originX: number;
|
|
22
|
-
}
|
|
23
|
-
export interface StageGeometry {
|
|
24
|
-
stageHeight: number;
|
|
25
|
-
gap: number;
|
|
26
|
-
activeScale: number;
|
|
27
|
-
}
|
|
28
|
-
export interface StagePlacement {
|
|
29
|
-
y: number;
|
|
30
|
-
visible: boolean;
|
|
31
|
-
}
|
|
32
|
-
export interface StageBox {
|
|
33
|
-
x: number;
|
|
34
|
-
y: number;
|
|
35
|
-
width: number;
|
|
36
|
-
height: number;
|
|
37
|
-
}
|
|
38
|
-
export interface StageSpanRect {
|
|
39
|
-
x: number;
|
|
40
|
-
width: number;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* A wrapped `fit-content` box fills the width offered, so the plate follows the text instead. The rects
|
|
44
|
-
* miss printed `::before` labels, so the span is widened to what the alignment guarantees.
|
|
45
|
-
*/
|
|
46
|
-
export declare function stageTextSpan(offsetLeft: number, offsetWidth: number, box: StageSpanRect, textRects: Iterable<StageSpanRect>, padding: {
|
|
47
|
-
left: number;
|
|
48
|
-
right: number;
|
|
49
|
-
}, originX: number): {
|
|
50
|
-
left: number;
|
|
51
|
-
width: number;
|
|
52
|
-
};
|
|
53
|
-
/** Where a line waits below the floor, and where it rises from as it enters. */
|
|
54
|
-
export declare function queuedStageY(stageHeight: number, height: number, gap: number): number;
|
|
55
|
-
export declare function layoutStage(roles: readonly StageRole[], items: readonly StageItem[], metrics: readonly StageMetrics[], previousY: readonly (number | null)[], geometry: StageGeometry): {
|
|
56
|
-
placements: StagePlacement[];
|
|
57
|
-
box: StageBox | null;
|
|
58
|
-
};
|
package/dist/stage.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
export const STAGE_LEAD_S = 0.5;
|
|
2
|
-
export const STAGE_HANDOFF_S = 0.12;
|
|
3
|
-
export const STAGE_OVERLAP_S = 0.15;
|
|
4
|
-
export function overlapsPrevious(items, index) {
|
|
5
|
-
const previous = items[index - 1];
|
|
6
|
-
return (previous !== undefined &&
|
|
7
|
-
previous.kind === "line" &&
|
|
8
|
-
items[index].kind !== "blank" &&
|
|
9
|
-
items[index].start < previous.end - STAGE_OVERLAP_S);
|
|
10
|
-
}
|
|
11
|
-
export function stageEnterTimes(items) {
|
|
12
|
-
return items.map((item, index) => {
|
|
13
|
-
const early = item.start - STAGE_LEAD_S;
|
|
14
|
-
const previous = items[index - 1];
|
|
15
|
-
// An outro note would otherwise keep the credits off stage until the song ends.
|
|
16
|
-
if (item.kind === "credits" && previous?.kind === "instrumental")
|
|
17
|
-
return (previous.start + previous.end) / 2;
|
|
18
|
-
if (previous?.kind !== "line" || overlapsPrevious(items, index))
|
|
19
|
-
return early;
|
|
20
|
-
return Math.max(early, Math.min(previous.end, item.start) - STAGE_HANDOFF_S);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
export function planStage(items, timeS) {
|
|
24
|
-
const enterTimes = stageEnterTimes(items);
|
|
25
|
-
let current = -1;
|
|
26
|
-
enterTimes.forEach((enterTime, index) => {
|
|
27
|
-
if (enterTime <= timeS)
|
|
28
|
-
current = index;
|
|
29
|
-
});
|
|
30
|
-
const roles = items.map((_, index) => index < current ? "gone" : index > current ? "queued" : "current");
|
|
31
|
-
if (current < 0)
|
|
32
|
-
return roles;
|
|
33
|
-
const previous = items[current - 1];
|
|
34
|
-
if (previous?.kind === "line" && overlapsPrevious(items, current) && timeS < previous.end) {
|
|
35
|
-
roles[current - 1] = "previous";
|
|
36
|
-
}
|
|
37
|
-
return roles;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* A wrapped `fit-content` box fills the width offered, so the plate follows the text instead. The rects
|
|
41
|
-
* miss printed `::before` labels, so the span is widened to what the alignment guarantees.
|
|
42
|
-
*/
|
|
43
|
-
export function stageTextSpan(offsetLeft, offsetWidth, box, textRects, padding, originX) {
|
|
44
|
-
const whole = { left: offsetLeft, width: offsetWidth };
|
|
45
|
-
if (box.width <= 0 || offsetWidth <= 0 || originX === 1)
|
|
46
|
-
return whole;
|
|
47
|
-
const scale = box.width / offsetWidth;
|
|
48
|
-
let start = Number.POSITIVE_INFINITY;
|
|
49
|
-
let end = Number.NEGATIVE_INFINITY;
|
|
50
|
-
for (const rect of textRects) {
|
|
51
|
-
if (rect.width <= 0)
|
|
52
|
-
continue;
|
|
53
|
-
start = Math.min(start, (rect.x - box.x) / scale);
|
|
54
|
-
end = Math.max(end, (rect.x + rect.width - box.x) / scale);
|
|
55
|
-
}
|
|
56
|
-
if (start > end)
|
|
57
|
-
return whole;
|
|
58
|
-
const contentLeft = padding.left;
|
|
59
|
-
const contentRight = offsetWidth - padding.right;
|
|
60
|
-
if (originX === 0) {
|
|
61
|
-
start = contentLeft;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
const centre = (contentLeft + contentRight) / 2;
|
|
65
|
-
const half = Math.max(end - centre, centre - start);
|
|
66
|
-
start = centre - half;
|
|
67
|
-
end = centre + half;
|
|
68
|
-
}
|
|
69
|
-
const left = Math.max(0, start - padding.left);
|
|
70
|
-
const right = Math.min(offsetWidth, end + padding.right);
|
|
71
|
-
return { left: offsetLeft + left, width: right - left };
|
|
72
|
-
}
|
|
73
|
-
function unionBox(box, next) {
|
|
74
|
-
if (box === null)
|
|
75
|
-
return next;
|
|
76
|
-
const x = Math.min(box.x, next.x);
|
|
77
|
-
const y = Math.min(box.y, next.y);
|
|
78
|
-
return {
|
|
79
|
-
x,
|
|
80
|
-
y,
|
|
81
|
-
width: Math.max(box.x + box.width, next.x + next.width) - x,
|
|
82
|
-
height: Math.max(box.y + box.height, next.y + next.height) - y,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/** Where a line waits below the floor, and where it rises from as it enters. */
|
|
86
|
-
export function queuedStageY(stageHeight, height, gap) {
|
|
87
|
-
return stageHeight - height + gap;
|
|
88
|
-
}
|
|
89
|
-
export function layoutStage(roles, items, metrics, previousY, geometry) {
|
|
90
|
-
const { stageHeight, gap } = geometry;
|
|
91
|
-
const current = roles.indexOf("current");
|
|
92
|
-
const currentY = current >= 0 ? stageHeight - metrics[current].height : stageHeight;
|
|
93
|
-
const placements = roles.map((role, index) => {
|
|
94
|
-
const { height } = metrics[index];
|
|
95
|
-
switch (role) {
|
|
96
|
-
case "current":
|
|
97
|
-
return { y: currentY, visible: true };
|
|
98
|
-
case "previous":
|
|
99
|
-
return { y: currentY - gap - height, visible: true };
|
|
100
|
-
case "queued":
|
|
101
|
-
return { y: queuedStageY(stageHeight, height, gap), visible: false };
|
|
102
|
-
case "gone":
|
|
103
|
-
return { y: previousY[index] ?? currentY, visible: false };
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
let box = null;
|
|
107
|
-
roles.forEach((role, index) => {
|
|
108
|
-
const { kind } = items[index];
|
|
109
|
-
if ((role !== "current" && role !== "previous") || kind === "instrumental" || kind === "blank")
|
|
110
|
-
return;
|
|
111
|
-
const { height, left, width, originX } = metrics[index];
|
|
112
|
-
const scale = geometry.activeScale;
|
|
113
|
-
box = unionBox(box, {
|
|
114
|
-
x: left + width * originX * (1 - scale),
|
|
115
|
-
y: placements[index].y + (height * (1 - scale)) / 2,
|
|
116
|
-
width: width * scale,
|
|
117
|
-
height: height * scale,
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
return { placements, box };
|
|
121
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import type { Lyric, LyricPart, LyricSyncType } from "@braccato/types";
|
|
2
|
-
import type { AnimationTickStatus } from "./engine/tick.js";
|
|
3
|
-
import type { LineData } from "./inject.js";
|
|
4
|
-
import type { StageBox } from "./stage.js";
|
|
5
|
-
import type { SetLyricsOptions } from "./view.js";
|
|
6
|
-
export type { Lyric, LyricPart, LyricSyncType };
|
|
7
|
-
/**
|
|
8
|
-
* The play state is the only thing a tick cannot be given a sensible default for. Everything else
|
|
9
|
-
* describes a setting the consumer may not have, so it may be left out.
|
|
10
|
-
*/
|
|
11
|
-
export interface TickOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Wall clock timestamp of the player snapshot the time came from, in milliseconds.
|
|
14
|
-
* Defaults to -1, which reads as a time that was not sampled from a live player.
|
|
15
|
-
*/
|
|
16
|
-
eventCreationTime?: number;
|
|
17
|
-
isPlaying: boolean;
|
|
18
|
-
/** Defaults to true. */
|
|
19
|
-
smoothScroll?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* User offsets, in seconds, subtracted from the playback time before matching. Each defaults to 0.
|
|
22
|
-
*/
|
|
23
|
-
globalLyricOffset?: number;
|
|
24
|
-
lyricOffset?: number;
|
|
25
|
-
richsyncOffsetTrim?: number;
|
|
26
|
-
lineOffsetTrim?: number;
|
|
27
|
-
/**
|
|
28
|
-
* Whether the user has passive scrolling switched on. Only unsynced lyrics use it. Defaults to
|
|
29
|
-
* false.
|
|
30
|
-
*/
|
|
31
|
-
passiveScrollEnabled?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* How fast the song moves through its own timeline, as a multiple of real time. Defaults to 1, and
|
|
34
|
-
* zero or less reads as 1 because `isPlaying` is what says a song is stopped. Scales the animations
|
|
35
|
-
* that follow the song; a line's exit, a word's fade and the scroll between lines are the
|
|
36
|
-
* interface's own gestures and keep the timing the theme asked for at every rate.
|
|
37
|
-
*/
|
|
38
|
-
playbackRate?: number;
|
|
39
|
-
/**
|
|
40
|
-
* Whether a paused clock that moves by less than the jump threshold resets the highlight to the
|
|
41
|
-
* new time, as an editor scrubbing a paused song needs. Defaults to false.
|
|
42
|
-
*/
|
|
43
|
-
followPausedSeeks?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Whether every user scroll the host reports can pause autoscroll of synced lyrics. By default
|
|
46
|
-
* the view always holds one scroll back, for the one a refocused window fires, and a host that
|
|
47
|
-
* ticks every frame spends that reserve on each scroll the reader makes. Unsynced lyrics drifting
|
|
48
|
-
* on their own are not covered. Defaults to false.
|
|
49
|
-
*/
|
|
50
|
-
countEveryUserScroll?: boolean;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* A tick with nothing left out. The engine reads every field unconditionally, so the defaults are
|
|
54
|
-
* filled in at the edge rather than guessed at each read.
|
|
55
|
-
*/
|
|
56
|
-
export type ResolvedTickOptions = Required<TickOptions>;
|
|
57
|
-
export interface LyricsRendererDebugSink {
|
|
58
|
-
/**
|
|
59
|
-
* Clears the debug surface and returns a context translated to the given scroll offset.
|
|
60
|
-
*/
|
|
61
|
-
beginFrame(scrollOffset: number): CanvasRenderingContext2D | null;
|
|
62
|
-
resize(): void;
|
|
63
|
-
}
|
|
64
|
-
export interface LyricsRendererHost {
|
|
65
|
-
isViewVisible(): boolean;
|
|
66
|
-
isLoaderActive(): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Reports whether an ad is playing, and lets the host move whatever it shows in place of lyrics
|
|
69
|
-
* into the matching state. One call rather than a query and a command, because the renderer never
|
|
70
|
-
* needs one without the other and the host already knows the answer when it is asked.
|
|
71
|
-
*/
|
|
72
|
-
syncAdState(): boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Resolved per tick rather than handed over once: YouTube Music swaps its scroll container out,
|
|
75
|
-
* and the renderer is constructed before that container exists.
|
|
76
|
-
*/
|
|
77
|
-
getScrollElement(): HTMLElement | null;
|
|
78
|
-
/**
|
|
79
|
-
* Shows or puts away whatever the host offers for resuming autoscroll. The host decides what it
|
|
80
|
-
* looks like and where it lives; the renderer only says whether it is wanted.
|
|
81
|
-
*/
|
|
82
|
-
setResumeAffordanceVisible(visible: boolean): void;
|
|
83
|
-
/**
|
|
84
|
-
* Called when a lyric line is clicked. How the seek reaches the player is the host's business:
|
|
85
|
-
* this extension dispatches an event at the page world, another consumer might set
|
|
86
|
-
* currentTime on a media element directly.
|
|
87
|
-
*/
|
|
88
|
-
seek(timeS: number): void;
|
|
89
|
-
/**
|
|
90
|
-
* Where the view's diagnostics go. The host owns the prefix and whether logging is on at all.
|
|
91
|
-
*/
|
|
92
|
-
log(...args: unknown[]): void;
|
|
93
|
-
/**
|
|
94
|
-
* Stage layout only. Where the lines being sung sit, in the container's coordinates, or null when
|
|
95
|
-
* nothing sung is on stage. Called when it changes. A consumer draws its own backdrop from it,
|
|
96
|
-
* outside the container that themes style.
|
|
97
|
-
*/
|
|
98
|
-
onStageLayout?(box: StageBox | null): void;
|
|
99
|
-
debug?: LyricsRendererDebugSink;
|
|
100
|
-
}
|
|
101
|
-
export type LyricsLayout = "scroll" | "stage";
|
|
102
|
-
export interface LyricsRendererOptions {
|
|
103
|
-
document: Document;
|
|
104
|
-
window: Window;
|
|
105
|
-
/**
|
|
106
|
-
* Where the lyrics are built. `setLyrics` takes one too, for a consumer whose mount only exists
|
|
107
|
-
* once there is something to put in it; the last one given is the one in use.
|
|
108
|
-
*/
|
|
109
|
-
mount?: HTMLElement;
|
|
110
|
-
/**
|
|
111
|
-
* Every member has a default, so a consumer with nothing to say about its surroundings says
|
|
112
|
-
* nothing at all.
|
|
113
|
-
*/
|
|
114
|
-
host?: Partial<LyricsRendererHost>;
|
|
115
|
-
/** `"scroll"` (default) is the scrolling lyrics view. `"stage"` shows only what is being sung. */
|
|
116
|
-
layout?: LyricsLayout;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* One rendered lyrics view, and everything it takes to keep it measured. The consumer owns the
|
|
120
|
-
* clock and the lyrics; the renderer owns the DOM it builds from them and every re-measurement that
|
|
121
|
-
* DOM needs.
|
|
122
|
-
*/
|
|
123
|
-
export interface LyricsRenderer {
|
|
124
|
-
/**
|
|
125
|
-
* Replaces whatever this renderer last built, or, given the `songKey` of the song on screen, swaps
|
|
126
|
-
* these lyrics into it so the lines the two share stay as they were. Every option has a default, so a
|
|
127
|
-
* consumer with an opinion about only one of them says only that one. The mount rides along with the CSS flags
|
|
128
|
-
* rather than taking a parameter of its own: it is an option of this call like the others, and a
|
|
129
|
-
* third parameter would have every caller that only wants to move the mount pass over the two in
|
|
130
|
-
* front of it.
|
|
131
|
-
*/
|
|
132
|
-
setLyrics(lyrics: Lyric[], options?: Partial<SetLyricsOptions> & {
|
|
133
|
-
mount?: HTMLElement;
|
|
134
|
-
}): void;
|
|
135
|
-
/** Updates a late-detected source language and layout without rebuilding lines or animations. */
|
|
136
|
-
setLanguage(language?: string | null): void;
|
|
137
|
-
/**
|
|
138
|
-
* Applies a compiled theme. The `blyrics-*` configuration in its comments becomes the module's
|
|
139
|
-
* theme settings, and the stylesheet itself is applied to the document this renderer builds in.
|
|
140
|
-
*
|
|
141
|
-
* The settings are the module's rather than this instance's, so a second renderer in the same
|
|
142
|
-
* realm renders against the last theme any of them was given. The stylesheet is per document.
|
|
143
|
-
*
|
|
144
|
-
* @returns Whether a setting the lines are built out of changed, so the caller can hand the
|
|
145
|
-
* lyrics back. The renderer does not hold them, so it cannot rebuild them itself.
|
|
146
|
-
*/
|
|
147
|
-
setTheme(css: string): boolean;
|
|
148
|
-
/**
|
|
149
|
-
* Renders the view at a playback time, in seconds. The module owns no clock, so this is the whole
|
|
150
|
-
* of how the song reaches it, and the answer says whether there was a view here to render.
|
|
151
|
-
*/
|
|
152
|
-
tick(currentTimeS: number, options: TickOptions): AnimationTickStatus;
|
|
153
|
-
/**
|
|
154
|
-
* Re-reads the layout and renders nothing, leaving the lines it just re-read to the next tick.
|
|
155
|
-
*
|
|
156
|
-
* @param measureLines - Defaults to true, and asking is not the same as getting: lines the page is
|
|
157
|
-
* not rendering measure as zero height at zero offset, so the renderer holds the line
|
|
158
|
-
* measurement back itself while they are off the screen. Pass false to rewrite only the padding,
|
|
159
|
-
* which is sized against the viewport and so is knowable either way.
|
|
160
|
-
*/
|
|
161
|
-
relayout(measureLines?: boolean): void;
|
|
162
|
-
/**
|
|
163
|
-
* Drops the song and the DOM built for it. The renderer built that DOM, so it takes it away again.
|
|
164
|
-
*/
|
|
165
|
-
clear(): void;
|
|
166
|
-
/**
|
|
167
|
-
* Clears, and gives up the window and document it was holding. Final: everything here does
|
|
168
|
-
* nothing afterwards.
|
|
169
|
-
*/
|
|
170
|
-
destroy(): void;
|
|
171
|
-
/**
|
|
172
|
-
* The user scrolled the view. Whether that resumes sooner because the lyrics are unsynced is the
|
|
173
|
-
* renderer's own reading of what it has on screen, not something the caller has to supply.
|
|
174
|
-
*/
|
|
175
|
-
noteUserScroll(): void;
|
|
176
|
-
/**
|
|
177
|
-
* The document this view is in was shown or hidden. Nothing is reset either way, and a view told
|
|
178
|
-
* nothing goes on rendering: this is where the view records what it decided about the animations
|
|
179
|
-
* it is running, and only when a theme has asked for the timing diagnostics.
|
|
180
|
-
*/
|
|
181
|
-
noteVisibilityChange(): void;
|
|
182
|
-
resumeAutoscroll(): void;
|
|
183
|
-
/**
|
|
184
|
-
* Takes this view's lines off the screen, keeping the container they were in, and reports whether
|
|
185
|
-
* there were any there to take. For a consumer that is about to build the next song into the same
|
|
186
|
-
* place and wants the last one gone in the meantime: `clear` is the one that drops the song, and
|
|
187
|
-
* this one drops only what is on the screen.
|
|
188
|
-
*/
|
|
189
|
-
clearOnScreenLyrics(): boolean;
|
|
190
|
-
/**
|
|
191
|
-
* Re-measures the lines on the next frame and renders the view again against them. This is the door
|
|
192
|
-
* a consumer knocks on after streaming in a translation or romanization, and it is what slides the
|
|
193
|
-
* lines the new decoration moved from where they were to where it put them, together with any
|
|
194
|
-
* surviving decorator that shifted within its own line, so the rest of the lyric eases down rather
|
|
195
|
-
* than jumping. The slide honours reduced motion and `--blyrics-animate-decoration-entry`; with
|
|
196
|
-
* either off the lines are re-measured with no slide. The predicate is the caller's half of whether
|
|
197
|
-
* that frame does anything, and only that half: whether the lines are on the screen to be measured
|
|
198
|
-
* at all is the renderer's own question, and it asks it itself.
|
|
199
|
-
*
|
|
200
|
-
* @param isTicking - Whether whoever drives this view is still driving it, asked on the frame
|
|
201
|
-
* rather than now. A driver that has stopped is one whose lines may no longer be rendered, and
|
|
202
|
-
* an unrendered line measures as zero height at zero offset, which is what every scroll target
|
|
203
|
-
* for the rest of the song would then be read off. A false answer declines both the
|
|
204
|
-
* re-measurement and the render.
|
|
205
|
-
* @param retick - Runs after the re-measurement, on the frame.
|
|
206
|
-
*/
|
|
207
|
-
scheduleLyricPositionUpdate(isTicking: () => boolean, retick: () => void): void;
|
|
208
|
-
/**
|
|
209
|
-
* Renders this view again against the last player snapshot, measuring nothing, which is what an
|
|
210
|
-
* offset nudge needs.
|
|
211
|
-
*
|
|
212
|
-
* The snapshot is the module's rather than this renderer's: whichever view in this bundle ticked
|
|
213
|
-
* last is the one that wrote it, so two renderers in one realm replay each other's clock here.
|
|
214
|
-
* That is the same constraint the theme settings are under, and `resetPlaybackClock` is what
|
|
215
|
-
* forgets the snapshot.
|
|
216
|
-
*
|
|
217
|
-
* @param buildOptions - Given the snapshot the tick will run against, returns what to render it
|
|
218
|
-
* with. Built here rather than handed in, so a caller that reads its settings at tick time still
|
|
219
|
-
* reads them at tick time.
|
|
220
|
-
*/
|
|
221
|
-
retickFromPlaybackClock(buildOptions: (eventCreationTime: number, isPlaying: boolean) => TickOptions): AnimationTickStatus;
|
|
222
|
-
/** The element this view built its lines into, and null before it has built any. */
|
|
223
|
-
readonly container: HTMLElement | null;
|
|
224
|
-
/**
|
|
225
|
-
* The render records this view built, which are the view's own live state rather than a copy of
|
|
226
|
-
* it: each one holds the line's element and the `Animation` objects running against it.
|
|
227
|
-
*
|
|
228
|
-
* `readonly` freezes the array and nothing else. The records are writable, deliberately, because
|
|
229
|
-
* rewriting a line's time or hanging a translation off its element is how a consumer decorates a
|
|
230
|
-
* song that is already built. What it does not do is reach a second view: these elements belong
|
|
231
|
-
* to this renderer, so a consumer with two of them decorates each one.
|
|
232
|
-
*/
|
|
233
|
-
readonly lines: readonly LineData[];
|
|
234
|
-
/** How the loaded lyrics are timed, and `"none"` once there are none loaded. */
|
|
235
|
-
readonly syncType: LyricSyncType;
|
|
236
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/view.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { type AnimationEngineInstance } from "./engine/instance.js";
|
|
2
|
-
import { type LineData } from "./inject.js";
|
|
3
|
-
import type { Lyric } from "./types.js";
|
|
4
|
-
export interface SetLyricsOptions {
|
|
5
|
-
/** BCP 47 language of the original lyrics. Kana/Hangul provide a fallback when omitted. */
|
|
6
|
-
language?: string | null;
|
|
7
|
-
/**
|
|
8
|
-
* Whether the loader is still covering the view. Recorded on the container for CSS to key on.
|
|
9
|
-
*/
|
|
10
|
-
loaderVisible: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* These lyrics are a "not found" placeholder rather than a real result.
|
|
13
|
-
*/
|
|
14
|
-
noLyrics: boolean;
|
|
15
|
-
/** Who wrote the song, shown after the last line. */
|
|
16
|
-
songwriters?: readonly string[];
|
|
17
|
-
/**
|
|
18
|
-
* Which song these lyrics are for. Lyrics given with the key the view on screen was given are
|
|
19
|
-
* swapped into it, so lines the two share stay as they were; without a key, or with another one,
|
|
20
|
-
* the view is built anew.
|
|
21
|
-
*/
|
|
22
|
-
songKey?: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Replaces whatever the mount holds with a container built from these lyrics, and hands the render
|
|
26
|
-
* records, the container and its measured size to the engine that animates them.
|
|
27
|
-
*
|
|
28
|
-
* @param engine - Instance that owns the document to build in and the host to seek through
|
|
29
|
-
* @param mount - Element whose children the built container replaces
|
|
30
|
-
* @param lyrics - Lines to render, left untouched
|
|
31
|
-
* @param options - What the container records for CSS to key on
|
|
32
|
-
*/
|
|
33
|
-
export declare function setLyrics(engine: AnimationEngineInstance, mount: HTMLElement, lyrics: Lyric[], options: SetLyricsOptions): void;
|
|
34
|
-
/**
|
|
35
|
-
* Where each line of a swap was before it, in the container's coordinates, and how tall it was: a
|
|
36
|
-
* kept line's own place, and for a line built in place of one, the place of the line it replaced.
|
|
37
|
-
*/
|
|
38
|
-
export type SwapPositions = Map<LineData, {
|
|
39
|
-
position: number;
|
|
40
|
-
height: number;
|
|
41
|
-
motionOffset: number;
|
|
42
|
-
}>;
|
|
43
|
-
/**
|
|
44
|
-
* Swaps these lyrics into the view already on screen, rebuilding only the lines that differ, and
|
|
45
|
-
* answers where each line was before so the caller can carry the view across the change. Answers
|
|
46
|
-
* null without touching anything when the view cannot be swapped, and the caller builds it whole.
|
|
47
|
-
*
|
|
48
|
-
* Nothing about where the reader is goes back to the start of a song: the scroll, a pause the reader
|
|
49
|
-
* scrolled into, and the scrolls the engine is waiting to swallow are all the song's before.
|
|
50
|
-
*/
|
|
51
|
-
export declare function swapLyrics(engine: AnimationEngineInstance, mount: HTMLElement, lyrics: Lyric[], options: SetLyricsOptions): SwapPositions | null;
|