@lwrjs/loader 0.17.2-alpha.3 → 0.17.2-alpha.30

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.
Files changed (33) hide show
  1. package/README.md +1 -0
  2. package/build/assets/prod/lwr-error-shim.js +1 -1
  3. package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +168 -46
  4. package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +4 -3
  5. package/build/assets/prod/lwr-loader-shim-legacy.js +58 -16
  6. package/build/assets/prod/lwr-loader-shim.bundle.js +180 -54
  7. package/build/assets/prod/lwr-loader-shim.bundle.min.js +4 -3
  8. package/build/assets/prod/lwr-loader-shim.js +58 -16
  9. package/build/cjs/modules/lwr/loader/constants/constants.cjs +8 -1
  10. package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +2 -2
  11. package/build/cjs/modules/lwr/loader/moduleRegistry/moduleRegistry.cjs +49 -7
  12. package/build/cjs/modules/lwr/loaderLegacy/constants/constants.cjs +8 -1
  13. package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.cjs +50 -8
  14. package/build/modules/lwr/esmLoader/esmLoader.js +1 -1
  15. package/build/modules/lwr/loader/constants/constants.d.ts +5 -0
  16. package/build/modules/lwr/loader/constants/constants.js +6 -0
  17. package/build/modules/lwr/loader/loader.d.ts +1 -0
  18. package/build/modules/lwr/loader/loader.js +122 -38
  19. package/build/modules/lwr/loader/moduleRegistry/importMetadataResolver.js +7 -7
  20. package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.d.ts +4 -0
  21. package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.js +66 -15
  22. package/build/modules/lwr/loaderLegacy/constants/constants.d.ts +5 -0
  23. package/build/modules/lwr/loaderLegacy/constants/constants.js +6 -0
  24. package/build/modules/lwr/loaderLegacy/loaderLegacy.d.ts +1 -0
  25. package/build/modules/lwr/loaderLegacy/loaderLegacy.js +110 -30
  26. package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.d.ts +4 -0
  27. package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.js +67 -16
  28. package/build/shim/shim.d.ts +2 -0
  29. package/build/shim/shim.js +45 -8
  30. package/build/shim-legacy/shimLegacy.d.ts +2 -0
  31. package/build/shim-legacy/shimLegacy.js +45 -8
  32. package/build/types.d.ts +1 -0
  33. package/package.json +8 -8
