{"version":3,"file":"LoopPlay.RlCGb7At.mjs","names":["useState","useRef","__esmMin","init_ssg_sandbox_shims","init_npm_react_18_3_1","_e","ce","de","window","init_framer_BpuvUAiZ","ControlType","useLoop","options","phase","setPhase","cycle","setCycle","seen","setSeen","observing","setObserving","plays","away","setAway","beginRef","begin","loopsRef","loops","on","el","ref","io","e","entries","view","fill","amount","THRESHOLDS","visible","timer","after","run","ms","playMs","holdMs","cap","fadeMs","c","loopControls","what","p","readLoop","n","props","init_LoopPlay","i"],"sources":["https:/framerusercontent.com/modules/quoiQWnZSFV7x2C41dRW/Q1c1eweezFUx9ncqCEgi/LoopPlay.js"],"sourcesContent":["import{ControlType}from\"framer\";import{useEffect,useRef,useState}from\"react\";const THRESHOLDS=Array.from({length:21},(_,i)=>i/20);export function useLoop(ref,options){const{on,playMs,loops=3,holdMs=1e3,fadeMs=300,amount=.35,begin=\"play\"}=options;const[phase,setPhase]=useState(\"wait\");const[cycle,setCycle]=useState(0);const[seen,setSeen]=useState(\"out\");const[observing,setObserving]=useState(false);const plays=useRef(0);const[away,setAway]=useState(false);const beginRef=useRef(begin);beginRef.current=begin;const loopsRef=useRef(loops);loopsRef.current=loops;// Watch the element: \"in\" once enough of it shows, \"out\" once none of it does, \"some\" in between.\nuseEffect(()=>{if(!on)return;const el=ref.current;if(!el||typeof window===\"undefined\"||typeof IntersectionObserver===\"undefined\")return;const io=new IntersectionObserver(entries=>{const e=entries[entries.length-1];if(!e)return;if(!e.isIntersecting)return setSeen(\"out\");const view=e.rootBounds&&e.rootBounds.height||window.innerHeight||1;const fill=Math.max(e.intersectionRatio,e.intersectionRect.height/view);setSeen(fill>=Math.min(.99,Math.max(.01,amount))?\"in\":\"some\");},{threshold:THRESHOLDS});io.observe(el);setObserving(true);return()=>{io.disconnect();setObserving(false);};},[on,amount,ref]);// Loop switched off (or not yet on): start clean next time.\nuseEffect(()=>{if(on)return;plays.current=0;setAway(false);setPhase(\"wait\");setSeen(\"out\");},[on]);// Entering and leaving the view.\nuseEffect(()=>{if(!on||!observing)return;if(seen===\"out\"){// Gone: wind back to the start out of sight, and wait there.\nif(phase!==\"wait\"&&!away){setAway(true);setPhase(\"reset\");}return;}if(seen!==\"in\")return;if(phase===\"wait\"){plays.current=1;setPhase(beginRef.current);return;}if(away){// Back in view: play again from the start, with a fresh count (the reset's timer runs once away is false).\nsetAway(false);plays.current=0;}},[on,observing,seen,phase,away]);// The clock: one timer per phase, none while the element is off screen, and none after a return until it is in view.\nconst visible=seen!==\"out\";useEffect(()=>{if(!on||!observing||!visible||away||typeof window===\"undefined\")return;let timer=0;const after=(ms,run)=>{timer=window.setTimeout(run,Math.max(0,ms));};if(phase===\"play\")after(playMs,()=>setPhase(\"hold\"));else if(phase===\"hold\"){after(holdMs,()=>{const cap=loopsRef.current;setPhase(cap>0&&plays.current>=cap?\"rest\":\"reset\");});}else if(phase===\"reset\"){after(fadeMs,()=>{plays.current+=1;setCycle(c=>c+1);setPhase(\"play\");});}return()=>window.clearTimeout(timer);},[on,observing,visible,away,phase,cycle,playMs,holdMs,fadeMs]);return{phase:on&&observing?phase:\"off\",cycle,fadeMs};}/** The two flat controls every looping component adds: Loop (default on) and Loops (default 3). */export function loopControls(what=\"The sequence\"){return{loop:{type:ControlType.Boolean,title:\"Loop\",defaultValue:true,description:`${what} holds its end state for a second, fades back and plays again while it is on screen. Off: it plays once, as before.`},loops:{type:ControlType.Number,title:\"Loops\",defaultValue:3,min:1,max:10,step:1,displayStepper:true,description:\"Plays before it rests on its end state (the first play included). It starts again when the section comes back into view.\",hidden:p=>p.loop===false}};}/** Reads the two controls with their defaults (an instance placed before section 23 has neither prop). */export function readLoop(props){const n=Math.round(Number(props.loops));return{loop:props.loop!==false,loops:Number.isFinite(n)&&n>=1?Math.min(10,n):3};}\nexport const __FramerMetadata__ = {\"exports\":{\"LoopOptions\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"useLoop\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"LoopState\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"readLoop\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"loopControls\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"LoopPhase\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./LoopPlay.map"],"mappings":"A,iLAAkI,SAAgBW,EAAQ,EAAI,EAAQ,CAAC,GAAK,CAAC,KAAG,SAAO,QAAM,EAAE,SAAO,IAAI,SAAO,IAAI,SAAO,IAAI,QAAM,QAAQC,EAAa,CAACC,EAAMC,GAAUd,EAAS,MAAM,EAAO,CAACe,EAAMC,GAAUhB,EAAS,CAAC,EAAO,CAACiB,EAAKC,GAASlB,EAAS,KAAK,EAAO,CAACmB,EAAUC,GAAcpB,EAAS,EAAK,EAAQqB,EAAMpB,EAAO,CAAC,EAAO,CAACqB,EAAKC,GAASvB,EAAS,EAAK,EAAQwB,EAASvB,EAAOwB,CAAK,EAAE,EAAS,QAAQA,EAAM,IAAMC,EAASzB,EAAO0B,CAAK,EAAE,EAAS,QAAQA,EAC7iBrB,MAAc,CAAC,GAAG,CAACsB,EAAG,OAAO,IAAMC,EAAGC,EAAI,QAAQ,GAAG,CAACD,GAAWrB,IAAS,QAAa,OAAO,qBAAuB,IAAY,OAAO,IAAMuB,EAAG,IAAI,qBAAqB,GAAS,CAAC,IAAMC,EAAEC,EAAQA,EAAQ,OAAO,GAAG,GAAG,CAACD,EAAE,OAAO,GAAG,CAACA,EAAE,eAAe,OAAOd,EAAQ,KAAK,EAAE,IAAMgB,EAAKF,EAAE,YAAYA,EAAE,WAAW,QAAQxB,EAAO,aAAa,EAAQ2B,EAAK,KAAK,IAAIH,EAAE,kBAAkBA,EAAE,iBAAiB,OAAOE,CAAI,EAAEhB,EAAQiB,GAAM,KAAK,IAAI,IAAI,KAAK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