From fa273705ad9cc368132dd899548ef78d4cdb0da4 Mon Sep 17 00:00:00 2001 From: meowarex Date: Mon, 1 Jun 2026 19:17:02 +1000 Subject: [PATCH] Fix Romanization <3 --- plugins/radiant-lyrics-luna/src/Settings.tsx | 2 +- plugins/radiant-lyrics-luna/src/index.ts | 36 +++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/plugins/radiant-lyrics-luna/src/Settings.tsx b/plugins/radiant-lyrics-luna/src/Settings.tsx index 1f65b1b..7467444 100644 --- a/plugins/radiant-lyrics-luna/src/Settings.tsx +++ b/plugins/radiant-lyrics-luna/src/Settings.tsx @@ -281,7 +281,7 @@ export const Settings = () => { }} /> { diff --git a/plugins/radiant-lyrics-luna/src/index.ts b/plugins/radiant-lyrics-luna/src/index.ts index d748200..cb6bc67 100644 --- a/plugins/radiant-lyrics-luna/src/index.ts +++ b/plugins/radiant-lyrics-luna/src/index.ts @@ -49,6 +49,14 @@ const toastErr = (msg: string) => // clean up resources export const unloads = new Set(); +// MARKER: Romanization Gate +const romanizedText = ( + item: { text?: string | null; romanized?: string | null }, + fallback = "", +): string => + (settings.romanizeLyrics && item.romanized ? item.romanized : item.text) ?? + fallback; + // MARKER: Player Market UI (Ensure new UI is enabled) function enablePlayerMarketUI() { @@ -1852,17 +1860,13 @@ const formatLrcTime = (timeSeconds: number): string => { const buildSyntheticLyricsText = (response: LyricsApiResponse): string => response.data - .map((line) => ("romanized" in line && line.romanized ? line.romanized : line.text)) + .map((line) => romanizedText(line)) .filter((line) => line.trim().length > 0) .join("\n"); const buildSyntheticLrcText = (response: LyricsApiResponse): string => response.data - .map((line) => { - const text = - ("romanized" in line && line.romanized ? line.romanized : line.text) ?? ""; - return `[${formatLrcTime(line.startTime)}]${text}`; - }) + .map((line) => `[${formatLrcTime(line.startTime)}]${romanizedText(line)}`) .join("\n"); const registerSyntheticNativeLyrics = ( @@ -2432,19 +2436,19 @@ const normalizeLineData = (data: ApiLine[]): WordLine[] => { : startMs + durationMs; const safeSinger = line.element?.singer ?? "v1000"; const safeKey = line.element?.key ?? `line-${idx}`; - const text = line.romanized ?? line.text; - + // Romanization Gate now decides which text to show (romanized or original) return { - text, + text: romanizedText(line), startTime: startMs / 1000, duration: durationMs / 1000, endTime: endMs / 1000, syllabus: [ { - text: `${text} `, + text: `${line.text} `, time: startMs, duration: Math.max(1, endMs - startMs), isBackground: false, + romanized: line.romanized ? `${line.romanized} ` : undefined, }, ], element: { @@ -2805,9 +2809,7 @@ const buildWordSpans = (): { return span; }; - const useRomanized = settings.romanizeLyrics; - const sylDisplay = (s: WordTiming) => - useRomanized && s.romanized != null ? s.romanized : s.text; + const sylDisplay = (s: WordTiming) => romanizedText(s); // Group syllables into words: trailing whitespace in syl.text marks a word boundary const wordGroups: number[][] = []; @@ -3028,10 +3030,10 @@ const buildTidalLines = ( let textIdx = 0; for (const tidalSpan of tidalSpans) { const rawText = tidalSpan.textContent ?? ""; - const text = - settings.romanizeLyrics && romanizedLines?.[textIdx] - ? romanizedLines[textIdx] - : rawText; + const text = romanizedText({ + text: rawText, + romanized: romanizedLines?.[textIdx], + }); if (rawText.trim().length > 0) textIdx++; if (rawText.trim().length === 0) { const spacer = document.createElement("div");