{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "run-progress",
  "title": "Run progress",
  "description": "A custom property run from 0 to 1 on its own transition, read each frame for what CSS can’t draw, such as a number counting, so the feel, reduced motion and slow motion time it. Also registers custom properties once per page. Animated number, Highlight and the Line and Radar charts share it.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/resize.json"
  ],
  "files": [
    {
      "path": "registry/lib/run-progress.ts",
      "content": "import { runningTransitions, startRun, withoutTransition } from '@/registry/lib/resize'\n\nconst registered = new Set<string>()\n\n/**\n * Registers custom properties, so a transition can run them or so they\n * don't inherit. Once per page for each name.\n */\nexport function registerProperties(properties: readonly PropertyDefinition[]) {\n  if (typeof CSS === 'undefined' || !('registerProperty' in CSS)) return\n  for (const property of properties) {\n    if (registered.has(property.name)) continue\n    registered.add(property.name)\n    try {\n      CSS.registerProperty(property)\n    } catch (error) {\n      // A second copy of this file on the page has registered it already.\n      if (!(error instanceof DOMException && error.name === 'InvalidModificationError')) {\n        throw error\n      }\n    }\n  }\n}\n\n/** Registers `name` as a number from 0 to 1 that a transition can run, resting at 1. */\nexport function registerProgress(name: string) {\n  registerProperties([{ name, syntax: '<number>', inherits: false, initialValue: '1' }])\n}\n\n/** How far `element`'s progress `name` is, read from its transition; 1 once nothing runs it. */\nexport function progressOf(element: Element, name: string): number {\n  const value = Number.parseFloat(getComputedStyle(element).getPropertyValue(name))\n  return Number.isFinite(value) ? value : 1\n}\n\n/**\n * Runs `element`'s progress `name` from 0 to 1 on its own transition, and\n * calls `frame` with it every frame, then with 1 and `done`. A run started\n * later on the same element ends this one. With no transition, as under\n * reduced motion, it calls `frame` with 1 at once. Kept outside components:\n * the React Compiler drops a forced style read written inside one.\n */\nexport function runProgress(\n  element: HTMLElement | SVGElement,\n  name: string,\n  frame: (progress: number, done: boolean) => void,\n) {\n  const latest = startRun(element)\n  withoutTransition(element, () => element.style.setProperty(name, '0'))\n  element.style.setProperty(name, '1')\n  const step = () => {\n    if (!latest()) return\n    if (runningTransitions(element, { property: name }).length === 0) {\n      frame(1, true)\n      return\n    }\n    frame(progressOf(element, name), false)\n    requestAnimationFrame(step)\n  }\n  step()\n}\n\n/** Ends the run on `element`, if any, where it is. */\nexport function stopProgress(element: Element) {\n  startRun(element)\n}\n",
      "type": "registry:lib",
      "target": "@lib/run-progress.ts"
    }
  ],
  "type": "registry:lib"
}