@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.
@@ -444,19 +444,28 @@ const getSlottedChildNodes = (childNodes) => {
444
444
  * @returns a reference to the slot node that matches the provided name, `null` otherwise
445
445
  */
446
446
  function getHostSlotNodes(childNodes, hostName, slotName) {
447
- let i = 0;
448
- let slottedNodes = [];
449
- let childNode;
450
- for (; i < childNodes.length; i++) {
451
- childNode = childNodes[i];
447
+ const slotNodes = [];
448
+ collectHostSlotNodes(childNodes, hostName, slotName, slotNodes);
449
+ return slotNodes;
450
+ }
451
+ /**
452
+ * Pre-order walk for {@link getHostSlotNodes}, appending to `out`.
453
+ * @param childNodes the nodes to search
454
+ * @param hostName the host name of the slot to match on
455
+ * @param slotName the name of the slot to match on; stops at the first match when given
456
+ * @param out the matching slot nodes, in document order
457
+ * @returns true once a named slot has been found
458
+ */
459
+ function collectHostSlotNodes(childNodes, hostName, slotName, out) {
460
+ for (let i = 0; i < childNodes.length; i++) {
461
+ const childNode = childNodes[i];
452
462
  if (childNode["s-sr"] && (!hostName || childNode["s-hn"] === hostName) && (slotName === void 0 || getSlotName(childNode) === slotName)) {
453
- slottedNodes.push(childNode);
454
- if (typeof slotName !== "undefined") return slottedNodes;
463
+ out.push(childNode);
464
+ if (slotName !== void 0) return true;
455
465
  }
456
- slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
457
- if (typeof slotName !== "undefined" && slottedNodes.length) return slottedNodes;
466
+ if (collectHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName, out) && slotName !== void 0) return true;
458
467
  }
459
- return slottedNodes;
468
+ return false;
460
469
  }
461
470
  /**
462
471
  * Get all 'child' sibling nodes of a slot node
@@ -575,11 +584,40 @@ function findSlotFromSlottedNode(slottedNode, parentHost) {
575
584
  slotName: ""
576
585
  };
577
586
  const slotName = slottedNode["s-sn"] = getSlotName(slottedNode) || "";
587
+ let hostSlots = slotNodeCache.get(parentHost);
588
+ const cached = hostSlots?.get(slotName);
589
+ if (cached && isHostSlot(cached, parentHost, slotName)) return {
590
+ slotNode: cached,
591
+ slotName
592
+ };
593
+ const slotNode = getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0];
594
+ if (slotNode) {
595
+ if (!hostSlots) slotNodeCache.set(parentHost, hostSlots = /* @__PURE__ */ new Map());
596
+ hostSlots.set(slotName, slotNode);
597
+ }
578
598
  return {
579
- slotNode: getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0],
599
+ slotNode,
580
600
  slotName
581
601
  };
582
602
  }
603
+ /**
604
+ * The slot node last found per host and slot name. Each slotted child of a host looks up its
605
+ * slot, and a full search walks the host's whole internal tree, so a host with many slotted
606
+ * children would otherwise cost O(children × tree).
607
+ */
608
+ const slotNodeCache = /* @__PURE__ */ new WeakMap();
609
+ /**
610
+ * Whether a cached slot node is still the host's slot of that name.
611
+ * @param slotNode the cached slot node
612
+ * @param host the host element
613
+ * @param slotName the slot name
614
+ * @returns true if `slotNode` is still a slot of `host` named `slotName`, inside its internal tree
615
+ */
616
+ const isHostSlot = (slotNode, host, slotName) => {
617
+ if (!slotNode["s-sr"] || slotNode["s-hn"] !== host.tagName || getSlotName(slotNode) !== slotName) return false;
618
+ for (let n = internalCall(slotNode, "parentNode"); n; n = internalCall(n, "parentNode")) if (n === host) return true;
619
+ return false;
620
+ };
583
621
  //#endregion
584
622
  //#region src/runtime/dom-extras.ts
