@stencil/core 5.0.0-alpha.9 → 5.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +94 -0
  2. package/dist/app-data/index.d.ts +1 -1
  3. package/dist/app-data/index.js +4 -1
  4. package/dist/client-BRu0GtRn.mjs +2368 -0
  5. package/dist/compiler/index.d.mts +167 -3
  6. package/dist/compiler/index.mjs +3 -3
  7. package/dist/compiler/utils/index.d.mts +272 -2
  8. package/dist/compiler/utils/index.mjs +4 -3
  9. package/dist/{compiler-C0qmPoKu.mjs → compiler-NrvbUOX1.mjs} +2754 -1259
  10. package/dist/declarations/stencil-ext-modules.d.ts +5 -5
  11. package/dist/declarations/stencil-public-compiler.d.ts +208 -66
  12. package/dist/declarations/stencil-public-docs.d.ts +9 -0
  13. package/dist/declarations/stencil-public-runtime.d.ts +91 -6
  14. package/dist/fragment-Di1hWOC8.mjs +4 -0
  15. package/dist/{regular-expression-CFVJOTUh.mjs → helpers-Cpp3qc3u.mjs} +31 -15
  16. package/dist/index-BOrz3rbJ.d.mts +100 -0
  17. package/dist/{index-xAkMgLX_.d.ts → index-DnISpqrd.d.ts} +149 -9
  18. package/dist/{index-vY35H18z.d.mts → index-RrQfiPWK.d.mts} +490 -845
  19. package/dist/index.d.mts +4 -0
  20. package/dist/index.mjs +91 -2
  21. package/dist/jsx-runtime.mjs +2 -1
  22. package/dist/{node--akYC-sG.mjs → node-75gQKkFz.mjs} +60 -58
  23. package/dist/{chunk-z9aeyW2b.mjs → rolldown-runtime-BhDjJH2R.mjs} +1 -1
  24. package/dist/runtime/client/lazy.js +481 -184
  25. package/dist/runtime/client/runtime.d.ts +149 -10
  26. package/dist/runtime/client/runtime.js +481 -184
  27. package/dist/runtime/index.d.ts +6 -4
  28. package/dist/runtime/index.js +480 -182
  29. package/dist/runtime/server/index.d.mts +80 -8
  30. package/dist/runtime/server/index.mjs +403 -177
  31. package/dist/runtime/server/runner.d.mts +3 -0
  32. package/dist/runtime/server/runner.mjs +320 -337
  33. package/dist/signals/index.d.ts +2 -0
  34. package/dist/signals/index.js +4 -1
  35. package/dist/sys/node/index.d.mts +1 -2
  36. package/dist/sys/node/index.mjs +1 -1
  37. package/dist/sys/node/worker.d.mts +1 -1
  38. package/dist/sys/node/worker.mjs +6 -3
  39. package/dist/testing/index.d.mts +4716 -105
  40. package/dist/testing/index.mjs +7590 -794
  41. package/dist/util-IKfWWLJo.mjs +724 -0
  42. package/dist/validation-DAdGTrys.mjs +791 -0
  43. package/package.json +27 -27
  44. package/dist/client-aTQ7xHxx.mjs +0 -4678
  45. package/dist/index-BvkyxSY6.d.mts +0 -205
  46. package/dist/validation-ByxKj8bC.mjs +0 -1458
  47. /package/{LICENSE.md → LICENSE} +0 -0
