Reference

Every export of `@usefluid/motion` and `@usefluid/motion/react`.

Springs

ExportSignature and use
springsPresets { w, z } for frequency and damping: snappy, soft, bouncy, firm.
createSpringcreateSpring(initial, config?) returns { value, velocity, target, step(dt), jump(value) }. Set target, call step(dt) each frame; it returns false once settled.
stepSpringstepSpring(x, v, target, w, z, dt) returns { x, v } after dt seconds. The exact solution, so it gives the same result at any frame rate.
springCssspringCss(config?, samples?) returns { easing, duration, transition(property, delay?) }: a CSS linear() easing that follows the spring.
SpringConfig, SpringTypes for the above.

Frame loop

ExportSignature and use
playplay(tick) adds tick(dt) to one shared requestAnimationFrame loop and returns a function that removes it. Return false from the tick to stop.
Tick(dt: number) => boolean | undefined.

Paths

ExportSignature and use
shapesBuilt-in paths in a 120 box: dot, circle, square, capsule, triangle, flower, drop, pebble.
scalePathscalePath(d, from, size = 120) rescales a path from its box (24 or "minX minY width height") into the 120 box, keeping its size and place.
fitPathfitPath(d, size = 120, padding = 0) fills the box with the drawing, centred. For logos.
parsePathparsePath(d) returns absolute M, C and Z commands. Lines, quadratics and arcs become cubic curves.
serializePathserializePath(commands) writes commands back to a d string.
sampleContourssampleContours(d, count = 160) returns each closed part as count evenly spaced points, biggest part first.
PathErrorThrown for a path or box that cannot be read. code is one of the codes on Troubleshooting.
Command, Contour, PathErrorCode, ShapeNameTypes for the above.

Morph

ExportSignature and use
createMorphercreateMorpher(initial, config?) returns { to(d), jump(d), step(dt), path() }. to starts a morph, step advances it and returns false when done, path gives the current d.
MorpherConfigSpringConfig plus points (default 160) and spread (default 0.22, how much the points' speeds differ).
MorpherType for the above.

React

ExportSignature and use
MorphPath<MorphPath d config? onRest? …pathProps /> flows into every new d. Keeps the last good shape on a bad d.
useSpringuseSpring(target, apply, config?) springs named values and calls apply(values, velocities) each frame, without re-rendering.
useSequenceuseSequence(times, active?) returns the index of the latest time in seconds reached: a simple timeline.
useInViewuseInView(ref, threshold?) returns true once the element has been seen.
useSkipuseSkip(enabled?, initial?) returns true after the first key or pointer press, to skip an opening.
useReducedMotionuseReducedMotion() returns whether the system asks for reduced motion.

Theme

ExportUse
@usefluid/motion/theme.cssThe ten --fluid-* variables with defaults: accent, on-accent, surface, surface-2, text, text-2, border, focus, radius, font.