motion 10.17.1 → 11.11.12

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 (320) hide show
  1. package/.turbo/turbo-build.log +29 -0
  2. package/{LICENSE → LICENSE.md} +2 -2
  3. package/README.md +99 -7
  4. package/dist/cjs/index.js +6117 -0
  5. package/dist/cjs/react-client.js +10003 -0
  6. package/dist/cjs/react-m.js +1852 -0
  7. package/dist/es/framer-motion/dist/es/animation/GroupPlaybackControls.mjs +78 -0
  8. package/dist/es/framer-motion/dist/es/animation/animate/index.mjs +34 -0
  9. package/dist/es/framer-motion/dist/es/animation/animate/resolve-subjects.mjs +19 -0
  10. package/dist/es/framer-motion/dist/es/animation/animate/sequence.mjs +14 -0
  11. package/dist/es/framer-motion/dist/es/animation/animate/single-value.mjs +11 -0
  12. package/dist/es/framer-motion/dist/es/animation/animate/subject.mjs +52 -0
  13. package/dist/es/framer-motion/dist/es/animation/animators/AcceleratedAnimation.mjs +318 -0
  14. package/dist/es/framer-motion/dist/es/animation/animators/BaseAnimation.mjs +112 -0
  15. package/dist/es/framer-motion/dist/es/animation/animators/MainThreadAnimation.mjs +380 -0
  16. package/dist/es/framer-motion/dist/es/animation/animators/drivers/driver-frameloop.mjs +17 -0
  17. package/dist/es/framer-motion/dist/es/animation/animators/utils/accelerated-values.mjs +14 -0
  18. package/dist/es/framer-motion/dist/es/animation/animators/utils/can-animate.mjs +42 -0
  19. package/dist/es/framer-motion/dist/es/animation/animators/waapi/NativeAnimation.mjs +169 -0
  20. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-elements.mjs +36 -0
  21. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-style.mjs +12 -0
  22. package/dist/es/framer-motion/dist/es/animation/animators/waapi/easing.mjs +44 -0
  23. package/dist/es/framer-motion/dist/es/animation/animators/waapi/index.mjs +23 -0
  24. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/attach-timeline.mjs +6 -0
  25. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/get-final-keyframe.mjs +12 -0
  26. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/linear.mjs +15 -0
  27. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/memo-supports.mjs +9 -0
  28. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/style.mjs +8 -0
  29. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-flags.mjs +9 -0
  30. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-linear-easing.mjs +15 -0
  31. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-partial-keyframes.mjs +13 -0
  32. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-waapi.mjs +5 -0
  33. package/dist/es/framer-motion/dist/es/animation/generators/inertia.mjs +87 -0
  34. package/dist/es/framer-motion/dist/es/animation/generators/keyframes.mjs +51 -0
  35. package/dist/es/framer-motion/dist/es/animation/generators/spring/find.mjs +89 -0
  36. package/dist/es/framer-motion/dist/es/animation/generators/spring/index.mjs +129 -0
  37. package/dist/es/framer-motion/dist/es/animation/generators/utils/calc-duration.mjs +17 -0
  38. package/dist/es/framer-motion/dist/es/animation/generators/utils/is-generator.mjs +5 -0
  39. package/dist/es/framer-motion/dist/es/animation/generators/utils/velocity.mjs +9 -0
  40. package/dist/es/framer-motion/dist/es/animation/interfaces/motion-value.mjs +105 -0
  41. package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-target.mjs +75 -0
  42. package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-variant.mjs +66 -0
  43. package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element.mjs +26 -0
  44. package/dist/es/framer-motion/dist/es/animation/optimized-appear/data-id.mjs +6 -0
  45. package/dist/es/framer-motion/dist/es/animation/optimized-appear/get-appear-id.mjs +7 -0
  46. package/dist/es/framer-motion/dist/es/animation/sequence/create.mjs +230 -0
  47. package/dist/es/framer-motion/dist/es/animation/sequence/utils/calc-time.mjs +21 -0
  48. package/dist/es/framer-motion/dist/es/animation/sequence/utils/edit.mjs +31 -0
  49. package/dist/es/framer-motion/dist/es/animation/sequence/utils/sort.mjs +14 -0
  50. package/dist/es/framer-motion/dist/es/animation/utils/create-visual-element.mjs +44 -0
  51. package/dist/es/framer-motion/dist/es/animation/utils/default-transitions.mjs +40 -0
  52. package/dist/es/framer-motion/dist/es/animation/utils/get-value-transition.mjs +9 -0
  53. package/dist/es/framer-motion/dist/es/animation/utils/is-animatable.mjs +30 -0
  54. package/dist/es/framer-motion/dist/es/animation/utils/is-animation-controls.mjs +7 -0
  55. package/dist/es/framer-motion/dist/es/animation/utils/is-dom-keyframes.mjs +5 -0
  56. package/dist/es/framer-motion/dist/es/animation/utils/is-keyframes-target.mjs +5 -0
  57. package/dist/es/framer-motion/dist/es/animation/utils/is-none.mjs +15 -0
  58. package/dist/es/framer-motion/dist/es/animation/utils/is-transition-defined.mjs +10 -0
  59. package/dist/es/framer-motion/dist/es/animation/utils/stagger.mjs +26 -0
  60. package/dist/es/framer-motion/dist/es/components/AnimatePresence/use-presence.mjs +40 -0
  61. package/dist/es/framer-motion/dist/es/context/LayoutGroupContext.mjs +6 -0
  62. package/dist/es/framer-motion/dist/es/context/LazyContext.mjs +6 -0
  63. package/dist/es/framer-motion/dist/es/context/MotionConfigContext.mjs +13 -0
  64. package/dist/es/framer-motion/dist/es/context/MotionContext/create.mjs +13 -0
  65. package/dist/es/framer-motion/dist/es/context/MotionContext/index.mjs +6 -0
  66. package/dist/es/framer-motion/dist/es/context/MotionContext/utils.mjs +17 -0
  67. package/dist/es/framer-motion/dist/es/context/PresenceContext.mjs +9 -0
  68. package/dist/es/framer-motion/dist/es/context/SwitchLayoutGroupContext.mjs +9 -0
  69. package/dist/es/framer-motion/dist/es/easing/anticipate.mjs +5 -0
  70. package/dist/es/framer-motion/dist/es/easing/back.mjs +9 -0
  71. package/dist/es/framer-motion/dist/es/easing/circ.mjs +8 -0
  72. package/dist/es/framer-motion/dist/es/easing/cubic-bezier.mjs +51 -0
  73. package/dist/es/framer-motion/dist/es/easing/ease.mjs +7 -0
  74. package/dist/es/framer-motion/dist/es/easing/modifiers/mirror.mjs +5 -0
  75. package/dist/es/framer-motion/dist/es/easing/modifiers/reverse.mjs +5 -0
  76. package/dist/es/framer-motion/dist/es/easing/steps.mjs +15 -0
  77. package/dist/es/framer-motion/dist/es/easing/utils/create-generator-easing.mjs +17 -0
  78. package/dist/es/framer-motion/dist/es/easing/utils/get-easing-for-segment.mjs +8 -0
  79. package/dist/es/framer-motion/dist/es/easing/utils/is-bezier-definition.mjs +3 -0
  80. package/dist/es/framer-motion/dist/es/easing/utils/is-easing-array.mjs +5 -0
  81. package/dist/es/framer-motion/dist/es/easing/utils/map.mjs +38 -0
  82. package/dist/es/framer-motion/dist/es/events/add-dom-event.mjs +6 -0
  83. package/dist/es/framer-motion/dist/es/events/add-pointer-event.mjs +8 -0
  84. package/dist/es/framer-motion/dist/es/events/event-info.mjs +15 -0
  85. package/dist/es/framer-motion/dist/es/events/utils/is-primary-pointer.mjs +18 -0
  86. package/dist/es/framer-motion/dist/es/frameloop/batcher.mjs +71 -0
  87. package/dist/es/framer-motion/dist/es/frameloop/frame.mjs +6 -0
  88. package/dist/es/framer-motion/dist/es/frameloop/index-legacy.mjs +20 -0
  89. package/dist/es/framer-motion/dist/es/frameloop/microtask.mjs +5 -0
  90. package/dist/es/framer-motion/dist/es/frameloop/render-step.mjs +80 -0
  91. package/dist/es/framer-motion/dist/es/frameloop/sync-time.mjs +31 -0
  92. package/dist/es/framer-motion/dist/es/gestures/drag/VisualElementDragControls.mjs +487 -0
  93. package/dist/es/framer-motion/dist/es/gestures/drag/index.mjs +27 -0
  94. package/dist/es/framer-motion/dist/es/gestures/drag/utils/constraints.mjs +129 -0
  95. package/dist/es/framer-motion/dist/es/gestures/drag/utils/lock.mjs +53 -0
  96. package/dist/es/framer-motion/dist/es/gestures/focus.mjs +41 -0
  97. package/dist/es/framer-motion/dist/es/gestures/hover.mjs +33 -0
  98. package/dist/es/framer-motion/dist/es/gestures/pan/PanSession.mjs +156 -0
  99. package/dist/es/framer-motion/dist/es/gestures/pan/index.mjs +50 -0
  100. package/dist/es/framer-motion/dist/es/gestures/press.mjs +130 -0
  101. package/dist/es/framer-motion/dist/es/gestures/utils/is-node-or-child.mjs +20 -0
  102. package/dist/es/framer-motion/dist/es/motion/features/Feature.mjs +9 -0
  103. package/dist/es/framer-motion/dist/es/motion/features/animation/exit.mjs +31 -0
  104. package/dist/es/framer-motion/dist/es/motion/features/animation/index.mjs +41 -0
  105. package/dist/es/framer-motion/dist/es/motion/features/animations.mjs +13 -0
  106. package/dist/es/framer-motion/dist/es/motion/features/definitions.mjs +28 -0
  107. package/dist/es/framer-motion/dist/es/motion/features/drag.mjs +17 -0
  108. package/dist/es/framer-motion/dist/es/motion/features/gestures.mjs +21 -0
  109. package/dist/es/framer-motion/dist/es/motion/features/layout/MeasureLayout.mjs +134 -0
  110. package/dist/es/framer-motion/dist/es/motion/features/layout.mjs +11 -0
  111. package/dist/es/framer-motion/dist/es/motion/features/load-features.mjs +12 -0
  112. package/dist/es/framer-motion/dist/es/motion/features/viewport/index.mjs +72 -0
  113. package/dist/es/framer-motion/dist/es/motion/features/viewport/observers.mjs +49 -0
  114. package/dist/es/framer-motion/dist/es/motion/index.mjs +98 -0
  115. package/dist/es/framer-motion/dist/es/motion/utils/is-forced-motion-value.mjs +11 -0
  116. package/dist/es/framer-motion/dist/es/motion/utils/symbol.mjs +3 -0
  117. package/dist/es/framer-motion/dist/es/motion/utils/use-motion-ref.mjs +36 -0
  118. package/dist/es/framer-motion/dist/es/motion/utils/use-visual-element.mjs +134 -0
  119. package/dist/es/framer-motion/dist/es/motion/utils/use-visual-state.mjs +82 -0
  120. package/dist/es/framer-motion/dist/es/motion/utils/valid-prop.mjs +57 -0
  121. package/dist/es/framer-motion/dist/es/projection/animation/mix-values.mjs +93 -0
  122. package/dist/es/framer-motion/dist/es/projection/geometry/conversion.mjs +33 -0
  123. package/dist/es/framer-motion/dist/es/projection/geometry/copy.mjs +31 -0
  124. package/dist/es/framer-motion/dist/es/projection/geometry/delta-apply.mjs +119 -0
  125. package/dist/es/framer-motion/dist/es/projection/geometry/delta-calc.mjs +52 -0
  126. package/dist/es/framer-motion/dist/es/projection/geometry/delta-remove.mjs +54 -0
  127. package/dist/es/framer-motion/dist/es/projection/geometry/models.mjs +17 -0
  128. package/dist/es/framer-motion/dist/es/projection/geometry/utils.mjs +31 -0
  129. package/dist/es/framer-motion/dist/es/projection/node/DocumentProjectionNode.mjs +13 -0
  130. package/dist/es/framer-motion/dist/es/projection/node/HTMLProjectionNode.mjs +27 -0
  131. package/dist/es/framer-motion/dist/es/projection/node/create-projection-node.mjs +1583 -0
  132. package/dist/es/framer-motion/dist/es/projection/node/state.mjs +19 -0
  133. package/dist/es/framer-motion/dist/es/projection/shared/stack.mjs +112 -0
  134. package/dist/es/framer-motion/dist/es/projection/styles/scale-border-radius.mjs +41 -0
  135. package/dist/es/framer-motion/dist/es/projection/styles/scale-box-shadow.mjs +35 -0
  136. package/dist/es/framer-motion/dist/es/projection/styles/scale-correction.mjs +6 -0
  137. package/dist/es/framer-motion/dist/es/projection/styles/transform.mjs +49 -0
  138. package/dist/es/framer-motion/dist/es/projection/utils/each-axis.mjs +5 -0
  139. package/dist/es/framer-motion/dist/es/projection/utils/has-transform.mjs +26 -0
  140. package/dist/es/framer-motion/dist/es/projection/utils/measure.mjs +17 -0
  141. package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +477 -0
  142. package/dist/es/framer-motion/dist/es/render/components/create-factory.mjs +23 -0
  143. package/dist/es/framer-motion/dist/es/render/components/m/create.mjs +6 -0
  144. package/dist/es/framer-motion/dist/es/render/components/m/elements.mjs +227 -0
  145. package/dist/es/framer-motion/dist/es/render/components/motion/create.mjs +15 -0
  146. package/dist/es/framer-motion/dist/es/render/components/motion/elements.mjs +194 -0
  147. package/dist/es/framer-motion/dist/es/render/dom/DOMKeyframesResolver.mjs +130 -0
  148. package/dist/es/framer-motion/dist/es/render/dom/DOMVisualElement.mjs +28 -0
  149. package/dist/es/framer-motion/dist/es/render/dom/create-visual-element.mjs +14 -0
  150. package/dist/es/framer-motion/dist/es/render/dom/resize/handle-element.mjs +64 -0
  151. package/dist/es/framer-motion/dist/es/render/dom/resize/handle-window.mjs +30 -0
  152. package/dist/es/framer-motion/dist/es/render/dom/resize/index.mjs +8 -0
  153. package/dist/es/framer-motion/dist/es/render/dom/scroll/index.mjs +80 -0
  154. package/dist/es/framer-motion/dist/es/render/dom/scroll/info.mjs +56 -0
  155. package/dist/es/framer-motion/dist/es/render/dom/scroll/observe.mjs +18 -0
  156. package/dist/es/framer-motion/dist/es/render/dom/scroll/offsets/edge.mjs +45 -0
  157. package/dist/es/framer-motion/dist/es/render/dom/scroll/offsets/index.mjs +59 -0
  158. package/dist/es/framer-motion/dist/es/render/dom/scroll/offsets/inset.mjs +45 -0
  159. package/dist/es/framer-motion/dist/es/render/dom/scroll/offsets/offset.mjs +35 -0
  160. package/dist/es/framer-motion/dist/es/render/dom/scroll/offsets/presets.mjs +20 -0
  161. package/dist/es/framer-motion/dist/es/render/dom/scroll/on-scroll-handler.mjs +48 -0
  162. package/dist/es/framer-motion/dist/es/render/dom/scroll/supports.mjs +5 -0
  163. package/dist/es/framer-motion/dist/es/render/dom/scroll/track.mjs +84 -0
  164. package/dist/es/framer-motion/dist/es/render/dom/use-render.mjs +33 -0
  165. package/dist/es/framer-motion/dist/es/render/dom/utils/camel-to-dash.mjs +6 -0
  166. package/dist/es/framer-motion/dist/es/render/dom/utils/css-variables-conversion.mjs +42 -0
  167. package/dist/es/framer-motion/dist/es/render/dom/utils/filter-props.mjs +59 -0
  168. package/dist/es/framer-motion/dist/es/render/dom/utils/is-css-variable.mjs +15 -0
  169. package/dist/es/framer-motion/dist/es/render/dom/utils/is-svg-component.mjs +30 -0
  170. package/dist/es/framer-motion/dist/es/render/dom/utils/is-svg-element.mjs +5 -0
  171. package/dist/es/framer-motion/dist/es/render/dom/utils/resolve-element.mjs +28 -0
  172. package/dist/es/framer-motion/dist/es/render/dom/utils/unit-conversion.mjs +65 -0
  173. package/dist/es/framer-motion/dist/es/render/dom/value-types/animatable-none.mjs +15 -0
  174. package/dist/es/framer-motion/dist/es/render/dom/value-types/defaults.mjs +30 -0
  175. package/dist/es/framer-motion/dist/es/render/dom/value-types/dimensions.mjs +15 -0
  176. package/dist/es/framer-motion/dist/es/render/dom/value-types/find.mjs +15 -0
  177. package/dist/es/framer-motion/dist/es/render/dom/value-types/get-as-type.mjs +10 -0
  178. package/dist/es/framer-motion/dist/es/render/dom/value-types/number-browser.mjs +41 -0
  179. package/dist/es/framer-motion/dist/es/render/dom/value-types/number.mjs +18 -0
  180. package/dist/es/framer-motion/dist/es/render/dom/value-types/test.mjs +6 -0
  181. package/dist/es/framer-motion/dist/es/render/dom/value-types/transform.mjs +31 -0
  182. package/dist/es/framer-motion/dist/es/render/dom/value-types/type-auto.mjs +9 -0
  183. package/dist/es/framer-motion/dist/es/render/dom/value-types/type-int.mjs +8 -0
  184. package/dist/es/framer-motion/dist/es/render/dom/viewport/index.mjs +43 -0
  185. package/dist/es/framer-motion/dist/es/render/html/HTMLVisualElement.mjs +57 -0
  186. package/dist/es/framer-motion/dist/es/render/html/config-motion.mjs +12 -0
  187. package/dist/es/framer-motion/dist/es/render/html/use-props.mjs +57 -0
  188. package/dist/es/framer-motion/dist/es/render/html/utils/build-styles.mjs +65 -0
  189. package/dist/es/framer-motion/dist/es/render/html/utils/build-transform.mjs +62 -0
  190. package/dist/es/framer-motion/dist/es/render/html/utils/create-render-state.mjs +8 -0
  191. package/dist/es/framer-motion/dist/es/render/html/utils/make-none-animatable.mjs +30 -0
  192. package/dist/es/framer-motion/dist/es/render/html/utils/render.mjs +9 -0
  193. package/dist/es/framer-motion/dist/es/render/html/utils/scrape-motion-values.mjs +20 -0
  194. package/dist/es/framer-motion/dist/es/render/html/utils/transform.mjs +28 -0
  195. package/dist/es/framer-motion/dist/es/render/object/ObjectVisualElement.mjs +41 -0
  196. package/dist/es/framer-motion/dist/es/render/store.mjs +3 -0
  197. package/dist/es/framer-motion/dist/es/render/svg/SVGVisualElement.mjs +45 -0
  198. package/dist/es/framer-motion/dist/es/render/svg/config-motion.mjs +40 -0
  199. package/dist/es/framer-motion/dist/es/render/svg/lowercase-elements.mjs +33 -0
  200. package/dist/es/framer-motion/dist/es/render/svg/use-props.mjs +24 -0
  201. package/dist/es/framer-motion/dist/es/render/svg/utils/build-attrs.mjs +52 -0
  202. package/dist/es/framer-motion/dist/es/render/svg/utils/camel-case-attrs.mjs +30 -0
  203. package/dist/es/framer-motion/dist/es/render/svg/utils/create-render-state.mjs +8 -0
  204. package/dist/es/framer-motion/dist/es/render/svg/utils/is-svg-tag.mjs +3 -0
  205. package/dist/es/framer-motion/dist/es/render/svg/utils/path.mjs +32 -0
  206. package/dist/es/framer-motion/dist/es/render/svg/utils/render.mjs +12 -0
  207. package/dist/es/framer-motion/dist/es/render/svg/utils/scrape-motion-values.mjs +19 -0
  208. package/dist/es/framer-motion/dist/es/render/svg/utils/transform-origin.mjs +18 -0
  209. package/dist/es/framer-motion/dist/es/render/utils/KeyframesResolver.mjs +164 -0
  210. package/dist/es/framer-motion/dist/es/render/utils/animation-state.mjs +332 -0
  211. package/dist/es/framer-motion/dist/es/render/utils/compare-by-depth.mjs +3 -0
  212. package/dist/es/framer-motion/dist/es/render/utils/flat-tree.mjs +24 -0
  213. package/dist/es/framer-motion/dist/es/render/utils/get-variant-context.mjs +28 -0
  214. package/dist/es/framer-motion/dist/es/render/utils/is-controlling-variants.mjs +13 -0
  215. package/dist/es/framer-motion/dist/es/render/utils/is-variant-label.mjs +8 -0
  216. package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +59 -0
  217. package/dist/es/framer-motion/dist/es/render/utils/resolve-dynamic-variants.mjs +8 -0
  218. package/dist/es/framer-motion/dist/es/render/utils/resolve-variants.mjs +36 -0
  219. package/dist/es/framer-motion/dist/es/render/utils/setters.mjs +27 -0
  220. package/dist/es/framer-motion/dist/es/render/utils/variant-props.mjs +12 -0
  221. package/dist/es/framer-motion/dist/es/utils/GlobalConfig.mjs +6 -0
  222. package/dist/es/framer-motion/dist/es/utils/array.mjs +11 -0
  223. package/dist/es/framer-motion/dist/es/utils/clamp.mjs +9 -0
  224. package/dist/es/framer-motion/dist/es/utils/delay.mjs +24 -0
  225. package/dist/es/framer-motion/dist/es/utils/distance.mjs +9 -0
  226. package/dist/es/framer-motion/dist/es/utils/errors.mjs +18 -0
  227. package/dist/es/framer-motion/dist/es/utils/get-context-window.mjs +6 -0
  228. package/dist/es/framer-motion/dist/es/utils/hsla-to-rgba.mjs +42 -0
  229. package/dist/es/framer-motion/dist/es/utils/interpolate.mjs +75 -0
  230. package/dist/es/framer-motion/dist/es/utils/is-browser.mjs +3 -0
  231. package/dist/es/framer-motion/dist/es/utils/is-numerical-string.mjs +6 -0
  232. package/dist/es/framer-motion/dist/es/utils/is-ref-object.mjs +7 -0
  233. package/dist/es/framer-motion/dist/es/utils/is-zero-value-string.mjs +6 -0
  234. package/dist/es/framer-motion/dist/es/utils/memo.mjs +10 -0
  235. package/dist/es/framer-motion/dist/es/utils/mix/color.mjs +47 -0
  236. package/dist/es/framer-motion/dist/es/utils/mix/complex.mjs +94 -0
  237. package/dist/es/framer-motion/dist/es/utils/mix/immediate.mjs +5 -0
  238. package/dist/es/framer-motion/dist/es/utils/mix/index.mjs +14 -0
  239. package/dist/es/framer-motion/dist/es/utils/mix/number.mjs +26 -0
  240. package/dist/es/framer-motion/dist/es/utils/mix/visibility.mjs +16 -0
  241. package/dist/es/framer-motion/dist/es/utils/noop.mjs +3 -0
  242. package/dist/es/framer-motion/dist/es/utils/offsets/default.mjs +9 -0
  243. package/dist/es/framer-motion/dist/es/utils/offsets/fill.mjs +12 -0
  244. package/dist/es/framer-motion/dist/es/utils/offsets/time.mjs +5 -0
  245. package/dist/es/framer-motion/dist/es/utils/pipe.mjs +11 -0
  246. package/dist/es/framer-motion/dist/es/utils/progress.mjs +18 -0
  247. package/dist/es/framer-motion/dist/es/utils/reduced-motion/index.mjs +19 -0
  248. package/dist/es/framer-motion/dist/es/utils/reduced-motion/state.mjs +5 -0
  249. package/dist/es/framer-motion/dist/es/utils/resolve-value.mjs +11 -0
  250. package/dist/es/framer-motion/dist/es/utils/shallow-compare.mjs +14 -0
  251. package/dist/es/framer-motion/dist/es/utils/subscription-manager.mjs +40 -0
  252. package/dist/es/framer-motion/dist/es/utils/time-conversion.mjs +10 -0
  253. package/dist/es/framer-motion/dist/es/utils/transform.mjs +21 -0
  254. package/dist/es/framer-motion/dist/es/utils/use-constant.mjs +18 -0
  255. package/dist/es/framer-motion/dist/es/utils/use-isomorphic-effect.mjs +6 -0
  256. package/dist/es/framer-motion/dist/es/utils/velocity-per-second.mjs +11 -0
  257. package/dist/es/framer-motion/dist/es/utils/warn-once.mjs +11 -0
  258. package/dist/es/framer-motion/dist/es/utils/wrap.mjs +6 -0
  259. package/dist/es/framer-motion/dist/es/value/index.mjs +313 -0
  260. package/dist/es/framer-motion/dist/es/value/types/color/hex.mjs +40 -0
  261. package/dist/es/framer-motion/dist/es/value/types/color/hsla.mjs +22 -0
  262. package/dist/es/framer-motion/dist/es/value/types/color/index.mjs +27 -0
  263. package/dist/es/framer-motion/dist/es/value/types/color/rgba.mjs +25 -0
  264. package/dist/es/framer-motion/dist/es/value/types/color/utils.mjs +29 -0
  265. package/dist/es/framer-motion/dist/es/value/types/complex/filter.mjs +30 -0
  266. package/dist/es/framer-motion/dist/es/value/types/complex/index.mjs +92 -0
  267. package/dist/es/framer-motion/dist/es/value/types/numbers/index.mjs +17 -0
  268. package/dist/es/framer-motion/dist/es/value/types/numbers/units.mjs +17 -0
  269. package/dist/es/framer-motion/dist/es/value/types/utils/color-regex.mjs +3 -0
  270. package/dist/es/framer-motion/dist/es/value/types/utils/float-regex.mjs +3 -0
  271. package/dist/es/framer-motion/dist/es/value/types/utils/is-nullish.mjs +5 -0
  272. package/dist/es/framer-motion/dist/es/value/types/utils/sanitize.mjs +5 -0
  273. package/dist/es/framer-motion/dist/es/value/types/utils/single-color-regex.mjs +3 -0
  274. package/dist/es/framer-motion/dist/es/value/use-will-change/add-will-change.mjs +14 -0
  275. package/dist/es/framer-motion/dist/es/value/use-will-change/is.mjs +7 -0
  276. package/dist/es/framer-motion/dist/es/value/utils/is-motion-value.mjs +3 -0
  277. package/dist/es/framer-motion/dist/es/value/utils/resolve-motion-value.mjs +16 -0
  278. package/dist/es/motion/lib/index.mjs +30 -0
  279. package/dist/es/motion/lib/react-client.mjs +3 -0
  280. package/dist/es/motion/lib/react-m.mjs +3 -0
  281. package/dist/index.d.ts +1 -0
  282. package/dist/motion.dev.js +6121 -0
  283. package/dist/motion.js +1 -0
  284. package/dist/react-client.d.ts +1 -0
  285. package/dist/react-m.d.ts +1 -0
  286. package/lib/index.js +1 -3
  287. package/lib/index.js.map +1 -1
  288. package/lib/react-client.js +3 -0
  289. package/lib/react-client.js.map +1 -0
  290. package/lib/react-m.js +3 -0
  291. package/lib/react-m.js.map +1 -0
  292. package/lib/react.js +3 -0
  293. package/lib/react.js.map +1 -0
  294. package/package.json +79 -29
  295. package/react/package.json +6 -0
  296. package/react-client/package.json +6 -0
  297. package/react-m/package.json +6 -0
  298. package/rollup.config.mjs +174 -0
  299. package/src/index.ts +1 -0
  300. package/src/react-client.ts +3 -0
  301. package/src/react-m.ts +3 -0
  302. package/src/react.ts +3 -0
  303. package/tsconfig.json +25 -0
  304. package/types/index.d.ts +1 -4
  305. package/types/react-client.d.ts +1 -0
  306. package/types/react-m.d.ts +1 -0
  307. package/types/react.d.ts +1 -0
  308. package/CHANGELOG.md +0 -372
  309. package/dist/animate.cjs.js +0 -22
  310. package/dist/animate.es.js +0 -19
  311. package/dist/main.cjs.js +0 -21
  312. package/dist/main.es.js +0 -3
  313. package/dist/motion.min.js +0 -1
  314. package/dist/motion.umd.js +0 -2359
  315. package/dist/size-index.js +0 -1
  316. package/lib/animate.js +0 -17
  317. package/lib/animate.js.map +0 -1
  318. package/types/animate.d.ts +0 -6
  319. package/types/animate.d.ts.map +0 -1
  320. package/types/index.d.ts.map +0 -1
