{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-sliding-text",
  "type": "registry:component",
  "title": "Sliding text",
  "description": "A value that slides horizontally into place when it changes",
  "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-components.json",
    "https://gpuixui.sudokw.com/gpuix-motion.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/fx/src/internal/text-swap.ts",
      "target": "@ui/gpuixui/fx/internal/text-swap.ts",
      "type": "registry:lib",
      "content": "import type { MotionStyle, MotionTransition } from \"@gpuix/react\";\nimport {\n  motionTiming,\n  type MotionLevel,\n  type MotionPreference,\n} from \"../../motion/timing.js\";\nimport { Match } from \"effect\";\nimport * as Option from \"effect/Option\";\nimport { transitionWindowMs } from \"../../components/authoring.js\";\n\nexport type SwapPhase = \"rest\" | \"leaving\" | \"entering\";\n\nexport interface SwapState {\n  readonly shown: string;\n\n  readonly run: number;\n  readonly phase: SwapPhase;\n\n  readonly pending: Option.Option<string>;\n}\n\nexport const initialSwap = (text: string): SwapState => ({\n  shown: text,\n  run: 0,\n  phase: \"rest\",\n  pending: Option.none(),\n});\n\nconst jump = (state: SwapState, text: string): SwapState =>\n  state.shown === text && state.phase === \"rest\"\n    ? state\n    : {\n        shown: text,\n        run: state.shown === text ? state.run : state.run + 1,\n        phase: \"rest\",\n        pending: Option.none(),\n      };\n\nexport const requestSwap = (\n  state: SwapState,\n  text: string,\n  reduced: boolean,\n): SwapState =>\n  reduced\n    ? jump(state, text)\n    : Match.value(state.phase).pipe(\n        Match.when(\"leaving\", () =>\n          state.shown === text\n            ? { ...state, phase: \"entering\" as const, pending: Option.none() }\n            : { ...state, pending: Option.some(text) },\n        ),\n        Match.when(\"entering\", () =>\n          state.shown === text\n            ? state\n            : {\n                ...state,\n                phase: \"leaving\" as const,\n                pending: Option.some(text),\n              },\n        ),\n        Match.when(\"rest\", () =>\n          state.shown === text\n            ? state\n            : {\n                ...state,\n                phase: \"leaving\" as const,\n                pending: Option.some(text),\n              },\n        ),\n        Match.exhaustive,\n      );\n\nexport const settleSwap = (state: SwapState): SwapState =>\n  Option.match(state.pending, {\n    onNone: () => state,\n    onSome: (text) => ({\n      shown: text,\n      run: state.run + 1,\n      phase: \"entering\",\n      pending: Option.none(),\n    }),\n  });\n\nexport const restSwap = (state: SwapState): SwapState =>\n  state.phase === \"entering\" ? { ...state, phase: \"rest\" } : state;\n\nexport type SwapAxis = \"left\" | \"top\";\n\nexport type Travel = 1 | -1;\n\nexport interface SwapFrames {\n  readonly enterFrom: MotionStyle;\n\n  readonly rest: MotionStyle;\n\n  readonly exitTo: MotionStyle;\n}\n\nconst frame = (axis: SwapAxis, offset: number, opacity: number): MotionStyle =>\n  axis === \"top\" ? { opacity, top: offset } : { opacity, left: offset };\n\nexport const swapFrames = (\n  axis: SwapAxis,\n  travel: Travel,\n  distance: number,\n): SwapFrames => {\n  const length = Number.isFinite(distance) ? Math.max(0, distance) : 0;\n  const offset = (sign: Travel): number => (length === 0 ? 0 : sign * length);\n  return {\n    enterFrom: frame(axis, offset(travel), 0),\n    rest: frame(axis, 0, 1),\n    exitTo: frame(axis, offset(travel === 1 ? -1 : 1), 0),\n  };\n};\n\nexport interface SwapTiming {\n  readonly exit: MotionTransition;\n  readonly enter: MotionTransition;\n\n  readonly swapMs: number;\n}\n\nconst halve = (timing: MotionTransition): MotionTransition => ({\n  ...timing,\n  duration: (timing.duration ?? 0) / 2,\n});\n\nexport const swapHalves = (\n  level: MotionLevel,\n  preference: MotionPreference,\n): SwapTiming => {\n  const exit = halve(motionTiming(level, { phase: \"exit\", preference }));\n  return {\n    exit,\n    enter: halve(motionTiming(level, { phase: \"enter\", preference })),\n    swapMs: transitionWindowMs(exit),\n  };\n};\n"
    },
    {
      "path": "packages/fx/src/sliding-text.tsx",
      "target": "@ui/gpuixui/fx/sliding-text.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { EventPayload, MotionProps, Props } from \"@gpuix/react\";\nimport {\n  mergeStyles,\n  resolveStyle,\n  type StateStyle,\n} from \"@gpuix/react/floating\";\nimport type { MotionLevel } from \"../motion/timing.js\";\nimport { cn } from \"../tw/index.js\";\nimport { Match } from \"effect\";\nimport * as Option from \"effect/Option\";\nimport { useEffect, useState } from \"react\";\nimport {\n  measuredBox,\n  useMotionPreference,\n  recipeStyle,\n  textOf,\n  textStyle,\n  useTheme,\n  type TextRole,\n} from \"../components/authoring.js\";\nimport {\n  initialSwap,\n  requestSwap,\n  restSwap,\n  settleSwap,\n  swapHalves,\n  type SwapPhase,\n} from \"./internal/text-swap.js\";\nimport { slideFrames, type SlideDirection } from \"./sliding-text/logic.js\";\n\nexport interface SlidingTextState {\n  readonly text: string;\n\n  readonly phase: SwapPhase;\n  readonly direction: SlideDirection;\n\n  readonly width: number;\n  readonly reducedMotion: boolean;\n}\n\nexport interface SlidingTextProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly text: string;\n\n  readonly direction?: SlideDirection;\n\n  readonly level?: MotionLevel;\n\n  readonly role?: TextRole;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<SlidingTextState>;\n}\n\nexport const SlidingText = ({\n  text,\n  direction = \"forward\",\n  level = \"normal\",\n  role = \"body\",\n  className,\n  style,\n  onLayout,\n  ...rest\n}: SlidingTextProps) => {\n  const theme = useTheme();\n  const preference = useMotionPreference();\n  const timing = swapHalves(level, preference);\n\n  const value = textOf(text);\n  const [swap, setSwap] = useState(() => initialSwap(value));\n  const [width, setWidth] = useState(0);\n\n  useEffect(() => {\n    setSwap((current) => requestSwap(current, value, preference === \"reduced\"));\n  }, [value, preference]);\n\n  useEffect(() => {\n    if (swap.phase !== \"leaving\") return;\n\n    const handle = setTimeout(() => setSwap(settleSwap), timing.swapMs);\n    return () => clearTimeout(handle);\n  }, [swap.phase, timing.swapMs]);\n\n  const measure = (event: EventPayload) => {\n    onLayout?.(event);\n    Option.match(measuredBox(event), {\n      onNone: () => undefined,\n      onSome: (box) => setWidth(box.width),\n    });\n  };\n\n  const metrics = textStyle(theme, role);\n  const frames = slideFrames(direction, width);\n  const motion = Match.value(swap.phase).pipe(\n    Match.when(\n      \"rest\",\n      (): MotionProps => ({\n        initial: false,\n        animate: frames.rest,\n        transition: { duration: 0 },\n      }),\n    ),\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.exhaustive,\n  );\n  const state: SlidingTextState = {\n    text: swap.shown,\n    phase: swap.phase,\n    direction,\n    width,\n    reducedMotion: preference === \"reduced\",\n  };\n\n  return (\n    <div\n      {...rest}\n      onLayout={measure}\n      style={mergeStyles(\n        mergeStyles(\n          {\n            display: \"flex\",\n            flexDirection: \"column\",\n            alignItems: \"flex-start\",\n            overflow: \"hidden\",\n            width: \"100%\",\n            height: metrics.lineHeight,\n          },\n          recipeStyle(cn(className), theme),\n        ),\n        resolveStyle(style, state),\n      )}\n    >\n      <text\n        key={swap.run}\n        motion={motion}\n        onMotionComplete={() => setSwap(restSwap)}\n        style={{\n          position: \"relative\",\n          flexShrink: 0,\n          ...metrics,\n          color: theme.colors.foreground,\n          whiteSpace: \"nowrap\",\n        }}\n      >\n        {swap.shown}\n      </text>\n    </div>\n  );\n};\n\nexport const slidingTextMeta = {\n  name: \"Sliding text\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"the travel is a relative left inside a clipping box, not a transform (upstream issue #102), and the runtime keeps insets as numbers, so the distance is the box width the runtime reports after its first paint\",\n    \"a value changed before the box has been laid out fades in place, because the width is not known yet\",\n    \"one value is mounted at a time: the swap happens while the clip is empty, because 0.11.0 has no aria-hidden to keep the outgoing value out of the accessibility tree\",\n    \"the value is one line: a string wider than the box is clipped at the edge it slides past, not wrapped\",\n  ],\n  docs: \"docs/sliding-text.mdx\",\n  example: \"examples/sliding-text.example.tsx\",\n  testFile: \"src/behaviour/sliding-text.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/sliding-text/logic.ts",
      "target": "@ui/gpuixui/fx/sliding-text/logic.ts",
      "type": "registry:lib",
      "content": "import { swapFrames, type SwapFrames } from \"../internal/text-swap.js\";\n\nexport type SlideDirection = \"forward\" | \"back\";\n\nexport const slideFrames = (\n  direction: SlideDirection,\n  width: number,\n): SwapFrames => swapFrames(\"left\", direction === \"forward\" ? 1 : -1, width);\n"
    }
  ],
  "docs": "[Sliding text](https://gpuixui.sudokw.com/effects/sliding-text) — 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": "/effects/sliding-text",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}