@percy/dom 1.28.1 → 1.28.2-beta.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.
- package/dist/bundle.js +47 -0
- package/package.json +3 -3
package/dist/bundle.js
CHANGED
|
@@ -598,7 +598,54 @@
|
|
|
598
598
|
return stringifyResponse ? JSON.stringify(result) : result;
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
+
function getSrcsets(dom) {
|
|
602
|
+
const links = new Set();
|
|
603
|
+
for (let img of dom.querySelectorAll('img[srcset]')) {
|
|
604
|
+
handleSrcSet(img.srcset, links);
|
|
605
|
+
}
|
|
606
|
+
for (let picture of dom.querySelectorAll('picture')) {
|
|
607
|
+
for (let source of picture.querySelectorAll('source')) {
|
|
608
|
+
handleSrcSet(source.srcset, links);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return Array.from(links);
|
|
612
|
+
}
|
|
613
|
+
function handleSrcSet(srcSet, links) {
|
|
614
|
+
let pattern = /,\s+/;
|
|
615
|
+
|
|
616
|
+
// We found couple of combination of srcset which needs different regex.
|
|
617
|
+
// example - https://url.com?param=a,b <--- here only separeting with , will cause incorrect capture.
|
|
618
|
+
// srcset = https://abc.com 320w,https://abc.com/a 400 <--- here srcset doesnot have space after comm.
|
|
619
|
+
if (!srcSet.match(pattern)) {
|
|
620
|
+
pattern = /,/;
|
|
621
|
+
}
|
|
622
|
+
srcSet = srcSet.split(pattern);
|
|
623
|
+
for (let src of srcSet) {
|
|
624
|
+
src = src.trim();
|
|
625
|
+
src = src.split(' ')[0];
|
|
626
|
+
links.add(getFormattedLink(src));
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
function getFormattedLink(src) {
|
|
630
|
+
const anchor = document.createElement('a');
|
|
631
|
+
anchor.href = src;
|
|
632
|
+
return anchor.href;
|
|
633
|
+
}
|
|
634
|
+
function loadAllSrcsetLinks() {
|
|
635
|
+
const allImgTags = [];
|
|
636
|
+
const links = getSrcsets(document);
|
|
637
|
+
for (const link of links) {
|
|
638
|
+
const img = document.createElement('img');
|
|
639
|
+
img.src = link;
|
|
640
|
+
allImgTags.push(img);
|
|
641
|
+
}
|
|
642
|
+
// Adding to window so GC won't abort request
|
|
643
|
+
window.allImgTags = allImgTags;
|
|
644
|
+
return allImgTags;
|
|
645
|
+
}
|
|
646
|
+
|
|
601
647
|
exports["default"] = serializeDOM;
|
|
648
|
+
exports.loadAllSrcsetLinks = loadAllSrcsetLinks;
|
|
602
649
|
exports.serialize = serializeDOM;
|
|
603
650
|
exports.serializeDOM = serializeDOM;
|
|
604
651
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/dom",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.2-beta.0",
|
|
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": "beta"
|
|
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": "0519aa061bd36acd0852b961e24c05b9ad67274f"
|
|
39
39
|
}
|