@@ -26,6 +26,47 @@ import {
2626import { isDarkThemeAtom , lyricLinesAtom } from "$/states/main.ts" ;
2727import styles from "./index.module.css" ;
2828
29+ const parseLineVocalIds = ( value ?: string | string [ ] ) => {
30+ if ( ! value ) return [ ] ;
31+ const parts = Array . isArray ( value ) ? value : value . split ( / [ \s , ] + / ) ;
32+ return parts . map ( ( v ) => v . trim ( ) ) . filter ( Boolean ) ;
33+ } ;
34+
35+ const mapVocalTagsForPreview = (
36+ vocal : string | string [ ] | undefined ,
37+ vocalTagMap : Map < string , string > ,
38+ ) => {
39+ if ( ! vocal ) return ;
40+ const fallbackParts = Array . isArray ( vocal ) ? vocal : [ vocal ] ;
41+ const normalizedFallback = fallbackParts
42+ . map ( ( v ) => v . trim ( ) )
43+ . filter ( Boolean ) ;
44+ if ( vocalTagMap . size === 0 ) {
45+ return normalizedFallback . length > 0 ? normalizedFallback : undefined ;
46+ }
47+ const ids = parseLineVocalIds ( vocal ) ;
48+ if ( ids . length === 0 ) return ;
49+ let hasMatch = false ;
50+ const mapped = ids
51+ . map ( ( id ) => {
52+ const value = vocalTagMap . get ( id ) ;
53+ if ( value && value . trim ( ) . length > 0 ) {
54+ hasMatch = true ;
55+ return value ;
56+ }
57+ if ( vocalTagMap . has ( id ) ) {
58+ hasMatch = true ;
59+ }
60+ return id ;
61+ } )
62+ . map ( ( v ) => v . trim ( ) )
63+ . filter ( Boolean ) ;
64+ if ( ! hasMatch ) {
65+ return normalizedFallback . length > 0 ? normalizedFallback : undefined ;
66+ }
67+ return mapped . length > 0 ? mapped : undefined ;
68+ } ;
69+
2970export const AMLLWrapper = memo ( ( ) => {
3071 const originalLyricLines = useAtomValue ( lyricLinesAtom ) ;
3172 const currentTime = useAtomValue ( currentTimeAtom ) ;
@@ -38,11 +79,15 @@ export const AMLLWrapper = memo(() => {
3879 const playerRef = useRef < LyricPlayerRef > ( null ) ;
3980
4081 const lyricLines = useMemo ( ( ) => {
82+ const vocalTagMap = new Map (
83+ ( originalLyricLines . vocalTags ?? [ ] ) . map ( ( tag ) => [ tag . key , tag . value ] ) ,
84+ ) ;
4185 return structuredClone (
4286 originalLyricLines . lyricLines . map ( ( line ) => ( {
4387 ...line ,
4488 translatedLyric : showTranslationLines ? line . translatedLyric : "" ,
4589 romanLyric : showRomanLines ? line . romanLyric : "" ,
90+ vocal : mapVocalTagsForPreview ( line . vocal , vocalTagMap ) ,
4691 } ) ) ,
4792 ) ;
4893 } , [ originalLyricLines , showTranslationLines , showRomanLines ] ) ;
@@ -80,3 +125,4 @@ export const AMLLWrapper = memo(() => {
80125} ) ;
81126
82127export default AMLLWrapper ;
128+
0 commit comments