(doc: Document, docWindow: Window, plugin: CodeSpacePlugin)
| 406 | } |
| 407 | |
| 408 | function 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 | |
| 437 | function ensureCodeSpaceStylesInDocument(targetDoc: Document, plugin: CodeSpacePlugin) { |
| 438 | applyEmbedCssVariables(targetDoc, plugin); |
no outgoing calls
no test coverage detected