@stencil/core 5.0.0-beta.9 → 5.0.0-rc.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 (40) hide show
  1. package/dist/app-data/index.d.ts +1 -1
  2. package/dist/app-data/index.js +1 -0
  3. package/dist/{client-BRu0GtRn.mjs → client-ClM4H9-P.mjs} +204 -76
  4. package/dist/compiler/browser.d.ts +120 -81
  5. package/dist/compiler/browser.js +964 -402
  6. package/dist/compiler/index.d.mts +110 -2
  7. package/dist/compiler/index.mjs +3 -3
  8. package/dist/compiler/utils/index.d.mts +2 -2
  9. package/dist/compiler/utils/index.mjs +3 -3
  10. package/dist/{compiler-wLrjuSOK.mjs → compiler-DFanjq9z.mjs} +5300 -3005
  11. package/dist/declarations/stencil-public-compiler.d.ts +178 -133
  12. package/dist/declarations/stencil-public-docs.d.ts +23 -0
  13. package/dist/declarations/stencil-public-runtime.d.ts +81 -59
  14. package/dist/{index-BvF31nqP.d.mts → index-DvfFOkiJ.d.mts} +220 -133
  15. package/dist/{index-BXAcVN2j.d.ts → index-XQHZl0MW.d.ts} +70 -57
  16. package/dist/{index-BAP9T4CB.d.mts → index-aBMJC5F9.d.mts} +6 -2
  17. package/dist/index.d.mts +3 -0
  18. package/dist/index.mjs +1 -1
  19. package/dist/jsx-runtime.d.mts +6 -0
  20. package/dist/jsx-runtime.mjs +1 -1
  21. package/dist/{node-75gQKkFz.mjs → node-DJP8JuAS.mjs} +42 -48
  22. package/dist/runtime/client/lazy.js +522 -262
  23. package/dist/runtime/client/runtime.d.ts +100 -68
  24. package/dist/runtime/client/runtime.js +522 -262
  25. package/dist/runtime/index.d.ts +6 -6
  26. package/dist/runtime/index.js +521 -261
  27. package/dist/runtime/server/index.d.mts +36 -12
  28. package/dist/runtime/server/index.mjs +635 -304
  29. package/dist/runtime/server/runner.d.mts +49 -6
  30. package/dist/runtime/server/runner.mjs +385 -87
  31. package/dist/signals/index.d.ts +11 -2
  32. package/dist/signals/index.js +15 -35
  33. package/dist/sys/node/index.d.mts +1 -1
  34. package/dist/sys/node/index.mjs +1 -1
  35. package/dist/sys/node/worker.mjs +2 -2
  36. package/dist/testing/index.d.mts +152 -124
  37. package/dist/testing/index.mjs +535 -269
  38. package/dist/{util-IKfWWLJo.mjs → util-C-H1H84W.mjs} +8 -1
  39. package/dist/{validation-DAdGTrys.mjs → validation-ByYYKvnS.mjs} +37 -3
  40. package/package.json +8 -4
@@ -1,6 +1,107 @@
1
1
  import { BUILD, BUILD as BUILD$1, Env, NAMESPACE, NAMESPACE as NAMESPACE$1 } from "@stencil/core/app-data";
2
2
  import { globalScripts, globalStyles } from "@stencil/core/app-globals";
3
- import { effect, effect as effect$1, signal } from "@preact/signals-core";
3
+ import * as SignalsCore from "@preact/signals-core";
4
+ //#region src/runtime/runtime-constants.ts
5
+ /**
6
+ * Bit flags for recording various properties of VDom nodes
7
+ */
8
+ const VNODE_FLAGS = {
9
+ /**
10
+ * Whether or not a vdom node is a slot reference
11
+ */
12
+ isSlotReference: 1,
13
+ /**
14
+ * Whether or not a slot element has fallback content
15
+ */
16
+ isSlotFallback: 2,
17
+ /**
18
+ * Whether or not an element is a host element
19
+ */
20
+ isHost: 4
21
+ };
22
+ const PROXY_FLAGS = {
23
+ isElementConstructor: 1,
24
+ proxyState: 2
25
+ };
26
+ const PLATFORM_FLAGS = {
27
+ /**
28
+ * designates a node in the DOM as being actively moved by the runtime
29
+ */
30
+ isTmpDisconnected: 1,
31
+ appLoaded: 2,
32
+ queueSync: 4,
33
+ queueMask: 6
34
+ };
35
+ /**
36
+ * A (subset) of node types which are relevant for the Stencil runtime. These
37
+ * values are based on the values which can possibly be returned by the
38
+ * `.nodeType` property of a DOM node. See here for details:
39
+ *
40
+ * {@link https://dom.spec.whatwg.org/#ref-for-dom-node-nodetype%E2%91%A0}
41
+ */
42
+ const NODE_TYPE = {
43
+ ElementNode: 1,
44
+ TextNode: 3,
45
+ CommentNode: 8,
46
+ DocumentNode: 9,
47
+ DocumentTypeNode: 10,
48
+ DocumentFragment: 11
49
+ };
50
+ const HYDRATE_ID = "s-id";
51
+ const HYDRATED_STYLE_ID = "sty-id";
52
+ const HYDRATE_CHILD_ID = "c-id";
53
+ /** `Symbol.for()` key of the `ssrProp()` registry on the server's real global object. */
54
+ const SSR_PROPS_REGISTRY_KEY = "stencil.ssrProps";
55
+ const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
56
+ const STENCIL_DOC_DATA = "_stencilDocData";
57
+ const DEFAULT_DOC_DATA = {
58
+ hostIds: 0,
59
+ rootLevelIds: 0,
60
+ staticComponents: /* @__PURE__ */ new Set()
61
+ };
62
+ /**
63
+ * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
64
+ *
65
+ * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
66
+ * support as of Stencil v4.
67
+ */
68
+ const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
69
+ const XLINK_NS = "http://www.w3.org/1999/xlink";
70
+ /**
71
+ * Minimum delay, in milliseconds, before retrying a failed lazy component load.
72
+ */
73
+ const LAZY_LOAD_RETRY_INTERVAL_MS = 1e3;
74
+ const FORM_ASSOCIATED_CUSTOM_ELEMENT_CALLBACKS = [
75
+ "formAssociatedCallback",
76
+ "formResetCallback",
77
+ "formDisabledCallback",
78
+ "formStateRestoreCallback"
79
+ ];
80
+ const SERVER_BUILD_FLAGS = {
81
+ isBrowser: false,
82
+ isServer: true,
83
+ isDev: false,
84
+ isTesting: false
85
+ };
86
+ //#endregion
87
+ //#region src/runtime/tag-transform.ts
88
+ let tagTransformer = void 0;
89
+ /**
90
+ * Transforms a tag name using the current tag transformer
91
+ * @param tag - the tag to transform e.g. `my-tag`
92
+ * @returns the transformed tag e.g. `new-my-tag`
93
+ */
94
+ function transformTag(tag) {
95
+ if (!tagTransformer) return tag;
96
+ return tagTransformer(tag);
97
+ }
98
+ /**
99
+ * Sets the tag transformer to be used when rendering custom elements
100
+ * @param transformer the transformer function to use. Must return a string
101
+ */
102
+ function setTagTransformer(transformer) {
103
+ tagTransformer = transformer;
104
+ }
4
105
  const MEMBER_FLAGS = {
5
106
  String: 1,
6
107
  Number: 2,
@@ -253,81 +354,6 @@ const reWireGetterSetter = (instance, hostRef) => {
253
354
  });
254
355
  };
255
356
  //#endregion
256
- //#region src/runtime/runtime-constants.ts
257
- /**
258
- * Bit flags for recording various properties of VDom nodes
259
- */
260
- const VNODE_FLAGS = {
261
- /**
262
- * Whether or not a vdom node is a slot reference
263
- */
264
- isSlotReference: 1,
265
- /**
266
- * Whether or not a slot element has fallback content
267
- */
268
- isSlotFallback: 2,
269
- /**
270
- * Whether or not an element is a host element
271
- */
272
- isHost: 4
273
- };
274
- const PROXY_FLAGS = {
275
- isElementConstructor: 1,
276
- proxyState: 2
277
- };
278
- const PLATFORM_FLAGS = {
279
- /**
280
- * designates a node in the DOM as being actively moved by the runtime
281
- */
282
- isTmpDisconnected: 1,
283
- appLoaded: 2,
284
- queueSync: 4,
285
- queueMask: 6
286
- };
287
- /**
288
- * A (subset) of node types which are relevant for the Stencil runtime. These
289
- * values are based on the values which can possibly be returned by the
290
- * `.nodeType` property of a DOM node. See here for details:
291
- *
292
- * {@link https://dom.spec.whatwg.org/#ref-for-dom-node-nodetype%E2%91%A0}
293
- */
294
- const NODE_TYPE = {
295
- ElementNode: 1,
296
- TextNode: 3,
297
- CommentNode: 8,
298
- DocumentNode: 9,
299
- DocumentTypeNode: 10,
300
- DocumentFragment: 11
301
- };
302
- const HYDRATE_ID = "s-id";
303
- const HYDRATED_STYLE_ID = "sty-id";
304
- const HYDRATE_CHILD_ID = "c-id";
305
- const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
306
- const STENCIL_DOC_DATA = "_stencilDocData";
307
- const DEFAULT_DOC_DATA = {
308
- hostIds: 0,
309
- rootLevelIds: 0,
310
- staticComponents: /* @__PURE__ */ new Set()
311
- };
312
- /**
313
- * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
314
- *
315
- * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
316
- * support as of Stencil v4.
317
- */
318
- const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
319
- const XLINK_NS = "http://www.w3.org/1999/xlink";
320
- /**
321
- * Minimum delay, in milliseconds, before retrying a failed lazy component load.
322
- */
323
- const LAZY_LOAD_RETRY_INTERVAL_MS = 1e3;
324
- const FORM_ASSOCIATED_CUSTOM_ELEMENT_CALLBACKS = [
325
- "formAssociatedCallback",
326
- "formResetCallback",
327
- "formDisabledCallback",
328
- "formStateRestoreCallback"
329
- ];
330
- //#endregion
331
357
  //#region src/utils/shadow-root.ts
332
358
  let globalStyleSheet;
333
359
  const GLOBAL_STYLE_ID = "sc-global";
@@ -342,6 +368,7 @@ function createShadowRoot(cmpMeta) {
342
368
  }
343
369
  if (BUILD$1.shadowClonable) opts.clonable = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowClonable);
344
370
  if (BUILD$1.shadowSerializable) opts.serializable = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowSerializable);
371
+ if (BUILD$1.shadowReferenceTarget && cmpMeta.$referenceTarget$) opts.referenceTarget = cmpMeta.$referenceTarget$;
345
372
  const shadowRoot = this.attachShadow(opts);
346
373
  if (BUILD$1.shadowModeClosed && isClosed) this.__shadowRoot = shadowRoot;
347
374
  if (globalStyleSheet === void 0) globalStyleSheet = null;
@@ -418,6 +445,7 @@ function getHostSlotNodes(childNodes, hostName, slotName) {
418
445
  if (typeof slotName !== "undefined") return slottedNodes;
419
446
  }
420
447
  slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
448
+ if (typeof slotName !== "undefined" && slottedNodes.length) return slottedNodes;
421
449
  }
422
450
  return slottedNodes;
423
451
  }
@@ -552,6 +580,7 @@ const applyLightDomPatches = (hostElementPrototype) => {
552
580
  patchSlotInsertAdjacentHTML(hostElementPrototype);
553
581
  patchInsertBefore(hostElementPrototype);
554
582
  patchTextContent(hostElementPrototype);
583
+ patchInnerContentSetters(hostElementPrototype);
555
584
  patchChildSlotNodes(hostElementPrototype);
556
585
  patchSlotRemoveChild(hostElementPrototype);
557
586
  };
