motion-dom 14.11.1 → 14.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/gestures/pinch/index.ts"],"sourcesContent":["import { clamp, type Point } from \"motion-utils\"\nimport { spring } from \"../../animation/generators/spring\"\nimport type { SpringOptions } from \"../../animation/types\"\nimport { readStyleValue, styleSubjectEffect } from \"../../effects/style\"\nimport { svgSubjectEffect } from \"../../effects/svg\"\nimport { cancelFrame, frame } from \"../../frameloop\"\nimport { time } from \"../../frameloop/sync-time\"\nimport { visualElementStore } from \"../../render/store\"\nimport { activeScope, addToScope } from \"../../scope/active\"\nimport { isSVGElement } from \"../../utils/is-svg-element\"\nimport { mixNumber } from \"../../utils/mix/number\"\nimport {\n resolveElements,\n type ElementOrSelector,\n} from \"../../utils/resolve-elements\"\nimport { motionValue, type MotionValue } from \"../../value\"\nimport { setDragLock } from \"../drag/state/set-active\"\nimport { applyConstraints, defaultElastic } from \"../drag/utils/constraints\"\nimport { elementDragControls } from \"../drag/VisualElementDragControls\"\n\n/**\n * @public\n */\nexport interface PinchInfo {\n /**\n * The gesture's focal point in client coordinates: the midpoint\n * between two touches, or the cursor for a trackpad pinch.\n */\n point: Point\n\n /**\n * How far the focal point has moved since the gesture started.\n */\n offset: Point\n\n /**\n * The gesture's scale relative to its start.\n */\n scale: number\n\n /**\n * The gesture's rotation since its start, in degrees.\n */\n rotate: number\n}\n\n/**\n * Called with the latest event and the gesture's info.\n *\n * @public\n */\nexport type OnPinchEvent = (event: Event, info: PinchInfo) => void\n\n/**\n * Handlers for a single pinch gesture, returned from the pinch start\n * callback.\n *\n * @public\n */\nexport interface PinchHandlers {\n /**\n * Called each frame the gesture changes, after the element's values\n * are updated.\n */\n onPinch?: OnPinchEvent\n\n /**\n * Called once when the gesture ends: a touch lifts or is cancelled, a\n * trackpad pinch stops, or the gesture is disabled or removed.\n *\n * Returning this function directly from the pinch start callback is\n * equivalent.\n */\n onComplete?: OnPinchEvent\n}\n\n/**\n * Called once when a pinch gesture starts: when a second touch lands, on\n * the first trackpad pinch event, or on Safari's `gesturestart`. Can\n * return a function to call when the pinch ends, or an object of\n * `PinchHandlers`.\n *\n * @public\n */\nexport type OnPinchStartEvent = (\n element: Element,\n event: Event\n) => OnPinchEvent | PinchHandlers | void\n\n/**\n * The limits of a pinch's scale or rotation.\n *\n * @public\n */\nexport interface PinchLimits {\n /**\n * The minimum. Past it, the gesture resists by `elastic`, and the\n * value springs back to it on release.\n */\n min?: number\n\n /**\n * The maximum. Past it, the gesture resists by `elastic`, and the\n * value springs back to it on release.\n */\n max?: number\n}\n\n/**\n * @public\n */\nexport interface PinchRotateOptions extends PinchLimits {\n /**\n * On release, rotate to the nearest multiple of this many degrees.\n */\n snap?: number\n}\n\n/**\n * @public\n */\nexport interface PinchOptions {\n /**\n * Scale the element. Defaults to `true`. Pass `{ min, max }` to limit\n * the scale.\n */\n scale?: boolean | PinchLimits\n\n /**\n * Rotate the element with the touches. Defaults to `true`. Pass\n * `{ min, max }` (in degrees) to limit the rotation, and `snap` to\n * rotate to the nearest multiple of `snap` degrees on release.\n */\n rotate?: boolean | PinchRotateOptions\n\n /**\n * Move the element with the focal point, and keep the point under the\n * fingers (or cursor) in place while scaling and rotating. Defaults to\n * `true`. Composes with drag: a drag that one of the touches started\n * carries on from wherever the pinch leaves the element (its offset\n * restarts there). Drag constraints aren't applied while pinching.\n *\n * Assumes the default `transform-origin` (the element's centre).\n */\n pan?: boolean\n\n /**\n * The point that scale and rotation pivot around. `\"pointer\"` (the\n * default) is the focal point between the touches, or the cursor.\n * `{ x, y }` is a point on the element, as a fraction of its width\n * and height: `{ x: 0.5, y: 0.5 }` is its centre. With `pan: false`,\n * the default is the centre.\n */\n origin?: \"pointer\" | Point\n\n /**\n * How far scale and rotation can go past their limits, as for\n * `dragElastic`: `0` stops at the limit, `1` doesn't resist. Pass\n * `{ min, max }` to set each side. Defaults to `0.35`.\n */\n elastic?: boolean | number | PinchLimits\n\n /**\n * On release, animate scale back to `1`, and rotation and `x`/`y`\n * back to `0`.\n */\n snapToOrigin?: boolean\n\n /**\n * The spring values use to animate back inside their limits, to a\n * `snap` angle or to their origin.\n */\n transition?: SpringOptions\n}\n\n/**\n * Options for the `pinch` prop.\n *\n * @public\n */\nexport interface PinchProps extends PinchOptions {\n /**\n * Called when the pinch starts.\n */\n onStart?: OnPinchEvent\n\n /**\n * Called each frame the pinch changes.\n */\n onMove?: OnPinchEvent\n\n /**\n * Called when the pinch ends.\n */\n onEnd?: OnPinchEvent\n}\n\nexport type PinchValues = [\n scale: MotionValue<number>,\n rotate: MotionValue<number>,\n x: MotionValue<number>,\n y: MotionValue<number>,\n]\n\n/**\n * A trackpad pinch arrives as a stream of `wheel` events with no end\n * event, so it ends once none have arrived for this long.\n */\nconst wheelTimeout = 150\n\n/**\n * Convert an `x`/`y` set in other units (e.g. `\"-50%\"` to centre an\n * element) to pixels, so the gesture can add to it.\n */\nconst toPixels = (value: MotionValue<number>, size: number) => {\n const latest = value.get() as number | string\n\n if (typeof latest === \"string\") {\n value.set(parseFloat(latest) * (latest.endsWith(\"%\") ? size / 100 : 1))\n }\n}\n\nconst limitsOf = (option?: boolean | PinchRotateOptions): PinchRotateOptions =>\n typeof option === \"object\" ? option : {}\n\n/**\n * Resolve `elastic` to a resistance for each side, as for `dragElastic`.\n */\nconst resolveElastic = (\n elastic: PinchOptions[\"elastic\"] = defaultElastic\n): { min: number; max: number } => {\n const side = (value?: number | boolean) =>\n value === true ? defaultElastic : +(value || 0)\n\n return typeof elastic === \"object\"\n ? { min: side(elastic.min), max: side(elastic.max) }\n : { min: side(elastic), max: side(elastic) }\n}\n\n/**\n * Whether the gesture writes `x`/`y`: to follow the focal point, or to\n * keep an `origin` on the element in place.\n */\nconst writesXY = ({ pan, origin }: PinchOptions) => pan !== false || !!origin\n\nconst clampTo = (value: number, { min = -Infinity, max = Infinity }) =>\n clamp(min, max, value)\n\n/**\n * The raw gesture value that elastic shows as `value`. A pinch that starts\n * while a value is still past its limit (like during a spring back) carries\n * on from it, rather than jumping.\n */\nconst unconstrain = (\n value: number,\n option: boolean | PinchRotateOptions | undefined,\n resistance: { min: number; max: number }\n) => {\n const limit = clampTo(value, limitsOf(option))\n const elastic = resistance[value < limit ? \"min\" : \"max\"]\n\n return elastic ? limit + (value - limit) / elastic : value\n}\n\n/**\n * Listen for pinch gestures on `element`: two touches (or pens), a trackpad\n * pinch (`wheel` with `ctrlKey`, as Chrome, Edge and Firefox report it),\n * and Safari's `gesture*` events.\n *\n * `getValues` is called each time a gesture starts, in the frame's read\n * step, for the scale/rotate/x/y values to write to. It runs alongside the\n * element measurement so neither forces a layout.\n *\n * `getOptions` is read whenever it's needed, so options can change while\n * listening. Return `false` to disable the gesture, which also ends one in\n * progress.\n *\n * `onPinchStart` is called once as each gesture starts, with the gesture's\n * info as a third argument. It can return the gesture's handlers, as for\n * `pinch()`.\n */\nexport function addPinchListeners(\n element: Element,\n getValues: () => PinchValues,\n getEnabledOptions: () => PinchOptions | false | undefined,\n onPinchStart: (\n element: Element,\n event: Event,\n info: PinchInfo\n ) => ReturnType<OnPinchStartEvent>\n): VoidFunction {\n const pointers = new Map<number, Point>()\n\n /**\n * The gesture as last reported: focal point, log of a distance and an\n * angle. Only changes in distance and angle matter, so trackpad and\n * Safari input write a virtual distance (the scale) here. Logs keep\n * a long trackpad pinch from overflowing.\n */\n const current = { x: 0, y: 0, l: 0, a: 0 }\n const start = { ...current }\n const prev = { ...current }\n\n let source: \"pointer\" | \"wheel\" | \"gesture\" | undefined\n let lastEvent: Event\n let values: PinchValues | undefined\n let originX = 0\n let originY = 0\n let width = 0\n let height = 0\n let lastX = 0\n let lastY = 0\n let hasMoved = false\n let wheelTime = 0\n let handlers: PinchHandlers = {}\n let unlock: VoidFunction | null | undefined\n\n /**\n * The gesture's scale and rotation before limits and elastic apply.\n */\n let rawScale = 1\n let rawRotate = 0\n let stopSnap = () => {}\n\n /**\n * The latest enabled options, so a gesture disabled mid-way can still\n * report its end.\n */\n let options: PinchOptions = {}\n const getOptions = () => (options = getEnabledOptions() || options)\n\n const info = (): PinchInfo => ({\n point: { x: current.x, y: current.y },\n offset: { x: current.x - start.x, y: current.y - start.y },\n scale: Math.exp(current.l - start.l),\n rotate: current.a - start.a,\n })\n\n /**\n * Read the element's box and values, and find its layout origin: its\n * centre without `x`/`y`. Scale and rotate are applied around the\n * centre (the default transform origin), so they don't move it.\n */\n const measure = () => {\n const box = element.getBoundingClientRect()\n const { left, top } = box\n const { scale, rotate, elastic } = getOptions()\n const [s, r, x, y] = (values = getValues())\n const resistance = resolveElastic(elastic)\n\n /**\n * Stop animations on values this gesture writes, and leave the\n * rest running.\n */\n scale !== false && s.stop()\n rotate !== false && r.stop()\n rawScale = unconstrain(s.get(), scale, resistance)\n rawRotate = unconstrain(r.get(), rotate, resistance)\n\n width = (element as HTMLElement).offsetWidth ?? box.width\n height = (element as HTMLElement).offsetHeight ?? box.height\n\n if (writesXY(options)) {\n x.stop()\n y.stop()\n toPixels(x, width)\n toPixels(y, height)\n }\n\n lastX = x.get()\n lastY = y.get()\n originX = left + box.width / 2 - lastX\n originY = top + box.height / 2 - lastY\n }\n\n /**\n * The point scale and rotation pivot around, in client coordinates:\n * the focal point, or `origin` on the element at scale `s`, rotation\n * `r` and offset `x`/`y`.\n */\n const pivot = (\n focal: Point,\n s: number,\n r: number,\n x: number,\n y: number\n ): Point => {\n const { origin } = options\n if (typeof origin !== \"object\") return focal\n\n const a = (r * Math.PI) / 180\n const u = (origin.x - 0.5) * width * s\n const v = (origin.y - 0.5) * height * s\n\n return {\n x: originX + x + Math.cos(a) * u - Math.sin(a) * v,\n y: originY + y + Math.sin(a) * u + Math.cos(a) * v,\n }\n }\n\n const dragControls = () =>\n elementDragControls.get(visualElementStore.get(element)!)\n\n /**\n * On release, spring scale and rotation back inside their limits (or\n * to a `snap` angle), keeping the focal point in place, or everything\n * back to its origin with `snapToOrigin`.\n */\n const snap = () => {\n const {\n scale: scaleOption,\n rotate: rotateOption,\n snapToOrigin,\n transition,\n } = options\n const [scale, rotate, x, y] = values!\n const s0 = scale.get()\n const r0 = rotate.get()\n const x0 = x.get()\n const y0 = y.get()\n const { snap: step } = limitsOf(rotateOption)\n let s1 = clampTo(s0, limitsOf(scaleOption))\n /**\n * Snap to the step nearest where the release velocity would carry\n * the rotation, found as inertia finds its target (with a lower power\n * than inertia's 0.8).\n */\n let r1 = clampTo(\n step\n ? Math.round((r0 + 0.2 * rotate.getVelocity()) / step) * step\n : r0,\n limitsOf(rotateOption)\n )\n\n if (snapToOrigin) {\n s1 = 1\n // The nearest upright angle, so it turns the shortest way\n r1 = Math.round(r0 / 360) * 360\n }\n\n /**\n * Keep the focal point in place, unless the element doesn't move\n * with it, or a drag carries on and owns x/y.\n */\n const moves = writesXY(options) && !dragControls()?.isDragging\n const p0 = pivot(current, s0, r0, x0, y0)\n const vx = originX + x0 - p0.x\n const vy = originY + y0 - p0.y\n\n /**\n * Scale, rotation and x/y at progress `p` of the snap, keeping the\n * focal point in place.\n */\n const at = (p: number) => {\n const k = mixNumber(s0, s1, p)\n const r = mixNumber(r0, r1, p)\n const angle = ((r - r0) * Math.PI) / 180\n const cos = (Math.cos(angle) * k) / s0\n const sin = (Math.sin(angle) * k) / s0\n return [\n k,\n r,\n x0 + cos * vx - sin * vy - vx,\n y0 + sin * vx + cos * vy - vy,\n ]\n }\n\n if (\n !s0 ||\n (s1 === s0 && r1 === r0 && !(snapToOrigin && moves && (x0 || y0)))\n ) {\n return\n }\n\n const generator = spring({\n keyframes: [0, 1],\n stiffness: 200,\n damping: 40,\n ...transition,\n })\n const startTime = time.now()\n\n /**\n * Drive the values from one spring, from 0 to 1, so they stay in\n * step and the focal point stays in place.\n */\n const tick = () => {\n if (dragControls()?.isDragging) return stopSnap()\n\n const { value: p, done } = generator.next(time.now() - startTime)\n if (done) stopSnap()\n\n const [k, r, fx, fy] = at(p)\n\n scaleOption !== false && scale.set(k)\n rotateOption !== false && rotate.set(r)\n\n if (moves) {\n x.set(snapToOrigin ? mixNumber(x0, 0, p) : fx)\n y.set(snapToOrigin ? mixNumber(y0, 0, p) : fy)\n }\n }\n\n stopSnap = () => cancelFrame(tick)\n frame.update(tick, true)\n }\n\n /**\n * Apply the change in the gesture since the last frame as an\n * incremental scale and rotation around the previous focal point,\n * plus the focal point's movement.\n */\n const apply = () => {\n if (!values || !hasMoved) return\n hasMoved = false\n\n const {\n rotate: rotateOption,\n scale: scaleOption,\n pan,\n elastic,\n } = getOptions()\n const [scale, rotate, x, y] = values\n const resistance = resolveElastic(elastic)\n const latest = scale.get()\n const drag = dragControls()\n const isDragging = drag?.isDragging\n\n if (!isDragging) {\n lastX = x.get()\n lastY = y.get()\n }\n\n const p = pivot(prev, latest, rotate.get(), lastX, lastY)\n let theta = 0\n let k = 1\n\n /**\n * Apply limits and elastic to the gesture's raw scale and rotation.\n * At a hard limit, the raw value stops too, so moving back responds\n * straight away.\n */\n const constrain = (raw: number, option?: boolean | PinchLimits) => {\n const limits = limitsOf(option)\n const limit = clampTo(raw, limits)\n\n return resistance[raw < limit ? \"min\" : \"max\"]\n ? [applyConstraints(raw, limits, resistance), raw]\n : [limit, limit]\n }\n\n if (scaleOption !== false && latest) {\n const [next, raw] = constrain(\n clamp(1e-9, 1e9, rawScale * Math.exp(current.l - prev.l)),\n scaleOption\n )\n rawScale = raw\n k = next / latest\n scale.set(next)\n }\n\n if (rotateOption !== false) {\n const [next, raw] = constrain(\n rawRotate + current.a - prev.a,\n rotateOption\n )\n rawRotate = raw\n theta = next - rotate.get()\n if (theta) rotate.set(next)\n }\n\n if (writesXY(options)) {\n /**\n * Pinch owns x/y while it runs, so stop any animation started\n * on them since (like a drag's snap back) taking over after.\n */\n x.stop()\n y.stop()\n\n /**\n * If drag() or the drag prop is dragging this element with one\n * of the touches, it has set x/y this frame to where it started\n * plus the touch's offset. Carry on from our own values instead,\n * and restart the drag from them and the touch's latest point.\n * That way it continues from wherever the pinch leaves the\n * element, and its release velocity only counts movement after\n * the pinch, so a zoom doesn't end in a fling.\n */\n const angle = (theta * Math.PI) / 180\n const cos = Math.cos(angle) * k\n const sin = Math.sin(angle) * k\n const dx = p.x - originX - lastX\n const dy = p.y - originY - lastY\n const panX = pan !== false ? current.x - prev.x : 0\n const panY = pan !== false ? current.y - prev.y : 0\n\n /**\n * Move the centre so the pivot, scaled and rotated around the\n * centre, stays in place, plus the focal point's movement.\n */\n lastX += dx + panX - (cos * dx - sin * dy)\n lastY += dy + panY - (sin * dx + cos * dy)\n\n if (isDragging) {\n const history = drag!.panSession!.history\n history.splice(0, history.length - 1)\n\n /**\n * Date the point long ago, so drag only measures release\n * velocity from moves after the pinch. A move that drag\n * processes as the touch lifts is part of the pinch.\n */\n history[0].timestamp = -Infinity\n drag!.originPoint.x = lastX\n drag!.originPoint.y = lastY\n }\n\n x.set(lastX)\n y.set(lastY)\n }\n\n Object.assign(prev, current)\n handlers.onPinch?.(lastEvent, info())\n }\n\n /**\n * Runs after the update step, where drag sets x/y, so it has the final\n * say on them each frame.\n */\n const update = () => {\n if (!getEnabledOptions()) return end(lastEvent)\n\n apply()\n\n if (source === \"wheel\" && time.now() - wheelTime > wheelTimeout) {\n end(lastEvent)\n }\n }\n\n const begin = (event: Event, from: typeof source) => {\n if (!getEnabledOptions()) return\n\n stopSnap()\n source = from\n lastEvent = event\n hasMoved = false\n values = undefined\n handlers = {}\n Object.assign(start, current)\n Object.assign(prev, current)\n frame.read(measure)\n frame.preRender(update, true)\n\n const result = onPinchStart(element, event, info())\n handlers =\n typeof result === \"function\" ? { onComplete: result } : result || {}\n }\n\n const end = (event: Event) => {\n if (!source) return\n cancelFrame(measure)\n cancelFrame(update)\n\n if (getEnabledOptions()) {\n apply()\n values && snap()\n }\n\n source = undefined\n handlers.onComplete?.(event, info())\n }\n\n const moved = (event: Event) => {\n lastEvent = event\n hasMoved = true\n }\n\n const readPointers = () => {\n const [a, b] = pointers.values()\n const angle = (Math.atan2(b.y - a.y, b.x - a.x) * 180) / Math.PI\n const delta = angle - current.a\n\n current.x = (a.x + b.x) / 2\n current.y = (a.y + b.y) / 2\n current.l = Math.log(Math.hypot(b.x - a.x, b.y - a.y) || 1)\n\n /**\n * Take the shortest way round, so rotation keeps counting past\n * 180deg rather than flipping to -180deg.\n */\n current.a += delta - 360 * Math.round(delta / 360)\n }\n\n const setPointer = (event: PointerEvent) =>\n pointers.set(event.pointerId, { x: event.clientX, y: event.clientY })\n\n const onPointerMove = (event: PointerEvent) => {\n if (!pointers.has(event.pointerId)) return\n setPointer(event)\n\n if (source === \"pointer\") {\n readPointers()\n moved(event)\n }\n }\n\n const onPointerUp = (event: PointerEvent) => {\n if (!pointers.delete(event.pointerId)) return\n\n if (source === \"pointer\") end(event)\n\n if (!pointers.size) {\n toggleWindowListeners()\n release()\n }\n }\n\n /**\n * Once a touch is down on the element, listen on the window too, so\n * the second touch can land beside it (for instance on a small image).\n */\n const onPointerDown = (event: PointerEvent) => {\n if (\n source ||\n pointers.size > 1 ||\n pointers.has(event.pointerId) ||\n event.pointerType === \"mouse\"\n ) {\n return\n }\n\n if (!pointers.size) toggleWindowListeners(true)\n setPointer(event)\n\n if (pointers.size === 2) {\n readPointers()\n begin(event, \"pointer\")\n\n /**\n * Unless this element drags, hold the drag lock until every\n * touch lifts. A press on it then ends as a cancel, rather than\n * a tap, and a draggable parent doesn't drag.\n */\n if (\n source &&\n !unlock &&\n !elementDragControls.get(visualElementStore.get(element)!)\n ) {\n unlock = setDragLock(true)\n }\n }\n }\n\n /**\n * Release the drag lock a frame later, so a press ending on this same\n * pointerup still sees it.\n */\n const release = () => {\n const done = unlock\n unlock = undefined\n done && frame.postRender(done)\n }\n\n const toggleWindowListeners = (add?: boolean) => {\n const method = add ? \"addEventListener\" : \"removeEventListener\"\n window[method](\"pointerdown\", onPointerDown as EventListener)\n window[method](\"pointermove\", onPointerMove as EventListener)\n window[method](\"pointerup\", onPointerUp as EventListener)\n window[method](\"pointercancel\", onPointerUp as EventListener)\n }\n\n const onWheel = (event: WheelEvent) => {\n if (!event.ctrlKey || (source && source !== \"wheel\")) return\n\n current.x = event.clientX\n current.y = event.clientY\n\n if (!source) {\n current.l = 0\n begin(event, \"wheel\")\n if (!source) return\n }\n\n event.preventDefault()\n\n /**\n * Lines (Firefox's mouse wheel) to pixels, and cap each event so a\n * mouse wheel notch with ctrl held (about 100px) zooms a step.\n */\n current.l -=\n clamp(-50, 50, event.deltaY * (event.deltaMode ? 16 : 1)) / 100\n wheelTime = time.now()\n moved(event)\n }\n\n /**\n * Safari reports trackpad pinches as `gesture*` events. iOS Safari\n * fires them for touches too, alongside the pointer events we track.\n */\n const onGesture = (event: Event) => {\n if (!pointers.size && (!source || source === \"gesture\")) {\n const { scale, rotation, clientX, clientY } = event as any\n current.x = clientX\n current.y = clientY\n current.l = Math.log(scale)\n current.a = rotation\n\n if (source) {\n moved(event)\n if (event.type === \"gestureend\") end(event)\n } else if (event.type === \"gesturestart\") {\n begin(event, \"gesture\")\n }\n }\n\n if (source) event.preventDefault()\n }\n\n const listeners = {\n pointerdown: onPointerDown,\n wheel: onWheel,\n gesturestart: onGesture,\n gesturechange: onGesture,\n gestureend: onGesture,\n }\n\n for (const name in listeners) {\n element.addEventListener(\n name,\n listeners[name as keyof typeof listeners] as EventListener,\n { passive: false }\n )\n }\n\n return () => {\n for (const name in listeners) {\n element.removeEventListener(\n name,\n listeners[name as keyof typeof listeners] as EventListener\n )\n }\n toggleWindowListeners()\n end(lastEvent)\n stopSnap()\n pointers.clear()\n release()\n }\n}\n\nconst valueKeys = [\"scale\", \"rotate\", \"x\", \"y\"]\n\n/**\n * The element's scale/rotate/x/y motion values: those of its\n * VisualElement if it has one (it's a <motion.*> component, or drag() or\n * animateLayout() own it), otherwise those animate() binds to it, created\n * from its current style if this is the first time.\n */\nconst getElementValues = (element: HTMLElement | SVGElement) => {\n const visualElement = visualElementStore.get(element)\n const effect = isSVGElement(element) ? svgSubjectEffect : styleSubjectEffect\n\n return valueKeys.map((key) => {\n if (visualElement) {\n return visualElement.getValue(key, key === \"scale\" ? 1 : 0)\n }\n\n let value = effect.get(element as any, key)\n\n if (!value) {\n value = motionValue(readStyleValue(element, key))\n effect(element as any, { [key]: value })\n }\n\n return value\n }) as PinchValues\n}\n\n/**\n * Make elements pinchable. Returns a function that removes the gesture.\n * The start callback is optional:\n *\n * ```javascript\n * pinch(\"img\")\n * pinch(\"img\", { scale: { min: 1, max: 4 } })\n * ```\n *\n * ```javascript\n * const stop = pinch(\"#photo\", (element, startEvent) => {\n * return (endEvent, info) => {}\n * }, { scale: { min: 1, max: 4 } })\n * ```\n *\n * `onPinchStart` is called once as each pinch starts. It can return a\n * function to call when the pinch ends, or an object of handlers:\n *\n * ```javascript\n * pinch(\"#photo\", () => ({\n * onPinch: (event, { scale }) => {},\n * onComplete: (event, info) => {},\n * }))\n * ```\n *\n * Touches, trackpad pinches and Safari's gesture events scale the element\n * around the focal point and move it with the touches. Its `scale`,\n * `rotate`, `x` and `y` are motion values shared with `animate()`, so an\n * `onComplete` handler can animate the element after a pinch.\n *\n * @public\n */\nexport function pinch(\n elementOrSelector: ElementOrSelector,\n options?: PinchOptions\n): VoidFunction\nexport function pinch(\n elementOrSelector: ElementOrSelector,\n onPinchStart?: OnPinchStartEvent,\n options?: PinchOptions\n): VoidFunction\nexport function pinch(\n elementOrSelector: ElementOrSelector,\n startOrOptions?: OnPinchStartEvent | PinchOptions,\n options: PinchOptions = {}\n): VoidFunction {\n let onPinchStart: OnPinchStartEvent = () => {}\n\n if (typeof startOrOptions === \"function\") {\n onPinchStart = startOrOptions\n } else if (startOrOptions) {\n options = startOrOptions\n }\n\n const scope = activeScope.current\n\n /**\n * Run the start callback and the handlers it returns in the active\n * scope, so work they start is collected. A returned function is\n * bound by `scope.bind` itself.\n */\n if (scope) {\n const start = scope.bind(onPinchStart)\n onPinchStart = (element, event) => {\n const result = start(element, event)\n if (typeof result !== \"object\") return result\n\n const handlers: PinchHandlers = {}\n for (const key in result) {\n const name = key as keyof PinchHandlers\n const handler = result[name]\n handlers[name] = handler && scope.bind(handler)\n }\n return handlers\n }\n }\n\n const cleanups = resolveElements(elementOrSelector).map((element) => {\n scope?.track(element)\n\n const { style } = element as HTMLElement\n const touchAction = style.touchAction\n style.touchAction = \"none\"\n\n const remove = addPinchListeners(\n element,\n () => getElementValues(element as HTMLElement),\n () => options,\n onPinchStart\n )\n\n return () => {\n remove()\n style.touchAction = touchAction\n }\n })\n\n return addToScope(() => cleanups.forEach((cleanup) => cleanup()))\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA4MA;;;AAGG;AACH,MAAM,YAAY,GAAG,GAAG;AAExB;;;AAGG;AACH,MAAM,QAAQ,GAAG,CAAC,KAA0B,EAAE,IAAY,KAAI;AAC1D,IAAA,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAqB;AAE7C,IAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC5B,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC;IAC3E;AACJ,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,MAAqC,KACnD,OAAO,MAAM,KAAK,QAAQ,GAAG,MAAM,GAAG,EAAE;AAE5C;;AAEG;AACH,MAAM,cAAc,GAAG,CACnB,OAAA,GAAmC,cAAc,KACnB;IAC9B,MAAM,IAAI,GAAG,CAAC,KAAwB,KAClC,KAAK,KAAK,IAAI,GAAG,cAAc,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC;IAEnD,OAAO,OAAO,OAAO,KAAK;AACtB,UAAE,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;AAClD,UAAE,EAAE,GAAG,EAAE,IAAI,CAA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MAAM,MAAM,GAAG,iBAAiB,CAC5B,OAAO,EACP,MAAM,gBAAgB,CAAC,OAAsB,CAAC,EAC9C,MAAM,OAAO,EACb,YAAY,CACf;AAED,QAAA,OAAO,MAAK;AACR,YAAA,MAAM,EAAE;AACR,YAAA,KAAK,CAAC,WAAW,GAAG,WAAW;AACnC,QAAA,CAAC;AACL,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,UAAU,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC,CAAC;AACrE;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/gestures/pinch/index.ts"],"sourcesContent":["import { clamp, type Point } from \"motion-utils\"\nimport { spring } from \"../../animation/generators/spring\"\nimport type { SpringOptions } from \"../../animation/types\"\nimport { readStyleValue, styleSubjectEffect } from \"../../effects/style\"\nimport { svgSubjectEffect } from \"../../effects/svg\"\nimport { cancelFrame, frame } from \"../../frameloop\"\nimport { time } from \"../../frameloop/sync-time\"\nimport { visualElementStore } from \"../../render/store\"\nimport { activeScope, addToScope } from \"../../scope/active\"\nimport { isSVGElement } from \"../../utils/is-svg-element\"\nimport { mixNumber } from \"../../utils/mix/number\"\nimport {\n resolveElements,\n type ElementOrSelector,\n} from \"../../utils/resolve-elements\"\nimport { motionValue, type MotionValue } from \"../../value\"\nimport { setDragLock } from \"../drag/state/set-active\"\nimport { applyConstraints, defaultElastic } from \"../drag/utils/constraints\"\nimport { elementDragControls } from \"../drag/VisualElementDragControls\"\n\n/**\n * @public\n */\nexport interface PinchInfo {\n /**\n * The gesture's focal point in client coordinates: the midpoint\n * between two touches, or the cursor for a trackpad pinch.\n */\n point: Point\n\n /**\n * How far the focal point has moved since the gesture started.\n */\n offset: Point\n\n /**\n * The gesture's scale relative to its start.\n */\n scale: number\n\n /**\n * The gesture's rotation since its start, in degrees.\n */\n rotate: number\n}\n\n/**\n * Called with the latest event and the gesture's info.\n *\n * @public\n */\nexport type OnPinchEvent = (event: Event, info: PinchInfo) => void\n\n/**\n * Handlers for a single pinch gesture, returned from the pinch start\n * callback.\n *\n * @public\n */\nexport interface PinchHandlers {\n /**\n * Called each frame the gesture changes, after the element's values\n * are updated.\n */\n onPinch?: OnPinchEvent\n\n /**\n * Called once when the gesture ends: a touch lifts or is cancelled, a\n * trackpad pinch stops, or the gesture is disabled or removed.\n *\n * Returning this function directly from the pinch start callback is\n * equivalent.\n */\n onComplete?: OnPinchEvent\n}\n\n/**\n * Called once when a pinch gesture starts: when a second touch lands, on\n * the first trackpad pinch event, or on Safari's `gesturestart`. Can\n * return a function to call when the pinch ends, or an object of\n * `PinchHandlers`.\n *\n * @public\n */\nexport type OnPinchStartEvent = (\n element: Element,\n event: Event\n) => OnPinchEvent | PinchHandlers | void\n\n/**\n * The limits of a pinch's scale or rotation.\n *\n * @public\n */\nexport interface PinchLimits {\n /**\n * The minimum. Past it, the gesture resists by `elastic`, and the\n * value springs back to it on release.\n */\n min?: number\n\n /**\n * The maximum. Past it, the gesture resists by `elastic`, and the\n * value springs back to it on release.\n */\n max?: number\n}\n\n/**\n * @public\n */\nexport interface PinchRotateOptions extends PinchLimits {\n /**\n * On release, rotate to the nearest multiple of this many degrees.\n */\n snap?: number\n}\n\n/**\n * @public\n */\nexport interface PinchOptions {\n /**\n * Scale the element. Defaults to `true`. Pass `{ min, max }` to limit\n * the scale.\n */\n scale?: boolean | PinchLimits\n\n /**\n * Rotate the element with the touches. Defaults to `true`. Pass\n * `{ min, max }` (in degrees) to limit the rotation, and `snap` to\n * rotate to the nearest multiple of `snap` degrees on release.\n */\n rotate?: boolean | PinchRotateOptions\n\n /**\n * Move the element with the focal point, and keep the point under the\n * fingers (or cursor) in place while scaling and rotating. Defaults to\n * `true`. Composes with drag: a drag that one of the touches started\n * carries on from wherever the pinch leaves the element (its offset\n * restarts there). Drag constraints aren't applied while pinching.\n *\n * Assumes the default `transform-origin` (the element's centre).\n */\n pan?: boolean\n\n /**\n * The point that scale and rotation pivot around. `\"pointer\"` (the\n * default) is the focal point between the touches, or the cursor.\n * `{ x, y }` is a point on the element, as a fraction of its width\n * and height: `{ x: 0.5, y: 0.5 }` is its centre. With `pan: false`,\n * the default is the centre.\n */\n origin?: \"pointer\" | Point\n\n /**\n * How far scale and rotation can go past their limits, as for\n * `dragElastic`: `0` stops at the limit, `1` doesn't resist. Pass\n * `{ min, max }` to set each side. Defaults to `0.35`.\n */\n elastic?: boolean | number | PinchLimits\n\n /**\n * On release, animate scale back to `1`, and rotation and `x`/`y`\n * back to `0`.\n */\n snapToOrigin?: boolean\n\n /**\n * The spring values use to animate back inside their limits, to a\n * `snap` angle or to their origin.\n */\n transition?: SpringOptions\n}\n\n/**\n * Options for the `pinch` prop.\n *\n * @public\n */\nexport interface PinchProps extends PinchOptions {\n /**\n * Called when the pinch starts.\n */\n onStart?: OnPinchEvent\n\n /**\n * Called each frame the pinch changes.\n */\n onMove?: OnPinchEvent\n\n /**\n * Called when the pinch ends.\n */\n onEnd?: OnPinchEvent\n}\n\nexport type PinchValues = [\n scale: MotionValue<number>,\n rotate: MotionValue<number>,\n x: MotionValue<number>,\n y: MotionValue<number>,\n]\n\n/**\n * A trackpad pinch arrives as a stream of `wheel` events with no end\n * event, so it ends once none have arrived for this long.\n */\nconst wheelTimeout = 150\n\n/**\n * Convert an `x`/`y` set in other units (e.g. `\"-50%\"` to centre an\n * element) to pixels, so the gesture can add to it.\n */\nconst toPixels = (value: MotionValue<number>, size: number) => {\n const latest = value.get() as number | string\n\n if (typeof latest === \"string\") {\n value.set(parseFloat(latest) * (latest.endsWith(\"%\") ? size / 100 : 1))\n }\n}\n\nconst limitsOf = (option?: boolean | PinchRotateOptions): PinchRotateOptions =>\n typeof option === \"object\" ? option : {}\n\n/**\n * Resolve `elastic` to a resistance for each side, as for `dragElastic`.\n */\nconst resolveElastic = (\n elastic: PinchOptions[\"elastic\"] = defaultElastic\n): { min: number; max: number } => {\n const side = (value?: number | boolean) =>\n value === true ? defaultElastic : +(value || 0)\n\n return typeof elastic === \"object\"\n ? { min: side(elastic.min), max: side(elastic.max) }\n : { min: side(elastic), max: side(elastic) }\n}\n\n/**\n * Whether the gesture writes `x`/`y`: to follow the focal point, or to\n * keep an `origin` on the element in place.\n */\nconst writesXY = ({ pan, origin }: PinchOptions) => pan !== false || !!origin\n\nconst clampTo = (value: number, { min = -Infinity, max = Infinity }) =>\n clamp(min, max, value)\n\n/**\n * The raw gesture value that elastic shows as `value`. A pinch that starts\n * while a value is still past its limit (like during a spring back) carries\n * on from it, rather than jumping.\n */\nconst unconstrain = (\n value: number,\n option: boolean | PinchRotateOptions | undefined,\n resistance: { min: number; max: number }\n) => {\n const limit = clampTo(value, limitsOf(option))\n const elastic = resistance[value < limit ? \"min\" : \"max\"]\n\n return elastic ? limit + (value - limit) / elastic : value\n}\n\n/**\n * Listen for pinch gestures on `element`: two touches (or pens), a trackpad\n * pinch (`wheel` with `ctrlKey`, as Chrome, Edge and Firefox report it),\n * and Safari's `gesture*` events.\n *\n * `getValues` is called each time a gesture starts, in the frame's read\n * step, for the scale/rotate/x/y values to write to. It runs alongside the\n * element measurement so neither forces a layout.\n *\n * `getOptions` is read whenever it's needed, so options can change while\n * listening. Return `false` to disable the gesture, which also ends one in\n * progress.\n *\n * `onPinchStart` is called once as each gesture starts, with the gesture's\n * info as a third argument. It can return the gesture's handlers, as for\n * `pinch()`.\n */\nexport function addPinchListeners(\n element: Element,\n getValues: () => PinchValues,\n getEnabledOptions: () => PinchOptions | false | undefined,\n onPinchStart: (\n element: Element,\n event: Event,\n info: PinchInfo\n ) => ReturnType<OnPinchStartEvent>\n): VoidFunction {\n const pointers = new Map<number, Point>()\n\n /**\n * The gesture as last reported: focal point, log of a distance and an\n * angle. Only changes in distance and angle matter, so trackpad and\n * Safari input write a virtual distance (the scale) here. Logs keep\n * a long trackpad pinch from overflowing.\n */\n const current = { x: 0, y: 0, l: 0, a: 0 }\n const start = { ...current }\n const prev = { ...current }\n\n let source: \"pointer\" | \"wheel\" | \"gesture\" | undefined\n let lastEvent: Event\n let values: PinchValues | undefined\n let originX = 0\n let originY = 0\n let width = 0\n let height = 0\n let lastX = 0\n let lastY = 0\n let hasMoved = false\n let wheelTime = 0\n let handlers: PinchHandlers = {}\n let unlock: VoidFunction | null | undefined\n\n /**\n * The gesture's scale and rotation before limits and elastic apply.\n */\n let rawScale = 1\n let rawRotate = 0\n let stopSnap = () => {}\n\n /**\n * The latest enabled options, so a gesture disabled mid-way can still\n * report its end.\n */\n let options: PinchOptions = {}\n const getOptions = () => (options = getEnabledOptions() || options)\n\n const info = (): PinchInfo => ({\n point: { x: current.x, y: current.y },\n offset: { x: current.x - start.x, y: current.y - start.y },\n scale: Math.exp(current.l - start.l),\n rotate: current.a - start.a,\n })\n\n /**\n * Read the element's box and values, and find its layout origin: its\n * centre without `x`/`y`. Scale and rotate are applied around the\n * centre (the default transform origin), so they don't move it.\n */\n const measure = () => {\n const box = element.getBoundingClientRect()\n const { left, top } = box\n const { scale, rotate, elastic } = getOptions()\n const [s, r, x, y] = (values = getValues())\n const resistance = resolveElastic(elastic)\n\n /**\n * Stop animations on values this gesture writes, and leave the\n * rest running.\n */\n scale !== false && s.stop()\n rotate !== false && r.stop()\n rawScale = unconstrain(s.get(), scale, resistance)\n rawRotate = unconstrain(r.get(), rotate, resistance)\n\n width = (element as HTMLElement).offsetWidth ?? box.width\n height = (element as HTMLElement).offsetHeight ?? box.height\n\n if (writesXY(options)) {\n x.stop()\n y.stop()\n toPixels(x, width)\n toPixels(y, height)\n }\n\n lastX = x.get()\n lastY = y.get()\n originX = left + box.width / 2 - lastX\n originY = top + box.height / 2 - lastY\n }\n\n /**\n * The point scale and rotation pivot around, in client coordinates:\n * the focal point, or `origin` on the element at scale `s`, rotation\n * `r` and offset `x`/`y`.\n */\n const pivot = (\n focal: Point,\n s: number,\n r: number,\n x: number,\n y: number\n ): Point => {\n const { origin } = options\n if (typeof origin !== \"object\") return focal\n\n const a = (r * Math.PI) / 180\n const u = (origin.x - 0.5) * width * s\n const v = (origin.y - 0.5) * height * s\n\n return {\n x: originX + x + Math.cos(a) * u - Math.sin(a) * v,\n y: originY + y + Math.sin(a) * u + Math.cos(a) * v,\n }\n }\n\n const dragControls = () =>\n elementDragControls.get(visualElementStore.get(element)!)\n\n /**\n * On release, spring scale and rotation back inside their limits (or\n * to a `snap` angle), keeping the focal point in place, or everything\n * back to its origin with `snapToOrigin`.\n */\n const snap = () => {\n const {\n scale: scaleOption,\n rotate: rotateOption,\n snapToOrigin,\n transition,\n } = options\n const [scale, rotate, x, y] = values!\n const s0 = scale.get()\n const r0 = rotate.get()\n const x0 = x.get()\n const y0 = y.get()\n const { snap: step } = limitsOf(rotateOption)\n let s1 = clampTo(s0, limitsOf(scaleOption))\n /**\n * Snap to the step nearest where the release velocity would carry\n * the rotation, found as inertia finds its target (with a lower power\n * than inertia's 0.8).\n */\n let r1 = clampTo(\n step\n ? Math.round((r0 + 0.2 * rotate.getVelocity()) / step) * step\n : r0,\n limitsOf(rotateOption)\n )\n\n if (snapToOrigin) {\n s1 = 1\n // The nearest upright angle, so it turns the shortest way\n r1 = Math.round(r0 / 360) * 360\n }\n\n /**\n * Keep the focal point in place, unless the element doesn't move\n * with it, or a drag carries on and owns x/y.\n */\n const moves = writesXY(options) && !dragControls()?.isDragging\n const p0 = pivot(current, s0, r0, x0, y0)\n const vx = originX + x0 - p0.x\n const vy = originY + y0 - p0.y\n\n /**\n * Scale, rotation and x/y at progress `p` of the snap, keeping the\n * focal point in place.\n */\n const at = (p: number) => {\n const k = mixNumber(s0, s1, p)\n const r = mixNumber(r0, r1, p)\n const angle = ((r - r0) * Math.PI) / 180\n const cos = (Math.cos(angle) * k) / s0\n const sin = (Math.sin(angle) * k) / s0\n return [\n k,\n r,\n x0 + cos * vx - sin * vy - vx,\n y0 + sin * vx + cos * vy - vy,\n ]\n }\n\n if (\n !s0 ||\n (s1 === s0 && r1 === r0 && !(snapToOrigin && moves && (x0 || y0)))\n ) {\n return\n }\n\n const generator = spring({\n keyframes: [0, 1],\n stiffness: 200,\n damping: 40,\n ...transition,\n })\n const startTime = time.now()\n\n /**\n * Drive the values from one spring, from 0 to 1, so they stay in\n * step and the focal point stays in place.\n */\n const tick = () => {\n const { value: p, done } = generator.next(time.now() - startTime)\n if (done) stopSnap()\n\n const [k, r, fx, fy] = at(p)\n\n scaleOption !== false && scale.set(k)\n rotateOption !== false && rotate.set(r)\n\n // A drag that starts mid-snap owns x/y from then on.\n if (moves && !dragControls()?.isDragging) {\n x.set(snapToOrigin ? mixNumber(x0, 0, p) : fx)\n y.set(snapToOrigin ? mixNumber(y0, 0, p) : fy)\n }\n }\n\n stopSnap = () => cancelFrame(tick)\n frame.update(tick, true)\n }\n\n /**\n * Apply the change in the gesture since the last frame as an\n * incremental scale and rotation around the previous focal point,\n * plus the focal point's movement.\n */\n const apply = () => {\n if (!values || !hasMoved) return\n hasMoved = false\n\n const {\n rotate: rotateOption,\n scale: scaleOption,\n pan,\n elastic,\n } = getOptions()\n const [scale, rotate, x, y] = values\n const resistance = resolveElastic(elastic)\n const latest = scale.get()\n const drag = dragControls()\n const isDragging = drag?.isDragging\n\n if (!isDragging) {\n lastX = x.get()\n lastY = y.get()\n }\n\n const p = pivot(prev, latest, rotate.get(), lastX, lastY)\n let theta = 0\n let k = 1\n\n /**\n * Apply limits and elastic to the gesture's raw scale and rotation.\n * At a hard limit, the raw value stops too, so moving back responds\n * straight away.\n */\n const constrain = (raw: number, option?: boolean | PinchLimits) => {\n const limits = limitsOf(option)\n const limit = clampTo(raw, limits)\n\n return resistance[raw < limit ? \"min\" : \"max\"]\n ? [applyConstraints(raw, limits, resistance), raw]\n : [limit, limit]\n }\n\n if (scaleOption !== false && latest) {\n const [next, raw] = constrain(\n clamp(1e-9, 1e9, rawScale * Math.exp(current.l - prev.l)),\n scaleOption\n )\n rawScale = raw\n k = next / latest\n scale.set(next)\n }\n\n if (rotateOption !== false) {\n const [next, raw] = constrain(\n rawRotate + current.a - prev.a,\n rotateOption\n )\n rawRotate = raw\n theta = next - rotate.get()\n if (theta) rotate.set(next)\n }\n\n if (writesXY(options)) {\n /**\n * Pinch owns x/y while it runs, so stop any animation started\n * on them since (like a drag's snap back) taking over after.\n */\n x.stop()\n y.stop()\n\n /**\n * If drag() or the drag prop is dragging this element with one\n * of the touches, it has set x/y this frame to where it started\n * plus the touch's offset. Carry on from our own values instead,\n * and restart the drag from them and the touch's latest point.\n * That way it continues from wherever the pinch leaves the\n * element, and its release velocity only counts movement after\n * the pinch, so a zoom doesn't end in a fling.\n */\n const angle = (theta * Math.PI) / 180\n const cos = Math.cos(angle) * k\n const sin = Math.sin(angle) * k\n const dx = p.x - originX - lastX\n const dy = p.y - originY - lastY\n const panX = pan !== false ? current.x - prev.x : 0\n const panY = pan !== false ? current.y - prev.y : 0\n\n /**\n * Move the centre so the pivot, scaled and rotated around the\n * centre, stays in place, plus the focal point's movement.\n */\n lastX += dx + panX - (cos * dx - sin * dy)\n lastY += dy + panY - (sin * dx + cos * dy)\n\n if (isDragging) {\n const history = drag!.panSession!.history\n history.splice(0, history.length - 1)\n\n /**\n * Date the point long ago, so drag only measures release\n * velocity from moves after the pinch. A move that drag\n * processes as the touch lifts is part of the pinch.\n */\n history[0].timestamp = -Infinity\n drag!.originPoint.x = lastX\n drag!.originPoint.y = lastY\n }\n\n x.set(lastX)\n y.set(lastY)\n }\n\n Object.assign(prev, current)\n handlers.onPinch?.(lastEvent, info())\n }\n\n /**\n * Runs after the update step, where drag sets x/y, so it has the final\n * say on them each frame.\n */\n const update = () => {\n if (!getEnabledOptions()) return end(lastEvent)\n\n apply()\n\n if (source === \"wheel\" && time.now() - wheelTime > wheelTimeout) {\n end(lastEvent)\n }\n }\n\n const begin = (event: Event, from: typeof source) => {\n if (!getEnabledOptions()) return\n\n stopSnap()\n source = from\n lastEvent = event\n hasMoved = false\n values = undefined\n handlers = {}\n Object.assign(start, current)\n Object.assign(prev, current)\n frame.read(measure)\n frame.preRender(update, true)\n\n const result = onPinchStart(element, event, info())\n handlers =\n typeof result === \"function\" ? { onComplete: result } : result || {}\n }\n\n const end = (event: Event) => {\n if (!source) return\n cancelFrame(measure)\n cancelFrame(update)\n\n if (getEnabledOptions()) {\n apply()\n values && snap()\n }\n\n source = undefined\n handlers.onComplete?.(event, info())\n }\n\n const moved = (event: Event) => {\n lastEvent = event\n hasMoved = true\n }\n\n const readPointers = () => {\n const [a, b] = pointers.values()\n const angle = (Math.atan2(b.y - a.y, b.x - a.x) * 180) / Math.PI\n const delta = angle - current.a\n\n current.x = (a.x + b.x) / 2\n current.y = (a.y + b.y) / 2\n current.l = Math.log(Math.hypot(b.x - a.x, b.y - a.y) || 1)\n\n /**\n * Take the shortest way round, so rotation keeps counting past\n * 180deg rather than flipping to -180deg.\n */\n current.a += delta - 360 * Math.round(delta / 360)\n }\n\n const setPointer = (event: PointerEvent) =>\n pointers.set(event.pointerId, { x: event.clientX, y: event.clientY })\n\n const onPointerMove = (event: PointerEvent) => {\n if (!pointers.has(event.pointerId)) return\n setPointer(event)\n\n if (source === \"pointer\") {\n readPointers()\n moved(event)\n }\n }\n\n const onPointerUp = (event: PointerEvent) => {\n if (!pointers.delete(event.pointerId)) return\n\n if (source === \"pointer\") end(event)\n\n if (!pointers.size) {\n toggleWindowListeners()\n release()\n }\n }\n\n /**\n * Once a touch is down on the element, listen on the window too, so\n * the second touch can land beside it (for instance on a small image).\n */\n const onPointerDown = (event: PointerEvent) => {\n if (\n source ||\n pointers.size > 1 ||\n pointers.has(event.pointerId) ||\n event.pointerType === \"mouse\"\n ) {\n return\n }\n\n if (!pointers.size) toggleWindowListeners(true)\n setPointer(event)\n\n if (pointers.size === 2) {\n readPointers()\n begin(event, \"pointer\")\n\n /**\n * Unless this element drags, hold the drag lock until every\n * touch lifts. A press on it then ends as a cancel, rather than\n * a tap, and a draggable parent doesn't drag.\n */\n if (\n source &&\n !unlock &&\n !elementDragControls.get(visualElementStore.get(element)!)\n ) {\n unlock = setDragLock(true)\n }\n }\n }\n\n /**\n * Release the drag lock a frame later, so a press ending on this same\n * pointerup still sees it.\n */\n const release = () => {\n const done = unlock\n unlock = undefined\n done && frame.postRender(done)\n }\n\n const toggleWindowListeners = (add?: boolean) => {\n const method = add ? \"addEventListener\" : \"removeEventListener\"\n window[method](\"pointerdown\", onPointerDown as EventListener)\n window[method](\"pointermove\", onPointerMove as EventListener)\n window[method](\"pointerup\", onPointerUp as EventListener)\n window[method](\"pointercancel\", onPointerUp as EventListener)\n }\n\n const onWheel = (event: WheelEvent) => {\n if (!event.ctrlKey || (source && source !== \"wheel\")) return\n\n current.x = event.clientX\n current.y = event.clientY\n\n if (!source) {\n current.l = 0\n begin(event, \"wheel\")\n if (!source) return\n }\n\n event.preventDefault()\n\n /**\n * Lines (Firefox's mouse wheel) to pixels, and cap each event so a\n * mouse wheel notch with ctrl held (about 100px) zooms a step.\n */\n current.l -=\n clamp(-50, 50, event.deltaY * (event.deltaMode ? 16 : 1)) / 100\n wheelTime = time.now()\n moved(event)\n }\n\n /**\n * Safari reports trackpad pinches as `gesture*` events. iOS Safari\n * fires them for touches too, alongside the pointer events we track.\n */\n const onGesture = (event: Event) => {\n if (!pointers.size && (!source || source === \"gesture\")) {\n const { scale, rotation, clientX, clientY } = event as any\n current.x = clientX\n current.y = clientY\n current.l = Math.log(scale)\n current.a = rotation\n\n if (source) {\n moved(event)\n if (event.type === \"gestureend\") end(event)\n } else if (event.type === \"gesturestart\") {\n begin(event, \"gesture\")\n }\n }\n\n if (source) event.preventDefault()\n }\n\n const listeners = {\n pointerdown: onPointerDown,\n wheel: onWheel,\n gesturestart: onGesture,\n gesturechange: onGesture,\n gestureend: onGesture,\n }\n\n for (const name in listeners) {\n element.addEventListener(\n name,\n listeners[name as keyof typeof listeners] as EventListener,\n { passive: false }\n )\n }\n\n return () => {\n for (const name in listeners) {\n element.removeEventListener(\n name,\n listeners[name as keyof typeof listeners] as EventListener\n )\n }\n toggleWindowListeners()\n end(lastEvent)\n stopSnap()\n pointers.clear()\n release()\n }\n}\n\nconst valueKeys = [\"scale\", \"rotate\", \"x\", \"y\"]\n\n/**\n * The element's scale/rotate/x/y motion values: those of its\n * VisualElement if it has one (it's a <motion.*> component, or drag() or\n * animateLayout() own it), otherwise those animate() binds to it, created\n * from its current style if this is the first time.\n */\nconst getElementValues = (element: HTMLElement | SVGElement) => {\n const visualElement = visualElementStore.get(element)\n const effect = isSVGElement(element) ? svgSubjectEffect : styleSubjectEffect\n\n return valueKeys.map((key) => {\n if (visualElement) {\n return visualElement.getValue(key, key === \"scale\" ? 1 : 0)\n }\n\n let value = effect.get(element as any, key)\n\n if (!value) {\n value = motionValue(readStyleValue(element, key))\n effect(element as any, { [key]: value })\n }\n\n return value\n }) as PinchValues\n}\n\n/**\n * Make elements pinchable. Returns a function that removes the gesture.\n * The start callback is optional:\n *\n * ```javascript\n * pinch(\"img\")\n * pinch(\"img\", { scale: { min: 1, max: 4 } })\n * ```\n *\n * ```javascript\n * const stop = pinch(\"#photo\", (element, startEvent) => {\n * return (endEvent, info) => {}\n * }, { scale: { min: 1, max: 4 } })\n * ```\n *\n * `onPinchStart` is called once as each pinch starts. It can return a\n * function to call when the pinch ends, or an object of handlers:\n *\n * ```javascript\n * pinch(\"#photo\", () => ({\n * onPinch: (event, { scale }) => {},\n * onComplete: (event, info) => {},\n * }))\n * ```\n *\n * Touches, trackpad pinches and Safari's gesture events scale the element\n * around the focal point and move it with the touches. Its `scale`,\n * `rotate`, `x` and `y` are motion values shared with `animate()`, so an\n * `onComplete` handler can animate the element after a pinch.\n *\n * @public\n */\nexport function pinch(\n elementOrSelector: ElementOrSelector,\n options?: PinchOptions\n): VoidFunction\nexport function pinch(\n elementOrSelector: ElementOrSelector,\n onPinchStart?: OnPinchStartEvent,\n options?: PinchOptions\n): VoidFunction\nexport function pinch(\n elementOrSelector: ElementOrSelector,\n startOrOptions?: OnPinchStartEvent | PinchOptions,\n options: PinchOptions = {}\n): VoidFunction {\n let onPinchStart: OnPinchStartEvent = () => {}\n\n if (typeof startOrOptions === \"function\") {\n onPinchStart = startOrOptions\n } else if (startOrOptions) {\n options = startOrOptions\n }\n\n const scope = activeScope.current\n\n /**\n * Run the start callback and the handlers it returns in the active\n * scope, so work they start is collected. A returned function is\n * bound by `scope.bind` itself.\n */\n if (scope) {\n const start = scope.bind(onPinchStart)\n onPinchStart = (element, event) => {\n const result = start(element, event)\n if (typeof result !== \"object\") return result\n\n const handlers: PinchHandlers = {}\n for (const key in result) {\n const name = key as keyof PinchHandlers\n const handler = result[name]\n handlers[name] = handler && scope.bind(handler)\n }\n return handlers\n }\n }\n\n const cleanups = resolveElements(elementOrSelector).map((element) => {\n scope?.track(element)\n\n const { style } = element as HTMLElement\n const touchAction = style.touchAction\n style.touchAction = \"none\"\n\n const remove = addPinchListeners(\n element,\n () => getElementValues(element as HTMLElement),\n () => options,\n onPinchStart\n )\n\n return () => {\n remove()\n style.touchAction = touchAction\n }\n })\n\n return addToScope(() => cleanups.forEach((cleanup) => cleanup()))\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA4MA;;;AAGG;AACH,MAAM,YAAY,GAAG,GAAG;AAExB;;;AAGG;AACH,MAAM,QAAQ,GAAG,CAAC,KAA0B,EAAE,IAAY,KAAI;AAC1D,IAAA,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAqB;AAE7C,IAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC5B,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC;IAC3E;AACJ,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,MAAqC,KACnD,OAAO,MAAM,KAAK,QAAQ,GAAG,MAAM,GAAG,EAAE;AAE5C;;AAEG;AACH,MAAM,cAAc,GAAG,CACnB,OAAA,GAAmC,cAAc,KACnB;IAC9B,MAAM,IAAI,GAAG,CAAC,KAAwB,KAClC,KAAK,K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GAAG,CAAC,CAAC,OAAO,KAAI;AAChE,QAAA,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;AAErB,QAAA,MAAM,EAAE,KAAK,EAAE,GAAG,OAAsB;AACxC,QAAA,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW;AACrC,QAAA,KAAK,CAAC,WAAW,GAAG,MAAM;QAE1B,MAAM,MAAM,GAAG,iBAAiB,CAC5B,OAAO,EACP,MAAM,gBAAgB,CAAC,OAAsB,CAAC,EAC9C,MAAM,OAAO,EACb,YAAY,CACf;AAED,QAAA,OAAO,MAAK;AACR,YAAA,MAAM,EAAE;AACR,YAAA,KAAK,CAAC,WAAW,GAAG,WAAW;AACnC,QAAA,CAAC;AACL,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,UAAU,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC,CAAC;AACrE;;;;"}
package/dist/es/index.mjs CHANGED
@@ -24,7 +24,7 @@ export { optimizedAppearDataAttribute, optimizedAppearDataId } from './animation
24
24
  export { getOptimisedAppearId } from './animation/optimized-appear/get-appear-id.mjs';