@@ -4,8 +4,9 @@
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.17.2-alpha.3 */
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(e,t){return t?`${e}-${t}`:e}function s(e,t,r){const o=n(e,t);return t&&r?`${o}_${r}`:o}function a(e,t){const r=e||t?{...t}:null;return r&&e&&(r.specifier=e),r}function l({id:r,specifier:n,specifierIndex:l,metadata:d}){if(t)t({id:r,phase:e.Start,specifier:n,metadata:d});else if(i){const e=s(r,n,l),t=a(n,d);o.mark(e,{detail:t})}}function d({id:r,specifier:l,specifierIndex:d,metadata:c}){if(t)t({id:r,phase:e.End,specifier:l,metadata:c});else if(i){const e=s(r,l,d),t=n(r,l),i=a(l,c);o.measure(t,{start:e,detail:i}),o.clearMarks(e),o.clearMeasures(t)}}function c(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 p="function"==typeof setTimeout,u="undefined"!=typeof console;class h{__init(){this.defineCache={}}__init2(){this.orderedDefs=[]}constructor(e){h.prototype.__init.call(this),h.prototype.__init2.call(this),p&&(this.watchdogTimerId=this.startWatchdogTimer()),this.global=e,this.config=e.LWR,this.loaderSpecifier="lwr/loader/v/0_17_2-alpha_3",this.errorHandler=this.config.onError;const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot;try{this.createProfilerModule(e.LWR.define),c(Object.freeze(this.config),this.postCustomInit.bind(this),t,(e=>{this.errorHandler=e}))}catch(e){this.enterErrorState(e)}}canInit(){if(!this.config.requiredModules)throw new Error("Unexpected missing requiredModules");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()&&(p&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&(p&&clearTimeout(this.watchdogTimerId),this.initApp())}initApp(){try{const e={endpoints:this.config.endpoints,baseUrl:this.config.baseUrl,profiler:{logOperationStart:l,logOperationEnd:d},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;if(!n)throw new Error("Expected Loader class to be defined");const 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("lwr/profiler/v/0_17_2-alpha_3",["exports"],(e=>{Object.assign(e,{logOperationStart:l,logOperationEnd:d})}))}mountApp(e){const{bootstrapModule:t,rootComponent:r,rootComponents:o,serverData:i,endpoints:n,imports:s,index:a}=this.config,l=s||{};this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,serverData:i||{},endpoints:n,imports:l,index:a||{},env:this.global.LWR.env}),this.orderedDefs.forEach((t=>{t!==this.loaderSpecifier&&e.define(...this.defineCache[t])}));const{disableInitDefer:d}=this.config;e.registerImportMappings({imports:l,index:a},[t,r]).then((()=>{if(!d)return this.waitForDOMContentLoaded()})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r||t} could not be loaded: ${e}`))}))}enterErrorState(e){l({id:"lwr.bootstrap.error"}),this.errorHandler?this.errorHandler(e):u&&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"))}),6e4)}}const f=globalThis;f.LWR.requiredModules=f.LWR.requiredModules||[],f.LWR.requiredModules.indexOf("lwr/loader/v/0_17_2-alpha_3")<0&&f.LWR.requiredModules.push("lwr/loader/v/0_17_2-alpha_3"),new h(f)}(),LWR.define("lwr/loader/v/0_17_2-alpha_3",["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}"}),EXPORTER_ERROR=Object.freeze({code:3021,level:0,message:'Error evaluating module "{0}", error was "{1}"'}),UNRESOLVEABLE_MAPPING_ERROR=Object.freeze({code:3022,level:0,message:'Unexpected undefined URI resolving mapping for "{0}"'});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,hasProcess="undefined"!=typeof process,hasProcessEnv=hasProcess&&process.env;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_DYNAMIC_LOAD=`${LOADER_PREFIX}module.dynamicLoad`,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&&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());if(!t)throw new LoaderError(UNRESOLVEABLE_MAPPING_ERROR,[e]);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=6e4,SUPPORTS_TRUSTED_TYPES="undefined"!=typeof trustedTypes;
7
+ /* LWR Module Loader Shim v0.17.2-alpha.30 */
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(e,t){return t?`${e}-${t}`:e}function s(e,t,r){const o=n(e,t);return t&&r?`${o}_${r}`:o}function a(e,t){const r=e||t?{...t}:null;return r&&e&&(r.specifier=e),r}function l({id:r,specifier:n,specifierIndex:l,metadata:d}){if(t)t({id:r,phase:e.Start,specifier:n,metadata:d,specifierIndex:l});else if(i){const e=s(r,n,l),t=a(n,d);o.mark(e,{detail:t})}}function d({id:r,specifier:l,specifierIndex:d,metadata:c}){if(t)t({id:r,phase:e.End,specifier:l,metadata:c,specifierIndex:d});else if(i){const e=s(r,l,d),t=n(r,l),i=a(l,c);o.measure(t,{start:e,detail:i}),o.clearMarks(e),o.clearMeasures(t)}}function c(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 p="function"==typeof setTimeout,u="undefined"!=typeof console;class h{__init(){this.defineCache={}}__init2(){this.orderedDefs=[]}constructor(e){h.prototype.__init.call(this),h.prototype.__init2.call(this),p&&(this.watchdogTimerId=this.startWatchdogTimer()),this.global=e,this.config=e.LWR,this.loaderSpecifier="lwr/loader/v/0_17_2-alpha_30",this.errorHandler=this.config.onError;const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot;try{this.createProfilerModule(e.LWR.define),c(Object.freeze(this.config),this.postCustomInit.bind(this),t,(e=>{this.errorHandler=e}))}catch(e){this.enterErrorState(e)}}canInit(){if(!this.config.requiredModules)throw new Error("Unexpected missing requiredModules");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()&&(p&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&(p&&clearTimeout(this.watchdogTimerId),this.initApp())}initApp(){try{const e={endpoints:this.config.endpoints,baseUrl:this.config.baseUrl,profiler:{logOperationStart:l,logOperationEnd:d},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;if(!n)throw new Error("Expected Loader class to be defined");const 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),t&&t.getModuleWarnings}catch(e){this.enterErrorState(e)}}waitForBody(){return new Promise((e=>{if(document.body)e();else{const t=new MutationObserver((()=>{document.body&&(t.disconnect(),e())}));t.observe(document.documentElement,{childList:!0})}}))}waitForDOMContentLoaded(){return"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}createProfilerModule(e){e("lwr/profiler/v/0_17_2-alpha_30",["exports"],(e=>{Object.assign(e,{logOperationStart:l,logOperationEnd:d})}))}mountApp(e){const{bootstrapModule:t,rootComponent:r,rootComponents:o,serverData:i,endpoints:n,imports:s,index:a}=this.config,l=s||{};this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,serverData:i||{},endpoints:n,imports:l,index:a||{},env:this.global.LWR.env}),this.orderedDefs.forEach((t=>{t!==this.loaderSpecifier&&e.define(...this.defineCache[t])}));const{initDeferDOM:d}=this.config;e.registerImportMappings({imports:l,index:a},[t,r]).then((()=>"undefined"==typeof window||void 0===typeof document?Promise.resolve():d?this.waitForDOMContentLoaded():this.waitForBody())).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r||t} could not be loaded: ${e}`))}))}enterErrorState(e){l({id:"lwr.bootstrap.error"}),this.errorHandler?this.errorHandler(e):u&&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"))}),6e4)}logWarnings(e){for(const t in e)e[t].length&&console.warn(t,e[t])}}const f=globalThis;f.LWR.requiredModules=f.LWR.requiredModules||[],f.LWR.requiredModules.indexOf("lwr/loader/v/0_17_2-alpha_30")<0&&f.LWR.requiredModules.push("lwr/loader/v/0_17_2-alpha_30"),new h(f)}(),LWR.define("lwr/loader/v/0_17_2-alpha_30",["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}"}),EXPORTER_ERROR=Object.freeze({code:3021,level:0,message:'Error evaluating module "{0}", error was "{1}"'}),UNRESOLVEABLE_MAPPING_ERROR=Object.freeze({code:3022,level:0,message:'Unexpected undefined URI resolving mapping for "{0}"'});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,hasProcess="undefined"!=typeof process,hasProcessEnv=hasProcess&&process.env;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_DYNAMIC_LOAD=`${LOADER_PREFIX}module.dynamicLoad`,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&&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());if(!t)throw new LoaderError(UNRESOLVEABLE_MAPPING_ERROR,[e]);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=6e4;var MODULE_WARNING;!function(e){e.MODULE_REDEFINE="Module redefine attempted";e.MODULE_ALREADY_LOADED="Marking module(s) as externally loaded, but they are already loaded";e.ALIAS_UPDATE="Alias update attempt"}(MODULE_WARNING||(MODULE_WARNING={}));
9
9
  /*!
10
10
  * Copyright (C) 2023 salesforce.com, inc.
11
- */function createTrustedTypesPolicy(e,t){return trustedTypes.createPolicy(e,t)}function createFallbackPolicy(e,t){return t}const createPolicy=SUPPORTS_TRUSTED_TYPES?createTrustedTypesPolicy:createFallbackPolicy,policyOptions={createHTML:e=>e,createScript:e=>e,createScriptURL:e=>e};try{createPolicy("default",{createHTML:e=>e,createScript(e){if("null"===e||"undefined"===e)return e},createScriptURL:e=>e})}catch(e){}const trusted=createPolicy("trusted",policyOptions);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||!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(trusted.createScript(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=t?{importer:t}:{};this.profiler.logOperationStart({id:MODULE_DYNAMIC_LOAD,specifier:e,metadata:r});const o=await this.resolve(e,t),i=await this.getModuleRecord(o,e);return i.evaluated?i.module:(i.evaluationPromise||(i.evaluationPromise=this.topLevelEvaluation(i)),i.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),!this.isValidResolveResponse(s))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(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)){const e=this.namedDefineRegistry.get(t);if(e.external||e.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}async 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),i.then((()=>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=i?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;try{a=o(...s)}catch(t){throw new LoaderError(EXPORTER_ERROR,[e.id,t.message||t])}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 e instanceof LoaderError||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]}isValidResolveResponse(e){return null===e||"string"==typeof e||e&&"string"==typeof e.url}}class Loader{constructor(e){let t=e.baseUrl;const r=e.endpoints?e.endpoints.uris.mapping:void 0;let o=e.profiler;if(!r||!e.endpoints)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})}));
11
+ */
12
+ const SUPPORTS_TRUSTED_TYPES="undefined"!=typeof trustedTypes,trustedTypePolicyRegistry={__proto__:null};function createDuplicateSafeTrustedTypesPolicy(e,t){return trustedTypePolicyRegistry[e]?trustedTypePolicyRegistry[e]:trustedTypePolicyRegistry[e]=trustedTypes.createPolicy(e,t)}function createDuplicateSafeFallbackPolicy(e,t){return trustedTypePolicyRegistry[e]?trustedTypePolicyRegistry[e]:trustedTypePolicyRegistry[e]=t}const createPolicy=SUPPORTS_TRUSTED_TYPES?createDuplicateSafeTrustedTypesPolicy:createDuplicateSafeFallbackPolicy,policyOptions={createHTML:e=>e,createScript:e=>e,createScriptURL:e=>e};try{createPolicy("default",{createHTML:e=>e,createScript(e){if("null"===e||"undefined"===e)return e},createScriptURL:e=>e})}catch(e){}const trusted=createPolicy("trusted",policyOptions);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||!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(trusted.createScript(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{__init(){this.isAppMounted=!1}constructor(e){ModuleRegistry.prototype.__init.call(this),ModuleRegistry.prototype.__init2.call(this),ModuleRegistry.prototype.__init3.call(this),ModuleRegistry.prototype.__init4.call(this),this.profiler=e.profiler,this.resolver=new ImportMetadataResolver(e,this.importMetadataInvalidationCallback.bind(this)),this.warnings={[MODULE_WARNING.MODULE_REDEFINE]:[],[MODULE_WARNING.MODULE_ALREADY_LOADED]:[],[MODULE_WARNING.ALIAS_UPDATE]:[]}}async load(e,t){const r=t?{importer:t}:{};this.profiler.logOperationStart({id:MODULE_DYNAMIC_LOAD,specifier:e,metadata:r});const o=await this.resolve(e,t),i=await this.getModuleRecord(o,e);return i.evaluated?i.module:(i.evaluationPromise||(i.evaluationPromise=this.topLevelEvaluation(i)),i.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),!this.isValidResolveResponse(s))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(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)){const e=this.namedDefineRegistry.get(t);if(e.external||e.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)}}))}__init2(){this.namedDefineRegistry=new Map}__init3(){this.moduleRegistry=new Map}__init4(){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}async 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),i.then((()=>n))}storeModuleAlias(e,t){e!==t&&(this.aliases.has(e)||this.aliases.set(e,t))}async getModuleDependencyRecord(e){let t=await this.resolve(e);if(isUrl(t)){const r=this.moduleRegistry.get(t);r&&!this.aliases.has(e)&&(await r.instantiation,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=i?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;try{a=o(...s)}catch(t){throw new LoaderError(EXPORTER_ERROR,[e.id,t.message||t])}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||(this.logMessage("warning",`${r} not found, falling back to the last loader.define call`),o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return this.profiler.logOperationEnd({id:MODULE_FETCH,specifier:n}),o})).catch((e=>{throw e instanceof LoaderError||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]}isValidResolveResponse(e){return null===e||"string"==typeof e||e&&"string"==typeof e.url}getModuleWarnings(e=!1){return this.isAppMounted=e,this.warnings}logMessage(e,t){}}class Loader{constructor(e){let t=e.baseUrl;const r=e.endpoints?e.endpoints.uris.mapping:void 0;let o=e.profiler;if(!r||!e.endpoints)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)}getModuleWarnings(e=!1){return this.registry.getModuleWarnings(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.17.2-alpha.3 */
7
+ /* LWR Module Loader Shim v0.17.2-alpha.30 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
@@ -25,6 +25,7 @@
25
25
 
26
26
  // Check if the Performance API is available
27
27
  // e.g. JSDom (used in Jest) doesn't implement these
28
+ // eslint-disable-next-line
28
29
  const perf = globalThis.performance;
29
30
  const isPerfSupported = typeof perf !== 'undefined' && typeof perf.mark === 'function' && typeof perf.clearMarks === 'function' && typeof perf.measure === 'function' && typeof perf.clearMeasures === 'function';
30
31
  function getMeasureName(id, specifier) {
@@ -57,7 +58,8 @@
57
58
  id,
58
59
  phase: Phase.Start,
59
60
  specifier,
60
- metadata
61
+ metadata,
62
+ specifierIndex
61
63
  });
62
64
  return;
63
65
  }
@@ -84,7 +86,8 @@
84
86
  id,
85
87
  phase: Phase.End,
86
88
  specifier,
87
- metadata
89
+ metadata,
90
+ specifierIndex
88
91
  });
89
92
  } else if (isPerfSupported) {
90
93
  const markName = getMarkName(id, specifier, specifierIndex);
@@ -175,7 +178,7 @@
175
178
  }
176
179
  }
177
180
 
178
- /* global document */
181
+ /* global document, process, console */
179
182
 
180
183
 
181
184
 
@@ -188,6 +191,7 @@
188
191
  /* eslint-disable lwr/no-unguarded-apis */
189
192
  const hasSetTimeout = typeof setTimeout === 'function';
190
193
  const hasConsole = typeof console !== 'undefined';
194
+ const hasProcess = typeof process !== 'undefined';
191
195
  /* eslint-enable lwr/no-unguarded-apis */
192
196
 
193
197
  class LoaderShim {
@@ -209,7 +213,7 @@
209
213
  // Parse configuration
210
214
  this.global = global;
211
215
  this.config = global.LWR ;
212
- this.loaderSpecifier = 'lwr/loader/v/0_17_2-alpha_3';
216
+ this.loaderSpecifier = 'lwr/loader/v/0_17_2-alpha_30';
213
217
 
214
218
  // Set up error handler
215
219
  this.errorHandler = this.config.onError ;
@@ -307,17 +311,40 @@
307
311
  this.config.preloadModules,
308
312
  );
309
313
  this.mountApp(loader);
314
+ if (
315
+ loader &&
316
+ typeof loader.getModuleWarnings === 'function' &&
317
+ hasProcess &&
318
+ hasConsole &&
319
+ // eslint-disable-next-line lwr/no-unguarded-apis
320
+ process.env.NODE_ENV !== 'production'
321
+ ) {
322
+ this.logWarnings(loader.getModuleWarnings(true)); // the true indicates the app is mounted
323
+ }
310
324
  } catch (e) {
311
325
  this.enterErrorState(e);
312
326
  }
313
327
  }
314
328
 
315
- waitForDOMContentLoaded() {
316
- // eslint-disable-next-line lwr/no-unguarded-apis
317
- if (typeof document === undefined) {
318
- return Promise.resolve();
319
- }
329
+ waitForBody() {
330
+ return new Promise((resolve) => {
331
+ // eslint-disable-next-line lwr/no-unguarded-apis
332
+ if (document.body) {
333
+ resolve();
334
+ } else {
335
+ const observer = new MutationObserver(() => {
336
+ // eslint-disable-next-line lwr/no-unguarded-apis
337
+ if (document.body) {
338
+ observer.disconnect();
339
+ resolve();
340
+ }
341
+ });
342
+ observer.observe(document.documentElement, { childList: true });
343
+ }
344
+ });
345
+ }
320
346
 
347
+ waitForDOMContentLoaded() {
321
348
  // Resolve if document is already "ready" https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
322
349
  // eslint-disable-next-line lwr/no-unguarded-apis
323
350
  if (document.readyState === 'interactive' || document.readyState === 'complete') {
@@ -337,7 +364,7 @@
337
364
  const exporter = (exports) => {
338
365
  Object.assign(exports, { logOperationStart, logOperationEnd });
339
366
  };
340
- define('lwr/profiler/v/0_17_2-alpha_3', ['exports'], exporter);
367
+ define('lwr/profiler/v/0_17_2-alpha_30', ['exports'], exporter);
341
368
  }
342
369
 
343
370
  // Set up the application globals, import map, root custom element...
@@ -365,8 +392,9 @@
365
392
  }
366
393
  });
