Skip to main content

Constructor

The constructor resolves config.element immediately and begins initialisation asynchronously.

element: string | HTMLElement

Either an element id (without the #) or an HTMLElement reference. If the id does not resolve, the constructor throws Element not found: <id>.

src: string

URL of a ScreenJSON document. The internal DocumentLoader fetches and parses it. Failures call onError with a structured LoaderError.

document: ScreenJSONDocument

A pre-loaded document. Takes precedence over src when both are provided — useful when you’ve already fetched and validated the doc.

Loading precedence

When no document is passed, the loader looks for a source in this order:
  1. config.src
  2. ?src= query parameter on the host page URL
  3. data-src / data-source on the currently-executing <script> tag (CDN auto-mount)
If none resolve, the viewer renders a LoaderError with code UNKNOWN and a “No Document Source” suggestion.

Theme

config.theme is the initial theme. The viewer also:
  • Reads localStorage['screenjson-theme'] first.
  • Falls back to prefers-color-scheme.
  • Persists the user’s toolbar choice back to localStorage.
Toggle theme programmatically by calling setTheme('light' | 'dark') on the instance, or by toggling the dark class on the <html> element directly.

Zoom

config.zoom is a manual multiplier on top of the auto-fit zoom that shrinks the paper to fit the viewport. 1 is auto-fit; 1.5 zooms in 50% on top of fit; 0.5 halves the auto-fit scale.

Callbacks

Complete example

See Options for the complete config surface.