import{i as t,n as e}from"./f1384cc2.BX1JbjgR.js";function n(t,e){return t.protocol===e.protocol&&t.port===e.port&&(t.hostname===e.hostname||t.hostname.endsWith(`.${e.hostname}`))}var r="data-special-id";function i({id:t,url:e,privileges:n,title:i,name:o,referrerPolicy:a,iframeSpecialId:s,onLoad:d}){const u=document.getElementById(`sandbox-${t}`);if(u&&"IFRAME"===u.tagName)return u;const l=document.createElement("iframe");if(l.setAttribute("id",`sandbox-${t}`),l.setAttribute("src",e),l.setAttribute("sandbox",n.join(" ")),l.setAttribute("tabIndex","-1"),l.setAttribute("aria-hidden","true"),s&&l.setAttribute(r,s),i&&l.setAttribute("title",i),o&&l.setAttribute("name",o),a&&l.setAttribute("referrerpolicy",a),l.setAttribute("style","display:none; height:0; width:0; visibility: hidden;"),c(l),d){const t=d(l);l.addEventListener("load",t,{once:!0})}return l}var o={};function a(n,r,i,a){const c=n.getAttribute("id");if(!c)throw Error("Endpoint cannot be created without an iframe id");a&&s(r,a);const d=`${c}-endpoint-${i}`,u=o[d];u&&(a?.leaveErrorBreadcrumb(`Terminating existing RPC endpoint ${d}`),u.terminate());const l=t(e(n,{targetOrigin:new URL(r).origin}));return o[d]=l,l}function s(t,e){let r;try{r=new URL(t,window.location.href)}catch{return}const i=r.searchParams.get("shopHost");if(!i)return;const o=`https://${i}`,a=window.location.origin;(function(t,e,r=[]){try{const i=new URL(t),o=n(i,new URL(e))||r.some(t=>{try{const e=new URL(t);return e.origin===t&&n(i,e)}catch{return!1}});return i.origin===t&&"https:"===i.protocol&&o}catch{return!1}})(a,o,function(){const t=document.querySelector('meta[name="serialized-shop"]')?.getAttribute("content");if(t)try{return JSON.parse(t)}catch{return}}()?.origins)||e.log("sandbox_parent_origin_mismatch","Sandbox shopHost does not match the parent origin",{sandbox:r.pathname,expectedOrigin:o,actualOrigin:a})}function c(t){let e=document.querySelector("#SandboxContainer");null==e&&(e=document.createElement("div"),e.setAttribute("id","SandboxContainer"),document.body.appendChild(e)),e.appendChild(t)}export{s as a,i,c as n,a as r,r as t};