mirror of
https://github.com/jeffvli/feishin.git
synced 2026-07-13 14:10:04 +02:00
fix romaji showing up on non-kana lines
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user