motion-dom 14.10.0 → 14.11.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.
Files changed (46) hide show
  1. package/dist/cjs/index.js +886 -126
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/GroupAnimation.mjs +21 -15
  4. package/dist/es/animation/GroupAnimation.mjs.map +1 -1
  5. package/dist/es/animation/animate/effects.mjs +15 -4
  6. package/dist/es/animation/animate/effects.mjs.map +1 -1
  7. package/dist/es/animation/animate/single-value.mjs +1 -1
  8. package/dist/es/animation/animate/single-value.mjs.map +1 -1
  9. package/dist/es/animation/generators/keyframes.mjs +44 -16
  10. package/dist/es/animation/generators/keyframes.mjs.map +1 -1
  11. package/dist/es/animation/interfaces/visual-element-target.mjs +1 -1
  12. package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
  13. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +8 -3
  14. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
  15. package/dist/es/animation/keyframes/get-final.mjs +18 -4
  16. package/dist/es/animation/keyframes/get-final.mjs.map +1 -1
  17. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +155 -42
  18. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
  19. package/dist/es/gestures/drag/VisualElementDragControls.mjs +4 -0
  20. package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
  21. package/dist/es/gestures/pan/PanSession.mjs.map +1 -1
  22. package/dist/es/gestures/pinch/index.mjs +552 -0
  23. package/dist/es/gestures/pinch/index.mjs.map +1 -0
  24. package/dist/es/gestures/press/index.mjs +6 -2
  25. package/dist/es/gestures/press/index.mjs.map +1 -1
  26. package/dist/es/index.mjs +1 -0
  27. package/dist/es/index.mjs.map +1 -1
  28. package/dist/es/projection/styles/transform.mjs +39 -17
  29. package/dist/es/projection/styles/transform.mjs.map +1 -1
  30. package/dist/es/render/utils/get-variant-context.mjs.map +1 -1
  31. package/dist/es/render/utils/variant-props.mjs +1 -0
  32. package/dist/es/render/utils/variant-props.mjs.map +1 -1
  33. package/dist/es/value/index.mjs +24 -20
  34. package/dist/es/value/index.mjs.map +1 -1
  35. package/dist/es/value/types/utils/animatable-none.mjs +13 -1
  36. package/dist/es/value/types/utils/animatable-none.mjs.map +1 -1
  37. package/dist/index.d.ts +360 -105
  38. package/dist/motion-dom.dev.js +886 -126
  39. package/dist/motion-dom.js +1 -1
  40. package/dist/size-rollup-motion-value.js +1 -1
  41. package/dist/size-rollup-motion-value.js.map +1 -1
  42. package/dist/size-rollup-pinch.js +2 -0
  43. package/dist/size-rollup-pinch.js.map +1 -0
  44. package/dist/size-rollup-style-effect.js +1 -1
  45. package/dist/size-rollup-style-effect.js.map +1 -1
  46. package/package.json +6 -2
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/gestures/press/index.ts"],"sourcesContent":["import { secondsToMilliseconds } from \"motion-utils\"\nimport { cancelFrame, frame } from \"../../frameloop/frame\"\nimport { time } from \"../../frameloop/sync-time\"\nimport { bindToScope } from \"../../scope/active\"\nimport { isHTMLElement } from \"../../utils/is-html-element\"\nimport { ElementOrSelector } from \"../../utils/resolve-elements\"\nimport { isDragActive } from \"../drag/state/is-active\"\nimport { EventOptions } from \"../types\"\nimport { isNodeOrChild } from \"../utils/is-node-or-child\"\nimport { isPrimaryPointer } from \"../utils/is-primary-pointer\"\nimport { setupGesture } from \"../utils/setup\"\nimport { OnPressStartEvent, PressHandlers, PressOptions } from \"./types\"\nimport { isElementKeyboardAccessible } from \"./utils/is-keyboard-accessible\"\nimport { enableKeyboardPress } from \"./utils/keyboard\"\nimport { isPressing } from \"./utils/state\"\n\n/**\n * Filter out events that are not primary pointer events, or are triggering\n * while a Motion gesture is active.\n */\nfunction isValidPressEvent(event: PointerEvent) {\n return isPrimaryPointer(event) && !isDragActive()\n}\n\nconst claimedPointerDownEvents = new WeakSet<Event>()\n\n/**\n * Max distance in px between consecutive presses of a `count` sequence.\n * Android's `ViewConfiguration` double tap slop is 100dp.\n */\nconst sequenceSlop = 100\n\n/**\n * Max distance in px a pointer can move during a held press (`hold`\n * pending, or `repeat`). Android's `ViewConfiguration` touch slop is 8dp.\n */\nconst holdSlop = 8\n\nconst exceeds = (a: PointerEvent, b: PointerEvent, max: number) =>\n Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY) > max\n\nconst preventDefault = (event: Event) => event.preventDefault()\n\n/**\n * A `count` sequence waiting for its next press.\n */\ninterface PressSequence {\n count: number\n event: PointerEvent\n handlers: PressHandlers\n expire: (force?: unknown) => true | void\n}\n\nexport interface PointerEventOptions extends EventOptions, PressOptions {\n useGlobalTarget?: boolean\n stopPropagation?: boolean\n}\n\n/**\n * Create a press gesture.\n *\n * Press is different to `\"pointerdown\"`, `\"pointerup\"` in that it\n * automatically filters out secondary pointer events like right\n * click and multitouch.\n *\n * It also adds accessibility support for keyboards, where\n * an element with a press gesture will receive focus and\n * trigger on Enter `\"keydown\"` and `\"keyup\"` events.\n *\n * This is different to a browser's `\"click\"` event, which does\n * respond to keyboards but only for the `\"click\"` itself, rather\n * than the press start and end/cancel. The element also needs\n * to be focusable for this to work, whereas a press gesture will\n * make an element focusable by default.\n *\n * `onPressStart` fires on the first pointer or key down, and can return\n * a function to call when the press ends, or an object of handlers for\n * this press:\n *\n * ```js\n * press(button, () => ({\n * onHold: (progress) => {},\n * onComplete: (event, { success }) => {},\n * }), { hold: 0.5 })\n * ```\n *\n * @public\n */\nexport function press(\n targetOrSelector: ElementOrSelector,\n onPressStart: OnPressStartEvent,\n options: PointerEventOptions = {}\n): VoidFunction {\n onPressStart = bindToScope(onPressStart)\n\n const [targets, eventOptions, cancelEvents] = setupGesture(\n targetOrSelector,\n options\n )\n\n const sequences = new WeakMap<Element, PressSequence>()\n\n const startPress = (startEvent: PointerEvent) => {\n const target = startEvent.currentTarget as Element\n\n if (!isValidPressEvent(startEvent)) return\n if (claimedPointerDownEvents.has(startEvent)) return\n\n if (options.stopPropagation) {\n claimedPointerDownEvents.add(startEvent)\n }\n\n /**\n * Options are read per press so they can be updated between presses.\n */\n const {\n count: presses = 1,\n countTimeout = 0.3,\n hold = 0,\n repeat,\n } = options\n const downTime = time.now()\n const holdTime = secondsToMilliseconds(hold)\n const timeout = secondsToMilliseconds(countTimeout)\n let previous = sequences.get(target)\n\n /**\n * A press during a `count` sequence continues it. If it's too late\n * or too far away, the sequence is cancelled and this press starts\n * a new one.\n */\n if (\n previous?.expire(exceeds(previous.event, startEvent, sequenceSlop))\n ) {\n previous = undefined\n } else if (previous) {\n cancelFrame(previous.expire)\n sequences.delete(target)\n }\n\n const count = previous ? previous.count + 1 : 1\n const isFinal = count >= presses\n const isHeld = isFinal && (hold || repeat)\n let isActive = !hold\n let repeats = 0\n let handlers: PressHandlers\n\n isPressing.add(target)\n\n if (previous) {\n handlers = previous.handlers\n } else {\n const result = onPressStart(target, startEvent)\n handlers =\n typeof result === \"function\"\n ? { onComplete: result }\n : result || {}\n }\n\n isFinal && isActive && handlers.onActive?.()\n\n /**\n * While held, `onHold` reports progress from 0 to 1 over `hold`,\n * then over each `repeat`. Each cycle reports exactly 1 at its end,\n * then 0 on the next frame.\n */\n const repeatTime = secondsToMilliseconds(repeat!)\n let length = holdTime || repeatTime\n let cycleEnd = downTime + length\n let isCycleStart = true\n\n const tick = () => {\n if (eventOptions.signal!.aborted) return cancelFrame(tick)\n\n let progress = Math.min(1 - (cycleEnd - time.now()) / length, 1)\n\n /**\n * The frame after a boundary reports 0, so each cycle visibly\n * restarts. Boundaries are timed from `downTime`, so this\n * doesn't delay the next one. If a long frame has already\n * passed the next boundary, it reports 1 instead.\n */\n if (isCycleStart && progress < 1) progress = 0\n isCycleStart = false\n handlers.onHold?.(progress)\n\n if (progress < 1) return\n\n if (isActive) {\n handlers.onRepeat?.(++repeats)\n } else {\n isActive = true\n handlers.onActive?.()\n }\n\n if (repeat) {\n isCycleStart = true\n cycleEnd += length = repeatTime\n } else {\n cancelFrame(tick)\n }\n }\n\n /**\n * End listeners run in the capture phase so a descendant calling\n * stopPropagation() in its own pointerup handler can't prevent the\n * press gesture from ending. This also keeps the gesture-end\n * ordering consistent with the drag gesture. See #2794.\n */\n const endEventOptions = { ...eventOptions, capture: true }\n\n const onPointerEnd = (endEvent: PointerEvent, success: boolean) => {\n window.removeEventListener(\n \"pointerup\",\n onPointerUp,\n endEventOptions\n )\n window.removeEventListener(\n \"pointercancel\",\n onPointerCancel,\n endEventOptions\n )\n window.removeEventListener(\n \"pointermove\",\n onPointerMove,\n endEventOptions\n )\n target.removeEventListener(\"contextmenu\", preventDefault)\n cancelFrame(tick)\n isPressing.delete(target)\n\n if (!isPrimaryPointer(endEvent)) return\n\n /**\n * A press that ends while a drag is active is a cancel.\n */\n if (isDragActive()) success = false\n\n if (success && !isFinal) {\n /**\n * Wait for the next press of the sequence, and cancel the\n * gesture if it doesn't arrive in time.\n */\n const end = time.now()\n\n /**\n * Cancels the sequence if it's `force`d, or the interval\n * has passed. Runs every frame, where `force` is frame\n * data, so it's checked with `=== true`.\n */\n const expire = (force?: unknown) => {\n const isAborted = eventOptions.signal!.aborted\n if (\n isAborted ||\n force === true ||\n time.now() - end > timeout\n ) {\n cancelFrame(expire)\n sequences.delete(target)\n isAborted ||\n handlers.onComplete?.(endEvent, { success: false })\n return true\n }\n }\n sequences.set(target, {\n count,\n event: startEvent,\n handlers,\n expire,\n })\n frame.update(expire, true)\n } else {\n /**\n * Releasing before `hold` is reached is a cancel.\n */\n handlers.onComplete?.(endEvent, {\n success: success && isActive,\n })\n }\n }\n\n const onPointerUp = (upEvent: PointerEvent) => {\n onPointerEnd(\n upEvent,\n (target as any) === window ||\n (target as any) === document ||\n options.useGlobalTarget ||\n isNodeOrChild(target, upEvent.target as Element)\n )\n }\n\n const onPointerCancel = (cancelEvent: PointerEvent) => {\n onPointerEnd(cancelEvent, false)\n }\n\n /**\n * Moving during a pending long press, or a repeating press, cancels\n * it, so scrolling on touch devices doesn't trigger it. A drag\n * starting during a `count` sequence cancels it.\n */\n const onPointerMove = (moveEvent: PointerEvent) => {\n if (\n isPrimaryPointer(moveEvent) &&\n (((repeat || !isActive) &&\n exceeds(startEvent, moveEvent, holdSlop)) ||\n (presses > 1 && isDragActive()))\n ) {\n onPointerCancel(moveEvent)\n }\n }\n\n window.addEventListener(\"pointerup\", onPointerUp, endEventOptions)\n window.addEventListener(\n \"pointercancel\",\n onPointerCancel,\n endEventOptions\n )\n\n if (isHeld || presses > 1) {\n window.addEventListener(\n \"pointermove\",\n onPointerMove,\n endEventOptions\n )\n }\n\n if (isHeld) {\n frame.update(tick, true)\n /**\n * Touch devices open a context menu or callout on long press,\n * which would cancel the gesture.\n */\n target.addEventListener(\"contextmenu\", preventDefault, {\n ...eventOptions,\n passive: false,\n })\n }\n }\n\n targets.forEach((target: EventTarget) => {\n const pointerDownTarget = options.useGlobalTarget ? window : target\n pointerDownTarget.addEventListener(\n \"pointerdown\",\n startPress as EventListener,\n eventOptions\n )\n\n if (isHTMLElement(target)) {\n target.addEventListener(\n \"focus\",\n () => enableKeyboardPress(target, eventOptions),\n eventOptions\n )\n\n if (\n !isElementKeyboardAccessible(target) &&\n !target.hasAttribute(\"tabindex\")\n ) {\n target.tabIndex = 0\n }\n }\n })\n\n return cancelEvents\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAgBA;;;AAGG;AACH,SAAS,iBAAiB,CAAC,KAAmB,EAAA;IAC1C,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE;AACrD;AAEA,MAAM,wBAAwB,GAAG,IAAI,OAAO,EAAS;AAErD;;;AAGG;AACH,MAAM,YAAY,GAAG,GAAG;AAExB;;;AAGG;AACH,MAAM,QAAQ,GAAG,CAAC;AAElB,MAAM,OAAO,GAAG,CAAC,CAAe,EAAE,CAAe,EAAE,GAAW,KAC1D,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,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M,mBAAmB,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/C,YAAY,CACf;AAED,YAAA,IACI,CAAC,2BAA2B,CAAC,MAAM,CAAC;AACpC,gBAAA,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,EAClC;AACE,gBAAA,MAAM,CAAC,QAAQ,GAAG,CAAC;YACvB;QACJ;AACJ,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,YAAY;AACvB;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/gestures/press/index.ts"],"sourcesContent":["import { secondsToMilliseconds } from \"motion-utils\"\nimport { cancelFrame, frame } from \"../../frameloop/frame\"\nimport { time } from \"../../frameloop/sync-time\"\nimport { bindToScope } from \"../../scope/active\"\nimport { isHTMLElement } from \"../../utils/is-html-element\"\nimport { ElementOrSelector } from \"../../utils/resolve-elements\"\nimport { isDragActive } from \"../drag/state/is-active\"\nimport { EventOptions } from \"../types\"\nimport { isNodeOrChild } from \"../utils/is-node-or-child\"\nimport { isPrimaryPointer } from \"../utils/is-primary-pointer\"\nimport { setupGesture } from \"../utils/setup\"\nimport { OnPressStartEvent, PressHandlers, PressOptions } from \"./types\"\nimport { isElementKeyboardAccessible } from \"./utils/is-keyboard-accessible\"\nimport { enableKeyboardPress } from \"./utils/keyboard\"\nimport { isPressing } from \"./utils/state\"\n\n/**\n * Filter out events that are not primary pointer events, or are triggering\n * while a Motion gesture is active.\n */\nfunction isValidPressEvent(event: PointerEvent) {\n return isPrimaryPointer(event) && !isDragActive()\n}\n\nconst claimedPointerDownEvents = new WeakSet<Event>()\n\n/**\n * Max distance in px between consecutive presses of a `count` sequence.\n * Android's `ViewConfiguration` double tap slop is 100dp.\n */\nconst sequenceSlop = 100\n\n/**\n * Max distance in px a pointer can move during a held press (`hold`\n * pending, or `repeat`). Android's `ViewConfiguration` touch slop is 8dp.\n */\nconst holdSlop = 8\n\nconst exceeds = (a: PointerEvent, b: PointerEvent, max: number) =>\n Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY) > max\n\nconst preventDefault = (event: Event) => event.preventDefault()\n\n/**\n * A `count` sequence waiting for its next press.\n */\ninterface PressSequence {\n count: number\n event: PointerEvent\n handlers: PressHandlers\n expire: (force?: unknown) => true | void\n}\n\nexport interface PointerEventOptions extends EventOptions, PressOptions {\n useGlobalTarget?: boolean\n stopPropagation?: boolean\n}\n\n/**\n * Create a press gesture.\n *\n * Press is different to `\"pointerdown\"`, `\"pointerup\"` in that it\n * automatically filters out secondary pointer events like right\n * click and multitouch.\n *\n * It also adds accessibility support for keyboards, where\n * an element with a press gesture will receive focus and\n * trigger on Enter `\"keydown\"` and `\"keyup\"` events.\n *\n * This is different to a browser's `\"click\"` event, which does\n * respond to keyboards but only for the `\"click\"` itself, rather\n * than the press start and end/cancel. The element also needs\n * to be focusable for this to work, whereas a press gesture will\n * make an element focusable by default.\n *\n * `onPressStart` fires on the first pointer or key down, and can return\n * a function to call when the press ends, or an object of handlers for\n * this press:\n *\n * ```js\n * press(button, () => ({\n * onHold: (progress) => {},\n * onComplete: (event, { success }) => {},\n * }), { hold: 0.5 })\n * ```\n *\n * @public\n */\nexport function press(\n targetOrSelector: ElementOrSelector,\n onPressStart: OnPressStartEvent,\n options: PointerEventOptions = {}\n): VoidFunction {\n onPressStart = bindToScope(onPressStart)\n\n const [targets, eventOptions, cancelEvents] = setupGesture(\n targetOrSelector,\n options\n )\n\n const sequences = new WeakMap<Element, PressSequence>()\n\n const startPress = (startEvent: PointerEvent) => {\n const target = startEvent.currentTarget as Element\n\n if (!isValidPressEvent(startEvent)) return\n if (claimedPointerDownEvents.has(startEvent)) return\n\n if (options.stopPropagation) {\n claimedPointerDownEvents.add(startEvent)\n }\n\n /**\n * Options are read per press so they can be updated between presses.\n */\n const {\n count: presses = 1,\n countTimeout = 0.3,\n hold = 0,\n repeat,\n } = options\n const downTime = time.now()\n const holdTime = secondsToMilliseconds(hold)\n const timeout = secondsToMilliseconds(countTimeout)\n let previous = sequences.get(target)\n\n /**\n * A press during a `count` sequence continues it. If it's too late\n * or too far away, the sequence is cancelled and this press starts\n * a new one.\n */\n if (\n previous?.expire(exceeds(previous.event, startEvent, sequenceSlop))\n ) {\n previous = undefined\n } else if (previous) {\n cancelFrame(previous.expire)\n sequences.delete(target)\n }\n\n const count = previous ? previous.count + 1 : 1\n const isFinal = count >= presses\n const isHeld = isFinal && (hold || repeat)\n let isActive = !hold\n let repeats = 0\n let handlers: PressHandlers\n\n isPressing.add(target)\n\n if (previous) {\n handlers = previous.handlers\n } else {\n const result = onPressStart(target, startEvent)\n handlers =\n typeof result === \"function\"\n ? { onComplete: result }\n : result || {}\n }\n\n isFinal && isActive && handlers.onActive?.()\n\n /**\n * While held, `onHold` reports progress from 0 to 1 over `hold`,\n * then over each `repeat`. Each cycle reports exactly 1 at its end,\n * then 0 on the next frame.\n */\n const repeatTime = secondsToMilliseconds(repeat!)\n let length = holdTime || repeatTime\n let cycleEnd = downTime + length\n let isCycleStart = true\n\n const tick = () => {\n if (eventOptions.signal!.aborted) return cancelFrame(tick)\n\n let progress = Math.min(1 - (cycleEnd - time.now()) / length, 1)\n\n /**\n * The frame after a boundary reports 0, so each cycle visibly\n * restarts. Boundaries are timed from `downTime`, so this\n * doesn't delay the next one. If a long frame has already\n * passed the next boundary, it reports 1 instead.\n */\n if (isCycleStart && progress < 1) progress = 0\n isCycleStart = false\n handlers.onHold?.(progress)\n\n if (progress < 1) return\n\n if (isActive) {\n handlers.onRepeat?.(++repeats)\n } else {\n isActive = true\n handlers.onActive?.()\n }\n\n if (repeat) {\n isCycleStart = true\n cycleEnd += length = repeatTime\n } else {\n cancelFrame(tick)\n }\n }\n\n /**\n * End listeners run in the capture phase so a descendant calling\n * stopPropagation() in its own pointerup handler can't prevent the\n * press gesture from ending. This also keeps the gesture-end\n * ordering consistent with the drag gesture. See #2794.\n */\n const endEventOptions = { ...eventOptions, capture: true }\n\n const onPointerEnd = (endEvent: PointerEvent, success: boolean) => {\n /**\n * Another touch lifting (for instance after a pinch) doesn't\n * end the press.\n */\n if (!isPrimaryPointer(endEvent)) return\n\n window.removeEventListener(\n \"pointerup\",\n onPointerUp,\n endEventOptions\n )\n window.removeEventListener(\n \"pointercancel\",\n onPointerCancel,\n endEventOptions\n )\n window.removeEventListener(\n \"pointermove\",\n onPointerMove,\n endEventOptions\n )\n target.removeEventListener(\"contextmenu\", preventDefault)\n cancelFrame(tick)\n isPressing.delete(target)\n\n /**\n * A press that ends while a drag is active is a cancel.\n */\n if (isDragActive()) success = false\n\n if (success && !isFinal) {\n /**\n * Wait for the next press of the sequence, and cancel the\n * gesture if it doesn't arrive in time.\n */\n const end = time.now()\n\n /**\n * Cancels the sequence if it's `force`d, or the interval\n * has passed. Runs every frame, where `force` is frame\n * data, so it's checked with `=== true`.\n */\n const expire = (force?: unknown) => {\n const isAborted = eventOptions.signal!.aborted\n if (\n isAborted ||\n force === true ||\n time.now() - end > timeout\n ) {\n cancelFrame(expire)\n sequences.delete(target)\n isAborted ||\n handlers.onComplete?.(endEvent, { success: false })\n return true\n }\n }\n sequences.set(target, {\n count,\n event: startEvent,\n handlers,\n expire,\n })\n frame.update(expire, true)\n } else {\n /**\n * Releasing before `hold` is reached is a cancel.\n */\n handlers.onComplete?.(endEvent, {\n success: success && isActive,\n })\n }\n }\n\n const onPointerUp = (upEvent: PointerEvent) => {\n onPointerEnd(\n upEvent,\n (target as any) === window ||\n (target as any) === document ||\n options.useGlobalTarget ||\n isNodeOrChild(target, upEvent.target as Element)\n )\n }\n\n const onPointerCancel = (cancelEvent: PointerEvent) => {\n onPointerEnd(cancelEvent, false)\n }\n\n /**\n * Moving during a pending long press, or a repeating press, cancels\n * it, so scrolling on touch devices doesn't trigger it. A drag\n * starting during a `count` sequence cancels it.\n */\n const onPointerMove = (moveEvent: PointerEvent) => {\n if (\n isPrimaryPointer(moveEvent) &&\n (((repeat || !isActive) &&\n exceeds(startEvent, moveEvent, holdSlop)) ||\n (presses > 1 && isDragActive()))\n ) {\n onPointerCancel(moveEvent)\n }\n }\n\n window.addEventListener(\"pointerup\", onPointerUp, endEventOptions)\n window.addEventListener(\n \"pointercancel\",\n onPointerCancel,\n endEventOptions\n )\n\n if (isHeld || presses > 1) {\n window.addEventListener(\n \"pointermove\",\n onPointerMove,\n endEventOptions\n )\n }\n\n if (isHeld) {\n frame.update(tick, true)\n /**\n * Touch devices open a context menu or callout on long press,\n * which would cancel the gesture.\n */\n target.addEventListener(\"contextmenu\", preventDefault, {\n ...eventOptions,\n passive: false,\n })\n }\n }\n\n targets.forEach((target: EventTarget) => {\n const pointerDownTarget = options.useGlobalTarget ? window : target\n pointerDownTarget.addEventListener(\n \"pointerdown\",\n startPress as EventListener,\n eventOptions\n )\n\n if (isHTMLElement(target)) {\n target.addEventListener(\n \"focus\",\n () => enableKeyboardPress(target, eventOptions),\n eventOptions\n )\n\n if (\n !isElementKeyboardAccessible(target) &&\n !target.hasAttribute(\"tabindex\")\n ) {\n target.tabIndex = 0\n }\n }\n })\n\n return cancelEvents\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAgBA;;;AAGG;AACH,SAAS,iBAAiB,CAAC,KAAmB,EAAA;IAC1C,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE;AACrD;AAEA,MAAM,wBAAwB,GAAG,IAAI,OAAO,EAAS;AAErD;;;AAGG;AACH,MAAM,YAAY,GAAG,GAAG;AAExB;;;AAGG;AACH,MAAM,QAAQ,GAAG,CAAC;AAElB,MAAM,OAAO,GAAG,CAAC,CAAe,EAAE,CAAe,EAAE,GAAW,KAC1D,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,GAAG;AAElE,MAAM,cAAc,GAAG,CAAC,KAAY,KAAK,KAAK,CAAC,cAAc,EAAE;AAiB/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AACG,SAAU,K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MAAM,CAAC,QAAQ,GAAG,CAAC;YACvB;QACJ;AACJ,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,YAAY;AACvB;;;;"}
package/dist/es/index.mjs CHANGED
@@ -64,6 +64,7 @@ export { setDragLock } from './gestures/drag/state/set-active.mjs';
64
64
  export { VisualElementDragControls, elementDragControls, expectsResolvedDragConstraints } from './gestures/drag/VisualElementDragControls.mjs';
