import { Image } from '.' ; const sizes = [ 160 , 180 , 282 , 320 , 420 , 600 , 880 , 960 , 1024 , 1338 ] ; type Size = typeof sizes [ number ] ; type Params = { w : Size ; } ; export function getImageUrlAtSize ( image , params ) { const crop = image [ '16:9' ] ?? image ; if ( ! crop ?. url ) return ; const url = new URL ( crop . url ) ; const base = `${ url . origin }${ url . pathname }` ; const urlSearchParams = new URLSearchParams ( ) ; for ( const [ key , val ] of url . searchParams ) { urlSearchParams . set ( key , val . toString ( ) ) ; } for ( const [ key , val ] of Object . entries ( params ) ) { urlSearchParams . set ( key , val . toString ( ) ) ; } urlSearchParams . delete ( 'h' ) ; return `${ base }?${ urlSearchParams . toString ( ) }` ; }