{"version":3,"file":"index.cjs","names":["AspectRatio"],"sources":["../../../src/components/Image/Image.tsx"],"sourcesContent":["import * as AspectRatio from \"@radix-ui/react-aspect-ratio\";\nimport clsx from \"clsx\";\nimport React, { forwardRef } from \"react\";\n\ntype AspectRatioType = \"1:1\" | \"3:2\" | \"3:4\" | \"4:3\" | \"16:9\";\ntype ScaleType = \"fit\" | \"fill\";\n\nexport interface ImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {\n  src: string;\n  alt?: string;\n  styles?: React.CSSProperties;\n  className?: string;\n  aspectRatio?: AspectRatioType;\n  scale?: ScaleType;\n}\n\nconst aspectRatioMap: Record<AspectRatioType, number> = {\n  \"1:1\": 1,\n  \"3:2\": 3 / 2,\n  \"3:4\": 3 / 4,\n  \"4:3\": 4 / 3,\n  \"16:9\": 16 / 9,\n};\n\nconst scaleMap: Record<ScaleType, string> = {\n  fit: \"openui-image-fit\",\n  fill: \"openui-image-fill\",\n};\n\nexport const Image = forwardRef<HTMLImageElement, ImageProps>((props, ref) => {\n  const { src, alt, styles, className, aspectRatio = \"3:2\", scale = \"fill\", ...rest } = props;\n\n  const imageClasses = clsx(\n    \"openui-image\",\n    {\n      [`${scaleMap[scale]}`]: scale,\n    },\n    className,\n  );\n\n  const image = (\n    <img\n      ref={ref}\n      src={src}\n      alt={alt}\n      className={imageClasses}\n      style={styles}\n      onError={(e) => {\n        e.currentTarget.style.display = \"none\";\n        console.error(`Failed to load image: ${src}`);\n      }}\n      {...rest}\n    />\n  );\n\n  return <AspectRatio.Root ratio={aspectRatioMap[aspectRatio]}>{image}</AspectRatio.Root>;\n});\n\nImage.displayName = \"Image\";\n"],"mappings":";;;;;;;;;;AAgBA,MAAM,iBAAkD;CACtD,OAAO;CACP,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO,IAAI;CACX,QAAQ,KAAK;CACd;AAED,MAAM,WAAsC;CAC1C,KAAK;CACL,MAAM;CACP;AAED,MAAa,SAAA,GAAA,MAAA,aAAkD,OAAO,QAAQ;CAC5E,MAAM,EAAE,KAAK,KAAK,QAAQ,WAAW,cAAc,OAAO,QAAQ,QAAQ,GAAG,SAAS;CAUtF,MAAM,QACJ,iBAAA,GAAA,kBAAA,KAAC,OAAD;EACO;EACA;EACA;EACL,YAAA,GAAA,KAAA,SAZF,gBACA,GACG,GAAG,SAAS,WAAW,OACzB,EACD,UAQyB;EACvB,OAAO;EACP,UAAU,MAAM;AACd,KAAE,cAAc,MAAM,UAAU;AAChC,WAAQ,MAAM,yBAAyB,MAAM;;EAE/C,GAAI;EACJ,CAAA;AAGJ,QAAO,iBAAA,GAAA,kBAAA,KAACA,6BAAY,MAAb;EAAkB,OAAO,eAAe;YAAe;EAAyB,CAAA;EACvF;AAEF,MAAM,cAAc"}