feishin/src/renderer/features/lyrics/unsynchronized-lyrics.tsx

88 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-05-22 17:38:31 -07:00
import { useMemo } from 'react';
2023-06-04 16:19:13 -07:00
import styled from 'styled-components';
2023-05-22 17:38:31 -07:00
import { LyricLine } from '/@/renderer/features/lyrics/lyric-line';
import { FullLyricsMetadata } from '/@/renderer/api/types';
import { useLyricsSettings } from '/@/renderer/store';
2023-05-22 17:38:31 -07:00
2024-02-01 23:53:10 -08:00
export interface UnsynchronizedLyricsProps extends Omit<FullLyricsMetadata, 'lyrics'> {
2023-07-01 19:10:05 -07:00
lyrics: string;
2023-05-22 17:38:31 -07:00
}
const UnsynchronizedLyricsContainer = styled.div<{ $gap: number }>`
2023-07-01 19:10:05 -07:00
display: flex;
flex-direction: column;
gap: ${(props) => props.$gap || 5}px;
2023-07-01 19:10:05 -07:00
width: 100%;
height: 100%;
padding: 10vh 0 6vh;
overflow: scroll;
transform: translateY(-2rem);
-webkit-mask-image: linear-gradient(
180deg,
transparent 5%,
rgb(0 0 0 / 100%) 20%,
rgb(0 0 0 / 100%) 85%,
transparent 95%
);
2023-07-01 19:10:05 -07:00
mask-image: linear-gradient(
180deg,
transparent 5%,
2023-09-15 20:42:38 -07:00
rgb(0 0 0 / 100%) 20%,
rgb(0 0 0 / 100%) 85%,
2023-07-01 19:10:05 -07:00
transparent 95%
);
@media screen and (orientation: portrait) {
2023-07-01 19:10:05 -07:00
padding: 5vh 0;
}
2023-06-04 16:19:13 -07:00
`;
export const UnsynchronizedLyrics = ({
2023-07-01 19:10:05 -07:00
artist,
lyrics,
name,
remote,
source,
}: UnsynchronizedLyricsProps) => {
const settings = useLyricsSettings();
2023-07-01 19:10:05 -07:00
const lines = useMemo(() => {
return lyrics.split('\n');
}, [lyrics]);
2023-05-22 17:38:31 -07:00
2023-07-01 19:10:05 -07:00
return (
<UnsynchronizedLyricsContainer
$gap={settings.gapUnsync}
className="unsynchronized-lyrics"
>
{settings.showProvider && source && (
2023-07-01 19:10:05 -07:00
<LyricLine
alignment={settings.alignment}
2023-07-01 19:10:05 -07:00
className="lyric-credit"
fontSize={settings.fontSizeUnsync}
2023-07-01 19:10:05 -07:00
text={`Provided by ${source}`}
/>
)}
{settings.showMatch && remote && (
2023-07-01 19:10:05 -07:00
<LyricLine
alignment={settings.alignment}
2023-07-01 19:10:05 -07:00
className="lyric-credit"
fontSize={settings.fontSizeUnsync}
2023-07-01 19:10:05 -07:00
text={`"${name} by ${artist}"`}
/>
)}
{lines.map((text, idx) => (
<LyricLine
key={idx}
alignment={settings.alignment}
className="lyric-line unsynchronized"
fontSize={settings.fontSizeUnsync}
2023-07-01 19:10:05 -07:00
id={`lyric-${idx}`}
text={text}
/>
))}
</UnsynchronizedLyricsContainer>
);
2023-05-22 17:38:31 -07:00
};