@stencil/core 4.18.3-dev.1718220868.532557e → 4.18.3-dev.1718341300.87e5b33

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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Stencil Hydrate Runner v4.18.3-dev.1718220868.532557e | MIT Licensed | https://stenciljs.com
2
+ Stencil Hydrate Runner v4.18.3-dev.1718341300.87e5b33 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  var __defProp = Object.defineProperty;
5
5
  var __export = (target, all) => {
@@ -10397,50 +10397,67 @@ function humanReadableList(items) {
10397
10397
  }
10398
10398
 
10399
10399
  // src/mock-doc/serialize-node.ts
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);
10400
+ function serializeNodeToHtml(elm, opts = {}) {
10423
10401
  const output = {
10424
10402
  currentLineWidth: 0,
10425
10403
  indent: 0,
10426
10404
  isWithinBody: false,
10427
10405
  text: []
10428
10406
  };
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("");
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();
10435
10451
  }
10436
- return renderedNode.trim();
10452
+ if (output.text[output.text.length - 1] === "\n") {
10453
+ output.text.pop();
10454
+ }
10455
+ return output.text.join("");
10437
10456
  }
10438
- var shadowRootTag = "mock:shadow-root";
10439
- function* streamToHtml(node, opts, output) {
10457
+ function serializeToHtml(node, opts, output, isShadowRoot) {
10440
10458
  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 */;
10442
10459
  if (node.nodeType === 1 /* ELEMENT_NODE */ || isShadowRoot) {
10443
- const tagName = isShadowRoot ? shadowRootTag : getTagName(node);
10460
+ const tagName = isShadowRoot ? "mock:shadow-root" : getTagName(node);
10444
10461
  if (tagName === "body") {
10445
10462
  output.isWithinBody = true;
10446
10463
  }
@@ -10448,23 +10465,17 @@ function* streamToHtml(node, opts, output) {
10448
10465
  if (ignoreTag === false) {
10449
10466
  const isWithinWhitespaceSensitiveNode = opts.newLines || ((_a2 = opts.indentSpaces) != null ? _a2 : 0) > 0 ? isWithinWhitespaceSensitive(node) : false;
10450
10467
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
10451
- yield "\n";
10468
+ output.text.push("\n");
10452
10469
  output.currentLineWidth = 0;
10453
10470
  }
10454
10471
  if (((_b = opts.indentSpaces) != null ? _b : 0) > 0 && !isWithinWhitespaceSensitiveNode) {
10455
10472
  for (let i = 0; i < output.indent; i++) {
10456
- yield " ";
10473
+ output.text.push(" ");
10457
10474
  }
10458
10475
  output.currentLineWidth += output.indent;
10459
10476
  }
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
- }
10477
+ output.text.push("<" + tagName);
10478
+ output.currentLineWidth += tagName.length + 1;
10468
10479
  const attrsLength = node.attributes.length;
10469
10480
  const attributes = opts.prettyHtml && attrsLength > 1 ? cloneAttributes(node.attributes, true) : node.attributes;
10470
10481
  for (let i = 0; i < attrsLength; i++) {
@@ -10481,27 +10492,27 @@ function* streamToHtml(node, opts, output) {
10481
10492
  if (attrNamespaceURI == null) {
10482
10493
  output.currentLineWidth += attrName.length + 1;
10483
10494
  if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth > opts.approximateLineWidth) {
10484
- yield "\n" + attrName;
10495
+ output.text.push("\n" + attrName);
10485
10496
  output.currentLineWidth = 0;
10486
10497
  } else {
10487
- yield " " + attrName;
10498
+ output.text.push(" " + attrName);
10488
10499
  }
10489
10500
  } else if (attrNamespaceURI === "http://www.w3.org/XML/1998/namespace") {
10490
- yield " xml:" + attrName;
10501
+ output.text.push(" xml:" + attrName);
10491
10502
  output.currentLineWidth += attrName.length + 5;
10492
10503
  } else if (attrNamespaceURI === "http://www.w3.org/2000/xmlns/") {
10493
10504
  if (attrName !== "xmlns") {
10494
- yield " xmlns:" + attrName;
10505
+ output.text.push(" xmlns:" + attrName);
10495
10506
  output.currentLineWidth += attrName.length + 7;
10496
10507
  } else {
10497
- yield " " + attrName;
10508
+ output.text.push(" " + attrName);
10498
10509
  output.currentLineWidth += attrName.length + 1;
10499
10510
  }
10500
10511
  } else if (attrNamespaceURI === XLINK_NS) {
10501
- yield " xlink:" + attrName;
10512
+ output.text.push(" xlink:" + attrName);
10502
10513
  output.currentLineWidth += attrName.length + 7;
10503
10514
  } else {
10504
- yield " " + attrNamespaceURI + ":" + attrName;
10515
+ output.text.push(" " + attrNamespaceURI + ":" + attrName);
10505
10516
  output.currentLineWidth += attrNamespaceURI.length + attrName.length + 2;
10506
10517
  }
10507
10518
  if (opts.prettyHtml && attrName === "class") {
@@ -10516,45 +10527,43 @@ function* streamToHtml(node, opts, output) {
10516
10527
  }
10517
10528
  }
10518
10529
  if (opts.removeAttributeQuotes && CAN_REMOVE_ATTR_QUOTES.test(attrValue)) {
10519
- yield "=" + escapeString(attrValue, true);
10530
+ output.text.push("=" + escapeString(attrValue, true));
10520
10531
  output.currentLineWidth += attrValue.length + 1;
10521
10532
  } else {
10522
- yield '="' + escapeString(attrValue, true) + '"';
10533
+ output.text.push('="' + escapeString(attrValue, true) + '"');
10523
10534
  output.currentLineWidth += attrValue.length + 3;
10524
10535
  }
10525
10536
  }
10526
10537
  if (node.hasAttribute("style")) {
10527
10538
  const cssText = node.style.cssText;
10528
10539
  if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth + cssText.length + 10 > opts.approximateLineWidth) {
10529
- yield `
10530
- style="${cssText}">`;
10540
+ output.text.push(`
10541
+ style="${cssText}">`);
10531
10542
  output.currentLineWidth = 0;
10532
10543
  } else {
10533
- yield ` style="${cssText}">`;
10544
+ output.text.push(` style="${cssText}">`);
10534
10545
  output.currentLineWidth += cssText.length + 10;
10535
10546
  }
10536
10547
  } else {
10537
- yield ">";
10548
+ output.text.push(">");
10538
10549
  output.currentLineWidth += 1;
10539
10550
  }
10540
10551
  }
10541
10552
  if (EMPTY_ELEMENTS.has(tagName) === false) {
10542
- const shadowRoot = node.shadowRoot;
10543
- if (opts.serializeShadowRoot && shadowRoot != null) {
10553
+ if (opts.serializeShadowRoot && node.shadowRoot != null) {
10544
10554
  output.indent = output.indent + ((_c = opts.indentSpaces) != null ? _c : 0);
10545
- yield* streamToHtml(shadowRoot, opts, output);
10555
+ serializeToHtml(node.shadowRoot, opts, output, true);
10546
10556
  output.indent = output.indent - ((_d = opts.indentSpaces) != null ? _d : 0);
10547
10557
  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()) === "")) {
10548
- yield "\n";
10558
+ output.text.push("\n");
10549
10559
  output.currentLineWidth = 0;
10550
10560
  for (let i = 0; i < output.indent; i++) {
10551
- yield " ";
10561
+ output.text.push(" ");
10552
10562
  }
10553
10563
  output.currentLineWidth += output.indent;
10554
10564
  }
10555
10565
  }
