// @bun
var{defineProperty:V,getOwnPropertyNames:Y,getOwnPropertyDescriptor:Z}=Object,$=Object.prototype.hasOwnProperty;function w(j){return this[j]}var _=(j)=>{var q=(W??=new WeakMap).get(j),v;if(q)return q;if(q=V({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var x of Y(j))if(!$.call(q,x))V(q,x,{get:w.bind(j,x),enumerable:!(v=Z(j,x))||v.enumerable})}return W.set(j,q),q},W;var D=(j)=>j;function F(j,q){this[j]=D.bind(null,q)}var C=(j,q)=>{for(var v in q)V(j,v,{get:q[v],enumerable:!0,configurable:!0,set:F.bind(q,v)})};var L=(j,q)=>()=>(j&&(q=j(j=0)),q);var I=import.meta.require;import{createHash as N}from"crypto";function b(j){try{return new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(j).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return j}}function G(j){return Bun.hash(j).toString(16)}function S(j,q={}){if(!j.includes('type="stx/island"'))return{html:j,chunks:[]};let v=new Map,x=j.replace(A,(K,J,M,Q)=>{let z=Q.trim();if(!z)return K;if(/\bdata-stx-src=/.test(M))return K;if(q.minify)z=b(z);let U=G(z);if(!v.has(U))v.set(U,z);let X=q.integrity?` data-stx-integrity="sha384-${N("sha384").update(z).digest("base64")}"`:"";return`<script type="stx/island" data-stx-island="${J}" data-stx-src="/_stx/islands/${U}.js"${X}${M}></script>`}),O=Array.from(v,([K,J])=>({hash:K,code:J}));return{html:x,chunks:O}}function f(j){if(!j.includes("data-stx-src="))return j;let q=new Map,v=/data-stx-scope="([^"]+)"[^>]*?stx-hydrate="([^"]+)"/g,x;while((x=v.exec(j))!==null)q.set(x[1],x[2]);let O=new Set,K=/data-stx-island="([^"]+)"[^>]*?data-stx-src="([^"]+)"/g,J;while((J=K.exec(j))!==null)if(P.has(q.get(J[1])||""))O.add(J[2]);let M=j.lastIndexOf("</head>");if(O.size===0||M===-1)return j;let Q=Array.from(O).filter((z)=>!j.includes(`rel="prefetch" href="${z}"`)).map((z)=>`<link rel="prefetch" href="${z}" as="script">`).join("");if(!Q)return j;return j.slice(0,M)+Q+j.slice(M)}var A,P;var T=L(()=>{A=/<script\s+type="stx\/island"\s+data-stx-island="([^"]+)"([^>]*)>([\s\S]*?)<\/script>/g;P=new Set(["visible","idle"])});T();export{f as injectIslandChunkPrefetch,S as extractIslandChunks};
