{"version":3,"names":["onCleanup","AnimationFrame","create","request","fn","requestAnimationFrame","cancel","id","cancelAnimationFrame","currentId","isStarted","useAnimationFrame","frame"],"sources":["use-animation-frame.ts"],"sourcesContent":["import { onCleanup } from \"solid-js\";\n\ntype AnimationFrameId = number;\n\n/**\n * Class-instance-like animation-frame handle with `request` / `cancel`.\n *\n * Mirrors Base UI React's `AnimationFrame`\n * (`@base-ui/utils/useAnimationFrame` —\n * `packages/utils/src/useAnimationFrame.ts`) so component ports can read 1:1\n * against the React source.\n *\n * React's version bounces through an internal scheduler for `O(1)` cancel\n * ergonomics and fake-timer resilience; here we delegate directly to\n * `requestAnimationFrame` / `cancelAnimationFrame`. The public handle shape\n * (`request(fn)`, `cancel()`, `isStarted()`) is identical.\n */\nexport class AnimationFrame {\n\tstatic create(): AnimationFrame {\n\t\treturn new AnimationFrame();\n\t}\n\n\tstatic request(fn: FrameRequestCallback): AnimationFrameId {\n\t\treturn requestAnimationFrame(fn);\n\t}\n\n\tstatic cancel(id: AnimationFrameId): void {\n\t\tcancelAnimationFrame(id);\n\t}\n\n\tprivate currentId: AnimationFrameId | null = null;\n\n\t/**\n\t * Requests `fn` on the next animation frame, cancelling any previously\n\t * requested frame from this handle first.\n\t */\n\trequest(fn: () => void): void {\n\t\tthis.cancel();\n\t\tthis.currentId = requestAnimationFrame(() => {\n\t\t\tthis.currentId = null;\n\t\t\tfn();\n\t\t});\n\t}\n\n\tisStarted(): boolean {\n\t\treturn this.currentId !== null;\n\t}\n\n\tcancel = (): void => {\n\t\tif (this.currentId !== null) {\n\t\t\tcancelAnimationFrame(this.currentId);\n\t\t\tthis.currentId = null;\n\t\t}\n\t};\n}\n\n/**\n * A `requestAnimationFrame` with automatic cleanup via `onCleanup`.\n *\n * Returns an {@link AnimationFrame} handle whose `request(fn)` schedules `fn`\n * on the next frame (cancelling any previously requested frame) and whose\n * `cancel()` cancels any pending frame. On disposal of the owning scope,\n * `cancel()` fires automatically so outstanding frames don't leak.\n *\n * Must be called from an owned scope so `onCleanup` has somewhere to\n * register.\n */\nexport function useAnimationFrame(): AnimationFrame {\n\tconst frame = AnimationFrame.create();\n\tonCleanup(frame.cancel);\n\treturn frame;\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,UAAU;AAIpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,CAAC;EAC3B,OAAOC,MAAMA,CAAA,EAAmB;IAC/B,OAAO,IAAID,cAAc,CAAC,CAAC;EAC5B;EAEA,OAAOE,OAAOA,CAACC,EAAwB,EAAoB;IAC1D,OAAOC,qBAAqB,CAACD,EAAE,CAAC;EACjC;EAEA,OAAOE,MAAMA,CAACC,EAAoB,EAAQ;IACzCC,oBAAoB,CAACD,EAAE,CAAC;EACzB;EAEQE,SAAS,GAA4B,IAAI;;EAEjD;AACD;AACA;AACA;EACCN,OAAOA,CAACC,EAAc,EAAQ;IAC7B,IAAI,CAACE,MAAM,CAAC,CAAC;IACb,IAAI,CAACG,SAAS,GAAGJ,qBAAqB,CAAC,MAAM;MAC5C,IAAI,CAACI,SAAS,GAAG,IAAI;MACrBL,EAAE,CAAC,CAAC;IACL,CAAC,CAAC;EACH;EAEAM,SAASA,CAAA,EAAY;IACpB,OAAO,IAAI,CAACD,SAAS,KAAK,IAAI;EAC/B;EAEAH,MAAM,GAAGA,CAAA,KAAY;IACpB,IAAI,IAAI,CAACG,SAAS,KAAK,IAAI,EAAE;MAC5BD,oBAAoB,CAAC,IAAI,CAACC,SAAS,CAAC;MACpC,IAAI,CAACA,SAAS,GAAG,IAAI;IACtB;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,iBAAiBA,CAAA,EAAmB;EACnD,MAAMC,KAAK,GAAGX,cAAc,CAACC,MAAM,CAAC,CAAC;EACrCF,SAAS,CAACY,KAAK,CAACN,MAAM,CAAC;EACvB,OAAOM,KAAK;AACb","ignoreList":[]}