From 8333da13514194c40d4e8a39758992fb5ba538c4 Mon Sep 17 00:00:00 2001 From: translator Date: Fri, 6 Mar 2026 15:09:22 +0900 Subject: [PATCH] Upgrade to karaoke display window, including slightly more interesting graphical options. --- SUMMARIES.md | 120 ++++++ backend/static/index.html | 4 +- frontend/src/components/LyricsLivePreview.tsx | 359 +++++++++++++++--- 3 files changed, 428 insertions(+), 55 deletions(-) diff --git a/SUMMARIES.md b/SUMMARIES.md index 80af81d..f9dad52 100644 --- a/SUMMARIES.md +++ b/SUMMARIES.md @@ -213,3 +213,123 @@ Changed `color: isActive ? bright : dim` → `color: (isActive || done) ? bright **Problem:** Active word is `fontSize * 1.15`; `base` uses `verticalAlign: 'top'`, so the larger word's top aligns with others but extends further down. **Fix:** Override to `verticalAlign: 'middle'` in the pop-mode branch so all words (normal and enlarged) center on the same axis. + +--- + +### Album card font not affected by font option + +Both the small windowed overlay and the fullscreen album panel used hardcoded `fontFamily` / `fontWeight` values, so the user's font selection had no effect. + +**Fix:** Added `fontFamily` to both text containers (windowed overlay `
` and fullscreen panel `
`). The subtitle in both also respects `fontWeight: fontBold ? 700 : 400`. Artist name stays at 700 (it's always a heading). + +Also changed the windowed overlay from `flexDirection: 'column'` (art above, text below) to `flexDirection: 'row', alignItems: 'center'` so text sits beside and vertically centered on the art. + +--- + +### TypeScript error 7026 / 2875 / 2322 (pre-existing, not build-blocking) + +These TS language server errors ("no interface JSX.IntrinsicElements exists", "react/jsx-runtime not found") appear on whichever line was last edited. They are a pre-existing tsconfig / language server cache issue — not introduced by any of the above changes. Vite uses esbuild for transpilation and does not type-check, so `vite build` is unaffected. Restart the TS server (VS Code: Ctrl+Shift+P → "TypeScript: Restart TS Server") or let the container run `npm install` to resolve. + +### Styling options — stroke, shadow, scale, pop size + +Added to `StyleState`: `strokeWidth`, `strokeColor`, `shadowBlur`, `shadowX`, `shadowY`, `shadowColor`, `scaleX`, `scaleY`, `popScale`. + +**StylePicker** gained two new rows: +- **Effects row**: stroke color swatch + width slider (0–4), shadow color swatch + blur/X/Y sliders. +- **Scale row**: W (horizontal) and H (vertical) scale sliders (0.5–2×). A **Pop** slider (15–25%) appears conditionally when `karaokeMode === 'pop'`. + +**Lyrics container** (outer div): `textShadow` and `WebkitTextStroke` applied from state; `as any` cast used because the file uses named React imports (no `React` namespace for `React.CSSProperties`). + +**Inner lyrics div**: `transform` updated to `translateY(…) scaleX(…) scaleY(…)`. + +**`KaraokeWord`**: accepts `popScale?: number` (default 15); pop branch uses `fontSize * (1 + popScale / 100)` for the active word size. + +**All three `KaraokeWord` call sites** (karaoke / glow / blur renderers) updated to pass `popScale={popScale}`. + +### Stroke fix — proper outer border, not hollow outline; show/hide toggles; shadow opacity; Reset + +**Problem:** `-webkit-text-stroke` strokes symmetrically inward and outward, hollowing the glyph fill. In gradient (fill) mode, `-webkit-text-fill-color: transparent` made it worse — just an outline with no visible fill. + +**Fix:** Replaced `-webkit-text-stroke` entirely with a disc-shaped `text-shadow` simulation. `makeStrokeShadow(width, color)` generates zero-blur shadows at every integer offset within a radius, producing a filled outer ring. Works correctly with `WebkitTextFillColor: transparent` (gradient mode) and normal color fills (pop mode). + +**Added `hexToRgba(hex, opacity)`** to apply shadow opacity to the drop shadow. + +**New `StyleState` fields:** `strokeEnabled: boolean`, `shadowEnabled: boolean`, `shadowOpacity: number` (0–1). + +**`DEFAULT_STYLE` constant** extracted so defaults are a single source of truth used by both `useState` and the new `resetStyle` handler. + +**StylePicker UI changes:** +- Stroke and Shadow labels are now toggle **buttons** (click to enable/disable); controls collapse when disabled. +- Shadow controls gained an **Opacity** slider (0–1) next to the color swatch. +- **Reset** button added in the font row (right side) — clears localStorage and restores `DEFAULT_STYLE`. + +**`StylePicker` prop:** `onReset: () => void` added. `resetStyle` callback in main component removes the localStorage key and calls `setStyle(DEFAULT_STYLE)`. + +### Stroke rendering order — abandoned text-shadow approach; switched to WebkitTextStroke + paint-order + +**Attempt 1 (disc text-shadow):** Generated a disc of zero-blur `text-shadow` entries. Inner shadows covered the gradient interior, making text look hollow/broken. + +**Attempt 2 (ring text-shadow):** Limited shadows to the outermost pixel band. Still jagged/bubbly in practice — each shadow entry is a full pixel-offset copy of the glyph shape; many overlapping copies create rough anti-aliasing artefacts visible as a bubbly halo. + +**Final fix:** Removed `makeStrokeShadow` entirely. Now use: +- `WebkitTextStroke: '${strokeWidth}px ${strokeColor}'` on the container (cascades to all child text) +- `paintOrder: 'stroke fill'` on the container (cascades): renders stroke first, then fill on top — only the outer half of the stroke extends beyond the glyph edge; the inner half is covered by the opaque fill + +For pop mode (solid fill): only the outer stroke ring is visible. Clean outer border. ✓ +For fill/gradient mode (`WebkitTextFillColor: transparent`): fill is transparent, so inner half of stroke is slightly visible at the glyph edge. For thin strokes this is a minor tint at the very edge; outer border is clean and anti-aliased. Acceptable trade-off vs. jagged shadow approach. ✓ + +Drop shadow remains via `textShadow` on the container, unchanged. + +### Stroke/shadow layered DOM approach in KaraokeWord + +**Problem:** `WebkitTextStroke` + `paint-order: stroke fill` still broke gradient text. CSS paints `background` (where the gradient lives via `background-clip:text`) before `text-shadow`/`WebkitTextStroke`, so any stroke technique on the same element appears on top of the gradient, not behind it. No single-element CSS solution can place the stroke behind a `background-clip:text` gradient. + +**Fix:** Layered DOM structure inside `KaraokeWord`. When stroke or shadow is active: +``` + ← wrapper (layout) + ← behind-layer: stroke + shadow + ← fill-layer: gradient/pop text +``` +- **Behind-layer**: renders `WebkitTextStroke` + `paintOrder: stroke fill` + `textShadow`. With opaque fill color, only the outer half of the stroke extends beyond the glyph → clean outer ring. +- **Fill-layer**: resets `WebkitTextStroke: '0 transparent'` and `textShadow: 'none'` to cancel container inheritance, then renders gradient or solid-color text on top. + +Result: shadow (back) → stroke → base text (front), all properly layered. + +**`WordEffects` interface** added; `wordEffects` object constructed from destructured style state; passed to all 3 `KaraokeWord` call sites as `effects={wordEffects}`. + +**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. + +### Layer z-index fix + sluggishness fix + +**z-index bug:** `position: absolute` elements paint on top of in-flow elements by default regardless of DOM order. The behind-layer (`position: absolute`) was rendering above the fill span. Fixed by adding `zIndex: 0` to the behind-layer and `position: relative; zIndex: 1` to the fill/pop front span via `frontLayerBase`. CSS z-index only applies to positioned elements, so the fill span needed `position: relative` to participate in z-index stacking. + +**Sluggishness:** The RAF loop triggers React state updates (~60 fps), causing re-renders of the lyrics line. Each re-render was constructing a new `wordEffects` object, propagating as a changed prop to every `KaraokeWord` in the line. Fixed by wrapping `wordEffects` in `useMemo` with the style fields as dependencies — the object reference is now stable during playback and only changes when the user adjusts a style control. `useMemo` added to the React import. + +### Album art overlay text exempt from stroke/shadow + +The windowed overlay (`div` wrapping artist + title `

