@stencil/core 4.18.3 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/cli/index.cjs +43 -16
  2. package/cli/index.js +43 -16
  3. package/cli/package.json +1 -1
  4. package/compiler/package.json +1 -1
  5. package/compiler/stencil.js +175 -72
  6. package/dev-server/client/index.js +1 -1
  7. package/dev-server/client/package.json +1 -1
  8. package/dev-server/connector.html +3 -3
  9. package/dev-server/index.js +1 -1
  10. package/dev-server/package.json +1 -1
  11. package/dev-server/server-process.js +2 -2
  12. package/dev-server/ws.js +1 -1
  13. package/internal/app-data/package.json +1 -1
  14. package/internal/client/index.js +534 -507
  15. package/internal/client/package.json +3 -1
  16. package/internal/client/patch-browser.js +1 -1
  17. package/internal/hydrate/index.js +108 -50
  18. package/internal/hydrate/package.json +1 -1
  19. package/internal/hydrate/runner.d.ts +29 -11
  20. package/internal/hydrate/runner.js +239 -260
  21. package/internal/package.json +1 -1
  22. package/internal/stencil-private.d.ts +39 -14
  23. package/internal/stencil-public-compiler.d.ts +21 -0
  24. package/internal/stencil-public-runtime.d.ts +0 -2
  25. package/internal/testing/index.js +439 -407
  26. package/internal/testing/package.json +1 -1
  27. package/mock-doc/index.cjs +137 -131
  28. package/mock-doc/index.d.ts +18 -4
  29. package/mock-doc/index.js +137 -131
  30. package/mock-doc/package.json +1 -1
  31. package/package.json +34 -6
  32. package/screenshot/index.js +1 -1
  33. package/screenshot/package.json +1 -1
  34. package/screenshot/pixel-match.js +1 -1
  35. package/sys/node/index.js +10 -10
  36. package/sys/node/package.json +1 -1
  37. package/sys/node/worker.js +1 -1
  38. package/testing/index.js +95 -16
  39. package/testing/jest/jest-27-and-under/matchers/events.d.ts +4 -0
  40. package/testing/jest/jest-27-and-under/matchers/index.d.ts +2 -1
  41. package/testing/jest/jest-28/matchers/events.d.ts +4 -0
  42. package/testing/jest/jest-28/matchers/index.d.ts +2 -1
  43. package/testing/jest/jest-29/matchers/events.d.ts +4 -0
  44. package/testing/jest/jest-29/matchers/index.d.ts +2 -1
  45. package/testing/mocks.d.ts +9 -9
  46. package/testing/package.json +1 -1
  47. package/testing/puppeteer/puppeteer-declarations.d.ts +11 -0
