@braccato/core 1.20.1 → 1.21.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.
Files changed (52) hide show
  1. package/README.md +40 -37
  2. package/dist/README.md +40 -37
  3. package/dist/constants.d.ts +10 -0
  4. package/dist/constants.js +10 -0
  5. package/dist/engine/animationConfig.d.ts +0 -5
  6. package/dist/engine/animationConfig.js +0 -5
  7. package/dist/engine/animationTiming.d.ts +2 -1
  8. package/dist/engine/animationTiming.js +3 -2
  9. package/dist/engine/contextSweep.d.ts +10 -0
  10. package/dist/engine/contextSweep.js +102 -0
  11. package/dist/engine/culling.d.ts +11 -1
  12. package/dist/engine/culling.js +97 -24
  13. package/dist/engine/decorationSlides.d.ts +1 -1
  14. package/dist/engine/decorationSlides.js +13 -4
  15. package/dist/engine/elementMotion.d.ts +17 -0
  16. package/dist/engine/elementMotion.js +98 -0
  17. package/dist/engine/glow.js +1 -1
  18. package/dist/engine/instance.d.ts +7 -3
  19. package/dist/engine/instance.js +6 -4
  20. package/dist/engine/letterPlans.d.ts +0 -11
  21. package/dist/engine/letterPlans.js +0 -41
  22. package/dist/engine/lineAnimationState.js +1 -4
  23. package/dist/engine/lineAnimations.d.ts +1 -1
  24. package/dist/engine/lineAnimations.js +5 -24
  25. package/dist/engine/lineLifecycle.js +1 -1
  26. package/dist/engine/lineScroll.d.ts +5 -6
  27. package/dist/engine/lineScroll.js +36 -26
  28. package/dist/engine/lineScrollStyle.d.ts +8 -3
  29. package/dist/engine/lineScrollStyle.js +18 -4
  30. package/dist/engine/motionCurves.d.ts +19 -0
  31. package/dist/engine/motionCurves.js +85 -0
  32. package/dist/engine/renderedLines.d.ts +1 -2
  33. package/dist/engine/renderedLines.js +10 -19
  34. package/dist/engine/sweepPlans.d.ts +36 -0
  35. package/dist/engine/sweepPlans.js +59 -0
  36. package/dist/engine/tick.d.ts +4 -1
  37. package/dist/engine/tick.js +40 -10
  38. package/dist/engine/wavePool.d.ts +0 -1
  39. package/dist/engine/wordAnimations.d.ts +1 -5
  40. package/dist/engine/wordAnimations.js +88 -66
  41. package/dist/imageHighlights.d.ts +0 -11
  42. package/dist/imageHighlights.js +2 -48
  43. package/dist/inject.d.ts +41 -2
  44. package/dist/inject.js +72 -27
  45. package/dist/renderer.js +3 -2
  46. package/dist/styles/image-highlights.css +1 -59
  47. package/dist/styles/lyrics.css +128 -57
  48. package/dist/view.d.ts +1 -1
  49. package/dist/view.js +6 -5
  50. package/package.json +1 -1
  51. package/dist/engine/highlightKeyframes.d.ts +0 -8
  52. package/dist/engine/highlightKeyframes.js +0 -37
@@ -1,15 +1,4 @@
1
- import type { PartData } from "./inject.js";
2
1
  export declare const imageHighlights: import("./themeSettings.js").Setting;
3
- export interface ImageHighlightLayers {
4
- glow: HTMLElement;
5
- glowLetters: HTMLElement[];
6
- /** A separate inline layout host, only for runs that can fragment. */
7
- highlight?: HTMLElement;
8
- }
9
- export declare function wrapImageHighlight(highlight: HTMLElement): ImageHighlightLayers | undefined;
10
- /** Keep bidi ordering and inline fragments in the browser's normal text layout. An
11
- * absolutely positioned copy inside an inline word cannot reproduce those fragments. */
12
- export declare function alignImageGlowRun(run: HTMLElement, parts: PartData[]): void;
13
2
  /** A single CSS url(), not gradients or an arbitrary list of background layers. */
14
3
  export declare function imageURL(value: string): string | null;
15
4
  export declare function refreshInstrumentalImages(container: HTMLElement | null, view: Window): void;
@@ -1,53 +1,7 @@
1
- // Optional image paint, independent of HDR: a theme supplies the image and its dynamic range.
2
- // The extra layer exists only when requested. Blur surrounds the already-masked paint, so it
3
- // cannot be cut off by the karaoke mask. Both copies are driven by the engine's own animations.
1
+ // Optional image paint for the instrumental note, independent of HDR: a theme supplies the image and
2
+ // its dynamic range.
4
3
  import { registerThemeSetting } from "./themeSettings.js";
5
4
  export const imageHighlights = registerThemeSetting("blyrics-image-highlights", false, true);
