import { createEffect, For, Show, createSignal, createMemo } from 'solid-js'; import { type VirtualizerHandle } from 'virtua/solid'; import { type LineLyrics } from '@/plugins/synced-lyrics/types'; import { config, currentTime } from '../renderer'; import { _ytAPI } from '..'; import { canonicalize, romanize, simplifyUnicode } from '../utils'; interface SyncedLineProps { scroller: VirtualizerHandle; index: number; line: LineLyrics; status: 'upcoming' | 'current' | 'previous'; } const EmptyLine = (props: SyncedLineProps) => { const states = createMemo(() => { const defaultText = config()?.defaultTextString ?? ''; return Array.isArray(defaultText) ? defaultText : [defaultText]; }); const index = createMemo(() => { const progress = currentTime() - props.line.timeInMs; const total = props.line.duration; const percentage = Math.min(1, progress / total); return Math.max(0, Math.floor((states().length - 1) * percentage)); }); return (
{ _ytAPI?.seekTo((props.line.timeInMs + 10) / 1000); }} >
} when={states().length > 1} >
); }; export const SyncedLine = (props: SyncedLineProps) => { const text = createMemo(() => props.line.text.trim()); const [romanization, setRomanization] = createSignal(''); createEffect(() => { const input = canonicalize(text()); if (!config()?.romanization) return; romanize(input).then((result) => { setRomanization(canonicalize(result)); }); }); return ( } when={text()}>
{ _ytAPI?.seekTo((props.line.timeInMs + 10) / 1000); }} >
{ // TODO: Investigate the animation, even though the duration is properly set, all lines have the same animation duration div.style.setProperty( '--lyrics-duration', `${props.line.duration / 1000}s`, 'important', ); }} style={{ 'display': 'flex', 'flex-direction': 'column' }} > {(word, index) => { return ( ); }} {(word, index) => { return ( ); }}
); };