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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,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 Legacy Module Loader Shim v0.12.0-alpha.0 */
7
+ /* LWR Legacy Module Loader Shim v0.12.0-alpha.10 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
@@ -207,7 +207,7 @@
207
207
  // Parse configuration
208
208
  this.global = global;
209
209
  this.config = global.LWR ;
210
- this.loaderModule = 'lwr/loaderLegacy/v/0_12_0-alpha_0';
210
+ this.loaderModule = 'lwr/loaderLegacy/v/0_12_0-alpha_10';
211
211
 
212
212
  // Set up error handler
213
213
  this.errorHandler = this.config.onError;
@@ -327,7 +327,7 @@
327
327
  const exporter = (exports) => {
328
328
  Object.assign(exports, { logOperationStart, logOperationEnd });
329
329
  };
330
- globalLWR.define('lwr/profiler/v/0_12_0-alpha_0', ['exports'], exporter, {});
330
+ globalLWR.define('lwr/profiler/v/0_12_0-alpha_10', ['exports'], exporter, {});
331
331
  }
332
332
 
333
333
  // Set up the application globals, import map, root custom element...
@@ -398,10 +398,9 @@
398
398
  // The loader module is ALWAYS required
399
399
  const GLOBAL = globalThis ;
400
400
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
401
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_12_0-alpha_0') < 0) {
402
- GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_12_0-alpha_0');
401
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_12_0-alpha_10') < 0) {
402
+ GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_12_0-alpha_10');
403
403
  }
404
404
  new LoaderShim(GLOBAL);
405
405
 
406
406
  })();
407
- //# sourceMappingURL=lwr-loader-shim-legacy.js.map
@@ -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.12.0-alpha.0 */
7
+ /* LWR Module Loader Shim v0.12.0-alpha.10 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
@@ -205,7 +205,7 @@
205
205
  // Parse configuration
206
206
  this.global = global;
207
207
  this.config = global.LWR ;
208
- this.loaderSpecifier = 'lwr/loader/v/0_12_0-alpha_0';
208
+ this.loaderSpecifier = 'lwr/loader/v/0_12_0-alpha_10';
209
209
 
210
210
  // Set up error handler
211
211
  this.errorHandler = this.config.onError;
@@ -326,7 +326,7 @@
326
326
  const exporter = (exports) => {
327
327
  Object.assign(exports, { logOperationStart, logOperationEnd });
328
328
  };
329
- globalLWR.define('lwr/profiler/v/0_12_0-alpha_0', ['exports'], exporter);
329
+ globalLWR.define('lwr/profiler/v/0_12_0-alpha_10', ['exports'], exporter);
330
330
  }
331
331
 
332
332
  // Set up the application globals, import map, root custom element...
@@ -398,14 +398,14 @@
398
398
  // The loader module is ALWAYS required
399
399
  const GLOBAL = globalThis ;
400
400
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
401
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_12_0-alpha_0') < 0) {
402
- GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_12_0-alpha_0');
401
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_12_0-alpha_10') < 0) {
402
+ GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_12_0-alpha_10');
403
403
  }
404
404
  new LoaderShim(GLOBAL);
405
405
 
406
406
  })();
407
407
 
408
- LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'use strict';
408
+ LWR.define('lwr/loader/v/0_12_0-alpha_10', ['exports'], (function (exports) { 'use strict';
409
409
 
410
410
  const templateRegex = /\{([0-9]+)\}/g;
411
411
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1048,7 +1048,7 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1048
1048
  // swallow
1049
1049
  }
1050
1050
  const trusted = createPolicy('trusted', policyOptions);
1051
- /*! version: 0.20.6 */
1051
+ /*! version: 0.21.0 */
1052
1052
 
1053
1053
  /* global console,process */
1054
1054
 
@@ -1200,13 +1200,22 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1200
1200
 
1201
1201
 
1202
1202
 