` tags) and the fullscreen album panel (`div` with artist/title) both inherit `WebkitTextStroke` and `textShadow` from the outer lyrics container. Fixed by adding `WebkitTextStroke: 'initial'` and `textShadow: 'none'` to the `style` prop of each wrapper div (`as any` cast to avoid TS CSSProperties namespace error). + +### Pop mode syllable transition — font-size → transform: scale() + +**Problem:** Pop mode used `fontSize: activeFontSize` (switching between base and scaled size) on the wrapper, with `transition: 'font-size 0.08s ease'`. Font-size changes trigger layout reflow on every transition frame, causing jank. 80ms was also too short, making the snap feel jarring. + +**Fix:** +- Replaced `fontSize` toggling with `transform: scale(1 + popScale/100)` on the wrapper span — GPU-composited, zero layout reflow. +- `fontSize` is now always `fontSize` (base size); the wrapper transform handles the visual growth. +- Transition: `transform 0.15s ease-out, color 0.15s ease-out` — 150ms feels smooth without lag; `ease-out` snaps into the active state and eases out of it naturally. +- `willChange: 'transform'` added on pop-mode wrappers to hint the browser to promote them to a compositor layer. +- Behind-layer `fontSize` also stays at base size (scales with the wrapper via inherited transform). + +### 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). + +### Pop mode — Snap slider (transition duration) + +Added `popSnap: number` (ms) to `StyleState` and `DEFAULT_STYLE` (default: 150ms). A **Snap** slider (50–500ms, step 25ms) appears next to the Pop slider when `karaokeMode === 'pop'`. The value is passed as `snapMs` prop to `KaraokeWord` (default 150) and used in the `wrapStyle` transition: `` `transform ${snapMs}ms ease-out, color ${snapMs}ms ease-out` ``. Range rationale: 50ms feels near-instant/snappy; 500ms is a slow, deliberate fade. + +### BG color scope fix — fullscreen root no longer inherits bgColor + +The fullscreen root `

