import{i as e}from"./p-BCkDiHIY.js";const t="undefined"!=typeof CSSStyleSheet&&"replace"in CSSStyleSheet.prototype&&"adoptedStyleSheets"in Document.prototype,n=new Map,o=new WeakMap;function r(r,i){if(!r||!i||!e(r))return Promise.resolve();if(!t){let e=o.get(i);if(e||(e=new Set,o.set(i,e)),!e.has(r)){e.add(r);const t=document.createElement("link");t.rel="stylesheet",t.href=r,i.appendChild(t)}return Promise.resolve()}if(!n.has(r)){const e=fetch(r).then((e=>{if(!e.ok)throw new Error(`[ai12z] adoptStyleSheet: HTTP ${e.status} for ${r}`);return e.text()})).then((e=>{const t=new CSSStyleSheet;return t.replace(e).then((()=>t))})).catch((e=>(n.delete(r),Promise.reject(e))));n.set(r,e)}return n.get(r).then((e=>{i.adoptedStyleSheets.includes(e)||(i.adoptedStyleSheets=[...i.adoptedStyleSheets,e])})).catch((e=>{console.error("[ai12z] adoptStyleSheet failed for",r,e)}))}const i=new Map,s=new WeakMap;function c(t,n){if(!t||!e(t))return t&&console.warn("[ai12z] Blocked script injection — URL must use HTTPS.",t),Promise.resolve();let o=s.get(n);if(o||(o=new Set,s.set(n,o)),o.has(t)){const e=i.get(t);if(e)return e;o.delete(t)}if(o.add(t),i.has(t)){const e=document.createElement("script");e.src=t,e.async=!1,n.appendChild(e)}else{const e=new Promise(((e,o)=>{const r=document.createElement("script");r.src=t,r.async=!1,r.onload=()=>e(),r.onerror=()=>o(new Error(`[ai12z] Failed to load script: ${t}`)),n.appendChild(r)}));i.set(t,e.catch((e=>(i.delete(t),o.delete(t),Promise.reject(e)))))}return i.get(t).catch((e=>{console.warn("[ai12z] loadScriptOnce:",e)}))}export{r as a,c as l}