Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { readTheme, schemeCss, schemeOf, themeCss } from "./play-theme.ts";

// The playground's preview is a document of its own, so the plugins' inlined scripts run as they do on a real page.
// The build writes the first preset with it and the playground every edit after, with the Theme pane's scheme as a
// class on the root and its CSS in #play-theme, so a render doesn't flash the default theme.
// class on the root and its CSS in #play-theme, so a render doesn't flash the default theme. The body keeps 1rem, so
// annotate's marks and badges, which sit past a screenshot's edge, aren't cut off by the frame.
export const previewDocument = (html: string, theme?: { scheme: string; css: string }) =>
`<!doctype html><html lang="en"${theme ? ` class="${theme.scheme}" style="color-scheme:${theme.scheme}"` : ' style="color-scheme:light dark"'}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">` +
`<link rel="stylesheet" href="/play/preview.css"><style>body{padding:2rem;background:var(--comark-background,var(--bg))}body>main{margin:0}</style>` +
`<link rel="stylesheet" href="/play/preview.css"><style>body{padding:1rem;background:var(--comark-background,var(--bg))}body>main{margin:0}</style>` +
`<style id="play-theme">${theme ? theme.css.replaceAll("</", "<\\/") : ""}</style></head>` +
`<body><main class="play-preview-content">${html}</main></body></html>`;

Expand Down
7 changes: 7 additions & 0 deletions e2e/play-preview.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,10 @@ test("system changes preserve custom theme colors", async ({ page }) => {
await setSystem(page, "dark");
await expect(text).toHaveCSS("background-color", "rgb(46, 16, 101)");
});

test("the preview pads its content only enough for marks drawn past a block's edge", async ({
page,
}) => {
await open(page, "light");
await expect(preview(page).locator("body")).toHaveCSS("padding", "16px");
});
Loading