10556
10566
  if (opts.excludeTagContent == null || opts.excludeTagContent.includes(tagName) === false) {
10557
- const tag = tagName === shadowRootTag ? "template" : tagName;
10558
10567
  const childNodes = tagName === "template" ? node.content.childNodes : node.childNodes;
10559
10568
  const childNodeLength = childNodes.length;
10560
10569
  if (childNodeLength > 0) {
@@ -10565,17 +10574,17 @@ style="${cssText}">`;
10565
10574
  output.indent = output.indent + ((_h = opts.indentSpaces) != null ? _h : 0);
10566
10575
  }
10567
10576
  for (let i = 0; i < childNodeLength; i++) {
10568
- yield* streamToHtml(childNodes[i], opts, output);
10577
+ serializeToHtml(childNodes[i], opts, output, false);
10569
10578
  }
10570
10579
  if (ignoreTag === false) {
10571
10580
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
10572
- yield "\n";
10581
+ output.text.push("\n");
10573
10582
  output.currentLineWidth = 0;
10574
10583
  }
10575
10584
  if (((_i = opts.indentSpaces) != null ? _i : 0) > 0 && !isWithinWhitespaceSensitiveNode) {
10576
10585
  output.indent = output.indent - ((_j = opts.indentSpaces) != null ? _j : 0);
10577
10586
  for (let i = 0; i < output.indent; i++) {
10578
- yield " ";
10587
+ output.text.push(" ");
10579
10588
  }
10580
10589
  output.currentLineWidth += output.indent;
10581
10590
  }
@@ -10583,13 +10592,13 @@ style="${cssText}">`;
10583
10592
  }
10584
10593
  }
