@lwrjs/loader 0.10.0-alpha.0 → 0.10.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,5 +4,5 @@
4
4
  * SPDX-License-Identifier: MIT
5
5
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
6
  */
7
- /* LWR Module Loader Shim v0.10.0-alpha.0 */
8
- !function(){"use strict";var e;let t;function r(e){t=e}!function(e){e[e.Start=0]="Start",e[e.End=1]="End"}(e||(e={}));const o=globalThis.performance,i=void 0!==o&&"function"==typeof o.mark&&"function"==typeof o.clearMarks&&"function"==typeof o.measure&&"function"==typeof o.clearMeasures;function n({id:r,specifier:n}){t?t({id:r,phase:e.Start,specifier:n}):i&&o.mark(r+(n?`.${n}`:""))}function s({id:r,specifier:n}){if(t)t({id:r,phase:e.End,specifier:n});else if(i){const e=n?`.${n}`:"",t=r+e,i=`${r}.duration${e}`;o.measure(i,t),o.clearMarks(t),o.clearMeasures(i)}}function a(e,t,o,i){const{autoBoot:n,customInit:s}=e;if(function(e,t){if(!e&&!t)throw new Error("The customInit hook is required when autoBoot is false");if(e&&t)throw new Error("The customInit hook must not be defined when autoBoot is true")}(n,s),s){s({initializeApp:t,define:o,onBootstrapError:i,attachDispatcher:r},e)}}const l="function"==typeof setTimeout,d="undefined"!=typeof console;const c=globalThis;c.LWR.requiredModules=c.LWR.requiredModules||[],c.LWR.requiredModules.indexOf("lwr/loader/v/0_10_0-alpha_0")<0&&c.LWR.requiredModules.push("lwr/loader/v/0_10_0-alpha_0"),new class{constructor(e){this.defineCache={},this.orderedDefs=[],l&&(this.watchdogTimerId=this.startWatchdogTimer()),this.global=e,this.config=e.LWR,this.loaderSpecifier="lwr/loader/v/0_10_0-alpha_0",this.errorHandler=this.config.onError;const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot;try{this.createProfilerModule(this.config),a(Object.freeze(this.config),this.postCustomInit.bind(this),t,(e=>{this.errorHandler=e}))}catch(e){this.enterErrorState(e)}}canInit(){const e=this.config.requiredModules.every((e=>this.orderedDefs.includes(e)));return this.bootReady&&e}tempDefine(...e){const t=e[0];this.defineCache[t]=e,this.orderedDefs.push(t),this.canInit()&&(l&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&this.initApp()}initApp(){try{const e={endpoints:this.config.endpoints,baseUrl:this.config.baseUrl,profiler:{logOperationStart:n,logOperationEnd:s},appMetadata:{appId:this.config.appId,bootstrapModule:this.config.bootstrapModule,rootComponent:this.config.rootComponent,rootComponents:this.config.rootComponents}},t=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const i={};t[2].call(null,i);const{Loader:n}=i,s=new n(r);return o&&o.length&&s.registerExternalModules(o),s.define(e,["exports"],(e=>{Object.assign(e,{define:s.define.bind(s),load:s.load.bind(s),services:s.services})})),s}(this.loaderSpecifier,this.defineCache[this.loaderSpecifier],e,this.config.preloadModules);this.mountApp(t)}catch(e){this.enterErrorState(e)}}waitForDOMContentLoaded(){return void 0===typeof document||"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}createProfilerModule(e){e.define("lwr/profiler/v/0_10_0-alpha_0",["exports"],(e=>{Object.assign(e,{logOperationStart:n,logOperationEnd:s})}))}mountApp(e){const{bootstrapModule:t,rootComponent:r,rootComponents:o,ssrProps:i,endpoints:n,imports:s,index:a}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,ssrProps:i,endpoints:n,imports:s||{},index:a||{}}),this.orderedDefs.forEach((t=>{t!==this.loaderSpecifier&&e.define(...this.defineCache[t])}));const{disableInitDefer:l}=this.config;e.registerImportMappings({imports:s,index:a},[t,r]).then((()=>{if(!l)return this.waitForDOMContentLoaded()})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r||t} could not be loaded: ${e}`))}))}enterErrorState(e){n({id:"lwr.bootstrap.error"}),this.errorHandler?this.errorHandler(e):d&&console.error(`An error occurred during LWR bootstrap. ${e.message}`,e.stack)}startWatchdogTimer(){return setTimeout((()=>{this.enterErrorState(new Error("Failed to load required modules - timed out"))}),3e5)}}(c)}(),LWR.define("lwr/loader/v/0_10_0-alpha_0",["exports"],(function(exports){"use strict";const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"});Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded:"});const FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),NO_MAPPING_URL=Object.freeze({code:3019,level:0,message:"Mapping endpoint not set"}),BAD_IMPORT_METADATA=Object.freeze({code:3020,level:0,message:"Invalid import metadata: {0} {1}"});Object.freeze({code:3011,level:0,message:"import map is not valid"});const hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const i=o.slice(0,o.lastIndexOf("/")+1)+e,n=[];let s=-1;for(let e=0;e<i.length;e++)-1!==s?"/"===i[e]&&(n.push(i.slice(s,e+1)),s=-1):"."===i[e]?"."!==i[e+1]||"/"!==i[e+2]&&e+2!==i.length?"/"===i[e+1]||e+1===i.length?e+=1:s=e:(n.pop(),e+=2):s=e;return-1!==s&&n.push(i.slice(s)),t.slice(0,t.length-o.length)+n.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const LOADER_PREFIX="lwr.loader.",MODULE_DEFINE=`${LOADER_PREFIX}module.define`,MODULE_FETCH=`${LOADER_PREFIX}module.fetch`,MODULE_ERROR=`${LOADER_PREFIX}module.error`,MAPPINGS_FETCH=`${LOADER_PREFIX}mappings.fetch`,MAPPINGS_ERROR=`${LOADER_PREFIX}mappings.error`;class ImportMetadataResolver{constructor(e,t){this.importURICache=new Map,this.pendingURICache=new Map,this.loadMappingHooks=[],this.config=e,this.invalidationCallback=t}addLoadMappingHook(e){this.loadMappingHooks.push(e)}getMappingEndpoint(){return this.config.endpoints&&this.config.endpoints.uris?this.config.endpoints.uris.mapping:void 0}getModifiersAsUrlParams(){const e=this.config.endpoints?this.config.endpoints.modifiers:void 0;if(e){return`?${Object.keys(e).map((t=>`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`)).join("&")}`}return""}buildMappingUrl(e){return`${this.getMappingEndpoint()}${encodeURIComponent(e)}${this.getModifiersAsUrlParams()}`}getBaseUrl(){return this.config.baseUrl}registerImportMappings(e,t){if(!t||0===t.length){const r=e?JSON.stringify(e):"undefined";throw new LoaderError(BAD_IMPORT_METADATA,[r,t?"[]":"undefined"])}if(!e)throw new LoaderError(BAD_IMPORT_METADATA,["undefined",JSON.stringify(t)]);if(!e.imports||0===Object.keys(e.imports).length)throw new LoaderError(BAD_IMPORT_METADATA,[JSON.stringify(e),JSON.stringify(t)]);const r=e.index||{};for(const[o,i]of Object.entries(e.imports))i.forEach((e=>{const i=r[e],n=this.importURICache.get(e);if(n){const t=i||o,r=n.identity||n.uri;r!==t&&this.invalidationCallback({name:e,oldUrl:r,newUrl:t})}else this.saveImportURIRecord(e,o,i,t.includes(e))}))}getURI(e){return this.importURICache.has(e)?resolveUrl(this.importURICache.get(e).uri,this.getBaseUrl()):void 0}resolveLocal(e){const t=this.getURI(e);return t||(isUrl(e)||e.startsWith("/")?e:void 0)}async resolve(e){let t=this.getURI(e);if(t)return t;if(isUrl(e)||e.startsWith("/"))return e;{const r=this.pendingURICache.get(e);if(r)return r;this.config.profiler.logOperationStart({id:MAPPINGS_FETCH,specifier:e});const o=(this.hasMappingHooks()?this.evaluateMappingHooks:this.fetchNewMappings).bind(this)(e).then((r=>{if(!r||!r.imports)throw new LoaderError(UNRESOLVED,[e]);if(this.registerImportMappings(r,[e]),t=this.getURI(e),!t)throw new LoaderError(UNRESOLVED,[e]);return this.config.profiler.logOperationEnd({id:MAPPINGS_FETCH,specifier:e}),t})).finally((()=>{this.pendingURICache.delete(e)}));return this.pendingURICache.set(e,o),o}}hasMappingHooks(){return this.loadMappingHooks.length>0}async evaluateMappingHooks(e){const t=this.loadMappingHooks;if(t.length){const r=Array.from(this.importURICache.keys());for(let o=0;o<t.length;o++){const i=t[o],n=await i(e,{knownModules:r});if(n||void 0===n)return n}}return this.fetchNewMappings(e)}async fetchNewMappings(e){if("function"!=typeof globalThis.fetch)throw new LoaderError(UNRESOLVED,[e]);const t=resolveUrl(this.buildMappingUrl(e),this.getBaseUrl());return globalThis.fetch(t).then((t=>{if(!t.ok)throw this.config.profiler.logOperationStart({id:MAPPINGS_ERROR,specifier:e}),new LoaderError(UNRESOLVED,[e]);return t.json().then((e=>e)).catch((t=>{throw new LoaderError(UNRESOLVED,[e])}))}))}saveImportURIRecord(e,t,r,o){r&&t!==r?this.importURICache.set(e,{uri:t,identity:r,isRoot:o}):this.importURICache.set(e,{uri:t,isRoot:o})}}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldUrl:o,newUrl:i}=t;for(let t=0;t<e.length;t++){const n=e[t];try{if(null!==n({name:r,oldUrl:o,newUrl:i}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then((async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,`${response.status}`]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0}))}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise(((r,o)=>{const i=setTimeout((()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER);t.then((e=>{r(e)})).catch((()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))})).finally((()=>{clearTimeout(i)}))})):t}hasDocument&&globalThis.addEventListener("error",(e=>{lastWindowError=e.error}));class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.aliases=new Map,this.profiler=e.profiler,this.resolver=new ImportMetadataResolver(e,this.importMetadataInvalidationCallback.bind(this))}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.resolver.getBaseUrl();let o,i=e;const n=this.resolveHook;if(n){for(let e=0;e<n.length;e++){const t=(0,n[e])(i,{parentUrl:r});let s;if((t||null===t)&&(s=isResponseAPromise(t)?await t:t),null!==s){if("string"==typeof s){if(resolveIfNotPlainOrUrl(s,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);i=s;continue}if(o=s&&s.url&&(resolveIfNotPlainOrUrl(s.url,r)||s.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(i!==e){if(!o&&this.namedDefineRegistry.has(i))return i;e=i}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;const i=this.resolver.resolveLocal(t);if(i){if(this.namedDefineRegistry.has(t)&&this.namedDefineRegistry.get(t).defined){if(!this.moduleRegistry.get(i)||!this.aliases.has(t))return t}return i}if(this.namedDefineRegistry.has(t))return t;try{o=await this.resolver.resolve(t)}catch(e){}}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+=`?importer=${encodeURIComponent(t)}`),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r){const o=this.namedDefineRegistry.get(e);if(o&&o.defined)return void(this.lastDefine=o);const i={name:e,dependencies:t,exporter:r,defined:!0};o&&o.external&&o.external.resolveExternal(i),this.profiler.logOperationStart({id:MODULE_DEFINE,specifier:e}),this.namedDefineRegistry.set(e,i),this.lastDefine=i}registerExternalModules(e){e.map((e=>{if(!this.namedDefineRegistry.has(e)){let t,r;const o=new Promise(((o,i)=>{t=o,r=setTimeout((()=>{i(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER)})).finally((()=>{clearTimeout(r)})),i={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,i)}}))}getImportMetadataResolver(){return this.resolver}getExistingModuleRecord(e,t){const r=this.moduleRegistry.get(e);if(r)return this.storeModuleAlias(t,e),r;if(e!==t){const e=this.aliases.get(t);if(e){const t=this.moduleRegistry.get(e);if(t)return t}}return r}getModuleRecord(e,t){const r=this.getExistingModuleRecord(e,t);if(r)return r;const o=this.getModuleDef(e,t),i=o.then((e=>{const t=e.dependencies.map((e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)})).filter((e=>void 0!==e));return Promise.all(t)})),n={id:e,module:Object.create(null),dependencyRecords:i,instantiation:o,evaluated:!1,evaluationPromise:null};return this.moduleRegistry.set(e,n),this.storeModuleAlias(t,e),n}storeModuleAlias(e,t){e!==t&&(this.aliases.has(e)||this.aliases.set(e,t))}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:i}=await e.instantiation,n={},s=await Promise.all(i.map((async e=>{if("exports"===e)return n;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));if(e.evaluated)return e.module;let a=o(...s);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(n)&&Object.defineProperty(n,"__useDefault",{value:!0});const l=a||n;for(const t in l)Object.defineProperty(e.module,t,{enumerable:!0,set(e){l[t]=e},get:()=>l[t]});return l.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),l.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),l.__esModule&&Object.defineProperty(e.module,"__esModule",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const i=this.resolver.getBaseUrl(),n=r||t;return this.profiler.logOperationStart({id:MODULE_FETCH,specifier:n}),Promise.resolve().then((async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,i),n=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===n)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(n&&null!==n)return evaluateLoadHookResponse(n,e)}return!1})).then((t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)})).then((()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return this.profiler.logOperationEnd({id:MODULE_FETCH,specifier:n}),o})).catch((e=>{throw this.profiler.logOperationStart({id:MODULE_ERROR,specifier:n}),e}))}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r,loadMapping:o}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t]),o&&this.resolver.addLoadMappingHook(o)}importMetadataInvalidationCallback({name:e,oldUrl:t,newUrl:r}){const o=this.handleStaleModuleHook;o&&evaluateHandleStaleModuleHooks(o,{name:e,oldUrl:t,newUrl:r})}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}class Loader{constructor(e){let t=e.baseUrl;const r=e.endpoints?e.endpoints.uris.mapping:void 0;let o=e.profiler;if(!r)throw new LoaderError(NO_MAPPING_URL);if(e.endpoints.uris.mapping=r.replace(/\/?$/,"/"),t&&(t=t.replace(/\/?$/,"/")),t||(t=getBaseUrl()),!t)throw new LoaderError(NO_BASE_URL);if(o||(o={logOperationStart:()=>{},logOperationEnd:()=>{}}),this.registry=new ModuleRegistry(Object.freeze({endpoints:e.endpoints,baseUrl:t,profiler:o})),e.appMetadata&&!e.appMetadata.appId){const t=e.appMetadata.bootstrapModule.match(/@lwr-bootstrap\/(.+)\/v\/.+/),r=t&&t[1];e.appMetadata.appId=r}this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry),appMetadata:e.appMetadata})}define(e,t,r){invariant("string"==typeof e,MISSING_NAME);let o=r,i=t;"function"==typeof i&&(o=t,i=[]),invariant(Array.isArray(i),INVALID_DEPS),this.registry.define(e,i,o)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e,t){this.registry.getImportMetadataResolver().registerImportMappings(e,t)}registerExternalModules(e){this.registry.registerExternalModules(e)}}exports.Loader=Loader,Object.defineProperty(exports,"__esModule",{value:!0})}));
7
+ /* LWR Module Loader Shim v0.10.0-alpha.10 */
8
+ !function(){"use strict";var e=function(e){return e[e.Start=0]="Start",e[e.End=1]="End",e}(e||{});let t;function r(e){t=e}const o=globalThis.performance,i=void 0!==o&&"function"==typeof o.mark&&"function"==typeof o.clearMarks&&"function"==typeof o.measure&&"function"==typeof o.clearMeasures;function n({id:r,specifier:n}){t?t({id:r,phase:e.Start,specifier:n}):i&&o.mark(r+(n?`.${n}`:""))}function s({id:r,specifier:n}){if(t)t({id:r,phase:e.End,specifier:n});else if(i){const e=n?`.${n}`:"",t=r+e,i=`${r}.duration${e}`;o.measure(i,t),o.clearMarks(t),o.clearMeasures(i)}}function a(e,t,o,i){const{autoBoot:n,customInit:s}=e;if(function(e,t){if(!e&&!t)throw new Error("The customInit hook is required when autoBoot is false");if(e&&t)throw new Error("The customInit hook must not be defined when autoBoot is true")}(n,s),s){s({initializeApp:t,define:o,onBootstrapError:i,attachDispatcher:r},e)}}const l="function"==typeof setTimeout,d="undefined"!=typeof console;class c{__init(){this.defineCache={}}__init2(){this.orderedDefs=[]}constructor(e){c.prototype.__init.call(this),c.prototype.__init2.call(this),l&&(this.watchdogTimerId=this.startWatchdogTimer()),this.global=e,this.config=e.LWR,this.loaderSpecifier="lwr/loader/v/0_10_0-alpha_10",this.errorHandler=this.config.onError;const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot;try{this.createProfilerModule(this.config),a(Object.freeze(this.config),this.postCustomInit.bind(this),t,(e=>{this.errorHandler=e}))}catch(e){this.enterErrorState(e)}}canInit(){const e=this.config.requiredModules.every((e=>this.orderedDefs.includes(e)));return this.bootReady&&e}tempDefine(...e){const t=e[0];this.defineCache[t]=e,this.orderedDefs.push(t),this.canInit()&&(l&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&this.initApp()}initApp(){try{const e={endpoints:this.config.endpoints,baseUrl:this.config.baseUrl,profiler:{logOperationStart:n,logOperationEnd:s},appMetadata:{appId:this.config.appId,bootstrapModule:this.config.bootstrapModule,rootComponent:this.config.rootComponent,rootComponents:this.config.rootComponents}},t=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const i={};t[2].call(null,i);const{Loader:n}=i,s=new n(r);return o&&o.length&&s.registerExternalModules(o),s.define(e,["exports"],(e=>{Object.assign(e,{define:s.define.bind(s),load:s.load.bind(s),services:s.services})})),s}(this.loaderSpecifier,this.defineCache[this.loaderSpecifier],e,this.config.preloadModules);this.mountApp(t)}catch(e){this.enterErrorState(e)}}waitForDOMContentLoaded(){return void 0===typeof document||"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}createProfilerModule(e){e.define("lwr/profiler/v/0_10_0-alpha_10",["exports"],(e=>{Object.assign(e,{logOperationStart:n,logOperationEnd:s})}))}mountApp(e){const{bootstrapModule:t,rootComponent:r,rootComponents:o,ssrProps:i,endpoints:n,imports:s,index:a}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,ssrProps:i,endpoints:n,imports:s||{},index:a||{}}),this.orderedDefs.forEach((t=>{t!==this.loaderSpecifier&&e.define(...this.defineCache[t])}));const{disableInitDefer:l}=this.config;e.registerImportMappings({imports:s,index:a},[t,r]).then((()=>{if(!l)return this.waitForDOMContentLoaded()})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r||t} could not be loaded: ${e}`))}))}enterErrorState(e){n({id:"lwr.bootstrap.error"}),this.errorHandler?this.errorHandler(e):d&&console.error(`An error occurred during LWR bootstrap. ${e.message}`,e.stack)}startWatchdogTimer(){return setTimeout((()=>{this.enterErrorState(new Error("Failed to load required modules - timed out"))}),3e5)}}const p=globalThis;p.LWR.requiredModules=p.LWR.requiredModules||[],p.LWR.requiredModules.indexOf("lwr/loader/v/0_10_0-alpha_10")<0&&p.LWR.requiredModules.push("lwr/loader/v/0_10_0-alpha_10"),new c(p)}(),LWR.define("lwr/loader/v/0_10_0-alpha_10",["exports"],(function(exports){"use strict";const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"});Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded:"});const FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),NO_MAPPING_URL=Object.freeze({code:3019,level:0,message:"Mapping endpoint not set"}),BAD_IMPORT_METADATA=Object.freeze({code:3020,level:0,message:"Invalid import metadata: {0} {1}"});Object.freeze({code:3011,level:0,message:"import map is not valid"});const hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const i=o.slice(0,o.lastIndexOf("/")+1)+e,n=[];let s=-1;for(let e=0;e<i.length;e++)-1!==s?"/"===i[e]&&(n.push(i.slice(s,e+1)),s=-1):"."===i[e]?"."!==i[e+1]||"/"!==i[e+2]&&e+2!==i.length?"/"===i[e+1]||e+1===i.length?e+=1:s=e:(n.pop(),e+=2):s=e;return-1!==s&&n.push(i.slice(s)),t.slice(0,t.length-o.length)+n.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const LOADER_PREFIX="lwr.loader.",MODULE_DEFINE=`${LOADER_PREFIX}module.define`,MODULE_FETCH=`${LOADER_PREFIX}module.fetch`,MODULE_ERROR=`${LOADER_PREFIX}module.error`,MAPPINGS_FETCH=`${LOADER_PREFIX}mappings.fetch`,MAPPINGS_ERROR=`${LOADER_PREFIX}mappings.error`;class ImportMetadataResolver{__init(){this.importURICache=new Map}__init2(){this.pendingURICache=new Map}__init3(){this.loadMappingHooks=[]}constructor(e,t){ImportMetadataResolver.prototype.__init.call(this),ImportMetadataResolver.prototype.__init2.call(this),ImportMetadataResolver.prototype.__init3.call(this),this.config=e,this.invalidationCallback=t}addLoadMappingHook(e){this.loadMappingHooks.push(e)}getMappingEndpoint(){return this.config.endpoints&&this.config.endpoints.uris?this.config.endpoints.uris.mapping:void 0}getModifiersAsUrlParams(){const e=this.config.endpoints?this.config.endpoints.modifiers:void 0;if(e){return`?${Object.keys(e).map((t=>`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`)).join("&")}`}return""}buildMappingUrl(e){return`${this.getMappingEndpoint()}${encodeURIComponent(e)}${this.getModifiersAsUrlParams()}`}getBaseUrl(){return this.config.baseUrl}registerImportMappings(e,t){if(!t||0===t.length){const r=e?JSON.stringify(e):"undefined";throw new LoaderError(BAD_IMPORT_METADATA,[r,t?"[]":"undefined"])}if(!e)throw new LoaderError(BAD_IMPORT_METADATA,["undefined",JSON.stringify(t)]);if(!e.imports||0===Object.keys(e.imports).length)throw new LoaderError(BAD_IMPORT_METADATA,[JSON.stringify(e),JSON.stringify(t)]);const r=e.index||{};for(const[o,i]of Object.entries(e.imports))i.forEach((e=>{const i=r[e],n=this.importURICache.get(e);if(n){const t=i||o,r=n.identity||n.uri;r!==t&&this.invalidationCallback({name:e,oldUrl:r,newUrl:t})}else this.saveImportURIRecord(e,o,i,t.includes(e))}))}getURI(e){return this.importURICache.has(e)?resolveUrl(this.importURICache.get(e).uri,this.getBaseUrl()):void 0}resolveLocal(e){const t=this.getURI(e);return t||(isUrl(e)||e.startsWith("/")?e:void 0)}async resolve(e){let t=this.getURI(e);if(t)return t;if(isUrl(e)||e.startsWith("/"))return e;{const r=this.pendingURICache.get(e);if(r)return r;this.config.profiler.logOperationStart({id:MAPPINGS_FETCH,specifier:e});const o=(this.hasMappingHooks()?this.evaluateMappingHooks:this.fetchNewMappings).bind(this)(e).then((r=>{if(!r||!r.imports)throw new LoaderError(UNRESOLVED,[e]);if(this.registerImportMappings(r,[e]),t=this.getURI(e),!t)throw new LoaderError(UNRESOLVED,[e]);return this.config.profiler.logOperationEnd({id:MAPPINGS_FETCH,specifier:e}),t})).finally((()=>{this.pendingURICache.delete(e)}));return this.pendingURICache.set(e,o),o}}hasMappingHooks(){return this.loadMappingHooks.length>0}async evaluateMappingHooks(e){const t=this.loadMappingHooks;if(t.length){const r=Array.from(this.importURICache.keys());for(let o=0;o<t.length;o++){const i=t[o],n=await i(e,{knownModules:r});if(n||void 0===n)return n}}return this.fetchNewMappings(e)}async fetchNewMappings(e){if("function"!=typeof globalThis.fetch)throw new LoaderError(UNRESOLVED,[e]);const t=resolveUrl(this.buildMappingUrl(e),this.getBaseUrl());return globalThis.fetch(t).then((t=>{if(!t.ok)throw this.config.profiler.logOperationStart({id:MAPPINGS_ERROR,specifier:e}),new LoaderError(UNRESOLVED,[e]);return t.json().then((e=>e)).catch((t=>{throw new LoaderError(UNRESOLVED,[e])}))}))}saveImportURIRecord(e,t,r,o){r&&t!==r?this.importURICache.set(e,{uri:t,identity:r,isRoot:o}):this.importURICache.set(e,{uri:t,isRoot:o})}}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldUrl:o,newUrl:i}=t;for(let t=0;t<e.length;t++){const n=e[t];try{if(null!==n({name:r,oldUrl:o,newUrl:i}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then((async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,`${response.status}`]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0}))}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise(((r,o)=>{const i=setTimeout((()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER);t.then((e=>{r(e)})).catch((()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))})).finally((()=>{clearTimeout(i)}))})):t}hasDocument&&globalThis.addEventListener("error",(e=>{lastWindowError=e.error}));class ModuleRegistry{constructor(e){ModuleRegistry.prototype.__init.call(this),ModuleRegistry.prototype.__init2.call(this),ModuleRegistry.prototype.__init3.call(this),this.profiler=e.profiler,this.resolver=new ImportMetadataResolver(e,this.importMetadataInvalidationCallback.bind(this))}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.resolver.getBaseUrl();let o,i=e;const n=this.resolveHook;if(n){for(let e=0;e<n.length;e++){const t=(0,n[e])(i,{parentUrl:r});let s;if((t||null===t)&&(s=isResponseAPromise(t)?await t:t),null!==s){if("string"==typeof s){if(resolveIfNotPlainOrUrl(s,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);i=s;continue}if(o=s&&s.url&&(resolveIfNotPlainOrUrl(s.url,r)||s.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(i!==e){if(!o&&this.namedDefineRegistry.has(i))return i;e=i}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;const i=this.resolver.resolveLocal(t);if(i){if(this.namedDefineRegistry.has(t)&&this.namedDefineRegistry.get(t).defined){if(!this.moduleRegistry.get(i)||!this.aliases.has(t))return t}return i}if(this.namedDefineRegistry.has(t))return t;try{o=await this.resolver.resolve(t)}catch(e){}}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+=`?importer=${encodeURIComponent(t)}`),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r){const o=this.namedDefineRegistry.get(e);if(o&&o.defined)return void(this.lastDefine=o);const i={name:e,dependencies:t,exporter:r,defined:!0};o&&o.external&&o.external.resolveExternal(i),this.profiler.logOperationStart({id:MODULE_DEFINE,specifier:e}),this.namedDefineRegistry.set(e,i),this.lastDefine=i}registerExternalModules(e){e.map((e=>{if(!this.namedDefineRegistry.has(e)){let t,r;const o=new Promise(((o,i)=>{t=o,r=setTimeout((()=>{i(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER)})).finally((()=>{clearTimeout(r)})),i={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,i)}}))}__init(){this.namedDefineRegistry=new Map}__init2(){this.moduleRegistry=new Map}__init3(){this.aliases=new Map}getImportMetadataResolver(){return this.resolver}getExistingModuleRecord(e,t){const r=this.moduleRegistry.get(e);if(r)return this.storeModuleAlias(t,e),r;if(e!==t){const e=this.aliases.get(t);if(e){const t=this.moduleRegistry.get(e);if(t)return t}}return r}getModuleRecord(e,t){const r=this.getExistingModuleRecord(e,t);if(r)return r;const o=this.getModuleDef(e,t),i=o.then((e=>{const t=e.dependencies.map((e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)})).filter((e=>void 0!==e));return Promise.all(t)})),n={id:e,module:Object.create(null),dependencyRecords:i,instantiation:o,evaluated:!1,evaluationPromise:null};return this.moduleRegistry.set(e,n),this.storeModuleAlias(t,e),n}storeModuleAlias(e,t){e!==t&&(this.aliases.has(e)||this.aliases.set(e,t))}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:i}=await e.instantiation,n={},s=await Promise.all(i.map((async e=>{if("exports"===e)return n;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));if(e.evaluated)return e.module;let a=o(...s);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(n)&&Object.defineProperty(n,"__useDefault",{value:!0});const l=a||n;for(const t in l)Object.defineProperty(e.module,t,{enumerable:!0,set(e){l[t]=e},get:()=>l[t]});return l.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),l.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),l.__esModule&&Object.defineProperty(e.module,"__esModule",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const i=this.resolver.getBaseUrl(),n=r||t;return this.profiler.logOperationStart({id:MODULE_FETCH,specifier:n}),Promise.resolve().then((async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,i),n=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===n)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(n&&null!==n)return evaluateLoadHookResponse(n,e)}return!1})).then((t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)})).then((()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return this.profiler.logOperationEnd({id:MODULE_FETCH,specifier:n}),o})).catch((e=>{throw this.profiler.logOperationStart({id:MODULE_ERROR,specifier:n}),e}))}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r,loadMapping:o}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t]),o&&this.resolver.addLoadMappingHook(o)}importMetadataInvalidationCallback({name:e,oldUrl:t,newUrl:r}){const o=this.handleStaleModuleHook;o&&evaluateHandleStaleModuleHooks(o,{name:e,oldUrl:t,newUrl:r})}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}class Loader{constructor(e){let t=e.baseUrl;const r=e.endpoints?e.endpoints.uris.mapping:void 0;let o=e.profiler;if(!r)throw new LoaderError(NO_MAPPING_URL);if(e.endpoints.uris.mapping=r.replace(/\/?$/,"/"),t&&(t=t.replace(/\/?$/,"/")),t||(t=getBaseUrl()),!t)throw new LoaderError(NO_BASE_URL);if(o||(o={logOperationStart:()=>{},logOperationEnd:()=>{}}),this.registry=new ModuleRegistry(Object.freeze({endpoints:e.endpoints,baseUrl:t,profiler:o})),e.appMetadata&&!e.appMetadata.appId){const t=e.appMetadata.bootstrapModule.match(/@lwr-bootstrap\/(.+)\/v\/.+/),r=t&&t[1];e.appMetadata.appId=r}this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry),appMetadata:e.appMetadata})}define(e,t,r){invariant("string"==typeof e,MISSING_NAME);let o=r,i=t;"function"==typeof i&&(o=t,i=[]),invariant(Array.isArray(i),INVALID_DEPS),this.registry.define(e,i,o)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e,t){this.registry.getImportMetadataResolver().registerImportMappings(e,t)}registerExternalModules(e){this.registry.registerExternalModules(e)}}exports.Loader=Loader,Object.defineProperty(exports,"__esModule",{value:!0})}));
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: MIT
5
5
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
6
  */
7
- /* LWR Module Loader Shim v0.10.0-alpha.0 */
7
+ /* LWR Module Loader Shim v0.10.0-alpha.10 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
@@ -12,11 +12,11 @@
12
12
  const BOOTSTRAP_PREFIX = 'lwr.bootstrap.';
13
13
  const BOOTSTRAP_ERROR = `${BOOTSTRAP_PREFIX}error`;
14
14
 
15
- var Phase;
16
- (function (Phase) {
15
+ var Phase = /*#__PURE__*/function (Phase) {
17
16
  Phase[Phase["Start"] = 0] = "Start";
18
17
  Phase[Phase["End"] = 1] = "End";
19
- })(Phase || (Phase = {}));
18
+ return Phase;
19
+ }(Phase || {});
20
20
  // Attach a custom dispatcher
