!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["for-form-embed-handler"]=t():e["for-form-embed-handler"]=t()}(this,function(){return function(){"use strict";var e={};let t=["jotform.com","jotform.us","jotform.ca","jotformeu.com","jotformpro.com","jotform.me","myjotform.com","jotformz.com","jotform.co","jotform.net","jotform2.com","jotfor.ms","jot-form.com","jotformform.com","jotformforms.com","jotform.pro","jotform.com.tr","jotform.dev","jform.co.kr","formresponse.com","jotformsign.com","jotform.ooo","jotform.ai","jotform.io"];function o(e,...t){var n,r;"production"!==(null==(r=globalThis.process)||null==(n=r.env)?void 0:n.NODE_ENV)&&console.warn(e,...t)}function n(e){var t,o;let n=null!=(t=null==(o=e.data)?void 0:o.type)?t:e.data;return"string"==typeof n?n:null}function r({allowedOrigins:e,allowedSources:i,allowWildcardTargetOrigin:l=!1,mode:s="enforce",busId:a=null,debugAudit:c=null}={}){var d;let u="observe"===s?"observe":"enforce",m={enabled:(null==c?void 0:c.enabled)!=null?!!c.enabled:"observe"===u,endpoint:null!=(d=null==c?void 0:c.endpoint)?d:"/API/send-from-frontend-logs",shouldAudit:"function"==typeof(null==c?void 0:c.shouldAudit)?c.shouldAudit:null},f=new Map,w=new Set;function p(r){var l,s;let c,d,p,g,h,y=(c="function"==typeof e?e():null!=e?e:[window.location.origin],p=null==(d="function"==typeof i?i():i)?null:d.filter(e=>null!=e),!(g=Array.isArray(c)&&c.includes(r.origin))&&function(e){if(!e)return!1;let[,o]=e.trim().match(/^https?:\/\/(?:[^/?#@\s]*@)?([^/?#:\s]+)(?::[0-9]+)?(?:[/?#]|$)/i)||[],n=null==o?void 0:o.toLowerCase().replace(/\.$/,"");return!(!n||n.split(".").some(e=>!/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(e)))&&t.some(e=>n===e||n.endsWith(`.${e}`))}(r.origin)&&(g=!0),h=!0,null!=p&&(h=Array.isArray(p)&&p.some(e=>e===r.source)),{origins:c,sources:p,originAllowed:g,sourceAllowed:h,allowed:g&&h}),b=n(r);if(function(e,t,o){if(!m.enabled||t.allowed)return!1;if(m.shouldAudit)return m.shouldAudit(e,t);if("string"!=typeof o)return!1;let n=f.get(o);return!!(null==n?void 0:n.length)}(r,y,b)&&(l=m.endpoint,s=function({busId:e,event:t,validation:o}){var r,i,l,s,a,c,d,u;let m,f,w;return{title:"POST_MESSAGE_ORIGIN_SOURCE_VALIDATION_LOG",log:{busId:e,windowLocationPathname:window.location.pathname,windowLocationOrigin:window.location.origin,eventOrigin:null!=(r=t.origin)?r:null,messageType:n(t),messageAction:"string"==typeof(null==(i=t.data)?void 0:i.action)?t.data.action:null,envelopeSource:"string"==typeof(m=null!=(l=null==(s=t.data)?void 0:s.source)?l:null==(c=t.data)||null==(a=c.message)?void 0:a.source)?m:null,payloadKeys:null==(f=null==(d=t.data)?void 0:d.payload)||"object"!=typeof f||Array.isArray(f)?[]:Object.keys(f).slice(0,20),payloadSize:function(e){try{var t,o;return null!=(t=null==(o=JSON.stringify(e.data))?void 0:o.length)?t:0}catch(e){return 0}}(t),expectedOrigins:o.origins,hasAllowedSources:Array.isArray(o.sources),expectedSourceCount:Array.isArray(o.sources)?o.sources.length:0,acceptedByOrigin:o.originAllowed,acceptedBySource:o.sourceAllowed,sourceHints:(w=Array.isArray(u=o.sources)?u.findIndex(e=>e===t.source):-1,{isWindow:t.source===window,isParent:t.source===window.parent,isOpener:t.source===window.opener,matchedAllowedSourceIndex:w>=0?w:null,hasSource:!!t.source,allowedSourceCount:Array.isArray(u)?u.length:0}),timestamp:Date.now()}}}({busId:a,event:r,validation:y}),"function"!=typeof fetch?o("[SecureMessageBus] fetch is not available, audit log could not be sent."):fetch(l,{method:"POST",credentials:"same-origin",keepalive:!0,headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}).catch(()=>{})),"enforce"===u&&!y.allowed){m.enabled&&o("[SecureMessageBus] Refused to dispatch a message with invalid origin or source.",r);return}if(w.forEach(e=>e(r)),"string"!=typeof b)return;let v=f.get(b);v&&v.forEach(e=>e(r.data,r))}return window.addEventListener("message",p),{on(e,t){let o=f.get(e)||[];return o.push(t),f.set(e,o),()=>{let o=(f.get(e)||[]).filter(e=>e!==t);0===o.length?f.delete(e):f.set(e,o)}},onRaw:e=>(w.add(e),()=>{w.delete(e)}),send(e,t,n){if(!e)return o("[SecureMessageBus] send() called with a null target window."),!1;let r=null!=n?n:window.location.origin;return"*"!==r||l?(e.postMessage(t,r),!0):(o("[SecureMessageBus] Refused to send a message with wildcard targetOrigin. Pass allowWildcardTargetOrigin: true to opt in."),!1)},destroy(){window.removeEventListener("message",p),f.clear(),w.clear()}}}function i(e){return e.map(e=>{let t=e.substring(e.indexOf("=")+1),o=encodeURIComponent(decodeURIComponent(t));return e.replace(t,o)}).join("&")}let l=["challengeCenterY","validationErrorY"];function s(e,t,o,n){if(!t||o!==t.contentWindow)return!1;let r=null==e?void 0:e.formId,i=null==e?void 0:e[n];if("261414825751962"!==r||function(e){let t=e.id||"",o=t.match(/^JotFormIFrame-(\d+)$/);if(o)return o[1];let n=t.match(/^(\d+)$/);if(n)return n[1];try{var r;return(null==(r=new URL(e.src,window.location.href).pathname.match(/\/(\d+)(?:\/)?$/))?void 0:r[1])||""}catch(e){return""}}(t)!==r||!l.includes(n)||"number"!=typeof i||!Number.isFinite(i)||i<0)return!1;let s=t.getBoundingClientRect();if(i>Math.max(s.height,t.clientHeight,parseFloat(t.style.height)||0))return!1;let a=Math.max(0,(window.scrollY||window.pageYOffset||0)+s.top+i-window.innerHeight/2);return window.scrollTo({top:a,behavior:"smooth"}),!0}let a=/^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?(\/[^\s]*)?$/i;return window.jotformEmbedHandler=function(e,t){var o,n,l,c;null==(n=window.__jotformEmbedHandlerBus)||null==(o=n.destroy)||o.call(n),window.__jotformEmbedScrollPositionBuses=window.__jotformEmbedScrollPositionBuses||new Map,null==(c=window.__jotformEmbedScrollPositionBuses.get(e))||null==(l=c.destroy)||l.call(c);let d=()=>{try{var t;return[new URL(null==(t=document.querySelector(e))?void 0:t.src,window.location.href).origin,"https://www.jotformers.com"].filter(Boolean)}catch(e){return["https://www.jotformers.com"]}},u=r({allowedOrigins:d});u.onRaw(function(o){if("object"==typeof o.data)return;let n=o.data.split(":"),r=document.querySelector(e);if(!r)return;let i=[];if(t){let{hostname:e}=new URL(t);i=[e]}else i=["jotform.com","jotform.pro"];!function(e,t,o,n){let r=document.querySelector(n);switch(e[0]){case"scrollIntoView":r.scrollIntoView();break;case"setHeight":r.style.height=`${e[1]}px`,!Number.isNaN(e[1])&&parseInt(r.style.minHeight,10)>parseInt(e[1],10)&&(r.style.minHeight=`${e[1]}px`);break;case"setMinHeight":r.style.minHeight=`${e[1]}px`;break;case"collapseErrorPage":r.clientHeight>window.innerHeight&&(r.style.height=`${window.innerHeight}px`);break;case"reloadPage":window.location.reload();break;case"removeIframeOnloadAttr":r.removeAttribute("onload");break;case"loadScript":if(!window.isPermitted(t.origin,o))break;let i=document.createElement("script");i.src=e.length>3?`${e[1]}:${e[2]}`:e[1],i.type="text/javascript",document.body.appendChild(i);break;case"exitFullscreen":window.document.exitFullscreen?window.document.exitFullscreen():window.document.mozCancelFullScreen||window.document.mozCancelFullscreen?window.document.mozCancelFullScreen():window.document.webkitExitFullscreen?window.document.webkitExitFullscreen():window.document.msExitFullscreen&&window.document.msExitFullscreen();break;case"setDeviceType":let[,l]=e;window.jfDeviceType=l;break;case"backgroundStyles":new URLSearchParams(e[1]).forEach((e,t)=>{r.style[t]=e}),(r.contentDocument?r.contentDocument:r.contentWindow.document||r.document).documentElement.style.background="none"}}(n,o,i,e);var l=i;if(window.isPermitted(o.origin,l)&&"contentWindow"in r&&"postMessage"in r.contentWindow){let e={docurl:encodeURIComponent(document.URL),referrer:encodeURIComponent(document.referrer)};r.contentWindow.postMessage(JSON.stringify({type:"urls",value:e}),"*")}});let m=r({allowedOrigins:d,allowedSources:()=>{var t;return[null==(t=document.querySelector(e))?void 0:t.contentWindow].filter(Boolean)}});m.on("NVA_CAPTCHA_CHALLENGE_POSITION",(t,o)=>{s(t,document.querySelector(e),o.source,"challengeCenterY")}),m.on("NVA_VALIDATION_ERROR_POSITION",(t,o)=>{s(t,document.querySelector(e),o.source,"validationErrorY")}),function(){let t=document.querySelector(e);if(t){let e,{src:o}=t;if(o.includes("jsForm=true"))return;let n=window.location.href,r=[];if(n&&n.indexOf("?")>-1&&r.push(...i(n.substring(n.indexOf("?")+1).split("&")).split("&").filter(Boolean)),o&&o.indexOf("?")>-1){let e=o.substr(o.indexOf("?")+1).split("&");e=i(e),r.push(...e.split("&").filter(Boolean)),o=o.substring(0,o.indexOf("?"))}r.push("isIframeEmbed=1"),r.push(`parentURL=${encodeURIComponent((e=window.location.href,a.test(e)?e:window.top.location.href))}`);let l=`${o}?${r.join("&")}`;if(t.getAttribute("src")===l||t.getAttribute("data-jf-embed-src")===l)return;!function(e,t){if(e.getAttribute("data-jf-embed-src")===t)return;let o=e.cloneNode(!0);o.setAttribute("data-jf-embed-src",t),o.setAttribute("src",t),e.parentNode&&(e.setAttribute("src","about:blank"),e.parentNode.replaceChild(o,e))}(t,l)}}(),window.isPermitted=function(e,t){let o=document.createElement("a");o.href=e;let{hostname:n}=o,r=!1;if(void 0!==n)return t.forEach(e=>{(n.slice(-1*e.length-1)===".".concat(e)||n===e)&&(r=!0)}),r},window.__jotformEmbedHandlerBus=u,window.__jotformEmbedScrollPositionBuses.set(e,m)},e=e.default}()});