367
394
 
368
- // by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
369
- const { disableInitDefer } = this.config;
395
+ // by default, app initialization is gated on waiting for body to be available
396
+ // this flag uses the DOMContentLoaded event instead
397
+ const { initDeferDOM } = this.config;
370
398
 
371
399
  // Load the import mappings and application bootstrap module
372
400
  loader
@@ -375,9 +403,14 @@
375
403
  rootComponent ,
376
404
  ])
377
405
  .then(() => {
378
- if (!disableInitDefer) {
406
+ // eslint-disable-next-line lwr/no-unguarded-apis
407
+ if (typeof window === 'undefined' || typeof document === undefined) {
408
+ return Promise.resolve();
409
+ }
410
+ if (initDeferDOM) {
379
411
  return this.waitForDOMContentLoaded();
380
412
  }
413
+ return this.waitForBody();
381
414
  })
382
415
  .then(() => loader.load(bootstrapModule))
383
416
  .catch((reason) => {
@@ -409,13 +442,22 @@
409
442
  this.enterErrorState(new Error('Failed to load required modules - timed out'));
410
443
  }, REQUIRED_MODULES_TIMEOUT);
411
444
  }
445
+
446
+ logWarnings(warnings) {
447
+ for (const warningKey in warnings) {
448
+ if (warnings[warningKey].length) {
449
+ // eslint-disable-next-line lwr/no-unguarded-apis
450
+ console.warn(warningKey, warnings[warningKey]);
451
+ }
452
+ }
453
+ }
412
454
  }
