Constructor
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 nodocument is passed, the loader looks for a source in this order:
config.src?src=query parameter on the host page URLdata-src/data-sourceon the currently-executing<script>tag (CDN auto-mount)
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.
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.