motion 10.18.0 → 11.11.13

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