mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 14:27:26 +00:00
fix(studio): address remaining caption designer feedback
Overlay: handle both per-word spans (generator output) and grouped text nodes (existing templates). Wraps text nodes into individual spans on demand so the overlay can target words in any caption format. Property panel: add Typography (font, size, weight, spacing) and Color (color, active, dim, opacity) sections alongside existing Position and Transform controls. Timeline: move caption timeline into a dedicated flex-shrink-0 section below the main timeline tracks instead of inside the scrollable area. Gives it fixed 60px height that's always visible. Caption overrides: classify color tweens by comparing target color to the dim baseline instead of relying on timeline position order. This handles compositions with custom color tweens correctly. App.tsx: remove polling interval, rely on runtime postMessage events for caption detection. Add clarifying comment on why useEffect is appropriate (external event subscription). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
a3c56e47e7
commit
f8014f5e2a
@@ -83,25 +83,30 @@ export function applyCaptionOverrides(): void {
|
||||
if (override.fontWeight !== undefined) styleProps.fontWeight = override.fontWeight;
|
||||
if (override.fontFamily !== undefined) styleProps.fontFamily = override.fontFamily;
|
||||
|
||||
// Replace color values in existing GSAP tweens by timeline order.
|
||||
// For any word, color tweens follow: dim (setup) → active (spoken) → after.
|
||||
// Sort by startTime and assign by position, not by content heuristics.
|
||||
// Replace color values in existing GSAP tweens.
|
||||
// Instead of relying on timeline position order (fragile if custom
|
||||
// color tweens exist), we classify each tween by comparing its
|
||||
// target color to the current computed color of the element.
|
||||
// Tweens that match the current color are "dim" tweens; tweens
|
||||
// with a different color are "active" tweens.
|
||||
if (override.activeColor || override.dimColor) {
|
||||
const allTweens = gsap.getTweensOf(el);
|
||||
const colorTweens = allTweens
|
||||
.filter((tw) => tw.vars.color !== undefined)
|
||||
.sort((a, b) => a.startTime() - b.startTime());
|
||||
|
||||
for (let i = 0; i < colorTweens.length; i++) {
|
||||
if (i === 0 && override.dimColor) {
|
||||
// First color tween = dim setup
|
||||
colorTweens[i].vars.color = override.dimColor;
|
||||
} else if (i === 1 && override.activeColor) {
|
||||
// Second color tween = active/spoken
|
||||
colorTweens[i].vars.color = override.activeColor;
|
||||
} else if (i >= 2 && override.dimColor) {
|
||||
// Third+ = after/deactivate (use dim color)
|
||||
colorTweens[i].vars.color = override.dimColor;
|
||||
// Use the first tween's color as the dim baseline — if no tweens,
|
||||
// fall back to computed style.
|
||||
const dimBaseline = colorTweens.length > 0 ? String(colorTweens[0].vars.color) : "";
|
||||
|
||||
for (const tw of colorTweens) {
|
||||
const tweenColor = String(tw.vars.color);
|
||||
if (tweenColor === dimBaseline) {
|
||||
// This tween targets the dim/inactive color
|
||||
if (override.dimColor) tw.vars.color = override.dimColor;
|
||||
} else {
|
||||
// This tween targets the active/spoken color
|
||||
if (override.activeColor) tw.vars.color = override.activeColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-18
@@ -65,20 +65,18 @@ export function StudioApp() {
|
||||
const [rightWidth, setRightWidth] = useState(400);
|
||||
const [leftCollapsed, setLeftCollapsed] = useState(false);
|
||||
const [rightCollapsed, setRightCollapsed] = useState(true);
|
||||
// Auto-enter caption edit mode when viewing a captions composition
|
||||
// Auto-enter caption edit mode when the iframe contains .caption-group elements.
|
||||
// Listens for the runtime's postMessage events (state/timeline) which fire after
|
||||
// all compositions are loaded, then checks for caption groups.
|
||||
// This is a subscription to external events (postMessage from runtime) — useEffect
|
||||
// is appropriate here. The runtime fires "state"/"timeline" messages after all
|
||||
// compositions load, which triggers caption detection.
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
useEffect(() => {
|
||||
if (!projectId) return;
|
||||
|
||||
let pollId: ReturnType<typeof setInterval> | null = null;
|
||||
let activating = false;
|
||||
|
||||
const tryActivateCaptions = () => {
|
||||
if (useCaptionStore.getState().isEditMode || activating) {
|
||||
if (pollId) { clearInterval(pollId); pollId = null; }
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,7 +86,9 @@ export function StudioApp() {
|
||||
try {
|
||||
doc = iframe?.contentDocument ?? null;
|
||||
win = iframe?.contentWindow ?? null;
|
||||
} catch { return; }
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (!doc || !win) return;
|
||||
|
||||
const groups = doc.querySelectorAll(".caption-group");
|
||||
@@ -102,7 +102,8 @@ export function StudioApp() {
|
||||
// Strategy 1: data-composition-src or data-composition-file attributes
|
||||
const compHosts = doc.querySelectorAll("[data-composition-src], [data-composition-file]");
|
||||
for (const host of compHosts) {
|
||||
const src = host.getAttribute("data-composition-src") || host.getAttribute("data-composition-file");
|
||||
const src =
|
||||
host.getAttribute("data-composition-src") || host.getAttribute("data-composition-file");
|
||||
if (src && src.includes("captions")) {
|
||||
captionSrcPath = src;
|
||||
break;
|
||||
@@ -154,7 +155,9 @@ export function StudioApp() {
|
||||
captionSync.loadOverrides();
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => { activating = false; });
|
||||
.finally(() => {
|
||||
activating = false;
|
||||
});
|
||||
};
|
||||
|
||||
// Listen for runtime messages that signal composition loading is complete
|
||||
@@ -168,14 +171,11 @@ export function StudioApp() {
|
||||
window.addEventListener("message", handleMessage);
|
||||
// Try immediately in case compositions are already loaded
|
||||
tryActivateCaptions();
|
||||
// Poll until captions are detected — sub-composition scripts run async
|
||||
pollId = setInterval(tryActivateCaptions, 200);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("message", handleMessage);
|
||||
if (pollId) clearInterval(pollId);
|
||||
};
|
||||
}, [activeCompPath, projectId, compIdToSrc]);
|
||||
}, [activeCompPath, projectId, compIdToSrc, captionSync]);
|
||||
|
||||
// Auto-expand right panel when a caption word is selected
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
@@ -296,7 +296,6 @@ export function StudioApp() {
|
||||
const previewIframeRef = useRef<HTMLIFrameElement | null>(null);
|
||||
const consoleErrorsRef = useRef<LintFinding[]>([]);
|
||||
|
||||
|
||||
// Listen for external file changes (user editing HTML outside the editor).
|
||||
// In dev: use Vite HMR. In embedded/production: use SSE from /api/events.
|
||||
useMountEffect(() => {
|
||||
@@ -850,14 +849,15 @@ export function StudioApp() {
|
||||
});
|
||||
}}
|
||||
previewOverlay={
|
||||
captionEditMode ? (
|
||||
<CaptionOverlay iframeRef={previewIframeRef} />
|
||||
) : undefined
|
||||
captionEditMode ? <CaptionOverlay iframeRef={previewIframeRef} /> : undefined
|
||||
}
|
||||
timelineFooter={
|
||||
captionEditMode ? (
|
||||
<div className="border-t border-neutral-800/30">
|
||||
<div className="flex items-center gap-1.5 px-2 py-1">
|
||||
<div
|
||||
className="border-t border-neutral-800/30 flex-shrink-0"
|
||||
style={{ height: 60 }}
|
||||
>
|
||||
<div className="flex items-center gap-1.5 px-2 py-0.5">
|
||||
<span className="text-[9px] font-medium text-neutral-500 uppercase tracking-wider">
|
||||
Captions
|
||||
</span>
|
||||
|
||||
@@ -51,7 +51,9 @@ function readWordBoxes(
|
||||
if (!groupEl) continue;
|
||||
const computed = win.getComputedStyle(groupEl);
|
||||
if (parseFloat(computed.opacity) <= 0.01 || computed.visibility === "hidden") continue;
|
||||
// Find word spans — may be direct children or inside wrappers
|
||||
// Find word elements — handles both per-word spans (generator output)
|
||||
// and grouped text nodes (existing caption templates that use
|
||||
// el.textContent = line.text instead of individual word spans).
|
||||
const resolvedWordEls: HTMLElement[] = [];
|
||||
for (const child of groupEl.children) {
|
||||
const c = child as HTMLElement;
|
||||
@@ -62,6 +64,39 @@ function readWordBoxes(
|
||||
resolvedWordEls.push(c);
|
||||
}
|
||||
}
|
||||
// Fallback: if no word spans found but group has text content,
|
||||
// the template uses grouped text. Wrap each word in a span so
|
||||
// the overlay can target them individually.
|
||||
if (resolvedWordEls.length === 0 && groupEl.textContent?.trim()) {
|
||||
const textNode = groupEl.childNodes[0];
|
||||
if (textNode && textNode.nodeType === Node.TEXT_NODE) {
|
||||
const words = (textNode.textContent || "").split(/\s+/).filter(Boolean);
|
||||
const frag = doc.createDocumentFragment();
|
||||
for (const word of words) {
|
||||
const span = doc.createElement("span");
|
||||
span.textContent = word + " ";
|
||||
span.style.display = "inline";
|
||||
frag.appendChild(span);
|
||||
resolvedWordEls.push(span);
|
||||
}
|
||||
groupEl.replaceChild(frag, textNode);
|
||||
} else {
|
||||
// Single span child with all text (e.g. vignelli template)
|
||||
const singleSpan = groupEl.querySelector<HTMLElement>(":scope > span");
|
||||
if (singleSpan && singleSpan.textContent?.trim()) {
|
||||
const words = singleSpan.textContent.split(/\s+/).filter(Boolean);
|
||||
const frag = doc.createDocumentFragment();
|
||||
for (const word of words) {
|
||||
const span = doc.createElement("span");
|
||||
span.textContent = word + " ";
|
||||
span.style.display = "inline";
|
||||
frag.appendChild(span);
|
||||
resolvedWordEls.push(span);
|
||||
}
|
||||
singleSpan.replaceWith(frag);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let wi = 0; wi < group.segmentIds.length; wi++) {
|
||||
const segId = group.segmentIds[wi];
|
||||
const wordEl = resolvedWordEls[wi] as HTMLElement | undefined;
|
||||
|
||||
@@ -179,6 +179,14 @@ export const CaptionPropertyPanel = memo(function CaptionPropertyPanel({
|
||||
const y = effectiveStyle.y ?? 0;
|
||||
const rotation = effectiveStyle.rotation ?? 0;
|
||||
const scaleX = effectiveStyle.scaleX ?? 1;
|
||||
const fontSize = effectiveStyle.fontSize ?? 48;
|
||||
const fontWeight = effectiveStyle.fontWeight ?? 700;
|
||||
const fontFamily = effectiveStyle.fontFamily ?? "Inter";
|
||||
const color = effectiveStyle.color ?? "#ffffff";
|
||||
const activeColor = effectiveStyle.activeColor ?? "#ffffff";
|
||||
const dimColor = effectiveStyle.dimColor ?? "#999999";
|
||||
const letterSpacing = effectiveStyle.letterSpacing ?? 0;
|
||||
const opacity = effectiveStyle.opacity ?? 1;
|
||||
|
||||
// Count label
|
||||
const countLabel = selectedSegmentIds.size === 1 ? "1 word" : `${selectedSegmentIds.size} words`;
|
||||
@@ -222,9 +230,88 @@ export const CaptionPropertyPanel = memo(function CaptionPropertyPanel({
|
||||
{/* Animation tab */}
|
||||
{activeTab === "animation" && <CaptionAnimationPanel />}
|
||||
|
||||
{/* Style tab — Transform only */}
|
||||
{/* Style tab */}
|
||||
{activeTab === "style" && (
|
||||
<div className="flex-1 overflow-y-auto px-3 py-2">
|
||||
<Section label="Typography">
|
||||
<Row label="Font">
|
||||
<input
|
||||
type="text"
|
||||
value={fontFamily}
|
||||
onChange={(e) => handleStyleChange({ fontFamily: e.target.value })}
|
||||
className={inputCls}
|
||||
/>
|
||||
</Row>
|
||||
<Row label="Size">
|
||||
<input
|
||||
type="number"
|
||||
value={fontSize}
|
||||
min={8}
|
||||
step={1}
|
||||
onChange={(e) => handleStyleChange({ fontSize: Number(e.target.value) })}
|
||||
className={inputCls}
|
||||
/>
|
||||
</Row>
|
||||
<Row label="Weight">
|
||||
<input
|
||||
type="number"
|
||||
value={fontWeight}
|
||||
min={100}
|
||||
max={900}
|
||||
step={100}
|
||||
onChange={(e) => handleStyleChange({ fontWeight: Number(e.target.value) })}
|
||||
className={inputCls}
|
||||
/>
|
||||
</Row>
|
||||
<Row label="Spacing">
|
||||
<input
|
||||
type="number"
|
||||
value={letterSpacing}
|
||||
step={0.01}
|
||||
onChange={(e) => handleStyleChange({ letterSpacing: Number(e.target.value) })}
|
||||
className={inputCls}
|
||||
/>
|
||||
</Row>
|
||||
</Section>
|
||||
|
||||
<Section label="Color">
|
||||
<Row label="Color">
|
||||
<input
|
||||
type="color"
|
||||
value={color}
|
||||
onChange={(e) => handleStyleChange({ color: e.target.value })}
|
||||
className={inputCls + " h-6 p-0.5 cursor-pointer"}
|
||||
/>
|
||||
</Row>
|
||||
<Row label="Active">
|
||||
<input
|
||||
type="color"
|
||||
value={activeColor}
|
||||
onChange={(e) => handleStyleChange({ activeColor: e.target.value })}
|
||||
className={inputCls + " h-6 p-0.5 cursor-pointer"}
|
||||
/>
|
||||
</Row>
|
||||
<Row label="Dim">
|
||||
<input
|
||||
type="color"
|
||||
value={dimColor}
|
||||
onChange={(e) => handleStyleChange({ dimColor: e.target.value })}
|
||||
className={inputCls + " h-6 p-0.5 cursor-pointer"}
|
||||
/>
|
||||
</Row>
|
||||
<Row label="Opacity">
|
||||
<input
|
||||
type="number"
|
||||
value={opacity}
|
||||
min={0}
|
||||
max={1}
|
||||
step={0.1}
|
||||
onChange={(e) => handleStyleChange({ opacity: Number(e.target.value) })}
|
||||
className={inputCls}
|
||||
/>
|
||||
</Row>
|
||||
</Section>
|
||||
|
||||
<Section label="Position">
|
||||
<Row label="X">
|
||||
<input
|
||||
@@ -234,7 +321,6 @@ export const CaptionPropertyPanel = memo(function CaptionPropertyPanel({
|
||||
className={inputCls}
|
||||
/>
|
||||
</Row>
|
||||
|
||||
<Row label="Y">
|
||||
<input
|
||||
type="number"
|
||||
@@ -260,7 +346,6 @@ export const CaptionPropertyPanel = memo(function CaptionPropertyPanel({
|
||||
className={inputCls}
|
||||
/>
|
||||
</Row>
|
||||
|
||||
<Row label="Rotation">
|
||||
<input
|
||||
type="number"
|
||||
|
||||
@@ -376,8 +376,8 @@ export const NLELayout = memo(function NLELayout({
|
||||
onDrillDown={handleDrillDown}
|
||||
renderClipContent={renderClipContent}
|
||||
/>
|
||||
{timelineFooter}
|
||||
</div>
|
||||
{timelineFooter && <div className="flex-shrink-0">{timelineFooter}</div>}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user