This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.
Every visitor gets a working page: Diorama only ever adds to the HTML. This page covers the three cases where it adds less or nothing: visitors who asked for reduced motion, touch devices without hover, and browsers without WebGPU or WebGL 2.
Reduced motion
When the system setting prefers-reduced-motion: reduce is on, effects keep running but stop moving on their own. Motion inputs read zero and clocks stand still.
So a hover ripple shows a still picture, a scroll-speed bend lies flat, and an effect driven by time holds one frame. The visitor still sees the effect’s picture, colors and layout.
The setting can change while the page is open. Diorama reads it live: inputs are recomputed and a frame is drawn at once.
Live preview needs WebGPU or WebGL 2. A photo with ripple and bend and a checkbox that emulates reduced motion: with it on, the photo stays still under the pointer and while the page scrolls.
This example failed to draw.
The checkbox emulates the setting for this whole page, the same way the Rendering panel of DevTools does.
<img
src="/media/ridges.jpg"
width="800"
height="450"
data-dio="ripple bend"
/>
Turn an effect off
reducedMotion: 'off' removes the effect for these visitors. The instance is off, the element stays plain HTML with data-dio-state="off", and the device does not start the engine for it.
src/effects/sway.ts
import{
functioneffect(
setup:EffectSetup<Empty>
):Effect<Empty>(+2overloads)
Short form of defineEffect: defaults, optional options, setup. An unnamed effect takes its
registry key (the file name when a build plugin finds it).
The default, 'static', keeps the effect with motion inputs at zero. Choose 'off' when the still frame makes no sense, such as particles frozen mid-flight.
Keep inputs still yourself
pointer, progress and pin keep moving, because they follow what the visitor does. When an effect turns them into large motion, scale that part by u.motion, which is 1 normally and 0 under reduced motion.
src/effects/slide.ts
import{
functioneffect(
setup:EffectSetup<Empty>
):Effect<Empty>(+2overloads)
Short form of defineEffect: defaults, optional options, setup. An unnamed effect takes its
registry key (the file name when a build plugin finds it).
On the CPU, input.reducedMotion is true under reduced motion. Read it in update, which asks for frames by returning true and gets them under reduced motion too, or in a function passed to animate, which decides frames on its own.
Page transitions
Under reduced motion page transitions do not fly. A keyed copy fades out in place in 0.2 seconds, and its target shows its DOM until its own copy is ready. Inside a browser view transition, copies fade with the root crossfade over 0.25 seconds. Durations and timelines you set for leaving and entering copies do not play.
Test it
Chrome DevTools: open the Rendering panel and set “Emulate CSS media feature prefers-reduced-motion” to reduce.
An effect that moves only under the pointer shows nothing new on a phone, while the engine costs about 225 KB to download. Set when: 'hover' on such effects. It is short for the media query '(hover: hover)'; on a device where it does not match, the instance is off, the element stays plain HTML with data-dio-state="off" and the engine does not start for it.
src/effects/brighten.ts
import{
functioneffect(
setup:EffectSetup<Empty>
):Effect<Empty>(+2overloads)
Short form of defineEffect: defaults, optional options, setup. An unnamed effect takes its
registry key (the file name when a build plugin finds it).
The built-in ripple declares when: 'hover' in its registry entry as well, so a touch device downloads neither its module nor the engine for it. An effect from your folder has its when in the file, which the device reads first: the module downloads, the engine does not start. when takes any media query, such as '(min-width: 768px)', and follows it live: when the query starts or stops matching, instances turn on or off.
when is never guessed from the code, since an effect can react to a tap on purpose: pointer follows touch too. To enable one of your effects on touch without editing its file, register it in start() with when: 'all'. An entry’s when beats the one in the definition, and an entry with when: 'hover' saves the module download on touch devices.
src/main.ts
import{
functionstart(options?:StartOptions):App
Starts Diorama on the page and returns the app at once. It finishes starting in the
background. A second call returns the same app, so a re-run module doesn't make another.
import { start } from '@dioramajs/diorama'
export const app = start()
start}from'@dioramajs/diorama'
exportconst
const app:App
app=
functionstart(options?:StartOptions):App
Starts Diorama on the page and returns the app at once. It finishes starting in the
background. A second call returns the same app, so a re-run module doesn't make another.
Effects besides the folder's and the catalogue's: a new entry replaces the one of its name,
a patch ({ ripple: { when: 'all' } }) changes when or reducedMotion of a known one.
Replacing a built-in warns EFFECT_OVERRIDE in development unless the entry has
override: true.
To keep the engine off every device without hover, pass the query to enabled.
src/main.ts
import{
functionstart(options?:StartOptions):App
Starts Diorama on the page and returns the app at once. It finishes starting in the
background. A second call returns the same app, so a re-run module doesn't make another.
import { start } from '@dioramajs/diorama'
export const app = start()
start}from'@dioramajs/diorama'
exportconst
const app:App
app=
functionstart(options?:StartOptions):App
Starts Diorama on the page and returns the app at once. It finishes starting in the
background. A second call returns the same app, so a re-run module doesn't make another.
import { start } from '@dioramajs/diorama'
export const app = start()
start({
StartOptions.enabled?: boolean |"auto"|undefined
'auto' (default) is off under Save-Data and unavailable without WebGPU or WebGL 2. true
ignores Save-Data but not a missing GPU: the page stays plain, as with 'auto'. false is off.
enabled:
functionmatchMedia(query:string):MediaQueryList
The Window interface's matchMedia() method returns a new MediaQueryList object that can then be used to determine if the document matches the media query string, as well as to monitor the document to detect when it matches (or stops matching) that media query.
The matches read-only property of the MediaQueryList interface is a boolean value that returns true if the document currently matches the media query list, or false if not.
Effects driven by scroll speed, such as bend, trail native touch scrolling by one frame, because the browser scrolls on its compositor. Lenis with syncTouch: true scrolls touch on the main thread in step with the canvas; see GSAP and Lenis. To test touch, turn on device emulation in DevTools: it reports (hover: none).
Without WebGL
Before it downloads three.js or any effect module, Diorama checks the device once per app: Save-Data first, then the GPU, a WebGPU adapter or a WebGL 2 context. The check runs when the first element with an effect nears the viewport, or earlier for the idle-time prefetch after the window load event. The table also lists the cases from the sections above, since they leave the element the same way.
In the first three cases nothing of three.js or the effects is downloaded, not even by the idle-time prefetch, and the page works as written. Page transitions still swap the page, without flights. A browser without a GPU prints the RENDER_UNAVAILABLE warning once, in development builds only; production stays silent, since such visitors are expected. A lost device is a real failure: RENDER_LOST is reported once as an error.
enabled sets the check: 'auto' applies both rules, true ignores Save-Data but still checks the GPU, so a browser without one stays plain as with 'auto', and false turns the effects off.
Style the fallback with the attribute. A hint that only makes sense with the effect, for example, can hide without it.
figure:has([data-dio-state="off"]).hover-hint{
display:none;
}
To react in code, wait until the app runs and watch the status.
src/main.ts
import{
functionready(app?:App):Promise<App>
Resolves with the app once it runs: the page's app of start() by default, waiting for the
call if it has not happened yet. Rejects if the app fails or is destroyed first.
const app = await ready()
app.effects.get(el, 'ripple')
ready,
functionstart(options?:StartOptions):App
Starts Diorama on the page and returns the app at once. It finishes starting in the
background. A second call returns the same app, so a re-run module doesn't make another.
import { start } from '@dioramajs/diorama'
export const app = start()
start}from'@dioramajs/diorama'
exportconst
const app:App
app=
functionstart(options?:StartOptions):App
Starts Diorama on the page and returns the app at once. It finishes starting in the
background. A second call returns the same app, so a re-run module doesn't make another.
import { start } from '@dioramajs/diorama'
export const app = start()
start()
void
functionready(app?:App):Promise<App>
Resolves with the app once it runs: the page's app of start() by default, waiting for the
call if it has not happened yet. Rejects if the app fails or is destroyed first.
const app = await ready()
app.effects.get(el, 'ripple')
ready(
const app:App
app).
Promise<App>.then<void,never>(
onfulfilled?:
|((value:App)=>void| PromiseLike<void>)
|null
|undefined,
onrejected?:
|((reason:any)=> PromiseLike<never>)
|null
|undefined
): Promise<void>
Attaches callbacks for the resolution and/or rejection of the Promise.
@param ― onfulfilled The callback to execute when the Promise is resolved.
@param ― onrejected The callback to execute when the Promise is rejected.
@returns ― A Promise for the completion of which ever callback is executed.
then((
app: App
app)=>{
app: App
app.
Services.effects: EffectsApi
effects.
EffectsApi.status: ReadonlySignal<EffectsStatus>
The state of the engine.
status.
ReadonlySignal<EffectsStatus>.subscribe(
listener: (value:EffectsStatus)=>void
): Off
Calls the listener now and after every change (Svelte store contract).
subscribe((
status: EffectsStatus
status)=>{
const
const flat:boolean
flat=
status: EffectsStatus
status==='unavailable'||
status:"idle"|"loading"|"ready"|"off"
status==='off'
var document:Document
window.document returns a reference to the document contained in the window.
The documentElement read-only property of the Document interface returns the Element that is the root element of the document (for example, the element for HTML documents).
The read-only classList property of the Element interface contains a live DOMTokenList collection representing the class attribute of the element. This can then be used to manipulate the class list.
The toggle() method of the DOMTokenList interface removes an existing token from the list and returns false. If the token doesn't exist it's added and the function returns true.