65
65
  export { hover } from './gestures/hover.mjs';
66
66
  export { PanSession } from './gestures/pan/PanSession.mjs';
67
+ export { addPinchListeners, pinch } from './gestures/pinch/index.mjs';
67
68
  export { press } from './gestures/press/index.mjs';
68
69
  export { isElementKeyboardAccessible, isElementTextInput } from './gestures/press/utils/is-keyboard-accessible.mjs';
69
70
  export { isNodeOrChild } from './gestures/utils/is-node-or-child.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -14,13 +14,7 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
14
14
  if (xTranslate || yTranslate || zTranslate) {
15
15
  transform = `translate3d(${xTranslate}px, ${yTranslate}px, ${zTranslate}px) `;
16
16
  }
17
- /**
18
- * Apply scale correction for the tree transform.
19
- * This will apply scale to the screen-orientated axes.
20
- */
21
- if (treeScale.x !== 1 || treeScale.y !== 1) {
22
- transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
23
- }
17
+ let angles = "";
24
18
  if (latestTransform) {
25
19
  const { transformPerspective } = latestTransform;
26
20
  if (transformPerspective)
@@ -29,20 +23,48 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
29
23
  const key = angleTransforms[i];
30
24
  const value = latestTransform[key];
31
25
  if (value)
32
- transform += `${key}(${value}deg) `;
26
+ angles += `${key}(${value}deg) `;
33
27
  // Additive `rotate()` so user `rotate` isn't clobbered.
34
28
  if (!i && latestTransform.pathRotation)
35
- transform += `rotate(${latestTransform.pathRotation}deg) `;
29
+ angles += `rotate(${latestTransform.pathRotation}deg) `;
36
30
  }