585
623
  const applyLightDomPatches = (hostElementPrototype) => {
@@ -2336,8 +2374,7 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2336
2374
  if (parent?.["s-cr"]) checkSlotRelocate = true;
2337
2375
  if (BUILD$1.scoped && typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
2338
2376
  else if (typeof newNode["s-sn"] === "string") {
2339
- const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2340
- 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);
2377
+ if ((BUILD$1.lightDomPatches || BUILD$1.slotChildNodes || BUILD$1.patchAll && hostPatchesAll(newNode, parent)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchSlottedNode(newNode);
2341
2378
  parent.insertBefore(newNode, reference);
2342
2379
  const { slotNode } = findSlotFromSlottedNode(newNode);
2343
2380
  if (slotNode) {
@@ -2351,6 +2388,16 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
2351
2388
  else return parent?.insertBefore(newNode, reference);
2352
2389
  };
2353
2390
  /**
2391
+ * Whether the host a slotted node belongs to opted into `patchAll`.
2392
+ * @param newNode the slotted node
2393
+ * @param parent the node it is being inserted into
2394
+ * @returns true if the host component has the `patchAll` flag
2395
+ */
2396
+ const hostPatchesAll = (newNode, parent) => {
2397
+ const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
2398
+ return !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll);
2399
+ };
2400
+ /**
2354
2401
  * Adds or removes a scoped class to the parent element of a slotted node.
2355
2402
  * This is used for styling slotted content (e.g. with `::scoped(...) {...}` selectors )
2356
2403
  * in `scoped: true` components.
@@ -3569,6 +3616,11 @@ const initializeDocumentHydrate = (node, orgLocNodes) => {
3569
3616
  const createSimpleVNode = (vnode) => ({
3570
3617
  $flags$: 0,
3571
3618
  $index$: "0",
3619
+ $tag$: null,
3620
+ $text$: null,
3621
+ $key$: null,
3622
+ $name$: null,
3623
+ $attrs$: null,
3572
3624
  $children$: null,
3573
3625
  ...vnode
3574
3626
  });
@@ -3844,7 +3896,7 @@ const insertPolyfillHostInCssText = (cssText) => {
3844
3896
  const _colonHostContextRe = createSupportsRuleRe(":host-context");
3845
3897
  cssText = cssText.replace(_colonHostContextRe, `$1${_polyfillHostContext}`).replace(_colonHostRe, `$1${_polyfillHost}`).replace(_colonSlottedRe, `$1${_polyfillSlotted}`);
3846
3898
  supportsBlocks.forEach((originalSelector, index) => {
3847
- cssText = cssText.replace(`__supports_${index}__`, originalSelector);
3899
+ cssText = cssText.replace(`__supports_${index}__`, () => originalSelector);
3848
3900
  });
3849
3901
  return cssText;
3850
3902
  };
@@ -4077,11 +4129,11 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
4077
4129
  const scoped = scopeCssText(cssText, scopeId, hostScopeId, slotScopeId, commentOriginalSelector);
4078
4130
  cssText = [scoped.cssText, ...commentsWithHash].join("\n");
4079
4131
  if (commentOriginalSelector) orgSelectors.forEach(({ placeholder, comment }) => {
4080
- cssText = cssText.replace(placeholder, comment);
4132
+ cssText = cssText.replace(placeholder, () => comment);
4081
4133
  });
4082
4134
  scoped.slottedSelectors.forEach((slottedSelector) => {
4083
4135
  const regex = new RegExp(escapeRegExpSpecialCharacters(slottedSelector.orgSelector) + "(?=\\s*[,{]|$)", "g");
4084
- cssText = cssText.replace(regex, slottedSelector.updatedSelector);
4136
+ cssText = cssText.replace(regex, () => slottedSelector.updatedSelector);
4085
4137
  });
4086
4138
  cssText = expandPartSelectors(cssText);
4087
4139
  return cssText;
@@ -4326,6 +4378,28 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
4326
4378
  };
4327
4379
  //#endregion
4328
4380
  //#region src/runtime/initialize-component.ts
4381
+ /** Distinct style texts kept; an app has one per component and mode. */
4382
+ const SSR_CSS_CACHE_MAX = 1e3;
4383
+ /**
4384
+ * Memoizes a server-side rewrite of a component's style text. The rewrites are pure, but the
4385
+ * platform (and its `styles` registry) is rebuilt per render, so without this they'd rerun on
4386
+ * every render.
4387
+ * @param style the component's style text
4388
+ * @param key what the rewrite depends on besides the text
4389
+ * @param rewrite computes the result
4390
+ * @returns the rewritten style
4391
+ */
4392
+ const ssrCachedCss = (style, key, rewrite) => {
4393
+ if (typeof $stencilSsrCssCache === "undefined" || typeof style !== "string") return rewrite();
4394
+ let byKey = $stencilSsrCssCache.get(style);
4395
+ if (!byKey) {
4396
+ if ($stencilSsrCssCache.size >= SSR_CSS_CACHE_MAX) $stencilSsrCssCache.clear();
4397
+ $stencilSsrCssCache.set(style, byKey = /* @__PURE__ */ new Map());
4398
+ }
4399
+ let result = byKey.get(key);
4400
+ if (result === void 0) byKey.set(key, result = rewrite());
4401
+ return result;
4402
+ };
4329
4403
  /**
4330
4404
  * Initialize a Stencil component given a reference to its host element, its
4331
4405
  * runtime bookkeeping data structure, runtime metadata about the component,
@@ -4426,8 +4500,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4426
4500
  if (!styles.has(scopeId) || BUILD$1.hotModuleReplacement && hmrVersionId) {
4427
4501
  const endRegisterStyles = createTime("registerStyles", cmpMeta.$tagName$);
4428
4502
  if (BUILD$1.hydrateServerSide && BUILD$1.shadowDom) {
4429
- if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = scopeCss(style, scopeId, true);
4430
- else if (needsScopedSSR()) style = expandPartSelectors(style);
4503
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = ssrCachedCss(style, `s:${scopeId}`, () => scopeCss(style, scopeId, true));
4504
+ else if (needsScopedSSR()) style = ssrCachedCss(style, "p", () => expandPartSelectors(style));
4431
4505
  }
4432
4506
  registerStyle(scopeId, style, !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation));
4433
4507
  endRegisterStyles();
@@ -6788,8 +6788,9 @@ function getPrefixForNamespace(namespaceURI) {
6788
6788
  return null;
6789
6789
  }
6790
6790
  const attrHandler = { get(obj, prop) {
6791
- if (prop in obj) return obj[prop];
6792
- if (typeof prop !== "symbol" && !isNaN(prop)) return obj.__items[prop];
6791
+ const value = obj[prop];
6792
+ if (value !== void 0 || typeof prop === "symbol") return value;
6793
+ if (!isNaN(prop)) return obj.__items[prop];
6793
6794
  } };
6794
6795
  const createAttributeProxy = (caseInsensitive) => new Proxy(new MockAttributeMap(caseInsensitive), attrHandler);
6795
6796
  var MockAttributeMap = class {
@@ -6810,9 +6811,12 @@ var MockAttributeMap = class {
6810
6811
  }
6811
6812
  setNamedItemNS(attr) {
6812
6813
  if (attr != null && attr.value != null) attr.value = String(attr.value);
6813
- const existingAttr = this.__items.find((a) => a.localName === attr.localName && a.namespaceURI === attr.namespaceURI);
6814
- if (existingAttr != null) existingAttr.value = attr.value;
6815
- else this.__items.push(attr);
6814
+ const items = this.__items;
6815
+ for (let i = 0; i < items.length; i++) if (items[i].localName === attr.localName && items[i].namespaceURI === attr.namespaceURI) {
6816
+ items[i].value = attr.value;
6817
+ return;
6818
+ }
6819
+ items.push(attr);
6816
6820
  }
6817
6821
  getNamedItem(attrName) {
6818
6822
  if (this.caseInsensitive) attrName = attrName.toLowerCase();
@@ -6820,14 +6824,20 @@ var MockAttributeMap = class {
6820
6824
  }
6821
6825
  getNamedItemNS(namespaceURI, attrName) {
6822
6826
  namespaceURI = getNamespaceURI(namespaceURI);
6823
- return this.__items.find((attr) => attr.localName === attrName && getNamespaceURI(attr.namespaceURI) === namespaceURI) || null;
6827
+ const items = this.__items;
6828
+ for (let i = 0; i < items.length; i++) {
6829
+ const attr = items[i];
6830
+ if (attr.localName === attrName && getNamespaceURI(attr.namespaceURI) === namespaceURI) return attr;
6831
+ }
6832
+ return null;
6824
6833
  }
6825
6834
  removeNamedItem(attr) {
6826
6835
  this.removeNamedItemNS(attr);
6827
6836
  }
6828
6837
  removeNamedItemNS(attr) {
6829
- for (let i = 0, ii = this.__items.length; i < ii; i++) if (this.__items[i].localName === attr.localName && this.__items[i].namespaceURI === attr.namespaceURI) {
6830
- this.__items.splice(i, 1);
6838
+ const items = this.__items;
6839
+ for (let i = 0, ii = items.length; i < ii; i++) if (items[i].localName === attr.localName && items[i].namespaceURI === attr.namespaceURI) {
6840
+ items.splice(i, 1);
6831
6841
  break;
6832
6842
  }
6833
6843
  }
@@ -7640,8 +7650,7 @@ function normalizeSerializationOptions(opts = {}) {
7640
7650
  * Serialize a node (either a DOM node or a mock-doc node) to an HTML string.
7641
7651
  * This operation is similar to `outerHTML` but allows for more control over the
7642
7652
  * serialization process. It is fully synchronous meaning that it will not
7643
- * wait for a component to be fully rendered before serializing it. Use `streamToHtml`
7644
- * for a streaming version of this function.
7653
+ * wait for a component to be fully rendered before serializing it.
7645
7654
  *
7646
7655
  * @param elm the node to serialize
7647
7656
  * @param serializationOptions options to control serialization behavior
@@ -7655,27 +7664,21 @@ function serializeNodeToHtml(elm, serializationOptions = {}) {
7655
7664
  isWithinBody: false,
7656
7665
  text: []
7657
7666
  };
7658
- let renderedNode = "";
7667
+ const out = { html: "" };
7659
7668
  const children = !opts.fullDocument && elm.body ? Array.from(elm.body.childNodes) : opts.outerHtml ? [elm] : Array.from(getChildNodes(elm));
7660
- for (let i = 0, ii = children.length; i < ii; i++) {
7661
- const child = children[i];
7662
- const chunks = Array.from(streamToHtml(child, opts, output));
7663
- renderedNode += chunks.join("");
7664
- }
7665
- return renderedNode.trim();
7669
+ for (let i = 0, ii = children.length; i < ii; i++) serializeToBuffer(children[i], opts, output, out);
7670
+ return out.html.trim();
7666
7671
  }
7667
7672
  const shadowRootTag = "mock:shadow-root";
7668
7673
  /**
7669
- * Same as `serializeNodeToHtml` but returns a generator that yields the serialized
7670
- * HTML in chunks. This is useful for streaming the serialized HTML to the client
7671
- * as it is being generated.
7674
+ * Serializes a node and its subtree, appending to `out`.
7672
7675
  *
7673
7676
  * @param node the node to serialize
7674
7677
  * @param opts options to control serialization behavior
7675
7678
  * @param output keeps track of the current line width and indentation
7676
- * @yields the serialized HTML in chunks
7679
+ * @param out the buffer the HTML is appended to
7677
7680
  */
7678
- function* streamToHtml(node, opts, output) {
7681
+ function serializeToBuffer(node, opts, output, out) {
7679
7682
  const isShadowRoot = node.nodeType === 11;
7680
7683
  if (node.nodeType === 1 || isShadowRoot) {
7681
7684
  const tagName = isShadowRoot ? shadowRootTag : getTagName(node);
@@ -7684,15 +7687,15 @@ function* streamToHtml(node, opts, output) {
7684
7687
  if (ignoreTag === false) {
7685
7688
  const isWithinWhitespaceSensitiveNode = opts.newLines || (opts.indentSpaces ?? 0) > 0 ? isWithinWhitespaceSensitive(node) : false;
7686
7689
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
7687
- yield "\n";
7690
+ out.html += "\n";
7688
7691
  output.currentLineWidth = 0;
7689
7692
  }
7690
7693
  if ((opts.indentSpaces ?? 0) > 0 && !isWithinWhitespaceSensitiveNode) {
7691
- for (let i = 0; i < output.indent; i++) yield " ";
7694
+ for (let i = 0; i < output.indent; i++) out.html += " ";
7692
7695
  output.currentLineWidth += output.indent;
7693
7696
  }
7694
7697
  const tag = tagName === shadowRootTag ? "template" : tagName;
7695
- yield "<" + tag;
7698
+ out.html += "<" + tag;
7696
7699
  output.currentLineWidth += tag.length + 1;
7697
7700
  /**
7698
7701
  * ToDo(https://github.com/stenciljs/core/issues/4111): the shadow root class is `#document-fragment`
@@ -7700,23 +7703,23 @@ function* streamToHtml(node, opts, output) {
7700
7703
  */
7701
7704
  if (tag === "template" && (!node.getAttribute || !node.getAttribute("shadowrootmode")) && ("host" in node || node.nodeName.toLocaleLowerCase() === shadowRootTag)) {
7702
7705
  const mode = ` shadowrootmode="open"`;
7703
- yield mode;
7706
+ out.html += mode;
7704
7707
  output.currentLineWidth += mode.length;
7705
7708
  if (node.delegatesFocus) {
7706
- yield " shadowrootdelegatesfocus";
7709
+ out.html += " shadowrootdelegatesfocus";
7707
7710
  output.currentLineWidth += 25;
7708
7711
  }
7709
7712
  if (node.clonable) {
7710
- yield " shadowrootclonable";
7713
+ out.html += " shadowrootclonable";
7711
7714
  output.currentLineWidth += 19;
7712
7715
  }
7713
7716
  if (node.serializable) {
7714
- yield " shadowrootserializable";
7717
+ out.html += " shadowrootserializable";
7715
7718
  output.currentLineWidth += 23;
7716
7719
  }
7717
7720
  if ("referenceTarget" in node && typeof node.referenceTarget === "string" && node.referenceTarget) {
7718
7721
  const referenceTargetAttr = ` shadowrootreferencetarget="${escapeString(node.referenceTarget, true)}"`;
7719
- yield referenceTargetAttr;
7722
+ out.html += referenceTargetAttr;
7720
7723
  output.currentLineWidth += referenceTargetAttr.length;
7721
7724
  }
7722
7725
  }
@@ -7734,25 +7737,25 @@ function* streamToHtml(node, opts, output) {
7734
7737
  if (attrNamespaceURI == null) {
7735
7738
  output.currentLineWidth += attrName.length + 1;
7736
7739
  if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth > opts.approximateLineWidth) {
7737
- yield "\n" + attrName;
7740
+ out.html += "\n" + attrName;
7738
7741
  output.currentLineWidth = 0;
7739
- } else yield " " + attrName;
7742
+ } else out.html += " " + attrName;
7740
7743
  } else if (attrNamespaceURI === "http://www.w3.org/XML/1998/namespace") {
7741
- yield " xml:" + attrLocalName;
7744
+ out.html += " xml:" + attrLocalName;
7742
7745
  output.currentLineWidth += attrLocalName.length + 5;
7743
7746
  } else if (attrNamespaceURI === "http://www.w3.org/2000/xmlns/") {
7744
7747
  if (attrLocalName !== "xmlns") {
7745
- yield " xmlns:" + attrLocalName;
7748
+ out.html += " xmlns:" + attrLocalName;
7746
7749
  output.currentLineWidth += attrLocalName.length + 7;
7747
7750
  } else {
7748
- yield " " + attrLocalName;
7751
+ out.html += " " + attrLocalName;
7749
7752
  output.currentLineWidth += attrLocalName.length + 1;
7750
7753
  }
7751
7754
  } else if (attrNamespaceURI === "http://www.w3.org/1999/xlink") {
7752
- yield " xlink:" + attrLocalName;
7755
+ out.html += " xlink:" + attrLocalName;
7753
7756
  output.currentLineWidth += attrLocalName.length + 7;
7754
7757
  } else {
7755
- yield " " + attrNamespaceURI + ":" + attrLocalName;
7758
+ out.html += " " + attrNamespaceURI + ":" + attrLocalName;
7756
7759
  output.currentLineWidth += attrNamespaceURI.length + attrLocalName.length + 2;
7757
7760
  }
7758
7761
  if (opts.prettyHtml && attrName === "class") attrValue = attr.value = attrValue.split(" ").filter((t) => t !== "").sort().join(" ").trim();
@@ -7762,24 +7765,24 @@ function* streamToHtml(node, opts, output) {
7762
7765
  if (opts.removeEmptyAttributes && attrName.startsWith("data-")) continue;
7763
7766
  }
7764
7767
  if (opts.removeAttributeQuotes && CAN_REMOVE_ATTR_QUOTES.test(attrValue)) {
7765
- yield "=" + escapeString(attrValue, true);
7768
+ out.html += "=" + escapeString(attrValue, true);
7766
7769
  output.currentLineWidth += attrValue.length + 1;
7767
7770
  } else {
7768
- yield "=\"" + escapeString(attrValue, true) + "\"";
7771
+ out.html += "=\"" + escapeString(attrValue, true) + "\"";
7769
7772
  output.currentLineWidth += attrValue.length + 3;
7770
7773
  }
7771
7774
  }
7772
7775
  if (node.hasAttribute("style")) {
7773
7776
  const cssText = node.style.cssText;
7774
7777
  if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth + cssText.length + 10 > opts.approximateLineWidth) {
7775
- yield `\nstyle="${escapeString(cssText, true)}">`;
7778
+ out.html += `\nstyle="${escapeString(cssText, true)}">`;
7776
7779
  output.currentLineWidth = 0;
7777
7780
  } else {
7778
- yield ` style="${escapeString(cssText, true)}">`;
7781
+ out.html += ` style="${escapeString(cssText, true)}">`;
7779
7782
  output.currentLineWidth += cssText.length + 10;
7780
7783
  }
7781
7784
  } else {
7782
- yield ">";
7785
+ out.html += ">";
7783
7786
  output.currentLineWidth += 1;
7784
7787
  }
7785
7788
  }
@@ -7787,13 +7790,13 @@ function* streamToHtml(node, opts, output) {
7787
7790
  const shadowRoot = node.shadowRoot;
7788
7791
  if (shadowRoot != null && opts.serializeShadowRoot !== false) {
7789
7792
  output.indent = output.indent + (opts.indentSpaces ?? 0);
7790
- yield* streamToHtml(shadowRoot, opts, output);
7793
+ serializeToBuffer(shadowRoot, opts, output, out);
7791
7794
  output.indent = output.indent - (opts.indentSpaces ?? 0);
7792
7795
  const childNodes = getChildNodes(node);
7793
7796
  if (opts.newLines && (childNodes.length === 0 || childNodes.length === 1 && childNodes[0].nodeType === 3 && childNodes[0].nodeValue?.trim() === "" || hasOnlyRemovedComments(childNodes, opts))) {
7794
- yield "\n";
7797
+ out.html += "\n";
7795
7798
  output.currentLineWidth = 0;
7796
- for (let i = 0; i < output.indent; i++) yield " ";
7799
+ for (let i = 0; i < output.indent; i++) out.html += " ";
7797
7800
  output.currentLineWidth += output.indent;
7798
7801
  }
7799
7802
  }
@@ -7807,29 +7810,29 @@ function* streamToHtml(node, opts, output) {
7807
7810
  if (!isWithinWhitespaceSensitiveNode && (opts.indentSpaces ?? 0) > 0 && ignoreTag === false) output.indent = output.indent + (opts.indentSpaces ?? 0);
7808
7811
  for (let i = 0; i < childNodeLength; i++) {
7809
7812
  if (childNodes[i].nodeName.toLowerCase() === "template" && node.attributes.getNamedItem("s-id")) continue;
7810
- yield* streamToHtml(childNodes[i], opts, output);
7813
+ serializeToBuffer(childNodes[i], opts, output, out);
7811
7814
  }
7812
7815
  if (ignoreTag === false) {
7813
7816
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
7814
- yield "\n";
7817
+ out.html += "\n";
7815
7818
  output.currentLineWidth = 0;
7816
7819
  }
7817
7820
  if ((opts.indentSpaces ?? 0) > 0 && !isWithinWhitespaceSensitiveNode) {
7818
7821
  output.indent = output.indent - (opts.indentSpaces ?? 0);
7819
- for (let i = 0; i < output.indent; i++) yield " ";
7822
+ for (let i = 0; i < output.indent; i++) out.html += " ";
7820
7823
  output.currentLineWidth += output.indent;
7821
7824
  }
7822
7825
  }
7823
7826
  }
7824
7827
  }
7825
7828
  if (ignoreTag === false) {
7826
- yield "</" + tag + ">";
7829
+ out.html += "</" + tag + ">";
7827
7830
  output.currentLineWidth += tag.length + 3;
7828
7831
  }
7829
7832
  }
7830
7833
  }
