@percy/dom 1.9.1 → 1.10.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 +19 -5
  2. package/package.json +2 -2
package/dist/bundle.js CHANGED
@@ -105,23 +105,37 @@
105
105
 
106
106
  // Returns true if a stylesheet is a CSSOM-based stylesheet.
107
107
  function isCSSOM(styleSheet) {
108
- var _styleSheet$ownerNode, _styleSheet$ownerNode2;
108
+ // no href, has a rulesheet, and has an owner node
109
+ return !styleSheet.href && styleSheet.cssRules && styleSheet.ownerNode;
110
+ } // Returns false if any stylesheet rules do not match between two stylesheets
109
111
 
110
- // no href, has a rulesheet, and isn't already in the DOM
111
- return !styleSheet.href && styleSheet.cssRules && !((_styleSheet$ownerNode = styleSheet.ownerNode) !== null && _styleSheet$ownerNode !== void 0 && (_styleSheet$ownerNode2 = _styleSheet$ownerNode.innerText) !== null && _styleSheet$ownerNode2 !== void 0 && _styleSheet$ownerNode2.trim().length);
112
+
113
+ function styleSheetsMatch(sheetA, sheetB) {
114
+ for (let i = 0; i < sheetA.cssRules.length; i++) {
115
+ var _sheetB$cssRules$i;
116
+
117
+ let ruleA = sheetA.cssRules[i].cssText;
118
+ let ruleB = (_sheetB$cssRules$i = sheetB.cssRules[i]) === null || _sheetB$cssRules$i === void 0 ? void 0 : _sheetB$cssRules$i.cssText;
119
+ if (ruleA !== ruleB) return false;
120
+ }
121
+
122
+ return true;
112
123
  } // Outputs in-memory CSSOM into their respective DOM nodes.
113
124
 
114
125
 
115
126
  function serializeCSSOM(dom, clone) {
116
127
  for (let styleSheet of dom.styleSheets) {
117
128
  if (isCSSOM(styleSheet)) {
118
- let style = clone.createElement('style');
119
129
  let styleId = styleSheet.ownerNode.getAttribute('data-percy-element-id');
120
130
  let cloneOwnerNode = clone.querySelector(`[data-percy-element-id="${styleId}"]`);
131
+ if (styleSheetsMatch(styleSheet, cloneOwnerNode.sheet)) continue;
132
+ let style = clone.createElement('style');
121
133
  style.type = 'text/css';
134
+ style.setAttribute('data-percy-element-id', styleId);
122
135
  style.setAttribute('data-percy-cssom-serialized', 'true');
123
- style.innerHTML = Array.from(styleSheet.cssRules).reduce((prev, cssRule) => prev + cssRule.cssText, '');
136
+ style.innerHTML = Array.from(styleSheet.cssRules).map(cssRule => cssRule.cssText).join('\n');
124
137
  cloneOwnerNode.parentNode.insertBefore(style, cloneOwnerNode.nextSibling);
138
+ cloneOwnerNode.remove();
125
139
  }
126
140
  }
127
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/dom",
3
- "version": "1.9.1",
3
+ "version": "1.10.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,5 +34,5 @@
34
34
  "devDependencies": {
35
35
  "interactor.js": "^2.0.0-beta.10"
36
36
  },
37
- "gitHead": "b2ff5100698488c8bf8c681972f4f2b9a1e2055f"
37
+ "gitHead": "66527175cdac3848157be7dd8368f5845d98e77e"
38
38
  }