@braccato/core 1.16.8 → 1.16.9

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/dist/inject.js CHANGED
@@ -15,7 +15,7 @@ import { alignImageGlowRun, wrapImageHighlight } from "./imageHighlights.js";
15
15
  import { normalizeLanguage } from "./language.js";
16
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, 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";
17
17
  import { getSeekTimeFromClick } from "./seek.js";
18
- import { testJoiningScript, testRtl } from "./text.js";
18
+ import { isSameText, testJoiningScript, testRtl } from "./text.js";
19
19
  import { registerThemeSetting } from "./themeSettings.js";
20
20
  export let disableRichsync = registerThemeSetting("blyrics-disable-richsync", false, true);
21
21
  let lineSyncedAnimationDelay = registerThemeSetting("blyrics-line-synced-animation-delay", 50, true);
@@ -414,8 +414,15 @@ export function addSeekHandler(seek, lyricElement, allZero) {
414
414
  seek(seekTime);
415
415
  });
416
416
  }
417
+ function repeatsLine(lyricElement, text) {
418
+ const mainRun = [
419
+ ...(lyricElement.querySelector(`:scope > .${LINE_MAIN_CLASS}`)?.querySelectorAll(`:scope > .${BIDI_RUN_CLASS}`) ??
420
+ []),
421
+ ].find(run => !run.classList.contains(HIGHLIGHT_RUN_CLASS));
422
+ return mainRun?.textContent != null && isSameText(mainRun.textContent, text);
423
+ }
417
424
  export function injectRomanization(doc, lyricElement, lineData, text, timedRomanization = null) {
418
- if (lyricElement.querySelector(`.${ROMANIZED_LYRICS_CLASS}`))
425
+ if (lyricElement.querySelector(`.${ROMANIZED_LYRICS_CLASS}`) || repeatsLine(lyricElement, text))
419
426
  return;
420
427
  const romanizedLine = doc.createElement("div");
421
428
  romanizedLine.classList.add(ROMANIZED_LYRICS_CLASS, CONTENT_LINE_CLASS);
@@ -433,7 +440,7 @@ export function injectRomanization(doc, lyricElement, lineData, text, timedRoman
433
440
  lyricElement.insertBefore(romanizedLine, translation);
434
441
  }
435
442
  export function injectTranslation(doc, lyricElement, text, language) {
436
- if (lyricElement.querySelector(`.${TRANSLATED_LYRICS_CLASS}`))
443
+ if (lyricElement.querySelector(`.${TRANSLATED_LYRICS_CLASS}`) || repeatsLine(lyricElement, text))
437
444
  return;
438
445
  const translatedLine = doc.createElement("div");
439
446
  translatedLine.classList.add(TRANSLATED_LYRICS_CLASS, CONTENT_LINE_CLASS);
package/dist/text.d.ts CHANGED
@@ -9,4 +9,5 @@ export declare function containsNonLatin(text: string): boolean;
9
9
  declare const SCRIPT_TO_LANG: readonly [readonly [RegExp, "ja"], readonly [RegExp, "ko"], readonly [RegExp, "zh"], readonly [RegExp, "ru"], readonly [RegExp, "hi"], readonly [RegExp, "ar"], readonly [RegExp, "th"], readonly [RegExp, "el"], readonly [RegExp, "he"], readonly [RegExp, "bn"], readonly [RegExp, "ta"], readonly [RegExp, "te"], readonly [RegExp, "ml"], readonly [RegExp, "kn"], readonly [RegExp, "gu"], readonly [RegExp, "pa"], readonly [RegExp, "si"], readonly [RegExp, "my"], readonly [RegExp, "ka"], readonly [RegExp, "km"], readonly [RegExp, "lo"]];
10
10
  type NonLatinLanguageCode = (typeof SCRIPT_TO_LANG)[number][1];
11
11
  export declare function detectNonLatinLanguage(text: string): NonLatinLanguageCode | null;
12
+ export declare const isSameText: (a: string, b: string) => boolean;
12
13
  export {};
package/dist/text.js CHANGED
@@ -53,3 +53,5 @@ export function detectNonLatinLanguage(text) {
53
53
  }
54
54
  return null;
55
55
  }
56
+ const comparable = (text) => text.toLowerCase().replaceAll(/\p{P}/gu, "").trim();
57
+ export const isSameText = (a, b) => comparable(a) === comparable(b);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braccato/core",
3
- "version": "1.16.8",
3
+ "version": "1.16.9",
4
4
  "description": "Synchronized lyrics renderer with word-by-word animations",
5
5
  "type": "module",
6
6
  "license": "MIT",