{
  "name": "marquee",
  "type": "registry:ui",
  "dependencies": [
    "cn",
    "radix-ui",
    "@base-ui/utils@0.5.0"
  ],
  "cssVars": {
    "theme": {
      "--animate-marquee-left": "marquee-left var(--marquee-duration) linear var(--marquee-loop-count)",
      "--animate-marquee-right": "marquee-right var(--marquee-duration) linear var(--marquee-loop-count)",
      "--animate-marquee-left-rtl": "marquee-left-rtl var(--marquee-duration) linear var(--marquee-loop-count)",
      "--animate-marquee-right-rtl": "marquee-right-rtl var(--marquee-duration) linear var(--marquee-loop-count)",
      "--animate-marquee-up": "marquee-up var(--marquee-duration) linear var(--marquee-loop-count)",
      "--animate-marquee-down": "marquee-down var(--marquee-duration) linear var(--marquee-loop-count)"
    }
  },
  "css": {
    "@keyframes marquee-left": {
      "0%": {
        "transform": "translateX(0%)"
      },
      "100%": {
        "transform": "translateX(calc(-100% - var(--marquee-gap)))"
      }
    },
    "@keyframes marquee-right": {
      "0%": {
        "transform": "translateX(calc(-100% - var(--marquee-gap)))"
      },
      "100%": {
        "transform": "translateX(0%)"
      }
    },
    "@keyframes marquee-up": {
      "0%": {
        "transform": "translateY(0%)"
      },
      "100%": {
        "transform": "translateY(calc(-100% - var(--marquee-gap)))"
      }
    },
    "@keyframes marquee-down": {
      "0%": {
        "transform": "translateY(calc(-100% - var(--marquee-gap)))"
      },
      "100%": {
        "transform": "translateY(0%)"
      }
    },
    "@keyframes marquee-left-rtl": {
      "0%": {
        "transform": "translateX(0%)"
      },
      "100%": {
        "transform": "translateX(calc(100% + var(--marquee-gap)))"
      }
    },
    "@keyframes marquee-right-rtl": {
      "0%": {
        "transform": "translateX(calc(100% + var(--marquee-gap)))"
      },
      "100%": {
        "transform": "translateX(0%)"
      }
    }
  },
  "files": [
    {
      "path": "ui/marquee.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport { useMergedRefs } from \"@base-ui/utils/useMergedRefs\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport { cn } from \"cn\";\nimport {\n  Direction as DirectionPrimitive,\n  Slot as SlotPrimitive,\n} from \"radix-ui\";\nimport * as React from \"react\";\n\nconst ROOT_NAME = \"Marquee\";\nconst CONTENT_NAME = \"MarqueeContent\";\n\ntype Side = \"top\" | \"right\" | \"bottom\" | \"left\";\ntype Orientation = \"horizontal\" | \"vertical\";\ntype Direction = \"ltr\" | \"rtl\";\n\ntype RootElement = HTMLDivElement;\ntype ContentElement = HTMLDivElement;\n\ninterface Dimensions {\n  width: number;\n  height: number;\n}\n\ninterface ElementDimensions {\n  rootSize: number;\n  contentSize: number;\n}\n\ninterface MarqueeSizes {\n  root: Dimensions;\n  content: Dimensions;\n}\n\nfunction getIsSameDimensions(a: Dimensions, b: Dimensions) {\n  return a.width === b.width && a.height === b.height;\n}\n\nfunction getRectDimensions(element: Element): Dimensions {\n  const rect = element.getBoundingClientRect();\n  return { width: rect.width, height: rect.height };\n}\n\nfunction getElementDimensions(\n  sizes: MarqueeSizes | null,\n  orientation: Orientation,\n): ElementDimensions | null {\n  if (!sizes) return null;\n  const key = orientation === \"vertical\" ? \"height\" : \"width\";\n  return { rootSize: sizes.root[key], contentSize: sizes.content[key] };\n}\n\ninterface MarqueeContextValue {\n  side: Side;\n  orientation: Orientation;\n  dir: Direction;\n  speed: number;\n  loopCount: number;\n  contentRef: React.RefObject<ContentElement | null>;\n  rootRef: React.RefObject<RootElement | null>;\n  dimensions: ElementDimensions | null;\n  onSizesChange: (sizes: MarqueeSizes) => void;\n  autoFill: boolean;\n  pauseOnHover: boolean;\n  pauseOnKeyboard: boolean;\n  reverse: boolean;\n  paused: boolean;\n}\n\nconst MarqueeContext = React.createContext<MarqueeContextValue | null>(null);\n\nfunction useMarqueeContext(consumerName: string) {\n  const context = React.useContext(MarqueeContext);\n  if (!context) {\n    throw new Error(`\\`${consumerName}\\` must be used within \\`${ROOT_NAME}\\``);\n  }\n  return context;\n}\n\ninterface MarqueeProps extends React.ComponentProps<\"div\"> {\n  asChild?: boolean;\n  side?: Side;\n  dir?: Direction;\n  speed?: number;\n  delay?: number;\n  loopCount?: number;\n  gap?: string | number;\n  autoFill?: boolean;\n  pauseOnHover?: boolean;\n  pauseOnKeyboard?: boolean;\n  reverse?: boolean;\n}\n\nfunction Marquee(props: MarqueeProps) {\n  const {\n    side = \"left\",\n    dir: dirProp,\n    speed = 50,\n    delay = 0,\n    loopCount = 0,\n    gap = \"1rem\",\n    asChild,\n    autoFill = false,\n    pauseOnHover = false,\n    pauseOnKeyboard = false,\n    reverse = false,\n    className,\n    style: styleProp,\n    ref,\n    ...marqueeProps\n  } = props;\n\n  const orientation: Orientation =\n    side === \"top\" || side === \"bottom\" ? \"vertical\" : \"horizontal\";\n\n  const dir = DirectionPrimitive.useDirection(dirProp);\n\n  const rootRef = React.useRef<RootElement>(null);\n  const contentRef = React.useRef<ContentElement>(null);\n  const composedRef = useMergedRefs(ref, rootRef);\n\n  const [paused, setPaused] = React.useState(false);\n\n  const onKeyDown = React.useCallback(\n    (event: React.KeyboardEvent) => {\n      if (pauseOnKeyboard && event.key === \" \") {\n        event.preventDefault();\n        setPaused((prev) => !prev);\n      }\n    },\n    [pauseOnKeyboard],\n  );\n\n  const [sizes, setSizes] = React.useState<MarqueeSizes | null>(null);\n  const dimensions = getElementDimensions(sizes, orientation);\n  const rootSize = dimensions?.rootSize;\n  const contentSize = dimensions?.contentSize;\n\n  const duration = React.useMemo(() => {\n    const safeSpeed = Math.max(0.001, speed);\n\n    if (rootSize === undefined || contentSize === undefined) {\n      const defaultDistance = autoFill ? 1000 : 2000;\n      return defaultDistance / safeSpeed;\n    }\n\n    if (autoFill) {\n      const multiplier =\n        contentSize < rootSize ? Math.ceil(rootSize / contentSize) : 1;\n      return (contentSize * multiplier) / safeSpeed;\n    } else {\n      return contentSize < rootSize\n        ? rootSize / safeSpeed\n        : contentSize / safeSpeed;\n    }\n  }, [rootSize, contentSize, speed, autoFill]);\n\n  const style = React.useMemo<React.CSSProperties>(\n    () => ({\n      \"--marquee-duration\": `${duration}s`,\n      \"--marquee-gap\": gap,\n      \"--marquee-delay\": `${delay}s`,\n      \"--marquee-loop-count\":\n        loopCount === 0 || loopCount === Infinity\n          ? \"infinite\"\n          : loopCount.toString(),\n      ...styleProp,\n    }),\n    [duration, gap, delay, loopCount, styleProp],\n  );\n\n  const contextValue = React.useMemo<MarqueeContextValue>(\n    () => ({\n      side,\n      orientation,\n      dir,\n      speed,\n      loopCount,\n      contentRef,\n      rootRef,\n      dimensions:\n        rootSize === undefined || contentSize === undefined\n          ? null\n          : { rootSize, contentSize },\n      onSizesChange: setSizes,\n      autoFill,\n      paused,\n      pauseOnHover,\n      pauseOnKeyboard,\n      reverse,\n    }),\n    [\n      side,\n      orientation,\n      dir,\n      speed,\n      loopCount,\n      rootSize,\n      contentSize,\n      autoFill,\n      paused,\n      pauseOnHover,\n      pauseOnKeyboard,\n      reverse,\n    ],\n  );\n\n  const MarqueePrimitive = asChild ? SlotPrimitive.Slot : \"div\";\n\n  return (\n    <MarqueeContext.Provider value={contextValue}>\n      <div data-slot=\"marquee-wrapper\" className=\"grid\">\n        <MarqueePrimitive\n          role=\"marquee\"\n          aria-live=\"off\"\n          data-orientation={orientation}\n          data-slot=\"marquee\"\n          dir={dir}\n          tabIndex={pauseOnKeyboard ? 0 : undefined}\n          {...marqueeProps}\n          ref={composedRef}\n          className={cn(\n            \"relative flex overflow-hidden motion-reduce:animate-none\",\n            orientation === \"vertical\" && \"h-full flex-col\",\n            orientation === \"horizontal\" && \"w-full\",\n            paused && \"[&_*]:[animation-play-state:paused]\",\n            pauseOnHover && \"group\",\n            pauseOnKeyboard &&\n              \"rounded-md focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none\",\n            className,\n          )}\n          style={style}\n          onKeyDown={pauseOnKeyboard ? onKeyDown : undefined}\n        />\n      </div>\n    </MarqueeContext.Provider>\n  );\n}\n\nconst marqueeContentVariants = cva(\"flex min-w-full shrink-0 gap-(--marquee-gap)\", {\n  variants: {\n    side: {\n      left: \"animate-marquee-left\",\n      right: \"animate-marquee-right\",\n      top: \"min-h-full min-w-auto animate-marquee-up flex-col\",\n      bottom: \"min-h-full min-w-auto animate-marquee-down flex-col\",\n    },\n    dir: {\n      ltr: \"\",\n      rtl: \"\",\n    },\n    pauseOnHover: {\n      true: \"group-hover:[animation-play-state:paused]\",\n      false: \"\",\n    },\n    reverse: {\n      true: \"[animation-direction:reverse]\",\n      false: \"\",\n    },\n  },\n  compoundVariants: [\n    {\n      side: \"left\",\n      dir: \"rtl\",\n      className: \"animate-marquee-left-rtl\",\n    },\n    {\n      side: \"right\",\n      dir: \"rtl\",\n      className: \"animate-marquee-right-rtl\",\n    },\n  ],\n  defaultVariants: {\n    side: \"left\",\n    dir: \"ltr\",\n    pauseOnHover: false,\n    reverse: false,\n  },\n});\n\ninterface MarqueeContentProps extends React.ComponentProps<\"div\"> {\n  asChild?: boolean;\n}\n\nfunction MarqueeContent(props: MarqueeContentProps) {\n  const {\n    className,\n    asChild,\n    ref,\n    children,\n    style: styleProp,\n    ...contentProps\n  } = props;\n\n  const context = useMarqueeContext(CONTENT_NAME);\n  const composedRef = useMergedRefs(ref, context.contentRef);\n\n  const isVertical = context.orientation === \"vertical\";\n  const isRtl = context.dir === \"rtl\";\n\n  const { rootRef, contentRef, dimensions, onSizesChange } = context;\n\n  React.useEffect(() => {\n    const rootElement = rootRef.current;\n    const contentElement = contentRef.current;\n    if (\n      typeof ResizeObserver === \"undefined\" ||\n      !rootElement ||\n      !contentElement\n    ) {\n      return;\n    }\n\n    let sizes: MarqueeSizes = {\n      root: getRectDimensions(rootElement),\n      content: getRectDimensions(contentElement),\n    };\n    if (\n      sizes.root.width > 0 &&\n      sizes.root.height > 0 &&\n      sizes.content.width > 0 &&\n      sizes.content.height > 0\n    ) {\n      onSizesChange(sizes);\n    }\n\n    const observer = new ResizeObserver((entries) => {\n      let nextSizes = sizes;\n      for (const entry of entries) {\n        const { width, height } = entry.contentRect;\n        const key = entry.target === rootElement ? \"root\" : \"content\";\n        if (!getIsSameDimensions(nextSizes[key], { width, height })) {\n          nextSizes = { ...nextSizes, [key]: { width, height } };\n        }\n      }\n      if (nextSizes === sizes) return;\n      sizes = nextSizes;\n      onSizesChange(sizes);\n    });\n\n    observer.observe(rootElement);\n    observer.observe(contentElement);\n    return () => observer.disconnect();\n  }, [rootRef, contentRef, onSizesChange]);\n\n  const multiplier = React.useMemo(() => {\n    if (!context.autoFill || !dimensions) return 1;\n\n    const { rootSize, contentSize } = dimensions;\n    if (contentSize === 0) return 1;\n\n    return contentSize < rootSize ? Math.ceil(rootSize / contentSize) : 1;\n  }, [context.autoFill, dimensions]);\n\n  const onMultipliedChildrenRender = React.useCallback(\n    (count: number) => {\n      return Array.from({ length: Math.max(0, count) }).map((_, i) => (\n        <React.Fragment key={i}>{children}</React.Fragment>\n      ));\n    },\n    [children],\n  );\n\n  const style = React.useMemo(\n    () => ({\n      ...styleProp,\n      animationDuration: \"var(--marquee-duration)\",\n      animationDelay: \"var(--marquee-delay)\",\n      animationIterationCount: \"var(--marquee-loop-count)\",\n      animationDirection: context.reverse ? \"reverse\" : \"normal\",\n    }),\n    [styleProp, context.reverse],\n  );\n\n  const ContentPrimitive = asChild ? SlotPrimitive.Slot : \"div\";\n\n  return (\n    <>\n      <ContentPrimitive\n        data-orientation={context.orientation}\n        data-slot=\"marquee-content\"\n        {...contentProps}\n        style={style}\n        className={cn(\n          marqueeContentVariants({\n            side: context.side,\n            dir: context.dir,\n            pauseOnHover: context.pauseOnHover,\n            reverse: context.reverse,\n            className,\n          }),\n          isVertical && \"flex-col\",\n          isVertical\n            ? \"mb-(--marquee-gap)\"\n            : isRtl\n              ? \"ml-(--marquee-gap)\"\n              : \"mr-(--marquee-gap)\",\n        )}\n      >\n        <div\n          ref={composedRef}\n          className={cn(\"flex shrink-0 gap-(--marquee-gap)\", isVertical && \"flex-col\")}\n        >\n          {children}\n        </div>\n        {onMultipliedChildrenRender(multiplier - 1)}\n      </ContentPrimitive>\n      <ContentPrimitive\n        role=\"presentation\"\n        aria-hidden=\"true\"\n        {...contentProps}\n        style={style}\n        className={cn(\n          marqueeContentVariants({\n            side: context.side,\n            dir: context.dir,\n            pauseOnHover: context.pauseOnHover,\n            reverse: context.reverse,\n            className,\n          }),\n          isVertical && \"flex-col\",\n        )}\n      >\n        {onMultipliedChildrenRender(multiplier)}\n      </ContentPrimitive>\n    </>\n  );\n}\n\ninterface MarqueeItemProps extends React.ComponentProps<\"div\"> {\n  asChild?: boolean;\n}\n\nfunction MarqueeItem(props: MarqueeItemProps) {\n  const { className, asChild, ...itemProps } = props;\n\n  const ItemPrimitive = asChild ? SlotPrimitive.Slot : \"div\";\n\n  return (\n    <ItemPrimitive\n      data-slot=\"marquee-item\"\n      {...itemProps}\n      className={cn(\"shrink-0\", className)}\n    />\n  );\n}\n\nconst marqueeEdgeVariants = cva(\"pointer-events-none absolute z-10\", {\n  variants: {\n    side: {\n      left: \"top-0 [left:0] h-full bg-linear-to-r from-background to-transparent\",\n      right: \"top-0 [right:0] h-full bg-linear-to-l from-background to-transparent\",\n      top: \"top-0 left-0 w-full bg-linear-to-b from-background to-transparent\",\n      bottom: \"bottom-0 left-0 w-full bg-linear-to-t from-background to-transparent\",\n    },\n    size: {\n      default: \"\",\n      sm: \"\",\n      lg: \"\",\n    },\n  },\n  compoundVariants: [\n    {\n      side: [\"left\", \"right\"],\n      size: \"default\",\n      className: \"w-1/4\",\n    },\n    {\n      side: [\"left\", \"right\"],\n      size: \"sm\",\n      className: \"w-1/6\",\n    },\n    {\n      side: [\"left\", \"right\"],\n      size: \"lg\",\n      className: \"w-1/3\",\n    },\n    {\n      side: [\"top\", \"bottom\"],\n      size: \"default\",\n      className: \"h-1/4\",\n    },\n    {\n      side: [\"top\", \"bottom\"],\n      size: \"sm\",\n      className: \"h-1/6\",\n    },\n    {\n      side: [\"top\", \"bottom\"],\n      size: \"lg\",\n      className: \"h-1/3\",\n    },\n  ],\n  defaultVariants: {\n    size: \"default\",\n  },\n});\n\ninterface MarqueeEdgeProps\n  extends\n    VariantProps<typeof marqueeEdgeVariants>,\n    React.ComponentProps<\"div\"> {\n  asChild?: boolean;\n}\n\nfunction MarqueeEdge(props: MarqueeEdgeProps) {\n  const { side, size, className, asChild, ...edgeProps } = props;\n\n  const EdgePrimitive = asChild ? SlotPrimitive.Slot : \"div\";\n\n  return (\n    <EdgePrimitive\n      data-size={size}\n      data-slot=\"marquee-edge\"\n      {...edgeProps}\n      className={cn(marqueeEdgeVariants({ side, size, className }))}\n    />\n  );\n}\n\nexport { Marquee, MarqueeContent, MarqueeEdge, MarqueeItem, type MarqueeProps };\n",
      "target": ""
    }
  ]
}