MCPcopy Index your code
hub / github.com/UNLINEARITY/Obsidian-CodeSpace / installPrintRefreshForDocument

Function installPrintRefreshForDocument

src/code_embed.ts:408–435  ·  view source on GitHub ↗
(doc: Document, docWindow: Window, plugin: CodeSpacePlugin)

Source from the content-addressed store, hash-verified

406}
407
408function installPrintRefreshForDocument(doc: Document, docWindow: Window, plugin: CodeSpacePlugin) {
409 if (embedPrintRefreshByDoc.has(doc)) return;
410
411 const refresh = () => {
412 ensureCodeSpaceStylesInDocument(doc, plugin);
413 queueAllCodeEmbedsInDocument(doc, docWindow, plugin);
414 };
415
416 docWindow.addEventListener("beforeprint", refresh);
417
418 const mediaQuery = typeof docWindow.matchMedia === "function" ? docWindow.matchMedia("print") : null;
419 const onMediaChange = (event: MediaQueryListEvent) => {
420 if (event.matches) {
421 refresh();
422 }
423 };
424
425 if (mediaQuery) {
426 mediaQuery.addEventListener("change", onMediaChange);
427 }
428
429 embedPrintRefreshByDoc.set(doc, () => {
430 docWindow.removeEventListener("beforeprint", refresh);
431 if (!mediaQuery) return;
432
433 mediaQuery.removeEventListener("change", onMediaChange);
434 });
435}
436
437function ensureCodeSpaceStylesInDocument(targetDoc: Document, plugin: CodeSpacePlugin) {
438 applyEmbedCssVariables(targetDoc, plugin);

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected