@@ -34,9 +34,7 @@ function getValidTagName(tagName: string): string {
34
34
function getCssRulesString ( s : CSSStyleSheet ) : string | null {
35
35
try {
36
36
const rules = s . rules || s . cssRules ;
37
- return rules
38
- ? Array . from ( rules ) . map ( getCssRuleString ) . join ( '' )
39
- : null ;
37
+ return rules ? Array . from ( rules ) . map ( getCssRuleString ) . join ( '' ) : null ;
40
38
} catch ( error ) {
41
39
return null ;
42
40
}
@@ -74,18 +72,20 @@ export function absoluteToStylesheet(
74
72
URL_IN_CSS_REF ,
75
73
( origin , quote1 , path1 , quote2 , path2 , path3 ) => {
76
74
const filePath = path1 || path2 || path3 ;
77
- const maybe_quote = quote1 || quote2 || '' ;
75
+ const maybeQuote = quote1 || quote2 || '' ;
78
76
if ( ! filePath ) {
79
77
return origin ;
80
78
}
81
79
if ( ! RELATIVE_PATH . test ( filePath ) ) {
82
- return `url(${ maybe_quote } ${ filePath } ${ maybe_quote } )` ;
80
+ return `url(${ maybeQuote } ${ filePath } ${ maybeQuote } )` ;
83
81
}
84
82
if ( DATA_URI . test ( filePath ) ) {
85
- return `url(${ maybe_quote } ${ filePath } ${ maybe_quote } )` ;
83
+ return `url(${ maybeQuote } ${ filePath } ${ maybeQuote } )` ;
86
84
}
87
85
if ( filePath [ 0 ] === '/' ) {
88
- return `url(${ maybe_quote } ${ extractOrigin ( href ) + filePath } ${ maybe_quote } )` ;
86
+ return `url(${ maybeQuote } ${
87
+ extractOrigin ( href ) + filePath
88
+ } ${ maybeQuote } )`;
89
89
}
90
90
const stack = href . split ( '/' ) ;
91
91
const parts = filePath . split ( '/' ) ;
@@ -99,7 +99,7 @@ export function absoluteToStylesheet(
99
99
stack . push ( part ) ;
100
100
}
101
101
}
102
- return `url(${ maybe_quote } ${ stack . join ( '/' ) } ${ maybe_quote } )` ;
102
+ return `url(${ maybeQuote } ${ stack . join ( '/' ) } ${ maybeQuote } )` ;
103
103
} ,
104
104
) ;
105
105
}
@@ -179,7 +179,7 @@ export function _isBlockedElement(
179
179
} ) ;
180
180
}
181
181
if ( blockSelector ) {
182
- return element . matches ( blockSelector )
182
+ return element . matches ( blockSelector ) ;
183
183
}
184
184
185
185
return false ;
@@ -208,7 +208,11 @@ function serializeNode(
208
208
systemId : ( n as DocumentType ) . systemId ,
209
209
} ;
210
210
case n . ELEMENT_NODE :
211
- const needBlock = _isBlockedElement ( n as HTMLElement , blockClass , blockSelector ) ;
211
+ const needBlock = _isBlockedElement (
212
+ n as HTMLElement ,
213
+ blockClass ,
214
+ blockSelector ,
215
+ ) ;
212
216
const tagName = getValidTagName ( ( n as HTMLElement ) . tagName ) ;
213
217
let attributes : attributes = { } ;
214
218
for ( const { name, value } of Array . from ( ( n as HTMLElement ) . attributes ) ) {
@@ -339,76 +343,91 @@ function serializeNode(
339
343
}
340
344
}
341
345
342
- function lowerIfExists ( maybeAttr : string | number | boolean ) : string {
346
+ function lowerIfExists ( maybeAttr : string | number | boolean ) : string {
343
347
if ( maybeAttr === undefined ) {
344
348
return '' ;
345
349
} else {
346
350
return ( maybeAttr as string ) . toLowerCase ( ) ;
347
351
}
348
352
}
349
353
350
- function slimDOMExcluded ( sn : serializedNode , slimDOMOptions : SlimDOMOptions ) : boolean {
354
+ function slimDOMExcluded (
355
+ sn : serializedNode ,
356
+ slimDOMOptions : SlimDOMOptions ,
357
+ ) : boolean {
351
358
if ( slimDOMOptions . comment && sn . type === NodeType . Comment ) {
352
359
// TODO: convert IE conditional comments to real nodes
353
360
return true ;
354
361
} else if ( sn . type === NodeType . Element ) {
355
- if ( slimDOMOptions . script &&
356
- ( sn . tagName === 'script' ||
357
- ( sn . tagName === 'link' && sn . attributes . rel === 'preload' && sn . attributes [ 'as' ] === 'script' )
358
- ) ) {
362
+ if (
363
+ slimDOMOptions . script &&
364
+ ( sn . tagName === 'script' ||
365
+ ( sn . tagName === 'link' &&
366
+ sn . attributes . rel === 'preload' &&
367
+ sn . attributes . as === 'script' ) )
368
+ ) {
359
369
return true ;
360
- } else if ( slimDOMOptions . headFavicon && (
361
- ( sn . tagName === 'link' && sn . attributes . rel === 'shortcut icon' )
362
- || ( sn . tagName === 'meta' && (
363
- lowerIfExists ( sn . attributes [ 'name' ] ) . match ( / ^ m s a p p l i c a t i o n - t i l e ( i m a g e | c o l o r ) $ / )
364
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'application-name'
365
- || lowerIfExists ( sn . attributes [ 'rel' ] ) === 'icon'
366
- || lowerIfExists ( sn . attributes [ 'rel' ] ) === 'apple-touch-icon'
367
- || lowerIfExists ( sn . attributes [ 'rel' ] ) === 'shortcut icon'
368
- ) ) ) ) {
370
+ } else if (
371
+ slimDOMOptions . headFavicon &&
372
+ ( ( sn . tagName === 'link' && sn . attributes . rel === 'shortcut icon' ) ||
373
+ ( sn . tagName === 'meta' &&
374
+ ( lowerIfExists ( sn . attributes . name ) . match (
375
+ / ^ m s a p p l i c a t i o n - t i l e ( i m a g e | c o l o r ) $ / ,
376
+ ) ||
377
+ lowerIfExists ( sn . attributes . name ) === 'application-name' ||
378
+ lowerIfExists ( sn . attributes . rel ) === 'icon' ||
379
+ lowerIfExists ( sn . attributes . rel ) === 'apple-touch-icon' ||
380
+ lowerIfExists ( sn . attributes . rel ) === 'shortcut icon' ) ) )
381
+ ) {
369
382
return true ;
370
383
} else if ( sn . tagName === 'meta' ) {
371
- if ( slimDOMOptions . headMetaDescKeywords && (
372
- lowerIfExists ( sn . attributes [ 'name' ] ) . match ( / ^ d e s c r i p t i o n | k e y w o r d s $ / )
373
- ) ) {
384
+ if (
385
+ slimDOMOptions . headMetaDescKeywords &&
386
+ lowerIfExists ( sn . attributes . name ) . match ( / ^ d e s c r i p t i o n | k e y w o r d s $ / )
387
+ ) {
374
388
return true ;
375
- } else if ( slimDOMOptions . headMetaSocial && (
376
- lowerIfExists ( sn . attributes [ 'property' ] ) . match ( / ^ ( o g | t w i t t e r | f b ) : / ) // og = opengraph (facebook)
377
- || lowerIfExists ( sn . attributes [ 'name' ] ) . match ( / ^ ( o g | t w i t t e r ) : / )
378
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'pinterest'
379
- ) ) {
389
+ } else if (
390
+ slimDOMOptions . headMetaSocial &&
391
+ ( lowerIfExists ( sn . attributes . property ) . match ( / ^ ( o g | t w i t t e r | f b ) : / ) || // og = opengraph (facebook)
392
+ lowerIfExists ( sn . attributes . name ) . match ( / ^ ( o g | t w i t t e r ) : / ) ||
393
+ lowerIfExists ( sn . attributes . name ) === 'pinterest' )
394
+ ) {
380
395
return true ;
381
- } else if ( slimDOMOptions . headMetaRobots && (
382
- lowerIfExists ( sn . attributes [ 'name' ] ) === 'robots'
383
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'googlebot'
384
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'bingbot'
385
- ) ) {
396
+ } else if (
397
+ slimDOMOptions . headMetaRobots &&
398
+ ( lowerIfExists ( sn . attributes . name ) === 'robots' ||
399
+ lowerIfExists ( sn . attributes . name ) === 'googlebot' ||
400
+ lowerIfExists ( sn . attributes . name ) === 'bingbot' )
401
+ ) {
386
402
return true ;
387
- } else if ( slimDOMOptions . headMetaHttpEquiv && (
403
+ } else if (
404
+ slimDOMOptions . headMetaHttpEquiv &&
388
405
sn . attributes [ 'http-equiv' ] !== undefined
389
- ) ) {
406
+ ) {
390
407
// e.g. X-UA-Compatible, Content-Type, Content-Language,
391
408
// cache-control, X-Translated-By
392
409
return true ;
393
- } else if ( slimDOMOptions . headMetaAuthorship && (
394
- lowerIfExists ( sn . attributes [ 'name' ] ) === 'author'
395
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'generator'
396
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'framework'
397
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'publisher'
398
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'progid'
399
- || lowerIfExists ( sn . attributes [ 'property' ] ) . match ( / ^ a r t i c l e : / )
400
- || lowerIfExists ( sn . attributes [ 'property' ] ) . match ( / ^ p r o d u c t : / )
401
- ) ) {
410
+ } else if (
411
+ slimDOMOptions . headMetaAuthorship &&
412
+ ( lowerIfExists ( sn . attributes . name ) === 'author' ||
413
+ lowerIfExists ( sn . attributes . name ) === 'generator' ||
414
+ lowerIfExists ( sn . attributes . name ) === 'framework' ||
415
+ lowerIfExists ( sn . attributes . name ) === 'publisher' ||
416
+ lowerIfExists ( sn . attributes . name ) === 'progid' ||
417
+ lowerIfExists ( sn . attributes . property ) . match ( / ^ a r t i c l e : / ) ||
418
+ lowerIfExists ( sn . attributes . property ) . match ( / ^ p r o d u c t : / ) )
419
+ ) {
402
420
return true ;
403
- } else if ( slimDOMOptions . headMetaVerification && (
404
- lowerIfExists ( sn . attributes [ 'name' ] ) === 'google-site-verification'
405
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'yandex-verification'
406
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'csrf-token'
407
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'p:domain_verify'
408
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'verify-v1'
409
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'verification'
410
- || lowerIfExists ( sn . attributes [ 'name' ] ) === 'shopify-checkout-api-token'
411
- ) ) {
421
+ } else if (
422
+ slimDOMOptions . headMetaVerification &&
423
+ ( lowerIfExists ( sn . attributes . name ) === 'google-site-verification' ||
424
+ lowerIfExists ( sn . attributes . name ) === 'yandex-verification' ||
425
+ lowerIfExists ( sn . attributes . name ) === 'csrf-token' ||
426
+ lowerIfExists ( sn . attributes . name ) === 'p:domain_verify' ||
427
+ lowerIfExists ( sn . attributes . name ) === 'verify-v1' ||
428
+ lowerIfExists ( sn . attributes . name ) === 'verification' ||
429
+ lowerIfExists ( sn . attributes . name ) === 'shopify-checkout-api-token' )
430
+ ) {
412
431
return true ;
413
432
}
414
433
}
@@ -448,20 +467,21 @@ export function serializeNodeWithId(
448
467
// Try to reuse the previous id
449
468
if ( '__sn' in n ) {
450
469
id = n . __sn . id ;
451
- } else if ( slimDOMExcluded ( _serializedNode , slimDOMOptions ) ||
452
- ( ! preserveWhiteSpace &&
453
- _serializedNode . type === NodeType . Text &&
454
- ! _serializedNode . isStyle &&
455
- ! _serializedNode . textContent . replace ( / ^ \s + | \s + $ / gm, '' ) . length
456
- ) ) {
470
+ } else if (
471
+ slimDOMExcluded ( _serializedNode , slimDOMOptions ) ||
472
+ ( ! preserveWhiteSpace &&
473
+ _serializedNode . type === NodeType . Text &&
474
+ ! _serializedNode . isStyle &&
475
+ ! _serializedNode . textContent . replace ( / ^ \s + | \s + $ / gm, '' ) . length )
476
+ ) {
457
477
id = IGNORED_NODE ;
458
478
} else {
459
479
id = genId ( ) ;
460
480
}
461
481
const serializedNode = Object . assign ( _serializedNode , { id } ) ;
462
482
( n as INode ) . __sn = serializedNode ;
463
483
if ( id === IGNORED_NODE ) {
464
- return null ; // slimDOM
484
+ return null ; // slimDOM
465
485
}
466
486
map [ id ] = n as INode ;
467
487
let recordChild = ! skipChild ;
@@ -476,9 +496,9 @@ export function serializeNodeWithId(
476
496
recordChild
477
497
) {
478
498
if (
479
- ( slimDOMOptions . headWhitespace &&
480
- _serializedNode . type === NodeType . Element &&
481
- _serializedNode . tagName == 'head' )
499
+ slimDOMOptions . headWhitespace &&
500
+ _serializedNode . type === NodeType . Element &&
501
+ _serializedNode . tagName === 'head'
482
502
// would impede performance: || getComputedStyle(n)['white-space'] === 'normal'
483
503
) {
484
504
preserveWhiteSpace = false ;
@@ -538,24 +558,23 @@ function snapshot(
538
558
? { }
539
559
: maskAllInputsOrOptions ;
540
560
const slimDOMOptions : SlimDOMOptions =
541
- ( slimDOMSensibleOrOptions === true ||
542
- slimDOMSensibleOrOptions === 'all' )
543
- // if true: set of sensible options that should not throw away any information
544
- ? {
545
- script : true ,
546
- comment : true ,
547
- headFavicon : true ,
548
- headWhitespace : true ,
549
- headMetaDescKeywords : slimDOMSensibleOrOptions === 'all' , // destructive
550
- headMetaSocial : true ,
551
- headMetaRobots : true ,
552
- headMetaHttpEquiv : true ,
553
- headMetaAuthorship : true ,
554
- headMetaVerification : true ,
555
- }
556
- : slimDOMSensibleOrOptions === false
557
- ? { }
558
- : slimDOMSensibleOrOptions ;
561
+ slimDOMSensibleOrOptions === true || slimDOMSensibleOrOptions === 'all'
562
+ ? // if true: set of sensible options that should not throw away any information
563
+ {
564
+ script : true ,
565
+ comment : true ,
566
+ headFavicon : true ,
567
+ headWhitespace : true ,
568
+ headMetaDescKeywords : slimDOMSensibleOrOptions === 'all' , // destructive
569
+ headMetaSocial : true ,
570
+ headMetaRobots : true ,
571
+ headMetaHttpEquiv : true ,
572
+ headMetaAuthorship : true ,
573
+ headMetaVerification : true ,
574
+ }
575
+ : slimDOMSensibleOrOptions === false
576
+ ? { }
577
+ : slimDOMSensibleOrOptions ;
559
578
return [
560
579
serializeNodeWithId (
561
580
n ,
0 commit comments