{"version":3,"file":"AlternatingCoverColors.DPMTFP_r.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/F5HxW4pNcRKTsVMs3jTI/ZsUiGNSbZiR4kku36xm1/AlternatingCoverColors.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useEffect,useRef}from\"react\";import{addPropertyControls,ControlType}from\"framer\";function isVisibleElement(element){const style=window.getComputedStyle(element);if(style.display===\"none\"||style.visibility===\"hidden\"||Number(style.opacity)===0)return false;const rect=element.getBoundingClientRect();return rect.width>0&&rect.height>0;}function chooseCoverElement(card,selector){if(selector.trim().length>0){const selected=card.querySelector(selector);if(selected instanceof HTMLElement)return selected;}const candidates=Array.from(card.querySelectorAll(\"img, [style*='background-image'], [data-cover], [class*='cover'], [class*='image']\")).filter(node=>node instanceof HTMLElement);if(candidates.length===0){const first=card.firstElementChild;return first instanceof HTMLElement?first:card;}const cardRect=card.getBoundingClientRect();let best=null;let bestScore=-Infinity;for(const candidate of candidates){const rect=candidate.getBoundingClientRect();if(rect.width===0||rect.height===0)continue;const area=rect.width*rect.height;const topDistance=Math.max(0,rect.top-cardRect.top);const score=area-topDistance*500;if(score>bestScore){bestScore=score;best=candidate;}}return best;}function patternValue(index,pattern){if(pattern===\"TwoDarkOneLight\"){return index%3===2?0:1;}return index%2;}function colorFor(index,pattern,lightColor,darkColor){const value=patternValue(index,pattern);return value===0?lightColor:darkColor;}export function withAlternatingCoverColors(Component){const Wrapped=/*#__PURE__*/forwardRef(function WithAlternatingCoverColors(props,ref){const{pattern=\"Alternate\",lightColor=\"#eaf7cf\",darkColor=\"#0b2e12\",coverSelector=\"[data-cover], .cover, img, [style*='background-image']\"}=props;const rootRef=useRef(null);useEffect(()=>{if(typeof window===\"undefined\")return;const getRoot=()=>{if(rootRef.current)return rootRef.current;const maybe=ref?.current;if(maybe instanceof HTMLElement)return maybe;return null;};let rafId=0;let paintScheduled=false;const paint=()=>{const root=getRoot();if(!root)return;const cards=Array.from(root.children).filter(node=>node instanceof HTMLElement);const visibleCards=cards.filter(card=>isVisibleElement(card));visibleCards.forEach((card,index)=>{const cover=chooseCoverElement(card,coverSelector);if(!cover)return;const color=colorFor(index,pattern,lightColor,darkColor);if(cover.style.getPropertyValue(\"--cover-tone\")!==color){cover.style.setProperty(\"--cover-tone\",color);}if(cover.style.background!==color){cover.style.background=color;}if(cover.style.backgroundImage!==\"none\"){cover.style.backgroundImage=\"none\";}if(cover.style.backgroundColor!==color){cover.style.backgroundColor=color;}});};const schedulePaint=()=>{if(paintScheduled)return;paintScheduled=true;rafId=window.requestAnimationFrame(()=>{paintScheduled=false;paint();});};schedulePaint();const root=getRoot();if(!root)return;const mutationObserver=new MutationObserver(()=>schedulePaint());mutationObserver.observe(root,{childList:true,subtree:true,attributes:true,attributeFilter:[\"style\",\"class\",\"hidden\",\"aria-hidden\"]});const resizeObserver=new ResizeObserver(()=>schedulePaint());resizeObserver.observe(root);return()=>{mutationObserver.disconnect();resizeObserver.disconnect();if(rafId){window.cancelAnimationFrame(rafId);}};},[coverSelector,darkColor,lightColor,pattern,ref]);return /*#__PURE__*/_jsx(Component,{ref:node=>{if(node instanceof HTMLElement){rootRef.current=node;}else{rootRef.current=null;}if(typeof ref===\"function\")ref(node);else if(ref&&typeof ref===\"object\")ref.current=node;},...props,style:{...props.style}});});addPropertyControls(Wrapped,{pattern:{type:ControlType.Enum,title:\"Pattern\",options:[\"Alternate\",\"TwoDarkOneLight\"],optionTitles:[\"Alternate\",\"Two Dark / One Light\"],defaultValue:\"Alternate\",displaySegmentedControl:true},lightColor:{type:ControlType.Color,title:\"Light\",defaultValue:\"#eaf7cf\"},darkColor:{type:ControlType.Color,title:\"Dark\",defaultValue:\"#0b2e12\"},coverSelector:{type:ControlType.String,title:\"Cover Selector\",defaultValue:\"[data-cover], .cover, img, [style*='background-image']\"}});return Wrapped;}\nexport const __FramerMetadata__ = {\"exports\":{\"withAlternatingCoverColors\":{\"type\":\"reactHoc\",\"name\":\"withAlternating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