@uimaxbai/am-lyrics 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/react.js CHANGED
@@ -322,16 +322,17 @@ class GoogleService {
322
322
  }
323
323
  }
324
324
 
325
- const VERSION = '1.2.5';
325
+ const VERSION = '1.2.7';
326
326
  const INSTRUMENTAL_THRESHOLD_MS = 7000; // Show dots for gaps >= 7s
327
327
  const FETCH_TIMEOUT_MS = 8000; // Timeout for all lyrics fetch requests
328
328
  const SEEK_THRESHOLD_MS = 500;
329
329
  const PRE_SCROLL_LEAD_MS = 500;
330
+ const PRE_SCROLL_LEAD_SHORT_MS = 350;
330
331
  const SCROLL_ANIMATION_DURATION_MS = 280;
331
332
  const SCROLL_DELAY_INCREMENT_MS = 24;
332
333
  const GAP_PULSE_DURATION_MS = 4000;
333
334
  const GAP_PULSE_CYCLE_MS = GAP_PULSE_DURATION_MS * 2;
334
- const GAP_EXIT_LEAD_MS = 360;
335
+ const GAP_EXIT_LEAD_MS = 600;
335
336
  const GAP_MIN_SCALE = 0.85;
336
337
  /**
337
338
  * Fetch with an automatic timeout via AbortSignal.
@@ -1902,15 +1903,24 @@ let AmLyrics$1 = class AmLyrics extends i {
1902
1903
  const line = this.lyrics[i];
1903
1904
  const timeUntilStart = line.timestamp - newTime;
1904
1905
  const nextLineEl = this.lyricsContainer.querySelector(`#lyrics-line-${i}`);
1905
- if (timeUntilStart > 0 && timeUntilStart <= PRE_SCROLL_LEAD_MS) {
1906
+ const isBackToBack = this.activeLineIndices.length > 0;
1907
+ const leadTime = isBackToBack
1908
+ ? PRE_SCROLL_LEAD_SHORT_MS
1909
+ : PRE_SCROLL_LEAD_MS;
1910
+ if (timeUntilStart > leadTime) {
1911
+ break; // Lines are ordered by timestamp, no need to check further
1912
+ }
1913
+ if (timeUntilStart > 0 && timeUntilStart <= leadTime) {
1906
1914
  // Time to pre-scroll and pre-activate!
1907
1915
  if (nextLineEl) {
1908
- // Apply unblur & zoom effect ahead of lyric start
1909
1916
  preActiveLineIndex = i;
1910
- nextLineEl.classList.add('pre-active');
1917
+ if (!isBackToBack) {
1918
+ // Apply unblur & zoom effect ahead of lyric start only if no line is currently active
1919
+ nextLineEl.classList.add('pre-active');
1920
+ }
1911
1921
  this.clearPreActiveClasses(i);
1912
1922
  const slowScrollDuration = Math.max(SCROLL_ANIMATION_DURATION_MS, timeUntilStart);
1913
- this.focusLine(nextLineEl, false, slowScrollDuration, !!currentGap);
1923
+ this.focusLine(nextLineEl, false, isBackToBack ? 500 : slowScrollDuration);
1914
1924
  }
1915
1925
  break;
1916
1926
  }
@@ -2716,42 +2726,19 @@ let AmLyrics$1 = class AmLyrics extends i {
2716
2726
  // Use a Map to collect animations like YouLyPlus
2717
2727
  const charAnimationsMap = new Map();
2718
2728
  const styleUpdates = [];
2719
- // Step 1 & 2: Apply animations
2729
+ // Step 1: Grow Pass
2720
2730
  if (isGrowable && isFirstSyllable && allWordCharSpans.length > 0) {
2721
- // Glow AND wipe applied to ALL characters simultaneously from the first syllable
2722
- // This prevents CSS animation restarts because the `animation` property is set once.
2723
- const firstSyllableStartTime = parseFloat(syllable.getAttribute('data-start-time') || '0');
2724
- allWordCharSpans.forEach((span, charIndexInWord) => {
2731
+ const finalDuration = wordDurationMs;
2732
+ const baseDelayPerChar = finalDuration * 0.09;
2733
+ const growDurationMs = finalDuration * 1.5;
2734
+ allWordCharSpans.forEach(span => {
2725
2735
  const horizontalOffset = parseFloat(span.dataset.horizontalOffset || '0');
2726
2736
  const maxScale = span.dataset.maxScale || '1.1';
2727
2737
  const shadowIntensity = span.dataset.shadowIntensity || '0.6';
2728
2738
  const translateYPeak = span.dataset.translateYPeak || '-2';
2729
- const animationParts = [];
2730
- const parentSyllable = span.closest('.lyrics-syllable');
2731
- if (parentSyllable) {
2732
- const parentDuration = parseFloat(parentSyllable.getAttribute('data-duration') || '0');
2733
- const parentStartTime = parseFloat(parentSyllable.getAttribute('data-start-time') || '0');
2734
- const startPct = parseFloat(span.dataset.wipeStart || '0');
2735
- const durationPct = parseFloat(span.dataset.wipeDuration || '0');
2736
- const relativeStartOffset = Math.max(0, parentStartTime - firstSyllableStartTime);
2737
- const wipeDelay = relativeStartOffset + parentDuration * startPct;
2738
- const wipeDuration = parentDuration * durationPct;
2739
- const useStartAnimation = isFirstInContainer && charIndexInWord === 0;
2740
- let charWipeAnimation = 'wipe';
2741
- if (useStartAnimation)
2742
- charWipeAnimation = isRTL ? 'start-wipe-rtl' : 'start-wipe';
2743
- else
2744
- charWipeAnimation = isRTL ? 'wipe-rtl' : 'wipe';
2745
- // Blend word and syllable durations to let the gradient flow smoothly
2746
- // while still responding to syllable pacing (no strict exactness, just natural flow)
2747
- const growDelay = wipeDelay;
2748
- const growDurationMs = Math.max(600, wordDurationMs * 0.8 + parentDuration * 1.5);
2749
- animationParts.push(`grow-dynamic ${growDurationMs}ms ease-in-out ${growDelay}ms forwards`);
2750
- if (wipeDuration > 0) {
2751
- animationParts.push(`${charWipeAnimation} ${wipeDuration}ms linear ${wipeDelay}ms forwards`);
2752
- }
2753
- }
2754
- charAnimationsMap.set(span, animationParts.join(', '));
2739
+ const syllableCharIndex = parseFloat(span.dataset.syllableCharIndex || '0');
2740
+ const growDelay = baseDelayPerChar * syllableCharIndex;
2741
+ charAnimationsMap.set(span, `grow-dynamic ${growDurationMs}ms ease-in-out ${growDelay}ms forwards`);
2755
2742
  styleUpdates.push({
2756
2743
  element: span,
2757
2744
  property: '--char-offset-x',
@@ -2774,26 +2761,8 @@ let AmLyrics$1 = class AmLyrics extends i {
2774
2761
  });
2775
2762
  });
2776
2763
  }
2777
- else if (isGrowable && !isFirstSyllable && charSpans.length > 0) {
2778
- // For subsequent syllables of a growable word:
2779
- // If they already have `grow-dynamic`, it means the first syllable correctly took care of BOTH grow and wipe!
2780
- // Otherwise, they scrubbed directly into this syllable, so let's at least do the wipe.
2781
- charSpans.forEach(span => {
2782
- const existingAnimation = charAnimationsMap.get(span) || span.style.animation || '';
2783
- if (existingAnimation.includes('grow-dynamic'))
2784
- return;
2785
- const startPct = parseFloat(span.dataset.wipeStart || '0');
2786
- const durationPct = parseFloat(span.dataset.wipeDuration || '0');
2787
- const wipeDelay = syllableDurationMs * startPct;
2788
- const wipeDuration = syllableDurationMs * durationPct;
2789
- const charWipeAnimation = isRTL ? 'wipe-rtl' : 'wipe';
2790
- if (wipeDuration > 0) {
2791
- charAnimationsMap.set(span, `${charWipeAnimation} ${wipeDuration}ms linear ${wipeDelay}ms forwards`);
2792
- }
2793
- });
2794
- }
2795
- else if (charSpans.length > 0) {
2796
- // Per-character wipe for non-growable words (matching YouLyPlus)
2764
+ // Step 2: Wipe Pass
2765
+ if (charSpans.length > 0) {
2797
2766
  charSpans.forEach((span, charIndex) => {
2798
2767
  const startPct = parseFloat(span.dataset.wipeStart || '0');
2799
2768
  const durationPct = parseFloat(span.dataset.wipeDuration || '0');
@@ -2807,8 +2776,26 @@ let AmLyrics$1 = class AmLyrics extends i {
2807
2776
  else {
2808
2777
  charWipeAnimation = isRTL ? 'wipe-rtl' : 'wipe';
2809
2778
  }
2779
+ const existingAnimation = charAnimationsMap.get(span) || span.style.animation || '';
2780
+ const animationParts = [];
2781
+ if (existingAnimation && existingAnimation.includes('grow-dynamic')) {
2782
+ animationParts.push(existingAnimation.split(',')[0].trim());
2783
+ }
2784
+ if (charIndex > 0) {
2785
+ const arrivalTime = span.dataset.preWipeArrival
2786
+ ? parseFloat(span.dataset.preWipeArrival)
2787
+ : wipeDelay;
2788
+ const constantDuration = parseFloat(span.dataset.preWipeDuration || '100');
2789
+ const animDelay = arrivalTime - constantDuration;
2790
+ if (constantDuration > 0) {
2791
+ animationParts.push(`pre-wipe-char ${constantDuration}ms linear ${animDelay}ms forwards`);
2792
+ }
2793
+ }
2810
2794
  if (wipeDuration > 0) {
2811
- charAnimationsMap.set(span, `${charWipeAnimation} ${wipeDuration}ms linear ${wipeDelay}ms forwards`);
2795
+ animationParts.push(`${charWipeAnimation} ${wipeDuration}ms linear ${wipeDelay}ms forwards`);
2796
+ }
2797
+ if (animationParts.length > 0) {
2798
+ charAnimationsMap.set(span, animationParts.join(', '));
2812
2799
  }
2813
2800
  });
2814
2801
  }
@@ -4644,8 +4631,8 @@ AmLyrics$1.styles = i$3 `
4644
4631
  0.75em 100%,
4645
4632
  0% 100%;
4646
4633
  background-position:
4647
- -0.375em 0%,
4648
- left;
4634
+ -0.75em 0%,
4635
+ -0.375em 0%;
4649
4636
  }
4650
4637
  100% {
4651
4638
  background-size:
@@ -4739,7 +4726,7 @@ AmLyrics$1.styles = i$3 `
4739
4726
  0.75em 100%,
4740
4727
  0% 100%;
4741
4728
  background-position:
4742
- -0.85em 0%,
4729
+ -0.75em 0%,
4743
4730
  left;
4744
4731
  }
4745
4732
  to {
@@ -4747,7 +4734,7 @@ AmLyrics$1.styles = i$3 `
4747
4734
  0.75em 100%,
4748
4735
  0% 100%;
4749
4736
  background-position:
4750
- -0.85em 0%,
4737
+ -0.375em 0%,
4751
4738
  left;
4752
4739
  }
4753
4740
  }