{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "lightbox",
  "title": "Lightbox",
  "description": "Astro image zoom and media detail views with a dialog container.",
  "dependencies": [
    "class-variance-authority",
    "cn"
  ],
  "registryDependencies": [
    "@gnostic/dialog"
  ],
  "files": [
    {
      "path": "packages/ui/src/components/ui/lightbox/index.ts",
      "content": "// Dialog supplies the root behavior. Lightbox supplies the media layout.\nexport { default as Lightbox } from '../dialog/dialog.astro'\nexport { default as LightboxContent } from './lightbox-content.astro'\nexport { default as LightboxTrigger } from './lightbox-trigger.astro'\nexport { default as LightboxImage } from './lightbox-image.astro'\nexport type {\n    LightboxContentProps,\n    LightboxProps,\n    LightboxTriggerProps,\n} from './types.ts'\n",
      "type": "registry:file",
      "target": "~/src/components/ui/lightbox/index.ts"
    },
    {
      "path": "packages/ui/src/components/ui/lightbox/types.ts",
      "content": "import type { DialogOptions } from '../dialog/types.ts'\nimport type { LightboxPopupVariantProps } from './lightbox-variants.ts'\n\n/** Options for the dialog that shows the enlarged view. */\nexport type LightboxProps = Omit<DialogOptions, 'alertDialog'>\n\n/** Props for the thumbnail button. */\nexport interface LightboxTriggerProps {\n    /**\n     * Scale the preview on hover.\n     * Adds the class `hover:scale-105`.\n     *\n     * @default false\n     */\n    hoverZoom?: boolean\n}\n\n/** Props for the enlarged media view. */\nexport interface LightboxContentProps {\n    /** Accessible name, rendered as a visually hidden dialog title. */\n    label: string\n    /** Text below the media. The caption slot takes precedence. */\n    caption?: string\n    /** Classes for the media container. */\n    mediaClass?: string\n    /**\n     * `panel` centers the media in a dialog.\n     * `default` fills the screen and uses a dark backdrop.\n     *\n     * @default 'default'\n     */\n    variant?: LightboxPopupVariantProps['variant']\n    /**\n     * Show the close button.\n     *\n     * @default true\n     */\n    showCloseButton?: boolean\n    /** Extra classes for the backdrop. */\n    overlayClass?: string\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/lightbox/types.ts"
    },
    {
      "path": "packages/ui/src/components/ui/lightbox/lightbox-image.astro",
      "content": "---\nimport { Image } from \"astro:assets\"\nimport type { ComponentProps } from \"astro/types\"\nimport { cn } from \"cn\"\n\ntype Props = ComponentProps<typeof Image>\n\nconst {\n  widths = [100, 250, 500, 1000, 1250],\n  class: className,\n  ...props\n} = Astro.props\n---\n\n<Image\n  {...({ ...props, widths } as Props)}\n  data-slot=\"lightbox-image-trigger\"\n  role=\"button\"\n  tabindex={0}\n  aria-label={`Enlarge image: ${props.alt}`}\n  aria-expanded=\"false\"\n  class={cn(\n    \"cursor-zoom-in focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-ring\",\n    className,\n  )}\n/>\n\n<script>\n  // Image-only zoom. Dialog remains the container for captions and carousels.\n  const selector = '[data-slot=\"lightbox-image-trigger\"]'\n  let active:\n    { close: (immediate?: boolean, restoreFocus?: boolean) => void } | undefined\n\n  function open(image: HTMLImageElement) {\n    if (!image.complete || !image.naturalWidth) return\n    active?.close(true, false)\n\n    const rect = image.getBoundingClientRect()\n    if (!rect.width || !rect.height) return\n\n    const overlay = document.createElement(\"button\")\n    overlay.type = \"button\"\n    overlay.dataset.slot = \"lightbox-overlay\"\n    overlay.setAttribute(\"aria-label\", \"Close enlarged image\")\n    overlay.className =\n      \"fixed inset-0 z-[100] m-0 size-full cursor-zoom-out border-0 bg-transparent p-0 text-foreground focus-visible:outline-none\"\n\n    // Fade only the backdrop so the image stays opaque throughout the zoom.\n    const backdrop = document.createElement(\"span\")\n    backdrop.dataset.slot = \"lightbox-backdrop\"\n    backdrop.setAttribute(\"aria-hidden\", \"true\")\n    backdrop.className =\n      \"pointer-events-none absolute inset-0 bg-background/95 backdrop-blur-sm\"\n\n    // Do not copy thumbnail classes, IDs, or responsive layout constraints.\n    const zoomed = document.createElement(\"img\")\n    zoomed.dataset.slot = \"lightbox-image\"\n    zoomed.alt = image.alt\n    zoomed.src = image.currentSrc || image.src\n    zoomed.srcset = image.srcset\n    zoomed.sizes = \"90vw\"\n    zoomed.draggable = false\n    zoomed.className =\n      \"absolute m-0 max-h-none max-w-none origin-top-left object-contain\"\n\n    const ratio = image.naturalWidth / image.naturalHeight\n    const width = Math.min(\n      window.innerWidth * 0.9,\n      window.innerHeight * 0.9 * ratio,\n    )\n    const height = width / ratio\n    const left = (window.innerWidth - width) / 2\n    const top = (window.innerHeight - height) / 2\n    Object.assign(zoomed.style, {\n      width: `${width}px`,\n      height: `${height}px`,\n      left: `${left}px`,\n      top: `${top}px`,\n    })\n    const thumbnailTransform = () => {\n      const bounds = image.getBoundingClientRect()\n      return `translate(${bounds.left - left}px, ${bounds.top - top}px) scale(${bounds.width / width}, ${bounds.height / height})`\n    }\n    const reducedMotion = window.matchMedia(\n      \"(prefers-reduced-motion: reduce)\",\n    ).matches\n    const timing = {\n      duration: reducedMotion ? 0 : 300,\n      easing: \"cubic-bezier(0.2, 0, 0, 1)\",\n      fill: \"both\" as const,\n    }\n    const visibility = image.style.getPropertyValue(\"visibility\")\n    const visibilityPriority = image.style.getPropertyPriority(\"visibility\")\n    const events = new AbortController()\n    let closing = false\n    let removed = false\n\n    overlay.append(backdrop, zoomed)\n    document.body.append(overlay)\n    image.setAttribute(\"aria-expanded\", \"true\")\n    overlay.focus({ preventScroll: true })\n    image.style.setProperty(\"visibility\", \"hidden\")\n\n    let movement = zoomed.animate(\n      [{ transform: thumbnailTransform() }, { transform: \"none\" }],\n      timing,\n    )\n    let fade = backdrop.animate([{ opacity: 0 }, { opacity: 1 }], timing)\n\n    function remove(restoreFocus: boolean) {\n      if (removed) return\n      removed = true\n      events.abort()\n      movement.cancel()\n      fade.cancel()\n      overlay.remove()\n      if (visibility)\n        image.style.setProperty(\"visibility\", visibility, visibilityPriority)\n      else image.style.removeProperty(\"visibility\")\n      image.setAttribute(\"aria-expanded\", \"false\")\n      if (active === instance) active = undefined\n      if (restoreFocus && image.isConnected)\n        image.focus({ preventScroll: true })\n    }\n\n    function close(immediate = false, restoreFocus = true) {\n      if (immediate) return remove(restoreFocus)\n      if (closing) return\n      closing = true\n      const transform = getComputedStyle(zoomed).transform\n      const opacity = getComputedStyle(backdrop).opacity\n      movement.cancel()\n      fade.cancel()\n      movement = zoomed.animate(\n        [{ transform }, { transform: thumbnailTransform() }],\n        timing,\n      )\n      fade = backdrop.animate([{ opacity }, { opacity: 0 }], timing)\n      void movement.finished.then(\n        () => remove(restoreFocus),\n        () => {},\n      )\n    }\n\n    const instance = { close }\n    active = instance\n    const { signal } = events\n    overlay.addEventListener(\"click\", () => close(), { signal })\n    document.addEventListener(\n      \"keydown\",\n      (event) => {\n        if (event.key === \"Escape\") {\n          event.preventDefault()\n          close()\n        } else if (event.key === \"Tab\") {\n          // Return to the thumbnail before the browser moves to the next control.\n          close(true)\n        }\n      },\n      { signal },\n    )\n    document.addEventListener(\n      \"scroll\",\n      () => {\n        // A scroll queued before opening must not close the new zoom.\n        const bounds = image.getBoundingClientRect()\n        if (bounds.top !== rect.top || bounds.left !== rect.left) close(true)\n      },\n      {\n        capture: true,\n        passive: true,\n        signal,\n      },\n    )\n    window.addEventListener(\"resize\", () => close(true), { signal })\n  }\n\n  // Delegation also covers examples inserted after the first page load.\n  document.addEventListener(\"click\", (event) => {\n    const image = event.target\n    if (image instanceof HTMLImageElement && image.matches(selector))\n      open(image)\n  })\n  document.addEventListener(\"keydown\", (event) => {\n    const image = event.target\n    if (!(image instanceof HTMLImageElement) || !image.matches(selector)) return\n    if (event.key === \"Enter\" || event.key === \" \") {\n      event.preventDefault()\n      if (!event.repeat) open(image)\n    }\n  })\n  document.addEventListener(\"astro:before-swap\", () =>\n    active?.close(true, false),\n  )\n</script>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/lightbox/lightbox-image.astro"
    },
    {
      "path": "packages/ui/src/components/ui/lightbox/lightbox-content.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport { cn } from \"cn\"\nimport {\n  DialogClose,\n  DialogDescription,\n  DialogOverlay,\n  DialogPortal,\n  DialogTitle,\n} from \"../dialog/index.ts\"\nimport {\n  lightboxOverlayVariants,\n  lightboxPopupVariants,\n} from \"./lightbox-variants.ts\"\nimport type { LightboxContentProps } from \"./types.ts\"\n\ntype Props = HTMLAttributes<\"div\"> & LightboxContentProps\n\nconst {\n  class: className,\n  label,\n  caption,\n  mediaClass,\n  overlayClass,\n  showCloseButton = true,\n  style: styleProp,\n  variant = \"default\",\n  ...props\n} = Astro.props\n\nif (!label?.trim()) throw new Error(\"LightboxContent requires a label.\")\n\nconst style =\n  typeof styleProp === \"string\"\n    ? `z-index: calc(var(--dialog-content-stack-index, 0) * 2 + 101); ${styleProp}`\n    : {\n        \"z-index\": \"calc(var(--dialog-content-stack-index, 0) * 2 + 101)\",\n        ...styleProp,\n      }\n---\n\n<DialogPortal>\n  <DialogOverlay\n    class={cn(lightboxOverlayVariants({ variant }), overlayClass)}\n  />\n  <div\n    data-slot=\"dialog-content\"\n    data-variant={variant}\n    hidden\n    class={cn(lightboxPopupVariants({ variant }), className)}\n    style={style}\n    {...props}\n  >\n    {showCloseButton && (\n      <DialogClose\n        variant=\"ghost\"\n        size=\"icon-sm\"\n        class={cn(\n          \"pointer-events-auto absolute top-4 right-4\",\n          variant === \"default\" && \"text-white hover:bg-white/12\",\n        )}\n      />\n    )}\n    <DialogTitle class=\"sr-only\" data-lightbox-title>\n      {label}\n    </DialogTitle>\n    <div\n      data-slot=\"lightbox-media\"\n      class={cn(\n        \"size-full *:pointer-events-auto *:mx-auto *:h-auto *:max-h-[calc(100dvh-10rem)] *:w-full *:object-contain [&>:where(img,video)]:w-full [&>:where(img,video)]:max-w-full\",\n        mediaClass,\n      )}\n    >\n      <slot />\n    </div>\n    {(caption || Astro.slots.has(\"caption\")) && (\n      <DialogDescription\n        class={cn(\n          \"pointer-events-auto shrink-0 text-center\",\n          variant === \"default\" && \"text-white/80\",\n        )}\n      >\n        <slot name=\"caption\">{caption}</slot>\n      </DialogDescription>\n    )}\n  </div>\n</DialogPortal>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/lightbox/lightbox-content.astro"
    },
    {
      "path": "packages/ui/src/components/ui/lightbox/lightbox-trigger.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport { cn } from \"cn\"\nimport type { LightboxTriggerProps } from \"./types.ts\"\n\ntype Props = Omit<HTMLAttributes<\"button\">, \"type\"> & LightboxTriggerProps\n\nconst { hoverZoom = false, class: className, ...props } = Astro.props\n\n// The button clips the scale.\n// hoverZoom adds hover:scale-105 on the preview.\n---\n\n<button\n  data-slot=\"dialog-trigger\"\n  class={cn(\n    \"bg-muted grid w-full cursor-zoom-in overflow-hidden rounded-xl border-0 p-0 focus-visible:outline-2 focus-visible:outline-offset-3 focus-visible:outline-ring\",\n    className,\n  )}\n  {...props}\n  type=\"button\"\n>\n  <span\n    data-slot=\"lightbox-preview\"\n    class={cn(\n      \"min-h-0 w-full [&_img]:pointer-events-none [&_img]:block [&_img]:max-w-full\",\n      hoverZoom &&\n        \"transition-transform duration-300 hover:scale-105 ease-in-out motion-reduce:transform-none motion-reduce:transition-none\",\n    )}\n  >\n    <slot />\n  </span>\n</button>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/lightbox/lightbox-trigger.astro"
    },
    {
      "path": "packages/ui/src/components/ui/lightbox/lightbox-variants.ts",
      "content": "import { cva, type VariantProps } from 'class-variance-authority'\n\n/**\n * Classes for the enlarged panel.\n * `panel` centers the media. `default` fills the screen.\n */\nexport const lightboxPopupVariants = cva(\n    'data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 duration-100 outline-none motion-reduce:animate-none!',\n    {\n        defaultVariants: {\n            variant: 'default',\n        },\n        variants: {\n            variant: {\n                panel: 'bg-popover text-popover-foreground ring-foreground/10 @container/dialog fixed top-1/2 left-1/2 z-50 grid max-h-[calc(100dvh-2rem)] w-[calc(100%-2rem)] max-w-6xl -translate-x-1/2 -translate-y-1/2 gap-3 overflow-y-auto rounded-xl p-4 pt-14 text-sm ring-1 sm:max-w-6xl',\n                default:\n                    'pointer-events-none fixed inset-0 flex flex-col justify-center gap-4 overflow-visible bg-transparent px-3 py-16 text-white shadow-none ring-0',\n            },\n        },\n    },\n)\n\n/**\n * Extra classes for the backdrop.\n * DialogOverlay supplies the base backdrop. These classes replace its color.\n * `panel` keeps that base. `default` uses a dark backdrop.\n */\nexport const lightboxOverlayVariants = cva('', {\n    defaultVariants: {\n        variant: 'panel',\n    },\n    variants: {\n        variant: {\n            panel: '',\n            default: 'bg-black/90',\n        },\n    },\n})\n\nexport type LightboxPopupVariantProps = VariantProps<\n    typeof lightboxPopupVariants\n>\nexport type LightboxOverlayVariantProps = VariantProps<\n    typeof lightboxOverlayVariants\n>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/lightbox/lightbox-variants.ts"
    }
  ],
  "meta": {
    "framework": "astro",
    "source": "@gnostic/ui",
    "testedDependencies": {
      "class-variance-authority": "^0.7.1",
      "cn": "0.5.2"
    }
  },
  "docs": "https://ui.gnosticai.com/components/lightbox",
  "categories": [
    "ui"
  ],
  "type": "registry:ui"
}
