{"version":3,"names":["createContext","createMemo","useContext","createPopupCore","readOption","SNAPSHOT_KEYS","snapshotKeys","PopoverContext","usePopover","optional","ctx","Error","createPopover","options","core","open","disabled","onOpenChange","modal","name","api","setOpen","toggle","Provider","props","children","POPOVER_SNAPSHOT_KEYS"],"sources":["create-popover.tsx"],"sourcesContent":["import type { JSX } from \"@solidjs/web\";\nimport { type Accessor, createContext, createMemo, useContext } from \"solid-js\";\nimport { createPopupCore } from \"../internals/create-popup-core\";\nimport { type MaybeAccessor, readOption } from \"../internals/maybe-accessor\";\nimport {\n\tSNAPSHOT_KEYS,\n\ttype Snapshottable,\n\tsnapshotKeys,\n} from \"../internals/observability/snapshot\";\n\n/**\n * Why the popover's open state changed.\n *\n * - `\"trigger-press\"` — trigger was clicked or keyboard-activated.\n * - `\"escape-key\"` — Escape dismissed the popover.\n * - `\"outside-press\"` — pointer pressed outside.\n * - `\"close-button\"` — `<Popover.Close>` was pressed.\n * - `\"imperative\"` — `p.setOpen()` called programmatically.\n */\nexport type PopoverChangeReason =\n\t| \"trigger-press\"\n\t| \"escape-key\"\n\t| \"outside-press\"\n\t| \"close-button\"\n\t| \"imperative\";\n\nimport type { PopoverModalKind } from \"./popover-root-context\";\n\nexport type { PopoverModalKind };\n\n/**\n * Options for {@link createPopover}.\n */\nexport interface CreatePopoverOptions {\n\t/**\n\t * Open state. Consumer-owned signal.\n\t */\n\topen: MaybeAccessor<boolean>;\n\t/**\n\t * Whether interaction is suppressed.\n\t * @default false\n\t */\n\tdisabled?: MaybeAccessor<boolean>;\n\t/**\n\t * Modal surface kind.\n\t * @default false\n\t */\n\tmodal?: MaybeAccessor<PopoverModalKind>;\n\t/**\n\t * Pre-change callback fired via `runWithOwner(null, ...)`.\n\t */\n\tonOpenChange?: (\n\t\topen: boolean,\n\t\tevent: Event,\n\t\treason: PopoverChangeReason,\n\t) => void;\n}\n\n/**\n * Public API returned by {@link createPopover}.\n */\nexport interface PopoverApi {\n\t/** Reactive accessor for the current open state. */\n\topen: Accessor<boolean>;\n\t/** Whether interaction is suppressed. */\n\tdisabled: Accessor<boolean>;\n\t/** Modal surface kind. */\n\tmodal: Accessor<PopoverModalKind>;\n\n\t/** Imperative open setter. */\n\tsetOpen: (next: boolean, event?: Event, reason?: PopoverChangeReason) => void;\n\t/** Flip open (no-op when disabled). */\n\ttoggle: (event?: Event, reason?: PopoverChangeReason) => void;\n\n\t/** Context provider. */\n\tProvider: (props: { children: JSX.Element }) => JSX.Element;\n}\n\nconst PopoverContext = createContext<PopoverApi | null>(null);\n\n/**\n * Read the nearest {@link PopoverApi}. Throws unless `optional` is true.\n */\nexport function usePopover(): PopoverApi;\nexport function usePopover(optional: true): PopoverApi | null;\nexport function usePopover(optional?: boolean): PopoverApi | null {\n\tconst ctx = useContext(PopoverContext);\n\tif (ctx == null && !optional) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: usePopover() must be called inside a <p.Provider>.\",\n\t\t);\n\t}\n\treturn ctx;\n}\n\n/**\n * Headless primitive for a popover compound. Owns logical state — open,\n * disabled, modal kind. DOM machinery lives in `<Popover.Root>`.\n */\nexport function createPopover(options: CreatePopoverOptions): PopoverApi {\n\tconst core = createPopupCore<PopoverChangeReason>({\n\t\topen: options.open,\n\t\tdisabled: options.disabled,\n\t\tonOpenChange: options.onOpenChange,\n\t});\n\n\tconst modal = createMemo<PopoverModalKind>(\n\t\t() => readOption(options.modal) ?? false,\n\t\t{ name: \"popover.modal\" },\n\t);\n\n\tconst api: PopoverApi = {\n\t\topen: core.open,\n\t\tdisabled: core.disabled,\n\t\tmodal,\n\t\tsetOpen: core.setOpen,\n\t\ttoggle: core.toggle,\n\t\tProvider: (props) => (\n\t\t\t<PopoverContext value={api}>{props.children}</PopoverContext>\n\t\t),\n\t};\n\n\t(api as PopoverApi & Snapshottable)[SNAPSHOT_KEYS] = POPOVER_SNAPSHOT_KEYS;\n\n\treturn api;\n}\n\nconst POPOVER_SNAPSHOT_KEYS = snapshotKeys<PopoverApi>(\n\t\"open\",\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