1203
-
1204
-
1205
1203
 
1206
1204
 
1207
1205
 
1208
1206
  class ModuleRegistry {
1209
1207
 
1208
+
1209
+ // A registry for named AMD defines containing the *metadata* of AMD module
1210
+ __init() {this.namedDefineRegistry = new Map();}
1211
+ // The evaluated module registry where the module identifier (name or URL?) is the key
1212
+ __init2() {this.moduleRegistry = new Map();}
1213
+ // Aliases of modules in the registry
1214
+ __init3() {this.aliases = new Map();}
1215
+
1216
+
1217
+
1218
+
1210
1219
 
1211
1220
  constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);
1212
1221
  this.profiler = config.profiler;
@@ -1216,6 +1225,9 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1216
1225
  );
1217
1226
  }
1218
1227
 
1228
+ /**
1229
+ * Module import
1230
+ */
1219
1231
  async load(id, importer) {
1220
1232
  const metadata = importer ? { importer } : {};
1221
1233
  this.profiler.logOperationStart({
@@ -1223,18 +1235,23 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1223
1235
  specifier: id,
1224
1236
  metadata,
1225
1237
  });
1238
+
1226
1239
  const resolvedId = await this.resolve(id, importer);
1227
- const moduleRecord = await this.getModuleRecord(resolvedId, id);
1240
+ const moduleRecord = this.getModuleRecord(resolvedId, id);
1241
+
1228
1242
  if (moduleRecord.evaluated) {
1229
1243
  return moduleRecord.module;
1230
1244
  } else {
1231
1245
  if (!moduleRecord.evaluationPromise) {
1232
- moduleRecord.evaluationPromise = this.topLevelEvaluation(moduleRecord);
1246
+ moduleRecord.evaluationPromise = this.evaluateModule(moduleRecord, {});
1233
1247
  }
1234
1248
  return moduleRecord.evaluationPromise;
1235
1249
  }
1236
1250
  }
1237
1251
 
1252
+ /**
1253
+ * Resolve id for a module
1254
+ */
1238
1255
  async resolve(id, importer) {
1239
1256
  const parentUrl = this.resolver.getBaseUrl(); // only support baseUrl for now
1240
1257
 
@@ -1250,7 +1267,7 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1250
1267
  // eslint-disable-next-line no-await-in-loop
1251
1268
  result = isResponseAPromise(response) ? await response : response;
1252
1269
  }
1253
- if (!this.isValidResolveResponse(result)) {
1270
+ if (!isValidResolveResponse(result)) {
1254
1271
  throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);
1255
1272
  }
1256
1273
 
@@ -1336,6 +1353,9 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1336
1353
  return this.moduleRegistry.has(id);
1337
1354
  }
1338
1355
 
1356
+ /**
1357
+ * Module entry point LWR.define()
1358
+ */
1339
1359
  define(name, dependencies, exporter) {
1340
1360
  const mod = this.namedDefineRegistry.get(name);
1341
1361
  // Don't allow redefining a module.
@@ -1402,19 +1422,6 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1402
1422
  });
1403
1423
  }
1404
1424
 
1405
-
1406
-
1407
- // A registry for named AMD defines containing the *metadata* of AMD module
1408
- __init() {this.namedDefineRegistry = new Map();}
1409
-
1410
- // The evaluated module registry where the module identifier (name or URL?) is the key
1411
- __init2() {this.moduleRegistry = new Map();}
1412
-
1413
- // Aliases of modules in the registry
1414
- __init3() {this.aliases = new Map();}
1415
-
1416
-
1417
-
1418
1425
  getImportMetadataResolver() {
1419
1426
  return this.resolver;
1420
1427
  }
@@ -1440,7 +1447,7 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1440
1447
  return moduleRecord;
1441
1448
  }
1442
1449
 
