{"version":3,"names":["untrack","SNAPSHOT_KEYS","Symbol","for","snapshot","c","explicit","call","keys","Array","isArray","out","key","v","snapshotKeys"],"sources":["snapshot.ts"],"sourcesContent":["import { untrack } from \"solid-js\";\n\n// Stage 04 — observability spike.\n//\n// `snapshot(c)` is the one-shot, untracked, plain-object representation of\n// a compound's state. Used by:\n//\n//   - Devtools dumps.\n//   - `JSON.stringify(snapshot(c))` for persistence / SSR payloads.\n//   - Test assertions: `expect(snapshot(c)).toEqual({...})`.\n//\n// **Design choice — explicit opt-in over auto-iteration.** A compound's\n// API object mixes state accessors (`c.open()`), slot getters\n// (`c.trigger(props?)`), setters (`c.setOpen`), methods (`c.toggle`),\n// directives (`c.triggerRef`), and a Provider component. Auto-iterating\n// own enumerable properties and \"calling every function\" would invoke\n// slot getters (allocating per-call) and the Provider component. Wrong.\n//\n// Instead: each compound declares its observable surface via the\n// `SNAPSHOT_KEYS` symbol, OR ships a `snapshot()` method (escape hatch).\n// The library's helper is a tiny dispatcher; the contract lives at the\n// compound's own definition site.\n//\n// Companion doc: work-left/primitive-template.md §2.5.\n\nexport const SNAPSHOT_KEYS = Symbol.for(\"base-ui.snapshot-keys\");\n\nexport interface Snapshottable {\n\t/** Per-compound declared observable surface. */\n\t[SNAPSHOT_KEYS]?: readonly string[];\n\t/**\n\t * Optional override that takes precedence over `SNAPSHOT_KEYS`. Use\n\t * when the snapshot shape is computed (e.g. async-shaped compounds\n\t * that want to project a stable `{ status, items }` payload regardless\n\t * of internal accessor names).\n\t */\n\tsnapshot?: () => Record<string, unknown>;\n}\n\n/**\n * Read the declared state surface of a compound API object as a plain\n * object. Reads are untracked — calling `snapshot(c)` does NOT subscribe\n * the caller to future state changes; it returns a frozen-in-time view.\n *\n * If neither `snapshot()` nor `SNAPSHOT_KEYS` is declared, returns `{}`.\n * The library does not auto-iterate own properties (see file header).\n */\nexport function snapshot<C extends object>(c: C): Record<string, unknown> {\n\treturn untrack(() => {\n\t\tconst explicit = (c as Snapshottable).snapshot;\n\t\tif (typeof explicit === \"function\") {\n\t\t\treturn explicit.call(c);\n\t\t}\n\t\tconst keys = (c as Snapshottable)[SNAPSHOT_KEYS];\n\t\tif (Array.isArray(keys)) {\n\t\t\tconst out: Record<string, unknown> = {};\n\t\t\tfor (const key of keys) {\n\t\t\t\tconst v = (c as Record<string, unknown>)[key];\n\t\t\t\tout[key] = typeof v === \"function\" ? (v as () => unknown).call(c) : v;\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\treturn {};\n\t});\n}\n\n/**\n * Convenience for declaring `SNAPSHOT_KEYS` with type-safe key names.\n * Returns the key tuple; use as\n *\n *   return { ...api, [SNAPSHOT_KEYS]: snapshotKeys<MyApi>('open', 'disabled') };\n *\n * Compile-time check that every passed key exists on the API type.\n */\nexport function snapshotKeys<C>(\n\t...keys: ReadonlyArray<keyof C & string>\n): readonly string[] {\n\treturn keys;\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,UAAU;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMC,aAAa,GAAGC,MAAM,CAACC,GAAG,CAAC,uBAAuB,CAAC;AAchE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAAmBC,CAAI,EAA2B;EACzE,OAAOL,OAAO,CAAC,MAAM;IACpB,MAAMM,QAAQ,GAAID,CAAC,CAAmBD,QAAQ;IAC9C,IAAI,OAAOE,QAAQ,KAAK,UAAU,EAAE;MACnC,OAAOA,QAAQ,CAACC,IAAI,CAACF,CAAC,CAAC;IACxB;IACA,MAAMG,IAAI,GAAIH,CAAC,CAAmBJ,aAAa,CAAC;IAChD,IAAIQ,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,EAAE;MACxB,MAAMG,GAA4B,GAAG,CAAC,CAAC;MACvC,KAAK,MAAMC,GAAG,IAAIJ,IAAI,EAAE;QACvB,MAAMK,CAAC,GAAIR,CAAC,CAA6BO,GAAG,CAAC;QAC7CD,GAAG,CAACC,GAAG,CAAC,GAAG,OAAOC,CAAC,KAAK,UAAU,GAAIA,CAAC,CAAmBN,IAAI,CAACF,CAAC,CAAC,GAAGQ,CAAC;MACtE;MACA,OAAOF,GAAG;IACX;IACA,OAAO,CAAC,CAAC;EACV,CAAC,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,YAAYA,CAC3B,GAAGN,IAAqC,EACpB;EACpB,OAAOA,IAAI;AACZ","ignoreList":[]}