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 and whether the Environment is shown, live, as Atoms; and observes a target's resizes and whether it's in view. Layout animations, in-view gestures and reduced motion all read it. A container's scroll is ScrollSource's.

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

const probe = yield* Probe.Probe
const bounds = yield* probe.measure(card)

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.

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 ScrollSource.Options.offset.

root?
readonly root?: unknown;

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


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.