{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "page-preview-card",
  "type": "registry:ui",
  "title": "Page Preview Card",
  "description": "The page-preview-card primitive.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/badge.json",
    "https://ui.klarhimmel.com/r/skeleton.json",
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/page-preview-card.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/page-preview-card.tsx",
      "content": "import { useEffect, useRef, useState, type ReactNode } from 'react';\nimport { cn } from '../lib/utils';\nimport { Badge } from './badge';\nimport { Skeleton } from './skeleton';\n\nexport interface PagePreviewCardProps {\n  /** The page to show: a same-origin preview URL. It renders at `viewport` px wide and is scaled down to the card. */\n  src: string;\n  /** One line; the card's link text. */\n  title: ReactNode;\n  /** Where the card goes (the editor, the live page). */\n  href: string;\n  /** A quiet line under the title: the address, when it was changed. */\n  meta?: ReactNode;\n  /** A string becomes a neutral Badge (Live, Draft); pass a Badge for another tone. */\n  badge?: ReactNode;\n  /** The width the page is laid out at before scaling. 1280 shows the desktop layout; 390 a phone. */\n  viewport?: number;\n  /** Iframe sandbox. The default runs no scripts, so a preview must be server-rendered HTML. */\n  sandbox?: string;\n  /** Renders the title link, for a router's Link (keeps app paths and client navigation). Default: a plain <a>. */\n  link?: (props: { href: string; className: string; children: ReactNode }) => ReactNode;\n  className?: string;\n}\n\nconst plainLink: NonNullable<PagePreviewCardProps['link']> = ({ href, className, children }) => <a href={href} className={className}>{children}</a>;\n\n/**\n * A page as a picture: the real page, scaled into a 16:10 card, with its title, an optional meta line and a badge.\n * The whole card is one link (a stretched title link, so the iframe is never inside an <a>). The preview is decorative:\n * hidden from assistive tech, not focusable, no pointer events. A skeleton holds the space until the page has loaded.\n */\nexport function PagePreviewCard({ src, title, href, meta, badge, viewport = 1280, sandbox = 'allow-same-origin', link = plainLink, className }: PagePreviewCardProps) {\n  const frame = useRef<HTMLDivElement>(null);\n  const [scale, setScale] = useState(0);\n  const [loaded, setLoaded] = useState(false);\n\n  // Size and scale are set from script, never as a style attribute: the server HTML stays CSP-clean (style-src 'self').\n  useEffect(() => {\n    const el = frame.current;\n    const page = el?.querySelector('iframe');\n    if (!el || !page) return;\n    const measure = () => {\n      const k = el.clientWidth / viewport;\n      page.style.width = `${viewport}px`;\n      page.style.height = `${viewport * 10 / 16}px`;\n      page.style.transform = `scale(${k || 1})`;\n      setScale(k);\n    };\n    measure();\n    if (typeof ResizeObserver === 'undefined') return;\n    const ro = new ResizeObserver(measure);\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [viewport]);\n\n  // A server-rendered frame can finish loading before hydration attaches onLoad, so the event is missed and the skeleton\n  // stays: listen natively, and count a same-origin document that is already complete as loaded.\n  useEffect(() => {\n    const page = frame.current?.querySelector('iframe');\n    if (!page) return;\n    const done = () => setLoaded(true);\n    page.addEventListener('load', done);\n    try {\n      const doc = page.contentDocument;\n      if (doc && doc.readyState === 'complete' && doc.location.href !== 'about:blank') done();\n    } catch { /* not same-origin: wait for the load event */ }\n    return () => page.removeEventListener('load', done);\n  }, [src]);\n\n  const ready = loaded && scale > 0;\n  return (\n    <article className={cn('group relative flex min-w-0 flex-col overflow-hidden rounded-kh-lg border border-kh-line bg-kh-surface transition-shadow hover:shadow-kh-2 has-[a:focus-visible]:outline-2 has-[a:focus-visible]:outline-offset-2 has-[a:focus-visible]:outline-(--kh-focus)', className)}>\n      <div ref={frame} className=\"relative aspect-[16/10] overflow-hidden border-b border-kh-line bg-kh-surface-2\">\n        {!ready && <Skeleton className=\"absolute inset-0 rounded-none\" />}\n        <iframe\n          src={src}\n          title=\"\"\n          aria-hidden\n          tabIndex={-1}\n          loading=\"lazy\"\n          sandbox={sandbox}\n          className={cn('pointer-events-none absolute left-0 top-0 origin-top-left border-0 bg-kh-canvas transition-opacity motion-reduce:transition-none', ready ? 'opacity-100' : 'opacity-0')}\n        />\n      </div>\n      <div className=\"flex min-w-0 items-start gap-3 p-4\">\n        <div className=\"min-w-0 flex-1\">\n          <h3 className=\"truncate text-kh-body font-medium text-kh-ink\">\n            {link({ href, className: \"outline-none after:absolute after:inset-0 after:content-['']\", children: title })}\n          </h3>\n          {meta && <p className=\"mt-0.5 truncate text-kh-small text-kh-muted\">{meta}</p>}\n        </div>\n        {badge && <div className=\"relative shrink-0\">{typeof badge === 'string' ? <Badge>{badge}</Badge> : badge}</div>}\n      </div>\n    </article>\n  );\n}\n"
    }
  ]
}