7831
7834
  if ((opts.approximateLineWidth ?? 0) > 0 && STRUCTURE_ELEMENTS.has(tagName)) {
7832
- yield "\n";
7835
+ out.html += "\n";
7833
7836
  output.currentLineWidth = 0;
7834
7837
  }
7835
7838
  if (tagName === "body") output.isWithinBody = false;
@@ -7839,37 +7842,37 @@ function* streamToHtml(node, opts, output) {
7839
7842
  const trimmedTextContent = textContent.trim();
7840
7843
  if (trimmedTextContent === "") {
7841
7844
  if (isWithinWhitespaceSensitive(node)) {
7842
- yield textContent;
7845
+ out.html += textContent;
7843
7846
  output.currentLineWidth += textContent.length;
7844
7847
  } else if ((opts.approximateLineWidth ?? 0) > 0 && !output.isWithinBody) {} else if (!opts.prettyHtml) {
7845
7848
  output.currentLineWidth += 1;
7846
7849
  if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth > opts.approximateLineWidth) {
7847
- yield "\n";
7850
+ out.html += "\n";
7848
7851
  output.currentLineWidth = 0;
7849
- } else yield " ";
7852
+ } else out.html += " ";
7850
7853
  }
7851
7854
  } else {
7852
7855
  const isWithinWhitespaceSensitiveNode = opts.newLines || (opts.indentSpaces ?? 0) > 0 || opts.prettyHtml ? isWithinWhitespaceSensitive(node) : false;
7853
7856
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
7854
- yield "\n";
7857
+ out.html += "\n";
7855
7858
  output.currentLineWidth = 0;
7856
7859
  }
