{"version":3,"names":["createContext","createEffect","useContext","readOption","SNAPSHOT_KEYS","snapshotKeys","createToastStore","ToastContext","useToast","ctx","Error","createToast","options","initialTimeout","timeout","initialLimit","limit","store","next","setTimeoutOption","setLimitOption","toastManager","manager","undefined","unsubscribe","event","action","opts","id","promise","promiseOptions","loading","success","error","setPromise","promiseToast","updateToast","closeToast","addToast","api","toasts","expanded","hovering","focused","isEmpty","add","addOptions","close","update","updateOptions","value","Provider","props","children","TOAST_SNAPSHOT_KEYS"],"sources":["create-toast.tsx"],"sourcesContent":["import type { JSX } from \"@solidjs/web\";\nimport {\n\ttype Accessor,\n\tcreateContext,\n\tcreateEffect,\n\tuseContext,\n} from \"solid-js\";\nimport { type MaybeAccessor, readOption } from \"../internals/maybe-accessor\";\nimport {\n\tSNAPSHOT_KEYS,\n\ttype Snapshottable,\n\tsnapshotKeys,\n} from \"../internals/observability/snapshot\";\nimport type { ToastManager, ToastManagerEvent } from \"./create-toast-manager\";\nimport { createToastStore, type ToastStore } from \"./toast-store\";\nimport type {\n\tToastManagerAddOptions,\n\tToastManagerPromiseOptions,\n\tToastManagerUpdateOptions,\n\tToastObject,\n} from \"./use-toast-manager\";\n\nexport type { ToastObject };\n\n/**\n * Options for {@link createToast}.\n *\n * The queue is internally owned — `timeout` / `limit` configure it but the\n * consumer does not hold signals for them. Unlike `createTabs`/etc the toast\n * primitive owns internal state because the queue IS the implementation (it\n * is not a consumer-controlled value; the consumer drives it via `add` / `close`\n * / `update` imperatives).\n */\nexport interface CreateToastOptions {\n\t/**\n\t * Default auto-dismiss duration in milliseconds. `0` disables auto-dismiss.\n\t * @default 5000\n\t */\n\ttimeout?: MaybeAccessor<number>;\n\t/**\n\t * Maximum number of visible toasts. Oldest toasts beyond the limit are\n\t * marked `limited` so consumers can animate them out.\n\t * @default 3\n\t */\n\tlimit?: MaybeAccessor<number>;\n\t/**\n\t * Optional external manager created via {@link createToastManager}. Events\n\t * emitted by the manager are forwarded into this primitive's queue, letting\n\t * code outside the component tree add / close / update toasts.\n\t */\n\ttoastManager?: MaybeAccessor<ToastManager | undefined>;\n}\n\n/**\n * Public API returned by {@link createToast}.\n */\nexport interface ToastApi {\n\t/** Reactive accessor for the current toast queue. */\n\ttoasts: Accessor<ToastObject<object>[]>;\n\t/** Whether any toast is hovered or focused. */\n\texpanded: Accessor<boolean>;\n\t/** Whether the viewport is hovering. */\n\thovering: Accessor<boolean>;\n\t/** Whether the viewport is focused. */\n\tfocused: Accessor<boolean>;\n\t/** Whether the queue is empty. */\n\tisEmpty: Accessor<boolean>;\n\n\t/** Add a toast and return its id. */\n\tadd: (options: ToastManagerAddOptions<object>) => string;\n\t/** Close a toast by id, or all toasts when id is omitted. */\n\tclose: (id?: string) => void;\n\t/** Update an existing toast in place. */\n\tupdate: (id: string, options: ToastManagerUpdateOptions<object>) => void;\n\t/** Add a promise-backed toast that transitions through loading → success/error. */\n\tpromise: <Value>(\n\t\tvalue: Promise<Value>,\n\t\toptions: ToastManagerPromiseOptions<Value, object>,\n\t) => Promise<Value>;\n\n\t/**\n\t * The underlying store. Passed into `<ToastProviderContext>` so the\n\t * existing wrapper components (`Toast.Provider`, `Toast.Viewport`, etc.)\n\t * can compose this primitive.\n\t */\n\treadonly store: ToastStore;\n\n\t/** Context provider — pair with {@link useToast}. */\n\tProvider: (props: { children: JSX.Element }) => JSX.Element;\n}\n\nconst ToastContext = createContext<ToastApi | null>(null);\n\n/**\n * Read the nearest {@link ToastApi} provided by `c.Provider`. Throws if\n * called outside a Provider.\n */\nexport function useToast(): ToastApi {\n\tconst ctx = useContext(ToastContext);\n\tif (ctx == null) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: useToast() must be called inside a <c.Provider>.\",\n\t\t);\n\t}\n\treturn ctx;\n}\n\n/**\n * Solid-native headless toast primitive. Owns the queue, timers, and\n * lifecycle bookkeeping. The consumer drives the queue via `add` / `close` /\n * `update` / `promise` imperatives and reads reactive state (`toasts`,\n * `expanded`, `hovering`, `focused`, `isEmpty`) through accessors.\n *\n * Internal state IS appropriate here: the queue is implementation detail\n * (not a consumer-controlled value). `timeout` / `limit` configure the store\n * but the consumer never holds the backing signals.\n *\n * Callbacks (`onValueChange` etc.) are not part of this surface because there\n * is no discrete \"value\" the consumer needs to mirror — the consumer observes\n * the queue reactively via `toasts()`. The `onClose` / `onRemove` hooks on\n * individual `ToastObject`s serve per-toast lifecycle needs.\n */\nexport function createToast(options: CreateToastOptions = {}): ToastApi {\n\tconst initialTimeout = readOption(options.timeout) ?? 5000;\n\tconst initialLimit = readOption(options.limit) ?? 3;\n\n\tconst store = createToastStore({\n\t\ttimeout: initialTimeout,\n\t\tlimit: initialLimit,\n\t});\n\n\t// Sync timeout/limit into the store when the accessor values change.\n\t// Split compute/apply (RFC 02) so reads and writes stay in separate scopes.\n\tcreateEffect(\n\t\t() => readOption(options.timeout) ?? 5000,\n\t\t(next: number) => {\n\t\t\tstore.setTimeoutOption(next);\n\t\t},\n\t);\n\tcreateEffect(\n\t\t() => readOption(options.limit) ?? 3,\n\t\t(next: number) => {\n\t\t\tstore.setLimitOption(next);\n\t\t},\n\t);\n\n\t// Forward external manager events into the store. Returns cleanup so the\n\t// apply phase can unsubscribe without needing `onCleanup` (the apply runs\n\t// in an unowned scope where `onCleanup` would trip NO_OWNER_CLEANUP).\n\tcreateEffect(\n\t\t() => readOption(options.toastManager),\n\t\t(manager: ToastManager | undefined) => {\n\t\t\tif (!manager) return undefined;\n\t\t\tconst unsubscribe = manager[\" subscribe\"]((event: ToastManagerEvent) => {\n\t\t\t\tconst { action, options: opts } = event;\n\t\t\t\tconst id = opts.id as string | undefined;\n\t\t\t\tif (\n\t\t\t\t\taction === \"promise\" &&\n\t\t\t\t\topts.promise &&\n\t\t\t\t\t\"loading\" in opts &&\n\t\t\t\t\t\"success\" in opts &&\n\t\t\t\t\t\"error\" in opts\n\t\t\t\t) {\n\t\t\t\t\tconst promiseOptions = {\n\t\t\t\t\t\tloading: opts.loading as ToastManagerPromiseOptions<\n\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\tobject\n\t\t\t\t\t\t>[\"loading\"],\n\t\t\t\t\t\tsuccess: opts.success as ToastManagerPromiseOptions<\n\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\tobject\n\t\t\t\t\t\t>[\"success\"],\n\t\t\t\t\t\terror: opts.error as ToastManagerPromiseOptions<\n\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\tobject\n\t\t\t\t\t\t>[\"error\"],\n\t\t\t\t\t\tsetPromise: opts.setPromise,\n\t\t\t\t\t};\n\t\t\t\t\tstore.promiseToast(opts.promise, promiseOptions);\n\t\t\t\t} else if (action === \"update\" && id) {\n\t\t\t\t\tstore.updateToast(\n\t\t\t\t\t\tid,\n\t\t\t\t\t\topts as Parameters<typeof store.updateToast>[1],\n\t\t\t\t\t);\n\t\t\t\t} else if (action === \"close\") {\n\t\t\t\t\tstore.closeToast(id);\n\t\t\t\t} else {\n\t\t\t\t\tstore.addToast(opts as Parameters<typeof store.addToast>[0]);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn unsubscribe;\n\t\t},\n\t);\n\n\tconst api: ToastApi = {\n\t\ttoasts: store.toasts as Accessor<ToastObject<object>[]>,\n\t\texpanded: store.expanded,\n\t\thovering: store.hovering,\n\t\tfocused: store.focused,\n\t\tisEmpty: store.isEmpty,\n\t\tadd(addOptions) {\n\t\t\treturn store.addToast(addOptions);\n\t\t},\n\t\tclose(id) {\n\t\t\tstore.closeToast(id);\n\t\t},\n\t\tupdate(id, updateOptions) {\n\t\t\tstore.updateToast(id, updateOptions);\n\t\t},\n\t\tpromise(value, promiseOptions) {\n\t\t\treturn store.promiseToast(value, promiseOptions);\n\t\t},\n\t\tget store() {\n\t\t\treturn store;\n\t\t},\n\t\tProvider: (props) => (\n\t\t\t<ToastContext value={api}>{props.children}</ToastContext>\n\t\t),\n\t};\n\t(api as ToastApi & Snapshottable)[SNAPSHOT_KEYS] = TOAST_SNAPSHOT_KEYS;\n\treturn api;\n}\n\nconst TOAST_SNAPSHOT_KEYS = snapshotKeys<ToastApi>(\n\t\"toasts\",\n\t\"expanded\",\n\t\"hovering\",\n\t\"focused\",\n\t\"isEmpty\",\n);\n"],"mappings":"AACA,SAECA,aAAa,EACbC,YAAY,EACZC,UAAU,QACJ,UAAU;AACjB,SAA6BC,UAAU,QAAQ,6BAA6B;AAC5E,SACCC,aAAa,EAEbC,YAAY,QACN,qCAAqC;AAE5C,SAASC,gBAAgB,QAAyB,eAAe;;AAUjE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAqBA;AACA;AACA;;AAoCA,MAAMC,YAAY,GAAGP,aAAa,CAAkB,IAAI,CAAC;;AAEzD;AACA;AACA;AACA;AACA,OAAO,SAASQ,QAAQA,CAAA,EAAa;EACpC,MAAMC,GAAG,GAAGP,UAAU,CAACK,YAAY,CAAC;EACpC,IAAIE,GAAG,IAAI,IAAI,EAAE;IAChB,MAAM,IAAIC,KAAK,CACd,2DACD,CAAC;EACF;EACA,OAAOD,GAAG;AACX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,WAAWA,CAACC,OAA2B,GAAG,CAAC,CAAC,EAAY;EACvE,MAAMC,cAAc,GAAGV,UAAU,CAACS,OAAO,CAACE,OAAO,CAAC,IAAI,IAAI;EAC1D,MAAMC,YAAY,GAAGZ,UAAU,CAACS,OAAO,CAACI,KAAK,CAAC,IAAI,CAAC;EAEnD,MAAMC,KAAK,GAAGX,gBAAgB,CAAC;IAC9BQ,OAAO,EAAED,cAAc;IACvBG,KAAK,EAAED;EACR,CAAC,CAAC;;EAEF;EACA;EACAd,YAAY,CACX,MAAME,UAAU,CAACS,OAAO,CAACE,OAAO,CAAC,IAAI,IAAI,EACxCI,IAAY,IAAK;IACjBD,KAAK,CAACE,gBAAgB,CAACD,IAAI,CAAC;EAC7B,CACD,CAAC;EACDjB,YAAY,CACX,MAAME,UAAU,CAAC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