@@ -616,11 +645,13 @@ const patchSlotAppendChild = (HostElementPrototype) => {
616
645
  const { slotName, slotNode } = findSlotFromSlottedNode(newChild, this);
617
646
  if (slotNode) {
618
647
  addSlotRelocateNode(newChild, slotNode);
648
+ patchSlottedNode(newChild);
619
649
  const slotChildNodes = getSlotChildSiblings(slotNode, slotName);
620
650
  const appendAfter = slotChildNodes[slotChildNodes.length - 1];
651
+ const slotWasEmpty = slotChildNodes.every((node) => node["s-sr"]);
621
652
  const insertedNode = internalCall(internalCall(appendAfter, "parentNode"), "insertBefore")(newChild, appendAfter.nextSibling);
622
653
  dispatchSlotChangeEvent(slotNode);
623
- updateFallbackSlotVisibility(this);
654
+ if (slotWasEmpty) updateFallbackSlotVisibility(this);
624
655
  return insertedNode;
625
656
  }
626
657
  return this.__appendChild(newChild);
@@ -638,8 +669,10 @@ const patchSlotRemoveChild = (ElementPrototype) => {
638
669
  ElementPrototype.__removeChild = ElementPrototype.removeChild;
639
670
  ElementPrototype.removeChild = function(toRemove) {
640
671
  if (toRemove && typeof toRemove["s-sn"] !== "undefined") {
641
- if (getHostSlotNodes(this.__childNodes || this.childNodes, this.tagName, toRemove["s-sn"]) && toRemove.isConnected) {
642
- toRemove.remove();
672
+ const slotNode = getHostSlotNodes(this.__childNodes || this.childNodes, this.tagName, toRemove["s-sn"])[0];
673
+ if (slotNode && toRemove.isConnected) {
674
+ removeSlottedNode(toRemove);
675
+ dispatchSlotChangeEvent(slotNode);
643
676
  updateFallbackSlotVisibility(this);
644
677
  return;
645
678
  }
@@ -662,6 +695,7 @@ const patchSlotPrepend = (HostElementPrototype) => {
662
695
  const slotNode = getHostSlotNodes(internalCall(this, "childNodes"), this.tagName, slotName)[0];
663
696
  if (slotNode) {
664
697
  addSlotRelocateNode(newChild, slotNode, true);
698
+ patchSlottedNode(newChild);
665
699
  const appendAfter = getSlotChildSiblings(slotNode, slotName)[0];
666
700
  const toReturn = internalCall(internalCall(appendAfter, "parentNode"), "insertBefore")(newChild, internalCall(appendAfter, "nextSibling"));
667
701
  dispatchSlotChangeEvent(slotNode);
@@ -725,25 +759,21 @@ const patchInsertBefore = (HostElementPrototype) => {
725
759
  eleProto.__insertBefore = HostElementPrototype.insertBefore;
726
760
  HostElementPrototype.insertBefore = function(newChild, currentChild) {
727
761
  const { slotName, slotNode } = findSlotFromSlottedNode(newChild, this);
728
- const slottedNodes = this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes);
729
762
  if (slotNode) {
730
- let found = false;
731
- slottedNodes.forEach((childNode) => {
732
- if (childNode === currentChild || currentChild === null) {
733
- found = true;
734
- if (currentChild === null || slotName !== currentChild["s-sn"]) {
735
- this.appendChild(newChild);
736
- return;
737
- }
738
- if (slotName === currentChild["s-sn"]) {
739
- addSlotRelocateNode(newChild, slotNode);
740
- internalCall(internalCall(currentChild, "parentNode"), "insertBefore")(newChild, currentChild);
741
- dispatchSlotChangeEvent(slotNode);
742
- }
743
- return;
763
+ if (currentChild === null) {
764
+ this.appendChild(newChild);
765
+ return newChild;
766
+ }
767
+ if ((this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes)).includes(currentChild)) {
768
+ if (slotName !== currentChild["s-sn"]) this.appendChild(newChild);
769
+ else {
770
+ addSlotRelocateNode(newChild, slotNode);
771
+ patchSlottedNode(newChild);
772
+ internalCall(internalCall(currentChild, "parentNode"), "insertBefore")(newChild, currentChild);
773
+ dispatchSlotChangeEvent(slotNode);
744
774
  }
745
- });
746
- if (found) return newChild;
775
+ return newChild;
776
+ }
747
777
  }
748
778
  /**
749
779
  * Fixes an issue where slotted elements are dynamically relocated in React, such as after data fetch.
@@ -770,18 +800,55 @@ const patchTextContent = (hostElementPrototype) => {
770
800
  Object.defineProperty(hostElementPrototype, "textContent", {
771
801
  get: function() {
772
802
  let text = "";
773
- (this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes)).forEach((node) => text += node.textContent || "");
803
+ (this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes)).forEach((node) => {
804
+ if (node.nodeType !== NODE_TYPE.CommentNode) text += node.textContent || "";
805
+ });
774
806
  return text;
775
807
  },
776
808
  set: function(value) {
777
- (this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes)).forEach((node) => {
778
- if (node["s-ol"]) node["s-ol"].remove();
779
- node.remove();
780
- });
781
- this.insertAdjacentHTML("beforeend", value);
809
+ removeSlottedNodes(this);
810
+ if (value != null && value !== "") this.append(this.ownerDocument.createTextNode(String(value)));
782
811
  }
783
812
  });
784
813
  };
814
+ /**
815
+ * Patches the `innerHTML` and `innerText` setters of a scoped component so they replace only
816
+ * the slotted content. Natively they would also remove the component's rendered nodes and its
817
+ * content reference node, leaving nothing for the next render to relocate into the slot.
818
+ * The getters are left as they are.
819
+ *
820
+ * @param hostElementPrototype the `Element` to be patched
821
+ */
822
+ const patchInnerContentSetters = (hostElementPrototype) => {
823
+ if (!globalThis.HTMLElement) return;
824
+ const patchSetter = (proto, name, insert) => {
825
+ const get = Object.getOwnPropertyDescriptor(proto, name)?.get;
826
+ if (!get) return;
827
+ Object.defineProperty(hostElementPrototype, name, {
828
+ get,
829
+ set: function(value) {
830
+ removeSlottedNodes(this);
831
+ Array.from(internalCall(this, "childNodes")).forEach((node) => {
832
+ if (!node["s-cn"] && !node["s-nr"] && node["s-hn"] !== this.tagName) node.remove();
833
+ });
834
+ insert(this, value ?? "");
835
+ }
836
+ });
837
+ };
838
+ patchSetter(Element.prototype, "innerHTML", (host, value) => host.insertAdjacentHTML("beforeend", value));
839
+ patchSetter(HTMLElement.prototype, "innerText", (host, value) => host.append(value));
840
+ };
841
+ /**
842
+ * Removes the slotted nodes of a scoped component, along with their original location markers.
843
+ *
844
+ * @param host the host element of the component
845
+ */
846
+ const removeSlottedNodes = (host) => {
847
+ (host.__childNodes ? host.childNodes : getSlottedChildNodes(host.childNodes)).forEach((node) => {
848
+ if (node["s-ol"]) node["s-ol"].remove();
849
+ node.remove();
850
+ });
851
+ };
785
852
  const patchChildSlotNodes = (elm) => {
786
853
  class FakeNodeList extends Array {
787
854
  item(n) {
@@ -815,10 +882,21 @@ const patchChildSlotNodes = (elm) => {
815
882
  } });
816
883
  };
817
884
  /**
818
- * Patches sibling accessors of a 'slotted' node within a non-shadow component.
819
- * Meaning whilst stepping through a non-shadow element's nodes, only the mock 'lightDOM' nodes are returned.
820
- * Especially relevant when rendering components via SSR... Frameworks will often try to reconcile their
821
- * VDOM with the real DOM by stepping through nodes with 'nextSibling' et al.
885
+ * Patches a node slotted into a non-shadow component so it behaves as it would in a native slot:
886
+ * - `parentNode` returns the host element
887
+ * - `remove()` fires `slotchange` on the node's slot
888
+ *
889
+ * @param node the slotted node to be patched
890
+ */
891
+ const patchSlottedNode = (node) => {
892
+ patchParentNode(node);
893
+ patchSlottedRemove(node);
894
+ };
895
+ /**
896
+ * Patches a slotted node from SSR markup: everything {@link patchSlottedNode} does, plus its
897
+ * sibling accessors, so whilst stepping through a non-shadow element's nodes only the mock
898
+ * 'lightDOM' nodes are returned. Frameworks hydrating SSR output often reconcile their VDOM with
899
+ * the real DOM by stepping through nodes with 'nextSibling' et al.
822
900
  * - `nextSibling`
823
901
  * - `nextElementSibling`
824
902
  * - `previousSibling`
@@ -826,11 +904,11 @@ const patchChildSlotNodes = (elm) => {
826
904
  *
827
905
  * @param node the slotted node to be patched
828
906
  */
829
- const patchSlottedNode = (node) => {
907
+ const patchSsrSlottedNode = (node) => {
830
908
  if (!node || node.__nextSibling !== void 0 || !globalThis.Node) return;
831
909
  patchNextSibling(node);
832
910
  patchPreviousSibling(node);
833
- patchParentNode(node);
911
+ patchSlottedNode(node);
834
912
  if (node.nodeType === Node.ELEMENT_NODE) {
835
913
  patchNextElementSibling(node);
836
914
  patchPreviousElementSibling(node);
@@ -897,6 +975,39 @@ const patchPreviousElementSibling = (element) => {
897
975
  } });
898
976
  };
899
977
  /**
978
+ * Detaches a slotted node from where it physically sits in the component's rendered DOM, through
979
+ * the unpatched accessors. Not via `remove()`: mock-doc's `remove()` calls
980
+ * `parentNode.removeChild()`, and a slotted node's patched `parentNode` is the host, whose patched
981
+ * `removeChild()` would come straight back here.
982
+ *
983
+ * @param node the slotted node to detach
984
+ */
985
+ const removeSlottedNode = (node) => {
986
+ const parent = internalCall(node, "parentNode");
987
+ if (parent) internalCall(parent, "removeChild")(node);
988
+ };
989
+ /**
990
+ * Patches `remove()` on a node slotted into a non-shadow component, so that removing it fires
991
+ * `slotchange` on its slot (and updates fallback content), as removing a node from a native slot
992
+ * does. Stencil's own node moves, while `isTmpDisconnected` is set, don't fire it.
993
+ *
994
+ * @param node the slotted node to patch
995
+ */
996
+ const patchSlottedRemove = (node) => {
997
+ const child = node;
998
+ if (!child || child.__remove || typeof child.remove !== "function") return;
999
+ child.__remove = child.remove;
1000
+ child.remove = function() {
1001
+ const host = this["s-ol"]?.parentElement;
1002
+ const { slotNode } = findSlotFromSlottedNode(this);
1003
+ removeSlottedNode(this);
1004
+ if (slotNode && !(plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected)) {
1005
+ dispatchSlotChangeEvent(slotNode);
1006
+ updateFallbackSlotVisibility(host);
1007
+ }
1008
+ };
1009
+ };
1010
+ /**
900
1011
  * Patches the `parentNode` accessor of a non-shadow slotted node
901
1012
  *
902
1013
  * @param node the slotted node to be patched
@@ -1146,13 +1257,15 @@ const addStyle = (styleContainerNode, cmpMeta, mode) => {
1146
1257
  const appliedStyles = getAppliedStyles(styleContainerNode);
1147
1258
  let styleElm;
1148
1259
  const existingStyleElm = (BUILD$1.hydrateClientSide || BUILD$1.hotModuleReplacement) && styleContainerNode.querySelector(`[sty-id="${scopeId}"]`);
1149
- if (existingStyleElm) existingStyleElm.textContent = style;
1150
- else if (!appliedStyles.has(scopeId)) {
1260
+ if (existingStyleElm) {
1261
+ if (BUILD$1.hotModuleReplacement) existingStyleElm.textContent = style;
1262
+ appliedStyles.add(scopeId);
1263
+ } else if (!appliedStyles.has(scopeId)) {
1151
1264
  styleElm = win.document.createElement("style");
1152
1265
  styleElm.textContent = style;
1153
1266
  const nonce = plt.$nonce$ ?? queryNonceMetaTagContent(win.document);
1154
1267
  if (nonce != null) styleElm.setAttribute("nonce", nonce);
1155
- if (BUILD$1.hydrateServerSide && (cmpMeta.$flags$ & CMP_FLAGS.scopedCssEncapsulation || cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss || cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) || BUILD$1.hotModuleReplacement) styleElm.setAttribute(HYDRATED_STYLE_ID, scopeId);
1268
+ if (BUILD$1.hydrateServerSide || BUILD$1.hotModuleReplacement) styleElm.setAttribute(HYDRATED_STYLE_ID, scopeId);
1156
1269
  if (BUILD$1.hotModuleReplacement && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation) styleElm.setAttribute("data-slot-fb", "");
1157
1270
  /**
1158
1271
  * attach styles at the end of the head tag if we render scoped components
@@ -1274,20 +1387,28 @@ const getScopeId = (cmp, mode) => "sc-" + (BUILD$1.mode && mode && cmp.$flags$ &
1274
1387
  */
1275
1388
  const convertScopedToShadow = (css) => css.replace(/\/\*!@([^/]+)\*\/[^{]+\{/g, "$1{");
1276
1389
  /**
1277
- * Hydrate styles after SSR for components *not* using DSD. Convert 'scoped' styles to 'shadow'
1278
- * and add them to a constructable stylesheet.
1390
+ * Hydrate styles after SSR for shadow components that were serialized as 'scoped' (not DSD).
1391
+ * Convert their 'scoped' styles back to 'shadow' and add them to a constructable stylesheet.
1279
1392
  *
1280
- * @returns void
1393
+ * Sheets of scoped and non-encapsulated components are left alone so they stay in the
1394
+ * document head, where `addStyle()` reuses them.
1395
+ *
1396
+ * @param cmpMetas the components whose server-rendered styles may need converting
1281
1397
  */
1282
- const hydrateScopedToShadow = () => {
1398
+ const hydrateScopedToShadow = (cmpMetas) => {
1283
1399
  if (!win.document) return;
1284
- const styleElements = win.document.querySelectorAll(`[${HYDRATED_STYLE_ID}]`);
1400
+ const styleElms = win.document.querySelectorAll(`[${HYDRATED_STYLE_ID}]`);
1285
1401
  let i = 0;
1286
- for (; i < styleElements.length; i++) {
1287
- const scopeId = styleElements[i].getAttribute(HYDRATED_STYLE_ID);
1288
- const existing = styles.get(scopeId);
1289
- const allowCS = existing !== void 0 ? existing instanceof CSSStyleSheet : true;
1290
- registerStyle(scopeId, convertScopedToShadow(styleElements[i].innerHTML), allowCS);
1402
+ for (; i < styleElms.length; i++) {
1403
+ const scopeId = styleElms[i].getAttribute(HYDRATED_STYLE_ID);
1404
+ if (cmpMetas.some((cmpMeta) => {
1405
+ const cmpScopeId = "sc-" + cmpMeta.$tagName$;
1406
+ return cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation && (scopeId === cmpScopeId || BUILD$1.mode && cmpMeta.$flags$ & CMP_FLAGS.hasMode && scopeId.startsWith(cmpScopeId + "-"));
1407
+ })) {
1408
+ const existing = styles.get(scopeId);
1409
+ const allowCS = existing !== void 0 ? existing instanceof CSSStyleSheet : true;
1410
+ registerStyle(scopeId, convertScopedToShadow(styleElms[i].innerHTML), allowCS);
1411
+ }
1291
1412
  }
1292
1413
  };
1293
1414
  //#endregion
@@ -1300,6 +1421,13 @@ const hydrateScopedToShadow = () => {
1300
1421
  */
1301
1422
  const isDef = (v) => v != null && v !== void 0;
1302
1423
  /**
1424
+ * Convert a string from PascalCase to dash-case
1425
+ *
1426
+ * @param str the string to convert
1427
+ * @returns a converted string
1428
+ */
1429
+ const toDashCase = (str) => str.replace(/([A-Z0-9])/g, (match) => ` ${match[0]}`).trim().split(" ").join("-").toLowerCase();
1430
+ /**
1303
1431
  * Check whether a value is a 'complex type', defined here as an object or a
1304
1432
  * function.
1305
1433
  *
@@ -1311,6 +1439,13 @@ const isComplexType = (o) => {
1311
1439
  return o === "object" || o === "function";
1312
1440
  };
1313
1441
  //#endregion
1442
+ //#region src/runtime/signals-core.ts
1443
+ const getCore = () => globalThis[Symbol.for("stencil.preact-signals-core")] ??= SignalsCore;
1444
+ const effect = (fn, options) => getCore().effect(fn, options);
1445
+ function signal(value, options) {
1446
+ return getCore().signal(value, options);
1447
+ }
1448
+ //#endregion
1314
1449
  //#region src/runtime/event-emitter.ts
1315
1450
  const createEvent = (ref, name, flags) => {
1316
1451
  const elm = getElement(ref);
@@ -1336,7 +1471,12 @@ const emitEvent = (elm, name, opts) => {
1336
1471
  elm.dispatchEvent(ev);
1337
1472
  return ev;
1338
1473
  };
1339
- const getRegistry = () => customElements;
1474
+ const getRegistry = () => globalThis.customElements;
1475
+ /**
1476
+ * @param elm a defined component host
1477
+ * @returns the registry the host's class was defined in, else the active registry
1478
+ */
1479
+ const getHostRegistry = (elm) => elm.constructor._registry ?? getRegistry();
1340
1480
  //#endregion
1341
1481
  //#region src/runtime/vdom/set-accessor.ts
1342
1482
  /**
@@ -1380,7 +1520,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1380
1520
  attrMap.get(memberName)?.();
1381
1521
  if (!signalAttrDisposers.has(elm)) signalAttrDisposers.set(elm, attrMap);
1382
1522
  let prevVal = oldValue;
1383
- attrMap.set(memberName, effect$1(() => {
1523
+ attrMap.set(memberName, effect(() => {
1384
1524
  const curVal = newValue.value;
1385
1525
  setAccessor(elm, memberName, prevVal, curVal, isSvg, flags);
1386
1526
  prevVal = curVal;
@@ -1460,10 +1600,10 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1460
1600
  const isComplex = isComplexType(newValue);
1461
1601
  if (!BUILD$1.lazyLoad) {
1462
1602
  const isStandardAttr = ln.startsWith("aria-") || ln.startsWith("data-");
1463
- if (!isProp && !isStandardAttr && elm.tagName?.includes("-") && elm.tagName !== "SLOT-FB" && typeof customElements !== "undefined" && !customElements.get(elm.tagName.toLowerCase())) {
1603
+ if (!isProp && !isStandardAttr && elm.tagName?.includes("-") && elm.tagName !== "SLOT-FB" && !customElements.get(elm.tagName.toLowerCase())) {
1464
1604
  if (!elm["s-pp"]) elm["s-pp"] = /* @__PURE__ */ new Map();
1465
1605
  elm["s-pp"].set(memberName, newValue);
1466
- return;
1606
+ if (isComplex || /[A-Z]/.test(memberName)) return;
1467
1607
  }
1468
1608
  }
1469
1609
  if ((isProp || isComplex && newValue !== null) && !isSvg) try {
@@ -1490,7 +1630,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1490
1630
  xlink = true;
1491
1631
  }
1492
1632
  }
1493
- if (newValue == null || newValue === false) {
1633
+ if (newValue == null || newValue === false || isComplex) {
1494
1634
  if (newValue !== false || elm.getAttribute(memberName) === "" || flags & VNODE_FLAGS.isHost && !isEnumeratedAttribute(memberName)) {
1495
1635
  if (BUILD$1.vdomXlink && xlink) elm.removeAttributeNS(XLINK_NS, memberName);
1496
1636
  else elm.removeAttribute(memberName);
@@ -1581,8 +1721,10 @@ function sortedAttrNames(attrNames) {
1581
1721
  let scopeId;
1582
1722
  let contentRef;
1583
1723
  let hostTagName;
1724
+ let hostRegistry;
1584
1725
  let useNativeShadowDom = false;
1585
1726
  let checkSlotFallbackVisibility = false;
1727
+ /** Whether the current render has slotted content to relocate. Set at the start of each render. */
1586
1728
  let checkSlotRelocate = false;
1587
1729
  let isSvgMode = false;
1588
1730
  /**
@@ -1590,6 +1732,7 @@ let isSvgMode = false;
1590
1732
  * These ensure that ref callbacks are called in the correct order:
1591
1733
  * first all removal callbacks (with null), then all attachment callbacks (with elements).
1592
1734
  */
1735
+ const initialSlotChanges = /* @__PURE__ */ new Set();
1593
1736
  const refCallbacksToRemove = [];
1594
1737
  const refCallbacksToAttach = [];
1595
1738
  /** Disposers for signal subscriptions on individual DOM nodes (text nodes, <s-show> wrappers). */
@@ -1597,16 +1740,33 @@ const signalNodeDisposers = /* @__PURE__ */ new WeakMap();
1597
1740
  const disposeSignalVNode = (vnode) => {
1598
1741
  const elm = vnode.$elm$;
1599
1742
  if (elm) {
1600
- const dispose = signalNodeDisposers.get(elm);
1601
- if (dispose) {
1602
- dispose();
1603
- signalNodeDisposers.delete(elm);
1604
- }
1743
+ disposeTextSignal(elm);
1605
1744
  disposeAllSignalAttrs(elm);
1606
1745
  }
1607
1746
  vnode.$children$?.forEach(disposeSignalVNode);
1608
1747
  };
1609
1748
  /**
1749
+ * Tear down a text node's signal subscription, if it has one.
1750
+ * @param textNode the text node to unsubscribe
1751
+ */
1752
+ const disposeTextSignal = (textNode) => {
1753
+ const dispose = signalNodeDisposers.get(textNode);
1754
+ if (dispose) {
1755
+ dispose();
1756
+ signalNodeDisposers.delete(textNode);
1757
+ }
1758
+ };
1759
+ /**
1760
+ * Subscribe a text node to a signal, keeping its `data` in sync on every change.
1761
+ * @param textNode the text node to keep in sync
1762
+ * @param textSig the signal to subscribe to
1763
+ */
1764
+ const wireTextSignal = (textNode, textSig) => {
1765
+ signalNodeDisposers.set(textNode, effect(() => {
1766
+ textNode.data = String(textSig.value);
1767
+ }));
1768
+ };
1769
+ /**
1610
1770
  * Create a DOM Node corresponding to one of the children of a given VNode.
1611
1771
  *
1612
1772
  * @param oldParentVNode the parent VNode from the previous render
@@ -1628,13 +1788,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex) => {
1628
1788
  if (BUILD$1.isDev && newVNode.$elm$) newVNode.$text$ !== null ? `${newVNode.$text$}` : `${String(newVNode.$tag$)}`;
1629
1789
  if (BUILD$1.vdomText && newVNode.$text$ != null) {
1630
1790
  elm = newVNode.$elm$ = win.document.createTextNode(newVNode.$text$);
1631
- if (BUILD$1.vdomSignals && newVNode.$signal$) {
1632
- const textSig = newVNode.$signal$;
1633
- const textNode = elm;
1634
- signalNodeDisposers.set(textNode, effect$1(() => {
1635
- textNode.data = String(textSig.value);
1636
- }));
1637
- }
1791
+ if (BUILD$1.vdomSignals && newVNode.$signal$) wireTextSignal(elm, newVNode.$signal$);
1638
1792
  } else if (BUILD$1.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotReference) {
1639
1793
  elm = newVNode.$elm$ = BUILD$1.isDebug || BUILD$1.hydrateServerSide ? slotReferenceDebugNode(newVNode) : win.document.createTextNode("");
1640
1794
  if (typeof newVNode.$attrs$?.slot === "string") elm["s-sa"] = newVNode.$attrs$.slot;
@@ -1643,8 +1797,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex) => {
1643
1797
  if (BUILD$1.svg && !isSvgMode) isSvgMode = newVNode.$tag$ === "svg";
1644
1798
  if (!win.document) throw new Error("No DOM environment available for rendering.");
1645
1799
  const tag = !useNativeShadowDom && BUILD$1.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotFallback ? "slot-fb" : newVNode.$tag$;
1646
- const _reg = getRegistry();
1647
- const registryOpts = _reg !== win.customElements && tag.includes("-") ? { customElementRegistry: _reg } : void 0;
1800
+ const registryOpts = hostRegistry !== win.customElements && tag.includes("-") ? { customElementRegistry: hostRegistry } : void 0;
1648
1801
  elm = newVNode.$elm$ = BUILD$1.svg && isSvgMode ? win.document.createElementNS(SVG_NS, tag) : win.document.createElement(tag, registryOpts);
1649
1802
  if (BUILD$1.svg && isSvgMode && newVNode.$tag$ === "foreignObject") isSvgMode = false;
1650
1803
  if (BUILD$1.vdomAttribute) updateElement(null, newVNode, isSvgMode);
@@ -1902,7 +2055,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = fal
1902
2055
  }
1903
2056
  if (BUILD$1.vdomKey && idxInOld >= 0) {
1904
2057
  elmToMove = oldCh[idxInOld];
1905
- if (elmToMove.$tag$ !== newStartVnode.$tag$) node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
2058
+ if (elmToMove.$tag$ !== newStartVnode.$tag$) node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
1906
2059
  else {
1907
2060
  patch(elmToMove, newStartVnode, isInitialRender);
1908
2061
  oldCh[idxInOld] = void 0;
@@ -1995,7 +2148,17 @@ const patch = (oldVNode, newVNode, isInitialRender = false) => {
1995
2148
  else if (BUILD$1.hydrateClientSide && isInitialRender && BUILD$1.updatable && oldChildren !== null && newChildren === null) newVNode.$children$ = oldChildren;
1996
2149
  if (BUILD$1.svg && isSvgMode && tag === "svg") isSvgMode = false;
1997
2150
  } else if (BUILD$1.vdomText && BUILD$1.slotRelocation && (defaultHolder = elm["s-cr"])) defaultHolder.parentNode.textContent = text;
1998
- else if (BUILD$1.vdomText && oldVNode.$text$ !== text) elm.data = text;
2151
+ else if (BUILD$1.vdomText) {
2152
+ if (BUILD$1.vdomSignals && newVNode.$signal$) {
2153
+ if (newVNode.$signal$ !== oldVNode.$signal$) {
2154
+ disposeTextSignal(elm);
2155
+ wireTextSignal(elm, newVNode.$signal$);
2156
+ }
2157
+ } else {
2158
+ if (BUILD$1.vdomSignals && oldVNode.$signal$) disposeTextSignal(elm);
2159
+ if (oldVNode.$text$ !== text) elm.data = text;
2160
+ }
2161
+ }
1999
2162
  };
2000
2163
  /**
2001
2164
  * Component-global information about nodes which are either currently being
@@ -2121,13 +2284,17 @@ const flushQueuedRefCallbacks = () => {
2121
2284
  */
2122
2285
  const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2123
2286
  if (BUILD$1.slotRelocation) {
2287
+ if (parent?.["s-cr"]) checkSlotRelocate = true;
2124
2288
  if (BUILD$1.scoped && typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
2125
2289
  else if (typeof newNode["s-sn"] === "string") {
2126
2290
  const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2127
- if ((BUILD$1.lightDomPatches || BUILD$1.slotChildNodes || BUILD$1.patchAll && !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchParentNode(newNode);
2291
+ if ((BUILD$1.lightDomPatches || BUILD$1.slotChildNodes || BUILD$1.patchAll && !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchSlottedNode(newNode);
2128
2292
  parent.insertBefore(newNode, reference);
2129
2293
  const { slotNode } = findSlotFromSlottedNode(newNode);
2130
- if (slotNode && !isInitialLoad) dispatchSlotChangeEvent(slotNode);
2294
+ if (slotNode) {
2295
+ if (isInitialLoad) initialSlotChanges.add(slotNode);
2296
+ else dispatchSlotChangeEvent(slotNode);
2297
+ }
2131
2298
  return newNode;
2132
2299
  }
2133
2300
  }
@@ -2183,6 +2350,7 @@ const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
2183
2350
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
2184
2351
  const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
2185
2352
  hostTagName = hostElm.tagName;
2353
+ hostRegistry = getHostRegistry(hostElm);
2186
2354
  if (BUILD$1.isDev && Array.isArray(renderFnResults) && renderFnResults.some(isHost)) throw new Error(`The <Host> must be the single root component.
2187
2355
  Looks like the render() function of "${hostTagName.toLowerCase()}" is returning an array that contains the <Host>.
2188
2356
 
@@ -2219,6 +2387,7 @@ render() {
2219
2387
  if (BUILD$1.slotRelocation) {
2220
2388
  contentRef = hostElm["s-cr"];
2221
2389
  checkSlotFallbackVisibility = false;
2390
+ checkSlotRelocate = !useNativeShadowDom && !!(cmpMeta.$flags$ & CMP_FLAGS.hasSlot);
2222
2391
  }
2223
2392
  patch(oldVNode, rootVnode, isInitialLoad);
2224
2393
  if (BUILD$1.slotRelocation) {
@@ -2282,8 +2451,13 @@ render() {
2282
2451
  if (checkSlotFallbackVisibility) updateFallbackSlotVisibility(rootVnode.$elm$);
2283
2452
  plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
2284
2453
  relocateNodes.length = 0;
2454
+ if (initialSlotChanges.size) {
2455
+ const slotNodes = [...initialSlotChanges];
2456
+ initialSlotChanges.clear();
2457
+ nextTick(() => slotNodes.forEach(dispatchSlotChangeEvent));
2458
+ }
2285
2459
  }
2286
- if (BUILD$1.slotRelocation && !useNativeShadowDom && !(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && hostElm["s-cr"]) {
2460
+ if (BUILD$1.slotRelocation && !(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && hostElm["s-cr"]) {
2287
2461
  const children = rootVnode.$elm$.__childNodes || rootVnode.$elm$.childNodes;
2288
2462
  for (const childNode of children) if (childNode["s-hn"] !== hostTagName && childNode["s-sh"] !== hostTagName) {
2289
2463
  if (isInitialLoad && childNode["s-ih"] == null) childNode["s-ih"] = childNode.hidden ?? false;
@@ -2335,11 +2509,12 @@ const markFirstConnected = (hostRef) => {
2335
2509
  * autoloader, where the ancestor tag may not be defined yet.
2336
2510
  *
2337
2511
  * @param ancestorElm the nearest Stencil ancestor element
2512
+ * @param registry the registry the waiting component is defined in
2338
2513
  */
2339
- const awaitAncestorConnected = async (ancestorElm) => {
2514
+ const awaitAncestorConnected = async (ancestorElm, registry) => {
2340
2515
  let ancestorHostRef = getHostRef(ancestorElm);
2341
2516
  if (!BUILD$1.lazyLoad && !ancestorHostRef) {
2342
- await getRegistry().whenDefined(ancestorElm.tagName.toLowerCase());
2517
+ await registry.whenDefined(ancestorElm.tagName.toLowerCase());
2343
2518
  ancestorHostRef = getHostRef(ancestorElm);
2344
2519
  }
2345
2520
  if (ancestorHostRef && !(ancestorHostRef.$flags$ & HOST_FLAGS.hasFiredConnected)) await ensureFirstConnectPromise(ancestorHostRef);
@@ -2695,8 +2870,7 @@ const initializeSignals = (elm, hostRef, cmpMeta) => {
2695
2870
  const instance = BUILD$1.lazyLoad ? hostRef.$lazyInstance$ : elm;
2696
2871
  for (const [memberName, [memberFlags]] of Object.entries(cmpMeta.$members$ ?? {})) {
2697
2872
  if (!(memberFlags & MEMBER_FLAGS.PropLike)) continue;
2698
- const initialVal = hostRef.$instanceValues$.get(memberName);
2699
- const sig = signal(initialVal);
2873
+ const sig = signal(hostRef.$instanceValues$.get(memberName));
2700
2874
  hostRef.$signalValues$.set(memberName, sig);
2701
2875
  let prevScheduleVal = sig.peek();
2702
2876
  disposers.push(effect(() => {
@@ -2875,17 +3049,23 @@ const vdomFnUtils = {
2875
3049
  * Convert a {@link d.VNode} to a {@link d.ChildNode} in order to present a
2876
3050
  * friendlier public interface (hence, 'convertToPublic').
2877
3051
  *
2878
- * @param node the virtual DOM node to convert
3052
+ * Functional components receive primitive children unwrapped, so those
3053
+ * become text-only child nodes.
3054
+ *
3055
+ * @param node the virtual DOM node (or primitive child) to convert
2879
3056
  * @returns a converted child node
2880
3057
  */
2881
- const convertToPublic = (node) => ({
3058
+ const convertToPublic = (node) => typeof node !== "object" ? {
3059
+ vtag: null,
3060
+ vtext: String(node)
3061
+ } : {
2882
3062
  vattrs: node.$attrs$,
2883
3063
  vchildren: node.$children$,
2884
3064
  vkey: node.$key$,
2885
3065
  vname: node.$name$,
2886
3066
  vtag: node.$tag$,
2887
3067
  vtext: node.$text$
2888
- });
3068
+ };
2889
3069
  /**
2890
3070
  * Convert a {@link d.ChildNode} back to an equivalent {@link d.VNode} in
2891
3071
  * order to use the resulting object in the virtual DOM. The initial object was
@@ -2902,11 +3082,11 @@ const convertToPrivate = (node) => {
2902
3082
  if (node.vname) vnodeData.name = node.vname;
2903
3083
  return h(node.vtag, vnodeData, ...node.vchildren || []);
2904
3084
  }
2905
- const vnode = newVNode(node.vtag, node.vtext);
2906
- vnode.$attrs$ = node.vattrs;
2907
- vnode.$children$ = node.vchildren;
2908
- vnode.$key$ = node.vkey;
2909
- vnode.$name$ = node.vname;
3085
+ const vnode = newVNode(node.vtag ?? null, node.vtext);
3086
+ vnode.$attrs$ = node.vattrs ?? null;
3087
+ vnode.$children$ = node.vchildren ?? null;
3088
+ vnode.$key$ = node.vkey ?? null;
3089
+ vnode.$name$ = node.vname ?? null;
2910
3090
  return vnode;
2911
3091
  };
2912
3092
  /**
@@ -2956,7 +3136,10 @@ const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
2956
3136
  hostElm.classList.add(scopeId + "-h");
2957
3137
  } else if (hostElm["s-sc"]) delete hostElm["s-sc"];
2958
3138
  }
2959
- if (win.document && (!plt.$orgLocNodes$ || !plt.$orgLocNodes$.size)) initializeDocumentHydrate(win.document.body, plt.$orgLocNodes$ = /* @__PURE__ */ new Map());
3139
+ if (win.document && !plt.$orgLocNodes$?.has(hostId)) {
3140
+ initializeDocumentHydrate(win.document.body, plt.$orgLocNodes$ ??= /* @__PURE__ */ new Map());
3141
+ plt.$orgLocNodes$.set(hostId, hostElm);
3142
+ }
2960
3143
  hostElm[HYDRATE_ID] = hostId;
2961
3144
  hostElm.removeAttribute(HYDRATE_ID);
2962
3145
  hostRef.$vnode$ = clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId, slottedNodes);
@@ -2969,7 +3152,7 @@ const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
2969
3152
  const orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
2970
3153
  const node = childRenderNode.$elm$;
2971
3154
  if (!shadowRoot) {
2972
- node["s-hn"] = transformTag(tagName).toUpperCase();
3155
+ if (childRenderNode.$hostId$ === hostId) node["s-hn"] = transformTag(tagName).toUpperCase();
2973
3156
  if (childRenderNode.$tag$ === "slot") node["s-cr"] = hostElm["s-cr"];
2974
3157
  } else if (childRenderNode.$tag$?.toString().includes("-") && childRenderNode.$tag$ !== "slot-fb" && !childRenderNode.$elm$.shadowRoot) {
2975
3158
  const cmpMeta = getHostRef(childRenderNode.$elm$);
@@ -3019,14 +3202,10 @@ const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
3019
3202
  const siSlot = slottedItem.slot;
3020
3203
  if (hostEle.shadowRoot && siNode.parentElement !== hostEle) hostEle.insertBefore(siNode, slotGroup[snGroupIdx - 1]?.node?.nextSibling);
3021
3204
  if (!hostEle.shadowRoot || !shadowRoot) {
3022
- if (!siSlot["s-cr"]) {
3023
- siSlot["s-cr"] = hostEle["s-cr"];
3024
- if (!siSlot["s-cr"] && hostEle.shadowRoot) siSlot["s-cr"] = hostEle;
3025
- else siSlot["s-cr"] = (hostEle.__childNodes || hostEle.childNodes)[0];
3026
- }
3205
+ if (!siSlot["s-cr"]) siSlot["s-cr"] = hostEle["s-cr"] || (hostEle.shadowRoot ? hostEle : (hostEle.__childNodes || hostEle.childNodes)[0]);
3027
3206
  addSlotRelocateNode(siNode, siSlot, false, siNode["s-oo"] || currentPos);
3028
3207
  if (siNode.parentElement?.shadowRoot && siNode["getAttribute"] && siNode.getAttribute("slot")) siNode.removeAttribute("slot");
3029
- if (BUILD$1.lightDomPatches || BUILD$1.slotChildNodes || BUILD$1.patchAll && hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll) patchSlottedNode(siNode);
3208
+ if (BUILD$1.lightDomPatches || BUILD$1.slotChildNodes || BUILD$1.patchAll && hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll) patchSsrSlottedNode(siNode);
3030
3209
  }
3031
3210
  currentPos = (siNode["s-oo"] || currentPos) + 1;
3032
3211
  }
@@ -3086,7 +3265,7 @@ const clientHydrate = (parentVNode, childRenderNodes, slotNodes, shadowRootNodes
3086
3265
  const scopeId = hostElm["s-sc"];
3087
3266
  if (node.nodeType === NODE_TYPE.ElementNode) {
3088
3267
  childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
3089
- if (childNodeType) {
3268
+ if (childNodeType && node !== hostElm) {
3090
3269
  childIdSplt = childNodeType.split(".");
3091
3270
  if (childIdSplt[0] === hostId || childIdSplt[0] === "0") {
3092
3271
  childVNode = createSimpleVNode({
@@ -3204,6 +3383,7 @@ const initializeDocumentHydrate = (node, orgLocNodes) => {
3204
3383
  const createSimpleVNode = (vnode) => ({
3205
3384
  $flags$: 0,
3206
3385
  $index$: "0",
3386
+ $children$: null,
3207
3387
  ...vnode
3208
3388
  });
3209
3389
  function addSlot(slotName, slotId, childVNode, node, parentVNode, childRenderNodes, slotNodes, shadowRootNodes, slottedNodes) {
@@ -3267,6 +3447,11 @@ const addSlottedNodes = (slottedNodes, slotNodeId, slotName, slotNode, hostId) =
3267
3447
  * @returns the first corresponding node of the type
3268
3448
  */
3269
3449
  const findCorrespondingNode = (node, type) => {
3450
+ if (type === NODE_TYPE.TextNode) {
3451
+ const next = node.nextSibling;
3452
+ if (next?.nodeType === NODE_TYPE.TextNode) return next;
3453
+ return node.parentNode.insertBefore(node.ownerDocument.createTextNode(""), next);
3454
+ }
3270
3455
  let sibling = node;
3271
3456
  do
3272
3457
  sibling = sibling.nextSibling;
@@ -3598,7 +3783,7 @@ const scopeSelector = (selector, scopeSelectorText, hostSelector, slotSelector)
3598
3783
  else return shallowPart.trim();
3599
3784
  }).join(", ");
3600
3785
  };
3601
- const isScopableAtRule = (selector) => selector.startsWith("@media") || selector.startsWith("@supports") || selector.startsWith("@page") || selector.startsWith("@document") || selector.startsWith("@layer");
3786
+ const isScopableAtRule = (selector) => selector.startsWith("@media") || selector.startsWith("@supports") || selector.startsWith("@page") || selector.startsWith("@document") || selector.startsWith("@layer") || selector.startsWith("@container");
3602
3787
  const scopeSelectors = (cssText, scopeSelectorText, hostSelector, slotSelector, commentOriginalSelector) => {
3603
3788
  return processRules(cssText, (rule) => {
3604
3789
  let selector = rule.selector;
@@ -3717,8 +3902,11 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
3717
3902
  };
3718
3903
  //#endregion
3719
3904
  //#region src/runtime/mode.ts
3720
- const computeMode = (elm) => modeResolutionChain.map((h) => h(elm)).find((m) => !!m);
3721
- const setMode = (handler) => modeResolutionChain.push(handler);
3905
+ const computeMode = (elm) => modeResolver.map((h) => h(elm)).find((m) => !!m);
3906
+ const setMode = (handler) => {
3907
+ modeResolver.length = 0;
3908
+ modeResolver.push(handler);
3909
+ };
3722
3910
  const getMode = (ref) => getHostRef(ref)?.$modeName$;
3723
3911
  //#endregion
3724
3912
  //#region src/runtime/normalize-watchers.ts
@@ -3783,23 +3971,14 @@ const normalizeWatchers = (raw) => {
3783
3971
  *
3784
3972
  * @param propValue the new value to coerce to some type
3785
3973
  * @param propType the type of the prop, expressed as a binary number
3786
- * @param isFormAssociated whether the component is form-associated (optional)
3787
3974
  * @returns the parsed/coerced value
3788
3975
  */
3789
- const parsePropertyValue = (propValue, propType, isFormAssociated) => {
3976
+ const parsePropertyValue = (propValue, propType) => {
3790
3977
  if (propValue != null && !isComplexType(propValue)) {
3791
3978
  /**
3792
3979
  * ensure this value is of the correct prop type
3793
3980
  */
3794
- if (BUILD$1.propBoolean && propType & MEMBER_FLAGS.Boolean) {
3795
- /**
3796
- * For form-associated components, according to HTML spec, the presence of any boolean attribute
3797
- * (regardless of its value, even "false") should make the property true.
3798
- * For non-form-associated components, we maintain the legacy behavior where "false" becomes false.
3799
- */
3800
- if (BUILD$1.formAssociated && isFormAssociated && typeof propValue === "string") return propValue === "" || !!propValue;
3801
- else return propValue === "false" ? false : propValue === "" || !!propValue;
3802
- }
3981
+ if (BUILD$1.propBoolean && propType & MEMBER_FLAGS.Boolean) return propValue === "" || !!propValue;
3803
3982
  /**
3804
3983
  * force it to be a number
3805
3984
  */
@@ -3841,7 +4020,7 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
3841
4020
  if (BUILD$1.signalBacking) {
3842
4021
  const sig = hostRef?.$signalValues$?.get(propName);
3843
4022
  if (sig !== void 0) {
3844
- const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0], BUILD$1.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
4023
+ const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
3845
4024
  if (BUILD$1.serializer && BUILD$1.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) {
3846
4025
  const elm = BUILD$1.lazyLoad ? hostRef.$hostElement$ : ref;
3847
4026
  applySerializers(hostRef, cmpMeta, propName, parsed, BUILD$1.lazyLoad ? hostRef.$lazyInstance$ : elm);
@@ -3859,7 +4038,7 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
3859
4038
  const oldVal = hostRef.$instanceValues$.get(propName);
3860
4039
  const flags = hostRef.$flags$;
3861
4040
  const instance = BUILD$1.lazyLoad ? hostRef.$lazyInstance$ : elm;
3862
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0], BUILD$1.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
4041
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
3863
4042
  const didValueChange = newVal !== oldVal && !(Number.isNaN(oldVal) && Number.isNaN(newVal));
3864
4043
  if ((!BUILD$1.lazyLoad || !(flags & HOST_FLAGS.isConstructingInstance) || oldVal === void 0) && didValueChange) {
3865
4044
  hostRef.$instanceValues$.set(propName, newVal);
@@ -3908,6 +4087,22 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
3908
4087
  */
3909
4088
  const reflectedAttrValue = (propValue) => propValue == null || propValue === false ? null : propValue === true ? "" : String(propValue);
3910
4089
  /**
4090
+ * Hand values written to a lazy component's element before its instance existed to the
4091
+ * instance's own `@Prop` setters. Must run as soon as the instance is constructed, so that
4092
+ * whenever `$lazyInstance$` is set, reads through it agree with the element's last write.
4093
+ *
4094
+ * @param hostRef the runtime bookkeeping object of a freshly constructed lazy instance
4095
+ * @param cmpMeta runtime metadata for the component (with any run-time only setters flagged)
4096
+ */
4097
+ const replayPendingSetterValues = (hostRef, cmpMeta) => {
4098
+ const instance = hostRef.$lazyInstance$;
4099
+ if (!instance) return;
4100
+ for (const [memberName, [memberFlags]] of Object.entries(cmpMeta.$members$ ?? {})) if (memberFlags & MEMBER_FLAGS.Setter && hostRef.$instanceValues$.has(memberName)) {
4101
+ const pendingValue = hostRef.$instanceValues$.get(memberName);
4102
+ if (instance[memberName] !== pendingValue) instance[memberName] = pendingValue;
4103
+ }
4104
+ };
4105
+ /**
3911
4106
  * Attach a series of runtime constructs to a compiled Stencil component
3912
4107
  * constructor, including getters and setters for the `@Prop` and `@State`
3913
4108
  * decorators, callbacks for when attributes change, and so on.
@@ -3964,9 +4159,8 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
3964
4159
  if (BUILD$1.lazyLoad) {
3965
4160
  if ((cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Getter) === 0) return getValue(this, memberName);
3966
4161
  const ref = getHostRef(this);
3967
- const instance = ref ? ref.$lazyInstance$ : prototype;
3968
- if (!instance) return;
3969
- return instance[memberName];
4162
+ if (!ref) return prototype[memberName];
4163
+ return ref.$lazyInstance$ ? ref.$lazyInstance$[memberName] : getValue(this, memberName);
3970
4164
  }
3971
4165
  if (!BUILD$1.lazyLoad) return origGetter ? origGetter.apply(this) : getValue(this, memberName);
3972
4166
  },
@@ -3981,7 +4175,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
3981
4175
  }
3982
4176
  if (origSetter) {
3983
4177
  if (typeof (memberFlags & MEMBER_FLAGS.State ? this[memberName] : ref.$hostElement$[memberName]) === "undefined" && ref.$instanceValues$.get(memberName)) newValue = ref.$instanceValues$.get(memberName);
3984
- origSetter.apply(this, [parsePropertyValue(newValue, memberFlags, BUILD$1.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated))]);
4178
+ origSetter.apply(this, [parsePropertyValue(newValue, memberFlags)]);
3985
4179
  newValue = memberFlags & MEMBER_FLAGS.State ? this[memberName] : ref.$hostElement$[memberName];
3986
4180
  setValue(this, memberName, newValue, cmpMeta);
3987
4181
  return;
@@ -3993,21 +4187,15 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
3993
4187
  if (BUILD$1.lazyLoad) {
3994
4188
  if ((flags & PROXY_FLAGS.isElementConstructor) === 0 || (cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Setter) === 0) {
3995
4189
  setValue(this, memberName, newValue, cmpMeta);
3996
- if (flags & PROXY_FLAGS.isElementConstructor && !ref.$lazyInstance$) ref.$fetchedCbList$.push(() => {
3997
- if (cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Setter && ref.$lazyInstance$[memberName] !== ref.$instanceValues$.get(memberName)) ref.$lazyInstance$[memberName] = newValue;
3998
- });
3999
4190
  return;
4000
4191
  }
4001
- const setterSetVal = () => {
4192
+ const parsedValue = parsePropertyValue(newValue, memberFlags);
4193
+ if (ref.$lazyInstance$) {
4002
4194
  const currentValue = ref.$lazyInstance$[memberName];
4003
4195
  if (!ref.$instanceValues$.get(memberName) && currentValue) ref.$instanceValues$.set(memberName, currentValue);
4004
- ref.$lazyInstance$[memberName] = parsePropertyValue(newValue, memberFlags, BUILD$1.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
4196
+ ref.$lazyInstance$[memberName] = parsedValue;
4005
4197
  setValue(this, memberName, ref.$lazyInstance$[memberName], cmpMeta);
4006
- };
4007
- if (ref.$lazyInstance$) setterSetVal();
4008
- else ref.$fetchedCbList$.push(() => {
4009
- setterSetVal();
4010
- });
4198
+ } else ref.$instanceValues$.set(memberName, parsedValue);
4011
4199
  }
4012
4200
  } });
4013
4201
  } else if (BUILD$1.lazyLoad && BUILD$1.method && flags & PROXY_FLAGS.isElementConstructor && memberFlags & MEMBER_FLAGS.Method) Object.defineProperty(prototype, memberName, { value(...args) {
@@ -4049,7 +4237,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4049
4237
  const instance = BUILD$1.lazyLoad ? hostRef.$lazyInstance$ : elm;
4050
4238
  (cmpMeta.$watchers$?.[attrName])?.forEach((watcher) => {
4051
4239
  const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
4052
- if (instance[watchMethodName] != null && (hostFlags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate)) instance[watchMethodName](newValue, oldValue, attrName);
4240
+ if (instance?.[watchMethodName] != null && (hostFlags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate)) instance[watchMethodName](newValue, oldValue, attrName);
4053
4241
  });
4054
4242
  }
4055
4243
  return;
@@ -4059,9 +4247,13 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4059
4247
  const isBooleanTarget = propMemberFlags & MEMBER_FLAGS.Boolean;
4060
4248
  if (BUILD$1.reflect && propMemberFlags & MEMBER_FLAGS.ReflectAttr && propMemberFlags & MEMBER_FLAGS.Any && !isComplexType(this[propName]) && reflectedAttrValue(this[propName]) === newValue) return;
4061
4249
  const isSpuriousBooleanRemoval = isBooleanTarget && newValue === null && this[propName] === void 0;
4062
- if (isBooleanTarget) newValue = !(newValue === null || newValue === "false");
4250
+ if (isBooleanTarget) {
4251
+ if (BUILD$1.isDev && newValue === "false") `${cmpMeta.$tagName$}${attrName}${propName}`;
4252
+ newValue = newValue !== null;
4253
+ }
4063
4254
  const propDesc = Object.getOwnPropertyDescriptor(prototype, propName);
4064
- if (!isSpuriousBooleanRemoval && newValue != this[propName] && (!propDesc.get || !!propDesc.set)) this[propName] = newValue;
4255
+ const isUnchanged = newValue === this[propName] || newValue == null && this[propName] == null;
4256
+ if (!isSpuriousBooleanRemoval && !isUnchanged && (!propDesc.get || !!propDesc.set)) this[propName] = newValue;
4065
4257
  });
4066
4258
  };
4067
4259
  Cstr.observedAttributes = Array.from(/* @__PURE__ */ new Set([...Object.keys(cmpMeta.$watchers$ ?? {}), ...members.filter(([_, m]) => m[0] & MEMBER_FLAGS.HasAttribute).map(([propName, m]) => {
@@ -4122,9 +4314,12 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4122
4314
  } catch (e) {
4123
4315
  consoleError(e, elm);
4124
4316
  }
4125
- if (BUILD$1.member) hostRef.$flags$ &= ~HOST_FLAGS.isConstructingInstance;
4317
+ if (BUILD$1.member) {
4318
+ hostRef.$flags$ &= ~HOST_FLAGS.isConstructingInstance;
4319
+ replayPendingSetterValues(hostRef, cmpMeta);
4320
+ }
4126
4321
  endNewInstance();
4127
- if (BUILD$1.asyncLoading && hostRef.$ancestorComponent$) await awaitAncestorConnected(hostRef.$ancestorComponent$);
4322
+ if (BUILD$1.asyncLoading && hostRef.$ancestorComponent$) await awaitAncestorConnected(hostRef.$ancestorComponent$, getHostRegistry(elm));
4128
4323
  if (!(BUILD$1.slotRelocation && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation)) {
4129
4324
  fireConnectedCallback(hostRef.$lazyInstance$, elm);
4130
4325
  if (BUILD$1.asyncLoading) markFirstConnected(hostRef);
@@ -4224,9 +4419,16 @@ const connectedCallback = (elm) => {
4224
4419
  }
4225
4420
  if (BUILD$1.asyncLoading) {
4226
4421
  let ancestorComponent = elm;
4227
- while (ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host) if (BUILD$1.hydrateClientSide && ancestorComponent.nodeType === NODE_TYPE.ElementNode && ancestorComponent.hasAttribute("s-id") && ancestorComponent["s-p"] || ancestorComponent["s-p"]) {
4228
- attachToAncestor(hostRef, hostRef.$ancestorComponent$ = ancestorComponent);
4229
- break;
4422
+ while (ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host) {
4423
+ if (BUILD$1.hydrateClientSide && !ancestorComponent["s-p"] && ancestorComponent.nodeType === NODE_TYPE.ElementNode && ancestorComponent.hasAttribute("s-id")) {
4424
+ ancestorComponent["s-p"] = [];
4425
+ ancestorComponent["s-rc"] = [];
4426
+ ancestorComponent["s-pc"] = [];
4427
+ }
4428
+ if (ancestorComponent["s-p"]) {
4429
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$ = ancestorComponent);
4430
+ break;
4431
+ }
4230
4432
  }
4231
4433
  }
4232
4434
  if (BUILD$1.prop && !BUILD$1.hydrateServerSide && cmpMeta.$members$) Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
@@ -4342,48 +4544,112 @@ const hmrStandalone = async (hostElement, cmpMeta, hmrVersionId) => {
4342
4544
  `${modulePath}?s-hmr=${hmrVersionId}`
4343
4545
  );
4344
4546
  const NewClass = Object.values(newModule).find((v) => typeof v === "function" && v.is === cmpMeta.$tagName$) ?? newModule.default;
4345
- if (!NewClass) return;
4346
- const ctor = customElements.get(cmpMeta.$tagName$);
4347
- if (ctor) {
4348
- for (const key of Object.getOwnPropertyNames(NewClass.prototype)) {
4349
- if (key === "constructor") continue;
4350
- Object.defineProperty(ctor.prototype, key, Object.getOwnPropertyDescriptor(NewClass.prototype, key));
4351
- }
4352
- const styleDesc = Object.getOwnPropertyDescriptor(NewClass, "style");
4353
- if (styleDesc) {
4354
- Object.defineProperty(ctor, "style", styleDesc);
4355
- const newStyle = NewClass.style;
4356
- if (newStyle) {
4357
- const scopeId = getScopeId(cmpMeta);
4358
- const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4359
- console.log("[stencil-hmr] registerStyle", {
4360
- tag: cmpMeta.$tagName$,
4361
- scopeId,
4362
- isShadow,
4363
- cssLen: newStyle.length
4364
- });
4365
- registerStyle(scopeId, newStyle, isShadow);
4366
- }
4367
- }
4368
- }
4369
- const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4370
- document.querySelectorAll(cmpMeta.$tagName$).forEach((el) => {
4371
- const hostRef = getHostRef(el);
4372
- if (BUILD$1.hostListener && hostRef?.$rmListeners$) {
4373
- hostRef.$rmListeners$.map((rmListener) => rmListener());
4374
- hostRef.$rmListeners$ = void 0;
4375
- addHostEventListeners(el, hostRef, cmpMeta.$listeners$);
4376
- }
4377
- if (!isShadow && hostRef) {
4378
- console.log("[stencil-hmr] calling attachStyles for", cmpMeta.$tagName$);
4379
- attachStyles(hostRef);
4380
- }
4381
- forceUpdate(el);
4382
- });
4547
+ if (NewClass) hmrApplyClass(cmpMeta, NewClass);
4383
4548
  } catch (e) {
4384
4549
  console.error(`[Stencil HMR] Failed to reload <${cmpMeta.$tagName$}>`, e);
4385
4550
  }
4386
4551
  };
4552
+ /**
4553
+ * Patch a re-executed component class onto the registered one and re-render every live instance.
4554
+ * Shared by the standalone re-import above and bundlers that re-execute the module themselves
4555
+ * (webpack/rspack `module.hot`), which reach it via the constructor's `s-hmr-apply` hook.
4556
+ *
4557
+ * @param cmpMeta runtime metadata for the component
4558
+ * @param NewClass the component's newly executed class
4559
+ */
4560
+ const hmrApplyClass = (cmpMeta, NewClass) => {
4561
+ const ctor = customElements.get(cmpMeta.$tagName$);
4562
+ const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4563
+ if (ctor && ctor !== NewClass) {
4564
+ for (const key of Object.getOwnPropertyNames(NewClass.prototype)) {
4565
+ if (key === "constructor") continue;
4566
+ Object.defineProperty(ctor.prototype, key, Object.getOwnPropertyDescriptor(NewClass.prototype, key));
4567
+ }
4568
+ const styleDesc = Object.getOwnPropertyDescriptor(NewClass, "style");
4569
+ if (styleDesc) {
4570
+ Object.defineProperty(ctor, "style", styleDesc);
4571
+ const newStyle = NewClass.style;
4572
+ if (newStyle) registerStyle(getScopeId(cmpMeta), newStyle, isShadow);
4573
+ }
4574
+ }
4575
+ document.querySelectorAll(cmpMeta.$tagName$).forEach((el) => {
4576
+ const hostRef = getHostRef(el);
4577
+ if (BUILD$1.hostListener && hostRef?.$rmListeners$) {
4578
+ hostRef.$rmListeners$.map((rmListener) => rmListener());
4579
+ hostRef.$rmListeners$ = void 0;
4580
+ addHostEventListeners(el, hostRef, cmpMeta.$listeners$);
4581
+ }
4582
+ if (!isShadow && hostRef) attachStyles(hostRef);
4583
+ forceUpdate(el);
4584
+ });
4585
+ };
4586
+ //#endregion
4587
+ //#region src/runtime/parse-gate.ts
4588
+ /**
4589
+ * SSR hosts connected while the HTML parser is still inside them (streamed documents),
4590
+ * in connection order - which is document order. Each is held until its subtree is
4591
+ * parsed so hydration sees its declarative shadow root and children.
4592
+ */
4593
+ const pending = /* @__PURE__ */ new Set();
4594
+ let observer;
4595
+ const parentOf = (node) => node.parentNode ?? (node.nodeType === NODE_TYPE.DocumentFragment ? node.host : null);
4596
+ /**
4597
+ * The parser has finished with `elm` once it, or any ancestor, has a following sibling.
4598
+ * @param elm the element to check
4599
+ * @returns whether the element's subtree is fully parsed
4600
+ */
4601
+ const isParsed = (elm) => {
4602
+ if (win.document.readyState !== "loading") return true;
4603
+ for (let n = elm; n; n = parentOf(n)) if (n.nextSibling) return true;
4604
+ return false;
4605
+ };
4606
+ const hasPendingAncestor = (elm) => {
4607
+ for (let n = parentOf(elm); n; n = parentOf(n)) if (pending.has(n)) return true;
4608
+ return false;
4609
+ };
4610
+ const flush = () => {
4611
+ for (const elm of pending) if (!elm.isConnected) pending.delete(elm);
4612
+ else if (isParsed(elm)) elm.__attachShadow?.();
4613
+ for (const elm of pending) if (isParsed(elm) && !hasPendingAncestor(elm)) {
4614
+ pending.delete(elm);
4615
+ elm.connectedCallback?.();
4616
+ }
4617
+ if (!pending.size) {
4618
+ observer?.disconnect();
4619
+ observer = void 0;
4620
+ }
4621
+ };
4622
+ /**
4623
+ * Whether the parser may still be adding children (including a declarative shadow root)
4624
+ * to `elm`: it was just created by the parser, or it's an SSR host the parser is still inside.
4625
+ * @param elm the host element
4626
+ * @returns `true` if the element's subtree may be incomplete
4627
+ */
4628
+ const mayStillBeParsing = (elm) => win.document?.readyState === "loading" && (!elm.parentNode || elm.hasAttribute("s-id") && !isParsed(elm));
4629
+ /**
4630
+ * Holds back `elm`'s `connectedCallback` while it's an SSR host the parser hasn't finished
4631
+ * with, or one nested inside such a host. Its shadow root is attached once its own subtree
4632
+ * is parsed; `connectedCallback` is re-called once no ancestor host is still held.
4633
+ * @param elm the host element being connected
4634
+ * @returns `true` if processing was deferred
4635
+ */
4636
+ const deferUntilParsed = (elm) => {
4637
+ if (pending.has(elm)) return true;
4638
+ if (!win.document || !elm.hasAttribute("s-id")) return false;
4639
+ const parsed = isParsed(elm);
4640
+ if (parsed && !hasPendingAncestor(elm)) return false;
4641
+ if (parsed) elm.__attachShadow?.();
4642
+ pending.add(elm);
4643
+ if (!observer) {
4644
+ observer = new MutationObserver(flush);
4645
+ observer.observe(win.document, {
4646
+ childList: true,
4647
+ subtree: true
4648
+ });
4649
+ win.document.addEventListener("DOMContentLoaded", flush, { once: true });
4650
+ }
4651
+ return true;
4652
+ };
4387
4653
  //#endregion
4388
4654
  //#region src/runtime/bootstrap-standalone.ts
4389
4655
  const defineCustomElement = (Cstr, compactMeta) => {
@@ -4406,9 +4672,13 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4406
4672
  cmpMeta.$serializers$ = Cstr.$serializers$;
4407
4673
  }
4408
4674
  if (BUILD$1.reflect) cmpMeta.$attrsToReflect$ = [];
4409
- if (BUILD$1.hotModuleReplacement) Cstr.prototype["s-hmr"] = function(hmrVersionId) {
4410
- hmrStart(this, cmpMeta, hmrVersionId);
4411
- };
4675
+ if (BUILD$1.shadowReferenceTarget) cmpMeta.$referenceTarget$ = compactMeta[7];
4676
+ if (BUILD$1.hotModuleReplacement) {
4677
+ Cstr.prototype["s-hmr"] = function(hmrVersionId) {
4678
+ hmrStart(this, cmpMeta, hmrVersionId);
4679
+ };
4680
+ Cstr["s-hmr-apply"] = (NewClass) => hmrApplyClass(cmpMeta, NewClass);
4681
+ }
4412
4682
  if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && (BUILD$1.slotCloneNode || BUILD$1.patchClone && cmpMeta.$flags$ & CMP_FLAGS.patchClone)) patchCloneNode(Cstr.prototype);
4413
4683
  if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) {
4414
4684
  if (BUILD$1.lightDomPatches || BUILD$1.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(Cstr.prototype);
@@ -4421,11 +4691,12 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4421
4691
  patchSlotInsertAdjacentHTML(Cstr.prototype);
4422
4692
  patchInsertBefore(Cstr.prototype);
4423
4693
  patchSlotRemoveChild(Cstr.prototype);
4694
+ patchInnerContentSetters(Cstr.prototype);
4424
4695
  }
4425
4696
  if (BUILD$1.slotTextContent) patchTextContent(Cstr.prototype);
4426
4697
  }
4427
4698
  }
4428
- if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) hydrateScopedToShadow();
4699
+ if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) hydrateScopedToShadow([cmpMeta]);
4429
4700
  const originalConnectedCallback = Cstr.prototype.connectedCallback;
4430
4701
  const originalDisconnectedCallback = Cstr.prototype.disconnectedCallback;
4431
4702
  Object.assign(Cstr.prototype, {
@@ -4437,6 +4708,8 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4437
4708
  return getHostRef(this)?.$onReadyPromise$;
4438
4709
  },
4439
4710
  async connectedCallback() {
4711
+ if (BUILD$1.hydrateClientSide && deferUntilParsed(this)) return;
4712
+ if (BUILD$1.shadowDom) this.__attachShadow();
4440
4713
  const isFirstConnect = !this.__hasHostListenerAttached;
4441
4714
  let hostRef;
4442
4715
  if (isFirstConnect) {
@@ -4447,7 +4720,7 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4447
4720
  }
4448
4721
  connectedCallback(this);
4449
4722
  if (BUILD$1.asyncLoading && hostRef && hostRef.$ancestorComponent$) {
4450
- await awaitAncestorConnected(hostRef.$ancestorComponent$);
4723
+ await awaitAncestorConnected(hostRef.$ancestorComponent$, getHostRegistry(this));
4451
4724
  if (!this.isConnected) return;
4452
4725
  }
4453
4726
  if (originalConnectedCallback && (plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) originalConnectedCallback.call(this);
@@ -4458,11 +4731,10 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4458
4731
  if (originalDisconnectedCallback && (plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) originalDisconnectedCallback.call(this);
4459
4732
  },
4460
4733
  __attachShadow() {
4461
- const isClosed = BUILD$1.shadowModeClosed && !!(cmpMeta.$flags$ & CMP_FLAGS.shadowModeClosed);
4462
- let existingRoot = this.shadowRoot;
4463
- if (BUILD$1.shadowModeClosed && isClosed) existingRoot = this.__shadowRoot ?? null;
4734
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) || BUILD$1.hydrateClientSide && mayStillBeParsing(this)) return;
4735
+ const existingRoot = getShadowRoot(this);
4464
4736
  if (!existingRoot) createShadowRoot.call(this, cmpMeta);
4465
- else if (BUILD$1.isDev && BUILD$1.shadowModeClosed && isClosed && existingRoot.mode !== "closed") throw new Error(`Unable to re-use existing shadow root for ${cmpMeta.$tagName$}! Mode is set to ${existingRoot.mode} but expected closed.`);
4737
+ else if (BUILD$1.isDev && BUILD$1.shadowModeClosed && cmpMeta.$flags$ & CMP_FLAGS.shadowModeClosed && existingRoot.mode !== "closed") throw new Error(`Unable to re-use existing shadow root for ${cmpMeta.$tagName$}! Mode is set to ${existingRoot.mode} but expected closed.`);
4466
4738
  }
4467
4739
  });
4468
4740
  Object.defineProperty(Cstr, "is", {
@@ -4517,7 +4789,14 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4517
4789
  Object.assign(plt, options);
4518
4790
  if (BUILD$1.asyncQueue && options.syncQueue) plt.$flags$ |= PLATFORM_FLAGS.queueSync;
4519
4791
  if (BUILD$1.hydrateClientSide) plt.$flags$ |= PLATFORM_FLAGS.appLoaded;
4520
- if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) hydrateScopedToShadow();
4792
+ if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) {
4793
+ const cmpMetas = [];
4794
+ lazyBundles.map((lazyBundle) => lazyBundle[1].map(([$flags$, $tagName$]) => cmpMetas.push({
4795
+ $flags$,
4796
+ $tagName$
4797
+ })));
4798
+ hydrateScopedToShadow(cmpMetas);
4799
+ }
4521
4800
  lazyBundles.map((lazyBundle) => {
4522
4801
  lazyBundle[1].map((compactMeta) => {
4523
4802
  const cmpMeta = {
@@ -4534,7 +4813,11 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4534
4813
  cmpMeta.$serializers$ = compactMeta[5] ?? {};
4535
4814
  cmpMeta.$deserializers$ = compactMeta[6] ?? {};
4536
4815
  }
4816
+ if (BUILD$1.shadowReferenceTarget) cmpMeta.$referenceTarget$ = compactMeta[7];
4537
4817
  const tagName = transformTag(cmpMeta.$tagName$);
4818
+ const attachShadowRoot = (elm) => {
4819
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation && !(cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) && !getShadowRoot(elm)) createShadowRoot.call(elm, cmpMeta);
4820
+ };
4538
4821
  const HostElement = class extends HTMLElement {
4539
4822
  ["s-p"];
4540
4823
  ["s-rc"];
@@ -4543,14 +4826,13 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4543
4826
  super(self);
4544
4827
  self = this;
4545
4828
  registerHost(self, cmpMeta);
4546
- if (BUILD$1.shadowDom && cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation && !(cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss)) {
4547
- if (!self.shadowRoot) createShadowRoot.call(self, cmpMeta);
4548
- else if (BUILD$1.isDev && self.shadowRoot.mode !== "open") throw new Error(`Unable to re-use existing shadow root for ${cmpMeta.$tagName$}! Mode is set to ${self.shadowRoot.mode} but DSD shadow roots must use open mode.`);
4549
- }
4829
+ if (BUILD$1.shadowDom && !(BUILD$1.hydrateClientSide && mayStillBeParsing(self))) attachShadowRoot(self);
4550
4830
  }
4551
4831
  connectedCallback() {
4552
4832
  const hostRef = getHostRef(this);
4553
4833
  if (!hostRef) return;
4834
+ if (BUILD$1.hydrateClientSide && deferUntilParsed(this)) return;
4835
+ if (BUILD$1.shadowDom) attachShadowRoot(this);
4554
4836
  /**
4555
4837
  * The `connectedCallback` lifecycle event can potentially be fired multiple times
4556
4838
  * if the element is removed from the DOM and re-inserted. This is not a common use case,
@@ -4606,10 +4888,14 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4606
4888
  patchSlotInsertAdjacentHTML(HostElement.prototype);
4607
4889
  patchInsertBefore(HostElement.prototype);
4608
4890
  patchSlotRemoveChild(HostElement.prototype);
4891
+ patchInnerContentSetters(HostElement.prototype);
4609
4892
  }
4610
4893
  if (BUILD$1.slotTextContent) patchTextContent(HostElement.prototype);
4611
4894
  }
4612
4895
  }
4896
+ if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) HostElement.prototype.__attachShadow = function() {
4897
+ attachShadowRoot(this);
4898
+ };
4613
4899
  if (BUILD$1.formAssociated && cmpMeta.$flags$ & CMP_FLAGS.formAssociated) HostElement.formAssociated = true;
4614
4900
  if (BUILD$1.hotModuleReplacement) HostElement.prototype["s-hmr"] = function(hmrVersionId) {
4615
4901
  hmrStart(this, cmpMeta, hmrVersionId);
@@ -4759,31 +5045,12 @@ function Mixin(...mixins) {
4759
5045
  //#region src/runtime/nonce.ts
4760
5046
  /**
4761
5047
  * Assigns the given value to the nonce property on the runtime platform object.
4762
- * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
5048
+ * During runtime, this value is used to set the nonce attribute on all dynamically created style tags.
4763
5049
  * @param nonce The value to be assigned to the platform nonce property.
4764
5050
  * @returns void
4765
5051
  */
4766
5052
  const setNonce = (nonce) => plt.$nonce$ = nonce;
4767
5053
  //#endregion
4768
- //#region src/runtime/tag-transform.ts
4769
- let tagTransformer = void 0;
4770
- /**
4771
- * Transforms a tag name using the current tag transformer
4772
- * @param tag - the tag to transform e.g. `my-tag`
4773
- * @returns the transformed tag e.g. `new-my-tag`
4774
- */
4775
- function transformTag(tag) {
4776
- if (!tagTransformer) return tag;
4777
- return tagTransformer(tag);
4778
- }
4779
- /**
4780
- * Sets the tag transformer to be used when rendering custom elements
4781
- * @param transformer the transformer function to use. Must return a string
4782
- */
4783
- function setTagTransformer(transformer) {
4784
- tagTransformer = transformer;
4785
- }
4786
- //#endregion
4787
5054
  //#region src/runtime/vdom/jsx-runtime.ts
4788
5055
  function jsx(type, props, key) {
4789
5056
  const { children, ...rest } = props ?? {};
@@ -4910,7 +5177,10 @@ const insertVNodeAnnotations = (doc, hostElm, vnode, docData, cmpData) => {
4910
5177
  if (vnode != null) {
4911
5178
  const hostId = ++docData.hostIds;
4912
5179
  hostElm.setAttribute(HYDRATE_ID, hostId);
4913
- if (hostElm["s-cr"] != null) hostElm["s-cr"].nodeValue = `r.${hostId}`;
5180
+ if (hostElm["s-cr"] != null) {
5181
+ if (hostElm.shadowRoot) hostElm["s-cr"].remove();
5182
+ else hostElm["s-cr"].nodeValue = `r.${hostId}`;
5183
+ }
4914
5184
  if (vnode.$children$ != null) {
4915
5185
  const depth = 0;
4916
5186
  vnode.$children$.forEach((vnodeChild, index) => {
@@ -4972,7 +5242,14 @@ const insertChildVNodeAnnotations = (doc, vnodeChild, cmpData, hostId, depth, in
4972
5242
  };
4973
5243
  //#endregion
4974
5244
  //#region src/server/platform/proxy-host-element.ts
4975
- function proxyHostElement(elm, cstr) {
5245
+ /**
5246
+ * Set up a component's host element on the server: its props (from attributes, values set on
5247
+ * the element before it was defined, and `ssrProp()` references), getters/setters and shadow root.
5248
+ * @param elm the host element
5249
+ * @param cstr the component's constructor
5250
+ * @param warn report a problem with the render (to its `diagnostics`)
5251
+ */
5252
+ function proxyHostElement(elm, cstr, warn = () => {}) {
4976
5253
  const cmpMeta = cstr.cmpMeta;
4977
5254
  cmpMeta.$watchers$ = cmpMeta.$watchers$ || cstr.watchers;
4978
5255
  cmpMeta.$deserializers$ = cmpMeta.$deserializers$ || cstr.deserializers;
@@ -4989,7 +5266,9 @@ function proxyHostElement(elm, cstr) {
4989
5266
  Object.entries(cmpMeta.$members$).forEach(([memberName, [memberFlags, metaAttributeName]]) => {
4990
5267
  if (memberFlags & MEMBER_FLAGS.Prop) {
4991
5268
  const attributeName = metaAttributeName || memberName;
4992
- const attrValue = elm.getAttribute(attributeName);
5269
+ let attrValue = elm.getAttribute(attributeName);
5270
+ const ssrProp = takeSsrProp(elm, attributeName, memberName, warn);
5271
+ if (ssrProp) attrValue = null;
4993
5272
  const propValue = elm[memberName];
4994
5273
  let attrPropVal;
4995
5274
  const { get: origGetter, set: origSetter } = Object.getOwnPropertyDescriptor(cstr.prototype, memberName) || {};
@@ -4998,14 +5277,20 @@ function proxyHostElement(elm, cstr) {
4998
5277
  const [[methodName]] = Object.entries(deserializer);
4999
5278
  attrPropVal = cstr.prototype[methodName](attrValue, memberName);
5000
5279
  }
5001
- else attrPropVal = parsePropertyValue(attrValue, memberFlags, !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
5280
+ else attrPropVal = parsePropertyValue(attrValue, memberFlags);
5002
5281
  }
5282
+ if (ssrProp?.value !== void 0) attrPropVal = ssrProp.value;
5003
5283
  if (propValue !== void 0) {
5004
5284
  attrPropVal = propValue;
5005
5285
  delete elm[memberName];
5006
5286
  }
5287
+ const setFromOutside = ssrProp?.value !== void 0 || propValue !== void 0;
5288
+ if (setFromOutside && typeof attrPropVal === "object" && attrPropVal !== null && !cmpMeta.$serializers$?.[memberName]) warn(`<${cmpMeta.$tagName$}>'s "${memberName}" prop was given an object on the server, but has no @PropSerialize(), so the browser won't get it: the component will first render there without it. To keep it, use @Prop({ serialize: 'json' }), or a @PropSerialize() / @AttrDeserialize() pair for other formats.`);
5007
5289
  const userSetter = !cstr.isProxied ? origSetter : void 0;
5008
- if (attrPropVal !== void 0 && !userSetter) hostRef?.$instanceValues$?.set(memberName, attrPropVal);
5290
+ if (attrPropVal !== void 0 && !userSetter) {
5291
+ hostRef?.$instanceValues$?.set(memberName, attrPropVal);
5292
+ if (setFromOutside && cmpMeta.$serializers$?.[memberName]) applySerializers(hostRef, cmpMeta, memberName, attrPropVal, void 0);
5293
+ }
5009
5294
  const getterSetterDescriptor = {
5010
5295
  get: function() {
5011
5296
  return getValue(this, memberName);
@@ -5053,6 +5338,34 @@ function componentOnReady() {
5053
5338
  return getHostRef(this)?.$onReadyPromise$;
5054
5339
  }
5055
5340
  function forceUpdate$1() {}
5341
+ /**
5342
+ * Read and remove an `ssrProp()` reference: a value a framework template passed to this prop,
5343
+ * which reached the server as an attribute pointing into the `ssrProp()` registry. Templates bind
5344
+ * it under the prop name, which HTML lower-cases (`chartData` -> `chartdata`), or dash-cased
5345
+ * (`chart-data`); complex props usually have no attribute name of their own.
5346
+ * @param elm the component's host element
5347
+ * @param attributeName the prop's attribute name
5348
+ * @param memberName the prop's name
5349
+ * @param warn report a problem with the render
5350
+ * @returns `undefined` if there's no reference, otherwise its value (`undefined` if it's gone)
5351
+ */
5352
+ const takeSsrProp = (elm, attributeName, memberName, warn) => {
5353
+ for (const name of /* @__PURE__ */ new Set([
5354
+ attributeName,
5355
+ memberName,
5356
+ toDashCase(memberName)
5357
+ ])) {
5358
+ const attr = elm.getAttribute(name);
5359
+ if (!attr?.startsWith("__stencil_ssr_ref:")) continue;
5360
+ elm.removeAttribute(name);
5361
+ const id = attr.slice(18);
5362
+ const registry = (typeof $stencilNativeGlobal !== "undefined" ? $stencilNativeGlobal : globalThis)[Symbol.for(SSR_PROPS_REGISTRY_KEY)];
5363
+ const entry = registry?.get(id);
5364
+ registry?.delete(id);
5365
+ if (!entry) warn(`<${elm.tagName.toLowerCase()}>'s "${memberName}" was passed with ssrProp(), but its value isn't available here: it's only available to renderToString() in the same process, for a short time after the template ran.`);
5366
+ return { value: entry?.value };
5367
+ }
5368
+ };
5056
5369
  //#endregion
5057
5370
  //#region src/server/platform/ssr-app.ts
5058
5371
  /**
@@ -5065,8 +5378,9 @@ function forceUpdate$1() {}
5065
5378
  * @param results The results object to store the hydration results.
5066
5379
  * @param afterSsr The callback to be called after SSR is complete.
5067
5380
  * @param resolve The resolve function to be called when SSR is complete.
5381
+ * @param abortController The AbortController to use for aborting in-flight fetch() calls and other cancellable work when SSR times out.
5068
5382
  */
5069
- function ssrApp(win, opts, results, afterSsr, resolve) {
5383
+ function ssrApp(win, opts, results, afterSsr, resolve, abortController) {
5070
5384
  const connectedElements = /* @__PURE__ */ new Set();
5071
5385
  const createdElements = /* @__PURE__ */ new Set();
5072
5386
  const waitingElements = /* @__PURE__ */ new Set();
@@ -5076,10 +5390,20 @@ function ssrApp(win, opts, results, afterSsr, resolve) {
5076
5390
  setScopedSsr(opts);
5077
5391
  let tmrId;
5078
5392
  let ranCompleted = false;
5393
+ let modeResolverSnapshot;
5394
+ const abortedPromise = new Promise((res) => {
5395
+ if (abortController.signal.aborted) res();
5396
+ else abortController.signal.addEventListener("abort", () => res(), { once: true });
5397
+ });
5079
5398
  function hydratedComplete() {
5080
5399
  $nativeClearTimeout(tmrId);
5081
5400
  createdElements.clear();
5082
5401
  connectedElements.clear();
5402
+ if (modeResolverSnapshot) {
5403
+ modeResolver.length = 0;
5404
+ modeResolver.push(...modeResolverSnapshot);
5405
+ modeResolverSnapshot = void 0;
5406
+ }
5083
5407
  if (!ranCompleted) {
5084
5408
  ranCompleted = true;
5085
5409
  try {
@@ -5095,6 +5419,7 @@ function ssrApp(win, opts, results, afterSsr, resolve) {
5095
5419
  }
5096
5420
  function hydratedError(err) {
5097
5421
  renderCatchError(opts, results, err);
5422
+ abortController.abort();
5098
5423
  hydratedComplete();
5099
5424
  }
5100
5425
  function timeoutExceeded() {
@@ -5122,7 +5447,13 @@ function ssrApp(win, opts, results, afterSsr, resolve) {
5122
5447
  createdElements.add(elm);
5123
5448
  elm.connectedCallback = patchedConnectedCallback;
5124
5449
  registerHost(elm, Cstr.cmpMeta);
5125
- proxyHostElement(elm, Cstr);
5450
+ proxyHostElement(elm, Cstr, (messageText) => results.diagnostics.push({
5451
+ level: "warn",
5452
+ type: "hydrate",
5453
+ header: "SSR Warning",
5454
+ messageText,
5455
+ lines: []
5456
+ }));
5126
5457
  }
5127
5458
  }
5128
5459
  }
@@ -5139,7 +5470,7 @@ function ssrApp(win, opts, results, afterSsr, resolve) {
5139
5470
  if (isValidComponent(elm, opts) && results.hydratedCount < opts.maxHydrateCount) {
5140
5471
  if (!connectedElements.has(elm) && shouldHydrate(elm)) {
5141
5472
  connectedElements.add(elm);
5142
- return hydrateComponent.call(elm, win, results, elm.nodeName, elm, waitingElements);
5473
+ return hydrateComponent.call(elm, win, results, elm.nodeName, elm, waitingElements, abortedPromise);
5143
5474
  }
5144
5475
  }
5145
5476
  return resolved;
@@ -5162,13 +5493,17 @@ function ssrApp(win, opts, results, afterSsr, resolve) {
5162
5493
  tmrId = $nativeSetTimeout(timeoutExceeded, opts.timeout);
5163
5494
  plt.$resourcesUrl$ = new URL(opts.resourcesUrl || "./", win.document.baseURI).href;
5164
5495
  globalScripts();
5496
+ if (Array.isArray(opts.modes)) {
5497
+ modeResolverSnapshot = modeResolver.slice();
5498
+ opts.modes.forEach((mode) => setMode(mode));
5499
+ }
5165
5500
  patchChild(win.document.body);
5166
5501
  waitLoop().then(hydratedComplete).catch(hydratedError);
5167
5502
  } catch (e) {
5168
5503
  hydratedError(e);
5169
5504
  }
5170
5505
  }
5171
- async function hydrateComponent(win, results, tagName, elm, waitingElements) {
5506
+ async function hydrateComponent(win, results, tagName, elm, waitingElements, aborted) {
5172
5507
  tagName = tagName.toLowerCase();
5173
5508
  const Cstr = loadModule({
5174
5509
  $tagName$: tagName,
@@ -5183,16 +5518,17 @@ async function hydrateComponent(win, results, tagName, elm, waitingElements) {
5183
5518
  addHostEventListeners(this, hostRef, cmpMeta.$listeners$);
5184
5519
  try {
5185
5520
  connectedCallback(elm);
5186
- await elm.componentOnReady();
5187
- results.hydratedCount++;
5188
- const ref = getHostRef(elm);
5189
- const modeName = !ref?.$modeName$ ? "$" : ref?.$modeName$;
5190
- if (!results.components.some((c) => c.tag === tagName && c.mode === modeName)) results.components.push({
5191
- tag: tagName,
5192
- mode: modeName,
5193
- count: 0,
5194
- depth: -1
5195
- });
5521
+ if (!await Promise.race([elm.componentOnReady().then(() => false), aborted.then(() => true)])) {
5522
+ results.hydratedCount++;
5523
+ const ref = getHostRef(elm);
5524
+ const modeName = !ref?.$modeName$ ? "$" : ref?.$modeName$;
5525
+ if (!results.components.some((c) => c.tag === tagName && c.mode === modeName)) results.components.push({
5526
+ tag: tagName,
5527
+ mode: modeName,
5528
+ count: 0,
5529
+ depth: -1
5530
+ });
5531
+ }
5196
5532
  } catch (e) {
5197
5533
  win.console.error(e);
5198
5534
  }
@@ -5338,7 +5674,7 @@ const isMemberInElement = (elm, memberName) => {
5338
5674
  const registerComponents = (Cstrs) => {
5339
5675
  for (const Cstr of Cstrs) {
5340
5676
  const exportName = Cstr.cmpMeta.$tagName$;
5341
- const transformedTagName = $stencilTagTransform.transformTag(exportName);
5677
+ const transformedTagName = transformTag(exportName);
5342
5678
  cmpModules.set(exportName, { [exportName]: Cstr });
5343
5679
  if (transformedTagName !== exportName) cmpModules.set(transformedTagName, { [transformedTagName]: Cstr });
5344
5680
  }
@@ -5414,14 +5750,9 @@ const registerHost = (elm, cmpMeta) => {
5414
5750
  elm.__s_ghr = () => hostRef;
5415
5751
  return hostRef;
5416
5752
  };
5417
- const Build = {
5418
- isDev: false,
5419
- isBrowser: false,
5420
- isServer: true,
5421
- isTesting: false
5422
- };
5753
+ const Build = { ...SERVER_BUILD_FLAGS };
5423
5754
  const styles = /* @__PURE__ */ new Map();
5424
- const modeResolutionChain = [];
5755
+ const modeResolver = [];
5425
5756
  /**
5426
5757
  * Server-side implementation of getAssetPath.
5427
5758
  *
@@ -5453,4 +5784,4 @@ const setScopedSsr = (opts) => {
5453
5784
  const needsScopedSSR = () => scopedSSR;
5454
5785
  let scopedSSR = false;
5455
5786
  //#endregion
5456
- export { BUILD, Build, Env, Fragment, Host, Mixin, NAMESPACE, addHostEventListeners, bootstrapLazy, cmpModules, connectedCallback, consoleDevError, consoleDevInfo, consoleDevWarn, consoleError, createEvent, defineCustomElement, disconnectedCallback, forceModeUpdate, forceUpdate, getAssetPath, getElement, getHostRef, getMode, getRenderingRef, getShadowRoot, getValue, hAsync as h, injectSideEffectStyle, insertVdomAnnotations, isMemberInElement, jsx, jsxs, loadModule, modeResolutionChain, needsScopedSSR, nextTick, parsePropertyValue, plt, postUpdateComponent, proxyComponent, proxyCustomElement, readTask, registerComponents, registerHost, registerInstance, registerSideEffectStyleTarget, renderVdom, setAssetPath, setErrorHandler, setMode, setNonce, setPlatformHelpers, setScopedSsr, setTagTransformer, setValue, ssrApp, styles, supportsConstructableStylesheets, supportsListenerOptions, supportsMutableAdoptedStyleSheets, transformTag, unregisterSideEffectStyleTarget, win, writeTask };
5787
+ export { BUILD, Build, Env, Fragment, Host, Mixin, NAMESPACE, addHostEventListeners, bootstrapLazy, cmpModules, connectedCallback, consoleDevError, consoleDevInfo, consoleDevWarn, consoleError, createEvent, defineCustomElement, disconnectedCallback, forceModeUpdate, forceUpdate, getAssetPath, getElement, getHostRef, getMode, getRenderingRef, getShadowRoot, getValue, hAsync as h, injectSideEffectStyle, insertVdomAnnotations, isMemberInElement, jsx, jsxs, loadModule, modeResolver, needsScopedSSR, nextTick, parsePropertyValue, plt, postUpdateComponent, proxyComponent, proxyCustomElement, readTask, registerComponents, registerHost, registerInstance, registerSideEffectStyleTarget, renderVdom, setAssetPath, setErrorHandler, setMode, setNonce, setPlatformHelpers, setScopedSsr, setTagTransformer, setValue, ssrApp, styles, supportsConstructableStylesheets, supportsListenerOptions, supportsMutableAdoptedStyleSheets, transformTag, unregisterSideEffectStyleTarget, win, writeTask };