(
{
src,
sizes,
unoptimized = false,
priority = false,
preload = false,
loading,
className,
quality,
width,
height,
fill = false,
style,
overrideSrc,
onLoad,
onLoadingComplete,
placeholder = 'empty',
blurDataURL,
fetchPriority,
decoding = 'async',
layout,
objectFit,
objectPosition,
lazyBoundary,
lazyRoot,
...rest
}: ImageProps,
_state: {
defaultLoader: ImageLoaderWithConfig
imgConf: ImageConfigComplete
showAltText?: boolean
blurComplete?: boolean
}
)
| 282 | * A shared function, used on both client and server, to generate the props for <img>. |
| 283 | */ |
| 284 | export function getImgProps( |
| 285 | { |
| 286 | src, |
| 287 | sizes, |
| 288 | unoptimized = false, |
| 289 | priority = false, |
| 290 | preload = false, |
| 291 | loading, |
| 292 | className, |
| 293 | quality, |
| 294 | width, |
| 295 | height, |
| 296 | fill = false, |
| 297 | style, |
| 298 | overrideSrc, |
| 299 | onLoad, |
| 300 | onLoadingComplete, |
| 301 | placeholder = 'empty', |
| 302 | blurDataURL, |
| 303 | fetchPriority, |
| 304 | decoding = 'async', |
| 305 | layout, |
| 306 | objectFit, |
| 307 | objectPosition, |
| 308 | lazyBoundary, |
| 309 | lazyRoot, |
| 310 | ...rest |
| 311 | }: ImageProps, |
| 312 | _state: { |
| 313 | defaultLoader: ImageLoaderWithConfig |
| 314 | imgConf: ImageConfigComplete |
| 315 | showAltText?: boolean |
| 316 | blurComplete?: boolean |
| 317 | } |
| 318 | ): { |
| 319 | props: ImgProps |
| 320 | meta: { |
| 321 | unoptimized: boolean |
| 322 | preload: boolean |
| 323 | placeholder: NonNullable<ImageProps['placeholder']> |
| 324 | fill: boolean |
| 325 | } |
| 326 | } { |
| 327 | const { imgConf, showAltText, blurComplete, defaultLoader } = _state |
| 328 | let config: ImageConfig |
| 329 | let c = imgConf || imageConfigDefault |
| 330 | if ('allSizes' in c) { |
| 331 | config = c as ImageConfig |
| 332 | } else { |
| 333 | const allSizes = [...c.deviceSizes, ...c.imageSizes].sort((a, b) => a - b) |
| 334 | const deviceSizes = c.deviceSizes.sort((a, b) => a - b) |
| 335 | const qualities = c.qualities?.sort((a, b) => a - b) |
| 336 | config = { ...c, allSizes, deviceSizes, qualities } |
| 337 | } |
| 338 | |
| 339 | if (typeof defaultLoader === 'undefined') { |
| 340 | throw new Error( |
| 341 | 'images.loaderFile detected but the file is missing default export.\nRead more: https://nextjs.org/docs/messages/invalid-images-config' |
no test coverage detected