{"version":3,"names":["untrack","NOOP","rafId","enqueueFocus","el","options","preventScroll","cancelPrevious","sync","cancelAnimationFrame","exec","focus","currentRafId","requestAnimationFrame"],"sources":["enqueue-focus.ts"],"sourcesContent":["import { untrack } from \"solid-js\";\nimport type { FocusableElement } from \"./tabbable\";\n\ninterface Options {\n\tpreventScroll?: boolean | undefined;\n\tcancelPrevious?: boolean | undefined;\n\tsync?: boolean | undefined;\n}\n\nconst NOOP = () => {};\n\n// Module-scoped so consecutive calls with `cancelPrevious: true` share a slot.\n// Matches the React source — the cancellation is cross-call-site by design.\nlet rafId = 0;\n\n/**\n * Focus `el` on the next animation frame (or synchronously when `sync`\n * is true). Returns a cancellation function that only cancels the frame\n * it scheduled, so \"stale\" cancellations from later calls are no-ops.\n *\n * `cancelPrevious` (default `true`) cancels any prior RAF scheduled by\n * this module, which is the standard \"focus the latest element\" pattern\n * when multiple focus requests queue up in the same tick.\n */\nexport function enqueueFocus(\n\tel: FocusableElement | null,\n\toptions: Options = {},\n): () => void {\n\tconst {\n\t\tpreventScroll = false,\n\t\tcancelPrevious = true,\n\t\tsync = false,\n\t} = options;\n\tif (cancelPrevious) {\n\t\tcancelAnimationFrame(rafId);\n\t}\n\t// `focus()` dispatches focus events synchronously; keep their handlers out\n\t// of the caller's reactive scope (e.g. a sync focus from an effect).\n\tconst exec = () => untrack(() => el?.focus({ preventScroll }));\n\tif (sync) {\n\t\texec();\n\t\treturn NOOP;\n\t}\n\n\tconst currentRafId = requestAnimationFrame(exec);\n\trafId = currentRafId;\n\treturn () => {\n\t\tif (rafId === currentRafId) {\n\t\t\tcancelAnimationFrame(currentRafId);\n\t\t\trafId = 0;\n\t\t}\n\t};\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,UAAU;AASlC,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;;AAErB;AACA;AACA,IAAIC,KAAK,GAAG,CAAC;;AAEb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAC3BC,EAA2B,EAC3BC,OAAgB,GAAG,CAAC,CAAC,EACR;EACb,MAAM;IACLC,aAAa,GAAG,KAAK;IACrBC,cAAc,GAAG,IAAI;IACrBC,IAAI,GAAG;EACR,CAAC,GAAGH,OAAO;EACX,IAAIE,cAAc,EAAE;IACnBE,oBAAoB,CAACP,KAAK,CAAC;EAC5B;EACA;EACA;EACA,MAAMQ,IAAI,GAAGA,CAAA,KAAMV,OAAO,CAAC,MAAMI,EAAE,EAAEO,KAAK,CAAC;IAAEL;EAAc,CAAC,CAAC,CAAC;EAC9D,IAAIE,IAAI,EAAE;IACTE,IAAI,CAAC,CAAC;IACN,OAAOT,IAAI;EACZ;EAEA,MAAMW,YAAY,GAAGC,qBAAqB,CAACH,IAAI,CAAC;EAChDR,KAAK,GAAGU,YAAY;EACpB,OAAO,MAAM;IACZ,IAAIV,KAAK,KAAKU,YAAY,EAAE;MAC3BH,oBAAoB,CAACG,YAAY,CAAC;MAClCV,KAAK,GAAG,CAAC;IACV;EACD,CAAC;AACF","ignoreList":[]}