fix(ui): keep subtitle preview playable for karaoke presets
Selecting a karaoke preset swapped the playable RemotionPreview for a static CSS mock, so the preview video couldn't be played/scrubbed. Instead, teach the Remotion Subtitles component to render dim (baseOpacity, opaque scaled color like the backend) and uppercase, and pass those from the modal — so the preview stays a live, playable Player that also reflects the karaoke look. Drops the static mock.
This commit is contained in:
parent
f683dc66df
commit
7162667bbf
3 changed files with 20 additions and 40 deletions
|
|
@ -60,16 +60,6 @@ const CAPTION_PRESETS = [
|
|||
{ id: 'classic', label: 'Classic', style: 'classic', effect: 'none', highlightColor: '#FFD700', baseOpacity: 1.0, uppercase: false, fontName: 'Verdana', borderWidth: 2 },
|
||||
];
|
||||
|
||||
// Mirrors the backend's ASS dimming: a fully-opaque scaled color (not CSS
|
||||
// opacity), so the preview matches what gets burned into the video.
|
||||
const dimColor = (hex, k) => {
|
||||
const m = /^#?([0-9a-f]{6})$/i.exec(hex || '');
|
||||
if (!m) return hex;
|
||||
const scale = 0.35 + 0.65 * k;
|
||||
const [r, g, b] = [0, 2, 4].map(i => Math.round(parseInt(m[1].slice(i, i + 2), 16) * scale));
|
||||
return `rgb(${r}, ${g}, ${b})`;
|
||||
};
|
||||
|
||||
const swatchClass = (selected) =>
|
||||
`w-6 h-6 rounded-full transition-all ${selected
|
||||
? 'ring-2 ring-[color:var(--color-accent)] ring-offset-2 ring-offset-[color:var(--color-paper-2)]'
|
||||
|
|
@ -178,6 +168,9 @@ export default function SubtitleModal({ isOpen, onClose, onGenerate, onApplyAll,
|
|||
bgColor,
|
||||
bgOpacity,
|
||||
animation,
|
||||
// Karaoke look reflected live in the playable preview.
|
||||
baseOpacity: style === 'karaoke' ? baseOpacity : 1,
|
||||
uppercase: style === 'karaoke' ? uppercase : false,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -220,36 +213,6 @@ export default function SubtitleModal({ isOpen, onClose, onGenerate, onApplyAll,
|
|||
<Loader2 size={16} className="animate-spin" />
|
||||
<span className="text-sm lowercase">Loading preview...</span>
|
||||
</div>
|
||||
) : style === 'karaoke' ? (
|
||||
/* Karaoke burns server-side; show a CSS mock that mirrors
|
||||
the exact burned look (dim, uppercase, effects). */
|
||||
<>
|
||||
<video src={videoUrl} className="w-full h-full object-contain opacity-50" muted playsInline />
|
||||
<div className={`absolute w-full px-8 text-center pointer-events-none flex flex-col items-center justify-center
|
||||
${position === 'top' ? 'top-20' : position === 'middle' ? 'top-0 bottom-0' : 'bottom-20'}
|
||||
`}>
|
||||
<span style={{ ...fallbackPreviewStyle, color: undefined }}>
|
||||
{(captions.length >= 4
|
||||
? captions.slice(0, 4).map(c => c.text)
|
||||
: ['this', 'word', 'is', 'spoken']
|
||||
).map((w, i) => {
|
||||
const word = uppercase ? w.toUpperCase() : w;
|
||||
const active = i === 1;
|
||||
if (!active) {
|
||||
return <span key={i} style={{ color: dimColor(fontColor, baseOpacity) }}>{word} </span>;
|
||||
}
|
||||
return (
|
||||
<span key={i} style={{
|
||||
color: effect === 'box' ? '#FFFFFF' : highlightColor,
|
||||
...(effect === 'glow' ? { textShadow: `0 0 6px ${highlightColor}, 0 0 14px ${highlightColor}` } : {}),
|
||||
...(effect === 'pop' ? { display: 'inline-block', transform: 'scale(1.18)', margin: '0 3px' } : {}),
|
||||
...(effect === 'box' ? { backgroundColor: highlightColor, borderRadius: '4px', padding: '0 5px' } : {}),
|
||||
}}>{word} </span>
|
||||
);
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
) : useRemotionPreview ? (
|
||||
<RemotionPreview
|
||||
videoUrl={videoUrl}
|
||||
|
|
|
|||
|
|
@ -158,6 +158,19 @@ const WordSpan: React.FC<WordSpanProps> = ({
|
|||
let color = style.fontColor;
|
||||
let extraStyle: React.CSSProperties = {};
|
||||
|
||||
// Dim inactive words toward the backend's opaque scaled color (matches the
|
||||
// burned ASS look; not CSS opacity).
|
||||
if (!isActive && style.baseOpacity != null && style.baseOpacity < 1) {
|
||||
const m = /^#?([0-9a-fA-F]{6})$/.exec(style.fontColor || "#FFFFFF");
|
||||
if (m) {
|
||||
const scale = 0.35 + 0.65 * style.baseOpacity;
|
||||
const [r, g, b] = [0, 2, 4].map((i) =>
|
||||
Math.round(parseInt(m[1].slice(i, i + 2), 16) * scale)
|
||||
);
|
||||
color = `rgb(${r}, ${g}, ${b})`;
|
||||
}
|
||||
}
|
||||
|
||||
if (isActive) {
|
||||
color = style.highlightColor;
|
||||
|
||||
|
|
@ -218,6 +231,7 @@ const WordSpan: React.FC<WordSpanProps> = ({
|
|||
transform,
|
||||
display: "inline-block",
|
||||
transition: "none",
|
||||
textTransform: style.uppercase ? "uppercase" : "none",
|
||||
...extraStyle,
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ export interface SubtitleStyle {
|
|||
bgColor: string;
|
||||
bgOpacity: number;
|
||||
animation: SubtitleAnimation;
|
||||
// Karaoke look: dim inactive words (0-1) and force uppercase.
|
||||
baseOpacity?: number;
|
||||
uppercase?: boolean;
|
||||
}
|
||||
|
||||
export interface SubtitleConfig {
|
||||
|
|
|
|||
Loading…
Reference in a new issue