Skip to content

Commit 33ec768

Browse files
committed
fix(web): fill and top-align presentation preview pages
1 parent 4db2721 commit 33ec768

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎apps/web/src/components/files/OfficeViewer.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { OFFICE_PREVIEW_MAX_BYTES, type OfficeWorkerResult } from "./officePrevi
1111
type Workbook = Extract<OfficeWorkerResult, { type: "xlsx" }>;
1212
type Slide = Extract<OfficeWorkerResult, { type: "slide" }>;
1313

14+
const OFFICE_PAGE_PADDING = 20;
15+
const OFFICE_PAGE_BACKGROUND = { light: "#f4f4f5", dark: "#141414" };
16+
1417
async function readOfficeFile(src: string, signal: AbortSignal) {
1518
const response = await fetch(src, { signal });
1619
if (!response.ok) throw new Error("The file could not be loaded. Close it and try again.");
@@ -86,7 +89,7 @@ function WordFrame(props: {
8689
readonly name: string;
8790
}) {
8891
const { resolvedTheme } = useTheme();
89-
const srcDoc = `<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'"><style>${props.content.css}</style><style>html{background:${resolvedTheme === "dark" ? "#141414" : "#f4f4f5"}}body{margin:0}.docx-wrapper{background:transparent;padding:20px;box-sizing:border-box}.docx-wrapper section.docx{max-width:100%;box-sizing:border-box;padding:32px!important;min-height:0!important}img{max-width:100%;height:auto}.docx-wrapper section.docx div{max-width:100%}img{height:auto!important}*{scrollbar-width:thin}</style></head><body>${props.content.html}</body></html>`;
92+
const srcDoc = `<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'"><style>${props.content.css}</style><style>html{background:${OFFICE_PAGE_BACKGROUND[resolvedTheme]}}body{margin:0}.docx-wrapper{background:transparent;padding:${OFFICE_PAGE_PADDING}px;box-sizing:border-box}.docx-wrapper section.docx{max-width:100%;box-sizing:border-box;padding:32px!important;min-height:0!important}img{max-width:100%;height:auto}.docx-wrapper section.docx div{max-width:100%}img{height:auto!important}*{scrollbar-width:thin}</style></head><body>${props.content.html}</body></html>`;
9093
return (
9194
<iframe title={props.name} srcDoc={srcDoc} sandbox="" className="min-h-0 flex-1 border-0" />
9295
);
@@ -97,6 +100,7 @@ function SlideCanvas(props: {
97100
readonly onError: (message: string) => void;
98101
}) {
99102
const { slide, onError } = props;
103+
const { resolvedTheme } = useTheme();
100104
const canvasRef = useRef<HTMLCanvasElement>(null);
101105
useEffect(() => {
102106
let cancelled = false;
@@ -138,12 +142,15 @@ function SlideCanvas(props: {
138142
};
139143
}, [slide, onError]);
140144
return (
141-
<div className="flex min-h-0 flex-1 items-center justify-center bg-muted/30 p-4">
145+
<div
146+
className="min-h-0 flex-1 overflow-auto"
147+
style={{ background: OFFICE_PAGE_BACKGROUND[resolvedTheme], padding: OFFICE_PAGE_PADDING }}
148+
>
142149
<canvas
143150
ref={canvasRef}
144151
role="img"
145152
aria-label={props.slide.text || `Slide ${props.slide.index + 1}`}
146-
className="max-h-full max-w-full object-contain shadow-sm"
153+
className="block h-auto w-full shadow-sm"
147154
/>
148155
</div>
149156
);

0 commit comments

Comments
 (0)