{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "page-wipe",
  "title": "Page Wipe",
  "description": "Full-page wipes on the View Transitions API: an accent curtain, a slanted sweep or an iris from the click. Reduced motion falls back to a fade.",
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/use-view-transition.json"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/page-wipe.tsx",
      "content": "import type * as React from \"react\"\nimport { useCallback, useEffect } from \"react\"\nimport { useViewTransition } from \"@/registry/miseui/hooks/use-view-transition\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype PageWipeVariant = \"curtain\" | \"sweep\" | \"iris\"\ntype PageWipeEffect = \"recede\"\n\nconst PAGE_WIPE_STYLE_ID = \"miseui-page-wipes\"\n\nconst EASE_THROUGH = \"cubic-bezier(0.76, 0, 0.24, 1)\"\nconst CURTAIN_LEG_MS = 320\nconst SWEEP_MS = 560\nconst IRIS_MS = 520\nconst RECEDE_SCALE = 0.96\nconst RECEDE_LIGHT = 0.8\n\n/**\n * Both pseudo-elements are visible at once in a wipe, so the default plus-lighter blend would wash them out.\n * The old page dims under a sweep or iris because two pages often share most of their pixels, and then the edge cannot be seen.\n */\nconst WIPE_CSS = `\n@keyframes miseui-wipe-cover { to { clip-path: inset(0 0 100% 0) } }\n@keyframes miseui-wipe-lift { from { clip-path: inset(100% 0 0 0) } to { clip-path: inset(0) } }\n@keyframes miseui-wipe-sweep {\n  from { clip-path: polygon(-20% 0, -20% 0, -40% 100%, -40% 100%) }\n  to { clip-path: polygon(-20% 0, 120% 0, 100% 100%, -40% 100%) }\n}\n@keyframes miseui-wipe-iris {\n  from { clip-path: circle(0 at var(--page-wipe-x, 50%) var(--page-wipe-y, 50%)) }\n  to { clip-path: circle(150vmax at var(--page-wipe-x, 50%) var(--page-wipe-y, 50%)) }\n}\n@keyframes miseui-wipe-dim { to { filter: brightness(${RECEDE_LIGHT}) } }\n@keyframes miseui-wipe-recede { to { transform: scale(${RECEDE_SCALE}); filter: brightness(${RECEDE_LIGHT}) } }\n@media (prefers-reduced-motion: no-preference) {\n  html[data-transition][data-page-wipe]::view-transition-old(root),\n  html[data-transition][data-page-wipe]::view-transition-new(root) { mix-blend-mode: normal; animation-delay: 0ms; animation-fill-mode: both }\n  html[data-transition][data-page-wipe]::view-transition { background: var(--background) }\n  html[data-transition][data-page-wipe=\"curtain\"]::view-transition { background: var(--mise) }\n  html[data-transition][data-page-wipe=\"curtain\"]::view-transition-old(root) { animation: miseui-wipe-cover ${CURTAIN_LEG_MS}ms ${EASE_THROUGH} both }\n  html[data-transition][data-page-wipe=\"curtain\"]::view-transition-new(root) { animation: miseui-wipe-lift ${CURTAIN_LEG_MS}ms ${EASE_THROUGH} ${CURTAIN_LEG_MS}ms both }\n  html[data-transition][data-page-wipe=\"sweep\"]::view-transition-old(root) { animation: miseui-wipe-dim ${SWEEP_MS}ms ${EASE_THROUGH} both }\n  html[data-transition][data-page-wipe=\"sweep\"]::view-transition-new(root) { animation: miseui-wipe-sweep ${SWEEP_MS}ms ${EASE_THROUGH} both }\n  html[data-transition][data-page-wipe=\"iris\"]::view-transition-old(root) { animation: miseui-wipe-dim ${IRIS_MS}ms ${EASE_THROUGH} both }\n  html[data-transition][data-page-wipe=\"iris\"]::view-transition-new(root) { animation: miseui-wipe-iris ${IRIS_MS}ms ${EASE_THROUGH} both }\n  html[data-transition][data-page-wipe=\"curtain\"][data-page-wipe-effect=\"recede\"]::view-transition-old(root) {\n    animation: miseui-wipe-cover ${CURTAIN_LEG_MS}ms ${EASE_THROUGH} both, miseui-wipe-recede ${CURTAIN_LEG_MS}ms ${EASE_THROUGH} both\n  }\n  html[data-transition][data-page-wipe=\"sweep\"][data-page-wipe-effect=\"recede\"]::view-transition-old(root) { animation: miseui-wipe-recede ${SWEEP_MS}ms ${EASE_THROUGH} both }\n  html[data-transition][data-page-wipe=\"iris\"][data-page-wipe-effect=\"recede\"]::view-transition-old(root) { animation: miseui-wipe-recede ${IRIS_MS}ms ${EASE_THROUGH} both }\n}\n`\n\nfunction ensureWipeStyles() {\n  if (document.getElementById(PAGE_WIPE_STYLE_ID)) return\n  const style = document.createElement(\"style\")\n  style.id = PAGE_WIPE_STYLE_ID\n  style.textContent = WIPE_CSS\n  document.head.append(style)\n}\n\nfunction clearWipeMarks() {\n  const root = document.documentElement\n  delete root.dataset.pageWipe\n  delete root.dataset.pageWipeEffect\n}\n\n/** A keyboard click reports (0, 0), which would open the iris from a corner, so it starts from the control instead. */\nfunction wipeOrigin(event: Pick<React.MouseEvent<HTMLElement>, \"detail\" | \"clientX\" | \"clientY\" | \"currentTarget\">) {\n  if (event.detail > 0) return { x: event.clientX, y: event.clientY }\n  const rect = event.currentTarget.getBoundingClientRect()\n  return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }\n}\n\n/** A click with a modifier means a new tab or window, and the browser should be left to do that. */\nfunction isPlainClick(event: React.MouseEvent<HTMLElement>) {\n  return event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey\n}\n\ninterface PageWipeOptions {\n  /** `curtain` the accent colour rises then lifts away, `sweep` the new page slides over on a slanted edge, `iris` it opens from where you pressed. */\n  variant?: PageWipeVariant\n  /** `recede` pushes the old page back and down in light while the new one arrives. */\n  effect?: PageWipeEffect\n}\n\n/**\n * Returns `wipe(update, event?)`. The update runs inside a View Transition: browsers without one just run it, and\n * reduced motion gets the hook's cross-fade, because every wipe rule here sits inside a no-preference query.\n */\nfunction usePageWipe({ variant = \"curtain\", effect }: PageWipeOptions = {}) {\n  const transition = useViewTransition(\"fade-through\")\n\n  useEffect(() => {\n    ensureWipeStyles()\n    return clearWipeMarks\n  }, [])\n\n  return useCallback(\n    (update: () => void, event?: React.MouseEvent<HTMLElement>) => {\n      // These marks can stay on <html> afterwards: the rules also need the hook's data-transition, which only exists during a transition.\n      const root = document.documentElement\n      root.dataset.pageWipe = variant\n      if (effect) root.dataset.pageWipeEffect = effect\n      else delete root.dataset.pageWipeEffect\n      if (event) {\n        const origin = wipeOrigin(event)\n        root.style.setProperty(\"--page-wipe-x\", `${origin.x}px`)\n        root.style.setProperty(\"--page-wipe-y\", `${origin.y}px`)\n      }\n      transition(update)\n    },\n    [effect, transition, variant],\n  )\n}\n\ntype PageWipeLinkProps = React.ComponentProps<\"a\"> & PageWipeOptions & {\n  /** Do the navigation here, for example `router.push(href)`. The wipe wraps it. */\n  onNavigate: (href: string) => void\n}\n\nfunction PageWipeLink({ variant = \"curtain\", effect, onNavigate, href, target, onClick, className, ...props }: PageWipeLinkProps) {\n  const wipe = usePageWipe({ variant, effect })\n  return (\n    <a\n      data-slot=\"page-wipe\"\n      data-variant={variant}\n      data-effect={effect}\n      href={href}\n      target={target}\n      className={cn(\"rounded-sm outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50\", className)}\n      onClick={(event) => {\n        onClick?.(event)\n        if (event.defaultPrevented || !href || !isPlainClick(event) || (target && target !== \"_self\")) return\n        event.preventDefault()\n        wipe(() => onNavigate(href), event)\n      }}\n      {...props}\n    />\n  )\n}\n\nexport { PageWipeLink, usePageWipe, type PageWipeLinkProps, type PageWipeOptions, type PageWipeVariant, type PageWipeEffect }\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "transitions"
  ],
  "type": "registry:ui"
}