@stencil/core 5.0.0-rc.14 → 5.0.0-rc.16

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.
@@ -724,7 +724,6 @@ interface BuildFeatures {
724
724
  patchInsert: boolean;
725
725
  slot: boolean;
726
726
  svg: boolean;
727
- element: boolean;
728
727
  event: boolean;
729
728
  hostListener: boolean;
730
729
  hostListenerTargetWindow: boolean;
@@ -1094,7 +1093,6 @@ interface ComponentCompilerFeatures {
1094
1093
  hasConnectedCallbackFn: boolean;
1095
1094
  hasDeserializer: boolean;
1096
1095
  hasDisconnectedCallbackFn: boolean;
1097
- hasElement: boolean;
1098
1096
  hasEvent: boolean;
1099
1097
  hasLifecycle: boolean;
1100
1098
  hasListener: boolean;
@@ -4729,7 +4729,6 @@ interface BuildFeatures {
4729
4729
  patchInsert: boolean;
4730
4730
  slot: boolean;
4731
4731
  svg: boolean;
4732
- element: boolean;
4733
4732
  event: boolean;
4734
4733
  hostListener: boolean;
4735
4734
  hostListenerTargetWindow: boolean;
@@ -5099,7 +5098,6 @@ interface ComponentCompilerFeatures {
5099
5098
  hasConnectedCallbackFn: boolean;
5100
5099
  hasDeserializer: boolean;
5101
5100
  hasDisconnectedCallbackFn: boolean;
5102
- hasElement: boolean;
5103
5101
  hasEvent: boolean;
5104
5102
  hasLifecycle: boolean;
5105
5103
  hasListener: boolean;
@@ -1,4 +1,4 @@
1
- import { cr as ResolutionHandler, dr as VNode, ir as FunctionalComponent, lr as TagTransformer, n as ChildType, or as RafCallback, p as HostElement, rr as ErrorHandler, ur as UserBuildConditionals, v as PropsType, y as RuntimeRef } from "./index-BDAZsQzV.mjs";
1
+ import { cr as ResolutionHandler, dr as VNode, ir as FunctionalComponent, lr as TagTransformer, n as ChildType, or as RafCallback, p as HostElement, rr as ErrorHandler, ur as UserBuildConditionals, v as PropsType, y as RuntimeRef } from "./index-BOBfOxcK.mjs";
2
2
  //#region src/client/client-build.d.ts
3
3
  /**
4
4
  * `isDev` / `isTesting` are getters, not copies: the transpile path (e.g. `@stencil/unplugin`)
@@ -1444,7 +1444,6 @@ interface BuildFeatures {
1444
1444
  patchInsert: boolean;
1445
1445
  slot: boolean;
1446
1446
  svg: boolean;
1447
- element: boolean;
1448
1447
  event: boolean;
1449
1448
  hostListener: boolean;
1450
1449
  hostListenerTargetWindow: boolean;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as Build, S as setErrorHandler, _ as getAssetPath, a as transformTag, b as writeTask, c as Mixin, d as Host, f as h, g as getShadowRoot, h as getElement, i as setTagTransformer, l as getMode, m as getRenderingRef, o as render, p as forceUpdate, s as ReactiveControllerHost, u as setMode, v as setAssetPath, x as setPlatformHelpers, y as readTask } from "./client-Cpehp9QL.mjs";
1
+ import { C as Build, S as setErrorHandler, _ as getAssetPath, a as transformTag, b as writeTask, c as Mixin, d as Host, f as h, g as getShadowRoot, h as getElement, i as setTagTransformer, l as getMode, m as getRenderingRef, o as render, p as forceUpdate, s as ReactiveControllerHost, u as setMode, v as setAssetPath, x as setPlatformHelpers, y as readTask } from "./client-nVB5tHhh.mjs";
2
2
  import { t as Fragment } from "./fragment-Di1hWOC8.mjs";
3
3
  //#region src/client/client-decorators.ts
4
4
  /**
@@ -1,3 +1,3 @@
1
- import { n as jsxDEV, r as jsxs, t as jsx } from "./client-Cpehp9QL.mjs";
1
+ import { n as jsxDEV, r as jsxs, t as jsx } from "./client-nVB5tHhh.mjs";
2
2
  import { t as Fragment } from "./fragment-Di1hWOC8.mjs";
3
3
  export { Fragment, jsx, jsxDEV, jsxs };
@@ -1,5 +1,5 @@
1
1
  import { n as __require } from "./rolldown-runtime-BhDjJH2R.mjs";
2
- import "./client-Cpehp9QL.mjs";
2
+ import "./client-nVB5tHhh.mjs";
3
3
  import { c as isFunction, f as isString, m as noop, r as flatOne } from "./helpers-k8xQHE77.mjs";
4
4
  import { X as TASK_CANCELED_MSG, Z as buildError, et as catchError, it as isGlob, q as normalizePath, rt as shouldIgnoreError } from "./util-Cj2D3x_h.mjs";
5
5
  import fs from "node:fs";
@@ -781,19 +781,28 @@ const getSlottedChildNodes = (childNodes) => {
781
781
  * @returns a reference to the slot node that matches the provided name, `null` otherwise
782
782
  */
783
783
  function getHostSlotNodes(childNodes, hostName, slotName) {
784
- let i = 0;
785
- let slottedNodes = [];
786
- let childNode;
787
- for (; i < childNodes.length; i++) {
788
- childNode = childNodes[i];
784
+ const slotNodes = [];
785
+ collectHostSlotNodes(childNodes, hostName, slotName, slotNodes);
786
+ return slotNodes;
787
+ }
788
+ /**
789
+ * Pre-order walk for {@link getHostSlotNodes}, appending to `out`.
790
+ * @param childNodes the nodes to search
791
+ * @param hostName the host name of the slot to match on
792
+ * @param slotName the name of the slot to match on; stops at the first match when given
793
+ * @param out the matching slot nodes, in document order
794
+ * @returns true once a named slot has been found
795
+ */
796
+ function collectHostSlotNodes(childNodes, hostName, slotName, out) {
797
+ for (let i = 0; i < childNodes.length; i++) {
798
+ const childNode = childNodes[i];
789
799
  if (childNode["s-sr"] && (!hostName || childNode["s-hn"] === hostName) && (slotName === void 0 || getSlotName(childNode) === slotName)) {
790
- slottedNodes.push(childNode);
791
- if (typeof slotName !== "undefined") return slottedNodes;
800
+ out.push(childNode);
801
+ if (slotName !== void 0) return true;
792
802
  }
793
- slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
794
- if (typeof slotName !== "undefined" && slottedNodes.length) return slottedNodes;
803
+ if (collectHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName, out) && slotName !== void 0) return true;
795
804
  }
796
- return slottedNodes;
805
+ return false;
797
806
  }
798
807
  /**
799
808
  * Get all 'child' sibling nodes of a slot node
@@ -912,11 +921,40 @@ function findSlotFromSlottedNode(slottedNode, parentHost) {
912
921
  slotName: ""
913
922
  };
914
923
  const slotName = slottedNode["s-sn"] = getSlotName(slottedNode) || "";
924
+ let hostSlots = slotNodeCache.get(parentHost);
925
+ const cached = hostSlots?.get(slotName);
926
+ if (cached && isHostSlot(cached, parentHost, slotName)) return {
927
+ slotNode: cached,
928
+ slotName
929
+ };
930
+ const slotNode = getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0];
931
+ if (slotNode) {
932
+ if (!hostSlots) slotNodeCache.set(parentHost, hostSlots = /* @__PURE__ */ new Map());
933
+ hostSlots.set(slotName, slotNode);
934
+ }
915
935
  return {
916
- slotNode: getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0],
936
+ slotNode,
917
937
  slotName
918
938
  };
919
939
  }
