mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-08 02:36:10 +00:00
refactor(studio): simplify dropdown helpers + use stage-size message for dims
Cleanup from the /simplify pass on PR #715. - App.tsx: subscribe to the runtime's `stage-size` message (which carries authoritative width/height post-applyCompositionSizing) instead of re-parsing data-width/data-height from the iframe DOM. Drops the cross-origin try/catch, querySelector, and parseInt logic, and fires once per comp load instead of on every state/timeline tick. - App.tsx: import CompositionDimensions from RenderQueue instead of inlining the shape. - RenderQueue.tsx: replace scaleLabel() with a SCALE_LABEL record, inline the one-call formatDims helper, and trim the type comment to the WHY.
This commit is contained in:
@@ -26,13 +26,19 @@ interface RenderQueueProps {
|
||||
compositionDimensions?: CompositionDimensions | null;
|
||||
}
|
||||
|
||||
// User-facing render scale. Orientation is derived from the composition's
|
||||
// authored aspect ratio at render time, so the user never picks an
|
||||
// orientation that mismatches their comp.
|
||||
// Orientation is derived from the composition's authored aspect ratio,
|
||||
// not chosen by the user — picking "1080p portrait" for a landscape comp
|
||||
// would just produce a wrong-aspect render.
|
||||
type RenderScale = "auto" | "1080p" | "4k";
|
||||
|
||||
const SCALE_OPTION_ORDER: RenderScale[] = ["auto", "1080p", "4k"];
|
||||
|
||||
const SCALE_LABEL: Record<RenderScale, string> = {
|
||||
auto: "Auto",
|
||||
"1080p": "1080p",
|
||||
"4k": "4K",
|
||||
};
|
||||
|
||||
function isPortraitComp(dims: CompositionDimensions | null | undefined): boolean {
|
||||
// Squares and missing dims fall through to landscape — matches the legacy
|
||||
// default ("landscape" was the first preset). The auto option exists for
|
||||
@@ -50,15 +56,6 @@ function resolveResolution(
|
||||
return portrait ? "portrait-4k" : "landscape-4k";
|
||||
}
|
||||
|
||||
function scaleLabel(scale: RenderScale): string {
|
||||
if (scale === "auto") return "Auto";
|
||||
if (scale === "1080p") return "1080p";
|
||||
return "4K";
|
||||
}
|
||||
|
||||
// Resolved output dimensions for a given scale + composition. Mirrors
|
||||
// `CANVAS_DIMENSIONS` in core for the 1080p / 4K presets; `auto` echoes the
|
||||
// composition's authored dims so the user can see exactly what they'll get.
|
||||
function resolvedDimensions(
|
||||
scale: RenderScale,
|
||||
dims: CompositionDimensions | null | undefined,
|
||||
@@ -71,17 +68,14 @@ function resolvedDimensions(
|
||||
return portrait ? { width: 2160, height: 3840 } : { width: 3840, height: 2160 };
|
||||
}
|
||||
|
||||
function formatDims(dims: CompositionDimensions | null): string {
|
||||
if (!dims) return "?";
|
||||
return `${dims.width}×${dims.height}`;
|
||||
}
|
||||
|
||||
function scaleOptionLabel(
|
||||
scale: RenderScale,
|
||||
dims: CompositionDimensions | null | undefined,
|
||||
): string {
|
||||
const resolved = resolvedDimensions(scale, dims);
|
||||
return resolved ? `${scaleLabel(scale)} · ${formatDims(resolved)}` : scaleLabel(scale);
|
||||
return resolved
|
||||
? `${SCALE_LABEL[scale]} · ${resolved.width}×${resolved.height}`
|
||||
: SCALE_LABEL[scale];
|
||||
}
|
||||
|
||||
const FORMAT_INFO: Record<"mp4" | "webm" | "mov", { label: string; desc: string }> = {
|
||||
|
||||
Reference in New Issue
Block a user