@percy/dom 1.28.1 → 1.28.2-alpha.1
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 +83 -1
- package/package.json +3 -3
package/dist/bundle.js
CHANGED
|
@@ -369,6 +369,39 @@
|
|
|
369
369
|
dropLoadingAttribute(domElement);
|
|
370
370
|
}
|
|
371
371
|
|
|
372
|
+
let mimetype = null;
|
|
373
|
+
function getBase64Substring(src) {
|
|
374
|
+
let base64Index = src.indexOf(';base64,');
|
|
375
|
+
if (base64Index === -1) return null;
|
|
376
|
+
mimetype = src.substring(5, base64Index);
|
|
377
|
+
base64Index += ';base64,'.length;
|
|
378
|
+
return src.substring(base64Index);
|
|
379
|
+
}
|
|
380
|
+
function serializeBase64(node, resources) {
|
|
381
|
+
let src = node.src;
|
|
382
|
+
let isHrefUsed = false;
|
|
383
|
+
|
|
384
|
+
// case for SVGAnimatedString
|
|
385
|
+
if (src == null && node.href) {
|
|
386
|
+
isHrefUsed = true;
|
|
387
|
+
src = node.href.baseVal;
|
|
388
|
+
}
|
|
389
|
+
// skip if src is null
|
|
390
|
+
if (src == null) return;
|
|
391
|
+
let base64String = getBase64Substring(src.toString());
|
|
392
|
+
// skip if src is not base64
|
|
393
|
+
if (base64String == null) return;
|
|
394
|
+
|
|
395
|
+
// create a resource from the serialized data url
|
|
396
|
+
let resource = resourceFromText(uid(), mimetype, base64String);
|
|
397
|
+
resources.add(resource);
|
|
398
|
+
if (isHrefUsed === true) {
|
|
399
|
+
node.href.baseVal = resource.url;
|
|
400
|
+
} else {
|
|
401
|
+
node.src = resource.url;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
372
405
|
/**
|
|
373
406
|
* Custom deep clone function that replaces Percy's current clone behavior.
|
|
374
407
|
* This enables us to capture shadow DOM in snapshots. It takes advantage of `attachShadow`'s mode option set to open
|
|
@@ -384,7 +417,8 @@
|
|
|
384
417
|
function cloneNodeAndShadow(_ref) {
|
|
385
418
|
let {
|
|
386
419
|
dom,
|
|
387
|
-
disableShadowDOM
|
|
420
|
+
disableShadowDOM,
|
|
421
|
+
resources
|
|
388
422
|
} = _ref;
|
|
389
423
|
// clones shadow DOM and light DOM for a given node
|
|
390
424
|
let cloneNode = (node, parent) => {
|
|
@@ -403,6 +437,7 @@
|
|
|
403
437
|
|
|
404
438
|
// We apply any element transformations here to avoid another treeWalk
|
|
405
439
|
applyElementTransformations(clone);
|
|
440
|
+
serializeBase64(clone, resources);
|
|
406
441
|
parent.appendChild(clone);
|
|
407
442
|
|
|
408
443
|
// shallow clone should not contain children
|
|
@@ -598,7 +633,54 @@
|
|
|
598
633
|
return stringifyResponse ? JSON.stringify(result) : result;
|
|
599
634
|
}
|
|
600
635
|
|
|
636
|
+
function getSrcsets(dom) {
|
|
637
|
+
const links = new Set();
|
|
638
|
+
for (let img of dom.querySelectorAll('img[srcset]')) {
|
|
639
|
+
handleSrcSet(img.srcset, links);
|
|
640
|
+
}
|
|
641
|
+
for (let picture of dom.querySelectorAll('picture')) {
|
|
642
|
+
for (let source of picture.querySelectorAll('source')) {
|
|
643
|
+
handleSrcSet(source.srcset, links);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return Array.from(links);
|
|
647
|
+
}
|
|
648
|
+
function handleSrcSet(srcSet, links) {
|
|
649
|
+
let pattern = /,\s+/;
|
|
650
|
+
|
|
651
|
+
// We found couple of combination of srcset which needs different regex.
|
|
652
|
+
// example - https://url.com?param=a,b <--- here only separeting with , will cause incorrect capture.
|
|
653
|
+
// srcset = https://abc.com 320w,https://abc.com/a 400 <--- here srcset doesnot have space after comm.
|
|
654
|
+
if (!srcSet.match(pattern)) {
|
|
655
|
+
pattern = /,/;
|
|
656
|
+
}
|
|
657
|
+
srcSet = srcSet.split(pattern);
|
|
658
|
+
for (let src of srcSet) {
|
|
659
|
+
src = src.trim();
|
|
660
|
+
src = src.split(' ')[0];
|
|
661
|
+
links.add(getFormattedLink(src));
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function getFormattedLink(src) {
|
|
665
|
+
const anchor = document.createElement('a');
|
|
666
|
+
anchor.href = src;
|
|
667
|
+
return anchor.href;
|
|
668
|
+
}
|
|
669
|
+
function loadAllSrcsetLinks() {
|
|
670
|
+
const allImgTags = [];
|
|
671
|
+
const links = getSrcsets(document);
|
|
672
|
+
for (const link of links) {
|
|
673
|
+
const img = document.createElement('img');
|
|
674
|
+
img.src = link;
|
|
675
|
+
allImgTags.push(img);
|
|
676
|
+
}
|
|
677
|
+
// Adding to window so GC won't abort request
|
|
678
|
+
window.allImgTags = allImgTags;
|
|
679
|
+
return allImgTags;
|
|
680
|
+
}
|
|
681
|
+
|
|
601
682
|
exports["default"] = serializeDOM;
|
|
683
|
+
exports.loadAllSrcsetLinks = loadAllSrcsetLinks;
|
|
602
684
|
exports.serialize = serializeDOM;
|
|
603
685
|
exports.serializeDOM = serializeDOM;
|
|
604
686
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/dom",
|
|
3
|
-
"version": "1.28.1",
|
|
3
|
+
"version": "1.28.2-alpha.1",
|
|
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": "alpha"
|
|
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": "7aa1309dad35bbae9b4114620b6d338dfc964bc6"
|
|
39
39
|
}
|