Diorama

Made for a big screen.

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.

GitHub

DioramaDocs

@dioramajs/diorama/core

Exports of @dioramajs/diorama/core.

View as Markdown
On this page
import { anchors, batch, cancel } from '@dioramajs/diorama/core'

Functions

batchRuns `fn` and notifies effects once at the end, not after each write.
cancelReturned from a hook handler to stop the chain. `callHook` then returns it.
computedA read-only value derived from signals, recomputed lazily when they change.
createAppCreates an app with the built-in web layer and the given presets and plugins. Call `start()` to run it.
definePluginDefines a plugin. The result is a frozen function: call it with options for a configured copy.
definePresetGroups plugins and other presets under one name for `createApp({ presets })`.
effectRuns `fn` now and again whenever a signal it read changes. Returns Off.
isCancelWhether a hook result is a `cancel()`.
isDioramaErrorWhether `value` is a `DioramaError`, with `code` if one is given.
manualDriverA driver that frames only on `tick()` or `flush()`, for tests.
offlineDriverA fixed-step driver that frames on `step()`, for video capture.
rafDriverFrames on `requestAnimationFrame`. The default driver in the browser.
satisfiesWhether `version` is within a semver `range` such as `^1.2.0 || >=2`.
signalA writable reactive value. Reading `value` inside `effect` or `computed` tracks it.
tickerDriverA driver on an external ticker, such as `gsap.ticker`. `subscribe` returns its own Off.
untrackedRuns `fn` without tracking the signals it reads.

Classes

DioramaErrorAn error of the kernel or a plugin. Its message reads `[diorama] CODE: message`.

Constants

anchorsLayout is read only when something may have moved (resize, observed size changes, fonts). Each frame just offsets the cached page boxes by the scroll position. Live anchors near the viewport are re-read every frame, since sticky, fixed and transformed boxes move without a layout change.
pointerTracks the pointer over the page. Built in.
scrollTracks page scroll, its velocity and progress. Built in.
stageOne canvas for the whole site. It outlives page transitions.
VERSIONVersion of @dioramajs/core.
visibilityTracks tab visibility and pauses frames while the tab is hidden. Built in.

Interfaces

AnchorAn element's box, kept in sync with the page in the `layout` stage.
AnchorsApiThe `anchors` service: element boxes kept in sync with the page.
AppControlsLifecycle controls of an app.
AppCoreThe kernel API seen by the app, plugins and scopes. Registrations belong to the view's owner and are undone with it. Methods are unbound: pass arrows to callbacks.
AppOptionsOptions of `createApp`.
CancelResult of `cancel()`: stops a hook chain.
DioramaErrorOptionsOptions of `DioramaError`.
DisposableLikeAnything with `dispose()`.
DriverLinkThe loop's connection to a driver.
ErrorReportWhat `app:error` listeners and `onError` receive.
EventsEvent payloads by name (`undefined` for none). Extend via declaration merging.
FrameDriverDecides when frames happen, while the loop decides whether one is needed. `now()` is in ms.
FrameProfilerReceives timing points of every frame, see `app.profile`.
FrameStatsCounters of the frame loop.
FrameTimeOne mutable object per app. Durations are seconds, timestamps milliseconds.
HooksHook signatures by name, `(value, context?) => result`. A `Promise` result makes the hook async. A handler returns a new value, nothing, or `cancel()`.
LoggerConsole-like sink for logs. `console` by default.
LoopLive loop state. Change settings with `overrideLoop`.
LoopOptionsLoop options of `createApp`.
LoopSettingsLoop settings that `overrideLoop` can change.
ManualDriverFrames only on `tick()` or `flush()`, for deterministic tests.
ManualDriverOptionsOptions of `manualDriver`.
OfflineDriverFixed-step frames on `step()` for video capture. Runs even while paused.
OfflineDriverOptionsOptions of `offlineDriver`.
OrderOptions`name` defaults to the owner label. `before`/`after` match entry names or plugin names.
PluginA plugin is a frozen function. Calling it with options returns a configured copy. N is the name and service key, O the options, S the service, R the keys required at call time.
PluginDefinitionWhat `definePlugin` takes.
PluginRefA plugin or anything with its name and types, for `get`, `find` and dependencies.
PluginStatusEventPayload of `plugin:status`.
PluginTypesPhantom types of a plugin, for inference.
PointerApiThe `pointer` service.
PointerStateLive pointer state. A move asks for a frame only if someone read the position in the last frame (or since), so a page whose effects ignore the pointer draws nothing on mouse moves.
PresetA named group of plugins and presets.
PresetDefinitionWhat `definePreset` takes.
ReadonlySignalA reactive value that can be read and watched.
RemoveOptionsOptions of `app.remove`.
ScopeControlsLifecycle controls of a scope.
ScrollApiThe `scroll` service.
ScrollSampleOne frame's reading of a scroll source, filled in place.
ScrollSourceWhere `scroll` takes the offset from. Without one, window scroll events are cached.
ScrollStateLive scroll state, updated in place in the `input` stage.
ServicesServices by plugin name, exposed as `app.<name>`. Extend via declaration merging.
SignalA reactive value that can be written.
SignalOptionsOptions of `signal` and `computed`.
StageApiThe `stage` service: the canvas and the viewport.
StageOptionsOptions of the `stage` plugin.
StagesFrame stages in run order. `addStage` inserts more, extend this to type them.
StandardSchemaIssueOne validation problem.
StandardSchemaPropsStandard Schema properties.
StandardSchemaTypesInput and output types of a schema.
StandardSchemaV1Standard Schema v1, inlined to stay dependency-free (Zod, Valibot, ArkType implement it).
SystemHandleCalling the handle removes the system.
SystemInfoA system as the profiler sees it.
TickerDriverOptionsOptions of `tickerDriver`.
TrackOptionsOptions of `anchors.track`.
VisibilityApiThe `visibility` service.
VisibilityOptionsOptions of the `visibility` plugin.