940
+ /**
941
+ * The slot node last found per host and slot name. Each slotted child of a host looks up its
942
+ * slot, and a full search walks the host's whole internal tree, so a host with many slotted
943
+ * children would otherwise cost O(children × tree).
944
+ */
945
+ const slotNodeCache = /* @__PURE__ */ new WeakMap();
946
+ /**
947
+ * Whether a cached slot node is still the host's slot of that name.
948
+ * @param slotNode the cached slot node
949
+ * @param host the host element
950
+ * @param slotName the slot name
951
+ * @returns true if `slotNode` is still a slot of `host` named `slotName`, inside its internal tree
952
+ */
953
+ const isHostSlot = (slotNode, host, slotName) => {
954
+ if (!slotNode["s-sr"] || slotNode["s-hn"] !== host.tagName || getSlotName(slotNode) !== slotName) return false;
955
+ for (let n = internalCall(slotNode, "parentNode"); n; n = internalCall(n, "parentNode")) if (n === host) return true;
956
+ return false;
957
+ };
920
958
  //#endregion
921
959
  //#region src/runtime/dom-extras.ts
922
960
  const applyLightDomPatches = (hostElementPrototype) => {
@@ -2698,8 +2736,7 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2698
2736
  if (parent?.["s-cr"]) checkSlotRelocate = true;
2699
2737
  if (BUILD.scoped && typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
2700
2738
  else if (typeof newNode["s-sn"] === "string") {
2701
- const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2702
- if ((BUILD.lightDomPatches || BUILD.slotChildNodes || BUILD.patchAll && !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchSlottedNode(newNode);
2739
+ if ((BUILD.lightDomPatches || BUILD.slotChildNodes || BUILD.patchAll && hostPatchesAll(newNode, parent)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchSlottedNode(newNode);
2703
2740
  parent.insertBefore(newNode, reference);
2704
2741
  const { slotNode } = findSlotFromSlottedNode(newNode);
2705
2742
  if (slotNode) {
@@ -2713,6 +2750,16 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2713
2750
  else return parent?.insertBefore(newNode, reference);
2714
2751
  };
2715
2752
  /**
2753
+ * Whether the host a slotted node belongs to opted into `patchAll`.
2754
+ * @param newNode the slotted node
2755
+ * @param parent the node it is being inserted into
2756
+ * @returns true if the host component has the `patchAll` flag
2757
+ */
2758
+ const hostPatchesAll = (newNode, parent) => {
2759
+ const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2760
+ return !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll);
2761
+ };
2762
+ /**
2716
2763
  * Adds or removes a scoped class to the parent element of a slotted node.
2717
2764
  * This is used for styling slotted content (e.g. with `::scoped(...) {...}` selectors )
2718
2765
  * in `scoped: true` components.
@@ -4208,7 +4255,7 @@ const insertPolyfillHostInCssText = (cssText) => {
4208
4255
  const _colonHostContextRe = createSupportsRuleRe(":host-context");
4209
4256
  cssText = cssText.replace(_colonHostContextRe, `$1${_polyfillHostContext}`).replace(_colonHostRe, `$1${_polyfillHost}`).replace(_colonSlottedRe, `$1${_polyfillSlotted}`);
4210
4257
  supportsBlocks.forEach((originalSelector, index) => {
4211
- cssText = cssText.replace(`__supports_${index}__`, originalSelector);
4258
+ cssText = cssText.replace(`__supports_${index}__`, () => originalSelector);
4212
4259
  });
4213
4260
  return cssText;
4214
4261
  };
@@ -4441,11 +4488,11 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
4441
4488
  const scoped = scopeCssText(cssText, scopeId, hostScopeId, slotScopeId, commentOriginalSelector);
4442
4489
  cssText = [scoped.cssText, ...commentsWithHash].join("\n");
4443
4490
  if (commentOriginalSelector) orgSelectors.forEach(({ placeholder, comment }) => {
4444
- cssText = cssText.replace(placeholder, comment);
4491
+ cssText = cssText.replace(placeholder, () => comment);
4445
4492
  });
4446
4493
  scoped.slottedSelectors.forEach((slottedSelector) => {
4447
4494
  const regex = new RegExp(escapeRegExpSpecialCharacters(slottedSelector.orgSelector) + "(?=\\s*[,{]|$)", "g");
4448
- cssText = cssText.replace(regex, slottedSelector.updatedSelector);
4495
+ cssText = cssText.replace(regex, () => slottedSelector.updatedSelector);
4449
4496
  });
4450
4497
  cssText = expandPartSelectors(cssText);
4451
4498
  return cssText;
@@ -4690,6 +4737,28 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4690
4737
  };
4691
4738
  //#endregion
4692
4739
  //#region src/runtime/initialize-component.ts
4740
+ /** Distinct style texts kept; an app has one per component and mode. */
4741
+ const SSR_CSS_CACHE_MAX = 1e3;
4742
+ /**
4743
+ * Memoizes a server-side rewrite of a component's style text. The rewrites are pure, but the
4744
+ * platform (and its `styles` registry) is rebuilt per render, so without this they'd rerun on
4745
+ * every render.
4746
+ * @param style the component's style text
4747
+ * @param key what the rewrite depends on besides the text
4748
+ * @param rewrite computes the result
4749
+ * @returns the rewritten style
4750
+ */
4751
+ const ssrCachedCss = (style, key, rewrite) => {
4752
+ if (typeof $stencilSsrCssCache === "undefined" || typeof style !== "string") return rewrite();
4753
+ let byKey = $stencilSsrCssCache.get(style);
4754
+ if (!byKey) {
4755
+ if ($stencilSsrCssCache.size >= SSR_CSS_CACHE_MAX) $stencilSsrCssCache.clear();
4756
+ $stencilSsrCssCache.set(style, byKey = /* @__PURE__ */ new Map());
4757
+ }
4758
+ let result = byKey.get(key);
4759
+ if (result === void 0) byKey.set(key, result = rewrite());
4760
+ return result;
4761
+ };
4693
4762
  /**
4694
4763
  * Initialize a Stencil component given a reference to its host element, its
4695
4764
  * runtime bookkeeping data structure, runtime metadata about the component,
@@ -4790,8 +4859,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4790
4859
  if (!styles.has(scopeId) || BUILD.hotModuleReplacement && hmrVersionId) {
4791
4860
  const endRegisterStyles = createTime("registerStyles", cmpMeta.$tagName$);
4792
4861
  if (BUILD.hydrateServerSide && BUILD.shadowDom) {
4793
- if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = scopeCss(style, scopeId, true);
4794
- else if (needsScopedSSR()) style = expandPartSelectors(style);
4862
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = ssrCachedCss(style, `s:${scopeId}`, () => scopeCss(style, scopeId, true));
4863
+ else if (needsScopedSSR()) style = ssrCachedCss(style, "p", () => expandPartSelectors(style));
4795
4864
  }
4796
4865
  registerStyle(scopeId, style, !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation));
4797
4866
  endRegisterStyles();
@@ -5010,12 +5079,12 @@ const hmrApplyClass = (cmpMeta, NewClass) => {
5010
5079
  /**
5011
5080
  * SSR hosts connected while the HTML parser is still inside them (streamed documents),
5012
5081
  * in connection order - which is document order. Each is held until its subtree is
5013
- * parsed so hydration sees its declarative shadow root and children.
5082
+ * parsed so hydration sees its declarative shadow root and children, and watched for
5083
+ * its end marker arriving (wherever it is - a document observer can't see into shadow roots).
5014
5084
  */
5015
- const pending = /* @__PURE__ */ new Set();
5085
+ const pending = /* @__PURE__ */ new Map();
5016
5086
  /** SSR hosts seen parsed: hydration may since have moved or removed their end marker */
5017
5087
  const parsedHosts = /* @__PURE__ */ new WeakSet();
5018
- let observer;
5019
5088
  const parentOf = (node) => node.parentNode ?? (node.nodeType === NODE_TYPE.DocumentFragment ? node.host : null);
5020
5089
  /**
5021
5090
  * The server writes a `HOST_END_ID` comment as an SSR host's last child, so the parser has
@@ -5035,17 +5104,17 @@ const hasPendingAncestor = (elm) => {
5035
5104
  for (let n = parentOf(elm); n; n = parentOf(n)) if (pending.has(n)) return true;
5036
5105
  return false;
5037
5106
  };
5107
+ const drop = (elm) => {
5108
+ pending.get(elm)?.disconnect();
5109
+ pending.delete(elm);
5110
+ };
5038
5111
  const flush = () => {
5039
- for (const elm of pending) if (!elm.isConnected) pending.delete(elm);
5112
+ for (const elm of pending.keys()) if (!elm.isConnected) drop(elm);
5040
5113
  else if (isParsed(elm)) elm.__attachShadow?.();
5041
- for (const elm of pending) if (isParsed(elm) && !hasPendingAncestor(elm)) {
5042
- pending.delete(elm);
5114
+ for (const elm of pending.keys()) if (isParsed(elm) && !hasPendingAncestor(elm)) {
5115
+ drop(elm);
5043
5116
  elm.connectedCallback?.();
5044
5117
  }
5045
- if (!pending.size) {
5046
- observer?.disconnect();
5047
- observer = void 0;
5048
- }
5049
5118
  };
5050
5119
  /**
5051
5120
  * Whether the parser may still be adding children (including a declarative shadow root)
@@ -5064,18 +5133,13 @@ const mayStillBeParsing = (elm) => win.document?.readyState === "loading" && (!e
5064
5133
  const deferUntilParsed = (elm) => {
5065
5134
  if (pending.has(elm)) return true;
5066
5135
  if (!win.document || !elm.hasAttribute("s-id")) return false;
5067
- const parsed = isParsed(elm);
5068
- if (parsed && !hasPendingAncestor(elm)) return false;
5069
- if (parsed) elm.__attachShadow?.();
5070
- pending.add(elm);
5071
- if (!observer) {
5072
- observer = new MutationObserver(flush);
5073
- observer.observe(win.document, {
5074
- childList: true,
5075
- subtree: true
5076
- });
5077
- win.document.addEventListener("DOMContentLoaded", flush, { once: true });
5078
- }
5136
+ const done = isParsed(elm);
5137
+ if (done && !hasPendingAncestor(elm)) return false;
5138
+ if (done) elm.__attachShadow?.();
5139
+ const observer = new MutationObserver(flush);
5140
+ observer.observe(elm, { childList: true });
5141
+ pending.set(elm, observer);
5142
+ win.document.addEventListener("DOMContentLoaded", flush, { once: true });
5079
5143
  return true;
5080
5144
  };
5081
5145
  //#endregion
@@ -775,19 +775,28 @@ const getSlottedChildNodes = (childNodes) => {
775
775
  * @returns a reference to the slot node that matches the provided name, `null` otherwise
776
776
  */
777
777
  function getHostSlotNodes(childNodes, hostName, slotName) {
778
- let i = 0;
779
- let slottedNodes = [];
780
- let childNode;
781
- for (; i < childNodes.length; i++) {
782
- childNode = childNodes[i];
778
+ const slotNodes = [];
779
+ collectHostSlotNodes(childNodes, hostName, slotName, slotNodes);
780
+ return slotNodes;
781
+ }
782
+ /**
783
+ * Pre-order walk for {@link getHostSlotNodes}, appending to `out`.
784
+ * @param childNodes the nodes to search
785
+ * @param hostName the host name of the slot to match on
786
+ * @param slotName the name of the slot to match on; stops at the first match when given
787
+ * @param out the matching slot nodes, in document order
788
+ * @returns true once a named slot has been found
789
+ */
790
+ function collectHostSlotNodes(childNodes, hostName, slotName, out) {
791
+ for (let i = 0; i < childNodes.length; i++) {
792
+ const childNode = childNodes[i];
783
793
  if (childNode["s-sr"] && (!hostName || childNode["s-hn"] === hostName) && (slotName === void 0 || getSlotName(childNode) === slotName)) {
784
- slottedNodes.push(childNode);
785
- if (typeof slotName !== "undefined") return slottedNodes;
794
+ out.push(childNode);
795
+ if (slotName !== void 0) return true;
786
796
  }
787
- slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
788
- if (typeof slotName !== "undefined" && slottedNodes.length) return slottedNodes;
797
+ if (collectHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName, out) && slotName !== void 0) return true;
789
798
  }
790
- return slottedNodes;
799
+ return false;
791
800
  }
792
801
  /**
793
802
  * Get all 'child' sibling nodes of a slot node
@@ -906,11 +915,40 @@ function findSlotFromSlottedNode(slottedNode, parentHost) {
906
915
  slotName: ""
907
916
  };
908
917
  const slotName = slottedNode["s-sn"] = getSlotName(slottedNode) || "";
918
+ let hostSlots = slotNodeCache.get(parentHost);
919
+ const cached = hostSlots?.get(slotName);
920
+ if (cached && isHostSlot(cached, parentHost, slotName)) return {
921
+ slotNode: cached,
922
+ slotName
923
+ };
924
+ const slotNode = getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0];
925
+ if (slotNode) {
926
+ if (!hostSlots) slotNodeCache.set(parentHost, hostSlots = /* @__PURE__ */ new Map());
927
+ hostSlots.set(slotName, slotNode);
928
+ }
909
929
  return {
910
- slotNode: getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0],
930
+ slotNode,
911
931
  slotName
912
932
  };
913
933
  }
934
+ /**
935
+ * The slot node last found per host and slot name. Each slotted child of a host looks up its
936
+ * slot, and a full search walks the host's whole internal tree, so a host with many slotted
937
+ * children would otherwise cost O(children × tree).
938
+ */
939
+ const slotNodeCache = /* @__PURE__ */ new WeakMap();
940
+ /**
941
+ * Whether a cached slot node is still the host's slot of that name.
942
+ * @param slotNode the cached slot node
943
+ * @param host the host element
944
+ * @param slotName the slot name
945
+ * @returns true if `slotNode` is still a slot of `host` named `slotName`, inside its internal tree
946
+ */
947
+ const isHostSlot = (slotNode, host, slotName) => {
948
+ if (!slotNode["s-sr"] || slotNode["s-hn"] !== host.tagName || getSlotName(slotNode) !== slotName) return false;
949
+ for (let n = internalCall(slotNode, "parentNode"); n; n = internalCall(n, "parentNode")) if (n === host) return true;
950
+ return false;
951
+ };
914
952
  //#endregion
915
953
  //#region src/runtime/dom-extras.ts
916
954
  const applyLightDomPatches = (hostElementPrototype) => {
@@ -2692,8 +2730,7 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2692
2730
  if (parent?.["s-cr"]) checkSlotRelocate = true;
2693
2731
  if (BUILD$1.scoped && typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
2694
2732
  else if (typeof newNode["s-sn"] === "string") {
2695
- const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2696
- 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);
2733
+ if ((BUILD$1.lightDomPatches || BUILD$1.slotChildNodes || BUILD$1.patchAll && hostPatchesAll(newNode, parent)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchSlottedNode(newNode);
2697
2734
  parent.insertBefore(newNode, reference);
2698
2735
  const { slotNode } = findSlotFromSlottedNode(newNode);
2699
2736
  if (slotNode) {
@@ -2707,6 +2744,16 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2707
2744
  else return parent?.insertBefore(newNode, reference);
2708
2745
  };
2709
2746
  /**
2747
+ * Whether the host a slotted node belongs to opted into `patchAll`.
2748
+ * @param newNode the slotted node
2749
+ * @param parent the node it is being inserted into
2750
+ * @returns true if the host component has the `patchAll` flag
2751
+ */
2752
+ const hostPatchesAll = (newNode, parent) => {
2753
+ const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2754
+ return !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll);
2755
+ };
2756
+ /**
2710
2757
  * Adds or removes a scoped class to the parent element of a slotted node.
2711
2758
  * This is used for styling slotted content (e.g. with `::scoped(...) {...}` selectors )
2712
2759
  * in `scoped: true` components.
@@ -4202,7 +4249,7 @@ const insertPolyfillHostInCssText = (cssText) => {
4202
4249
  const _colonHostContextRe = createSupportsRuleRe(":host-context");
4203
4250
  cssText = cssText.replace(_colonHostContextRe, `$1${_polyfillHostContext}`).replace(_colonHostRe, `$1${_polyfillHost}`).replace(_colonSlottedRe, `$1${_polyfillSlotted}`);
4204
4251
  supportsBlocks.forEach((originalSelector, index) => {
4205
- cssText = cssText.replace(`__supports_${index}__`, originalSelector);
4252
+ cssText = cssText.replace(`__supports_${index}__`, () => originalSelector);
4206
4253
  });
4207
4254
  return cssText;
4208
4255
  };
@@ -4435,11 +4482,11 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
4435
4482
  const scoped = scopeCssText(cssText, scopeId, hostScopeId, slotScopeId, commentOriginalSelector);
4436
4483
  cssText = [scoped.cssText, ...commentsWithHash].join("\n");
4437
4484
  if (commentOriginalSelector) orgSelectors.forEach(({ placeholder, comment }) => {
4438
- cssText = cssText.replace(placeholder, comment);
4485
+ cssText = cssText.replace(placeholder, () => comment);
4439
4486
  });
4440
4487
  scoped.slottedSelectors.forEach((slottedSelector) => {
4441
4488
  const regex = new RegExp(escapeRegExpSpecialCharacters(slottedSelector.orgSelector) + "(?=\\s*[,{]|$)", "g");
4442
- cssText = cssText.replace(regex, slottedSelector.updatedSelector);
4489
+ cssText = cssText.replace(regex, () => slottedSelector.updatedSelector);
4443
4490
  });
4444
4491
  cssText = expandPartSelectors(cssText);
4445
4492
  return cssText;
@@ -4684,6 +4731,28 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4684
4731
  };
4685
4732
  //#endregion
4686
4733
  //#region src/runtime/initialize-component.ts
4734
+ /** Distinct style texts kept; an app has one per component and mode. */
4735
+ const SSR_CSS_CACHE_MAX = 1e3;
4736
+ /**
4737
+ * Memoizes a server-side rewrite of a component's style text. The rewrites are pure, but the
4738
+ * platform (and its `styles` registry) is rebuilt per render, so without this they'd rerun on
4739
+ * every render.
4740
+ * @param style the component's style text
4741
+ * @param key what the rewrite depends on besides the text
4742
+ * @param rewrite computes the result
4743
+ * @returns the rewritten style
4744
+ */
4745
+ const ssrCachedCss = (style, key, rewrite) => {
4746
+ if (typeof $stencilSsrCssCache === "undefined" || typeof style !== "string") return rewrite();
4747
+ let byKey = $stencilSsrCssCache.get(style);
4748
+ if (!byKey) {
4749
+ if ($stencilSsrCssCache.size >= SSR_CSS_CACHE_MAX) $stencilSsrCssCache.clear();
4750
+ $stencilSsrCssCache.set(style, byKey = /* @__PURE__ */ new Map());
4751
+ }
4752
+ let result = byKey.get(key);
4753
+ if (result === void 0) byKey.set(key, result = rewrite());
4754
+ return result;
4755
+ };
4687
4756
  /**
4688
4757
  * Initialize a Stencil component given a reference to its host element, its
4689
4758
  * runtime bookkeeping data structure, runtime metadata about the component,
@@ -4784,8 +4853,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4784
4853
  if (!styles.has(scopeId) || BUILD$1.hotModuleReplacement && hmrVersionId) {
4785
4854
  const endRegisterStyles = createTime("registerStyles", cmpMeta.$tagName$);
4786
4855
  if (BUILD$1.hydrateServerSide && BUILD$1.shadowDom) {
4787
- if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = scopeCss(style, scopeId, true);
4788
- else if (needsScopedSSR()) style = expandPartSelectors(style);
4856
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = ssrCachedCss(style, `s:${scopeId}`, () => scopeCss(style, scopeId, true));
4857
+ else if (needsScopedSSR()) style = ssrCachedCss(style, "p", () => expandPartSelectors(style));
4789
4858
  }
4790
4859
  registerStyle(scopeId, style, !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation));
4791
4860
  endRegisterStyles();
@@ -5004,12 +5073,12 @@ const hmrApplyClass = (cmpMeta, NewClass) => {
5004
5073
  /**
5005
5074
  * SSR hosts connected while the HTML parser is still inside them (streamed documents),
5006
5075
  * in connection order - which is document order. Each is held until its subtree is
5007
- * parsed so hydration sees its declarative shadow root and children.
5076
+ * parsed so hydration sees its declarative shadow root and children, and watched for
5077
+ * its end marker arriving (wherever it is - a document observer can't see into shadow roots).
5008
5078
  */
5009
- const pending = /* @__PURE__ */ new Set();
5079
+ const pending = /* @__PURE__ */ new Map();
5010
5080
  /** SSR hosts seen parsed: hydration may since have moved or removed their end marker */
5011
5081
  const parsedHosts = /* @__PURE__ */ new WeakSet();
5012
- let observer;
5013
5082
  const parentOf = (node) => node.parentNode ?? (node.nodeType === NODE_TYPE.DocumentFragment ? node.host : null);
5014
5083
  /**
5015
5084
  * The server writes a `HOST_END_ID` comment as an SSR host's last child, so the parser has
@@ -5029,17 +5098,17 @@ const hasPendingAncestor = (elm) => {
5029
5098
  for (let n = parentOf(elm); n; n = parentOf(n)) if (pending.has(n)) return true;
5030
5099
  return false;
5031
5100
  };
5101
+ const drop = (elm) => {
5102
+ pending.get(elm)?.disconnect();
5103
+ pending.delete(elm);
5104
+ };
5032
5105
  const flush = () => {
5033
- for (const elm of pending) if (!elm.isConnected) pending.delete(elm);
5106
+ for (const elm of pending.keys()) if (!elm.isConnected) drop(elm);
5034
5107
  else if (isParsed(elm)) elm.__attachShadow?.();
5035
- for (const elm of pending) if (isParsed(elm) && !hasPendingAncestor(elm)) {
5036
- pending.delete(elm);
5108
+ for (const elm of pending.keys()) if (isParsed(elm) && !hasPendingAncestor(elm)) {
5109
+ drop(elm);
5037
5110
  elm.connectedCallback?.();
5038
5111
  }
5039
- if (!pending.size) {
5040
- observer?.disconnect();
5041
- observer = void 0;
5042
- }
5043
5112
  };
5044
5113
  /**
5045
5114
  * Whether the parser may still be adding children (including a declarative shadow root)
@@ -5058,18 +5127,13 @@ const mayStillBeParsing = (elm) => win.document?.readyState === "loading" && (!e
5058
5127
  const deferUntilParsed = (elm) => {
5059
5128
  if (pending.has(elm)) return true;
5060
5129
  if (!win.document || !elm.hasAttribute("s-id")) return false;
5061
- const parsed = isParsed(elm);
5062
- if (parsed && !hasPendingAncestor(elm)) return false;
5063
- if (parsed) elm.__attachShadow?.();
5064
- pending.add(elm);
5065
- if (!observer) {
5066
- observer = new MutationObserver(flush);
5067
- observer.observe(win.document, {
5068
- childList: true,
5069
- subtree: true
5070
- });
5071
- win.document.addEventListener("DOMContentLoaded", flush, { once: true });
5072
- }
5130
+ const done = isParsed(elm);
5131
+ if (done && !hasPendingAncestor(elm)) return false;
5132
+ if (done) elm.__attachShadow?.();
5133
+ const observer = new MutationObserver(flush);
5134
+ observer.observe(elm, { childList: true });
5135
+ pending.set(elm, observer);
5136
+ win.document.addEventListener("DOMContentLoaded", flush, { once: true });
5073
5137
  return true;
5074
5138
  };
5075
5139
  //#endregion
@@ -1,4 +1,4 @@
1
- import { C as ReactiveControllerHostInterface, E as VNode, S as MixedInCtor, T as TagTransformer, _ as ComponentInterface, a as ComponentConstructor, b as HTMLStencilElement, c as ComponentRuntimeMeta, d as HostRef, f as LazyBundlesRuntimeData, g as RuntimeRef, h as RenderNode, i as ChildType, l as ComponentRuntimeMetaCompact, m as PropsType, o as ComponentConstructorChangeHandlers, p as PlatformRuntime, s as ComponentRuntimeHostListener, u as HostElement, v as CustomElementsDefineOptions, w as ResolutionHandler, x as JSXBase, y as FunctionalComponent } from "../index-CWPcrnEJ.js";
1
+ import { C as ReactiveControllerHostInterface, E as VNode, S as MixedInCtor, T as TagTransformer, _ as ComponentInterface, a as ComponentConstructor, b as HTMLStencilElement, c as ComponentRuntimeMeta, d as HostRef, f as LazyBundlesRuntimeData, g as RuntimeRef, h as RenderNode, i as ChildType, l as ComponentRuntimeMetaCompact, m as PropsType, o as ComponentConstructorChangeHandlers, p as PlatformRuntime, s as ComponentRuntimeHostListener, u as HostElement, v as CustomElementsDefineOptions, w as ResolutionHandler, x as JSXBase, y as FunctionalComponent } from "../index-DaYfl65k.js";
2
2
  //#region src/runtime/asset-path.d.ts
3
3
  declare const getAssetPath: (path: string) => string;
4
4
  declare const setAssetPath: (path: string) => string;