{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "space-type",
  "title": "SpaceType",
  "description": "Wraps a phrase around rotating rings with a soft radial wave.",
  "dependencies": [],
  "files": [
    {
      "path": "packages/react/src/space-type.tsx",
      "content": "'use client'\n\nimport './space-type.css'\nimport {\n  getSpaceTypeGeometry,\n  type SpaceTypeControls,\n  type SpaceTypeGeometry,\n  type SpaceTypeOptions,\n  spaceType,\n} from './motion/space-type.js'\nimport {\n  type CSSProperties,\n  forwardRef,\n  type HTMLAttributes,\n  useEffect,\n  useMemo,\n  useRef,\n  useState,\n} from 'react'\nimport { composeRefs } from './compose-refs.js'\nimport { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect.js'\n\nexport interface SpaceTypeProps\n  extends SpaceTypeOptions,\n    Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'color'> {\n  text: string\n  /** Number of stacked rings, from 1 to 6. @default 1 */\n  rows?: number\n  /** Text color; alternatively set --kida-space-type-color. */\n  color?: string\n  /** Surface color; alternatively set --kida-space-type-background. */\n  background?: string\n  /** Strength of the pulsing cylinder and tilting letter surface, from 0 to 100. @default 0 */\n  longitude?: number\n  /** Base radius in pixels, clamped to the available frame. Defaults to auto. */\n  radius?: number\n  /** Reports fitted geometry and the available radius range after measurement. */\n  onGeometryChange?: (geometry: SpaceTypeGeometry | null) => void\n}\n\nexport const SpaceType = forwardRef<HTMLDivElement, SpaceTypeProps>(function SpaceType(\n  {\n    text,\n    speed = 1,\n    paused = false,\n    rows = 1,\n    color,\n    background,\n    longitude = 0,\n    radius,\n    onGeometryChange,\n    style,\n    ...props\n  },\n  forwardedRef,\n) {\n  const rootRef = useRef<HTMLDivElement>(null)\n  const controlsRef = useRef<SpaceTypeControls | null>(null)\n  const [size, setSize] = useState({ width: 0, height: 0 })\n  const rowCount = Number.isFinite(rows) ? Math.max(1, Math.min(6, Math.round(rows))) : 1\n  const wave = Number.isFinite(longitude) ? Math.max(0, Math.min(100, longitude)) : 0\n  const characters = Array.from(text)\n  const geometry = useMemo(\n    () => getSpaceTypeGeometry(size.width, size.height, characters.length, rowCount, wave, radius),\n    [size.width, size.height, characters.length, rowCount, wave, radius],\n  )\n\n  useIsomorphicLayoutEffect(() => {\n    const root = rootRef.current\n    if (!root) return\n    const observer = new ResizeObserver(([entry]) => {\n      if (!entry) return\n      const { width, height } = entry.contentRect\n      setSize((current) =>\n        current.width === width && current.height === height ? current : { width, height },\n      )\n    })\n    observer.observe(root)\n    const controls = spaceType(root)\n    controlsRef.current = controls\n    return () => {\n      observer.disconnect()\n      controls.destroy()\n      controlsRef.current = null\n    }\n  }, [])\n\n  useIsomorphicLayoutEffect(() => {\n    controlsRef.current?.setPlayback({ speed, paused: paused || characters.length === 0 })\n  }, [speed, paused, characters.length])\n\n  useEffect(() => {\n    onGeometryChange?.(geometry)\n  }, [geometry, onGeometryChange])\n\n  return (\n    <div\n      {...props}\n      ref={composeRefs(rootRef, forwardedRef)}\n      data-kida-space-type=\"\"\n      style={\n        {\n          '--kida-space-type-count': Math.max(characters.length, 1),\n          '--kida-space-type-rows': rowCount,\n          '--kida-space-type-longitude': wave,\n          ...(color === undefined ? {} : { '--kida-space-type-color': color }),\n          ...(background === undefined ? {} : { '--kida-space-type-background': background }),\n          ...(geometry\n            ? {\n                '--kida-space-type-size': `${geometry.fontSize}px`,\n                '--kida-space-type-radius': `${geometry.radius}px`,\n                '--kida-space-type-perspective': `${geometry.perspective}px`,\n              }\n            : {}),\n          ...style,\n        } as CSSProperties\n      }\n    >\n      <span data-kida-space-type-text=\"\">{text}</span>\n      <div data-kida-space-type-space=\"\" aria-hidden=\"true\">\n        <div data-kida-space-type-camera=\"\">\n          <div data-kida-space-type-ring=\"\">\n            {Array.from({ length: rowCount }, (_, row) => (\n              <div\n                // biome-ignore lint/suspicious/noArrayIndexKey: row slots are stable positions without local state\n                key={row}\n                data-kida-space-type-row=\"\"\n                style={{ '--kida-space-type-row': row } as CSSProperties}\n              >\n                {characters.map((character, index) => (\n                  <span\n                    // biome-ignore lint/suspicious/noArrayIndexKey: glyph slots preserve rotation while editing text\n                    key={index}\n                    data-kida-space-type-letter=\"\"\n                    style={{ '--kida-space-type-index': index } as CSSProperties}\n                  >\n                    <span data-kida-space-type-face=\"front\">{character}</span>\n                    <span data-kida-space-type-face=\"back\">{character}</span>\n                  </span>\n                ))}\n              </div>\n            ))}\n          </div>\n        </div>\n      </div>\n    </div>\n  )\n})\n",
      "type": "registry:ui",
      "target": "@ui/kida/space-type.tsx"
    },
    {
      "path": "packages/react/src/compose-refs.ts",
      "content": "import type { Ref } from 'react'\n\n/** Feed one node to several refs — ours for measuring, Zag's for animation detection. */\nexport function composeRefs<T>(...refs: (Ref<T> | undefined)[]) {\n  return (node: T | null) => {\n    for (const ref of refs) {\n      if (typeof ref === 'function') ref(node)\n      else if (ref) (ref as { current: T | null }).current = node\n    }\n  }\n}\n",
      "type": "registry:lib",
      "target": "@ui/kida/compose-refs.ts"
    },
    {
      "path": "packages/react/src/use-isomorphic-layout-effect.ts",
      "content": "'use client'\n\nimport { useEffect, useLayoutEffect } from 'react'\n\n/**\n * `useLayoutEffect` in the browser, `useEffect` on the server.\n *\n * Motion has to be applied before paint or the user sees an unstyled frame, but React\n * warns when `useLayoutEffect` runs during SSR — where it does nothing anyway.\n */\nexport const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect\n",
      "type": "registry:hook",
      "target": "@ui/kida/use-isomorphic-layout-effect.ts"
    },
    {
      "path": "packages/styles/components/space-type.css",
      "content": "[data-kida-space-type] {\n  --kida-space-type-color: #211c24;\n  --kida-space-type-background: #fffafb;\n  width: 100%;\n  --kida-space-type-size: calc(\n    min(9cqw, 350cqw / var(--kida-space-type-count), 20cqw / var(--kida-space-type-rows))\n  );\n  /* Reserve the strongest wave before measurement as well. */\n  --kida-space-type-radius: calc(34cqw / 1.32);\n  position: relative;\n  container-type: inline-size;\n  height: var(--kida-space-type-height, clamp(15rem, 40vw, 28rem));\n  padding: 0;\n  border: 0;\n  overflow: clip;\n  background: var(--kida-space-type-background);\n}\n\n[data-kida-space-type] [data-kida-space-type-space] {\n  position: relative;\n  width: 100%;\n  height: 100%;\n  user-select: none;\n  pointer-events: none;\n  perspective: var(--kida-space-type-perspective, 1200cqw);\n}\n\n[data-kida-space-type] [data-kida-space-type-camera],\n[data-kida-space-type] [data-kida-space-type-ring],\n[data-kida-space-type] [data-kida-space-type-row],\n[data-kida-space-type] [data-kida-space-type-letter] {\n  position: absolute;\n  width: 0;\n  height: 0;\n  transform-style: preserve-3d;\n}\n\n[data-kida-space-type] [data-kida-space-type-camera] {\n  top: 50%;\n  left: 50%;\n  transform: rotateX(18deg) rotateZ(-3deg);\n}\n\n[data-kida-space-type] [data-kida-space-type-ring] {\n  transform: rotateY(-90deg);\n}\n\n[data-kida-space-type] [data-kida-space-type-row] {\n  /* A wave travels along the cylinder's rows. Each letter follows its local slope. */\n  --kida-space-type-wave-angle: calc(\n    var(--kida-space-type-phase) *\n    2880deg +\n    var(--kida-space-type-row) *\n    2160deg /\n    var(--kida-space-type-count)\n  );\n  --kida-space-type-wave-amplitude: calc(\n    var(--kida-space-type-radius) *\n    var(--kida-space-type-longitude) *\n    0.0032\n  );\n  --kida-space-type-row-radius: calc(\n    var(--kida-space-type-radius) +\n    sin(var(--kida-space-type-wave-angle)) *\n    var(--kida-space-type-wave-amplitude)\n  );\n  --kida-space-type-surface-tilt: atan2(\n    calc(\n      var(--kida-space-type-wave-amplitude) *\n      cos(var(--kida-space-type-wave-angle)) *\n      sin(2160deg / var(--kida-space-type-count))\n    ),\n    calc(var(--kida-space-type-size) * 1.2)\n  );\n  transform: translateY(\n    calc(\n      (var(--kida-space-type-row) - (var(--kida-space-type-rows) - 1) / 2) *\n      var(--kida-space-type-size) *\n      1.2\n    )\n  );\n}\n\n[data-kida-space-type] [data-kida-space-type-letter] {\n  transform: rotateY(calc(var(--kida-space-type-index) * 360deg / var(--kida-space-type-count)))\n    translateZ(var(--kida-space-type-row-radius)) rotateX(var(--kida-space-type-surface-tilt));\n}\n\n[data-kida-space-type] [data-kida-space-type-face] {\n  position: absolute;\n  top: calc(var(--kida-space-type-size) * -0.5);\n  left: calc(var(--kida-space-type-size) * -0.4);\n  width: calc(var(--kida-space-type-size) * 0.8);\n  height: var(--kida-space-type-size);\n  backface-visibility: hidden;\n  font-family: var(--kida-space-type-font, \"Helvetica Neue\", \"Segoe UI\", sans-serif);\n  font-size: var(--kida-space-type-size);\n  font-weight: 200;\n  line-height: 1;\n  text-align: center;\n  white-space: pre;\n}\n\n[data-kida-space-type] [data-kida-space-type-face=\"front\"] {\n  color: var(--kida-space-type-color);\n  transform: translateZ(0.1px) scaleX(0.7);\n}\n\n[data-kida-space-type] [data-kida-space-type-face=\"back\"] {\n  color: color-mix(in srgb, var(--kida-space-type-color) 30%, var(--kida-space-type-background));\n  transform: rotateY(180deg) translateZ(0.1px) scaleX(-0.7);\n}\n\n[data-kida-space-type] [data-kida-space-type-text] {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  padding: 0;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n\n@property --kida-space-type-phase {\n  syntax: \"<number>\";\n  inherits: true;\n  initial-value: 0;\n}\n",
      "type": "registry:ui",
      "target": "@ui/kida/space-type.css"
    },
    {
      "path": "packages/motion/src/space-type.ts",
      "content": "import { prefersReducedMotion, watchReducedMotion } from './reduced-motion.js'\n\nexport { getSpaceTypeGeometry, type SpaceTypeGeometry } from './space-type-geometry.js'\n\nexport interface SpaceTypeOptions {\n  /** Rotation rate; zero freezes the current angle. @default 1 */\n  speed?: number\n  /** Pause without resetting the current angle. @default false */\n  paused?: boolean\n}\n\nexport interface SpaceTypeControls {\n  setPlayback(options: SpaceTypeOptions): void\n  destroy(): void\n}\n\n/** Shared loop lifecycle; adapters only render the geometry and update playback options. */\nexport function spaceType(root: HTMLElement, options: SpaceTypeOptions = {}): SpaceTypeControls {\n  const ring = root.querySelector<HTMLElement>('[data-kida-space-type-ring]')\n  let animation: Animation | undefined\n  let visible = false\n  let destroyed = false\n  let speed = 1\n  let paused = false\n\n  const sync = () => {\n    if (destroyed || !ring) return\n    if (prefersReducedMotion()) {\n      animation?.cancel()\n      animation = undefined\n      root.dataset.state = 'reduced'\n      return\n    }\n    if (!animation) {\n      animation = ring.animate(\n        [\n          { transform: 'rotateY(-90deg)', '--kida-space-type-phase': '0' },\n          { transform: 'rotateY(270deg)', '--kida-space-type-phase': '1' },\n        ],\n        { duration: 24000, iterations: Number.POSITIVE_INFINITY, easing: 'linear' },\n      )\n      animation.pause()\n    }\n    if (animation.playbackRate !== speed) animation.updatePlaybackRate(speed)\n    if (paused || speed === 0 || !visible || document.hidden) {\n      animation.pause()\n      root.dataset.state = 'paused'\n    } else {\n      animation.play()\n      root.dataset.state = 'active'\n    }\n  }\n\n  const setPlayback = (next: SpaceTypeOptions) => {\n    speed = Number.isFinite(next.speed) ? Math.max(0, Math.min(3, next.speed ?? 1)) : 1\n    paused = next.paused ?? false\n    sync()\n  }\n  const observer = new IntersectionObserver(([entry]) => {\n    visible = entry?.isIntersecting ?? false\n    sync()\n  })\n  observer.observe(root)\n  document.addEventListener('visibilitychange', sync)\n  const unwatch = watchReducedMotion(sync)\n  setPlayback(options)\n\n  return {\n    setPlayback,\n    destroy() {\n      destroyed = true\n      observer.disconnect()\n      document.removeEventListener('visibilitychange', sync)\n      unwatch()\n      animation?.cancel()\n      animation = undefined\n      root.dataset.state = 'idle'\n    },\n  }\n}\n",
      "type": "registry:lib",
      "target": "@ui/kida/motion/space-type.ts"
    },
    {
      "path": "packages/motion/src/space-type-geometry.ts",
      "content": "const TILT = (18 * Math.PI) / 180\nconst ROLL = (3 * Math.PI) / 180\nconst PROJECTION_ALLOWANCE = 1.1\nconst RADIUS_RESERVE = 0.88\nconst MAX_WAVE = 0.32\n\n/** Bounds reserve the full longitude wave, so its strength never changes the base radius. */\nexport function getSpaceTypeGeometry(\n  width: number,\n  height: number,\n  characterCount: number,\n  rows: number,\n  _longitude: number,\n  requestedRadius?: number,\n) {\n  if (width <= 0 || height <= 0) return null\n\n  rows = Number.isFinite(rows) ? Math.max(1, Math.min(6, Math.round(rows))) : 1\n  const count = Math.max(1, characterCount)\n  const inset = Math.max(8, width * 0.018)\n  const halfWidth = Math.max(0, width / 2 - inset) / PROJECTION_ALLOWANCE\n  const halfHeight = Math.max(0, height / 2 - inset) / PROJECTION_ALLOWANCE\n  const radialX = Math.cos(ROLL)\n  const stackX = Math.sin(ROLL)\n  const radialY = Math.hypot(Math.cos(TILT) * Math.sin(ROLL), Math.sin(TILT))\n  const stackY = Math.cos(TILT) * Math.cos(ROLL)\n\n  const radiusLimit = (fontSize: number, tilted = false) => {\n    // Tilting the glyph surface can project half its height into the radial plane.\n    const glyphRadialExtent = fontSize * (tilted ? 0.9 : 0.4)\n    const stackHalfHeight = fontSize * ((rows - 1) * 0.6 + 0.5)\n    return Math.max(\n      0,\n      Math.min(\n        (halfWidth - stackHalfHeight * stackX) / radialX - glyphRadialExtent,\n        (halfHeight - stackHalfHeight * stackY) / radialY - glyphRadialExtent,\n      ),\n    )\n  }\n\n  // Size type against the resting ring, independently of radius and wave strength.\n  let fontSize = Math.min(width * 0.09, (width * 3.5) / count, (width * 0.2) / rows)\n  const nominalRadius = width * 0.34\n  const initialRadius = Math.min(nominalRadius, radiusLimit(fontSize) * RADIUS_RESERVE)\n  if (count > 1) {\n    fontSize = Math.min(fontSize, (2 * initialRadius * Math.sin(Math.PI / count)) / 0.7)\n  }\n\n  const maxRadius = radiusLimit(fontSize, true) / (1 + MAX_WAVE)\n  const defaultRadius = Math.min(nominalRadius, maxRadius * RADIUS_RESERVE)\n  // Compact rings intentionally pack the same-sized letters more densely.\n  const minRadius = Math.min(maxRadius, (width * 0.1) / (1 + MAX_WAVE))\n  const radius = Math.max(\n    minRadius,\n    Math.min(\n      maxRadius,\n      typeof requestedRadius === 'number' && Number.isFinite(requestedRadius)\n        ? requestedRadius\n        : defaultRadius,\n    ),\n  )\n\n  return {\n    fontSize,\n    radius,\n    minRadius,\n    maxRadius,\n    perspective: Math.max(width, height) * 12,\n  }\n}\n\nexport type SpaceTypeGeometry = NonNullable<ReturnType<typeof getSpaceTypeGeometry>>\n",
      "type": "registry:lib",
      "target": "@ui/kida/motion/space-type-geometry.ts"
    },
    {
      "path": "packages/motion/src/reduced-motion.ts",
      "content": "const QUERY = '(prefers-reduced-motion: reduce)'\n\n/**\n * Whether the user has asked for reduced motion.\n *\n * SSR-safe: returns `false` when there is no `window`, matching the CSS default\n * (the `prefers-reduced-motion` media query in `@kida-ui/styles` is the real guard;\n * this is for the JS-driven paths that CSS cannot express).\n */\nexport function prefersReducedMotion(): boolean {\n  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return false\n  return window.matchMedia(QUERY).matches\n}\n\n/**\n * Subscribe to changes of the reduced-motion preference.\n * Returns an unsubscribe function. No-op (and immediately unsubscribable) on the server.\n */\nexport function watchReducedMotion(onChange: (reduced: boolean) => void): () => void {\n  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return () => {}\n\n  const list = window.matchMedia(QUERY)\n  const handler = (event: MediaQueryListEvent) => onChange(event.matches)\n  list.addEventListener('change', handler)\n  return () => list.removeEventListener('change', handler)\n}\n",
      "type": "registry:lib",
      "target": "@ui/kida/motion/reduced-motion.ts"
    }
  ],
  "meta": {
    "kida": {
      "package": {
        "name": "@kida-ui/react",
        "exportName": "SpaceType",
        "styleImports": [
          "@kida-ui/styles/components/space-type.css"
        ]
      }
    }
  },
  "categories": [
    "text"
  ],
  "type": "registry:ui"
}
