{"version":3,"names":["createContext","createMemo","untrack","useContext","makeSlotRefDirective","readOption","mergeRootProps","SNAPSHOT_KEYS","snapshotKeys","CheckboxContext","useCheckbox","ctx","Error","createCheckbox","options","checked","Boolean","name","indeterminate","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-indeterminate","data-disabled","data-readonly","data-required","onClick","trigger","userProps","triggerRef","api","Provider","props","children","CHECKBOX_SNAPSHOT_KEYS"],"sources":["create-checkbox.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 checkbox root, OR a change on the co-located hidden `<input>`.\n * - `\"imperative\"` — programmatic `setChecked` / `toggle` with no originating\n *   DOM event.\n */\nexport type CheckboxChangeReason = \"trigger-press\" | \"imperative\";\n\n/**\n * Options for {@link createCheckbox}. Every reactive input is\n * `MaybeAccessor<T>` — pass an accessor to make the value reactive.\n *\n * Design note on tri-state: the rollout doc floated\n * `checked: boolean | \"indeterminate\"` for the api shape; this primitive\n * mirrors React's two-signal convention instead (`checked` + `indeterminate`\n * are independent). Reason: indeterminate is a presentation concern (what\n * `aria-checked` reports + native `<input>.indeterminate` property) layered\n * on top of the underlying boolean. Folding them into a single union loses\n * the \"what does the next click flip to\" answer (native checkboxes flip an\n * indeterminate one to `true`, regardless of the underlying boolean), and\n * forces consumers to encode/decode the union at every read site.\n *\n * **Solid-native shape (2026-04-30).** No internal state. `checked` is\n * required and the consumer always owns the signal. See `solidify.md` §6.\n */\nexport interface CreateCheckboxOptions {\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 the checkbox is in mixed state. Independent of `checked`:\n\t * a click on an indeterminate checkbox flips `checked` to `true`\n\t * regardless of the current `checked` value (matches the native\n\t * `<input type=\"checkbox\">.indeterminate` semantics). Always reactive.\n\t * @default false\n\t */\n\tindeterminate?: 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 checkbox is read-only — focusable but not activatable.\n\t * @default false\n\t */\n\treadOnly?: MaybeAccessor<boolean>;\n\t/**\n\t * Whether the checkbox must be ticked 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: CheckboxChangeReason,\n\t) => void;\n}\n\n/**\n * Public API returned by {@link createCheckbox}. Flat accessors and setters\n * at the root; no `state` snapshot blob.\n */\nexport interface CheckboxApi {\n\tchecked: Accessor<boolean>;\n\tindeterminate: Accessor<boolean>;\n\tdisabled: Accessor<boolean>;\n\treadOnly: Accessor<boolean>;\n\trequired: Accessor<boolean>;\n\n\t/**\n\t * Click-style toggle. While indeterminate, flips to `true` regardless\n\t * of the underlying `checked` value (native `<input>` parity).\n\t * No-op while `disabled` or `readOnly`.\n\t */\n\ttoggle: (event?: Event, reason?: CheckboxChangeReason) => 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?: CheckboxChangeReason,\n\t) => void;\n\n\t/**\n\t * Trigger slot — getter-bag of attributes ready for spreading onto a\n\t * `<button role=\"checkbox\">`.\n\t */\n\ttrigger: <U extends object | undefined = undefined>(\n\t\tuserProps?: U,\n\t) => CheckboxTriggerSlotProps & (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 * `useCheckbox()` 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 CheckboxTriggerSlotProps {\n\ttype: \"button\";\n\trole: \"checkbox\";\n\t\"aria-checked\": \"true\" | \"false\" | \"mixed\";\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-indeterminate\": \"\" | undefined;\n\t\"data-disabled\": \"\" | undefined;\n\t\"data-readonly\": \"\" | undefined;\n\t\"data-required\": \"\" | undefined;\n\tonClick: (event: MouseEvent) => void;\n}\n\nconst CheckboxContext = createContext<CheckboxApi | null>(null);\n\n/**\n * Read the nearest {@link CheckboxApi} provided by `c.Provider`. Throws\n * when used outside a Provider.\n */\nexport function useCheckbox(): CheckboxApi {\n\tconst ctx = useContext(CheckboxContext);\n\tif (ctx == null) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: useCheckbox() 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 checkbox. One call owns logical\n * state (checked/indeterminate/disabled/readOnly/required, onCheckedChange).\n * Form wiring (the hidden `<input>`, name/value, indeterminate DOM-property\n * sync, field-control validation) and CheckboxGroup parent/child integration\n * stay in the `<Checkbox.Root>` wrapper — those are integration concerns\n * layered on top of this primitive.\n */\nexport function createCheckbox(options: CreateCheckboxOptions): CheckboxApi {\n\t// `checked` reads through the consumer's accessor — no internal signal,\n\t// no controlled-or-internal branching.\n\tconst checked = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.checked)),\n\t\t{ name: \"checkbox.checked\" },\n\t);\n\n\tconst indeterminate = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.indeterminate)),\n\t\t{ name: \"checkbox.indeterminate\" },\n\t);\n\tconst disabled = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.disabled)),\n\t\t{ name: \"checkbox.disabled\" },\n\t);\n\tconst readOnly = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.readOnly)),\n\t\t{ name: \"checkbox.readOnly\" },\n\t);\n\tconst required = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.required)),\n\t\t{ name: \"checkbox.required\" },\n\t);\n\n\t// `setChecked` / `toggle` are pure event-emitters. The consumer is\n\t// responsible for updating their checked-signal in response.\n\tconst setChecked = (\n\t\tnext: boolean,\n\t\tevent?: Event,\n\t\treason: CheckboxChangeReason = \"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: CheckboxChangeReason = \"imperative\",\n\t): void => {\n\t\t// Indeterminate → click lands on `true` (matches native\n\t\t// <input type=\"checkbox\">.indeterminate semantics). Otherwise invert.\n\t\tconst next = untrack(indeterminate) ? true : !untrack(checked);\n\t\tsetChecked(next, event, reason);\n\t};\n\n\tconst triggerInternal = {\n\t\ttype: \"button\" as const,\n\t\trole: \"checkbox\" as const,\n\t\tget \"aria-checked\"() {\n\t\t\tif (indeterminate()) return \"mixed\" as const;\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 !indeterminate() && checked() ? \"\" : undefined;\n\t\t},\n\t\tget \"data-unchecked\"() {\n\t\t\treturn !indeterminate() && !checked() ? \"\" : undefined;\n\t\t},\n\t\tget \"data-indeterminate\"() {\n\t\t\treturn indeterminate() ? \"\" : 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\tconst next = indeterminate() ? true : !untrack(checked);\n\t\t\tsetChecked(next, event, \"trigger-press\");\n\t\t},\n\t};\n\n\tconst trigger = <U extends object | undefined>(userProps?: U) =>\n\t\tmergeRootProps(triggerInternal, userProps) as CheckboxTriggerSlotProps &\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: CheckboxApi = {\n\t\tchecked,\n\t\tindeterminate,\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<CheckboxContext value={api}>{props.children}</CheckboxContext>\n\t\t),\n\t};\n\t(api as CheckboxApi & Snapshottable)[SNAPSHOT_KEYS] = CHECKBOX_SNAPSHOT_KEYS;\n\treturn api;\n}\n\nconst CHECKBOX_SNAPSHOT_KEYS = snapshotKeys<CheckboxApi>(\n\t\"checked\",\n\t\"indeterminate\",\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;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgDA;AACA;AACA;AACA;;AA8CA;;AAgBA,MAAMC,eAAe,GAAGT,aAAa,CAAqB,IAAI,CAAC;;AAE/D;AACA;AACA;AACA;AACA,OAAO,SAASU,WAAWA,CAAA,EAAgB;EAC1C,MAAMC,GAAG,GAAGR,UAAU,CAACM,eAAe,CAAC;EACvC,IAAIE,GAAG,IAAI,IAAI,EAAE;IAChB,MAAM,IAAIC,KAAK,CACd,8DACD,CAAC;EACF;EACA,OAAOD,GAAG;AACX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,cAAcA,CAACC,OAA8B,EAAe;EAC3E;EACA;EACA,MAAMC,OAAO,GAAGd,UAAU,CACzB,MAAMe,OAAO,CAACX,UAAU,CAACS,OAAO,CAACC,OAAO,CAAC,CAAC,EAC1C;IAAEE,IAAI,EAAE;EAAmB,CAC5B,CAAC;EAED,MAAMC,aAAa,GAAGjB,UAAU,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