Adjusted smoothness on lyrical scroll.

This commit is contained in:
translator committed 2026-03-06 15:35:36 +09:00
1 parent 8333da1351
commit 3e0472d998
3 files changed
+118 -62

No files matched your search

+32
View File
@@ -333,3 +333,35 @@ Added `popSnap: number` (ms) to `StyleState` and `DEFAULT_STYLE` (default: 150ms
### BG color scope fix — fullscreen root no longer inherits bgColor
The fullscreen root `<div>` had `style={isFullscreen ? { backgroundColor: effectiveBg } : undefined}`. This painted the entire fullscreen container (including toolbar, controls, album panel) with the user's BG color. The BG color is already applied correctly on the inner lyrics area div (`backgroundColor: effectiveBg` at line ~1804). Removed the root-level style entirely (`style={undefined}`).
---
### Karaoke scroll jitter — root cause and fix
**Root cause (windowed rendering):** `renderKaraokeStyle`, `renderGlowStyle`, and `renderBlurStyle` each used a `window = 3` slice (`lines.slice(activeLine-3, activeLine+4)`). Because the active line was always at index 3 within this window, its `offsetTop` was effectively constant (~3 × lineHeight) regardless of which line was active. The `translateY` formula `containerHeight/2 − offsetTop − lineHeight/2` therefore produced the same value on every line transition — no scroll animation occurred and lines appeared to "jump" into place.
**Fix:** All three windowed render functions now iterate over **all lines** (`lines.map(...)`). Lines with `dist > 5` from the active line get `opacity: 0`; lines with `dist > 4` in blur mode skip the expensive `blur()` filter. The inner scroll div still uses `overflow: hidden` on its container, so only nearby lines are visible. With all lines in the DOM, `offsetTop` grows monotonically as `activeLine` advances, and the CSS `transition: transform 0.35s cubic-bezier(0.33, 1, 0.68, 1)` on the scroll div animates a true smooth vertical scroll.
**Secondary fix — translateY bypasses React state:** `translateY` was moved from `useState` to a direct DOM write in `useLayoutEffect` via `scrollDivRef.current.style.transform`. This eliminates the two-render sequence on line changes (content update → state update → second render) that could cause the transition to be interrupted. `translateYRef` tracks the current value for use by `handleRecenter` and the `scaleX`/`scaleY` deps in the same effect.
---
### Glow slider — configurable glow radius
Added `glowSize: number` to `StyleState` and `DEFAULT_STYLE` (default: 8px). A **Glow** slider (2–24px, step 1px) appears in StylePicker when `visualStyle === 'glow'`. Required passing `visualStyle` as a new optional prop to `StylePicker`. The glow filter in `renderGlowStyle` uses `glowSize` for the inner shadow and `glowSize * 2` for the wider outer shadow: `` `drop-shadow(0 0 ${glowSize}px ${color}cc) drop-shadow(0 0 ${glowSize*2}px ${color}66)` ``.
---
### Smooth size transition between active and adjacent lines
**Problem:** The active line used a different `fontSize` multiplier (e.g. `fontSize * 1.05`) than inactive lines (`fontSize * 0.85`), causing an instant size jump on each line transition with no animation.
**Why font-size transition wasn't used:** CSS `font-size` transitions cause layout reflow on every frame, which would desync the scroll position (the `useLayoutEffect` measures `offsetTop` based on the final layout, but the font-size is still mid-animation, so lines aren't at their measured positions yet).
**Fix:** All three render functions (`renderKaraokeStyle`, `renderGlowStyle`, `renderBlurStyle`) now use a uniform base `fontSize` for all line divs in layout. Visual size is controlled via `transform: scale()` per line based on distance from active:
- `dist = 0` (active): `scale(1.0)`
- `dist = 1`: `scale(0.88)`
- `dist = 2`: `scale(0.82)`
- `dist ≥ 3`: `scale(0.78)`, opacity fades to 0 past dist 5
`transformOrigin` is set to match `textAlign` (`left center` / `center center` / `right center`). All lines get `transition: 'transform 0.35s ease-out, opacity 0.35s ease-out'` matching the scroll transition duration so both animate in sync. Since `transform` doesn't affect layout, `offsetTop` is stable and the scroll calculation remains correct. `KaraokeWord` now receives base `fontSize` (the wrapper div's scale handles visual enlargement).
+1 -1
View File
@@ -19,7 +19,7 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="StemEngine" />
<link rel="apple-touch-icon" href="/icon.svg" />
<script type="module" crossorigin src="/assets/index-BtPYzF_7.js"></script>
<script type="module" crossorigin src="/assets/index-CT4p0YjA.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-02k6pNvN.css">
</head>
<body>
+85 -61
View File
@@ -422,6 +422,7 @@ interface StyleState {
scaleY: number
popScale: number
popSnap: number
glowSize: number
}
const DEFAULT_STYLE: StyleState = {
@@ -449,6 +450,7 @@ const DEFAULT_STYLE: StyleState = {
scaleY: 1,
popScale: 15,
popSnap: 150,
glowSize: 8,
}
function StylePicker({
@@ -456,11 +458,13 @@ function StylePicker({
onChange,
onReset,
hasCoverArt,
visualStyle,
}: {
style: StyleState
onChange: (patch: Partial<StyleState>) => void
onReset: () => void
hasCoverArt?: boolean
visualStyle?: string
}) {
return (
<div className="px-3 py-2.5 border-b border-white/10 space-y-2.5">
@@ -623,6 +627,16 @@ function StylePicker({
<span className="text-[10px] tabular-nums text-slate-400 w-8">{style.popSnap}ms</span>
</div>
)}
{visualStyle === 'glow' && (
<div className="flex items-center gap-1">
<span className="text-[10px] text-slate-500">Glow</span>
<input type="range" min={2} max={24} step={1}
value={style.glowSize}
onChange={e => onChange({ glowSize: +e.target.value })}
className="w-16 h-1.5 accent-brand-400" title="Glow radius (px)" />
<span className="text-[10px] tabular-nums text-slate-400 w-6">{style.glowSize}px</span>
</div>
)}
</div>
{/* Dynamic BG from album art — only shown when cover art is available */}
{hasCoverArt && (
@@ -816,7 +830,7 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
}, [])
// Destructure for convenience
const { fontFamily, fontSize: baseFontSize, bgColor, textColor, highlightColor, wordHighlight, textAlign, lineSpacing, dynBg, karaokeMode, fontBold, strokeEnabled, strokeWidth, strokeColor, shadowEnabled, shadowBlur, shadowX, shadowY, shadowColor, shadowOpacity, scaleX, scaleY, popScale, popSnap } = style
const { fontFamily, fontSize: baseFontSize, bgColor, textColor, highlightColor, wordHighlight, textAlign, lineSpacing, dynBg, karaokeMode, fontBold, strokeEnabled, strokeWidth, strokeColor, shadowEnabled, shadowBlur, shadowX, shadowY, shadowColor, shadowOpacity, scaleX, scaleY, popScale, popSnap, glowSize } = style
// fontSize is finalised after isFullscreen is available (declared below)
// Passed to KaraokeWord so each word can render its own stroke/shadow behind-layer.
@@ -901,9 +915,9 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
const audioCtxRef = useRef<AudioContext | null>(null)
const gainRefs = useRef<Record<string, GainNode>>({})
const [translateY, setTranslateY] = useState(0)
const containerRef = useRef<HTMLDivElement>(null)
const scrollDivRef = useRef<HTMLDivElement>(null)
const translateYRef = useRef(0)
const activeLineRef = useRef<HTMLDivElement | null>(null)
const rafRef = useRef<number | null>(null)
const manualTimeRef = useRef(0)
@@ -1177,18 +1191,22 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
// The container has position:relative so children's offsetTop is measured
// from the container, not a distant ancestor.
useLayoutEffect(() => {
if (!activeLineRef.current || !containerRef.current) return
if (!activeLineRef.current || !containerRef.current || !scrollDivRef.current) return
const container = containerRef.current
const el = activeLineRef.current
setTranslateY(container.clientHeight / 2 - el.offsetTop - el.offsetHeight / 2)
}, [activeLine])
const ty = container.clientHeight / 2 - el.offsetTop - el.offsetHeight / 2
translateYRef.current = ty
scrollDivRef.current.style.transform = `translateY(${ty}px) scaleX(${scaleX}) scaleY(${scaleY})`
}, [activeLine, scaleX, scaleY])
// ── Recenter active line ──────────────────────────────────────────────────
function handleRecenter() {
if (!activeLineRef.current || !containerRef.current) return
if (!activeLineRef.current || !containerRef.current || !scrollDivRef.current) return
const container = containerRef.current
const el = activeLineRef.current
setTranslateY(container.clientHeight / 2 - el.offsetTop - el.offsetHeight / 2)
const ty = container.clientHeight / 2 - el.offsetTop - el.offsetHeight / 2
translateYRef.current = ty
scrollDivRef.current.style.transform = `translateY(${ty}px) scaleX(${scaleX}) scaleY(${scaleY})`
}
// ── Controls ──────────────────────────────────────────────────────────────
@@ -1453,18 +1471,16 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
function renderKaraokeStyle() {
if (lines.length === 0) return <p style={{ color: textColor, opacity: 0.4, textAlign }}>No lyrics</p>
const window = 3
const start = Math.max(0, activeLine - window)
const end = Math.min(lines.length - 1, activeLine + window + 1)
const visible = lines.slice(start, end + 1)
const lineOrigin = textAlign === 'left' ? 'left center' : textAlign === 'right' ? 'right center' : 'center center'
return (
<>
{visible.map((line, vi) => {
const i = start + vi
{lines.map((line, i) => {
const active = i === activeLine
const past = i < activeLine
const dist = Math.abs(i - activeLine)
const nextLineTime = lines[i + 1]?.time
const scale = active ? 1.0 : dist === 1 ? 0.88 : dist === 2 ? 0.82 : 0.78
if (!active) {
return (
@@ -1472,11 +1488,13 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
key={i}
style={{
textAlign,
padding: '0.3em 0.75em',
fontSize: fontSize * 0.85,
lineHeight: lineSpacing,
opacity: past ? 0.55 : 0.25,
transition: 'opacity 0.3s',
padding: '0.4em 0.75em',
fontSize,
lineHeight: lineSpacing,
opacity: dist > 5 ? 0 : (past ? 0.55 : 0.25),
transform: `scale(${scale})`,
transformOrigin: lineOrigin,
transition: 'transform 0.35s ease-out, opacity 0.35s ease-out',
}}
>
<SpeakerDot line={line} prevSpeaker={lines[i - 1]?.speaker} color={line.speaker ? getSpeakerColor(line.speaker) : undefined} name={line.speaker ? getSpeakerName(line.speaker) : undefined} />
@@ -1506,9 +1524,12 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
ref={(el) => { activeLineRef.current = el }}
style={{
textAlign,
padding: '0.4em 0.75em',
fontSize: fontSize * 1.05,
lineHeight: lineSpacing,
padding: '0.4em 0.75em',
fontSize,
lineHeight: lineSpacing,
transform: 'scale(1)',
transformOrigin: lineOrigin,
transition: 'transform 0.35s ease-out',
}}
>
<SpeakerDot line={line} prevSpeaker={lines[i - 1]?.speaker} color={line.speaker ? getSpeakerColor(line.speaker) : undefined} name={line.speaker ? getSpeakerName(line.speaker) : undefined} />
@@ -1526,7 +1547,7 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
done={done}
bright={activeBright}
dim={activeDim}
fontSize={fontSize * 1.05}
fontSize={fontSize}
isWordEnd={w.isWordEnd}
elRef={wi === activeWordIdx ? activeWordSpanRef : undefined}
isActive={wi === activeWordIdx}
@@ -1567,18 +1588,16 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
function renderGlowStyle() {
if (lines.length === 0) return <p style={{ color: textColor, opacity: 0.4, textAlign }}>No lyrics</p>
const window = 3
const start = Math.max(0, activeLine - window)
const end = Math.min(lines.length - 1, activeLine + window + 1)
const visible = lines.slice(start, end + 1)
const lineOrigin = textAlign === 'left' ? 'left center' : textAlign === 'right' ? 'right center' : 'center center'
return (
<>
{visible.map((line, vi) => {
const i = start + vi
{lines.map((line, i) => {
const active = i === activeLine
const past = i < activeLine
const dist = Math.abs(i - activeLine)
const nextLineTime = lines[i + 1]?.time
const scale = active ? 1.0 : dist === 1 ? 0.88 : dist === 2 ? 0.82 : 0.78
if (!active) {
return (
@@ -1586,11 +1605,13 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
key={i}
style={{
textAlign,
padding: '0.3em 0.75em',
fontSize: fontSize * 0.85,
lineHeight: lineSpacing,
opacity: past ? 0.5 : 0.2,
transition: 'opacity 0.4s ease',
padding: '0.4em 0.75em',
fontSize,
lineHeight: lineSpacing,
opacity: dist > 5 ? 0 : (past ? 0.5 : 0.2),
transform: `scale(${scale})`,
transformOrigin: lineOrigin,
transition: 'transform 0.35s ease-out, opacity 0.35s ease-out',
}}
>
<SpeakerDot line={line} prevSpeaker={lines[i - 1]?.speaker} color={line.speaker ? getSpeakerColor(line.speaker) : undefined} name={line.speaker ? getSpeakerName(line.speaker) : undefined} />
@@ -1618,11 +1639,13 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
ref={(el) => { activeLineRef.current = el }}
style={{
textAlign,
padding: '0.4em 0.75em',
fontSize: fontSize * 1.05,
lineHeight: lineSpacing,
filter: `drop-shadow(0 0 8px ${glowColor}cc) drop-shadow(0 0 16px ${glowColor}66)`,
transition: 'filter 0.3s ease',
padding: '0.4em 0.75em',
fontSize,
lineHeight: lineSpacing,
transform: 'scale(1)',
transformOrigin: lineOrigin,
filter: `drop-shadow(0 0 ${glowSize}px ${glowColor}cc) drop-shadow(0 0 ${glowSize * 2}px ${glowColor}66)`,
transition: 'transform 0.35s ease-out, filter 0.3s ease',
}}
>
<SpeakerDot line={line} prevSpeaker={lines[i - 1]?.speaker} color={line.speaker ? getSpeakerColor(line.speaker) : undefined} name={line.speaker ? getSpeakerName(line.speaker) : undefined} />
@@ -1640,7 +1663,7 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
done={done}
bright={glowColor}
dim={dimColor}
fontSize={fontSize * 1.05}
fontSize={fontSize}
isWordEnd={w.isWordEnd}
elRef={wi === activeWordIdx ? activeWordSpanRef : undefined}
isActive={wi === activeWordIdx}
@@ -1681,19 +1704,16 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
function renderBlurStyle() {
if (lines.length === 0) return <p style={{ color: textColor, opacity: 0.4, textAlign }}>No lyrics</p>
const window = 3
const start = Math.max(0, activeLine - window)
const end = Math.min(lines.length - 1, activeLine + window + 1)
const visible = lines.slice(start, end + 1)
const lineOrigin = textAlign === 'left' ? 'left center' : textAlign === 'right' ? 'right center' : 'center center'
return (
<>
{visible.map((line, vi) => {
const i = start + vi
{lines.map((line, i) => {
const active = i === activeLine
const past = i < activeLine
const dist = Math.abs(i - activeLine)
const nextLineTime = lines[i + 1]?.time
const scale = active ? 1.0 : dist === 1 ? 0.88 : dist === 2 ? 0.82 : 0.78
if (!active) {
return (
@@ -1701,13 +1721,15 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
key={i}
style={{
textAlign,
padding: '0.3em 0.75em',
fontSize: fontSize * 0.88,
lineHeight: lineSpacing,
color: past ? (line.speaker ? getSpeakerColor(line.speaker) : wordHighlight) : textColor,
opacity: past ? 0.4 : 0.15,
filter: `blur(${dist * 1.5}px)`,
transition: 'opacity 0.4s ease, filter 0.4s ease',
padding: '0.4em 0.75em',
fontSize,
lineHeight: lineSpacing,
color: past ? (line.speaker ? getSpeakerColor(line.speaker) : wordHighlight) : textColor,
opacity: dist > 5 ? 0 : (past ? 0.4 : 0.15),
filter: dist > 4 ? 'none' : `blur(${dist * 1.5}px)`,
transform: `scale(${scale})`,
transformOrigin: lineOrigin,
transition: 'transform 0.35s ease-out, opacity 0.35s ease-out, filter 0.35s ease-out',
}}
>
<SpeakerDot line={line} prevSpeaker={lines[i - 1]?.speaker} color={line.speaker ? getSpeakerColor(line.speaker) : undefined} name={line.speaker ? getSpeakerName(line.speaker) : undefined} />
@@ -1726,11 +1748,13 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
ref={(el) => { activeLineRef.current = el }}
style={{
textAlign,
padding: '0.4em 0.75em',
fontSize: fontSize * 1.1,
lineHeight: lineSpacing,
filter: 'none',
transition: 'filter 0.4s ease',
padding: '0.4em 0.75em',
fontSize,
lineHeight: lineSpacing,
transform: 'scale(1)',
transformOrigin: lineOrigin,
filter: 'none',
transition: 'transform 0.35s ease-out, filter 0.35s ease-out',
}}
>
<SpeakerDot line={line} prevSpeaker={lines[i - 1]?.speaker} color={line.speaker ? getSpeakerColor(line.speaker) : undefined} name={line.speaker ? getSpeakerName(line.speaker) : undefined} />
@@ -1748,7 +1772,7 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
done={done}
bright={activeBright}
dim={activeDim}
fontSize={fontSize * 1.1}
fontSize={fontSize}
isWordEnd={w.isWordEnd}
elRef={wi === activeWordIdx ? activeWordSpanRef : undefined}
isActive={wi === activeWordIdx}
@@ -1820,8 +1844,8 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
} as any}
>
<div
ref={scrollDivRef}
style={{
transform: `translateY(${translateY}px) scaleX(${scaleX}) scaleY(${scaleY})`,
transition: 'transform 0.35s cubic-bezier(0.33, 1, 0.68, 1)',
willChange: 'transform',
textAlign,
@@ -2063,7 +2087,7 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
{/* Style picker panel */}
{showStylePicker && (
<div className={isFullscreen ? 'bg-black/50' : 'bg-slate-100/80 dark:bg-gray-800/80'}>
<StylePicker style={style} onChange={patchStyle} onReset={resetStyle} hasCoverArt={!!coverArtUrl && artLoaded} />
<StylePicker style={style} onChange={patchStyle} onReset={resetStyle} hasCoverArt={!!coverArtUrl && artLoaded} visualStyle={visualStyle} />
{/* Speaker colour swatches — always shown so user knows if diarization is missing */}
<div className="px-3 py-2 border-b border-white/10 flex items-center gap-3 flex-wrap">
<span className="text-[10px] text-slate-500 shrink-0">Speakers</span>