21
21
  let customDispatcher;
22
22
  function attachDispatcher(dispatcher) {
@@ -71,18 +71,26 @@
71
71
  }
72
72
  }
73
73
 
74
- function createLoader(name, definition, config, externalModules) {
74
+ function createLoader(
75
+ name,
76
+ definition,
77
+ config,
78
+ externalModules,
79
+ ) {
75
80
  if (!definition || typeof definition[2] !== 'function') {
76
81
  throw new Error(`Expected loader with specifier "${name}" to be a module`);
77
82
  }
83
+
78
84
  // Create a Loader instance
79
85
  const exports = {};
80
86
  definition[2].call(null, exports);
81
87
  const { Loader } = exports;
82
88
  const loader = new Loader(config);
89
+
83
90
  if (externalModules && externalModules.length) {
84
91
  loader.registerExternalModules(externalModules);
85
92
  }
93
+
86
94
  // Define the loader module with public API: { define, load, services }
87
95
  const exporter = (exports) => {
88
96
  Object.assign(exports, {
@@ -92,6 +100,7 @@
92
100
  });
93
101
  };
94
102
  loader.define(name, ['exports'], exporter);
103
+
95
104
  return loader;
96
105
  }
97
106
 
@@ -108,11 +117,18 @@
108
117
  throw new Error('The customInit hook must not be defined when autoBoot is true');
109
118
  }
