From 5885229c822d93f0f75571f779e9bc079b4bfa69 Mon Sep 17 00:00:00 2001 From: translator Date: Fri, 6 Mar 2026 16:56:04 +0900 Subject: [PATCH] Fixed karaoke rendering engine. --- .gitignore | 1 + SUMMARIES.md | 39 ++- backend/static/index.html | 2 +- frontend/src/components/LyricsLivePreview.tsx | 245 +++++++++++------- 4 files changed, 195 insertions(+), 92 deletions(-) diff --git a/.gitignore b/.gitignore index 88e3e2a..33c2e98 100755 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ imports/ db/ ./db/ projects/ +claude/ # Model caches (large files, downloaded at runtime) # These are typically mounted as volumes diff --git a/SUMMARIES.md b/SUMMARIES.md index ba1f22e..badf284 100644 --- a/SUMMARIES.md +++ b/SUMMARIES.md @@ -299,7 +299,7 @@ Result: shadow (back) → stroke → base text (front), all properly layered. **hexToRgba** moved above `KaraokeWord` so `behindLayer` can call it. -Container keeps `WebkitTextStroke` + `paintOrder` + `textShadow` for non-karaoke modes (scroll/fade) where text has opaque fills and the single-element approach works correctly. +**Superseded** — stroke/shadow are now handled per-line via the behind-layer pattern for all modes. See "Universal behind-layer stroke/shadow" below. ### Layer z-index fix + sluggishness fix @@ -324,7 +324,7 @@ The windowed overlay (`div` wrapping artist + title `

` tags) and the fullscre ### Stroke rounded joins — prevent "fang" artefacts -`-webkit-text-stroke` defaults to miter joins at sharp glyph corners, producing spike/fang artefacts. Fixed by adding `strokeLinejoin: 'round'` and `strokeLinecap: 'round'` (SVG stroke properties, honoured by Chromium/WebKit on HTML text with `-webkit-text-stroke`) to both the `KaraokeWord` behind-layer span and the outer lyrics container (for non-karaoke/scroll/fade modes). +`-webkit-text-stroke` defaults to miter joins at sharp glyph corners, producing spike/fang artefacts. Fixed by adding `strokeLinejoin: 'round'` and `strokeLinecap: 'round'` (SVG stroke properties, honoured by Chromium/WebKit on HTML text with `-webkit-text-stroke`) to behind-layer spans. **Superseded** by universal behind-layer approach — see below. ### Pop mode — Snap slider (transition duration) @@ -365,3 +365,38 @@ Added `glowSize: number` to `StyleState` and `DEFAULT_STYLE` (default: 8px). A * - `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). + +--- + +### Universal behind-layer stroke/shadow for all line types + +**Problem:** Stroke and shadow were applied via `WebkitTextStroke` / `textShadow` on the outer lyrics container div, inherited by all descendant text. This caused: +- **Fangs** on non-active karaoke/glow/blur lines: plain `` elements inherited `paintOrder: stroke fill` from the container, producing miter-join spikes at sharp letter corners. +- **Stroke inside gradient fill**: for wordless active lines using `WebkitTextFillColor: transparent`, the inherited stroke bled through the transparent fill area. + +Previously only `KaraokeWord` (active words) used the behind-layer pattern. Non-active lines and wordless active lines inherited stroke/shadow from the container. + +**Fix:** `WebkitTextStroke`, `paintOrder`, `strokeLinejoin`, `strokeLinecap`, and `textShadow` are **removed from the container entirely**. Every line in every mode now renders stroke and shadow via its own behind-layer: + +``` +Outer div — opacity, transform/scale, font size (NO stroke/shadow/padding) + behindLayer div — position: absolute, zIndex: 0, aria-hidden + strokeColor fill, WebkitTextStroke, paintOrder: stroke fill + strokeLinejoin: round, textShadow + frontLayer div — position: relative, zIndex: 1, padding + WebkitTextStroke: '0 transparent', textShadow: none + actual text color / gradient fill +``` + +Three shared constants computed once per render: +```typescript +const lineStrokeVal = strokeEnabled && strokeWidth > 0 ? `${strokeWidth}px ${strokeColor}` : undefined +const lineShadowVal = shadowEnabled ? `${shadowX}px ${shadowY}px ${shadowBlur}px ${hexToRgba(...)}` : undefined +const lineNeedsLayer = !!(lineStrokeVal || lineShadowVal) +``` + +When `lineNeedsLayer` is false the behindLayer is skipped entirely (single-div fast path). + +**Coverage:** `renderScrollStyle`, `renderFadeStyle`, `renderKaraokeStyle` (non-active + active wordless), `renderGlowStyle` (non-active + active wordless), `renderBlurStyle` (non-active + active wordless). Active word-by-word lines continue to use `KaraokeWord`'s existing behind-layer. + +**Result:** Fill is always the top layer; stroke appears only outside the letterform; shadow is always behind both stroke and fill — in every mode, for every line. diff --git a/backend/static/index.html b/backend/static/index.html index 08db5b0..c0e6ae0 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -19,7 +19,7 @@ - + diff --git a/frontend/src/components/LyricsLivePreview.tsx b/frontend/src/components/LyricsLivePreview.tsx index 8b7aa9d..97faab4 100755 --- a/frontend/src/components/LyricsLivePreview.tsx +++ b/frontend/src/components/LyricsLivePreview.tsx @@ -1397,33 +1397,50 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty }) } + // ── Line-level stroke / shadow layer values ─────────────────────────────── + // Used by every render function to implement the behind-layer pattern: + // behindLayer (zIndex 0): stroke + shadow, painted first + // frontLayer (zIndex 1): fill only, no stroke, no shadow — always on top + // This guarantees stroke is ONLY outside the letterform and shadow is BEHIND. + const lineStrokeVal = strokeEnabled && strokeWidth > 0 ? `${strokeWidth}px ${strokeColor}` : undefined + const lineShadowVal = shadowEnabled ? `${shadowX}px ${shadowY}px ${shadowBlur}px ${hexToRgba(shadowColor, shadowOpacity)}` : undefined + const lineNeedsLayer = !!(lineStrokeVal || lineShadowVal) + // ── Line renderers ──────────────────────────────────────────────────────── function renderScrollStyle() { if (lines.length === 0) return

