({ notePath }: { notePath: string })
| 207 | } |
| 208 | |
| 209 | function ExportNoteWindow({ notePath }: { notePath: string }): JSX.Element { |
| 210 | const [prefs] = useState(loadExportPrefs) |
| 211 | const [note, setNote] = useState<NoteContent | null>(null) |
| 212 | const [error, setError] = useState<string | null>(null) |
| 213 | // When exporting in the user's theme, the page follows the theme background; |
| 214 | // otherwise it's the clean white print page. |
| 215 | const pageBg = prefs.pdfExportUseTheme ? 'rgb(var(--z-bg))' : '#ffffff' |
| 216 | // A themed export goes full-bleed: with a non-zero @page margin, paged media |
| 217 | // leaves that margin frame unpainted and `color-scheme: dark` fills it with |
| 218 | // Chromium's default dark canvas (#121212) — a mismatched frame around the |
| 219 | // themed content. So drop the page margin and inset the content with padding |
| 220 | // instead, letting --z-bg cover the whole sheet. The light export keeps the |
| 221 | // classic per-page margin (white paper margins look correct there). |
| 222 | const pageMargin = prefs.pdfExportUseTheme ? '0' : '0.7in' |
| 223 | const contentInset = prefs.pdfExportUseTheme ? '0.7in' : '0' |
| 224 | |
| 225 | useEffect(() => { |
| 226 | applyExportPrefs(prefs) |
| 227 | setExportState('loading') |
| 228 | |
| 229 | let cancelled = false |
| 230 | |
| 231 | const load = async (): Promise<void> => { |
| 232 | try { |
| 233 | const [vault, notes, assetFiles, noteContent] = await Promise.all([ |
| 234 | window.zen.getCurrentVault(), |
| 235 | window.zen.listNotes(), |
| 236 | window.zen.listAssets(), |
| 237 | window.zen.readNote(notePath) |
| 238 | ]) |
| 239 | if (cancelled) return |
| 240 | if (!vault) { |
| 241 | throw new Error('No active vault was available for PDF export.') |
| 242 | } |
| 243 | |
| 244 | // A custom theme's CSS lives on disk, not in index.css — inject it (and |
| 245 | // finalize its light/dark mode) before rendering so printToPDF captures |
| 246 | // the themed styles. Built-ins and the light default are already applied. |
| 247 | if (prefs.pdfExportUseTheme && isCustomThemeId(prefs.themeId)) { |
| 248 | await applyCustomExportTheme(prefs) |
| 249 | if (cancelled) return |
| 250 | } |
| 251 | |
| 252 | useStore.setState({ |
| 253 | vault: vault as VaultInfo, |
| 254 | notes: notes as NoteMeta[], |
| 255 | assetFiles: assetFiles as AssetMeta[], |
| 256 | selectedPath: noteContent.path, |
| 257 | activeNote: noteContent |
| 258 | }) |
| 259 | document.title = noteContent.title |
| 260 | setNote(noteContent) |
| 261 | } catch (err) { |
| 262 | if (cancelled) return |
| 263 | const message = err instanceof Error ? err.message : String(err) |
| 264 | setError(message) |
| 265 | setExportState('error', message) |
| 266 | } |
nothing calls this directly
no test coverage detected