@rindo/core 3.1.0 → 3.2.1

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.
package/compiler/rindo.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Rindo Compiler v3.1.0 | MIT Licensed | https://rindojs.web.app
2
+ Rindo Compiler v3.2.1 | MIT Licensed | https://rindojs.web.app
3
3
  */
4
4
  (function(exports) {
5
5
  'use strict';
@@ -72,6 +72,97 @@ const DEFAULT_STYLE_MODE = '$';
72
72
  * File names and value
73
73
  */
74
74
  const COLLECTION_MANIFEST_FILE_NAME = 'collection-manifest.json';
75
+ /**
76
+ * Constant for the 'copy' output target
77
+ */
78
+ const COPY = 'copy';
79
+ /**
80
+ * Constant for the 'custom' output target
81
+ */
82
+ const CUSTOM = 'custom';
83
+ /**
84
+ * Constant for the 'dist' output target
85
+ */
86
+ const DIST = 'dist';
87
+ /**
88
+ * Constant for the 'dist-collection' output target
89
+ */
90
+ const DIST_COLLECTION = 'dist-collection';
91
+ /**
92
+ * Constant for the 'dist-custom-elements' output target
93
+ */
94
+ const DIST_CUSTOM_ELEMENTS = 'dist-custom-elements';
95
+ /**
96
+ * Constant for the 'dist-types' output target
97
+ */
98
+ const DIST_TYPES = 'dist-types';
99
+ /**
100
+ * Constant for the 'dist-hydrate-script' output target
101
+ */
102
+ const DIST_HYDRATE_SCRIPT = 'dist-hydrate-script';
103
+ /**
104
+ * Constant for the 'dist-lazy' output target
105
+ */
106
+ const DIST_LAZY = 'dist-lazy';
107
+ /**
108
+ * Constant for the 'dist-lazy-loader' output target
109
+ */
110
+ const DIST_LAZY_LOADER = 'dist-lazy-loader';
111
+ /**
112
+ * Constant for the 'dist-global-styles' output target
113
+ */
114
+ const DIST_GLOBAL_STYLES = 'dist-global-styles';
115
+ /**
116
+ * Constant for the 'docs-custom' output target
117
+ */
118
+ const DOCS_CUSTOM = 'docs-custom';
119
+ /**
120
+ * Constant for the 'docs-json' output target
121
+ */
122
+ const DOCS_JSON = 'docs-json';
123
+ /**
124
+ * Constant for the 'docs-readme' output target
125
+ */
126
+ const DOCS_README = 'docs-readme';
127
+ /**
128
+ * Constant for the 'docs-vscode' output target
129
+ */
130
+ const DOCS_VSCODE = 'docs-vscode';
131
+ /**
132
+ * Constant for the 'stats' output target
133
+ */
134
+ const STATS = 'stats';
135
+ /**
136
+ * Constant for the 'www' output target
137
+ */
138
+ const WWW = 'www';
139
+ /**
140
+ * Valid output targets to specify in a Rindo config.
141
+ *
142
+ * Note that there are some output targets (e.g. `DIST_TYPES`) which are
143
+ * programmatically set as output targets by the compiler when other output
144
+ * targets (in that case `DIST`) are set, but which are _not_ supported in a
145
+ * Rindo config. This is enforced in the output target validation code.
146
+ */
147
+ const VALID_CONFIG_OUTPUT_TARGETS = [
148
+ // DIST
149
+ WWW,
150
+ DIST,
151
+ DIST_COLLECTION,
152
+ DIST_CUSTOM_ELEMENTS,
153
+ DIST_LAZY,
154
+ DIST_HYDRATE_SCRIPT,
155
+ // DOCS
156
+ DOCS_JSON,
157
+ DOCS_README,
158
+ DOCS_VSCODE,
159
+ DOCS_CUSTOM,
160
+ // MISC
161
+ COPY,
162
+ CUSTOM,
163
+ STATS,
164
+ ];
165
+ const GENERATED_DTS = 'components.d.ts';
75
166
 
76
167
  /**
77
168
  * Transform metadata about a component from the compiler to a compact form for
@@ -1199,355 +1290,6 @@ const flattenDiagnosticMessageText = (tsDiagnostic, diag) => {
1199
1290
  return result.trim();
1200
1291
  };
1201
1292
 
1202
- /**
1203
- * Converts a rollup provided source map to one that Rindo can easily understand
1204
- * @param rollupSourceMap the sourcemap to transform
1205
- * @returns the transformed sourcemap
1206
- */
1207
- const rollupToRindoSourceMap = (rollupSourceMap) => {
1208
- if (!rollupSourceMap) {
1209
- return null;
1210
- }
1211
- return {
1212
- file: rollupSourceMap.file,
1213
- mappings: rollupSourceMap.mappings,
1214
- names: rollupSourceMap.names,
1215
- sources: rollupSourceMap.sources,
1216
- sourcesContent: rollupSourceMap.sourcesContent,
1217
- version: rollupSourceMap.version,
1218
- };
1219
- };
1220
- /**
1221
- * A JavaScript formatted string used to link generated code back to the original. This string follows the guidelines
1222
- * found in the [Linking generated code to source maps](https://sourcemaps.info/spec.html#h.lmz475t4mvbx) section of
1223
- * the Sourcemaps V3 specification proposal.
1224
- */
1225
- const JS_SOURCE_MAPPING_URL_LINKER = '//# sourceMappingURL=';
1226
- /**
1227
- * Generates an RFC-3986 compliant string for the given input.
1228
- * More information about RFC-3986 can be found [here](https://datatracker.ietf.org/doc/html/rfc3986)
1229
- * This function's original source is derived from
1230
- * [MDN's encodeURIComponent documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#description)
1231
- * @param filename the filename to encode
1232
- * @returns the encoded URI
1233
- */
1234
- const encodeToRfc3986 = (filename) => {
1235
- const encodedUri = encodeURIComponent(filename);
1236
- // replace all '!', single quotes, '(', ')', and '*' with their hexadecimal values (UTF-16)
1237
- return encodedUri.replace(/[!'()*]/g, (matchedCharacter) => {
1238
- return '%' + matchedCharacter.charCodeAt(0).toString(16);
1239
- });
1240
- };
1241
- /**
1242
- * Generates a string used to link generated code with the original source, to be placed at the end of the generated
1243
- * code.
1244
- * @param url the url of the source map
1245
- * @returns a linker string, of the format {@link JS_SOURCE_MAPPING_URL_LINKER}=<url>
1246
- */
1247
- const getSourceMappingUrlLinker = (url) => {
1248
- return `${JS_SOURCE_MAPPING_URL_LINKER}${encodeToRfc3986(url)}`;
1249
- };
1250
- /**
1251
- * Generates a string used to link generated code with the original source, to be placed at the end of the generated
1252
- * code as an inline source map.
1253
- * @param sourceMapContents the sourceMapContents of the source map
1254
- * @returns a linker string, of the format {@link JS_SOURCE_MAPPING_URL_LINKER}<dataUriPrefixAndMime><sourceMapContents>
1255
- */
1256
- const getInlineSourceMappingUrlLinker = (sourceMapContents) => {
1257
- const mapBase64 = Buffer.from(sourceMapContents, 'utf8').toString('base64');
1258
- // do not RFC-3986 encode an already valid base64 string. the sourcemaps will not resolve correctly when there is an
1259
- // allowed base64 character is encoded (because it is a disallowed RFC-3986 character)
1260
- return `${JS_SOURCE_MAPPING_URL_LINKER}data:application/json;charset=utf-8;base64,${mapBase64}`;
1261
- };
1262
- /**
1263
- * Generates a string used to link generated code with the original source, to be placed at the end of the generated
1264
- * code. This function prepends a newline to the string.
1265
- * @param url the url of the source map
1266
- * @returns a linker string, of the format {@link JS_SOURCE_MAPPING_URL_LINKER}=<url>.map, prepended with a newline
1267
- */
1268
- const getSourceMappingUrlForEndOfFile = (url) => {
1269
- return `\n${getSourceMappingUrlLinker(url)}.map`;
1270
- };
1271
-
1272
- /**
1273
- * Determines whether a string should be considered a remote url or not.
1274
- *
1275
- * This helper only checks the provided string to evaluate is one of a few pre-defined schemes, and should not be
1276
- * considered all-encompassing
1277
- *
1278
- * @param p the string to evaluate
1279
- * @returns `true` if the provided string is a remote url, `false` otherwise
1280
- */
1281
- const isRemoteUrl = (p) => {
1282
- if (isString$1(p)) {
1283
- p = p.toLowerCase();
1284
- return p.startsWith('https://') || p.startsWith('http://');
1285
- }
1286
- return false;
1287
- };
1288
-
1289
- /**
1290
- * A set of JSDoc tags which should be excluded from JSDoc comments
1291
- * included in output typedefs.
1292
- */
1293
- const SUPPRESSED_JSDOC_TAGS = ['virtualProp', 'slot', 'part', 'internal'];
1294
- /**
1295
- * Create a stylistically-appropriate JS variable name from a filename
1296
- *
1297
- * If the filename has any of the special characters "?", "#", "&" and "=" it
1298
- * will take the string before the left-most instance of one of those
1299
- * characters.
1300
- *
1301
- * @param fileName the filename which serves as starting material
1302
- * @returns a JS variable name based on the filename
1303
- */
1304
- const createJsVarName = (fileName) => {
1305
- if (isString$1(fileName)) {
1306
- fileName = fileName.split('?')[0];
1307
- fileName = fileName.split('#')[0];
1308
- fileName = fileName.split('&')[0];
1309
- fileName = fileName.split('=')[0];
1310
- fileName = toDashCase(fileName);
1311
- fileName = fileName.replace(/[|;$%@"<>()+,.{}_\!\/\\]/g, '-');
1312
- fileName = dashToPascalCase$1(fileName);
1313
- if (fileName.length > 1) {
1314
- fileName = fileName[0].toLowerCase() + fileName.slice(1);
1315
- }
1316
- else {
1317
- fileName = fileName.toLowerCase();
1318
- }
1319
- if (fileName.length > 0 && !isNaN(fileName[0])) {
1320
- fileName = '_' + fileName;
1321
- }
1322
- }
1323
- return fileName;
1324
- };
1325
- /**
1326
- * Determines if a given file path points to a type declaration file (ending in .d.ts) or not. This function is
1327
- * case-insensitive in its heuristics.
1328
- * @param filePath the path to check
1329
- * @returns `true` if the given `filePath` points to a type declaration file, `false` otherwise
1330
- */
1331
- const isDtsFile$1 = (filePath) => {
1332
- const parts = filePath.toLowerCase().split('.');
1333
- if (parts.length > 2) {
1334
- return parts[parts.length - 2] === 'd' && parts[parts.length - 1] === 'ts';
1335
- }
1336
- return false;
1337
- };
1338
- /**
1339
- * Generate the preamble to be placed atop the main file of the build
1340
- * @param config the Rindo configuration file
1341
- * @returns the generated preamble
1342
- */
1343
- const generatePreamble = (config) => {
1344
- const { preamble } = config;
1345
- if (!preamble) {
1346
- return '';
1347
- }
1348
- // generate the body of the JSDoc-style comment
1349
- const preambleComment = preamble.split('\n').map((l) => ` * ${l}`);
1350
- preambleComment.unshift(`/*!`);
1351
- preambleComment.push(` */`);
1352
- return preambleComment.join('\n');
1353
- };
1354
- const lineBreakRegex = /\r?\n|\r/g;
1355
- function getTextDocs(docs) {
1356
- if (docs == null) {
1357
- return '';
1358
- }
1359
- return `${docs.text.replace(lineBreakRegex, ' ')}
1360
- ${docs.tags
1361
- .filter((tag) => tag.name !== 'internal')
1362
- .map((tag) => `@${tag.name} ${(tag.text || '').replace(lineBreakRegex, ' ')}`)
1363
- .join('\n')}`.trim();
1364
- }
1365
- /**
1366
- * Adds a doc block to a string
1367
- * @param str the string to add a doc block to
1368
- * @param docs the compiled JS docs
1369
- * @param indentation number of spaces to indent the block with
1370
- * @returns the doc block
1371
- */
1372
- function addDocBlock(str, docs, indentation = 0) {
1373
- if (!docs) {
1374
- return str;
1375
- }
1376
- return [formatDocBlock(docs, indentation), str].filter(Boolean).join(`\n`);
1377
- }
1378
- /**
1379
- * Formats the given compiled docs to a JavaScript doc block
1380
- * @param docs the compiled JS docs
1381
- * @param indentation number of spaces to indent the block with
1382
- * @returns the formatted doc block
1383
- */
1384
- function formatDocBlock(docs, indentation = 0) {
1385
- const textDocs = getDocBlockLines(docs);
1386
- if (!textDocs.filter(Boolean).length) {
1387
- return '';
1388
- }
1389
- const spaces = new Array(indentation + 1).join(' ');
1390
- return [spaces + '/**', ...textDocs.map((line) => spaces + ` * ${line}`), spaces + ' */'].join(`\n`);
1391
- }
1392
- /**
1393
- * Get all lines which are part of the doc block
1394
- *
1395
- * @param docs the compiled JS docs
1396
- * @returns list of lines part of the doc block
1397
- */
1398
- function getDocBlockLines(docs) {
1399
- return [
1400
- ...docs.text.split(lineBreakRegex),
1401
- ...docs.tags
1402
- .filter((tag) => !SUPPRESSED_JSDOC_TAGS.includes(tag.name))
1403
- .map((tag) => `@${tag.name} ${tag.text || ''}`.split(lineBreakRegex)),
1404
- ]
1405
- .flat()
1406
- .filter(Boolean);
1407
- }
1408
- /**
1409
- * Retrieve a project's dependencies from the current build context
1410
- * @param buildCtx the current build context to query for a specific package
1411
- * @returns a list of package names the project is dependent on
1412
- */
1413
- const getDependencies = (buildCtx) => {
1414
- if (buildCtx.packageJson != null && buildCtx.packageJson.dependencies != null) {
1415
- return Object.keys(buildCtx.packageJson.dependencies).filter((pkgName) => !SKIP_DEPS.includes(pkgName));
1416
- }
1417
- return [];
1418
- };
1419
- /**
1420
- * Utility to determine whether a project has a dependency on a package
1421
- * @param buildCtx the current build context to query for a specific package
1422
- * @param depName the name of the dependency/package
1423
- * @returns `true` if the project has a dependency a packaged with the provided name, `false` otherwise
1424
- */
1425
- const hasDependency = (buildCtx, depName) => {
1426
- return getDependencies(buildCtx).includes(depName);
1427
- };
1428
- // TODO: Remove code related to the dynamic import shim
1429
- const getDynamicImportFunction$1 = (namespace) => `__sc_import_${namespace.replace(/\s|-/g, '_')}`;
1430
- const readPackageJson = async (config, compilerCtx, buildCtx) => {
1431
- try {
1432
- const pkgJson = await compilerCtx.fs.readFile(config.packageJsonFilePath);
1433
- if (pkgJson) {
1434
- const parseResults = parsePackageJson(pkgJson, config.packageJsonFilePath);
1435
- if (parseResults.diagnostic) {
1436
- buildCtx.diagnostics.push(parseResults.diagnostic);
1437
- }
1438
- else {
1439
- buildCtx.packageJson = parseResults.data;
1440
- }
1441
- }
1442
- }
1443
- catch (e) {
1444
- if (!config.outputTargets.some((o) => o.type.includes('dist'))) {
1445
- const diagnostic = buildError(buildCtx.diagnostics);
1446
- diagnostic.header = `Missing "package.json"`;
1447
- diagnostic.messageText = `Valid "package.json" file is required for distribution: ${config.packageJsonFilePath}`;
1448
- }
1449
- }
1450
- };
1451
- /**
1452
- * Parse a string read from a `package.json` file
1453
- * @param pkgJsonStr the string read from a `package.json` file
1454
- * @param pkgJsonFilePath the path to the already read `package.json` file
1455
- * @returns the results of parsing the provided contents of the `package.json` file
1456
- */
1457
- const parsePackageJson = (pkgJsonStr, pkgJsonFilePath) => {
1458
- const parseResult = {
1459
- diagnostic: null,
1460
- data: null,
1461
- filePath: pkgJsonFilePath,
1462
- };
1463
- try {
1464
- parseResult.data = JSON.parse(pkgJsonStr);
1465
- }
1466
- catch (e) {
1467
- parseResult.diagnostic = buildError();
1468
- parseResult.diagnostic.absFilePath = isString$1(pkgJsonFilePath) ? pkgJsonFilePath : undefined;
1469
- parseResult.diagnostic.header = `Error Parsing JSON`;
1470
- if (e instanceof Error) {
1471
- parseResult.diagnostic.messageText = e.message;
1472
- }
1473
- }
1474
- return parseResult;
1475
- };
1476
- const SKIP_DEPS = ['@rindo/core'];
1477
- /**
1478
- * Check whether a string is a member of a ReadonlyArray<string>
1479
- *
1480
- * We need a little helper for this because unfortunately `includes` is typed
1481
- * on `ReadonlyArray<T>` as `(el: T): boolean` so a `string` cannot be passed
1482
- * to `includes` on a `ReadonlyArray` 😢 thus we have a little helper function
1483
- * where we do the type coercion just once.
1484
- *
1485
- * see microsoft/TypeScript#31018 for some discussion of this
1486
- *
1487
- * @param readOnlyArray the array we're checking
1488
- * @param maybeMember a value which is possibly a member of the array
1489
- * @returns whether the array contains the member or not
1490
- */
1491
- const readOnlyArrayHasStringMember = (readOnlyArray, maybeMember) => readOnlyArray.includes(maybeMember);
1492
-
1493
- /**
1494
- * Validates that a component tag meets required naming conventions to be used for a web component
1495
- * @param tag the tag to validate
1496
- * @returns an error message if the tag has an invalid name, undefined if the tag name passes all checks
1497
- */
1498
- const validateComponentTag = (tag) => {
1499
- // we want to check this first since we call some String.prototype methods below
1500
- if (typeof tag !== 'string') {
1501
- return `Tag "${tag}" must be a string type`;
1502
- }
1503
- if (tag !== tag.trim()) {
1504
- return `Tag can not contain white spaces`;
1505
- }
1506
- if (tag !== tag.toLowerCase()) {
1507
- return `Tag can not contain upper case characters`;
1508
- }
1509
- if (tag.length === 0) {
1510
- return `Received empty tag value`;
1511
- }
1512
- if (tag.indexOf(' ') > -1) {
1513
- return `"${tag}" tag cannot contain a space`;
1514
- }
1515
- if (tag.indexOf(',') > -1) {
1516
- return `"${tag}" tag cannot be used for multiple tags`;
1517
- }
1518
- const invalidChars = tag.replace(/\w|-/g, '');
1519
- if (invalidChars !== '') {
1520
- return `"${tag}" tag contains invalid characters: ${invalidChars}`;
1521
- }
1522
- if (tag.indexOf('-') === -1) {
1523
- return `"${tag}" tag must contain a dash (-) to work as a valid web component`;
1524
- }
1525
- if (tag.indexOf('--') > -1) {
1526
- return `"${tag}" tag cannot contain multiple dashes (--) next to each other`;
1527
- }
1528
- if (tag.indexOf('-') === 0) {
1529
- return `"${tag}" tag cannot start with a dash (-)`;
1530
- }
1531
- if (tag.lastIndexOf('-') === tag.length - 1) {
1532
- return `"${tag}" tag cannot end with a dash (-)`;
1533
- }
1534
- return undefined;
1535
- };
1536
-
1537
- const EOL = '\n';
1538
- const platform = () => OS_PLATFORM;
1539
- const os$2 = {
1540
- EOL,
1541
- platform,
1542
- };
1543
-
1544
- const os$3 = {
1545
- __proto__: null,
1546
- EOL: EOL,
1547
- platform: platform,
1548
- 'default': os$2
1549
- };
1550
-
1551
1293
  // 'path' module extracted from Node.js v8.11.1 (only the posix part)
1552
1294
 
1553
1295
  function assertPath(path) {
@@ -2117,6 +1859,407 @@ const path$6 = {
2117
1859
  'default': path$5
2118
1860
  };
2119
1861
 
1862
+ const relativeImport = (pathFrom, pathTo, ext, addPrefix = true) => {
1863
+ let relativePath = relative$1(dirname(pathFrom), dirname(pathTo));
1864
+ if (addPrefix) {
1865
+ if (relativePath === '') {
1866
+ relativePath = '.';
1867
+ }
1868
+ else if (relativePath[0] !== '.') {
1869
+ relativePath = './' + relativePath;
1870
+ }
1871
+ }
1872
+ return normalizePath$2(`${relativePath}/${basename(pathTo, ext)}`);
1873
+ };
1874
+ const getComponentsDtsSrcFilePath = (config) => join(config.srcDir, GENERATED_DTS);
1875
+ const getComponentsDtsTypesFilePath = (outputTarget) => join(outputTarget.typesDir, GENERATED_DTS);
1876
+ const isOutputTargetDist = (o) => o.type === DIST;
1877
+ const isOutputTargetDistCollection = (o) => o.type === DIST_COLLECTION;
1878
+ const isOutputTargetDistCustomElements = (o) => o.type === DIST_CUSTOM_ELEMENTS;
1879
+ const isOutputTargetCopy = (o) => o.type === COPY;
1880
+ const isOutputTargetDistLazy = (o) => o.type === DIST_LAZY;
1881
+ const isOutputTargetDistLazyLoader = (o) => o.type === DIST_LAZY_LOADER;
1882
+ const isOutputTargetDistGlobalStyles = (o) => o.type === DIST_GLOBAL_STYLES;
1883
+ const isOutputTargetHydrate = (o) => o.type === DIST_HYDRATE_SCRIPT;
1884
+ const isOutputTargetCustom = (o) => o.type === CUSTOM;
1885
+ const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
1886
+ const isOutputTargetDocsReadme = (o) => o.type === DOCS_README;
1887
+ const isOutputTargetDocsJson = (o) => o.type === DOCS_JSON;
1888
+ const isOutputTargetDocsCustom = (o) => o.type === DOCS_CUSTOM;
1889
+ const isOutputTargetDocsVscode = (o) => o.type === DOCS_VSCODE;
1890
+ const isOutputTargetWww = (o) => o.type === WWW;
1891
+ const isOutputTargetStats = (o) => o.type === STATS;
1892
+ const isOutputTargetDistTypes = (o) => o.type === DIST_TYPES;
1893
+ /**
1894
+ * Retrieve the Rindo component compiler metadata from a collection of Rindo {@link Module}s
1895
+ * @param moduleFiles the collection of `Module`s to retrieve the metadata from
1896
+ * @returns the metadata, lexicographically sorted by the tag names of the components
1897
+ */
1898
+ const getComponentsFromModules = (moduleFiles) => sortBy(flatOne(moduleFiles.map((m) => m.cmps)), (c) => c.tagName);
1899
+ /**
1900
+ * Check whether a given output target is a valid one to be set in a Rindo config
1901
+ *
1902
+ * @param targetType the type which we want to check
1903
+ * @returns whether or not the targetType is a valid, configurable output target.
1904
+ */
1905
+ function isValidConfigOutputTarget(targetType) {
1906
+ // unfortunately `includes` is typed on `ReadonlyArray<T>` as `(el: T):
1907
+ // boolean` so a `string` cannot be passed to `includes` on a
1908
+ // `ReadonlyArray` 😢 thus we `as any`
1909
+ //
1910
+ // see microsoft/TypeScript#31018 for some discussion of this
1911
+ return VALID_CONFIG_OUTPUT_TARGETS.includes(targetType);
1912
+ }
1913
+
1914
+ /**
1915
+ * Converts a rollup provided source map to one that Rindo can easily understand
1916
+ * @param rollupSourceMap the sourcemap to transform
1917
+ * @returns the transformed sourcemap
1918
+ */
1919
+ const rollupToRindoSourceMap = (rollupSourceMap) => {
1920
+ if (!rollupSourceMap) {
1921
+ return null;
1922
+ }
1923
+ return {
1924
+ file: rollupSourceMap.file,
1925
+ mappings: rollupSourceMap.mappings,
1926
+ names: rollupSourceMap.names,
1927
+ sources: rollupSourceMap.sources,
1928
+ sourcesContent: rollupSourceMap.sourcesContent,
1929
+ version: rollupSourceMap.version,
1930
+ };
1931
+ };
1932
+ /**
1933
+ * A JavaScript formatted string used to link generated code back to the original. This string follows the guidelines
1934
+ * found in the [Linking generated code to source maps](https://sourcemaps.info/spec.html#h.lmz475t4mvbx) section of
1935
+ * the Sourcemaps V3 specification proposal.
1936
+ */
1937
+ const JS_SOURCE_MAPPING_URL_LINKER = '//# sourceMappingURL=';
1938
+ /**
1939
+ * Generates an RFC-3986 compliant string for the given input.
1940
+ * More information about RFC-3986 can be found [here](https://datatracker.ietf.org/doc/html/rfc3986)
1941
+ * This function's original source is derived from
1942
+ * [MDN's encodeURIComponent documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#description)
1943
+ * @param filename the filename to encode
1944
+ * @returns the encoded URI
1945
+ */
1946
+ const encodeToRfc3986 = (filename) => {
1947
+ const encodedUri = encodeURIComponent(filename);
1948
+ // replace all '!', single quotes, '(', ')', and '*' with their hexadecimal values (UTF-16)
1949
+ return encodedUri.replace(/[!'()*]/g, (matchedCharacter) => {
1950
+ return '%' + matchedCharacter.charCodeAt(0).toString(16);
1951
+ });
1952
+ };
1953
+ /**
1954
+ * Generates a string used to link generated code with the original source, to be placed at the end of the generated
1955
+ * code.
1956
+ * @param url the url of the source map
1957
+ * @returns a linker string, of the format {@link JS_SOURCE_MAPPING_URL_LINKER}=<url>
1958
+ */
1959
+ const getSourceMappingUrlLinker = (url) => {
1960
+ return `${JS_SOURCE_MAPPING_URL_LINKER}${encodeToRfc3986(url)}`;
1961
+ };
1962
+ /**
1963
+ * Generates a string used to link generated code with the original source, to be placed at the end of the generated
1964
+ * code as an inline source map.
1965
+ * @param sourceMapContents the sourceMapContents of the source map
1966
+ * @returns a linker string, of the format {@link JS_SOURCE_MAPPING_URL_LINKER}<dataUriPrefixAndMime><sourceMapContents>
1967
+ */
1968
+ const getInlineSourceMappingUrlLinker = (sourceMapContents) => {
1969
+ const mapBase64 = Buffer.from(sourceMapContents, 'utf8').toString('base64');
1970
+ // do not RFC-3986 encode an already valid base64 string. the sourcemaps will not resolve correctly when there is an
1971
+ // allowed base64 character is encoded (because it is a disallowed RFC-3986 character)
1972
+ return `${JS_SOURCE_MAPPING_URL_LINKER}data:application/json;charset=utf-8;base64,${mapBase64}`;
1973
+ };
1974
+ /**
1975
+ * Generates a string used to link generated code with the original source, to be placed at the end of the generated
1976
+ * code. This function prepends a newline to the string.
1977
+ * @param url the url of the source map
1978
+ * @returns a linker string, of the format {@link JS_SOURCE_MAPPING_URL_LINKER}=<url>.map, prepended with a newline
1979
+ */
1980
+ const getSourceMappingUrlForEndOfFile = (url) => {
1981
+ return `\n${getSourceMappingUrlLinker(url)}.map`;
1982
+ };
1983
+
1984
+ /**
1985
+ * Determines whether a string should be considered a remote url or not.
1986
+ *
1987
+ * This helper only checks the provided string to evaluate is one of a few pre-defined schemes, and should not be
1988
+ * considered all-encompassing
1989
+ *
1990
+ * @param p the string to evaluate
1991
+ * @returns `true` if the provided string is a remote url, `false` otherwise
1992
+ */
1993
+ const isRemoteUrl = (p) => {
1994
+ if (isString$1(p)) {
1995
+ p = p.toLowerCase();
1996
+ return p.startsWith('https://') || p.startsWith('http://');
1997
+ }
1998
+ return false;
1999
+ };
2000
+
2001
+ /**
2002
+ * A set of JSDoc tags which should be excluded from JSDoc comments
2003
+ * included in output typedefs.
2004
+ */
2005
+ const SUPPRESSED_JSDOC_TAGS = ['virtualProp', 'slot', 'part', 'internal'];
2006
+ /**
2007
+ * Create a stylistically-appropriate JS variable name from a filename
2008
+ *
2009
+ * If the filename has any of the special characters "?", "#", "&" and "=" it
2010
+ * will take the string before the left-most instance of one of those
2011
+ * characters.
2012
+ *
2013
+ * @param fileName the filename which serves as starting material
2014
+ * @returns a JS variable name based on the filename
2015
+ */
2016
+ const createJsVarName = (fileName) => {
2017
+ if (isString$1(fileName)) {
2018
+ fileName = fileName.split('?')[0];
2019
+ fileName = fileName.split('#')[0];
2020
+ fileName = fileName.split('&')[0];
2021
+ fileName = fileName.split('=')[0];
2022
+ fileName = toDashCase(fileName);
2023
+ fileName = fileName.replace(/[|;$%@"<>()+,.{}_\!\/\\]/g, '-');
2024
+ fileName = dashToPascalCase$1(fileName);
2025
+ if (fileName.length > 1) {
2026
+ fileName = fileName[0].toLowerCase() + fileName.slice(1);
2027
+ }
2028
+ else {
2029
+ fileName = fileName.toLowerCase();
2030
+ }
2031
+ if (fileName.length > 0 && !isNaN(fileName[0])) {
2032
+ fileName = '_' + fileName;
2033
+ }
2034
+ }
2035
+ return fileName;
2036
+ };
2037
+ /**
2038
+ * Determines if a given file path points to a type declaration file (ending in .d.ts) or not. This function is
2039
+ * case-insensitive in its heuristics.
2040
+ * @param filePath the path to check
2041
+ * @returns `true` if the given `filePath` points to a type declaration file, `false` otherwise
2042
+ */
2043
+ const isDtsFile$1 = (filePath) => {
2044
+ const parts = filePath.toLowerCase().split('.');
2045
+ if (parts.length > 2) {
2046
+ return parts[parts.length - 2] === 'd' && parts[parts.length - 1] === 'ts';
2047
+ }
2048
+ return false;
2049
+ };
2050
+ /**
2051
+ * Generate the preamble to be placed atop the main file of the build
2052
+ * @param config the Rindo configuration file
2053
+ * @returns the generated preamble
2054
+ */
2055
+ const generatePreamble = (config) => {
2056
+ const { preamble } = config;
2057
+ if (!preamble) {
2058
+ return '';
2059
+ }
2060
+ // generate the body of the JSDoc-style comment
2061
+ const preambleComment = preamble.split('\n').map((l) => ` * ${l}`);
2062
+ preambleComment.unshift(`/*!`);
2063
+ preambleComment.push(` */`);
2064
+ return preambleComment.join('\n');
2065
+ };
2066
+ const lineBreakRegex = /\r?\n|\r/g;
2067
+ function getTextDocs(docs) {
2068
+ if (docs == null) {
2069
+ return '';
2070
+ }
2071
+ return `${docs.text.replace(lineBreakRegex, ' ')}
2072
+ ${docs.tags
2073
+ .filter((tag) => tag.name !== 'internal')
2074
+ .map((tag) => `@${tag.name} ${(tag.text || '').replace(lineBreakRegex, ' ')}`)
2075
+ .join('\n')}`.trim();
2076
+ }
2077
+ /**
2078
+ * Adds a doc block to a string
2079
+ * @param str the string to add a doc block to
2080
+ * @param docs the compiled JS docs
2081
+ * @param indentation number of spaces to indent the block with
2082
+ * @returns the doc block
2083
+ */
2084
+ function addDocBlock(str, docs, indentation = 0) {
2085
+ if (!docs) {
2086
+ return str;
2087
+ }
2088
+ return [formatDocBlock(docs, indentation), str].filter(Boolean).join(`\n`);
2089
+ }
2090
+ /**
2091
+ * Formats the given compiled docs to a JavaScript doc block
2092
+ * @param docs the compiled JS docs
2093
+ * @param indentation number of spaces to indent the block with
2094
+ * @returns the formatted doc block
2095
+ */
2096
+ function formatDocBlock(docs, indentation = 0) {
2097
+ const textDocs = getDocBlockLines(docs);
2098
+ if (!textDocs.filter(Boolean).length) {
2099
+ return '';
2100
+ }
2101
+ const spaces = new Array(indentation + 1).join(' ');
2102
+ return [spaces + '/**', ...textDocs.map((line) => spaces + ` * ${line}`), spaces + ' */'].join(`\n`);
2103
+ }
2104
+ /**
2105
+ * Get all lines which are part of the doc block
2106
+ *
2107
+ * @param docs the compiled JS docs
2108
+ * @returns list of lines part of the doc block
2109
+ */
2110
+ function getDocBlockLines(docs) {
2111
+ return [
2112
+ ...docs.text.split(lineBreakRegex),
2113
+ ...docs.tags
2114
+ .filter((tag) => !SUPPRESSED_JSDOC_TAGS.includes(tag.name))
2115
+ .map((tag) => `@${tag.name} ${tag.text || ''}`.split(lineBreakRegex)),
2116
+ ]
2117
+ .flat()
2118
+ .filter(Boolean);
2119
+ }
2120
+ /**
2121
+ * Retrieve a project's dependencies from the current build context
2122
+ * @param buildCtx the current build context to query for a specific package
2123
+ * @returns a list of package names the project is dependent on
2124
+ */
2125
+ const getDependencies = (buildCtx) => {
2126
+ if (buildCtx.packageJson != null && buildCtx.packageJson.dependencies != null) {
2127
+ return Object.keys(buildCtx.packageJson.dependencies).filter((pkgName) => !SKIP_DEPS.includes(pkgName));
2128
+ }
2129
+ return [];
2130
+ };
2131
+ /**
2132
+ * Utility to determine whether a project has a dependency on a package
2133
+ * @param buildCtx the current build context to query for a specific package
2134
+ * @param depName the name of the dependency/package
2135
+ * @returns `true` if the project has a dependency a packaged with the provided name, `false` otherwise
2136
+ */
2137
+ const hasDependency = (buildCtx, depName) => {
2138
+ return getDependencies(buildCtx).includes(depName);
2139
+ };
2140
+ // TODO: Remove code related to the dynamic import shim
2141
+ const getDynamicImportFunction$1 = (namespace) => `__sc_import_${namespace.replace(/\s|-/g, '_')}`;
2142
+ const readPackageJson = async (config, compilerCtx, buildCtx) => {
2143
+ try {
2144
+ const pkgJson = await compilerCtx.fs.readFile(config.packageJsonFilePath);
2145
+ if (pkgJson) {
2146
+ const parseResults = parsePackageJson(pkgJson, config.packageJsonFilePath);
2147
+ if (parseResults.diagnostic) {
2148
+ buildCtx.diagnostics.push(parseResults.diagnostic);
2149
+ }
2150
+ else {
2151
+ buildCtx.packageJson = parseResults.data;
2152
+ }
2153
+ }
2154
+ }
2155
+ catch (e) {
2156
+ if (!config.outputTargets.some((o) => o.type.includes('dist'))) {
2157
+ const diagnostic = buildError(buildCtx.diagnostics);
2158
+ diagnostic.header = `Missing "package.json"`;
2159
+ diagnostic.messageText = `Valid "package.json" file is required for distribution: ${config.packageJsonFilePath}`;
2160
+ }
2161
+ }
2162
+ };
2163
+ /**
2164
+ * Parse a string read from a `package.json` file
2165
+ * @param pkgJsonStr the string read from a `package.json` file
2166
+ * @param pkgJsonFilePath the path to the already read `package.json` file
2167
+ * @returns the results of parsing the provided contents of the `package.json` file
2168
+ */
2169
+ const parsePackageJson = (pkgJsonStr, pkgJsonFilePath) => {
2170
+ const parseResult = {
2171
+ diagnostic: null,
2172
+ data: null,
2173
+ filePath: pkgJsonFilePath,
2174
+ };
2175
+ try {
2176
+ parseResult.data = JSON.parse(pkgJsonStr);
2177
+ }
2178
+ catch (e) {
2179
+ parseResult.diagnostic = buildError();
2180
+ parseResult.diagnostic.absFilePath = isString$1(pkgJsonFilePath) ? pkgJsonFilePath : undefined;
2181
+ parseResult.diagnostic.header = `Error Parsing JSON`;
2182
+ if (e instanceof Error) {
2183
+ parseResult.diagnostic.messageText = e.message;
2184
+ }
2185
+ }
2186
+ return parseResult;
2187
+ };
2188
+ const SKIP_DEPS = ['@rindo/core'];
2189
+ /**
2190
+ * Check whether a string is a member of a ReadonlyArray<string>
2191
+ *
2192
+ * We need a little helper for this because unfortunately `includes` is typed
2193
+ * on `ReadonlyArray<T>` as `(el: T): boolean` so a `string` cannot be passed
2194
+ * to `includes` on a `ReadonlyArray` 😢 thus we have a little helper function
2195
+ * where we do the type coercion just once.
2196
+ *
2197
+ * see microsoft/TypeScript#31018 for some discussion of this
2198
+ *
2199
+ * @param readOnlyArray the array we're checking
2200
+ * @param maybeMember a value which is possibly a member of the array
2201
+ * @returns whether the array contains the member or not
2202
+ */
2203
+ const readOnlyArrayHasStringMember = (readOnlyArray, maybeMember) => readOnlyArray.includes(maybeMember);
2204
+
2205
+ /**
2206
+ * Validates that a component tag meets required naming conventions to be used for a web component
2207
+ * @param tag the tag to validate
2208
+ * @returns an error message if the tag has an invalid name, undefined if the tag name passes all checks
2209
+ */
2210
+ const validateComponentTag = (tag) => {
2211
+ // we want to check this first since we call some String.prototype methods below
2212
+ if (typeof tag !== 'string') {
2213
+ return `Tag "${tag}" must be a string type`;
2214
+ }
2215
+ if (tag !== tag.trim()) {
2216
+ return `Tag can not contain white spaces`;
2217
+ }
2218
+ if (tag !== tag.toLowerCase()) {
2219
+ return `Tag can not contain upper case characters`;
2220
+ }
2221
+ if (tag.length === 0) {
2222
+ return `Received empty tag value`;
2223
+ }
2224
+ if (tag.indexOf(' ') > -1) {
2225
+ return `"${tag}" tag cannot contain a space`;
2226
+ }
2227
+ if (tag.indexOf(',') > -1) {
2228
+ return `"${tag}" tag cannot be used for multiple tags`;
2229
+ }
2230
+ const invalidChars = tag.replace(/\w|-/g, '');
2231
+ if (invalidChars !== '') {
2232
+ return `"${tag}" tag contains invalid characters: ${invalidChars}`;
2233
+ }
2234
+ if (tag.indexOf('-') === -1) {
2235
+ return `"${tag}" tag must contain a dash (-) to work as a valid web component`;
2236
+ }
2237
+ if (tag.indexOf('--') > -1) {
2238
+ return `"${tag}" tag cannot contain multiple dashes (--) next to each other`;
2239
+ }
2240
+ if (tag.indexOf('-') === 0) {
2241
+ return `"${tag}" tag cannot start with a dash (-)`;
2242
+ }
2243
+ if (tag.lastIndexOf('-') === tag.length - 1) {
2244
+ return `"${tag}" tag cannot end with a dash (-)`;
2245
+ }
2246
+ return undefined;
2247
+ };
2248
+
2249
+ const EOL = '\n';
2250
+ const platform = () => OS_PLATFORM;
2251
+ const os$2 = {
2252
+ EOL,
2253
+ platform,
2254
+ };
2255
+
2256
+ const os$3 = {
2257
+ __proto__: null,
2258
+ EOL: EOL,
2259
+ platform: platform,
2260
+ 'default': os$2
2261
+ };
2262
+
2120
2263
  var commonjsGlobal$1 = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2121
2264
 
2122
2265
  function createCommonjsModule$1(fn, basedir, module) {
@@ -2155,7 +2298,7 @@ const process$3 = /*#__PURE__*/Object.assign(/*#__PURE__*/Object.create(null), p
2155
2298
  'default': process_1
2156
2299
  });
2157
2300
 
2158
- const buildId = '20230407110404';
2301
+ const buildId = '1682086722';
2159
2302
  const minfyJsId = 'terser5.16.1_7';
2160
2303
  const optimizeCssId = 'autoprefixer10.4.13_postcss8.4.21_7';
2161
2304
  const parse5Version = '7.1.2';
@@ -2163,8 +2306,8 @@ const rollupVersion = '2.42.3';
2163
2306
  const sizzleVersion = '2.42.3';
2164
2307
  const terserVersion = '5.16.1';
2165
2308
  const typescriptVersion = '4.9.4';
2166
- const vermoji = '💥';
2167
- const version$3 = '3.1.0';
2309
+ const vermoji = '🎉';
2310
+ const version$3 = '3.2.1';
2168
2311
  const versions = {
2169
2312
  rindo: version$3,
2170
2313
  parse5: parse5Version,
@@ -11644,6 +11787,7 @@ class MagicString$3 {
11644
11787
  sourcemapLocations: { writable: true, value: new BitSet$3() },
11645
11788
  storedNames: { writable: true, value: {} },
11646
11789
  indentStr: { writable: true, value: undefined },
11790
+ ignoreList: { writable: true, value: options.ignoreList },
11647
11791
  });
11648
11792
 
11649
11793
  this.byStart[0] = chunk;
@@ -11761,11 +11905,12 @@ class MagicString$3 {
11761
11905
  });
11762
11906
 
11763
11907
  return {
11764
- file: options.file ? options.file.split(/[/\\]/).pop() : null,
11765
- sources: [options.source ? getRelativePath$3(options.file || '', options.source) : null],
11766
- sourcesContent: options.includeContent ? [this.original] : [null],
11908
+ file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
11909
+ sources: [options.source ? getRelativePath$3(options.file || '', options.source) : (options.file || '')],
11910
+ sourcesContent: options.includeContent ? [this.original] : undefined,
11767
11911
  names,
11768
11912
  mappings: mappings.raw,
11913
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined
11769
11914
  };
11770
11915
  }
11771
11916
 
@@ -13342,6 +13487,7 @@ const getModuleLegacy = (_config, compilerCtx, sourceFilePath) => {
13342
13487
  jsFilePath: jsFilePath,
13343
13488
  cmps: [],
13344
13489
  coreRuntimeApis: [],
13490
+ outputTargetCoreRuntimeApis: {},
13345
13491
  collectionName: null,
13346
13492
  dtsFilePath: null,
13347
13493
  excludeFromCollection: false,
@@ -13401,100 +13547,6 @@ const resetModuleLegacy = (moduleFile) => {
13401
13547
  moduleFile.potentialCmpRefs.length = 0;
13402
13548
  };
13403
13549
 
13404
- const relativeImport = (pathFrom, pathTo, ext, addPrefix = true) => {
13405
- let relativePath = relative$1(dirname(pathFrom), dirname(pathTo));
13406
- if (addPrefix) {
13407
- if (relativePath === '') {
13408
- relativePath = '.';
13409
- }
13410
- else if (relativePath[0] !== '.') {
13411
- relativePath = './' + relativePath;
13412
- }
13413
- }
13414
- return normalizePath$2(`${relativePath}/${basename(pathTo, ext)}`);
13415
- };
13416
- const getComponentsDtsSrcFilePath = (config) => join(config.srcDir, GENERATED_DTS);
13417
- const getComponentsDtsTypesFilePath = (outputTarget) => join(outputTarget.typesDir, GENERATED_DTS);
13418
- const isOutputTargetDist = (o) => o.type === DIST;
13419
- const isOutputTargetDistCollection = (o) => o.type === DIST_COLLECTION;
13420
- const isOutputTargetDistCustomElements = (o) => o.type === DIST_CUSTOM_ELEMENTS;
13421
- // TODO: fully delete dist-custom-elements-bundle code
13422
- const isOutputTargetDistCustomElementsBundle = (o) => o.type === DIST_CUSTOM_ELEMENTS_BUNDLE;
13423
- const isOutputTargetCopy = (o) => o.type === COPY;
13424
- const isOutputTargetDistLazy = (o) => o.type === DIST_LAZY;
13425
- const isOutputTargetDistLazyLoader = (o) => o.type === DIST_LAZY_LOADER;
13426
- const isOutputTargetDistGlobalStyles = (o) => o.type === DIST_GLOBAL_STYLES;
13427
- const isOutputTargetHydrate = (o) => o.type === DIST_HYDRATE_SCRIPT;
13428
- const isOutputTargetCustom = (o) => o.type === CUSTOM;
13429
- const isOutputTargetDocs = (o) => o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
13430
- const isOutputTargetDocsReadme = (o) => o.type === DOCS_README;
13431
- const isOutputTargetDocsJson = (o) => o.type === DOCS_JSON;
13432
- const isOutputTargetDocsCustom = (o) => o.type === DOCS_CUSTOM;
13433
- const isOutputTargetDocsVscode = (o) => o.type === DOCS_VSCODE;
13434
- const isOutputTargetWww = (o) => o.type === WWW;
13435
- const isOutputTargetStats = (o) => o.type === STATS;
13436
- const isOutputTargetDistTypes = (o) => o.type === DIST_TYPES;
13437
- const getComponentsFromModules = (moduleFiles) => sortBy(flatOne(moduleFiles.map((m) => m.cmps)), (c) => c.tagName);
13438
- const COPY = 'copy';
13439
- const CUSTOM = 'custom';
13440
- const DIST = 'dist';
13441
- const DIST_COLLECTION = 'dist-collection';
13442
- const DIST_CUSTOM_ELEMENTS = 'dist-custom-elements';
13443
- // TODO: fully delete dist-custom-elements-bundle code
13444
- const DIST_CUSTOM_ELEMENTS_BUNDLE = 'dist-custom-elements-bundle';
13445
- const DIST_TYPES = 'dist-types';
13446
- const DIST_HYDRATE_SCRIPT = 'dist-hydrate-script';
13447
- const DIST_LAZY = 'dist-lazy';
13448
- const DIST_LAZY_LOADER = 'dist-lazy-loader';
13449
- const DIST_GLOBAL_STYLES = 'dist-global-styles';
13450
- const DOCS_CUSTOM = 'docs-custom';
13451
- const DOCS_JSON = 'docs-json';
13452
- const DOCS_README = 'docs-readme';
13453
- const DOCS_VSCODE = 'docs-vscode';
13454
- const STATS = 'stats';
13455
- const WWW = 'www';
13456
- /**
13457
- * Valid output targets to specify in a Rindo config.
13458
- *
13459
- * Note that there are some output targets (e.g. `DIST_TYPES`) which are
13460
- * programmatically set as output targets by the compiler when other output
13461
- * targets (in that case `DIST`) are set, but which are _not_ supported in a
13462
- * Rindo config. This is enforced in the output target validation code.
13463
- */
13464
- const VALID_CONFIG_OUTPUT_TARGETS = [
13465
- // DIST
13466
- WWW,
13467
- DIST,
13468
- DIST_COLLECTION,
13469
- DIST_CUSTOM_ELEMENTS,
13470
- DIST_LAZY,
13471
- DIST_HYDRATE_SCRIPT,
13472
- // DOCS
13473
- DOCS_JSON,
13474
- DOCS_README,
13475
- DOCS_VSCODE,
13476
- DOCS_CUSTOM,
13477
- // MISC
13478
- COPY,
13479
- CUSTOM,
13480
- STATS,
13481
- ];
13482
- /**
13483
- * Check whether a given output target is a valid one to be set in a Rindo config
13484
- *
13485
- * @param targetType the type which we want to check
13486
- * @returns whether or not the targetType is a valid, configurable output target.
13487
- */
13488
- function isValidConfigOutputTarget(targetType) {
13489
- // unfortunately `includes` is typed on `ReadonlyArray<T>` as `(el: T):
13490
- // boolean` so a `string` cannot be passed to `includes` on a
13491
- // `ReadonlyArray` 😢 thus we `as any`
13492
- //
13493
- // see microsoft/TypeScript#31018 for some discussion of this
13494
- return VALID_CONFIG_OUTPUT_TARGETS.includes(targetType);
13495
- }
13496
- const GENERATED_DTS = 'components.d.ts';
13497
-
13498
13550
  /**
13499
13551
  * Derive a {@link ts.CompilerOptions} object from the options currently set
13500
13552
  * on the user-supplied configuration object.
@@ -17507,9 +17559,14 @@ class MockWindow {
17507
17559
  this.__location = val;
17508
17560
  }
17509
17561
  }
17510
- matchMedia() {
17562
+ matchMedia(media) {
17511
17563
  return {
17564
+ media,
17512
17565
  matches: false,
17566
+ addEventListener,
17567
+ dispatchEvent,
17568
+ removeEventListener,
17569
+ onchange: null,
17513
17570
  };
17514
17571
  }
17515
17572
  get Node() {
@@ -19799,6 +19856,13 @@ const objectToObjectLiteral = (obj, refs) => {
19799
19856
  const createStaticGetter = (propName, returnExpression) => {
19800
19857
  return t.factory.createGetAccessorDeclaration([t.factory.createToken(t.SyntaxKind.StaticKeyword)], propName, [], undefined, t.factory.createBlock([t.factory.createReturnStatement(returnExpression)]));
19801
19858
  };
19859
+ /**
19860
+ * Retrieves a value represented by TypeScript's syntax tree by name of a static getter. The value is transformed to a
19861
+ * runtime value.
19862
+ * @param staticMembers a collection of static getters to search
19863
+ * @param staticName the name of the static getter to pull a value from
19864
+ * @returns a TypeScript value, converted from its TypeScript syntax tree representation
19865
+ */
19802
19866
  const getStaticValue = (staticMembers, staticName) => {
19803
19867
  const staticMember = staticMembers.find((member) => member.name.escapedText === staticName);
19804
19868
  if (!staticMember || !staticMember.body || !staticMember.body.statements) {
@@ -20104,6 +20168,40 @@ const getTypeReferenceLocation = (typeName, tsNode) => {
20104
20168
  location: 'global',
20105
20169
  };
20106
20170
  };
20171
+ /**
20172
+ * Resolve a type annotation, using the TypeScript typechecker to convert a
20173
+ * {@link ts.Type} record to a string.
20174
+ *
20175
+ * For instance, assume there's a module `foo.ts` which exports a type `Foo`
20176
+ * which looks like this:
20177
+ *
20178
+ * ```ts
20179
+ * // foo.ts
20180
+ * type Foo = (b: string) => boolean;
20181
+ * ```
20182
+ *
20183
+ * and then a module `bar.ts` which imports `Foo` and uses it to annotate a
20184
+ * variable declaration like so:
20185
+ *
20186
+ * ```ts
20187
+ * // bar.ts
20188
+ * import { Foo } from './foo';
20189
+ *
20190
+ * let foo: Foo | undefined;
20191
+ * ```
20192
+ *
20193
+ * If this function is called with the {@link ts.Type} object corresponding to
20194
+ * the {@link ts.Node} object for the `foo` variable, it will return something
20195
+ * like:
20196
+ *
20197
+ * ```ts
20198
+ * "(b: string) => boolean | undefined";
20199
+ * ```
20200
+ *
20201
+ * @param checker a typescript typechecker
20202
+ * @param type the type to resolve
20203
+ * @returns a resolved, user-readable string
20204
+ */
20107
20205
  const resolveType = (checker, type) => {
20108
20206
  const set = new Set();
20109
20207
  parseDocsType(checker, type, set);
@@ -20114,7 +20212,7 @@ const resolveType = (checker, type) => {
20114
20212
  set.add('boolean');
20115
20213
  }
20116
20214
  let parts = Array.from(set.keys()).sort();
20117
- // TODO: Get this section of code under tests that directly exercises this behavior
20215
+ // TODO: Get this section of code under tests that directly exercise this behavior
20118
20216
  if (parts.length > 1) {
20119
20217
  parts = parts.map((p) => (p.indexOf('=>') >= 0 ? `(${p})` : p));
20120
20218
  }
@@ -20127,6 +20225,7 @@ const resolveType = (checker, type) => {
20127
20225
  };
20128
20226
  /**
20129
20227
  * Formats a TypeScript `Type` entity as a string
20228
+ *
20130
20229
  * @param checker a reference to the TypeScript type checker
20131
20230
  * @param type a TypeScript `Type` entity to format
20132
20231
  * @returns the formatted string
@@ -20135,6 +20234,18 @@ const typeToString = (checker, type) => {
20135
20234
  const TYPE_FORMAT_FLAGS = t.TypeFormatFlags.NoTruncation | t.TypeFormatFlags.InTypeAlias | t.TypeFormatFlags.InElementType;
20136
20235
  return checker.typeToString(type, undefined, TYPE_FORMAT_FLAGS);
20137
20236
  };
20237
+ /**
20238
+ * Parse a type into its component parts, recursively dealing with each variant
20239
+ * if it is a union type.
20240
+ *
20241
+ * **Note**: this function will mutate the `parts` set, adding new strings for
20242
+ * any types it finds.
20243
+ *
20244
+ * @param checker a TypeScript typechecker instance
20245
+ * @param type a TypeScript type
20246
+ * @param parts an out param that holds parts of the type annotation we're
20247
+ * assembling
20248
+ */
20138
20249
  const parseDocsType = (checker, type, parts) => {
20139
20250
  if (type.isUnion()) {
20140
20251
  type.types.forEach((t) => {
@@ -20146,15 +20257,32 @@ const parseDocsType = (checker, type, parts) => {
20146
20257
  parts.add(text);
20147
20258
  }
20148
20259
  };
20260
+ /**
20261
+ * Retrieves a Rindo `Module` entity from the compiler context for a given TypeScript `SourceFile`
20262
+ * @param compilerCtx the current compiler context to retrieve the `Module` from
20263
+ * @param tsSourceFile the TypeScript compiler `SourceFile` entity to use to retrieve the `Module`
20264
+ * @returns the `Module`, or `undefined` if it cannot be found
20265
+ */
20149
20266
  const getModuleFromSourceFile = (compilerCtx, tsSourceFile) => {
20150
20267
  const sourceFilePath = normalizePath$2(tsSourceFile.fileName);
20151
20268
  const moduleFile = compilerCtx.moduleMap.get(sourceFilePath);
20152
20269
  if (moduleFile != null) {
20153
20270
  return moduleFile;
20154
20271
  }
20272
+ // a key with the `Module`'s filename could not be found, attempt to resolve it by iterating over all modules in the
20273
+ // compiler context
20155
20274
  const moduleFiles = Array.from(compilerCtx.moduleMap.values());
20156
20275
  return moduleFiles.find((m) => m.jsFilePath === sourceFilePath);
20157
20276
  };
20277
+ /**
20278
+ * Retrieve the Rindo metadata for a component from the current compiler context, based on the provided TypeScript
20279
+ * syntax tree node. The TypeScript source file is used as a fallback in the event the metadata cannot be found based
20280
+ * on the TypeScript node.
20281
+ * @param compilerCtx the current compiler context
20282
+ * @param tsSourceFile the TypeScript `SourceFile` entity
20283
+ * @param node a TypeScript class representation of a Rindo component
20284
+ * @returns the found metadata, or `undefined` if it cannot be found
20285
+ */
20158
20286
  const getComponentMeta = (compilerCtx, tsSourceFile, node) => {
20159
20287
  const meta = compilerCtx.nodeMap.get(node);
20160
20288
  if (meta) {
@@ -20170,6 +20298,11 @@ const getComponentMeta = (compilerCtx, tsSourceFile, node) => {
20170
20298
  }
20171
20299
  return undefined;
20172
20300
  };
20301
+ /**
20302
+ * Retrieves the tag name associated with a Rindo component, based on the 'is' static getter assigned to the class at compile time
20303
+ * @param staticMembers the static getters belonging to the Rindo component class
20304
+ * @returns the tage name, or null if one cannot be found
20305
+ */
20173
20306
  const getComponentTagName = (staticMembers) => {
20174
20307
  if (staticMembers.length > 0) {
20175
20308
  const tagName = getStaticValue(staticMembers, 'is');
@@ -58620,8 +58753,23 @@ const getTsResolveExtension = (p) => {
58620
58753
  };
58621
58754
  const shouldPatchRemoteTypeScript = (compilerExe) => !IS_NODE_ENV && isRemoteUrl(compilerExe);
58622
58755
 
58756
+ /**
58757
+ * Helper function for retrieving a Rindo {@link Module} from the provided compiler context
58758
+ * @param compilerCtx the compiler context to retrieve the `Module` from
58759
+ * @param filePath the path of the file corresponding to the `Module` to lookup
58760
+ * @returns the `Module`, or `undefined` if one cannot be found
58761
+ */
58623
58762
  const getModule = (compilerCtx, filePath) => compilerCtx.moduleMap.get(normalizePath$2(filePath));
58624
- const createModule = (staticSourceFile, // this is NOT the original
58763
+ /**
58764
+ * Creates a {@link Module} entity with reasonable defaults
58765
+ * @param staticSourceFile the TypeScript representation of the source file. This may not be the original
58766
+ * representation of the file, but instead a new `SourceFile` created using the TypeScript API
58767
+ * @param staticSourceFileText the text from the `SourceFile`. This text may originate from the original representation
58768
+ * of the file.
58769
+ * @param emitFilepath the path of the JavaScript file that should be emitted after transpilation
58770
+ * @returns the created `Module`
58771
+ */
58772
+ const createModule = (staticSourceFile, // this may NOT be the original
58625
58773
  staticSourceFileText, emitFilepath) => ({
58626
58774
  sourceFilePath: normalizePath$2(staticSourceFile.fileName),
58627
58775
  jsFilePath: emitFilepath,
@@ -58629,6 +58777,7 @@ staticSourceFileText, emitFilepath) => ({
58629
58777
  staticSourceFileText,
58630
58778
  cmps: [],
58631
58779
  coreRuntimeApis: [],
58780
+ outputTargetCoreRuntimeApis: {},
58632
58781
  collectionName: null,
58633
58782
  dtsFilePath: null,
58634
58783
  excludeFromCollection: false,
@@ -59430,11 +59579,37 @@ const RUNTIME_APIS = {
59430
59579
  registerHost: `registerHost as ${REGISTER_HOST}`,
59431
59580
  registerInstance: `registerInstance as ${REGISTER_INSTANCE}`,
59432
59581
  };
59582
+ /**
59583
+ * Update a Rindo Module entity to include a {@link RUNTIME_APIS} entry if it does not already exist.
59584
+ * This allows Rindo to keep `moduleFile` easily serializable, where this helper function treats the data structure
59585
+ * that stores {@link Module#coreRuntimeApis} similar to a JS `Set`.
59586
+ * @param moduleFile the Module entity to update
59587
+ * @param coreRuntimeApi the API to add to the provided module
59588
+ */
59433
59589
  const addCoreRuntimeApi = (moduleFile, coreRuntimeApi) => {
59434
59590
  if (!moduleFile.coreRuntimeApis.includes(coreRuntimeApi)) {
59435
59591
  moduleFile.coreRuntimeApis.push(coreRuntimeApi);
59436
59592
  }
59437
59593
  };
59594
+ /**
59595
+ * Update a Rindo Module entity to include a {@link RUNTIME_APIS} entry for a specific output target, if it does not
59596
+ * already exist.
59597
+ * This allows Rindo to keep `moduleFile` easily serializable, where this helper function treats the data structure
59598
+ * that stores {@link Module#outputTargetCoreRuntimeApis} similar to a JS `Set`.
59599
+ * @param moduleFile the Module entity to update
59600
+ * @param outputTarget the output target to assign the provided runtime api under
59601
+ * @param coreRuntimeApi the API to add to the provided module
59602
+ */
59603
+ const addOutputTargetCoreRuntimeApi = (moduleFile, outputTarget, coreRuntimeApi) => {
59604
+ if (!moduleFile.outputTargetCoreRuntimeApis[outputTarget]) {
59605
+ // no such output target-specific collection exists, create the empty collection
59606
+ moduleFile.outputTargetCoreRuntimeApis[outputTarget] = [];
59607
+ }
59608
+ if (!moduleFile.outputTargetCoreRuntimeApis[outputTarget].includes(coreRuntimeApi)) {
59609
+ // add the api to the collection
59610
+ moduleFile.outputTargetCoreRuntimeApis[outputTarget].push(coreRuntimeApi);
59611
+ }
59612
+ };
59438
59613
  const addLegacyApis = (moduleFile) => {
59439
59614
  addCoreRuntimeApi(moduleFile, RUNTIME_APIS.legacyH);
59440
59615
  };
@@ -59442,12 +59617,9 @@ const addLegacyApis = (moduleFile) => {
59442
59617
  const addModuleMetadataProxies = (tsSourceFile, moduleFile) => {
59443
59618
  const statements = tsSourceFile.statements.slice();
59444
59619
  addCoreRuntimeApi(moduleFile, RUNTIME_APIS.proxyCustomElement);
59445
- statements.push(...moduleFile.cmps.map(addComponentMetadataProxy));
59620
+ statements.push(...moduleFile.cmps.map(createComponentMetadataProxy));
59446
59621
  return t.factory.updateSourceFile(tsSourceFile, statements);
59447
59622
  };
59448
- const addComponentMetadataProxy = (compilerMeta) => {
59449
- return t.factory.createExpressionStatement(createComponentMetadataProxy(compilerMeta));
59450
- };
59451
59623
  /**
59452
59624
  * Create a call expression for wrapping a component in a proxy. This call expression takes a form:
59453
59625
  * ```ts
@@ -59455,7 +59627,7 @@ const addComponentMetadataProxy = (compilerMeta) => {
59455
59627
  * ```
59456
59628
  * where
59457
59629
  * - `PROXY_CUSTOM_ELEMENT` is a Rindo internal identifier that will be replaced with the name of the actual function
59458
- * name at compile name
59630
+ * name at compile time
59459
59631
  * - `ComponentClassName` is the name Rindo component's class
59460
59632
  * - `Metadata` is the compiler metadata associated with the Rindo component
59461
59633
  *
@@ -59466,30 +59638,49 @@ const createComponentMetadataProxy = (compilerMeta) => {
59466
59638
  const compactMeta = formatComponentRuntimeMeta(compilerMeta, true);
59467
59639
  const literalCmpClassName = t.factory.createIdentifier(compilerMeta.componentClassName);
59468
59640
  const literalMeta = convertValueToLiteral(compactMeta);
59469
- return t.factory.createCallExpression(t.factory.createIdentifier(PROXY_CUSTOM_ELEMENT), [], [literalCmpClassName, literalMeta]);
59641
+ return t.factory.createExpressionStatement(t.factory.createCallExpression(t.factory.createIdentifier(PROXY_CUSTOM_ELEMENT), [], [literalCmpClassName, literalMeta]));
59470
59642
  };
59471
59643
  /**
59472
- * Create a call expression for wrapping a component represented as an anonymous class in a proxy. This call expression
59473
- * takes a form:
59644
+ * Create a call expression for wrapping a component represented as a class
59645
+ * expression in a proxy. This call expression takes the form:
59646
+ *
59474
59647
  * ```ts
59475
59648
  * PROXY_CUSTOM_ELEMENT(Clazz, Metadata);
59476
59649
  * ```
59650
+ *
59477
59651
  * where
59478
- * - `PROXY_CUSTOM_ELEMENT` is a Rindo internal identifier that will be replaced with the name of the actual function
59479
- * name at compile name
59480
- * - `Clazz` is an anonymous class to be proxied
59652
+ * - `PROXY_CUSTOM_ELEMENT` is a Rindo internal identifier that will be
59653
+ * replaced with the name of the actual function name at compile time
59654
+ * - `Clazz` is a class expression to be proxied
59481
59655
  * - `Metadata` is the compiler metadata associated with the Rindo component
59482
59656
  *
59483
- * @param compilerMeta compiler metadata associated with the component to be wrapped in a proxy
59484
- * @param clazz the anonymous class to proxy
59657
+ * @param compilerMeta compiler metadata associated with the component to be
59658
+ * wrapped in a proxy
59659
+ * @param clazz the class expression to proxy
59485
59660
  * @returns the generated call expression
59486
59661
  */
59487
- const createAnonymousClassMetadataProxy = (compilerMeta, clazz) => {
59662
+ const createClassMetadataProxy = (compilerMeta, clazz) => {
59488
59663
  const compactMeta = formatComponentRuntimeMeta(compilerMeta, true);
59489
59664
  const literalMeta = convertValueToLiteral(compactMeta);
59490
59665
  return t.factory.createCallExpression(t.factory.createIdentifier(PROXY_CUSTOM_ELEMENT), [], [clazz, literalMeta]);
59491
59666
  };
59492
59667
 
59668
+ /**
59669
+ * Create a new import statement, and update the provided source file with the newly created statement.
59670
+ *
59671
+ * The generated import statement will be placed at the beginning of the source file.
59672
+ *
59673
+ * The generated import statement will be either a commonjs require statement or esm import statement, based on the
59674
+ * provided transform options.
59675
+ *
59676
+ * The import statement may include more than one named imports (identifiers) for the provided import path.
59677
+ *
59678
+ * @param transformOpts transform options configured for the current output target transpilation
59679
+ * @param tsSourceFile the TypeScript source file that is being updated
59680
+ * @param importFnNames a collection of named imports to add to the generated import statement
59681
+ * @param importPath the path to the module that the collection of named imports should be imported from
59682
+ * @returns the updated TypeScript source file
59683
+ */
59493
59684
  const addImports = (transformOpts, tsSourceFile, importFnNames, importPath) => {
59494
59685
  if (importFnNames.length === 0) {
59495
59686
  return tsSourceFile;
@@ -59543,8 +59734,13 @@ const proxyCustomElement = (compilerCtx, transformOpts) => {
59543
59734
  if (declaration.name.getText() !== principalComponent.componentClassName) {
59544
59735
  continue;
59545
59736
  }
59737
+ // to narrow the type of `declaration.initializer` to `ts.ClassExpression`
59738
+ if (!t.isClassExpression(declaration.initializer)) {
59739
+ continue;
59740
+ }
59741
+ const renamedClassExpression = t.factory.updateClassExpression(declaration.initializer, t.getModifiers(declaration.initializer), t.factory.createIdentifier(principalComponent.componentClassName), declaration.initializer.typeParameters, declaration.initializer.heritageClauses, declaration.initializer.members);
59546
59742
  // wrap the Rindo component's class declaration in a component proxy
59547
- const proxyCreationCall = createAnonymousClassMetadataProxy(principalComponent, declaration.initializer);
59743
+ const proxyCreationCall = createClassMetadataProxy(principalComponent, renamedClassExpression);
59548
59744
  t.addSyntheticLeadingComment(proxyCreationCall, t.SyntaxKind.MultiLineCommentTrivia, '@__PURE__', false);
59549
59745
  // update the component's variable declaration to use the new initializer
59550
59746
  const proxiedComponentDeclaration = t.factory.updateVariableDeclaration(declaration, declaration.name, declaration.exclamationToken, declaration.type, proxyCreationCall);
@@ -59748,6 +59944,13 @@ const syntheticRender = (moduleFile, hasRender) => {
59748
59944
  };
59749
59945
  const INTERNAL_RENDER = '__rindo_render';
59750
59946
 
59947
+ /**
59948
+ * Creates a new collection of class members that belong to the provided class node and that do not exist in
59949
+ * {@link REMOVE_STATIC_GETTERS}
59950
+ * @param classNode the class node in the syntax tree to inspect
59951
+ * @returns a new collection of class members belonging to the provided class node, less those found in
59952
+ * {@link REMOVE_STATIC_GETTERS}
59953
+ */
59751
59954
  const removeStaticMetaProperties = (classNode) => {
59752
59955
  if (classNode.members == null) {
59753
59956
  return [];
@@ -59763,6 +59966,9 @@ const removeStaticMetaProperties = (classNode) => {
59763
59966
  return true;
59764
59967
  });
59765
59968
  };
59969
+ /**
59970
+ * A list of static getter names that are specific to Rindo to exclude from a class's member list
59971
+ */
59766
59972
  const REMOVE_STATIC_GETTERS = new Set([
59767
59973
  'is',
59768
59974
  'properties',
@@ -59848,9 +60054,17 @@ const addNativeConnectedCallback = (classMembers, cmp) => {
59848
60054
  }
59849
60055
  };
59850
60056
 
60057
+ /**
60058
+ * For a Rindo component, generate the code to create custom emitted events, based on `@Event()` decorators
60059
+ * @param moduleFile the 'home module' of the class for which code is being generated
60060
+ * @param cmp the component metadata associated with the provided module
60061
+ * @returns the generated event creation code
60062
+ */
59851
60063
  const addCreateEvents = (moduleFile, cmp) => {
59852
60064
  return cmp.events.map((ev) => {
59853
60065
  addCoreRuntimeApi(moduleFile, RUNTIME_APIS.createEvent);
60066
+ // for `@Event('eventName', { <eventOptions> }`, generate assignment to the class constructor of the form:
60067
+ // this.eventName = createEvent(this, 'eventName', eventOptionsAsBitwiseNumber);
59854
60068
  return t.factory.createExpressionStatement(t.factory.createAssignment(t.factory.createPropertyAccessExpression(t.factory.createThis(), t.factory.createIdentifier(ev.method)), t.factory.createCallExpression(t.factory.createIdentifier(CREATE_EVENT), undefined, [
59855
60069
  t.factory.createThis(),
59856
60070
  t.factory.createStringLiteral(ev.name),
@@ -59858,6 +60072,15 @@ const addCreateEvents = (moduleFile, cmp) => {
59858
60072
  ])));
59859
60073
  });
59860
60074
  };
60075
+ /**
60076
+ * Generate a bit flag encoded with event behavior information.
60077
+ *
60078
+ * This function uses the provided event metadata to determine which flags are set. {@link EVENT_FLAGS} acts as the
60079
+ * backing data structure that sets the actual bits on the returned value.
60080
+ *
60081
+ * @param eventMeta the metadata associated with the event
60082
+ * @returns the encoded event behaviors
60083
+ */
59861
60084
  const computeFlags = (eventMeta) => {
59862
60085
  let flags = 0;
59863
60086
  if (eventMeta.bubbles) {
@@ -59891,7 +60114,21 @@ const getStatement = (propName, method, arg) => {
59891
60114
  ])));
59892
60115
  };
59893
60116
 
59894
- const updateNativeConstructor = (classMembers, moduleFile, cmp, ensureSuper) => {
60117
+ /**
60118
+ * Updates a constructor to include:
60119
+ * - a `super()` call
60120
+ * - function calls to initialize the component
60121
+ * - function calls to create custom event emitters
60122
+ * If a constructor does not exist, one will be created
60123
+ *
60124
+ * The constructor will be added to the provided list of {@link ts.ClassElement}s in place
60125
+ *
60126
+ * @param classMembers the class elements to modify
60127
+ * @param moduleFile the Rindo module representation of the component class
60128
+ * @param cmp the component metadata generated for the component
60129
+ */
60130
+ const updateNativeConstructor = (classMembers, moduleFile, cmp) => {
60131
+ var _a, _b;
59895
60132
  if (cmp.isPlain) {
59896
60133
  return;
59897
60134
  }
@@ -59899,30 +60136,28 @@ const updateNativeConstructor = (classMembers, moduleFile, cmp, ensureSuper) =>
59899
60136
  if (cstrMethodIndex >= 0) {
59900
60137
  // add to the existing constructor()
59901
60138
  const cstrMethod = classMembers[cstrMethodIndex];
60139
+ // a constructor may not have a body (e.g. in the case of constructor overloads)
60140
+ const cstrBodyStatements = (_b = (_a = cstrMethod.body) === null || _a === void 0 ? void 0 : _a.statements) !== null && _b !== void 0 ? _b : t.factory.createNodeArray();
59902
60141
  let statements = [
59903
60142
  ...nativeInit(moduleFile, cmp),
59904
60143
  ...addCreateEvents(moduleFile, cmp),
59905
- ...cstrMethod.body.statements,
60144
+ ...cstrBodyStatements,
59906
60145
  ...addLegacyProps(moduleFile, cmp),
59907
60146
  ];
59908
- if (ensureSuper) {
59909
- const hasSuper = cstrMethod.body.statements.some((s) => s.kind === t.SyntaxKind.SuperKeyword);
59910
- if (!hasSuper) {
59911
- statements = [createNativeConstructorSuper(), ...statements];
59912
- }
60147
+ const hasSuper = cstrBodyStatements.some((s) => s.kind === t.SyntaxKind.SuperKeyword);
60148
+ if (!hasSuper) {
60149
+ statements = [createNativeConstructorSuper(), ...statements];
59913
60150
  }
59914
60151
  classMembers[cstrMethodIndex] = t.factory.updateConstructorDeclaration(cstrMethod, retrieveTsModifiers(cstrMethod), cstrMethod.parameters, t.factory.updateBlock(cstrMethod.body, statements));
59915
60152
  }
59916
60153
  else {
59917
60154
  // create a constructor()
59918
- let statements = [
60155
+ const statements = [
60156
+ createNativeConstructorSuper(),
59919
60157
  ...nativeInit(moduleFile, cmp),
59920
60158
  ...addCreateEvents(moduleFile, cmp),
59921
60159
  ...addLegacyProps(moduleFile, cmp),
59922
60160
  ];
59923
- if (ensureSuper) {
59924
- statements = [createNativeConstructorSuper(), ...statements];
59925
- }
59926
60161
  const cstrMethod = t.factory.createConstructorDeclaration(undefined, [], t.factory.createBlock(statements, true));
59927
60162
  classMembers.unshift(cstrMethod);
59928
60163
  }
@@ -59940,7 +60175,13 @@ const nativeInit = (moduleFile, cmp) => {
59940
60175
  }
59941
60176
  return initStatements;
59942
60177
  };
60178
+ /**
60179
+ * Generate an expression statement to register a host element with its VDOM equivalent in a global element-to-vdom
60180
+ * mapping.
60181
+ * @returns the generated expression statement
60182
+ */
59943
60183
  const nativeRegisterHostStatement = () => {
60184
+ // Create an expression statement, `this.__registerHost();`
59944
60185
  return t.factory.createExpressionStatement(t.factory.createCallExpression(t.factory.createPropertyAccessExpression(t.factory.createThis(), t.factory.createIdentifier('__registerHost')), undefined, undefined));
59945
60186
  };
59946
60187
  /**
@@ -59949,12 +60190,16 @@ const nativeRegisterHostStatement = () => {
59949
60190
  * @returns the generated expression statement
59950
60191
  */
59951
60192
  const nativeAttachShadowStatement = (moduleFile) => {
59952
- addCoreRuntimeApi(moduleFile, RUNTIME_APIS.attachShadow);
60193
+ addOutputTargetCoreRuntimeApi(moduleFile, DIST_CUSTOM_ELEMENTS, RUNTIME_APIS.attachShadow);
59953
60194
  // Create an expression statement, `this.__attachShadow();`
59954
60195
  return t.factory.createExpressionStatement(t.factory.createCallExpression(t.factory.createPropertyAccessExpression(t.factory.createThis(), t.factory.createIdentifier('__attachShadow')), undefined, undefined));
59955
60196
  };
60197
+ /**
60198
+ * Create an expression statement for calling `super()` for a class.
60199
+ * @returns the generated expression statement
60200
+ */
59956
60201
  const createNativeConstructorSuper = () => {
59957
- return t.factory.createExpressionStatement(t.factory.createCallExpression(t.factory.createIdentifier('super'), undefined, undefined));
60202
+ return t.factory.createExpressionStatement(t.factory.createCallExpression(t.factory.createSuper(), undefined, undefined));
59958
60203
  };
59959
60204
 
59960
60205
  const addNativeElementGetter = (classMembers, cmp) => {
@@ -60058,11 +60303,19 @@ const updateNativeComponentClass = (transformOpts, classNode, moduleFile, cmp) =
60058
60303
  const members = updateNativeHostComponentMembers(transformOpts, classNode, moduleFile, cmp);
60059
60304
  return updateComponentClass(transformOpts, classNode, heritageClauses, members);
60060
60305
  };
60306
+ /**
60307
+ * Generate a heritage clause (e.g. `extends [IDENTIFIER]`) for a Rindo component to extend `HTMLElement`
60308
+ * @param classNode the syntax tree of the Rindo component class to update
60309
+ * @param moduleFile the Rindo Module associated with the provided class node
60310
+ * @returns the generated heritage clause
60311
+ */
60061
60312
  const updateNativeHostComponentHeritageClauses = (classNode, moduleFile) => {
60062
60313
  if (classNode.heritageClauses != null && classNode.heritageClauses.length > 0) {
60314
+ // the syntax tree has a heritage clause already, don't generate a new one
60063
60315
  return classNode.heritageClauses;
60064
60316
  }
60065
60317
  if (moduleFile.cmps.length >= 1) {
60318
+ // we'll need to import `HTMLElement` in order to extend it
60066
60319
  addCoreRuntimeApi(moduleFile, RUNTIME_APIS.HTMLElement);
60067
60320
  }
60068
60321
  const heritageClause = t.factory.createHeritageClause(t.SyntaxKind.ExtendsKeyword, [
@@ -60072,7 +60325,7 @@ const updateNativeHostComponentHeritageClauses = (classNode, moduleFile) => {
60072
60325
  };
60073
60326
  const updateNativeHostComponentMembers = (transformOpts, classNode, moduleFile, cmp) => {
60074
60327
  const classMembers = removeStaticMetaProperties(classNode);
60075
- updateNativeConstructor(classMembers, moduleFile, cmp, true);
60328
+ updateNativeConstructor(classMembers, moduleFile, cmp);
60076
60329
  addNativeConnectedCallback(classMembers, cmp);
60077
60330
  addNativeElementGetter(classMembers, cmp);
60078
60331
  addWatchers(classMembers, cmp);
@@ -60086,10 +60339,24 @@ const updateNativeHostComponentMembers = (transformOpts, classNode, moduleFile,
60086
60339
  return classMembers;
60087
60340
  };
60088
60341
 
60342
+ /**
60343
+ * A function that returns a transformation factory. The returned factory performs a series of transformations on
60344
+ * Rindo components, in order to generate 'native' web components.
60345
+ * @param compilerCtx the current compiler context, which acts as the source of truth for the transformations
60346
+ * @param transformOpts the transformation configuration to use when performing the transformations
60347
+ * @returns a transformer factory, to be run by the TypeScript compiler
60348
+ */
60089
60349
  const nativeComponentTransform = (compilerCtx, transformOpts) => {
60090
60350
  return (transformCtx) => {
60091
60351
  return (tsSourceFile) => {
60352
+ var _a, _b;
60092
60353
  const moduleFile = getModuleFromSourceFile(compilerCtx, tsSourceFile);
60354
+ /**
60355
+ * Helper function that recursively walks the concrete syntax tree. Upon finding a class declaration that Rindo
60356
+ * recognizes as a component, update the component class
60357
+ * @param node the current node in the tree being inspected
60358
+ * @returns the updated component class, or the unchanged node
60359
+ */
60093
60360
  const visitNode = (node) => {
60094
60361
  if (t.isClassDeclaration(node)) {
60095
60362
  const cmp = getComponentMeta(compilerCtx, tsSourceFile, node);
@@ -60114,7 +60381,11 @@ const nativeComponentTransform = (compilerCtx, transformOpts) => {
60114
60381
  if (moduleFile.isLegacy) {
60115
60382
  addLegacyApis(moduleFile);
60116
60383
  }
60117
- tsSourceFile = addImports(transformOpts, tsSourceFile, moduleFile.coreRuntimeApis, transformOpts.coreImportPath);
60384
+ const imports = [
60385
+ ...((_a = moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.coreRuntimeApis) !== null && _a !== void 0 ? _a : []),
60386
+ ...((_b = moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.outputTargetCoreRuntimeApis[DIST_CUSTOM_ELEMENTS]) !== null && _b !== void 0 ? _b : []),
60387
+ ];
60388
+ tsSourceFile = addImports(transformOpts, tsSourceFile, imports, transformOpts.coreImportPath);
60118
60389
  return tsSourceFile;
60119
60390
  };
60120
60391
  };
@@ -60331,6 +60602,14 @@ const updateBuildConditionals = (config, b) => {
60331
60602
  }
60332
60603
  };
60333
60604
 
60605
+ /**
60606
+ * Get build conditions appropriate for the `dist-custom-elements` Output
60607
+ * Target, including disabling lazy loading and hydration.
60608
+ *
60609
+ * @param config a validated user-supplied config
60610
+ * @param cmps metadata about the components currently being compiled
60611
+ * @returns build conditionals appropriate for the `dist-custom-elements` OT
60612
+ */
60334
60613
  const getCustomElementsBuildConditionals = (config, cmps) => {
60335
60614
  // because custom elements bundling does not customize the build conditionals by default
60336
60615
  // then the default in "import { BUILD, NAMESPACE } from '@rindo/core/internal/app-data'"
@@ -60365,9 +60644,9 @@ const outputCustomElements = async (config, compilerCtx, buildCtx) => {
60365
60644
  if (outputTargets.length === 0) {
60366
60645
  return;
60367
60646
  }
60368
- const bundlingEventMessage = 'generate custom elements';
60647
+ const bundlingEventMessage = `generate custom elements${config.sourceMap ? ' + source maps' : ''}`;
60369
60648
  const timespan = buildCtx.createTimeSpan(`${bundlingEventMessage} started`);
60370
- await Promise.all(outputTargets.map((target) => bundleCustomElements$1(config, compilerCtx, buildCtx, target)));
60649
+ await Promise.all(outputTargets.map((target) => bundleCustomElements(config, compilerCtx, buildCtx, target)));
60371
60650
  timespan.finish(`${bundlingEventMessage} finished`);
60372
60651
  };
60373
60652
  /**
@@ -60409,7 +60688,7 @@ const getBundleOptions = (config, buildCtx, compilerCtx, outputTarget) => ({
60409
60688
  * @param outputTarget the outputTarget we're currently dealing with
60410
60689
  * @returns an empty promise
60411
60690
  */
60412
- const bundleCustomElements$1 = async (config, compilerCtx, buildCtx, outputTarget) => {
60691
+ const bundleCustomElements = async (config, compilerCtx, buildCtx, outputTarget) => {
60413
60692
  try {
60414
60693
  const bundleOpts = getBundleOptions(config, buildCtx, compilerCtx, outputTarget);
60415
60694
  addCustomElementInputs(buildCtx, bundleOpts, outputTarget);
@@ -60515,7 +60794,7 @@ const addCustomElementInputs = (buildCtx, bundleOpts, outputTarget) => {
60515
60794
  bundleOpts.loader[coreKey] = exp.join('\n');
60516
60795
  });
60517
60796
  // Generate the contents of the entry file to be created by the bundler
60518
- bundleOpts.loader['\0core'] = generateEntryPoint$1(outputTarget, indexImports, indexExports, exportNames);
60797
+ bundleOpts.loader['\0core'] = generateEntryPoint(outputTarget, indexImports, indexExports, exportNames);
60519
60798
  };
60520
60799
  /**
60521
60800
  * Generate the entrypoint (`index.ts` file) contents for the `dist-custom-elements` output target
@@ -60525,7 +60804,7 @@ const addCustomElementInputs = (buildCtx, bundleOpts, outputTarget) => {
60525
60804
  * @param cmpNames The exported component names (could be aliased) from local component modules.
60526
60805
  * @returns the stringified contents to be placed in the entrypoint
60527
60806
  */
60528
- const generateEntryPoint$1 = (outputTarget, cmpImports = [], cmpExports = [], cmpNames = []) => {
60807
+ const generateEntryPoint = (outputTarget, cmpImports = [], cmpExports = [], cmpNames = []) => {
60529
60808
  const body = [];
60530
60809
  const imports = [];
60531
60810
  const exports = [];
@@ -60586,134 +60865,6 @@ const getCustomElementCustomTransformer = (config, compilerCtx, components, outp
60586
60865
  ];
60587
60866
  };
60588
60867
 
60589
- // TODO: fully delete dist-custom-elements-bundle code
60590
- const outputCustomElementsBundle = async (config, compilerCtx, buildCtx) => {
60591
- if (!config.buildDist) {
60592
- return;
60593
- }
60594
- const outputTargets = config.outputTargets.filter(isOutputTargetDistCustomElementsBundle);
60595
- if (outputTargets.length === 0) {
60596
- return;
60597
- }
60598
- const bundlingEventMessage = `generate custom elements bundle${config.sourceMap ? ' + source maps' : ''}`;
60599
- const timespan = buildCtx.createTimeSpan(`${bundlingEventMessage} started`);
60600
- await Promise.all(outputTargets.map((o) => bundleCustomElements(config, compilerCtx, buildCtx, o)));
60601
- timespan.finish(`${bundlingEventMessage} finished`);
60602
- };
60603
- const bundleCustomElements = async (config, compilerCtx, buildCtx, outputTarget) => {
60604
- try {
60605
- const bundleOpts = {
60606
- id: 'customElementsBundle',
60607
- platform: 'client',
60608
- conditionals: getCustomElementsBuildConditionals(config, buildCtx.components),
60609
- customTransformers: getCustomElementBundleCustomTransformer(config, compilerCtx),
60610
- externalRuntime: !!outputTarget.externalRuntime,
60611
- inlineWorkers: true,
60612
- inputs: {
60613
- index: '\0core',
60614
- },
60615
- loader: {
60616
- '\0core': generateEntryPoint(outputTarget, buildCtx),
60617
- },
60618
- preserveEntrySignatures: 'allow-extension',
60619
- };
60620
- const build = await bundleOutput(config, compilerCtx, buildCtx, bundleOpts);
60621
- if (build) {
60622
- const rollupOutput = await build.generate({
60623
- banner: generatePreamble(config),
60624
- format: 'esm',
60625
- sourcemap: config.sourceMap,
60626
- chunkFileNames: outputTarget.externalRuntime || !config.hashFileNames ? '[name].js' : 'p-[hash].js',
60627
- entryFileNames: '[name].js',
60628
- hoistTransitiveImports: false,
60629
- preferConst: true,
60630
- });
60631
- const minify = outputTarget.externalRuntime || outputTarget.minify !== true ? false : config.minifyJs;
60632
- const files = rollupOutput.output.map(async (bundle) => {
60633
- if (bundle.type === 'chunk') {
60634
- let code = bundle.code;
60635
- let sourceMap = rollupToRindoSourceMap(bundle.map);
60636
- const optimizeResults = await optimizeModule(config, compilerCtx, {
60637
- input: code,
60638
- isCore: bundle.isEntry,
60639
- minify,
60640
- sourceMap,
60641
- });
60642
- buildCtx.diagnostics.push(...optimizeResults.diagnostics);
60643
- if (!hasError(optimizeResults.diagnostics) && typeof optimizeResults.output === 'string') {
60644
- code = optimizeResults.output;
60645
- sourceMap = optimizeResults.sourceMap;
60646
- }
60647
- if (sourceMap) {
60648
- code = code + getSourceMappingUrlForEndOfFile(bundle.fileName);
60649
- await compilerCtx.fs.writeFile(join(outputTarget.dir, bundle.fileName + '.map'), JSON.stringify(sourceMap), {
60650
- outputTargetType: outputTarget.type,
60651
- });
60652
- }
60653
- await compilerCtx.fs.writeFile(join(outputTarget.dir, bundle.fileName), code, {
60654
- outputTargetType: outputTarget.type,
60655
- });
60656
- }
60657
- });
60658
- await Promise.all(files);
60659
- }
60660
- }
60661
- catch (e) {
60662
- catchError(buildCtx.diagnostics, e);
60663
- }
60664
- };
60665
- const generateEntryPoint = (outputTarget, buildCtx) => {
60666
- const imp = [];
60667
- const exp = [];
60668
- const exportNames = [];
60669
- imp.push(`import { proxyCustomElement } from '${RINDO_INTERNAL_CLIENT_ID}';`, `export { setAssetPath, setPlatformOptions } from '${RINDO_INTERNAL_CLIENT_ID}';`, `export * from '${USER_INDEX_ENTRY_ID}';`);
60670
- if (outputTarget.includeGlobalScripts !== false) {
60671
- imp.push(`import { globalScripts } from '${RINDO_APP_GLOBALS_ID}';`, `globalScripts();`);
60672
- }
60673
- buildCtx.components.forEach((cmp) => {
60674
- const exportName = dashToPascalCase$1(cmp.tagName);
60675
- const importName = cmp.componentClassName;
60676
- const importAs = `$Cmp${exportName}`;
60677
- if (cmp.isPlain) {
60678
- exp.push(`export { ${importName} as ${exportName} } from '${cmp.sourceFilePath}';`);
60679
- }
60680
- else {
60681
- const meta = stringifyRuntimeData(formatComponentRuntimeMeta(cmp, false));
60682
- imp.push(`import { ${importName} as ${importAs} } from '${cmp.sourceFilePath}';`);
60683
- exp.push(`export const ${exportName} = /*@__PURE__*/proxyCustomElement(${importAs}, ${meta});`);
60684
- }
60685
- exportNames.push(exportName);
60686
- });
60687
- exp.push(`export const defineCustomElements = (opts) => {`);
60688
- exp.push(` if (typeof customElements !== 'undefined') {`);
60689
- exp.push(` [`);
60690
- exp.push(` ${exportNames.join(',\n ')}`);
60691
- exp.push(` ].forEach(cmp => {`);
60692
- exp.push(` if (!customElements.get(cmp.is)) {`);
60693
- exp.push(` customElements.define(cmp.is, cmp, opts);`);
60694
- exp.push(` }`);
60695
- exp.push(` });`);
60696
- exp.push(` }`);
60697
- exp.push(`};`);
60698
- return [...imp, ...exp].join('\n') + '\n';
60699
- };
60700
- const getCustomElementBundleCustomTransformer = (config, compilerCtx) => {
60701
- const transformOpts = {
60702
- coreImportPath: RINDO_INTERNAL_CLIENT_ID,
60703
- componentExport: null,
60704
- componentMetadata: null,
60705
- currentDirectory: config.sys.getCurrentDirectory(),
60706
- proxy: null,
60707
- style: 'static',
60708
- styleImportData: 'queryparams',
60709
- };
60710
- return [
60711
- updateRindoCoreImports(transformOpts.coreImportPath),
60712
- nativeComponentTransform(compilerCtx, transformOpts),
60713
- removeCollectionImports(compilerCtx),
60714
- ];
60715
- };
60716
-
60717
60868
  const updateLazyComponentConstructor = (classMembers, moduleFile, cmp) => {
60718
60869
  const cstrMethodArgs = [
60719
60870
  t.factory.createParameterDeclaration(undefined, undefined, t.factory.createIdentifier(HOST_REF_ARG)),
@@ -61770,7 +61921,7 @@ const getBundleId = async (config, entryKey, shouldHash, code, sufix) => {
61770
61921
  };
61771
61922
 
61772
61923
  const generateLazyModules = async (config, compilerCtx, buildCtx, outputTargetType, destinations, results, sourceTarget, isBrowserBuild, sufix) => {
61773
- var _a;
61924
+ var _a, _b;
61774
61925
  if (!Array.isArray(destinations) || destinations.length === 0) {
61775
61926
  return [];
61776
61927
  }
@@ -61781,7 +61932,7 @@ const generateLazyModules = async (config, compilerCtx, buildCtx, outputTargetTy
61781
61932
  const bundleModules = await Promise.all(entryComponentsResults.map((rollupResult) => {
61782
61933
  return generateLazyEntryModule(config, compilerCtx, buildCtx, rollupResult, outputTargetType, destinations, sourceTarget, shouldMinify, isBrowserBuild, sufix);
61783
61934
  }));
61784
- if (!!((_a = config.extras) === null || _a === void 0 ? void 0 : _a.experimentalImportInjection) && !isBrowserBuild) {
61935
+ if ((!!((_a = config.extras) === null || _a === void 0 ? void 0 : _a.experimentalImportInjection) || !!((_b = config.extras) === null || _b === void 0 ? void 0 : _b.enableImportInjection)) && !isBrowserBuild) {
61785
61936
  addStaticImports(rollupResults, bundleModules);
61786
61937
  }
61787
61938
  await Promise.all(chunkResults.map((rollupResult) => {
@@ -63678,7 +63829,7 @@ export interface CustomElementsDefineOptions {
63678
63829
  export declare function defineCustomElements(win?: Window, opts?: CustomElementsDefineOptions): Promise<void>;
63679
63830
  export declare function applyPolyfills(): Promise<void>;
63680
63831
 
63681
- /**
63832
+ /**
63682
63833
  * Used to specify a nonce value that corresponds with an application's CSP.
63683
63834
  * When set, the nonce will be added to all dynamically created script and style tags at runtime.
63684
63835
  * Alternatively, the nonce value can be set on a meta tag in the DOM head
@@ -63699,7 +63850,7 @@ export declare function setNonce(nonce: string): void;
63699
63850
  */
63700
63851
  const generateCustomElementsTypes = async (config, compilerCtx, buildCtx, typesDir) => {
63701
63852
  const outputTargets = config.outputTargets.filter(isOutputTargetDistCustomElements);
63702
- await Promise.all(outputTargets.map((outputTarget) => generateCustomElementsTypesOutput$1(config, compilerCtx, buildCtx, typesDir, outputTarget)));
63853
+ await Promise.all(outputTargets.map((outputTarget) => generateCustomElementsTypesOutput(config, compilerCtx, buildCtx, typesDir, outputTarget)));
63703
63854
  };
63704
63855
  /**
63705
63856
  * Generates types for a single `dist-custom-elements` output target definition in a Rindo project's configuration
@@ -63710,7 +63861,7 @@ const generateCustomElementsTypes = async (config, compilerCtx, buildCtx, typesD
63710
63861
  * @param typesDir path to the directory where type declarations are saved
63711
63862
  * @param outputTarget the output target for which types are being currently generated
63712
63863
  */
63713
- const generateCustomElementsTypesOutput$1 = async (config, compilerCtx, buildCtx, typesDir, outputTarget) => {
63864
+ const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx, typesDir, outputTarget) => {
63714
63865
  const isBarrelExport = outputTarget.customElementsExportBehavior === 'single-export-module';
63715
63866
  const isBundleExport = outputTarget.customElementsExportBehavior === 'bundle';
63716
63867
  // the path where we're going to write the typedef for the whole dist-custom-elements output
@@ -63736,9 +63887,20 @@ const generateCustomElementsTypesOutput$1 = async (config, compilerCtx, buildCtx
63736
63887
  // - get the relative path to the component's source file from the source directory
63737
63888
  // - join that relative path to the relative path from the `index.d.ts` file to the
63738
63889
  // directory where typedefs are saved
63739
- const componentSourceRelPath = relative$1(config.srcDir, component.sourceFilePath).replace('.tsx', '');
63890
+ const componentSourceRelPath = relative$1(config.srcDir, component.sourceFilePath).replace(/\.tsx$/, '');
63740
63891
  const componentDTSPath = join(componentsTypeDirectoryRelPath, componentSourceRelPath);
63741
- return `export { ${importName} as ${exportName} } from '${componentDTSPath}';`;
63892
+ const defineFunctionExportName = `defineCustomElement${exportName}`;
63893
+ // Get the path to the sibling typedef file for the current component
63894
+ // When we bundle the code to generate the component JS files it generates
63895
+ // the JS and typedef files based on the component tag name. So, we can
63896
+ // just use the tagname to create the relative path
63897
+ const localComponentTypeDefFilePath = `./${component.tagName}`;
63898
+ return [
63899
+ `export { ${importName} as ${exportName} } from '${componentDTSPath}';`,
63900
+ // We need to alias each `defineCustomElement` function typedef to match the aliased name given to the
63901
+ // function in the `index.js`
63902
+ `export { defineCustomElement as ${defineFunctionExportName} } from '${localComponentTypeDefFilePath}';`,
63903
+ ].join('\n');
63742
63904
  }),
63743
63905
  ``,
63744
63906
  ]
@@ -63787,7 +63949,7 @@ const generateCustomElementsTypesOutput$1 = async (config, compilerCtx, buildCtx
63787
63949
  ]
63788
63950
  : []),
63789
63951
  ];
63790
- const componentsDtsRelPath = relDts$1(outputTarget.dir, join(typesDir, 'components.d.ts'));
63952
+ const componentsDtsRelPath = relDts(outputTarget.dir, join(typesDir, 'components.d.ts'));
63791
63953
  // To mirror the index.js file and only export the typedefs for the
63792
63954
  // entities exported there, we will re-export the typedefs iff
63793
63955
  // the `customElementsExportBehavior` is set to barrel component exports
@@ -63810,7 +63972,7 @@ const generateCustomElementsTypesOutput$1 = async (config, compilerCtx, buildCtx
63810
63972
  outputTargetType: outputTarget.type,
63811
63973
  });
63812
63974
  await Promise.all(components.map(async (cmp) => {
63813
- const dtsCode = generateCustomElementType$1(componentsDtsRelPath, cmp);
63975
+ const dtsCode = generateCustomElementType(componentsDtsRelPath, cmp);
63814
63976
  const fileName = `${cmp.tagName}.d.ts`;
63815
63977
  const filePath = join(outputTarget.dir, fileName);
63816
63978
  await compilerCtx.fs.writeFile(filePath, dtsCode, { outputTargetType: outputTarget.type });
@@ -63823,7 +63985,7 @@ const generateCustomElementsTypesOutput$1 = async (config, compilerCtx, buildCtx
63823
63985
  * @param cmp the component to generate the type declaration file for
63824
63986
  * @returns the contents of the type declaration file for the provided `cmp`
63825
63987
  */
63826
- const generateCustomElementType$1 = (componentsDtsRelPath, cmp) => {
63988
+ const generateCustomElementType = (componentsDtsRelPath, cmp) => {
63827
63989
  const tagNameAsPascal = dashToPascalCase$1(cmp.tagName);
63828
63990
  const o = [
63829
63991
  `import type { Components, JSX } from "${componentsDtsRelPath}";`,
@@ -63848,89 +64010,6 @@ const generateCustomElementType$1 = (componentsDtsRelPath, cmp) => {
63848
64010
  * @param dtsPath the destination path
63849
64011
  * @returns the relative path from the provided `fromPath` to the `dtsPath`
63850
64012
  */
63851
- const relDts$1 = (fromPath, dtsPath) => {
63852
- dtsPath = relative$1(fromPath, dtsPath);
63853
- if (!dtsPath.startsWith('.')) {
63854
- dtsPath = '.' + dtsPath;
63855
- }
63856
- return normalizePath$2(dtsPath.replace('.d.ts', ''));
63857
- };
63858
-
63859
- // TODO: fully delete dist-custom-elements-bundle code
63860
- const generateCustomElementsBundleTypes = async (config, compilerCtx, buildCtx, distDtsFilePath) => {
63861
- const outputTargets = config.outputTargets.filter(isOutputTargetDistCustomElementsBundle);
63862
- await Promise.all(outputTargets.map((outputTarget) => generateCustomElementsTypesOutput(config, compilerCtx, buildCtx, distDtsFilePath, outputTarget)));
63863
- };
63864
- const generateCustomElementsTypesOutput = async (config, compilerCtx, buildCtx, distDtsFilePath, outputTarget) => {
63865
- const customElementsDtsPath = join(outputTarget.dir, 'index.d.ts');
63866
- const componentsDtsRelPath = relDts(outputTarget.dir, distDtsFilePath);
63867
- const components = buildCtx.components.filter((m) => !m.isCollectionDependency);
63868
- const code = [
63869
- `/* ${config.namespace} custom elements bundle */`,
63870
- ``,
63871
- `import type { Components, JSX } from "${componentsDtsRelPath}";`,
63872
- ``,
63873
- ...components.map(generateCustomElementType),
63874
- `/**`,
63875
- ` * Utility to define all custom elements within this package using the tag name provided in the component's source. `,
63876
- ` * When defining each custom element, it will also check it's safe to define by:`,
63877
- ` *`,
63878
- ` * 1. Ensuring the "customElements" registry is available in the global context (window).`,
63879
- ` * 2. The component tag name is not already defined.`,
63880
- ` *`,
63881
- ` * Use the standard [customElements.define()](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define) `,
63882
- ` * method instead to define custom elements individually, or to provide a different tag name.`,
63883
- ` */`,
63884
- `export declare const defineCustomElements: (opts?: any) => void;`,
63885
- ``,
63886
- `/**`,
63887
- ` * Used to manually set the base path where assets can be found.`,
63888
- ` * If the script is used as "module", it's recommended to use "import.meta.url",`,
63889
- ` * such as "setAssetPath(import.meta.url)". Other options include`,
63890
- ` * "setAssetPath(document.currentScript.src)", or using a bundler's replace plugin to`,
63891
- ` * dynamically set the path at build time, such as "setAssetPath(process.env.ASSET_PATH)".`,
63892
- ` * But do note that this configuration depends on how your script is bundled, or lack of`,
63893
- ` * bunding, and where your assets can be loaded from. Additionally custom bundling`,
63894
- ` * will have to ensure the static assets are copied to its build directory.`,
63895
- ` */`,
63896
- `export declare const setAssetPath: (path: string) => void;`,
63897
- ``,
63898
- `export interface SetPlatformOptions {`,
63899
- ` raf?: (c: FrameRequestCallback) => number;`,
63900
- ` ael?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;`,
63901
- ` rel?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;`,
63902
- ` ce?: (eventName: string, opts?: any) => CustomEvent;`,
63903
- `}`,
63904
- `export declare const setPlatformOptions: (opts: SetPlatformOptions) => void;`,
63905
- ``,
63906
- `export type { Components, JSX };`,
63907
- ``,
63908
- ];
63909
- const usersIndexJsPath = join(config.srcDir, 'index.ts');
63910
- const hasUserIndex = await compilerCtx.fs.access(usersIndexJsPath);
63911
- if (hasUserIndex) {
63912
- const userIndexRelPath = normalizePath$2(dirname(componentsDtsRelPath));
63913
- code.push(`export * from '${userIndexRelPath}';`);
63914
- }
63915
- else {
63916
- code.push(`export * from '${componentsDtsRelPath}';`);
63917
- }
63918
- await compilerCtx.fs.writeFile(customElementsDtsPath, code.join('\n') + `\n`, {
63919
- outputTargetType: outputTarget.type,
63920
- });
63921
- };
63922
- const generateCustomElementType = (cmp) => {
63923
- const tagNameAsPascal = dashToPascalCase$1(cmp.tagName);
63924
- const o = [
63925
- `interface ${tagNameAsPascal} extends Components.${tagNameAsPascal}, HTMLElement {}`,
63926
- `export const ${tagNameAsPascal}: {`,
63927
- ` prototype: ${tagNameAsPascal};`,
63928
- ` new (): ${tagNameAsPascal};`,
63929
- `};`,
63930
- ``,
63931
- ];
63932
- return o.join('\n');
63933
- };
63934
64013
  const relDts = (fromPath, dtsPath) => {
63935
64014
  dtsPath = relative$1(fromPath, dtsPath);
63936
64015
  if (!dtsPath.startsWith('.')) {
@@ -64489,7 +64568,6 @@ const generateTypesOutput = async (config, compilerCtx, buildCtx, outputTarget)
64489
64568
  await generateAppTypes(config, compilerCtx, buildCtx, distPath);
64490
64569
  const { typesDir } = outputTarget;
64491
64570
  if (distDtsFilePath) {
64492
- await generateCustomElementsBundleTypes(config, compilerCtx, buildCtx, distDtsFilePath);
64493
64571
  await generateCustomElementsTypes(config, compilerCtx, buildCtx, typesDir);
64494
64572
  }
64495
64573
  };
@@ -65055,7 +65133,6 @@ const generateOutputTargets = async (config, compilerCtx, buildCtx) => {
65055
65133
  outputCopy(config, compilerCtx, buildCtx),
65056
65134
  outputCollection(config, compilerCtx, buildCtx, changedModuleFiles),
65057
65135
  outputCustomElements(config, compilerCtx, buildCtx),
65058
- outputCustomElementsBundle(config, compilerCtx, buildCtx),
65059
65136
  outputHydrateScript(config, compilerCtx, buildCtx),
65060
65137
  outputLazyLoader(config, compilerCtx),
65061
65138
  outputLazy(config, compilerCtx, buildCtx),
@@ -65080,7 +65157,6 @@ const invalidateRollupCaches = (compilerCtx) => {
65080
65157
 
65081
65158
  const isEmptable = (o) => isOutputTargetDist(o) ||
65082
65159
  isOutputTargetDistCustomElements(o) ||
65083
- isOutputTargetDistCustomElementsBundle(o) ||
65084
65160
  isOutputTargetWww(o) ||
65085
65161
  isOutputTargetDistLazy(o) ||
65086
65162
  isOutputTargetDistLazyLoader(o) ||
@@ -69002,7 +69078,6 @@ const validateModule = async (config, compilerCtx, buildCtx) => {
69002
69078
  * value is supplied
69003
69079
  */
69004
69080
  function recommendedModulePath(config) {
69005
- const customElementsBundleOT = config.outputTargets.find(isOutputTargetDistCustomElementsBundle);
69006
69081
  const customElementsOT = config.outputTargets.find(isOutputTargetDistCustomElements);
69007
69082
  const distCollectionOT = config.outputTargets.find(isOutputTargetDistCollection);
69008
69083
  if (distCollectionOT) {
@@ -69012,10 +69087,6 @@ function recommendedModulePath(config) {
69012
69087
  const componentsIndexAbs = join(customElementsOT.dir, 'index.js');
69013
69088
  return relative$1(config.rootDir, componentsIndexAbs);
69014
69089
  }
69015
- if (customElementsBundleOT) {
69016
- const customElementsAbs = join(customElementsBundleOT.dir, 'index.js');
69017
- return relative$1(config.rootDir, customElementsAbs);
69018
- }
69019
69090
  // if no output target for which we define a recommended output target is set
69020
69091
  // we return `null`
69021
69092
  return null;
@@ -69584,6 +69655,12 @@ const createWatchBuild = async (config, compilerCtx) => {
69584
69655
  buildCtx.hasStyleChanges = hasStyleChanges(buildCtx);
69585
69656
  buildCtx.hasHtmlChanges = hasHtmlChanges(config, buildCtx);
69586
69657
  buildCtx.hasServiceWorkerChanges = hasServiceWorkerChanges(config, buildCtx);
69658
+ if (config.flags.debug) {
69659
+ config.logger.debug(`WATCH_BUILD::watchBuild::onBuild filesAdded: ${formatFilesForDebug(buildCtx.filesAdded)}`);
69660
+ config.logger.debug(`WATCH_BUILD::watchBuild::onBuild filesDeleted: ${formatFilesForDebug(buildCtx.filesDeleted)}`);
69661
+ config.logger.debug(`WATCH_BUILD::watchBuild::onBuild filesUpdated: ${formatFilesForDebug(buildCtx.filesUpdated)}`);
69662
+ config.logger.debug(`WATCH_BUILD::watchBuild::onBuild filesWritten: ${formatFilesForDebug(buildCtx.filesWritten)}`);
69663
+ }
69587
69664
  dirsAdded.clear();
69588
69665
  dirsDeleted.clear();
69589
69666
  filesAdded.clear();
@@ -69596,6 +69673,21 @@ const createWatchBuild = async (config, compilerCtx) => {
69596
69673
  isRebuild = true;
69597
69674
  }
69598
69675
  };
69676
+ /**
69677
+ * Utility method for formatting a debug message that must either list a number of files, or the word 'none' if the
69678
+ * provided list is empty
69679
+ * @param files a list of files, the list may be empty
69680
+ * @returns the provided list if it is not empty. otherwise, return the word 'none'
69681
+ */
69682
+ const formatFilesForDebug = (files) => {
69683
+ /**
69684
+ * In the created message, it's important that there's no whitespace prior to the file name.
69685
+ * Rindo's logger will split messages by whitespace according to the width of the terminal window.
69686
+ * Since file names can be fully qualified paths (and therefore quite long), putting whitespace between a '-' and
69687
+ * the path can lead to formatted messages where the '-' is on its own line
69688
+ */
69689
+ return files.length > 0 ? files.map((filename) => `-${filename}`).join('\n') : 'none';
69690
+ };
69599
69691
  const start = async () => {
69600
69692
  const srcRead = watchSrcDirectory(config, compilerCtx);
69601
69693
  const otherRead = watchRootFiles(config, compilerCtx);
@@ -69626,7 +69718,7 @@ const createWatchBuild = async (config, compilerCtx) => {
69626
69718
  filesDeleted.add(p);
69627
69719
  break;
69628
69720
  }
69629
- config.logger.debug(`onFsChange ${eventKind}: ${p}`);
69721
+ config.logger.debug(`WATCH_BUILD::fs_event_change - type=${eventKind}, path=${p}, time=${new Date().getTime()}`);
69630
69722
  tsWatchProgram.rebuild();
69631
69723
  }
69632
69724
  };
@@ -71398,32 +71490,6 @@ const validateCustomElement = (config, userOutputs) => {
71398
71490
  }, []);
71399
71491
  };
71400
71492
 
71401
- // TODO: fully delete dist-custom-elements-bundle code
71402
- const validateCustomElementBundle = (config, userOutputs) => {
71403
- return userOutputs.filter(isOutputTargetDistCustomElementsBundle).reduce((arr, o) => {
71404
- const outputTarget = {
71405
- ...o,
71406
- dir: getAbsolutePath(config, o.dir || 'dist/custom-elements'),
71407
- };
71408
- if (!isBoolean$1(outputTarget.empty)) {
71409
- outputTarget.empty = true;
71410
- }
71411
- if (!isBoolean$1(outputTarget.externalRuntime)) {
71412
- outputTarget.externalRuntime = true;
71413
- }
71414
- outputTarget.copy = validateCopy(outputTarget.copy, []);
71415
- if (outputTarget.copy.length > 0) {
71416
- arr.push({
71417
- type: COPY,
71418
- dir: config.rootDir,
71419
- copy: [...outputTarget.copy],
71420
- });
71421
- }
71422
- arr.push(outputTarget);
71423
- return arr;
71424
- }, []);
71425
- };
71426
-
71427
71493
  const validateCustomOutput = (config, diagnostics, userOutputs) => {
71428
71494
  return userOutputs.filter(isOutputTargetCustom).map((o) => {
71429
71495
  if (o.validate) {
@@ -71925,7 +71991,6 @@ const validateOutputTargets = (config, diagnostics) => {
71925
71991
  config.outputTargets = [
71926
71992
  ...validateCollection(config, userOutputs),
71927
71993
  ...validateCustomElement(config, userOutputs),
71928
- ...validateCustomElementBundle(config, userOutputs),
71929
71994
  ...validateCustomOutput(config, diagnostics, userOutputs),
71930
71995
  ...validateLazy(config, userOutputs),
71931
71996
  ...validateWww(config, diagnostics, userOutputs),
@@ -73676,10 +73741,12 @@ const transpileModule = (config, input, transformOpts) => {
73676
73741
  return normalizePath$2(fileName) === normalizePath$2(sourceFilePath) ? sourceFile : undefined;
73677
73742
  },
73678
73743
  writeFile: (name, text) => {
73679
- if (name.endsWith('.js.map')) {
73744
+ if (name.endsWith('.js.map') || name.endsWith('.mjs.map')) {
73680
73745
  results.map = text;
73681
73746
  }
73682
- else if (name.endsWith('.js')) {
73747
+ else if (name.endsWith('.js') || name.endsWith('.mjs')) {
73748
+ // if the source file is an ES module w/ `.mjs` extension then
73749
+ // TypeScript will output a `.mjs` file
73683
73750
  results.code = text;
73684
73751
  }
73685
73752
  },