@stencil/core 5.0.0-rc.15 → 5.0.0-rc.17

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.
@@ -3933,6 +3980,11 @@ const initializeDocumentHydrate = (node, orgLocNodes) => {
3933
3980
  const createSimpleVNode = (vnode) => ({
3934
3981
  $flags$: 0,
3935
3982
  $index$: "0",
3983
+ $tag$: null,
3984
+ $text$: null,
3985
+ $key$: null,
3986
+ $name$: null,
3987
+ $attrs$: null,
3936
3988
  $children$: null,
3937
3989
  ...vnode
3938
3990
  });
@@ -4208,7 +4260,7 @@ const insertPolyfillHostInCssText = (cssText) => {
4208
4260
  const _colonHostContextRe = createSupportsRuleRe(":host-context");
4209
4261
  cssText = cssText.replace(_colonHostContextRe, `$1${_polyfillHostContext}`).replace(_colonHostRe, `$1${_polyfillHost}`).replace(_colonSlottedRe, `$1${_polyfillSlotted}`);
4210
4262
  supportsBlocks.forEach((originalSelector, index) => {
4211
- cssText = cssText.replace(`__supports_${index}__`, originalSelector);
4263
+ cssText = cssText.replace(`__supports_${index}__`, () => originalSelector);
4212
4264
  });
4213
4265
  return cssText;
4214
4266
  };
@@ -4441,11 +4493,11 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
4441
4493
  const scoped = scopeCssText(cssText, scopeId, hostScopeId, slotScopeId, commentOriginalSelector);
4442
4494
  cssText = [scoped.cssText, ...commentsWithHash].join("\n");
4443
4495
  if (commentOriginalSelector) orgSelectors.forEach(({ placeholder, comment }) => {
4444
- cssText = cssText.replace(placeholder, comment);
4496
+ cssText = cssText.replace(placeholder, () => comment);
4445
4497
  });
4446
4498
  scoped.slottedSelectors.forEach((slottedSelector) => {
4447
4499
  const regex = new RegExp(escapeRegExpSpecialCharacters(slottedSelector.orgSelector) + "(?=\\s*[,{]|$)", "g");
4448
- cssText = cssText.replace(regex, slottedSelector.updatedSelector);
4500
+ cssText = cssText.replace(regex, () => slottedSelector.updatedSelector);
4449
4501
  });
4450
4502
  cssText = expandPartSelectors(cssText);
4451
4503
  return cssText;
@@ -4690,6 +4742,28 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4690
4742
  };
4691
4743
  //#endregion
4692
4744
  //#region src/runtime/initialize-component.ts
