@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,12 +1,89 @@
1
1
  import { BUILD, BUILD as BUILD$1, Env, NAMESPACE, NAMESPACE as NAMESPACE$1 } from "@stencil/core/app-data";
2
2
  import { 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
+ const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
54
+ /**
55
+ * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
56
+ *
57
+ * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
58
+ * support as of Stencil v4.
59
+ */
60
+ const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
61
+ const XLINK_NS = "http://www.w3.org/1999/xlink";
62
+ /**
63
+ * Minimum delay, in milliseconds, before retrying a failed lazy component load.
64
+ */
65
+ const LAZY_LOAD_RETRY_INTERVAL_MS = 1e3;
66
+ const FORM_ASSOCIATED_CUSTOM_ELEMENT_CALLBACKS = [
67
+ "formAssociatedCallback",
68
+ "formResetCallback",
69
+ "formDisabledCallback",
70
+ "formStateRestoreCallback"
71
+ ];
72
+ //#endregion
4
73
  //#region src/client/client-build.ts
74
+ /**
75
+ * `isDev` / `isTesting` are getters, not copies: the transpile path (e.g. `@stencil/unplugin`)
76
+ * sets `BUILD.*` overrides from each component module, which runs after this module is evaluated.
77
+ */
5
78
  const Build = {
6
- isDev: BUILD$1.isDev,
7
79
  isBrowser: true,
8
80
  isServer: false,
9
- isTesting: BUILD$1.isTesting
81
+ get isDev() {
82
+ return BUILD$1.isDev;
83
+ },
84
+ get isTesting() {
85
+ return BUILD$1.isTesting;
86
+ }
10
87
  };
11
88
  //#endregion
12
89
  //#region src/client/client-decorators.ts
@@ -479,6 +556,7 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
479
556
  ).then(onLoad, onError);
480
557
  return import(
481
558
  /* @vite-ignore */
559
+ /* turbopackIgnore: true */
482
560
  /* webpackInclude: /\.entry\.js$/ */
483
561
  /* webpackExclude: /\.system\.entry\.js$/ */
484
562
  /* webpackMode: "lazy" */
@@ -488,79 +566,10 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
488
566
  //#endregion
489
567
  //#region src/client/client-style.ts
490
568
  const styles = /*@__PURE__*/ new Map();
491
- const modeResolutionChain = [];
492
- const setScopedSsr = (_opts) => {};
569
+ const modeResolver = [];
570
+ const setScopedSSR = (_opts) => {};
493
571
  const needsScopedSSR = () => false;
494
572
  //#endregion
495
- //#region src/runtime/runtime-constants.ts
496
- /**
497
- * Bit flags for recording various properties of VDom nodes
498
- */
499
- const VNODE_FLAGS = {
500
- /**
501
- * Whether or not a vdom node is a slot reference
502
- */
503
- isSlotReference: 1,
504
- /**
505
- * Whether or not a slot element has fallback content
506
- */
507
- isSlotFallback: 2,
508
- /**
509
- * Whether or not an element is a host element
510
- */
511
- isHost: 4
512
- };
513
- const PROXY_FLAGS = {
514
- isElementConstructor: 1,
515
- proxyState: 2
516
- };
517
- const PLATFORM_FLAGS = {
518
- /**
519
- * designates a node in the DOM as being actively moved by the runtime
520
- */
521
- isTmpDisconnected: 1,
522
- appLoaded: 2,
523
- queueSync: 4,
524
- queueMask: 6
525
- };
526
- /**
527
- * A (subset) of node types which are relevant for the Stencil runtime. These
528
- * values are based on the values which can possibly be returned by the
529
- * `.nodeType` property of a DOM node. See here for details:
530
- *
531
- * {@link https://dom.spec.whatwg.org/#ref-for-dom-node-nodetype%E2%91%A0}
532
- */
533
- const NODE_TYPE = {
534
- ElementNode: 1,
535
- TextNode: 3,
536
- CommentNode: 8,
537
- DocumentNode: 9,
538
- DocumentTypeNode: 10,
539
- DocumentFragment: 11
540
- };
541
- const HYDRATE_ID = "s-id";
542
- const HYDRATED_STYLE_ID = "sty-id";
543
- const HYDRATE_CHILD_ID = "c-id";
544
- const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
545
- /**
546
- * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
547
- *
548
- * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
549
- * support as of Stencil v4.
550
- */
551
- const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
552
- const XLINK_NS = "http://www.w3.org/1999/xlink";
553
- /**
554
- * Minimum delay, in milliseconds, before retrying a failed lazy component load.
555
- */
556
- const LAZY_LOAD_RETRY_INTERVAL_MS = 1e3;
557
- const FORM_ASSOCIATED_CUSTOM_ELEMENT_CALLBACKS = [
558
- "formAssociatedCallback",
559
- "formResetCallback",
560
- "formDisabledCallback",
561
- "formStateRestoreCallback"
562
- ];
563
- //#endregion
564
573
  //#region src/client/client-window.ts
565
574
  const win = typeof window !== "undefined" ? window : {};
566
575
  const H = win.HTMLElement || class {};
@@ -601,12 +610,12 @@ let queuePending = false;
601
610
  const queueDomReads = [];
602
611
  const queueDomWrites = [];
603
612
  const queueDomWritesLow = [];
604
- const scheduleFlush = () => win.document?.hidden ? nextTick(flush) : plt.raf(flush);
613
+ const scheduleFlush = () => win.document?.hidden ? setTimeout(flush$1, 16) : plt.raf(flush$1);
605
614
  const queueTask = (queue, write) => (cb) => {
606
615
  queue.push(cb);
607
616
  if (!queuePending) {
608
617
  queuePending = true;
609
- if (write && plt.$flags$ & PLATFORM_FLAGS.queueSync) nextTick(flush);
618
+ if (write && plt.$flags$ & PLATFORM_FLAGS.queueSync) nextTick(flush$1);
610
619
  else scheduleFlush();
611
620
  }
612
621
  };
@@ -629,7 +638,7 @@ const consumeTimeout = (queue, timeout) => {
629
638
  if (i === queue.length) queue.length = 0;
630
639
  else if (i !== 0) queue.splice(0, i);
631
640
  };
632
- const flush = () => {
641
+ const flush$1 = () => {
633
642
  if (BUILD$1.asyncQueue) queueCongestion++;
634
643
  consume(queueDomReads);
635
644
  if (BUILD$1.asyncQueue) {
@@ -688,6 +697,7 @@ function createShadowRoot(cmpMeta) {
688
697
  }
689
698
  if (BUILD$1.shadowClonable) opts.clonable = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowClonable);
690
699
  if (BUILD$1.shadowSerializable) opts.serializable = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowSerializable);
700
+ if (BUILD$1.shadowReferenceTarget && cmpMeta.$referenceTarget$) opts.referenceTarget = cmpMeta.$referenceTarget$;
691
701
  const shadowRoot = this.attachShadow(opts);
692
702
  if (BUILD$1.shadowModeClosed && isClosed) this.__shadowRoot = shadowRoot;
693
703
  if (globalStyleSheet === void 0) globalStyleSheet = createStyleSheetIfNeededAndSupported(globalStyles) ?? null;
@@ -766,6 +776,7 @@ function getHostSlotNodes(childNodes, hostName, slotName) {
766
776
  if (typeof slotName !== "undefined") return slottedNodes;
767
777
  }
768
778
  slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
779
+ if (typeof slotName !== "undefined" && slottedNodes.length) return slottedNodes;
769
780
  }
770
781
  return slottedNodes;
771
782
  }
@@ -900,6 +911,7 @@ const applyLightDomPatches = (hostElementPrototype) => {
900
911
  patchSlotInsertAdjacentHTML(hostElementPrototype);
901
912
  patchInsertBefore(hostElementPrototype);
902
913
  patchTextContent(hostElementPrototype);
914
+ patchInnerContentSetters(hostElementPrototype);
903
915
  patchChildSlotNodes(hostElementPrototype);
904
916
  patchSlotRemoveChild(hostElementPrototype);
905
917
  };
