{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-rotating-text",
  "type": "registry:component",
  "title": "Rotating text",
  "description": "One line whose phrase changes on an interval",
  "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-tw.json"
  ],
  "files": [
    {
      "path": "packages/fx/src/rotating-text.tsx",
      "target": "@ui/gpuixui/fx/rotating-text.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { Props } from \"@gpuix/react\";\nimport {\n  mergeStyles,\n  resolveStyle,\n  type StateStyle,\n} from \"@gpuix/react/floating\";\nimport { cn } from \"../tw/index.js\";\nimport * as Option from \"effect/Option\";\nimport { useEffect, useRef } from \"react\";\nimport {\n  useControllableState,\n  useSurfaceTiming,\n  recipeStyle,\n  nameOf,\n  textStyle,\n  useTheme,\n  type TextRole,\n} from \"../components/authoring.js\";\nimport { at, nextIndex, phraseAt, phrasesOf } from \"./rotating-text/logic.js\";\n\nexport interface RotatingTextState {\n  readonly phrase: string;\n\n  readonly index: number;\n}\n\nexport interface RotatingTextProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly phrases: ReadonlyArray<string>;\n\n  readonly intervalMs?: number;\n\n  readonly index?: number;\n\n  readonly defaultIndex?: number;\n  readonly onIndexChange?: (index: number) => void;\n\n  readonly label?: string;\n\n  readonly role?: TextRole;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<RotatingTextState>;\n}\n\nconst intervalOf = (value: Option.Option<number>): number =>\n  Option.getOrElse(\n    Option.filter(value, (ms) => Number.isFinite(ms) && ms >= 50),\n    () => 3000,\n  );\n\nexport const RotatingText = ({\n  phrases,\n  intervalMs,\n  index: indexProp,\n  defaultIndex = 0,\n  onIndexChange,\n  label,\n  role = \"body\",\n  className,\n  style,\n  ...rest\n}: RotatingTextProps) => {\n  const theme = useTheme();\n  const timing = useSurfaceTiming(\"fast\");\n  const interval = intervalOf(Option.fromNullishOr(intervalMs));\n\n  const list = phrasesOf(phrases);\n  const [rawIndex, setIndex] = useControllableState({\n    value: indexProp,\n    defaultValue: defaultIndex,\n    onChange: onIndexChange,\n  });\n  const index = at(rawIndex, list.length);\n  const phrase = Option.getOrElse(phraseAt(list, index), () => \"\");\n\n  const latest = useRef({ index, length: list.length, setIndex });\n  latest.current = { index, length: list.length, setIndex };\n\n  useEffect(() => {\n    if (list.length < 2) return;\n    const handle = setInterval(() => {\n      const next = latest.current;\n      next.setIndex(nextIndex(next.index, next.length));\n    }, interval);\n    return () => clearInterval(handle);\n  }, [interval, list.length]);\n\n  const state: RotatingTextState = { phrase, index };\n\n  return (\n    <text\n      key={index}\n      {...rest}\n      aria-label={nameOf(label) ?? nameOf(phrase)}\n      motion={{\n        initial: { opacity: 0 },\n        animate: { opacity: 1 },\n        transition: timing.enter,\n      }}\n      style={mergeStyles(\n        mergeStyles(recipeStyle(cn(className), theme), {\n          ...textStyle(theme, role),\n          color: theme.colors.foreground,\n        }),\n        resolveStyle(style, state),\n      )}\n    >\n      {phrase}\n    </text>\n  );\n};\n\nexport const rotatingTextMeta = {\n  name: \"Rotating text\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"yes\",\n  limitations: [\n    \"each step remounts one text host: the runtime cannot animate text content in place\",\n    \"the rotation keeps its interval under the reduced preference; only the fade is removed\",\n    \"no per-word layout, so no slide, mask or stagger between phrases\",\n  ],\n  docs: \"docs/rotating-text.mdx\",\n  example: \"examples/rotating-text.example.tsx\",\n  testFile: \"src/behaviour/rotating-text.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/rotating-text/logic.ts",
      "target": "@ui/gpuixui/fx/rotating-text/logic.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport * as P from \"effect/Predicate\";\n\nexport const phrasesOf = (value: unknown): ReadonlyArray<string> =>\n  Arr.isArray(value) ? Arr.filter(value, P.isString) : [];\n\nconst lengthOf = (count: number): number =>\n  Number.isFinite(count) ? Math.max(0, Math.trunc(count)) : 0;\n\nexport const nextIndex = (index: number, count: number): number => {\n  const size = lengthOf(count);\n  if (size === 0) return 0;\n  const current = Number.isFinite(index) ? Math.trunc(index) : 0;\n  return (((current + 1) % size) + size) % size;\n};\n\nexport const at = (index: number, count: number): number => {\n  const size = lengthOf(count);\n  if (size === 0) return 0;\n  const current = Number.isFinite(index) ? Math.trunc(index) : 0;\n  return ((current % size) + size) % size;\n};\n\nexport const phraseAt = (\n  phrases: ReadonlyArray<string>,\n  index: number,\n): Option.Option<string> => Arr.get(phrases, at(index, phrases.length));\n"
    }
  ],
  "docs": "[Rotating text](https://gpuixui.sudokw.com/effects/rotating-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/rotating-text",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}