@lwrjs/loader 0.6.0-alpha.1 → 0.6.0-alpha.13

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,28 +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.6.0-alpha.1 */
8
- !function(){"use strict";function e(e,t,r,o){const{autoBoot:n,customInit:i}=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,i),i){i({initializeApp:t,define:r,onBootstrapError:o},e)}}const t="function"==typeof setTimeout,r="undefined"!=typeof console;const o=globalThis;o.LWR.requiredModules=o.LWR.requiredModules||[],o.LWR.requiredModules.indexOf("lwr/loader/v/0_6_0-alpha_1")<0&&o.LWR.requiredModules.push("lwr/loader/v/0_6_0-alpha_1"),new class{constructor(r){this.defineCache={},this.orderedDefs=[],this.global=r,this.config=r.LWR,this.loaderModule="lwr/loader/v/0_6_0-alpha_1";const o=this.tempDefine.bind(this);r.LWR.define=o,this.bootReady=this.config.autoBoot,t&&(this.watchdogTimerId=this.startWatchdogTimer());try{e(Object.freeze(this.config),this.postCustomInit.bind(this),o,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 r=e[0];this.defineCache[r]=e,this.orderedDefs.push(r),this.canInit()&&(t&&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},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 n={};t[2].call(null,n);const{Loader:i}=n,s=new i(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.loaderModule,this.defineCache[this.loaderModule],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()})})}mountApp(e){const{bootstrapModule:t,rootComponent:r,rootComponents:o,endpoints:n,imports:i,index:s}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,endpoints:n,imports:i||{},index:s||{}}),this.orderedDefs.forEach(t=>{t!==this.loaderModule&&e.define(...this.defineCache[t])});const{disableInitDefer:a}=this.config;e.registerImportMappings({imports:i,index:s},[t,r]).then(()=>{if(!a)return this.waitForDOMContentLoaded()}).then(()=>e.load(t)).catch(e=>{this.enterErrorState(new Error(`Application ${r} could not be loaded: ${e}`))})}enterErrorState(e){this.errorHandler?this.errorHandler(e):r&&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)}}(o)}(),LWR.define("lwr/loader/v/0_6_0-alpha_1",["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"}),MODULE_ALREADY_LOADED=Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"}),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=void 0;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}
9
- /**
10
- * Check if a string is a URL based on Common Internet Scheme Syntax
11
- * https://www.ietf.org/rfc/rfc1738.txt
12
- *
13
- * URL Format:
14
- * <scheme>:<scheme-specific-part>
15
- * Common Internet Scheme Syntax:
16
- * The scheme specific part starts with a double slash('//')
17
- *
18
- * A valid URL has a colon that is followed by a double slash.
19
- *
20
- * @param url - the url that is being checked
21
- * @returns boolean
22
- *
23
- * @example Valid URLs
24
- * 'https://salesforce.com'
25
- * 'http://localhost:3000'
26
- *
27
- * @example Invalid URLs
28
- * 'salesforce.com'
29
- * 'localhost:3000'
30
- * '@salesforce/label/type:namespace:name'
31
- */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 n=o.slice(0,o.lastIndexOf("/")+1)+e,i=[];let s=-1;for(let e=0;e<n.length;e++)-1!==s?"/"===n[e]&&(i.push(n.slice(s,e+1)),s=-1):"."===n[e]?"."!==n[e+1]||"/"!==n[e+2]&&e+2!==n.length?"/"===n[e+1]||e+1===n.length?e+=1:s=e:(i.pop(),e+=2):s=e;return-1!==s&&i.push(n.slice(s)),t.slice(0,t.length-o.length)+i.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.charset="utf-8",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});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,n]of Object.entries(e.imports))n.forEach(e=>{const n=r[e],i=this.importURICache.get(e);if(i){const t=n||o,r=i.identity||i.uri;r!==t&&this.invalidationCallback({name:e,oldUrl:r,newUrl:t})}else this.saveImportURIRecord(e,o,n,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;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 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 n=t[o],i=await n(e,{knownModules:r});if(i||void 0===i)return i}}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 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:n}=t;for(let t=0;t<e.length;t++){const i=e[t];try{if(null!==i({name:r,oldUrl:o,newUrl:n}))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}).finally(()=>{})}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise((r,o)=>{const n=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(n)})}):t}hasDocument&&globalThis.addEventListener("error",e=>{lastWindowError=e.error}),!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,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,n=e;const i=this.resolveHook;if(i){for(let e=0;e<i.length;e++){const t=(0,i[e])(n,{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);n=s;continue}if(o=s&&s.url&&(resolveIfNotPlainOrUrl(s.url,r)||s.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(n!==e){if(!o&&this.namedDefineRegistry.has(n))return n;e=n}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;const n=this.resolver.resolveLocal(t);if(n){if(this.namedDefineRegistry.has(t)){const e=this.moduleRegistry.get(n);if(!e||e.originalId!==t)return t}return n}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 n={name:e,dependencies:t,exporter:r,defined:!0};o&&o.external&&o.external.resolveExternal(n),this.namedDefineRegistry.set(e,n),this.lastDefine=n}registerExternalModules(e){const t=[];if(e.map(e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{let t,r;const o=new Promise((o,n)=>{t=o,r=setTimeout(()=>{n(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))},MODULE_LOAD_TIMEOUT_TIMER)}).finally(()=>{clearTimeout(r)}),n={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,n)}}),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}getImportMetadataResolver(){return this.resolver}getModuleRecord(e,t){let r=this.moduleRegistry.get(e);if(r)return r;const o=this.getModuleDef(e,t),n=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)});return r={id:e,originalId:t,module:Object.create(null),dependencyRecords:n,instantiation:o,evaluated:!1,evaluationPromise:null},this.moduleRegistry.set(e,r),r}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:n}=await e.instantiation,i={},s=await Promise.all(n.map(async e=>{if("exports"===e)return i;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(i)&&Object.defineProperty(i,"__useDefault",{value:!0});const l=a||i;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}),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 n=this.resolver.getBaseUrl();return Promise.resolve().then(async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,n),i=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===i)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(i&&null!==i)return evaluateLoadHookResponse(i,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 o}).catch(e=>{throw 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}):hasConsole&&console.warn(`stale module detected ${e}, current URL:${t}, new URL:${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;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);this.registry=new ModuleRegistry(Object.freeze({endpoints:e.endpoints,baseUrl:t})),this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry)})}define(e,t,r){invariant("string"==typeof e,MISSING_NAME);let o=r,n=t;"function"==typeof n&&(o=t,n=[]),invariant(Array.isArray(n),INVALID_DEPS),this.registry.define(e,n,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.6.0-alpha.13 */
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_6_0-alpha_13")<0&&c.LWR.requiredModules.push("lwr/loader/v/0_6_0-alpha_13"),new class{constructor(e){this.defineCache={},this.orderedDefs=[],this.global=e,this.config=e.LWR,this.loaderSpecifier="lwr/loader/v/0_6_0-alpha_13";const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot,l&&(this.watchdogTimerId=this.startWatchdogTimer());try{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:{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.createProfilerModule(t),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_6_0-alpha_13",["exports"],(e=>{Object.assign(e,{logOperationStart:n,logOperationEnd:s})}))}mountApp(e){const{bootstrapModule:t,rootComponent:r,rootComponents:o,endpoints:i,imports:n,index:s}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,endpoints:i,imports:n||{},index:s||{}}),this.orderedDefs.forEach((t=>{t!==this.loaderSpecifier&&e.define(...this.defineCache[t])}));const{disableInitDefer:a}=this.config;e.registerImportMappings({imports:n,index:s},[t,r]).then((()=>{if(!a)return this.waitForDOMContentLoaded()})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r} 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_6_0-alpha_13",["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"}),MODULE_ALREADY_LOADED=Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"}),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.charset="utf-8",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})).finally((()=>{}))}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})),!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=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){const e=this.moduleRegistry.get(i);if(!e||!e.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){const t=[];if(e.map((e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{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)}})),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}getImportMetadataResolver(){return this.resolver}getModuleRecord(e,t){let r=this.moduleRegistry.get(e);if(r)return r.aliases.has(t)||r.aliases.add(t),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)}));return r={id:e,aliases:new Set([t]),module:Object.create(null),dependencyRecords:i,instantiation:o,evaluated:!1,evaluationPromise:null},this.moduleRegistry.set(e,r),r}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}):hasConsole&&console.warn(`stale module detected ${e}, current URL:${t}, new URL:${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);o||(o={logOperationStart:()=>{},logOperationEnd:()=>{}}),this.registry=new ModuleRegistry(Object.freeze({endpoints:e.endpoints,baseUrl:t,profiler:o})),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,223 +4,302 @@
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.6.0-alpha.1 */
7
+ /* LWR Module Loader Shim v0.6.0-alpha.13 */
8
8
  (function () {
9
- 'use strict';
9
+ 'use strict';
10
10
 
11
- function createLoader(name, definition, config, externalModules) {
12
- if (!definition || typeof definition[2] !== 'function') {
13
- throw new Error(`Expected loader with specifier "${name}" to be a module`);
14
- }
15
- // Create a Loader instance
16
- const exports = {};
17
- definition[2].call(null, exports);
18
- const { Loader } = exports;
19
- const loader = new Loader(config);
20
- if (externalModules && externalModules.length) {
21
- loader.registerExternalModules(externalModules);
22
- }
23
- // Define the loader module with public API: { define, load, services }
24
- const exporter = (exports) => {
25
- Object.assign(exports, {
26
- define: loader.define.bind(loader),
27
- load: loader.load.bind(loader),
28
- services: loader.services,
29
- });
30
- return;
31
- };
32
- loader.define(name, ['exports'], exporter);
33
- return loader;
34
- }
11
+ // Bootstrap / shim
12
+ const BOOTSTRAP_PREFIX = 'lwr.bootstrap.';
13
+ const BOOTSTRAP_ERROR = `${BOOTSTRAP_PREFIX}error`;
35
14
 
36
- const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
15
+ var Phase;
37
16
 
38
- // Check for errors with autoBoot and customInit
39
- function validatePreInit(autoBoot, customInit) {
40
- // If autoBoot === false, there must be a customInit hook
41
- if (!autoBoot && !customInit) {
42
- throw new Error('The customInit hook is required when autoBoot is false');
43
- }
44
- // If autoBoot === true, there must NOT be a customInit hook
45
- if (autoBoot && customInit) {
46
- throw new Error('The customInit hook must not be defined when autoBoot is true');
47
- }
48
- }
49
- // Process the customInit hook
50
- function customInit(config, initializeApp, define, onBootstrapError) {
51
- // Validate config
52
- const { autoBoot, customInit } = config;
53
- validatePreInit(autoBoot, customInit);
54
- // Set up arguments and call the customInit hook, if available
55
- if (customInit) {
56
- const lwr = {
57
- initializeApp,
58
- define,
59
- onBootstrapError,
60
- };
61
- customInit(lwr, config);
62
- }
63
- }
17
+ (function (Phase) {
18
+ Phase[Phase["Start"] = 0] = "Start";
19
+ Phase[Phase["End"] = 1] = "End";
20
+ })(Phase || (Phase = {}));
64
21
 
65
- /* global document */
66
- /* eslint-disable lwr/no-unguarded-apis */
67
- const hasSetTimeout = typeof setTimeout === 'function';
68
- const hasConsole = typeof console !== 'undefined';
69
- /* eslint-enable lwr/no-unguarded-apis */
70
- class LoaderShim {
71
- constructor(global) {
72
- this.defineCache = {};
73
- this.orderedDefs = [];
74
- // Parse configuration
75
- this.global = global;
76
- this.config = global.LWR;
77
- this.loaderModule = 'lwr/loader/v/0_6_0-alpha_1';
78
- // Set up the temporary LWR.define function and customInit hook
79
- const tempDefine = this.tempDefine.bind(this);
80
- global.LWR.define = tempDefine;
81
- this.bootReady = this.config.autoBoot;
82
- // Start watchdog timer
83
- if (hasSetTimeout) {
84
- this.watchdogTimerId = this.startWatchdogTimer();
85
- }
86
- try {
87
- customInit(Object.freeze(this.config), this.postCustomInit.bind(this), tempDefine, (e) => {
88
- this.errorHandler = e;
89
- });
90
- }
91
- catch (e) {
92
- this.enterErrorState(e);
93
- }
94
- }
95
- // Return true if the app can be initialized
96
- canInit() {
97
- // Initialize the app if:
98
- // - bootReady: autoBoot is on OR customInit has finished
99
- // - all required modules are defined
100
- const allDefined = this.config.requiredModules.every((m) => this.orderedDefs.includes(m));
101
- return this.bootReady && allDefined;
102
- }
103
- /**
104
- * Create a temporary LWR.define() function which captures all
105
- * calls that occur BEFORE the full loader module is available
106
- *
107
- * Each call to LWR.define() is stored in 2 ways:
108
- * - in a map as [moduleName, arguments] pairs
109
- * - each moduleName is pushed onto an array, to preserve
110
- * the order in which the modules were defined
111
- */
112
- tempDefine(...args) {
113
- // Cache the incoming module
114
- const moduleName = args[0];
115
- this.defineCache[moduleName] = args;
116
- this.orderedDefs.push(moduleName);
117
- if (this.canInit()) {
118
- if (hasSetTimeout) {
119
- // requiredModules are defined, clear watchdog timer
120
- // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
121
- clearTimeout(this.watchdogTimerId);
122
- }
123
- this.initApp();
124
- }
125
- }
126
- // Called by the customInit hook via lwr.initializeApp()
127
- postCustomInit() {
128
- this.bootReady = true;
129
- if (this.canInit()) {
130
- this.initApp();
131
- }
132
- }
133
- // Create the loader and initialize the application
134
- initApp() {
135
- try {
136
- const loaderConfig = {
137
- endpoints: this.config.endpoints,
138
- baseUrl: this.config.baseUrl,
139
- };
140
- const loader = createLoader(this.loaderModule, this.defineCache[this.loaderModule], loaderConfig, this.config.preloadModules);
141
- this.mountApp(loader);
142
- }
143
- catch (e) {
144
- this.enterErrorState(e);
145
- }
146
- }
147
- waitForDOMContentLoaded() {
148
- // eslint-disable-next-line lwr/no-unguarded-apis
149
- if (typeof document === undefined) {
150
- return Promise.resolve();
151
- }
152
- // Resolve if document is already "ready" https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
153
- // eslint-disable-next-line lwr/no-unguarded-apis
154
- if (document.readyState === 'interactive' || document.readyState === 'complete') {
155
- return Promise.resolve();
156
- }
157
- return new Promise((resolve) => {
158
- // eslint-disable-next-line lwr/no-unguarded-apis
159
- document.addEventListener('DOMContentLoaded', () => {
160
- resolve();
161
- });
162
- });
163
- }
164
- // Set up the application globals, import map, root custom element...
165
- mountApp(loader) {
166
- const { bootstrapModule, rootComponent, rootComponents, endpoints, imports, index } = this.config;
167
- // Set global LWR.define to loader.define
168
- this.global.LWR = Object.freeze({
169
- define: loader.define.bind(loader),
170
- rootComponent,
171
- rootComponents,
172
- endpoints,
173
- imports: imports || {},
174
- index: index || {},
175
- });
176
- // Redefine all modules in the temporary cache
177
- this.orderedDefs.forEach((specifier) => {
178
- if (specifier !== this.loaderModule) {
179
- loader.define(...this.defineCache[specifier]);
180
- }
181
- });
182
- // by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
183
- const { disableInitDefer } = this.config;
184
- // Load the import mappings and application bootstrap module
185
- loader
186
- .registerImportMappings({ imports, index }, [bootstrapModule, rootComponent])
187
- .then(() => {
188
- if (!disableInitDefer) {
189
- return this.waitForDOMContentLoaded();
190
- }
191
- })
192
- .then(() => loader.load(bootstrapModule))
193
- .catch((reason) => {
194
- this.enterErrorState(new Error(`Application ${rootComponent} could not be loaded: ${reason}`));
195
- });
196
- }
197
- // Trigger bootstrap error state, and call error handler if registered
198
- enterErrorState(error) {
199
- if (this.errorHandler) {
200
- this.errorHandler(error);
201
- }
202
- else {
203
- if (hasConsole) {
204
- // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
205
- console.error(`An error occurred during LWR bootstrap. ${error.message}`, error.stack);
206
- }
207
- }
208
- }
209
- // eslint-disable-next-line no-undef, lwr/no-unguarded-apis
210
- startWatchdogTimer() {
211
- // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
212
- return setTimeout(() => {
213
- this.enterErrorState(new Error('Failed to load required modules - timed out'));
214
- }, REQUIRED_MODULES_TIMEOUT);
215
- }
22
+ // Attach a custom dispatcher
23
+ let customDispatcher;
24
+ function attachDispatcher(dispatcher) {
25
+ customDispatcher = dispatcher;
26
+ } // Check if the Performance API is available
27
+ // e.g. JSDom (used in Jest) doesn't implement these
28
+
29
+ const perf = globalThis.performance;
30
+ const isPerfSupported = typeof perf !== 'undefined' && typeof perf.mark === 'function' && typeof perf.clearMarks === 'function' && typeof perf.measure === 'function' && typeof perf.clearMeasures === 'function'; // For marking request metrics
31
+ // Fallback to the Performance API if there is no custom dispatcher
32
+
33
+ function logOperationStart({
34
+ id,
35
+ specifier
36
+ }) {
37
+ if (customDispatcher) {
38
+ customDispatcher({
39
+ id,
40
+ phase: Phase.Start,
41
+ specifier
42
+ });
43
+ } else if (isPerfSupported) {
44
+ perf.mark(id + (specifier ? `.${specifier}` : ''));
216
45
  }
46
+ } // For measuring duration metrics
47
+ // Fallback to the Performance API if there is no custom dispatcher
48
+
49
+ /* istanbul ignore next */
217
50
 
218
- // The loader module is ALWAYS required
219
- const GLOBAL = globalThis;
220
- GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
221
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-alpha_1') < 0) {
222
- GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-alpha_1');
51
+ function logOperationEnd({
52
+ id,
53
+ specifier
54
+ }) {
55
+ if (customDispatcher) {
56
+ customDispatcher({
57
+ id,
58
+ phase: Phase.End,
59
+ specifier
60
+ });
61
+ } else if (isPerfSupported) {
62
+ const suffix = specifier ? `.${specifier}` : '';
63
+ const markName = id + suffix;
64
+ const measureName = `${id}.duration${suffix}`;
65
+ perf.measure(measureName, markName); // Clear the created mark and measure to avoid filling the performance entry buffer
66
+ // Even if they get deleted, existing PerformanceObservers preserve copies of the entries
67
+
68
+ perf.clearMarks(markName);
69
+ perf.clearMeasures(measureName);
223
70
  }
224
- new LoaderShim(GLOBAL);
71
+ }
72
+
73
+ function createLoader(name, definition, config, externalModules) {
74
+ if (!definition || typeof definition[2] !== 'function') {
75
+ throw new Error(`Expected loader with specifier "${name}" to be a module`);
76
+ }
77
+ // Create a Loader instance
78
+ const exports = {};
79
+ definition[2].call(null, exports);
80
+ const { Loader } = exports;
81
+ const loader = new Loader(config);
82
+ if (externalModules && externalModules.length) {
83
+ loader.registerExternalModules(externalModules);
84
+ }
85
+ // Define the loader module with public API: { define, load, services }
86
+ const exporter = (exports) => {
87
+ Object.assign(exports, {
88
+ define: loader.define.bind(loader),
89
+ load: loader.load.bind(loader),
90
+ services: loader.services,
91
+ });
92
+ };
93
+ loader.define(name, ['exports'], exporter);
94
+ return loader;
95
+ }
96
+
97
+ const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
98
+
99
+ // Check for errors with autoBoot and customInit
100
+ function validatePreInit(autoBoot, customInit) {
101
+ // If autoBoot === false, there must be a customInit hook
102
+ if (!autoBoot && !customInit) {
103
+ throw new Error('The customInit hook is required when autoBoot is false');
104
+ }
105
+ // If autoBoot === true, there must NOT be a customInit hook
106
+ if (autoBoot && customInit) {
107
+ throw new Error('The customInit hook must not be defined when autoBoot is true');
108
+ }
109
+ }
110
+ // Process the customInit hook
111
+ function customInit(config, initializeApp, define, onBootstrapError) {
112
+ // Validate config
113
+ const { autoBoot, customInit } = config;
114
+ validatePreInit(autoBoot, customInit);
115
+ // Set up arguments and call the customInit hook, if available
116
+ if (customInit) {
117
+ const lwr = {
118
+ initializeApp,
119
+ define,
120
+ onBootstrapError,
121
+ attachDispatcher,
122
+ };
123
+ customInit(lwr, config);
124
+ }
125
+ }
126
+
127
+ /* global document */
128
+ /* eslint-disable lwr/no-unguarded-apis */
129
+ const hasSetTimeout = typeof setTimeout === 'function';
130
+ const hasConsole = typeof console !== 'undefined';
131
+ /* eslint-enable lwr/no-unguarded-apis */
132
+ class LoaderShim {
133
+ constructor(global) {
134
+ this.defineCache = {};
135
+ this.orderedDefs = [];
136
+ // Parse configuration
137
+ this.global = global;
138
+ this.config = global.LWR;
139
+ this.loaderSpecifier = 'lwr/loader/v/0_6_0-alpha_13';
140
+ // Set up the temporary LWR.define function and customInit hook
141
+ const tempDefine = this.tempDefine.bind(this);
142
+ global.LWR.define = tempDefine;
143
+ this.bootReady = this.config.autoBoot;
144
+ // Start watchdog timer
145
+ if (hasSetTimeout) {
146
+ this.watchdogTimerId = this.startWatchdogTimer();
147
+ }
148
+ try {
149
+ customInit(Object.freeze(this.config), this.postCustomInit.bind(this), tempDefine, (e) => {
150
+ this.errorHandler = e;
151
+ });
152
+ }
153
+ catch (e) {
154
+ this.enterErrorState(e);
155
+ }
156
+ }
157
+ // Return true if the app can be initialized
158
+ canInit() {
159
+ // Initialize the app if:
160
+ // - bootReady: autoBoot is on OR customInit has finished
161
+ // - all required modules are defined
162
+ const allDefined = this.config.requiredModules.every((m) => this.orderedDefs.includes(m));
163
+ return this.bootReady && allDefined;
164
+ }
165
+ /**
166
+ * Create a temporary LWR.define() function which captures all
167
+ * calls that occur BEFORE the full loader module is available
168
+ *
169
+ * Each call to LWR.define() is stored in 2 ways:
170
+ * - in a map as [moduleName, arguments] pairs
171
+ * - each moduleName is pushed onto an array, to preserve
172
+ * the order in which the modules were defined
173
+ */
174
+ tempDefine(...args) {
175
+ // Cache the incoming module
176
+ const moduleName = args[0];
177
+ this.defineCache[moduleName] = args;
178
+ this.orderedDefs.push(moduleName);
179
+ if (this.canInit()) {
180
+ if (hasSetTimeout) {
181
+ // requiredModules are defined, clear watchdog timer
182
+ // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
183
+ clearTimeout(this.watchdogTimerId);
184
+ }
185
+ this.initApp();
186
+ }
187
+ }
188
+ // Called by the customInit hook via lwr.initializeApp()
189
+ postCustomInit() {
190
+ this.bootReady = true;
191
+ if (this.canInit()) {
192
+ this.initApp();
193
+ }
194
+ }
195
+ // Create the loader and initialize the application
196
+ initApp() {
197
+ try {
198
+ const loaderConfig = {
199
+ endpoints: this.config.endpoints,
200
+ baseUrl: this.config.baseUrl,
201
+ profiler: { logOperationStart, logOperationEnd },
202
+ // TODO: can be removed following https://github.com/salesforce/lwr/issues/1087
203
+ appMetadata: {
204
+ bootstrapModule: this.config.bootstrapModule,
205
+ rootComponent: this.config.rootComponent,
206
+ rootComponents: this.config.rootComponents,
207
+ },
208
+ };
209
+ const loader = createLoader(this.loaderSpecifier, this.defineCache[this.loaderSpecifier], loaderConfig, this.config.preloadModules);
210
+ this.createProfilerModule(loader);
211
+ this.mountApp(loader);
212
+ }
213
+ catch (e) {
214
+ this.enterErrorState(e);
215
+ }
216
+ }
217
+ waitForDOMContentLoaded() {
218
+ // eslint-disable-next-line lwr/no-unguarded-apis
219
+ if (typeof document === undefined) {
220
+ return Promise.resolve();
221
+ }
222
+ // Resolve if document is already "ready" https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
223
+ // eslint-disable-next-line lwr/no-unguarded-apis
224
+ if (document.readyState === 'interactive' || document.readyState === 'complete') {
225
+ return Promise.resolve();
226
+ }
227
+ return new Promise((resolve) => {
228
+ // eslint-disable-next-line lwr/no-unguarded-apis
229
+ document.addEventListener('DOMContentLoaded', () => {
230
+ resolve();
231
+ });
232
+ });
233
+ }
234
+ // Create a module out of the profiler
235
+ // Note: The profiler is also available as a module through lwc module resolution (see package.json)
236
+ createProfilerModule(loader) {
237
+ const exporter = (exports) => {
238
+ Object.assign(exports, { logOperationStart, logOperationEnd });
239
+ };
240
+ loader.define('lwr/profiler/v/0_6_0-alpha_13', ['exports'], exporter);
241
+ }
242
+ // Set up the application globals, import map, root custom element...
243
+ mountApp(loader) {
244
+ const { bootstrapModule, rootComponent, rootComponents, endpoints, imports, index } = this.config;
245
+ // Set global LWR.define to loader.define
246
+ this.global.LWR = Object.freeze({
247
+ define: loader.define.bind(loader),
248
+ rootComponent,
249
+ rootComponents,
250
+ endpoints,
251
+ imports: imports || {},
252
+ index: index || {},
253
+ });
254
+ // Redefine all modules in the temporary cache
255
+ this.orderedDefs.forEach((specifier) => {
256
+ if (specifier !== this.loaderSpecifier) {
257
+ loader.define(...this.defineCache[specifier]);
258
+ }
259
+ });
260
+ // by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
261
+ const { disableInitDefer } = this.config;
262
+ // Load the import mappings and application bootstrap module
263
+ loader
264
+ .registerImportMappings({ imports, index }, [bootstrapModule, rootComponent])
265
+ .then(() => {
266
+ if (!disableInitDefer) {
267
+ return this.waitForDOMContentLoaded();
268
+ }
269
+ })
270
+ .then(() => loader.load(bootstrapModule))
271
+ .catch((reason) => {
272
+ this.enterErrorState(new Error(`Application ${rootComponent} could not be loaded: ${reason}`));
273
+ });
274
+ }
275
+ // Trigger bootstrap error state, and call error handler if registered
276
+ enterErrorState(error) {
277
+ logOperationStart({ id: BOOTSTRAP_ERROR });
278
+ if (this.errorHandler) {
279
+ this.errorHandler(error);
280
+ }
281
+ else {
282
+ if (hasConsole) {
283
+ // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
284
+ console.error(`An error occurred during LWR bootstrap. ${error.message}`, error.stack);
285
+ }
286
+ }
287
+ }
288
+ // eslint-disable-next-line no-undef, lwr/no-unguarded-apis
289
+ startWatchdogTimer() {
290
+ // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
291
+ return setTimeout(() => {
292
+ this.enterErrorState(new Error('Failed to load required modules - timed out'));
293
+ }, REQUIRED_MODULES_TIMEOUT);
294
+ }
295
+ }
296
+
297
+ // The loader module is ALWAYS required
298
+ const GLOBAL = globalThis;
299
+ GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
300
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-alpha_13') < 0) {
301
+ GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-alpha_13');
302
+ }
303
+ new LoaderShim(GLOBAL);
225
304
 
226
305
  }());
@@ -1 +1 @@
1
- const o=globalThis.LWR&&globalThis.LWR.endpoints,t=globalThis.LWR&&globalThis.LWR.imports||{},r=globalThis.LWR&&globalThis.LWR.index||{},i=new class{constructor(o){if(this.importURICache=new Map,o&&o.imports)for(const[t,r]of Object.entries(o.imports))if(t&&r){(Array.isArray(r)?r:[]).forEach(o=>{this.importURICache.set(o,t)})}}resolve(o){return this.importURICache.get(o)}}({imports:t,index:r}),e=new class{constructor(o){this.importURICache=o&&o.imports?o:{imports:{}}}legacyResolve(o){return this.importURICache.imports[o]}}(globalThis.LWR&&globalThis.LWR.importMappings);function s(t,r){const s=function(t,r){let s;if(s=i.resolve(t),s)return s;if(s=e.legacyResolve(t),s)return s;s=t,s.indexOf("://")<0&&!s.startsWith("/")&&o&&o.uris&&o.uris.module&&(s=o.uris.module+encodeURIComponent(t),r&&(s+="?importer="+encodeURIComponent(r)));return s}(t,r);return import(s)}export{s as load};
1
+ class t{constructor(t){if(this.importURICache=new Map,t&&t.imports)for(const[r,e]of Object.entries(t.imports))if(r&&e){(Array.isArray(e)?e:[]).forEach((t=>{this.importURICache.set(t,r)}))}}resolve(t){return this.importURICache.get(t)}}class r{constructor(t){this.importURICache=t&&t.imports?t:{imports:{}}}legacyResolve(t){return this.importURICache.imports[t]}}let e,o,i;function n(n){e=n;const{imports:s,index:c,importMappings:p}=n;o=new t({imports:s,index:c}),i=new r(p)}function s(t,r){const n=function(t,r){let n;if(!o||!i)throw new Error("The ESM Loader was not initialized");if(n=o.resolve(t),n)return n;if(n=i.legacyResolve(t),n)return n;if(n=t,n.indexOf("://")<0&&!n.startsWith("/")){const{endpoints:o}=e;o&&o.uris&&o.uris.module&&(n=o.uris.module+encodeURIComponent(t),r&&(n+=`?importer=${encodeURIComponent(r)}`))}return n}(t,r);return import(n)}export{n as init,s as load};