10585
10594
  if (ignoreTag === false) {
10586
- yield "</" + tag + ">";
10587
- output.currentLineWidth += tag.length + 3;
10595
+ output.text.push("</" + tagName + ">");
10596
+ output.currentLineWidth += tagName.length + 3;
10588
10597
  }
10589
10598
  }
10590
10599
  }
10591
10600
  if (((_k = opts.approximateLineWidth) != null ? _k : 0) > 0 && STRUCTURE_ELEMENTS.has(tagName)) {
10592
- yield "\n";
10601
+ output.text.push("\n");
10593
10602
  output.currentLineWidth = 0;
10594
10603
  }
10595
10604
  if (tagName === "body") {
@@ -10601,27 +10610,27 @@ style="${cssText}">`;
10601
10610
  const trimmedTextContent = textContent.trim();
10602
10611
  if (trimmedTextContent === "") {
10603
10612
  if (isWithinWhitespaceSensitive(node)) {
10604
- yield textContent;
10613
+ output.text.push(textContent);
10605
10614
  output.currentLineWidth += textContent.length;
10606
10615
  } else if (((_l = opts.approximateLineWidth) != null ? _l : 0) > 0 && !output.isWithinBody) {
10607
10616
  } else if (!opts.prettyHtml) {
10608
10617
  output.currentLineWidth += 1;
10609
10618
  if (opts.approximateLineWidth && opts.approximateLineWidth > 0 && output.currentLineWidth > opts.approximateLineWidth) {
10610
- yield "\n";
10619
+ output.text.push("\n");
10611
10620
  output.currentLineWidth = 0;
10612
10621
  } else {
10613
- yield " ";
10622
+ output.text.push(" ");
10614
10623
  }
10615
10624
  }
10616
10625
  } else {
10617
10626
  const isWithinWhitespaceSensitiveNode = opts.newLines || ((_m = opts.indentSpaces) != null ? _m : 0) > 0 || opts.prettyHtml ? isWithinWhitespaceSensitive(node) : false;
10618
10627
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
10619
- yield "\n";
10628
+ output.text.push("\n");
10620
10629
  output.currentLineWidth = 0;
10621
10630
  }
10622
10631
  if (((_n = opts.indentSpaces) != null ? _n : 0) > 0 && !isWithinWhitespaceSensitiveNode) {
10623
10632
  for (let i = 0; i < output.indent; i++) {
10624
- yield " ";
10633
+ output.text.push(" ");
10625
10634
  }
10626
10635
  output.currentLineWidth += output.indent;
10627
10636
  }
@@ -10630,15 +10639,15 @@ style="${cssText}">`;
10630
10639
  const parentTagName = node.parentNode != null && node.parentNode.nodeType === 1 /* ELEMENT_NODE */ ? node.parentNode.nodeName : null;
10631
10640
  if (typeof parentTagName === "string" && NON_ESCAPABLE_CONTENT.has(parentTagName)) {
10632
10641
  if (isWithinWhitespaceSensitive(node)) {
10633
- yield textContent;
10642
+ output.text.push(textContent);
10634
10643
  } else {
10635
- yield trimmedTextContent;
10644
+ output.text.push(trimmedTextContent);
10636
10645
  textContentLength = trimmedTextContent.length;
10637
10646
  }
10638
10647
  output.currentLineWidth += textContentLength;
10639
10648
  } else {
10640
10649
  if (opts.prettyHtml && !isWithinWhitespaceSensitiveNode) {
10641
- yield escapeString(textContent.replace(/\s\s+/g, " ").trim(), false);
10650
+ output.text.push(escapeString(textContent.replace(/\s\s+/g, " ").trim(), false));
10642
10651
  output.currentLineWidth += textContentLength;
10643
10652
  } else {
10644
10653
  if (isWithinWhitespaceSensitive(node)) {
@@ -10660,7 +10669,7 @@ style="${cssText}">`;
10660
10669
  }
10661
10670
  output.currentLineWidth += textContentLength;
10662
10671
  }
10663
- yield escapeString(textContent, false);
10672
+ output.text.push(escapeString(textContent, false));
10664
10673
  }
10665
10674
  }
10666
10675
  }
@@ -10668,25 +10677,27 @@ style="${cssText}">`;
10668
10677
  }
10669
10678
  } else if (node.nodeType === 8 /* COMMENT_NODE */) {
10670
10679
  const nodeValue = node.nodeValue;
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;
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
+ }
10674
10685
  }
10675
10686
  const isWithinWhitespaceSensitiveNode = opts.newLines || ((_o = opts.indentSpaces) != null ? _o : 0) > 0 ? isWithinWhitespaceSensitive(node) : false;
10676
10687
  if (opts.newLines && !isWithinWhitespaceSensitiveNode) {
10677
- yield "\n";
10688
+ output.text.push("\n");
10678
10689
  output.currentLineWidth = 0;
10679
10690
  }
10680
10691
  if (((_p = opts.indentSpaces) != null ? _p : 0) > 0 && !isWithinWhitespaceSensitiveNode) {
10681
10692
  for (let i = 0; i < output.indent; i++) {
10682
- yield " ";
10693
+ output.text.push(" ");
10683
10694
  }
10684
10695
  output.currentLineWidth += output.indent;
10685
10696
  }
10686
- yield "<!--" + nodeValue + "-->";
10697
+ output.text.push("<!--" + nodeValue + "-->");
10687
10698
  output.currentLineWidth += nodeValue.length + 7;
10688
10699
  } else if (node.nodeType === 10 /* DOCUMENT_TYPE_NODE */) {
10689
- yield "<!doctype html>";
10700
+ output.text.push("<!doctype html>");
10690
10701
  }