25
25
  export { inertia } from './animation/generators/inertia.mjs';
26
26
  export { defaultEasing, keyframes } from './animation/generators/keyframes.mjs';
27
- export { spring } from './animation/generators/spring.mjs';
27
+ export { getSpringOptions, spring } from './animation/generators/spring.mjs';
28
28
  export { calcGeneratorDuration, maxGeneratorDuration } from './animation/generators/utils/calc-duration.mjs';
29
29
  export { createGeneratorEasing } from './animation/generators/utils/create-generator-easing.mjs';
30
30
  export { isGenerator } from './animation/generators/utils/is-generator.mjs';
@@ -0,0 +1,28 @@
1
+ import { clamp, secondsToMilliseconds } from 'motion-utils';
2
+ import { getSpringOptions } from '../../animation/generators/spring.mjs';
3
+
4
+ /**
5
+ * A curved path ties x and y to one progress value, so it takes the part of
6
+ * the velocity along the straight line from start to end.
7
+ */
8
+ const pointToProgressVelocity = (tx, ty, { x, y }) => {
9
+ const lengthSquared = tx * tx + ty * ty;
10
+ return lengthSquared < 1 ? 0 : (-1e3 * (x * tx + y * ty)) / lengthSquared;
11
+ };
12
+ /**
13
+ * With `mass: "auto"`, mass comes from the element's size: a 300px square
14
+ * has mass 1, bigger elements are heavier and slower (mass 0.25 to 2), and
15
+ * damping scales with mass so the spring keeps its bounce. The result is a
16
+ * physics spring.
17
+ */
18
+ const resolveAutoMass = (t, size = 300) => {
19
+ const mass = clamp(0.25, 2, size / 300);
20
+ const { stiffness, damping } = getSpringOptions({
21
+ ...t,
22
+ duration: t.duration && secondsToMilliseconds(t.duration),
23
+ });
24
+ return { ...t, stiffness, damping: damping * Math.sqrt(mass), mass };
25
+ };
26
+
27
+ export { pointToProgressVelocity, resolveAutoMass };
28
+ //# sourceMappingURL=layout-velocity.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-velocity.mjs","sources":["../../../../src/projection/animation/layout-velocity.ts"],"sourcesContent":["import { clamp, Point, secondsToMilliseconds } from \"motion-utils\"\nimport { getSpringOptions } from \"../../animation/generators/spring\"\nimport type { ValueAnimationOptions } from \"../../animation/types\"\n\n/**\n * A curved path ties x and y to one progress value, so it takes the part of\n * the velocity along the straight line from start to end.\n */\nexport const pointToProgressVelocity = (\n tx: number,\n ty: number,\n { x, y }: Point\n) => {\n const lengthSquared = tx * tx + ty * ty\n return lengthSquared < 1 ? 0 : (-1000 * (x * tx + y * ty)) / lengthSquared\n}\n\n/**\n * With `mass: \"auto\"`, mass comes from the element's size: a 300px square\n * has mass 1, bigger elements are heavier and slower (mass 0.25 to 2), and\n * damping scales with mass so the spring keeps its bounce. The result is a\n * physics spring.\n */\nexport const resolveAutoMass = (\n t: any,\n size = 300\n): ValueAnimationOptions<number> => {\n const mass = clamp(0.25, 2, size / 300)\n const { stiffness, damping } = getSpringOptions({\n ...t,\n duration: t.duration && secondsToMilliseconds(t.duration),\n })\n return { ...t, stiffness, damping: damping * Math.sqrt(mass), mass }\n}\n"],"names":[],"mappings":";;;AAIA;;;AAGG;AACI,MAAM,uBAAuB,GAAG,CACnC,EAAU,EACV,EAAU,EACV,EAAE,CAAC,EAAE,CAAC,EAAS,KACf;IACA,MAAM,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;IACvC,OAAO,aAAa,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAK,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,aAAa;AAC9E;AAEA;;;;;AAKG;AACI,MAAM,eAAe,GAAG,CAC3B,CAAM,EACN,IAAI,GAAG,GAAG,KACqB;AAC/B,IAAA,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,GAAG,CAAC;AACvC,IAAA,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC;AAC5C,QAAA,GAAG,CAAC;QACJ,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,qBAAqB,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC5D,KAAA,CAAC;AACF,IAAA,OAAO,EAAE,GAAG,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE;AACxE;;;;"}
@@ -1,5 +1,7 @@
1
1
  import { SubscriptionManager, clamp } from 'motion-utils';
