{"version":3,"names":["useCompositeRootContext","useCompositeListItem","useCompositeItem","params","root","ref","listItemRef","index","itemEl","el","isHighlighted","highlightedIndex","props","Object","defineProperties","create","tabIndex","enumerable","configurable","get","onFocus","value","onHighlightedIndexChange","onMouseMove","highlightItemOnHover","disabled","hasAttribute","getAttribute","focus"],"sources":["composite-item.ts"],"sourcesContent":["/**\n * `useCompositeItem` — thin wrapper around `useCompositeListItem` that also\n * reads the composite root context so items can contribute `tabIndex`,\n * `onFocus` and `onMouseMove` that keep `highlightedIndex` in sync.\n *\n * Mirrors `packages/react/src/internals/composite/item/useCompositeItem.ts`\n * in Base UI React.\n */\n\nimport type { Accessor } from \"solid-js\";\nimport type { PropsLike } from \"../merge-props-n\";\nimport { useCompositeRootContext } from \"./composite-context\";\nimport {\n\ttype UseCompositeListItemParameters,\n\tuseCompositeListItem,\n} from \"./composite-list\";\n\nexport interface UseCompositeItemParameters<Metadata>\n\textends Pick<\n\t\tUseCompositeListItemParameters<Metadata>,\n\t\t\"metadata\" | \"label\"\n\t> {}\n\nexport interface UseCompositeItemReturn {\n\t/** Props to pass to the item element through `renderElement`. */\n\tprops: PropsLike;\n\t/** Ref callback for the item element (composable via Solid 2 array ref form). */\n\tref: (el: HTMLElement | null) => void;\n\t/** Accessor for the item's live DOM-ordered index. */\n\tindex: Accessor<number>;\n}\n\nexport function useCompositeItem<Metadata>(\n\tparams: UseCompositeItemParameters<Metadata> = {},\n): UseCompositeItemReturn {\n\tconst root = useCompositeRootContext();\n\tconst { ref: listItemRef, index } = useCompositeListItem<Metadata>(params);\n\n\tlet itemEl: HTMLElement | null = null;\n\tconst ref = (el: HTMLElement | null): void => {\n\t\titemEl = el;\n\t\tlistItemRef(el);\n\t};\n\n\tconst isHighlighted = (): boolean => root.highlightedIndex() === index();\n\n\tconst props: PropsLike = Object.defineProperties(\n\t\tObject.create(null) as PropsLike,\n\t\t{\n\t\t\ttabIndex: {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\tget: () => (isHighlighted() ? 0 : -1),\n\t\t\t},\n\t\t\tonFocus: {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (): void => {\n\t\t\t\t\troot.onHighlightedIndexChange(index());\n\t\t\t\t},\n\t\t\t},\n\t\t\tonMouseMove: {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (): void => {\n\t\t\t\t\tif (!root.highlightItemOnHover()) return;\n\t\t\t\t\tconst el = itemEl;\n\t\t\t\t\tif (!el) return;\n\t\t\t\t\tconst disabled =\n\t\t\t\t\t\tel.hasAttribute(\"disabled\") ||\n\t\t\t\t\t\tel.getAttribute(\"aria-disabled\") === \"true\";\n\t\t\t\t\tif (!isHighlighted() && !disabled) el.focus();\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t);\n\n\treturn { props, ref, index };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,uBAAuB,QAAQ,qBAAqB;AAC7D,SAECC,oBAAoB,QACd,kBAAkB;AAiBzB,OAAO,SAASC,gBAAgBA,CAC/BC,MAA4C,GAAG,CAAC,CAAC,EACxB;EACzB,MAAMC,IAAI,GAAGJ,uBAAuB,CAAC,CAAC;EACtC,MAAM;IAAEK,GAAG,EAAEC,WAAW;IAAEC;EAAM,CAAC,GAAGN,oBAAoB,CAAWE,MAAM,CAAC;EAE1E,IAAIK,MAA0B,GAAG,IAAI;EACrC,MAAMH,GAAG,GAAII,EAAsB,IAAW;IAC7CD,MAAM,GAAGC,EAAE;IACXH,WAAW,CAACG,EAAE,CAAC;EAChB,CAAC;EAED,MAAMC,aAAa,GAAGA,CAAA,KAAeN,IAAI,CAACO,gBAAgB,CAAC,CAAC,KAAKJ,KAAK,CAAC,CAAC;EAExE,MAAMK,KAAgB,GAAGC,MAAM,CAACC,gBAAgB,CAC/CD,MAAM,CAACE,MAAM,CAAC,IAAI,CAAC,EACnB;IAC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