4745
+ /** Distinct style texts kept; an app has one per component and mode. */
4746
+ const SSR_CSS_CACHE_MAX = 1e3;
4747
+ /**
4748
+ * Memoizes a server-side rewrite of a component's style text. The rewrites are pure, but the
4749
+ * platform (and its `styles` registry) is rebuilt per render, so without this they'd rerun on
4750
+ * every render.
4751
+ * @param style the component's style text
4752
+ * @param key what the rewrite depends on besides the text
4753
+ * @param rewrite computes the result
4754
+ * @returns the rewritten style
4755
+ */
4756
+ const ssrCachedCss = (style, key, rewrite) => {
4757
+ if (typeof $stencilSsrCssCache === "undefined" || typeof style !== "string") return rewrite();
4758
+ let byKey = $stencilSsrCssCache.get(style);
4759
+ if (!byKey) {
4760
+ if ($stencilSsrCssCache.size >= SSR_CSS_CACHE_MAX) $stencilSsrCssCache.clear();
4761
+ $stencilSsrCssCache.set(style, byKey = /* @__PURE__ */ new Map());
4762
+ }
4763
+ let result = byKey.get(key);
4764
+ if (result === void 0) byKey.set(key, result = rewrite());
4765
+ return result;
4766
+ };
4693
4767
  /**
4694
4768
  * Initialize a Stencil component given a reference to its host element, its
4695
4769
  * runtime bookkeeping data structure, runtime metadata about the component,
@@ -4790,8 +4864,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4790
4864
  if (!styles.has(scopeId) || BUILD.hotModuleReplacement && hmrVersionId) {
4791
4865
  const endRegisterStyles = createTime("registerStyles", cmpMeta.$tagName$);
4792
4866
  if (BUILD.hydrateServerSide && BUILD.shadowDom) {
4793
- if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = scopeCss(style, scopeId, true);
4794
- else if (needsScopedSSR()) style = expandPartSelectors(style);
4867
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = ssrCachedCss(style, `s:${scopeId}`, () => scopeCss(style, scopeId, true));
4868
+ else if (needsScopedSSR()) style = ssrCachedCss(style, "p", () => expandPartSelectors(style));
4795
4869
  }
4796
4870
  registerStyle(scopeId, style, !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation));
4797
4871
  endRegisterStyles();
@@ -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.
@@ -3927,6 +3974,11 @@ const initializeDocumentHydrate = (node, orgLocNodes) => {
3927
3974
  const createSimpleVNode = (vnode) => ({
3928
3975
  $flags$: 0,
3929
3976
  $index$: "0",
3977
+ $tag$: null,
3978
+ $text$: null,
3979
+ $key$: null,
3980
+ $name$: null,
3981
+ $attrs$: null,
3930
3982
  $children$: null,
3931
3983
  ...vnode
3932
3984
  });
@@ -4202,7 +4254,7 @@ const insertPolyfillHostInCssText = (cssText) => {
4202
4254
  const _colonHostContextRe = createSupportsRuleRe(":host-context");
4203
4255
  cssText = cssText.replace(_colonHostContextRe, `$1${_polyfillHostContext}`).replace(_colonHostRe, `$1${_polyfillHost}`).replace(_colonSlottedRe, `$1${_polyfillSlotted}`);
4204
4256
  supportsBlocks.forEach((originalSelector, index) => {
4205
- cssText = cssText.replace(`__supports_${index}__`, originalSelector);
4257
+ cssText = cssText.replace(`__supports_${index}__`, () => originalSelector);
4206
4258
  });
4207
4259
  return cssText;
4208
4260
  };
@@ -4435,11 +4487,11 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
4435
4487
  const scoped = scopeCssText(cssText, scopeId, hostScopeId, slotScopeId, commentOriginalSelector);
4436
4488
  cssText = [scoped.cssText, ...commentsWithHash].join("\n");
4437
4489
  if (commentOriginalSelector) orgSelectors.forEach(({ placeholder, comment }) => {
4438
- cssText = cssText.replace(placeholder, comment);
4490
+ cssText = cssText.replace(placeholder, () => comment);
4439
4491
  });
4440
4492
  scoped.slottedSelectors.forEach((slottedSelector) => {
4441
4493
  const regex = new RegExp(escapeRegExpSpecialCharacters(slottedSelector.orgSelector) + "(?=\\s*[,{]|$)", "g");
4442
- cssText = cssText.replace(regex, slottedSelector.updatedSelector);
4494
+ cssText = cssText.replace(regex, () => slottedSelector.updatedSelector);
4443
4495
  });
4444
4496
  cssText = expandPartSelectors(cssText);
4445
4497
  return cssText;
@@ -4684,6 +4736,28 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4684
4736
  };
4685
4737
  //#endregion
4686
4738
  //#region src/runtime/initialize-component.ts
4739
+ /** Distinct style texts kept; an app has one per component and mode. */
4740
+ const SSR_CSS_CACHE_MAX = 1e3;
4741
+ /**
4742
+ * Memoizes a server-side rewrite of a component's style text. The rewrites are pure, but the
4743
+ * platform (and its `styles` registry) is rebuilt per render, so without this they'd rerun on
4744
+ * every render.
4745
+ * @param style the component's style text
4746
+ * @param key what the rewrite depends on besides the text
4747
+ * @param rewrite computes the result
4748
+ * @returns the rewritten style
4749
+ */
4750
+ const ssrCachedCss = (style, key, rewrite) => {
4751
+ if (typeof $stencilSsrCssCache === "undefined" || typeof style !== "string") return rewrite();
4752
+ let byKey = $stencilSsrCssCache.get(style);
4753
+ if (!byKey) {
4754
+ if ($stencilSsrCssCache.size >= SSR_CSS_CACHE_MAX) $stencilSsrCssCache.clear();
4755
+ $stencilSsrCssCache.set(style, byKey = /* @__PURE__ */ new Map());
4756
+ }
4757
+ let result = byKey.get(key);
4758
+ if (result === void 0) byKey.set(key, result = rewrite());
4759
+ return result;
4760
+ };
4687
4761
  /**
4688
4762
  * Initialize a Stencil component given a reference to its host element, its
4689
4763
  * runtime bookkeeping data structure, runtime metadata about the component,
@@ -4784,8 +4858,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4784
4858
  if (!styles.has(scopeId) || BUILD$1.hotModuleReplacement && hmrVersionId) {
4785
4859
  const endRegisterStyles = createTime("registerStyles", cmpMeta.$tagName$);
4786
4860
  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);
4861
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = ssrCachedCss(style, `s:${scopeId}`, () => scopeCss(style, scopeId, true));
4862
+ else if (needsScopedSSR()) style = ssrCachedCss(style, "p", () => expandPartSelectors(style));
4789
4863
  }
4790
4864
  registerStyle(scopeId, style, !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation));
4791
4865
  endRegisterStyles();
@@ -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;
@@ -647,19 +647,28 @@ const getSlottedChildNodes = (childNodes) => {
647
647
  * @returns a reference to the slot node that matches the provided name, `null` otherwise
648
648
  */
