# @dioramajs/diorama/kit

Helpers for your own effects, and the built-in image layer for their children.

## Functions and values

- [approach](/docs/api/diorama-kit/approach.md): Moves `current` towards `target` by at most `step`: a linear fade, `delta / seconds` a frame.
- [between](/docs/api/diorama-kit/between.md): Where `value` is between `start` and `end`, 0..1: a step at `start` when `end` is not past it.
- [chase](/docs/api/diorama-kit/chase.md): Moves `at` towards `aim` with `damp` on both axes and lands on it once within `near` (a distance), like `damp`'s own `near`. Returns whether it is still on its way, which an update can return to keep frames coming. `seconds` 0 jumps.
- [cornerRadius](/docs/api/diorama-kit/corner-radius.md): The radius of the corner `point` is nearest to, for `point` from the box centre with y up and `corners` the four radii of `radii` (top left, top right, bottom right, bottom left), for a `roundedBox` with corners that differ.
- [damp](/docs/api/diorama-kit/damp.md): Exponential approach, frame-rate independent: `seconds` is the time to cover ~63%, 0 jumps. Within `near` of the target it lands there, so a caller can tell when it has settled. Without `near` it lands only when floating point reaches the target, seconds later: to stop drawing once it settles, pass a step too small to see, such as 0.5 for px or 1e-3 for a 0..1 value.
- [dither](/docs/api/diorama-kit/dither.md): ±0.5/255 from the integer hash of the screen pixel, against banding in gradients. With `rgb`, ±0.5/255 after the sRGB encoding of that linear colour: the dither scaled by the slope of the decoding curve there, so dark gradients get as much as light ones. Add it to the colour.
- [ease](/docs/api/diorama-kit/ease.md): Easing curves on 0..1, clamped.
- [entering](/docs/api/diorama-kit/entering.md): Scroll progress of a box coming into view, 0..1: 0 while less than `share` of it shows, 1 once it is centred in the viewport. `progress` is `input.progress`, `height` the box height and `viewport` the viewport height in px.
- [flags](/docs/api/diorama-kit/flags.md): Reads a switch list param such as `close="esc backdrop swipe"`: the known names it holds, in any order, separated by spaces or commas. `'all'` or `'*'` turns on all of them, an empty string none. Unknown names are left out and returned, so the effect can note them once.
- [follow](/docs/api/diorama-kit/follow.md): Follows the pointer the way a light or a brush on an element wants it: a mouse or pen while it is over the element, the first finger while it is pressed on it. Touch never blocks the page's scroll: the browser takes the finger with `pointercancel` when one starts. Each change asks for a frame. Listeners go with `ctx.signal`. Returns the live pointer; `on` adds callbacks.
- [fresnel](/docs/api/diorama-kit/fresnel.md): Schlick's Fresnel: the share of light a surface reflects at `cosine` between its normal and the view, `f0` head-on (0.04 for glass and plastic, 0.02 for water). Edges catch more light.
- [fromOklab](/docs/api/diorama-kit/from-oklab.md): Linear sRGB of an OKLab colour into `out`, clamped to the gamut.
- [image](/docs/api/diorama-kit/image.md): Draws the image unchanged. `layers()` gives it to bare media.
- [inView](/docs/api/diorama-kit/in-view.md): Whether `share` 0..1 of a box is in view, counted above the bottom tenth of the viewport: a box peeking in at the edge has not been looked at yet. `top` and `height` are the box's in viewport px (`input.y`, `input.height`), `viewport` the viewport height. An empty box never is.
- [maxTextureSize](/docs/api/diorama-kit/max-texture-size.md): Largest 2D texture side the device takes: the WebGPU device limit (8192 for three r187, which asks for default limits), WebGL 2 `MAX_TEXTURE_SIZE`, else 4096. Caps decodes of big pictures.
- [mixOklab](/docs/api/diorama-kit/mix-oklab.md): `a` and `b` mixed in OKLab by `t` 0..1, into `out`.
- [noise](/docs/api/diorama-kit/noise.md): Tiling value noise, baked on the CPU, linear, RepeatWrapping. Shared per renderer and options with a reference count tied to `ctx`: never dispose it.
- [oklabToLinear](/docs/api/diorama-kit/oklab-to-linear.md): `fromOklab` in a shader: linear sRGB of an OKLab colour, clamped to the gamut.
- [palette](/docs/api/diorama-kit/palette.md): The colours of a list as `#rrggbb`, such as a brand palette in a param: any CSS colour, `var(--brand)` (its value or fallback, followed 8 levels deep) and `currentColor` read from the element's computed style, as `cssColor` of `@dioramajs/render` reads them. Spaces and commas outside parentheses separate the colours; words that are no colour are left out. Read at the call: a later change of a variable shows when the effect reads the list again.
- [radii](/docs/api/diorama-kit/radii.md): The corner radii of an element in px as CSS draws them: top left, top right, bottom right, bottom left. A `%` counts against the shorter side of the `width` × `height` box, and no corner takes more than half of that side, so `999px` draws a pill.
- [rng](/docs/api/diorama-kit/rng.md): mulberry32: the same sequence for the same seed on every load and backend.
- [roundedBox](/docs/api/diorama-kit/rounded-box.md): Signed distance in px from a rounded box, negative inside: `point` from the box centre, `half` its half size, `radius` its corners. `clamp(0.5 - d, 0, 1)` is a 1 px antialiased mask.
- [spiralBlur](/docs/api/diorama-kit/spiral-blur.md): A soft blur: the mean of `taps` reads on a golden-angle spiral over the disc of `radius` (in the units of `uv`) around `uv`. `turn` rotates the spiral; turned per pixel, the taps read as grain instead of ghost copies. One tap reads `uv` itself.
- [toBox](/docs/api/diorama-kit/to-box.md): A point in client px, such as an event's `clientX` and `clientY`, in px of `box` from its bottom left: the units of the shader's `box` times `u.size`. Pass `input` as the box in the update, since the page may scroll under a still pointer. Writes into `out` when given.
- [toOklab](/docs/api/diorama-kit/to-oklab.md): OKLab (Björn Ottosson) of a linear sRGB colour, three's working space. Mixed in OKLab, two colours meet through a clean middle instead of a muddy grey.

## Types

- [ClientBox](/docs/api/diorama-kit/types/client-box.md): The box `toBox` measures from: its left and top edges in client px and its height.
- [FollowedPointer](/docs/api/diorama-kit/types/followed-pointer.md): The pointer `follow` tracks. Live: read it in the update.
- [FollowHandlers](/docs/api/diorama-kit/types/follow-handlers.md): Callbacks of `follow`. Each gets the pointer event; the pointer is already updated.
- [NoiseOptions](/docs/api/diorama-kit/types/noise-options.md): Options of `noise`.
- [Oklab](/docs/api/diorama-kit/types/oklab.md): A colour in OKLab: lightness, a, b.
