{"version":3,"names":["createContext","createMemo","useContext","createChangeEventDetails","REASONS","readOption","SNAPSHOT_KEYS","snapshotKeys","AccordionContext","useAccordion","ctx","Error","createAccordion","options","value","name","multiple","Boolean","disabled","orientation","isOpen","itemValue","includes","toggle","nextOpen","event","current","nextArr","filter","v","details","none","onValueChange","api","Provider","props","children","ACCORDION_SNAPSHOT_KEYS"],"sources":["create-accordion.tsx"],"sourcesContent":["import type { JSX } from \"@solidjs/web\";\nimport { type Accessor, createContext, createMemo, useContext } from \"solid-js\";\nimport {\n\ttype BaseUIChangeEventDetails,\n\ttype BaseUIEventReasons,\n\tcreateChangeEventDetails,\n\tREASONS,\n} from \"../internals/change-event-details\";\nimport { type MaybeAccessor, readOption } from \"../internals/maybe-accessor\";\nimport {\n\tSNAPSHOT_KEYS,\n\ttype Snapshottable,\n\tsnapshotKeys,\n} from \"../internals/observability/snapshot\";\nimport type { Orientation } from \"../internals/types\";\n\nimport type { AccordionValue } from \"./accordion-root-context\";\n\nexport type { AccordionValue };\n\nexport type AccordionChangeReason = BaseUIEventReasons[\"none\"];\n\nexport type AccordionChangeEventDetails =\n\tBaseUIChangeEventDetails<AccordionChangeReason>;\n\n/**\n * Options for {@link createAccordion}. Every reactive input is\n * `MaybeAccessor<T>`. Pure function: no internal state.\n *\n * **Solid-native shape (2026-04-30).** `value` is required and the consumer\n * always owns the signal; the primitive reads through the accessor and\n * dispatches changes via `onValueChange`.\n */\nexport interface CreateAccordionOptions<Value = unknown> {\n\t/** Open values. Empty array → \"no item open\". Consumer-owned signal. */\n\tvalue: MaybeAccessor<AccordionValue<Value>>;\n\t/**\n\t * Whether multiple items can be open at the same time.\n\t * @default false\n\t */\n\tmultiple?: MaybeAccessor<boolean>;\n\t/** Whether the whole accordion is disabled. @default false */\n\tdisabled?: MaybeAccessor<boolean>;\n\t/** Layout orientation. @default \"vertical\" */\n\torientation?: MaybeAccessor<Orientation>;\n\t/**\n\t * Pre-change callback. Called with the new value array + a cancel-capable\n\t * details bag. The consumer's signal write is the only writer — the\n\t * primitive holds no internal state.\n\t */\n\tonValueChange?: (\n\t\tvalue: AccordionValue<Value>,\n\t\tdetails: AccordionChangeEventDetails,\n\t) => void;\n}\n\n/** Public api returned by {@link createAccordion}. */\nexport interface AccordionApi<Value = unknown> {\n\t/** Currently-open values (always an array). */\n\tvalue: Accessor<AccordionValue<Value>>;\n\t/** Whether multi-expand mode is on. */\n\tmultiple: Accessor<boolean>;\n\t/** Whether the whole accordion is disabled. */\n\tdisabled: Accessor<boolean>;\n\t/** Layout orientation. */\n\torientation: Accessor<Orientation>;\n\t/** Selection check for a given item value. */\n\tisOpen: (itemValue: Value) => boolean;\n\t/**\n\t * Toggle an item open or closed. In single-expand mode, opening one item\n\t * implicitly closes any other open item; in multi-expand mode, the new\n\t * item is added to / removed from the open set.\n\t *\n\t * `nextOpen` is the desired state. Pass `event` if dispatching from a DOM\n\t * handler — it's threaded through the details bag for cancellation.\n\t */\n\ttoggle: (itemValue: Value, nextOpen: boolean, event?: Event) => void;\n\n\t/** Context provider — pair with {@link useAccordion}. */\n\tProvider: (props: { children: JSX.Element }) => JSX.Element;\n}\n\nconst AccordionContext = createContext<AccordionApi<unknown> | null>(null);\n\n/**\n * Read the nearest {@link AccordionApi} provided by `c.Provider`. Throws if\n * called outside a Provider.\n */\nexport function useAccordion<Value = unknown>(): AccordionApi<Value> {\n\tconst ctx = useContext(AccordionContext);\n\tif (ctx == null) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: useAccordion() must be called inside a <c.Provider>.\",\n\t\t);\n\t}\n\treturn ctx as AccordionApi<Value>;\n}\n\n/**\n * Solid-native headless accordion primitive. Owns the value-array\n * normalization + single/multi toggle logic; the structural wrapper\n * `<Accordion.Root>` layers the CompositeList (sibling-trigger keyboard\n * navigation) and the region role on top.\n */\nexport function createAccordion<Value = unknown>(\n\toptions: CreateAccordionOptions<Value>,\n): AccordionApi<Value> {\n\tconst value = createMemo<AccordionValue<Value>>(\n\t\t() => readOption(options.value) ?? ([] as AccordionValue<Value>),\n\t\t{ name: \"accordion.value\" },\n\t);\n\tconst multiple = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.multiple)),\n\t\t{ name: \"accordion.multiple\" },\n\t);\n\tconst disabled = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.disabled)),\n\t\t{ name: \"accordion.disabled\" },\n\t);\n\tconst orientation = createMemo<Orientation>(\n\t\t() => (readOption(options.orientation) ?? \"vertical\") as Orientation,\n\t\t{ name: \"accordion.orientation\" },\n\t);\n\n\tconst isOpen = (itemValue: Value): boolean => value().includes(itemValue);\n\n\tconst toggle = (itemValue: Value, nextOpen: boolean, event?: Event): void => {\n\t\tconst current = value();\n\t\tlet nextArr: AccordionValue<Value>;\n\t\tif (!multiple()) {\n\t\t\t// Single-expand: toggling the already-open item closes it; otherwise\n\t\t\t// the new value becomes the sole open item.\n\t\t\tnextArr = (\n\t\t\t\tcurrent[0] === itemValue ? [] : [itemValue]\n\t\t\t) as AccordionValue<Value>;\n\t\t} else if (nextOpen) {\n\t\t\tnextArr = [...current, itemValue] as AccordionValue<Value>;\n\t\t} else {\n\t\t\tnextArr = current.filter((v) => v !== itemValue) as AccordionValue<Value>;\n\t\t}\n\t\tconst details = createChangeEventDetails(REASONS.none, event);\n\t\toptions.onValueChange?.(nextArr, details);\n\t};\n\n\tconst api: AccordionApi<Value> = {\n\t\tvalue,\n\t\tmultiple,\n\t\tdisabled,\n\t\torientation,\n\t\tisOpen,\n\t\ttoggle,\n\t\tProvider: (props) => (\n\t\t\t<AccordionContext value={api as AccordionApi<unknown>}>\n\t\t\t\t{props.children}\n\t\t\t</AccordionContext>\n\t\t),\n\t};\n\t(api as AccordionApi<Value> & Snapshottable)[SNAPSHOT_KEYS] =\n\t\tACCORDION_SNAPSHOT_KEYS;\n\treturn api;\n}\n\nconst ACCORDION_SNAPSHOT_KEYS = snapshotKeys<AccordionApi<unknown>>(\n\t\"value\",\n\t\"multiple\",\n\t\"disabled\",\n\t\"orientation\",\n);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