@@ -964,11 +976,13 @@ const patchSlotAppendChild = (HostElementPrototype) => {
964
976
  const { slotName, slotNode } = findSlotFromSlottedNode(newChild, this);
965
977
  if (slotNode) {
966
978
  addSlotRelocateNode(newChild, slotNode);
979
+ patchSlottedNode(newChild);
967
980
  const slotChildNodes = getSlotChildSiblings(slotNode, slotName);
968
981
  const appendAfter = slotChildNodes[slotChildNodes.length - 1];
982
+ const slotWasEmpty = slotChildNodes.every((node) => node["s-sr"]);
969
983
  const insertedNode = internalCall(internalCall(appendAfter, "parentNode"), "insertBefore")(newChild, appendAfter.nextSibling);
970
984
  dispatchSlotChangeEvent(slotNode);
971
- updateFallbackSlotVisibility(this);
985
+ if (slotWasEmpty) updateFallbackSlotVisibility(this);
972
986
  return insertedNode;
973
987
  }
974
988
  return this.__appendChild(newChild);
@@ -986,8 +1000,10 @@ const patchSlotRemoveChild = (ElementPrototype) => {
986
1000
  ElementPrototype.__removeChild = ElementPrototype.removeChild;
987
1001
  ElementPrototype.removeChild = function(toRemove) {
988
1002
  if (toRemove && typeof toRemove["s-sn"] !== "undefined") {
989
- if (getHostSlotNodes(this.__childNodes || this.childNodes, this.tagName, toRemove["s-sn"]) && toRemove.isConnected) {
990
- toRemove.remove();
1003
+ const slotNode = getHostSlotNodes(this.__childNodes || this.childNodes, this.tagName, toRemove["s-sn"])[0];
1004
+ if (slotNode && toRemove.isConnected) {
1005
+ removeSlottedNode(toRemove);
1006
+ dispatchSlotChangeEvent(slotNode);
991
1007
  updateFallbackSlotVisibility(this);
992
1008
  return;
993
1009
  }
@@ -1010,6 +1026,7 @@ const patchSlotPrepend = (HostElementPrototype) => {
1010
1026
  const slotNode = getHostSlotNodes(internalCall(this, "childNodes"), this.tagName, slotName)[0];
1011
1027
  if (slotNode) {
1012
1028
  addSlotRelocateNode(newChild, slotNode, true);
1029
+ patchSlottedNode(newChild);
1013
1030
  const appendAfter = getSlotChildSiblings(slotNode, slotName)[0];
1014
1031
  const toReturn = internalCall(internalCall(appendAfter, "parentNode"), "insertBefore")(newChild, internalCall(appendAfter, "nextSibling"));
1015
1032
  dispatchSlotChangeEvent(slotNode);
@@ -1073,25 +1090,21 @@ const patchInsertBefore = (HostElementPrototype) => {
1073
1090
  eleProto.__insertBefore = HostElementPrototype.insertBefore;
1074
1091
  HostElementPrototype.insertBefore = function(newChild, currentChild) {
1075
1092
  const { slotName, slotNode } = findSlotFromSlottedNode(newChild, this);
1076
- const slottedNodes = this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes);
1077
1093
  if (slotNode) {
1078
- let found = false;
1079
- slottedNodes.forEach((childNode) => {
1080
- if (childNode === currentChild || currentChild === null) {
1081
- found = true;
1082
- if (currentChild === null || slotName !== currentChild["s-sn"]) {
1083
- this.appendChild(newChild);
1084
- return;
1085
- }
1086
- if (slotName === currentChild["s-sn"]) {
1087
- addSlotRelocateNode(newChild, slotNode);
1088
- internalCall(internalCall(currentChild, "parentNode"), "insertBefore")(newChild, currentChild);
1089
- dispatchSlotChangeEvent(slotNode);
1090
- }
1091
- return;
1094
+ if (currentChild === null) {
1095
+ this.appendChild(newChild);
1096
+ return newChild;
1097
+ }
1098
+ if ((this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes)).includes(currentChild)) {
1099
+ if (slotName !== currentChild["s-sn"]) this.appendChild(newChild);
1100
+ else {
1101
+ addSlotRelocateNode(newChild, slotNode);
1102
+ patchSlottedNode(newChild);
1103
+ internalCall(internalCall(currentChild, "parentNode"), "insertBefore")(newChild, currentChild);
1104
+ dispatchSlotChangeEvent(slotNode);
1092
1105
  }
1093
- });
1094
- if (found) return newChild;
1106
+ return newChild;
1107
+ }
1095
1108
  }
1096
1109
  /**
1097
1110
  * Fixes an issue where slotted elements are dynamically relocated in React, such as after data fetch.
@@ -1118,18 +1131,55 @@ const patchTextContent = (hostElementPrototype) => {
1118
1131
  Object.defineProperty(hostElementPrototype, "textContent", {
1119
1132
  get: function() {
1120
1133
  let text = "";
1121
- (this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes)).forEach((node) => text += node.textContent || "");
1134
+ (this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes)).forEach((node) => {
1135
+ if (node.nodeType !== NODE_TYPE.CommentNode) text += node.textContent || "";
1136
+ });
1122
1137
  return text;
1123
1138
  },
1124
1139
  set: function(value) {
1125
- (this.__childNodes ? this.childNodes : getSlottedChildNodes(this.childNodes)).forEach((node) => {
1126
- if (node["s-ol"]) node["s-ol"].remove();
1127
- node.remove();
1128
- });
1129
- this.insertAdjacentHTML("beforeend", value);
1140
+ removeSlottedNodes(this);
1141
+ if (value != null && value !== "") this.append(this.ownerDocument.createTextNode(String(value)));
1130
1142
  }
1131
1143
  });
1132
1144
  };
1145
+ /**
1146
+ * Patches the `innerHTML` and `innerText` setters of a scoped component so they replace only
1147
+ * the slotted content. Natively they would also remove the component's rendered nodes and its
1148
+ * content reference node, leaving nothing for the next render to relocate into the slot.
1149
+ * The getters are left as they are.
1150
+ *
1151
+ * @param hostElementPrototype the `Element` to be patched
1152
+ */
1153
+ const patchInnerContentSetters = (hostElementPrototype) => {
1154
+ if (!globalThis.HTMLElement) return;
1155
+ const patchSetter = (proto, name, insert) => {
1156
+ const get = Object.getOwnPropertyDescriptor(proto, name)?.get;
1157
+ if (!get) return;
1158
+ Object.defineProperty(hostElementPrototype, name, {
1159
+ get,
1160
+ set: function(value) {
1161
+ removeSlottedNodes(this);
1162
+ Array.from(internalCall(this, "childNodes")).forEach((node) => {
1163
+ if (!node["s-cn"] && !node["s-nr"] && node["s-hn"] !== this.tagName) node.remove();
1164
+ });
1165
+ insert(this, value ?? "");
1166
+ }
1167
+ });
1168
+ };
1169
+ patchSetter(Element.prototype, "innerHTML", (host, value) => host.insertAdjacentHTML("beforeend", value));
1170
+ patchSetter(HTMLElement.prototype, "innerText", (host, value) => host.append(value));
1171
+ };
1172
+ /**
1173
+ * Removes the slotted nodes of a scoped component, along with their original location markers.
1174
+ *
1175
+ * @param host the host element of the component
1176
+ */
1177
+ const removeSlottedNodes = (host) => {
1178
+ (host.__childNodes ? host.childNodes : getSlottedChildNodes(host.childNodes)).forEach((node) => {
1179
+ if (node["s-ol"]) node["s-ol"].remove();
1180
+ node.remove();
1181
+ });
1182
+ };
1133
1183
  const patchChildSlotNodes = (elm) => {
1134
1184
  class FakeNodeList extends Array {
1135
1185
  item(n) {
@@ -1163,10 +1213,21 @@ const patchChildSlotNodes = (elm) => {
1163
1213
  } });
1164
1214
  };
1165
1215
  /**
1166
- * Patches sibling accessors of a 'slotted' node within a non-shadow component.
1167
- * Meaning whilst stepping through a non-shadow element's nodes, only the mock 'lightDOM' nodes are returned.
1168
- * Especially relevant when rendering components via SSR... Frameworks will often try to reconcile their
1169
- * VDOM with the real DOM by stepping through nodes with 'nextSibling' et al.
1216
+ * Patches a node slotted into a non-shadow component so it behaves as it would in a native slot:
1217
+ * - `parentNode` returns the host element
1218
+ * - `remove()` fires `slotchange` on the node's slot
1219
+ *
1220
+ * @param node the slotted node to be patched
1221
+ */
1222
+ const patchSlottedNode = (node) => {
1223
+ patchParentNode(node);
1224
+ patchSlottedRemove(node);
1225
+ };
1226
+ /**
1227
+ * Patches a slotted node from SSR markup: everything {@link patchSlottedNode} does, plus its
1228
+ * sibling accessors, so whilst stepping through a non-shadow element's nodes only the mock
1229
+ * 'lightDOM' nodes are returned. Frameworks hydrating SSR output often reconcile their VDOM with
1230
+ * the real DOM by stepping through nodes with 'nextSibling' et al.
1170
1231
  * - `nextSibling`
1171
1232
  * - `nextElementSibling`
1172
1233
  * - `previousSibling`
@@ -1174,11 +1235,11 @@ const patchChildSlotNodes = (elm) => {
1174
1235
  *
1175
1236
  * @param node the slotted node to be patched
1176
1237
  */
1177
- const patchSlottedNode = (node) => {
1238
+ const patchSsrSlottedNode = (node) => {
1178
1239
  if (!node || node.__nextSibling !== void 0 || !globalThis.Node) return;
1179
1240
  patchNextSibling(node);
1180
1241
  patchPreviousSibling(node);
1181
- patchParentNode(node);
1242
+ patchSlottedNode(node);
1182
1243
  if (node.nodeType === Node.ELEMENT_NODE) {
1183
1244
  patchNextElementSibling(node);
1184
1245
  patchPreviousElementSibling(node);
@@ -1245,6 +1306,39 @@ const patchPreviousElementSibling = (element) => {
1245
1306
  } });
1246
1307
  };
1247
1308
  /**
1309
+ * Detaches a slotted node from where it physically sits in the component's rendered DOM, through
1310
+ * the unpatched accessors. Not via `remove()`: mock-doc's `remove()` calls
1311
+ * `parentNode.removeChild()`, and a slotted node's patched `parentNode` is the host, whose patched
1312
+ * `removeChild()` would come straight back here.
1313
+ *
1314
+ * @param node the slotted node to detach
1315
+ */
1316
+ const removeSlottedNode = (node) => {
1317
+ const parent = internalCall(node, "parentNode");
1318
+ if (parent) internalCall(parent, "removeChild")(node);
1319
+ };
1320
+ /**
1321
+ * Patches `remove()` on a node slotted into a non-shadow component, so that removing it fires
1322
+ * `slotchange` on its slot (and updates fallback content), as removing a node from a native slot
1323
+ * does. Stencil's own node moves, while `isTmpDisconnected` is set, don't fire it.
1324
+ *
1325
+ * @param node the slotted node to patch
1326
+ */
1327
+ const patchSlottedRemove = (node) => {
1328
+ const child = node;
1329
+ if (!child || child.__remove || typeof child.remove !== "function") return;
1330
+ child.__remove = child.remove;
1331
+ child.remove = function() {
1332
+ const host = this["s-ol"]?.parentElement;
1333
+ const { slotNode } = findSlotFromSlottedNode(this);
1334
+ removeSlottedNode(this);
1335
+ if (slotNode && !(plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected)) {
1336
+ dispatchSlotChangeEvent(slotNode);
1337
+ updateFallbackSlotVisibility(host);
1338
+ }
1339
+ };
1340
+ };
1341
+ /**
1248
1342
  * Patches the `parentNode` accessor of a non-shadow slotted node
1249
1343
  *
1250
1344
  * @param node the slotted node to be patched
@@ -1515,13 +1609,15 @@ const addStyle = (styleContainerNode, cmpMeta, mode) => {
1515
1609
  const appliedStyles = getAppliedStyles(styleContainerNode);
1516
1610
  let styleElm;
1517
1611
  const existingStyleElm = (BUILD$1.hydrateClientSide || BUILD$1.hotModuleReplacement) && styleContainerNode.querySelector(`[sty-id="${scopeId}"]`);
1518
- if (existingStyleElm) existingStyleElm.textContent = style;
1519
- else if (!appliedStyles.has(scopeId)) {
1612
+ if (existingStyleElm) {
1613
+ if (BUILD$1.hotModuleReplacement) existingStyleElm.textContent = style;
1614
+ appliedStyles.add(scopeId);
1615
+ } else if (!appliedStyles.has(scopeId)) {
1520
1616
  styleElm = win.document.createElement("style");
1521
1617
  styleElm.textContent = style;
1522
1618
  const nonce = plt.$nonce$ ?? queryNonceMetaTagContent(win.document);
1523
1619
  if (nonce != null) styleElm.setAttribute("nonce", nonce);
1524
- 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);
1620
+ if (BUILD$1.hydrateServerSide || BUILD$1.hotModuleReplacement) styleElm.setAttribute(HYDRATED_STYLE_ID, scopeId);
1525
1621
  if (BUILD$1.hotModuleReplacement && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation) styleElm.setAttribute("data-slot-fb", "");
1526
1622
  /**
1527
1623
  * attach styles at the end of the head tag if we render scoped components
@@ -1648,20 +1744,28 @@ const getScopeId = (cmp, mode) => "sc-" + (BUILD$1.mode && mode && cmp.$flags$ &
1648
1744
  */
1649
1745
  const convertScopedToShadow = (css) => css.replace(/\/\*!@([^/]+)\*\/[^{]+\{/g, "$1{");
1650
1746
  /**
1651
- * Hydrate styles after SSR for components *not* using DSD. Convert 'scoped' styles to 'shadow'
1652
- * and add them to a constructable stylesheet.
1747
+ * Hydrate styles after SSR for shadow components that were serialized as 'scoped' (not DSD).
1748
+ * Convert their 'scoped' styles back to 'shadow' and add them to a constructable stylesheet.
1653
1749
  *
1654
- * @returns void
1750
+ * Sheets of scoped and non-encapsulated components are left alone so they stay in the
1751
+ * document head, where `addStyle()` reuses them.
1752
+ *
1753
+ * @param cmpMetas the components whose server-rendered styles may need converting
1655
1754
  */
1656
- const hydrateScopedToShadow = () => {
1755
+ const hydrateScopedToShadow = (cmpMetas) => {
1657
1756
  if (!win.document) return;
1658
- const styleElements = win.document.querySelectorAll(`[${HYDRATED_STYLE_ID}]`);
1757
+ const styleElms = win.document.querySelectorAll(`[${HYDRATED_STYLE_ID}]`);
1659
1758
  let i = 0;
1660
- for (; i < styleElements.length; i++) {
1661
- const scopeId = styleElements[i].getAttribute(HYDRATED_STYLE_ID);
1662
- const existing = styles.get(scopeId);
1663
- const allowCS = existing !== void 0 ? existing instanceof CSSStyleSheet : true;
1664
- registerStyle(scopeId, convertScopedToShadow(styleElements[i].innerHTML), allowCS);
1759
+ for (; i < styleElms.length; i++) {
1760
+ const scopeId = styleElms[i].getAttribute(HYDRATED_STYLE_ID);
1761
+ if (cmpMetas.some((cmpMeta) => {
1762
+ const cmpScopeId = "sc-" + cmpMeta.$tagName$;
1763
+ return cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation && (scopeId === cmpScopeId || BUILD$1.mode && cmpMeta.$flags$ & CMP_FLAGS.hasMode && scopeId.startsWith(cmpScopeId + "-"));
1764
+ })) {
1765
+ const existing = styles.get(scopeId);
1766
+ const allowCS = existing !== void 0 ? existing instanceof CSSStyleSheet : true;
1767
+ registerStyle(scopeId, convertScopedToShadow(styleElms[i].innerHTML), allowCS);
1768
+ }
1665
1769
  }
1666
1770
  };
1667
1771
  //#endregion
@@ -1685,6 +1789,13 @@ const isComplexType = (o) => {
1685
1789
  return o === "object" || o === "function";
1686
1790
  };
1687
1791
  //#endregion
1792
+ //#region src/runtime/signals-core.ts
1793
+ const getCore = () => globalThis[Symbol.for("stencil.preact-signals-core")] ??= SignalsCore;
1794
+ const effect = (fn, options) => getCore().effect(fn, options);
1795
+ function signal(value, options) {
1796
+ return getCore().signal(value, options);
1797
+ }
1798
+ //#endregion
1688
1799
  //#region src/runtime/event-emitter.ts
1689
1800
  const createEvent = (ref, name, flags) => {
1690
1801
  const elm = getElement(ref);
@@ -1716,7 +1827,12 @@ let _registry;
1716
1827
  const setRegistry = (registry) => {
1717
1828
  _registry = registry;
1718
1829
  };
1719
- const getRegistry = () => _registry ?? customElements;
1830
+ const getRegistry = () => _registry ?? globalThis.customElements;
1831
+ /**
1832
+ * @param elm a defined component host
1833
+ * @returns the registry the host's class was defined in, else the active registry
1834
+ */
1835
+ const getHostRegistry = (elm) => elm.constructor._registry ?? getRegistry();
1720
1836
  //#endregion
1721
1837
  //#region src/runtime/vdom/set-accessor.ts
1722
1838
  /**
@@ -1760,7 +1876,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1760
1876
  attrMap.get(memberName)?.();
1761
1877
  if (!signalAttrDisposers.has(elm)) signalAttrDisposers.set(elm, attrMap);
1762
1878
  let prevVal = oldValue;
1763
- attrMap.set(memberName, effect$1(() => {
1879
+ attrMap.set(memberName, effect(() => {
1764
1880
  const curVal = newValue.value;
1765
1881
  setAccessor(elm, memberName, prevVal, curVal, isSvg, flags);
1766
1882
  prevVal = curVal;
@@ -1840,10 +1956,10 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1840
1956
  const isComplex = isComplexType(newValue);
1841
1957
  if (!BUILD$1.lazyLoad) {
1842
1958
  const isStandardAttr = ln.startsWith("aria-") || ln.startsWith("data-");
1843
- if (!isProp && !isStandardAttr && elm.tagName?.includes("-") && elm.tagName !== "SLOT-FB" && typeof customElements !== "undefined" && !customElements.get(elm.tagName.toLowerCase())) {
1959
+ if (!isProp && !isStandardAttr && elm.tagName?.includes("-") && elm.tagName !== "SLOT-FB" && !customElements.get(elm.tagName.toLowerCase())) {
1844
1960
  if (!elm["s-pp"]) elm["s-pp"] = /* @__PURE__ */ new Map();
1845
1961
  elm["s-pp"].set(memberName, newValue);
1846
- return;
1962
+ if (isComplex || /[A-Z]/.test(memberName)) return;
1847
1963
  }
1848
1964
  }
1849
1965
  if ((isProp || isComplex && newValue !== null) && !isSvg) try {
@@ -1870,7 +1986,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialR
1870
1986
  xlink = true;
1871
1987
  }
1872
1988
  }
1873
- if (newValue == null || newValue === false) {
1989
+ if (newValue == null || newValue === false || isComplex) {
1874
1990
  if (newValue !== false || elm.getAttribute(memberName) === "" || flags & VNODE_FLAGS.isHost && !isEnumeratedAttribute(memberName)) {
1875
1991
  if (BUILD$1.vdomXlink && xlink) elm.removeAttributeNS(XLINK_NS, memberName);
1876
1992
  else elm.removeAttribute(memberName);
@@ -1961,8 +2077,10 @@ function sortedAttrNames(attrNames) {
1961
2077
  let scopeId;
1962
2078
  let contentRef;
1963
2079
  let hostTagName;
2080
+ let hostRegistry;
1964
2081
  let useNativeShadowDom = false;
1965
2082
  let checkSlotFallbackVisibility = false;
2083
+ /** Whether the current render has slotted content to relocate. Set at the start of each render. */
1966
2084
  let checkSlotRelocate = false;
1967
2085
  let isSvgMode = false;
1968
2086
  /**
@@ -1970,6 +2088,7 @@ let isSvgMode = false;
1970
2088
  * These ensure that ref callbacks are called in the correct order:
1971
2089
  * first all removal callbacks (with null), then all attachment callbacks (with elements).
1972
2090
  */
2091
+ const initialSlotChanges = /* @__PURE__ */ new Set();
1973
2092
  const refCallbacksToRemove = [];
1974
2093
  const refCallbacksToAttach = [];
1975
2094
  /** Disposers for signal subscriptions on individual DOM nodes (text nodes, <s-show> wrappers). */
@@ -1977,16 +2096,33 @@ const signalNodeDisposers = /* @__PURE__ */ new WeakMap();
1977
2096
  const disposeSignalVNode = (vnode) => {
1978
2097
  const elm = vnode.$elm$;
1979
2098
  if (elm) {
1980
- const dispose = signalNodeDisposers.get(elm);
1981
- if (dispose) {
1982
- dispose();
1983
- signalNodeDisposers.delete(elm);
1984
- }
2099
+ disposeTextSignal(elm);
1985
2100
  disposeAllSignalAttrs(elm);
1986
2101
  }
1987
2102
  vnode.$children$?.forEach(disposeSignalVNode);
1988
2103
  };
1989
2104
  /**
2105
+ * Tear down a text node's signal subscription, if it has one.
2106
+ * @param textNode the text node to unsubscribe
2107
+ */
2108
+ const disposeTextSignal = (textNode) => {
2109
+ const dispose = signalNodeDisposers.get(textNode);
2110
+ if (dispose) {
2111
+ dispose();
2112
+ signalNodeDisposers.delete(textNode);
2113
+ }
2114
+ };
2115
+ /**
2116
+ * Subscribe a text node to a signal, keeping its `data` in sync on every change.
2117
+ * @param textNode the text node to keep in sync
2118
+ * @param textSig the signal to subscribe to
2119
+ */
2120
+ const wireTextSignal = (textNode, textSig) => {
2121
+ signalNodeDisposers.set(textNode, effect(() => {
2122
+ textNode.data = String(textSig.value);
2123
+ }));
2124
+ };
2125
+ /**
1990
2126
  * Create a DOM Node corresponding to one of the children of a given VNode.
1991
2127
  *
1992
2128
  * @param oldParentVNode the parent VNode from the previous render
@@ -2008,13 +2144,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex) => {
2008
2144
  if (BUILD$1.isDev && newVNode.$elm$) consoleDevError(`The JSX ${newVNode.$text$ !== null ? `"${newVNode.$text$}" text` : `"${String(newVNode.$tag$)}" element`} node should not be shared within the same renderer. The renderer caches element lookups in order to improve performance. However, a side effect from this is that the exact same JSX node should not be reused. For more information please see https://stenciljs.com/docs/templating-jsx#avoid-shared-jsx-nodes`);
2009
2145
  if (BUILD$1.vdomText && newVNode.$text$ != null) {
2010
2146
  elm = newVNode.$elm$ = win.document.createTextNode(newVNode.$text$);
2011
- if (BUILD$1.vdomSignals && newVNode.$signal$) {
2012
- const textSig = newVNode.$signal$;
2013
- const textNode = elm;
2014
- signalNodeDisposers.set(textNode, effect$1(() => {
2015
- textNode.data = String(textSig.value);
2016
- }));
2017
- }
2147
+ if (BUILD$1.vdomSignals && newVNode.$signal$) wireTextSignal(elm, newVNode.$signal$);
2018
2148
  } else if (BUILD$1.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotReference) {
2019
2149
  elm = newVNode.$elm$ = BUILD$1.isDebug || BUILD$1.hydrateServerSide ? slotReferenceDebugNode(newVNode) : win.document.createTextNode("");
2020
2150
  if (typeof newVNode.$attrs$?.slot === "string") elm["s-sa"] = newVNode.$attrs$.slot;
@@ -2023,8 +2153,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex) => {
2023
2153
  if (BUILD$1.svg && !isSvgMode) isSvgMode = newVNode.$tag$ === "svg";
2024
2154
  if (!win.document) throw new Error("No DOM environment available for rendering.");
2025
2155
  const tag = !useNativeShadowDom && BUILD$1.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotFallback ? "slot-fb" : newVNode.$tag$;
2026
- const _reg = getRegistry();
2027
- const registryOpts = _reg !== win.customElements && tag.includes("-") ? { customElementRegistry: _reg } : void 0;
2156
+ const registryOpts = hostRegistry !== win.customElements && tag.includes("-") ? { customElementRegistry: hostRegistry } : void 0;
2028
2157
  elm = newVNode.$elm$ = BUILD$1.svg && isSvgMode ? win.document.createElementNS(SVG_NS, tag) : win.document.createElement(tag, registryOpts);
2029
2158
  if (BUILD$1.svg && isSvgMode && newVNode.$tag$ === "foreignObject") isSvgMode = false;
2030
2159
  if (BUILD$1.vdomAttribute) updateElement(null, newVNode, isSvgMode);
@@ -2282,7 +2411,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = fal
2282
2411
  }
2283
2412
  if (BUILD$1.vdomKey && idxInOld >= 0) {
2284
2413
  elmToMove = oldCh[idxInOld];
2285
- if (elmToMove.$tag$ !== newStartVnode.$tag$) node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
2414
+ if (elmToMove.$tag$ !== newStartVnode.$tag$) node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
2286
2415
  else {
2287
2416
  patch(elmToMove, newStartVnode, isInitialRender);
2288
2417
  oldCh[idxInOld] = void 0;
@@ -2375,7 +2504,17 @@ const patch = (oldVNode, newVNode, isInitialRender = false) => {
2375
2504
  else if (BUILD$1.hydrateClientSide && isInitialRender && BUILD$1.updatable && oldChildren !== null && newChildren === null) newVNode.$children$ = oldChildren;
2376
2505
  if (BUILD$1.svg && isSvgMode && tag === "svg") isSvgMode = false;
2377
2506
  } else if (BUILD$1.vdomText && BUILD$1.slotRelocation && (defaultHolder = elm["s-cr"])) defaultHolder.parentNode.textContent = text;
2378
- else if (BUILD$1.vdomText && oldVNode.$text$ !== text) elm.data = text;
2507
+ else if (BUILD$1.vdomText) {
2508
+ if (BUILD$1.vdomSignals && newVNode.$signal$) {
2509
+ if (newVNode.$signal$ !== oldVNode.$signal$) {
2510
+ disposeTextSignal(elm);
2511
+ wireTextSignal(elm, newVNode.$signal$);
2512
+ }
2513
+ } else {
2514
+ if (BUILD$1.vdomSignals && oldVNode.$signal$) disposeTextSignal(elm);
2515
+ if (oldVNode.$text$ !== text) elm.data = text;
2516
+ }
2517
+ }
2379
2518
  };
2380
2519
  /**
2381
2520
  * Component-global information about nodes which are either currently being
@@ -2501,13 +2640,17 @@ const flushQueuedRefCallbacks = () => {
2501
2640
  */
2502
2641
  const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2503
2642
  if (BUILD$1.slotRelocation) {
2643
+ if (parent?.["s-cr"]) checkSlotRelocate = true;
2504
2644
  if (BUILD$1.scoped && typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
2505
2645
  else if (typeof newNode["s-sn"] === "string") {
2506
2646
  const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2507
- 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);
2647
+ 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);
2508
2648
  parent.insertBefore(newNode, reference);
2509
2649
  const { slotNode } = findSlotFromSlottedNode(newNode);
2510
- if (slotNode && !isInitialLoad) dispatchSlotChangeEvent(slotNode);
2650
+ if (slotNode) {
2651
+ if (isInitialLoad) initialSlotChanges.add(slotNode);
2652
+ else dispatchSlotChangeEvent(slotNode);
2653
+ }
2511
2654
  return newNode;
2512
2655
  }
2513
2656
  }
@@ -2563,6 +2706,7 @@ const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
2563
2706
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
2564
2707
  const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
2565
2708
  hostTagName = hostElm.tagName;
2709
+ hostRegistry = getHostRegistry(hostElm);
2566
2710
  if (BUILD$1.isDev && Array.isArray(renderFnResults) && renderFnResults.some(isHost)) throw new Error(`The <Host> must be the single root component.
2567
2711
  Looks like the render() function of "${hostTagName.toLowerCase()}" is returning an array that contains the <Host>.
2568
2712
 
@@ -2599,6 +2743,7 @@ render() {
2599
2743
  if (BUILD$1.slotRelocation) {
2600
2744
  contentRef = hostElm["s-cr"];
2601
2745
  checkSlotFallbackVisibility = false;
2746
+ checkSlotRelocate = !useNativeShadowDom && !!(cmpMeta.$flags$ & CMP_FLAGS.hasSlot);
2602
2747
  }
2603
2748
  patch(oldVNode, rootVnode, isInitialLoad);
2604
2749
  if (BUILD$1.slotRelocation) {
@@ -2662,8 +2807,13 @@ render() {
2662
2807
  if (checkSlotFallbackVisibility) updateFallbackSlotVisibility(rootVnode.$elm$);
2663
2808
  plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
2664
2809
  relocateNodes.length = 0;
2810
+ if (initialSlotChanges.size) {
2811
+ const slotNodes = [...initialSlotChanges];
2812
+ initialSlotChanges.clear();
2813
+ nextTick(() => slotNodes.forEach(dispatchSlotChangeEvent));
2814
+ }
2665
2815
  }
2666
- if (BUILD$1.slotRelocation && !useNativeShadowDom && !(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && hostElm["s-cr"]) {
2816
+ if (BUILD$1.slotRelocation && !(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && hostElm["s-cr"]) {
2667
2817
  const children = rootVnode.$elm$.__childNodes || rootVnode.$elm$.childNodes;
2668
2818
  for (const childNode of children) if (childNode["s-hn"] !== hostTagName && childNode["s-sh"] !== hostTagName) {
2669
2819
  if (isInitialLoad && childNode["s-ih"] == null) childNode["s-ih"] = childNode.hidden ?? false;
@@ -2715,11 +2865,12 @@ const markFirstConnected = (hostRef) => {
2715
2865
  * autoloader, where the ancestor tag may not be defined yet.
2716
2866
  *
2717
2867
  * @param ancestorElm the nearest Stencil ancestor element
2868
+ * @param registry the registry the waiting component is defined in
2718
2869
  */
2719
- const awaitAncestorConnected = async (ancestorElm) => {
2870
+ const awaitAncestorConnected = async (ancestorElm, registry) => {
2720
2871
  let ancestorHostRef = getHostRef(ancestorElm);
2721
2872
  if (!BUILD$1.lazyLoad && !ancestorHostRef) {
2722
- await getRegistry().whenDefined(ancestorElm.tagName.toLowerCase());
2873
+ await registry.whenDefined(ancestorElm.tagName.toLowerCase());
2723
2874
  ancestorHostRef = getHostRef(ancestorElm);
2724
2875
  }
2725
2876
  if (ancestorHostRef && !(ancestorHostRef.$flags$ & HOST_FLAGS.hasFiredConnected)) await ensureFirstConnectPromise(ancestorHostRef);
@@ -3075,8 +3226,7 @@ const initializeSignals = (elm, hostRef, cmpMeta) => {
3075
3226
  const instance = BUILD$1.lazyLoad ? hostRef.$lazyInstance$ : elm;
3076
3227
  for (const [memberName, [memberFlags]] of Object.entries(cmpMeta.$members$ ?? {})) {
3077
3228
  if (!(memberFlags & MEMBER_FLAGS.PropLike)) continue;
3078
- const initialVal = hostRef.$instanceValues$.get(memberName);
3079
- const sig = signal(initialVal);
3229
+ const sig = signal(hostRef.$instanceValues$.get(memberName));
3080
3230
  hostRef.$signalValues$.set(memberName, sig);
3081
3231
  let prevScheduleVal = sig.peek();
3082
3232
  disposers.push(effect(() => {
@@ -3204,9 +3354,7 @@ const h = (nodeName, vnodeData, ...children) => {
3204
3354
  if (classData && !(BUILD$1.vdomSignals && isSignalLike(classData))) vnodeData.class = typeof classData !== "object" ? classData : Object.keys(classData).filter((k) => classData[k]).join(" ");
3205
3355
  }
3206
3356
  }
3207
- if (BUILD$1.isDev && vNodeChildren.some(isHost)) consoleDevError(`The <Host> must be the single root component. Make sure:
3208
- - You are NOT using hostData() and <Host> in the same component.
3209
- - <Host> is used once, and it's the single root component of the render() function.`);
3357
+ if (BUILD$1.isDev && vNodeChildren.some(isHost)) consoleDevError(`The <Host> must be used once, and be the single root component of the render() function.`);
3210
3358
  if (BUILD$1.vdomFunctional && typeof nodeName === "function") return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
3211
3359
  const vnode = newVNode(nodeName, null);
3212
3360
  vnode.$attrs$ = vnodeData;
@@ -3259,17 +3407,23 @@ const vdomFnUtils = {
3259
3407
  * Convert a {@link d.VNode} to a {@link d.ChildNode} in order to present a
3260
3408
  * friendlier public interface (hence, 'convertToPublic').
3261
3409
  *
3262
- * @param node the virtual DOM node to convert
3410
+ * Functional components receive primitive children unwrapped, so those
3411
+ * become text-only child nodes.
3412
+ *
3413
+ * @param node the virtual DOM node (or primitive child) to convert
3263
3414
  * @returns a converted child node
3264
3415
  */
3265
- const convertToPublic = (node) => ({
3416
+ const convertToPublic = (node) => typeof node !== "object" ? {
3417
+ vtag: null,
3418
+ vtext: String(node)
3419
+ } : {
3266
3420
  vattrs: node.$attrs$,
3267
3421
  vchildren: node.$children$,
3268
3422
  vkey: node.$key$,
3269
3423
  vname: node.$name$,
3270
3424
  vtag: node.$tag$,
3271
3425
  vtext: node.$text$
3272
- });
3426
+ };
3273
3427
  /**
3274
3428
  * Convert a {@link d.ChildNode} back to an equivalent {@link d.VNode} in
3275
3429
  * order to use the resulting object in the virtual DOM. The initial object was
@@ -3286,11 +3440,11 @@ const convertToPrivate = (node) => {
3286
3440
  if (node.vname) vnodeData.name = node.vname;
3287
3441
  return h(node.vtag, vnodeData, ...node.vchildren || []);
3288
3442
  }
3289
- const vnode = newVNode(node.vtag, node.vtext);
3290
- vnode.$attrs$ = node.vattrs;
3291
- vnode.$children$ = node.vchildren;
3292
- vnode.$key$ = node.vkey;
3293
- vnode.$name$ = node.vname;
3443
+ const vnode = newVNode(node.vtag ?? null, node.vtext);
3444
+ vnode.$attrs$ = node.vattrs ?? null;
3445
+ vnode.$children$ = node.vchildren ?? null;
3446
+ vnode.$key$ = node.vkey ?? null;
3447
+ vnode.$name$ = node.vname ?? null;
3294
3448
  return vnode;
3295
3449
  };
3296
3450
  /**
@@ -3340,7 +3494,10 @@ const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
3340
3494
  hostElm.classList.add(scopeId + "-h");
3341
3495
  } else if (hostElm["s-sc"]) delete hostElm["s-sc"];
3342
3496
  }
3343
- if (win.document && (!plt.$orgLocNodes$ || !plt.$orgLocNodes$.size)) initializeDocumentHydrate(win.document.body, plt.$orgLocNodes$ = /* @__PURE__ */ new Map());
3497
+ if (win.document && !plt.$orgLocNodes$?.has(hostId)) {
3498
+ initializeDocumentHydrate(win.document.body, plt.$orgLocNodes$ ??= /* @__PURE__ */ new Map());
3499
+ plt.$orgLocNodes$.set(hostId, hostElm);
3500
+ }
3344
3501
  hostElm[HYDRATE_ID] = hostId;
3345
3502
  hostElm.removeAttribute(HYDRATE_ID);
3346
3503
  hostRef.$vnode$ = clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId, slottedNodes);
@@ -3353,7 +3510,7 @@ const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
3353
3510
  const orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
3354
3511
  const node = childRenderNode.$elm$;
3355
3512
  if (!shadowRoot) {
3356
- node["s-hn"] = transformTag(tagName).toUpperCase();
3513
+ if (childRenderNode.$hostId$ === hostId) node["s-hn"] = transformTag(tagName).toUpperCase();
3357
3514
  if (childRenderNode.$tag$ === "slot") node["s-cr"] = hostElm["s-cr"];
3358
3515
  } else if (childRenderNode.$tag$?.toString().includes("-") && childRenderNode.$tag$ !== "slot-fb" && !childRenderNode.$elm$.shadowRoot) {
3359
3516
  const cmpMeta = getHostRef(childRenderNode.$elm$);
@@ -3403,14 +3560,10 @@ const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
3403
3560
  const siSlot = slottedItem.slot;
3404
3561
  if (hostEle.shadowRoot && siNode.parentElement !== hostEle) hostEle.insertBefore(siNode, slotGroup[snGroupIdx - 1]?.node?.nextSibling);
3405
3562
  if (!hostEle.shadowRoot || !shadowRoot) {
3406
- if (!siSlot["s-cr"]) {
3407
- siSlot["s-cr"] = hostEle["s-cr"];
3408
- if (!siSlot["s-cr"] && hostEle.shadowRoot) siSlot["s-cr"] = hostEle;
3409
- else siSlot["s-cr"] = (hostEle.__childNodes || hostEle.childNodes)[0];
3410
- }
3563
+ if (!siSlot["s-cr"]) siSlot["s-cr"] = hostEle["s-cr"] || (hostEle.shadowRoot ? hostEle : (hostEle.__childNodes || hostEle.childNodes)[0]);
3411
3564
  addSlotRelocateNode(siNode, siSlot, false, siNode["s-oo"] || currentPos);
3412
3565
  if (siNode.parentElement?.shadowRoot && siNode["getAttribute"] && siNode.getAttribute("slot")) siNode.removeAttribute("slot");
3413
- if (BUILD$1.lightDomPatches || BUILD$1.slotChildNodes || BUILD$1.patchAll && hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll) patchSlottedNode(siNode);
3566
+ if (BUILD$1.lightDomPatches || BUILD$1.slotChildNodes || BUILD$1.patchAll && hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll) patchSsrSlottedNode(siNode);
3414
3567
  }
3415
3568
  currentPos = (siNode["s-oo"] || currentPos) + 1;
3416
3569
  }
@@ -3470,7 +3623,7 @@ const clientHydrate = (parentVNode, childRenderNodes, slotNodes, shadowRootNodes
3470
3623
  const scopeId = hostElm["s-sc"];
3471
3624
  if (node.nodeType === NODE_TYPE.ElementNode) {
3472
3625
  childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
3473
- if (childNodeType) {
3626
+ if (childNodeType && node !== hostElm) {
3474
3627
  childIdSplt = childNodeType.split(".");
3475
3628
  if (childIdSplt[0] === hostId || childIdSplt[0] === "0") {
3476
3629
  childVNode = createSimpleVNode({
@@ -3588,6 +3741,7 @@ const initializeDocumentHydrate = (node, orgLocNodes) => {
3588
3741
  const createSimpleVNode = (vnode) => ({
3589
3742
  $flags$: 0,
3590
3743
  $index$: "0",
3744
+ $children$: null,
3591
3745
  ...vnode
3592
3746
  });
3593
3747
  function addSlot(slotName, slotId, childVNode, node, parentVNode, childRenderNodes, slotNodes, shadowRootNodes, slottedNodes) {
@@ -3651,6 +3805,11 @@ const addSlottedNodes = (slottedNodes, slotNodeId, slotName, slotNode, hostId) =
3651
3805
  * @returns the first corresponding node of the type
3652
3806
  */
3653
3807
  const findCorrespondingNode = (node, type) => {
3808
+ if (type === NODE_TYPE.TextNode) {
3809
+ const next = node.nextSibling;
3810
+ if (next?.nodeType === NODE_TYPE.TextNode) return next;
3811
+ return node.parentNode.insertBefore(node.ownerDocument.createTextNode(""), next);
3812
+ }
3654
3813
  let sibling = node;
3655
3814
  do
3656
3815
  sibling = sibling.nextSibling;
@@ -3982,7 +4141,7 @@ const scopeSelector = (selector, scopeSelectorText, hostSelector, slotSelector)
3982
4141
  else return shallowPart.trim();
3983
4142
  }).join(", ");
3984
4143
  };
3985
- const isScopableAtRule = (selector) => selector.startsWith("@media") || selector.startsWith("@supports") || selector.startsWith("@page") || selector.startsWith("@document") || selector.startsWith("@layer");
4144
+ const isScopableAtRule = (selector) => selector.startsWith("@media") || selector.startsWith("@supports") || selector.startsWith("@page") || selector.startsWith("@document") || selector.startsWith("@layer") || selector.startsWith("@container");
3986
4145
  const scopeSelectors = (cssText, scopeSelectorText, hostSelector, slotSelector, commentOriginalSelector) => {
3987
4146
  return processRules(cssText, (rule) => {
3988
4147
  let selector = rule.selector;
@@ -4101,8 +4260,11 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
4101
4260
  };
4102
4261
  //#endregion
4103
4262
  //#region src/runtime/mode.ts
4104
- const computeMode = (elm) => modeResolutionChain.map((h) => h(elm)).find((m) => !!m);
4105
- const setMode = (handler) => modeResolutionChain.push(handler);
4263
+ const computeMode = (elm) => modeResolver.map((h) => h(elm)).find((m) => !!m);
4264
+ const setMode = (handler) => {
4265
+ modeResolver.length = 0;
4266
+ modeResolver.push(handler);
4267
+ };
4106
4268
  const getMode = (ref) => getHostRef(ref)?.$modeName$;
4107
4269
  //#endregion
4108
4270
  //#region src/runtime/normalize-watchers.ts
@@ -4167,23 +4329,14 @@ const normalizeWatchers = (raw) => {
4167
4329
  *
4168
4330
  * @param propValue the new value to coerce to some type
4169
4331
  * @param propType the type of the prop, expressed as a binary number
4170
- * @param isFormAssociated whether the component is form-associated (optional)
4171
4332
  * @returns the parsed/coerced value
4172
4333
  */
4173
- const parsePropertyValue = (propValue, propType, isFormAssociated) => {
4334
+ const parsePropertyValue = (propValue, propType) => {
4174
4335
  if (propValue != null && !isComplexType(propValue)) {
4175
4336
  /**
4176
4337
  * ensure this value is of the correct prop type
4177
4338
  */
4178
- if (BUILD$1.propBoolean && propType & MEMBER_FLAGS.Boolean) {
4179
- /**
4180
- * For form-associated components, according to HTML spec, the presence of any boolean attribute
4181
- * (regardless of its value, even "false") should make the property true.
4182
- * For non-form-associated components, we maintain the legacy behavior where "false" becomes false.
4183
- */
4184
- if (BUILD$1.formAssociated && isFormAssociated && typeof propValue === "string") return propValue === "" || !!propValue;
4185
- else return propValue === "false" ? false : propValue === "" || !!propValue;
4186
- }
4339
+ if (BUILD$1.propBoolean && propType & MEMBER_FLAGS.Boolean) return propValue === "" || !!propValue;
4187
4340
  /**
4188
4341
  * force it to be a number
4189
4342
  */
@@ -4225,7 +4378,7 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
4225
4378
  if (BUILD$1.signalBacking) {
4226
4379
  const sig = hostRef?.$signalValues$?.get(propName);
4227
4380
  if (sig !== void 0) {
4228
- const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0], BUILD$1.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
4381
+ const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
4229
4382
  if (BUILD$1.serializer && BUILD$1.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) {
4230
4383
  const elm = BUILD$1.lazyLoad ? hostRef.$hostElement$ : ref;
4231
4384
  applySerializers(hostRef, cmpMeta, propName, parsed, BUILD$1.lazyLoad ? hostRef.$lazyInstance$ : elm);
@@ -4243,7 +4396,7 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
4243
4396
  const oldVal = hostRef.$instanceValues$.get(propName);
4244
4397
  const flags = hostRef.$flags$;
4245
4398
  const instance = BUILD$1.lazyLoad ? hostRef.$lazyInstance$ : elm;
4246
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0], BUILD$1.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
4399
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
4247
4400
  const didValueChange = newVal !== oldVal && !(Number.isNaN(oldVal) && Number.isNaN(newVal));
4248
4401
  if ((!BUILD$1.lazyLoad || !(flags & HOST_FLAGS.isConstructingInstance) || oldVal === void 0) && didValueChange) {
4249
4402
  hostRef.$instanceValues$.set(propName, newVal);
@@ -4292,6 +4445,22 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
4292
4445
  */
4293
4446
  const reflectedAttrValue = (propValue) => propValue == null || propValue === false ? null : propValue === true ? "" : String(propValue);
4294
4447
  /**
4448
+ * Hand values written to a lazy component's element before its instance existed to the
4449
+ * instance's own `@Prop` setters. Must run as soon as the instance is constructed, so that
4450
+ * whenever `$lazyInstance$` is set, reads through it agree with the element's last write.
4451
+ *
4452
+ * @param hostRef the runtime bookkeeping object of a freshly constructed lazy instance
4453
+ * @param cmpMeta runtime metadata for the component (with any run-time only setters flagged)
4454
+ */
4455
+ const replayPendingSetterValues = (hostRef, cmpMeta) => {
4456
+ const instance = hostRef.$lazyInstance$;
4457
+ if (!instance) return;
4458
+ for (const [memberName, [memberFlags]] of Object.entries(cmpMeta.$members$ ?? {})) if (memberFlags & MEMBER_FLAGS.Setter && hostRef.$instanceValues$.has(memberName)) {
4459
+ const pendingValue = hostRef.$instanceValues$.get(memberName);
4460
+ if (instance[memberName] !== pendingValue) instance[memberName] = pendingValue;
4461
+ }
4462
+ };
4463
+ /**
4295
4464
  * Attach a series of runtime constructs to a compiled Stencil component
4296
4465
  * constructor, including getters and setters for the `@Prop` and `@State`
4297
4466
  * decorators, callbacks for when attributes change, and so on.
@@ -4348,9 +4517,8 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4348
4517
  if (BUILD$1.lazyLoad) {
4349
4518
  if ((cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Getter) === 0) return getValue(this, memberName);
4350
4519
  const ref = getHostRef(this);
4351
- const instance = ref ? ref.$lazyInstance$ : prototype;
4352
- if (!instance) return;
4353
- return instance[memberName];
4520
+ if (!ref) return prototype[memberName];
4521
+ return ref.$lazyInstance$ ? ref.$lazyInstance$[memberName] : getValue(this, memberName);
4354
4522
  }
4355
4523
  if (!BUILD$1.lazyLoad) return origGetter ? origGetter.apply(this) : getValue(this, memberName);
4356
4524
  },
@@ -4365,7 +4533,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4365
4533
  }
4366
4534
  if (origSetter) {
4367
4535
  if (typeof (memberFlags & MEMBER_FLAGS.State ? this[memberName] : ref.$hostElement$[memberName]) === "undefined" && ref.$instanceValues$.get(memberName)) newValue = ref.$instanceValues$.get(memberName);
4368
- origSetter.apply(this, [parsePropertyValue(newValue, memberFlags, BUILD$1.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated))]);
4536
+ origSetter.apply(this, [parsePropertyValue(newValue, memberFlags)]);
4369
4537
  newValue = memberFlags & MEMBER_FLAGS.State ? this[memberName] : ref.$hostElement$[memberName];
4370
4538
  setValue(this, memberName, newValue, cmpMeta);
4371
4539
  return;
@@ -4377,21 +4545,15 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4377
4545
  if (BUILD$1.lazyLoad) {
4378
4546
  if ((flags & PROXY_FLAGS.isElementConstructor) === 0 || (cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Setter) === 0) {
4379
4547
  setValue(this, memberName, newValue, cmpMeta);
4380
- if (flags & PROXY_FLAGS.isElementConstructor && !ref.$lazyInstance$) ref.$fetchedCbList$.push(() => {
4381
- if (cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Setter && ref.$lazyInstance$[memberName] !== ref.$instanceValues$.get(memberName)) ref.$lazyInstance$[memberName] = newValue;
4382
- });
4383
4548
  return;
4384
4549
  }
4385
- const setterSetVal = () => {
4550
+ const parsedValue = parsePropertyValue(newValue, memberFlags);
4551
+ if (ref.$lazyInstance$) {
4386
4552
  const currentValue = ref.$lazyInstance$[memberName];
4387
4553
  if (!ref.$instanceValues$.get(memberName) && currentValue) ref.$instanceValues$.set(memberName, currentValue);
4388
- ref.$lazyInstance$[memberName] = parsePropertyValue(newValue, memberFlags, BUILD$1.formAssociated && !!(cmpMeta.$flags$ & CMP_FLAGS.formAssociated));
4554
+ ref.$lazyInstance$[memberName] = parsedValue;
4389
4555
  setValue(this, memberName, ref.$lazyInstance$[memberName], cmpMeta);
4390
- };
4391
- if (ref.$lazyInstance$) setterSetVal();
4392
- else ref.$fetchedCbList$.push(() => {
4393
- setterSetVal();
4394
- });
4556
+ } else ref.$instanceValues$.set(memberName, parsedValue);
4395
4557
  }
4396
4558
  } });
4397
4559
  } else if (BUILD$1.lazyLoad && BUILD$1.method && flags & PROXY_FLAGS.isElementConstructor && memberFlags & MEMBER_FLAGS.Method) Object.defineProperty(prototype, memberName, { value(...args) {
@@ -4433,7 +4595,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4433
4595
  const instance = BUILD$1.lazyLoad ? hostRef.$lazyInstance$ : elm;
4434
4596
  (cmpMeta.$watchers$?.[attrName])?.forEach((watcher) => {
4435
4597
  const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
4436
- if (instance[watchMethodName] != null && (hostFlags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate)) instance[watchMethodName](newValue, oldValue, attrName);
4598
+ if (instance?.[watchMethodName] != null && (hostFlags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate)) instance[watchMethodName](newValue, oldValue, attrName);
4437
4599
  });
4438
4600
  }
4439
4601
  return;
@@ -4443,9 +4605,13 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4443
4605
  const isBooleanTarget = propMemberFlags & MEMBER_FLAGS.Boolean;
4444
4606
  if (BUILD$1.reflect && propMemberFlags & MEMBER_FLAGS.ReflectAttr && propMemberFlags & MEMBER_FLAGS.Any && !isComplexType(this[propName]) && reflectedAttrValue(this[propName]) === newValue) return;
4445
4607
  const isSpuriousBooleanRemoval = isBooleanTarget && newValue === null && this[propName] === void 0;
4446
- if (isBooleanTarget) newValue = !(newValue === null || newValue === "false");
4608
+ if (isBooleanTarget) {
4609
+ if (BUILD$1.isDev && newValue === "false") consoleDevWarn(`<${cmpMeta.$tagName$} ${attrName}="false">: boolean attributes are true when present, regardless of value. Remove the attribute or set the "${propName}" property to false instead.`);
4610
+ newValue = newValue !== null;
4611
+ }
4447
4612
  const propDesc = Object.getOwnPropertyDescriptor(prototype, propName);
4448
- if (!isSpuriousBooleanRemoval && newValue != this[propName] && (!propDesc.get || !!propDesc.set)) this[propName] = newValue;
4613
+ const isUnchanged = newValue === this[propName] || newValue == null && this[propName] == null;
4614
+ if (!isSpuriousBooleanRemoval && !isUnchanged && (!propDesc.get || !!propDesc.set)) this[propName] = newValue;
4449
4615
  });
4450
4616
  };
4451
4617
  Cstr.observedAttributes = Array.from(/* @__PURE__ */ new Set([...Object.keys(cmpMeta.$watchers$ ?? {}), ...members.filter(([_, m]) => m[0] & MEMBER_FLAGS.HasAttribute).map(([propName, m]) => {
@@ -4506,9 +4672,12 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4506
4672
  } catch (e) {
4507
4673
  consoleError(e, elm);
4508
4674
  }
4509
- if (BUILD$1.member) hostRef.$flags$ &= ~HOST_FLAGS.isConstructingInstance;
4675
+ if (BUILD$1.member) {
4676
+ hostRef.$flags$ &= ~HOST_FLAGS.isConstructingInstance;
4677
+ replayPendingSetterValues(hostRef, cmpMeta);
4678
+ }
4510
4679
  endNewInstance();
4511
- if (BUILD$1.asyncLoading && hostRef.$ancestorComponent$) await awaitAncestorConnected(hostRef.$ancestorComponent$);
4680
+ if (BUILD$1.asyncLoading && hostRef.$ancestorComponent$) await awaitAncestorConnected(hostRef.$ancestorComponent$, getHostRegistry(elm));
4512
4681
  if (!(BUILD$1.slotRelocation && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation)) {
4513
4682
  fireConnectedCallback(hostRef.$lazyInstance$, elm);
4514
4683
  if (BUILD$1.asyncLoading) markFirstConnected(hostRef);
@@ -4608,9 +4777,16 @@ const connectedCallback = (elm) => {
4608
4777
  }
4609
4778
  if (BUILD$1.asyncLoading) {
4610
4779
  let ancestorComponent = elm;
4611
- 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"]) {
4612
- attachToAncestor(hostRef, hostRef.$ancestorComponent$ = ancestorComponent);
4613
- break;
4780
+ while (ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host) {
4781
+ if (BUILD$1.hydrateClientSide && !ancestorComponent["s-p"] && ancestorComponent.nodeType === NODE_TYPE.ElementNode && ancestorComponent.hasAttribute("s-id")) {
4782
+ ancestorComponent["s-p"] = [];
4783
+ ancestorComponent["s-rc"] = [];
4784
+ ancestorComponent["s-pc"] = [];
4785
+ }
4786
+ if (ancestorComponent["s-p"]) {
4787
+ attachToAncestor(hostRef, hostRef.$ancestorComponent$ = ancestorComponent);
4788
+ break;
4789
+ }
4614
4790
  }
4615
4791
  }
4616
4792
  if (BUILD$1.prop && !BUILD$1.hydrateServerSide && cmpMeta.$members$) Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
@@ -4726,48 +4902,112 @@ const hmrStandalone = async (hostElement, cmpMeta, hmrVersionId) => {
4726
4902
  `${modulePath}?s-hmr=${hmrVersionId}`
4727
4903
  );
4728
4904
  const NewClass = Object.values(newModule).find((v) => typeof v === "function" && v.is === cmpMeta.$tagName$) ?? newModule.default;
4729
- if (!NewClass) return;
4730
- const ctor = customElements.get(cmpMeta.$tagName$);
4731
- if (ctor) {
4732
- for (const key of Object.getOwnPropertyNames(NewClass.prototype)) {
4733
- if (key === "constructor") continue;
4734
- Object.defineProperty(ctor.prototype, key, Object.getOwnPropertyDescriptor(NewClass.prototype, key));
4735
- }
4736
- const styleDesc = Object.getOwnPropertyDescriptor(NewClass, "style");
4737
- if (styleDesc) {
4738
- Object.defineProperty(ctor, "style", styleDesc);
4739
- const newStyle = NewClass.style;
4740
- if (newStyle) {
4741
- const scopeId = getScopeId(cmpMeta);
4742
- const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4743
- console.log("[stencil-hmr] registerStyle", {
4744
- tag: cmpMeta.$tagName$,
4745
- scopeId,
4746
- isShadow,
4747
- cssLen: newStyle.length
4748
- });
4749
- registerStyle(scopeId, newStyle, isShadow);
4750
- }
4751
- }
4752
- }
4753
- const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4754
- document.querySelectorAll(cmpMeta.$tagName$).forEach((el) => {
4755
- const hostRef = getHostRef(el);
4756
- if (BUILD$1.hostListener && hostRef?.$rmListeners$) {
4757
- hostRef.$rmListeners$.map((rmListener) => rmListener());
4758
- hostRef.$rmListeners$ = void 0;
4759
- addHostEventListeners(el, hostRef, cmpMeta.$listeners$);
4760
- }
4761
- if (!isShadow && hostRef) {
4762
- console.log("[stencil-hmr] calling attachStyles for", cmpMeta.$tagName$);
4763
- attachStyles(hostRef);
4764
- }
4765
- forceUpdate(el);
4766
- });
4905
+ if (NewClass) hmrApplyClass(cmpMeta, NewClass);
4767
4906
  } catch (e) {
4768
4907
  console.error(`[Stencil HMR] Failed to reload <${cmpMeta.$tagName$}>`, e);
4769
4908
  }
4770
4909
  };
4910
+ /**
4911
+ * Patch a re-executed component class onto the registered one and re-render every live instance.
4912
+ * Shared by the standalone re-import above and bundlers that re-execute the module themselves
4913
+ * (webpack/rspack `module.hot`), which reach it via the constructor's `s-hmr-apply` hook.
4914
+ *
4915
+ * @param cmpMeta runtime metadata for the component
4916
+ * @param NewClass the component's newly executed class
4917
+ */
4918
+ const hmrApplyClass = (cmpMeta, NewClass) => {
4919
+ const ctor = customElements.get(cmpMeta.$tagName$);
4920
+ const isShadow = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation);
4921
+ if (ctor && ctor !== NewClass) {
4922
+ for (const key of Object.getOwnPropertyNames(NewClass.prototype)) {
4923
+ if (key === "constructor") continue;
4924
+ Object.defineProperty(ctor.prototype, key, Object.getOwnPropertyDescriptor(NewClass.prototype, key));
4925
+ }
4926
+ const styleDesc = Object.getOwnPropertyDescriptor(NewClass, "style");
4927
+ if (styleDesc) {
4928
+ Object.defineProperty(ctor, "style", styleDesc);
4929
+ const newStyle = NewClass.style;
4930
+ if (newStyle) registerStyle(getScopeId(cmpMeta), newStyle, isShadow);
4931
+ }
4932
+ }
4933
+ document.querySelectorAll(cmpMeta.$tagName$).forEach((el) => {
4934
+ const hostRef = getHostRef(el);
4935
+ if (BUILD$1.hostListener && hostRef?.$rmListeners$) {
4936
+ hostRef.$rmListeners$.map((rmListener) => rmListener());
4937
+ hostRef.$rmListeners$ = void 0;
4938
+ addHostEventListeners(el, hostRef, cmpMeta.$listeners$);
4939
+ }
4940
+ if (!isShadow && hostRef) attachStyles(hostRef);
4941
+ forceUpdate(el);
4942
+ });
4943
+ };
4944
+ //#endregion
4945
+ //#region src/runtime/parse-gate.ts
4946
+ /**
4947
+ * SSR hosts connected while the HTML parser is still inside them (streamed documents),
4948
+ * in connection order - which is document order. Each is held until its subtree is
4949
+ * parsed so hydration sees its declarative shadow root and children.
4950
+ */
4951
+ const pending = /* @__PURE__ */ new Set();
4952
+ let observer;
4953
+ const parentOf = (node) => node.parentNode ?? (node.nodeType === NODE_TYPE.DocumentFragment ? node.host : null);
4954
+ /**
4955
+ * The parser has finished with `elm` once it, or any ancestor, has a following sibling.
4956
+ * @param elm the element to check
4957
+ * @returns whether the element's subtree is fully parsed
4958
+ */
4959
+ const isParsed = (elm) => {
4960
+ if (win.document.readyState !== "loading") return true;
4961
+ for (let n = elm; n; n = parentOf(n)) if (n.nextSibling) return true;
4962
+ return false;
4963
+ };
4964
+ const hasPendingAncestor = (elm) => {
4965
+ for (let n = parentOf(elm); n; n = parentOf(n)) if (pending.has(n)) return true;
4966
+ return false;
4967
+ };
4968
+ const flush = () => {
4969
+ for (const elm of pending) if (!elm.isConnected) pending.delete(elm);
4970
+ else if (isParsed(elm)) elm.__attachShadow?.();
4971
+ for (const elm of pending) if (isParsed(elm) && !hasPendingAncestor(elm)) {
4972
+ pending.delete(elm);
4973
+ elm.connectedCallback?.();
4974
+ }
4975
+ if (!pending.size) {
4976
+ observer?.disconnect();
4977
+ observer = void 0;
4978
+ }
4979
+ };
4980
+ /**
4981
+ * Whether the parser may still be adding children (including a declarative shadow root)
4982
+ * to `elm`: it was just created by the parser, or it's an SSR host the parser is still inside.
4983
+ * @param elm the host element
4984
+ * @returns `true` if the element's subtree may be incomplete
4985
+ */
4986
+ const mayStillBeParsing = (elm) => win.document?.readyState === "loading" && (!elm.parentNode || elm.hasAttribute("s-id") && !isParsed(elm));
4987
+ /**
4988
+ * Holds back `elm`'s `connectedCallback` while it's an SSR host the parser hasn't finished
4989
+ * with, or one nested inside such a host. Its shadow root is attached once its own subtree
4990
+ * is parsed; `connectedCallback` is re-called once no ancestor host is still held.
4991
+ * @param elm the host element being connected
4992
+ * @returns `true` if processing was deferred
4993
+ */
4994
+ const deferUntilParsed = (elm) => {
4995
+ if (pending.has(elm)) return true;
4996
+ if (!win.document || !elm.hasAttribute("s-id")) return false;
4997
+ const parsed = isParsed(elm);
4998
+ if (parsed && !hasPendingAncestor(elm)) return false;
4999
+ if (parsed) elm.__attachShadow?.();
5000
+ pending.add(elm);
5001
+ if (!observer) {
5002
+ observer = new MutationObserver(flush);
5003
+ observer.observe(win.document, {
5004
+ childList: true,
5005
+ subtree: true
5006
+ });
5007
+ win.document.addEventListener("DOMContentLoaded", flush, { once: true });
5008
+ }
5009
+ return true;
5010
+ };
4771
5011
  //#endregion
4772
5012
  //#region src/runtime/bootstrap-standalone.ts
4773
5013
  const defineCustomElement = (Cstr, compactMeta) => {
@@ -4790,9 +5030,13 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4790
5030
  cmpMeta.$serializers$ = Cstr.$serializers$;
4791
5031
  }
4792
5032
  if (BUILD$1.reflect) cmpMeta.$attrsToReflect$ = [];
4793
- if (BUILD$1.hotModuleReplacement) Cstr.prototype["s-hmr"] = function(hmrVersionId) {
4794
- hmrStart(this, cmpMeta, hmrVersionId);
4795
- };
5033
+ if (BUILD$1.shadowReferenceTarget) cmpMeta.$referenceTarget$ = compactMeta[7];
5034
+ if (BUILD$1.hotModuleReplacement) {
5035
+ Cstr.prototype["s-hmr"] = function(hmrVersionId) {
5036
+ hmrStart(this, cmpMeta, hmrVersionId);
5037
+ };
5038
+ Cstr["s-hmr-apply"] = (NewClass) => hmrApplyClass(cmpMeta, NewClass);
5039
+ }
4796
5040
  if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && (BUILD$1.slotCloneNode || BUILD$1.patchClone && cmpMeta.$flags$ & CMP_FLAGS.patchClone)) patchCloneNode(Cstr.prototype);
4797
5041
  if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && cmpMeta.$flags$ & CMP_FLAGS.hasSlot) {
4798
5042
  if (BUILD$1.lightDomPatches || BUILD$1.patchAll && cmpMeta.$flags$ & CMP_FLAGS.patchAll) applyLightDomPatches(Cstr.prototype);
@@ -4805,11 +5049,12 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4805
5049
  patchSlotInsertAdjacentHTML(Cstr.prototype);
4806
5050
  patchInsertBefore(Cstr.prototype);
4807
5051
  patchSlotRemoveChild(Cstr.prototype);
5052
+ patchInnerContentSetters(Cstr.prototype);
4808
5053
  }
4809
5054
  if (BUILD$1.slotTextContent) patchTextContent(Cstr.prototype);
4810
5055
  }
4811
5056
  }
4812
- if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) hydrateScopedToShadow();
5057
+ if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) hydrateScopedToShadow([cmpMeta]);
4813
5058
  const originalConnectedCallback = Cstr.prototype.connectedCallback;
4814
5059
  const originalDisconnectedCallback = Cstr.prototype.disconnectedCallback;
4815
5060
  Object.assign(Cstr.prototype, {
@@ -4821,6 +5066,8 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4821
5066
  return getHostRef(this)?.$onReadyPromise$;
4822
5067
  },
4823
5068
  async connectedCallback() {
5069
+ if (BUILD$1.hydrateClientSide && deferUntilParsed(this)) return;
5070
+ if (BUILD$1.shadowDom) this.__attachShadow();
4824
5071
  const isFirstConnect = !this.__hasHostListenerAttached;
4825
5072
  let hostRef;
4826
5073
  if (isFirstConnect) {
@@ -4831,7 +5078,7 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4831
5078
  }
4832
5079
  connectedCallback(this);
4833
5080
  if (BUILD$1.asyncLoading && hostRef && hostRef.$ancestorComponent$) {
4834
- await awaitAncestorConnected(hostRef.$ancestorComponent$);
5081
+ await awaitAncestorConnected(hostRef.$ancestorComponent$, getHostRegistry(this));
4835
5082
  if (!this.isConnected) return;
4836
5083
  }
4837
5084
  if (originalConnectedCallback && (plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) originalConnectedCallback.call(this);
@@ -4842,11 +5089,10 @@ const proxyCustomElement = (Cstr, compactMeta) => {
4842
5089
  if (originalDisconnectedCallback && (plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) originalDisconnectedCallback.call(this);
4843
5090
  },
4844
5091
  __attachShadow() {
4845
- const isClosed = BUILD$1.shadowModeClosed && !!(cmpMeta.$flags$ & CMP_FLAGS.shadowModeClosed);
4846
- let existingRoot = this.shadowRoot;
4847
- if (BUILD$1.shadowModeClosed && isClosed) existingRoot = this.__shadowRoot ?? null;
5092
+ if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) || BUILD$1.hydrateClientSide && mayStillBeParsing(this)) return;
5093
+ const existingRoot = getShadowRoot(this);
4848
5094
  if (!existingRoot) createShadowRoot.call(this, cmpMeta);
4849
- 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.`);
5095
+ 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.`);
4850
5096
  }
4851
5097
  });
4852
5098
  Object.defineProperty(Cstr, "is", {
@@ -4901,7 +5147,14 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4901
5147
  Object.assign(plt, options);
4902
5148
  if (BUILD$1.asyncQueue && options.syncQueue) plt.$flags$ |= PLATFORM_FLAGS.queueSync;
4903
5149
  if (BUILD$1.hydrateClientSide) plt.$flags$ |= PLATFORM_FLAGS.appLoaded;
4904
- if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) hydrateScopedToShadow();
5150
+ if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) {
5151
+ const cmpMetas = [];
5152
+ lazyBundles.map((lazyBundle) => lazyBundle[1].map(([$flags$, $tagName$]) => cmpMetas.push({
5153
+ $flags$,
5154
+ $tagName$
5155
+ })));
5156
+ hydrateScopedToShadow(cmpMetas);
5157
+ }
4905
5158
  lazyBundles.map((lazyBundle) => {
4906
5159
  lazyBundle[1].map((compactMeta) => {
4907
5160
  const cmpMeta = {
@@ -4918,7 +5171,11 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4918
5171
  cmpMeta.$serializers$ = compactMeta[5] ?? {};
4919
5172
  cmpMeta.$deserializers$ = compactMeta[6] ?? {};
4920
5173
  }
5174
+ if (BUILD$1.shadowReferenceTarget) cmpMeta.$referenceTarget$ = compactMeta[7];
4921
5175
  const tagName = transformTag(cmpMeta.$tagName$);
5176
+ const attachShadowRoot = (elm) => {
5177
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation && !(cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) && !getShadowRoot(elm)) createShadowRoot.call(elm, cmpMeta);
5178
+ };
4922
5179
  const HostElement = class extends HTMLElement {
4923
5180
  ["s-p"];
4924
5181
  ["s-rc"];
@@ -4927,14 +5184,13 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4927
5184
  super(self);
4928
5185
  self = this;
4929
5186
  registerHost(self, cmpMeta);
4930
- if (BUILD$1.shadowDom && cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation && !(cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss)) {
4931
- if (!self.shadowRoot) createShadowRoot.call(self, cmpMeta);
4932
- 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.`);
4933
- }
5187
+ if (BUILD$1.shadowDom && !(BUILD$1.hydrateClientSide && mayStillBeParsing(self))) attachShadowRoot(self);
4934
5188
  }
4935
5189
  connectedCallback() {
4936
5190
  const hostRef = getHostRef(this);
4937
5191
  if (!hostRef) return;
5192
+ if (BUILD$1.hydrateClientSide && deferUntilParsed(this)) return;
5193
+ if (BUILD$1.shadowDom) attachShadowRoot(this);
4938
5194
  /**
4939
5195
  * The `connectedCallback` lifecycle event can potentially be fired multiple times
4940
5196
  * if the element is removed from the DOM and re-inserted. This is not a common use case,
@@ -4990,10 +5246,14 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
4990
5246
  patchSlotInsertAdjacentHTML(HostElement.prototype);
4991
5247
  patchInsertBefore(HostElement.prototype);
4992
5248
  patchSlotRemoveChild(HostElement.prototype);
5249
+ patchInnerContentSetters(HostElement.prototype);
4993
5250
  }
4994
5251
  if (BUILD$1.slotTextContent) patchTextContent(HostElement.prototype);
4995
5252
  }
4996
5253
  }
5254
+ if (BUILD$1.hydrateClientSide && BUILD$1.shadowDom) HostElement.prototype.__attachShadow = function() {
5255
+ attachShadowRoot(this);
5256
+ };
4997
5257
  if (BUILD$1.formAssociated && cmpMeta.$flags$ & CMP_FLAGS.formAssociated) HostElement.formAssociated = true;
4998
5258
  if (BUILD$1.hotModuleReplacement) HostElement.prototype["s-hmr"] = function(hmrVersionId) {
4999
5259
  hmrStart(this, cmpMeta, hmrVersionId);
@@ -5146,7 +5406,7 @@ function Mixin(...mixins) {
5146
5406
  //#region src/runtime/nonce.ts
5147
5407
  /**
5148
5408
  * Assigns the given value to the nonce property on the runtime platform object.
5149
- * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
5409
+ * During runtime, this value is used to set the nonce attribute on all dynamically created style tags.
5150
5410
  * @param nonce The value to be assigned to the platform nonce property.
5151
5411
  * @returns void
5152
5412
  */
@@ -5308,4 +5568,4 @@ function hasKeys(obj) {
5308
5568
  return false;
5309
5569
  }
5310
5570
  //#endregion
5311
- 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, injectSideEffectStyle, isMemberInElement, jsx, jsxDEV, jsxs, loadModule, modeResolutionChain, needsScopedSSR, nextTick, normalizeWatchers, parsePropertyValue, plt, postUpdateComponent, promiseResolve, proxyComponent, proxyCustomElement, readTask, registerHost, registerInstance, registerSideEffectStyleTarget, render, resolveVar, setAssetPath, setErrorHandler, setLazyLoadBasePath, setMode, setNonce, setPlatformHelpers, setPlatformOptions, setRegistry, setScopedSsr, setTagTransformer, setValue, styles, supportsConstructableStylesheets, supportsListenerOptions, supportsMutableAdoptedStyleSheets, transformTag, unregisterSideEffectStyleTarget, win, writeTask };
5571
+ 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, applySerializers, bootstrapLazy, cmpModules, connectedCallback, consoleDevError, consoleDevInfo, consoleDevWarn, consoleError, createEvent, defineCustomElement, disconnectedCallback, forceModeUpdate, forceUpdate, getAssetPath, getElement, getHostRef, getMode, getRegistry, getRenderingRef, getShadowRoot, getValue, h, injectSideEffectStyle, isMemberInElement, jsx, jsxDEV, jsxs, loadModule, modeResolver, needsScopedSSR, nextTick, normalizeWatchers, parsePropertyValue, plt, postUpdateComponent, promiseResolve, proxyComponent, proxyCustomElement, readTask, registerHost, registerInstance, registerSideEffectStyleTarget, render, resolveVar, setAssetPath, setErrorHandler, setLazyLoadBasePath, setMode, setNonce, setPlatformHelpers, setPlatformOptions, setRegistry, setScopedSSR, setTagTransformer, setValue, styles, supportsConstructableStylesheets, supportsListenerOptions, supportsMutableAdoptedStyleSheets, transformTag, unregisterSideEffectStyleTarget, win, writeTask };