{"version":3,"file":"EmailToDemoRedirectBridge.vIvpgaTe.mjs","names":["useRef","__esmMin","init_ssg_sandbox_shims","window","de","init_jsx_runtime","c","init_npm_react_18_3_1","ce","addPropertyControls","RenderTarget","init_framer_DcGZRLrs","ControlType","EmailToDemoRedirectBridge","props","bridgeRef","emailRef","redirectedRef","destinationRef","destination","redirect","url","k","v","form","onSubmit","input","CARRY_KEY","originalFetch","restored","restore","patchedFetch","FRAMER_FORMS_SUBMIT","init","request","submitted","EmailCarryOver","ref","saved","value","setter","tries","fill","timer","init_EmailToDemoRedirectBridge"],"sources":["https:/framerusercontent.com/modules/EDodkgvwS9izTRoqZyxm/4mddMgrGdtI0LPzyRjA8/EmailToDemoRedirectBridge.js"],"sourcesContent":["// Invisible bridge inside the email-only demo forms (/book-a-demo-email, /lp/meta).\n// Lets Framer submit the form normally (so the email lands in the backend),\n// remembers the email, and redirects to the wizard with ?email= prefilled.\n//\n// Speed-up: as soon as Framer's submit request has been SENT, we redirect\n// instead of waiting ~1.5s for Framer's response. The request is marked\n// `keepalive`, so the browser finishes delivering it even after the page\n// changes. If anything about that fast path fails, we fall back to the\n// original behavior (redirect when the form's onSuccess / onError fires).\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";const CARRY_KEY=\"annie_carry_email\";const FRAMER_FORMS_SUBMIT=/api\\.framer\\.com\\/forms\\/v1\\/forms\\/[^/]+\\/submit/;/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function EmailToDemoRedirectBridge(props){const{submitted=false,destination=\"/demo-practice\"}=props;const bridgeRef=useRef(null);const emailRef=useRef(\"\");const redirectedRef=useRef(false);const destinationRef=useRef(destination);destinationRef.current=destination;const redirect=()=>{if(typeof window===\"undefined\"||redirectedRef.current)return;redirectedRef.current=true;const url=new URL(destinationRef.current||\"/demo-practice\",window.location.origin);if(emailRef.current)url.searchParams.set(\"email\",emailRef.current);for(const[k,v]of new URLSearchParams(window.location.search)){if(!url.searchParams.has(k))url.searchParams.set(k,v);}window.location.assign(url.toString());};// Capture the email at submit time and arm the fast redirect.\nuseEffect(()=>{if(typeof window===\"undefined\")return;const form=bridgeRef.current?.closest(\"form\");if(!(form instanceof HTMLFormElement))return;const onSubmit=()=>{const input=form.querySelector('input[name=\"email\"]:not([type=\"hidden\"])')??form.querySelector('input[name=\"email\"]');emailRef.current=(input?.value??\"\").trim();try{if(emailRef.current)window.sessionStorage.setItem(CARRY_KEY,emailRef.current);}catch{}// Wrap fetch for this one submission only.\nconst originalFetch=window.fetch;let restored=false;const restore=()=>{if(restored)return;restored=true;if(window.fetch===patchedFetch)window.fetch=originalFetch;};const patchedFetch=function(input,init){const url=typeof input===\"string\"?input:input instanceof URL?input.href:input.url;if(!FRAMER_FORMS_SUBMIT.test(url)){return originalFetch.call(window,input,init);}restore();let request;try{request=originalFetch.call(window,input,{...init||{},keepalive:true});}catch{// keepalive not allowed for this body: use the normal path\n// and let onSuccess / onError handle the redirect.\nreturn originalFetch.call(window,input,init);}// Request is on its way: leave now.\nsetTimeout(redirect,0);return request;};window.fetch=patchedFetch;// If Framer doesn't submit (e.g. validation fails), un-patch.\nsetTimeout(restore,5e3);};form.addEventListener(\"submit\",onSubmit,true);return()=>form.removeEventListener(\"submit\",onSubmit,true);},[]);// Fallback: redirect once the form reports success / error.\nuseEffect(()=>{if(submitted)redirect();},[submitted]);return /*#__PURE__*/_jsx(\"span\",{ref:bridgeRef,\"aria-hidden\":\"true\",style:{position:\"relative\",display:\"none\",width:0,height:0,overflow:\"hidden\",...props.style}});}addPropertyControls(EmailToDemoRedirectBridge,{submitted:{type:ControlType.Boolean,title:\"Submitted\",defaultValue:false},destination:{type:ControlType.String,title:\"Destination\",defaultValue:\"/demo-practice\"}});/**\n * EmailCarryOver: place inside the wizard form. If the email field is empty\n * and the URL has no ?email=, fills it from the email saved by the email page.\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export function EmailCarryOver(props){const ref=useRef(null);useEffect(()=>{if(typeof window===\"undefined\")return;if(RenderTarget.current()===RenderTarget.canvas)return;let saved=\"\";try{saved=window.sessionStorage.getItem(CARRY_KEY)||\"\";}catch{}const fromUrl=new URLSearchParams(window.location.search).get(\"email\")||\"\";const value=fromUrl||saved;if(!value)return;const setter=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,\"value\")?.set;let tries=0;const fill=()=>{const form=ref.current?.closest(\"form\");const input=(form||document).querySelector('input[name=\"email\"]:not([type=\"hidden\"])');if(input&&!input.value){setter?.call(input,value);input.dispatchEvent(new Event(\"input\",{bubbles:true}));input.dispatchEvent(new Event(\"change\",{bubbles:true}));}};// inputs and form-persistence restore can mount late; keep the value for a few seconds\nconst timer=window.setInterval(()=>{fill();if(++tries>20)window.clearInterval(timer);},250);fill();return()=>window.clearInterval(timer);},[]);return /*#__PURE__*/_jsx(\"span\",{ref:ref,\"aria-hidden\":\"true\",style:{display:\"none\",...props.style}});}\nexport const __FramerMetadata__ = {\"exports\":{\"EmailCarryOver\":{\"type\":\"reactComponent\",\"name\":\"EmailCarryOver\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"fixed\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"fixed\"}},\"default\":{\"type\":\"reactComponent\",\"name\":\"EmailToDemoRedirectBridge\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"fixed\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./EmailToDemoRedirectBridge.map"],"mappings":"A,wMAYG,SAAwBa,EAA0B,EAAM,CAAC,GAAK,CAAC,YAAU,GAAM,cAAY,kBAAkBC,EAAYC,EAAUf,EAAO,IAAI,EAAQgB,EAAShB,EAAO,EAAE,EAAQiB,EAAcjB,EAAO,EAAK,EAAQkB,EAAelB,EAAOmB,CAAW,EAA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