diff --git a/.gitignore b/.gitignore
index f28b76f..b967bbb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,5 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
-data/pending
\ No newline at end of file
+data/pending
+.vscode
\ No newline at end of file
diff --git a/src/lib/components/lyrics.svelte b/src/lib/components/lyrics.svelte
index 2c030ce..a115667 100644
--- a/src/lib/components/lyrics.svelte
+++ b/src/lib/components/lyrics.svelte
@@ -2,7 +2,7 @@
import userAdjustingProgress from '$lib/state/userAdjustingProgress';
import createLyricsSearcher from '$lib/lyrics/lyricSearcher';
import progressBarRaw from '$lib/state/progressBarRaw';
- import type { LrcJsonData } from '$lib/lyrics/parser';
+ import type { LrcJsonData } from '$lib/lyrics/type';
import progressBarSlideValue from '$lib/state/progressBarSlideValue';
import nextUpdate from '$lib/state/nextUpdate';
import truncate from '$lib/truncate';
@@ -20,15 +20,13 @@
let showTranslation = false;
if (localStorage.getItem('debugMode') == null) {
localStorage.setItem('debugMode', 'false');
- }
- else {
- debugMode = localStorage.getItem('debugMode')!.toLowerCase() === "true";
+ } else {
+ debugMode = localStorage.getItem('debugMode')!.toLowerCase() === 'true';
}
if (localStorage.getItem('showTranslation') == null) {
localStorage.setItem('showTranslation', 'false');
- }
- else {
- showTranslation = localStorage.getItem('showTranslation')!.toLowerCase() === "true";
+ } else {
+ showTranslation = localStorage.getItem('showTranslation')!.toLowerCase() === 'true';
}
let currentLyricIndex = -1;
let currentPositionIndex = -1;
@@ -47,18 +45,16 @@
$: refs = _refs.filter(Boolean);
$: getLyricIndex = createLyricsSearcher(originalLyrics);
-
// handle KeyDown event
function onKeyDown(e: KeyboardEvent) {
if (e.altKey && e.shiftKey && (e.metaKey || e.key === 'OS') && e.key === 'Enter') {
debugMode = !debugMode;
localStorage.setItem('debugMode', debugMode ? 'true' : 'false');
- }
- else if (e.key === 't') {
+ } else if (e.key === 't') {
showTranslation = !showTranslation;
localStorage.setItem('showTranslation', showTranslation ? 'true' : 'false');
setTimeout(() => {
- scrollToLyric(refs[currentPositionIndex])
+ scrollToLyric(refs[currentPositionIndex]);
}, 50);
}
}
@@ -67,7 +63,7 @@
function extractTranslateValue(s: string): string | null {
const regex = /translateY\((-?\d*px)\)/;
let arr = regex.exec(s);
- return arr==null ? null : arr[1];
+ return arr == null ? null : arr[1];
}
// Helper function to get CSS class for a lyric based on its index and progress
@@ -80,7 +76,7 @@
// Function to move the lyrics up smoothly
async function moveToNextLine(h: number) {
- console.debug(new Date().getTime() , 'moveToNextLine', h);
+ console.debug(new Date().getTime(), 'moveToNextLine', h);
// the line that's going to process (like a pointer)
// by default, it's "the next line" after the lift
let processingLineIndex = currentPositionIndex + 2;
@@ -88,14 +84,17 @@
// modify translateY of all lines in viewport one by one to lift them up
for (let i = processingLineIndex; i < refs.length; i++) {
const lyric = refs[i];
- lyric.style.transition =
- `transform .5s cubic-bezier(.16,.02,.38,.98), filter 200ms ease, opacity 200ms ease,
+ lyric.style.transition = `transform .5s cubic-bezier(.16,.02,.38,.98), filter 200ms ease, opacity 200ms ease,
font-size 200ms ease, scale 250ms ease`;
lyric.style.transform = `translateY(${-h}px)`;
processingLineIndex = i;
await sleep(75);
const twoLinesAhead = refs[i - 2];
- if (lyricsContainer && twoLinesAhead.getBoundingClientRect().top > lyricsContainer.getBoundingClientRect().height) break;
+ if (
+ lyricsContainer &&
+ twoLinesAhead.getBoundingClientRect().top > lyricsContainer.getBoundingClientRect().height
+ )
+ break;
}
if (refs.length - processingLineIndex < 3) {
@@ -200,7 +199,7 @@
const currentLyric = refs[currentPositionIndex];
if ($userAdjustingProgress || scrolling || currentLyric.getBoundingClientRect().top < 0) return;
-
+
for (let i = 0; i < refs.length; i++) {
const offset = Math.abs(i - currentPositionIndex);
let blurRadius = Math.min(offset * 1.25, 16);
@@ -222,8 +221,7 @@
const element = refs[i];
if (element.getBoundingClientRect().top < 0) {
min = i;
- }
- else if (element.getBoundingClientRect().bottom < 0) {
+ } else if (element.getBoundingClientRect().bottom < 0) {
max = i;
return [min, max];
}
@@ -232,13 +230,14 @@
// Main function that control's lyrics update during playing
// triggered by nextUpdate's update
- async function lyricsUpdate(){
+ async function lyricsUpdate() {
if (
currentPositionIndex < 0 ||
currentPositionIndex === currentAnimationIndex ||
$userAdjustingProgress === true ||
scrolling
- ) return;
+ )
+ return;
const currentLyric = refs[currentPositionIndex];
const currentLyricRect = currentLyric.getBoundingClientRect();
@@ -269,8 +268,7 @@
currentAnimationIndex = currentPositionIndex;
}
-
- nextUpdate.subscribe(lyricsUpdate)
+ nextUpdate.subscribe(lyricsUpdate);
// Process while user is adjusting progress
userAdjustingProgress.subscribe((adjusting) => {
@@ -304,63 +302,77 @@
});
function lyricClick(lyricIndex: number) {
- if (player===null || originalLyrics.scripts === undefined) return;
+ if (player === null || originalLyrics.scripts === undefined) return;
player.currentTime = originalLyrics.scripts[lyricIndex].start;
- player.play()
+ player.play();
}
-
- LyricIndex: {currentLyricIndex} PositionIndex: {currentPositionIndex} - AnimationIndex:{currentAnimationIndex} - NextUpdate: {$nextUpdate} - Progress: {progress.toFixed(2)} - scrollPosition: {lyricsContainer.scrollTop} -
-+ LyricIndex: {currentLyricIndex} PositionIndex: {currentPositionIndex} + AnimationIndex:{currentAnimationIndex} + NextUpdate: {$nextUpdate} + Progress: {progress.toFixed(2)} + scrollPosition: {lyricsContainer.scrollTop} +
+- {#if originalLyrics.scripts[i].singer} - {originalLyrics.scripts[i].singer} + bind:this={lyricsContainer} + on:scroll={scrollHandler} + > + {#each lyrics as lyric, i} + + +
+ {#if originalLyrics.scripts[i].singer} + {originalLyrics.scripts[i].singer} + {/if} + {lyric} +
+ {#if originalLyrics.scripts[i].translation && showTranslation} +