37
31
  }
38
- /**
39
- * Apply scale to match the size of the element to the size we want it.
40
- * This will apply scale to the element-orientated axes.
41
- */
42
- const elementScaleX = delta.x.scale * treeScale.x;
43
- const elementScaleY = delta.y.scale * treeScale.y;
44
- if (elementScaleX !== 1 || elementScaleY !== 1) {
45
- transform += `scale(${elementScaleX}, ${elementScaleY})`;
32
+ if (angles) {
33
+ /**
34
+ * Apply scale correction for the tree transform.
35
+ * This will apply scale to the screen-orientated axes.
36
+ */
37
+ if (treeScale.x !== 1 || treeScale.y !== 1) {
38
+ transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
39
+ }
40
+ transform += angles;
41
+ /**
42
+ * Apply scale to match the size of the element to the size we want it.
43
+ * This will apply scale to the element-orientated axes.
44
+ */
45
+ const elementScaleX = delta.x.scale * treeScale.x;
46
+ const elementScaleY = delta.y.scale * treeScale.y;
47
+ if (elementScaleX !== 1 || elementScaleY !== 1) {
48
+ transform += `scale(${elementScaleX}, ${elementScaleY})`;
49
+ }
50
+ }
51
+ else if (delta.x.scale !== 1 || delta.y.scale !== 1) {
52
+ /**
53
+ * With no rotation or skew between them, the tree scale correction
54
+ * (1 / treeScale) and the element scale (delta.scale * treeScale)
55
+ * combine into a single scale. A shorter transform is quicker for
56
+ * the browser to parse, which matters when it's set every frame.
57
+ */
58
+ transform += `scale(${delta.x.scale}, ${delta.y.scale})`;
59
+ }
60
+ else if (!transform && (treeScale.x !== 1 || treeScale.y !== 1)) {
61
+ /**
62
+ * Inside a scaled tree the transform must never be "none", even when
63
+ * this element's own delta is the identity: scale correction for
64
+ * borderRadius and boxShadow is skipped for "none", and the element
65
+ * would gain and lose its stacking context as the delta snaps.
66
+ */
67
+ transform = "scale(1, 1)";
46
68
  }
47
69
  return transform || "none";
48
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transform.mjs","sources":["../../../../src/projection/styles/transform.ts"],"sourcesContent":["import type { Delta, Point } from \"motion-utils\"\nimport type { ResolvedValues } from \"../../node/types\"\nimport { angleTransforms } from \"../utils/has-transform\"\n\nexport function buildProjectionTransform(\n delta: Delta,\n treeScale: Point,\n latestTransform?: ResolvedValues\n): string {\n let transform = \"\"\n\n /**\n * The translations we use to calculate are always relative to the viewport coordinate space.\n * But when we apply scales, we also scale the coordinate space of an element and its children.\n * For instance if we have a treeScale (the culmination of all parent scales) of 0.5 and we need\n * to move an element 100 pixels, we actually need to move it 200 in within that scaled space.\n */\n const xTranslate = delta.x.translate / treeScale.x\n const yTranslate = delta.y.translate / treeScale.y\n const zTranslate = latestTransform?.z || 0\n if (xTranslate || yTranslate || zTranslate) {\n transform = `translate3d(${xTranslate}px, ${yTranslate}px, ${zTranslate}px) `\n }\n\n /**\n * Apply scale correction for the tree transform.\n * This will apply scale to the screen-orientated axes.\n */\n if (treeScale.x !== 1 || treeScale.y !== 1) {\n transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `\n }\n\n if (latestTransform) {\n const { transformPerspective } = latestTransform\n if (transformPerspective)\n transform = `perspective(${transformPerspective}px) ${transform}`\n\n for (let i = 0; i < angleTransforms.length; i++) {\n const key = angleTransforms[i]\n const value = latestTransform[key]\n if (value) transform += `${key}(${value}deg) `\n // Additive `rotate()` so user `rotate` isn't clobbered.\n if (!i && latestTransform.pathRotation)\n transform += `rotate(${latestTransform.pathRotation}deg) `\n }\n }\n\n /**\n * Apply scale to match the size of the element to the size we want it.\n * This will apply scale to the element-orientated axes.\n */\n const elementScaleX = delta.x.scale * treeScale.x\n const elementScaleY = delta.y.scale * treeScale.y\n if (elementScaleX !== 1 || elementScaleY !== 1) {\n transform += `scale(${elementScaleX}, ${elementScaleY})`\n }\n\n return transform || \"none\"\n}\n"],"names":[],"mappings":";;SAIgB,wBAAwB,CACpC,KAAY,EACZ,SAAgB,EAChB,eAAgC,EAAA;IAEhC,IAAI,SAAS,GAAG,EAAE;AAElB;;;;;AAKG;IACH,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;AAClD,IAAA,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC,IAAI,CAAC;AAC1C,IAAA,IAAI,UAAU,IAAI,UAAU,IAAI,UAAU,EAAE;QACxC,SAAS,GAAG,eAAe,UAAU,CAAA,IAAA,EAAO,UAAU,CAAA,IAAA,EAAO,UAAU,MAAM;IACjF;AAEA;;;AAGG;AACH,IAAA,IAAI,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,CAAC,KAAK,CAAC,EAAE;AACxC,QAAA,SAAS,IAAI,CAAA,MAAA,EAAS,CAAC,GAAG,SAAS,CAAC,CAAC,CAAA,EAAA,EAAK,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI;IACjE;IAEA,IAAI,eAAe,EAAE;AACjB,QAAA,MAAM,EAAE,oBAAoB,EAAE,GAAG,eAAe;AAChD,QAAA,IAAI,oBAAoB;AACpB,YAAA,SAAS,GAAG,CAAA,YAAA,EAAe,oBAAoB,CAAA,IAAA,EAAO,SAAS,EAAE;AAErE,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAC7C,YAAA,MAAM,GAAG,GAAG,eAAe,CAAC,CAAC,CAAC;AAC9B,YAAA,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC;AAClC,YAAA,IAAI,KAAK;AAAE,gBAAA,SAAS,IAAI,CAAA,EAAG,GAAG,CAAA,CAAA,EAAI,KAAK,OAAO;;AAE9C,YAAA,IAAI,CAAC,CAAC,IAAI,eAAe,CAAC,YAAY;AAClC,gBAAA,SAAS,IAAI,CAAA,OAAA,EAAU,eAAe,CAAC,YAAY,OAAO;QAClE;IACJ;AAEA;;;AAGG;IACH,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IACjD,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IACjD,IAAI,aAAa,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,EAAE;AAC5C,QAAA,SAAS,IAAI,CAAA,MAAA,EAAS,aAAa,CAAA,EAAA,EAAK,aAAa,GAAG;IAC5D;IAEA,OAAO,SAAS,IAAI,MAAM;AAC9B;;;;"}
1
+ {"version":3,"file":"transform.mjs","sources":["../../../../src/projection/styles/transform.ts"],"sourcesContent":["import type { Delta, Point } from \"motion-utils\"\nimport type { ResolvedValues } from \"../../node/types\"\nimport { angleTransforms } from \"../utils/has-transform\"\n\nexport function buildProjectionTransform(\n delta: Delta,\n treeScale: Point,\n latestTransform?: ResolvedValues\n): string {\n let transform = \"\"\n\n /**\n * The translations we use to calculate are always relative to the viewport coordinate space.\n * But when we apply scales, we also scale the coordinate space of an element and its children.\n * For instance if we have a treeScale (the culmination of all parent scales) of 0.5 and we need\n * to move an element 100 pixels, we actually need to move it 200 in within that scaled space.\n */\n const xTranslate = delta.x.translate / treeScale.x\n const yTranslate = delta.y.translate / treeScale.y\n const zTranslate = latestTransform?.z || 0\n if (xTranslate || yTranslate || zTranslate) {\n transform = `translate3d(${xTranslate}px, ${yTranslate}px, ${zTranslate}px) `\n }\n\n let angles = \"\"\n if (latestTransform) {\n const { transformPerspective } = latestTransform\n if (transformPerspective)\n transform = `perspective(${transformPerspective}px) ${transform}`\n\n for (let i = 0; i < angleTransforms.length; i++) {\n const key = angleTransforms[i]\n const value = latestTransform[key]\n if (value) angles += `${key}(${value}deg) `\n // Additive `rotate()` so user `rotate` isn't clobbered.\n if (!i && latestTransform.pathRotation)\n angles += `rotate(${latestTransform.pathRotation}deg) `\n }\n }\n\n if (angles) {\n /**\n * Apply scale correction for the tree transform.\n * This will apply scale to the screen-orientated axes.\n */\n if (treeScale.x !== 1 || treeScale.y !== 1) {\n transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `\n }\n\n transform += angles\n\n /**\n * Apply scale to match the size of the element to the size we want it.\n * This will apply scale to the element-orientated axes.\n */\n const elementScaleX = delta.x.scale * treeScale.x\n const elementScaleY = delta.y.scale * treeScale.y\n if (elementScaleX !== 1 || elementScaleY !== 1) {\n transform += `scale(${elementScaleX}, ${elementScaleY})`\n }\n } else if (delta.x.scale !== 1 || delta.y.scale !== 1) {\n /**\n * With no rotation or skew between them, the tree scale correction\n * (1 / treeScale) and the element scale (delta.scale * treeScale)\n * combine into a single scale. A shorter transform is quicker for\n * the browser to parse, which matters when it's set every frame.\n */\n transform += `scale(${delta.x.scale}, ${delta.y.scale})`\n } else if (!transform && (treeScale.x !== 1 || treeScale.y !== 1)) {\n /**\n * Inside a scaled tree the transform must never be \"none\", even when\n * this element's own delta is the identity: scale correction for\n * borderRadius and boxShadow is skipped for \"none\", and the element\n * would gain and lose its stacking context as the delta snaps.\n */\n transform = \"scale(1, 1)\"\n }\n\n return transform || \"none\"\n}\n"],"names":[],"mappings":";;SAIgB,wBAAwB,CACpC,KAAY,EACZ,SAAgB,EAChB,eAAgC,EAAA;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AS,CAAC,GAAG,SAAS,CAAC,CAAC,CAAA,EAAA,EAAK,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI;QACjE;QAEA,SAAS,IAAI,MAAM;AAEnB;;;AAGG;QACH,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;QACjD,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;QACjD,IAAI,aAAa,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,EAAE;AAC5C,YAAA,SAAS,IAAI,CAAA,MAAA,EAAS,aAAa,CAAA,EAAA,EAAK,aAAa,GAAG;QAC5D;IACJ;AAAO,SAAA,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,EAAE;AACnD;;;;;AAKG;AACH,QAAA,SAAS,IAAI,CAAA,MAAA,EAAS,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA,EAAA,EAAK,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG;IAC5D;AAAO,SAAA,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE;AAC/D;;;;;AAKG;QACH,SAAS,GAAG,aAAa;IAC7B;IAEA,OAAO,SAAS,IAAI,MAAM;AAC9B;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-variant-context.mjs","sources":["../../../../src/render/utils/get-variant-context.ts"],"sourcesContent":["import { isVariantLabel } from \"./is-variant-label\"\nimport { variantProps } from \"./variant-props\"\n\nconst numVariantProps = variantProps.length\n\ntype VariantStateContext = {\n initial?: string | string[]\n animate?: string | string[]\n exit?: string | string[]\n whileHover?: string | string[]\n whileDrag?: string | string[]\n whileFocus?: string | string[]\n whileTap?: string | string[]\n}\n\n/**\n * Get variant context from a visual element's parent chain.\n * Uses `any` type for visualElement to avoid circular dependencies.\n */\nexport function getVariantContext(\n visualElement?: any\n): undefined | VariantStateContext {\n if (!visualElement) return undefined\n\n if (!visualElement.isControllingVariants) {\n const context = visualElement.parent\n ? getVariantContext(visualElement.parent) || {}\n : {}\n if (visualElement.props.initial !== undefined) {\n context.initial = visualElement.props.initial as any\n }\n return context\n }\n\n const context: VariantStateContext = {}\n for (let i = 0; i < numVariantProps; i++) {\n const name = variantProps[i] as keyof typeof context\n const prop = visualElement.props[name]\n\n if (isVariantLabel(prop) || prop === false) {\n ;(context as any)[name] = prop\n }\n }\n\n return context\n}\n"],"names":[],"mappings":";;;AAGA,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM;AAY3C;;;AAGG;AACG,SAAU,iBAAiB,CAC7B,aAAmB,EAAA;AAEnB,IAAA,IAAI,CAAC,aAAa;AAAE,QAAA,OAAO,SAAS;AAEpC,IAAA,IAAI,CAAC,aAAa,CAAC,qBAAqB,EAAE;AACtC,QAAA,MAAM,OAAO,GAAG,aAAa,CAAC;cACxB,iBAAiB,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI;cAC3C,EAAE;QACR,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE;YAC3C,OAAO,CAAC,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,OAAc;QACxD;AACA,QAAA,OAAO,OAAO;IAClB;IAEA,MAAM,OAAO,GAAwB,EAAE;AACvC,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE;AACtC,QAAA,MAAM,IAAI,GAAG,YAAY,CAAC,CAAC,CAAyB;QACpD,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;QAEtC,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,KAAK,EAAE;AACtC,YAAA,OAAe,CAAC,IAAI,CAAC,GAAG,IAAI;QAClC;IACJ;AAEA,IAAA,OAAO,OAAO;AAClB;;;;"}
1
+ {"version":3,"file":"get-variant-context.mjs","sources":["../../../../src/render/utils/get-variant-context.ts"],"sourcesContent":["import { isVariantLabel } from \"./is-variant-label\"\nimport { variantProps } from \"./variant-props\"\n\nconst numVariantProps = variantProps.length\n\ntype VariantStateContext = {\n initial?: string | string[]\n animate?: string | string[]\n exit?: string | string[]\n whileHover?: string | string[]\n whileDrag?: string | string[]\n whilePinch?: string | string[]\n whileFocus?: string | string[]\n whileTap?: string | string[]\n}\n\n/**\n * Get variant context from a visual element's parent chain.\n * Uses `any` type for visualElement to avoid circular dependencies.\n */\nexport function getVariantContext(\n visualElement?: any\n): undefined | VariantStateContext {\n if (!visualElement) return undefined\n\n if (!visualElement.isControllingVariants) {\n const context = visualElement.parent\n ? getVariantContext(visualElement.parent) || {}\n : {}\n if (visualElement.props.initial !== undefined) {\n context.initial = visualElement.props.initial as any\n }\n return context\n }\n\n const context: VariantStateContext = {}\n for (let i = 0; i < numVariantProps; i++) {\n const name = variantProps[i] as keyof typeof context\n const prop = visualElement.props[name]\n\n if (isVariantLabel(prop) || prop === false) {\n ;(context as any)[name] = prop\n }\n }\n\n return context\n}\n"],"names":[],"mappings":";;;AAGA,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM;AAa3C;;;AAGG;AACG,SAAU,iBAAiB,CAC7B,aAAmB,EAAA;AAEnB,IAAA,IAAI,CAAC,aAAa;AAAE,QAAA,OAAO,SAAS;AAEpC,IAAA,IAAI,CAAC,aAAa,CAAC,qBAAqB,EAAE;AACtC,QAAA,MAAM,OAAO,GAAG,aAAa,CAAC;cACxB,iBAAiB,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI;cAC3C,EAAE;QACR,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE;YAC3C,OAAO,CAAC,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,OAAc;QACxD;AACA,QAAA,OAAO,OAAO;IAClB;IAEA,MAAM,OAAO,GAAwB,EAAE;AACvC,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE;AACtC,QAAA,MAAM,IAAI,GAAG,YAAY,CAAC,CAAC,CAAyB;QACpD,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;QAEtC,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,KAAK,EAAE;AACtC,YAAA,OAAe,CAAC,IAAI,CAAC,GAAG,IAAI;QAClC;IACJ;AAEA,IAAA,OAAO,OAAO;AAClB;;;;"}
@@ -5,6 +5,7 @@ const variantPriorityOrder = [
5
5
  "whileHover",
6
6
  "whileTap",
7
7
  "whileDrag",
8
+ "whilePinch",
8
9
  "exit",
9
10
  ];
