window.HUDLibraryLoader=new class{constructor(){this.loadedLibraries=new Set,this.loadingPromises=new Map,this.loadingCallbacks=new Map,this.libraries=[{name:"cytoscape",url:"https://unpkg.com/cytoscape@3.26.0/dist/cytoscape.min.js",globalCheck:()=>void 0!==window.cytoscape,dependencies:[]},{name:"dagre",url:"https://unpkg.com/dagre@0.8.5/dist/dagre.min.js",globalCheck:()=>void 0!==window.dagre,dependencies:[]},{name:"cytoscape-dagre",url:"https://unpkg.com/cytoscape-dagre@2.5.0/cytoscape-dagre.js",globalCheck:()=>void 0!==window.cytoscapeDagre,dependencies:["cytoscape","dagre"]}]}loadLibrary(e){if(e.globalCheck())return this.loadedLibraries.add(e.name),Promise.resolve();if(this.loadingPromises.has(e.name))return this.loadingPromises.get(e.name);console.log(`Loading library: ${e.name} from ${e.url}`);const r=new Promise((r,a)=>{const i=document.createElement("script");i.src=e.url,i.async=!0,i.onload=()=>{if(e.globalCheck())console.log(`Successfully loaded library: ${e.name}`),this.loadedLibraries.add(e.name),this.loadingPromises.delete(e.name),r();else{const r=new Error(`Library ${e.name} failed global check after loading`);console.error(r),this.loadingPromises.delete(e.name),a(r)}},i.onerror=()=>{const r=new Error(`Failed to load library: ${e.name} from ${e.url}`);console.error(r),this.loadingPromises.delete(e.name),a(r)},document.head.appendChild(i)});return this.loadingPromises.set(e.name,r),r}async loadDependencies(e){const r=e.map(e=>{const r=this.libraries.find(r=>r.name===e);if(!r)throw new Error(`Dependency ${e} not found in library configuration`);return this.loadLibraryWithDependencies(r)});return Promise.all(r)}async loadLibraryWithDependencies(e){return e.dependencies.length>0&&await this.loadDependencies(e.dependencies),this.loadLibrary(e)}async loadHUDLibraries(e=null){console.log("Starting HUD libraries loading...");try{for(let a=0;a<this.libraries.length;a++){const r=this.libraries[a];e&&e({library:r.name,current:a+1,total:this.libraries.length,message:`Loading ${r.name}...`}),await this.loadLibraryWithDependencies(r)}const r=this.libraries.filter(e=>!e.globalCheck());if(r.length>0)throw new Error(`Failed to load libraries: ${r.map(e=>e.name).join(", ")}`);return console.log("All HUD libraries loaded successfully"),e&&e({library:"complete",current:this.libraries.length,total:this.libraries.length,message:"All libraries loaded successfully"}),!0}catch(r){throw console.error("Failed to load HUD libraries:",r),e&&e({library:"error",current:0,total:this.libraries.length,message:`Error: ${r.message}`,error:r}),r}}areLibrariesLoaded(){return this.libraries.every(e=>e.globalCheck())}getLoadingStatus(){return{loaded:Array.from(this.loadedLibraries),loading:Array.from(this.loadingPromises.keys()),total:this.libraries.length,allLoaded:this.areLibrariesLoaded()}}reset(){this.loadedLibraries.clear(),this.loadingPromises.clear(),this.loadingCallbacks.clear()}};
//# sourceMappingURL=hud-library-loader.js.map