` 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}`). diff --git a/backend/static/index.html b/backend/static/index.html index 9e56a21..57b6eef 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -19,8 +19,8 @@ - - + +
diff --git a/frontend/src/components/LyricsLivePreview.tsx b/frontend/src/components/LyricsLivePreview.tsx index af2d0ab..f5fc0f9 100755 --- a/frontend/src/components/LyricsLivePreview.tsx +++ b/frontend/src/components/LyricsLivePreview.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useLayoutEffect, useRef, useCallback } from 'react' +import { useState, useEffect, useLayoutEffect, useRef, useCallback, useMemo } from 'react' import { Play, Pause, SkipBack, Volume2, VolumeX, Palette, Pencil, X, AlignLeft, AlignCenter, AlignRight, Type, Crosshair, Maximize2, Minimize2 } from 'lucide-react' import type { LyricsStyleOptions } from '../types' import { registerPlayback, unregisterPlayback, publishMeta, clearMeta } from '../utils/audioRegistry' @@ -230,7 +230,27 @@ function formatTime(s: number): string { // ─── Word rendering helpers ─────────────────────────────────────────────────── -/** Karaoke word renderer — supports 'fill' (gradient sweep) and 'pop' (active word lit) modes. */ +interface WordEffects { + strokeEnabled: boolean + strokeWidth: number + strokeColor: string + shadowEnabled: boolean + shadowX: number + shadowY: number + shadowBlur: number + shadowColor: string + shadowOpacity: number +} + +/** + * Karaoke word renderer — supports 'fill' (gradient sweep) and 'pop' (active word lit) modes. + * + * Stroke + shadow are composited via a separately positioned behind-layer so that the + * base text always renders in front: shadow → stroke → base text (front). + * This is the only reliable approach for gradient text where WebkitTextFillColor is + * transparent — CSS paint-order alone cannot push text-shadow/stroke behind a + * background-clip:text gradient. + */ function KaraokeWord({ word, fill, @@ -242,6 +262,9 @@ function KaraokeWord({ elRef, isActive, mode, + popScale = 15, + snapMs = 150, + effects, }: { word: string fill: number // 0–1 @@ -253,53 +276,127 @@ function KaraokeWord({ elRef?: { current: HTMLSpanElement | null } isActive?: boolean mode?: 'fill' | 'pop' + popScale?: number + snapMs?: number + effects?: WordEffects }) { - const base: React.CSSProperties = { + const strokeVal = effects?.strokeEnabled && effects.strokeWidth > 0 + ? `${effects.strokeWidth}px ${effects.strokeColor}` : undefined + const shadowVal = effects?.shadowEnabled + ? `${effects.shadowX}px ${effects.shadowY}px ${effects.shadowBlur}px ${hexToRgba(effects.shadowColor, effects.shadowOpacity)}` + : undefined + const needsLayer = !!(strokeVal || shadowVal) + + // Pop scale via CSS transform — GPU-accelerated, no layout reflow (unlike font-size changes) + const popTransform = mode === 'pop' + ? `scale(${isActive ? 1 + popScale / 100 : 1})` + : undefined + + // ── Wrapper layout props (applied to the outermost element in every branch) ── + const wrapStyle = { display: 'inline-block', - verticalAlign: 'top', + verticalAlign: mode === 'pop' ? 'middle' : 'top', marginRight: isWordEnd ? '0.25em' : '0', fontSize, - } + position: needsLayer ? 'relative' : undefined, + transform: popTransform, + transition: mode === 'pop' ? `transform ${snapMs}ms ease-out, color ${snapMs}ms ease-out` : undefined, + willChange: mode === 'pop' ? 'transform' : undefined, + } as React.CSSProperties + + // ── Behind-layer span (stroke + shadow, rendered under the fill text) ────── + const behindLayer = needsLayer ? ( + + ) : null + + // Positioned so z-index works; z-index 1 ensures fill is always above the behind-layer (z-index 0) + const frontLayerBase = needsLayer + ? { position: 'relative' as const, zIndex: 1, display: 'block' } + : {} + if (mode === 'pop') { + const popStyle = { + ...frontLayerBase, + color: (isActive || done) ? bright : dim, + transition: 'color 0.15s ease-out', + backgroundImage: 'none', + WebkitBackgroundClip: 'border-box', + WebkitTextFillColor: 'currentColor', + backgroundClip: 'border-box', + WebkitTextStroke: '0 transparent', + textShadow: 'none', + } + if (!needsLayer) { + return ( + { if (elRef) elRef.current = el }} style={{ ...wrapStyle, ...popStyle } as any}> + {word} + + ) + } return ( - { if (elRef) elRef.current = el }} - style={{ - ...base, - verticalAlign: 'middle', - color: (isActive || done) ? bright : dim, - fontSize: isActive ? fontSize * 1.15 : fontSize, - transition: 'font-size 0.08s ease, color 0.08s ease', - // Explicitly clear gradient-clip props so they don't bleed in from a prior fill-mode render - backgroundImage: 'none', - WebkitBackgroundClip: 'border-box', - WebkitTextFillColor: 'currentColor', - backgroundClip: 'border-box', - } as React.CSSProperties} - > + + {behindLayer} + { if (elRef) elRef.current = el }} style={popStyle as any}>{word} + + ) + } + + // fill mode: gradient sweep + const pct = done ? 100 : Math.round(fill * 100) + const fillStyle = { + ...frontLayerBase, + backgroundImage: `linear-gradient(to right, ${bright} ${pct}%, ${dim} ${pct}%)`, + WebkitBackgroundClip: 'text', + WebkitTextFillColor: 'transparent', + backgroundClip: 'text', + WebkitTextStroke: '0 transparent', + textShadow: 'none', + } + if (!needsLayer) { + return ( + { if (elRef) elRef.current = el }} style={{ ...wrapStyle, ...fillStyle } as any}> {word} ) } - const pct = done ? 100 : Math.round(fill * 100) return ( - { if (elRef) elRef.current = el }} - style={{ - ...base, - backgroundImage: `linear-gradient(to right, ${bright} ${pct}%, ${dim} ${pct}%)`, - WebkitBackgroundClip: 'text', - WebkitTextFillColor: 'transparent', - backgroundClip: 'text', - } as React.CSSProperties} - > - {word} + + {behindLayer} + { if (elRef) elRef.current = el }} style={fillStyle as any}>{word} ) } // ─── Style Picker Panel ─────────────────────────────────────────────────────── + +function hexToRgba(hex: string, opacity: number): string { + const r = parseInt(hex.slice(1, 3), 16) + const g = parseInt(hex.slice(3, 5), 16) + const b = parseInt(hex.slice(5, 7), 16) + return `rgba(${r}, ${g}, ${b}, ${opacity})` +} + interface StyleState { fontFamily: string fontSize: number @@ -312,15 +409,57 @@ interface StyleState { dynBg: boolean karaokeMode: 'fill' | 'pop' fontBold: boolean + strokeEnabled: boolean + strokeWidth: number + strokeColor: string + shadowEnabled: boolean + shadowBlur: number + shadowX: number + shadowY: number + shadowColor: string + shadowOpacity: number + scaleX: number + scaleY: number + popScale: number + popSnap: number +} + +const DEFAULT_STYLE: StyleState = { + fontFamily: 'system-ui, sans-serif', + fontSize: 20, + bgColor: '#0f172a', + textColor: '#c8d3e0', + highlightColor: '#3b82f6', + wordHighlight: '#60a5fa', + textAlign: 'center', + lineSpacing: 1.6, + dynBg: false, + karaokeMode: 'fill', + fontBold: false, + strokeEnabled: false, + strokeWidth: 2, + strokeColor: '#000000', + shadowEnabled: false, + shadowBlur: 4, + shadowX: 2, + shadowY: 2, + shadowColor: '#000000', + shadowOpacity: 1, + scaleX: 1, + scaleY: 1, + popScale: 15, + popSnap: 150, } function StylePicker({ style, onChange, + onReset, hasCoverArt, }: { style: StyleState onChange: (patch: Partial) => void + onReset: () => void hasCoverArt?: boolean }) { return ( @@ -370,6 +509,11 @@ function StylePicker({ ) })} +
{/* Color row */} @@ -379,7 +523,6 @@ function StylePicker({ onChange({ highlightColor: v })} /> onChange({ wordHighlight: v })} />
- Fill {(['fill', 'pop'] as const).map(m => (
+ {/* Effects row — stroke + shadow */} +
+
+ + {style.strokeEnabled && <> + onChange({ strokeColor: v })} /> + onChange({ strokeWidth: +e.target.value })} + className="w-16 h-1.5 accent-brand-400" title="Stroke width" /> + {style.strokeWidth} + } +
+
+ + {style.shadowEnabled && <> + onChange({ shadowColor: v })} /> + onChange({ shadowOpacity: +e.target.value })} + className="w-10 h-1.5 accent-brand-400" title="Opacity" /> + onChange({ shadowBlur: +e.target.value })} + className="w-14 h-1.5 accent-brand-400" title="Blur" /> + onChange({ shadowX: +e.target.value })} + className="w-10 h-1.5 accent-brand-400" title="X" /> + onChange({ shadowY: +e.target.value })} + className="w-10 h-1.5 accent-brand-400" title="Y" /> + } +
+
+ {/* Scale row — scaleX, scaleY + pop size (conditional) */} +
+
+ W + onChange({ scaleX: +e.target.value })} + className="w-20 h-1.5 accent-brand-400" title="Horizontal scale" /> + {style.scaleX.toFixed(2)} +
+
+ H + onChange({ scaleY: +e.target.value })} + className="w-20 h-1.5 accent-brand-400" title="Vertical scale" /> + {style.scaleY.toFixed(2)} +
+ {style.karaokeMode === 'pop' && ( +
+ Pop + onChange({ popScale: +e.target.value })} + className="w-16 h-1.5 accent-brand-400" title="Pop word scale %" /> + {style.popScale}% +
+ )} + {style.karaokeMode === 'pop' && ( +
+ Snap + onChange({ popSnap: +e.target.value })} + className="w-16 h-1.5 accent-brand-400" title="Transition duration (ms)" /> + {style.popSnap}ms +
+ )} +
{/* Dynamic BG from album art — only shown when cover art is available */} {hasCoverArt && (