1443
- async getModuleRecord(resolvedId, id) {
1450
+ getModuleRecord(resolvedId, id) {
1444
1451
  // Look for an existing record
1445
1452
  const existingRecord = this.getExistingModuleRecord(resolvedId, id);
1446
1453
  if (existingRecord) {
@@ -1448,29 +1455,10 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1448
1455
  return existingRecord;
1449
1456
  }
1450
1457
 
1451
- // Create a new Module Record
1452
- const instantiation = this.getModuleDef(resolvedId, id);
1453
- const dependencyRecords = instantiation.then((moduleDef) => {
1454
- const dependencies = moduleDef.dependencies || [];
1455
- // get dep and filter out exports
1456
- const filtered = dependencies
1457
- .map((dep) => {
1458
- if (dep === 'exports') {
1459
- return;
1460
- }
1461
- invariant(dep !== 'require', NO_AMD_REQUIRE);
1462
- return this.getModuleDependencyRecord.call(this, dep);
1463
- })
1464
- .filter((depRecord) => depRecord !== undefined) ;
1465
-
1466
- return Promise.all(filtered);
1467
- });
1468
-
1469
1458
  const newModuleRecord = {
1470
1459
  id: resolvedId,
1471
1460
  module: Object.create(null),
1472
- dependencyRecords,
1473
- instantiation,
1461
+ instantiation: this.getModuleDef(resolvedId, id),
1474
1462
  evaluated: false,
1475
1463
  evaluationPromise: null,
1476
1464
  };
@@ -1478,8 +1466,7 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1478
1466
  this.moduleRegistry.set(resolvedId, newModuleRecord);
1479
1467
  this.storeModuleAlias(id, resolvedId);
1480
1468
 
1481
- // Wait for the dependencies to resolve the return the moduleRecord
1482
- return dependencyRecords.then(() => newModuleRecord);
1469
+ return newModuleRecord;
1483
1470
  }
1484
1471
 
1485
1472
  storeModuleAlias(aliasId, resolvedId) {
@@ -1500,95 +1487,87 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1500
1487
  }
1501
1488
  }
1502
1489
 
