{"version":3,"names":["onCleanup","untrack","useBaseUiId","useRegisteredLabelId","idOverride","setLabelId","id","undefined"],"sources":["use-registered-label-id.ts"],"sourcesContent":["import { onCleanup, untrack } from \"solid-js\";\nimport { useBaseUiId } from \"./base-ui-id\";\n\n/**\n * Generates a base-ui id for a label component and registers it with the\n * parent root via `setLabelId`. Clears the registration on cleanup so the\n * parent's `aria-labelledby` empties when the label unmounts. Mirrors Base UI\n * React's `useRegisteredLabelId` hook (`packages/react/src/utils/useRegisteredLabelId.ts`).\n *\n * Solid 2 notes:\n *\n * - The optional `idOverride` is expected to be read from `props.id` by the\n *   caller. Callers should wrap the read in `untrack` themselves, or pass an\n *   accessor if they want the id to follow prop changes. In practice, id\n *   overrides are stable per-mount (React's hook keys the effect on the\n *   resolved id, but the generated id is stable anyway), so we read the\n *   override once during setup.\n * - `setLabelId` is called synchronously during setup so the id is available\n *   on the very first render pass (the parent's `aria-labelledby` binding\n *   picks it up via its own reactive read). The parent's label-id signal is\n *   expected to opt into `ownedWrite` so this setup-time write is allowed in\n *   owned scope.\n * - Cleanup calls `setLabelId(undefined)` so a later-mounted label doesn't\n *   see a stale id, and so the DOM attribute clears cleanly on unmount.\n */\nexport function useRegisteredLabelId(\n\tidOverride: string | undefined,\n\tsetLabelId: (id: string | undefined) => void,\n): string {\n\t// `useBaseUiId` is stable for the component's lifetime; generate once and\n\t// hold on to it. `untrack` is belt-and-braces: the override is typically a\n\t// plain string (prop read at call site), but if the caller hands us a\n\t// reactive value we don't want to track it here.\n\tconst id = untrack(() => useBaseUiId(idOverride));\n\tsetLabelId(id);\n\tonCleanup(() => {\n\t\tsetLabelId(undefined);\n\t});\n\treturn id;\n}\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,OAAO,QAAQ,UAAU;AAC7C,SAASC,WAAW,QAAQ,cAAc;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CACnCC,UAA8B,EAC9BC,UAA4C,EACnC;EACT;EACA;EACA;EACA;EACA,MAAMC,EAAE,GAAGL,OAAO,CAAC,MAAMC,WAAW,CAACE,UAAU,CAAC,CAAC;EACjDC,UAAU,CAACC,EAAE,CAAC;EACdN,SAAS,CAAC,MAAM;IACfK,UAAU,CAACE,SAAS,CAAC;EACtB,CAAC,CAAC;EACF,OAAOD,EAAE;AACV","ignoreList":[]}