InterpolatorRegistry

The registry of value kinds: given two values, it finds the kind that blends them and returns the blend each frame calls. An Environment builds one over core's kinds and its own (make, or layer for core's alone), and adds Key rules, which blend a key by its name, as @wardic/dom's keep a key that hides an element at its old value until an animation's last frame. A binding resolves each pair once, as it builds an animation.

import * as InterpolatorRegistry from "@wardic/core/InterpolatorRegistry"

const registry = yield* InterpolatorRegistry.InterpolatorRegistry
const blend = yield* registry.resolve("0px", "120px")
blend(0.5) // "60px"

Its exports also name types the module doesn't export: its internal types.

Classes

InterpolatorRegistry

The registry of value kinds: a pair of values in, and out the blend each frame calls. A new kind is added by registering it, with no change to the engine.

Extends

  • Context.Service

Properties

forget
readonly forget: Effect<void>;

Forgets every pair resolved so far, so a pair resolves again when next asked: for when a kind now reads what it didn't, as @wardic/dom's colours do once an app registers more colour spaces.

interpolate
readonly interpolate: <From, To>(from, to, t) => Effect<From | To>;

resolve applied at t, once: for a one-off value. It reads both values each call.

Type Parameters
From

From

To

To

Parameters
from

From

to

To

t

number

Returns

Effect<From | To>

keyBlendOf
readonly keyBlendOf: (key, from, to) => Option<Effect<KeyBlend, never, never>>;

The blend of the first Key rule, latest registered first, that takes key's pair: the Effect that builds it. None when every rule declines: the pair blends by value, through resolve. Synchronous: it's asked once per key each time a leg is built.

Parameters
key

string

from

string | number

to

string | number

Returns

Option<Effect<KeyBlend, never, never>>

register
readonly register: <Decoded, Encoded>(entry) => Effect<void>;

Adds a kind, ahead of those already registered.

Type Parameters
Decoded

Decoded

Encoded

Encoded

Parameters
entry

Entry<Decoded, Encoded>

Returns

Effect<void>

registerKeyRule
readonly registerKeyRule: (rule) => Effect<void>;

Adds a Key rule, ahead of those already registered.

Parameters
rule

KeyRule

Returns

Effect<void>

resolve
readonly resolve: <From, To>(from, to) => Effect<(t) => From | To>;

The blend for from and to: the first kind that reads both, once, and the function each frame calls with its progress. A pair no kind blends switches to to at the first frame, with a warning.

Type Parameters
From

From

To

To

Parameters
from

From

to

To

Returns

Effect<(t) => From | To>

Interfaces

KeyRule

An Environment's Key rule: how one key's pair blends, picked by the key's name, as @wardic/dom's keep a key that hides an element at its old value until an animation's last frame. Core holds none: which keys need one is the Environment's to know. Most hold for the whole Environment (make, registerKeyRule); one that reads an element is added for that element's animations with withKeyRules.

Properties

blend
readonly blend: (key, from, to, resolve, next) => Option<Effect<KeyBlend, never, never>>;

Whether it takes key's pair: None to decline, at once and allocating nothing, or the Effect that builds the key's blend, which may resolve pairs by value through resolve, or hand a pair on to the rules after it through next.

Parameters
key

string

from

string | number

to

string | number

resolve

ResolveByValue

next

NextKeyBlend

Returns

Option<Effect<KeyBlend, never, never>>

name
readonly name: string;

Its name, for a warning or a trace.

Type Aliases

KeyBlend

type KeyBlend = (t, done) => number | string;

A key's blend for a whole animation: its value at progress t, given whether that's the run's last frame. What a Key rule returns.

Parameters

t

number

done

boolean

Returns

number | string


KeyBlendOf

type KeyBlendOf = (key, from, to) => Option.Option<Effect.Effect<KeyBlend>>;

The first Key rule's blend for a key's pair, or None: keyBlendOf's shape.

Parameters

key

string

from

number | string

to

number | string

Returns

Option.Option<Effect.Effect<KeyBlend>>


NextKeyBlend

type NextKeyBlend = (key, from, to) => Effect.Effect<KeyBlend>;

A key's pair as the rules after one rule, then the kinds, blend it: what a rule that rewrites a pair hands it on to, so the rules after it still apply. A rule that reads a value from elsewhere, as @wardic/dom's for an element's own variables, resolves it, then blends what it resolved to through next, so the key's other rules still apply to it.

Parameters

key

string

from

number | string

to

number | string

Returns

Effect.Effect<KeyBlend>


ResolveByValue

type ResolveByValue = <From, To>(from, to) => Effect.Effect<(t) => From | To>;

Resolve a pair by value: the registry's resolve, which a Key rule calls for the pairs it blends.

Type Parameters

From

From

To

To

Parameters

from

From

to

To

Returns

Effect.Effect<(t) => From | To>

Variables

layer

const layer: Layer.Layer<InterpolatorRegistry>;

The InterpolatorRegistry pre-loaded with core's built-in interpolators (Interpolator.defaults) and no Key rules.


withKeyRules

const withKeyRules: {
  (rules): <A, E, R>(self) => Effect<A, E, InterpolatorRegistry | R>;
  <A, E, R>(self, rules): Effect<A, E, InterpolatorRegistry | R>;
};

self run with rules asked first, ahead of the registry's own Key rules, for that run alone: how a binding adds a rule bound to one element, as @wardic/dom's for its own variables, to that element's animations. Each rule's next is the rules after it, then the registry's, then by value. The registry itself is unchanged, so one element's rule never reaches another's.

Call Signature

(rules): <A, E, R>(self) => Effect<A, E, InterpolatorRegistry | R>;
Parameters
rules

readonly KeyRule[]

Returns

<A, E, R>(self) => Effect<A, E, InterpolatorRegistry | R>

Call Signature

<A, E, R>(self, rules): Effect<A, E, InterpolatorRegistry | R>;
Type Parameters
A

A

E

E

R

R

Parameters
self

Effect<A, E, R>

rules

readonly KeyRule[]

Returns

Effect<A, E, InterpolatorRegistry | R>

Example

yield* buildLegs.pipe(InterpolatorRegistry.withKeyRules([ruleOf(element)]))

Functions

make()

function make(initial?, keyRules?): Effect<{
  forget: Effect<void, never, never>;
  interpolate: <From, To>(from, to, t) => Effect<From | To>;
  keyBlendOf: (key, from, to) => Option<Effect<KeyBlend, never, never>>;
  register: <Decoded, Encoded>(...args) => Effect<void, never, never>;
  registerKeyRule: (...args) => Effect<void, never, never>;
  resolve: <From, To>(from, to) => Effect<Blend<From, To>>;
}, never, never>;

A registry over initial, core's kinds by default, and keyRules, each in precedence order: the first that takes a pair wins, and register and registerKeyRule add ahead. A pair is resolved by the first kind that reads both of it, once; a pair of strings is resolved once per registry and kept.

Parameters

initial?

readonly Entry<any, any>[] = Interpolator.defaults

keyRules?

readonly KeyRule[] = []

Returns

Effect<{ forget: Effect<void, never, never>; interpolate: <From, To>(from, to, t) => Effect<From | To>; keyBlendOf: (key, from, to) => Option<Effect<KeyBlend, never, never>>; register: <Decoded, Encoded>(...args) => Effect<void, never, never>; registerKeyRule: (...args) => Effect<void, never, never>; resolve: <From, To>(from, to) => Effect<Blend<From, To>>; }, never, never>

Example

const registry = yield* InterpolatorRegistry.make([colors, ...Interpolator.defaults], displayRules)