@@ -1,5 +1,5 @@
1
1
  /*
2
- Stencil Hydrate Runner v4.18.3 | MIT Licensed | https://stenciljs.com
2
+ Stencil Hydrate Runner v4.19.0 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  var __defProp = Object.defineProperty;
5
5
  var __export = (target, all) => {
@@ -10397,67 +10397,50 @@ function humanReadableList(items) {
10397
10397
  }
10398
10398
 
10399
10399
  // src/mock-doc/serialize-node.ts
10400
- function serializeNodeToHtml(elm, opts = {}) {
10400
+ function normalizeSerializationOptions(opts = {}) {
10401
+ return {
10402
+ ...opts,
10403
+ outerHtml: typeof opts.outerHtml !== "boolean" ? false : opts.outerHtml,
10404
+ ...opts.prettyHtml ? {
10405
+ indentSpaces: typeof opts.indentSpaces !== "number" ? 2 : opts.indentSpaces,
10406
+ newLines: typeof opts.newLines !== "boolean" ? true : opts.newLines
10407
+ } : {
10408
+ prettyHtml: false,
10409
+ indentSpaces: typeof opts.indentSpaces !== "number" ? 0 : opts.indentSpaces,
10410
+ newLines: typeof opts.newLines !== "boolean" ? false : opts.newLines
10411
+ },
10412
+ approximateLineWidth: typeof opts.approximateLineWidth !== "number" ? -1 : opts.approximateLineWidth,
10413
+ removeEmptyAttributes: typeof opts.removeEmptyAttributes !== "boolean" ? true : opts.removeEmptyAttributes,
10414
+ removeAttributeQuotes: typeof opts.removeAttributeQuotes !== "boolean" ? false : opts.removeAttributeQuotes,
10415
+ removeBooleanAttributeQuotes: typeof opts.removeBooleanAttributeQuotes !== "boolean" ? false : opts.removeBooleanAttributeQuotes,
10416
+ removeHtmlComments: typeof opts.removeHtmlComments !== "boolean" ? false : opts.removeHtmlComments,
10417
+ serializeShadowRoot: typeof opts.serializeShadowRoot !== "boolean" ? false : opts.serializeShadowRoot,
10418
+ fullDocument: typeof opts.fullDocument !== "boolean" ? true : opts.fullDocument
10419
+ };
10420
+ }
10421
+ function serializeNodeToHtml(elm, serializationOptions = {}) {
10422
+ const opts = normalizeSerializationOptions(serializationOptions);
10401
10423
  const output = {
10402
10424
  currentLineWidth: 0,
10403
10425
  indent: 0,
10404
10426
  isWithinBody: false,
10405
10427
  text: []
10406
10428
  };
10407
- if (opts.prettyHtml) {
10408
- if (typeof opts.indentSpaces !== "number") {
10409
- opts.indentSpaces = 2;
10410
- }
10411
- if (typeof opts.newLines !== "boolean") {
10412
- opts.newLines = true;
10413
- }
10414
- opts.approximateLineWidth = -1;
10415
- } else {
10416
- opts.prettyHtml = false;
10417
- if (typeof opts.newLines !== "boolean") {
10418
- opts.newLines = false;
10419
- }
10420
- if (typeof opts.indentSpaces !== "number") {
10421
- opts.indentSpaces = 0;
10422
- }
10423
- }
10424
- if (typeof opts.approximateLineWidth !== "number") {
10425
- opts.approximateLineWidth = -1;
10426
- }
10427
- if (typeof opts.removeEmptyAttributes !== "boolean") {
10428
- opts.removeEmptyAttributes = true;
10429
- }
10430
- if (typeof opts.removeAttributeQuotes !== "boolean") {
10431
- opts.removeAttributeQuotes = false;
10432
- }
10433
- if (typeof opts.removeBooleanAttributeQuotes !== "boolean") {
10434
- opts.removeBooleanAttributeQuotes = false;
10435
- }
10436
- if (typeof opts.removeHtmlComments !== "boolean") {
10437
- opts.removeHtmlComments = false;
10438
- }
10439
- if (typeof opts.serializeShadowRoot !== "boolean") {
10440
- opts.serializeShadowRoot = false;
10441
- }
10442
- if (opts.outerHtml) {
10443
- serializeToHtml(elm, opts, output, false);
10444
- } else {
10445
- for (let i = 0, ii = elm.childNodes.length; i < ii; i++) {
10446
- serializeToHtml(elm.childNodes[i], opts, output, false);
10447
- }
10448
- }
10449
- if (output.text[0] === "\n") {
10450
- output.text.shift();
10451
- }
10452
- if (output.text[output.text.length - 1] === "\n") {
10453
- output.text.pop();
10429
+ let renderedNode = "";
10430
+ const children = !opts.fullDocument && elm.body ? Array.from(elm.body.childNodes) : opts.outerHtml ? [elm] : Array.from(elm.childNodes);
10431
+ for (let i = 0, ii = children.length; i < ii; i++) {
10432
+ const child = children[i];
10433
+ const chunks = Array.from(streamToHtml(child, opts, output));
10434
+ renderedNode += chunks.join("");
10454
10435
  }
10455
- return output.text.join("");
10436
+ return renderedNode.trim();
10456
10437
  }
10457
- function serializeToHtml(node, opts, output, isShadowRoot) {
10438
+ var shadowRootTag = "mock:shadow-root";
10439
+ function* streamToHtml(node, opts, output) {
10458
10440
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
10441
+ const isShadowRoot = node.nodeType === 11 /* DOCUMENT_FRAGMENT_NODE */;
10459
10442
  if (node.nodeType === 1 /* ELEMENT_NODE */ || isShadowRoot) {
10460
- const tagName = isShadowRoot ? "mock:shadow-root" : getTagName(node);
10443
+ const tagName = isShadowRoot ? shadowRootTag : getTagName(node);
10461
10444
  if (tagName === "body") {
10462
10445
  output.isWithinBody = true;
10463
10446
  }
@@ -10465,17 +10448,23 @@ function serializeToHtml(node, opts, output, isShadowRoot) {
10465
10448
  if (ignoreTag === false) {
10466
10449
  const isWithinWhitespaceSensitiveNode = opts.newLines || ((_a2 = opts.indentSpaces) != null ? _a2 : 0) > 0 ? isWithinWhitespaceSensitive(node) : false;
10467
10450
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
10468
- output.text.push("\n");
10451
+ yield "\n";
10469
10452
  output.currentLineWidth = 0;
10470
10453
  }
10471
10454
  if (((_b = opts.indentSpaces) != null ? _b : 0) > 0 && !isWithinWhitespaceSensitiveNode) {
10472
10455
  for (let i = 0; i < output.indent; i++) {
10473
- output.text.push(" ");
10456
+ yield " ";
10474
10457
  }
10475
10458
  output.currentLineWidth += output.indent;
10476
10459
  }
10477
- output.text.push("<" + tagName);
10478
- output.currentLineWidth += tagName.length + 1;
10460
+ const tag = tagName === shadowRootTag ? "template" : tagName;
10461
+ yield "<" + tag;
10462
+ output.currentLineWidth += tag.length + 1;
10463
+ if (tag === "template") {
10464
+ const mode = ` shadowrootmode="open"`;
10465
+ yield mode;
10466
+ output.currentLineWidth += mode.length;
10467
+ }
10479
10468
  const attrsLength = node.attributes.length;
10480
10469
  const attributes = opts.prettyHtml && attrsLength > 1 ? cloneAttributes(node.attributes, true) : node.attributes;
10481
10470
  for (let i = 0; i < attrsLength; i++) {
@@ -10492,27 +10481,27 @@ function serializeToHtml(node, opts, output, isShadowRoot) {
10492
10481
  if (attrNamespaceURI == null) {
10493
10482
  output.currentLineWidth += attrName.length + 1;
10494
10483
  if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth > opts.approximateLineWidth) {
10495
- output.text.push("\n" + attrName);
10484
+ yield "\n" + attrName;
10496
10485
  output.currentLineWidth = 0;
10497
10486
  } else {
10498
- output.text.push(" " + attrName);
10487
+ yield " " + attrName;
10499
10488
  }
10500
10489
  } else if (attrNamespaceURI === "http://www.w3.org/XML/1998/namespace") {
10501
- output.text.push(" xml:" + attrName);
10490
+ yield " xml:" + attrName;
10502
10491
  output.currentLineWidth += attrName.length + 5;
10503
10492
  } else if (attrNamespaceURI === "http://www.w3.org/2000/xmlns/") {
10504
10493
  if (attrName !== "xmlns") {
10505
- output.text.push(" xmlns:" + attrName);
10494
+ yield " xmlns:" + attrName;
10506
10495
  output.currentLineWidth += attrName.length + 7;
10507
10496
  } else {
10508
- output.text.push(" " + attrName);
10497
+ yield " " + attrName;
10509
10498
  output.currentLineWidth += attrName.length + 1;
10510
10499
  }
10511
10500
  } else if (attrNamespaceURI === XLINK_NS) {
10512
- output.text.push(" xlink:" + attrName);
10501
+ yield " xlink:" + attrName;
10513
10502
  output.currentLineWidth += attrName.length + 7;
10514
10503
  } else {
10515
- output.text.push(" " + attrNamespaceURI + ":" + attrName);
10504
+ yield " " + attrNamespaceURI + ":" + attrName;
10516
10505
  output.currentLineWidth += attrNamespaceURI.length + attrName.length + 2;
10517
10506
  }
10518
10507
  if (opts.prettyHtml && attrName === "class") {
@@ -10527,43 +10516,45 @@ function serializeToHtml(node, opts, output, isShadowRoot) {
10527
10516
  }
10528
10517
  }
10529
10518
  if (opts.removeAttributeQuotes && CAN_REMOVE_ATTR_QUOTES.test(attrValue)) {
10530
- output.text.push("=" + escapeString(attrValue, true));
10519
+ yield "=" + escapeString(attrValue, true);
10531
10520
  output.currentLineWidth += attrValue.length + 1;
10532
10521
  } else {
10533
- output.text.push('="' + escapeString(attrValue, true) + '"');
10522
+ yield '="' + escapeString(attrValue, true) + '"';
10534
10523
  output.currentLineWidth += attrValue.length + 3;
10535
10524
  }
10536
10525
  }
10537
10526
  if (node.hasAttribute("style")) {
10538
10527
  const cssText = node.style.cssText;
10539
10528
  if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth + cssText.length + 10 > opts.approximateLineWidth) {
10540
- output.text.push(`
10541
- style="${cssText}">`);
10529
+ yield `
10530
+ style="${cssText}">`;
10542
10531
  output.currentLineWidth = 0;
10543
10532
  } else {
10544
- output.text.push(` style="${cssText}">`);
10533
+ yield ` style="${cssText}">`;
10545
10534
  output.currentLineWidth += cssText.length + 10;
10546
10535
  }
10547
10536
  } else {
10548
- output.text.push(">");
10537
+ yield ">";
10549
10538
  output.currentLineWidth += 1;
10550
10539
  }
10551
10540
  }
