WardicObject

Wardic for any object's properties: Motion's animate on plain objects (a three.js mesh's material, a camera, a uniforms object, a Canvas 2D sprite, a plain { x, y }), on frames the host pumps. One runtime per Host loop: make builds it, the host calls frame(time) once a frame before it renders, and dispose ends it.

  • Keys are an object's own properties, by name: animate(sprite, { x: 100 }) writes sprite.x. Each starts from the property's value when the animation starts. A key the object doesn't have, can't write, or whose value is neither a number nor a string, is an error at the call naming it, and the call takes nothing: what animated the other keys runs on.
  • Values are numbers, and strings with a unit or of numbers ("10px", "0 0 4px"). An array in a target is keyframes, as Motion's.
  • Transitions are Motion's by a key's name when a key gives none: a spring for a transform's (x, rotate, scale…), a 0.3 s ease for any other.
  • The controls are the DOM's: awaitable, with stop, cancel, complete, pause, play, speed, time and duration. A later animate of a key takes it over, keeping its velocity.
import * as WardicObject from "@wardic/object/WardicObject"

const wardic = WardicObject.make()
renderer.setAnimationLoop((time) => {
  wardic.frame(time)
  renderer.render(scene, camera)
})
await wardic.animate(material, { opacity: 0 }, { duration: 0.4 })

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

Interfaces

BatchSource

A Batch of something that isn't a list of Subjects, an InstancedMesh's instances: a handle per member, and how they're drawn and read.

Properties

members
readonly members: readonly object[];

Its members, in order: what the writer and the read are given for each.

read
readonly read: (subject, key) => unknown;

How it reads a member's key before the Batch moves it.

Parameters
subject

object

key

string

Returns

unknown

writer
readonly writer: Writer<object>;

How its members are drawn.


Environment

What an Environment of objects gives the runtime: how its Subjects are written and read, which of its keys are positional, how a Batch of them is drawn, and any Layers of its own. OBJECTS is plain objects'; @wardic/three gives three's.

Properties

batchRead
readonly batchRead: (subject, key) => unknown;

How a Batch reads a member's key before it moves it.

Parameters
subject

object

key

string

Returns

unknown

batchSource?
readonly batchSource?: (given) => BatchSource | undefined;

A Batch of given, something other than a list (an InstancedMesh): its members, drawn and read its own way. undefined for anything it doesn't make a Batch of.

Parameters
given

object

Returns

BatchSource | undefined

batchWriter
readonly batchWriter: Writer<object>;

How a Batch of its Subjects is drawn.

gate
readonly gate: GateEnvironment;

What its Flush gate reads of a Subject.

layers?
readonly layers?: Layer<never, never, never>;

Layers of its own, which win over the services make gives: its UnitScale, say, or a Default transition.

ownValues
readonly ownValues: Shape;

Its values in the shape of their targets.

positionalKeys
readonly positionalKeys: Layer<PositionalKeys>;

Which of its keys reduced motion snaps.

renderer
readonly renderer: Layer<Renderer>;

Its writer: Wardic's values onto a Subject, once a frame.

startLinksOf
readonly startLinksOf: (subject) => StartLinks;

A plain Subject's Base-value links: where each key it animates starts.

Parameters
subject

object

Returns

StartLinks


ObjectAnimate()

animate(subject, target, options?) animates an object, or each of a list of them, to target; animate(sequence, options?) plays a sequence. Either returns its Playback controls. Motion's. The options' transition takes an entry under any of the keys the Subject animates: a Batch's, its keys. A Subject whose keys are any name (an index signature) has its target checked key by key as given, though a misspelt key isn't caught, any name being one of its keys; naming its type, animate<T>(…), checks its keys as values only.

Call Signature

ObjectAnimate<T>(
   batch, 
   target, 
   options?
): WardicPlaybackControls;

animate(subject, target, options?) animates an object, or each of a list of them, to target; animate(sequence, options?) plays a sequence. Either returns its Playback controls. Motion's. The options' transition takes an entry under any of the keys the Subject animates: a Batch's, its keys. A Subject whose keys are any name (an index signature) has its target checked key by key as given, though a misspelt key isn't caught, any name being one of its keys; naming its type, animate<T>(…), checks its keys as values only.

Type Parameters
T

T extends object

Parameters
batch

| ObjectBatch<T, NumberKey<T>> | Member<T, NumberKey<T>>

target

Target<T>

options?

any

Returns

WardicPlaybackControls

Call Signature

ObjectAnimate<T, G>(
   subject, 
   target, 
   options?
): WardicPlaybackControls;

animate(subject, target, options?) animates an object, or each of a list of them, to target; animate(sequence, options?) plays a sequence. Either returns its Playback controls. Motion's. The options' transition takes an entry under any of the keys the Subject animates: a Batch's, its keys. A Subject whose keys are any name (an index signature) has its target checked key by key as given, though a misspelt key isn't caught, any name being one of its keys; naming its type, animate<T>(…), checks its keys as values only.

Type Parameters
T

T extends Readonly<Record<string, unknown>>

G

G extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>

Parameters
subject

T

target

| ObjectTarget<T> | AnyKeyTargetFor<T, G>

options?

any

Returns

WardicPlaybackControls

Call Signature

ObjectAnimate(sequence, options?): WardicPlaybackControls;

animate(subject, target, options?) animates an object, or each of a list of them, to target; animate(sequence, options?) plays a sequence. Either returns its Playback controls. Motion's. The options' transition takes an entry under any of the keys the Subject animates: a Batch's, its keys. A Subject whose keys are any name (an index signature) has its target checked key by key as given, though a misspelt key isn't caught, any name being one of its keys; naming its type, animate<T>(…), checks its keys as values only.

Parameters
sequence

ObjectSequence

options?

any

Returns

WardicPlaybackControls

Call Signature

ObjectAnimate<T, G>(
   subject, 
   target, 
   options?
): WardicPlaybackControls;

animate(subject, target, options?) animates an object, or each of a list of them, to target; animate(sequence, options?) plays a sequence. Either returns its Playback controls. Motion's. The options' transition takes an entry under any of the keys the Subject animates: a Batch's, its keys. A Subject whose keys are any name (an index signature) has its target checked key by key as given, though a misspelt key isn't caught, any name being one of its keys; naming its type, animate<T>(…), checks its keys as values only.

Type Parameters
T

T extends object

G

G extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>

Parameters
subject

T | readonly T[]

target

| ObjectTarget<T> | AnyKeyTargetFor<T, G>

options?

any

Returns

WardicPlaybackControls


Options

A runtime's options.

Properties

now?
readonly now?: () => number;

The host's steady clock on its frames' timebase: performance.now() when left out.

Returns

number

reducedMotion?
readonly reducedMotion?: any;

Whether reduced motion applies ("user", the default: the user's preference where the host reports one, through matchMedia, else never; "always"; "never"). Under it, a transform's keys (x, rotate, scale…) snap to their targets after their delay, and other keys animate.

registry?
readonly registry?: AtomRegistry;

The AtomRegistry Live values are shared through: the page's, so a DOM value can drive an object's.

skipAnimations?
readonly skipAnimations?: boolean;

Land every animation on its next frame: for tests and screenshots, and a user who turned motion off.


StageEnvironment

What a binding's ward runs on, to move this runtime's Subjects as a ward moves an element: what animate runs on, where a Subject starts, and its Frame effects. Unstable: for @wardic/solid's Stage ward and the Stages built on it.

Extends

  • unknown

Properties

frameEffects
readonly frameEffects: Pick<FrameEffects.FrameEffects, "add" | "request">;

Its Frame effects: what afterWrites adds to, and how one asks for a frame.

startLinksOf
readonly startLinksOf: (subject) => StartLinks;

Where each key of a Subject starts: its Environment's Base-value links.

Parameters
subject

object

Returns

StartLinks


WardicObject

A runtime: what animates objects on one Host loop.

Properties

afterWrites
readonly afterWrites: (effect) => () => void;

Run effect at the end of each frame from now on, after Wardic's writes for it and the effects added before it, with the frame's time in ms: an app's own code before the render. Returns its remover.

Parameters
effect

(time) => void

Returns

() => void

animate
readonly animate: ObjectAnimate;
batch
readonly batch: <T>(objects, options?) => ObjectBatch<T>;

A Batch of objects: one run for all of them, on the keys of its first animate (or keys). animate(batch, target) moves every member; animate(batch.at(i), target) member i.

Type Parameters
T

T extends object

Parameters
objects

readonly T[]

options?

Options<T, NumberKey<T>>

Returns

ObjectBatch<T>

dispose
readonly dispose: () => void;

Stop every animation, and end the runtime.

Returns

void

frame
readonly frame: (time) => void;

Run the frame, time in ms: Wardic's writes for it, then afterWrites' effects. Call it once a frame, before rendering.

Parameters
time

number

Returns

void

stageEnvironment
readonly stageEnvironment: StageEnvironment;

What a binding's ward runs on, for this runtime's Subjects. Unstable: @wardic/solid's Stage ward's.

wantsFrame
readonly wantsFrame: () => boolean;

Whether Wardic wants another frame: what a loop that draws on demand checks to go on.

Returns

boolean

Type Aliases

AnimatableKey

type AnimatableKey<T> = [T] extends [ReadonlyArray<unknown>] ? never : Exclude<{ readonly [K in keyof T]-?: [Defined<T[K]>] extends [never] ? never : Defined<T[K]> extends number | string ? KeyName<K> : never }[keyof T], TypedArrayOwnKey<T>>;

A key of T Wardic animates, by name: one whose value is a number or a string. An optional one among them: animate throws if the object lacks it when called. A numeric key by its name too, as "0", a number index's as `${number}`: a typed array's elements, not its own numbers (length, byteLength, byteOffset, BYTES_PER_ELEMENT), which it can't write. An array has none: a list is many Subjects.

Type Parameters

T

T


ObjectBatchSegment

type ObjectBatchSegment = 
  | readonly [batch: 
  | ObjectBatch<any, any>
  | Member<any, any>, target: Readonly<Record<string, SegmentValue>>]
  | readonly [batch: 
  | ObjectBatch<any, any>
  | Member<any, any>, target: Readonly<Record<string, SegmentValue>>, options: Imperative.WardicSegmentOptions];

A Segment of a Batch, [batch, target, options?]: every member, or a member's handle, batch.at(i).


ObjectSegment

type ObjectSegment = 
  | readonly [subject: object | ReadonlyArray<object>, target: Readonly<Record<string, number | string | Config.WardicKeyframes<number | string>>>]
  | readonly [subject: object | ReadonlyArray<object>, target: Readonly<Record<string, number | string | Config.WardicKeyframes<number | string>>>, options: Imperative.WardicSegmentOptions];

A Segment of objects, [subject, target, options?]: an object, or a list of them. Motion's.


ObjectSequence

type ObjectSequence = ReadonlyArray<
  | Imperative.WardicSequenceLabel
  | ObjectSegment
  | ObjectBatchSegment
| Imperative.WardicFunctionSegment>;

A sequence of objects: Segments of objects and of Batches, function Segments and labels. Motion's AnimationSequence.


ObjectTarget

type ObjectTarget<T> = [T] extends [ReadonlyArray<unknown>] ? NotOneSubject : { readonly [K in AnimatableKey<T> as TargetKey<K>]?: ValueAt<T, K> } & object;

A target for T: each of its animatable keys a value or keyframes, never undefined (an optional key's too), a numeric key by its index (a typed array's element, { 0: 1 }); a transition, with an entry under any of those keys, which animate's options are laid over field by field; and a Transition end, its values set once the object lands. An array has none that fits: animate reads one as a list of Subjects, or a sequence, never as one Subject.

Type Parameters

T

T

Variables

OBJECTS

const OBJECTS: Environment;

Plain objects' Environment: each key the object's own property.

Functions

layer()

function layer(
   frames, 
   options?, 
   environment?
): Layer<WardicServices>;

The Environment's services, on frames: the Effect form, for an app that runs Wardic's Effects itself. make builds its runtime on it; environment is plain objects' unless given.

Parameters

frames

PumpedFrames

options?

Options = {}

environment?

Environment = OBJECTS

Returns

Layer<WardicServices>


make()

function make(options?): WardicObject;

A runtime on frames the host pumps, for plain objects: frame(time) once a frame, before it renders.

Parameters

options?

Options = {}

Returns

WardicObject


makeWith()

function makeWith(environment, options?): WardicObject;

A runtime on frames the host pumps, for environment's objects: what @wardic/three builds on.

Parameters

environment

Environment

options?

Options = {}

Returns

WardicObject