@percy/dom 1.31.2-beta.1 → 1.31.2-beta.3
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 +51 -31
- package/package.json +2 -2
package/dist/bundle.js
CHANGED
|
@@ -194,7 +194,7 @@
|
|
|
194
194
|
function uid() {
|
|
195
195
|
return `_${Math.random().toString(36).substr(2, 9)}`;
|
|
196
196
|
}
|
|
197
|
-
function markElement(domElement, disableShadowDOM) {
|
|
197
|
+
function markElement(domElement, disableShadowDOM, forceShadowAsLightDOM) {
|
|
198
198
|
var _domElement$tagName;
|
|
199
199
|
// Mark elements that are to be serialized later with a data attribute.
|
|
200
200
|
if (['input', 'textarea', 'select', 'iframe', 'canvas', 'video', 'style'].includes((_domElement$tagName = domElement.tagName) === null || _domElement$tagName === void 0 ? void 0 : _domElement$tagName.toLowerCase())) {
|
|
@@ -205,7 +205,10 @@
|
|
|
205
205
|
|
|
206
206
|
// add special marker for shadow host
|
|
207
207
|
if (!disableShadowDOM && domElement.shadowRoot) {
|
|
208
|
-
|
|
208
|
+
// When forceShadowAsLightDOM is true, don't mark as shadow host
|
|
209
|
+
if (!forceShadowAsLightDOM) {
|
|
210
|
+
domElement.setAttribute('data-percy-shadow-host', '');
|
|
211
|
+
}
|
|
209
212
|
if (!domElement.getAttribute('data-percy-element-id')) {
|
|
210
213
|
domElement.setAttribute('data-percy-element-id', uid());
|
|
211
214
|
}
|
|
@@ -565,6 +568,7 @@
|
|
|
565
568
|
let {
|
|
566
569
|
dom,
|
|
567
570
|
disableShadowDOM,
|
|
571
|
+
forceShadowAsLightDOM,
|
|
568
572
|
resources,
|
|
569
573
|
cache,
|
|
570
574
|
enableJavaScript
|
|
@@ -582,7 +586,7 @@
|
|
|
582
586
|
};
|
|
583
587
|
|
|
584
588
|
// mark the node before cloning
|
|
585
|
-
markElement(node, disableShadowDOM);
|
|
589
|
+
markElement(node, disableShadowDOM, forceShadowAsLightDOM);
|
|
586
590
|
let clone = cloneElementWithoutLifecycle(node);
|
|
587
591
|
|
|
588
592
|
// Handle <style> tag specifically for media queries
|
|
@@ -618,18 +622,23 @@
|
|
|
618
622
|
|
|
619
623
|
// clone shadow DOM
|
|
620
624
|
if (node.shadowRoot && !disableShadowDOM) {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
clone.shadowRoot.innerHTML = '';
|
|
625
|
+
if (forceShadowAsLightDOM) {
|
|
626
|
+
// When forceShadowAsLightDOM is true, treat shadow content as normal DOM
|
|
627
|
+
walkTree(node.shadowRoot.firstChild, clone);
|
|
625
628
|
} else {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
629
|
+
// create shadowRoot
|
|
630
|
+
if (clone.shadowRoot) {
|
|
631
|
+
// it may be set up in a custom element's constructor
|
|
632
|
+
clone.shadowRoot.innerHTML = '';
|
|
633
|
+
} else {
|
|
634
|
+
clone.attachShadow({
|
|
635
|
+
mode: 'open',
|
|
636
|
+
serializable: true
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
// clone dom elements
|
|
640
|
+
walkTree(node.shadowRoot.firstChild, clone.shadowRoot);
|
|
630
641
|
}
|
|
631
|
-
// clone dom elements
|
|
632
|
-
walkTree(node.shadowRoot.firstChild, clone.shadowRoot);
|
|
633
642
|
}
|
|
634
643
|
|
|
635
644
|
// clone light DOM
|
|
@@ -654,10 +663,15 @@
|
|
|
654
663
|
* Use `getInnerHTML()` to serialize shadow dom as <template> tags. `innerHTML` and `outerHTML` don't do this. Buzzword: "declarative shadow dom"
|
|
655
664
|
*/
|
|
656
665
|
function getOuterHTML(docElement, {
|
|
657
|
-
shadowRootElements
|
|
666
|
+
shadowRootElements,
|
|
667
|
+
forceShadowAsLightDOM
|
|
658
668
|
}) {
|
|
659
669
|
// chromium gives us declarative shadow DOM serialization API
|
|
660
670
|
let innerHTML = '';
|
|
671
|
+
// When forceShadowAsLightDOM is true, treat shadow DOM as normal HTML
|
|
672
|
+
if (forceShadowAsLightDOM) {
|
|
673
|
+
return docElement.outerHTML;
|
|
674
|
+
}
|
|
661
675
|
/* istanbul ignore else if: Only triggered in chrome <= 128 and tests runs on latest */
|
|
662
676
|
if (docElement.getHTML) {
|
|
663
677
|
// All major browsers in latest versions supports getHTML API to get serialized DOM
|
|
@@ -702,7 +716,8 @@
|
|
|
702
716
|
// Serializes and returns the cloned DOM as an HTML string
|
|
703
717
|
function serializeHTML(ctx) {
|
|
704
718
|
let html = getOuterHTML(ctx.clone.documentElement, {
|
|
705
|
-
shadowRootElements: ctx.shadowRootElements
|
|
719
|
+
shadowRootElements: ctx.shadowRootElements,
|
|
720
|
+
forceShadowAsLightDOM: ctx.forceShadowAsLightDOM
|
|
706
721
|
});
|
|
707
722
|
// this is replacing serialized data tag with real tag
|
|
708
723
|
html = html.replace(/(<\/?)data-percy-custom-element-/g, '$1');
|
|
@@ -719,20 +734,23 @@
|
|
|
719
734
|
serializeCSSOM(ctx);
|
|
720
735
|
serializeCanvas(ctx);
|
|
721
736
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
737
|
+
// Only process shadow hosts if forceShadowAsLightDOM is not enabled
|
|
738
|
+
if (!ctx.forceShadowAsLightDOM) {
|
|
739
|
+
for (const shadowHost of ctx.dom.querySelectorAll('[data-percy-shadow-host]')) {
|
|
740
|
+
let percyElementId = shadowHost.getAttribute('data-percy-element-id');
|
|
741
|
+
let cloneShadowHost = ctx.clone.querySelector(`[data-percy-element-id="${percyElementId}"]`);
|
|
742
|
+
if (shadowHost.shadowRoot && cloneShadowHost.shadowRoot) {
|
|
743
|
+
// getHTML requires shadowRoot to be passed explicitly
|
|
744
|
+
// to serialize the shadow elements properly
|
|
745
|
+
ctx.shadowRootElements.push(cloneShadowHost.shadowRoot);
|
|
746
|
+
serializeElements({
|
|
747
|
+
...ctx,
|
|
748
|
+
dom: shadowHost.shadowRoot,
|
|
749
|
+
clone: cloneShadowHost.shadowRoot
|
|
750
|
+
});
|
|
751
|
+
} else {
|
|
752
|
+
ctx.warnings.add('data-percy-shadow-host does not have shadowRoot');
|
|
753
|
+
}
|
|
736
754
|
}
|
|
737
755
|
}
|
|
738
756
|
}
|
|
@@ -764,7 +782,8 @@
|
|
|
764
782
|
stringifyResponse = options === null || options === void 0 ? void 0 : options.stringify_response,
|
|
765
783
|
disableShadowDOM = options === null || options === void 0 ? void 0 : options.disable_shadow_dom,
|
|
766
784
|
reshuffleInvalidTags = options === null || options === void 0 ? void 0 : options.reshuffle_invalid_tags,
|
|
767
|
-
ignoreCanvasSerializationErrors = options === null || options === void 0 ? void 0 : options.ignore_canvas_serialization_errors
|
|
785
|
+
ignoreCanvasSerializationErrors = options === null || options === void 0 ? void 0 : options.ignore_canvas_serialization_errors,
|
|
786
|
+
forceShadowAsLightDOM = options === null || options === void 0 ? void 0 : options.force_shadow_dom_as_light_dom
|
|
768
787
|
} = options || {};
|
|
769
788
|
|
|
770
789
|
// keep certain records throughout serialization
|
|
@@ -776,7 +795,8 @@
|
|
|
776
795
|
shadowRootElements: [],
|
|
777
796
|
enableJavaScript,
|
|
778
797
|
disableShadowDOM,
|
|
779
|
-
ignoreCanvasSerializationErrors
|
|
798
|
+
ignoreCanvasSerializationErrors,
|
|
799
|
+
forceShadowAsLightDOM
|
|
780
800
|
};
|
|
781
801
|
ctx.dom = dom;
|
|
782
802
|
ctx.clone = cloneNodeAndShadow(ctx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/dom",
|
|
3
|
-
"version": "1.31.2-beta.
|
|
3
|
+
"version": "1.31.2-beta.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"interactor.js": "^2.0.0-beta.10"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "761ef7aef1d13d45afb0cedae50e6e82d84a3521"
|
|
39
39
|
}
|