2
2
  import { animateSingleValue } from '../../animation/animate/single-value.mjs';
3
+ import { spring } from '../../animation/generators/spring.mjs';
4
+ import { calcGeneratorDuration } from '../../animation/generators/utils/calc-duration.mjs';
3
5
  import { notifyLayoutAnimationStart } from '../../animation/utils/notify-inspector.mjs';
4
6
  import { getOptimisedAppearId } from '../../animation/optimized-appear/get-appear-id.mjs';
5
7
  import { getValueTransition } from '../../animation/utils/get-value-transition.mjs';
@@ -15,6 +17,7 @@ import { mixNumber } from '../../utils/mix/number.mjs';
15
17
  import { motionValue } from '../../value/index.mjs';
16
18
  import { resolveMotionValue } from '../../value/utils/resolve-motion-value.mjs';
17
19
  import { mixValues } from '../animation/mix-values.mjs';
20
+ import { pointToProgressVelocity, resolveAutoMass } from '../animation/layout-velocity.mjs';
18
21
  import { transformGroups } from '../../animation/waapi/transforms/groups.mjs';
19
22
  import { copyBoxInto, copyAxisDeltaInto, copyAxisInto } from '../geometry/copy.mjs';
20
23
  import { translateAxis, transformBox, applyBoxDelta, applyTreeDeltas } from '../geometry/delta-apply.mjs';
