@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/inject.js
DELETED
|
@@ -1,591 +0,0 @@
|
|
|
1
|
-
// Builds what goes inside a lyric line: the main and background content lines, the bidi runs inside
|
|
2
|
-
// them, the word groups and the timed word spans the sweep animates, and the two decorators that
|
|
3
|
-
// hang a translation or a romanization off a line that is already built. `view.ts` builds the line
|
|
4
|
-
// and the container around it.
|
|
5
|
-
//
|
|
6
|
-
// The structure emitted here is as much published contract as the names written into it.
|
|
7
|
-
// `constants.ts` says why a class name cannot be renamed; the nesting is under the same rule,
|
|
8
|
-
// because a marketplace theme selects on the shape as well as on the names.
|
|
9
|
-
//
|
|
10
|
-
// A part is not a word. Providers hand over parts that run to several words, and the unit the sweep
|
|
11
|
-
// animates is one word, so every part is split on whitespace with its timing pro-rated across the
|
|
12
|
-
// split by character count. A line that arrives with no timed parts at all is rebuilt the same way
|
|
13
|
-
// into zero duration words, so line synced lyrics reach the DOM the sweep already knows.
|
|
14
|
-
import { releasePart } from "./engine/lineAnimationState.js";
|
|
15
|
-
import { normalizeLanguage } from "./language.js";
|
|
16
|
-
import { BACKGROUND_LINE_CLASS, BACKGROUND_LYRIC_CLASS, BIDI_RUN_CLASS, BIDI_SENSITIVE_CLASS, CONTENT_LINE_CLASS, EXPLICIT_WORD_CLASS, HIGHLIGHT_RUN_CLASS, LETTER_CLASS, LINE_MAIN_CLASS, LINE_SYNCED_WORD_CLASS, LONG_WORD_GROUP_CLASS, ROMANIZED_LYRICS_CLASS, RTL_CLASS, SWEEP_CELL_CLASS, SWEEP_MASK_CLASS, SWEEP_TEXT_CLASS, TRANSLATED_LYRICS_CLASS, WORD_CLASS, WORD_GROUP_CLASS, WORD_HIGHLIGHT_CLASS, WORD_HIGHLIGHT_CONTEXT_CLASS, WORD_HIGHLIGHT_LETTERED_CLASS, WORD_HIGHLIGHT_SWEEP_CLASS, WORD_STATE_ATTR, WORD_STATE_UPCOMING, ZERO_DURATION_ANIMATION_CLASS, } from "./constants.js";
|
|
17
|
-
import { letterClusters } from "./letters.js";
|
|
18
|
-
import { getSeekTimeFromClick } from "./seek.js";
|
|
19
|
-
import { isSameText, testJoiningScript, testRtl } from "./text.js";
|
|
20
|
-
import { registerThemeSetting } from "./themeSettings.js";
|
|
21
|
-
export let disableRichsync = registerThemeSetting("blyrics-disable-richsync", false, true);
|
|
22
|
-
let lineSyncedAnimationDelay = registerThemeSetting("blyrics-line-synced-animation-delay", 50, true);
|
|
23
|
-
let longWordThreshold = registerThemeSetting("blyrics-long-word-threshold", 1500, true);
|
|
24
|
-
let longWordWrapThreshold = registerThemeSetting("blyrics-long-word-wrap-threshold", 10, true);
|
|
25
|
-
let letterWave = registerThemeSetting("blyrics-letter-wave", true, true);
|
|
26
|
-
export const hideCredits = registerThemeSetting("blyrics-hide-credits", false, true);
|
|
27
|
-
const LTR_SCRIPT_REGEX = /[\p{Script=Latin}\p{Script=Greek}\p{Script=Cyrillic}\p{Script=Han}\p{Script=Hangul}\p{Script=Hiragana}\p{Script=Katakana}]/u;
|
|
28
|
-
const SPACE_REGEX = /^\s+$/u;
|
|
29
|
-
export function findNearestAgent(lyrics, fromIndex) {
|
|
30
|
-
// Look in the downwards direction first
|
|
31
|
-
for (let i = fromIndex + 1; i < lyrics.length; i++) {
|
|
32
|
-
if (!lyrics[i].isInstrumental && lyrics[i].agent) {
|
|
33
|
-
return lyrics[i].agent;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
for (let i = fromIndex - 1; i >= 0; i--) {
|
|
37
|
-
if (!lyrics[i].isInstrumental && lyrics[i].agent) {
|
|
38
|
-
return lyrics[i].agent;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
export function isNearestLyricRtl(lyrics, fromIndex) {
|
|
44
|
-
// Look in the downwards direction first
|
|
45
|
-
for (let i = fromIndex + 1; i < lyrics.length; i++) {
|
|
46
|
-
if (!lyrics[i].isInstrumental && lyrics[i].words?.trim()) {
|
|
47
|
-
return testRtl(lyrics[i].words);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
for (let i = fromIndex - 1; i >= 0; i--) {
|
|
51
|
-
if (!lyrics[i].isInstrumental && lyrics[i].words?.trim()) {
|
|
52
|
-
return testRtl(lyrics[i].words);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
// -- Lyric shape --------------------------------------------
|
|
58
|
-
// A line whose parts are missing, empty or overridden by the theme is rebuilt as line synced words,
|
|
59
|
-
// which carry no duration, so only pre-existing timed parts count as rich sync.
|
|
60
|
-
export function deriveSyncType(lyrics) {
|
|
61
|
-
const hasTimedParts = !disableRichsync.getBooleanValue() &&
|
|
62
|
-
lyrics.some(item => !item.isInstrumental && item.parts?.some(part => part.durationMs !== 0) === true);
|
|
63
|
-
if (hasTimedParts)
|
|
64
|
-
return "richsync";
|
|
65
|
-
return lyrics.every(item => item.startTimeMs === 0) ? "none" : "synced";
|
|
66
|
-
}
|
|
67
|
-
function newPartData(part, span, highlight, wobbleElements, letterElements, highlightLetterElements, sweep) {
|
|
68
|
-
return {
|
|
69
|
-
time: part.startTimeMs / 1000,
|
|
70
|
-
duration: part.durationMs / 1000,
|
|
71
|
-
lyricElement: span,
|
|
72
|
-
highlightElement: highlight,
|
|
73
|
-
sweep,
|
|
74
|
-
sweepContext: highlight.classList.contains(WORD_HIGHLIGHT_CONTEXT_CLASS) ? {} : undefined,
|
|
75
|
-
letterElements,
|
|
76
|
-
highlightLetterElements,
|
|
77
|
-
wobbleElements,
|
|
78
|
-
animations: [],
|
|
79
|
-
wordState: WORD_STATE_UPCOMING,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
export function newLineData(lyricElement, startTimeMs, durationMs) {
|
|
83
|
-
return {
|
|
84
|
-
lyricElement,
|
|
85
|
-
time: startTimeMs / 1000,
|
|
86
|
-
duration: durationMs / 1000,
|
|
87
|
-
parts: [],
|
|
88
|
-
isScrolled: false,
|
|
89
|
-
isAnimationPlayStatePlaying: false,
|
|
90
|
-
accumulatedOffsetMs: 0,
|
|
91
|
-
isAnimating: false,
|
|
92
|
-
lastAnimSetupAt: 0,
|
|
93
|
-
isSelected: false,
|
|
94
|
-
height: -1,
|
|
95
|
-
position: -1,
|
|
96
|
-
decorations: new Map(),
|
|
97
|
-
animations: [],
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function detectDirection(text) {
|
|
101
|
-
for (const char of text) {
|
|
102
|
-
if (testRtl(char))
|
|
103
|
-
return "rtl";
|
|
104
|
-
if (LTR_SCRIPT_REGEX.test(char))
|
|
105
|
-
return "ltr";
|
|
106
|
-
}
|
|
107
|
-
return "auto";
|
|
108
|
-
}
|
|
109
|
-
export function applyDirection(element, text) {
|
|
110
|
-
const direction = detectDirection(text);
|
|
111
|
-
element.dir = "auto";
|
|
112
|
-
if (direction === "rtl") {
|
|
113
|
-
element.classList.add(RTL_CLASS);
|
|
114
|
-
element.dataset.direction = "rtl";
|
|
115
|
-
}
|
|
116
|
-
else if (direction === "ltr") {
|
|
117
|
-
element.dataset.direction = "ltr";
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function applyBidiSensitivity(element, text) {
|
|
121
|
-
if (testRtl(text)) {
|
|
122
|
-
element.classList.add(BIDI_SENSITIVE_CLASS);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function splitPartIntoTokens(part) {
|
|
126
|
-
const chunks = part.words.match(/\s+|\S+/gu) ?? [];
|
|
127
|
-
if (chunks.length === 0)
|
|
128
|
-
return [];
|
|
129
|
-
const tokens = [];
|
|
130
|
-
let spaceChars = 0;
|
|
131
|
-
for (const chunk of chunks) {
|
|
132
|
-
if (SPACE_REGEX.test(chunk)) {
|
|
133
|
-
tokens.push({ kind: "space", text: chunk });
|
|
134
|
-
spaceChars += chunk.length;
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
tokens.push({
|
|
138
|
-
kind: "part",
|
|
139
|
-
text: chunk,
|
|
140
|
-
part: {
|
|
141
|
-
words: chunk,
|
|
142
|
-
isBackground: part.isBackground,
|
|
143
|
-
backgroundGroup: part.backgroundGroup,
|
|
144
|
-
explicit: part.explicit,
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
const nonWhiteSpaceChars = part.words.length - spaceChars;
|
|
149
|
-
let cursor = 0;
|
|
150
|
-
return tokens.map(t => {
|
|
151
|
-
if (t.kind === "part") {
|
|
152
|
-
const startTimeMs = part.startTimeMs + Math.round((part.durationMs * cursor) / nonWhiteSpaceChars);
|
|
153
|
-
const endTimeMs = part.startTimeMs + Math.round((part.durationMs * (cursor + t.text.length)) / nonWhiteSpaceChars);
|
|
154
|
-
cursor += t.text.length;
|
|
155
|
-
return {
|
|
156
|
-
...t,
|
|
157
|
-
part: {
|
|
158
|
-
...t.part,
|
|
159
|
-
startTimeMs,
|
|
160
|
-
durationMs: endTimeMs - startTimeMs,
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
return t;
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
function normalizeParts(parts) {
|
|
168
|
-
return parts.flatMap(splitPartIntoTokens);
|
|
169
|
-
}
|
|
170
|
-
function groupTokensByWord(tokens, splitBackgroundGroups) {
|
|
171
|
-
const groups = [];
|
|
172
|
-
let current = null;
|
|
173
|
-
const flush = () => {
|
|
174
|
-
if (current && current.tokens.length > 0) {
|
|
175
|
-
groups.push(current);
|
|
176
|
-
}
|
|
177
|
-
current = null;
|
|
178
|
-
};
|
|
179
|
-
for (const token of tokens) {
|
|
180
|
-
if (token.kind === "space") {
|
|
181
|
-
flush();
|
|
182
|
-
groups.push(token);
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
const isBackground = token.part?.isBackground === true;
|
|
186
|
-
const backgroundGroup = splitBackgroundGroups ? token.part?.backgroundGroup : undefined;
|
|
187
|
-
if (!current || current.isBackground !== isBackground || current.backgroundGroup !== backgroundGroup) {
|
|
188
|
-
flush();
|
|
189
|
-
current = { text: "", isBackground, backgroundGroup, tokens: [] };
|
|
190
|
-
}
|
|
191
|
-
current.text += token.text;
|
|
192
|
-
current.tokens.push(token);
|
|
193
|
-
}
|
|
194
|
-
flush();
|
|
195
|
-
return groups;
|
|
196
|
-
}
|
|
197
|
-
function appendLongWordBreaks(doc, span, clusters, threshold) {
|
|
198
|
-
if (clusters.length <= threshold) {
|
|
199
|
-
span.textContent = clusters.join("");
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
for (let i = 0; i < clusters.length; i += threshold) {
|
|
203
|
-
span.appendChild(doc.createTextNode(clusters.slice(i, i + threshold).join("")));
|
|
204
|
-
if (i + threshold < clusters.length) {
|
|
205
|
-
span.appendChild(doc.createElement("wbr"));
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return true;
|
|
209
|
-
}
|
|
210
|
-
function appendLetters(doc, wordElement, chars) {
|
|
211
|
-
wordElement.style.setProperty("--letters", String(chars.length));
|
|
212
|
-
return chars.map(char => {
|
|
213
|
-
const letter = doc.createElement("span");
|
|
214
|
-
letter.classList.add(LETTER_CLASS);
|
|
215
|
-
letter.textContent = char;
|
|
216
|
-
wordElement.appendChild(letter);
|
|
217
|
-
return letter;
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
function fillWordText(doc, host, clusters, wrapThreshold, perLetter, preserveJoining) {
|
|
221
|
-
if (perLetter)
|
|
222
|
-
return appendLetters(doc, host, clusters);
|
|
223
|
-
if (preserveJoining)
|
|
224
|
-
host.textContent = clusters.join("");
|
|
225
|
-
else
|
|
226
|
-
appendLongWordBreaks(doc, host, clusters, wrapThreshold);
|
|
227
|
-
return undefined;
|
|
228
|
-
}
|
|
229
|
-
export function createSweepCell(doc, host, fill) {
|
|
230
|
-
const mask = doc.createElement("span");
|
|
231
|
-
mask.classList.add(SWEEP_MASK_CLASS);
|
|
232
|
-
const text = doc.createElement("span");
|
|
233
|
-
text.classList.add(SWEEP_TEXT_CLASS);
|
|
234
|
-
mask.appendChild(text);
|
|
235
|
-
const letters = fill(text);
|
|
236
|
-
host.classList.add(SWEEP_CELL_CLASS);
|
|
237
|
-
host.appendChild(mask);
|
|
238
|
-
return { mask, text, letters };
|
|
239
|
-
}
|
|
240
|
-
/** Makes each letter of a word that flows inline its own sweep cell, holding the letter's text. */
|
|
241
|
-
function createLetterSweepCells(doc, letters) {
|
|
242
|
-
return letters.map(letter => {
|
|
243
|
-
const text = letter.textContent ?? "";
|
|
244
|
-
letter.textContent = "";
|
|
245
|
-
return createSweepCell(doc, letter, into => {
|
|
246
|
-
into.appendChild(doc.createTextNode(text));
|
|
247
|
-
return undefined;
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
function createTimedWordSpan(doc, part, wrapThreshold, perLetter, preserveJoining, atomic) {
|
|
252
|
-
const span = doc.createElement("span");
|
|
253
|
-
const highlight = doc.createElement("span");
|
|
254
|
-
highlight.classList.add(WORD_HIGHLIGHT_CLASS);
|
|
255
|
-
let sweep;
|
|
256
|
-
let letters;
|
|
257
|
-
let highlightLetters;
|
|
258
|
-
const clusters = perLetter || (!preserveJoining && part.words.length > wrapThreshold) ? letterClusters(part.words) : [part.words];
|
|
259
|
-
for (const wordElement of [span, highlight]) {
|
|
260
|
-
wordElement.classList.add(WORD_CLASS);
|
|
261
|
-
wordElement.dir = "auto";
|
|
262
|
-
if (part.durationMs === 0) {
|
|
263
|
-
wordElement.classList.add(ZERO_DURATION_ANIMATION_CLASS);
|
|
264
|
-
wordElement.classList.add(LINE_SYNCED_WORD_CLASS);
|
|
265
|
-
}
|
|
266
|
-
if (testRtl(part.words))
|
|
267
|
-
wordElement.classList.add(RTL_CLASS);
|
|
268
|
-
if (part.durationMs > longWordThreshold.getNumberValue())
|
|
269
|
-
wordElement.dataset.longWord = "true";
|
|
270
|
-
if (part.isBackground)
|
|
271
|
-
wordElement.classList.add(BACKGROUND_LYRIC_CLASS);
|
|
272
|
-
if (part.explicit)
|
|
273
|
-
wordElement.classList.add(EXPLICIT_WORD_CLASS);
|
|
274
|
-
if (perLetter) {
|
|
275
|
-
wordElement.classList.add("blyrics-word--lettered");
|
|
276
|
-
if (wordElement === highlight)
|
|
277
|
-
wordElement.classList.add(WORD_HIGHLIGHT_LETTERED_CLASS);
|
|
278
|
-
}
|
|
279
|
-
if (wordElement === highlight && atomic) {
|
|
280
|
-
const cell = createSweepCell(doc, highlight, into => fillWordText(doc, into, clusters, wrapThreshold, perLetter, preserveJoining));
|
|
281
|
-
sweep = [cell];
|
|
282
|
-
highlightLetters = cell.letters;
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
const collected = fillWordText(doc, wordElement, clusters, wrapThreshold, perLetter, preserveJoining);
|
|
286
|
-
if (wordElement === span)
|
|
287
|
-
letters = collected;
|
|
288
|
-
else
|
|
289
|
-
highlightLetters = collected;
|
|
290
|
-
if (wordElement === highlight && collected)
|
|
291
|
-
sweep = createLetterSweepCells(doc, collected);
|
|
292
|
-
}
|
|
293
|
-
if (wordElement === highlight && sweep)
|
|
294
|
-
highlight.classList.add(WORD_HIGHLIGHT_SWEEP_CLASS);
|
|
295
|
-
else if (wordElement === highlight)
|
|
296
|
-
highlight.classList.add(WORD_HIGHLIGHT_CONTEXT_CLASS);
|
|
297
|
-
wordElement.dataset.time = String(part.startTimeMs / 1000);
|
|
298
|
-
wordElement.dataset.duration = String(part.durationMs / 1000);
|
|
299
|
-
wordElement.dataset.content = part.words;
|
|
300
|
-
wordElement.setAttribute(WORD_STATE_ATTR, WORD_STATE_UPCOMING);
|
|
301
|
-
wordElement.style.setProperty("--blyrics-duration", part.durationMs + "ms");
|
|
302
|
-
}
|
|
303
|
-
return { span, highlight, letters, highlightLetters, sweep };
|
|
304
|
-
}
|
|
305
|
-
function createWordGroup(doc, group, lineData, wordsFlowInline) {
|
|
306
|
-
const wrapThreshold = Math.max(1, longWordWrapThreshold.getNumberValue());
|
|
307
|
-
// Atomic grapheme spans disrupt the browser's bidi ordering inside a mixed word.
|
|
308
|
-
const mixedDirection = testRtl(group.text) && [...group.text].some(char => /[\p{Letter}\p{Number}]/u.test(char) && !testRtl(char));
|
|
309
|
-
const preserveJoining = testJoiningScript(group.text);
|
|
310
|
-
const perLetter = letterWave.getBooleanValue() && !preserveJoining && !mixedDirection;
|
|
311
|
-
const isLongGroup = group.text.length > wrapThreshold * 2 && letterClusters(group.text).length > wrapThreshold * 2;
|
|
312
|
-
const lyricGroup = doc.createElement("span");
|
|
313
|
-
const highlightGroup = doc.createElement("span");
|
|
314
|
-
// A word that is its own inline-block box can hold the sweep's block layers. Long groups and
|
|
315
|
-
// bidi-sensitive rows lay their words out inline, where a word can break across lines.
|
|
316
|
-
const atomic = !wordsFlowInline && !isLongGroup;
|
|
317
|
-
for (const groupElement of [lyricGroup, highlightGroup]) {
|
|
318
|
-
groupElement.classList.add(WORD_GROUP_CLASS);
|
|
319
|
-
groupElement.dir = "auto";
|
|
320
|
-
groupElement.dataset.content = group.text;
|
|
321
|
-
if (isLongGroup) {
|
|
322
|
-
groupElement.classList.add(LONG_WORD_GROUP_CLASS);
|
|
323
|
-
}
|
|
324
|
-
if (group.isBackground) {
|
|
325
|
-
groupElement.classList.add(BACKGROUND_LYRIC_CLASS);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
for (const token of group.tokens) {
|
|
329
|
-
if (token.kind === "space")
|
|
330
|
-
continue;
|
|
331
|
-
const { span, highlight, letters, highlightLetters, sweep } = createTimedWordSpan(doc, token.part, wrapThreshold, perLetter, preserveJoining, atomic);
|
|
332
|
-
const wobbleElements = lyricGroup.childNodes.length === 0 ? [lyricGroup, highlightGroup] : [];
|
|
333
|
-
lineData.parts.push(newPartData(token.part, span, highlight, wobbleElements, letters, highlightLetters, sweep));
|
|
334
|
-
lyricGroup.appendChild(span);
|
|
335
|
-
highlightGroup.appendChild(highlight);
|
|
336
|
-
}
|
|
337
|
-
return { lyricGroup, highlightGroup };
|
|
338
|
-
}
|
|
339
|
-
function createContentLine(doc, className, text) {
|
|
340
|
-
const line = doc.createElement("div");
|
|
341
|
-
line.classList.add(className);
|
|
342
|
-
applyDirection(line, text);
|
|
343
|
-
applyBidiSensitivity(line, text);
|
|
344
|
-
return line;
|
|
345
|
-
}
|
|
346
|
-
function createBidiRun(doc, text) {
|
|
347
|
-
const run = doc.createElement("span");
|
|
348
|
-
run.classList.add(BIDI_RUN_CLASS);
|
|
349
|
-
applyDirection(run, text);
|
|
350
|
-
return run;
|
|
351
|
-
}
|
|
352
|
-
function createHighlightRun(doc, text) {
|
|
353
|
-
const run = createBidiRun(doc, text);
|
|
354
|
-
run.classList.add(HIGHLIGHT_RUN_CLASS);
|
|
355
|
-
run.setAttribute("aria-hidden", "true");
|
|
356
|
-
return run;
|
|
357
|
-
}
|
|
358
|
-
// A background gap must carry the background size too, or it renders full-size and the gap looks oversized.
|
|
359
|
-
function createSpaceNode(doc, text, isBackground) {
|
|
360
|
-
if (!isBackground)
|
|
361
|
-
return doc.createTextNode(text);
|
|
362
|
-
const span = doc.createElement("span");
|
|
363
|
-
span.classList.add(BACKGROUND_LYRIC_CLASS);
|
|
364
|
-
span.textContent = text;
|
|
365
|
-
return span;
|
|
366
|
-
}
|
|
367
|
-
export function createLyricsLine(doc, parts, line, lyricElement, options = { splitBackgroundLine: true }) {
|
|
368
|
-
const lineText = parts.map(part => part.words).join("");
|
|
369
|
-
const mainText = options.splitBackgroundLine
|
|
370
|
-
? parts
|
|
371
|
-
.filter(part => part.isBackground !== true)
|
|
372
|
-
.map(part => part.words)
|
|
373
|
-
.join("")
|
|
374
|
-
: lineText;
|
|
375
|
-
const backgroundTextOf = (group) => parts
|
|
376
|
-
.filter(part => part.isBackground === true && (part.backgroundGroup ?? 0) === group)
|
|
377
|
-
.map(part => part.words)
|
|
378
|
-
.join("");
|
|
379
|
-
const main = createContentLine(doc, LINE_MAIN_CLASS, mainText);
|
|
380
|
-
const mainRun = createBidiRun(doc, mainText);
|
|
381
|
-
const mainHighlightRun = createHighlightRun(doc, mainText);
|
|
382
|
-
const groupedTokens = groupTokensByWord(normalizeParts(parts), options.splitBackgroundLine);
|
|
383
|
-
const backgroundRows = new Map();
|
|
384
|
-
const backgroundRowOf = (group) => {
|
|
385
|
-
let row = backgroundRows.get(group);
|
|
386
|
-
if (!row) {
|
|
387
|
-
const text = backgroundTextOf(group);
|
|
388
|
-
row = {
|
|
389
|
-
line: createContentLine(doc, BACKGROUND_LINE_CLASS, text),
|
|
390
|
-
run: createBidiRun(doc, text),
|
|
391
|
-
highlightRun: createHighlightRun(doc, text),
|
|
392
|
-
used: false,
|
|
393
|
-
};
|
|
394
|
-
row.line.appendChild(row.highlightRun);
|
|
395
|
-
row.line.appendChild(row.run);
|
|
396
|
-
backgroundRows.set(group, row);
|
|
397
|
-
}
|
|
398
|
-
return row;
|
|
399
|
-
};
|
|
400
|
-
backgroundRowOf(0);
|
|
401
|
-
let pendingForegroundSpace = "";
|
|
402
|
-
let pendingBackgroundSpace = "";
|
|
403
|
-
main.appendChild(mainHighlightRun);
|
|
404
|
-
main.appendChild(mainRun);
|
|
405
|
-
for (const item of groupedTokens) {
|
|
406
|
-
if ("kind" in item) {
|
|
407
|
-
// Is a RenderToken, not a WordGroup, only whitespace should enter this path
|
|
408
|
-
pendingForegroundSpace += item.text;
|
|
409
|
-
pendingBackgroundSpace += item.text;
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
const shouldUseBackgroundLine = options.splitBackgroundLine && item.isBackground;
|
|
413
|
-
const backgroundRow = shouldUseBackgroundLine ? backgroundRowOf(item.backgroundGroup ?? 0) : null;
|
|
414
|
-
const target = backgroundRow ? backgroundRow.run : mainRun;
|
|
415
|
-
const highlightRun = backgroundRow ? backgroundRow.highlightRun : mainHighlightRun;
|
|
416
|
-
const pendingSpace = shouldUseBackgroundLine ? pendingBackgroundSpace : pendingForegroundSpace;
|
|
417
|
-
if (target.childNodes.length > 0 && pendingSpace.length > 0) {
|
|
418
|
-
target.appendChild(createSpaceNode(doc, pendingSpace, shouldUseBackgroundLine));
|
|
419
|
-
highlightRun.appendChild(createSpaceNode(doc, pendingSpace, shouldUseBackgroundLine));
|
|
420
|
-
}
|
|
421
|
-
const contentLine = backgroundRow ? backgroundRow.line : main;
|
|
422
|
-
const { lyricGroup, highlightGroup } = createWordGroup(doc, item, line, contentLine.classList.contains(BIDI_SENSITIVE_CLASS));
|
|
423
|
-
target.appendChild(lyricGroup);
|
|
424
|
-
highlightRun.appendChild(highlightGroup);
|
|
425
|
-
if (backgroundRow) {
|
|
426
|
-
backgroundRow.used = true;
|
|
427
|
-
pendingBackgroundSpace = "";
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
pendingForegroundSpace = "";
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
const usedBackgroundRows = [...backgroundRows]
|
|
435
|
-
.filter(([, row]) => row.used)
|
|
436
|
-
.sort(([a], [b]) => a - b)
|
|
437
|
-
.map(([, row]) => row);
|
|
438
|
-
lyricElement.appendChild(main);
|
|
439
|
-
for (const row of usedBackgroundRows)
|
|
440
|
-
lyricElement.appendChild(row.line);
|
|
441
|
-
return main;
|
|
442
|
-
}
|
|
443
|
-
export function buildLineSyncedParts(item) {
|
|
444
|
-
const parts = [];
|
|
445
|
-
const tokens = item.words.match(/\s+|\S+/gu) ?? [];
|
|
446
|
-
let wordIndex = 0;
|
|
447
|
-
for (const token of tokens) {
|
|
448
|
-
const isSpace = SPACE_REGEX.test(token);
|
|
449
|
-
const startTimeMs = item.startTimeMs + wordIndex * lineSyncedAnimationDelay.getNumberValue();
|
|
450
|
-
parts.push({
|
|
451
|
-
startTimeMs,
|
|
452
|
-
words: token,
|
|
453
|
-
durationMs: 0,
|
|
454
|
-
});
|
|
455
|
-
if (!isSpace) {
|
|
456
|
-
wordIndex += 1;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
return parts;
|
|
460
|
-
}
|
|
461
|
-
export function addSeekHandler(seek, lyricElement, allZero) {
|
|
462
|
-
if (allZero) {
|
|
463
|
-
lyricElement.style.cursor = "unset";
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
lyricElement.addEventListener("click", event => {
|
|
467
|
-
const seekTime = getSeekTimeFromClick(event, lyricElement);
|
|
468
|
-
if (seekTime === null)
|
|
469
|
-
return;
|
|
470
|
-
seek(seekTime);
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
function repeatsLine(lyricElement, text) {
|
|
474
|
-
const mainRun = [
|
|
475
|
-
...(lyricElement.querySelector(`:scope > .${LINE_MAIN_CLASS}`)?.querySelectorAll(`:scope > .${BIDI_RUN_CLASS}`) ??
|
|
476
|
-
[]),
|
|
477
|
-
].find(run => !run.classList.contains(HIGHLIGHT_RUN_CLASS));
|
|
478
|
-
return mainRun?.textContent != null && isSameText(mainRun.textContent, text);
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* What each injected decoration was made from. A line a swap kept still carries what was hung on it,
|
|
482
|
-
* so injecting the same again is nothing to do and injecting something else replaces it.
|
|
483
|
-
*/
|
|
484
|
-
const decorationSources = new WeakMap();
|
|
485
|
-
/**
|
|
486
|
-
* Has the next tick set a line's animations up again, the parts just added to it included. A line
|
|
487
|
-
* already being sung sets its parts up once, so parts added after that would stay still until the
|
|
488
|
-
* line came round again. Its running animations are left alone: the setup replaces each one, so
|
|
489
|
-
* nothing on the line goes still in between.
|
|
490
|
-
*/
|
|
491
|
-
function rearmLineAnimations(lineData) {
|
|
492
|
-
lineData.isAnimating = false;
|
|
493
|
-
}
|
|
494
|
-
/** Takes a decoration off its line, along with any timed parts it brought, and stops their animations. */
|
|
495
|
-
function removeDecoration(lineData, decoration) {
|
|
496
|
-
lineData.parts = lineData.parts.filter(part => {
|
|
497
|
-
if (!decoration.contains(part.lyricElement))
|
|
498
|
-
return true;
|
|
499
|
-
releasePart(part);
|
|
500
|
-
return false;
|
|
501
|
-
});
|
|
502
|
-
decoration.remove();
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Takes the romanization off a line, along with any timed parts it brought. A line a swap kept goes on
|
|
506
|
-
* carrying what was hung on it, so this is how a consumer drops one it no longer wants. Answers
|
|
507
|
-
* whether there was one to take off.
|
|
508
|
-
*/
|
|
509
|
-
export function removeRomanization(lyricElement, lineData) {
|
|
510
|
-
const existing = lyricElement.querySelector(`:scope > .${ROMANIZED_LYRICS_CLASS}`);
|
|
511
|
-
if (existing === null)
|
|
512
|
-
return false;
|
|
513
|
-
removeDecoration(lineData, existing);
|
|
514
|
-
return true;
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Takes the translation off a line. A line a swap kept goes on carrying what was hung on it, so this is
|
|
518
|
-
* how a consumer drops one it no longer wants. Answers whether there was one to take off.
|
|
519
|
-
*/
|
|
520
|
-
export function removeTranslation(lyricElement) {
|
|
521
|
-
const existing = lyricElement.querySelector(`:scope > .${TRANSLATED_LYRICS_CLASS}`);
|
|
522
|
-
if (existing === null)
|
|
523
|
-
return false;
|
|
524
|
-
existing.remove();
|
|
525
|
-
return true;
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Moves the translation and romanization hung on one line onto the line built in its place, with any
|
|
529
|
-
* timed parts they brought, so a line rebuilt for its timing keeps what the consumer hung on it. The
|
|
530
|
-
* parts are let go of whatever the old line was showing; the new line sets them up again with its own.
|
|
531
|
-
*/
|
|
532
|
-
export function moveDecorations(from, to) {
|
|
533
|
-
const decorations = Array.from(from.lyricElement.childNodes).filter((node) => node.classList?.contains(ROMANIZED_LYRICS_CLASS) === true ||
|
|
534
|
-
node.classList?.contains(TRANSLATED_LYRICS_CLASS) === true);
|
|
535
|
-
for (const decoration of decorations) {
|
|
536
|
-
from.parts = from.parts.filter(part => {
|
|
537
|
-
if (!decoration.contains(part.lyricElement))
|
|
538
|
-
return true;
|
|
539
|
-
releasePart(part);
|
|
540
|
-
to.parts.push(part);
|
|
541
|
-
return false;
|
|
542
|
-
});
|
|
543
|
-
to.lyricElement.appendChild(decoration);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
export function injectRomanization(doc, lyricElement, lineData, text, timedRomanization = null) {
|
|
547
|
-
const source = JSON.stringify([text, timedRomanization ?? null]);
|
|
548
|
-
const existing = lyricElement.querySelector(`:scope > .${ROMANIZED_LYRICS_CLASS}`);
|
|
549
|
-
if (existing !== null) {
|
|
550
|
-
if (decorationSources.get(existing) === source)
|
|
551
|
-
return;
|
|
552
|
-
removeDecoration(lineData, existing);
|
|
553
|
-
}
|
|
554
|
-
if (repeatsLine(lyricElement, text))
|
|
555
|
-
return;
|
|
556
|
-
const romanizedLine = doc.createElement("div");
|
|
557
|
-
romanizedLine.classList.add(ROMANIZED_LYRICS_CLASS, CONTENT_LINE_CLASS);
|
|
558
|
-
romanizedLine.dir = "auto";
|
|
559
|
-
const language = normalizeLanguage(lyricElement.lang);
|
|
560
|
-
romanizedLine.lang = `${language ? new Intl.Locale(language).language : "und"}-Latn`;
|
|
561
|
-
applyDirection(romanizedLine, text);
|
|
562
|
-
if (timedRomanization && timedRomanization.length > 0 && !disableRichsync.getBooleanValue()) {
|
|
563
|
-
createLyricsLine(doc, timedRomanization, lineData, romanizedLine, { splitBackgroundLine: false });
|
|
564
|
-
rearmLineAnimations(lineData);
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
romanizedLine.textContent = text;
|
|
568
|
-
}
|
|
569
|
-
decorationSources.set(romanizedLine, source);
|
|
570
|
-
const translation = lyricElement.querySelector(`.${TRANSLATED_LYRICS_CLASS}`);
|
|
571
|
-
lyricElement.insertBefore(romanizedLine, translation);
|
|
572
|
-
}
|
|
573
|
-
export function injectTranslation(doc, lyricElement, text, language) {
|
|
574
|
-
const source = JSON.stringify([text, normalizeLanguage(language)]);
|
|
575
|
-
const existing = lyricElement.querySelector(`:scope > .${TRANSLATED_LYRICS_CLASS}`);
|
|
576
|
-
if (existing !== null) {
|
|
577
|
-
if (decorationSources.get(existing) === source)
|
|
578
|
-
return;
|
|
579
|
-
existing.remove();
|
|
580
|
-
}
|
|
581
|
-
if (repeatsLine(lyricElement, text))
|
|
582
|
-
return;
|
|
583
|
-
const translatedLine = doc.createElement("div");
|
|
584
|
-
translatedLine.classList.add(TRANSLATED_LYRICS_CLASS, CONTENT_LINE_CLASS);
|
|
585
|
-
translatedLine.dir = "auto";
|
|
586
|
-
translatedLine.lang = normalizeLanguage(language);
|
|
587
|
-
applyDirection(translatedLine, text);
|
|
588
|
-
translatedLine.textContent = text;
|
|
589
|
-
decorationSources.set(translatedLine, source);
|
|
590
|
-
lyricElement.appendChild(translatedLine);
|
|
591
|
-
}
|
package/dist/instrumental.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const INSTRUMENTAL_WAVE_PATH_HIGH = "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";
|
|
2
|
-
export declare const INSTRUMENTAL_WAVE_PATH_LOW = "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";
|
|
3
|
-
/**
|
|
4
|
-
* Creates an HTML element representing an instrumental break in the lyrics.
|
|
5
|
-
*
|
|
6
|
-
* @param doc - Document the SVG nodes are created in
|
|
7
|
-
* @param container - Element to place instrumental parts into
|
|
8
|
-
* @param durationMs - Duration of the instrumental break in milliseconds
|
|
9
|
-
* @returns HTMLDivElement representing the instrumental break
|
|
10
|
-
*/
|
|
11
|
-
export declare function createInstrumentalElement(doc: Document, container: HTMLDivElement, durationMs: number): HTMLDivElement;
|