MCPcopy
hub / github.com/vercel/next.js / getImgProps

Function getImgProps

packages/next/src/shared/lib/get-img-props.ts:284–781  ·  view source on GitHub ↗
(
  {
    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
  }
)

Source from the content-addressed store, hash-verified

282 * A shared function, used on both client and server, to generate the props for <img>.
283 */
284export 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'

Callers 2

getImagePropsFunction · 0.90

Calls 15

warnOnceFunction · 0.90
getImageBlurSvgFunction · 0.90
startsWithMethod · 0.80
splitMethod · 0.80
includesMethod · 0.80
assignMethod · 0.80
getIntFunction · 0.70
isStaticImportFunction · 0.70
isStaticRequireFunction · 0.70
loaderFunction · 0.70
generateImgAttrsFunction · 0.70
testMethod · 0.65

Tested by

no test coverage detected