@@ -655,6 +658,37 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
655
658
  !calcLength(this.snapshot.measuredBox.y)) {
656
659
  this.snapshot = undefined;
657
660
  }
661
+ /**
662
+ * Record how fast the element is moving when it's measured, so
663
+ * the next layout animation can start at the same speed.
664
+ */
665
+ if (this.snapshot) {
666
+ const { visualElement } = this.options;
667
+ /**
668
+ * A paused or stopped animation hands on no velocity.
669
+ */
670
+ const isRunning = this.currentAnimation?.state === "running";
671
+ const edges = isRunning && this.animationEdges;
672
+ /**
673
+ * A child moving inside its parent hands on only its
674
+ * velocity relative to the parent.
675
+ */
676
+ if (isRunning && this.relativeTarget) {
677
+ this.snapshot.relativeVelocity =
678
+ this.relativeVelocity?.slice() || [];
679
+ }
680
+ const progress = (edges && this.motionValue?.getVelocity()) || 0;
681
+ const velocity = [0, 1, 2, 3, 4, 5].map((i) => (i < 4
682
+ ? edges &&
683
+ (this.edgeValues
684
+ ? this.edgeVelocity(i)
685
+ : (-edges[i] * progress) / 1000)
686
+ : visualElement
687
+ ?.getValue(i < 5 ? "x" : "y")
688
+ ?.getVelocity()) || 0);
689
+ if (velocity.some(Boolean))
690
+ this.snapshot.velocity = velocity;
691
+ }
658
692
  }
