Skip to main content
Introducing packages.sweber.dev
Documentation menuAPI

API

Every export of @sweberdev/lagrangian and @sweberdev/lagrangian-react.

@sweberdev/lagrangian

ExportSignature
animate(targets, props, { duration?, bounce?, stiffness?, damping?, mass?, velocity?, delay?, stagger? }) => Animation
set(targets, props) => void: jump without animation
getValue(element, prop) => PhysicsValue
draggable(element, { axis?, bounds?, rubberband?, inertia?, deceleration?, snap?, spring?, onStart?, onMove?, onEnd? }) => Draggable
value(initial) => PhysicsValue
PhysicsValueget(), velocity, animating, set(x), jump(x), to(target, spring?), throw(decay?), start(motion), stop(), on(listener)
spring(from, to, velocity?, options?) => Motion
decay(from, { velocity?, deceleration?, min?, max?, snap?, bounce?, restDelta? }) => Motion
springParams, dampingRatioresolve duration/bounce into stiffness, damping, mass
settleTime, restValue(motion) => number
projectRest, timeConstant, nearestthrow maths
rubberband, rubberClampiOS-style overscroll
VelocityTrackeradd(timeMs, value), velocity(timeMs?), reset()
World, worldsee The world
rk4, systemsee Equations of motion
loopadd(task), manual(on), step(ms), size: the shared frame loop
reducedMotion, setReducedMotionsee Reduced motion

targets is an element, a selector or a list of elements. An Animation has finished: Promise<boolean> and stop(). A Motion is (seconds) => { value, velocity, done }.

@sweberdev/lagrangian-react

ExportSignature
useSpringProps(props, options?) => RefObject
useSpring(target, options?) => PhysicsValue
useValue(value) => number
usePhysicsValue(initial?) => PhysicsValue
useDraggable(options?) => [ref, Draggable | null]
useWorld(options?) => [ref, World]
useBody(world, options) => [ref, Body | null]

Testing

loop.manual(true) stops using requestAnimationFrame; loop.step(ms) then advances every animation and world by hand.