On this page
Overview
Prints complete current rendered content through one document-owned print lifecycle and shared print stylesheet.
- Artifact
PrintView.js· esm - Classification
public first party - Availability
Browser/native WebView with DOM, Fetch, and browser printing - Normalization
Explicit requests await view-owned preparation; native Print captures synchronously. Rendered content, fonts, images, and resource retention remain complete. A true print result confirms only a requested browser dialog; snapshots and retained media survive until afterprint.
Import and lifecycle
import * as module from '/node_modules/arcane-os/runtime/arcane/modules/PrintView.js';
Import fetches complete css/print.css text through a module-relative URL and resolves only when that required stylesheet is ready. Components load this module independently of rendering; only print availability waits. createPrintView registers one shared beforeprint/afterprint owner per document, whose synchronous native capture needs no stylesheet fetch. A selected print request captures the current rendered DOM/styles into a temporary print-only surface; afterprint removes it and releases retained resources. Destruction cancels preparation, while an already requested print keeps its snapshot until afterprint.
Application-facing behavior: createPrintView({host,content,title,active,priority,signal,onError,retain,prepare}) returns print() and destroy(). Import awaits the required shared print stylesheet.
Protocol and host implementation
DOM snapshots, beforeprint/afterprint, and shared css/print.css This detail does not widen the application-facing API or grant authority.
Exports, signatures, parameters, and results
| Binding | Form | Declaration or signature | Parameter syntax |
|---|---|---|---|
createPrintView | function | function createPrintView({
host,
content,
title,
active,
priority=0,
signal,
onError,
retain,
prepare
}) | {
host,
content,
title,
active,
priority=0,
signal,
onError,
retain,
prepare
} |
Parameter meanings and results
createPrintView({host,content,title,active,priority=0,signal,onError,retain,prepare}) returns {print,destroy}. content/title/active callbacks are synchronous. retain may return a release function for owned media. Optional prepare(signal) awaits view-owned explicit-print readiness; current content/title are reread synchronously before capture. Native printing never invokes prepare. print() resolves false when unavailable or cancelled during preparation, true when the browser dialog is requested, and rejects preparation failures. Native Print selects the highest-priority visible active view, latest registration on ties; explicit print selects its own view. Accessible HTML frames are flattened from their current DOM. Complete text, resolved images, rendered fonts, font sizing, line height, emphasis and title are retained while print layout expands scrolling content. Shared css/print.css owns the existing light palette, 1in (25.4mm) page margins, snapshot expansion, underlined links, table borders, and scoped documentation-site print rules. Ordinary HTML and pseudo-elements lose screen-theme text/shadow paint; image pixels, canvas snapshots, and SVG artwork keep their colors. The live screen theme is unchanged and browser settings still control actual page output.
Events, side effects, and errors
Source-literal CustomEvent dispatches
No source-literal CustomEvent dispatch is part of this artifact.
Lifecycle and event flow
- Owns native beforeprint and afterprint listeners; no new application event bus. Native beforeprint is synchronous and cannot await new resource readiness or cancel the browser dialog.
Direct coded failures
This artifact directly assigns no stable coded failure.
Exported Error subclasses
This artifact exports no Error subclass.
Documented failure behavior
- Initial shared stylesheet fetch/HTTP/text failures reject module loading. TypeError for unusable host/callback inputs.
- Explicit preparation rejects image/font/frame failures and overlapping print requests; native preparation failures reach onError or complete console diagnostics.
- Inaccessible HTML frames and native object/embed/PDF viewers require their owning print surface.
Availability and capabilities
Browser/native WebView with DOM, Fetch, and browser printing. Explicit requests await view-owned preparation; native Print captures synchronously. Rendered content, fonts, images, and resource retention remain complete. A true print result confirms only a requested browser dialog; snapshots and retained media survive until afterprint.
No Core capability. Browser DOM, CSSOM, Fetch for initial stylesheet loading, fonts, image decoding and the host print-dialog implementation are required. A successful request is not evidence of saved PDF or physical output.
Contract example
import {createPrintView} from '/node_modules/arcane-os/runtime/arcane/modules/PrintView.js';
const ledger = document.querySelector('#moon-library-ledger');
const printing = createPrintView({
host:ledger,
content:() => ledger,
title:() => 'Books overdue on the Moon',
active:() => true
});
document.querySelector('#print-ledger').onclick = async function printLedger(){
try { await printing.print(); }
catch(error) { console.error('Unable to print the ledger:', error); }
};
Related reference
No direct Core call is claimed for this artifact. Any injected provider or consuming module retains its own documented authority.