/**
 * Copyright 2020 The Pennsylvania State University
 * @license Apache-2.0, see License.md for full text.
 */
globalThis.DynamicImportRegistry=globalThis.DynamicImportRegistry||{},globalThis.DynamicImportRegistry.requestAvailability=()=>(!globalThis.DynamicImportRegistry.instance&&globalThis.document&&globalThis.document.body&&(globalThis.DynamicImportRegistry.instance=globalThis.document.createElement("dynamic-import-registry"),globalThis.document.body.appendChild(globalThis.DynamicImportRegistry.instance)),globalThis.DynamicImportRegistry.instance);class DynamicImportRegistry extends HTMLElement{static get tag(){return"dynamic-import-registry"}constructor(t=!1){super(),this.windowControllers=new AbortController,this.list={},this.__loaded={},this.basePath=new URL("./dynamic-import-registry.js",import.meta.url).href+"/../../../",globalThis.WCAutoloadBasePath?this.basePath=globalThis.WCAutoloadBasePath:globalThis.WCGlobalBasePath&&(this.basePath=globalThis.WCGlobalBasePath)}connectedCallback(){globalThis.addEventListener("dynamic-import-registry--register",this.registerDefinitionEvent.bind(this),{signal:this.windowControllers.signal})}disconnectedCallback(){this.windowControllers.abort()}register(t){t.tag&&t.path?this.list[t.tag]||(this.list[t.tag]=t.path):console.warn("DynamicImportRegistry: registration requires tag and path be set")}registerDefinitionEvent(t){t.detail.tag&&t.detail.path&&this.register(t.detail)}getPathToTag(t){return!!(this.list&&t&&this.list[t])&&`${this.basePath}${this.list[t]}`}async loadDefinition(t){if(t=t.toLowerCase(),!globalThis.customElements.get(t)&&this.list[t]&&!this.__loaded[t]){this.__loaded[t]=!0;try{return await import(`${this.basePath}${this.list[t]}`).then((i=>{this.dispatchEvent(new CustomEvent("dynamic-import-registry-loaded",{detail:{tag:t,path:this.list[t],module:i}}))}))}catch(i){return console.warn(`${this.basePath}${this.list[t]}`),console.warn(i),this.dispatchEvent(new CustomEvent("dynamic-import-registry-failure",{detail:{tag:t,path:this.list[t],module:null}})),!1}}}}customElements.define(DynamicImportRegistry.tag,DynamicImportRegistry);export{DynamicImportRegistry};