10552
10541
  if (EMPTY_ELEMENTS.has(tagName) === false) {
10553
- if (opts.serializeShadowRoot && node.shadowRoot != null) {
10542
+ const shadowRoot = node.shadowRoot;
10543
+ if (opts.serializeShadowRoot && shadowRoot != null) {
10554
10544
  output.indent = output.indent + ((_c = opts.indentSpaces) != null ? _c : 0);
10555
- serializeToHtml(node.shadowRoot, opts, output, true);
10545
+ yield* streamToHtml(shadowRoot, opts, output);
10556
10546
  output.indent = output.indent - ((_d = opts.indentSpaces) != null ? _d : 0);
10557
10547
  if (opts.newLines && (node.childNodes.length === 0 || node.childNodes.length === 1 && node.childNodes[0].nodeType === 3 /* TEXT_NODE */ && ((_e = node.childNodes[0].nodeValue) == null ? void 0 : _e.trim()) === "")) {
10558
- output.text.push("\n");
10548
+ yield "\n";
10559
10549
  output.currentLineWidth = 0;
10560
10550
  for (let i = 0; i < output.indent; i++) {
10561
- output.text.push(" ");
10551
+ yield " ";
10562
10552
  }
10563
10553
  output.currentLineWidth += output.indent;
10564
10554
  }
10565
10555
  }
10566
10556
  if (opts.excludeTagContent == null || opts.excludeTagContent.includes(tagName) === false) {
10557
+ const tag = tagName === shadowRootTag ? "template" : tagName;
10567
10558
  const childNodes = tagName === "template" ? node.content.childNodes : node.childNodes;
10568
10559
  const childNodeLength = childNodes.length;
10569
10560
  if (childNodeLength > 0) {
@@ -10574,17 +10565,17 @@ style="${cssText}">`);
10574
10565
  output.indent = output.indent + ((_h = opts.indentSpaces) != null ? _h : 0);
10575
10566
  }
10576
10567
  for (let i = 0; i < childNodeLength; i++) {
10577
- serializeToHtml(childNodes[i], opts, output, false);
10568
+ yield* streamToHtml(childNodes[i], opts, output);
10578
10569
  }
10579
10570
  if (ignoreTag === false) {
10580
10571
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
10581
- output.text.push("\n");
10572
+ yield "\n";
10582
10573
  output.currentLineWidth = 0;
10583
10574
  }
10584
10575
  if (((_i = opts.indentSpaces) != null ? _i : 0) > 0 && !isWithinWhitespaceSensitiveNode) {
10585
10576
  output.indent = output.indent - ((_j = opts.indentSpaces) != null ? _j : 0);
10586
10577
  for (let i = 0; i < output.indent; i++) {
10587
- output.text.push(" ");
10578
+ yield " ";
10588
10579
  }
10589
10580
  output.currentLineWidth += output.indent;
10590
10581
  }
@@ -10592,13 +10583,13 @@ style="${cssText}">`);
10592
10583
  }
10593
10584
  }
10594
10585
  if (ignoreTag === false) {
10595
- output.text.push("</" + tagName + ">");
10596
- output.currentLineWidth += tagName.length + 3;
10586
+ yield "</" + tag + ">";
10587
+ output.currentLineWidth += tag.length + 3;
10597
10588
  }
10598
10589
  }
