{"version":3,"file":"Theme_switcher.BVQeXvcC.mjs","names":["useState","useState","useCallback"],"sources":["https:/framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js","https:/framer.com/m/framer/store.js@^1.0.0","https:/framerusercontent.com/modules/4Bry5M5cmK5v58QYtaXo/sTqLTLrid6k1LqP4DURf/Theme_switcher.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\nconst 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\nlet storeState=typeof state1===\"object\"?Object.freeze({...state1}):state1;// Keep a list of all the listeners, in the form of React hook setters\nconst storeSetters=new Set();// Create a set function that updates all the listeners / setters\nconst 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\nstoreSetters.forEach(setter=>setter(storeState));};// Create the actual hook based on everything above\nfunction 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\nif(useObserveData()===true){useObserveData();return[dataStore.state,setDataStore];}else{// Return the state and a function to update the central store\nreturn[state,setStoreState];}}return useStore;}\nexport const __FramerMetadata__ = {\"exports\":{\"createStore\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./createStore.map","/*\n * createStore (framer/store@1.0.1)\n *\n * Learn More: https://www.framer.com/asset-urls\n */\n\nexport * from \"https://framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js\"\n","import{jsx as _jsx}from\"react/jsx-runtime\";import{useIsStaticRenderer}from\"framer\";import{forwardRef,startTransition,useCallback,useEffect,useState}from\"react\";// @ts-ignore\nimport{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";const useStore=createStore({// Set the starting theme below, otherwise default to system.\ntheme:\"system\"});const changeTheme=theme=>{if(typeof window===\"undefined\"||typeof document===\"undefined\")return;const htmlElement=document.getElementsByTagName(\"html\")[0];const bodyElement=document.getElementsByTagName(\"body\")[0];htmlElement.setAttribute(\"toggle-theme\",`${theme}`);bodyElement.setAttribute(\"toggle-theme\",`${theme}`);localStorage.setItem(\"theme\",`${theme}`);// Trigger event that is compatible with Framestack Theme Image Component\nconst event=new Event(\"themeChange\");window.dispatchEvent(event);return;};export function withSingleToggle(Component){return props=>{const[store,setStore]=useStore();useEffect(()=>{// If starting theme is other than light/dark then match device theme.\nif(store.theme!==\"dark\"&&store.theme!==\"light\"){// Detect system theme\nconst mediaQuery=window.matchMedia(\"(prefers-color-scheme: dark)\");let newTheme=mediaQuery.matches?\"dark\":\"light\";// Set store theme\nsetStore({theme:newTheme});localStorage.setItem(\"theme\",`${newTheme}`);}else{// Set the starting theme based on store\nlocalStorage.setItem(\"theme\",`${store.theme}`);}// Create attributes on html and body so that theme will be applied based on store\nconst htmlElement=document.getElementsByTagName(\"html\")[0];const bodyElement=document.getElementsByTagName(\"body\")[0];htmlElement&&htmlElement.setAttribute(\"toggle-theme\",`${store.theme}`);bodyElement&&bodyElement.setAttribute(\"toggle-theme\",`${store.theme}`);// Create sets of light and dark mode tokens\nlet lightThemeTokens=[];let darkThemeTokens=\"\";for(let i=0;i<document.styleSheets.length;i++){const sheet=document.styleSheets[i];try{for(let rule of sheet.cssRules){// Get light and dark mode tokens\nconst styleRule=rule;const mediaRule=rule;if(styleRule.selectorText===\"body\"){const style=styleRule.style;for(let j=0;j<style.length;j++){const propertyName=style[j];if(propertyName.includes(\"--token\")){const value=style.getPropertyValue(propertyName);// Check for specific tokens or list all\nconst combinedCssRule=`${propertyName}: ${value};`;lightThemeTokens.push(combinedCssRule);}}}else if(mediaRule.conditionText===\"(prefers-color-scheme: dark)\"){const cssTextIgnore=\"body:not([data-framer-theme])\";if(!rule.cssText.includes(cssTextIgnore)){const mediaRulesString=mediaRule.cssRules[0].cssText.replace(\"body\",\"\").replace(/\\s*{\\s*/,\"\").replace(/\\s*}\\s*$/,\"\");darkThemeTokens=mediaRulesString;}}}}catch(e){console.warn(\"Cannot access stylesheet:\",sheet.href);}}// Create styleSheet with id and populate with correct CSS text\nlet styleElement=document.createElement(\"style\");styleElement.id=\"toggle-theme\";const customCssRule=`body[toggle-theme=\"light\"] {${lightThemeTokens.join(\" \")}} body[toggle-theme=\"dark\"]{${darkThemeTokens}} html[toggle-theme=\"light\"] { color-scheme: light; } html[toggle-theme=\"dark\"] { color-scheme: dark; }`;styleElement.textContent=customCssRule;document.head.appendChild(styleElement);// Cleanup function\nreturn()=>{// Check if the style element exists and remove it\nconst existingStyleElement=document.getElementById(\"toggle-theme\");if(existingStyleElement){document.head.removeChild(existingStyleElement);}htmlElement&&htmlElement.setAttribute(\"toggle-theme\",\"system\");bodyElement&&bodyElement.setAttribute(\"toggle-theme\",\"system\");};},[]);const handleClick=()=>{let newTheme=store.theme===\"light\"?\"dark\":\"light\";setStore({theme:newTheme});changeTheme(newTheme);};return /*#__PURE__*/_jsx(Component,{...props,variant:store.theme===\"light\"?\"Light\":\"Dark\",whileHover:{scale:.9},onClick:handleClick});};}const getRuntimeTheme=()=>{if(typeof window===\"undefined\"||typeof document===\"undefined\"){return\"light\";}const htmlTheme=document.documentElement?.getAttribute(\"toggle-theme\");const bodyTheme=document.body?.getAttribute(\"toggle-theme\");const attributeTheme=htmlTheme||bodyTheme;if(attributeTheme===\"light\"||attributeTheme===\"dark\"){return attributeTheme;}const localTheme=window.localStorage.getItem(\"theme\");if(localTheme===\"light\"||localTheme===\"dark\"){return localTheme;}return window.matchMedia(\"(prefers-color-scheme: dark)\").matches?\"dark\":\"light\";};export function ThemeAwareIcon(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const isStatic=useIsStaticRenderer();const[theme,setTheme]=useState(()=>getRuntimeTheme());const syncTheme=useCallback(()=>{const nextTheme=getRuntimeTheme();startTransition(()=>{setTheme(prevTheme=>prevTheme===nextTheme?prevTheme:nextTheme);});},[]);useEffect(()=>{if(isStatic||typeof window===\"undefined\"||typeof document===\"undefined\"){return;}syncTheme();window.addEventListener(\"themeChange\",syncTheme);const htmlObserver=new MutationObserver(syncTheme);const bodyObserver=new MutationObserver(syncTheme);htmlObserver.observe(document.documentElement,{attributes:true,attributeFilter:[\"toggle-theme\"]});if(document.body){bodyObserver.observe(document.body,{attributes:true,attributeFilter:[\"toggle-theme\"]});}const mediaQuery=window.matchMedia(\"(prefers-color-scheme: dark)\");const onMediaChange=()=>syncTheme();mediaQuery.addEventListener(\"change\",onMediaChange);return()=>{window.removeEventListener(\"themeChange\",syncTheme);mediaQuery.removeEventListener(\"change\",onMediaChange);htmlObserver.disconnect();bodyObserver.disconnect();};},[isStatic,syncTheme]);const existingFilter=typeof props?.style?.filter===\"string\"?props.style.filter:\"\";return /*#__PURE__*/_jsx(Component,{ref:ref,...props,style:{...props.style,filter:theme===\"dark\"?`${existingFilter?`${existingFilter} `:\"\"}invert(1)`:existingFilter||undefined}});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withSingleToggle\":{\"type\":\"reactHoc\",\"name\":\"withSingleToggle\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"ThemeAwareIcon\":{\"type\":\"reactHoc\",\"name\":\"ThemeAwareIcon\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Theme_switcher.map"],"mappings":"wNAA8E,SAAgB,EAAY,EAAO,CACjH,IAA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