{"version":3,"names":["createContext","createMemo","untrack","useContext","makeSlotRefDirective","readOption","mergeRootProps","SNAPSHOT_KEYS","snapshotKeys","SwitchContext","useSwitch","ctx","Error","createSwitch","options","checked","Boolean","name","disabled","readOnly","required","setChecked","next","event","reason","ev","Event","cancelable","onCheckedChange","toggle","triggerInternal","type","role","aria-checked","aria-readonly","undefined","aria-required","data-checked","data-unchecked","data-disabled","data-readonly","data-required","onClick","trigger","userProps","triggerRef","api","Provider","props","children","SWITCH_SNAPSHOT_KEYS"],"sources":["create-switch.tsx"],"sourcesContent":["import type { JSX } from \"@solidjs/web\";\nimport {\n\ttype Accessor,\n\tcreateContext,\n\tcreateMemo,\n\tuntrack,\n\tuseContext,\n} from \"solid-js\";\nimport { makeSlotRefDirective } from \"../internals/make-slot-ref-directive\";\nimport { type MaybeAccessor, readOption } from \"../internals/maybe-accessor\";\nimport { mergeRootProps } from \"../internals/merge-root-props\";\nimport {\n\tSNAPSHOT_KEYS,\n\ttype Snapshottable,\n\tsnapshotKeys,\n} from \"../internals/observability/snapshot\";\n\n/**\n * Why the checked state changed. Emitted on the third arg of\n * `onCheckedChange(next, event, reason)`.\n *\n * - `\"trigger-press\"` — click / keyboard activation that bubbles to click on\n *   the switch root, OR a change on the co-located hidden `<input>` (AT /\n *   keyboard activating the checkbox directly).\n * - `\"imperative\"` — programmatic `setChecked` / `toggle` with no originating\n *   DOM event.\n */\nexport type SwitchChangeReason = \"trigger-press\" | \"imperative\";\n\n/**\n * Options for {@link createSwitch}. Every reactive input is\n * `MaybeAccessor<T>` — pass an accessor to make the value reactive.\n *\n * **Solid-native shape (2026-04-30).** No internal state. `checked` is\n * required and the consumer always owns the signal. The primitive is a pure\n * function from `(checked, onCheckedChange) → api`. Migration:\n * `createSwitch({ defaultChecked: false })` becomes\n * `const [checked, setChecked] = createSignal(false); createSwitch({ checked, onCheckedChange: setChecked })`.\n * See `solidify.md` §6 for rationale.\n */\nexport interface CreateSwitchOptions {\n\t/**\n\t * Checked state. Consumer-owned signal — the primitive reads through\n\t * the accessor and does NOT keep an internal copy. Writes happen\n\t * via `onCheckedChange` (the consumer's responsibility to update their\n\t * signal in response).\n\t */\n\tchecked: MaybeAccessor<boolean>;\n\t/**\n\t * Whether interaction is suppressed.\n\t * @default false\n\t */\n\tdisabled?: MaybeAccessor<boolean>;\n\t/**\n\t * Whether the switch is read-only — focusable but not activatable.\n\t * @default false\n\t */\n\treadOnly?: MaybeAccessor<boolean>;\n\t/**\n\t * Whether the switch must be on for form submission.\n\t * @default false\n\t */\n\trequired?: MaybeAccessor<boolean>;\n\t/**\n\t * Pre-change callback. `event.preventDefault()` is now a no-op for\n\t * the primitive (the consumer's signal write is the only writer);\n\t * left in the signature for parity with other event channels.\n\t *\n\t * Pre/post asymmetry: reading `c.checked()` inside this handler returns\n\t * the OLD value (the consumer's signal write hasn't flushed yet). For\n\t * post-change observation use `createEffect(c.checked, ...)`.\n\t */\n\tonCheckedChange?: (\n\t\tchecked: boolean,\n\t\tevent: Event,\n\t\treason: SwitchChangeReason,\n\t) => void;\n}\n\n/**\n * Public API returned by {@link createSwitch}. Flat accessors and setters at\n * the root; no `state` snapshot blob.\n */\nexport interface SwitchApi {\n\tchecked: Accessor<boolean>;\n\tdisabled: Accessor<boolean>;\n\treadOnly: Accessor<boolean>;\n\trequired: Accessor<boolean>;\n\n\t/**\n\t * Flip `checked`. No-op while `disabled` or `readOnly`. Same `event?` /\n\t * `reason?` contract as {@link setChecked}.\n\t */\n\ttoggle: (event?: Event, reason?: SwitchChangeReason) => void;\n\t/**\n\t * Pure event-emitter: fires `onCheckedChange(next, event, reason)`.\n\t * No-op while `disabled` or `readOnly`. The consumer's signal write\n\t * (in their `onCheckedChange` handler) is the only writer.\n\t */\n\tsetChecked: (\n\t\tnext: boolean,\n\t\tevent?: Event,\n\t\treason?: SwitchChangeReason,\n\t) => void;\n\n\t/**\n\t * Trigger slot — getter-bag of attributes ready for spreading onto a\n\t * `<button role=\"switch\">`.\n\t */\n\ttrigger: <U extends object | undefined = undefined>(\n\t\tuserProps?: U,\n\t) => SwitchTriggerSlotProps & (U extends object ? U : object);\n\n\t/**\n\t * Directive form of {@link trigger} — returns a `ref` callback that\n\t * spreads the trigger slot bag onto the element at apply time.\n\t */\n\ttriggerRef: () => (el: HTMLButtonElement | null) => void;\n\n\t/**\n\t * Context provider. Wrap a subtree to make the api discoverable via\n\t * `useSwitch()` without prop-drilling.\n\t */\n\tProvider: (props: { children: JSX.Element }) => JSX.Element;\n}\n\n/** Shape of attributes emitted by `c.trigger()`. */\nexport interface SwitchTriggerSlotProps {\n\ttype: \"button\";\n\trole: \"switch\";\n\t\"aria-checked\": \"true\" | \"false\";\n\t\"aria-readonly\": \"true\" | undefined;\n\t\"aria-required\": \"true\" | undefined;\n\t\"data-checked\": \"\" | undefined;\n\t\"data-unchecked\": \"\" | undefined;\n\t\"data-disabled\": \"\" | undefined;\n\t\"data-readonly\": \"\" | undefined;\n\t\"data-required\": \"\" | undefined;\n\tonClick: (event: MouseEvent) => void;\n}\n\nconst SwitchContext = createContext<SwitchApi | null>(null);\n\n/**\n * Read the nearest {@link SwitchApi} provided by `c.Provider`. Throws when\n * used outside a Provider.\n */\nexport function useSwitch(): SwitchApi {\n\tconst ctx = useContext(SwitchContext);\n\tif (ctx == null) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: useSwitch() must be called inside a <c.Provider>.\",\n\t\t);\n\t}\n\treturn ctx;\n}\n\n/**\n * Solid 2.0-native compound primitive for a two-state switch. One call owns\n * logical state (checked/disabled/readOnly/required, onCheckedChange). Form\n * wiring (the hidden `<input>`, name/value, field-control validation) is the\n * `<Switch.Root>` wrapper's job — those are integration concerns layered on\n * top of this primitive.\n */\nexport function createSwitch(options: CreateSwitchOptions): SwitchApi {\n\t// `checked` reads through the consumer's accessor — no internal signal,\n\t// no controlled-or-internal branching. Memoized so dependents see the\n\t// same identity within a tracking scope.\n\tconst checked = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.checked)),\n\t\t{\n\t\t\tname: \"switch.checked\",\n\t\t},\n\t);\n\n\tconst disabled = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.disabled)),\n\t\t{ name: \"switch.disabled\" },\n\t);\n\tconst readOnly = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.readOnly)),\n\t\t{ name: \"switch.readOnly\" },\n\t);\n\tconst required = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.required)),\n\t\t{ name: \"switch.required\" },\n\t);\n\n\t// `setChecked` / `toggle` are pure event-emitters. They fire\n\t// `onCheckedChange(next, event, reason)`; the consumer is responsible\n\t// for updating their checked-signal in response. There is no internal\n\t// state to write — `event.preventDefault()` is now a no-op for the\n\t// primitive.\n\tconst setChecked = (\n\t\tnext: boolean,\n\t\tevent?: Event,\n\t\treason: SwitchChangeReason = \"imperative\",\n\t): void => {\n\t\tif (untrack(disabled) || untrack(readOnly)) return;\n\t\tconst ev = event ?? new Event(\"checkedchange\", { cancelable: true });\n\t\toptions.onCheckedChange?.(next, ev, reason);\n\t};\n\n\tconst toggle = (\n\t\tevent?: Event,\n\t\treason: SwitchChangeReason = \"imperative\",\n\t): void => {\n\t\tsetChecked(!untrack(checked), event, reason);\n\t};\n\n\tconst triggerInternal = {\n\t\ttype: \"button\" as const,\n\t\trole: \"switch\" as const,\n\t\tget \"aria-checked\"() {\n\t\t\treturn checked() ? (\"true\" as const) : (\"false\" as const);\n\t\t},\n\t\tget \"aria-readonly\"() {\n\t\t\treturn readOnly() ? (\"true\" as const) : undefined;\n\t\t},\n\t\tget \"aria-required\"() {\n\t\t\treturn required() ? (\"true\" as const) : undefined;\n\t\t},\n\t\tget \"data-checked\"() {\n\t\t\treturn checked() ? \"\" : undefined;\n\t\t},\n\t\tget \"data-unchecked\"() {\n\t\t\treturn checked() ? undefined : \"\";\n\t\t},\n\t\tget \"data-disabled\"() {\n\t\t\treturn disabled() ? \"\" : undefined;\n\t\t},\n\t\tget \"data-readonly\"() {\n\t\t\treturn readOnly() ? \"\" : undefined;\n\t\t},\n\t\tget \"data-required\"() {\n\t\t\treturn required() ? \"\" : undefined;\n\t\t},\n\t\tonClick(event: MouseEvent) {\n\t\t\tif (disabled() || readOnly()) return;\n\t\t\tsetChecked(!untrack(checked), event, \"trigger-press\");\n\t\t},\n\t};\n\n\tconst trigger = <U extends object | undefined>(userProps?: U) =>\n\t\tmergeRootProps(triggerInternal, userProps) as SwitchTriggerSlotProps &\n\t\t\t(U extends object ? U : object);\n\n\tconst triggerRef = (): ((el: HTMLButtonElement | null) => void) =>\n\t\tmakeSlotRefDirective(() => trigger());\n\n\tconst api: SwitchApi = {\n\t\tchecked,\n\t\tdisabled,\n\t\treadOnly,\n\t\trequired,\n\t\ttoggle,\n\t\tsetChecked,\n\t\ttrigger,\n\t\ttriggerRef,\n\t\tProvider: (props) => (\n\t\t\t<SwitchContext value={api}>{props.children}</SwitchContext>\n\t\t),\n\t};\n\t(api as SwitchApi & Snapshottable)[SNAPSHOT_KEYS] = SWITCH_SNAPSHOT_KEYS;\n\treturn api;\n}\n\nconst SWITCH_SNAPSHOT_KEYS = snapshotKeys<SwitchApi>(\n\t\"checked\",\n\t\"disabled\",\n\t\"readOnly\",\n\t\"required\",\n);\n"],"mappings":"AACA,SAECA,aAAa,EACbC,UAAU,EACVC,OAAO,EACPC,UAAU,QACJ,UAAU;AACjB,SAASC,oBAAoB,QAAQ,sCAAsC;AAC3E,SAA6BC,UAAU,QAAQ,6BAA6B;AAC5E,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SACCC,aAAa,EAEbC,YAAY,QACN,qCAAqC;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwCA;AACA;AACA;AACA;;AA4CA;;AAeA,MAAMC,aAAa,GAAGT,aAAa,CAAmB,IAAI,CAAC;;AAE3D;AACA;AACA;AACA;AACA,OAAO,SAASU,SAASA,CAAA,EAAc;EACtC,MAAMC,G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