/** * Runtime light/dark theme control for rendered previews. * * A rendered PreTeXt page already knows how to switch between light and dark * — pretext-core.js exposes a global `window.setDarkMode(isDark)` — but it * only ever decides *which* to use from `localStorage` and the browser's * `prefers-color-scheme`. Neither reflects the surroundings an embedder cares * about: "VS Code is using a dark editor theme", "pretext.plus is in dark * mode". This module lets the embedding app drive the preview's theme instead. * * It is entirely opt-in, controlled by `RenderOptions.theme`. When set, the * renderer injects the small script produced by {@link themeBridgeScript}, * which: * * 1. applies an *initial* theme baked into the page (so an explicit dark * preview does not flash light first), and * 2. listens for a `postMessage` from the embedder and re-applies the theme * live — no re-render needed. * * The embedder posts {@link previewThemeMessage}`(theme)` to the preview's * window (a VS Code webview, an `