659
693
  updateLayout() {
660
694
  if (!this.instance)
@@ -1180,11 +1214,62 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1180
1214
  // The path decides whether the layout shift is worth curving
1181
1215
  // (distance floor) and resolves the interpolator from the delta.
1182
1216
  const interpolate = pathFn?.interpolateProjection(delta);
1217
+ const box = this.layout?.layoutBox;
1218
+ let edges = box &&
1219
+ [box.x.min, box.x.max, box.y.min, box.y.max].map((edge, i) => {
1220
+ const { translate, scale, originPoint } = delta[i < 2 ? "x" : "y"];
1221
+ return (edge - originPoint) * (scale - 1) + translate;
1222
+ });
1223
+ /**
1224
+ * A zero-length layout axis has no finite edge offsets.
1225
+ */
1226
+ if (!edges?.every(isFinite))
1227
+ edges = undefined;
1228
+ this.animationEdges = edges;
1229
+ this.edgeValues =
1230
+ this.startVelocity =
1231
+ this.impulse =
1232
+ this.relativeVelocity =
1233
+ this.relativeStart =
1234
+ undefined;
1235
+ /**
1236
+ * A shared snapshot is measured with the old element's own
1237
+ * transforms (like x/y from drag), so it hands their velocity on
1238
+ * too. Otherwise those values keep animating themselves.
1239
+ */
1240
+ const velocity = snapshot?.velocity;
1241
+ /**
1242
+ * A child that wasn't moving inside an animating parent before
1243
+ * moved in page space, so that is its relative velocity.
1244
+ */
1245
+ const relative = snapshot?.relativeVelocity || velocity;
1246
+ if (relative?.slice(0, 4).some(Boolean) &&
1247
+ this.getClosestProjectingParent()) {
1248
+ this.relativeStart = relative;
1249
+ }
1250
+ if (velocity && edges) {
1251
+ const v = velocity
1252
+ .slice(0, 4)
1253
+ .map((edge, i) => edge +
1254
+ (isSharedLayoutAnimation
1255
+ ? velocity[4 + (i >> 1)]
1256
+ : 0));
1257
+ if (v.some(Boolean)) {
1258
+ this.startVelocity = interpolate
1259
+ ? pointToProgressVelocity(delta.x.translate, delta.y.translate, { x: (v[0] + v[1]) / 2, y: (v[2] + v[3]) / 2 })
1260
+ : v;
1261
+ }
1262
+ }
1183
1263
  this.mixTargetDelta = (latest) => {
1184
1264
  const progress = latest / 1000;
1185
1265
  const point = interpolate?.(progress);
1186
- mixAxisDeltaLinear(targetDelta.x, delta.x, progress);
1187
- mixAxisDeltaLinear(targetDelta.y, delta.y, progress);
1266
+ const values = this.edgeValues;
1267
+ for (let i = 0; i < 2; i++) {
1268
+ const axis = i ? "y" : "x";
1269
+ values
1270
+ ? edgesToDelta(targetDelta[axis], delta[axis], this.layout.layoutBox[axis], values[i * 2], values[i * 2 + 1])
1271
+ : mixAxisDeltaLinear(targetDelta[axis], delta[axis], progress);
1272
+ }
1188
1273
  if (point) {
1189
1274
  targetDelta.x.translate = point.x;
1190
1275
  targetDelta.y.translate = point.y;
@@ -1196,7 +1281,41 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1196
1281
  this.relativeParent &&
1197
1282
  this.relativeParent.layout) {
1198
1283
  calcRelativePosition(relativeLayout, this.layout.layoutBox, this.relativeParent.layout.layoutBox, this.options.layoutAnchor || undefined);
1199
- mixBox(this.relativeTarget, this.relativeTargetOrigin, relativeLayout, progress);
1284
+ const from = this.relativeTargetOrigin;
1285
+ const to = relativeLayout;
1286
+ /**
1287
+ * A child mixes its place in its parent by progress,
1288
+ * so a nested tree moves as one.
1289
+ */
1290
+ mixBox(this.relativeTarget, from, to, progress);
1291
+ /**
1292
+ * Springs are linear, so the child's own velocity adds
1293
+ * the impulse response on top of the mix.
1294
+ */
1295
+ /**
1296
+ * Only springs take velocity, so a tween skips this.
1297
+ */
1298
+ if (this.isSpringLayout) {
1299
+ const box = this.relativeTarget;
1300
+ const impulse = this.impulse || 0;
1301
+ const start = this.relativeStart;
1302
+ const now = time.now();
1303
+ const dt = (now - this.relativeTime) / 1000;
1304
+ this.relativeTime = now;
1305
+ const speeds = (this.relativeVelocity || (this.relativeVelocity = [0, 0, 0, 0]));
1306
+ for (let i = 0; i < 4; i++) {
1307
+ const axis = i < 2 ? "x" : "y";
1308
+ const edge = i & 1 ? "max" : "min";
1309
+ if (start)
1310
+ box[axis][edge] += start[i] * impulse;
1311
+ if (prevRelativeTarget && dt > 0) {
1312
+ speeds[i] =
1313
+ (box[axis][edge] -
1314
+ prevRelativeTarget[axis][edge]) /
1315
+ dt;
1316
+ }
1317
+ }
1318
+ }
1200
1319
  /**
1201
1320
  * If this is an unchanged relative target we can consider the
1202
1321
  * projection not dirty.
@@ -1228,8 +1347,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1228
1347
  }
1229
1348
  startAnimation(options) {
1230
1349
  this.notifyListeners("animationStart");
1350
+ const isSpring = (this.isSpringLayout = options.type === "spring");
1231
1351
  this.currentAnimation?.stop();
1232
1352
  this.resumingFrom?.currentAnimation?.stop();
1353
+ if (this.resumingFrom)
1354
+ this.resumingFrom.edgeValues = undefined;
1233
1355
  if (this.pendingAnimation) {
1234
1356
  cancelFrame(this.pendingAnimation);
1235
1357
  this.pendingAnimation = undefined;
@@ -1243,9 +1365,114 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1243
1365
  globalProjectionState.hasAnimatedSinceResize = true;
1244
1366
  this.motionValue || (this.motionValue = motionValue(0));
1245
1367
  this.motionValue.jump(0, false);
1246
- this.currentAnimation = animateSingleValue(this.motionValue, [0, 1000], {
1247
- ...options,
1248
- velocity: 0,
1368
+ /**
1369
+ * A duration spring ignores velocity, like in animate(), so
1370
+ * it ends on time.
1371
+ */
1372
+ const velocity = this.startVelocity;
1373
+ this.startVelocity = undefined;
1374
+ let transition = options;
1375
+ let mainVelocity = 0;
1376
+ if (isSpring) {
1377
+ /**
1378
+ * With mass: "auto", mass comes from the element's own
1379
+ * size.
1380
+ */
1381
+ if (options.mass === "auto") {
1382
+ const box = this.layout?.layoutBox;
1383
+ transition = resolveAutoMass(options, box &&
1384
+ Math.sqrt(calcLength(box.x) * calcLength(box.y)));
1385
+ }
1386
+ /**
1387
+ * Only springs take a velocity. A tween keeps one
1388
+ * driver, so its controls (pause, time) reach it all.
1389
+ */
1390
+ const relative = this.relativeStart;
1391
+ if ((velocity || relative) && !options.repeat) {
1392
+ if (typeof velocity === "number") {
1393
+ mainVelocity = velocity;
1394
+ }
1395
+ else {
1396
+ /**
1397
+ * Each edge (x min, x max, y min, y max) gets its
1398
+ * own spring in pixels, with its own start
1399
+ * velocity. An edge that doesn't move keeps
1400
+ * still, and a thrown element keeps its size.
1401
+ * One generator steps them all with the main
1402
+ * spring, so one animation drives them and its
1403
+ * controls reach them all.
1404
+ */
1405
+ const edges = velocity && this.animationEdges;
1406
+ transition = {
1407
+ ...transition,
1408
+ type: (o) => {
1409
+ const springs = [
1410
+ o.velocity,
1411
+ ...(velocity || []),
1412
+ ].map((v, i) => spring({
1413
+ ...o,
1414
+ keyframes: i
1415
+ ? [edges[i - 1], 0]
1416
+ : o.keyframes,
1417
+ velocity: v,
1418
+ }));
1419
+ const count = springs.length;
1420
+ /**
1421
+ * The response to 1000 px/s, for a
1422
+ * child's velocity inside its parent.
1423
+ * Coarse rest thresholds, because a
1424
+ * small offset of it is far below 1px.
1425
+ */
1426
+ relative &&
1427
+ springs.push(spring({
1428
+ ...o,
1429
+ keyframes: [0, 0],
1430
+ velocity: 1000,
1431
+ restDelta: 0.5,
1432
+ restSpeed: 5,
1433
+ }));
1434
+ let time = 0;
1435
+ const values = [];
1436
+ const generator = {
1437
+ calculatedDuration: null,
1438
+ next: (t) => {
1439
+ time = t;
1440
+ const state = springs[0].next(t);
1441
+ let done = state.done;
1442
+ for (let i = 1; i < springs.length; i++) {
1443
+ const { value, done: rest } = springs[i].next(t);
1444
+ if (i < count) {
1445
+ values[i - 1] = value;
1446
+ }
1447
+ else {
1448
+ this.impulse = value / 1000;
1449
+ }
1450
+ done = done && rest;
1451
+ }
1452
+ if (edges)
1453
+ this.edgeValues = values;
1454
+ state.done = done;
1455
+ return state;
1456
+ },
1457
+ };
1458
+ /**
1459
+ * Measure the duration now, then go back
1460
+ * to the start, so a delay shows the
1461
+ * start and not the end.
1462
+ */
1463
+ generator.calculatedDuration =
1464
+ calcGeneratorDuration(generator);
1465
+ generator.next(0);
1466
+ this.edgeVelocity = (i) => springs[i + 1].velocity(time);
1467
+ return generator;
1468
+ },
1469
+ };
1470
+ }
1471
+ }
1472
+ }
1473
+ const main = animateSingleValue(this.motionValue, [0, 1000], {
1474
+ ...transition,
1475
+ velocity: mainVelocity,
1249
1476
  isSync: true,
1250
1477
  onUpdate: (latest) => {
1251
1478
  this.mixTargetDelta(latest);
@@ -1256,6 +1483,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1256
1483
  this.completeAnimation();
1257
1484
  },
1258
1485
  });
1486
+ this.currentAnimation = main;
1259
1487
  notifyLayoutAnimationStart(this.currentAnimation, this);
1260
1488
  if (this.resumingFrom) {
1261
1489
  this.resumingFrom.currentAnimation = this.currentAnimation;
@@ -1273,11 +1501,15 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
1273
1501
  this.resumingFrom =
1274
1502
  this.currentAnimation =
1275
1503
  this.animationValues =
1276
- undefined;
1504
+ this.edgeValues =
1505
+ this.edgeVelocity =
1506
+ this.impulse =
1507
+ undefined;
1277
1508
  this.notifyListeners("animationComplete");
1278
1509
  }
1279
1510
  finishAnimation() {
1280
1511
  if (this.currentAnimation) {
1512
+ this.edgeValues = this.impulse = undefined;
1281
1513
  this.mixTargetDelta?.(animationTarget);
1282
1514
  this.currentAnimation.stop();
1283
1515
  }
@@ -1773,6 +2005,18 @@ function calcProjection(node) {
1773
2005
  function resetSkewAndRotation(node) {
1774
2006
  node.resetSkewAndRotation();
1775
2007
  }
2008
+ /**
2009
+ * Build an axis delta that moves the layout's edges by these offsets (px).
2010
+ */
2011
+ function edgesToDelta(output, delta, layout, min, max) {
2012
+ const length = layout.max - layout.min;
2013
+ const scale = length ? Math.max(0, (length + max - min) / length) : 1;
2014
+ const origin = (output.originPoint = delta.originPoint);
2015
+ output.origin = delta.origin;
2016
+ output.scale = scale;
2017
+ output.translate =
2018
+ layout.min + min - (origin + (layout.min - origin) * scale);
2019
+ }
1776
2020
  function mixAxisDeltaLinear(output, delta, p) {
1777
2021
  output.translate = mixNumber(delta.translate, 0, p);
1778
2022
  output.scale = mixNumber(delta.scale, 1, p);