7857
7860
  if ((opts.indentSpaces ?? 0) > 0 && !isWithinWhitespaceSensitiveNode) {
7858
- for (let i = 0; i < output.indent; i++) yield " ";
7861
+ for (let i = 0; i < output.indent; i++) out.html += " ";
7859
7862
  output.currentLineWidth += output.indent;
7860
7863
  }
7861
7864
  let textContentLength = textContent.length;
7862
7865
  if (textContentLength > 0) {
7863
7866
  const parentTagName = node.parentNode != null && node.parentNode.nodeType === 1 ? node.parentNode.nodeName : null;
7864
7867
  if (typeof parentTagName === "string" && NON_ESCAPABLE_CONTENT.has(parentTagName)) {
7865
- if (isWithinWhitespaceSensitive(node)) yield textContent;
7868
+ if (isWithinWhitespaceSensitive(node)) out.html += textContent;
7866
7869
  else {
7867
- yield trimmedTextContent;
7870
+ out.html += trimmedTextContent;
7868
7871
  textContentLength = trimmedTextContent.length;
7869
7872
  }
7870
7873
  output.currentLineWidth += textContentLength;
7871
7874
  } else if (opts.prettyHtml && !isWithinWhitespaceSensitiveNode) {
7872
- yield escapeString(textContent.replace(/\s\s+/g, " ").trim(), false);
7875
+ out.html += escapeString(textContent.replace(/\s\s+/g, " ").trim(), false);
7873
7876
  output.currentLineWidth += textContentLength;
7874
7877
  } else {
7875
7878
  if (isWithinWhitespaceSensitive(node)) output.currentLineWidth += textContentLength;
@@ -7886,7 +7889,7 @@ function* streamToHtml(node, opts, output) {
7886
7889
  }
7887
7890
  output.currentLineWidth += textContentLength;
7888
7891
  }
7889
- yield escapeString(textContent, false);
7892
+ out.html += escapeString(textContent, false);
7890
7893
  }
