{"version":3,"file":"ColorTransitionBox.DMTAOCIy.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/LiwO5uAHW5ZnaLIKchXG/jHhegxxXc1tt3fcfGir8/ColorTransitionBox.js"],"sourcesContent":["// Rectangle that changes color based on scroll position (Y position in viewport)\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useState,useRef,startTransition}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * @framerIntrinsicWidth 480\n * @framerIntrinsicHeight 480\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */export default function ColorTransitionBox(props){const{defaultColor,accentColor,triggerY,stickyRange,clipContent,colorEasing,colorDuration,style,children}=props;const[currentColor,setCurrentColor]=useState(defaultColor);const elementRef=useRef(null);const previousColorRef=useRef(defaultColor);const[transition,setTransition]=useState(`background-color 0s ease`);useEffect(()=>{if(typeof window===\"undefined\"){return;}const handleScroll=()=>{if(!elementRef.current)return;const rect=elementRef.current.getBoundingClientRect();const elementY=rect.top;// Accent color when between (triggerY - stickyRange) and triggerY\nconst lowerBound=triggerY-stickyRange;const upperBound=triggerY;const newColor=elementY>=lowerBound&&elementY<=upperBound?accentColor:defaultColor;// Determine transition based on color change direction\nif(newColor!==previousColorRef.current){if(previousColorRef.current===accentColor&&newColor===defaultColor){// Moving from accent to default: apply easing and duration\nstartTransition(()=>setTransition(`background-color ${colorDuration}s ${colorEasing}`));}else{// Moving from default to accent: instant\nstartTransition(()=>setTransition(`background-color 0s ease`));}previousColorRef.current=newColor;}startTransition(()=>setCurrentColor(newColor));};handleScroll();// Find all scrollable parents\nconst scrollableParents=[window];let parent=elementRef.current?.parentElement;while(parent){const overflowY=window.getComputedStyle(parent).overflowY;if(overflowY===\"auto\"||overflowY===\"scroll\"){scrollableParents.push(parent);}parent=parent.parentElement;}scrollableParents.forEach(el=>{el.addEventListener(\"scroll\",handleScroll,{passive:true});});window.addEventListener(\"resize\",handleScroll);return()=>{scrollableParents.forEach(el=>{el.removeEventListener(\"scroll\",handleScroll);});window.removeEventListener(\"resize\",handleScroll);};},[defaultColor,accentColor,triggerY,stickyRange,colorEasing,colorDuration]);return /*#__PURE__*/_jsx(\"div\",{ref:elementRef,style:{...style,width:style?.width||\"100%\",height:style?.height||\"100%\",backgroundColor:currentColor,transition:transition,position:\"relative\",overflow:clipContent?\"hidden\":\"visible\"},children:children});}addPropertyControls(ColorTransitionBox,{defaultColor:{type:ControlType.Color,title:\"Default Color\",defaultValue:\"#EEEEEE\"},accentColor:{type:ControlType.Color,title:\"Accent Color\",defaultValue:\"#000000\"},triggerY:{type:ControlType.Number,title:\"Trigger Y Position\",defaultValue:300,min:0,max:2e3,step:10,unit:\"px\"},stickyRange:{type:ControlType.Number,title:\"Sticky Range\",defaultValue:100,min:0,max:1e3,step:10,unit:\"px\"},clipContent:{type:ControlType.Boolean,title:\"Clip Content\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},colorEasing:{type:ControlType.Enum,title:\"Color Easing\",defaultValue:\"ease\",options:[\"linear\",\"ease\",\"ease-in\",\"ease-out\",\"ease-in-out\"],optionTitles:[\"Linear\",\"Ease\",\"Ease In\",\"Ease Out\",\"Ease In-Out\"]},colorDuration:{type:ControlType.Number,title:\"Color Duration\",defaultValue:.3,min:0,max:5,step:.1,unit:\"s\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ColorTransitionBox\",\"slots\":[\"children\"],\"annotations\":{\"framerIntrinsicWidth\":\"480\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerIntrinsicHeight\":\"480\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ColorTransitionBox.map"],"mappings":"6MAMG,SAAwB,EAAmB,EAAM,CAAC,GAAK,CAAC,eAAa,cAAY,WAAS,cAAY,cAAY,cAAY,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