Skip to content

Commit 326df8d

Browse files
feat(studio): let an embedder draw the preview edge to edge with fillBox (#4408)
NLEPreview always drew its picture 8px in from each side on a dark band, so an embedder that sizes the box to the film saw a smaller picture in a black frame. fillBox drops that inset from both the layout and the stage-size math. Default look is unchanged.
1 parent 261af22 commit 326df8d

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

‎packages/studio/src/components/nle/NLEPreview.test.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ function renderPreview(
8080
previewSlots: Array<{ gen: number; role: "live" | "shadow"; url?: string }> = [
8181
{ gen: 0, role: "live" },
8282
],
83+
{
84+
box = { width: 800, height: 600 },
85+
fillBox,
86+
}: { box?: { width: number; height: number }; fillBox?: boolean } = {},
8387
) {
8488
resizeCallbacks = [];
8589
const host = document.createElement("div");
@@ -99,6 +103,7 @@ function renderPreview(
99103
onShadowError: () => {},
100104
setShadowIframeNode: () => {},
101105
resetPreviewSlots: () => {},
106+
fillBox,
102107
}),
103108
);
104109
});
@@ -108,7 +113,7 @@ function renderPreview(
108113
expect(viewport).toBeTruthy();
109114
expect(stage).toBeTruthy();
110115

111-
setRect(viewport, { width: 800, height: 600 });
116+
setRect(viewport, box);
112117
act(() => {
113118
for (const fire of resizeCallbacks) fire();
114119
});
@@ -251,6 +256,19 @@ describe("NLEPreview", () => {
251256
view.cleanup();
252257
});
253258

259+
it("insets the picture by default and fills a same-shape box when fillBox is on", () => {
260+
const box = { width: 640, height: 360 };
261+
const inset = renderPreview(undefined, { box });
262+
expect([inset.stage.style.width, inset.stage.style.height]).toEqual(["611.5556px", "344px"]);
263+
expect(parseFloat(inset.stage.parentElement!.style.inset)).toBe(8);
264+
inset.cleanup();
265+
266+
const filled = renderPreview(undefined, { box, fillBox: true });
267+
expect([filled.stage.style.width, filled.stage.style.height]).toEqual(["640px", "360px"]);
268+
expect(parseFloat(filled.stage.parentElement!.style.inset)).toBe(0);
269+
filled.cleanup();
270+
});
271+
254272
it("clips a shadow reload so its own loading overlay cannot paint over the live frame", () => {
255273
const view = renderPreview([
256274
{ gen: 0, role: "live" },

‎packages/studio/src/components/nle/NLEPreview.tsx‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ interface NLEPreviewProps {
3636
onStageRef?: (ref: React.RefObject<HTMLDivElement | null>) => void;
3737
/** Reports the authored composition size measured from the loaded preview. */
3838
onCompositionSizeChange?: (size: PreviewCompositionSize | null) => void;
39+
/** Draws the picture edge to edge in this box, without Studio's inset band. */
40+
fillBox?: boolean;
3941
}
4042

4143
export function getPreviewPlayerKey({
@@ -50,7 +52,7 @@ export function getPreviewPlayerKey({
5052

5153
const ZOOM_HUD_TIMEOUT_MS = 1200;
5254
const ZOOM_SETTLE_MS = 200;
53-
const PREVIEW_STAGE_INSET_PX = 16;
55+
const PREVIEW_STAGE_INSET_PX = 8;
5456

5557
// clip-path as well as visibility: the player's loading overlay sets its own
5658
// visibility:visible and would otherwise paint over the live frame.
@@ -87,9 +89,10 @@ export function resolvePreviewStageSize(
8789
compositionSize: PreviewCompositionSize | null,
8890
portrait: boolean | undefined,
8991
gutterPx = 0,
92+
insetPx = PREVIEW_STAGE_INSET_PX,
9093
): { width: number; height: number } {
91-
const availableWidth = Math.max(0, viewportWidth - PREVIEW_STAGE_INSET_PX - 2 * gutterPx);
92-
const availableHeight = Math.max(0, viewportHeight - PREVIEW_STAGE_INSET_PX - 2 * gutterPx);
94+
const availableWidth = Math.max(0, viewportWidth - 2 * (insetPx + gutterPx));
95+
const availableHeight = Math.max(0, viewportHeight - 2 * (insetPx + gutterPx));
9396
const aspectRatio =
9497
compositionSize && compositionSize.width > 0 && compositionSize.height > 0
9598
? compositionSize.width / compositionSize.height
@@ -130,6 +133,7 @@ export const NLEPreview = memo(function NLEPreview({
130133
suppressLoadingOverlay,
131134
onStageRef,
132135
onCompositionSizeChange,
136+
fillBox,
133137
}: NLEPreviewProps) {
134138
const activeKey = getPreviewPlayerKey({ projectId, directUrl });
135139
const viewportRef = useRef<HTMLDivElement>(null);
@@ -151,6 +155,7 @@ export const NLEPreview = memo(function NLEPreview({
151155
const reportPreviewFirstFrame = usePreviewFirstFrameTelemetry(previewSlots);
152156
const [compositionSize, setCompositionSize] = useState<PreviewCompositionSize | null>(null);
153157
const gutterPx = usePreviewGuidesStore((s) => (s.rulerVisible ? RULER_GUTTER_PX : 0));
158+
const insetPx = fillBox ? 0 : PREVIEW_STAGE_INSET_PX;
154159
const [stageSize, setStageSize] = useState(() => resolvePreviewStageSize(0, 0, null, portrait));
155160

156161
const zoomRef = useRef<PreviewZoomState>(loadInitialZoom());
@@ -181,15 +186,22 @@ export const NLEPreview = memo(function NLEPreview({
181186
const updateStageSize = () => {
182187
const rect = viewport.getBoundingClientRect();
183188
setStageSize(
184-
resolvePreviewStageSize(rect.width, rect.height, compositionSize, portrait, gutterPx),
189+
resolvePreviewStageSize(
190+
rect.width,
191+
rect.height,
192+
compositionSize,
193+
portrait,
194+
gutterPx,
195+
insetPx,
196+
),
185197
);
186198
};
187199

188200
updateStageSize();
189201
const observer = new ResizeObserver(updateStageSize);
190202
observer.observe(viewport);
191203
return () => observer.disconnect();
192-
}, [compositionSize, portrait, gutterPx]);
204+
}, [compositionSize, portrait, gutterPx, insetPx]);
193205

194206
const onCompositionSizeChangeRef = useRef(onCompositionSizeChange);
195207
onCompositionSizeChangeRef.current = onCompositionSizeChange;
@@ -467,11 +479,14 @@ export const NLEPreview = memo(function NLEPreview({
467479
<div className="flex flex-col h-full min-h-0">
468480
<div
469481
ref={viewportRef}
470-
className="relative flex-1 flex items-center justify-center p-2 overflow-hidden min-h-0 outline-hidden focus:ring-1 focus:ring-studio-accent/40 bg-[var(--studio-preview-bg,var(--color-neutral-950))]"
482+
className="relative flex-1 flex items-center justify-center overflow-hidden min-h-0 outline-hidden focus:ring-1 focus:ring-studio-accent/40 bg-[var(--studio-preview-bg,var(--color-neutral-950))]"
471483
tabIndex={0}
472484
aria-label="Composition preview"
473485
>
474-
<div className="absolute inset-2 flex items-center justify-center pointer-events-none">
486+
<div
487+
className="absolute flex items-center justify-center pointer-events-none"
488+
style={{ inset: insetPx }}
489+
>
475490
<div
476491
ref={stageRef}
477492
className="relative shrink-0 pointer-events-auto"

0 commit comments

Comments
 (0)