@stencil/core 5.0.0-alpha.27 → 5.0.0-alpha.29

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 (44) hide show
  1. package/dist/app-data/index.d.ts +1 -1
  2. package/dist/{client-CvcvHKz4.mjs → client-D1MsT-Rp.mjs} +373 -238
  3. package/dist/compiler/index.d.mts +2 -3
  4. package/dist/compiler/index.mjs +3 -3
  5. package/dist/compiler/utils/index.d.mts +272 -2
  6. package/dist/compiler/utils/index.mjs +4 -3
  7. package/dist/{compiler-D43Ied7R.mjs → compiler-BbS9TDF_.mjs} +1845 -1118
  8. package/dist/declarations/stencil-ext-modules.d.ts +5 -5
  9. package/dist/declarations/stencil-public-compiler.d.ts +108 -40
  10. package/dist/declarations/stencil-public-docs.d.ts +9 -0
  11. package/dist/declarations/stencil-public-runtime.d.ts +81 -6
  12. package/dist/fragment-Di1hWOC8.mjs +4 -0
  13. package/dist/{index-F3IidHM1.d.mts → index-BHj3EBl2.d.mts} +395 -312
  14. package/dist/{index-xAkMgLX_.d.ts → index-D2PAsXxx.d.ts} +133 -9
  15. package/dist/index-VK8okIiF.d.mts +108 -0
  16. package/dist/index.d.mts +4 -0
  17. package/dist/index.mjs +91 -2
  18. package/dist/jsx-runtime.mjs +2 -1
  19. package/dist/{node-DKVq_Ud0.mjs → node-BQR4L-TG.mjs} +60 -58
  20. package/dist/reactive-controller-BdCpSAQP.d.mts +13 -0
  21. package/dist/{regular-expression-CFVJOTUh.mjs → regular-expression-XqU5zmPp.mjs} +20 -3
  22. package/dist/{chunk-z9aeyW2b.mjs → rolldown-runtime-BhDjJH2R.mjs} +1 -1
  23. package/dist/runtime/client/lazy.js +411 -165
  24. package/dist/runtime/client/runtime.d.ts +136 -9
  25. package/dist/runtime/client/runtime.js +411 -165
  26. package/dist/runtime/index.d.ts +5 -3
  27. package/dist/runtime/index.js +410 -163
  28. package/dist/runtime/server/index.d.mts +80 -8
  29. package/dist/runtime/server/index.mjs +333 -158
  30. package/dist/runtime/server/runner.d.mts +3 -0
  31. package/dist/runtime/server/runner.mjs +232 -308
  32. package/dist/signals/index.d.ts +2 -0
  33. package/dist/sys/node/index.d.mts +1 -2
  34. package/dist/sys/node/index.mjs +1 -1
  35. package/dist/sys/node/worker.d.mts +1 -1
  36. package/dist/sys/node/worker.mjs +6 -3
  37. package/dist/testing/index.d.mts +4 -9
  38. package/dist/testing/index.mjs +74 -56
  39. package/dist/util-BIa-iHnt.mjs +724 -0
  40. package/dist/validation-Dd3g77T5.mjs +778 -0
  41. package/package.json +27 -27
  42. package/dist/index-3fu7WQs4.d.mts +0 -205
  43. package/dist/validation-ByxKj8bC.mjs +0 -1458
  44. /package/{LICENSE.md → LICENSE} +0 -0
@@ -138,8 +138,20 @@ const HOST_FLAGS = {
138
138
  isWatchReady: 128,
139
139
  isListenReady: 256,
140
140
  needsRerender: 512,
141
- devOnRender: 1024,
142
- devOnDidLoad: 2048
141
+ /**
142
+ * Set once this component's real (lazy-loaded) `connectedCallback` has fired for
143
+ * the first time. Lets a descendant skip creating/awaiting a connect-promise for
144
+ * an ancestor that's already connected. See {@link HostRef.$onFirstConnectResolve$}.
145
+ */
146
+ hasFiredConnected: 1024,
147
+ /**
148
+ * Set when a lazy component's dynamic `import()` fails to resolve a
149
+ * constructor. Distinct from `hasInitializedComponent` being unset, which
150
+ * is true while an initialization attempt is merely queued/in-flight.
151
+ */
152
+ hasFailedLoad: 2048,
153
+ devOnRender: 4096,
154
+ devOnDidLoad: 8192
143
155
  };
144
156
  const CF_scopedCssEncapsulation = 2;
145
157
  /**
@@ -371,8 +383,13 @@ const registerHost = (hostElement, cmpMeta) => {
371
383
  if (BUILD$1.asyncLoading) {
372
384
  hostRef.$onReadyPromise$ = new Promise((r) => hostRef.$onReadyResolve$ = r);
373
385
  hostElement["s-rp"] = hostRef.$onReadyPromise$;
386
+ if (!BUILD$1.lazyLoad) {
387
+ hostRef.$onFirstConnectPromise$ = new Promise((r) => hostRef.$onFirstConnectResolve$ = r);
388
+ hostElement["s-fc"] = hostRef.$onFirstConnectPromise$;
389
+ }
374
390
  if (!hostElement["s-p"]) hostElement["s-p"] = [];
375
391
  if (!hostElement["s-rc"]) hostElement["s-rc"] = [];
392
+ if (!hostElement["s-pc"]) hostElement["s-pc"] = [];
376
393
  }
377
394
  if (BUILD$1.lazyLoad) hostRef.$fetchedCbList$ = [];
378
395
  const ref = hostRef;
@@ -392,7 +409,12 @@ const consoleDevInfo = (...m) => console.info(...STENCIL_DEV_MODE, ...m);
392
409
  const setErrorHandler = (handler) => customError = handler;
393
410
  //#endregion
394
411
  //#region src/client/client-load-module.ts
395
- const cmpModules = /* @__PURE__ */ new Map();
412
+ const cmpModules = /*@__PURE__*/ new Map();
413
+ /**
414
+ * Tracks how many times a dynamic `import()` for a given lazy bundle has failed.
415
+ * Used to cache bust the retry attempt in connected-callback.ts
416
+ */
417
+ const failedLoadAttempts = /*@__PURE__*/ new Map();
396
418
  /**
397
419
  * We need to separate out this prefix so that Esbuild doesn't try to resolve
398
420
  * the below, but instead retains a dynamic `import()` statement in the
@@ -423,13 +445,21 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
423
445
  } else if (!bundleId) return;
424
446
  const module = !BUILD$1.hotModuleReplacement ? cmpModules.get(bundleId) : false;
425
447
  if (module) return module[exportName];
448
+ const retryCount = failedLoadAttempts.get(bundleId) ?? 0;
449
+ const cacheBustParams = [retryCount > 0 ? `s-retry=${retryCount}` : "", BUILD$1.hotModuleReplacement && hmrVersionId ? `s-hmr=${hmrVersionId}` : ""].filter(Boolean).join("&");
426
450
  /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
427
- const entryFile = `${bundleId}.entry.js${BUILD$1.hotModuleReplacement && hmrVersionId ? "?s-hmr=" + hmrVersionId : ""}`;
451
+ const entryFile = `${bundleId}.entry.js${cacheBustParams ? "?" + cacheBustParams : ""}`;
428
452
  const onLoad = (importedModule) => {
429
- if (!BUILD$1.hotModuleReplacement) cmpModules.set(bundleId, importedModule);
453
+ if (!BUILD$1.hotModuleReplacement) {
454
+ failedLoadAttempts.delete(bundleId);
455
+ cmpModules.set(bundleId, importedModule);
456
+ }
430
457
  return importedModule[exportName];
431
458
  };
432
- const onError = (e) => consoleError(e, hostRef.$hostElement$);
459
+ const onError = (e) => {
460
+ failedLoadAttempts.set(bundleId, retryCount + 1);
461
+ consoleError(e, hostRef.$hostElement$);
462
+ };
433
463
  if (lazyLoadBasePath) return import(
434
464
  /* @vite-ignore */
435
465
  /* webpackInclude: /\.entry\.js$/ */
@@ -447,7 +477,7 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
447
477
  };
448
478
  //#endregion
449
479
  //#region src/client/client-style.ts
450
- const styles = /* @__PURE__ */ new Map();
480
+ const styles = /*@__PURE__*/ new Map();
451
481
  const modeResolutionChain = [];
452
482
  const setScopedSsr = (_opts) => {};
453
483
  const needsScopedSSR = () => false;
@@ -510,6 +540,10 @@ const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
510
540
  */
511
541
  const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
512
542
  const XLINK_NS = "http://www.w3.org/1999/xlink";
