{"version":3,"names":["createContext","createMemo","runWithOwner","untrack","useContext","readOption","SNAPSHOT_KEYS","snapshotKeys","PopupCoreContext","usePopupCore","optional","ctx","Error","createPopupCore","options","open","Boolean","name","disabled","setOpen","next","event","reason","ev","Event","cancelable","onOpenChange","toggle","api","Provider","props","children","POPUP_CORE_SNAPSHOT_KEYS"],"sources":["create-popup-core.tsx"],"sourcesContent":["import type { JSX } from \"@solidjs/web\";\nimport {\n\ttype Accessor,\n\tcreateContext,\n\tcreateMemo,\n\trunWithOwner,\n\tuntrack,\n\tuseContext,\n} from \"solid-js\";\nimport { type MaybeAccessor, readOption } from \"./maybe-accessor\";\nimport {\n\tSNAPSHOT_KEYS,\n\ttype Snapshottable,\n\tsnapshotKeys,\n} from \"./observability/snapshot\";\n\n/**\n * Why a popup's open state changed.\n *\n * Compounds may extend this with their own reason literals — e.g.\n * `\"trigger-hover\"` for Tooltip. The common reasons are surfaced here so\n * `createPopupCore` can emit a meaningful default without knowing the\n * per-compound vocabulary.\n *\n * - `\"trigger-press\"` — user activated the trigger (click / Enter / Space).\n * - `\"imperative\"` — `popup.setOpen()` called with no originating DOM event.\n * - `\"escape-key\"` — Escape key dismissed the popup.\n * - `\"outside-press\"` — pointer press outside the popup dismissed it.\n */\nexport type PopupCoreChangeReason =\n\t| \"trigger-press\"\n\t| \"imperative\"\n\t| \"escape-key\"\n\t| \"outside-press\";\n\n/**\n * Options accepted by {@link createPopupCore}. Every reactive field is\n * `MaybeAccessor<T>` — pass an accessor to keep the option live.\n */\nexport interface CreatePopupCoreOptions<\n\tReason extends string = PopupCoreChangeReason,\n> {\n\t/**\n\t * Open state. Consumer-owned signal — the primitive reads through the\n\t * accessor and does NOT keep an internal copy. Writes happen via\n\t * `onOpenChange` (the consumer's responsibility to update their 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 * Pre-change callback. Called via `runWithOwner(null, ...)` so consumer\n\t * signal writes inside the handler don't trigger SIGNAL_WRITE_IN_OWNED_SCOPE.\n\t */\n\tonOpenChange?: (open: boolean, event: Event, reason: Reason) => void;\n}\n\n/**\n * Public API returned by {@link createPopupCore}.\n */\nexport interface PopupCoreApi<Reason extends string = PopupCoreChangeReason> {\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/**\n\t * Imperative open setter. Fires `onOpenChange(next, event, reason)` via\n\t * `runWithOwner(null, ...)` to escape the reactive owner.\n\t */\n\tsetOpen: (next: boolean, event?: Event, reason?: Reason) => void;\n\t/**\n\t * Flip open (no-op when disabled). Same event/reason contract as setOpen.\n\t */\n\ttoggle: (event?: Event, reason?: Reason) => void;\n\n\t/**\n\t * Context provider. Wrap a subtree to expose the core api via\n\t * `usePopupCore()`.\n\t */\n\tProvider: (props: { children: JSX.Element }) => JSX.Element;\n}\n\nconst PopupCoreContext = createContext<PopupCoreApi<string> | null>(null);\n\n/**\n * Read the nearest {@link PopupCoreApi} from a `<popup.Provider>`.\n * Throws unless `optional` is true.\n */\nexport function usePopupCore(): PopupCoreApi<string>;\nexport function usePopupCore(optional: true): PopupCoreApi<string> | null;\nexport function usePopupCore(optional?: boolean): PopupCoreApi<string> | null {\n\tconst ctx = useContext(PopupCoreContext);\n\tif (ctx == null && !optional) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: usePopupCore() must be called inside a <popup.Provider>.\",\n\t\t);\n\t}\n\treturn ctx;\n}\n\n/**\n * Shared headless primitive for popup compounds (Tooltip, Popover, Dialog,\n * PreviewCard, AlertDialog, Drawer). Owns:\n *\n *  - `open` memo — reads through the consumer's accessor.\n *  - `disabled` memo — guards setOpen / toggle.\n *  - `setOpen` / `toggle` — pure event-emitters that fire `onOpenChange`\n *    via `runWithOwner(null, ...)`.\n *  - `Provider` — optional context provider.\n *\n * DOM machinery (floating-ui, portal, focus trap, scroll lock, animation)\n * lives in the per-compound `<X.Root>` wrappers that compose this.\n */\nexport function createPopupCore<Reason extends string = PopupCoreChangeReason>(\n\toptions: CreatePopupCoreOptions<Reason>,\n): PopupCoreApi<Reason> {\n\tconst open = createMemo<boolean>(() => Boolean(readOption(options.open)), {\n\t\tname: \"popup.open\",\n\t});\n\n\tconst disabled = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.disabled)),\n\t\t{ name: \"popup.disabled\" },\n\t);\n\n\tconst setOpen = (\n\t\tnext: boolean,\n\t\tevent?: Event,\n\t\treason: Reason = \"imperative\" as Reason,\n\t): void => {\n\t\tconst ev = event ?? new Event(\"openchange\", { cancelable: true });\n\t\t// Escape the reactive owner so consumer signal writes inside\n\t\t// onOpenChange don't trip SIGNAL_WRITE_IN_OWNED_SCOPE.\n\t\trunWithOwner(null, () => options.onOpenChange?.(next, ev, reason));\n\t};\n\n\tconst toggle = (event?: Event, reason?: Reason): void => {\n\t\tif (untrack(disabled)) return;\n\t\tsetOpen(!untrack(open), event, reason);\n\t};\n\n\tconst api: PopupCoreApi<Reason> = {\n\t\topen,\n\t\tdisabled,\n\t\tsetOpen,\n\t\ttoggle,\n\t\tProvider: (props) => (\n\t\t\t<PopupCoreContext value={api as PopupCoreApi<string>}>\n\t\t\t\t{props.children}\n\t\t\t</PopupCoreContext>\n\t\t),\n\t};\n\n\t(api as PopupCoreApi<Reason> & Snapshottable)[SNAPSHOT_KEYS] =\n\t\tPOPUP_CORE_SNAPSHOT_KEYS;\n\n\treturn api;\n}\n\nconst POPUP_CORE_SNAPSHOT_KEYS = snapshotKeys<PopupCoreApi>(\"open\", \"disabled\");\n"],"mappings":"AACA,SAECA,aAAa,EACbC,UAAU,EACVC,YAAY,EACZC,OAAO,EACPC,UAAU,QACJ,UAAU;AACjB,SAA6BC,UAAU,QAAQ,kBAAkB;AACjE,SACCC,aAAa,EAEbC,YAAY,QACN,0BAA0B;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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