@mhmo91/schmancy 0.10.16 → 0.10.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/dist/active-host-BP0zy_Y9.js.map +1 -1
  2. package/dist/agent/flow-CvG1fLW5.js.map +1 -1
  3. package/dist/agent/schmancy.agent.js +3704 -3704
  4. package/dist/agent/schmancy.agent.js.map +1 -1
  5. package/dist/agent/vendor-material-color-DcL7ZPxx.js.map +1 -1
  6. package/dist/animation-DCznELuT.js.map +1 -1
  7. package/dist/area-ChxsDTu_.js.map +1 -1
  8. package/dist/area-Qt6yUnuA.cjs.map +1 -1
  9. package/dist/audio-DS43uoRA.js.map +1 -1
  10. package/dist/autocomplete-CXvUjMD-.js.map +1 -1
  11. package/dist/autocomplete-Ck2zbdF9.cjs.map +1 -1
  12. package/dist/avatar.cjs +1 -1
  13. package/dist/avatar.js +1 -1
  14. package/dist/avatar.js.map +1 -1
  15. package/dist/badge.cjs +1 -1
  16. package/dist/badge.js +1 -1
  17. package/dist/boat-Bj0wVcZi.js.map +1 -1
  18. package/dist/breadcrumb.js.map +1 -1
  19. package/dist/busy-CyZSBnZP.js.map +1 -1
  20. package/dist/button.js.map +1 -1
  21. package/dist/card-nYZCKmOO.js.map +1 -1
  22. package/dist/checkbox-DiUrZiyc.js.map +1 -1
  23. package/dist/chips-CfPFXv7Z.js.map +1 -1
  24. package/dist/chips-DK6m-VCM.cjs.map +1 -1
  25. package/dist/connectivity.js.map +1 -1
  26. package/dist/content-drawer.cjs +1 -1
  27. package/dist/content-drawer.js +1 -1
  28. package/dist/cursor-glow-Cs2XLDB9.js.map +1 -1
  29. package/dist/date-range-DA6anfcF.cjs.map +1 -1
  30. package/dist/date-range-DjlF2u7o.js.map +1 -1
  31. package/dist/date-range-inline-BfYK795W.cjs.map +1 -1
  32. package/dist/date-range-inline-n7y_H6PJ.js.map +1 -1
  33. package/dist/delay.js.map +1 -1
  34. package/dist/details-BdAVsLl-.cjs.map +1 -1
  35. package/dist/details-CS_ToAOj.js.map +1 -1
  36. package/dist/directives.cjs.map +1 -1
  37. package/dist/directives.js.map +1 -1
  38. package/dist/discovery.js.map +1 -1
  39. package/dist/divider-COLK0RbT.js.map +1 -1
  40. package/dist/dropdown.js.map +1 -1
  41. package/dist/expand-D9LzmpoV.js.map +1 -1
  42. package/dist/expand-r2sATPUJ.cjs.map +1 -1
  43. package/dist/{form-DhjedCWm.js → form-D1iJOLVb.js} +9 -0
  44. package/dist/{form-DhjedCWm.js.map → form-D1iJOLVb.js.map} +1 -1
  45. package/dist/form-D9K1GhlP.cjs +42 -0
  46. package/dist/{form-g5c70rac.cjs.map → form-D9K1GhlP.cjs.map} +1 -1
  47. package/dist/form.cjs +1 -1
  48. package/dist/form.js +9 -2
  49. package/dist/handover/agent-runtime-followups.md +1 -1
  50. package/dist/handover/agent-runtime-v1.md +3 -3
  51. package/dist/hashContent-dJrI-9sc.js.map +1 -1
  52. package/dist/{icons-1HIENBco.cjs.map → icons-BXp4vbnW.cjs.map} +1 -1
  53. package/dist/{icons-3y0kr1aB.js.map → icons-COrlmBPB.js.map} +1 -1
  54. package/dist/icons.cjs +1 -1
  55. package/dist/icons.js +1 -1
  56. package/dist/{iframe-CjqYuZG5.cjs.map → iframe-BwXj6mLp.cjs.map} +1 -1
  57. package/dist/{iframe-Z5gTK-gd.js.map → iframe-CPNsIy7k.js.map} +1 -1
  58. package/dist/iframe.cjs +1 -1
  59. package/dist/iframe.js +1 -1
  60. package/dist/index.cjs +1 -1
  61. package/dist/index.js +32 -32
  62. package/dist/{input-BtcIhu0Q.cjs.map → input-BGrF2qVq.cjs.map} +1 -1
  63. package/dist/{input-B-fw6f_r.js.map → input-C1SnMNuQ.js.map} +1 -1
  64. package/dist/input-chip-CtQ0pH5b.js.map +1 -1
  65. package/dist/input-chip-DZktYohr.cjs.map +1 -1
  66. package/dist/input.cjs +1 -1
  67. package/dist/input.js +1 -1
  68. package/dist/json.cjs +1 -1
  69. package/dist/json.js +1 -1
  70. package/dist/json.js.map +1 -1
  71. package/dist/kbd.js.map +1 -1
  72. package/dist/layout-BH28sKGc.js.map +1 -1
  73. package/dist/layout.cjs +1 -1
  74. package/dist/layout.js +1 -1
  75. package/dist/lazy-D-bO2r4m.js.map +1 -1
  76. package/dist/{lightbox-BL3LWp-P.js.map → lightbox-CLwpaiai.js.map} +1 -1
  77. package/dist/{lightbox-BHTZOn8K.cjs.map → lightbox-Ck6BpN5u.cjs.map} +1 -1
  78. package/dist/lightbox.cjs +1 -1
  79. package/dist/lightbox.js +1 -1
  80. package/dist/{list-DLJL1JQj.js.map → list-Bmce1Rb8.js.map} +1 -1
  81. package/dist/{list-CHYa5VGY.cjs.map → list-EmRwSpTU.cjs.map} +1 -1
  82. package/dist/list.cjs +1 -1
  83. package/dist/list.js +1 -1
  84. package/dist/magnetic-DxvoEz8_.js.map +1 -1
  85. package/dist/{menu-BNq93w6X.js.map → menu-BA_B7QOG.js.map} +1 -1
  86. package/dist/{menu-DAikvkeV.cjs.map → menu-BTU3wGP6.cjs.map} +1 -1
  87. package/dist/menu.cjs +1 -1
  88. package/dist/menu.js +1 -1
  89. package/dist/mixins-BOOu6q2n.cjs.map +1 -1
  90. package/dist/mixins-BWb9_e1s.js.map +1 -1
  91. package/dist/nav-drawer.cjs +1 -1
  92. package/dist/nav-drawer.js +1 -1
  93. package/dist/navigation-bar.cjs +1 -1
  94. package/dist/navigation-bar.js +1 -1
  95. package/dist/navigation-rail.js.map +1 -1
  96. package/dist/{notification-Dy2azMyt.cjs → notification-CliGbcfU.cjs} +1 -1
  97. package/dist/{notification-Dy2azMyt.cjs.map → notification-CliGbcfU.cjs.map} +1 -1
  98. package/dist/{notification-CUmb9c3Y.js → notification-R2_Mf1HR.js} +1 -1
  99. package/dist/{notification-CUmb9c3Y.js.map → notification-R2_Mf1HR.js.map} +1 -1
  100. package/dist/notification.cjs +1 -1
  101. package/dist/notification.js +1 -1
  102. package/dist/{option-DFvQ551b.js.map → option-DU1X4SDu.js.map} +1 -1
  103. package/dist/{option-CDgIKifG.cjs.map → option-Db98Ndzv.cjs.map} +1 -1
  104. package/dist/option.cjs +1 -1
  105. package/dist/option.js +1 -1
  106. package/dist/overlay-stack-BR4iYivO.js.map +1 -1
  107. package/dist/overlay.cjs.map +1 -1
  108. package/dist/overlay.confirm-body-uFp-0Zfh.js.map +1 -1
  109. package/dist/overlay.js.map +1 -1
  110. package/dist/overlay.service-1YWfUD2S.cjs.map +1 -1
  111. package/dist/overlay.service-BcF12kGb.js.map +1 -1
  112. package/dist/page.cjs +1 -1
  113. package/dist/page.js +1 -1
  114. package/dist/page.js.map +1 -1
  115. package/dist/{progress-bLbGRuQ1.js.map → progress-C9Y2D5cm.js.map} +1 -1
  116. package/dist/{progress-C02sWkmE.cjs.map → progress-DiVTGAXa.cjs.map} +1 -1
  117. package/dist/progress.cjs +1 -1
  118. package/dist/progress.js +1 -1
  119. package/dist/{radio-group-DA4eIGCj.js.map → radio-group-CAzjBI2n.js.map} +1 -1
  120. package/dist/{radio-group-BA-jRct5.cjs.map → radio-group-DIRJyYv6.cjs.map} +1 -1
  121. package/dist/radio-group.cjs +1 -1
  122. package/dist/radio-group.js +1 -1
  123. package/dist/range.js.map +1 -1
  124. package/dist/reduced-motion-D7LqTUMn.js.map +1 -1
  125. package/dist/{rxjs-utils-kWPShgKu.cjs.map → rxjs-utils-BKB2UM_j.cjs.map} +1 -1
  126. package/dist/{rxjs-utils-D9U4MW0Q.js.map → rxjs-utils-Dv9T9IpA.js.map} +1 -1
  127. package/dist/rxjs-utils.cjs +1 -1
  128. package/dist/rxjs-utils.js +1 -1
  129. package/dist/{scroll-CG5up5oy.js.map → scroll-BFHUtZOa.js.map} +1 -1
  130. package/dist/{scroll-D8vBF_gY.cjs.map → scroll-nIZyoEMt.cjs.map} +1 -1
  131. package/dist/search-MvIBA93K.js.map +1 -1
  132. package/dist/{select-BrK1BJoU.js → select-7WqaUWBU.js} +1 -1
  133. package/dist/{select-BrK1BJoU.js.map → select-7WqaUWBU.js.map} +1 -1
  134. package/dist/{select-Dh2j7Qc-.cjs → select-DTuf6p6T.cjs} +1 -1
  135. package/dist/{select-Dh2j7Qc-.cjs.map → select-DTuf6p6T.cjs.map} +1 -1
  136. package/dist/select.cjs +1 -1
  137. package/dist/select.js +1 -1
  138. package/dist/skeleton.js.map +1 -1
  139. package/dist/skills/SKILL.md +3 -0
  140. package/dist/skills/schmancy/SKILL.md +3 -0
  141. package/dist/slider.js.map +1 -1
  142. package/dist/sound.service-BIN2W7Rv.js.map +1 -1
  143. package/dist/splash-screen-BcjjJSlK.js.map +1 -1
  144. package/dist/{src-B2-CU8fu.cjs → src-BbMJeLk9.cjs} +1 -1
  145. package/dist/{src-B2-CU8fu.cjs.map → src-BbMJeLk9.cjs.map} +1 -1
  146. package/dist/{src-DvywUq7l.js → src-DCu_mEk4.js} +18 -18
  147. package/dist/{src-DvywUq7l.js.map → src-DCu_mEk4.js.map} +1 -1
  148. package/dist/state-avic94Ft.cjs.map +1 -1
  149. package/dist/state-nm8yzMPp.js.map +1 -1
  150. package/dist/steps.js.map +1 -1
  151. package/dist/surface-BtMMHKol.js.map +1 -1
  152. package/dist/switch.js.map +1 -1
  153. package/dist/table.js.map +1 -1
  154. package/dist/{tabs-CikPr7by.js.map → tabs-81ADWQqa.js.map} +1 -1
  155. package/dist/{tabs-CitVls3_.cjs.map → tabs-DnG3K0bu.cjs.map} +1 -1
  156. package/dist/tabs.cjs +1 -1
  157. package/dist/tabs.js +1 -1
  158. package/dist/teleport.cjs +1 -1
  159. package/dist/teleport.js +1 -1
  160. package/dist/{textarea-DVkwQSis.js.map → textarea-3mWewuAf.js.map} +1 -1
  161. package/dist/{textarea-CqV1wvmB.cjs.map → textarea-BenjiTXB.cjs.map} +1 -1
  162. package/dist/textarea.cjs +1 -1
  163. package/dist/textarea.js +1 -1
  164. package/dist/{theme-BIWS4TOW.js → theme-CFPJW933.js} +1 -1
  165. package/dist/{theme-BIWS4TOW.js.map → theme-CFPJW933.js.map} +1 -1
  166. package/dist/{theme-DMgjiKda.cjs → theme-DNymrucy.cjs} +1 -1
  167. package/dist/{theme-DMgjiKda.cjs.map → theme-DNymrucy.cjs.map} +1 -1
  168. package/dist/theme-button-DC_shZ_7.js.map +1 -1
  169. package/dist/theme.cjs +1 -1
  170. package/dist/{theme.interface-C8OHheXg.js.map → theme.interface-C2XNgsLB.js.map} +1 -1
  171. package/dist/{theme.interface-CYo4UpWK.cjs.map → theme.interface-D4NeufQA.cjs.map} +1 -1
  172. package/dist/theme.js +2 -2
  173. package/dist/theme.service-BOWIT_5k.js.map +1 -1
  174. package/dist/tooltip.js.map +1 -1
  175. package/dist/tree.js.map +1 -1
  176. package/dist/types.js.map +1 -1
  177. package/dist/typewriter.cjs.map +1 -1
  178. package/dist/typewriter.js.map +1 -1
  179. package/dist/typography.js.map +1 -1
  180. package/dist/utils-Cj_nRRyx.js.map +1 -1
  181. package/dist/visually-hidden.js.map +1 -1
  182. package/dist/window-BTecgE_U.js.map +1 -1
  183. package/package.json +1 -1
  184. package/skills/schmancy/SKILL.md +3 -0
  185. package/src/form/fields/index.ts +9 -0
  186. package/src/form/index.ts +1 -0
  187. package/types/src/form/fields/index.d.ts +9 -0
  188. package/types/src/form/index.d.ts +1 -0
  189. package/dist/form-g5c70rac.cjs +0 -42
  190. /package/dist/{icons-1HIENBco.cjs → icons-BXp4vbnW.cjs} +0 -0
  191. /package/dist/{icons-3y0kr1aB.js → icons-COrlmBPB.js} +0 -0
  192. /package/dist/{iframe-CjqYuZG5.cjs → iframe-BwXj6mLp.cjs} +0 -0
  193. /package/dist/{iframe-Z5gTK-gd.js → iframe-CPNsIy7k.js} +0 -0
  194. /package/dist/{input-BtcIhu0Q.cjs → input-BGrF2qVq.cjs} +0 -0
  195. /package/dist/{input-B-fw6f_r.js → input-C1SnMNuQ.js} +0 -0
  196. /package/dist/{lightbox-BL3LWp-P.js → lightbox-CLwpaiai.js} +0 -0
  197. /package/dist/{lightbox-BHTZOn8K.cjs → lightbox-Ck6BpN5u.cjs} +0 -0
  198. /package/dist/{list-DLJL1JQj.js → list-Bmce1Rb8.js} +0 -0
  199. /package/dist/{list-CHYa5VGY.cjs → list-EmRwSpTU.cjs} +0 -0
  200. /package/dist/{menu-BNq93w6X.js → menu-BA_B7QOG.js} +0 -0
  201. /package/dist/{menu-DAikvkeV.cjs → menu-BTU3wGP6.cjs} +0 -0
  202. /package/dist/{option-DFvQ551b.js → option-DU1X4SDu.js} +0 -0
  203. /package/dist/{option-CDgIKifG.cjs → option-Db98Ndzv.cjs} +0 -0
  204. /package/dist/{progress-bLbGRuQ1.js → progress-C9Y2D5cm.js} +0 -0
  205. /package/dist/{progress-C02sWkmE.cjs → progress-DiVTGAXa.cjs} +0 -0
  206. /package/dist/{radio-group-DA4eIGCj.js → radio-group-CAzjBI2n.js} +0 -0
  207. /package/dist/{radio-group-BA-jRct5.cjs → radio-group-DIRJyYv6.cjs} +0 -0
  208. /package/dist/{rxjs-utils-kWPShgKu.cjs → rxjs-utils-BKB2UM_j.cjs} +0 -0
  209. /package/dist/{rxjs-utils-D9U4MW0Q.js → rxjs-utils-Dv9T9IpA.js} +0 -0
  210. /package/dist/{scroll-CG5up5oy.js → scroll-BFHUtZOa.js} +0 -0
  211. /package/dist/{scroll-D8vBF_gY.cjs → scroll-nIZyoEMt.cjs} +0 -0
  212. /package/dist/{tabs-CikPr7by.js → tabs-81ADWQqa.js} +0 -0
  213. /package/dist/{tabs-CitVls3_.cjs → tabs-DnG3K0bu.cjs} +0 -0
  214. /package/dist/{textarea-DVkwQSis.js → textarea-3mWewuAf.js} +0 -0
  215. /package/dist/{textarea-CqV1wvmB.cjs → textarea-BenjiTXB.cjs} +0 -0
  216. /package/dist/{theme.interface-C8OHheXg.js → theme.interface-C2XNgsLB.js} +0 -0
  217. /package/dist/{theme.interface-CYo4UpWK.cjs → theme.interface-D4NeufQA.cjs} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"state-nm8yzMPp.js","names":["finalize","#data","#db","#opening"],"sources":["../node_modules/immer/dist/immer.mjs","../src/state/persist.ts","../src/state/schmancy-context.ts","../src/state/index.ts"],"sourcesContent":["// src/utils/env.ts\nvar NOTHING = Symbol.for(\"immer-nothing\");\nvar DRAFTABLE = Symbol.for(\"immer-draftable\");\nvar DRAFT_STATE = Symbol.for(\"immer-state\");\n\n// src/utils/errors.ts\nvar errors = process.env.NODE_ENV !== \"production\" ? [\n // All error codes, starting by 0:\n function(plugin) {\n return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \\`enable${plugin}()\\` when initializing your application.`;\n },\n function(thing) {\n return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;\n },\n \"This object has been frozen and should not be mutated\",\n function(data) {\n return \"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? \" + data;\n },\n \"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.\",\n \"Immer forbids circular references\",\n \"The first or second argument to `produce` must be a function\",\n \"The third argument to `produce` must be a function or undefined\",\n \"First argument to `createDraft` must be a plain object, an array, or an immerable object\",\n \"First argument to `finishDraft` must be a draft returned by `createDraft`\",\n function(thing) {\n return `'current' expects a draft, got: ${thing}`;\n },\n \"Object.defineProperty() cannot be used on an Immer draft\",\n \"Object.setPrototypeOf() cannot be used on an Immer draft\",\n \"Immer only supports deleting array indices\",\n \"Immer only supports setting array indices and the 'length' property\",\n function(thing) {\n return `'original' expects a draft, got: ${thing}`;\n }\n // Note: if more errors are added, the errorOffset in Patches.ts should be increased\n // See Patches.ts for additional errors\n] : [];\nfunction die(error, ...args) {\n if (process.env.NODE_ENV !== \"production\") {\n const e = errors[error];\n const msg = isFunction(e) ? e.apply(null, args) : e;\n throw new Error(`[Immer] ${msg}`);\n }\n throw new Error(\n `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`\n );\n}\n\n// src/utils/common.ts\nvar O = Object;\nvar getPrototypeOf = O.getPrototypeOf;\nvar CONSTRUCTOR = \"constructor\";\nvar PROTOTYPE = \"prototype\";\nvar CONFIGURABLE = \"configurable\";\nvar ENUMERABLE = \"enumerable\";\nvar WRITABLE = \"writable\";\nvar VALUE = \"value\";\nvar isDraft = (value) => !!value && !!value[DRAFT_STATE];\nfunction isDraftable(value) {\n if (!value)\n return false;\n return isPlainObject(value) || isArray(value) || !!value[DRAFTABLE] || !!value[CONSTRUCTOR]?.[DRAFTABLE] || isMap(value) || isSet(value);\n}\nvar objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString();\nvar cachedCtorStrings = /* @__PURE__ */ new WeakMap();\nfunction isPlainObject(value) {\n if (!value || !isObjectish(value))\n return false;\n const proto = getPrototypeOf(value);\n if (proto === null || proto === O[PROTOTYPE])\n return true;\n const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR];\n if (Ctor === Object)\n return true;\n if (!isFunction(Ctor))\n return false;\n let ctorString = cachedCtorStrings.get(Ctor);\n if (ctorString === void 0) {\n ctorString = Function.toString.call(Ctor);\n cachedCtorStrings.set(Ctor, ctorString);\n }\n return ctorString === objectCtorString;\n}\nfunction original(value) {\n if (!isDraft(value))\n die(15, value);\n return value[DRAFT_STATE].base_;\n}\nfunction each(obj, iter, strict = true) {\n if (getArchtype(obj) === 0 /* Object */) {\n const keys = strict ? Reflect.ownKeys(obj) : O.keys(obj);\n keys.forEach((key) => {\n iter(key, obj[key], obj);\n });\n } else {\n obj.forEach((entry, index) => iter(index, entry, obj));\n }\n}\nfunction getArchtype(thing) {\n const state = thing[DRAFT_STATE];\n return state ? state.type_ : isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;\n}\nvar has = (thing, prop, type = getArchtype(thing)) => type === 2 /* Map */ ? thing.has(prop) : O[PROTOTYPE].hasOwnProperty.call(thing, prop);\nvar get = (thing, prop, type = getArchtype(thing)) => (\n // @ts-ignore\n type === 2 /* Map */ ? thing.get(prop) : thing[prop]\n);\nvar set = (thing, propOrOldValue, value, type = getArchtype(thing)) => {\n if (type === 2 /* Map */)\n thing.set(propOrOldValue, value);\n else if (type === 3 /* Set */) {\n thing.add(value);\n } else\n thing[propOrOldValue] = value;\n};\nfunction is(x, y) {\n if (x === y) {\n return x !== 0 || 1 / x === 1 / y;\n } else {\n return x !== x && y !== y;\n }\n}\nvar isArray = Array.isArray;\nvar isMap = (target) => target instanceof Map;\nvar isSet = (target) => target instanceof Set;\nvar isObjectish = (target) => typeof target === \"object\";\nvar isFunction = (target) => typeof target === \"function\";\nvar isBoolean = (target) => typeof target === \"boolean\";\nfunction isArrayIndex(value) {\n const n = +value;\n return Number.isInteger(n) && String(n) === value;\n}\nvar getProxyDraft = (value) => {\n if (!isObjectish(value))\n return null;\n return value?.[DRAFT_STATE];\n};\nvar latest = (state) => state.copy_ || state.base_;\nvar getValue = (value) => {\n const proxyDraft = getProxyDraft(value);\n return proxyDraft ? proxyDraft.copy_ ?? proxyDraft.base_ : value;\n};\nvar getFinalValue = (state) => state.modified_ ? state.copy_ : state.base_;\nfunction shallowCopy(base, strict) {\n if (isMap(base)) {\n return new Map(base);\n }\n if (isSet(base)) {\n return new Set(base);\n }\n if (isArray(base))\n return Array[PROTOTYPE].slice.call(base);\n const isPlain = isPlainObject(base);\n if (strict === true || strict === \"class_only\" && !isPlain) {\n const descriptors = O.getOwnPropertyDescriptors(base);\n delete descriptors[DRAFT_STATE];\n let keys = Reflect.ownKeys(descriptors);\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const desc = descriptors[key];\n if (desc[WRITABLE] === false) {\n desc[WRITABLE] = true;\n desc[CONFIGURABLE] = true;\n }\n if (desc.get || desc.set)\n descriptors[key] = {\n [CONFIGURABLE]: true,\n [WRITABLE]: true,\n // could live with !!desc.set as well here...\n [ENUMERABLE]: desc[ENUMERABLE],\n [VALUE]: base[key]\n };\n }\n return O.create(getPrototypeOf(base), descriptors);\n } else {\n const proto = getPrototypeOf(base);\n if (proto !== null && isPlain) {\n return { ...base };\n }\n const obj = O.create(proto);\n return O.assign(obj, base);\n }\n}\nfunction freeze(obj, deep = false) {\n if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))\n return obj;\n if (getArchtype(obj) > 1) {\n O.defineProperties(obj, {\n set: dontMutateMethodOverride,\n add: dontMutateMethodOverride,\n clear: dontMutateMethodOverride,\n delete: dontMutateMethodOverride\n });\n }\n O.freeze(obj);\n if (deep)\n each(\n obj,\n (_key, value) => {\n freeze(value, true);\n },\n false\n );\n return obj;\n}\nfunction dontMutateFrozenCollections() {\n die(2);\n}\nvar dontMutateMethodOverride = {\n [VALUE]: dontMutateFrozenCollections\n};\nfunction isFrozen(obj) {\n if (obj === null || !isObjectish(obj))\n return true;\n return O.isFrozen(obj);\n}\n\n// src/utils/plugins.ts\nvar PluginMapSet = \"MapSet\";\nvar PluginPatches = \"Patches\";\nvar PluginArrayMethods = \"ArrayMethods\";\nvar plugins = {};\nfunction getPlugin(pluginKey) {\n const plugin = plugins[pluginKey];\n if (!plugin) {\n die(0, pluginKey);\n }\n return plugin;\n}\nvar isPluginLoaded = (pluginKey) => !!plugins[pluginKey];\nfunction loadPlugin(pluginKey, implementation) {\n if (!plugins[pluginKey])\n plugins[pluginKey] = implementation;\n}\n\n// src/core/scope.ts\nvar currentScope;\nvar getCurrentScope = () => currentScope;\nvar createScope = (parent_, immer_) => ({\n drafts_: [],\n parent_,\n immer_,\n // Whenever the modified draft contains a draft from another scope, we\n // need to prevent auto-freezing so the unowned draft can be finalized.\n canAutoFreeze_: true,\n unfinalizedDrafts_: 0,\n handledSet_: /* @__PURE__ */ new Set(),\n processedForPatches_: /* @__PURE__ */ new Set(),\n mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0,\n arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) ? getPlugin(PluginArrayMethods) : void 0\n});\nfunction usePatchesInScope(scope, patchListener) {\n if (patchListener) {\n scope.patchPlugin_ = getPlugin(PluginPatches);\n scope.patches_ = [];\n scope.inversePatches_ = [];\n scope.patchListener_ = patchListener;\n }\n}\nfunction revokeScope(scope) {\n leaveScope(scope);\n scope.drafts_.forEach(revokeDraft);\n scope.drafts_ = null;\n}\nfunction leaveScope(scope) {\n if (scope === currentScope) {\n currentScope = scope.parent_;\n }\n}\nvar enterScope = (immer2) => currentScope = createScope(currentScope, immer2);\nfunction revokeDraft(draft) {\n const state = draft[DRAFT_STATE];\n if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)\n state.revoke_();\n else\n state.revoked_ = true;\n}\n\n// src/core/finalize.ts\nfunction processResult(result, scope) {\n scope.unfinalizedDrafts_ = scope.drafts_.length;\n const baseDraft = scope.drafts_[0];\n const isReplaced = result !== void 0 && result !== baseDraft;\n if (isReplaced) {\n if (baseDraft[DRAFT_STATE].modified_) {\n revokeScope(scope);\n die(4);\n }\n if (isDraftable(result)) {\n result = finalize(scope, result);\n }\n const { patchPlugin_ } = scope;\n if (patchPlugin_) {\n patchPlugin_.generateReplacementPatches_(\n baseDraft[DRAFT_STATE].base_,\n result,\n scope\n );\n }\n } else {\n result = finalize(scope, baseDraft);\n }\n maybeFreeze(scope, result, true);\n revokeScope(scope);\n if (scope.patches_) {\n scope.patchListener_(scope.patches_, scope.inversePatches_);\n }\n return result !== NOTHING ? result : void 0;\n}\nfunction finalize(rootScope, value) {\n if (isFrozen(value))\n return value;\n const state = value[DRAFT_STATE];\n if (!state) {\n const finalValue = handleValue(value, rootScope.handledSet_, rootScope);\n return finalValue;\n }\n if (!isSameScope(state, rootScope)) {\n return value;\n }\n if (!state.modified_) {\n return state.base_;\n }\n if (!state.finalized_) {\n const { callbacks_ } = state;\n if (callbacks_) {\n while (callbacks_.length > 0) {\n const callback = callbacks_.pop();\n callback(rootScope);\n }\n }\n generatePatchesAndFinalize(state, rootScope);\n }\n return state.copy_;\n}\nfunction maybeFreeze(scope, value, deep = false) {\n if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {\n freeze(value, deep);\n }\n}\nfunction markStateFinalized(state) {\n state.finalized_ = true;\n state.scope_.unfinalizedDrafts_--;\n}\nvar isSameScope = (state, rootScope) => state.scope_ === rootScope;\nvar EMPTY_LOCATIONS_RESULT = [];\nfunction updateDraftInParent(parent, draftValue, finalizedValue, originalKey) {\n const parentCopy = latest(parent);\n const parentType = parent.type_;\n if (originalKey !== void 0) {\n const currentValue = get(parentCopy, originalKey, parentType);\n if (currentValue === draftValue) {\n set(parentCopy, originalKey, finalizedValue, parentType);\n return;\n }\n }\n if (!parent.draftLocations_) {\n const draftLocations = parent.draftLocations_ = /* @__PURE__ */ new Map();\n each(parentCopy, (key, value) => {\n if (isDraft(value)) {\n const keys = draftLocations.get(value) || [];\n keys.push(key);\n draftLocations.set(value, keys);\n }\n });\n }\n const locations = parent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT;\n for (const location of locations) {\n set(parentCopy, location, finalizedValue, parentType);\n }\n}\nfunction registerChildFinalizationCallback(parent, child, key) {\n parent.callbacks_.push(function childCleanup(rootScope) {\n const state = child;\n if (!state || !isSameScope(state, rootScope)) {\n return;\n }\n rootScope.mapSetPlugin_?.fixSetContents(state);\n const finalizedValue = getFinalValue(state);\n updateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key);\n generatePatchesAndFinalize(state, rootScope);\n });\n}\nfunction generatePatchesAndFinalize(state, rootScope) {\n const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 /* Set */ || state.type_ === 1 /* Array */ && state.allIndicesReassigned_ || (state.assigned_?.size ?? 0) > 0);\n if (shouldFinalize) {\n const { patchPlugin_ } = rootScope;\n if (patchPlugin_) {\n const basePath = patchPlugin_.getPath(state);\n if (basePath) {\n patchPlugin_.generatePatches_(state, basePath, rootScope);\n }\n }\n markStateFinalized(state);\n }\n}\nfunction handleCrossReference(target, key, value) {\n const { scope_ } = target;\n if (isDraft(value)) {\n const state = value[DRAFT_STATE];\n if (isSameScope(state, scope_)) {\n state.callbacks_.push(function crossReferenceCleanup() {\n prepareCopy(target);\n const finalizedValue = getFinalValue(state);\n updateDraftInParent(target, value, finalizedValue, key);\n });\n }\n } else if (isDraftable(value)) {\n target.callbacks_.push(function nestedDraftCleanup() {\n const targetCopy = latest(target);\n if (target.type_ === 3 /* Set */) {\n if (targetCopy.has(value)) {\n handleValue(value, scope_.handledSet_, scope_);\n }\n } else {\n if (get(targetCopy, key, target.type_) === value) {\n if (scope_.drafts_.length > 1 && (target.assigned_.get(key) ?? false) === true && target.copy_) {\n handleValue(\n get(target.copy_, key, target.type_),\n scope_.handledSet_,\n scope_\n );\n }\n }\n }\n });\n }\n}\nfunction handleValue(target, handledSet, rootScope) {\n if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {\n return target;\n }\n if (isDraft(target) || handledSet.has(target) || !isDraftable(target) || isFrozen(target)) {\n return target;\n }\n handledSet.add(target);\n each(target, (key, value) => {\n if (isDraft(value)) {\n const state = value[DRAFT_STATE];\n if (isSameScope(state, rootScope)) {\n const updatedValue = getFinalValue(state);\n set(target, key, updatedValue, target.type_);\n markStateFinalized(state);\n }\n } else if (isDraftable(value)) {\n handleValue(value, handledSet, rootScope);\n }\n });\n return target;\n}\n\n// src/core/proxy.ts\nfunction createProxyProxy(base, parent) {\n const baseIsArray = isArray(base);\n const state = {\n type_: baseIsArray ? 1 /* Array */ : 0 /* Object */,\n // Track which produce call this is associated with.\n scope_: parent ? parent.scope_ : getCurrentScope(),\n // True for both shallow and deep changes.\n modified_: false,\n // Used during finalization.\n finalized_: false,\n // Track which properties have been assigned (true) or deleted (false).\n // actually instantiated in `prepareCopy()`\n assigned_: void 0,\n // The parent draft state.\n parent_: parent,\n // The base state.\n base_: base,\n // The base proxy.\n draft_: null,\n // set below\n // The base copy with any updated values.\n copy_: null,\n // Called by the `produce` function.\n revoke_: null,\n isManual_: false,\n // `callbacks` actually gets assigned in `createProxy`\n callbacks_: void 0\n };\n let target = state;\n let traps = objectTraps;\n if (baseIsArray) {\n target = [state];\n traps = arrayTraps;\n }\n const { revoke, proxy } = Proxy.revocable(target, traps);\n state.draft_ = proxy;\n state.revoke_ = revoke;\n return [proxy, state];\n}\nvar objectTraps = {\n get(state, prop) {\n if (prop === DRAFT_STATE)\n return state;\n let arrayPlugin = state.scope_.arrayMethodsPlugin_;\n const isArrayWithStringProp = state.type_ === 1 /* Array */ && typeof prop === \"string\";\n if (isArrayWithStringProp) {\n if (arrayPlugin?.isArrayOperationMethod(prop)) {\n return arrayPlugin.createMethodInterceptor(state, prop);\n }\n }\n const source = latest(state);\n if (!has(source, prop, state.type_)) {\n return readPropFromProto(state, source, prop);\n }\n const value = source[prop];\n if (state.finalized_ || !isDraftable(value)) {\n return value;\n }\n if (isArrayWithStringProp && state.operationMethod && arrayPlugin?.isMutatingArrayMethod(\n state.operationMethod\n ) && isArrayIndex(prop)) {\n return value;\n }\n if (value === peek(state.base_, prop)) {\n prepareCopy(state);\n const childKey = state.type_ === 1 /* Array */ ? +prop : prop;\n const childDraft = createProxy(state.scope_, value, state, childKey);\n return state.copy_[childKey] = childDraft;\n }\n return value;\n },\n has(state, prop) {\n return prop in latest(state);\n },\n ownKeys(state) {\n return Reflect.ownKeys(latest(state));\n },\n set(state, prop, value) {\n const desc = getDescriptorFromProto(latest(state), prop);\n if (desc?.set) {\n desc.set.call(state.draft_, value);\n return true;\n }\n if (!state.modified_) {\n const current2 = peek(latest(state), prop);\n const currentState = current2?.[DRAFT_STATE];\n if (currentState && currentState.base_ === value) {\n state.copy_[prop] = value;\n state.assigned_.set(prop, false);\n return true;\n }\n if (is(value, current2) && (value !== void 0 || has(state.base_, prop, state.type_)))\n return true;\n prepareCopy(state);\n markChanged(state);\n }\n if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'\n (value !== void 0 || prop in state.copy_) || // special case: NaN\n Number.isNaN(value) && Number.isNaN(state.copy_[prop]))\n return true;\n state.copy_[prop] = value;\n state.assigned_.set(prop, true);\n handleCrossReference(state, prop, value);\n return true;\n },\n deleteProperty(state, prop) {\n prepareCopy(state);\n if (peek(state.base_, prop) !== void 0 || prop in state.base_) {\n state.assigned_.set(prop, false);\n markChanged(state);\n } else {\n state.assigned_.delete(prop);\n }\n if (state.copy_) {\n delete state.copy_[prop];\n }\n return true;\n },\n // Note: We never coerce `desc.value` into an Immer draft, because we can't make\n // the same guarantee in ES5 mode.\n getOwnPropertyDescriptor(state, prop) {\n const owner = latest(state);\n const desc = Reflect.getOwnPropertyDescriptor(owner, prop);\n if (!desc)\n return desc;\n return {\n [WRITABLE]: true,\n [CONFIGURABLE]: state.type_ !== 1 /* Array */ || prop !== \"length\",\n [ENUMERABLE]: desc[ENUMERABLE],\n [VALUE]: owner[prop]\n };\n },\n defineProperty() {\n die(11);\n },\n getPrototypeOf(state) {\n return getPrototypeOf(state.base_);\n },\n setPrototypeOf() {\n die(12);\n }\n};\nvar arrayTraps = {};\nfor (let key in objectTraps) {\n let fn = objectTraps[key];\n arrayTraps[key] = function() {\n const args = arguments;\n args[0] = args[0][0];\n return fn.apply(this, args);\n };\n}\narrayTraps.deleteProperty = function(state, prop) {\n if (process.env.NODE_ENV !== \"production\" && isNaN(parseInt(prop)))\n die(13);\n return arrayTraps.set.call(this, state, prop, void 0);\n};\narrayTraps.set = function(state, prop, value) {\n if (process.env.NODE_ENV !== \"production\" && prop !== \"length\" && isNaN(parseInt(prop)))\n die(14);\n return objectTraps.set.call(this, state[0], prop, value, state[0]);\n};\nfunction peek(draft, prop) {\n const state = draft[DRAFT_STATE];\n const source = state ? latest(state) : draft;\n return source[prop];\n}\nfunction readPropFromProto(state, source, prop) {\n const desc = getDescriptorFromProto(source, prop);\n return desc ? VALUE in desc ? desc[VALUE] : (\n // This is a very special case, if the prop is a getter defined by the\n // prototype, we should invoke it with the draft as context!\n desc.get?.call(state.draft_)\n ) : void 0;\n}\nfunction getDescriptorFromProto(source, prop) {\n if (!(prop in source))\n return void 0;\n let proto = getPrototypeOf(source);\n while (proto) {\n const desc = Object.getOwnPropertyDescriptor(proto, prop);\n if (desc)\n return desc;\n proto = getPrototypeOf(proto);\n }\n return void 0;\n}\nfunction markChanged(state) {\n if (!state.modified_) {\n state.modified_ = true;\n if (state.parent_) {\n markChanged(state.parent_);\n }\n }\n}\nfunction prepareCopy(state) {\n if (!state.copy_) {\n state.assigned_ = /* @__PURE__ */ new Map();\n state.copy_ = shallowCopy(\n state.base_,\n state.scope_.immer_.useStrictShallowCopy_\n );\n }\n}\n\n// src/core/immerClass.ts\nvar Immer2 = class {\n constructor(config) {\n this.autoFreeze_ = true;\n this.useStrictShallowCopy_ = false;\n this.useStrictIteration_ = false;\n /**\n * The `produce` function takes a value and a \"recipe function\" (whose\n * return value often depends on the base state). The recipe function is\n * free to mutate its first argument however it wants. All mutations are\n * only ever applied to a __copy__ of the base state.\n *\n * Pass only a function to create a \"curried producer\" which relieves you\n * from passing the recipe function every time.\n *\n * Only plain objects and arrays are made mutable. All other objects are\n * considered uncopyable.\n *\n * Note: This function is __bound__ to its `Immer` instance.\n *\n * @param {any} base - the initial state\n * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified\n * @param {Function} patchListener - optional function that will be called with all the patches produced here\n * @returns {any} a new state, or the initial state if nothing was modified\n */\n this.produce = (base, recipe, patchListener) => {\n if (isFunction(base) && !isFunction(recipe)) {\n const defaultBase = recipe;\n recipe = base;\n const self = this;\n return function curriedProduce(base2 = defaultBase, ...args) {\n return self.produce(base2, (draft) => recipe.call(this, draft, ...args));\n };\n }\n if (!isFunction(recipe))\n die(6);\n if (patchListener !== void 0 && !isFunction(patchListener))\n die(7);\n let result;\n if (isDraftable(base)) {\n const scope = enterScope(this);\n const proxy = createProxy(scope, base, void 0);\n let hasError = true;\n try {\n result = recipe(proxy);\n hasError = false;\n } finally {\n if (hasError)\n revokeScope(scope);\n else\n leaveScope(scope);\n }\n usePatchesInScope(scope, patchListener);\n return processResult(result, scope);\n } else if (!base || !isObjectish(base)) {\n result = recipe(base);\n if (result === void 0)\n result = base;\n if (result === NOTHING)\n result = void 0;\n if (this.autoFreeze_)\n freeze(result, true);\n if (patchListener) {\n const p = [];\n const ip = [];\n getPlugin(PluginPatches).generateReplacementPatches_(base, result, {\n patches_: p,\n inversePatches_: ip\n });\n patchListener(p, ip);\n }\n return result;\n } else\n die(1, base);\n };\n this.produceWithPatches = (base, recipe) => {\n if (isFunction(base)) {\n return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));\n }\n let patches, inversePatches;\n const result = this.produce(base, recipe, (p, ip) => {\n patches = p;\n inversePatches = ip;\n });\n return [result, patches, inversePatches];\n };\n if (isBoolean(config?.autoFreeze))\n this.setAutoFreeze(config.autoFreeze);\n if (isBoolean(config?.useStrictShallowCopy))\n this.setUseStrictShallowCopy(config.useStrictShallowCopy);\n if (isBoolean(config?.useStrictIteration))\n this.setUseStrictIteration(config.useStrictIteration);\n }\n createDraft(base) {\n if (!isDraftable(base))\n die(8);\n if (isDraft(base))\n base = current(base);\n const scope = enterScope(this);\n const proxy = createProxy(scope, base, void 0);\n proxy[DRAFT_STATE].isManual_ = true;\n leaveScope(scope);\n return proxy;\n }\n finishDraft(draft, patchListener) {\n const state = draft && draft[DRAFT_STATE];\n if (!state || !state.isManual_)\n die(9);\n const { scope_: scope } = state;\n usePatchesInScope(scope, patchListener);\n return processResult(void 0, scope);\n }\n /**\n * Pass true to automatically freeze all copies created by Immer.\n *\n * By default, auto-freezing is enabled.\n */\n setAutoFreeze(value) {\n this.autoFreeze_ = value;\n }\n /**\n * Pass true to enable strict shallow copy.\n *\n * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n */\n setUseStrictShallowCopy(value) {\n this.useStrictShallowCopy_ = value;\n }\n /**\n * Pass false to use faster iteration that skips non-enumerable properties\n * but still handles symbols for compatibility.\n *\n * By default, strict iteration is enabled (includes all own properties).\n */\n setUseStrictIteration(value) {\n this.useStrictIteration_ = value;\n }\n shouldUseStrictIteration() {\n return this.useStrictIteration_;\n }\n applyPatches(base, patches) {\n let i;\n for (i = patches.length - 1; i >= 0; i--) {\n const patch = patches[i];\n if (patch.path.length === 0 && patch.op === \"replace\") {\n base = patch.value;\n break;\n }\n }\n if (i > -1) {\n patches = patches.slice(i + 1);\n }\n const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_;\n if (isDraft(base)) {\n return applyPatchesImpl(base, patches);\n }\n return this.produce(\n base,\n (draft) => applyPatchesImpl(draft, patches)\n );\n }\n};\nfunction createProxy(rootScope, value, parent, key) {\n const [draft, state] = isMap(value) ? getPlugin(PluginMapSet).proxyMap_(value, parent) : isSet(value) ? getPlugin(PluginMapSet).proxySet_(value, parent) : createProxyProxy(value, parent);\n const scope = parent?.scope_ ?? getCurrentScope();\n scope.drafts_.push(draft);\n state.callbacks_ = parent?.callbacks_ ?? [];\n state.key_ = key;\n if (parent && key !== void 0) {\n registerChildFinalizationCallback(parent, state, key);\n } else {\n state.callbacks_.push(function rootDraftCleanup(rootScope2) {\n rootScope2.mapSetPlugin_?.fixSetContents(state);\n const { patchPlugin_ } = rootScope2;\n if (state.modified_ && patchPlugin_) {\n patchPlugin_.generatePatches_(state, [], rootScope2);\n }\n });\n }\n return draft;\n}\n\n// src/core/current.ts\nfunction current(value) {\n if (!isDraft(value))\n die(10, value);\n return currentImpl(value);\n}\nfunction currentImpl(value) {\n if (!isDraftable(value) || isFrozen(value))\n return value;\n const state = value[DRAFT_STATE];\n let copy;\n let strict = true;\n if (state) {\n if (!state.modified_)\n return state.base_;\n state.finalized_ = true;\n copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);\n strict = state.scope_.immer_.shouldUseStrictIteration();\n } else {\n copy = shallowCopy(value, true);\n }\n each(\n copy,\n (key, childValue) => {\n set(copy, key, currentImpl(childValue));\n },\n strict\n );\n if (state) {\n state.finalized_ = false;\n }\n return copy;\n}\n\n// src/plugins/patches.ts\nfunction enablePatches() {\n const errorOffset = 16;\n if (process.env.NODE_ENV !== \"production\") {\n errors.push(\n 'Sets cannot have \"replace\" patches.',\n function(op) {\n return \"Unsupported patch operation: \" + op;\n },\n function(path) {\n return \"Cannot apply patch, path doesn't resolve: \" + path;\n },\n \"Patching reserved attributes like __proto__, prototype and constructor is not allowed\"\n );\n }\n function getPath(state, path = []) {\n if (state.key_ !== void 0) {\n const parentCopy = state.parent_.copy_ ?? state.parent_.base_;\n const proxyDraft = getProxyDraft(get(parentCopy, state.key_));\n const valueAtKey = get(parentCopy, state.key_);\n if (valueAtKey === void 0) {\n return null;\n }\n if (valueAtKey !== state.draft_ && valueAtKey !== state.base_ && valueAtKey !== state.copy_) {\n return null;\n }\n if (proxyDraft != null && proxyDraft.base_ !== state.base_) {\n return null;\n }\n const isSet2 = state.parent_.type_ === 3 /* Set */;\n let key;\n if (isSet2) {\n const setParent = state.parent_;\n key = Array.from(setParent.drafts_.keys()).indexOf(state.key_);\n } else {\n key = state.key_;\n }\n if (!(isSet2 && parentCopy.size > key || has(parentCopy, key))) {\n return null;\n }\n path.push(key);\n }\n if (state.parent_) {\n return getPath(state.parent_, path);\n }\n path.reverse();\n try {\n resolvePath(state.copy_, path);\n } catch (e) {\n return null;\n }\n return path;\n }\n function resolvePath(base, path) {\n let current2 = base;\n for (let i = 0; i < path.length - 1; i++) {\n const key = path[i];\n current2 = get(current2, key);\n if (!isObjectish(current2) || current2 === null) {\n throw new Error(`Cannot resolve path at '${path.join(\"/\")}'`);\n }\n }\n return current2;\n }\n const REPLACE = \"replace\";\n const ADD = \"add\";\n const REMOVE = \"remove\";\n function generatePatches_(state, basePath, scope) {\n if (state.scope_.processedForPatches_.has(state)) {\n return;\n }\n state.scope_.processedForPatches_.add(state);\n const { patches_, inversePatches_ } = scope;\n switch (state.type_) {\n case 0 /* Object */:\n case 2 /* Map */:\n return generatePatchesFromAssigned(\n state,\n basePath,\n patches_,\n inversePatches_\n );\n case 1 /* Array */:\n return generateArrayPatches(\n state,\n basePath,\n patches_,\n inversePatches_\n );\n case 3 /* Set */:\n return generateSetPatches(\n state,\n basePath,\n patches_,\n inversePatches_\n );\n }\n }\n function generateArrayPatches(state, basePath, patches, inversePatches) {\n let { base_, assigned_ } = state;\n let copy_ = state.copy_;\n if (copy_.length < base_.length) {\n ;\n [base_, copy_] = [copy_, base_];\n [patches, inversePatches] = [inversePatches, patches];\n }\n const allReassigned = state.allIndicesReassigned_ === true;\n for (let i = 0; i < base_.length; i++) {\n const copiedItem = copy_[i];\n const baseItem = base_[i];\n const isAssigned = allReassigned || assigned_?.get(i.toString());\n if (isAssigned && copiedItem !== baseItem) {\n const childState = copiedItem?.[DRAFT_STATE];\n if (childState && childState.modified_) {\n continue;\n }\n const path = basePath.concat([i]);\n patches.push({\n op: REPLACE,\n path,\n // Need to maybe clone it, as it can in fact be the original value\n // due to the base/copy inversion at the start of this function\n value: clonePatchValueIfNeeded(copiedItem)\n });\n inversePatches.push({\n op: REPLACE,\n path,\n value: clonePatchValueIfNeeded(baseItem)\n });\n }\n }\n for (let i = base_.length; i < copy_.length; i++) {\n const path = basePath.concat([i]);\n patches.push({\n op: ADD,\n path,\n // Need to maybe clone it, as it can in fact be the original value\n // due to the base/copy inversion at the start of this function\n value: clonePatchValueIfNeeded(copy_[i])\n });\n }\n for (let i = copy_.length - 1; base_.length <= i; --i) {\n const path = basePath.concat([i]);\n inversePatches.push({\n op: REMOVE,\n path\n });\n }\n }\n function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {\n const { base_, copy_, type_ } = state;\n each(state.assigned_, (key, assignedValue) => {\n const origValue = get(base_, key, type_);\n const value = get(copy_, key, type_);\n const op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD;\n if (origValue === value && op === REPLACE)\n return;\n const path = basePath.concat(key);\n patches.push(\n op === REMOVE ? { op, path } : { op, path, value: clonePatchValueIfNeeded(value) }\n );\n inversePatches.push(\n op === ADD ? { op: REMOVE, path } : op === REMOVE ? { op: ADD, path, value: clonePatchValueIfNeeded(origValue) } : { op: REPLACE, path, value: clonePatchValueIfNeeded(origValue) }\n );\n });\n }\n function generateSetPatches(state, basePath, patches, inversePatches) {\n let { base_, copy_ } = state;\n let i = 0;\n base_.forEach((value) => {\n if (!copy_.has(value)) {\n const path = basePath.concat([i]);\n patches.push({\n op: REMOVE,\n path,\n value\n });\n inversePatches.unshift({\n op: ADD,\n path,\n value\n });\n }\n i++;\n });\n i = 0;\n copy_.forEach((value) => {\n if (!base_.has(value)) {\n const path = basePath.concat([i]);\n patches.push({\n op: ADD,\n path,\n value\n });\n inversePatches.unshift({\n op: REMOVE,\n path,\n value\n });\n }\n i++;\n });\n }\n function generateReplacementPatches_(baseValue, replacement, scope) {\n const { patches_, inversePatches_ } = scope;\n patches_.push({\n op: REPLACE,\n path: [],\n value: replacement === NOTHING ? void 0 : replacement\n });\n inversePatches_.push({\n op: REPLACE,\n path: [],\n value: baseValue\n });\n }\n function applyPatches_(draft, patches) {\n patches.forEach((patch) => {\n const { path, op } = patch;\n let base = draft;\n for (let i = 0; i < path.length - 1; i++) {\n const parentType = getArchtype(base);\n let p = path[i];\n if (typeof p !== \"string\" && typeof p !== \"number\") {\n p = \"\" + p;\n }\n if ((parentType === 0 /* Object */ || parentType === 1 /* Array */) && (p === \"__proto__\" || p === CONSTRUCTOR))\n die(errorOffset + 3);\n if (isFunction(base) && p === PROTOTYPE)\n die(errorOffset + 3);\n base = get(base, p);\n if (!isObjectish(base))\n die(errorOffset + 2, path.join(\"/\"));\n }\n const type = getArchtype(base);\n const value = deepClonePatchValue(patch.value);\n const key = path[path.length - 1];\n switch (op) {\n case REPLACE:\n switch (type) {\n case 2 /* Map */:\n return base.set(key, value);\n case 3 /* Set */:\n die(errorOffset);\n default:\n return base[key] = value;\n }\n case ADD:\n switch (type) {\n case 1 /* Array */:\n return key === \"-\" ? base.push(value) : base.splice(key, 0, value);\n case 2 /* Map */:\n return base.set(key, value);\n case 3 /* Set */:\n return base.add(value);\n default:\n return base[key] = value;\n }\n case REMOVE:\n switch (type) {\n case 1 /* Array */:\n return base.splice(key, 1);\n case 2 /* Map */:\n return base.delete(key);\n case 3 /* Set */:\n return base.delete(patch.value);\n default:\n return delete base[key];\n }\n default:\n die(errorOffset + 1, op);\n }\n });\n return draft;\n }\n function deepClonePatchValue(obj) {\n if (!isDraftable(obj))\n return obj;\n if (isArray(obj))\n return obj.map(deepClonePatchValue);\n if (isMap(obj))\n return new Map(\n Array.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)])\n );\n if (isSet(obj))\n return new Set(Array.from(obj).map(deepClonePatchValue));\n const cloned = Object.create(getPrototypeOf(obj));\n for (const key in obj)\n cloned[key] = deepClonePatchValue(obj[key]);\n if (has(obj, DRAFTABLE))\n cloned[DRAFTABLE] = obj[DRAFTABLE];\n return cloned;\n }\n function clonePatchValueIfNeeded(obj) {\n if (isDraft(obj)) {\n return deepClonePatchValue(obj);\n } else\n return obj;\n }\n loadPlugin(PluginPatches, {\n applyPatches_,\n generatePatches_,\n generateReplacementPatches_,\n getPath\n });\n}\n\n// src/plugins/mapset.ts\nfunction enableMapSet() {\n class DraftMap extends Map {\n constructor(target, parent) {\n super();\n this[DRAFT_STATE] = {\n type_: 2 /* Map */,\n parent_: parent,\n scope_: parent ? parent.scope_ : getCurrentScope(),\n modified_: false,\n finalized_: false,\n copy_: void 0,\n assigned_: void 0,\n base_: target,\n draft_: this,\n isManual_: false,\n revoked_: false,\n callbacks_: []\n };\n }\n get size() {\n return latest(this[DRAFT_STATE]).size;\n }\n has(key) {\n return latest(this[DRAFT_STATE]).has(key);\n }\n set(key, value) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (!latest(state).has(key) || latest(state).get(key) !== value) {\n prepareMapCopy(state);\n markChanged(state);\n state.assigned_.set(key, true);\n state.copy_.set(key, value);\n state.assigned_.set(key, true);\n handleCrossReference(state, key, value);\n }\n return this;\n }\n delete(key) {\n if (!this.has(key)) {\n return false;\n }\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareMapCopy(state);\n markChanged(state);\n if (state.base_.has(key)) {\n state.assigned_.set(key, false);\n } else {\n state.assigned_.delete(key);\n }\n state.copy_.delete(key);\n return true;\n }\n clear() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (latest(state).size) {\n prepareMapCopy(state);\n markChanged(state);\n state.assigned_ = /* @__PURE__ */ new Map();\n each(state.base_, (key) => {\n state.assigned_.set(key, false);\n });\n state.copy_.clear();\n }\n }\n forEach(cb, thisArg) {\n const state = this[DRAFT_STATE];\n latest(state).forEach((_value, key, _map) => {\n cb.call(thisArg, this.get(key), key, this);\n });\n }\n get(key) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n const value = latest(state).get(key);\n if (state.finalized_ || !isDraftable(value)) {\n return value;\n }\n if (value !== state.base_.get(key)) {\n return value;\n }\n const draft = createProxy(state.scope_, value, state, key);\n prepareMapCopy(state);\n state.copy_.set(key, draft);\n return draft;\n }\n keys() {\n return latest(this[DRAFT_STATE]).keys();\n }\n values() {\n const iterator = this.keys();\n return {\n [Symbol.iterator]: () => this.values(),\n next: () => {\n const r = iterator.next();\n if (r.done)\n return r;\n const value = this.get(r.value);\n return {\n done: false,\n value\n };\n }\n };\n }\n entries() {\n const iterator = this.keys();\n return {\n [Symbol.iterator]: () => this.entries(),\n next: () => {\n const r = iterator.next();\n if (r.done)\n return r;\n const value = this.get(r.value);\n return {\n done: false,\n value: [r.value, value]\n };\n }\n };\n }\n [(DRAFT_STATE, Symbol.iterator)]() {\n return this.entries();\n }\n }\n function proxyMap_(target, parent) {\n const map = new DraftMap(target, parent);\n return [map, map[DRAFT_STATE]];\n }\n function prepareMapCopy(state) {\n if (!state.copy_) {\n state.assigned_ = /* @__PURE__ */ new Map();\n state.copy_ = new Map(state.base_);\n }\n }\n class DraftSet extends Set {\n constructor(target, parent) {\n super();\n this[DRAFT_STATE] = {\n type_: 3 /* Set */,\n parent_: parent,\n scope_: parent ? parent.scope_ : getCurrentScope(),\n modified_: false,\n finalized_: false,\n copy_: void 0,\n base_: target,\n draft_: this,\n drafts_: /* @__PURE__ */ new Map(),\n revoked_: false,\n isManual_: false,\n assigned_: void 0,\n callbacks_: []\n };\n }\n get size() {\n return latest(this[DRAFT_STATE]).size;\n }\n has(value) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (!state.copy_) {\n return state.base_.has(value);\n }\n if (state.copy_.has(value))\n return true;\n if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))\n return true;\n return false;\n }\n add(value) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (!this.has(value)) {\n prepareSetCopy(state);\n markChanged(state);\n state.copy_.add(value);\n handleCrossReference(state, value, value);\n }\n return this;\n }\n delete(value) {\n if (!this.has(value)) {\n return false;\n }\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareSetCopy(state);\n markChanged(state);\n return state.copy_.delete(value) || (state.drafts_.has(value) ? state.copy_.delete(state.drafts_.get(value)) : (\n /* istanbul ignore next */\n false\n ));\n }\n clear() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (latest(state).size) {\n prepareSetCopy(state);\n markChanged(state);\n state.copy_.clear();\n }\n }\n values() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareSetCopy(state);\n return state.copy_.values();\n }\n entries() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareSetCopy(state);\n return state.copy_.entries();\n }\n keys() {\n return this.values();\n }\n [(DRAFT_STATE, Symbol.iterator)]() {\n return this.values();\n }\n forEach(cb, thisArg) {\n const iterator = this.values();\n let result = iterator.next();\n while (!result.done) {\n cb.call(thisArg, result.value, result.value, this);\n result = iterator.next();\n }\n }\n }\n function proxySet_(target, parent) {\n const set2 = new DraftSet(target, parent);\n return [set2, set2[DRAFT_STATE]];\n }\n function prepareSetCopy(state) {\n if (!state.copy_) {\n state.copy_ = /* @__PURE__ */ new Set();\n state.base_.forEach((value) => {\n if (isDraftable(value)) {\n const draft = createProxy(state.scope_, value, state, value);\n state.drafts_.set(value, draft);\n state.copy_.add(draft);\n } else {\n state.copy_.add(value);\n }\n });\n }\n }\n function assertUnrevoked(state) {\n if (state.revoked_)\n die(3, JSON.stringify(latest(state)));\n }\n function fixSetContents(target) {\n if (target.type_ === 3 /* Set */ && target.copy_) {\n const copy = new Set(target.copy_);\n target.copy_.clear();\n copy.forEach((value) => {\n target.copy_.add(getValue(value));\n });\n }\n }\n loadPlugin(PluginMapSet, { proxyMap_, proxySet_, fixSetContents });\n}\n\n// src/plugins/arrayMethods.ts\nfunction enableArrayMethods() {\n const SHIFTING_METHODS = /* @__PURE__ */ new Set([\"shift\", \"unshift\"]);\n const QUEUE_METHODS = /* @__PURE__ */ new Set([\"push\", \"pop\"]);\n const RESULT_RETURNING_METHODS = /* @__PURE__ */ new Set([\n ...QUEUE_METHODS,\n ...SHIFTING_METHODS\n ]);\n const REORDERING_METHODS = /* @__PURE__ */ new Set([\"reverse\", \"sort\"]);\n const MUTATING_METHODS = /* @__PURE__ */ new Set([\n ...RESULT_RETURNING_METHODS,\n ...REORDERING_METHODS,\n \"splice\"\n ]);\n const FIND_METHODS = /* @__PURE__ */ new Set([\"find\", \"findLast\"]);\n const NON_MUTATING_METHODS = /* @__PURE__ */ new Set([\n \"filter\",\n \"slice\",\n \"concat\",\n \"flat\",\n ...FIND_METHODS,\n \"findIndex\",\n \"findLastIndex\",\n \"some\",\n \"every\",\n \"indexOf\",\n \"lastIndexOf\",\n \"includes\",\n \"join\",\n \"toString\",\n \"toLocaleString\"\n ]);\n function isMutatingArrayMethod(method) {\n return MUTATING_METHODS.has(method);\n }\n function isNonMutatingArrayMethod(method) {\n return NON_MUTATING_METHODS.has(method);\n }\n function isArrayOperationMethod(method) {\n return isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method);\n }\n function enterOperation(state, method) {\n state.operationMethod = method;\n }\n function exitOperation(state) {\n state.operationMethod = void 0;\n }\n function executeArrayMethod(state, operation, markLength = true) {\n prepareCopy(state);\n const result = operation();\n markChanged(state);\n if (markLength)\n state.assigned_.set(\"length\", true);\n return result;\n }\n function markAllIndicesReassigned(state) {\n state.allIndicesReassigned_ = true;\n }\n function normalizeSliceIndex(index, length) {\n if (index < 0) {\n return Math.max(length + index, 0);\n }\n return Math.min(index, length);\n }\n function handleInsertedValues(state, startIndex, values) {\n for (let i = 0; i < values.length; i++) {\n const index = startIndex + i;\n state.assigned_.set(index, true);\n handleCrossReference(state, index, values[i]);\n }\n }\n function handleSimpleOperation(state, method, args) {\n return executeArrayMethod(state, () => {\n const lengthBefore = state.copy_.length;\n const result = state.copy_[method](...args);\n if (SHIFTING_METHODS.has(method)) {\n markAllIndicesReassigned(state);\n }\n if (method === \"push\" && args.length > 0) {\n handleInsertedValues(state, lengthBefore, args);\n } else if (method === \"unshift\" && args.length > 0) {\n handleInsertedValues(state, 0, args);\n }\n return RESULT_RETURNING_METHODS.has(method) ? result : state.draft_;\n });\n }\n function handleReorderingOperation(state, method, args) {\n return executeArrayMethod(\n state,\n () => {\n ;\n state.copy_[method](...args);\n markAllIndicesReassigned(state);\n return state.draft_;\n },\n false\n );\n }\n function createMethodInterceptor(state, originalMethod) {\n return function interceptedMethod(...args) {\n const method = originalMethod;\n enterOperation(state, method);\n try {\n if (isMutatingArrayMethod(method)) {\n if (RESULT_RETURNING_METHODS.has(method)) {\n return handleSimpleOperation(state, method, args);\n }\n if (REORDERING_METHODS.has(method)) {\n return handleReorderingOperation(state, method, args);\n }\n if (method === \"splice\") {\n const res = executeArrayMethod(\n state,\n () => state.copy_.splice(...args)\n );\n markAllIndicesReassigned(state);\n if (args.length > 2) {\n const startIndex = normalizeSliceIndex(\n args[0] ?? 0,\n state.copy_.length\n );\n handleInsertedValues(state, startIndex, args.slice(2));\n }\n return res;\n }\n } else {\n return handleNonMutatingOperation(state, method, args);\n }\n } finally {\n exitOperation(state);\n }\n };\n }\n function handleNonMutatingOperation(state, method, args) {\n const source = latest(state);\n if (method === \"filter\") {\n const predicate = args[0];\n const result = [];\n for (let i = 0; i < source.length; i++) {\n if (predicate(source[i], i, source)) {\n result.push(state.draft_[i]);\n }\n }\n return result;\n }\n if (FIND_METHODS.has(method)) {\n const predicate = args[0];\n const isForward = method === \"find\";\n const step = isForward ? 1 : -1;\n const start = isForward ? 0 : source.length - 1;\n for (let i = start; i >= 0 && i < source.length; i += step) {\n if (predicate(source[i], i, source)) {\n return state.draft_[i];\n }\n }\n return void 0;\n }\n if (method === \"slice\") {\n const rawStart = args[0] ?? 0;\n const rawEnd = args[1] ?? source.length;\n const start = normalizeSliceIndex(rawStart, source.length);\n const end = normalizeSliceIndex(rawEnd, source.length);\n const result = [];\n for (let i = start; i < end; i++) {\n result.push(state.draft_[i]);\n }\n return result;\n }\n return source[method](...args);\n }\n loadPlugin(PluginArrayMethods, {\n createMethodInterceptor,\n isArrayOperationMethod,\n isMutatingArrayMethod\n });\n}\n\n// src/immer.ts\nvar immer = new Immer2();\nvar produce = immer.produce;\nvar produceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(immer);\nvar setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer);\nvar setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(immer);\nvar setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind(immer);\nvar applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer);\nvar createDraft = /* @__PURE__ */ immer.createDraft.bind(immer);\nvar finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer);\nvar castDraft = (value) => value;\nvar castImmutable = (value) => value;\nexport {\n Immer2 as Immer,\n applyPatches,\n castDraft,\n castImmutable,\n createDraft,\n current,\n enableArrayMethods,\n enableMapSet,\n enablePatches,\n finishDraft,\n freeze,\n DRAFTABLE as immerable,\n isDraft,\n isDraftable,\n NOTHING as nothing,\n original,\n produce,\n produceWithPatches,\n setAutoFreeze,\n setUseStrictIteration,\n setUseStrictShallowCopy\n};\n//# sourceMappingURL=immer.mjs.map","// Storage adapters for the state() module. Lifted from the v1\n// store/storage-manager.ts and tightened — same four backends\n// (memory / local / session / indexeddb), same Map/Set JSON tunnel,\n// gives the state() factory a uniform async interface to load + save.\n//\n// The microtask write-debouncer lives in state.ts (the consumer of\n// this module) — adapters here are plain load/save/clear.\n\nexport type StorageBackend = 'memory' | 'local' | 'session' | 'indexeddb'\n\nexport interface StorageAdapter<T> {\n\tload(): Promise<T | null>\n\tsave(value: T): Promise<void>\n\tclear(): Promise<void>\n\tclose?(): Promise<void>\n}\n\nexport class StateStorageError<T = unknown> extends Error {\n\treadonly cause?: T\n\treadonly context?: Record<string, unknown>\n\treadonly timestamp: Date\n\tconstructor(message: string, cause?: T, context?: Record<string, unknown>) {\n\t\tsuper(message)\n\t\tthis.name = 'StateStorageError'\n\t\tthis.cause = cause\n\t\tthis.context = context\n\t\tthis.timestamp = new Date()\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// JSON tunnel for Map/Set values stored in string-backed storage.\n// IDB stores native objects so doesn't need this — only used by local/session.\n\nconst MAP_TAG = '__schmancy_state_Map'\nconst SET_TAG = '__schmancy_state_Set'\n\ninterface TaggedMap {\n\t$kind: typeof MAP_TAG\n\tentries: Array<[unknown, unknown]>\n}\ninterface TaggedSet {\n\t$kind: typeof SET_TAG\n\tvalues: unknown[]\n}\n\nfunction replacer(_key: string, value: unknown): unknown {\n\tif (value instanceof Map) {\n\t\treturn { $kind: MAP_TAG, entries: Array.from(value.entries()) } satisfies TaggedMap\n\t}\n\tif (value instanceof Set) {\n\t\treturn { $kind: SET_TAG, values: Array.from(value.values()) } satisfies TaggedSet\n\t}\n\treturn value\n}\n\nfunction reviver(_key: string, value: unknown): unknown {\n\tif (value && typeof value === 'object' && '$kind' in value) {\n\t\tconst tagged = value as { $kind: unknown; entries?: unknown; values?: unknown }\n\t\tconst kind = tagged.$kind\n\t\tif (kind === MAP_TAG) {\n\t\t\tif (!Array.isArray(tagged.entries)) return value\n\t\t\tconst ok = tagged.entries.every(e => Array.isArray(e) && e.length === 2)\n\t\t\tif (!ok) return value\n\t\t\treturn new Map(tagged.entries as Iterable<readonly [unknown, unknown]>)\n\t\t}\n\t\tif (kind === SET_TAG) {\n\t\t\tif (!Array.isArray(tagged.values)) return value\n\t\t\treturn new Set(tagged.values)\n\t\t}\n\t}\n\treturn value\n}\n\n// ---------------------------------------------------------------------------\n\nclass MemoryAdapter<T> implements StorageAdapter<T> {\n\t#data: T | null = null\n\tasync load(): Promise<T | null> {\n\t\treturn this.#data\n\t}\n\tasync save(value: T): Promise<void> {\n\t\tthis.#data = value\n\t}\n\tasync clear(): Promise<void> {\n\t\tthis.#data = null\n\t}\n}\n\nclass WebStorageAdapter<T> implements StorageAdapter<T> {\n\tconstructor(\n\t\tprivate readonly storage: Storage,\n\t\tprivate readonly key: string,\n\t\tprivate readonly label: string,\n\t) {}\n\tasync load(): Promise<T | null> {\n\t\ttry {\n\t\t\tconst raw = this.storage.getItem(this.key)\n\t\t\treturn raw ? (JSON.parse(raw, reviver) as T) : null\n\t\t} catch (err) {\n\t\t\tconsole.error(`[state] ${this.label} load failed (${this.key}):`, err)\n\t\t\treturn null\n\t\t}\n\t}\n\tasync save(value: T): Promise<void> {\n\t\ttry {\n\t\t\tthis.storage.setItem(this.key, JSON.stringify(value, replacer))\n\t\t} catch (err) {\n\t\t\tthrow new StateStorageError(\n\t\t\t\t`[state] ${this.label} save failed (${this.key})`,\n\t\t\t\terr,\n\t\t\t)\n\t\t}\n\t}\n\tasync clear(): Promise<void> {\n\t\tthis.storage.removeItem(this.key)\n\t}\n}\n\nclass IndexedDBAdapter<T> implements StorageAdapter<T> {\n\tprivate static readonly DB_NAME = 'SchmancyState'\n\tprivate static readonly STORE_NAME = 'states'\n\tprivate static readonly DB_VERSION = 1\n\n\t#db: IDBDatabase | null = null\n\t#opening: Promise<IDBDatabase> | null = null\n\n\tconstructor(private readonly key: string) {}\n\n\tprivate openDB(): Promise<IDBDatabase> {\n\t\tif (this.#db) return Promise.resolve(this.#db)\n\t\tif (this.#opening) return this.#opening\n\t\tthis.#opening = new Promise<IDBDatabase>((resolve, reject) => {\n\t\t\tconst req = indexedDB.open(IndexedDBAdapter.DB_NAME, IndexedDBAdapter.DB_VERSION)\n\t\t\treq.onupgradeneeded = () => {\n\t\t\t\tconst db = req.result\n\t\t\t\tif (!db.objectStoreNames.contains(IndexedDBAdapter.STORE_NAME)) {\n\t\t\t\t\tdb.createObjectStore(IndexedDBAdapter.STORE_NAME)\n\t\t\t\t}\n\t\t\t}\n\t\t\treq.addEventListener('success', () => {\n\t\t\t\tthis.#db = req.result\n\t\t\t\tresolve(req.result)\n\t\t\t}, { once: true })\n\t\t\treq.addEventListener('error', () => reject(req.error), { once: true })\n\t\t})\n\t\treturn this.#opening\n\t}\n\n\tasync load(): Promise<T | null> {\n\t\ttry {\n\t\t\tconst db = await this.openDB()\n\t\t\treturn await new Promise<T | null>((resolve, reject) => {\n\t\t\t\tconst tx = db.transaction(IndexedDBAdapter.STORE_NAME, 'readonly')\n\t\t\t\tconst req = tx.objectStore(IndexedDBAdapter.STORE_NAME).get(this.key)\n\t\t\t\treq.addEventListener('success', () => resolve((req.result ?? null) as T | null), { once: true })\n\t\t\t\treq.addEventListener('error', () => reject(req.error), { once: true })\n\t\t\t})\n\t\t} catch (err) {\n\t\t\tconsole.error(`[state] IDB load failed (${this.key}):`, err)\n\t\t\treturn null\n\t\t}\n\t}\n\n\tasync save(value: T): Promise<void> {\n\t\tconst db = await this.openDB()\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tconst tx = db.transaction(IndexedDBAdapter.STORE_NAME, 'readwrite')\n\t\t\tconst req = tx.objectStore(IndexedDBAdapter.STORE_NAME).put(value, this.key)\n\t\t\treq.addEventListener('success', () => resolve(), { once: true })\n\t\t\treq.addEventListener('error', () => reject(\n\t\t\t\tnew StateStorageError(`[state] IDB save failed (${this.key})`, req.error),\n\t\t\t), { once: true })\n\t\t})\n\t}\n\n\tasync clear(): Promise<void> {\n\t\tconst db = await this.openDB()\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tconst tx = db.transaction(IndexedDBAdapter.STORE_NAME, 'readwrite')\n\t\t\tconst req = tx.objectStore(IndexedDBAdapter.STORE_NAME).delete(this.key)\n\t\t\treq.addEventListener('success', () => resolve(), { once: true })\n\t\t\treq.addEventListener('error', () => reject(req.error), { once: true })\n\t\t})\n\t}\n\n\tasync close(): Promise<void> {\n\t\tif (this.#db) {\n\t\t\tthis.#db.close()\n\t\t\tthis.#db = null\n\t\t}\n\t\tthis.#opening = null\n\t}\n}\n\nexport function createAdapter<T>(backend: StorageBackend, key: string): StorageAdapter<T> {\n\tswitch (backend) {\n\t\tcase 'local':\n\t\t\treturn new WebStorageAdapter<T>(localStorage, key, 'localStorage')\n\t\tcase 'session':\n\t\t\treturn new WebStorageAdapter<T>(sessionStorage, key, 'sessionStorage')\n\t\tcase 'indexeddb':\n\t\t\treturn new IndexedDBAdapter<T>(key)\n\t\tcase 'memory':\n\t\tdefault:\n\t\t\treturn new MemoryAdapter<T>()\n\t}\n}\n","// `<schmancy-context provides={[cart, …]}>` — declarative state isolation.\n//\n// Mounts one isolated copy of each provided state under the element. Reads\n// and writes from descendants resolve to the isolated copy via the\n// `@lit/context` request protocol; descendants outside any `<schmancy-context>`\n// continue to read/write the module-scoped global. The isolated copy is\n// initialised with a snapshot of `tmpl.value` at mount time so the subtree\n// starts from \"current global state, then diverges.\"\n//\n// Lifetime: each isolated copy lives exactly as long as this element is\n// connected. `disconnectedCallback` destroys all isolated copies; their\n// pending writes flush, their adapters close.\n\nimport { LitElement, html } from 'lit'\nimport { property } from 'lit/decorators.js'\nimport { ContextProvider, createContext, type Context } from '@lit/context'\nimport { _publishEventHost, stateContextKey } from './active-host'\n\n// Curated set of DOM event types that descendants are likely to bind state-\n// mutating handlers to. The capture-phase listener publishes `this` as the\n// active event-host before the event reaches the target; descendants whose\n// inline handlers (or any code reached during the synchronous chain) call a\n// state mutator can resolve back to the isolated copy this context provides.\nconst EVENT_TYPES = [\n\t'click',\n\t'dblclick',\n\t'submit',\n\t'change',\n\t'input',\n\t'keydown',\n\t'keyup',\n\t'keypress',\n\t'pointerdown',\n\t'pointerup',\n\t'mousedown',\n\t'mouseup',\n\t'focus',\n\t'blur',\n\t'paste',\n\t'drop',\n] as const\n\n/** Duck-typed view of what the `state()` factory hands out, restricted to the\n * bits `<schmancy-context>` needs. Kept internal — consumers see the full\n * `State<>` type and never refer to this. */\nexport interface StateTemplate {\n\treadonly namespace: string\n\treadonly value: unknown\n\t/** Internal hook the factory adds to every state instance. Builds a fresh\n\t * per-context copy seeded with the current value, sharing nothing with the\n\t * global instance. The returned object exposes `destroy()` so the context\n\t * element can flush + close on disconnect. */\n\t_isolatedInstance(): { destroy(): void } & Record<string | symbol, unknown>\n}\n\nexport class SchmancyContext extends LitElement {\n\t/** States to isolate under this subtree. Pass the same instances you import\n\t * at module scope (e.g. `provides={[cart, menu]}`). Outside this element\n\t * they continue to behave as module-scoped globals; descendants of this\n\t * element see a per-element isolated copy. */\n\t@property({ attribute: false }) provides: readonly StateTemplate[] = []\n\n\t// Per-mount records. Keep both the provider (so we can release it on\n\t// disconnect) and the isolated instance (so we can destroy it).\n\tprivate _scoped: Array<{\n\t\tisolated: { destroy(): void }\n\t\tprovider: ContextProvider<Context<unknown, unknown>>\n\t}> = []\n\n\tprivate _publishEventTargetAsHost = (e: Event): void => {\n\t\t// Publish the deepest event target (across shadow boundaries) rather\n\t\t// than `this`. The downstream `ContextRequestEvent` will be dispatched\n\t\t// from this host and must bubble up through `<schmancy-context>` to\n\t\t// reach our `ContextProvider`. `@lit/context` skips self-registration\n\t\t// (`consumerHost === this.host` ⇒ no-op), so dispatching from\n\t\t// schmancy-context itself would silently fall back to the global.\n\t\tconst path = e.composedPath()\n\t\tfor (const node of path) {\n\t\t\tif (node instanceof HTMLElement) {\n\t\t\t\t_publishEventHost(node)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\toverride connectedCallback(): void {\n\t\tsuper.connectedCallback()\n\t\tfor (const tmpl of this.provides) {\n\t\t\tconst isolated = tmpl._isolatedInstance()\n\t\t\tconst ctx = createContext<unknown>(stateContextKey(tmpl.namespace))\n\t\t\t// ContextProvider auto-wires via the host's ReactiveControllerHost\n\t\t\t// interface (LitElement satisfies it). It listens for\n\t\t\t// `context-request` events and responds with `isolated` for any\n\t\t\t// requester whose `event.context === ctx`.\n\t\t\tconst provider = new ContextProvider(this, { context: ctx, initialValue: isolated })\n\t\t\tthis._scoped.push({ isolated, provider })\n\t\t}\n\t\tfor (const type of EVENT_TYPES) {\n\t\t\tthis.addEventListener(type, this._publishEventTargetAsHost, { capture: true })\n\t\t}\n\t}\n\n\toverride disconnectedCallback(): void {\n\t\tfor (const type of EVENT_TYPES) {\n\t\t\tthis.removeEventListener(type, this._publishEventTargetAsHost, { capture: true })\n\t\t}\n\t\tfor (const entry of this._scoped) {\n\t\t\tentry.isolated.destroy()\n\t\t}\n\t\tthis._scoped = []\n\t\tsuper.disconnectedCallback()\n\t}\n\n\toverride render() {\n\t\treturn html`<slot></slot>`\n\t}\n}\n\n// Imperative define so a second load (source + dist) is a no-op rather than\n// a throw — the registry is process-global; whichever class wins serves the\n// element identity for the page.\nif (!customElements.get('schmancy-context')) {\n\tcustomElements.define('schmancy-context', SchmancyContext)\n}\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'schmancy-context': SchmancyContext\n\t}\n}\n","// @mhmo91/schmancy/state — reactive state primitive.\n//\n// Module-scoped singletons keyed by namespace. Each state exposes:\n// - `value: T` current snapshot (defaultValue while loading)\n// - `signal: Signal.State<T>` raw TC39 signal (use with computed())\n// - `$: Observable<T>` RxJS surface (auto-emits on change, microtask-coalesced)\n// - `ready: Promise<void>` resolves once initial load attempt completes\n// - `loaded: boolean` runtime flag — `value` reflects stored data\n//\n// Three call shapes:\n// const cart = state<CartState>('hannah/cart').session({ items: [], total: 0 })\n// const cart = state('hannah/cart').session(initialCart) // typed-const\n// declare module '@mhmo91/schmancy/state' { // registry\n// interface SchmancyStateRegistry { 'hannah/cart': CartState }\n// }\n// const cart = state('hannah/cart').session({ items: [], total: 0 })\n\nimport { Signal } from '@lit-labs/signals'\n// `@lit/context` re-exports `ContextRequestEvent` as `ContextEvent` from\n// its public entry. Same class, just a shorter public name.\nimport { ContextEvent as ContextRequestEvent, createContext } from '@lit/context'\nimport { Observable } from 'rxjs'\nimport { produce, type Draft } from 'immer'\n\nimport { createAdapter, type StorageAdapter, type StorageBackend } from './persist'\nimport { resolveActiveHost, stateContextKey } from './active-host'\n// Side-effect import: registers the `<schmancy-context>` element so users\n// only need to import from `@mhmo91/schmancy/state` to get both the factory\n// and the scoping primitive.\nimport './schmancy-context'\n\nexport type { StorageBackend } from './persist'\nexport { Signal } from '@lit-labs/signals'\nexport { _activeHost } from './active-host'\nexport { SchmancyContext } from './schmancy-context'\n\n// ---------------------------------------------------------------------------\n// Public type surface\n// ---------------------------------------------------------------------------\n\nconst stateBrand: unique symbol = Symbol('schmancy.state')\nconst namespaceBrand: unique symbol = Symbol('schmancy.state.namespace')\n\n/**\n * Open registry — augment via `declare module '@mhmo91/schmancy/state'` to\n * bind a TypeScript type to a namespace string. Augmenting flips that\n * namespace to overload (A) of the factory: zero ceremony at the call\n * site, T comes from the registry.\n */\nexport interface SchmancyStateRegistry {}\n\nexport type RegisteredNamespace = keyof SchmancyStateRegistry & string\n\n/** Feature-prefix convention enforced at compile time. */\nexport type FeatureNamespace = `${string}/${string}`\n\nexport type AssertNovel<NS extends string> = NS extends RegisteredNamespace\n\t? never & { readonly __error: `Namespace \"${NS}\" already registered` }\n\t: NS\n\nexport type SyncStorage = Exclude<StorageBackend, 'indexeddb'>\nexport type AsyncStorage = Extract<StorageBackend, 'indexeddb'>\nexport type IsAsync<S extends StorageBackend> = S extends AsyncStorage ? true : false\n\n// Detect explicit null/undefined in T's union — works in BOTH strict and\n// non-strict tsconfigs. The relaxed `null extends T` form fires for every\n// T when strictNullChecks is off, which classifies every shape as\n// 'nullable'. Distributing `T extends null/undefined` is a structural\n// subtype check that doesn't depend on strict mode.\ntype _Has<T, U> = T extends U ? true : never\ntype _IsNullable<T> = [_Has<T, null> | _Has<T, undefined>] extends [never] ? false : true\n\n/**\n * Shape classifier — drives the variant write API per T. Order: structural\n * shapes first (Map / Set / Array), primitives, then nullable-union check,\n * then plain object.\n */\nexport type Kind<T> = [T] extends [Map<unknown, unknown>]\n\t? 'map'\n\t: [T] extends [Set<unknown>]\n\t\t? 'set'\n\t\t: [T] extends [readonly unknown[]]\n\t\t\t? 'array'\n\t\t\t: [T] extends [string | number | boolean | bigint | symbol]\n\t\t\t\t? 'primitive'\n\t\t\t\t: _IsNullable<T> extends true\n\t\t\t\t\t? 'nullable'\n\t\t\t\t\t: [T] extends [object]\n\t\t\t\t\t\t? 'object'\n\t\t\t\t\t\t: 'unknown'\n\nexport interface ObjectAPI<T> {\n\tset(patch: Partial<T>, merge?: boolean): void\n\treplace(next: T): void\n\tupdate(recipe: (draft: Draft<T>) => void): void\n\tdelete<K extends keyof T>(key: K): void\n}\n\nexport interface MapAPI<T> {\n\tset: T extends Map<infer K, infer V> ? (key: K, value: V) => void : never\n\treplace(next: T): void\n\tdelete: T extends Map<infer K, unknown> ? (key: K) => void : never\n\tclear(): void\n}\n\nexport interface SetAPI<T> {\n\tadd: T extends Set<infer U> ? (value: U) => void : never\n\tdelete: T extends Set<infer U> ? (value: U) => boolean : never\n\ttoggle: T extends Set<infer U> ? (value: U) => void : never\n\treplace(next: T): void\n\tclear(): void\n}\n\nexport interface ArrayAPI<T> {\n\tpush: T extends readonly (infer U)[] ? (...items: U[]) => void : never\n\treplace(next: T): void\n\tupdate(recipe: (draft: Draft<T>) => void): void\n\tclear(): void\n}\n\nexport interface ScalarAPI<T> {\n\tset(next: T): void\n\treplace(next: T): void\n}\n\nexport type WriteAPI<T> = Kind<T> extends 'map'\n\t? MapAPI<T>\n\t: Kind<T> extends 'set'\n\t\t? SetAPI<T>\n\t\t: Kind<T> extends 'array'\n\t\t\t? ArrayAPI<T>\n\t\t\t: Kind<T> extends 'object'\n\t\t\t\t? ObjectAPI<T>\n\t\t\t\t: ScalarAPI<T>\n\nexport interface BaseAPI<NS extends string, T, S extends StorageBackend> {\n\treadonly [stateBrand]: true\n\treadonly namespace: NS & { readonly [namespaceBrand]: NS }\n\treadonly storage: S\n\t/**\n\t * Current value. For sync backends (memory/local/session) the load is\n\t * synchronous, so the type narrows to `T`. For `idb` the load is genuinely\n\t * async — `value` is `T | undefined` until `ready` resolves. Read with\n\t * `state.value ?? state.defaultValue` if you don't care about the\n\t * pre-load distinction; await `state.ready` if you do.\n\t */\n\treadonly value: IsAsync<S> extends true ? T | undefined : T\n\treadonly defaultValue: T\n\treadonly ready: Promise<void>\n\treadonly loaded: boolean\n\treadonly signal: Signal.State<T>\n\treadonly $: Observable<T>\n\tdestroy(): void\n\t/** Internal: build a fresh per-`<schmancy-context>` copy seeded with the\n\t * current value. Exposed on the type so a state can be passed to\n\t * `<schmancy-context provides={[…]}>` without casts. Not for end-user\n\t * code — the leading underscore signals \"internal API\". */\n\t_isolatedInstance(): { destroy(): void } & Record<string | symbol, unknown>\n}\n\nexport interface SyncState<NS extends string, T, S extends SyncStorage>\n\textends BaseAPI<NS, T, S>,\n\t\tDisposable {\n\t[Symbol.dispose](): void\n}\n\nexport interface AsyncState<NS extends string, T>\n\textends BaseAPI<NS, T, 'indexeddb'>,\n\t\tDisposable,\n\t\tAsyncDisposable {\n\t[Symbol.dispose](): void\n\t[Symbol.asyncDispose](): Promise<void>\n}\n\nexport type State<NS extends string, T, S extends StorageBackend> = S extends AsyncStorage\n\t? AsyncState<NS, T> & WriteAPI<T>\n\t: SyncState<NS, T, S extends SyncStorage ? S : never> & WriteAPI<T>\n\nexport interface NamespaceHandlePinned<NS extends string, T> {\n\tmemory(initial: T): State<NS, T, 'memory'>\n\tlocal(initial: T): State<NS, T, 'local'>\n\tsession(initial: T): State<NS, T, 'session'>\n\tidb(initial: T): State<NS, T, 'indexeddb'>\n}\n\nexport interface NamespaceHandleInferred<NS extends string> {\n\tmemory<U>(initial: U): State<NS, U, 'memory'>\n\tlocal<U>(initial: U): State<NS, U, 'local'>\n\tsession<U>(initial: U): State<NS, U, 'session'>\n\tidb<U>(initial: U): State<NS, U, 'indexeddb'>\n}\n\n// ---------------------------------------------------------------------------\n// Runtime — variant detection + state instance construction\n// ---------------------------------------------------------------------------\n\ntype RuntimeKind = 'map' | 'set' | 'array' | 'object' | 'scalar'\n\nfunction detectKind(value: unknown): RuntimeKind {\n\tif (value instanceof Map) return 'map'\n\tif (value instanceof Set) return 'set'\n\tif (Array.isArray(value)) return 'array'\n\tif (value === null || value === undefined) return 'scalar'\n\tif (typeof value !== 'object') return 'scalar'\n\treturn 'object'\n}\n\n// Globalize the namespace-claim set so any number of schmancy module copies\n// share a single registry. Without this, source-state and dist-state would\n// each maintain their own `claimed` set and could both register the same\n// namespace, producing two singletons with the same name.\nconst CLAIMED_KEY = Symbol.for('schmancy.state.claimed')\nconst __claimedSlot = (globalThis as { [CLAIMED_KEY]?: Set<string> })\n__claimedSlot[CLAIMED_KEY] ??= new Set<string>()\nconst claimed = __claimedSlot[CLAIMED_KEY]!\n\n// ---------------------------------------------------------------------------\n// Context resolution.\n//\n// Every read (`value`, `signal`, `$`) and write (`set`, `replace`, `update`,\n// `delete`, `push`, `add`, `toggle`, `clear`) on a state instance routes\n// through `resolveContextual`. It asks \"is this call happening inside a\n// `<schmancy-context provides={[...]}>` subtree?\" by dispatching a\n// `context-request` event from the active host (resolved via the layered\n// fallback in `active-host.ts`). If a provider responds, the call routes to\n// the per-context isolated instance; otherwise it falls through to the\n// module-scoped global. The decision is cached per-host-per-namespace in a\n// WeakMap so repeat reads stay O(1).\n// ---------------------------------------------------------------------------\n\n// Globalize the per-host resolver cache so that a write through one schmancy\n// copy and a read through another resolve to the same target object — the\n// cache keys are DOM elements (process-global), but the cache itself must\n// also be shared.\nconst CACHE_KEY = Symbol.for('schmancy.state.hostResolverCache')\nconst __cacheSlot = (globalThis as {\n\t[CACHE_KEY]?: WeakMap<HTMLElement, Map<string, unknown>>\n})\n__cacheSlot[CACHE_KEY] ??= new WeakMap<HTMLElement, Map<string, unknown>>()\nconst hostResolverCache = __cacheSlot[CACHE_KEY]!\n\nfunction resolveContextual(namespace: string, fallback: unknown): unknown {\n\tconst host = resolveActiveHost()\n\tif (host === undefined) return fallback\n\n\tconst cached = hostResolverCache.get(host)?.get(namespace)\n\tif (cached !== undefined) return cached\n\n\tlet resolved: unknown = undefined\n\tconst ctx = createContext<unknown>(stateContextKey(namespace))\n\thost.dispatchEvent(\n\t\tnew ContextRequestEvent(ctx, host, value => {\n\t\t\tresolved = value\n\t\t}),\n\t)\n\n\tconst result = resolved !== undefined ? resolved : fallback\n\tlet perHost = hostResolverCache.get(host)\n\tif (!perHost) {\n\t\tperHost = new Map<string, unknown>()\n\t\thostResolverCache.set(host, perHost)\n\t}\n\tperHost.set(namespace, result)\n\treturn result\n}\n\ninterface InternalState {\n\tsignal: Signal.State<unknown>\n\tstorage: StorageBackend\n\tadapter: StorageAdapter<unknown>\n\tpendingWrite: Promise<void> | null\n\tscheduledWrite: boolean\n\tdisposed: boolean\n}\n\nfunction scheduleWrite(internal: InternalState): void {\n\tif (internal.scheduledWrite || internal.disposed) return\n\tinternal.scheduledWrite = true\n\tqueueMicrotask(() => {\n\t\tinternal.scheduledWrite = false\n\t\tif (internal.disposed) return\n\t\tinternal.pendingWrite = internal.adapter.save(internal.signal.get()).catch(err => {\n\t\t\tconsole.error('[state] save failed:', err)\n\t\t})\n\t})\n}\n\nfunction signalToObservable<T>(signal: Signal.State<T>): Observable<T> {\n\treturn new Observable<T>(subscriber => {\n\t\tsubscriber.next(signal.get())\n\t\tlet scheduled = false\n\t\tconst watcher = new Signal.subtle.Watcher(() => {\n\t\t\tif (scheduled) return\n\t\t\tscheduled = true\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tscheduled = false\n\t\t\t\tif (subscriber.closed) return\n\t\t\t\tsubscriber.next(signal.get())\n\t\t\t\twatcher.watch(signal)\n\t\t\t})\n\t\t})\n\t\twatcher.watch(signal)\n\t\treturn () => watcher.unwatch(signal)\n\t})\n}\n\nfunction buildWriteApi(internal: InternalState, kind: RuntimeKind): Record<string, unknown> {\n\tconst commit = (next: unknown): void => {\n\t\tif (internal.disposed) return\n\t\tinternal.signal.set(next)\n\t\tscheduleWrite(internal)\n\t}\n\n\tconst common = {\n\t\treplace: (next: unknown) => commit(next),\n\t}\n\n\tswitch (kind) {\n\t\tcase 'object':\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tset(patch: Record<string, unknown>, merge = true) {\n\t\t\t\t\tconst current = internal.signal.get() as Record<string, unknown>\n\t\t\t\t\tcommit(merge ? { ...current, ...patch } : patch)\n\t\t\t\t},\n\t\t\t\tupdate(recipe: (draft: unknown) => void) {\n\t\t\t\t\tcommit(produce(internal.signal.get(), recipe))\n\t\t\t\t},\n\t\t\t\tdelete(key: string) {\n\t\t\t\t\tconst current = internal.signal.get() as Record<string, unknown>\n\t\t\t\t\tconst next = { ...current }\n\t\t\t\t\tdelete next[key]\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t}\n\n\t\tcase 'map':\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tset(key: unknown, value: unknown) {\n\t\t\t\t\tconst current = internal.signal.get() as Map<unknown, unknown>\n\t\t\t\t\tconst next = new Map(current)\n\t\t\t\t\tnext.set(key, value)\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t\tdelete(key: unknown) {\n\t\t\t\t\tconst current = internal.signal.get() as Map<unknown, unknown>\n\t\t\t\t\tconst next = new Map(current)\n\t\t\t\t\tnext.delete(key)\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t\tclear() {\n\t\t\t\t\tcommit(new Map())\n\t\t\t\t},\n\t\t\t}\n\n\t\tcase 'set':\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tadd(value: unknown) {\n\t\t\t\t\tconst current = internal.signal.get() as Set<unknown>\n\t\t\t\t\tif (current.has(value)) return\n\t\t\t\t\tconst next = new Set(current)\n\t\t\t\t\tnext.add(value)\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t\tdelete(value: unknown): boolean {\n\t\t\t\t\tconst current = internal.signal.get() as Set<unknown>\n\t\t\t\t\tif (!current.has(value)) return false\n\t\t\t\t\tconst next = new Set(current)\n\t\t\t\t\tnext.delete(value)\n\t\t\t\t\tcommit(next)\n\t\t\t\t\treturn true\n\t\t\t\t},\n\t\t\t\ttoggle(value: unknown) {\n\t\t\t\t\tconst current = internal.signal.get() as Set<unknown>\n\t\t\t\t\tconst next = new Set(current)\n\t\t\t\t\tif (next.has(value)) {\n\t\t\t\t\t\tnext.delete(value)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnext.add(value)\n\t\t\t\t\t}\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t\tclear() {\n\t\t\t\t\tcommit(new Set())\n\t\t\t\t},\n\t\t\t}\n\n\t\tcase 'array':\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tpush(...items: unknown[]) {\n\t\t\t\t\tconst current = internal.signal.get() as unknown[]\n\t\t\t\t\tcommit([...current, ...items])\n\t\t\t\t},\n\t\t\t\tupdate(recipe: (draft: unknown) => void) {\n\t\t\t\t\tcommit(produce(internal.signal.get(), recipe))\n\t\t\t\t},\n\t\t\t\tclear() {\n\t\t\t\t\tcommit([])\n\t\t\t\t},\n\t\t\t}\n\n\t\tcase 'scalar':\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tset(next: unknown) {\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t}\n\t}\n}\n\ninterface CreateInstanceArgs {\n\tnamespace: string\n\tinitial: unknown\n\tstorage: StorageBackend\n}\n\ninterface CreateInstanceOptions {\n\t/** When true, the returned instance is a per-`<schmancy-context>` copy:\n\t * it does NOT claim the namespace in `claimed`, it does NOT route reads\n\t * or writes through `resolveContextual` (so it can serve as the\n\t * resolution target without recursion), and it does NOT expose\n\t * `_isolatedInstance` (you only isolate the global). */\n\tisolated?: boolean\n}\n\nfunction reportLoadError(err: unknown): void {\n\tconsole.error('[state] load failed:', err)\n}\n\nfunction createInstance(args: CreateInstanceArgs, options: CreateInstanceOptions = {}): unknown {\n\tconst { namespace, initial, storage } = args\n\tconst isolated = options.isolated === true\n\tconst adapter = createAdapter<unknown>(storage, namespace)\n\tconst signal = new Signal.State<unknown>(initial)\n\tconst internal: InternalState = {\n\t\tsignal,\n\t\tstorage,\n\t\tadapter,\n\t\tpendingWrite: null,\n\t\tscheduledWrite: false,\n\t\tdisposed: false,\n\t}\n\n\tlet loaded = false\n\tconst applyLoaded = (stored: unknown): void => {\n\t\tif (internal.disposed) return\n\t\tif (stored !== null && stored !== undefined) {\n\t\t\tinternal.signal.set(stored)\n\t\t}\n\t}\n\tconst markLoaded = (): boolean => (loaded = true)\n\tconst ready = adapter\n\t\t.load()\n\t\t.then(applyLoaded, reportLoadError)\n\t\t.then(markLoaded)\n\t\t.then(() => undefined)\n\n\tconst observable = signalToObservable(signal)\n\tconst writeApi = buildWriteApi(internal, detectKind(initial))\n\n\tasync function flushAndClose(): Promise<void> {\n\t\t// Wait for any in-flight write, then any scheduled microtask write.\n\t\tif (internal.pendingWrite) await internal.pendingWrite\n\t\t// Drain a possibly-still-scheduled microtask:\n\t\tawait new Promise<void>(resolve => queueMicrotask(resolve))\n\t\tif (internal.pendingWrite) await internal.pendingWrite\n\t\tif (adapter.close) await adapter.close()\n\t}\n\n\tconst dispose = (): void => {\n\t\tif (internal.disposed) return\n\t\tinternal.disposed = true\n\t\t// Fire-and-forget close for sync backends; AsyncDisposable variant\n\t\t// has its own awaited path via Symbol.asyncDispose.\n\t\tvoid flushAndClose()\n\t\tclaimed.delete(namespace)\n\t}\n\n\tconst asyncDispose = async (): Promise<void> => {\n\t\tif (internal.disposed) return\n\t\tinternal.disposed = true\n\t\tawait flushAndClose()\n\t\tclaimed.delete(namespace)\n\t}\n\n\t// Build the instance with explicit property definitions so the `value`\n\t// and `loaded` getters stay live. (A `{ ...base }` spread invokes the\n\t// getter once at spread time and freezes the result — that snapshot\n\t// then disagrees with the signal on every subsequent write.)\n\tconst instance: Record<string | symbol, unknown> = Object.assign(Object.create(null) as object, {\n\t\t[stateBrand]: true,\n\t\tnamespace,\n\t\tstorage,\n\t\tdefaultValue: initial,\n\t\tready,\n\t\tdestroy: dispose,\n\t\t[Symbol.dispose]: dispose,\n\t})\n\n\tObject.defineProperty(instance, 'loaded', {\n\t\tget: () => loaded,\n\t\tenumerable: true,\n\t})\n\n\tif (storage === 'indexeddb') {\n\t\tinstance[Symbol.asyncDispose] = asyncDispose\n\t}\n\n\tif (isolated) {\n\t\t// Per-context copy. Reads and writes go straight to its own signal —\n\t\t// no resolveContextual call, so it serves as a recursion-free\n\t\t// resolution target.\n\t\tObject.defineProperty(instance, 'value', {\n\t\t\tget: () => signal.get(),\n\t\t\tenumerable: true,\n\t\t})\n\t\tinstance.signal = signal\n\t\tinstance.$ = observable\n\t\tObject.assign(instance, writeApi)\n\t\treturn instance\n\t}\n\n\t// Global instance. Every public read/write resolves through the active\n\t// host: inside a `<schmancy-context provides={[…]}>` it routes to the\n\t// per-context copy; outside, it falls back to this same instance and\n\t// reads/writes its own signal directly. The cache in `resolveContextual`\n\t// keeps the lookup O(1) past the first hit.\n\tconst isolatedTarget: Record<string | symbol, unknown> = Object.assign(Object.create(null), {\n\t\tsignal,\n\t\t$: observable,\n\t\t...writeApi,\n\t})\n\tObject.defineProperty(isolatedTarget, 'value', {\n\t\tget: () => signal.get(),\n\t\tenumerable: true,\n\t})\n\n\tObject.defineProperty(instance, 'value', {\n\t\tget: () => (resolveContextual(namespace, isolatedTarget) as { value: unknown }).value,\n\t\tenumerable: true,\n\t})\n\tObject.defineProperty(instance, 'signal', {\n\t\tget: () =>\n\t\t\t(resolveContextual(namespace, isolatedTarget) as { signal: Signal.State<unknown> }).signal,\n\t\tenumerable: true,\n\t})\n\tObject.defineProperty(instance, '$', {\n\t\tget: () =>\n\t\t\t(resolveContextual(namespace, isolatedTarget) as { $: Observable<unknown> }).$,\n\t\tenumerable: true,\n\t})\n\tfor (const key of Object.keys(writeApi)) {\n\t\tinstance[key] = (...args: unknown[]): unknown => {\n\t\t\tconst target = resolveContextual(namespace, isolatedTarget) as Record<\n\t\t\t\tstring,\n\t\t\t\t(...a: unknown[]) => unknown\n\t\t\t>\n\t\t\treturn target[key](...args)\n\t\t}\n\t}\n\n\t// Hook used by `<schmancy-context>` to mint a per-context copy seeded\n\t// with the current value. Internal: not part of the public State<> type.\n\tinstance._isolatedInstance = (): unknown =>\n\t\tcreateInstance(\n\t\t\t{ namespace, initial: signal.get(), storage: 'memory' },\n\t\t\t{ isolated: true },\n\t\t)\n\n\treturn instance\n}\n\nfunction makeHandle(namespace: string): Record<string, (initial: unknown) => unknown> {\n\tif (claimed.has(namespace)) {\n\t\tthrow new Error(\n\t\t\t`[state] namespace \"${namespace}\" already registered. Each namespace must be unique.`,\n\t\t)\n\t}\n\tclaimed.add(namespace)\n\treturn {\n\t\tmemory: initial => createInstance({ namespace, initial, storage: 'memory' }),\n\t\tlocal: initial => createInstance({ namespace, initial, storage: 'local' }),\n\t\tsession: initial => createInstance({ namespace, initial, storage: 'session' }),\n\t\tidb: initial => createInstance({ namespace, initial, storage: 'indexeddb' }),\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Three-overload factory.\n// (A) registered → pinned T from registry\n// (C) unregistered, no type arg → inferred T (typed-const flow)\n// (B) unregistered, explicit type arg → pinned T\n// Order matters for resolution; do not reorder.\n// ---------------------------------------------------------------------------\n\nexport function state<NS extends RegisteredNamespace>(\n\tnamespace: NS,\n): NamespaceHandlePinned<NS, SchmancyStateRegistry[NS]>\n\nexport function state<const NS extends FeatureNamespace>(\n\tnamespace: NS extends RegisteredNamespace ? never : AssertNovel<NS>,\n): NamespaceHandleInferred<NS>\n\nexport function state<T, const NS extends FeatureNamespace = FeatureNamespace>(\n\tnamespace: NS extends RegisteredNamespace ? never : AssertNovel<NS>,\n): NamespaceHandlePinned<NS, T>\n\nexport function state(namespace: unknown): unknown {\n\tif (typeof namespace !== 'string') {\n\t\tthrow new TypeError('[state] namespace must be a string')\n\t}\n\tif (!namespace.includes('/')) {\n\t\tthrow new TypeError(\n\t\t\t`[state] namespace \"${namespace}\" must follow the \"feature/name\" convention.`,\n\t\t)\n\t}\n\treturn makeHandle(namespace)\n}\n\n// ---------------------------------------------------------------------------\n// Derived state — re-export the upstream computed primitive directly.\n// Reading state.value (which calls signal.get() under the hood) inside a\n// computed callback auto-tracks the dependency.\n// ---------------------------------------------------------------------------\n\nexport { computed } from '@lit-labs/signals'\n\n// ---------------------------------------------------------------------------\n// effect(fn) — run a side-effect function whenever any signal it reads\n// changes. Returns a Disposable so the effect can be cleaned up.\n//\n// const stop = effect(() => {\n// document.title = `${cart.value.items.length} items`\n// })\n// ...later...\n// stop[Symbol.dispose]()\n//\n// The effect runs once eagerly to register dependencies, then re-runs\n// (microtask-coalesced) whenever any read signal changes.\n// ---------------------------------------------------------------------------\n\nexport interface EffectHandle extends Disposable {\n\t[Symbol.dispose](): void\n}\n\nexport function effect(fn: () => void): EffectHandle {\n\tlet scheduled = false\n\tlet disposed = false\n\tlet watcher: Signal.subtle.Watcher | undefined\n\n\tconst run = (): void => {\n\t\tif (disposed) return\n\t\t// Wrap fn in a Computed so signal reads are tracked. The computed's\n\t\t// value is unused — we only care about the dependency graph it builds.\n\t\tconst computation = new Signal.Computed(() => {\n\t\t\tfn()\n\t\t\treturn undefined\n\t\t})\n\t\t// Reading the computed registers our Watcher as a sink for every\n\t\t// signal the fn touches.\n\t\twatcher?.unwatch()\n\t\twatcher = new Signal.subtle.Watcher(() => {\n\t\t\tif (scheduled || disposed) return\n\t\t\tscheduled = true\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tscheduled = false\n\t\t\t\tif (disposed) return\n\t\t\t\trun()\n\t\t\t})\n\t\t})\n\t\twatcher.watch(computation)\n\t\tcomputation.get()\n\t}\n\n\trun()\n\n\treturn {\n\t\t[Symbol.dispose](): void {\n\t\t\tif (disposed) return\n\t\t\tdisposed = true\n\t\t\twatcher?.unwatch()\n\t\t\twatcher = undefined\n\t\t},\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Observable → state bridge.\n// ---------------------------------------------------------------------------\n\nexport interface FromObservableOptions {\n\tstorage?: StorageBackend\n}\n\n/**\n * Lift an Observable into a state(). The state is initialized with\n * `initial`, then updates on every Observable emission. Cleanup on\n * dispose unsubscribes the source.\n */\nexport function stateFromObservable<T, NS extends FeatureNamespace>(\n\tobservable: Observable<T>,\n\tnamespace: NS,\n\tinitial: T,\n\toptions: FromObservableOptions = {},\n): State<NS, T, 'memory'> {\n\tconst storage = options.storage ?? 'memory'\n\tconst handle = makeHandle(namespace)\n\tconst inst = handle[storage](initial) as State<NS, T, 'memory'> & {\n\t\treadonly signal: Signal.State<T>\n\t\t[Symbol.dispose](): void\n\t}\n\tconst subscription = observable.subscribe({\n\t\tnext: value => inst.signal.set(value),\n\t\terror: err => console.error(`[state] from(${namespace}) source errored:`, err),\n\t})\n\tconst originalDispose = inst[Symbol.dispose].bind(inst)\n\t;(inst as { [Symbol.dispose]: () => void })[Symbol.dispose] = () => {\n\t\tsubscription.unsubscribe()\n\t\toriginalDispose()\n\t}\n\treturn inst\n}\n\n// ---------------------------------------------------------------------------\n// bindState(host, source) — Lit ReactiveController helper for one-way binding.\n//\n// Subscribes in hostConnected, unsubscribes in hostDisconnected, calls\n// host.requestUpdate() on every emission. Returned object exposes the same\n// `value` and `$` surface as the source so render code reads naturally:\n//\n// class CartView extends LitElement {\n// cart = bindState(this, cartState)\n// render() { return html`Items: ${this.cart.value.items.length}` }\n// }\n//\n// Decorator (`@observe`) form is deliberately deferred — schmancy's\n// tsconfig still uses experimentalDecorators=true and flipping to\n// TC39 native produces ~9k errors across the codebase. The helper\n// gives the same lifecycle guarantees with zero tsconfig churn.\n// ---------------------------------------------------------------------------\n\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\n\n/** Permissive duck-typed contract — v1 IStore<T>, v2 State<>, and\n * computed() outputs (`Signal.Computed<T>` wrapped in a thin shim) all\n * satisfy it once you supply a `value` getter and an Observable `$`. */\nexport interface ObservableState<T> {\n\treadonly value: T\n\treadonly $: Observable<T>\n}\n\nexport interface BoundState<T> {\n\treadonly value: T\n\treadonly $: Observable<T>\n}\n\nclass BindStateController<T> implements ReactiveController {\n\tprivate subscription: import('rxjs').Subscription | undefined\n\tprivate latest: T\n\tconstructor(\n\t\tprivate readonly host: ReactiveControllerHost,\n\t\tprivate readonly source: ObservableState<T>,\n\t) {\n\t\tthis.latest = source.value\n\t\thost.addController(this)\n\t}\n\tget value(): T {\n\t\treturn this.latest\n\t}\n\tget $(): Observable<T> {\n\t\treturn this.source.$\n\t}\n\thostConnected(): void {\n\t\tthis.subscription = this.source.$.subscribe(v => {\n\t\t\tthis.latest = v\n\t\t\tthis.host.requestUpdate()\n\t\t})\n\t}\n\thostDisconnected(): void {\n\t\tthis.subscription?.unsubscribe()\n\t\tthis.subscription = undefined\n\t}\n}\n\nexport function bindState<T>(\n\thost: ReactiveControllerHost,\n\tsource: ObservableState<T>,\n): BoundState<T> {\n\treturn new BindStateController(host, source)\n}\n\n// ---------------------------------------------------------------------------\n// @observe(source) — legacy property decorator for one-way binding.\n//\n// Usage:\n// class CartView extends LitElement {\n// @observe(cart) cart!: CartState\n// render() { return html`Items: ${this.cart.items.length}` }\n// }\n//\n// Reads return the latest value emitted by the source (falling back to\n// `source.value` before the first emission). Caller writes are dropped\n// with a dev-mode warning — the source is the single source of truth.\n//\n// Per-instance subscription is wired via Lit's static `addInitializer`,\n// which runs at instance construction and gives the decorator access to\n// the host. A `ReactiveController` handles the lifecycle: subscribe in\n// `hostConnected`, unsubscribe in `hostDisconnected`. Multiple `@observe`\n// decorators on the same class register independent controllers — no\n// init-order bookkeeping, no prototype-walking.\n//\n// Legacy decorator (matches the rest of schmancy's @property / @state /\n// @query family). Works under the existing `experimentalDecorators: true`\n// tsconfig — no migration required.\n// ---------------------------------------------------------------------------\n\ninterface ObserveHost extends ReactiveControllerHost {\n\taddController(controller: ReactiveController): void\n}\n\ninterface LitElementCtor {\n\taddInitializer(initializer: (host: ObserveHost) => void): void\n}\n\nexport function observe<T>(source: ObservableState<T>) {\n\treturn function (proto: object, propertyKey: string | symbol): void {\n\t\tconst storageKey = Symbol(`__observe_${String(propertyKey)}`)\n\n\t\t// Per-prototype accessor — reads return the latest cached value,\n\t\t// falling back to `source.value` before the first emission lands.\n\t\t// Writes from callers are dropped with a dev warning.\n\t\tObject.defineProperty(proto, propertyKey, {\n\t\t\tget(this: Record<symbol, T>): T {\n\t\t\t\tconst cached = this[storageKey]\n\t\t\t\treturn cached !== undefined ? cached : source.value\n\t\t\t},\n\t\t\tset(_value: T): void {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`@observe: field \"${String(propertyKey)}\" is read-only — write ignored. ` +\n\t\t\t\t\t\t`Update the source state directly.`,\n\t\t\t\t)\n\t\t\t},\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t})\n\n\t\t// Per-instance subscription via Lit's addInitializer hook.\n\t\tconst ctor = proto.constructor as unknown as LitElementCtor\n\t\tif (typeof ctor.addInitializer !== 'function') {\n\t\t\tthrow new TypeError(\n\t\t\t\t`@observe requires a Lit ReactiveElement subclass — ${proto.constructor.name} ` +\n\t\t\t\t\t`does not provide static addInitializer.`,\n\t\t\t)\n\t\t}\n\n\t\tctor.addInitializer((host: ObserveHost) => {\n\t\t\tlet subscription: import('rxjs').Subscription | undefined\n\t\t\thost.addController({\n\t\t\t\thostConnected(): void {\n\t\t\t\t\tsubscription = source.$.subscribe(value => {\n\t\t\t\t\t\t;(host as unknown as Record<symbol, T>)[storageKey] = value\n\t\t\t\t\t\thost.requestUpdate()\n\t\t\t\t\t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;GAE/B,IAAI,GAAA;GAMJ,cAAA,CAAc;GACd,YAAA,CAAY;GAAA,CAAA;EAIb,IAAM,IAAO,EAAM;AACnB,MAAmC,OAAxB,EAAK,kBAAmB,WAClC,OAAU,UACT,sDAAsD,EAAM,YAAY,KAAA,0CAAA;AAK1E,IAAK,gBAAgB,MAAA;GACpB,IAAI;AACJ,KAAK,cAAc;IAClB,gBAAA;AACC,SAAe,EAAO,EAAE,WAAU,MAAA;AAC/B,QAAsC,KAAc,GACtD,EAAK,eAAA;OAAA;;IAGP,mBAAA;AACC,QAAc,aAAA,EACd,IAAA,KAAe;;IAAA,CAAA;IAAA;;;AAAA,SAAA,MAAA,GAAA,MAAA,GAAA,MAAA,GAAA,MAAA,GAAA,MAAA,GAAA,KAAA,GAAA,MAAA,GAAA,MAAA"}
