@stencil/core 5.0.0-alpha.8 → 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 (50) hide show
  1. package/README.md +94 -0
  2. package/dist/app-data/index.d.ts +2 -0
  3. package/dist/{runtime/app-data → app-data}/index.js +5 -2
  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-B3pUYg_P.mjs → compiler-NrvbUOX1.mjs} +2904 -1269
  10. package/dist/declarations/stencil-ext-modules.d.ts +5 -5
  11. package/dist/declarations/stencil-public-compiler.d.ts +208 -62
  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-BuveMLxy.d.ts → index-DnISpqrd.d.ts} +150 -10
  18. package/dist/{index-CVhWFUM0.d.mts → index-RrQfiPWK.d.mts} +490 -841
  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-10UamZmn.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 +483 -347
  25. package/dist/runtime/client/runtime.d.ts +150 -39
  26. package/dist/runtime/client/runtime.js +483 -347
  27. package/dist/runtime/index.d.ts +6 -32
  28. package/dist/runtime/index.js +482 -345
  29. package/dist/runtime/server/index.d.mts +81 -9
  30. package/dist/runtime/server/index.mjs +419 -193
  31. package/dist/runtime/server/runner.d.mts +3 -0
  32. package/dist/runtime/server/runner.mjs +321 -338
  33. package/dist/signals/index.d.ts +2 -0
  34. package/dist/signals/index.js +5 -2
  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 +7744 -791
  41. package/dist/util-IKfWWLJo.mjs +724 -0
  42. package/dist/validation-DAdGTrys.mjs +791 -0
  43. package/package.json +33 -33
  44. package/dist/client-Dd-NB5Ei.mjs +0 -4833
  45. package/dist/index-ch-cf-bZ.d.mts +0 -205
  46. package/dist/runtime/app-data/index.d.ts +0 -2
  47. package/dist/validation-ByxKj8bC.mjs +0 -1458
  48. /package/{LICENSE.md → LICENSE} +0 -0
  49. /package/dist/{runtime/app-globals → app-globals}/index.d.ts +0 -0
  50. /package/dist/{runtime/app-globals → app-globals}/index.js +0 -0
@@ -1,5 +1,5 @@
1
- import { BUILD } from "./app-data/index.js";
2
- import "./app-globals/index.js";
1
+ import { BUILD } from "../app-data/index.js";
2
+ import "../app-globals/index.js";
3
3
  import { effect, effect as effect$1, signal } from "@preact/signals-core";
4
4
  //#region src/client/client-build.ts
5
5
  const Build = {
@@ -50,8 +50,20 @@ const HOST_FLAGS = {
50
50
  isWatchReady: 128,
51
51
  isListenReady: 256,
52
52
  needsRerender: 512,
53
- devOnRender: 1024,
54
- devOnDidLoad: 2048
53
+ /**
54
+ * Set once this component's real (lazy-loaded) `connectedCallback` has fired for
55
+ * the first time. Lets a descendant skip creating/awaiting a connect-promise for
56
+ * an ancestor that's already connected. See {@link HostRef.$onFirstConnectResolve$}.
57
+ */
58
+ hasFiredConnected: 1024,
59
+ /**
60
+ * Set when a lazy component's dynamic `import()` fails to resolve a
61
+ * constructor. Distinct from `hasInitializedComponent` being unset, which
62
+ * is true while an initialization attempt is merely queued/in-flight.
63
+ */
64
+ hasFailedLoad: 2048,
65
+ devOnRender: 4096,
66
+ devOnDidLoad: 8192
55
67
  };
56
68
  const CF_scopedCssEncapsulation = 2;
57
69
  /**
@@ -136,7 +148,17 @@ const CMP_FLAGS = {
136
148
  * e.g. `encapsulation: { type: 'none', patches: ['all'] }`
137
149
  * Equivalent to the global `experimentalSlotFixes` config option.
138
150
  */
139
- patchAll: 32768
151
+ patchAll: 32768,
152
+ /**
153
+ * Determines if `clonable` is enabled for a component that uses the shadow DOM.
154
+ * e.g. `encapsulation: { type: 'shadow', clonable: true }` is set on the `@Component()` decorator
155
+ */
156
+ shadowClonable: 65536,
157
+ /**
158
+ * Determines if `serializable` is enabled for a component that uses the shadow DOM.
159
+ * e.g. `encapsulation: { type: 'shadow', serializable: true }` is set on the `@Component()` decorator
160
+ */
161
+ shadowSerializable: 1 << 17
140
162
  };
141
163
  /**
142
164
  * Namespaces
@@ -270,8 +292,13 @@ const registerHost = (hostElement, cmpMeta) => {
270
292
  if (BUILD.asyncLoading) {
271
293
  hostRef.$onReadyPromise$ = new Promise((r) => hostRef.$onReadyResolve$ = r);
272
294
  hostElement["s-rp"] = hostRef.$onReadyPromise$;
295
+ if (!BUILD.lazyLoad) {
296
+ hostRef.$onFirstConnectPromise$ = new Promise((r) => hostRef.$onFirstConnectResolve$ = r);
297
+ hostElement["s-fc"] = hostRef.$onFirstConnectPromise$;
298
+ }
273
299
  if (!hostElement["s-p"]) hostElement["s-p"] = [];
274
300
  if (!hostElement["s-rc"]) hostElement["s-rc"] = [];
301
+ if (!hostElement["s-pc"]) hostElement["s-pc"] = [];
275
302
  }
276
303
  if (BUILD.lazyLoad) hostRef.$fetchedCbList$ = [];
277
304
  const ref = hostRef;
@@ -286,7 +313,12 @@ const consoleDevError = (...m) => console.error(...STENCIL_DEV_MODE, ...m);
286
313
  const consoleDevWarn = (...m) => console.warn(...STENCIL_DEV_MODE, ...m);
287
314
  //#endregion
288
315
  //#region src/client/client-load-module.ts
289
- const cmpModules = /* @__PURE__ */ new Map();
316
+ const cmpModules = /*@__PURE__*/ new Map();
317
+ /**
318
+ * Tracks how many times a dynamic `import()` for a given lazy bundle has failed.
319
+ * Used to cache bust the retry attempt in connected-callback.ts
320
+ */
321
+ const failedLoadAttempts = /*@__PURE__*/ new Map();
290
322
  /**
291
323
  * We need to separate out this prefix so that Esbuild doesn't try to resolve
292
324
  * the below, but instead retains a dynamic `import()` statement in the
@@ -313,13 +345,21 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
313
345
  } else if (!bundleId) return;
314
346
  const module = !BUILD.hotModuleReplacement ? cmpModules.get(bundleId) : false;
315
347
  if (module) return module[exportName];
348
+ const retryCount = failedLoadAttempts.get(bundleId) ?? 0;
349
+ const cacheBustParams = [retryCount > 0 ? `s-retry=${retryCount}` : "", BUILD.hotModuleReplacement && hmrVersionId ? `s-hmr=${hmrVersionId}` : ""].filter(Boolean).join("&");
316
350
  /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
317
- const entryFile = `${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVersionId ? "?s-hmr=" + hmrVersionId : ""}`;
351
+ const entryFile = `${bundleId}.entry.js${cacheBustParams ? "?" + cacheBustParams : ""}`;
318
352
  const onLoad = (importedModule) => {
319
- if (!BUILD.hotModuleReplacement) cmpModules.set(bundleId, importedModule);
353
+ if (!BUILD.hotModuleReplacement) {
354
+ failedLoadAttempts.delete(bundleId);
355
+ cmpModules.set(bundleId, importedModule);
356
+ }
320
357
  return importedModule[exportName];
321
358
  };
322
- const onError = (e) => consoleError(e, hostRef.$hostElement$);
359
+ const onError = (e) => {
360
+ failedLoadAttempts.set(bundleId, retryCount + 1);
361
+ consoleError(e, hostRef.$hostElement$);
362
+ };
323
363
  return import(
324
364
  /* @vite-ignore */
325
365
  /* webpackInclude: /\.entry\.js$/ */
@@ -330,7 +370,7 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
330
370
  };
331
371
  //#endregion
332
372
  //#region src/client/client-style.ts
333
- const styles = /* @__PURE__ */ new Map();
373
+ const styles = /*@__PURE__*/ new Map();
334
374
  const modeResolutionChain = [];
335
375
  const needsScopedSSR = () => false;
336
376
  //#endregion
@@ -384,12 +424,6 @@ const HYDRATE_ID = "s-id";
384
424
  const HYDRATED_STYLE_ID = "sty-id";
385
425
  const HYDRATE_CHILD_ID = "c-id";
386
426
  const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
387
- const STENCIL_DOC_DATA = "_stencilDocData";
388
- const DEFAULT_DOC_DATA = {
389
- hostIds: 0,
390
- rootLevelIds: 0,
391
- staticComponents: /* @__PURE__ */ new Set()
392
- };
393
427
  /**
394
428
  * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
395
429
  *
@@ -398,6 +432,10 @@ const DEFAULT_DOC_DATA = {
398
432
  */
399
433
  const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
400
434
  const XLINK_NS = "http://www.w3.org/1999/xlink";
