{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "press",
  "title": "Press",
  "description": "Press feedback shared by the controls.",
  "dependencies": [
    "motion@^13.4.4"
  ],
  "registryDependencies": [
    "https://liquikit.dev/r/glass.json"
  ],
  "files": [
    {
      "path": "src/press.ts",
      "content": "\"use client\";\n\nimport { animate, useMotionValue, useReducedMotion } from \"motion/react\";\nimport {\n\ttype FocusEvent,\n\ttype KeyboardEvent,\n\ttype PointerEvent,\n\tuseCallback,\n\tuseEffect,\n\tuseRef,\n} from \"react\";\nimport { CLOSE, OPEN } from \"./glass\";\n\nconst HOVER = 0.25;\n\ntype PressHandlers<\n\tP extends PointerEvent<Element>,\n\tK extends KeyboardEvent<Element>,\n\tF extends FocusEvent<Element>,\n> = {\n\tonPointerDown?: (event: P) => void;\n\tonPointerEnter?: (event: P) => void;\n\tonPointerLeave?: (event: P) => void;\n\tonKeyDown?: (event: K) => void;\n\tonKeyUp?: (event: K) => void;\n\tonBlur?: (event: F) => void;\n};\n\nexport function usePressGlass<\n\tP extends PointerEvent<Element> = PointerEvent<HTMLElement>,\n\tK extends KeyboardEvent<Element> = KeyboardEvent<HTMLElement>,\n\tF extends FocusEvent<Element> = FocusEvent<HTMLElement>,\n>(disabled: boolean | undefined, handlers: PressHandlers<P, K, F> = {}) {\n\tconst press = useMotionValue(0);\n\tconst reduceMotion = useReducedMotion() ?? false;\n\tconst hovered = useRef(false);\n\tconst held = useRef(false);\n\tconst release = useRef<() => void>(() => {});\n\n\tconst to = useCallback(\n\t\t(value: number) => {\n\t\t\tif (reduceMotion) press.set(value);\n\t\t\telse animate(press, value, value > press.get() ? OPEN : CLOSE);\n\t\t},\n\t\t[press, reduceMotion],\n\t);\n\tconst settle = useCallback(() => {\n\t\theld.current = false;\n\t\tto(hovered.current ? HOVER : 0);\n\t}, [to]);\n\n\tuseEffect(() => () => release.current(), []);\n\n\tconst pressHandlers: Required<PressHandlers<P, K, F>> = {\n\t\tonPointerDown: (event) => {\n\t\t\thandlers.onPointerDown?.(event);\n\t\t\tif (disabled || event.button !== 0) return;\n\t\t\theld.current = true;\n\t\t\tto(1);\n\t\t\trelease.current();\n\t\t\tconst up = () => {\n\t\t\t\trelease.current();\n\t\t\t\tsettle();\n\t\t\t};\n\t\t\twindow.addEventListener(\"pointerup\", up);\n\t\t\twindow.addEventListener(\"pointercancel\", up);\n\t\t\trelease.current = () => {\n\t\t\t\twindow.removeEventListener(\"pointerup\", up);\n\t\t\t\twindow.removeEventListener(\"pointercancel\", up);\n\t\t\t\trelease.current = () => {};\n\t\t\t};\n\t\t},\n\t\tonPointerEnter: (event) => {\n\t\t\thandlers.onPointerEnter?.(event);\n\t\t\tif (event.pointerType !== \"mouse\" || disabled) return;\n\t\t\thovered.current = true;\n\t\t\tif (!held.current) to(HOVER);\n\t\t},\n\t\tonPointerLeave: (event) => {\n\t\t\thandlers.onPointerLeave?.(event);\n\t\t\thovered.current = false;\n\t\t\tif (!held.current) to(0);\n\t\t},\n\t\tonKeyDown: (event) => {\n\t\t\thandlers.onKeyDown?.(event);\n\t\t\tif (disabled || event.repeat) return;\n\t\t\tif (event.key === \" \" || event.key === \"Enter\") {\n\t\t\t\theld.current = true;\n\t\t\t\tto(1);\n\t\t\t}\n\t\t},\n\t\tonKeyUp: (event) => {\n\t\t\thandlers.onKeyUp?.(event);\n\t\t\tif (event.key === \" \" || event.key === \"Enter\") settle();\n\t\t},\n\t\tonBlur: (event) => {\n\t\t\thandlers.onBlur?.(event);\n\t\t\tif (held.current) settle();\n\t\t},\n\t};\n\n\treturn { press, pressHandlers };\n}\n",
      "type": "registry:lib",
      "target": "@components/liquikit/press.ts"
    }
  ],
  "type": "registry:lib"
}