{"version":3,"names":["untrack","composeRefs","refs","live","filter","r","Boolean","length","undefined","userRef","props","ref"],"sources":["compose-refs.ts"],"sourcesContent":["/**\n * Ref composition helpers for Solid 2.0 setter-fn refs.\n *\n * Solid's `ref={...}` binding accepts a single setter callback or a (nested)\n * array of them; `applyRef` flattens arrays. Compound parts that combine an\n * internal ref (focus, measurement, floating-ui) with the consumer's ref\n * write the same shape over and over:\n *\n *     ref={[localRef, (props as { ref?: (el: HTMLElement) => void }).ref]}\n *\n * The cast is there because Solid's component-prop types don't expose `ref`\n * (the compiler hoists it), so reading `props.ref` directly fails typecheck.\n * `composeRefs` + `userRef` centralize that cast and let multi-ref sites read\n * as a single call.\n */\n\nimport { untrack } from \"solid-js\";\n\n/**\n * Ref callbacks are effectively bivariant in T — a trigger may render a button\n * that delivers HTMLButtonElement to one setter and HTMLElement to another.\n * The composer doesn't observe the element type; it just hands callbacks to\n * Solid's apply layer. The type parameter is preserved for documentation and\n * `RefLike<T>` propagation, even though it's unused in the callback body.\n */\nexport type RefCallback<_T extends Element = HTMLElement> = (\n\t// biome-ignore lint/suspicious/noExplicitAny: see RefCallback note above\n\tel: any,\n) => void;\n\n/** A value Solid's `ref={...}` binding will accept (single, nested, or absent). */\nexport type RefLike<T extends Element = HTMLElement> =\n\t| RefCallback<T>\n\t| RefLike<T>[]\n\t| null\n\t| undefined\n\t| false;\n\n/**\n * Bundle multiple ref slots into a single value suitable for `ref={...}`.\n *\n * Falsy entries (`undefined`, `null`, `false`) are dropped so callers can pass\n * conditional refs without manual guarding. The result collapses to:\n *  - the lone callback when only one entry is live (avoids a 1-element array),\n *  - an array otherwise (Solid flattens nested arrays at apply time).\n */\nexport function composeRefs<T extends Element = HTMLElement>(\n\t...refs: RefLike<T>[]\n): RefLike<T> {\n\tconst live = refs.filter((r): r is RefCallback<T> | RefLike<T>[] =>\n\t\tBoolean(r),\n\t);\n\tif (live.length === 0) return undefined;\n\tif (live.length === 1) return live[0];\n\treturn live;\n}\n\n/**\n * Read the consumer-supplied `ref` off a component's `props` without the\n * `(props as { ref?: ... }).ref` cast at every call site. Solid hoists `ref`\n * during compile, so it isn't part of the typed prop interface — the cast\n * is the price of typed access from inside the component body.\n *\n * The read is `untrack`ed: refs are bound once at element creation (Solid\n * never re-applies a swapped `ref` prop), so the component-body read is\n * intentionally non-reactive and must not trip `[STRICT_READ_UNTRACKED]`.\n */\nexport function userRef<T extends Element = HTMLElement>(\n\tprops: object,\n): RefCallback<T> | undefined {\n\treturn untrack(() => (props as { ref?: RefCallback<T> }).ref);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,OAAO,QAAQ,UAAU;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAC1B,GAAGC,IAAkB,EACR;EACb,MAAMC,IAAI,GAAGD,IAAI,CAACE,MAAM,CAAEC,CAAC,IAC1BC,OAAO,CAACD,CAAC,CACV,CAAC;EACD,IAAIF,IAAI,CAACI,MAAM,KAAK,CAAC,EAAE,OAAOC,SAAS;EACvC,IAAIL,IAAI,CAACI,MAAM,KAAK,CAAC,EAAE,OAAOJ,IAAI,CAAC,CAAC,CAAC;EACrC,OAAOA,IAAI;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,OAAOA,CACtBC,KAAa,EACgB;EAC7B,OAAOV,OAAO,CAAC,MAAOU,KAAK,CAA8BC,GAAG,CAAC;AAC9D","ignoreList":[]}