import DOMPurify from "dompurify"; export interface SanitizeOptions { /** Map of Content-ID (without angle brackets) → URL for inline images. */ cidMap?: Record; /** Whether remote content (http/https images, css urls) may load. */ allowRemote?: boolean; /** Route remote images through the privacy proxy. */ proxyRemote?: boolean; } export interface SanitizeResult { html: string; remoteCount: number; bodyStyle: string; } const REMOTE_URL_RE = /^(https?:)?\/\//i; const CSS_URL_RE = /url\(\s*(['"]?)([^'")]+)\1\s*\)/gi; let hooked = false; function ensureHooks() { if (hooked) return; hooked = true; DOMPurify.addHook("uponSanitizeElement", (node, data) => { // Strip