{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "media-image-preview",
  "type": "registry:component",
  "title": "ImagePreview",
  "description": "An image surface with loading, error and pointer zoom",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-components.json",
    "https://gpuixui.sudokw.com/gpuix-icons.json",
    "https://gpuixui.sudokw.com/gpuix-primitives.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/media/src/image-preview.tsx",
      "target": "@ui/gpuixui/media/image-preview.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { Props, StyleDesc } from \"@gpuix/react\";\nimport { mergeStyles } from \"@gpuix/react/floating\";\nimport { ImageZoom } from \"../components/image-zoom.js\";\nimport { Icon } from \"../icons/index.js\";\nimport { Spinner } from \"../primitives/index.js\";\nimport { Button } from \"../primitives/button.js\";\nimport { visibleCopy } from \"../primitives/core/index.js\";\nimport { cn } from \"../tw/index.js\";\nimport { Match } from \"effect\";\nimport * as Schema from \"effect/Schema\";\nimport * as Str from \"effect/String\";\nimport type { ReactElement } from \"react\";\nimport { recipeStyle, useTheme, type Theme } from \"./internal.js\";\nimport { accessibleName, PICTURE_NAME } from \"./name.js\";\n\nexport const ImagePreviewStatus = Schema.Literals([\n  \"loading\",\n  \"loaded\",\n  \"error\",\n]);\n\nexport type ImagePreviewStatus = typeof ImagePreviewStatus.Type;\n\nconst isStatus = Schema.is(ImagePreviewStatus);\n\nexport interface ImagePreviewProps extends Omit<Props, \"children\"> {\n  readonly src: string;\n\n  readonly alt: string;\n\n  readonly caption?: string;\n\n  readonly status?: ImagePreviewStatus;\n\n  readonly loadingLabel?: string;\n\n  readonly errorLabel?: string;\n\n  readonly retryLabel?: string;\n\n  readonly onRetry?: () => void;\n\n  readonly width?: number;\n\n  readonly height?: number;\n\n  readonly zoom?: boolean;\n\n  readonly scale?: number;\n\n  readonly radius?: number;\n  readonly className?: string;\n}\n\nconst DEFAULT_WIDTH = 240;\nconst DEFAULT_HEIGHT = 160;\n\nconst isBlank = (src: string): boolean => Str.isEmpty(Str.trim(src));\n\nconst frameSide = (value: number, fallback: number): number =>\n  Number.isFinite(value) && value >= 1 ? value : fallback;\n\nconst cornerRadius = (value: number | undefined, theme: Theme): number =>\n  value === undefined || !Number.isFinite(value) || value < 0\n    ? theme.radius.md\n    : value;\n\nconst resolveStatus = (\n  src: string,\n  status?: ImagePreviewStatus,\n): ImagePreviewStatus =>\n  isStatus(status) ? status : isBlank(src) ? \"error\" : \"loaded\";\n\nconst frameStyle = (theme: Theme): StyleDesc => ({\n  display: \"flex\",\n  alignItems: \"center\",\n  justifyContent: \"center\",\n  backgroundColor: theme.colors.muted,\n});\n\nexport const renderImagePreview = (\n  props: ImagePreviewProps,\n  theme: Theme,\n): ReactElement => {\n  const {\n    src,\n    alt,\n    caption,\n    status: statusProp,\n    loadingLabel,\n    errorLabel,\n    retryLabel,\n    onRetry,\n    width = DEFAULT_WIDTH,\n    height = DEFAULT_HEIGHT,\n    zoom = true,\n    scale,\n    radius,\n    className,\n    style,\n    ...rest\n  } = props;\n  const loading = accessibleName(loadingLabel, \"Loading\");\n  const error = accessibleName(errorLabel, \"Could not load image\");\n  const retry = accessibleName(retryLabel, \"Retry\");\n\n  const pictureName = accessibleName(alt, PICTURE_NAME);\n\n  const captionText = visibleCopy(caption);\n\n  const source = typeof src === \"string\" ? src : \"\";\n  const status = resolveStatus(source, statusProp);\n  const boxWidth = frameSide(width, DEFAULT_WIDTH);\n  const boxHeight = frameSide(height, DEFAULT_HEIGHT);\n  const corner = cornerRadius(radius, theme);\n\n  const body = Match.value(status).pipe(\n    Match.when(\"loading\", () => (\n      <Spinner label={loading} testId=\"image-preview-loading\" />\n    )),\n    Match.when(\"error\", () => (\n      <div\n        testId=\"image-preview-error\"\n        style={{\n          display: \"flex\",\n          flexDirection: \"column\",\n          alignItems: \"center\",\n          gap: theme.spacing.sm,\n        }}\n      >\n        <Icon name=\"error\" color={theme.colors.destructive} />\n        <text style={{ color: theme.colors.mutedForeground }}>{error}</text>\n        {onRetry === undefined ? null : (\n          <Button variant=\"secondary\" size=\"sm\" onActivate={() => onRetry()}>\n            {retry}\n          </Button>\n        )}\n      </div>\n    )),\n    Match.when(\"loaded\", () =>\n      zoom ? (\n        <ImageZoom\n          src={source}\n          alt={pictureName}\n          width={boxWidth}\n          height={boxHeight}\n          scale={scale}\n          radius={corner}\n        />\n      ) : (\n        <img\n          src={source}\n          alt={pictureName}\n          objectFit=\"contain\"\n          style={{ width: \"100%\", height: \"100%\" }}\n        />\n      ),\n    ),\n    Match.exhaustive,\n  );\n\n  return (\n    <div\n      {...rest}\n      style={mergeStyles(\n        recipeStyle(cn(\"flex flex-col gap-2\", className), theme),\n        style,\n      )}\n    >\n      <div\n        style={{\n          ...frameStyle(theme),\n          width: boxWidth,\n          height: boxHeight,\n          borderRadius: corner,\n          overflow: \"hidden\",\n          position: \"relative\",\n        }}\n      >\n        {body}\n      </div>\n      {captionText === undefined ? null : (\n        <text style={{ color: theme.colors.mutedForeground }}>\n          {captionText}\n        </text>\n      )}\n    </div>\n  );\n};\n\nexport const ImagePreview = (props: ImagePreviewProps): ReactElement =>\n  renderImagePreview(props, useTheme());\n"
    },
    {
      "path": "packages/media/src/internal.ts",
      "target": "@ui/gpuixui/media/internal.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { classesToStyle } from \"../tw/index.js\";\nimport type { Theme } from \"../tokens/index.js\";\n\nexport { ThemeProvider, useTheme } from \"../tokens/react.js\";\nexport type { Theme } from \"../tokens/index.js\";\n\nexport const recipeStyle = (recipe: string, theme: Theme): StyleDesc =>\n  classesToStyle(recipe, theme).style;\n"
    },
    {
      "path": "packages/media/src/name.ts",
      "target": "@ui/gpuixui/media/name.ts",
      "type": "registry:lib",
      "content": "import * as Str from \"effect/String\";\n\nexport const accessibleName = (label: unknown, fallback: string): string => {\n  const text = typeof label === \"string\" ? Str.trim(label) : \"\";\n  return Str.isEmpty(text) ? fallback : text;\n};\n\nexport const PICTURE_NAME = \"Picture\";\n"
    }
  ],
  "docs": "[ImagePreview](https://gpuixui.sudokw.com/media/image-preview) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/media/image-preview",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}