{"version":3,"file":"ThemeVariants.DY5RM5Az.mjs","names":["useState","_Fragment"],"sources":["https:/framerusercontent.com/modules/x1C06LhciZkPwlrHaUFg/P376Mm6phGkB4SP2NiMg/ThemeVariants.js"],"sourcesContent":["import{jsx as _jsx,Fragment as _Fragment}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useState,useLayoutEffect,useEffect,cloneElement}from\"react\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n */export default function ThemeVariants(props){const[isDarkTheme,setIsDarkTheme]=useState(null);// Helpers are defined once so both effects can use them\nconst getAttrTheme=()=>{if(typeof document===\"undefined\")return null;const html=document.documentElement;const body=document.body;if(!body||!html)return null;// Check supersonicart-theme on <html> first (your new requirement)\nconst htmlAttr=html.getAttribute(\"supersonicart-theme\");if(htmlAttr===\"dark\")return true;if(htmlAttr===\"light\")return false;// Fallback: check body attributes (existing logic)\nconst attr=body.getAttribute(\"toggle-theme\")??body.getAttribute(\"toggle-them\");if(attr===\"dark\")return true;if(attr===\"light\")return false;return null;};const getStoredTheme=()=>{if(typeof window===\"undefined\")return null;const v=(localStorage.getItem(\"currentToggleState\")||\"\").toLowerCase();if(v===\"dark\")return true;if(v===\"light\")return false;return null;};const getSystemPref=()=>{if(typeof window===\"undefined\"||!window.matchMedia)return null;return window.matchMedia(\"(prefers-color-scheme: dark)\").matches;};const computeTheme=()=>{// Priority: <html supersonicart-theme> → <body toggle-theme> → stored → system\nconst fromAttr=getAttrTheme();if(fromAttr!==null)return fromAttr;const stored=getStoredTheme();if(stored!==null)return stored;const sys=getSystemPref();return sys??false// final fallback = light\n;};// Do the very first calculation before paint to avoid flashes\nuseLayoutEffect(()=>{setIsDarkTheme(computeTheme());},[]);// Subscribe to changes (OS, attribute, custom event, storage)\nuseEffect(()=>{if(typeof window===\"undefined\")return;const mq=window.matchMedia?window.matchMedia(\"(prefers-color-scheme: dark)\"):null;const updateIfNoExplicitOverride=()=>{const hasExplicit=getAttrTheme()!==null||getStoredTheme()!==null;if(!hasExplicit)setIsDarkTheme(getSystemPref()??false);};const onOsThemeChange=()=>updateIfNoExplicitOverride();const onThemeChangeEvent=()=>{// Someone in your app toggled theme; recompute with priority rules\nsetIsDarkTheme(computeTheme());};const onStorage=e=>{if(e.key===\"currentToggleState\")setIsDarkTheme(computeTheme());};// Observe both <html> and <body> for theme attribute changes\nconst attrObserver=typeof MutationObserver!==\"undefined\"?new MutationObserver(muts=>{for(const m of muts){if(m.type===\"attributes\"&&(m.attributeName===\"supersonicart-theme\"||m.attributeName===\"toggle-theme\"||m.attributeName===\"toggle-them\")){setIsDarkTheme(computeTheme());break;}}}):null;window.addEventListener(\"themeChange\",onThemeChangeEvent);window.addEventListener(\"storage\",onStorage);if(mq){if(mq.addEventListener)mq.addEventListener(\"change\",onOsThemeChange);else mq.addListener(onOsThemeChange);}if(attrObserver){if(document.documentElement)attrObserver.observe(document.documentElement,{attributes:true,attributeFilter:[\"supersonicart-theme\"]});if(document.body)attrObserver.observe(document.body,{attributes:true,attributeFilter:[\"toggle-theme\",\"toggle-them\"]});}return()=>{window.removeEventListener(\"themeChange\",onThemeChangeEvent);window.removeEventListener(\"storage\",onStorage);if(mq){if(mq.removeEventListener)mq.removeEventListener(\"change\",onOsThemeChange);else mq.removeListener(onOsThemeChange);}attrObserver?.disconnect();};},[]);// Prevent render until we know the theme (no flash)\nif(isDarkTheme===null)return null;// Support both a single element and an array defensively\nconst getFirst=v=>Array.isArray(v)?v[0]:v;let lightEl=getFirst(props.light);let darkEl=getFirst(props.dark);// Pass container width/height down if provided\nconst maybeClone=el=>{if(!el)return el;if(props.style?.width||props.style?.height){return /*#__PURE__*/cloneElement(el,{style:{...el.props?.style,...props.style}});}return el;};lightEl=maybeClone(lightEl);darkEl=maybeClone(darkEl);const themeEl=isDarkTheme?darkEl:lightEl;return themeEl?/*#__PURE__*/_jsx(_Fragment,{children:themeEl}):/*#__PURE__*/_jsx(\"div\",{style:{minWidth:100,minHeight:100}});}ThemeVariants.displayName=\"Theme Variants\";addPropertyControls(ThemeVariants,{light:{type:ControlType.ComponentInstance,title:\"Light\"},dark:{type:ControlType.ComponentInstance,title:\"Dark\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ThemeVariants\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ThemeVariants.map"],"mappings":"oNAGG,SAAwB,EAAc,EAAM,CAAC,GAAK,CAAC,EAAY,GAAgBA,EAAS,KAAK,CAC1F,MAAiB,CAAC,GAAG,OAAO,SAAW,IAAY,OAAO,KAAK,IAAM,EAAK,SAAS,gBAAsB,EAAK,SAAS,KAAK,GAAG,CAAC,GAAM,CAAC,EAAK,OAAO,KACzJ,IAAM,EAAS,EAAK,aAAa,sBAAsB,CAAC,GAAG,IAAW,OAAO,MAAO,GAAK,GAAG,IAAW,QAAQ,MAAO,GACtH,IAAM,EAAK,EAAK,aAAa,eAAe,EAAE,EAAK,aAAa,cAAc,CAA6D,OAAzD,IAAO,OAAc,GAAQ,IAAO,QAAe,GAAa,MAAa,MAAmB,CAAC,GAAU,IAAS,OAAY,OAAO,KAAK,IAAM,GAAG,aAAa,QAAQ,qBAAqB,EAAE,IAAI,aAAa,CAAuD,OAAnD,IAAI,OAAc,GAAQ,IAAI,QAAe,GAAa,MAAa,MAA6B,IAAS,QAAa,CAAC,EAAO,WAAkB,KAAY,EAAO,WAAW,+BAA+B,CAAC,QAAgB,MAAiB,CAC3hB,IAAM,EAAS,GAAc,CAAC,GAAG,IAAW,KAAK,OAAO,EAAS,IAAM,EAAO,GAAgB,CAA0D,OAAtD,IAAS,KAA6B,GAAe,EAAa,GAA7C,GAMvH,GAJA,MAAoB,CAAC,EAAe,GAAc,CAAC,EAAG,EAAE,CAAC,CACzD,MAAc,CAAC,GAAU,IA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