10691
10702
  }
10692
10703
  var AMP_REGEX = /&/g;
@@ -11027,10 +11038,6 @@ Testing components with ElementInternals is fully supported in e2e tests.`
11027
11038
  get shadowRoot() {
11028
11039
  return this.__shadowRoot || null;
11029
11040
  }
11030
- /**
11031
- * Set shadow root for element
11032
- * @param shadowRoot - ShadowRoot to set
11033
- */
11034
11041
  set shadowRoot(shadowRoot) {
11035
11042
  if (shadowRoot != null) {
11036
11043
  shadowRoot.host = this;
@@ -12817,14 +12824,16 @@ var WINDOW_PROPS = [
12817
12824
  ];
12818
12825
  var GLOBAL_CONSTRUCTORS = [
12819
12826
  ["CustomEvent", MockCustomEvent],
12827
+ ["DocumentFragment", MockDocumentFragment],
12828
+ ["DOMParser", MockDOMParser],
12820
12829
  ["Event", MockEvent],
12821
- ["Headers", MockHeaders],
12822
12830
  ["FocusEvent", MockFocusEvent],
12831
+ ["Headers", MockHeaders],
12823
12832
  ["KeyboardEvent", MockKeyboardEvent],
12824
12833
  ["MouseEvent", MockMouseEvent],
12825
12834
  ["Request", MockRequest],
12826
12835
  ["Response", MockResponse],
12827
- ["DOMParser", MockDOMParser],
12836
+ ["ShadowRoot", MockDocumentFragment],
12828
12837
  ["HTMLAnchorElement", MockAnchorElement],
12829
12838
  ["HTMLBaseElement", MockBaseElement],
12830
12839
  ["HTMLButtonElement", MockButtonElement],
@@ -13035,7 +13044,6 @@ var nativeClearTimeout = clearTimeout;
13035
13044
  var nativeSetInterval = setInterval;
13036
13045
  var nativeSetTimeout = setTimeout;
13037
13046
  var nativeURL = URL;
13038
- var nativeWindow = globalThis.window;
13039
13047
  var MockWindow = class {
13040
13048
  constructor(html = null) {
13041
13049
  if (html !== false) {
@@ -13062,10 +13070,10 @@ var MockWindow = class {
13062
13070
  blur() {
13063
13071
  }
13064
13072
  cancelAnimationFrame(id) {
13065
- this.__clearTimeout.call(nativeWindow || this, id);
13073
+ this.__clearTimeout(id);
13066
13074
  }
13067
13075
  cancelIdleCallback(id) {
13068
- this.__clearTimeout.call(nativeWindow || this, id);
13076
+ this.__clearTimeout(id);
13069
13077
  }
13070
13078
  get CharacterData() {
13071
13079
  if (this.__charDataCstr == null) {
@@ -13083,10 +13091,10 @@ var MockWindow = class {
13083
13091
  this.__charDataCstr = charDataCstr;
13084
13092
  }
13085
13093
  clearInterval(id) {
13086
- this.__clearInterval.call(nativeWindow || this, id);
13094
+ this.__clearInterval(id);
13087
13095
  }
13088
13096
  clearTimeout(id) {
13089
- this.__clearTimeout.call(nativeWindow || this, id);
13097
+ this.__clearTimeout(id);
13090
13098
  }
13091
13099
  close() {
13092
13100
  resetWindow(this);
@@ -13386,24 +13394,20 @@ var MockWindow = class {
13386
13394
  }
13387
13395
  return intervalId;
13388
13396
  }
13389
- const timeoutId = this.__setTimeout.call(
13390
- nativeWindow || this,
13391
- () => {
13392
- if (this.__timeouts) {
13393
- this.__timeouts.delete(timeoutId);
13394
- try {
13395
- callback(...args);
13396
- } catch (e) {
13397
- if (this.console) {
13398
- this.console.error(e);
13399
- } else {
13400
- console.error(e);
13401
- }
13397
+ const timeoutId = this.__setTimeout(() => {
13398
+ if (this.__timeouts) {
13399
+ this.__timeouts.delete(timeoutId);
13400
+ try {
13401
+ callback(...args);
13402
+ } catch (e) {
13403
+ if (this.console) {
13404
+ this.console.error(e);
13405
+ } else {
13406
+ console.error(e);
13402
13407
  }
13403
13408
  }
13404
- },
13405
- ms
13406
- );
13409
+ }
13410
+ }, ms);
13407
13411
  if (this.__timeouts) {
13408
13412
  this.__timeouts.add(timeoutId);
13409
13413
  }
@@ -13414,24 +13418,20 @@ var MockWindow = class {
13414
13418
  this.__timeouts = /* @__PURE__ */ new Set();
13415
13419
  }
13416
13420
  ms = Math.min(ms, this.__maxTimeout);
13417
- const timeoutId = this.__setTimeout.call(
13418
- nativeWindow || this,
13419
- () => {
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);
13429
- }
13421
+ const timeoutId = this.__setTimeout(() => {
13422
+ if (this.__timeouts) {
13423
+ this.__timeouts.delete(timeoutId);
13424
+ try {
13425
+ callback(...args);
13426
+ } catch (e) {
13427
+ if (this.console) {
13428
+ this.console.error(e);
13429
+ } else {
13430
+ console.error(e);
13430
13431
  }
13431
13432
  }
13432
- },
13433
- ms
13434
- );
13433
+ }
13434
+ }, ms);
13435
13435
  if (this.__timeouts) {
13436
13436
  this.__timeouts.add(timeoutId);
13437
13437
  }
@@ -14005,11 +14005,11 @@ function createWindowFromHtml(templateHtml, uniqueId) {
14005
14005
  }
14006
14006
 
14007
14007
  // src/hydrate/runner/render.ts
14008
- import { Readable } from "stream";
14009
14008
  import { hydrateFactory } from "@stencil/core/hydrate-factory";
14010
14009
 
14011
14010
  // src/utils/helpers.ts
14012
14011
  var isString = (v) => typeof v === "string";
14012
+ var isPromise = (v) => !!v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function";
14013
14013
 
14014
14014
  // src/utils/message-utils.ts
14015
14015
  var catchError = (diagnostics, err2, msg) => {
@@ -15264,99 +15264,134 @@ function initializeWindow(win, doc, opts, results) {
15264
15264
  }
15265
15265
 
15266
15266
  // src/hydrate/runner/render.ts
15267
- var NOOP = () => {
15268
- };
15269
- function streamToString(html, option) {
15270
- return renderToString(html, option, true);
15271
- }
15272
- function renderToString(html, options, asStream) {
15267
+ function renderToString(html, options) {
15273
15268
  const opts = normalizeHydrateOptions(options);
15274
15269
  opts.serializeToHtml = true;
15275
- opts.fullDocument = typeof opts.fullDocument === "boolean" ? opts.fullDocument : true;
15276
- opts.serializeShadowRoot = Boolean(opts.serializeShadowRoot);
15277
- opts.constrainTimeouts = false;
15278
- return hydrateDocument(html, opts, asStream);
15279
- }
15280
- function hydrateDocument(doc, options, asStream) {
15281
- const opts = normalizeHydrateOptions(options);
15282
- let win;
15283
- const results = generateHydrateResults(opts);
15284
- if (hasError(results.diagnostics)) {
15285
- return Promise.resolve(results);
15286
- }
15287
- if (typeof doc === "string") {
15288
- try {
15289
- opts.destroyWindow = true;
15290
- opts.destroyDocument = true;
15291
- win = new MockWindow(doc);
15292
- if (!asStream) {
15293
- return render(win, opts, results).then(() => results);
15270
+ return new Promise((resolve) => {
15271
+ let win;
15272
+ const results = generateHydrateResults(opts);
15273
+ if (hasError(results.diagnostics)) {
15274
+ resolve(results);
15275
+ } else if (typeof html === "string") {
15276
+ try {
15277
+ opts.destroyWindow = true;
15278
+ opts.destroyDocument = true;
15279
+ win = new MockWindow(html);
15280
+ render(win, opts, results, resolve);
15281
+ } catch (e) {
15282
+ if (win && win.close) {
15283
+ win.close();
15284
+ }
15285
+ win = null;
15286
+ renderCatchError(results, e);
15287
+ resolve(results);
15294
15288
  }
15295
- return renderStream(win, opts, results);
15296
- } catch (e) {
15297
- if (win && win.close) {
15298
- win.close();
15289
+ } else if (isValidDocument(html)) {
15290
+ try {
15291
+ opts.destroyDocument = false;
15292
+ win = patchDomImplementation(html, opts);
15293
+ render(win, opts, results, resolve);
15294
+ } catch (e) {
15295
+ if (win && win.close) {
15296
+ win.close();
15297
+ }
15298
+ win = null;
15299
+ renderCatchError(results, e);
15300
+ resolve(results);
15299
15301
  }
15300
- win = null;
15301
- renderCatchError(results, e);
15302
- return Promise.resolve(results);
15302
+ } else {
15303
+ renderBuildError(results, `Invalid html or document. Must be either a valid "html" string, or DOM "document".`);
15304
+ resolve(results);
15303
15305
  }
15304
- }
15305
- if (isValidDocument(doc)) {
15306
- try {
15307
- opts.destroyDocument = false;
15308
- win = patchDomImplementation(doc, opts);
15309
- if (!asStream) {
15310
- return render(win, opts, results).then(() => results);
15306
+ });
15307
+ }
15308
+ function hydrateDocument(doc, options) {
15309
+ const opts = normalizeHydrateOptions(options);
15310
+ opts.serializeToHtml = false;
15311
+ return new Promise((resolve) => {
15312
+ let win;
15313
+ const results = generateHydrateResults(opts);
15314
+ if (hasError(results.diagnostics)) {
15315
+ resolve(results);
15316
+ } else if (typeof doc === "string") {
15317
+ try {
15318
+ opts.destroyWindow = true;
15319
+ opts.destroyDocument = true;
15320
+ win = new MockWindow(doc);
15321
+ render(win, opts, results, resolve);
15322
+ } catch (e) {
15323
+ if (win && win.close) {
15324
+ win.close();
15325
+ }
15326
+ win = null;
15327
+ renderCatchError(results, e);
15328
+ resolve(results);
15311
15329
  }
15312
- return renderStream(win, opts, results);
15313
- } catch (e) {
15314
- if (win && win.close) {
15315
- win.close();
15330
+ } else if (isValidDocument(doc)) {
15331
+ try {
15332
+ opts.destroyDocument = false;
15333
+ win = patchDomImplementation(doc, opts);
15334
+ render(win, opts, results, resolve);
15335
+ } catch (e) {
15336
+ if (win && win.close) {
15337
+ win.close();
15338
+ }
15339
+ win = null;
15340
+ renderCatchError(results, e);
15341
+ resolve(results);
15316
15342
  }
15317
- win = null;
15318
- renderCatchError(results, e);
15319
- return Promise.resolve(results);
15343
+ } else {
15344
+ renderBuildError(results, `Invalid html or document. Must be either a valid "html" string, or DOM "document".`);
15345
+ resolve(results);
15320
15346
  }
15321
- }
15322
- renderBuildError(results, `Invalid html or document. Must be either a valid "html" string, or DOM "document".`);
15323
- return Promise.resolve(results);
15347
+ });
15324
15348
  }
15325
- async function render(win, opts, results) {
15326
- if ("process" in globalThis && typeof process.on === "function" && !process.__stencilErrors) {
15349
+ function render(win, opts, results, resolve) {
15350
+ if (!process.__stencilErrors) {
15327
15351
  process.__stencilErrors = true;
15328
15352
  process.on("unhandledRejection", (e) => {
15329
15353
  console.log("unhandledRejection", e);
15330
15354
  });
15331
15355
  }
15332
15356
  initializeWindow(win, win.document, opts, results);
15333
- const beforeHydrateFn = typeof opts.beforeHydrate === "function" ? opts.beforeHydrate(win.document) : NOOP;
15334
- try {
15335
- await Promise.resolve(beforeHydrateFn(win.document));
15336
- return new Promise((resolve) => hydrateFactory(win, opts, results, afterHydrate, resolve));
15337
- } catch (e) {
15338
- renderCatchError(results, e);
15339
- return finalizeHydrate(win, win.document, opts, results);
15340
- }
15341
- }
15342
- function renderStream(win, opts, results) {
15343
- async function* processRender() {
15344
- const renderResult = await render(win, opts, results);
15345
- yield renderResult.html;
15357
+ if (typeof opts.beforeHydrate === "function") {
15358
+ try {
15359
+ const rtn = opts.beforeHydrate(win.document);
15360
+ if (isPromise(rtn)) {
15361
+ rtn.then(() => {
15362
+ hydrateFactory(win, opts, results, afterHydrate, resolve);
15363
+ });
15364
+ } else {
15365
+ hydrateFactory(win, opts, results, afterHydrate, resolve);
15366
+ }
15367
+ } catch (e) {
15368
+ renderCatchError(results, e);
15369
+ finalizeHydrate(win, win.document, opts, results, resolve);
15370
+ }
15371
+ } else {
15372
+ hydrateFactory(win, opts, results, afterHydrate, resolve);
15346
15373
  }
15347
- return Readable.from(processRender());
15348
15374
  }
15349
- async function afterHydrate(win, opts, results, resolve) {
15350
- const afterHydrateFn = typeof opts.afterHydrate === "function" ? opts.afterHydrate(win.document) : NOOP;
15351
- try {
15352
- await Promise.resolve(afterHydrateFn(win.document));
15353
- return resolve(finalizeHydrate(win, win.document, opts, results));
15354
- } catch (e) {
15355
- renderCatchError(results, e);
15356
- return resolve(finalizeHydrate(win, win.document, opts, results));
15375
+ function afterHydrate(win, opts, results, resolve) {
15376
+ if (typeof opts.afterHydrate === "function") {
15377
+ try {
15378
+ const rtn = opts.afterHydrate(win.document);
15379
+ if (isPromise(rtn)) {
15380
+ rtn.then(() => {
15381
+ finalizeHydrate(win, win.document, opts, results, resolve);
15382
+ });
15383
+ } else {
15384
+ finalizeHydrate(win, win.document, opts, results, resolve);
15385
+ }
15386
+ } catch (e) {
15387
+ renderCatchError(results, e);
15388
+ finalizeHydrate(win, win.document, opts, results, resolve);
15389
+ }
15390
+ } else {
15391
+ finalizeHydrate(win, win.document, opts, results, resolve);
15357
15392
  }
15358
15393
  }
15359
- function finalizeHydrate(win, doc, opts, results) {
15394
+ function finalizeHydrate(win, doc, opts, results, resolve) {
15360
15395
  try {
15361
15396
  inspectElement(results, doc.documentElement, 0);
15362
15397
  if (opts.removeUnusedStyles !== false) {
@@ -15408,24 +15443,20 @@ function finalizeHydrate(win, doc, opts, results) {
15408
15443
  } catch (e) {
15409
15444
  renderCatchError(results, e);
15410
15445
  }
15411
- destroyWindow(win, doc, opts, results);
15412
- return results;
15413
- }
15414
- function destroyWindow(win, doc, opts, results) {
15415
- if (!opts.destroyWindow) {
15416
- return;
15417
- }
15418
- try {
15419
- if (!opts.destroyDocument) {
15420
- win.document = null;
15421
- doc.defaultView = null;
15422
- }
15423
- if (win.close) {
15424
- win.close();
15446
+ if (opts.destroyWindow) {
15447
+ try {
15448
+ if (!opts.destroyDocument) {
15449
+ win.document = null;
15450
+ doc.defaultView = null;
15451
+ }
15452
+ if (win.close) {
15453
+ win.close();
15454
+ }
15455
+ } catch (e) {
15456
+ renderCatchError(results, e);
15425
15457
  }
15426
- } catch (e) {
15427
- renderCatchError(results, e);
15428
15458
  }
15459
+ resolve(results);
15429
15460
  }
15430
15461
  function serializeDocumentToString(doc, opts) {
15431
15462
  return serializeNodeToHtml(doc, {
@@ -15436,8 +15467,7 @@ function serializeDocumentToString(doc, opts) {
15436
15467
  removeBooleanAttributeQuotes: opts.removeBooleanAttributeQuotes,
15437
15468
  removeEmptyAttributes: opts.removeEmptyAttributes,
15438
15469
  removeHtmlComments: opts.removeHtmlComments,
15439
- serializeShadowRoot: opts.serializeShadowRoot,
15440
- fullDocument: opts.fullDocument
15470
+ serializeShadowRoot: false
15441
15471
  });
15442
15472
  }
15443
15473
  function isValidDocument(doc) {
@@ -15457,6 +15487,5 @@ export {
15457
15487
  createWindowFromHtml,
15458
15488
  hydrateDocument,
15459
15489
  renderToString,
15460
- serializeDocumentToString,
15461
- streamToString
15490
+ serializeDocumentToString
15462
15491
  };