@@ -0,0 +1,791 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
+ import { C as CMP_FLAGS, H as LISTENER_FLAGS, W as MEMBER_FLAGS, et as WATCH_FLAGS, f as isString, l as isIterable, y as toTitleCase } from "./helpers-Cpp3qc3u.mjs";
3
+ import { K as normalizePath, Q as buildWarn } from "./util-IKfWWLJo.mjs";
4
+ //#region src/utils/regular-expression.ts
5
+ /**
6
+ * Utility function that will escape all regular expression special characters in a string.
7
+ *
8
+ * @param text The string potentially containing special characters.
9
+ * @returns The string with all special characters escaped.
10
+ */
11
+ const escapeRegExpSpecialCharacters = (text) => {
12
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
13
+ };
14
+ //#endregion
15
+ //#region src/utils/byte-size.ts
16
+ /**
17
+ * Used to learn the size of a string in bytes.
18
+ *
19
+ * @param str The string to measure
20
+ * @returns number
21
+ */
22
+ const byteSize = (str) => Buffer.byteLength(str, "utf8");
23
+ //#endregion
24
+ //#region src/utils/format-component-runtime-meta.ts
25
+ const formatLazyBundleRuntimeMeta = (bundleId, cmps) => {
26
+ return [bundleId, cmps.map((cmp) => formatComponentRuntimeMeta(cmp, true))];
27
+ };
28
+ /**
29
+ * Transform metadata about a component from the compiler to a compact form for
30
+ * use at runtime.
31
+ *
32
+ * @param compilerMeta component metadata gathered during compilation
33
+ * @param includeMethods include methods in the component's members or not
34
+ * @returns a compact format for component metadata, intended for runtime use
35
+ */
36
+ const formatComponentRuntimeMeta = (compilerMeta, includeMethods) => {
37
+ let flags = 0;
38
+ if (compilerMeta.encapsulation === "shadow") {
39
+ flags |= CMP_FLAGS.shadowDomEncapsulation;
40
+ if (compilerMeta.shadowDelegatesFocus) flags |= CMP_FLAGS.shadowDelegatesFocus;
41
+ if (compilerMeta.slotAssignment === "manual") flags |= CMP_FLAGS.shadowSlotAssignmentManual;
42
+ if (compilerMeta.shadowMode === "closed") flags |= CMP_FLAGS.shadowModeClosed;
43
+ if (compilerMeta.shadowClonable) flags |= CMP_FLAGS.shadowClonable;
44
+ if (compilerMeta.shadowSerializable) flags |= CMP_FLAGS.shadowSerializable;
45
+ } else if (compilerMeta.encapsulation === "scoped") flags |= CMP_FLAGS.scopedCssEncapsulation;
46
+ if (compilerMeta.formAssociated) flags |= CMP_FLAGS.formAssociated;
47
+ if (compilerMeta.encapsulation !== "shadow" && compilerMeta.htmlTagNames.includes("slot")) flags |= CMP_FLAGS.hasSlotRelocation;
48
+ if (compilerMeta.hasSlot) flags |= CMP_FLAGS.hasSlot;
49
+ if (compilerMeta.hasMode) flags |= CMP_FLAGS.hasMode;
50
+ if (compilerMeta.hasModernPropertyDecls) flags |= CMP_FLAGS.hasModernPropertyDecls;
51
+ if (compilerMeta.patches) {
52
+ if (compilerMeta.patches.all) flags |= CMP_FLAGS.patchAll;
53
+ if (compilerMeta.patches.children) flags |= CMP_FLAGS.patchChildren;
54
+ if (compilerMeta.patches.clone) flags |= CMP_FLAGS.patchClone;
55
+ if (compilerMeta.patches.insert) flags |= CMP_FLAGS.patchInsert;
56
+ }
57
+ const members = formatComponentRuntimeMembers(compilerMeta, includeMethods);
58
+ const hostListeners = formatHostListeners(compilerMeta);
59
+ const watchers = formatComponentRuntimeReactiveHandlers(compilerMeta, "watchers");
60
+ const serializers = formatComponentRuntimeReactiveHandlers(compilerMeta, "serializers");
61
+ const deserializers = formatComponentRuntimeReactiveHandlers(compilerMeta, "deserializers");
62
+ return trimFalsy([
63
+ flags,
64
+ compilerMeta.tagName,
65
+ Object.keys(members).length > 0 ? members : void 0,
66
+ hostListeners.length > 0 ? hostListeners : void 0,
67
+ Object.keys(watchers).length > 0 ? watchers : void 0,
68
+ Object.keys(serializers).length > 0 ? serializers : void 0,
69
+ Object.keys(deserializers).length > 0 ? deserializers : void 0
70
+ ]);
71
+ };
72
+ const stringifyRuntimeData = (data) => {
73
+ const json = JSON.stringify(data);
74
+ if (json.length > 1e4) return `JSON.parse(${JSON.stringify(json)})`;
75
+ return json;
76
+ };
77
+ /**
78
+ * Transforms Stencil compiler metadata into a {@link d.ComponentCompilerMeta} object.
79
+ * This handles processing any compiler metadata transformed from components' uses of `@Watch()`, `@PropSerialize()`, and `@AttrDeserialize()`.
80
+ * The map of watched properties to their callback(s) will be immediately available
81
+ * to the runtime at bootstrap.
82
+ *
83
+ * @param compilerMeta Component metadata gathered during compilation
84
+ * @param decorator The decorator type to be processed: 'watchers', 'serializers', or 'deserializers'
85
+ * @returns An object mapping watched properties to their respective callback(s)
86
+ */
87
+ const formatComponentRuntimeReactiveHandlers = (compilerMeta, decorator) => {
88
+ const handlers = {};
89
+ compilerMeta[decorator]?.forEach(({ propName, methodName, handlerOptions }) => {
90
+ let watcherFlags = 0;
91
+ if (handlerOptions?.immediate) watcherFlags |= WATCH_FLAGS.Immediate;
92
+ handlers[propName] = [...handlers[propName] ?? [], { [methodName]: watcherFlags }];
93
+ });
94
+ return handlers;
95
+ };
96
+ const formatComponentRuntimeMembers = (compilerMeta, includeMethods = true) => {
97
+ return {
98
+ ...formatPropertiesRuntimeMember(compilerMeta.properties),
99
+ ...formatStatesRuntimeMember(compilerMeta.states),
100
+ ...includeMethods ? formatMethodsRuntimeMember(compilerMeta.methods) : {}
101
+ };
102
+ };
103
+ const formatPropertiesRuntimeMember = (properties) => {
104
+ const runtimeMembers = {};
105
+ properties.forEach((member) => {
106
+ runtimeMembers[member.name] = trimFalsy([formatFlags(member), formatAttrName(member)]);
107
+ });
108
+ return runtimeMembers;
109
+ };
110
+ const formatFlags = (compilerProperty) => {
111
+ let type = formatPropType(compilerProperty.type);
112
+ if (compilerProperty.mutable) type |= MEMBER_FLAGS.Mutable;
113
+ if (compilerProperty.reflect) type |= MEMBER_FLAGS.ReflectAttr;
114
+ if (compilerProperty.getter) type |= MEMBER_FLAGS.Getter;
115
+ if (compilerProperty.setter) type |= MEMBER_FLAGS.Setter;
116
+ return type;
117
+ };
118
+ /**
119
+ * We mainly add the alternative kebab-case attribute name because it might
120
+ * be used in an HTML environment (non JSX). Since we support hydration of
121
+ * complex types we provide a kebab-case attribute name for properties with
122
+ * these types.
123
+ */
124
+ const kebabCaseSupportForTypes = ["string", "unknown"];
125
+ const formatAttrName = (compilerProperty) => {
126
+ if (kebabCaseSupportForTypes.includes(typeof compilerProperty.attribute)) {
127
+ if (compilerProperty.name === compilerProperty.attribute) return;
128
+ return compilerProperty.attribute;
129
+ }
130
+ };
131
+ const formatPropType = (type) => {
132
+ if (type === "string") return MEMBER_FLAGS.String;
133
+ if (type === "number") return MEMBER_FLAGS.Number;
134
+ if (type === "boolean") return MEMBER_FLAGS.Boolean;
135
+ if (type === "any") return MEMBER_FLAGS.Any;
136
+ return MEMBER_FLAGS.Unknown;
137
+ };
138
+ const formatStatesRuntimeMember = (states) => {
139
+ const runtimeMembers = {};
140
+ states.forEach((member) => {
141
+ runtimeMembers[member.name] = [MEMBER_FLAGS.State];
142
+ });
143
+ return runtimeMembers;
144
+ };
145
+ const formatMethodsRuntimeMember = (methods) => {
146
+ const runtimeMembers = {};
147
+ methods.forEach((member) => {
148
+ runtimeMembers[member.name] = [MEMBER_FLAGS.Method];
149
+ });
150
+ return runtimeMembers;
151
+ };
152
+ const formatHostListeners = (compilerMeta) => {
153
+ return compilerMeta.listeners.map((compilerListener) => {
154
+ return [
155
+ computeListenerFlags(compilerListener),
156
+ compilerListener.name,
157
+ compilerListener.method
158
+ ];
159
+ });
160
+ };
161
+ const computeListenerFlags = (listener) => {
162
+ let flags = 0;
163
+ if (listener.capture) flags |= LISTENER_FLAGS.Capture;
164
+ if (listener.passive) flags |= LISTENER_FLAGS.Passive;
165
+ switch (listener.target) {
166
+ case "document":
167
+ flags |= LISTENER_FLAGS.TargetDocument;
168
+ break;
169
+ case "window":
170
+ flags |= LISTENER_FLAGS.TargetWindow;
171
+ break;
172
+ case "body": flags |= LISTENER_FLAGS.TargetBody;
173
+ }
174
+ return flags;
175
+ };
176
+ const trimFalsy = (data) => {
177
+ const arr = data;
178
+ for (let i = arr.length - 1; i >= 0; i--) {
179
+ if (arr[i]) break;
180
+ arr.pop();
181
+ }
182
+ return arr;
183
+ };
184
+ //#endregion
185
+ //#region src/utils/is-root-path.ts
186
+ /**
187
+ * Checks if the path is the Operating System (OS) root path, such as "/" or "C:\". This function does not take the OS
188
+ * the code is running on into account when performing this evaluation.
189
+ * @param p the path to check
190
+ * @returns `true` if the path is an OS root path, `false` otherwise
191
+ */
192
+ const isRootPath = (p) => p === "/" || windowsPathRegex.test(p);
193
+ const windowsPathRegex = /^(?:[a-zA-Z]:|[\\/]{2}[^\\/]+[\\/]+[^\\/]+)?[\\/]$/;
194
+ //#endregion
195
+ //#region src/utils/logger/logger-utils.ts
196
+ /**
197
+ * Iterate through a series of diagnostics to provide minor fix-ups for various edge cases, deduplicate messages, etc.
198
+ * @param compilerCtx the current compiler context
199
+ * @param diagnostics the diagnostics to normalize
200
+ * @returns the normalize documents
201
+ */
202
+ const normalizeDiagnostics = (compilerCtx, diagnostics) => {
203
+ const maxErrorsToNormalize = 25;
204
+ const normalizedErrors = [];
205
+ const normalizedOthers = [];
206
+ const dups = /* @__PURE__ */ new Set();
207
+ for (let i = 0; i < diagnostics.length; i++) {
208
+ const diagnostic = normalizeDiagnostic(compilerCtx, diagnostics[i]);
209
+ const key = (diagnostic.absFilePath ?? "") + (diagnostic.code ?? "") + diagnostic.messageText + diagnostic.type;
210
+ if (dups.has(key)) continue;
211
+ dups.add(key);
212
+ const total = normalizedErrors.length + normalizedOthers.length;
213
+ if (diagnostic.level === "error") normalizedErrors.push(diagnostic);
214
+ else if (total < maxErrorsToNormalize) normalizedOthers.push(diagnostic);
215
+ }
216
+ return [...normalizedErrors, ...normalizedOthers];
217
+ };
218
+ /**
219
+ * Perform post-processing on a `Diagnostic` to handle a few message edge cases, massaging error message text and
220
+ * updating build failure contexts
221
+ * @param compilerCtx the current compiler
222
+ * @param diagnostic the diagnostic to normalize
223
+ * @returns the altered diagnostic
224
+ */
225
+ const normalizeDiagnostic = (compilerCtx, diagnostic) => {
226
+ if (diagnostic.messageText) {
227
+ if (typeof diagnostic.messageText.message === "string") diagnostic.messageText = diagnostic.messageText.message;
228
+ else if (typeof diagnostic.messageText === "string" && diagnostic.messageText.indexOf("Error: ") === 0) diagnostic.messageText = diagnostic.messageText.slice(7);
229
+ }
230
+ if (diagnostic.messageText) {
231
+ if (diagnostic.messageText.includes(`Cannot find name 'h'`)) {
232
+ diagnostic.header = `Missing "h" import for JSX types`;
233
+ diagnostic.messageText = `In order to load accurate JSX types for components, the "h" function must be imported from "@stencil/core" by each component using JSX. For example: import { Component, h } from '@stencil/core';`;
234
+ if (diagnostic.absFilePath) try {
235
+ const sourceText = compilerCtx.fs.readFileSync(diagnostic.absFilePath);
236
+ const srcLines = splitLineBreaks(sourceText);
237
+ for (let i = 0; i < srcLines.length; i++) {
238
+ const srcLine = srcLines[i];
239
+ if (srcLine.includes("@stencil/core")) {
240
+ const msgLines = [];
241
+ const beforeLineIndex = i - 1;
242
+ if (beforeLineIndex > -1) {
243
+ const beforeLine = {
244
+ lineIndex: beforeLineIndex,
245
+ lineNumber: beforeLineIndex + 1,
246
+ text: srcLines[beforeLineIndex],
247
+ errorCharStart: -1,
248
+ errorLength: -1
249
+ };
250
+ msgLines.push(beforeLine);
251
+ }
252
+ const errorLine = {
253
+ lineIndex: i,
254
+ lineNumber: i + 1,
255
+ text: srcLine,
256
+ errorCharStart: 0,
257
+ errorLength: -1
258
+ };
259
+ msgLines.push(errorLine);
260
+ diagnostic.lineNumber = errorLine.lineNumber;
261
+ diagnostic.columnNumber = srcLine.indexOf("}");
262
+ const afterLineIndex = i + 1;
263
+ if (afterLineIndex < srcLines.length) {
264
+ const afterLine = {
265
+ lineIndex: afterLineIndex,
266
+ lineNumber: afterLineIndex + 1,
267
+ text: srcLines[afterLineIndex],
268
+ errorCharStart: -1,
269
+ errorLength: -1
270
+ };
271
+ msgLines.push(afterLine);
272
+ }
273
+ diagnostic.lines = msgLines;
274
+ break;
275
+ }
276
+ }
277
+ } catch {}
278
+ }
279
+ }
280
+ return diagnostic;
281
+ };
282
+ /**
283
+ * Split a corpus by newlines. Carriage returns are treated a newlines.
284
+ * @param sourceText the corpus to split
285
+ * @returns the split text
286
+ */
287
+ const splitLineBreaks = (sourceText) => {
288
+ if (typeof sourceText !== "string") return [];
289
+ sourceText = sourceText.replace(/\\r/g, "\n");
290
+ return sourceText.split("\n");
291
+ };
292
+ const escapeHtml = (unsafe) => {
293
+ if (unsafe === void 0) return "undefined";
294
+ if (unsafe === null) return "null";
295
+ if (typeof unsafe !== "string") unsafe = unsafe.toString();
296
+ return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
297
+ };
298
+ //#endregion
299
+ //#region src/utils/logger/logger-rolldown.ts
300
+ const isRolldownError = (e) => typeof e === "object" && e !== null && "message" in e;
301
+ const loadRolldownDiagnostics = (config, compilerCtx, buildCtx, rolldownError) => {
302
+ const formattedCode = formatErrorCode(rolldownError.code);
303
+ const diagnostic = {
304
+ level: "error",
305
+ type: "bundling",
306
+ language: "javascript",
307
+ code: rolldownError.code,
308
+ header: `Rolldown${formattedCode.length > 0 ? ": " + formattedCode : ""}`,
309
+ messageText: formattedCode,
310
+ relFilePath: void 0,
311
+ absFilePath: void 0,
312
+ lines: []
313
+ };
314
+ if (config.logLevel === "debug" && rolldownError.stack) diagnostic.messageText = rolldownError.stack;
315
+ else if (rolldownError.message) diagnostic.messageText = rolldownError.message;
316
+ if (rolldownError.plugin) diagnostic.messageText += ` (plugin: ${rolldownError.plugin}${rolldownError.hook ? `, ${rolldownError.hook}` : ""})`;
317
+ const loc = rolldownError.loc;
318
+ if (loc != null) {
319
+ const srcFile = loc.file || rolldownError.id;
320
+ if (isString(srcFile)) try {
321
+ const sourceText = compilerCtx.fs.readFileSync(srcFile);
322
+ if (sourceText) {
323
+ diagnostic.absFilePath = srcFile;
324
+ try {
325
+ const srcLines = splitLineBreaks(sourceText);
326
+ const errorLine = {
327
+ lineIndex: loc.line - 1,
328
+ lineNumber: loc.line,
329
+ text: srcLines[loc.line - 1],
330
+ errorCharStart: loc.column,
331
+ errorLength: 0
332
+ };
333
+ diagnostic.lineNumber = errorLine.lineNumber;
334
+ diagnostic.columnNumber = errorLine.errorCharStart;
335
+ const highlightLine = errorLine.text?.slice(loc.column) ?? "";
336
+ for (let i = 0; i < highlightLine.length; i++) {
337
+ if (charBreak.has(highlightLine.charAt(i))) break;
338
+ errorLine.errorLength++;
339
+ }
340
+ diagnostic.lines.push(errorLine);
341
+ if (errorLine.errorLength === 0 && errorLine.errorCharStart > 0) {
342
+ errorLine.errorLength = 1;
343
+ errorLine.errorCharStart--;
344
+ }
345
+ if (errorLine.lineIndex > 0) {
346
+ const previousLine = {
347
+ lineIndex: errorLine.lineIndex - 1,
348
+ lineNumber: errorLine.lineNumber - 1,
349
+ text: srcLines[errorLine.lineIndex - 1],
350
+ errorCharStart: -1,
351
+ errorLength: -1
352
+ };
353
+ diagnostic.lines.unshift(previousLine);
354
+ }
355
+ if (errorLine.lineIndex + 1 < srcLines.length) {
356
+ const nextLine = {
357
+ lineIndex: errorLine.lineIndex + 1,
358
+ lineNumber: errorLine.lineNumber + 1,
359
+ text: srcLines[errorLine.lineIndex + 1],
360
+ errorCharStart: -1,
361
+ errorLength: -1
362
+ };
363
+ diagnostic.lines.push(nextLine);
364
+ }
365
+ } catch {
366
+ diagnostic.messageText += `\nError parsing: ${diagnostic.absFilePath}, line: ${loc.line}, column: ${loc.column}`;
367
+ diagnostic.debugText = sourceText;
368
+ }
369
+ } else if (typeof rolldownError.frame === "string") diagnostic.messageText += "\n" + rolldownError.frame;
370
+ } catch {}
371
+ }
372
+ buildCtx.diagnostics.push(diagnostic);
373
+ };
374
+ const createOnWarnFn = (diagnostics, bundleModulesFiles) => {
375
+ const previousWarns = /* @__PURE__ */ new Set();
376
+ return function onWarningMessage(warning) {
377
+ if (warning == null || warning.code && ignoreWarnCodes.has(warning.code) || warning.message && previousWarns.has(warning.message)) return;
378
+ if (warning.message) previousWarns.add(warning.message);
379
+ let label = "";
380
+ if (bundleModulesFiles) {
381
+ label = bundleModulesFiles.reduce((cmps, m) => {
382
+ cmps.push(...m.cmps);
383
+ return cmps;
384
+ }, []).join(", ").trim();
385
+ if (label.length) label += ": ";
386
+ }
387
+ const diagnostic = buildWarn(diagnostics);
388
+ diagnostic.header = `Bundling Warning ${warning.code}`;
389
+ diagnostic.messageText = label + (warning.message || warning);
390
+ };
391
+ };
392
+ const ignoreWarnCodes = /* @__PURE__ */ new Set([
393
+ "THIS_IS_UNDEFINED",
394
+ "NON_EXISTENT_EXPORT",
395
+ "CIRCULAR_DEPENDENCY",
396
+ "EMPTY_BUNDLE",
397
+ "UNUSED_EXTERNAL_IMPORT",
398
+ "EMPTY_IMPORT_META"
399
+ ]);
400
+ const charBreak = /* @__PURE__ */ new Set([
401
+ " ",
402
+ "=",
403
+ ".",
404
+ ",",
405
+ "?",
406
+ ":",
407
+ ";",
408
+ "(",
409
+ ")",
410
+ "{",
411
+ "}",
412
+ "[",
413
+ "]",
414
+ "|",
415
+ `'`,
416
+ `"`,
417
+ "`"
418
+ ]);
419
+ const formatErrorCode = (errorCode) => {
420
+ if (typeof errorCode === "string") return errorCode.split("_").map((c) => {
421
+ return toTitleCase(c.toLowerCase());
422
+ }).join(" ");
423
+ return (errorCode || "").trim();
424
+ };
425
+ //#endregion
426
+ //#region src/utils/logger/logger-typescript.ts
427
+ /**
428
+ * Augment a `Diagnostic` with information from a `Node` in the AST to provide richer error information
429
+ * @param d the diagnostic to augment
430
+ * @param node the node to augment with additional information
431
+ * @returns the augmented diagnostic
432
+ */
433
+ const augmentDiagnosticWithNode = (d, node) => {
434
+ if (!node) return d;
435
+ const sourceFile = node.getSourceFile();
436
+ if (!sourceFile) return d;
437
+ d.absFilePath = normalizePath(sourceFile.fileName);
438
+ const sourceText = sourceFile.text;
439
+ const srcLines = splitLineBreaks(sourceText);
440
+ const start = node.getStart();
441
+ const end = node.getEnd();
442
+ const posStart = sourceFile.getLineAndCharacterOfPosition(start);
443
+ const errorLine = {
444
+ lineIndex: posStart.line,
445
+ lineNumber: posStart.line + 1,
446
+ text: srcLines[posStart.line],
447
+ errorCharStart: posStart.character,
448
+ errorLength: Math.max(end - start, 1)
449
+ };
450
+ d.lineNumber = errorLine.lineNumber;
451
+ d.columnNumber = errorLine.errorCharStart + 1;
452
+ d.lines.push(errorLine);
453
+ if (errorLine.errorLength === 0 && errorLine.errorCharStart > 0) {
454
+ errorLine.errorLength = 1;
455
+ errorLine.errorCharStart--;
456
+ }
457
+ if (errorLine.lineIndex > 0) {
458
+ const previousLine = {
459
+ lineIndex: errorLine.lineIndex - 1,
460
+ lineNumber: errorLine.lineNumber - 1,
461
+ text: srcLines[errorLine.lineIndex - 1],
462
+ errorCharStart: -1,
463
+ errorLength: -1
464
+ };
465
+ d.lines.unshift(previousLine);
466
+ }
467
+ if (errorLine.lineIndex + 1 < srcLines.length) {
468
+ const nextLine = {
469
+ lineIndex: errorLine.lineIndex + 1,
470
+ lineNumber: errorLine.lineNumber + 1,
471
+ text: srcLines[errorLine.lineIndex + 1],
472
+ errorCharStart: -1,
473
+ errorLength: -1
474
+ };
475
+ d.lines.push(nextLine);
476
+ }
477
+ return d;
478
+ };
479
+ /**
480
+ * Ok, so formatting overkill, we know. But whatever, it makes for great
481
+ * error reporting within a terminal. So, yeah, let's code it up, shall we?
482
+ */
483
+ /**
484
+ * Convert an array of TypeScript diagnostics to Stencil diagnostic format.
485
+ *
486
+ * @param tsDiagnostics - array of TypeScript diagnostic objects
487
+ * @returns array of Stencil diagnostic objects
488
+ */
489
+ const loadTypeScriptDiagnostics = (tsDiagnostics) => {
490
+ const diagnostics = [];
491
+ const maxErrors = Math.min(tsDiagnostics.length, 50);
492
+ for (let i = 0; i < maxErrors; i++) diagnostics.push(loadTypeScriptDiagnostic(tsDiagnostics[i]));
493
+ return diagnostics;
494
+ };
495
+ /**
496
+ * Convert a TypeScript diagnostic object into our internal, Stencil-specific
497
+ * diagnostic format
498
+ *
499
+ * @param tsDiagnostic a TypeScript diagnostic message record
500
+ * @returns a Stencil diagnostic, suitable for showing an error to the user
501
+ */
502
+ const loadTypeScriptDiagnostic = (tsDiagnostic) => {
503
+ const d = {
504
+ absFilePath: void 0,
505
+ code: tsDiagnostic.code.toString(),
506
+ columnNumber: void 0,
507
+ header: "TypeScript",
508
+ language: "typescript",
509
+ level: "warn",
510
+ lineNumber: void 0,
511
+ lines: [],
512
+ messageText: flattenDiagnosticMessageText(tsDiagnostic, tsDiagnostic.messageText),
513
+ relFilePath: void 0,
514
+ type: "typescript"
515
+ };
516
+ if (tsDiagnostic.category === 1) d.level = "error";
517
+ if (tsDiagnostic.file && typeof tsDiagnostic.start === "number") {
518
+ d.absFilePath = tsDiagnostic.file.fileName;
519
+ const sourceText = tsDiagnostic.file.text;
520
+ const srcLines = splitLineBreaks(sourceText);
521
+ const posData = tsDiagnostic.file.getLineAndCharacterOfPosition(tsDiagnostic.start);
522
+ const errorLine = {
523
+ lineIndex: posData.line,
524
+ lineNumber: posData.line + 1,
525
+ text: srcLines[posData.line],
526
+ errorCharStart: posData.character,
527
+ errorLength: Math.max(tsDiagnostic.length ?? 0, 1)
528
+ };
529
+ d.lineNumber = errorLine.lineNumber;
530
+ d.columnNumber = errorLine.errorCharStart + 1;
531
+ d.lines.push(errorLine);
532
+ if (errorLine.errorLength === 0 && errorLine.errorCharStart > 0) {
533
+ errorLine.errorLength = 1;
534
+ errorLine.errorCharStart--;
535
+ }
536
+ if (errorLine.lineIndex > 0) {
537
+ const previousLine = {
538
+ lineIndex: errorLine.lineIndex - 1,
539
+ lineNumber: errorLine.lineNumber - 1,
540
+ text: srcLines[errorLine.lineIndex - 1],
541
+ errorCharStart: -1,
542
+ errorLength: -1
543
+ };
544
+ d.lines.unshift(previousLine);
545
+ }
546
+ if (errorLine.lineIndex + 1 < srcLines.length) {
547
+ const nextLine = {
548
+ lineIndex: errorLine.lineIndex + 1,
549
+ lineNumber: errorLine.lineNumber + 1,
550
+ text: srcLines[errorLine.lineIndex + 1],
551
+ errorCharStart: -1,
552
+ errorLength: -1
553
+ };
554
+ d.lines.push(nextLine);
555
+ }
556
+ }
557
+ return d;
558
+ };
559
+ /**
560
+ * Flatten a TypeScript diagnostic object into a string which can be easily
561
+ * included in a Stencil diagnostic record.
562
+ *
563
+ * @param tsDiagnostic a TypeScript diagnostic record
564
+ * @param diag a {@link DiagnosticMessageChain} or a string with further info
565
+ * @returns a string with the relevant error message
566
+ */
567
+ const flattenDiagnosticMessageText = (tsDiagnostic, diag) => {
568
+ if (typeof diag === "string") return diag;
569
+ else if (diag === void 0) return "";
570
+ const ignoreCodes = [];
571
+ const isStencilConfig = (tsDiagnostic.file?.fileName ?? "").includes("stencil.config");
572
+ if (isStencilConfig) ignoreCodes.push(2322);
573
+ let result = "";
574
+ if (!ignoreCodes.includes(diag.code)) {
575
+ result = diag.messageText;
576
+ if (isIterable(diag.next)) for (const kid of diag.next) result += flattenDiagnosticMessageText(tsDiagnostic, kid);
577
+ }
578
+ if (isStencilConfig) {
579
+ result = result.replace(`type 'StencilConfig'`, `Stencil Config`);
580
+ result = result.replace(`Object literal may only specify known properties, but `, ``);
581
+ result = result.replace(`Object literal may only specify known properties, and `, ``);
582
+ }
583
+ return result.trim();
584
+ };
585
+ //#endregion
586
+ //#region src/utils/result.ts
587
+ var result_exports = /* @__PURE__ */ __exportAll({
588
+ err: () => err,
589
+ map: () => map,
590
+ ok: () => ok,
591
+ unwrap: () => unwrap,
592
+ unwrapErr: () => unwrapErr
593
+ });
594
+ /**
595
+ * Create an `Ok` given a value. This doesn't do any checking that the value is
596
+ * 'ok-ish' since doing so would make an undue assumption about what is 'ok'.
597
+ * Instead, this trusts the user to determine, at the call site, whether
598
+ * something is `ok()` or `err()`.
599
+ *
600
+ * @param value the value to wrap up in an `Ok`
601
+ * @returns an Ok wrapping the value
602
+ */
603
+ const ok = (value) => ({
604
+ isOk: true,
605
+ isErr: false,
606
+ value
607
+ });
608
+ /**
609
+ * Create an `Err` given a value.
610
+ *
611
+ * @param value the value to wrap up in an `Err`
612
+ * @returns an Ok wrapping the value
613
+ */
614
+ const err = (value) => ({
615
+ isOk: false,
616
+ isErr: true,
617
+ value
618
+ });
619
+ function map(result, fn) {
620
+ if (result.isOk) {
621
+ const val = fn(result.value);
622
+ if (val instanceof Promise) return val.then((newVal) => ok(newVal));
623
+ else return ok(val);
624
+ }
625
+ if (result.isErr) {
626
+ const value = result.value;
627
+ return err(value);
628
+ }
629
+ throw "should never get here";
630
+ }
631
+ /**
632
+ * Unwrap a {@link Result}, return the value inside if it is an `Ok` and
633
+ * throw with the wrapped value if it is an `Err`.
634
+ *
635
+ * @throws with the wrapped value if it is an `Err`.
636
+ * @param result a result to peer inside of
637
+ * @returns the wrapped value, if `Ok`
638
+ */
639
+ const unwrap = (result) => {
640
+ if (result.isOk) return result.value;
641
+ else throw result.value;
642
+ };
643
+ /**
644
+ * Unwrap a {@link Result}, return the value inside if it is an `Err` and
645
+ * throw with the wrapped value if it is an `Ok`.
646
+ *
647
+ * @throws with the wrapped value if it is an `Ok`.
648
+ * @param result a result to peer inside of
649
+ * @returns the wrapped value, if `Err`
650
+ */
651
+ const unwrapErr = (result) => {
652
+ if (result.isErr) return result.value;
653
+ else throw result.value;
654
+ };
655
+ //#endregion
656
+ //#region src/utils/sourcemaps.ts
657
+ function rolldownToStencilSourceMap(rolldownSourceMap) {
658
+ if (!rolldownSourceMap || !rolldownSourceMap.file) return null;
659
+ return {
660
+ file: rolldownSourceMap.file,
661
+ mappings: rolldownSourceMap.mappings,
662
+ names: rolldownSourceMap.names,
663
+ sources: rolldownSourceMap.sources,
664
+ sourcesContent: rolldownSourceMap.sourcesContent,
665
+ version: rolldownSourceMap.version
666
+ };
667
+ }
668
+ /**
669
+ * A JavaScript formatted string used to link generated code back to the original. This string follows the guidelines
670
+ * found in the [Linking generated code to source maps](https://sourcemaps.info/spec.html#h.lmz475t4mvbx) section of
671
+ * the Sourcemaps V3 specification proposal.
672
+ */
673
+ const JS_SOURCE_MAPPING_URL_LINKER = "//# sourceMappingURL=";
674
+ /**
675
+ * Generates an RFC-3986 compliant string for the given input.
676
+ * More information about RFC-3986 can be found [here](https://datatracker.ietf.org/doc/html/rfc3986)
677
+ * This function's original source is derived from
678
+ * [MDN's encodeURIComponent documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#description)
679
+ * @param filename the filename to encode
680
+ * @returns the encoded URI
681
+ */
682
+ const encodeToRfc3986 = (filename) => {
683
+ return encodeURIComponent(filename).replace(/[!'()*]/g, (matchedCharacter) => {
684
+ return "%" + matchedCharacter.charCodeAt(0).toString(16);
685
+ });
686
+ };
687
+ /**
688
+ * Generates a string used to link generated code with the original source, to be placed at the end of the generated
689
+ * code.
690
+ * @param url the url of the source map
691
+ * @returns a linker string, of the format {@link JS_SOURCE_MAPPING_URL_LINKER}=<url>
692
+ */
693
+ const getSourceMappingUrlLinker = (url) => {
694
+ return `${JS_SOURCE_MAPPING_URL_LINKER}${encodeToRfc3986(url)}`;
695
+ };
696
+ /**
697
+ * Generates a string used to link generated code with the original source, to be placed at the end of the generated
698
+ * code as an inline source map.
699
+ * @param sourceMapContents the sourceMapContents of the source map
700
+ * @returns a linker string, of the format {@link JS_SOURCE_MAPPING_URL_LINKER}<dataUriPrefixAndMime><sourceMapContents>
701
+ */
702
+ const getInlineSourceMappingUrlLinker = (sourceMapContents) => {
703
+ const mapBase64 = Buffer.from(sourceMapContents, "utf8").toString("base64");
704
+ return `${JS_SOURCE_MAPPING_URL_LINKER}data:application/json;charset=utf-8;base64,${mapBase64}`;
705
+ };
706
+ /**
707
+ * Generates a string used to link generated code with the original source, to be placed at the end of the generated
708
+ * code. This function prepends a newline to the string.
709
+ * @param url the url of the source map
710
+ * @returns a linker string, of the format {@link JS_SOURCE_MAPPING_URL_LINKER}=<url>.map, prepended with a newline
711
+ */
712
+ const getSourceMappingUrlForEndOfFile = (url) => {
713
+ return `\n${getSourceMappingUrlLinker(url)}.map`;
714
+ };
715
+ //#endregion
716
+ //#region src/utils/url-paths.ts
717
+ /**
718
+ * Determines whether a string should be considered a remote url or not.
719
+ *
720
+ * This helper only checks the provided string to evaluate is one of a few pre-defined schemes, and should not be
721
+ * considered all-encompassing
722
+ *
723
+ * @param p the string to evaluate
724
+ * @returns `true` if the provided string is a remote url, `false` otherwise
725
+ */
726
+ const isRemoteUrl = (p) => {
727
+ if (isString(p)) {
728
+ p = p.toLowerCase();
729
+ return p.startsWith("https://") || p.startsWith("http://");
730
+ }
731
+ return false;
732
+ };
733
+ //#endregion
734
+ //#region src/utils/validation.ts
735
+ const getModeKeys = (value) => {
736
+ if (value == null || typeof value !== "object" || Array.isArray(value) || value.__identifier) return [];
737
+ return Object.keys(value);
738
+ };
739
+ /**
740
+ * Validates the mode keys used in a component's `styleUrls`/`styles` against a
741
+ * `config.modes` allowlist, if one is declared.
742
+ * @param configModes the `config.modes` allowlist (mixed string/{@link d.ModeConfig} entries)
743
+ * @param componentOptions the `@Component()` decorator options for a single component
744
+ * @returns a validation error if a used mode is unknown or a required mode is missing, undefined otherwise
745
+ */
746
+ const validateComponentModes = (configModes, componentOptions) => {
747
+ if (!configModes || configModes.length === 0) return;
748
+ const allowedModes = /* @__PURE__ */ new Map();
749
+ for (const entry of configModes) if (typeof entry === "string") allowedModes.set(entry, false);
750
+ else allowedModes.set(entry.mode, !!entry.required);
751
+ const fields = [{
752
+ propName: "styleUrls",
753
+ keys: getModeKeys(componentOptions.styleUrls)
754
+ }, {
755
+ propName: "styles",
756
+ keys: getModeKeys(componentOptions.styles)
757
+ }];
758
+ for (const field of fields) for (const key of field.keys) if (!allowedModes.has(key)) return {
759
+ propName: field.propName,
760
+ message: `Invalid mode "${key}" in "${field.propName}". Valid modes are: ${[...allowedModes.keys()].join(", ")}.`
761
+ };
762
+ const usedModes = /* @__PURE__ */ new Set([...fields[0].keys, ...fields[1].keys]);
763
+ if (usedModes.size > 0) {
764
+ const missingRequired = [...allowedModes.entries()].filter(([mode, required]) => required && !usedModes.has(mode)).map(([mode]) => mode);
765
+ if (missingRequired.length > 0) return {
766
+ propName: fields[0].keys.length > 0 ? "styleUrls" : "styles",
767
+ message: `Missing required mode${missingRequired.length > 1 ? "s" : ""}: ${missingRequired.join(", ")}.`
768
+ };
769
+ }
770
+ };
771
+ /**
772
+ * Validates that a component tag meets required naming conventions to be used for a web component
773
+ * @param tag the tag to validate
774
+ * @returns an error message if the tag has an invalid name, undefined if the tag name passes all checks
775
+ */
776
+ const validateComponentTag = (tag) => {
777
+ if (typeof tag !== "string") return `Tag "${tag}" must be a string type`;
778
+ if (tag !== tag.trim()) return `Tag can not contain white spaces`;
779
+ if (tag !== tag.toLowerCase()) return `Tag can not contain upper case characters`;
780
+ if (tag.length === 0) return `Received empty tag value`;
781
+ if (tag.indexOf(" ") > -1) return `"${tag}" tag cannot contain a space`;
782
+ if (tag.indexOf(",") > -1) return `"${tag}" tag cannot be used for multiple tags`;
783
+ const invalidChars = tag.replace(/\w|-/g, "");
784
+ if (invalidChars !== "") return `"${tag}" tag contains invalid characters: ${invalidChars}`;
785
+ if (tag.indexOf("-") === -1) return `"${tag}" tag must contain a dash (-) to work as a valid web component`;
786
+ if (tag.indexOf("--") > -1) return `"${tag}" tag cannot contain multiple dashes (--) next to each other`;
787
+ if (tag.indexOf("-") === 0) return `"${tag}" tag cannot start with a dash (-)`;
788
+ if (tag.lastIndexOf("-") === tag.length - 1) return `"${tag}" tag cannot end with a dash (-)`;
789
+ };
790
+ //#endregion
791
+ export { formatLazyBundleRuntimeMeta as C, escapeRegExpSpecialCharacters as E, formatComponentRuntimeMeta as S, byteSize as T, loadRolldownDiagnostics as _, getSourceMappingUrlForEndOfFile as a, splitLineBreaks as b, err as c, result_exports as d, augmentDiagnosticWithNode as f, isRolldownError as g, createOnWarnFn as h, getInlineSourceMappingUrlLinker as i, map as l, loadTypeScriptDiagnostics as m, validateComponentTag as n, getSourceMappingUrlLinker as o, loadTypeScriptDiagnostic as p, isRemoteUrl as r, rolldownToStencilSourceMap as s, validateComponentModes as t, ok as u, escapeHtml as v, stringifyRuntimeData as w, isRootPath as x, normalizeDiagnostics as y };