1
+ {"version":3,"file":"state-nm8yzMPp.js","names":["finalize","#data","#db","#opening"],"sources":["../node_modules/immer/dist/immer.mjs","../src/state/persist.ts","../src/state/schmancy-context.ts","../src/state/index.ts"],"sourcesContent":["// src/utils/env.ts\nvar NOTHING = Symbol.for(\"immer-nothing\");\nvar DRAFTABLE = Symbol.for(\"immer-draftable\");\nvar DRAFT_STATE = Symbol.for(\"immer-state\");\n\n// src/utils/errors.ts\nvar errors = process.env.NODE_ENV !== \"production\" ? [\n // All error codes, starting by 0:\n function(plugin) {\n return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \\`enable${plugin}()\\` when initializing your application.`;\n },\n function(thing) {\n return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;\n },\n \"This object has been frozen and should not be mutated\",\n function(data) {\n return \"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? \" + data;\n },\n \"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.\",\n \"Immer forbids circular references\",\n \"The first or second argument to `produce` must be a function\",\n \"The third argument to `produce` must be a function or undefined\",\n \"First argument to `createDraft` must be a plain object, an array, or an immerable object\",\n \"First argument to `finishDraft` must be a draft returned by `createDraft`\",\n function(thing) {\n return `'current' expects a draft, got: ${thing}`;\n },\n \"Object.defineProperty() cannot be used on an Immer draft\",\n \"Object.setPrototypeOf() cannot be used on an Immer draft\",\n \"Immer only supports deleting array indices\",\n \"Immer only supports setting array indices and the 'length' property\",\n function(thing) {\n return `'original' expects a draft, got: ${thing}`;\n }\n // Note: if more errors are added, the errorOffset in Patches.ts should be increased\n // See Patches.ts for additional errors\n] : [];\nfunction die(error, ...args) {\n if (process.env.NODE_ENV !== \"production\") {\n const e = errors[error];\n const msg = isFunction(e) ? e.apply(null, args) : e;\n throw new Error(`[Immer] ${msg}`);\n }\n throw new Error(\n `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`\n );\n}\n\n// src/utils/common.ts\nvar O = Object;\nvar getPrototypeOf = O.getPrototypeOf;\nvar CONSTRUCTOR = \"constructor\";\nvar PROTOTYPE = \"prototype\";\nvar CONFIGURABLE = \"configurable\";\nvar ENUMERABLE = \"enumerable\";\nvar WRITABLE = \"writable\";\nvar VALUE = \"value\";\nvar isDraft = (value) => !!value && !!value[DRAFT_STATE];\nfunction isDraftable(value) {\n if (!value)\n return false;\n return isPlainObject(value) || isArray(value) || !!value[DRAFTABLE] || !!value[CONSTRUCTOR]?.[DRAFTABLE] || isMap(value) || isSet(value);\n}\nvar objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString();\nvar cachedCtorStrings = /* @__PURE__ */ new WeakMap();\nfunction isPlainObject(value) {\n if (!value || !isObjectish(value))\n return false;\n const proto = getPrototypeOf(value);\n if (proto === null || proto === O[PROTOTYPE])\n return true;\n const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR];\n if (Ctor === Object)\n return true;\n if (!isFunction(Ctor))\n return false;\n let ctorString = cachedCtorStrings.get(Ctor);\n if (ctorString === void 0) {\n ctorString = Function.toString.call(Ctor);\n cachedCtorStrings.set(Ctor, ctorString);\n }\n return ctorString === objectCtorString;\n}\nfunction original(value) {\n if (!isDraft(value))\n die(15, value);\n return value[DRAFT_STATE].base_;\n}\nfunction each(obj, iter, strict = true) {\n if (getArchtype(obj) === 0 /* Object */) {\n const keys = strict ? Reflect.ownKeys(obj) : O.keys(obj);\n keys.forEach((key) => {\n iter(key, obj[key], obj);\n });\n } else {\n obj.forEach((entry, index) => iter(index, entry, obj));\n }\n}\nfunction getArchtype(thing) {\n const state = thing[DRAFT_STATE];\n return state ? state.type_ : isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;\n}\nvar has = (thing, prop, type = getArchtype(thing)) => type === 2 /* Map */ ? thing.has(prop) : O[PROTOTYPE].hasOwnProperty.call(thing, prop);\nvar get = (thing, prop, type = getArchtype(thing)) => (\n // @ts-ignore\n type === 2 /* Map */ ? thing.get(prop) : thing[prop]\n);\nvar set = (thing, propOrOldValue, value, type = getArchtype(thing)) => {\n if (type === 2 /* Map */)\n thing.set(propOrOldValue, value);\n else if (type === 3 /* Set */) {\n thing.add(value);\n } else\n thing[propOrOldValue] = value;\n};\nfunction is(x, y) {\n if (x === y) {\n return x !== 0 || 1 / x === 1 / y;\n } else {\n return x !== x && y !== y;\n }\n}\nvar isArray = Array.isArray;\nvar isMap = (target) => target instanceof Map;\nvar isSet = (target) => target instanceof Set;\nvar isObjectish = (target) => typeof target === \"object\";\nvar isFunction = (target) => typeof target === \"function\";\nvar isBoolean = (target) => typeof target === \"boolean\";\nfunction isArrayIndex(value) {\n const n = +value;\n return Number.isInteger(n) && String(n) === value;\n}\nvar getProxyDraft = (value) => {\n if (!isObjectish(value))\n return null;\n return value?.[DRAFT_STATE];\n};\nvar latest = (state) => state.copy_ || state.base_;\nvar getValue = (value) => {\n const proxyDraft = getProxyDraft(value);\n return proxyDraft ? proxyDraft.copy_ ?? proxyDraft.base_ : value;\n};\nvar getFinalValue = (state) => state.modified_ ? state.copy_ : state.base_;\nfunction shallowCopy(base, strict) {\n if (isMap(base)) {\n return new Map(base);\n }\n if (isSet(base)) {\n return new Set(base);\n }\n if (isArray(base))\n return Array[PROTOTYPE].slice.call(base);\n const isPlain = isPlainObject(base);\n if (strict === true || strict === \"class_only\" && !isPlain) {\n const descriptors = O.getOwnPropertyDescriptors(base);\n delete descriptors[DRAFT_STATE];\n let keys = Reflect.ownKeys(descriptors);\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const desc = descriptors[key];\n if (desc[WRITABLE] === false) {\n desc[WRITABLE] = true;\n desc[CONFIGURABLE] = true;\n }\n if (desc.get || desc.set)\n descriptors[key] = {\n [CONFIGURABLE]: true,\n [WRITABLE]: true,\n // could live with !!desc.set as well here...\n [ENUMERABLE]: desc[ENUMERABLE],\n [VALUE]: base[key]\n };\n }\n return O.create(getPrototypeOf(base), descriptors);\n } else {\n const proto = getPrototypeOf(base);\n if (proto !== null && isPlain) {\n return { ...base };\n }\n const obj = O.create(proto);\n return O.assign(obj, base);\n }\n}\nfunction freeze(obj, deep = false) {\n if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))\n return obj;\n if (getArchtype(obj) > 1) {\n O.defineProperties(obj, {\n set: dontMutateMethodOverride,\n add: dontMutateMethodOverride,\n clear: dontMutateMethodOverride,\n delete: dontMutateMethodOverride\n });\n }\n O.freeze(obj);\n if (deep)\n each(\n obj,\n (_key, value) => {\n freeze(value, true);\n },\n false\n );\n return obj;\n}\nfunction dontMutateFrozenCollections() {\n die(2);\n}\nvar dontMutateMethodOverride = {\n [VALUE]: dontMutateFrozenCollections\n};\nfunction isFrozen(obj) {\n if (obj === null || !isObjectish(obj))\n return true;\n return O.isFrozen(obj);\n}\n\n// src/utils/plugins.ts\nvar PluginMapSet = \"MapSet\";\nvar PluginPatches = \"Patches\";\nvar PluginArrayMethods = \"ArrayMethods\";\nvar plugins = {};\nfunction getPlugin(pluginKey) {\n const plugin = plugins[pluginKey];\n if (!plugin) {\n die(0, pluginKey);\n }\n return plugin;\n}\nvar isPluginLoaded = (pluginKey) => !!plugins[pluginKey];\nfunction loadPlugin(pluginKey, implementation) {\n if (!plugins[pluginKey])\n plugins[pluginKey] = implementation;\n}\n\n// src/core/scope.ts\nvar currentScope;\nvar getCurrentScope = () => currentScope;\nvar createScope = (parent_, immer_) => ({\n drafts_: [],\n parent_,\n immer_,\n // Whenever the modified draft contains a draft from another scope, we\n // need to prevent auto-freezing so the unowned draft can be finalized.\n canAutoFreeze_: true,\n unfinalizedDrafts_: 0,\n handledSet_: /* @__PURE__ */ new Set(),\n processedForPatches_: /* @__PURE__ */ new Set(),\n mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0,\n arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) ? getPlugin(PluginArrayMethods) : void 0\n});\nfunction usePatchesInScope(scope, patchListener) {\n if (patchListener) {\n scope.patchPlugin_ = getPlugin(PluginPatches);\n scope.patches_ = [];\n scope.inversePatches_ = [];\n scope.patchListener_ = patchListener;\n }\n}\nfunction revokeScope(scope) {\n leaveScope(scope);\n scope.drafts_.forEach(revokeDraft);\n scope.drafts_ = null;\n}\nfunction leaveScope(scope) {\n if (scope === currentScope) {\n currentScope = scope.parent_;\n }\n}\nvar enterScope = (immer2) => currentScope = createScope(currentScope, immer2);\nfunction revokeDraft(draft) {\n const state = draft[DRAFT_STATE];\n if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)\n state.revoke_();\n else\n state.revoked_ = true;\n}\n\n// src/core/finalize.ts\nfunction processResult(result, scope) {\n scope.unfinalizedDrafts_ = scope.drafts_.length;\n const baseDraft = scope.drafts_[0];\n const isReplaced = result !== void 0 && result !== baseDraft;\n if (isReplaced) {\n if (baseDraft[DRAFT_STATE].modified_) {\n revokeScope(scope);\n die(4);\n }\n if (isDraftable(result)) {\n result = finalize(scope, result);\n }\n const { patchPlugin_ } = scope;\n if (patchPlugin_) {\n patchPlugin_.generateReplacementPatches_(\n baseDraft[DRAFT_STATE].base_,\n result,\n scope\n );\n }\n } else {\n result = finalize(scope, baseDraft);\n }\n maybeFreeze(scope, result, true);\n revokeScope(scope);\n if (scope.patches_) {\n scope.patchListener_(scope.patches_, scope.inversePatches_);\n }\n return result !== NOTHING ? result : void 0;\n}\nfunction finalize(rootScope, value) {\n if (isFrozen(value))\n return value;\n const state = value[DRAFT_STATE];\n if (!state) {\n const finalValue = handleValue(value, rootScope.handledSet_, rootScope);\n return finalValue;\n }\n if (!isSameScope(state, rootScope)) {\n return value;\n }\n if (!state.modified_) {\n return state.base_;\n }\n if (!state.finalized_) {\n const { callbacks_ } = state;\n if (callbacks_) {\n while (callbacks_.length > 0) {\n const callback = callbacks_.pop();\n callback(rootScope);\n }\n }\n generatePatchesAndFinalize(state, rootScope);\n }\n return state.copy_;\n}\nfunction maybeFreeze(scope, value, deep = false) {\n if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {\n freeze(value, deep);\n }\n}\nfunction markStateFinalized(state) {\n state.finalized_ = true;\n state.scope_.unfinalizedDrafts_--;\n}\nvar isSameScope = (state, rootScope) => state.scope_ === rootScope;\nvar EMPTY_LOCATIONS_RESULT = [];\nfunction updateDraftInParent(parent, draftValue, finalizedValue, originalKey) {\n const parentCopy = latest(parent);\n const parentType = parent.type_;\n if (originalKey !== void 0) {\n const currentValue = get(parentCopy, originalKey, parentType);\n if (currentValue === draftValue) {\n set(parentCopy, originalKey, finalizedValue, parentType);\n return;\n }\n }\n if (!parent.draftLocations_) {\n const draftLocations = parent.draftLocations_ = /* @__PURE__ */ new Map();\n each(parentCopy, (key, value) => {\n if (isDraft(value)) {\n const keys = draftLocations.get(value) || [];\n keys.push(key);\n draftLocations.set(value, keys);\n }\n });\n }\n const locations = parent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT;\n for (const location of locations) {\n set(parentCopy, location, finalizedValue, parentType);\n }\n}\nfunction registerChildFinalizationCallback(parent, child, key) {\n parent.callbacks_.push(function childCleanup(rootScope) {\n const state = child;\n if (!state || !isSameScope(state, rootScope)) {\n return;\n }\n rootScope.mapSetPlugin_?.fixSetContents(state);\n const finalizedValue = getFinalValue(state);\n updateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key);\n generatePatchesAndFinalize(state, rootScope);\n });\n}\nfunction generatePatchesAndFinalize(state, rootScope) {\n const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 /* Set */ || state.type_ === 1 /* Array */ && state.allIndicesReassigned_ || (state.assigned_?.size ?? 0) > 0);\n if (shouldFinalize) {\n const { patchPlugin_ } = rootScope;\n if (patchPlugin_) {\n const basePath = patchPlugin_.getPath(state);\n if (basePath) {\n patchPlugin_.generatePatches_(state, basePath, rootScope);\n }\n }\n markStateFinalized(state);\n }\n}\nfunction handleCrossReference(target, key, value) {\n const { scope_ } = target;\n if (isDraft(value)) {\n const state = value[DRAFT_STATE];\n if (isSameScope(state, scope_)) {\n state.callbacks_.push(function crossReferenceCleanup() {\n prepareCopy(target);\n const finalizedValue = getFinalValue(state);\n updateDraftInParent(target, value, finalizedValue, key);\n });\n }\n } else if (isDraftable(value)) {\n target.callbacks_.push(function nestedDraftCleanup() {\n const targetCopy = latest(target);\n if (target.type_ === 3 /* Set */) {\n if (targetCopy.has(value)) {\n handleValue(value, scope_.handledSet_, scope_);\n }\n } else {\n if (get(targetCopy, key, target.type_) === value) {\n if (scope_.drafts_.length > 1 && (target.assigned_.get(key) ?? false) === true && target.copy_) {\n handleValue(\n get(target.copy_, key, target.type_),\n scope_.handledSet_,\n scope_\n );\n }\n }\n }\n });\n }\n}\nfunction handleValue(target, handledSet, rootScope) {\n if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {\n return target;\n }\n if (isDraft(target) || handledSet.has(target) || !isDraftable(target) || isFrozen(target)) {\n return target;\n }\n handledSet.add(target);\n each(target, (key, value) => {\n if (isDraft(value)) {\n const state = value[DRAFT_STATE];\n if (isSameScope(state, rootScope)) {\n const updatedValue = getFinalValue(state);\n set(target, key, updatedValue, target.type_);\n markStateFinalized(state);\n }\n } else if (isDraftable(value)) {\n handleValue(value, handledSet, rootScope);\n }\n });\n return target;\n}\n\n// src/core/proxy.ts\nfunction createProxyProxy(base, parent) {\n const baseIsArray = isArray(base);\n const state = {\n type_: baseIsArray ? 1 /* Array */ : 0 /* Object */,\n // Track which produce call this is associated with.\n scope_: parent ? parent.scope_ : getCurrentScope(),\n // True for both shallow and deep changes.\n modified_: false,\n // Used during finalization.\n finalized_: false,\n // Track which properties have been assigned (true) or deleted (false).\n // actually instantiated in `prepareCopy()`\n assigned_: void 0,\n // The parent draft state.\n parent_: parent,\n // The base state.\n base_: base,\n // The base proxy.\n draft_: null,\n // set below\n // The base copy with any updated values.\n copy_: null,\n // Called by the `produce` function.\n revoke_: null,\n isManual_: false,\n // `callbacks` actually gets assigned in `createProxy`\n callbacks_: void 0\n };\n let target = state;\n let traps = objectTraps;\n if (baseIsArray) {\n target = [state];\n traps = arrayTraps;\n }\n const { revoke, proxy } = Proxy.revocable(target, traps);\n state.draft_ = proxy;\n state.revoke_ = revoke;\n return [proxy, state];\n}\nvar objectTraps = {\n get(state, prop) {\n if (prop === DRAFT_STATE)\n return state;\n let arrayPlugin = state.scope_.arrayMethodsPlugin_;\n const isArrayWithStringProp = state.type_ === 1 /* Array */ && typeof prop === \"string\";\n if (isArrayWithStringProp) {\n if (arrayPlugin?.isArrayOperationMethod(prop)) {\n return arrayPlugin.createMethodInterceptor(state, prop);\n }\n }\n const source = latest(state);\n if (!has(source, prop, state.type_)) {\n return readPropFromProto(state, source, prop);\n }\n const value = source[prop];\n if (state.finalized_ || !isDraftable(value)) {\n return value;\n }\n if (isArrayWithStringProp && state.operationMethod && arrayPlugin?.isMutatingArrayMethod(\n state.operationMethod\n ) && isArrayIndex(prop)) {\n return value;\n }\n if (value === peek(state.base_, prop)) {\n prepareCopy(state);\n const childKey = state.type_ === 1 /* Array */ ? +prop : prop;\n const childDraft = createProxy(state.scope_, value, state, childKey);\n return state.copy_[childKey] = childDraft;\n }\n return value;\n },\n has(state, prop) {\n return prop in latest(state);\n },\n ownKeys(state) {\n return Reflect.ownKeys(latest(state));\n },\n set(state, prop, value) {\n const desc = getDescriptorFromProto(latest(state), prop);\n if (desc?.set) {\n desc.set.call(state.draft_, value);\n return true;\n }\n if (!state.modified_) {\n const current2 = peek(latest(state), prop);\n const currentState = current2?.[DRAFT_STATE];\n if (currentState && currentState.base_ === value) {\n state.copy_[prop] = value;\n state.assigned_.set(prop, false);\n return true;\n }\n if (is(value, current2) && (value !== void 0 || has(state.base_, prop, state.type_)))\n return true;\n prepareCopy(state);\n markChanged(state);\n }\n if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'\n (value !== void 0 || prop in state.copy_) || // special case: NaN\n Number.isNaN(value) && Number.isNaN(state.copy_[prop]))\n return true;\n state.copy_[prop] = value;\n state.assigned_.set(prop, true);\n handleCrossReference(state, prop, value);\n return true;\n },\n deleteProperty(state, prop) {\n prepareCopy(state);\n if (peek(state.base_, prop) !== void 0 || prop in state.base_) {\n state.assigned_.set(prop, false);\n markChanged(state);\n } else {\n state.assigned_.delete(prop);\n }\n if (state.copy_) {\n delete state.copy_[prop];\n }\n return true;\n },\n // Note: We never coerce `desc.value` into an Immer draft, because we can't make\n // the same guarantee in ES5 mode.\n getOwnPropertyDescriptor(state, prop) {\n const owner = latest(state);\n const desc = Reflect.getOwnPropertyDescriptor(owner, prop);\n if (!desc)\n return desc;\n return {\n [WRITABLE]: true,\n [CONFIGURABLE]: state.type_ !== 1 /* Array */ || prop !== \"length\",\n [ENUMERABLE]: desc[ENUMERABLE],\n [VALUE]: owner[prop]\n };\n },\n defineProperty() {\n die(11);\n },\n getPrototypeOf(state) {\n return getPrototypeOf(state.base_);\n },\n setPrototypeOf() {\n die(12);\n }\n};\nvar arrayTraps = {};\nfor (let key in objectTraps) {\n let fn = objectTraps[key];\n arrayTraps[key] = function() {\n const args = arguments;\n args[0] = args[0][0];\n return fn.apply(this, args);\n };\n}\narrayTraps.deleteProperty = function(state, prop) {\n if (process.env.NODE_ENV !== \"production\" && isNaN(parseInt(prop)))\n die(13);\n return arrayTraps.set.call(this, state, prop, void 0);\n};\narrayTraps.set = function(state, prop, value) {\n if (process.env.NODE_ENV !== \"production\" && prop !== \"length\" && isNaN(parseInt(prop)))\n die(14);\n return objectTraps.set.call(this, state[0], prop, value, state[0]);\n};\nfunction peek(draft, prop) {\n const state = draft[DRAFT_STATE];\n const source = state ? latest(state) : draft;\n return source[prop];\n}\nfunction readPropFromProto(state, source, prop) {\n const desc = getDescriptorFromProto(source, prop);\n return desc ? VALUE in desc ? desc[VALUE] : (\n // This is a very special case, if the prop is a getter defined by the\n // prototype, we should invoke it with the draft as context!\n desc.get?.call(state.draft_)\n ) : void 0;\n}\nfunction getDescriptorFromProto(source, prop) {\n if (!(prop in source))\n return void 0;\n let proto = getPrototypeOf(source);\n while (proto) {\n const desc = Object.getOwnPropertyDescriptor(proto, prop);\n if (desc)\n return desc;\n proto = getPrototypeOf(proto);\n }\n return void 0;\n}\nfunction markChanged(state) {\n if (!state.modified_) {\n state.modified_ = true;\n if (state.parent_) {\n markChanged(state.parent_);\n }\n }\n}\nfunction prepareCopy(state) {\n if (!state.copy_) {\n state.assigned_ = /* @__PURE__ */ new Map();\n state.copy_ = shallowCopy(\n state.base_,\n state.scope_.immer_.useStrictShallowCopy_\n );\n }\n}\n\n// src/core/immerClass.ts\nvar Immer2 = class {\n constructor(config) {\n this.autoFreeze_ = true;\n this.useStrictShallowCopy_ = false;\n this.useStrictIteration_ = false;\n /**\n * The `produce` function takes a value and a \"recipe function\" (whose\n * return value often depends on the base state). The recipe function is\n * free to mutate its first argument however it wants. All mutations are\n * only ever applied to a __copy__ of the base state.\n *\n * Pass only a function to create a \"curried producer\" which relieves you\n * from passing the recipe function every time.\n *\n * Only plain objects and arrays are made mutable. All other objects are\n * considered uncopyable.\n *\n * Note: This function is __bound__ to its `Immer` instance.\n *\n * @param {any} base - the initial state\n * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified\n * @param {Function} patchListener - optional function that will be called with all the patches produced here\n * @returns {any} a new state, or the initial state if nothing was modified\n */\n this.produce = (base, recipe, patchListener) => {\n if (isFunction(base) && !isFunction(recipe)) {\n const defaultBase = recipe;\n recipe = base;\n const self = this;\n return function curriedProduce(base2 = defaultBase, ...args) {\n return self.produce(base2, (draft) => recipe.call(this, draft, ...args));\n };\n }\n if (!isFunction(recipe))\n die(6);\n if (patchListener !== void 0 && !isFunction(patchListener))\n die(7);\n let result;\n if (isDraftable(base)) {\n const scope = enterScope(this);\n const proxy = createProxy(scope, base, void 0);\n let hasError = true;\n try {\n result = recipe(proxy);\n hasError = false;\n } finally {\n if (hasError)\n revokeScope(scope);\n else\n leaveScope(scope);\n }\n usePatchesInScope(scope, patchListener);\n return processResult(result, scope);\n } else if (!base || !isObjectish(base)) {\n result = recipe(base);\n if (result === void 0)\n result = base;\n if (result === NOTHING)\n result = void 0;\n if (this.autoFreeze_)\n freeze(result, true);\n if (patchListener) {\n const p = [];\n const ip = [];\n getPlugin(PluginPatches).generateReplacementPatches_(base, result, {\n patches_: p,\n inversePatches_: ip\n });\n patchListener(p, ip);\n }\n return result;\n } else\n die(1, base);\n };\n this.produceWithPatches = (base, recipe) => {\n if (isFunction(base)) {\n return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));\n }\n let patches, inversePatches;\n const result = this.produce(base, recipe, (p, ip) => {\n patches = p;\n inversePatches = ip;\n });\n return [result, patches, inversePatches];\n };\n if (isBoolean(config?.autoFreeze))\n this.setAutoFreeze(config.autoFreeze);\n if (isBoolean(config?.useStrictShallowCopy))\n this.setUseStrictShallowCopy(config.useStrictShallowCopy);\n if (isBoolean(config?.useStrictIteration))\n this.setUseStrictIteration(config.useStrictIteration);\n }\n createDraft(base) {\n if (!isDraftable(base))\n die(8);\n if (isDraft(base))\n base = current(base);\n const scope = enterScope(this);\n const proxy = createProxy(scope, base, void 0);\n proxy[DRAFT_STATE].isManual_ = true;\n leaveScope(scope);\n return proxy;\n }\n finishDraft(draft, patchListener) {\n const state = draft && draft[DRAFT_STATE];\n if (!state || !state.isManual_)\n die(9);\n const { scope_: scope } = state;\n usePatchesInScope(scope, patchListener);\n return processResult(void 0, scope);\n }\n /**\n * Pass true to automatically freeze all copies created by Immer.\n *\n * By default, auto-freezing is enabled.\n */\n setAutoFreeze(value) {\n this.autoFreeze_ = value;\n }\n /**\n * Pass true to enable strict shallow copy.\n *\n * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n */\n setUseStrictShallowCopy(value) {\n this.useStrictShallowCopy_ = value;\n }\n /**\n * Pass false to use faster iteration that skips non-enumerable properties\n * but still handles symbols for compatibility.\n *\n * By default, strict iteration is enabled (includes all own properties).\n */\n setUseStrictIteration(value) {\n this.useStrictIteration_ = value;\n }\n shouldUseStrictIteration() {\n return this.useStrictIteration_;\n }\n applyPatches(base, patches) {\n let i;\n for (i = patches.length - 1; i >= 0; i--) {\n const patch = patches[i];\n if (patch.path.length === 0 && patch.op === \"replace\") {\n base = patch.value;\n break;\n }\n }\n if (i > -1) {\n patches = patches.slice(i + 1);\n }\n const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_;\n if (isDraft(base)) {\n return applyPatchesImpl(base, patches);\n }\n return this.produce(\n base,\n (draft) => applyPatchesImpl(draft, patches)\n );\n }\n};\nfunction createProxy(rootScope, value, parent, key) {\n const [draft, state] = isMap(value) ? getPlugin(PluginMapSet).proxyMap_(value, parent) : isSet(value) ? getPlugin(PluginMapSet).proxySet_(value, parent) : createProxyProxy(value, parent);\n const scope = parent?.scope_ ?? getCurrentScope();\n scope.drafts_.push(draft);\n state.callbacks_ = parent?.callbacks_ ?? [];\n state.key_ = key;\n if (parent && key !== void 0) {\n registerChildFinalizationCallback(parent, state, key);\n } else {\n state.callbacks_.push(function rootDraftCleanup(rootScope2) {\n rootScope2.mapSetPlugin_?.fixSetContents(state);\n const { patchPlugin_ } = rootScope2;\n if (state.modified_ && patchPlugin_) {\n patchPlugin_.generatePatches_(state, [], rootScope2);\n }\n });\n }\n return draft;\n}\n\n// src/core/current.ts\nfunction current(value) {\n if (!isDraft(value))\n die(10, value);\n return currentImpl(value);\n}\nfunction currentImpl(value) {\n if (!isDraftable(value) || isFrozen(value))\n return value;\n const state = value[DRAFT_STATE];\n let copy;\n let strict = true;\n if (state) {\n if (!state.modified_)\n return state.base_;\n state.finalized_ = true;\n copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);\n strict = state.scope_.immer_.shouldUseStrictIteration();\n } else {\n copy = shallowCopy(value, true);\n }\n each(\n copy,\n (key, childValue) => {\n set(copy, key, currentImpl(childValue));\n },\n strict\n );\n if (state) {\n state.finalized_ = false;\n }\n return copy;\n}\n\n// src/plugins/patches.ts\nfunction enablePatches() {\n const errorOffset = 16;\n if (process.env.NODE_ENV !== \"production\") {\n errors.push(\n 'Sets cannot have \"replace\" patches.',\n function(op) {\n return \"Unsupported patch operation: \" + op;\n },\n function(path) {\n return \"Cannot apply patch, path doesn't resolve: \" + path;\n },\n \"Patching reserved attributes like __proto__, prototype and constructor is not allowed\"\n );\n }\n function getPath(state, path = []) {\n if (state.key_ !== void 0) {\n const parentCopy = state.parent_.copy_ ?? state.parent_.base_;\n const proxyDraft = getProxyDraft(get(parentCopy, state.key_));\n const valueAtKey = get(parentCopy, state.key_);\n if (valueAtKey === void 0) {\n return null;\n }\n if (valueAtKey !== state.draft_ && valueAtKey !== state.base_ && valueAtKey !== state.copy_) {\n return null;\n }\n if (proxyDraft != null && proxyDraft.base_ !== state.base_) {\n return null;\n }\n const isSet2 = state.parent_.type_ === 3 /* Set */;\n let key;\n if (isSet2) {\n const setParent = state.parent_;\n key = Array.from(setParent.drafts_.keys()).indexOf(state.key_);\n } else {\n key = state.key_;\n }\n if (!(isSet2 && parentCopy.size > key || has(parentCopy, key))) {\n return null;\n }\n path.push(key);\n }\n if (state.parent_) {\n return getPath(state.parent_, path);\n }\n path.reverse();\n try {\n resolvePath(state.copy_, path);\n } catch (e) {\n return null;\n }\n return path;\n }\n function resolvePath(base, path) {\n let current2 = base;\n for (let i = 0; i < path.length - 1; i++) {\n const key = path[i];\n current2 = get(current2, key);\n if (!isObjectish(current2) || current2 === null) {\n throw new Error(`Cannot resolve path at '${path.join(\"/\")}'`);\n }\n }\n return current2;\n }\n const REPLACE = \"replace\";\n const ADD = \"add\";\n const REMOVE = \"remove\";\n function generatePatches_(state, basePath, scope) {\n if (state.scope_.processedForPatches_.has(state)) {\n return;\n }\n state.scope_.processedForPatches_.add(state);\n const { patches_, inversePatches_ } = scope;\n switch (state.type_) {\n case 0 /* Object */:\n case 2 /* Map */:\n return generatePatchesFromAssigned(\n state,\n basePath,\n patches_,\n inversePatches_\n );\n case 1 /* Array */:\n return generateArrayPatches(\n state,\n basePath,\n patches_,\n inversePatches_\n );\n case 3 /* Set */:\n return generateSetPatches(\n state,\n basePath,\n patches_,\n inversePatches_\n );\n }\n }\n function generateArrayPatches(state, basePath, patches, inversePatches) {\n let { base_, assigned_ } = state;\n let copy_ = state.copy_;\n if (copy_.length < base_.length) {\n ;\n [base_, copy_] = [copy_, base_];\n [patches, inversePatches] = [inversePatches, patches];\n }\n const allReassigned = state.allIndicesReassigned_ === true;\n for (let i = 0; i < base_.length; i++) {\n const copiedItem = copy_[i];\n const baseItem = base_[i];\n const isAssigned = allReassigned || assigned_?.get(i.toString());\n if (isAssigned && copiedItem !== baseItem) {\n const childState = copiedItem?.[DRAFT_STATE];\n if (childState && childState.modified_) {\n continue;\n }\n const path = basePath.concat([i]);\n patches.push({\n op: REPLACE,\n path,\n // Need to maybe clone it, as it can in fact be the original value\n // due to the base/copy inversion at the start of this function\n value: clonePatchValueIfNeeded(copiedItem)\n });\n inversePatches.push({\n op: REPLACE,\n path,\n value: clonePatchValueIfNeeded(baseItem)\n });\n }\n }\n for (let i = base_.length; i < copy_.length; i++) {\n const path = basePath.concat([i]);\n patches.push({\n op: ADD,\n path,\n // Need to maybe clone it, as it can in fact be the original value\n // due to the base/copy inversion at the start of this function\n value: clonePatchValueIfNeeded(copy_[i])\n });\n }\n for (let i = copy_.length - 1; base_.length <= i; --i) {\n const path = basePath.concat([i]);\n inversePatches.push({\n op: REMOVE,\n path\n });\n }\n }\n function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {\n const { base_, copy_, type_ } = state;\n each(state.assigned_, (key, assignedValue) => {\n const origValue = get(base_, key, type_);\n const value = get(copy_, key, type_);\n const op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD;\n if (origValue === value && op === REPLACE)\n return;\n const path = basePath.concat(key);\n patches.push(\n op === REMOVE ? { op, path } : { op, path, value: clonePatchValueIfNeeded(value) }\n );\n inversePatches.push(\n op === ADD ? { op: REMOVE, path } : op === REMOVE ? { op: ADD, path, value: clonePatchValueIfNeeded(origValue) } : { op: REPLACE, path, value: clonePatchValueIfNeeded(origValue) }\n );\n });\n }\n function generateSetPatches(state, basePath, patches, inversePatches) {\n let { base_, copy_ } = state;\n let i = 0;\n base_.forEach((value) => {\n if (!copy_.has(value)) {\n const path = basePath.concat([i]);\n patches.push({\n op: REMOVE,\n path,\n value\n });\n inversePatches.unshift({\n op: ADD,\n path,\n value\n });\n }\n i++;\n });\n i = 0;\n copy_.forEach((value) => {\n if (!base_.has(value)) {\n const path = basePath.concat([i]);\n patches.push({\n op: ADD,\n path,\n value\n });\n inversePatches.unshift({\n op: REMOVE,\n path,\n value\n });\n }\n i++;\n });\n }\n function generateReplacementPatches_(baseValue, replacement, scope) {\n const { patches_, inversePatches_ } = scope;\n patches_.push({\n op: REPLACE,\n path: [],\n value: replacement === NOTHING ? void 0 : replacement\n });\n inversePatches_.push({\n op: REPLACE,\n path: [],\n value: baseValue\n });\n }\n function applyPatches_(draft, patches) {\n patches.forEach((patch) => {\n const { path, op } = patch;\n let base = draft;\n for (let i = 0; i < path.length - 1; i++) {\n const parentType = getArchtype(base);\n let p = path[i];\n if (typeof p !== \"string\" && typeof p !== \"number\") {\n p = \"\" + p;\n }\n if ((parentType === 0 /* Object */ || parentType === 1 /* Array */) && (p === \"__proto__\" || p === CONSTRUCTOR))\n die(errorOffset + 3);\n if (isFunction(base) && p === PROTOTYPE)\n die(errorOffset + 3);\n base = get(base, p);\n if (!isObjectish(base))\n die(errorOffset + 2, path.join(\"/\"));\n }\n const type = getArchtype(base);\n const value = deepClonePatchValue(patch.value);\n const key = path[path.length - 1];\n switch (op) {\n case REPLACE:\n switch (type) {\n case 2 /* Map */:\n return base.set(key, value);\n case 3 /* Set */:\n die(errorOffset);\n default:\n return base[key] = value;\n }\n case ADD:\n switch (type) {\n case 1 /* Array */:\n return key === \"-\" ? base.push(value) : base.splice(key, 0, value);\n case 2 /* Map */:\n return base.set(key, value);\n case 3 /* Set */:\n return base.add(value);\n default:\n return base[key] = value;\n }\n case REMOVE:\n switch (type) {\n case 1 /* Array */:\n return base.splice(key, 1);\n case 2 /* Map */:\n return base.delete(key);\n case 3 /* Set */:\n return base.delete(patch.value);\n default:\n return delete base[key];\n }\n default:\n die(errorOffset + 1, op);\n }\n });\n return draft;\n }\n function deepClonePatchValue(obj) {\n if (!isDraftable(obj))\n return obj;\n if (isArray(obj))\n return obj.map(deepClonePatchValue);\n if (isMap(obj))\n return new Map(\n Array.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)])\n );\n if (isSet(obj))\n return new Set(Array.from(obj).map(deepClonePatchValue));\n const cloned = Object.create(getPrototypeOf(obj));\n for (const key in obj)\n cloned[key] = deepClonePatchValue(obj[key]);\n if (has(obj, DRAFTABLE))\n cloned[DRAFTABLE] = obj[DRAFTABLE];\n return cloned;\n }\n function clonePatchValueIfNeeded(obj) {\n if (isDraft(obj)) {\n return deepClonePatchValue(obj);\n } else\n return obj;\n }\n loadPlugin(PluginPatches, {\n applyPatches_,\n generatePatches_,\n generateReplacementPatches_,\n getPath\n });\n}\n\n// src/plugins/mapset.ts\nfunction enableMapSet() {\n class DraftMap extends Map {\n constructor(target, parent) {\n super();\n this[DRAFT_STATE] = {\n type_: 2 /* Map */,\n parent_: parent,\n scope_: parent ? parent.scope_ : getCurrentScope(),\n modified_: false,\n finalized_: false,\n copy_: void 0,\n assigned_: void 0,\n base_: target,\n draft_: this,\n isManual_: false,\n revoked_: false,\n callbacks_: []\n };\n }\n get size() {\n return latest(this[DRAFT_STATE]).size;\n }\n has(key) {\n return latest(this[DRAFT_STATE]).has(key);\n }\n set(key, value) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (!latest(state).has(key) || latest(state).get(key) !== value) {\n prepareMapCopy(state);\n markChanged(state);\n state.assigned_.set(key, true);\n state.copy_.set(key, value);\n state.assigned_.set(key, true);\n handleCrossReference(state, key, value);\n }\n return this;\n }\n delete(key) {\n if (!this.has(key)) {\n return false;\n }\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareMapCopy(state);\n markChanged(state);\n if (state.base_.has(key)) {\n state.assigned_.set(key, false);\n } else {\n state.assigned_.delete(key);\n }\n state.copy_.delete(key);\n return true;\n }\n clear() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (latest(state).size) {\n prepareMapCopy(state);\n markChanged(state);\n state.assigned_ = /* @__PURE__ */ new Map();\n each(state.base_, (key) => {\n state.assigned_.set(key, false);\n });\n state.copy_.clear();\n }\n }\n forEach(cb, thisArg) {\n const state = this[DRAFT_STATE];\n latest(state).forEach((_value, key, _map) => {\n cb.call(thisArg, this.get(key), key, this);\n });\n }\n get(key) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n const value = latest(state).get(key);\n if (state.finalized_ || !isDraftable(value)) {\n return value;\n }\n if (value !== state.base_.get(key)) {\n return value;\n }\n const draft = createProxy(state.scope_, value, state, key);\n prepareMapCopy(state);\n state.copy_.set(key, draft);\n return draft;\n }\n keys() {\n return latest(this[DRAFT_STATE]).keys();\n }\n values() {\n const iterator = this.keys();\n return {\n [Symbol.iterator]: () => this.values(),\n next: () => {\n const r = iterator.next();\n if (r.done)\n return r;\n const value = this.get(r.value);\n return {\n done: false,\n value\n };\n }\n };\n }\n entries() {\n const iterator = this.keys();\n return {\n [Symbol.iterator]: () => this.entries(),\n next: () => {\n const r = iterator.next();\n if (r.done)\n return r;\n const value = this.get(r.value);\n return {\n done: false,\n value: [r.value, value]\n };\n }\n };\n }\n [(DRAFT_STATE, Symbol.iterator)]() {\n return this.entries();\n }\n }\n function proxyMap_(target, parent) {\n const map = new DraftMap(target, parent);\n return [map, map[DRAFT_STATE]];\n }\n function prepareMapCopy(state) {\n if (!state.copy_) {\n state.assigned_ = /* @__PURE__ */ new Map();\n state.copy_ = new Map(state.base_);\n }\n }\n class DraftSet extends Set {\n constructor(target, parent) {\n super();\n this[DRAFT_STATE] = {\n type_: 3 /* Set */,\n parent_: parent,\n scope_: parent ? parent.scope_ : getCurrentScope(),\n modified_: false,\n finalized_: false,\n copy_: void 0,\n base_: target,\n draft_: this,\n drafts_: /* @__PURE__ */ new Map(),\n revoked_: false,\n isManual_: false,\n assigned_: void 0,\n callbacks_: []\n };\n }\n get size() {\n return latest(this[DRAFT_STATE]).size;\n }\n has(value) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (!state.copy_) {\n return state.base_.has(value);\n }\n if (state.copy_.has(value))\n return true;\n if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))\n return true;\n return false;\n }\n add(value) {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (!this.has(value)) {\n prepareSetCopy(state);\n markChanged(state);\n state.copy_.add(value);\n handleCrossReference(state, value, value);\n }\n return this;\n }\n delete(value) {\n if (!this.has(value)) {\n return false;\n }\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareSetCopy(state);\n markChanged(state);\n return state.copy_.delete(value) || (state.drafts_.has(value) ? state.copy_.delete(state.drafts_.get(value)) : (\n /* istanbul ignore next */\n false\n ));\n }\n clear() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n if (latest(state).size) {\n prepareSetCopy(state);\n markChanged(state);\n state.copy_.clear();\n }\n }\n values() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareSetCopy(state);\n return state.copy_.values();\n }\n entries() {\n const state = this[DRAFT_STATE];\n assertUnrevoked(state);\n prepareSetCopy(state);\n return state.copy_.entries();\n }\n keys() {\n return this.values();\n }\n [(DRAFT_STATE, Symbol.iterator)]() {\n return this.values();\n }\n forEach(cb, thisArg) {\n const iterator = this.values();\n let result = iterator.next();\n while (!result.done) {\n cb.call(thisArg, result.value, result.value, this);\n result = iterator.next();\n }\n }\n }\n function proxySet_(target, parent) {\n const set2 = new DraftSet(target, parent);\n return [set2, set2[DRAFT_STATE]];\n }\n function prepareSetCopy(state) {\n if (!state.copy_) {\n state.copy_ = /* @__PURE__ */ new Set();\n state.base_.forEach((value) => {\n if (isDraftable(value)) {\n const draft = createProxy(state.scope_, value, state, value);\n state.drafts_.set(value, draft);\n state.copy_.add(draft);\n } else {\n state.copy_.add(value);\n }\n });\n }\n }\n function assertUnrevoked(state) {\n if (state.revoked_)\n die(3, JSON.stringify(latest(state)));\n }\n function fixSetContents(target) {\n if (target.type_ === 3 /* Set */ && target.copy_) {\n const copy = new Set(target.copy_);\n target.copy_.clear();\n copy.forEach((value) => {\n target.copy_.add(getValue(value));\n });\n }\n }\n loadPlugin(PluginMapSet, { proxyMap_, proxySet_, fixSetContents });\n}\n\n// src/plugins/arrayMethods.ts\nfunction enableArrayMethods() {\n const SHIFTING_METHODS = /* @__PURE__ */ new Set([\"shift\", \"unshift\"]);\n const QUEUE_METHODS = /* @__PURE__ */ new Set([\"push\", \"pop\"]);\n const RESULT_RETURNING_METHODS = /* @__PURE__ */ new Set([\n ...QUEUE_METHODS,\n ...SHIFTING_METHODS\n ]);\n const REORDERING_METHODS = /* @__PURE__ */ new Set([\"reverse\", \"sort\"]);\n const MUTATING_METHODS = /* @__PURE__ */ new Set([\n ...RESULT_RETURNING_METHODS,\n ...REORDERING_METHODS,\n \"splice\"\n ]);\n const FIND_METHODS = /* @__PURE__ */ new Set([\"find\", \"findLast\"]);\n const NON_MUTATING_METHODS = /* @__PURE__ */ new Set([\n \"filter\",\n \"slice\",\n \"concat\",\n \"flat\",\n ...FIND_METHODS,\n \"findIndex\",\n \"findLastIndex\",\n \"some\",\n \"every\",\n \"indexOf\",\n \"lastIndexOf\",\n \"includes\",\n \"join\",\n \"toString\",\n \"toLocaleString\"\n ]);\n function isMutatingArrayMethod(method) {\n return MUTATING_METHODS.has(method);\n }\n function isNonMutatingArrayMethod(method) {\n return NON_MUTATING_METHODS.has(method);\n }\n function isArrayOperationMethod(method) {\n return isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method);\n }\n function enterOperation(state, method) {\n state.operationMethod = method;\n }\n function exitOperation(state) {\n state.operationMethod = void 0;\n }\n function executeArrayMethod(state, operation, markLength = true) {\n prepareCopy(state);\n const result = operation();\n markChanged(state);\n if (markLength)\n state.assigned_.set(\"length\", true);\n return result;\n }\n function markAllIndicesReassigned(state) {\n state.allIndicesReassigned_ = true;\n }\n function normalizeSliceIndex(index, length) {\n if (index < 0) {\n return Math.max(length + index, 0);\n }\n return Math.min(index, length);\n }\n function handleInsertedValues(state, startIndex, values) {\n for (let i = 0; i < values.length; i++) {\n const index = startIndex + i;\n state.assigned_.set(index, true);\n handleCrossReference(state, index, values[i]);\n }\n }\n function handleSimpleOperation(state, method, args) {\n return executeArrayMethod(state, () => {\n const lengthBefore = state.copy_.length;\n const result = state.copy_[method](...args);\n if (SHIFTING_METHODS.has(method)) {\n markAllIndicesReassigned(state);\n }\n if (method === \"push\" && args.length > 0) {\n handleInsertedValues(state, lengthBefore, args);\n } else if (method === \"unshift\" && args.length > 0) {\n handleInsertedValues(state, 0, args);\n }\n return RESULT_RETURNING_METHODS.has(method) ? result : state.draft_;\n });\n }\n function handleReorderingOperation(state, method, args) {\n return executeArrayMethod(\n state,\n () => {\n ;\n state.copy_[method](...args);\n markAllIndicesReassigned(state);\n return state.draft_;\n },\n false\n );\n }\n function createMethodInterceptor(state, originalMethod) {\n return function interceptedMethod(...args) {\n const method = originalMethod;\n enterOperation(state, method);\n try {\n if (isMutatingArrayMethod(method)) {\n if (RESULT_RETURNING_METHODS.has(method)) {\n return handleSimpleOperation(state, method, args);\n }\n if (REORDERING_METHODS.has(method)) {\n return handleReorderingOperation(state, method, args);\n }\n if (method === \"splice\") {\n const res = executeArrayMethod(\n state,\n () => state.copy_.splice(...args)\n );\n markAllIndicesReassigned(state);\n if (args.length > 2) {\n const startIndex = normalizeSliceIndex(\n args[0] ?? 0,\n state.copy_.length\n );\n handleInsertedValues(state, startIndex, args.slice(2));\n }\n return res;\n }\n } else {\n return handleNonMutatingOperation(state, method, args);\n }\n } finally {\n exitOperation(state);\n }\n };\n }\n function handleNonMutatingOperation(state, method, args) {\n const source = latest(state);\n if (method === \"filter\") {\n const predicate = args[0];\n const result = [];\n for (let i = 0; i < source.length; i++) {\n if (predicate(source[i], i, source)) {\n result.push(state.draft_[i]);\n }\n }\n return result;\n }\n if (FIND_METHODS.has(method)) {\n const predicate = args[0];\n const isForward = method === \"find\";\n const step = isForward ? 1 : -1;\n const start = isForward ? 0 : source.length - 1;\n for (let i = start; i >= 0 && i < source.length; i += step) {\n if (predicate(source[i], i, source)) {\n return state.draft_[i];\n }\n }\n return void 0;\n }\n if (method === \"slice\") {\n const rawStart = args[0] ?? 0;\n const rawEnd = args[1] ?? source.length;\n const start = normalizeSliceIndex(rawStart, source.length);\n const end = normalizeSliceIndex(rawEnd, source.length);\n const result = [];\n for (let i = start; i < end; i++) {\n result.push(state.draft_[i]);\n }\n return result;\n }\n return source[method](...args);\n }\n loadPlugin(PluginArrayMethods, {\n createMethodInterceptor,\n isArrayOperationMethod,\n isMutatingArrayMethod\n });\n}\n\n// src/immer.ts\nvar immer = new Immer2();\nvar produce = immer.produce;\nvar produceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(immer);\nvar setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer);\nvar setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(immer);\nvar setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind(immer);\nvar applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer);\nvar createDraft = /* @__PURE__ */ immer.createDraft.bind(immer);\nvar finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer);\nvar castDraft = (value) => value;\nvar castImmutable = (value) => value;\nexport {\n Immer2 as Immer,\n applyPatches,\n castDraft,\n castImmutable,\n createDraft,\n current,\n enableArrayMethods,\n enableMapSet,\n enablePatches,\n finishDraft,\n freeze,\n DRAFTABLE as immerable,\n isDraft,\n isDraftable,\n NOTHING as nothing,\n original,\n produce,\n produceWithPatches,\n setAutoFreeze,\n setUseStrictIteration,\n setUseStrictShallowCopy\n};\n//# sourceMappingURL=immer.mjs.map","// Storage adapters for the state() module. Lifted from the v1\n// store/storage-manager.ts and tightened — same four backends\n// (memory / local / session / indexeddb), same Map/Set JSON tunnel,\n// gives the state() factory a uniform async interface to load + save.\n//\n// The microtask write-debouncer lives in state.ts (the consumer of\n// this module) — adapters here are plain load/save/clear.\n\nexport type StorageBackend = 'memory' | 'local' | 'session' | 'indexeddb'\n\nexport interface StorageAdapter<T> {\n\tload(): Promise<T | null>\n\tsave(value: T): Promise<void>\n\tclear(): Promise<void>\n\tclose?(): Promise<void>\n}\n\nexport class StateStorageError<T = unknown> extends Error {\n\treadonly cause?: T\n\treadonly context?: Record<string, unknown>\n\treadonly timestamp: Date\n\tconstructor(message: string, cause?: T, context?: Record<string, unknown>) {\n\t\tsuper(message)\n\t\tthis.name = 'StateStorageError'\n\t\tthis.cause = cause\n\t\tthis.context = context\n\t\tthis.timestamp = new Date()\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// JSON tunnel for Map/Set values stored in string-backed storage.\n// IDB stores native objects so doesn't need this — only used by local/session.\n\nconst MAP_TAG = '__schmancy_state_Map'\nconst SET_TAG = '__schmancy_state_Set'\n\ninterface TaggedMap {\n\t$kind: typeof MAP_TAG\n\tentries: Array<[unknown, unknown]>\n}\ninterface TaggedSet {\n\t$kind: typeof SET_TAG\n\tvalues: unknown[]\n}\n\nfunction replacer(_key: string, value: unknown): unknown {\n\tif (value instanceof Map) {\n\t\treturn { $kind: MAP_TAG, entries: Array.from(value.entries()) } satisfies TaggedMap\n\t}\n\tif (value instanceof Set) {\n\t\treturn { $kind: SET_TAG, values: Array.from(value.values()) } satisfies TaggedSet\n\t}\n\treturn value\n}\n\nfunction reviver(_key: string, value: unknown): unknown {\n\tif (value && typeof value === 'object' && '$kind' in value) {\n\t\tconst tagged = value as { $kind: unknown; entries?: unknown; values?: unknown }\n\t\tconst kind = tagged.$kind\n\t\tif (kind === MAP_TAG) {\n\t\t\tif (!Array.isArray(tagged.entries)) return value\n\t\t\tconst ok = tagged.entries.every(e => Array.isArray(e) && e.length === 2)\n\t\t\tif (!ok) return value\n\t\t\treturn new Map(tagged.entries as Iterable<readonly [unknown, unknown]>)\n\t\t}\n\t\tif (kind === SET_TAG) {\n\t\t\tif (!Array.isArray(tagged.values)) return value\n\t\t\treturn new Set(tagged.values)\n\t\t}\n\t}\n\treturn value\n}\n\n// ---------------------------------------------------------------------------\n\nclass MemoryAdapter<T> implements StorageAdapter<T> {\n\t#data: T | null = null\n\tasync load(): Promise<T | null> {\n\t\treturn this.#data\n\t}\n\tasync save(value: T): Promise<void> {\n\t\tthis.#data = value\n\t}\n\tasync clear(): Promise<void> {\n\t\tthis.#data = null\n\t}\n}\n\nclass WebStorageAdapter<T> implements StorageAdapter<T> {\n\tconstructor(\n\t\tprivate readonly storage: Storage,\n\t\tprivate readonly key: string,\n\t\tprivate readonly label: string,\n\t) {}\n\tasync load(): Promise<T | null> {\n\t\ttry {\n\t\t\tconst raw = this.storage.getItem(this.key)\n\t\t\treturn raw ? (JSON.parse(raw, reviver) as T) : null\n\t\t} catch (err) {\n\t\t\tconsole.error(`[state] ${this.label} load failed (${this.key}):`, err)\n\t\t\treturn null\n\t\t}\n\t}\n\tasync save(value: T): Promise<void> {\n\t\ttry {\n\t\t\tthis.storage.setItem(this.key, JSON.stringify(value, replacer))\n\t\t} catch (err) {\n\t\t\tthrow new StateStorageError(\n\t\t\t\t`[state] ${this.label} save failed (${this.key})`,\n\t\t\t\terr,\n\t\t\t)\n\t\t}\n\t}\n\tasync clear(): Promise<void> {\n\t\tthis.storage.removeItem(this.key)\n\t}\n}\n\nclass IndexedDBAdapter<T> implements StorageAdapter<T> {\n\tprivate static readonly DB_NAME = 'SchmancyState'\n\tprivate static readonly STORE_NAME = 'states'\n\tprivate static readonly DB_VERSION = 1\n\n\t#db: IDBDatabase | null = null\n\t#opening: Promise<IDBDatabase> | null = null\n\n\tconstructor(private readonly key: string) {}\n\n\tprivate openDB(): Promise<IDBDatabase> {\n\t\tif (this.#db) return Promise.resolve(this.#db)\n\t\tif (this.#opening) return this.#opening\n\t\tthis.#opening = new Promise<IDBDatabase>((resolve, reject) => {\n\t\t\tconst req = indexedDB.open(IndexedDBAdapter.DB_NAME, IndexedDBAdapter.DB_VERSION)\n\t\t\treq.onupgradeneeded = () => {\n\t\t\t\tconst db = req.result\n\t\t\t\tif (!db.objectStoreNames.contains(IndexedDBAdapter.STORE_NAME)) {\n\t\t\t\t\tdb.createObjectStore(IndexedDBAdapter.STORE_NAME)\n\t\t\t\t}\n\t\t\t}\n\t\t\treq.addEventListener('success', () => {\n\t\t\t\tthis.#db = req.result\n\t\t\t\tresolve(req.result)\n\t\t\t}, { once: true })\n\t\t\treq.addEventListener('error', () => reject(req.error), { once: true })\n\t\t})\n\t\treturn this.#opening\n\t}\n\n\tasync load(): Promise<T | null> {\n\t\ttry {\n\t\t\tconst db = await this.openDB()\n\t\t\treturn await new Promise<T | null>((resolve, reject) => {\n\t\t\t\tconst tx = db.transaction(IndexedDBAdapter.STORE_NAME, 'readonly')\n\t\t\t\tconst req = tx.objectStore(IndexedDBAdapter.STORE_NAME).get(this.key)\n\t\t\t\treq.addEventListener('success', () => resolve((req.result ?? null) as T | null), { once: true })\n\t\t\t\treq.addEventListener('error', () => reject(req.error), { once: true })\n\t\t\t})\n\t\t} catch (err) {\n\t\t\tconsole.error(`[state] IDB load failed (${this.key}):`, err)\n\t\t\treturn null\n\t\t}\n\t}\n\n\tasync save(value: T): Promise<void> {\n\t\tconst db = await this.openDB()\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tconst tx = db.transaction(IndexedDBAdapter.STORE_NAME, 'readwrite')\n\t\t\tconst req = tx.objectStore(IndexedDBAdapter.STORE_NAME).put(value, this.key)\n\t\t\treq.addEventListener('success', () => resolve(), { once: true })\n\t\t\treq.addEventListener('error', () => reject(\n\t\t\t\tnew StateStorageError(`[state] IDB save failed (${this.key})`, req.error),\n\t\t\t), { once: true })\n\t\t})\n\t}\n\n\tasync clear(): Promise<void> {\n\t\tconst db = await this.openDB()\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tconst tx = db.transaction(IndexedDBAdapter.STORE_NAME, 'readwrite')\n\t\t\tconst req = tx.objectStore(IndexedDBAdapter.STORE_NAME).delete(this.key)\n\t\t\treq.addEventListener('success', () => resolve(), { once: true })\n\t\t\treq.addEventListener('error', () => reject(req.error), { once: true })\n\t\t})\n\t}\n\n\tasync close(): Promise<void> {\n\t\tif (this.#db) {\n\t\t\tthis.#db.close()\n\t\t\tthis.#db = null\n\t\t}\n\t\tthis.#opening = null\n\t}\n}\n\nexport function createAdapter<T>(backend: StorageBackend, key: string): StorageAdapter<T> {\n\tswitch (backend) {\n\t\tcase 'local':\n\t\t\treturn new WebStorageAdapter<T>(localStorage, key, 'localStorage')\n\t\tcase 'session':\n\t\t\treturn new WebStorageAdapter<T>(sessionStorage, key, 'sessionStorage')\n\t\tcase 'indexeddb':\n\t\t\treturn new IndexedDBAdapter<T>(key)\n\t\tcase 'memory':\n\t\tdefault:\n\t\t\treturn new MemoryAdapter<T>()\n\t}\n}\n","// `<schmancy-context provides={[cart, …]}>` — declarative state isolation.\n//\n// Mounts one isolated copy of each provided state under the element. Reads\n// and writes from descendants resolve to the isolated copy via the\n// `@lit/context` request protocol; descendants outside any `<schmancy-context>`\n// continue to read/write the module-scoped global. The isolated copy is\n// initialised with a snapshot of `tmpl.value` at mount time so the subtree\n// starts from \"current global state, then diverges.\"\n//\n// Lifetime: each isolated copy lives exactly as long as this element is\n// connected. `disconnectedCallback` destroys all isolated copies; their\n// pending writes flush, their adapters close.\n\nimport { LitElement, html } from 'lit'\nimport { property } from 'lit/decorators.js'\nimport { ContextProvider, createContext, type Context } from '@lit/context'\nimport { _publishEventHost, stateContextKey } from './active-host'\n\n// Curated set of DOM event types that descendants are likely to bind state-\n// mutating handlers to. The capture-phase listener publishes `this` as the\n// active event-host before the event reaches the target; descendants whose\n// inline handlers (or any code reached during the synchronous chain) call a\n// state mutator can resolve back to the isolated copy this context provides.\nconst EVENT_TYPES = [\n\t'click',\n\t'dblclick',\n\t'submit',\n\t'change',\n\t'input',\n\t'keydown',\n\t'keyup',\n\t'keypress',\n\t'pointerdown',\n\t'pointerup',\n\t'mousedown',\n\t'mouseup',\n\t'focus',\n\t'blur',\n\t'paste',\n\t'drop',\n] as const\n\n/** Duck-typed view of what the `state()` factory hands out, restricted to the\n * bits `<schmancy-context>` needs. Kept internal — consumers see the full\n * `State<>` type and never refer to this. */\nexport interface StateTemplate {\n\treadonly namespace: string\n\treadonly value: unknown\n\t/** Internal hook the factory adds to every state instance. Builds a fresh\n\t * per-context copy seeded with the current value, sharing nothing with the\n\t * global instance. The returned object exposes `destroy()` so the context\n\t * element can flush + close on disconnect. */\n\t_isolatedInstance(): { destroy(): void } & Record<string | symbol, unknown>\n}\n\nexport class SchmancyContext extends LitElement {\n\t/** States to isolate under this subtree. Pass the same instances you import\n\t * at module scope (e.g. `provides={[cart, menu]}`). Outside this element\n\t * they continue to behave as module-scoped globals; descendants of this\n\t * element see a per-element isolated copy. */\n\t@property({ attribute: false }) provides: readonly StateTemplate[] = []\n\n\t// Per-mount records. Keep both the provider (so we can release it on\n\t// disconnect) and the isolated instance (so we can destroy it).\n\tprivate _scoped: Array<{\n\t\tisolated: { destroy(): void }\n\t\tprovider: ContextProvider<Context<unknown, unknown>>\n\t}> = []\n\n\tprivate _publishEventTargetAsHost = (e: Event): void => {\n\t\t// Publish the deepest event target (across shadow boundaries) rather\n\t\t// than `this`. The downstream `ContextRequestEvent` will be dispatched\n\t\t// from this host and must bubble up through `<schmancy-context>` to\n\t\t// reach our `ContextProvider`. `@lit/context` skips self-registration\n\t\t// (`consumerHost === this.host` ⇒ no-op), so dispatching from\n\t\t// schmancy-context itself would silently fall back to the global.\n\t\tconst path = e.composedPath()\n\t\tfor (const node of path) {\n\t\t\tif (node instanceof HTMLElement) {\n\t\t\t\t_publishEventHost(node)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\toverride connectedCallback(): void {\n\t\tsuper.connectedCallback()\n\t\tfor (const tmpl of this.provides) {\n\t\t\tconst isolated = tmpl._isolatedInstance()\n\t\t\tconst ctx = createContext<unknown>(stateContextKey(tmpl.namespace))\n\t\t\t// ContextProvider auto-wires via the host's ReactiveControllerHost\n\t\t\t// interface (LitElement satisfies it). It listens for\n\t\t\t// `context-request` events and responds with `isolated` for any\n\t\t\t// requester whose `event.context === ctx`.\n\t\t\tconst provider = new ContextProvider(this, { context: ctx, initialValue: isolated })\n\t\t\tthis._scoped.push({ isolated, provider })\n\t\t}\n\t\tfor (const type of EVENT_TYPES) {\n\t\t\tthis.addEventListener(type, this._publishEventTargetAsHost, { capture: true })\n\t\t}\n\t}\n\n\toverride disconnectedCallback(): void {\n\t\tfor (const type of EVENT_TYPES) {\n\t\t\tthis.removeEventListener(type, this._publishEventTargetAsHost, { capture: true })\n\t\t}\n\t\tfor (const entry of this._scoped) {\n\t\t\tentry.isolated.destroy()\n\t\t}\n\t\tthis._scoped = []\n\t\tsuper.disconnectedCallback()\n\t}\n\n\toverride render() {\n\t\treturn html`<slot></slot>`\n\t}\n}\n\n// Imperative define so a second load (source + dist) is a no-op rather than\n// a throw — the registry is process-global; whichever class wins serves the\n// element identity for the page.\nif (!customElements.get('schmancy-context')) {\n\tcustomElements.define('schmancy-context', SchmancyContext)\n}\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'schmancy-context': SchmancyContext\n\t}\n}\n","// @mhmo91/schmancy/state — reactive state primitive.\n//\n// Module-scoped singletons keyed by namespace. Each state exposes:\n// - `value: T` current snapshot (defaultValue while loading)\n// - `signal: Signal.State<T>` raw TC39 signal (use with computed())\n// - `$: Observable<T>` RxJS surface (auto-emits on change, microtask-coalesced)\n// - `ready: Promise<void>` resolves once initial load attempt completes\n// - `loaded: boolean` runtime flag — `value` reflects stored data\n//\n// Three call shapes:\n// const cart = state<CartState>('hannah/cart').session({ items: [], total: 0 })\n// const cart = state('hannah/cart').session(initialCart) // typed-const\n// declare module '@mhmo91/schmancy/state' { // registry\n// interface SchmancyStateRegistry { 'hannah/cart': CartState }\n// }\n// const cart = state('hannah/cart').session({ items: [], total: 0 })\n\nimport { Signal } from '@lit-labs/signals'\n// `@lit/context` re-exports `ContextRequestEvent` as `ContextEvent` from\n// its public entry. Same class, just a shorter public name.\nimport { ContextEvent as ContextRequestEvent, createContext } from '@lit/context'\nimport { Observable } from 'rxjs'\nimport { produce, type Draft } from 'immer'\n\nimport { createAdapter, type StorageAdapter, type StorageBackend } from './persist'\nimport { resolveActiveHost, stateContextKey } from './active-host'\n// Side-effect import: registers the `<schmancy-context>` element so users\n// only need to import from `@mhmo91/schmancy/state` to get both the factory\n// and the scoping primitive.\nimport './schmancy-context'\n\nexport type { StorageBackend } from './persist'\nexport { Signal } from '@lit-labs/signals'\nexport { _activeHost } from './active-host'\nexport { SchmancyContext } from './schmancy-context'\n\n// ---------------------------------------------------------------------------\n// Public type surface\n// ---------------------------------------------------------------------------\n\nconst stateBrand: unique symbol = Symbol('schmancy.state')\nconst namespaceBrand: unique symbol = Symbol('schmancy.state.namespace')\n\n/**\n * Open registry — augment via `declare module '@mhmo91/schmancy/state'` to\n * bind a TypeScript type to a namespace string. Augmenting flips that\n * namespace to overload (A) of the factory: zero ceremony at the call\n * site, T comes from the registry.\n */\nexport interface SchmancyStateRegistry {}\n\nexport type RegisteredNamespace = keyof SchmancyStateRegistry & string\n\n/** Feature-prefix convention enforced at compile time. */\nexport type FeatureNamespace = `${string}/${string}`\n\nexport type AssertNovel<NS extends string> = NS extends RegisteredNamespace\n\t? never & { readonly __error: `Namespace \"${NS}\" already registered` }\n\t: NS\n\nexport type SyncStorage = Exclude<StorageBackend, 'indexeddb'>\nexport type AsyncStorage = Extract<StorageBackend, 'indexeddb'>\nexport type IsAsync<S extends StorageBackend> = S extends AsyncStorage ? true : false\n\n// Detect explicit null/undefined in T's union — works in BOTH strict and\n// non-strict tsconfigs. The relaxed `null extends T` form fires for every\n// T when strictNullChecks is off, which classifies every shape as\n// 'nullable'. Distributing `T extends null/undefined` is a structural\n// subtype check that doesn't depend on strict mode.\ntype _Has<T, U> = T extends U ? true : never\ntype _IsNullable<T> = [_Has<T, null> | _Has<T, undefined>] extends [never] ? false : true\n\n/**\n * Shape classifier — drives the variant write API per T. Order: structural\n * shapes first (Map / Set / Array), primitives, then nullable-union check,\n * then plain object.\n */\nexport type Kind<T> = [T] extends [Map<unknown, unknown>]\n\t? 'map'\n\t: [T] extends [Set<unknown>]\n\t\t? 'set'\n\t\t: [T] extends [readonly unknown[]]\n\t\t\t? 'array'\n\t\t\t: [T] extends [string | number | boolean | bigint | symbol]\n\t\t\t\t? 'primitive'\n\t\t\t\t: _IsNullable<T> extends true\n\t\t\t\t\t? 'nullable'\n\t\t\t\t\t: [T] extends [object]\n\t\t\t\t\t\t? 'object'\n\t\t\t\t\t\t: 'unknown'\n\nexport interface ObjectAPI<T> {\n\tset(patch: Partial<T>, merge?: boolean): void\n\treplace(next: T): void\n\tupdate(recipe: (draft: Draft<T>) => void): void\n\tdelete<K extends keyof T>(key: K): void\n}\n\nexport interface MapAPI<T> {\n\tset: T extends Map<infer K, infer V> ? (key: K, value: V) => void : never\n\treplace(next: T): void\n\tdelete: T extends Map<infer K, unknown> ? (key: K) => void : never\n\tclear(): void\n}\n\nexport interface SetAPI<T> {\n\tadd: T extends Set<infer U> ? (value: U) => void : never\n\tdelete: T extends Set<infer U> ? (value: U) => boolean : never\n\ttoggle: T extends Set<infer U> ? (value: U) => void : never\n\treplace(next: T): void\n\tclear(): void\n}\n\nexport interface ArrayAPI<T> {\n\tpush: T extends readonly (infer U)[] ? (...items: U[]) => void : never\n\treplace(next: T): void\n\tupdate(recipe: (draft: Draft<T>) => void): void\n\tclear(): void\n}\n\nexport interface ScalarAPI<T> {\n\tset(next: T): void\n\treplace(next: T): void\n}\n\nexport type WriteAPI<T> = Kind<T> extends 'map'\n\t? MapAPI<T>\n\t: Kind<T> extends 'set'\n\t\t? SetAPI<T>\n\t\t: Kind<T> extends 'array'\n\t\t\t? ArrayAPI<T>\n\t\t\t: Kind<T> extends 'object'\n\t\t\t\t? ObjectAPI<T>\n\t\t\t\t: ScalarAPI<T>\n\nexport interface BaseAPI<NS extends string, T, S extends StorageBackend> {\n\treadonly [stateBrand]: true\n\treadonly namespace: NS & { readonly [namespaceBrand]: NS }\n\treadonly storage: S\n\t/**\n\t * Current value. For sync backends (memory/local/session) the load is\n\t * synchronous, so the type narrows to `T`. For `idb` the load is genuinely\n\t * async — `value` is `T | undefined` until `ready` resolves. Read with\n\t * `state.value ?? state.defaultValue` if you don't care about the\n\t * pre-load distinction; await `state.ready` if you do.\n\t */\n\treadonly value: IsAsync<S> extends true ? T | undefined : T\n\treadonly defaultValue: T\n\treadonly ready: Promise<void>\n\treadonly loaded: boolean\n\treadonly signal: Signal.State<T>\n\treadonly $: Observable<T>\n\tdestroy(): void\n\t/** Internal: build a fresh per-`<schmancy-context>` copy seeded with the\n\t * current value. Exposed on the type so a state can be passed to\n\t * `<schmancy-context provides={[…]}>` without casts. Not for end-user\n\t * code — the leading underscore signals \"internal API\". */\n\t_isolatedInstance(): { destroy(): void } & Record<string | symbol, unknown>\n}\n\nexport interface SyncState<NS extends string, T, S extends SyncStorage>\n\textends BaseAPI<NS, T, S>,\n\t\tDisposable {\n\t[Symbol.dispose](): void\n}\n\nexport interface AsyncState<NS extends string, T>\n\textends BaseAPI<NS, T, 'indexeddb'>,\n\t\tDisposable,\n\t\tAsyncDisposable {\n\t[Symbol.dispose](): void\n\t[Symbol.asyncDispose](): Promise<void>\n}\n\nexport type State<NS extends string, T, S extends StorageBackend> = S extends AsyncStorage\n\t? AsyncState<NS, T> & WriteAPI<T>\n\t: SyncState<NS, T, S extends SyncStorage ? S : never> & WriteAPI<T>\n\nexport interface NamespaceHandlePinned<NS extends string, T> {\n\tmemory(initial: T): State<NS, T, 'memory'>\n\tlocal(initial: T): State<NS, T, 'local'>\n\tsession(initial: T): State<NS, T, 'session'>\n\tidb(initial: T): State<NS, T, 'indexeddb'>\n}\n\nexport interface NamespaceHandleInferred<NS extends string> {\n\tmemory<U>(initial: U): State<NS, U, 'memory'>\n\tlocal<U>(initial: U): State<NS, U, 'local'>\n\tsession<U>(initial: U): State<NS, U, 'session'>\n\tidb<U>(initial: U): State<NS, U, 'indexeddb'>\n}\n\n// ---------------------------------------------------------------------------\n// Runtime — variant detection + state instance construction\n// ---------------------------------------------------------------------------\n\ntype RuntimeKind = 'map' | 'set' | 'array' | 'object' | 'scalar'\n\nfunction detectKind(value: unknown): RuntimeKind {\n\tif (value instanceof Map) return 'map'\n\tif (value instanceof Set) return 'set'\n\tif (Array.isArray(value)) return 'array'\n\tif (value === null || value === undefined) return 'scalar'\n\tif (typeof value !== 'object') return 'scalar'\n\treturn 'object'\n}\n\n// Globalize the namespace-claim set so any number of schmancy module copies\n// share a single registry. Without this, source-state and dist-state would\n// each maintain their own `claimed` set and could both register the same\n// namespace, producing two singletons with the same name.\nconst CLAIMED_KEY = Symbol.for('schmancy.state.claimed')\nconst __claimedSlot = (globalThis as { [CLAIMED_KEY]?: Set<string> })\n__claimedSlot[CLAIMED_KEY] ??= new Set<string>()\nconst claimed = __claimedSlot[CLAIMED_KEY]!\n\n// ---------------------------------------------------------------------------\n// Context resolution.\n//\n// Every read (`value`, `signal`, `$`) and write (`set`, `replace`, `update`,\n// `delete`, `push`, `add`, `toggle`, `clear`) on a state instance routes\n// through `resolveContextual`. It asks \"is this call happening inside a\n// `<schmancy-context provides={[...]}>` subtree?\" by dispatching a\n// `context-request` event from the active host (resolved via the layered\n// fallback in `active-host.ts`). If a provider responds, the call routes to\n// the per-context isolated instance; otherwise it falls through to the\n// module-scoped global. The decision is cached per-host-per-namespace in a\n// WeakMap so repeat reads stay O(1).\n// ---------------------------------------------------------------------------\n\n// Globalize the per-host resolver cache so that a write through one schmancy\n// copy and a read through another resolve to the same target object — the\n// cache keys are DOM elements (process-global), but the cache itself must\n// also be shared.\nconst CACHE_KEY = Symbol.for('schmancy.state.hostResolverCache')\nconst __cacheSlot = (globalThis as {\n\t[CACHE_KEY]?: WeakMap<HTMLElement, Map<string, unknown>>\n})\n__cacheSlot[CACHE_KEY] ??= new WeakMap<HTMLElement, Map<string, unknown>>()\nconst hostResolverCache = __cacheSlot[CACHE_KEY]!\n\nfunction resolveContextual(namespace: string, fallback: unknown): unknown {\n\tconst host = resolveActiveHost()\n\tif (host === undefined) return fallback\n\n\tconst cached = hostResolverCache.get(host)?.get(namespace)\n\tif (cached !== undefined) return cached\n\n\tlet resolved: unknown = undefined\n\tconst ctx = createContext<unknown>(stateContextKey(namespace))\n\thost.dispatchEvent(\n\t\tnew ContextRequestEvent(ctx, host, value => {\n\t\t\tresolved = value\n\t\t}),\n\t)\n\n\tconst result = resolved !== undefined ? resolved : fallback\n\tlet perHost = hostResolverCache.get(host)\n\tif (!perHost) {\n\t\tperHost = new Map<string, unknown>()\n\t\thostResolverCache.set(host, perHost)\n\t}\n\tperHost.set(namespace, result)\n\treturn result\n}\n\ninterface InternalState {\n\tsignal: Signal.State<unknown>\n\tstorage: StorageBackend\n\tadapter: StorageAdapter<unknown>\n\tpendingWrite: Promise<void> | null\n\tscheduledWrite: boolean\n\tdisposed: boolean\n}\n\nfunction scheduleWrite(internal: InternalState): void {\n\tif (internal.scheduledWrite || internal.disposed) return\n\tinternal.scheduledWrite = true\n\tqueueMicrotask(() => {\n\t\tinternal.scheduledWrite = false\n\t\tif (internal.disposed) return\n\t\tinternal.pendingWrite = internal.adapter.save(internal.signal.get()).catch(err => {\n\t\t\tconsole.error('[state] save failed:', err)\n\t\t})\n\t})\n}\n\nfunction signalToObservable<T>(signal: Signal.State<T>): Observable<T> {\n\treturn new Observable<T>(subscriber => {\n\t\tsubscriber.next(signal.get())\n\t\tlet scheduled = false\n\t\tconst watcher = new Signal.subtle.Watcher(() => {\n\t\t\tif (scheduled) return\n\t\t\tscheduled = true\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tscheduled = false\n\t\t\t\tif (subscriber.closed) return\n\t\t\t\tsubscriber.next(signal.get())\n\t\t\t\twatcher.watch(signal)\n\t\t\t})\n\t\t})\n\t\twatcher.watch(signal)\n\t\treturn () => watcher.unwatch(signal)\n\t})\n}\n\nfunction buildWriteApi(internal: InternalState, kind: RuntimeKind): Record<string, unknown> {\n\tconst commit = (next: unknown): void => {\n\t\tif (internal.disposed) return\n\t\tinternal.signal.set(next)\n\t\tscheduleWrite(internal)\n\t}\n\n\tconst common = {\n\t\treplace: (next: unknown) => commit(next),\n\t}\n\n\tswitch (kind) {\n\t\tcase 'object':\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tset(patch: Record<string, unknown>, merge = true) {\n\t\t\t\t\tconst current = internal.signal.get() as Record<string, unknown>\n\t\t\t\t\tcommit(merge ? { ...current, ...patch } : patch)\n\t\t\t\t},\n\t\t\t\tupdate(recipe: (draft: unknown) => void) {\n\t\t\t\t\tcommit(produce(internal.signal.get(), recipe))\n\t\t\t\t},\n\t\t\t\tdelete(key: string) {\n\t\t\t\t\tconst current = internal.signal.get() as Record<string, unknown>\n\t\t\t\t\tconst next = { ...current }\n\t\t\t\t\tdelete next[key]\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t}\n\n\t\tcase 'map':\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tset(key: unknown, value: unknown) {\n\t\t\t\t\tconst current = internal.signal.get() as Map<unknown, unknown>\n\t\t\t\t\tconst next = new Map(current)\n\t\t\t\t\tnext.set(key, value)\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t\tdelete(key: unknown) {\n\t\t\t\t\tconst current = internal.signal.get() as Map<unknown, unknown>\n\t\t\t\t\tconst next = new Map(current)\n\t\t\t\t\tnext.delete(key)\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t\tclear() {\n\t\t\t\t\tcommit(new Map())\n\t\t\t\t},\n\t\t\t}\n\n\t\tcase 'set':\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tadd(value: unknown) {\n\t\t\t\t\tconst current = internal.signal.get() as Set<unknown>\n\t\t\t\t\tif (current.has(value)) return\n\t\t\t\t\tconst next = new Set(current)\n\t\t\t\t\tnext.add(value)\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t\tdelete(value: unknown): boolean {\n\t\t\t\t\tconst current = internal.signal.get() as Set<unknown>\n\t\t\t\t\tif (!current.has(value)) return false\n\t\t\t\t\tconst next = new Set(current)\n\t\t\t\t\tnext.delete(value)\n\t\t\t\t\tcommit(next)\n\t\t\t\t\treturn true\n\t\t\t\t},\n\t\t\t\ttoggle(value: unknown) {\n\t\t\t\t\tconst current = internal.signal.get() as Set<unknown>\n\t\t\t\t\tconst next = new Set(current)\n\t\t\t\t\tif (next.has(value)) {\n\t\t\t\t\t\tnext.delete(value)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnext.add(value)\n\t\t\t\t\t}\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t\tclear() {\n\t\t\t\t\tcommit(new Set())\n\t\t\t\t},\n\t\t\t}\n\n\t\tcase 'array':\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tpush(...items: unknown[]) {\n\t\t\t\t\tconst current = internal.signal.get() as unknown[]\n\t\t\t\t\tcommit([...current, ...items])\n\t\t\t\t},\n\t\t\t\tupdate(recipe: (draft: unknown) => void) {\n\t\t\t\t\tcommit(produce(internal.signal.get(), recipe))\n\t\t\t\t},\n\t\t\t\tclear() {\n\t\t\t\t\tcommit([])\n\t\t\t\t},\n\t\t\t}\n\n\t\tcase 'scalar':\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\t...common,\n\t\t\t\tset(next: unknown) {\n\t\t\t\t\tcommit(next)\n\t\t\t\t},\n\t\t\t}\n\t}\n}\n\ninterface CreateInstanceArgs {\n\tnamespace: string\n\tinitial: unknown\n\tstorage: StorageBackend\n}\n\ninterface CreateInstanceOptions {\n\t/** When true, the returned instance is a per-`<schmancy-context>` copy:\n\t * it does NOT claim the namespace in `claimed`, it does NOT route reads\n\t * or writes through `resolveContextual` (so it can serve as the\n\t * resolution target without recursion), and it does NOT expose\n\t * `_isolatedInstance` (you only isolate the global). */\n\tisolated?: boolean\n}\n\nfunction reportLoadError(err: unknown): void {\n\tconsole.error('[state] load failed:', err)\n}\n\nfunction createInstance(args: CreateInstanceArgs, options: CreateInstanceOptions = {}): unknown {\n\tconst { namespace, initial, storage } = args\n\tconst isolated = options.isolated === true\n\tconst adapter = createAdapter<unknown>(storage, namespace)\n\tconst signal = new Signal.State<unknown>(initial)\n\tconst internal: InternalState = {\n\t\tsignal,\n\t\tstorage,\n\t\tadapter,\n\t\tpendingWrite: null,\n\t\tscheduledWrite: false,\n\t\tdisposed: false,\n\t}\n\n\tlet loaded = false\n\tconst applyLoaded = (stored: unknown): void => {\n\t\tif (internal.disposed) return\n\t\tif (stored !== null && stored !== undefined) {\n\t\t\tinternal.signal.set(stored)\n\t\t}\n\t}\n\tconst markLoaded = (): boolean => (loaded = true)\n\tconst ready = adapter\n\t\t.load()\n\t\t.then(applyLoaded, reportLoadError)\n\t\t.then(markLoaded)\n\t\t.then(() => undefined)\n\n\tconst observable = signalToObservable(signal)\n\tconst writeApi = buildWriteApi(internal, detectKind(initial))\n\n\tasync function flushAndClose(): Promise<void> {\n\t\t// Wait for any in-flight write, then any scheduled microtask write.\n\t\tif (internal.pendingWrite) await internal.pendingWrite\n\t\t// Drain a possibly-still-scheduled microtask:\n\t\tawait new Promise<void>(resolve => queueMicrotask(resolve))\n\t\tif (internal.pendingWrite) await internal.pendingWrite\n\t\tif (adapter.close) await adapter.close()\n\t}\n\n\tconst dispose = (): void => {\n\t\tif (internal.disposed) return\n\t\tinternal.disposed = true\n\t\t// Fire-and-forget close for sync backends; AsyncDisposable variant\n\t\t// has its own awaited path via Symbol.asyncDispose.\n\t\tvoid flushAndClose()\n\t\tclaimed.delete(namespace)\n\t}\n\n\tconst asyncDispose = async (): Promise<void> => {\n\t\tif (internal.disposed) return\n\t\tinternal.disposed = true\n\t\tawait flushAndClose()\n\t\tclaimed.delete(namespace)\n\t}\n\n\t// Build the instance with explicit property definitions so the `value`\n\t// and `loaded` getters stay live. (A `{ ...base }` spread invokes the\n\t// getter once at spread time and freezes the result — that snapshot\n\t// then disagrees with the signal on every subsequent write.)\n\tconst instance: Record<string | symbol, unknown> = Object.assign(Object.create(null) as object, {\n\t\t[stateBrand]: true,\n\t\tnamespace,\n\t\tstorage,\n\t\tdefaultValue: initial,\n\t\tready,\n\t\tdestroy: dispose,\n\t\t[Symbol.dispose]: dispose,\n\t})\n\n\tObject.defineProperty(instance, 'loaded', {\n\t\tget: () => loaded,\n\t\tenumerable: true,\n\t})\n\n\tif (storage === 'indexeddb') {\n\t\tinstance[Symbol.asyncDispose] = asyncDispose\n\t}\n\n\tif (isolated) {\n\t\t// Per-context copy. Reads and writes go straight to its own signal —\n\t\t// no resolveContextual call, so it serves as a recursion-free\n\t\t// resolution target.\n\t\tObject.defineProperty(instance, 'value', {\n\t\t\tget: () => signal.get(),\n\t\t\tenumerable: true,\n\t\t})\n\t\tinstance.signal = signal\n\t\tinstance.$ = observable\n\t\tObject.assign(instance, writeApi)\n\t\treturn instance\n\t}\n\n\t// Global instance. Every public read/write resolves through the active\n\t// host: inside a `<schmancy-context provides={[…]}>` it routes to the\n\t// per-context copy; outside, it falls back to this same instance and\n\t// reads/writes its own signal directly. The cache in `resolveContextual`\n\t// keeps the lookup O(1) past the first hit.\n\tconst isolatedTarget: Record<string | symbol, unknown> = Object.assign(Object.create(null), {\n\t\tsignal,\n\t\t$: observable,\n\t\t...writeApi,\n\t})\n\tObject.defineProperty(isolatedTarget, 'value', {\n\t\tget: () => signal.get(),\n\t\tenumerable: true,\n\t})\n\n\tObject.defineProperty(instance, 'value', {\n\t\tget: () => (resolveContextual(namespace, isolatedTarget) as { value: unknown }).value,\n\t\tenumerable: true,\n\t})\n\tObject.defineProperty(instance, 'signal', {\n\t\tget: () =>\n\t\t\t(resolveContextual(namespace, isolatedTarget) as { signal: Signal.State<unknown> }).signal,\n\t\tenumerable: true,\n\t})\n\tObject.defineProperty(instance, '$', {\n\t\tget: () =>\n\t\t\t(resolveContextual(namespace, isolatedTarget) as { $: Observable<unknown> }).$,\n\t\tenumerable: true,\n\t})\n\tfor (const key of Object.keys(writeApi)) {\n\t\tinstance[key] = (...args: unknown[]): unknown => {\n\t\t\tconst target = resolveContextual(namespace, isolatedTarget) as Record<\n\t\t\t\tstring,\n\t\t\t\t(...a: unknown[]) => unknown\n\t\t\t>\n\t\t\treturn target[key](...args)\n\t\t}\n\t}\n\n\t// Hook used by `<schmancy-context>` to mint a per-context copy seeded\n\t// with the current value. Internal: not part of the public State<> type.\n\tinstance._isolatedInstance = (): unknown =>\n\t\tcreateInstance(\n\t\t\t{ namespace, initial: signal.get(), storage: 'memory' },\n\t\t\t{ isolated: true },\n\t\t)\n\n\treturn instance\n}\n\nfunction makeHandle(namespace: string): Record<string, (initial: unknown) => unknown> {\n\tif (claimed.has(namespace)) {\n\t\tthrow new Error(\n\t\t\t`[state] namespace \"${namespace}\" already registered. Each namespace must be unique.`,\n\t\t)\n\t}\n\tclaimed.add(namespace)\n\treturn {\n\t\tmemory: initial => createInstance({ namespace, initial, storage: 'memory' }),\n\t\tlocal: initial => createInstance({ namespace, initial, storage: 'local' }),\n\t\tsession: initial => createInstance({ namespace, initial, storage: 'session' }),\n\t\tidb: initial => createInstance({ namespace, initial, storage: 'indexeddb' }),\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Three-overload factory.\n// (A) registered → pinned T from registry\n// (C) unregistered, no type arg → inferred T (typed-const flow)\n// (B) unregistered, explicit type arg → pinned T\n// Order matters for resolution; do not reorder.\n// ---------------------------------------------------------------------------\n\nexport function state<NS extends RegisteredNamespace>(\n\tnamespace: NS,\n): NamespaceHandlePinned<NS, SchmancyStateRegistry[NS]>\n\nexport function state<const NS extends FeatureNamespace>(\n\tnamespace: NS extends RegisteredNamespace ? never : AssertNovel<NS>,\n): NamespaceHandleInferred<NS>\n\nexport function state<T, const NS extends FeatureNamespace = FeatureNamespace>(\n\tnamespace: NS extends RegisteredNamespace ? never : AssertNovel<NS>,\n): NamespaceHandlePinned<NS, T>\n\nexport function state(namespace: unknown): unknown {\n\tif (typeof namespace !== 'string') {\n\t\tthrow new TypeError('[state] namespace must be a string')\n\t}\n\tif (!namespace.includes('/')) {\n\t\tthrow new TypeError(\n\t\t\t`[state] namespace \"${namespace}\" must follow the \"feature/name\" convention.`,\n\t\t)\n\t}\n\treturn makeHandle(namespace)\n}\n\n// ---------------------------------------------------------------------------\n// Derived state — re-export the upstream computed primitive directly.\n// Reading state.value (which calls signal.get() under the hood) inside a\n// computed callback auto-tracks the dependency.\n// ---------------------------------------------------------------------------\n\nexport { computed } from '@lit-labs/signals'\n\n// ---------------------------------------------------------------------------\n// effect(fn) — run a side-effect function whenever any signal it reads\n// changes. Returns a Disposable so the effect can be cleaned up.\n//\n// const stop = effect(() => {\n// document.title = `${cart.value.items.length} items`\n// })\n// ...later...\n// stop[Symbol.dispose]()\n//\n// The effect runs once eagerly to register dependencies, then re-runs\n// (microtask-coalesced) whenever any read signal changes.\n// ---------------------------------------------------------------------------\n\nexport interface EffectHandle extends Disposable {\n\t[Symbol.dispose](): void\n}\n\nexport function effect(fn: () => void): EffectHandle {\n\tlet scheduled = false\n\tlet disposed = false\n\tlet watcher: Signal.subtle.Watcher | undefined\n\n\tconst run = (): void => {\n\t\tif (disposed) return\n\t\t// Wrap fn in a Computed so signal reads are tracked. The computed's\n\t\t// value is unused — we only care about the dependency graph it builds.\n\t\tconst computation = new Signal.Computed(() => {\n\t\t\tfn()\n\t\t\treturn undefined\n\t\t})\n\t\t// Reading the computed registers our Watcher as a sink for every\n\t\t// signal the fn touches.\n\t\twatcher?.unwatch()\n\t\twatcher = new Signal.subtle.Watcher(() => {\n\t\t\tif (scheduled || disposed) return\n\t\t\tscheduled = true\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tscheduled = false\n\t\t\t\tif (disposed) return\n\t\t\t\trun()\n\t\t\t})\n\t\t})\n\t\twatcher.watch(computation)\n\t\tcomputation.get()\n\t}\n\n\trun()\n\n\treturn {\n\t\t[Symbol.dispose](): void {\n\t\t\tif (disposed) return\n\t\t\tdisposed = true\n\t\t\twatcher?.unwatch()\n\t\t\twatcher = undefined\n\t\t},\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Observable → state bridge.\n// ---------------------------------------------------------------------------\n\nexport interface FromObservableOptions {\n\tstorage?: StorageBackend\n}\n\n/**\n * Lift an Observable into a state(). The state is initialized with\n * `initial`, then updates on every Observable emission. Cleanup on\n * dispose unsubscribes the source.\n */\nexport function stateFromObservable<T, NS extends FeatureNamespace>(\n\tobservable: Observable<T>,\n\tnamespace: NS,\n\tinitial: T,\n\toptions: FromObservableOptions = {},\n): State<NS, T, 'memory'> {\n\tconst storage = options.storage ?? 'memory'\n\tconst handle = makeHandle(namespace)\n\tconst inst = handle[storage](initial) as State<NS, T, 'memory'> & {\n\t\treadonly signal: Signal.State<T>\n\t\t[Symbol.dispose](): void\n\t}\n\tconst subscription = observable.subscribe({\n\t\tnext: value => inst.signal.set(value),\n\t\terror: err => console.error(`[state] from(${namespace}) source errored:`, err),\n\t})\n\tconst originalDispose = inst[Symbol.dispose].bind(inst)\n\t;(inst as { [Symbol.dispose]: () => void })[Symbol.dispose] = () => {\n\t\tsubscription.unsubscribe()\n\t\toriginalDispose()\n\t}\n\treturn inst\n}\n\n// ---------------------------------------------------------------------------\n// bindState(host, source) — Lit ReactiveController helper for one-way binding.\n//\n// Subscribes in hostConnected, unsubscribes in hostDisconnected, calls\n// host.requestUpdate() on every emission. Returned object exposes the same\n// `value` and `$` surface as the source so render code reads naturally:\n//\n// class CartView extends LitElement {\n// cart = bindState(this, cartState)\n// render() { return html`Items: ${this.cart.value.items.length}` }\n// }\n//\n// Decorator (`@observe`) form is deliberately deferred — schmancy's\n// tsconfig still uses experimentalDecorators=true and flipping to\n// TC39 native produces ~9k errors across the codebase. The helper\n// gives the same lifecycle guarantees with zero tsconfig churn.\n// ---------------------------------------------------------------------------\n\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\n\n/** Permissive duck-typed contract — v1 IStore<T>, v2 State<>, and\n * computed() outputs (`Signal.Computed<T>` wrapped in a thin shim) all\n * satisfy it once you supply a `value` getter and an Observable `$`. */\nexport interface ObservableState<T> {\n\treadonly value: T\n\treadonly $: Observable<T>\n}\n\nexport interface BoundState<T> {\n\treadonly value: T\n\treadonly $: Observable<T>\n}\n\nclass BindStateController<T> implements ReactiveController {\n\tprivate subscription: import('rxjs').Subscription | undefined\n\tprivate latest: T\n\tconstructor(\n\t\tprivate readonly host: ReactiveControllerHost,\n\t\tprivate readonly source: ObservableState<T>,\n\t) {\n\t\tthis.latest = source.value\n\t\thost.addController(this)\n\t}\n\tget value(): T {\n\t\treturn this.latest\n\t}\n\tget $(): Observable<T> {\n\t\treturn this.source.$\n\t}\n\thostConnected(): void {\n\t\tthis.subscription = this.source.$.subscribe(v => {\n\t\t\tthis.latest = v\n\t\t\tthis.host.requestUpdate()\n\t\t})\n\t}\n\thostDisconnected(): void {\n\t\tthis.subscription?.unsubscribe()\n\t\tthis.subscription = undefined\n\t}\n}\n\nexport function bindState<T>(\n\thost: ReactiveControllerHost,\n\tsource: ObservableState<T>,\n): BoundState<T> {\n\treturn new BindStateController(host, source)\n}\n\n// ---------------------------------------------------------------------------\n// @observe(source) — legacy property decorator for one-way binding.\n//\n// Usage:\n// class CartView extends LitElement {\n// @observe(cart) cart!: CartState\n// render() { return html`Items: ${this.cart.items.length}` }\n// }\n//\n// Reads return the latest value emitted by the source (falling back to\n// `source.value` before the first emission). Caller writes are dropped\n// with a dev-mode warning — the source is the single source of truth.\n//\n// Per-instance subscription is wired via Lit's static `addInitializer`,\n// which runs at instance construction and gives the decorator access to\n// the host. A `ReactiveController` handles the lifecycle: subscribe in\n// `hostConnected`, unsubscribe in `hostDisconnected`. Multiple `@observe`\n// decorators on the same class register independent controllers — no\n// init-order bookkeeping, no prototype-walking.\n//\n// Legacy decorator (matches the rest of schmancy's @property / @state /\n// @query family). Works under the existing `experimentalDecorators: true`\n// tsconfig — no migration required.\n// ---------------------------------------------------------------------------\n\ninterface ObserveHost extends ReactiveControllerHost {\n\taddController(controller: ReactiveController): void\n}\n\ninterface LitElementCtor {\n\taddInitializer(initializer: (host: ObserveHost) => void): void\n}\n\nexport function observe<T>(source: ObservableState<T>) {\n\treturn function (proto: object, propertyKey: string | symbol): void {\n\t\tconst storageKey = Symbol(`__observe_${String(propertyKey)}`)\n\n\t\t// Per-prototype accessor — reads return the latest cached value,\n\t\t// falling back to `source.value` before the first emission lands.\n\t\t// Writes from callers are dropped with a dev warning.\n\t\tObject.defineProperty(proto, propertyKey, {\n\t\t\tget(this: Record<symbol, T>): T {\n\t\t\t\tconst cached = this[storageKey]\n\t\t\t\treturn cached !== undefined ? cached : source.value\n\t\t\t},\n\t\t\tset(_value: T): void {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`@observe: field \"${String(propertyKey)}\" is read-only — write ignored. ` +\n\t\t\t\t\t\t`Update the source state directly.`,\n\t\t\t\t)\n\t\t\t},\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t})\n\n\t\t// Per-instance subscription via Lit's addInitializer hook.\n\t\tconst ctor = proto.constructor as unknown as LitElementCtor\n\t\tif (typeof ctor.addInitializer !== 'function') {\n\t\t\tthrow new TypeError(\n\t\t\t\t`@observe requires a Lit ReactiveElement subclass — ${proto.constructor.name} ` +\n\t\t\t\t\t`does not provide static addInitializer.`,\n\t\t\t)\n\t\t}\n\n\t\tctor.addInitializer((host: ObserveHost) => {\n\t\t\tlet subscription: import('rxjs').Subscription | undefined\n\t\t\thost.addController({\n\t\t\t\thostConnected(): void {\n\t\t\t\t\tsubscription = source.$.subscribe(value => {\n\t\t\t\t\t\t;(host as unknown as Record<symbol, T>)[storageKey] = value\n\t\t\t\t\t\thost.requestUpdate()\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t\thostDisconnected(): void {\n\t\t\t\t\tsubscription?.unsubscribe()\n\t\t\t\t\tsubscription = undefined\n\t\t\t\t},\n\t\t\t})\n\t\t})\n\t}\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;;;AACA,IAAI,IAAU,OAAO,IAAI,gBAAA,EACrB,IAAY,OAAO,IAAI,kBAAA,EACvB,IAAc,OAAO,IAAI,cAAA,EAGzB,IAAA,QAAA,IAAA,aAAkC,eA8BlC,EAAA,GA9BiD;CAEnD,SAAS,GAAA;EACP,OAAO,mBAAmB,EAAA,kFAAyF,EAAA;;CAErH,SAAS,GAAA;EACP,OAAO,sJAAsJ,EAAA;;CAE/J;CACA,SAAS,GAAA;EACP,OAAO,yHAAyH;;CAElI;CACA;CACA;CACA;CACA;CACA;CACA,SAAS,GAAA;EACP,OAAO,mCAAmC;;CAE5C;CACA;CACA;CACA;CACA,SAAS,GAAA;EACP,OAAO,oCAAoC;;CAAA;AAK/C,SAAS,EAAI,GAAA,GAAU,GAAA;CACrB,IAAA,QAAA,IAAA,aAA6B,cAAc;EACzC,IAAM,IAAI,EAAO,I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