fix romaji showing up on non-kana lines

This commit is contained in:
jeffvli
2026-07-09 01:58:33 -07:00
parent 2d363190bd
commit 19ec6e2f0a
3 changed files with 16 additions and 9 deletions
@@ -230,7 +230,7 @@ export const alignRomajiTokensToWordCues = (
aligned.push({ aligned.push({
...word, ...word,
text: romajiText || word.text, text: romajiText,
}); });
} }
@@ -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 ( const buildSyncedRomajiLine = async (
cueLines: SyncedCueLine[], cueLines: SyncedCueLine[],
): Promise<null | SyncedCueLine[]> => { ): Promise<(null | SyncedCueLine)[]> => {
const romajiCueLines: SyncedCueLine[] = []; const romajiCueLines: (null | SyncedCueLine)[] = [];
for (const cueLine of cueLines) { for (const cueLine of cueLines) {
if (!cueLine.words.length) { if (!cueLine.words.length) {
romajiCueLines.push({ ...cueLine }); romajiCueLines.push(null);
continue; continue;
} }
if (!lyricsApi) { if (!lyricsApi) {
return null; return cueLines.map(() => null);
} }
const tokens = (await lyricsApi.convertRomajiTokens(cueLine.value)) as RomajiToken[]; const tokens = (await lyricsApi.convertRomajiTokens(cueLine.value)) as RomajiToken[];
if (!tokens.length) {
romajiCueLines.push(null);
continue;
}
const alignedWords = alignRomajiTokensToWordCues(cueLine.value, cueLine.words, tokens); const alignedWords = alignRomajiTokensToWordCues(cueLine.value, cueLine.words, tokens);
if (!alignedWords) { if (!alignedWords) {
return null; romajiCueLines.push(null);
continue;
} }
romajiCueLines.push({ romajiCueLines.push({
@@ -170,7 +176,8 @@ export const useSyncedRomajiLyrics = (
continue; continue;
} }
result.push(await buildSyncedRomajiLine(line.cueLines)); const romajiCueLines = await buildSyncedRomajiLine(line.cueLines);
result.push(romajiCueLines.some((entry) => entry !== null) ? romajiCueLines : null);
} }
return result; return result;
@@ -21,7 +21,7 @@ interface KaraokeLyricLineProps extends ComponentPropsWithoutRef<'div'> {
cueLines: SyncedCueLine[]; cueLines: SyncedCueLine[];
fontSize: number; fontSize: number;
lineIndex: number; lineIndex: number;
romajiCueLines?: null | SyncedCueLine[]; romajiCueLines?: (null | SyncedCueLine)[] | null;
romajiText?: null | string; romajiText?: null | string;
text?: string; text?: string;
translatedText?: null | string; translatedText?: null | string;