@dioramajs/diorama/core
Exports of @dioramajs/diorama/core.
On this page
import { anchors, batch, cancel } from '@dioramajs/diorama/core'Functions
batch | Runs `fn` and notifies effects once at the end, not after each write. |
cancel | Returned from a hook handler to stop the chain. `callHook` then returns it. |
computed | A read-only value derived from signals, recomputed lazily when they change. |
createApp | Creates an app with the built-in web layer and the given presets and plugins. Call `start()` to run it. |
definePlugin | Defines a plugin. The result is a frozen function: call it with options for a configured copy. |
definePreset | Groups plugins and other presets under one name for `createApp({ presets })`. |
effect | Runs `fn` now and again whenever a signal it read changes. Returns Off. |
isCancel | Whether a hook result is a `cancel()`. |
isDioramaError | Whether `value` is a `DioramaError`, with `code` if one is given. |
manualDriver | A driver that frames only on `tick()` or `flush()`, for tests. |
offlineDriver | A fixed-step driver that frames on `step()`, for video capture. |
rafDriver | Frames on `requestAnimationFrame`. The default driver in the browser. |
satisfies | Whether `version` is within a semver `range` such as `^1.2.0 || >=2`. |
signal | A writable reactive value. Reading `value` inside `effect` or `computed` tracks it. |
tickerDriver | A driver on an external ticker, such as `gsap.ticker`. `subscribe` returns its own Off. |
untracked | Runs `fn` without tracking the signals it reads. |
Classes
DioramaError | An error of the kernel or a plugin. Its message reads `[diorama] CODE: message`. |
Constants
anchors | Layout 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. |
pointer | Tracks the pointer over the page. Built in. |
scroll | Tracks page scroll, its velocity and progress. Built in. |
stage | One canvas for the whole site. It outlives page transitions. |
VERSION | Version of @dioramajs/core. |
visibility | Tracks tab visibility and pauses frames while the tab is hidden. Built in. |
Interfaces
Anchor | An element's box, kept in sync with the page in the `layout` stage. |
AnchorsApi | The `anchors` service: element boxes kept in sync with the page. |
AppControls | Lifecycle controls of an app. |
AppCore | The 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. |
AppOptions | Options of `createApp`. |
Cancel | Result of `cancel()`: stops a hook chain. |
DioramaErrorOptions | Options of `DioramaError`. |
DisposableLike | Anything with `dispose()`. |
DriverLink | The loop's connection to a driver. |
ErrorReport | What `app:error` listeners and `onError` receive. |
Events | Event payloads by name (`undefined` for none). Extend via declaration merging. |
FrameDriver | Decides when frames happen, while the loop decides whether one is needed. `now()` is in ms. |
FrameProfiler | Receives timing points of every frame, see `app.profile`. |
FrameStats | Counters of the frame loop. |
FrameTime | One mutable object per app. Durations are seconds, timestamps milliseconds. |
Hooks | Hook signatures by name, `(value, context?) => result`. A `Promise` result makes the hook async. A handler returns a new value, nothing, or `cancel()`. |
Logger | Console-like sink for logs. `console` by default. |
Loop | Live loop state. Change settings with `overrideLoop`. |
LoopOptions | Loop options of `createApp`. |
LoopSettings | Loop settings that `overrideLoop` can change. |
ManualDriver | Frames only on `tick()` or `flush()`, for deterministic tests. |
ManualDriverOptions | Options of `manualDriver`. |
OfflineDriver | Fixed-step frames on `step()` for video capture. Runs even while paused. |
OfflineDriverOptions | Options of `offlineDriver`. |
OrderOptions | `name` defaults to the owner label. `before`/`after` match entry names or plugin names. |
Plugin | A 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. |
PluginDefinition | What `definePlugin` takes. |
PluginRef | A plugin or anything with its name and types, for `get`, `find` and dependencies. |
PluginStatusEvent | Payload of `plugin:status`. |
PluginTypes | Phantom types of a plugin, for inference. |
PointerApi | The `pointer` service. |
PointerState | Live 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. |
Preset | A named group of plugins and presets. |
PresetDefinition | What `definePreset` takes. |
ReadonlySignal | A reactive value that can be read and watched. |
RemoveOptions | Options of `app.remove`. |
ScopeControls | Lifecycle controls of a scope. |
ScrollApi | The `scroll` service. |
ScrollSample | One frame's reading of a scroll source, filled in place. |
ScrollSource | Where `scroll` takes the offset from. Without one, window scroll events are cached. |
ScrollState | Live scroll state, updated in place in the `input` stage. |
Services | Services by plugin name, exposed as `app.<name>`. Extend via declaration merging. |
Signal | A reactive value that can be written. |
SignalOptions | Options of `signal` and `computed`. |
StageApi | The `stage` service: the canvas and the viewport. |
StageOptions | Options of the `stage` plugin. |
Stages | Frame stages in run order. `addStage` inserts more, extend this to type them. |
StandardSchemaIssue | One validation problem. |
StandardSchemaProps | Standard Schema properties. |
StandardSchemaTypes | Input and output types of a schema. |
StandardSchemaV1 | Standard Schema v1, inlined to stay dependency-free (Zod, Valibot, ArkType implement it). |
SystemHandle | Calling the handle removes the system. |
SystemInfo | A system as the profiler sees it. |
TickerDriverOptions | Options of `tickerDriver`. |
TrackOptions | Options of `anchors.track`. |
VisibilityApi | The `visibility` service. |
VisibilityOptions | Options of the `visibility` plugin. |
Types
AnyPlugin | A plugin of any name, options and service. |
App | What `createApp` returns: the kernel API, lifecycle controls and services. |
AppScope | A child view of the app whose registrations are undone together by `dispose()`. |
AppState | Lifecycle state of an app. |
Cleanup | A function or anything with `dispose()`, so Three.js resources fit as is. |
DependenciesOf | Services of the declared dependencies, as `setup` sees them. |
DependencyRef | A dependency by name or by plugin. |
EffectFn | May return a cleanup, run before the next run and on disposal. |
Empty | An object type with no keys. |
ErrorCode | Codes of errors from the kernel and the built-in web layer. |
ErrorSource | Where a reported error was caught. |
EventArgs | Arguments of `emit` for event `K`: none when the payload is `undefined`. |
EventName | Names of the registered events. |
FrameMode | `demand` frames only when something asks, `always` frames continuously. |
FrameReason | Why the last frame ran. |
FrameTick | Runs one frame at `now` (ms). Returns whether a frame ran. |
HandlerReturn | What a hook handler may return: a new value, nothing, or a promise of either for async hooks. |
HookArgs | Arguments of hook `K`. |
HookHandler | Handler of hook `K`. |
HookName | Names of the registered hooks. |
HookResult | Result of hook `K`. |
Listener | Listener of event `K`. |
LogCode | Codes of warnings and notes that adapters and `start()` log as `CODE: message`, outside the error code unions of the packages. |
LogLevel | Least severe level that is logged. `silent` logs nothing. |
MaybePromise | A value or a promise of it. |
Off | Undoes a registration immediately. Calling it again does nothing. |
OptionsOf | Options type of a plugin from its declared types, defaults and schema. |
OrderRef | One name or several, for `before` and `after`. |
PluginApp | `app` inside setup: its own service and declared dependencies only. |
PluginArgs | Arguments of a plugin call: partial options, with the keys in `R` required. |
PluginEntry | Falsy entries are skipped, so `dev && devtools` works. |
PluginName | A plugin name: a registered service or any string. |
PluginNameProblem | Why `N` is not a valid plugin name, or `never` when it is. |
PluginSource | How a plugin came in: built in, from a preset, from `createApp` or from `use`. |
PluginStatus | Lifecycle state of a plugin. |
PresetEntry | A preset, or a falsy value that is skipped. |
PresetPlugins | Plugins of a preset type. |
RegisteredService | Service registered under name `N` in `Services`, or `void`. |
RequiredOptions | Option keys that a plugin call must pass. |
ReservedName | Names a plugin cannot take, since the app API uses them. |
ScrollAxis | Scroll axis: `x` for horizontal, `y` for vertical. |
ServiceFor | Service of plugin `N`: the registered one when `N` is in `Services`, else `S`. |
ServiceName | Names of the registered services. |
ServiceOf | Service type of a plugin. |
ServicesOf | Services of a union of plugins, keyed by name. |
StageName | Names of the frame stages. |
StagePosition | Where `addStage` puts a stage: before or after an existing one. |
StandardSchemaResult | Result of a Standard Schema validation. |
SyncHookArgs | Arguments of `callHook` for hook `K`. Async hooks need `callHookAsync`. |
System | Runs once per frame and must be synchronous. |