{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "report-figure",
  "type": "registry:block",
  "title": "Report, figure",
  "description": "A picture in a report, or a gallery of them, shown whole (never cropped, at most 90 % of the screen tall) with an optional title and captions, for decisions that need a visual pick. kh-report embeds a local image file as a data address so the page stays one file; remote addresses are refused there.",
  "categories": [
    "report"
  ],
  "dependencies": [
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/kit-report.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/blocks/report-figure/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/report-figure/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, t } from '../_shared/schema';\n\nconst schema = z.object({\n  /** A short heading above the picture; empty draws none. */\n  title: t(80),\n  /** An address (https or a site path) or, in a one-file report, the picture itself as a base64 image address (kh-report embeds a local file). At most about 3 MB of text, which is a 2 MB file. */\n  src: z.string().max(3_000_000),\n  /** What the picture shows, for someone who cannot see it. Decisions that ask for a visual pick depend on it. */\n  alt: t(300),\n  /** Printed under the picture: write \"Figure 2\" yourself when a decision card refers to it by number. */\n  caption: t(300),\n  /** 'text' keeps the reading width, 'wide' uses the whole page column. Unset is 'text'. */\n  width: z.enum(['text', 'wide']).optional(),\n  /** Two or more pictures shown together as a gallery (a grid on a wide page, one column on a phone); src, alt and caption are then unused. kh-report makes one from images that follow each other. A picture with `wide` (kh-report sets it when the image is wider than tall, a desktop shot) takes a row of its own; the others (phone shots) sit side by side. */\n  images: z.array(z.object({ src: z.string().max(3_000_000), alt: t(300), caption: t(300), wide: z.boolean().optional() })).max(12).optional(),\n});\n\nexport const spec = defineSpec({\n  type: 'report-figure',\n  aliases: ['report/figure'],\n  name: 'Report, figure',\n  category: 'report',\n  role: 'body',\n  description: 'A picture in a report, or a gallery of them, shown whole (never cropped, at most 90 % of the screen tall) with an optional title and captions, for decisions that need a visual pick. kh-report embeds a local image file as a data address so the page stays one file; remote addresses are refused there.',\n  schema,\n  defaults: {\n    title: 'Name what is shown',\n    src: '',\n    alt: 'Show what the picture contains',\n    caption: 'Say what to look at in the picture, in a line',\n    width: 'text',\n  },\n});\n"
    },
    {
      "path": "src/blocks/report-figure/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/report-figure/index.tsx",
      "content": "import { useId } from 'react';\nimport { Media, withHeadingLevel } from '../../editing';\nimport { cn } from '../../lib/utils';\nimport { Opt } from '../_shared/kit';\nimport { ReportSection, ReportTitle } from '../_shared/report-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nconst isDataVideo = (src: string) => /^data:video\\//i.test(src);\nconst isWebVideo = (src: string) => /^https?:\\/\\//i.test(src);\n\n// Shown whole and never taller than the screen (Felix 2026-10-24: phone shots ran past the window on desktop, \"each image max\n// height 90svh\"): the box hugs the picture, so its border and corners follow it.\nconst FIT = 'w-fit max-w-full rounded-kh-lg border border-kh-line [&>img]:max-h-[90svh] [&>img]:w-auto [&>img]:max-w-full';\n\nfunction Picture({ src, alt, path }: { src: string; alt: string; path: (string | number)[] }) {\n  if (isDataVideo(src)) return <video controls playsInline preload=\"metadata\" src={src} aria-label={alt} className=\"max-h-[90svh] w-full rounded-kh-lg border border-kh-line\" />;\n  if (isWebVideo(src)) {\n    return (\n      <a href={src} target=\"_blank\" rel=\"noopener noreferrer\" className=\"block rounded-kh-lg border border-kh-line p-4 text-kh-body underline [overflow-wrap:anywhere]\">\n        {'\\u25B6 Watch video: '}{alt || src}\n      </a>\n    );\n  }\n  return <Media path={path} value={{ src, alt }} ratio=\"auto\" allowData className={FIT} />;\n}\n\nfunction ReportFigure({ props }: BlockProps<Props>) {\n  const id = useId();\n  const gallery = (props.images ?? []).filter((x) => x.src);\n  return (\n    <ReportSection labelledBy={props.title ? id : undefined} className=\"py-4 @3xl:py-5 print:py-2\">\n      <ReportTitle id={id} title={props.title} />\n      {gallery.length > 0 ? (\n        // Pictures that follow each other: phone shots side by side on a wide page (two, then three across), one column on a phone;\n        // a desktop shot (wide) always takes its own row (Felix 2026-11-04: \"desktop screens always get their own row\").\n        <ul className={cn('grid grid-cols-1 items-start gap-4 @2xl:grid-cols-2 @5xl:grid-cols-3', props.title && 'mt-4')}>\n          {gallery.map((x, i) => (\n            <li key={i} className={cn('min-w-0', x.wide && 'col-span-full')}>\n              <figure className=\"print:break-inside-avoid\">\n                <Picture src={x.src} alt={x.alt} path={['images', i, 'src']} />\n                <Opt path={['images', i, 'caption']} value={x.caption} as=\"figcaption\" className=\"mt-2 text-kh-small text-kh-muted [overflow-wrap:anywhere]\" placeholder=\"Caption\" />\n              </figure>\n            </li>\n          ))}\n        </ul>\n      ) : (\n        <figure className={cn('print:break-inside-avoid', props.title && 'mt-4', props.width === 'wide' ? '' : 'max-w-kh-prose')}>\n          {/* shown whole: the box takes the picture's own shape (ratio auto), and a picture that is not drawn leaves its alt text, not a hole */}\n          <Picture src={props.src} alt={props.alt || props.caption} path={['src']} />\n          <Opt path={['caption']} value={props.caption} as=\"figcaption\" className=\"mt-2 text-kh-small text-kh-muted [overflow-wrap:anywhere]\" placeholder=\"Caption\" />\n        </figure>\n      )}\n    </ReportSection>\n  );\n}\n\nexport default withHeadingLevel(ReportFigure);\n"
    }
  ]
}
