/**
 * Ref composition helpers for Solid 2.0 setter-fn refs.
 *
 * Solid's `ref={...}` binding accepts a single setter callback or a (nested)
 * array of them; `applyRef` flattens arrays. Compound parts that combine an
 * internal ref (focus, measurement, floating-ui) with the consumer's ref
 * write the same shape over and over:
 *
 *     ref={[localRef, (props as { ref?: (el: HTMLElement) => void }).ref]}
 *
 * The cast is there because Solid's component-prop types don't expose `ref`
 * (the compiler hoists it), so reading `props.ref` directly fails typecheck.
 * `composeRefs` + `userRef` centralize that cast and let multi-ref sites read
 * as a single call.
 */

import { untrack } from "solid-js";

/**
 * Ref callbacks are effectively bivariant in T — a trigger may render a button
 * that delivers HTMLButtonElement to one setter and HTMLElement to another.
 * The composer doesn't observe the element type; it just hands callbacks to
 * Solid's apply layer. The type parameter is preserved for documentation and
 * `RefLike<T>` propagation, even though it's unused in the callback body.
 */

/** A value Solid's `ref={...}` binding will accept (single, nested, or absent). */

/**
 * Bundle multiple ref slots into a single value suitable for `ref={...}`.
 *
 * Falsy entries (`undefined`, `null`, `false`) are dropped so callers can pass
 * conditional refs without manual guarding. The result collapses to:
 *  - the lone callback when only one entry is live (avoids a 1-element array),
 *  - an array otherwise (Solid flattens nested arrays at apply time).
 */
export function composeRefs(...refs) {
  const live = refs.filter(r => Boolean(r));
  if (live.length === 0) return undefined;
  if (live.length === 1) return live[0];
  return live;
}

/**
 * Read the consumer-supplied `ref` off a component's `props` without the
 * `(props as { ref?: ... }).ref` cast at every call site. Solid hoists `ref`
 * during compile, so it isn't part of the typed prop interface — the cast
 * is the price of typed access from inside the component body.
 *
 * The read is `untrack`ed: refs are bound once at element creation (Solid
 * never re-applies a swapped `ref` prop), so the component-body read is
 * intentionally non-reactive and must not trip `[STRICT_READ_UNTRACKED]`.
 */
export function userRef(props) {
  return untrack(() => props.ref);
}
//# sourceMappingURL=compose-refs.jsx.map
