{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "meter",
  "title": "Meter",
  "description": "A segmented gauge with thresholds that change its tone and print a word.",
  "dependencies": [
    "@ui-sdk/react@0.1.0-beta.5"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/meter.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Meter as SdkMeter, MeterIndicator, MeterLabel, MeterTrack, MeterValue } from \"@ui-sdk/react/meter\"\nimport \"@/registry/cyber/ui/cyber/meter.css\"\n\ntype Status = \"low\" | \"high\"\n\n// A gauge: a measurement inside a known range, as a bar of segments with the\n// reading beside its label. Where a progress bar is a task and burns in the\n// accent, a gauge is a value, so it reads in the signal color.\n//\n// - `value`, `min`, `max`: the reading and its range (0 to 100 unless set).\n// - `low` and `high` are thresholds. At or under `low` the fill turns yellow\n//   and LOW is printed; at or over `high` it burns in the accent on a lit\n//   track and CRIT is printed. The zones are tinted on the track before the\n//   reading reaches them, like a redline, with a tick under each threshold.\n// - `lowLabel` and `highLabel` replace those words.\n// - `format`: without one the readout is the reading over the top of the\n//   range, \"10/50\". Pass Intl.NumberFormat options or a function of the value\n//   for a unit or a percentage, and the readout is that text alone.\n// - `segments`: how many steps the bar has.\nfunction Meter({\n  label,\n  value,\n  min = 0,\n  max = 100,\n  low,\n  high,\n  lowLabel = \"Low\",\n  highLabel = \"Crit\",\n  segments = 20,\n  format,\n  getValueLabel,\n  style,\n  ...props\n}: Omit<React.ComponentProps<typeof SdkMeter>, \"children\"> & {\n  label: string\n  low?: number\n  high?: number\n  lowLabel?: string\n  highLabel?: string\n  segments?: number\n}) {\n  const status: Status | undefined = high != null && value >= high ? \"high\" : low != null && value <= low ? \"low\" : undefined\n  const word = status === \"high\" ? highLabel : status === \"low\" ? lowLabel : undefined\n  const fraction = format == null\n  // Where a threshold sits along the track, as a percentage of the range.\n  const at = (point: number) => `${Math.min(100, Math.max(0, ((point - min) / (max - min || 1)) * 100))}%`\n  const marks = { \"--segments\": segments, \"--low\": low != null ? at(low) : undefined, \"--high\": high != null ? at(high) : undefined }\n\n  return (\n    <SdkMeter\n      data-kit=\"meter\"\n      data-status={status}\n      value={value}\n      min={min}\n      max={max}\n      format={format ?? { style: \"decimal\" }}\n      // The printed readout is hidden from screen readers, which get the\n      // reading from the gauge itself: the range and the word go in there too.\n      getValueLabel={\n        getValueLabel ??\n        ((current, details) => [fraction ? `${details.formatted} of ${details.max}` : details.formatted, word].filter(Boolean).join(\", \"))\n      }\n      style={(state) => ({ ...marks, ...(typeof style === \"function\" ? style(state) : style) }) as React.CSSProperties}\n      {...props}\n    >\n      <span data-kit=\"meter-head\">\n        <MeterLabel data-kit=\"label\">{label}</MeterLabel>\n        {word && <span data-kit=\"meter-status\">{word}</span>}\n        <MeterValue data-kit=\"meter-value\">\n          {(state) => (\n            <>\n              {state.text}\n              {fraction && <span data-kit=\"meter-max\">/{max}</span>}\n            </>\n          )}\n        </MeterValue>\n      </span>\n      <MeterTrack data-kit=\"meter-track\">\n        <MeterIndicator data-kit=\"meter-indicator\" />\n      </MeterTrack>\n      {(low != null || high != null) && (\n        <span data-kit=\"meter-scale\" aria-hidden>\n          {low != null && <span data-kit=\"meter-tick\" data-at=\"low\" data-passed={value <= low ? \"\" : undefined} />}\n          {high != null && <span data-kit=\"meter-tick\" data-at=\"high\" data-passed={value >= high ? \"\" : undefined} />}\n        </span>\n      )}\n    </SdkMeter>\n  )\n}\n\nexport { Meter }\n",
      "type": "registry:ui",
      "target": "@ui/meter.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/meter.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.ui {\n  /* One color for the reading, as --tone: the signal while it's nominal,\n     yellow at or under the low threshold, the accent at or over the high\n     one. Each of those also prints its word, so the tone is never the only\n     thing that changed. */\n  [data-skin=\"cyber\"] [data-kit=\"meter\"] {\n    --tone: var(--cy-signal);\n    --zone-low: color-mix(in srgb, var(--cy-flag) 30%, var(--cy-panel));\n    --zone-high: color-mix(in srgb, var(--cy-accent) 50%, var(--cy-panel));\n    --rest: color-mix(in srgb, var(--cy-signal) 20%, var(--cy-panel));\n\n    display: grid;\n    gap: 6px;\n    width: 100%;\n    min-width: 0;\n    text-align: start;\n\n    &[data-status=\"low\"] {\n      --tone: var(--cy-flag);\n    }\n    &[data-status=\"high\"] {\n      --tone: var(--cy-accent);\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"meter-head\"] {\n    display: flex;\n    align-items: baseline;\n    gap: 8px;\n    min-width: 0;\n\n    & [data-kit=\"label\"] {\n      flex: 1;\n      min-width: 0;\n      overflow: hidden;\n      text-overflow: ellipsis;\n      white-space: nowrap;\n    }\n  }\n\n  /* The word a threshold prints: a small solid tag in the tone, with a lamp\n     that isn't quite steady while the reading is critical. */\n  [data-skin=\"cyber\"] [data-kit=\"meter-status\"] {\n    flex: none;\n    display: inline-flex;\n    align-items: center;\n    gap: 5px;\n    align-self: center;\n    height: 16px;\n    padding-inline: 5px 7px;\n    font-size: var(--cy-text-xs);\n    font-weight: 700;\n    line-height: 1;\n    letter-spacing: 0.08em;\n    text-transform: uppercase;\n    color: var(--cy-on-solid);\n    background: var(--tone);\n    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0 100%);\n\n    &::before {\n      content: \"\";\n      width: 5px;\n      height: 5px;\n      background: currentColor;\n    }\n\n    [data-status=\"high\"] &::before {\n      animation: var(--cy-fx-flicker) 2.4s linear infinite;\n    }\n  }\n\n  /* The reading, with the top of its range dimmer after it. */\n  [data-skin=\"cyber\"] [data-kit=\"meter-value\"] {\n    flex: none;\n    font-family: var(--cy-mono);\n    font-size: var(--cy-text-xs);\n    font-variant-numeric: tabular-nums;\n    color: var(--cy-signal);\n\n    [data-status=\"low\"] & {\n      color: var(--cy-flag);\n    }\n    [data-status=\"high\"] & {\n      color: var(--cy-ink-hi);\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"meter-max\"] {\n    color: var(--cy-ink-mute);\n  }\n\n  /* The track is one strip, cut into segments by a mask (only the mask's\n     alpha counts, so its \"color\" is any opaque token). Under the fill, the\n     strip is tinted where the thresholds are: a yellow zone up to `low`, an\n     accent zone from `high`, so the redline shows before the reading gets\n     there. */\n  [data-skin=\"cyber\"] [data-kit=\"meter-track\"] {\n    --seg: calc(100% / var(--segments, 20));\n    --gap: 2px;\n    --on: var(--cy-void);\n    --dir: to right;\n\n    position: relative;\n    height: 12px;\n    background: linear-gradient(\n      var(--dir),\n      var(--zone-low) 0 var(--low, 0%),\n      var(--rest) var(--low, 0%) var(--high, 100%),\n      var(--zone-high) var(--high, 100%) 100%\n    );\n    mask-image: repeating-linear-gradient(var(--dir), var(--on) 0 calc(var(--seg) - var(--gap)), transparent calc(var(--seg) - var(--gap)) var(--seg));\n    /* Two pixels wider than the track, which pushes the gap after the last\n       segment out of sight. */\n    mask-size: calc(100% + var(--gap)) 100%;\n    mask-repeat: no-repeat;\n\n    &:dir(rtl) {\n      --dir: to left;\n      mask-position: right;\n    }\n\n    /* Critical: the whole track comes up, the way a lit fill does. */\n    [data-status=\"high\"] > & {\n      --rest: var(--cy-fill-active);\n      --zone-high: var(--cy-fill-flash);\n    }\n  }\n\n  /* The SDK sets the fill's width to the exact percentage. Pinning its\n     minimum and maximum to that value rounded to a whole segment makes it\n     step: a segment is lit or it isn't. Any reading above zero lights at\n     least one, so a small value never reads as none. */\n  [data-skin=\"cyber\"] [data-kit=\"meter-indicator\"] {\n    --lit: max(round(nearest, var(--meter-value), var(--seg)), min(calc(var(--meter-value) * 1000), var(--seg)));\n\n    height: 100%;\n    min-width: var(--lit);\n    max-width: var(--lit);\n    background: var(--tone);\n    transition: background-color var(--cy-t) linear;\n  }\n\n  /* Under the track: a tick at each threshold. Hollow until the reading\n     crosses it, solid in the tone once it has. */\n  [data-skin=\"cyber\"] [data-kit=\"meter-scale\"] {\n    position: relative;\n    display: block;\n    height: 5px;\n    margin-block-start: -3px;\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"meter-tick\"] {\n    position: absolute;\n    inset-block-start: 0;\n    width: 7px;\n    height: 5px;\n    translate: -50% 0;\n    background: var(--cy-ink-mute);\n    clip-path: polygon(50% 0, 100% 100%, 0 100%);\n\n    &[data-at=\"low\"] {\n      inset-inline-start: var(--low);\n    }\n    &[data-at=\"high\"] {\n      inset-inline-start: var(--high);\n    }\n    &[data-passed] {\n      background: var(--tone);\n    }\n\n    &:dir(rtl) {\n      translate: 50% 0;\n    }\n  }\n\n  /* Forced colors drop backgrounds, which is all a segment is: the track\n     gets an edge, and the fill becomes a solid system color. */\n  @media (forced-colors: active) {\n    [data-skin=\"cyber\"] [data-kit=\"meter-track\"] {\n      mask-image: none;\n      border: 1px solid CanvasText;\n    }\n    [data-skin=\"cyber\"] [data-kit=\"meter-indicator\"] {\n      background: Highlight;\n    }\n    [data-skin=\"cyber\"] [data-kit=\"meter-status\"] {\n      border: 1px solid CanvasText;\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/meter.css"
    }
  ],
  "type": "registry:ui"
}