413
455
 
414
456
  // The loader module is ALWAYS required
415
457
  const GLOBAL = globalThis ;
416
458
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
417
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_17_2-alpha_3') < 0) {
418
- GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_17_2-alpha_3');
459
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_17_2-alpha_30') < 0) {
460
+ GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_17_2-alpha_30');
419
461
  }
420
462
  new LoaderShim(GLOBAL);
421
463
 
@@ -8,6 +8,13 @@ var __export = (target, all) => {
8
8
  // packages/@lwrjs/loader/src/modules/lwr/loader/constants/constants.ts
9
9
  __markAsModule(exports);
10
10
  __export(exports, {
11
- MODULE_LOAD_TIMEOUT_TIMER: () => MODULE_LOAD_TIMEOUT_TIMER
11
+ MODULE_LOAD_TIMEOUT_TIMER: () => MODULE_LOAD_TIMEOUT_TIMER,
12
+ MODULE_WARNING: () => MODULE_WARNING
12
13
  });
13
14
  var MODULE_LOAD_TIMEOUT_TIMER = 60 * 1e3;
15
+ var MODULE_WARNING;
16
+ (function(MODULE_WARNING2) {
17
+ MODULE_WARNING2["MODULE_REDEFINE"] = "Module redefine attempted";
18
+ MODULE_WARNING2["MODULE_ALREADY_LOADED"] = "Marking module(s) as externally loaded, but they are already loaded";
19
+ MODULE_WARNING2["ALIAS_UPDATE"] = "Alias update attempt";
20
+ })(MODULE_WARNING || (MODULE_WARNING = {}));
@@ -171,9 +171,9 @@ var ImportMetadataResolver = class {
171
171
  }
172
172
  return res.json().then((ret) => {
173
173
  return ret;
174
- }).catch((err) => {
175
- throw new import_messages.LoaderError(import_messages.UNRESOLVED, [specifier]);
176
174
  });
175
+ }).catch((err) => {
176
+ throw new import_messages.LoaderError(import_messages.UNRESOLVED, [specifier]);
177
177
  });
