import * as seadn from "@opensea/seadn" import { CenterAligned, classNames, Flex } from "@opensea/ui-kit" import { Image as ImageIcon } from "@opensea/ui-kit/icons" import NextImage from "next/image" import React, { forwardRef } from "react" import { blurhashToBase64 } from "./blurhash" type NextImageProps = React.ComponentProps export type ImageProps = Omit & { alt?: string src: string | null | undefined /* Fit for the media optimisation. This does not influence the html element's object-fit which is a separate property */ fit?: seadn.MediaFit frameTime?: number format?: seadn.MediaFormat blurhash?: string | null /** * This can be useful for cases where we have the blurDataURL already computed */ blurDataURL?: string | null original?: boolean /** * Boost the image quality by going to the next image bucket. E.g. boost=2 will go up one bucket. */ boost?: number } export const Image = forwardRef(function Image( { original, src, unoptimized, blurhash, alt = "", fit, frameTime, boost, format, blurDataURL: blurDataURLProp, ...rest }, ref, ) { if (!src) { const height = Number(rest.height?.toString().replace("px", "") ?? 0) const width = Number(rest.width?.toString().replace("px", "") ?? 0) const smallestSide = Math.min(height, width) const size = smallestSide <= 100 ? "50%" : "20%" return ( {/* Placeholder image to maintain sizing */} ) } const blurDataURL = blurDataURLProp ?? (blurhash ? blurhashToBase64(blurhash) : undefined) const placeholder = blurDataURL ? "blur" : undefined // if we have no dimensions, let the NextJS srcset logic kicking and we might resize // via loader if ( original !== true && (typeof src !== "string" || (!rest.height && !rest.width)) ) { return ( ) } const resized = original ? seadn.originalURL(src) : seadn.optimize(src, { height: rest.height, width: rest.width, quality: rest.quality, fit, frameTime, boost, format, }) return ( ) })