@percy/dom 1.27.0-alpha.0 → 1.27.0-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.
Files changed (2) hide show
  1. package/dist/bundle.js +45 -19
  2. package/package.json +3 -3
package/dist/bundle.js CHANGED
@@ -195,15 +195,22 @@
195
195
  }
196
196
  return true;
197
197
  }
198
+ function createStyleResource(styleSheet) {
199
+ const styles = Array.from(styleSheet.cssRules).map(cssRule => cssRule.cssText).join('\n');
200
+ let resource = resourceFromText(uid(), 'text/css', styles);
201
+ return resource;
202
+ }
198
203
  function serializeCSSOM(_ref) {
199
204
  let {
200
205
  dom,
201
206
  clone,
202
207
  resources,
203
- cache
208
+ cache,
209
+ warnings
204
210
  } = _ref;
205
211
  // in-memory CSSOM into their respective DOM nodes.
206
212
  for (let styleSheet of dom.styleSheets) {
213
+ var _styleSheet$href;
207
214
  if (isCSSOM(styleSheet)) {
208
215
  let styleId = styleSheet.ownerNode.getAttribute('data-percy-element-id');
209
216
  let cloneOwnerNode = clone.querySelector(`[data-percy-element-id="${styleId}"]`);
@@ -215,30 +222,49 @@
215
222
  style.innerHTML = Array.from(styleSheet.cssRules).map(cssRule => cssRule.cssText).join('\n');
216
223
  cloneOwnerNode.parentNode.insertBefore(style, cloneOwnerNode.nextSibling);
217
224
  cloneOwnerNode.remove();
225
+ } else if ((_styleSheet$href = styleSheet.href) !== null && _styleSheet$href !== void 0 && _styleSheet$href.startsWith('blob:')) {
226
+ const styleLink = document.createElement('link');
227
+ styleLink.setAttribute('rel', 'stylesheet');
228
+ let resource = createStyleResource(styleSheet);
229
+ resources.add(resource);
230
+ styleLink.setAttribute('data-percy-blob-stylesheets-serialized', 'true');
231
+ styleLink.setAttribute('data-percy-serialized-attribute-href', resource.url);
232
+
233
+ /* istanbul ignore next: tested, but coverage is stripped */
234
+ if (clone.constructor.name === 'HTMLDocument' || clone.constructor.name === 'DocumentFragment') {
235
+ // handle document and iframe
236
+ clone.body.prepend(styleLink);
237
+ } else if (clone.constructor.name === 'ShadowRoot') {
238
+ clone.prepend(styleLink);
239
+ }
218
240
  }
219
241
  }
220
242
 
221
243
  // clone Adopted Stylesheets
222
244
  // Regarding ordering of the adopted stylesheets - https://github.com/WICG/construct-stylesheets/issues/93
223
- for (let sheet of dom.adoptedStyleSheets) {
224
- const styleLink = document.createElement('link');
225
- styleLink.setAttribute('rel', 'stylesheet');
226
- if (!cache.has(sheet)) {
227
- const styles = Array.from(sheet.cssRules).map(cssRule => cssRule.cssText).join('\n');
228
- let resource = resourceFromText(uid(), 'text/css', styles);
229
- resources.add(resource);
230
- cache.set(sheet, resource.url);
231
- }
232
- styleLink.setAttribute('data-percy-adopted-stylesheets-serialized', 'true');
233
- styleLink.setAttribute('data-percy-serialized-attribute-href', cache.get(sheet));
234
-
235
- /* istanbul ignore next: tested, but coverage is stripped */
236
- if (clone.constructor.name === 'HTMLDocument' || clone.constructor.name === 'DocumentFragment') {
237
- // handle document and iframe
238
- clone.body.prepend(styleLink);
239
- } else if (clone.constructor.name === 'ShadowRoot') {
240
- clone.prepend(styleLink);
245
+ /* istanbul ignore next: tested, but coverage is stripped */
246
+ if (dom.adoptedStyleSheets) {
247
+ for (let sheet of dom.adoptedStyleSheets) {
248
+ const styleLink = document.createElement('link');
249
+ styleLink.setAttribute('rel', 'stylesheet');
250
+ if (!cache.has(sheet)) {
251
+ let resource = createStyleResource(sheet);
252
+ resources.add(resource);
253
+ cache.set(sheet, resource.url);
254
+ }
255
+ styleLink.setAttribute('data-percy-adopted-stylesheets-serialized', 'true');
256
+ styleLink.setAttribute('data-percy-serialized-attribute-href', cache.get(sheet));
257
+
258
+ /* istanbul ignore next: tested, but coverage is stripped */
259
+ if (clone.constructor.name === 'HTMLDocument' || clone.constructor.name === 'DocumentFragment') {
260
+ // handle document and iframe
261
+ clone.body.prepend(styleLink);
262
+ } else if (clone.constructor.name === 'ShadowRoot') {
263
+ clone.prepend(styleLink);
264
+ }
241
265
  }
266
+ } else {
267
+ warnings.add('Skipping `adoptedStyleSheets` as it is not supported.');
242
268
  }
243
269
  }
244
270
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/dom",
3
- "version": "1.27.0-alpha.0",
3
+ "version": "1.27.0-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": "latest"
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": "48f85a08c19aa274a3576c477fbdb9647310ef82"
38
+ "gitHead": "2bc16314f51dddcc1cda459e7aa4b7b2db85f00a"
39
39
  }