Wardic
Wardic for Foldkit (ADR-0071, #561): a Handle made once per program with make, whose
html(h) gives a view the builder w. A w.* element takes Foldkit's attributes and Wardic's
(w.Initial, w.Animate, w.Transition, w.Style), animates its Animate target from Initial
as it mounts, Retargets on a render that changes its target and holds through one that doesn't. The
first w.* element to mount builds Wardic's services on the Handle's env, which every element
shares until the last has left; w.Provider(options) on the w.* element at the top names the root
the subtree options hang on.
Example
// src/lib/wardic.ts
import { DomLive } from "@wardic/dom"
import * as Wardic from "@wardic/foldkit/Wardic"
export const wardic = Wardic.make({ env: DomLive })
// src/view.ts
const view = (model: Model, h: HtmlBuilder<Message>): Html => {
const w = wardic.html(h)
return w.div([h.Class("app")], [
w.div([h.Class("card"), w.Initial({ opacity: 0, y: 8 }), w.Animate({ opacity: 1, y: 0 }), w.Transition({ duration: 0.3 })], [model.title]),
])
}Its exports also name types the module doesn't export: its internal types.
Classes
AnimationFailed
animate found nothing to animate: a selector matching no element under the root, or an empty list.
Extends
YieldableError<this> &object&Readonly<{subject:string; }>
Constructors
Constructor
new AnimationFailed(args): AnimationFailed;Parameters
args
subject
string
Returns
Inherited from
Data.TaggedError("AnimationFailed")<{ readonly subject: string }>.constructor
Properties
subject
readonly subject: string;Inherited from
Data.TaggedError("AnimationFailed").subject
LayoutFailed
animateLayout found no layout to animate: the Handle has no layout Feature (Features.layout).
Extends
YieldableError<this> &object&Readonly<{reason:"no-layout-feature"; }>
Constructors
Constructor
new LayoutFailed(args): LayoutFailed;Parameters
args
reason
"no-layout-feature"
Returns
Inherited from
Data.TaggedError("LayoutFailed")<{ readonly reason: "no-layout-feature" }>.constructor
Properties
reason
readonly reason: "no-layout-feature";Inherited from
Data.TaggedError("LayoutFailed").reason
ScrollFailed
scroll found no scroll to read: the Handle wasn't given Features.scroll, or a load of it hasn't arrived.
Extends
YieldableError<this> &object&Readonly<{reason:"no-scroll-feature"; }>
Constructors
Constructor
new ScrollFailed(args): ScrollFailed;Parameters
args
reason
"no-scroll-feature"
Returns
Inherited from
Data.TaggedError("ScrollFailed")<{ readonly reason: "no-scroll-feature" }>.constructor
Properties
reason
readonly reason: "no-scroll-feature";Inherited from
Data.TaggedError("ScrollFailed").reason
Wardic
The Wardic service: a program's Handle, which wardic.resources gives its Commands.
Extends
Interfaces
Handle
A Handle: one Wardic runtime inside a Foldkit program (ADR-0071, decision 9), typed by its
Features F. Made once, at module scope.
Type Parameters
F
F = never
Properties
[HANDLE]
readonly [HANDLE]: true;The Handle's mark: what the Wardic service carries.
Element
readonly Element: MountAction<never>;An element's raw Mount, for a Scene test to resolve by name (decision 36): one per w.* element in the view.
html
readonly html: <Message>(h) => Html<Message, F>;The builder w for a view's h, made once per h.
Type Parameters
Message
Message
Parameters
h
HtmlBuilder<Message>
Returns
Html<Message, F>
hydrate
readonly hydrate: <P, Flags, Resources>(program, options?) => void;Foldkit's Runtime.hydrate, for a page its experimental/server's renderToString rendered: the
client entry calls this instead. It moves the Appear animations' rules the Provider element
rendered into the head, and has the hydration render keep each element's running animation, which
its mount takes over where the CSS has got (the Handoff); then Foldkit adopts the page.
Experimental
Starts a Foldkit runtime by adopting a server-rendered DOM in place instead
of building it fresh. Use this as the client entry for a page served by
renderToString: the first render attaches to the stamped root, keeps the
existing nodes, and reconstructs the Model from the Flags the server
embedded. The handoff is strict: a missing server root, an empty or
duplicated root stamp, more than one stamped root, a requested root outside
the document body light DOM, a missing Flags payload, an undecodable
payload, or a page from another deployment terminates startup. Every one of
those contains the page first:
the document's body is marked inert and a nondismissable modal shield is
opened above existing top-layer content, so pointer and physical keyboard
input do not activate same-document native links, forms, or controls.
Containment leaves author-owned dialogs open without calling close or
dispatching cancel.
Nothing is moved, so no custom element reconnects and no frame reloads.
This is not a script, event, or embedded-document sandbox: existing
capture-phase handlers, browser-generated top-layer events, timers, and
stale scripts can still run. Controls in embedded documents can still
receive input if stale code focuses them. Stale code can also open newer
top-layer UI. Use run in a separate client-only entry when the page should
boot without server output.
Server rendering and hydration are experimental while their contracts settle.
Type Parameters
P
P extends
| Readonly<{
}>
| undefined
Flags
Flags
Resources
Resources
Parameters
program
MakeRuntimeReturn<P, Flags, Resources, "Application">
options?
Readonly<{
}>
Returns
void
Presence
readonly Presence: MountAction<never>;A w.Presence element's raw Mount, for a Scene test to resolve by name (#792, Q19).
Provider
readonly Provider: MountAction<never>;The provider's raw Mount, for a Scene test to resolve by name (decision 36): Scene.Mount.resolve(wardic.Provider, Done()).
Reorder
readonly Reorder: MountAction<never>;A w.ReorderGroup element's raw Mount, for a Scene test to resolve by name (#793, Q18); its items stay Element.
resources
readonly resources: Layer<Wardic>;The Layer a program's resources takes (decision 9): its Commands then run Wardic.animate,
Wardic.animateLayout and Wardic.provide, which need the Wardic service, this Handle.
viewTransition
readonly viewTransition: <Model, Message>(decide) => ViewTransitionConfig<Model, Message>;The app's viewTransition predicate, wrapped (decision 33): Runtime.makeElement({ viewTransition: wardic.viewTransition(decide) }). In a render decide transitions, layout moves and layoutId
handovers land at once, for the View Transition's morph to carry; the decision passes through
unchanged, and where the document has no startViewTransition Wardic animates them itself.
Type Parameters
Model
Model
Message
Message
Parameters
decide
ViewTransitionConfig<Model, Message>
Returns
ViewTransitionConfig<Model, Message>
MakeOptions
What make takes.
Type Parameters
F
F
Properties
appear?
readonly appear?: boolean | "explain";Appear animations on a server: on by default, under w.Provider(), whose element renders their
rules; false renders none; "explain" says, at Warning, why each element that doesn't play waits
for the JavaScript.
config?
readonly config?: ConfigOptions;The app-wide settings (ADR-0062; ADR-0071 decision 22): what w.Config(…) takes, under every subtree's.
env
readonly env: WardicEnv;Wardic's Environment: @wardic/dom's DomLive in a browser. Required, as a Solid provider's env is (#791, Q1).
features?
readonly features?: F;The Features its elements have (#511, ADR-0067 Amendment (#516)): given at once, or loads
(() => import(…)), as Solid's createWardic takes them. Without any, the base props alone: a
gesture or layout attribute is then a type error naming its Feature (from slice 3 on).
layoutAttributes?
readonly layoutAttributes?: readonly string[];Attributes the observer watches beside class and hidden (decision 30): those the app's CSS lays out by.
layoutTrigger?
readonly layoutTrigger?: "patch" | "declared";What runs a Measure pass (decision 30; #792, Q10 and Q17): "patch" (the default), a pass after
every patch that changed the DOM, found by a MutationObserver on the w.Provider() element, else
the document's body; "declared", only a w.LayoutDependency change and Wardic.animateLayout.
nonce?
readonly nonce?: string;The nonce the page's Content Security Policy gives inline styles: the rules' <style> carries it.
Type Aliases
AnimateLayoutOptions
type AnimateLayoutOptions = Omit<ProjectionSystem.AnimateLayoutOptions, "onSettled">;What animateLayout takes: dom's options, less onSettled, which the Effect's success is.
AnimateOptions
type AnimateOptions = Imperative.WardicAnimateOptions & Scoped;What animate takes with a subject: dom's options, less onComplete, which the Effect's success is, and the Animation scope its selectors resolve under.
AnimationEnd
type AnimationEnd = Imperative.WardicAnimationEnd;What animate ends with: whether every key landed, or a later animation took its keys.
ArcOptions
type ArcOptions = Arc.Options;arc()'s options (Motion's ArcOptions): strength, peak, direction and rotate, core's.
ElementFunction
type ElementFunction<Message> = (attributes, children?) => FoldkitHtml.Html;A w.* element's function: h.div's shape, taking Wardic's attributes too.
Type Parameters
Message
Message
Parameters
attributes
Attributes<Message>
children?
ReadonlyArray<Child>
Returns
FoldkitHtml.Html
Html
type Html<Message, F> = { readonly [Tag in FoldkitHtml.TagName]: ElementFunction<Message> } & Readonly<{
[FEATURES]?: F;
Animate: (value) => Attribute;
AnimationScope: (scope) => Attribute;
Appear: (value) => Attribute;
attributes: (bundle) => ReadonlyArray<FoldkitHtml.Attribute<Message> | FoldkitHtml.ChildAttribute>;
Config: (options) => Attribute;
Custom: (value) => Attribute;
Drag: Needs<F, "drag", (value?) => Attribute>;
DragConstraints: Needs<F, "drag", (value) => Attribute>;
DragControls: Needs<F, "drag", (controls) => Attribute>;
DragDirectionLock: Needs<F, "drag", (value?) => Attribute>;
DragElastic: Needs<F, "drag", (value) => Attribute>;
DragListener: Needs<F, "drag", (value) => Attribute>;
DragMomentum: Needs<F, "drag", (value) => Attribute>;
DragPropagation: Needs<F, "drag", (value?) => Attribute>;
DragSnapToOrigin: Needs<F, "drag", (value?) => Attribute>;
DragTransition: Needs<F, "drag", (value) => Attribute>;
Exit: (value) => Attribute;
Inherit: (value) => Attribute;
Initial: (value) => Attribute;
keyed: (tag) => (key, attributes, children?) => FoldkitHtml.Html;
Layout: Needs<F, "layout", (value?) => Attribute>;
LayoutCrossfade: Needs<F, "layout", (value?) => Attribute>;
LayoutDependency: Needs<F, "layout", (value) => Attribute>;
LayoutGroup: Needs<F, "layout", (options?) => Attribute>;
LayoutId: Needs<F, "layout", (id) => Attribute>;
LayoutRoot: Needs<F, "layout", (value?) => Attribute>;
LayoutScroll: Needs<F, "layout", (value?) => Attribute>;
OnAnimationComplete: (handler) => Attribute;
OnAnimationStart: (handler) => Attribute;
OnBeforeLayoutMeasure: Needs<F, "layout", (fn) => Attribute>;
OnDirectionLock: Needs<F, "drag", (handler) => Attribute>;
OnDrag: Needs<F, "drag", (handler) => Attribute>;
OnDragEnd: Needs<F, "drag", (handler) => Attribute>;
OnDragStart: Needs<F, "drag", (handler) => Attribute>;
OnDragTransitionEnd: Needs<F, "drag", (handler) => Attribute>;
OnHoverEnd: Needs<F, "hover", (handler) => Attribute>;
OnHoverStart: Needs<F, "hover", (handler) => Attribute>;
OnLayoutAnimationComplete: Needs<F, "layout", (handler) => Attribute>;
OnLayoutAnimationStart: Needs<F, "layout", (handler) => Attribute>;
OnLayoutMeasure: Needs<F, "layout", (fn) => Attribute>;
OnMeasureDragConstraints: Needs<F, "drag", (fn) => Attribute>;
OnPan: Needs<F, "pan", (handler) => Attribute>;
OnPanEnd: Needs<F, "pan", (handler) => Attribute>;
OnPanSessionStart: Needs<F, "pan", (handler) => Attribute>;
OnPanStart: Needs<F, "pan", (handler) => Attribute>;
OnTap: Needs<F, "press", (handler) => Attribute>;
OnTapCancel: Needs<F, "press", (handler) => Attribute>;
OnTapStart: Needs<F, "press", (handler) => Attribute>;
OnUpdate: (atom) => Attribute;
OnViewportEnter: Needs<F, "inView", (handler) => Attribute>;
OnViewportLeave: Needs<F, "inView", (handler) => Attribute>;
Presence: (options?) => Attribute;
Propagate: Needs<F, "press", (options) => Attribute>;
Provider: (options?) => Attribute;
ReorderGroup: Needs<F, "layout", Needs<F, "drag", <V>(options) => Attribute>>;
ReorderItem: Needs<F, "layout", Needs<F, "drag", (value) => Attribute>>;
StartsDrag: Needs<F, "drag", (controls, options?) => Attribute>;
Style: (value) => Attribute;
Text: (atom) => Attribute;
TransformTemplate: (template) => Attribute;
Transition: (value) => Attribute;
Variants: (value) => Attribute;
Viewport: Needs<F, "inView", (options) => Attribute>;
WhileDrag: Needs<F, "drag", (value) => Attribute>;
WhileFocus: Needs<F, "focus", (value) => Attribute>;
WhileHover: Needs<F, "hover", (value) => Attribute>;
WhileInView: Needs<F, "inView", (value) => Attribute>;
WhileTap: Needs<F, "press", (value) => Attribute>;
}>;The builder w of wardic.html(h): h's element factories, each taking Wardic's attributes beside
Foldkit's; keyed; the attributes bundle, for an element w doesn't make (a custom element, a
component library's); and Wardic's attribute factories. Foldkit's own attributes stay on h.
Type Parameters
Message
Message
F
F = never
PointerOptions
type PointerOptions = DomPointer.Options;What pointer takes: the pointer types that count, a mouse and a pen unless given.
PointerValues
type PointerValues = DomPointer.PointerValues;What pointer gives: the pointer's place in the element's pixels, its progress across the element's box, the box's size, and whether it's inside, each an Atom.
ScrollOptions
type ScrollOptions = ScrollSource.Options;What scroll takes: Motion's useScroll options, the container and target as elements.
Sequence
type Sequence = ReadonlyArray<Exclude<Imperative.WardicSegment, Imperative.WardicBatchSegment>>;A sequence (Motion's animate(sequence)): Segments of elements, function Segments and labels, laid out in time. No Batch Segment: Foldkit has no Batch.
SequenceOptions
type SequenceOptions = Imperative.WardicSequenceOptions & Scoped;What animate takes with a sequence: dom's options, less onComplete, which the Effect's success is, and the scope.
StaggerOptions
type StaggerOptions = Stagger.Options;stagger(duration, options)'s options (#436, Motion's stagger): startDelay, from and ease, core's.
Variables
animate
const animate: Animate;animate (above): the form told by what it's given, as dom's own animate tells it.
animateLayout
const animateLayout: (options?) => Effect.Effect<void, LayoutFailed, Wardic>;A Declared layout change (ADR-0071, decision 26; ADR-0038; Motion's animateLayout): what a
Command runs after the Model change that moved the layout elements, under either trigger, and the
only trigger beside w.LayoutDependency under layoutTrigger: "declared". It waits for the
render's commit (Foldkit's Render.afterCommit), then asks for a Measure pass from the boxes the
last pass kept (from: "lastPass", the default: the change is on the page by then), and succeeds
once every layout animation the pass started has ended, at once if none. Fails with
LayoutFailed when the Handle has no layout Feature. Wrap it in Command.define, with
resources: wardic.resources on the program.
Parameters
options?
Returns
Effect.Effect<void, LayoutFailed, Wardic>
provide
const provide: <A, E, R>(effect) => Effect.Effect<A, E,
| Exclude<R, Feature.ProviderServices>
| Wardic
| Scope.Scope>;effect run on the Provider's services (ADR-0071, the grill's Q23): how a Command makes a derived
Live value (LiveValue.spring, follow, velocity, scroll). The Scope is the caller's: a
ManagedResource's acquire, whose Scope Foldkit closes when its Model condition drops, or an
Effect.scoped that ends with the Command. The Provider is held while that Scope lives.
Type Parameters
A
A
E
E
R
R
Parameters
effect
Effect.Effect<A, E, R>
Returns
Effect.Effect<A, E,
| Exclude<R, Feature.ProviderServices>
| Wardic
| Scope.Scope>
scroll
const scroll: (options?) => Effect.Effect<LiveValue.ScrollValues, ScrollFailed, Wardic | Scope.Scope>;A container's scroll as Live values (Motion's useScroll): how far it's scrolled on each axis,
and the progress through its range, or through the offsets a target passes, each an Atom a view
binds, set within the scroll's own event. Its listeners are held while the caller's Scope lives, as
a Live value made under provide is. Fails with ScrollFailed when the Handle has no scroll
Feature: name it, Wardic.make({ env, features: [Features.scroll] }).
Parameters
options?
Returns
Effect.Effect<LiveValue.ScrollValues, ScrollFailed, Wardic | Scope.Scope>
Functions
arc()
function arc(options?): WardicPath;A curved path for a transition's path (Motion's arc()): x and y travel along a curve between
where they start and their target, on x's transition, in place of two straight lines. Make it once,
at module scope: with no direction, it remembers which side of the screen it bulged to.
Parameters
options?
Options = {}
Returns
WardicPath
Example
const toss = arc({ strength: 0.4 })
w.img([w.LayoutId("photo"), w.Transition({ layout: { type: "tween", duration: 0.6, path: toss } })])make()
function make<F>(options): Handle<F>;Makes a Handle on env, with features (above). One per program, at module scope: a second
w.Provider() for it while the first's element is mounted is reported and ignored.
Type Parameters
F
F extends InstanceFeaturesProp = never
Parameters
options
MakeOptions<F>
Returns
Handle<F>
pointer()
function pointer(element, options?): Effect<PointerValues, never, Wardic | Scope>;The pointer over an element as Live values: where it is in the element's pixels, from the box's
top left; its progress across the box, from 0 to 1 each way; the box's size; and whether it's
inside, each an Atom a view binds, set within the pointer's own events (pointerenter,
pointermove, pointerdown, pointerleave). A leave keeps the place: what returns to rest with
it is a derived Atom over inside. Its listeners are held while the caller's Scope lives, as a
Live value made under provide is. A mouse and a pen count unless types says; a finger never
hovers. Plain pointer events, not the hover gesture: no Feature to name, nothing to fail.
Parameters
element
Element
options?
any
Returns
Effect<PointerValues, never, Wardic | Scope>
stagger()
function stagger(duration?, options?): WardicStagger;A stagger for a transition's delayChildren, or an animate's delay (Motion's stagger): duration
seconds between children, from options.from, after options.startDelay.
Parameters
duration?
number = 0.1
options?
Options = {}
Returns
WardicStagger
References
correctParentTransform
Renames and re-exports layout
ElementGiven
Renames and re-exports layout
transformViewBoxPoint
Renames and re-exports layout