Appear
Appear animations: a mount animation a server renders as CSS, played from the first paint, before any code runs, which the engine takes over at mount from where it has got to. The DOM's half, for any binding:
- On a server:
keyframessamples an element's spec, its mount animation built with core's machines, into one@keyframesrule, cached across requests. A render'ssheetgives each element a slot, whoseanimationgoes in its inline style, and writes the head's<style>once every slot's timing is defined. - At mount:
findthe element's animation, check itmatchesthe client's own spec, start the runelapsedOfit in (Machine.startAt), andreleasethe element in the task that writes the engine's first frame. Elements that hydrate together read their page once, withfindAll, and each looks its own up in that read withfindIn. - A Batch's members (#706):
batchKeyframessamples one rule for every member on one set of transitions, each member's own values read from custom properties; a sheet'sbatchgives them one slot, and each member its style. At the Handoff,findAllreads every member's animation in one call, eachmatchesBatchthe client's key, and its change startselapsedOfit in (Batch.retarget'sstartAt).
import * as Appear from "@wardic/dom/Appear"
// On a server, a sheet a render:
const render = Appear.sheet()
const slot = render.slot()
slot.define({ spec, delay: 0 }) // `slot.animation` goes in the element's style, `render.css()` in the head
// At mount:
const elapsed = Option.map(Appear.find(element), Appear.elapsedOf)Interfaces
BatchKeyframes
A Batch's rule, and each member's own values for it.
Extends
Properties
css
readonly css: string;The rule, @keyframes <name>{…}.
Inherited from
duration
readonly duration: number;Seconds the rule plays, a multiple of 1/60 s: to the first Frame from which every one is within tolerance of the settled one.
Inherited from
infinite
readonly infinite: boolean;Whether it plays over and over.
Inherited from
memberStyle
readonly memberStyle: (member) => Readonly<Record<string, string>> | undefined;A member's own values as the custom properties the rule reads (--wardic-x1: 120px), by its index
in the spec; undefined for a member none of whose keys moves, which plays nothing.
Parameters
member
number
Returns
Readonly<Record<string, string>> | undefined
name
readonly name: string;The rule's name: wardic- and the spec's hash.
Inherited from
settled
readonly settled: number;Seconds to the Frame the spec settles at, which a client waits for: at or past duration.
Inherited from
supports
readonly supports: readonly string[];The SVG geometry properties its stops write (cx, r…), which some browsers don't draw from CSS: an
element playing it is defined under @supports for each, so a browser without them keeps it at its
starting style. Empty for most rules.
Inherited from
times
readonly times: readonly number[];The time of each stop kept, in seconds from the start.
Inherited from
BatchSlot
A Batch's members' place in a sheet: one slot for every member on one rule (#706).
Properties
styleOf
readonly styleOf: (member, delay) => Readonly<Record<string, string>> | undefined;A member's inline style, by its index in the rule's spec: its own values, and its animation, the slot
and, when it waits (its stagger), its delay after it. undefined for a member that doesn't move.
Parameters
member
number
delay
number
Returns
Readonly<Record<string, string>> | undefined
BatchSpec
A Batch's entrance, as its binding describes it: its members on one set of transitions, each with its own start and target. One rule plays them all, each member's own values read from custom properties on its element (#706).
Properties
key
readonly key: string;Its transitions, key by key, and whether motion is reduced, as one string the binding writes the same on the server and the client: the rule's name starts with its hash, which a client checks (matchesBatch) before it takes a member over.
keys
readonly keys: readonly string[];The Batch's keys, in its order: the DOM's transform keys and opacity.
starts
readonly starts: readonly (readonly number[])[];Each member's start, a number a key, in keys' order.
targets
readonly targets: readonly (readonly number[])[];Each member's target, as starts.
transition
readonly transition: Transitions;How its keys move, as Batch.make takes it.
Keyframes
A spec's @keyframes rule.
Extended by
Properties
css
readonly css: string;The rule, @keyframes <name>{…}.
duration
readonly duration: number;Seconds the rule plays, a multiple of 1/60 s: to the first Frame from which every one is within tolerance of the settled one.
infinite
readonly infinite: boolean;Whether it plays over and over.
name
readonly name: string;The rule's name: wardic- and the spec's hash.
settled
readonly settled: number;Seconds to the Frame the spec settles at, which a client waits for: at or past duration.
supports
readonly supports: readonly string[];The SVG geometry properties its stops write (cx, r…), which some browsers don't draw from CSS: an
element playing it is defined under @supports for each, so a browser without them keeps it at its
starting style. Empty for most rules.
times
readonly times: readonly number[];The time of each stop kept, in seconds from the start.
Play
Where an element's timing is decided: a spec, and the delay it starts after.
Properties
delay
readonly delay: number;Seconds before it starts: its orchestration's, and any delay on the whole element.
spec
readonly spec: Spec;The element's mount animation.
Sheet
One render's Appear rules: a slot per element, and the <style> text for the head and each late chunk.
Properties
batch
readonly batch: (play, reduced?) => BatchSlot;A slot for a Batch's members on play's rule, and under prefers-reduced-motion: reduce reduced's
when given (a provider's "user"): both rules, and the slot's :root lines naming each with no delay,
since each member gives its own.
Parameters
play
reduced?
Returns
css
readonly css: () => string;The CSS since the last call: each rule this render hasn't written yet, and the custom property of each slot defined since, the reduced ones under the media query. Called once for the head, and again for each chunk a stream sends after its shell, with only what that chunk adds.
Returns
string
slot
readonly slot: (name?) => Slot;A slot for the next element: named by the sheet's count, or by name under --wardic-a when the
binding names it (a Foldkit render names each by its element's path, the same on the server and the
hydration render, #794). A Batch's slot (batch) stays on the count, in the same namespace: a
binding naming slots keeps its names apart from the count's digits, or asks for no Batch rule.
Parameters
name?
string
Returns
Slot
One element's place in a sheet.
Properties
animation
readonly animation: string;The element's inline animation: var(--wardic-aN), which the sheet defines once define is called.
define
readonly define: (play, reduced?, supports?) => Result<void, string>;The element's timing: play, and under prefers-reduced-motion: reduce reduced when given
(a provider's "user"). Undefined until called, and left so when either spec has no rule: the
element keeps its Starting style. The reason comes back for the debug log.
Defined under @supports for the geometry properties its rules write and supports: a binding
passes the ones every element it orchestrates with writes, so a browser without them keeps the whole
group at its starting style, not half of it.
Parameters
play
reduced?
supports?
readonly string[]
Returns
Result<void, string>
Spec
An element's mount animation, as its binding describes it.
Properties
infinite?
readonly infinite?: boolean;Played over and over: an infinite repeat, machine one cycle of it.
key
readonly key: string;What built the animation, as one string the binding writes the same on the server and the client: its starting values, its targets, its transition, whether motion is reduced. The rule's name is its hash, so a client tells a Handoff it can continue from one it can't (decision 6).
machine
readonly machine: LazyArg<Machine<Frame<Values>>>;The animation's values from its start (for an infinite one, one cycle of it), built only when
the rule isn't cached: a server render calls it once per spec per process.
projected?
readonly projected?: boolean;A layout node: drawn through its projection at rest, as the client draws it, its own move on top.
tag
readonly tag: string | undefined;The element's tag, so an SVG element's keys go to its attributes; undefined for an HTML element.
template?
readonly template?: TransformTemplate;The element's transform template: each stop's transform drawn through it, as the client draws it. A function's text can't name a rule, so a templated spec's rule is named by its stops, and sampled for each element that has one, never cached.
Variables
CHUNK_ATTRIBUTE
const CHUNK_ATTRIBUTE: "data-wardic-appear-chunk" = "data-wardic-appear-chunk";The attribute a late chunk's <style> carries: a chunk a stream sends after its shell brings its own
rules, in a node its client doesn't render.
MAX_SECONDS
const MAX_SECONDS: 60 = 60;The longest mount animation sampled, in seconds; a longer one keeps its Starting style.
PREFIX
const PREFIX: "wardic-" = "wardic-";The prefix every Appear rule's name starts with.
Functions
adoptChunks()
function adoptChunks(doc): void;Moves each late chunk's Appear rules into the head: its <style data-wardic-appear-chunk>'s text into a
head <style>, then the node out, before the chunk hydrates, since a hydrating client expects no node it
doesn't render. The text goes first, so the rule a running animation plays is never missing. Chunks
already in the document move at once; while it's still loading, a stream still coming, a
MutationObserver moves each as it lands, until DOMContentLoaded. Every call moves what's there; one
observer a document.
Parameters
doc
Document
Returns
void
animationOf()
function animationOf(rule, delay): string;An element's animation value for a play of rule: its name, length, delay and repeat, filling
forwards. Not backwards: through its delay the element shows its inline starting style, which is the
rule's first stop for a rule that moves from it.
Parameters
rule
delay
number
Returns
string
batchKeyframes()
function batchKeyframes(spec): Result<BatchKeyframes, string>;A Batch's rule for its members' entrance, or why it has none: one @keyframes for every member, each
key's stops sampled from the Batch's own spring or tween at 60 Hz and thinned within its tolerance at
its longest move. A key whose start and target every member that moves shares is written as it is;
one whose values differ, as each member's custom properties and its progress between them.
Parameters
spec
Returns
Result<BatchKeyframes, string>
chunkStyle()
function chunkStyle(css, nonce?): string;A late chunk's <style> for css, as server text; "" for none. With a nonce, the one the page's
Content Security Policy gives inline styles, it carries it.
Parameters
css
string
nonce?
string
Returns
string
delayOf()
function delayOf(animation): number;The delay animation started after, in seconds: what its element's animation-delay holds.
Parameters
animation
Animation
Returns
number
elapsedOf()
function elapsedOf(animation): number;How far animation has got, in seconds since it started (its delay included): 0 before it has.
Parameters
animation
Animation
Returns
number
find()
function find(element): Option<Animation>;The element's Appear animation: its wardic-… CSS animation, running, or finished and filling. A
Batch's rule on a member's element isn't one (#706): its Batch takes it over, not a Wardic element there.
Parameters
element
Element
Returns
Option<Animation>
findAll()
function findAll(root): ReadonlyMap<Element, Animation>;A page's Appear animations by element, running or finished and filling: one getAnimations() for every
element on it, for a Handoff of many elements at once. Each element's first: a member's Batch rule, or
the one find gets. The page is a document, or a shadow root: a document's read doesn't reach into its
shadow trees, so an element there is in its own root's (element.getRootNode()).
Parameters
root
Document | ShadowRoot
Returns
ReadonlyMap<Element, Animation>
findIn()
function findIn(animations, element): Option<Animation>;The element's own Appear animation in a page's read (findAll's): the one find gets, with no read of
its own. A Batch's rule on a member's element isn't one.
Parameters
animations
ReadonlyMap<Element, Animation>
element
Element
Returns
Option<Animation>
keyframes()
function keyframes(spec): Result<Keyframes, string>;A spec's rule, or why it has none, for a debug log. Sampled once a spec and cached across requests by
its name, since a spec's rule changes only once the page registers every colour space
(Color.registerSpaces): a wide-gamut colour blends as written before, in sRGB after. Its name stays,
so a client matches it whatever it had registered. A templated spec's is sampled each time: its name
comes from its stops.
Parameters
spec
Returns
Result<Keyframes, string>
matches()
function matches(animation, spec): boolean;Whether animation is spec's: the rule the server sampled from the same spec.
Parameters
animation
Animation
spec
Pick<Spec, "key" | "tag" | "infinite" | "projected">
Returns
boolean
matchesBatch()
function matchesBatch(animation, key): boolean;Whether animation is a Batch rule for a spec's key: its name starts with the key's prefix, so the
server's transitions and reduced motion are the client's. Its members' values aren't checked (#706, Q9).
Parameters
animation
Animation
key
string
Returns
boolean
nameOf()
function nameOf(spec): string;The rule's name for a spec: its key, tag, repeat and projection, hashed.
Parameters
spec
Pick<Spec, "key" | "tag" | "infinite" | "projected">
Returns
string
pending()
function pending(element): boolean;Whether element's Appear animation is running, not yet handed over: its inline style still names its
slot, which release removes. A layout measure asks it of each node, so a running animation's
transform, which beats the inline one, stays out of the box it reads.
Parameters
element
ElementCSSInlineStyle
Returns
boolean
release()
function release(element): void;The handover's last step: the element's inline animation removed, in the task that writes the
engine's first frame, so no paint falls between. While it ran, its value beat the inline style the
engine writes; removing it ends the CSS animation at that task's style update.
Parameters
element
ElementCSSInlineStyle
Returns
void
sheet()
function sheet(): Sheet;A sheet for one render: a slot per element, and the CSS for the head.