{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tempo",
  "title": "TempoProvider",
  "description": "Provides the viewer's animation tempo (auto, 12 on twos, 60 smooth, 0 still) to every FRAME/12 animation below it: controlled or persisted in localStorage, cross-tab, nested still always wins, layout-neutral (or asChild).",
  "registryDependencies": [
    "https://frame12.dev/r/frame12-styles.json",
    "https://frame12.dev/r/use-tempo.json"
  ],
  "files": [
    {
      "path": "ui/tempo.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport {\n  TempoContext,\n  normalizeTempo,\n  isTempo,\n  useReducedMotion,\n  type Tempo,\n  type TempoContextValue,\n} from '@/hooks/use-tempo';\n\nexport interface TempoProviderProps {\n  /** Controlled tempo. Pair with `onChange`. Wins over `defaultValue` (with a development warning). */\n  value?: Tempo;\n  /** Called with the new tempo whenever a TempoControl (or `setTempo`) inside changes it. */\n  onChange?: (tempo: Tempo) => void;\n  /** Uncontrolled starting tempo. Server render and first client render use it (or `auto`). */\n  defaultValue?: Tempo;\n  /** Uncontrolled only: persists the tempo in `localStorage` under this key and syncs across tabs. */\n  storageKey?: string;\n  /** Puts the `data-f12-tempo` attribute and motion class on the single child element instead of a wrapper. */\n  asChild?: boolean;\n  children?: React.ReactNode;\n}\n\nconst useIsoLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;\n\n// Bundlers (Next.js, webpack, Vite) statically replace `process.env.NODE_ENV`. Declared locally so\n// browser-only TypeScript consumers without @types/node still compile (as in panel.tsx).\ndeclare const process: { env: { NODE_ENV?: string } };\n\nconst isDev = (): boolean => {\n  try {\n    return process.env.NODE_ENV !== 'production';\n  } catch {\n    return false;\n  }\n};\n\nfunction readStored(key: string | undefined): Tempo | undefined {\n  if (!key) return undefined;\n  try {\n    const raw = window.localStorage.getItem(key);\n    return isTempo(raw) ? raw : undefined;\n  } catch {\n    return undefined;\n  }\n}\n\nfunction writeStored(key: string | undefined, tempo: Tempo): void {\n  if (!key) return;\n  try {\n    window.localStorage.setItem(key, tempo);\n  } catch {\n    // Storage can be full, disabled or blocked: the choice still applies for this page.\n  }\n}\n\n/** Keeps `<html data-f12-tempo>` (set before first paint by the first-paint script) current. */\nfunction syncDocumentTempo(tempo: Tempo): void {\n  if (typeof document === 'undefined') return;\n  const root = document.documentElement;\n  if (root.hasAttribute('data-f12-tempo') && root.getAttribute('data-f12-tempo') !== tempo) {\n    root.setAttribute('data-f12-tempo', tempo);\n  }\n}\n\n/**\n * Provides the viewer's animation tempo to every FRAME/12 animation below it.\n *\n * - The nearest provider sets `twos`/`ones`/`auto` for its subtree; `still` from any ancestor\n *   propagates down and cannot be undone by a nested provider. OS reduced motion always applies.\n * - Renders a layout-neutral `<div style=\"display: contents\">` (or, with `asChild`, decorates its\n *   one child) carrying `data-f12-tempo` and, when the tempo forces a mode, the matching\n *   `f12-m-*` class so CSS-only consumers follow it.\n */\nexport function TempoProvider({\n  value,\n  onChange,\n  defaultValue,\n  storageKey,\n  asChild = false,\n  children,\n}: TempoProviderProps) {\n  const parent = React.useContext(TempoContext);\n  const reduced = useReducedMotion();\n  const controlled = value !== undefined;\n\n  const warnedRef = React.useRef(false);\n  if (controlled && defaultValue !== undefined && !warnedRef.current && isDev()) {\n    warnedRef.current = true;\n    console.warn(\n      'TempoProvider: both `value` and `defaultValue` were given. `value` wins; remove `defaultValue` (or `value` to make it uncontrolled).',\n    );\n  }\n\n  const [internal, setInternal] = React.useState<Tempo>(() => normalizeTempo(defaultValue));\n  // True once the persisted value has been read (set in the same batch as `internal`).\n  const [loaded, setLoaded] = React.useState(false);\n\n  // The server and the hydrating client render `defaultValue` (or `auto`); the stored choice is\n  // read before the first paint, so there is no hydration mismatch and no flash of the default.\n  useIsoLayoutEffect(() => {\n    if (controlled || !storageKey) return;\n    const stored = readStored(storageKey);\n    if (stored) setInternal(stored);\n    setLoaded(true);\n    const onStorage = (e: StorageEvent) => {\n      if (e.key !== null && e.key !== storageKey) return;\n      setInternal(readStored(storageKey) ?? normalizeTempo(defaultValue));\n    };\n    window.addEventListener('storage', onStorage);\n    return () => window.removeEventListener('storage', onStorage);\n  }, [controlled, storageKey, defaultValue]);\n\n  const tempo: Tempo = controlled ? normalizeTempo(value) : internal;\n\n  // Only the outermost persisted provider owns the page-wide <html data-f12-tempo> (a nested\n  // provider must not turn motion off for the whole page). It syncs only once the stored value has\n  // been read: before that `tempo` still holds the default, and syncing would briefly flip a stored\n  // `still` (already written by the first-paint script) back to `auto`.\n  const ownsDocument = Boolean(storageKey) && !controlled && !parent.inProvider;\n  useIsoLayoutEffect(() => {\n    if (ownsDocument && loaded) syncDocumentTempo(tempo);\n  }, [ownsDocument, loaded, tempo]);\n\n  const onChangeRef = React.useRef(onChange);\n  onChangeRef.current = onChange;\n\n  const setTempo = React.useCallback(\n    (next: Tempo) => {\n      const t = normalizeTempo(next);\n      if (!controlled) {\n        setInternal(t);\n        writeStored(storageKey, t);\n      }\n      onChangeRef.current?.(t);\n    },\n    [controlled, storageKey],\n  );\n\n  const ancestorStill = parent.ancestorStill || (parent.inProvider && parent.tempo === 'still');\n\n  const ctx = React.useMemo<TempoContextValue>(\n    () => ({ tempo, setTempo, ancestorStill, inProvider: true }),\n    [tempo, setTempo, ancestorStill],\n  );\n\n  // The resolved mode for a context with no component base: `auto` adds no class.\n  const forced =\n    reduced || ancestorStill || tempo === 'still'\n      ? 'cut'\n      : tempo === 'twos'\n        ? 'stepped'\n        : tempo === 'ones'\n          ? 'smooth'\n          : null;\n  const motionClass = forced ? `f12-m-${forced}` : '';\n\n  let content: React.ReactElement;\n  if (asChild) {\n    const child = React.Children.only(children) as React.ReactElement<{\n      className?: string;\n      'data-f12-tempo'?: string;\n    }>;\n    const childClass = child.props.className ?? '';\n    content = React.cloneElement(child, {\n      className: [childClass, motionClass].filter(Boolean).join(' ') || undefined,\n      'data-f12-tempo': tempo,\n    });\n  } else {\n    content = (\n      <div style={{ display: 'contents' }} data-f12-tempo={tempo} className={motionClass || undefined}>\n        {children}\n      </div>\n    );\n  }\n\n  return <TempoContext.Provider value={ctx}>{content}</TempoContext.Provider>;\n}\n",
      "type": "registry:ui",
      "target": "components/frame12/tempo.tsx"
    }
  ],
  "type": "registry:ui"
}