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/effects

Effects on DOM elements and their runtime.

View as Markdown
On this page
import { attachPlugin, color, defineEffect } from '@dioramajs/effects'

Functions

colorColour param. A CSS colour string on the CPU, as written; a `color` uniform on the GPU. The uniform reads `var(--name)` and `currentColor` from the element when the value is written and again in every frame the element draws, so a theme switch shows with the next frame. Code that reads the string itself resolves it with `cssColor(value, element)` of `@dioramajs/render`.
defineEffectChecks a definition and returns it as a frozen callable. Registers and loads nothing. Throws `EFFECT_DEFINITION` on a bad definition.
effectShort form of `defineEffect`: defaults, optional options, setup. An unnamed effect takes its registry key (the file name when a build plugin finds it).
effectsPreset of the `effects` and `attach` plugins.
groupEntries of a package whose map loads on first need: one entry per name, each sharing the loader, with `extra` fields that must be known before the map, such as `intro`.
oneOfString param limited to these values. The first one is the default.
redefineSwaps the definition registered under `key` in live apps.
textPlain string param for a default that looks like a colour, e.g. `text('#cafe')`.

Classes

EffectErrorGoes through `app.report`, which wraps it as `REPORTED` with this as `cause`. `instanceof EffectError` checks the name, so it also holds for definition errors thrown by `@dioramajs/effects/effect`, which cannot import this class, and across two copies.

Constants

attachPlugin`app.attach`, the same function as `app.effects.attach`.
effectsPluginEffects from markup and code. This light part loads the runtime when needed.

Interfaces

Attach`app.attach`: puts an effect on elements by selector, element or list.
AttachOptionsOptions of `attach`.
BoxA viewport box in CSS px, as anchors report it.
ChoiceParamA string param limited to some values, made by `oneOf()`.
ColorParamA colour param, made by `color()`. Its uniform reads `var(--name)` and `currentColor` from the element, again in every frame the element draws, so it follows a theme switch.
CopyControl of one element's GL copy from outside its effects. Taken with `leave: 'ghost'`, the copy is not parked or released when its element leaves the document. It becomes a ghost owned by the taker. Every write requests a frame. One owner per element.
CropA region of a picture in texture UV, y up: `texture uv = box uv * size + xy`.
DocExampleAn example of an effect's docs: markup and optional code.
DrawnBoxWhat the copy showed in its last drawn frame, in viewport CSS px.
EffectFrozen callable, like a plugin. Calling it returns a configured use.
EffectContextMethods are bound, so `setup({ surface, u, place })` works.
EffectDefinitionWhat `defineEffect` takes: the params, the options and `setup`.
EffectEntryA loader plus what the light part must know before three loads. Checked against the definition after load. On a mismatch the definition wins and dev mode warns.
EffectGroupThe shared loader of a package's entry map; see `group()`.
EffectGroupEntryAn entry whose metadata comes with its package's map, loaded on first need. Its own fields lie over the map's entry, like a site's patch.
EffectHandleCalling the handle detaches it, like kernel handles. `scope.onDispose(handle)` ties it to a scope.
EffectInputThe same inputs as numbers. One object per layer, updated in place in `layout`.
EffectInstanceStable facade of an (element, name) pair. The same object, with its runtime writes, survives park, dispose and re-creation for the same pair (Vue KeepAlive, cached nodes).
EffectMetaOne effect in `meta.json`: what the definition says plus its `.doc.ts`.
EffectsApiThe `effects` service, `app.effects`.
EffectsOptionsOptions of the `effects` preset.
EffectsStatsCounters of `app.effects.stats()`.
EffectTypesEffect types of packages by name, for typed attach and get. Extend via declaration merging.
EffectUseAn effect with params, as `ripple({ strength: 2 })` returns it.
EventDocA DOM event an effect dispatches on its element.
FitA texture framed in the element's box like CSS object-fit.
FitOptionsOptions of `ctx.fit`.
InputUniformsBuilt-in inputs as TSL uniforms. Each one is created on first access and only then updated.
LayerOne per element with at least one live effect.
ModelOptionsOptions of `ctx.model`.
ParamDocDescription of one param in an effect's `.doc.ts`.
ParamMetaOne param in `meta.json`.
ParamVectorLive view of a tuple param. Each component can be tweened.
PartDocA shadow part of the effect's own UI, styled by the site with `::part()`.
PlaceOptionsOptions of `ctx.place`.
PosedBoxWhere the element's own effects pose its copy, in viewport CSS px.
PoseTargetAbsolute target in world px (viewport centre 0,0, y up) and radians. Omitted fields keep layout.
QualitySpecHow an effect gets cheaper: the lowest tier it runs at and its caps per tier.
ReleaseRequestPayload of `effects:release`: a drawn copy's element left the document and nobody took it.
SiteEffectsEffect types of the site's own files, written by the build plugin. A site file named like a package effect (`ripple.ts`) overrides its type instead of conflicting with it.
SurfaceThe element's single GL copy. Effects add transforms in the order they sit on the element.
SurfaceInputInput of a colour transform. The final alpha is then multiplied by `u.opacity` and the clip mask.
TakeOptionsOptions of `app.effects.take`.
TextParamA plain string param whose default looks like a colour, e.g. `text('#cafe')`.
TextureOptionsOptions of `ctx.texture`.

