@@ -16,11 +16,13 @@ export function ImageOnionSkin(props: ImageDiffProps) {
1616// Two images on top of one another with a slider to move the divider from left
1717// to right.
1818export function ImageSwipe ( props : ImageSwipeProps ) {
19- const mode = props . mode || 'swipe' ;
19+ const mode = props . mode ?? 'swipe' ;
2020 const [ rangePosition , setRangePosition ] = React . useState < number | null > ( null ) ;
2121 const sliderRef = React . createRef < HTMLInputElement > ( ) ;
2222 const onSlide = ( ) => {
23- setRangePosition ( Number ( sliderRef . current ! . value ) ) ;
23+ if ( sliderRef . current ) {
24+ setRangePosition ( Number ( sliderRef . current . value ) ) ;
25+ }
2426 } ;
2527
2628 const pair = props . filePair ;
@@ -40,33 +42,34 @@ export function ImageSwipe(props: ImageSwipeProps) {
4042 containerWidth = Math . max ( imA . width , imB . width ) ;
4143 }
4244 const diffBoxDiv = makePerceptualBoxDiv ( props . pdiffMode , pair , scaleDown ) ;
43- const urlA = ' /a/image/' + pair . a ;
44- const urlB = ' /b/image/' + pair . b ;
45- const styleA : React . CSSProperties = {
46- backgroundImage : ' url(' + urlA + ')' ,
47- backgroundSize : imA . width + ' px ' + imA . height + 'px' ,
48- width : imA . width + 'px' ,
49- height : imA . height + 'px' ,
45+ const urlA = ` /a/image/${ pair . a } ` ;
46+ const urlB = ` /b/image/${ pair . b } ` ;
47+ const styleA : React . CSSProperties & { backgroundSize : string ; backgroundImage : string } = {
48+ backgroundImage : ` url(${ urlA } )` ,
49+ backgroundSize : ` ${ imA . width } px ${ imA . height } px` ,
50+ width : ` ${ imA . width } px` ,
51+ height : ` ${ imA . height } px` ,
5052 } ;
51- const styleB : React . CSSProperties = {
52- backgroundImage : ' url(' + urlB + ')' ,
53- backgroundSize : imB . width + ' px ' + imB . height + 'px' ,
54- width : imB . width + 'px' ,
55- height : imB . height + 'px' ,
53+ const styleB : React . CSSProperties & { backgroundSize : string ; backgroundImage : string } = {
54+ backgroundImage : ` url(${ urlB } )` ,
55+ backgroundSize : ` ${ imB . width } px ${ imB . height } px` ,
56+ width : ` ${ imB . width } px` ,
57+ height : ` ${ imB . height } px` ,
5658 } ;
5759 const styleContainer : React . CSSProperties = {
58- width : containerWidth + 'px' ,
59- height : Math . max ( imA . height , imB . height ) + 'px' ,
60+ width : containerWidth ,
61+ height : Math . max ( imA . height , imB . height ) ,
6062 } ;
6163 if ( mode === 'swipe' ) {
6264 _ . extend ( styleA , {
63- width : Math . floor ( frac * imA . width ) + 'px' ,
65+ width : Math . floor ( frac * imA . width ) ,
6466 } ) ;
67+ const bgTop = - Math . floor ( frac * imB . width ) ;
6568 _ . extend ( styleB , {
66- left : Math . floor ( frac * imB . width ) + 'px' ,
69+ left : Math . floor ( frac * imB . width ) ,
6770 width : null ,
68- right : containerWidth - imB . width + 'px' ,
69- backgroundPosition : - Math . floor ( frac * imB . width ) + ' px top' ,
71+ right : containerWidth - imB . width ,
72+ backgroundPosition : ` ${ bgTop } px top` ,
7073 } ) ;
7174 } else {
7275 _ . extend ( styleB , { opacity : frac } ) ;
0 commit comments