11<script >
22export let src = []
33export let sizes = undefined
4+ export let width = undefined
5+ export let height = undefined
46export let loading = ' lazy'
57export let decoding = ' async'
68export let ref = undefined
79
10+ const priority = [' heic' , ' heif' , ' avif' , ' webp' , ' jpeg' , ' jpg' , ' png' , ' gif' , ' tiff' ]
811let image = {}
912let sources = []
1013
@@ -18,14 +21,17 @@ $: if (src.length) {
1821 { list: [], lqip: undefined }
1922 )
2023 const groups = []
21- for (const format of [ ' heic ' , ' heif ' , ' avif ' , ' webp ' , ' jpeg ' , ' jpg ' , ' png ' , ' gif ' , ' tiff ' ] ) {
24+ for (const format of priority ) {
2225 const group = list .filter ((i ) => i .format === format)
2326 if (group .length ) {
2427 group .sort ((a , b ) => a .width - b .width )
28+ const { src , width , height } = group[group .length - 1 ]
2529 groups .push ({
2630 format: format === ' jpg' ? ' jpeg' : format,
2731 srcset: group .reduce ((a , c ) => [... a, ` ${ c .src } ${ c .width } w` ], []).join (' ,' ),
28- src: group[group .length - 1 ].src
32+ src,
33+ width,
34+ height
2935 })
3036 }
3137 }
@@ -44,6 +50,8 @@ $: if (src.length) {
4450 src ={image .src }
4551 srcset ={image .srcset }
4652 {sizes }
53+ width ={width || image .width || undefined }
54+ height ={height || image .height || undefined }
4755 {loading }
4856 {decoding }
4957 style:background ={image .lqip }
0 commit comments