Types

AnyPluginA plugin of any name, options and service.
AppWhat `createApp` returns: the kernel API, lifecycle controls and services.
AppScopeA child view of the app whose registrations are undone together by `dispose()`.
AppStateLifecycle state of an app.
CleanupA function or anything with `dispose()`, so Three.js resources fit as is.
DependenciesOfServices of the declared dependencies, as `setup` sees them.
DependencyRefA dependency by name or by plugin.
EffectFnMay return a cleanup, run before the next run and on disposal.
EmptyAn object type with no keys.
ErrorCodeCodes of errors from the kernel and the built-in web layer.
ErrorSourceWhere a reported error was caught.
EventArgsArguments of `emit` for event `K`: none when the payload is `undefined`.
EventNameNames of the registered events.
FrameMode`demand` frames only when something asks, `always` frames continuously.
FrameReasonWhy the last frame ran.
FrameTickRuns one frame at `now` (ms). Returns whether a frame ran.
HandlerReturnWhat a hook handler may return: a new value, nothing, or a promise of either for async hooks.
HookArgsArguments of hook `K`.
HookHandlerHandler of hook `K`.
HookNameNames of the registered hooks.
HookResultResult of hook `K`.
ListenerListener of event `K`.
LogCodeCodes of warnings and notes that adapters and `start()` log as `CODE: message`, outside the error code unions of the packages.
LogLevelLeast severe level that is logged. `silent` logs nothing.
MaybePromiseA value or a promise of it.
OffUndoes a registration immediately. Calling it again does nothing.
OptionsOfOptions type of a plugin from its declared types, defaults and schema.
OrderRefOne name or several, for `before` and `after`.
PluginApp`app` inside setup: its own service and declared dependencies only.
PluginArgsArguments of a plugin call: partial options, with the keys in `R` required.
PluginEntryFalsy entries are skipped, so `dev && devtools` works.
PluginNameA plugin name: a registered service or any string.
PluginNameProblemWhy `N` is not a valid plugin name, or `never` when it is.
PluginSourceHow a plugin came in: built in, from a preset, from `createApp` or from `use`.
PluginStatusLifecycle state of a plugin.
PresetEntryA preset, or a falsy value that is skipped.
PresetPluginsPlugins of a preset type.
RegisteredServiceService registered under name `N` in `Services`, or `void`.
RequiredOptionsOption keys that a plugin call must pass.
ReservedNameNames a plugin cannot take, since the app API uses them.
ScrollAxisScroll axis: `x` for horizontal, `y` for vertical.
ServiceForService of plugin `N`: the registered one when `N` is in `Services`, else `S`.
ServiceNameNames of the registered services.
ServiceOfService type of a plugin.
ServicesOfServices of a union of plugins, keyed by name.
StageNameNames of the frame stages.
StagePositionWhere `addStage` puts a stage: before or after an existing one.
StandardSchemaResultResult of a Standard Schema validation.
SyncHookArgsArguments of `callHook` for hook `K`. Async hooks need `callHookAsync`.
SystemRuns once per frame and must be synchronous.