@percy/dom 1.30.5-beta.1 → 1.30.5
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.
- package/dist/bundle.js +18 -11
- package/package.json +3 -3
package/dist/bundle.js
CHANGED
|
@@ -547,26 +547,27 @@
|
|
|
547
547
|
/**
|
|
548
548
|
* Use `getInnerHTML()` to serialize shadow dom as <template> tags. `innerHTML` and `outerHTML` don't do this. Buzzword: "declarative shadow dom"
|
|
549
549
|
*/
|
|
550
|
-
function getOuterHTML(docElement
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
// old firefox doesn't serialize shadow DOM, we're awaiting API's by firefox to become ready and are not polyfilling it.
|
|
554
|
-
// new firefox from 128 onwards serializes it using getHTML
|
|
555
|
-
/* istanbul ignore if: Only triggered in firefox <= 128 and tests runs on latest */
|
|
556
|
-
if (!docElement.getHTML) {
|
|
557
|
-
return docElement.outerHTML;
|
|
558
|
-
}
|
|
550
|
+
function getOuterHTML(docElement, {
|
|
551
|
+
shadowRootElements
|
|
552
|
+
}) {
|
|
559
553
|
// chromium gives us declarative shadow DOM serialization API
|
|
560
554
|
let innerHTML = '';
|
|
561
555
|
/* istanbul ignore else if: Only triggered in chrome <= 128 and tests runs on latest */
|
|
562
556
|
if (docElement.getHTML) {
|
|
557
|
+
// All major browsers in latest versions supports getHTML API to get serialized DOM
|
|
558
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/getHTML
|
|
563
559
|
innerHTML = docElement.getHTML({
|
|
564
|
-
serializableShadowRoots: true
|
|
560
|
+
serializableShadowRoots: true,
|
|
561
|
+
shadowRoots: shadowRootElements
|
|
565
562
|
});
|
|
566
563
|
} else if (docElement.getInnerHTML) {
|
|
567
564
|
innerHTML = docElement.getInnerHTML({
|
|
568
565
|
includeShadowRoots: true
|
|
569
566
|
});
|
|
567
|
+
} else {
|
|
568
|
+
// old firefox doesn't serialize shadow DOM, we're awaiting API's by firefox to become ready and are not polyfilling it.
|
|
569
|
+
// new firefox from 128 onwards serializes it using getHTML
|
|
570
|
+
return docElement.outerHTML;
|
|
570
571
|
}
|
|
571
572
|
docElement.textContent = '';
|
|
572
573
|
// Note: Here we are specifically passing replacer function to avoid any replacements due to
|
|
@@ -594,7 +595,9 @@
|
|
|
594
595
|
|
|
595
596
|
// Serializes and returns the cloned DOM as an HTML string
|
|
596
597
|
function serializeHTML(ctx) {
|
|
597
|
-
let html = getOuterHTML(ctx.clone.documentElement
|
|
598
|
+
let html = getOuterHTML(ctx.clone.documentElement, {
|
|
599
|
+
shadowRootElements: ctx.shadowRootElements
|
|
600
|
+
});
|
|
598
601
|
// replace serialized data attributes with real attributes
|
|
599
602
|
html = html.replace(/ data-percy-serialized-attribute-(\w+?)=/ig, ' $1=');
|
|
600
603
|
// include the doctype with the html string
|
|
@@ -612,6 +615,9 @@
|
|
|
612
615
|
let percyElementId = shadowHost.getAttribute('data-percy-element-id');
|
|
613
616
|
let cloneShadowHost = ctx.clone.querySelector(`[data-percy-element-id="${percyElementId}"]`);
|
|
614
617
|
if (shadowHost.shadowRoot && cloneShadowHost.shadowRoot) {
|
|
618
|
+
// getHTML requires shadowRoot to be passed explicitly
|
|
619
|
+
// to serialize the shadow elements properly
|
|
620
|
+
ctx.shadowRootElements.push(cloneShadowHost.shadowRoot);
|
|
615
621
|
serializeElements({
|
|
616
622
|
...ctx,
|
|
617
623
|
dom: shadowHost.shadowRoot,
|
|
@@ -657,6 +663,7 @@
|
|
|
657
663
|
warnings: new Set(),
|
|
658
664
|
hints: new Set(),
|
|
659
665
|
cache: new Map(),
|
|
666
|
+
shadowRootElements: [],
|
|
660
667
|
enableJavaScript,
|
|
661
668
|
disableShadowDOM
|
|
662
669
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/dom",
|
|
3
|
-
"version": "1.30.5
|
|
3
|
+
"version": "1.30.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public",
|
|
12
|
-
"tag": "
|
|
12
|
+
"tag": "latest"
|
|
13
13
|
},
|
|
14
14
|
"main": "dist/bundle.js",
|
|
15
15
|
"browser": "dist/bundle.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"interactor.js": "^2.0.0-beta.10"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "bf1c4a33777ea241f1f0256a70068d34983812a7"
|
|
39
39
|
}
|