{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tick-strip",
  "title": "Tick Strip",
  "description": "Dense strip of uniform ticks for recent samples, such as CPU or memory load.",
  "dependencies": [
    "class-variance-authority@^0.7.1"
  ],
  "registryDependencies": [
    "@pestoui/style",
    "@pestoui/utils"
  ],
  "files": [
    {
      "path": "pestoui/components/tick-strip.tsx",
      "content": "import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\n\n/* Dense sample strip — the CPU / Memory / Disk I/O meters along the top of an\n   ops console. Not a bar chart: the ticks are uniform width and packed to a\n   hairline gap, so the strip reads as one texture whose shape is the trend,\n   rather than as N discrete bars each asking to be read individually.\n\n   Spans, not SVG. Sixty-odd elements is exactly the size where CSS wins twice —\n   no viewBox arithmetic to keep in sync with the box, and every tick inherits\n   its colour from a semantic utility instead of needing a fill piped in.\n\n   The container is transparent and carries only the ceiling that ticks measure\n   against plus the gap that stops them fusing into a solid block, so one strip\n   drops onto card, muted or surface without bringing a background with it.\n\n   `justify-end` under a clipped overflow is the rolling-window contract: when\n   the strip is narrower than its series, the samples pushed out are the oldest\n   ones. Losing the left edge of a live meter is survivable; losing the reading\n   that just arrived is not. */\nconst tickStripVariants = cva(\n  \"inline-flex max-w-full items-end justify-end overflow-hidden\",\n  {\n    variants: {\n      size: {\n        sm: \"h-3 gap-px\",\n        default: \"h-5 gap-px\",\n        lg: \"h-8 gap-0.5\",\n      },\n    },\n    defaultVariants: {\n      size: \"default\",\n    },\n  }\n)\n\n/* Height and opacity both ride the same value, and the redundancy is the whole\n   reason this reads at 20px tall: across that range the difference between the\n   60th and the 90th percentile is three pixels, and three pixels is not a\n   reading. The alpha step is what actually carries it — height alone would\n   need the strip to be twice as tall to say the same thing.\n\n   No transition. A meter like this repaints on every poll, and when the window\n   rolls one slot every tick changes height at once — animating that makes the\n   whole strip ripple instead of showing one new sample arriving, and it costs\n   sixty simultaneous property animations to do it.\n\n   `rounded-full` is not a style choice: the surface scale starts at 9.6px\n   (`--radius-sm`), which would swallow a 2px tick whole, so it is the only\n   radius in the system this element can legally take. At these widths it lands\n   as a softened cap rather than a pill. */\nconst tickStripTickVariants = cva(\"min-h-px shrink-0 rounded-full\", {\n  variants: {\n    tone: {\n      selected: \"bg-selected\",\n      success: \"bg-success\",\n      warning: \"bg-warning\",\n      destructive: \"bg-destructive\",\n      info: \"bg-info\",\n      muted: \"bg-muted-foreground\",\n      \"chart-1\": \"bg-chart-1\",\n      \"chart-2\": \"bg-chart-2\",\n      \"chart-3\": \"bg-chart-3\",\n      \"chart-4\": \"bg-chart-4\",\n      \"chart-5\": \"bg-chart-5\",\n    },\n    size: {\n      sm: \"w-px\",\n      default: \"w-0.5\",\n      lg: \"w-1\",\n    },\n  },\n  defaultVariants: {\n    tone: \"selected\",\n    size: \"default\",\n  },\n})\n\ntype TickStripTone = NonNullable<VariantProps<typeof tickStripTickVariants>[\"tone\"]>\n\ntype TickStripSize = NonNullable<VariantProps<typeof tickStripVariants>[\"size\"]>\n\n/* Four bands, not a continuous ramp. Sixty ticks on a continuous alpha give\n   sixty near-identical values that the eye resolves as noise; quantising lets\n   it group the strip into regions, and two neighbours that differ by a\n   rounding error paint identically instead of shimmering against each other. */\nconst TICK_ALPHA = [0.35, 0.55, 0.75, 1] as const\n\n/* The floor of the height range, not a clamp on it. `Math.max(floor, n)` would\n   flatten every low sample into one identical stub and destroy the ordering at\n   the bottom of the scale, which is precisely where an idle meter spends its\n   time. Remapping into [floor, 1] keeps a zero visible as a baseline stub while\n   a 2% sample still sits measurably above it. */\nconst TICK_FLOOR = 0.12\n\n/* Integers stay integers so a percentage series doesn't get spoken as \"72.0\". */\nfunction formatReading(value: number) {\n  return Number.isInteger(value) ? value.toString() : value.toFixed(1)\n}\n\ntype TickStripProps = Omit<React.ComponentProps<\"div\">, \"children\"> &\n  VariantProps<typeof tickStripVariants> & {\n    /** The series, oldest sample first. Non-finite entries read as 0. */\n    data: number[]\n    tone?: TickStripTone\n    /** Pins the scale. Omit to normalise against the series' own peak. */\n    max?: number\n    /**\n     * Samples at or above this take the destructive tone whatever `tone` says,\n     * so a spike reads as a spike. Compared against raw values, not normalised\n     * ones — a threshold is stated in the units the caller thinks in.\n     */\n    threshold?: number\n    /** Names the series in the spoken summary — \"CPU\", \"Disk I/O\". */\n    srLabel?: string\n    /** Formats the readings in the summary. Units belong here. */\n    formatValue?: (value: number) => string\n  }\n\nfunction TickStrip({\n  data,\n  tone = \"selected\",\n  size = \"default\",\n  max,\n  threshold,\n  srLabel,\n  formatValue = formatReading,\n  className,\n  \"aria-label\": ariaLabel,\n  ...props\n}: TickStripProps) {\n  /* One NaN anywhere would poison the peak and drop every tick to its floor at\n     once — a strip that silently flatlines is a worse failure than one that\n     admits a bad sample as zero. Negatives clamp for the same reason: this\n     encodes intensity and has no mirrored baseline to draw them against. */\n  const values = data.map((value) =>\n    Number.isFinite(value) ? Math.max(0, value) : 0\n  )\n\n  const peak = values.reduce((highest, value) => Math.max(highest, value), 0)\n  const scale = max ?? peak\n  /* A zero or non-finite scale divides by zero, and NaN paints nothing at all.\n     Read the series as empty instead, so the strip shows its baseline. */\n  const usableScale = Number.isFinite(scale) && scale > 0\n  const current = values.length > 0 ? values[values.length - 1] : 0\n\n  /* Infinity when unset keeps the per-tick test a single comparison instead of\n     a branch that runs on every element — nothing is ever at or above it. */\n  const limit =\n    typeof threshold === \"number\" && Number.isFinite(threshold)\n      ? threshold\n      : Number.POSITIVE_INFINITY\n  const breaches = values.filter((value) => value >= limit).length\n\n  const readings = [`${formatValue(current)} current`, `${formatValue(peak)} peak`]\n  if (Number.isFinite(limit)) {\n    readings.push(\n      `${breaches} of ${values.length} at or above ${formatValue(limit)}`\n    )\n  }\n\n  /* The ticks themselves say nothing to a screen reader — role=\"img\" prunes the\n     subtree, which is the point: sixty spans announced one by one is worse than\n     silence. srLabel is the entire non-visual reading of this component, so\n     it carries the two numbers a glance at the strip would give you. */\n  const summary = values.length === 0 ? \"No data\" : readings.join(\", \")\n\n  return (\n    <div\n      data-slot=\"tick-strip\"\n      data-tone={tone}\n      data-size={size}\n      role=\"img\"\n      aria-label={ariaLabel ?? (srLabel ? `${srLabel}: ${summary}` : summary)}\n      className={cn(tickStripVariants({ size }), className)}\n      {...props}\n    >\n      {values.map((value, index) => {\n        const norm = usableScale ? Math.min(1, value / scale) : 0\n        const breached = value >= limit\n        const band = Math.min(\n          TICK_ALPHA.length - 1,\n          Math.floor(norm * TICK_ALPHA.length)\n        )\n\n        return (\n          <span\n            key={index}\n            data-slot=\"tick-strip-tick\"\n            className={cn(\n              tickStripTickVariants({\n                tone: breached ? \"destructive\" : tone,\n                size,\n              })\n            )}\n            style={{\n              height: `${((TICK_FLOOR + (1 - TICK_FLOOR) * norm) * 100).toFixed(2)}%`,\n              /* A breach is pinned opaque rather than taking its band. With a\n                 low threshold the crossing sample can be dim enough that the\n                 tone change alone doesn't register, and the one tick that most\n                 needs to be seen is the one that must never be faded. */\n              opacity: breached ? 1 : TICK_ALPHA[band],\n            }}\n          />\n        )\n      })}\n    </div>\n  )\n}\n\nexport { TickStrip, tickStripVariants, tickStripTickVariants }\nexport type { TickStripProps, TickStripSize, TickStripTone }\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}