@percy/dom 1.31.3-beta.0 → 1.31.3-beta.2

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 +38 -21
  2. package/package.json +2 -2
package/dist/bundle.js CHANGED
@@ -39,19 +39,22 @@
39
39
  }
40
40
  function styleSheetFromNode(node) {
41
41
  /* istanbul ignore if: sanity check */
42
- if (node.sheet) return node.sheet;
43
-
44
- // Cloned style nodes don't have a sheet instance unless they are within
45
- // a document; we get it by temporarily adding the rules to DOM
46
- const tempStyle = node.cloneNode();
47
- tempStyle.setAttribute('data-percy-style-helper', '');
48
- tempStyle.innerHTML = node.innerHTML;
49
- const clone = document.cloneNode();
50
- clone.appendChild(tempStyle);
51
- const sheet = tempStyle.sheet;
52
- // Cleanup node
53
- tempStyle.remove();
54
- return sheet;
42
+ try {
43
+ if (node.sheet) return node.sheet;
44
+ // Cloned style nodes don't have a sheet instance unless they are within
45
+ // a document; we get it by temporarily adding the rules to DOM
46
+ const scratch = document.implementation.createHTMLDocument('percy-scratch');
47
+ const tempStyle = node.cloneNode();
48
+ tempStyle.setAttribute('data-percy-style-helper', '');
49
+ tempStyle.textContent = node.textContent || '';
50
+ scratch.head.appendChild(tempStyle);
51
+ const sheet = tempStyle.sheet;
52
+ // Cleanup node
53
+ tempStyle.remove();
54
+ return sheet;
55
+ } catch (err) {
56
+ handleErrors(err, 'Failed to get stylesheet from node: ', node);
57
+ }
55
58
  }
56
59
  function rewriteLocalhostURL(url) {
57
60
  return url.replace(/(http[s]{0,1}:\/\/)(localhost|127.0.0.1)[:\d+]*/, '$1render.percy.local');
@@ -71,8 +74,10 @@
71
74
  ...additionalData,
72
75
  ...elementData
73
76
  };
74
- error.message += `\n${prefixMessage} \n${JSON.stringify(additionalData)}`;
75
- error.message += '\n Please validate that your DOM is as per W3C standards using any online tool';
77
+ let message = error.message;
78
+ message += `\n${prefixMessage} \n${JSON.stringify(additionalData)}`;
79
+ message += '\n Please validate that your DOM is as per W3C standards using any online tool';
80
+ error.message = message;
76
81
  error.handled = true;
77
82
  throw error;
78
83
  }
@@ -115,7 +120,7 @@
115
120
  }
116
121
  break;
117
122
  case 'textarea':
118
- cloneEl.innerHTML = elem.value;
123
+ cloneEl.textContent = elem.value || '';
119
124
  break;
120
125
  default:
121
126
  cloneEl.setAttribute('value', elem.value);
@@ -223,10 +228,22 @@
223
228
 
224
229
  // Returns false if any stylesheet rules do not match between two stylesheets
225
230
  function styleSheetsMatch(sheetA, sheetB) {
226
- for (let i = 0; i < sheetA.cssRules.length; i++) {
227
- var _sheetB$cssRules$i;
228
- let ruleA = sheetA.cssRules[i].cssText;
229
- let ruleB = (_sheetB$cssRules$i = sheetB.cssRules[i]) === null || _sheetB$cssRules$i === void 0 ? void 0 : _sheetB$cssRules$i.cssText;
231
+ if (!sheetA || !sheetB) return false;
232
+ const hasOwnAccessor = (obj, prop) => {
233
+ if (!obj || typeof obj !== 'object') return false;
234
+ const desc = Object.getOwnPropertyDescriptor(obj, prop);
235
+ return !!(desc && (typeof desc.get === 'function' || typeof desc.set === 'function'));
236
+ };
237
+ if (hasOwnAccessor(sheetA, 'cssRules') || hasOwnAccessor(sheetB, 'cssRules')) {
238
+ return false;
239
+ }
240
+ if (!sheetA.cssRules || !sheetB.cssRules) return false;
241
+ const lenA = sheetA.cssRules.length;
242
+ const lenB = sheetB.cssRules.length;
243
+ if (lenA !== lenB) return false;
244
+ for (let i = 0; i < lenA; i++) {
245
+ const ruleA = sheetA.cssRules[i] && sheetA.cssRules[i].cssText;
246
+ const ruleB = sheetB.cssRules[i] && sheetB.cssRules[i].cssText;
230
247
  if (ruleA !== ruleB) return false;
231
248
  }
232
249
  return true;
@@ -266,7 +283,7 @@
266
283
  style.type = 'text/css';
267
284
  style.setAttribute('data-percy-element-id', styleId);
268
285
  style.setAttribute('data-percy-cssom-serialized', 'true');
269
- style.innerHTML = Array.from(styleSheet.cssRules).map(cssRule => cssRule.cssText).join('\n');
286
+ style.textContent = Array.from(styleSheet.cssRules).map(cssRule => cssRule.cssText).join('\n');
270
287
  cloneOwnerNode.parentNode.insertBefore(style, cloneOwnerNode.nextSibling);
271
288
  cloneOwnerNode.remove();
272
289
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/dom",
3
- "version": "1.31.3-beta.0",
3
+ "version": "1.31.3-beta.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "interactor.js": "^2.0.0-beta.10"
37
37
  },
38
- "gitHead": "5979f9463370916036b700109320b6e9f2d17bc5"
38
+ "gitHead": "88c987a1544fc803397b5298b88f7a254c729a75"
39
39
  }