feat: multiple changes

Signed-off-by: Avior <git@avior.me>
This commit is contained in:
2024-09-09 14:27:46 +02:00
parent d8f203f434
commit 3e91597dca
31 changed files with 216 additions and 223 deletions

View File

@ -1,12 +1,9 @@
---
import { getImage } from 'astro:assets'
import AstroUtils from '../../libs/AstroUtils'
import { objectOmit } from '@dzeio/object-util'
import AstroUtils from '../../libs/AstroUtils'
const formats = [
'avif',
'webp'
]
const formats = ['avif', 'webp']
export interface Props extends Omit<astroHTML.JSX.ImgHTMLAttributes, 'src'> {
src: ImageMetadata | string
@ -17,7 +14,7 @@ export interface Props extends Omit<astroHTML.JSX.ImgHTMLAttributes, 'src'> {
type PictureResult = {
format: 'new'
formats: Array<{format: string, img: Awaited<ReturnType<typeof getImage>>}>
formats: Array<{ format: string, img: Awaited<ReturnType<typeof getImage>> }>
src: Awaited<ReturnType<typeof getImage>>
} | {
format: 'raw'
@ -38,14 +35,25 @@ async function resolvePicture(image: ImageMetadata | string): Promise<PictureRes
}
}
const imageFormats: Array<{format: string, img: Awaited<ReturnType<typeof getImage>>}> = await Promise.all(
formats.map(async (it) => ({
img: await getImage({src: Astro.props.src, format: it, width: Astro.props.width, height: Astro.props.height}),
format: it
}))
)
const imageFormats: Array<{ format: string, img: Awaited<ReturnType<typeof getImage>> }> =
await Promise.all(
formats.map(async (it) => ({
img: await getImage({
src: Astro.props.src,
format: it,
width: Astro.props.width,
height: Astro.props.height
}),
format: it
}))
)
const orig = await getImage({src: Astro.props.src, format: ext, width: Astro.props.width, height: Astro.props.height})
const orig = await getImage({
src: Astro.props.src,
format: ext,
width: Astro.props.width,
height: Astro.props.height
})
return {
format: 'new',
@ -62,7 +70,6 @@ const res = await AstroUtils.wrap<Result>(async () => {
})
const props = objectOmit(Astro.props, 'src', 'srcDark', 'class')
---
{res.light.format === 'new' && (