{"version":3,"names":["onCleanup","untrack","useBaseUiId","useLabelableContext","useLabelableId","params","context","idOverride","id","source","Symbol","registerControlId","undefined"],"sources":["use-labelable-id.ts"],"sourcesContent":["import { onCleanup, untrack } from \"solid-js\";\nimport { useBaseUiId } from \"../base-ui-id\";\nimport { useLabelableContext } from \"./labelable-context\";\n\nexport interface UseLabelableIdParameters {\n\t/**\n\t * Explicit id for the control. When omitted, {@link useBaseUiId} generates\n\t * one. Read once during setup — later changes to `params.id` are ignored\n\t * to match `useBaseUiId`'s stable-id semantics.\n\t */\n\tid?: string | undefined;\n}\n\nexport interface UseLabelableIdReturnValue {\n\t/**\n\t * The id to render on the control element. Stable for the component's\n\t * lifetime; the context's `controlId()` accessor will reflect this id\n\t * while the control is mounted.\n\t */\n\tid: string;\n}\n\n/**\n * Register a labelable control's id with the surrounding\n * `<LabelableProvider>`. Labels rendered inside that provider can then read\n * `context.controlId()` to wire `htmlFor` / click-to-focus behavior.\n *\n * ### Lifecycle\n *\n * - On setup, resolves the id (override or generated) and registers it under\n *   a per-call `Symbol()` source key. Registration is synchronous so the\n *   context is populated before the first render of descendants reads it.\n * - On cleanup, unregisters the id. The provider falls back to its seeded\n *   default control id when no registrations remain (matching React).\n *\n * ### Relationship to React's `useLabelableId`\n *\n * React's version has an `implicit` branch that checks whether the control\n * is wrapped in a native `<label>` (and, if so, registers `null` to signal\n * implicit association). That DOM probe needs the host element. We have\n * deliberately **not** ported that branch here — the tier-2 components this\n * hook serves don't rely on implicit labelling. If/when a consumer needs it,\n * extend this hook to accept a `controlRef` + `implicit` flag and add a\n * post-mount registration step inside `onSettled`. For now keeping the\n * simpler shape honors the \"no wrappers, clean cuts\" policy.\n */\nexport function useLabelableId(\n\tparams: UseLabelableIdParameters = {},\n): UseLabelableIdReturnValue {\n\tconst context = useLabelableContext();\n\n\tconst idOverride = untrack(() => params.id);\n\tconst id = useBaseUiId(idOverride);\n\n\tconst source = Symbol(\"labelable-control\");\n\tcontext.registerControlId(source, id);\n\n\tonCleanup(() => {\n\t\tcontext.registerControlId(source, undefined);\n\t});\n\n\treturn { id };\n}\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,OAAO,QAAQ,UAAU;AAC7C,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,mBAAmB,QAAQ,qBAAqB;AAoBzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAC7BC,MAAgC,GAAG,CAAC,CAAC,EACT;EAC5B,MAAMC,OAAO,GAAGH,mBAAmB,CAAC,CAAC;EAErC,MAAMI,UAAU,GAAGN,OAAO,CAAC,MAAMI,MAAM,CAACG,EAAE,CAAC;EAC3C,MAAMA,EAAE,GAAGN,WAAW,CAACK,UAAU,CAAC;EAElC,MAAME,MAAM,GAAGC,MAAM,CAAC,mBAAmB,CAAC;EAC1CJ,OAAO,CAACK,iBAAiB,CAACF,MAAM,EAAED,EAAE,CAAC;EAErCR,SAAS,CAAC,MAAM;IACfM,OAAO,CAACK,iBAAiB,CAACF,MAAM,EAAEG,SAAS,CAAC;EAC7C,CAAC,CAAC;EAEF,OAAO;IAAEJ;EAAG,CAAC;AACd","ignoreList":[]}