6
- export function wrapImageHighlight(highlight) {
7
- if (!imageHighlights.getBooleanValue())
8
- return;
9
- const doc = highlight.ownerDocument;
10
- const paint = doc.createElement("span");
11
- paint.classList.add("blyrics-image-fill");
12
- while (highlight.firstChild)
13
- paint.appendChild(highlight.firstChild);
14
- const glow = doc.createElement("span");
15
- glow.classList.add("blyrics-image-glow");
16
- glow.setAttribute("aria-hidden", "true");
17
- glow.appendChild(paint.cloneNode(true));
18
- highlight.classList.add("blyrics-image-highlight");
19
- highlight.appendChild(glow);
20
- highlight.appendChild(paint);
21
- return { glow, glowLetters: Array.from(glow.querySelectorAll(".blyrics--letter")) };
22
- }
23
- /** Keep bidi ordering and inline fragments in the browser's normal text layout. An
24
- * absolutely positioned copy inside an inline word cannot reproduce those fragments. */
25
- export function alignImageGlowRun(run, parts) {
26
- if (!imageHighlights.getBooleanValue())
27
- return;
28
- if (!run.parentElement?.classList.contains("blyrics-bidi-sensitive") &&
29
- !run.querySelector(".blyrics-word-group-long"))
30
- return;
31
- const originals = Array.from(run.querySelectorAll(".blyrics-word-highlight"));
32
- const byHighlight = new Map(parts.map(part => [part.highlightElement, part]));
33
- const glowRun = run.cloneNode(true);
34
- glowRun.classList.add("blyrics-image-glow-run");
35
- const copies = glowRun.querySelectorAll(".blyrics-word-highlight");
36
- originals.forEach((original, index) => {
37
- const part = byHighlight.get(original);
38
- if (!part?.imageLayers)
39
- return;
40
- const copy = copies[index];
41
- copy.replaceChildren(part.imageLayers.glow);
42
- part.imageLayers.highlight = copy;
43
- // Non-fragmented groups in a mixed run can still wobble. Give their glow the
44
- // identical group transform, rather than letting it drift from the sharp copy.
45
- const group = original.parentElement;
46
- if (group && part.wobbleElements.includes(group) && copy.parentElement)
47
- part.wobbleElements.push(copy.parentElement);
48
- });
49
- run.parentElement.insertBefore(glowRun, run);
50
- }
51
5
  /** A single CSS url(), not gradients or an arbitrary list of background layers. */
52
6
  export function imageURL(value) {
53
7
  const match = /^url\(\s*(?:"([^"]*)"|'([^']*)'|([^\s'"()]+))\s*\)$/i.exec(value.trim());
package/dist/inject.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { type ImageHighlightLayers } from "./imageHighlights.js";
2
1
  import { type WordState } from "./constants.js";
3
2
  import type { Lyric, LyricPart, LyricSyncType } from "./types.js";
4
3
  export declare let disableRichsync: import("./themeSettings.js").Setting;
@@ -18,9 +17,46 @@ export interface AnimationData {
18
17
  lyricElement: HTMLElement;
19
18
  animations: Animation[];
20
19
  }
20
+ /** A copy of the word under a text shadow that never changes, faded in and out by opacity. */
21
+ export interface SweepGlow {
22
+ glow: HTMLElement;
23
+ letters?: HTMLElement[];
24
+ }
25
+ /**
26
+ * One box of a word's sweep, run by the compositor: the whole word when it is its own inline-block
27
+ * box, or one letter of a word that flows inline. Its mask holds a static soft edge and slides one way
28
+ * while the text inside it slides the other, so the glyphs hold still and only the edge crosses them.
29
+ * The glow is a pair of halos at two radii inside the same text, so the edge reveals them with it,
30
+ * crossfaded so the glow tightens as it fades. With nothing animating, the mask rests with the cell
31
+ * fully lit.
32
+ */
33
+ export interface SweepCell {
34
+ mask: HTMLElement;
35
+ text: HTMLElement;
36
+ letters?: HTMLElement[];
37
+ glows: SweepGlow[];
38
+ /** Where the cell sits along the word, as fractions of the word's width; equal shares if unset. */
39
+ span?: {
40
+ start: number;
41
+ width: number;
42
+ };
43
+ }
44
+ /**
45
+ * The sweep of a word that flows inline without letters: a word in a bidi-sensitive row or a long
46
+ * group whose script joins or whose letters are not split. Such a word can break across lines and
47
+ * shape with its neighbours, so no box of its own can hold the sweep. The engine places a cell over
48
+ * each box the word breaks into, drawing the word from a copy of its line, once the line is laid out.
49
+ */
50
+ export interface SweepContext {
51
+ host?: HTMLElement;
52
+ placedAt?: string;
53
+ unplaced?: boolean;
54
+ }
21
55
  export interface PartData extends AnimationData {
22
56
  highlightElement: HTMLElement;
23
- imageLayers?: ImageHighlightLayers;
57
+ /** The sweep's cells in reading order. */
58
+ sweep?: SweepCell[];
59
+ sweepContext?: SweepContext;
24
60
  letterElements?: HTMLElement[];
25
61
  highlightLetterElements?: HTMLElement[];
26
62
  wobbleElements: HTMLElement[];
@@ -41,6 +77,9 @@ export type LineData = {
41
77
  } & AnimationData;
42
78
  export declare function newLineData(lyricElement: HTMLElement, startTimeMs: number, durationMs: number): LineData;
43
79
  export declare function applyDirection(element: HTMLElement, text: string): void;
80
+ /** Puts a copy of the cell's text into an element, returning its letters if the word is split. */
81
+ export type FillSweepText = (into: HTMLElement) => HTMLElement[] | undefined;
82
+ export declare function createSweepCell(doc: Document, host: HTMLElement, fill: FillSweepText): SweepCell;
44
83
  export declare function createLyricsLine(doc: Document, parts: LyricPart[], line: LineData, lyricElement: HTMLElement, options?: {
45
84
  splitBackgroundLine: boolean;
46
85
  }): HTMLElement;
package/dist/inject.js CHANGED
@@ -12,9 +12,8 @@
12
12
  // split by character count. A line that arrives with no timed parts at all is rebuilt the same way
13
13
  // into zero duration words, so line synced lyrics reach the DOM the sweep already knows.
14
14
  import { releasePart } from "./engine/lineAnimationState.js";
15
- import { alignImageGlowRun, wrapImageHighlight } from "./imageHighlights.js";
16
15
  import { normalizeLanguage } from "./language.js";
17
- 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, TRANSLATED_LYRICS_CLASS, WORD_CLASS, WORD_GROUP_CLASS, WORD_HIGHLIGHT_CLASS, WORD_HIGHLIGHT_LETTERED_CLASS, WORD_STATE_ATTR, WORD_STATE_UPCOMING, ZERO_DURATION_ANIMATION_CLASS, } from "./constants.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_GLOW_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";
18
17
  import { getSeekTimeFromClick } from "./seek.js";
