feat(monospace): print-preview iframe uses bundled monospace font

Inlines @font-face as base64 data URI so the iframe srcdoc can render
JetBrains Mono / Fira Code without depending on the parent window's
loaded @font-face sets. Reads family + ligature state from the
renderer-wide cache populated by applyMonospaceClasses().

Amit Haridas
This commit is contained in:
2026-08-23 19:31:33 +05:30
parent 228ee04b09
commit 151be60b03
3 changed files with 1698 additions and 4 deletions
+18 -2
View File
@@ -15,10 +15,21 @@ const { undo, redo } = require('@codemirror/commands');
/**
* Toggle body classes that drive the monospace font + ligatures CSS tokens.
* Single source of truth for the live preview/editor font behaviour.
* Also pushes the settings into the renderer-wide cache so PrintPreview can read them.
* @param {{monospaceFont?: string, monospaceLigatures?: boolean} | null | undefined} settings
*/
function applyMonospaceClasses(settings) {
const s = settings || {};
// Cache for downstream consumers (PrintPreview, future settings UI, etc.)
if (typeof window !== 'undefined') {
window.__monospaceSettings = {
monospaceFont: s.monospaceFont || 'jetbrains-mono',
monospaceLigatures: s.monospaceLigatures === true,
};
if (window.__printPreview && typeof window.__printPreview.setMonospaceSettings === 'function') {
window.__printPreview.setMonospaceSettings(window.__monospaceSettings);
}
}
const body = document.body;
if (!body) return;
const isFira = s.monospaceFont === 'fira-code';
@@ -1951,7 +1962,10 @@ document.addEventListener('DOMContentLoaded', async () => {
// Initialize print preview
const PrintPreview = getPrintPreview();
const printPreview = new PrintPreview();
const printPreview = new PrintPreview(
window.__monospaceSettings || { monospaceFont: 'jetbrains-mono', monospaceLigatures: false }
);
window.__printPreview = printPreview;
// Register commands
commandPalette.register('New File', 'Ctrl+N', () => tabManager.createNewTab());
@@ -2270,7 +2284,9 @@ function openPrintPreviewDialog() {
return;
}
const PrintPreviewClass = getPrintPreview();
const printPreviewInstance = new PrintPreviewClass();
const printPreviewInstance = new PrintPreviewClass(
window.__monospaceSettings || { monospaceFont: 'jetbrains-mono', monospaceLigatures: false }
);
printPreviewInstance.open(previewContent.innerHTML);
}