{"version":3,"file":"Trigger_scroll_popup.DIa7_a-e.mjs","names":[],"sources":["https:/framerusercontent.com/modules/teZ96Da2MDtdPsxQ3XLf/IK0cM5BD54M06ElN0Cyy/Trigger_scroll_popup.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useEffect}from\"react\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";// ============================\n// CONFIGURATION\n// ============================\nconst SCROLL_THRESHOLD_PERCENT=50;const SHOW_ONCE=true;const MIN_DELAY_MS=2e3;// ============================\n// STORE PARTAGÉ\n// ============================\nconst usePopupStore=createStore({isOpen:false,hasBeenShown:false,showConfirmation:false});// ============================\n// OVERRIDE 1 : TRIGGER\n// À appliquer sur le Body ou une section de la page\n// ============================\nexport const withScrollTrigger=Component=>{return /*#__PURE__*/forwardRef((props,ref)=>{const[store,setStore]=usePopupStore();useEffect(()=>{let enabled=false;const timer=setTimeout(()=>{enabled=true;},MIN_DELAY_MS);const handleScroll=()=>{if(!enabled)return;if(SHOW_ONCE&&store.hasBeenShown)return;if(store.isOpen)return;const scrollTop=window.pageYOffset||document.documentElement.scrollTop;const scrollHeight=document.documentElement.scrollHeight-window.innerHeight;if(scrollHeight<=0)return;const scrolledPercent=scrollTop/scrollHeight*100;if(scrolledPercent>=SCROLL_THRESHOLD_PERCENT){setStore({isOpen:true,hasBeenShown:true});}};window.addEventListener(\"scroll\",handleScroll,{passive:true});return()=>{clearTimeout(timer);window.removeEventListener(\"scroll\",handleScroll);};},[store.isOpen,store.hasBeenShown]);return /*#__PURE__*/_jsx(Component,{ref:ref,...props});});};// ============================\n// OVERRIDE 2 : POPUP\n// À appliquer sur le frame de ta popup\n// ============================\nexport const withScrollPopup=Component=>{return /*#__PURE__*/forwardRef((props,ref)=>{const[store,setStore]=usePopupStore();const handleOverlayClick=e=>{if(e.target===e.currentTarget){setStore({isOpen:false,showConfirmation:false});}};return /*#__PURE__*/_jsx(\"div\",{onClick:handleOverlayClick,style:{position:\"fixed\",inset:0,display:\"flex\",alignItems:\"center\",justifyContent:\"center\",backgroundColor:store.isOpen?\"rgba(0, 0, 0, 0.5)\":\"rgba(0, 0, 0, 0)\",opacity:store.isOpen?1:0,pointerEvents:store.isOpen?\"auto\":\"none\",transition:\"opacity 0.4s ease, background-color 0.4s ease\",zIndex:9999},children:/*#__PURE__*/_jsx(\"div\",{style:{transform:store.isOpen?\"translateY(0)\":\"translateY(20px)\",transition:\"transform 0.4s ease\"},children:/*#__PURE__*/_jsx(Component,{ref:ref,...props})})});});};// ============================\n// OVERRIDE 3 : BOUTON CLOSE\n// À appliquer sur ton bouton X / croix\n// ============================\nexport const withClosePopup=Component=>{return /*#__PURE__*/forwardRef((props,ref)=>{const[,setStore]=usePopupStore();return /*#__PURE__*/_jsx(Component,{ref:ref,...props,onClick:e=>{e?.stopPropagation?.();setStore({isOpen:false,showConfirmation:false});props?.onClick?.();},style:{...props?.style,cursor:\"pointer\"}});});};// ============================\n// OVERRIDE 4 : BOUTON S'INSCRIRE\n// Valide l'email, submit, puis affiche la confirmation\n// À appliquer sur le bouton \"S'inscrire à la newsletter\"\n// ============================\nexport const withSubmitAndClose=Component=>{return /*#__PURE__*/forwardRef((props,ref)=>{const[,setStore]=usePopupStore();return /*#__PURE__*/_jsx(Component,{ref:ref,...props,onClick:e=>{e?.stopPropagation?.();// Cherche l'input email dans la popup\nconst container=e.target.closest(\"[style]\");const input=container?.closest(\"form\")?.querySelector('input[type=\"email\"]')||container?.closest(\"form\")?.querySelector(\"input\")||container?.closest(\"div\")?.parentElement?.querySelector('input[type=\"email\"]')||container?.closest(\"div\")?.parentElement?.querySelector(\"input\");const email=input?.value||\"\";const isValidEmail=/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email);// Laisse le comportement natif se faire\nprops?.onClick?.(e);if(isValidEmail){// Affiche la confirmation après un court délai\nsetTimeout(()=>{setStore({showConfirmation:true});},500);// Ferme tout après 3 secondes\nsetTimeout(()=>{setStore({isOpen:false,showConfirmation:false});},3500);}// Si email invalide : rien ne se passe, popup reste ouverte\n},style:{...props?.style,cursor:\"pointer\"}});});};// ============================\n// OVERRIDE 5 : OVERLAY DE CONFIRMATION\n// À appliquer sur ton frame \"Merci\" / confirmation\n// S'affiche uniquement après un submit valide\n// ============================\nexport const withConfirmationOverlay=Component=>{return /*#__PURE__*/forwardRef((props,ref)=>{const[store]=usePopupStore();return /*#__PURE__*/_jsx(Component,{ref:ref,...props,style:{...props?.style,opacity:store.showConfirmation?1:0,pointerEvents:store.showConfirmation?\"auto\":\"none\",transition:\"opacity 0.3s ease\"}});});};\nexport const __FramerMetadata__ = {\"exports\":{\"withConfirmationOverlay\":{\"type\":\"reactHoc\",\"name\":\"withConfirmationOverlay\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withScrollPopup\":{\"type\":\"reactHoc\",\"name\":\"withScrollPopup\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withClosePopup\":{\"type\":\"reactHoc\",\"name\":\"withClosePopup\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withScrollTrigger\":{\"type\":\"reactHoc\",\"name\":\"withScrollTrigger\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withSubmitAndClose\":{\"type\":\"reactHoc\",\"name\":\"withSubmitAndClose\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Trigger_scroll_popup.map"],"mappings":"6NAA2C,IAAwC,IAAqE,CAGlJ,EAAyB,GAA8B,EAAa,IAGpE,EAAc,EAAY,CAAC,OAAO,GAAM,aAAa,GAAM,iBAAiB,GAAM,CAAC,CAI5E,EAAkB,GAAgC,GAAY,EAAM,IAAM,CAAC,GAAK,CAAC,EAAM,GAAU,GAAe,CAAorB,OAAnrB,MAAc,CAAC,IAAI,EAAQ,GAAY,EAAM,eAAe,CAAC,EAAQ,IAAO,EAAa,CAAO,MAAiB,CAA4D,GAAxD,CAAC,GAA6B,EAAM,cAAuB,EA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