{"version":3,"file":"ModalTrigger.ChGi_bRp.mjs","names":["useState","useRef","useCallback"],"sources":["https:/framerusercontent.com/modules/1WkTQm6zZV6gvy3c0e7u/ZR0HCVLK7uDx5zO6FomS/ModalTrigger.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useState,useCallback,useEffect,useRef}from\"react\";import{addPropertyControls,ControlType}from\"framer\";// Framer's tracking\nimport{useTracking}from\"framer\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n *\n * Popup trigger: multiple triggers, unique modal key, analytics, and remember dismissal for X days.\n */export default function ModalTriggerV5({showOnMouseLeave,delayConfig,scrollConfig,persistenceConfig,onPopupOpen,onPopupDismiss}){const modalKey=persistenceConfig?.modalKey||\"default\";const dismissKey=`modalDismissExpiration--${modalKey}`;// Framer's custom event tracking\nconst{track}=useTracking();const[hasBeenTriggered,setHasBeenTriggered]=useState(false);const triggerRef=useRef(null);const triggeredRef=useRef(false);// On mount: check if user already dismissed\nuseEffect(()=>{if(!persistenceConfig?.persistDismissal)return;const expiration=localStorage.getItem(dismissKey);if(expiration&&Date.now()<Number(expiration)){setHasBeenTriggered(true);triggeredRef.current=true;if(typeof onPopupDismiss===\"function\")onPopupDismiss(true);if(typeof track===\"function\")track(`${modalKey}-popup-dismissed`);}},[persistenceConfig?.persistDismissal,dismissKey,onPopupDismiss,modalKey,track]);// Set as dismissed and remember if desired\nconst setDismissed=useCallback(()=>{setHasBeenTriggered(true);triggeredRef.current=true;if(persistenceConfig?.persistDismissal){const expirationTime=Date.now()+(persistenceConfig.dismissDays||1)*864e5;localStorage.setItem(dismissKey,expirationTime.toString());}if(typeof onPopupDismiss===\"function\")onPopupDismiss(true);if(typeof track===\"function\")track(`${modalKey}-popup-dismissed`);},[persistenceConfig,dismissKey,onPopupDismiss,modalKey,track]);// Fire the modal one time\nconst showModal=useCallback(()=>{if(triggeredRef.current)return;simulateModalClick(triggerRef.current);setHasBeenTriggered(true);triggeredRef.current=true;if(typeof track===\"function\")track(`${modalKey}-popup-opened`);if(typeof onPopupOpen===\"function\")onPopupOpen(true);},[onPopupOpen,modalKey,track]);// Mouse leave (exit intent)\nuseEffect(()=>{if(!showOnMouseLeave||hasBeenTriggered)return;const handler=e=>{if(e.clientY<=0||e.clientX<=0||e.clientX>=window.innerWidth||e.clientY>=window.innerHeight){showModal();}};window.addEventListener(\"mouseout\",handler);return()=>window.removeEventListener(\"mouseout\",handler);},[showOnMouseLeave,showModal,hasBeenTriggered]);// Delay trigger\nuseEffect(()=>{if(!delayConfig?.showOnDelay||hasBeenTriggered)return;const timer=setTimeout(()=>showModal(),delayConfig.delaySeconds*1e3);return()=>clearTimeout(timer);},[delayConfig?.showOnDelay,delayConfig?.delaySeconds,showModal,hasBeenTriggered]);// Scroll trigger\nuseEffect(()=>{if(!scrollConfig?.showOnScrollToPercentage||hasBeenTriggered)return;const body=document.body;const triggerPoint=body.scrollHeight*(scrollConfig.scrollPercentage||0)/100;const startY=window.scrollY+window.innerHeight;const handler=()=>{const y=window.scrollY+window.innerHeight;if(y>=triggerPoint&&startY<triggerPoint){showModal();}};window.addEventListener(\"scroll\",handler);return()=>window.removeEventListener(\"scroll\",handler);},[scrollConfig?.showOnScrollToPercentage,scrollConfig?.scrollPercentage,showModal,hasBeenTriggered]);// If they close via related modal button: set dismissal\nuseEffect(()=>{const triggerNode=triggerRef.current;const button=triggerNode?triggerNode.parentElement?.parentElement:null;if(!button)return;const prevent=()=>setDismissed();button.addEventListener(\"keyup\",prevent);button.addEventListener(\"mouseup\",prevent);return()=>{button.removeEventListener(\"keyup\",prevent);button.removeEventListener(\"mouseup\",prevent);};},[setDismissed]);// The hidden trigger node\nreturn /*#__PURE__*/_jsx(\"div\",{ref:triggerRef,\"aria-hidden\":\"true\",style:{position:\"absolute\",width:0,height:0}});}// Framer DOM \"simulate click\"\nfunction simulateModalClick(node){if(node&&node.parentElement&&node.parentElement.parentElement){const btn=node.parentElement.parentElement;btn.dispatchEvent(new FocusEvent(\"focus\"));btn.dispatchEvent(new KeyboardEvent(\"keydown\",{key:\"Enter\"}));btn.dispatchEvent(new KeyboardEvent(\"keyup\",{key:\"Enter\"}));}}// Property controls with persistence and tracking\naddPropertyControls(ModalTriggerV5,{showOnMouseLeave:{type:ControlType.Boolean,title:\"MouseLeave\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},delayConfig:{type:ControlType.Object,title:\"Delay\",buttonTitle:\"Configure\",controls:{showOnDelay:{type:ControlType.Boolean,title:\"Trigger\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},delaySeconds:{type:ControlType.Number,title:\"Seconds\",defaultValue:10,min:0,max:300,step:5,displayStepper:true,unit:\" s\"}}},scrollConfig:{type:ControlType.Object,title:\"Scroll\",buttonTitle:\"Configure\",controls:{showOnScrollToPercentage:{type:ControlType.Boolean,title:\"Trigger\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},scrollPercentage:{type:ControlType.Number,title:\"Scroll %\",defaultValue:50,min:0,max:100,step:1,displayStepper:true,unit:\" %\"}}},persistenceConfig:{type:ControlType.Object,title:\"Persistence\",buttonTitle:\"Configure\",controls:{persistDismissal:{type:ControlType.Boolean,title:\"Remember Close\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},dismissDays:{type:ControlType.Number,title:\"Don't Show Again (days)\",defaultValue:7,min:1,max:999,step:1,unit:\" days\"},modalKey:{type:ControlType.String,title:\"Modal Key\",defaultValue:\"default\"}}}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ModalTriggerV5\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"any\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ModalTrigger.map"],"mappings":"qNAMG,SAAwB,EAAe,CAAC,mBAAiB,cAAY,eAAa,oBAAkB,cAAY,kBAAgB,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