{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-fade",
  "type": "registry:ui",
  "title": "Scroll Fade",
  "description": "Container edges that fade only where there is more content.",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "components/prequelui/motion.tsx",
      "type": "registry:lib",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport {\n  MotionConfig,\n  useInView as useMotionInView,\n  type Transition,\n} from \"motion/react\";\nimport { useHydratedReducedMotion } from \"@/lib/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\nconst TempoContext = React.createContext(1);\n\nexport function PrequelMotionProvider({\n  tempo = 1,\n  children,\n}: {\n  tempo?: number;\n  children: React.ReactNode;\n}) {\n  const value = React.useMemo(() => Math.max(0.4, tempo), [tempo]);\n  return (\n    <TempoContext.Provider value={value}>\n      <MotionConfig reducedMotion=\"user\">{children}</MotionConfig>\n    </TempoContext.Provider>\n  );\n}\n\nexport function useTempo() {\n  return React.useContext(TempoContext);\n}\n\nconst TIME_KEYS = [\n  \"duration\",\n  \"visualDuration\",\n  \"delay\",\n  \"repeatDelay\",\n  \"delayChildren\",\n] as const;\n\nfunction scaleValue(transition: Transition, tempo: number): Transition {\n  if (tempo === 1 || !transition || typeof transition !== \"object\") {\n    return transition;\n  }\n  const next: Record<string, unknown> = {};\n  for (const [key, value] of Object.entries(transition)) {\n    if (typeof value === \"number\" && (TIME_KEYS as readonly string[]).includes(key)) {\n      next[key] = value * tempo;\n    } else if (typeof value === \"number\" && key === \"stiffness\") {\n      next[key] = value / (tempo * tempo);\n    } else if (typeof value === \"number\" && key === \"damping\") {\n      next[key] = value / tempo;\n    } else if (value && typeof value === \"object\" && !Array.isArray(value)) {\n      next[key] = scaleValue(value as Transition, tempo);\n    } else {\n      next[key] = value;\n    }\n  }\n  return next as Transition;\n}\n\nexport function useTempoTransition(transition: Transition) {\n  const tempo = useTempo();\n  return React.useMemo(\n    () => scaleValue(transition, tempo),\n    [tempo, JSON.stringify(transition)],\n  );\n}\n\nexport function useReduceMotion() {\n  return useHydratedReducedMotion();\n}\n\nexport function usePageVisible() {\n  const [visible, setVisible] = React.useState(true);\n  React.useEffect(() => {\n    const update = () => setVisible(!document.hidden);\n    update();\n    document.addEventListener(\"visibilitychange\", update);\n    return () => document.removeEventListener(\"visibilitychange\", update);\n  }, []);\n  return visible;\n}\n\nexport function useMounted() {\n  return React.useSyncExternalStore(\n    () => () => {},\n    () => true,\n    () => false,\n  );\n}\n\nexport function useSeen(\n  ref: React.RefObject<Element | null>,\n  enabled = true,\n  once = true,\n) {\n  const inView = useMotionInView(ref, { once, amount: 0.35 });\n  return enabled ? inView : true;\n}\n\ntype SlotProps = React.HTMLAttributes<HTMLElement> & {\n  children?: React.ReactNode;\n  ref?: React.Ref<HTMLElement>;\n};\n\nexport function Slot({ children, ...props }: SlotProps) {\n  if (!React.isValidElement<Record<string, unknown>>(children)) {\n    return null;\n  }\n  const child = children as React.ReactElement<Record<string, unknown>>;\n  const childProps = child.props;\n  return React.cloneElement(child, {\n    ...props,\n    ...childProps,\n    className: cn(\n      String(props.className ?? \"\"),\n      String(childProps.className ?? \"\"),\n    ),\n    style: {\n      ...((props.style as React.CSSProperties) ?? {}),\n      ...((childProps.style as React.CSSProperties) ?? {}),\n    },\n  } as Record<string, unknown>);\n}\n\nexport function srOnlyStyle(): React.CSSProperties {\n  return {\n    position: \"absolute\",\n    width: 1,\n    height: 1,\n    padding: 0,\n    margin: -1,\n    overflow: \"hidden\",\n    clip: \"rect(0, 0, 0, 0)\",\n    whiteSpace: \"nowrap\",\n    borderWidth: 0,\n  };\n}\n\nlet segmenter: Intl.Segmenter | null | undefined;\n\nexport function splitGraphemes(text: string): string[] {\n  if (segmenter === undefined) {\n    segmenter =\n      typeof Intl !== \"undefined\" && typeof Intl.Segmenter === \"function\"\n        ? new Intl.Segmenter(undefined, { granularity: \"grapheme\" })\n        : null;\n  }\n  if (!segmenter) return Array.from(text);\n  return Array.from(segmenter.segment(text), (entry) => entry.segment);\n}\n\nexport const easeOut = [0.23, 1, 0.32, 1] as const;\nexport const easeSoft = [0.215, 0.61, 0.355, 1] as const;\nexport const easeInOut = [0.77, 0, 0.175, 1] as const;\nexport const easeEnter = [0.25, 0.1, 0.35, 1] as const;\nexport const easeLeave = [0, 0, 0.58, 1] as const;\nexport const easeResize = [0.4, 0, 0.1, 1] as const;\nexport const easeAway = [0.33, 0.17, 0.67, 0.5] as const;\n\nexport const pressSpring: Transition = {\n  type: \"spring\",\n  stiffness: 550,\n  damping: 30,\n  restSpeed: 10,\n};\n\nexport const selectionSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 30,\n};\n\nexport const highlightSpring: Transition = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 40,\n};\n\nexport const popSpring: Transition = {\n  type: \"spring\",\n  stiffness: 400,\n  damping: 29,\n};\n\nexport const tooltipSpring: Transition = {\n  type: \"spring\",\n  stiffness: 400,\n  damping: 31,\n};\n\nexport const dialogSpring: Transition = {\n  type: \"spring\",\n  stiffness: 150,\n  damping: 25,\n};\n\nexport const toastSpring: Transition = {\n  type: \"spring\",\n  stiffness: 280,\n  damping: 24,\n};\n\nexport const heightSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 30,\n  bounce: 0,\n  restDelta: 0.01,\n};\n\nexport const progressSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 35,\n  restDelta: 0.01,\n  restSpeed: 0.1,\n};\n\nexport const scrollSpring: Transition = {\n  type: \"spring\",\n  stiffness: 250,\n  damping: 40,\n  bounce: 0,\n};\n\nexport const avatarSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 17,\n};\n\nexport const pinnedSpring: Transition = {\n  type: \"spring\",\n  stiffness: 320,\n  damping: 25,\n  mass: 0.8,\n};\n\nexport const thumbSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 25,\n};\n\nexport const checkSpring: Transition = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 24,\n};\n\nexport const cursorEntry: Transition = {\n  type: \"spring\",\n  stiffness: 550,\n  damping: 30,\n  restSpeed: 10,\n};\n\nexport const cursorExit: Transition = {\n  type: \"spring\",\n  stiffness: 550,\n  damping: 46.9,\n  restSpeed: 10,\n};\n\nexport const cursorLabel: Transition = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 50,\n  bounce: 0,\n};\n\nexport const swapTween: Transition = {\n  duration: 0.15,\n  ease: easeOut,\n};\n\nexport const overlayTween: Transition = {\n  duration: 0.4,\n  ease: easeSoft,\n};\n\nexport const disclosureTween: Transition = {\n  duration: 0.35,\n  ease: easeSoft,\n};\n\nexport const menuTween: Transition = {\n  duration: 0.22,\n  ease: easeSoft,\n};\n\nexport const panelOutTween: Transition = {\n  duration: 0.15,\n  ease: easeLeave,\n};\n\nexport const panelInTween: Transition = {\n  duration: 0.3,\n  ease: easeEnter,\n};\n\nexport const panelHeightTween: Transition = {\n  duration: 0.45,\n  ease: easeResize,\n};\n\nexport const exitTween: Transition = {\n  duration: 0.2,\n  ease: easeAway,\n};\n\nexport const faceSpring: Transition = {\n  type: \"spring\",\n  stiffness: 280,\n  damping: 20,\n};\n\nexport const blurIcon = \"blur(2px)\";\n\nexport function flipTransform(side: \"top\" | \"bottom\" | \"left\" | \"right\") {\n  const rotate =\n    side === \"top\"\n      ? \"rotateX(-20deg)\"\n      : side === \"bottom\"\n        ? \"rotateX(20deg)\"\n        : side === \"left\"\n          ? \"rotateY(20deg)\"\n          : \"rotateY(-20deg)\";\n  return `perspective(500px) ${rotate} scale(0.8)`;\n}\n\nexport function uprightTransform(side: \"top\" | \"bottom\" | \"left\" | \"right\") {\n  const rotate = side === \"left\" || side === \"right\" ? \"rotateY(0deg)\" : \"rotateX(0deg)\";\n  return `perspective(500px) ${rotate} scale(1)`;\n}\n",
      "target": "components/prequelui/motion.tsx"
    },
    {
      "path": "components/prequelui/effects/shared.ts",
      "type": "registry:lib",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { useInView, type Transition } from \"motion/react\";\n\nexport const entranceSpring: Transition = {\n  type: \"spring\",\n  stiffness: 200,\n  damping: 20,\n};\n\nexport const heightSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 30,\n  bounce: 0,\n  restDelta: 0.01,\n};\n\nexport const highlightSpring: Transition = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 40,\n};\n\nexport const fadeTween: Transition = {\n  duration: 0.2,\n  ease: [0.23, 1, 0.32, 1],\n};\n\nexport const softEase = [0.23, 1, 0.32, 1] as const;\n\nexport type SlideDirection = \"up\" | \"down\" | \"left\" | \"right\";\n\nconst HOVER_QUERY = \"(hover: hover) and (pointer: fine)\";\nconst COARSE_QUERY = \"(pointer: coarse)\";\n\nfunction useMediaQuery(query: string) {\n  const [matches, setMatches] = React.useState(false);\n\n  React.useEffect(() => {\n    const mql = window.matchMedia(query);\n    const update = () => setMatches(mql.matches);\n    update();\n    mql.addEventListener(\"change\", update);\n    return () => mql.removeEventListener(\"change\", update);\n  }, [query]);\n\n  return matches;\n}\n\nexport function useCanHover() {\n  return useMediaQuery(HOVER_QUERY);\n}\n\nexport function useCoarsePointer() {\n  return useMediaQuery(COARSE_QUERY);\n}\n\nexport function useMounted() {\n  const [mounted, setMounted] = React.useState(false);\n  React.useEffect(() => setMounted(true), []);\n  return mounted;\n}\n\nexport function useInViewEffect(\n  ref: React.RefObject<Element | null>,\n  enabled: boolean,\n  once: boolean,\n  margin: string,\n) {\n  const inView = useInView(ref, {\n    once,\n    amount: 0.35,\n    margin: margin as `${number}px`,\n  });\n  return enabled ? inView : true;\n}\n\nexport function clamp(value: number, min: number, max: number) {\n  return Math.min(max, Math.max(min, value));\n}\n\nexport function mergeRefs<T>(\n  ...refs: Array<React.Ref<T> | undefined>\n): React.RefCallback<T> {\n  return (node) => {\n    for (const ref of refs) {\n      if (!ref) continue;\n      if (typeof ref === \"function\") ref(node);\n      else (ref as React.MutableRefObject<T | null>).current = node;\n    }\n  };\n}\n",
      "target": "components/prequelui/effects/shared.ts"
    },
    {
      "path": "components/prequelui/effects/scroll-fade.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { animate, useMotionValue, type MotionValue, type Transition } from \"motion/react\";\nimport { useReduceMotion, useTempoTransition } from \"../motion\";\nimport { clamp, fadeTween, mergeRefs } from \"./shared\";\n\nexport type ScrollFadeOrientation = \"vertical\" | \"horizontal\" | \"both\";\nexport type ScrollFadeEdge = \"top\" | \"bottom\" | \"left\" | \"right\";\nexport type ScrollFadeValues = Record<ScrollFadeEdge, MotionValue<number>>;\n\nexport type UseScrollFadeOptions = {\n  orientation?: ScrollFadeOrientation;\n  size?: number;\n  transition?: Transition;\n  enabled?: boolean;\n};\n\nconst EDGES: ScrollFadeEdge[] = [\"top\", \"bottom\", \"left\", \"right\"];\nconst VARS: Record<ScrollFadeEdge | \"size\", string> = {\n  top: \"--scroll-fade-top\",\n  bottom: \"--scroll-fade-bottom\",\n  left: \"--scroll-fade-left\",\n  right: \"--scroll-fade-right\",\n  size: \"--scroll-fade-size\",\n};\n\nfunction maskFor(orientation: ScrollFadeOrientation) {\n  const stop = (edge: ScrollFadeEdge) =>\n    `rgb(0 0 0 / calc(1 - var(${VARS[edge]}, 0)))`;\n  const depth = (edge: ScrollFadeEdge) =>\n    `calc(var(${VARS.size}) * min(1, var(${VARS[edge]}, 0) * 1000))`;\n  const vertical = `linear-gradient(to bottom, ${stop(\"top\")} 0, #000 ${depth(\n    \"top\",\n  )}, #000 calc(100% - ${depth(\"bottom\")}), ${stop(\"bottom\")} 100%)`;\n  const horizontal = `linear-gradient(to right, ${stop(\"left\")} 0, #000 ${depth(\n    \"left\",\n  )}, #000 calc(100% - ${depth(\"right\")}), ${stop(\"right\")} 100%)`;\n\n  if (orientation === \"vertical\") return vertical;\n  if (orientation === \"horizontal\") return horizontal;\n  return `${vertical}, ${horizontal}`;\n}\n\nfunction applyMask(element: HTMLElement, mask: string | null) {\n  if (mask) {\n    element.style.setProperty(\"mask-image\", mask);\n    element.style.setProperty(\"-webkit-mask-image\", mask);\n    element.style.setProperty(\"mask-composite\", \"intersect\");\n    element.style.setProperty(\"-webkit-mask-composite\", \"source-in\");\n  } else {\n    for (const property of [\n      \"mask-image\",\n      \"-webkit-mask-image\",\n      \"mask-composite\",\n      \"-webkit-mask-composite\",\n    ]) {\n      element.style.removeProperty(property);\n    }\n  }\n}\n\nexport function useScrollFade(\n  ref: React.RefObject<HTMLElement | null>,\n  {\n    orientation = \"vertical\",\n    size = 40,\n    transition,\n    enabled = true,\n  }: UseScrollFadeOptions = {},\n): ScrollFadeValues {\n  const reduce = useReduceMotion();\n  const settle = useTempoTransition(transition ?? fadeTween);\n  const top = useMotionValue(0);\n  const bottom = useMotionValue(0);\n  const left = useMotionValue(0);\n  const right = useMotionValue(0);\n  const values = React.useMemo(\n    () => ({ top, bottom, left, right }),\n    [top, bottom, left, right],\n  );\n\n  React.useEffect(() => {\n    const element = ref.current;\n    if (!element || !enabled) return;\n\n    const vertical = orientation !== \"horizontal\";\n    const horizontal = orientation !== \"vertical\";\n    const mask = maskFor(orientation);\n    let masked = false;\n\n    element.style.setProperty(VARS.size, `${size}px`);\n\n    const write = () => {\n      let any = false;\n      for (const edge of EDGES) {\n        const amount = clamp(values[edge].get(), 0, 1);\n        if (amount > 0.001) any = true;\n        element.style.setProperty(VARS[edge], amount.toFixed(4));\n      }\n      if (any !== masked) {\n        masked = any;\n        applyMask(element, any ? mask : null);\n      }\n    };\n\n    const unsubscribers = EDGES.map((edge) => values[edge].on(\"change\", write));\n    const ramp = size / 2;\n    const amount = (distance: number) =>\n      ramp > 0 ? clamp(distance / ramp, 0, 1) : distance > 0.5 ? 1 : 0;\n\n    const measure = (follow: boolean) => {\n      const targets = { top: 0, bottom: 0, left: 0, right: 0 } as Record<\n        ScrollFadeEdge,\n        number\n      >;\n\n      if (vertical) {\n        const max = element.scrollHeight - element.clientHeight;\n        if (max > 1) {\n          targets.top = amount(element.scrollTop);\n          targets.bottom = amount(max - element.scrollTop);\n        }\n      }\n\n      if (horizontal) {\n        const max = element.scrollWidth - element.clientWidth;\n        if (max > 1) {\n          const fromStart = Math.abs(element.scrollLeft);\n          const fromEnd = max - fromStart;\n          const rtl = getComputedStyle(element).direction === \"rtl\";\n          targets.left = amount(rtl ? fromEnd : fromStart);\n          targets.right = amount(rtl ? fromStart : fromEnd);\n        }\n      }\n\n      for (const edge of EDGES) {\n        if (follow || reduce) values[edge].jump(targets[edge]);\n        else if (Math.abs(values[edge].get() - targets[edge]) > 0.001) {\n          animate(values[edge], targets[edge], settle);\n        }\n      }\n      write();\n    };\n\n    measure(true);\n\n    const onScroll = () => measure(true);\n    element.addEventListener(\"scroll\", onScroll, { passive: true });\n\n    const observer = new ResizeObserver(() => measure(false));\n    observer.observe(element);\n    for (const child of element.children) observer.observe(child);\n\n    const mutation = new MutationObserver(() => {\n      measure(false);\n      observer.disconnect();\n      observer.observe(element);\n      for (const child of element.children) observer.observe(child);\n    });\n    mutation.observe(element, { childList: true, subtree: true });\n\n    return () => {\n      element.removeEventListener(\"scroll\", onScroll);\n      observer.disconnect();\n      mutation.disconnect();\n      unsubscribers.forEach((unsubscribe) => unsubscribe());\n      applyMask(element, null);\n      for (const name of Object.values(VARS)) element.style.removeProperty(name);\n      for (const edge of EDGES) values[edge].jump(0);\n    };\n  }, [enabled, orientation, ref, reduce, settle, size, values]);\n\n  return values;\n}\n\nconst OVERFLOW: Record<ScrollFadeOrientation, React.CSSProperties> = {\n  vertical: { overflowY: \"auto\" },\n  horizontal: { overflowX: \"auto\" },\n  both: { overflow: \"auto\" },\n};\n\nexport type ScrollFadeProps = React.ComponentProps<\"div\"> &\n  UseScrollFadeOptions & {\n    asChild?: boolean;\n  };\n\nexport function ScrollFade({\n  orientation = \"vertical\",\n  size,\n  transition,\n  enabled,\n  asChild = false,\n  className,\n  style,\n  children,\n  ...props\n}: ScrollFadeProps) {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const childRef = React.isValidElement<{ ref?: React.Ref<HTMLElement> }>(children)\n    ? children.props.ref\n    : undefined;\n  const merged = React.useMemo(\n    () => mergeRefs<HTMLDivElement>(ref, childRef as React.Ref<HTMLDivElement>),\n    [childRef],\n  );\n\n  useScrollFade(ref, { orientation, size, transition, enabled });\n\n  const shared = {\n    \"data-slot\": \"scroll-fade\",\n    \"data-orientation\": orientation,\n    className,\n    style: { ...OVERFLOW[orientation], ...style },\n  };\n\n  if (asChild && React.isValidElement(children)) {\n    return React.cloneElement(\n      children as React.ReactElement<Record<string, unknown>>,\n      {\n        ...props,\n        ...shared,\n        ref: merged,\n      },\n    );\n  }\n\n  return (\n    <div ref={ref} {...shared} {...props}>\n      {children}\n    </div>\n  );\n}\n",
      "target": "components/prequelui/effects/scroll-fade.tsx"
    }
  ]
}
