{"version":3,"names":["untrack","useBaseUiId","useFloatingParentNodeId","getFloatingFocusElement","componentRoleToAriaRoleMap","Map","EMPTY_OBJECT","Object","freeze","useRole","context","props","store","rootStore","role","defaultReferenceId","ariaRole","get","parentId","isNested","getOpen","state","open","getFloatingId","floatingElement","defaultFloatingId","floatingId","id","getReferenceId","domReference","domReferenceElement","triggerProps","reference","undefined","refResult","aria-expanded","aria-controls","defineProperty","enumerable","configurable","floating","base","item","active","selected","commonProps","trigger"],"sources":["use-role.ts"],"sourcesContent":["/**\n * Stage 4.2 port of Base UI React's `useRole` hook.\n *\n * React source:\n *   `base-ui/packages/react/src/floating-ui-react/hooks/useRole.ts`\n *\n * Adds base screen-reader props to the reference / floating elements for a\n * given floating-element `role`. Mostly a pure getter — the only reactive\n * surface is the `open` / `floatingId` / `floatingElement` / `domReferenceElement`\n * reads off the root store, which Solid consumers pick up through\n * `store.useState(...)` when this hook is invoked inside a tracking scope.\n *\n * ### React → Solid deviations\n *\n * 1. React memoises each prop bag with `useMemo` keyed on `[ariaRole, open,\n *    floatingId, referenceId, role, ...]` so identity is stable across\n *    renders. Solid components don't re-run their bodies, so the getters\n *    are plain object literals — identity is stable for the lifetime of\n *    the call site already. Consumers that need reactivity on `open` /\n *    `floatingId` route through `mergePropsN`'s prop-getter pipeline,\n *    which re-reads these values at event-time.\n *\n * 2. Since the bag is built once during setup and re-used, the dynamic\n *    fields (`aria-expanded`, `aria-controls`, `aria-describedby`) are\n *    computed inline by reading `store.useState('open')`. Because every\n *    call to `useRole(...)` is invoked inside a consumer scope that reads\n *    these props through `useInteractions`'s `mergePropsN` at render time,\n *    Solid's fine-grained DOM updates will re-read the getter on every\n *    commit. To keep the ARIA contract 1:1 without over-subscribing, we\n *    expose these as plain lookups on the store — Solid's JSX spread\n *    observes the lookup during render and re-runs it when the store\n *    signal fires.\n *\n * 3. `useId` in React → `useBaseUiId` in Solid.\n */\nimport { untrack } from \"solid-js\";\nimport { useBaseUiId } from \"../../base-ui-id\";\nimport { useFloatingParentNodeId } from \"../components/floating-tree\";\nimport type {\n\tElementProps,\n\tElementPropsBag,\n\tExtendedUserProps,\n\tFloatingContext,\n\tFloatingRootContext,\n} from \"../types\";\nimport { getFloatingFocusElement } from \"../utils/element\";\n\ntype AriaRole =\n\t| \"tooltip\"\n\t| \"dialog\"\n\t| \"alertdialog\"\n\t| \"menu\"\n\t| \"listbox\"\n\t| \"grid\"\n\t| \"tree\";\ntype ComponentRole = \"select\" | \"label\" | \"combobox\";\n\nexport interface UseRoleProps {\n\t/**\n\t * The role of the floating element.\n\t * @default 'dialog'\n\t */\n\trole?: AriaRole | ComponentRole | undefined;\n}\n\nconst componentRoleToAriaRoleMap = new Map<\n\tAriaRole | ComponentRole,\n\tAriaRole | false\n>([\n\t[\"select\", \"listbox\"],\n\t[\"combobox\", \"listbox\"],\n\t[\"label\", false],\n]);\n\nconst EMPTY_OBJECT = Object.freeze({}) as Record<string, never>;\n\n/**\n * Adds base screen reader props to the reference and floating elements for a\n * given floating element `role`.\n * @see https://floating-ui.com/docs/useRole\n */\nexport function useRole(\n\tcontext: FloatingRootContext | FloatingContext,\n\tprops: UseRoleProps = {},\n): ElementProps {\n\tconst store = \"rootStore\" in context ? context.rootStore : context;\n\n\t// Untrack the body-time `role` read so a parent passing a\n\t// signal-derived value via JSX does not fire `[STRICT_READ_UNTRACKED]`\n\t// in the strict-read scope set up by `devComponent(...)`. `role` is\n\t// not declared as `MaybeAccessor` — it's a snapshot value matching\n\t// the React fork's semantics.\n\tconst { role = \"dialog\" } = untrack(() => ({ role: props.role }));\n\n\tconst defaultReferenceId = useBaseUiId();\n\tconst ariaRole = (componentRoleToAriaRoleMap.get(role) ?? role) as\n\t\t| AriaRole\n\t\t| false\n\t\t| undefined;\n\n\tconst parentId = useFloatingParentNodeId();\n\tconst isNested = parentId != null;\n\n\t// Reactive lookups. Each call reads from the store mirror; when\n\t// `mergePropsN` (via `useInteractions`) spreads these into JSX, Solid's\n\t// render-effect subscribes to the store signal and re-evaluates on\n\t// each change.\n\tconst getOpen = () => store.state.open;\n\tconst getFloatingId = () => {\n\t\tconst floatingElement = store.state.floatingElement;\n\t\tconst defaultFloatingId = store.state.floatingId;\n\t\treturn getFloatingFocusElement(floatingElement)?.id ?? defaultFloatingId;\n\t};\n\tconst getReferenceId = () => {\n\t\tconst domReference = store.state.domReferenceElement;\n\t\treturn (domReference as HTMLElement | null)?.id || defaultReferenceId;\n\t};\n\n\tconst triggerProps: ElementProps[\"trigger\"] = (() => {\n\t\tif (ariaRole === \"tooltip\" || role === \"label\") {\n\t\t\treturn EMPTY_OBJECT;\n\t\t}\n\n\t\treturn {\n\t\t\t\"aria-haspopup\": ariaRole === \"alertdialog\" ? \"dialog\" : ariaRole,\n\t\t\t\"aria-expanded\": \"false\",\n\t\t\t...(ariaRole === \"listbox\" && { role: \"combobox\" }),\n\t\t\t...(ariaRole === \"menu\" && isNested && { role: \"menuitem\" }),\n\t\t\t...(role === \"select\" && { \"aria-autocomplete\": \"none\" }),\n\t\t\t...(role === \"combobox\" && { \"aria-autocomplete\": \"list\" }),\n\t\t};\n\t})();\n\n\tconst reference: ElementProps[\"reference\"] = (() => {\n\t\tif (ariaRole === \"tooltip\" || role === \"label\") {\n\t\t\t// Describedby / labelledby swap — seed with \"\" when closed (Solid 2's\n\t\t\t// JSX spread cannot subscribe to keys that start undefined, so we\n\t\t\t// emit an empty string).\n\t\t\treturn {\n\t\t\t\tget [`aria-${role === \"label\" ? \"labelledby\" : \"describedby\"}`]() {\n\t\t\t\t\treturn getOpen() ? getFloatingId() : undefined;\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tconst refResult: ElementPropsBag = {\n\t\t\t...triggerProps,\n\t\t\tget \"aria-expanded\"() {\n\t\t\t\treturn getOpen() ? \"true\" : \"false\";\n\t\t\t},\n\t\t\tget \"aria-controls\"() {\n\t\t\t\treturn getOpen() ? getFloatingId() : undefined;\n\t\t\t},\n\t\t};\n\t\t// `{...(condition && {get id() {...}})}` LOSES the getter (object\n\t\t// spread invokes getters and copies values), which both breaks\n\t\t// reactivity AND fires `[STRICT_READ_UNTRACKED]` at this hook's\n\t\t// body-time strict-read scope. Define the getter directly so the\n\t\t// signal read happens lazily inside whatever JSX tracking scope\n\t\t// later consumes `reference.id`.\n\t\tif (ariaRole === \"menu\") {\n\t\t\tObject.defineProperty(refResult, \"id\", {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\tget: () => getReferenceId(),\n\t\t\t});\n\t\t}\n\t\treturn refResult;\n\t})();\n\n\tconst floating: ElementProps[\"floating\"] = (() => {\n\t\t// Build with `Object.defineProperty` so the `id` getter is copied\n\t\t// as a descriptor, not invoked + recopied as a value (the latter\n\t\t// is what `{ ...base }` would do, breaking reactivity AND firing\n\t\t// `[STRICT_READ_UNTRACKED]` at this hook's body-time scope).\n\t\tconst base: ElementPropsBag = {};\n\t\tObject.defineProperty(base, \"id\", {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t\tget: () => getFloatingId(),\n\t\t});\n\t\tif (ariaRole) {\n\t\t\tbase.role = ariaRole;\n\t\t}\n\n\t\tif (ariaRole === \"tooltip\" || role === \"label\") {\n\t\t\treturn base;\n\t\t}\n\n\t\tif (ariaRole === \"menu\") {\n\t\t\tObject.defineProperty(base, \"aria-labelledby\", {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\tget: () => getReferenceId(),\n\t\t\t});\n\t\t\treturn base;\n\t\t}\n\n\t\treturn base;\n\t})();\n\n\tconst item: ElementProps[\"item\"] = ({\n\t\tactive,\n\t\tselected,\n\t}: ExtendedUserProps) => {\n\t\tconst commonProps: Record<string, unknown> = {\n\t\t\trole: \"option\",\n\t\t};\n\t\t// Use a getter so `getFloatingId()` is read lazily inside the JSX\n\t\t// tracking scope rather than at this object-build time (which is the\n\t\t// `<MenuRootComponent>` body for menu items via `useInteractions`).\n\t\tif (active) {\n\t\t\tObject.defineProperty(commonProps, \"id\", {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\tget: () => `${getFloatingId()}-fui-option`,\n\t\t\t});\n\t\t}\n\n\t\t// For `menu`, we are unable to tell if the item is a `menuitemradio`\n\t\t// or `menuitemcheckbox`. For backwards-compatibility reasons, also\n\t\t// avoid defaulting to `menuitem` as it may overwrite custom role\n\t\t// props.\n\t\tswitch (role) {\n\t\t\tcase \"select\":\n\t\t\tcase \"combobox\":\n\t\t\t\treturn {\n\t\t\t\t\t...commonProps,\n\t\t\t\t\t\"aria-selected\": selected,\n\t\t\t\t};\n\t\t\tdefault:\n\t\t}\n\n\t\treturn {};\n\t};\n\n\treturn { reference, floating, item, trigger: triggerProps };\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;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,UAAU;AAClC,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,uBAAuB,QAAQ,6BAA6B;AAQrE,SAASC,uBAAuB,QAAQ,kBAAkB;AAoB1D,MAAMC,0BAA0B,GAAG,IAAIC,GAAG,CAGxC,CACD,CAAC,QAAQ,EAAE,SAAS,CAAC,EACrB,CAAC,UAAU,EAAE,SAAS,CAAC,EACvB,CAAC,OAAO,EAAE,KAAK,CAAC,CAChB,CAAC;AAEF,MAAMC,YAAY,GAAGC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,CAA0B;;AAE/D;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CACtBC,OAA8C,EAC9CC,KAAmB,GAAG,CAAC,CAAC,EACT;EACf,MAAMC,KAAK,GAAG,WAAW,IAAIF,OAAO,GAAGA,OAAO,CAACG,SAAS,GAAGH,OAAO;;EAElE;EACA;EACA;EACA;EACA;EACA,MAAM;IAAE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