{"version":3,"file":"ScrollColor.CuPyochj.mjs","names":["useRef","useCallback","__esmMin","init_ssg_sandbox_shims","ne","window","de","c","J","init_npm_react_18_3_1","ce","ramp","t","value","from","to","colorAmount","r","el","vh","top","bottom","comingIn","IN_START","IN_FULL","stillIn","OUT_FULL","OUT_START","setFilter","filter","update","on","enabled","members","color","GRAY_AMOUNT","schedule","raf","startListening","listening","stopListening","add","remove","forwardTo","ref","node","withScrollColor","current","outer","setRefs","Component","props","init_ScrollColor","init_jsx_runtime"],"sources":["https:/framerusercontent.com/modules/e89F3Vyk79pf5PtaJM6A/pKot8HonuHBJRc15L10C/ScrollColor.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useCallback,useEffect,useRef}from\"react\";/**\n * ScrollColor (GAMPworks): gray -> color driven by the scroll itself\n *\n * No timers: the amount of color follows the scroll position exactly.\n *  - A project coming up from the bottom is gray. Once it has come up a third\n *    of the screen it starts turning to color, and it's full color when its\n *    top reaches the top third of the screen.\n *  - Keep scrolling down: as it leaves at the top it turns back to gray,\n *    while the next one coming up turns to color the same way.\n *  - Scroll back up and everything plays in reverse.\n *\n * HOW TO USE (pick ONE, not both):\n *  - withScrollColor      -> on \"Project\" (the item INSIDE the Collection List)\n *  - withScrollColorList  -> on \"Projects\" (the Collection List itself)\n * Check it in Preview or on the published site. Overrides don't run on the canvas.\n *\n * Positions are measured from the top of the screen: 0 = top, 1 = bottom.\n */// Settings\nconst IN_START=.6// starts turning to color (2/5 up the screen)\n;const IN_FULL=.25// full color\n;const OUT_START=.67// leaving at the top: the project's BOTTOM edge here -> starts turning gray\n;const OUT_FULL=.33// leaving at the top: the project's BOTTOM edge here -> fully gray\n;const GRAY_AMOUNT=100// % gray when fully gray\n;const PHONE_ONLY=false// true = only on phones, desktop and tablet stay in color\n;const PHONE_MAX_WIDTH=809// px, Framer's phone breakpoint\n;// ---------- shared engine ----------\nconst members=new Set;let raf=0;let listening=false;const enabled=()=>!PHONE_ONLY||window.matchMedia(`(max-width: ${PHONE_MAX_WIDTH}px)`).matches;// 0 at `from`, 1 at `to`, eased in between\nfunction ramp(value,from,to){let t=(value-from)/(to-from);t=Math.min(1,Math.max(0,t));return t*t*(3-2*t);}function colorAmount(el){const r=el.getBoundingClientRect();if(r.height<=0||r.width<=0)return null// hidden (other breakpoint)\n;const vh=window.innerHeight;const top=r.top/vh;const bottom=r.bottom/vh;const comingIn=ramp(top,IN_START,IN_FULL)// 0 low on screen -> 1 high up\n;const stillIn=ramp(bottom,OUT_FULL,OUT_START)// 1 normally -> 0 as it leaves at the top\n;return Math.min(comingIn,stillIn);}function setFilter(el,filter){if(el.style.filter===filter)return;el.style.filter=filter;el.style.setProperty(\"-webkit-filter\",filter);}function update(){raf=0;const on=enabled();members.forEach(el=>{if(!el.isConnected)return;if(!on)return setFilter(el,\"\");const color=colorAmount(el);if(color===null)return;const gray=Math.round((1-color)*GRAY_AMOUNT*10)/10;setFilter(el,`grayscale(${gray}%)`);});}function schedule(){if(!raf)raf=requestAnimationFrame(update);}function startListening(){if(listening)return;listening=true;window.addEventListener(\"scroll\",schedule,{passive:true,capture:true});window.addEventListener(\"resize\",schedule);window.addEventListener(\"orientationchange\",schedule);}function stopListening(){if(!listening||members.size)return;listening=false;window.removeEventListener(\"scroll\",schedule,true);window.removeEventListener(\"resize\",schedule);window.removeEventListener(\"orientationchange\",schedule);}function add(el){if(members.has(el))return;members.add(el);startListening();schedule();}function remove(el){if(!members.delete(el))return;setFilter(el,\"\");stopListening();}function forwardTo(ref,node){if(typeof ref===\"function\")ref(node);else if(ref)ref.current=node;}// ---------- on \"Project\" (each item inside the Collection List) ----------\nexport function withScrollColor(Component){return /*#__PURE__*/forwardRef(function ScrollColor(props,ref){const current=useRef(null);const outer=useRef(ref);outer.current=ref;// Follows the actual layer on the page, even if Framer swaps it.\nconst setRefs=useCallback(node=>{if(current.current&&current.current!==node)remove(current.current);current.current=node;if(node)add(node);forwardTo(outer.current,node);},[]);useEffect(()=>()=>{if(current.current)remove(current.current);},[]);return /*#__PURE__*/_jsx(Component,{...props,ref:setRefs});});}// ---------- on \"Projects\" (the Collection List that holds them all) ----------\nexport function withScrollColorList(Component){return /*#__PURE__*/forwardRef(function ScrollColorList(props,ref){const local=useRef(null);const outer=useRef(ref);outer.current=ref;const setRefs=useCallback(node=>{local.current=node;forwardTo(outer.current,node);},[]);useEffect(()=>{const box=local.current;if(!box)return;let items=[];// The projects are the list's children. Step down through any\n// single wrapper layer the Collection List adds.\nconst collect=()=>{let level=box;while(level.children.length===1&&level.firstElementChild)level=level.firstElementChild;const next=Array.from(level.children).filter(c=>c instanceof HTMLElement);items.forEach(el=>!next.includes(el)&&remove(el));next.forEach(add);items=next;};collect();const mo=new MutationObserver(collect);mo.observe(box,{childList:true,subtree:true});return()=>{mo.disconnect();items.forEach(remove);};},[]);return /*#__PURE__*/_jsx(Component,{...props,ref:setRefs});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withScrollColorList\":{\"type\":\"reactHoc\",\"name\":\"withScrollColorList\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withScrollColor\":{\"type\":\"reactHoc\",\"name\":\"withScrollColor\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollColor.map"],"mappings":"A,gJA2BA,SAASW,EAAK,EAAM,EAAK,EAAG,CAAC,IAAIC,GAAGC,EAAMC,IAAOC,EAAGD,GAAkC,MAA5B,GAAE,KAAK,IAAI,EAAE,KAAK,IAAI,EAAEF,CAAC,CAAC,EAASA,EAAEA,GAAG,EAAE,EAAEA,EAAG,CAAC,SAASI,EAAY,EAAG,CAAC,IAAMC,EAAEC,EAAG,sBAAsB,EAAE,GAAGD,EAAE,QAAQ,GAAGA,EAAE,OAAO,EAAE,OAAO,KACvM,IAAME,EAAGd,EAAO,YAAkBe,EAAIH,EAAE,IAAIE,EAASE,EAAOJ,EAAE,OAAOE,EAASG,EAASX,EAAKS,EAAIG,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