{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-rolling-text",
  "type": "registry:component",
  "title": "Rolling text",
  "description": "A value that rolls 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/rolling-text.tsx",
      "target": "@ui/gpuixui/fx/rolling-text.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 type { MotionLevel } from \"../motion/timing.js\";\nimport { cn } from \"../tw/index.js\";\nimport { Match } from \"effect\";\nimport { useEffect } from \"react\";\nimport { rollFrames, type RollDirection } from \"./rolling-text/logic.js\";\nimport { makeRollingStore } from \"./rolling-text/store.js\";\nimport {\n  send,\n  useLocalState,\n  useLocalStore,\n  useMotionPreference,\n  recipeStyle,\n  textOf,\n  textStyle,\n  useTheme,\n  type TextRole,\n} from \"../components/authoring.js\";\nimport { swapHalves, type SwapPhase } from \"./internal/text-swap.js\";\n\nexport interface RollingTextState {\n  readonly text: string;\n\n  readonly phase: SwapPhase;\n  readonly direction: RollDirection;\n  readonly reducedMotion: boolean;\n}\n\nexport interface RollingTextProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly text: string;\n\n  readonly direction?: RollDirection;\n\n  readonly level?: MotionLevel;\n\n  readonly role?: TextRole;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<RollingTextState>;\n}\n\nexport const RollingText = ({\n  text,\n  direction = \"up\",\n  level = \"normal\",\n  role = \"body\",\n  className,\n  style,\n  ...rest\n}: RollingTextProps) => {\n  const theme = useTheme();\n  const preference = useMotionPreference();\n  const timing = swapHalves(level, preference);\n  const reduced = preference === \"reduced\";\n\n  const value = textOf(text);\n  const store = useLocalStore(makeRollingStore(value));\n  const roll = useLocalState(store.local);\n\n  useEffect(() => {\n    send(store.show(value, { reduced, swapMs: timing.swapMs }));\n  }, [store, value, reduced, timing.swapMs]);\n\n  const metrics = textStyle(theme, role);\n  const frames = rollFrames(direction, metrics.lineHeight);\n  const motion = Match.value(roll.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: RollingTextState = {\n    text: roll.shown,\n    phase: roll.phase,\n    direction,\n    reducedMotion: preference === \"reduced\",\n  };\n\n  return (\n    <div\n      {...rest}\n      style={mergeStyles(\n        mergeStyles(\n          {\n            display: \"flex\",\n            flexDirection: \"column\",\n            alignItems: \"flex-start\",\n            overflow: \"hidden\",\n            height: metrics.lineHeight,\n          },\n          recipeStyle(cn(className), theme),\n        ),\n        resolveStyle(style, state),\n      )}\n    >\n      <text\n        key={roll.run}\n        motion={motion}\n        onMotionComplete={() => send(store.entered)}\n        style={{\n          position: \"relative\",\n          ...metrics,\n          color: theme.colors.foreground,\n          whiteSpace: \"nowrap\",\n        }}\n      >\n        {roll.shown}\n      </text>\n    </div>\n  );\n};\n\nexport const rollingTextMeta = {\n  name: \"Rolling text\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\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 travel is a relative top inside a clipping box, not a transform (upstream issue #102)\",\n    \"the box is as wide as the value on screen: the runtime cannot measure a string before it lays it out, so a caller reserves width when the layout must not move\",\n    \"no horizontal direction: a full-width slide needs the same measured width, so it is not implemented\",\n  ],\n  docs: \"docs/rolling-text.mdx\",\n  example: \"examples/rolling-text.example.tsx\",\n  testFile: \"src/behaviour/rolling-text.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/rolling-text/logic.ts",
      "target": "@ui/gpuixui/fx/rolling-text/logic.ts",
      "type": "registry:lib",
      "content": "import { swapFrames, type SwapFrames } from \"../internal/text-swap.js\";\n\nexport type RollDirection = \"up\" | \"down\";\n\nexport const rollFrames = (\n  direction: RollDirection,\n  lineHeight: number,\n): SwapFrames => swapFrames(\"top\", direction === \"up\" ? 1 : -1, lineHeight);\n"
    },
    {
      "path": "packages/fx/src/rolling-text/store.ts",
      "target": "@ui/gpuixui/fx/rolling-text/store.ts",
      "type": "registry:lib",
      "content": "import { Effect } from \"effect\";\nimport * as SubscriptionRef from \"effect/SubscriptionRef\";\nimport { makeLocalState, type LocalState } from \"../../components/authoring.js\";\nimport {\n  initialSwap,\n  requestSwap,\n  restSwap,\n  settleSwap,\n  type SwapState,\n} from \"../internal/text-swap.js\";\n\nexport interface RollPolicy {\n  readonly reduced: boolean;\n\n  readonly swapMs: number;\n}\n\nexport interface RollingStore {\n  readonly local: LocalState<SwapState>;\n\n  readonly show: (text: string, policy: RollPolicy) => Effect.Effect<void>;\n\n  readonly entered: Effect.Effect<void>;\n}\n\nexport const makeRollingStore = (text: string): Effect.Effect<RollingStore> =>\n  Effect.gen(function* () {\n    const local = yield* makeLocalState<SwapState>(initialSwap(text));\n\n    const settle = Effect.gen(function* () {\n      const current = yield* SubscriptionRef.get(local.state);\n      const next = settleSwap(current);\n      if (next !== current) yield* local.write(next);\n    });\n\n    const show = Effect.fnUntraced(function* (\n      text: string,\n      policy: RollPolicy,\n    ) {\n      const current = yield* SubscriptionRef.get(local.state);\n      const next = requestSwap(current, text, policy.reduced);\n      if (next === current) return;\n      yield* local.write(next);\n      if (next.phase !== \"leaving\") {\n        yield* local.cancel;\n        return;\n      }\n\n      if (!local.running()) yield* local.after(policy.swapMs, settle);\n    });\n\n    const entered = Effect.gen(function* () {\n      const current = yield* SubscriptionRef.get(local.state);\n      const next = restSwap(current);\n      if (next !== current) yield* local.write(next);\n    });\n\n    return { local, show, entered };\n  });\n"
    }
  ],
  "docs": "[Rolling text](https://gpuixui.sudokw.com/effects/rolling-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/rolling-text",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}