@@ -38,14 +38,14 @@ function getDefaultSvgBoundsIfUndefined(text: string, src: string) {
3838 return null ;
3939}
4040
41- function createContext ( imageAfter : HTMLImageElement , imageBefore : HTMLImageElement ) {
41+ function createContext ( imageAfter : HTMLImageElement , imageBefore : HTMLImageElement , boundPair : any ) {
4242 const sizeAfter = {
43- width : imageAfter ?. width || 0 ,
44- height : imageAfter ?. height || 0 ,
43+ width : boundPair . after ?. width || imageAfter ?. width || 0 ,
44+ height : boundPair . after ?. height || imageAfter ?. height || 0 ,
4545 } ;
4646 const sizeBefore = {
47- width : imageBefore ?. width || 0 ,
48- height : imageBefore ?. height || 0 ,
47+ width : boundPair . before ?. width || imageBefore ?. width || 0 ,
48+ height : boundPair . before ?. height || imageBefore ?. height || 0 ,
4949 } ;
5050 const maxSize = {
5151 width : Math . max ( sizeBefore . width , sizeAfter . width ) ,
@@ -92,7 +92,8 @@ class ImageDiff {
9292 boundsInfo : containerEl . querySelector ( '.bounds-info-before' ) ,
9393 } ] ;
9494
95- await Promise . all ( imageInfos . map ( async ( info ) => {
95+ const boundPair : any = { before : null , after : null } ;
96+ await Promise . all ( imageInfos . map ( async ( info , index ) => {
9697 const [ success ] = await Promise . all ( Array . from ( info . images , ( img ) => {
9798 return loadElem ( img , info . path ) ;
9899 } ) ) ;
@@ -102,11 +103,8 @@ class ImageDiff {
102103 const resp = await GET ( info . path ) ;
103104 const text = await resp . text ( ) ;
104105 const bounds = getDefaultSvgBoundsIfUndefined ( text , info . path ) ;
106+ boundPair [ index === 0 ? 'after' : 'before' ] = bounds ;
105107 if ( bounds ) {
106- for ( const el of info . images ) {
107- el . setAttribute ( 'width' , String ( bounds . width ) ) ;
108- el . setAttribute ( 'height' , String ( bounds . height ) ) ;
109- }
110108 hideElem ( info . boundsInfo ) ;
111109 }
112110 }
@@ -115,10 +113,10 @@ class ImageDiff {
115113 const imagesAfter = imageInfos [ 0 ] . images ;
116114 const imagesBefore = imageInfos [ 1 ] . images ;
117115
118- this . initSideBySide ( createContext ( imagesAfter [ 0 ] , imagesBefore [ 0 ] ) ) ;
116+ this . initSideBySide ( createContext ( imagesAfter [ 0 ] , imagesBefore [ 0 ] , boundPair ) ) ;
119117 if ( imagesAfter . length > 0 && imagesBefore . length > 0 ) {
120- this . initSwipe ( createContext ( imagesAfter [ 1 ] , imagesBefore [ 1 ] ) ) ;
121- this . initOverlay ( createContext ( imagesAfter [ 2 ] , imagesBefore [ 2 ] ) ) ;
118+ this . initSwipe ( createContext ( imagesAfter [ 1 ] , imagesBefore [ 1 ] , boundPair ) ) ;
119+ this . initOverlay ( createContext ( imagesAfter [ 2 ] , imagesBefore [ 2 ] , boundPair ) ) ;
122120 }
123121 queryElemChildren ( containerEl , '.image-diff-tabs' , ( el ) => el . classList . remove ( 'is-loading' ) ) ;
124122 }
0 commit comments