{"ast":null,"code":"import { useContext, useRef, useInsertionEffect } from 'react';\nimport { isMotionValue } from './utils/is-motion-value.mjs';\nimport { useMotionValue } from './use-motion-value.mjs';\nimport { MotionConfigContext } from '../context/MotionConfigContext.mjs';\nimport { useIsomorphicLayoutEffect } from '../utils/use-isomorphic-effect.mjs';\nimport { animateValue } from '../animation/animators/js/index.mjs';\nimport { frameData } from '../frameloop/frame.mjs';\n\n/**\n * Creates a `MotionValue` that, when `set`, will use a spring animation to animate to its new state.\n *\n * It can either work as a stand-alone `MotionValue` by initialising it with a value, or as a subscriber\n * to another `MotionValue`.\n *\n * @remarks\n *\n * ```jsx\n * const x = useSpring(0, { stiffness: 300 })\n * const y = useSpring(x, { damping: 10 })\n * ```\n *\n * @param inputValue - `MotionValue` or number. If provided a `MotionValue`, when the input `MotionValue` changes, the created `MotionValue` will spring towards that value.\n * @param springConfig - Configuration options for the spring.\n * @returns `MotionValue`\n *\n * @public\n */\nfunction useSpring(source) {\n  let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n  const {\n    isStatic\n  } = useContext(MotionConfigContext);\n  const activeSpringAnimation = useRef(null);\n  const value = useMotionValue(isMotionValue(source) ? source.get() : source);\n  const stopAnimation = () => {\n    if (activeSpringAnimation.current) {\n      activeSpringAnimation.current.stop();\n    }\n  };\n  useInsertionEffect(() => {\n    return value.attach((v, set) => {\n      /**\n       * A more hollistic approach to this might be to use isStatic to fix VisualElement animations\n       * at that level, but this will work for now\n       */\n      if (isStatic) return set(v);\n      /**\n       * If the previous animation hasn't had the chance to even render a frame, render it now.\n       */\n      const animation = activeSpringAnimation.current;\n      if (animation && animation.time === 0) {\n        animation.sample(frameData.delta);\n      }\n      stopAnimation();\n      activeSpringAnimation.current = animateValue({\n        keyframes: [value.get(), v],\n        velocity: value.getVelocity(),\n        type: \"spring\",\n        restDelta: 0.001,\n        restSpeed: 0.01,\n        ...config,\n        onUpdate: set\n      });\n      return value.get();\n    }, stopAnimation);\n  }, [JSON.stringify(config)]);\n  useIsomorphicLayoutEffect(() => {\n    if (isMotionValue(source)) {\n      return source.on(\"change\", v => value.set(parseFloat(v)));\n    }\n  }, [value]);\n  return value;\n}\nexport { useSpring };","map":{"version":3,"names":["useContext","useRef","useInsertionEffect","isMotionValue","useMotionValue","MotionConfigContext","useIsomorphicLayoutEffect","animateValue","frameData","useSpring","source","config","arguments","length","undefined","isStatic","activeSpringAnimation","value","get","stopAnimation","current","stop","attach","v","set","animation","time","sample","delta","keyframes","velocity","getVelocity","type","restDelta","restSpeed","onUpdate","JSON","stringify","on","parseFloat"],"sources":["/opt/bitnami/minigames/frasle/node_modules/framer-motion/dist/es/value/use-spring.mjs"],"sourcesContent":["import { useContext, useRef, useInsertionEffect } from 'react';\nimport { isMotionValue } from './utils/is-motion-value.mjs';\nimport { useMotionValue } from './use-motion-value.mjs';\nimport { MotionConfigContext } from '../context/MotionConfigContext.mjs';\nimport { useIsomorphicLayoutEffect } from '../utils/use-isomorphic-effect.mjs';\nimport { animateValue } from '../animation/animators/js/index.mjs';\nimport { frameData } from '../frameloop/frame.mjs';\n\n/**\n * Creates a `MotionValue` that, when `set`, will use a spring animation to animate to its new state.\n *\n * It can either work as a stand-alone `MotionValue` by initialising it with a value, or as a subscriber\n * to another `MotionValue`.\n *\n * @remarks\n *\n * ```jsx\n * const x = useSpring(0, { stiffness: 300 })\n * const y = useSpring(x, { damping: 10 })\n * ```\n *\n * @param inputValue - `MotionValue` or number. If provided a `MotionValue`, when the input `MotionValue` changes, the created `MotionValue` will spring towards that value.\n * @param springConfig - Configuration options for the spring.\n * @returns `MotionValue`\n *\n * @public\n */\nfunction useSpring(source, config = {}) {\n    const { isStatic } = useContext(MotionConfigContext);\n    const activeSpringAnimation = useRef(null);\n    const value = useMotionValue(isMotionValue(source) ? source.get() : source);\n    const stopAnimation = () => {\n        if (activeSpringAnimation.current) {\n            activeSpringAnimation.current.stop();\n        }\n    };\n    useInsertionEffect(() => {\n        return value.attach((v, set) => {\n            /**\n             * A more hollistic approach to this might be to use isStatic to fix VisualElement animations\n             * at that level, but this will work for now\n             */\n            if (isStatic)\n                return set(v);\n            /**\n             * If the previous animation hasn't had the chance to even render a frame, render it now.\n             */\n            const animation = activeSpringAnimation.current;\n            if (animation && animation.time === 0) {\n                animation.sample(frameData.delta);\n            }\n            stopAnimation();\n            activeSpringAnimation.current = animateValue({\n                keyframes: [value.get(), v],\n                velocity: value.getVelocity(),\n                type: \"spring\",\n                restDelta: 0.001,\n                restSpeed: 0.01,\n                ...config,\n                onUpdate: set,\n            });\n            return value.get();\n        }, stopAnimation);\n    }, [JSON.stringify(config)]);\n    useIsomorphicLayoutEffect(() => {\n        if (isMotionValue(source)) {\n            return source.on(\"change\", (v) => value.set(parseFloat(v)));\n        }\n    }, [value]);\n    return value;\n}\n\nexport { useSpring };\n"],"mappings":"AAAA,SAASA,UAAU,EAAEC,MAAM,EAAEC,kBAAkB,QAAQ,OAAO;AAC9D,SAASC,aAAa,QAAQ,6BAA6B;AAC3D,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,mBAAmB,QAAQ,oCAAoC;AACxE,SAASC,yBAAyB,QAAQ,oCAAoC;AAC9E,SAASC,YAAY,QAAQ,qCAAqC;AAClE,SAASC,SAAS,QAAQ,wBAAwB;;AAElD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAACC,MAAM,EAAe;EAAA,IAAbC,MAAM,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAClC,MAAM;IAAEG;EAAS,CAAC,GAAGf,UAAU,CAACK,mBAAmB,CAAC;EACpD,MAAMW,qBAAqB,GAAGf,MAAM,CAAC,IAAI,CAAC;EAC1C,MAAMgB,KAAK,GAAGb,cAAc,CAACD,aAAa,CAACO,MAAM,CAAC,GAAGA,MAAM,CAACQ,GAAG,CAAC,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