{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "refuse",
  "title": "Refuse",
  "description": "How a part says no to what the person tried: it swells for a moment and settles back. The Alert dialog and the Save bar share it.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/resize.json"
  ],
  "files": [
    {
      "path": "registry/lib/refuse.ts",
      "content": "import { roleDuration, runningTransitions } from '@/registry/lib/resize'\n\n/*\n * How a part says no to what the person tried: it swells for a moment and\n * settles back, on the `press` role. The Alert dialog's answer to a press\n * outside, and the Save bar's to leaving with changes unsaved. The part\n * scales on `data-refused`, and holds a still cue (a ring, a colour) on it\n * under reduced motion, where nothing scales.\n */\n\nconst refusing = new WeakMap<HTMLElement, () => void>()\n\n/**\n * Marks `element` `data-refused` until its swell has peaked, then lets it\n * settle back. A second no while it swells is the same one. Returns a\n * function that ends it at once.\n */\nexport function refuse(element: HTMLElement): () => void {\n  const running = refusing.get(element)\n  if (running) return running\n  let timer: ReturnType<typeof setTimeout> | undefined\n  const settle = () => {\n    if (refusing.get(element) !== settle) return\n    refusing.delete(element)\n    clearTimeout(timer)\n    cancelAnimationFrame(frame)\n    element.removeEventListener('transitionend', onTransitionEnd)\n    element.removeAttribute('data-refused')\n  }\n  const onTransitionEnd = (event: TransitionEvent) => {\n    if (event.target === element && event.propertyName === 'scale') settle()\n  }\n  refusing.set(element, settle)\n  element.setAttribute('data-refused', '')\n  element.addEventListener('transitionend', onTransitionEnd)\n  // Under reduced motion nothing scales, so nothing ends: the still cue stays for two presses.\n  const frame = requestAnimationFrame(() => {\n    if (runningTransitions(element, { property: 'scale' }).length === 0) {\n      timer = setTimeout(settle, roleDuration(element, 'press', 300) * 2)\n    }\n  })\n  return settle\n}\n",
      "type": "registry:lib",
      "target": "@lib/refuse.ts"
    }
  ],
  "type": "registry:lib"
}