import { randomBytes } from 'node:crypto' import { darkReaderPath } from './preview-assets.js' // A separate document keeps the main application's strict image/script policy intact. // The sandbox has no same-origin access. Only the nonce-protected integration and // the locally bundled Dark Reader code can execute; scripts from mail are removed. 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 = `${dark ? `` : ''}
` return { html, csp } }