{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-splitting-text",
  "type": "registry:component",
  "title": "Splitting text",
  "description": "A headline that arrives word by word",
  "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/splitting-text.tsx",
      "target": "@ui/gpuixui/fx/splitting-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 type { StaggerFrom } from \"../motion/timeline.js\";\nimport { cn } from \"../tw/index.js\";\nimport * as Option from \"effect/Option\";\nimport { useEffect } from \"react\";\nimport {\n  send,\n  useLocalState,\n  useLocalStore,\n  delayedTiming,\n  useSurfaceTiming,\n  recipeStyle,\n  textOf,\n  textStyle,\n  useTheme,\n  type TextRole,\n} from \"../components/authoring.js\";\nimport { offsetOf, type SplitMode } from \"./splitting-text/logic.js\";\nimport { makeSplittingStore } from \"./splitting-text/store.js\";\n\nexport interface SplittingTextState {\n  readonly text: string;\n\n  readonly units: number;\n  readonly reducedMotion: boolean;\n}\n\nexport interface SplittingTextProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly text: string;\n\n  readonly split?: SplitMode;\n\n  readonly stepMs?: number;\n\n  readonly from?: StaggerFrom;\n\n  readonly offset?: number;\n\n  readonly role?: TextRole;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<SplittingTextState>;\n}\n\nexport const SplittingText = ({\n  text,\n  split = \"words\",\n  stepMs,\n  from = \"start\",\n  offset,\n  role = \"body\",\n  className,\n  style,\n  ...rest\n}: SplittingTextProps) => {\n  const theme = useTheme();\n  const timing = useSurfaceTiming(\"normal\");\n\n  const phrase = textOf(text);\n  const store = useLocalStore(\n    makeSplittingStore({ text: phrase, split, stepMs, from }),\n  );\n  const reveal = useLocalState(store.local);\n\n  useEffect(() => {\n    send(store.show({ text: phrase, split, stepMs, from }));\n  }, [store, phrase, split, stepMs, from]);\n\n  const rise = offsetOf(Option.fromNullishOr(offset));\n  const metrics = textStyle(theme, role);\n  const state: SplittingTextState = {\n    text: reveal.text,\n    units: reveal.units,\n    reducedMotion: timing.enter.duration === 0,\n  };\n\n  return (\n    <div\n      {...rest}\n      style={mergeStyles(\n        mergeStyles(recipeStyle(cn(className), theme), {\n          display: \"flex\",\n          flexDirection: \"column\",\n        }),\n        resolveStyle(style, state),\n      )}\n    >\n      {reveal.lines.map((line) => (\n        <div\n          key={line.key}\n          style={{\n            display: \"flex\",\n            flexDirection: \"row\",\n            flexWrap: \"wrap\",\n            alignItems: \"baseline\",\n\n            columnGap:\n              split === \"words\" ? Math.round(metrics.fontSize * 0.3) : 0,\n          }}\n        >\n          {line.units.map((unit) => (\n            <text\n              key={unit.key}\n              motion={{\n                initial: { opacity: 0, top: rise },\n                animate: { opacity: 1, top: 0 },\n                transition: delayedTiming(timing.enter, unit.delayMs),\n              }}\n              style={{\n                position: \"relative\",\n                ...metrics,\n                color: theme.colors.foreground,\n              }}\n            >\n              {unit.text}\n            </text>\n          ))}\n        </div>\n      ))}\n    </div>\n  );\n};\n\nexport const splittingTextMeta = {\n  name: \"Splitting text\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"the runtime cannot animate one text node, so every unit is its own host\",\n    \"no transform: a unit fades and rises on a relative top offset\",\n    \"no aria-hidden in 0.11.0, so assistive technology hears the split units in order\",\n  ],\n  docs: \"docs/splitting-text.mdx\",\n  example: \"examples/splitting-text.example.tsx\",\n  testFile: \"src/behaviour/splitting-text.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/splitting-text/logic.ts",
      "target": "@ui/gpuixui/fx/splitting-text/logic.ts",
      "type": "registry:lib",
      "content": "import { stagger, type StaggerFrom } from \"../../motion/timeline.js\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport * as Str from \"effect/String\";\n\nexport type SplitMode = \"words\" | \"characters\";\n\nexport interface SplitUnit {\n  readonly key: string;\n  readonly text: string;\n\n  readonly delayMs: number;\n}\n\nexport interface SplitLine {\n  readonly key: string;\n  readonly units: ReadonlyArray<SplitUnit>;\n}\n\nexport interface SplitOptions {\n  readonly mode?: SplitMode;\n\n  readonly stepMs?: number;\n\n  readonly from?: StaggerFrom;\n}\n\nconst WORD_GAP = \"\\u00A0\";\n\nconst STEP_MS = 40;\n\nconst OFFSET_PX = 8;\n\nconst stepOf = (value: Option.Option<number>): number =>\n  Option.getOrElse(\n    Option.filter(value, (ms) => Number.isFinite(ms) && ms >= 0),\n    () => STEP_MS,\n  );\n\nexport const offsetOf = (value: Option.Option<number>): number =>\n  Option.getOrElse(Option.filter(value, Number.isFinite), () => OFFSET_PX);\n\nconst lineTexts = (line: string, mode: SplitMode): ReadonlyArray<string> =>\n  mode === \"words\"\n    ? Arr.filter(Str.split(line, /\\s+/), Str.isNonEmpty)\n    : Arr.map(Arr.fromIterable(line), (unit) =>\n        unit === \" \" ? WORD_GAP : unit,\n      );\n\nexport const splitUnits = (\n  text: string,\n  options: SplitOptions = {},\n): ReadonlyArray<SplitLine> => {\n  const mode = options.mode ?? \"words\";\n  const stepMs = stepOf(Option.fromNullishOr(options.stepMs));\n  const from = options.from ?? \"start\";\n  const texts = Arr.filter(\n    Arr.map(Str.split(text, \"\\n\"), (line) => lineTexts(line, mode)),\n    Arr.isReadonlyArrayNonEmpty,\n  );\n  const total = Arr.reduce(texts, 0, (count, units) => count + units.length);\n  const placed = Arr.mapAccum(texts, 0, (start, units) => [\n    start + units.length,\n    Arr.map(units, (unit, local) => ({\n      key: `${start + local}:${unit}`,\n      text: unit,\n      delayMs: stagger(stepMs, start + local, total, from),\n    })),\n  ]);\n\n  return Arr.map(placed[1], (units, index) => ({\n    key: String(index),\n    units,\n  }));\n};\n"
    },
    {
      "path": "packages/fx/src/splitting-text/store.ts",
      "target": "@ui/gpuixui/fx/splitting-text/store.ts",
      "type": "registry:lib",
      "content": "import type { StaggerFrom } from \"../../motion/timeline.js\";\nimport { Effect } from \"effect\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport * as SubscriptionRef from \"effect/SubscriptionRef\";\nimport { makeLocalState, type LocalState } from \"../../components/authoring.js\";\nimport { splitUnits, type SplitLine, type SplitMode } from \"./logic.js\";\n\nexport interface SplitState {\n  readonly text: string;\n  readonly mode: SplitMode;\n\n  readonly stepMs: Option.Option<number>;\n  readonly from: StaggerFrom;\n  readonly lines: ReadonlyArray<SplitLine>;\n  readonly units: number;\n}\n\nexport interface SplitInput {\n  readonly text: string;\n  readonly split: SplitMode;\n  readonly stepMs: number | undefined;\n  readonly from: StaggerFrom;\n}\n\nexport interface SplittingStore {\n  readonly local: LocalState<SplitState>;\n\n  readonly show: (input: SplitInput) => Effect.Effect<void>;\n}\n\nconst splitOf = (input: SplitInput): SplitState => {\n  const lines = splitUnits(input.text, {\n    mode: input.split,\n    stepMs: input.stepMs,\n    from: input.from,\n  });\n  return {\n    text: input.text,\n    mode: input.split,\n    stepMs: Option.fromNullishOr(input.stepMs),\n    from: input.from,\n    lines,\n    units: Arr.reduce(lines, 0, (count, line) => count + line.units.length),\n  };\n};\n\nconst sameInput = (state: SplitState, input: SplitInput): boolean =>\n  state.text === input.text &&\n  state.mode === input.split &&\n  state.from === input.from &&\n  Option.getOrNull(state.stepMs) === (input.stepMs ?? null);\n\nexport const makeSplittingStore = (\n  input: SplitInput,\n): Effect.Effect<SplittingStore> =>\n  Effect.gen(function* () {\n    const local = yield* makeLocalState<SplitState>(splitOf(input));\n\n    const show = Effect.fnUntraced(function* (next: SplitInput) {\n      const current = yield* SubscriptionRef.get(local.state);\n      if (sameInput(current, next)) return;\n      yield* local.write(splitOf(next));\n    });\n\n    return { local, show };\n  });\n"
    }
  ],
  "docs": "[Splitting text](https://gpuixui.sudokw.com/effects/splitting-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/splitting-text",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}