{"version":3,"names":["createContext","createMemo","untrack","useContext","makeSlotRefDirective","readOption","mergeRootProps","SNAPSHOT_KEYS","snapshotKeys","ToggleContext","useToggle","ctx","Error","createToggle","options","pressed","Boolean","name","disabled","setPressed","next","event","reason","ev","Event","cancelable","onPressedChange","toggle","triggerInternal","type","aria-pressed","data-pressed","undefined","data-disabled","onClick","trigger","userProps","triggerRef","api","Provider","props","children","TOGGLE_SNAPSHOT_KEYS"],"sources":["create-toggle.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 pressed state changed. Emitted on the third arg of\n * `onPressedChange(next, event, reason)` and accepted by\n * `c.setPressed(next, event?, reason?)` / `c.toggle(event?, reason?)`.\n *\n * - `\"trigger-press\"` — click (or keyboard activation that bubbles to click)\n *   on the trigger slot.\n * - `\"imperative\"` — programmatic `setPressed` / `toggle` with no\n *   originating DOM event.\n *\n * Outer compounds that embed Toggle (ToggleGroup) translate this to their\n * own reason taxonomy.\n */\nexport type ToggleChangeReason = \"trigger-press\" | \"imperative\";\n\n/**\n * Options for {@link createToggle}.\n *\n * Every reactive input is `MaybeAccessor<T>` — pass an accessor to make the\n * value reactive, or a bare value for one-shot config. Read at use time via\n * `readOption(opt)`.\n *\n * **Solid-native shape (2026-04-30).** No internal state. `pressed` is\n * required and the consumer always owns the signal. The primitive is\n * a pure function from `(pressed, onPressedChange) → api`. Migration from\n * pre-2026-04-30: `createToggle({ defaultPressed: false })` becomes\n * `const [pressed, setPressed] = createSignal(false); createToggle({ pressed, onPressedChange: setPressed })`.\n * See `solidify.md` §6 for rationale.\n */\nexport interface CreateToggleOptions {\n\t/**\n\t * Pressed state. Consumer-owned signal — the primitive reads through\n\t * the accessor and does NOT keep an internal copy. Writes happen\n\t * via `onPressedChange` (the consumer's responsibility to update their\n\t * signal in response).\n\t */\n\tpressed: MaybeAccessor<boolean>;\n\t/**\n\t * Whether interaction is suppressed.\n\t * @default false\n\t */\n\tdisabled?: MaybeAccessor<boolean>;\n\t/**\n\t * Pre-change callback. Called synchronously before any internal state\n\t * write with `(next, event, reason)`. The consumer can call\n\t * `event.preventDefault()` to veto the transition.\n\t *\n\t * Pre/post asymmetry: reading `c.pressed()` inside this handler returns\n\t * the OLD value (the setter's microtask write hasn't flushed yet). For\n\t * post-change observation use `createEffect(c.pressed, ...)`.\n\t */\n\tonPressedChange?: (\n\t\tpressed: boolean,\n\t\tevent: Event,\n\t\treason: ToggleChangeReason,\n\t) => void;\n}\n\n/**\n * Public API returned by {@link createToggle}. Flat accessors and setters\n * at the root; no `state` snapshot blob.\n */\nexport interface ToggleApi {\n\t/** Reactive accessor for the current pressed state. */\n\tpressed: Accessor<boolean>;\n\t/** Whether interaction is suppressed. */\n\tdisabled: Accessor<boolean>;\n\n\t/**\n\t * Flip `pressed` (no-op while `disabled`). Same `event?` / `reason?`\n\t * contract as {@link setPressed}.\n\t */\n\ttoggle: (event?: Event, reason?: ToggleChangeReason) => void;\n\t/**\n\t * Imperative pressed setter. Fires `onPressedChange(next, event, reason)`\n\t * and the consumer's signal write is the only writer.\n\t */\n\tsetPressed: (\n\t\tnext: boolean,\n\t\tevent?: Event,\n\t\treason?: ToggleChangeReason,\n\t) => void;\n\n\t/**\n\t * Trigger slot — returns a getter-bag of HTML attributes ready for\n\t * spreading onto a `<button>` (or `dynamic(...)`).\n\t */\n\ttrigger: <U extends object | undefined = undefined>(\n\t\tuserProps?: U,\n\t) => ToggleTriggerSlotProps & (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 * `useToggle()` without prop-drilling.\n\t */\n\tProvider: (props: { children: JSX.Element }) => JSX.Element;\n}\n\n/**\n * Shape of attributes emitted by `c.trigger()`.\n */\nexport interface ToggleTriggerSlotProps {\n\ttype: \"button\";\n\t\"aria-pressed\": \"true\" | \"false\";\n\t\"data-pressed\": \"\" | undefined;\n\t\"data-disabled\": \"\" | undefined;\n\tonClick: (event: MouseEvent) => void;\n}\n\nconst ToggleContext = createContext<ToggleApi | null>(null);\n\n/**\n * Read the nearest {@link ToggleApi} provided by `c.Provider`. Throws if\n * used outside a Provider.\n */\nexport function useToggle(): ToggleApi {\n\tconst ctx = useContext(ToggleContext);\n\tif (ctx == null) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: useToggle() 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 pressed button. One\n * call owns logical state (pressed/disabled, onPressedChange). Composite-list\n * registration, keyboard-driven activation, and group-mode behaviour are\n * NOT in this primitive — they belong to the wrapping `<Toggle>` /\n * `<ToggleGroup>` adapters.\n */\nexport function createToggle(options: CreateToggleOptions): ToggleApi {\n\t// `pressed` 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 and so dev-time observability\n\t// (`name`) lines up with the rest of the api's signals.\n\tconst pressed = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.pressed)),\n\t\t{ name: \"toggle.pressed\" },\n\t);\n\n\tconst disabled = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.disabled)),\n\t\t{ name: \"toggle.disabled\" },\n\t);\n\n\t// `setPressed` / `toggle` are pure event-emitters. They fire\n\t// `onPressedChange(next, event, reason)`; the consumer is responsible\n\t// for updating their pressed-signal in response. There is no internal\n\t// state to write — `event.preventDefault()` is now a no-op for the\n\t// primitive (the consumer's handler is the only writer).\n\tconst setPressed = (\n\t\tnext: boolean,\n\t\tevent?: Event,\n\t\treason: ToggleChangeReason = \"imperative\",\n\t): void => {\n\t\tconst ev = event ?? new Event(\"pressedchange\", { cancelable: true });\n\t\toptions.onPressedChange?.(next, ev, reason);\n\t};\n\n\tconst toggle = (\n\t\tevent?: Event,\n\t\treason: ToggleChangeReason = \"imperative\",\n\t): void => {\n\t\tif (untrack(disabled)) return;\n\t\tsetPressed(!untrack(pressed), event, reason);\n\t};\n\n\tconst triggerInternal = {\n\t\ttype: \"button\" as const,\n\t\tget \"aria-pressed\"() {\n\t\t\treturn pressed() ? (\"true\" as const) : (\"false\" as const);\n\t\t},\n\t\tget \"data-pressed\"() {\n\t\t\treturn pressed() ? \"\" : undefined;\n\t\t},\n\t\tget \"data-disabled\"() {\n\t\t\treturn disabled() ? \"\" : undefined;\n\t\t},\n\t\tonClick(event: MouseEvent) {\n\t\t\tif (disabled()) return;\n\t\t\tsetPressed(!untrack(pressed), event, \"trigger-press\");\n\t\t},\n\t};\n\n\tconst trigger = <U extends object | undefined>(userProps?: U) =>\n\t\tmergeRootProps(triggerInternal, userProps) as ToggleTriggerSlotProps &\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: ToggleApi = {\n\t\tpressed,\n\t\tdisabled,\n\t\ttoggle,\n\t\tsetPressed,\n\t\ttrigger,\n\t\ttriggerRef,\n\t\tProvider: (props) => (\n\t\t\t<ToggleContext value={api}>{props.children}</ToggleContext>\n\t\t),\n\t};\n\t(api as ToggleApi & Snapshottable)[SNAPSHOT_KEYS] = TOGGLE_SNAPSHOT_KEYS;\n\treturn api;\n}\n\nconst TOGGLE_SNAPSHOT_KEYS = snapshotKeys<ToggleApi>(\"pressed\", \"disabled\");\n"],"mappings":"AACA,SAECA,aAAa,EACbC,UAAU,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