10
11
  const variantProps = /* @__PURE__ */ ["initial"].concat(variantPriorityOrder);
@@ -1 +1 @@
1
- {"version":3,"file":"variant-props.mjs","sources":["../../../../src/render/utils/variant-props.ts"],"sourcesContent":["import type { AnimationType } from \"../types\"\n\nexport const variantPriorityOrder: AnimationType[] = [\n \"animate\",\n \"whileInView\",\n \"whileFocus\",\n \"whileHover\",\n \"whileTap\",\n \"whileDrag\",\n \"exit\",\n]\n\nexport const variantProps = /* @__PURE__ */ [\"initial\"].concat(\n variantPriorityOrder\n)\n"],"names":[],"mappings":"AAEO,MAAM,oBAAoB,GAAoB;IACjD,SAAS;IACT,aAAa;IACb,YAAY;IACZ,YAAY;IACZ,UAAU;IACV,WAAW;IACX,MAAM;;AAGH,MAAM,YAAY,mBAAmB,CAAC,SAAS,CAAC,CAAC,MAAM,CAC1D,oBAAoB;;;;"}
1
+ {"version":3,"file":"variant-props.mjs","sources":["../../../../src/render/utils/variant-props.ts"],"sourcesContent":["import type { AnimationType } from \"../types\"\n\nexport const variantPriorityOrder: AnimationType[] = [\n \"animate\",\n \"whileInView\",\n \"whileFocus\",\n \"whileHover\",\n \"whileTap\",\n \"whileDrag\",\n \"whilePinch\",\n \"exit\",\n]\n\nexport const variantProps = /* @__PURE__ */ [\"initial\"].concat(\n variantPriorityOrder\n)\n"],"names":[],"mappings":"AAEO,MAAM,oBAAoB,GAAoB;IACjD,SAAS;IACT,aAAa;IACb,YAAY;IACZ,YAAY;IACZ,UAAU;IACV,WAAW;IACX,YAAY;IACZ,MAAM;;AAGH,MAAM,YAAY,mBAAmB,CAAC,SAAS,CAAC,CAAC,MAAM,CAC1D,oBAAoB;;;;"}
@@ -299,28 +299,32 @@ class MotionValue {
299
299
  * @param animation - A function that starts the provided animation
300
300
  */
301
301
  start(startAnimation) {
302
+ return new Promise((resolve) => this.run(startAnimation, resolve));
303
+ }
304
+ /**
305
+ * As start(), without making a promise, for animations started
306
+ * internally, which complete through their own controls.
307
+ */
308
+ run(startAnimation, onComplete) {
302
309
  this.stop();
303
- return new Promise((resolve) => {
304
- this.hasAnimated = true;
305
- /**
306
- * Complete synchronously via the callback rather than chaining a
307
- * second promise per animation. Guard against animations that
308
- * complete before startAnimation has returned.
309
- */
310
- let isComplete = false;
311
- let animation;
312
- // eslint-disable-next-line prefer-const -- read by the callback before assignment when completing synchronously
313
- animation = startAnimation(() => {
314
- isComplete = true;
315
- this.events.animationComplete?.notify();
316
- if (this.animation === animation)
317
- this.animation = undefined;
318
- resolve();
319
- });
320
- if (!isComplete)
321
- this.animation = animation;
322
- this.events.animationStart?.notify();
310
+ this.hasAnimated = true;
311
+ /**
312
+ * Guard against animations that complete before startAnimation
313
+ * has returned.
314
+ */
315
+ let isComplete = false;
316
+ let animation;
317
+ // eslint-disable-next-line prefer-const -- read by the callback before assignment when completing synchronously
318
+ animation = startAnimation(() => {
319
+ isComplete = true;
320
+ this.events.animationComplete?.notify();
321
+ if (this.animation === animation)
322
+ this.animation = undefined;
323
+ onComplete?.();
323
324
  });
325
+ if (!isComplete)
326
+ this.animation = animation;
327
+ this.events.animationStart?.notify();
324
328
  }
325
329
  /**
326
330
  * Stop the currently active animation.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/value/index.ts"],"sourcesContent":["import {\n EasingFunction,\n SubscriptionManager,\n velocityPerSecond,\n warnOnce,\n} from \"motion-utils\"\nimport {\n AnimationPlaybackControlsWithThen,\n AnyResolvedKeyframe,\n MotionValueAnimation,\n TransformProperties,\n} from \"../animation/types\"\nimport { frame } from \"../frameloop\"\nimport { time } from \"../frameloop/sync-time\"\n\n/**\n * @public\n */\nexport type Subscriber<T> = (v: T) => void\n\n/**\n * @public\n */\nexport type PassiveEffect<T> = (v: T, safeSetter: (v: T) => void) => void\n\nexport type StartAnimation = (\n complete: () => void\n) => AnimationPlaybackControlsWithThen | undefined\n\nexport interface MotionValueEventCallbacks<V> {\n animationStart: () => void\n animationComplete: () => void\n animationCancel: () => void\n change: (latestValue: V) => void\n destroy: () => void\n}\n\n/**\n * Maximum time between the value of two frames, beyond which we\n * assume the velocity has since been 0.\n */\nconst MAX_VELOCITY_DELTA = 30\n\nconst isFloat = (value: any): value is string => {\n return !isNaN(parseFloat(value))\n}\n\ninterface ResolvedValues {\n [key: string]: AnyResolvedKeyframe\n}\n\nexport interface Owner {\n current: HTMLElement | unknown\n getProps: () => {\n onUpdate?: (latest: ResolvedValues) => void\n transformTemplate?: (\n transform: TransformProperties,\n generatedTransform: string\n ) => string\n }\n}\n\nexport interface AccelerateConfig {\n factory: (animation: AnimationPlaybackControlsWithThen) => VoidFunction\n times: number[]\n keyframes: any[]\n ease?: EasingFunction | EasingFunction[]\n duration: number\n isTransformed?: boolean\n}\n\nexport interface MotionValueOptions {\n owner?: Owner\n}\n\nexport const collectMotionValues: { current: MotionValue[] | undefined } = {\n current: undefined,\n}\n\n/**\n * `MotionValue` is used to track the state and velocity of motion values.\n *\n * @public\n */\nexport class MotionValue<V = any> {\n /**\n * If a MotionValue has an owner, it was created internally within Motion\n * and therefore has no external listeners. It is therefore safe to animate via WAAPI.\n */\n owner?: Owner\n\n /**\n * The current state of the `MotionValue`.\n */\n private current: V | undefined\n\n /**\n * The previous state of the `MotionValue`.\n */\n private prev: V | undefined\n\n /**\n * The previous state of the `MotionValue` at the end of the previous frame.\n */\n private prevFrameValue: V | undefined\n\n /**\n * The last time the `MotionValue` was updated.\n */\n updatedAt: number\n\n /**\n * The time `prevFrameValue` was updated.\n */\n prevUpdatedAt: number | undefined\n\n /**\n * Add a passive effect to this `MotionValue`.\n *\n * A passive effect intercepts calls to `set`. For instance, `useSpring` adds\n * a passive effect that attaches a `spring` to the latest\n * set value. Hypothetically there could be a `useSmooth` that attaches an input smoothing effect.\n *\n * @internal\n */\n private passiveEffect?: PassiveEffect<V>\n private stopPassiveEffect?: VoidFunction\n\n /**\n * Whether the passive effect is active.\n */\n isEffectActive?: boolean\n\n /**\n * A reference to the currently-controlling animation.\n */\n animation?: MotionValueAnimation\n\n /**\n * The sole `change` subscriber. Most values have exactly one (an\n * effect or a follower), so it's stored and notified directly. A\n * SubscriptionManager is only created for a second subscriber.\n */\n private changeSubscriber?: Subscriber<V>\n\n /**\n * Tracks whether this value can output a velocity. Currently this is only true\n * if the value is numerical, but we might be able to widen the scope here and support\n * other value types.\n *\n * @internal\n */\n private canTrackVelocity: boolean | null = null\n\n /**\n * A list of MotionValues whose values are computed from this one.\n * This is a rough start to a proper signal-like dirtying system.\n */\n private dependents: Set<MotionValue> | undefined\n\n /**\n * Tracks whether this value should be removed\n */\n liveStyle?: boolean\n\n /**\n * Scroll timeline acceleration metadata. When set, VisualElement\n * can create a native WAAPI animation attached to a scroll timeline\n * instead of driving updates through JS.\n */\n accelerate?: AccelerateConfig\n\n /**\n * @param init - The initiating value\n * @param config - Optional configuration options\n *\n * - `transformer`: A function to transform incoming values with.\n */\n constructor(init: V, options: MotionValueOptions = {}) {\n this.setCurrent(init)\n this.owner = options.owner\n }\n\n setCurrent(current: V) {\n this.current = current\n this.updatedAt = time.now()\n\n if (this.canTrackVelocity === null && current !== undefined) {\n this.canTrackVelocity = isFloat(this.current)\n }\n }\n\n setPrevFrameValue(prevFrameValue: V | undefined = this.current) {\n this.prevFrameValue = prevFrameValue\n this.prevUpdatedAt = this.updatedAt\n }\n\n /**\n * Adds a function that will be notified when the `MotionValue` is updated.\n *\n * It returns a function that, when called, will cancel the subscription.\n *\n * When calling `onChange` inside a React component, it should be wrapped with the\n * `useEffect` hook. As it returns an unsubscribe function, this should be returned\n * from the `useEffect` function to ensure you don't add duplicate subscribers..\n *\n * ```jsx\n * export const MyComponent = () => {\n * const x = useMotionValue(0)\n * const y = useMotionValue(0)\n * const opacity = useMotionValue(1)\n *\n * useEffect(() => {\n * function updateOpacity() {\n * const maxXY = Math.max(x.get(), y.get())\n * const newOpacity = transform(maxXY, [0, 100], [1, 0])\n * opacity.set(newOpacity)\n * }\n *\n * const unsubscribeX = x.on(\"change\", updateOpacity)\n * const unsubscribeY = y.on(\"change\", updateOpacity)\n *\n * return () => {\n * unsubscribeX()\n * unsubscribeY()\n * }\n * }, [])\n *\n * return <motion.div style={{ x }} />\n * }\n * ```\n *\n * @param subscriber - A function that receives the latest value.\n * @returns A function that, when called, will cancel this subscription.\n *\n * @deprecated\n */\n onChange(subscription: Subscriber<V>): () => void {\n if (process.env.NODE_ENV !== \"production\") {\n warnOnce(\n false,\n `value.onChange(callback) is deprecated. Switch to value.on(\"change\", callback).`\n )\n }\n return this.on(\"change\", subscription)\n }\n\n /**\n * An object containing a SubscriptionManager for each active event.\n */\n private events: {\n [key: string]: SubscriptionManager<any>\n } = {}\n\n on<EventName extends keyof MotionValueEventCallbacks<V>>(\n eventName: EventName,\n callback: MotionValueEventCallbacks<V>[EventName]\n ): VoidFunction {\n if (eventName === \"change\") return this.onChangeSubscribe(callback)\n\n return (this.events[eventName] ||= new SubscriptionManager()).add(\n callback\n )\n }\n\n private onChangeSubscribe(callback: Subscriber<V>): VoidFunction {\n const { events } = this\n\n if (!events.change && !this.changeSubscriber) {\n this.changeSubscriber = callback\n } else {\n if (!events.change) {\n events.change = new SubscriptionManager()\n events.change.add(this.changeSubscriber!)\n this.changeSubscriber = undefined\n }\n events.change.add(callback)\n }\n\n return () => {\n if (this.changeSubscriber === callback) {\n this.changeSubscriber = undefined\n } else {\n events.change?.remove(callback)\n }\n this.stopIfUnobserved()\n }\n }\n\n /**\n * If we have no more change listeners by the start\n * of the next frame, stop active animations.\n */\n private stopIfUnobserved() {\n frame.read(() => {\n if (!this.changeSubscriber && !this.events.change?.getSize()) {\n this.stop()\n }\n })\n }\n\n clearListeners() {\n this.changeSubscriber = undefined\n for (const eventManagers in this.events) {\n this.events[eventManagers].clear()\n }\n }\n\n /**\n * Attaches a passive effect to the `MotionValue`.\n */\n attach(passiveEffect: PassiveEffect<V>, stopPassiveEffect: VoidFunction) {\n this.passiveEffect = passiveEffect\n this.stopPassiveEffect = stopPassiveEffect\n }\n\n /**\n * Sets the state of the `MotionValue`.\n *\n * @remarks\n *\n * ```jsx\n * const x = useMotionValue(0)\n * x.set(10)\n * ```\n *\n * @param latest - Latest value to set.\n * @param render - Whether to notify render subscribers. Defaults to `true`\n *\n * @public\n */\n set(v: V) {\n this.passiveEffect\n ? this.passiveEffect(v, this.updateAndNotify)\n : this.updateAndNotify(v)\n }\n\n setWithVelocity(prev: V, current: V, delta: number) {\n this.set(current)\n this.prev = undefined\n this.prevFrameValue = prev\n this.prevUpdatedAt = this.updatedAt - delta\n }\n\n /**\n * Set the state of the `MotionValue`, stopping any active animations,\n * effects, and resets velocity to `0`.\n */\n jump(v: V, endAnimation = true) {\n if (endAnimation) {\n /**\n * Stop first, as stopping a running animation can set the\n * value it's showing, which would replace v. Marking the value\n * as updated now skips a JS animation's catch-up tick on stop,\n * which could otherwise complete it.\n */\n this.updatedAt = time.now()\n this.stop()\n }\n this.updateAndNotify(v)\n this.prev = v\n this.prevUpdatedAt = this.prevFrameValue = undefined\n this.stopPassiveEffect?.()\n }\n\n dirty() {\n const { current, changeSubscriber } = this\n /**\n * One or the other exists. Subscribing during the direct\n * subscriber's call moves it into a new manager, which must not\n * then be notified for the same change.\n */\n if (changeSubscriber) {\n changeSubscriber(current!)\n } else {\n this.events.change?.notify(current)\n }\n }\n\n addDependent(dependent: MotionValue) {\n ;(this.dependents ||= new Set()).add(dependent)\n }\n\n removeDependent(dependent: MotionValue) {\n this.dependents?.delete(dependent)\n }\n\n updateAndNotify = (v: V) => {\n const currentTime = time.now()\n\n /**\n * If we're updating the value during another frame or eventloop\n * than the previous frame, then the we set the previous frame value\n * to current.\n */\n if (this.updatedAt !== currentTime) {\n this.setPrevFrameValue()\n }\n\n this.prev = this.current\n\n this.setCurrent(v)\n\n // Update update subscribers\n if (this.current !== this.prev) {\n this.dirty()\n\n if (this.dependents) {\n for (const dependent of this.dependents) {\n dependent.dirty()\n }\n }\n }\n }\n\n /**\n * Returns the latest state of `MotionValue`\n *\n * @returns - The latest state of `MotionValue`\n *\n * @public\n */\n get() {\n collectMotionValues.current?.push(this)\n\n /**\n * A value animating on the compositor isn't updated every frame,\n * so read it from its animation.\n */\n const sampled = this.animation?.liveValue?.()\n\n return sampled === undefined ? this.current! : (sampled as V)\n }\n\n /**\n * The value as last set. Unlike get(), this doesn't read an animation\n * running on the compositor, which renders the value itself.\n */\n getCurrent() {\n return this.current!\n }\n\n /**\n * @public\n */\n getPrevious() {\n return this.prev\n }\n\n /**\n * Returns the latest velocity of `MotionValue`\n *\n * @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.\n *\n * @public\n */\n getVelocity() {\n const currentTime = time.now()\n\n if (\n !this.canTrackVelocity ||\n this.prevFrameValue === undefined ||\n currentTime - this.updatedAt > MAX_VELOCITY_DELTA\n ) {\n return 0\n }\n\n const delta = Math.min(\n this.updatedAt - this.prevUpdatedAt!,\n MAX_VELOCITY_DELTA\n )\n\n // Casts because of parseFloat's poor typing\n return velocityPerSecond(\n parseFloat(this.current as any) -\n parseFloat(this.prevFrameValue as any),\n delta\n )\n }\n\n hasAnimated = false\n\n /**\n * Registers a new animation to control this `MotionValue`. Only one\n * animation can drive a `MotionValue` at one time.\n *\n * ```jsx\n * value.start()\n * ```\n *\n * @param animation - A function that starts the provided animation\n */\n start(startAnimation: StartAnimation) {\n this.stop()\n\n return new Promise<void>((resolve) => {\n this.hasAnimated = true\n\n /**\n * Complete synchronously via the callback rather than chaining a\n * second promise per animation. Guard against animations that\n * complete before startAnimation has returned.\n */\n let isComplete = false\n let animation: MotionValueAnimation | undefined\n // eslint-disable-next-line prefer-const -- read by the callback before assignment when completing synchronously\n animation = startAnimation(() => {\n isComplete = true\n this.events.animationComplete?.notify()\n if (this.animation === animation) this.animation = undefined\n resolve()\n })\n\n if (!isComplete) this.animation = animation\n\n this.events.animationStart?.notify()\n })\n }\n\n /**\n * Stop the currently active animation.\n *\n * @public\n */\n stop() {\n if (this.animation) {\n this.animation.stop()\n this.events.animationCancel?.notify()\n }\n // Assign rather than delete to keep the object's shape stable\n this.animation = undefined\n }\n\n /**\n * Returns `true` if this value is currently animating.\n *\n * @public\n */\n isAnimating() {\n return !!this.animation\n }\n\n /**\n * Destroy and clean up subscribers to this `MotionValue`.\n *\n * The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically\n * handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually\n * created a `MotionValue` via the `motionValue` function.\n *\n * @public\n */\n destroy() {\n this.dependents?.clear()\n this.events.destroy?.notify()\n this.clearListeners()\n this.stop()\n this.stopPassiveEffect?.()\n }\n}\n\nexport function motionValue<V>(init: V, options?: MotionValueOptions) {\n return new MotionValue<V>(init, options)\n}\n"],"names":[],"mappings":";;;;AAqCA;;;AAGG;AACH,MAAM,kBAAkB,GAAG,EAAE;AAE7B,MAAM,OAAO,GAAG,CAAC,KAAU,KAAqB;IAC5C,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AA8BM,MAAM,mBAAmB,GAA2C;AACvE,IAAA,OAAO,EAAE,SAAS;;AAGtB;;;;AAIG;MACU,WAAW,CAAA;AAwFpB;;;;;AAKG;IACH,WAAA,CAAY,IAAO,EAAE,OAAA,GAA8B,EAAE,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AI,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE;AACxC,QAAA,CAAC,CAAC;IACN;AAEA;;;;AAIG;IACH,IAAI,GAAA;AACA,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAChB,YAAA,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;AACrB,YAAA,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,EAAE;QACzC;;AAEA,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS;IAC9B;AAEA;;;;AAIG;IACH,WAAW,GAAA;AACP,QAAA,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS;IAC3B;AAEA;;;;;;;;AAQG;IACH,OAAO,GAAA;AACH,QAAA,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE;AACxB,QAAA,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE;QAC7B,IAAI,CAAC,cAAc,EAAE;QACrB,IAAI,CAAC,IAAI,EAAE;AACX,QAAA,IAAI,CAAC,iBAAiB,IAAI;IAC9B;AACH;AAEK,SAAU,WAAW,CAAI,IAAO,EAAE,OAA4B,EAAA;AAChE,IAAA,OAAO,IAAI,WAAW,CAAI,IAAI,EAAE,OAAO,CAAC;AAC5C;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/value/index.ts"],"sourcesContent":["import {\n EasingFunction,\n SubscriptionManager,\n velocityPerSecond,\n warnOnce,\n} from \"motion-utils\"\nimport {\n AnimationPlaybackControlsWithThen,\n AnyResolvedKeyframe,\n MotionValueAnimation,\n TransformProperties,\n} from \"../animation/types\"\nimport { frame } from \"../frameloop\"\nimport { time } from \"../frameloop/sync-time\"\n\n/**\n * @public\n */\nexport type Subscriber<T> = (v: T) => void\n\n/**\n * @public\n */\nexport type PassiveEffect<T> = (v: T, safeSetter: (v: T) => void) => void\n\nexport type StartAnimation = (\n complete: () => void\n) => AnimationPlaybackControlsWithThen | undefined\n\nexport interface MotionValueEventCallbacks<V> {\n animationStart: () => void\n animationComplete: () => void\n animationCancel: () => void\n change: (latestValue: V) => void\n destroy: () => void\n}\n\n/**\n * Maximum time between the value of two frames, beyond which we\n * assume the velocity has since been 0.\n */\nconst MAX_VELOCITY_DELTA = 30\n\nconst isFloat = (value: any): value is string => {\n return !isNaN(parseFloat(value))\n}\n\ninterface ResolvedValues {\n [key: string]: AnyResolvedKeyframe\n}\n\nexport interface Owner {\n current: HTMLElement | unknown\n getProps: () => {\n onUpdate?: (latest: ResolvedValues) => void\n transformTemplate?: (\n transform: TransformProperties,\n generatedTransform: string\n ) => string\n }\n}\n\nexport interface AccelerateConfig {\n factory: (animation: AnimationPlaybackControlsWithThen) => VoidFunction\n times: number[]\n keyframes: any[]\n ease?: EasingFunction | EasingFunction[]\n duration: number\n isTransformed?: boolean\n}\n\nexport interface MotionValueOptions {\n owner?: Owner\n}\n\nexport const collectMotionValues: { current: MotionValue[] | undefined } = {\n current: undefined,\n}\n\n/**\n * `MotionValue` is used to track the state and velocity of motion values.\n *\n * @public\n */\nexport class MotionValue<V = any> {\n /**\n * If a MotionValue has an owner, it was created internally within Motion\n * and therefore has no external listeners. It is therefore safe to animate via WAAPI.\n */\n owner?: Owner\n\n /**\n * The current state of the `MotionValue`.\n */\n private current: V | undefined\n\n /**\n * The previous state of the `MotionValue`.\n */\n private prev: V | undefined\n\n /**\n * The previous state of the `MotionValue` at the end of the previous frame.\n */\n private prevFrameValue: V | undefined\n\n /**\n * The last time the `MotionValue` was updated.\n */\n updatedAt: number\n\n /**\n * The time `prevFrameValue` was updated.\n */\n prevUpdatedAt: number | undefined\n\n /**\n * Add a passive effect to this `MotionValue`.\n *\n * A passive effect intercepts calls to `set`. For instance, `useSpring` adds\n * a passive effect that attaches a `spring` to the latest\n * set value. Hypothetically there could be a `useSmooth` that attaches an input smoothing effect.\n *\n * @internal\n */\n private passiveEffect?: PassiveEffect<V>\n private stopPassiveEffect?: VoidFunction\n\n /**\n * Whether the passive effect is active.\n */\n isEffectActive?: boolean\n\n /**\n * A reference to the currently-controlling animation.\n */\n animation?: MotionValueAnimation\n\n /**\n * The sole `change` subscriber. Most values have exactly one (an\n * effect or a follower), so it's stored and notified directly. A\n * SubscriptionManager is only created for a second subscriber.\n */\n private changeSubscriber?: Subscriber<V>\n\n /**\n * Tracks whether this value can output a velocity. Currently this is only true\n * if the value is numerical, but we might be able to widen the scope here and support\n * other value types.\n *\n * @internal\n */\n private canTrackVelocity: boolean | null = null\n\n /**\n * A list of MotionValues whose values are computed from this one.\n * This is a rough start to a proper signal-like dirtying system.\n */\n private dependents: Set<MotionValue> | undefined\n\n /**\n * Tracks whether this value should be removed\n */\n liveStyle?: boolean\n\n /**\n * Scroll timeline acceleration metadata. When set, VisualElement\n * can create a native WAAPI animation attached to a scroll timeline\n * instead of driving updates through JS.\n */\n accelerate?: AccelerateConfig\n\n /**\n * @param init - The initiating value\n * @param config - Optional configuration options\n *\n * - `transformer`: A function to transform incoming values with.\n */\n constructor(init: V, options: MotionValueOptions = {}) {\n this.setCurrent(init)\n this.owner = options.owner\n }\n\n setCurrent(current: V) {\n this.current = current\n this.updatedAt = time.now()\n\n if (this.canTrackVelocity === null && current !== undefined) {\n this.canTrackVelocity = isFloat(this.current)\n }\n }\n\n setPrevFrameValue(prevFrameValue: V | undefined = this.current) {\n this.prevFrameValue = prevFrameValue\n this.prevUpdatedAt = this.updatedAt\n }\n\n /**\n * Adds a function that will be notified when the `MotionValue` is updated.\n *\n * It returns a function that, when called, will cancel the subscription.\n *\n * When calling `onChange` inside a React component, it should be wrapped with the\n * `useEffect` hook. As it returns an unsubscribe function, this should be returned\n * from the `useEffect` function to ensure you don't add duplicate subscribers..\n *\n * ```jsx\n * export const MyComponent = () => {\n * const x = useMotionValue(0)\n * const y = useMotionValue(0)\n * const opacity = useMotionValue(1)\n *\n * useEffect(() => {\n * function updateOpacity() {\n * const maxXY = Math.max(x.get(), y.get())\n * const newOpacity = transform(maxXY, [0, 100], [1, 0])\n * opacity.set(newOpacity)\n * }\n *\n * const unsubscribeX = x.on(\"change\", updateOpacity)\n * const unsubscribeY = y.on(\"change\", updateOpacity)\n *\n * return () => {\n * unsubscribeX()\n * unsubscribeY()\n * }\n * }, [])\n *\n * return <motion.div style={{ x }} />\n * }\n * ```\n *\n * @param subscriber - A function that receives the latest value.\n * @returns A function that, when called, will cancel this subscription.\n *\n * @deprecated\n */\n onChange(subscription: Subscriber<V>): () => void {\n if (process.env.NODE_ENV !== \"production\") {\n warnOnce(\n false,\n `value.onChange(callback) is deprecated. Switch to value.on(\"change\", callback).`\n )\n }\n return this.on(\"change\", subscription)\n }\n\n /**\n * An object containing a SubscriptionManager for each active event.\n */\n private events: {\n [key: string]: SubscriptionManager<any>\n } = {}\n\n on<EventName extends keyof MotionValueEventCallbacks<V>>(\n eventName: EventName,\n callback: MotionValueEventCallbacks<V>[EventName]\n ): VoidFunction {\n if (eventName === \"change\") return this.onChangeSubscribe(callback)\n\n return (this.events[eventName] ||= new SubscriptionManager()).add(\n callback\n )\n }\n\n private onChangeSubscribe(callback: Subscriber<V>): VoidFunction {\n const { events } = this\n\n if (!events.change && !this.changeSubscriber) {\n this.changeSubscriber = callback\n } else {\n if (!events.change) {\n events.change = new SubscriptionManager()\n events.change.add(this.changeSubscriber!)\n this.changeSubscriber = undefined\n }\n events.change.add(callback)\n }\n\n return () => {\n if (this.changeSubscriber === callback) {\n this.changeSubscriber = undefined\n } else {\n events.change?.remove(callback)\n }\n this.stopIfUnobserved()\n }\n }\n\n /**\n * If we have no more change listeners by the start\n * of the next frame, stop active animations.\n */\n private stopIfUnobserved() {\n frame.read(() => {\n if (!this.changeSubscriber && !this.events.change?.getSize()) {\n this.stop()\n }\n })\n }\n\n clearListeners() {\n this.changeSubscriber = undefined\n for (const eventManagers in this.events) {\n this.events[eventManagers].clear()\n }\n }\n\n /**\n * Attaches a passive effect to the `MotionValue`.\n */\n attach(passiveEffect: PassiveEffect<V>, stopPassiveEffect: VoidFunction) {\n this.passiveEffect = passiveEffect\n this.stopPassiveEffect = stopPassiveEffect\n }\n\n /**\n * Sets the state of the `MotionValue`.\n *\n * @remarks\n *\n * ```jsx\n * const x = useMotionValue(0)\n * x.set(10)\n * ```\n *\n * @param latest - Latest value to set.\n * @param render - Whether to notify render subscribers. Defaults to `true`\n *\n * @public\n */\n set(v: V) {\n this.passiveEffect\n ? this.passiveEffect(v, this.updateAndNotify)\n : this.updateAndNotify(v)\n }\n\n setWithVelocity(prev: V, current: V, delta: number) {\n this.set(current)\n this.prev = undefined\n this.prevFrameValue = prev\n this.prevUpdatedAt = this.updatedAt - delta\n }\n\n /**\n * Set the state of the `MotionValue`, stopping any active animations,\n * effects, and resets velocity to `0`.\n */\n jump(v: V, endAnimation = true) {\n if (endAnimation) {\n /**\n * Stop first, as stopping a running animation can set the\n * value it's showing, which would replace v. Marking the value\n * as updated now skips a JS animation's catch-up tick on stop,\n * which could otherwise complete it.\n */\n this.updatedAt = time.now()\n this.stop()\n }\n this.updateAndNotify(v)\n this.prev = v\n this.prevUpdatedAt = this.prevFrameValue = undefined\n this.stopPassiveEffect?.()\n }\n\n dirty() {\n const { current, changeSubscriber } = this\n /**\n * One or the other exists. Subscribing during the direct\n * subscriber's call moves it into a new manager, which must not\n * then be notified for the same change.\n */\n if (changeSubscriber) {\n changeSubscriber(current!)\n } else {\n this.events.change?.notify(current)\n }\n }\n\n addDependent(dependent: MotionValue) {\n ;(this.dependents ||= new Set()).add(dependent)\n }\n\n removeDependent(dependent: MotionValue) {\n this.dependents?.delete(dependent)\n }\n\n updateAndNotify = (v: V) => {\n const currentTime = time.now()\n\n /**\n * If we're updating the value during another frame or eventloop\n * than the previous frame, then the we set the previous frame value\n * to current.\n */\n if (this.updatedAt !== currentTime) {\n this.setPrevFrameValue()\n }\n\n this.prev = this.current\n\n this.setCurrent(v)\n\n // Update update subscribers\n if (this.current !== this.prev) {\n this.dirty()\n\n if (this.dependents) {\n for (const dependent of this.dependents) {\n dependent.dirty()\n }\n }\n }\n }\n\n /**\n * Returns the latest state of `MotionValue`\n *\n * @returns - The latest state of `MotionValue`\n *\n * @public\n */\n get() {\n collectMotionValues.current?.push(this)\n\n /**\n * A value animating on the compositor isn't updated every frame,\n * so read it from its animation.\n */\n const sampled = this.animation?.liveValue?.()\n\n return sampled === undefined ? this.current! : (sampled as V)\n }\n\n /**\n * The value as last set. Unlike get(), this doesn't read an animation\n * running on the compositor, which renders the value itself.\n */\n getCurrent() {\n return this.current!\n }\n\n /**\n * @public\n */\n getPrevious() {\n return this.prev\n }\n\n /**\n * Returns the latest velocity of `MotionValue`\n *\n * @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.\n *\n * @public\n */\n getVelocity() {\n const currentTime = time.now()\n\n if (\n !this.canTrackVelocity ||\n this.prevFrameValue === undefined ||\n currentTime - this.updatedAt > MAX_VELOCITY_DELTA\n ) {\n return 0\n }\n\n const delta = Math.min(\n this.updatedAt - this.prevUpdatedAt!,\n MAX_VELOCITY_DELTA\n )\n\n // Casts because of parseFloat's poor typing\n return velocityPerSecond(\n parseFloat(this.current as any) -\n parseFloat(this.prevFrameValue as any),\n delta\n )\n }\n\n hasAnimated = false\n\n /**\n * Registers a new animation to control this `MotionValue`. Only one\n * animation can drive a `MotionValue` at one time.\n *\n * ```jsx\n * value.start()\n * ```\n *\n * @param animation - A function that starts the provided animation\n */\n start(startAnimation: StartAnimation) {\n return new Promise<void>((resolve) => this.run(startAnimation, resolve))\n }\n\n /**\n * As start(), without making a promise, for animations started\n * internally, which complete through their own controls.\n */\n run(startAnimation: StartAnimation, onComplete?: VoidFunction) {\n this.stop()\n this.hasAnimated = true\n\n /**\n * Guard against animations that complete before startAnimation\n * has returned.\n */\n let isComplete = false\n let animation: MotionValueAnimation | undefined\n // eslint-disable-next-line prefer-const -- read by the callback before assignment when completing synchronously\n animation = startAnimation(() => {\n isComplete = true\n this.events.animationComplete?.notify()\n if (this.animation === animation) this.animation = undefined\n onComplete?.()\n })\n\n if (!isComplete) this.animation = animation\n\n this.events.animationStart?.notify()\n }\n\n /**\n * Stop the currently active animation.\n *\n * @public\n */\n stop() {\n if (this.animation) {\n this.animation.stop()\n this.events.animationCancel?.notify()\n }\n // Assign rather than delete to keep the object's shape stable\n this.animation = undefined\n }\n\n /**\n * Returns `true` if this value is currently animating.\n *\n * @public\n */\n isAnimating() {\n return !!this.animation\n }\n\n /**\n * Destroy and clean up subscribers to this `MotionValue`.\n *\n * The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically\n * handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually\n * created a `MotionValue` via the `motionValue` function.\n *\n * @public\n */\n destroy() {\n this.dependents?.clear()\n this.events.destroy?.notify()\n this.clearListeners()\n this.stop()\n this.stopPassiveEffect?.()\n }\n}\n\nexport function motionValue<V>(init: V, options?: MotionValueOptions) {\n return new MotionValue<V>(init, options)\n}\n"],"names":[],"mappings":";;;;AAqCA;;;AAGG;AACH,MAAM,kBAAkB,GAAG,EAAE;AAE7B,MAAM,OAAO,GAAG,CAAC,KAAU,KAAqB;IAC5C,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AA8BM,MAAM,mBAAmB,GAA2C;AACvE,IAAA,OAAO,EAAE,SAAS;;AAGtB;;;;AAIG;MACU,WAAW,CAAA;AAwFpB;;;;;AAKG;IACH,WAAA,CAAY,IAAO,EAAE,OAAA,GAA8B,EAAE,EAAA;AAjCrD;;;;;;AAMG;QACK,IAAA,CAAA,gBAAgB,GAAmB,IAAI;AA+F/C;;AAEG;QACK,IAAA,CAAA,MAAM,GAEV,EAAE;AAuIN,QAAA,IAAA,CAAA,eAAe,GAAG,CAAC,CAAI,KAAI;AACvB,YAAA,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE;AAE9B;;;;AAIG;AACH,YAAA,IAAI,IAAI,CAAC,SAAS,KAAK,WAAW,EAAE;gBAChC,IAAI,CAAC,iBAAiB,EAAE;YAC5B;AAEA,YAAA,IAAI,CAAC,IAAI,GAAG,IAA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,GAAG,SAAS;IAC9B;AAEA;;;;AAIG;IACH,WAAW,GAAA;AACP,QAAA,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS;IAC3B;AAEA;;;;;;;;AAQG;IACH,OAAO,GAAA;AACH,QAAA,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE;AACxB,QAAA,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE;QAC7B,IAAI,CAAC,cAAc,EAAE;QACrB,IAAI,CAAC,IAAI,EAAE;AACX,QAAA,IAAI,CAAC,iBAAiB,IAAI;IAC9B;AACH;AAEK,SAAU,WAAW,CAAI,IAAO,EAAE,OAA4B,EAAA;AAChE,IAAA,OAAO,IAAI,WAAW,CAAI,IAAI,EAAE,OAAO,CAAC;AAC5C;;;;"}
@@ -4,14 +4,26 @@ import { mask } from '../complex/mask.mjs';
4
4
  import { getDefaultValueType } from '../maps/defaults.mjs';
5
5
 
6
6
  const customTypes = /*@__PURE__*/ new Set([filter, mask]);
7
+ /**
8
+ * The last call and its result. animate() on many elements asks for the
9
+ * same none for each one, and parsing the value is the slow part.
10
+ */
11
+ let lastKey;
12
+ let lastValue;
13
+ let lastNone;
7
14
  function getAnimatableNone(key, value) {
15
+ if (key === lastKey && value === lastValue)
16
+ return lastNone;
8
17
  let defaultValueType = getDefaultValueType(key);
9
18
  if (!customTypes.has(defaultValueType))
10
19
  defaultValueType = complex;
11
20
  // If value is not recognised as animatable, ie "none", create an animatable version origin based on the target
12
- return defaultValueType.getAnimatableNone
21
+ lastNone = defaultValueType.getAnimatableNone
13
22
  ? defaultValueType.getAnimatableNone(value)
14
23
  : undefined;
24
+ lastKey = key;
25
+ lastValue = value;
26
+ return lastNone;
15
27
  }
16
28
 
17
29
  export { getAnimatableNone };
@@ -1 +1 @@
1
- {"version":3,"file":"animatable-none.mjs","sources":["../../../../../src/value/types/utils/animatable-none.ts"],"sourcesContent":["import { complex } from \"../complex\"\nimport { filter } from \"../complex/filter\"\nimport { mask } from \"../complex/mask\"\nimport { getDefaultValueType } from \"../maps/defaults\"\n\nconst customTypes = /*@__PURE__*/ new Set([filter, mask])\n\nexport function getAnimatableNone(key: string, value: string) {\n let defaultValueType = getDefaultValueType(key)\n if (!customTypes.has(defaultValueType as any)) defaultValueType = complex\n // If value is not recognised as animatable, ie \"none\", create an animatable version origin based on the target\n return defaultValueType.getAnimatableNone\n ? defaultValueType.getAnimatableNone(value)\n : undefined\n}\n"],"names":[],"mappings":";;;;;AAKA,MAAM,WAAW,iBAAiB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEnD,SAAU,iBAAiB,CAAC,GAAW,EAAE,KAAa,EAAA;AACxD,IAAA,IAAI,gBAAgB,GAAG,mBAAmB,CAAC,GAAG,CAAC;AAC/C,IAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,gBAAuB,CAAC;QAAE,gBAAgB,GAAG,OAAO;;IAEzE,OAAO,gBAAgB,CAAC;AACpB,UAAE,gBAAgB,CAAC,iBAAiB,CAAC,KAAK;UACxC,SAAS;AACnB;;;;"}
1
+ {"version":3,"file":"animatable-none.mjs","sources":["../../../../../src/value/types/utils/animatable-none.ts"],"sourcesContent":["import { complex } from \"../complex\"\nimport { filter } from \"../complex/filter\"\nimport { mask } from \"../complex/mask\"\nimport { getDefaultValueType } from \"../maps/defaults\"\n\nconst customTypes = /*@__PURE__*/ new Set([filter, mask])\n\n/**\n * The last call and its result. animate() on many elements asks for the\n * same none for each one, and parsing the value is the slow part.\n */\nlet lastKey: string | undefined\nlet lastValue: string | undefined\nlet lastNone: any\n\nexport function getAnimatableNone(key: string, value: string) {\n if (key === lastKey && value === lastValue) return lastNone\n\n let defaultValueType = getDefaultValueType(key)\n if (!customTypes.has(defaultValueType as any)) defaultValueType = complex\n // If value is not recognised as animatable, ie \"none\", create an animatable version origin based on the target\n lastNone = defaultValueType.getAnimatableNone\n ? defaultValueType.getAnimatableNone(value)\n : undefined\n lastKey = key\n lastValue = value\n\n return lastNone\n}\n"],"names":[],"mappings":";;;;;AAKA,MAAM,WAAW,iBAAiB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEzD;;;AAGG;AACH,IAAI,OAA2B;AAC/B,IAAI,SAA6B;AACjC,IAAI,QAAa;AAEX,SAAU,iBAAiB,CAAC,GAAW,EAAE,KAAa,EAAA;AACxD,IAAA,IAAI,GAAG,KAAK,OAAO,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,OAAO,QAAQ;AAE3D,IAAA,IAAI,gBAAgB,GAAG,mBAAmB,CAAC,GAAG,CAAC;AAC/C,IAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,gBAAuB,CAAC;QAAE,gBAAgB,GAAG,OAAO;;IAEzE,QAAQ,GAAG,gBAAgB,CAAC;AACxB,UAAE,gBAAgB,CAAC,iBAAiB,CAAC,KAAK;UACxC,SAAS;IACf,OAAO,GAAG,GAAG;IACb,SAAS,GAAG,KAAK;AAEjB,IAAA,OAAO,QAAQ;AACnB;;;;"}