649
649
  function getHostSlotNodes(childNodes, hostName, slotName) {
650
- let i = 0;
651
- let slottedNodes = [];
652
- let childNode;
653
- for (; i < childNodes.length; i++) {
654
- childNode = childNodes[i];
650
+ const slotNodes = [];
651
+ collectHostSlotNodes(childNodes, hostName, slotName, slotNodes);
652
+ return slotNodes;
653
+ }
654
+ /**
655
+ * Pre-order walk for {@link getHostSlotNodes}, appending to `out`.
656
+ * @param childNodes the nodes to search
657
+ * @param hostName the host name of the slot to match on
658
+ * @param slotName the name of the slot to match on; stops at the first match when given
659
+ * @param out the matching slot nodes, in document order
660
+ * @returns true once a named slot has been found
661
+ */
662
+ function collectHostSlotNodes(childNodes, hostName, slotName, out) {
663
+ for (let i = 0; i < childNodes.length; i++) {
664
+ const childNode = childNodes[i];
655
665
  if (childNode["s-sr"] && (!hostName || childNode["s-hn"] === hostName) && (slotName === void 0 || getSlotName(childNode) === slotName)) {
656
- slottedNodes.push(childNode);
657
- if (typeof slotName !== "undefined") return slottedNodes;
666
+ out.push(childNode);
667
+ if (slotName !== void 0) return true;
658
668
  }
659
- slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
660
- if (typeof slotName !== "undefined" && slottedNodes.length) return slottedNodes;
669
+ if (collectHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName, out) && slotName !== void 0) return true;
661
670
  }
662
- return slottedNodes;
671
+ return false;
663
672
  }
664
673
  /**
665
674
  * Get all 'child' sibling nodes of a slot node
@@ -778,11 +787,40 @@ function findSlotFromSlottedNode(slottedNode, parentHost) {
778
787
  slotName: ""
779
788
  };
780
789
  const slotName = slottedNode["s-sn"] = getSlotName(slottedNode) || "";
790
+ let hostSlots = slotNodeCache.get(parentHost);
791
+ const cached = hostSlots?.get(slotName);
792
+ if (cached && isHostSlot(cached, parentHost, slotName)) return {
793
+ slotNode: cached,
794
+ slotName
795
+ };
796
+ const slotNode = getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0];
797
+ if (slotNode) {
798
+ if (!hostSlots) slotNodeCache.set(parentHost, hostSlots = /* @__PURE__ */ new Map());
799
+ hostSlots.set(slotName, slotNode);
800
+ }
781
801
  return {
782
- slotNode: getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0],
802
+ slotNode,
783
803
  slotName
