{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "core-spin-delay",
  "type": "registry:lib",
  "title": "core/spin-delay",
  "description": "Framework-free behaviour shared by the ui-* components (spin-delay); no DOM, no lit. Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [],
  "registryDependencies": [
    "@kanok-ui/core-timers"
  ],
  "files": [
    {
      "path": "src/core/spin-delay.ts",
      "type": "registry:lib",
      "target": "components/ui/core/spin-delay.ts",
      "content": "import { cancelLater, later } from './timers.ts';\n\n/**\n * When a spinner shows (no Carbon counterpart; the \"spin-delay\" pattern): work that ends within\n * `delay` never shows it, and once shown it stays at least `minDuration`, so it doesn't flash on\n * and off. With both 0 it follows `active` at once, as Carbon.\n */\nexport class SpinDelay {\n    shown: boolean;\n    private shownAt = 0;\n    private timer?: unknown;\n    private readonly onChange: (shown: boolean) => void;\n\n    /** Shown from the start when `active` with no `delay`. */\n    constructor(onChange: (shown: boolean) => void, active = false, delay = 0) {\n        this.onChange = onChange;\n        this.shown = active && delay <= 0;\n    }\n\n    /** `active` changed (or the timing): show / hide now or after the wait. */\n    update(active: boolean, delay: number, minDuration: number, now = Date.now()) {\n        cancelLater(this.timer);\n        this.timer = undefined;\n        if (active === this.shown) return;\n        const wait = active ? delay : this.shownAt + minDuration - now;\n        if (wait <= 0) this.set(active, now);\n        else this.timer = later(() => this.set(active, Date.now()), wait);\n    }\n\n    /** Stops a pending change (the element went away). */\n    dispose() {\n        cancelLater(this.timer);\n        this.timer = undefined;\n    }\n\n    private set(shown: boolean, now: number) {\n        this.timer = undefined;\n        if (shown === this.shown) return;\n        this.shown = shown;\n        if (shown) this.shownAt = now;\n        this.onChange(shown);\n    }\n}\n"
    }
  ]
}