110
119
  }
120
+
111
121
  // Process the customInit hook
112
- function customInit(config, initializeApp, define, onBootstrapError) {
122
+ function customInit(
123
+ config,
124
+ initializeApp,
125
+ define,
126
+ onBootstrapError,
127
+ ) {
113
128
  // Validate config
114
129
  const { autoBoot, customInit } = config;
115
130
  validatePreInit(autoBoot, customInit);
131
+
116
132
  // Set up arguments and call the customInit hook, if available
117
133
  if (customInit) {
118
134
  const lwr = {
@@ -126,48 +142,74 @@
126
142
  }
127
143
 
128
144
  /* global document */
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
129
153
  /* eslint-disable lwr/no-unguarded-apis */
130
154
  const hasSetTimeout = typeof setTimeout === 'function';
131
155
  const hasConsole = typeof console !== 'undefined';
132
156
  /* eslint-enable lwr/no-unguarded-apis */
157
+
133
158
  class LoaderShim {
134
- constructor(global) {
135
- this.defineCache = {};
136
- this.orderedDefs = [];
159
+
160
+
161
+
162
+
163
+ __init() {this.defineCache = {};}
164
+ __init2() {this.orderedDefs = [];}
165
+
166
+ // eslint-disable-line no-undef, lwr/no-unguarded-apis
167
+
168
+ constructor(global) {LoaderShim.prototype.__init.call(this);LoaderShim.prototype.__init2.call(this);
137
169
  // Start watchdog timer
138
170
  if (hasSetTimeout) {
139
171
  this.watchdogTimerId = this.startWatchdogTimer();
140
172
  }
173
+
141
174
  // Parse configuration
142
175
  this.global = global;
143
- this.config = global.LWR;
144
- this.loaderSpecifier = 'lwr/loader/v/0_10_0-alpha_0';
176
+ this.config = global.LWR ;
177
+ this.loaderSpecifier = 'lwr/loader/v/0_10_0-alpha_10';
178
+
145
179
  // Set up error handler
146
180
  this.errorHandler = this.config.onError;
181
+
147
182
  // Set up the temporary LWR.define function and customInit hook
148
183
  const tempDefine = this.tempDefine.bind(this);
149
184
  global.LWR.define = tempDefine;
150
185
  this.bootReady = this.config.autoBoot;
186
+
151
187
  try {
152
188
  this.createProfilerModule(this.config);
153
- customInit(Object.freeze(this.config), this.postCustomInit.bind(this), tempDefine, (e) => {
154
- // customInit handlers can overwrite
155
- // the error handler with onBootstrapError
156
- this.errorHandler = e;
157
- });
158
- }
159
- catch (e) {
189
+ customInit(
190
+ Object.freeze(this.config),
191
+ this.postCustomInit.bind(this),
192
+ tempDefine,
193
+ (e) => {
194
+ // customInit handlers can overwrite
195
+ // the error handler with onBootstrapError
196
+ this.errorHandler = e;
197
+ },
198
+ );
199
+ } catch (e) {
160
200
  this.enterErrorState(e);
161
201
  }
162
202
  }
203
+
163
204
  // Return true if the app can be initialized
164
- canInit() {
205
+ canInit() {
165
206
  // Initialize the app if:
166
207
  // - bootReady: autoBoot is on OR customInit has finished
167
208
  // - all required modules are defined
168
209
  const allDefined = this.config.requiredModules.every((m) => this.orderedDefs.includes(m));
169
210
  return this.bootReady && allDefined;
170
211
  }
212
+
171
213
  /**
172
214
  * Create a temporary LWR.define() function which captures all
173
215
  * calls that occur BEFORE the full loader module is available
@@ -177,7 +219,7 @@
177
219
  * - each moduleName is pushed onto an array, to preserve
178
220
  * the order in which the modules were defined
179
221
  */
180
- tempDefine(...args) {
222
+ tempDefine(...args) {
181
223
  // Cache the incoming module
182
224
  const moduleName = args[0];
183
225
  this.defineCache[moduleName] = args;
@@ -191,15 +233,17 @@
191
233
  this.initApp();
192
234
  }
193
235
  }
236
+
194
237
  // Called by the customInit hook via lwr.initializeApp()
195
- postCustomInit() {
238
+ postCustomInit() {
196
239
  this.bootReady = true;
197
240
  if (this.canInit()) {
198
241
  this.initApp();
199
242
  }
200
243
  }
244
+
201
245
  // Create the loader and initialize the application
202
- initApp() {
246
+ initApp() {
203
247
  try {
204
248
  const loaderConfig = {
205
249
  endpoints: this.config.endpoints,
@@ -213,18 +257,24 @@
213
257
  rootComponents: this.config.rootComponents,
214
258
  },
215
259
  };
216
- const loader = createLoader(this.loaderSpecifier, this.defineCache[this.loaderSpecifier], loaderConfig, this.config.preloadModules);
260
+ const loader = createLoader(
261
+ this.loaderSpecifier,
262
+ this.defineCache[this.loaderSpecifier],
263
+ loaderConfig,
264
+ this.config.preloadModules,
265
+ );
217
266
  this.mountApp(loader);
218
- }
219
- catch (e) {
267
+ } catch (e) {
220
268
  this.enterErrorState(e);
221
269
  }
222
270
  }
223
- waitForDOMContentLoaded() {
271
+
272
+ waitForDOMContentLoaded() {
224
273
  // eslint-disable-next-line lwr/no-unguarded-apis
225
274
  if (typeof document === undefined) {
226
275
  return Promise.resolve();
227
276
  }
277
+
228
278
  // Resolve if document is already "ready" https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
229
279
  // eslint-disable-next-line lwr/no-unguarded-apis
230
280
  if (document.readyState === 'interactive' || document.readyState === 'complete') {
@@ -237,17 +287,21 @@
237
287
  });
238
288
  });
239
289
  }
290
+
240
291
  // Create a module out of the profiler
241
292
  // Note: The profiler is also available as a module through lwc module resolution (see package.json)
242
- createProfilerModule(globalLWR) {
293
+ createProfilerModule(globalLWR) {
243
294
  const exporter = (exports) => {
244
295
  Object.assign(exports, { logOperationStart, logOperationEnd });
245
296
  };
246
- globalLWR.define('lwr/profiler/v/0_10_0-alpha_0', ['exports'], exporter);
297
+ globalLWR.define('lwr/profiler/v/0_10_0-alpha_10', ['exports'], exporter);
247
298
  }
299
+
248
300
  // Set up the application globals, import map, root custom element...
249
- mountApp(loader) {
250
- const { bootstrapModule, rootComponent, rootComponents, ssrProps, endpoints, imports, index } = this.config;
301
+ mountApp(loader) {
302
+ const { bootstrapModule, rootComponent, rootComponents, ssrProps, endpoints, imports, index } =
303
+ this.config;
304
+
251
305
  // Set global LWR.define to loader.define
252
306
  this.global.LWR = Object.freeze({
253
307
  define: loader.define.bind(loader),
@@ -258,42 +312,50 @@
258
312
  imports: imports || {},
259
313
  index: index || {},
260
314
  });
315
+
261
316
  // Redefine all modules in the temporary cache
262
317
  this.orderedDefs.forEach((specifier) => {
263
318
  if (specifier !== this.loaderSpecifier) {
264
319
  loader.define(...this.defineCache[specifier]);
265
320
  }
266
321
  });
322
+
267
323
  // by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
268
324
  const { disableInitDefer } = this.config;
325
+
269
326
  // Load the import mappings and application bootstrap module
270
327
  loader
271
328
  .registerImportMappings({ imports, index }, [bootstrapModule, rootComponent])
272
329
  .then(() => {
273
- if (!disableInitDefer) {
274
- return this.waitForDOMContentLoaded();
275
- }
276
- })
330
+ if (!disableInitDefer) {
331
+ return this.waitForDOMContentLoaded();
332
+ }
333
+ })
277
334
  .then(() => loader.load(bootstrapModule))
278
335
  .catch((reason) => {
279
- this.enterErrorState(new Error(`Application ${rootComponent || bootstrapModule} could not be loaded: ${reason}`));
280
- });
336
+ this.enterErrorState(
337
+ new Error(
338
+ `Application ${rootComponent || bootstrapModule} could not be loaded: ${reason}`,
339
+ ),
340
+ );
341
+ });
281
342
  }
343
+
282
344
  // Trigger bootstrap error state, and call error handler if registered
283
- enterErrorState(error) {
345
+ enterErrorState(error) {
284
346
  logOperationStart({ id: BOOTSTRAP_ERROR });
285
347
  if (this.errorHandler) {
286
348
  this.errorHandler(error);
287
- }
288
- else {
349
+ } else {
289
350
  if (hasConsole) {
290
351
  // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
291
352
  console.error(`An error occurred during LWR bootstrap. ${error.message}`, error.stack);
292
353
  }
293
354
  }
294
355
  }
356
+
295
357
  // eslint-disable-next-line no-undef, lwr/no-unguarded-apis
296
- startWatchdogTimer() {
358
+ startWatchdogTimer() {
297
359
  // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
298
360
  return setTimeout(() => {
299
361
  this.enterErrorState(new Error('Failed to load required modules - timed out'));
@@ -302,11 +364,12 @@
302
364
  }
303
365
 
304
366
  // The loader module is ALWAYS required
305
- const GLOBAL = globalThis;
367
+ const GLOBAL = globalThis ;
306
368
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
307
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_10_0-alpha_0') < 0) {
308
- GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_10_0-alpha_0');
369
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_10_0-alpha_10') < 0) {
370
+ GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_10_0-alpha_10');
309
371
  }
310
372
  new LoaderShim(GLOBAL);
311
373
 
312
- }());
374
+ })();
375
+ //# sourceMappingURL=lwr-loader-shim.js.map
@@ -1 +1 @@
1
- class i{constructor(i){var t,o;this.importURICache=new Map,this.modifiers="",this.normalizeMetadata(i),this.mappingEndpoint=(null==i?void 0:i.importMappings)||null===(t=null==i?void 0:i.endpoints)||void 0===t?void 0:t.uris.mapping,(null===(o=null==i?void 0:i.endpoints)||void 0===o?void 0:o.modifiers)&&(this.modifiers=Object.entries(i.endpoints.modifiers).reduce(((i,[t,o])=>i+`${t}=${o}&`),"?"))}normalizeMetadata(i){if(i&&i.imports)for(const[t,o]of Object.entries(i.imports))if(t&&o){(Array.isArray(o)?o:[]).forEach((i=>{this.importURICache.set(i,t)}))}}async fetchMappings(i){const t=`${this.mappingEndpoint}${encodeURIComponent(i)}${this.modifiers}`,o=await globalThis.fetch(t);if(o.ok){const i=await o.json();this.normalizeMetadata(i)}}async resolve(i){let t=this.importURICache.get(i);return!t&&this.mappingEndpoint&&(await this.fetchMappings(i),t=this.importURICache.get(i)),t}}class t{constructor(i){this.importURICache=i&&i.imports?i:{imports:{}}}legacyResolve(i){return this.importURICache.imports[i]}}let o,e,n;function r(r){o=r;const{imports:s,index:a,importMappings:p,endpoints:c}=r;e=new i({imports:s,index:a,endpoints:c,importMappings:p}),n=new t(p)}async function s(i,t){const r=await async function(i,t){var r;if(i.includes("://")||i.startsWith("/"))return i;if(!e||!n)throw new Error("The ESM Loader was not initialized");if(e){const t=await e.resolve(i);if(t)return t}if(n){const t=n.legacyResolve(i);if(t)return t}const{endpoints:s}=o;if(!(null===(r=null==s?void 0:s.uris)||void 0===r?void 0:r.module))throw new Error(`Unable to resolve the URL for "${i}"`);let a=s.uris.module+encodeURIComponent(i);t&&(a+=`?importer=${encodeURIComponent(t)}`);s.modifiers&&(a+=Object.entries(s.modifiers).reduce(((i,[t,o])=>i+`${t}=${o}&`),t?"&":"?"));return a}(i,t);return import(r)}export{r as init,s as load};
1
+ function t(t){let i,o=t[0],e=1;for(;e<t.length;){const n=t[e],s=t[e+1];if(e+=2,("optionalAccess"===n||"optionalCall"===n)&&null==o)return;"access"===n||"optionalAccess"===n?(i=o,o=s(o)):"call"!==n&&"optionalCall"!==n||(o=s(((...t)=>o.call(i,...t))),i=void 0)}return o}class i{__init(){this.importURICache=new Map}__init2(){this.modifiers=""}constructor(o){i.prototype.__init.call(this),i.prototype.__init2.call(this),this.normalizeMetadata(o),this.mappingEndpoint=t([o,"optionalAccess",t=>t.importMappings])?void 0:t([o,"optionalAccess",t=>t.endpoints,"optionalAccess",t=>t.uris,"access",t=>t.mapping]),t([o,"optionalAccess",t=>t.endpoints,"optionalAccess",t=>t.modifiers])&&(this.modifiers=Object.entries(o.endpoints.modifiers).reduce(((t,[i,o])=>t+`${i}=${o}&`),"?"))}normalizeMetadata(t){if(t&&t.imports)for(const[i,o]of Object.entries(t.imports))if(i&&o){(Array.isArray(o)?o:[]).forEach((t=>{this.importURICache.set(t,i)}))}}async fetchMappings(t){const i=`${this.mappingEndpoint}${encodeURIComponent(t)}${this.modifiers}`,o=await globalThis.fetch(i);if(o.ok){const t=await o.json();this.normalizeMetadata(t)}}async resolve(t){let i=this.importURICache.get(t);return!i&&this.mappingEndpoint&&(await this.fetchMappings(t),i=this.importURICache.get(t)),i}}class o{constructor(t){this.importURICache=t&&t.imports?t:{imports:{}}}legacyResolve(t){return this.importURICache.imports[t]}}let e,n,s;function r(t){e=t;const{imports:r,index:a,importMappings:c,endpoints:p}=t;n=new i({imports:r,index:a,endpoints:p,importMappings:c}),s=new o(c)}async function a(t,i){const o=await async function(t,i){if(t.includes("://")||t.startsWith("/"))return t;if(!n||!s)throw new Error("The ESM Loader was not initialized");if(n){const i=await n.resolve(t);if(i)return i}if(s){const i=s.legacyResolve(t);if(i)return i}const{endpoints:o}=e;if(!function(t){let i,o=t[0],e=1;for(;e<t.length;){const n=t[e],s=t[e+1];if(e+=2,("optionalAccess"===n||"optionalCall"===n)&&null==o)return;"access"===n||"optionalAccess"===n?(i=o,o=s(o)):"call"!==n&&"optionalCall"!==n||(o=s(((...t)=>o.call(i,...t))),i=void 0)}return o}([o,"optionalAccess",t=>t.uris,"optionalAccess",t=>t.module]))throw new Error(`Unable to resolve the URL for "${t}"`);let r=o.uris.module+encodeURIComponent(t);i&&(r+=`?importer=${encodeURIComponent(i)}`);o.modifiers&&(r+=Object.entries(o.modifiers).reduce(((t,[i,o])=>t+`${i}=${o}&`),i?"&":"?"));return r}(t,i);return import(o)}export{r as init,a as load};
@@ -4,30 +4,39 @@
4
4
  * SPDX-License-Identifier: MIT
5
5
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
6
  */
7
- /* LWR ESM Module Loader v0.10.0-alpha.0 */
7
+ /* LWR ESM Module Loader v0.10.0-alpha.10 */
8
+ function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
9
+
10
+
11
+
8
12
  /**
9
13
  * Simplified version of the AMD Import Metadata Resolver.
10
14
  * Just reads the ImportMetadata at construction time.
11
15
  */
12
16
  class ImportResolver {
13
- constructor(config) {
14
- var _a, _b;
15
- this.importURICache = new Map();
16
- this.modifiers = '';
17
+ __init() {this.importURICache = new Map();}
18
+
19
+ __init2() {this.modifiers = '';}
20
+
21
+ constructor(config) {ImportResolver.prototype.__init.call(this);ImportResolver.prototype.__init2.call(this);
17
22
  this.normalizeMetadata(config);
18
23
  // only fetch mappings if fingerprints is ON
19
- this.mappingEndpoint = (config === null || config === void 0 ? void 0 : config.importMappings) ? undefined : (_a = config === null || config === void 0 ? void 0 : config.endpoints) === null || _a === void 0 ? void 0 : _a.uris.mapping;
20
- if ((_b = config === null || config === void 0 ? void 0 : config.endpoints) === null || _b === void 0 ? void 0 : _b.modifiers) {
24
+ this.mappingEndpoint = _optionalChain$1([config, 'optionalAccess', _ => _.importMappings]) ? undefined : _optionalChain$1([config, 'optionalAccess', _2 => _2.endpoints, 'optionalAccess', _3 => _3.uris, 'access', _4 => _4.mapping]);
25
+ if (_optionalChain$1([config, 'optionalAccess', _5 => _5.endpoints, 'optionalAccess', _6 => _6.modifiers])) {
21
26
  // Add URI modifiers to mapping endpoint query
22
- this.modifiers = Object.entries(config.endpoints.modifiers).reduce((q, [k, v]) => (q += `${k}=${v}&`), '?');
27
+ this.modifiers = Object.entries(config.endpoints.modifiers).reduce(
28
+ (q, [k, v]) => (q += `${k}=${v}&`),
29
+ '?',
30
+ );
23
31
  }
24
32
  }
25
- normalizeMetadata(importMetada) {
33
+
34
+ normalizeMetadata(importMetada) {
26
35
  // Normalize the URI cache to optimize retrieval
27
36
  if (importMetada && importMetada.imports) {
28
37
  for (const [uri, value] of Object.entries(importMetada.imports)) {
29
38
  if (uri && value) {
30
- const specifiers = Array.isArray(value) ? value : [];
39
+ const specifiers = Array.isArray(value) ? (value ) : [];
31
40
  specifiers.forEach((specifier) => {
32
41
  this.importURICache.set(specifier, uri);
33
42
  });
@@ -35,7 +44,8 @@ class ImportResolver {
35
44
  }
36
45
  }
37
46
  }
38
- async fetchMappings(specifier) {
47
+
48
+ async fetchMappings(specifier) {
39
49
  const mappingUri = `${this.mappingEndpoint}${encodeURIComponent(specifier)}${this.modifiers}`;
40
50
  const res = await globalThis.fetch(mappingUri);
41
51
  if (res.ok) {
@@ -43,6 +53,7 @@ class ImportResolver {
43
53
  this.normalizeMetadata(mappings);
44
54
  }
45
55
  }
56
+
46
57
  async resolve(specifier) {
47
58
  let uri = this.importURICache.get(specifier);
48
59
  if (!uri && this.mappingEndpoint) {
@@ -58,9 +69,12 @@ class ImportResolver {
58
69
  * Just read the legacy ImportMap at construction time.
59
70
  */
60
71
  class ImportResolverLegacy {
72
+
73
+
61
74
  constructor(importMap) {
62
75
  this.importURICache = importMap && importMap.imports ? importMap : { imports: {} };
63
76
  }
77
+
64
78
  /**
65
79
  * Resolves the URL for a specifier if it is in the global imports
66
80
  * This is using the pre-fingerprints importMappings syntax
@@ -71,30 +85,38 @@ class ImportResolverLegacy {
71
85
  }
72
86
  }
73
87
 
88
+ function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
89
+
90
+
91
+
74
92
  // Singleton state:
75
93
  let esmLoaderConfig;
76
94
  let resolver;
77
95
  let resolverLegacy;
96
+
78
97
  function init(config) {
79
98
  // Save config from globalThis.LWR
80
99
  esmLoaderConfig = config;
81
100
  const { imports, index, importMappings, endpoints } = config;
82
101
  resolver = new ImportResolver({ imports, index, endpoints, importMappings });
83
- resolverLegacy = new ImportResolverLegacy(importMappings);
102
+ resolverLegacy = new ImportResolverLegacy(importMappings );
84
103
  }
104
+
85
105
  async function load(specifier, importer) {
86
106
  const uri = await resolveUrl(specifier, importer);
87
107
  return import(uri);
88
108
  }
109
+
89
110
  async function resolveUrl(specifier, importer) {
90
- var _a;
91
111
  // HMR imports complete URIs when swapping out modules
92
112
  if (specifier.includes('://') || specifier.startsWith('/')) {
93
113
  return specifier;
94
114
  }
115
+
95
116
  if (!resolver || !resolverLegacy) {
96
117
  throw new Error('The ESM Loader was not initialized');
97
118
  }
119
+
98
120
  // Check if the URI is in the import metadata
99
121
  if (resolver) {
100
122
  const uri = await resolver.resolve(specifier);
@@ -102,6 +124,7 @@ async function resolveUrl(specifier, importer) {
102
124
  return uri;
103
125
  }
104
126
  }
127
+
105
128
  // Check if the URI is in the legacy import metadata
106
129
  if (resolverLegacy) {
107
130
  const uri = resolverLegacy.legacyResolve(specifier);
@@ -109,10 +132,12 @@ async function resolveUrl(specifier, importer) {
109
132
  return uri;
110
133
  }
111
134
  }
135
+
112
136
  const { endpoints } = esmLoaderConfig;
113
- if (!((_a = endpoints === null || endpoints === void 0 ? void 0 : endpoints.uris) === null || _a === void 0 ? void 0 : _a.module)) {
137
+ if (!_optionalChain([endpoints, 'optionalAccess', _ => _.uris, 'optionalAccess', _2 => _2.module])) {
114
138
  throw new Error(`Unable to resolve the URL for "${specifier}"`);
115
139
  }
140
+
116
141
  // add the specifier and importer to the default URI
117
142
  let uri = endpoints.uris.module + encodeURIComponent(specifier);
118
143
  if (importer) {
@@ -120,8 +145,12 @@ async function resolveUrl(specifier, importer) {
120
145
  }
121
146
  if (endpoints.modifiers) {
122
147
  // Add URI modifiers to query
123
- uri += Object.entries(endpoints.modifiers).reduce((q, [k, v]) => (q += `${k}=${v}&`), importer ? '&' : '?');
148
+ uri += Object.entries(endpoints.modifiers).reduce(
149
+ (q, [k, v]) => (q += `${k}=${v}&`),
150
+ importer ? '&' : '?',
151
+ );
124
152
  }
153
+
125
154
  return uri;
126
155
  }
127
156