Probe

The Probe: what an Environment can tell the engine about what it draws. It measures a target's box; holds the viewport's size, whether the user prefers reduced motion, whether the Environment is shown, and a container's scroll, live, as Atoms; and observes a target's resizes and whether it's in view. Layout animations, in-view gestures, scroll-linked values and reduced motion all read it.

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

const probe = yield* Probe.Probe
const bounds = yield* probe.measure(card)
const scroll = yield* probe.scroll({ container: list })

Classes

Probe

An Environment's Probe.

Extends

  • Context.Service

Properties

measure
readonly measure: (target) => Effect<Bounds>;

Measures target's box, now.

Parameters
target

unknown

Returns

Effect<Bounds>

observeIntersection
readonly observeIntersection: (target, options?) => InputFeed<Intersection>;

A target's intersection with the viewport, or options' root: a report each time it comes in or goes out, and the first as it starts. An Input feed, one observer per subscriber, since each may ask its own root, margin and amount.

Parameters
target

unknown

options?

IntersectionOptions

Returns

InputFeed<Intersection>

observeResize
readonly observeResize: (target) => Stream<Bounds>;

A target's box each time it resizes.

Parameters
target

unknown

Returns

Stream<Bounds>

prefersReducedMotion
readonly prefersReducedMotion: Atom<boolean>;

Whether the user prefers reduced motion, live, as their Environment reports it.

scroll
readonly scroll: (options?) => Effect<Atom<Scroll>, never, Scope>;

A container's scroll, live: an Atom the Environment sets as the container scrolls or resizes, as it happens, so a value derived from it is written in the frame that shows the scroll. One listener a container, however many read it, held while the Scope is.

Parameters
options?

ScrollOptions

Returns

Effect<Atom<Scroll>, never, Scope>

viewport
readonly viewport: Atom<Viewport>;

The viewport's size, live.

visible
readonly visible: Atom<boolean>;

Whether the Environment is shown, live, as Motion's usePageInView: false while it's hidden, put in the background, say.

Interfaces

Bounds

A target's box as an Environment measures it, in its coordinates: its corner, its size and its four edges.

Properties

bottom
readonly bottom: number;

Its bottom edge.

height
readonly height: number;

Its height.

left
readonly left: number;

Its left edge.

readonly right: number;

Its right edge.

top
readonly top: number;

Its top edge.

width
readonly width: number;

Its width.

x
readonly x: number;

Its left edge: left.

y
readonly y: number;

Its top edge: top.


Intersection

A target's intersection, as an Environment reports it.

Properties

intersecting
readonly intersecting: boolean;

Whether the target is in.

raw?
readonly raw?: unknown;

The platform's own record of it, which core never reads: a binding hands it to an app's callback.


IntersectionOptions

What an intersection is observed against, as Motion's viewport. Default: the viewport, no margin, any of the target.

Extended by

Properties

amount?
readonly amount?: number;

How much of the target must be in it to count: from 0, any of it, to 1, all of it.

margin?
readonly margin?: unknown;

How far the container's edges are grown, or shrunk, before it counts, in the Environment's own syntax: core passes it on, as it does ScrollOptions.offset.

root?
readonly root?: unknown;

The container it's observed against: the viewport when left out.


Scroll

A container's scroll on both axes: what the Probe's scroll holds.

Properties

x
readonly x: ScrollAxis;

Across.

y
readonly y: ScrollAxis;

Down.


ScrollAxis

One axis of a container's scroll.

Properties

current
readonly current: number;

How far the container is scrolled on the axis, in the Environment's units.

length
readonly length: number;

How far it can scroll on the axis: 0 for a container that doesn't overflow.

progress
readonly progress: number;

Progress, 0 to 1: through the container's scroll range, or, on the options' axis with a target or an offset, through the offsets the target passes.


ScrollOptions

What the Probe's scroll reads, as Motion's scroll options.

Properties

axis?
readonly axis?: "x" | "y";

The axis target and offset apply to. Default "y".

container?
readonly container?: unknown;

The scroll container: the Environment's own when left out.

offset?
readonly offset?: unknown;

Where on axis the target's progress runs, from 0 to 1, in the Environment's own terms, which it reads and resolves, as @wardic/dom's ScrollOffset does. Core passes it through, as it does container and target.

target?
readonly target?: unknown;

An element whose progress through the container progress reads, on axis.


Viewport

The viewport's size: how much of its content the Environment shows.

Properties

height
readonly height: number;

Its height.

width
readonly width: number;

Its width.