import { randomBytes } from 'node:crypto' // A separate document keeps the main application's strict image/script policy intact. // The sandbox has no same-origin access; only this nonce-protected sizing bridge runs. export function htmlPreviewDocument({ dark = false, remoteImages = false } = {}) { const nonce = randomBytes(24).toString('base64') const background = dark ? '#222225' : '#ffffff', foreground = dark ? '#eeeef0' : '#252329', accent = dark ? '#b49aef' : '#6d3bd1' const csp = `default-src 'none'; img-src data:${remoteImages ? ' https:' : ''}; style-src 'unsafe-inline'; script-src 'nonce-${nonce}'; base-uri 'none'; form-action 'none'; frame-ancestors 'self'; sandbox allow-scripts` const html = `
` return { html, csp } }