@dioramajs/effects
Effects on DOM elements and their runtime.
On this page
import { attachPlugin, color, defineEffect } from '@dioramajs/effects'Functions
color | Colour 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`. |
defineEffect | Checks a definition and returns it as a frozen callable. Registers and loads nothing. Throws `EFFECT_DEFINITION` on a bad definition. |
effect | Short form of `defineEffect`: defaults, optional options, setup. An unnamed effect takes its registry key (the file name when a build plugin finds it). |
effects | Preset of the `effects` and `attach` plugins. |
group | Entries 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`. |
oneOf | String param limited to these values. The first one is the default. |
redefine | Swaps the definition registered under `key` in live apps. |
text | Plain string param for a default that looks like a colour, e.g. `text('#cafe')`. |
Classes
EffectError | Goes 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`. |
effectsPlugin | Effects 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. |
AttachOptions | Options of `attach`. |
Box | A viewport box in CSS px, as anchors report it. |
ChoiceParam | A string param limited to some values, made by `oneOf()`. |
ColorParam | A 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. |
Copy | Control 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. |
Crop | A region of a picture in texture UV, y up: `texture uv = box uv * size + xy`. |
DocExample | An example of an effect's docs: markup and optional code. |
DrawnBox | What the copy showed in its last drawn frame, in viewport CSS px. |
Effect | Frozen callable, like a plugin. Calling it returns a configured use. |
EffectContext | Methods are bound, so `setup({ surface, u, place })` works. |
EffectDefinition | What `defineEffect` takes: the params, the options and `setup`. |
EffectEntry | A 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. |
EffectGroup | The shared loader of a package's entry map; see `group()`. |
EffectGroupEntry | An 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. |
EffectHandle | Calling the handle detaches it, like kernel handles. `scope.onDispose(handle)` ties it to a scope. |
EffectInput | The same inputs as numbers. One object per layer, updated in place in `layout`. |
EffectInstance | Stable 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). |
EffectMeta | One effect in `meta.json`: what the definition says plus its `.doc.ts`. |
EffectsApi | The `effects` service, `app.effects`. |
EffectsOptions | Options of the `effects` preset. |
EffectsStats | Counters of `app.effects.stats()`. |
EffectTypes | Effect types of packages by name, for typed attach and get. Extend via declaration merging. |
EffectUse | An effect with params, as `ripple({ strength: 2 })` returns it. |
EventDoc | A DOM event an effect dispatches on its element. |
Fit | A texture framed in the element's box like CSS object-fit. |
FitOptions | Options of `ctx.fit`. |
InputUniforms | Built-in inputs as TSL uniforms. Each one is created on first access and only then updated. |
Layer | One per element with at least one live effect. |
ModelOptions | Options of `ctx.model`. |
ParamDoc | Description of one param in an effect's `.doc.ts`. |
ParamMeta | One param in `meta.json`. |
ParamVector | Live view of a tuple param. Each component can be tweened. |
PartDoc | A shadow part of the effect's own UI, styled by the site with `::part()`. |
PlaceOptions | Options of `ctx.place`. |
PosedBox | Where the element's own effects pose its copy, in viewport CSS px. |
PoseTarget | Absolute target in world px (viewport centre 0,0, y up) and radians. Omitted fields keep layout. |
QualitySpec | How an effect gets cheaper: the lowest tier it runs at and its caps per tier. |
ReleaseRequest | Payload of `effects:release`: a drawn copy's element left the document and nobody took it. |
SiteEffects | Effect 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. |
Surface | The element's single GL copy. Effects add transforms in the order they sit on the element. |
SurfaceInput | Input of a colour transform. The final alpha is then multiplied by `u.opacity` and the clip mask. |
TakeOptions | Options of `app.effects.take`. |
TextParam | A plain string param whose default looks like a colour, e.g. `text('#cafe')`. |
TextureOptions | Options of `ctx.texture`. |
Types
AnimatePolicy | When 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. |
AnyParamValue | Any param value. |
AttachPlugin | The `attach` plugin, which gives `app.attach`. |
CheckParams | Makes reserved param names fail in `defineEffect`. |
CheckSpec | Makes reserved names fail at the call site. |
ChildDoc | What 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"]' }`). |
CopyState | The state of a taken copy. |
EffectApp | Kernel scope of one instance. Registrations die with it. Exposes the services effects use, plus `assets` when `@dioramajs/assets` is installed. |
EffectCategory | A 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`). |
EffectDoc | The written part of an effect's docs, typed against the effect so every param is described. |
EffectEntries | The key is the token in markup and the instance name. A definition with another name is an alias. |
EffectErrorCode | Codes of `EffectError`. |
EffectLoader | A lazy import of an effect module. |
EffectModule | A module whose default export is an effect, or the effect itself. |
EffectName | Checked once a registry is extended, any string before that. |
EffectOptions | Options of `effect()`, the definition minus params and setup. |
EffectSetup | The `setup` function of an effect. |
EffectSource | An effect, a loader, an entry with metadata or an entry of a lazy group. |
EffectsPlugin | The `effects` plugin. |
EffectsStatus | The state of the engine. |
EffectUpdate | Runs 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. |
InstanceStatus | Where an instance is in its life. |
LiveParams | Writable params of handles and instances. Tuples read as live vectors you can tween by component. Write a whole tuple with `set({ offset: [1, 2] })`. |
OptionName | Definition options, never valid as param names: `effect({ when: 'hover' }, setup)` fails. |
ParamDefault | A 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. |
ParamsOf | Param values by name. |
ParamSpec | Param defaults by name. |
ParamUniform | The uniform node of a param with default `D`; strings and choices have none. |
ParamValue | The value type of a param with default `D`. |
QualityCaps | Upper bounds of numeric params at a tier. A value above the bound is lowered, never raised. |
QualityTier | Quality tier, from `@dioramajs/quality`. |
ReservedAttr | `data-dio-*` names used by the framework itself. |
ReservedParam | Names a param cannot take: input uniforms (they share `ctx.u`) and reserved attributes. `EffectInput` keys are fine because inputs live on `ctx.input`. |
SpecFor | The params of a known effect by name, `ParamSpec` for any other. |
Target | A 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. |
When | A media query. 'hover' is short for '(hover: hover)'. |
WidenSpec | Widens literal defaults so `Effect<{ strength: number }>` accepts `{ strength: 1 }`. |