{"version":3,"names":["untrack","createChangeEventDetails","REASONS","readOption","useAnimationFrame","useTimeout","getTarget","isTypeableElement","isClickLikeEvent","isMouseLikePointerType","EMPTY_OBJECT","Object","freeze","useClick","context","props","store","rootStore","dataRef","event","eventOption","ignoreMouse","stickIfOpen","touchOpenDelay","reason","triggerPress","getEnabled","enabled","undefined","getToggle","toggle","pointerType","frame","touchOpenTimeout","reference","onPointerDown","onMouseDown","nativeEvent","open","state","button","openEvent","current","openEventType","type","hasClickedOnInactiveTrigger","domReferenceElement","currentTarget","nextOpen","target","details","start","setOpen","eventCurrentTarget","request","onClick","onKeyDown","isStaticallyDisabled"],"sources":["use-click.ts"],"sourcesContent":["/**\n * Stage 4.2 port of Base UI React's `useClick` hook.\n *\n * React source:\n *   `base-ui/packages/react/src/floating-ui-react/hooks/useClick.ts`\n *\n * Opens or closes the floating element when the reference element is\n * clicked. Supports `event: 'click' | 'mousedown' | 'mousedown-only'`,\n * `toggle`, `ignoreMouse`, `stickIfOpen`, `touchOpenDelay`, and a custom\n * `reason`.\n *\n * ### React → Solid deviations\n *\n * 1. React `useRef` for `pointerTypeRef` → a plain closure `let`. Solid\n *    component bodies don't re-run, so mutables live as variables.\n *\n * 2. React memoises `reference` via `useMemo` keyed on all option deps.\n *    Solid reads the options directly at event time off the captured\n *    props, so the returned object is a plain literal. Callers that\n *    want option reactivity can pass accessors (see `touchOpenDelay`\n *    resolution below) — but the React source also treated these as\n *    simple values, so the default Solid shape is 1:1.\n *\n * 3. `useAnimationFrame` and `useTimeout` are already ported (shared\n *    internals). They provide the same `request()` / `cancel()` and\n *    `start()` / `clear()` handles.\n *\n * 4. The reason default (`REASONS.triggerPress`) stays identical.\n */\nimport { untrack } from \"solid-js\";\nimport type { BaseUIChangeEventDetails } from \"../../change-event-details\";\nimport { createChangeEventDetails, REASONS } from \"../../change-event-details\";\nimport { type MaybeAccessor, readOption } from \"../../maybe-accessor\";\nimport { useAnimationFrame } from \"../../use-animation-frame\";\nimport { useTimeout } from \"../../use-timeout\";\nimport type {\n\tElementProps,\n\tFloatingContext,\n\tFloatingRootContext,\n} from \"../types\";\nimport { getTarget, isTypeableElement } from \"../utils/element\";\nimport { isClickLikeEvent, isMouseLikePointerType } from \"../utils/event\";\n\nexport interface UseClickProps {\n\t/**\n\t * Whether the Hook is enabled, including all internal Effects and event\n\t * handlers. Accepts an accessor so reactive flips land without\n\t * re-mounting the consumer (solidify.md P3).\n\t * @default true\n\t */\n\tenabled?: MaybeAccessor<boolean> | undefined;\n\t/**\n\t * The type of event to use to determine a \"click\" with mouse input.\n\t * Keyboard clicks work as normal.\n\t * @default 'click'\n\t */\n\tevent?: \"click\" | \"mousedown\" | \"mousedown-only\" | undefined;\n\t/**\n\t * Whether to toggle the open state with repeated clicks. Accepts an\n\t * accessor for live updates (solidify.md P3).\n\t * @default true\n\t */\n\ttoggle?: MaybeAccessor<boolean> | undefined;\n\t/**\n\t * Whether to ignore the logic for mouse input (for example, if\n\t * `useHover()` is also being used).\n\t * @default false\n\t */\n\tignoreMouse?: boolean | undefined;\n\t/**\n\t * If already open from another event such as the `useHover()` Hook,\n\t * determines whether to keep the floating element open when clicking\n\t * the reference element for the first time.\n\t * @default true\n\t */\n\tstickIfOpen?: boolean | undefined;\n\t/**\n\t * Touch-only delay (ms) before opening. Useful to allow mobile\n\t * viewport/keyboard to settle.\n\t * @default 0\n\t */\n\ttouchOpenDelay?: number | undefined;\n\t/**\n\t * The reason for the click.\n\t * @default REASONS.triggerPress\n\t */\n\treason?: typeof REASONS.triggerPress | typeof REASONS.inputPress | undefined;\n}\n\nconst EMPTY_OBJECT = Object.freeze({}) as Record<string, never>;\n\n/**\n * Opens or closes the floating element when clicking the reference element.\n * @see https://floating-ui.com/docs/useClick\n */\nexport function useClick(\n\tcontext: FloatingRootContext | FloatingContext,\n\tprops: UseClickProps = {},\n): ElementProps {\n\tconst store = \"rootStore\" in context ? context.rootStore : context;\n\tconst dataRef = store.context.dataRef;\n\n\t// Untrack the body-time destructure (see use-dismiss for the full\n\t// reasoning). These fields are not `MaybeAccessor` shapes.\n\tconst {\n\t\tevent: eventOption = \"click\",\n\t\tignoreMouse = false,\n\t\tstickIfOpen = true,\n\t\ttouchOpenDelay = 0,\n\t\treason = REASONS.triggerPress,\n\t} = untrack(() => ({\n\t\tevent: props.event,\n\t\tignoreMouse: props.ignoreMouse,\n\t\tstickIfOpen: props.stickIfOpen,\n\t\ttouchOpenDelay: props.touchOpenDelay,\n\t\treason: props.reason,\n\t}));\n\n\t// `enabled` + `toggle` are read lazily so reactive accessor callers\n\t// observe live changes without re-mounting (solidify.md P3).\n\tconst getEnabled = (): boolean =>\n\t\tprops.enabled === undefined ? true : readOption(props.enabled);\n\tconst getToggle = (): boolean =>\n\t\tprops.toggle === undefined ? true : readOption(props.toggle);\n\n\tlet pointerType: \"mouse\" | \"pen\" | \"touch\" | undefined;\n\tconst frame = useAnimationFrame();\n\tconst touchOpenTimeout = useTimeout();\n\n\tconst reference: ElementProps[\"reference\"] = {\n\t\tonPointerDown(event: PointerEvent) {\n\t\t\tif (!getEnabled()) return;\n\t\t\tpointerType = event.pointerType as \"mouse\" | \"pen\" | \"touch\";\n\t\t},\n\t\tonMouseDown(event: MouseEvent) {\n\t\t\tif (!getEnabled()) return;\n\t\t\tconst nativeEvent = event;\n\t\t\tconst open = store.state.open;\n\n\t\t\t// Ignore all buttons except for the \"main\" button.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button\n\t\t\tif (\n\t\t\t\tevent.button !== 0 ||\n\t\t\t\teventOption === \"click\" ||\n\t\t\t\t(isMouseLikePointerType(pointerType, true) && ignoreMouse)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst openEvent = dataRef.current.openEvent;\n\t\t\tconst openEventType = openEvent?.type;\n\t\t\tconst hasClickedOnInactiveTrigger =\n\t\t\t\tstore.state.domReferenceElement !== event.currentTarget;\n\t\t\tconst toggle = getToggle();\n\t\t\tconst nextOpen =\n\t\t\t\t(open && hasClickedOnInactiveTrigger) ||\n\t\t\t\t!(\n\t\t\t\t\topen &&\n\t\t\t\t\ttoggle &&\n\t\t\t\t\t(openEvent && stickIfOpen\n\t\t\t\t\t\t? openEventType === \"click\" || openEventType === \"mousedown\"\n\t\t\t\t\t\t: true)\n\t\t\t\t);\n\n\t\t\t// Animations sometimes won't run on a typeable element if using\n\t\t\t// a rAF. Focus is always set on these elements. For touch, we\n\t\t\t// may delay opening.\n\t\t\tconst target = getTarget(nativeEvent);\n\n\t\t\tif (isTypeableElement(target)) {\n\t\t\t\tconst details = createChangeEventDetails(\n\t\t\t\t\treason,\n\t\t\t\t\tnativeEvent,\n\t\t\t\t\ttarget as HTMLElement,\n\t\t\t\t) as BaseUIChangeEventDetails<string>;\n\t\t\t\tif (nextOpen && pointerType === \"touch\" && touchOpenDelay > 0) {\n\t\t\t\t\ttouchOpenTimeout.start(touchOpenDelay, () => {\n\t\t\t\t\t\tstore.setOpen(true, details);\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tstore.setOpen(nextOpen, details);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Capture the currentTarget before the rAF. React sets it to\n\t\t\t// null after the event handler completes; happy-dom / Solid do\n\t\t\t// the same, so keep the snapshot.\n\t\t\tconst eventCurrentTarget = event.currentTarget as HTMLElement;\n\n\t\t\t// Wait until focus is set on the element. This is an\n\t\t\t// alternative to `event.preventDefault()` to avoid\n\t\t\t// `:focus-visible` from appearing when using a pointer.\n\t\t\tframe.request(() => {\n\t\t\t\tconst details = createChangeEventDetails(\n\t\t\t\t\treason,\n\t\t\t\t\tnativeEvent,\n\t\t\t\t\teventCurrentTarget,\n\t\t\t\t) as BaseUIChangeEventDetails<string>;\n\t\t\t\tif (nextOpen && pointerType === \"touch\" && touchOpenDelay > 0) {\n\t\t\t\t\ttouchOpenTimeout.start(touchOpenDelay, () => {\n\t\t\t\t\t\tstore.setOpen(true, details);\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tstore.setOpen(nextOpen, details);\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tonClick(event: MouseEvent) {\n\t\t\tif (!getEnabled()) return;\n\t\t\tif (eventOption === \"mousedown-only\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (eventOption === \"mousedown\" && pointerType) {\n\t\t\t\tpointerType = undefined;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (isMouseLikePointerType(pointerType, true) && ignoreMouse) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst open = store.state.open;\n\t\t\tconst openEvent = dataRef.current.openEvent;\n\t\t\tconst hasClickedOnInactiveTrigger =\n\t\t\t\tstore.state.domReferenceElement !== event.currentTarget;\n\t\t\tconst toggle = getToggle();\n\t\t\tconst nextOpen =\n\t\t\t\t(open && hasClickedOnInactiveTrigger) ||\n\t\t\t\t!(\n\t\t\t\t\topen &&\n\t\t\t\t\ttoggle &&\n\t\t\t\t\t(openEvent && stickIfOpen ? isClickLikeEvent(openEvent) : true)\n\t\t\t\t);\n\t\t\tconst details = createChangeEventDetails(\n\t\t\t\treason,\n\t\t\t\tevent,\n\t\t\t\tevent.currentTarget as HTMLElement,\n\t\t\t) as BaseUIChangeEventDetails<string>;\n\n\t\t\tif (nextOpen && pointerType === \"touch\" && touchOpenDelay > 0) {\n\t\t\t\ttouchOpenTimeout.start(touchOpenDelay, () => {\n\t\t\t\t\tstore.setOpen(true, details);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tstore.setOpen(nextOpen, details);\n\t\t\t}\n\t\t},\n\t\tonKeyDown() {\n\t\t\tif (!getEnabled()) return;\n\t\t\tpointerType = undefined;\n\t\t},\n\t};\n\n\t// When `enabled` is an accessor, always return the bag so attached\n\t// handlers can reactively short-circuit. When it's a literal `false`,\n\t// preserve the React-compatible empty-bag shape. The body-time\n\t// `props.enabled` access is wrapped in `untrack` so the strict-read\n\t// scope established by `devComponent(...)` does not warn — the\n\t// accessor branch goes via `getEnabled()` at event time inside\n\t// already-tracked handlers.\n\tconst isStaticallyDisabled = untrack(\n\t\t() => typeof props.enabled !== \"function\" && !getEnabled(),\n\t);\n\tif (isStaticallyDisabled) {\n\t\treturn EMPTY_OBJECT;\n\t}\n\treturn { reference };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,UAAU;AAElC,SAASC,wBAAwB,EAAEC,OAAO,QAAQ,4BAA4B;AAC9E,SAA6BC,UAAU,QAAQ,sBAAsB;AACrE,SAASC,iBAAiB,QAAQ,2BAA2B;AAC7D,SAASC,UAAU,QAAQ,mBAAmB;AAM9C,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,kBAAkB;AAC/D,SAASC,gBAAgB,EAAEC,sBAAsB,QAAQ,gBAAgB;AAgDzE,MAAMC,YAAY,GAAGC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,CAA0B;;AAE/D;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CACvBC,OAA8C,EAC9CC,KAAoB,GAAG,CAAC,CAAC,EACV;EACf,MAAMC,KAAK,GAAG,WAAW,IAAIF,OAAO,GAAGA,OAAO,CAACG,SAAS,GAAGH,OAAO;EAClE,MAAMI,OAAO,GAAGF,KAAK,CAACF,OAAO,CAACI,OAAO;;EAErC;EACA;EACA,MAAM;IACLC,KAAK,EAAEC,WAAW,GAAG,OAAO;IAC5BC,WAAW,GAAG,KAAK;IACnBC,WAAW,GAAG,IAAI;IAClBC,cAAc,GAAG,CAAC;IAClBC,MAAM,GAAGtB,OAAO,CAACuB;EAClB,CAAC,GAAGzB,OAAO,CAAC,OAAO;IAClBmB,KAAK,EAAEJ,KAAK,CAACI,KAAK;IAClBE,WAAW,EAAEN,KAAK,CAACM,WAAW;I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