@@ -1,2359 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Motion = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- function addUniqueItem(array, item) {
8
- array.indexOf(item) === -1 && array.push(item);
9
- }
10
- function removeItem(arr, item) {
11
- const index = arr.indexOf(item);
12
- index > -1 && arr.splice(index, 1);
13
- }
14
-
15
- const clamp = (min, max, v) => Math.min(Math.max(v, min), max);
16
-
17
- const defaults$1 = {
18
- duration: 0.3,
19
- delay: 0,
20
- endDelay: 0,
21
- repeat: 0,
22
- easing: "ease",
23
- };
24
-
25
- const isNumber = (value) => typeof value === "number";
26
-
27
- const isEasingList = (easing) => Array.isArray(easing) && !isNumber(easing[0]);
28
-
29
- const wrap = (min, max, v) => {
30
- const rangeSize = max - min;
31
- return ((((v - min) % rangeSize) + rangeSize) % rangeSize) + min;
32
- };
33
-
34
- function getEasingForSegment(easing, i) {
35
- return isEasingList(easing)
36
- ? easing[wrap(0, easing.length, i)]
37
- : easing;
38
- }
39
-
40
- const mix = (min, max, progress) => -progress * min + progress * max + min;
41
-
42
- const noop = () => { };
43
- const noopReturn = (v) => v;
44
-
45
- const progress = (min, max, value) => max - min === 0 ? 1 : (value - min) / (max - min);
46
-
47
- function fillOffset(offset, remaining) {
48
- const min = offset[offset.length - 1];
49
- for (let i = 1; i <= remaining; i++) {
50
- const offsetProgress = progress(0, remaining, i);
51
- offset.push(mix(min, 1, offsetProgress));
52
- }
53
- }
54
- function defaultOffset$1(length) {
55
- const offset = [0];
56
- fillOffset(offset, length - 1);
57
- return offset;
58
- }
59
-
60
- function interpolate(output, input = defaultOffset$1(output.length), easing = noopReturn) {
61
- const length = output.length;
62
- /**
63
- * If the input length is lower than the output we
64
- * fill the input to match. This currently assumes the input
65
- * is an animation progress value so is a good candidate for
66
- * moving outside the function.
67
- */
68
- const remainder = length - input.length;
69
- remainder > 0 && fillOffset(input, remainder);
70
- return (t) => {
71
- let i = 0;
72
- for (; i < length - 2; i++) {
73
- if (t < input[i + 1])
74
- break;
75
- }
76
- let progressInRange = clamp(0, 1, progress(input[i], input[i + 1], t));
77
- const segmentEasing = getEasingForSegment(easing, i);
78
- progressInRange = segmentEasing(progressInRange);
79
- return mix(output[i], output[i + 1], progressInRange);
80
- };
81
- }
82
-
83
- const isCubicBezier = (easing) => Array.isArray(easing) && isNumber(easing[0]);
84
-
85
- const isEasingGenerator = (easing) => typeof easing === "object" &&
86
- Boolean(easing.createAnimation);
87
-
88
- const isFunction = (value) => typeof value === "function";
89
-
90
- const isString = (value) => typeof value === "string";
91
-
92
- const time = {
93
- ms: (seconds) => seconds * 1000,
94
- s: (milliseconds) => milliseconds / 1000,
95
- };
96
-
97
- /*
98
- Convert velocity into velocity per second
99
-
100
- @param [number]: Unit per frame
101
- @param [number]: Frame duration in ms
102
- */
103
- function velocityPerSecond(velocity, frameDuration) {
104
- return frameDuration ? velocity * (1000 / frameDuration) : 0;
105
- }
106
-
107
- /*
108
- Bezier function generator
109
-
110
- This has been modified from Gaëtan Renaudeau's BezierEasing
111
- https://github.com/gre/bezier-easing/blob/master/src/index.js
112
- https://github.com/gre/bezier-easing/blob/master/LICENSE
113
-
114
- I've removed the newtonRaphsonIterate algo because in benchmarking it
115
- wasn't noticiably faster than binarySubdivision, indeed removing it
116
- usually improved times, depending on the curve.
117
-
118
- I also removed the lookup table, as for the added bundle size and loop we're
119
- only cutting ~4 or so subdivision iterations. I bumped the max iterations up
120
- to 12 to compensate and this still tended to be faster for no perceivable
121
- loss in accuracy.
122
-
123
- Usage
124
- const easeOut = cubicBezier(.17,.67,.83,.67);
125
- const x = easeOut(0.5); // returns 0.627...
126
- */
127
- // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
128
- const calcBezier = (t, a1, a2) => (((1.0 - 3.0 * a2 + 3.0 * a1) * t + (3.0 * a2 - 6.0 * a1)) * t + 3.0 * a1) * t;
129
- const subdivisionPrecision = 0.0000001;
130
- const subdivisionMaxIterations = 12;
131
- function binarySubdivide(x, lowerBound, upperBound, mX1, mX2) {
132
- let currentX;
133
- let currentT;
134
- let i = 0;
135
- do {
136
- currentT = lowerBound + (upperBound - lowerBound) / 2.0;
137
- currentX = calcBezier(currentT, mX1, mX2) - x;
138
- if (currentX > 0.0) {
139
- upperBound = currentT;
140
- }
141
- else {
142
- lowerBound = currentT;
143
- }
144
- } while (Math.abs(currentX) > subdivisionPrecision &&
145
- ++i < subdivisionMaxIterations);
146
- return currentT;
147
- }
148
- function cubicBezier(mX1, mY1, mX2, mY2) {
149
- // If this is a linear gradient, return linear easing
150
- if (mX1 === mY1 && mX2 === mY2)
151
- return noopReturn;
152
- const getTForX = (aX) => binarySubdivide(aX, 0, 1, mX1, mX2);
153
- // If animation is at start/end, return t without easing
154
- return (t) => t === 0 || t === 1 ? t : calcBezier(getTForX(t), mY1, mY2);
155
- }
156
-
157
- const steps = (steps, direction = "end") => (progress) => {
158
- progress =
159
- direction === "end"
160
- ? Math.min(progress, 0.999)
161
- : Math.max(progress, 0.001);
162
- const expanded = progress * steps;
163
- const rounded = direction === "end" ? Math.floor(expanded) : Math.ceil(expanded);
164
- return clamp(0, 1, rounded / steps);
165
- };
166
-
167
- const namedEasings = {
168
- ease: cubicBezier(0.25, 0.1, 0.25, 1.0),
169
- "ease-in": cubicBezier(0.42, 0.0, 1.0, 1.0),
170
- "ease-in-out": cubicBezier(0.42, 0.0, 0.58, 1.0),
171
- "ease-out": cubicBezier(0.0, 0.0, 0.58, 1.0),
172
- };
173
- const functionArgsRegex = /\((.*?)\)/;
174
- function getEasingFunction(definition) {
175
- // If already an easing function, return
176
- if (isFunction(definition))
177
- return definition;
178
- // If an easing curve definition, return bezier function
179
- if (isCubicBezier(definition))
180
- return cubicBezier(...definition);
181
- // If we have a predefined easing function, return
182
- if (namedEasings[definition])
183
- return namedEasings[definition];
184
- // If this is a steps function, attempt to create easing curve
185
- if (definition.startsWith("steps")) {
186
- const args = functionArgsRegex.exec(definition);
187
- if (args) {
188
- const argsArray = args[1].split(",");
189
- return steps(parseFloat(argsArray[0]), argsArray[1].trim());
190
- }
191
- }
192
- return noopReturn;
193
- }
194
-
195
- class Animation {
196
- constructor(output, keyframes = [0, 1], { easing, duration: initialDuration = defaults$1.duration, delay = defaults$1.delay, endDelay = defaults$1.endDelay, repeat = defaults$1.repeat, offset, direction = "normal", autoplay = true, } = {}) {
197
- this.startTime = null;
198
- this.rate = 1;
199
- this.t = 0;
200
- this.cancelTimestamp = null;
201
- this.easing = noopReturn;
202
- this.duration = 0;
203
- this.totalDuration = 0;
204
- this.repeat = 0;
205
- this.playState = "idle";
206
- this.finished = new Promise((resolve, reject) => {
207
- this.resolve = resolve;
208
- this.reject = reject;
209
- });
210
- easing = easing || defaults$1.easing;
211
- if (isEasingGenerator(easing)) {
212
- const custom = easing.createAnimation(keyframes);
213
- easing = custom.easing;
214
- keyframes = custom.keyframes || keyframes;
215
- initialDuration = custom.duration || initialDuration;
216
- }
217
- this.repeat = repeat;
218
- this.easing = isEasingList(easing) ? noopReturn : getEasingFunction(easing);
219
- this.updateDuration(initialDuration);
220
- const interpolate$1 = interpolate(keyframes, offset, isEasingList(easing) ? easing.map(getEasingFunction) : noopReturn);
221
- this.tick = (timestamp) => {
222
- var _a;
223
- // TODO: Temporary fix for OptionsResolver typing
224
- delay = delay;
225
- let t = 0;
226
- if (this.pauseTime !== undefined) {
227
- t = this.pauseTime;
228
- }
229
- else {
230
- t = (timestamp - this.startTime) * this.rate;
231
- }
232
- this.t = t;
233
- // Convert to seconds
234
- t /= 1000;
235
- // Rebase on delay
236
- t = Math.max(t - delay, 0);
237
- /**
238
- * If this animation has finished, set the current time
239
- * to the total duration.
240
- */
241
- if (this.playState === "finished" && this.pauseTime === undefined) {
242
- t = this.totalDuration;
243
- }
244
- /**
245
- * Get the current progress (0-1) of the animation. If t is >
246
- * than duration we'll get values like 2.5 (midway through the
247
- * third iteration)
248
- */
249
- const progress = t / this.duration;
250
- // TODO progress += iterationStart
251
- /**
252
- * Get the current iteration (0 indexed). For instance the floor of
253
- * 2.5 is 2.
254
- */
255
- let currentIteration = Math.floor(progress);
256
- /**
257
- * Get the current progress of the iteration by taking the remainder
258
- * so 2.5 is 0.5 through iteration 2
259
- */
260
- let iterationProgress = progress % 1.0;
261
- if (!iterationProgress && progress >= 1) {
262
- iterationProgress = 1;
263
- }
264
- /**
265
- * If iteration progress is 1 we count that as the end
266
- * of the previous iteration.
267
- */
268
- iterationProgress === 1 && currentIteration--;
269
- /**
270
- * Reverse progress if we're not running in "normal" direction
271
- */
272
- const iterationIsOdd = currentIteration % 2;
273
- if (direction === "reverse" ||
274
- (direction === "alternate" && iterationIsOdd) ||
275
- (direction === "alternate-reverse" && !iterationIsOdd)) {
276
- iterationProgress = 1 - iterationProgress;
277
- }
278
- const p = t >= this.totalDuration ? 1 : Math.min(iterationProgress, 1);
279
- const latest = interpolate$1(this.easing(p));
280
- output(latest);
281
- const isAnimationFinished = this.pauseTime === undefined &&
282
- (this.playState === "finished" || t >= this.totalDuration + endDelay);
283
- if (isAnimationFinished) {
284
- this.playState = "finished";
285
- (_a = this.resolve) === null || _a === void 0 ? void 0 : _a.call(this, latest);
286
- }
287
- else if (this.playState !== "idle") {
288
- this.frameRequestId = requestAnimationFrame(this.tick);
289
- }
290
- };
291
- if (autoplay)
292
- this.play();
293
- }
294
- play() {
295
- const now = performance.now();
296
- this.playState = "running";
297
- if (this.pauseTime !== undefined) {
298
- this.startTime = now - this.pauseTime;
299
- }
300
- else if (!this.startTime) {
301
- this.startTime = now;
302
- }
303
- this.cancelTimestamp = this.startTime;
304
- this.pauseTime = undefined;
305
- this.frameRequestId = requestAnimationFrame(this.tick);
306
- }
307
- pause() {
308
- this.playState = "paused";
309
- this.pauseTime = this.t;
310
- }
311
- finish() {
312
- this.playState = "finished";
313
- this.tick(0);
314
- }
315
- stop() {
316
- var _a;
317
- this.playState = "idle";
318
- if (this.frameRequestId !== undefined) {
319
- cancelAnimationFrame(this.frameRequestId);
320
- }
321
- (_a = this.reject) === null || _a === void 0 ? void 0 : _a.call(this, false);
322
- }
323
- cancel() {
324
- this.stop();
325
- this.tick(this.cancelTimestamp);
326
- }
327
- reverse() {
328
- this.rate *= -1;
329
- }
330
- commitStyles() { }
331
- updateDuration(duration) {
332
- this.duration = duration;
333
- this.totalDuration = duration * (this.repeat + 1);
334
- }
335
- get currentTime() {
336
- return this.t;
337
- }
338
- set currentTime(t) {
339
- if (this.pauseTime !== undefined || this.rate === 0) {
340
- this.pauseTime = t;
341
- }
342
- else {
343
- this.startTime = performance.now() - t / this.rate;
344
- }
345
- }
346
- get playbackRate() {
347
- return this.rate;
348
- }
349
- set playbackRate(rate) {
350
- this.rate = rate;
351
- }
352
- }
353
-
354
- var invariant = function () { };
355
- {
356
- invariant = function (check, message) {
357
- if (!check) {
358
- throw new Error(message);
359
- }
360
- };
361
- }
362
-
363
- /**
364
- * The MotionValue tracks the state of a single animatable
365
- * value. Currently, updatedAt and current are unused. The
366
- * long term idea is to use this to minimise the number
367
- * of DOM reads, and to abstract the DOM interactions here.
368
- */
369
- class MotionValue {
370
- setAnimation(animation) {
371
- this.animation = animation;
372
- animation === null || animation === void 0 ? void 0 : animation.finished.then(() => this.clearAnimation()).catch(() => { });
373
- }
374
- clearAnimation() {
375
- this.animation = this.generator = undefined;
376
- }
377
- }
378
-
379
- const data = new WeakMap();
380
- function getAnimationData(element) {
381
- if (!data.has(element)) {
382
- data.set(element, {
383
- transforms: [],
384
- values: new Map(),
385
- });
386
- }
387
- return data.get(element);
388
- }
389
- function getMotionValue(motionValues, name) {
390
- if (!motionValues.has(name)) {
391
- motionValues.set(name, new MotionValue());
392
- }
393
- return motionValues.get(name);
394
- }
395
-
396
- /**
397
- * A list of all transformable axes. We'll use this list to generated a version
398
- * of each axes for each transform.
399
- */
400
- const axes = ["", "X", "Y", "Z"];
401
- /**
402
- * An ordered array of each transformable value. By default, transform values
403
- * will be sorted to this order.
404
- */
405
- const order = ["translate", "scale", "rotate", "skew"];
406
- const transformAlias = {
407
- x: "translateX",
408
- y: "translateY",
409
- z: "translateZ",
410
- };
411
- const rotation = {
412
- syntax: "<angle>",
413
- initialValue: "0deg",
414
- toDefaultUnit: (v) => v + "deg",
415
- };
416
- const baseTransformProperties = {
417
- translate: {
418
- syntax: "<length-percentage>",
419
- initialValue: "0px",
420
- toDefaultUnit: (v) => v + "px",
421
- },
422
- rotate: rotation,
423
- scale: {
424
- syntax: "<number>",
425
- initialValue: 1,
426
- toDefaultUnit: noopReturn,
427
- },
428
- skew: rotation,
429
- };
430
- const transformDefinitions = new Map();
431
- const asTransformCssVar = (name) => `--motion-${name}`;
432
- /**
433
- * Generate a list of every possible transform key
434
- */
435
- const transforms = ["x", "y", "z"];
436
- order.forEach((name) => {
437
- axes.forEach((axis) => {
438
- transforms.push(name + axis);
439
- transformDefinitions.set(asTransformCssVar(name + axis), baseTransformProperties[name]);
440
- });
441
- });
442
- /**
443
- * A function to use with Array.sort to sort transform keys by their default order.
444
- */
445
- const compareTransformOrder = (a, b) => transforms.indexOf(a) - transforms.indexOf(b);
446
- /**
447
- * Provide a quick way to check if a string is the name of a transform
448
- */
449
- const transformLookup = new Set(transforms);
450
- const isTransform = (name) => transformLookup.has(name);
451
- const addTransformToElement = (element, name) => {
452
- // Map x to translateX etc
453
- if (transformAlias[name])
454
- name = transformAlias[name];
455
- const { transforms } = getAnimationData(element);
456
- addUniqueItem(transforms, name);
457
- /**
458
- * TODO: An optimisation here could be to cache the transform in element data
459
- * and only update if this has changed.
460
- */
461
- element.style.transform = buildTransformTemplate(transforms);
462
- };
463
- const buildTransformTemplate = (transforms) => transforms
464
- .sort(compareTransformOrder)
465
- .reduce(transformListToString, "")
466
- .trim();
467
- const transformListToString = (template, name) => `${template} ${name}(var(${asTransformCssVar(name)}))`;
468
-
469
- const isCssVar = (name) => name.startsWith("--");
470
- const registeredProperties = new Set();
471
- function registerCssVariable(name) {
472
- if (registeredProperties.has(name))
473
- return;
474
- registeredProperties.add(name);
475
- try {
476
- const { syntax, initialValue } = transformDefinitions.has(name)
477
- ? transformDefinitions.get(name)
478
- : {};
479
- CSS.registerProperty({
480
- name,
481
- inherits: false,
482
- syntax,
483
- initialValue,
484
- });
485
- }
486
- catch (e) { }
487
- }
488
-
489
- const testAnimation = (keyframes, options) => document.createElement("div").animate(keyframes, options);
490
- const featureTests = {
491
- cssRegisterProperty: () => typeof CSS !== "undefined" &&
492
- Object.hasOwnProperty.call(CSS, "registerProperty"),
493
- waapi: () => Object.hasOwnProperty.call(Element.prototype, "animate"),
494
- partialKeyframes: () => {
495
- try {
496
- testAnimation({ opacity: [1] });
497
- }
498
- catch (e) {
499
- return false;
500
- }
501
- return true;
502
- },
503
- finished: () => Boolean(testAnimation({ opacity: [0, 1] }, { duration: 0.001 }).finished),
504
- linearEasing: () => {
505
- try {
506
- testAnimation({ opacity: 0 }, { easing: "linear(0, 1)" });
507
- }
508
- catch (e) {
509
- return false;
510
- }
511
- return true;
512
- },
513
- };
514
- const results = {};
515
- const supports = {};
516
- for (const key in featureTests) {
517
- supports[key] = () => {
518
- if (results[key] === undefined)
519
- results[key] = featureTests[key]();
520
- return results[key];
521
- };
522
- }
523
-
524
- // Create a linear easing point for every x second
525
- const resolution = 0.015;
526
- const generateLinearEasingPoints = (easing, duration) => {
527
- let points = "";
528
- const numPoints = Math.round(duration / resolution);
529
- for (let i = 0; i < numPoints; i++) {
530
- points += easing(progress(0, numPoints - 1, i)) + ", ";
531
- }
532
- return points.substring(0, points.length - 2);
533
- };
534
- const convertEasing = (easing, duration) => {
535
- if (isFunction(easing)) {
536
- return supports.linearEasing()
537
- ? `linear(${generateLinearEasingPoints(easing, duration)})`
538
- : defaults$1.easing;
539
- }
540
- else {
541
- return isCubicBezier(easing) ? cubicBezierAsString(easing) : easing;
542
- }
543
- };
544
- const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
545
-
546
- function hydrateKeyframes(keyframes, readInitialValue) {
547
- for (let i = 0; i < keyframes.length; i++) {
548
- if (keyframes[i] === null) {
549
- keyframes[i] = i ? keyframes[i - 1] : readInitialValue();
550
- }
551
- }
552
- return keyframes;
553
- }
554
- const keyframesList = (keyframes) => Array.isArray(keyframes) ? keyframes : [keyframes];
555
-
556
- function getStyleName(key) {
557
- if (transformAlias[key])
558
- key = transformAlias[key];
559
- return isTransform(key) ? asTransformCssVar(key) : key;
560
- }
561
-
562
- const style = {
563
- get: (element, name) => {
564
- name = getStyleName(name);
565
- let value = isCssVar(name)
566
- ? element.style.getPropertyValue(name)
567
- : getComputedStyle(element)[name];
568
- if (!value && value !== 0) {
569
- const definition = transformDefinitions.get(name);
570
- if (definition)
571
- value = definition.initialValue;
572
- }
573
- return value;
574
- },
575
- set: (element, name, value) => {
576
- name = getStyleName(name);
577
- if (isCssVar(name)) {
578
- element.style.setProperty(name, value);
579
- }
580
- else {
581
- element.style[name] = value;
582
- }
583
- },
584
- };
585
-
586
- function stopAnimation(animation, needsCommit = true) {
587
- if (!animation || animation.playState === "finished")
588
- return;
589
- // Suppress error thrown by WAAPI
590
- try {
591
- if (animation.stop) {
592
- animation.stop();
593
- }
594
- else {
595
- needsCommit && animation.commitStyles();
596
- animation.cancel();
597
- }
598
- }
599
- catch (e) { }
600
- }
601
-
602
- function getUnitConverter(keyframes, definition) {
603
- var _a;
604
- let toUnit = (definition === null || definition === void 0 ? void 0 : definition.toDefaultUnit) || noopReturn;
605
- const finalKeyframe = keyframes[keyframes.length - 1];
606
- if (isString(finalKeyframe)) {
607
- const unit = ((_a = finalKeyframe.match(/(-?[\d.]+)([a-z%]*)/)) === null || _a === void 0 ? void 0 : _a[2]) || "";
608
- if (unit)
609
- toUnit = (value) => value + unit;
610
- }
611
- return toUnit;
612
- }
613
-
614
- function getDevToolsRecord() {
615
- return window.__MOTION_DEV_TOOLS_RECORD;
616
- }
617
- function animateStyle(element, key, keyframesDefinition, options = {}, AnimationPolyfill) {
618
- const record = getDevToolsRecord();
619
- const isRecording = options.record !== false && record;
620
- let animation;
621
- let { duration = defaults$1.duration, delay = defaults$1.delay, endDelay = defaults$1.endDelay, repeat = defaults$1.repeat, easing = defaults$1.easing, persist = false, direction, offset, allowWebkitAcceleration = false, autoplay = true, } = options;
622
- const data = getAnimationData(element);
623
- const valueIsTransform = isTransform(key);
624
- let canAnimateNatively = supports.waapi();
625
- /**
626
- * If this is an individual transform, we need to map its
627
- * key to a CSS variable and update the element's transform style
628
- */
629
- valueIsTransform && addTransformToElement(element, key);
630
- const name = getStyleName(key);
631
- const motionValue = getMotionValue(data.values, name);
632
- /**
633
- * Get definition of value, this will be used to convert numerical
634
- * keyframes into the default value type.
635
- */
636
- const definition = transformDefinitions.get(name);
637
- /**
638
- * Stop the current animation, if any. Because this will trigger
639
- * commitStyles (DOM writes) and we might later trigger DOM reads,
640
- * this is fired now and we return a factory function to create
641
- * the actual animation that can get called in batch,
642
- */
643
- stopAnimation(motionValue.animation, !(isEasingGenerator(easing) && motionValue.generator) &&
644
- options.record !== false);
645
- /**
646
- * Batchable factory function containing all DOM reads.
647
- */
648
- return () => {
649
- const readInitialValue = () => { var _a, _b; return (_b = (_a = style.get(element, name)) !== null && _a !== void 0 ? _a : definition === null || definition === void 0 ? void 0 : definition.initialValue) !== null && _b !== void 0 ? _b : 0; };
650
- /**
651
- * Replace null values with the previous keyframe value, or read
652
- * it from the DOM if it's the first keyframe.
653
- */
654
- let keyframes = hydrateKeyframes(keyframesList(keyframesDefinition), readInitialValue);
655
- /**
656
- * Detect unit type of keyframes.
657
- */
658
- const toUnit = getUnitConverter(keyframes, definition);
659
- if (isEasingGenerator(easing)) {
660
- const custom = easing.createAnimation(keyframes, key !== "opacity", readInitialValue, name, motionValue);
661
- easing = custom.easing;
662
- keyframes = custom.keyframes || keyframes;
663
- duration = custom.duration || duration;
664
- }
665
- /**
666
- * If this is a CSS variable we need to register it with the browser
667
- * before it can be animated natively. We also set it with setProperty
668
- * rather than directly onto the element.style object.
669
- */
670
- if (isCssVar(name)) {
671
- if (supports.cssRegisterProperty()) {
672
- registerCssVariable(name);
673
- }
674
- else {
675
- canAnimateNatively = false;
676
- }
677
- }
678
- /**
679
- * If we've been passed a custom easing function, and this browser
680
- * does **not** support linear() easing, and the value is a transform
681
- * (and thus a pure number) we can still support the custom easing
682
- * by falling back to the animation polyfill.
683
- */
684
- if (valueIsTransform &&
685
- !supports.linearEasing() &&
686
- (isFunction(easing) || (isEasingList(easing) && easing.some(isFunction)))) {
687
- canAnimateNatively = false;
688
- }
689
- /**
690
- * If we can animate this value with WAAPI, do so.
691
- */
692
- if (canAnimateNatively) {
693
- /**
694
- * Convert numbers to default value types. Currently this only supports
695
- * transforms but it could also support other value types.
696
- */
697
- if (definition) {
698
- keyframes = keyframes.map((value) => isNumber(value) ? definition.toDefaultUnit(value) : value);
699
- }
700
- /**
701
- * If this browser doesn't support partial/implicit keyframes we need to
702
- * explicitly provide one.
703
- */
704
- if (keyframes.length === 1 &&
705
- (!supports.partialKeyframes() || isRecording)) {
706
- keyframes.unshift(readInitialValue());
707
- }
708
- const animationOptions = {
709
- delay: time.ms(delay),
710
- duration: time.ms(duration),
711
- endDelay: time.ms(endDelay),
712
- easing: !isEasingList(easing)
713
- ? convertEasing(easing, duration)
714
- : undefined,
715
- direction,
716
- iterations: repeat + 1,
717
- fill: "both",
718
- };
719
- animation = element.animate({
720
- [name]: keyframes,
721
- offset,
722
- easing: isEasingList(easing)
723
- ? easing.map((thisEasing) => convertEasing(thisEasing, duration))
724
- : undefined,
725
- }, animationOptions);
726
- /**
727
- * Polyfill finished Promise in browsers that don't support it
728
- */
729
- if (!animation.finished) {
730
- animation.finished = new Promise((resolve, reject) => {
731
- animation.onfinish = resolve;
732
- animation.oncancel = reject;
733
- });
734
- }
735
- const target = keyframes[keyframes.length - 1];
736
- animation.finished
737
- .then(() => {
738
- if (persist)
739
- return;
740
- // Apply styles to target
741
- style.set(element, name, target);
742
- // Ensure fill modes don't persist
743
- animation.cancel();
744
- })
745
- .catch(noop);
746
- /**
747
- * This forces Webkit to run animations on the main thread by exploiting
748
- * this condition:
749
- * https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp?rev=281238#L1099
750
- *
751
- * This fixes Webkit's timing bugs, like accelerated animations falling
752
- * out of sync with main thread animations and massive delays in starting
753
- * accelerated animations in WKWebView.
754
- */
755
- if (!allowWebkitAcceleration)
756
- animation.playbackRate = 1.000001;
757
- /**
758
- * If we can't animate the value natively then we can fallback to the numbers-only
759
- * polyfill for transforms.
760
- */
761
- }
762
- else if (AnimationPolyfill && valueIsTransform) {
763
- /**
764
- * If any keyframe is a string (because we measured it from the DOM), we need to convert
765
- * it into a number before passing to the Animation polyfill.
766
- */
767
- keyframes = keyframes.map((value) => typeof value === "string" ? parseFloat(value) : value);
768
- /**
769
- * If we only have a single keyframe, we need to create an initial keyframe by reading
770
- * the current value from the DOM.
771
- */
772
- if (keyframes.length === 1) {
773
- keyframes.unshift(parseFloat(readInitialValue()));
774
- }
775
- animation = new AnimationPolyfill((latest) => {
776
- style.set(element, name, toUnit ? toUnit(latest) : latest);
777
- }, keyframes, Object.assign(Object.assign({}, options), { duration,
778
- easing }));
779
- }
780
- else {
781
- const target = keyframes[keyframes.length - 1];
782
- style.set(element, name, definition && isNumber(target)
783
- ? definition.toDefaultUnit(target)
784
- : target);
785
- }
786
- if (isRecording) {
787
- record(element, key, keyframes, {
788
- duration,
789
- delay: delay,
790
- easing,
791
- repeat,
792
- offset,
793
- }, "motion-one");
794
- }
795
- motionValue.setAnimation(animation);
796
- if (animation && !autoplay)
797
- animation.pause();
798
- return animation;
799
- };
800
- }
801
-
802
- const getOptions = (options, key) =>
803
- /**
804
- * TODO: Make test for this
805
- * Always return a new object otherwise delay is overwritten by results of stagger
806
- * and this results in no stagger
807
- */
808
- options[key] ? Object.assign(Object.assign({}, options), options[key]) : Object.assign({}, options);
809
-
810
- function resolveElements(elements, selectorCache) {
811
- var _a;
812
- if (typeof elements === "string") {
813
- if (selectorCache) {
814
- (_a = selectorCache[elements]) !== null && _a !== void 0 ? _a : (selectorCache[elements] = document.querySelectorAll(elements));
815
- elements = selectorCache[elements];
816
- }
817
- else {
818
- elements = document.querySelectorAll(elements);
819
- }
820
- }
821
- else if (elements instanceof Element) {
822
- elements = [elements];
823
- }
824
- /**
825
- * Return an empty array
826
- */
827
- return Array.from(elements || []);
828
- }
829
-
830
- const createAnimation = (factory) => factory();
831
- const withControls = (animationFactory, options, duration = defaults$1.duration) => {
832
- return new Proxy({
833
- animations: animationFactory.map(createAnimation).filter(Boolean),
834
- duration,
835
- options,
836
- }, controls);
837
- };
838
- /**
839
- * TODO:
840
- * Currently this returns the first animation, ideally it would return
841
- * the first active animation.
842
- */
843
- const getActiveAnimation = (state) => state.animations[0];
844
- const controls = {
845
- get: (target, key) => {
846
- const activeAnimation = getActiveAnimation(target);
847
- switch (key) {
848
- case "duration":
849
- return target.duration;
850
- case "currentTime":
851
- return time.s((activeAnimation === null || activeAnimation === void 0 ? void 0 : activeAnimation[key]) || 0);
852
- case "playbackRate":
853
- case "playState":
854
- return activeAnimation === null || activeAnimation === void 0 ? void 0 : activeAnimation[key];
855
- case "finished":
856
- if (!target.finished) {
857
- target.finished = Promise.all(target.animations.map(selectFinished)).catch(noop);
858
- }
859
- return target.finished;
860
- case "stop":
861
- return () => {
862
- target.animations.forEach((animation) => stopAnimation(animation));
863
- };
864
- case "forEachNative":
865
- /**
866
- * This is for internal use only, fire a callback for each
867
- * underlying animation.
868
- */
869
- return (callback) => {
870
- target.animations.forEach((animation) => callback(animation, target));
871
- };
872
- default:
873
- return typeof (activeAnimation === null || activeAnimation === void 0 ? void 0 : activeAnimation[key]) === "undefined"
874
- ? undefined
875
- : () => target.animations.forEach((animation) => animation[key]());
876
- }
877
- },
878
- set: (target, key, value) => {
879
- switch (key) {
880
- case "currentTime":
881
- value = time.ms(value);
882
- // Fall-through
883
- case "playbackRate":
884
- for (let i = 0; i < target.animations.length; i++) {
885
- target.animations[i][key] = value;
886
- }
887
- return true;
888
- }
889
- return false;
890
- },
891
- };
892
- const selectFinished = (animation) => animation.finished;
893
-
894
- function stagger(duration = 0.1, { start = 0, from = 0, easing } = {}) {
895
- return (i, total) => {
896
- const fromIndex = isNumber(from) ? from : getFromIndex(from, total);
897
- const distance = Math.abs(fromIndex - i);
898
- let delay = duration * distance;
899
- if (easing) {
900
- const maxDelay = total * duration;
901
- const easingFunction = getEasingFunction(easing);
902
- delay = easingFunction(delay / maxDelay) * maxDelay;
903
- }
904
- return start + delay;
905
- };
906
- }
907
- function getFromIndex(from, total) {
908
- if (from === "first") {
909
- return 0;
910
- }
911
- else {
912
- const lastIndex = total - 1;
913
- return from === "last" ? lastIndex : lastIndex / 2;
914
- }
915
- }
916
- function resolveOption(option, i, total) {
917
- return isFunction(option) ? option(i, total) : option;
918
- }
919
-
920
- function createAnimate(AnimatePolyfill) {
921
- return function animate(elements, keyframes, options = {}) {
922
- elements = resolveElements(elements);
923
- const numElements = elements.length;
924
- invariant(Boolean(numElements), "No valid element provided.");
925
- invariant(Boolean(keyframes), "No keyframes defined.");
926
- /**
927
- * Create and start new animations
928
- */
929
- const animationFactories = [];
930
- for (let i = 0; i < numElements; i++) {
931
- const element = elements[i];
932
- for (const key in keyframes) {
933
- const valueOptions = getOptions(options, key);
934
- valueOptions.delay = resolveOption(valueOptions.delay, i, numElements);
935
- const animation = animateStyle(element, key, keyframes[key], valueOptions, AnimatePolyfill);
936
- animationFactories.push(animation);
937
- }
938
- }
939
- return withControls(animationFactories, options,
940
- /**
941
- * TODO:
942
- * If easing is set to spring or glide, duration will be dynamically
943
- * generated. Ideally we would dynamically generate this from
944
- * animation.effect.getComputedTiming().duration but this isn't
945
- * supported in iOS13 or our number polyfill. Perhaps it's possible
946
- * to Proxy animations returned from animateStyle that has duration
947
- * as a getter.
948
- */
949
- options.duration);
950
- };
951
- }
952
-
953
- const animate$1 = createAnimate(Animation);
954
-
955
- /******************************************************************************
956
- Copyright (c) Microsoft Corporation.
957
-
958
- Permission to use, copy, modify, and/or distribute this software for any
959
- purpose with or without fee is hereby granted.
960
-
961
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
962
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
963
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
964
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
965
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
966
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
967
- PERFORMANCE OF THIS SOFTWARE.
968
- ***************************************************************************** */
969
- /* global Reflect, Promise, SuppressedError, Symbol */
970
-
971
-
972
- function __rest(s, e) {
973
- var t = {};
974
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
975
- t[p] = s[p];
976
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
977
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
978
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
979
- t[p[i]] = s[p[i]];
980
- }
981
- return t;
982
- }
983
-
984
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
985
- var e = new Error(message);
986
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
987
- };
988
-
989
- function calcNextTime(current, next, prev, labels) {
990
- var _a;
991
- if (isNumber(next)) {
992
- return next;
993
- }
994
- else if (next.startsWith("-") || next.startsWith("+")) {
995
- return Math.max(0, current + parseFloat(next));
996
- }
997
- else if (next === "<") {
998
- return prev;
999
- }
1000
- else {
1001
- return (_a = labels.get(next)) !== null && _a !== void 0 ? _a : current;
1002
- }
1003
- }
1004
-
1005
- function eraseKeyframes(sequence, startTime, endTime) {
1006
- for (let i = 0; i < sequence.length; i++) {
1007
- const keyframe = sequence[i];
1008
- if (keyframe.at > startTime && keyframe.at < endTime) {
1009
- removeItem(sequence, keyframe);
1010
- // If we remove this item we have to push the pointer back one
1011
- i--;
1012
- }
1013
- }
1014
- }
1015
- function addKeyframes(sequence, keyframes, easing, offset, startTime, endTime) {
1016
- /**
1017
- * Erase every existing value between currentTime and targetTime,
1018
- * this will essentially splice this timeline into any currently
1019
- * defined ones.
1020
- */
1021
- eraseKeyframes(sequence, startTime, endTime);
1022
- for (let i = 0; i < keyframes.length; i++) {
1023
- sequence.push({
1024
- value: keyframes[i],
1025
- at: mix(startTime, endTime, offset[i]),
1026
- easing: getEasingForSegment(easing, i),
1027
- });
1028
- }
1029
- }
1030
-
1031
- function compareByTime(a, b) {
1032
- if (a.at === b.at) {
1033
- return a.value === null ? 1 : -1;
1034
- }
1035
- else {
1036
- return a.at - b.at;
1037
- }
1038
- }
1039
-
1040
- function timeline(definition, options = {}) {
1041
- var _a;
1042
- const animationDefinitions = createAnimationsFromTimeline(definition, options);
1043
- /**
1044
- * Create and start animations
1045
- */
1046
- const animationFactories = animationDefinitions
1047
- .map((definition) => animateStyle(...definition, Animation))
1048
- .filter(Boolean);
1049
- return withControls(animationFactories, options,
1050
- // Get the duration from the first animation definition
1051
- (_a = animationDefinitions[0]) === null || _a === void 0 ? void 0 : _a[3].duration);
1052
- }
1053
- function createAnimationsFromTimeline(definition, _a = {}) {
1054
- var { defaultOptions = {} } = _a, timelineOptions = __rest(_a, ["defaultOptions"]);
1055
- const animationDefinitions = [];
1056
- const elementSequences = new Map();
1057
- const elementCache = {};
1058
- const timeLabels = new Map();
1059
- let prevTime = 0;
1060
- let currentTime = 0;
1061
- let totalDuration = 0;
1062
- /**
1063
- * Build the timeline by mapping over the definition array and converting
1064
- * the definitions into keyframes and offsets with absolute time values.
1065
- * These will later get converted into relative offsets in a second pass.
1066
- */
1067
- for (let i = 0; i < definition.length; i++) {
1068
- const segment = definition[i];
1069
- /**
1070
- * If this is a timeline label, mark it and skip the rest of this iteration.
1071
- */
1072
- if (isString(segment)) {
1073
- timeLabels.set(segment, currentTime);
1074
- continue;
1075
- }
1076
- else if (!Array.isArray(segment)) {
1077
- timeLabels.set(segment.name, calcNextTime(currentTime, segment.at, prevTime, timeLabels));
1078
- continue;
1079
- }
1080
- const [elementDefinition, keyframes, options = {}] = segment;
1081
- /**
1082
- * If a relative or absolute time value has been specified we need to resolve
1083
- * it in relation to the currentTime.
1084
- */
1085
- if (options.at !== undefined) {
1086
- currentTime = calcNextTime(currentTime, options.at, prevTime, timeLabels);
1087
- }
1088
- /**
1089
- * Keep track of the maximum duration in this definition. This will be
1090
- * applied to currentTime once the definition has been parsed.
1091
- */
1092
- let maxDuration = 0;
1093
- /**
1094
- * Find all the elements specified in the definition and parse value
1095
- * keyframes from their timeline definitions.
1096
- */
1097
- const elements = resolveElements(elementDefinition, elementCache);
1098
- const numElements = elements.length;
1099
- for (let elementIndex = 0; elementIndex < numElements; elementIndex++) {
1100
- const element = elements[elementIndex];
1101
- const elementSequence = getElementSequence(element, elementSequences);
1102
- for (const key in keyframes) {
1103
- const valueSequence = getValueSequence(key, elementSequence);
1104
- let valueKeyframes = keyframesList(keyframes[key]);
1105
- const valueOptions = getOptions(options, key);
1106
- let { duration = defaultOptions.duration || defaults$1.duration, easing = defaultOptions.easing || defaults$1.easing, } = valueOptions;
1107
- if (isEasingGenerator(easing)) {
1108
- invariant(key === "opacity" || valueKeyframes.length > 1, "spring must be provided 2 keyframes within timeline()");
1109
- const custom = easing.createAnimation(valueKeyframes, key !== "opacity", () => 0, key);
1110
- easing = custom.easing;
1111
- valueKeyframes = custom.keyframes || valueKeyframes;
1112
- duration = custom.duration || duration;
1113
- }
1114
- const delay = resolveOption(options.delay, elementIndex, numElements) || 0;
1115
- const startTime = currentTime + delay;
1116
- const targetTime = startTime + duration;
1117
- /**
1118
- *
1119
- */
1120
- let { offset = defaultOffset$1(valueKeyframes.length) } = valueOptions;
1121
- /**
1122
- * If there's only one offset of 0, fill in a second with length 1
1123
- *
1124
- * TODO: Ensure there's a test that covers this removal
1125
- */
1126
- if (offset.length === 1 && offset[0] === 0) {
1127
- offset[1] = 1;
1128
- }
1129
- /**
1130
- * Fill out if offset if fewer offsets than keyframes
1131
- */
1132
- const remainder = offset.length - valueKeyframes.length;
1133
- remainder > 0 && fillOffset(offset, remainder);
1134
- /**
1135
- * If only one value has been set, ie [1], push a null to the start of
1136
- * the keyframe array. This will let us mark a keyframe at this point
1137
- * that will later be hydrated with the previous value.
1138
- */
1139
- valueKeyframes.length === 1 && valueKeyframes.unshift(null);
1140
- /**
1141
- * Add keyframes, mapping offsets to absolute time.
1142
- */
1143
- addKeyframes(valueSequence, valueKeyframes, easing, offset, startTime, targetTime);
1144
- maxDuration = Math.max(delay + duration, maxDuration);
1145
- totalDuration = Math.max(targetTime, totalDuration);
1146
- }
1147
- }
1148
- prevTime = currentTime;
1149
- currentTime += maxDuration;
1150
- }
1151
- /**
1152
- * For every element and value combination create a new animation.
1153
- */
1154
- elementSequences.forEach((valueSequences, element) => {
1155
- for (const key in valueSequences) {
1156
- const valueSequence = valueSequences[key];
1157
- /**
1158
- * Arrange all the keyframes in ascending time order.
1159
- */
1160
- valueSequence.sort(compareByTime);
1161
- const keyframes = [];
1162
- const valueOffset = [];
1163
- const valueEasing = [];
1164
- /**
1165
- * For each keyframe, translate absolute times into
1166
- * relative offsets based on the total duration of the timeline.
1167
- */
1168
- for (let i = 0; i < valueSequence.length; i++) {
1169
- const { at, value, easing } = valueSequence[i];
1170
- keyframes.push(value);
1171
- valueOffset.push(progress(0, totalDuration, at));
1172
- valueEasing.push(easing || defaults$1.easing);
1173
- }
1174
- /**
1175
- * If the first keyframe doesn't land on offset: 0
1176
- * provide one by duplicating the initial keyframe. This ensures
1177
- * it snaps to the first keyframe when the animation starts.
1178
- */
1179
- if (valueOffset[0] !== 0) {
1180
- valueOffset.unshift(0);
1181
- keyframes.unshift(keyframes[0]);
1182
- valueEasing.unshift("linear");
1183
- }
1184
- /**
1185
- * If the last keyframe doesn't land on offset: 1
1186
- * provide one with a null wildcard value. This will ensure it
1187
- * stays static until the end of the animation.
1188
- */
1189
- if (valueOffset[valueOffset.length - 1] !== 1) {
1190
- valueOffset.push(1);
1191
- keyframes.push(null);
1192
- }
1193
- animationDefinitions.push([
1194
- element,
1195
- key,
1196
- keyframes,
1197
- Object.assign(Object.assign(Object.assign({}, defaultOptions), { duration: totalDuration, easing: valueEasing, offset: valueOffset }), timelineOptions),
1198
- ]);
1199
- }
1200
- });
1201
- return animationDefinitions;
1202
- }
1203
- function getElementSequence(element, sequences) {
1204
- !sequences.has(element) && sequences.set(element, {});
1205
- return sequences.get(element);
1206
- }
1207
- function getValueSequence(name, sequences) {
1208
- if (!sequences[name])
1209
- sequences[name] = [];
1210
- return sequences[name];
1211
- }
1212
-
1213
- const sampleT = 5; // ms
1214
- function calcGeneratorVelocity(resolveValue, t, current) {
1215
- const prevT = Math.max(t - sampleT, 0);
1216
- return velocityPerSecond(current - resolveValue(prevT), t - prevT);
1217
- }
1218
-
1219
- const defaults = {
1220
- stiffness: 100.0,
1221
- damping: 10.0,
1222
- mass: 1.0,
1223
- };
1224
-
1225
- const calcDampingRatio = (stiffness = defaults.stiffness, damping = defaults.damping, mass = defaults.mass) => damping / (2 * Math.sqrt(stiffness * mass));
1226
-
1227
- function hasReachedTarget(origin, target, current) {
1228
- return ((origin < target && current >= target) ||
1229
- (origin > target && current <= target));
1230
- }
1231
-
1232
- const spring$1 = ({ stiffness = defaults.stiffness, damping = defaults.damping, mass = defaults.mass, from = 0, to = 1, velocity = 0.0, restSpeed, restDistance, } = {}) => {
1233
- velocity = velocity ? time.s(velocity) : 0.0;
1234
- const state = {
1235
- done: false,
1236
- hasReachedTarget: false,
1237
- current: from,
1238
- target: to,
1239
- };
1240
- const initialDelta = to - from;
1241
- const undampedAngularFreq = Math.sqrt(stiffness / mass) / 1000;
1242
- const dampingRatio = calcDampingRatio(stiffness, damping, mass);
1243
- const isGranularScale = Math.abs(initialDelta) < 5;
1244
- restSpeed || (restSpeed = isGranularScale ? 0.01 : 2);
1245
- restDistance || (restDistance = isGranularScale ? 0.005 : 0.5);
1246
- let resolveSpring;
1247
- if (dampingRatio < 1) {
1248
- const angularFreq = undampedAngularFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
1249
- // Underdamped spring (bouncy)
1250
- resolveSpring = (t) => to -
1251
- Math.exp(-dampingRatio * undampedAngularFreq * t) *
1252
- (((-velocity + dampingRatio * undampedAngularFreq * initialDelta) /
1253
- angularFreq) *
1254
- Math.sin(angularFreq * t) +
1255
- initialDelta * Math.cos(angularFreq * t));
1256
- }
1257
- else {
1258
- // Critically damped spring
1259
- resolveSpring = (t) => {
1260
- return (to -
1261
- Math.exp(-undampedAngularFreq * t) *
1262
- (initialDelta + (-velocity + undampedAngularFreq * initialDelta) * t));
1263
- };
1264
- }
1265
- return (t) => {
1266
- state.current = resolveSpring(t);
1267
- const currentVelocity = t === 0
1268
- ? velocity
1269
- : calcGeneratorVelocity(resolveSpring, t, state.current);
1270
- const isBelowVelocityThreshold = Math.abs(currentVelocity) <= restSpeed;
1271
- const isBelowDisplacementThreshold = Math.abs(to - state.current) <= restDistance;
1272
- state.done = isBelowVelocityThreshold && isBelowDisplacementThreshold;
1273
- state.hasReachedTarget = hasReachedTarget(from, to, state.current);
1274
- return state;
1275
- };
1276
- };
1277
-
1278
- const glide$1 = ({ from = 0, velocity = 0.0, power = 0.8, decay = 0.325, bounceDamping, bounceStiffness, changeTarget, min, max, restDistance = 0.5, restSpeed, }) => {
1279
- decay = time.ms(decay);
1280
- const state = {
1281
- hasReachedTarget: false,
1282
- done: false,
1283
- current: from,
1284
- target: from,
1285
- };
1286
- const isOutOfBounds = (v) => (min !== undefined && v < min) || (max !== undefined && v > max);
1287
- const nearestBoundary = (v) => {
1288
- if (min === undefined)
1289
- return max;
1290
- if (max === undefined)
1291
- return min;
1292
- return Math.abs(min - v) < Math.abs(max - v) ? min : max;
1293
- };
1294
- let amplitude = power * velocity;
1295
- const ideal = from + amplitude;
1296
- const target = changeTarget === undefined ? ideal : changeTarget(ideal);
1297
- state.target = target;
1298
- /**
1299
- * If the target has changed we need to re-calculate the amplitude, otherwise
1300
- * the animation will start from the wrong position.
1301
- */
1302
- if (target !== ideal)
1303
- amplitude = target - from;
1304
- const calcDelta = (t) => -amplitude * Math.exp(-t / decay);
1305
- const calcLatest = (t) => target + calcDelta(t);
1306
- const applyFriction = (t) => {
1307
- const delta = calcDelta(t);
1308
- const latest = calcLatest(t);
1309
- state.done = Math.abs(delta) <= restDistance;
1310
- state.current = state.done ? target : latest;
1311
- };
1312
- /**
1313
- * Ideally this would resolve for t in a stateless way, we could
1314
- * do that by always precalculating the animation but as we know
1315
- * this will be done anyway we can assume that spring will
1316
- * be discovered during that.
1317
- */
1318
- let timeReachedBoundary;
1319
- let spring$1$1;
1320
- const checkCatchBoundary = (t) => {
1321
- if (!isOutOfBounds(state.current))
1322
- return;
1323
- timeReachedBoundary = t;
1324
- spring$1$1 = spring$1({
1325
- from: state.current,
1326
- to: nearestBoundary(state.current),
1327
- velocity: calcGeneratorVelocity(calcLatest, t, state.current),
1328
- damping: bounceDamping,
1329
- stiffness: bounceStiffness,
1330
- restDistance,
1331
- restSpeed,
1332
- });
1333
- };
1334
- checkCatchBoundary(0);
1335
- return (t) => {
1336
- /**
1337
- * We need to resolve the friction to figure out if we need a
1338
- * spring but we don't want to do this twice per frame. So here
1339
- * we flag if we updated for this frame and later if we did
1340
- * we can skip doing it again.
1341
- */
1342
- let hasUpdatedFrame = false;
1343
- if (!spring$1$1 && timeReachedBoundary === undefined) {
1344
- hasUpdatedFrame = true;
1345
- applyFriction(t);
1346
- checkCatchBoundary(t);
1347
- }
1348
- /**
1349
- * If we have a spring and the provided t is beyond the moment the friction
1350
- * animation crossed the min/max boundary, use the spring.
1351
- */
1352
- if (timeReachedBoundary !== undefined && t > timeReachedBoundary) {
1353
- state.hasReachedTarget = true;
1354
- return spring$1$1(t - timeReachedBoundary);
1355
- }
1356
- else {
1357
- state.hasReachedTarget = false;
1358
- !hasUpdatedFrame && applyFriction(t);
1359
- return state;
1360
- }
1361
- };
1362
- };
1363
-
1364
- const timeStep = 10;
1365
- const maxDuration = 10000;
1366
- function pregenerateKeyframes(generator, toUnit = noopReturn) {
1367
- let overshootDuration = undefined;
1368
- let timestamp = timeStep;
1369
- let state = generator(0);
1370
- const keyframes = [toUnit(state.current)];
1371
- while (!state.done && timestamp < maxDuration) {
1372
- state = generator(timestamp);
1373
- keyframes.push(toUnit(state.done ? state.target : state.current));
1374
- if (overshootDuration === undefined && state.hasReachedTarget) {
1375
- overshootDuration = timestamp;
1376
- }
1377
- timestamp += timeStep;
1378
- }
1379
- const duration = timestamp - timeStep;
1380
- /**
1381
- * If generating an animation that didn't actually move,
1382
- * generate a second keyframe so we have an origin and target.
1383
- */
1384
- if (keyframes.length === 1)
1385
- keyframes.push(state.current);
1386
- return {
1387
- keyframes,
1388
- duration: duration / 1000,
1389
- overshootDuration: (overshootDuration !== null && overshootDuration !== void 0 ? overshootDuration : duration) / 1000,
1390
- };
1391
- }
1392
-
1393
- function canGenerate(value) {
1394
- return isNumber(value) && !isNaN(value);
1395
- }
1396
- function getAsNumber(value) {
1397
- return isString(value) ? parseFloat(value) : value;
1398
- }
1399
- function createGeneratorEasing(createGenerator) {
1400
- const keyframesCache = new WeakMap();
1401
- return (options = {}) => {
1402
- const generatorCache = new Map();
1403
- const getGenerator = (from = 0, to = 100, velocity = 0, isScale = false) => {
1404
- const key = `${from}-${to}-${velocity}-${isScale}`;
1405
- if (!generatorCache.has(key)) {
1406
- generatorCache.set(key, createGenerator(Object.assign({ from,
1407
- to,
1408
- velocity }, options)));
1409
- }
1410
- return generatorCache.get(key);
1411
- };
1412
- const getKeyframes = (generator, toUnit) => {
1413
- if (!keyframesCache.has(generator)) {
1414
- keyframesCache.set(generator, pregenerateKeyframes(generator, toUnit));
1415
- }
1416
- return keyframesCache.get(generator);
1417
- };
1418
- return {
1419
- createAnimation: (keyframes, shouldGenerate = true, getOrigin, name, motionValue) => {
1420
- let settings;
1421
- let origin;
1422
- let target;
1423
- let velocity = 0;
1424
- let toUnit = noopReturn;
1425
- const numKeyframes = keyframes.length;
1426
- /**
1427
- * If we should generate an animation for this value, run some preperation
1428
- * like resolving target/origin, finding a unit (if any) and determine if
1429
- * it is actually possible to generate.
1430
- */
1431
- if (shouldGenerate) {
1432
- toUnit = getUnitConverter(keyframes, name ? transformDefinitions.get(getStyleName(name)) : undefined);
1433
- const targetDefinition = keyframes[numKeyframes - 1];
1434
- target = getAsNumber(targetDefinition);
1435
- if (numKeyframes > 1 && keyframes[0] !== null) {
1436
- /**
1437
- * If we have multiple keyframes, take the initial keyframe as the origin.
1438
- */
1439
- origin = getAsNumber(keyframes[0]);
1440
- }
1441
- else {
1442
- const prevGenerator = motionValue === null || motionValue === void 0 ? void 0 : motionValue.generator;
1443
- /**
1444
- * If we have an existing generator for this value we can use it to resolve
1445
- * the animation's current value and velocity.
1446
- */
1447
- if (prevGenerator) {
1448
- /**
1449
- * If we have a generator for this value we can use it to resolve
1450
- * the animations's current value and velocity.
1451
- */
1452
- const { animation, generatorStartTime } = motionValue;
1453
- const startTime = (animation === null || animation === void 0 ? void 0 : animation.startTime) || generatorStartTime || 0;
1454
- const currentTime = (animation === null || animation === void 0 ? void 0 : animation.currentTime) || performance.now() - startTime;
1455
- const prevGeneratorCurrent = prevGenerator(currentTime).current;
1456
- origin = prevGeneratorCurrent;
1457
- velocity = calcGeneratorVelocity((t) => prevGenerator(t).current, currentTime, prevGeneratorCurrent);
1458
- }
1459
- else if (getOrigin) {
1460
- /**
1461
- * As a last resort, read the origin from the DOM.
1462
- */
1463
- origin = getAsNumber(getOrigin());
1464
- }
1465
- }
1466
- }
1467
- /**
1468
- * If we've determined it is possible to generate an animation, do so.
1469
- */
1470
- if (canGenerate(origin) && canGenerate(target)) {
1471
- const generator = getGenerator(origin, target, velocity, name === null || name === void 0 ? void 0 : name.includes("scale"));
1472
- settings = Object.assign(Object.assign({}, getKeyframes(generator, toUnit)), { easing: "linear" });
1473
- // TODO Add test for this
1474
- if (motionValue) {
1475
- motionValue.generator = generator;
1476
- motionValue.generatorStartTime = performance.now();
1477
- }
1478
- }
1479
- /**
1480
- * If by now we haven't generated a set of keyframes, create a generic generator
1481
- * based on the provided props that animates from 0-100 to fetch a rough
1482
- * "overshootDuration" - the moment when the generator first hits the animation target.
1483
- * Then return animation settings that will run a normal animation for that duration.
1484
- */
1485
- if (!settings) {
1486
- const keyframesMetadata = getKeyframes(getGenerator(0, 100));
1487
- settings = {
1488
- easing: "ease",
1489
- duration: keyframesMetadata.overshootDuration,
1490
- };
1491
- }
1492
- return settings;
1493
- },
1494
- };
1495
- };
1496
- }
1497
-
1498
- const spring = createGeneratorEasing(spring$1);
1499
-
1500
- const glide = createGeneratorEasing(glide$1);
1501
-
1502
- const thresholds = {
1503
- any: 0,
1504
- all: 1,
1505
- };
1506
- function inView$1(elementOrSelector, onStart, { root, margin: rootMargin, amount = "any" } = {}) {
1507
- /**
1508
- * If this browser doesn't support IntersectionObserver, return a dummy stop function.
1509
- * Default triggering of onStart is tricky - it could be used for starting/stopping
1510
- * videos, lazy loading content etc. We could provide an option to enable a fallback, or
1511
- * provide a fallback callback option.
1512
- */
1513
- if (typeof IntersectionObserver === "undefined") {
1514
- return () => { };
1515
- }
1516
- const elements = resolveElements(elementOrSelector);
1517
- const activeIntersections = new WeakMap();
1518
- const onIntersectionChange = (entries) => {
1519
- entries.forEach((entry) => {
1520
- const onEnd = activeIntersections.get(entry.target);
1521
- /**
1522
- * If there's no change to the intersection, we don't need to
1523
- * do anything here.
1524
- */
1525
- if (entry.isIntersecting === Boolean(onEnd))
1526
- return;
1527
- if (entry.isIntersecting) {
1528
- const newOnEnd = onStart(entry);
1529
- if (isFunction(newOnEnd)) {
1530
- activeIntersections.set(entry.target, newOnEnd);
1531
- }
1532
- else {
1533
- observer.unobserve(entry.target);
1534
- }
1535
- }
1536
- else if (onEnd) {
1537
- onEnd(entry);
1538
- activeIntersections.delete(entry.target);
1539
- }
1540
- });
1541
- };
1542
- const observer = new IntersectionObserver(onIntersectionChange, {
1543
- root,
1544
- rootMargin,
1545
- threshold: typeof amount === "number" ? amount : thresholds[amount],
1546
- });
1547
- elements.forEach((element) => observer.observe(element));
1548
- return () => observer.disconnect();
1549
- }
1550
-
1551
- const resizeHandlers = new WeakMap();
1552
- let observer;
1553
- function getElementSize(target, borderBoxSize) {
1554
- if (borderBoxSize) {
1555
- const { inlineSize, blockSize } = borderBoxSize[0];
1556
- return { width: inlineSize, height: blockSize };
1557
- }
1558
- else if (target instanceof SVGElement && "getBBox" in target) {
1559
- return target.getBBox();
1560
- }
1561
- else {
1562
- return {
1563
- width: target.offsetWidth,
1564
- height: target.offsetHeight,
1565
- };
1566
- }
1567
- }
1568
- function notifyTarget({ target, contentRect, borderBoxSize, }) {
1569
- var _a;
1570
- (_a = resizeHandlers.get(target)) === null || _a === void 0 ? void 0 : _a.forEach((handler) => {
1571
- handler({
1572
- target,
1573
- contentSize: contentRect,
1574
- get size() {
1575
- return getElementSize(target, borderBoxSize);
1576
- },
1577
- });
1578
- });
1579
- }
1580
- function notifyAll(entries) {
1581
- entries.forEach(notifyTarget);
1582
- }
1583
- function createResizeObserver() {
1584
- if (typeof ResizeObserver === "undefined")
1585
- return;
1586
- observer = new ResizeObserver(notifyAll);
1587
- }
1588
- function resizeElement(target, handler) {
1589
- if (!observer)
1590
- createResizeObserver();
1591
- const elements = resolveElements(target);
1592
- elements.forEach((element) => {
1593
- let elementHandlers = resizeHandlers.get(element);
1594
- if (!elementHandlers) {
1595
- elementHandlers = new Set();
1596
- resizeHandlers.set(element, elementHandlers);
1597
- }
1598
- elementHandlers.add(handler);
1599
- observer === null || observer === void 0 ? void 0 : observer.observe(element);
1600
- });
1601
- return () => {
1602
- elements.forEach((element) => {
1603
- const elementHandlers = resizeHandlers.get(element);
1604
- elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.delete(handler);
1605
- if (!(elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.size)) {
1606
- observer === null || observer === void 0 ? void 0 : observer.unobserve(element);
1607
- }
1608
- });
1609
- };
1610
- }
1611
-
1612
- const windowCallbacks = new Set();
1613
- let windowResizeHandler;
1614
- function createWindowResizeHandler() {
1615
- windowResizeHandler = () => {
1616
- const size = {
1617
- width: window.innerWidth,
1618
- height: window.innerHeight,
1619
- };
1620
- const info = {
1621
- target: window,
1622
- size,
1623
- contentSize: size,
1624
- };
1625
- windowCallbacks.forEach((callback) => callback(info));
1626
- };
1627
- window.addEventListener("resize", windowResizeHandler);
1628
- }
1629
- function resizeWindow(callback) {
1630
- windowCallbacks.add(callback);
1631
- if (!windowResizeHandler)
1632
- createWindowResizeHandler();
1633
- return () => {
1634
- windowCallbacks.delete(callback);
1635
- if (!windowCallbacks.size && windowResizeHandler) {
1636
- windowResizeHandler = undefined;
1637
- }
1638
- };
1639
- }
1640
-
1641
- function resize(a, b) {
1642
- return isFunction(a) ? resizeWindow(a) : resizeElement(a, b);
1643
- }
1644
-
1645
- /**
1646
- * A time in milliseconds, beyond which we consider the scroll velocity to be 0.
1647
- */
1648
- const maxElapsed = 50;
1649
- const createAxisInfo = () => ({
1650
- current: 0,
1651
- offset: [],
1652
- progress: 0,
1653
- scrollLength: 0,
1654
- targetOffset: 0,
1655
- targetLength: 0,
1656
- containerLength: 0,
1657
- velocity: 0,
1658
- });
1659
- const createScrollInfo = () => ({
1660
- time: 0,
1661
- x: createAxisInfo(),
1662
- y: createAxisInfo(),
1663
- });
1664
- const keys = {
1665
- x: {
1666
- length: "Width",
1667
- position: "Left",
1668
- },
1669
- y: {
1670
- length: "Height",
1671
- position: "Top",
1672
- },
1673
- };
1674
- function updateAxisInfo(element, axisName, info, time) {
1675
- const axis = info[axisName];
1676
- const { length, position } = keys[axisName];
1677
- const prev = axis.current;
1678
- const prevTime = info.time;
1679
- axis.current = element["scroll" + position];
1680
- axis.scrollLength = element["scroll" + length] - element["client" + length];
1681
- axis.offset.length = 0;
1682
- axis.offset[0] = 0;
1683
- axis.offset[1] = axis.scrollLength;
1684
- axis.progress = progress(0, axis.scrollLength, axis.current);
1685
- const elapsed = time - prevTime;
1686
- axis.velocity =
1687
- elapsed > maxElapsed ? 0 : velocityPerSecond(axis.current - prev, elapsed);
1688
- }
1689
- function updateScrollInfo(element, info, time) {
1690
- updateAxisInfo(element, "x", info, time);
1691
- updateAxisInfo(element, "y", info, time);
1692
- info.time = time;
1693
- }
1694
-
1695
- function calcInset(element, container) {
1696
- let inset = { x: 0, y: 0 };
1697
- let current = element;
1698
- while (current && current !== container) {
1699
- if (current instanceof HTMLElement) {
1700
- inset.x += current.offsetLeft;
1701
- inset.y += current.offsetTop;
1702
- current = current.offsetParent;
1703
- }
1704
- else if (current instanceof SVGGraphicsElement && "getBBox" in current) {
1705
- const { top, left } = current.getBBox();
1706
- inset.x += left;
1707
- inset.y += top;
1708
- /**
1709
- * Assign the next parent element as the <svg /> tag.
1710
- */
1711
- while (current && current.tagName !== "svg") {
1712
- current = current.parentNode;
1713
- }
1714
- }
1715
- }
1716
- return inset;
1717
- }
1718
-
1719
- const ScrollOffset = {
1720
- Enter: [
1721
- [0, 1],
1722
- [1, 1],
1723
- ],
1724
- Exit: [
1725
- [0, 0],
1726
- [1, 0],
1727
- ],
1728
- Any: [
1729
- [1, 0],
1730
- [0, 1],
1731
- ],
1732
- All: [
1733
- [0, 0],
1734
- [1, 1],
1735
- ],
1736
- };
1737
-
1738
- const namedEdges = {
1739
- start: 0,
1740
- center: 0.5,
1741
- end: 1,
1742
- };
1743
- function resolveEdge(edge, length, inset = 0) {
1744
- let delta = 0;
1745
- /**
1746
- * If we have this edge defined as a preset, replace the definition
1747
- * with the numerical value.
1748
- */
1749
- if (namedEdges[edge] !== undefined) {
1750
- edge = namedEdges[edge];
1751
- }
1752
- /**
1753
- * Handle unit values
1754
- */
1755
- if (isString(edge)) {
1756
- const asNumber = parseFloat(edge);
1757
- if (edge.endsWith("px")) {
1758
- delta = asNumber;
1759
- }
1760
- else if (edge.endsWith("%")) {
1761
- edge = asNumber / 100;
1762
- }
1763
- else if (edge.endsWith("vw")) {
1764
- delta = (asNumber / 100) * document.documentElement.clientWidth;
1765
- }
1766
- else if (edge.endsWith("vh")) {
1767
- delta = (asNumber / 100) * document.documentElement.clientHeight;
1768
- }
1769
- else {
1770
- edge = asNumber;
1771
- }
1772
- }
1773
- /**
1774
- * If the edge is defined as a number, handle as a progress value.
1775
- */
1776
- if (isNumber(edge)) {
1777
- delta = length * edge;
1778
- }
1779
- return inset + delta;
1780
- }
1781
-
1782
- const defaultOffset = [0, 0];
1783
- function resolveOffset(offset, containerLength, targetLength, targetInset) {
1784
- let offsetDefinition = Array.isArray(offset) ? offset : defaultOffset;
1785
- let targetPoint = 0;
1786
- let containerPoint = 0;
1787
- if (isNumber(offset)) {
1788
- /**
1789
- * If we're provided offset: [0, 0.5, 1] then each number x should become
1790
- * [x, x], so we default to the behaviour of mapping 0 => 0 of both target
1791
- * and container etc.
1792
- */
1793
- offsetDefinition = [offset, offset];
1794
- }
1795
- else if (isString(offset)) {
1796
- offset = offset.trim();
1797
- if (offset.includes(" ")) {
1798
- offsetDefinition = offset.split(" ");
1799
- }
1800
- else {
1801
- /**
1802
- * If we're provided a definition like "100px" then we want to apply
1803
- * that only to the top of the target point, leaving the container at 0.
1804
- * Whereas a named offset like "end" should be applied to both.
1805
- */
1806
- offsetDefinition = [offset, namedEdges[offset] ? offset : `0`];
1807
- }
1808
- }
1809
- targetPoint = resolveEdge(offsetDefinition[0], targetLength, targetInset);
1810
- containerPoint = resolveEdge(offsetDefinition[1], containerLength);
1811
- return targetPoint - containerPoint;
1812
- }
1813
-
1814
- const point = { x: 0, y: 0 };
1815
- function resolveOffsets(container, info, options) {
1816
- let { offset: offsetDefinition = ScrollOffset.All } = options;
1817
- const { target = container, axis = "y" } = options;
1818
- const lengthLabel = axis === "y" ? "height" : "width";
1819
- const inset = target !== container ? calcInset(target, container) : point;
1820
- /**
1821
- * Measure the target and container. If they're the same thing then we
1822
- * use the container's scrollWidth/Height as the target, from there
1823
- * all other calculations can remain the same.
1824
- */
1825
- const targetSize = target === container
1826
- ? { width: container.scrollWidth, height: container.scrollHeight }
1827
- : { width: target.clientWidth, height: target.clientHeight };
1828
- const containerSize = {
1829
- width: container.clientWidth,
1830
- height: container.clientHeight,
1831
- };
1832
- /**
1833
- * Reset the length of the resolved offset array rather than creating a new one.
1834
- * TODO: More reusable data structures for targetSize/containerSize would also be good.
1835
- */
1836
- info[axis].offset.length = 0;
1837
- /**
1838
- * Populate the offset array by resolving the user's offset definition into
1839
- * a list of pixel scroll offets.
1840
- */
1841
- let hasChanged = !info[axis].interpolate;
1842
- const numOffsets = offsetDefinition.length;
1843
- for (let i = 0; i < numOffsets; i++) {
1844
- const offset = resolveOffset(offsetDefinition[i], containerSize[lengthLabel], targetSize[lengthLabel], inset[axis]);
1845
- if (!hasChanged && offset !== info[axis].interpolatorOffsets[i]) {
1846
- hasChanged = true;
1847
- }
1848
- info[axis].offset[i] = offset;
1849
- }
1850
- /**
1851
- * If the pixel scroll offsets have changed, create a new interpolator function
1852
- * to map scroll value into a progress.
1853
- */
1854
- if (hasChanged) {
1855
- info[axis].interpolate = interpolate(defaultOffset$1(numOffsets), info[axis].offset);
1856
- info[axis].interpolatorOffsets = [...info[axis].offset];
1857
- }
1858
- info[axis].progress = info[axis].interpolate(info[axis].current);
1859
- }
1860
-
1861
- function measure(container, target = container, info) {
1862
- /**
1863
- * Find inset of target within scrollable container
1864
- */
1865
- info.x.targetOffset = 0;
1866
- info.y.targetOffset = 0;
1867
- if (target !== container) {
1868
- let node = target;
1869
- while (node && node != container) {
1870
- info.x.targetOffset += node.offsetLeft;
1871
- info.y.targetOffset += node.offsetTop;
1872
- node = node.offsetParent;
1873
- }
1874
- }
1875
- info.x.targetLength =
1876
- target === container ? target.scrollWidth : target.clientWidth;
1877
- info.y.targetLength =
1878
- target === container ? target.scrollHeight : target.clientHeight;
1879
- info.x.containerLength = container.clientWidth;
1880
- info.y.containerLength = container.clientHeight;
1881
- }
1882
- function createOnScrollHandler(element, onScroll, info, options = {}) {
1883
- const axis = options.axis || "y";
1884
- return {
1885
- measure: () => measure(element, options.target, info),
1886
- update: (time) => {
1887
- updateScrollInfo(element, info, time);
1888
- if (options.offset || options.target) {
1889
- resolveOffsets(element, info, options);
1890
- }
1891
- },
1892
- notify: isFunction(onScroll)
1893
- ? () => onScroll(info)
1894
- : scrubAnimation(onScroll, info[axis]),
1895
- };
1896
- }
1897
- function scrubAnimation(controls, axisInfo) {
1898
- controls.pause();
1899
- controls.forEachNative((animation, { easing }) => {
1900
- var _a, _b;
1901
- if (animation.updateDuration) {
1902
- if (!easing)
1903
- animation.easing = noopReturn;
1904
- animation.updateDuration(1);
1905
- }
1906
- else {
1907
- const timingOptions = { duration: 1000 };
1908
- if (!easing)
1909
- timingOptions.easing = "linear";
1910
- (_b = (_a = animation.effect) === null || _a === void 0 ? void 0 : _a.updateTiming) === null || _b === void 0 ? void 0 : _b.call(_a, timingOptions);
1911
- }
1912
- });
1913
- return () => {
1914
- controls.currentTime = axisInfo.progress;
1915
- };
1916
- }
1917
-
1918
- const scrollListeners = new WeakMap();
1919
- const resizeListeners = new WeakMap();
1920
- const onScrollHandlers = new WeakMap();
1921
- const getEventTarget = (element) => element === document.documentElement ? window : element;
1922
- function scroll(onScroll, _a = {}) {
1923
- var { container = document.documentElement } = _a, options = __rest(_a, ["container"]);
1924
- let containerHandlers = onScrollHandlers.get(container);
1925
- /**
1926
- * Get the onScroll handlers for this container.
1927
- * If one isn't found, create a new one.
1928
- */
1929
- if (!containerHandlers) {
1930
- containerHandlers = new Set();
1931
- onScrollHandlers.set(container, containerHandlers);
1932
- }
1933
- /**
1934
- * Create a new onScroll handler for the provided callback.
1935
- */
1936
- const info = createScrollInfo();
1937
- const containerHandler = createOnScrollHandler(container, onScroll, info, options);
1938
- containerHandlers.add(containerHandler);
1939
- /**
1940
- * Check if there's a scroll event listener for this container.
1941
- * If not, create one.
1942
- */
1943
- if (!scrollListeners.has(container)) {
1944
- const listener = () => {
1945
- const time = performance.now();
1946
- for (const handler of containerHandlers)
1947
- handler.measure();
1948
- for (const handler of containerHandlers)
1949
- handler.update(time);
1950
- for (const handler of containerHandlers)
1951
- handler.notify();
1952
- };
1953
- scrollListeners.set(container, listener);
1954
- const target = getEventTarget(container);
1955
- window.addEventListener("resize", listener, { passive: true });
1956
- if (container !== document.documentElement) {
1957
- resizeListeners.set(container, resize(container, listener));
1958
- }
1959
- target.addEventListener("scroll", listener, { passive: true });
1960
- }
1961
- const listener = scrollListeners.get(container);
1962
- const onLoadProcesss = requestAnimationFrame(listener);
1963
- return () => {
1964
- var _a;
1965
- if (typeof onScroll !== "function")
1966
- onScroll.stop();
1967
- cancelAnimationFrame(onLoadProcesss);
1968
- /**
1969
- * Check if we even have any handlers for this container.
1970
- */
1971
- const containerHandlers = onScrollHandlers.get(container);
1972
- if (!containerHandlers)
1973
- return;
1974
- containerHandlers.delete(containerHandler);
1975
- if (containerHandlers.size)
1976
- return;
1977
- /**
1978
- * If no more handlers, remove the scroll listener too.
1979
- */
1980
- const listener = scrollListeners.get(container);
1981
- scrollListeners.delete(container);
1982
- if (listener) {
1983
- getEventTarget(container).removeEventListener("scroll", listener);
1984
- (_a = resizeListeners.get(container)) === null || _a === void 0 ? void 0 : _a();
1985
- window.removeEventListener("resize", listener);
1986
- }
1987
- };
1988
- }
1989
-
1990
- function hasChanged(a, b) {
1991
- if (typeof a !== typeof b)
1992
- return true;
1993
- if (Array.isArray(a) && Array.isArray(b))
1994
- return !shallowCompare(a, b);
1995
- return a !== b;
1996
- }
1997
- function shallowCompare(next, prev) {
1998
- const prevLength = prev.length;
1999
- if (prevLength !== next.length)
2000
- return false;
2001
- for (let i = 0; i < prevLength; i++) {
2002
- if (prev[i] !== next[i])
2003
- return false;
2004
- }
2005
- return true;
2006
- }
2007
-
2008
- function isVariant(definition) {
2009
- return typeof definition === "object";
2010
- }
2011
-
2012
- function resolveVariant(definition, variants) {
2013
- if (isVariant(definition)) {
2014
- return definition;
2015
- }
2016
- else if (definition && variants) {
2017
- return variants[definition];
2018
- }
2019
- }
2020
-
2021
- let scheduled = undefined;
2022
- function processScheduledAnimations() {
2023
- if (!scheduled)
2024
- return;
2025
- const generators = scheduled.sort(compareByDepth).map(fireAnimateUpdates);
2026
- generators.forEach(fireNext);
2027
- generators.forEach(fireNext);
2028
- scheduled = undefined;
2029
- }
2030
- function scheduleAnimation(state) {
2031
- if (!scheduled) {
2032
- scheduled = [state];
2033
- requestAnimationFrame(processScheduledAnimations);
2034
- }
2035
- else {
2036
- addUniqueItem(scheduled, state);
2037
- }
2038
- }
2039
- function unscheduleAnimation(state) {
2040
- scheduled && removeItem(scheduled, state);
2041
- }
2042
- const compareByDepth = (a, b) => a.getDepth() - b.getDepth();
2043
- const fireAnimateUpdates = (state) => state.animateUpdates();
2044
- const fireNext = (iterator) => iterator.next();
2045
-
2046
- const motionEvent = (name, target) => new CustomEvent(name, { detail: { target } });
2047
- function dispatchPointerEvent(element, name, event) {
2048
- element.dispatchEvent(new CustomEvent(name, { detail: { originalEvent: event } }));
2049
- }
2050
- function dispatchViewEvent(element, name, entry) {
2051
- element.dispatchEvent(new CustomEvent(name, { detail: { originalEntry: entry } }));
2052
- }
2053
-
2054
- const inView = {
2055
- isActive: (options) => Boolean(options.inView),
2056
- subscribe: (element, { enable, disable }, { inViewOptions = {} }) => {
2057
- const { once } = inViewOptions, viewOptions = __rest(inViewOptions, ["once"]);
2058
- return inView$1(element, (enterEntry) => {
2059
- enable();
2060
- dispatchViewEvent(element, "viewenter", enterEntry);
2061
- if (!once) {
2062
- return (leaveEntry) => {
2063
- disable();
2064
- dispatchViewEvent(element, "viewleave", leaveEntry);
2065
- };
2066
- }
2067
- }, viewOptions);
2068
- },
2069
- };
2070
-
2071
- const mouseEvent = (element, name, action) => (event) => {
2072
- if (event.pointerType && event.pointerType !== "mouse")
2073
- return;
2074
- action();
2075
- dispatchPointerEvent(element, name, event);
2076
- };
2077
- const hover = {
2078
- isActive: (options) => Boolean(options.hover),
2079
- subscribe: (element, { enable, disable }) => {
2080
- const onEnter = mouseEvent(element, "hoverstart", enable);
2081
- const onLeave = mouseEvent(element, "hoverend", disable);
2082
- element.addEventListener("pointerenter", onEnter);
2083
- element.addEventListener("pointerleave", onLeave);
2084
- return () => {
2085
- element.removeEventListener("pointerenter", onEnter);
2086
- element.removeEventListener("pointerleave", onLeave);
2087
- };
2088
- },
2089
- };
2090
-
2091
- const press = {
2092
- isActive: (options) => Boolean(options.press),
2093
- subscribe: (element, { enable, disable }) => {
2094
- const onPointerUp = (event) => {
2095
- disable();
2096
- dispatchPointerEvent(element, "pressend", event);
2097
- window.removeEventListener("pointerup", onPointerUp);
2098
- };
2099
- const onPointerDown = (event) => {
2100
- enable();
2101
- dispatchPointerEvent(element, "pressstart", event);
2102
- window.addEventListener("pointerup", onPointerUp);
2103
- };
2104
- element.addEventListener("pointerdown", onPointerDown);
2105
- return () => {
2106
- element.removeEventListener("pointerdown", onPointerDown);
2107
- window.removeEventListener("pointerup", onPointerUp);
2108
- };
2109
- },
2110
- };
2111
-
2112
- const gestures = { inView, hover, press };
2113
- /**
2114
- * A list of state types, in priority order. If a value is defined in
2115
- * a righter-most type, it will override any definition in a lefter-most.
2116
- */
2117
- const stateTypes = ["initial", "animate", ...Object.keys(gestures), "exit"];
2118
- /**
2119
- * A global store of all generated motion states. This can be used to lookup
2120
- * a motion state for a given Element.
2121
- */
2122
- const mountedStates = new WeakMap();
2123
- function createMotionState(options = {}, parent) {
2124
- /**
2125
- * The element represented by the motion state. This is an empty reference
2126
- * when we create the state to support SSR and allow for later mounting
2127
- * in view libraries.
2128
- *
2129
- * @ts-ignore
2130
- */
2131
- let element;
2132
- /**
2133
- * Calculate a depth that we can use to order motion states by tree depth.
2134
- */
2135
- let depth = parent ? parent.getDepth() + 1 : 0;
2136
- /**
2137
- * Track which states are currently active.
2138
- */
2139
- const activeStates = { initial: true, animate: true };
2140
- /**
2141
- * A map of functions that, when called, will remove event listeners for
2142
- * a given gesture.
2143
- */
2144
- const gestureSubscriptions = {};
2145
- /**
2146
- * Initialise a context to share through motion states. This
2147
- * will be populated by variant names (if any).
2148
- */
2149
- const context = {};
2150
- for (const name of stateTypes) {
2151
- context[name] =
2152
- typeof options[name] === "string"
2153
- ? options[name]
2154
- : parent === null || parent === void 0 ? void 0 : parent.getContext()[name];
2155
- }
2156
- /**
2157
- * If initial is set to false we use the animate prop as the initial
2158
- * animation state.
2159
- */
2160
- const initialVariantSource = options.initial === false ? "animate" : "initial";
2161
- /**
2162
- * Destructure an initial target out from the resolved initial variant.
2163
- */
2164
- let _a = resolveVariant(options[initialVariantSource] || context[initialVariantSource], options.variants) || {}, target = __rest(_a, ["transition"]);
2165
- /**
2166
- * The base target is a cached map of values that we'll use to animate
2167
- * back to if a value is removed from all active state types. This
2168
- * is usually the initial value as read from the DOM, for instance if
2169
- * it hasn't been defined in initial.
2170
- */
2171
- const baseTarget = Object.assign({}, target);
2172
- /**
2173
- * A generator that will be processed by the global animation scheduler.
2174
- * This yields when it switches from reading the DOM to writing to it
2175
- * to prevent layout thrashing.
2176
- */
2177
- function* animateUpdates() {
2178
- var _a, _b;
2179
- const prevTarget = target;
2180
- target = {};
2181
- const animationOptions = {};
2182
- for (const name of stateTypes) {
2183
- if (!activeStates[name])
2184
- continue;
2185
- const variant = resolveVariant(options[name]);
2186
- if (!variant)
2187
- continue;
2188
- for (const key in variant) {
2189
- if (key === "transition")
2190
- continue;
2191
- target[key] = variant[key];
2192
- animationOptions[key] = getOptions((_b = (_a = variant.transition) !== null && _a !== void 0 ? _a : options.transition) !== null && _b !== void 0 ? _b : {}, key);
2193
- }
2194
- }
2195
- const allTargetKeys = new Set([
2196
- ...Object.keys(target),
2197
- ...Object.keys(prevTarget),
2198
- ]);
2199
- const animationFactories = [];
2200
- allTargetKeys.forEach((key) => {
2201
- var _a;
2202
- if (target[key] === undefined) {
2203
- target[key] = baseTarget[key];
2204
- }
2205
- if (hasChanged(prevTarget[key], target[key])) {
2206
- (_a = baseTarget[key]) !== null && _a !== void 0 ? _a : (baseTarget[key] = style.get(element, key));
2207
- animationFactories.push(animateStyle(element, key, target[key], animationOptions[key], Animation));
2208
- }
2209
- });
2210
- // Wait for all animation states to read from the DOM
2211
- yield;
2212
- const animations = animationFactories
2213
- .map((factory) => factory())
2214
- .filter(Boolean);
2215
- if (!animations.length)
2216
- return;
2217
- const animationTarget = target;
2218
- element.dispatchEvent(motionEvent("motionstart", animationTarget));
2219
- Promise.all(animations.map((animation) => animation.finished))
2220
- .then(() => {
2221
- element.dispatchEvent(motionEvent("motioncomplete", animationTarget));
2222
- })
2223
- .catch(noop);
2224
- }
2225
- const setGesture = (name, isActive) => () => {
2226
- activeStates[name] = isActive;
2227
- scheduleAnimation(state);
2228
- };
2229
- const updateGestureSubscriptions = () => {
2230
- for (const name in gestures) {
2231
- const isGestureActive = gestures[name].isActive(options);
2232
- const remove = gestureSubscriptions[name];
2233
- if (isGestureActive && !remove) {
2234
- gestureSubscriptions[name] = gestures[name].subscribe(element, {
2235
- enable: setGesture(name, true),
2236
- disable: setGesture(name, false),
2237
- }, options);
2238
- }
2239
- else if (!isGestureActive && remove) {
2240
- remove();
2241
- delete gestureSubscriptions[name];
2242
- }
2243
- }
2244
- };
2245
- const state = {
2246
- update: (newOptions) => {
2247
- if (!element)
2248
- return;
2249
- options = newOptions;
2250
- updateGestureSubscriptions();
2251
- scheduleAnimation(state);
2252
- },
2253
- setActive: (name, isActive) => {
2254
- if (!element)
2255
- return;
2256
- activeStates[name] = isActive;
2257
- scheduleAnimation(state);
2258
- },
2259
- animateUpdates,
2260
- getDepth: () => depth,
2261
- getTarget: () => target,
2262
- getOptions: () => options,
2263
- getContext: () => context,
2264
- mount: (newElement) => {
2265
- invariant(Boolean(newElement), "Animation state must be mounted with valid Element");
2266
- element = newElement;
2267
- mountedStates.set(element, state);
2268
- updateGestureSubscriptions();
2269
- return () => {
2270
- mountedStates.delete(element);
2271
- unscheduleAnimation(state);
2272
- for (const key in gestureSubscriptions) {
2273
- gestureSubscriptions[key]();
2274
- }
2275
- };
2276
- },
2277
- isMounted: () => Boolean(element),
2278
- };
2279
- return state;
2280
- }
2281
-
2282
- function createStyles(keyframes) {
2283
- const initialKeyframes = {};
2284
- const transformKeys = [];
2285
- for (let key in keyframes) {
2286
- const value = keyframes[key];
2287
- if (isTransform(key)) {
2288
- if (transformAlias[key])
2289
- key = transformAlias[key];
2290
- transformKeys.push(key);
2291
- key = asTransformCssVar(key);
2292
- }
2293
- let initialKeyframe = Array.isArray(value) ? value[0] : value;
2294
- /**
2295
- * If this is a number and we have a default value type, convert the number
2296
- * to this type.
2297
- */
2298
- const definition = transformDefinitions.get(key);
2299
- if (definition) {
2300
- initialKeyframe = isNumber(value)
2301
- ? definition.toDefaultUnit(value)
2302
- : value;
2303
- }
2304
- initialKeyframes[key] = initialKeyframe;
2305
- }
2306
- if (transformKeys.length) {
2307
- initialKeyframes.transform = buildTransformTemplate(transformKeys);
2308
- }
2309
- return initialKeyframes;
2310
- }
2311
-
2312
- const camelLetterToPipeLetter = (letter) => `-${letter.toLowerCase()}`;
2313
- const camelToPipeCase = (str) => str.replace(/[A-Z]/g, camelLetterToPipeLetter);
2314
- function createStyleString(target = {}) {
2315
- const styles = createStyles(target);
2316
- let style = "";
2317
- for (const key in styles) {
2318
- style += key.startsWith("--") ? key : camelToPipeCase(key);
2319
- style += `: ${styles[key]}; `;
2320
- }
2321
- return style;
2322
- }
2323
-
2324
- function animateProgress(target, options = {}) {
2325
- return withControls([
2326
- () => {
2327
- const animation = new Animation(target, [0, 1], options);
2328
- animation.finished.catch(() => { });
2329
- return animation;
2330
- },
2331
- ], options, options.duration);
2332
- }
2333
- function animate(target, keyframesOrOptions, options) {
2334
- const factory = isFunction(target) ? animateProgress : animate$1;
2335
- return factory(target, keyframesOrOptions, options);
2336
- }
2337
-
2338
- exports.MotionValue = MotionValue;
2339
- exports.ScrollOffset = ScrollOffset;
2340
- exports.animate = animate;
2341
- exports.animateStyle = animateStyle;
2342
- exports.createAnimate = createAnimate;
2343
- exports.createMotionState = createMotionState;
2344
- exports.createStyleString = createStyleString;
2345
- exports.createStyles = createStyles;
2346
- exports.getAnimationData = getAnimationData;
2347
- exports.getStyleName = getStyleName;
2348
- exports.glide = glide;
2349
- exports.inView = inView$1;
2350
- exports.mountedStates = mountedStates;
2351
- exports.resize = resize;
2352
- exports.scroll = scroll;
2353
- exports.spring = spring;
2354
- exports.stagger = stagger;
2355
- exports.style = style;
2356
- exports.timeline = timeline;
2357
- exports.withControls = withControls;
2358
-
2359
- }));