{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-typing-text",
  "type": "registry:component",
  "title": "Typing text",
  "description": "A string that arrives a character at a time",
  "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/typing-text.tsx",
      "target": "@ui/gpuixui/fx/typing-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 { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n  useMotionPreference,\n  recipeStyle,\n  nameOf,\n  textOf,\n  textStyle,\n  useTheme,\n  type TextRole,\n  type Theme,\n} from \"../components/authoring.js\";\nimport {\n  characters,\n  typingTiming,\n  visibleText,\n  type TypingTiming,\n} from \"./typing-text/logic.js\";\n\nexport interface TypingTextState {\n  readonly revealed: number;\n\n  readonly complete: boolean;\n\n  readonly reducedMotion: boolean;\n}\n\nexport interface TypingTextProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly text: string;\n\n  readonly speed?: number;\n\n  readonly delay?: number;\n\n  readonly caret?: boolean;\n\n  readonly label?: string;\n\n  readonly onComplete?: () => void;\n\n  readonly role?: TextRole;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<TypingTextState>;\n}\n\ninterface Progress {\n  readonly run: string;\n  readonly revealed: number;\n}\n\nconst caretStyle = (theme: Theme, role: TextRole) => ({\n  width: 2,\n  height: textStyle(theme, role).lineHeight,\n  backgroundColor: theme.colors.primary,\n  borderRadius: 1,\n});\n\nexport const TypingText = ({\n  text,\n  speed,\n  delay,\n  caret = false,\n  label,\n  onComplete,\n  role = \"body\",\n  className,\n  style,\n  ...rest\n}: TypingTextProps) => {\n  const theme = useTheme();\n  const reducedMotion = useMotionPreference() === \"reduced\";\n\n  const phrase = textOf(text);\n  const timing: TypingTiming = useMemo(\n    () => typingTiming({ speedMs: speed, delayMs: delay }),\n    [delay, speed],\n  );\n  const charactersOf = useMemo(() => characters(phrase), [phrase]);\n  const total = charactersOf.length;\n  const instant = reducedMotion || timing.speedMs === 0;\n\n  const run = `${timing.speedMs}:${timing.delayMs}:${phrase}`;\n\n  const [progress, setProgress] = useState<Progress>({ run, revealed: 0 });\n  const revealed = instant\n    ? total\n    : progress.run === run\n      ? progress.revealed\n      : 0;\n  const complete = revealed >= total;\n\n  useEffect(() => {\n    if (instant || total === 0) return;\n\n    let shown = 0;\n    let handle: ReturnType<typeof setTimeout> | undefined;\n    const reveal = (): void => {\n      shown += 1;\n      setProgress({ run, revealed: shown });\n      if (shown < total) handle = setTimeout(reveal, timing.speedMs);\n    };\n    handle = setTimeout(reveal, timing.delayMs);\n\n    return () => {\n      if (handle !== undefined) clearTimeout(handle);\n    };\n  }, [instant, run, timing.delayMs, timing.speedMs, total]);\n\n  const announced = useRef<{ readonly text: string } | undefined>(undefined);\n  useEffect(() => {\n    if (!complete || announced.current?.text === phrase) return;\n    announced.current = { text: phrase };\n    onComplete?.();\n  }, [complete, onComplete, phrase]);\n\n  const state: TypingTextState = { revealed, complete, reducedMotion };\n\n  return (\n    <div\n      {...rest}\n      style={mergeStyles(\n        mergeStyles(recipeStyle(cn(className), theme), {\n          display: \"flex\",\n          flexDirection: \"row\",\n          alignItems: \"center\",\n        }),\n        resolveStyle(style, state),\n      )}\n    >\n      <text\n        aria-label={nameOf(label) ?? phrase}\n        style={{\n          ...textStyle(theme, role),\n          color: theme.colors.foreground,\n        }}\n      >\n        {visibleText(phrase, revealed)}\n      </text>\n      {caret && !complete ? <div style={caretStyle(theme, role)} /> : null}\n    </div>\n  );\n};\n\nexport const typingTextMeta = {\n  name: \"Typing text\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"yes\",\n  limitations: [\n    \"the reveal is a real-time timer, so it is not driven by the renderer's motion clock\",\n    \"a caret sits after the text block, not at the end of the last wrapped line\",\n    \"no per-glyph paint: the runtime cannot animate or measure individual characters\",\n  ],\n  docs: \"docs/typing-text.mdx\",\n  example: \"examples/typing-text.example.tsx\",\n  testFile: \"src/behaviour/typing-text.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/typing-text/logic.ts",
      "target": "@ui/gpuixui/fx/typing-text/logic.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\n\nexport const typingDefaults = {\n  speedMs: 45,\n\n  delayMs: 0,\n} as const;\n\nexport interface TypingTiming {\n  readonly delayMs: number;\n\n  readonly speedMs: number;\n}\n\nconst milliseconds = (value: Option.Option<number>, fallback: number): number =>\n  Option.match(\n    Option.filter(value, (ms) => Number.isFinite(ms) && ms >= 0),\n    {\n      onNone: () => fallback,\n      onSome: (ms) => Math.round(ms),\n    },\n  );\n\nexport const typingTiming = (\n  options: {\n    readonly speedMs?: number;\n    readonly delayMs?: number;\n  } = {},\n): TypingTiming => ({\n  delayMs: milliseconds(\n    Option.fromNullishOr(options.delayMs),\n    typingDefaults.delayMs,\n  ),\n  speedMs: milliseconds(\n    Option.fromNullishOr(options.speedMs),\n    typingDefaults.speedMs,\n  ),\n});\n\nexport const characters = (text: string): ReadonlyArray<string> =>\n  Arr.fromIterable(text);\n\nexport const visibleText = (text: string, revealed: number): string =>\n  Arr.join(\n    Arr.take(\n      characters(text),\n      Number.isFinite(revealed) ? Math.max(0, Math.trunc(revealed)) : 0,\n    ),\n    \"\",\n  );\n"
    }
  ],
  "docs": "[Typing text](https://gpuixui.sudokw.com/effects/typing-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/typing-text",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}