7891
7894
  }
7892
7895
  }
@@ -7900,16 +7903,16 @@ function* streamToHtml(node, opts, output) {
7900
7903
  if (isRemovedComment(node, opts)) return;
7901
7904
  const isWithinWhitespaceSensitiveNode = opts.newLines || (opts.indentSpaces ?? 0) > 0 ? isWithinWhitespaceSensitive(node) : false;
7902
7905
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
7903
- yield "\n";
7906
+ out.html += "\n";
7904
7907
  output.currentLineWidth = 0;
7905
7908
  }
7906
7909
  if ((opts.indentSpaces ?? 0) > 0 && !isWithinWhitespaceSensitiveNode) {
7907
- for (let i = 0; i < output.indent; i++) yield " ";
7910
+ for (let i = 0; i < output.indent; i++) out.html += " ";
7908
7911
  output.currentLineWidth += output.indent;
7909
7912
  }
7910
- yield "<!--" + nodeValue + "-->";
7913
+ out.html += "<!--" + nodeValue + "-->";
7911
7914
  if (nodeValue) output.currentLineWidth += nodeValue.length + 7;
7912
- } else if (node.nodeType === 10) yield "<!doctype html>";
7915
+ } else if (node.nodeType === 10) out.html += "<!doctype html>";
7913
7916
  }
