import{t as e}from"./debugLog-Bpx6IrJw.js";function t(e){try{let t=new URL(e).hostname.toLowerCase();return t===`live.browser-use.com`||t.endsWith(`.browser-use.com`)}catch{return!1}}function n(e){let t=e.split(`.`).map(e=>Number.parseInt(e,10));if(t.length!==4||t.some(e=>!Number.isFinite(e)||e<0||e>255))return!1;let[n,r]=t;return n===10||n===172&&r>=16&&r<=31||n===192&&r===168||n===100&&r>=64&&r<=127}function r(e){try{let t=new URL(e,window.location.origin);return(t.protocol===`http:`||t.protocol===`https:`)&&!!t.port&&n(t.hostname)}catch{return!1}}function i(e){return!!e&&!t(e)&&r(e)}var a=2,o=[],s=new Map,c=0,l=0;function u(t,n){e(`browser-live`,t,n)}function d(){for(;c<a&&o.length>0;){let e=o.shift();if(!e)return;let{key:t,opts:n,resolve:r,reject:i,enqueuedAt:a}=e;c+=1;let f=++l,p=performance.now();u(`warm:start`,{id:f,key:t,url:n.url,source:n.source??`unknown`,priority:n.priority??`visible`,queuedMs:Math.round(p-a),active:c,queued:o.length,width:n.width,height:n.height});let m=fetch(`/api/browser-preview/live/warm`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({url:n.url,width:n.width,height:n.height})}).then(async e=>{if(!e.ok)throw Error(await e.text());let r=await e.json();return u(`warm:done`,{id:f,key:t,url:n.url,source:n.source??`unknown`,elapsedMs:Math.round(performance.now()-p)}),r}).catch(e=>{throw u(`warm:error`,{id:f,key:t,url:n.url,source:n.source??`unknown`,elapsedMs:Math.round(performance.now()-p),message:e instanceof Error?e.message:String(e)}),e}).finally(()=>{s.delete(t),c=Math.max(0,c-1),d()});s.set(t,m),m.then(r,i)}}function f(e){let t=e.width?Math.round(e.width):void 0,n=e.height?Math.round(e.height):void 0,r=e.priority??`visible`,i=`${e.url}|${t??0}x${n??0}`,a=s.get(i);if(a)return a;let c=o.find(e=>e.key===i);return c?new Promise((e,t)=>{let n=c.resolve,r=c.reject;c.resolve=t=>{n(t),e(t)},c.reject=e=>{r(e),t(e)}}):new Promise((a,s)=>{let c={key:i,opts:{...e,width:t,height:n,priority:r},resolve:a,reject:s,enqueuedAt:performance.now()};r===`visible`?o.unshift(c):o.push(c),d()})}export{i as a,u as i,n,f as o,r,t};