{"version":3,"file":"chunk-Image.mjs","names":["Icon.Icon"],"sources":["../../src/components/Image/Image.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport React, {\n  type ComponentPropsWithoutRef,\n  type CSSProperties,\n  type ImgHTMLAttributes,\n  forwardRef,\n  useState,\n} from 'react';\n\nimport { sampleDominantColor } from '@dxos/lit-ui';\nimport { mx } from '@dxos/ui-theme';\nimport { type ThemedClassName } from '@dxos/ui-types';\n\nimport { clickableProps } from '../../clickable.ts';\nimport { recipes } from '../../recipes.ts';\nimport { type CSSVariables } from '../Container/Container.tsx';\nimport * as Icon from '../Icon/Icon.tsx';\n\ntype ImageStatus = 'loading' | 'loaded' | 'error';\n\ntype ImageElementProps = Pick<\n  ImgHTMLAttributes<HTMLImageElement>,\n  'src' | 'srcSet' | 'sizes' | 'crossOrigin' | 'referrerPolicy' | 'loading' | 'decoding' | 'onLoad' | 'onError'\n>;\n\nexport type ImageProps = ThemedClassName<Omit<ComponentPropsWithoutRef<'div'>, 'children' | 'onLoad' | 'onError'>> &\n  ImageElementProps & {\n    /** Required: also names the fallback icon when the image fails to load. */\n    alt: string;\n    /** CSS `aspect-ratio` of the frame. */\n    aspectRatio?: string;\n    fit?: 'cover' | 'contain';\n    /**\n     * `dominant` fills the frame behind a loaded image (the letterbox of `contain`) with the colour of its corners;\n     * an image whose pixels cannot be read (cross-origin without `crossOrigin` and CORS) leaves the host surface.\n     */\n    backdrop?: 'dominant';\n  };\n\n/**\n * An `<img>` in a fixed-ratio frame that shows the well while loading and a broken-image icon on error. With `onClick`\n * the frame is a button named by `alt`, operable by Enter and Space.\n */\nexport const Image = forwardRef<HTMLDivElement, ImageProps>(\n  (\n    {\n      classNames,\n      style,\n      src,\n      srcSet,\n      sizes,\n      crossOrigin,\n      referrerPolicy,\n      alt,\n      loading = 'lazy',\n      decoding = 'async',\n      aspectRatio = '16 / 9',\n      fit = 'cover',\n      backdrop,\n      onLoad,\n      onError,\n      onClick,\n      onKeyDown,\n      ...props\n    },\n    forwardedRef,\n  ) => {\n    // Keyed by source so a new `src` starts loading again without an effect racing the load event.\n    const source = `${src ?? ''} ${srcSet ?? ''}`;\n    const [result, setResult] = useState<{ source: string; status: ImageStatus; color?: string }>();\n    const status: ImageStatus = result?.source === source ? result.status : 'loading';\n    const color = result?.source === source ? result.color : undefined;\n    const aspectStyle: CSSProperties & CSSVariables = {\n      '--dx-image-aspect': aspectRatio,\n      ...(color ? { '--dx-image-backdrop': color } : {}),\n    };\n    return (\n      <div\n        {...props}\n        {...clickableProps(onClick, onKeyDown)}\n        data-scope='image'\n        data-part='root'\n        data-fit={fit}\n        data-status={status}\n        data-backdrop={backdrop}\n        style={{ ...aspectStyle, ...style }}\n        className={mx(recipes.image(), onClick && recipes.imageClickable(), classNames)}\n        ref={forwardedRef}\n      >\n        {status === 'error' ? (\n          <Icon.Icon icon='ph--image-broken--regular' label={alt} />\n        ) : (\n          <img\n            src={src}\n            srcSet={srcSet}\n            sizes={sizes}\n            crossOrigin={crossOrigin}\n            referrerPolicy={referrerPolicy}\n            alt={alt}\n            loading={loading}\n            decoding={decoding}\n            data-scope='image'\n            data-part='img'\n            onLoad={(event) => {\n              const sampled = backdrop === 'dominant' ? sampleDominantColor(event.currentTarget) : undefined;\n              setResult({ source, status: 'loaded', color: sampled });\n              onLoad?.(event);\n            }}\n            onError={(event) => {\n              setResult({ source, status: 'error' });\n              onError?.(event);\n            }}\n          />\n        )}\n      </div>\n    );\n  },\n);\n\nImage.displayName = 'Image';\n"],"mappings":";;;;;;;;;;;;AA8CA,IAAa,QAAQ,YAEjB,EACE,YACA,OACA,KACA,QACA,OACA,aACA,gBACA,KACA,UAAU,QACV,WAAW,SACX,cAAc,UACd,MAAM,SACN,UACA,QACA,SACA,SACA,WACA,GAAG,SAEL,iBACG;CAEH,MAAM,SAAS,GAAG,OAAO,GAAG,GAAG,UAAU;CACzC,MAAM,CAAC,QAAQ,aAAa,SAAkE;CAC9F,MAAM,SAAsB,QAAQ,WAAW,SAAS,OAAO,SAAS;CACxE,MAAM,QAAQ,QAAQ,WAAW,SAAS,OAAO,QAAQ,KAAA;CACzD,MAAM,cAA4C;EAChD,qBAAqB;EACrB,GAAI,QAAQ,EAAE,uBAAuB,MAAM,IAAI,CAAC;CAClD;CACA,OACE,oBAAC,OAAD;EACE,GAAI;EACJ,GAAI,eAAe,SAAS,SAAS;EACrC,cAAW;EACX,aAAU;EACV,YAAU;EACV,eAAa;EACb,iBAAe;EACf,OAAO;GAAE,GAAG;GAAa,GAAG;EAAM;EAClC,WAAW,GAAG,QAAQ,MAAM,GAAG,WAAW,QAAQ,eAAe,GAAG,UAAU;EAC9E,KAAK;EAEJ,UAAA,WAAW,UACV,oBAACA,MAAD;GAAW,MAAK;GAA4B,OAAO;EAAM,CAAA,IAEzD,oBAAC,OAAD;GACO;GACG;GACD;GACM;GACG;GACX;GACI;GACC;GACV,cAAW;GACX,aAAU;GACV,SAAS,UAAU;IACjB,MAAM,UAAU,aAAa,aAAa,oBAAoB,MAAM,aAAa,IAAI,KAAA;IACrF,UAAU;KAAE;KAAQ,QAAQ;KAAU,OAAO;IAAQ,CAAC;IACtD,SAAS,KAAK;GAChB;GACA,UAAU,UAAU;IAClB,UAAU;KAAE;KAAQ,QAAQ;IAAQ,CAAC;IACrC,UAAU,KAAK;GACjB;EACD,CAAA;CAEA,CAAA;AAET,CACF;AAEA,MAAM,cAAc"}