2023-03-24 14:51:05 +00:00
|
|
|
import type { JSX } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2023-11-18 14:10:02 +00:00
|
|
|
import { Link } from '@solidjs/meta'
|
2023-12-24 08:16:41 +00:00
|
|
|
import { createEffect, splitProps } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2023-10-27 18:50:13 +00:00
|
|
|
import { getImageUrl } from '../../../utils/getImageUrl'
|
2023-03-24 14:51:05 +00:00
|
|
|
|
2023-10-27 18:50:13 +00:00
|
|
|
type Props = JSX.ImgHTMLAttributes<HTMLImageElement> & {
|
|
|
|
width: number
|
|
|
|
alt: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Image = (props: Props) => {
|
|
|
|
const [local, others] = splitProps(props, ['src', 'alt'])
|
2023-11-18 14:10:02 +00:00
|
|
|
|
|
|
|
const imageUrl = getImageUrl(local.src, { width: others.width })
|
|
|
|
|
|
|
|
const imageSrcSet = [1, 2, 3]
|
|
|
|
.map(
|
|
|
|
(pixelDensity) =>
|
|
|
|
`${getImageUrl(local.src, { width: others.width * pixelDensity })} ${pixelDensity}x`,
|
|
|
|
)
|
|
|
|
.join(', ')
|
|
|
|
return (
|
|
|
|
<>
|
2023-12-24 08:16:41 +00:00
|
|
|
<Link rel="preload" as="image" imagesrcset={imageSrcSet} href={imageUrl} />
|
2023-11-18 14:10:02 +00:00
|
|
|
<img src={imageUrl} alt={local.alt} srcSet={imageSrcSet} {...others} />
|
|
|
|
</>
|
|
|
|
)
|
2023-03-24 14:51:05 +00:00
|
|
|
}
|