@percy/dom
Advanced tools
Comparing version 1.27.0-alpha.0 to 1.27.0-beta.0
@@ -198,2 +198,7 @@ (function() { | ||
} | ||
function createStyleResource(styleSheet) { | ||
const styles = Array.from(styleSheet.cssRules).map(cssRule => cssRule.cssText).join('\n'); | ||
let resource = resourceFromText(uid(), 'text/css', styles); | ||
return resource; | ||
} | ||
function serializeCSSOM(_ref) { | ||
@@ -204,6 +209,8 @@ let { | ||
resources, | ||
cache | ||
cache, | ||
warnings | ||
} = _ref; | ||
// in-memory CSSOM into their respective DOM nodes. | ||
for (let styleSheet of dom.styleSheets) { | ||
var _styleSheet$href; | ||
if (isCSSOM(styleSheet)) { | ||
@@ -220,2 +227,17 @@ let styleId = styleSheet.ownerNode.getAttribute('data-percy-element-id'); | ||
cloneOwnerNode.remove(); | ||
} else if ((_styleSheet$href = styleSheet.href) !== null && _styleSheet$href !== void 0 && _styleSheet$href.startsWith('blob:')) { | ||
const styleLink = document.createElement('link'); | ||
styleLink.setAttribute('rel', 'stylesheet'); | ||
let resource = createStyleResource(styleSheet); | ||
resources.add(resource); | ||
styleLink.setAttribute('data-percy-blob-stylesheets-serialized', 'true'); | ||
styleLink.setAttribute('data-percy-serialized-attribute-href', resource.url); | ||
/* istanbul ignore next: tested, but coverage is stripped */ | ||
if (clone.constructor.name === 'HTMLDocument' || clone.constructor.name === 'DocumentFragment') { | ||
// handle document and iframe | ||
clone.body.prepend(styleLink); | ||
} else if (clone.constructor.name === 'ShadowRoot') { | ||
clone.prepend(styleLink); | ||
} | ||
} | ||
@@ -226,21 +248,25 @@ } | ||
// Regarding ordering of the adopted stylesheets - https://github.com/WICG/construct-stylesheets/issues/93 | ||
for (let sheet of dom.adoptedStyleSheets) { | ||
const styleLink = document.createElement('link'); | ||
styleLink.setAttribute('rel', 'stylesheet'); | ||
if (!cache.has(sheet)) { | ||
const styles = Array.from(sheet.cssRules).map(cssRule => cssRule.cssText).join('\n'); | ||
let resource = resourceFromText(uid(), 'text/css', styles); | ||
resources.add(resource); | ||
cache.set(sheet, resource.url); | ||
} | ||
styleLink.setAttribute('data-percy-adopted-stylesheets-serialized', 'true'); | ||
styleLink.setAttribute('data-percy-serialized-attribute-href', cache.get(sheet)); | ||
/* istanbul ignore next: tested, but coverage is stripped */ | ||
if (dom.adoptedStyleSheets) { | ||
for (let sheet of dom.adoptedStyleSheets) { | ||
const styleLink = document.createElement('link'); | ||
styleLink.setAttribute('rel', 'stylesheet'); | ||
if (!cache.has(sheet)) { | ||
let resource = createStyleResource(sheet); | ||
resources.add(resource); | ||
cache.set(sheet, resource.url); | ||
} | ||
styleLink.setAttribute('data-percy-adopted-stylesheets-serialized', 'true'); | ||
styleLink.setAttribute('data-percy-serialized-attribute-href', cache.get(sheet)); | ||
/* istanbul ignore next: tested, but coverage is stripped */ | ||
if (clone.constructor.name === 'HTMLDocument' || clone.constructor.name === 'DocumentFragment') { | ||
// handle document and iframe | ||
clone.body.prepend(styleLink); | ||
} else if (clone.constructor.name === 'ShadowRoot') { | ||
clone.prepend(styleLink); | ||
/* istanbul ignore next: tested, but coverage is stripped */ | ||
if (clone.constructor.name === 'HTMLDocument' || clone.constructor.name === 'DocumentFragment') { | ||
// handle document and iframe | ||
clone.body.prepend(styleLink); | ||
} else if (clone.constructor.name === 'ShadowRoot') { | ||
clone.prepend(styleLink); | ||
} | ||
} | ||
} else { | ||
warnings.add('Skipping `adoptedStyleSheets` as it is not supported.'); | ||
} | ||
@@ -247,0 +273,0 @@ } |
{ | ||
"name": "@percy/dom", | ||
"version": "1.27.0-alpha.0", | ||
"version": "1.27.0-beta.0", | ||
"license": "MIT", | ||
@@ -12,3 +12,3 @@ "repository": { | ||
"access": "public", | ||
"tag": "latest" | ||
"tag": "beta" | ||
}, | ||
@@ -39,3 +39,3 @@ "main": "dist/bundle.js", | ||
}, | ||
"gitHead": "48f85a08c19aa274a3576c477fbdb9647310ef82" | ||
"gitHead": "2bc16314f51dddcc1cda459e7aa4b7b2db85f00a" | ||
} |
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
29190
534