@applitools/dom-snapshot
Advanced tools
Comparing version 1.4.5 to 1.4.6
@@ -1,2 +0,2 @@ | ||
/* @applitools/dom-snapshot@1.4.4 */ | ||
/* @applitools/dom-snapshot@1.4.5 */ | ||
@@ -69,3 +69,3 @@ function __processPage() { | ||
const cdt = [{nodeType: Node.DOCUMENT_NODE}]; | ||
const documents = [docNode]; | ||
const docRoots = [docNode]; | ||
const canvasElements = []; | ||
@@ -75,3 +75,3 @@ const inlineFrames = []; | ||
cdt[0].childNodeIndexes = childrenFactory(cdt, docNode.childNodes); | ||
return {cdt, documents, canvasElements, inlineFrames}; | ||
return {cdt, docRoots, canvasElements, inlineFrames}; | ||
@@ -114,3 +114,3 @@ function childrenFactory(cdt, elementNodes) { | ||
node.shadowRootIndex = elementNodeFactory(cdt, elementNode.shadowRoot); | ||
documents.push(elementNode.shadowRoot); | ||
docRoots.push(elementNode.shadowRoot); | ||
} | ||
@@ -400,3 +400,21 @@ | ||
function makeExtractResourcesFromSvg({parser, decoder}) { | ||
function getUrlFromCssText(cssText) { | ||
const re = /url\((?!['"]?:)['"]?([^'")]*)['"]?\)/g; | ||
const ret = []; | ||
let result; | ||
while ((result = re.exec(cssText)) !== null) { | ||
ret.push(result[1]); | ||
} | ||
return ret; | ||
} | ||
var getUrlFromCssText_1 = getUrlFromCssText; | ||
function flat(arr) { | ||
return [].concat(...arr); | ||
} | ||
var flat_1 = flat; | ||
function makeExtractResourcesFromSvg({parser, decoder, extractResourceUrlsFromStyleTags}) { | ||
return function(svgArrayBuffer) { | ||
@@ -417,3 +435,10 @@ let svgStr; | ||
); | ||
urls = fromImages.concat(fromObjects).filter(u => u[0] !== '#'); | ||
const fromStyleTags = extractResourceUrlsFromStyleTags(doc, false); | ||
const fromStyleAttrs = urlsFromStyleAttrOfDoc(doc); | ||
urls = fromImages | ||
.concat(fromObjects) | ||
.concat(fromStyleTags) | ||
.concat(fromStyleAttrs) | ||
.filter(u => u[0] !== '#'); | ||
} catch (e) { | ||
@@ -426,2 +451,11 @@ console.log('could not parse svg content', e); | ||
function urlsFromStyleAttrOfDoc(doc) { | ||
return flat_1( | ||
Array.from(doc.querySelectorAll('*[style]')) | ||
.map(e => e.style.cssText) | ||
.map(getUrlFromCssText_1) | ||
.filter(Boolean), | ||
); | ||
} | ||
var makeExtractResourcesFromSvg_1 = makeExtractResourcesFromSvg; | ||
@@ -445,8 +479,2 @@ | ||
function flat(arr) { | ||
return [].concat(...arr); | ||
} | ||
var flat_1 = flat; | ||
function makeFindStyleSheetByUrl({styleSheetCache}) { | ||
@@ -464,17 +492,5 @@ return function findStyleSheetByUrl(url, documents) { | ||
function getUrlFromCssText(cssText) { | ||
const re = /url\((?!['"]?:)['"]?([^'")]*)['"]?\)/g; | ||
const ret = []; | ||
let result; | ||
while ((result = re.exec(cssText)) !== null) { | ||
ret.push(result[1]); | ||
} | ||
return ret; | ||
} | ||
var getUrlFromCssText_1 = getUrlFromCssText; | ||
function makeExtractResourcesFromStyleSheet({styleSheetCache}) { | ||
return function extractResourcesFromStyleSheet(styleSheet, doc = document) { | ||
const win = doc.defaultView || doc.ownerDocument.defaultView; | ||
return function extractResourcesFromStyleSheet(styleSheet, doc) { | ||
const win = doc.defaultView || (doc.ownerDocument && doc.ownerDocument.defaultView) || window; | ||
return uniq_1( | ||
@@ -521,8 +537,8 @@ Array.from(styleSheet.cssRules || []).reduce((acc, rule) => { | ||
function makeExtractResourceUrlsFromStyleTags(extractResourcesFromStyleSheet) { | ||
return function extractResourceUrlsFromStyleTags(doc) { | ||
return function extractResourceUrlsFromStyleTags(doc, onlyDocStylesheet = true) { | ||
return uniq_1( | ||
Array.from(doc.querySelectorAll('style')).reduce((resourceUrls, styleEl) => { | ||
const styleSheet = Array.from(doc.styleSheets).find( | ||
styleSheet => styleSheet.ownerNode === styleEl, | ||
); | ||
const styleSheet = onlyDocStylesheet | ||
? Array.from(doc.styleSheets).find(styleSheet => styleSheet.ownerNode === styleEl) | ||
: styleEl.sheet; | ||
return styleSheet | ||
@@ -610,4 +626,8 @@ ? resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc)) | ||
const extractResourcesFromStyleSheet$$1 = extractResourcesFromStyleSheet({styleSheetCache}); | ||
const extractResourcesFromSvg = makeExtractResourcesFromSvg_1({}); | ||
const findStyleSheetByUrl$$1 = findStyleSheetByUrl({styleSheetCache}); | ||
const extractResourceUrlsFromStyleTags$$1 = extractResourceUrlsFromStyleTags( | ||
extractResourcesFromStyleSheet$$1, | ||
); | ||
const extractResourcesFromSvg = makeExtractResourcesFromSvg_1({extractResourceUrlsFromStyleTags: extractResourceUrlsFromStyleTags$$1}); | ||
const processResource$$1 = processResource({ | ||
@@ -626,6 +646,2 @@ fetchUrl: fetchUrl_1, | ||
const extractResourceUrlsFromStyleTags$$1 = extractResourceUrlsFromStyleTags( | ||
extractResourcesFromStyleSheet$$1, | ||
); | ||
return doProcessPage(doc); | ||
@@ -635,6 +651,6 @@ | ||
const url = baesUrl || getBaseUrl(doc); | ||
const {cdt, documents, canvasElements, inlineFrames} = domNodesToCdt_1(doc, url); | ||
const {cdt, docRoots, canvasElements, inlineFrames} = domNodesToCdt_1(doc, url); | ||
const linkUrls = flat_1(documents.map(extractLinks_1)); | ||
const styleTagUrls = flat_1(documents.map(extractResourceUrlsFromStyleTags$$1)); | ||
const linkUrls = flat_1(docRoots.map(extractLinks_1)); | ||
const styleTagUrls = flat_1(docRoots.map(extractResourceUrlsFromStyleTags$$1)); | ||
const absolutizeThisUrl = getAbsolutizeByUrl(url); | ||
@@ -651,6 +667,6 @@ const links = uniq_1( | ||
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(documents, url, links); | ||
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(docRoots, url, links); | ||
const canvasBlobs = buildCanvasBlobs_1(canvasElements); | ||
const frameDocs = extractFrames_1(documents); | ||
const frameDocs = extractFrames_1(docRoots); | ||
const processFramesPromise = frameDocs.map(f => doProcessPage(f, null)); | ||
@@ -657,0 +673,0 @@ const processInlineFramesPromise = inlineFrames.map(({element, url}) => |
@@ -1,2 +0,2 @@ | ||
/* @applitools/dom-snapshot@1.4.4 */ | ||
/* @applitools/dom-snapshot@1.4.5 */ | ||
@@ -121,3 +121,3 @@ function __processPageAndPoll() { | ||
const cdt = [{nodeType: Node.DOCUMENT_NODE}]; | ||
const documents = [docNode]; | ||
const docRoots = [docNode]; | ||
const canvasElements = []; | ||
@@ -127,3 +127,3 @@ const inlineFrames = []; | ||
cdt[0].childNodeIndexes = childrenFactory(cdt, docNode.childNodes); | ||
return {cdt, documents, canvasElements, inlineFrames}; | ||
return {cdt, docRoots, canvasElements, inlineFrames}; | ||
@@ -166,3 +166,3 @@ function childrenFactory(cdt, elementNodes) { | ||
node.shadowRootIndex = elementNodeFactory(cdt, elementNode.shadowRoot); | ||
documents.push(elementNode.shadowRoot); | ||
docRoots.push(elementNode.shadowRoot); | ||
} | ||
@@ -452,3 +452,21 @@ | ||
function makeExtractResourcesFromSvg({parser, decoder}) { | ||
function getUrlFromCssText(cssText) { | ||
const re = /url\((?!['"]?:)['"]?([^'")]*)['"]?\)/g; | ||
const ret = []; | ||
let result; | ||
while ((result = re.exec(cssText)) !== null) { | ||
ret.push(result[1]); | ||
} | ||
return ret; | ||
} | ||
var getUrlFromCssText_1 = getUrlFromCssText; | ||
function flat(arr) { | ||
return [].concat(...arr); | ||
} | ||
var flat_1 = flat; | ||
function makeExtractResourcesFromSvg({parser, decoder, extractResourceUrlsFromStyleTags}) { | ||
return function(svgArrayBuffer) { | ||
@@ -469,3 +487,10 @@ let svgStr; | ||
); | ||
urls = fromImages.concat(fromObjects).filter(u => u[0] !== '#'); | ||
const fromStyleTags = extractResourceUrlsFromStyleTags(doc, false); | ||
const fromStyleAttrs = urlsFromStyleAttrOfDoc(doc); | ||
urls = fromImages | ||
.concat(fromObjects) | ||
.concat(fromStyleTags) | ||
.concat(fromStyleAttrs) | ||
.filter(u => u[0] !== '#'); | ||
} catch (e) { | ||
@@ -478,2 +503,11 @@ console.log('could not parse svg content', e); | ||
function urlsFromStyleAttrOfDoc(doc) { | ||
return flat_1( | ||
Array.from(doc.querySelectorAll('*[style]')) | ||
.map(e => e.style.cssText) | ||
.map(getUrlFromCssText_1) | ||
.filter(Boolean), | ||
); | ||
} | ||
var makeExtractResourcesFromSvg_1 = makeExtractResourcesFromSvg; | ||
@@ -497,8 +531,2 @@ | ||
function flat(arr) { | ||
return [].concat(...arr); | ||
} | ||
var flat_1 = flat; | ||
function makeFindStyleSheetByUrl({styleSheetCache}) { | ||
@@ -516,17 +544,5 @@ return function findStyleSheetByUrl(url, documents) { | ||
function getUrlFromCssText(cssText) { | ||
const re = /url\((?!['"]?:)['"]?([^'")]*)['"]?\)/g; | ||
const ret = []; | ||
let result; | ||
while ((result = re.exec(cssText)) !== null) { | ||
ret.push(result[1]); | ||
} | ||
return ret; | ||
} | ||
var getUrlFromCssText_1 = getUrlFromCssText; | ||
function makeExtractResourcesFromStyleSheet({styleSheetCache}) { | ||
return function extractResourcesFromStyleSheet(styleSheet, doc = document) { | ||
const win = doc.defaultView || doc.ownerDocument.defaultView; | ||
return function extractResourcesFromStyleSheet(styleSheet, doc) { | ||
const win = doc.defaultView || (doc.ownerDocument && doc.ownerDocument.defaultView) || window; | ||
return uniq_1( | ||
@@ -573,8 +589,8 @@ Array.from(styleSheet.cssRules || []).reduce((acc, rule) => { | ||
function makeExtractResourceUrlsFromStyleTags(extractResourcesFromStyleSheet) { | ||
return function extractResourceUrlsFromStyleTags(doc) { | ||
return function extractResourceUrlsFromStyleTags(doc, onlyDocStylesheet = true) { | ||
return uniq_1( | ||
Array.from(doc.querySelectorAll('style')).reduce((resourceUrls, styleEl) => { | ||
const styleSheet = Array.from(doc.styleSheets).find( | ||
styleSheet => styleSheet.ownerNode === styleEl, | ||
); | ||
const styleSheet = onlyDocStylesheet | ||
? Array.from(doc.styleSheets).find(styleSheet => styleSheet.ownerNode === styleEl) | ||
: styleEl.sheet; | ||
return styleSheet | ||
@@ -662,4 +678,8 @@ ? resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc)) | ||
const extractResourcesFromStyleSheet$$1 = extractResourcesFromStyleSheet({styleSheetCache}); | ||
const extractResourcesFromSvg = makeExtractResourcesFromSvg_1({}); | ||
const findStyleSheetByUrl$$1 = findStyleSheetByUrl({styleSheetCache}); | ||
const extractResourceUrlsFromStyleTags$$1 = extractResourceUrlsFromStyleTags( | ||
extractResourcesFromStyleSheet$$1, | ||
); | ||
const extractResourcesFromSvg = makeExtractResourcesFromSvg_1({extractResourceUrlsFromStyleTags: extractResourceUrlsFromStyleTags$$1}); | ||
const processResource$$1 = processResource({ | ||
@@ -678,6 +698,2 @@ fetchUrl: fetchUrl_1, | ||
const extractResourceUrlsFromStyleTags$$1 = extractResourceUrlsFromStyleTags( | ||
extractResourcesFromStyleSheet$$1, | ||
); | ||
return doProcessPage(doc); | ||
@@ -687,6 +703,6 @@ | ||
const url = baesUrl || getBaseUrl(doc); | ||
const {cdt, documents, canvasElements, inlineFrames} = domNodesToCdt_1(doc, url); | ||
const {cdt, docRoots, canvasElements, inlineFrames} = domNodesToCdt_1(doc, url); | ||
const linkUrls = flat_1(documents.map(extractLinks_1)); | ||
const styleTagUrls = flat_1(documents.map(extractResourceUrlsFromStyleTags$$1)); | ||
const linkUrls = flat_1(docRoots.map(extractLinks_1)); | ||
const styleTagUrls = flat_1(docRoots.map(extractResourceUrlsFromStyleTags$$1)); | ||
const absolutizeThisUrl = getAbsolutizeByUrl(url); | ||
@@ -703,6 +719,6 @@ const links = uniq_1( | ||
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(documents, url, links); | ||
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(docRoots, url, links); | ||
const canvasBlobs = buildCanvasBlobs_1(canvasElements); | ||
const frameDocs = extractFrames_1(documents); | ||
const frameDocs = extractFrames_1(docRoots); | ||
const processFramesPromise = frameDocs.map(f => doProcessPage(f, null)); | ||
@@ -709,0 +725,0 @@ const processInlineFramesPromise = inlineFrames.map(({element, url}) => |
@@ -1,2 +0,2 @@ | ||
/* @applitools/dom-snapshot@1.4.4 */ | ||
/* @applitools/dom-snapshot@1.4.5 */ | ||
@@ -121,3 +121,3 @@ function __processPageAndSerialize() { | ||
const cdt = [{nodeType: Node.DOCUMENT_NODE}]; | ||
const documents = [docNode]; | ||
const docRoots = [docNode]; | ||
const canvasElements = []; | ||
@@ -127,3 +127,3 @@ const inlineFrames = []; | ||
cdt[0].childNodeIndexes = childrenFactory(cdt, docNode.childNodes); | ||
return {cdt, documents, canvasElements, inlineFrames}; | ||
return {cdt, docRoots, canvasElements, inlineFrames}; | ||
@@ -166,3 +166,3 @@ function childrenFactory(cdt, elementNodes) { | ||
node.shadowRootIndex = elementNodeFactory(cdt, elementNode.shadowRoot); | ||
documents.push(elementNode.shadowRoot); | ||
docRoots.push(elementNode.shadowRoot); | ||
} | ||
@@ -452,3 +452,21 @@ | ||
function makeExtractResourcesFromSvg({parser, decoder}) { | ||
function getUrlFromCssText(cssText) { | ||
const re = /url\((?!['"]?:)['"]?([^'")]*)['"]?\)/g; | ||
const ret = []; | ||
let result; | ||
while ((result = re.exec(cssText)) !== null) { | ||
ret.push(result[1]); | ||
} | ||
return ret; | ||
} | ||
var getUrlFromCssText_1 = getUrlFromCssText; | ||
function flat(arr) { | ||
return [].concat(...arr); | ||
} | ||
var flat_1 = flat; | ||
function makeExtractResourcesFromSvg({parser, decoder, extractResourceUrlsFromStyleTags}) { | ||
return function(svgArrayBuffer) { | ||
@@ -469,3 +487,10 @@ let svgStr; | ||
); | ||
urls = fromImages.concat(fromObjects).filter(u => u[0] !== '#'); | ||
const fromStyleTags = extractResourceUrlsFromStyleTags(doc, false); | ||
const fromStyleAttrs = urlsFromStyleAttrOfDoc(doc); | ||
urls = fromImages | ||
.concat(fromObjects) | ||
.concat(fromStyleTags) | ||
.concat(fromStyleAttrs) | ||
.filter(u => u[0] !== '#'); | ||
} catch (e) { | ||
@@ -478,2 +503,11 @@ console.log('could not parse svg content', e); | ||
function urlsFromStyleAttrOfDoc(doc) { | ||
return flat_1( | ||
Array.from(doc.querySelectorAll('*[style]')) | ||
.map(e => e.style.cssText) | ||
.map(getUrlFromCssText_1) | ||
.filter(Boolean), | ||
); | ||
} | ||
var makeExtractResourcesFromSvg_1 = makeExtractResourcesFromSvg; | ||
@@ -497,8 +531,2 @@ | ||
function flat(arr) { | ||
return [].concat(...arr); | ||
} | ||
var flat_1 = flat; | ||
function makeFindStyleSheetByUrl({styleSheetCache}) { | ||
@@ -516,17 +544,5 @@ return function findStyleSheetByUrl(url, documents) { | ||
function getUrlFromCssText(cssText) { | ||
const re = /url\((?!['"]?:)['"]?([^'")]*)['"]?\)/g; | ||
const ret = []; | ||
let result; | ||
while ((result = re.exec(cssText)) !== null) { | ||
ret.push(result[1]); | ||
} | ||
return ret; | ||
} | ||
var getUrlFromCssText_1 = getUrlFromCssText; | ||
function makeExtractResourcesFromStyleSheet({styleSheetCache}) { | ||
return function extractResourcesFromStyleSheet(styleSheet, doc = document) { | ||
const win = doc.defaultView || doc.ownerDocument.defaultView; | ||
return function extractResourcesFromStyleSheet(styleSheet, doc) { | ||
const win = doc.defaultView || (doc.ownerDocument && doc.ownerDocument.defaultView) || window; | ||
return uniq_1( | ||
@@ -573,8 +589,8 @@ Array.from(styleSheet.cssRules || []).reduce((acc, rule) => { | ||
function makeExtractResourceUrlsFromStyleTags(extractResourcesFromStyleSheet) { | ||
return function extractResourceUrlsFromStyleTags(doc) { | ||
return function extractResourceUrlsFromStyleTags(doc, onlyDocStylesheet = true) { | ||
return uniq_1( | ||
Array.from(doc.querySelectorAll('style')).reduce((resourceUrls, styleEl) => { | ||
const styleSheet = Array.from(doc.styleSheets).find( | ||
styleSheet => styleSheet.ownerNode === styleEl, | ||
); | ||
const styleSheet = onlyDocStylesheet | ||
? Array.from(doc.styleSheets).find(styleSheet => styleSheet.ownerNode === styleEl) | ||
: styleEl.sheet; | ||
return styleSheet | ||
@@ -662,4 +678,8 @@ ? resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc)) | ||
const extractResourcesFromStyleSheet$$1 = extractResourcesFromStyleSheet({styleSheetCache}); | ||
const extractResourcesFromSvg = makeExtractResourcesFromSvg_1({}); | ||
const findStyleSheetByUrl$$1 = findStyleSheetByUrl({styleSheetCache}); | ||
const extractResourceUrlsFromStyleTags$$1 = extractResourceUrlsFromStyleTags( | ||
extractResourcesFromStyleSheet$$1, | ||
); | ||
const extractResourcesFromSvg = makeExtractResourcesFromSvg_1({extractResourceUrlsFromStyleTags: extractResourceUrlsFromStyleTags$$1}); | ||
const processResource$$1 = processResource({ | ||
@@ -678,6 +698,2 @@ fetchUrl: fetchUrl_1, | ||
const extractResourceUrlsFromStyleTags$$1 = extractResourceUrlsFromStyleTags( | ||
extractResourcesFromStyleSheet$$1, | ||
); | ||
return doProcessPage(doc); | ||
@@ -687,6 +703,6 @@ | ||
const url = baesUrl || getBaseUrl(doc); | ||
const {cdt, documents, canvasElements, inlineFrames} = domNodesToCdt_1(doc, url); | ||
const {cdt, docRoots, canvasElements, inlineFrames} = domNodesToCdt_1(doc, url); | ||
const linkUrls = flat_1(documents.map(extractLinks_1)); | ||
const styleTagUrls = flat_1(documents.map(extractResourceUrlsFromStyleTags$$1)); | ||
const linkUrls = flat_1(docRoots.map(extractLinks_1)); | ||
const styleTagUrls = flat_1(docRoots.map(extractResourceUrlsFromStyleTags$$1)); | ||
const absolutizeThisUrl = getAbsolutizeByUrl(url); | ||
@@ -703,6 +719,6 @@ const links = uniq_1( | ||
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(documents, url, links); | ||
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(docRoots, url, links); | ||
const canvasBlobs = buildCanvasBlobs_1(canvasElements); | ||
const frameDocs = extractFrames_1(documents); | ||
const frameDocs = extractFrames_1(docRoots); | ||
const processFramesPromise = frameDocs.map(f => doProcessPage(f, null)); | ||
@@ -709,0 +725,0 @@ const processInlineFramesPromise = inlineFrames.map(({element, url}) => |
@@ -1,2 +0,2 @@ | ||
/* @applitools/dom-snapshot@1.4.4 */ | ||
/* @applitools/dom-snapshot@1.4.5 */ | ||
'use strict'; | ||
@@ -66,3 +66,3 @@ | ||
const cdt = [{nodeType: Node.DOCUMENT_NODE}]; | ||
const documents = [docNode]; | ||
const docRoots = [docNode]; | ||
const canvasElements = []; | ||
@@ -72,3 +72,3 @@ const inlineFrames = []; | ||
cdt[0].childNodeIndexes = childrenFactory(cdt, docNode.childNodes); | ||
return {cdt, documents, canvasElements, inlineFrames}; | ||
return {cdt, docRoots, canvasElements, inlineFrames}; | ||
@@ -111,3 +111,3 @@ function childrenFactory(cdt, elementNodes) { | ||
node.shadowRootIndex = elementNodeFactory(cdt, elementNode.shadowRoot); | ||
documents.push(elementNode.shadowRoot); | ||
docRoots.push(elementNode.shadowRoot); | ||
} | ||
@@ -397,3 +397,21 @@ | ||
function makeExtractResourcesFromSvg({parser, decoder}) { | ||
function getUrlFromCssText(cssText) { | ||
const re = /url\((?!['"]?:)['"]?([^'")]*)['"]?\)/g; | ||
const ret = []; | ||
let result; | ||
while ((result = re.exec(cssText)) !== null) { | ||
ret.push(result[1]); | ||
} | ||
return ret; | ||
} | ||
var getUrlFromCssText_1 = getUrlFromCssText; | ||
function flat(arr) { | ||
return [].concat(...arr); | ||
} | ||
var flat_1 = flat; | ||
function makeExtractResourcesFromSvg({parser, decoder, extractResourceUrlsFromStyleTags}) { | ||
return function(svgArrayBuffer) { | ||
@@ -414,3 +432,10 @@ let svgStr; | ||
); | ||
urls = fromImages.concat(fromObjects).filter(u => u[0] !== '#'); | ||
const fromStyleTags = extractResourceUrlsFromStyleTags(doc, false); | ||
const fromStyleAttrs = urlsFromStyleAttrOfDoc(doc); | ||
urls = fromImages | ||
.concat(fromObjects) | ||
.concat(fromStyleTags) | ||
.concat(fromStyleAttrs) | ||
.filter(u => u[0] !== '#'); | ||
} catch (e) { | ||
@@ -423,2 +448,11 @@ console.log('could not parse svg content', e); | ||
function urlsFromStyleAttrOfDoc(doc) { | ||
return flat_1( | ||
Array.from(doc.querySelectorAll('*[style]')) | ||
.map(e => e.style.cssText) | ||
.map(getUrlFromCssText_1) | ||
.filter(Boolean), | ||
); | ||
} | ||
var makeExtractResourcesFromSvg_1 = makeExtractResourcesFromSvg; | ||
@@ -442,8 +476,2 @@ | ||
function flat(arr) { | ||
return [].concat(...arr); | ||
} | ||
var flat_1 = flat; | ||
function makeFindStyleSheetByUrl({styleSheetCache}) { | ||
@@ -461,17 +489,5 @@ return function findStyleSheetByUrl(url, documents) { | ||
function getUrlFromCssText(cssText) { | ||
const re = /url\((?!['"]?:)['"]?([^'")]*)['"]?\)/g; | ||
const ret = []; | ||
let result; | ||
while ((result = re.exec(cssText)) !== null) { | ||
ret.push(result[1]); | ||
} | ||
return ret; | ||
} | ||
var getUrlFromCssText_1 = getUrlFromCssText; | ||
function makeExtractResourcesFromStyleSheet({styleSheetCache}) { | ||
return function extractResourcesFromStyleSheet(styleSheet, doc = document) { | ||
const win = doc.defaultView || doc.ownerDocument.defaultView; | ||
return function extractResourcesFromStyleSheet(styleSheet, doc) { | ||
const win = doc.defaultView || (doc.ownerDocument && doc.ownerDocument.defaultView) || window; | ||
return uniq_1( | ||
@@ -518,8 +534,8 @@ Array.from(styleSheet.cssRules || []).reduce((acc, rule) => { | ||
function makeExtractResourceUrlsFromStyleTags(extractResourcesFromStyleSheet) { | ||
return function extractResourceUrlsFromStyleTags(doc) { | ||
return function extractResourceUrlsFromStyleTags(doc, onlyDocStylesheet = true) { | ||
return uniq_1( | ||
Array.from(doc.querySelectorAll('style')).reduce((resourceUrls, styleEl) => { | ||
const styleSheet = Array.from(doc.styleSheets).find( | ||
styleSheet => styleSheet.ownerNode === styleEl, | ||
); | ||
const styleSheet = onlyDocStylesheet | ||
? Array.from(doc.styleSheets).find(styleSheet => styleSheet.ownerNode === styleEl) | ||
: styleEl.sheet; | ||
return styleSheet | ||
@@ -607,4 +623,8 @@ ? resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc)) | ||
const extractResourcesFromStyleSheet$$1 = extractResourcesFromStyleSheet({styleSheetCache}); | ||
const extractResourcesFromSvg = makeExtractResourcesFromSvg_1({}); | ||
const findStyleSheetByUrl$$1 = findStyleSheetByUrl({styleSheetCache}); | ||
const extractResourceUrlsFromStyleTags$$1 = extractResourceUrlsFromStyleTags( | ||
extractResourcesFromStyleSheet$$1, | ||
); | ||
const extractResourcesFromSvg = makeExtractResourcesFromSvg_1({extractResourceUrlsFromStyleTags: extractResourceUrlsFromStyleTags$$1}); | ||
const processResource$$1 = processResource({ | ||
@@ -623,6 +643,2 @@ fetchUrl: fetchUrl_1, | ||
const extractResourceUrlsFromStyleTags$$1 = extractResourceUrlsFromStyleTags( | ||
extractResourcesFromStyleSheet$$1, | ||
); | ||
return doProcessPage(doc); | ||
@@ -632,6 +648,6 @@ | ||
const url = baesUrl || getBaseUrl(doc); | ||
const {cdt, documents, canvasElements, inlineFrames} = domNodesToCdt_1(doc, url); | ||
const {cdt, docRoots, canvasElements, inlineFrames} = domNodesToCdt_1(doc, url); | ||
const linkUrls = flat_1(documents.map(extractLinks_1)); | ||
const styleTagUrls = flat_1(documents.map(extractResourceUrlsFromStyleTags$$1)); | ||
const linkUrls = flat_1(docRoots.map(extractLinks_1)); | ||
const styleTagUrls = flat_1(docRoots.map(extractResourceUrlsFromStyleTags$$1)); | ||
const absolutizeThisUrl = getAbsolutizeByUrl(url); | ||
@@ -648,6 +664,6 @@ const links = uniq_1( | ||
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(documents, url, links); | ||
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs$$1(docRoots, url, links); | ||
const canvasBlobs = buildCanvasBlobs_1(canvasElements); | ||
const frameDocs = extractFrames_1(documents); | ||
const frameDocs = extractFrames_1(docRoots); | ||
const processFramesPromise = frameDocs.map(f => doProcessPage(f, null)); | ||
@@ -654,0 +670,0 @@ const processInlineFramesPromise = inlineFrames.map(({element, url}) => |
{ | ||
"name": "@applitools/dom-snapshot", | ||
"version": "1.4.5", | ||
"version": "1.4.6", | ||
"main": "index.js", | ||
@@ -52,4 +52,3 @@ "license": "MIT", | ||
"url-polyfill": "^1.1.5", | ||
"whatwg-fetch": "^3.0.0", | ||
"xmldom": "^0.1.27" | ||
"whatwg-fetch": "^3.0.0" | ||
}, | ||
@@ -56,0 +55,0 @@ "dependencies": { |
@@ -9,3 +9,3 @@ /* eslint-disable no-use-before-define */ | ||
const cdt = [{nodeType: Node.DOCUMENT_NODE}]; | ||
const documents = [docNode]; | ||
const docRoots = [docNode]; | ||
const canvasElements = []; | ||
@@ -15,3 +15,3 @@ const inlineFrames = []; | ||
cdt[0].childNodeIndexes = childrenFactory(cdt, docNode.childNodes); | ||
return {cdt, documents, canvasElements, inlineFrames}; | ||
return {cdt, docRoots, canvasElements, inlineFrames}; | ||
@@ -54,3 +54,3 @@ function childrenFactory(cdt, elementNodes) { | ||
node.shadowRootIndex = elementNodeFactory(cdt, elementNode.shadowRoot); | ||
documents.push(elementNode.shadowRoot); | ||
docRoots.push(elementNode.shadowRoot); | ||
} | ||
@@ -57,0 +57,0 @@ |
@@ -6,4 +6,4 @@ 'use strict'; | ||
function makeExtractResourcesFromStyleSheet({styleSheetCache}) { | ||
return function extractResourcesFromStyleSheet(styleSheet, doc = document) { | ||
const win = doc.defaultView || doc.ownerDocument.defaultView; | ||
return function extractResourcesFromStyleSheet(styleSheet, doc) { | ||
const win = doc.defaultView || (doc.ownerDocument && doc.ownerDocument.defaultView) || window; | ||
return uniq( | ||
@@ -10,0 +10,0 @@ Array.from(styleSheet.cssRules || []).reduce((acc, rule) => { |
@@ -5,8 +5,8 @@ 'use strict'; | ||
function makeExtractResourceUrlsFromStyleTags(extractResourcesFromStyleSheet) { | ||
return function extractResourceUrlsFromStyleTags(doc) { | ||
return function extractResourceUrlsFromStyleTags(doc, onlyDocStylesheet = true) { | ||
return uniq( | ||
Array.from(doc.querySelectorAll('style')).reduce((resourceUrls, styleEl) => { | ||
const styleSheet = Array.from(doc.styleSheets).find( | ||
styleSheet => styleSheet.ownerNode === styleEl, | ||
); | ||
const styleSheet = onlyDocStylesheet | ||
? Array.from(doc.styleSheets).find(styleSheet => styleSheet.ownerNode === styleEl) | ||
: styleEl.sheet; | ||
return styleSheet | ||
@@ -13,0 +13,0 @@ ? resourceUrls.concat(extractResourcesFromStyleSheet(styleSheet, doc)) |
'use strict'; | ||
const getUrlFromCssText = require('./getUrlFromCssText'); | ||
const flat = require('./flat'); | ||
function makeExtractResourcesFromSvg({parser, decoder}) { | ||
function makeExtractResourcesFromSvg({parser, decoder, extractResourceUrlsFromStyleTags}) { | ||
return function(svgArrayBuffer) { | ||
@@ -19,3 +21,10 @@ let svgStr; | ||
); | ||
urls = fromImages.concat(fromObjects).filter(u => u[0] !== '#'); | ||
const fromStyleTags = extractResourceUrlsFromStyleTags(doc, false); | ||
const fromStyleAttrs = urlsFromStyleAttrOfDoc(doc); | ||
urls = fromImages | ||
.concat(fromObjects) | ||
.concat(fromStyleTags) | ||
.concat(fromStyleAttrs) | ||
.filter(u => u[0] !== '#'); | ||
} catch (e) { | ||
@@ -28,2 +37,11 @@ console.log('could not parse svg content', e); | ||
function urlsFromStyleAttrOfDoc(doc) { | ||
return flat( | ||
Array.from(doc.querySelectorAll('*[style]')) | ||
.map(e => e.style.cssText) | ||
.map(getUrlFromCssText) | ||
.filter(Boolean), | ||
); | ||
} | ||
module.exports = makeExtractResourcesFromSvg; |
@@ -26,4 +26,8 @@ 'use strict'; | ||
const extractResourcesFromStyleSheet = makeExtractResourcesFromStyleSheet({styleSheetCache}); | ||
const extractResourcesFromSvg = makeExtractResourcesFromSvg({}); | ||
const findStyleSheetByUrl = makeFindStyleSheetByUrl({styleSheetCache}); | ||
const extractResourceUrlsFromStyleTags = makeExtractResourceUrlsFromStyleTags( | ||
extractResourcesFromStyleSheet, | ||
); | ||
const extractResourcesFromSvg = makeExtractResourcesFromSvg({extractResourceUrlsFromStyleTags}); | ||
const processResource = makeProcessResource({ | ||
@@ -42,6 +46,2 @@ fetchUrl, | ||
const extractResourceUrlsFromStyleTags = makeExtractResourceUrlsFromStyleTags( | ||
extractResourcesFromStyleSheet, | ||
); | ||
return doProcessPage(doc); | ||
@@ -51,6 +51,6 @@ | ||
const url = baesUrl || getBaesUrl(doc); | ||
const {cdt, documents, canvasElements, inlineFrames} = domNodesToCdt(doc, url); | ||
const {cdt, docRoots, canvasElements, inlineFrames} = domNodesToCdt(doc, url); | ||
const linkUrls = flat(documents.map(extractLinks)); | ||
const styleTagUrls = flat(documents.map(extractResourceUrlsFromStyleTags)); | ||
const linkUrls = flat(docRoots.map(extractLinks)); | ||
const styleTagUrls = flat(docRoots.map(extractResourceUrlsFromStyleTags)); | ||
const absolutizeThisUrl = getAbsolutizeByUrl(url); | ||
@@ -67,6 +67,6 @@ const links = uniq( | ||
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs(documents, url, links); | ||
const resourceUrlsAndBlobsPromise = getResourceUrlsAndBlobs(docRoots, url, links); | ||
const canvasBlobs = buildCanvasBlobs(canvasElements); | ||
const frameDocs = extractFrames(documents); | ||
const frameDocs = extractFrames(docRoots); | ||
const processFramesPromise = frameDocs.map(f => doProcessPage(f, null)); | ||
@@ -73,0 +73,0 @@ const processInlineFramesPromise = inlineFrames.map(({element, url}) => |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
583758
28
12400