{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "clip-indicator",
  "title": "Clip Indicator",
  "description": "A clip light with hold, count, and reset behavior.",
  "dependencies": [
    "solid-js@^1.9.15"
  ],
  "registryDependencies": [
    "@audiocn-solid/core",
    "@audiocn-solid/use-clip-hold",
    "@audiocn-solid/use-frame-source"
  ],
  "files": [
    {
      "path": "components/ui/clip-indicator.tsx",
      "content": "import { createMemo, untrack } from \"solid-js\";\n\nimport { useClipHold } from \"@/hooks/use-clip-hold\";\nimport { useFrameSource } from \"@/hooks/use-frame-source\";\nimport { SILENCE_DB } from \"@/lib/audio/decibels\";\nimport type { FrameSource, MeterFrame } from \"@/lib/audio/types\";\nimport { CLIP_HOLD_MS, CLIP_THRESHOLD_DB } from \"@/lib/audio/zones\";\nimport { createCompatEffect } from \"@/lib/solid/effect\";\nimport type { ButtonDOMProps, JSXElement } from \"@/lib/solid/jsx-types\";\nimport { forwardProps, omitProps } from \"@/lib/solid/props\";\nimport { setRefValue } from \"@/lib/solid/ref\";\nimport type { RefTarget } from \"@/lib/solid/ref\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ClipIndicatorActions {\n  report: (db: number) => void;\n  reset: () => void;\n}\n\nexport interface ClipIndicatorState {\n  readonly clipping: boolean;\n  readonly slot: \"clip-indicator\";\n}\n\nexport interface ClipIndicatorClickEvent extends MouseEvent {\n  preventBaseUIHandler: () => void;\n  readonly baseUIHandlerPrevented?: boolean;\n}\n\ntype NativeClipButtonProps = Omit<\n  ButtonDOMProps,\n  \"children\" | \"class\" | \"className\" | \"onClick\" | \"ref\" | \"tabIndex\" | \"type\"\n>;\n\nexport type ClipIndicatorRenderProps = NativeClipButtonProps & {\n  \"aria-label\": string;\n  class: string;\n  \"data-clipping\"?: string;\n  \"data-slot\": \"clip-indicator\";\n  children: ButtonDOMProps[\"children\"];\n  onClick: (event: MouseEvent) => void;\n  type: \"button\" | \"submit\" | \"reset\";\n};\n\nexport type ClipIndicatorRender = (\n  props: ClipIndicatorRenderProps,\n  state: ClipIndicatorState\n) => JSXElement;\n\ntype ButtonProps = NativeClipButtonProps & {\n  class?: string;\n  className?: string;\n  children?: ButtonDOMProps[\"children\"];\n  ref?: RefTarget<HTMLButtonElement>;\n  onClick?: (event: ClipIndicatorClickEvent) => void;\n  type?: \"button\" | \"submit\" | \"reset\";\n  \"aria-label\"?: string;\n  render?: ClipIndicatorRender;\n};\n\nexport type ClipIndicatorProps = ButtonProps & {\n  clipping?: boolean;\n  source?: FrameSource<MeterFrame> | null;\n  thresholdDb?: number;\n  holdMs?: number;\n  onClippingChange?: (clipping: boolean) => void;\n  showCount?: boolean;\n  actionsRef?: RefTarget<ClipIndicatorActions>;\n};\n\nconst OWN_PROPS = [\n  \"clipping\",\n  \"source\",\n  \"thresholdDb\",\n  \"holdMs\",\n  \"onClippingChange\",\n  \"showCount\",\n  \"actionsRef\",\n  \"class\",\n  \"className\",\n  \"children\",\n  \"ref\",\n  \"onClick\",\n  \"type\",\n  \"aria-label\",\n  \"render\",\n] as const;\n\nconst loudestPeak = (frame: MeterFrame) => {\n  let loudest = SILENCE_DB;\n\n  for (const level of frame.channels) {\n    loudest = Math.max(loudest, level.peakDb);\n  }\n\n  return loudest;\n};\n\nexport const ClipIndicator = (props: ClipIndicatorProps) => {\n  const rest = omitProps(props, OWN_PROPS);\n\n  const hold = useClipHold({\n    get holdMs() {\n      return props.holdMs ?? CLIP_HOLD_MS;\n    },\n    get onClippingChange() {\n      return props.onClippingChange;\n    },\n    get thresholdDb() {\n      return props.thresholdDb ?? CLIP_THRESHOLD_DB;\n    },\n  });\n\n  const clipping = createMemo(() => props.clipping ?? hold.clipping);\n\n  useFrameSource(\n    () => props.source,\n    (frame) => hold.report(loudestPeak(frame))\n  );\n\n  const actions: ClipIndicatorActions = {\n    report: hold.report,\n    reset: hold.reset,\n  };\n\n  createCompatEffect(\n    () => props.actionsRef,\n    (ref) => {\n      setRefValue(ref, actions);\n\n      return () => setRefValue(ref, null);\n    }\n  );\n\n  const onClick = (event: MouseEvent) => {\n    let prevented = false;\n    // SAFETY: both ClipIndicatorClickEvent additions are defined immediately below.\n    const baseEvent = event as ClipIndicatorClickEvent;\n\n    Object.defineProperties(baseEvent, {\n      baseUIHandlerPrevented: {\n        configurable: true,\n        get: () => prevented,\n      },\n      preventBaseUIHandler: {\n        configurable: true,\n        value: () => {\n          prevented = true;\n        },\n      },\n    });\n\n    untrack(() => props.onClick)?.(baseEvent);\n\n    if (!prevented) {\n      hold.reset();\n    }\n  };\n\n  const content = () => (\n    <>\n      {props.children ?? (\n        <span\n          class=\"bg-muted-foreground/30 group-data-clipping/clip-indicator:bg-meter-clip size-2 shrink-0 rounded-full transition-colors\"\n          data-slot=\"clip-indicator-light\"\n        />\n      )}\n      {(props.showCount ?? false) ? (\n        <span class=\"tabular-nums\" data-slot=\"clip-indicator-count\">\n          {hold.count}\n        </span>\n      ) : null}\n      <span aria-live=\"polite\" class=\"sr-only\">\n        {clipping() ? \"Clipping\" : \"\"}\n      </span>\n    </>\n  );\n\n  const renderProps: ClipIndicatorRenderProps = {\n    get \"aria-label\"() {\n      return (\n        props[\"aria-label\"] ??\n        (clipping() ? \"Clipping. Reset clip indicator\" : \"Clip indicator\")\n      );\n    },\n    get class() {\n      return cn(\n        \"group/clip-indicator text-muted-foreground hover:bg-muted focus-visible:ring-ring/30 data-clipping:text-meter-clip-foreground relative inline-flex h-5 shrink-0 items-center justify-center gap-1 rounded-full px-1 text-xs font-medium transition-colors outline-none after:absolute after:-inset-1 focus-visible:ring-3 pointer-coarse:after:-inset-2.5\",\n        props.class,\n        props.className\n      );\n    },\n    get \"data-clipping\"() {\n      return clipping() ? \"\" : undefined;\n    },\n    \"data-slot\": \"clip-indicator\",\n    get children() {\n      return content();\n    },\n    onClick,\n    get type() {\n      return props.type ?? \"button\";\n    },\n  };\n\n  forwardProps(renderProps, rest);\n\n  const state: ClipIndicatorState = {\n    get clipping() {\n      return clipping();\n    },\n    slot: \"clip-indicator\",\n  };\n\n  const customRender = untrack(() => props.render);\n\n  if (customRender) {\n    const rendered = createMemo(() => customRender(renderProps, state));\n\n    return <>{rendered()}</>;\n  }\n\n  return (\n    <button\n      aria-label={\n        props[\"aria-label\"] ??\n        (clipping() ? \"Clipping. Reset clip indicator\" : \"Clip indicator\")\n      }\n      class={cn(\n        \"group/clip-indicator text-muted-foreground hover:bg-muted focus-visible:ring-ring/30 data-clipping:text-meter-clip-foreground relative inline-flex h-5 shrink-0 items-center justify-center gap-1 rounded-full px-1 text-xs font-medium transition-colors outline-none after:absolute after:-inset-1 focus-visible:ring-3 pointer-coarse:after:-inset-2.5\",\n        props.class,\n        props.className\n      )}\n      data-clipping={clipping() ? \"\" : undefined}\n      data-slot=\"clip-indicator\"\n      onClick={onClick}\n      ref={(node) => setRefValue(props.ref, node)}\n      type={props.type ?? \"button\"}\n      {...rest}\n    >\n      {content()}\n    </button>\n  );\n};\n",
      "type": "registry:ui"
    },
    {
      "path": "lib/audiocn-license.txt",
      "content": "Audio component source adapted from https://github.com/audiocn/ui.\nMIT License — Copyright (c) 2026 OrcDev\n\nRegular SVG icon geometry adapted from @phosphor-icons/react 2.1.10.\nMIT License — Copyright (c) 2020 Phosphor Icons\n\nThe following permission and warranty terms apply to both notices.\nRetain this file with copies or substantial portions of the source.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
      "type": "registry:file",
      "target": "@lib/audiocn-license.txt"
    }
  ],
  "type": "registry:ui"
}