10599
10590
  }
10600
10591
  if (((_k = opts.approximateLineWidth) != null ? _k : 0) > 0 && STRUCTURE_ELEMENTS.has(tagName)) {
10601
- output.text.push("\n");
10592
+ yield "\n";
10602
10593
  output.currentLineWidth = 0;
10603
10594
  }
10604
10595
  if (tagName === "body") {
@@ -10610,27 +10601,27 @@ style="${cssText}">`);
10610
10601
  const trimmedTextContent = textContent.trim();
10611
10602
  if (trimmedTextContent === "") {
10612
10603
  if (isWithinWhitespaceSensitive(node)) {
10613
- output.text.push(textContent);
10604
+ yield textContent;
10614
10605
  output.currentLineWidth += textContent.length;
10615
10606
  } else if (((_l = opts.approximateLineWidth) != null ? _l : 0) > 0 && !output.isWithinBody) {
10616
10607
  } else if (!opts.prettyHtml) {
10617
10608
  output.currentLineWidth += 1;
10618
10609
  if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth > opts.approximateLineWidth) {
10619
- output.text.push("\n");
10610
+ yield "\n";
10620
10611
  output.currentLineWidth = 0;
10621
10612
  } else {
10622
- output.text.push(" ");
10613
+ yield " ";
10623
10614
  }
10624
10615
  }
10625
10616
  } else {
10626
10617
  const isWithinWhitespaceSensitiveNode = opts.newLines || ((_m = opts.indentSpaces) != null ? _m : 0) > 0 || opts.prettyHtml ? isWithinWhitespaceSensitive(node) : false;
10627
10618
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
10628
- output.text.push("\n");
10619
+ yield "\n";
10629
10620
  output.currentLineWidth = 0;
10630
10621
  }
10631
10622
  if (((_n = opts.indentSpaces) != null ? _n : 0) > 0 && !isWithinWhitespaceSensitiveNode) {
10632
10623
  for (let i = 0; i < output.indent; i++) {
10633
- output.text.push(" ");
10624
+ yield " ";
10634
10625
  }
10635
10626
  output.currentLineWidth += output.indent;
10636
10627
  }
@@ -10639,15 +10630,15 @@ style="${cssText}">`);
10639
10630
  const parentTagName = node.parentNode != null && node.parentNode.nodeType === 1 /* ELEMENT_NODE */ ? node.parentNode.nodeName : null;
10640
10631
  if (typeof parentTagName === "string" && NON_ESCAPABLE_CONTENT.has(parentTagName)) {
10641
10632
  if (isWithinWhitespaceSensitive(node)) {
10642
- output.text.push(textContent);
10633
+ yield textContent;
10643
10634
  } else {
10644
- output.text.push(trimmedTextContent);
10635
+ yield trimmedTextContent;
10645
10636
  textContentLength = trimmedTextContent.length;
10646
10637
  }
10647
10638
  output.currentLineWidth += textContentLength;
10648
10639
  } else {
10649
10640
  if (opts.prettyHtml && !isWithinWhitespaceSensitiveNode) {
10650
- output.text.push(escapeString(textContent.replace(/\s\s+/g, " ").trim(), false));
10641
+ yield escapeString(textContent.replace(/\s\s+/g, " ").trim(), false);
10651
10642
  output.currentLineWidth += textContentLength;
10652
10643
  } else {
10653
10644
  if (isWithinWhitespaceSensitive(node)) {
@@ -10669,7 +10660,7 @@ style="${cssText}">`);
10669
10660
  }
10670
10661
  output.currentLineWidth += textContentLength;
10671
10662
  }
10672
- output.text.push(escapeString(textContent, false));
10663
+ yield escapeString(textContent, false);
10673
10664
  }
10674
10665
  }
10675
10666
  }
@@ -10677,27 +10668,27 @@ style="${cssText}">`);
10677
10668
  }
10678
10669
  } else if (node.nodeType === 8 /* COMMENT_NODE */) {
10679
10670
  const nodeValue = node.nodeValue;
10680
- if (opts.removeHtmlComments) {
10681
- const isHydrateAnnotation = (nodeValue == null ? void 0 : nodeValue.startsWith(CONTENT_REF_ID + ".")) || (nodeValue == null ? void 0 : nodeValue.startsWith(ORG_LOCATION_ID + ".")) || (nodeValue == null ? void 0 : nodeValue.startsWith(SLOT_NODE_ID + ".")) || (nodeValue == null ? void 0 : nodeValue.startsWith(TEXT_NODE_ID + "."));
10682
- if (!isHydrateAnnotation) {
10683
- return;
10684
- }
10671
+ const isHydrateAnnotation = (nodeValue == null ? void 0 : nodeValue.startsWith(CONTENT_REF_ID + ".")) || (nodeValue == null ? void 0 : nodeValue.startsWith(ORG_LOCATION_ID + ".")) || (nodeValue == null ? void 0 : nodeValue.startsWith(SLOT_NODE_ID + ".")) || (nodeValue == null ? void 0 : nodeValue.startsWith(TEXT_NODE_ID + "."));
10672
+ if (opts.removeHtmlComments && !isHydrateAnnotation) {
10673
+ return;
10685
10674
  }
10686
10675
  const isWithinWhitespaceSensitiveNode = opts.newLines || ((_o = opts.indentSpaces) != null ? _o : 0) > 0 ? isWithinWhitespaceSensitive(node) : false;
10687
10676
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
10688
- output.text.push("\n");
10677
+ yield "\n";
10689
10678
  output.currentLineWidth = 0;
10690
10679
  }
10691
10680
  if (((_p = opts.indentSpaces) != null ? _p : 0) > 0 && !isWithinWhitespaceSensitiveNode) {
10692
10681
  for (let i = 0; i < output.indent; i++) {
10693
- output.text.push(" ");
10682
+ yield " ";
10694
10683
  }
10695
10684
  output.currentLineWidth += output.indent;
10696
10685
  }
10697
- output.text.push("<!--" + nodeValue + "-->");
10698
- output.currentLineWidth += nodeValue.length + 7;
10686
+ yield "<!--" + nodeValue + "-->";
10687
+ if (nodeValue) {
10688
+ output.currentLineWidth += nodeValue.length + 7;
10689
+ }
10699
10690
  } else if (node.nodeType === 10 /* DOCUMENT_TYPE_NODE */) {
10700
- output.text.push("<!doctype html>");
10691
+ yield "<!doctype html>";
10701
10692
  }
