{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "components-page-transition",
  "type": "registry:component",
  "title": "Page transition",
  "description": "A region that swaps views with the house motion",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-motion.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/components/src/internal/presence.tsx",
      "target": "@ui/gpuixui/components/internal/presence.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { MotionProps } from \"@gpuix/react\";\nimport {\n  delayedTiming,\n  exitWindowMs,\n  fadeFrom,\n  fadeFromAnchor,\n  fadeFromSide,\n  fadeOnly,\n  presenceMotion as motionOfPresence,\n  presenceStyle,\n  transitionWindowMs,\n  type PresenceFrames,\n  type PresenceHitRule,\n  type PresenceSide,\n  type PresenceTiming,\n  type PresenceTransition,\n} from \"../../motion/presence.js\";\nimport {\n  MotionProvider,\n  useMotionPreference,\n  useSurfacePresence,\n  useSurfaceTiming,\n  type MotionProviderProps,\n  type SurfacePresence,\n} from \"../../motion/react/presence.js\";\nimport {\n  motionTiming,\n  type MotionLevel,\n  type MotionPreference,\n} from \"../../motion/timing.js\";\n\nexport { MotionProvider, useMotionPreference, type MotionProviderProps };\n\nexport type SurfaceFrames = PresenceFrames;\n\nexport type SurfaceTiming = PresenceTiming;\n\nexport type PanelSide = PresenceSide;\n\nexport {\n  delayedTiming,\n  exitWindowMs,\n  fadeFrom,\n  fadeFromAnchor,\n  fadeFromSide,\n  fadeOnly,\n  presenceStyle,\n  transitionWindowMs,\n};\nexport type { PresenceHitRule };\n\nexport { useSurfacePresence, useSurfaceTiming, type SurfacePresence };\n\nexport const moveTiming = (\n  level: MotionLevel,\n  preference: MotionPreference,\n): PresenceTransition => motionTiming(level, { phase: \"standard\", preference });\n\nexport const useMoveTiming = (level: MotionLevel): PresenceTransition =>\n  moveTiming(level, useMotionPreference());\n\nexport const presenceMotion = (\n  frames: SurfaceFrames,\n  presence: SurfacePresence,\n  timing: SurfaceTiming = presence.timing,\n): MotionProps => motionOfPresence(frames, presence.present, timing);\n\nexport const PresenceShield = ({ present }: { readonly present: boolean }) =>\n  present ? null : (\n    <div\n      testId=\"presence-shield\"\n      style={{ position: \"absolute\", top: 0, right: 0, bottom: 0, left: 0 }}\n    />\n  );\n\nexport const presenceTabStop = (\n  present: boolean,\n): { readonly tabIndex?: number } => (present ? {} : { tabIndex: -1 });\n"
    },
    {
      "path": "packages/components/src/internal/recipe.ts",
      "target": "@ui/gpuixui/components/internal/recipe.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { createRecipeCache } from \"../../tw/index.js\";\nimport type { Theme } from \"./theme.js\";\n\nexport const recipeStyle: (recipe: string, theme: Theme) => StyleDesc =\n  createRecipeCache(512);\n"
    },
    {
      "path": "packages/components/src/internal/theme.ts",
      "target": "@ui/gpuixui/components/internal/theme.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport * as Schema from \"effect/Schema\";\nimport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  brandTextOn,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  pointerWash,\n  selectionOn,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n  type BoxShadow,\n  type ElevationLevel,\n  type FindHighlightSource,\n  type NativeTextFill,\n  type PlatformName,\n  type PointerWashSurface,\n  type StatusTone,\n  type SyntaxColors,\n  type SyntaxRole,\n  type TextRole,\n  type Theme,\n  type ThemeColors,\n} from \"../../tokens/index.js\";\n\nexport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n};\nexport type {\n  BoxShadow,\n  ElevationLevel,\n  FindHighlightSource,\n  NativeTextFill,\n  PlatformName,\n  StatusTone,\n  SyntaxColors,\n  SyntaxRole,\n  TextRole,\n  Theme,\n};\nexport { ThemeProvider, useTheme } from \"../../tokens/react.js\";\n\nexport const keyboardRing = (theme: Theme, invalid = false): StyleDesc =>\n  controlFocusRing(theme, { invalid }) ?? {};\n\nexport interface ControlRingState {\n  readonly disabled?: boolean;\n\n  readonly invalid?: boolean;\n}\n\nexport const controlRing = (\n  theme: Theme,\n  state: ControlRingState = {},\n): StyleDesc => controlFocusRing(theme, state) ?? {};\n\nexport const pressWash = (theme: Theme, replaced: PointerWashSurface): string =>\n  pointerWash(theme, \"active\", replaced) ?? theme.colors.active;\n\nexport const selectionWash = (theme: Theme): StyleDesc => ({\n  selectionColor: theme.colors.selection,\n});\n\nexport const keepContent: StyleDesc = { keyboardFocusDim: false };\n\nexport const disabledFade = (\n  disabled: boolean,\n): { readonly opacity: number } | undefined =>\n  disabled ? { opacity: disabledOpacity } : undefined;\n\nconst Tones = Schema.Literals([\"info\", \"success\", \"warning\", \"danger\"]);\n\nexport type Tone = typeof Tones.Type;\n\nexport const toneOf = (value: unknown): Tone =>\n  Schema.is(Tones)(value) ? value : \"info\";\n\nexport interface ToneStyle {\n  readonly fg: string;\n  readonly bg: string;\n  readonly border: string;\n}\n\nconst TOKEN_TONE: Readonly<Record<Tone, StatusTone>> = {\n  info: \"info\",\n  success: \"success\",\n  warning: \"warning\",\n  danger: \"destructive\",\n};\n\nexport const tone = (theme: Theme, value: Tone): ToneStyle => {\n  const { background, border, foreground } = statusTone(\n    theme,\n    TOKEN_TONE[value],\n  );\n  return { bg: background, border, fg: foreground };\n};\n\nconst softRoles: Readonly<Record<Tone, keyof ThemeColors>> = {\n  info: \"infoSoft\",\n  success: \"successSoft\",\n  warning: \"warningSoft\",\n  danger: \"destructiveSoft\",\n};\n\nexport const messageLink = (theme: Theme, value: Tone): string =>\n  brandTextOn(theme, softRoles[value]);\n\nexport const messageSelection = (theme: Theme, value: Tone): string =>\n  selectionOn(theme, softRoles[value]);\n\nexport const toneSurface = (theme: Theme, value: Tone): StyleDesc => {\n  const { bg, border, fg } = tone(theme, value);\n  return {\n    backgroundColor: bg,\n    color: fg,\n    borderWidth: theme.borderWidth.thin,\n    borderColor: border,\n  };\n};\n"
    },
    {
      "path": "packages/components/src/motion.tsx",
      "target": "@ui/gpuixui/components/motion.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport { motionLevelOf, type MotionLevel } from \"../motion/timing.js\";\n\nexport {\n  MotionProvider,\n  useMotionPreference,\n  type MotionProviderProps,\n} from \"./internal/presence.js\";\nexport type { MotionPreference } from \"../motion/timing.js\";\n\nexport type SurfaceLevel = MotionLevel | \"none\";\n\nexport const surfaceLevelOf = (value: unknown): SurfaceLevel =>\n  value === \"none\" ? \"none\" : motionLevelOf(value);\n"
    },
    {
      "path": "packages/components/src/page-transition.tsx",
      "target": "@ui/gpuixui/components/page-transition.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { MotionProps, Props } from \"@gpuix/react\";\nimport {\n  mergeStyles,\n  resolveStyle,\n  type StateStyle,\n} from \"@gpuix/react/floating\";\nimport { cn } from \"../tw/index.js\";\nimport { Match } from \"effect\";\nimport * as Option from \"effect/Option\";\nimport { useLayoutEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n  PresenceShield,\n  presenceStyle,\n  useMotionPreference,\n  useSurfaceTiming,\n  transitionWindowMs,\n} from \"./internal/presence.js\";\nimport { recipeStyle } from \"./internal/recipe.js\";\nimport { useTheme } from \"./internal/theme.js\";\nimport { surfaceLevelOf, type SurfaceLevel } from \"./motion.js\";\nimport {\n  PAGE_TRAVEL,\n  finishPage,\n  initialPageTransition,\n  pageFrames,\n  requestPage,\n  settlePage,\n  type PageDirection,\n  type PagePhase,\n} from \"./page-transition/logic.js\";\n\nexport interface PageTransitionPaint {\n  readonly view: string;\n\n  readonly phase: PagePhase;\n  readonly direction: PageDirection;\n  readonly reducedMotion: boolean;\n}\n\nexport interface PageTransitionProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly viewKey: string;\n\n  readonly children?: ReactNode;\n\n  readonly direction?: PageDirection;\n\n  readonly distance?: number;\n\n  readonly level?: SurfaceLevel;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<PageTransitionPaint>;\n}\n\nexport const PageTransition = ({\n  viewKey,\n  children,\n  direction = \"forward\",\n  distance,\n  level: storedLevel = \"normal\",\n  className,\n  style,\n  testId,\n  ...rest\n}: PageTransitionProps) => {\n  const theme = useTheme();\n  const preference = useMotionPreference();\n  const level = surfaceLevelOf(storedLevel);\n  const timing = useSurfaceTiming(level === \"none\" ? \"normal\" : level);\n  const instant = preference === \"reduced\" || level === \"none\";\n  const [transition, setTransition] = useState(() =>\n    initialPageTransition(viewKey),\n  );\n\n  const latest = useRef(children);\n\n  const outgoing = useRef(children);\n\n  useLayoutEffect(() => {\n    latest.current = children;\n  });\n\n  const waitingForView = Option.exists(\n    transition.pendingKey,\n    (key) => key === viewKey,\n  );\n  const needsRequest = instant\n    ? transition.shownKey !== viewKey\n    : transition.phase === \"leaving\"\n      ? !waitingForView\n      : transition.shownKey !== viewKey;\n\n  if (needsRequest) {\n    if (transition.phase !== \"leaving\") outgoing.current = latest.current;\n    setTransition(requestPage(transition, viewKey, instant));\n  }\n\n  const exitWindow = transitionWindowMs(timing.exit);\n  const enterWindow = transitionWindowMs(timing.enter);\n\n  useLayoutEffect(() => {\n    const ms = transition.phase === \"leaving\" ? exitWindow : enterWindow;\n\n    if (transition.phase === \"leaving\") {\n      if (ms <= 0) {\n        setTransition(settlePage);\n        return;\n      }\n      const handle = setTimeout(() => setTransition(settlePage), ms);\n      return () => clearTimeout(handle);\n    }\n\n    if (transition.phase === \"entering\") {\n      if (ms <= 0) {\n        setTransition(finishPage);\n        return;\n      }\n      const handle = setTimeout(() => setTransition(finishPage), ms);\n      return () => clearTimeout(handle);\n    }\n  }, [transition.phase, transition.run, exitWindow, enterWindow]);\n\n  const frames = pageFrames(\n    direction,\n    Option.getOrElse(Option.fromNullishOr(distance), () => PAGE_TRAVEL),\n  );\n  const motion: MotionProps = Match.value(transition.phase).pipe(\n    Match.when(\n      \"leaving\",\n      (): MotionProps => ({\n        initial: false,\n        animate: frames.exitTo,\n        transition: timing.exit,\n      }),\n    ),\n    Match.when(\n      \"entering\",\n      (): MotionProps => ({\n        initial: frames.enterFrom,\n        animate: frames.rest,\n        transition: timing.enter,\n      }),\n    ),\n    Match.when(\n      \"rest\",\n      (): MotionProps => ({\n        initial: false,\n        animate: frames.rest,\n        transition: { duration: 0 },\n      }),\n    ),\n    Match.exhaustive,\n  );\n  const painted = Option.isNone(transition.pendingKey)\n    ? children\n    : outgoing.current;\n  const base = testId ?? \"page-transition\";\n  const state: PageTransitionPaint = {\n    view: transition.shownKey,\n    phase: transition.phase,\n    direction,\n    reducedMotion: preference === \"reduced\",\n  };\n\n  return (\n    <div\n      {...rest}\n      testId={base}\n      style={mergeStyles(\n        mergeStyles({ overflow: \"hidden\" }, recipeStyle(cn(className), theme)),\n        resolveStyle(style, state),\n      )}\n    >\n      <div\n        key={`${transition.shownKey}:${transition.run}`}\n        testId={`${base}-view`}\n        motion={motion}\n        style={mergeStyles(\n          { position: \"relative\" },\n\n          presenceStyle(transition.phase !== \"leaving\", \"wrapper\"),\n        )}\n      >\n        {painted}\n        <PresenceShield present={transition.phase !== \"leaving\"} />\n      </div>\n    </div>\n  );\n};\n\nexport const pageTransitionMeta = {\n  name: \"Page transition\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"one view is mounted at a time: the old view leaves before the new one arrives, because 0.11.0 has no aria-hidden to keep the outgoing page out of the accessibility tree\",\n    \"the travel is a relative left on a clipped box, not a transform (upstream issue #102)\",\n    \"the region clips its view, so a page that overflows sideways is cut at the region's edge\",\n    \"the swap does not move the focus: a control inside the outgoing view unmounts, so the caller restores focus when the new view needs it\",\n    \"forward/back on the horizontal axis only: a vertical slide reads as a scroll, not a page\",\n  ],\n  docs: \"docs/page-transition.mdx\",\n  example: \"examples/page-transition.example.tsx\",\n  testFile: \"src/behaviour/page-transition.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/components/src/page-transition/logic.ts",
      "target": "@ui/gpuixui/components/page-transition/logic.ts",
      "type": "registry:lib",
      "content": "import type { MotionStyle } from \"@gpuix/react\";\nimport { Match } from \"effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\n\nconst ViewDirection = Schema.Literals([\"forward\", \"back\"]);\n\nexport type PageDirection = typeof ViewDirection.Type;\n\nconst directionOf = (direction: unknown): PageDirection =>\n  Schema.is(ViewDirection)(direction) ? direction : \"forward\";\n\nexport type PagePhase = \"rest\" | \"leaving\" | \"entering\";\n\nexport const PAGE_TRAVEL = 16;\n\nexport interface PageFrames {\n  readonly enterFrom: MotionStyle;\n\n  readonly rest: MotionStyle;\n\n  readonly exitTo: MotionStyle;\n}\n\nexport const pageTravel = (distance: number): number =>\n  Number.isFinite(distance) && distance > 0\n    ? Math.round(distance)\n    : PAGE_TRAVEL;\n\nexport const pageFrames = (\n  direction: unknown,\n  distance: number,\n): PageFrames => {\n  const travel = pageTravel(distance);\n\n  return Match.value(directionOf(direction)).pipe(\n    Match.when(\"forward\", () => ({\n      enterFrom: { opacity: 0, left: travel },\n      rest: { opacity: 1, left: 0 },\n      exitTo: { opacity: 0, left: -travel },\n    })),\n    Match.when(\"back\", () => ({\n      enterFrom: { opacity: 0, left: -travel },\n      rest: { opacity: 1, left: 0 },\n      exitTo: { opacity: 0, left: travel },\n    })),\n    Match.exhaustive,\n  );\n};\n\nexport interface PageTransitionState {\n  readonly shownKey: string;\n\n  readonly pendingKey: Option.Option<string>;\n  readonly phase: PagePhase;\n  readonly run: number;\n}\n\nexport const initialPageTransition = (\n  viewKey: string,\n): PageTransitionState => ({\n  shownKey: viewKey,\n  pendingKey: Option.none(),\n  phase: \"rest\",\n  run: 0,\n});\n\nexport const requestPage = (\n  state: PageTransitionState,\n  viewKey: string,\n  instant: boolean,\n): PageTransitionState => {\n  if (viewKey === state.shownKey) {\n    if (Option.isNone(state.pendingKey)) return state;\n    return { ...state, pendingKey: Option.none(), phase: \"entering\" };\n  }\n\n  if (instant) {\n    return {\n      shownKey: viewKey,\n      pendingKey: Option.none(),\n      phase: \"rest\",\n      run: state.run + 1,\n    };\n  }\n\n  return state.phase === \"leaving\"\n    ? { ...state, pendingKey: Option.some(viewKey) }\n    : { ...state, pendingKey: Option.some(viewKey), phase: \"leaving\" };\n};\n\nexport const settlePage = (state: PageTransitionState): PageTransitionState =>\n  state.phase !== \"leaving\"\n    ? state\n    : Option.match(state.pendingKey, {\n        onNone: () => state,\n        onSome: (viewKey) => ({\n          shownKey: viewKey,\n          pendingKey: Option.none(),\n          phase: \"entering\",\n          run: state.run + 1,\n        }),\n      });\n\nexport const finishPage = (state: PageTransitionState): PageTransitionState =>\n  state.phase === \"entering\" ? { ...state, phase: \"rest\" } : state;\n"
    }
  ],
  "docs": "[Page transition](https://gpuixui.sudokw.com/components/page-transition) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/components/page-transition",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}