7914
7917
  const AMP_REGEX = /&/g;
7915
7918
  const NBSP_REGEX = /\u00a0/g;
@@ -7921,7 +7924,10 @@ function getTagName(element) {
7921
7924
  if (element.namespaceURI === "http://www.w3.org/1999/xhtml") return element.nodeName.toLowerCase();
7922
7925
  else return element.nodeName;
7923
7926
  }
7927
+ const ATTR_NEEDS_ESCAPE = /[&\u00a0"]/;
7928
+ const TEXT_NEEDS_ESCAPE = /[&\u00a0<>]/;
7924
7929
  function escapeString(str, attrMode) {
7930
+ if (!(attrMode ? ATTR_NEEDS_ESCAPE : TEXT_NEEDS_ESCAPE).test(str)) return str;
7925
7931
  str = str.replace(AMP_REGEX, "&amp;").replace(NBSP_REGEX, "&nbsp;");
7926
7932
  if (attrMode) return str.replace(DOUBLE_QUOTE_REGEX, "&quot;");
7927
7933
  return str.replace(LT_REGEX, "&lt;").replace(GT_REGEX, "&gt;");
@@ -8438,10 +8444,16 @@ var MockElement = class extends MockNode {
8438
8444
  this.__attributeMap = attrs;
8439
8445
  }
8440
8446
  get children() {
8441
- return this.childNodes.filter((n) => n.nodeType === 1);
8447
+ const nodes = this.childNodes;
8448
+ const elements = [];
8449
+ for (let i = 0; i < nodes.length; i++) if (nodes[i].nodeType === 1) elements.push(nodes[i]);
8450
+ return elements;
8442
8451
  }
8443
8452
  get childElementCount() {
8444
- return this.childNodes.filter((n) => n.nodeType === 1).length;
8453
+ const nodes = this.childNodes;
8454
+ let count = 0;
8455
+ for (let i = 0; i < nodes.length; i++) if (nodes[i].nodeType === 1) count++;
8456
+ return count;
8445
8457
  }
8446
8458
  get className() {
8447
8459
  return this.getAttributeNS(null, "class") || "";
@@ -8484,7 +8496,9 @@ var MockElement = class extends MockNode {
8484
8496
  return dispatchEvent(this, ev);
8485
8497
  }
8486
8498
  get firstElementChild() {
8487
- return this.children[0] || null;
8499
+ const nodes = this.childNodes;
8500
+ for (let i = 0; i < nodes.length; i++) if (nodes[i].nodeType === 1) return nodes[i];
8501
+ return null;
8488
8502
  }
8489
8503
  focus(_options) {
8490
8504
  dispatchEvent(this, new MockFocusEvent("focus", {
@@ -24,7 +24,6 @@ import * as SignalsCore from "@preact/signals-core";
24
24
  */
25
25
  const BUILD = {
26
26
  allRenderFn: false,
27
- element: true,
28
27
  event: true,
29
28
  hasRenderFn: true,
30
29
  hostListener: true,
@@ -1,4 +1,4 @@
1
- import { Bt as Logger, nt as CompilerSystem } from "../../index-BDAZsQzV.mjs";
1
+ import { Bt as Logger, nt as CompilerSystem } from "../../index-BOBfOxcK.mjs";
2
2
  //#region src/sys/node/logger/index.d.ts
3
3
  /**
4
4
  * Create a logger to run in a Node environment
@@ -1,2 +1,2 @@
1
- import { n as setupNodeProcess, r as createNodeLogger, t as createNodeSys } from "../../node-C6N23fLr.mjs";
1
+ import { n as setupNodeProcess, r as createNodeLogger, t as createNodeSys } from "../../node-IRt_dGbC.mjs";
2
2
  export { createNodeLogger, createNodeSys, setupNodeProcess };
@@ -1,5 +1,5 @@
1
- import { l as createWorkerMessageHandler } from "../../compiler-D92bSZzV.mjs";
2
- import { t as createNodeSys } from "../../node-C6N23fLr.mjs";
1
+ import { l as createWorkerMessageHandler } from "../../compiler--CBIwBTZ.mjs";
2
+ import { t as createNodeSys } from "../../node-IRt_dGbC.mjs";
3
3
  //#region src/sys/node/node-worker-thread.ts
4
4
  /**
5
5
  * Initialize a worker thread, setting up various machinery for managing
@@ -3094,7 +3094,6 @@ interface BuildFeatures {
3094
3094
  patchInsert: boolean;
3095
3095
  slot: boolean;
3096
3096
  svg: boolean;
3097
- element: boolean;
3098
3097
  event: boolean;
3099
3098
  hostListener: boolean;
3100
3099
  hostListenerTargetWindow: boolean;
@@ -3464,7 +3463,6 @@ interface ComponentCompilerFeatures {
3464
3463
  hasConnectedCallbackFn: boolean;
3465
3464
  hasDeserializer: boolean;
3466
3465
  hasDisconnectedCallbackFn: boolean;
3467
- hasElement: boolean;
3468
3466
  hasEvent: boolean;
3469
3467
  hasLifecycle: boolean;
3470
3468
  hasListener: boolean;