{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "level-meter",
  "title": "LevelMeter",
  "description": "A small live input level: a row of bars that light from the start edge as a microphone picks up sound, so the person can tell it hears them before anyone else does (before joining a call, in a device menu, in a \"test your microphone\" row).",
  "registryDependencies": [
    "@ouro/ax-component",
    "@ouro/lib-appearance-hints",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-tones",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/level-meter/level-meter-styles.ts",
      "content": "export {\n  ATTACK_MS,\n  barClass,\n  BARS_DEFAULT,\n  BARS_MAX,\n  BARS_MIN,\n  bandFor,\n  bandValues,\n  barSizes,\n  DB_FLOOR,\n  HOLD_MS,\n  levelFromAmplitude,\n  levelMeterAx,\n  litTones,\n  LOUD_FROM,\n  mutedLit,\n  QUIET_BELOW,\n  READ_EVERY_MS,\n  RELEASE_MS,\n  rowSizes,\n  stepToward,\n  type LevelMeterBand,\n  type LevelMeterValueText,\n};\n\n// Values, the level's arithmetic, class strings and the agent side for LevelMeter, apart from the\n// component so its file exports only components (React Fast Refresh). Class strings are literal so\n// the app's Tailwind finds them when it compiles.\n\nimport { defineComponentAx } from \"@/registry/ouro/ax/component\";\n\n/** How many bars a meter draws without `bars`. @internal */\nconst BARS_DEFAULT = 8;\n/**\n * The fewest bars a meter draws. @internal\n * @claim \"The fewest bars a meter draws.\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > draws 8 bars by default, or the nearest whole number from 3 to 24)\n */\nconst BARS_MIN = 3;\n/**\n * The most bars a meter draws. @internal\n * @claim \"The most bars a meter draws.\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > draws 8 bars by default, or the nearest whole number from 3 to 24)\n */\nconst BARS_MAX = 24;\n\n/**\n * The quietest level the meter shows, in dBFS: an amplitude at or below it lights no bar, and full\n * scale (0 dBFS) lights them all. @internal\n * @claim \"The quietest level the meter shows, in\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > maps a linear amplitude to the bars on a decibel scale from -60 dBFS to 0, so speech lights 3 to 5 of 8 bars)\n */\nconst DB_FLOOR = -60;\n\n/**\n * The meter's level, from 0 to 1, for a linear amplitude from 0 to 1 (an RMS, as an analyser gives\n * it): its decibels from {@link DB_FLOOR} to 0, as a share of that range. Silence, a negative\n * amplitude and one that is not a number are 0; full scale and above is 1. @internal\n * @claim \"Silence, a negative amplitude and one\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > maps a linear amplitude to the bars on a decibel scale from -60 dBFS to 0, so speech lights 3 to 5 of 8 bars)\n * @claim \"The meter's level, from 0 to 1,\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > maps a linear amplitude to the bars on a decibel scale from -60 dBFS to 0, so speech lights 3 to 5 of 8 bars)\n */\nfunction levelFromAmplitude(amplitude: number): number {\n  // Silence is -Infinity dB, which clamps to 0; a negative amplitude or NaN has no logarithm (NaN), which reads as 0.\n  return Math.min(Math.max((20 * Math.log10(amplitude) - DB_FLOOR) / -DB_FLOOR, 0), 1) || 0;\n}\n\n/**\n * Below this level (-48 dBFS) the meter reads \"Quiet\". @internal\n * @claim \"Below this level (-48 dBFS) the meter\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > reads Quiet below -48 dBFS, Speaking up to -12 dBFS and Loud from there, in words valueText translates)\n */\nconst QUIET_BELOW = 0.2;\n/**\n * From this level on (-12 dBFS) the meter reads \"Loud\". @internal\n * @claim \"From this level on (-12 dBFS) the\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > reads Quiet below -48 dBFS, Speaking up to -12 dBFS and Loud from there, in words valueText translates)\n */\nconst LOUD_FROM = 0.8;\n\n/**\n * The words a meter's level is read as, one for each band of level, and one for a muted microphone.\n * @claim \"The words a meter's level is read\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > reads Quiet below -48 dBFS, Speaking up to -12 dBFS and Loud from there, in words valueText translates)\n * @claim \"and one for a muted microphone.\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > dims its lit bars while muted, still showing the level, and reads Muted with a value of 0)\n */\ninterface LevelMeterValueText {\n  /**\n   * Below -48 dBFS, silence included: \"Quiet\".\n   * @claim \"Below -48 dBFS, silence included:\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > reads Quiet below -48 dBFS, Speaking up to -12 dBFS and Loud from there, in words valueText translates)\n   */\n  quiet: string;\n  /**\n   * From -48 dBFS up to -12 dBFS, where speech sits: \"Speaking\".\n   * @claim \"From -48 dBFS up to -12 dBFS,\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > reads Quiet below -48 dBFS, Speaking up to -12 dBFS and Loud from there, in words valueText translates)\n   */\n  speaking: string;\n  /**\n   * From -12 dBFS up: \"Loud\".\n   * @claim \"From -12 dBFS up:\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > reads Quiet below -48 dBFS, Speaking up to -12 dBFS and Loud from there, in words valueText translates)\n   */\n  loud: string;\n  /**\n   * While `muted`, whatever the level: \"Muted\".\n   * @claim \"While `muted`, whatever the level:\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > dims its lit bars while muted, still showing the level, and reads Muted with a value of 0)\n   */\n  muted: string;\n}\n\n/** A band of level, read as one word. @internal */\ntype LevelMeterBand = \"quiet\" | \"speaking\" | \"loud\";\n\n/**\n * The band a meter level from 0 to 1 falls in. @internal\n * @claim \"The band a meter level from 0\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > reads Quiet below -48 dBFS, Speaking up to -12 dBFS and Loud from there, in words valueText translates)\n */\nfunction bandFor(level: number): LevelMeterBand {\n  if (level < QUIET_BELOW) return \"quiet\";\n  return level < LOUD_FROM ? \"speaking\" : \"loud\";\n}\n\n/**\n * The value screen readers get for each band, the middle of the band as a percentage, so it\n * changes only when the word does. A muted meter's value is 0. @internal\n * @claim \"The value screen readers get for each\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > is a meter named by its label, from 0 to 100, its value the middle of its word's band)\n * @claim \"A muted meter's value is 0.\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > dims its lit bars while muted, still showing the level, and reads Muted with a value of 0)\n */\nconst bandValues = { quiet: 10, speaking: 50, loud: 90, muted: 0 } as const;\n\n/**\n * How fast the bars rise toward a louder level: the time constant, in milliseconds. @internal\n * @claim \"How fast the bars rise toward a\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > rises within about 50 ms and falls over about 350 ms, the same with reduced motion)\n */\nconst ATTACK_MS = 50;\n/**\n * How slowly the bars fall toward a quieter level, so they hold between syllables: the time\n * constant, in milliseconds. @internal\n * @claim \"How slowly the bars fall toward a\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > rises within about 50 ms and falls over about 350 ms, the same with reduced motion)\n */\nconst RELEASE_MS = 350;\n\n/**\n * The shown level `elapsed` milliseconds on from `shown`, moving toward `goal`: fast when it rises\n * and slowly when it falls, as an audio meter's ballistics do. @internal\n * @claim \"The shown level `elapsed` milliseconds on from\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > rises within about 50 ms and falls over about 350 ms, the same with reduced motion)\n */\nfunction stepToward(shown: number, goal: number, elapsed: number): number {\n  // Stryker disable next-line EqualityOperator: when goal equals shown, either constant gives goal.\n  const constant = goal > shown ? ATTACK_MS : RELEASE_MS;\n  return goal + (shown - goal) * Math.exp(-elapsed / constant);\n}\n\n/**\n * How far back the reading screen readers hear looks for the loudest level, in milliseconds. @internal\n * @claim \"How far back the reading screen readers\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > holds its reading at the loudest level of the last 1.5 seconds, so a pause after speech still reads Speaking)\n */\nconst HOLD_MS = 1500;\n/**\n * How often the reading screen readers hear may change, in milliseconds. @internal\n * @claim \"How often the reading screen readers hear\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > changes its ARIA values only when its word changes, and at most twice a second)\n */\nconst READ_EVERY_MS = 500;\n\n/**\n * The row of bars at each size: its height and the gap between bars. @internal\n * @claim \"The row of bars at each size:\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > draws bars 12, 16 and 24px high, md by default)\n */\nconst rowSizes = { sm: \"h-3 gap-0.5\", md: \"h-4 gap-1\", lg: \"h-6 gap-1\" } as const;\n\n/**\n * One bar's width at each size. @internal\n * @claim \"One bar's width at each size.\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > draws bars 12, 16 and 24px high, md by default)\n */\nconst barSizes = { sm: \"w-1\", md: \"w-1.5\", lg: \"w-2\" } as const;\n\n/**\n * A bar: a pill the row's full height, filled in the input colour while unlit, a quiet track with\n * no outline, and in the tone while lit (`data-highlighted`). Nothing moves or scales: a bar's\n * colours cross-fade, in a third of `--ouro-duration-fast` as it lights and over\n * `--ouro-duration-fast` as it goes out, the same with reduced motion. With more contrast an unlit\n * bar is outlined in the muted foreground. Under forced colours its edge is CanvasText and a lit bar\n * is Highlight. @internal\n * @claim \"Nothing moves or scales: a bar's colours\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter motion > cross-fades a bar as it lights in a third of --ouro-duration-fast, the same with reduced motion, and nothing moves or scales)\n * @claim \"filled in the input colour while unlit,\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > lights its bars in the tone's colour, success by default, and draws unlit bars as a quiet filled track)\n * @claim \"With more contrast an unlit bar is\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > outlines unlit bars in the muted foreground with more contrast)\n * @claim \"Under forced colours its edge is CanvasText\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > keeps an edge on every bar under forced colours, and fills a lit bar with Highlight)\n */\nconst barClass =\n  \"relative block h-full shrink-0 rounded-full box-border border border-solid border-transparent bg-input \" +\n  \"transition-[background-color,border-color] duration-(--ouro-duration-fast) ease-[ease] \" +\n  \"data-highlighted:duration-[calc(var(--ouro-duration-fast)/3)] contrast-more:not-data-highlighted:border-muted-foreground \" +\n  \"forced-colors:border-[CanvasText] forced-colors:bg-transparent forced-colors:data-highlighted:border-[Highlight] forced-colors:data-highlighted:bg-[Highlight]\";\n\n/**\n * A lit bar's colour for each tone. @internal\n * @claim \"A lit bar's colour for each tone.\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > lights its bars in the tone's colour, success by default, and draws unlit bars as a quiet filled track)\n */\nconst litTones = {\n  primary: \"data-highlighted:border-primary data-highlighted:bg-primary\",\n  secondary: \"data-highlighted:border-muted-foreground data-highlighted:bg-muted-foreground\",\n  destructive: \"data-highlighted:border-destructive data-highlighted:bg-destructive\",\n  success: \"data-highlighted:border-success data-highlighted:bg-success\",\n  warning: \"data-highlighted:border-warning data-highlighted:bg-warning\",\n} as const;\n\n/**\n * A lit bar's colour while muted, whatever the tone: the muted foreground, and GrayText under\n * forced colours. @internal\n * @claim \"A lit bar's colour while muted, whatever\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > dims its lit bars while muted, still showing the level, and reads Muted with a value of 0)\n */\nconst mutedLit =\n  \"data-highlighted:border-muted-foreground data-highlighted:bg-muted-foreground \" +\n  \"forced-colors:data-highlighted:border-[GrayText] forced-colors:data-highlighted:bg-[GrayText]\";\n\n/**\n * LevelMeter's agent side, declared with Ouro AX's `defineComponentAx`. It declares no reads and no\n * actions: audio levels stay with the person.\n *\n * @example\n * levelMeterAx.reads.length; // 0\n * @claim \"It declares no reads and no\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > declares no agent reads and no actions)\n */\nconst levelMeterAx = defineComponentAx({ component: \"LevelMeter\", reads: [], actions: [] });\n",
      "type": "registry:ui",
      "target": "@components/ouro/level-meter/level-meter-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/level-meter/level-meter.tsx",
      "content": "\"use client\";\n\nimport { memo, useEffect, useId, useRef, useState, type JSX, type Ref } from \"react\";\nimport {\n  bandFor,\n  bandValues,\n  barClass,\n  BARS_DEFAULT,\n  BARS_MAX,\n  BARS_MIN,\n  barSizes,\n  HOLD_MS,\n  levelFromAmplitude,\n  litTones,\n  mutedLit,\n  READ_EVERY_MS,\n  rowSizes,\n  stepToward,\n  type LevelMeterBand,\n  type LevelMeterValueText,\n} from \"@/registry/ouro/components/ouro/level-meter/level-meter-styles\";\nimport { toneFor } from \"@/registry/ouro/lib/ouro/appearance-hints\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { toneWarning } from \"@/registry/ouro/lib/ouro/tones\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\nexport type { LevelMeterValueText };\n\n/** Props for {@link LevelMeter}. */\nexport interface LevelMeterProps {\n  /**\n   * The microphone's linear amplitude now, from 0 (silence) to 1 (full scale): the RMS of the\n   * samples an `AnalyserNode` gives, fed up to about 15 times a second. The meter maps it to its\n   * bars on a decibel scale from -60 dBFS (no bar) to 0 dBFS (every bar), so ordinary speech,\n   * around -40 to -20 dBFS, lights 3 to 5 of 8 bars. An amplitude below 0 or not a number shows as\n   * silence, and one above 1 as full scale. To get it: `analyser.getFloatTimeDomainData(samples)`,\n   * then `Math.sqrt(samples.reduce((sum, sample) => sum + sample * sample, 0) / samples.length)`.\n   * @claim \"The microphone's linear amplitude now, from\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > maps a linear amplitude to the bars on a decibel scale from -60 dBFS to 0, so speech lights 3 to 5 of 8 bars)\n   * @claim \"The meter maps it to its\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > maps a linear amplitude to the bars on a decibel scale from -60 dBFS to 0, so speech lights 3 to 5 of 8 bars)\n   * @claim \"An amplitude below 0 or not a\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > shows an amplitude outside 0 to 1, or not a number, as silence or full scale, and says so in development)\n   */\n  value: number;\n  /** What the meter measures: \"Microphone level\". It names the meter for screen readers. */\n  label: string;\n  /**\n   * Hides the label visually; screen readers still use it.\n   * @claim \"Hides the label visually; screen readers\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > hides the label visually with hideLabel, and keeps the name)\n   */\n  hideLabel?: boolean | undefined;\n  /**\n   * How many bars to draw, a whole number from 3 to 24. A number outside that, or with a\n   * fraction, draws the nearest one.\n   * @default 8\n   * @claim \"How many bars to draw, a\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > draws 8 bars by default, or the nearest whole number from 3 to 24)\n   * @claim \"A number outside that, or with\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > draws 8 bars by default, or the nearest whole number from 3 to 24)\n   */\n  bars?: number | undefined;\n  /**\n   * The meter's size: bars 12px, 16px or 24px high. `sm` fits a menu row.\n   * @default \"md\"\n   * @claim \"The meter's size: bars 12px, 16px\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > draws bars 12, 16 and 24px high, md by default)\n   */\n  size?: \"sm\" | \"md\" | \"lg\" | (string & { 'Use \"sm\", \"md\" or \"lg\"': never }) | undefined;\n  /**\n   * Color role from the theme for the lit bars, named after its token. Unlit bars are always a\n   * quiet track in the input colour, so a silent meter is quiet whatever its tone. `secondary`\n   * fills lit bars in the muted foreground, as `muted` does.\n   * @default \"success\"\n   * @claim \"Unlit bars are always a quiet track\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > lights its bars in the tone's colour, success by default, and draws unlit bars as a quiet filled track)\n   */\n  tone?:\n    | \"primary\"\n    | \"secondary\"\n    | \"destructive\"\n    | \"success\"\n    | \"warning\"\n    | (string & { 'danger is \"destructive\"; accent is \"primary\"; neutral is \"secondary\"': never })\n    | undefined;\n  /**\n   * The microphone is muted: the lit bars dim to the muted foreground, whatever the tone, and still\n   * follow `value`, so the person can tell the microphone hears them while nobody else does.\n   * Screen readers hear \"Muted\" (`valueText.muted`) and a value of 0, whatever the level.\n   * @claim \"The microphone is muted: the lit bars\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > dims its lit bars while muted, still showing the level, and reads Muted with a value of 0)\n   * @claim \"and a value of 0, whatever the level.\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > dims its lit bars while muted, still showing the level, and reads Muted with a value of 0)\n   */\n  muted?: boolean | undefined;\n  /**\n   * The words screen readers hear for the loudest level of the last 1.5 seconds: below -48\n   * dBFS, up to -12 dBFS, and from there, and the word while `muted`. Translate them with the\n   * rest of your interface.\n   * @default { quiet: \"Quiet\", speaking: \"Speaking\", loud: \"Loud\", muted: \"Muted\" }\n   * @claim \"The words screen readers hear for\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > reads Quiet below -48 dBFS, Speaking up to -12 dBFS and Loud from there, in words valueText translates)\n   * @claim \"The words screen readers hear for\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > holds its reading at the loudest level of the last 1.5 seconds, so a pause after speech still reads Speaking)\n   */\n  valueText?: LevelMeterValueText | undefined;\n  /** Layout only: margins, grid placement (`mt-2`, `ms-auto`). Appearance classes warn in development; use `tone` and `size`. */\n  className?: string | undefined;\n  /** The meter's id, for `aria-describedby` elsewhere on the page. */\n  id?: string | undefined;\n  ref?: Ref<HTMLDivElement> | undefined;\n\n  /** Not a prop. The amplitude is `value`: `<LevelMeter value={rms}>`. */\n  level?: { 'Use <LevelMeter value={rms}>': never };\n  /**\n   * Not a prop. `value` is an amplitude from 0 to 1: `<LevelMeter value={rms}>`.\n   * @claim \"`value` is an amplitude from 0 to\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > shows an amplitude outside 0 to 1, or not a number, as silence or full scale, and says so in development)\n   */\n  max?: { 'value is an amplitude from 0 to 1: <LevelMeter value={rms}>': never };\n  /** Not a prop. Ouro UI uses `bars`: `<LevelMeter bars={8}>`. */\n  segments?: { 'Use <LevelMeter bars={8}>': never };\n  /** Not a prop. Ouro UI uses `tone`: `<LevelMeter tone=\"success\">`. */\n  color?: { 'Use <LevelMeter tone=\"success\">': never };\n}\n\nconst defaultValueText: LevelMeterValueText = { quiet: \"Quiet\", speaking: \"Speaking\", loud: \"Loud\", muted: \"Muted\" };\n\n/**\n * The level the bars show: `level` followed with an audio meter's ballistics, fast up and slow\n * down, on animation frames while it moves. It re-renders only when the number of lit bars changes.\n */\nfunction useShownLevel(level: number, bars: number): number {\n  const [shown, setShown] = useState(level);\n  const current = useRef(level);\n  const drawn = useRef(level);\n  useEffect(() => {\n    let frame = 0;\n    let last = performance.now();\n    const tick = () => {\n      const now = performance.now();\n      current.current = stepToward(current.current, level, now - last);\n      last = now;\n      if (Math.round(current.current * bars) !== Math.round(drawn.current * bars)) {\n        drawn.current = current.current;\n        setShown(current.current);\n      }\n      // On the way to the goal the lit bars stop changing once they match the goal's.\n      if (Math.round(current.current * bars) !== Math.round(level * bars)) frame = requestAnimationFrame(tick);\n    };\n    frame = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(frame);\n  }, [level, bars]);\n  return shown;\n}\n\n/**\n * The band screen readers hear: that of the loudest level of the last `HOLD_MS`, checked every\n * `READ_EVERY_MS`, so a pause after speech still reads as speech, and the ARIA values change only\n * when the band does, at most twice a second.\n * @claim \"The band screen readers hear: that of\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > holds its reading at the loudest level of the last 1.5 seconds, so a pause after speech still reads Speaking)\n * @claim \"The band screen readers hear: that of\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > changes its ARIA values only when its word changes, and at most twice a second)\n */\nfunction useReading(level: number): LevelMeterBand {\n  const [band, setBand] = useState(() => bandFor(level));\n  const latest = useRef(level);\n  // Stryker disable next-line ArrayDeclaration: the first check drops every entry without a time before it reads one.\n  const heard = useRef<Array<readonly [time: number, level: number]>>([]);\n  useEffect(() => {\n    latest.current = level;\n    heard.current.push([performance.now(), level]);\n  }, [level]);\n  useEffect(() => {\n    const timer = setInterval(() => {\n      const now = performance.now();\n      heard.current = heard.current.filter(([time]) => now - time <= HOLD_MS);\n      const loudest = heard.current.reduce((most, [, past]) => Math.max(most, past), latest.current);\n      // The same band bails out of the render, so nothing changes until the word does.\n      setBand(bandFor(loudest));\n    }, READ_EVERY_MS);\n    return () => clearInterval(timer);\n  },\n  // Stryker disable next-line ArrayDeclaration: any constant dependency list starts the check once, as this one does.\n  []);\n  return band;\n}\n\ninterface BarProps {\n  lit: boolean;\n  className: string;\n}\n\n// Memoised: a new count of lit bars re-renders only the bars that light or go out.\nconst Bar = memo(function Bar({ lit, className }: BarProps): JSX.Element {\n  return <span data-ouro-part=\"segment\" data-highlighted={lit ? \"\" : undefined} className={className} />;\n});\n\n/**\n * A small live input level: a row of bars that light from the start edge as a microphone picks up\n * sound, so the person can tell it hears them before anyone else does (before joining a call, in\n * a device menu, in a \"test your microphone\" row). The app feeds `value`, the microphone's linear\n * amplitude from 0 to 1, as often as about 15 times a second, and the meter maps it to its bars on\n * a decibel scale, so ordinary speech lights about half of them. To get the amplitude, read an\n * `AnalyserNode`'s samples with `getFloatTimeDomainData(samples)` and take their RMS:\n * `Math.sqrt(samples.reduce((sum, sample) => sum + sample * sample, 0) / samples.length)`.\n *\n * The bars move as an audio meter's do: they rise within about 50 ms and fall over about 350 ms,\n * so they hold between syllables. Every bar is the row's full height: lit bars are filled in the\n * tone and unlit ones are a quiet track with no outline. Nothing moves or scales; a bar's colours\n * cross-fade as it lights and goes out, the same with reduced motion. With more contrast unlit bars\n * are outlined, and under forced colours each bar keeps an edge and a lit one is Highlight.\n *\n * With `muted` the lit bars dim to the muted foreground and still follow the level, so a person\n * who speaks while muted sees that the microphone hears them and that nobody else does.\n *\n * It is a `meter` named by its label, from 0 to 100, with its level in words (\"Quiet\",\n * \"Speaking\", \"Loud\", or \"Muted\") and a value at the middle of the word's band (10, 50 or 90; 0\n * while muted). What it reports is the loudest level of the last 1.5 seconds, so a person who\n * speaks and then moves to the meter hears \"Speaking\", and its ARIA values change only when the\n * word does, at most twice a second, so a screen reader has nothing new to repeat while the person\n * speaks. It is no live region: screen readers read it when the person goes to it, and it never\n * announces the level as it changes.\n *\n * A new `value` re-renders the meter once. Between values it re-renders only when a bar lights\n * or goes out or the word changes, and the page changes only for those bars and, when the word\n * changes, the reading. The bars that keep their state are memoised.\n *\n * Its agent side, `levelMeterAx` in `level-meter-styles.ts`, declares no agent reads and no\n * actions: audio levels stay with the person.\n *\n * Use `Progress` instead to show how far along a task is, and `Spinner` for a wait you\n * can't measure.\n *\n * @claim \"The app feeds `value`, the microphone's linear\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > maps a linear amplitude to the bars on a decibel scale from -60 dBFS to 0, so speech lights 3 to 5 of 8 bars)\n * @claim \"The bars move as an audio meter's\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > rises within about 50 ms and falls over about 350 ms, the same with reduced motion)\n * @claim \"Every bar is the row's full height:\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > lights whole bars from the start edge in either direction, every bar the full height of the row)\n * @claim \"Every bar is the row's full height:\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > lights its bars in the tone's colour, success by default, and draws unlit bars as a quiet filled track)\n * @claim \"With more contrast unlit bars are outlined,\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > outlines unlit bars in the muted foreground with more contrast)\n * @claim \"Nothing moves or scales; a bar's colours\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter motion > cross-fades a bar as it lights in a third of --ouro-duration-fast, the same with reduced motion, and nothing moves or scales)\n * @claim \"With `muted` the lit bars dim to\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > dims its lit bars while muted, still showing the level, and reads Muted with a value of 0)\n * @claim \"and under forced colours each bar keeps\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > keeps an edge on every bar under forced colours, and fills a lit bar with Highlight)\n * @claim \"It is a `meter` named by its\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > is a meter named by its label, from 0 to 100, its value the middle of its word's band)\n * @claim \"What it reports is the loudest level\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > holds its reading at the loudest level of the last 1.5 seconds, so a pause after speech still reads Speaking)\n * @claim \"What it reports is the loudest level\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > changes its ARIA values only when its word changes, and at most twice a second)\n * @claim \"It is no live region: screen readers\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > is no live region, so nothing is announced as the level changes)\n * @claim \"A new `value` re-renders the meter once.\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > re-renders between values only when a bar lights or goes out or the word changes, and changes the page only there)\n * @claim \"Between values it re-renders only when a\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > re-renders between values only when a bar lights or goes out or the word changes, and changes the page only there)\n * @claim \"Its agent side, `levelMeterAx` in `level-meter-styles.ts`,\" registry/ouro/components/ouro/level-meter/level-meter.test.tsx verify:testExists(registry/ouro/components/ouro/level-meter/level-meter.test.tsx::LevelMeter > declares no agent reads and no actions)\n * @group Feedback\n * @see https://ui.ouroboros.bot/docs/level-meter\n *\n * @example\n * <LevelMeter label=\"Microphone level\" value={rms} />\n * <LevelMeter label=\"Microphone level\" hideLabel value={rms} size=\"sm\" bars={5} />\n * <LevelMeter label=\"Microphone level\" value={rms} muted={micMuted} />\n */\nexport function LevelMeter(props: LevelMeterProps): JSX.Element {\n  const {\n    value,\n    label,\n    hideLabel,\n    bars: barsProp = BARS_DEFAULT,\n    size: sizeProp = \"md\",\n    tone: toneProp = \"success\",\n    muted = false,\n    valueText = defaultValueText,\n    className,\n    id,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    level: levelProp,\n    max,\n    segments,\n    color,\n  } = props;\n  const count = Math.min(Math.max(Math.round(barsProp), BARS_MIN), BARS_MAX) || BARS_DEFAULT;\n  const size = Object.hasOwn(rowSizes, sizeProp) ? (sizeProp as keyof typeof rowSizes) : \"md\";\n  const tone = Object.hasOwn(litTones, toneProp) ? (toneProp as keyof typeof litTones) : \"success\";\n  const level = levelFromAmplitude(value);\n  const lit = Math.round(useShownLevel(level, count) * count);\n  const band = useReading(level);\n  // An id of our own puts aria-labelledby in the server HTML too.\n  const labelId = `${useId()}-label`;\n  useAppearanceClassNameCheck(\n    \"LevelMeter\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `tone=\"${toneFor(token)}\"`\n      : // Stryker disable next-line StringLiteral: production only; the check never runs there.\n        /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"LevelMeter\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          !(value >= 0 && value <= 1) && [\"value is a linear amplitude from 0 to 1, such as an analyser's RMS\", \"<LevelMeter value={rms}>\"],\n          count !== barsProp && [`bars={${String(barsProp)}} is not a whole number from ${BARS_MIN} to ${BARS_MAX}`, `<LevelMeter bars={${count}}>`],\n          size !== sizeProp && [`size=\"${String(sizeProp)}\" is not a size; use \"sm\", \"md\", \"lg\"`, '<LevelMeter size=\"md\">'],\n          tone !== toneProp && toneWarning(\"LevelMeter\", String(toneProp), Object.keys(litTones)),\n          levelProp !== undefined && [\"level is not a prop\", \"<LevelMeter value={rms}>\"],\n          max !== undefined && [\"max is not a prop; value is an amplitude from 0 to 1\", \"<LevelMeter value={rms}>\"],\n          segments !== undefined && [\"segments is not a prop\", `<LevelMeter bars={${String(segments)}}>`],\n          color !== undefined && [\"color is not a prop\", `<LevelMeter tone=\"${toneFor(`bg-${String(color)}`)}\">`],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const barClassName = cn(barClass, barSizes[size], muted ? mutedLit : litTones[tone]);\n  return (\n    <div\n      ref={ref}\n      id={id}\n      role=\"meter\"\n      aria-labelledby={labelId}\n      aria-valuemin={0}\n      aria-valuemax={100}\n      aria-valuenow={bandValues[muted ? \"muted\" : band]}\n      aria-valuetext={valueText[muted ? \"muted\" : band]}\n      data-ouro=\"level-meter\"\n      data-muted={muted ? \"\" : undefined}\n      className={cn(\"grid w-fit gap-1.5\", className)}\n    >\n      <span id={labelId} data-ouro-level-meter-label=\"\" className={hideLabel ? \"sr-only\" : \"text-sm font-medium text-foreground\"}>\n        {label}\n      </span>\n      <span className={cn(\"flex items-end\", rowSizes[size])}>\n        {Array.from({ length: count }, (_, index) => (\n          <Bar key={index} lit={index < lit} className={barClassName} />\n        ))}\n      </span>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/level-meter/level-meter.tsx"
    }
  ],
  "docs": "A small live input level: a row of bars that light from the start edge as a microphone picks up sound, so the person can tell it hears them before anyone else does (before joining a call, in a device menu, in a \"test your microphone\" row). Import: import { LevelMeter } from \"@/components/ouro/level-meter/level-meter\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: ax-component, ax-effects, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/level-meter.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}