{"version":3,"names":["createContext","useContext","SwitchRootContext","useSwitchRootContext","context","Error"],"sources":["switch-root-context.ts"],"sourcesContent":["import { type Accessor, createContext, useContext } from \"solid-js\";\nimport type { FieldRootState } from \"../internals/field-constants\";\n\n/**\n * Shape of the state surface exposed by `<Switch.Root>` to its compound parts\n * (currently just `<Switch.Thumb>`). Mirrors Base UI React's\n * `SwitchRootState` — it extends the shared `FieldRootState` (valid / touched\n * / dirty / filled / focused / disabled) with the switch-specific flags.\n */\nexport interface SwitchRootState extends FieldRootState {\n\t/** Whether the switch is currently active. */\n\tchecked: boolean;\n\t/** Whether the component should ignore user interaction. */\n\tdisabled: boolean;\n\t/** Whether the user should be unable to activate or deactivate the switch. */\n\treadOnly: boolean;\n\t/** Whether the user must activate the switch before submitting a form. */\n\trequired: boolean;\n}\n\n/**\n * The value handed down by `<Switch.Root>` to its descendants.\n *\n * Solid 2 adaptations vs. React:\n *\n * - Reactive reads are exposed as `Accessor<T>` so descendants never perform a\n *   top-level reactive read on the context object itself (RFC 01).\n * - `state` is also an accessor so `<Switch.Thumb>` can drive its own\n *   `data-*` projection through `renderElement` without re-deriving.\n */\nexport interface SwitchRootContextValue {\n\t/** Current checked state. */\n\tchecked: Accessor<boolean>;\n\t/** Whether the switch ignores user interaction. */\n\tdisabled: Accessor<boolean>;\n\t/** Whether the switch is read-only (focusable but not activatable). */\n\treadOnly: Accessor<boolean>;\n\t/** Whether the switch is required for form submission. */\n\trequired: Accessor<boolean>;\n\t/** Composite state snapshot — drives compound-part `data-*` projection. */\n\tstate: Accessor<SwitchRootState>;\n}\n\n/**\n * Switch root context. `createContext<T | null>(null)` + `== null` sentinel\n * — Solid 2's `useContext` throws `ContextNotFoundError` when\n * the default is `undefined`, which would shadow the intended Base UI error\n * message below.\n */\nexport const SwitchRootContext = createContext<SwitchRootContextValue | null>(\n\tnull,\n);\n\n/**\n * Read the `<Switch.Root>` context. Throws when the caller forgot to wrap\n * the subtree in `<Switch.Root>`.\n */\nexport function useSwitchRootContext(): SwitchRootContextValue {\n\tconst context = useContext(SwitchRootContext);\n\tif (context == null) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: SwitchRootContext is missing. Switch parts must be placed within <Switch.Root>.\",\n\t\t);\n\t}\n\treturn context;\n}\n"],"mappings":"AAAA,SAAwBA,aAAa,EAAEC,UAAU,QAAQ,UAAU;;AAGnE;AACA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAGF,aAAa,CAC7C,IACD,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASG,oBAAoBA,CAAA,EAA2B;EAC9D,MAAMC,OAAO,GAAGH,UAAU,CAACC,iBAAiB,CAAC;EAC7C,IAAIE,OAAO,IAAI,IAAI,EAAE;IACpB,MAAM,IAAIC,KAAK,CACd,0FACD,CAAC;EACF;EACA,OAAOD,OAAO;AACf","ignoreList":[]}