{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gallery-fluted-glass-01",
  "title": "Fluted Glass Slideshow",
  "description": "A wide slideshow where each new slide arrives through ribbed glass that splits it into bent vertical strips, which line up into a clear picture as it lands, with autoplay, a pause button, arrows, and a bar per slide",
  "dependencies": [
    "lucide-react@1",
    "motion@13"
  ],
  "registryDependencies": [
    "https://ui.cortexcn.dev/r/utils.json",
    "button"
  ],
  "files": [
    {
      "path": "registry/blocks/gallery-fluted-glass-01/components/fluted-glass-slideshow.tsx",
      "content": "\"use client\";\n\nimport { useReducedMotion } from \"motion/react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { FlutedLayer } from \"./fluted-glass/fluted-layer\";\nimport { SlideCaption } from \"./fluted-glass/slide-caption\";\nimport { SlideControls } from \"./fluted-glass/slide-controls\";\nimport { SlideProgress } from \"./fluted-glass/slide-progress\";\nimport { DEFAULT_SLIDES, type Slide } from \"./fluted-glass/slides\";\nimport { usePageHidden, useSlideshow } from \"./fluted-glass/use-slideshow\";\n\n// Cortexcn item \"gallery-fluted-glass-01\", revision 1290ed066905, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-fluted-glass-01/1290ed066905.json\n\nexport type { Slide } from \"./fluted-glass/slides\";\n\nexport interface FlutedGlassSlideshowProps {\n  slides?: Slide[];\n  /** Seconds each slide stays while the slideshow plays. */\n  interval?: number;\n  /** Vertical ribs in the glass. Fewer, wider ribs bend the picture more. */\n  flutes?: number;\n  /** Moves on by itself. Always off for visitors who prefer less motion. */\n  autoPlay?: boolean;\n  /** Names the slideshow for screen readers. */\n  label?: string;\n  className?: string;\n}\n\n/**\n * A wide slideshow where each new slide arrives through fluted glass: cut\n * into vertical ribs that bend it, which clear one after another as it lands.\n * It plays on its own; pointing at it holds it, and focus inside or the\n * pause button stops it until Play is pressed. Arrow keys, the previous and\n * next buttons, and the bars along the bottom move between slides.\n */\nexport function FlutedGlassSlideshow({\n  slides = DEFAULT_SLIDES,\n  interval = 6,\n  flutes = 24,\n  autoPlay = true,\n  label = \"Paintings\",\n  className,\n}: FlutedGlassSlideshowProps) {\n  const show = useSlideshow(slides.length);\n  const reduceMotion = useReducedMotion();\n  const pageHidden = usePageHidden();\n  const [userPaused, setUserPaused] = useState(false);\n  const [hovered, setHovered] = useState(false);\n  const [focused, setFocused] = useState(false);\n  /** Play pressed while focus is inside, which overrides the focus pause. */\n  const [resumed, setResumed] = useState(false);\n\n  const autoplay = autoPlay && reduceMotion === false && slides.length > 1;\n  // Focus inside stops it until Play is pressed; pointing at it only holds it.\n  const paused = userPaused || (focused && !resumed);\n  const playing = autoplay && !paused && !hovered && !pageHidden;\n\n  const rootRef = useRef<HTMLElement>(null);\n  const moves = useRef({ next: show.next, previous: show.previous });\n  moves.current = { next: show.next, previous: show.previous };\n\n  // Arrow keys move between slides, focus inside stops autoplay until Play\n  // is pressed, and pointing at the slideshow holds it.\n  useEffect(() => {\n    const root = rootRef.current;\n    if (!root) {\n      return;\n    }\n    const onKeyDown = (event: KeyboardEvent) => {\n      if (event.key === \"ArrowRight\") {\n        event.preventDefault();\n        moves.current.next();\n      } else if (event.key === \"ArrowLeft\") {\n        event.preventDefault();\n        moves.current.previous();\n      }\n    };\n    const onFocusIn = () => setFocused(true);\n    const onFocusOut = (event: FocusEvent) => {\n      if (!root.contains(event.relatedTarget as Node | null)) {\n        setFocused(false);\n        setResumed(false);\n      }\n    };\n    const onEnter = () => setHovered(true);\n    const onLeave = () => setHovered(false);\n    root.addEventListener(\"keydown\", onKeyDown);\n    root.addEventListener(\"focusin\", onFocusIn);\n    root.addEventListener(\"focusout\", onFocusOut);\n    root.addEventListener(\"pointerenter\", onEnter);\n    root.addEventListener(\"pointerleave\", onLeave);\n    return () => {\n      root.removeEventListener(\"keydown\", onKeyDown);\n      root.removeEventListener(\"focusin\", onFocusIn);\n      root.removeEventListener(\"focusout\", onFocusOut);\n      root.removeEventListener(\"pointerenter\", onEnter);\n      root.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, []);\n\n  // Loads every picture up front, so no slide waits on the network mid-change.\n  useEffect(() => {\n    for (const slide of slides) {\n      const image = new Image();\n      image.src = slide.src;\n    }\n  }, [slides]);\n\n  const slide = slides[show.current];\n  const base = slides[show.base];\n  if (!(slide && base)) {\n    return null;\n  }\n\n  const change = show.change;\n  const arriving = change ? slides[change.to] : undefined;\n\n  const togglePause = () => {\n    if (paused) {\n      setUserPaused(false);\n      setResumed(true);\n    } else {\n      setUserPaused(true);\n    }\n  };\n\n  return (\n    <section\n      aria-label={label}\n      aria-roledescription=\"carousel\"\n      className={cn(\"w-full\", className)}\n      ref={rootRef}\n    >\n      <div className=\"relative aspect-4/3 w-full overflow-hidden rounded-2xl bg-muted sm:aspect-video lg:aspect-21/9\">\n        {/* biome-ignore lint/performance/noImgElement: framework-agnostic registry block */}\n        <img\n          alt=\"\"\n          className=\"absolute inset-0 size-full object-cover\"\n          decoding=\"async\"\n          draggable={false}\n          height={base.height}\n          src={base.src}\n          width={base.width}\n        />\n        {change && arriving ? (\n          <FlutedLayer\n            direction={change.direction}\n            flutes={flutes}\n            key={change.id}\n            onSettled={() => show.settle(change.id)}\n            slide={arriving}\n          />\n        ) : null}\n\n        {/* Keeps the caption and controls readable on light pictures. */}\n        <div\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute inset-x-0 bottom-0 h-3/4 bg-linear-to-t from-black/70 via-black/25 to-transparent\"\n        />\n\n        <div className=\"absolute inset-x-0 bottom-0 flex flex-col gap-3 p-4 sm:gap-4 sm:p-6 lg:p-8\">\n          <div className=\"flex items-end justify-between gap-4\">\n            {/* biome-ignore lint/a11y/useSemanticElements: a carousel slide is a labeled group, not a form fieldset */}\n            <div\n              aria-label={`${show.current + 1} of ${slides.length}`}\n              aria-live={playing ? \"off\" : \"polite\"}\n              aria-roledescription=\"slide\"\n              className=\"min-w-0\"\n              role=\"group\"\n            >\n              <SlideCaption\n                count={slides.length}\n                index={show.current}\n                slide={slide}\n              />\n              <p className=\"sr-only\">{slide.alt}</p>\n            </div>\n            <SlideControls\n              autoplay={autoplay}\n              onNext={show.next}\n              onPrevious={show.previous}\n              onTogglePause={togglePause}\n              paused={paused}\n            />\n          </div>\n          <SlideProgress\n            autoplay={autoplay}\n            current={show.current}\n            onDone={show.next}\n            onSelect={(index) => show.goTo(index)}\n            playing={playing}\n            seconds={interval}\n            slides={slides}\n          />\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/fluted-glass-slideshow.tsx"
    },
    {
      "path": "registry/blocks/gallery-fluted-glass-01/components/fluted-glass/fluted-layer.tsx",
      "content": "\"use client\";\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport type { Slide } from \"./slides\";\nimport type { Direction } from \"./use-slideshow\";\n\n// Cortexcn item \"gallery-fluted-glass-01\", revision 1290ed066905, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-fluted-glass-01/1290ed066905.json\n\ninterface FlutedLayerProps {\n  slide: Slide;\n  direction: Direction;\n  /** Vertical ribs in the glass. */\n  flutes: number;\n  /** Called once the glass has cleared and the picture is whole. */\n  onSettled: () => void;\n}\n\n/** Seconds the arriving slide takes to cross the frame. */\nconst SLIDE_SECONDS = 0.9;\n/** When the glass starts to clear, as a share of the slide. */\nconst CLEAR_START = 0.55;\n/** Seconds between one rib clearing and the next. */\nconst CLEAR_STAGGER = 0.022;\n/** Seconds each rib takes to clear. */\nconst CLEAR_SECONDS = 0.62;\n\n/** How much each rib magnifies its slice, like a lens, before it clears. */\nconst RIB_ZOOM = 1.22;\n/** Pixels each slice is pushed against the travel, as the glass bends it. */\nconst RIB_SHIFT = 10;\n\nconst SLIDE_EASE = [0.65, 0, 0.35, 1] as const;\nconst CLEAR_EASE = [0.22, 1, 0.36, 1] as const;\n\n/** Light down one side of each rib and shade down the other. */\nconst RIB_SHEEN =\n  \"linear-gradient(90deg, rgb(255 255 255 / 0.32), rgb(255 255 255 / 0) 36%, rgb(0 0 0 / 0) 64%, rgb(0 0 0 / 0.22))\";\n\nfunction Rib({\n  slide,\n  index,\n  flutes,\n  direction,\n  delay,\n  onCleared,\n}: {\n  slide: Slide;\n  index: number;\n  flutes: number;\n  direction: Direction;\n  delay: number;\n  onCleared?: () => void;\n}) {\n  const left = (index / flutes) * 100;\n  const right = ((flutes - index - 1) / flutes) * 100;\n  const center = ((index + 0.5) / flutes) * 100;\n  const transition = { delay, duration: CLEAR_SECONDS, ease: CLEAR_EASE };\n\n  return (\n    <div\n      className=\"absolute inset-0\"\n      style={{ clipPath: `inset(0 ${right}% 0 ${left}%)` }}\n    >\n      {/* biome-ignore lint/performance/noImgElement: framework-agnostic registry block */}\n      <motion.img\n        alt=\"\"\n        animate={{ x: 0, scaleX: 1 }}\n        className=\"absolute inset-0 size-full object-cover will-change-transform\"\n        decoding=\"async\"\n        draggable={false}\n        height={slide.height}\n        initial={{ x: -direction * RIB_SHIFT, scaleX: RIB_ZOOM }}\n        onAnimationComplete={onCleared}\n        src={slide.src}\n        style={{ transformOrigin: `${center}% 50%` }}\n        transition={transition}\n        width={slide.width}\n      />\n      <motion.span\n        animate={{ opacity: 0 }}\n        className=\"absolute inset-y-0\"\n        initial={{ opacity: 1 }}\n        style={{\n          left: `${left}%`,\n          right: `${right}%`,\n          backgroundImage: RIB_SHEEN,\n        }}\n        transition={transition}\n      />\n    </div>\n  );\n}\n\n/**\n * The arriving slide, seen through a sheet of fluted glass. It slides in cut\n * into vertical ribs, each showing its own slice magnified and pushed aside\n * the way ribbed glass bends light, with light down one edge and shade down\n * the other. Once it lands, the ribs ease back one after another, starting\n * from the side it came from, until the slices meet as one clear picture.\n * With reduced motion it fades in instead.\n */\nexport function FlutedLayer({\n  slide,\n  direction,\n  flutes,\n  onSettled,\n}: FlutedLayerProps) {\n  const reduceMotion = useReducedMotion();\n\n  if (reduceMotion) {\n    return (\n      // biome-ignore lint/performance/noImgElement: framework-agnostic registry block\n      <motion.img\n        alt=\"\"\n        animate={{ opacity: 1 }}\n        className=\"absolute inset-0 size-full object-cover\"\n        height={slide.height}\n        initial={{ opacity: 0 }}\n        onAnimationComplete={onSettled}\n        src={slide.src}\n        transition={{ duration: 0.35 }}\n        width={slide.width}\n      />\n    );\n  }\n\n  const ribs = Array.from({ length: flutes }, (_, rib) => rib);\n  const clearFrom = SLIDE_SECONDS * CLEAR_START;\n\n  return (\n    <motion.div\n      animate={{ x: \"0%\" }}\n      aria-hidden=\"true\"\n      className=\"absolute inset-0\"\n      initial={{ x: `${direction * 100}%` }}\n      transition={{ duration: SLIDE_SECONDS, ease: SLIDE_EASE }}\n    >\n      {ribs.map((rib) => {\n        // The ribs clear in the order the slide travels.\n        const order = direction === 1 ? rib : flutes - 1 - rib;\n        return (\n          <Rib\n            delay={clearFrom + order * CLEAR_STAGGER}\n            direction={direction}\n            flutes={flutes}\n            index={rib}\n            key={rib}\n            onCleared={order === flutes - 1 ? onSettled : undefined}\n            slide={slide}\n          />\n        );\n      })}\n    </motion.div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/fluted-glass/fluted-layer.tsx"
    },
    {
      "path": "registry/blocks/gallery-fluted-glass-01/components/fluted-glass/slide-caption.tsx",
      "content": "\"use client\";\n\nimport { AnimatePresence, motion } from \"motion/react\";\nimport type { Slide } from \"./slides\";\n\n// Cortexcn item \"gallery-fluted-glass-01\", revision 1290ed066905, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-fluted-glass-01/1290ed066905.json\n\nfunction pad(value: number) {\n  return String(value).padStart(2, \"0\");\n}\n\n/**\n * The slide's number, title, and one line about it, over the picture. The\n * words change as soon as a new slide is picked, while its glass clears.\n */\nexport function SlideCaption({\n  slide,\n  index,\n  count,\n}: {\n  slide: Slide;\n  index: number;\n  count: number;\n}) {\n  return (\n    <div className=\"min-w-0 text-white\">\n      <p className=\"font-mono text-white/70 text-xs tabular-nums\">\n        {pad(index + 1)} / {pad(count)}\n      </p>\n      <AnimatePresence initial={false} mode=\"wait\">\n        <motion.div\n          animate={{ opacity: 1, y: 0 }}\n          exit={{ opacity: 0, y: -6 }}\n          initial={{ opacity: 0, y: 8 }}\n          key={slide.src}\n          transition={{ duration: 0.28, ease: \"easeOut\" }}\n        >\n          <p className=\"mt-1.5 truncate font-medium text-lg tracking-tight sm:text-2xl\">\n            {slide.title}\n          </p>\n          <p className=\"mt-1 hidden truncate text-sm text-white/75 sm:block\">\n            {slide.caption}\n          </p>\n        </motion.div>\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/fluted-glass/slide-caption.tsx"
    },
    {
      "path": "registry/blocks/gallery-fluted-glass-01/components/fluted-glass/slide-controls.tsx",
      "content": "\"use client\";\n\nimport { ChevronLeft, ChevronRight, Pause, Play } from \"lucide-react\";\nimport { Button } from \"@/components/ui/button\";\n\n// Cortexcn item \"gallery-fluted-glass-01\", revision 1290ed066905, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-fluted-glass-01/1290ed066905.json\n\n/** Round glassy buttons that read on any picture, in either theme. */\nconst glassButton =\n  \"rounded-full border-white/25 bg-black/25 text-white backdrop-blur-md hover:bg-black/45 hover:text-white dark:border-white/25 dark:bg-black/25 dark:hover:bg-black/45\";\n\n/**\n * Play or pause, then previous and next. The pause button only shows when\n * the slideshow plays on its own.\n */\nexport function SlideControls({\n  autoplay,\n  paused,\n  onTogglePause,\n  onPrevious,\n  onNext,\n}: {\n  autoplay: boolean;\n  paused: boolean;\n  onTogglePause: () => void;\n  onPrevious: () => void;\n  onNext: () => void;\n}) {\n  return (\n    <div className=\"flex shrink-0 items-center gap-2\">\n      {autoplay ? (\n        <Button\n          aria-label={paused ? \"Play slideshow\" : \"Pause slideshow\"}\n          className={glassButton}\n          onClick={onTogglePause}\n          size=\"icon\"\n          variant=\"outline\"\n        >\n          {paused ? <Play /> : <Pause />}\n        </Button>\n      ) : null}\n      <Button\n        aria-label=\"Previous slide\"\n        className={glassButton}\n        onClick={onPrevious}\n        size=\"icon\"\n        variant=\"outline\"\n      >\n        <ChevronLeft />\n      </Button>\n      <Button\n        aria-label=\"Next slide\"\n        className={glassButton}\n        onClick={onNext}\n        size=\"icon\"\n        variant=\"outline\"\n      >\n        <ChevronRight />\n      </Button>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/fluted-glass/slide-controls.tsx"
    },
    {
      "path": "registry/blocks/gallery-fluted-glass-01/components/fluted-glass/slide-progress.tsx",
      "content": "\"use client\";\n\nimport { type AnimationPlaybackControls, useAnimate } from \"motion/react\";\nimport { useEffect, useRef } from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport type { Slide } from \"./slides\";\n\n// Cortexcn item \"gallery-fluted-glass-01\", revision 1290ed066905, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-fluted-glass-01/1290ed066905.json\n\n/**\n * The bar of the slide on screen, filling while it plays. It pauses where it\n * is, and when it is full the slideshow moves on.\n */\nfunction PlayingFill({\n  seconds,\n  playing,\n  onDone,\n}: {\n  seconds: number;\n  playing: boolean;\n  onDone: () => void;\n}) {\n  const [scope, animate] = useAnimate<HTMLSpanElement>();\n  const controls = useRef<AnimationPlaybackControls | null>(null);\n  const done = useRef(onDone);\n  done.current = onDone;\n\n  useEffect(() => {\n    const playback = animate(\n      scope.current,\n      { scaleX: [0, 1] },\n      { duration: seconds, ease: \"linear\", onComplete: () => done.current() },\n    );\n    controls.current = playback;\n    return () => playback.stop();\n  }, [animate, scope, seconds]);\n\n  useEffect(() => {\n    if (playing) {\n      controls.current?.play();\n    } else {\n      controls.current?.pause();\n    }\n  }, [playing]);\n\n  return (\n    <span\n      className=\"absolute inset-0 origin-left rounded-full bg-white\"\n      ref={scope}\n      // A transform, not a scale class, since the animation drives `transform`.\n      style={{ transform: \"scaleX(0)\" }}\n    />\n  );\n}\n\n/**\n * One bar per slide that also picks it: the ones already seen are full, the\n * one on screen fills while the slideshow plays, and the rest are empty.\n */\nexport function SlideProgress({\n  slides,\n  current,\n  autoplay,\n  playing,\n  seconds,\n  onSelect,\n  onDone,\n}: {\n  slides: Slide[];\n  current: number;\n  autoplay: boolean;\n  playing: boolean;\n  seconds: number;\n  onSelect: (index: number) => void;\n  onDone: () => void;\n}) {\n  return (\n    <div className=\"flex items-center gap-1.5\">\n      {slides.map((slide, index) => {\n        const isCurrent = index === current;\n        return (\n          <button\n            aria-current={isCurrent ? \"true\" : undefined}\n            aria-label={`Show slide ${index + 1}, ${slide.title}`}\n            className=\"group/bar flex h-6 flex-1 items-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-white/80\"\n            key={slide.src}\n            onClick={() => onSelect(index)}\n            type=\"button\"\n          >\n            <span className=\"relative h-1 w-full overflow-hidden rounded-full bg-white/30 transition-colors group-hover/bar:bg-white/45\">\n              {isCurrent && autoplay ? (\n                <PlayingFill\n                  key={current}\n                  onDone={onDone}\n                  playing={playing}\n                  seconds={seconds}\n                />\n              ) : (\n                <span\n                  className={cn(\n                    \"absolute inset-0 origin-left rounded-full bg-white transition-transform duration-300\",\n                    index <= current ? \"scale-x-100\" : \"scale-x-0\",\n                  )}\n                />\n              )}\n            </span>\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/fluted-glass/slide-progress.tsx"
    },
    {
      "path": "registry/blocks/gallery-fluted-glass-01/components/fluted-glass/slides.ts",
      "content": "export interface Slide {\n  src: string;\n  /** Describes the picture for screen readers. */\n  alt: string;\n  title: string;\n  caption: string;\n  /** The picture's size, so the browser can reserve its space. */\n  width: number;\n  height: number;\n}\n\n// Cortexcn item \"gallery-fluted-glass-01\", revision 1290ed066905, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-fluted-glass-01/1290ed066905.json\n\n/** The oil paintings from the Cortexcn site. Swap in your own pictures. */\nconst ART_BASE = \"https://www.cortexcn.dev/images/ui-home\";\n\nexport const DEFAULT_SLIDES: Slide[] = [\n  {\n    src: `${ART_BASE}/pastel-meadow-flowers.webp`,\n    alt: \"An oil painting of white flowers on tall stems bending in the wind against a pale blue sky\",\n    title: \"Wind through the meadow\",\n    caption: \"White blooms on tall stems, leaning into a blue haze.\",\n    width: 1344,\n    height: 896,\n  },\n  {\n    src: `${ART_BASE}/meadow-grass.webp`,\n    alt: \"An oil painting of tall grass and seed heads sweeping across a blue sky\",\n    title: \"Tall grass\",\n    caption: \"Seed heads sweeping across an open sky.\",\n    width: 1344,\n    height: 896,\n  },\n  {\n    src: `${ART_BASE}/white-blossoms.webp`,\n    alt: \"An oil painting of a branch of white blossoms with amber centers\",\n    title: \"Blossom branch\",\n    caption: \"White petals with amber hearts, drifting in from the right.\",\n    width: 1344,\n    height: 896,\n  },\n  {\n    src: `${ART_BASE}/pastel-daisies.webp`,\n    alt: \"An oil painting of daisies with gold centers rising out of green grass\",\n    title: \"Field of daisies\",\n    caption: \"Gold centers rising out of soft green grass.\",\n    width: 1344,\n    height: 896,\n  },\n  {\n    src: `${ART_BASE}/blue-white-flowers.webp`,\n    alt: \"An oil painting of white and pink flowers whose stems blur into blue and green\",\n    title: \"Morning bouquet\",\n    caption: \"White and pink blooms, their stems washed into blue and green.\",\n    width: 1344,\n    height: 896,\n  },\n];\n",
      "type": "registry:lib",
      "target": "components/fluted-glass/slides.ts"
    },
    {
      "path": "registry/blocks/gallery-fluted-glass-01/components/fluted-glass/use-slideshow.ts",
      "content": "\"use client\";\n\nimport { useCallback, useReducer, useSyncExternalStore } from \"react\";\n\n// Cortexcn item \"gallery-fluted-glass-01\", revision 1290ed066905, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-fluted-glass-01/1290ed066905.json\n\n/** 1 when the next slide comes in from the right, -1 from the left. */\nexport type Direction = 1 | -1;\n\nexport interface SlideChange {\n  /** Counts up, so every change mounts a fresh glass layer. */\n  id: number;\n  to: number;\n  direction: Direction;\n}\n\ninterface SlideshowState {\n  /** The slide the caption and progress show: where the slideshow is going. */\n  current: number;\n  /** The slide drawn underneath, which the arriving one covers. */\n  base: number;\n  /** The change in progress, until its glass has cleared. */\n  change: SlideChange | null;\n  nextId: number;\n}\n\ntype SlideshowAction =\n  | { type: \"go\"; to: number; direction: Direction }\n  | { type: \"settle\"; id: number };\n\nfunction reducer(\n  state: SlideshowState,\n  action: SlideshowAction,\n): SlideshowState {\n  if (action.type === \"settle\") {\n    if (state.change?.id !== action.id) {\n      return state;\n    }\n    return { ...state, base: state.change.to, change: null };\n  }\n  if (action.to === state.current) {\n    return state;\n  }\n  return {\n    current: action.to,\n    // A change made while another is still landing snaps that one into place.\n    base: state.change ? state.change.to : state.base,\n    change: { id: state.nextId, to: action.to, direction: action.direction },\n    nextId: state.nextId + 1,\n  };\n}\n\n/**\n * Which slide is showing, which one sits underneath, and the change in\n * progress. `settle` is called once the arriving slide's glass has cleared.\n */\nexport function useSlideshow(count: number) {\n  const [state, dispatch] = useReducer(reducer, {\n    current: 0,\n    base: 0,\n    change: null,\n    nextId: 0,\n  });\n\n  const goTo = useCallback(\n    (to: number, direction?: Direction) => {\n      const target = ((to % count) + count) % count;\n      dispatch({\n        type: \"go\",\n        to: target,\n        direction: direction ?? (target > state.current ? 1 : -1),\n      });\n    },\n    [count, state.current],\n  );\n\n  const next = useCallback(\n    () => goTo(state.current + 1, 1),\n    [goTo, state.current],\n  );\n  const previous = useCallback(\n    () => goTo(state.current - 1, -1),\n    [goTo, state.current],\n  );\n  const settle = useCallback(\n    (id: number) => dispatch({ type: \"settle\", id }),\n    [],\n  );\n\n  return { ...state, goTo, next, previous, settle };\n}\n\nfunction subscribeVisibility(onChange: () => void) {\n  document.addEventListener(\"visibilitychange\", onChange);\n  return () => document.removeEventListener(\"visibilitychange\", onChange);\n}\n\n/** True while the tab is in the background, so autoplay can wait. */\nexport function usePageHidden() {\n  return useSyncExternalStore(\n    subscribeVisibility,\n    () => document.hidden,\n    () => false,\n  );\n}\n",
      "type": "registry:lib",
      "target": "components/fluted-glass/use-slideshow.ts"
    }
  ],
  "type": "registry:block",
  "author": "Cortexcn (https://ui.cortexcn.dev)",
  "meta": {
    "license": "MIT",
    "revision": "1290ed066905"
  }
}