@@ -32,6 +32,9 @@ const tagNameRegex = new RegExp('[^a-z0-9-_:]');
32
32
33
33
export const IGNORED_NODE = - 2 ;
34
34
35
+ const BLANK_IMAGE_SRC =
36
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAABNJREFUCB1jZGBg+A/EDEwgAgQADigBA//q6GsAAAAASUVORK5CYII%3D' ;
37
+
35
38
export function genId ( ) : number {
36
39
return _id ++ ;
37
40
}
@@ -440,6 +443,7 @@ function serializeNode(
440
443
mirror : Mirror ;
441
444
blockClass : string | RegExp ;
442
445
blockSelector : string | null ;
446
+ maskTextClass : string | RegExp ;
443
447
needsMask : boolean | undefined ;
444
448
inlineStylesheet : boolean ;
445
449
maskInputOptions : MaskInputOptions ;
@@ -460,6 +464,7 @@ function serializeNode(
460
464
mirror,
461
465
blockClass,
462
466
blockSelector,
467
+ maskTextClass,
463
468
needsMask,
464
469
inlineStylesheet,
465
470
maskInputOptions = { } ,
@@ -500,6 +505,7 @@ function serializeNode(
500
505
doc,
501
506
blockClass,
502
507
blockSelector,
508
+ maskTextClass,
503
509
inlineStylesheet,
504
510
maskInputOptions,
505
511
maskInputFn,
@@ -600,6 +606,7 @@ function serializeElementNode(
600
606
doc : Document ;
601
607
blockClass : string | RegExp ;
602
608
blockSelector : string | null ;
609
+ maskTextClass : string | RegExp ;
603
610
inlineStylesheet : boolean ;
604
611
maskInputOptions : MaskInputOptions ;
605
612
maskInputFn : MaskInputFn | undefined ;
@@ -779,6 +786,36 @@ function serializeElementNode(
779
786
if ( image . complete && image . naturalWidth !== 0 ) recordInlineImage ( ) ;
780
787
else image . addEventListener ( 'load' , recordInlineImage ) ;
781
788
}
789
+ // dont store src of img with maskTextClass class
790
+ // replace src with blank png
791
+ let maskTextClass = options . maskTextClass ;
792
+ if (
793
+ tagName === 'img' &&
794
+ attributes . class &&
795
+ typeof attributes . class === 'string' &&
796
+ maskTextClass &&
797
+ typeof maskTextClass === 'string' &&
798
+ attributes . class . includes ( maskTextClass )
799
+ ) {
800
+ const image = n as HTMLImageElement ;
801
+ const maskImg = ( ) => {
802
+ attributes . src = BLANK_IMAGE_SRC ;
803
+ // set width & height in style attribute of img
804
+ if ( attributes . style && typeof attributes . style === 'string' ) {
805
+ if ( ! attributes . style . includes ( 'width' ) ) {
806
+ attributes . style = `${ attributes . style } ; width: ${ image . width } px;` ;
807
+ }
808
+ if ( ! attributes . style . includes ( 'height' ) ) {
809
+ attributes . style = `${ attributes . style } ; height: ${ image . height } px` ;
810
+ }
811
+ } else {
812
+ attributes . style = `width: ${ image . width } px; height: ${ image . height } px` ;
813
+ }
814
+ } ;
815
+ // The image content may not have finished loading yet.
816
+ if ( image . complete ) maskImg ( ) ;
817
+ else image . onload = maskImg ;
818
+ }
782
819
// media elements
783
820
if ( tagName === 'audio' || tagName === 'video' ) {
784
821
const mediaAttributes = attributes as mediaAttributes ;
@@ -1026,6 +1063,7 @@ export function serializeNodeWithId(
1026
1063
blockClass,
1027
1064
blockSelector,
1028
1065
needsMask,
1066
+ maskTextClass,
1029
1067
inlineStylesheet,
1030
1068
maskInputOptions,
1031
1069
maskTextFn,
0 commit comments