No lyrics

+ const pad = '0.3em 0.75em' return ( <> {lines.map((line, i) => { - const isActive = i === activeLine - const isPast = i < activeLine + const isActive = i === activeLine + const isPast = i < activeLine const lineColor = line.speaker ? getSpeakerColor(line.speaker) : (isActive ? highlightColor : textColor) + const lineFSize = isActive ? fontSize * 1.08 : fontSize * 0.9 return (
{ activeLineRef.current = el } : undefined} style={{ - color: lineColor, opacity: isActive ? 1 : isPast ? 0.45 : 0.35, - fontSize: isActive ? fontSize * 1.08 : fontSize * 0.9, + fontSize: lineFSize, fontWeight: isActive ? 700 : 400, textAlign, - padding: '0.3em 0.75em', lineHeight: lineSpacing, transition: 'all 0.25s ease', + position: lineNeedsLayer ? 'relative' : undefined, }} > - - {line.text} + {lineNeedsLayer && ( + + )} +
+ + {line.text} +
) })} @@ -1433,6 +1450,7 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty function renderFadeStyle() { if (lines.length === 0) return

No lyrics

+ const pad = '0.4em 0.75em' return ( <> {lines.map((line, i) => { @@ -1449,18 +1467,24 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty key={i} ref={active ? (el) => { activeLineRef.current = el } : undefined} style={{ - color: lineColor, opacity, fontSize: active ? fontSize * 1.12 : fontSize, fontWeight: active ? 700 : 400, textAlign, - padding: '0.4em 0.75em', lineHeight: lineSpacing, transition: 'all 0.35s ease', + position: lineNeedsLayer ? 'relative' : undefined, }} > - - {line.text} + {lineNeedsLayer && ( + + )} +
+ + {line.text} +
) })} @@ -1483,34 +1507,37 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty const scale = active ? 1.0 : dist === 1 ? 0.88 : dist === 2 ? 0.82 : 0.78 if (!active) { + const pad = '0.4em 0.75em' + const wColor = line.speaker ? getSpeakerColor(line.speaker) : (past ? wordHighlight : textColor) + const behindContent = line.words.length > 0 + ? line.words.map((w, wi) => {w.text}) + : line.text + const frontContent = line.words.length > 0 + ? line.words.map((w, wi) => {w.text}) + : {line.text} return (
5 ? 0 : (past ? 0.55 : 0.25), transform: `scale(${scale})`, transformOrigin: lineOrigin, transition: 'transform 0.35s ease-out, opacity 0.35s ease-out', + position: lineNeedsLayer ? 'relative' : undefined, }} > - - {line.words.length > 0 - ? line.words.map((w, wi) => { - const wColor = line.speaker - ? getSpeakerColor(line.speaker) - : (past ? wordHighlight : textColor) - return ( - - {w.text} - - ) - }) - : {line.text} - } + {lineNeedsLayer && ( + + )} +
+ + {frontContent} +
) } @@ -1559,22 +1586,32 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty ) }) : (() => { - const nextTime = lines[activeLine + 1]?.time ?? (line.time + 4) - const pct = Math.max(0, Math.min(1, (currentTime - line.time) / (nextTime - line.time))) + const nextTime = lines[activeLine + 1]?.time ?? (line.time + 4) + const pct = Math.max(0, Math.min(1, (currentTime - line.time) / (nextTime - line.time))) const fillColor = line.speaker ? getSpeakerColor(line.speaker) : highlightColor return ( - - {line.text} - + <> + {lineNeedsLayer && ( + + )} + + {line.text} + + ) })() } @@ -1600,29 +1637,37 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty const scale = active ? 1.0 : dist === 1 ? 0.88 : dist === 2 ? 0.82 : 0.78 if (!active) { + const pad = '0.4em 0.75em' + const wColor = past ? (line.speaker ? getSpeakerColor(line.speaker) : wordHighlight) : textColor + const behindContent = line.words.length > 0 + ? line.words.map((w, wi) => {w.text}) + : line.text + const frontContent = line.words.length > 0 + ? line.words.map((w, wi) => {w.text}) + : {line.text} return (
5 ? 0 : (past ? 0.5 : 0.2), transform: `scale(${scale})`, transformOrigin: lineOrigin, transition: 'transform 0.35s ease-out, opacity 0.35s ease-out', + position: lineNeedsLayer ? 'relative' : undefined, }} > - - {line.words.length > 0 - ? line.words.map((w, wi) => ( - - {w.text} - - )) - : {line.text} - } + {lineNeedsLayer && ( + + )} +
+ + {frontContent} +
) } @@ -1678,19 +1723,29 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty const nextT = lines[activeLine + 1]?.time ?? (line.time + 4) const pct = Math.max(0, Math.min(1, (currentTime - line.time) / (nextT - line.time))) return ( - - {line.text} - + <> + {lineNeedsLayer && ( + + )} + + {line.text} + + ) })() } @@ -1716,24 +1771,33 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty const scale = active ? 1.0 : dist === 1 ? 0.88 : dist === 2 ? 0.82 : 0.78 if (!active) { + const pad = '0.4em 0.75em' + const wColor = past ? (line.speaker ? getSpeakerColor(line.speaker) : wordHighlight) : textColor + const lineText = line.words.length > 0 ? line.words.map(w => w.text + (w.isWordEnd ? ' ' : '')).join('') : line.text return (
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', + position: lineNeedsLayer ? 'relative' : undefined, }} > - - {line.words.length > 0 ? line.words.map(w => w.text + (w.isWordEnd ? ' ' : '')).join('') : line.text} + {lineNeedsLayer && ( + + )} +
+ + {lineText} +
) } @@ -1788,19 +1852,29 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty const pct = Math.max(0, Math.min(1, (currentTime - line.time) / (nextT - line.time))) const fillColor = line.speaker ? getSpeakerColor(line.speaker) : highlightColor return ( - - {line.text} - + <> + {lineNeedsLayer && ( + + )} + + {line.text} + + ) })() } @@ -1832,15 +1906,8 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty flex: isFullscreen ? '1 1 0' : undefined, overflow: 'hidden', position: 'relative', - textShadow: shadowEnabled - ? `${shadowX}px ${shadowY}px ${shadowBlur}px ${hexToRgba(shadowColor, shadowOpacity)}` - : undefined, - WebkitTextStroke: (strokeEnabled && strokeWidth > 0) - ? `${strokeWidth}px ${strokeColor}` - : undefined, - paintOrder: (strokeEnabled && strokeWidth > 0) ? 'stroke fill' : undefined, - strokeLinejoin: (strokeEnabled && strokeWidth > 0) ? 'round' : undefined, - strokeLinecap: (strokeEnabled && strokeWidth > 0) ? 'round' : undefined, + // Stroke and shadow are NOT set on the container — each line div renders them + // via its own behindLayer (see lineNeedsLayer / lineStrokeVal / lineShadowVal above). } as any} >