Types

AnimatePolicyWhen an effect asks for frames beyond input and its update's answer: - 'input' (default): frames only on input (scroll, pointer, resize, param writes). - 'hover': also while hovered or hover decays. - 'visible': every frame while on screen. - a function: checked after update, true requests the next frame. The runtime also asks it between frames whether a burst in `ctx.overlay` still flies, which an update's answer cannot tell before the next frame (a click that starts a burst and hides its element). - `{ fps }`: time frames at most `fps` a second while visible, 0 means none. Input frames run at full rate.
AnyParamValueAny param value.
AttachPluginThe `attach` plugin, which gives `app.attach`.
CheckParamsMakes reserved param names fail in `defineEffect`.
CheckSpecMakes reserved names fail at the call site.
ChildDocWhat the effect reads from or drives in the element's children, not a param: an attribute (`{ attribute: 'data-dio-src' }`) or a child element (`{ element: 'input[type="range"]' }`).
CopyStateThe state of a taken copy.
EffectAppKernel scope of one instance. Registrations die with it. Exposes the services effects use, plus `assets` when `@dioramajs/assets` is installed.
EffectCategoryA group of the docs site's effect gallery, named by what the reader wants to animate. An effect has one primary group (`category`) and may show in others (`tags`).
EffectDocThe written part of an effect's docs, typed against the effect so every param is described.
EffectEntriesThe key is the token in markup and the instance name. A definition with another name is an alias.
EffectErrorCodeCodes of `EffectError`.
EffectLoaderA lazy import of an effect module.
EffectModuleA module whose default export is an effect, or the effect itself.
EffectNameChecked once a registry is extended, any string before that.
EffectOptionsOptions of `effect()`, the definition minus params and setup.
EffectSetupThe `setup` function of an effect.
EffectSourceAn effect, a loader, an entry with metadata or an entry of a lazy group.
EffectsPluginThe `effects` plugin.
EffectsStatusThe state of the engine.
EffectUpdateRuns every frame while the instance is running and visible. Return `true` to ask for the next frame while state kept in JavaScript still moves (a damped value, a fade, a simulation), and `false` once it has settled. Without an `animate` option a returned boolean decides alone, so reading `input.delta` for the motion does not draw every frame; return one on every path. With `animate`, `true` adds frames to the policy. Returning nothing leaves it to the policy. `true` is honoured under reduced motion too: settle at once when `input.reducedMotion` is set.
InstanceStatusWhere an instance is in its life.
LiveParamsWritable params of handles and instances. Tuples read as live vectors you can tween by component. Write a whole tuple with `set({ offset: [1, 2] })`.
OptionNameDefinition options, never valid as param names: `effect({ when: 'hover' }, setup)` fails.
ParamDefaultA param default: its type is the param type. The string 'auto' makes a number param that may also be 'auto': the effect picks the value itself. It has no uniform, so a change rebuilds.
ParamsOfParam values by name.
ParamSpecParam defaults by name.
ParamUniformThe uniform node of a param with default `D`; strings and choices have none.
ParamValueThe value type of a param with default `D`.
QualityCapsUpper bounds of numeric params at a tier. A value above the bound is lowered, never raised.
QualityTierQuality tier, from `@dioramajs/quality`.
ReservedAttr`data-dio-*` names used by the framework itself.
ReservedParamNames a param cannot take: input uniforms (they share `ctx.u`) and reserved attributes. `EffectInput` keys are fine because inputs live on `ctx.input`.
SpecForThe params of a known effect by name, `ParamSpec` for any other.
TargetA selector is a live rule, like a CSS rule. An element or a list is a fixed set, held weakly.
Uniforms`ctx.u`: the input uniforms and one uniform per live param.
WhenA media query. 'hover' is short for '(hover: hover)'.
WidenSpecWidens literal defaults so `Effect<{ strength: number }>` accepts `{ strength: 1 }`.