@@ -5,10 +5,11 @@ import {
5
5
attributes ,
6
6
INode ,
7
7
idNodeMap ,
8
+ MaskInputOptions ,
8
9
} from './types' ;
9
10
10
11
let _id = 1 ;
11
- const symbolAndNumberRegex = RegExp ( '[^a-z1-6\ -]' ) ;
12
+ const symbolAndNumberRegex = RegExp ( '[^a-z1-6-]' ) ;
12
13
13
14
function genId ( ) : number {
14
15
return _id ++ ;
@@ -32,9 +33,9 @@ function getCssRulesString(s: CSSStyleSheet): string | null {
32
33
const rules = s . rules || s . cssRules ;
33
34
return rules
34
35
? Array . from ( rules ) . reduce (
35
- ( prev , cur ) => prev + getCssRuleString ( cur ) ,
36
- '' ,
37
- )
36
+ ( prev , cur ) => prev + getCssRuleString ( cur ) ,
37
+ '' ,
38
+ )
38
39
: null ;
39
40
} catch ( error ) {
40
41
return null ;
@@ -54,10 +55,7 @@ function isCSSImportRule(rule: CSSRule): rule is CSSImportRule {
54
55
function extractOrigin ( url : string ) : string {
55
56
let origin ;
56
57
if ( url . indexOf ( '//' ) > - 1 ) {
57
- origin = url
58
- . split ( '/' )
59
- . slice ( 0 , 3 )
60
- . join ( '/' ) ;
58
+ origin = url . split ( '/' ) . slice ( 0 , 3 ) . join ( '/' ) ;
61
59
} else {
62
60
origin = url . split ( '/' ) [ 0 ] ;
63
61
}
@@ -114,7 +112,7 @@ function getAbsoluteSrcsetString(doc: Document, attributeValue: string) {
114
112
// srcset attributes is defined as such:
115
113
// srcset = "url size,url1 size1"
116
114
const resultingSrcsetString = srcsetValues
117
- . map ( srcItem => {
115
+ . map ( ( srcItem ) => {
118
116
// removing all but middle spaces
119
117
const trimmedSrcItem = srcItem . trimLeft ( ) . trimRight ( ) ;
120
118
const urlAndSize = trimmedSrcItem . split ( ' ' ) ;
@@ -168,7 +166,7 @@ function serializeNode(
168
166
doc : Document ,
169
167
blockClass : string | RegExp ,
170
168
inlineStylesheet : boolean ,
171
- maskAllInputs : boolean ,
169
+ maskInputOptions : MaskInputOptions = { } ,
172
170
) : serializedNode | false {
173
171
switch ( n . nodeType ) {
174
172
case n . DOCUMENT_NODE :
@@ -188,7 +186,7 @@ function serializeNode(
188
186
if ( typeof blockClass === 'string' ) {
189
187
needBlock = ( n as HTMLElement ) . classList . contains ( blockClass ) ;
190
188
} else {
191
- ( n as HTMLElement ) . classList . forEach ( className => {
189
+ ( n as HTMLElement ) . classList . forEach ( ( className ) => {
192
190
if ( blockClass . test ( className ) ) {
193
191
needBlock = true ;
194
192
}
@@ -201,7 +199,7 @@ function serializeNode(
201
199
}
202
200
// remote css
203
201
if ( tagName === 'link' && inlineStylesheet ) {
204
- const stylesheet = Array . from ( doc . styleSheets ) . find ( s => {
202
+ const stylesheet = Array . from ( doc . styleSheets ) . find ( ( s ) => {
205
203
return s . href === ( n as HTMLLinkElement ) . href ;
206
204
} ) ;
207
205
const cssText = getCssRulesString ( stylesheet as CSSStyleSheet ) ;
@@ -246,7 +244,11 @@ function serializeNode(
246
244
attributes . type !== 'button' &&
247
245
value
248
246
) {
249
- attributes . value = maskAllInputs ? '*' . repeat ( value . length ) : value ;
247
+ attributes . value = maskInputOptions [
248
+ attributes . type as keyof MaskInputOptions
249
+ ]
250
+ ? '*' . repeat ( value . length )
251
+ : value ;
250
252
} else if ( ( n as HTMLInputElement ) . checked ) {
251
253
attributes . checked = ( n as HTMLInputElement ) . checked ;
252
254
}
@@ -320,14 +322,14 @@ export function serializeNodeWithId(
320
322
blockClass : string | RegExp ,
321
323
skipChild = false ,
322
324
inlineStylesheet = true ,
323
- maskAllInputs = false ,
325
+ maskInputOptions ?: MaskInputOptions ,
324
326
) : serializedNodeWithId | null {
325
327
const _serializedNode = serializeNode (
326
328
n ,
327
329
doc ,
328
330
blockClass ,
329
331
inlineStylesheet ,
330
- maskAllInputs ,
332
+ maskInputOptions ,
331
333
) ;
332
334
if ( ! _serializedNode ) {
333
335
// TODO: dev only
@@ -363,7 +365,7 @@ export function serializeNodeWithId(
363
365
blockClass ,
364
366
skipChild ,
365
367
inlineStylesheet ,
366
- maskAllInputs ,
368
+ maskInputOptions ,
367
369
) ;
368
370
if ( serializedChildNode ) {
369
371
serializedNode . childNodes . push ( serializedChildNode ) ;
@@ -377,9 +379,29 @@ function snapshot(
377
379
n : Document ,
378
380
blockClass : string | RegExp = 'rr-block' ,
379
381
inlineStylesheet = true ,
380
- maskAllInputs = false ,
382
+ maskAllInputsOrOptions : boolean | MaskInputOptions ,
381
383
) : [ serializedNodeWithId | null , idNodeMap ] {
382
384
const idNodeMap : idNodeMap = { } ;
385
+ const maskInputOptions : MaskInputOptions =
386
+ maskAllInputsOrOptions === true
387
+ ? {
388
+ color : true ,
389
+ date : true ,
390
+ 'datetime-local' : true ,
391
+ email : true ,
392
+ month : true ,
393
+ number : true ,
394
+ range : true ,
395
+ search : true ,
396
+ tel : true ,
397
+ text : true ,
398
+ time : true ,
399
+ url : true ,
400
+ week : true ,
401
+ }
402
+ : maskAllInputsOrOptions === false
403
+ ? { }
404
+ : maskAllInputsOrOptions ;
383
405
return [
384
406
serializeNodeWithId (
385
407
n ,
@@ -388,7 +410,7 @@ function snapshot(
388
410
blockClass ,
389
411
false ,
390
412
inlineStylesheet ,
391
- maskAllInputs ,
413
+ maskInputOptions ,
392
414
) ,
393
415
idNodeMap ,
394
416
] ;
0 commit comments