class IntegrityWrapper{module;queue=[];queueCapacity=100;lastLoadTime=0;async check(){if(this.module===void 0)throw new Error("Integrity module not loaded.");if(this.queue.length>=this.queueCapacity)throw new Error("Too many concurrent integrity checks running.");const i=Math.random();for(this.queue.push(i);this.queue[0]!==i;)await new Promise(e=>setTimeout(e,20));try{return await this.module.ccall("x","string",["boolean"],[!1],{async:!0})}finally{this.queue.shift()}}async loadModule(i=!1){if(!i&&this.module&&Date.now()-this.lastLoadTime<60*1e3)return;const e=this.module,o="./integrity.module.js?t="+Date.now(),{default:n}=await import(o),a=await n();await a.ccall("main","number",[],[],{async:!0}),this.module=a,e&&await e.ccall("quit",null,[],[],{async:!0}),this.lastLoadTime=Date.now()}}const Integrity=new IntegrityWrapper;Integrity.loadModule(),setInterval(()=>{Integrity.loadModule().catch(t=>{console.error("Failed to reload integrity module:",t)})},300*1e3),window.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Integrity.loadModule().catch(t=>{console.error("Failed to reload integrity module:",t)})}),window.Integrity=Integrity;