19
18
  import { isSameText, testJoiningScript, testRtl } from "./text.js";
20
19
  import { registerThemeSetting } from "./themeSettings.js";
@@ -65,13 +64,14 @@ export function deriveSyncType(lyrics) {
65
64
  return "richsync";
66
65
  return lyrics.every(item => item.startTimeMs === 0) ? "none" : "synced";
67
66
  }
68
- function newPartData(part, span, highlight, wobbleElements, letterElements, highlightLetterElements) {
67
+ function newPartData(part, span, highlight, wobbleElements, letterElements, highlightLetterElements, sweep) {
69
68
  return {
70
69
  time: part.startTimeMs / 1000,
71
70
  duration: part.durationMs / 1000,
72
71
  lyricElement: span,
73
72
  highlightElement: highlight,
74
- imageLayers: wrapImageHighlight(highlight),
73
+ sweep,
74
+ sweepContext: highlight.classList.contains(WORD_HIGHLIGHT_CONTEXT_CLASS) ? {} : undefined,
75
75
  letterElements,
76
76
  highlightLetterElements,
77
77
  wobbleElements,
@@ -210,9 +210,6 @@ function appendLongWordBreaks(doc, span, text, threshold) {
210
210
  function appendLetters(doc, wordElement, text) {
211
211
  const chars = [...graphemeSegmenter.segment(text)].map(segment => segment.segment);
212
212
  wordElement.style.setProperty("--letters", String(chars.length));
213
- // Width of the reveal mask's soft edge as a percentage of its (n+2)-letter-wide box, so the fade
214
- // spans the same 0.1*letters of a letter that the old gradient did. See the mask rule in lyrics.css.
215
- wordElement.style.setProperty("--mask-fade", `${(10 * chars.length) / (chars.length + 2)}%`);
216
213
  return chars.map(char => {
217
214
  const letter = doc.createElement("span");
218
215
  letter.classList.add(LETTER_CLASS);
@@ -221,10 +218,50 @@ function appendLetters(doc, wordElement, text) {
221
218
  return letter;
222
219
  });
223
220
  }
224
- function createTimedWordSpan(doc, part, wrapThreshold, perLetter, preserveJoining) {
221
+ function fillWordText(doc, host, text, wrapThreshold, perLetter, preserveJoining) {
222
+ if (perLetter)
223
+ return appendLetters(doc, host, text);
224
+ if (preserveJoining)
225
+ host.textContent = text;
226
+ else
227
+ appendLongWordBreaks(doc, host, text, wrapThreshold);
228
+ return undefined;
229
+ }
230
+ const SWEEP_GLOW_RADII = ["wide", "tight"];
231
+ export function createSweepCell(doc, host, fill) {
232
+ const mask = doc.createElement("span");
233
+ mask.classList.add(SWEEP_MASK_CLASS);
234
+ const text = doc.createElement("span");
235
+ text.classList.add(SWEEP_TEXT_CLASS);
236
+ mask.appendChild(text);
237
+ const letters = fill(text);
238
+ const glows = SWEEP_GLOW_RADII.map(radius => {
239
+ const glow = doc.createElement("span");
240
+ glow.classList.add(SWEEP_GLOW_CLASS, `${SWEEP_GLOW_CLASS}--${radius}`);
241
+ const glowLetters = fill(glow);
242
+ text.appendChild(glow);
243
+ return { glow, letters: glowLetters };
244
+ });
245
+ host.classList.add(SWEEP_CELL_CLASS);
246
+ host.appendChild(mask);
247
+ return { mask, text, letters, glows };
248
+ }
249
+ /** Makes each letter of a word that flows inline its own sweep cell, holding the letter's text. */
250
+ function createLetterSweepCells(doc, letters) {
251
+ return letters.map(letter => {
252
+ const text = letter.textContent ?? "";
253
+ letter.textContent = "";
254
+ return createSweepCell(doc, letter, into => {
255
+ into.appendChild(doc.createTextNode(text));
256
+ return undefined;
257
+ });
258
+ });
259
+ }
260
+ function createTimedWordSpan(doc, part, wrapThreshold, perLetter, preserveJoining, atomic) {
225
261
  const span = doc.createElement("span");
226
262
  const highlight = doc.createElement("span");
227
263
  highlight.classList.add(WORD_HIGHLIGHT_CLASS);
264
+ let sweep;
228
265
  let letters;
229
266
  let highlightLetters;
230
267
  for (const wordElement of [span, highlight]) {
@@ -244,30 +281,36 @@ function createTimedWordSpan(doc, part, wrapThreshold, perLetter, preserveJoinin
244
281
  wordElement.classList.add(EXPLICIT_WORD_CLASS);
245
282
  if (perLetter) {
246
283
  wordElement.classList.add("blyrics-word--lettered");
247
- const collected = appendLetters(doc, wordElement, part.words);
248
- if (wordElement === span) {
249
- letters = collected;
250
- }
251
- else {
252
- highlightLetters = collected;
284
+ if (wordElement === highlight)
253
285
  wordElement.classList.add(WORD_HIGHLIGHT_LETTERED_CLASS);
254
- }
255
286
  }
256
- else if (preserveJoining) {
257
- wordElement.textContent = part.words;
287
+ if (wordElement === highlight && atomic) {
288
+ const cell = createSweepCell(doc, highlight, into => fillWordText(doc, into, part.words, wrapThreshold, perLetter, preserveJoining));
289
+ sweep = [cell];
290
+ highlightLetters = cell.letters;
258
291
  }
259
292
  else {
260
- appendLongWordBreaks(doc, wordElement, part.words, wrapThreshold);
293
+ const collected = fillWordText(doc, wordElement, part.words, wrapThreshold, perLetter, preserveJoining);
294
+ if (wordElement === span)
295
+ letters = collected;
296
+ else
297
+ highlightLetters = collected;
298
+ if (wordElement === highlight && collected)
299
+ sweep = createLetterSweepCells(doc, collected);
261
300
  }
301
+ if (wordElement === highlight && sweep)
302
+ highlight.classList.add(WORD_HIGHLIGHT_SWEEP_CLASS);
303
+ else if (wordElement === highlight)
304
+ highlight.classList.add(WORD_HIGHLIGHT_CONTEXT_CLASS);
262
305
  wordElement.dataset.time = String(part.startTimeMs / 1000);
263
306
  wordElement.dataset.duration = String(part.durationMs / 1000);
264
307
  wordElement.dataset.content = part.words;
265
308
  wordElement.setAttribute(WORD_STATE_ATTR, WORD_STATE_UPCOMING);
266
309
  wordElement.style.setProperty("--blyrics-duration", part.durationMs + "ms");
267
310
  }
268
- return { span, highlight, letters, highlightLetters };
311
+ return { span, highlight, letters, highlightLetters, sweep };
269
312
  }
270
- function createWordGroup(doc, group, lineData) {
313
+ function createWordGroup(doc, group, lineData, wordsFlowInline) {
271
314
  const wrapThreshold = Math.max(1, longWordWrapThreshold.getNumberValue());
272
315
  // Atomic grapheme spans disrupt the browser's bidi ordering inside a mixed word.
273
316
  const mixedDirection = testRtl(group.text) && [...group.text].some(char => /[\p{Letter}\p{Number}]/u.test(char) && !testRtl(char));
@@ -275,11 +318,15 @@ function createWordGroup(doc, group, lineData) {
275
318
  const perLetter = letterWave.getBooleanValue() && !preserveJoining && !mixedDirection;
276
319
  const lyricGroup = doc.createElement("span");
277
320
  const highlightGroup = doc.createElement("span");
321
+ const isLongGroup = group.text.length > wrapThreshold * 2;
322
+ // A word that is its own inline-block box can hold the sweep's block layers. Long groups and
323
+ // bidi-sensitive rows lay their words out inline, where a word can break across lines.
324
+ const atomic = !wordsFlowInline && !isLongGroup;
278
325
  for (const groupElement of [lyricGroup, highlightGroup]) {
279
326
  groupElement.classList.add(WORD_GROUP_CLASS);
280
327
  groupElement.dir = "auto";
281
328
  groupElement.dataset.content = group.text;
282
- if (group.text.length > wrapThreshold * 2) {
329
+ if (isLongGroup) {
283
330
  groupElement.classList.add(LONG_WORD_GROUP_CLASS);
284
331
  }
285
332
  if (group.isBackground) {
@@ -289,9 +336,9 @@ function createWordGroup(doc, group, lineData) {
289
336
  for (const token of group.tokens) {
290
337
  if (token.kind === "space")
291
338
  continue;
292
- const { span, highlight, letters, highlightLetters } = createTimedWordSpan(doc, token.part, wrapThreshold, perLetter, preserveJoining);
339
+ const { span, highlight, letters, highlightLetters, sweep } = createTimedWordSpan(doc, token.part, wrapThreshold, perLetter, preserveJoining, atomic);
293
340
  const wobbleElements = lyricGroup.childNodes.length === 0 ? [lyricGroup, highlightGroup] : [];
294
- lineData.parts.push(newPartData(token.part, span, highlight, wobbleElements, letters, highlightLetters));
341
+ lineData.parts.push(newPartData(token.part, span, highlight, wobbleElements, letters, highlightLetters, sweep));
295
342
  lyricGroup.appendChild(span);
296
343
  highlightGroup.appendChild(highlight);
297
344
  }
@@ -379,7 +426,8 @@ export function createLyricsLine(doc, parts, line, lyricElement, options = { spl
379
426
  target.appendChild(createSpaceNode(doc, pendingSpace, shouldUseBackgroundLine));
380
427
  highlightRun.appendChild(createSpaceNode(doc, pendingSpace, shouldUseBackgroundLine));
381
428
  }
382
- const { lyricGroup, highlightGroup } = createWordGroup(doc, item, line);
429
+ const contentLine = backgroundRow ? backgroundRow.line : main;
430
+ const { lyricGroup, highlightGroup } = createWordGroup(doc, item, line, contentLine.classList.contains(BIDI_SENSITIVE_CLASS));
383
431
  target.appendChild(lyricGroup);
384
432
  highlightRun.appendChild(highlightGroup);
385
433
  if (backgroundRow) {
@@ -395,9 +443,6 @@ export function createLyricsLine(doc, parts, line, lyricElement, options = { spl
395
443
  .filter(([, row]) => row.used)
396
444
  .sort(([a], [b]) => a - b)
397
445
  .map(([, row]) => row);
398
- alignImageGlowRun(mainHighlightRun, line.parts);
399
- for (const row of usedBackgroundRows)
400
- alignImageGlowRun(row.highlightRun, line.parts);
401
446
  lyricElement.appendChild(main);
402
447
  for (const row of usedBackgroundRows)
403
448
  lyricElement.appendChild(row.line);
package/dist/renderer.js CHANGED
@@ -17,7 +17,7 @@ import { createAnimationEngineInstance } from "./engine/instance.js";
17
17
  import { hasUnsyncedLyrics } from "./engine/passiveScroll.js";
18
18
  import { hasContainerResized, noteUserScroll as noteEngineUserScroll, resetScrollResume } from "./engine/userScroll.js";
19
19
  import { noteVisibilityChange as noteEngineVisibilityChange } from "./engine/timingLogs.js";
20
- import { relayout, resolveTickOptions, retickFromPlaybackClock as retickEngineFromPlaybackClock, scheduleLyricPositionUpdate as scheduleEngineLyricPositionUpdate, tickView, } from "./engine/tick.js";
20
+ import { relayout, resolveTickOptions, retickAtLastTime, retickFromPlaybackClock as retickEngineFromPlaybackClock, scheduleLyricPositionUpdate as scheduleEngineLyricPositionUpdate, tickView, } from "./engine/tick.js";
21
21
  import { parseThemeConfig, setThemeSettings } from "./themeSettings.js";
22
22
  import { applyLyricLanguage, normalizeLanguage, resolveLyricLanguages } from "./language.js";
23
23
  import { setLyrics as buildLyricsView, swapLyrics as swapLyricsView } from "./view.js";
@@ -176,7 +176,8 @@ export function createLyricsRenderer(rendererOptions) {
176
176
  */
177
177
  function measure(measureLines = true) {
178
178
  forgetScrollElement();
179
- relayout(engine, measureLines && areLinesMeasurable(getRenderedLines(engine)));
179
+ if (relayout(engine, measureLines && areLinesMeasurable(getRenderedLines(engine))))
180
+ retickAtLastTime(engine);
180
181
  }
181
182
  function stopObservingContainer() {
182
183
  containerResizeObserver?.disconnect();
@@ -1,67 +1,9 @@
1
- /* The renderer adds these classes only for blyrics-image-highlights = true.
1
+ /* The renderer adds the instrumental image only for blyrics-image-highlights = true.
2
2
  An SDR image is equally valid. HDR assets and dynamic-range-limit belong to the theme. */
3
- .blyrics--word.blyrics-word-highlight.blyrics-image-highlight {
4
- background: none;
5
- mask: none;
6
- -webkit-mask: none;
7
- color: transparent;
8
- }
9
- .blyrics-image-fill,
10
- .blyrics-word-highlight.blyrics-image-highlight .blyrics--letter {
11
- background-image: var(--blyrics-highlight-image, none);
12
- background-color: var(--blyrics-lyric-active-color, white);
13
- background-size: 100% 100%;
14
- background-repeat: no-repeat;
15
- background-clip: text;
16
- -webkit-background-clip: text;
17
- color: transparent;
18
- -webkit-text-fill-color: transparent;
19
- }
20
- /* The content-box copy keeps each letter's image; the padding-box copy carries it under glyph overhang. */
21
- .blyrics-word-highlight.blyrics-image-highlight .blyrics--letter {
22
- background-image: var(--blyrics-highlight-image, none), var(--blyrics-highlight-image, none);
23
- background-origin: content-box, padding-box;
24
- }
25
- .blyrics-image-highlight:not(.blyrics-word-highlight--lettered) .blyrics-image-fill {
26
- --blyrics-image-sweep-angle: 90deg;
27
- mask-image: linear-gradient(var(--blyrics-image-sweep-angle),
28
- #000 calc(100% * var(--lyric-transition-amount-start)),
29
- transparent calc(100% * var(--lyric-transition-amount-end) + 1px));
30
- mask-repeat: no-repeat;
31
- }
32
- .blyrics-image-highlight.blyrics-rtl:not(.blyrics-word-highlight--lettered) .blyrics-image-fill {
33
- --blyrics-image-sweep-angle: 270deg;
34
- }
35
- .blyrics-image-highlight.blyrics-word-highlight--lettered .blyrics-image-fill {
36
- background: none;
37
- }
38
- .blyrics-image-glow {
39
- position: absolute;
40
- inset: 0;
41
- pointer-events: none;
42
- user-select: none;
43
- opacity: 0;
44
- overflow: visible;
45
- }
46
- /* A parallel run reproduces the full inline formatting context, including bidi
47
- reordering and every wrapped fragment. No generated text or per-frame measuring. */
48
- .blyrics-image-glow-run .blyrics-image-glow {
49
- position: static;
50
- inset: auto;
51
- display: inline;
52
- }
53
3
  .blyrics-instrumental-image { display: none; }
54
4
  .blyrics--instrumental-icon[data-image-ready] .blyrics-instrumental-image { display: inline; }
55
5
  .blyrics--instrumental-icon[data-image-ready] .blyrics-instrumental-color { display: none; }
56
6
  @media (forced-colors: active) {
57
- .blyrics-image-glow,
58
- .blyrics-image-glow-run .blyrics-image-glow { display: none; }
59
- .blyrics-image-fill,
60
- .blyrics-word-highlight.blyrics-image-highlight .blyrics--letter {
61
- background: none;
62
- color: CanvasText;
63
- -webkit-text-fill-color: CanvasText;
64
- }
65
7
  .blyrics--instrumental-icon[data-image-ready] .blyrics-instrumental-image { display: none; }
66
8
  .blyrics--instrumental-icon[data-image-ready] .blyrics-instrumental-color { display: inline; }
67
9
  }
@@ -127,44 +127,9 @@
127
127
  white-space: inherit;
128
128
  }
129
129
 
130
- @property --lyric-transition-amount-start {
131
- syntax: "<number>";
132
- inherits: true;
133
- initial-value: -0.2;
134
- }
135
-
136
- @property --lyric-transition-amount-end {
137
- syntax: "<number>";
138
- inherits: true;
139
- initial-value: -0.1;
140
- }
141
-
142
130
  .blyrics--word.blyrics-word-highlight {
143
- color: transparent;
144
- background-image: linear-gradient(
145
- 90deg,
146
- var(--blyrics-lyric-active-color)
147
- calc(100% * var(--lyric-transition-amount-start)),
148
- #00000000
149
- calc(100% * var(--lyric-transition-amount-end) + 1px)
150
- );
151
- background-clip: text;
152
131
  opacity: 0;
153
132
  pointer-events: none;
154
- --lyric-transition-amount-start: var(
155
- --blyrics-highlight-swipe-start-from,
156
- -0.2
157
- );
158
- --lyric-transition-amount-end: var(--blyrics-highlight-swipe-end-from, -0.1);
159
- }
160
- .blyrics-word-highlight.blyrics-rtl {
161
- background-image: linear-gradient(
162
- 270deg,
163
- var(--blyrics-lyric-active-color)
164
- calc(100% * var(--lyric-transition-amount-start)),
165
- #00000000
166
- calc(100% * var(--lyric-transition-amount-end) + 1px)
167
- );
168
133
  }
169
134
 
170
135
  .blyrics--letter {
@@ -182,33 +147,138 @@
182
147
  perspective: 100000px;
183
148
  }
184
149
 
185
- .blyrics-word-highlight.blyrics-word-highlight--lettered {
186
- background-image: none;
150
+ /* The compositor's sweep. A cell is a word that is its own inline-block box, or one letter of a word
151
+ that flows inline. Its mask box is 3 + fade cells wide and starts a cell before the cell: opaque up
152
+ to half a cell past the cell's end (SWEEP_REST in sweepPlans.ts), then a soft edge `fade` cells
153
+ wide, where fade is the swipe's width from its last start stop to its last end stop, in cells. The
154
+ engine slides the mask back to where the swipe begins and the text inside it the other way by the
155
+ same distance, so the glyphs hold still while the edge crosses them. The glow's two halos sit in
156
+ that same text, so the edge reveals them with it. With nothing animating the mask rests with the
157
+ cell lit and its halos whole. */
158
+ .blyrics--word.blyrics-word-highlight.blyrics-word-highlight--sweep {
159
+ color: var(--blyrics-lyric-active-color);
160
+ --blyrics-sweep-angle: 90deg;
161
+ --blyrics-sweep-fade: calc(
162
+ var(--blyrics-highlight-swipe-end-to, 1.5) - var(--blyrics-highlight-swipe-start-to, 1.4)
163
+ );
187
164
  }
188
165
 
189
- /* A mask clips to the border box, cutting off glyph overhang (a j's hook, italics). The padding
190
- widens that clip without moving layout, and the content-box origin keeps the sweep geometry. */
191
- .blyrics-word-highlight .blyrics--letter {
192
- padding-inline: 0.25em;
193
- margin-inline: -0.25em;
194
- -webkit-mask-origin: content-box;
195
- mask-origin: content-box;
196
- color: var(--blyrics-lyric-active-color);
197
- -webkit-mask-image: linear-gradient(90deg, #000 0, #000 50%, #0000 calc(50% + var(--mask-fade, 3%)));
198
- mask-image: linear-gradient(90deg, #000 0, #000 50%, #0000 calc(50% + var(--mask-fade, 3%)));
166
+ .blyrics--word.blyrics-word-highlight.blyrics-word-highlight--sweep.blyrics-rtl,
167
+ .blyrics-sweep-window.blyrics-sweep-cell[dir="rtl"] {
168
+ --blyrics-sweep-angle: 270deg;
169
+ }
170
+
171
+ .blyrics-word-highlight--sweep .blyrics--letter.blyrics-sweep-cell {
172
+ --blyrics-sweep-fade: calc(
173
+ (var(--blyrics-highlight-swipe-end-to, 1.5) - var(--blyrics-highlight-swipe-start-to, 1.4)) *
174
+ var(--letters, 1)
175
+ );
176
+ }
177
+
178
+ /* The mask boxes are laid out by direction, which a `dir="auto"` word does not hand down to its letters,
179
+ so each cell takes the direction of the word the engine sweeps it for. */
180
+ .blyrics-sweep-cell {
181
+ direction: ltr;
182
+ /* The mask boxes add nothing to the row's scroll width; the margin keeps the glow's halo. */
183
+ overflow: clip;
184
+ overflow-clip-margin: 2rem;
185
+ position: relative;
186
+ }
187
+
188
+ .blyrics-word-highlight--sweep.blyrics-rtl .blyrics-sweep-cell,
189
+ .blyrics-sweep-window.blyrics-sweep-cell[dir="rtl"] {
190
+ direction: rtl;
191
+ }
192
+
193
+ .blyrics-sweep-mask {
194
+ --blyrics-sweep-widths: calc(3 + var(--blyrics-sweep-fade));
195
+ box-sizing: content-box;
196
+ display: block;
197
+ margin-inline-start: -100%;
198
+ width: calc(var(--blyrics-sweep-widths) * 100%);
199
+ /* Room above and below for the halo, the letter wave and glyphs that reach past the line box. */
200
+ padding-block: calc(0.5em + var(--blyrics-highlight-glow-radius-from, 0.8rem));
201
+ margin-block: calc(-0.5em - var(--blyrics-highlight-glow-radius-from, 0.8rem));
202
+ --blyrics-sweep-solid: calc(250% / var(--blyrics-sweep-widths));
203
+ --blyrics-sweep-clear: calc((2.5 + var(--blyrics-sweep-fade)) * 100% / var(--blyrics-sweep-widths));
204
+ -webkit-mask-image: linear-gradient(var(--blyrics-sweep-angle), #000 var(--blyrics-sweep-solid), #0000 var(--blyrics-sweep-clear));
205
+ mask-image: linear-gradient(var(--blyrics-sweep-angle), #000 var(--blyrics-sweep-solid), #0000 var(--blyrics-sweep-clear));
199
206
  -webkit-mask-repeat: no-repeat;
200
207
  mask-repeat: no-repeat;
201
- -webkit-mask-size: calc((var(--letters, 1) + 2) * 100%) 100%;
202
- mask-size: calc((var(--letters, 1) + 2) * 100%) 100%;
203
- -webkit-mask-position: 0% 0%;
204
- mask-position: 0% 0%;
205
208
  }
206
209
 
207
- .blyrics-word-highlight.blyrics-rtl .blyrics--letter {
208
- -webkit-mask-image: linear-gradient(270deg, #000 0, #000 50%, #0000 calc(50% + var(--mask-fade, 3%)));
209
- mask-image: linear-gradient(270deg, #000 0, #000 50%, #0000 calc(50% + var(--mask-fade, 3%)));
210
- -webkit-mask-position: 100% 0%;
211
- mask-position: 100% 0%;
210
+ .blyrics-sweep-text {
211
+ box-sizing: content-box;
212
+ display: block;
213
+ isolation: isolate;
214
+ margin-inline-start: calc(100% / var(--blyrics-sweep-widths));
215
+ position: relative;
216
+ width: calc(100% / var(--blyrics-sweep-widths));
217
+ }
218
+
219
+ /* A halo is a copy of the text whose own glyphs are clear, under a text shadow that never changes; the
220
+ engine fades it by opacity. */
221
+ .blyrics-sweep-glow {
222
+ --blyrics-sweep-glow-radius: var(--blyrics-highlight-glow-radius-from, 0.8rem);
223
+ color: transparent;
224
+ inset: 0;
225
+ opacity: 0;
226
+ pointer-events: none;
227
+ position: absolute;
228
+ text-shadow: 0 0 var(--blyrics-sweep-glow-radius) var(--blyrics-glow-color);
229
+ user-select: none;
230
+ z-index: -1;
231
+ }
232
+
233
+ /* The glow shrinks as it fades. The engine crossfades from the wide halo to this one, which sits where
234
+ the radius has shrunk to by the time the wide one is gone. */
235
+ .blyrics-sweep-glow--tight {
236
+ --blyrics-sweep-glow-radius: calc(var(--blyrics-highlight-glow-radius-from, 0.8rem) * 0.4);
237
+ }
238
+
239
+ /* A word that flows inline keeps its text here only for layout; its sweep is drawn by cells placed over
240
+ each box it breaks into, which show the word from copies of its line. */
241
+ .blyrics--word.blyrics-word-highlight.blyrics-word-highlight--context {
242
+ color: transparent;
243
+ }
244
+
245
+ .blyrics-sweep-context {
246
+ inset: 0;
247
+ opacity: 0;
248
+ pointer-events: none;
249
+ position: absolute;
250
+ user-select: none;
251
+ z-index: 1;
252
+ }
253
+
254
+ .blyrics-sweep-window {
255
+ --blyrics-sweep-angle: 90deg;
256
+ position: absolute;
257
+ }
258
+
259
+ .blyrics-sweep-window .blyrics-sweep-mask,
260
+ .blyrics-sweep-window .blyrics-sweep-text {
261
+ height: 100%;
262
+ }
263
+
264
+ .blyrics-sweep-clone {
265
+ color: transparent;
266
+ max-width: none;
267
+ position: absolute;
268
+ text-shadow: none;
269
+ }
270
+
271
+ .blyrics-sweep-clone .blyrics--word {
272
+ color: transparent;
273
+ }
274
+
275
+ .blyrics-sweep-clone .blyrics--word.blyrics-sweep-target {
276
+ color: var(--blyrics-lyric-active-color);
277
+ }
278
+
279
+ .blyrics-sweep-glow .blyrics-sweep-clone .blyrics--word.blyrics-sweep-target {
280
+ color: transparent;
281
+ text-shadow: 0 0 var(--blyrics-sweep-glow-radius) var(--blyrics-glow-color);
212
282
  }
213
283
 
214
284
  /* text-decoration skips inline-block letters and rides the wave, so draw on the word box instead, from its
@@ -225,7 +295,8 @@
225
295
  .blyrics--line > .blyrics-line-main > .blyrics-background-lyric,
226
296
  .blyrics--line > .blyrics-background-line > .blyrics-background-lyric,
227
297
  .blyrics--line > .blyrics-line-main > .blyrics-bidi-run > .blyrics-background-lyric,
228
- .blyrics--line > .blyrics-background-line > .blyrics-bidi-run > .blyrics-background-lyric {
298
+ .blyrics--line > .blyrics-background-line > .blyrics-bidi-run > .blyrics-background-lyric,
299
+ .blyrics-sweep-clone > .blyrics-background-lyric {
229
300
  font-size: 0.75em;
230
301
  font-weight: 500;
231
302
  }
package/dist/view.d.ts CHANGED
@@ -38,7 +38,7 @@ export declare function setLyrics(engine: AnimationEngineInstance, mount: HTMLEl
38
38
  export type SwapPositions = Map<LineData, {
39
39
  position: number;
40
40
  height: number;
41
- scrollAnimationOffset: number;
41
+ motionOffset: number;
42
42
  }>;
43
43
  /**
44
44
  * Swaps these lyrics into the view already on screen, rebuilding only the lines that differ, and