435
+ /**
436
+ * Minimum delay, in milliseconds, before retrying a failed lazy component load.
437
+ */
438
+ const LAZY_LOAD_RETRY_INTERVAL_MS = 1e3;
401
439
  const FORM_ASSOCIATED_CUSTOM_ELEMENT_CALLBACKS = [
402
440
  "formAssociatedCallback",
403
441
  "formResetCallback",
@@ -417,7 +455,7 @@ const plt = {
417
455
  rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
418
456
  ce: (eventName, opts) => new CustomEvent(eventName, opts)
419
457
  };
420
- const supportsListenerOptions = /* @__PURE__ */ (() => {
458
+ const supportsListenerOptions = /*@__PURE__*/ (() => {
421
459
  let supported = false;
422
460
  try {
423
461
  win.document?.addEventListener("e", null, Object.defineProperty({}, "passive", { get() {
@@ -427,14 +465,14 @@ const supportsListenerOptions = /* @__PURE__ */ (() => {
427
465
  return supported;
428
466
  })();
429
467
  const promiseResolve = (v) => Promise.resolve(v);
430
- const supportsConstructableStylesheets = BUILD.constructableCSS ? /* @__PURE__ */ (() => {
468
+ const supportsConstructableStylesheets = BUILD.constructableCSS ? /*@__PURE__*/ (() => {
431
469
  try {
432
470
  if (!win.document.adoptedStyleSheets) return false;
433
471
  return typeof new CSSStyleSheet().replaceSync === "function";
434
472
  } catch {}
435
473
  return false;
436
474
  })() : false;
437
- const supportsMutableAdoptedStyleSheets = supportsConstructableStylesheets ? /* @__PURE__ */ (() => !!win.document && Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, "length").writable)() : false;
475
+ const supportsMutableAdoptedStyleSheets = supportsConstructableStylesheets ? /*@__PURE__*/ (() => !!win.document && Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, "length").writable)() : false;
438
476
  //#endregion
439
477
  //#region src/client/client-task-queue.ts
440
478
  let queueCongestion = 0;
@@ -442,12 +480,13 @@ let queuePending = false;
442
480
  const queueDomReads = [];
443
481
  const queueDomWrites = [];
444
482
  const queueDomWritesLow = [];
483
+ const scheduleFlush = () => win.document?.hidden ? nextTick(flush) : plt.raf(flush);
445
484
  const queueTask = (queue, write) => (cb) => {
446
485
  queue.push(cb);
447
486
  if (!queuePending) {
448
487
  queuePending = true;
449
488
  if (write && plt.$flags$ & PLATFORM_FLAGS.queueSync) nextTick(flush);
450
- else plt.raf(flush);
489
+ else scheduleFlush();
451
490
  }
452
491
  };
453
492
  const consume = (queue) => {
@@ -480,15 +519,15 @@ const flush = () => {
480
519
  queueDomWritesLow.push(...queueDomWrites);
481
520
  queueDomWrites.length = 0;
482
521
  }
483
- if (queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0) plt.raf(flush);
522
+ if (queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0) scheduleFlush();
484
523
  else queueCongestion = 0;
485
524
  } else {
486
525
  consume(queueDomWrites);
487
- if (queuePending = queueDomReads.length > 0) plt.raf(flush);
526
+ if (queuePending = queueDomReads.length > 0) scheduleFlush();
488
527
  }
489
528
  };
490
529
  const nextTick = (cb) => promiseResolve().then(cb);
491
- const writeTask = /* @__PURE__ */ queueTask(queueDomWrites, true);
530
+ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
492
531
  //#endregion
493
532
  //#region src/runtime/asset-path.ts
494
533
  const getAssetPath = (path) => {
@@ -524,11 +563,15 @@ function createShadowRoot(cmpMeta) {
524
563
  if (BUILD.shadowSlotAssignmentManual) {
525
564
  if (!!(cmpMeta.$flags$ & CMP_FLAGS.shadowSlotAssignmentManual)) opts.slotAssignment = "manual";
526
565
  }
566
+ if (BUILD.shadowClonable) opts.clonable = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowClonable);
567
+ if (BUILD.shadowSerializable) opts.serializable = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowSerializable);
527
568
  const shadowRoot = this.attachShadow(opts);
528
569
  if (BUILD.shadowModeClosed && isClosed) this.__shadowRoot = shadowRoot;
529
570
  if (globalStyleSheet === void 0) globalStyleSheet = createStyleSheetIfNeededAndSupported("") ?? null;
530
- if (globalStyleSheet) if (supportsMutableAdoptedStyleSheets) shadowRoot.adoptedStyleSheets.push(globalStyleSheet);
531
- else shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, globalStyleSheet];
571
+ if (globalStyleSheet) {
572
+ if (supportsMutableAdoptedStyleSheets) shadowRoot.adoptedStyleSheets.push(globalStyleSheet);
573
+ else shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, globalStyleSheet];
574
+ }
532
575
  }
533
576
  //#endregion
534
577
  //#region src/runtime/slot-polyfill-utils.ts
@@ -548,8 +591,10 @@ function createShadowRoot(cmpMeta) {
548
591
  const updateFallbackSlotVisibility = (elm) => {
549
592
  const childNodes = internalCall(elm, "childNodes");
550
593
  if (elm.tagName && elm.tagName.includes("-") && elm["s-cr"] && elm.tagName !== "SLOT-FB") getHostSlotNodes(childNodes, elm.tagName).forEach((slotNode) => {
551
- if (slotNode.nodeType === NODE_TYPE.ElementNode && slotNode.tagName === "SLOT-FB") if (getSlotChildSiblings(slotNode, getSlotName(slotNode), false).length) slotNode.hidden = true;
552
- else slotNode.hidden = false;
594
+ if (slotNode.nodeType === NODE_TYPE.ElementNode && slotNode.tagName === "SLOT-FB") {
595
+ if (getSlotChildSiblings(slotNode, getSlotName(slotNode), false).length) slotNode.hidden = true;
596
+ else slotNode.hidden = false;
597
+ }
553
598
  });
554
599
  let i = 0;
555
600
  for (i = 0; i < childNodes.length; i++) {
@@ -592,7 +637,7 @@ function getHostSlotNodes(childNodes, hostName, slotName) {
592
637
  slottedNodes.push(childNode);
593
638
  if (typeof slotName !== "undefined") return slottedNodes;
594
639
  }
595
- slottedNodes = [...slottedNodes, ...getHostSlotNodes(childNode.childNodes, hostName, slotName)];
640
+ slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
596
641
  }
597
642
  return slottedNodes;
598
643
  }
@@ -623,7 +668,7 @@ const isNodeLocatedInSlot = (nodeToRelocate, slotName) => {
623
668
  if (nodeToRelocate.getAttribute("slot") === slotName) return true;
624
669
  return false;
625
670
  }
626
- if (nodeToRelocate["s-sn"] === slotName) return true;
671
+ if (typeof nodeToRelocate["s-sa"] === "string") return nodeToRelocate["s-sa"] === slotName;
627
672
  return slotName === "";
628
673
  };
629
674
  /**
@@ -672,8 +717,10 @@ function patchSlotNode(node) {
672
717
  const assignedFactory = (elementsOnly) => function(opts) {
673
718
  const toReturn = [];
674
719
  const slotName = this["s-sn"];
675
- if (opts?.flatten) if (BUILD.isDev) console.error("Flattening is not supported for Stencil non-shadow slots. You can use `.childNodes` for nested slot fallback content.");
676
- else console.error("Flattening not supported for Stencil non-shadow slots");
720
+ if (opts?.flatten) {
721
+ if (BUILD.isDev) console.error("Flattening is not supported for Stencil non-shadow slots. You can use `.childNodes` for nested slot fallback content.");
722
+ else console.error("Flattening not supported for Stencil non-shadow slots");
723
+ }
677
724
  const parent = this["s-cr"].parentElement;
678
725
  (parent.__childNodes ? parent.childNodes : getSlottedChildNodes(parent.childNodes)).forEach((n) => {
679
726
  if (slotName === getSlotName(n)) toReturn.push(n);
@@ -764,8 +811,10 @@ const patchCloneNode = (HostElementPrototype) => {
764
811
  for (; i < childNodes.length; i++) {
765
812
  slotted = childNodes[i]["s-nr"];
766
813
  nonStencilNode = stencilPrivates.every((privateField) => !childNodes[i][privateField]);
767
- if (slotted) if (clonedNode.__appendChild) clonedNode.__appendChild(slotted.cloneNode(true));
768
- else clonedNode.appendChild(slotted.cloneNode(true));
814
+ if (slotted) {
815
+ if (clonedNode.__appendChild) clonedNode.__appendChild(slotted.cloneNode(true));
816
+ else clonedNode.appendChild(slotted.cloneNode(true));
817
+ }
769
818
  if (nonStencilNode) clonedNode.appendChild(childNodes[i].cloneNode(true));
770
819
  }
771
820
  }
@@ -968,11 +1017,11 @@ const patchChildSlotNodes = (elm) => {
968
1017
  } });
969
1018
  patchHostOriginalAccessor("firstChild", elm);
970
1019
  Object.defineProperty(elm, "firstChild", { get() {
971
- return this.childNodes[0];
1020
+ return this.childNodes[0] || null;
972
1021
  } });
973
1022
  patchHostOriginalAccessor("lastChild", elm);
974
1023
  Object.defineProperty(elm, "lastChild", { get() {
975
- return this.childNodes[this.childNodes.length - 1];
1024
+ return this.childNodes[this.childNodes.length - 1] || null;
976
1025
  } });
977
1026
  patchHostOriginalAccessor("childNodes", elm);
978
1027
  Object.defineProperty(elm, "childNodes", { get() {
@@ -1018,7 +1067,7 @@ const patchNextSibling = (node) => {
1018
1067
  Object.defineProperty(node, "nextSibling", { get: function() {
1019
1068
  const parentNodes = this["s-ol"]?.parentNode.childNodes;
1020
1069
  const index = parentNodes?.indexOf(this);
1021
- if (parentNodes && index > -1) return parentNodes[index + 1];
1070
+ if (parentNodes && index > -1) return parentNodes[index + 1] || null;
1022
1071
  return this.__nextSibling;
1023
1072
  } });
1024
1073
  };
@@ -1033,7 +1082,7 @@ const patchNextElementSibling = (element) => {
1033
1082
  Object.defineProperty(element, "nextElementSibling", { get: function() {
1034
1083
  const parentEles = this["s-ol"]?.parentNode.children;
1035
1084
  const index = parentEles?.indexOf(this);
1036
- if (parentEles && index > -1) return parentEles[index + 1];
1085
+ if (parentEles && index > -1) return parentEles[index + 1] || null;
1037
1086
  return this.__nextElementSibling;
1038
1087
  } });
1039
1088
  };
@@ -1048,7 +1097,7 @@ const patchPreviousSibling = (node) => {
1048
1097
  Object.defineProperty(node, "previousSibling", { get: function() {
1049
1098
  const parentNodes = this["s-ol"]?.parentNode.childNodes;
1050
1099
  const index = parentNodes?.indexOf(this);
1051
- if (parentNodes && index > -1) return parentNodes[index - 1];
1100
+ if (parentNodes && index > -1) return parentNodes[index - 1] || null;
1052
1101
  return this.__previousSibling;
1053
1102
  } });
1054
1103
  };
@@ -1063,7 +1112,7 @@ const patchPreviousElementSibling = (element) => {
1063
1112
  Object.defineProperty(element, "previousElementSibling", { get: function() {
1064
1113
  const parentNodes = this["s-ol"]?.parentNode.children;
1065
1114
  const index = parentNodes?.indexOf(this);
1066
- if (parentNodes && index > -1) return parentNodes[index - 1];
1115
+ if (parentNodes && index > -1) return parentNodes[index - 1] || null;
1067
1116
  return this.__previousElementSibling;
1068
1117
  } });
1069
1118
  };
@@ -1238,7 +1287,7 @@ function queryNonceMetaTagContent(doc) {
1238
1287
  }
1239
1288
  //#endregion
1240
1289
  //#region src/runtime/styles.ts
1241
- const rootAppliedStyles = /* @__PURE__ */ new WeakMap();
1290
+ const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
1242
1291
  /**
1243
1292
  * Get or initialize the set of applied style scope IDs for a container element.
1244
1293
  *
@@ -1262,9 +1311,10 @@ const getAppliedStyles = (container) => {
1262
1311
  * @param prepend if true, add to beginning; if false, add to end
1263
1312
  */
1264
1313
  const adoptStylesheet = (container, sheet, prepend = false) => {
1265
- if (supportsMutableAdoptedStyleSheets) if (prepend) container.adoptedStyleSheets.unshift(sheet);
1266
- else container.adoptedStyleSheets.push(sheet);
1267
- else if (prepend) container.adoptedStyleSheets = [sheet, ...container.adoptedStyleSheets];
1314
+ if (supportsMutableAdoptedStyleSheets) {
1315
+ if (prepend) container.adoptedStyleSheets.unshift(sheet);
1316
+ else container.adoptedStyleSheets.push(sheet);
1317
+ } else if (prepend) container.adoptedStyleSheets = [sheet, ...container.adoptedStyleSheets];
1268
1318
  else container.adoptedStyleSheets = [...container.adoptedStyleSheets, sheet];
1269
1319
  };
1270
1320
  /**
@@ -1277,7 +1327,7 @@ const adoptStylesheet = (container, sheet, prepend = false) => {
1277
1327
  * @returns a new CSSStyleSheet for the correct window
1278
1328
  */
1279
1329
  const createStylesheetForWindow = (container, cssText) => {
1280
- const sheet = new (container.defaultView ?? container.ownerDocument?.defaultView ?? win).CSSStyleSheet();
1330
+ const sheet = new (container.defaultView ?? (container.ownerDocument?.defaultView) ?? win).CSSStyleSheet();
1281
1331
  sheet.replaceSync(cssText);
1282
1332
  return sheet;
1283
1333
  };
@@ -1348,41 +1398,46 @@ const addStyle = (styleContainerNode, cmpMeta, mode) => {
1348
1398
  /**
1349
1399
  * attach styles at the end of the head tag if we render scoped components
1350
1400
  */
1351
- if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation)) if (styleContainerNode.nodeName === "HEAD") {
1352
- /**
1353
- * if the page contains preconnect links, we want to insert the styles
1354
- * after the last preconnect link to ensure the styles are preloaded
1355
- */
1356
- const preconnectLinks = styleContainerNode.querySelectorAll("link[rel=preconnect]");
1357
- const referenceNode = preconnectLinks.length > 0 ? preconnectLinks[preconnectLinks.length - 1].nextSibling : styleContainerNode.querySelector("style");
1358
- styleContainerNode.insertBefore(styleElm, referenceNode?.parentNode === styleContainerNode ? referenceNode : null);
1359
- } else if ("host" in styleContainerNode) if (supportsConstructableStylesheets) {
1360
- const stylesheet = createStylesheetForWindow(styleContainerNode, style);
1361
- adoptStylesheet(styleContainerNode, stylesheet, true);
1362
- } else {
1363
- /**
1364
- * If a scoped component is used within a shadow root and constructable stylesheets are
1365
- * not supported, we want to insert the styles at the beginning of the shadow root node.
1366
- *
1367
- * However, if there is already a style node in the shadow root, we just append
1368
- * the styles to the existing node.
1369
- *
1370
- * Note: order of how styles are applied is important. The new style node
1371
- * should be inserted before the existing style node.
1372
- *
1373
- * During HMR, create separate style elements for scoped components so they can be
1374
- * updated independently without affecting other components' styles.
1375
- */
1376
- const existingStyleContainer = styleContainerNode.querySelector("style");
1377
- if (existingStyleContainer && !BUILD.hotModuleReplacement) existingStyleContainer.textContent = style + existingStyleContainer.textContent;
1378
- else styleContainerNode.prepend(styleElm);
1401
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation)) {
1402
+ if (styleContainerNode.nodeName === "HEAD") {
1403
+ /**
1404
+ * if the page contains preconnect links, we want to insert the styles
1405
+ * after the last preconnect link to ensure the styles are preloaded
1406
+ */
1407
+ const preconnectLinks = styleContainerNode.querySelectorAll("link[rel=preconnect]");
1408
+ const referenceNode = preconnectLinks.length > 0 ? preconnectLinks[preconnectLinks.length - 1].nextSibling : styleContainerNode.querySelector("style");
1409
+ styleContainerNode.insertBefore(styleElm, referenceNode?.parentNode === styleContainerNode ? referenceNode : null);
1410
+ } else if ("host" in styleContainerNode) {
1411
+ if (supportsConstructableStylesheets) {
1412
+ const stylesheet = createStylesheetForWindow(styleContainerNode, style);
1413
+ adoptStylesheet(styleContainerNode, stylesheet, true);
1414
+ } else {
1415
+ /**
1416
+ * If a scoped component is used within a shadow root and constructable stylesheets are
1417
+ * not supported, we want to insert the styles at the beginning of the shadow root node.
1418
+ *
1419
+ * However, if there is already a style node in the shadow root, we just append
1420
+ * the styles to the existing node.
1421
+ *
1422
+ * Note: order of how styles are applied is important. The new style node
1423
+ * should be inserted before the existing style node.
1424
+ *
1425
+ * During HMR, create separate style elements for scoped components so they can be
1426
+ * updated independently without affecting other components' styles.
1427
+ */
1428
+ const existingStyleContainer = styleContainerNode.querySelector("style");
1429
+ if (existingStyleContainer && !BUILD.hotModuleReplacement) existingStyleContainer.textContent = style + existingStyleContainer.textContent;
1430
+ else styleContainerNode.prepend(styleElm);
1431
+ }
1432
+ } else styleContainerNode.append(styleElm);
1379
1433
  }
1380
- else styleContainerNode.append(styleElm);
1381
1434
  /**
1382
1435
  * attach styles at the beginning of a shadow root node if we render shadow components
1383
1436
  */
1384
- if (cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) if (isClosedShadowSSR) styleContainerNode.prepend(styleElm);
1385
- else styleContainerNode.insertBefore(styleElm, null);
1437
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) {
1438
+ if (isClosedShadowSSR) styleContainerNode.prepend(styleElm);
1439
+ else styleContainerNode.insertBefore(styleElm, null);
1440
+ }
1386
1441
  if (appliedStyles) appliedStyles.add(scopeId);
1387
1442
  }
1388
1443
  } else if (BUILD.constructableCSS) {
@@ -1474,7 +1529,12 @@ const hydrateScopedToShadow = () => {
1474
1529
  if (!win.document) return;
1475
1530
  const styleElements = win.document.querySelectorAll(`[${HYDRATED_STYLE_ID}]`);
1476
1531
  let i = 0;
1477
- for (; i < styleElements.length; i++) registerStyle(styleElements[i].getAttribute(HYDRATED_STYLE_ID), convertScopedToShadow(styleElements[i].innerHTML), true);
1532
+ for (; i < styleElements.length; i++) {
1533
+ const scopeId = styleElements[i].getAttribute(HYDRATED_STYLE_ID);
1534
+ const existing = styles.get(scopeId);
1535
+ const allowCS = existing !== void 0 ? existing instanceof CSSStyleSheet : true;
1536
+ registerStyle(scopeId, convertScopedToShadow(styleElements[i].innerHTML), allowCS);
1537
+ }
1478
1538
  };
1479
1539
  //#endregion
1480
1540
  //#region src/utils/helpers.ts
@@ -1606,11 +1666,15 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1606
1666
  }
1607
1667
  } else if (BUILD.vdomStyle && memberName === "style") {
1608
1668
  if (BUILD.updatable) {
1609
- for (const prop in oldValue) if (!newValue || newValue[prop] == null) if (!BUILD.hydrateServerSide && prop.includes("-")) elm.style.removeProperty(prop);
1610
- else elm.style[prop] = "";
1669
+ for (const prop in oldValue) if (!newValue || newValue[prop] == null) {
1670
+ if (!BUILD.hydrateServerSide && prop.includes("-")) elm.style.removeProperty(prop);
1671
+ else elm.style[prop] = "";
1672
+ }
1673
+ }
1674
+ for (const prop in newValue) if (!oldValue || newValue[prop] !== oldValue[prop]) {
1675
+ if (!BUILD.hydrateServerSide && prop.includes("-")) elm.style.setProperty(prop, newValue[prop]);
1676
+ else elm.style[prop] = newValue[prop];
1611
1677
  }
1612
- for (const prop in newValue) if (!oldValue || newValue[prop] !== oldValue[prop]) if (!BUILD.hydrateServerSide && prop.includes("-")) elm.style.setProperty(prop, newValue[prop]);
1613
- else elm.style[prop] = newValue[prop];
1614
1678
  } else if (BUILD.vdomKey && memberName === "key") {} else if (BUILD.vdomRef && memberName === "ref") {
1615
1679
  if (newValue) queueRefAttachment(newValue, elm);
1616
1680
  } else if (BUILD.vdomListener && (BUILD.lazyLoad ? !isProp : !elm.__lookupSetter__(memberName)) && memberName[0] === "o" && memberName[1] === "n") {
@@ -1619,11 +1683,11 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1619
1683
  else memberName = ln[2] + memberName.slice(3);
1620
1684
  if (oldValue || newValue) {
1621
1685
  const capture = memberName.endsWith(CAPTURE_EVENT_SUFFIX);
1622
- memberName = memberName.replace(/* @__PURE__ */ new RegExp(CAPTURE_EVENT_SUFFIX + "$"), "");
1686
+ memberName = memberName.replace(/*@__PURE__*/ new RegExp(CAPTURE_EVENT_SUFFIX + "$"), "");
1623
1687
  if (oldValue) plt.rel(elm, memberName, oldValue, capture);
1624
1688
  if (newValue) plt.ael(elm, memberName, newValue, capture);
1625
1689
  }
1626
- } else if (BUILD.vdomPropOrAttr && memberName[0] === "a" && memberName.startsWith("attr:")) {
1690
+ } else if (BUILD.vdomPropOrAttrPrefix && memberName[0] === "a" && memberName.startsWith("attr:")) {
1627
1691
  const propName = memberName.slice(5);
1628
1692
  let attrName;
1629
1693
  if (BUILD.member) {
@@ -1638,7 +1702,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1638
1702
  if (newValue !== false || elm.getAttribute(attrName) === "") elm.removeAttribute(attrName);
1639
1703
  } else elm.setAttribute(attrName, newValue === true ? "" : newValue);
1640
1704
  return;
1641
- } else if (BUILD.vdomPropOrAttr && memberName[0] === "p" && memberName.startsWith("prop:")) {
1705
+ } else if (BUILD.vdomPropOrAttrPrefix && memberName[0] === "p" && memberName.startsWith("prop:")) {
1642
1706
  const propName = memberName.slice(5);
1643
1707
  try {
1644
1708
  elm[propName] = newValue;
@@ -1658,8 +1722,10 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1658
1722
  if (!elm.tagName.includes("-")) {
1659
1723
  const n = newValue == null ? "" : newValue;
1660
1724
  if (memberName === "list") isProp = false;
1661
- else if (oldValue == null || elm[memberName] !== n) if (typeof elm.__lookupSetter__(memberName) === "function") elm[memberName] = n;
1662
- else elm.setAttribute(memberName, n);
1725
+ else if (oldValue == null || elm[memberName] !== n) {
1726
+ if (typeof elm.__lookupSetter__(memberName) === "function") elm[memberName] = n;
1727
+ else elm.setAttribute(memberName, n);
1728
+ }
1663
1729
  } else if (elm[memberName] !== newValue) elm[memberName] = newValue;
1664
1730
  } catch {}
1665
1731
  /**
@@ -1677,8 +1743,10 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1677
1743
  }
1678
1744
  }
1679
1745
  if (newValue == null || newValue === false) {
1680
- if (newValue !== false || elm.getAttribute(memberName) === "") if (BUILD.vdomXlink && xlink) elm.removeAttributeNS(XLINK_NS, memberName);
1681
- else elm.removeAttribute(memberName);
1746
+ if (newValue !== false || elm.getAttribute(memberName) === "" || flags & VNODE_FLAGS.isHost && !isEnumeratedAttribute(memberName)) {
1747
+ if (BUILD.vdomXlink && xlink) elm.removeAttributeNS(XLINK_NS, memberName);
1748
+ else elm.removeAttribute(memberName);
1749
+ }
1682
1750
  } else if ((!isProp || flags & VNODE_FLAGS.isHost || isSvg) && !isComplex && elm.nodeType === NODE_TYPE.ElementNode) {
1683
1751
  newValue = newValue === true ? "" : newValue;
1684
1752
  if (BUILD.vdomXlink && xlink) elm.setAttributeNS(XLINK_NS, memberName, newValue);
@@ -1686,6 +1754,18 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1686
1754
  }
1687
1755
  }
1688
1756
  };
1757
+ /**
1758
+ * Attribute names that are enumerated (tri-state true/false/unset) rather than
1759
+ * plain boolean-presence attributes. An explicit `"false"` string on one of
1760
+ * these is semantically different from the attribute being absent, so a
1761
+ * reflected `false` value must not clear a pre-existing literal value.
1762
+ */
1763
+ const ENUMERATED_ATTRIBUTES = /*@__PURE__*/ new Set([
1764
+ "draggable",
1765
+ "contenteditable",
1766
+ "spellcheck"
1767
+ ]);
1768
+ const isEnumeratedAttribute = (attrName) => ENUMERATED_ATTRIBUTES.has(attrName) || attrName.startsWith("aria-");
1689
1769
  const parseClassListRegex = /\s/;
1690
1770
  /**
1691
1771
  * Parsed a string of classnames into an array
@@ -1809,6 +1889,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex) => {
1809
1889
  }
1810
1890
  } else if (BUILD.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotReference) {
1811
1891
  elm = newVNode.$elm$ = BUILD.isDebug || BUILD.hydrateServerSide ? slotReferenceDebugNode(newVNode) : win.document.createTextNode("");
1892
+ if (typeof newVNode.$attrs$?.slot === "string") elm["s-sa"] = newVNode.$attrs$.slot;
1812
1893
  if (BUILD.vdomAttribute) updateElement(null, newVNode, isSvgMode);
1813
1894
  } else {
1814
1895
  if (BUILD.svg && !isSvgMode) isSvgMode = newVNode.$tag$ === "svg";
@@ -2084,8 +2165,10 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = fal
2084
2165
  node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
2085
2166
  newStartVnode = newCh[++newStartIdx];
2086
2167
  }
2087
- if (node) if (BUILD.slotRelocation) insertBefore(referenceNode(oldStartVnode.$elm$).parentNode, node, referenceNode(oldStartVnode.$elm$));
2088
- else insertBefore(oldStartVnode.$elm$.parentNode, node, oldStartVnode.$elm$);
2168
+ if (node) {
2169
+ if (BUILD.slotRelocation) insertBefore(referenceNode(oldStartVnode.$elm$).parentNode, node, referenceNode(oldStartVnode.$elm$));
2170
+ else insertBefore(oldStartVnode.$elm$.parentNode, node, oldStartVnode.$elm$);
2171
+ }
2089
2172
  }
2090
2173
  if (oldStartIdx > oldEndIdx) addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
2091
2174
  else if (BUILD.updatable && newStartIdx > newEndIdx) removeVnodes(oldCh, oldStartIdx, oldEndIdx);
@@ -2172,6 +2255,30 @@ const patch = (oldVNode, newVNode, isInitialRender = false) => {
2172
2255
  */
2173
2256
  const relocateNodes = [];
2174
2257
  /**
2258
+ * When a forwarded `<slot>` gets relocated, drag along any content already forwarded through it,
2259
+ * to wherever it just landed (or nowhere, to be hidden, if it didn't match anything).
2260
+ *
2261
+ * Runs as its own pass after {@link markSlotContentForRelocation} rather than inside it, so that
2262
+ * function's matching order - which hydration's node/comment ordering depends on - is untouched.
2263
+ */
2264
+ const carryContentWithRelocatedSlotRefs = () => {
2265
+ for (const relocateData of relocateNodes.slice()) {
2266
+ const marker = relocateData.$nodeToRelocate$;
2267
+ if (!marker["s-sr"]) continue;
2268
+ const carriedSiblings = getSlotChildSiblings(marker, marker["s-sn"] || "", false);
2269
+ for (const carriedSibling of carriedSiblings) {
2270
+ if (!carriedSibling["s-ol"]) continue;
2271
+ let siblingRelocateData = relocateNodes.find((r) => r.$nodeToRelocate$ === carriedSibling);
2272
+ if (!siblingRelocateData) {
2273
+ siblingRelocateData = { $nodeToRelocate$: carriedSibling };
2274
+ relocateNodes.push(siblingRelocateData);
2275
+ }
2276
+ siblingRelocateData.$slotRefNode$ = relocateData.$slotRefNode$;
2277
+ if (relocateData.$slotRefNode$) carriedSibling["s-sh"] = relocateData.$slotRefNode$["s-hn"];
2278
+ }
2279
+ }
2280
+ };
2281
+ /**
2175
2282
  * Mark the contents of a slot for relocation via adding references to them to
2176
2283
  * the {@link relocateNodes} data structure. The actual work of relocating them
2177
2284
  * will then be handled in {@link renderVdom}.
@@ -2276,7 +2383,7 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2276
2383
  return newNode;
2277
2384
  }
2278
2385
  }
2279
- if (parent.__insertBefore) return parent.__insertBefore(newNode, reference);
2386
+ if (BUILD.slotRelocation && parent?.__insertBefore) return parent.__insertBefore(newNode, reference);
2280
2387
  else return parent?.insertBefore(newNode, reference);
2281
2388
  };
2282
2389
  /**
@@ -2370,6 +2477,7 @@ render() {
2370
2477
  plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
2371
2478
  if (checkSlotRelocate) {
2372
2479
  markSlotContentForRelocation(rootVnode.$elm$);
2480
+ carryContentWithRelocatedSlotRefs();
2373
2481
  for (const relocateData of relocateNodes) {
2374
2482
  const nodeToRelocate = relocateData.$nodeToRelocate$;
2375
2483
  if (!nodeToRelocate["s-ol"] && win.document) {
@@ -2429,7 +2537,7 @@ render() {
2429
2537
  }
2430
2538
  if (BUILD.slotRelocation && !useNativeShadowDom && !(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && hostElm["s-cr"]) {
2431
2539
  const children = rootVnode.$elm$.__childNodes || rootVnode.$elm$.childNodes;
2432
- for (const childNode of children) if (childNode["s-hn"] !== hostTagName && !childNode["s-sh"]) {
2540
+ for (const childNode of children) if (childNode["s-hn"] !== hostTagName && childNode["s-sh"] !== hostTagName) {
2433
2541
  if (isInitialLoad && childNode["s-ih"] == null) childNode["s-ih"] = childNode.hidden ?? false;
2434
2542
  if (childNode.nodeType === NODE_TYPE.ElementNode) childNode.hidden = true;
2435
2543
  else if (childNode.nodeType === NODE_TYPE.TextNode && !!childNode.nodeValue.trim()) {
@@ -2447,16 +2555,58 @@ const slotReferenceDebugNode = (slotVNode) => win.document?.createComment(`<slot
2447
2555
  const originalLocationDebugNode = (nodeToRelocate) => win.document?.createComment(`org-location for ` + (nodeToRelocate.localName ? `<${nodeToRelocate.localName}> (host=${nodeToRelocate["s-hn"]})` : `[${nodeToRelocate.textContent}]`));
2448
2556
  //#endregion
2449
2557
  //#region src/runtime/update-component.ts
2558
+ /**
2559
+ * Get a promise that resolves once `hostRef`'s real `connectedCallback` has fired for the first time.
2560
+ *
2561
+ * @param hostRef the component's host reference
2562
+ * @returns a promise that resolves once the component's real `connectedCallback` has fired
2563
+ */
2564
+ const ensureFirstConnectPromise = (hostRef) => {
2565
+ if (!hostRef.$onFirstConnectPromise$) hostRef.$onFirstConnectPromise$ = new Promise((r) => hostRef.$onFirstConnectResolve$ = r);
2566
+ return hostRef.$onFirstConnectPromise$;
2567
+ };
2568
+ /**
2569
+ * Resolve `hostRef`'s first-connect promise and flag it connected. Called once this
2570
+ * component's real `connectedCallback` fires, plus from error/disconnect cleanup so a
2571
+ * component that never connects can't hang an ancestor or descendant forever.
2572
+ *
2573
+ * @param hostRef the component's host reference
2574
+ */
2575
+ const markFirstConnected = (hostRef) => {
2576
+ hostRef.$flags$ |= HOST_FLAGS.hasFiredConnected;
2577
+ hostRef.$onFirstConnectResolve$?.();
2578
+ hostRef.$onFirstConnectResolve$ = void 0;
2579
+ };
2580
+ /**
2581
+ * Wait for `ancestorElm` to be defined and its real `connectedCallback` to have completed.
2582
+ * Shared by the lazy ({@link initializeComponent}) and standalone (`bootstrap-standalone.ts`)
2583
+ * `connectedCallback` paths so a component never connects before its nearest Stencil
2584
+ * ancestor, regardless of load order. Both call sites already check `BUILD.asyncLoading` and
2585
+ * that an ancestor exists before calling this. Lazy's proxy classes are always pre-defined,
2586
+ * so the `whenDefined` wait is a no-op there - it only does real work for standalone's
2587
+ * autoloader, where the ancestor tag may not be defined yet.
2588
+ *
2589
+ * @param ancestorElm the nearest Stencil ancestor element
2590
+ */
2591
+ const awaitAncestorConnected = async (ancestorElm) => {
2592
+ let ancestorHostRef = getHostRef(ancestorElm);
2593
+ if (!BUILD.lazyLoad && !ancestorHostRef) {
2594
+ await getRegistry().whenDefined(ancestorElm.tagName.toLowerCase());
2595
+ ancestorHostRef = getHostRef(ancestorElm);
2596
+ }
2597
+ if (ancestorHostRef && !(ancestorHostRef.$flags$ & HOST_FLAGS.hasFiredConnected)) await ensureFirstConnectPromise(ancestorHostRef);
2598
+ };
2450
2599
  const attachToAncestor = (hostRef, ancestorComponent) => {
2451
2600
  if (BUILD.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent["s-p"]) {
2452
2601
  const index = ancestorComponent["s-p"].push(new Promise((r) => hostRef.$onRenderResolve$ = () => {
2453
2602
  ancestorComponent["s-p"].splice(index - 1, 1);
2454
2603
  r();
2455
2604
  }));
2605
+ if (ancestorComponent["s-pc"]) ancestorComponent["s-pc"].push(ensureFirstConnectPromise(hostRef));
2456
2606
  }
2457
2607
  };
2458
2608
  const scheduleUpdate = (hostRef, isInitialLoad) => {
2459
- if (BUILD.taskQueue && BUILD.updatable) hostRef.$flags$ |= HOST_FLAGS.isQueuedForUpdate;
2609
+ if (BUILD.updatable) hostRef.$flags$ |= HOST_FLAGS.isQueuedForUpdate;
2460
2610
  if (BUILD.asyncLoading && hostRef.$flags$ & HOST_FLAGS.isWaitingForChildren) {
2461
2611
  hostRef.$flags$ |= HOST_FLAGS.needsRerender;
2462
2612
  return;
@@ -2464,6 +2614,8 @@ const scheduleUpdate = (hostRef, isInitialLoad) => {
2464
2614
  attachToAncestor(hostRef, hostRef.$ancestorComponent$);
2465
2615
  const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
2466
2616
  if (isInitialLoad) {
2617
+ const pendingConnects = BUILD.asyncLoading ? hostRef.$hostElement$["s-pc"] : void 0;
2618
+ if (pendingConnects && pendingConnects.length > 0) return Promise.all(pendingConnects).then(dispatch).catch(dispatch);
2467
2619
  queueMicrotask(() => {
2468
2620
  dispatch();
2469
2621
  });
@@ -2503,10 +2655,6 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
2503
2655
  let maybePromise;
2504
2656
  if (isInitialLoad) {
2505
2657
  if (BUILD.lazyLoad) {
2506
- if (BUILD.slotRelocation && hostRef.$deferredConnectedCallback$) {
2507
- hostRef.$deferredConnectedCallback$ = false;
2508
- safeCall(instance, "connectedCallback", void 0, elm);
2509
- }
2510
2658
  if (BUILD.hostListener) {
2511
2659
  hostRef.$flags$ |= HOST_FLAGS.isListenReady;
2512
2660
  if (hostRef.$queuedListeners$) {
@@ -2519,6 +2667,14 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
2519
2667
  if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillLoad");
2520
2668
  maybePromise = safeCall(instance, "componentWillLoad", void 0, elm);
2521
2669
  } else {
2670
+ if (BUILD.updatable && hostRef.$queuedPropChanges$) {
2671
+ const changes = hostRef.$queuedPropChanges$;
2672
+ hostRef.$queuedPropChanges$ = void 0;
2673
+ if (safeCall(instance, "componentShouldUpdate", changes, elm) === false) {
2674
+ hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
2675
+ return;
2676
+ }
2677
+ }
2522
2678
  if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillUpdate");
2523
2679
  maybePromise = safeCall(instance, "componentWillUpdate", void 0, elm);
2524
2680
  }
@@ -2633,7 +2789,6 @@ let renderingRef = null;
2633
2789
  const callRender = (hostRef, instance, elm, isInitialLoad) => {
2634
2790
  const allRenderFn = !!BUILD.allRenderFn;
2635
2791
  const lazyLoad = !!BUILD.lazyLoad;
2636
- const taskQueue = !!BUILD.taskQueue;
2637
2792
  const updatable = !!BUILD.updatable;
2638
2793
  try {
2639
2794
  renderingRef = instance;
@@ -2642,14 +2797,17 @@ const callRender = (hostRef, instance, elm, isInitialLoad) => {
2642
2797
  * method, so we can call the method immediately. If not, check before calling it.
2643
2798
  */
2644
2799
  instance = allRenderFn ? instance.render() : instance.render && instance.render();
2645
- if (updatable && taskQueue) hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
2800
+ if (updatable) hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
2646
2801
  if (updatable || lazyLoad) hostRef.$flags$ |= HOST_FLAGS.hasRendered;
2647
- if (BUILD.hasRenderFn || BUILD.reflect) if (BUILD.vdomRender || BUILD.reflect) if (BUILD.hydrateServerSide) return Promise.resolve(instance).then((value) => renderVdom(hostRef, value, isInitialLoad));
2648
- else renderVdom(hostRef, instance, isInitialLoad);
2649
- else {
2650
- const shadowRoot = elm.shadowRoot;
2651
- if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.shadowDomEncapsulation) shadowRoot.textContent = instance;
2652
- else elm.textContent = instance;
2802
+ if (BUILD.hasRenderFn || BUILD.reflect) {
2803
+ if (BUILD.vdomRender || BUILD.reflect) {
2804
+ if (BUILD.hydrateServerSide) return Promise.resolve(instance).then((value) => renderVdom(hostRef, value, isInitialLoad));
2805
+ else renderVdom(hostRef, instance, isInitialLoad);
2806
+ } else {
2807
+ const shadowRoot = elm.shadowRoot;
2808
+ if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.shadowDomEncapsulation) shadowRoot.textContent = instance;
2809
+ else elm.textContent = instance;
2810
+ }
2653
2811
  }
2654
2812
  } catch (e) {
2655
2813
  consoleError(e, hostRef.$hostElement$);
@@ -2789,17 +2947,19 @@ const initializeSignals = (elm, hostRef, cmpMeta) => {
2789
2947
  const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2790
2948
  for (const [memberName, [memberFlags]] of Object.entries(cmpMeta.$members$ ?? {})) {
2791
2949
  if (!(memberFlags & MEMBER_FLAGS.PropLike)) continue;
2792
- const sig = signal(hostRef.$instanceValues$.get(memberName));
2950
+ const initialVal = hostRef.$instanceValues$.get(memberName);
2951
+ const sig = signal(initialVal);
2793
2952
  hostRef.$signalValues$.set(memberName, sig);
2794
2953
  let prevScheduleVal = sig.peek();
2795
2954
  disposers.push(effect(() => {
2796
2955
  const newVal = sig.value;
2797
2956
  if (hostRef.$flags$ & HOST_FLAGS.hasRendered) {
2798
2957
  if (instance?.componentShouldUpdate) {
2799
- if (instance.componentShouldUpdate(newVal, prevScheduleVal, memberName) === false && !(hostRef.$flags$ & HOST_FLAGS.isQueuedForUpdate)) {
2800
- prevScheduleVal = newVal;
2801
- return;
2802
- }
2958
+ const changes = hostRef.$queuedPropChanges$ ||= {};
2959
+ changes[memberName] = {
2960
+ newVal,
2961
+ oldVal: changes[memberName]?.oldVal ?? prevScheduleVal
2962
+ };
2803
2963
  }
2804
2964
  if (!(hostRef.$flags$ & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
2805
2965
  }
@@ -2834,7 +2994,8 @@ const initializeSignals = (elm, hostRef, cmpMeta) => {
2834
2994
  consoleError(e, elm);
2835
2995
  }
2836
2996
  }));
2837
- elm[STENCIL_SIGNALS_SYMBOL] = new Map([...hostRef.$signalValues$].filter(([k]) => (cmpMeta.$members$?.[k]?.[0] ?? 0) & MEMBER_FLAGS.Prop));
2997
+ const publicSignals = new Map([...hostRef.$signalValues$].filter(([k]) => (cmpMeta.$members$?.[k]?.[0] ?? 0) & MEMBER_FLAGS.Prop));
2998
+ elm[STENCIL_SIGNALS_SYMBOL] = publicSignals;
2838
2999
  hostRef.$signalCleanup$ = () => {
2839
3000
  disposers.forEach((d) => d());
2840
3001
  elm[STENCIL_SIGNALS_SYMBOL] = void 0;
@@ -2883,24 +3044,30 @@ const h = (nodeName, vnodeData, ...children) => {
2883
3044
  for (let i = 0; i < c.length; i++) {
2884
3045
  child = c[i];
2885
3046
  if (Array.isArray(child)) walk(child);
2886
- else if (child != null && typeof child !== "boolean") if (BUILD.vdomSignals && isSignalLike(child)) {
2887
- const sigVNode = newVNode(null, String(child.peek()));
2888
- sigVNode.$signal$ = child;
2889
- vNodeChildren.push(sigVNode);
2890
- lastSimple = false;
2891
- } else {
2892
- if (simple = typeof nodeName !== "function" && !isComplexType(child)) child = String(child);
2893
- else if (BUILD.isDev && typeof nodeName !== "function" && child.$flags$ === void 0) consoleDevError(`vNode passed as children has unexpected type.
2894
- Make sure it's using the correct h() function.
2895
- Empty objects can also be the cause, look for JSX comments that became objects.`);
2896
- if (simple && lastSimple) vNodeChildren[vNodeChildren.length - 1].$text$ += child;
2897
- else vNodeChildren.push(simple ? newVNode(null, child) : child);
2898
- lastSimple = simple;
3047
+ else if (child != null && typeof child !== "boolean") {
3048
+ if (BUILD.vdomSignals && isSignalLike(child)) {
3049
+ const sigVNode = newVNode(null, String(child.peek()));
3050
+ sigVNode.$signal$ = child;
3051
+ vNodeChildren.push(sigVNode);
3052
+ lastSimple = false;
3053
+ } else {
3054
+ if (simple = typeof nodeName !== "function" && !isComplexType(child)) child = String(child);
3055
+ else if (typeof nodeName !== "function" && child.$flags$ === void 0) {
3056
+ if (BUILD.isDev) consoleDevError(`vNode passed as children has unexpected type.
3057
+ Make sure it's using the correct h() function.
3058
+ Empty objects can also be the cause, look for JSX comments that became objects.`);
3059
+ else consoleError("Invalid vNode child");
3060
+ continue;
3061
+ }
3062
+ if (simple && lastSimple) vNodeChildren[vNodeChildren.length - 1].$text$ += child;
3063
+ else vNodeChildren.push(simple ? newVNode(null, child) : child);
3064
+ lastSimple = simple;
3065
+ }
2899
3066
  }
2900
3067
  }
2901
3068
  };
2902
3069
  walk(children);
2903
- if (vnodeData) {
3070
+ if (vnodeData && typeof vnodeData === "object") {
2904
3071
  if (BUILD.isDev && nodeName === "input") validateInputProperties(vnodeData);
2905
3072
  if (BUILD.vdomKey && vnodeData.key) key = vnodeData.key;
2906
3073
  if (BUILD.slotRelocation && vnodeData.name) slotName = vnodeData.name;
@@ -3001,7 +3168,7 @@ const convertToPrivate = (node) => {
3001
3168
  /**
3002
3169
  * Validates the ordering of attributes on an input element
3003
3170
  *
3004
- * @param inputElm the element to validate
3171
+ * @param inputElm the vnode data (JSX props) for the element to validate
3005
3172
  */
3006
3173
  const validateInputProperties = (inputElm) => {
3007
3174
  const props = Object.keys(inputElm);
@@ -3880,14 +4047,15 @@ const parsePropertyValue = (propValue, propType, isFormAssociated) => {
3880
4047
  /**
3881
4048
  * ensure this value is of the correct prop type
3882
4049
  */
3883
- if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean)
3884
- /**
3885
- * For form-associated components, according to HTML spec, the presence of any boolean attribute
3886
- * (regardless of its value, even "false") should make the property true.
3887
- * For non-form-associated components, we maintain the legacy behavior where "false" becomes false.
3888
- */
3889
- if (BUILD.formAssociated && isFormAssociated && typeof propValue === "string") return propValue === "" || !!propValue;
3890
- else return propValue === "false" ? false : propValue === "" || !!propValue;
4050
+ if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean) {
4051
+ /**
4052
+ * For form-associated components, according to HTML spec, the presence of any boolean attribute
4053
+ * (regardless of its value, even "false") should make the property true.
4054
+ * For non-form-associated components, we maintain the legacy behavior where "false" becomes false.
4055
+ */
4056
+ if (BUILD.formAssociated && isFormAssociated && typeof propValue === "string") return propValue === "" || !!propValue;
4057
+ else return propValue === "false" ? false : propValue === "" || !!propValue;
4058
+ }
3891
4059
  /**
3892
4060
  * force it to be a number
3893
4061
  */
@@ -3975,7 +4143,11 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
3975
4143
  }
3976
4144
  if (BUILD.updatable && flags & HOST_FLAGS.hasRendered) {
3977
4145
  if (instance.componentShouldUpdate) {
3978
- if (instance.componentShouldUpdate(newVal, oldVal, propName) === false && !(flags & HOST_FLAGS.isQueuedForUpdate)) return;
4146
+ const changes = hostRef.$queuedPropChanges$ ||= {};
4147
+ changes[propName] = {
4148
+ newVal,
4149
+ oldVal: changes[propName]?.oldVal ?? oldVal
4150
+ };
3979
4151
  }
3980
4152
  if (!(flags & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
3981
4153
  }
@@ -4109,11 +4281,12 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4109
4281
  };
4110
4282
  for (const deserializer of cmpMeta.$deserializers$[propName]) {
4111
4283
  const [[methodName]] = Object.entries(deserializer);
4112
- if (BUILD.lazyLoad) if (hostRef.$lazyInstance$) setVal(methodName, hostRef.$lazyInstance$);
4113
- else hostRef.$fetchedCbList$.push(() => {
4114
- setVal(methodName, hostRef.$lazyInstance$);
4115
- });
4116
- else setVal(methodName, this);
4284
+ if (BUILD.lazyLoad) {
4285
+ if (hostRef.$lazyInstance$) setVal(methodName, hostRef.$lazyInstance$);
4286
+ else hostRef.$fetchedCbList$.push(() => {
4287
+ setVal(methodName, hostRef.$lazyInstance$);
4288
+ });
4289
+ } else setVal(methodName, this);
4117
4290
  }
4118
4291
  return;
4119
4292
  } else if (prototype.hasOwnProperty(propName) && typeof this[propName] === "number" && this[propName] == newValue) return;
@@ -4137,7 +4310,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4137
4310
  if (!isSpuriousBooleanRemoval && newValue != this[propName] && (!propDesc.get || !!propDesc.set)) this[propName] = newValue;
4138
4311
  });
4139
4312
  };
4140
- Cstr.observedAttributes = Array.from(new Set([...Object.keys(cmpMeta.$watchers$ ?? {}), ...members.filter(([_, m]) => m[0] & MEMBER_FLAGS.HasAttribute).map(([propName, m]) => {
4313
+ Cstr.observedAttributes = Array.from(/* @__PURE__ */ new Set([...Object.keys(cmpMeta.$watchers$ ?? {}), ...members.filter(([_, m]) => m[0] & MEMBER_FLAGS.HasAttribute).map(([propName, m]) => {
4141
4314
  const attrName = m[1] || propName;
4142
4315
  attrNameToPropName.set(attrName, propName);
4143
4316
  if (BUILD.reflect && m[0] & MEMBER_FLAGS.ReflectAttr) cmpMeta.$attrsToReflect$?.push([propName, attrName]);
@@ -4164,6 +4337,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4164
4337
  try {
4165
4338
  if ((hostRef.$flags$ & HOST_FLAGS.hasInitializedComponent) === 0) {
4166
4339
  hostRef.$flags$ |= HOST_FLAGS.hasInitializedComponent;
4340
+ hostRef.$flags$ &= ~HOST_FLAGS.hasFailedLoad;
4167
4341
  const bundleId = cmpMeta.$lazyBundleId$;
4168
4342
  if (BUILD.lazyLoad && bundleId) {
4169
4343
  const CstrImport = loadModule(cmpMeta, hostRef, hmrVersionId);
@@ -4172,7 +4346,12 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4172
4346
  Cstr = await CstrImport;
4173
4347
  endLoad();
4174
4348
  } else Cstr = CstrImport;
4175
- if (!Cstr) throw new Error(`Constructor for "${cmpMeta.$tagName$}#${hostRef.$modeName$}" was not found`);
4349
+ if (!Cstr) {
4350
+ hostRef.$flags$ &= ~HOST_FLAGS.hasInitializedComponent;
4351
+ hostRef.$loadRetryCount$ = (hostRef.$loadRetryCount$ ?? 0) + 1;
4352
+ if (hostRef.$loadRetryCount$ < 3) hostRef.$flags$ |= HOST_FLAGS.hasFailedLoad;
4353
+ throw new Error(`Constructor for "${cmpMeta.$tagName$}#${hostRef.$modeName$}" was not found`);
4354
+ }
4176
4355
  if (BUILD.member && !Cstr.isProxied) {
4177
4356
  if (BUILD.propChangeCallback) {
4178
4357
  cmpMeta.$watchers$ = normalizeWatchers(Cstr.watchers);
@@ -4191,8 +4370,14 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4191
4370
  }
4192
4371
  if (BUILD.member) hostRef.$flags$ &= ~HOST_FLAGS.isConstructingInstance;
4193
4372
  endNewInstance();
4194
- if (!(BUILD.slotRelocation && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation)) fireConnectedCallback(hostRef.$lazyInstance$, elm);
4195
- else hostRef.$deferredConnectedCallback$ = true;
4373
+ if (BUILD.asyncLoading && hostRef.$ancestorComponent$) await awaitAncestorConnected(hostRef.$ancestorComponent$);
4374
+ if (!(BUILD.slotRelocation && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation)) {
4375
+ fireConnectedCallback(hostRef.$lazyInstance$, elm);
4376
+ if (BUILD.asyncLoading) markFirstConnected(hostRef);
4377
+ } else queueMicrotask(() => {
4378
+ fireConnectedCallback(hostRef.$lazyInstance$, elm);
4379
+ if (BUILD.asyncLoading) markFirstConnected(hostRef);
4380
+ });
4196
4381
  } else Cstr = elm.constructor;
4197
4382
  if (BUILD.style && Cstr && Cstr.style) {
4198
4383
  /**
@@ -4251,7 +4436,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4251
4436
  hostRef.$onRenderResolve$();
4252
4437
  hostRef.$onRenderResolve$ = void 0;
4253
4438
  }
4254
- if (BUILD.asyncLoading && hostRef.$onReadyResolve$) hostRef.$onReadyResolve$(elm);
4439
+ if (BUILD.asyncLoading) markFirstConnected(hostRef);
4440
+ if (BUILD.asyncLoading && hostRef.$onReadyResolve$ && !(hostRef.$flags$ & HOST_FLAGS.hasFailedLoad)) hostRef.$onReadyResolve$(elm);
4255
4441
  }
4256
4442
  };
4257
4443
  const fireConnectedCallback = (instance, elm) => {
@@ -4314,6 +4500,7 @@ const connectedCallback = (elm) => {
4314
4500
  } else {
4315
4501
  addHostEventListeners(elm, hostRef, cmpMeta.$listeners$);
4316
4502
  if (hostRef?.$lazyInstance$) fireConnectedCallback(hostRef.$lazyInstance$, elm);
4503
+ else if (hostRef.$flags$ & HOST_FLAGS.hasFailedLoad) setTimeout(() => initializeComponent(elm, hostRef, cmpMeta), LAZY_LOAD_RETRY_INTERVAL_MS);
4317
4504
  else if (hostRef?.$onReadyPromise$) hostRef.$onReadyPromise$.then(() => fireConnectedCallback(hostRef.$lazyInstance$, elm));
4318
4505
  }
4319
4506
  endConnected();
@@ -4343,6 +4530,7 @@ const disconnectedCallback = async (elm) => {
4343
4530
  hostRef.$signalCleanup$();
4344
4531
  hostRef.$signalCleanup$ = void 0;
4345
4532
  }
4533
+ if (BUILD.asyncLoading && hostRef && !(hostRef.$flags$ & HOST_FLAGS.hasFiredConnected)) markFirstConnected(hostRef);
4346
4534
  if (!BUILD.lazyLoad) disconnectInstance(elm);
4347
4535
  else if (hostRef?.$lazyInstance$) disconnectInstance(hostRef.$lazyInstance$, elm);
4348
4536
  else if (hostRef?.$onReadyPromise$) hostRef.$onReadyPromise$.then(() => disconnectInstance(hostRef.$lazyInstance$, elm));
@@ -4390,7 +4578,6 @@ const hmrStart = (hostElement, cmpMeta, hmrVersionId) => {
4390
4578
  };
4391
4579
  const hmrStandalone = async (hostElement, cmpMeta, hmrVersionId) => {
4392
4580
  const modulePath = hostElement.constructor.__stencil_module__;
4393
- console.log(`[Stencil HMR] hmrStandalone <${cmpMeta.$tagName$}> modulePath:`, modulePath);
4394
4581
  if (!modulePath) {
4395
4582
  console.warn(`[Stencil HMR] No __stencil_module__ on <${cmpMeta.$tagName$}> constructor - was this built with devMode?`);
4396
4583
  return;
@@ -4403,18 +4590,39 @@ const hmrStandalone = async (hostElement, cmpMeta, hmrVersionId) => {
4403
4590
  const NewClass = Object.values(newModule).find((v) => typeof v === "function" && v.is === cmpMeta.$tagName$) ?? newModule.default;
4404
4591
  if (!NewClass) return;
4405
4592
  const ctor = customElements.get(cmpMeta.$tagName$);
4406
- if (ctor) for (const key of Object.getOwnPropertyNames(NewClass.prototype)) {
4407
- if (key === "constructor") continue;
4408
- Object.defineProperty(ctor.prototype, key, Object.getOwnPropertyDescriptor(NewClass.prototype, key));
4593
+ if (ctor) {
4594
+ for (const key of Object.getOwnPropertyNames(NewClass.prototype)) {
4595
+ if (key === "constructor") continue;
4596
+ Object.defineProperty(ctor.prototype, key, Object.getOwnPropertyDescriptor(NewClass.prototype, key));
4597
+ }
4598
+ const styleDesc = Object.getOwnPropertyDescriptor(NewClass, "style");
4599
+ if (styleDesc) {
4600
+ Object.defineProperty(ctor, "style", styleDesc);
4601
+ const newStyle = NewClass.style;
4602
+ if (newStyle) {
4603
+ const scopeId = getScopeId(cmpMeta);
4604
+ const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4605
+ console.log("[stencil-hmr] registerStyle", {
4606
+ tag: cmpMeta.$tagName$,
4607
+ scopeId,
4608
+ isShadow,
4609
+ cssLen: newStyle.length
4610
+ });
4611
+ registerStyle(scopeId, newStyle, isShadow);
4612
+ }
4613
+ }
4409
4614
  }
4615
+ const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4410
4616
  document.querySelectorAll(cmpMeta.$tagName$).forEach((el) => {
4411
- if (BUILD.hostListener) {
4412
- const hostRef = getHostRef(el);
4413
- if (hostRef?.$rmListeners$) {
4414
- hostRef.$rmListeners$.map((rmListener) => rmListener());
4415
- hostRef.$rmListeners$ = void 0;
4416
- addHostEventListeners(el, hostRef, cmpMeta.$listeners$);
4417
- }
4617
+ const hostRef = getHostRef(el);
4618
+ if (BUILD.hostListener && hostRef?.$rmListeners$) {
4619
+ hostRef.$rmListeners$.map((rmListener) => rmListener());
4620
+ hostRef.$rmListeners$ = void 0;
4621
+ addHostEventListeners(el, hostRef, cmpMeta.$listeners$);
4622
+ }
4623
+ if (!isShadow && hostRef) {
4624
+ console.log("[stencil-hmr] calling attachStyles for", cmpMeta.$tagName$);
4625
+ attachStyles(hostRef);
4418
4626
  }
4419
4627
  forceUpdate(el);
4420
4628
  });
@@ -4425,7 +4633,9 @@ const hmrStandalone = async (hostElement, cmpMeta, hmrVersionId) => {
4425
4633
  //#endregion
4426
4634
  //#region src/runtime/bootstrap-standalone.ts
4427
4635
  const defineCustomElement = (Cstr, compactMeta) => {
4428
- customElements.define(transformTag(compactMeta[1]), proxyCustomElement(Cstr, compactMeta));
4636
+ const tag = transformTag(compactMeta[1]);
4637
+ const proxied = proxyCustomElement(Cstr, compactMeta);
4638
+ if (!customElements.get(tag)) customElements.define(tag, proxied);
4429
4639
  };
4430
4640
  const proxyCustomElement = (Cstr, compactMeta) => {
4431
4641
  if (BUILD.profile && performance.mark && performance.getEntriesByName("st:app:start", "mark").length === 0) performance.mark("st:app:start");
@@ -4446,18 +4656,20 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4446
4656
  hmrStart(this, cmpMeta, hmrVersionId);
4447
4657
  };
4448
4658
  if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && (BUILD.slotCloneNode || BUILD.patchClone && cmpMeta.$flags$ & CMP_FLAGS.patchClone)) patchCloneNode(Cstr.prototype);
4449
- if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) if (BUILD.lightDomPatches || BUILD.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(Cstr.prototype);
4450
- else {
4451
- if (BUILD.slotChildNodes || BUILD.patchChildren && cmpMeta.$flags$ & CMP_FLAGS.patchChildren) patchChildSlotNodes(Cstr.prototype);
4452
- if (BUILD.slotDomMutations || BUILD.patchInsert && cmpMeta.$flags$ & CMP_FLAGS.patchInsert) {
4453
- patchSlotAppendChild(Cstr.prototype);
4454
- patchSlotAppend(Cstr.prototype);
4455
- patchSlotPrepend(Cstr.prototype);
4456
- patchSlotInsertAdjacentHTML(Cstr.prototype);
4457
- patchInsertBefore(Cstr.prototype);
4458
- patchSlotRemoveChild(Cstr.prototype);
4659
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) {
4660
+ if (BUILD.lightDomPatches || BUILD.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(Cstr.prototype);
4661
+ else {
4662
+ if (BUILD.slotChildNodes || BUILD.patchChildren && cmpMeta.$flags$ & CMP_FLAGS.patchChildren) patchChildSlotNodes(Cstr.prototype);
4663
+ if (BUILD.slotDomMutations || BUILD.patchInsert && cmpMeta.$flags$ & CMP_FLAGS.patchInsert) {
4664
+ patchSlotAppendChild(Cstr.prototype);
4665
+ patchSlotAppend(Cstr.prototype);
4666
+ patchSlotPrepend(Cstr.prototype);
4667
+ patchSlotInsertAdjacentHTML(Cstr.prototype);
4668
+ patchInsertBefore(Cstr.prototype);
4669
+ patchSlotRemoveChild(Cstr.prototype);
4670
+ }
4671
+ if (BUILD.slotTextContent) patchTextContent(Cstr.prototype);
4459
4672
  }
4460
- if (BUILD.slotTextContent) patchTextContent(Cstr.prototype);
4461
4673
  }
4462
4674
  if (BUILD.hydrateClientSide && BUILD.shadowDom) hydrateScopedToShadow();
4463
4675
  const originalConnectedCallback = Cstr.prototype.connectedCallback;
@@ -4470,19 +4682,26 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4470
4682
  componentOnReady() {
4471
4683
  return getHostRef(this)?.$onReadyPromise$;
4472
4684
  },
4473
- connectedCallback() {
4474
- if (!this.__hasHostListenerAttached) {
4475
- const hostRef = getHostRef(this);
4685
+ async connectedCallback() {
4686
+ const isFirstConnect = !this.__hasHostListenerAttached;
4687
+ let hostRef;
4688
+ if (isFirstConnect) {
4689
+ hostRef = getHostRef(this);
4476
4690
  if (!hostRef) return;
4477
4691
  addHostEventListeners(this, hostRef, cmpMeta.$listeners$);
4478
4692
  this.__hasHostListenerAttached = true;
4479
4693
  }
4480
4694
  connectedCallback(this);
4481
- if (originalConnectedCallback) originalConnectedCallback.call(this);
4695
+ if (BUILD.asyncLoading && hostRef && hostRef.$ancestorComponent$) {
4696
+ await awaitAncestorConnected(hostRef.$ancestorComponent$);
4697
+ if (!this.isConnected) return;
4698
+ }
4699
+ if (originalConnectedCallback && (plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) originalConnectedCallback.call(this);
4700
+ if (BUILD.asyncLoading && hostRef) markFirstConnected(hostRef);
4482
4701
  },
4483
4702
  disconnectedCallback() {
4484
4703
  disconnectedCallback(this);
4485
- if (originalDisconnectedCallback) originalDisconnectedCallback.call(this);
4704
+ if (originalDisconnectedCallback && (plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) originalDisconnectedCallback.call(this);
4486
4705
  },
4487
4706
  __attachShadow() {
4488
4707
  const isClosed = BUILD.shadowModeClosed && !!(cmpMeta.$flags$ & CMP_FLAGS.shadowModeClosed);
@@ -4536,8 +4755,8 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4536
4755
  const exclude = options.exclude || [];
4537
4756
  const _reg = options.registry ?? getRegistry();
4538
4757
  const head = win.document.head;
4539
- const metaCharset = /* @__PURE__ */ head.querySelector("meta[charset]");
4540
- const dataStyles = /* @__PURE__ */ win.document.createElement("style");
4758
+ const metaCharset = /*@__PURE__*/ head.querySelector("meta[charset]");
4759
+ const dataStyles = /*@__PURE__*/ win.document.createElement("style");
4541
4760
  const deferredConnectedCallbacks = [];
4542
4761
  let appLoadFallback;
4543
4762
  let isBootstrapping = true;
@@ -4605,8 +4824,11 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4605
4824
  *
4606
4825
  * Also remove the reference from `deferredConnectedCallbacks` array
4607
4826
  * otherwise removed instances won't get garbage collected.
4827
+ *
4828
+ * Use `nextTick` (microtask) rather than `plt.raf` since
4829
+ * `requestAnimationFrame` callbacks do not fire while `document.hidden`
4608
4830
  */
4609
- plt.raf(() => {
4831
+ nextTick(() => {
4610
4832
  const hostRef = getHostRef(this);
4611
4833
  if (!hostRef) return;
4612
4834
  const i = deferredConnectedCallbacks.findIndex((host) => host === this);
@@ -4619,18 +4841,20 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4619
4841
  }
4620
4842
  };
4621
4843
  if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && (BUILD.slotCloneNode || BUILD.patchClone && cmpMeta.$flags$ & CMP_FLAGS.patchClone)) patchCloneNode(HostElement.prototype);
4622
- if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) if (BUILD.lightDomPatches || BUILD.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(HostElement.prototype);
4623
- else {
4624
- if (BUILD.slotChildNodes || BUILD.patchChildren && cmpMeta.$flags$ & CMP_FLAGS.patchChildren) patchChildSlotNodes(HostElement.prototype);
4625
- if (BUILD.slotDomMutations || BUILD.patchInsert && cmpMeta.$flags$ & CMP_FLAGS.patchInsert) {
4626
- patchSlotAppendChild(HostElement.prototype);
4627
- patchSlotAppend(HostElement.prototype);
4628
- patchSlotPrepend(HostElement.prototype);
4629
- patchSlotInsertAdjacentHTML(HostElement.prototype);
4630
- patchInsertBefore(HostElement.prototype);
4631
- patchSlotRemoveChild(HostElement.prototype);
4844
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) {
4845
+ if (BUILD.lightDomPatches || BUILD.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(HostElement.prototype);
4846
+ else {
4847
+ if (BUILD.slotChildNodes || BUILD.patchChildren && cmpMeta.$flags$ & CMP_FLAGS.patchChildren) patchChildSlotNodes(HostElement.prototype);
4848
+ if (BUILD.slotDomMutations || BUILD.patchInsert && cmpMeta.$flags$ & CMP_FLAGS.patchInsert) {
4849
+ patchSlotAppendChild(HostElement.prototype);
4850
+ patchSlotAppend(HostElement.prototype);
4851
+ patchSlotPrepend(HostElement.prototype);
4852
+ patchSlotInsertAdjacentHTML(HostElement.prototype);
4853
+ patchInsertBefore(HostElement.prototype);
4854
+ patchSlotRemoveChild(HostElement.prototype);
4855
+ }
4856
+ if (BUILD.slotTextContent) patchTextContent(HostElement.prototype);
4632
4857
  }
4633
- if (BUILD.slotTextContent) patchTextContent(HostElement.prototype);
4634
4858
  }
4635
4859
  if (BUILD.formAssociated && cmpMeta.$flags$ & CMP_FLAGS.formAssociated) HostElement.formAssociated = true;
4636
4860
  if (BUILD.hotModuleReplacement) HostElement.prototype["s-hmr"] = function(hmrVersionId) {
@@ -4676,9 +4900,10 @@ const addHostEventListeners = (elm, hostRef, listeners) => {
4676
4900
  };
4677
4901
  const hostListenerProxy = (hostRef, methodName) => (ev) => {
4678
4902
  try {
4679
- if (BUILD.lazyLoad) if (hostRef.$flags$ & HOST_FLAGS.isListenReady) hostRef.$lazyInstance$?.[methodName](ev);
4680
- else (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
4681
- else hostRef.$hostElement$[methodName](ev);
4903
+ if (BUILD.lazyLoad) {
4904
+ if (hostRef.$flags$ & HOST_FLAGS.isListenReady) hostRef.$lazyInstance$?.[methodName](ev);
4905
+ else (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
4906
+ } else hostRef.$hostElement$[methodName](ev);
4682
4907
  } catch (e) {
4683
4908
  consoleError(e, hostRef.$hostElement$);
4684
4909
  }
@@ -4712,6 +4937,73 @@ const setNonce = (nonce) => plt.$nonce$ = nonce;
4712
4937
  //#region src/runtime/platform-options.ts
4713
4938
  const setPlatformOptions = (opts) => Object.assign(plt, opts);
4714
4939
  //#endregion
4940
+ //#region src/runtime/reactive-controller.ts
4941
+ const ReactiveControllerHost = (Base) => class ReactiveControllerHostMixin extends Base {
4942
+ controllers = /* @__PURE__ */ new Set();
4943
+ #connected = false;
4944
+ #updateCompleteResolvers = [];
4945
+ addController(controller) {
4946
+ this.controllers.add(controller);
4947
+ if (this.#connected) controller.hostConnected?.();
4948
+ }
4949
+ removeController(controller) {
4950
+ this.controllers.delete(controller);
4951
+ }
4952
+ requestUpdate() {
4953
+ forceUpdate(this);
4954
+ }
4955
+ get updateComplete() {
4956
+ return new Promise((resolve) => this.#updateCompleteResolvers.push(resolve));
4957
+ }
4958
+ connectedCallback() {
4959
+ super.connectedCallback?.();
4960
+ this.#connected = true;
4961
+ const el = getElement(this);
4962
+ if (el && el !== this) {
4963
+ el.addController = (controller) => this.addController(controller);
4964
+ el.removeController = (controller) => this.removeController(controller);
4965
+ el.requestUpdate = () => this.requestUpdate();
4966
+ Object.defineProperty(el, "updateComplete", {
4967
+ configurable: true,
4968
+ get: () => this.updateComplete
4969
+ });
4970
+ }
4971
+ this.controllers.forEach((c) => c.hostConnected?.());
4972
+ }
4973
+ disconnectedCallback() {
4974
+ super.disconnectedCallback?.();
4975
+ this.#connected = false;
4976
+ this.controllers.forEach((c) => c.hostDisconnected?.());
4977
+ }
4978
+ async componentWillLoad() {
4979
+ await super.componentWillLoad?.();
4980
+ await Promise.all([...this.controllers].map((c) => c.hostWillLoad?.()));
4981
+ }
4982
+ componentDidLoad() {
4983
+ super.componentDidLoad?.();
4984
+ this.controllers.forEach((c) => c.hostDidLoad?.());
4985
+ }
4986
+ async componentWillRender() {
4987
+ await super.componentWillRender?.();
4988
+ await Promise.all([...this.controllers].map((c) => c.hostWillRender?.()));
4989
+ }
4990
+ componentDidRender() {
4991
+ super.componentDidRender?.();
4992
+ this.controllers.forEach((c) => c.hostDidRender?.());
4993
+ const resolvers = this.#updateCompleteResolvers;
4994
+ this.#updateCompleteResolvers = [];
4995
+ resolvers.forEach((resolve) => resolve(true));
4996
+ }
4997
+ async componentWillUpdate() {
4998
+ await super.componentWillUpdate?.();
4999
+ await Promise.all([...this.controllers].map((c) => c.hostWillUpdate?.()));
5000
+ }
5001
+ componentDidUpdate() {
5002
+ super.componentDidUpdate?.();
5003
+ this.controllers.forEach((c) => c.hostDidUpdate?.());
5004
+ }
5005
+ };
5006
+ //#endregion
4715
5007
  //#region src/runtime/render.ts
4716
5008
  /**
4717
5009
  * A WeakMap to persist HostRef objects across multiple render() calls to the
@@ -4798,159 +5090,4 @@ function hasKeys(obj) {
4798
5090
  return false;
4799
5091
  }
4800
5092
  //#endregion
4801
- //#region src/runtime/vdom/vdom-annotations.ts
4802
- /**
4803
- * Updates the DOM generated on the server with annotations such as node attributes and
4804
- * comment nodes to facilitate future client-side hydration. These annotations are used for things
4805
- * like moving elements back to their original hosts if using Shadow DOM on the client, and for quickly
4806
- * reconstructing the vNode representations of the DOM.
4807
- *
4808
- * @param doc The DOM generated by the server.
4809
- * @param staticComponents Any components that should be considered static and do not need client-side hydration.
4810
- */
4811
- const insertVdomAnnotations = (doc, staticComponents) => {
4812
- if (doc != null) {
4813
- /**
4814
- * Initiated `docData` object from the document if it exists to ensure we
4815
- * maintain the same `docData` object across multiple hydration hydration runs.
4816
- */
4817
- const docData = "_stencilDocData" in doc ? doc[STENCIL_DOC_DATA] : { ...DEFAULT_DOC_DATA };
4818
- docData.staticComponents = new Set(staticComponents);
4819
- const orgLocationNodes = [];
4820
- parseVNodeAnnotations(doc, doc.body, docData, orgLocationNodes);
4821
- orgLocationNodes.forEach((orgLocationNode) => {
4822
- if (orgLocationNode != null && orgLocationNode["s-nr"]) {
4823
- const nodeRef = orgLocationNode["s-nr"];
4824
- let hostId = nodeRef["s-host-id"];
4825
- let nodeId = nodeRef["s-node-id"];
4826
- let childId = `${hostId}.${nodeId}`;
4827
- if (hostId == null) {
4828
- hostId = 0;
4829
- docData.rootLevelIds++;
4830
- nodeId = docData.rootLevelIds;
4831
- childId = `${hostId}.${nodeId}`;
4832
- if (nodeRef.nodeType === NODE_TYPE.ElementNode) {
4833
- nodeRef.setAttribute(HYDRATE_CHILD_ID, childId);
4834
- if (typeof nodeRef["s-sn"] === "string" && !nodeRef.getAttribute("slot")) nodeRef.setAttribute("s-sn", nodeRef["s-sn"]);
4835
- } else if (nodeRef.nodeType === NODE_TYPE.TextNode) {
4836
- if (hostId === 0) {
4837
- if (nodeRef.nodeValue?.trim() === "") {
4838
- orgLocationNode.remove();
4839
- return;
4840
- }
4841
- }
4842
- const commentBeforeTextNode = doc.createComment(childId);
4843
- commentBeforeTextNode.nodeValue = `t.${childId}`;
4844
- insertBefore(nodeRef.parentNode, commentBeforeTextNode, nodeRef);
4845
- } else if (nodeRef.nodeType === NODE_TYPE.CommentNode) {
4846
- const commentBeforeTextNode = doc.createComment(childId);
4847
- commentBeforeTextNode.nodeValue = `c.${childId}`;
4848
- nodeRef.parentNode.insertBefore(commentBeforeTextNode, nodeRef);
4849
- }
4850
- }
4851
- let orgLocationNodeId = `o.${childId}`;
4852
- const orgLocationParentNode = orgLocationNode.parentElement;
4853
- if (orgLocationParentNode) {
4854
- if (orgLocationParentNode["s-en"] === "") orgLocationNodeId += `.`;
4855
- else if (orgLocationParentNode["s-en"] === "c") orgLocationNodeId += `.c`;
4856
- }
4857
- orgLocationNode.nodeValue = orgLocationNodeId;
4858
- }
4859
- });
4860
- }
4861
- };
4862
- /**
4863
- * Recursively parses a node generated by the server and its children to set host and child id
4864
- * attributes read during client-side hydration. This function also tracks whether each node is
4865
- * an original location reference node meaning that a node has been moved via slot relocation.
4866
- *
4867
- * @param doc The DOM generated by the server.
4868
- * @param node The node to parse.
4869
- * @param docData An object containing metadata about the document.
4870
- * @param orgLocationNodes An array of nodes that have been moved via slot relocation.
4871
- */
4872
- const parseVNodeAnnotations = (doc, node, docData, orgLocationNodes) => {
4873
- if (node == null) return;
4874
- if (node["s-nr"] != null) orgLocationNodes.push(node);
4875
- if (node.nodeType === NODE_TYPE.ElementNode) [...Array.from(node.childNodes), ...Array.from(node.shadowRoot?.childNodes || [])].forEach((childNode) => {
4876
- const hostRef = getHostRef(childNode);
4877
- if (hostRef != null && !docData.staticComponents.has(childNode.nodeName.toLowerCase())) insertVNodeAnnotations(doc, childNode, hostRef.$vnode$, docData, { nodeIds: 0 });
4878
- parseVNodeAnnotations(doc, childNode, docData, orgLocationNodes);
4879
- });
4880
- };
4881
- /**
4882
- * Insert attribute annotations on an element for its host ID and, potentially, its child ID.
4883
- * Also makes calls to insert annotations on the element's children, keeping track of the depth of
4884
- * the component tree.
4885
- *
4886
- * @param doc The DOM generated by the server.
4887
- * @param hostElm The element to insert annotations for.
4888
- * @param vnode The vNode representation of the element.
4889
- * @param docData An object containing metadata about the document.
4890
- * @param cmpData An object containing metadata about the component.
4891
- */
4892
- const insertVNodeAnnotations = (doc, hostElm, vnode, docData, cmpData) => {
4893
- if (vnode != null) {
4894
- const hostId = ++docData.hostIds;
4895
- hostElm.setAttribute(HYDRATE_ID, hostId);
4896
- if (hostElm["s-cr"] != null) hostElm["s-cr"].nodeValue = `r.${hostId}`;
4897
- if (vnode.$children$ != null) {
4898
- const depth = 0;
4899
- vnode.$children$.forEach((vnodeChild, index) => {
4900
- insertChildVNodeAnnotations(doc, vnodeChild, cmpData, hostId, depth, index);
4901
- });
4902
- }
4903
- if (hostElm && vnode && vnode.$elm$ && !hostElm.hasAttribute("c-id")) {
4904
- const parent = hostElm.parentElement;
4905
- if (parent && parent.childNodes) {
4906
- const parentChildNodes = Array.from(parent.childNodes);
4907
- const comment = parentChildNodes.find((node) => node.nodeType === NODE_TYPE.CommentNode && node["s-sr"]);
4908
- if (comment) {
4909
- const index = parentChildNodes.indexOf(hostElm) - 1;
4910
- vnode.$elm$.setAttribute(HYDRATE_CHILD_ID, `${comment["s-host-id"]}.${comment["s-node-id"]}.0.${index}`);
4911
- }
4912
- }
4913
- }
4914
- }
4915
- };
4916
- /**
4917
- * Recursively analyzes the type of a child vNode and inserts annotations on the vNodes's element based on its type.
4918
- * Element nodes receive a child ID attribute, text nodes have a comment with the child ID inserted before them,
4919
- * and comment nodes representing a slot have their node value set to a slot node ID containing the child ID.
4920
- *
4921
- * @param doc The DOM generated by the server.
4922
- * @param vnodeChild The vNode to insert annotations for.
4923
- * @param cmpData An object containing metadata about the component.
4924
- * @param hostId The host ID of this element's parent.
4925
- * @param depth How deep this element sits in the component tree relative to its parent.
4926
- * @param index The index of this element in its parent's children array.
4927
- */
4928
- const insertChildVNodeAnnotations = (doc, vnodeChild, cmpData, hostId, depth, index) => {
4929
- const childElm = vnodeChild.$elm$;
4930
- if (childElm == null) return;
4931
- const nodeId = cmpData.nodeIds++;
4932
- const childId = `${hostId}.${nodeId}.${depth}.${index}`;
4933
- childElm["s-host-id"] = hostId;
4934
- childElm["s-node-id"] = nodeId;
4935
- if (childElm.nodeType === NODE_TYPE.ElementNode) {
4936
- childElm.setAttribute(HYDRATE_CHILD_ID, childId);
4937
- if (typeof childElm["s-sn"] === "string" && !childElm.getAttribute("slot")) childElm.setAttribute("s-sn", childElm["s-sn"]);
4938
- } else if (childElm.nodeType === NODE_TYPE.TextNode) {
4939
- const parentNode = childElm.parentNode;
4940
- const nodeName = parentNode?.nodeName;
4941
- if (nodeName !== "STYLE" && nodeName !== "SCRIPT") {
4942
- const textNodeId = `t.${childId}`;
4943
- insertBefore(parentNode, doc.createComment(textNodeId), childElm);
4944
- }
4945
- } else if (childElm.nodeType === NODE_TYPE.CommentNode) {
4946
- if (childElm["s-sr"]) childElm.nodeValue = `s.${childId}.${childElm["s-sn"] || ""}`;
4947
- }
4948
- if (vnodeChild.$children$ != null) {
4949
- const childDepth = depth + 1;
4950
- vnodeChild.$children$.forEach((vnode, childIndex) => {
4951
- insertChildVNodeAnnotations(doc, vnode, cmpData, hostId, childDepth, childIndex);
4952
- });
4953
- }
4954
- };
4955
- //#endregion
4956
- export { Fragment, HYDRATED_STYLE_ID, Host, Mixin, addHostEventListeners, bootstrapLazy, connectedCallback, createEvent, defineCustomElement, disconnectedCallback, forceModeUpdate, forceUpdate, getAssetPath, getElement, getMode, getRegistry, getRenderingRef, getShadowRoot, getValue, h, insertVdomAnnotations, jsx, jsxDEV, jsxs, normalizeWatchers, parsePropertyValue, postUpdateComponent, proxyComponent, proxyCustomElement, render, renderVdom, setAssetPath, setMode, setNonce, setPlatformOptions, setRegistry, setTagTransformer, setValue, transformTag };
5093
+ export { Fragment, HYDRATED_STYLE_ID, Host, Mixin, ReactiveControllerHost, addHostEventListeners, bootstrapLazy, connectedCallback, createEvent, defineCustomElement, disconnectedCallback, forceModeUpdate, forceUpdate, getAssetPath, getElement, getMode, getRegistry, getRenderingRef, getShadowRoot, getValue, h, jsx, jsxDEV, jsxs, normalizeWatchers, parsePropertyValue, postUpdateComponent, proxyComponent, proxyCustomElement, render, setAssetPath, setMode, setNonce, setPlatformOptions, setRegistry, setTagTransformer, setValue, transformTag };