10702
10693
  }
10703
10694
  var AMP_REGEX = /&/g;
@@ -10722,7 +10713,7 @@ function escapeString(str, attrMode) {
10722
10713
  }
10723
10714
  function isWithinWhitespaceSensitive(node) {
10724
10715
  let _node = node;
10725
- while (_node != null) {
10716
+ while (_node == null ? void 0 : _node.nodeName) {
10726
10717
  if (WHITESPACE_SENSITIVE.has(_node.nodeName)) {
10727
10718
  return true;
10728
10719
  }
@@ -11038,6 +11029,10 @@ Testing components with ElementInternals is fully supported in e2e tests.`
11038
11029
  get shadowRoot() {
11039
11030
  return this.__shadowRoot || null;
11040
11031
  }
11032
+ /**
11033
+ * Set shadow root for element
11034
+ * @param shadowRoot - ShadowRoot to set
11035
+ */
11041
11036
  set shadowRoot(shadowRoot) {
11042
11037
  if (shadowRoot != null) {
11043
11038
  shadowRoot.host = this;
@@ -12824,14 +12819,16 @@ var WINDOW_PROPS = [
12824
12819
  ];
12825
12820
  var GLOBAL_CONSTRUCTORS = [
12826
12821
  ["CustomEvent", MockCustomEvent],
12822
+ ["DocumentFragment", MockDocumentFragment],
12823
+ ["DOMParser", MockDOMParser],
12827
12824
  ["Event", MockEvent],
12828
- ["Headers", MockHeaders],
12829
12825
  ["FocusEvent", MockFocusEvent],
12826
+ ["Headers", MockHeaders],
12830
12827
  ["KeyboardEvent", MockKeyboardEvent],
12831
12828
  ["MouseEvent", MockMouseEvent],
12832
12829
  ["Request", MockRequest],
12833
12830
  ["Response", MockResponse],
12834
- ["DOMParser", MockDOMParser],
12831
+ ["ShadowRoot", MockDocumentFragment],
12835
12832
  ["HTMLAnchorElement", MockAnchorElement],
12836
12833
  ["HTMLBaseElement", MockBaseElement],
12837
12834
  ["HTMLButtonElement", MockButtonElement],
@@ -13042,6 +13039,7 @@ var nativeClearTimeout = clearTimeout;
13042
13039
  var nativeSetInterval = setInterval;
13043
13040
  var nativeSetTimeout = setTimeout;
13044
13041
  var nativeURL = URL;
13042
+ var nativeWindow = globalThis.window;
13045
13043
  var MockWindow = class {
13046
13044
  constructor(html = null) {
13047
13045
  if (html !== false) {
@@ -13068,10 +13066,10 @@ var MockWindow = class {
13068
13066
  blur() {
13069
13067
  }
13070
13068
  cancelAnimationFrame(id) {
13071
- this.__clearTimeout(id);
13069
+ this.__clearTimeout.call(nativeWindow || this, id);
13072
13070
  }
13073
13071
  cancelIdleCallback(id) {
13074
- this.__clearTimeout(id);
13072
+ this.__clearTimeout.call(nativeWindow || this, id);
13075
13073
  }
13076
13074
  get CharacterData() {
13077
13075
  if (this.__charDataCstr == null) {
@@ -13089,10 +13087,10 @@ var MockWindow = class {
13089
13087
  this.__charDataCstr = charDataCstr;
13090
13088
  }
13091
13089
  clearInterval(id) {
13092
- this.__clearInterval(id);
13090
+ this.__clearInterval.call(nativeWindow || this, id);
13093
13091
  }
13094
13092
  clearTimeout(id) {
13095
- this.__clearTimeout(id);
13093
+ this.__clearTimeout.call(nativeWindow || this, id);
13096
13094
  }
13097
13095
  close() {
13098
13096
  resetWindow(this);
@@ -13392,20 +13390,24 @@ var MockWindow = class {
13392
13390
  }
13393
13391
  return intervalId;
13394
13392
  }
13395
- const timeoutId = this.__setTimeout(() => {
13396
- if (this.__timeouts) {
13397
- this.__timeouts.delete(timeoutId);
13398
- try {
13399
- callback(...args);
13400
- } catch (e) {
13401
- if (this.console) {
13402
- this.console.error(e);
13403
- } else {
13404
- console.error(e);
13393
+ const timeoutId = this.__setTimeout.call(
13394
+ nativeWindow || this,
13395
+ () => {
13396
+ if (this.__timeouts) {
13397
+ this.__timeouts.delete(timeoutId);
13398
+ try {
13399
+ callback(...args);
13400
+ } catch (e) {
13401
+ if (this.console) {
13402
+ this.console.error(e);
13403
+ } else {
13404
+ console.error(e);
13405
+ }
13405
13406
  }
13406
13407
  }
13407
- }
13408
- }, ms);
13408
+ },
13409
+ ms
13410
+ );
13409
13411
  if (this.__timeouts) {
13410
13412
  this.__timeouts.add(timeoutId);
13411
13413
  }
@@ -13416,20 +13418,24 @@ var MockWindow = class {
13416
13418
  this.__timeouts = /* @__PURE__ */ new Set();
13417
13419
  }
13418
13420
  ms = Math.min(ms, this.__maxTimeout);
13419
- const timeoutId = this.__setTimeout(() => {
13420
- if (this.__timeouts) {
13421
- this.__timeouts.delete(timeoutId);
13422
- try {
13423
- callback(...args);
13424
- } catch (e) {
13425
- if (this.console) {
13426
- this.console.error(e);
13427
- } else {
13428
- console.error(e);
13421
+ const timeoutId = this.__setTimeout.call(
13422
+ nativeWindow || this,
13423
+ () => {
13424
+ if (this.__timeouts) {
13425
+ this.__timeouts.delete(timeoutId);
13426
+ try {
13427
+ callback(...args);
13428
+ } catch (e) {
13429
+ if (this.console) {
13430
+ this.console.error(e);
13431
+ } else {
13432
+ console.error(e);
13433
+ }
13429
13434
  }
13430
13435
  }
13431
- }
13432
- }, ms);
13436
+ },
13437
+ ms
13438
+ );
13433
13439
  if (this.__timeouts) {
13434
13440
  this.__timeouts.add(timeoutId);
13435
13441
  }
@@ -14003,11 +14009,11 @@ function createWindowFromHtml(templateHtml, uniqueId) {
14003
14009
  }
14004
14010
 
14005
14011
  // src/hydrate/runner/render.ts
14012
+ import { Readable } from "stream";
14006
14013
  import { hydrateFactory } from "@stencil/core/hydrate-factory";
14007
14014
 
14008
14015
  // src/utils/helpers.ts
14009
14016
  var isString = (v) => typeof v === "string";
14010
- var isPromise = (v) => !!v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function";
14011
14017
 
14012
14018
  // src/utils/message-utils.ts
14013
14019
  var catchError = (diagnostics, err2, msg) => {
@@ -14098,6 +14104,7 @@ var unwrapErr = (result) => {
14098
14104
 
14099
14105
  // src/compiler/html/canonical-link.ts
14100
14106
  var updateCanonicalLink = (doc, href) => {
14107
+ var _a2;
14101
14108
  let canonicalLinkElm = doc.head.querySelector('link[rel="canonical"]');
14102
14109
  if (typeof href === "string") {
14103
14110
  if (canonicalLinkElm == null) {
@@ -14110,7 +14117,7 @@ var updateCanonicalLink = (doc, href) => {
14110
14117
  if (canonicalLinkElm != null) {
14111
14118
  const existingHref = canonicalLinkElm.getAttribute("href");
14112
14119
  if (!existingHref) {
14113
- canonicalLinkElm.parentNode.removeChild(canonicalLinkElm);
14120
+ (_a2 = canonicalLinkElm.parentNode) == null ? void 0 : _a2.removeChild(canonicalLinkElm);
14114
14121
  }
14115
14122
  }
14116
14123
  }
@@ -15144,10 +15151,10 @@ function renderBuildDiagnostic(results, level, header, msg) {
15144
15151
  return diagnostic;
15145
15152
  }
15146
15153
  function renderBuildError(results, msg) {
15147
- return renderBuildDiagnostic(results, "error", "Hydrate Error", msg);
15154
+ return renderBuildDiagnostic(results, "error", "Hydrate Error", msg || "");
15148
15155
  }
15149
15156
  function renderCatchError(results, err2) {
15150
- const diagnostic = renderBuildError(results, null);
15157
+ const diagnostic = renderBuildError(results);
15151
15158
  if (err2 != null) {
15152
15159
  if (err2.stack != null) {
15153
15160
  diagnostic.messageText = err2.stack.toString();
@@ -15209,10 +15216,11 @@ function runtimeLog(pathname, type, msgs) {
15209
15216
 
15210
15217
  // src/hydrate/runner/window-initialize.ts
15211
15218
  function initializeWindow(win, doc, opts, results) {
15212
- try {
15213
- win.location.href = opts.url;
15214
- } catch (e) {
15215
- renderCatchError(results, e);
15219
+ if (typeof opts.url === "string") {
15220
+ try {
15221
+ win.location.href = opts.url;
15222
+ } catch (e) {
15223
+ }
15216
15224
  }
15217
15225
  if (typeof opts.userAgent === "string") {
15218
15226
  try {
@@ -15262,134 +15270,99 @@ function initializeWindow(win, doc, opts, results) {
15262
15270
  }
15263
15271
 
15264
15272
  // src/hydrate/runner/render.ts
15265
- function renderToString(html, options) {
15273
+ var NOOP = () => {
15274
+ };
15275
+ function streamToString(html, option) {
15276
+ return renderToString(html, option, true);
15277
+ }
15278
+ function renderToString(html, options, asStream) {
15266
15279
  const opts = normalizeHydrateOptions(options);
15267
15280
  opts.serializeToHtml = true;
15268
- return new Promise((resolve) => {
15269
- let win;
15270
- const results = generateHydrateResults(opts);
15271
- if (hasError(results.diagnostics)) {
15272
- resolve(results);
15273
- } else if (typeof html === "string") {
15274
- try {
15275
- opts.destroyWindow = true;
15276
- opts.destroyDocument = true;
15277
- win = new MockWindow(html);
15278
- render(win, opts, results, resolve);
15279
- } catch (e) {
15280
- if (win && win.close) {
15281
- win.close();
15282
- }
15283
- win = null;
15284
- renderCatchError(results, e);
15285
- resolve(results);
15281
+ opts.fullDocument = typeof opts.fullDocument === "boolean" ? opts.fullDocument : true;
15282
+ opts.serializeShadowRoot = Boolean(opts.serializeShadowRoot);
15283
+ opts.constrainTimeouts = false;
15284
+ return hydrateDocument(html, opts, asStream);
15285
+ }
15286
+ function hydrateDocument(doc, options, asStream) {
15287
+ const opts = normalizeHydrateOptions(options);
15288
+ let win = null;
15289
+ const results = generateHydrateResults(opts);
15290
+ if (hasError(results.diagnostics)) {
15291
+ return Promise.resolve(results);
15292
+ }
15293
+ if (typeof doc === "string") {
15294
+ try {
15295
+ opts.destroyWindow = true;
15296
+ opts.destroyDocument = true;
15297
+ win = new MockWindow(doc);
15298
+ if (!asStream) {
15299
+ return render(win, opts, results).then(() => results);
15286
15300
  }
15287
- } else if (isValidDocument(html)) {
15288
- try {
15289
- opts.destroyDocument = false;
15290
- win = patchDomImplementation(html, opts);
15291
- render(win, opts, results, resolve);
15292
- } catch (e) {
15293
- if (win && win.close) {
15294
- win.close();
15295
- }
15296
- win = null;
15297
- renderCatchError(results, e);
15298
- resolve(results);
15301
+ return renderStream(win, opts, results);
15302
+ } catch (e) {
15303
+ if (win && win.close) {
15304
+ win.close();
15299
15305
  }
15300
- } else {
15301
- renderBuildError(results, `Invalid html or document. Must be either a valid "html" string, or DOM "document".`);
15302
- resolve(results);
15306
+ win = null;
15307
+ renderCatchError(results, e);
15308
+ return Promise.resolve(results);
15303
15309
  }
15304
- });
15305
- }
15306
- function hydrateDocument(doc, options) {
15307
- const opts = normalizeHydrateOptions(options);
15308
- opts.serializeToHtml = false;
15309
- return new Promise((resolve) => {
15310
- let win;
15311
- const results = generateHydrateResults(opts);
15312
- if (hasError(results.diagnostics)) {
15313
- resolve(results);
15314
- } else if (typeof doc === "string") {
15315
- try {
15316
- opts.destroyWindow = true;
15317
- opts.destroyDocument = true;
15318
- win = new MockWindow(doc);
15319
- render(win, opts, results, resolve);
15320
- } catch (e) {
15321
- if (win && win.close) {
15322
- win.close();
15323
- }
15324
- win = null;
15325
- renderCatchError(results, e);
15326
- resolve(results);
15310
+ }
15311
+ if (isValidDocument(doc)) {
15312
+ try {
15313
+ opts.destroyDocument = false;
15314
+ win = patchDomImplementation(doc, opts);
15315
+ if (!asStream) {
15316
+ return render(win, opts, results).then(() => results);
15327
15317
  }
15328
- } else if (isValidDocument(doc)) {
15329
- try {
15330
- opts.destroyDocument = false;
15331
- win = patchDomImplementation(doc, opts);
15332
- render(win, opts, results, resolve);
15333
- } catch (e) {
15334
- if (win && win.close) {
15335
- win.close();
15336
- }
15337
- win = null;
15338
- renderCatchError(results, e);
15339
- resolve(results);
15318
+ return renderStream(win, opts, results);
15319
+ } catch (e) {
15320
+ if (win && win.close) {
15321
+ win.close();
15340
15322
  }
15341
- } else {
15342
- renderBuildError(results, `Invalid html or document. Must be either a valid "html" string, or DOM "document".`);
15343
- resolve(results);
15323
+ win = null;
15324
+ renderCatchError(results, e);
15325
+ return Promise.resolve(results);
15344
15326
  }
15345
- });
15327
+ }
15328
+ renderBuildError(results, `Invalid html or document. Must be either a valid "html" string, or DOM "document".`);
15329
+ return Promise.resolve(results);
15346
15330
  }
15347
- function render(win, opts, results, resolve) {
15348
- if (!process.__stencilErrors) {
15331
+ async function render(win, opts, results) {
15332
+ if ("process" in globalThis && typeof process.on === "function" && !process.__stencilErrors) {
15349
15333
  process.__stencilErrors = true;
15350
15334
  process.on("unhandledRejection", (e) => {
15351
15335
  console.log("unhandledRejection", e);
15352
15336
  });
15353
15337
  }
15354
15338
  initializeWindow(win, win.document, opts, results);
15355
- if (typeof opts.beforeHydrate === "function") {
15356
- try {
15357
- const rtn = opts.beforeHydrate(win.document);
15358
- if (isPromise(rtn)) {
15359
- rtn.then(() => {
15360
- hydrateFactory(win, opts, results, afterHydrate, resolve);
15361
- });
15362
- } else {
15363
- hydrateFactory(win, opts, results, afterHydrate, resolve);
15364
- }
15365
- } catch (e) {
15366
- renderCatchError(results, e);
15367
- finalizeHydrate(win, win.document, opts, results, resolve);
15368
- }
15369
- } else {
15370
- hydrateFactory(win, opts, results, afterHydrate, resolve);
15339
+ const beforeHydrateFn = typeof opts.beforeHydrate === "function" ? opts.beforeHydrate(win.document) : NOOP;
15340
+ try {
15341
+ await Promise.resolve(beforeHydrateFn(win.document));
15342
+ return new Promise((resolve) => hydrateFactory(win, opts, results, afterHydrate, resolve));
15343
+ } catch (e) {
15344
+ renderCatchError(results, e);
15345
+ return finalizeHydrate(win, win.document, opts, results);
15371
15346
  }
15372
15347
  }
15373
- function afterHydrate(win, opts, results, resolve) {
15374
- if (typeof opts.afterHydrate === "function") {
15375
- try {
15376
- const rtn = opts.afterHydrate(win.document);
15377
- if (isPromise(rtn)) {
15378
- rtn.then(() => {
15379
- finalizeHydrate(win, win.document, opts, results, resolve);
15380
- });
15381
- } else {
15382
- finalizeHydrate(win, win.document, opts, results, resolve);
15383
- }
15384
- } catch (e) {
15385
- renderCatchError(results, e);
15386
- finalizeHydrate(win, win.document, opts, results, resolve);
15387
- }
15388
- } else {
15389
- finalizeHydrate(win, win.document, opts, results, resolve);
15348
+ function renderStream(win, opts, results) {
15349
+ async function* processRender() {
15350
+ const renderResult = await render(win, opts, results);
15351
+ yield renderResult.html;
15390
15352
  }
15353
+ return Readable.from(processRender());
15391
15354
  }
15392
- function finalizeHydrate(win, doc, opts, results, resolve) {
15355
+ async function afterHydrate(win, opts, results, resolve) {
15356
+ const afterHydrateFn = typeof opts.afterHydrate === "function" ? opts.afterHydrate(win.document) : NOOP;
15357
+ try {
15358
+ await Promise.resolve(afterHydrateFn(win.document));
15359
+ return resolve(finalizeHydrate(win, win.document, opts, results));
15360
+ } catch (e) {
15361
+ renderCatchError(results, e);
15362
+ return resolve(finalizeHydrate(win, win.document, opts, results));
15363
+ }
15364
+ }
15365
+ function finalizeHydrate(win, doc, opts, results) {
15393
15366
  try {
15394
15367
  inspectElement(results, doc.documentElement, 0);
15395
15368
  if (opts.removeUnusedStyles !== false) {
@@ -15441,20 +15414,24 @@ function finalizeHydrate(win, doc, opts, results, resolve) {
15441
15414
  } catch (e) {
15442
15415
  renderCatchError(results, e);
15443
15416
  }
15444
- if (opts.destroyWindow) {
15445
- try {
15446
- if (!opts.destroyDocument) {
15447
- win.document = null;
15448
- doc.defaultView = null;
15449
- }
15450
- if (win.close) {
15451
- win.close();
15452
- }
15453
- } catch (e) {
15454
- renderCatchError(results, e);
15417
+ destroyWindow(win, doc, opts, results);
15418
+ return results;
15419
+ }
15420
+ function destroyWindow(win, doc, opts, results) {
15421
+ if (!opts.destroyWindow) {
15422
+ return;
15423
+ }
15424
+ try {
15425
+ if (!opts.destroyDocument) {
15426
+ win.document = null;
15427
+ doc.defaultView = null;
15428
+ }
15429
+ if (win.close) {
15430
+ win.close();
15455
15431
  }
15432
+ } catch (e) {
15433
+ renderCatchError(results, e);
15456
15434
  }
15457
- resolve(results);
15458
15435
  }
15459
15436
  function serializeDocumentToString(doc, opts) {
15460
15437
  return serializeNodeToHtml(doc, {
@@ -15465,7 +15442,8 @@ function serializeDocumentToString(doc, opts) {
15465
15442
  removeBooleanAttributeQuotes: opts.removeBooleanAttributeQuotes,
15466
15443
  removeEmptyAttributes: opts.removeEmptyAttributes,
15467
15444
  removeHtmlComments: opts.removeHtmlComments,
15468
- serializeShadowRoot: false
15445
+ serializeShadowRoot: opts.serializeShadowRoot,
15446
+ fullDocument: opts.fullDocument
15469
15447
  });
15470
15448
  }
15471
15449
  function isValidDocument(doc) {
@@ -15485,5 +15463,6 @@ export {
15485
15463
  createWindowFromHtml,
15486
15464
  hydrateDocument,
15487
15465
  renderToString,
15488
- serializeDocumentToString
15466
+ serializeDocumentToString,
15467
+ streamToString
15489
15468
  };