Skip to content

Commit 4177e18

Browse files
eoghanmurraygithub-actions[bot]
authored andcommitted
Apply formatting changes
1 parent ff52332 commit 4177e18

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

packages/rrweb-snapshot/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import snapshot, {
99
IGNORED_NODE,
1010
genId,
1111
} from './snapshot';
12-
import rebuild, {
13-
buildNodeWithSN,
14-
createCache,
15-
} from './rebuild';
12+
import rebuild, { buildNodeWithSN, createCache } from './rebuild';
1613
export * from './types';
1714
export * from './utils';
1815

packages/rrweb-snapshot/src/rebuild.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,35 @@ export function adaptStylesheetForReplay(cssRules: CSSRuleList) {
102102
for (const cssRule of cssRules) {
103103
if ('media' in cssRule) {
104104
const cssMediaRule = cssRule as CSSMediaRule;
105-
if (cssMediaRule.media.mediaText &&
106-
MEDIA_SELECTOR.test(cssMediaRule.media.mediaText)) {
105+
if (
106+
cssMediaRule.media.mediaText &&
107+
MEDIA_SELECTOR.test(cssMediaRule.media.mediaText)
108+
) {
107109
// not attempting to maintain min-device-width along with min-width
108-
// (it's non standard)
109-
cssMediaRule.media.mediaText =
110-
cssMediaRule.media.mediaText.replace(MEDIA_SELECTOR_GLOBAL, '$1-$2');
110+
// (it's non standard)
111+
cssMediaRule.media.mediaText = cssMediaRule.media.mediaText.replace(
112+
MEDIA_SELECTOR_GLOBAL,
113+
'$1-$2',
114+
);
111115
}
112116
} else if ('selectorText' in cssRule) {
113117
const cssStyleRule = cssRule as CSSStyleRule;
114-
if (cssStyleRule.selectorText &&
115-
HOVER_SELECTOR.test(cssStyleRule.selectorText)) {
116-
cssStyleRule.selectorText = splitSelector(cssStyleRule.selectorText).map((selector) => {
117-
if (!HOVER_SELECTOR.test(selector)) {
118-
return selector;
119-
}
120-
const newSelector = selector.replace(
121-
HOVER_SELECTOR_GLOBAL,
122-
'$1.\\:hover',
123-
);
124-
return `${selector}, ${newSelector}`;
125-
}).join(', ');
118+
if (
119+
cssStyleRule.selectorText &&
120+
HOVER_SELECTOR.test(cssStyleRule.selectorText)
121+
) {
122+
cssStyleRule.selectorText = splitSelector(cssStyleRule.selectorText)
123+
.map((selector) => {
124+
if (!HOVER_SELECTOR.test(selector)) {
125+
return selector;
126+
}
127+
const newSelector = selector.replace(
128+
HOVER_SELECTOR_GLOBAL,
129+
'$1.\\:hover',
130+
);
131+
return `${selector}, ${newSelector}`;
132+
})
133+
.join(', ');
126134
}
127135
}
128136
if ('cssRules' in cssRule) {
@@ -499,7 +507,11 @@ export function buildNodeWithSN(
499507
} else {
500508
node.appendChild(childNode);
501509
}
502-
if (hackCss && childN.type === NodeType.Element && childN.tagName === 'STYLE') {
510+
if (
511+
hackCss &&
512+
childN.type === NodeType.Element &&
513+
childN.tagName === 'STYLE'
514+
) {
503515
const styleEl = childNode as HTMLStyleElement;
504516
if (styleEl.sheet) {
505517
adaptStylesheetForReplay(styleEl.sheet.cssRules);

packages/rrweb-snapshot/test/rebuild.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import { NodeType } from '../src/types';
1212
import { createMirror, Mirror, stringifyStylesheet } from '../src/utils';
1313

14-
1514
/*
1615
function toEqualCss(actual: string, expected: string) {
1716
const pass = actual.replace(/\s/g, '') === expected.replace(/\s/g, '');
@@ -43,7 +42,7 @@ expect.extend({
4342
});
4443
*/
4544

46-
export function adaptCssForReplay(cssText: string): string {
45+
export function adaptCssForReplay(cssText: string): string {
4746
let tempStyleSheet = new CSSStyleSheet();
4847
if (tempStyleSheet.replaceSync) {
4948
tempStyleSheet.replaceSync(cssText);
@@ -57,7 +56,7 @@ export function adaptCssForReplay(cssText: string): string {
5756
return "error: can't find sheet";
5857
}
5958
}
60-
adaptStylesheetForReplay(tempStyleSheet.cssRules);
59+
adaptStylesheetForReplay(tempStyleSheet.cssRules);
6160
let ss = stringifyStylesheet(tempStyleSheet);
6261
if (!ss) {
6362
return 'error' + tempStyleSheet.cssRules.length;
@@ -205,7 +204,9 @@ ul li.specified c.\\:hover img { color: white }`),
205204
it('can add hover class when there is a multi selector with the same prefix', () => {
206205
const cssText = '.a:hover, .a:hover::after { color: white }';
207206
expect(adaptCssForReplay(cssText, cache)).toEqual(
208-
norm('.a:hover, .a.\\:hover, .a:hover::after, .a.\\:hover::after { color: white }'),
207+
norm(
208+
'.a:hover, .a.\\:hover, .a:hover::after, .a.\\:hover::after { color: white }',
209+
),
209210
);
210211
});
211212

@@ -232,7 +233,9 @@ ul li.specified c.\\:hover img { color: white }`),
232233
const cssText =
233234
'@media only screen and (min-device-width : 1200px) { .a { width: 10px; }}';
234235
expect(adaptCssForReplay(cssText, cache)).toEqual(
235-
norm('@media only screen and (min-width : 1200px) { .a { width: 10px; }}'),
236+
norm(
237+
'@media only screen and (min-width : 1200px) { .a { width: 10px; }}',
238+
),
236239
);
237240
});
238241

0 commit comments

Comments
 (0)