{"version":3,"file":"useAutoMotionValue.DSbptbdW.mjs","names":["useRef","useCallback","useEffect","__esmMin","ne","de","init_npm_react_18_3_1","ce","init_framer_ChujFWHC","animate","RenderTarget","MotionValue","motionValue","init_useConstant","useConstant","isMotionValue","init_isMotionValue","v","useAutoMotionValue","inputValue","options","optionsRef","animation","didInitialMount","isOnCanvas","onChangeDeps","onChange","transformer","value","value1","ref","newValue","init_useAutoMotionValue"],"sources":["https:/framerusercontent.com/modules/3mKFSGQqKHV82uOV1eBc/TbXI1XaZFNevVKcgIt7G/isMotionValue.js","https:/framerusercontent.com/modules/kNDwabfjDEb3vUxkQlZS/V4SPg9g59hF1vFH3ZTF0/useAutoMotionValue.js"],"sourcesContent":["import{MotionValue}from\"framer\";// Basic MotionValue check\nexport const isMotionValue=v=>v instanceof MotionValue;\nexport const __FramerMetadata__ = {\"exports\":{\"isMotionValue\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./isMotionValue.map","import{useCallback,useEffect,useRef}from\"react\";import{motionValue,animate,RenderTarget}from\"framer\";import{isMotionValue}from\"https://framerusercontent.com/modules/3mKFSGQqKHV82uOV1eBc/TbXI1XaZFNevVKcgIt7G/isMotionValue.js\";import{useConstant}from\"https://framerusercontent.com/modules/ExNgrA7EJTKUPpH6vIlN/eiOrSJ2Ab5M9jPCvVwUz/useConstant.js\";export function useAutoMotionValue(inputValue,options){// Put options on a local ref\n// Might wanna just memo instead but it works for now\nconst optionsRef=useRef(options);const animation=useRef();const didInitialMount=useRef(false);const isOnCanvas=RenderTarget.current()===RenderTarget.canvas;// in-progress - trying to figure out effect hooks\nconst onChangeDeps=(options===null||options===void 0?void 0:options.onChangeDeps)?options.onChangeDeps:[];// Memoize the onChange handler\nconst onChange=useCallback(options===null||options===void 0?void 0:options.onChange,[...onChangeDeps,]);// Optionally scale the value from props\nconst transformer=useCallback(value=>{var ref;return((ref=optionsRef.current)===null||ref===void 0?void 0:ref.transform)?optionsRef.current.transform(value):value;},[]);// Create new MotionValue from inputValue\nconst value1=useConstant(()=>isMotionValue(inputValue)?inputValue:motionValue(transformer(inputValue)));// Setting value from prop change\nuseEffect(()=>{if(!isMotionValue(inputValue)&&didInitialMount.current){var ref,ref1;const newValue=transformer(inputValue);(ref=animation.current)===null||ref===void 0?void 0:ref.stop();// Call change callback\nif(onChange)onChange(newValue,value1);// Trigger animation to new value\nif(((ref1=optionsRef.current)===null||ref1===void 0?void 0:ref1.animate)&&!isOnCanvas){var ref2;// @ts-ignore\nanimation.current=animate(value1,newValue,(ref2=optionsRef.current)===null||ref2===void 0?void 0:ref2.transition);}else{value1.set(newValue);}}didInitialMount.current=true;},[inputValue,...onChangeDeps]);return value1;}\nexport const __FramerMetadata__ = {\"exports\":{\"useAutoMotionValue\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./useAutoMotionValue.map"],"mappings":"A,uTACae,EAAcE,GAAGA,aAAaN,C,OCD8S,SAAgBO,EAAmBC,EAAWC,EAAQ,CAE/Y,IAAMC,EAAWrB,EAAOoB,CAAO,EAAQE,EAAUtB,EAAO,EAAQuB,EAAgBvB,EAAO,EAAK,EAAQwB,EAAWd,EAAa,QAAQ,IAAIA,EAAa,OAC/Ie,EAAcL,GAAgD,aAAcA,EAAQ,aAAa,CAAC,EAClGM,EAASzB,EAAYmB,GAAgD,SAAS,CAAC,GAAGK,CAAa,CAAC,EAChGE,EAAY1B,EAAY2B,GAA4BP,EAAW,SAAyC,UAAWA,EAAW,QAAQ,UAAUO,CAAK,EAAEA,EAAQ,CAAC,CAAC,EACjKC,EAAOf,MAAgBC,EAAcI,CAAU,EAAEA,EAAWP,EAAYe,EAAYR,CAAU,CAAC,CAAC,EAIsG,OAH5MjB,MAAc,CAAC,GAAG,CAACa,EAAcI,CAAU,GAAGI,EAAgB,QAAQ,CAAC,IAAIO,EAAS,IAAMC,EAASJ,EAAYR,CAAU,GAAGW,EAAIR,EAAU,UAAW,MAA0BQ,EAAI,KAAK,EACrLJ,GAASA,EAASK,EAASF,CAAM,EAC1BR,EAAW,SAA2C,SAAU,CAACG,EAC3EF,EAAU,QAAQb,EAAQoB,EAAOE,EAAeV,EAAW,SAA2C,UAAU,EAAQQ,EAAO,IAAIE,CAAQ,CAAG,CAACR,EAAgB,QAAQ,EAAK,EAAE,CAACJ,EAAW,GAAGM,CAAY,CAAC,EAASI,CAAO,C"}