{"version":3,"file":"ThemeVariants.CVdyKyPL.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,IAAI,EACzF,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,qBAAqB,EAAE,GAAG,IAAW,OAAO,MAAO,GAAK,GAAG,IAAW,QAAQ,MAAO,GACtH,IAAM,EAAK,EAAK,aAAa,cAAc,GAAG,EAAK,aAAa,aAAa,EAA8D,OAAzD,IAAO,QAAsB,IAAO,SAA4B,IAAK,EAAQ,MAAmB,CAAC,GAAU,IAAS,OAAY,OAAO,KAAK,IAAM,GAAG,aAAa,QAAQ,oBAAoB,GAAG,GAAA,CAAI,YAAY,EAAwD,OAAnD,IAAI,QAAsB,IAAI,SAA4B,IAAK,EAAQ,MAA6B,IAAS,QAAa,CAAC,EAAO,WAAkB,KAAY,EAAO,WAAW,8BAA8B,CAAC,CAAC,QAAgB,MAAiB,CAC3hB,IAAM,EAAS,EAAa,EAAE,GAAG,IAAW,KAAK,OAAO,EAAS,IAAM,EAAO,EAAe,EAA2D,OAAtD,IAAS,KAA6B,EAAyB,GAAG,GAA7C,CACtH,EAKD,GAJA,MAAoB,CAAC,EAAe,EAAa,CAAC,CAAE,EAAE,CAAC,CAAC,EACxD,MAAc,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