1- import  $  from  'jquery' ; 
21import  { GET }  from  '../modules/fetch.ts' ; 
32import  { hideElem ,  loadElem ,  queryElemChildren ,  queryElems }  from  '../utils/dom.ts' ; 
43import  { parseDom }  from  '../utils.ts' ; 
4+ import  { fomanticQuery }  from  '../modules/fomantic/base.ts' ; 
55
66function  getDefaultSvgBoundsIfUndefined ( text ,  src )  { 
77  const  defaultSize  =  300 ; 
88  const  maxSize  =  99999 ; 
99
1010  const  svgDoc  =  parseDom ( text ,  'image/svg+xml' ) ; 
11-   const  svg  =  svgDoc . documentElement ; 
11+   const  svg  =  ( svgDoc . documentElement   as   unknown )   as   SVGSVGElement ; 
1212  const  width  =  svg ?. width ?. baseVal ; 
1313  const  height  =  svg ?. height ?. baseVal ; 
1414  if  ( width  ===  undefined  ||  height  ===  undefined )  { 
@@ -68,25 +68,27 @@ function createContext(imageAfter, imageBefore) {
6868} 
6969
7070class  ImageDiff  { 
71-   async  init ( containerEl )  { 
71+   containerEl : HTMLElement ; 
72+   diffContainerWidth : number ; 
73+ 
74+   async  init ( containerEl : HTMLElement )  { 
7275    this . containerEl  =  containerEl ; 
7376    containerEl . setAttribute ( 'data-image-diff-loaded' ,  'true' ) ; 
7477
75-     // the only jQuery usage in this file 
76-     $ ( containerEl ) . find ( '.ui.menu.tabular .item' ) . tab ( { autoTabActivation : false } ) ; 
78+     fomanticQuery ( containerEl ) . find ( '.ui.menu.tabular .item' ) . tab ( { autoTabActivation : false } ) ; 
7779
7880    // the container may be hidden by "viewed" checkbox, so use the parent's width for reference 
7981    this . diffContainerWidth  =  Math . max ( containerEl . closest ( '.diff-file-box' ) . clientWidth  -  300 ,  100 ) ; 
8082
8183    const  imageInfos  =  [ { 
8284      path : containerEl . getAttribute ( 'data-path-after' ) , 
8385      mime : containerEl . getAttribute ( 'data-mime-after' ) , 
84-       images : containerEl . querySelectorAll ( 'img.image-after' ) ,  // matches 3 <img> 
86+       images : containerEl . querySelectorAll < HTMLImageElement > ( 'img.image-after' ) ,  // matches 3 <img> 
8587      boundsInfo : containerEl . querySelector ( '.bounds-info-after' ) , 
8688    } ,  { 
8789      path : containerEl . getAttribute ( 'data-path-before' ) , 
8890      mime : containerEl . getAttribute ( 'data-mime-before' ) , 
89-       images : containerEl . querySelectorAll ( 'img.image-before' ) ,  // matches 3 <img> 
91+       images : containerEl . querySelectorAll < HTMLImageElement > ( 'img.image-before' ) ,  // matches 3 <img> 
9092      boundsInfo : containerEl . querySelector ( '.bounds-info-before' ) , 
9193    } ] ; 
9294
@@ -102,8 +104,8 @@ class ImageDiff {
102104        const  bounds  =  getDefaultSvgBoundsIfUndefined ( text ,  info . path ) ; 
103105        if  ( bounds )  { 
104106          for  ( const  el  of  info . images )  { 
105-             el . setAttribute ( 'width' ,  bounds . width ) ; 
106-             el . setAttribute ( 'height' ,  bounds . height ) ; 
107+             el . setAttribute ( 'width' ,  String ( bounds . width ) ) ; 
108+             el . setAttribute ( 'height' ,  String ( bounds . height ) ) ; 
107109          } 
108110          hideElem ( info . boundsInfo ) ; 
109111        } 
@@ -151,7 +153,7 @@ class ImageDiff {
151153      const  boundsInfoBeforeHeight  =  this . containerEl . querySelector ( '.bounds-info-before .bounds-info-height' ) ; 
152154      if  ( boundsInfoBeforeHeight )  { 
153155        boundsInfoBeforeHeight . textContent  =  `${ sizes . imageBefore . naturalHeight }  px` ; 
154-         boundsInfoBeforeHeight . classList . add ( 'red' ,  heightChanged ) ; 
156+         boundsInfoBeforeHeight . classList . toggle ( 'red' ,  heightChanged ) ; 
155157      } 
156158    } 
157159
@@ -205,7 +207,7 @@ class ImageDiff {
205207    } 
206208
207209    // extra height for inner "position: absolute" elements 
208-     const  swipe  =  this . containerEl . querySelector ( '.diff-swipe' ) ; 
210+     const  swipe  =  this . containerEl . querySelector < HTMLElement > ( '.diff-swipe' ) ; 
209211    if  ( swipe )  { 
210212      swipe . style . width  =  `${ sizes . maxSize . width  *  factor  +  2 }  px` ; 
211213      swipe . style . height  =  `${ sizes . maxSize . height  *  factor  +  30 }  px` ; 
@@ -225,7 +227,7 @@ class ImageDiff {
225227      const  rect  =  swipeFrame . getBoundingClientRect ( ) ; 
226228      const  value  =  Math . max ( 0 ,  Math . min ( e . clientX  -  rect . left ,  width ) ) ; 
227229      swipeBar . style . left  =  `${ value }  px` ; 
228-       this . containerEl . querySelector ( '.swipe-container' ) . style . width  =  `${ swipeFrame . clientWidth  -  value }  px` ; 
230+       this . containerEl . querySelector < HTMLElement > ( '.swipe-container' ) . style . width  =  `${ swipeFrame . clientWidth  -  value }  px` ; 
229231    } ; 
230232    const  removeEventListeners  =  ( )  =>  { 
231233      document . removeEventListener ( 'mousemove' ,  onSwipeMouseMove ) ; 
@@ -264,11 +266,11 @@ class ImageDiff {
264266      overlayFrame . style . height  =  `${ sizes . maxSize . height  *  factor  +  2 }  px` ; 
265267    } 
266268
267-     const  rangeInput  =  this . containerEl . querySelector ( 'input[type="range"]' ) ; 
269+     const  rangeInput  =  this . containerEl . querySelector < HTMLInputElement > ( 'input[type="range"]' ) ; 
268270
269271    function  updateOpacity ( )  { 
270272      if  ( sizes . imageAfter )  { 
271-         sizes . imageAfter . parentNode . style . opacity  =  `${ rangeInput . value  /  100 }  ` ; 
273+         sizes . imageAfter . parentNode . style . opacity  =  `${ Number ( rangeInput . value )  /  100 }  ` ; 
272274      } 
273275    } 
274276
@@ -278,7 +280,7 @@ class ImageDiff {
278280} 
279281
280282export  function  initImageDiff ( )  { 
281-   for  ( const  el  of  queryElems ( '.image-diff:not([data-image-diff-loaded])' ) )  { 
283+   for  ( const  el  of  queryElems < HTMLImageElement > ( document ,   '.image-diff:not([data-image-diff-loaded])' ) )  { 
282284    ( new  ImageDiff ( ) ) . init ( el ) ;  // it is async, but we don't need to await for it 
283285  } 
284286} 
0 commit comments