178
178
  }
179
179
  saveImportURIRecord(specifier, uri, identity, isRoot) {
@@ -37,11 +37,17 @@ var import_metrics = __toModule(require("lwr/metrics"));
37
37
  var import_constants = __toModule(require("../constants/constants.cjs"));
38
38
  var ModuleRegistry = class {
39
39
  constructor(config) {
40
+ this.isAppMounted = false;
40
41
  this.namedDefineRegistry = new Map();
41
42
  this.moduleRegistry = new Map();
42
43
  this.aliases = new Map();
43
44
  this.profiler = config.profiler;
44
45
  this.resolver = new import_importMetadataResolver.ImportMetadataResolver(config, this.importMetadataInvalidationCallback.bind(this));
46
+ this.warnings = {
47
+ [import_constants.MODULE_WARNING.MODULE_REDEFINE]: [],
48
+ [import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
49
+ [import_constants.MODULE_WARNING.ALIAS_UPDATE]: []
50
+ };
45
51
  }
46
52
  async load(id, importer) {
47
53
  const metadata = importer ? {importer} : {};
@@ -143,8 +149,13 @@ var ModuleRegistry = class {
143
149
  define(name, dependencies, exporter) {
144
150
  const mod = this.namedDefineRegistry.get(name);
145
151
  if (mod && mod.defined) {
146
- if (import_dom.hasProcessEnv && process.env.NODE_ENV !== "production" && process.env.MRT_HMR !== "true" && import_dom.hasConsole) {
147
- console.warn(`Module redefine attempted: ${name}`);
152
+ if (import_dom.hasProcessEnv && process.env.NODE_ENV !== "production" && process.env.MRT_HMR !== "true") {
153
+ if (!this.warnings[import_constants.MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
154
+ this.warnings[import_constants.MODULE_WARNING.MODULE_REDEFINE].push(name);
155
+ }
156
+ if (this.isAppMounted) {
157
+ this.logMessage("warning", `${import_constants.MODULE_WARNING.MODULE_REDEFINE}: ${name}`);
158
+ }
148
159
  }
149
160
  this.lastDefine = mod;
150
161
  return;
@@ -184,8 +195,13 @@ var ModuleRegistry = class {
184
195
  }
185
196
  };
186
197
  this.namedDefineRegistry.set(id, moduleDef);
187
- } else if (process.env.NODE_ENV !== "production" && import_dom.hasConsole) {
188
- console.warn(import_messages.MODULE_ALREADY_LOADED.message, id);
198
+ } else if (process.env.NODE_ENV !== "production") {
199
+ if (!this.warnings[import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
200
+ this.warnings[import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
201
+ }
202
+ if (this.isAppMounted) {
203
+ this.logMessage("warning", `${import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED}: ${id}`);
204
+ }
189
205
  }
190
206
  });
191
207
  }
@@ -245,15 +261,26 @@ var ModuleRegistry = class {
245
261
  } else if (process.env.NODE_ENV !== "production" && import_dom.hasConsole) {
246
262
  const currentResolvedId = this.aliases.get(aliasId);
247
263
  if (currentResolvedId !== resolvedId) {
248
- if (process.env.NODE_ENV !== "production" && import_dom.hasConsole) {
249
- console.warn(`Alias update attempt: ${aliasId}=>${currentResolvedId}, ${resolvedId}`);
264
+ const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
265
+ if (!this.warnings[import_constants.MODULE_WARNING.ALIAS_UPDATE].includes(warningMsg)) {
266
+ this.warnings[import_constants.MODULE_WARNING.ALIAS_UPDATE].push(warningMsg);
267
+ }
268
+ if (this.isAppMounted) {
269
+ this.logMessage("warning", `${import_constants.MODULE_WARNING.ALIAS_UPDATE}: ${warningMsg}`);
250
270
  }
251
271
  }
252
272
  }
253
273
  }
254
274
  }
255
275
  async getModuleDependencyRecord(dependency) {
256
- const resolvedDepId = await this.resolve(dependency);
276
+ let resolvedDepId = await this.resolve(dependency);
277
+ if ((0, import_url.isUrl)(resolvedDepId)) {
278
+ const existingRecord = this.moduleRegistry.get(resolvedDepId);
279
+ if (existingRecord && !this.aliases.has(dependency)) {
280
+ await existingRecord.instantiation;
281
+ resolvedDepId = await this.resolve(dependency);
282
+ }
283
+ }
257
284
  return this.getModuleRecord(resolvedDepId, dependency);
258
285
  }
259
286
  async topLevelEvaluation(moduleRecord) {
@@ -395,6 +422,7 @@ var ModuleRegistry = class {
395
422
  }).then(() => {
396
423
  moduleDef = moduleName && this.namedDefineRegistry.get(moduleName);
397
424
  if (!moduleDef) {
425
+ this.logMessage("warning", `${moduleName} not found, falling back to the last loader.define call`);
398
426
  moduleDef = this.lastDefine;
399
427
  }
400
428
  if (!moduleDef) {
@@ -456,4 +484,18 @@ var ModuleRegistry = class {
456
484
  isValidResolveResponse(res) {
457
485
  return res === null || typeof res === "string" || res && typeof res.url === "string";
458
486
  }
487
+ getModuleWarnings(isAppMounted = false) {
488
+ this.isAppMounted = isAppMounted;
489
+ return this.warnings;
490
+ }
491
+ logMessage(logType, message) {
492
+ if (!import_dom.hasProcessEnv || !import_dom.hasConsole || process.env.NODE_ENV === "production") {
493
+ return;
494
+ }
495
+ if (logType == "warning") {
496
+ console.warn(message);
497
+ } else {
498
+ console.log(message);
499
+ }
500
+ }
459
501
  };
@@ -8,6 +8,13 @@ var __export = (target, all) => {
8
8
  // packages/@lwrjs/loader/src/modules/lwr/loaderLegacy/constants/constants.ts
9
9
  __markAsModule(exports);
10
10
  __export(exports, {
11
- MODULE_LOAD_TIMEOUT_TIMER: () => MODULE_LOAD_TIMEOUT_TIMER
11
+ MODULE_LOAD_TIMEOUT_TIMER: () => MODULE_LOAD_TIMEOUT_TIMER,
12
+ MODULE_WARNING: () => MODULE_WARNING
12
13
  });
13
14
  var MODULE_LOAD_TIMEOUT_TIMER = 60 * 1e3;
15
+ var MODULE_WARNING;
16
+ (function(MODULE_WARNING2) {
17
+ MODULE_WARNING2["MODULE_REDEFINE"] = "Module redefine attempted";
18
+ MODULE_WARNING2["MODULE_ALREADY_LOADED"] = "Marking module(s) as externally loaded, but they are already loaded";
19
+ MODULE_WARNING2["ALIAS_UPDATE"] = "Alias update attempt";
20
+ })(MODULE_WARNING || (MODULE_WARNING = {}));
@@ -36,11 +36,17 @@ var import_constants = __toModule(require("../constants/constants.cjs"));
36
36
  var import_metrics = __toModule(require("lwr/metrics"));
37
37
  var ModuleRegistry = class {
38
38
  constructor(config) {
39
+ this.isAppMounted = false;
39
40
  this.namedDefineRegistry = new Map();
40
41
  this.moduleRegistry = new Map();
41
42
  this.aliases = new Map();
42
43
  this.baseUrl = config.baseUrl || "";
43
44
  this.profiler = config.profiler;
45
+ this.warnings = {
46
+ [import_constants.MODULE_WARNING.MODULE_REDEFINE]: [],
47
+ [import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
48
+ [import_constants.MODULE_WARNING.ALIAS_UPDATE]: []
49
+ };
44
50
  }
45
51
  clearRegistry() {
46
52
  this.moduleRegistry = new Map();
@@ -142,8 +148,13 @@ var ModuleRegistry = class {
142
148
  define(name, dependencies, exporter, signatures) {
143
149
  const mod = this.namedDefineRegistry.get(name);
144
150
  if (mod && mod.defined) {
145
- if (import_dom.hasProcessEnv && process.env.NODE_ENV !== "production" && process.env.MRT_HMR !== "true" && import_dom.hasConsole) {
146
- console.warn(`Module redefine attempted: ${name}`);
151
+ if (import_dom.hasProcessEnv && process.env.NODE_ENV !== "production" && process.env.MRT_HMR !== "true") {
152
+ if (!this.warnings[import_constants.MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
153
+ this.warnings[import_constants.MODULE_WARNING.MODULE_REDEFINE].push(name);
154
+ }
155
+ if (this.isAppMounted) {
156
+ this.logMessage("warning", `${import_constants.MODULE_WARNING.MODULE_REDEFINE}: ${name}`);
157
+ }
147
158
  }
148
159
  this.lastDefine = mod;
149
160
  return;
@@ -189,8 +200,13 @@ var ModuleRegistry = class {
189
200
  }
190
201
  };
191
202
  this.namedDefineRegistry.set(id, moduleDef);
192
- } else if (process.env.NODE_ENV !== "production" && import_dom.hasConsole) {
193
- console.warn(import_messages.MODULE_ALREADY_LOADED.message, id);
203
+ } else if (process.env.NODE_ENV !== "production") {
204
+ if (!this.warnings[import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
205
+ this.warnings[import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
206
+ }
207
+ if (this.isAppMounted) {
208
+ this.logMessage("warning", `${import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED}: ${id}`);
209
+ }
194
210
  }
195
211
  });
196
212
  }
@@ -276,18 +292,29 @@ var ModuleRegistry = class {
276
292
  if (aliasId !== resolvedId) {
277
293
  if (!this.aliases.has(aliasId)) {
278
294
  this.aliases.set(aliasId, resolvedId);
279
- } else if (import_dom.hasConsole) {
295
+ } else if (import_dom.hasConsole && process.env.NODE_ENV !== "production") {
280
296
  const currentResolvedId = this.aliases.get(aliasId);
281
297
  if (currentResolvedId !== resolvedId) {
282
- if (process.env.NODE_ENV !== "production" && import_dom.hasConsole) {
283
- console.warn(`Alias update attempt: ${aliasId}=>${currentResolvedId}, ${resolvedId}`);
298
+ const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
299
+ if (!this.warnings[import_constants.MODULE_WARNING.ALIAS_UPDATE].includes(warningMsg)) {
300
+ this.warnings[import_constants.MODULE_WARNING.ALIAS_UPDATE].push(warningMsg);
301
+ }
302
+ if (this.isAppMounted) {
303
+ this.logMessage("warning", `${import_constants.MODULE_WARNING.ALIAS_UPDATE}: ${warningMsg}`);
284
304
  }
285
305
  }
286
306
  }
287
307
  }
288
308
  }
289
309
  async getModuleDependencyRecord(dependency) {
290
- const resolvedDepId = await this.resolve(dependency);
310
+ let resolvedDepId = await this.resolve(dependency);
311
+ if ((0, import_url.isUrl)(resolvedDepId)) {
312
+ const existingRecord = this.moduleRegistry.get(resolvedDepId);
313
+ if (existingRecord && !this.aliases.has(dependency)) {
314
+ await existingRecord.instantiation;
315
+ resolvedDepId = await this.resolve(dependency);
316
+ }
317
+ }
291
318
  return this.getModuleRecord(resolvedDepId, dependency);
292
319
  }
293
320
  async topLevelEvaluation(moduleRecord) {
@@ -429,6 +456,7 @@ var ModuleRegistry = class {
429
456
  }).then(() => {
430
457
  moduleDef = moduleName && this.namedDefineRegistry.get(moduleName);
431
458
  if (!moduleDef) {
459
+ this.logMessage("warning", `${moduleName} not found, falling back to the last loader.define call`);
432
460
  moduleDef = this.lastDefine;
433
461
  }
434
462
  if (!moduleDef) {
@@ -473,4 +501,18 @@ var ModuleRegistry = class {
473
501
  isValidResolveResponse(res) {
474
502
  return res === null || typeof res === "string" || res && typeof res.url === "string";
475
503
  }
504
+ getModuleWarnings(isAppMounted = false) {
505
+ this.isAppMounted = isAppMounted;
506
+ return this.warnings;
507
+ }
508
+ logMessage(logType, message) {
509
+ if (!import_dom.hasProcessEnv || !import_dom.hasConsole || process.env.NODE_ENV === "production") {
510
+ return;
511
+ }
512
+ if (logType == "warning") {
513
+ console.warn(message);
514
+ } else {
515
+ console.log(message);
516
+ }
517
+ }
476
518
  };
@@ -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 ESM Module Loader v0.17.2-alpha.3 */
7
+ /* LWR ESM Module Loader v0.17.2-alpha.30 */
8
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
9
 
10
10
 
@@ -1,2 +1,7 @@
1
1
  export declare const MODULE_LOAD_TIMEOUT_TIMER: number;
2
+ export declare enum MODULE_WARNING {
3
+ MODULE_REDEFINE = "Module redefine attempted",
4
+ MODULE_ALREADY_LOADED = "Marking module(s) as externally loaded, but they are already loaded",
5
+ ALIAS_UPDATE = "Alias update attempt"
6
+ }
2
7
  //# sourceMappingURL=constants.d.ts.map
@@ -1,2 +1,8 @@
1
1
  export const MODULE_LOAD_TIMEOUT_TIMER = 60 * 1000; // 1m
2
+ export var MODULE_WARNING;
3
+ (function (MODULE_WARNING) {
4
+ MODULE_WARNING["MODULE_REDEFINE"] = "Module redefine attempted";
5
+ MODULE_WARNING["MODULE_ALREADY_LOADED"] = "Marking module(s) as externally loaded, but they are already loaded";
6
+ MODULE_WARNING["ALIAS_UPDATE"] = "Alias update attempt";
7
+ })(MODULE_WARNING || (MODULE_WARNING = {}));
2
8
  //# sourceMappingURL=constants.js.map
@@ -49,5 +49,6 @@ export declare class Loader {
49
49
  * @param modules - list of module identifiers
50
50
  */
51
51
  registerExternalModules(modules: string[]): void;
52
+ getModuleWarnings(isAppMounted?: boolean): Record<string, string[]>;
52
53
  }
53
54
  //# sourceMappingURL=loader.d.ts.map