From 19ec6e2f0a00048a7acec843aaa9f07e440dfcea Mon Sep 17 00:00:00 2001 From: jeffvli Date: Thu, 9 Jul 2026 01:58:33 -0700 Subject: [PATCH] fix romaji showing up on non-kana lines --- .../features/lyrics/api/lyric-conversion.ts | 2 +- .../lyrics/hooks/use-furigana-lyrics.ts | 21 ++++++++++++------- .../features/lyrics/karaoke-lyric-line.tsx | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/renderer/features/lyrics/api/lyric-conversion.ts b/src/renderer/features/lyrics/api/lyric-conversion.ts index 6a5f76981..d58697101 100644 --- a/src/renderer/features/lyrics/api/lyric-conversion.ts +++ b/src/renderer/features/lyrics/api/lyric-conversion.ts @@ -230,7 +230,7 @@ export const alignRomajiTokensToWordCues = ( aligned.push({ ...word, - text: romajiText || word.text, + text: romajiText, }); } diff --git a/src/renderer/features/lyrics/hooks/use-furigana-lyrics.ts b/src/renderer/features/lyrics/hooks/use-furigana-lyrics.ts index 91da48bac..cfe6ebf7b 100644 --- a/src/renderer/features/lyrics/hooks/use-furigana-lyrics.ts +++ b/src/renderer/features/lyrics/hooks/use-furigana-lyrics.ts @@ -115,28 +115,34 @@ export const useRomajiLyrics = (lyrics: LyricsResponse | null | undefined, enabl }); }; -export type SyncedRomajiLyrics = (null | SyncedCueLine[])[]; +export type SyncedRomajiLyrics = ((null | SyncedCueLine)[] | null)[]; const buildSyncedRomajiLine = async ( cueLines: SyncedCueLine[], -): Promise => { - const romajiCueLines: SyncedCueLine[] = []; +): Promise<(null | SyncedCueLine)[]> => { + const romajiCueLines: (null | SyncedCueLine)[] = []; for (const cueLine of cueLines) { if (!cueLine.words.length) { - romajiCueLines.push({ ...cueLine }); + romajiCueLines.push(null); continue; } if (!lyricsApi) { - return null; + return cueLines.map(() => null); } const tokens = (await lyricsApi.convertRomajiTokens(cueLine.value)) as RomajiToken[]; + if (!tokens.length) { + romajiCueLines.push(null); + continue; + } + const alignedWords = alignRomajiTokensToWordCues(cueLine.value, cueLine.words, tokens); if (!alignedWords) { - return null; + romajiCueLines.push(null); + continue; } romajiCueLines.push({ @@ -170,7 +176,8 @@ export const useSyncedRomajiLyrics = ( continue; } - result.push(await buildSyncedRomajiLine(line.cueLines)); + const romajiCueLines = await buildSyncedRomajiLine(line.cueLines); + result.push(romajiCueLines.some((entry) => entry !== null) ? romajiCueLines : null); } return result; diff --git a/src/renderer/features/lyrics/karaoke-lyric-line.tsx b/src/renderer/features/lyrics/karaoke-lyric-line.tsx index f1529b316..88af4f6ee 100644 --- a/src/renderer/features/lyrics/karaoke-lyric-line.tsx +++ b/src/renderer/features/lyrics/karaoke-lyric-line.tsx @@ -21,7 +21,7 @@ interface KaraokeLyricLineProps extends ComponentPropsWithoutRef<'div'> { cueLines: SyncedCueLine[]; fontSize: number; lineIndex: number; - romajiCueLines?: null | SyncedCueLine[]; + romajiCueLines?: (null | SyncedCueLine)[] | null; romajiText?: null | string; text?: string; translatedText?: null | string;