{"version":3,"file":"State.Dowu87IL.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/ecmnSddXBJpQsAujxCSQ/2zMFA9EQryEKkWl3wsPK/State.js"],"sourcesContent":["import{useState,useEffect}from\"react\";import{Data,useObserveData}from\"framer\";export function createStore(state1){// Use Data so that a Preview reload resets the state\nconst dataStore=Data({state:Object.freeze({...state1})})// Create a set function that updates the state\n;const setDataStore=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(dataStore.state);}dataStore.state=Object.freeze({...dataStore.state,...newState});}// Store the initial state, copy the object if it's an object\n;let storeState=typeof state1===\"object\"?Object.freeze({...state1}):state1// Keep a list of all the listeners, in the form of React hook setters\n;const storeSetters=new Set// Create a set function that updates all the listeners / setters\n;const setStoreState=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(storeState);}storeState=typeof newState===\"object\"?Object.freeze({...storeState,...newState}):newState// Update all the listeners / setters with the new value\n;storeSetters.forEach(setter=>setter(storeState));}// Create the actual hook based on everything above\n;function useStore(){// Create the hook we are going to use as a listener\nconst[state,setState]=useState(storeState)// If we unmount the component using this hook, we need to remove the listener\n;// @ts-ignore\nuseEffect(()=>{// But right now, we need to add the listener\nstoreSetters.add(setState);return()=>storeSetters.delete(setState);},[])// If Data context exists, use Data, otherwise use vanilla React state\n;if(useObserveData()===true){useObserveData();return[dataStore.state,setDataStore];}else{// Return the state and a function to update the central store\nreturn[state,setStoreState];}}return useStore;}export function createStorePersist(state1,storageKey){// Cargar el estado desde localStorage si existe\nconst loadState=()=>{if(typeof window!==\"undefined\"){const storedState=localStorage.getItem(storageKey);return storedState?JSON.parse(storedState):state1;}return state1;};const dataStore=Data({state:Object.freeze({...loadState()})});const setDataStore=newState=>{if(typeof newState===\"function\"){newState=newState(dataStore.state);}dataStore.state=Object.freeze({...dataStore.state,...newState});// Guardar en localStorage cada vez que cambia el estado\nif(typeof window!==\"undefined\"){localStorage.setItem(storageKey,JSON.stringify(dataStore.state));}};let storeState=typeof state1===\"object\"?Object.freeze({...loadState()}):state1;const storeSetters=new Set;const setStoreState=newState=>{if(typeof newState===\"function\"){newState=newState(storeState);}storeState=typeof newState===\"object\"?Object.freeze({...storeState,...newState}):newState;storeSetters.forEach(setter=>setter(storeState));// Guardar en localStorage\nif(typeof window!==\"undefined\"){localStorage.setItem(storageKey,JSON.stringify(storeState));}};function useStore(){const[state,setState]=useState(storeState);useEffect(()=>{storeSetters.add(setState);return()=>storeSetters.delete(setState);},[]);if(useObserveData()===true){useObserveData();return[dataStore.state,setDataStore];}else{return[state,setStoreState];}}return useStore;}\nexport const __FramerMetadata__ = {\"exports\":{\"createStorePersist\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"createStore\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./State.map"],"mappings":"8KAA8E,SAAgB,EAAY,EAAO,CACjH,IAAM,EAAU,EAAK,CAAC,MAAM,OAAO,OAAO,CAAC,GAAG,CAAM,CAAC,CAAC,CAAC,EAChD,EAAa,GAAU,CAC3B,OAAO,GAAW,aAAY,EAAS,EAAS,EAAU,KAAK,GAAG,EAAU,MAAM,OAAO,OAAO,CAAC,GAAG,EAAU,MAAM,GAAG,CAAQ,CAAC,CAAE,EAChI,EAAW,OAAO,GAAS,SAAS,OAAO,OAAO,CAAC,GAAG,CAAM,CAAC,EAAE,EAC7D,EAAa,IAAI,IACjB,EAAc,GAAU,CAC5B,OAAO,GAAW,aAAY,EAAS,EAAS,CAAU,GAAG,EAAW,OAAO,GAAW,SAAS,OAAO,OAAO,CAAC,GAAG,EAAW,GAAG,CAAQ,CAAC,EAAE,EAChJ,EAAa,QAAQ,GAAQ,EAAO,CAAU,CAAC,CAAE,EACjD,SAAS,GAAU,CACpB,GAAK,CAAC,EAAM,GAAUA,EAAS,CAAU,EAKzC,OAHA,OACA,EAAa,IAAI,CAAQ,MA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