UNPKG

motion-dom

Version:
29 lines (26 loc) • 1.13 kB
import { clamp, secondsToMilliseconds } from 'motion-utils'; import { getSpringOptions } from '../../animation/generators/spring.mjs'; /** * A curved path ties x and y to one progress value, so it takes the part of * the velocity along the straight line from start to end. */ const pointToProgressVelocity = (tx, ty, { x, y }) => { const lengthSquared = tx * tx + ty * ty; return lengthSquared < 1 ? 0 : (-1e3 * (x * tx + y * ty)) / lengthSquared; }; /** * With `mass: "auto"`, mass comes from the element's size: a 300px square * has mass 1, bigger elements are heavier and slower (mass 0.25 to 2), and * damping scales with mass so the spring keeps its bounce. The result is a * physics spring. */ const resolveAutoMass = (t, size = 300) => { const mass = clamp(0.25, 2, size / 300); const { stiffness, damping } = getSpringOptions({ ...t, duration: t.duration && secondsToMilliseconds(t.duration), }); return { ...t, stiffness, damping: damping * Math.sqrt(mass), mass }; }; export { pointToProgressVelocity, resolveAutoMass }; //# sourceMappingURL=layout-velocity.mjs.map