WardicStage

The context a scene's Stage is found through. A Stage runs a scene for its owner: its Host loop, its input and its canvas's size. Under one, the hooks run in its scene instead of on the page:

import { ward, WardicStage } from "@wardic/solid"

<WardicStage value={stage}>
  <Crate mesh={crate} />
</WardicStage>

function Crate(props: { readonly mesh: Mesh }) {
  const crate = ward(props.mesh, { whileHover: { scale: 1.08 } })
  return crate.held
}
  • ward(subject, config) hands the Stage a Subject that's its own, and any accessor of one: the Stage's ward moves it, and has the same events and read a ward on an element has.
  • createFrameEffect runs in the Stage's Host loop, after Wardic's writes and before the scene renders.
  • createHover(mesh) and createPress(mesh) read the pointer over the Subject, and pressed on it, through the Stage's input.
  • An element stays the page's, under a Stage or not.

A scene's hooks alone

ward, createBatch and the sensors take a page's element as well as a scene's object, so each brings the page's half with it. For ward, that's the page's ward and every Feature, 57.6 KB gzipped, in an app that may have no page wards at all. Their Stage halves are exported apart, taking only what the Stage above takes:

HookIts Stage half
ward(subject, config)wardOnStage
createBatch({ object | instances, … })createBatchOnStage
createHover(subject)createHoverOnStage
createPress(subject)createPressOnStage
createDrag(subject)createDragOnStage

An Environment's binding re-exports them under the hooks' own names. A scene with no page wards imports them from there, as @wardic/three/solid's ward, createBatch, createHover, createPress and createDrag, and its app carries none of the page's code: a three.js scene and one ward come to 243.1 KB gzipped, against 300.5 through @wardic/solid's ward. A page with both can use either. Given a page's element, each says to import its hook from @wardic/solid, in development.

A ward on a scene's Subject

It takes initial, animate, transition, its own variants, whileHover, whileTap and custom. A key of the page's alone (whileFocus, whileInView) or of an element's (drag, exit, layout, style) is an error in development, naming it.

  • held renders nothing. While its Subject or its animate is still loading, it holds its component's <Loading>, so the fallback shows and <Reveal> orders it.
  • Its events are a ward's: settled(), tapped(), and next, each and when for settled, the hover events and the press events. Each event's element is the Subject.
  • read(key) and atom(key) give the Subject's value for key as Wardic draws it. A key the ward hasn't moved reads what the Subject holds, so ward(light, {}).read("intensity")() is the light's intensity from the start. A key its Subject has reads at its type: ward(mesh, {}).read("y") is an Accessor<number>, and undefined only while an accessor gives no Subject. A colour reads by its channels in linear light, colorR, colorG and colorB.
  • An accessor Subject: ward(() => active(), config) follows each Subject it gives. A new one takes the ward over, starting from initial as the ward did, and the last keeps where it was, with no exit.
  • A key a gesture moves returns, once the gesture ends, to the value the Subject had before the ward first moved it.
  • The Stage's animate on a Subject a ward is on goes through the ward, which takes the key back at its next change.

WardicStage is Solid 2's own provider, <WardicStage value={stage}>; read it with useContext(WardicStage), which is null outside one. A scene's Subject given to ward with no Stage above it is an error that names it, in development.

Scenes come with @wardic/three/solid's createStage, which makes a Stage for a three.js scene. The Stage interface names no three.js code, so another Environment can fill it: its ward is stageWard(environment), given what Wardic's runtime for its Subjects runs on and the scene's input. Solid 2 only.

Types

  • Stage: what the hooks read of a Stage: whether a value is one of its Subjects, its ward, animate, its Frame effects and its pointer input.
  • StageWard: a ward on a Stage's Subject: held, settled, next, each, when and read.
  • StageSubjects: the Subjects a Stage takes, which an Environment adds to by declaration merging: @wardic/three/solid adds three.js's objects, so ward(mesh, config) is typed.
  • StageSubject: any of them.
  • StageValues, StageValueKey: the values a Stage's Subjects take beyond an element's, which an Environment adds to by declaration merging: @wardic/three/solid adds three.js's, so ward(mesh, { animate: { roughness: 0.2, emissive: "#ff6a00" } }) typechecks, and a name in neither is still an error naming it.
  • StageTargetValues: what each of a Stage's Subject's values takes in a target, by name, which an Environment adds to by declaration merging, a generic interface of the Subject: @wardic/three/solid adds three.js's, a number for each of a Subject's number keys and a colour for each of its colours. ward(subject, config) doesn't read it: it checks a target's names by StageValues.
  • StageReads: what each key of a Stage's Subject reads as, which an Environment adds to by declaration merging, a generic interface of the Subject: @wardic/three/solid adds three.js's, each number a scene object has, its material's and its vectors' axes, so read gives a mesh's roughness, a light's intensity or a number of your own on a Group as a number.
  • StageRead, StageReadKey, StageValueOf: a Stage ward's read, the keys it reads at its Subject's types, and the type it reads for a key: the Subject's for a key it has, as a page ward's for any other.
  • StageSubjectOf: the Subject a ward is given: itself, or what an accessor gives, undefined among it.
  • StageEvent, StageEvents: the events a ward on a Stage's Subject tells, and each one's info.
  • stageWard, StageWardEnvironment: a Stage's ward, bound to what it runs on: an animate environment, where a Subject's keys start (startLinksOf) and the scene's input.
  • stageSceneObject, StageMembership: a Scene object's ward, what an Environment's createSceneObject builds on. Given what joins its Subject to the scene and what takes it out, it joins once the ward can start, and plays its exit before its Subject leaves, past its owner.
  • StageGraph: a scene's graph, which an Environment with one gives its Stage: a Subject's parent, its moves, its place among an ancestor's children, and its descendants. On a Stage with one, a ward with variants and no names of its own follows the nearest ward above its Subject, and its stagger slot is its place among that ward's Subject's children.
  • StageDrag, StageDragHandlers: what a Stage drags its Subjects with, its Environment's: it watches a Subject's drags on the Stage's input, moves it, and tells each pointer sample and its release coming to rest. A ward's drag on a Stage with none is an error in development.
  • StageDragConfig, StageDragRange, StageDragTransition: a scene's drag keys, in the page's drag keys' place: drag (true, or "x", "y" or "z"), dragConstraints per axis as [min, max], dragElastic, dragMomentum, dragTransition (its release's inertia) and dragSnapToOrigin. An Environment adds its own by declaration merging: @wardic/three/solid adds dragPlane.
  • StageWardConfig, StageWardConfigValues, StageWardChecked: a ward's config on a Stage's Subject: a ward's, with the scene's drag keys.
  • StageBatch, StageKeyedBatchConfig, StageCountBatchConfig, StageBatchMembers, StageBatchValues, StageBatchTarget, StageBatchEvents, StageBatchMemberInfo: a scene's Batch, what createBatch makes under a Stage given object (a three.js object per member, added as it enters and removed once its exit lands) or instances (an InstancedMesh's instances), keyed by each and key or by count, with its landings and its members' hovers and presses as a page's Batch's.
  • StageBatchBinding, StageBatchHooks: what a Stage's batch gives createBatch, and what it tells it: an Environment's side of a scene's Batch.
  • SceneWard, SceneObjectEvent, SceneObjectEvents, SceneObjectExit: a Scene object's handle, a ward that also tells exitStart and exitComplete, and their info: the Subject leaving, as element.