784
804
  };
785
805
  }
806
+ /**
807
+ * The slot node last found per host and slot name. Each slotted child of a host looks up its
808
+ * slot, and a full search walks the host's whole internal tree, so a host with many slotted
809
+ * children would otherwise cost O(children × tree).
810
+ */
811
+ const slotNodeCache = /* @__PURE__ */ new WeakMap();
812
+ /**
813
+ * Whether a cached slot node is still the host's slot of that name.
814
+ * @param slotNode the cached slot node
815
+ * @param host the host element
816
+ * @param slotName the slot name
817
+ * @returns true if `slotNode` is still a slot of `host` named `slotName`, inside its internal tree
818
+ */
819
+ const isHostSlot = (slotNode, host, slotName) => {
820
+ if (!slotNode["s-sr"] || slotNode["s-hn"] !== host.tagName || getSlotName(slotNode) !== slotName) return false;
821
+ for (let n = internalCall(slotNode, "parentNode"); n; n = internalCall(n, "parentNode")) if (n === host) return true;
822
+ return false;
823
+ };
786
824
  //#endregion
787
825
  //#region src/runtime/dom-extras.ts
788
826
  const applyLightDomPatches = (hostElementPrototype) => {
@@ -2564,8 +2602,7 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2564
2602
  if (parent?.["s-cr"]) checkSlotRelocate = true;
2565
2603
  if (BUILD.scoped && typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
2566
2604
  else if (typeof newNode["s-sn"] === "string") {
2567
- const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2568
- 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);
2605
+ if ((BUILD.lightDomPatches || BUILD.slotChildNodes || BUILD.patchAll && hostPatchesAll(newNode, parent)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchSlottedNode(newNode);
2569
2606
  parent.insertBefore(newNode, reference);
2570
2607
  const { slotNode } = findSlotFromSlottedNode(newNode);
2571
2608
  if (slotNode) {
@@ -2579,6 +2616,16 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2579
2616
  else return parent?.insertBefore(newNode, reference);
2580
2617
  };
2581
2618
  /**
2619
+ * Whether the host a slotted node belongs to opted into `patchAll`.
2620
+ * @param newNode the slotted node
2621
+ * @param parent the node it is being inserted into
2622
+ * @returns true if the host component has the `patchAll` flag
2623
+ */
2624
+ const hostPatchesAll = (newNode, parent) => {
2625
+ const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2626
+ return !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll);
2627
+ };
2628
+ /**
2582
2629
  * Adds or removes a scoped class to the parent element of a slotted node.
2583
2630
  * This is used for styling slotted content (e.g. with `::scoped(...) {...}` selectors )
2584
2631
  * in `scoped: true` components.
@@ -3799,6 +3846,11 @@ const initializeDocumentHydrate = (node, orgLocNodes) => {
3799
3846
  const createSimpleVNode = (vnode) => ({
3800
3847
  $flags$: 0,
3801
3848
  $index$: "0",
3849
+ $tag$: null,
3850
+ $text$: null,
3851
+ $key$: null,
3852
+ $name$: null,
3853
+ $attrs$: null,
3802
3854
  $children$: null,
3803
3855
  ...vnode
3804
3856
  });
@@ -4074,7 +4126,7 @@ const insertPolyfillHostInCssText = (cssText) => {
4074
4126
  const _colonHostContextRe = createSupportsRuleRe(":host-context");
4075
4127
  cssText = cssText.replace(_colonHostContextRe, `$1${_polyfillHostContext}`).replace(_colonHostRe, `$1${_polyfillHost}`).replace(_colonSlottedRe, `$1${_polyfillSlotted}`);
4076
4128
  supportsBlocks.forEach((originalSelector, index) => {
4077
- cssText = cssText.replace(`__supports_${index}__`, originalSelector);
4129
+ cssText = cssText.replace(`__supports_${index}__`, () => originalSelector);
4078
4130
  });
4079
4131
  return cssText;
4080
4132
  };
@@ -4307,11 +4359,11 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
4307
4359
  const scoped = scopeCssText(cssText, scopeId, hostScopeId, slotScopeId, commentOriginalSelector);
4308
4360
  cssText = [scoped.cssText, ...commentsWithHash].join("\n");
4309
4361
  if (commentOriginalSelector) orgSelectors.forEach(({ placeholder, comment }) => {
4310
- cssText = cssText.replace(placeholder, comment);
4362
+ cssText = cssText.replace(placeholder, () => comment);
4311
4363
  });
4312
4364
  scoped.slottedSelectors.forEach((slottedSelector) => {
4313
4365
  const regex = new RegExp(escapeRegExpSpecialCharacters(slottedSelector.orgSelector) + "(?=\\s*[,{]|$)", "g");
4314
- cssText = cssText.replace(regex, slottedSelector.updatedSelector);
4366
+ cssText = cssText.replace(regex, () => slottedSelector.updatedSelector);
4315
4367
  });
4316
4368
  cssText = expandPartSelectors(cssText);
4317
4369
  return cssText;
@@ -4556,6 +4608,28 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4556
4608
  };
4557
4609
  //#endregion
4558
4610
  //#region src/runtime/initialize-component.ts
4611
+ /** Distinct style texts kept; an app has one per component and mode. */
4612
+ const SSR_CSS_CACHE_MAX = 1e3;
4613
+ /**
4614
+ * Memoizes a server-side rewrite of a component's style text. The rewrites are pure, but the
4615
+ * platform (and its `styles` registry) is rebuilt per render, so without this they'd rerun on
4616
+ * every render.
4617
+ * @param style the component's style text
4618
+ * @param key what the rewrite depends on besides the text
4619
+ * @param rewrite computes the result
4620
+ * @returns the rewritten style
4621
+ */
4622
+ const ssrCachedCss = (style, key, rewrite) => {
4623
+ if (typeof $stencilSsrCssCache === "undefined" || typeof style !== "string") return rewrite();
4624
+ let byKey = $stencilSsrCssCache.get(style);
4625
+ if (!byKey) {
4626
+ if ($stencilSsrCssCache.size >= SSR_CSS_CACHE_MAX) $stencilSsrCssCache.clear();
4627
+ $stencilSsrCssCache.set(style, byKey = /* @__PURE__ */ new Map());
4628
+ }
4629
+ let result = byKey.get(key);
4630
+ if (result === void 0) byKey.set(key, result = rewrite());
4631
+ return result;
4632
+ };
4559
4633
  /**
4560
4634
  * Initialize a Stencil component given a reference to its host element, its
4561
4635
  * runtime bookkeeping data structure, runtime metadata about the component,
@@ -4656,8 +4730,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4656
4730
  if (!styles.has(scopeId) || BUILD.hotModuleReplacement && hmrVersionId) {
4657
4731
  const endRegisterStyles = createTime("registerStyles", cmpMeta.$tagName$);
4658
4732
  if (BUILD.hydrateServerSide && BUILD.shadowDom) {
4659
- if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = scopeCss(style, scopeId, true);
4660
- else if (needsScopedSSR()) style = expandPartSelectors(style);
4733
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = ssrCachedCss(style, `s:${scopeId}`, () => scopeCss(style, scopeId, true));
4734
+ else if (needsScopedSSR()) style = ssrCachedCss(style, "p", () => expandPartSelectors(style));
4661
4735
  }
4662
4736
  registerStyle(scopeId, style, !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation));
4663
4737
  endRegisterStyles();