1503
- async getModuleDependencyRecord(dependency) {
1504
- const resolvedDepId = await this.resolve(dependency);
1505
- return this.getModuleRecord(resolvedDepId, dependency);
1506
- }
1490
+ /**
1491
+ * Evaluate all module dependencies
1492
+ */
1493
+ async evaluateDependencies(
1494
+ dependencies,
1495
+ evaluationMap,
1496
+ ) {
1497
+ const exports = {};
1498
+ const promiseArray = [];
1499
+
1500
+ if (dependencies) {
1501
+ for (const dep of dependencies) {
1502
+ if (dep === 'exports') {
1503
+ promiseArray.push(Promise.resolve(exports));
1504
+ } else {
1505
+ invariant(dep !== 'require', NO_AMD_REQUIRE);
1506
+ promiseArray.push(this.evaluateDependent(dep, evaluationMap));
1507
+ }
1508
+ }
1509
+ }
1507
1510
 
1508
- // execute the "top-level code" (the code outside of functions) of a module
1509
- async topLevelEvaluation(moduleRecord) {
1510
- await this.instantiateAll(moduleRecord, {});
1511
- return this.evaluateModule(moduleRecord, {});
1511
+ return Promise.all(promiseArray).then((results) => {
1512
+ const depsMapped = results.filter((result) => result !== undefined);
1513
+ return { depsMapped, exports };
1514
+ });
1512
1515
  }
1513
1516
 
1514
- // Returns a promise when a module and all of it's dependencies have finished instantiation
1515
- async instantiateAll(
1516
- moduleRecord,
1517
- instantiatedMap,
1518
- ) {
1519
- if (!instantiatedMap[moduleRecord.id]) {
1520
- instantiatedMap[moduleRecord.id] = true;
1521
- const dependencyModuleRecords = await moduleRecord.dependencyRecords;
1522
- if (dependencyModuleRecords) {
1523
- for (let i = 0; i < dependencyModuleRecords.length; i++) {
1524
- const depRecord = dependencyModuleRecords[i];
1525
- // eslint-disable-next-line no-await-in-loop
1526
- await this.instantiateAll(depRecord, instantiatedMap);
1527
- }
1517
+ async evaluateDependent(dep, evaluationMap) {
1518
+ const resolvedDepId = await this.resolve(dep);
1519
+
1520
+ const depModuleRecord = this.getModuleRecord(resolvedDepId, dep);
1521
+ let module = depModuleRecord.module;
1522
+
1523
+ const handleReturn = (module) => {
1524
+ if (module) {
1525
+ return module.__defaultInterop ? module.default : module;
1528
1526
  }
1527
+ throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1528
+ };
1529
+
1530
+ // If evaluated return the module
1531
+ if (depModuleRecord.evaluated) {
1532
+ return handleReturn(module);
1533
+ }
1534
+ /**
1535
+ * Circular dependencies are handled properly when named exports are used,
1536
+ * however, for default exports there is a bug: https://github.com/rollup/rollup/issues/3384
1537
+ *
1538
+ * The workaround below applies for circular dependencies (!moduleRecord.evaluated)
1539
+ */
1540
+ if (!evaluationMap[depModuleRecord.id]) {
1541
+ // If we have not started dependency evaluation kick it off
1542
+ if (!depModuleRecord.evaluationPromise) {
1543
+ depModuleRecord.evaluationPromise = this.evaluateModule(depModuleRecord, evaluationMap);
1544
+ }
1545
+ return depModuleRecord.evaluationPromise.then((module) => {
1546
+ return handleReturn(module);
1547
+ });
1548
+ } else {
1549
+ // Otherwise return a dummy circular module wrapper
1550
+ module = getCircularDependencyWrapper(module);
1529
1551
  }
1552
+ return handleReturn(module);
1530
1553
  }
1531
1554
 
1532
1555
  async evaluateModule(
1533
1556
  moduleRecord,
1534
1557
  evaluationMap,
1535
1558
  ) {
1536
- const dependencyModuleRecords = await moduleRecord.dependencyRecords;
1537
- if (dependencyModuleRecords.length > 0) {
1538
- evaluationMap[moduleRecord.id] = true;
1539
- // evaluate dependencies first
1540
- await this.evaluateModuleDependencies(dependencyModuleRecords, evaluationMap);
1541
- }
1559
+ // Create a evaluationMap to detect cycles in this dep chain
1560
+ const chainMap = { ...evaluationMap };
1561
+ chainMap[moduleRecord.id] = true;
1542
1562
 
1563
+ // Wait for load to finish
1543
1564
  const { exporter, dependencies } = await moduleRecord.instantiation;
1544
- // The exports object automatically gets filled in by the exporter evaluation
1545
- const exports = {};
1546
- const depsMapped = dependencies
1547
- ? await Promise.all(
1548
- dependencies.map(async (dep) => {
1549
- if (dep === 'exports') {
1550
- return exports;
1551
- }
1552
- const resolvedDepId = await this.resolve(dep);
1553
-
1554
- const moduleRecord = this.moduleRegistry.get(resolvedDepId) ;
1555
- if (!moduleRecord) {
1556
- throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1557
- }
1558
-
1559
- const module = moduleRecord.module;
1560
-
1561
- /**
1562
- * Circular dependencies are handled properly when named exports are used,
1563
- * however, for default exports there is a bug: https://github.com/rollup/rollup/issues/3384
1564
- *
1565
- * The workaround below applies for circular dependencies (!moduleRecord.evaluated)
1566
- */
1567
- if (!moduleRecord.evaluated) {
1568
- return this.getCircularDependencyWrapper(module);
1569
- }
1570
-
1571
- if (module) {
1572
- return module.__defaultInterop ? module.default : module;
1573
- }
1574
-
1575
- throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1576
- }),
1577
- )
1578
- : [];
1579
-
1580
- // W-10029836 - In the case where we could be instantiating multiple graphs at the same time lets make sure the module have not already been evaluated
1581
- if (moduleRecord.evaluated) {
1582
- return moduleRecord.module;
1583
- }
1565
+
1566
+ // Evaluate all it's dependents
1567
+ const { depsMapped, exports } = await this.evaluateDependencies(dependencies, chainMap);
1584
1568
 
1585
1569
  // evaluates the module function
1586
- let moduleDefault;
1587
- try {
1588
- moduleDefault = exporter(...depsMapped);
1589
- } catch (e) {
1590
- throw new LoaderError(EXPORTER_ERROR, [moduleRecord.id, e.message || e]);
1591
- }
1570
+ let moduleDefault = this.evaluateModuleCode(exporter, depsMapped, moduleRecord);
1592
1571
  // value is returned from exporter, then we are not using named exports
1593
1572
  if (moduleDefault !== undefined) {
1594
1573
  moduleDefault = { default: moduleDefault };
@@ -1600,7 +1579,7 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1600
1579
  // if no return value, then we are using the exports object
1601
1580
  else {
1602
1581
  // handle only default export with Rollup forced named exports
1603
- if (this.isNamedExportDefaultOnly(exports)) {
1582
+ if (isNamedExportDefaultOnly(exports)) {
1604
1583
  Object.defineProperty(exports, '__useDefault', { value: true });
1605
1584
  }
1606
1585
  }
@@ -1632,42 +1611,17 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1632
1611
  Object.defineProperty(moduleRecord.module, '__esModule', { value: true });
1633
1612
  }
1634
1613
 
1635
- moduleRecord.evaluated = true;
1636
1614
  Object.freeze(moduleRecord.module);
1615
+ moduleRecord.evaluated = true;
1616
+ moduleRecord.evaluationPromise = null;
1637
1617
  return moduleRecord.module;
1638
1618
  }
1639
1619
 
1640
- // Determines if named exports module has only default export
1641
- isNamedExportDefaultOnly(exports) {
1642
- return (
1643
- exports !== undefined &&
1644
- Object.getOwnPropertyNames(exports).length === 2 &&
1645
- Object.prototype.hasOwnProperty.call(exports, 'default') &&
1646
- Object.prototype.hasOwnProperty.call(exports, '__esModule')
1647
- );
1648
- }
1649
-
1650
- // Wrap the dependency in a function that can be called and detected by __circular__ property.
1651
- // The LWC engine checks for __circular__ to detect circular dependencies.
1652
- getCircularDependencyWrapper(module) {
1653
- const tmp = () => {
1654
- return module.__useDefault || module.__defaultInterop ? module.default : module;
1655
- };
1656
- tmp.__circular__ = true;
1657
- return tmp;
1658
- }
1659
-
1660
- async evaluateModuleDependencies(
1661
- dependencyModuleRecords,
1662
- evaluationMap,
1663
- ) {
1664
- for (let i = 0; i < dependencyModuleRecords.length; i++) {
1665
- const depRecord = dependencyModuleRecords[i];
1666
- if (!depRecord.evaluated && !evaluationMap[depRecord.id]) {
1667
- evaluationMap[depRecord.id] = true;
1668
- // eslint-disable-next-line no-await-in-loop
1669
- await this.evaluateModule(depRecord, evaluationMap);
1670
- }
1620
+ evaluateModuleCode(evaluatedExporter, depsMapped, moduleRecord) {
1621
+ try {
1622
+ return evaluatedExporter(...depsMapped);
1623
+ } catch (e) {
1624
+ throw new LoaderError(EXPORTER_ERROR, [moduleRecord.id, e.message || e]);
1671
1625
  }
1672
1626
  }
1673
1627
 
@@ -1747,9 +1701,6 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1747
1701
  });
1748
1702
  }
1749
1703
 
1750
-
1751
-
1752
-
1753
1704
  addLoaderPlugin(hooks) {
1754
1705
  if (typeof hooks !== 'object') {
1755
1706
  throw new LoaderError(INVALID_HOOK);
@@ -1791,7 +1742,6 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1791
1742
  }
1792
1743
  }
1793
1744
 
1794
-
1795
1745
  registerHandleStaleModuleHook(handleStaleModule) {
1796
1746
  if (this.handleStaleModuleHook) {
1797
1747
  this.handleStaleModuleHook.push(handleStaleModule);
@@ -1799,12 +1749,30 @@ LWR.define('lwr/loader/v/0_12_0-alpha_0', ['exports'], (function (exports) { 'us
1799
1749
  this.handleStaleModuleHook = [handleStaleModule];
1800
1750
  }
1801
1751
  }
1752
+ }
1802
1753
 
1803
- isValidResolveResponse(res) {
1804
- return (
1805
- res === null || typeof res === 'string' || (res && typeof (res ).url === 'string')
1806
- );
1807
- }
1754
+ // Determines if named exports module has only default export
1755
+ function isNamedExportDefaultOnly(exports) {
1756
+ return (
1757
+ exports !== undefined &&
1758
+ Object.getOwnPropertyNames(exports).length === 2 &&
1759
+ Object.prototype.hasOwnProperty.call(exports, 'default') &&
1760
+ Object.prototype.hasOwnProperty.call(exports, '__esModule')
1761
+ );
1762
+ }
1763
+
1764
+ // Wrap the dependency in a function that can be called and detected by __circular__ property.
1765
+ // The LWC engine checks for __circular__ to detect circular dependencies.
1766
+ function getCircularDependencyWrapper(module) {
1767
+ const tmp = () => {
1768
+ return module.__useDefault || module.__defaultInterop ? module.default : module;
1769
+ };
1770
+ tmp.__circular__ = true;
1771
+ return tmp;
1772
+ }
1773
+
1774
+ function isValidResolveResponse(res) {
1775
+ return res === null || typeof res === 'string' || (res && typeof (res ).url === 'string');
1808
1776
  }
1809
1777
 
1810
1778
  /**
@@ -4,8 +4,8 @@
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.12.0-alpha.0 */
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_12_0-alpha_0",this.errorHandler=this.config.onError;const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot;try{this.createProfilerModule(this.config),c(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()&&(p&&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:l,logOperationEnd:d},serverData:this.config.serverData,appMetadata:{appId:this.config.appId,bootstrapModule:this.config.bootstrapModule,rootComponent:this.config.rootComponent,rootComponents:this.config.rootComponents}},t=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const i={};t[2].call(null,i);const{Loader:n}=i,s=new n(r);return o&&o.length&&s.registerExternalModules(o),s.define(e,["exports"],(e=>{Object.assign(e,{define:s.define.bind(s),load:s.load.bind(s),services:s.services})})),s}(this.loaderSpecifier,this.defineCache[this.loaderSpecifier],e,this.config.preloadModules);this.mountApp(t)}catch(e){this.enterErrorState(e)}}waitForDOMContentLoaded(){return void 0===typeof document||"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}createProfilerModule(e){e.define("lwr/profiler/v/0_12_0-alpha_0",["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;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,serverData:i,endpoints:n,imports:s||{},index:a||{}}),this.orderedDefs.forEach((t=>{t!==this.loaderSpecifier&&e.define(...this.defineCache[t])}));const{disableInitDefer:l}=this.config;e.registerImportMappings({imports:s,index:a},[t,r]).then((()=>{if(!l)return this.waitForDOMContentLoaded()})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r||t} could not be loaded: ${e}`))}))}enterErrorState(e){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_12_0-alpha_0")<0&&f.LWR.requiredModules.push("lwr/loader/v/0_12_0-alpha_0"),new h(f)}(),LWR.define("lwr/loader/v/0_12_0-alpha_0",["exports"],(function(exports){"use strict";const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"});Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded:"});const FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),NO_MAPPING_URL=Object.freeze({code:3019,level:0,message:"Mapping endpoint not set"}),BAD_IMPORT_METADATA=Object.freeze({code:3020,level:0,message:"Invalid import metadata: {0} {1}"}),EXPORTER_ERROR=Object.freeze({code:3021,level:0,message:'Error evaluating module "{0}", error was "{1}"'});Object.freeze({code:3011,level:0,message:"import map is not valid"});const hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const i=o.slice(0,o.lastIndexOf("/")+1)+e,n=[];let s=-1;for(let e=0;e<i.length;e++)-1!==s?"/"===i[e]&&(n.push(i.slice(s,e+1)),s=-1):"."===i[e]?"."!==i[e+1]||"/"!==i[e+2]&&e+2!==i.length?"/"===i[e+1]||e+1===i.length?e+=1:s=e:(n.pop(),e+=2):s=e;return-1!==s&&n.push(i.slice(s)),t.slice(0,t.length-o.length)+n.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const LOADER_PREFIX="lwr.loader.",MODULE_DEFINE=`${LOADER_PREFIX}module.define`,MODULE_DYNAMIC_LOAD=`${LOADER_PREFIX}moduleRegistry.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.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=6e4,SUPPORTS_TRUSTED_TYPES="undefined"!=typeof trustedTypes;
7
+ /* LWR Module Loader Shim v0.12.0-alpha.10 */
8
+ !function(){"use strict";var e=function(e){return e[e.Start=0]="Start",e[e.End=1]="End",e}(e||{});let t;function r(e){t=e}const o=globalThis.performance,i=void 0!==o&&"function"==typeof o.mark&&"function"==typeof o.clearMarks&&"function"==typeof o.measure&&"function"==typeof o.clearMeasures;function n(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_12_0-alpha_10",this.errorHandler=this.config.onError;const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot;try{this.createProfilerModule(this.config),c(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()&&(p&&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:l,logOperationEnd:d},serverData:this.config.serverData,appMetadata:{appId:this.config.appId,bootstrapModule:this.config.bootstrapModule,rootComponent:this.config.rootComponent,rootComponents:this.config.rootComponents}},t=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const i={};t[2].call(null,i);const{Loader:n}=i,s=new n(r);return o&&o.length&&s.registerExternalModules(o),s.define(e,["exports"],(e=>{Object.assign(e,{define:s.define.bind(s),load:s.load.bind(s),services:s.services})})),s}(this.loaderSpecifier,this.defineCache[this.loaderSpecifier],e,this.config.preloadModules);this.mountApp(t)}catch(e){this.enterErrorState(e)}}waitForDOMContentLoaded(){return void 0===typeof document||"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}createProfilerModule(e){e.define("lwr/profiler/v/0_12_0-alpha_10",["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;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,serverData:i,endpoints:n,imports:s||{},index:a||{}}),this.orderedDefs.forEach((t=>{t!==this.loaderSpecifier&&e.define(...this.defineCache[t])}));const{disableInitDefer:l}=this.config;e.registerImportMappings({imports:s,index:a},[t,r]).then((()=>{if(!l)return this.waitForDOMContentLoaded()})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r||t} could not be loaded: ${e}`))}))}enterErrorState(e){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_12_0-alpha_10")<0&&f.LWR.requiredModules.push("lwr/loader/v/0_12_0-alpha_10"),new h(f)}(),LWR.define("lwr/loader/v/0_12_0-alpha_10",["exports"],(function(exports){"use strict";const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"});Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded:"});const FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),NO_MAPPING_URL=Object.freeze({code:3019,level:0,message:"Mapping endpoint not set"}),BAD_IMPORT_METADATA=Object.freeze({code:3020,level:0,message:"Invalid import metadata: {0} {1}"}),EXPORTER_ERROR=Object.freeze({code:3021,level:0,message:'Error evaluating module "{0}", error was "{1}"'});Object.freeze({code:3011,level:0,message:"import map is not valid"});const hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const i=o.slice(0,o.lastIndexOf("/")+1)+e,n=[];let s=-1;for(let e=0;e<i.length;e++)-1!==s?"/"===i[e]&&(n.push(i.slice(s,e+1)),s=-1):"."===i[e]?"."!==i[e+1]||"/"!==i[e+2]&&e+2!==i.length?"/"===i[e+1]||e+1===i.length?e+=1:s=e:(n.pop(),e+=2):s=e;return-1!==s&&n.push(i.slice(s)),t.slice(0,t.length-o.length)+n.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const LOADER_PREFIX="lwr.loader.",MODULE_DEFINE=`${LOADER_PREFIX}module.define`,MODULE_DYNAMIC_LOAD=`${LOADER_PREFIX}moduleRegistry.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.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=6e4,SUPPORTS_TRUSTED_TYPES="undefined"!=typeof trustedTypes;
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)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,serverData:e.serverData||{}})}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
+ */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{__init(){this.namedDefineRegistry=new Map}__init2(){this.moduleRegistry=new Map}__init3(){this.aliases=new Map}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=this.getModuleRecord(o,e);return i.evaluated?i.module:(i.evaluationPromise||(i.evaluationPromise=this.evaluateModule(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),!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)}}))}getImportMetadataResolver(){return this.resolver}getExistingModuleRecord(e,t){const r=this.moduleRegistry.get(e);if(r)return this.storeModuleAlias(t,e),r;if(e!==t){const e=this.aliases.get(t);if(e){const t=this.moduleRegistry.get(e);if(t)return t}}return r}getModuleRecord(e,t){const r=this.getExistingModuleRecord(e,t);if(r)return r;const o={id:e,module:Object.create(null),instantiation:this.getModuleDef(e,t),evaluated:!1,evaluationPromise:null};return this.moduleRegistry.set(e,o),this.storeModuleAlias(t,e),o}storeModuleAlias(e,t){e!==t&&(this.aliases.has(e)||this.aliases.set(e,t))}async evaluateDependencies(e,t){const r={},o=[];if(e)for(const i of e)"exports"===i?o.push(Promise.resolve(r)):(invariant("require"!==i,NO_AMD_REQUIRE),o.push(this.evaluateDependent(i,t)));return Promise.all(o).then((e=>({depsMapped:e.filter((e=>void 0!==e)),exports:r})))}async evaluateDependent(e,t){const r=await this.resolve(e),o=this.getModuleRecord(r,e);let i=o.module;const n=e=>{if(e)return e.__defaultInterop?e.default:e;throw new LoaderError(FAILED_DEP,[r])};return o.evaluated?n(i):t[o.id]?(i=getCircularDependencyWrapper(i),n(i)):(o.evaluationPromise||(o.evaluationPromise=this.evaluateModule(o,t)),o.evaluationPromise.then((e=>n(e))))}async evaluateModule(e,t){const r={...t};r[e.id]=!0;const{exporter:o,dependencies:i}=await e.instantiation,{depsMapped:n,exports:s}=await this.evaluateDependencies(i,r);let a=this.evaluateModuleCode(o,n,e);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):isNamedExportDefaultOnly(s)&&Object.defineProperty(s,"__useDefault",{value:!0});const l=a||s;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}),Object.freeze(e.module),e.evaluated=!0,e.evaluationPromise=null,e.module}evaluateModuleCode(e,t,r){try{return e(...t)}catch(e){throw new LoaderError(EXPORTER_ERROR,[r.id,e.message||e])}}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]}}function isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}function getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}function 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)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,serverData:e.serverData||{}})}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})}));