543
+ /**
544
+ * Minimum delay, in milliseconds, before retrying a failed lazy component load.
545
+ */
546
+ const LAZY_LOAD_RETRY_INTERVAL_MS = 1e3;
513
547
  const FORM_ASSOCIATED_CUSTOM_ELEMENT_CALLBACKS = [
514
548
  "formAssociatedCallback",
515
549
  "formResetCallback",
@@ -532,7 +566,7 @@ const plt = {
532
566
  const setPlatformHelpers = (helpers) => {
533
567
  Object.assign(plt, helpers);
534
568
  };
535
- const supportsListenerOptions = /* @__PURE__ */ (() => {
569
+ const supportsListenerOptions = /*@__PURE__*/ (() => {
536
570
  let supported = false;
537
571
  try {
538
572
  win.document?.addEventListener("e", null, Object.defineProperty({}, "passive", { get() {
@@ -542,14 +576,14 @@ const supportsListenerOptions = /* @__PURE__ */ (() => {
542
576
  return supported;
543
577
  })();
544
578
  const promiseResolve = (v) => Promise.resolve(v);
545
- const supportsConstructableStylesheets = BUILD$1.constructableCSS ? /* @__PURE__ */ (() => {
579
+ const supportsConstructableStylesheets = BUILD$1.constructableCSS ? /*@__PURE__*/ (() => {
546
580
  try {
547
581
  if (!win.document.adoptedStyleSheets) return false;
548
582
  return typeof new CSSStyleSheet().replaceSync === "function";
549
583
  } catch {}
550
584
  return false;
551
585
  })() : false;
552
- const supportsMutableAdoptedStyleSheets = supportsConstructableStylesheets ? /* @__PURE__ */ (() => !!win.document && Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, "length").writable)() : false;
586
+ const supportsMutableAdoptedStyleSheets = supportsConstructableStylesheets ? /*@__PURE__*/ (() => !!win.document && Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, "length").writable)() : false;
553
587
  //#endregion
554
588
  //#region src/client/client-task-queue.ts
555
589
  let queueCongestion = 0;
@@ -557,12 +591,13 @@ let queuePending = false;
557
591
  const queueDomReads = [];
558
592
  const queueDomWrites = [];
559
593
  const queueDomWritesLow = [];
594
+ const scheduleFlush = () => win.document?.hidden ? nextTick(flush) : plt.raf(flush);
560
595
  const queueTask = (queue, write) => (cb) => {
561
596
  queue.push(cb);
562
597
  if (!queuePending) {
563
598
  queuePending = true;
564
599
  if (write && plt.$flags$ & PLATFORM_FLAGS.queueSync) nextTick(flush);
565
- else plt.raf(flush);
600
+ else scheduleFlush();
566
601
  }
567
602
  };
568
603
  const consume = (queue) => {
@@ -595,16 +630,16 @@ const flush = () => {
595
630
  queueDomWritesLow.push(...queueDomWrites);
596
631
  queueDomWrites.length = 0;
597
632
  }
598
- if (queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0) plt.raf(flush);
633
+ if (queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0) scheduleFlush();
599
634
  else queueCongestion = 0;
600
635
  } else {
601
636
  consume(queueDomWrites);
602
- if (queuePending = queueDomReads.length > 0) plt.raf(flush);
637
+ if (queuePending = queueDomReads.length > 0) scheduleFlush();
603
638
  }
604
639
  };
605
640
  const nextTick = (cb) => promiseResolve().then(cb);
606
- const readTask = /* @__PURE__ */ queueTask(queueDomReads, false);
607
- const writeTask = /* @__PURE__ */ queueTask(queueDomWrites, true);
641
+ const readTask = /*@__PURE__*/ queueTask(queueDomReads, false);
642
+ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
608
643
  //#endregion
609
644
  //#region src/runtime/asset-path.ts
610
645
  const getAssetPath = (path) => {
@@ -644,9 +679,10 @@ function createShadowRoot(cmpMeta) {
644
679
  const shadowRoot = this.attachShadow(opts);
645
680
  if (BUILD$1.shadowModeClosed && isClosed) this.__shadowRoot = shadowRoot;
646
681
  if (globalStyleSheet === void 0) globalStyleSheet = createStyleSheetIfNeededAndSupported(globalStyles) ?? null;
647
- if (globalStyleSheet) if (supportsMutableAdoptedStyleSheets) shadowRoot.adoptedStyleSheets.push(globalStyleSheet);
648
- else shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, globalStyleSheet];
649
- else if (globalStyles && !supportsConstructableStylesheets) {
682
+ if (globalStyleSheet) {
683
+ if (supportsMutableAdoptedStyleSheets) shadowRoot.adoptedStyleSheets.push(globalStyleSheet);
684
+ else shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, globalStyleSheet];
685
+ } else if (globalStyles && !supportsConstructableStylesheets) {
650
686
  const styleElm = document.createElement("style");
651
687
  styleElm.innerHTML = globalStyles;
652
688
  if (BUILD$1.hotModuleReplacement) styleElm.setAttribute(HYDRATED_STYLE_ID, GLOBAL_STYLE_ID);
@@ -671,8 +707,10 @@ function createShadowRoot(cmpMeta) {
671
707
  const updateFallbackSlotVisibility = (elm) => {
672
708
  const childNodes = internalCall(elm, "childNodes");
673
709
  if (elm.tagName && elm.tagName.includes("-") && elm["s-cr"] && elm.tagName !== "SLOT-FB") getHostSlotNodes(childNodes, elm.tagName).forEach((slotNode) => {
674
- if (slotNode.nodeType === NODE_TYPE.ElementNode && slotNode.tagName === "SLOT-FB") if (getSlotChildSiblings(slotNode, getSlotName(slotNode), false).length) slotNode.hidden = true;
675
- else slotNode.hidden = false;
710
+ if (slotNode.nodeType === NODE_TYPE.ElementNode && slotNode.tagName === "SLOT-FB") {
711
+ if (getSlotChildSiblings(slotNode, getSlotName(slotNode), false).length) slotNode.hidden = true;
712
+ else slotNode.hidden = false;
713
+ }
676
714
  });
677
715
  let i = 0;
678
716
  for (i = 0; i < childNodes.length; i++) {
@@ -715,7 +753,7 @@ function getHostSlotNodes(childNodes, hostName, slotName) {
715
753
  slottedNodes.push(childNode);
716
754
  if (typeof slotName !== "undefined") return slottedNodes;
717
755
  }
718
- slottedNodes = [...slottedNodes, ...getHostSlotNodes(childNode.childNodes, hostName, slotName)];
756
+ slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
719
757
  }
720
758
  return slottedNodes;
721
759
  }
@@ -746,7 +784,7 @@ const isNodeLocatedInSlot = (nodeToRelocate, slotName) => {
746
784
  if (nodeToRelocate.getAttribute("slot") === slotName) return true;
747
785
  return false;
748
786
  }
749
- if (nodeToRelocate["s-sn"] === slotName) return true;
787
+ if (typeof nodeToRelocate["s-sa"] === "string") return nodeToRelocate["s-sa"] === slotName;
750
788
  return slotName === "";
751
789
  };
752
790
  /**
@@ -795,8 +833,10 @@ function patchSlotNode(node) {
795
833
  const assignedFactory = (elementsOnly) => function(opts) {
796
834
  const toReturn = [];
797
835
  const slotName = this["s-sn"];
798
- if (opts?.flatten) if (BUILD$1.isDev) console.error("Flattening is not supported for Stencil non-shadow slots. You can use `.childNodes` for nested slot fallback content.");
799
- else console.error("Flattening not supported for Stencil non-shadow slots");
836
+ if (opts?.flatten) {
837
+ if (BUILD$1.isDev) console.error("Flattening is not supported for Stencil non-shadow slots. You can use `.childNodes` for nested slot fallback content.");
838
+ else console.error("Flattening not supported for Stencil non-shadow slots");
839
+ }
800
840
  const parent = this["s-cr"].parentElement;
801
841
  (parent.__childNodes ? parent.childNodes : getSlottedChildNodes(parent.childNodes)).forEach((n) => {
802
842
  if (slotName === getSlotName(n)) toReturn.push(n);
@@ -887,8 +927,10 @@ const patchCloneNode = (HostElementPrototype) => {
887
927
  for (; i < childNodes.length; i++) {
888
928
  slotted = childNodes[i]["s-nr"];
889
929
  nonStencilNode = stencilPrivates.every((privateField) => !childNodes[i][privateField]);
890
- if (slotted) if (clonedNode.__appendChild) clonedNode.__appendChild(slotted.cloneNode(true));
891
- else clonedNode.appendChild(slotted.cloneNode(true));
930
+ if (slotted) {
931
+ if (clonedNode.__appendChild) clonedNode.__appendChild(slotted.cloneNode(true));
932
+ else clonedNode.appendChild(slotted.cloneNode(true));
933
+ }
892
934
  if (nonStencilNode) clonedNode.appendChild(childNodes[i].cloneNode(true));
893
935
  }
894
936
  }
@@ -1091,11 +1133,11 @@ const patchChildSlotNodes = (elm) => {
1091
1133
  } });
1092
1134
  patchHostOriginalAccessor("firstChild", elm);
1093
1135
  Object.defineProperty(elm, "firstChild", { get() {
1094
- return this.childNodes[0];
1136
+ return this.childNodes[0] || null;
1095
1137
  } });
1096
1138
  patchHostOriginalAccessor("lastChild", elm);
1097
1139
  Object.defineProperty(elm, "lastChild", { get() {
1098
- return this.childNodes[this.childNodes.length - 1];
1140
+ return this.childNodes[this.childNodes.length - 1] || null;
1099
1141
  } });
1100
1142
  patchHostOriginalAccessor("childNodes", elm);
1101
1143
  Object.defineProperty(elm, "childNodes", { get() {
@@ -1141,7 +1183,7 @@ const patchNextSibling = (node) => {
1141
1183
  Object.defineProperty(node, "nextSibling", { get: function() {
1142
1184
  const parentNodes = this["s-ol"]?.parentNode.childNodes;
1143
1185
  const index = parentNodes?.indexOf(this);
1144
- if (parentNodes && index > -1) return parentNodes[index + 1];
1186
+ if (parentNodes && index > -1) return parentNodes[index + 1] || null;
1145
1187
  return this.__nextSibling;
1146
1188
  } });
1147
1189
  };
@@ -1156,7 +1198,7 @@ const patchNextElementSibling = (element) => {
1156
1198
  Object.defineProperty(element, "nextElementSibling", { get: function() {
1157
1199
  const parentEles = this["s-ol"]?.parentNode.children;
1158
1200
  const index = parentEles?.indexOf(this);
1159
- if (parentEles && index > -1) return parentEles[index + 1];
1201
+ if (parentEles && index > -1) return parentEles[index + 1] || null;
1160
1202
  return this.__nextElementSibling;
1161
1203
  } });
1162
1204
  };
@@ -1171,7 +1213,7 @@ const patchPreviousSibling = (node) => {
1171
1213
  Object.defineProperty(node, "previousSibling", { get: function() {
1172
1214
  const parentNodes = this["s-ol"]?.parentNode.childNodes;
1173
1215
  const index = parentNodes?.indexOf(this);
1174
- if (parentNodes && index > -1) return parentNodes[index - 1];
1216
+ if (parentNodes && index > -1) return parentNodes[index - 1] || null;
1175
1217
  return this.__previousSibling;
1176
1218
  } });
1177
1219
  };
@@ -1186,7 +1228,7 @@ const patchPreviousElementSibling = (element) => {
1186
1228
  Object.defineProperty(element, "previousElementSibling", { get: function() {
1187
1229
  const parentNodes = this["s-ol"]?.parentNode.children;
1188
1230
  const index = parentNodes?.indexOf(this);
1189
- if (parentNodes && index > -1) return parentNodes[index - 1];
1231
+ if (parentNodes && index > -1) return parentNodes[index - 1] || null;
1190
1232
  return this.__previousElementSibling;
1191
1233
  } });
1192
1234
  };
@@ -1361,7 +1403,7 @@ function queryNonceMetaTagContent(doc) {
1361
1403
  }
1362
1404
  //#endregion
1363
1405
  //#region src/runtime/styles.ts
1364
- const rootAppliedStyles = /* @__PURE__ */ new WeakMap();
1406
+ const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
1365
1407
  /**
1366
1408
  * Get or initialize the set of applied style scope IDs for a container element.
1367
1409
  *
@@ -1385,9 +1427,10 @@ const getAppliedStyles = (container) => {
1385
1427
  * @param prepend if true, add to beginning; if false, add to end
1386
1428
  */
1387
1429
  const adoptStylesheet = (container, sheet, prepend = false) => {
1388
- if (supportsMutableAdoptedStyleSheets) if (prepend) container.adoptedStyleSheets.unshift(sheet);
1389
- else container.adoptedStyleSheets.push(sheet);
1390
- else if (prepend) container.adoptedStyleSheets = [sheet, ...container.adoptedStyleSheets];
1430
+ if (supportsMutableAdoptedStyleSheets) {
1431
+ if (prepend) container.adoptedStyleSheets.unshift(sheet);
1432
+ else container.adoptedStyleSheets.push(sheet);
1433
+ } else if (prepend) container.adoptedStyleSheets = [sheet, ...container.adoptedStyleSheets];
1391
1434
  else container.adoptedStyleSheets = [...container.adoptedStyleSheets, sheet];
1392
1435
  };
1393
1436
  /**
@@ -1400,7 +1443,7 @@ const adoptStylesheet = (container, sheet, prepend = false) => {
1400
1443
  * @returns a new CSSStyleSheet for the correct window
1401
1444
  */
1402
1445
  const createStylesheetForWindow = (container, cssText) => {
1403
- const sheet = new (container.defaultView ?? container.ownerDocument?.defaultView ?? win).CSSStyleSheet();
1446
+ const sheet = new (container.defaultView ?? (container.ownerDocument?.defaultView) ?? win).CSSStyleSheet();
1404
1447
  sheet.replaceSync(cssText);
1405
1448
  return sheet;
1406
1449
  };
@@ -1471,41 +1514,46 @@ const addStyle = (styleContainerNode, cmpMeta, mode) => {
1471
1514
  /**
1472
1515
  * attach styles at the end of the head tag if we render scoped components
1473
1516
  */
1474
- if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation)) if (styleContainerNode.nodeName === "HEAD") {
1475
- /**
1476
- * if the page contains preconnect links, we want to insert the styles
1477
- * after the last preconnect link to ensure the styles are preloaded
1478
- */
1479
- const preconnectLinks = styleContainerNode.querySelectorAll("link[rel=preconnect]");
1480
- const referenceNode = preconnectLinks.length > 0 ? preconnectLinks[preconnectLinks.length - 1].nextSibling : styleContainerNode.querySelector("style");
1481
- styleContainerNode.insertBefore(styleElm, referenceNode?.parentNode === styleContainerNode ? referenceNode : null);
1482
- } else if ("host" in styleContainerNode) if (supportsConstructableStylesheets) {
1483
- const stylesheet = createStylesheetForWindow(styleContainerNode, style);
1484
- adoptStylesheet(styleContainerNode, stylesheet, true);
1485
- } else {
1486
- /**
1487
- * If a scoped component is used within a shadow root and constructable stylesheets are
1488
- * not supported, we want to insert the styles at the beginning of the shadow root node.
1489
- *
1490
- * However, if there is already a style node in the shadow root, we just append
1491
- * the styles to the existing node.
1492
- *
1493
- * Note: order of how styles are applied is important. The new style node
1494
- * should be inserted before the existing style node.
1495
- *
1496
- * During HMR, create separate style elements for scoped components so they can be
1497
- * updated independently without affecting other components' styles.
1498
- */
1499
- const existingStyleContainer = styleContainerNode.querySelector("style");
1500
- if (existingStyleContainer && !BUILD$1.hotModuleReplacement) existingStyleContainer.textContent = style + existingStyleContainer.textContent;
1501
- else styleContainerNode.prepend(styleElm);
1517
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation)) {
1518
+ if (styleContainerNode.nodeName === "HEAD") {
1519
+ /**
1520
+ * if the page contains preconnect links, we want to insert the styles
1521
+ * after the last preconnect link to ensure the styles are preloaded
1522
+ */
1523
+ const preconnectLinks = styleContainerNode.querySelectorAll("link[rel=preconnect]");
1524
+ const referenceNode = preconnectLinks.length > 0 ? preconnectLinks[preconnectLinks.length - 1].nextSibling : styleContainerNode.querySelector("style");
1525
+ styleContainerNode.insertBefore(styleElm, referenceNode?.parentNode === styleContainerNode ? referenceNode : null);
1526
+ } else if ("host" in styleContainerNode) {
1527
+ if (supportsConstructableStylesheets) {
1528
+ const stylesheet = createStylesheetForWindow(styleContainerNode, style);
1529
+ adoptStylesheet(styleContainerNode, stylesheet, true);
1530
+ } else {
1531
+ /**
1532
+ * If a scoped component is used within a shadow root and constructable stylesheets are
1533
+ * not supported, we want to insert the styles at the beginning of the shadow root node.
1534
+ *
1535
+ * However, if there is already a style node in the shadow root, we just append
1536
+ * the styles to the existing node.
1537
+ *
1538
+ * Note: order of how styles are applied is important. The new style node
1539
+ * should be inserted before the existing style node.
1540
+ *
1541
+ * During HMR, create separate style elements for scoped components so they can be
1542
+ * updated independently without affecting other components' styles.
1543
+ */
1544
+ const existingStyleContainer = styleContainerNode.querySelector("style");
1545
+ if (existingStyleContainer && !BUILD$1.hotModuleReplacement) existingStyleContainer.textContent = style + existingStyleContainer.textContent;
1546
+ else styleContainerNode.prepend(styleElm);
1547
+ }
1548
+ } else styleContainerNode.append(styleElm);
1502
1549
  }
1503
- else styleContainerNode.append(styleElm);
1504
1550
  /**
1505
1551
  * attach styles at the beginning of a shadow root node if we render shadow components
1506
1552
  */
1507
- if (cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) if (isClosedShadowSSR) styleContainerNode.prepend(styleElm);
1508
- else styleContainerNode.insertBefore(styleElm, null);
1553
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) {
1554
+ if (isClosedShadowSSR) styleContainerNode.prepend(styleElm);
1555
+ else styleContainerNode.insertBefore(styleElm, null);
1556
+ }
1509
1557
  if (appliedStyles) appliedStyles.add(scopeId);
1510
1558
  }
1511
1559
  } else if (BUILD$1.constructableCSS) {
@@ -1734,11 +1782,15 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1734
1782
  }
1735
1783
  } else if (BUILD$1.vdomStyle && memberName === "style") {
1736
1784
  if (BUILD$1.updatable) {
1737
- for (const prop in oldValue) if (!newValue || newValue[prop] == null) if (!BUILD$1.hydrateServerSide && prop.includes("-")) elm.style.removeProperty(prop);
1738
- else elm.style[prop] = "";
1785
+ for (const prop in oldValue) if (!newValue || newValue[prop] == null) {
1786
+ if (!BUILD$1.hydrateServerSide && prop.includes("-")) elm.style.removeProperty(prop);
1787
+ else elm.style[prop] = "";
1788
+ }
1789
+ }
1790
+ for (const prop in newValue) if (!oldValue || newValue[prop] !== oldValue[prop]) {
1791
+ if (!BUILD$1.hydrateServerSide && prop.includes("-")) elm.style.setProperty(prop, newValue[prop]);
1792
+ else elm.style[prop] = newValue[prop];
1739
1793
  }
1740
- for (const prop in newValue) if (!oldValue || newValue[prop] !== oldValue[prop]) if (!BUILD$1.hydrateServerSide && prop.includes("-")) elm.style.setProperty(prop, newValue[prop]);
1741
- else elm.style[prop] = newValue[prop];
1742
1794
  } else if (BUILD$1.vdomKey && memberName === "key") {} else if (BUILD$1.vdomRef && memberName === "ref") {
1743
1795
  if (newValue) queueRefAttachment(newValue, elm);
1744
1796
  } else if (BUILD$1.vdomListener && (BUILD$1.lazyLoad ? !isProp : !elm.__lookupSetter__(memberName)) && memberName[0] === "o" && memberName[1] === "n") {
@@ -1747,7 +1799,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1747
1799
  else memberName = ln[2] + memberName.slice(3);
1748
1800
  if (oldValue || newValue) {
1749
1801
  const capture = memberName.endsWith(CAPTURE_EVENT_SUFFIX);
1750
- memberName = memberName.replace(/* @__PURE__ */ new RegExp(CAPTURE_EVENT_SUFFIX + "$"), "");
1802
+ memberName = memberName.replace(/*@__PURE__*/ new RegExp(CAPTURE_EVENT_SUFFIX + "$"), "");
1751
1803
  if (oldValue) plt.rel(elm, memberName, oldValue, capture);
1752
1804
  if (newValue) plt.ael(elm, memberName, newValue, capture);
1753
1805
  }
@@ -1786,8 +1838,10 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1786
1838
  if (!elm.tagName.includes("-")) {
1787
1839
  const n = newValue == null ? "" : newValue;
1788
1840
  if (memberName === "list") isProp = false;
1789
- else if (oldValue == null || elm[memberName] !== n) if (typeof elm.__lookupSetter__(memberName) === "function") elm[memberName] = n;
1790
- else elm.setAttribute(memberName, n);
1841
+ else if (oldValue == null || elm[memberName] !== n) {
1842
+ if (typeof elm.__lookupSetter__(memberName) === "function") elm[memberName] = n;
1843
+ else elm.setAttribute(memberName, n);
1844
+ }
1791
1845
  } else if (elm[memberName] !== newValue) elm[memberName] = newValue;
1792
1846
  } catch {}
1793
1847
  /**
@@ -1805,8 +1859,10 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1805
1859
  }
1806
1860
  }
1807
1861
  if (newValue == null || newValue === false) {
1808
- if (newValue !== false || elm.getAttribute(memberName) === "") if (BUILD$1.vdomXlink && xlink) elm.removeAttributeNS(XLINK_NS, memberName);
1809
- else elm.removeAttribute(memberName);
1862
+ if (newValue !== false || elm.getAttribute(memberName) === "") {
1863
+ if (BUILD$1.vdomXlink && xlink) elm.removeAttributeNS(XLINK_NS, memberName);
1864
+ else elm.removeAttribute(memberName);
1865
+ }
1810
1866
  } else if ((!isProp || flags & VNODE_FLAGS.isHost || isSvg) && !isComplex && elm.nodeType === NODE_TYPE.ElementNode) {
1811
1867
  newValue = newValue === true ? "" : newValue;
1812
1868
  if (BUILD$1.vdomXlink && xlink) elm.setAttributeNS(XLINK_NS, memberName, newValue);
@@ -1937,6 +1993,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex) => {
1937
1993
  }
1938
1994
  } else if (BUILD$1.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotReference) {
1939
1995
  elm = newVNode.$elm$ = BUILD$1.isDebug || BUILD$1.hydrateServerSide ? slotReferenceDebugNode(newVNode) : win.document.createTextNode("");
1996
+ if (typeof newVNode.$attrs$?.slot === "string") elm["s-sa"] = newVNode.$attrs$.slot;
1940
1997
  if (BUILD$1.vdomAttribute) updateElement(null, newVNode, isSvgMode);
1941
1998
  } else {
1942
1999
  if (BUILD$1.svg && !isSvgMode) isSvgMode = newVNode.$tag$ === "svg";
@@ -2212,8 +2269,10 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = fal
2212
2269
  node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
2213
2270
  newStartVnode = newCh[++newStartIdx];
2214
2271
  }
2215
- if (node) if (BUILD$1.slotRelocation) insertBefore(referenceNode(oldStartVnode.$elm$).parentNode, node, referenceNode(oldStartVnode.$elm$));
2216
- else insertBefore(oldStartVnode.$elm$.parentNode, node, oldStartVnode.$elm$);
2272
+ if (node) {
2273
+ if (BUILD$1.slotRelocation) insertBefore(referenceNode(oldStartVnode.$elm$).parentNode, node, referenceNode(oldStartVnode.$elm$));
2274
+ else insertBefore(oldStartVnode.$elm$.parentNode, node, oldStartVnode.$elm$);
2275
+ }
2217
2276
  }
2218
2277
  if (oldStartIdx > oldEndIdx) addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
2219
2278
  else if (BUILD$1.updatable && newStartIdx > newEndIdx) removeVnodes(oldCh, oldStartIdx, oldEndIdx);
@@ -2300,6 +2359,30 @@ const patch = (oldVNode, newVNode, isInitialRender = false) => {
2300
2359
  */
2301
2360
  const relocateNodes = [];
2302
2361
  /**
2362
+ * When a forwarded `<slot>` gets relocated, drag along any content already forwarded through it,
2363
+ * to wherever it just landed (or nowhere, to be hidden, if it didn't match anything).
2364
+ *
2365
+ * Runs as its own pass after {@link markSlotContentForRelocation} rather than inside it, so that
2366
+ * function's matching order - which hydration's node/comment ordering depends on - is untouched.
2367
+ */
2368
+ const carryContentWithRelocatedSlotRefs = () => {
2369
+ for (const relocateData of relocateNodes.slice()) {
2370
+ const marker = relocateData.$nodeToRelocate$;
2371
+ if (!marker["s-sr"]) continue;
2372
+ const carriedSiblings = getSlotChildSiblings(marker, marker["s-sn"] || "", false);
2373
+ for (const carriedSibling of carriedSiblings) {
2374
+ if (!carriedSibling["s-ol"]) continue;
2375
+ let siblingRelocateData = relocateNodes.find((r) => r.$nodeToRelocate$ === carriedSibling);
2376
+ if (!siblingRelocateData) {
2377
+ siblingRelocateData = { $nodeToRelocate$: carriedSibling };
2378
+ relocateNodes.push(siblingRelocateData);
2379
+ }
2380
+ siblingRelocateData.$slotRefNode$ = relocateData.$slotRefNode$;
2381
+ if (relocateData.$slotRefNode$) carriedSibling["s-sh"] = relocateData.$slotRefNode$["s-hn"];
2382
+ }
2383
+ }
2384
+ };
2385
+ /**
2303
2386
  * Mark the contents of a slot for relocation via adding references to them to
2304
2387
  * the {@link relocateNodes} data structure. The actual work of relocating them
2305
2388
  * will then be handled in {@link renderVdom}.
@@ -2498,6 +2581,7 @@ render() {
2498
2581
  plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
2499
2582
  if (checkSlotRelocate) {
2500
2583
  markSlotContentForRelocation(rootVnode.$elm$);
2584
+ carryContentWithRelocatedSlotRefs();
2501
2585
  for (const relocateData of relocateNodes) {
2502
2586
  const nodeToRelocate = relocateData.$nodeToRelocate$;
2503
2587
  if (!nodeToRelocate["s-ol"] && win.document) {
@@ -2557,7 +2641,7 @@ render() {
2557
2641
  }
2558
2642
  if (BUILD$1.slotRelocation && !useNativeShadowDom && !(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && hostElm["s-cr"]) {
2559
2643
  const children = rootVnode.$elm$.__childNodes || rootVnode.$elm$.childNodes;
2560
- for (const childNode of children) if (childNode["s-hn"] !== hostTagName && !childNode["s-sh"]) {
2644
+ for (const childNode of children) if (childNode["s-hn"] !== hostTagName && childNode["s-sh"] !== hostTagName) {
2561
2645
  if (isInitialLoad && childNode["s-ih"] == null) childNode["s-ih"] = childNode.hidden ?? false;
2562
2646
  if (childNode.nodeType === NODE_TYPE.ElementNode) childNode.hidden = true;
2563
2647
  else if (childNode.nodeType === NODE_TYPE.TextNode && !!childNode.nodeValue.trim()) {
@@ -2575,16 +2659,58 @@ const slotReferenceDebugNode = (slotVNode) => win.document?.createComment(`<slot
2575
2659
  const originalLocationDebugNode = (nodeToRelocate) => win.document?.createComment(`org-location for ` + (nodeToRelocate.localName ? `<${nodeToRelocate.localName}> (host=${nodeToRelocate["s-hn"]})` : `[${nodeToRelocate.textContent}]`));
2576
2660
  //#endregion
2577
2661
  //#region src/runtime/update-component.ts
2662
+ /**
2663
+ * Get a promise that resolves once `hostRef`'s real `connectedCallback` has fired for the first time.
2664
+ *
2665
+ * @param hostRef the component's host reference
2666
+ * @returns a promise that resolves once the component's real `connectedCallback` has fired
2667
+ */
2668
+ const ensureFirstConnectPromise = (hostRef) => {
2669
+ if (!hostRef.$onFirstConnectPromise$) hostRef.$onFirstConnectPromise$ = new Promise((r) => hostRef.$onFirstConnectResolve$ = r);
2670
+ return hostRef.$onFirstConnectPromise$;
2671
+ };
2672
+ /**
2673
+ * Resolve `hostRef`'s first-connect promise and flag it connected. Called once this
2674
+ * component's real `connectedCallback` fires, plus from error/disconnect cleanup so a
2675
+ * component that never connects can't hang an ancestor or descendant forever.
2676
+ *
2677
+ * @param hostRef the component's host reference
2678
+ */
2679
+ const markFirstConnected = (hostRef) => {
2680
+ hostRef.$flags$ |= HOST_FLAGS.hasFiredConnected;
2681
+ hostRef.$onFirstConnectResolve$?.();
2682
+ hostRef.$onFirstConnectResolve$ = void 0;
2683
+ };
2684
+ /**
2685
+ * Wait for `ancestorElm` to be defined and its real `connectedCallback` to have completed.
2686
+ * Shared by the lazy ({@link initializeComponent}) and standalone (`bootstrap-standalone.ts`)
2687
+ * `connectedCallback` paths so a component never connects before its nearest Stencil
2688
+ * ancestor, regardless of load order. Both call sites already check `BUILD.asyncLoading` and
2689
+ * that an ancestor exists before calling this. Lazy's proxy classes are always pre-defined,
2690
+ * so the `whenDefined` wait is a no-op there - it only does real work for standalone's
2691
+ * autoloader, where the ancestor tag may not be defined yet.
2692
+ *
2693
+ * @param ancestorElm the nearest Stencil ancestor element
2694
+ */
2695
+ const awaitAncestorConnected = async (ancestorElm) => {
2696
+ let ancestorHostRef = getHostRef(ancestorElm);
2697
+ if (!BUILD$1.lazyLoad && !ancestorHostRef) {
2698
+ await getRegistry().whenDefined(ancestorElm.tagName.toLowerCase());
2699
+ ancestorHostRef = getHostRef(ancestorElm);
2700
+ }
2701
+ if (ancestorHostRef && !(ancestorHostRef.$flags$ & HOST_FLAGS.hasFiredConnected)) await ensureFirstConnectPromise(ancestorHostRef);
2702
+ };
2578
2703
  const attachToAncestor = (hostRef, ancestorComponent) => {
2579
2704
  if (BUILD$1.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent["s-p"]) {
2580
2705
  const index = ancestorComponent["s-p"].push(new Promise((r) => hostRef.$onRenderResolve$ = () => {
2581
2706
  ancestorComponent["s-p"].splice(index - 1, 1);
2582
2707
  r();
2583
2708
  }));
2709
+ if (ancestorComponent["s-pc"]) ancestorComponent["s-pc"].push(ensureFirstConnectPromise(hostRef));
2584
2710
  }
2585
2711
  };
2586
2712
  const scheduleUpdate = (hostRef, isInitialLoad) => {
2587
- if (BUILD$1.taskQueue && BUILD$1.updatable) hostRef.$flags$ |= HOST_FLAGS.isQueuedForUpdate;
2713
+ if (BUILD$1.updatable) hostRef.$flags$ |= HOST_FLAGS.isQueuedForUpdate;
2588
2714
  if (BUILD$1.asyncLoading && hostRef.$flags$ & HOST_FLAGS.isWaitingForChildren) {
2589
2715
  hostRef.$flags$ |= HOST_FLAGS.needsRerender;
2590
2716
  return;
@@ -2592,6 +2718,8 @@ const scheduleUpdate = (hostRef, isInitialLoad) => {
2592
2718
  attachToAncestor(hostRef, hostRef.$ancestorComponent$);
2593
2719
  const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
2594
2720
  if (isInitialLoad) {
2721
+ const pendingConnects = BUILD$1.asyncLoading ? hostRef.$hostElement$["s-pc"] : void 0;
2722
+ if (pendingConnects && pendingConnects.length > 0) return Promise.all(pendingConnects).then(dispatch).catch(dispatch);
2595
2723
  queueMicrotask(() => {
2596
2724
  dispatch();
2597
2725
  });
@@ -2631,10 +2759,6 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
2631
2759
  let maybePromise;
2632
2760
  if (isInitialLoad) {
2633
2761
  if (BUILD$1.lazyLoad) {
2634
- if (BUILD$1.slotRelocation && hostRef.$deferredConnectedCallback$) {
2635
- hostRef.$deferredConnectedCallback$ = false;
2636
- safeCall(instance, "connectedCallback", void 0, elm);
2637
- }
2638
2762
  if (BUILD$1.hostListener) {
2639
2763
  hostRef.$flags$ |= HOST_FLAGS.isListenReady;
2640
2764
  if (hostRef.$queuedListeners$) {
@@ -2647,6 +2771,14 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
2647
2771
  if (BUILD$1.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillLoad");
2648
2772
  maybePromise = safeCall(instance, "componentWillLoad", void 0, elm);
2649
2773
  } else {
2774
+ if (BUILD$1.updatable && hostRef.$queuedPropChanges$) {
2775
+ const changes = hostRef.$queuedPropChanges$;
2776
+ hostRef.$queuedPropChanges$ = void 0;
2777
+ if (safeCall(instance, "componentShouldUpdate", changes, elm) === false) {
2778
+ hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
2779
+ return;
2780
+ }
2781
+ }
2650
2782
  if (BUILD$1.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillUpdate");
2651
2783
  maybePromise = safeCall(instance, "componentWillUpdate", void 0, elm);
2652
2784
  }
@@ -2761,7 +2893,6 @@ let renderingRef = null;
2761
2893
  const callRender = (hostRef, instance, elm, isInitialLoad) => {
2762
2894
  const allRenderFn = !!BUILD$1.allRenderFn;
2763
2895
  const lazyLoad = !!BUILD$1.lazyLoad;
2764
- const taskQueue = !!BUILD$1.taskQueue;
2765
2896
  const updatable = !!BUILD$1.updatable;
2766
2897
  try {
2767
2898
  renderingRef = instance;
@@ -2770,14 +2901,17 @@ const callRender = (hostRef, instance, elm, isInitialLoad) => {
2770
2901
  * method, so we can call the method immediately. If not, check before calling it.
2771
2902
  */
2772
2903
  instance = allRenderFn ? instance.render() : instance.render && instance.render();
2773
- if (updatable && taskQueue) hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
2904
+ if (updatable) hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
2774
2905
  if (updatable || lazyLoad) hostRef.$flags$ |= HOST_FLAGS.hasRendered;
2775
- if (BUILD$1.hasRenderFn || BUILD$1.reflect) if (BUILD$1.vdomRender || BUILD$1.reflect) if (BUILD$1.hydrateServerSide) return Promise.resolve(instance).then((value) => renderVdom(hostRef, value, isInitialLoad));
2776
- else renderVdom(hostRef, instance, isInitialLoad);
2777
- else {
2778
- const shadowRoot = elm.shadowRoot;
2779
- if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.shadowDomEncapsulation) shadowRoot.textContent = instance;
2780
- else elm.textContent = instance;
2906
+ if (BUILD$1.hasRenderFn || BUILD$1.reflect) {
2907
+ if (BUILD$1.vdomRender || BUILD$1.reflect) {
2908
+ if (BUILD$1.hydrateServerSide) return Promise.resolve(instance).then((value) => renderVdom(hostRef, value, isInitialLoad));
2909
+ else renderVdom(hostRef, instance, isInitialLoad);
2910
+ } else {
2911
+ const shadowRoot = elm.shadowRoot;
2912
+ if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.shadowDomEncapsulation) shadowRoot.textContent = instance;
2913
+ else elm.textContent = instance;
2914
+ }
2781
2915
  }
2782
2916
  } catch (e) {
2783
2917
  consoleError(e, hostRef.$hostElement$);
@@ -2917,17 +3051,19 @@ const initializeSignals = (elm, hostRef, cmpMeta) => {
2917
3051
  const instance = BUILD$1.lazyLoad ? hostRef.$lazyInstance$ : elm;
2918
3052
  for (const [memberName, [memberFlags]] of Object.entries(cmpMeta.$members$ ?? {})) {
2919
3053
  if (!(memberFlags & MEMBER_FLAGS.PropLike)) continue;
2920
- const sig = signal(hostRef.$instanceValues$.get(memberName));
3054
+ const initialVal = hostRef.$instanceValues$.get(memberName);
3055
+ const sig = signal(initialVal);
2921
3056
  hostRef.$signalValues$.set(memberName, sig);
2922
3057
  let prevScheduleVal = sig.peek();
2923
3058
  disposers.push(effect(() => {
2924
3059
  const newVal = sig.value;
2925
3060
  if (hostRef.$flags$ & HOST_FLAGS.hasRendered) {
2926
3061
  if (instance?.componentShouldUpdate) {
2927
- if (instance.componentShouldUpdate(newVal, prevScheduleVal, memberName) === false && !(hostRef.$flags$ & HOST_FLAGS.isQueuedForUpdate)) {
2928
- prevScheduleVal = newVal;
2929
- return;
2930
- }
3062
+ const changes = hostRef.$queuedPropChanges$ ||= {};
3063
+ changes[memberName] = {
3064
+ newVal,
3065
+ oldVal: changes[memberName]?.oldVal ?? prevScheduleVal
3066
+ };
2931
3067
  }
2932
3068
  if (!(hostRef.$flags$ & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
2933
3069
  }
@@ -2962,7 +3098,8 @@ const initializeSignals = (elm, hostRef, cmpMeta) => {
2962
3098
  consoleError(e, elm);
2963
3099
  }
2964
3100
  }));
2965
- elm[STENCIL_SIGNALS_SYMBOL] = new Map([...hostRef.$signalValues$].filter(([k]) => (cmpMeta.$members$?.[k]?.[0] ?? 0) & MEMBER_FLAGS.Prop));
3101
+ const publicSignals = new Map([...hostRef.$signalValues$].filter(([k]) => (cmpMeta.$members$?.[k]?.[0] ?? 0) & MEMBER_FLAGS.Prop));
3102
+ elm[STENCIL_SIGNALS_SYMBOL] = publicSignals;
2966
3103
  hostRef.$signalCleanup$ = () => {
2967
3104
  disposers.forEach((d) => d());
2968
3105
  elm[STENCIL_SIGNALS_SYMBOL] = void 0;
@@ -3011,19 +3148,25 @@ const h = (nodeName, vnodeData, ...children) => {
3011
3148
  for (let i = 0; i < c.length; i++) {
3012
3149
  child = c[i];
3013
3150
  if (Array.isArray(child)) walk(child);
3014
- else if (child != null && typeof child !== "boolean") if (BUILD$1.vdomSignals && isSignalLike(child)) {
3015
- const sigVNode = newVNode(null, String(child.peek()));
3016
- sigVNode.$signal$ = child;
3017
- vNodeChildren.push(sigVNode);
3018
- lastSimple = false;
3019
- } else {
3020
- if (simple = typeof nodeName !== "function" && !isComplexType(child)) child = String(child);
3021
- else if (BUILD$1.isDev && typeof nodeName !== "function" && child.$flags$ === void 0) consoleDevError(`vNode passed as children has unexpected type.
3022
- Make sure it's using the correct h() function.
3023
- Empty objects can also be the cause, look for JSX comments that became objects.`);
3024
- if (simple && lastSimple) vNodeChildren[vNodeChildren.length - 1].$text$ += child;
3025
- else vNodeChildren.push(simple ? newVNode(null, child) : child);
3026
- lastSimple = simple;
3151
+ else if (child != null && typeof child !== "boolean") {
3152
+ if (BUILD$1.vdomSignals && isSignalLike(child)) {
3153
+ const sigVNode = newVNode(null, String(child.peek()));
3154
+ sigVNode.$signal$ = child;
3155
+ vNodeChildren.push(sigVNode);
3156
+ lastSimple = false;
3157
+ } else {
3158
+ if (simple = typeof nodeName !== "function" && !isComplexType(child)) child = String(child);
3159
+ else if (typeof nodeName !== "function" && child.$flags$ === void 0) {
3160
+ if (BUILD$1.isDev) consoleDevError(`vNode passed as children has unexpected type.
3161
+ Make sure it's using the correct h() function.
3162
+ Empty objects can also be the cause, look for JSX comments that became objects.`);
3163
+ else consoleError("Invalid vNode child");
3164
+ continue;
3165
+ }
3166
+ if (simple && lastSimple) vNodeChildren[vNodeChildren.length - 1].$text$ += child;
3167
+ else vNodeChildren.push(simple ? newVNode(null, child) : child);
3168
+ lastSimple = simple;
3169
+ }
3027
3170
  }
3028
3171
  }
3029
3172
  };
@@ -4008,14 +4151,15 @@ const parsePropertyValue = (propValue, propType, isFormAssociated) => {
4008
4151
  /**
4009
4152
  * ensure this value is of the correct prop type
4010
4153
  */
4011
- if (BUILD$1.propBoolean && propType & MEMBER_FLAGS.Boolean)
4012
- /**
4013
- * For form-associated components, according to HTML spec, the presence of any boolean attribute
4014
- * (regardless of its value, even "false") should make the property true.
4015
- * For non-form-associated components, we maintain the legacy behavior where "false" becomes false.
4016
- */
4017
- if (BUILD$1.formAssociated && isFormAssociated && typeof propValue === "string") return propValue === "" || !!propValue;
4018
- else return propValue === "false" ? false : propValue === "" || !!propValue;
4154
+ if (BUILD$1.propBoolean && propType & MEMBER_FLAGS.Boolean) {
4155
+ /**
4156
+ * For form-associated components, according to HTML spec, the presence of any boolean attribute
4157
+ * (regardless of its value, even "false") should make the property true.
4158
+ * For non-form-associated components, we maintain the legacy behavior where "false" becomes false.
4159
+ */
4160
+ if (BUILD$1.formAssociated && isFormAssociated && typeof propValue === "string") return propValue === "" || !!propValue;
4161
+ else return propValue === "false" ? false : propValue === "" || !!propValue;
4162
+ }
4019
4163
  /**
4020
4164
  * force it to be a number
4021
4165
  */
@@ -4103,7 +4247,11 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
4103
4247
  }
4104
4248
  if (BUILD$1.updatable && flags & HOST_FLAGS.hasRendered) {
4105
4249
  if (instance.componentShouldUpdate) {
4106
- if (instance.componentShouldUpdate(newVal, oldVal, propName) === false && !(flags & HOST_FLAGS.isQueuedForUpdate)) return;
4250
+ const changes = hostRef.$queuedPropChanges$ ||= {};
4251
+ changes[propName] = {
4252
+ newVal,
4253
+ oldVal: changes[propName]?.oldVal ?? oldVal
4254
+ };
4107
4255
  }
4108
4256
  if (!(flags & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
4109
4257
  }
@@ -4237,11 +4385,12 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4237
4385
  };
4238
4386
  for (const deserializer of cmpMeta.$deserializers$[propName]) {
4239
4387
  const [[methodName]] = Object.entries(deserializer);
4240
- if (BUILD$1.lazyLoad) if (hostRef.$lazyInstance$) setVal(methodName, hostRef.$lazyInstance$);
4241
- else hostRef.$fetchedCbList$.push(() => {
4242
- setVal(methodName, hostRef.$lazyInstance$);
4243
- });
4244
- else setVal(methodName, this);
4388
+ if (BUILD$1.lazyLoad) {
4389
+ if (hostRef.$lazyInstance$) setVal(methodName, hostRef.$lazyInstance$);
4390
+ else hostRef.$fetchedCbList$.push(() => {
4391
+ setVal(methodName, hostRef.$lazyInstance$);
4392
+ });
4393
+ } else setVal(methodName, this);
4245
4394
  }
4246
4395
  return;
4247
4396
  } else if (prototype.hasOwnProperty(propName) && typeof this[propName] === "number" && this[propName] == newValue) return;
@@ -4265,7 +4414,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4265
4414
  if (!isSpuriousBooleanRemoval && newValue != this[propName] && (!propDesc.get || !!propDesc.set)) this[propName] = newValue;
4266
4415
  });
4267
4416
  };
4268
- Cstr.observedAttributes = Array.from(new Set([...Object.keys(cmpMeta.$watchers$ ?? {}), ...members.filter(([_, m]) => m[0] & MEMBER_FLAGS.HasAttribute).map(([propName, m]) => {
4417
+ Cstr.observedAttributes = Array.from(/* @__PURE__ */ new Set([...Object.keys(cmpMeta.$watchers$ ?? {}), ...members.filter(([_, m]) => m[0] & MEMBER_FLAGS.HasAttribute).map(([propName, m]) => {
4269
4418
  const attrName = m[1] || propName;
4270
4419
  attrNameToPropName.set(attrName, propName);
4271
4420
  if (BUILD$1.reflect && m[0] & MEMBER_FLAGS.ReflectAttr) cmpMeta.$attrsToReflect$?.push([propName, attrName]);
@@ -4292,6 +4441,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4292
4441
  try {
4293
4442
  if ((hostRef.$flags$ & HOST_FLAGS.hasInitializedComponent) === 0) {
4294
4443
  hostRef.$flags$ |= HOST_FLAGS.hasInitializedComponent;
4444
+ hostRef.$flags$ &= ~HOST_FLAGS.hasFailedLoad;
4295
4445
  const bundleId = cmpMeta.$lazyBundleId$;
4296
4446
  if (BUILD$1.lazyLoad && bundleId) {
4297
4447
  const CstrImport = loadModule(cmpMeta, hostRef, hmrVersionId);
@@ -4300,7 +4450,12 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4300
4450
  Cstr = await CstrImport;
4301
4451
  endLoad();
4302
4452
  } else Cstr = CstrImport;
4303
- if (!Cstr) throw new Error(`Constructor for "${cmpMeta.$tagName$}#${hostRef.$modeName$}" was not found`);
4453
+ if (!Cstr) {
4454
+ hostRef.$flags$ &= ~HOST_FLAGS.hasInitializedComponent;
4455
+ hostRef.$loadRetryCount$ = (hostRef.$loadRetryCount$ ?? 0) + 1;
4456
+ if (hostRef.$loadRetryCount$ < 3) hostRef.$flags$ |= HOST_FLAGS.hasFailedLoad;
4457
+ throw new Error(`Constructor for "${cmpMeta.$tagName$}#${hostRef.$modeName$}" was not found`);
4458
+ }
4304
4459
  if (BUILD$1.member && !Cstr.isProxied) {
4305
4460
  if (BUILD$1.propChangeCallback) {
4306
4461
  cmpMeta.$watchers$ = normalizeWatchers(Cstr.watchers);
@@ -4319,8 +4474,14 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4319
4474
  }
4320
4475
  if (BUILD$1.member) hostRef.$flags$ &= ~HOST_FLAGS.isConstructingInstance;
4321
4476
  endNewInstance();
4322
- if (!(BUILD$1.slotRelocation && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation)) fireConnectedCallback(hostRef.$lazyInstance$, elm);
4323
- else hostRef.$deferredConnectedCallback$ = true;
4477
+ if (BUILD$1.asyncLoading && hostRef.$ancestorComponent$) await awaitAncestorConnected(hostRef.$ancestorComponent$);
4478
+ if (!(BUILD$1.slotRelocation && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation)) {
4479
+ fireConnectedCallback(hostRef.$lazyInstance$, elm);
4480
+ if (BUILD$1.asyncLoading) markFirstConnected(hostRef);
4481
+ } else queueMicrotask(() => {
4482
+ fireConnectedCallback(hostRef.$lazyInstance$, elm);
4483
+ if (BUILD$1.asyncLoading) markFirstConnected(hostRef);
4484
+ });
4324
4485
  } else Cstr = elm.constructor;
4325
4486
  if (BUILD$1.style && Cstr && Cstr.style) {
4326
4487
  /**
@@ -4379,7 +4540,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4379
4540
  hostRef.$onRenderResolve$();
4380
4541
  hostRef.$onRenderResolve$ = void 0;
4381
4542
  }
4382
- if (BUILD$1.asyncLoading && hostRef.$onReadyResolve$) hostRef.$onReadyResolve$(elm);
4543
+ if (BUILD$1.asyncLoading) markFirstConnected(hostRef);
4544
+ if (BUILD$1.asyncLoading && hostRef.$onReadyResolve$ && !(hostRef.$flags$ & HOST_FLAGS.hasFailedLoad)) hostRef.$onReadyResolve$(elm);
4383
4545
  }
4384
4546
  };
4385
4547
  const fireConnectedCallback = (instance, elm) => {
@@ -4442,6 +4604,7 @@ const connectedCallback = (elm) => {
4442
4604
  } else {
4443
4605
  addHostEventListeners(elm, hostRef, cmpMeta.$listeners$);
4444
4606
  if (hostRef?.$lazyInstance$) fireConnectedCallback(hostRef.$lazyInstance$, elm);
4607
+ else if (hostRef.$flags$ & HOST_FLAGS.hasFailedLoad) setTimeout(() => initializeComponent(elm, hostRef, cmpMeta), LAZY_LOAD_RETRY_INTERVAL_MS);
4445
4608
  else if (hostRef?.$onReadyPromise$) hostRef.$onReadyPromise$.then(() => fireConnectedCallback(hostRef.$lazyInstance$, elm));
4446
4609
  }
4447
4610
  endConnected();
@@ -4471,6 +4634,7 @@ const disconnectedCallback = async (elm) => {
4471
4634
  hostRef.$signalCleanup$();
4472
4635
  hostRef.$signalCleanup$ = void 0;
4473
4636
  }
4637
+ if (BUILD$1.asyncLoading && hostRef && !(hostRef.$flags$ & HOST_FLAGS.hasFiredConnected)) markFirstConnected(hostRef);
4474
4638
  if (!BUILD$1.lazyLoad) disconnectInstance(elm);
4475
4639
  else if (hostRef?.$lazyInstance$) disconnectInstance(hostRef.$lazyInstance$, elm);
4476
4640
  else if (hostRef?.$onReadyPromise$) hostRef.$onReadyPromise$.then(() => disconnectInstance(hostRef.$lazyInstance$, elm));
@@ -4596,18 +4760,20 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4596
4760
  hmrStart(this, cmpMeta, hmrVersionId);
4597
4761
  };
4598
4762
  if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && (BUILD$1.slotCloneNode || BUILD$1.patchClone && cmpMeta.$flags$ & CMP_FLAGS.patchClone)) patchCloneNode(Cstr.prototype);
4599
- if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) if (BUILD$1.lightDomPatches || BUILD$1.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(Cstr.prototype);
4600
- else {
4601
- if (BUILD$1.slotChildNodes || BUILD$1.patchChildren && cmpMeta.$flags$ & CMP_FLAGS.patchChildren) patchChildSlotNodes(Cstr.prototype);
4602
- if (BUILD$1.slotDomMutations || BUILD$1.patchInsert && cmpMeta.$flags$ & CMP_FLAGS.patchInsert) {
4603
- patchSlotAppendChild(Cstr.prototype);
4604
- patchSlotAppend(Cstr.prototype);
4605
- patchSlotPrepend(Cstr.prototype);
4606
- patchSlotInsertAdjacentHTML(Cstr.prototype);
4607
- patchInsertBefore(Cstr.prototype);
4608
- patchSlotRemoveChild(Cstr.prototype);
4763
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) {
4764
+ if (BUILD$1.lightDomPatches || BUILD$1.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(Cstr.prototype);
4765
+ else {
4766
+ if (BUILD$1.slotChildNodes || BUILD$1.patchChildren && cmpMeta.$flags$ & CMP_FLAGS.patchChildren) patchChildSlotNodes(Cstr.prototype);
4767
+ if (BUILD$1.slotDomMutations || BUILD$1.patchInsert && cmpMeta.$flags$ & CMP_FLAGS.patchInsert) {
4768
+ patchSlotAppendChild(Cstr.prototype);
4769
+ patchSlotAppend(Cstr.prototype);
4770
+ patchSlotPrepend(Cstr.prototype);
4771
+ patchSlotInsertAdjacentHTML(Cstr.prototype);
4772
+ patchInsertBefore(Cstr.prototype);
4773
+ patchSlotRemoveChild(Cstr.prototype);
4774
+ }
4775
+ if (BUILD$1.slotTextContent) patchTextContent(Cstr.prototype);
4609
4776
  }
4610
- if (BUILD$1.slotTextContent) patchTextContent(Cstr.prototype);
4611
4777
  }
4612
4778
  if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) hydrateScopedToShadow();
4613
4779
  const originalConnectedCallback = Cstr.prototype.connectedCallback;
@@ -4620,19 +4786,26 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4620
4786
  componentOnReady() {
4621
4787
  return getHostRef(this)?.$onReadyPromise$;
4622
4788
  },
4623
- connectedCallback() {
4624
- if (!this.__hasHostListenerAttached) {
4625
- const hostRef = getHostRef(this);
4789
+ async connectedCallback() {
4790
+ const isFirstConnect = !this.__hasHostListenerAttached;
4791
+ let hostRef;
4792
+ if (isFirstConnect) {
4793
+ hostRef = getHostRef(this);
4626
4794
  if (!hostRef) return;
4627
4795
  addHostEventListeners(this, hostRef, cmpMeta.$listeners$);
4628
4796
  this.__hasHostListenerAttached = true;
4629
4797
  }
4630
4798
  connectedCallback(this);
4631
- if (originalConnectedCallback) originalConnectedCallback.call(this);
4799
+ if (BUILD$1.asyncLoading && hostRef && hostRef.$ancestorComponent$) {
4800
+ await awaitAncestorConnected(hostRef.$ancestorComponent$);
4801
+ if (!this.isConnected) return;
4802
+ }
4803
+ if (originalConnectedCallback && (plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) originalConnectedCallback.call(this);
4804
+ if (BUILD$1.asyncLoading && hostRef) markFirstConnected(hostRef);
4632
4805
  },
4633
4806
  disconnectedCallback() {
4634
4807
  disconnectedCallback(this);
4635
- if (originalDisconnectedCallback) originalDisconnectedCallback.call(this);
4808
+ if (originalDisconnectedCallback && (plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) originalDisconnectedCallback.call(this);
4636
4809
  },
4637
4810
  __attachShadow() {
4638
4811
  const isClosed = BUILD$1.shadowModeClosed && !!(cmpMeta.$flags$ & CMP_FLAGS.shadowModeClosed);
@@ -4686,8 +4859,8 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4686
4859
  const exclude = options.exclude || [];
4687
4860
  const _reg = options.registry ?? getRegistry();
4688
4861
  const head = win.document.head;
4689
- const metaCharset = /* @__PURE__ */ head.querySelector("meta[charset]");
4690
- const dataStyles = /* @__PURE__ */ win.document.createElement("style");
4862
+ const metaCharset = /*@__PURE__*/ head.querySelector("meta[charset]");
4863
+ const dataStyles = /*@__PURE__*/ win.document.createElement("style");
4691
4864
  const deferredConnectedCallbacks = [];
4692
4865
  let appLoadFallback;
4693
4866
  let isBootstrapping = true;
@@ -4755,8 +4928,11 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4755
4928
  *
4756
4929
  * Also remove the reference from `deferredConnectedCallbacks` array
4757
4930
  * otherwise removed instances won't get garbage collected.
4931
+ *
4932
+ * Use `nextTick` (microtask) rather than `plt.raf` since
4933
+ * `requestAnimationFrame` callbacks do not fire while `document.hidden`
4758
4934
  */
4759
- plt.raf(() => {
4935
+ nextTick(() => {
4760
4936
  const hostRef = getHostRef(this);
4761
4937
  if (!hostRef) return;
4762
4938
  const i = deferredConnectedCallbacks.findIndex((host) => host === this);
@@ -4769,18 +4945,20 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4769
4945
  }
4770
4946
  };
4771
4947
  if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && (BUILD$1.slotCloneNode || BUILD$1.patchClone && cmpMeta.$flags$ & CMP_FLAGS.patchClone)) patchCloneNode(HostElement.prototype);
4772
- if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) if (BUILD$1.lightDomPatches || BUILD$1.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(HostElement.prototype);
4773
- else {
4774
- if (BUILD$1.slotChildNodes || BUILD$1.patchChildren && cmpMeta.$flags$ & CMP_FLAGS.patchChildren) patchChildSlotNodes(HostElement.prototype);
4775
- if (BUILD$1.slotDomMutations || BUILD$1.patchInsert && cmpMeta.$flags$ & CMP_FLAGS.patchInsert) {
4776
- patchSlotAppendChild(HostElement.prototype);
4777
- patchSlotAppend(HostElement.prototype);
4778
- patchSlotPrepend(HostElement.prototype);
4779
- patchSlotInsertAdjacentHTML(HostElement.prototype);
4780
- patchInsertBefore(HostElement.prototype);
4781
- patchSlotRemoveChild(HostElement.prototype);
4948
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) {
4949
+ if (BUILD$1.lightDomPatches || BUILD$1.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(HostElement.prototype);
4950
+ else {
4951
+ if (BUILD$1.slotChildNodes || BUILD$1.patchChildren && cmpMeta.$flags$ & CMP_FLAGS.patchChildren) patchChildSlotNodes(HostElement.prototype);
4952
+ if (BUILD$1.slotDomMutations || BUILD$1.patchInsert && cmpMeta.$flags$ & CMP_FLAGS.patchInsert) {
4953
+ patchSlotAppendChild(HostElement.prototype);
4954
+ patchSlotAppend(HostElement.prototype);
4955
+ patchSlotPrepend(HostElement.prototype);
4956
+ patchSlotInsertAdjacentHTML(HostElement.prototype);
4957
+ patchInsertBefore(HostElement.prototype);
4958
+ patchSlotRemoveChild(HostElement.prototype);
4959
+ }
4960
+ if (BUILD$1.slotTextContent) patchTextContent(HostElement.prototype);
4782
4961
  }
4783
- if (BUILD$1.slotTextContent) patchTextContent(HostElement.prototype);
4784
4962
  }
4785
4963
  if (BUILD$1.formAssociated && cmpMeta.$flags$ & CMP_FLAGS.formAssociated) HostElement.formAssociated = true;
4786
4964
  if (BUILD$1.hotModuleReplacement) HostElement.prototype["s-hmr"] = function(hmrVersionId) {
@@ -4826,9 +5004,10 @@ const addHostEventListeners = (elm, hostRef, listeners) => {
4826
5004
  };
4827
5005
  const hostListenerProxy = (hostRef, methodName) => (ev) => {
4828
5006
  try {
4829
- if (BUILD$1.lazyLoad) if (hostRef.$flags$ & HOST_FLAGS.isListenReady) hostRef.$lazyInstance$?.[methodName](ev);
4830
- else (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
4831
- else hostRef.$hostElement$[methodName](ev);
5007
+ if (BUILD$1.lazyLoad) {
5008
+ if (hostRef.$flags$ & HOST_FLAGS.isListenReady) hostRef.$lazyInstance$?.[methodName](ev);
5009
+ else (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
5010
+ } else hostRef.$hostElement$[methodName](ev);
4832
5011
  } catch (e) {
4833
5012
  consoleError(e, hostRef.$hostElement$);
4834
5013
  }
@@ -4862,6 +5041,73 @@ const setNonce = (nonce) => plt.$nonce$ = nonce;
4862
5041
  //#region src/runtime/platform-options.ts
4863
5042
  const setPlatformOptions = (opts) => Object.assign(plt, opts);
4864
5043
  //#endregion
5044
+ //#region src/runtime/reactive-controller.ts
5045
+ const ReactiveControllerHost = (Base) => class ReactiveControllerHostMixin extends Base {
5046
+ controllers = /* @__PURE__ */ new Set();
5047
+ #connected = false;
5048
+ #updateCompleteResolvers = [];
5049
+ addController(controller) {
5050
+ this.controllers.add(controller);
5051
+ if (this.#connected) controller.hostConnected?.();
5052
+ }
5053
+ removeController(controller) {
5054
+ this.controllers.delete(controller);
5055
+ }
5056
+ requestUpdate() {
5057
+ forceUpdate(this);
5058
+ }
5059
+ get updateComplete() {
5060
+ return new Promise((resolve) => this.#updateCompleteResolvers.push(resolve));
5061
+ }
5062
+ connectedCallback() {
5063
+ super.connectedCallback?.();
5064
+ this.#connected = true;
5065
+ const el = getElement(this);
5066
+ if (el && el !== this) {
5067
+ el.addController = (controller) => this.addController(controller);
5068
+ el.removeController = (controller) => this.removeController(controller);
5069
+ el.requestUpdate = () => this.requestUpdate();
5070
+ Object.defineProperty(el, "updateComplete", {
5071
+ configurable: true,
5072
+ get: () => this.updateComplete
5073
+ });
5074
+ }
5075
+ this.controllers.forEach((c) => c.hostConnected?.());
5076
+ }
5077
+ disconnectedCallback() {
5078
+ super.disconnectedCallback?.();
5079
+ this.#connected = false;
5080
+ this.controllers.forEach((c) => c.hostDisconnected?.());
5081
+ }
5082
+ async componentWillLoad() {
5083
+ await super.componentWillLoad?.();
5084
+ await Promise.all([...this.controllers].map((c) => c.hostWillLoad?.()));
5085
+ }
5086
+ componentDidLoad() {
5087
+ super.componentDidLoad?.();
5088
+ this.controllers.forEach((c) => c.hostDidLoad?.());
5089
+ }
5090
+ async componentWillRender() {
5091
+ await super.componentWillRender?.();
5092
+ await Promise.all([...this.controllers].map((c) => c.hostWillRender?.()));
5093
+ }
5094
+ componentDidRender() {
5095
+ super.componentDidRender?.();
5096
+ this.controllers.forEach((c) => c.hostDidRender?.());
5097
+ const resolvers = this.#updateCompleteResolvers;
5098
+ this.#updateCompleteResolvers = [];
5099
+ resolvers.forEach((resolve) => resolve(true));
5100
+ }
5101
+ async componentWillUpdate() {
5102
+ await super.componentWillUpdate?.();
5103
+ await Promise.all([...this.controllers].map((c) => c.hostWillUpdate?.()));
5104
+ }
5105
+ componentDidUpdate() {
5106
+ super.componentDidUpdate?.();
5107
+ this.controllers.forEach((c) => c.hostDidUpdate?.());
5108
+ }
5109
+ };
5110
+ //#endregion
4865
5111
  //#region src/runtime/render.ts
4866
5112
  /**
4867
5113
  * A WeakMap to persist HostRef objects across multiple render() calls to the
@@ -4948,4 +5194,4 @@ function hasKeys(obj) {
4948
5194
  return false;
4949
5195
  }
4950
5196
  //#endregion
4951
- export { AttachInternals, AttrDeserialize, BUILD, Build, Component, Element$1 as Element, Env, Event, Fragment, H, H as HTMLElement, HYDRATED_STYLE_ID, Host, Listen, Method, Mixin, NAMESPACE, Prop, PropSerialize, STENCIL_DEV_MODE, State, Watch, addHostEventListeners, bootstrapLazy, cmpModules, connectedCallback, consoleDevError, consoleDevInfo, consoleDevWarn, consoleError, createEvent, defineCustomElement, disconnectedCallback, forceModeUpdate, forceUpdate, getAssetPath, getElement, getHostRef, getMode, getRegistry, getRenderingRef, getShadowRoot, getValue, h, isMemberInElement, jsx, jsxDEV, jsxs, loadModule, modeResolutionChain, needsScopedSSR, nextTick, normalizeWatchers, parsePropertyValue, plt, postUpdateComponent, promiseResolve, proxyComponent, proxyCustomElement, readTask, registerHost, registerInstance, render, resolveVar, setAssetPath, setErrorHandler, setLazyLoadBasePath, setMode, setNonce, setPlatformHelpers, setPlatformOptions, setRegistry, setScopedSsr, setTagTransformer, setValue, styles, supportsConstructableStylesheets, supportsListenerOptions, supportsMutableAdoptedStyleSheets, transformTag, win, writeTask };
5197
+ export { AttachInternals, AttrDeserialize, BUILD, Build, Component, Element$1 as Element, Env, Event, Fragment, H, H as HTMLElement, HYDRATED_STYLE_ID, Host, Listen, Method, Mixin, NAMESPACE, Prop, PropSerialize, ReactiveControllerHost, STENCIL_DEV_MODE, State, Watch, addHostEventListeners, bootstrapLazy, cmpModules, connectedCallback, consoleDevError, consoleDevInfo, consoleDevWarn, consoleError, createEvent, defineCustomElement, disconnectedCallback, forceModeUpdate, forceUpdate, getAssetPath, getElement, getHostRef, getMode, getRegistry, getRenderingRef, getShadowRoot, getValue, h, isMemberInElement, jsx, jsxDEV, jsxs, loadModule, modeResolutionChain, needsScopedSSR, nextTick, normalizeWatchers, parsePropertyValue, plt, postUpdateComponent, promiseResolve, proxyComponent, proxyCustomElement, readTask, registerHost, registerInstance, render, resolveVar, setAssetPath, setErrorHandler, setLazyLoadBasePath, setMode, setNonce, setPlatformHelpers, setPlatformOptions, setRegistry, setScopedSsr, setTagTransformer, setValue, styles, supportsConstructableStylesheets, supportsListenerOptions, supportsMutableAdoptedStyleSheets, transformTag, win, writeTask };