{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "readout",
  "title": "Readout",
  "description": "A large numeral with a unit and a label that counts to its new value when it changes.",
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/readout.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { fxMoves } from \"@/registry/cyber/lib/fx\"\nimport { burst } from \"@/registry/cyber/lib/glitch\"\nimport \"@/registry/cyber/ui/cyber/readout.css\"\n\ntype Tone = \"signal\" | \"accent\" | \"flag\" | \"ok\"\ntype Size = \"sm\" | \"md\" | \"lg\"\n\n// The integer part in groups of three, and the decimals, of a number shown\n// to `precision` places. The sign is kept apart so \"-0.0\" never prints.\nfunction split(value: number, precision: number) {\n  const fixed = Math.abs(value).toFixed(precision)\n  const [whole, decimals] = fixed.split(\".\")\n  const groups: string[] = []\n  for (let end = whole.length; end > 0; end -= 3) groups.unshift(whole.slice(Math.max(0, end - 3), end))\n  return { negative: value < 0 && Number(fixed) !== 0, groups, decimals }\n}\n\n// A figure on a display: the whole number large, its decimals and unit\n// small beside it, in the signal color, over a short rule.\n//\n// When `value` changes the figure counts to the new number over a few\n// hundred milliseconds and slips its channels as it lands. With FX off it\n// simply changes. Assistive technology never hears the counting: it gets\n// the label and the final value as plain text.\n//\n// - `precision`: decimal places shown.\n// - `delta`: the change since last time. Prints ▲ or ▼ and the difference,\n//   and is read as \"up\" or \"down\".\n// - `tone`: \"signal\" for a value, \"accent\", \"flag\" for one to watch, \"ok\".\nfunction Readout({\n  value,\n  label,\n  unit,\n  prefix,\n  precision = 0,\n  delta,\n  size = \"md\",\n  tone = \"signal\",\n  ...props\n}: Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  value: number\n  label: string\n  unit?: string\n  /** A mark printed before the figure, like a currency sign. */\n  prefix?: string\n  precision?: number\n  delta?: number\n  size?: Size\n  tone?: Tone\n}) {\n  const [shown, setShown] = React.useState(value)\n  // Where the figure is right now, so a change that arrives mid-count\n  // carries on from there rather than jumping back.\n  const at = React.useRef(value)\n  const figure = React.useRef<HTMLSpanElement>(null)\n\n  React.useEffect(() => {\n    const from = at.current\n    if (from === value) return\n    if (!fxMoves() || !Number.isFinite(from) || !Number.isFinite(value)) {\n      at.current = value\n      setShown(value)\n      return\n    }\n    let frame = 0\n    let start = 0\n    const step = (now: number) => {\n      if (!start) start = now\n      const t = Math.min(1, (now - start) / 420)\n      // Fast at first, then settling: the last digits tick over slowly\n      // enough to read.\n      const current = t === 1 ? value : from + (value - from) * (1 - (1 - t) ** 3)\n      at.current = current\n      setShown(current)\n      if (t < 1) frame = requestAnimationFrame(step)\n      else if (figure.current) burst(figure.current, 300)\n    }\n    frame = requestAnimationFrame(step)\n    return () => cancelAnimationFrame(frame)\n  }, [value])\n\n  const { negative, groups, decimals } = split(shown, precision)\n  const change = delta == null ? null : Math.abs(delta).toFixed(precision)\n  const direction = delta == null ? null : delta > 0 ? \"up\" : delta < 0 ? \"down\" : \"flat\"\n  const spoken = [\n    `${prefix ? `${prefix} ` : \"\"}${value.toFixed(precision)}${unit ? ` ${unit}` : \"\"}`,\n    direction === \"flat\" ? \"no change\" : direction ? `${direction} ${change}` : null,\n  ]\n    .filter(Boolean)\n    .join(\", \")\n\n  return (\n    <div data-kit=\"readout\" data-size={size} data-tone={tone} data-counting={shown === value ? undefined : \"\"} {...props}>\n      <span data-kit=\"readout-label\">{label}</span>\n      <span data-sr-only>{spoken}</span>\n      <span data-kit=\"readout-line\" aria-hidden>\n        <span ref={figure} data-kit=\"readout-figure\">\n          {prefix && <span data-kit=\"readout-prefix\">{prefix}</span>}\n          <span data-kit=\"readout-whole\">\n            {negative && \"−\"}\n            {groups.map((group, index) => (\n              <span key={groups.length - index}>{group}</span>\n            ))}\n          </span>\n          {decimals && <span data-kit=\"readout-decimals\">.{decimals}</span>}\n          {unit && <span data-kit=\"readout-unit\">{unit}</span>}\n        </span>\n        {direction && (\n          <span data-kit=\"readout-delta\" data-direction={direction}>\n            {direction === \"up\" ? \"▲\" : direction === \"down\" ? \"▼\" : \"■\"} {change}\n          </span>\n        )}\n      </span>\n      <span data-kit=\"readout-rule\" aria-hidden />\n    </div>\n  )\n}\n\nexport { Readout }\nexport type { Size as ReadoutSize, Tone as ReadoutTone }\n",
      "type": "registry:ui",
      "target": "@ui/readout.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/readout.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.ui {\n  [data-skin=\"cyber\"] [data-kit=\"readout\"] {\n    --readout-color: var(--cy-signal);\n    --readout-size: var(--cy-text-2xl);\n\n    display: inline-grid;\n    gap: 3px;\n    justify-items: start;\n    min-width: 0;\n    text-align: start;\n\n    &[data-size=\"sm\"] {\n      --readout-size: var(--cy-text-xl);\n    }\n    &[data-size=\"lg\"] {\n      --readout-size: var(--cy-text-3xl);\n    }\n\n    &[data-tone=\"accent\"] {\n      --readout-color: var(--cy-ink);\n    }\n    &[data-tone=\"flag\"] {\n      --readout-color: var(--cy-flag);\n    }\n    &[data-tone=\"ok\"] {\n      --readout-color: var(--cy-ok);\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"readout-label\"] {\n    font-size: var(--cy-text-xs);\n    font-weight: 600;\n    line-height: 1.2;\n    letter-spacing: var(--cy-track);\n    text-transform: uppercase;\n    color: var(--cy-ink);\n  }\n\n  /* The figure and its delta share a baseline, and the delta drops under\n     the figure when a narrow column can't hold both. */\n  [data-skin=\"cyber\"] [data-kit=\"readout-line\"] {\n    display: flex;\n    flex-wrap: wrap;\n    align-items: baseline;\n    column-gap: 10px;\n    row-gap: 2px;\n    max-width: 100%;\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"readout-figure\"] {\n    display: inline-flex;\n    align-items: baseline;\n    font-family: var(--cy-mono);\n    font-variant-numeric: tabular-nums;\n    line-height: 1;\n    color: var(--readout-color);\n    white-space: nowrap;\n\n    /* It lands: the channels slip once (lib/glitch's burst). */\n    &[data-glitching] {\n      animation: var(--cy-fx-rgb) 300ms var(--cy-ease-snap);\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"readout-whole\"] {\n    display: inline-flex;\n    font-size: var(--readout-size);\n    font-weight: 600;\n    letter-spacing: -0.03em;\n\n    /* Thousands are set apart by a gap, never a separator character. */\n    & > span + span {\n      margin-inline-start: 0.22em;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"readout-decimals\"] {\n    font-size: max(var(--cy-text-xs), calc(var(--readout-size) * 0.52));\n    font-weight: 500;\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"readout-prefix\"] {\n    margin-inline-end: 0.3em;\n    font-size: max(var(--cy-text-xs), calc(var(--readout-size) * 0.62));\n    font-weight: 500;\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"readout-unit\"] {\n    margin-inline-start: 0.4em;\n    font-family: var(--cy-font);\n    font-size: max(var(--cy-text-xs), calc(var(--readout-size) * 0.46));\n    font-weight: 600;\n    letter-spacing: var(--cy-track);\n    text-transform: uppercase;\n  }\n\n  /* Up is green and points up, down is yellow and points down: the glyph\n     carries it, the color only agrees. */\n  [data-skin=\"cyber\"] [data-kit=\"readout-delta\"] {\n    font-family: var(--cy-mono);\n    font-size: var(--cy-text-xs);\n    font-variant-numeric: tabular-nums;\n    line-height: 1;\n    white-space: nowrap;\n    color: var(--cy-ink-mute);\n\n    &[data-direction=\"up\"] {\n      color: var(--cy-ok);\n    }\n    &[data-direction=\"down\"] {\n      color: var(--cy-flag);\n    }\n  }\n\n  /* The rule under it: a lit stub, then a row of dots running out. */\n  [data-skin=\"cyber\"] [data-kit=\"readout-rule\"] {\n    justify-self: stretch;\n    min-width: 56px;\n    height: 2px;\n    margin-block-start: 2px;\n    background:\n      linear-gradient(var(--readout-color), var(--readout-color)) left / 22px 100% no-repeat,\n      repeating-linear-gradient(to right, var(--cy-line-ctl) 0 2px, transparent 2px 6px) left 28px top 0 / calc(100% - 28px) 100% no-repeat;\n\n    &:dir(rtl) {\n      background-position:\n        right,\n        right 28px top 0;\n    }\n  }\n\n  /* While it counts, the stub runs the width of the rule's lit part. */\n  [data-skin=\"cyber\"] [data-kit=\"readout\"][data-counting] [data-kit=\"readout-rule\"] {\n    background-size:\n      100% 100%,\n      0 0;\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/readout.css"
    }
  ],
  "type": "registry:ui"
}
