mutts 1.0.6 → 1.0.8

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 (196) hide show
  1. package/README.md +61 -23
  2. package/dist/async/browser.d.ts +2 -0
  3. package/dist/async/browser.d.ts.map +1 -0
  4. package/dist/async/index.d.ts +18 -0
  5. package/dist/async/index.d.ts.map +1 -0
  6. package/dist/async/node.d.ts +2 -0
  7. package/dist/async/node.d.ts.map +1 -0
  8. package/dist/{chunks/index-CDCOjzTy.js → browser.cjs} +5913 -4382
  9. package/dist/browser.cjs.map +1 -0
  10. package/dist/browser.d.ts +1655 -0
  11. package/dist/browser.esm.js +305 -0
  12. package/dist/browser.esm.js.map +1 -0
  13. package/dist/chunks/async-browser-CA0jPWIi.cjs +304 -0
  14. package/dist/chunks/async-browser-CA0jPWIi.cjs.map +1 -0
  15. package/dist/chunks/async-core-UqHzvJ-S.cjs +25 -0
  16. package/dist/chunks/async-core-UqHzvJ-S.cjs.map +1 -0
  17. package/dist/chunks/async-node-BYHuGTni.cjs +103 -0
  18. package/dist/chunks/async-node-BYHuGTni.cjs.map +1 -0
  19. package/dist/chunks/{index-DiP0RXoZ.esm.js → index-DhaOVusv.esm.js} +5851 -4345
  20. package/dist/chunks/index-DhaOVusv.esm.js.map +1 -0
  21. package/dist/decorator.d.ts +17 -18
  22. package/dist/decorator.d.ts.map +1 -0
  23. package/dist/destroyable.d.ts +12 -15
  24. package/dist/destroyable.d.ts.map +1 -0
  25. package/dist/devtools/devtool/devtools.d.ts +1 -0
  26. package/dist/devtools/devtool/devtools.d.ts.map +1 -0
  27. package/dist/devtools/devtool/panel.d.ts +2 -0
  28. package/dist/devtools/devtool/panel.d.ts.map +1 -0
  29. package/dist/devtools/panel.js.map +1 -1
  30. package/dist/entry-browser.d.ts +3 -0
  31. package/dist/entry-browser.d.ts.map +1 -0
  32. package/dist/entry-node.d.ts +3 -0
  33. package/dist/entry-node.d.ts.map +1 -0
  34. package/dist/eventful.d.ts +3 -5
  35. package/dist/eventful.d.ts.map +1 -0
  36. package/dist/index.d.ts +13 -19
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/indexable.d.ts +10 -10
  39. package/dist/indexable.d.ts.map +1 -0
  40. package/dist/introspection.d.ts +27 -0
  41. package/dist/introspection.d.ts.map +1 -0
  42. package/dist/iterableWeak.d.ts +53 -0
  43. package/dist/iterableWeak.d.ts.map +1 -0
  44. package/dist/mixins.d.ts +25 -0
  45. package/dist/mixins.d.ts.map +1 -0
  46. package/dist/mutts.umd.js +1 -1
  47. package/dist/mutts.umd.js.map +1 -1
  48. package/dist/mutts.umd.min.js +1 -1
  49. package/dist/mutts.umd.min.js.map +1 -1
  50. package/dist/node.cjs +105 -0
  51. package/dist/node.cjs.map +1 -0
  52. package/dist/node.d.ts +1 -0
  53. package/dist/node.esm.js +104 -0
  54. package/dist/node.esm.js.map +1 -0
  55. package/dist/promiseChain.d.ts +4 -5
  56. package/dist/promiseChain.d.ts.map +1 -0
  57. package/dist/reactive/array.d.ts +49 -0
  58. package/dist/reactive/array.d.ts.map +1 -0
  59. package/dist/reactive/buffer.d.ts +44 -0
  60. package/dist/reactive/buffer.d.ts.map +1 -0
  61. package/dist/reactive/change.d.ts +29 -0
  62. package/dist/reactive/change.d.ts.map +1 -0
  63. package/dist/reactive/debug.d.ts +111 -0
  64. package/dist/reactive/debug.d.ts.map +1 -0
  65. package/dist/reactive/deep-touch.d.ts +28 -0
  66. package/dist/reactive/deep-touch.d.ts.map +1 -0
  67. package/dist/reactive/deep-watch-state.d.ts +25 -0
  68. package/dist/reactive/deep-watch-state.d.ts.map +1 -0
  69. package/dist/reactive/deep-watch.d.ts +19 -0
  70. package/dist/reactive/deep-watch.d.ts.map +1 -0
  71. package/dist/reactive/effect-context.d.ts +7 -0
  72. package/dist/reactive/effect-context.d.ts.map +1 -0
  73. package/dist/reactive/effects.d.ts +151 -0
  74. package/dist/reactive/effects.d.ts.map +1 -0
  75. package/dist/reactive/index.d.ts +20 -0
  76. package/dist/reactive/index.d.ts.map +1 -0
  77. package/dist/reactive/interface.d.ts +64 -0
  78. package/dist/reactive/interface.d.ts.map +1 -0
  79. package/dist/reactive/map.d.ts +30 -0
  80. package/dist/reactive/map.d.ts.map +1 -0
  81. package/dist/reactive/memoize.d.ts +5 -0
  82. package/dist/reactive/memoize.d.ts.map +1 -0
  83. package/dist/reactive/non-reactive-state.d.ts +9 -0
  84. package/dist/reactive/non-reactive-state.d.ts.map +1 -0
  85. package/dist/reactive/non-reactive.d.ts +11 -0
  86. package/dist/reactive/non-reactive.d.ts.map +1 -0
  87. package/dist/reactive/project.d.ts +41 -0
  88. package/dist/reactive/project.d.ts.map +1 -0
  89. package/dist/reactive/proxy-state.d.ts +8 -0
  90. package/dist/reactive/proxy-state.d.ts.map +1 -0
  91. package/dist/reactive/proxy.d.ts +23 -0
  92. package/dist/reactive/proxy.d.ts.map +1 -0
  93. package/dist/reactive/record.d.ts +116 -0
  94. package/dist/reactive/record.d.ts.map +1 -0
  95. package/dist/reactive/register.d.ts +64 -0
  96. package/dist/reactive/register.d.ts.map +1 -0
  97. package/dist/reactive/registry.d.ts +20 -0
  98. package/dist/reactive/registry.d.ts.map +1 -0
  99. package/dist/reactive/set.d.ts +28 -0
  100. package/dist/reactive/set.d.ts.map +1 -0
  101. package/dist/reactive/tracking.d.ts +7 -0
  102. package/dist/reactive/tracking.d.ts.map +1 -0
  103. package/dist/reactive/types.d.ts +376 -0
  104. package/dist/reactive/types.d.ts.map +1 -0
  105. package/dist/std-decorators.d.ts +9 -11
  106. package/dist/std-decorators.d.ts.map +1 -0
  107. package/dist/utils.d.ts +49 -0
  108. package/dist/utils.d.ts.map +1 -0
  109. package/dist/zone.d.ts +40 -0
  110. package/dist/zone.d.ts.map +1 -0
  111. package/docs/ai/api-reference.md +0 -2
  112. package/docs/reactive/advanced.md +2 -5
  113. package/docs/reactive/collections.md +0 -125
  114. package/docs/reactive/core.md +27 -24
  115. package/docs/reactive/debugging.md +12 -2
  116. package/docs/reactive/project.md +1 -1
  117. package/docs/reactive/scan.md +78 -0
  118. package/docs/reactive.md +2 -1
  119. package/docs/std-decorators.md +69 -0
  120. package/docs/zone.md +95 -0
  121. package/package.json +67 -23
  122. package/src/async/browser.ts +319 -0
  123. package/src/async/index.ts +23 -0
  124. package/src/async/node.ts +104 -0
  125. package/src/decorator.ts +5 -1
  126. package/src/destroyable.ts +1 -1
  127. package/src/entry-browser.ts +5 -0
  128. package/src/entry-node.ts +5 -0
  129. package/src/index.d.ts +12 -9
  130. package/src/index.ts +23 -14
  131. package/src/indexable.ts +42 -0
  132. package/src/mixins.ts +2 -2
  133. package/src/reactive/array.ts +274 -179
  134. package/src/reactive/buffer.ts +168 -0
  135. package/src/reactive/change.ts +2 -2
  136. package/src/reactive/effect-context.ts +15 -91
  137. package/src/reactive/effects.ts +119 -179
  138. package/src/reactive/index.ts +11 -13
  139. package/src/reactive/interface.ts +19 -33
  140. package/src/reactive/map.ts +49 -62
  141. package/src/reactive/memoize.ts +19 -9
  142. package/src/reactive/project.ts +43 -22
  143. package/src/reactive/proxy.ts +16 -41
  144. package/src/reactive/record.ts +3 -3
  145. package/src/reactive/register.ts +5 -7
  146. package/src/reactive/registry.ts +9 -17
  147. package/src/reactive/set.ts +43 -57
  148. package/src/reactive/tracking.ts +1 -29
  149. package/src/reactive/types.ts +46 -23
  150. package/src/utils.ts +80 -37
  151. package/src/zone.ts +138 -0
  152. package/dist/chunks/_tslib-BgjropY9.js +0 -81
  153. package/dist/chunks/_tslib-BgjropY9.js.map +0 -1
  154. package/dist/chunks/_tslib-MCKDzsSq.esm.js +0 -75
  155. package/dist/chunks/_tslib-MCKDzsSq.esm.js.map +0 -1
  156. package/dist/chunks/decorator-BGILvPtN.esm.js +0 -627
  157. package/dist/chunks/decorator-BGILvPtN.esm.js.map +0 -1
  158. package/dist/chunks/decorator-BQ2eBTCj.js +0 -651
  159. package/dist/chunks/decorator-BQ2eBTCj.js.map +0 -1
  160. package/dist/chunks/index-CDCOjzTy.js.map +0 -1
  161. package/dist/chunks/index-DiP0RXoZ.esm.js.map +0 -1
  162. package/dist/decorator.esm.js +0 -2
  163. package/dist/decorator.esm.js.map +0 -1
  164. package/dist/decorator.js +0 -11
  165. package/dist/decorator.js.map +0 -1
  166. package/dist/destroyable.esm.js +0 -109
  167. package/dist/destroyable.esm.js.map +0 -1
  168. package/dist/destroyable.js +0 -116
  169. package/dist/destroyable.js.map +0 -1
  170. package/dist/eventful.esm.js +0 -66
  171. package/dist/eventful.esm.js.map +0 -1
  172. package/dist/eventful.js +0 -68
  173. package/dist/eventful.js.map +0 -1
  174. package/dist/index.esm.js +0 -53
  175. package/dist/index.esm.js.map +0 -1
  176. package/dist/index.js +0 -139
  177. package/dist/index.js.map +0 -1
  178. package/dist/indexable.esm.js +0 -285
  179. package/dist/indexable.esm.js.map +0 -1
  180. package/dist/indexable.js +0 -291
  181. package/dist/indexable.js.map +0 -1
  182. package/dist/promiseChain.esm.js +0 -78
  183. package/dist/promiseChain.esm.js.map +0 -1
  184. package/dist/promiseChain.js +0 -80
  185. package/dist/promiseChain.js.map +0 -1
  186. package/dist/reactive.d.ts +0 -910
  187. package/dist/reactive.esm.js +0 -5
  188. package/dist/reactive.esm.js.map +0 -1
  189. package/dist/reactive.js +0 -59
  190. package/dist/reactive.js.map +0 -1
  191. package/dist/std-decorators.esm.js +0 -196
  192. package/dist/std-decorators.esm.js.map +0 -1
  193. package/dist/std-decorators.js +0 -204
  194. package/dist/std-decorators.js.map +0 -1
  195. package/src/reactive/mapped.ts +0 -129
  196. package/src/reactive/zone.ts +0 -208
@@ -1 +1 @@
1
- {"version":3,"file":"mutts.umd.min.js","sources":["../src/reactive/types.ts","../src/utils.ts","../src/decorator.ts","../src/destroyable.ts","../src/eventful.ts","../src/indexable.ts","../src/iterableWeak.ts","../src/mixins.ts","../src/reactive/registry.ts","../src/reactive/debug.ts","../src/reactive/effect-context.ts","../src/reactive/proxy-state.ts","../src/reactive/tracking.ts","../src/reactive/zone.ts","../src/reactive/effects.ts","../src/reactive/deep-watch-state.ts","../src/reactive/change.ts","../src/reactive/non-reactive-state.ts","../src/reactive/deep-touch.ts","../src/reactive/proxy.ts","../src/reactive/deep-watch.ts","../src/reactive/interface.ts","../src/reactive/non-reactive.ts","../src/reactive/array.ts","../src/reactive/mapped.ts","../src/reactive/memoize.ts","../src/reactive/register.ts","../src/reactive/project.ts","../src/reactive/record.ts","../src/reactive/map.ts","../src/reactive/set.ts","../src/reactive/index.ts","../src/std-decorators.ts","../src/index.ts"],"sourcesContent":["// biome-ignore-all lint/suspicious/noConfusingVoidType: Type 'void' is not assignable to type 'ScopedCallback | undefined'.\n// Argument of type '() => void' is not assignable to parameter of type '(dep: DependencyFunction) => ScopedCallback | undefined'.\n\n/**\n * Function type for dependency tracking in effects\n * Restores the active effect context for dependency tracking\n */\nexport type DependencyFunction = <T>(cb: () => T) => T\n/**\n * Dependency access passed to user callbacks within effects/watch\n * Provides functions to track dependencies and information about the effect execution\n */\nexport interface DependencyAccess {\n\t// TODO: remove tracked (async is managed)\n\t// TODO: remove ascend (make a global like `untracked` who withEffect(parentEffect, () => {}))\n\t/**\n\t * Tracks dependencies in the current effect context\n\t * Use this for normal dependency tracking within the effect\n\t * @example\n\t * ```typescript\n\t * effect(({ tracked }) => {\n\t * // In async context, use tracked to restore dependency tracking\n\t * await someAsyncOperation()\n\t * const value = tracked(() => state.count) // Tracks state.count in this effect\n\t * })\n\t * ```\n\t */\n\ttracked: DependencyFunction\n\t/**\n\t * Tracks dependencies in the parent effect context\n\t * Use this when child effects should track dependencies in the parent,\n\t * allowing parent cleanup to manage child effects while dependencies trigger the parent\n\t * @example\n\t * ```typescript\n\t * effect(({ ascend }) => {\n\t * const length = inputs.length\n\t * if (length > 0) {\n\t * ascend(() => {\n\t * // Dependencies here are tracked in the parent effect\n\t * inputs.forEach(item => console.log(item))\n\t * })\n\t * }\n\t * })\n\t * ```\n\t */\n\tascend: DependencyFunction\n\t/**\n\t * Indicates whether the effect is running as a reaction (i.e. not the first call)\n\t * - `false`: First execution when the effect is created\n\t * - `true`: Subsequent executions triggered by dependency changes\n\t * @example\n\t * ```typescript\n\t * effect(({ reaction }) => {\n\t * if (!reaction) {\n\t * console.log('Effect initialized')\n\t * // Setup code that should only run once\n\t * } else {\n\t * console.log('Effect re-ran due to dependency change')\n\t * // Code that runs on every update\n\t * }\n\t * })\n\t * ```\n\t */\n\treaction: boolean\n}\n// Zone-based async context preservation is implemented in zone.ts\n// It automatically preserves effect context across Promise boundaries (.then, .catch, .finally)\n\n/**\n * Type for effect cleanup functions\n */\nexport type ScopedCallback = () => void\n\n/**\n * Async execution mode for effects\n * - `cancel`: Cancel previous async execution when dependencies change (default)\n * - `queue`: Queue next execution to run after current completes\n * - `ignore`: Ignore new executions while async work is running\n */\nexport type AsyncExecutionMode = 'cancel' | 'queue' | 'ignore'\n\n/**\n * Options for effect creation\n */\nexport interface EffectOptions {\n\t/**\n\t * How to handle async effect executions when dependencies change\n\t * @default 'cancel'\n\t */\n\tasyncMode?: AsyncExecutionMode\n\t/**\n\t * If true, this effect is \"opaque\" to deep optimizations: it sees the object reference itself\n\t * and must be notified when it changes, regardless of deep content similarity.\n\t * Use this for effects that depend on object identity (like memoize).\n\t */\n\topaque?: boolean\n}\n\n/**\n * Type for property evolution events\n */\nexport type PropEvolution = {\n\ttype: 'set' | 'del' | 'add' | 'invalidate'\n\tprop: any\n}\n\n/**\n * Type for collection operation evolution events\n */\nexport type BunchEvolution = {\n\ttype: 'bunch'\n\tmethod: string\n}\nexport type Evolution = PropEvolution | BunchEvolution\n\ntype State =\n\t| {\n\t\t\tevolution: Evolution\n\t\t\tnext: State\n\t }\n\t| {}\n\n// Track native reactivity\nconst nativeReactive = Symbol('native-reactive')\n\n/**\n * Symbol to mark individual objects as non-reactive\n */\nexport const nonReactiveMark = Symbol('non-reactive')\n/**\n * Symbol to mark class properties as non-reactive\n */\nexport const unreactiveProperties = Symbol('unreactive-properties')\n/**\n * Symbol for prototype forwarding in reactive objects\n */\nexport const prototypeForwarding: unique symbol = Symbol('prototype-forwarding')\n\n/**\n * Symbol representing all properties in reactive tracking\n */\nexport const allProps = Symbol('all-props')\n\n/**\n * Symbol for accessing projection information on reactive objects\n */\nexport const projectionInfo = Symbol('projection-info')\n\n/**\n * Symbol to check if an effect is stopped\n */\nexport const stopped = Symbol('stopped')\n\n/**\n * Symbol to access effect cleanup function\n */\nexport const cleanup = Symbol('cleanup')\n\n/**\n * Context for a running projection item effect\n */\nexport interface ProjectionContext {\n\tsource: any\n\tkey?: any\n\ttarget: any\n\tdepth: number\n\tparent?: ProjectionContext\n}\n\n// Symbol to mark functions with their root function\nconst rootFunction = Symbol('root-function')\n\n/**\n * Structured error codes for machine-readable diagnosis\n */\nexport enum ReactiveErrorCode {\n\tCycleDetected = 'CYCLE_DETECTED',\n\tMaxDepthExceeded = 'MAX_DEPTH_EXCEEDED',\n\tMaxReactionExceeded = 'MAX_REACTION_EXCEEDED',\n\tWriteInComputed = 'WRITE_IN_COMPUTED',\n\tTrackingError = 'TRACKING_ERROR',\n}\n\nexport type CycleDebugInfo = {\n\tcode: ReactiveErrorCode.CycleDetected\n\tcycle: string[]\n\tdetails?: string\n}\n\nexport type MaxDepthDebugInfo = {\n\tcode: ReactiveErrorCode.MaxDepthExceeded\n\tdepth: number\n\tchain: string[]\n}\n\nexport type MaxReactionDebugInfo = {\n\tcode: ReactiveErrorCode.MaxReactionExceeded\n\tcount: number\n\teffect: string\n}\n\nexport type GenericDebugInfo = {\n\tcode: ReactiveErrorCode\n\tcausalChain?: string[]\n\tcreationStack?: string\n\t[key: string]: any\n}\n\nexport type ReactiveDebugInfo =\n\t| CycleDebugInfo\n\t| MaxDepthDebugInfo\n\t| MaxReactionDebugInfo\n\t| GenericDebugInfo\n\n/**\n * Error class for reactive system errors\n */\nexport class ReactiveError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic debugInfo?: ReactiveDebugInfo\n\t) {\n\t\tsuper(message)\n\t\tthis.name = 'ReactiveError'\n\t}\n}\n\n// biome-ignore-start lint/correctness/noUnusedFunctionParameters: Interface declaration with empty defaults\n/**\n * Global options for the reactive system\n */\nexport const options = {\n\t/**\n\t * Debug purpose: called when an effect is entered\n\t * @param effect - The effect that is entered\n\t */\n\tenter: (_effect: Function) => {},\n\t/**\n\t * Debug purpose: called when an effect is left\n\t * @param effect - The effect that is left\n\t */\n\tleave: (_effect: Function) => {},\n\t/**\n\t * Debug purpose: called when an effect is chained\n\t * @param target - The effect that is being triggered\n\t * @param caller - The effect that is calling the target\n\t */\n\tchain: (_targets: Function[], _caller?: Function) => {},\n\t/**\n\t * Debug purpose: called when an effect chain is started\n\t * @param target - The effect that is being triggered\n\t */\n\tbeginChain: (_targets: Function[]) => {},\n\t/**\n\t * Debug purpose: called when an effect chain is ended\n\t */\n\tendChain: () => {},\n\tgarbageCollected: (_fn: Function) => {},\n\t/**\n\t * Debug purpose: called when an object is touched\n\t * @param obj - The object that is touched\n\t * @param evolution - The type of change\n\t * @param props - The properties that changed\n\t * @param deps - The dependencies that changed\n\t */\n\ttouched: (_obj: any, _evolution: Evolution, _props?: any[], _deps?: Set<ScopedCallback>) => {},\n\t/**\n\t * Debug purpose: called when an effect is skipped because it's already running\n\t * @param effect - The effect that is already running\n\t * @param runningChain - The array of effects from the detected one to the currently running one\n\t */\n\tskipRunningEffect: (_effect: ScopedCallback, _runningChain: ScopedCallback[]) => {},\n\t/**\n\t * Debug purpose: maximum effect chain (like call stack max depth)\n\t * Used to prevent infinite loops\n\t * @default 100\n\t */\n\tmaxEffectChain: 100,\n\t/**\n\t * Maximum number of times an effect can be triggered by the same cause in a single batch\n\t * Used to detect aggressive re-computation or infinite loops\n\t * @default 10\n\t */\n\tmaxTriggerPerBatch: 10,\n\t/**\n\t * Debug purpose: maximum effect reaction (like call stack max depth)\n\t * Used to prevent infinite loops\n\t * @default 'throw'\n\t */\n\tmaxEffectReaction: 'throw' as 'throw' | 'debug' | 'warn',\n\t/**\n\t * Callback called when a memoization discrepancy is detected (debug only)\n\t * When defined, memoized functions will run a second time (untracked) to verify consistency.\n\t * If the untracked run returns a different value than the cached one, this callback is triggered.\n\t * \n\t * This is the primary tool for detecting missing reactive dependencies in computed values.\n\t * \n\t * @param cached - The value currently in the memoization cache\n\t * @param fresh - The value obtained by re-running the function untracked\n\t * @param fn - The memoized function itself\n\t * @param args - Arguments passed to the function\n\t * \n\t * @example\n\t * ```typescript\n\t * reactiveOptions.onMemoizationDiscrepancy = (cached, fresh, fn, args) => {\n\t * throw new Error(`Memoization discrepancy in ${fn.name}!`);\n\t * };\n\t * ```\n\t */\n\tonMemoizationDiscrepancy: undefined as\n\t\t| ((cached: any, fresh: any, fn: Function, args: any[], cause: \"calculation\" | \"comparison\") => void)\n\t\t| undefined,\n\t/**\n\t * How to handle cycles detected in effect batches\n\t * - 'throw': Throw an error with cycle information (default, recommended for development)\n\t * - 'warn': Log a warning and break the cycle by executing one effect\n\t * - 'break': Silently break the cycle by executing one effect (recommended for production)\n\t * - 'strict': Prevent cycle creation by checking graph before execution (throws error)\n\t * @default 'throw'\n\t */\n\tcycleHandling: 'throw' as 'throw' | 'warn' | 'break' | 'strict',\n\t/**\n\t * Internal flag used by memoization discrepancy detector to avoid counting calls in tests\n\t * @warning Do not modify this flag manually, this flag is given by the engine\n\t */\n\tisVerificationRun: false,\n\t/**\n\t * Maximum depth for deep watching traversal\n\t * Used to prevent infinite recursion in circular references\n\t * @default 100\n\t */\n\tmaxDeepWatchDepth: 100,\n\t/**\n\t * Only react on instance members modification (not inherited properties)\n\t * For instance, do not track class methods\n\t * @default true\n\t */\n\tinstanceMembers: true,\n\t/**\n\t * Ignore accessors (getters and setters) and only track direct properties\n\t * @default true\n\t */\n\tignoreAccessors: true,\n\t/**\n\t * Enable recursive touching when objects with the same prototype are replaced\n\t * When enabled, replacing an object with another of the same prototype triggers\n\t * recursive diffing instead of notifying parent effects\n\t * @default true\n\t */\n\trecursiveTouching: true,\n\t/**\n\t * Default async execution mode for effects that return Promises\n\t * - 'cancel': Cancel previous async execution when dependencies change (default, enables async zone)\n\t * - 'queue': Queue next execution to run after current completes (enables async zone)\n\t * - 'ignore': Ignore new executions while async work is running (enables async zone)\n\t * - false: Disable async zone and async mode handling (effects run concurrently)\n\t *\n\t * **When truthy:** Enables async zone (Promise.prototype wrapping) for automatic context\n\t * preservation in Promise callbacks. Warning: This modifies Promise.prototype globally.\n\t * Only enable if no other library modifies Promise.prototype.\n\t *\n\t * **When false:** Async zone is disabled. Use `tracked()` manually in Promise callbacks.\n\t *\n\t * Can be overridden per-effect via EffectOptions\n\t * @default 'cancel'\n\t */\n\tasyncMode: 'cancel' as AsyncExecutionMode | false,\n\t// biome-ignore lint/suspicious/noConsole: This is the whole point here\n\twarn: (...args: any[]) => console.warn(...args),\n\n\t/**\n\t * Configuration for the introspection system\n\t */\n\tintrospection: {\n\t\t/**\n\t\t * Whether to keep a history of mutations for debugging\n\t\t * @default false\n\t\t */\n\t\tenableHistory: false,\n\t\t/**\n\t\t * Number of mutations to keep in history\n\t\t * @default 50\n\t\t */\n\t\thistorySize: 50,\n\t},\n\n\t/**\n\t * Configuration for zone hooks - control which async APIs are hooked\n\t * Each option controls whether the corresponding async API is wrapped to preserve effect context\n\t * Only applies when asyncMode is enabled (truthy)\n\t */\n\tzones: {\n\t\t/**\n\t\t * Hook setTimeout to preserve effect context\n\t\t * @default true\n\t\t */\n\t\tsetTimeout: true,\n\t\t/**\n\t\t * Hook setInterval to preserve effect context\n\t\t * @default true\n\t\t */\n\t\tsetInterval: true,\n\t\t/**\n\t\t * Hook requestAnimationFrame (runs in untracked context when hooked)\n\t\t * @default true\n\t\t */\n\t\trequestAnimationFrame: true,\n\t\t/**\n\t\t * Hook queueMicrotask to preserve effect context\n\t\t * @default true\n\t\t */\n\t\tqueueMicrotask: true,\n\t},\n}\n// biome-ignore-end lint/correctness/noUnusedFunctionParameters: Interface declaration with empty defaults\n\nexport { type State, nativeReactive, rootFunction }\n","import { prototypeForwarding } from './reactive/types'\n\ntype ElementTypes<T extends readonly unknown[]> = {\n\t[K in keyof T]: T[K] extends readonly (infer U)[] ? U : T[K]\n}\n\n/**\n * Combines multiple arrays into an array of tuples, stopping at the shortest array length\n * @param args - Arrays to zip together\n * @returns Array of tuples containing elements from each input array\n */\nexport function zip<T extends (readonly unknown[])[]>(...args: T): ElementTypes<T>[] {\n\tif (!args.length) return []\n\tconst minLength = Math.min(...args.map((arr) => arr.length))\n\tconst result: ElementTypes<T>[] = []\n\n\tfor (let i = 0; i < minLength; i++) {\n\t\tconst tuple = args.map((arr) => arr[i]) as ElementTypes<T>\n\t\tresult.push(tuple)\n\t}\n\n\treturn result\n}\n\n/**\n * Checks if two arrays are strictly equal (shallow comparison)\n * @param a - First value\n * @param b - Second value\n * @returns True if arrays are equal or values are strictly equal\n */\nexport function arrayEquals(a: any, b: any): boolean {\n\tif (a === b) return true\n\tif (!Array.isArray(a) || !Array.isArray(b)) return false\n\tif (a.length !== b.length) return false\n\tfor (let i = 0; i < a.length; i++) {\n\t\tif (a[i] !== b[i]) return false\n\t}\n\treturn true\n}\n\nconst nativeConstructors = new Set<Function>([\n\tObject,\n\tArray,\n\tDate,\n\tFunction,\n\tSet,\n\tMap,\n\tWeakMap,\n\tWeakSet,\n\tPromise,\n\tError,\n\tTypeError,\n\tReferenceError,\n\tSyntaxError,\n\tRangeError,\n\tURIError,\n\tEvalError,\n\tReflect,\n\tProxy,\n\tRegExp,\n\tString,\n\tNumber,\n\tBoolean,\n] as Function[])\n/**\n * Checks if a function is a constructor (class or constructor function)\n * @param fn - The function to check\n * @returns True if the function is a constructor\n */\nexport function isConstructor(fn: Function): boolean {\n\treturn (\n\t\tfn &&\n\t\ttypeof fn === 'function' &&\n\t\t(nativeConstructors.has(fn) || fn.toString?.().startsWith('class '))\n\t)\n}\n\n/**\n * Renames a function with a new name\n * @param fct - The function to rename\n * @param name - The new name for the function\n * @returns The function with the new name\n */\nexport function renamed<F extends Function>(fct: F, name: string): F {\n\treturn Object.defineProperties(fct, {\n\t\tname: {\n\t\t\tvalue: name,\n\t\t},\n\t})\n}\n\nexport function ReflectGet(obj: any, prop: any, receiver: any) {\n\t// Check if Node is available and obj is an instance of Node\n\tif (typeof Node !== 'undefined' && obj instanceof Node) return (obj as any)[prop]\n\treturn Reflect.get(obj, prop, receiver)\n}\n\nexport function ReflectSet(obj: any, prop: any, value: any, receiver: any) {\n\t// Check if Node is available and obj is an instance of Node\n\tif (typeof Node !== 'undefined' && obj instanceof Node) {\n\t\t;(obj as any)[prop] = value\n\t\treturn true\n\t}\n\tif (!(obj instanceof Object) && !Reflect.has(obj, prop)) {\n\t\tObject.defineProperty(obj, prop, {\n\t\t\tvalue,\n\t\t\tconfigurable: true,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t})\n\t\treturn true\n\t}\n\treturn Reflect.set(obj, prop, value, receiver)\n}\n\nexport function isOwnAccessor(obj: any, prop: any) {\n\tconst opd = Object.getOwnPropertyDescriptor(obj, prop)\n\treturn !!(opd?.get || opd?.set)\n}\n\n/**\n * Deeply compares two values.\n * For objects, compares prototypes with === and then own properties recursively.\n * Uses a cache to handle circular references.\n * @param a - First value\n * @param b - Second value\n * @param cache - Map for circular reference protection (internal use)\n * @returns True if values are deeply equal\n */\nexport function deepCompare(a: any, b: any, cache = new Map<object, Set<object>>()): boolean {\n\t// Unwrap mutts proxies if present\n\twhile (a && typeof a === 'object' && prototypeForwarding in a) {\n\t\ta = (a as any)[prototypeForwarding]\n\t}\n\twhile (b && typeof b === 'object' && prototypeForwarding in b) {\n\t\tb = (b as any)[prototypeForwarding]\n\t}\n\n\tif (a === b) return true\n\n\tif (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {\n\t\treturn a === b\n\t}\n\n\t// Prototype check\n\tconst protoA = Object.getPrototypeOf(a)\n\tconst protoB = Object.getPrototypeOf(b)\n\tif (protoA !== protoB) {\n\t\tconsole.warn(`[deepCompare] prototype mismatch:`, { nameA: a?.constructor?.name, nameB: b?.constructor?.name })\n\t\treturn false\n\t}\n\t// Circular reference protection\n\tlet compared = cache.get(a)\n\tif (compared?.has(b)) return true\n\tif (!compared) {\n\t\tcompared = new Set()\n\t\tcache.set(a, compared)\n\t}\n\tcompared.add(b)\n\n\t// Handle specific object types\n\tif (Array.isArray(a)) {\n\t\tif (!Array.isArray(b)) {\n\t\t\tconsole.warn(`[deepCompare] B is not an array`)\n\t\t\treturn false\n\t\t}\n\t\tif (a.length !== b.length) {\n\t\t\tconsole.warn(`[deepCompare] array length mismatch:`, { lenA: a.length, lenB: b.length })\n\t\t\treturn false\n\t\t}\n\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\tif (!deepCompare(a[i], b[i], cache)) {\n\t\t\t\tconsole.warn(`[deepCompare] array element mismatch at index ${i}`)\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\tif (a instanceof Date) {\n\t\tconst match = b instanceof Date && a.getTime() === b.getTime()\n\t\tif (!match) console.warn(`[deepCompare] Date mismatch`)\n\t\treturn match\n\t}\n\tif (a instanceof RegExp) {\n\t\tconst match = b instanceof RegExp && a.toString() === b.toString()\n\t\tif (!match) console.warn(`[deepCompare] RegExp mismatch`)\n\t\treturn match\n\t}\n\tif (a instanceof Set) {\n\t\tif (!(b instanceof Set) || a.size !== b.size) {\n\t\t\tconsole.warn(`[deepCompare] Set size mismatch`)\n\t\t\treturn false\n\t\t}\n\t\tfor (const val of a) {\n\t\t\tlet found = false\n\t\t\tfor (const bVal of b) {\n\t\t\t\tif (deepCompare(val, bVal, cache)) {\n\t\t\t\t\tfound = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!found) {\n\t\t\t\tconsole.warn(`[deepCompare] missing Set element`)\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\tif (a instanceof Map) {\n\t\tif (!(b instanceof Map) || a.size !== b.size) {\n\t\t\tconsole.warn(`[deepCompare] Map size mismatch`)\n\t\t\treturn false\n\t\t}\n\t\tfor (const [key, val] of a) {\n\t\t\tif (!b.has(key)) {\n\t\t\t\tlet foundMatch = false\n\t\t\t\tfor (const [bKey, bVal] of b) {\n\t\t\t\t\tif (deepCompare(key, bKey, cache) && deepCompare(val, bVal, cache)) {\n\t\t\t\t\t\tfoundMatch = true\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!foundMatch) {\n\t\t\t\t\tconsole.warn(`[deepCompare] missing Map key`)\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (!deepCompare(val, b.get(key), cache)) {\n\t\t\t\t\tconsole.warn(`[deepCompare] Map value mismatch for key`)\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\t// Compare own properties\n\tconst keysA = Object.keys(a)\n\tconst keysB = Object.keys(b)\n\tif (keysA.length !== keysB.length) {\n\t\tconsole.warn(`[deepCompare] keys length mismatch:`, { lenA: keysA.length, lenB: keysB.length, keysA, keysB, a, b })\n\t\treturn false\n\t}\n\n\tfor (const key of keysA) {\n\t\tif (!Object.prototype.hasOwnProperty.call(b, key)) {\n\t\t\tconsole.warn(`[deepCompare] missing key ${String(key)} in B`)\n\t\t\treturn false\n\t\t}\n\t\tif (!deepCompare(a[key], b[key], cache)) {\n\t\t\tconsole.warn(`[deepCompare] value mismatch for key ${String(key)}:`, { valA: a[key], valB: b[key] })\n\t\t\treturn false\n\t\t}\n\t}\n\n\treturn true\n}\n","// biome-ignore-all lint/suspicious/noConfusingVoidType: We *love* voids\n// Standardized decorator system that works with both Legacy and Modern decorators\n\nimport { isConstructor } from './utils'\n\n/**\n * Error thrown when decorator operations fail\n */\nexport class DecoratorError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'DecoratorException'\n\t}\n}\n//#region all decorator types\n\n// Used for get/set and method decorators\n/**\n * Legacy property decorator type for methods, getters, and setters\n */\nexport type LegacyPropertyDecorator<T> = (\n\ttarget: T,\n\tname: string | symbol,\n\tdescriptor: PropertyDescriptor\n) => any\n\n/**\n * Legacy class decorator type\n */\nexport type LegacyClassDecorator<T> = (target: T) => any\n\n/**\n * Modern method decorator type\n */\nexport type ModernMethodDecorator<T> = (target: T, context: ClassMethodDecoratorContext) => any\n\n/**\n * Modern getter decorator type\n */\nexport type ModernGetterDecorator<T> = (target: T, context: ClassGetterDecoratorContext) => any\n\n/**\n * Modern setter decorator type\n */\nexport type ModernSetterDecorator<T> = (target: T, context: ClassSetterDecoratorContext) => any\n\n/**\n * Modern accessor decorator type\n */\nexport type ModernAccessorDecorator<T> = (target: T, context: ClassAccessorDecoratorContext) => any\n\n/**\n * Modern class decorator type\n */\nexport type ModernClassDecorator<T> = (target: T, context: ClassDecoratorContext) => any\n\n//#endregion\n\ntype DDMethod<T> = (\n\toriginal: (this: T, ...args: any[]) => any,\n\ttarget: any,\n\tname: PropertyKey\n) => ((this: T, ...args: any[]) => any) | void\n\ntype DDGetter<T> = (original: (this: T) => any, target: any, name: PropertyKey) => ((this: T) => any) | void\n\ntype DDSetter<T> = (\n\toriginal: (this: T, value: any) => void,\n\ttarget: any,\n\tname: PropertyKey\n) => ((this: T, value: any) => void) | void\n\ntype DDClass<T> = <Ctor extends new (...args: any[]) => T = new (...args: any[]) => T>(\n\ttarget: Ctor\n) => Ctor | void\n/**\n * Description object for creating decorators that work with both Legacy and Modern decorator proposals\n */\nexport interface DecoratorDescription<T> {\n\t/** Handler for method decorators */\n\tmethod?: DDMethod<T>\n\t/** Handler for class decorators */\n\tclass?: DDClass<T>\n\t/** Handler for getter decorators */\n\tgetter?: DDGetter<T>\n\t/** Handler for setter decorators */\n\tsetter?: DDSetter<T>\n\t/** Default handler for any decorator type not explicitly defined */\n\tdefault?: (...args: any[]) => any\n}\n\n/**\n * Type for decorators that work with both Legacy and Modern decorator proposals\n * Automatically infers the correct decorator type based on the description\n */\nexport type Decorator<T, Description extends DecoratorDescription<T>> = (Description extends {\n\tmethod: DDMethod<T>\n}\n\t? LegacyPropertyDecorator<T> & ModernMethodDecorator<T>\n\t: unknown) &\n\t(Description extends { class: DDClass<new (...args: any[]) => T> }\n\t\t? LegacyClassDecorator<new (...args: any[]) => T> &\n\t\t\t\tModernClassDecorator<new (...args: any[]) => T>\n\t\t: unknown) &\n\t(Description extends { getter: DDGetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { setter: DDSetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { default: infer Signature } ? Signature : unknown)\n\n/**\n * Factory type for creating decorators that work with both Legacy and Modern decorator proposals\n */\nexport type DecoratorFactory<T> = <Description extends DecoratorDescription<T>>(\n\tdescription: Description\n) => (Description extends { method: DDMethod<T> }\n\t? LegacyPropertyDecorator<T> & ModernMethodDecorator<T>\n\t: unknown) &\n\t(Description extends { class: DDClass<new (...args: any[]) => T> }\n\t\t? LegacyClassDecorator<new (...args: any[]) => T> &\n\t\t\t\tModernClassDecorator<new (...args: any[]) => T>\n\t\t: unknown) &\n\t(Description extends { getter: DDGetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { setter: DDSetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { default: infer Signature } ? Signature : unknown)\n\n/**\n * Creates a decorator that works with Legacy decorator proposals\n * @param description - The decorator description object\n * @returns A decorator function compatible with Legacy decorators\n */\nexport function legacyDecorator<T = any>(description: DecoratorDescription<T>): any {\n\treturn function (\n\t\tthis: any,\n\t\ttarget: any,\n\t\tpropertyKey?: PropertyKey,\n\t\tdescriptor?: PropertyDescriptor,\n\t\t...args: any[]\n\t) {\n\t\tif (propertyKey === undefined) {\n\t\t\tif (isConstructor(target)) {\n\t\t\t\tif (!('class' in description)) throw new Error('Decorator cannot be applied to a class')\n\t\t\t\treturn description.class!(target)\n\t\t\t}\n\t\t} else if (typeof target === 'object' && ['string', 'symbol'].includes(typeof propertyKey)) {\n\t\t\tif (!descriptor) throw new Error('Decorator cannot be applied to a field')\n\t\t\telse if (typeof descriptor === 'object' && 'configurable' in descriptor) {\n\t\t\t\tif ('get' in descriptor || 'set' in descriptor) {\n\t\t\t\t\tif (!('getter' in description || 'setter' in description))\n\t\t\t\t\t\tthrow new Error('Decorator cannot be applied to a getter or setter')\n\t\t\t\t\tif ('getter' in description) {\n\t\t\t\t\t\tconst newGetter = description.getter!(descriptor.get as any, target, propertyKey)\n\t\t\t\t\t\tif (newGetter) descriptor.get = newGetter\n\t\t\t\t\t}\n\t\t\t\t\tif ('setter' in description) {\n\t\t\t\t\t\tconst newSetter = description.setter!(descriptor.set as any, target, propertyKey)\n\t\t\t\t\t\tif (newSetter) descriptor.set = newSetter\n\t\t\t\t\t}\n\t\t\t\t\treturn descriptor\n\t\t\t\t} else if (typeof descriptor.value === 'function') {\n\t\t\t\t\tif (!('method' in description)) throw new Error('Decorator cannot be applied to a method')\n\t\t\t\t\tconst newMethod = description.method!(descriptor.value, target, propertyKey)\n\t\t\t\t\tif (newMethod) descriptor.value = newMethod\n\t\t\t\t\treturn descriptor\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!('default' in description))\n\t\t\tthrow new Error('Decorator do not have a default implementation')\n\t\treturn description.default!.call(this, target, propertyKey, descriptor, ...args)\n\t}\n}\n\n/**\n * Creates a decorator that works with Modern decorator proposals\n * @param description - The decorator description object\n * @returns A decorator function compatible with Modern decorators\n */\nexport function modernDecorator<T = any>(description: DecoratorDescription<T>): any {\n\t/*return function (target: any, context?: DecoratorContext, ...args: any[]) {*/\n\treturn function (this: any, target: any, context?: DecoratorContext, ...args: any[]) {\n\t\tif (!context?.kind || typeof context.kind !== 'string') {\n\t\t\tif (!('default' in description))\n\t\t\t\tthrow new Error('Decorator do not have a default implementation')\n\t\t\treturn description.default!.call(this, target, context, ...args)\n\t\t}\n\t\tswitch (context.kind) {\n\t\t\tcase 'class':\n\t\t\t\tif (!('class' in description)) throw new Error('Decorator cannot be applied to a class')\n\t\t\t\treturn description.class!(target)\n\t\t\tcase 'field':\n\t\t\t\tthrow new Error('Decorator cannot be applied to a field')\n\t\t\tcase 'getter':\n\t\t\t\tif (!('getter' in description)) throw new Error('Decorator cannot be applied to a getter')\n\t\t\t\treturn description.getter!(target, target, context.name)\n\t\t\tcase 'setter':\n\t\t\t\tif (!('setter' in description)) throw new Error('Decorator cannot be applied to a setter')\n\t\t\t\treturn description.setter!(target, target, context.name)\n\t\t\tcase 'method':\n\t\t\t\tif (!('method' in description)) throw new Error('Decorator cannot be applied to a method')\n\t\t\t\treturn description.method!(target, target, context.name)\n\t\t\tcase 'accessor': {\n\t\t\t\tif (!('getter' in description || 'setter' in description))\n\t\t\t\t\tthrow new Error('Decorator cannot be applied to a getter or setter')\n\t\t\t\tconst rv: Partial<ClassAccessorDecoratorResult<any, any>> = {}\n\t\t\t\tif ('getter' in description) {\n\t\t\t\t\tconst newGetter = description.getter!(target.get, target, context.name)\n\t\t\t\t\tif (newGetter) rv.get = newGetter\n\t\t\t\t}\n\t\t\t\tif ('setter' in description) {\n\t\t\t\t\tconst newSetter = description.setter!(target.set, target, context.name)\n\t\t\t\t\tif (newSetter) rv.set = newSetter\n\t\t\t\t}\n\t\t\t\treturn rv\n\t\t\t}\n\t\t\t//return description.accessor?.(target, context.name, target)\n\t\t}\n\t}\n}\n\n/**\n * Detects if the decorator is being called in modern (Modern) or legacy (Legacy) mode\n * based on the arguments passed to the decorator function\n */\nfunction detectDecoratorMode(\n\t_target: any,\n\tcontextOrKey?: any,\n\t_descriptor?: any\n): 'modern' | 'legacy' {\n\t// Modern decorators have a context object as the second parameter\n\t// Legacy decorators have a string/symbol key as the second parameter\n\tif (\n\t\ttypeof contextOrKey === 'object' &&\n\t\tcontextOrKey !== null &&\n\t\ttypeof contextOrKey.kind === 'string'\n\t) {\n\t\treturn 'modern'\n\t}\n\treturn 'legacy'\n}\n\n/**\n * Main decorator factory that automatically detects and works with both Legacy and Modern decorator proposals\n * @param description - The decorator description object\n * @returns A decorator that works in both Legacy and Modern environments\n */\nexport const decorator: DecoratorFactory<any> = (description: DecoratorDescription<any>) => {\n\tconst modern = modernDecorator(description)\n\tconst legacy = legacyDecorator(description)\n\treturn ((target: any, contextOrKey?: any, ...args: any[]) => {\n\t\tconst mode = detectDecoratorMode(target, contextOrKey, args[0])\n\t\treturn mode === 'modern'\n\t\t\t? modern(target, contextOrKey, ...args)\n\t\t\t: legacy(target, contextOrKey, ...args)\n\t}) as any\n}\n\n/**\n * Generic class decorator type that works with both Legacy and Modern decorator proposals\n */\nexport type GenericClassDecorator<T> = LegacyClassDecorator<abstract new (...args: any[]) => T> &\n\tModernClassDecorator<abstract new (...args: any[]) => T>\n","import { decorator } from './decorator'\n\n// Integrated with `using` statement via Symbol.dispose\nconst fr = new FinalizationRegistry<() => void>((f) => f())\n/**\n * Symbol for marking destructor methods\n */\nexport const destructor = Symbol('destructor')\n/**\n * Symbol for accessing allocated values in destroyable objects\n */\nexport const allocatedValues = Symbol('allocated')\n/**\n * Error thrown when attempting to access a destroyed object\n */\nexport class DestructionError extends Error {\n\tstatic throw<_T = void>(msg: string) {\n\t\treturn () => {\n\t\t\tthrow new DestructionError(msg)\n\t\t}\n\t}\n\tconstructor(msg: string) {\n\t\tsuper(`Object is destroyed. ${msg}`)\n\t\tthis.name = 'DestroyedAccessError'\n\t}\n}\nconst destroyedHandler = {\n\t[Symbol.toStringTag]: 'MutTs Destroyable',\n\tget: DestructionError.throw('Cannot access destroyed object'),\n\tset: DestructionError.throw('Cannot access destroyed object'),\n} as const\n\nabstract class AbstractDestroyable<Allocated> {\n\tabstract [destructor](allocated: Allocated): void\n\t[Symbol.dispose](): void {\n\t\tthis[destructor](this as unknown as Allocated)\n\t}\n}\n\ninterface Destructor<Allocated> {\n\tdestructor(allocated: Allocated): void\n}\n\n/**\n * Creates a destroyable class with a base class and destructor object\n * @param base - The base class to extend\n * @param destructorObj - Object containing the destructor method\n * @returns A destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Partial<InstanceType<T>>,\n>(\n\tbase: T,\n\tdestructorObj: Destructor<Allocated>\n): (new (\n\t...args: ConstructorParameters<T>\n) => InstanceType<T> & { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: InstanceType<T>): boolean\n\tisDestroyable(obj: InstanceType<T>): boolean\n}\n\n/**\n * Creates a destroyable class with only a destructor object (no base class)\n * @param destructorObj - Object containing the destructor method\n * @returns A destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<Allocated extends Record<PropertyKey, any> = Record<PropertyKey, any>>(\n\tdestructorObj: Destructor<Allocated>\n): (new () => { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: any): boolean\n\tisDestroyable(obj: any): boolean\n}\n\n/**\n * Creates a destroyable class with a base class (requires [destructor] method)\n * @param base - The base class to extend\n * @returns A destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(\n\tbase: T\n): (new (\n\t...args: ConstructorParameters<T>\n) => AbstractDestroyable<Allocated> & InstanceType<T> & { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: InstanceType<T>): boolean\n\tisDestroyable(obj: InstanceType<T>): boolean\n}\n\n/**\n * Creates an abstract destroyable base class\n * @returns An abstract destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(): abstract new () => (AbstractDestroyable<Allocated> & {\n\t[allocatedValues]: Allocated\n}) & {\n\tdestroy(obj: any): boolean\n\tisDestroyable(obj: any): boolean\n}\n\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(base?: T | Destructor<Allocated>, destructorObj?: Destructor<Allocated>) {\n\tif (base && typeof base !== 'function') {\n\t\tdestructorObj = base as Destructor<Allocated>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\tbase = class { } as T\n\t}\n\n\treturn class Destroyable extends (base as T) {\n\t\tstatic readonly destructors = new WeakMap<any, () => void>()\n\t\tstatic destroy(obj: Destroyable) {\n\t\t\tconst destructor = Destroyable.destructors.get(obj)\n\t\t\tif (!destructor) return false\n\t\t\tfr.unregister(obj[allocatedValues])\n\t\t\tDestroyable.destructors.delete(obj)\n\t\t\tObject.setPrototypeOf(obj, new Proxy({}, destroyedHandler))\n\t\t\t// Clear all own properties\n\t\t\tfor (const key of Object.getOwnPropertyNames(obj)) {\n\t\t\t\tdelete (obj as any)[key]\n\t\t\t}\n\t\t\tdestructor()\n\t\t\treturn true\n\t\t}\n\t\tstatic isDestroyable(obj: Destroyable) {\n\t\t\treturn Destroyable.destructors.has(obj)\n\t\t}\n\n\t\t[forwardProperties]!: PropertyKey[]\n\t\treadonly [allocatedValues]: Allocated\n\t\tconstructor(...args: any[]) {\n\t\t\tsuper(...args)\n\t\t\tconst allocated = {} as Allocated\n\t\t\tthis[allocatedValues] = allocated\n\t\t\t// @ts-expect-error `this` is an AbstractDestroyable\n\t\t\tconst myDestructor = destructorObj?.destructor ?? this[destructor]\n\t\t\tif (!myDestructor) {\n\t\t\t\tthrow new DestructionError('Destructor is not defined')\n\t\t\t}\n\t\t\tfunction destruction() {\n\t\t\t\tmyDestructor(allocated)\n\t\t\t}\n\t\t\tDestroyable.destructors.set(this, destruction)\n\t\t\tfr.register(this, destruction, allocated)\n\t\t}\n\t}\n}\n\nconst forwardProperties = Symbol('forwardProperties')\n/**\n * Decorator that marks properties to be stored in the allocated object and passed to the destructor\n * Use with accessor properties or explicit get/set pairs\n */\nexport const allocated = decorator({\n\tsetter(original, _target, propertyKey) {\n\t\treturn function (value) {\n\t\t\tthis[allocatedValues][propertyKey] = value\n\t\t\treturn original.call(this, value)\n\t\t}\n\t},\n})\n\n/**\n * Registers a callback to be called when an object is garbage collected\n * @param cb - The callback function to execute on garbage collection\n * @returns The object whose reference can be collected\n */\nexport function callOnGC(cb: () => void) {\n\tlet called = false\n\tconst forward = () => {\n\t\tif (called) return\n\t\tcalled = true\n\t\tcb()\n\t}\n\tfr.register(forward, cb, cb)\n\treturn forward\n}\n\n/**\n * Context Manager Protocol for `using` statement integration\n * Provides automatic resource cleanup when used with the `using` statement\n */\nexport interface ContextManager<T = any> {\n\t[Symbol.dispose](): void\n\tvalue?: T\n}\n","/**\n * Base type for event maps - all event handlers must be functions\n */\nexport type EventsBase = Record<string, (...args: any[]) => void>\n/**\n * A type-safe event system that provides a clean API for event handling\n * @template Events - The event map defining event names and their handler signatures\n */\nexport class Eventful<Events extends EventsBase> {\n\treadonly #events = new Map<keyof Events, ((...args: any[]) => void)[]>()\n\treadonly #hooks = [] as ((...args: any[]) => void)[]\n\n\tpublic hook(\n\t\tcb: <EventType extends keyof Events>(\n\t\t\tevent: EventType,\n\t\t\t...args: Parameters<Events[EventType]>\n\t\t) => void\n\t): () => void {\n\t\tif (!this.#hooks.includes(cb)) this.#hooks.push(cb)\n\t\treturn () => {\n\t\t\tthis.#hooks.splice(this.#hooks.indexOf(cb), 1)\n\t\t}\n\t}\n\n\tpublic on(events: Partial<Events>): void\n\tpublic on<EventType extends keyof Events>(event: EventType, cb: Events[EventType]): () => void\n\tpublic on<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): () => void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.on(e, eventOrEvents[e]!)\n\t\t\t}\n\t\t} else if (cb !== undefined) {\n\t\t\tlet callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (!callbacks) {\n\t\t\t\tcallbacks = []\n\t\t\t\tthis.#events.set(eventOrEvents, callbacks)\n\t\t\t}\n\t\t\tcallbacks.push(cb)\n\t\t}\n\t\t// @ts-expect-error Generic case leads to generic case\n\t\treturn () => this.off(eventOrEvents, cb)\n\t}\n\tpublic off(events: Partial<Events>): void\n\tpublic off<EventType extends keyof Events>(event: EventType, cb?: Events[EventType]): void\n\tpublic off<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.off(e, eventOrEvents[e])\n\t\t\t}\n\t\t} else if (cb !== null && cb !== undefined) {\n\t\t\tconst callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (callbacks) {\n\t\t\t\tthis.#events.set(\n\t\t\t\t\teventOrEvents,\n\t\t\t\t\tcallbacks.filter((c) => c !== cb)\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\t// Remove all listeners for this event\n\t\t\tthis.#events.delete(eventOrEvents)\n\t\t}\n\t}\n\tpublic emit<EventType extends keyof Events>(\n\t\tevent: EventType,\n\t\t...args: Parameters<Events[EventType]>\n\t) {\n\t\tconst callbacks = this.#events.get(event)\n\t\tif (callbacks) for (const cb of callbacks) cb.apply(this, args)\n\t\tfor (const cb of this.#hooks) cb.call(this, event, ...args)\n\t}\n}\n","/**\n * Symbol for defining custom getter logic for numeric index access\n */\nexport const getAt = Symbol('getAt')\n/**\n * Symbol for defining custom setter logic for numeric index access\n */\nexport const setAt = Symbol('setAt')\n\ninterface IndexingAt<Items = any> {\n\t[getAt](index: number): Items\n}\n\ninterface Accessor<T, Items> {\n\tget(this: T, index: number): Items\n\tset?(this: T, index: number, value: Items): void\n\tgetLength?(this: T): number\n\tsetLength?(this: T, value: number): void\n}\n\nabstract class AbstractGetAt<Items = any> {\n\tabstract [getAt](index: number): Items\n}\n\n/**\n * Creates an indexable class with a base class and accessor object\n * @param base - The base class to extend\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase: Base,\n\taccessor: Accessor<InstanceType<Base>, Items>\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: Items }\n\n/**\n * Creates an indexable class with only an accessor object (no base class)\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }\n\n/**\n * Creates an indexable class with a base class that has [getAt] method\n * @param base - The base class that implements [getAt] method\n * @returns A class that supports numeric index access using the base class's [getAt] method\n */\nexport function Indexable<Base extends new (...args: any[]) => IndexingAt>(\n\tbase: Base\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }\n\n/**\n * Creates an abstract indexable base class\n * @returns An abstract class that supports numeric index access\n */\nexport function Indexable<Items>(): abstract new (\n\t...args: any[]\n) => AbstractGetAt & { [x: number]: Items }\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase?: Base | Accessor<Base, Items>,\n\taccessor?: Accessor<Base, Items>\n) {\n\tif (base && typeof base !== 'function') {\n\t\taccessor = base as Accessor<Base, Items>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\t//@ts-expect-error\n\t\tbase = class {} as Base\n\t}\n\tif (!accessor) {\n\t\taccessor = {\n\t\t\tget(this: any, index: number) {\n\t\t\t\tif (typeof this[getAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class must have an [getAt] method')\n\t\t\t\t}\n\t\t\t\treturn this[getAt](index)\n\t\t\t},\n\t\t\tset(this: any, index: number, value: Items) {\n\t\t\t\tif (typeof this[setAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t}\n\t\t\t\tthis[setAt](index, value)\n\t\t\t},\n\t\t}\n\t}\n\n\tabstract class Indexable extends (base as Base) {\n\t\t[x: number]: Items\n\t}\n\n\tObject.setPrototypeOf(\n\t\tIndexable.prototype,\n\t\tnew Proxy((base as Base).prototype, {\n\t\t\t//@ts-expect-error\n\t\t\t[Symbol.toStringTag]: 'MutTs Indexable',\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\t\t\t\treturn getter ? getter.call(receiver) : target[prop]\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn accessor.get!.call(receiver, numProp) as Items\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t\tset(target, prop, value, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst setter = Object.getOwnPropertyDescriptor(target, prop)?.set\n\t\t\t\t\tif (setter) setter.call(receiver, value)\n\t\t\t\t\telse target[prop] = value\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.setLength) {\n\t\t\t\t\t\taccessor.setLength.call(receiver, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\tif (!accessor.set) throw new Error('Indexable class has read-only numeric index access')\n\t\t\t\t\t\taccessor.set!.call(receiver, numProp, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(receiver, prop, {\n\t\t\t\t\tvalue,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t})\n\t)\n\treturn Indexable\n}\n\ntype AtReturnType<T> = T extends { [getAt](index: number): infer R } ? R : never\n\n/**\n * Symbol for accessing the forwarded array in ArrayReadForward\n */\nexport const forwardArray = Symbol('forwardArray')\n\n/**\n * A read-only array forwarder that implements all reading/iterating methods of Array\n * but does not implement modification methods.\n *\n * The constructor takes a callback that returns an array, and all methods forward\n * their behavior to the result of that callback.\n */\nexport class ArrayReadForward<T> {\n\tprotected get [forwardArray](): readonly T[] {\n\t\tthrow new Error('ArrayReadForward is not implemented')\n\t}\n\n\t/**\n\t * Get the length of the array\n\t */\n\tget length(): number {\n\t\treturn this[forwardArray].length\n\t}\n\n\t/**\n\t * Get an element at a specific index\n\t */\n\t[index: number]: T | undefined\n\n\t/**\n\t * Iterator protocol support\n\t */\n\t[Symbol.iterator](): Iterator<T> {\n\t\treturn this[forwardArray][Symbol.iterator]()\n\t}\n\n\t// Reading/Iterating methods\n\n\t/**\n\t * Creates a new array with the results of calling a provided function on every element\n\t */\n\tmap<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[] {\n\t\treturn this[forwardArray].map(callbackfn, thisArg)\n\t}\n\n\t/**\n\t * Creates a new array with all elements that pass the test implemented by the provided function\n\t */\n\tfilter<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S[]\n\tfilter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[]\n\tfilter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[] {\n\t\treturn this[forwardArray].filter(predicate, thisArg)\n\t}\n\n\t/**\n\t * Executes a reducer function on each element of the array, resulting in a single output value\n\t */\n\treduce(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T\n\t): T\n\treduce(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T,\n\t\tinitialValue: T\n\t): T\n\treduce<U>(\n\t\tcallbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U,\n\t\tinitialValue: U\n\t): U\n\treduce(\n\t\tcallbackfn: (\n\t\t\tpreviousValue: any,\n\t\t\tcurrentValue: T,\n\t\t\tcurrentIndex: number,\n\t\t\tarray: readonly T[]\n\t\t) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\treturn initialValue !== undefined\n\t\t\t? this[forwardArray].reduce(callbackfn, initialValue)\n\t\t\t: this[forwardArray].reduce(callbackfn)\n\t}\n\n\t/**\n\t * Executes a reducer function on each element of the array (right-to-left), resulting in a single output value\n\t */\n\treduceRight(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T\n\t): T\n\treduceRight(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T,\n\t\tinitialValue: T\n\t): T\n\treduceRight<U>(\n\t\tcallbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U,\n\t\tinitialValue: U\n\t): U\n\treduceRight(\n\t\tcallbackfn: (\n\t\t\tpreviousValue: any,\n\t\t\tcurrentValue: T,\n\t\t\tcurrentIndex: number,\n\t\t\tarray: readonly T[]\n\t\t) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\treturn initialValue !== undefined\n\t\t\t? this[forwardArray].reduceRight(callbackfn, initialValue)\n\t\t\t: this[forwardArray].reduceRight(callbackfn)\n\t}\n\n\t/**\n\t * Executes a provided function once for each array element\n\t */\n\tforEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void {\n\t\tthis[forwardArray].forEach(callbackfn, thisArg)\n\t}\n\n\t/**\n\t * Returns the value of the first element in the array that satisfies the provided testing function\n\t */\n\tfind<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S | undefined\n\tfind(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined\n\tfind(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined {\n\t\treturn this[forwardArray].find(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the index of the first element in the array that satisfies the provided testing function\n\t */\n\tfindIndex(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): number {\n\t\treturn this[forwardArray].findIndex(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the value of the last element in the array that satisfies the provided testing function\n\t */\n\tfindLast<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S | undefined\n\tfindLast(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined\n\tfindLast(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined {\n\t\treturn this[forwardArray].findLast(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the index of the last element in the array that satisfies the provided testing function\n\t */\n\tfindLastIndex(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): number {\n\t\treturn this[forwardArray].findLastIndex(predicate, thisArg)\n\t}\n\n\t/**\n\t * Determines whether an array includes a certain value among its entries\n\t */\n\tincludes(searchElement: T, fromIndex?: number): boolean {\n\t\treturn this[forwardArray].includes(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns the first index at which a given element can be found in the array\n\t */\n\tindexOf(searchElement: T, fromIndex?: number): number {\n\t\treturn this[forwardArray].indexOf(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns the last index at which a given element can be found in the array\n\t */\n\tlastIndexOf(searchElement: T, fromIndex?: number): number {\n\t\treturn this[forwardArray].lastIndexOf(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns a shallow copy of a portion of an array into a new array object\n\t */\n\tslice(start?: number, end?: number): T[] {\n\t\treturn this[forwardArray].slice(start, end)\n\t}\n\n\t/**\n\t * Returns a new array comprised of this array joined with other array(s) and/or value(s)\n\t */\n\tconcat(...items: ConcatArray<T>[]): T[]\n\tconcat(...items: (T | ConcatArray<T>)[]): T[]\n\tconcat(...items: (T | ConcatArray<T>)[]): T[] {\n\t\treturn this[forwardArray].concat(...items)\n\t}\n\n\t/**\n\t * Tests whether all elements in the array pass the test implemented by the provided function\n\t */\n\tevery(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): boolean {\n\t\treturn this[forwardArray].every(predicate, thisArg)\n\t}\n\n\t/**\n\t * Tests whether at least one element in the array passes the test implemented by the provided function\n\t */\n\tsome(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): boolean {\n\t\treturn this[forwardArray].some(predicate, thisArg)\n\t}\n\n\t/**\n\t * Joins all elements of an array into a string\n\t */\n\tjoin(separator?: string): string {\n\t\treturn this[forwardArray].join(separator)\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the keys for each index in the array\n\t */\n\tkeys(): IterableIterator<number> {\n\t\treturn this[forwardArray].keys()\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the values for each index in the array\n\t */\n\tvalues(): IterableIterator<T> {\n\t\treturn this[forwardArray].values()\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the key/value pairs for each index in the array\n\t */\n\tentries(): IterableIterator<[number, T]> {\n\t\treturn this[forwardArray].entries()\n\t}\n\n\t/**\n\t * Returns a string representation of the array\n\t */\n\ttoString(): string {\n\t\treturn this[forwardArray].toString()\n\t}\n\n\t/**\n\t * Returns a localized string representing the array\n\t */\n\ttoLocaleString(\n\t\tlocales?: string | string[],\n\t\toptions?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions\n\t): string {\n\t\treturn this[forwardArray].toLocaleString(locales as string | string[], options)\n\t}\n\n\t/**\n\t * Returns the element at the specified index, or undefined if the index is out of bounds\n\t */\n\tat(index: number): T | undefined {\n\t\treturn this[forwardArray].at(index)\n\t}\n\n\t/**\n\t * Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth\n\t */\n\tflat(depth?: number): T[] {\n\t\treturn this[forwardArray].flat(depth) as T[]\n\t}\n\n\t/**\n\t * Returns a new array formed by applying a given callback function to each element of the array,\n\t * and then flattening the result by one level\n\t */\n\tflatMap<U, This = undefined>(\n\t\tcallback: (this: This, value: T, index: number, array: readonly T[]) => U | ReadonlyArray<U>,\n\t\tthisArg?: This\n\t): U[] {\n\t\treturn this[forwardArray].flatMap(callback as any, thisArg)\n\t}\n\n\t/**\n\t * Returns a new array with elements in reversed order (ES2023)\n\t */\n\ttoReversed(): T[] {\n\t\treturn this[forwardArray].toReversed?.() ?? [...this[forwardArray]].reverse()\n\t}\n\n\t/**\n\t * Returns a new array with elements sorted (ES2023)\n\t */\n\ttoSorted(compareFn?: ((a: T, b: T) => number) | undefined): T[] {\n\t\treturn this[forwardArray].toSorted?.(compareFn) ?? [...this[forwardArray]].sort(compareFn)\n\t}\n\n\t/**\n\t * Returns a new array with some elements removed and/or replaced at a given index (ES2023)\n\t */\n\ttoSpliced(start: number, deleteCount?: number, ...items: T[]): T[] {\n\t\tif (deleteCount === undefined) return this[forwardArray].toSpliced(start)\n\t\treturn this[forwardArray].toSpliced(start, deleteCount, ...items)\n\t}\n\n\t/**\n\t * Returns a new array with the element at the given index replaced with the given value (ES2023)\n\t */\n\twith(index: number, value: T): T[] {\n\t\treturn this[forwardArray].with(index, value)\n\t}\n\tget [Symbol.unscopables]() {\n\t\treturn this[forwardArray][Symbol.unscopables]\n\t}\n}\n","/// <reference lib=\"esnext.collection\" />\n\n/**\n * Uses weak references but still may iterate through them\n * Note: The behavior is highly dependant on the garbage collector - some entries are perhaps deemed to be collected: don't resuscitate them\n */\nexport class IterableWeakMap<K extends WeakKey, V> implements Map<K, V> {\n\tprivate uuids = new WeakMap<K, string>()\n\tprivate refs: Record<string, [WeakRef<K>, any]> = {}\n\tprivate readonly registry: FinalizationRegistry<string>\n\n\tconstructor(entries?: Iterable<[K, V]>) {\n\t\t// Create a FinalizationRegistry to clean up refs when keys are garbage collected\n\t\tthis.registry = new FinalizationRegistry((uuid: string) => {\n\t\t\tdelete this.refs[uuid]\n\t\t})\n\t\tif (entries) for (const [k, v] of entries) this.set(k, v)\n\t}\n\tprivate createIterator<I>(cb: (key: K, value: V) => I): MapIterator<I> {\n\t\tconst { refs } = this\n\t\treturn (function* () {\n\t\t\tfor (const uuid of Object.keys(refs)) {\n\t\t\t\tconst [keyRef, value] = refs[uuid]\n\t\t\t\tconst key = keyRef.deref()\n\t\t\t\tif (key) yield cb(key, value)\n\t\t\t\telse delete refs[uuid]\n\t\t\t}\n\t\t\treturn undefined\n\t\t})()\n\t}\n\tclear(): void {\n\t\t// Unregister all keys from the FinalizationRegistry\n\t\tfor (const uuid of Object.keys(this.refs)) {\n\t\t\tconst key = this.refs[uuid][0].deref()\n\t\t\tif (key) this.registry.unregister(key)\n\t\t}\n\t\tthis.uuids = new WeakMap<K, string>()\n\t\tthis.refs = {}\n\t}\n\tdelete(key: K): boolean {\n\t\tconst uuid = this.uuids.get(key)\n\t\tif (!uuid) return false\n\t\tdelete this.refs[uuid]\n\t\tthis.uuids.delete(key)\n\t\tthis.registry.unregister(key)\n\t\treturn true\n\t}\n\tforEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void {\n\t\tfor (const [k, v] of this) callbackfn.call(thisArg ?? this, v, k, thisArg ?? this)\n\t}\n\tget(key: K): V | undefined {\n\t\tconst uuid = this.uuids.get(key)\n\t\tif (!uuid) return undefined\n\t\treturn this.refs[uuid][1]\n\t}\n\thas(key: K): boolean {\n\t\treturn this.uuids.has(key)\n\t}\n\tset(key: K, value: V): this {\n\t\tlet uuid = this.uuids.get(key)\n\t\tif (uuid) {\n\t\t\tthis.refs[uuid][1] = value\n\t\t} else {\n\t\t\tuuid = crypto.randomUUID()\n\t\t\tthis.uuids.set(key, uuid)\n\t\t\tthis.refs[uuid] = [new WeakRef(key), value]\n\t\t\t// Register key for cleanup when garbage collected\n\t\t\tthis.registry.register(key, uuid, key)\n\t\t}\n\t\treturn this\n\t}\n\tget size(): number {\n\t\treturn [...this].length\n\t}\n\tentries(): MapIterator<[K, V]> {\n\t\treturn this.createIterator((key, value) => [key, value] as [K, V])\n\t}\n\tkeys(): MapIterator<K> {\n\t\treturn this.createIterator((key, _value) => key)\n\t}\n\tvalues(): MapIterator<V> {\n\t\treturn this.createIterator((_key, value) => value)\n\t}\n\t[Symbol.iterator](): MapIterator<[K, V]> {\n\t\treturn this.entries()\n\t}\n\treadonly [Symbol.toStringTag]: string = 'IterableWeakMap'\n}\n\n/**\n * Uses weak references but still may iterate through them\n * Note: The behavior is highly dependant on the garbage collector - some entries are perhaps deemed to be collected: don't resuscitate them\n */\nexport class IterableWeakSet<K extends WeakKey> implements Set<K> {\n\tprivate uuids = new WeakMap<K, string>()\n\tprivate refs: Record<string, WeakRef<K>> = {}\n\tprivate readonly registry: FinalizationRegistry<string>\n\n\tconstructor(entries?: Iterable<K>) {\n\t\t// Create a FinalizationRegistry to clean up refs when values are garbage collected\n\t\tthis.registry = new FinalizationRegistry((uuid: string) => {\n\t\t\tdelete this.refs[uuid]\n\t\t})\n\t\tif (entries) for (const k of entries) this.add(k)\n\t}\n\tprivate createIterator<I>(cb: (key: K) => I): MapIterator<I> {\n\t\tconst { refs } = this\n\t\treturn (function* () {\n\t\t\tfor (const uuid of Object.keys(refs)) {\n\t\t\t\tconst key = refs[uuid].deref()\n\t\t\t\tif (key) yield cb(key)\n\t\t\t\telse delete refs[uuid]\n\t\t\t}\n\t\t\treturn undefined\n\t\t})()\n\t}\n\n\tclear(): void {\n\t\t// Unregister all values from the FinalizationRegistry\n\t\tfor (const uuid of Object.keys(this.refs)) {\n\t\t\tconst value = this.refs[uuid].deref()\n\t\t\tif (value) this.registry.unregister(value)\n\t\t}\n\t\tthis.uuids = new WeakMap<K, string>()\n\t\tthis.refs = {}\n\t}\n\n\tadd(value: K): this {\n\t\tlet uuid = this.uuids.get(value)\n\t\tif (!uuid) {\n\t\t\tuuid = crypto.randomUUID()\n\t\t\tthis.uuids.set(value, uuid)\n\t\t\tthis.refs[uuid] = new WeakRef(value)\n\t\t\t// Register value for cleanup when garbage collected\n\t\t\tthis.registry.register(value, uuid, value)\n\t\t}\n\t\treturn this\n\t}\n\tdelete(value: K): boolean {\n\t\tconst uuid = this.uuids.get(value)\n\t\tif (!uuid) return false\n\t\tdelete this.refs[uuid]\n\t\tthis.uuids.delete(value)\n\t\tthis.registry.unregister(value)\n\t\treturn true\n\t}\n\n\tforEach(callbackfn: (value: K, value2: K, set: Set<K>) => void, thisArg?: any): void {\n\t\tfor (const value of this) callbackfn.call(thisArg ?? this, value, value, thisArg ?? this)\n\t}\n\n\thas(value: K): boolean {\n\t\treturn this.uuids.has(value)\n\t}\n\tget size(): number {\n\t\treturn [...this].length\n\t}\n\tentries(): SetIterator<[K, K]> {\n\t\treturn this.createIterator((key) => [key, key] as [K, K])\n\t}\n\tkeys(): SetIterator<K> {\n\t\treturn this.createIterator((key) => key)\n\t}\n\tvalues(): SetIterator<K> {\n\t\treturn this.createIterator((key) => key)\n\t}\n\t[Symbol.iterator](): SetIterator<K> {\n\t\treturn this.keys()\n\t}\n\treadonly [Symbol.toStringTag]: string = 'IterableWeakSet'\n\n\tunion<U>(other: ReadonlySetLike<U>): Set<K | U> {\n\t\tconst others = {\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn other.keys()\n\t\t\t},\n\t\t}\n\t\tconst that = this\n\t\treturn new Set(\n\t\t\t(function* () {\n\t\t\t\tyield* that\n\t\t\t\tfor (const value of others) if (!that.has(<K>(<unknown>value))) yield value\n\t\t\t})()\n\t\t)\n\t}\n\tintersection<U /**/>(other: ReadonlySetLike<U>): Set<K & U> {\n\t\tconst that = this\n\t\treturn new Set(\n\t\t\t(function* () {\n\t\t\t\tfor (const value of that) if (other.has(<U>(<unknown>value))) yield <K & U>value\n\t\t\t})()\n\t\t)\n\t}\n\tdifference<U>(other: ReadonlySetLike<U>): Set<K> {\n\t\tconst that = this\n\t\treturn new Set(\n\t\t\t(function* () {\n\t\t\t\tfor (const value of that) if (!other.has(<U>(<unknown>value))) yield <K>value\n\t\t\t})()\n\t\t)\n\t}\n\tsymmetricDifference<U>(other: ReadonlySetLike<U>): Set<K | U> {\n\t\tconst others = {\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn other.keys()\n\t\t\t},\n\t\t}\n\t\tconst that = this\n\t\treturn new Set(\n\t\t\t(function* () {\n\t\t\t\tfor (const value of that) if (!other.has(<U>(<unknown>value))) yield <K | U>value\n\t\t\t\tfor (const value of others) if (!that.has(<K>(<unknown>value))) yield <K | U>value\n\t\t\t})()\n\t\t)\n\t}\n\tisSubsetOf(other: ReadonlySetLike<unknown>): boolean {\n\t\tfor (const value of this) if (!other.has(value)) return false\n\t\treturn true\n\t}\n\tisSupersetOf(other: ReadonlySetLike<unknown>): boolean {\n\t\tconst others = {\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn other.keys()\n\t\t\t},\n\t\t}\n\t\tfor (const value of others) if (!this.has(<K>value)) return false\n\t\treturn true\n\t}\n\tisDisjointFrom(other: ReadonlySetLike<unknown>): boolean {\n\t\tfor (const value of this) if (other.has(value)) return false\n\t\treturn true\n\t}\n}\n","import { isConstructor, ReflectGet } from './utils'\n\n/**\n * A mixin function that takes a base class and returns a new class with mixed-in functionality\n * @template Mixed - The functionality to be mixed in\n */\nexport type MixinFunction<Mixed> = <Base>(\n\tbase: new (...args: any[]) => Base\n) => new (\n\t...args: any[]\n) => Base & Mixed\n\n/**\n * A mixin class that can be used both as a base class and as a mixin function\n * @template Mixed - The functionality to be mixed in\n */\nexport type MixinClass<Mixed> = new (...args: any[]) => Mixed\n\n/**\n * Creates a mixin that can be used both as a class (extends) and as a function (mixin)\n *\n * This function supports:\n * - Using mixins as base classes: `class MyClass extends MyMixin`\n * - Using mixins as functions: `class MyClass extends MyMixin(SomeBase)`\n * - Composing mixins: `const Composed = MixinA(MixinB)`\n * - Type-safe property inference for all patterns\n *\n * @param mixinFunction - The function that creates the mixin\n * @param unwrapFunction - Optional function to unwrap reactive objects for method calls\n * @returns A mixin that can be used both as a class and as a function\n */\nexport function mixin<MixinFn extends (base: any) => new (...args: any[]) => any>(\n\tmixinFunction: MixinFn,\n\tunwrapFunction?: (obj: any) => any\n): (new (\n\t...args: any[]\n) => InstanceType<ReturnType<MixinFn>>) &\n\t(<Base>(\n\t\tbase: abstract new (...args: any[]) => Base\n\t) => new (\n\t\t...args: any[]\n\t) => InstanceType<ReturnType<MixinFn>> & Base) {\n\t/**\n\t * Cache for mixin results to ensure the same base class always returns the same mixed class\n\t */\n\tconst mixinCache = new WeakMap<new (...args: any[]) => any, new (...args: any[]) => any>()\n\n\t// Apply the mixin to Object as the base class\n\tconst MixedBase = mixinFunction(Object)\n\tmixinCache.set(Object, MixedBase)\n\n\t// Create the proxy that handles both constructor and function calls\n\treturn new Proxy(MixedBase, {\n\t\t// Handle `MixinClass(SomeBase)` - use as mixin function\n\t\tapply(_target, _thisArg, args) {\n\t\t\tif (args.length === 0) {\n\t\t\t\tthrow new Error('Mixin requires a base class')\n\t\t\t}\n\n\t\t\tconst baseClass = args[0]\n\t\t\tif (typeof baseClass !== 'function') {\n\t\t\t\tthrow new Error('Mixin requires a constructor function')\n\t\t\t}\n\n\t\t\t// Check if it's a valid constructor or a mixin\n\t\t\tif (\n\t\t\t\t!isConstructor(baseClass) &&\n\t\t\t\t!(baseClass && typeof baseClass === 'function' && baseClass.prototype)\n\t\t\t) {\n\t\t\t\tthrow new Error('Mixin requires a valid constructor')\n\t\t\t}\n\n\t\t\t// Check cache first\n\t\t\tconst cached = mixinCache.get(baseClass)\n\t\t\tif (cached) {\n\t\t\t\treturn cached\n\t\t\t}\n\n\t\t\tlet usedBase = baseClass\n\t\t\tif (unwrapFunction) {\n\t\t\t\t// Create a proxied base class that handles method unwrapping\n\t\t\t\tconst ProxiedBaseClass = class extends baseClass {}\n\n\t\t\t\t// Proxy the prototype methods to handle unwrapping\n\t\t\t\tconst originalPrototype = baseClass.prototype\n\t\t\t\tconst proxiedPrototype = new Proxy(originalPrototype, {\n\t\t\t\t\tget(target, prop, receiver) {\n\t\t\t\t\t\tconst value = ReflectGet(target, prop, receiver)\n\n\t\t\t\t\t\t// Only wrap methods that are likely to access private fields\n\t\t\t\t\t\t// Skip symbols and special properties that the reactive system needs\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\ttypeof value === 'function' &&\n\t\t\t\t\t\t\ttypeof prop === 'string' &&\n\t\t\t\t\t\t\t!['constructor', 'toString', 'valueOf'].includes(prop)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Return a wrapped version that uses unwrapped context\n\t\t\t\t\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t\t\t\t\t// Use the unwrapping function if provided, otherwise use this\n\t\t\t\t\t\t\t\tconst context = unwrapFunction(this as any)\n\t\t\t\t\t\t\t\treturn value.apply(context, args)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn value\n\t\t\t\t\t},\n\t\t\t\t})\n\n\t\t\t\t// Set the proxied prototype\n\t\t\t\tObject.setPrototypeOf(ProxiedBaseClass.prototype, proxiedPrototype)\n\t\t\t\tusedBase = ProxiedBaseClass\n\t\t\t}\n\n\t\t\t// Create the mixed class using the proxied base class\n\t\t\tconst mixedClass = mixinFunction(usedBase)\n\n\t\t\t// Cache the result\n\t\t\tmixinCache.set(baseClass, mixedClass)\n\n\t\t\treturn mixedClass\n\t\t},\n\t}) as MixinFn & (new (...args: any[]) => InstanceType<ReturnType<MixinFn>>)\n}\n","import { rootFunction, type ScopedCallback } from './types'\n\n// Track which effects are watching which reactive objects for cleanup\nexport const effectToReactiveObjects = new WeakMap<ScopedCallback, Set<object>>()\n\n// Track effects per reactive object and property\nexport const watchers = new WeakMap<object, Map<any, Set<ScopedCallback>>>()\n\n// runEffect -> set<stop>\nexport const effectChildren = new WeakMap<ScopedCallback, Set<ScopedCallback>>()\n\n// Track parent effect relationships for hierarchy traversal (used in deep touch filtering)\nexport const effectParent = new WeakMap<ScopedCallback, ScopedCallback | undefined>()\n\n// Track reverse mapping to ensure unicity: One Root -> One Function\nconst reverseRoots = new WeakMap<any, WeakRef<Function>>()\n\n/**\n * Marks a function with its root function for effect tracking\n * Enforces strict unicity: A root function can only identify ONE function.\n * @param fn - The function to mark\n * @param root - The root function\n * @returns The marked function\n */\nexport function markWithRoot<T extends Function>(fn: T, root: any): T {\t\n\t// Check for collision\n\tconst existingRef = reverseRoots.get(root)\n\tconst existing = existingRef?.deref()\n\t\t\n\tif (existing && existing !== fn) {\n\t\tconst rootName = root.name || 'anonymous'\n\t\tconst existingName = existing.name || 'anonymous'\n\t\tconst fnName = fn.name || 'anonymous'\n\t\tthrow new Error(\n\t\t\t`[reactive] Abusive Shared Root detected: Root '${rootName}' is already identifying function '${existingName}'. ` +\n\t\t\t`Cannot reuse it for '${fnName}'. Shared roots cause lost updates and broken identity logic.`\n\t\t)\n\t}\n\t\n\t// Always update the map so subsequent checks find this one\n\t// (Last writer wins for the check)\n\treverseRoots.set(root, new WeakRef(fn))\n\n\t// Mark fn with the new root\n\treturn Object.defineProperty(fn, rootFunction, {\n\t\tvalue: getRoot(root),\n\t\t\twritable: false,\n\t\t})\n\t}\n\n/**\n * Gets the root function of a function for effect tracking\n * @param fn - The function to get the root of\n * @returns The root function\n */\nexport function getRoot<T extends Function | undefined>(fn: T): T {\n\twhile(fn && rootFunction in fn) fn = fn[rootFunction] as T\n\treturn fn\n}\n\n// Flag to disable dependency tracking for the current active effect (not globally)\nexport const trackingDisabledEffects = new WeakSet<ScopedCallback>()\nexport let globalTrackingDisabled = false\n\nexport function setGlobalTrackingDisabled(value: boolean): void {\n\tglobalTrackingDisabled = value\n}\n","/**\n * Debug utilities for the reactivity system\n * - Captures effect metadata (names, parent relationships)\n * - Records cause → consequence edges with object/prop labels\n * - Provides graph data for tooling (DevTools panel, etc.)\n */\n\nimport { effectParent, effectToReactiveObjects, getRoot } from './registry'\nimport { allProps, type Evolution, options, type ScopedCallback } from './types'\n\nconst EXTERNAL_SOURCE = Symbol('external-source')\ntype SourceEffect = ScopedCallback | typeof EXTERNAL_SOURCE\n\nlet devtoolsEnabled = false\n\n// Registry for debugging (populated lazily when DevTools are enabled)\nconst debugEffectRegistry = new Set<ScopedCallback>()\nconst debugObjectRegistry = new Set<object>()\n\n// Human-friendly names\nconst effectNames = new WeakMap<ScopedCallback, string>()\nconst objectNames = new WeakMap<object, string>()\nlet effectCounter = 0\nlet objectCounter = 0\n\n// Cause/consequence edges aggregated by (source, target, descriptor)\ninterface TriggerRecord {\n\tlabel: string\n\tobject: object\n\tprop: any\n\tevolution: Evolution\n\tcount: number\n\tlastTriggered: number\n}\n\nconst triggerGraph = new Map<SourceEffect, Map<ScopedCallback, Map<string, TriggerRecord>>>()\n\nexport type NodeKind = 'effect' | 'external' | 'state'\nexport type EdgeKind = 'cause' | 'dependency' | 'trigger'\n\nexport interface EffectNode {\n\tid: string\n\tlabel: string\n\ttype: NodeKind\n\tdepth: number\n\tparentId?: string\n\tdebugName?: string\n}\n\nexport interface ObjectNode {\n\tid: string\n\tlabel: string\n\ttype: NodeKind\n\tdebugName?: string\n}\n\nexport interface GraphEdge {\n\tid: string\n\tsource: string\n\ttarget: string\n\ttype: EdgeKind\n\tlabel: string\n\tcount?: number\n}\n\nexport interface ReactivityGraph {\n\tnodes: Array<EffectNode | ObjectNode>\n\tedges: GraphEdge[]\n\tmeta: {\n\t\tgeneratedAt: number\n\t\tdevtoolsEnabled: boolean\n\t}\n}\n\nfunction ensureEffectName(effect: ScopedCallback): string {\n\tlet name = effectNames.get(effect)\n\tif (!name) {\n\t\tconst root = getRoot(effect)\n\t\tname = root?.name?.trim() || `effect_${++effectCounter}`\n\t\teffectNames.set(effect, name)\n\t}\n\treturn name\n}\n\nfunction ensureObjectName(obj: object): string {\n\tlet name = objectNames.get(obj)\n\tif (!name) {\n\t\tconst ctorName = (obj as any)?.constructor?.name\n\t\tconst base = ctorName && ctorName !== 'Object' ? ctorName : 'object'\n\t\tname = `${base}_${++objectCounter}`\n\t\tobjectNames.set(obj, name)\n\t}\n\treturn name\n}\n\nfunction describeProp(obj: object, prop: any): string {\n\tconst objectName = ensureObjectName(obj)\n\tif (prop === allProps) return `${objectName}.*`\n\tif (typeof prop === 'symbol') return `${objectName}.${prop.description ?? prop.toString()}`\n\treturn `${objectName}.${String(prop)}`\n}\n\nfunction addEffectToRegistry(effect: ScopedCallback) {\n\tif (!effect || debugEffectRegistry.has(effect)) return\n\tdebugEffectRegistry.add(effect)\n\tconst deps = effectToReactiveObjects.get(effect)\n\tif (deps) {\n\t\tfor (const obj of deps) {\n\t\t\tdocumentObject(obj)\n\t\t}\n\t}\n}\n\nfunction documentObject(obj: object) {\n\tif (!debugObjectRegistry.has(obj)) {\n\t\tdbRegisterObject(obj)\n\t}\n}\n\nfunction dbRegisterObject(obj: object) {\n\tdebugObjectRegistry.add(obj)\n\tensureObjectName(obj)\n}\n\nfunction ensureParentChains(effects: Set<ScopedCallback>) {\n\tconst queue = Array.from(effects)\n\tfor (let i = 0; i < queue.length; i++) {\n\t\tconst effect = queue[i]\n\t\tconst parent = effectParent.get(effect)\n\t\tif (parent && !effects.has(parent)) {\n\t\t\teffects.add(parent)\n\t\t\tqueue.push(parent)\n\t\t}\n\t}\n}\n\nfunction ensureTriggerContainers(source: SourceEffect) {\n\tlet targetMap = triggerGraph.get(source)\n\tif (!targetMap) {\n\t\ttargetMap = new Map()\n\t\ttriggerGraph.set(source, targetMap)\n\t}\n\treturn targetMap\n}\n\nfunction ensureTriggerRecord(\n\tsource: SourceEffect,\n\ttarget: ScopedCallback,\n\tlabel: string,\n\tobj: object,\n\tprop: any,\n\tevolution: Evolution\n): TriggerRecord {\n\tconst targetMap = ensureTriggerContainers(source)\n\tlet labelMap = targetMap.get(target)\n\tif (!labelMap) {\n\t\tlabelMap = new Map()\n\t\ttargetMap.set(target, labelMap)\n\t}\n\tlet record = labelMap.get(label)\n\tif (!record) {\n\t\trecord = { label, object: obj, prop, evolution, count: 0, lastTriggered: Date.now() }\n\t\tlabelMap.set(label, record)\n\t}\n\treturn record\n}\n\n/**\n * Assign a debug-friendly name to an effect (shown in DevTools)\n */\nexport function setEffectName(effect: ScopedCallback, name: string) {\n\teffectNames.set(effect, name)\n}\n\n/**\n * Assign a debug-friendly name to a reactive object\n */\nexport function setObjectName(obj: object, name: string) {\n\tobjectNames.set(obj, name)\n\tdebugObjectRegistry.add(obj)\n}\n\n/**\n * Register an effect so it appears in the DevTools graph\n */\nexport function registerEffectForDebug(effect: ScopedCallback) {\n\tif (!effect || !devtoolsEnabled) return\n\taddEffectToRegistry(effect)\n}\n\n/**\n * Register a reactive object so it appears in the DevTools graph\n */\nexport function registerObjectForDebug(obj: object) {\n\tif (!devtoolsEnabled) return\n\tdocumentObject(obj)\n}\n\n/**\n * Records a cause → consequence relationship between effects.\n * @param source - The effect performing the write (undefined if external/user input)\n * @param target - The effect that re-ran because of the write\n * @param obj - The reactive object that changed\n * @param prop - The property that changed\n * @param evolution - The type of change (set/add/del/bunch)\n */\nexport function recordTriggerLink(\n\tsource: ScopedCallback | undefined,\n\ttarget: ScopedCallback,\n\tobj: object,\n\tprop: any,\n\tevolution: Evolution\n) {\n\tif (options.introspection.enableHistory) {\n\t\taddToMutationHistory(source, target, obj, prop, evolution)\n\t}\n\tif (!devtoolsEnabled) return\n\taddEffectToRegistry(target)\n\tif (source) addEffectToRegistry(source)\n\tconst descriptor = describeProp(obj, prop)\n\tconst record = ensureTriggerRecord(\n\t\tsource ?? EXTERNAL_SOURCE,\n\t\ttarget,\n\t\tdescriptor,\n\t\tobj,\n\t\tprop,\n\t\tevolution\n\t)\n\trecord.count += 1\n\trecord.lastTriggered = Date.now()\n\tdocumentObject(obj)\n}\n\n/**\n * Traces back the chain of triggers that led to a specific effect\n * @param effect The effect to trace back\n * @param limit Max depth\n */\nexport function getTriggerChain(effect: ScopedCallback, limit = 5): string[] {\n\tconst chain: string[] = []\n\tlet current = effect\n\tfor (let i = 0; i < limit; i++) {\n\t\t// Find who triggered 'current'\n\t\t// We need to reverse search the triggerGraph (source -> target)\n\t\t// This is expensive O(Edges) but okay for error reporting\n\t\tlet foundSource: ScopedCallback | undefined\n\t\tlet foundReason = ''\n\n\t\tsearch: for (const [source, targetMap] of triggerGraph) {\n\t\t\tfor (const [target, labelMap] of targetMap) {\n\t\t\t\tif (target === current) {\n\t\t\t\t\t// Found a source! Use the most recent trigger record\n\t\t\t\t\tlet lastTime = 0\n\t\t\t\t\tfor (const record of labelMap.values()) {\n\t\t\t\t\t\tif (record.lastTriggered > lastTime) {\n\t\t\t\t\t\t\tlastTime = record.lastTriggered\n\t\t\t\t\t\t\tfoundReason = record.label\n\t\t\t\t\t\t\tfoundSource = source === EXTERNAL_SOURCE ? undefined : (source as ScopedCallback)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (foundSource || foundReason) break search\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (foundSource) {\n\t\t\tchain.push(\n\t\t\t\t`${ensureEffectName(foundSource)} -> (${foundReason}) -> ${ensureEffectName(current)}`\n\t\t\t)\n\t\t\tcurrent = foundSource\n\t\t} else if (foundReason) {\n\t\t\tchain.push(`External -> (${foundReason}) -> ${ensureEffectName(current)}`)\n\t\t\tbreak\n\t\t} else {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn chain.reverse()\n}\n\nfunction buildEffectNodes(allEffects: Set<ScopedCallback>) {\n\tconst nodes: EffectNode[] = []\n\tconst nodeByEffect = new Map<ScopedCallback, EffectNode>()\n\n\tconst ordered = Array.from(allEffects)\n\tfor (const effect of ordered) {\n\t\tconst label = ensureEffectName(effect)\n\t\tconst node: EffectNode = {\n\t\t\tid: `effect_${nodes.length}`,\n\t\t\tlabel,\n\t\t\ttype: 'effect',\n\t\t\tdepth: 0,\n\t\t\tdebugName: label,\n\t\t}\n\t\tnodes.push(node)\n\t\tnodeByEffect.set(effect, node)\n\t}\n\n\tconst depthCache = new Map<ScopedCallback, number>()\n\tconst computeDepth = (effect: ScopedCallback | undefined): number => {\n\t\tif (!effect) return 0\n\t\tconst cached = depthCache.get(effect)\n\t\tif (cached !== undefined) return cached\n\t\tconst parent = effectParent.get(effect)\n\t\tconst depth = computeDepth(parent) + (parent ? 1 : 0)\n\t\tdepthCache.set(effect, depth)\n\t\treturn depth\n\t}\n\n\tfor (const [effect, node] of nodeByEffect) {\n\t\tnode.depth = computeDepth(effect)\n\t\tconst parent = effectParent.get(effect)\n\t\tif (parent) {\n\t\t\tconst parentNode = nodeByEffect.get(parent)\n\t\t\tif (parentNode) {\n\t\t\t\tnode.parentId = parentNode.id\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { nodes, nodeByEffect }\n}\n\n/**\n * Builds a graph representing current reactive state (effects, objects, and trigger edges)\n */\nexport function buildReactivityGraph(): ReactivityGraph {\n\tconst nodes: Array<EffectNode | ObjectNode> = []\n\tconst edges: GraphEdge[] = []\n\tconst nodeIds = new Map<ScopedCallback | object | SourceEffect, string>()\n\n\tconst allEffects = new Set<ScopedCallback>(debugEffectRegistry)\n\tensureParentChains(allEffects)\n\tconst { nodes: effectNodes, nodeByEffect } = buildEffectNodes(allEffects)\n\tfor (const node of effectNodes) nodes.push(node)\n\tfor (const [effect, node] of nodeByEffect) {\n\t\tnodeIds.set(effect, node.id)\n\t}\n\n\t// Object nodes (optional, used for dependency inspection)\n\tfor (const obj of debugObjectRegistry) {\n\t\tconst id = `object_${nodes.length}`\n\t\tnodes.push({ id, label: ensureObjectName(obj), type: 'state', debugName: objectNames.get(obj) })\n\t\tnodeIds.set(obj, id)\n\t}\n\n\t// External source node (user/system outside of effects)\n\tif (triggerGraph.has(EXTERNAL_SOURCE)) {\n\t\tconst externalId = `effect_external`\n\t\tnodes.push({ id: externalId, label: 'External', type: 'external', depth: 0 })\n\t\tnodeIds.set(EXTERNAL_SOURCE, externalId)\n\t}\n\n\t// Dependency edges (effect → object)\n\tfor (const effect of allEffects) {\n\t\tconst effectId = nodeIds.get(effect)\n\t\tif (!effectId) continue\n\t\tconst deps = effectToReactiveObjects.get(effect)\n\t\tif (!deps) continue\n\t\tfor (const obj of deps) {\n\t\t\tconst objId = nodeIds.get(obj)\n\t\t\tif (!objId) continue\n\t\t\tedges.push({\n\t\t\t\tid: `${effectId}->${objId}`,\n\t\t\t\tsource: effectId,\n\t\t\t\ttarget: objId,\n\t\t\t\ttype: 'dependency',\n\t\t\t\tlabel: 'depends',\n\t\t\t})\n\t\t}\n\t}\n\n\t// Cause edges (effect/object/prop → effect)\n\tfor (const [source, targetMap] of triggerGraph) {\n\t\tfor (const [targetEffect, labelMap] of targetMap) {\n\t\t\tconst targetId = nodeIds.get(targetEffect)\n\t\t\tif (!targetId) continue\n\t\t\tconst sourceId = nodeIds.get(source)\n\t\t\tif (!sourceId) continue\n\t\t\tfor (const record of labelMap.values()) {\n\t\t\t\tedges.push({\n\t\t\t\t\tid: `${sourceId}->${targetId}:${record.label}`,\n\t\t\t\t\tsource: sourceId,\n\t\t\t\t\ttarget: targetId,\n\t\t\t\t\ttype: 'cause',\n\t\t\t\t\tlabel: record.count > 1 ? `${record.label} (${record.count})` : record.label,\n\t\t\t\t\tcount: record.count,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tnodes,\n\t\tedges,\n\t\tmeta: {\n\t\t\tgeneratedAt: Date.now(),\n\t\t\tdevtoolsEnabled,\n\t\t},\n\t}\n}\n\n/**\n * Enables the DevTools bridge and exposes the debug API on window.\n * Call as early as possible in development builds.\n */\nexport function enableDevTools() {\n\tif (typeof window === 'undefined') return\n\tif (devtoolsEnabled) return\n\tdevtoolsEnabled = true\n\n\t// @ts-expect-error - global window extension\n\twindow.__MUTTS_DEVTOOLS__ = {\n\t\tgetGraph: buildReactivityGraph,\n\t\tsetEffectName,\n\t\tsetObjectName,\n\t\tregisterEffect: registerEffectForDebug,\n\t\tregisterObject: registerObjectForDebug,\n\t}\n}\n\nexport function forceEnableGraphTracking() {\n\tdevtoolsEnabled = true\n}\n\nexport function isDevtoolsEnabled() {\n\treturn devtoolsEnabled\n}\n\n// --- Introspection API ---\n\n/**\n * Returns the raw dependency graph data structure.\n * This is useful for programmatic analysis of the reactive system.\n */\nexport function getDependencyGraph() {\n\treturn {\n\t\tnodes: buildReactivityGraph().nodes,\n\t\tedges: buildReactivityGraph().edges,\n\t}\n}\n\n/**\n * Returns a list of effects that depend on the given object.\n */\nexport function getDependents(obj: object): ScopedCallback[] {\n\tconst dependents: ScopedCallback[] = []\n\t// Scan the trigger graph for effects triggered by this object\n\t// This is O(E) where E is the number of edges, might need optimization for large graphs\n\t// but acceptable for introspection\n\tfor (const [_source, targetMap] of triggerGraph) {\n\t\tfor (const [targetEffect, labelMap] of targetMap) {\n\t\t\tfor (const record of labelMap.values()) {\n\t\t\t\tif (record.object === obj) {\n\t\t\t\t\tdependents.push(targetEffect)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t// Also check direct dependencies (dependency graph)\n\t// We don't have a direct obj -> effect map without walking all effects\n\t// unless we use `watchers` from tracking.ts but that's internal\n\treturn [...new Set(dependents)]\n}\n\n/**\n * Returns a list of objects that the given effect depends on.\n */\nexport function getDependencies(effect: ScopedCallback): object[] {\n\tconst deps = effectToReactiveObjects.get(effect)\n\treturn deps ? Array.from(deps) : []\n}\n\n// --- Mutation History ---\n\nexport interface MutationRecord {\n\tid: number\n\ttimestamp: number\n\tsource: string\n\ttarget: string\n\tobjectName: string\n\tprop: string\n\ttype: string\n}\n\nconst mutationHistory: MutationRecord[] = []\nlet mutationCounter = 0\n\nfunction addToMutationHistory(\n\tsource: ScopedCallback | undefined,\n\ttarget: ScopedCallback,\n\tobj: object,\n\tprop: any,\n\tevolution: Evolution\n) {\n\tconst record: MutationRecord = {\n\t\tid: ++mutationCounter,\n\t\ttimestamp: Date.now(),\n\t\tsource: source ? ensureEffectName(source) : 'External',\n\t\ttarget: ensureEffectName(target),\n\t\tobjectName: ensureObjectName(obj),\n\t\tprop: String(prop),\n\t\ttype: evolution.type,\n\t}\n\n\tmutationHistory.push(record)\n\tif (mutationHistory.length > options.introspection.historySize) {\n\t\tmutationHistory.shift()\n\t}\n}\n\n/**\n * Get the recent mutation history\n */\nexport function getMutationHistory(): MutationRecord[] {\n\treturn [...mutationHistory]\n}\n","import { effectParent, getRoot } from './registry'\nimport { ReactiveError, type ScopedCallback } from './types'\n\n/**\n * Effect context stack for nested tracking (front = active, next = parent)\n */\nconst stack: (ScopedCallback | undefined)[] = []\nexport const effectStack = stack\n\nexport function captureEffectStack() {\n\treturn stack.slice()\n}\nexport function isRunning(effect: ScopedCallback): (ScopedCallback | undefined)[] | false {\n\tconst rootEffect = getRoot(effect)\n\n\t// Check if the effect is directly in the stack\n\tconst rootIndex = stack.indexOf(rootEffect)\n\tif (rootIndex !== -1) {\n\t\treturn stack.slice(0, rootIndex + 1).reverse()\n\t}\n\n\t// Check if any effect in the stack is a descendant of this effect\n\t// (i.e., walk up the parent chain from each stack effect to see if we reach this effect)\n\tfor (let i = 0; i < stack.length; i++) {\n\t\tconst stackEffect = stack[i]\n\t\tlet current: ScopedCallback | undefined = stackEffect\n\t\tconst visited = new WeakSet<ScopedCallback>()\n\t\tconst ancestorChain: ScopedCallback[] = []\n\t\t// TODO: That's perhaps a lot of computations for an `assert`\n\t\t// Walk up the parent chain to find if this effect is an ancestor\n\t\twhile (current && !visited.has(current)) {\n\t\t\tvisited.add(current)\n\t\t\tconst currentRoot = getRoot(current)\n\t\t\tancestorChain.push(currentRoot)\n\t\t\tif (currentRoot === rootEffect) {\n\t\t\t\t// Found a descendant - build the full chain from ancestor to active\n\t\t\t\t// The ancestorChain contains [descendant, parent, ..., ancestor] (walking up)\n\t\t\t\t// We need [ancestor (effect), ..., parent, descendant, ...stack from descendant to active]\n\t\t\t\tconst chainFromAncestor = ancestorChain.reverse() // [ancestor, ..., descendant]\n\t\t\t\t// Prepend the actual effect we're checking (in case current is a wrapper)\n\t\t\t\tif (chainFromAncestor[0] !== rootEffect) {\n\t\t\t\t\tchainFromAncestor.unshift(rootEffect)\n\t\t\t\t}\n\t\t\t\t// Append the rest of the stack from the descendant to the active effect\n\t\t\t\tconst stackFromDescendant = stack.slice(0, i + 1).reverse() // [descendant, ..., active]\n\t\t\t\t// Remove duplicate descendant (it's both at end of chainFromAncestor and start of stackFromDescendant)\n\t\t\t\tif (chainFromAncestor.length > 0 && stackFromDescendant.length > 0) {\n\t\t\t\t\tstackFromDescendant.shift() // Remove duplicate descendant\n\t\t\t\t}\n\t\t\t\treturn [...chainFromAncestor, ...stackFromDescendant]\n\t\t\t}\n\t\t\tcurrent = effectParent.get(current)\n\t\t}\n\t}\n\n\treturn false\n}\nexport function withEffectStack<T>(snapshot: (ScopedCallback | undefined)[], fn: () => T): T {\n\tconst previousStack = stack.slice()\n\tassignStack(snapshot)\n\ttry {\n\t\treturn fn()\n\t} finally {\n\t\tassignStack(previousStack)\n\t}\n}\n\nexport function getActiveEffect() {\n\treturn stack[0]\n}\n\n/**\n * Executes a function with a specific effect context\n * @param effect - The effect to use as context\n * @param fn - The function to execute\n * @param keepParent - Whether to keep the parent effect context\n * @returns The result of the function\n */\nexport function withEffect<T>(effect: ScopedCallback | undefined, fn: () => T): T {\n\n\tif (getRoot(effect) === getRoot(getActiveEffect())) return fn()\n\tstack.unshift(effect)\n\ttry {\n\t\treturn fn()\n\t} finally {\n\t\tconst recoveredEffect = stack.shift()\n\t\tif (recoveredEffect !== effect) throw new ReactiveError('[reactive] Effect stack mismatch')\n\t}\n}\n\nfunction assignStack(values: (ScopedCallback | undefined)[]) {\n\tstack.length = 0\n\tstack.push(...values)\n}\n","export const objectToProxy = new WeakMap<object, object>()\nexport const proxyToObject = new WeakMap<object, object>()\n\nexport function storeProxyRelationship(target: object, proxy: object) {\n\tobjectToProxy.set(target, proxy)\n\tproxyToObject.set(proxy, target)\n}\n\nexport function getExistingProxy<T extends object>(target: T): T | undefined {\n\treturn objectToProxy.get(target) as T | undefined\n}\n\nexport function trackProxyObject(proxy: object, target: object) {\n\tproxyToObject.set(proxy, target)\n}\n\nexport function unwrap<T>(obj: T): T {\n\tlet current = obj\n\twhile (current && typeof current === 'object' && current !== null && proxyToObject.has(current)) {\n\t\tcurrent = proxyToObject.get(current) as T\n\t}\n\treturn current\n}\n\nexport function isReactive(obj: any): boolean {\n\treturn proxyToObject.has(obj)\n}\n","import { getActiveEffect } from './effect-context'\nimport {\n\teffectToReactiveObjects,\n\tgetRoot,\n\tglobalTrackingDisabled,\n\tsetGlobalTrackingDisabled,\n\ttrackingDisabledEffects,\n\twatchers,\n} from './registry'\nimport { unwrap } from './proxy-state'\nimport { allProps, type ScopedCallback } from './types'\n\nexport function getTrackingDisabled(): boolean {\n\tconst active = getActiveEffect()\n\tif (!active) return globalTrackingDisabled\n\treturn trackingDisabledEffects.has(getRoot(active))\n}\n\nexport function setTrackingDisabled(value: boolean): void {\n\tconst active = getActiveEffect()\n\tif (!active) {\n\t\tsetGlobalTrackingDisabled(value)\n\t\treturn\n\t}\n\tconst root = getRoot(active)\n\tif (value) trackingDisabledEffects.add(root)\n\telse trackingDisabledEffects.delete(root)\n}\n\n\n\n/**\n * Marks a property as a dependency of the current effect\n * @param obj - The object containing the property\n * @param prop - The property name (defaults to allProps)\n */\nexport function dependant(obj: any, prop: any = allProps) {\n\tobj = unwrap(obj)\n\tconst currentActiveEffect = getActiveEffect()\n\n\t// Early return if no active effect, tracking disabled, or invalid prop\n\tif (\n\t\t!currentActiveEffect ||\n\t\tgetTrackingDisabled() ||\n\t\t(typeof prop === 'symbol' && prop !== allProps)\n\t)\n\t\treturn\n\n\tregisterDependency(obj, prop, currentActiveEffect)\n}\n\nfunction registerDependency(obj: any, prop: any, currentActiveEffect: ScopedCallback) {\n\tlet objectWatchers = watchers.get(obj)\n\tif (!objectWatchers) {\n\t\tobjectWatchers = new Map<PropertyKey, Set<ScopedCallback>>()\n\t\twatchers.set(obj, objectWatchers)\n\t}\n\tlet deps = objectWatchers.get(prop)\n\tif (!deps) {\n\t\tdeps = new Set<ScopedCallback>()\n\t\tobjectWatchers.set(prop, deps)\n\t}\n\tdeps.add(currentActiveEffect)\n\n\t// Track which reactive objects this effect is watching\n\tconst effectObjects = effectToReactiveObjects.get(currentActiveEffect)\n\tif (effectObjects) {\n\t\teffectObjects.add(obj)\n\t} else {\n\t\teffectToReactiveObjects.set(currentActiveEffect, new Set([obj]))\n\t}\n}\n","/**\n * Zone-like async context preservation for reactive effects\n *\n * Automatically preserves effect context across async boundaries:\n * - Promise methods: .then(), .catch(), .finally()\n * - Timers: setTimeout(), setInterval()\n * - Animation: requestAnimationFrame() (if available) - runs in untracked context\n * - Microtasks: queueMicrotask() (if available)\n *\n * **IMPORTANT:** This module is opt-in via `reactiveOptions.asyncMode` (truthy = enabled, false = disabled).\n * By default, async zone is ENABLED with 'cancel' mode.\n *\n * When disabled (asyncMode = false), use `tracked()` manually in async callbacks.\n * When enabled (asyncMode = 'cancel' | 'queue' | 'ignore'), async entry points are wrapped ONCE.\n */\n\nimport { captureEffectStack, withEffectStack } from './effect-context'\nimport { options, type ScopedCallback } from './types'\n\nlet zoneHooked = false\n\n// Store original Promise methods at module load time (before any wrapping)\n// This ensures we always have the true originals, even if wrapping happens multiple times\nconst originalPromiseThen =\n\tObject.getOwnPropertyDescriptor(Promise.prototype, 'then')?.value || Promise.prototype.then\nconst originalPromiseCatch =\n\tObject.getOwnPropertyDescriptor(Promise.prototype, 'catch')?.value || Promise.prototype.catch\nconst originalPromiseFinally =\n\tObject.getOwnPropertyDescriptor(Promise.prototype, 'finally')?.value || Promise.prototype.finally\n\n// Store original timer functions at module load time\nconst originalSetTimeout = globalThis.setTimeout\nconst originalSetInterval = globalThis.setInterval\nconst originalRequestAnimationFrame =\n\ttypeof globalThis.requestAnimationFrame !== 'undefined'\n\t\t? globalThis.requestAnimationFrame\n\t\t: undefined\nconst originalQueueMicrotask =\n\ttypeof globalThis.queueMicrotask !== 'undefined' ? globalThis.queueMicrotask : undefined\n\n// Store batch function to avoid circular dependency\nlet batchFn: ((cb: () => any, type: 'immediate') => any) | undefined\n\n/**\n * Check the asyncMode option and hook Promise.prototype once if enabled\n * Called lazily on first effect creation\n * asyncMode being truthy enables async zone, false disables it\n *\n * @param batch - Optional batch function injection from effects.ts to avoid circular dependency\n */\nexport function ensureZoneHooked(batch?: (cb: () => any, type: 'immediate') => any) {\n\tif (batch) batchFn = batch\n\tif (zoneHooked || !options.asyncMode) return\n\thookZone()\n\tzoneHooked = true\n}\n\n/**\n * Hook Promise.prototype methods to preserve effect context\n */\nfunction hookZone() {\n\t// biome-ignore lint/suspicious/noThenProperty: Intentional wrapping for zone functionality\n\tPromise.prototype.then = function <T, R1, R2>(\n\t\tthis: Promise<T>,\n\t\tonFulfilled?: ((value: T) => R1 | PromiseLike<R1>) | null,\n\t\tonRejected?: ((reason: any) => R2 | PromiseLike<R2>) | null\n\t): Promise<R1 | R2> {\n\t\tconst capturedStack = captureEffectStack()\n\t\treturn originalPromiseThen.call(\n\t\t\tthis,\n\t\t\twrapCallback(onFulfilled, capturedStack),\n\t\t\twrapCallback(onRejected, capturedStack)\n\t\t)\n\t}\n\n\tPromise.prototype.catch = function <T>(\n\t\tthis: Promise<T>,\n\t\tonRejected?: ((reason: any) => T | PromiseLike<T>) | null\n\t): Promise<T> {\n\t\tconst capturedStack = captureEffectStack()\n\t\treturn originalPromiseCatch.call(this, wrapCallback(onRejected, capturedStack))\n\t}\n\n\tPromise.prototype.finally = function <T>(\n\t\tthis: Promise<T>,\n\t\tonFinally?: (() => void) | null\n\t): Promise<T> {\n\t\tconst capturedStack = captureEffectStack()\n\t\treturn originalPromiseFinally.call(this, wrapCallback(onFinally, capturedStack))\n\t}\n\n\t// Hook setTimeout - preserve original function properties for Node.js compatibility\n\tconst wrappedSetTimeout = (<TArgs extends any[]>(\n\t\tcallback: (...args: TArgs) => void,\n\t\tdelay?: number,\n\t\t...args: TArgs\n\t): ReturnType<typeof originalSetTimeout> => {\n\t\tconst capturedStack = options.zones.setTimeout ? captureEffectStack() : undefined\n\t\treturn originalSetTimeout.apply(globalThis, [\n\t\t\twrapCallback(callback, capturedStack) as (...args: any[]) => void,\n\t\t\tdelay,\n\t\t\t...args,\n\t\t] as any)\n\t}) as typeof originalSetTimeout\n\tObject.assign(wrappedSetTimeout, originalSetTimeout)\n\tglobalThis.setTimeout = wrappedSetTimeout\n\n\t// Hook setInterval - preserve original function properties for Node.js compatibility\n\tconst wrappedSetInterval = (<TArgs extends any[]>(\n\t\tcallback: (...args: TArgs) => void,\n\t\tdelay?: number,\n\t\t...args: TArgs\n\t): ReturnType<typeof originalSetInterval> => {\n\t\tconst capturedStack = options.zones.setInterval ? captureEffectStack() : undefined\n\t\treturn originalSetInterval.apply(globalThis, [\n\t\t\twrapCallback(callback, capturedStack) as (...args: any[]) => void,\n\t\t\tdelay,\n\t\t\t...args,\n\t\t] as any)\n\t}) as typeof originalSetInterval\n\tObject.assign(wrappedSetInterval, originalSetInterval)\n\tglobalThis.setInterval = wrappedSetInterval\n\n\t// Hook requestAnimationFrame if available\n\tif (originalRequestAnimationFrame) {\n\t\tglobalThis.requestAnimationFrame = ((\n\t\t\tcallback: FrameRequestCallback\n\t\t): ReturnType<typeof originalRequestAnimationFrame> => {\n\t\t\tconst capturedStack = options.zones.requestAnimationFrame ? captureEffectStack() : undefined\n\t\t\treturn originalRequestAnimationFrame.call(\n\t\t\t\tglobalThis,\n\t\t\t\twrapCallback(callback as any, capturedStack) as FrameRequestCallback\n\t\t\t)\n\t\t}) as typeof originalRequestAnimationFrame\n\t}\n\n\t// Hook queueMicrotask if available\n\tif (originalQueueMicrotask) {\n\t\tglobalThis.queueMicrotask = ((callback: () => void): void => {\n\t\t\tconst capturedStack = options.zones.queueMicrotask ? captureEffectStack() : undefined\n\t\t\toriginalQueueMicrotask.call(globalThis, wrapCallback(callback, capturedStack) as () => void)\n\t\t}) as typeof originalQueueMicrotask\n\t}\n}\n\n/**\n * Wraps a callback to restore effect context and ensure batching\n */\nfunction wrapCallback<T extends (...args: any[]) => any>(\n\tcallback: T | null | undefined,\n\tcapturedStack: (ScopedCallback | undefined)[] | undefined\n): T | undefined {\n\tif (!callback) return undefined\n\n\t// If no stack to restore and no batch function, direct call (optimization)\n\tif ((!capturedStack || !capturedStack.length) && !batchFn) {\n\t\treturn callback\n\t}\n\n\treturn ((...args: any[]) => {\n\t\tconst execute = () => {\n\t\t\tif (capturedStack?.length) {\n\t\t\t\treturn withEffectStack(capturedStack, () => callback(...args))\n\t\t\t}\n\t\t\treturn callback(...args)\n\t\t}\n\n\t\tif (batchFn) {\n\t\t\treturn batchFn(execute, 'immediate')\n\t\t}\n\t\treturn execute()\n\t}) as T\n}\n\n/**\n * Manually enable/disable the zone (for testing)\n */\nexport function setZoneEnabled(enabled: boolean) {\n\tif (enabled && !zoneHooked) {\n\t\thookZone()\n\t\tzoneHooked = true\n\t} else if (!enabled && zoneHooked) {\n\t\t// Restore original Promise methods\n\t\t// biome-ignore lint/suspicious/noThenProperty: Restoring original methods\n\t\tPromise.prototype.then = originalPromiseThen\n\t\tPromise.prototype.catch = originalPromiseCatch\n\t\tPromise.prototype.finally = originalPromiseFinally\n\n\t\t// Restore original timer functions\n\t\tglobalThis.setTimeout = originalSetTimeout\n\t\tglobalThis.setInterval = originalSetInterval\n\t\tif (originalRequestAnimationFrame) {\n\t\t\tglobalThis.requestAnimationFrame = originalRequestAnimationFrame\n\t\t}\n\t\tif (originalQueueMicrotask) {\n\t\t\tglobalThis.queueMicrotask = originalQueueMicrotask\n\t\t}\n\n\t\tzoneHooked = false\n\t}\n}\n\n/**\n * Check if zone is currently hooked\n */\nexport function isZoneEnabled(): boolean {\n\treturn zoneHooked\n}\n","import { decorator } from '../decorator'\nimport { IterableWeakSet } from '../iterableWeak'\nimport { getTriggerChain, isDevtoolsEnabled, registerEffectForDebug } from './debug'\nimport {\n\tcaptureEffectStack,\n\teffectStack,\n\tgetActiveEffect,\n\twithEffect,\n\twithEffectStack,\n} from './effect-context'\nimport {\n\tgetTrackingDisabled,\n\tsetTrackingDisabled,\n} from './tracking'\nimport {\n\teffectChildren,\n\teffectParent,\n\teffectToReactiveObjects,\n\tgetRoot,\n\tmarkWithRoot,\n\twatchers,\n} from './registry'\nimport {\n\ttype DependencyAccess,\n\ttype EffectOptions,\n\ttype Evolution,\n\toptions,\n\tReactiveError,\n\tReactiveErrorCode,\n\t// type AsyncExecutionMode,\n\ttype ScopedCallback,\n\tcleanup as cleanupSymbol,\n\tstopped,\n} from './types'\n\n/**\n * Finds a cycle in a sequence of functions by looking for the first repetition\n */\nfunction findCycleInChain(roots: Function[]): Function[] | null {\n\tconst seen = new Map<Function, number>()\n\tfor (let i = 0; i < roots.length; i++) {\n\t\tconst root = roots[i]\n\t\tif (seen.has(root)) {\n\t\t\treturn roots.slice(seen.get(root)!)\n\t\t}\n\t\tseen.set(root, i)\n\t}\n\treturn null\n}\n\n/**\n * Formats a list of function roots into a readable trace\n */\nfunction formatRoots(roots: Function[], limit = 20): string {\n\tconst names = roots.map((r) => r.name || '<anonymous>')\n\tif (names.length <= limit) return names.join(' → ')\n\tconst start = names.slice(0, 5)\n\tconst end = names.slice(-10)\n\treturn `${start.join(' → ')} ... (${names.length - 15} more) ... ${end.join(' → ')}`\n}\n\nimport { ensureZoneHooked } from './zone'\n\ntype EffectTracking = (obj: any, evolution: Evolution, prop: any) => void\n\nexport { captureEffectStack, withEffectStack, getActiveEffect, effectStack }\nexport interface ActivationRecord {\n\teffect: ScopedCallback\n\tobj: any\n\tevolution: Evolution\n\tprop: any\n\tbatchId: number\n}\n\n// Nested map structure for efficient counting and batch cleanup\n// batchId -> effect root -> obj -> prop -> count\nlet activationRegistry: Map<Function, Map<any, Map<any, number>>> | undefined\n\nexport const activationLog: Omit<ActivationRecord, 'batchId'>[] = new Array(100)\n\nexport function getActivationLog() {\n\treturn activationLog\n}\n\nexport function recordActivation(\n\teffect: ScopedCallback,\n\tobj: any,\n\tevolution: Evolution,\n\tprop: any\n) {\n\tconst root = getRoot(effect)\n\n\tif (!activationRegistry) return\n\tlet effectData = activationRegistry.get(root)\n\tif (!effectData) {\n\t\teffectData = new Map()\n\t\tactivationRegistry.set(root, effectData)\n\t}\n\tlet objData = effectData.get(obj)\n\tif (!objData) {\n\t\tobjData = new Map()\n\t\teffectData.set(obj, objData)\n\t}\n\tconst count = (objData.get(prop) ?? 0) + 1\n\tobjData.set(prop, count)\n\n\t// Keep a limited history for diagnostics\n\tactivationLog.unshift({\n\t\teffect,\n\t\tobj,\n\t\tevolution,\n\t\tprop,\n\t})\n\tactivationLog.pop()\n\n\tif (count >= options.maxTriggerPerBatch) {\n\t\tconst effectName = (root as any)?.name || 'anonymous'\n\t\tconst message = `Aggressive trigger detected: effect \"${effectName}\" triggered ${count} times in the batch by the same cause.`\n\t\tif (options.maxEffectReaction === 'throw') {\n\t\t\tthrow new ReactiveError(message, {\n\t\t\t\tcode: ReactiveErrorCode.MaxReactionExceeded,\n\t\t\t\tcount,\n\t\t\t\teffect: effectName,\n\t\t\t})\n\t\t}\n\t\toptions.warn(`[reactive] ${message}`)\n\t}\n}\n\n/**\n * Registers a debug callback that is called when the current effect is triggered by a dependency change\n *\n * This function is useful for debugging purposes as it pin-points exactly which reactive property\n * change triggered the effect. The callback receives information about:\n * - The object that changed\n * - The type of change (evolution)\n * - The specific property that changed\n *\n * **Note:** The tracker callback is automatically removed after being called once. If you need\n * to track multiple triggers, call `trackEffect` again within the effect.\n *\n * @param onTouch - Callback function that receives (obj, evolution, prop) when the effect is triggered\n * @throws {Error} If called outside of an effect context\n *\n * @example\n * ```typescript\n * const state = reactive({ count: 0, name: 'John' })\n *\n * effect(() => {\n * // Register a tracker to see what triggers this effect\n * trackEffect((obj, evolution, prop) => {\n * console.log(`Effect triggered by:`, {\n * object: obj,\n * change: evolution.type,\n * property: prop\n * })\n * })\n *\n * // Access reactive properties\n * console.log(state.count, state.name)\n * })\n *\n * state.count = 5\n * // Logs: Effect triggered by: { object: state, change: 'set', property: 'count' }\n * ```\n */\nexport function trackEffect(onTouch: EffectTracking) {\n\tconst activeEffect = getActiveEffect()\n\tif (!activeEffect) throw new Error('Not in an effect')\n\tif (!effectTrackers.has(activeEffect)) effectTrackers.set(activeEffect, new Set([onTouch]))\n\telse effectTrackers.get(activeEffect)!.add(onTouch)\n}\n\nconst effectTrackers = new WeakMap<ScopedCallback, Set<EffectTracking>>()\n\nexport const opaqueEffects = new WeakSet<ScopedCallback>()\n\n// Dependency graph: tracks which effects trigger which other effects\n// Uses roots (Function) as keys for consistency\nconst effectTriggers = new WeakMap<Function, IterableWeakSet<Function>>()\nconst effectTriggeredBy = new WeakMap<Function, IterableWeakSet<Function>>()\n\n// Transitive closures: track all indirect relationships\n// causesClosure: for each effect, all effects that trigger it (directly or indirectly)\n// consequencesClosure: for each effect, all effects that it triggers (directly or indirectly)\nconst causesClosure = new WeakMap<Function, IterableWeakSet<Function>>()\nconst consequencesClosure = new WeakMap<Function, IterableWeakSet<Function>>()\n\n// Debug: Capture where an effect was created\nexport const effectCreationStacks = new WeakMap<Function, string>()\n\n/**\n * Gets or creates an IterableWeakSet for a closure map\n */\nfunction getOrCreateClosure(\n\tclosure: WeakMap<Function, IterableWeakSet<Function>>,\n\troot: Function\n): IterableWeakSet<Function> {\n\tlet set = closure.get(root)\n\tif (!set) {\n\t\tset = new IterableWeakSet()\n\t\tclosure.set(root, set)\n\t}\n\treturn set\n}\n\n/**\n * Adds an edge to the dependency graph: callerRoot → targetRoot\n * Also maintains transitive closures\n * @param callerRoot - Root function of the effect that triggers\n * @param targetRoot - Root function of the effect being triggered\n */\nfunction addGraphEdge(callerRoot: Function, targetRoot: Function) {\n\t// Skip if edge already exists\n\tconst triggers = effectTriggers.get(callerRoot)\n\tif (triggers?.has(targetRoot)) {\n\t\treturn // Edge already exists\n\t}\n\n\t// Add to forward graph: callerRoot → targetRoot\n\tif (!triggers) {\n\t\tconst newTriggers = new IterableWeakSet<Function>()\n\t\tnewTriggers.add(targetRoot)\n\t\teffectTriggers.set(callerRoot, newTriggers)\n\t} else {\n\t\ttriggers.add(targetRoot)\n\t}\n\n\t// Add to reverse graph: targetRoot ← callerRoot\n\tlet triggeredBy = effectTriggeredBy.get(targetRoot)\n\tif (!triggeredBy) {\n\t\ttriggeredBy = new IterableWeakSet()\n\t\teffectTriggeredBy.set(targetRoot, triggeredBy)\n\t}\n\ttriggeredBy.add(callerRoot)\n\n\t// Update transitive closures\n\t// When U→V is added, we need to propagate the relationship:\n\t// 1. Add U to causesClosure(V) and V to consequencesClosure(U) (direct relationship)\n\t// 2. For each X in causesClosure(U): add V to consequencesClosure(X) and X to causesClosure(V)\n\t// 3. For each Y in consequencesClosure(V): add U to causesClosure(Y) and Y to consequencesClosure(U)\n\t// Note: Self-loops (U→U) are not added to closures - if an effect appears in its own closure,\n\t// it means there's an indirect cycle that should be detected\n\n\t// Self-loops are explicitly ignored - an effect reading and writing the same property\n\t// (e.g., obj.prop++) should not create a dependency relationship or appear in closures\n\tif (callerRoot === targetRoot) {\n\t\treturn\n\t}\n\n\tconst uConsequences = getOrCreateClosure(consequencesClosure, callerRoot)\n\tconst vCauses = getOrCreateClosure(causesClosure, targetRoot)\n\n\t// 1. Add direct relationship\n\tuConsequences.add(targetRoot)\n\tvCauses.add(callerRoot)\n\n\t// 2. For each X in causesClosure(U): X→U→V means X→V\n\tconst uCausesSet = causesClosure.get(callerRoot)\n\tif (uCausesSet) {\n\t\tfor (const x of uCausesSet) {\n\t\t\t// Skip if this would create a self-loop\n\t\t\tif (x === targetRoot) continue\n\t\t\tconst xConsequences = getOrCreateClosure(consequencesClosure, x)\n\t\t\txConsequences.add(targetRoot)\n\t\t\tvCauses.add(x)\n\t\t}\n\t}\n\n\t// 3. For each Y in consequencesClosure(V): U→V→Y means U→Y\n\tconst vConsequencesSet = consequencesClosure.get(targetRoot)\n\tif (vConsequencesSet) {\n\t\tfor (const y of vConsequencesSet) {\n\t\t\t// Skip if this would create a self-loop\n\t\t\tif (y === callerRoot) continue\n\t\t\tconst yCauses = getOrCreateClosure(causesClosure, y)\n\t\t\tyCauses.add(callerRoot)\n\t\t\tuConsequences.add(y)\n\t\t}\n\t}\n\n\t// 4. Cross-product: for each X in causesClosure(U) and Y in consequencesClosure(V): X→Y\n\tif (uCausesSet && vConsequencesSet) {\n\t\tfor (const x of uCausesSet) {\n\t\t\tconst xConsequences = getOrCreateClosure(consequencesClosure, x)\n\t\t\tfor (const y of vConsequencesSet) {\n\t\t\t\t// Skip if this would create a self-loop\n\t\t\t\tif (x === y) continue\n\t\t\t\txConsequences.add(y)\n\t\t\t\tconst yCauses = getOrCreateClosure(causesClosure, y)\n\t\t\t\tyCauses.add(x)\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Checks if there's a path from start to end in the dependency graph, excluding a specific node\n * Uses BFS to find any path that doesn't go through the excluded node\n * @param start - Starting node\n * @param end - Target node\n * @param exclude - Node to exclude from the path\n * @returns true if a path exists without going through the excluded node\n * @todo Can be REALLY costly - optimise or make optional or ...\n */\nfunction hasPathExcluding(start: Function, end: Function, exclude: Function): boolean {\n\tif (start === end) return true\n\tif (start === exclude) return false\n\n\tconst visited = new Set<Function>()\n\tconst queue: Function[] = [start]\n\tvisited.add(start)\n\tvisited.add(exclude) // Pre-mark excluded node as visited to skip it\n\n\twhile (queue.length > 0) {\n\t\tconst current = queue.shift()!\n\t\tconst triggers = effectTriggers.get(current)\n\t\tif (!triggers) continue\n\n\t\tfor (const next of triggers) {\n\t\t\tif (next === end) return true\n\t\t\tif (!visited.has(next)) {\n\t\t\t\tvisited.add(next)\n\t\t\t\tqueue.push(next)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn false\n}\n\n/**\n * Removes all edges involving the given effect from the dependency graph\n * Also cleans up transitive closures by propagating cleanup to all affected effects\n * Called when an effect is stopped/cleaned up\n * @param effect - The effect being cleaned up\n */\nfunction cleanupEffectFromGraph(effect: ScopedCallback) {\n\tconst root = getRoot(effect)\n\n\t// Get closures before removing direct edges (needed for propagation)\n\tconst rootCauses = causesClosure.get(root)\n\tconst rootConsequences = consequencesClosure.get(root)\n\n\t// Remove from effectTriggers (outgoing edges)\n\tconst triggers = effectTriggers.get(root)\n\tif (triggers) {\n\t\t// Remove this root from all targets' effectTriggeredBy sets\n\t\tfor (const targetRoot of triggers) {\n\t\t\tconst triggeredBy = effectTriggeredBy.get(targetRoot)\n\t\t\ttriggeredBy?.delete(root)\n\t\t}\n\t\teffectTriggers.delete(root)\n\t}\n\n\t// Remove from effectTriggeredBy (incoming edges)\n\tconst triggeredBy = effectTriggeredBy.get(root)\n\tif (triggeredBy) {\n\t\t// Remove this root from all sources' effectTriggers sets\n\t\tfor (const sourceRoot of triggeredBy) {\n\t\t\tconst triggers = effectTriggers.get(sourceRoot)\n\t\t\ttriggers?.delete(root)\n\t\t}\n\t\teffectTriggeredBy.delete(root)\n\t}\n\n\t// Propagate closure cleanup to all affected effects\n\t// When removing B from A → B → C:\n\t// - Remove B from causesClosure(C) and consequencesClosure(A)\n\t// - For each X in causesClosure(B): remove C from consequencesClosure(X) if B was the only path\n\t// - For each Y in consequencesClosure(B): remove A from causesClosure(Y) if B was the only path\n\t// - Remove transitive relationships that depended on B\n\n\tif (rootCauses) {\n\t\t// For each X that triggers root: remove root from X's consequences\n\t\t// Only remove root's consequences if no alternate path exists\n\t\tfor (const causeRoot of rootCauses) {\n\t\t\tconst causeConsequences = consequencesClosure.get(causeRoot)\n\t\t\tif (causeConsequences) {\n\t\t\t\t// Remove root itself (it's being cleaned up)\n\t\t\t\tcauseConsequences.delete(root)\n\t\t\t\t// Only remove consequences of root if there's no alternate path from causeRoot to them\n\t\t\t\tif (rootConsequences) {\n\t\t\t\t\tfor (const consequence of rootConsequences) {\n\t\t\t\t\t\t// Check if causeRoot can still reach consequence without going through root\n\t\t\t\t\t\tif (!hasPathExcluding(causeRoot, consequence, root)) {\n\t\t\t\t\t\t\tcauseConsequences.delete(consequence)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (rootConsequences) {\n\t\t// For each Y that root triggers: remove root from Y's causes\n\t\t// Only remove root's causes if no alternate path exists\n\t\tfor (const consequenceRoot of rootConsequences) {\n\t\t\tconst consequenceCauses = causesClosure.get(consequenceRoot)\n\t\t\tif (consequenceCauses) {\n\t\t\t\t// Remove root itself (it's being cleaned up)\n\t\t\t\tconsequenceCauses.delete(root)\n\t\t\t\t// Only remove causes of root if there's no alternate path from them to consequenceRoot\n\t\t\t\tif (rootCauses) {\n\t\t\t\t\tfor (const cause of rootCauses) {\n\t\t\t\t\t\t// Check if cause can still reach consequenceRoot without going through root\n\t\t\t\t\t\tif (!hasPathExcluding(cause, consequenceRoot, root)) {\n\t\t\t\t\t\t\tconsequenceCauses.delete(cause)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Cross-product cleanup: for each X in causesClosure(B) and Y in consequencesClosure(B),\n\t// remove X→Y if B was the only path connecting them\n\tif (rootCauses && rootConsequences) {\n\t\tfor (const x of rootCauses) {\n\t\t\tconst xConsequences = consequencesClosure.get(x)\n\t\t\tif (xConsequences) {\n\t\t\t\tfor (const y of rootConsequences) {\n\t\t\t\t\t// Check if there's still a path from X to Y without going through root\n\t\t\t\t\t// Use BFS to find any path that doesn't include root\n\t\t\t\t\tif (!hasPathExcluding(x, y, root)) {\n\t\t\t\t\t\txConsequences.delete(y)\n\t\t\t\t\t\tconst yCauses = causesClosure.get(y)\n\t\t\t\t\t\tyCauses?.delete(x)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Finally, delete the closures for this effect\n\tcausesClosure.delete(root)\n\tconsequencesClosure.delete(root)\n}\n\n// Batch queue structure - optimized with cached in-degrees\ninterface BatchQueue {\n\t// All effects in the current batch that still need to be executed (todos)\n\tall: Map<Function, ScopedCallback> // root → effect\n\t// Cached in-degrees for each effect in the batch (number of causes in batch)\n\tinDegrees: Map<Function, number> // root → in-degree count\n}\n\n// Track currently executing effects to prevent re-execution\n// These are all the effects triggered under `activeEffect`\nlet batchQueue: BatchQueue | undefined\nexport function hasBatched(effect: ScopedCallback) {\n\treturn batchQueue?.all.has(getRoot(effect))\n}\nconst batchCleanups = new Set<ScopedCallback>()\n\n/**\n * Computes and caches in-degrees for all effects in the batch\n * Called once when batch starts or when new effects are added\n */\nfunction computeAllInDegrees(batch: BatchQueue): void {\n\tconst activeEffect = getActiveEffect()\n\tconst activeRoot = activeEffect ? getRoot(activeEffect) : null\n\n\t// Reset all in-degrees\n\tbatch.inDegrees.clear()\n\n\tfor (const [root] of batch.all) {\n\t\tlet inDegree = 0\n\t\tconst causes = causesClosure.get(root)\n\t\tif (causes) {\n\t\t\tfor (const causeRoot of causes) {\n\t\t\t\t// Only count if it's in the batch and not the active/self effect\n\t\t\t\tif (batch.all.has(causeRoot) && causeRoot !== activeRoot && causeRoot !== root) {\n\t\t\t\t\tinDegree++\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tbatch.inDegrees.set(root, inDegree)\n\t}\n}\n\n/**\n * Decrements in-degrees of all effects that depend on the executed effect\n * Called after an effect is executed to update the cached in-degrees\n */\nfunction decrementInDegreesForExecuted(batch: BatchQueue, executedRoot: Function): void {\n\t// Get all effects that this executed effect triggers\n\tconst consequences = consequencesClosure.get(executedRoot)\n\tif (!consequences) return\n\n\tfor (const consequenceRoot of consequences) {\n\t\t// Only update if it's still in the batch\n\t\tif (batch.all.has(consequenceRoot)) {\n\t\t\tconst currentDegree = batch.inDegrees.get(consequenceRoot) ?? 0\n\t\t\tif (currentDegree > 0) {\n\t\t\t\tbatch.inDegrees.set(consequenceRoot, currentDegree - 1)\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Computes the in-degree (number of dependencies) for an effect in the current batch\n * Uses causesClosure to count all effects (directly or indirectly) that trigger this effect\n * @param root - Root function of the effect\n * @param batchEffects - Map of all effects in current batch (todos - effects that still need execution)\n * @returns Number of effects in batch that trigger this effect (directly or indirectly)\n *\n * TODO: Optimization - For large graphs with small batches, iterating over all causes in the closure\n * can be expensive. Consider maintaining a separate \"batch causes\" set or caching in-degrees.\n */\n/* function computeInDegreeInBatch(\n\troot: Function,\n\tbatchEffects: Map<Function, ScopedCallback>\n): number {\n\tlet inDegree = 0\n\tconst activeEffect = getActiveEffect()\n\tconst activeRoot = activeEffect ? getRoot(activeEffect) : null\n\n\t// Count effects in batch that trigger this effect (directly or indirectly)\n\t// Using causesClosure which contains all transitive causes\n\t// Note: batchEffects only contains effects that still need execution (todos),\n\t// so we don't need to check if causes have been executed - they're not in the map if executed\n\tconst causes = causesClosure.get(root)\n\tif (causes) {\n\t\tfor (const causeRoot of causes) {\n\t\t\t// Only count if it's in the batch (still needs execution)\n\t\t\t// BUT: don't count the currently executing effect (active effect)\n\t\t\t// This handles the case where an effect is triggered during another effect's execution\n\t\t\t// Note: Self-loops are ignored - they should not appear in closures, but we check to be safe\n\t\t\tif (batchEffects.has(causeRoot) && causeRoot !== activeRoot && causeRoot !== root) {\n\t\t\t\tinDegree++\n\t\t\t}\n\t\t}\n\t}\n\n\treturn inDegree\n}\n\n/**\n * Finds a path from startRoot to endRoot in the dependency graph\n * Uses DFS to find the path through direct edges\n * @param startRoot - Starting effect root\n * @param endRoot - Target effect root\n * @param visited - Set of visited nodes (for recursion)\n * @param path - Current path being explored\n * @returns Path from startRoot to endRoot, or empty array if no path exists\n */\nfunction findPath(\n\tstartRoot: Function,\n\tendRoot: Function,\n\tvisited: Set<Function> = new Set(),\n\tpath: Function[] = []\n): Function[] {\n\tif (startRoot === endRoot) {\n\t\treturn [...path, endRoot]\n\t}\n\n\tif (visited.has(startRoot)) {\n\t\treturn []\n\t}\n\n\tvisited.add(startRoot)\n\tconst newPath = [...path, startRoot]\n\n\tconst triggers = effectTriggers.get(startRoot)\n\tif (triggers) {\n\t\tfor (const targetRoot of triggers) {\n\t\t\tconst result = findPath(targetRoot, endRoot, visited, newPath)\n\t\t\tif (result.length > 0) {\n\t\t\t\treturn result\n\t\t\t}\n\t\t}\n\t}\n\n\treturn []\n}\n\n/**\n * Gets the cycle path when adding an edge would create a cycle\n * @param callerRoot - Root of the effect that triggers\n * @param targetRoot - Root of the effect being triggered\n * @returns Array of effect roots forming the cycle, or empty array if no cycle\n */\nfunction getCyclePathForEdge(callerRoot: Function, targetRoot: Function): Function[] {\n\t// Find path from targetRoot back to callerRoot (this is the existing path)\n\t// Then adding callerRoot -> targetRoot completes the cycle\n\tconst path = findPath(targetRoot, callerRoot)\n\tif (path.length > 0) {\n\t\t// The cycle is: callerRoot -> targetRoot -> ... -> callerRoot\n\t\treturn [callerRoot, ...path]\n\t}\n\treturn []\n}\n\n/**\n * Checks if adding an edge would create a cycle\n * Uses causesClosure to check if callerRoot is already a cause of targetRoot\n * Self-loops (callerRoot === targetRoot) are explicitly ignored and return false\n * @param callerRoot - Root of the effect that triggers\n * @param targetRoot - Root of the effect being triggered\n * @returns true if adding this edge would create a cycle\n */\nfunction wouldCreateCycle(callerRoot: Function, targetRoot: Function): boolean {\n\t// Self-loops are explicitly ignored - an effect reading and writing the same property\n\t// (e.g., obj.prop++) should not create a dependency relationship\n\tif (callerRoot === targetRoot) {\n\t\treturn false\n\t}\n\n\t// Check if targetRoot already triggers callerRoot (directly or indirectly)\n\t// This would create a cycle: callerRoot -> targetRoot -> ... -> callerRoot\n\t// Using consequencesClosure: if targetRoot triggers callerRoot, then callerRoot is in consequencesClosure(targetRoot)\n\tconst targetConsequences = consequencesClosure.get(targetRoot)\n\tif (targetConsequences?.has(callerRoot)) {\n\t\treturn true // Cycle detected: targetRoot -> ... -> callerRoot, and we're adding callerRoot -> targetRoot\n\t}\n\n\treturn false\n}\n\n/**\n * Adds an effect to the batch queue\n * @param effect - The effect to add\n * @param caller - The active effect that triggered this one (optional)\n * @param immediate - If true, don't create edges in the dependency graph\n */\nfunction addToBatch(effect: ScopedCallback, caller?: ScopedCallback, immediate?: boolean) {\n\tconst cleanupFn = (effect as any)[cleanupSymbol]\n\tif (cleanupFn) cleanupFn()\n\t// If the effect was stopped during cleanup (e.g. lazy memoization), don't add it to the batch\n\tif ((effect as any)[stopped]) return\n\n\tif (!batchQueue) return\n\n\tconst root = getRoot(effect)\n\n\t// 1. Add to batch first (needed for cycle detection)\n\tbatchQueue.all.set(root, effect)\n\n\t// 2. Add to global graph (if caller exists and not immediate) - USE ROOTS ONLY\n\t// When immediate is true, don't create edges - the effect is not considered as a consequence\n\tif (caller && !immediate) {\n\t\tconst callerRoot = getRoot(caller)\n\n\t\t// Check for cycle BEFORE adding edge\n\t\t// We check if adding callerRoot -> root would create a cycle\n\t\t// This means checking if root already triggers callerRoot (directly or transitively)\n\t\tif (wouldCreateCycle(callerRoot, root)) {\n\t\t\t// Cycle detected! Get the full cycle path for debugging\n\t\t\tconst cyclePath = getCyclePathForEdge(callerRoot, root)\n\t\t\tconst cycleMessage =\n\t\t\t\tcyclePath.length > 0\n\t\t\t\t\t? `Cycle detected: ${cyclePath.map((r) => r.name || r.toString()).join(' → ')}`\n\t\t\t\t\t: `Cycle detected: ${callerRoot.name || callerRoot.toString()} → ${root.name || root.toString()} (and back)`\n\n\t\t\tconst cycleHandling = options.cycleHandling\n\n\t\t\t// In strict mode, we throw immediately on detection\n\t\t\tif (cycleHandling === 'strict') {\n\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\tconst causalChain = getTriggerChain(effect)\n\t\t\t\tconst creationStack = effectCreationStacks.get(root)\n\n\t\t\t\tthrow new ReactiveError(`[reactive] Strict Cycle Prevention: ${cycleMessage}`, {\n\t\t\t\t\tcode: ReactiveErrorCode.CycleDetected,\n\t\t\t\t\tcycle: cyclePath.map((r) => r.name || r.toString()),\n\t\t\t\t\tdetails: cycleMessage,\n\t\t\t\t\tcausalChain,\n\t\t\t\t\tcreationStack,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tswitch (cycleHandling) {\n\t\t\t\tcase 'throw': {\n\t\t\t\t\t// Remove from batch before throwing\n\t\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\t\tconst causalChain = getTriggerChain(effect)\n\t\t\t\t\tconst creationStack = effectCreationStacks.get(root)\n\n\t\t\t\t\tthrow new ReactiveError(`[reactive] ${cycleMessage}`, {\n\t\t\t\t\t\tcode: ReactiveErrorCode.CycleDetected,\n\t\t\t\t\t\tcycle: cyclePath.map((r) => r.name || r.toString()),\n\t\t\t\t\t\tdetails: cycleMessage,\n\t\t\t\t\t\tcausalChain,\n\t\t\t\t\t\tcreationStack,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tcase 'warn':\n\t\t\t\t\toptions.warn(`[reactive] ${cycleMessage}`)\n\t\t\t\t\t// Don't add the edge, break the cycle\n\t\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\t\treturn\n\t\t\t\tcase 'break':\n\t\t\t\t\t// Silently break cycle, don't add the edge\n\t\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\taddGraphEdge(callerRoot, root) // Add to persistent graph using roots\n\t}\n}\n\n/**\n * Adds a cleanup function to be called when the current batch of effects completes\n * @param cleanup - The cleanup function to add\n */\nexport function addBatchCleanup(cleanup: ScopedCallback) {\n\tif (!batchQueue) cleanup()\n\telse batchCleanups.add(cleanup)\n}\n\n/**\n * Semantic alias for `addBatchCleanup` - defers work to the end of the current reactive batch.\n *\n * Use this when an effect needs to perform an action that would modify state the effect depends on,\n * which would create a reactive cycle. The deferred callback runs after all effects complete.\n *\n * @param callback - The callback to defer until after the current batch completes\n *\n * @example\n * ```typescript\n * effect(() => {\n * processData()\n *\n * // Defer to avoid cycle (createMovement modifies state this effect reads)\n * defer(() => {\n * createMovement(data)\n * })\n * })\n * ```\n */\nexport const defer = addBatchCleanup\n\n/**\n * Gets a cycle path for debugging\n * Uses DFS to find cycles in the batch\n * @param batchQueue - The batch queue\n * @returns Array of effect roots forming a cycle\n */\nfunction getCyclePath(batchQueue: BatchQueue): Function[] {\n\t// If all effects have in-degree > 0, there must be a cycle\n\t// Use DFS to find it\n\tconst visited = new Set<Function>()\n\tconst recursionStack = new Set<Function>()\n\tconst path: Function[] = []\n\n\tfor (const [root] of batchQueue.all) {\n\t\tif (visited.has(root)) continue\n\t\tconst cycle = findCycle(root, visited, recursionStack, path, batchQueue)\n\t\tif (cycle.length > 0) {\n\t\t\treturn cycle\n\t\t}\n\t}\n\n\treturn []\n}\n\nfunction findCycle(\n\troot: Function,\n\tvisited: Set<Function>,\n\trecursionStack: Set<Function>,\n\tpath: Function[],\n\tbatchQueue: BatchQueue\n): Function[] {\n\tif (recursionStack.has(root)) {\n\t\t// Found a cycle! Return the path from the cycle start to root\n\t\tconst cycleStart = path.indexOf(root)\n\t\treturn path.slice(cycleStart).concat([root])\n\t}\n\n\tif (visited.has(root)) {\n\t\treturn []\n\t}\n\n\tvisited.add(root)\n\trecursionStack.add(root)\n\tpath.push(root)\n\n\t// Follow edges to effects in the batch\n\t// Use direct edges (effectTriggers) for cycle detection\n\tconst triggers = effectTriggers.get(root)\n\tif (triggers) {\n\t\tfor (const targetRoot of triggers) {\n\t\t\tif (batchQueue.all.has(targetRoot)) {\n\t\t\t\tconst cycle = findCycle(targetRoot, visited, recursionStack, path, batchQueue)\n\t\t\t\tif (cycle.length > 0) {\n\t\t\t\t\treturn cycle\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpath.pop()\n\trecursionStack.delete(root)\n\treturn []\n}\n\n/**\n * Executes the next effect in dependency order (using cached in-degrees)\n * Finds an effect with in-degree 0 and executes it\n * @returns The return value of the executed effect, or null if batch is complete\n */\nfunction executeNext(effectuatedRoots: Function[]): any {\n\t// Find an effect with in-degree 0 using cached values\n\tlet nextEffect: ScopedCallback | null = null\n\tlet nextRoot: Function | null = null\n\n\t// Find an effect with in-degree 0 (no dependencies in batch that still need execution)\n\t// Using cached in-degrees for O(n) lookup instead of O(n²)\n\tfor (const [root, effect] of batchQueue!.all) {\n\t\tconst inDegree = batchQueue!.inDegrees.get(root) ?? 0\n\t\tif (inDegree === 0) {\n\t\t\tnextEffect = effect\n\t\t\tnextRoot = root\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif (!nextEffect) {\n\t\t// No effect with in-degree 0 - there must be a cycle\n\t\t// If all effects have dependencies, it means there's a circular dependency\n\t\tif (batchQueue!.all.size > 0) {\n\t\t\tlet cycle = getCyclePath(batchQueue!)\n\t\t\t// If we couldn't find a cycle path using direct edges, try using closures\n\t\t\t// (transitive relationships) - if all effects have in-degree > 0, there must be a cycle\n\t\t\tif (cycle.length === 0) {\n\t\t\t\t// Try to find a cycle using consequencesClosure (transitive relationships)\n\t\t\t\t// Note: Self-loops are ignored - we only look for cycles between different effects\n\t\t\t\tfor (const [root] of batchQueue!.all) {\n\t\t\t\t\tconst consequences = consequencesClosure.get(root)\n\t\t\t\t\tif (consequences) {\n\t\t\t\t\t\t// Check if any consequence in the batch also has root as a consequence\n\t\t\t\t\t\tfor (const consequence of consequences) {\n\t\t\t\t\t\t\t// Skip self-loops - they are ignored\n\t\t\t\t\t\t\tif (consequence === root) continue\n\t\t\t\t\t\t\tif (batchQueue!.all.has(consequence)) {\n\t\t\t\t\t\t\t\tconst consequenceConsequences = consequencesClosure.get(consequence)\n\t\t\t\t\t\t\t\tif (consequenceConsequences?.has(root)) {\n\t\t\t\t\t\t\t\t\t// Found cycle: root -> consequence -> root\n\t\t\t\t\t\t\t\t\tcycle = [root, consequence, root]\n\t\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cycle.length > 0) break\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst cycleMessage =\n\t\t\t\tcycle.length > 0\n\t\t\t\t\t? `Cycle detected: ${cycle.map((r) => r.name || '<anonymous>').join(' → ')}`\n\t\t\t\t\t: 'Cycle detected in effect batch - all effects have dependencies that prevent execution'\n\n\t\t\tconst cycleHandling = options.cycleHandling\n\t\t\tswitch (cycleHandling) {\n\t\t\t\tcase 'throw':\n\t\t\t\t\tthrow new ReactiveError(`[reactive] ${cycleMessage}`)\n\t\t\t\tcase 'warn': {\n\t\t\t\t\toptions.warn(`[reactive] ${cycleMessage}`)\n\t\t\t\t\t// Break the cycle by executing one effect anyway\n\t\t\t\t\tconst firstEffect = batchQueue!.all.values().next().value\n\t\t\t\t\tif (firstEffect) {\n\t\t\t\t\t\tconst firstRoot = getRoot(firstEffect)\n\t\t\t\t\t\tbatchQueue!.all.delete(firstRoot)\n\t\t\t\t\t\tbatchQueue!.inDegrees.delete(firstRoot)\n\t\t\t\t\t\treturn firstEffect()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'break': {\n\t\t\t\t\t// Silently break cycle\n\t\t\t\t\tconst firstEffect2 = batchQueue!.all.values().next().value\n\t\t\t\t\tif (firstEffect2) {\n\t\t\t\t\t\tconst firstRoot2 = getRoot(firstEffect2)\n\t\t\t\t\t\tbatchQueue!.all.delete(firstRoot2)\n\t\t\t\t\t\tbatchQueue!.inDegrees.delete(firstRoot2)\n\t\t\t\t\t\treturn firstEffect2()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null // Batch complete\n\t}\n\n\teffectuatedRoots.push(getRoot(nextEffect))\n\t// Execute the effect\n\tconst result = nextEffect()\n\n\t// Remove from batch and update in-degrees of dependents\n\tbatchQueue!.all.delete(nextRoot!)\n\tbatchQueue!.inDegrees.delete(nextRoot!)\n\tdecrementInDegreesForExecuted(batchQueue!, nextRoot!)\n\n\treturn result\n}\n\n// Track which sub-effects have been executed to prevent infinite loops\n// These are all the effects triggered under `activeEffect` and all their sub-effects\nexport function batch(effect: ScopedCallback | ScopedCallback[], immediate?: 'immediate') {\n\tif (!Array.isArray(effect)) effect = [effect]\n\tconst roots = effect.map(getRoot)\n\n\tif (batchQueue) {\n\t\t// Nested batch - add to existing\n\t\toptions?.chain(roots, getRoot(getActiveEffect()))\n\t\tconst caller = getActiveEffect()\n\t\tfor (let i = 0; i < effect.length; i++) {\n\t\t\taddToBatch(effect[i], caller, immediate === 'immediate')\n\t\t}\n\t\tif (immediate) {\n\t\t\tconst firstReturn: { value?: any } = {}\n\t\t\t// Execute immediately (before batch returns)\n\t\t\tfor (let i = 0; i < effect.length; i++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst rv = effect[i]()\n\t\t\t\t\tif (rv !== undefined && !('value' in firstReturn)) firstReturn.value = rv\n\t\t\t\t} finally {\n\t\t\t\t\tconst root = getRoot(effect[i])\n\t\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn firstReturn.value\n\t\t}\n\t\t// Otherwise, effects will be picked up in next executeNext() call\n\t} else {\n\t\t// New batch - initialize\n\t\tif (!activationRegistry) activationRegistry = new Map()\n\t\telse throw new Error('Batch already in progress')\n\t\toptions.beginChain(roots)\n\t\tbatchQueue = {\n\t\t\tall: new Map(),\n\t\t\tinDegrees: new Map(),\n\t\t}\n\n\t\t// Add initial effects\n\t\tconst caller = getActiveEffect()\n\t\tfor (let i = 0; i < effect.length; i++) {\n\t\t\taddToBatch(effect[i], caller, immediate === 'immediate')\n\t\t}\n\n\t\tconst effectuatedRoots: ScopedCallback[] = []\n\t\tcomputeAllInDegrees(batchQueue)\n\t\tif (immediate) {\n\t\t\t// Execute immediately (before batch returns)\n\t\t\tconst firstReturn: { value?: any } = {}\n\t\t\ttry {\n\t\t\t\tfor (let i = 0; i < effect.length; i++) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst rv = effect[i]()\n\t\t\t\t\t\tif (rv !== undefined && !('value' in firstReturn)) firstReturn.value = rv\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tconst root = getRoot(effect[i])\n\t\t\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// After immediate execution, execute any effects that were triggered during execution\n\t\t\t\t// This is important for @atomic decorator - effects triggered inside should still run\n\t\t\t\twhile (batchQueue.all.size > 0) {\n\t\t\t\t\tif (effectuatedRoots.length > options.maxEffectChain) {\n\t\t\t\t\t\tconst cycle = findCycleInChain(effectuatedRoots as any)\n\t\t\t\t\t\tconst trace = formatRoots(effectuatedRoots as any)\n\t\t\t\t\t\tconst message = cycle\n\t\t\t\t\t\t\t? `Max effect chain reached (cycle detected: ${formatRoots(cycle)})`\n\t\t\t\t\t\t\t: `Max effect chain reached (trace: ${trace})`\n\n\t\t\t\t\t\tconst queuedRoots = batchQueue ? Array.from(batchQueue.all.keys()) : []\n\t\t\t\t\t\tconst queued = queuedRoots.map((r) => r.name || '<anonymous>')\n\t\t\t\t\t\tconst debugInfo = {\n\t\t\t\t\t\t\tcode: ReactiveErrorCode.MaxDepthExceeded,\n\t\t\t\t\t\t\teffectuatedRoots,\n\t\t\t\t\t\t\tcycle,\n\t\t\t\t\t\t\ttrace,\n\t\t\t\t\t\t\tmaxEffectChain: options.maxEffectChain,\n\t\t\t\t\t\t\tqueued: queued.slice(0, 50),\n\t\t\t\t\t\t\tqueuedCount: queued.length,\n\t\t\t\t\t\t\t// Try to get causation for the last effect\n\t\t\t\t\t\t\tcausalChain:\n\t\t\t\t\t\t\t\teffectuatedRoots.length > 0\n\t\t\t\t\t\t\t\t\t? getTriggerChain(\n\t\t\t\t\t\t\t\t\t\t\tbatchQueue.all.get(effectuatedRoots[effectuatedRoots.length - 1])!\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t}\n\t\t\t\t\t\tswitch (options.maxEffectReaction) {\n\t\t\t\t\t\t\tcase 'throw':\n\t\t\t\t\t\t\t\tthrow new ReactiveError(`[reactive] ${message}`, debugInfo)\n\t\t\t\t\t\t\tcase 'debug':\n\t\t\t\t\t\t\t\t// biome-ignore lint/suspicious/noDebugger: This is the whole point here\n\t\t\t\t\t\t\t\tdebugger\n\t\t\t\t\t\t\t\tthrow new ReactiveError(`[reactive] ${message}`, debugInfo)\n\t\t\t\t\t\t\tcase 'warn':\n\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t`[reactive] ${message} (queued: ${queued.slice(0, 10).join(', ')}${queued.length > 10 ? ', …' : ''})`\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!batchQueue || batchQueue.all.size === 0) break\n\t\t\t\t\tconst rv = executeNext(effectuatedRoots)\n\t\t\t\t\t// If executeNext() returned null but batch is not empty, it means a cycle was detected\n\t\t\t\t\t// and an error was thrown, so we won't reach here\n\t\t\t\t\tif (rv !== undefined && !('value' in firstReturn)) firstReturn.value = rv\n\t\t\t\t}\n\t\t\t\tconst cleanups = Array.from(batchCleanups)\n\t\t\t\tbatchCleanups.clear()\n\t\t\t\tfor (const cleanup of cleanups) cleanup()\n\t\t\t\treturn firstReturn.value\n\t\t\t} finally {\n\t\t\t\tactivationRegistry = undefined\n\t\t\t\tbatchQueue = undefined\n\t\t\t\toptions.endChain()\n\t\t\t}\n\t\t} else {\n\t\t\t// Execute in dependency order\n\t\t\tconst firstReturn: { value?: any } = {}\n\t\t\ttry {\n\t\t\t\t// Outer loop: continue while there are effects OR cleanups pending.\n\t\t\t\t// This ensures effects triggered by cleanups are not lost.\n\t\t\t\twhile (batchQueue.all.size > 0 || batchCleanups.size > 0) {\n\t\t\t\t\t// Inner loop: execute all pending effects\n\t\t\t\t\twhile (batchQueue.all.size > 0) {\n\t\t\t\t\t\tif (effectuatedRoots.length > options.maxEffectChain) {\n\t\t\t\t\t\t\tconst cycle = findCycleInChain(effectuatedRoots as any)\n\t\t\t\t\t\t\tconst trace = formatRoots(effectuatedRoots as any)\n\t\t\t\t\t\t\tconst message = cycle\n\t\t\t\t\t\t\t\t? `Max effect chain reached (cycle detected: ${formatRoots(cycle)})`\n\t\t\t\t\t\t\t\t: `Max effect chain reached (trace: ${trace})`\n\n\t\t\t\t\t\t\tconst queuedRoots = batchQueue ? Array.from(batchQueue.all.keys()) : []\n\t\t\t\t\t\t\tconst queued = queuedRoots.map((r) => r.name || '<anonymous>')\n\t\t\t\t\t\t\tconst debugInfo = {\n\t\t\t\t\t\t\t\tcode: ReactiveErrorCode.MaxDepthExceeded,\n\t\t\t\t\t\t\t\teffectuatedRoots,\n\t\t\t\t\t\t\t\tcycle,\n\t\t\t\t\t\t\t\ttrace,\n\t\t\t\t\t\t\t\tmaxEffectChain: options.maxEffectChain,\n\t\t\t\t\t\t\t\tqueued: queued.slice(0, 50),\n\t\t\t\t\t\t\t\tqueuedCount: queued.length,\n\t\t\t\t\t\t\t\t// Try to get causation for the last effect\n\t\t\t\t\t\t\t\tcausalChain:\n\t\t\t\t\t\t\t\t\teffectuatedRoots.length > 0\n\t\t\t\t\t\t\t\t\t\t? getTriggerChain(\n\t\t\t\t\t\t\t\t\t\t\t\tbatchQueue.all.get(effectuatedRoots[effectuatedRoots.length - 1])!\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tswitch (options.maxEffectReaction) {\n\t\t\t\t\t\t\t\tcase 'throw':\n\t\t\t\t\t\t\t\t\tthrow new ReactiveError(`[reactive] ${message}`, debugInfo)\n\t\t\t\t\t\t\t\tcase 'debug':\n\t\t\t\t\t\t\t\t\t// biome-ignore lint/suspicious/noDebugger: This is the whole point here\n\t\t\t\t\t\t\t\t\tdebugger\n\t\t\t\t\t\t\t\t\tthrow new ReactiveError(`[reactive] ${message}`, debugInfo)\n\t\t\t\t\t\t\t\tcase 'warn':\n\t\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t\t`[reactive] ${message} (queued: ${queued.slice(0, 10).join(', ')}${queued.length > 10 ? ', …' : ''})`\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst rv = executeNext(effectuatedRoots)\n\t\t\t\t\t\t// executeNext() returns null when batch is complete or cycle detected (throws error)\n\t\t\t\t\t\t// But functions can legitimately return null, so we check batchQueue.all.size instead\n\t\t\t\t\t\tif (batchQueue.all.size === 0) {\n\t\t\t\t\t\t\t// Batch complete\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// If executeNext() returned null but batch is not empty, it means a cycle was detected\n\t\t\t\t\t\t// and an error was thrown, so we won't reach here\n\t\t\t\t\t\tif (rv !== undefined && !('value' in firstReturn)) firstReturn.value = rv\n\t\t\t\t\t\t// Note: executeNext() already removed it from batchQueue, so we track by count\n\t\t\t\t\t}\n\t\t\t\t\t// Process cleanups. If they trigger new effects, the outer loop will catch them.\n\t\t\t\t\tif (batchCleanups.size > 0) {\n\t\t\t\t\t\tconst cleanups = Array.from(batchCleanups)\n\t\t\t\t\t\tbatchCleanups.clear()\n\t\t\t\t\t\tfor (const cleanup of cleanups) cleanup()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn firstReturn.value\n\t\t\t} finally {\n\t\t\t\tactivationRegistry = undefined\n\t\t\t\tbatchQueue = undefined\n\t\t\t\toptions.endChain()\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Decorator that makes methods atomic - batches all effects triggered within the method\n */\nexport const atomic = decorator({\n\tmethod(original) {\n\t\treturn function (this: any, ...args: any[]) {\n\t\t\tconst atomicEffect = () => original.apply(this, args)\n\t\t\t// Debug: helpful to have a name\n\t\t\tObject.defineProperty(atomicEffect, 'name', { value: `atomic(${original.name})` })\n\t\t\treturn batch(atomicEffect, 'immediate')\n\t\t}\n\t},\n\tdefault<Args extends any[], Return>(\n\t\toriginal: (...args: Args) => Return\n\t): (...args: Args) => Return {\n\t\treturn function (this: any, ...args: Args) {\n\t\t\tconst atomicEffect = () => original.apply(this, args)\n\t\t\t// Debug: helpful to have a name\n\t\t\tObject.defineProperty(atomicEffect, 'name', { value: `atomic(${original.name})` })\n\t\t\treturn batch(atomicEffect, 'immediate')\n\t\t}\n\t},\n})\n\nconst fr = new FinalizationRegistry<() => void>((f) => f())\n\n/**\n * @param fn - The effect function to run - provides the cleaner\n * @returns The cleanup function\n */\n/**\n * Creates a reactive effect that automatically re-runs when dependencies change\n * @param fn - The effect function that provides dependencies and may return a cleanup function or Promise\n * @param options - Options for effect execution\n * @returns A cleanup function to stop the effect\n */\nexport function effect(\n\t//biome-ignore lint/suspicious/noConfusingVoidType: We have to\n\tfn: (access: DependencyAccess) => ScopedCallback | undefined | void | Promise<any>,\n\teffectOptions?: EffectOptions\n): ScopedCallback {\n\t// Ensure zone is hooked if asyncZone option is enabled (lazy initialization)\n\t// Inject batch function to allow atomic game loops in requestAnimationFrame\n\tensureZoneHooked(batch)\n\n\t// Use per-effect asyncMode or fall back to global option\n\tconst asyncMode = effectOptions?.asyncMode ?? options.asyncMode ?? 'cancel'\n\tif (options.introspection.enableHistory) {\n\t\tconst stack = new Error().stack\n\t\tif (stack) {\n\t\t\t// Clean up the stack trace to remove internal frames\n\t\t\tconst cleanStack = stack.split('\\n').slice(2).join('\\n')\n\t\t\teffectCreationStacks.set(getRoot(fn), cleanStack)\n\t\t}\n\t}\n\tlet cleanup: (() => void) | null = null\n\t// capture the parent effect at creation time for ascend\n\tconst parentsForAscend = captureEffectStack()\n\tconst tracked = <T>(cb: () => T) => withEffect(runEffect, cb)\n\tconst ascend = <T>(cb: () => T) => withEffectStack(parentsForAscend, cb)\n\tlet effectStopped = false\n\tlet hasReacted = false\n\tlet runningPromise: Promise<any> | null = null\n\tlet cancelPrevious: (() => void) | null = null\n\n\tfunction runEffect() {\n\t\t// Clear previous dependencies\n\t\tif (cleanup) {\n\t\t\tconst prevCleanup = cleanup\n\t\t\tcleanup = null\n\t\t\twithEffect(undefined, () => prevCleanup())\n\t\t}\n\n\t\t// Handle async modes when effect is retriggered\n\t\tif (runningPromise) {\n\t\t\tif (asyncMode === 'cancel' && cancelPrevious) {\n\t\t\t\t// Cancel previous execution\n\t\t\t\tcancelPrevious()\n\t\t\t\tcancelPrevious = null\n\t\t\t\trunningPromise = null\n\t\t\t} else if (asyncMode === 'ignore') {\n\t\t\t\t// Ignore new execution while async work is running\n\t\t\t\treturn\n\t\t\t}\n\t\t\t// Note: 'queue' mode not yet implemented\n\t\t}\n\n\t\t// The effect has been stopped after having been planned\n\t\tif (effectStopped) return\n\n\t\toptions.enter(getRoot(fn))\n\t\tlet reactionCleanup: ScopedCallback | undefined\n\t\tlet result: any\n\t\ttry {\n\t\t\tresult = withEffect(runEffect, () => fn({ tracked, ascend, reaction: hasReacted }))\n\t\t\tif (\n\t\t\t\tresult &&\n\t\t\t\ttypeof result !== 'function' &&\n\t\t\t\t(typeof result !== 'object' || !('then' in result))\n\t\t\t)\n\t\t\t\tthrow new ReactiveError(`[reactive] Effect returned a non-function value: ${result}`)\n\t\t\t// Check if result is a Promise (async effect)\n\t\t\tif (result && typeof result === 'object' && typeof result.then === 'function') {\n\t\t\t\tconst originalPromise = result as Promise<any>\n\n\t\t\t\t// Create a cancellation promise that we can reject\n\t\t\t\tlet cancelReject: ((reason: any) => void) | null = null\n\t\t\t\tconst cancelPromise = new Promise<never>((_, reject) => {\n\t\t\t\t\tcancelReject = reject\n\t\t\t\t})\n\n\t\t\t\tconst cancelError = new ReactiveError('[reactive] Effect canceled due to dependency change')\n\n\t\t\t\t// Race between the actual promise and cancellation\n\t\t\t\t// If canceled, the race rejects, which will propagate through any promise chain\n\t\t\t\trunningPromise = Promise.race([originalPromise, cancelPromise])\n\n\t\t\t\t// Store the cancellation function\n\t\t\t\tcancelPrevious = () => {\n\t\t\t\t\tif (cancelReject) {\n\t\t\t\t\t\tcancelReject(cancelError)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Wrap the original promise chain so cancellation propagates\n\t\t\t\t// This ensures that when we cancel, the original promise's .catch() handlers are triggered\n\t\t\t\t// We do this by rejecting the race promise, which makes the original promise chain see the rejection\n\t\t\t\t// through the zone-wrapped .then()/.catch() handlers\n\t\t\t} else {\n\t\t\t\t// Synchronous result - treat as cleanup function\n\t\t\t\treactionCleanup = result as undefined | ScopedCallback\n\t\t\t}\n\t\t} finally {\n\t\t\thasReacted = true\n\t\t\toptions.leave(fn)\n\t\t}\n\n\t\t// Create cleanup function for next run\n\t\tcleanup = () => {\n\t\t\tcleanup = null\n\t\t\treactionCleanup?.()\n\t\t\t// Remove this effect from all reactive objects it's watching\n\t\t\tconst effectObjects = effectToReactiveObjects.get(runEffect)\n\t\t\tif (effectObjects) {\n\t\t\t\tfor (const reactiveObj of effectObjects) {\n\t\t\t\t\tconst objectWatchers = watchers.get(reactiveObj)\n\t\t\t\t\tif (objectWatchers) {\n\t\t\t\t\t\tfor (const [prop, deps] of objectWatchers.entries()) {\n\t\t\t\t\t\t\tdeps.delete(runEffect)\n\t\t\t\t\t\t\tif (deps.size === 0) {\n\t\t\t\t\t\t\t\tobjectWatchers.delete(prop)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (objectWatchers.size === 0) {\n\t\t\t\t\t\t\twatchers.delete(reactiveObj)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\teffectToReactiveObjects.delete(runEffect)\n\t\t\t}\n\t\t\t// Invoke all child stops (recursive via subEffectCleanup calling its own mainCleanup)\n\t\t\tconst children = effectChildren.get(runEffect)\n\t\t\tif (children) {\n\t\t\t\tfor (const childCleanup of children) childCleanup()\n\t\t\t\teffectChildren.delete(runEffect)\n\t\t\t}\n\t\t}\n\t}\n\t// Mark the runEffect callback with the original function as its root\n\tmarkWithRoot(runEffect, fn)\n\n\t// Register strict mode if enabled\n\tif (effectOptions?.opaque) {\n\t\topaqueEffects.add(runEffect)\n\t}\n\n\tif (isDevtoolsEnabled()) {\n\t\tregisterEffectForDebug(runEffect)\n\t}\n\n\tbatch(runEffect, 'immediate')\n\n\tconst parent = parentsForAscend[0]\n\t// Store parent relationship for hierarchy traversal\n\teffectParent.set(runEffect, parent)\n\t// Only ROOT effects are registered for GC cleanup and zone tracking\n\tconst isRootEffect = !parent\n\n\tconst stopEffect = (): void => {\n\t\tif (effectStopped) return\n\t\teffectStopped = true\n\t\t// Cancel any running async work\n\t\tif (cancelPrevious) {\n\t\t\tcancelPrevious()\n\t\t\tcancelPrevious = null\n\t\t\trunningPromise = null\n\t\t}\n\t\tcleanup?.()\n\t\t// Clean up dependency graph edges\n\t\tcleanupEffectFromGraph(runEffect)\n\t\tfr.unregister(stopEffect)\n\t}\n\tfunction augmentedRv(rv: ScopedCallback): ScopedCallback {\n\t\tObject.defineProperty(rv, stopped, {\n\t\t\tget() {\n\t\t\t\treturn effectStopped\n\t\t\t},\n\t\t})\n\t\tObject.defineProperty(rv, cleanupSymbol, {\n\t\t\tvalue: () => {\n\t\t\t\tif (cleanup) {\n\t\t\t\t\tconst prevCleanup = cleanup\n\t\t\t\t\tcleanup = null\n\t\t\t\t\twithEffect(undefined, () => prevCleanup())\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t\treturn rv\n\t}\n\tif (isRootEffect) {\n\t\tconst callIfCollected = augmentedRv(() => stopEffect())\n\t\tfr.register(\n\t\t\tcallIfCollected,\n\t\t\t() => {\n\t\t\t\tstopEffect()\n\t\t\t\toptions.garbageCollected(fn)\n\t\t\t},\n\t\t\tstopEffect\n\t\t)\n\t\treturn callIfCollected\n\t}\n\t// Register this effect to be stopped when the parent effect is cleaned up\n\tlet children = effectChildren.get(parent)\n\tif (!children) {\n\t\tchildren = new Set()\n\t\teffectChildren.set(parent, children)\n\t}\n\tconst subEffectCleanup = augmentedRv(() => {\n\t\tchildren.delete(subEffectCleanup)\n\t\tif (children.size === 0) {\n\t\t\teffectChildren.delete(parent)\n\t\t}\n\t\t// Execute this child effect cleanup (which triggers its own mainCleanup)\n\t\tstopEffect()\n\t})\n\tchildren.add(subEffectCleanup)\n\n\treturn subEffectCleanup\n}\n\n/**\n * Executes a function without tracking dependencies but maintains parent cleanup relationship\n * Effects created inside will still be cleaned up when the parent effect is destroyed\n * @param fn - The function to execute\n */\nexport function untracked<T>(fn: () => T): T {\n\t// Store current tracking state and temporarily disable it\n\t// This prevents the parent effect from tracking dependencies during fn execution\n\tconst wasTrackingDisabled = getTrackingDisabled()\n\tsetTrackingDisabled(true)\n\n\ttry {\n\t\treturn fn()\n\t} finally {\n\t\t// Restore tracking state\n\t\tsetTrackingDisabled(wasTrackingDisabled)\n\t}\n}\n\n/**\n * Executes a function from a virgin/root context - no parent effect, no tracking\n * Creates completely independent effects that won't be cleaned up by any parent\n * @param fn - The function to execute\n */\nexport function root<T>(fn: () => T): T {\n\tlet rv!: T\n\twithEffect(undefined, () => {\n\t\trv = fn()\n\t})\n\treturn rv\n}\n\nexport { effectTrackers }\n\n/**\n * Creates a bidirectional binding between a reactive value and a non-reactive external value\n * Prevents infinite loops by automatically suppressing circular notifications\n *\n * @param received - Function called when the reactive value changes (external setter)\n * @param get - Getter for the reactive value OR an object with `{ get, set }` properties\n * @param set - Setter for the reactive value (required if `get` is a function)\n * @returns A function to manually provide updates from the external side\n *\n * @example\n * ```typescript\n * const model = reactive({ value: '' })\n * const input = { value: '' }\n *\n * // Bidirectional binding\n * const provide = biDi(\n * (v) => input.value = v, // external setter\n * () => model.value, // reactive getter\n * (v) => model.value = v // reactive setter\n * )\n *\n * // External notification (e.g., from input event)\n * provide('new value') // Updates model.value, doesn't trigger circular loop\n * ```\n *\n * @example Using object syntax\n * ```typescript\n * const provide = biDi(\n * (v) => setHTMLValue(v),\n * { get: () => reactiveObj.value, set: (v) => reactiveObj.value = v }\n * )\n * ```\n */\nexport function biDi<T>(\n\treceived: (value: T) => void,\n\tvalue: { get: () => T; set: (value: T) => void }\n): (value: T) => void\nexport function biDi<T>(\n\treceived: (value: T) => void,\n\tget: () => T,\n\tset: (value: T) => void\n): (value: T) => void\nexport function biDi<T>(\n\treceived: (value: T) => void,\n\tget: (() => T) | { get: () => T; set: (value: T) => void },\n\tset?: (value: T) => void\n): (value: T) => void {\n\tif (typeof get !== 'function') {\n\t\tset = get.set\n\t\tget = get.get\n\t}\n\tconst root = getRoot(received)\n\teffect(\n\t\tmarkWithRoot(() => {\n\t\t\treceived(get())\n\t\t}, root)\n\t)\n\treturn atomic((value: T) => {\n\t\tset!(value)\n\t\tif (batchQueue?.all.has(root)) {\n\t\t\t// Remove the effect from the batch queue so it doesn't execute\n\t\t\t// This prevents circular updates in bidirectional bindings\n\t\t\tbatchQueue.all.delete(root)\n\t\t}\n\t})\n}\n","import { batch } from './effects'\nimport type { Evolution, ScopedCallback } from './types'\n\n// Track which objects contain which other objects (back-references)\nexport const objectParents = new WeakMap<object, Set<{ parent: object; prop: PropertyKey }>>()\n\n// Track which objects have deep watchers\nexport const objectsWithDeepWatchers = new WeakSet<object>()\n\n// Track deep watchers per object\nexport const deepWatchers = new WeakMap<object, Set<ScopedCallback>>()\n\n// Track which effects are doing deep watching\nexport const effectToDeepWatchedObjects = new WeakMap<ScopedCallback, Set<object>>()\n\n/**\n * Add a back-reference from child to parent\n */\nexport function addBackReference(child: object, parent: object, prop: any) {\n\tlet parents = objectParents.get(child)\n\tif (!parents) {\n\t\tparents = new Set()\n\t\tobjectParents.set(child, parents)\n\t}\n\tparents.add({ parent, prop })\n}\n\n/**\n * Remove a back-reference from child to parent\n */\nexport function removeBackReference(child: object, parent: object, prop: any) {\n\tconst parents = objectParents.get(child)\n\tif (parents) {\n\t\tfor (const entry of parents) {\n\t\t\tif (entry.parent === parent && entry.prop === prop) {\n\t\t\t\tparents.delete(entry)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (parents.size === 0) {\n\t\t\tobjectParents.delete(child)\n\t\t}\n\t}\n}\n\n/**\n * Check if an object needs back-references (has deep watchers or parents with deep watchers)\n */\nexport function needsBackReferences(obj: object): boolean {\n\t// Fast path: check if object itself has deep watchers\n\tif (objectsWithDeepWatchers.has(obj)) return true\n\t// Slow path: check if any parent has deep watchers (recursive)\n\treturn hasParentWithDeepWatchers(obj)\n}\n\n/**\n * Bubble up changes through the back-reference chain\n */\nexport function bubbleUpChange(changedObject: object, evolution: Evolution) {\n\tconst parents = objectParents.get(changedObject)\n\tif (!parents) return\n\n\tfor (const { parent } of parents) {\n\t\t// Trigger deep watchers on parent\n\t\tconst parentDeepWatchers = deepWatchers.get(parent)\n\t\tif (parentDeepWatchers) for (const watcher of parentDeepWatchers) batch(watcher)\n\n\t\t// Continue bubbling up\n\t\tbubbleUpChange(parent, evolution)\n\t}\n}\n\nfunction hasParentWithDeepWatchers(obj: object): boolean {\n\tconst parents = objectParents.get(obj)\n\tif (!parents) return false\n\n\tfor (const { parent } of parents) {\n\t\tif (objectsWithDeepWatchers.has(parent)) return true\n\t\tif (hasParentWithDeepWatchers(parent)) return true\n\t}\n\treturn false\n}\n","import { recordTriggerLink } from './debug'\nimport { bubbleUpChange, objectsWithDeepWatchers } from './deep-watch-state'\nimport { getActiveEffect, isRunning } from './effect-context'\nimport { batch, effectTrackers, hasBatched, opaqueEffects, recordActivation } from './effects'\nimport { unwrap } from './proxy-state'\nimport { watchers } from './registry'\nimport { allProps, type Evolution, options, type ScopedCallback, type State } from './types'\n\nconst states = new WeakMap<object, State>()\n\nexport function addState(obj: any, evolution: Evolution) {\n\tobj = unwrap(obj)\n\tconst next = {}\n\tconst state = getState(obj)\n\tif (state) Object.assign(state, { evolution, next })\n\tstates.set(obj, next)\n}\n\n/**\n * Gets the current state of a reactive object for evolution tracking\n * @param obj - The reactive object\n * @returns The current state object\n */\nexport function getState(obj: any) {\n\tobj = unwrap(obj)\n\tlet state = states.get(obj)\n\tif (!state) {\n\t\tstate = {}\n\t\tstates.set(obj, state)\n\t}\n\treturn state\n}\n\nexport function collectEffects(\n\tobj: any,\n\tevolution: Evolution,\n\teffects: Set<ScopedCallback>,\n\tobjectWatchers: Map<any, Set<ScopedCallback>>,\n\t...keyChains: Iterable<any>[]\n) {\n\tconst sourceEffect = getActiveEffect()\n\tfor (const keys of keyChains)\n\t\tfor (const key of keys) {\n\t\t\tconst deps = objectWatchers.get(key)\n\t\t\tif (deps)\n\t\t\t\tfor (const effect of deps) {\n\t\t\t\t\tconst runningChain = isRunning(effect)\n\t\t\t\t\tif (runningChain) {\n\t\t\t\t\t\toptions.skipRunningEffect(effect, runningChain as any)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (!effects.has(effect)) {\n\t\t\t\t\t\teffects.add(effect)\n\t\t\t\t\t\tif (!hasBatched(effect)) recordActivation(effect, obj, evolution, key)\n\t\t\t\t\t}\n\t\t\t\t\tconst trackers = effectTrackers.get(effect)\n\t\t\t\t\trecordTriggerLink(sourceEffect, effect, obj, key, evolution)\n\t\t\t\t\tif (trackers) {\n\t\t\t\t\t\tfor (const tracker of trackers) tracker(obj, evolution, key)\n\t\t\t\t\t\ttrackers.delete(effect)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n}\n\n/**\n * Triggers effects for a single property change\n * @param obj - The object that changed\n * @param evolution - The type of change\n * @param prop - The property that changed\n */\nexport function touched1(obj: any, evolution: Evolution, prop: any) {\n\ttouched(obj, evolution, [prop])\n}\n\n/**\n * Triggers effects for property changes\n * @param obj - The object that changed\n * @param evolution - The type of change\n * @param props - The properties that changed\n */\nexport function touched(obj: any, evolution: Evolution, props?: Iterable<any>) {\n\tobj = unwrap(obj)\n\taddState(obj, evolution)\n\tconst objectWatchers = watchers.get(obj)\n\tif (objectWatchers) {\n\t\t// Note: we have to collect effects to remove duplicates in the specific case when no batch is running\n\t\tconst effects = new Set<ScopedCallback>()\n\t\tif (props) collectEffects(obj, evolution, effects, objectWatchers, [allProps], props)\n\t\telse collectEffects(obj, evolution, effects, objectWatchers, objectWatchers.keys())\n\t\toptions.touched(obj, evolution, props as any[] | undefined, effects)\n\t\tbatch(Array.from(effects))\n\t}\n\n\t// Bubble up changes if this object has deep watchers\n\tif (objectsWithDeepWatchers.has(obj)) {\n\t\tbubbleUpChange(obj, evolution)\n\t}\n}\n\n/**\n * Triggers only opaque effects for property changes\n * Used by deep-touch to ensure opaque listeners are notified even when deep optimization is active\n */\nexport function touchedOpaque(obj: any, evolution: Evolution, prop: any) {\n\tobj = unwrap(obj)\n\tconst objectWatchers = watchers.get(obj)\n\tif (!objectWatchers) return\n\n\tconst deps = objectWatchers.get(prop)\n\tif (!deps) return\n\n\tconst effects = new Set<ScopedCallback>()\n\tconst sourceEffect = getActiveEffect()\n\n\tfor (const effect of deps) {\n\t\tif (!opaqueEffects.has(effect)) continue\n\n\t\tconst runningChain = isRunning(effect)\n\t\tif (runningChain) {\n\t\t\toptions.skipRunningEffect(effect, runningChain as any)\n\t\t\tcontinue\n\t\t}\n\t\teffects.add(effect)\n\t\trecordActivation(effect, obj, evolution, prop)\n\t\tconst trackers = effectTrackers.get(effect)\n\t\trecordTriggerLink(sourceEffect, effect, obj, prop, evolution)\n\t\tif (trackers) {\n\t\t\tfor (const tracker of trackers) tracker(obj, evolution, prop)\n\t\t\ttrackers.delete(effect)\n\t\t}\n\t}\n\n\tif (effects.size > 0) {\n\t\toptions.touched(obj, evolution, [prop], effects)\n\t\tbatch(Array.from(effects))\n\t}\n}\n","import { nativeReactive, nonReactiveMark } from './types'\n\nexport const nonReactiveObjects = new WeakSet<object>()\nexport const immutables = new Set<(tested: any) => boolean>()\nexport const absent = Symbol('absent')\n\nfunction markNonReactive<T extends object[]>(...obj: T): T[0] {\n\tfor (const o of obj) {\n\t\ttry {\n\t\t\tObject.defineProperty(o, nonReactiveMark, {\n\t\t\t\tvalue: true,\n\t\t\t\twritable: false,\n\t\t\t\tenumerable: false,\n\t\t\t\tconfigurable: false,\n\t\t\t})\n\t\t} catch {}\n\t\tif (!(nonReactiveMark in (o as object))) nonReactiveObjects.add(o as object)\n\t}\n\treturn obj[0]\n}\n\nexport function nonReactiveClass<T extends (new (...args: any[]) => any)[]>(...cls: T): T[0] {\n\tfor (const c of cls) if (c) (c.prototype as any)[nonReactiveMark] = true\n\treturn cls[0]\n}\n\nexport function isNonReactive(obj: any): boolean {\n\tif (obj === null || typeof obj !== 'object') return true\n\tif (nonReactiveObjects.has(obj)) return true\n\tif ((obj as any)[nonReactiveMark]) return true\n\tfor (const fn of immutables) if (fn(obj)) return true\n\treturn false\n}\n\nexport function registerNativeReactivity(\n\toriginalClass: new (...args: any[]) => any,\n\treactiveClass: new (...args: any[]) => any\n) {\n\toriginalClass.prototype[nativeReactive] = reactiveClass\n\tnonReactiveClass(reactiveClass)\n}\n\nnonReactiveClass(Date, RegExp, Error, Promise, Function)\nif (typeof window !== 'undefined') {\n\tmarkNonReactive(window, document)\n\tnonReactiveClass(Node, Element, HTMLElement, EventTarget)\n}\n\nexport { markNonReactive as nonReactive }\n","import { addState, collectEffects, touched1, touchedOpaque } from './change'\nimport { bubbleUpChange, objectsWithDeepWatchers } from './deep-watch-state'\nimport { batch } from './effects'\nimport { isNonReactive } from './non-reactive-state'\nimport { unwrap } from './proxy-state'\nimport { effectParent, watchers } from './registry'\nimport { allProps, type Evolution, options, type ScopedCallback } from './types'\n\nfunction isObject(value: any): value is object {\n\treturn typeof value === 'object' && value !== null\n}\n\nfunction isObjectLike(value: unknown): value is object {\n\treturn isObject(value)\n}\n\nfunction getPrototypeToken(value: any): object | null | undefined {\n\tif (!isObjectLike(value)) return undefined\n\tif (Array.isArray(value)) return Array.prototype\n\ttry {\n\t\treturn value.constructor\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\nexport function shouldRecurseTouch(oldValue: any, newValue: any): boolean {\n\tif (oldValue === newValue) return false\n\tif (!isObjectLike(oldValue) || !isObjectLike(newValue)) return false\n\tif (isNonReactive(oldValue) || isNonReactive(newValue)) return false\n\treturn getPrototypeToken(oldValue) === getPrototypeToken(newValue)\n}\n\n/**\n * Centralized function to handle property change notifications with optional recursive touch\n * @param targetObj - The object whose property changed\n * @param prop - The property that changed\n * @param oldValue - The old value (before change)\n * @param newValue - The new value (after change)\n * @param hadProperty - Whether the property existed before (for add vs set)\n */\nexport function notifyPropertyChange(\n\ttargetObj: any,\n\tprop: any,\n\toldValue: any,\n\tnewValue: any,\n\thadProperty: boolean\n) {\n\tconst evolution: Evolution = { type: hadProperty ? 'set' : 'add', prop }\n\n\tif (\n\t\toptions.recursiveTouching &&\n\t\toldValue !== undefined &&\n\t\tshouldRecurseTouch(oldValue, newValue)\n\t) {\n\t\tconst unwrappedObj = unwrap(targetObj)\n\t\tconst origin = { obj: unwrappedObj, prop }\n\t\t// Deep touch: only notify nested property changes with origin filtering\n\t\t// Don't notify direct property change - the whole point is to avoid parent effects re-running\n\t\tdispatchNotifications(recursiveTouch(oldValue, newValue, new WeakMap(), [], origin))\n\n\t\t// Notify opaque listeners (like memoize) that always want to know about identity changes\n\t\ttouchedOpaque(targetObj, evolution, prop)\n\t} else {\n\t\ttouched1(targetObj, evolution, prop)\n\t}\n}\n\ntype VisitedPairs = WeakMap<object, WeakSet<object>>\ntype PendingNotification = {\n\ttarget: any\n\tevolution: Evolution\n\tprop: any\n\torigin?: { obj: object; prop: PropertyKey } // The property access that triggered this deep touch\n}\n\nfunction hasVisitedPair(visited: VisitedPairs, oldObj: object, newObj: object): boolean {\n\tlet mapped = visited.get(oldObj)\n\tif (!mapped) {\n\t\tmapped = new WeakSet<object>()\n\t\tvisited.set(oldObj, mapped)\n\t}\n\tif (mapped.has(newObj)) return true\n\tmapped.add(newObj)\n\treturn false\n}\n\nfunction collectObjectKeys(obj: any): Set<PropertyKey> {\n\tconst keys = new Set<PropertyKey>(Reflect.ownKeys(obj))\n\tlet proto = Object.getPrototypeOf(obj)\n\t// Continue walking while prototype exists and doesn't have its own constructor\n\t// This stops at Object.prototype (has own constructor) and class prototypes (have own constructor)\n\t// but continues for data prototypes (Object.create({}), Object.create(instance), etc.)\n\twhile (proto && !Object.hasOwn(proto, 'constructor')) {\n\t\tfor (const key of Reflect.ownKeys(proto)) keys.add(key)\n\t\tproto = Object.getPrototypeOf(proto)\n\t}\n\treturn keys\n}\n\nexport function recursiveTouch(\n\toldValue: any,\n\tnewValue: any,\n\tvisited: VisitedPairs = new WeakMap(),\n\tnotifications: PendingNotification[] = [],\n\torigin?: { obj: object; prop: PropertyKey }\n): PendingNotification[] {\n\tif (!shouldRecurseTouch(oldValue, newValue)) return notifications\n\tif (!isObjectLike(oldValue) || !isObjectLike(newValue)) return notifications\n\tif (hasVisitedPair(visited, oldValue, newValue)) return notifications\n\n\tif (Array.isArray(oldValue) && Array.isArray(newValue)) {\n\t\tdiffArrayElements(oldValue, newValue, visited, notifications, origin)\n\t\treturn notifications\n\t}\n\n\tdiffObjectProperties(oldValue, newValue, visited, notifications, origin)\n\treturn notifications\n}\n\nfunction diffArrayElements(\n\toldArray: any[] | readonly any[],\n\tnewArray: any[] | readonly any[],\n\t_visited: VisitedPairs,\n\tnotifications: PendingNotification[],\n\torigin?: { obj: object; prop: PropertyKey }\n) {\n\tconst local: PendingNotification[] = []\n\tconst oldLength = oldArray.length\n\tconst newLength = newArray.length\n\tconst max = Math.max(oldLength, newLength)\n\n\tfor (let index = 0; index < max; index++) {\n\t\tconst hasOld = index < oldLength\n\t\tconst hasNew = index < newLength\n\t\tif (hasOld && !hasNew) {\n\t\t\tlocal.push({ target: oldArray, evolution: { type: 'del', prop: index }, prop: index, origin })\n\t\t\tcontinue\n\t\t}\n\t\tif (!hasOld && hasNew) {\n\t\t\tlocal.push({ target: oldArray, evolution: { type: 'add', prop: index }, prop: index, origin })\n\t\t\tcontinue\n\t\t}\n\t\tif (!hasOld || !hasNew) continue\n\t\tconst oldEntry = unwrap(oldArray[index])\n\t\tconst newEntry = unwrap(newArray[index])\n\t\tif (!Object.is(oldEntry, newEntry)) {\n\t\t\tlocal.push({ target: oldArray, evolution: { type: 'set', prop: index }, prop: index, origin })\n\t\t}\n\t}\n\n\tif (oldLength !== newLength)\n\t\tlocal.push({\n\t\t\ttarget: oldArray,\n\t\t\tevolution: { type: 'set', prop: 'length' },\n\t\t\tprop: 'length',\n\t\t\torigin,\n\t\t})\n\n\tnotifications.push(...local)\n}\n\nfunction diffObjectProperties(\n\toldObj: any,\n\tnewObj: any,\n\tvisited: VisitedPairs,\n\tnotifications: PendingNotification[],\n\torigin?: { obj: object; prop: PropertyKey }\n) {\n\tconst oldKeys = collectObjectKeys(oldObj)\n\tconst newKeys = collectObjectKeys(newObj)\n\tconst local: PendingNotification[] = []\n\n\tfor (const key of oldKeys)\n\t\tif (!newKeys.has(key))\n\t\t\tlocal.push({ target: oldObj, evolution: { type: 'del', prop: key }, prop: key, origin })\n\n\tfor (const key of newKeys)\n\t\tif (!oldKeys.has(key))\n\t\t\tlocal.push({ target: oldObj, evolution: { type: 'add', prop: key }, prop: key, origin })\n\n\tfor (const key of newKeys) {\n\t\tif (!oldKeys.has(key)) continue\n\t\tconst oldEntry = unwrap((oldObj as any)[key])\n\t\tconst newEntry = unwrap((newObj as any)[key])\n\t\tif (shouldRecurseTouch(oldEntry, newEntry)) {\n\t\t\trecursiveTouch(oldEntry, newEntry, visited, notifications, origin)\n\t\t} else if (!Object.is(oldEntry, newEntry)) {\n\t\t\tlocal.push({ target: oldObj, evolution: { type: 'set', prop: key }, prop: key, origin })\n\t\t}\n\t}\n\n\tnotifications.push(...local)\n}\n\n/**\n * Checks if an effect or any of its ancestors is in the allowed set\n */\nfunction hasAncestorInSet(effect: ScopedCallback, allowedSet: Set<ScopedCallback>): boolean {\n\tlet current: ScopedCallback | undefined = effect\n\tconst visited = new WeakSet<ScopedCallback>()\n\twhile (current && !visited.has(current)) {\n\t\tvisited.add(current)\n\t\tif (allowedSet.has(current)) return true\n\t\tcurrent = effectParent.get(current)\n\t}\n\treturn false\n}\n\nexport function dispatchNotifications(notifications: PendingNotification[]) {\n\tif (!notifications.length) return\n\tconst combinedEffects = new Set<ScopedCallback>()\n\n\t// Extract origin from first notification (all should have the same origin from a single deep touch)\n\tconst origin = notifications[0]?.origin\n\tlet allowedEffects: Set<ScopedCallback> | undefined\n\n\t// If origin exists, compute allowed effects (those that depend on origin.obj[origin.prop])\n\tif (origin) {\n\t\tallowedEffects = new Set<ScopedCallback>()\n\t\tconst originWatchers = watchers.get(origin.obj)\n\t\tif (originWatchers) {\n\t\t\tconst originEffects = new Set<ScopedCallback>()\n\t\t\tcollectEffects(\n\t\t\t\torigin.obj,\n\t\t\t\t{ type: 'set', prop: origin.prop },\n\t\t\t\toriginEffects,\n\t\t\t\toriginWatchers,\n\t\t\t\t[allProps],\n\t\t\t\t[origin.prop]\n\t\t\t)\n\t\t\tfor (const effect of originEffects) allowedEffects.add(effect)\n\t\t}\n\t\t// If no allowed effects, skip all notifications (no one should be notified)\n\t\tif (allowedEffects.size === 0) return\n\t}\n\n\tfor (const { target, evolution, prop } of notifications) {\n\t\tif (!isObjectLike(target)) continue\n\t\tconst obj = unwrap(target)\n\t\taddState(obj, evolution)\n\t\tconst objectWatchers = watchers.get(obj)\n\t\tlet currentEffects: Set<ScopedCallback> | undefined\n\t\tconst propsArray = [prop]\n\t\tif (objectWatchers) {\n\t\t\tcurrentEffects = new Set<ScopedCallback>()\n\t\t\tcollectEffects(obj, evolution, currentEffects, objectWatchers, [allProps], propsArray)\n\n\t\t\t// Filter effects by ancestor chain if origin exists\n\t\t\t// Include effects that either directly depend on origin or have an ancestor that does\n\t\t\tif (origin && allowedEffects) {\n\t\t\t\tconst filteredEffects = new Set<ScopedCallback>()\n\t\t\t\tfor (const effect of currentEffects) {\n\t\t\t\t\t// Check if effect itself is allowed OR has an ancestor that is allowed\n\t\t\t\t\tif (allowedEffects.has(effect) || hasAncestorInSet(effect, allowedEffects)) {\n\t\t\t\t\t\tfilteredEffects.add(effect)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcurrentEffects = filteredEffects\n\t\t\t}\n\n\t\t\tfor (const effect of currentEffects) combinedEffects.add(effect)\n\t\t}\n\t\toptions.touched(obj, evolution, propsArray, currentEffects)\n\t\tif (objectsWithDeepWatchers.has(obj)) bubbleUpChange(obj, evolution)\n\t}\n\tif (combinedEffects.size) batch([...combinedEffects])\n}\n","import { decorator } from '../decorator'\nimport { mixin } from '../mixins'\nimport { isOwnAccessor, ReflectGet, ReflectSet } from '../utils'\nimport { touched1 } from './change'\nimport { notifyPropertyChange } from './deep-touch'\nimport {\n\taddBackReference,\n\tbubbleUpChange,\n\tneedsBackReferences,\n\tobjectsWithDeepWatchers,\n\tremoveBackReference,\n} from './deep-watch-state'\nimport { withEffect } from './effect-context'\nimport { absent, isNonReactive } from './non-reactive-state'\nimport {\n\tgetExistingProxy,\n\tproxyToObject,\n\tstoreProxyRelationship,\n\ttrackProxyObject,\n\tunwrap,\n} from './proxy-state'\nimport { dependant } from './tracking'\nimport {\n\tallProps,\n\tnativeReactive,\n\tnonReactiveMark,\n\toptions,\n\tprototypeForwarding,\n\tReactiveError,\n\tReactiveErrorCode,\n\tunreactiveProperties,\n} from './types'\n\nconst hasReentry: any[] = []\nconst reactiveHandlers = {\n\t[Symbol.toStringTag]: 'MutTs Reactive',\n\tget(obj: any, prop: PropertyKey, receiver: any) {\n\t\tif (prop === nonReactiveMark) return false\n\t\tconst unwrappedObj = unwrap(obj)\n\t\t// Check if this property is marked as unreactive\n\t\tif (unwrappedObj[unreactiveProperties]?.has(prop) || typeof prop === 'symbol')\n\t\t\treturn ReflectGet(obj, prop, receiver)\n\n\t\t// Special-case: array wrappers use prototype forwarding + numeric accessors.\n\t\t// With options.instanceMembers=true, inherited reads are normally not tracked, which breaks\n\t\t// reactivity for array indices/length (they appear inherited on the proxy).\n\t\tconst isArrayCase =\n\t\t\tprototypeForwarding in obj &&\n\t\t\t// biome-ignore lint/suspicious/useIsArray: This is the whole point here\n\t\t\tobj[prototypeForwarding] instanceof Array &&\n\t\t\ttypeof prop === 'string' &&\n\t\t\t(prop === 'length' || !Number.isNaN(Number(prop)))\n\t\tif (isArrayCase) {\n\t\t\tdependant(obj, prop === 'length' ? 'length' : Number(prop))\n\t\t}\n\t\t// Check if property exists and if it's an own property (cached for later use)\n\t\tconst hasProp = Reflect.has(receiver, prop)\n\t\tconst isOwnProp = hasProp && Object.hasOwn(receiver, prop)\n\t\tconst isInheritedAccess = hasProp && !isOwnProp\n\n\t\t// For accessor properties, check the unwrapped object to see if it's an accessor\n\t\t// This ensures ignoreAccessors works correctly even after operations like Object.setPrototypeOf\n\t\tconst shouldIgnoreAccessor =\n\t\t\toptions.ignoreAccessors &&\n\t\t\tisOwnProp &&\n\t\t\t(isOwnAccessor(receiver, prop) || isOwnAccessor(unwrappedObj, prop))\n\n\t\t// Depend if...\n\t\tif (\n\t\t\t!hasProp ||\n\t\t\t(!(options.instanceMembers && isInheritedAccess && obj instanceof Object) &&\n\t\t\t\t!shouldIgnoreAccessor)\n\t\t)\n\t\t\tdependant(obj, prop)\n\n\t\t// Watch the whole prototype chain when requested or for null-proto objects\n\t\tif (isInheritedAccess && (!options.instanceMembers || !(obj instanceof Object))) {\n\t\t\tlet current = reactiveObject(Object.getPrototypeOf(obj))\n\t\t\twhile (current && current !== Object.prototype) {\n\t\t\t\tdependant(current, prop)\n\t\t\t\tif (Object.hasOwn(current, prop)) break\n\t\t\t\tlet next = reactiveObject(Object.getPrototypeOf(current))\n\t\t\t\tif (next === current) {\n\t\t\t\t\tnext = reactiveObject(Object.getPrototypeOf(unwrap(current)))\n\t\t\t\t}\n\t\t\t\tcurrent = next\n\t\t\t}\n\t\t}\n\t\tconst value = ReflectGet(obj, prop, receiver)\n\t\tif (typeof value === 'object' && value !== null) {\n\t\t\tconst reactiveValue = reactiveObject(value)\n\n\t\t\t// Only create back-references if this object needs them\n\t\t\tif (needsBackReferences(obj)) {\n\t\t\t\taddBackReference(reactiveValue, obj, prop)\n\t\t\t}\n\n\t\t\treturn reactiveValue\n\t\t}\n\t\treturn value\n\t},\n\tset(obj: any, prop: PropertyKey, value: any, receiver: any): boolean {\n\t\t// Read old value directly from unwrapped object to avoid triggering dependency tracking\n\t\tconst unwrappedObj = unwrap(obj)\n\t\tconst unwrappedReceiver = unwrap(receiver)\n\n\t\t// Check if this property is marked as unreactive\n\t\tif (unwrappedObj[unreactiveProperties]?.has(prop) || unwrappedObj !== unwrappedReceiver)\n\t\t\treturn ReflectSet(obj, prop, value, receiver)\n\t\t// Really specific case for when Array is forwarder, in order to let it manage the reactivity\n\t\tconst isArrayCase =\n\t\t\tprototypeForwarding in obj &&\n\t\t\t// biome-ignore lint/suspicious/useIsArray: This is the whole point here\n\t\t\tobj[prototypeForwarding] instanceof Array &&\n\t\t\t(!Number.isNaN(Number(prop)) || prop === 'length')\n\t\tconst newValue = unwrap(value)\n\n\t\tif (isArrayCase) {\n\t\t\t;(obj as any)[prop] = newValue\n\t\t\treturn true\n\t\t}\n\t\t// Read old value, using withEffect(undefined, ...) for getter-only accessors to avoid\n\t\t// breaking memoization dependency tracking during SET operations\n\t\tlet oldVal = absent\n\t\tif (Reflect.has(unwrappedReceiver, prop)) {\n\t\t\t// Check descriptor on both receiver and target to handle proxy cases\n\t\t\tconst receiverDesc = Object.getOwnPropertyDescriptor(unwrappedReceiver, prop)\n\t\t\tconst targetDesc = Object.getOwnPropertyDescriptor(unwrappedObj, prop)\n\t\t\tconst desc = receiverDesc || targetDesc\n\t\t\t// We *need* to use `receiver` and not `unwrappedObj` here, otherwise we break\n\t\t\t// the dependency tracking for memoized getters\n\t\t\tif (desc?.get && !desc?.set) {\n\t\t\t\toldVal = withEffect(undefined, () => Reflect.get(unwrappedObj, prop, receiver))\n\t\t\t} else {\n\t\t\t\toldVal = withEffect(undefined, () => Reflect.get(unwrappedObj, prop, receiver))\n\t\t\t}\n\t\t}\n\t\tif (objectsWithDeepWatchers.has(obj)) {\n\t\t\tif (typeof oldVal === 'object' && oldVal !== null) {\n\t\t\t\tremoveBackReference(oldVal, obj, prop)\n\t\t\t}\n\t\t\tif (typeof newValue === 'object' && newValue !== null) {\n\t\t\t\tconst reactiveValue = reactiveObject(newValue)\n\t\t\t\taddBackReference(reactiveValue, obj, prop)\n\t\t\t}\n\t\t}\n\n\t\tif (oldVal !== newValue) {\n\t\t\t// For getter-only accessors, Reflect.set() may fail, but we still return true\n\t\t\t// to avoid throwing errors. Only proceed with change notifications if set succeeded.\n\t\t\tif (ReflectSet(obj, prop, newValue, receiver)) {\n\t\t\t\tnotifyPropertyChange(obj, prop, oldVal, newValue, oldVal !== absent)\n\t\t\t}\n\t\t}\n\t\treturn true\n\t},\n\thas(obj: any, prop: PropertyKey): boolean {\n\t\tif (hasReentry.includes(obj))\n\t\t\tthrow new ReactiveError(\n\t\t\t\t`[reactive] Circular dependency detected in 'has' check for property '${String(prop)}'`,\n\t\t\t\t{\n\t\t\t\t\tcode: ReactiveErrorCode.CycleDetected,\n\t\t\t\t\tcycle: [], // We don't have the full cycle here, but we know it involves obj\n\t\t\t\t}\n\t\t\t)\n\t\thasReentry.push(obj)\n\t\tdependant(obj, prop)\n\t\tconst rv = Reflect.has(obj, prop)\n\t\thasReentry.pop()\n\t\treturn rv\n\t},\n\tdeleteProperty(obj: any, prop: PropertyKey): boolean {\n\t\tif (!Object.hasOwn(obj, prop)) return false\n\n\t\tconst oldVal = (obj as any)[prop]\n\n\t\t// Remove back-references if this object has deep watchers\n\t\tif (objectsWithDeepWatchers.has(obj) && typeof oldVal === 'object' && oldVal !== null) {\n\t\t\tremoveBackReference(oldVal, obj, prop)\n\t\t}\n\n\t\tdelete (obj as any)[prop]\n\t\ttouched1(obj, { type: 'del', prop }, prop)\n\n\t\t// Bubble up changes if this object has deep watchers\n\t\tif (objectsWithDeepWatchers.has(obj)) {\n\t\t\tbubbleUpChange(obj, { type: 'del', prop })\n\t\t}\n\n\t\treturn true\n\t},\n\tgetPrototypeOf(obj: any): object | null {\n\t\tif (prototypeForwarding in obj) return obj[prototypeForwarding]\n\t\treturn Object.getPrototypeOf(obj)\n\t},\n\tsetPrototypeOf(obj: any, proto: object | null): boolean {\n\t\tif (prototypeForwarding in obj) return false\n\t\tObject.setPrototypeOf(obj, proto)\n\t\treturn true\n\t},\n\townKeys(obj: any): (string | symbol)[] {\n\t\tdependant(obj, allProps)\n\t\treturn Reflect.ownKeys(obj)\n\t},\n} as const\n\nconst reactiveClasses = new WeakSet<Function>()\n\n// Create the ReactiveBase mixin\n/**\n * Base mixin for reactive classes that provides proper constructor reactivity\n * Solves constructor reactivity issues in complex inheritance trees\n */\nexport const ReactiveBase = mixin((base) => {\n\tclass ReactiveMixin extends base {\n\t\tconstructor(...args: any[]) {\n\t\t\tsuper(...args)\n\t\t\t// Only apply reactive transformation if the class is marked with @reactive\n\t\t\t// This allows the mixin to work properly with method inheritance\n\t\t\t// biome-ignore lint/correctness/noConstructorReturn: This is the whole point here\n\t\t\treturn reactiveClasses.has(new.target) ? reactive(this) : this\n\t\t}\n\t}\n\treturn ReactiveMixin\n})\nfunction reactiveObject<T>(anyTarget: T): T {\n\tif (!anyTarget || typeof anyTarget !== 'object') return anyTarget\n\tconst target = anyTarget as any\n\t// If target is already a proxy, return it\n\tif (isNonReactive(target)) return target as T\n\tconst isProxy = proxyToObject.has(target)\n\tif (isProxy) return target as T\n\n\t// If we already have a proxy for this object, return it (optimized: get returns undefined if not found)\n\tconst existing = getExistingProxy(target)\n\tif (existing !== undefined) return existing as T\n\n\tconst proxied =\n\t\tnativeReactive in target && !(target instanceof target[nativeReactive])\n\t\t\t? new target[nativeReactive](target)\n\t\t\t: target\n\tif (proxied !== target) trackProxyObject(proxied, target)\n\tconst proxy = new Proxy(proxied, reactiveHandlers)\n\n\t// Store the relationships\n\tstoreProxyRelationship(target, proxy)\n\treturn proxy as T\n}\n\n/**\n * Main decorator for making classes reactive\n * Automatically makes class instances reactive when created\n */\nexport const reactive = decorator({\n\tclass(original) {\n\t\tif (original.prototype instanceof ReactiveBase) {\n\t\t\treactiveClasses.add(original)\n\t\t\treturn original\n\t\t}\n\n\t\tclass Reactive extends original {\n\t\t\tconstructor(...args: any[]) {\n\t\t\t\tsuper(...args)\n\t\t\t\tif (new.target !== Reactive && !reactiveClasses.has(new.target))\n\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t`${(original as any).name} has been inherited by ${this.constructor.name} that is not reactive.\n@reactive decorator must be applied to the leaf class OR classes have to extend ReactiveBase.`\n\t\t\t\t\t)\n\t\t\t\t// biome-ignore lint/correctness/noConstructorReturn: This is the whole point here\n\t\t\t\treturn reactive(this)\n\t\t\t}\n\t\t}\n\t\tObject.defineProperty(Reactive, 'name', {\n\t\t\tvalue: `Reactive<${original.name}>`,\n\t\t})\n\t\treturn Reactive as any\n\t},\n\tget(original: any) {\n\t\treturn reactiveObject(original)\n\t},\n\tdefault: reactiveObject,\n})\n\n/**\n * Gets the original, non-reactive object from a reactive proxy\n * @param proxy - The reactive proxy\n * @returns The original object\n */\nexport { isReactive, objectToProxy, proxyToObject, unwrap } from './proxy-state'\n","import {\n\tdeepWatchers,\n\teffectToDeepWatchedObjects,\n\tobjectsWithDeepWatchers,\n} from './deep-watch-state'\nimport { effect } from './effects'\nimport { isNonReactive } from './non-reactive-state'\nimport { reactive, unwrap } from './proxy'\nimport { markWithRoot } from './registry'\nimport { options, type ScopedCallback } from './types'\n\nfunction isObject(value: any): value is object {\n\treturn typeof value === 'object' && value !== null\n}\n\nexport {\n\taddBackReference,\n\tbubbleUpChange,\n\tdeepWatchers,\n\teffectToDeepWatchedObjects,\n\tneedsBackReferences,\n\tobjectParents,\n\tobjectsWithDeepWatchers,\n\tremoveBackReference,\n} from './deep-watch-state'\n\n/**\n * Deep watch an object and all its nested properties\n * @param target - The object to watch deeply\n * @param callback - The callback to call when any nested property changes\n * @param options - Options for the deep watch\n * @returns A cleanup function to stop watching\n */\n/**\n * Sets up deep watching for an object, tracking all nested property changes\n * @param target - The object to watch\n * @param callback - The callback to call when changes occur\n * @param options - Options for deep watching\n * @returns A cleanup function to stop deep watching\n */\nexport function deepWatch<T extends object>(\n\ttarget: T,\n\tcallback: (value: T) => void,\n\t{ immediate = false } = {}\n): (() => void) | undefined {\n\tif (target === null || target === undefined) return undefined\n\tif (typeof target !== 'object') throw new Error('Target of deep watching must be an object')\n\t// Create a wrapper callback that matches ScopedCallback signature\n\tconst wrappedCallback: ScopedCallback = markWithRoot(() => callback(target), callback)\n\n\t// Use the existing effect system to register dependencies\n\treturn effect(() => {\n\t\t// Mark the target object as having deep watchers\n\t\tobjectsWithDeepWatchers.add(target)\n\n\t\t// Track which objects this effect is watching for cleanup\n\t\tlet effectObjects = effectToDeepWatchedObjects.get(wrappedCallback)\n\t\tif (!effectObjects) {\n\t\t\teffectObjects = new Set()\n\t\t\teffectToDeepWatchedObjects.set(wrappedCallback, effectObjects)\n\t\t}\n\t\teffectObjects!.add(target)\n\n\t\t// Traverse the object graph and register dependencies\n\t\t// This will re-run every time the effect runs, ensuring we catch all changes\n\t\tconst visited = new WeakSet()\n\t\tfunction traverseAndTrack(obj: any, depth = 0) {\n\t\t\t// Prevent infinite recursion and excessive depth\n\t\t\tif (!obj || visited.has(obj) || !isObject(obj) || depth > options.maxDeepWatchDepth) return\n\t\t\t// Do not traverse into unreactive objects\n\t\t\tif (isNonReactive(obj)) return\n\t\t\tvisited.add(obj)\n\n\t\t\t// Mark this object as having deep watchers\n\t\t\tobjectsWithDeepWatchers.add(obj)\n\t\t\teffectObjects!.add(obj)\n\n\t\t\t// Traverse all properties to register dependencies\n\t\t\t// unwrap to avoid kicking dependency\n\t\t\tfor (const key in unwrap(obj)) {\n\t\t\t\tif (Object.hasOwn(obj, key)) {\n\t\t\t\t\t// Access the property to register dependency\n\t\t\t\t\tconst value = (obj as any)[key]\n\t\t\t\t\t// Make the value reactive if it's an object\n\t\t\t\t\tconst reactiveValue =\n\t\t\t\t\t\ttypeof value === 'object' && value !== null ? reactive(value) : value\n\t\t\t\t\ttraverseAndTrack(reactiveValue, depth + 1)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Also handle array indices and length\n\t\t\t// biome-ignore lint/suspicious/useIsArray: Check for both native arrays and reactive arrays\n\t\t\tif (Array.isArray(obj) || obj instanceof Array) {\n\t\t\t\t// Access array length to register dependency on length changes\n\t\t\t\tconst length = obj.length\n\n\t\t\t\t// Access all current array elements to register dependencies\n\t\t\t\tfor (let i = 0; i < length; i++) {\n\t\t\t\t\t// Access the array element to register dependency\n\t\t\t\t\tconst value = obj[i]\n\t\t\t\t\t// Make the value reactive if it's an object\n\t\t\t\t\tconst reactiveValue =\n\t\t\t\t\t\ttypeof value === 'object' && value !== null ? reactive(value) : value\n\t\t\t\t\ttraverseAndTrack(reactiveValue, depth + 1)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Handle Set values (deep watch values only, not keys since Sets don't have separate keys)\n\t\t\telse if (obj instanceof Set) {\n\t\t\t\t// Access all Set values to register dependencies\n\t\t\t\tfor (const value of obj) {\n\t\t\t\t\t// Make the value reactive if it's an object\n\t\t\t\t\tconst reactiveValue =\n\t\t\t\t\t\ttypeof value === 'object' && value !== null ? reactive(value) : value\n\t\t\t\t\ttraverseAndTrack(reactiveValue, depth + 1)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Handle Map values (deep watch values only, not keys)\n\t\t\telse if (obj instanceof Map) {\n\t\t\t\t// Access all Map values to register dependencies\n\t\t\t\tfor (const [_key, value] of obj) {\n\t\t\t\t\t// Make the value reactive if it's an object\n\t\t\t\t\tconst reactiveValue =\n\t\t\t\t\t\ttypeof value === 'object' && value !== null ? reactive(value) : value\n\t\t\t\t\ttraverseAndTrack(reactiveValue, depth + 1)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Note: WeakSet and WeakMap cannot be iterated, so we can't deep watch their contents\n\t\t\t// They will only trigger when the collection itself is replaced\n\t\t}\n\n\t\t// Traverse the target object to register all dependencies\n\t\t// This will register dependencies on all current properties and array elements\n\t\ttraverseAndTrack(target)\n\n\t\t// Only call the callback if immediate is true or if it's not the first run\n\t\tif (immediate) callback(target)\n\t\timmediate = true\n\n\t\t// Return a cleanup function that properly removes deep watcher tracking\n\t\treturn () => {\n\t\t\t// Get the objects this effect was watching\n\t\t\tconst effectObjects = effectToDeepWatchedObjects.get(wrappedCallback)\n\t\t\tif (effectObjects) {\n\t\t\t\t// Remove deep watcher tracking from all objects this effect was watching\n\t\t\t\tfor (const obj of effectObjects) {\n\t\t\t\t\t// Check if this object still has other deep watchers\n\t\t\t\t\tconst watchers = deepWatchers.get(obj)\n\t\t\t\t\tif (watchers) {\n\t\t\t\t\t\t// Remove this effect's callback from the watchers\n\t\t\t\t\t\twatchers.delete(wrappedCallback)\n\n\t\t\t\t\t\t// If no more watchers, remove the object from deep watchers tracking\n\t\t\t\t\t\tif (watchers.size === 0) {\n\t\t\t\t\t\t\tdeepWatchers.delete(obj)\n\t\t\t\t\t\t\tobjectsWithDeepWatchers.delete(obj)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// No watchers found, remove from deep watchers tracking\n\t\t\t\t\t\tobjectsWithDeepWatchers.delete(obj)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Clean up the tracking data\n\t\t\t\teffectToDeepWatchedObjects.delete(wrappedCallback)\n\t\t\t}\n\t\t}\n\t})\n}\n","import { decorator, type GenericClassDecorator } from '../decorator'\nimport { deepWatch } from './deep-watch'\nimport { withEffect } from './effect-context'\nimport { effect, getActiveEffect, untracked } from './effects'\nimport { isNonReactive, nonReactiveClass, nonReactiveObjects } from './non-reactive-state'\nimport { unwrap } from './proxy-state'\nimport { dependant } from './tracking'\nimport { markWithRoot } from './registry'\nimport {\n\ttype DependencyAccess,\n\tnonReactiveMark,\n\ttype ScopedCallback,\n\tunreactiveProperties,\n} from './types'\n\n/**\n * Symbol for accessing the cleanup function on cleaned objects\n */\nexport const cleanup = Symbol('cleanup')\n\n//#region watch\n\nconst unsetYet = Symbol('unset-yet')\n/**\n * Options for the watch function\n */\nexport interface WatchOptions {\n\t/** Whether to call the callback immediately */\n\timmediate?: boolean\n\t/** Whether to watch nested properties */\n\tdeep?: boolean\n}\n\n/**\n * Watches a reactive value and calls a callback when it changes\n * @param value - Function that returns the value to watch\n * @param changed - Callback to call when the value changes\n * @param options - Watch options\n * @returns Cleanup function to stop watching\n */\nexport function watch<T>(\n\tvalue: (dep: DependencyAccess) => T,\n\tchanged: (value: T, oldValue?: T) => void,\n\toptions?: Omit<WatchOptions, 'deep'> & { deep?: false }\n): ScopedCallback\n/**\n * Watches a reactive value with deep watching enabled\n * @param value - Function that returns the value to watch\n * @param changed - Callback to call when the value changes\n * @param options - Watch options with deep watching enabled\n * @returns Cleanup function to stop watching\n */\nexport function watch<T extends object | any[]>(\n\tvalue: (dep: DependencyAccess) => T,\n\tchanged: (value: T, oldValue?: T) => void,\n\toptions?: Omit<WatchOptions, 'deep'> & { deep: true }\n): ScopedCallback\n/**\n * Watches a reactive object directly\n * @param value - The reactive object to watch\n * @param changed - Callback to call when the object changes\n * @param options - Watch options\n * @returns Cleanup function to stop watching\n */\nexport function watch<T extends object | any[]>(\n\tvalue: T,\n\tchanged: (value: T) => void,\n\toptions?: WatchOptions\n): ScopedCallback\n\nexport function watch(\n\tvalue: any, //object | ((dep: DependencyAccess) => object),\n\tchanged: (value?: object, oldValue?: object) => void,\n\toptions: any = {}\n) {\n\treturn typeof value === 'function'\n\t\t? watchCallBack(value, changed, options)\n\t\t: typeof value === 'object' && value !== null\n\t\t\t? watchObject(value, changed, options)\n\t\t\t: (() => {\n\t\t\t\t\tthrow new Error('watch: value must be a function or an object')\n\t\t\t\t})()\n}\n\nfunction watchObject(\n\tvalue: object,\n\tchanged: (value: object) => void,\n\t{ immediate = false, deep = false } = {}\n): ScopedCallback {\n\tconst myParentEffect = getActiveEffect()\n\tif (deep) return deepWatch(value, changed, { immediate })!\n\treturn effect(\n\t\tfunction watchObjectEffect() {\n\t\t\tdependant(value)\n\t\t\tif (immediate) withEffect(myParentEffect, () => changed(value))\n\t\t\timmediate = true\n\t\t}\n\t)\n}\n\nfunction watchCallBack<T>(\n\tvalue: (dep: DependencyAccess) => T,\n\tchanged: (value: T, oldValue?: T) => void,\n\t{ immediate = false, deep = false } = {}\n): ScopedCallback {\n\tconst myParentEffect = getActiveEffect()\n\tlet oldValue: T | typeof unsetYet = unsetYet\n\tlet deepCleanup: ScopedCallback | undefined\n\tconst cbCleanup = effect(\n\t\tmarkWithRoot(function watchCallBackEffect(access) {\n\t\t\tconst newValue = value(access)\n\t\t\tif (oldValue !== newValue)\n\t\t\t\twithEffect(\n\t\t\t\t\tmyParentEffect,\n\t\t\t\t\t() => {\n\t\t\t\t\t\tif (oldValue === unsetYet) {\n\t\t\t\t\t\t\tif (immediate) changed(newValue)\n\t\t\t\t\t\t} else changed(newValue, oldValue)\n\t\t\t\t\t\toldValue = newValue\n\t\t\t\t\t\tif (deep) {\n\t\t\t\t\t\t\tif (deepCleanup) deepCleanup()\n\t\t\t\t\t\t\tdeepCleanup = deepWatch(\n\t\t\t\t\t\t\t\tnewValue as object,\n\t\t\t\t\t\t\t\t(value) => changed(value as T, value as T)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t}, value)\n\t)\n\treturn () => {\n\t\tcbCleanup()\n\t\tif (deepCleanup) deepCleanup()\n\t}\n}\n\n//#endregion\n\n//#region nonReactive\n\n/**\n * Mark an object as non-reactive. This object and all its properties will never be made reactive.\n * @param obj - The object to mark as non-reactive\n */\nfunction deepNonReactive<T>(obj: T): T {\n\tobj = unwrap(obj)\n\tif (isNonReactive(obj)) return obj\n\ttry {\n\t\tObject.defineProperty(obj as object, nonReactiveMark, {\n\t\t\tvalue: true,\n\t\t\twritable: false,\n\t\t\tenumerable: false,\n\t\t\tconfigurable: true,\n\t\t})\n\t} catch {}\n\tif (!(nonReactiveMark in (obj as object))) nonReactiveObjects.add(obj as object)\n\t//for (const key in obj) deepNonReactive(obj[key])\n\treturn obj\n}\nfunction unreactiveApplication<T extends object>(...args: (keyof T)[]): GenericClassDecorator<T>\nfunction unreactiveApplication<T extends object>(obj: T): T\nfunction unreactiveApplication<T extends object>(\n\targ1: T | keyof T,\n\t...args: (keyof T)[]\n): GenericClassDecorator<T> | T {\n\treturn typeof arg1 === 'object'\n\t\t? deepNonReactive(arg1)\n\t\t: (((original) => {\n\t\t\t\t// Copy the parent's unreactive properties if they exist\n\t\t\t\toriginal.prototype[unreactiveProperties] = new Set<PropertyKey>(\n\t\t\t\t\toriginal.prototype[unreactiveProperties] || []\n\t\t\t\t)\n\t\t\t\t// Add all arguments (including the first one)\n\t\t\t\toriginal.prototype[unreactiveProperties].add(arg1)\n\t\t\t\tfor (const arg of args) original.prototype[unreactiveProperties].add(arg)\n\t\t\t\treturn original // Return the class\n\t\t\t}) as GenericClassDecorator<T>)\n}\n/**\n * Decorator that marks classes or properties as non-reactive\n * Prevents objects from being made reactive\n */\nexport const unreactive = decorator({\n\tclass(original) {\n\t\t// Called without arguments, mark entire class as non-reactive\n\t\tnonReactiveClass(original)\n\t},\n\tdefault: unreactiveApplication,\n})\n\n//#endregion\n\nexport function cleanedBy<T extends object>(obj: T, cleanupFn: ScopedCallback) {\n\treturn Object.defineProperty(obj, cleanup, {\n\t\tvalue: cleanupFn,\n\t\twritable: false,\n\t\tenumerable: false,\n\t\tconfigurable: true,\n\t}) as T & { [cleanup]: ScopedCallback }\n}\n\n//#region greedy caching\n\n/**\n * Creates a derived value that automatically recomputes when dependencies change\n * @param compute - Function that computes the derived value\n * @returns Object with value and cleanup function\n */\nexport function derived<T>(compute: (dep: DependencyAccess) => T): {\n\tvalue: T\n\t[cleanup]: ScopedCallback\n} {\n\tconst rv = { value: undefined as unknown as T }\n\treturn cleanedBy(\n\t\trv,\n\t\tuntracked(() =>\n\t\t\teffect(\n\t\t\t\tfunction derivedEffect(access) {\n\t\t\t\t\trv.value = compute(access)\n\t\t\t\t}\n\t\t\t)\n\t\t)\n\t)\n}\n","import {\n\tabsent,\n\timmutables,\n\tisNonReactive,\n\tnonReactive,\n\tnonReactiveClass,\n\tnonReactiveObjects,\n\tregisterNativeReactivity,\n} from './non-reactive-state'\nimport { reactive } from './proxy'\n\n/**\n * Converts an iterator to a generator that yields reactive values\n */\nexport function* makeReactiveIterator<T>(iterator: Iterator<T>): Generator<T> {\n\tlet result = iterator.next()\n\twhile (!result.done) {\n\t\tyield reactive(result.value)\n\t\tresult = iterator.next()\n\t}\n}\n\n/**\n * Converts an iterator of key-value pairs to a generator that yields reactive key-value pairs\n */\nexport function* makeReactiveEntriesIterator<K, V>(iterator: Iterator<[K, V]>): Generator<[K, V]> {\n\tlet result = iterator.next()\n\twhile (!result.done) {\n\t\tconst [key, value] = result.value\n\t\tyield [reactive(key), reactive(value)]\n\t\tresult = iterator.next()\n\t}\n}\n\nexport {\n\tabsent,\n\timmutables,\n\tisNonReactive,\n\tnonReactive,\n\tnonReactiveClass,\n\tnonReactiveObjects,\n\tregisterNativeReactivity,\n}\n","import { Indexable } from '../indexable'\nimport { touched } from './change'\nimport { makeReactiveEntriesIterator, makeReactiveIterator } from './non-reactive'\nimport { reactive } from './proxy'\nimport { unwrap } from './proxy-state'\nimport { dependant } from './tracking'\nimport { prototypeForwarding } from './types'\n\nexport const native = Symbol('native')\nconst isArray = Array.isArray\nArray.isArray = ((value: any) =>\n\tisArray(value) ||\n\t(value &&\n\t\ttypeof value === 'object' &&\n\t\tprototypeForwarding in value &&\n\t\tArray.isArray(value[prototypeForwarding]))) as any\nexport class ReactiveBaseArray {\n\treadonly [native]!: any[]\n\n\t// Safe array access with negative indices\n\tat(index: number): any {\n\t\tconst actualIndex = index < 0 ? this[native].length + index : index\n\t\tdependant(this, actualIndex)\n\t\tif (actualIndex < 0 || actualIndex >= this[native].length) return undefined\n\t\treturn reactive(this[native][actualIndex])\n\t}\n\n\t// Immutable versions of mutator methods\n\ttoReversed(): any[] {\n\t\tdependant(this)\n\t\treturn reactive(this[native].toReversed())\n\t}\n\n\ttoSorted(compareFn?: (a: any, b: any) => number): any[] {\n\t\tdependant(this)\n\t\treturn reactive(this[native].toSorted(compareFn))\n\t}\n\n\ttoSpliced(start: number, deleteCount?: number, ...items: any[]): any[] {\n\t\tdependant(this)\n\t\treturn deleteCount === undefined\n\t\t\t? this[native].toSpliced(start)\n\t\t\t: this[native].toSpliced(start, deleteCount, ...items)\n\t}\n\n\twith(index: number, value: any): any[] {\n\t\tdependant(this)\n\t\treturn reactive(this[native].with(index, value))\n\t}\n\n\t// Iterator methods with reactivity tracking\n\tentries() {\n\t\tdependant(this)\n\t\treturn makeReactiveEntriesIterator(this[native].entries())\n\t}\n\n\tkeys() {\n\t\tdependant(this, 'length')\n\t\treturn this[native].keys()\n\t}\n\n\tvalues() {\n\t\tdependant(this)\n\t\treturn makeReactiveIterator(this[native].values())\n\t}\n\n\t[Symbol.iterator]() {\n\t\tdependant(this)\n\t\tconst nativeIterator = this[native][Symbol.iterator]()\n\t\treturn {\n\t\t\tnext() {\n\t\t\t\tconst result = nativeIterator.next()\n\t\t\t\tif (result.done) {\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t\treturn { value: reactive(result.value), done: false }\n\t\t\t},\n\t\t}\n\t}\n\n\tindexOf(searchElement: any, fromIndex?: number): number {\n\t\tdependant(this)\n\t\tconst unwrappedSearch = unwrap(searchElement)\n\t\t// Check both wrapped and unwrapped versions since array may contain either\n\t\tconst index = this[native].indexOf(unwrappedSearch, fromIndex)\n\t\tif (index !== -1) return index\n\t\t// If not found with unwrapped, try with wrapped (in case array contains wrapped version)\n\t\treturn this[native].indexOf(searchElement, fromIndex)\n\t}\n\n\tlastIndexOf(searchElement: any, fromIndex?: number): number {\n\t\tdependant(this)\n\t\tconst unwrappedSearch = unwrap(searchElement)\n\t\t// Check both wrapped and unwrapped versions since array may contain either\n\t\tconst index = this[native].lastIndexOf(unwrappedSearch, fromIndex)\n\t\tif (index !== -1) return index\n\t\t// If not found with unwrapped, try with wrapped (in case array contains wrapped version)\n\t\treturn this[native].lastIndexOf(searchElement, fromIndex)\n\t}\n\n\tincludes(searchElement: any, fromIndex?: number): boolean {\n\t\tdependant(this)\n\t\tconst unwrappedSearch = unwrap(searchElement)\n\t\t// Check both wrapped and unwrapped versions since array may contain either\n\t\treturn (\n\t\t\tthis[native].includes(unwrappedSearch, fromIndex) ||\n\t\t\tthis[native].includes(searchElement, fromIndex)\n\t\t)\n\t}\n\n\tfind(predicate: (this: any, value: any, index: number, obj: any[]) => boolean, thisArg?: any): any\n\tfind(searchElement: any, fromIndex?: number): any\n\tfind(predicateOrElement: any, thisArg?: any): any {\n\t\tdependant(this)\n\t\tif (typeof predicateOrElement === 'function') {\n\t\t\tconst predicate = predicateOrElement as (\n\t\t\t\tthis: any,\n\t\t\t\tvalue: any,\n\t\t\t\tindex: number,\n\t\t\t\tobj: any[]\n\t\t\t) => boolean\n\t\t\treturn reactive(\n\t\t\t\tthis[native].find(\n\t\t\t\t\t(value, index, array) => predicate.call(thisArg, reactive(value), index, array),\n\t\t\t\t\tthisArg\n\t\t\t\t)\n\t\t\t)\n\t\t}\n\t\tconst fromIndex = typeof thisArg === 'number' ? thisArg : undefined\n\t\tconst index = this[native].indexOf(predicateOrElement, fromIndex)\n\t\tif (index === -1) return undefined\n\t\treturn reactive(this[native][index])\n\t}\n\n\tfindIndex(\n\t\tpredicate: (this: any, value: any, index: number, obj: any[]) => boolean,\n\t\tthisArg?: any\n\t): number\n\tfindIndex(searchElement: any, fromIndex?: number): number\n\tfindIndex(predicateOrElement: any, thisArg?: any): number {\n\t\tdependant(this)\n\t\tif (typeof predicateOrElement === 'function') {\n\t\t\tconst predicate = predicateOrElement as (\n\t\t\t\tthis: any,\n\t\t\t\tvalue: any,\n\t\t\t\tindex: number,\n\t\t\t\tobj: any[]\n\t\t\t) => boolean\n\t\t\treturn this[native].findIndex(\n\t\t\t\t(value, index, array) => predicate.call(thisArg, reactive(value), index, array),\n\t\t\t\tthisArg\n\t\t\t)\n\t\t}\n\t\tconst fromIndex = typeof thisArg === 'number' ? thisArg : undefined\n\t\treturn this[native].indexOf(predicateOrElement, fromIndex)\n\t}\n\n\tflat(): any[] {\n\t\tdependant(this)\n\t\treturn reactive(this[native].flat())\n\t}\n\n\tflatMap(\n\t\tcallbackfn: (this: any, value: any, index: number, array: any[]) => any[],\n\t\tthisArg?: any\n\t): any[] {\n\t\tdependant(this)\n\t\treturn reactive(this[native].flatMap(callbackfn, thisArg))\n\t}\n\n\tfilter(callbackfn: (value: any, index: number, array: any[]) => boolean, thisArg?: any): any[] {\n\t\tdependant(this)\n\t\treturn reactive(\n\t\t\tthis[native].filter((item, index, array) => callbackfn(reactive(item), index, array), thisArg)\n\t\t)\n\t}\n\n\tmap(callbackfn: (value: any, index: number, array: any[]) => any, thisArg?: any): any[] {\n\t\tdependant(this)\n\t\treturn reactive(\n\t\t\tthis[native].map((item, index, array) => callbackfn(reactive(item), index, array), thisArg)\n\t\t)\n\t}\n\n\treduce(\n\t\tcallbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\tdependant(this)\n\t\tconst result =\n\t\t\tinitialValue === undefined\n\t\t\t\t? this[native].reduce(callbackfn as any)\n\t\t\t\t: this[native].reduce(callbackfn as any, initialValue)\n\t\treturn reactive(result)\n\t}\n\n\treduceRight(\n\t\tcallbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\tdependant(this)\n\t\tconst result =\n\t\t\tinitialValue !== undefined\n\t\t\t\t? this[native].reduceRight(callbackfn as any, initialValue)\n\t\t\t\t: (this[native] as any).reduceRight(callbackfn as any)\n\t\treturn reactive(result)\n\t}\n\n\tslice(start?: number, end?: number): any[] {\n\t\tfor (const i of range(start || 0, end || this[native].length - 1)) dependant(this, i)\n\t\treturn start === undefined\n\t\t\t? this[native].slice()\n\t\t\t: end === undefined\n\t\t\t\t? this[native].slice(start)\n\t\t\t\t: this[native].slice(start, end)\n\t}\n\n\tconcat(...items: any[]): any[] {\n\t\tdependant(this)\n\t\treturn reactive(this[native].concat(...items))\n\t}\n\n\tjoin(separator?: string): string {\n\t\tdependant(this)\n\t\treturn this[native].join(separator as any)\n\t}\n\n\tforEach(callbackfn: (value: any, index: number, array: any[]) => void, thisArg?: any): void {\n\t\tdependant(this)\n\t\tthis[native].forEach((value, index, array) => {\n\t\t\tcallbackfn.call(thisArg, reactive(value), index, array)\n\t\t})\n\t}\n\n\t// TODO: re-implement for fun dependencies? (eg - every only check the first ones until it find some),\n\t// no need to make it dependant on indexes after the found one\n\tevery(callbackfn: (value: any, index: number, array: any[]) => boolean, thisArg?: any): boolean {\n\t\tdependant(this)\n\t\treturn this[native].every(\n\t\t\t(value, index, array) => callbackfn.call(thisArg, reactive(value), index, array),\n\t\t\tthisArg\n\t\t)\n\t}\n\n\tsome(callbackfn: (value: any, index: number, array: any[]) => boolean, thisArg?: any): boolean {\n\t\tdependant(this)\n\t\treturn this[native].some(\n\t\t\t(value, index, array) => callbackfn.call(thisArg, reactive(value), index, array),\n\t\t\tthisArg\n\t\t)\n\t}\n}\nfunction* index(i: number, { length = true } = {}): IterableIterator<number | 'length'> {\n\tif (length) yield 'length'\n\tyield i\n}\n\nfunction* range(\n\ta: number,\n\tb: number,\n\t{ length = false } = {}\n): IterableIterator<number | 'length'> {\n\tconst start = Math.min(a, b)\n\tconst end = Math.max(a, b)\n\tif (length) yield 'length'\n\tfor (let i = start; i <= end; i++) yield i\n}\n/**\n * Reactive wrapper around JavaScript's Array class with full array method support\n * Tracks length changes, individual index operations, and collection-wide operations\n */\nexport class ReactiveArray extends Indexable(ReactiveBaseArray, {\n\tget(i: number): any {\n\t\tdependant(this, i)\n\t\treturn reactive(this[native][i])\n\t},\n\tset(i: number, value: any) {\n\t\tconst added = i >= this[native].length\n\t\tthis[native][i] = value\n\t\ttouched(this, { type: 'set', prop: i }, index(i, { length: added }))\n\t},\n\tgetLength() {\n\t\tdependant(this, 'length')\n\t\treturn this[native].length\n\t},\n\tsetLength(value: number) {\n\t\tconst oldLength = this[native].length\n\t\ttry {\n\t\t\tthis[native].length = value\n\t\t} finally {\n\t\t\ttouched(this, { type: 'set', prop: 'length' }, range(oldLength, value, { length: true }))\n\t\t}\n\t},\n}) {\n\tconstructor(original: any[]) {\n\t\tsuper()\n\t\tObject.defineProperties(this, {\n\t\t\t// We have to make it double, as [native] must be `unique symbol` - impossible through import\n\t\t\t[native]: { value: original },\n\t\t\t[prototypeForwarding]: { value: original },\n\t\t})\n\t}\n\n\tpush(...items: any[]) {\n\t\tconst oldLength = this[native].length\n\t\ttry {\n\t\t\treturn this[native].push(...items)\n\t\t} finally {\n\t\t\ttouched(\n\t\t\t\tthis,\n\t\t\t\t{ type: 'bunch', method: 'push' },\n\t\t\t\trange(oldLength, oldLength + items.length - 1, { length: true })\n\t\t\t)\n\t\t}\n\t}\n\n\tpop() {\n\t\tif (this[native].length === 0) return undefined\n\t\ttry {\n\t\t\treturn reactive(this[native].pop())\n\t\t} finally {\n\t\t\ttouched(this, { type: 'bunch', method: 'pop' }, index(this[native].length))\n\t\t}\n\t}\n\n\tshift() {\n\t\tif (this[native].length === 0) return undefined\n\t\ttry {\n\t\t\treturn reactive(this[native].shift())\n\t\t} finally {\n\t\t\ttouched(\n\t\t\t\tthis,\n\t\t\t\t{ type: 'bunch', method: 'shift' },\n\t\t\t\trange(0, this[native].length + 1, { length: true })\n\t\t\t)\n\t\t}\n\t}\n\n\tunshift(...items: any[]) {\n\t\ttry {\n\t\t\treturn this[native].unshift(...items)\n\t\t} finally {\n\t\t\ttouched(\n\t\t\t\tthis,\n\t\t\t\t{ type: 'bunch', method: 'unshift' },\n\t\t\t\trange(0, this[native].length - items.length, { length: true })\n\t\t\t)\n\t\t}\n\t}\n\n\tsplice(start: number, deleteCount?: number, ...items: any[]) {\n\t\tconst oldLength = this[native].length\n\t\tif (deleteCount === undefined) deleteCount = oldLength - start\n\t\ttry {\n\t\t\tif (deleteCount === undefined) return reactive(this[native].splice(start))\n\t\t\treturn reactive(this[native].splice(start, deleteCount, ...items))\n\t\t} finally {\n\t\t\ttouched(\n\t\t\t\tthis,\n\t\t\t\t{ type: 'bunch', method: 'splice' },\n\t\t\t\t// TODO: edge cases\n\t\t\t\tdeleteCount === items.length\n\t\t\t\t\t? range(start, start + deleteCount)\n\t\t\t\t\t: range(start, oldLength + Math.max(items.length - deleteCount, 0), {\n\t\t\t\t\t\tlength: true,\n\t\t\t\t\t})\n\t\t\t)\n\t\t}\n\t}\n\n\treverse() {\n\t\ttry {\n\t\t\treturn this[native].reverse()\n\t\t} finally {\n\t\t\ttouched(this, { type: 'bunch', method: 'reverse' }, range(0, this[native].length - 1))\n\t\t}\n\t}\n\n\tsort(compareFn?: (a: any, b: any) => number) {\n\t\tcompareFn = compareFn || ((a, b) => a.toString().localeCompare(b.toString()))\n\t\ttry {\n\t\t\treturn this[native].sort((a, b) => compareFn(reactive(a), reactive(b))) as any\n\t\t} finally {\n\t\t\ttouched(this, { type: 'bunch', method: 'sort' }, range(0, this[native].length - 1))\n\t\t}\n\t}\n\n\tfill(value: any, start?: number, end?: number) {\n\t\ttry {\n\t\t\tif (start === undefined) return this[native].fill(value) as any\n\t\t\tif (end === undefined) return this[native].fill(value, start) as any\n\t\t\treturn this[native].fill(value, start, end) as any\n\t\t} finally {\n\t\t\ttouched(this, { type: 'bunch', method: 'fill' }, range(0, this[native].length - 1))\n\t\t}\n\t}\n\n\tcopyWithin(target: number, start: number, end?: number) {\n\t\ttry {\n\t\t\tif (end === undefined) return this[native].copyWithin(target, start) as any\n\t\t\treturn this[native].copyWithin(target, start, end) as any\n\t\t} finally {\n\t\t\ttouched(\n\t\t\t\tthis,\n\t\t\t\t{ type: 'bunch', method: 'copyWithin' },\n\t\t\t\t// TODO: calculate the range properly\n\t\t\t\trange(0, this[native].length - 1)\n\t\t\t)\n\t\t}\n\t\t// Touch all affected indices with a single allProps call\n\t}\n}\n","import { Indexable } from '../indexable'\nimport { native, ReactiveBaseArray } from './array'\nimport { touched, touched1 } from './change'\nimport { effect, untracked } from './effects'\nimport { cleanedBy } from './interface'\nimport { reactive } from './proxy'\nimport { dependant } from './tracking'\nimport { prototypeForwarding, type ScopedCallback } from './types'\n\n// TODO: Lazy reactivity ?\nexport class ReadOnlyError extends Error { }\n/**\n * Reactive wrapper around JavaScript's Array class with full array method support\n * Tracks length changes, individual index operations, and collection-wide operations\n */\nclass ReactiveReadOnlyArrayClass extends Indexable(ReactiveBaseArray, {\n\tget(i: number): any {\n\t\tdependant(this, i)\n\t\treturn reactive(this[native][i])\n\t},\n\tset(i: number, _value: any) {\n\t\tthrow new ReadOnlyError(`Setting index ${i} on a read-only array`)\n\t},\n\tgetLength() {\n\t\tdependant(this, 'length')\n\t\treturn this[native].length\n\t},\n\tsetLength(value: number) {\n\t\tthrow new ReadOnlyError(`Setting length to ${value} on a read-only array`)\n\t},\n}) {\n\tconstructor(original: any[]) {\n\t\tsuper()\n\t\tObject.defineProperties(this, {\n\t\t\t// We have to make it double, as [native] must be `unique symbol` - impossible through import\n\t\t\t[native]: { value: original },\n\t\t\t[prototypeForwarding]: { value: original },\n\t\t})\n\t}\n\n\tpush(..._items: any[]) {\n\t\tthrow new ReadOnlyError(`Pushing items to a read-only array`)\n\t}\n\n\tpop() {\n\t\tthrow new ReadOnlyError(`Popping from a read-only array`)\n\t}\n\n\tshift() {\n\t\tthrow new ReadOnlyError(`Shifting from a read-only array`)\n\t}\n\n\tunshift(..._items: any[]) {\n\t\tthrow new ReadOnlyError(`Unshifting items to a read-only array`)\n\t}\n\n\tsplice(_start: number, _deleteCount?: number, ..._items: any[]) {\n\t\tthrow new ReadOnlyError(`Splice from a read-only array`)\n\t}\n\n\treverse() {\n\t\tthrow new ReadOnlyError(`Reversing a read-only array`)\n\t}\n\n\tsort(_compareFn?: (a: any, b: any) => number) {\n\t\tthrow new ReadOnlyError(`Sorting a read-only array`)\n\t}\n\n\tfill(_value: any, _start?: number, _end?: number) {\n\t\tthrow new ReadOnlyError(`Filling a read-only array`)\n\t}\n\n\tcopyWithin(_target: number, _start: number, _end?: number) {\n\t\tthrow new ReadOnlyError(`Copying within a read-only array`)\n\t}\n}\n\nexport const ReactiveReadOnlyArray = reactive(ReactiveReadOnlyArrayClass)\nexport type ReactiveReadOnlyArray<T> = readonly T[]\nexport function mapped<T, U>(\n\tinputs: readonly T[],\n\tcompute: (input: T, index: number, output: U[]) => U,\n\tresize?: (newLength: number, oldLength: number) => void\n): readonly U[] {\n\tconst result: U[] = []\n\tconst resultReactive = new ReactiveReadOnlyArray(result)\n\tconst cleanups: ScopedCallback[] = []\n\tfunction input(index: number) {\n\t\treturn effect(function computedIndexedMapInputEffect() {\n\t\t\tresult[index] = compute(inputs[index], index, resultReactive)\n\t\t\ttouched1(resultReactive, { type: 'set', prop: index }, index)\n\t\t})\n\t}\n\tconst cleanupLength = effect(function computedMapLengthEffect({ ascend }) {\n\t\tconst length = inputs.length\n\t\tconst resultLength = untracked(() => result.length)\n\t\tresize?.(length, resultLength)\n\t\ttouched1(resultReactive, { type: 'set', prop: 'length' }, 'length')\n\t\tif (length < resultLength) {\n\t\t\tconst toCleanup = cleanups.splice(length)\n\t\t\tfor (const cleanup of toCleanup) cleanup()\n\t\t\tresult.length = length\n\t\t} else if (length > resultLength)\n\t\t\t// the input effects will be registered as the call's children, so they will remain not cleaned with this effect on length\n\t\t\tascend(function computedMapNewElements() {\n\t\t\t\tfor (let i = resultLength; i < length; i++) cleanups.push(input(i))\n\t\t\t})\n\t})\n\treturn cleanedBy(resultReactive, () => {\n\t\tfor (const cleanup of cleanups) cleanup()\n\t\tcleanups.length = 0\n\t\tcleanupLength()\n\t})\n}\n\nexport function reduced<T, U, R extends object = any>(\n\tinputs: readonly T[],\n\tcompute: (input: T, factor: R) => readonly U[]\n): readonly U[] {\n\tconst result: U[] = []\n\tconst resultReactive = new ReactiveReadOnlyArray(result)\n\tconst cleanupFactor = effect(function computedReducedFactorEffect() {\n\t\tconst factor: R = {} as R\n\t\tresult.length = 0\n\t\tfor (const input of inputs) result.push(...compute(input, factor))\n\t\ttouched(resultReactive, { type: 'invalidate', prop: 'reduced' })\n\t})\n\treturn cleanedBy(resultReactive, cleanupFactor)\n}\n","import { decorator } from '../decorator'\nimport { deepCompare, renamed } from '../utils'\nimport { touched1 } from './change'\nimport { effect, root, untracked } from './effects'\nimport { dependant } from './tracking'\nimport { getRoot, markWithRoot } from './registry'\nimport { options, rootFunction } from './types'\n\nexport type Memoizable = object | any[] | symbol | ((...args: any[]) => any)\n\ntype MemoCacheTree<Result> = {\n\tresult?: Result\n\tcleanup?: () => void\n\tbranches?: WeakMap<Memoizable, MemoCacheTree<Result>>\n}\n\nconst memoizedRegistry = new WeakMap<any, Function>()\nconst wrapperRegistry = new WeakMap<Function, Function>()\n\nfunction getBranch<Result>(tree: MemoCacheTree<Result>, key: Memoizable): MemoCacheTree<Result> {\n\ttree.branches ??= new WeakMap()\n\tlet branch = tree.branches.get(key)\n\tif (!branch) {\n\t\tbranch = {}\n\t\ttree.branches.set(key, branch)\n\t}\n\treturn branch\n}\n\nfunction memoizeFunction<Result, Args extends Memoizable[]>(\n\tfn: (...args: Args) => Result\n): (...args: Args) => Result {\n\tconst fnRoot = getRoot(fn)\n\tconst existing = memoizedRegistry.get(fnRoot)\n\tif (existing) return existing as (...args: Args) => Result\n\n\tconst cacheRoot: MemoCacheTree<Result> = {}\n\tconst memoized = markWithRoot((...args: Args): Result => {\n\t\tconst localArgs = args //: Args = maxArgs !== undefined ? (args.slice(0, maxArgs) as Args) : args\n\t\tif (localArgs.some((arg) => !(arg && ['object', 'symbol', 'function'].includes(typeof arg))))\n\t\t\tthrow new Error('memoize expects non-null object arguments')\n\n\t\tlet node: MemoCacheTree<Result> = cacheRoot\n\t\t// Note: decorators add `this` as first argument\n\t\tfor (const arg of localArgs) {\n\t\t\tnode = getBranch(node, arg)\n\t\t}\n\n\t\tdependant(node, 'memoize')\n\t\tif ('result' in node) {\n\t\t\tif (options.onMemoizationDiscrepancy) {\n\t\t\t\tconst wasVerification = options.isVerificationRun\n\t\t\t\toptions.isVerificationRun = true\n\t\t\t\ttry {\n\t\t\t\t\tconst fresh = untracked(() => fn(...localArgs))\n\t\t\t\t\tif (!deepCompare(node.result, fresh)) {\n\t\t\t\t\t\toptions.onMemoizationDiscrepancy(node.result, fresh, fn, localArgs, 'calculation')\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\toptions.isVerificationRun = wasVerification\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn node.result!\n\t\t}\n\n\t\t// Create memoize internal effect to track dependencies and invalidate cache\n\t\t// Use untracked to prevent the effect creation from being affected by parent effects\n\t\tnode.cleanup = root(() =>\n\t\t\teffect(\n\t\t\t\t() => {\n\t\t\t\t\t// Execute the function and track its dependencies\n\t\t\t\t\t// The function execution will automatically track dependencies on reactive objects\n\t\t\t\t\tnode.result = fn(...localArgs)\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\t// When dependencies change, clear the cache and notify consumers\n\t\t\t\t\t\tdelete node.result\n\t\t\t\t\t\ttouched1(node, { type: 'invalidate', prop: localArgs }, 'memoize')\n\t\t\t\t\t\t// Lazy memoization: stop the effect so it doesn't re-run immediately.\n\t\t\t\t\t\t// It will be re-created on next access.\n\t\t\t\t\t\tif (node.cleanup) {\n\t\t\t\t\t\t\tnode.cleanup()\n\t\t\t\t\t\t\tnode.cleanup = undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{ opaque: true }\n\t\t\t)\n\t\t)\n\n\t\tif (options.onMemoizationDiscrepancy) {\n\t\t\tconst wasVerification = options.isVerificationRun\n\t\t\toptions.isVerificationRun = true\n\t\t\ttry {\n\t\t\t\tconst fresh = untracked(() => fn(...localArgs))\n\t\t\t\tif (!deepCompare(node.result, fresh)) {\n\t\t\t\t\toptions.onMemoizationDiscrepancy(node.result, fresh, fn, localArgs, 'comparison')\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\toptions.isVerificationRun = wasVerification\n\t\t\t}\n\t\t}\n\n\t\treturn node.result!\n\t}, fn)\n\n\tmemoizedRegistry.set(fnRoot, memoized)\n\tmemoizedRegistry.set(memoized, memoized)\n\treturn memoized as (...args: Args) => Result\n}\n\nexport const memoize = decorator({\n\tgetter(original, target, propertyKey) {\n\t\treturn function (this: any) {\n\t\t\tlet wrapper = wrapperRegistry.get(original)\n\t\t\tif (!wrapper) {\n\t\t\t\twrapper = markWithRoot(\n\t\t\t\t\trenamed((that: object) => {\n\t\t\t\t\t\treturn original.call(that)\n\t\t\t\t\t}, `${String(target?.constructor?.name ?? target?.name ?? 'Object')}.${String(propertyKey)}`),\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: original,\n\t\t\t\t\t\tpropertyKey,\n\t\t\t\t\t\t...((original as any)[rootFunction] ? { [rootFunction]: (original as any)[rootFunction] } : {}),\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t\twrapperRegistry.set(original, wrapper)\n\t\t\t}\n\t\t\tconst memoized = memoizeFunction(wrapper as any)\n\t\t\treturn memoized(this)\n\t\t}\n\t},\n\tmethod(original, target, name) {\n\t\treturn function (this: any, ...args: object[]) {\n\t\t\tlet wrapper = wrapperRegistry.get(original)\n\t\t\tif (!wrapper) {\n\t\t\t\twrapper = markWithRoot(\n\t\t\t\t\trenamed((that: object, ...args: object[]) => {\n\t\t\t\t\t\treturn original.call(that, ...args)\n\t\t\t\t\t}, `${String(target?.constructor?.name ?? target?.name ?? 'Object')}.${String(name)}`),\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: original,\n\t\t\t\t\t\tpropertyKey: name,\n\t\t\t\t\t\t...((original as any)[rootFunction] ? { [rootFunction]: (original as any)[rootFunction] } : {}),\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t\twrapperRegistry.set(original, wrapper)\n\t\t\t}\n\t\t\tconst memoized = memoizeFunction(wrapper as any) as (...args: object[]) => unknown\n\t\t\treturn memoized(this, ...args)\n\t\t}\n\t},\n\tdefault: memoizeFunction,\n})\n","import { ArrayReadForward, forwardArray, getAt, Indexable, setAt } from '../indexable'\nimport { effect } from './effects'\nimport { unreactive } from './interface'\nimport { reactive } from './proxy'\nimport { type DependencyFunction, prototypeForwarding, type ScopedCallback } from './types'\n\n// TODO: use register in a real-world crud situation, have \"events\" for add, delete, update\n\ntype KeyFunction<T, K extends PropertyKey> = (item: T) => K\n\n// Helper to work around TypeScript limitation: base class expressions cannot reference class type parameters\nfunction getRegisterBase<T>() {\n\tclass RegisterBase extends Indexable(ArrayReadForward, {\n\t\tget(this: any, index: number) {\n\t\t\treturn this[getAt](index)\n\t\t},\n\t\tset(this: any, index: number, value: T) {\n\t\t\tthis[setAt](index, value)\n\t\t},\n\t\tgetLength(this: any) {\n\t\t\treturn this.length\n\t\t},\n\t\tsetLength(this: any, value: number) {\n\t\t\tthis.length = value\n\t\t},\n\t}) {\n\t\ttoArray(): T[] {\n\t\t\treturn Array.from(this)\n\t\t}\n\t}\n\treturn RegisterBase as new () => ArrayReadForward<T> & {\n\t\t[x: number]: T\n\t\ttoArray(): T[]\n\t}\n}\ninterface RegisterInstance<T> extends ArrayReadForward<T> {\n\t[index: number]: T\n}\n\n@unreactive\nclass RegisterClass<T, K extends PropertyKey = PropertyKey>\n\textends getRegisterBase<any>()\n\timplements RegisterInstance<T>\n{\n\tprotected get [forwardArray](): readonly T[] {\n\t\treturn this.toArray()\n\t}\n\treadonly #keyFn: KeyFunction<T, K>\n\treadonly #keys: K[]\n\treadonly #values: Map<K, T>\n\treadonly #usage = new Map<K, number>()\n\treadonly #valueInfo = new Map<T, { key: K; stop?: ScopedCallback }>()\n\treadonly #keyEffects = new Set<ScopedCallback>()\n\treadonly #ascend: DependencyFunction\n\n\tconstructor(keyFn: KeyFunction<T, K>, initial?: Iterable<T>) {\n\t\tsuper()\n\t\t/* Moved below initialization */\n\t\tlet ascendGet: DependencyFunction | undefined\n\t\teffect(({ ascend }) => {\n\t\t\tascendGet = ascend\n\t\t})\n\t\tthis.#ascend = ascendGet!\n\t\tif (typeof keyFn !== 'function') throw new Error('Register requires a key function')\n\t\tthis.#keyFn = keyFn\n\t\tthis.#keys = reactive([] as K[])\n\t\tthis.#values = reactive(new Map<K, T>())\n\t\tObject.defineProperties(this, {\n\t\t\t[prototypeForwarding]: { value: this.#keys },\n\t\t})\n\t\tif (initial) this.push(...initial)\n\t}\n\n\tprivate ensureKey(value: T): K {\n\t\tlet info = this.#valueInfo.get(value)\n\t\tif (info) return info.key\n\t\tinfo = { key: undefined as unknown as K }\n\t\tthis.#valueInfo.set(value, info)\n\t\tthis.#ascend(() => {\n\t\t\tconst stop = effect(({ reaction }) => {\n\t\t\t\tconst nextKey = this.#keyFn(value)\n\t\t\t\tthis.assertValidKey(nextKey)\n\t\t\t\tconst previousKey = info!.key\n\t\t\t\tif (reaction && previousKey !== undefined && !Object.is(nextKey, previousKey))\n\t\t\t\t\tthis.#rekeyValue(value, previousKey, nextKey)\n\t\t\t\tinfo!.key = nextKey\n\t\t\t})\n\t\t\tinfo!.stop = stop\n\t\t\tthis.#keyEffects.add(stop)\n\t\t})\n\t\tif (info.key === undefined) throw new Error('Register key function must return a property key')\n\t\treturn info.key\n\t}\n\n\tprivate assertValidKey(key: unknown): asserts key is K {\n\t\tconst type = typeof key\n\t\tif (type !== 'string' && type !== 'number' && type !== 'symbol')\n\t\t\tthrow new Error('Register key function must return a property key')\n\t}\n\n\tprivate setKeyValue(key: K, value: T) {\n\t\tconst existing = this.#values.get(key)\n\t\tif (existing !== undefined && existing !== value) this.cleanupValue(existing)\n\t\tthis.#values.set(key, value)\n\t}\n\n\tprivate cleanupValue(value: T) {\n\t\tconst info = this.#valueInfo.get(value)\n\t\tif (!info) return\n\t\tconst stop = info.stop\n\t\tif (stop) {\n\t\t\tinfo.stop = undefined\n\t\t\tthis.#keyEffects.delete(stop)\n\t\t\tstop()\n\t\t}\n\t\tthis.#valueInfo.delete(value)\n\t}\n\n\tprivate disposeKeyEffects() {\n\t\tfor (const value of Array.from(this.#valueInfo.keys())) this.cleanupValue(value)\n\t\tthis.#keyEffects.clear()\n\t}\n\n\t#rekeyValue(value: T, oldKey: K, newKey: K) {\n\t\tif (Object.is(oldKey, newKey)) return\n\t\tconst existingValue = this.#values.get(newKey)\n\t\tif (existingValue !== undefined && existingValue !== value)\n\t\t\tthrow new Error(`Register key collision for key ${String(newKey)}`)\n\t\tconst count = this.#usage.get(oldKey)\n\t\tif (!count) return\n\t\tconst existingCount = this.#usage.get(newKey) ?? 0\n\t\tthis.setKeyValue(newKey, value)\n\t\tfor (let i = 0; i < this.#keys.length; i++)\n\t\t\tif (Object.is(this.#keys[i], oldKey)) this.#keys[i] = newKey\n\t\tthis.#usage.set(newKey, existingCount + count)\n\t\tthis.#usage.delete(oldKey)\n\t\tthis.#values.delete(oldKey)\n\t\tconst updatedInfo = this.#valueInfo.get(value)\n\t\tif (updatedInfo) updatedInfo.key = newKey\n\t}\n\n\tprivate incrementUsage(key: K) {\n\t\tconst count = this.#usage.get(key) ?? 0\n\t\tthis.#usage.set(key, count + 1)\n\t}\n\n\tprivate decrementUsage(key: K) {\n\t\tconst count = this.#usage.get(key)\n\t\tif (!count) return\n\t\tif (count <= 1) {\n\t\t\tconst value = this.#values.get(key)\n\t\t\tthis.#usage.delete(key)\n\t\t\tthis.#values.delete(key)\n\t\t\tif (value !== undefined) this.cleanupValue(value)\n\t\t} else {\n\t\t\tthis.#usage.set(key, count - 1)\n\t\t}\n\t}\n\n\tprivate normalizeIndex(index: number, allowEnd = false): number {\n\t\tconst length = this.length\n\t\tlet resolved = index\n\t\tif (resolved < 0) resolved = Math.max(length + resolved, 0)\n\t\tif (resolved > length) {\n\t\t\tif (allowEnd) resolved = length\n\t\t\telse throw new RangeError('Index out of bounds')\n\t\t}\n\t\tif (!allowEnd && resolved === length) throw new RangeError('Index out of bounds')\n\t\treturn resolved\n\t}\n\n\tprivate assignAt(index: number, key: K, value: T) {\n\t\tconst oldKey = this.#keys[index]\n\t\tif (oldKey !== undefined && Object.is(oldKey, key)) {\n\t\t\tthis.setKeyValue(key, value)\n\t\t\treturn\n\t\t}\n\t\tif (oldKey !== undefined) this.decrementUsage(oldKey as K)\n\t\tthis.#keys[index] = key\n\t\tthis.incrementUsage(key)\n\t\tthis.setKeyValue(key, value)\n\t}\n\n\tprivate insertKeyValue(index: number, key: K, value: T) {\n\t\tthis.#keys.splice(index, 0, key)\n\t\tthis.incrementUsage(key)\n\t\tthis.setKeyValue(key, value)\n\t}\n\n\tprivate rebuildFrom(values: T[]) {\n\t\tthis.disposeKeyEffects()\n\t\tthis.#keys.splice(0, this.#keys.length)\n\t\tthis.#usage.clear()\n\t\tthis.#values.clear()\n\t\tfor (const value of values) {\n\t\t\tconst key = this.ensureKey(value)\n\t\t\tthis.#keys.push(key)\n\t\t\tthis.incrementUsage(key)\n\t\t\tthis.#values.set(key, value)\n\t\t}\n\t}\n\n\tget length(): number {\n\t\treturn this.#keys.length\n\t}\n\n\t[getAt](index: number): T | undefined {\n\t\tconst key = this.#keys[index]\n\t\treturn key === undefined ? undefined : this.#values.get(key)\n\t}\n\n\t[setAt](index: number, value: T): void {\n\t\tconst key = this.ensureKey(value)\n\t\tif (index === this.length) {\n\t\t\tthis.insertKeyValue(index, key, value)\n\t\t\treturn\n\t\t}\n\t\tconst normalized = this.normalizeIndex(index)\n\t\tthis.assignAt(normalized, key, value)\n\t}\n\n\tpush(...items: T[]): number {\n\t\tfor (const item of items) {\n\t\t\tconst key = this.ensureKey(item)\n\t\t\tthis.insertKeyValue(this.length, key, item)\n\t\t}\n\t\treturn this.length\n\t}\n\n\tpop(): T | undefined {\n\t\tif (!this.length) return undefined\n\t\treturn this.removeAt(this.length - 1)\n\t}\n\n\tshift(): T | undefined {\n\t\tif (!this.length) return undefined\n\t\treturn this.removeAt(0)\n\t}\n\n\tunshift(...items: T[]): number {\n\t\tlet index = 0\n\t\tfor (const item of items) {\n\t\t\tconst key = this.ensureKey(item)\n\t\t\tthis.insertKeyValue(index++, key, item)\n\t\t}\n\t\treturn this.length\n\t}\n\n\tsplice(start: number, deleteCount?: number, ...items: T[]): T[] {\n\t\tconst normalizedStart = this.normalizeIndex(start, true)\n\t\tconst maxDeletions = this.length - normalizedStart\n\t\tconst actualDelete = Math.min(\n\t\t\tdeleteCount === undefined ? maxDeletions : Math.max(deleteCount, 0),\n\t\t\tmaxDeletions\n\t\t)\n\t\tconst keysToInsert: K[] = []\n\t\tfor (const item of items) keysToInsert.push(this.ensureKey(item))\n\t\tconst removedKeys = this.#keys.splice(normalizedStart, actualDelete, ...keysToInsert)\n\t\tconst removedValues: T[] = []\n\t\tfor (const key of removedKeys) {\n\t\t\tif (key === undefined) continue\n\t\t\tconst value = this.#values.get(key as K)\n\t\t\tthis.decrementUsage(key as K)\n\t\t\tremovedValues.push(value as T)\n\t\t}\n\t\tfor (let i = 0; i < keysToInsert.length; i++) {\n\t\t\tconst key = keysToInsert[i]\n\t\t\tconst value = items[i]\n\t\t\tthis.incrementUsage(key)\n\t\t\tthis.setKeyValue(key, value)\n\t\t}\n\t\treturn removedValues\n\t}\n\n\tclear(): void {\n\t\tthis.#keys.length = 0\n\t\tthis.#usage.clear()\n\t\tthis.#values.clear()\n\t\tthis.disposeKeyEffects()\n\t}\n\n\tget(key: K): T | undefined {\n\t\treturn this.#values.get(key)\n\t}\n\tset(key: K, value: T): void {\n\t\tif (this.#values.has(key)) this.setKeyValue(key, value)\n\t}\n\n\tremove(key: K) {\n\t\tlet index: number = this.indexOfKey(key)\n\t\twhile (index !== -1) {\n\t\t\tthis.removeAt(index)\n\t\t\tindex = this.indexOfKey(key)\n\t\t}\n\t}\n\n\tpublic removeAt(index: number): T | undefined {\n\t\tconst [key] = this.#keys.splice(index, 1)\n\t\tif (key === undefined) return undefined\n\t\tconst value = this.#values.get(key as K)\n\t\tthis.decrementUsage(key as K)\n\t\treturn value\n\t}\n\n\t/**\n\t * Keep only the items for which the predicate returns true.\n\t * Items for which the predicate returns false are removed.\n\t *\n\t * The predicate is evaluated once per distinct key; duplicate keys\n\t * will follow the same keep/remove decision.\n\t */\n\tpublic keep(predicate: (value: T) => boolean): void {\n\t\tconst decisions = new Map<K, boolean>()\n\t\tfor (const [index, key] of this.#keys.entries()) {\n\t\t\tif (decisions.has(key)) {\n\t\t\t\tif (!decisions.get(key)) this.removeAt(index)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst value = this.#values.get(key)\n\t\t\tconst shouldKeep = predicate(value as T)\n\t\t\tdecisions.set(key, shouldKeep)\n\t\t\tif (!shouldKeep) this.removeAt(index)\n\t\t}\n\t}\n\n\thasKey(key: K): boolean {\n\t\treturn this.#usage.has(key)\n\t}\n\n\tindexOfKey(key: K): number {\n\t\treturn this.#keys.indexOf(key)\n\t}\n\n\tmapKeys(): IterableIterator<K> {\n\t\treturn this.#values.keys()\n\t}\n\n\tupdate(...values: T[]): void {\n\t\tfor (const value of values) {\n\t\t\tconst key = this.ensureKey(value)\n\t\t\tif (this.#values.has(key)) this.setKeyValue(key, value)\n\t\t}\n\t}\n\n\tupsert(insert: (value: T) => void, ...values: T[]): void {\n\t\tfor (const value of values) {\n\t\t\tconst key = this.ensureKey(value)\n\t\t\tif (this.#values.has(key)) this.setKeyValue(key, value)\n\t\t\telse insert(value)\n\t\t}\n\t}\n\n\tentries(): IterableIterator<[number, T]> {\n\t\tconst self = this\n\t\tfunction* iterator(): IterableIterator<[number, T]> {\n\t\t\tfor (let i = 0; i < self.#keys.length; i++) {\n\t\t\t\tconst val = self.#values.get(self.#keys[i])\n\t\t\t\tif (val !== undefined) yield [i, val]\n\t\t\t}\n\t\t}\n\t\treturn iterator()\n\t}\n\n\t[Symbol.iterator](): IterableIterator<T> {\n\t\tconst self = this\n\t\tfunction* iterator(): IterableIterator<T> {\n\t\t\tfor (const key of self.#keys) {\n\t\t\t\tconst value = self.#values.get(key)\n\t\t\t\tif (value !== undefined) yield value\n\t\t\t}\n\t\t}\n\t\treturn iterator()\n\t}\n\n\ttoString(): string {\n\t\treturn `[Register length=${this.length}]`\n\t}\n\n\tat(index: number): T | undefined {\n\t\tconst resolved = index < 0 ? this.length + index : index\n\t\tif (resolved < 0 || resolved >= this.length) return undefined\n\t\treturn this[getAt](resolved)\n\t}\n\treverse(): this {\n\t\tthis.#keys.reverse()\n\t\treturn this\n\t}\n\tsort(compareFn?: ((a: T, b: T) => number) | undefined): this {\n\t\tconst fwdCompareFn = compareFn\n\t\t\t? (a: K, b: K) => compareFn(this.#values.get(a) as T, this.#values.get(b) as T)\n\t\t\t: undefined\n\t\tthis.#keys.sort(fwdCompareFn)\n\t\treturn this\n\t}\n\tfill(value: T, start = 0, end = this.length): this {\n\t\tconst values = this.toArray()\n\t\tvalues.fill(value, start, end)\n\t\tthis.rebuildFrom(values)\n\t\treturn this\n\t}\n\n\tcopyWithin(target: number, start: number, end?: number): this {\n\t\tconst values = this.toArray()\n\t\tvalues.copyWithin(target, start, end)\n\t\tthis.rebuildFrom(values)\n\t\treturn this\n\t}\n}\n\nexport type Register<T, K extends PropertyKey = PropertyKey> = RegisterClass<T, K> & T[]\nexport const Register = RegisterClass as new <T, K extends PropertyKey = PropertyKey>(\n\tkeyFn: KeyFunction<T, K>,\n\tinitial?: Iterable<T>\n) => Register<T, K>\n\nexport function register<T, K extends PropertyKey = PropertyKey>(\n\tkeyFn: KeyFunction<T, K>,\n\tinitial?: Iterable<T>\n): Register<T, K> {\n\treturn new RegisterClass(keyFn, initial) as Register<T, K>\n}\n","import { ReflectGet, ReflectSet } from '../utils'\nimport { setEffectName } from './debug'\nimport { getActiveEffect } from './effect-context'\nimport { effect, untracked } from './effects'\nimport { cleanedBy, cleanup } from './interface'\nimport { reactive } from './proxy'\nimport { Register } from './register'\nimport { type ProjectionContext, projectionInfo, type ScopedCallback } from './types'\n\n/**\n * Maps projection effects (item effects) to their projection context\n */\nexport const effectProjectionMetadata = new WeakMap<ScopedCallback, ProjectionContext>()\n\n/**\n * Returns the projection context of the currently running effect, if any.\n */\nexport function getActiveProjection(): ProjectionContext | undefined {\n\tconst active = getActiveEffect()\n\treturn active ? effectProjectionMetadata.get(active) : undefined\n}\n\n/* TODO\nIt seems to work and I feel like it's correct but I couldn't validate theoretically that `ascend`\nis the correct way to deal with nested effects.\n*/\n\ntype ProjectOldValue<Target> = Target extends readonly (infer Item)[]\n\t? Item\n\t: Target extends Map<any, infer Item>\n\t\t? Item\n\t\t: Target extends Record<PropertyKey, infer Item>\n\t\t\t? Item\n\t\t\t: unknown\n\nexport type ProjectAccess<SourceValue, Key, SourceType, Target> = {\n\treadonly key: Key\n\tget(): SourceValue\n\tset(value: SourceValue): boolean\n\treadonly source: SourceType\n\treadonly old?: ProjectOldValue<Target>\n\tvalue: SourceValue\n}\n\ntype BivariantProjectCallback<Args extends any[], Return> = {\n\tbivarianceHack(...args: Args): Return\n}['bivarianceHack']\n\nexport type ProjectCallback<\n\tSourceValue,\n\tKey,\n\tTarget extends object,\n\tSourceType,\n\tResult,\n> = BivariantProjectCallback<[ProjectAccess<SourceValue, Key, SourceType, Target>, Target], Result>\n\nexport type ProjectResult<Target extends object> = Target & { [cleanup]: ScopedCallback }\n\nfunction defineAccessValue<Access extends { get(): unknown; set(value: unknown): boolean }>(\n\taccess: Access\n) {\n\tObject.defineProperty(access, 'value', {\n\t\tget: access.get,\n\t\tset: access.set,\n\t\tconfigurable: true,\n\t\tenumerable: true,\n\t})\n}\n\nfunction makeCleanup<Result extends object>(\n\ttarget: Result,\n\teffectMap: Map<unknown, ScopedCallback>,\n\tonDispose: () => void,\n\tmetadata?: any\n): ProjectResult<Result> {\n\tif (metadata) {\n\t\tObject.defineProperty(target, projectionInfo, {\n\t\t\tvalue: metadata,\n\t\t\twritable: false,\n\t\t\tenumerable: false,\n\t\t\tconfigurable: true,\n\t\t})\n\t}\n\treturn cleanedBy(target, () => {\n\t\tonDispose()\n\t\tfor (const stop of effectMap.values()) stop?.()\n\t\teffectMap.clear()\n\t}) as ProjectResult<Result>\n}\n\nfunction projectArray<SourceValue, ResultValue>(\n\tsource: readonly SourceValue[],\n\tapply: ProjectCallback<SourceValue, number, ResultValue[], readonly SourceValue[], ResultValue>\n): ProjectResult<ResultValue[]> {\n\tconst observedSource = reactive(source) as readonly SourceValue[]\n\tconst target = reactive([] as ResultValue[])\n\tconst indexEffects = new Map<number, ScopedCallback>()\n\n\tfunction normalizeTargetLength(length: number) {\n\t\tReflectSet(target as unknown as object, 'length', length, target)\n\t}\n\n\tfunction disposeIndex(index: number) {\n\t\tconst stopEffect = indexEffects.get(index)\n\t\tif (stopEffect) {\n\t\t\tindexEffects.delete(index)\n\t\t\tstopEffect()\n\t\t\tReflect.deleteProperty(target as unknown as object, index)\n\t\t}\n\t}\n\n\tconst parent = getActiveProjection()\n\tconst depth = parent ? parent.depth + 1 : 0\n\n\tconst cleanupLength = effect(function projectArrayLengthEffect({ ascend }) {\n\t\tconst length = observedSource.length\n\t\tnormalizeTargetLength(length)\n\t\tconst existing = Array.from(indexEffects.keys())\n\t\tfor (let i = 0; i < length; i++) {\n\t\t\tif (indexEffects.has(i)) continue\n\t\t\tascend(() => {\n\t\t\t\tconst index = i\n\t\t\t\tconst stop = effect(function projectArrayIndexEffect() {\n\t\t\t\t\tconst previous = untracked(() => target[index])\n\t\t\t\t\tconst accessBase = {\n\t\t\t\t\t\tkey: index,\n\t\t\t\t\t\tsource: observedSource,\n\t\t\t\t\t\tget: () => ReflectGet(observedSource as any, index, observedSource),\n\t\t\t\t\t\tset: (value: SourceValue) =>\n\t\t\t\t\t\t\tReflectSet(observedSource as any, index, value, observedSource),\n\t\t\t\t\t\told: previous,\n\t\t\t\t\t} as ProjectAccess<SourceValue, number, readonly SourceValue[], ResultValue[]>\n\t\t\t\t\tdefineAccessValue(accessBase)\n\t\t\t\t\tconst produced = apply(accessBase, target)\n\t\t\t\t\ttarget[index] = produced\n\t\t\t\t})\n\t\t\t\tsetEffectName(stop, `project[${depth}]:${index}`)\n\t\t\t\teffectProjectionMetadata.set(stop, {\n\t\t\t\t\tsource: observedSource,\n\t\t\t\t\tkey: index,\n\t\t\t\t\ttarget,\n\t\t\t\t\tdepth,\n\t\t\t\t\tparent,\n\t\t\t\t})\n\t\t\t\tindexEffects.set(i, stop)\n\t\t\t})\n\t\t}\n\t\tfor (const index of existing) if (index >= length) disposeIndex(index)\n\t})\n\n\treturn makeCleanup(target, indexEffects, () => cleanupLength(), {\n\t\tsource: observedSource,\n\t\ttarget,\n\t\tapply,\n\t\tdepth,\n\t\tparent,\n\t} as ProjectionContext)\n}\n\nfunction projectRegister<Key extends PropertyKey, SourceValue, ResultValue>(\n\tsource: Register<SourceValue, Key>,\n\tapply: ProjectCallback<\n\t\tSourceValue,\n\t\tKey,\n\t\tMap<Key, ResultValue>,\n\t\tRegister<SourceValue, Key>,\n\t\tResultValue\n\t>\n): ProjectResult<Map<Key, ResultValue>> {\n\tconst observedSource = reactive(source) as Register<SourceValue, Key>\n\tconst rawTarget = new Map<Key, ResultValue>()\n\tconst target = reactive(rawTarget) as Map<Key, ResultValue>\n\tconst keyEffects = new Map<Key, ScopedCallback>()\n\n\tfunction disposeKey(key: Key) {\n\t\tconst stopEffect = keyEffects.get(key)\n\t\tif (stopEffect) {\n\t\t\tstopEffect()\n\t\t\tkeyEffects.delete(key)\n\t\t\ttarget.delete(key)\n\t\t}\n\t}\n\n\tconst parent = getActiveProjection()\n\tconst depth = parent ? parent.depth + 1 : 0\n\n\tconst cleanupKeys = effect(function projectRegisterEffect({ ascend }) {\n\t\tconst keys = new Set<Key>()\n\t\tfor (const key of observedSource.mapKeys()) keys.add(key)\n\n\t\tfor (const key of keys) {\n\t\t\tif (keyEffects.has(key)) continue\n\t\t\tascend(() => {\n\t\t\t\tconst stop = effect(function projectRegisterKeyEffect() {\n\t\t\t\t\tconst previous = untracked(() => target.get(key))\n\t\t\t\t\tconst accessBase = {\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tsource: observedSource,\n\t\t\t\t\t\tget: () => observedSource.get(key) as SourceValue,\n\t\t\t\t\t\tset: (value: SourceValue) => {\n\t\t\t\t\t\t\tobservedSource.set(key, value)\n\t\t\t\t\t\t\treturn true\n\t\t\t\t\t\t},\n\t\t\t\t\t\told: previous,\n\t\t\t\t\t} as ProjectAccess<SourceValue, Key, Register<SourceValue, Key>, Map<Key, ResultValue>>\n\t\t\t\t\tdefineAccessValue(accessBase)\n\t\t\t\t\tconst produced = apply(accessBase, target)\n\t\t\t\t\ttarget.set(key, produced)\n\t\t\t\t})\n\t\t\t\tsetEffectName(stop, `project[${depth}]:${String(key)}`)\n\t\t\t\teffectProjectionMetadata.set(stop, {\n\t\t\t\t\tsource: observedSource,\n\t\t\t\t\tkey,\n\t\t\t\t\ttarget,\n\t\t\t\t\tdepth,\n\t\t\t\t\tparent,\n\t\t\t\t})\n\t\t\t\tkeyEffects.set(key, stop)\n\t\t\t})\n\t\t}\n\n\t\tfor (const key of Array.from(keyEffects.keys())) if (!keys.has(key)) disposeKey(key)\n\t})\n\n\treturn makeCleanup(target, keyEffects, () => cleanupKeys(), {\n\t\tsource: observedSource,\n\t\ttarget,\n\t\tapply,\n\t\tdepth,\n\t\tparent,\n\t} as ProjectionContext)\n}\n\nfunction projectRecord<Source extends Record<PropertyKey, any>, ResultValue>(\n\tsource: Source,\n\tapply: ProjectCallback<\n\t\tSource[keyof Source],\n\t\tkeyof Source,\n\t\tRecord<keyof Source, ResultValue>,\n\t\tSource,\n\t\tResultValue\n\t>\n): ProjectResult<Record<keyof Source, ResultValue>> {\n\tconst observedSource = reactive(source) as Source\n\tconst target = reactive({} as Record<keyof Source, ResultValue>)\n\tconst keyEffects = new Map<PropertyKey, ScopedCallback>()\n\n\tfunction disposeKey(key: PropertyKey) {\n\t\tconst stopEffect = keyEffects.get(key)\n\t\tif (stopEffect) {\n\t\t\tstopEffect()\n\t\t\tkeyEffects.delete(key)\n\t\t\tReflect.deleteProperty(target as Record<PropertyKey, unknown>, key)\n\t\t}\n\t}\n\n\tconst parent = getActiveProjection()\n\tconst depth = parent ? parent.depth + 1 : 0\n\n\tconst cleanupKeys = effect(function projectRecordEffect({ ascend }) {\n\t\tconst keys = new Set<PropertyKey>()\n\t\tfor (const key in observedSource) keys.add(key)\n\t\tconst observed = Reflect.ownKeys(observedSource)\n\t\tfor (const key of observed) keys.add(key)\n\n\t\tfor (const key of keys) {\n\t\t\tif (keyEffects.has(key)) continue\n\t\t\tascend(() => {\n\t\t\t\tconst stop = effect(function projectRecordKeyEffect() {\n\t\t\t\t\tconst sourceKey = key as keyof Source\n\t\t\t\t\tconst previous = untracked(\n\t\t\t\t\t\t() => (target as Record<PropertyKey, ResultValue | undefined>)[key]\n\t\t\t\t\t)\n\t\t\t\t\tconst accessBase = {\n\t\t\t\t\t\tkey: sourceKey,\n\t\t\t\t\t\tsource: observedSource,\n\t\t\t\t\t\tget: () => ReflectGet(observedSource, sourceKey, observedSource),\n\t\t\t\t\t\tset: (value: Source[typeof sourceKey]) =>\n\t\t\t\t\t\t\tReflectSet(observedSource, sourceKey, value, observedSource),\n\t\t\t\t\t\told: previous,\n\t\t\t\t\t} as ProjectAccess<\n\t\t\t\t\t\tSource[typeof sourceKey],\n\t\t\t\t\t\tkeyof Source,\n\t\t\t\t\t\tSource,\n\t\t\t\t\t\tRecord<keyof Source, ResultValue>\n\t\t\t\t\t>\n\t\t\t\t\tdefineAccessValue(accessBase)\n\t\t\t\t\tconst produced = apply(accessBase, target)\n\t\t\t\t\t;(target as any)[sourceKey] = produced\n\t\t\t\t})\n\t\t\t\tsetEffectName(stop, `project[${depth}]:${String(key)}`)\n\t\t\t\teffectProjectionMetadata.set(stop, {\n\t\t\t\t\tsource: observedSource,\n\t\t\t\t\tkey,\n\t\t\t\t\ttarget,\n\t\t\t\t\tdepth,\n\t\t\t\t\tparent,\n\t\t\t\t})\n\t\t\t\tkeyEffects.set(key, stop)\n\t\t\t})\n\t\t}\n\n\t\tfor (const key of Array.from(keyEffects.keys())) if (!keys.has(key)) disposeKey(key)\n\t})\n\n\treturn makeCleanup(target, keyEffects, () => cleanupKeys(), {\n\t\tsource: observedSource,\n\t\ttarget,\n\t\tapply,\n\t\tdepth,\n\t\tparent,\n\t} as ProjectionContext)\n}\n\nfunction projectMap<Key, Value, ResultValue>(\n\tsource: Map<Key, Value>,\n\tapply: ProjectCallback<Value, Key, Map<Key, ResultValue>, Map<Key, Value>, ResultValue>\n): ProjectResult<Map<Key, ResultValue>> {\n\tconst observedSource = reactive(source) as Map<Key, Value>\n\tconst rawTarget = new Map<Key, ResultValue>()\n\tconst target = reactive(rawTarget) as Map<Key, ResultValue>\n\tconst keyEffects = new Map<Key, ScopedCallback>()\n\n\tfunction disposeKey(key: Key) {\n\t\tconst stopEffect = keyEffects.get(key)\n\t\tif (stopEffect) {\n\t\t\tstopEffect()\n\t\t\tkeyEffects.delete(key)\n\t\t\ttarget.delete(key)\n\t\t}\n\t}\n\n\tconst parent = getActiveProjection()\n\tconst depth = parent ? parent.depth + 1 : 0\n\n\tconst cleanupKeys = effect(function projectMapEffect({ ascend }) {\n\t\tconst keys = new Set<Key>()\n\t\tfor (const key of observedSource.keys()) keys.add(key)\n\n\t\tfor (const key of keys) {\n\t\t\tif (keyEffects.has(key)) continue\n\t\t\tascend(() => {\n\t\t\t\tconst stop = effect(function projectMapKeyEffect() {\n\t\t\t\t\tconst previous = untracked(() => target.get(key))\n\t\t\t\t\tconst accessBase = {\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tsource: observedSource,\n\t\t\t\t\t\tget: () => observedSource.get(key) as Value,\n\t\t\t\t\t\tset: (value: Value) => {\n\t\t\t\t\t\t\tobservedSource.set(key, value)\n\t\t\t\t\t\t\treturn true\n\t\t\t\t\t\t},\n\t\t\t\t\t\told: previous,\n\t\t\t\t\t} as ProjectAccess<Value, Key, Map<Key, Value>, Map<Key, ResultValue>>\n\t\t\t\t\tdefineAccessValue(accessBase)\n\t\t\t\t\tconst produced = apply(accessBase, target)\n\t\t\t\t\ttarget.set(key, produced)\n\t\t\t\t})\n\t\t\t\tsetEffectName(stop, `project[${depth}]:${String(key)}`)\n\t\t\t\teffectProjectionMetadata.set(stop, {\n\t\t\t\t\tsource: observedSource,\n\t\t\t\t\tkey,\n\t\t\t\t\ttarget,\n\t\t\t\t\tdepth,\n\t\t\t\t\tparent,\n\t\t\t\t})\n\t\t\t\tkeyEffects.set(key, stop)\n\t\t\t})\n\t\t}\n\n\t\tfor (const key of Array.from(keyEffects.keys())) if (!keys.has(key)) disposeKey(key)\n\t})\n\n\treturn makeCleanup(target, keyEffects, () => cleanupKeys(), {\n\t\tsource: observedSource,\n\t\ttarget,\n\t\tapply,\n\t\tdepth,\n\t\tparent,\n\t} as ProjectionContext)\n}\n\ntype ProjectOverload = {\n\t<SourceValue, ResultValue>(\n\t\tsource: readonly SourceValue[],\n\t\tapply: ProjectCallback<SourceValue, number, ResultValue[], readonly SourceValue[], ResultValue>\n\t): ProjectResult<ResultValue[]>\n\t<Key extends PropertyKey, SourceValue, ResultValue>(\n\t\tsource: Register<SourceValue, Key>,\n\t\tapply: ProjectCallback<\n\t\t\tSourceValue,\n\t\t\tKey,\n\t\t\tMap<Key, ResultValue>,\n\t\t\tRegister<SourceValue, Key>,\n\t\t\tResultValue\n\t\t>\n\t): ProjectResult<Map<Key, ResultValue>>\n\t<Source extends Record<PropertyKey, any>, ResultValue>(\n\t\tsource: Source,\n\t\tapply: ProjectCallback<\n\t\t\tSource[keyof Source],\n\t\t\tkeyof Source,\n\t\t\tRecord<keyof Source, ResultValue>,\n\t\t\tSource,\n\t\t\tResultValue\n\t\t>\n\t): ProjectResult<Record<keyof Source, ResultValue>>\n\t<Key, Value, ResultValue>(\n\t\tsource: Map<Key, Value>,\n\t\tapply: ProjectCallback<Value, Key, Map<Key, ResultValue>, Map<Key, Value>, ResultValue>\n\t): ProjectResult<Map<Key, ResultValue>>\n\tarray: typeof projectArray\n\tregister: typeof projectRegister\n\trecord: typeof projectRecord\n\tmap: typeof projectMap\n}\n\nfunction projectCore(source: any, apply: any): ProjectResult<any> {\n\tif (Array.isArray(source)) return projectArray(source, apply)\n\tif (source instanceof Map) return projectMap(source, apply)\n\tif (source instanceof Register) return projectRegister(source, apply)\n\tif (source && (source.constructor === Object || source.constructor === undefined))\n\t\treturn projectRecord(source, apply)\n\tthrow new Error('Unsupported source type')\n}\n\nexport const project: ProjectOverload = Object.assign(projectCore, {\n\tarray: projectArray,\n\tregister: projectRegister,\n\trecord: projectRecord,\n\tmap: projectMap,\n})\n","import { ReflectGet, ReflectSet } from '../utils'\nimport { touched1 } from './change'\nimport { effect } from './effects'\nimport { cleanedBy, cleanup } from './interface'\nimport { reactive } from './proxy'\nimport { type ScopedCallback } from './types'\n\n/**\n * Provides type-safe access to a source object's property within the organized callback.\n * @template Source - The type of the source object\n * @template Key - The type of the property key in the source object\n */\nexport type OrganizedAccess<Source extends Record<PropertyKey, any>, Key extends keyof Source> = {\n\t/** The property key being accessed */\n\treadonly key: Key\n\n\t/**\n\t * Gets the current value of the property from the source object\n\t * @returns The current value of the property\n\t */\n\tget(): Source[Key]\n\n\t/**\n\t * Updates the property value in the source object\n\t * @param value - The new value to set\n\t * @returns {boolean} True if the update was successful\n\t */\n\tset(value: Source[Key]): boolean\n\n\t/**\n\t * The current value of the property (equivalent to using get()/set() directly)\n\t */\n\tvalue: Source[Key]\n}\n\n/**\n * Callback function type for the organized function that processes each source property.\n * @template Source - The type of the source object\n * @template Target - The type of the target object\n */\nexport type OrganizedCallback<Source extends Record<PropertyKey, any>, Target extends object> = <\n\tKey extends keyof Source,\n>(\n\t/**\n\t * Accessor object for the current source property\n\t */\n\taccess: OrganizedAccess<Source, Key>,\n\n\t/**\n\t * The target object where organized data will be stored\n\t */\n\ttarget: Target\n) => ScopedCallback | undefined\n\n/**\n * The result type of the organized function, combining the target object with cleanup capability.\n * @template Target - The type of the target object\n */\nexport type OrganizedResult<Target extends object> = Target & {\n\t/**\n\t * Cleanup function to dispose of all reactive bindings created by organized().\n\t * This is automatically called when the effect that created the organized binding is disposed.\n\t */\n\t[cleanup]: ScopedCallback\n}\n\n/**\n * Organizes a source object's properties into a target object using a callback function.\n * This creates a reactive mapping between source properties and a target object,\n * automatically handling property additions, updates, and removals.\n *\n * @template Source - The type of the source object\n * @template Target - The type of the target object (defaults to Record<PropertyKey, any>)\n *\n * @param {Source} source - The source object to organize\n * @param {OrganizedCallback<Source, Target>} apply - Callback function that defines how each source property is mapped to the target\n * @param {Target} [baseTarget={}] - Optional base target object to use (will be made reactive if not already)\n *\n * @returns {OrganizedResult<Target>} The target object with cleanup capability\n *\n * @example\n * // Organize user permissions into role-based access\n * const user = reactive({ isAdmin: true, canEdit: false });\n * const permissions = organized(\n * user,\n * (access, target) => {\n * if (access.key === 'isAdmin') {\n * target.hasFullAccess = access.value;\n * }\n * target[`can${access.key.charAt(0).toUpperCase() + access.key.slice(1)}`] = access.value;\n * }\n * );\n *\n * @example\n * // Transform object structure with cleanup\n * const source = reactive({ firstName: 'John', lastName: 'Doe' });\n * const formatted = organized(\n * source,\n * (access, target) => {\n * if (access.key === 'firstName' || access.key === 'lastName') {\n * target.fullName = `${source.firstName} ${source.lastName}`.trim();\n * }\n * }\n * );\n *\n * @example\n * // Using with cleanup in a component\n * effect(() => {\n * const data = fetchData();\n * const organizedData = organized(data, (access, target) => {\n * // Transform data\n * });\n *\n * // The cleanup will be called automatically when the effect is disposed\n * return () => organizedData[cleanup]();\n * });\n */\nexport function organized<\n\tSource extends Record<PropertyKey, any>,\n\tTarget extends object = Record<PropertyKey, any>,\n>(\n\tsource: Source,\n\tapply: OrganizedCallback<Source, Target>,\n\tbaseTarget: Target = {} as Target\n): OrganizedResult<Target> {\n\tconst observedSource = reactive(source) as Source\n\tconst target = reactive(baseTarget) as Target\n\tconst keyEffects = new Map<PropertyKey, ScopedCallback>()\n\n\tfunction disposeKey(key: PropertyKey) {\n\t\tconst stopEffect = keyEffects.get(key)\n\t\tif (stopEffect) {\n\t\t\tkeyEffects.delete(key)\n\t\t\tstopEffect()\n\t\t}\n\t}\n\n\tconst cleanupKeys = effect(function organizedKeysEffect({ ascend }) {\n\t\t//const keys = Reflect.ownKeys(observedSource) as PropertyKey[]\n\t\tconst keys = new Set<PropertyKey>()\n\t\tfor (const key in observedSource) keys.add(key)\n\n\t\tfor (const key of keys) {\n\t\t\tif (keyEffects.has(key)) continue\n\t\t\tascend(() => {\n\t\t\t\tconst stop = effect(function organizedKeyEffect() {\n\t\t\t\t\tconst sourceKey = key as keyof Source\n\t\t\t\t\tconst accessBase = {\n\t\t\t\t\t\tkey: sourceKey,\n\t\t\t\t\t\tget: () => ReflectGet(observedSource, sourceKey, observedSource),\n\t\t\t\t\t\tset: (value: Source[typeof sourceKey]) =>\n\t\t\t\t\t\t\tReflectSet(observedSource, sourceKey, value, observedSource),\n\t\t\t\t\t}\n\t\t\t\t\tObject.defineProperty(accessBase, 'value', {\n\t\t\t\t\t\tget: accessBase.get,\n\t\t\t\t\t\tset: accessBase.set,\n\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t})\n\t\t\t\t\treturn apply(accessBase as OrganizedAccess<Source, typeof sourceKey>, target)\n\t\t\t\t})\n\t\t\t\tkeyEffects.set(key, stop)\n\t\t\t})\n\t\t}\n\n\t\tfor (const key of Array.from(keyEffects.keys())) if (!keys.has(key)) disposeKey(key)\n\t})\n\n\treturn cleanedBy(target, () => {\n\t\tcleanupKeys()\n\t\tfor (const key of Array.from(keyEffects.keys())) disposeKey(key)\n\t}) as OrganizedResult<Target>\n}\n\n/**\n * Organizes a property on a target object\n * Shortcut for defineProperty/delete with touched signal\n * @param target - The target object\n * @param property - The property to organize\n * @param access - The access object\n * @returns The property descriptor\n */\nexport function organize<T>(\n\ttarget: object,\n\tproperty: PropertyKey,\n\taccess: { get?(): T; set?(value: T): boolean }\n) {\n\tObject.defineProperty(target, property, {\n\t\tget: access.get,\n\t\tset: access.set,\n\t\tconfigurable: true,\n\t\tenumerable: true,\n\t})\n\ttouched1(target, { type: 'set', prop: property }, property)\n\treturn () => delete (target as any)[property]\n}\n","import { touched, touched1 } from './change'\nimport { notifyPropertyChange } from './deep-touch'\nimport { makeReactiveEntriesIterator, makeReactiveIterator } from './non-reactive'\nimport { reactive } from './proxy'\nimport { dependant } from './tracking'\nimport { prototypeForwarding } from './types'\n\nconst native = Symbol('native')\n\n/**\n * Reactive wrapper around JavaScript's WeakMap class\n * Only tracks individual key operations, no size tracking (WeakMap limitation)\n */\nexport class ReactiveWeakMap<K extends object, V> {\n\treadonly [native]!: WeakMap<K, V>\n\treadonly content!: symbol\n\tconstructor(original: WeakMap<K, V>) {\n\t\tObject.defineProperties(this, {\n\t\t\t[native]: { value: original },\n\t\t\t[prototypeForwarding]: { value: original },\n\t\t\tcontent: { value: Symbol('WeakMapContent') },\n\t\t\t[Symbol.toStringTag]: { value: 'ReactiveWeakMap' },\n\t\t})\n\t}\n\n\t// Implement WeakMap interface methods with reactivity\n\tdelete(key: K): boolean {\n\t\tconst hadKey = this[native].has(key)\n\t\tconst result = this[native].delete(key)\n\n\t\tif (hadKey) touched1(this.content, { type: 'del', prop: key }, key)\n\n\t\treturn result\n\t}\n\n\tget(key: K): V | undefined {\n\t\tdependant(this.content, key)\n\t\treturn reactive(this[native].get(key))\n\t}\n\n\thas(key: K): boolean {\n\t\tdependant(this.content, key)\n\t\treturn this[native].has(key)\n\t}\n\n\tset(key: K, value: V): this {\n\t\tconst hadKey = this[native].has(key)\n\t\tconst oldValue = this[native].get(key)\n\t\tconst reactiveValue = reactive(value)\n\t\tthis[native].set(key, reactiveValue)\n\n\t\tif (!hadKey || oldValue !== reactiveValue) {\n\t\t\tnotifyPropertyChange(this.content, key, oldValue, reactiveValue, hadKey)\n\t\t}\n\n\t\treturn this\n\t}\n}\n\n/**\n * Reactive wrapper around JavaScript's Map class\n * Tracks size changes, individual key operations, and collection-wide operations\n */\nexport class ReactiveMap<K, V> {\n\treadonly [native]!: Map<K, V>\n\treadonly content!: symbol\n\n\tconstructor(original: Map<K, V>) {\n\t\tObject.defineProperties(this, {\n\t\t\t[native]: { value: original },\n\t\t\t[prototypeForwarding]: { value: original },\n\t\t\tcontent: { value: Symbol('MapContent') },\n\t\t\t[Symbol.toStringTag]: { value: 'ReactiveMap' },\n\t\t})\n\t}\n\n\t// Implement Map interface methods with reactivity\n\tget size(): number {\n\t\tdependant(this, 'size') // The ReactiveMap instance still goes through proxy\n\t\treturn this[native].size\n\t}\n\n\tclear(): void {\n\t\tconst hadEntries = this[native].size > 0\n\t\tthis[native].clear()\n\n\t\tif (hadEntries) {\n\t\t\tconst evolution = { type: 'bunch', method: 'clear' } as const\n\t\t\t// Clear triggers all effects since all keys are affected\n\t\t\ttouched1(this, evolution, 'size')\n\t\t\ttouched(this.content, evolution)\n\t\t}\n\t}\n\n\tentries(): Generator<[K, V]> {\n\t\tdependant(this.content)\n\t\treturn makeReactiveEntriesIterator(this[native].entries())\n\t}\n\n\tforEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void {\n\t\tdependant(this.content)\n\t\tthis[native].forEach(callbackfn, thisArg)\n\t}\n\n\tkeys(): MapIterator<K> {\n\t\tdependant(this.content)\n\t\treturn this[native].keys()\n\t}\n\n\tvalues(): Generator<V> {\n\t\tdependant(this.content)\n\t\treturn makeReactiveIterator(this[native].values())\n\t}\n\n\t[Symbol.iterator](): Iterator<[K, V]> {\n\t\tdependant(this.content)\n\t\tconst nativeIterator = this[native][Symbol.iterator]()\n\t\treturn {\n\t\t\tnext() {\n\t\t\t\tconst result = nativeIterator.next()\n\t\t\t\tif (result.done) {\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tvalue: [result.value[0], reactive(result.value[1])],\n\t\t\t\t\tdone: false,\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t}\n\n\t// Implement Map methods with reactivity\n\tdelete(key: K): boolean {\n\t\tconst hadKey = this[native].has(key)\n\t\tconst result = this[native].delete(key)\n\n\t\tif (hadKey) {\n\t\t\tconst evolution = { type: 'del', prop: key } as const\n\t\t\ttouched1(this.content, evolution, key)\n\t\t\ttouched1(this, evolution, 'size')\n\t\t}\n\n\t\treturn result\n\t}\n\n\tget(key: K): V | undefined {\n\t\tdependant(this.content, key)\n\t\treturn reactive(this[native].get(key))\n\t}\n\n\thas(key: K): boolean {\n\t\tdependant(this.content, key)\n\t\treturn this[native].has(key)\n\t}\n\n\tset(key: K, value: V): this {\n\t\tconst hadKey = this[native].has(key)\n\t\tconst oldValue = this[native].get(key)\n\t\tconst reactiveValue = reactive(value)\n\t\tthis[native].set(key, reactiveValue)\n\n\t\tif (!hadKey || oldValue !== reactiveValue) {\n\t\t\tnotifyPropertyChange(this.content, key, oldValue, reactiveValue, hadKey)\n\t\t\t// Also notify size change for Map (WeakMap doesn't track size)\n\t\t\tconst evolution = { type: hadKey ? 'set' : 'add', prop: key } as const\n\t\t\ttouched1(this, evolution, 'size')\n\t\t}\n\n\t\treturn this\n\t}\n}\n","import { touched, touched1 } from './change'\nimport { makeReactiveEntriesIterator, makeReactiveIterator } from './non-reactive'\nimport { reactive } from './proxy'\nimport { dependant } from './tracking'\nimport { prototypeForwarding } from './types'\n\nconst native = Symbol('native')\n\n/**\n * Reactive wrapper around JavaScript's WeakSet class\n * Only tracks individual value operations, no size tracking (WeakSet limitation)\n */\nexport class ReactiveWeakSet<T extends object> {\n\treadonly [native]!: WeakSet<T>\n\treadonly content!: symbol\n\n\tconstructor(original: WeakSet<T>) {\n\t\tObject.defineProperties(this, {\n\t\t\t[native]: { value: original },\n\t\t\t[prototypeForwarding]: { value: original },\n\t\t\tcontent: { value: Symbol('WeakSetContent') },\n\t\t\t[Symbol.toStringTag]: { value: 'ReactiveWeakSet' },\n\t\t})\n\t}\n\n\tadd(value: T): this {\n\t\tconst had = this[native].has(value)\n\t\tthis[native].add(value)\n\t\tif (!had) {\n\t\t\t// touch the specific value and the collection view\n\t\t\ttouched1(this.content, { type: 'add', prop: value }, value)\n\t\t\t// no size/allProps for WeakSet\n\t\t}\n\t\treturn this\n\t}\n\n\tdelete(value: T): boolean {\n\t\tconst had = this[native].has(value)\n\t\tconst res = this[native].delete(value)\n\t\tif (had) touched1(this.content, { type: 'del', prop: value }, value)\n\t\treturn res\n\t}\n\n\thas(value: T): boolean {\n\t\tdependant(this.content, value)\n\t\treturn this[native].has(value)\n\t}\n}\n\n/**\n * Reactive wrapper around JavaScript's Set class\n * Tracks size changes, individual value operations, and collection-wide operations\n */\nexport class ReactiveSet<T> {\n\treadonly [native]!: Set<T>\n\treadonly content!: symbol\n\tconstructor(original: Set<T>) {\n\t\tObject.defineProperties(this, {\n\t\t\t[native]: { value: original },\n\t\t\t[prototypeForwarding]: { value: original },\n\t\t\tcontent: { value: Symbol('SetContent') },\n\t\t\t[Symbol.toStringTag]: { value: 'ReactiveSet' },\n\t\t})\n\t}\n\n\tget size(): number {\n\t\t// size depends on the wrapper instance, like Map counterpart\n\t\tdependant(this, 'size')\n\t\treturn this[native].size\n\t}\n\n\tadd(value: T): this {\n\t\tconst had = this[native].has(value)\n\t\tconst reactiveValue = reactive(value)\n\t\tthis[native].add(reactiveValue)\n\t\tif (!had) {\n\t\t\tconst evolution = { type: 'add', prop: reactiveValue } as const\n\t\t\t// touch for value-specific and aggregate dependencies\n\t\t\ttouched1(this.content, evolution, reactiveValue)\n\t\t\ttouched1(this, evolution, 'size')\n\t\t}\n\t\treturn this\n\t}\n\n\tclear(): void {\n\t\tconst hadEntries = this[native].size > 0\n\t\tthis[native].clear()\n\t\tif (hadEntries) {\n\t\t\tconst evolution = { type: 'bunch', method: 'clear' } as const\n\t\t\ttouched1(this, evolution, 'size')\n\t\t\ttouched(this.content, evolution)\n\t\t}\n\t}\n\n\tdelete(value: T): boolean {\n\t\tconst had = this[native].has(value)\n\t\tconst res = this[native].delete(value)\n\t\tif (had) {\n\t\t\tconst evolution = { type: 'del', prop: value } as const\n\t\t\ttouched1(this.content, evolution, value)\n\t\t\ttouched1(this, evolution, 'size')\n\t\t}\n\t\treturn res\n\t}\n\n\thas(value: T): boolean {\n\t\tdependant(this.content, value)\n\t\treturn this[native].has(value)\n\t}\n\n\tentries(): Generator<[T, T]> {\n\t\tdependant(this.content)\n\t\treturn makeReactiveEntriesIterator(this[native].entries())\n\t}\n\n\tforEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void {\n\t\tdependant(this.content)\n\t\tthis[native].forEach(callbackfn, thisArg)\n\t}\n\n\tkeys(): Generator<T> {\n\t\tdependant(this.content)\n\t\treturn makeReactiveIterator(this[native].keys())\n\t}\n\n\tvalues(): Generator<T> {\n\t\tdependant(this.content)\n\t\treturn makeReactiveIterator(this[native].values())\n\t}\n\n\t[Symbol.iterator](): Iterator<T> {\n\t\tdependant(this.content)\n\t\tconst nativeIterator = this[native][Symbol.iterator]()\n\t\treturn {\n\t\t\tnext() {\n\t\t\t\tconst result = nativeIterator.next()\n\t\t\t\tif (result.done) {\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t\treturn { value: reactive(result.value), done: false }\n\t\t\t},\n\t\t}\n\t}\n}\n","export { getState, touched, touched1 } from './change'\nexport type { ReactivityGraph } from './debug'\nexport {\n\tbuildReactivityGraph,\n\tenableDevTools,\n\tisDevtoolsEnabled,\n\tregisterEffectForDebug,\n\tregisterObjectForDebug,\n\tsetEffectName,\n\tsetObjectName,\n} from './debug'\nexport { deepWatch } from './deep-watch'\nexport {\n\taddBatchCleanup,\n\tatomic,\n\tbatch, // TODO: Batch is now exported for testing purposes, though it shouldn't be - modify the tests to go through `atomic`\n\tbiDi,\n\tdefer,\n\teffect,\n\tgetActivationLog,\n\tgetActiveEffect,\n\troot,\n\ttrackEffect,\n\tuntracked,\n} from './effects'\nexport { cleanedBy, cleanup, derived, unreactive, watch } from './interface'\nexport { mapped, ReadOnlyError, reduced } from './mapped'\nexport { type Memoizable, memoize } from './memoize'\nexport { immutables, isNonReactive, registerNativeReactivity } from './non-reactive'\nexport { getActiveProjection, project } from './project'\nexport { isReactive, ReactiveBase, reactive, unwrap } from './proxy'\nexport { organize, organized } from './record'\nexport { Register, register } from './register'\nexport {\n\ttype DependencyAccess,\n\ttype DependencyFunction,\n\ttype Evolution,\n\toptions as reactiveOptions,\n\tReactiveError,\n\ttype ScopedCallback,\n} from './types'\nexport { isZoneEnabled, setZoneEnabled } from './zone'\n\nimport { ReactiveArray } from './array'\nimport {\n\tdeepWatchers,\n\teffectToDeepWatchedObjects,\n\tobjectParents,\n\tobjectsWithDeepWatchers,\n} from './deep-watch'\nimport { ReactiveMap, ReactiveWeakMap } from './map'\nimport { nonReactiveObjects, registerNativeReactivity } from './non-reactive-state'\nimport { objectToProxy, proxyToObject } from './proxy'\nimport { ReactiveSet, ReactiveWeakSet } from './set'\nimport { effectToReactiveObjects, watchers } from './registry'\n\n// Register native collection types to use specialized reactive wrappers\nregisterNativeReactivity(WeakMap, ReactiveWeakMap)\nregisterNativeReactivity(Map, ReactiveMap)\nregisterNativeReactivity(WeakSet, ReactiveWeakSet)\nregisterNativeReactivity(Set, ReactiveSet)\nregisterNativeReactivity(Array, ReactiveArray)\n\n/**\n * Object containing internal reactive system state for debugging and profiling\n */\nexport const profileInfo: any = {\n\tobjectToProxy,\n\tproxyToObject,\n\teffectToReactiveObjects,\n\twatchers,\n\tobjectParents,\n\tobjectsWithDeepWatchers,\n\tdeepWatchers,\n\teffectToDeepWatchedObjects,\n\tnonReactiveObjects,\n}\n","import { decorator, type GenericClassDecorator } from './decorator'\n\n// In order to avoid async re-entrance, we could use zone.js or something like that.\nconst syncCalculating: { object: object; prop: PropertyKey }[] = []\n/**\n * Decorator that caches the result of a getter method and only recomputes when dependencies change\n * Prevents circular dependencies and provides automatic cache invalidation\n */\nexport const cached = decorator({\n\tgetter(original, _target, propertyKey) {\n\t\treturn function (this: any) {\n\t\t\tconst alreadyCalculating = syncCalculating.findIndex(\n\t\t\t\t(c) => c.object === this && c.prop === propertyKey\n\t\t\t)\n\t\t\tif (alreadyCalculating > -1)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Circular dependency detected: ${syncCalculating\n\t\t\t\t\t\t.slice(alreadyCalculating)\n\t\t\t\t\t\t.map((c) => `${c.object.constructor.name}.${String(c.prop)}`)\n\t\t\t\t\t\t.join(' -> ')} -> again`\n\t\t\t\t)\n\t\t\tsyncCalculating.push({ object: this, prop: propertyKey })\n\t\t\ttry {\n\t\t\t\tconst rv = original.call(this)\n\t\t\t\tcache(this, propertyKey, rv)\n\t\t\t\treturn rv\n\t\t\t} finally {\n\t\t\t\tsyncCalculating.pop()\n\t\t\t}\n\t\t}\n\t},\n})\n\n/**\n * Checks if a property is cached (has a cached value)\n * @param object - The object to check\n * @param propertyKey - The property key to check\n * @returns True if the property has a cached value\n */\nexport function isCached(object: Object, propertyKey: PropertyKey) {\n\treturn !!Object.getOwnPropertyDescriptor(object, propertyKey)\n}\n\n/**\n * Caches a value for a property on an object\n * @param object - The object to cache the value on\n * @param propertyKey - The property key to cache\n * @param value - The value to cache\n */\nexport function cache(object: Object, propertyKey: PropertyKey, value: any) {\n\tObject.defineProperty(object, propertyKey, { value })\n}\n\n/**\n * Creates a decorator that modifies property descriptors for specified properties\n * @param descriptor - The descriptor properties to apply\n * @returns A class decorator that applies the descriptor to specified properties\n */\nexport function describe(descriptor: {\n\tenumerable?: boolean\n\tconfigurable?: boolean // Not modifiable once the property has been defined ?\n\twritable?: boolean\n}) {\n\treturn <T>(...properties: (keyof T)[]): GenericClassDecorator<T> =>\n\t\t(Base) => {\n\t\t\treturn class extends Base {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tfor (const key of properties) {\n\t\t\t\t\t\tObject.defineProperty(this, key, {\n\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptor(this, key),\n\t\t\t\t\t\t\t...descriptor,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n}\n\n/**\n * Decorator that marks methods, properties, or classes as deprecated\n * Provides warning messages when deprecated items are used\n */\nexport const deprecated = Object.assign(\n\tdecorator({\n\t\tmethod(original, _target, propertyKey) {\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.apply(this, args)\n\t\t\t}\n\t\t},\n\t\tgetter(original, _target, propertyKey) {\n\t\t\treturn function (this: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this)\n\t\t\t}\n\t\t},\n\t\tsetter(original, _target, propertyKey) {\n\t\t\treturn function (this: any, value: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this, value)\n\t\t\t}\n\t\t},\n\t\tclass(original) {\n\t\t\treturn class extends original {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tdeprecated.warn(this, 'constructor')\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tdefault(message: string) {\n\t\t\treturn decorator({\n\t\t\t\tmethod(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tgetter(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tsetter(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any, value: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this, value)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tclass(original) {\n\t\t\t\t\treturn class extends original {\n\t\t\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\t\t\tsuper(...args)\n\t\t\t\t\t\t\tdeprecated.warn(this, 'constructor', message)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t})\n\t\t},\n\t}),\n\t{\n\t\twarn: (target: any, propertyKey: PropertyKey, message?: string) => {\n\t\t\t// biome-ignore lint/suspicious/noConsole: To be overridden\n\t\t\tconsole.warn(\n\t\t\t\t`${target.constructor.name}.${String(propertyKey)} is deprecated${message ? `: ${message}` : ''}`\n\t\t\t)\n\t\t},\n\t}\n)\n\n/**\n * Creates a debounced method decorator that delays execution until after the delay period has passed\n * @param delay - The delay in milliseconds\n * @returns A method decorator that debounces method calls\n */\nexport function debounce(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _target, _propertyKey) {\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t// Clear existing timeout\n\t\t\t\tif (timeoutId) {\n\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t}\n\n\t\t\t\t// Set new timeout\n\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\toriginal.apply(this, args)\n\t\t\t\t\ttimeoutId = null\n\t\t\t\t}, delay)\n\t\t\t}\n\t\t},\n\t})\n}\n\n/**\n * Creates a throttled method decorator that limits execution to once per delay period\n * @param delay - The delay in milliseconds\n * @returns A method decorator that throttles method calls\n */\nexport function throttle(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _target, _propertyKey) {\n\t\t\tlet lastCallTime = 0\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tconst now = Date.now()\n\n\t\t\t\t// If enough time has passed since last call, execute immediately\n\t\t\t\tif (now - lastCallTime >= delay) {\n\t\t\t\t\t// Clear any pending timeout since we're executing now\n\t\t\t\t\tif (timeoutId) {\n\t\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}\n\t\t\t\t\tlastCallTime = now\n\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t}\n\n\t\t\t\t// Otherwise, schedule execution for when the delay period ends\n\t\t\t\tif (!timeoutId) {\n\t\t\t\t\tconst remainingTime = delay - (now - lastCallTime)\n\t\t\t\t\tconst scheduledArgs = [...args] // Capture args at scheduling time\n\t\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\t\tlastCallTime = Date.now()\n\t\t\t\t\t\toriginal.apply(this, scheduledArgs)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}, remainingTime)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t})\n}\n","export * from './decorator'\nexport * from './destroyable'\nexport * from './eventful'\nexport * from './indexable'\nexport * from './iterableWeak'\nexport * from './mixins'\nexport * from './reactive'\nexport * from './std-decorators'\nexport * from './utils'\n\nimport pkg from '../package.json'\nconst { version } = pkg\n\n// Singleton verification\nconst GLOBAL_MUTTS_KEY = '__MUTTS_INSTANCE__'\nconst globalScope = \n\t(typeof globalThis !== 'undefined' ? globalThis : \n\t(typeof window !== 'undefined' ? window : \n\t(typeof global !== 'undefined' ? global : false))) as any\nif(globalScope) {\n\t// Detect the source of this instance safely across different environments\n\tlet source = 'mutts/index'\n\ttry {\n\t\t// @ts-ignore\n\t\tif (typeof __filename !== 'undefined') source = __filename\n\t\t// @ts-ignore\n\t\telse {\n\t\t\t// Using eval to avoid SyntaxError in CJS environments where import.meta is not allowed\n\t\t\tconst meta = eval('import.meta')\n\t\t\tif (meta && meta.url) source = meta.url\n\t\t}\n\t} catch (e) {\n\t\t// Fallback for environments where neither is available or accessible\n\t}\n\n\tconst currentSourceInfo = {\n\t\tversion,\n\t\tsource,\n\t\ttimestamp: Date.now()\n\t}\n\n\tif (globalScope[GLOBAL_MUTTS_KEY]) {\n\t\tconst existing = globalScope[GLOBAL_MUTTS_KEY]\n\t\tthrow new Error(\n\t\t\t`[Mutts] Multiple instances detected!\\n` + \n\t\t\t`Existing instance: ${JSON.stringify(existing, null, 2)}\\n` +\n\t\t\t`New instance: ${JSON.stringify(currentSourceInfo, null, 2)}\\n` +\n\t\t\t`This usually happens when 'mutts' is both installed as a dependency and bundled, ` +\n\t\t\t`or when different versions are loaded. ` +\n\t\t\t`Please check your build configuration (aliases, externals) to ensure a single source of truth.`\n\t\t)\n\t}\n\n\tglobalScope[GLOBAL_MUTTS_KEY] = currentSourceInfo\n}\n"],"names":["nativeReactive","Symbol","nonReactiveMark","unreactiveProperties","prototypeForwarding","allProps","projectionInfo","stopped","cleanup","rootFunction","ReactiveErrorCode","ReactiveError","Error","constructor","message","debugInfo","super","this","name","options","enter","_effect","leave","chain","_targets","_caller","beginChain","endChain","garbageCollected","_fn","touched","_obj","_evolution","_props","_deps","skipRunningEffect","_runningChain","maxEffectChain","maxTriggerPerBatch","maxEffectReaction","onMemoizationDiscrepancy","undefined","cycleHandling","isVerificationRun","maxDeepWatchDepth","instanceMembers","ignoreAccessors","recursiveTouching","asyncMode","warn","args","introspection","enableHistory","historySize","zones","setTimeout","setInterval","requestAnimationFrame","queueMicrotask","zip","length","minLength","Math","min","map","arr","result","i","tuple","push","arrayEquals","a","b","Array","isArray","nativeConstructors","Set","Object","Date","Function","Map","WeakMap","WeakSet","Promise","TypeError","ReferenceError","SyntaxError","RangeError","URIError","EvalError","Reflect","Proxy","RegExp","String","Number","Boolean","isConstructor","fn","has","toString","startsWith","renamed","fct","defineProperties","value","ReflectGet","obj","prop","receiver","Node","get","ReflectSet","set","defineProperty","configurable","writable","enumerable","isOwnAccessor","opd","getOwnPropertyDescriptor","deepCompare","cache","getPrototypeOf","compared","add","match","getTime","size","val","found","bVal","key","foundMatch","bKey","keysA","keys","keysB","prototype","hasOwnProperty","call","DecoratorError","legacyDecorator","description","target","propertyKey","descriptor","class","includes","newGetter","getter","newSetter","setter","newMethod","method","default","modernDecorator","context","kind","rv","detectDecoratorMode","_target","contextOrKey","_descriptor","decorator","modern","legacy","fr","FinalizationRegistry","f","destructor","allocatedValues","DestructionError","msg","destroyedHandler","toStringTag","throw","Destroyable","base","destructorObj","_a","destroy","destructors","unregister","delete","setPrototypeOf","getOwnPropertyNames","isDestroyable","allocated","myDestructor","destruction","register","original","callOnGC","cb","called","forward","Eventful","_Eventful_events","_Eventful_hooks","hook","__classPrivateFieldGet","splice","indexOf","on","eventOrEvents","e","callbacks","off","filter","c","emit","event","apply","getAt","setAt","Indexable","accessor","index","getLength","numProp","isNaN","setLength","forwardArray","ArrayReadForward","iterator","callbackfn","thisArg","predicate","reduce","initialValue","reduceRight","forEach","find","findIndex","findLast","findLastIndex","searchElement","fromIndex","lastIndexOf","slice","start","end","concat","items","every","some","join","separator","values","entries","toLocaleString","locales","at","flat","depth","flatMap","callback","toReversed","reverse","toSorted","compareFn","sort","toSpliced","deleteCount","with","unscopables","IterableWeakMap","uuids","refs","registry","uuid","k","v","createIterator","keyRef","deref","clear","crypto","randomUUID","WeakRef","_value","_key","IterableWeakSet","_b","union","other","others","that","intersection","difference","symmetricDifference","isSubsetOf","isSupersetOf","isDisjointFrom","mixin","mixinFunction","unwrapFunction","mixinCache","MixedBase","_thisArg","baseClass","cached","usedBase","ProxiedBaseClass","originalPrototype","proxiedPrototype","mixedClass","effectToReactiveObjects","watchers","effectChildren","effectParent","reverseRoots","markWithRoot","root","existingRef","existing","rootName","existingName","fnName","getRoot","trackingDisabledEffects","globalTrackingDisabled","setGlobalTrackingDisabled","EXTERNAL_SOURCE","devtoolsEnabled","debugEffectRegistry","debugObjectRegistry","effectNames","objectNames","effectCounter","objectCounter","triggerGraph","ensureEffectName","effect","trim","ensureObjectName","ctorName","describeProp","objectName","addEffectToRegistry","deps","documentObject","dbRegisterObject","ensureParentChains","effects","queue","from","parent","ensureTriggerContainers","source","targetMap","ensureTriggerRecord","label","evolution","labelMap","record","object","count","lastTriggered","now","setEffectName","setObjectName","registerEffectForDebug","registerObjectForDebug","recordTriggerLink","addToMutationHistory","getTriggerChain","limit","current","foundSource","foundReason","search","lastTime","buildEffectNodes","allEffects","nodes","nodeByEffect","ordered","node","id","type","debugName","depthCache","computeDepth","parentNode","parentId","buildReactivityGraph","edges","nodeIds","effectNodes","externalId","effectId","objId","targetEffect","targetId","sourceId","meta","generatedAt","enableDevTools","window","__MUTTS_DEVTOOLS__","getGraph","registerEffect","registerObject","isDevtoolsEnabled","mutationHistory","mutationCounter","timestamp","shift","stack","captureEffectStack","isRunning","rootEffect","rootIndex","visited","ancestorChain","currentRoot","chainFromAncestor","unshift","stackFromDescendant","withEffectStack","snapshot","previousStack","assignStack","getActiveEffect","withEffect","objectToProxy","proxyToObject","storeProxyRelationship","proxy","getExistingProxy","trackProxyObject","unwrap","isReactive","getTrackingDisabled","active","setTrackingDisabled","dependant","currentActiveEffect","registerDependency","objectWatchers","effectObjects","zoneHooked","originalPromiseThen","then","originalPromiseCatch","catch","originalPromiseFinally","finally","originalSetTimeout","globalThis","originalSetInterval","originalRequestAnimationFrame","originalQueueMicrotask","batchFn","activationRegistry","ensureZoneHooked","batch","hookZone","onFulfilled","onRejected","capturedStack","wrapCallback","onFinally","wrappedSetTimeout","delay","assign","wrappedSetInterval","execute","setZoneEnabled","enabled","isZoneEnabled","findCycleInChain","roots","seen","formatRoots","names","r","activationLog","getActivationLog","recordActivation","effectData","objData","pop","effectName","code","MaxReactionExceeded","trackEffect","onTouch","activeEffect","effectTrackers","opaqueEffects","effectTriggers","effectTriggeredBy","causesClosure","consequencesClosure","effectCreationStacks","getOrCreateClosure","closure","addGraphEdge","callerRoot","targetRoot","triggers","newTriggers","triggeredBy","uConsequences","vCauses","uCausesSet","x","vConsequencesSet","y","xConsequences","hasPathExcluding","exclude","next","cleanupEffectFromGraph","rootCauses","rootConsequences","sourceRoot","causeRoot","causeConsequences","consequence","consequenceRoot","consequenceCauses","cause","yCauses","batchQueue","hasBatched","all","batchCleanups","computeAllInDegrees","activeRoot","inDegrees","inDegree","causes","decrementInDegreesForExecuted","executedRoot","consequences","currentDegree","findPath","startRoot","endRoot","path","newPath","getCyclePathForEdge","wouldCreateCycle","targetConsequences","addToBatch","caller","immediate","cleanupFn","cleanupSymbol","cyclePath","cycleMessage","causalChain","creationStack","CycleDetected","cycle","details","addBatchCleanup","defer","getCyclePath","recursionStack","findCycle","cycleStart","executeNext","effectuatedRoots","nextEffect","nextRoot","consequenceConsequences","firstEffect","firstRoot","firstEffect2","firstRoot2","firstReturn","trace","queued","MaxDepthExceeded","queuedCount","cleanups","atomic","atomicEffect","effectOptions","cleanStack","split","parentsForAscend","tracked","runEffect","ascend","effectStopped","hasReacted","runningPromise","cancelPrevious","prevCleanup","reactionCleanup","reaction","originalPromise","cancelReject","cancelPromise","_","reject","cancelError","race","reactiveObj","children","childCleanup","opaque","stopEffect","augmentedRv","callIfCollected","subEffectCleanup","untracked","wasTrackingDisabled","biDi","received","objectParents","objectsWithDeepWatchers","deepWatchers","effectToDeepWatchedObjects","addBackReference","child","parents","removeBackReference","entry","needsBackReferences","hasParentWithDeepWatchers","bubbleUpChange","changedObject","parentDeepWatchers","watcher","states","addState","state","getState","collectEffects","keyChains","sourceEffect","runningChain","trackers","tracker","touched1","props","touchedOpaque","nonReactiveObjects","immutables","absent","markNonReactive","o","nonReactiveClass","cls","isNonReactive","registerNativeReactivity","originalClass","reactiveClass","isObject","isObjectLike","getPrototypeToken","shouldRecurseTouch","oldValue","newValue","notifyPropertyChange","targetObj","hadProperty","origin","dispatchNotifications","recursiveTouch","hasVisitedPair","oldObj","newObj","mapped","collectObjectKeys","ownKeys","proto","hasOwn","notifications","diffArrayElements","diffObjectProperties","oldArray","newArray","_visited","local","oldLength","newLength","max","hasOld","hasNew","oldEntry","newEntry","is","oldKeys","newKeys","hasAncestorInSet","allowedSet","combinedEffects","allowedEffects","originWatchers","originEffects","currentEffects","propsArray","filteredEffects","document","Element","HTMLElement","EventTarget","hasReentry","reactiveHandlers","unwrappedObj","hasProp","isOwnProp","isInheritedAccess","shouldIgnoreAccessor","reactiveObject","reactiveValue","unwrappedReceiver","isArrayCase","oldVal","deleteProperty","reactiveClasses","ReactiveBase","reactive","anyTarget","proxied","Reactive","deepWatch","wrappedCallback","traverseAndTrack","unsetYet","watch","changed","watchCallBack","watchObject","deep","myParentEffect","deepCleanup","cbCleanup","access","deepNonReactive","unreactiveApplication","arg1","arg","unreactive","cleanedBy","derived","compute","makeReactiveIterator","done","makeReactiveEntriesIterator","native","ReactiveBaseArray","actualIndex","nativeIterator","unwrappedSearch","predicateOrElement","array","item","range","ReactiveArray","added","native$2","localeCompare","fill","copyWithin","ReadOnlyError","ReactiveReadOnlyArrayClass","_items","_start","_deleteCount","_compareFn","_end","ReactiveReadOnlyArray","inputs","resize","resultReactive","input","cleanupLength","resultLength","toCleanup","reduced","cleanupFactor","factor","memoizedRegistry","wrapperRegistry","getBranch","tree","branches","branch","memoizeFunction","fnRoot","cacheRoot","memoized","localArgs","wasVerification","fresh","memoize","wrapper","getRegisterBase","RegisterBase","toArray","RegisterClass","_classSuper","_classThis","_RegisterClass_keyFn","_RegisterClass_keys","_RegisterClass_values","_RegisterClass_usage","_RegisterClass_valueInfo","_RegisterClass_keyEffects","_RegisterClass_ascend","_RegisterClass_instances","keyFn","initial","ascendGet","__classPrivateFieldSet","ensureKey","info","stop","nextKey","assertValidKey","previousKey","_RegisterClass_rekeyValue","setKeyValue","cleanupValue","disposeKeyEffects","incrementUsage","decrementUsage","normalizeIndex","allowEnd","resolved","assignAt","oldKey","insertKeyValue","rebuildFrom","newKey","existingValue","existingCount","updatedInfo","normalized","removeAt","normalizedStart","maxDeletions","actualDelete","keysToInsert","removedKeys","removedValues","remove","indexOfKey","keep","decisions","shouldKeep","hasKey","mapKeys","update","upsert","insert","self","fwdCompareFn","__esDecorate","_classDescriptor","_classDecorators","metadata","_metadata","_classExtraInitializers","__runInitializers","Register","effectProjectionMetadata","getActiveProjection","defineAccessValue","makeCleanup","effectMap","onDispose","projectArray","observedSource","indexEffects","disposeIndex","normalizeTargetLength","previous","accessBase","old","produced","projectRegister","rawTarget","keyEffects","disposeKey","cleanupKeys","projectRecord","observed","sourceKey","projectMap","projectCore","project","organized","baseTarget","organize","property","ReactiveWeakMap","native$1","content","hadKey","ReactiveMap","hadEntries","ReactiveWeakSet","had","res","ReactiveSet","profileInfo","syncCalculating","alreadyCalculating","isCached","describe","properties","Base","deprecated","debounce","_propertyKey","timeoutId","clearTimeout","throttle","lastCallTime","remainingTime","scheduledArgs","version","pkg","GLOBAL_MUTTS_KEY","globalScope","global","__filename","eval","url","currentSourceInfo","JSON","stringify"],"mappings":"kPA2HA,MAAMA,eAAiBC,OAAO,mBAKjBC,gBAAkBD,OAAO,gBAIzBE,qBAAuBF,OAAO,yBAI9BG,oBAAqCH,OAAO,wBAK5CI,SAAWJ,OAAO,aAKlBK,eAAiBL,OAAO,mBAKxBM,QAAUN,OAAO,WAKjBO,UAAUP,OAAO,WAcxBQ,aAAeR,OAAO,iBAK5B,IAAYS,mBAAZ,SAAYA,GACXA,EAAA,cAAA,iBACAA,EAAA,iBAAA,qBACAA,EAAA,oBAAA,wBACAA,EAAA,gBAAA,oBACAA,EAAA,cAAA,gBACA,CAND,CAAYA,oBAAAA,kBAAiB,CAAA,IA0CvB,MAAOC,sBAAsBC,MAClC,WAAAC,CACCC,EACOC,GAEPC,MAAMF,GAFCG,KAAAF,UAAAA,EAGPE,KAAKC,KAAO,eACb,EAOM,MAAMC,QAAU,CAKtBC,MAAQC,MAKRC,MAAQD,MAMRE,MAAO,CAACC,EAAsBC,OAK9BC,WAAaF,MAIbG,SAAU,OACVC,iBAAmBC,MAQnBC,QAAS,CAACC,EAAWC,EAAuBC,EAAgBC,OAM5DC,kBAAmB,CAACd,EAAyBe,OAM7CC,eAAgB,IAMhBC,mBAAoB,GAMpBC,kBAAmB,QAoBnBC,8BAA0BC,EAW1BC,cAAe,QAKfC,mBAAmB,EAMnBC,kBAAmB,IAMnBC,iBAAiB,EAKjBC,iBAAiB,EAOjBC,mBAAmB,EAiBnBC,UAAW,SAEXC,KAAM,IAAIC,OAKVC,cAAe,CAKdC,eAAe,EAKfC,YAAa,IAQdC,MAAO,CAKNC,YAAY,EAKZC,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UAAU,CAChB,MAAAV,CAAOsC,EAAU/B,EAASivB,GACzB,IAAII,EAAe,EACfH,EAAkD,KAEtD,OAAO,YAAwBh2B,GAC9B,MAAMqT,EAAMzR,KAAKyR,MAGjB,GAAIA,EAAM8iB,GAAgBpc,EAOzB,OALIic,IACHC,aAAaD,GACbA,EAAY,MAEbG,EAAe9iB,EACRxK,EAASqB,MAAMnM,KAAMiC,GAI7B,IAAKg2B,EAAW,CACf,MAAMI,EAAgBrc,GAAS1G,EAAM8iB,GAC/BE,EAAgB,IAAIr2B,GAC1Bg2B,EAAY31B,WAAW,KACtB81B,EAAev0B,KAAKyR,MACpBxK,EAASqB,MAAMnM,KAAMs4B,GACrBL,EAAY,MACVI,EACJ,CACD,CACD,GAEF,+CC7MA,MAAME,QAAEA,SAAYC,IAGdC,iBAAmB,qBACnBC,YACkB,oBAAfzd,WAA6BA,WAClB,oBAAXnD,OAAyBA,OACd,oBAAX6gB,QAAyBA,OAClC,GAAGD,YAAa,CAEf,IAAI9jB,OAAS,cACb,IAEC,GAA0B,oBAAfgkB,WAA4BhkB,OAASgkB,eAE3C,CAEJ,MAAMjhB,KAAOkhB,KAAK,eACdlhB,MAAQA,KAAKmhB,MAAKlkB,OAAS+C,KAAKmhB,IACrC,CACD,CAAE,MAAOltB,GAET,CAEA,MAAMmtB,kBAAoB,CACzBR,gBACA3jB,cACA0D,UAAWzU,KAAKyR,OAGjB,GAAIojB,YAAYD,kBAAmB,CAClC,MAAM/lB,EAAWgmB,YAAYD,kBAC7B,MAAM,IAAI94B,MAET,4DAAsBq5B,KAAKC,UAAUvmB,EAAU,KAAM,qBACpCsmB,KAAKC,UAAUF,kBAAmB,KAAM,6NAK3D,CAEAL,YAAYD,kBAAoBM,iBACjC"}
1
+ {"version":3,"file":"mutts.umd.min.js","sources":["../src/async/index.ts","../src/async/browser.ts","../src/utils.ts","../src/decorator.ts","../src/destroyable.ts","../src/indexable.ts","../src/iterableWeak.ts","../src/mixins.ts","../src/promiseChain.ts","../src/reactive/types.ts","../src/reactive/registry.ts","../src/reactive/debug.ts","../src/zone.ts","../src/reactive/effect-context.ts","../src/reactive/proxy-state.ts","../src/reactive/effects.ts","../src/reactive/deep-watch-state.ts","../src/reactive/change.ts","../src/reactive/non-reactive-state.ts","../src/reactive/deep-touch.ts","../src/reactive/tracking.ts","../src/reactive/proxy.ts","../src/reactive/deep-watch.ts","../src/reactive/interface.ts","../src/reactive/memoize.ts","../src/reactive/non-reactive.ts","../src/reactive/register.ts","../src/reactive/project.ts","../src/reactive/array.ts","../src/reactive/map.ts","../src/reactive/set.ts","../src/reactive/index.ts","../src/std-decorators.ts","../src/index.ts","../src/eventful.ts","../src/reactive/record.ts","../src/reactive/buffer.ts"],"sourcesContent":["export type Restorer = () => () => void\nexport type Hook = () => Restorer\n\nexport const asyncHooks = {\n\taddHook(_hook: Hook): () => void {\n\t\tthrow 'One must import the library from the server or the client side'\n\t},\n /** \n * [Hack] Sanitize a promise (or value) to prevent context leaks. \n * Default: Identity function.\n * Browser: Uses Macrotask wrapping to break microtask chains.\n */\n sanitizePromise(p: any): any {\n return p\n }\n}\n\n/**\n * Register a hook that will be called whenever an asynchronous operation is initiated.\n * The hook should return a restorer function which will be called just before the async callback runs.\n * That restorer should in turn return an undoer function which will be called just after the async callback finishes.\n */\nexport const asyncHook = (hook: Hook) => asyncHooks.addHook(hook)","import { Hook, Restorer, asyncHooks } from '.'\n\nconst hooks = new Set<Hook>()\nconst promiseContexts = new WeakMap<Promise<any>, Set<Restorer>>()\n\nasyncHooks.addHook = function (hook: Hook) {\n\thooks.add(hook)\n\treturn () => {\n\t\thooks.delete(hook)\n\t}\n}\n\n// [HACK]: Sanitization\n// If a Promise is created inside the zone, it carries the \"Sticky\" zone context.\n// If returned to the outer scope, that context leaks. We wrap it in a new Promise\n// created here (in the outer scope) to break the chain and sanitize the return value.\n// See BROWSER_ASYNC_POLYFILL.md for full details.\nasyncHooks.sanitizePromise = (res: any) => {\n if (res && typeof (res as any).then === 'function') {\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n (res as any).then(resolve, reject)\n }, 0)\n })\n }\n return res\n}\n\nfunction captureRestorers() {\n\tconst restorers = new Set<Restorer>()\n\tfor (const hook of hooks) {\n\t\tconst restorer = hook()\n\t\tif (restorer) restorers.add(restorer)\n\t}\n\treturn restorers\n}\n\nfunction wrap<Args extends any[], R>(fn: ((...args: Args) => R) | null | undefined, capturedRestorers?: Set<Restorer>) {\n\tif (typeof fn !== 'function') return fn\n\tconst restorers = capturedRestorers || captureRestorers()\n\treturn function (this: any, ...args: Args) {\n\t\tconst undoers: (() => void)[] = []\n\t\tfor (const restore of restorers) undoers.push(restore())\n\t\ttry {\n\t\t\treturn fn.apply(this, args)\n\t\t} finally {\n\t\t\tif (originals.queueMicrotask) {\n\t\t\t\t// Double microtask ensures we run after the first await resumption microtask\n\t\t\t\toriginals.queueMicrotask.call(globalThis, () => {\n\t\t\t\t\toriginals.queueMicrotask.call(globalThis, () => {\n\t\t\t\t\t\toriginals.queueMicrotask.call(globalThis, () => {\n\t\t\t\t\t\t\tfor (let i = undoers.length - 1; i >= 0; i--) undoers[i]()\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tfor (let i = undoers.length - 1; i >= 0; i--) undoers[i]()\n\t\t\t}\n\t\t}\n\t}\n}\n\nconst targetWrappers = new WeakMap<any, Map<string, WeakMap<Function, Function>>>()\n\nfunction patchEventTarget(proto: any) {\n\tif (!proto || !proto.addEventListener || !proto.removeEventListener) return\n\tconst nativeAdd = proto.addEventListener\n\tconst nativeRemove = proto.removeEventListener\n\n\tproto.addEventListener = function (this: any, type: string, listener: any, options: any) {\n\t\tif (typeof listener !== 'function') {\n\t\t\treturn nativeAdd.call(this, type, listener, options)\n\t\t}\n\n\t\tlet types = targetWrappers.get(this)\n\t\tif (!types) {\n\t\t\ttypes = new Map()\n\t\t\ttargetWrappers.set(this, types)\n\t\t}\n\t\tlet listeners = types.get(type)\n\t\tif (!listeners) {\n\t\t\tlisteners = new WeakMap()\n\t\t\ttypes.set(type, listeners)\n\t\t}\n\n\t\tlet wrapped = listeners.get(listener)\n\t\tif (!wrapped) {\n\t\t\twrapped = wrap(listener)\n\t\t\tlisteners.set(listener, wrapped)\n\t\t}\n\t\t\n\t\treturn nativeAdd.call(this, type, wrapped, options)\n\t}\n\n\tproto.removeEventListener = function (this: any, type: string, listener: any, options: any) {\n\t\tif (typeof listener !== 'function') {\n\t\t\treturn nativeRemove.call(this, type, listener, options)\n\t\t}\n\n\t\tconst types = targetWrappers.get(this)\n\t\tif (types) {\n\t\t\tconst listeners = types.get(type)\n\t\t\tif (listeners) {\n\t\t\t\tconst wrapped = listeners.get(listener)\n\t\t\t\tif (wrapped) {\n\t\t\t\t\treturn nativeRemove.call(this, type, wrapped, options)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn nativeRemove.call(this, type, listener, options)\n\t}\n}\n\nfunction patchOnProperties(proto: any) {\n\tif (!proto) return\n\tfor (const prop of Object.getOwnPropertyNames(proto)) {\n\t\tif (prop.startsWith('on')) {\n\t\t\tconst desc = Object.getOwnPropertyDescriptor(proto, prop)\n\t\t\tif (desc && desc.set && desc.configurable) {\n\t\t\t\tconst nativeSet = desc.set\n\t\t\t\tObject.defineProperty(proto, prop, {\n\t\t\t\t\t...desc,\n\t\t\t\t\tset: function (this: any, fn: any) {\n\t\t\t\t\t\tnativeSet.call(this, wrap(fn))\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n}\n\nif (typeof EventTarget !== 'undefined') {\n\tpatchEventTarget(EventTarget.prototype)\n}\n\nconst prototypesToPatch = [\n\ttypeof EventTarget !== 'undefined' && EventTarget.prototype,\n\ttypeof HTMLElement !== 'undefined' && HTMLElement.prototype,\n\ttypeof Window !== 'undefined' && Window.prototype,\n\ttypeof Document !== 'undefined' && Document.prototype,\n\ttypeof MessagePort !== 'undefined' && MessagePort.prototype,\n\ttypeof XMLHttpRequest !== 'undefined' && XMLHttpRequest.prototype,\n\ttypeof IDBRequest !== 'undefined' && IDBRequest.prototype,\n\ttypeof IDBTransaction !== 'undefined' && IDBTransaction.prototype,\n\ttypeof IDBDatabase !== 'undefined' && IDBDatabase.prototype,\n\ttypeof FileReader !== 'undefined' && FileReader.prototype,\n\ttypeof AbortSignal !== 'undefined' && AbortSignal.prototype,\n]\n\nfor (const proto of prototypesToPatch) {\n\tif (proto) {\n\t\tpatchOnProperties(proto)\n\t}\n}\n\nconst GLOBAL_ORIGINALS = Symbol.for('mutts.originals');\nconst GLOBAL_PROMISE = Symbol.for('mutts.OriginalPromise');\n\nlet originals: any;\nlet OriginalPromise: any;\n\nif ((globalThis as any)[GLOBAL_ORIGINALS]) {\n originals = (globalThis as any)[GLOBAL_ORIGINALS];\n OriginalPromise = (globalThis as any)[GLOBAL_PROMISE];\n} else {\n OriginalPromise = globalThis.Promise;\n originals = {\n then: OriginalPromise.prototype.then,\n catch: OriginalPromise.prototype.catch,\n finally: OriginalPromise.prototype.finally,\n resolve: OriginalPromise.resolve,\n reject: OriginalPromise.reject,\n all: OriginalPromise.all,\n allSettled: (OriginalPromise as any).allSettled,\n race: OriginalPromise.race,\n any: (OriginalPromise as any).any,\n setTimeout: globalThis.setTimeout,\n setInterval: globalThis.setInterval,\n setImmediate: (globalThis as any).setImmediate,\n requestAnimationFrame: (globalThis as any).requestAnimationFrame,\n queueMicrotask: globalThis.queueMicrotask,\n };\n (globalThis as any)[GLOBAL_ORIGINALS] = originals;\n (globalThis as any)[GLOBAL_PROMISE] = OriginalPromise;\n}\n\n// Ensure modern statics are captured even if originals was cached from an older version\nif (!originals.allSettled) originals.allSettled = (OriginalPromise as any).allSettled\nif (!originals.any) originals.any = (OriginalPromise as any).any\nif (!originals.race) originals.race = OriginalPromise.race\n\nfunction patchedThen(this: any, onFulfilled: any, onRejected: any) {\n\tconst context = promiseContexts.get(this) || captureRestorers()\n\tconst nextPromise = originals.then.call(this, wrap(onFulfilled, context), wrap(onRejected, context))\n\tif (context.size > 0) promiseContexts.set(nextPromise, context)\n\treturn nextPromise\n}\n\nfunction patchedCatch(this: any, onRejected: any) {\n\tconst context = promiseContexts.get(this) || captureRestorers()\n\tconst nextPromise = originals.catch.call(this, wrap(onRejected, context))\n\tif (context.size > 0) promiseContexts.set(nextPromise, context)\n\treturn nextPromise\n}\n\nfunction patchedFinally(this: any, onFinally: any) {\n\tconst context = promiseContexts.get(this) || captureRestorers()\n\tconst nextPromise = originals.finally.call(this, wrap(onFinally, context))\n\tif (context.size > 0) promiseContexts.set(nextPromise, context)\n\treturn nextPromise\n}\n\nfunction PatchedPromise<T>(this: any, executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void) {\n if (typeof executor === 'function') {\n const p = new OriginalPromise((resolve, reject) => {\n const wrappedResolve = wrap(resolve)\n const wrappedReject = wrap(reject)\n executor(wrappedResolve, wrappedReject)\n })\n const context = captureRestorers()\n promiseContexts.set(p, context) // Always set, even if empty (Sticky Root)\n return p\n }\n return new OriginalPromise(executor)\n}\n\n// Copy statics\nObject.assign(PatchedPromise, (OriginalPromise as any))\n\n// Inherit prototype for instanceof checks\nPatchedPromise.prototype = OriginalPromise.prototype\n\nPatchedPromise.resolve = function<T>(value?: T | PromiseLike<T>): Promise<T> {\n const p = originals.resolve.call(OriginalPromise, value) as Promise<T>\n const context = captureRestorers()\n // Ensure we don't overwrite if it already has context (e.g. from constructor)\n if (context.size > 0 && !promiseContexts.has(p)) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.reject = function<T = never>(reason?: any): Promise<T> {\n const p = originals.reject.call(OriginalPromise, reason) as Promise<T>\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.all = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]> {\n const p = originals.all.call(OriginalPromise, values) as Promise<Awaited<T>[]>\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.allSettled = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<PromiseSettledResult<Awaited<T>>[]> {\n const p = (originals.allSettled as any).call(OriginalPromise, values)\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.race = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>> {\n const p = originals.race.call(OriginalPromise, values) as Promise<Awaited<T>>\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\nPatchedPromise.any = function<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>> {\n const p = (originals.any as any).call(OriginalPromise, values)\n const context = captureRestorers()\n if (context.size > 0) promiseContexts.set(p, context)\n return p\n} as any\n\n// Only apply patches if not already applied (or re-apply safely)\n// Note: OriginalPromise.prototype might be shared if we used the global one.\n// We must ensure we don't patch it twice if it's the SAME object.\nif (OriginalPromise.prototype.then !== patchedThen) {\n OriginalPromise.prototype.then = patchedThen as any\n OriginalPromise.prototype.catch = patchedCatch as any\n OriginalPromise.prototype.finally = patchedFinally as any\n}\n\ntry {\n\tObject.defineProperty(OriginalPromise, Symbol.species, {\n\t\tget: () => PatchedPromise,\n\t\tconfigurable: true\n\t})\n} catch (e) {}\n\n;(globalThis as any).Promise = PatchedPromise\n\nglobalThis.setTimeout = ((callback: Function, ...args: any[]) => {\n\treturn originals.setTimeout.call(globalThis, wrap(callback as any), ...args)\n}) as any\n\nglobalThis.setInterval = ((callback: Function, ...args: any[]) => {\n\treturn originals.setInterval.call(globalThis, wrap(callback as any), ...args)\n}) as any\n\nif (originals.setImmediate) {\n\t;(globalThis as any).setImmediate = ((callback: Function, ...args: any[]) => {\n\t\treturn originals.setImmediate.call(globalThis, wrap(callback as any), ...args)\n\t}) as any\n}\n\nif (originals.requestAnimationFrame) {\n\tglobalThis.requestAnimationFrame = (callback: FrameRequestCallback) => {\n\t\treturn originals.requestAnimationFrame.call(globalThis, wrap(callback))\n\t}\n}\n\nif (originals.queueMicrotask) {\n\tglobalThis.queueMicrotask = (callback: VoidFunction): void => {\n\t\toriginals.queueMicrotask.call(globalThis, wrap(callback))\n\t}\n}\n","type ElementTypes<T extends readonly unknown[]> = {\n\t[K in keyof T]: T[K] extends readonly (infer U)[] ? U : T[K]\n}\n\n/**\n * Combines multiple arrays into an array of tuples, stopping at the shortest array length\n * @param args - Arrays to zip together\n * @returns Array of tuples containing elements from each input array\n */\nexport function zip<T extends (readonly unknown[])[]>(...args: T): ElementTypes<T>[] {\n\tif (!args.length) return []\n\tconst minLength = Math.min(...args.map((arr) => arr.length))\n\tconst result: ElementTypes<T>[] = []\n\n\tfor (let i = 0; i < minLength; i++) {\n\t\tconst tuple = args.map((arr) => arr[i]) as ElementTypes<T>\n\t\tresult.push(tuple)\n\t}\n\n\treturn result\n}\n\n/**\n * Checks if two arrays are strictly equal (shallow comparison)\n * @param a - First value\n * @param b - Second value\n * @returns True if arrays are equal or values are strictly equal\n */\nexport function arrayEquals(a: any, b: any): boolean {\n\tif (a === b) return true\n\tif (!Array.isArray(a) || !Array.isArray(b)) return false\n\tif (a.length !== b.length) return false\n\tfor (let i = 0; i < a.length; i++) {\n\t\tif (a[i] !== b[i]) return false\n\t}\n\treturn true\n}\n\nconst nativeConstructors = new Set<Function>([\n\tObject,\n\tArray,\n\tDate,\n\tFunction,\n\tSet,\n\tMap,\n\tWeakMap,\n\tWeakSet,\n\tPromise,\n\tError,\n\tTypeError,\n\tReferenceError,\n\tSyntaxError,\n\tRangeError,\n\tURIError,\n\tEvalError,\n\tReflect,\n\tProxy,\n\tRegExp,\n\tString,\n\tNumber,\n\tBoolean,\n] as Function[])\n/**\n * Checks if a function is a constructor (class or constructor function)\n * @param fn - The function to check\n * @returns True if the function is a constructor\n */\nexport function isConstructor(fn: Function): boolean {\n\treturn (\n\t\tfn &&\n\t\ttypeof fn === 'function' &&\n\t\t(nativeConstructors.has(fn) || fn.toString?.().startsWith('class '))\n\t)\n}\n\n/**\n * Renames a function with a new name\n * @param fct - The function to rename\n * @param name - The new name for the function\n * @returns The function with the new name\n */\nexport function renamed<F extends Function>(fct: F, name: string): F {\n\treturn Object.defineProperties(fct, {\n\t\tname: {\n\t\t\tvalue: name,\n\t\t},\n\t})\n}\nexport const FoolProof = {\n\tget(obj: any, prop: any, receiver: any) {\n\t\t// Check if Node is available and obj is an instance of Node\n\t\tif (typeof Node !== 'undefined' && obj instanceof Node) return (obj as any)[prop]\n\t\treturn Reflect.get(obj, prop, receiver)\n\t},\n\tset(obj: any, prop: any, value: any, receiver: any) {\n\t\t// Check if Node is available and obj is an instance of Node\n\t\tif (typeof Node !== 'undefined' && obj instanceof Node) {\n\t\t\t;(obj as any)[prop] = value\n\t\t\treturn true\n\t\t}\n\t\tif (!(obj instanceof Object) && !Reflect.has(obj, prop)) {\n\t\t\tObject.defineProperty(obj, prop, {\n\t\t\t\tvalue,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t\tenumerable: true,\n\t\t\t})\n\t\t\treturn true\n\t\t}\n\t\treturn Reflect.set(obj, prop, value, receiver)\n\t},\n}\n\nexport function isOwnAccessor(obj: any, prop: any) {\n\tconst opd = Object.getOwnPropertyDescriptor(obj, prop)\n\treturn !!(opd?.get || opd?.set)\n}\n\n/**\n * Deeply compares two values.\n * For objects, compares prototypes with === and then own properties recursively.\n * Uses a cache to handle circular references.\n * @param a - First value\n * @param b - Second value\n * @param cache - Map for circular reference protection (internal use)\n * @returns True if values are deeply equal\n */\nexport function deepCompare(a: any, b: any, cache = new Map<object, Set<object>>()): boolean {\n\tif (a === b) return true\n\n\tif (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {\n\t\treturn a === b\n\t}\n\n\t// Prototype check\n\tconst protoA = Object.getPrototypeOf(a)\n\tconst protoB = Object.getPrototypeOf(b)\n\tif (protoA !== protoB) {\n\t\tconsole.warn(`[deepCompare] prototype mismatch:`, {\n\t\t\tnameA: a?.constructor?.name,\n\t\t\tnameB: b?.constructor?.name,\n\t\t})\n\t\treturn false\n\t}\n\t// Circular reference protection\n\tlet compared = cache.get(a)\n\tif (compared?.has(b)) return true\n\tif (!compared) {\n\t\tcompared = new Set()\n\t\tcache.set(a, compared)\n\t}\n\tcompared.add(b)\n\n\t// Handle specific object types\n\tif (Array.isArray(a)) {\n\t\tif (!Array.isArray(b)) {\n\t\t\tconsole.warn(`[deepCompare] B is not an array`)\n\t\t\treturn false\n\t\t}\n\t\tif (a.length !== b.length) {\n\t\t\tconsole.warn(`[deepCompare] array length mismatch:`, { lenA: a.length, lenB: b.length })\n\t\t\treturn false\n\t\t}\n\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\tif (!deepCompare(a[i], b[i], cache)) {\n\t\t\t\tconsole.warn(`[deepCompare] array element mismatch at index ${i}`)\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\tif (a instanceof Date) {\n\t\tconst match = b instanceof Date && a.getTime() === b.getTime()\n\t\tif (!match) console.warn(`[deepCompare] Date mismatch`)\n\t\treturn match\n\t}\n\tif (a instanceof RegExp) {\n\t\tconst match = b instanceof RegExp && a.toString() === b.toString()\n\t\tif (!match) console.warn(`[deepCompare] RegExp mismatch`)\n\t\treturn match\n\t}\n\tif (a instanceof Set) {\n\t\tif (!(b instanceof Set) || a.size !== b.size) {\n\t\t\tconsole.warn(`[deepCompare] Set size mismatch`)\n\t\t\treturn false\n\t\t}\n\t\tfor (const val of a) {\n\t\t\tlet found = false\n\t\t\tfor (const bVal of b) {\n\t\t\t\tif (deepCompare(val, bVal, cache)) {\n\t\t\t\t\tfound = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!found) {\n\t\t\t\tconsole.warn(`[deepCompare] missing Set element`)\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\tif (a instanceof Map) {\n\t\tif (!(b instanceof Map) || a.size !== b.size) {\n\t\t\tconsole.warn(`[deepCompare] Map size mismatch`)\n\t\t\treturn false\n\t\t}\n\t\tfor (const [key, val] of a) {\n\t\t\tif (!b.has(key)) {\n\t\t\t\tlet foundMatch = false\n\t\t\t\tfor (const [bKey, bVal] of b) {\n\t\t\t\t\tif (deepCompare(key, bKey, cache) && deepCompare(val, bVal, cache)) {\n\t\t\t\t\t\tfoundMatch = true\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!foundMatch) {\n\t\t\t\t\tconsole.warn(`[deepCompare] missing Map key`)\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (!deepCompare(val, b.get(key), cache)) {\n\t\t\t\t\tconsole.warn(`[deepCompare] Map value mismatch for key`)\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\t// Compare own properties\n\tconst keysA = Object.keys(a)\n\tconst keysB = Object.keys(b)\n\tif (keysA.length !== keysB.length) {\n\t\tconsole.warn(`[deepCompare] keys length mismatch:`, {\n\t\t\tlenA: keysA.length,\n\t\t\tlenB: keysB.length,\n\t\t\tkeysA,\n\t\t\tkeysB,\n\t\t\ta,\n\t\t\tb,\n\t\t})\n\t\treturn false\n\t}\n\n\tfor (const key of keysA) {\n\t\tif (!Object.hasOwn(b, key)) {\n\t\t\tconsole.warn(`[deepCompare] missing key ${String(key)} in B`)\n\t\t\treturn false\n\t\t}\n\t\tif (!deepCompare(a[key], b[key], cache)) {\n\t\t\tconsole.warn(`[deepCompare] value mismatch for key ${String(key)}:`, {\n\t\t\t\tvalA: a[key],\n\t\t\t\tvalB: b[key],\n\t\t\t})\n\t\t\treturn false\n\t\t}\n\t}\n\n\treturn true\n}\n\n\nconst contentRefs = new WeakMap<object, any>()\nexport function contentRef(container: object) {\n\tif (!contentRefs.has(container))\n\t\tcontentRefs.set(\n\t\t\tcontainer,\n\t\t\tObject.seal(\n\t\t\t\tObject.create(null, {\n\t\t\t\t\tcontentOf: { value: container, writable: false, configurable: false },\n\t\t\t\t})\n\t\t\t)\n\t\t)\n\treturn contentRefs.get(container)\n}\n\nexport function tag<T extends object>(name: string, obj: T): T {\n\tObject.defineProperties(obj, {\n\t\t[Symbol.toStringTag]: {\n\t\t\tvalue: name,\n\t\t\twritable: false,\n\t\t\tconfigurable: false,\n\t\t},\n\t\ttoString: {\n\t\t\tvalue: () => name,\n\t\t\twritable: false,\n\t\t\tconfigurable: false,\n\t\t},\n\t})\n\treturn obj\n}\n\nexport function named<T extends Function>(name: string, fn: T): T {\n\tObject.defineProperty(fn, 'name', {\n\t\tvalue: fn.name ? `${fn.name}::${name}` : name,\n\t\twritable: false,\n\t\tconfigurable: false,\n\t})\n\treturn fn\n}","// biome-ignore-all lint/suspicious/noConfusingVoidType: We *love* voids\n// Standardized decorator system that works with both Legacy and Modern decorators\n\nimport { isConstructor } from './utils'\n\n/**\n * Error thrown when decorator operations fail\n */\nexport class DecoratorError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'DecoratorException'\n\t}\n}\n//#region all decorator types\n\n// Used for get/set and method decorators\n/**\n * Legacy property decorator type for methods, getters, and setters\n */\nexport type LegacyPropertyDecorator<T> = (\n\ttarget: T,\n\tname: string | symbol,\n\tdescriptor: PropertyDescriptor\n) => any\n\n/**\n * Legacy class decorator type\n */\nexport type LegacyClassDecorator<T> = (target: T) => any\n\n/**\n * Modern method decorator type\n */\nexport type ModernMethodDecorator<T> = (target: T, context: ClassMethodDecoratorContext) => any\n\n/**\n * Modern getter decorator type\n */\nexport type ModernGetterDecorator<T> = (target: T, context: ClassGetterDecoratorContext) => any\n\n/**\n * Modern setter decorator type\n */\nexport type ModernSetterDecorator<T> = (target: T, context: ClassSetterDecoratorContext) => any\n\n/**\n * Modern accessor decorator type\n */\nexport type ModernAccessorDecorator<T> = (target: T, context: ClassAccessorDecoratorContext) => any\n\n/**\n * Modern class decorator type\n */\nexport type ModernClassDecorator<T> = (target: T, context: ClassDecoratorContext) => any\n\n//#endregion\n\ntype DDMethod<T> = (\n\toriginal: (this: T, ...args: any[]) => any,\n\ttarget: any,\n\tname: PropertyKey\n) => ((this: T, ...args: any[]) => any) | void\n\ntype DDGetter<T> = (\n\toriginal: (this: T) => any,\n\ttarget: any,\n\tname: PropertyKey\n) => ((this: T) => any) | void\n\ntype DDSetter<T> = (\n\toriginal: (this: T, value: any) => void,\n\ttarget: any,\n\tname: PropertyKey\n) => ((this: T, value: any) => void) | void\n\ntype DDClass<T> = <Ctor extends new (...args: any[]) => T = new (...args: any[]) => T>(\n\ttarget: Ctor\n) => Ctor | void\n/**\n * Description object for creating decorators that work with both Legacy and Modern decorator proposals\n */\nexport interface DecoratorDescription<T> {\n\t/** Handler for method decorators */\n\tmethod?: DDMethod<T>\n\t/** Handler for class decorators */\n\tclass?: DDClass<T>\n\t/** Handler for getter decorators */\n\tgetter?: DDGetter<T>\n\t/** Handler for setter decorators */\n\tsetter?: DDSetter<T>\n\t/** Default handler for any decorator type not explicitly defined */\n\tdefault?: (...args: any[]) => any\n}\n\n/**\n * Type for decorators that work with both Legacy and Modern decorator proposals\n * Automatically infers the correct decorator type based on the description\n */\nexport type Decorator<T, Description extends DecoratorDescription<T>> = (Description extends {\n\tmethod: DDMethod<T>\n}\n\t? LegacyPropertyDecorator<T> & ModernMethodDecorator<T>\n\t: unknown) &\n\t(Description extends { class: DDClass<new (...args: any[]) => T> }\n\t\t? LegacyClassDecorator<new (...args: any[]) => T> &\n\t\t\t\tModernClassDecorator<new (...args: any[]) => T>\n\t\t: unknown) &\n\t(Description extends { getter: DDGetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { setter: DDSetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { default: infer Signature } ? Signature : unknown)\n\n/**\n * Factory type for creating decorators that work with both Legacy and Modern decorator proposals\n */\nexport type DecoratorFactory<T> = <Description extends DecoratorDescription<T>>(\n\tdescription: Description\n) => (Description extends { method: DDMethod<T> }\n\t? LegacyPropertyDecorator<T> & ModernMethodDecorator<T>\n\t: unknown) &\n\t(Description extends { class: DDClass<new (...args: any[]) => T> }\n\t\t? LegacyClassDecorator<new (...args: any[]) => T> &\n\t\t\t\tModernClassDecorator<new (...args: any[]) => T>\n\t\t: unknown) &\n\t(Description extends { getter: DDGetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernGetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { setter: DDSetter<T> }\n\t\t? LegacyPropertyDecorator<T> & ModernSetterDecorator<T> & ModernAccessorDecorator<T>\n\t\t: unknown) &\n\t(Description extends { default: infer Signature } ? Signature : unknown)\n\n/**\n * Creates a decorator that works with Legacy decorator proposals\n * @param description - The decorator description object\n * @returns A decorator function compatible with Legacy decorators\n */\nexport function legacyDecorator<T = any>(description: DecoratorDescription<T>): any {\n\treturn function (\n\t\tthis: any,\n\t\ttarget: any,\n\t\tpropertyKey?: PropertyKey,\n\t\tdescriptor?: PropertyDescriptor,\n\t\t...args: any[]\n\t) {\n\t\tif (propertyKey === undefined) {\n\t\t\tif (isConstructor(target)) {\n\t\t\t\tif (!('class' in description)) throw new Error('Decorator cannot be applied to a class')\n\t\t\t\treturn description.class!(target)\n\t\t\t}\n\t\t} else if (typeof target === 'object' && ['string', 'symbol'].includes(typeof propertyKey)) {\n\t\t\tif (!descriptor) throw new Error('Decorator cannot be applied to a field')\n\t\t\telse if (typeof descriptor === 'object' && 'configurable' in descriptor) {\n\t\t\t\tif ('get' in descriptor || 'set' in descriptor) {\n\t\t\t\t\tif (!('getter' in description || 'setter' in description))\n\t\t\t\t\t\tthrow new Error('Decorator cannot be applied to a getter or setter')\n\t\t\t\t\tif ('getter' in description) {\n\t\t\t\t\t\tconst newGetter = description.getter!(descriptor.get as any, target, propertyKey)\n\t\t\t\t\t\tif (newGetter) descriptor.get = newGetter\n\t\t\t\t\t}\n\t\t\t\t\tif ('setter' in description) {\n\t\t\t\t\t\tconst newSetter = description.setter!(descriptor.set as any, target, propertyKey)\n\t\t\t\t\t\tif (newSetter) descriptor.set = newSetter\n\t\t\t\t\t}\n\t\t\t\t\treturn descriptor\n\t\t\t\t} else if (typeof descriptor.value === 'function') {\n\t\t\t\t\tif (!('method' in description)) throw new Error('Decorator cannot be applied to a method')\n\t\t\t\t\tconst newMethod = description.method!(descriptor.value, target, propertyKey)\n\t\t\t\t\tif (newMethod) descriptor.value = newMethod\n\t\t\t\t\treturn descriptor\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!('default' in description))\n\t\t\tthrow new Error('Decorator do not have a default implementation')\n\t\treturn description.default!.call(this, target, propertyKey, descriptor, ...args)\n\t}\n}\n\n/**\n * Creates a decorator that works with Modern decorator proposals\n * @param description - The decorator description object\n * @returns A decorator function compatible with Modern decorators\n */\nexport function modernDecorator<T = any>(description: DecoratorDescription<T>): any {\n\t/*return function (target: any, context?: DecoratorContext, ...args: any[]) {*/\n\treturn function (this: any, target: any, context?: DecoratorContext, ...args: any[]) {\n\t\tif (!context?.kind || typeof context.kind !== 'string') {\n\t\t\tif (!('default' in description))\n\t\t\t\tthrow new Error('Decorator do not have a default implementation')\n\t\t\treturn description.default!.call(this, target, context, ...args)\n\t\t}\n\t\tswitch (context.kind) {\n\t\t\tcase 'class':\n\t\t\t\tif (!('class' in description)) throw new Error('Decorator cannot be applied to a class')\n\t\t\t\treturn description.class!(target)\n\t\t\tcase 'field':\n\t\t\t\tthrow new Error('Decorator cannot be applied to a field')\n\t\t\tcase 'getter':\n\t\t\t\tif (!('getter' in description)) throw new Error('Decorator cannot be applied to a getter')\n\t\t\t\treturn description.getter!(target, target, context.name)\n\t\t\tcase 'setter':\n\t\t\t\tif (!('setter' in description)) throw new Error('Decorator cannot be applied to a setter')\n\t\t\t\treturn description.setter!(target, target, context.name)\n\t\t\tcase 'method':\n\t\t\t\tif (!('method' in description)) throw new Error('Decorator cannot be applied to a method')\n\t\t\t\treturn description.method!(target, target, context.name)\n\t\t\tcase 'accessor': {\n\t\t\t\tif (!('getter' in description || 'setter' in description))\n\t\t\t\t\tthrow new Error('Decorator cannot be applied to a getter or setter')\n\t\t\t\tconst rv: Partial<ClassAccessorDecoratorResult<any, any>> = {}\n\t\t\t\tif ('getter' in description) {\n\t\t\t\t\tconst newGetter = description.getter!(target.get, target, context.name)\n\t\t\t\t\tif (newGetter) rv.get = newGetter\n\t\t\t\t}\n\t\t\t\tif ('setter' in description) {\n\t\t\t\t\tconst newSetter = description.setter!(target.set, target, context.name)\n\t\t\t\t\tif (newSetter) rv.set = newSetter\n\t\t\t\t}\n\t\t\t\treturn rv\n\t\t\t}\n\t\t\t//return description.accessor?.(target, context.name, target)\n\t\t}\n\t}\n}\n\n/**\n * Detects if the decorator is being called in modern (Modern) or legacy (Legacy) mode\n * based on the arguments passed to the decorator function\n */\nfunction detectDecoratorMode(\n\t_target: any,\n\tcontextOrKey?: any,\n\t_descriptor?: any\n): 'modern' | 'legacy' {\n\t// Modern decorators have a context object as the second parameter\n\t// Legacy decorators have a string/symbol key as the second parameter\n\tif (\n\t\ttypeof contextOrKey === 'object' &&\n\t\tcontextOrKey !== null &&\n\t\ttypeof contextOrKey.kind === 'string'\n\t) {\n\t\treturn 'modern'\n\t}\n\treturn 'legacy'\n}\n\n/**\n * Main decorator factory that automatically detects and works with both Legacy and Modern decorator proposals\n * @param description - The decorator description object\n * @returns A decorator that works in both Legacy and Modern environments\n */\nexport const decorator: DecoratorFactory<any> = (description: DecoratorDescription<any>) => {\n\tconst modern = modernDecorator(description)\n\tconst legacy = legacyDecorator(description)\n\treturn ((target: any, contextOrKey?: any, ...args: any[]) => {\n\t\tconst mode = detectDecoratorMode(target, contextOrKey, args[0])\n\t\treturn mode === 'modern'\n\t\t\t? modern(target, contextOrKey, ...args)\n\t\t\t: legacy(target, contextOrKey, ...args)\n\t}) as any\n}\n\n/**\n * Generic class decorator type that works with both Legacy and Modern decorator proposals\n */\nexport type GenericClassDecorator<T> = LegacyClassDecorator<abstract new (...args: any[]) => T> &\n\tModernClassDecorator<abstract new (...args: any[]) => T>\n","import { decorator } from './decorator'\n\n// Integrated with `using` statement via Symbol.dispose\nconst fr = new FinalizationRegistry<() => void>((f) => f())\n/**\n * Symbol for marking destructor methods\n */\nexport const destructor = Symbol('destructor')\n/**\n * Symbol for accessing allocated values in destroyable objects\n */\nexport const allocatedValues = Symbol('allocated')\n/**\n * Error thrown when attempting to access a destroyed object\n */\nexport class DestructionError extends Error {\n\tstatic throw<_T = void>(msg: string) {\n\t\treturn () => {\n\t\t\tthrow new DestructionError(msg)\n\t\t}\n\t}\n\tconstructor(msg: string) {\n\t\tsuper(`Object is destroyed. ${msg}`)\n\t\tthis.name = 'DestroyedAccessError'\n\t}\n}\nconst destroyedHandler = {\n\t[Symbol.toStringTag]: 'MutTs Destroyable',\n\tget: DestructionError.throw('Cannot access destroyed object'),\n\tset: DestructionError.throw('Cannot access destroyed object'),\n} as const\n\nabstract class AbstractDestroyable<Allocated> {\n\tabstract [destructor](allocated: Allocated): void\n\t[Symbol.dispose](): void {\n\t\tthis[destructor](this as unknown as Allocated)\n\t}\n}\n\ninterface Destructor<Allocated> {\n\tdestructor(allocated: Allocated): void\n}\n\n/**\n * Creates a destroyable class with a base class and destructor object\n * @param base - The base class to extend\n * @param destructorObj - Object containing the destructor method\n * @returns A destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Partial<InstanceType<T>>,\n>(\n\tbase: T,\n\tdestructorObj: Destructor<Allocated>\n): (new (\n\t...args: ConstructorParameters<T>\n) => InstanceType<T> & { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: InstanceType<T>): boolean\n\tisDestroyable(obj: InstanceType<T>): boolean\n}\n\n/**\n * Creates a destroyable class with only a destructor object (no base class)\n * @param destructorObj - Object containing the destructor method\n * @returns A destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<Allocated extends Record<PropertyKey, any> = Record<PropertyKey, any>>(\n\tdestructorObj: Destructor<Allocated>\n): (new () => { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: any): boolean\n\tisDestroyable(obj: any): boolean\n}\n\n/**\n * Creates a destroyable class with a base class (requires [destructor] method)\n * @param base - The base class to extend\n * @returns A destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(\n\tbase: T\n): (new (\n\t...args: ConstructorParameters<T>\n) => AbstractDestroyable<Allocated> & InstanceType<T> & { [allocatedValues]: Allocated }) & {\n\tdestroy(obj: InstanceType<T>): boolean\n\tisDestroyable(obj: InstanceType<T>): boolean\n}\n\n/**\n * Creates an abstract destroyable base class\n * @returns An abstract destroyable class with static destroy and isDestroyable methods\n */\nexport function Destroyable<\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(): abstract new () => (AbstractDestroyable<Allocated> & {\n\t[allocatedValues]: Allocated\n}) & {\n\tdestroy(obj: any): boolean\n\tisDestroyable(obj: any): boolean\n}\n\nexport function Destroyable<\n\tT extends new (\n\t\t...args: any[]\n\t) => any,\n\tAllocated extends Record<PropertyKey, any> = Record<PropertyKey, any>,\n>(base?: T | Destructor<Allocated>, destructorObj?: Destructor<Allocated>) {\n\tif (base && typeof base !== 'function') {\n\t\tdestructorObj = base as Destructor<Allocated>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\tbase = class {} as T\n\t}\n\n\treturn class Destroyable extends (base as T) {\n\t\tstatic readonly destructors = new WeakMap<any, () => void>()\n\t\tstatic destroy(obj: Destroyable) {\n\t\t\tconst destructor = Destroyable.destructors.get(obj)\n\t\t\tif (!destructor) return false\n\t\t\tfr.unregister(obj[allocatedValues])\n\t\t\tDestroyable.destructors.delete(obj)\n\t\t\tObject.setPrototypeOf(obj, new Proxy({}, destroyedHandler))\n\t\t\t// Clear all own properties\n\t\t\tfor (const key of Object.getOwnPropertyNames(obj)) {\n\t\t\t\tdelete (obj as any)[key]\n\t\t\t}\n\t\t\tdestructor()\n\t\t\treturn true\n\t\t}\n\t\tstatic isDestroyable(obj: Destroyable) {\n\t\t\treturn Destroyable.destructors.has(obj)\n\t\t}\n\n\t\t[forwardProperties]!: PropertyKey[]\n\t\treadonly [allocatedValues]: Allocated\n\t\tconstructor(...args: any[]) {\n\t\t\tsuper(...args)\n\t\t\tconst allocated = {} as Allocated\n\t\t\tthis[allocatedValues] = allocated\n\t\t\t// @ts-expect-error `this` is an AbstractDestroyable\n\t\t\tconst myDestructor = destructorObj?.destructor ?? this[destructor]\n\t\t\tif (!myDestructor) {\n\t\t\t\tthrow new DestructionError('Destructor is not defined')\n\t\t\t}\n\t\t\tfunction destruction() {\n\t\t\t\tmyDestructor(allocated)\n\t\t\t}\n\t\t\tDestroyable.destructors.set(this, destruction)\n\t\t\tfr.register(this, destruction, allocated)\n\t\t}\n\t}\n}\n\nconst forwardProperties = Symbol('forwardProperties')\n/**\n * Decorator that marks properties to be stored in the allocated object and passed to the destructor\n * Use with accessor properties or explicit get/set pairs\n */\nexport const allocated = decorator({\n\tsetter(original, _target, propertyKey) {\n\t\treturn function (value) {\n\t\t\tthis[allocatedValues][propertyKey] = value\n\t\t\treturn original.call(this, value)\n\t\t}\n\t},\n})\n\n/**\n * Registers a callback to be called when an object is garbage collected\n * @param cb - The callback function to execute on garbage collection\n * @returns The object whose reference can be collected\n */\nexport function callOnGC(cb: () => void) {\n\tlet called = false\n\tconst forward = () => {\n\t\tif (called) return\n\t\tcalled = true\n\t\tcb()\n\t}\n\tfr.register(forward, cb, cb)\n\treturn forward\n}\n\n/**\n * Context Manager Protocol for `using` statement integration\n * Provides automatic resource cleanup when used with the `using` statement\n */\nexport interface ContextManager<T = any> {\n\t[Symbol.dispose](): void\n\tvalue?: T\n}\n","/**\n * Symbol for defining custom getter logic for numeric index access\n */\nexport const getAt = Symbol('getAt')\n/**\n * Symbol for defining custom setter logic for numeric index access\n */\nexport const setAt = Symbol('setAt')\n\ninterface IndexingAt<Items = any> {\n\t[getAt](index: number): Items\n}\n\ninterface Accessor<T, Items> {\n\tget(this: T, index: number): Items\n\tset?(this: T, index: number, value: Items): void\n\tgetLength?(this: T): number\n\tsetLength?(this: T, value: number): void\n}\n\nabstract class AbstractGetAt<Items = any> {\n\tabstract [getAt](index: number): Items\n}\n\n/**\n * Creates an indexable class with a base class and accessor object\n * @param base - The base class to extend\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase: Base,\n\taccessor: Accessor<InstanceType<Base>, Items>\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: Items }\n\n/**\n * Creates an indexable class with only an accessor object (no base class)\n * @param accessor - Object containing get/set methods for numeric index access\n * @returns A class that supports numeric index access\n */\nexport function Indexable<Items>(accessor: Accessor<any, Items>): new () => { [x: number]: Items }\n\n/**\n * Creates an indexable class with a base class that has [getAt] method\n * @param base - The base class that implements [getAt] method\n * @returns A class that supports numeric index access using the base class's [getAt] method\n */\nexport function Indexable<Base extends new (...args: any[]) => IndexingAt>(\n\tbase: Base\n): new (\n\t...args: ConstructorParameters<Base>\n) => InstanceType<Base> & { [x: number]: AtReturnType<InstanceType<Base>> }\n\n/**\n * Creates an abstract indexable base class\n * @returns An abstract class that supports numeric index access\n */\nexport function Indexable<Items>(): abstract new (\n\t...args: any[]\n) => AbstractGetAt & { [x: number]: Items }\n\nexport function Indexable<Items, Base extends abstract new (...args: any[]) => any>(\n\tbase?: Base | Accessor<Base, Items>,\n\taccessor?: Accessor<Base, Items>\n) {\n\tif (base && typeof base !== 'function') {\n\t\taccessor = base as Accessor<Base, Items>\n\t\tbase = undefined\n\t}\n\tif (!base) {\n\t\t//@ts-expect-error\n\t\tbase = class {} as Base\n\t}\n\tif (!accessor) {\n\t\taccessor = {\n\t\t\tget(this: any, index: number) {\n\t\t\t\tif (typeof this[getAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class must have an [getAt] method')\n\t\t\t\t}\n\t\t\t\treturn this[getAt](index)\n\t\t\t},\n\t\t\tset(this: any, index: number, value: Items) {\n\t\t\t\tif (typeof this[setAt] !== 'function') {\n\t\t\t\t\tthrow new Error('Indexable class has read-only numeric index access')\n\t\t\t\t}\n\t\t\t\tthis[setAt](index, value)\n\t\t\t},\n\t\t}\n\t}\n\n\tabstract class Indexable extends (base as Base) {\n\t\t[x: number]: Items\n\t}\n\n\tObject.setPrototypeOf(\n\t\tIndexable.prototype,\n\t\tnew Proxy((base as Base).prototype, {\n\t\t\t//@ts-expect-error\n\t\t\t[Symbol.toStringTag]: 'MutTs Indexable',\n\t\t\tget(target, prop, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\t\t\t\treturn getter ? getter.call(receiver) : target[prop]\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return accessor.getLength.call(receiver)\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn accessor.get!.call(receiver, numProp) as Items\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t\tset(target, prop, value, receiver) {\n\t\t\t\tif (prop in target) {\n\t\t\t\t\tconst setter = Object.getOwnPropertyDescriptor(target, prop)?.set\n\t\t\t\t\tif (setter) setter.call(receiver, value)\n\t\t\t\t\telse target[prop] = value\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.setLength) {\n\t\t\t\t\t\taccessor.setLength.call(receiver, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\tif (!accessor.set) throw new Error('Indexable class has read-only numeric index access')\n\t\t\t\t\t\taccessor.set!.call(receiver, numProp, value)\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject.defineProperty(receiver, prop, {\n\t\t\t\t\tvalue,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tenumerable: true,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t\thas(target, prop) {\n\t\t\t\tif (prop in target) return true\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) return true\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) return true\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t},\n\t\t\townKeys(target) {\n\t\t\t\tconst keys = Reflect.ownKeys(target)\n\t\t\t\tif (accessor.getLength) {\n\t\t\t\t\tkeys.push('length')\n\t\t\t\t\tconst len = accessor.getLength.call(this as any)\n\t\t\t\t\tfor (let i = 0; i < len; i++) keys.push(String(i))\n\t\t\t\t}\n\t\t\t\treturn keys\n\t\t\t},\n\t\t\tgetOwnPropertyDescriptor(target, prop) {\n\t\t\t\tif (prop in target) return Object.getOwnPropertyDescriptor(target, prop)\n\t\t\t\tif (typeof prop === 'string') {\n\t\t\t\t\tif (prop === 'length' && accessor.getLength) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tenumerable: false,\n\t\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t\t\tget: () => accessor.getLength!.call(this as any),\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst numProp = Number(prop)\n\t\t\t\t\tif (!Number.isNaN(numProp)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t\t\tget: () => accessor.get!.call(this as any, numProp),\n\t\t\t\t\t\t\tset: accessor.set\n\t\t\t\t\t\t\t\t? (v: any) => accessor.set!.call(this as any, numProp, v)\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined\n\t\t\t},\n\t\t})\n\t)\n\treturn Indexable\n}\n\ntype AtReturnType<T> = T extends { [getAt](index: number): infer R } ? R : never\n\n/**\n * Symbol for accessing the forwarded array in ArrayReadForward\n */\nexport const forwardArray = Symbol('forwardArray')\n\n/**\n * A read-only array forwarder that implements all reading/iterating methods of Array\n * but does not implement modification methods.\n *\n * The constructor takes a callback that returns an array, and all methods forward\n * their behavior to the result of that callback.\n */\nexport class ArrayReadForward<T> {\n\tprotected get [forwardArray](): readonly T[] {\n\t\tthrow new Error('ArrayReadForward is not implemented')\n\t}\n\n\t/**\n\t * Get the length of the array\n\t */\n\tget length(): number {\n\t\treturn this[forwardArray].length\n\t}\n\n\t/**\n\t * Get an element at a specific index\n\t */\n\t[index: number]: T | undefined\n\n\t/**\n\t * Iterator protocol support\n\t */\n\t[Symbol.iterator](): Iterator<T> {\n\t\treturn this[forwardArray][Symbol.iterator]()\n\t}\n\n\t// Reading/Iterating methods\n\n\t/**\n\t * Creates a new array with the results of calling a provided function on every element\n\t */\n\tmap<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: any): U[] {\n\t\treturn this[forwardArray].map(callbackfn, thisArg)\n\t}\n\n\t/**\n\t * Creates a new array with all elements that pass the test implemented by the provided function\n\t */\n\tfilter<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S[]\n\tfilter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[]\n\tfilter(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: any): T[] {\n\t\treturn this[forwardArray].filter(predicate, thisArg)\n\t}\n\n\t/**\n\t * Executes a reducer function on each element of the array, resulting in a single output value\n\t */\n\treduce(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T\n\t): T\n\treduce(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T,\n\t\tinitialValue: T\n\t): T\n\treduce<U>(\n\t\tcallbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U,\n\t\tinitialValue: U\n\t): U\n\treduce(\n\t\tcallbackfn: (\n\t\t\tpreviousValue: any,\n\t\t\tcurrentValue: T,\n\t\t\tcurrentIndex: number,\n\t\t\tarray: readonly T[]\n\t\t) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\treturn initialValue !== undefined\n\t\t\t? this[forwardArray].reduce(callbackfn, initialValue)\n\t\t\t: this[forwardArray].reduce(callbackfn)\n\t}\n\n\t/**\n\t * Executes a reducer function on each element of the array (right-to-left), resulting in a single output value\n\t */\n\treduceRight(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T\n\t): T\n\treduceRight(\n\t\tcallbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T,\n\t\tinitialValue: T\n\t): T\n\treduceRight<U>(\n\t\tcallbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U,\n\t\tinitialValue: U\n\t): U\n\treduceRight(\n\t\tcallbackfn: (\n\t\t\tpreviousValue: any,\n\t\t\tcurrentValue: T,\n\t\t\tcurrentIndex: number,\n\t\t\tarray: readonly T[]\n\t\t) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\treturn initialValue !== undefined\n\t\t\t? this[forwardArray].reduceRight(callbackfn, initialValue)\n\t\t\t: this[forwardArray].reduceRight(callbackfn)\n\t}\n\n\t/**\n\t * Executes a provided function once for each array element\n\t */\n\tforEach(callbackfn: (value: T, index: number, array: readonly T[]) => void, thisArg?: any): void {\n\t\tthis[forwardArray].forEach(callbackfn, thisArg)\n\t}\n\n\t/**\n\t * Returns the value of the first element in the array that satisfies the provided testing function\n\t */\n\tfind<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S | undefined\n\tfind(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined\n\tfind(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined {\n\t\treturn this[forwardArray].find(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the index of the first element in the array that satisfies the provided testing function\n\t */\n\tfindIndex(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): number {\n\t\treturn this[forwardArray].findIndex(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the value of the last element in the array that satisfies the provided testing function\n\t */\n\tfindLast<S extends T>(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => value is S,\n\t\tthisArg?: any\n\t): S | undefined\n\tfindLast(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined\n\tfindLast(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): T | undefined {\n\t\treturn this[forwardArray].findLast(predicate, thisArg)\n\t}\n\n\t/**\n\t * Returns the index of the last element in the array that satisfies the provided testing function\n\t */\n\tfindLastIndex(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): number {\n\t\treturn this[forwardArray].findLastIndex(predicate, thisArg)\n\t}\n\n\t/**\n\t * Determines whether an array includes a certain value among its entries\n\t */\n\tincludes(searchElement: T, fromIndex?: number): boolean {\n\t\treturn this[forwardArray].includes(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns the first index at which a given element can be found in the array\n\t */\n\tindexOf(searchElement: T, fromIndex?: number): number {\n\t\treturn this[forwardArray].indexOf(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns the last index at which a given element can be found in the array\n\t */\n\tlastIndexOf(searchElement: T, fromIndex?: number): number {\n\t\treturn this[forwardArray].lastIndexOf(searchElement, fromIndex)\n\t}\n\n\t/**\n\t * Returns a shallow copy of a portion of an array into a new array object\n\t */\n\tslice(start?: number, end?: number): T[] {\n\t\treturn this[forwardArray].slice(start, end)\n\t}\n\n\t/**\n\t * Returns a new array comprised of this array joined with other array(s) and/or value(s)\n\t */\n\tconcat(...items: ConcatArray<T>[]): T[]\n\tconcat(...items: (T | ConcatArray<T>)[]): T[]\n\tconcat(...items: (T | ConcatArray<T>)[]): T[] {\n\t\treturn this[forwardArray].concat(...items)\n\t}\n\n\t/**\n\t * Tests whether all elements in the array pass the test implemented by the provided function\n\t */\n\tevery(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): boolean {\n\t\treturn this[forwardArray].every(predicate, thisArg)\n\t}\n\n\t/**\n\t * Tests whether at least one element in the array passes the test implemented by the provided function\n\t */\n\tsome(\n\t\tpredicate: (value: T, index: number, array: readonly T[]) => unknown,\n\t\tthisArg?: any\n\t): boolean {\n\t\treturn this[forwardArray].some(predicate, thisArg)\n\t}\n\n\t/**\n\t * Joins all elements of an array into a string\n\t */\n\tjoin(separator?: string): string {\n\t\treturn this[forwardArray].join(separator)\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the keys for each index in the array\n\t */\n\tkeys(): IterableIterator<number> {\n\t\treturn this[forwardArray].keys()\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the values for each index in the array\n\t */\n\tvalues(): IterableIterator<T> {\n\t\treturn this[forwardArray].values()\n\t}\n\n\t/**\n\t * Returns a new array iterator that contains the key/value pairs for each index in the array\n\t */\n\tentries(): IterableIterator<[number, T]> {\n\t\treturn this[forwardArray].entries()\n\t}\n\n\t/**\n\t * Returns a string representation of the array\n\t */\n\ttoString(): string {\n\t\treturn this[forwardArray].toString()\n\t}\n\n\t/**\n\t * Returns a localized string representing the array\n\t */\n\ttoLocaleString(\n\t\tlocales?: string | string[],\n\t\toptions?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions\n\t): string {\n\t\treturn this[forwardArray].toLocaleString(locales as string | string[], options)\n\t}\n\n\t/**\n\t * Returns the element at the specified index, or undefined if the index is out of bounds\n\t */\n\tat(index: number): T | undefined {\n\t\treturn this[forwardArray].at(index)\n\t}\n\n\t/**\n\t * Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth\n\t */\n\tflat(depth?: number): T[] {\n\t\treturn this[forwardArray].flat(depth) as T[]\n\t}\n\n\t/**\n\t * Returns a new array formed by applying a given callback function to each element of the array,\n\t * and then flattening the result by one level\n\t */\n\tflatMap<U, This = undefined>(\n\t\tcallback: (this: This, value: T, index: number, array: readonly T[]) => U | ReadonlyArray<U>,\n\t\tthisArg?: This\n\t): U[] {\n\t\treturn this[forwardArray].flatMap(callback as any, thisArg)\n\t}\n\n\t/**\n\t * Returns a new array with elements in reversed order (ES2023)\n\t */\n\ttoReversed(): T[] {\n\t\treturn this[forwardArray].toReversed?.() ?? [...this[forwardArray]].reverse()\n\t}\n\n\t/**\n\t * Returns a new array with elements sorted (ES2023)\n\t */\n\ttoSorted(compareFn?: ((a: T, b: T) => number) | undefined): T[] {\n\t\treturn this[forwardArray].toSorted?.(compareFn) ?? [...this[forwardArray]].sort(compareFn)\n\t}\n\n\t/**\n\t * Returns a new array with some elements removed and/or replaced at a given index (ES2023)\n\t */\n\ttoSpliced(start: number, deleteCount?: number, ...items: T[]): T[] {\n\t\tif (deleteCount === undefined) return this[forwardArray].toSpliced(start)\n\t\treturn this[forwardArray].toSpliced(start, deleteCount, ...items)\n\t}\n\n\t/**\n\t * Returns a new array with the element at the given index replaced with the given value (ES2023)\n\t */\n\twith(index: number, value: T): T[] {\n\t\treturn this[forwardArray].with(index, value)\n\t}\n\tget [Symbol.unscopables]() {\n\t\treturn this[forwardArray][Symbol.unscopables]\n\t}\n}\n","/// <reference lib=\"esnext.collection\" />\n\n/**\n * Uses weak references but still may iterate through them\n * Note: The behavior is highly dependant on the garbage collector - some entries are perhaps deemed to be collected: don't resuscitate them\n */\nexport class IterableWeakMap<K extends WeakKey, V> implements Map<K, V> {\n\tprivate uuids = new WeakMap<K, string>()\n\tprivate refs: Record<string, [WeakRef<K>, any]> = {}\n\tprivate readonly registry: FinalizationRegistry<string>\n\n\tconstructor(entries?: Iterable<[K, V]>) {\n\t\t// Create a FinalizationRegistry to clean up refs when keys are garbage collected\n\t\tthis.registry = new FinalizationRegistry((uuid: string) => {\n\t\t\tdelete this.refs[uuid]\n\t\t})\n\t\tif (entries) for (const [k, v] of entries) this.set(k, v)\n\t}\n\tprivate createIterator<I>(cb: (key: K, value: V) => I): MapIterator<I> {\n\t\tconst { refs } = this\n\t\treturn (function* () {\n\t\t\tfor (const uuid of Object.keys(refs)) {\n\t\t\t\tconst [keyRef, value] = refs[uuid]\n\t\t\t\tconst key = keyRef.deref()\n\t\t\t\tif (key) yield cb(key, value)\n\t\t\t\telse delete refs[uuid]\n\t\t\t}\n\t\t\treturn undefined\n\t\t})()\n\t}\n\tclear(): void {\n\t\t// Unregister all keys from the FinalizationRegistry\n\t\tfor (const uuid of Object.keys(this.refs)) {\n\t\t\tconst key = this.refs[uuid][0].deref()\n\t\t\tif (key) this.registry.unregister(key)\n\t\t}\n\t\tthis.uuids = new WeakMap<K, string>()\n\t\tthis.refs = {}\n\t}\n\tdelete(key: K): boolean {\n\t\tconst uuid = this.uuids.get(key)\n\t\tif (!uuid) return false\n\t\tdelete this.refs[uuid]\n\t\tthis.uuids.delete(key)\n\t\tthis.registry.unregister(key)\n\t\treturn true\n\t}\n\tforEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void {\n\t\tfor (const [k, v] of this) callbackfn.call(thisArg ?? this, v, k, thisArg ?? this)\n\t}\n\tget(key: K): V | undefined {\n\t\tconst uuid = this.uuids.get(key)\n\t\tif (!uuid) return undefined\n\t\treturn this.refs[uuid][1]\n\t}\n\thas(key: K): boolean {\n\t\treturn this.uuids.has(key)\n\t}\n\tset(key: K, value: V): this {\n\t\tlet uuid = this.uuids.get(key)\n\t\tif (uuid) {\n\t\t\tthis.refs[uuid][1] = value\n\t\t} else {\n\t\t\tuuid = crypto.randomUUID()\n\t\t\tthis.uuids.set(key, uuid)\n\t\t\tthis.refs[uuid] = [new WeakRef(key), value]\n\t\t\t// Register key for cleanup when garbage collected\n\t\t\tthis.registry.register(key, uuid, key)\n\t\t}\n\t\treturn this\n\t}\n\tget size(): number {\n\t\treturn [...this].length\n\t}\n\tentries(): MapIterator<[K, V]> {\n\t\treturn this.createIterator((key, value) => [key, value] as [K, V])\n\t}\n\tkeys(): MapIterator<K> {\n\t\treturn this.createIterator((key, _value) => key)\n\t}\n\tvalues(): MapIterator<V> {\n\t\treturn this.createIterator((_key, value) => value)\n\t}\n\t[Symbol.iterator](): MapIterator<[K, V]> {\n\t\treturn this.entries()\n\t}\n\treadonly [Symbol.toStringTag]: string = 'IterableWeakMap'\n}\n\n/**\n * Uses weak references but still may iterate through them\n * Note: The behavior is highly dependant on the garbage collector - some entries are perhaps deemed to be collected: don't resuscitate them\n */\nexport class IterableWeakSet<K extends WeakKey> implements Set<K> {\n\tprivate uuids = new WeakMap<K, string>()\n\tprivate refs: Record<string, WeakRef<K>> = {}\n\tprivate readonly registry: FinalizationRegistry<string>\n\n\tconstructor(entries?: Iterable<K>) {\n\t\t// Create a FinalizationRegistry to clean up refs when values are garbage collected\n\t\tthis.registry = new FinalizationRegistry((uuid: string) => {\n\t\t\tdelete this.refs[uuid]\n\t\t})\n\t\tif (entries) for (const k of entries) this.add(k)\n\t}\n\tprivate createIterator<I>(cb: (key: K) => I): MapIterator<I> {\n\t\tconst { refs } = this\n\t\treturn (function* () {\n\t\t\tfor (const uuid of Object.keys(refs)) {\n\t\t\t\tconst key = refs[uuid].deref()\n\t\t\t\tif (key) yield cb(key)\n\t\t\t\telse delete refs[uuid]\n\t\t\t}\n\t\t\treturn undefined\n\t\t})()\n\t}\n\n\tclear(): void {\n\t\t// Unregister all values from the FinalizationRegistry\n\t\tfor (const uuid of Object.keys(this.refs)) {\n\t\t\tconst value = this.refs[uuid].deref()\n\t\t\tif (value) this.registry.unregister(value)\n\t\t}\n\t\tthis.uuids = new WeakMap<K, string>()\n\t\tthis.refs = {}\n\t}\n\n\tadd(value: K): this {\n\t\tlet uuid = this.uuids.get(value)\n\t\tif (!uuid) {\n\t\t\tuuid = crypto.randomUUID()\n\t\t\tthis.uuids.set(value, uuid)\n\t\t\tthis.refs[uuid] = new WeakRef(value)\n\t\t\t// Register value for cleanup when garbage collected\n\t\t\tthis.registry.register(value, uuid, value)\n\t\t}\n\t\treturn this\n\t}\n\tdelete(value: K): boolean {\n\t\tconst uuid = this.uuids.get(value)\n\t\tif (!uuid) return false\n\t\tdelete this.refs[uuid]\n\t\tthis.uuids.delete(value)\n\t\tthis.registry.unregister(value)\n\t\treturn true\n\t}\n\n\tforEach(callbackfn: (value: K, value2: K, set: Set<K>) => void, thisArg?: any): void {\n\t\tfor (const value of this) callbackfn.call(thisArg ?? this, value, value, thisArg ?? this)\n\t}\n\n\thas(value: K): boolean {\n\t\treturn this.uuids.has(value)\n\t}\n\tget size(): number {\n\t\treturn [...this].length\n\t}\n\tentries(): SetIterator<[K, K]> {\n\t\treturn this.createIterator((key) => [key, key] as [K, K])\n\t}\n\tkeys(): SetIterator<K> {\n\t\treturn this.createIterator((key) => key)\n\t}\n\tvalues(): SetIterator<K> {\n\t\treturn this.createIterator((key) => key)\n\t}\n\t[Symbol.iterator](): SetIterator<K> {\n\t\treturn this.keys()\n\t}\n\treadonly [Symbol.toStringTag]: string = 'IterableWeakSet'\n\n\tunion<U>(other: ReadonlySetLike<U>): Set<K | U> {\n\t\tconst others = {\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn other.keys()\n\t\t\t},\n\t\t}\n\t\tconst that = this\n\t\treturn new Set(\n\t\t\t(function* () {\n\t\t\t\tyield* that\n\t\t\t\tfor (const value of others) if (!that.has(<K>(<unknown>value))) yield value\n\t\t\t})()\n\t\t)\n\t}\n\tintersection<U /**/>(other: ReadonlySetLike<U>): Set<K & U> {\n\t\tconst that = this\n\t\treturn new Set(\n\t\t\t(function* () {\n\t\t\t\tfor (const value of that) if (other.has(<U>(<unknown>value))) yield <K & U>value\n\t\t\t})()\n\t\t)\n\t}\n\tdifference<U>(other: ReadonlySetLike<U>): Set<K> {\n\t\tconst that = this\n\t\treturn new Set(\n\t\t\t(function* () {\n\t\t\t\tfor (const value of that) if (!other.has(<U>(<unknown>value))) yield <K>value\n\t\t\t})()\n\t\t)\n\t}\n\tsymmetricDifference<U>(other: ReadonlySetLike<U>): Set<K | U> {\n\t\tconst others = {\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn other.keys()\n\t\t\t},\n\t\t}\n\t\tconst that = this\n\t\treturn new Set(\n\t\t\t(function* () {\n\t\t\t\tfor (const value of that) if (!other.has(<U>(<unknown>value))) yield <K | U>value\n\t\t\t\tfor (const value of others) if (!that.has(<K>(<unknown>value))) yield <K | U>value\n\t\t\t})()\n\t\t)\n\t}\n\tisSubsetOf(other: ReadonlySetLike<unknown>): boolean {\n\t\tfor (const value of this) if (!other.has(value)) return false\n\t\treturn true\n\t}\n\tisSupersetOf(other: ReadonlySetLike<unknown>): boolean {\n\t\tconst others = {\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn other.keys()\n\t\t\t},\n\t\t}\n\t\tfor (const value of others) if (!this.has(<K>value)) return false\n\t\treturn true\n\t}\n\tisDisjointFrom(other: ReadonlySetLike<unknown>): boolean {\n\t\tfor (const value of this) if (other.has(value)) return false\n\t\treturn true\n\t}\n}\n","import { FoolProof, isConstructor } from './utils'\n\n/**\n * A mixin function that takes a base class and returns a new class with mixed-in functionality\n * @template Mixed - The functionality to be mixed in\n */\nexport type MixinFunction<Mixed> = <Base>(\n\tbase: new (...args: any[]) => Base\n) => new (\n\t...args: any[]\n) => Base & Mixed\n\n/**\n * A mixin class that can be used both as a base class and as a mixin function\n * @template Mixed - The functionality to be mixed in\n */\nexport type MixinClass<Mixed> = new (...args: any[]) => Mixed\n\n/**\n * Creates a mixin that can be used both as a class (extends) and as a function (mixin)\n *\n * This function supports:\n * - Using mixins as base classes: `class MyClass extends MyMixin`\n * - Using mixins as functions: `class MyClass extends MyMixin(SomeBase)`\n * - Composing mixins: `const Composed = MixinA(MixinB)`\n * - Type-safe property inference for all patterns\n *\n * @param mixinFunction - The function that creates the mixin\n * @param unwrapFunction - Optional function to unwrap reactive objects for method calls\n * @returns A mixin that can be used both as a class and as a function\n */\nexport function mixin<MixinFn extends (base: any) => new (...args: any[]) => any>(\n\tmixinFunction: MixinFn,\n\tunwrapFunction?: (obj: any) => any\n): (new (\n\t...args: any[]\n) => InstanceType<ReturnType<MixinFn>>) &\n\t(<Base>(\n\t\tbase: abstract new (...args: any[]) => Base\n\t) => new (\n\t\t...args: any[]\n\t) => InstanceType<ReturnType<MixinFn>> & Base) {\n\t/**\n\t * Cache for mixin results to ensure the same base class always returns the same mixed class\n\t */\n\tconst mixinCache = new WeakMap<new (...args: any[]) => any, new (...args: any[]) => any>()\n\n\t// Apply the mixin to Object as the base class\n\tconst MixedBase = mixinFunction(Object)\n\tmixinCache.set(Object, MixedBase)\n\n\t// Create the proxy that handles both constructor and function calls\n\treturn new Proxy(MixedBase, {\n\t\t// Handle `MixinClass(SomeBase)` - use as mixin function\n\t\tapply(_target, _thisArg, args) {\n\t\t\tif (args.length === 0) {\n\t\t\t\tthrow new Error('Mixin requires a base class')\n\t\t\t}\n\n\t\t\tconst baseClass = args[0]\n\t\t\tif (typeof baseClass !== 'function') {\n\t\t\t\tthrow new Error('Mixin requires a constructor function')\n\t\t\t}\n\n\t\t\t// Check if it's a valid constructor or a mixin\n\t\t\tif (\n\t\t\t\t!isConstructor(baseClass) &&\n\t\t\t\t!(baseClass && typeof baseClass === 'function' && baseClass.prototype)\n\t\t\t) {\n\t\t\t\tthrow new Error('Mixin requires a valid constructor')\n\t\t\t}\n\n\t\t\t// Check cache first\n\t\t\tconst cached = mixinCache.get(baseClass)\n\t\t\tif (cached) {\n\t\t\t\treturn cached\n\t\t\t}\n\n\t\t\tlet usedBase = baseClass\n\t\t\tif (unwrapFunction) {\n\t\t\t\t// Create a proxied base class that handles method unwrapping\n\t\t\t\tconst ProxiedBaseClass = class extends baseClass {}\n\n\t\t\t\t// Proxy the prototype methods to handle unwrapping\n\t\t\t\tconst originalPrototype = baseClass.prototype\n\t\t\t\tconst proxiedPrototype = new Proxy(originalPrototype, {\n\t\t\t\t\tget(target, prop, receiver) {\n\t\t\t\t\t\tconst value = FoolProof.get(target, prop, receiver)\n\n\t\t\t\t\t\t// Only wrap methods that are likely to access private fields\n\t\t\t\t\t\t// Skip symbols and special properties that the reactive system needs\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\ttypeof value === 'function' &&\n\t\t\t\t\t\t\ttypeof prop === 'string' &&\n\t\t\t\t\t\t\t!['constructor', 'toString', 'valueOf'].includes(prop)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Return a wrapped version that uses unwrapped context\n\t\t\t\t\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t\t\t\t\t// Use the unwrapping function if provided, otherwise use this\n\t\t\t\t\t\t\t\tconst context = unwrapFunction(this as any)\n\t\t\t\t\t\t\t\treturn value.apply(context, args)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn value\n\t\t\t\t\t},\n\t\t\t\t})\n\n\t\t\t\t// Set the proxied prototype\n\t\t\t\tObject.setPrototypeOf(ProxiedBaseClass.prototype, proxiedPrototype)\n\t\t\t\tusedBase = ProxiedBaseClass\n\t\t\t}\n\n\t\t\t// Create the mixed class using the proxied base class\n\t\t\tconst mixedClass = mixinFunction(usedBase)\n\n\t\t\t// Cache the result\n\t\t\tmixinCache.set(baseClass, mixedClass)\n\n\t\t\treturn mixedClass\n\t\t},\n\t}) as MixinFn & (new (...args: any[]) => InstanceType<ReturnType<MixinFn>>)\n}\n","type Resolved<T> =\n\tT extends Promise<infer U>\n\t\t? Resolved<U>\n\t\t: T extends (...args: infer Args) => infer R\n\t\t\t? (...args: Args) => Resolved<R>\n\t\t\t: T extends object\n\t\t\t\t? {\n\t\t\t\t\t\t[k in keyof T]: k extends 'then' | 'catch' | 'finally' ? T[k] : Resolved<T[k]>\n\t\t\t\t\t}\n\t\t\t\t: T\ntype PromiseAnd<T> = Resolved<T> & Promise<Resolved<T>>\n/**\n * Type that transforms promises into chainable objects\n * Allows calling methods directly on promise results without awaiting them first\n */\nexport type PromiseChain<T> = T extends (...args: infer Args) => infer R\n\t? PromiseAnd<(...args: Args) => PromiseChain<Resolved<R>>>\n\t: T extends object\n\t\t? PromiseAnd<{\n\t\t\t\t[k in keyof T]: k extends 'then' | 'catch' | 'finally' ? T[k] : PromiseChain<Resolved<T[k]>>\n\t\t\t}>\n\t\t: Promise<Resolved<T>>\n\nconst forward =\n\t(name: string, target: any) =>\n\t(...args: any[]) => {\n\t\treturn target[name](...args)\n\t}\n\nconst alreadyChained = new WeakMap<any, PromiseChain<any>>()\nconst originals = new WeakMap<Promise<any>, any>()\n\nfunction cache(target: any, rv: PromiseChain<any>) {\n\toriginals.set(rv, target)\n\talreadyChained.set(target, rv)\n}\n\ntype ChainedFunction<T> = ((...args: any[]) => PromiseChain<T>) & {\n\tthen: Promise<T>['then']\n\tcatch: Promise<T>['catch']\n\tfinally: Promise<T>['finally']\n}\n\nconst promiseProxyHandler: ProxyHandler<ChainedFunction<any>> = {\n\t//@ts-expect-error\n\t[Symbol.toStringTag]: 'MutTs PromiseChain function',\n\tget(target, prop) {\n\t\tif (prop === Symbol.toStringTag) return 'PromiseProxy'\n\t\tif (typeof prop === 'string' && ['then', 'catch', 'finally'].includes(prop))\n\t\t\treturn target[prop as keyof typeof target]\n\t\treturn chainPromise(target.then((r) => r[prop as keyof typeof r]))\n\t},\n}\nconst promiseForward = (target: any) => ({\n\t// biome-ignore lint/suspicious/noThenProperty: This one is the whole point\n\tthen: forward('then', target),\n\tcatch: forward('catch', target),\n\tfinally: forward('finally', target),\n})\nconst objectProxyHandler: ProxyHandler<any> = {\n\t//@ts-expect-error\n\t[Symbol.toStringTag]: 'MutTs PromiseChain object',\n\tget(target, prop, receiver) {\n\t\tconst getter = Object.getOwnPropertyDescriptor(target, prop)?.get\n\t\tconst rv = getter ? getter.call(receiver) : target[prop]\n\t\t// Allows fct.call or fct.apply to bypass the chain system\n\t\tif (typeof target === 'function') return rv\n\t\treturn chainPromise(rv)\n\t},\n\tapply(target, thisArg, args) {\n\t\treturn chainPromise(target.apply(thisArg, args))\n\t},\n}\nfunction chainObject<T extends object | Function>(given: T): PromiseChain<T> {\n\tconst rv = new Proxy(given, objectProxyHandler) as PromiseChain<T>\n\tcache(given, rv)\n\treturn rv\n}\n\nfunction chainable(x: any): x is object | Function {\n\treturn x && ['function', 'object'].includes(typeof x)\n}\n/**\n * Transforms a promise or value into a chainable object\n * Allows calling methods directly on promise results without awaiting them first\n * @param given - The promise or value to make chainable\n * @returns A chainable version of the input\n */\nexport function chainPromise<T>(given: Promise<T> | T): PromiseChain<T> {\n\tif (!chainable(given)) return given as PromiseChain<T>\n\tif (alreadyChained.has(given)) return alreadyChained.get(given) as PromiseChain<T>\n\tif (!(given instanceof Promise)) return chainObject(given)\n\t// @ts-expect-error It's ok as we check if it's an object above\n\tgiven = given.then((r) => (chainable(r) ? chainObject(r) : r))\n\tconst target = Object.assign(function (this: any, ...args: any[]) {\n\t\treturn chainPromise(\n\t\t\tgiven.then((r) => {\n\t\t\t\treturn this?.then\n\t\t\t\t\t? this.then((t: any) => (r as any).apply(t, args))\n\t\t\t\t\t: (r as any).apply(this, args)\n\t\t\t})\n\t\t)\n\t}, promiseForward(given)) as ChainedFunction<T>\n\tconst chained = new Proxy(\n\t\ttarget,\n\t\tpromiseProxyHandler as ProxyHandler<ChainedFunction<T>>\n\t) as PromiseChain<T>\n\tcache(given, chained as PromiseChain<any>)\n\treturn chained\n}\n","// biome-ignore-all lint/suspicious/noConfusingVoidType: Type 'void' is not assignable to type 'ScopedCallback | undefined'.\n// Argument of type '() => void' is not assignable to parameter of type '(dep: DependencyFunction) => ScopedCallback | undefined'.\n\nimport { FunctionWrapper } from \"../zone\"\n\n/**\n * Dependency access passed to user callbacks within effects/watch\n * Provides functions to track dependencies and information about the effect execution\n */\nexport interface DependencyAccess {\n\t// TODO: remove tracked (async is managed)\n\t// TODO: remove ascend (make a global like `untracked` who withEffect(parentEffect, () => {}))\n\t/**\n\t * Tracks dependencies in the current effect context\n\t * Use this for normal dependency tracking within the effect\n\t * @example\n\t * ```typescript\n\t * effect(({ tracked }) => {\n\t * // In async context, use tracked to restore dependency tracking\n\t * await someAsyncOperation()\n\t * const value = tracked(() => state.count) // Tracks state.count in this effect\n\t * })\n\t * ```\n\t */\n\ttracked: FunctionWrapper\n\t/**\n\t * Tracks dependencies in the parent effect context\n\t * Use this when child effects should track dependencies in the parent,\n\t * allowing parent cleanup to manage child effects while dependencies trigger the parent\n\t * @example\n\t * ```typescript\n\t * effect(({ ascend }) => {\n\t * const length = inputs.length\n\t * if (length > 0) {\n\t * ascend(() => {\n\t * // Dependencies here are tracked in the parent effect\n\t * inputs.forEach(item => console.log(item))\n\t * })\n\t * }\n\t * })\n\t * ```\n\t */\n\tascend: FunctionWrapper\n\t/**\n\t * Indicates whether the effect is running as a reaction (i.e. not the first call)\n\t * - `false`: First execution when the effect is created\n\t * - `true`: Subsequent executions triggered by dependency changes\n\t * @example\n\t * ```typescript\n\t * effect(({ reaction }) => {\n\t * if (!reaction) {\n\t * console.log('Effect initialized')\n\t * // Setup code that should only run once\n\t * } else {\n\t * console.log('Effect re-ran due to dependency change')\n\t * // Code that runs on every update\n\t * }\n\t * })\n\t * ```\n\t */\n\treaction: boolean\n}\n// Zone-based async context preservation is implemented in zone.ts\n// It automatically preserves effect context across Promise boundaries (.then, .catch, .finally)\n\n/**\n * Type for effect cleanup functions\n */\nexport type ScopedCallback = () => void\n\n/**\n * Async execution mode for effects\n * - `cancel`: Cancel previous async execution when dependencies change (default)\n * - `queue`: Queue next execution to run after current completes\n * - `ignore`: Ignore new executions while async work is running\n */\nexport type AsyncExecutionMode = 'cancel' | 'queue' | 'ignore'\n\n/**\n * Options for effect creation\n */\nexport interface EffectOptions {\n\t/**\n\t * How to handle async effect executions when dependencies change\n\t * @default 'cancel'\n\t */\n\tasyncMode?: AsyncExecutionMode\n\t/**\n\t * If true, this effect is \"opaque\" to deep optimizations: it sees the object reference itself\n\t * and must be notified when it changes, regardless of deep content similarity.\n\t * Use this for effects that depend on object identity (like memoize).\n\t */\n\topaque?: boolean\n}\n\n/**\n * Type for property evolution events\n */\nexport type PropEvolution = {\n\ttype: 'set' | 'del' | 'add' | 'invalidate'\n\tprop: any\n}\n\n/**\n * Type for collection operation evolution events\n */\nexport type BunchEvolution = {\n\ttype: 'bunch'\n\tmethod: string\n}\nexport type Evolution = PropEvolution | BunchEvolution\n\ntype State =\n\t| {\n\t\t\tevolution: Evolution\n\t\t\tnext: State\n\t }\n\t| {}\n\n// Track native reactivity\nconst nativeReactive = Symbol('native-reactive')\n\n/**\n * Symbol to mark individual objects as non-reactive\n */\nexport const nonReactiveMark = Symbol('non-reactive')\n/**\n * Symbol to mark class properties as non-reactive\n */\nexport const unreactiveProperties = Symbol('unreactive-properties')\n\n/**\n * Symbol representing all properties in reactive tracking\n */\nexport const allProps = Symbol('all-props')\n\n/**\n * Symbol for accessing projection information on reactive objects\n */\nexport const projectionInfo = Symbol('projection-info')\n\n/**\n * Symbol to check if an effect is stopped\n */\nexport const stopped = Symbol('stopped')\n\n/**\n * Symbol to access effect cleanup function\n */\nexport const cleanup = Symbol('cleanup')\n\n/**\n * Context for a running projection item effect\n */\nexport interface ProjectionContext {\n\tsource: any\n\tkey?: any\n\ttarget: any\n\tdepth: number\n\tparent?: ProjectionContext\n}\n\n// Symbol to mark functions with their root function\nconst rootFunction = Symbol('root-function')\n\n/**\n * Structured error codes for machine-readable diagnosis\n */\nexport enum ReactiveErrorCode {\n\tCycleDetected = 'CYCLE_DETECTED',\n\tMaxDepthExceeded = 'MAX_DEPTH_EXCEEDED',\n\tMaxReactionExceeded = 'MAX_REACTION_EXCEEDED',\n\tWriteInComputed = 'WRITE_IN_COMPUTED',\n\tTrackingError = 'TRACKING_ERROR',\n\tBrokenEffects = 'BROKEN_EFFECTS',\n}\n\nexport type CycleDebugInfo = {\n\tcode: ReactiveErrorCode.CycleDetected\n\tcycle: string[]\n\tdetails?: string\n}\n\nexport type MaxDepthDebugInfo = {\n\tcode: ReactiveErrorCode.MaxDepthExceeded\n\tdepth: number\n\tchain: string[]\n}\n\nexport type MaxReactionDebugInfo = {\n\tcode: ReactiveErrorCode.MaxReactionExceeded\n\tcount: number\n\teffect: string\n}\n\nexport type BrokenEffectsDebugInfo = {\n\tcode: ReactiveErrorCode.BrokenEffects\n\tcause: any\n}\n\nexport type GenericDebugInfo = {\n\tcode: ReactiveErrorCode\n\tcausalChain?: string[]\n\tcreationStack?: string\n\t[key: string]: any\n}\n\nexport type ReactiveDebugInfo =\n\t| CycleDebugInfo\n\t| MaxDepthDebugInfo\n\t| MaxReactionDebugInfo\n\t| BrokenEffectsDebugInfo\n\t| GenericDebugInfo\n\n/**\n * Error class for reactive system errors\n */\nexport class ReactiveError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic debugInfo?: ReactiveDebugInfo\n\t) {\n\t\tsuper(message)\n\t\tthis.name = 'ReactiveError'\n\t}\n\n\tget code(): ReactiveErrorCode | undefined {\n\t\treturn this.debugInfo?.code\n\t}\n\n\tget cause(): any {\n\t\treturn (this.debugInfo as any)?.cause\n\t}\n}\n\n// biome-ignore-start lint/correctness/noUnusedFunctionParameters: Interface declaration with empty defaults\n/**\n * Global options for the reactive system\n */\nexport const options = {\n\t/**\n\t * Debug purpose: called when an effect is entered\n\t * @param effect - The effect that is entered\n\t */\n\tenter: (_effect: Function) => {},\n\t/**\n\t * Debug purpose: called when an effect is left\n\t * @param effect - The effect that is left\n\t */\n\tleave: (_effect: Function) => {},\n\t/**\n\t * Debug purpose: called when an effect is chained\n\t * @param target - The effect that is being triggered\n\t * @param caller - The effect that is calling the target\n\t */\n\tchain: (_targets: Function[], _caller?: Function) => {},\n\t/**\n\t * Debug purpose: called when an effect chain is started\n\t * @param target - The effect that is being triggered\n\t */\n\tbeginChain: (_targets: Function[]) => {},\n\t/**\n\t * Debug purpose: called when an effect chain is ended\n\t */\n\tendChain: () => {},\n\tgarbageCollected: (_fn: Function) => {},\n\t/**\n\t * Debug purpose: called when an object is touched\n\t * @param obj - The object that is touched\n\t * @param evolution - The type of change\n\t * @param props - The properties that changed\n\t * @param deps - The dependencies that changed\n\t */\n\ttouched: (_obj: any, _evolution: Evolution, _props?: any[], _deps?: Set<ScopedCallback>) => {},\n\t/**\n\t * Debug purpose: called when an effect is skipped because it's already running\n\t * @param effect - The effect that is already running\n\t * @param runningChain - The array of effects from the detected one to the currently running one\n\t */\n\tskipRunningEffect: (_effect: ScopedCallback) => {},\n\t/**\n\t * Debug purpose: maximum effect chain (like call stack max depth)\n\t * Used to prevent infinite loops\n\t * @default 100\n\t */\n\tmaxEffectChain: 100,\n\t/**\n\t * Maximum number of times an effect can be triggered by the same cause in a single batch\n\t * Used to detect aggressive re-computation or infinite loops\n\t * @default 10\n\t */\n\tmaxTriggerPerBatch: 10,\n\t/**\n\t * Debug purpose: maximum effect reaction (like call stack max depth)\n\t * Used to prevent infinite loops\n\t * @default 'throw'\n\t */\n\tmaxEffectReaction: 'throw' as 'throw' | 'debug' | 'warn',\n\t/**\n\t * Callback called when a memoization discrepancy is detected (debug only)\n\t * When defined, memoized functions will run a second time (untracked) to verify consistency.\n\t * If the untracked run returns a different value than the cached one, this callback is triggered.\n\t *\n\t * This is the primary tool for detecting missing reactive dependencies in computed values.\n\t *\n\t * @param cached - The value currently in the memoization cache\n\t * @param fresh - The value obtained by re-running the function untracked\n\t * @param fn - The memoized function itself\n\t * @param args - Arguments passed to the function\n\t *\n\t * @example\n\t * ```typescript\n\t * reactiveOptions.onMemoizationDiscrepancy = (cached, fresh, fn, args) => {\n\t * throw new Error(`Memoization discrepancy in ${fn.name}!`);\n\t * };\n\t * ```\n\t */\n\tonMemoizationDiscrepancy: undefined as\n\t\t| ((\n\t\t\t\tcached: any,\n\t\t\t\tfresh: any,\n\t\t\t\tfn: Function,\n\t\t\t\targs: any[],\n\t\t\t\tcause: 'calculation' | 'comparison'\n\t\t ) => void)\n\t\t| undefined,\n\t/**\n\t * How to handle cycles detected in effect batches.\n\t *\n\t * - `'none'` (Default): High-performance mode. Disables dependency graph maintenance and\n\t * Topological Sorting in favor of a simple FIFO queue. Use this for trustworthy, acyclic UI code.\n\t * Cycle detection is heuristic (uses execution counts).\n\t *\n\t * - `'throw'`: Traditional Topological Sorting. Guarantees dependency order and catches\n\t * circular dependencies mathematically before execution.\n\t *\n\t * - `'warn'`: Topological sorting, but logs a warning instead of throwing on cycles.\n\t * - `'break'`: Topological sorting, but silently breaks cycles.\n\t * - `'strict'`: Prevents cycle creation by checking the graph *during* dependency discovery.\n\t *\n\t * @default 'none'\n\t */\n\tcycleHandling: 'none' as 'none' | 'throw' | 'warn' | 'break' | 'strict',\n\t/**\n\t * Internal flag used by memoization discrepancy detector to avoid counting calls in tests\n\t * @warning Do not modify this flag manually, this flag is given by the engine\n\t */\n\tisVerificationRun: false,\n\t/**\n\t * Maximum depth for deep watching traversal\n\t * Used to prevent infinite recursion in circular references\n\t * @default 100\n\t */\n\tmaxDeepWatchDepth: 100,\n\t/**\n\t * Only react on instance members modification (not inherited properties)\n\t * For instance, do not track class methods\n\t * @default true\n\t */\n\tinstanceMembers: true,\n\t/**\n\t * Ignore accessors (getters and setters) and only track direct properties\n\t * @default true\n\t */\n\tignoreAccessors: true,\n\t/**\n\t * Enable recursive touching when objects with the same prototype are replaced\n\t * When enabled, replacing an object with another of the same prototype triggers\n\t * recursive diffing instead of notifying parent effects\n\t * @default true\n\t */\n\trecursiveTouching: true,\n\t/**\n\t * Default async execution mode for effects that return Promises\n\t * - 'cancel': Cancel previous async execution when dependencies change (default, enables async zone)\n\t * - 'queue': Queue next execution to run after current completes (enables async zone)\n\t * - 'ignore': Ignore new executions while async work is running (enables async zone)\n\t * - false: Disable async zone and async mode handling (effects run concurrently)\n\t *\n\t * **When truthy:** Enables async zone (Promise.prototype wrapping) for automatic context\n\t * preservation in Promise callbacks. Warning: This modifies Promise.prototype globally.\n\t * Only enable if no other library modifies Promise.prototype.\n\t *\n\t * **When false:** Async zone is disabled. Use `tracked()` manually in Promise callbacks.\n\t *\n\t * Can be overridden per-effect via EffectOptions\n\t * @default 'cancel'\n\t */\n\tasyncMode: 'cancel' as AsyncExecutionMode | false,\n\t// biome-ignore lint/suspicious/noConsole: This is the whole point here\n\twarn: (...args: any[]) => console.warn(...args),\n\n\t/**\n\t * Configuration for the introspection system\n\t */\n\tintrospection: {\n\t\t/**\n\t\t * Whether to keep a history of mutations for debugging\n\t\t * @default false\n\t\t */\n\t\tenableHistory: false,\n\t\t/**\n\t\t * Number of mutations to keep in history\n\t\t * @default 50\n\t\t */\n\t\thistorySize: 50,\n\t},\n\n\t/**\n\t * Configuration for zone hooks - control which async APIs are hooked\n\t * Each option controls whether the corresponding async API is wrapped to preserve effect context\n\t * Only applies when asyncMode is enabled (truthy)\n\t * @deprecated Should take all when we made sure PIXI.create, Game.create, ... are -> .root()\n\t */\n\tzones: {\n\t\t/**\n\t\t * Hook setTimeout to preserve effect context\n\t\t * @default true\n\t\t */\n\t\tsetTimeout: true,\n\t\t/**\n\t\t * Hook setInterval to preserve effect context\n\t\t * @default true\n\t\t */\n\t\tsetInterval: true,\n\t\t/**\n\t\t * Hook requestAnimationFrame (runs in untracked context when hooked)\n\t\t * @default true\n\t\t */\n\t\trequestAnimationFrame: true,\n\t\t/**\n\t\t * Hook queueMicrotask to preserve effect context\n\t\t * @default true\n\t\t */\n\t\tqueueMicrotask: true,\n\t},\n}\n// biome-ignore-end lint/correctness/noUnusedFunctionParameters: Interface declaration with empty defaults\n\nexport { type State, nativeReactive, rootFunction }\n","import { rootFunction, type ScopedCallback } from './types'\n\n// Track which effects are watching which reactive objects for cleanup\nexport const effectToReactiveObjects = new WeakMap<ScopedCallback, Set<object>>()\n\n// Track effects per reactive object and property\nexport const watchers = new WeakMap<object, Map<any, Set<ScopedCallback>>>()\n\n// runEffect -> set<stop>\nexport const effectChildren = new WeakMap<ScopedCallback, Set<ScopedCallback>>()\n\n// Track parent effect relationships for hierarchy traversal (used in deep touch filtering)\nexport const effectParent = new WeakMap<ScopedCallback, ScopedCallback | undefined>()\n\n// Track reverse mapping to ensure unicity: One Root -> One Function\nconst reverseRoots = new WeakMap<any, WeakRef<Function>>()\n\n/**\n * Marks a function with its root function for effect tracking\n * Enforces strict unicity: A root function can only identify ONE function.\n * @param fn - The function to mark\n * @param root - The root function\n * @returns The marked function\n */\nexport function markWithRoot<T extends Function>(fn: T, root: any): T {\n\t// Check for collision\n\tconst existingRef = reverseRoots.get(root)\n\tconst existing = existingRef?.deref()\n\n\tif (existing && existing !== fn) {\n\t\tconst rootName = root.name || 'anonymous'\n\t\tconst existingName = existing.name || 'anonymous'\n\t\tconst fnName = fn.name || 'anonymous'\n\t\tthrow new Error(\n\t\t\t`[reactive] Abusive Shared Root detected: Root '${rootName}' is already identifying function '${existingName}'. ` +\n\t\t\t\t`Cannot reuse it for '${fnName}'. Shared roots cause lost updates and broken identity logic.`\n\t\t)\n\t}\n\n\t// Always update the map so subsequent checks find this one\n\t// (Last writer wins for the check)\n\treverseRoots.set(root, new WeakRef(fn))\n\n\t// Mark fn with the new root\n\treturn Object.defineProperty(fn, rootFunction, {\n\t\tvalue: getRoot(root),\n\t\twritable: false,\n\t})\n}\n\n/**\n * Gets the root function of a function for effect tracking\n * @param fn - The function to get the root of\n * @returns The root function\n */\nexport function getRoot<T extends Function | undefined>(fn: T): T {\n\twhile (fn && rootFunction in fn) fn = fn[rootFunction] as T\n\treturn fn\n}","/**\n * Debug utilities for the reactivity system\n * - Captures effect metadata (names, parent relationships)\n * - Records cause → consequence edges with object/prop labels\n * - Provides graph data for tooling (DevTools panel, etc.)\n */\n\nimport { effectParent, effectToReactiveObjects, getRoot } from './registry'\nimport { allProps, type Evolution, options, type ScopedCallback } from './types'\n\nconst EXTERNAL_SOURCE = Symbol('external-source')\ntype SourceEffect = ScopedCallback | typeof EXTERNAL_SOURCE\n\nlet devtoolsEnabled = false\n\n// Registry for debugging (populated lazily when DevTools are enabled)\nconst debugEffectRegistry = new Set<ScopedCallback>()\nconst debugObjectRegistry = new Set<object>()\n\n// Human-friendly names\nconst effectNames = new WeakMap<ScopedCallback, string>()\nconst objectNames = new WeakMap<object, string>()\nlet effectCounter = 0\nlet objectCounter = 0\n\n// Cause/consequence edges aggregated by (source, target, descriptor)\ninterface TriggerRecord {\n\tlabel: string\n\tobject: object\n\tprop: any\n\tevolution: Evolution\n\tcount: number\n\tlastTriggered: number\n}\n\nconst triggerGraph = new Map<SourceEffect, Map<ScopedCallback, Map<string, TriggerRecord>>>()\n\nexport type NodeKind = 'effect' | 'external' | 'state'\nexport type EdgeKind = 'cause' | 'dependency' | 'trigger'\n\nexport interface EffectNode {\n\tid: string\n\tlabel: string\n\ttype: NodeKind\n\tdepth: number\n\tparentId?: string\n\tdebugName?: string\n}\n\nexport interface ObjectNode {\n\tid: string\n\tlabel: string\n\ttype: NodeKind\n\tdebugName?: string\n}\n\nexport interface GraphEdge {\n\tid: string\n\tsource: string\n\ttarget: string\n\ttype: EdgeKind\n\tlabel: string\n\tcount?: number\n}\n\nexport interface ReactivityGraph {\n\tnodes: Array<EffectNode | ObjectNode>\n\tedges: GraphEdge[]\n\tmeta: {\n\t\tgeneratedAt: number\n\t\tdevtoolsEnabled: boolean\n\t}\n}\n\nfunction ensureEffectName(effect: ScopedCallback): string {\n\tlet name = effectNames.get(effect)\n\tif (!name) {\n\t\tconst root = getRoot(effect)\n\t\tname = root?.name?.trim() || `effect_${++effectCounter}`\n\t\teffectNames.set(effect, name)\n\t}\n\treturn name\n}\n\nfunction ensureObjectName(obj: object): string {\n\tlet name = objectNames.get(obj)\n\tif (!name) {\n\t\tconst ctorName = (obj as any)?.constructor?.name\n\t\tconst base = ctorName && ctorName !== 'Object' ? ctorName : 'object'\n\t\tname = `${base}_${++objectCounter}`\n\t\tobjectNames.set(obj, name)\n\t}\n\treturn name\n}\n\nfunction describeProp(obj: object, prop: any): string {\n\tconst objectName = ensureObjectName(obj)\n\tif (prop === allProps) return `${objectName}.*`\n\tif (typeof prop === 'symbol') return `${objectName}.${prop.description ?? prop.toString()}`\n\treturn `${objectName}.${String(prop)}`\n}\n\nfunction addEffectToRegistry(effect: ScopedCallback) {\n\tif (!effect || debugEffectRegistry.has(effect)) return\n\tdebugEffectRegistry.add(effect)\n\tconst deps = effectToReactiveObjects.get(effect)\n\tif (deps) {\n\t\tfor (const obj of deps) {\n\t\t\tdocumentObject(obj)\n\t\t}\n\t}\n}\n\nfunction documentObject(obj: object) {\n\tif (!debugObjectRegistry.has(obj)) {\n\t\tdbRegisterObject(obj)\n\t}\n}\n\nfunction dbRegisterObject(obj: object) {\n\tdebugObjectRegistry.add(obj)\n\tensureObjectName(obj)\n}\n\nfunction ensureParentChains(effects: Set<ScopedCallback>) {\n\tconst queue = Array.from(effects)\n\tfor (let i = 0; i < queue.length; i++) {\n\t\tconst effect = queue[i]\n\t\tconst parent = effectParent.get(effect)\n\t\tif (parent && !effects.has(parent)) {\n\t\t\teffects.add(parent)\n\t\t\tqueue.push(parent)\n\t\t}\n\t}\n}\n\nfunction ensureTriggerContainers(source: SourceEffect) {\n\tlet targetMap = triggerGraph.get(source)\n\tif (!targetMap) {\n\t\ttargetMap = new Map()\n\t\ttriggerGraph.set(source, targetMap)\n\t}\n\treturn targetMap\n}\n\nfunction ensureTriggerRecord(\n\tsource: SourceEffect,\n\ttarget: ScopedCallback,\n\tlabel: string,\n\tobj: object,\n\tprop: any,\n\tevolution: Evolution\n): TriggerRecord {\n\tconst targetMap = ensureTriggerContainers(source)\n\tlet labelMap = targetMap.get(target)\n\tif (!labelMap) {\n\t\tlabelMap = new Map()\n\t\ttargetMap.set(target, labelMap)\n\t}\n\tlet record = labelMap.get(label)\n\tif (!record) {\n\t\trecord = { label, object: obj, prop, evolution, count: 0, lastTriggered: Date.now() }\n\t\tlabelMap.set(label, record)\n\t}\n\treturn record\n}\n\n/**\n * Assign a debug-friendly name to an effect (shown in DevTools)\n */\nexport function setEffectName(effect: ScopedCallback, name: string) {\n\teffectNames.set(effect, name)\n}\n\n/**\n * Assign a debug-friendly name to a reactive object\n */\nexport function setObjectName(obj: object, name: string) {\n\tobjectNames.set(obj, name)\n\tdebugObjectRegistry.add(obj)\n}\n\n/**\n * Register an effect so it appears in the DevTools graph\n */\nexport function registerEffectForDebug(effect: ScopedCallback) {\n\tif (!effect || !devtoolsEnabled) return\n\taddEffectToRegistry(effect)\n}\n\n/**\n * Register a reactive object so it appears in the DevTools graph\n */\nexport function registerObjectForDebug(obj: object) {\n\tif (!devtoolsEnabled) return\n\tdocumentObject(obj)\n}\n\n/**\n * Records a cause → consequence relationship between effects.\n * @param source - The effect performing the write (undefined if external/user input)\n * @param target - The effect that re-ran because of the write\n * @param obj - The reactive object that changed\n * @param prop - The property that changed\n * @param evolution - The type of change (set/add/del/bunch)\n */\nexport function recordTriggerLink(\n\tsource: ScopedCallback | undefined,\n\ttarget: ScopedCallback,\n\tobj: object,\n\tprop: any,\n\tevolution: Evolution\n) {\n\tif (options.introspection.enableHistory) {\n\t\taddToMutationHistory(source, target, obj, prop, evolution)\n\t}\n\tif (!devtoolsEnabled) return\n\taddEffectToRegistry(target)\n\tif (source) addEffectToRegistry(source)\n\tconst descriptor = describeProp(obj, prop)\n\tconst record = ensureTriggerRecord(\n\t\tsource ?? EXTERNAL_SOURCE,\n\t\ttarget,\n\t\tdescriptor,\n\t\tobj,\n\t\tprop,\n\t\tevolution\n\t)\n\trecord.count += 1\n\trecord.lastTriggered = Date.now()\n\tdocumentObject(obj)\n}\n\n/**\n * Traces back the chain of triggers that led to a specific effect\n * @param effect The effect to trace back\n * @param limit Max depth\n */\nexport function getTriggerChain(effect: ScopedCallback, limit = 5): string[] {\n\tconst chain: string[] = []\n\tlet current = effect\n\tfor (let i = 0; i < limit; i++) {\n\t\t// Find who triggered 'current'\n\t\t// We need to reverse search the triggerGraph (source -> target)\n\t\t// This is expensive O(Edges) but okay for error reporting\n\t\tlet foundSource: ScopedCallback | undefined\n\t\tlet foundReason = ''\n\n\t\tsearch: for (const [source, targetMap] of triggerGraph) {\n\t\t\tfor (const [target, labelMap] of targetMap) {\n\t\t\t\tif (target === current) {\n\t\t\t\t\t// Found a source! Use the most recent trigger record\n\t\t\t\t\tlet lastTime = 0\n\t\t\t\t\tfor (const record of labelMap.values()) {\n\t\t\t\t\t\tif (record.lastTriggered > lastTime) {\n\t\t\t\t\t\t\tlastTime = record.lastTriggered\n\t\t\t\t\t\t\tfoundReason = record.label\n\t\t\t\t\t\t\tfoundSource = source === EXTERNAL_SOURCE ? undefined : (source as ScopedCallback)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (foundSource || foundReason) break search\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (foundSource) {\n\t\t\tchain.push(\n\t\t\t\t`${ensureEffectName(foundSource)} -> (${foundReason}) -> ${ensureEffectName(current)}`\n\t\t\t)\n\t\t\tcurrent = foundSource\n\t\t} else if (foundReason) {\n\t\t\tchain.push(`External -> (${foundReason}) -> ${ensureEffectName(current)}`)\n\t\t\tbreak\n\t\t} else {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn chain.reverse()\n}\n\nfunction buildEffectNodes(allEffects: Set<ScopedCallback>) {\n\tconst nodes: EffectNode[] = []\n\tconst nodeByEffect = new Map<ScopedCallback, EffectNode>()\n\n\tconst ordered = Array.from(allEffects)\n\tfor (const effect of ordered) {\n\t\tconst label = ensureEffectName(effect)\n\t\tconst node: EffectNode = {\n\t\t\tid: `effect_${nodes.length}`,\n\t\t\tlabel,\n\t\t\ttype: 'effect',\n\t\t\tdepth: 0,\n\t\t\tdebugName: label,\n\t\t}\n\t\tnodes.push(node)\n\t\tnodeByEffect.set(effect, node)\n\t}\n\n\tconst depthCache = new Map<ScopedCallback, number>()\n\tconst computeDepth = (effect: ScopedCallback | undefined): number => {\n\t\tif (!effect) return 0\n\t\tconst cached = depthCache.get(effect)\n\t\tif (cached !== undefined) return cached\n\t\tconst parent = effectParent.get(effect)\n\t\tconst depth = computeDepth(parent) + (parent ? 1 : 0)\n\t\tdepthCache.set(effect, depth)\n\t\treturn depth\n\t}\n\n\tfor (const [effect, node] of nodeByEffect) {\n\t\tnode.depth = computeDepth(effect)\n\t\tconst parent = effectParent.get(effect)\n\t\tif (parent) {\n\t\t\tconst parentNode = nodeByEffect.get(parent)\n\t\t\tif (parentNode) {\n\t\t\t\tnode.parentId = parentNode.id\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { nodes, nodeByEffect }\n}\n\n/**\n * Builds a graph representing current reactive state (effects, objects, and trigger edges)\n */\nexport function buildReactivityGraph(): ReactivityGraph {\n\tconst nodes: Array<EffectNode | ObjectNode> = []\n\tconst edges: GraphEdge[] = []\n\tconst nodeIds = new Map<ScopedCallback | object | SourceEffect, string>()\n\n\tconst allEffects = new Set<ScopedCallback>(debugEffectRegistry)\n\tensureParentChains(allEffects)\n\tconst { nodes: effectNodes, nodeByEffect } = buildEffectNodes(allEffects)\n\tfor (const node of effectNodes) nodes.push(node)\n\tfor (const [effect, node] of nodeByEffect) {\n\t\tnodeIds.set(effect, node.id)\n\t}\n\n\t// Object nodes (optional, used for dependency inspection)\n\tfor (const obj of debugObjectRegistry) {\n\t\tconst id = `object_${nodes.length}`\n\t\tnodes.push({ id, label: ensureObjectName(obj), type: 'state', debugName: objectNames.get(obj) })\n\t\tnodeIds.set(obj, id)\n\t}\n\n\t// External source node (user/system outside of effects)\n\tif (triggerGraph.has(EXTERNAL_SOURCE)) {\n\t\tconst externalId = `effect_external`\n\t\tnodes.push({ id: externalId, label: 'External', type: 'external', depth: 0 })\n\t\tnodeIds.set(EXTERNAL_SOURCE, externalId)\n\t}\n\n\t// Dependency edges (effect → object)\n\tfor (const effect of allEffects) {\n\t\tconst effectId = nodeIds.get(effect)\n\t\tif (!effectId) continue\n\t\tconst deps = effectToReactiveObjects.get(effect)\n\t\tif (!deps) continue\n\t\tfor (const obj of deps) {\n\t\t\tconst objId = nodeIds.get(obj)\n\t\t\tif (!objId) continue\n\t\t\tedges.push({\n\t\t\t\tid: `${effectId}->${objId}`,\n\t\t\t\tsource: effectId,\n\t\t\t\ttarget: objId,\n\t\t\t\ttype: 'dependency',\n\t\t\t\tlabel: 'depends',\n\t\t\t})\n\t\t}\n\t}\n\n\t// Cause edges (effect/object/prop → effect)\n\tfor (const [source, targetMap] of triggerGraph) {\n\t\tfor (const [targetEffect, labelMap] of targetMap) {\n\t\t\tconst targetId = nodeIds.get(targetEffect)\n\t\t\tif (!targetId) continue\n\t\t\tconst sourceId = nodeIds.get(source)\n\t\t\tif (!sourceId) continue\n\t\t\tfor (const record of labelMap.values()) {\n\t\t\t\tedges.push({\n\t\t\t\t\tid: `${sourceId}->${targetId}:${record.label}`,\n\t\t\t\t\tsource: sourceId,\n\t\t\t\t\ttarget: targetId,\n\t\t\t\t\ttype: 'cause',\n\t\t\t\t\tlabel: record.count > 1 ? `${record.label} (${record.count})` : record.label,\n\t\t\t\t\tcount: record.count,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tnodes,\n\t\tedges,\n\t\tmeta: {\n\t\t\tgeneratedAt: Date.now(),\n\t\t\tdevtoolsEnabled,\n\t\t},\n\t}\n}\n\n/**\n * Enables the DevTools bridge and exposes the debug API on window.\n * Call as early as possible in development builds.\n */\nexport function enableDevTools() {\n\tif (typeof window === 'undefined') return\n\tif (devtoolsEnabled) return\n\tdevtoolsEnabled = true\n\n\t// @ts-expect-error - global window extension\n\twindow.__MUTTS_DEVTOOLS__ = {\n\t\tgetGraph: buildReactivityGraph,\n\t\tsetEffectName,\n\t\tsetObjectName,\n\t\tregisterEffect: registerEffectForDebug,\n\t\tregisterObject: registerObjectForDebug,\n\t}\n}\n\nexport function forceEnableGraphTracking() {\n\tdevtoolsEnabled = true\n}\n\nexport function isDevtoolsEnabled() {\n\treturn devtoolsEnabled\n}\n\n// --- Introspection API ---\n\n/**\n * Returns the raw dependency graph data structure.\n * This is useful for programmatic analysis of the reactive system.\n */\nexport function getDependencyGraph() {\n\treturn {\n\t\tnodes: buildReactivityGraph().nodes,\n\t\tedges: buildReactivityGraph().edges,\n\t}\n}\n\n/**\n * Returns a list of effects that depend on the given object.\n */\nexport function getDependents(obj: object): ScopedCallback[] {\n\tconst dependents: ScopedCallback[] = []\n\t// Scan the trigger graph for effects triggered by this object\n\t// This is O(E) where E is the number of edges, might need optimization for large graphs\n\t// but acceptable for introspection\n\tfor (const [_source, targetMap] of triggerGraph) {\n\t\tfor (const [targetEffect, labelMap] of targetMap) {\n\t\t\tfor (const record of labelMap.values()) {\n\t\t\t\tif (record.object === obj) {\n\t\t\t\t\tdependents.push(targetEffect)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t// Also check direct dependencies (dependency graph)\n\t// We don't have a direct obj -> effect map without walking all effects\n\t// unless we use `watchers` from tracking.ts but that's internal\n\treturn [...new Set(dependents)]\n}\n\n/**\n * Returns a list of objects that the given effect depends on.\n */\nexport function getDependencies(effect: ScopedCallback): object[] {\n\tconst deps = effectToReactiveObjects.get(effect)\n\treturn deps ? Array.from(deps) : []\n}\n\n// --- Mutation History ---\n\nexport interface MutationRecord {\n\tid: number\n\ttimestamp: number\n\tsource: string\n\ttarget: string\n\tobjectName: string\n\tprop: string\n\ttype: string\n}\n\nconst mutationHistory: MutationRecord[] = []\nlet mutationCounter = 0\n\nfunction addToMutationHistory(\n\tsource: ScopedCallback | undefined,\n\ttarget: ScopedCallback,\n\tobj: object,\n\tprop: any,\n\tevolution: Evolution\n) {\n\tconst record: MutationRecord = {\n\t\tid: ++mutationCounter,\n\t\ttimestamp: Date.now(),\n\t\tsource: source ? ensureEffectName(source) : 'External',\n\t\ttarget: ensureEffectName(target),\n\t\tobjectName: ensureObjectName(obj),\n\t\tprop: String(prop),\n\t\ttype: evolution.type,\n\t}\n\n\tmutationHistory.push(record)\n\tif (mutationHistory.length > options.introspection.historySize) {\n\t\tmutationHistory.shift()\n\t}\n}\n\n/**\n * Get the recent mutation history\n */\nexport function getMutationHistory(): MutationRecord[] {\n\treturn [...mutationHistory]\n}\n","import { asyncHooks } from \"./async\"\nimport { named, tag } from \"./utils\"\n\ninterface InternalZoneUse<T> {\n\tenter(value?: T): unknown\n\tleave(entered: unknown): void\n}\nfunction isu<T>(z: AZone<T> | InternalZoneUse<T>): InternalZoneUse<T> {\n\treturn z as InternalZoneUse<T>\n}\nexport abstract class AZone<T> {\n\tabstract active?: T\n\tprotected enter(value?: T): unknown {\n\t\tconst prev = this.active\n\t\tthis.active = value\n\t\treturn prev\n\t}\n\tprotected leave(entered: unknown): void {\n\t\tthis.active = entered as T | undefined\n\t}\n\twith<R>(value: T, fn: () => R): R {\n\t\tconst entered = this.enter(value)\n let res: R;\n\t\ttry {\n\t\t\tres = fn()\n\t\t} finally {\n\t\t\tthis.leave(entered)\n\t\t}\n // [HACK]: Sanitization\n // See BROWSER_ASYNC_POLYFILL.md\n return asyncHooks.sanitizePromise(res) as R\n\t}\n\troot<R>(fn: () => R): R {\n\t\tlet prev = this.enter()\n\t\ttry {\n\t\t\treturn fn()\n\t\t} finally {\n\t\t\tthis.leave(prev)\n\t\t}\n\t}\n\tget zoned(): FunctionWrapper {\n\t\tconst active = this.active\n\t\treturn named(`${this}@${active}`, (fn) => this.with(active, fn))\n\t}\n}\n\nexport type FunctionWrapper = <R>(fn?: () => R) => R\n\nexport class Zone<T> extends AZone<T> {\n\tactive: T | undefined\n}\ntype HistoryValue<T> = {present: T | undefined, history: Set<T>}\nexport class ZoneHistory<T> extends AZone<HistoryValue<T>> {\n\tprivate\thistory = new Set<T>()\n\tpublic readonly present: AZone<T>\n\tpublic has(value: T): boolean {\n\t\treturn this.history.has(value)\n\t}\n\tpublic some(predicate: (value: T) => boolean): boolean {\n\t\tfor(const value of this.history) if(predicate(value)) return true\n\t\treturn false\n\t}\n\tconstructor(private controlled: AZone<T> = new Zone<T>()) {\n\t\tsuper()\n\t\tconst self = this\n\t\tthis.present = Object.create(controlled,\n\t\t\tObject.getOwnPropertyDescriptors({\n\t\t\t\tget active() { return controlled.active },\n\t\t\t\tset active(value: T | undefined) {\n\t\t\t\t\tcontrolled.active = value\n\t\t\t\t},\n\t\t\t\tenter(value?: T) {\n\t\t\t\t\tif(value && self.history.has(value)) throw new Error('ZoneHistory: re-entering historical zone')\n\t\t\t\t\tif(value !== undefined) self.history.add(value)\n\t\t\t\t\treturn { added: value, entered: isu(controlled).enter(value) }\n\t\t\t\t},\n\t\t\t\tleave(entered: { added: T | undefined, entered: unknown }) {\n\t\t\t\t\tif(entered.added !== undefined) self.history.delete(entered.added)\n\t\t\t\t\treturn isu(controlled).leave(entered.entered)\n\t\t\t\t}\n\t\t\t})\n\t\t)\n\t}\n\tget active() {\n\t\treturn {present: this.controlled.active, history: new Set(this.history)}\n\t}\n\tset active(value: HistoryValue<T> | undefined) {\n\t\tthis.history = this.history && new Set(this.history)\n\t\tthis.controlled.active = value?.present\n\t}\n}\n\nexport class ZoneAggregator extends AZone<Map<AZone<unknown>, unknown>> {\n\t#zones = new Set<AZone<unknown>>()\n\tconstructor(...zones: AZone<unknown>[]) {\n\t\tsuper()\n\t\tfor (const z of zones) this.#zones.add(z)\n\t}\n\tget active(): Map<AZone<unknown>, unknown> | undefined {\n\t\tconst rv = new Map<AZone<unknown>, unknown>()\n\t\tfor (const z of this.#zones)\n\t\t\tif (z.active !== undefined) rv.set(z, z.active)\n\t\treturn rv\n\t}\n\tset active(value: Map<AZone<unknown>, unknown> | undefined) {\n\t\tfor (const z of this.#zones) z.active = value?.get(z)\n\t}\n\tenter(value?: Map<AZone<unknown>, unknown> | undefined) {\n\t\tconst entered = new Map<AZone<unknown>, unknown>()\n\t\tfor (const z of this.#zones) {\n\t\t\tconst v = value?.get(z)\n\t\t\tentered.set(z, isu(z).enter(v))\n\t\t}\n\t\treturn entered\n\t}\n\tleave(entered: Map<AZone<unknown>, unknown>): void {\n\t\tfor (const z of this.#zones) isu(z).leave(entered.get(z))\n\t}\n\tadd(z: AZone<unknown>) {\n\t\tthis.#zones.add(z)\n\t}\n\tdelete(z: AZone<unknown>) {\n\t\tthis.#zones.delete(z)\n\t}\n\tclear() {\n\t\tthis.#zones.clear()\n\t}\n}\n\nexport const asyncZone = tag('async', new ZoneAggregator())\nasyncHooks.addHook(() => {\n\tconst zone = asyncZone.active\n\treturn () => {\n\t\tconst prev = asyncZone.active\n\t\tasyncZone.active = zone\n\t\treturn () => asyncZone.active = prev\n\t}\n})\n","import { tag } from '../utils'\nimport { asyncZone, ZoneAggregator, ZoneHistory } from '../zone'\nimport { getRoot } from './registry'\nimport { type ScopedCallback } from './types'\n\nexport const effectHistory = tag('effectHistory', new ZoneHistory<ScopedCallback>())\ntag('effectHistory.present', effectHistory.present)\nasyncZone.add(effectHistory)\nexport const effectAggregator = tag('effectAggregator', new ZoneAggregator(effectHistory.present))\n\nexport function isRunning(effect: ScopedCallback): boolean {\n\tconst root = getRoot(effect)\n\treturn effectHistory.some((e) => getRoot(e) === root)\n}\n\nexport function getActiveEffect() {\n\treturn effectHistory.present.active\n}","export const objectToProxy = new WeakMap<object, object>()\nexport const proxyToObject = new WeakMap<object, object>()\n\nexport function storeProxyRelationship(target: object, proxy: object) {\n\tobjectToProxy.set(target, proxy)\n\tproxyToObject.set(proxy, target)\n}\n\nexport function getExistingProxy<T extends object>(target: T): T | undefined {\n\treturn objectToProxy.get(target) as T | undefined\n}\n\nexport function trackProxyObject(proxy: object, target: object) {\n\tproxyToObject.set(proxy, target)\n}\n\nexport function unwrap<T>(obj: T): T {\n\tlet current = obj\n\twhile (current && typeof current === 'object' && current !== null && proxyToObject.has(current)) {\n\t\tcurrent = proxyToObject.get(current) as T\n\t}\n\treturn current\n}\n\nexport function isReactive(obj: any): boolean {\n\treturn proxyToObject.has(obj)\n}\n","import { decorator } from '../decorator'\nimport { IterableWeakSet } from '../iterableWeak'\nimport { getTriggerChain, isDevtoolsEnabled, registerEffectForDebug } from './debug'\nimport {\n\teffectAggregator,\n\teffectHistory,\n\tgetActiveEffect,\n} from './effect-context'\nimport {\n\teffectChildren,\n\teffectParent,\n\teffectToReactiveObjects,\n\tgetRoot,\n\tmarkWithRoot,\n\twatchers,\n} from './registry'\nimport {\n\tcleanup as cleanupSymbol,\n\ttype DependencyAccess,\n\ttype EffectOptions,\n\ttype Evolution,\n\toptions,\n\tReactiveError,\n\tReactiveErrorCode,\n\t// type AsyncExecutionMode,\n\ttype ScopedCallback,\n\tstopped,\n} from './types'\n\nimport { unwrap } from './proxy-state'\n\n/**\n * Finds a cycle in a sequence of functions by looking for the first repetition\n */\nfunction findCycleInChain(roots: Function[]): Function[] | null {\n\tconst seen = new Map<Function, number>()\n\tfor (let i = 0; i < roots.length; i++) {\n\t\tconst root = roots[i]\n\t\tif (seen.has(root)) {\n\t\t\treturn roots.slice(seen.get(root)!)\n\t\t}\n\t\tseen.set(root, i)\n\t}\n\treturn null\n}\n\n/**\n * Formats a list of function roots into a readable trace\n */\nfunction formatRoots(roots: Function[], limit = 20): string {\n\tconst names = roots.map((r) => r.name || '<anonymous>')\n\tif (names.length <= limit) return names.join(' → ')\n\tconst start = names.slice(0, 5)\n\tconst end = names.slice(-10)\n\treturn `${start.join(' → ')} ... (${names.length - 15} more) ... ${end.join(' → ')}`\n}\n\ntype EffectTracking = (obj: any, evolution: Evolution, prop: any) => void\n\nexport interface ActivationRecord {\n\teffect: ScopedCallback\n\tobj: any\n\tevolution: Evolution\n\tprop: any\n\tbatchId: number\n}\n\n// Nested map structure for efficient counting and batch cleanup\n// batchId -> effect root -> obj -> prop -> count\nlet activationRegistry: Map<Function, Map<any, Map<any, number>>> | undefined\n\nexport const activationLog: Omit<ActivationRecord, 'batchId'>[] = new Array(100)\n\nexport function getActivationLog() {\n\treturn activationLog\n}\n\nexport function recordActivation(\n\teffect: ScopedCallback,\n\tobj: any,\n\tevolution: Evolution,\n\tprop: any\n) {\n\tconst root = getRoot(effect)\n\n\tif (!activationRegistry) return\n\tlet effectData = activationRegistry.get(root)\n\tif (!effectData) {\n\t\teffectData = new Map()\n\t\tactivationRegistry.set(root, effectData)\n\t}\n\tlet objData = effectData.get(obj)\n\tif (!objData) {\n\t\tobjData = new Map()\n\t\teffectData.set(obj, objData)\n\t}\n\tconst count = (objData.get(prop) ?? 0) + 1\n\tobjData.set(prop, count)\n\n\t// Keep a limited history for diagnostics\n\tactivationLog.unshift({\n\t\teffect,\n\t\tobj,\n\t\tevolution,\n\t\tprop,\n\t})\n\tactivationLog.pop()\n\n\tif (count >= options.maxTriggerPerBatch) {\n\t\tconst effectName = (root as any)?.name || 'anonymous'\n\t\tconst message = `Aggressive trigger detected: effect \"${effectName}\" triggered ${count} times in the batch by the same cause.`\n\t\tif (options.maxEffectReaction === 'throw') {\n\t\t\tthrow new ReactiveError(message, {\n\t\t\t\tcode: ReactiveErrorCode.MaxReactionExceeded,\n\t\t\t\tcount,\n\t\t\t\teffect: effectName,\n\t\t\t})\n\t\t}\n\t\toptions.warn(`[reactive] ${message}`)\n\t}\n}\n\n/**\n * Registers a debug callback that is called when the current effect is triggered by a dependency change\n *\n * This function is useful for debugging purposes as it pin-points exactly which reactive property\n * change triggered the effect. The callback receives information about:\n * - The object that changed\n * - The type of change (evolution)\n * - The specific property that changed\n *\n * **Note:** The tracker callback is automatically removed after being called once. If you need\n * to track multiple triggers, call `trackEffect` again within the effect.\n *\n * @param onTouch - Callback function that receives (obj, evolution, prop) when the effect is triggered\n * @throws {Error} If called outside of an effect context\n *\n * @example\n * ```typescript\n * const state = reactive({ count: 0, name: 'John' })\n *\n * effect(() => {\n * // Register a tracker to see what triggers this effect\n * trackEffect((obj, evolution, prop) => {\n * console.log(`Effect triggered by:`, {\n * object: obj,\n * change: evolution.type,\n * property: prop\n * })\n * })\n *\n * // Access reactive properties\n * console.log(state.count, state.name)\n * })\n *\n * state.count = 5\n * // Logs: Effect triggered by: { object: state, change: 'set', property: 'count' }\n * ```\n */\nexport function trackEffect(onTouch: EffectTracking) {\n\tconst activeEffect = getActiveEffect()\n\tif (!activeEffect) throw new Error('Not in an effect')\n\tif (!effectTrackers.has(activeEffect)) effectTrackers.set(activeEffect, new Set([onTouch]))\n\telse effectTrackers.get(activeEffect)!.add(onTouch)\n}\n\nconst effectTrackers = new WeakMap<ScopedCallback, Set<EffectTracking>>()\n\nexport const opaqueEffects = new WeakSet<ScopedCallback>()\n\n// Dependency graph: tracks which effects trigger which other effects\n// Uses roots (Function) as keys for consistency\nconst effectTriggers = new WeakMap<Function, IterableWeakSet<Function>>()\nconst effectTriggeredBy = new WeakMap<Function, IterableWeakSet<Function>>()\n\n// Transitive closures: track all indirect relationships\n// causesClosure: for each effect, all effects that trigger it (directly or indirectly)\n// consequencesClosure: for each effect, all effects that it triggers (directly or indirectly)\nconst causesClosure = new WeakMap<Function, IterableWeakSet<Function>>()\nconst consequencesClosure = new WeakMap<Function, IterableWeakSet<Function>>()\n\n// Debug: Capture where an effect was created\nexport const effectCreationStacks = new WeakMap<Function, string>()\n\n/**\n * Gets or creates an IterableWeakSet for a closure map\n */\nfunction getOrCreateClosure(\n\tclosure: WeakMap<Function, IterableWeakSet<Function>>,\n\troot: Function\n): IterableWeakSet<Function> {\n\tlet set = closure.get(root)\n\tif (!set) {\n\t\tset = new IterableWeakSet()\n\t\tclosure.set(root, set)\n\t}\n\treturn set\n}\n\n/**\n * Adds an edge to the dependency graph: callerRoot → targetRoot\n * Also maintains transitive closures\n * @param callerRoot - Root function of the effect that triggers\n * @param targetRoot - Root function of the effect being triggered\n */\nfunction addGraphEdge(callerRoot: Function, targetRoot: Function) {\n\tif (options.cycleHandling === 'none') return\n\t// Skip if edge already exists\n\tconst triggers = effectTriggers.get(callerRoot)\n\tif (triggers?.has(targetRoot)) {\n\t\treturn // Edge already exists\n\t}\n\n\t// Add to forward graph: callerRoot → targetRoot\n\tif (!triggers) {\n\t\tconst newTriggers = new IterableWeakSet<Function>()\n\t\tnewTriggers.add(targetRoot)\n\t\teffectTriggers.set(callerRoot, newTriggers)\n\t} else {\n\t\ttriggers.add(targetRoot)\n\t}\n\n\t// Add to reverse graph: targetRoot ← callerRoot\n\tlet triggeredBy = effectTriggeredBy.get(targetRoot)\n\tif (!triggeredBy) {\n\t\ttriggeredBy = new IterableWeakSet()\n\t\teffectTriggeredBy.set(targetRoot, triggeredBy)\n\t}\n\ttriggeredBy.add(callerRoot)\n\n\t// Update transitive closures\n\t// When U→V is added, we need to propagate the relationship:\n\t// 1. Add U to causesClosure(V) and V to consequencesClosure(U) (direct relationship)\n\t// 2. For each X in causesClosure(U): add V to consequencesClosure(X) and X to causesClosure(V)\n\t// 3. For each Y in consequencesClosure(V): add U to causesClosure(Y) and Y to consequencesClosure(U)\n\t// Note: Self-loops (U→U) are not added to closures - if an effect appears in its own closure,\n\t// it means there's an indirect cycle that should be detected\n\n\t// Self-loops are explicitly ignored - an effect reading and writing the same property\n\t// (e.g., obj.prop++) should not create a dependency relationship or appear in closures\n\tif (callerRoot === targetRoot) {\n\t\treturn\n\t}\n\n\tconst uConsequences = getOrCreateClosure(consequencesClosure, callerRoot)\n\tconst vCauses = getOrCreateClosure(causesClosure, targetRoot)\n\n\t// 1. Add direct relationship\n\tuConsequences.add(targetRoot)\n\tvCauses.add(callerRoot)\n\n\t// 2. For each X in causesClosure(U): X→U→V means X→V\n\tconst uCausesSet = causesClosure.get(callerRoot)\n\tif (uCausesSet) {\n\t\tfor (const x of uCausesSet) {\n\t\t\t// Skip if this would create a self-loop\n\t\t\tif (x === targetRoot) continue\n\t\t\tconst xConsequences = getOrCreateClosure(consequencesClosure, x)\n\t\t\txConsequences.add(targetRoot)\n\t\t\tvCauses.add(x)\n\t\t}\n\t}\n\n\t// 3. For each Y in consequencesClosure(V): U→V→Y means U→Y\n\tconst vConsequencesSet = consequencesClosure.get(targetRoot)\n\tif (vConsequencesSet) {\n\t\tfor (const y of vConsequencesSet) {\n\t\t\t// Skip if this would create a self-loop\n\t\t\tif (y === callerRoot) continue\n\t\t\tconst yCauses = getOrCreateClosure(causesClosure, y)\n\t\t\tyCauses.add(callerRoot)\n\t\t\tuConsequences.add(y)\n\t\t}\n\t}\n\n\t// 4. Cross-product: for each X in causesClosure(U) and Y in consequencesClosure(V): X→Y\n\tif (uCausesSet && vConsequencesSet) {\n\t\tfor (const x of uCausesSet) {\n\t\t\tconst xConsequences = getOrCreateClosure(consequencesClosure, x)\n\t\t\tfor (const y of vConsequencesSet) {\n\t\t\t\t// Skip if this would create a self-loop\n\t\t\t\tif (x === y) continue\n\t\t\t\txConsequences.add(y)\n\t\t\t\tconst yCauses = getOrCreateClosure(causesClosure, y)\n\t\t\t\tyCauses.add(x)\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Checks if there's a path from start to end in the dependency graph, excluding a specific node\n * Uses BFS to find any path that doesn't go through the excluded node\n * @param start - Starting node\n * @param end - Target node\n * @param exclude - Node to exclude from the path\n * @returns true if a path exists without going through the excluded node\n * @todo Can be REALLY costly - optimise or make optional or ...\n */\nfunction hasPathExcluding(start: Function, end: Function, exclude: Function): boolean {\n\tif (start === end) return true\n\tif (start === exclude) return false\n\n\tconst visited = new Set<Function>()\n\tconst queue: Function[] = [start]\n\tvisited.add(start)\n\tvisited.add(exclude) // Pre-mark excluded node as visited to skip it\n\n\twhile (queue.length > 0) {\n\t\tconst current = queue.shift()!\n\t\tconst triggers = effectTriggers.get(current)\n\t\tif (!triggers) continue\n\n\t\tfor (const next of triggers) {\n\t\t\tif (next === end) return true\n\t\t\tif (!visited.has(next)) {\n\t\t\t\tvisited.add(next)\n\t\t\t\tqueue.push(next)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn false\n}\n\n/**\n * Removes all edges involving the given effect from the dependency graph\n * Also cleans up transitive closures by propagating cleanup to all affected effects\n * Called when an effect is stopped/cleaned up\n * @param effect - The effect being cleaned up\n */\nfunction cleanupEffectFromGraph(effect: ScopedCallback) {\n\tif (options.cycleHandling === 'none') return\n\tconst root = getRoot(effect)\n\n\t// Get closures before removing direct edges (needed for propagation)\n\tconst rootCauses = causesClosure.get(root)\n\tconst rootConsequences = consequencesClosure.get(root)\n\n\t// Remove from effectTriggers (outgoing edges)\n\tconst triggers = effectTriggers.get(root)\n\tif (triggers) {\n\t\t// Remove this root from all targets' effectTriggeredBy sets\n\t\tfor (const targetRoot of triggers) {\n\t\t\tconst triggeredBy = effectTriggeredBy.get(targetRoot)\n\t\t\ttriggeredBy?.delete(root)\n\t\t}\n\t\teffectTriggers.delete(root)\n\t}\n\n\t// Remove from effectTriggeredBy (incoming edges)\n\tconst triggeredBy = effectTriggeredBy.get(root)\n\tif (triggeredBy) {\n\t\t// Remove this root from all sources' effectTriggers sets\n\t\tfor (const sourceRoot of triggeredBy) {\n\t\t\tconst triggers = effectTriggers.get(sourceRoot)\n\t\t\ttriggers?.delete(root)\n\t\t}\n\t\teffectTriggeredBy.delete(root)\n\t}\n\n\t// Propagate closure cleanup to all affected effects\n\t// When removing B from A → B → C:\n\t// - Remove B from causesClosure(C) and consequencesClosure(A)\n\t// - For each X in causesClosure(B): remove C from consequencesClosure(X) if B was the only path\n\t// - For each Y in consequencesClosure(B): remove A from causesClosure(Y) if B was the only path\n\t// - Remove transitive relationships that depended on B\n\n\tif (rootCauses) {\n\t\t// For each X that triggers root: remove root from X's consequences\n\t\t// Only remove root's consequences if no alternate path exists\n\t\tfor (const causeRoot of rootCauses) {\n\t\t\tconst causeConsequences = consequencesClosure.get(causeRoot)\n\t\t\tif (causeConsequences) {\n\t\t\t\t// Remove root itself (it's being cleaned up)\n\t\t\t\tcauseConsequences.delete(root)\n\t\t\t\t// Only remove consequences of root if there's no alternate path from causeRoot to them\n\t\t\t\tif (rootConsequences) {\n\t\t\t\t\tfor (const consequence of rootConsequences) {\n\t\t\t\t\t\t// Check if causeRoot can still reach consequence without going through root\n\t\t\t\t\t\tif (!hasPathExcluding(causeRoot, consequence, root)) {\n\t\t\t\t\t\t\tcauseConsequences.delete(consequence)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (rootConsequences) {\n\t\t// For each Y that root triggers: remove root from Y's causes\n\t\t// Only remove root's causes if no alternate path exists\n\t\tfor (const consequenceRoot of rootConsequences) {\n\t\t\tconst consequenceCauses = causesClosure.get(consequenceRoot)\n\t\t\tif (consequenceCauses) {\n\t\t\t\t// Remove root itself (it's being cleaned up)\n\t\t\t\tconsequenceCauses.delete(root)\n\t\t\t\t// Only remove causes of root if there's no alternate path from them to consequenceRoot\n\t\t\t\tif (rootCauses) {\n\t\t\t\t\tfor (const cause of rootCauses) {\n\t\t\t\t\t\t// Check if cause can still reach consequenceRoot without going through root\n\t\t\t\t\t\tif (!hasPathExcluding(cause, consequenceRoot, root)) {\n\t\t\t\t\t\t\tconsequenceCauses.delete(cause)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Cross-product cleanup: for each X in causesClosure(B) and Y in consequencesClosure(B),\n\t// remove X→Y if B was the only path connecting them\n\tif (rootCauses && rootConsequences) {\n\t\tfor (const x of rootCauses) {\n\t\t\tconst xConsequences = consequencesClosure.get(x)\n\t\t\tif (xConsequences) {\n\t\t\t\tfor (const y of rootConsequences) {\n\t\t\t\t\t// Check if there's still a path from X to Y without going through root\n\t\t\t\t\t// Use BFS to find any path that doesn't include root\n\t\t\t\t\tif (!hasPathExcluding(x, y, root)) {\n\t\t\t\t\t\txConsequences.delete(y)\n\t\t\t\t\t\tconst yCauses = causesClosure.get(y)\n\t\t\t\t\t\tyCauses?.delete(x)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Finally, delete the closures for this effect\n\tcausesClosure.delete(root)\n\tconsequencesClosure.delete(root)\n}\n\n// Batch queue structure - optimized with cached in-degrees\ninterface BatchQueue {\n\t// All effects in the current batch that still need to be executed (todos)\n\tall: Map<Function, ScopedCallback> // root → effect\n\t// Cached in-degrees for each effect in the batch (number of causes in batch)\n\tinDegrees: Map<Function, number> // root → in-degree count\n}\n\n// Track currently executing effects to prevent re-execution\n// These are all the effects triggered under `activeEffect`\nlet batchQueue: BatchQueue | undefined\nexport function hasBatched(effect: ScopedCallback) {\n\treturn batchQueue?.all.has(getRoot(effect))\n}\nconst batchCleanups = new Set<ScopedCallback>()\n\n/**\n * Computes and caches in-degrees for all effects in the batch\n * Called once when batch starts or when new effects are added\n */\nfunction computeAllInDegrees(batch: BatchQueue): void {\n\tif (options.cycleHandling === 'none') return\n\tconst activeEffect = getActiveEffect()\n\tconst activeRoot = activeEffect ? getRoot(activeEffect) : null\n\n\t// Reset all in-degrees\n\tbatch.inDegrees.clear()\n\n\tfor (const [root] of batch.all) {\n\t\tlet inDegree = 0\n\t\tconst causes = causesClosure.get(root)\n\t\tif (causes) {\n\t\t\tfor (const causeRoot of causes) {\n\t\t\t\t// Only count if it's in the batch and not the active/self effect\n\t\t\t\tif (batch.all.has(causeRoot) && causeRoot !== activeRoot && causeRoot !== root) {\n\t\t\t\t\tinDegree++\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tbatch.inDegrees.set(root, inDegree)\n\t}\n}\n\n/**\n * Decrements in-degrees of all effects that depend on the executed effect\n * Called after an effect is executed to update the cached in-degrees\n */\nfunction decrementInDegreesForExecuted(batch: BatchQueue, executedRoot: Function): void {\n\t// Get all effects that this executed effect triggers\n\tconst consequences = consequencesClosure.get(executedRoot)\n\tif (!consequences) return\n\n\tfor (const consequenceRoot of consequences) {\n\t\t// Only update if it's still in the batch\n\t\tif (batch.all.has(consequenceRoot)) {\n\t\t\tconst currentDegree = batch.inDegrees.get(consequenceRoot) ?? 0\n\t\t\tif (currentDegree > 0) {\n\t\t\t\tbatch.inDegrees.set(consequenceRoot, currentDegree - 1)\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Computes the in-degree (number of dependencies) for an effect in the current batch\n * Uses causesClosure to count all effects (directly or indirectly) that trigger this effect\n * @param root - Root function of the effect\n * @param batchEffects - Map of all effects in current batch (todos - effects that still need execution)\n * @returns Number of effects in batch that trigger this effect (directly or indirectly)\n *\n * TODO: Optimization - For large graphs with small batches, iterating over all causes in the closure\n * can be expensive. Consider maintaining a separate \"batch causes\" set or caching in-degrees.\n */\n/* function computeInDegreeInBatch(\n\troot: Function,\n\tbatchEffects: Map<Function, ScopedCallback>\n): number {\n\tlet inDegree = 0\n\tconst activeEffect = getActiveEffect()\n\tconst activeRoot = activeEffect ? getRoot(activeEffect) : null\n\n\t// Count effects in batch that trigger this effect (directly or indirectly)\n\t// Using causesClosure which contains all transitive causes\n\t// Note: batchEffects only contains effects that still need execution (todos),\n\t// so we don't need to check if causes have been executed - they're not in the map if executed\n\tconst causes = causesClosure.get(root)\n\tif (causes) {\n\t\tfor (const causeRoot of causes) {\n\t\t\t// Only count if it's in the batch (still needs execution)\n\t\t\t// BUT: don't count the currently executing effect (active effect)\n\t\t\t// This handles the case where an effect is triggered during another effect's execution\n\t\t\t// Note: Self-loops are ignored - they should not appear in closures, but we check to be safe\n\t\t\tif (batchEffects.has(causeRoot) && causeRoot !== activeRoot && causeRoot !== root) {\n\t\t\t\tinDegree++\n\t\t\t}\n\t\t}\n\t}\n\n\treturn inDegree\n}\n\n/**\n * Finds a path from startRoot to endRoot in the dependency graph\n * Uses DFS to find the path through direct edges\n * @param startRoot - Starting effect root\n * @param endRoot - Target effect root\n * @param visited - Set of visited nodes (for recursion)\n * @param path - Current path being explored\n * @returns Path from startRoot to endRoot, or empty array if no path exists\n */\nfunction findPath(\n\tstartRoot: Function,\n\tendRoot: Function,\n\tvisited: Set<Function> = new Set(),\n\tpath: Function[] = []\n): Function[] {\n\tif (startRoot === endRoot) {\n\t\treturn [...path, endRoot]\n\t}\n\n\tif (visited.has(startRoot)) {\n\t\treturn []\n\t}\n\n\tvisited.add(startRoot)\n\tconst newPath = [...path, startRoot]\n\n\tconst triggers = effectTriggers.get(startRoot)\n\tif (triggers) {\n\t\tfor (const targetRoot of triggers) {\n\t\t\tconst result = findPath(targetRoot, endRoot, visited, newPath)\n\t\t\tif (result.length > 0) {\n\t\t\t\treturn result\n\t\t\t}\n\t\t}\n\t}\n\n\treturn []\n}\n\n/**\n * Gets the cycle path when adding an edge would create a cycle\n * @param callerRoot - Root of the effect that triggers\n * @param targetRoot - Root of the effect being triggered\n * @returns Array of effect roots forming the cycle, or empty array if no cycle\n */\nfunction getCyclePathForEdge(callerRoot: Function, targetRoot: Function): Function[] {\n\t// Find path from targetRoot back to callerRoot (this is the existing path)\n\t// Then adding callerRoot -> targetRoot completes the cycle\n\tconst path = findPath(targetRoot, callerRoot)\n\tif (path.length > 0) {\n\t\t// The cycle is: callerRoot -> targetRoot -> ... -> callerRoot\n\t\treturn [callerRoot, ...path]\n\t}\n\treturn []\n}\n\n/**\n * Checks if adding an edge would create a cycle\n * Uses causesClosure to check if callerRoot is already a cause of targetRoot\n * Self-loops (callerRoot === targetRoot) are explicitly ignored and return false\n *\n * **Note**: This is the primary optimization benefit of the transitive closure system.\n * It allows detecting cycles in O(1) time before they are executed.\n *\n * @param callerRoot - Root of the effect that triggers\n * @param targetRoot - Root of the effect being triggered\n * @returns true if adding this edge would create a cycle\n */\nfunction wouldCreateCycle(callerRoot: Function, targetRoot: Function): boolean {\n\t// Self-loops are explicitly ignored - an effect reading and writing the same property\n\t// (e.g., obj.prop++) should not create a dependency relationship\n\tif (callerRoot === targetRoot) {\n\t\treturn false\n\t}\n\n\t// Check if targetRoot already triggers callerRoot (directly or indirectly)\n\t// This would create a cycle: callerRoot -> targetRoot -> ... -> callerRoot\n\t// Using consequencesClosure: if targetRoot triggers callerRoot, then callerRoot is in consequencesClosure(targetRoot)\n\tconst targetConsequences = consequencesClosure.get(targetRoot)\n\tif (targetConsequences?.has(callerRoot)) {\n\t\treturn true // Cycle detected: targetRoot -> ... -> callerRoot, and we're adding callerRoot -> targetRoot\n\t}\n\n\treturn false\n}\n\n/**\n * Adds an effect to the batch queue\n * @param effect - The effect to add\n * @param caller - The active effect that triggered this one (optional)\n * @param immediate - If true, don't create edges in the dependency graph\n */\nfunction addToBatch(effect: ScopedCallback, caller?: ScopedCallback, immediate?: boolean) {\n\t(effect as any)[cleanupSymbol]?.()\n\t// If the effect was stopped during cleanup (e.g. lazy memoization), don't add it to the batch\n\tif ((effect as any)[stopped]) return\n\n\tif (!batchQueue) return\n\n\tconst root = getRoot(effect)\n\n\t// 1. Add to batch first (needed for cycle detection)\n\tif (options.cycleHandling === 'none' && batchQueue.all.has(root)) {\n\t\t// If already present in flat mode, remove it so that the next set puts it at the end\n\t\tbatchQueue.all.delete(root)\n\t}\n\n\tbatchQueue.all.set(root, effect)\n\n\t// 2. Add to global graph (if caller exists and not immediate) - USE ROOTS ONLY\n\t// When immediate is true, don't create edges - the effect is not considered as a consequence\n\tif (caller && !immediate && options.cycleHandling !== 'none') {\n\t\tconst callerRoot = getRoot(caller)\n\n\t\t// Check for cycle BEFORE adding edge\n\t\t// We check if adding callerRoot -> root would create a cycle\n\t\t// This means checking if root already triggers callerRoot (directly or transitively)\n\t\tif (wouldCreateCycle(callerRoot, root)) {\n\t\t\t// Cycle detected! Get the full cycle path for debugging\n\t\t\tconst cyclePath = getCyclePathForEdge(callerRoot, root)\n\t\t\tconst cycleMessage =\n\t\t\t\tcyclePath.length > 0\n\t\t\t\t\t? `Cycle detected: ${cyclePath.map((r) => r.name || r.toString()).join(' → ')}`\n\t\t\t\t\t: `Cycle detected: ${callerRoot.name || callerRoot.toString()} → ${root.name || root.toString()} (and back)`\n\n\t\t\tconst cycleHandling = options.cycleHandling\n\n\t\t\t// In strict mode, we throw immediately on detection\n\t\t\tif (cycleHandling === 'strict') {\n\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\tconst causalChain = getTriggerChain(effect)\n\t\t\t\tconst creationStack = effectCreationStacks.get(root)\n\n\t\t\t\tthrow new ReactiveError(`[reactive] Strict Cycle Prevention: ${cycleMessage}`, {\n\t\t\t\t\tcode: ReactiveErrorCode.CycleDetected,\n\t\t\t\t\tcycle: cyclePath.map((r) => r.name || r.toString()),\n\t\t\t\t\tdetails: cycleMessage,\n\t\t\t\t\tcausalChain,\n\t\t\t\t\tcreationStack,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tswitch (cycleHandling) {\n\t\t\t\tcase 'throw': {\n\t\t\t\t\t// Remove from batch before throwing\n\t\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\t\tconst causalChain = getTriggerChain(effect)\n\t\t\t\t\tconst creationStack = effectCreationStacks.get(root)\n\n\t\t\t\t\tthrow new ReactiveError(`[reactive] ${cycleMessage}`, {\n\t\t\t\t\t\tcode: ReactiveErrorCode.CycleDetected,\n\t\t\t\t\t\tcycle: cyclePath.map((r) => r.name || r.toString()),\n\t\t\t\t\t\tdetails: cycleMessage,\n\t\t\t\t\t\tcausalChain,\n\t\t\t\t\t\tcreationStack,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tcase 'warn':\n\t\t\t\t\toptions.warn(`[reactive] ${cycleMessage}`)\n\t\t\t\t\t// Don't add the edge, break the cycle\n\t\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\t\treturn\n\t\t\t\tcase 'break':\n\t\t\t\t\t// Silently break cycle, don't add the edge\n\t\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\taddGraphEdge(callerRoot, root) // Add to persistent graph using roots\n\t}\n}\n\n/**\n * Adds a cleanup function to be called when the current batch of effects completes\n * @param cleanup - The cleanup function to add\n */\nexport function addBatchCleanup(cleanup: ScopedCallback) {\n\tif (!batchQueue) cleanup()\n\telse batchCleanups.add(cleanup)\n}\n\n/**\n * Semantic alias for `addBatchCleanup` - defers work to the end of the current reactive batch.\n *\n * Use this when an effect needs to perform an action that would modify state the effect depends on,\n * which would create a reactive cycle. The deferred callback runs after all effects complete.\n *\n * @param callback - The callback to defer until after the current batch completes\n *\n * @example\n * ```typescript\n * effect(() => {\n * processData()\n *\n * // Defer to avoid cycle (createMovement modifies state this effect reads)\n * defer(() => {\n * createMovement(data)\n * })\n * })\n * ```\n */\nexport const defer = addBatchCleanup\n\n/**\n * Gets a cycle path for debugging\n * Uses DFS to find cycles in the batch\n * @param batchQueue - The batch queue\n * @returns Array of effect roots forming a cycle\n */\nfunction getCyclePath(batchQueue: BatchQueue): Function[] {\n\t// If all effects have in-degree > 0, there must be a cycle\n\t// Use DFS to find it\n\tconst visited = new Set<Function>()\n\tconst recursionStack = new Set<Function>()\n\tconst path: Function[] = []\n\n\tfor (const [root] of batchQueue.all) {\n\t\tif (visited.has(root)) continue\n\t\tconst cycle = findCycle(root, visited, recursionStack, path, batchQueue)\n\t\tif (cycle.length > 0) {\n\t\t\treturn cycle\n\t\t}\n\t}\n\n\treturn []\n}\n\nfunction findCycle(\n\troot: Function,\n\tvisited: Set<Function>,\n\trecursionStack: Set<Function>,\n\tpath: Function[],\n\tbatchQueue: BatchQueue\n): Function[] {\n\tif (recursionStack.has(root)) {\n\t\t// Found a cycle! Return the path from the cycle start to root\n\t\tconst cycleStart = path.indexOf(root)\n\t\treturn path.slice(cycleStart).concat([root])\n\t}\n\n\tif (visited.has(root)) {\n\t\treturn []\n\t}\n\n\tvisited.add(root)\n\trecursionStack.add(root)\n\tpath.push(root)\n\n\t// Follow edges to effects in the batch\n\t// Use direct edges (effectTriggers) for cycle detection\n\tconst triggers = effectTriggers.get(root)\n\tif (triggers) {\n\t\tfor (const targetRoot of triggers) {\n\t\t\tif (batchQueue.all.has(targetRoot)) {\n\t\t\t\tconst cycle = findCycle(targetRoot, visited, recursionStack, path, batchQueue)\n\t\t\t\tif (cycle.length > 0) {\n\t\t\t\t\treturn cycle\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpath.pop()\n\trecursionStack.delete(root)\n\treturn []\n}\n\n/**\n * Executes the next effect in dependency order (using cached in-degrees)\n * Finds an effect with in-degree 0 and executes it\n * @returns The return value of the executed effect, or null if batch is complete\n */\nfunction executeNext(effectuatedRoots: Function[]): any {\n\t// Find an effect with in-degree 0 using cached values\n\tlet nextEffect: ScopedCallback | null = null\n\tlet nextRoot: Function | null = null\n\n\tif (options.cycleHandling === 'none') {\n\t\t// In flat mode, we just take the first effect in the queue (FIFO)\n\t\tconst first = batchQueue!.all.entries().next().value\n\t\tif (first) {\n\t\t\t;[nextRoot, nextEffect] = first\n\t\t}\n\t} else {\n\t\t// Find an effect with in-degree 0 (no dependencies in batch that still need execution)\n\t\t// Using cached in-degrees for O(n) lookup instead of O(n²)\n\t\tfor (const [root, effect] of batchQueue!.all) {\n\t\t\tconst inDegree = batchQueue!.inDegrees.get(root) ?? 0\n\t\t\tif (inDegree === 0) {\n\t\t\t\tnextEffect = effect\n\t\t\t\tnextRoot = root\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!nextEffect) {\n\t\t// No effect with in-degree 0 - there must be a cycle\n\t\t// If all effects have dependencies, it means there's a circular dependency\n\t\tif (batchQueue!.all.size > 0) {\n\t\t\tlet cycle = getCyclePath(batchQueue!)\n\t\t\t// If we couldn't find a cycle path using direct edges, try using closures\n\t\t\t// (transitive relationships) - if all effects have in-degree > 0, there must be a cycle\n\t\t\tif (cycle.length === 0) {\n\t\t\t\t// Try to find a cycle using consequencesClosure (transitive relationships)\n\t\t\t\t// Note: Self-loops are ignored - we only look for cycles between different effects\n\t\t\t\tfor (const [root] of batchQueue!.all) {\n\t\t\t\t\tconst consequences = consequencesClosure.get(root)\n\t\t\t\t\tif (consequences) {\n\t\t\t\t\t\t// Check if any consequence in the batch also has root as a consequence\n\t\t\t\t\t\tfor (const consequence of consequences) {\n\t\t\t\t\t\t\t// Skip self-loops - they are ignored\n\t\t\t\t\t\t\tif (consequence === root) continue\n\t\t\t\t\t\t\tif (batchQueue!.all.has(consequence)) {\n\t\t\t\t\t\t\t\tconst consequenceConsequences = consequencesClosure.get(consequence)\n\t\t\t\t\t\t\t\tif (consequenceConsequences?.has(root)) {\n\t\t\t\t\t\t\t\t\t// Found cycle: root -> consequence -> root\n\t\t\t\t\t\t\t\t\tcycle = [root, consequence, root]\n\t\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cycle.length > 0) break\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst cycleMessage =\n\t\t\t\tcycle.length > 0\n\t\t\t\t\t? `Cycle detected: ${cycle.map((r) => r.name || '<anonymous>').join(' → ')}`\n\t\t\t\t\t: 'Cycle detected in effect batch - all effects have dependencies that prevent execution'\n\n\t\t\tconst cycleHandling = options.cycleHandling\n\t\t\tswitch (cycleHandling) {\n\t\t\t\tcase 'throw':\n\t\t\t\t\tthrow new ReactiveError(`[reactive] ${cycleMessage}`)\n\t\t\t\tcase 'warn': {\n\t\t\t\t\toptions.warn(`[reactive] ${cycleMessage}`)\n\t\t\t\t\t// Break the cycle by executing one effect anyway\n\t\t\t\t\tconst firstEffect = batchQueue!.all.values().next().value\n\t\t\t\t\tif (firstEffect) {\n\t\t\t\t\t\tconst firstRoot = getRoot(firstEffect)\n\t\t\t\t\t\tbatchQueue!.all.delete(firstRoot)\n\t\t\t\t\t\tbatchQueue!.inDegrees.delete(firstRoot)\n\t\t\t\t\t\treturn firstEffect()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'break': {\n\t\t\t\t\t// Silently break cycle\n\t\t\t\t\tconst firstEffect2 = batchQueue!.all.values().next().value\n\t\t\t\t\tif (firstEffect2) {\n\t\t\t\t\t\tconst firstRoot2 = getRoot(firstEffect2)\n\t\t\t\t\t\tbatchQueue!.all.delete(firstRoot2)\n\t\t\t\t\t\tbatchQueue!.inDegrees.delete(firstRoot2)\n\t\t\t\t\t\treturn firstEffect2()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null // Batch complete\n\t}\n\n\teffectuatedRoots.push(getRoot(nextEffect))\n\t// Execute the effect\n\tconst result = nextEffect()\n\n\t// Remove from batch and update in-degrees of dependents\n\tbatchQueue!.all.delete(nextRoot!)\n\tbatchQueue!.inDegrees.delete(nextRoot!)\n\tdecrementInDegreesForExecuted(batchQueue!, nextRoot!)\n\n\treturn result\n}\n\n// Track which sub-effects have been executed to prevent infinite loops\n// These are all the effects triggered under `activeEffect` and all their sub-effects\nexport function batch(effect: ScopedCallback | ScopedCallback[], immediate?: 'immediate') {\n\tif (!Array.isArray(effect)) effect = [effect]\n\tconst roots = effect.map(getRoot)\n\n\tif (batchQueue) {\n\t\t// Nested batch - add to existing\n\t\toptions?.chain(roots, getRoot(getActiveEffect()))\n\t\tconst caller = getActiveEffect()\n\t\tfor (let i = 0; i < effect.length; i++)\n\t\t\taddToBatch(effect[i], caller, immediate === 'immediate')\n\t\tif (immediate) {\n\t\t\tconst firstReturn: { value?: any } = {}\n\t\t\t// Execute immediately (before batch returns)\n\t\t\tfor (let i = 0; i < effect.length; i++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst rv = effect[i]()\n\t\t\t\t\tif (rv !== undefined && !('value' in firstReturn)) firstReturn.value = rv\n\t\t\t\t} finally {\n\t\t\t\t\tconst root = getRoot(effect[i])\n\t\t\t\t\tbatchQueue.all.delete(root)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn firstReturn.value\n\t\t}\n\t\t// Otherwise, effects will be picked up in next executeNext() call\n\t} else {\n\t\t// New batch - initialize\n\t\tif (!activationRegistry) activationRegistry = new Map()\n\t\telse throw new Error('Batch already in progress')\n\t\toptions.beginChain(roots)\n\t\tbatchQueue = {\n\t\t\tall: new Map(),\n\t\t\tinDegrees: new Map(),\n\t\t}\n\n\t\tconst caller = getActiveEffect()\n\t\tconst effectuatedRoots: ScopedCallback[] = []\n\t\tconst firstReturn: { value?: any } = {}\n\n\t\ttry {\n\t\t\tif (immediate) {\n\t\t\t\t// Execute initial effects in providing order\n\t\t\t\tfor (let i = 0; i < effect.length; i++) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst rv = effect[i]()\n\t\t\t\t\t\tif (rv !== undefined && !('value' in firstReturn)) firstReturn.value = rv\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tbatchQueue.all.delete(getRoot(effect[i]))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Add initial effects to batch and compute dependencies\n\t\t\t\tfor (let i = 0; i < effect.length; i++) addToBatch(effect[i], caller, false)\n\t\t\t\tcomputeAllInDegrees(batchQueue)\n\t\t\t}\n\n\t\t\t// Processing loop for all triggered effects and cleanups\n\t\t\twhile (batchQueue.all.size > 0 || batchCleanups.size > 0) {\n\t\t\t\tif (batchQueue.all.size > 0) {\n\t\t\t\t\tif (effectuatedRoots.length > options.maxEffectChain) {\n\t\t\t\t\t\tconst cycle = findCycleInChain(effectuatedRoots as any)\n\t\t\t\t\t\tconst trace = formatRoots(effectuatedRoots as any)\n\t\t\t\t\t\tconst message = cycle\n\t\t\t\t\t\t\t? `Max effect chain reached (cycle detected: ${formatRoots(cycle)})`\n\t\t\t\t\t\t\t: `Max effect chain reached (trace: ${trace})`\n\n\t\t\t\t\t\tconst queuedRoots = batchQueue ? Array.from(batchQueue.all.keys()) : []\n\t\t\t\t\t\tconst queued = queuedRoots.map((r) => r.name || '<anonymous>')\n\t\t\t\t\t\tconst debugInfo = {\n\t\t\t\t\t\t\tcode: ReactiveErrorCode.MaxDepthExceeded,\n\t\t\t\t\t\t\teffectuatedRoots,\n\t\t\t\t\t\t\tcycle,\n\t\t\t\t\t\t\ttrace,\n\t\t\t\t\t\t\tmaxEffectChain: options.maxEffectChain,\n\t\t\t\t\t\t\tqueued: queued.slice(0, 50),\n\t\t\t\t\t\t\tqueuedCount: queued.length,\n\t\t\t\t\t\t\t// Try to get causation for the last effect\n\t\t\t\t\t\t\tcausalChain:\n\t\t\t\t\t\t\t\teffectuatedRoots.length > 0\n\t\t\t\t\t\t\t\t\t? getTriggerChain(\n\t\t\t\t\t\t\t\t\t\t\tbatchQueue.all.get(effectuatedRoots[effectuatedRoots.length - 1])!\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t}\n\t\t\t\t\t\tswitch (options.maxEffectReaction) {\n\t\t\t\t\t\t\tcase 'throw':\n\t\t\t\t\t\t\t\tthrow new ReactiveError(`[reactive] ${message}`, debugInfo)\n\t\t\t\t\t\t\tcase 'debug':\n\t\t\t\t\t\t\t\t// biome-ignore lint/suspicious/noDebugger: This is the whole point here\n\t\t\t\t\t\t\t\tdebugger\n\t\t\t\t\t\t\t\tthrow new ReactiveError(`[reactive] ${message}`, debugInfo)\n\t\t\t\t\t\t\tcase 'warn':\n\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t`[reactive] ${message} (queued: ${queued.slice(0, 10).join(', ')}${queued.length > 10 ? ', …' : ''})`\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst rv = executeNext(effectuatedRoots)\n\t\t\t\t\tif (rv !== undefined && !('value' in firstReturn)) firstReturn.value = rv\n\t\t\t\t} else {\n\t\t\t\t\t// Process cleanups. If they trigger more effects, they will be caught in the next iteration.\n\t\t\t\t\tconst cleanups = Array.from(batchCleanups)\n\t\t\t\t\tbatchCleanups.clear()\n\t\t\t\t\tfor (const cleanup of cleanups) cleanup()\n\n\t\t\t\t\t// In immediate mode, we traditionally don't process recursive effects from cleanups.\n\t\t\t\t\t// If we want to keep that behavior: if (immediate) break\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn firstReturn.value\n\t\t} catch (error) {\n\t\t\tthrow error instanceof ReactiveError\n\t\t\t\t? error\n\t\t\t\t: new ReactiveError('Effects are broken', { code: ReactiveErrorCode.BrokenEffects, cause: error })\n\t\t} finally {\n\t\t\tactivationRegistry = undefined\n\t\t\tbatchQueue = undefined\n\t\t\toptions.endChain()\n\t\t}\n\t}\n}\n\n// Inject batch function to allow atomic game loops in requestAnimationFrame/setTimeout/...\n// TODO: perhaps introduce somewhere a way to wrap async functions - find out if it's necessary\n// wrapAsync(fn=> batch(fn, 'immediate'))\n\n/**\n * Decorator that makes methods atomic - batches all effects triggered within the method\n */\nexport const atomic = decorator({\n\tmethod(original) {\n\t\treturn function (this: any, ...args: any[]) {\n\t\t\tconst atomicEffect = () => original.apply(this, args)\n\t\t\t// Debug: helpful to have a name\n\t\t\tObject.defineProperty(atomicEffect, 'name', { value: `atomic(${original.name})` })\n\t\t\treturn batch(atomicEffect, 'immediate')\n\t\t}\n\t},\n\tdefault<Args extends any[], Return>(\n\t\toriginal: (...args: Args) => Return\n\t): (...args: Args) => Return {\n\t\treturn function (this: any, ...args: Args) {\n\t\t\tconst atomicEffect = () => original.apply(this, args)\n\t\t\t// Debug: helpful to have a name\n\t\t\tObject.defineProperty(atomicEffect, 'name', { value: `atomic(${original.name})` })\n\t\t\treturn batch(atomicEffect, 'immediate')\n\t\t}\n\t},\n})\n\nconst fr = new FinalizationRegistry<() => void>((f) => f())\n\n/**\n * @param fn - The effect function to run - provides the cleaner\n * @returns The cleanup function\n */\n/**\n * Creates a reactive effect that automatically re-runs when dependencies change\n * @param fn - The effect function that provides dependencies and may return a cleanup function or Promise\n * @param options - Options for effect execution\n * @returns A cleanup function to stop the effect\n */\nexport function effect(\n\t//biome-ignore lint/suspicious/noConfusingVoidType: We have to\n\tfn: (access: DependencyAccess) => ScopedCallback | undefined | void | Promise<any>,\n\teffectOptions?: EffectOptions\n): ScopedCallback & {\n\t[stopped]: boolean\n\t[cleanupSymbol]: () => void\n} {\n\n\t// Use per-effect asyncMode or fall back to global option\n\tconst asyncMode = effectOptions?.asyncMode ?? options.asyncMode ?? 'cancel'\n\tif (options.introspection.enableHistory) {\n\t\tconst stack = new Error().stack\n\t\tif (stack) {\n\t\t\t// Clean up the stack trace to remove internal frames\n\t\t\tconst cleanStack = stack.split('\\n').slice(2).join('\\n')\n\t\t\teffectCreationStacks.set(getRoot(fn), cleanStack)\n\t\t}\n\t}\n\tlet cleanup: (() => void) | null = null\n\tconst tracked = effectHistory.present.with(runEffect, ()=> effectAggregator.zoned)\n\tconst ascend = effectHistory.zoned\n\t//const parent = effectHistory.present.active // TODO: Double-check parenting (untracked -> stop children) - use case or untracked(effect)\n\tlet parent = effectHistory.present.active\n\t/*if (!parent) {\n\t\tfor (const h of effectHistory.active.history) parent = h\n\t}*/\n\tlet effectStopped = false\n\tlet hasReacted = false\n\tlet runningPromise: Promise<any> | null = null\n\tlet cancelPrevious: (() => void) | null = null\n\n\tfunction runEffect() {\n\t\t// Clear previous dependencies\n\t\tif (cleanup) {\n\t\t\tconst prevCleanup = cleanup\n\t\t\tcleanup = null\n\t\t\tuntracked(() => prevCleanup())\n\t\t}\n\n\t\t// Handle async modes when effect is retriggered\n\t\tif (runningPromise) {\n\t\t\tif (asyncMode === 'cancel' && cancelPrevious) {\n\t\t\t\t// Cancel previous execution\n\t\t\t\tcancelPrevious()\n\t\t\t\tcancelPrevious = null\n\t\t\t\trunningPromise = null\n\t\t\t} else if (asyncMode === 'ignore') {\n\t\t\t\t// Ignore new execution while async work is running\n\t\t\t\treturn\n\t\t\t}\n\t\t\t// Note: 'queue' mode not yet implemented\n\t\t}\n\n\t\t// The effect has been stopped after having been planned\n\t\tif (effectStopped) return\n\n\t\toptions.enter(getRoot(fn))\n\t\tlet reactionCleanup: ScopedCallback | undefined\n\t\tlet result: any\n\t\ttry {\n\t\t\tresult = tracked(() => fn({ tracked, ascend, reaction: hasReacted }))\n\t\t\tif (\n\t\t\t\tresult &&\n\t\t\t\ttypeof result !== 'function' &&\n\t\t\t\t(typeof result !== 'object' || !('then' in result))\n\t\t\t)\n\t\t\t\tthrow new ReactiveError(`[reactive] Effect returned a non-function value: ${result}`)\n\t\t\t// Check if result is a Promise (async effect)\n\t\t\tif (result && typeof result === 'object' && typeof result.then === 'function') {\n\t\t\t\tconst originalPromise = result as Promise<any>\n\n\t\t\t\t// Create a cancellation promise that we can reject\n\t\t\t\tlet cancelReject: ((reason: any) => void) | null = null\n\t\t\t\tconst cancelPromise = new Promise<never>((_, reject) => {\n\t\t\t\t\tcancelReject = reject\n\t\t\t\t})\n\n\t\t\t\tconst cancelError = new ReactiveError('[reactive] Effect canceled due to dependency change')\n\n\t\t\t\t// Race between the actual promise and cancellation\n\t\t\t\t// If canceled, the race rejects, which will propagate through any promise chain\n\t\t\t\trunningPromise = Promise.race([originalPromise, cancelPromise])\n\n\t\t\t\t// Store the cancellation function\n\t\t\t\tcancelPrevious = () => {\n\t\t\t\t\tif (cancelReject) {\n\t\t\t\t\t\tcancelReject(cancelError)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Wrap the original promise chain so cancellation propagates\n\t\t\t\t// This ensures that when we cancel, the original promise's .catch() handlers are triggered\n\t\t\t\t// We do this by rejecting the race promise, which makes the original promise chain see the rejection\n\t\t\t\t// through the zone-wrapped .then()/.catch() handlers\n\t\t\t} else {\n\t\t\t\t// Synchronous result - treat as cleanup function\n\t\t\t\treactionCleanup = result as undefined | ScopedCallback\n\t\t\t}\n\t\t} finally {\n\t\t\thasReacted = true\n\t\t\toptions.leave(fn)\n\t\t}\n\n\t\t// Create cleanup function for next run\n\t\tcleanup = () => {\n\t\t\tcleanup = null\n\t\t\treactionCleanup?.()\n\t\t\t// Remove this effect from all reactive objects it's watching\n\t\t\tconst effectObjects = effectToReactiveObjects.get(runEffect)\n\t\t\tif (effectObjects) {\n\t\t\t\tfor (const reactiveObj of effectObjects) {\n\t\t\t\t\tconst objectWatchers = watchers.get(reactiveObj)\n\t\t\t\t\tif (objectWatchers) {\n\t\t\t\t\t\tfor (const [prop, deps] of objectWatchers.entries()) {\n\t\t\t\t\t\t\tdeps.delete(runEffect)\n\t\t\t\t\t\t\tif (deps.size === 0) {\n\t\t\t\t\t\t\t\tobjectWatchers.delete(prop)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (objectWatchers.size === 0) {\n\t\t\t\t\t\t\twatchers.delete(reactiveObj)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\teffectToReactiveObjects.delete(runEffect)\n\t\t\t}\n\t\t\t// Invoke all child stops (recursive via subEffectCleanup calling its own mainCleanup)\n\t\t\tconst children = effectChildren.get(runEffect)\n\t\t\tif (children) {\n\t\t\t\tfor (const childCleanup of children) childCleanup()\n\t\t\t\teffectChildren.delete(runEffect)\n\t\t\t}\n\t\t}\n\t}\n\t// Mark the runEffect callback with the original function as its root\n\tmarkWithRoot(runEffect, fn)\n\tfunction augmentedRv(rv: ScopedCallback) {\n\t\treturn Object.defineProperties(rv, {\n\t\t\t[stopped]: {\n\t\t\t\tget() {\n\t\t\t\t\treturn effectStopped\n\t\t\t\t},\n\t\t\t},\n\t\t\t[cleanupSymbol]: {\n\t\t\t\tvalue: () => {\n\t\t\t\t\tif (cleanup) {\n\t\t\t\t\t\tconst prevCleanup = cleanup\n\t\t\t\t\t\tcleanup = null\n\t\t\t\t\t\tuntracked(() => prevCleanup())\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t}) as ScopedCallback & {\n\t\t\t[stopped]: boolean\n\t\t\t[cleanupSymbol]: () => void\n\t\t}\n\t}\n\taugmentedRv(runEffect)\n\n\t// Register strict mode if enabled\n\tif (effectOptions?.opaque) {\n\t\topaqueEffects.add(runEffect)\n\t}\n\n\tif (isDevtoolsEnabled()) {\n\t\tregisterEffectForDebug(runEffect)\n\t}\n\n\tbatch(runEffect, 'immediate')\n\n\t// Store parent relationship for hierarchy traversal\n\teffectParent.set(runEffect, parent)\n\t// Only ROOT effects are registered for GC cleanup and zone tracking\n\tconst isRootEffect = !parent\n\n\tconst stopEffect = (): void => {\n\t\tif (effectStopped) return\n\t\teffectStopped = true\n\t\t// Cancel any running async work\n\t\tif (cancelPrevious) {\n\t\t\tcancelPrevious()\n\t\t\tcancelPrevious = null\n\t\t\trunningPromise = null\n\t\t}\n\t\tcleanup?.()\n\t\t// Clean up dependency graph edges\n\t\tcleanupEffectFromGraph(runEffect)\n\t\tfr.unregister(stopEffect)\n\t}\n\tif (isRootEffect) {\n\t\tconst callIfCollected = augmentedRv(() => stopEffect())\n\t\tfr.register(\n\t\t\tcallIfCollected,\n\t\t\t() => {\n\t\t\t\tstopEffect()\n\t\t\t\toptions.garbageCollected(fn)\n\t\t\t},\n\t\t\tstopEffect\n\t\t)\n\t\treturn callIfCollected\n\t}\n\t// Register this effect to be stopped when the parent effect is cleaned up\n\tlet children = effectChildren.get(parent)\n\tif (!children) {\n\t\tchildren = new Set()\n\t\teffectChildren.set(parent, children)\n\t}\n\tconst subEffectCleanup = augmentedRv(() => {\n\t\tchildren.delete(subEffectCleanup)\n\t\tif (children.size === 0) {\n\t\t\teffectChildren.delete(parent)\n\t\t}\n\t\t// Execute this child effect cleanup (which triggers its own mainCleanup)\n\t\tstopEffect()\n\t})\n\tchildren.add(subEffectCleanup)\n\n\treturn subEffectCleanup\n}\n\n/**\n * Executes a function without tracking dependencies but maintains parent cleanup relationship\n * Effects created inside will still be cleaned up when the parent effect is destroyed\n * @param fn - The function to execute\n */\nexport function untracked<T>(fn: () => T): T {\n\treturn effectHistory.present.root(fn)\n}\n\n/**\n * Executes a function from a virgin/root context - no parent effect, no tracking\n * Creates completely independent effects that won't be cleaned up by any parent\n * @param fn - The function to execute\n */\nexport function root<T>(fn: () => T): T {\n\treturn effectHistory.root(fn)\n}\n\nexport { effectTrackers }\n\n/**\n * Creates a bidirectional binding between a reactive value and a non-reactive external value\n * Prevents infinite loops by automatically suppressing circular notifications\n *\n * @param received - Function called when the reactive value changes (external setter)\n * @param get - Getter for the reactive value OR an object with `{ get, set }` properties\n * @param set - Setter for the reactive value (required if `get` is a function)\n * @returns A function to manually provide updates from the external side\n *\n * @example\n * ```typescript\n * const model = reactive({ value: '' })\n * const input = { value: '' }\n *\n * // Bidirectional binding\n * const provide = biDi(\n * (v) => input.value = v, // external setter\n * () => model.value, // reactive getter\n * (v) => model.value = v // reactive setter\n * )\n *\n * // External notification (e.g., from input event)\n * provide('new value') // Updates model.value, doesn't trigger circular loop\n * ```\n *\n * @example Using object syntax\n * ```typescript\n * const provide = biDi(\n * (v) => setHTMLValue(v),\n * { get: () => reactiveObj.value, set: (v) => reactiveObj.value = v }\n * )\n * ```\n */\nexport function biDi<T>(\n\treceived: (value: T) => void,\n\tvalue: { get: () => T; set: (value: T) => void }\n): (value: T) => void\nexport function biDi<T>(\n\treceived: (value: T) => void,\n\tget: () => T,\n\tset: (value: T) => void\n): (value: T) => void\nexport function biDi<T>(\n\treceived: (value: T) => void,\n\tget: (() => T) | { get: () => T; set: (value: T) => void },\n\tset?: (value: T) => void\n): (value: T) => void {\n\tif (typeof get !== 'function') {\n\t\tset = get.set\n\t\tget = get.get\n\t}\n\tlet programatticallySetValue: any = Symbol()\n\teffect(\n\t\tmarkWithRoot(() => {\n\t\t\tconst newValue = get()\n\t\t\tif (unwrap(newValue) !== programatticallySetValue) received(newValue)\n\t\t}, received)\n\t)\n\treturn set\n\t\t? atomic((value: T) => {\n\t\t\t\tprogramatticallySetValue = unwrap(value)\n\t\t\t\tset(value)\n\t\t\t})\n\t\t: () => {}\n}\n","import { batch } from './effects'\nimport type { Evolution, ScopedCallback } from './types'\n\n// Track which objects contain which other objects (back-references)\nexport const objectParents = new WeakMap<object, Set<{ parent: object; prop: PropertyKey }>>()\n\n// Track which objects have deep watchers\nexport const objectsWithDeepWatchers = new WeakSet<object>()\n\n// Track deep watchers per object\nexport const deepWatchers = new WeakMap<object, Set<ScopedCallback>>()\n\n// Track which effects are doing deep watching\nexport const effectToDeepWatchedObjects = new WeakMap<ScopedCallback, Set<object>>()\n\n/**\n * Add a back-reference from child to parent\n */\nexport function addBackReference(child: object, parent: object, prop: any) {\n\tlet parents = objectParents.get(child)\n\tif (!parents) {\n\t\tparents = new Set()\n\t\tobjectParents.set(child, parents)\n\t}\n\tparents.add({ parent, prop })\n}\n\n/**\n * Remove a back-reference from child to parent\n */\nexport function removeBackReference(child: object, parent: object, prop: any) {\n\tconst parents = objectParents.get(child)\n\tif (parents) {\n\t\tfor (const entry of parents) {\n\t\t\tif (entry.parent === parent && entry.prop === prop) {\n\t\t\t\tparents.delete(entry)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (parents.size === 0) {\n\t\t\tobjectParents.delete(child)\n\t\t}\n\t}\n}\n\n/**\n * Check if an object needs back-references (has deep watchers or parents with deep watchers)\n */\nexport function needsBackReferences(obj: object): boolean {\n\t// Fast path: check if object itself has deep watchers\n\tif (objectsWithDeepWatchers.has(obj)) return true\n\t// Slow path: check if any parent has deep watchers (recursive)\n\treturn hasParentWithDeepWatchers(obj)\n}\n\n/**\n * Bubble up changes through the back-reference chain\n */\nexport function bubbleUpChange(changedObject: object, evolution: Evolution) {\n\tconst parents = objectParents.get(changedObject)\n\tif (!parents) return\n\n\tfor (const { parent } of parents) {\n\t\t// Trigger deep watchers on parent\n\t\tconst parentDeepWatchers = deepWatchers.get(parent)\n\t\tif (parentDeepWatchers) for (const watcher of parentDeepWatchers) batch(watcher)\n\n\t\t// Continue bubbling up\n\t\tbubbleUpChange(parent, evolution)\n\t}\n}\n\nfunction hasParentWithDeepWatchers(obj: object): boolean {\n\tconst parents = objectParents.get(obj)\n\tif (!parents) return false\n\n\tfor (const { parent } of parents) {\n\t\tif (objectsWithDeepWatchers.has(parent)) return true\n\t\tif (hasParentWithDeepWatchers(parent)) return true\n\t}\n\treturn false\n}\n","import { recordTriggerLink } from './debug'\nimport { bubbleUpChange, objectsWithDeepWatchers } from './deep-watch-state'\nimport { getActiveEffect, isRunning } from './effect-context'\nimport { batch, effectTrackers, hasBatched, opaqueEffects, recordActivation } from './effects'\nimport { unwrap } from './proxy-state'\nimport { watchers } from './registry'\nimport { allProps, type Evolution, options, type ScopedCallback, type State } from './types'\n\nconst states = new WeakMap<object, State>()\n\nexport function addState(obj: any, evolution: Evolution) {\n\tobj = unwrap(obj)\n\tconst next = {}\n\tconst state = getState(obj)\n\tif (state) Object.assign(state, { evolution, next })\n\tstates.set(obj, next)\n}\n\n/**\n * Gets the current state of a reactive object for evolution tracking\n * @param obj - The reactive object\n * @returns The current state object\n */\nexport function getState(obj: any) {\n\tobj = unwrap(obj)\n\tlet state = states.get(obj)\n\tif (!state) {\n\t\tstate = {}\n\t\tstates.set(obj, state)\n\t}\n\treturn state\n}\n\nexport function collectEffects(\n\tobj: any,\n\tevolution: Evolution,\n\teffects: Set<ScopedCallback>,\n\tobjectWatchers: Map<any, Set<ScopedCallback>>,\n\t...keyChains: Iterable<any>[]\n) {\n\tconst sourceEffect = getActiveEffect()\n\tfor (const keys of keyChains)\n\t\tfor (const key of keys) {\n\t\t\tconst deps = objectWatchers.get(key)\n\t\t\tif (deps)\n\t\t\t\tfor (const effect of deps) {\n\t\t\t\t\tconst runningChain = isRunning(effect)\n\t\t\t\t\tif (runningChain) {\n\t\t\t\t\t\toptions.skipRunningEffect(effect)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (!effects.has(effect)) {\n\t\t\t\t\t\teffects.add(effect)\n\t\t\t\t\t\tif (!hasBatched(effect)) recordActivation(effect, obj, evolution, key)\n\t\t\t\t\t}\n\t\t\t\t\tconst trackers = effectTrackers.get(effect)\n\t\t\t\t\trecordTriggerLink(sourceEffect, effect, obj, key, evolution)\n\t\t\t\t\tif (trackers) {\n\t\t\t\t\t\tfor (const tracker of trackers) tracker(obj, evolution, key)\n\t\t\t\t\t\ttrackers.delete(effect)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n}\n\n/**\n * Triggers effects for a single property change\n * @param obj - The object that changed\n * @param evolution - The type of change\n * @param prop - The property that changed\n */\nexport function touched1(obj: any, evolution: Evolution, prop: any) {\n\ttouched(obj, evolution, [prop])\n}\n\n/**\n * Triggers effects for property changes\n * @param obj - The object that changed\n * @param evolution - The type of change\n * @param props - The properties that changed\n */\nexport function touched(obj: any, evolution: Evolution, props?: Iterable<any>) {\n\tobj = unwrap(obj)\n\taddState(obj, evolution)\n\tconst objectWatchers = watchers.get(obj)\n\tif (objectWatchers) {\n\t\t// Note: we have to collect effects to remove duplicates in the specific case when no batch is running\n\t\tconst effects = new Set<ScopedCallback>()\n\t\tif (props) collectEffects(obj, evolution, effects, objectWatchers, [allProps], props)\n\t\telse collectEffects(obj, evolution, effects, objectWatchers, objectWatchers.keys())\n\t\toptions.touched(obj, evolution, props as any[] | undefined, effects)\n\t\tbatch(Array.from(effects))\n\t}\n\n\t// Bubble up changes if this object has deep watchers\n\tif (objectsWithDeepWatchers.has(obj)) {\n\t\tbubbleUpChange(obj, evolution)\n\t}\n}\n\n/**\n * Triggers only opaque effects for property changes\n * Used by deep-touch to ensure opaque listeners are notified even when deep optimization is active\n */\nexport function touchedOpaque(obj: any, evolution: Evolution, prop: any) {\n\tobj = unwrap(obj)\n\tconst objectWatchers = watchers.get(obj)\n\tif (!objectWatchers) return\n\n\tconst deps = objectWatchers.get(prop)\n\tif (!deps) return\n\n\tconst effects = new Set<ScopedCallback>()\n\tconst sourceEffect = getActiveEffect()\n\n\tfor (const effect of deps) {\n\t\tif (!opaqueEffects.has(effect)) continue\n\n\t\tconst runningChain = isRunning(effect)\n\t\tif (runningChain) {\n\t\t\toptions.skipRunningEffect(effect)\n\t\t\tcontinue\n\t\t}\n\t\teffects.add(effect)\n\t\trecordActivation(effect, obj, evolution, prop)\n\t\tconst trackers = effectTrackers.get(effect)\n\t\trecordTriggerLink(sourceEffect, effect, obj, prop, evolution)\n\t\tif (trackers) {\n\t\t\tfor (const tracker of trackers) tracker(obj, evolution, prop)\n\t\t\ttrackers.delete(effect)\n\t\t}\n\t}\n\n\tif (effects.size > 0) {\n\t\toptions.touched(obj, evolution, [prop], effects)\n\t\tbatch(Array.from(effects))\n\t}\n}\n","import { nativeReactive, nonReactiveMark } from './types'\n\nexport const nonReactiveObjects = new WeakSet<object>()\nexport const immutables = new Set<(tested: any) => boolean>()\nexport const absent = Symbol('absent')\n\nfunction markNonReactive<T extends object[]>(...obj: T): T[0] {\n\tfor (const o of obj) {\n\t\ttry {\n\t\t\tObject.defineProperty(o, nonReactiveMark, {\n\t\t\t\tvalue: true,\n\t\t\t\twritable: false,\n\t\t\t\tenumerable: false,\n\t\t\t\tconfigurable: false,\n\t\t\t})\n\t\t} catch {}\n\t\tif (!(nonReactiveMark in (o as object))) nonReactiveObjects.add(o as object)\n\t}\n\treturn obj[0]\n}\n\nexport function nonReactiveClass<T extends (new (...args: any[]) => any)[]>(...cls: T): T[0] {\n\tfor (const c of cls) if (c) (c.prototype as any)[nonReactiveMark] = true\n\treturn cls[0]\n}\n\nexport function isNonReactive(obj: any): boolean {\n\tif (obj === null || typeof obj !== 'object') return true\n\tif (nonReactiveObjects.has(obj)) return true\n\tif ((obj as any)[nonReactiveMark]) return true\n\tfor (const fn of immutables) if (fn(obj)) return true\n\treturn false\n}\n\nexport function registerNativeReactivity(\n\toriginalClass: new (...args: any[]) => any,\n\treactiveClass: new (...args: any[]) => any\n) {\n\toriginalClass.prototype[nativeReactive] = reactiveClass\n\tnonReactiveClass(reactiveClass)\n}\n\nnonReactiveClass(Date, RegExp, Error, Promise, Function)\nif (typeof window !== 'undefined') {\n\tmarkNonReactive(window, document)\n\tnonReactiveClass(Node, Element, HTMLElement, EventTarget)\n}\n\nexport { markNonReactive as nonReactive }\n","import { addState, collectEffects, touched1, touchedOpaque } from './change'\nimport { bubbleUpChange, objectsWithDeepWatchers } from './deep-watch-state'\nimport { batch } from './effects'\nimport { isNonReactive } from './non-reactive-state'\nimport { unwrap } from './proxy-state'\nimport { effectParent, watchers } from './registry'\nimport { allProps, type Evolution, options, type ScopedCallback } from './types'\n\nfunction isObject(value: any): value is object {\n\treturn typeof value === 'object' && value !== null\n}\n\nfunction isObjectLike(value: unknown): value is object {\n\treturn isObject(value)\n}\n\nfunction getPrototypeToken(value: any): object | null | undefined {\n\tif (!isObjectLike(value)) return undefined\n\tif (Array.isArray(value)) return Array.prototype\n\ttry {\n\t\treturn value.constructor\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\nexport function shouldRecurseTouch(oldValue: any, newValue: any): boolean {\n\tif (oldValue === newValue) return false\n\tif (!isObjectLike(oldValue) || !isObjectLike(newValue)) return false\n\tif (isNonReactive(oldValue) || isNonReactive(newValue)) return false\n\treturn getPrototypeToken(oldValue) === getPrototypeToken(newValue)\n}\n\n/**\n * Centralized function to handle property change notifications with optional recursive touch\n * @param targetObj - The object whose property changed\n * @param prop - The property that changed\n * @param oldValue - The old value (before change)\n * @param newValue - The new value (after change)\n * @param hadProperty - Whether the property existed before (for add vs set)\n */\nexport function notifyPropertyChange(\n\ttargetObj: any,\n\tprop: any,\n\toldValue: any,\n\tnewValue: any,\n\thadProperty: boolean\n) {\n\tconst evolution: Evolution = { type: hadProperty ? 'set' : 'add', prop }\n\n\tif (\n\t\toptions.recursiveTouching &&\n\t\toldValue !== undefined &&\n\t\tshouldRecurseTouch(oldValue, newValue)\n\t) {\n\t\tconst unwrappedObj = unwrap(targetObj)\n\t\tconst origin = { obj: unwrappedObj, prop }\n\t\t// Deep touch: only notify nested property changes with origin filtering\n\t\t// Don't notify direct property change - the whole point is to avoid parent effects re-running\n\t\tdispatchNotifications(recursiveTouch(oldValue, newValue, new WeakMap(), [], origin))\n\n\t\t// Notify opaque listeners (like memoize) that always want to know about identity changes\n\t\ttouchedOpaque(targetObj, evolution, prop)\n\t} else {\n\t\ttouched1(targetObj, evolution, prop)\n\t}\n}\n\ntype VisitedPairs = WeakMap<object, WeakSet<object>>\ntype PendingNotification = {\n\ttarget: any\n\tevolution: Evolution\n\tprop: any\n\torigin?: { obj: object; prop: PropertyKey } // The property access that triggered this deep touch\n}\n\nfunction hasVisitedPair(visited: VisitedPairs, oldObj: object, newObj: object): boolean {\n\tlet mapped = visited.get(oldObj)\n\tif (!mapped) {\n\t\tmapped = new WeakSet<object>()\n\t\tvisited.set(oldObj, mapped)\n\t}\n\tif (mapped.has(newObj)) return true\n\tmapped.add(newObj)\n\treturn false\n}\n\nfunction collectObjectKeys(obj: any): Set<PropertyKey> {\n\tconst keys = new Set<PropertyKey>(Reflect.ownKeys(obj))\n\tlet proto = Object.getPrototypeOf(obj)\n\t// Continue walking while prototype exists and doesn't have its own constructor\n\t// This stops at Object.prototype (has own constructor) and class prototypes (have own constructor)\n\t// but continues for data prototypes (Object.create({}), Object.create(instance), etc.)\n\twhile (proto && !Object.hasOwn(proto, 'constructor')) {\n\t\tfor (const key of Reflect.ownKeys(proto)) keys.add(key)\n\t\tproto = Object.getPrototypeOf(proto)\n\t}\n\treturn keys\n}\n\nexport function recursiveTouch(\n\toldValue: any,\n\tnewValue: any,\n\tvisited: VisitedPairs = new WeakMap(),\n\tnotifications: PendingNotification[] = [],\n\torigin?: { obj: object; prop: PropertyKey }\n): PendingNotification[] {\n\tif (!shouldRecurseTouch(oldValue, newValue)) return notifications\n\tif (!isObjectLike(oldValue) || !isObjectLike(newValue)) return notifications\n\tif (hasVisitedPair(visited, oldValue, newValue)) return notifications\n\n\tif (Array.isArray(oldValue) && Array.isArray(newValue)) {\n\t\tdiffArrayElements(oldValue, newValue, visited, notifications, origin)\n\t\treturn notifications\n\t}\n\n\tdiffObjectProperties(oldValue, newValue, visited, notifications, origin)\n\treturn notifications\n}\n\nfunction diffArrayElements(\n\toldArray: any[] | readonly any[],\n\tnewArray: any[] | readonly any[],\n\t_visited: VisitedPairs,\n\tnotifications: PendingNotification[],\n\torigin?: { obj: object; prop: PropertyKey }\n) {\n\tconst local: PendingNotification[] = []\n\tconst oldLength = oldArray.length\n\tconst newLength = newArray.length\n\tconst max = Math.max(oldLength, newLength)\n\n\tfor (let index = 0; index < max; index++) {\n\t\tconst hasOld = index < oldLength\n\t\tconst hasNew = index < newLength\n\t\tif (hasOld && !hasNew) {\n\t\t\tlocal.push({ target: oldArray, evolution: { type: 'del', prop: index }, prop: index, origin })\n\t\t\tcontinue\n\t\t}\n\t\tif (!hasOld && hasNew) {\n\t\t\tlocal.push({ target: oldArray, evolution: { type: 'add', prop: index }, prop: index, origin })\n\t\t\tcontinue\n\t\t}\n\t\tif (!hasOld || !hasNew) continue\n\t\tconst oldEntry = unwrap(oldArray[index])\n\t\tconst newEntry = unwrap(newArray[index])\n\t\tif (!Object.is(oldEntry, newEntry)) {\n\t\t\tlocal.push({ target: oldArray, evolution: { type: 'set', prop: index }, prop: index, origin })\n\t\t}\n\t}\n\n\tif (oldLength !== newLength)\n\t\tlocal.push({\n\t\t\ttarget: oldArray,\n\t\t\tevolution: { type: 'set', prop: 'length' },\n\t\t\tprop: 'length',\n\t\t\torigin,\n\t\t})\n\n\tnotifications.push(...local)\n}\n\nfunction diffObjectProperties(\n\toldObj: any,\n\tnewObj: any,\n\tvisited: VisitedPairs,\n\tnotifications: PendingNotification[],\n\torigin?: { obj: object; prop: PropertyKey }\n) {\n\tconst oldKeys = collectObjectKeys(oldObj)\n\tconst newKeys = collectObjectKeys(newObj)\n\tconst local: PendingNotification[] = []\n\n\tfor (const key of oldKeys)\n\t\tif (!newKeys.has(key))\n\t\t\tlocal.push({ target: oldObj, evolution: { type: 'del', prop: key }, prop: key, origin })\n\n\tfor (const key of newKeys)\n\t\tif (!oldKeys.has(key))\n\t\t\tlocal.push({ target: oldObj, evolution: { type: 'add', prop: key }, prop: key, origin })\n\n\tfor (const key of newKeys) {\n\t\tif (!oldKeys.has(key)) continue\n\t\tconst oldEntry = unwrap((oldObj as any)[key])\n\t\tconst newEntry = unwrap((newObj as any)[key])\n\t\tif (shouldRecurseTouch(oldEntry, newEntry)) {\n\t\t\trecursiveTouch(oldEntry, newEntry, visited, notifications, origin)\n\t\t} else if (!Object.is(oldEntry, newEntry)) {\n\t\t\tlocal.push({ target: oldObj, evolution: { type: 'set', prop: key }, prop: key, origin })\n\t\t}\n\t}\n\n\tnotifications.push(...local)\n}\n\n/**\n * Checks if an effect or any of its ancestors is in the allowed set\n */\nfunction hasAncestorInSet(effect: ScopedCallback, allowedSet: Set<ScopedCallback>): boolean {\n\tlet current: ScopedCallback | undefined = effect\n\tconst visited = new WeakSet<ScopedCallback>()\n\twhile (current && !visited.has(current)) {\n\t\tvisited.add(current)\n\t\tif (allowedSet.has(current)) return true\n\t\tcurrent = effectParent.get(current)\n\t}\n\treturn false\n}\n\nexport function dispatchNotifications(notifications: PendingNotification[]) {\n\tif (!notifications.length) return\n\tconst combinedEffects = new Set<ScopedCallback>()\n\n\t// Extract origin from first notification (all should have the same origin from a single deep touch)\n\tconst origin = notifications[0]?.origin\n\tlet allowedEffects: Set<ScopedCallback> | undefined\n\n\t// If origin exists, compute allowed effects (those that depend on origin.obj[origin.prop])\n\tif (origin) {\n\t\tallowedEffects = new Set<ScopedCallback>()\n\t\tconst originWatchers = watchers.get(origin.obj)\n\t\tif (originWatchers) {\n\t\t\tconst originEffects = new Set<ScopedCallback>()\n\t\t\tcollectEffects(\n\t\t\t\torigin.obj,\n\t\t\t\t{ type: 'set', prop: origin.prop },\n\t\t\t\toriginEffects,\n\t\t\t\toriginWatchers,\n\t\t\t\t[allProps],\n\t\t\t\t[origin.prop]\n\t\t\t)\n\t\t\tfor (const effect of originEffects) allowedEffects.add(effect)\n\t\t}\n\t\t// If no allowed effects, skip all notifications (no one should be notified)\n\t\tif (allowedEffects.size === 0) return\n\t}\n\n\tfor (const { target, evolution, prop } of notifications) {\n\t\tif (!isObjectLike(target)) continue\n\t\tconst obj = unwrap(target)\n\t\taddState(obj, evolution)\n\t\tconst objectWatchers = watchers.get(obj)\n\t\tlet currentEffects: Set<ScopedCallback> | undefined\n\t\tconst propsArray = [prop]\n\t\tif (objectWatchers) {\n\t\t\tcurrentEffects = new Set<ScopedCallback>()\n\t\t\tcollectEffects(obj, evolution, currentEffects, objectWatchers, [allProps], propsArray)\n\n\t\t\t// Filter effects by ancestor chain if origin exists\n\t\t\t// Include effects that either directly depend on origin or have an ancestor that does\n\t\t\tif (origin && allowedEffects) {\n\t\t\t\tconst filteredEffects = new Set<ScopedCallback>()\n\t\t\t\tfor (const effect of currentEffects) {\n\t\t\t\t\t// Check if effect itself is allowed OR has an ancestor that is allowed\n\t\t\t\t\tif (allowedEffects.has(effect) || hasAncestorInSet(effect, allowedEffects)) {\n\t\t\t\t\t\tfilteredEffects.add(effect)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcurrentEffects = filteredEffects\n\t\t\t}\n\n\t\t\tfor (const effect of currentEffects) combinedEffects.add(effect)\n\t\t}\n\t\toptions.touched(obj, evolution, propsArray, currentEffects)\n\t\tif (objectsWithDeepWatchers.has(obj)) bubbleUpChange(obj, evolution)\n\t}\n\tif (combinedEffects.size) batch([...combinedEffects])\n}\n","import { getActiveEffect } from './effect-context'\nimport { unwrap } from './proxy-state'\nimport {\n\teffectToReactiveObjects,\n\twatchers,\n} from './registry'\nimport { allProps, type ScopedCallback } from './types'\n\n/**\n * Marks a property as a dependency of the current effect\n * @param obj - The object containing the property\n * @param prop - The property name (defaults to allProps)\n */\nexport function dependant(obj: any, prop: any = allProps) {\n\tobj = unwrap(obj)\n\tconst currentActiveEffect = getActiveEffect()\n\n\t// Early return if no active effect, tracking disabled, or invalid prop\n\tif (\n\t\t!currentActiveEffect ||\n\t\t(typeof prop === 'symbol' && prop !== allProps)\n\t)\n\t\treturn\n\n\tlet objectWatchers = watchers.get(obj)\n\tif (!objectWatchers) {\n\t\tobjectWatchers = new Map<PropertyKey, Set<ScopedCallback>>()\n\t\twatchers.set(obj, objectWatchers)\n\t}\n\tlet deps = objectWatchers.get(prop)\n\tif (!deps) {\n\t\tdeps = new Set<ScopedCallback>()\n\t\tobjectWatchers.set(prop, deps)\n\t}\n\tdeps.add(currentActiveEffect)\n\n\t// Track which reactive objects this effect is watching\n\tconst effectObjects = effectToReactiveObjects.get(currentActiveEffect)\n\tif (effectObjects) {\n\t\teffectObjects.add(obj)\n\t} else {\n\t\teffectToReactiveObjects.set(currentActiveEffect, new Set([obj]))\n\t}\n}\n","import { decorator } from '../decorator'\nimport { mixin } from '../mixins'\nimport { FoolProof, isOwnAccessor } from '../utils'\nimport { touched1 } from './change'\nimport { notifyPropertyChange } from './deep-touch'\nimport {\n\taddBackReference,\n\tbubbleUpChange,\n\tneedsBackReferences,\n\tobjectsWithDeepWatchers,\n\tremoveBackReference,\n} from './deep-watch-state'\nimport { untracked } from './effects'\nimport { absent, isNonReactive } from './non-reactive-state'\nimport {\n\tgetExistingProxy,\n\tproxyToObject,\n\tstoreProxyRelationship,\n\ttrackProxyObject,\n\tunwrap,\n} from './proxy-state'\nimport { dependant } from './tracking'\nimport {\n\tallProps,\n\tnativeReactive,\n\tnonReactiveMark,\n\toptions,\n\tReactiveError,\n\tReactiveErrorCode,\n\tunreactiveProperties,\n} from './types'\nexport const metaProtos = new WeakMap()\n\nconst hasReentry: any[] = []\nconst reactiveHandlers = {\n\t[Symbol.toStringTag]: 'MutTs Reactive',\n\tget(obj: any, prop: PropertyKey, receiver: any) {\n\t\tif (obj && typeof obj === 'object' && !Object.hasOwn(obj, prop)) {\n\t\t\tconst metaProto = metaProtos.get(obj.constructor)\n\t\t\tif (metaProto && prop in metaProto) {\n\t\t\t\tconst desc = Object.getOwnPropertyDescriptor(metaProto, prop)!\n\t\t\t\treturn desc.get ? desc.get.call(obj) : (...args) => desc.value.apply(obj, args)\n\t\t\t}\n\t\t}\n\t\tif (prop === nonReactiveMark) return false\n\t\tconst unwrappedObj = unwrap(obj)\n\t\t// Check if this property is marked as unreactive\n\t\tif (unwrappedObj[unreactiveProperties]?.has(prop) || typeof prop === 'symbol')\n\t\t\treturn FoolProof.get(obj, prop, receiver)\n\n\t\t// Check if property exists and if it's an own property (cached for later use)\n\t\tconst hasProp = Reflect.has(receiver, prop)\n\t\tconst isOwnProp = hasProp && Object.hasOwn(receiver, prop)\n\t\tconst isInheritedAccess = hasProp && !isOwnProp\n\n\t\t// For accessor properties, check the unwrapped object to see if it's an accessor\n\t\t// This ensures ignoreAccessors works correctly even after operations like Object.setPrototypeOf\n\t\tconst shouldIgnoreAccessor =\n\t\t\toptions.ignoreAccessors &&\n\t\t\tisOwnProp &&\n\t\t\t(isOwnAccessor(receiver, prop) || isOwnAccessor(unwrappedObj, prop))\n\n\t\t// Depend if...\n\t\tif (\n\t\t\t!hasProp ||\n\t\t\t(!(options.instanceMembers && isInheritedAccess && obj instanceof Object) &&\n\t\t\t\t!shouldIgnoreAccessor)\n\t\t)\n\t\t\tdependant(obj, prop)\n\n\t\t// Watch the whole prototype chain when requested or for null-proto objects\n\t\tif (isInheritedAccess && (!options.instanceMembers || !(obj instanceof Object))) {\n\t\t\tlet current = reactiveObject(Object.getPrototypeOf(obj))\n\t\t\twhile (current && current !== Object.prototype) {\n\t\t\t\tdependant(current, prop)\n\t\t\t\tif (Object.hasOwn(current, prop)) break\n\t\t\t\tlet next = reactiveObject(Object.getPrototypeOf(current))\n\t\t\t\tif (next === current) {\n\t\t\t\t\tnext = reactiveObject(Object.getPrototypeOf(unwrap(current)))\n\t\t\t\t}\n\t\t\t\tcurrent = next\n\t\t\t}\n\t\t}\n\t\tconst value = FoolProof.get(obj, prop, receiver)\n\t\tif (typeof value === 'object' && value !== null) {\n\t\t\tconst reactiveValue = reactiveObject(value)\n\n\t\t\t// Only create back-references if this object needs them\n\t\t\tif (needsBackReferences(obj)) {\n\t\t\t\taddBackReference(reactiveValue, obj, prop)\n\t\t\t}\n\n\t\t\treturn reactiveValue\n\t\t}\n\t\treturn value\n\t},\n\tset(obj: any, prop: PropertyKey, value: any, receiver: any): boolean {\n\t\t// Read old value directly from unwrapped object to avoid triggering dependency tracking\n\t\tconst unwrappedObj = unwrap(obj)\n\t\tconst unwrappedReceiver = unwrap(receiver)\n\n\t\t// Check if this property is marked as unreactive\n\t\tif (unwrappedObj[unreactiveProperties]?.has(prop) || unwrappedObj !== unwrappedReceiver)\n\t\t\treturn FoolProof.set(obj, prop, value, receiver)\n\t\tconst newValue = unwrap(value)\n\t\t// Read old value, using withEffect(undefined, ...) for getter-only accessors to avoid\n\t\t// breaking memoization dependency tracking during SET operations\n\t\tlet oldVal = absent\n\t\tif (Reflect.has(unwrappedReceiver, prop)) {\n\t\t\t// Check descriptor on both receiver and target to handle proxy cases\n\t\t\tconst receiverDesc = Object.getOwnPropertyDescriptor(unwrappedReceiver, prop)\n\t\t\tconst targetDesc = Object.getOwnPropertyDescriptor(unwrappedObj, prop)\n\t\t\tconst desc = receiverDesc || targetDesc\n\t\t\t// We *need* to use `receiver` and not `unwrappedObj` here, otherwise we break\n\t\t\t// the dependency tracking for memoized getters\n\t\t\tif (desc?.get && !desc?.set) {\n\t\t\t\toldVal = untracked(() => Reflect.get(unwrappedObj, prop, receiver))\n\t\t\t} else {\n\t\t\t\toldVal = untracked(() => Reflect.get(unwrappedObj, prop, receiver))\n\t\t\t}\n\t\t}\n\t\tif (objectsWithDeepWatchers.has(obj)) {\n\t\t\tif (typeof oldVal === 'object' && oldVal !== null) {\n\t\t\t\tremoveBackReference(oldVal, obj, prop)\n\t\t\t}\n\t\t\tif (typeof newValue === 'object' && newValue !== null) {\n\t\t\t\tconst reactiveValue = reactiveObject(newValue)\n\t\t\t\taddBackReference(reactiveValue, obj, prop)\n\t\t\t}\n\t\t}\n\n\t\tif (oldVal !== newValue) {\n\t\t\t// For getter-only accessors, Reflect.set() may fail, but we still return true\n\t\t\t// to avoid throwing errors. Only proceed with change notifications if set succeeded.\n\t\t\tif (FoolProof.set(obj, prop, newValue, receiver)) {\n\t\t\t\tnotifyPropertyChange(obj, prop, oldVal, newValue, oldVal !== absent)\n\t\t\t}\n\t\t}\n\t\treturn true\n\t},\n\thas(obj: any, prop: PropertyKey): boolean {\n\t\tif (hasReentry.includes(obj))\n\t\t\tthrow new ReactiveError(\n\t\t\t\t`[reactive] Circular dependency detected in 'has' check for property '${String(prop)}'`,\n\t\t\t\t{\n\t\t\t\t\tcode: ReactiveErrorCode.CycleDetected,\n\t\t\t\t\tcycle: [], // We don't have the full cycle here, but we know it involves obj\n\t\t\t\t}\n\t\t\t)\n\t\thasReentry.push(obj)\n\t\tdependant(obj, prop)\n\t\tconst rv = Reflect.has(obj, prop)\n\t\thasReentry.pop()\n\t\treturn rv\n\t},\n\tdeleteProperty(obj: any, prop: PropertyKey): boolean {\n\t\tif (!Object.hasOwn(obj, prop)) return false\n\n\t\tconst oldVal = (obj as any)[prop]\n\n\t\t// Remove back-references if this object has deep watchers\n\t\tif (objectsWithDeepWatchers.has(obj) && typeof oldVal === 'object' && oldVal !== null) {\n\t\t\tremoveBackReference(oldVal, obj, prop)\n\t\t}\n\n\t\tdelete (obj as any)[prop]\n\t\ttouched1(obj, { type: 'del', prop }, prop)\n\n\t\t// Bubble up changes if this object has deep watchers\n\t\tif (objectsWithDeepWatchers.has(obj)) {\n\t\t\tbubbleUpChange(obj, { type: 'del', prop })\n\t\t}\n\n\t\treturn true\n\t},\n\townKeys(obj: any): (string | symbol)[] {\n\t\tdependant(obj, allProps)\n\t\treturn Reflect.ownKeys(obj)\n\t},\n} as const\n\nconst reactiveClasses = new WeakSet<Function>()\n\n// Create the ReactiveBase mixin\n/**\n * Base mixin for reactive classes that provides proper constructor reactivity\n * Solves constructor reactivity issues in complex inheritance trees\n */\nexport const ReactiveBase = mixin((base) => {\n\tclass ReactiveMixin extends base {\n\t\tconstructor(...args: any[]) {\n\t\t\tsuper(...args)\n\t\t\t// Only apply reactive transformation if the class is marked with @reactive\n\t\t\t// This allows the mixin to work properly with method inheritance\n\t\t\t// biome-ignore lint/correctness/noConstructorReturn: This is the whole point here\n\t\t\treturn reactiveClasses.has(new.target) ? reactive(this) : this\n\t\t}\n\t}\n\treturn ReactiveMixin\n})\nfunction reactiveObject<T>(anyTarget: T): T {\n\tif (!anyTarget || typeof anyTarget !== 'object') return anyTarget\n\tconst target = anyTarget as any\n\t// If target is already a proxy, return it\n\tif (isNonReactive(target)) return target as T\n\tconst isProxy = proxyToObject.has(target)\n\tif (isProxy) return target as T\n\n\t// If we already have a proxy for this object, return it (optimized: get returns undefined if not found)\n\tconst existing = getExistingProxy(target)\n\tif (existing !== undefined) return existing as T\n\n\tconst proxied =\n\t\tnativeReactive in target && !(target instanceof target[nativeReactive])\n\t\t\t? new target[nativeReactive](target)\n\t\t\t: target\n\tif (proxied !== target) trackProxyObject(proxied, target)\n\tconst proxy = new Proxy(proxied, reactiveHandlers)\n\n\t// Store the relationships\n\tstoreProxyRelationship(target, proxy)\n\treturn proxy as T\n}\n\n/**\n * Main decorator for making classes reactive\n * Automatically makes class instances reactive when created\n */\nexport const reactive = decorator({\n\tclass(original) {\n\t\tif (original.prototype instanceof ReactiveBase) {\n\t\t\treactiveClasses.add(original)\n\t\t\treturn original\n\t\t}\n\n\t\tclass Reactive extends original {\n\t\t\tconstructor(...args: any[]) {\n\t\t\t\tsuper(...args)\n\t\t\t\tif (new.target !== Reactive && !reactiveClasses.has(new.target))\n\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t`${(original as any).name} has been inherited by ${this.constructor.name} that is not reactive.\n@reactive decorator must be applied to the leaf class OR classes have to extend ReactiveBase.`\n\t\t\t\t\t)\n\t\t\t\t// biome-ignore lint/correctness/noConstructorReturn: This is the whole point here\n\t\t\t\treturn reactive(this)\n\t\t\t}\n\t\t}\n\t\tObject.defineProperty(Reactive, 'name', {\n\t\t\tvalue: `Reactive<${original.name}>`,\n\t\t})\n\t\treturn Reactive as any\n\t},\n\tget(original: any) {\n\t\treturn reactiveObject(original)\n\t},\n\tdefault: reactiveObject,\n})\n\n/**\n * Gets the original, non-reactive object from a reactive proxy\n * @param proxy - The reactive proxy\n * @returns The original object\n */\nexport { isReactive, objectToProxy, proxyToObject, unwrap } from './proxy-state'\n","import {\n\tdeepWatchers,\n\teffectToDeepWatchedObjects,\n\tobjectsWithDeepWatchers,\n} from './deep-watch-state'\nimport { effect } from './effects'\nimport { isNonReactive } from './non-reactive-state'\nimport { reactive, unwrap } from './proxy'\nimport { markWithRoot } from './registry'\nimport { options, type ScopedCallback } from './types'\n\nfunction isObject(value: any): value is object {\n\treturn typeof value === 'object' && value !== null\n}\n\nexport {\n\taddBackReference,\n\tbubbleUpChange,\n\tdeepWatchers,\n\teffectToDeepWatchedObjects,\n\tneedsBackReferences,\n\tobjectParents,\n\tobjectsWithDeepWatchers,\n\tremoveBackReference,\n} from './deep-watch-state'\n\n/**\n * Deep watch an object and all its nested properties\n * @param target - The object to watch deeply\n * @param callback - The callback to call when any nested property changes\n * @param options - Options for the deep watch\n * @returns A cleanup function to stop watching\n */\n/**\n * Sets up deep watching for an object, tracking all nested property changes\n * @param target - The object to watch\n * @param callback - The callback to call when changes occur\n * @param options - Options for deep watching\n * @returns A cleanup function to stop deep watching\n */\nexport function deepWatch<T extends object>(\n\ttarget: T,\n\tcallback: (value: T) => void,\n\t{ immediate = false } = {}\n): (() => void) | undefined {\n\tif (target === null || target === undefined) return undefined\n\tif (typeof target !== 'object') throw new Error('Target of deep watching must be an object')\n\t// Create a wrapper callback that matches ScopedCallback signature\n\tconst wrappedCallback: ScopedCallback = markWithRoot(() => callback(target), callback)\n\n\t// Use the existing effect system to register dependencies\n\treturn effect(() => {\n\t\t// Mark the target object as having deep watchers\n\t\tobjectsWithDeepWatchers.add(target)\n\n\t\t// Track which objects this effect is watching for cleanup\n\t\tlet effectObjects = effectToDeepWatchedObjects.get(wrappedCallback)\n\t\tif (!effectObjects) {\n\t\t\teffectObjects = new Set()\n\t\t\teffectToDeepWatchedObjects.set(wrappedCallback, effectObjects)\n\t\t}\n\t\teffectObjects!.add(target)\n\n\t\t// Traverse the object graph and register dependencies\n\t\t// This will re-run every time the effect runs, ensuring we catch all changes\n\t\tconst visited = new WeakSet()\n\t\tfunction traverseAndTrack(obj: any, depth = 0) {\n\t\t\t// Prevent infinite recursion and excessive depth\n\t\t\tif (!obj || visited.has(obj) || !isObject(obj) || depth > options.maxDeepWatchDepth) return\n\t\t\t// Do not traverse into unreactive objects\n\t\t\tif (isNonReactive(obj)) return\n\t\t\tvisited.add(obj)\n\n\t\t\t// Mark this object as having deep watchers\n\t\t\tobjectsWithDeepWatchers.add(obj)\n\t\t\teffectObjects!.add(obj)\n\n\t\t\t// Traverse all properties to register dependencies\n\t\t\t// unwrap to avoid kicking dependency\n\t\t\tfor (const key in unwrap(obj)) {\n\t\t\t\tif (Object.hasOwn(obj, key)) {\n\t\t\t\t\t// Access the property to register dependency\n\t\t\t\t\tconst value = (obj as any)[key]\n\t\t\t\t\t// Make the value reactive if it's an object\n\t\t\t\t\tconst reactiveValue =\n\t\t\t\t\t\ttypeof value === 'object' && value !== null ? reactive(value) : value\n\t\t\t\t\ttraverseAndTrack(reactiveValue, depth + 1)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Also handle array indices and length\n\t\t\t// biome-ignore lint/suspicious/useIsArray: Check for both native arrays and reactive arrays\n\t\t\tif (Array.isArray(obj) || obj instanceof Array) {\n\t\t\t\t// Access array length to register dependency on length changes\n\t\t\t\tconst length = obj.length\n\n\t\t\t\t// Access all current array elements to register dependencies\n\t\t\t\tfor (let i = 0; i < length; i++) {\n\t\t\t\t\t// Access the array element to register dependency\n\t\t\t\t\tconst value = obj[i]\n\t\t\t\t\t// Make the value reactive if it's an object\n\t\t\t\t\tconst reactiveValue =\n\t\t\t\t\t\ttypeof value === 'object' && value !== null ? reactive(value) : value\n\t\t\t\t\ttraverseAndTrack(reactiveValue, depth + 1)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Handle Set values (deep watch values only, not keys since Sets don't have separate keys)\n\t\t\telse if (obj instanceof Set) {\n\t\t\t\t// Access all Set values to register dependencies\n\t\t\t\tfor (const value of obj) {\n\t\t\t\t\t// Make the value reactive if it's an object\n\t\t\t\t\tconst reactiveValue =\n\t\t\t\t\t\ttypeof value === 'object' && value !== null ? reactive(value) : value\n\t\t\t\t\ttraverseAndTrack(reactiveValue, depth + 1)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Handle Map values (deep watch values only, not keys)\n\t\t\telse if (obj instanceof Map) {\n\t\t\t\t// Access all Map values to register dependencies\n\t\t\t\tfor (const [_key, value] of obj) {\n\t\t\t\t\t// Make the value reactive if it's an object\n\t\t\t\t\tconst reactiveValue =\n\t\t\t\t\t\ttypeof value === 'object' && value !== null ? reactive(value) : value\n\t\t\t\t\ttraverseAndTrack(reactiveValue, depth + 1)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Note: WeakSet and WeakMap cannot be iterated, so we can't deep watch their contents\n\t\t\t// They will only trigger when the collection itself is replaced\n\t\t}\n\n\t\t// Traverse the target object to register all dependencies\n\t\t// This will register dependencies on all current properties and array elements\n\t\ttraverseAndTrack(target)\n\n\t\t// Only call the callback if immediate is true or if it's not the first run\n\t\tif (immediate) callback(target)\n\t\timmediate = true\n\n\t\t// Return a cleanup function that properly removes deep watcher tracking\n\t\treturn () => {\n\t\t\t// Get the objects this effect was watching\n\t\t\tconst effectObjects = effectToDeepWatchedObjects.get(wrappedCallback)\n\t\t\tif (effectObjects) {\n\t\t\t\t// Remove deep watcher tracking from all objects this effect was watching\n\t\t\t\tfor (const obj of effectObjects) {\n\t\t\t\t\t// Check if this object still has other deep watchers\n\t\t\t\t\tconst watchers = deepWatchers.get(obj)\n\t\t\t\t\tif (watchers) {\n\t\t\t\t\t\t// Remove this effect's callback from the watchers\n\t\t\t\t\t\twatchers.delete(wrappedCallback)\n\n\t\t\t\t\t\t// If no more watchers, remove the object from deep watchers tracking\n\t\t\t\t\t\tif (watchers.size === 0) {\n\t\t\t\t\t\t\tdeepWatchers.delete(obj)\n\t\t\t\t\t\t\tobjectsWithDeepWatchers.delete(obj)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// No watchers found, remove from deep watchers tracking\n\t\t\t\t\t\tobjectsWithDeepWatchers.delete(obj)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Clean up the tracking data\n\t\t\t\teffectToDeepWatchedObjects.delete(wrappedCallback)\n\t\t\t}\n\t\t}\n\t})\n}\n","import { decorator, type GenericClassDecorator } from '../decorator'\nimport { deepWatch } from './deep-watch'\nimport { effect, untracked } from './effects'\nimport { isNonReactive, nonReactiveClass, nonReactiveObjects } from './non-reactive-state'\nimport { unwrap } from './proxy-state'\nimport { markWithRoot } from './registry'\nimport { dependant } from './tracking'\nimport {\n\ttype DependencyAccess,\n\tnonReactiveMark,\n\ttype ScopedCallback,\n\tunreactiveProperties,\n} from './types'\n\n/**\n * Symbol for accessing the cleanup function on cleaned objects\n */\nexport const cleanup = Symbol('cleanup')\n\n//#region watch\n\nconst unsetYet = Symbol('unset-yet')\n/**\n * Options for the watch function\n */\nexport interface WatchOptions {\n\t/** Whether to call the callback immediately */\n\timmediate?: boolean\n\t/** Whether to watch nested properties */\n\tdeep?: boolean\n}\n\n/**\n * Watches a reactive value and calls a callback when it changes\n * @param value - Function that returns the value to watch\n * @param changed - Callback to call when the value changes\n * @param options - Watch options\n * @returns Cleanup function to stop watching\n */\nexport function watch<T>(\n\tvalue: (dep: DependencyAccess) => T,\n\tchanged: (value: T, oldValue?: T) => void,\n\toptions?: Omit<WatchOptions, 'deep'> & { deep?: false }\n): ScopedCallback\n/**\n * Watches a reactive value with deep watching enabled\n * @param value - Function that returns the value to watch\n * @param changed - Callback to call when the value changes\n * @param options - Watch options with deep watching enabled\n * @returns Cleanup function to stop watching\n */\nexport function watch<T extends object | any[]>(\n\tvalue: (dep: DependencyAccess) => T,\n\tchanged: (value: T, oldValue?: T) => void,\n\toptions?: Omit<WatchOptions, 'deep'> & { deep: true }\n): ScopedCallback\n/**\n * Watches a reactive object directly\n * @param value - The reactive object to watch\n * @param changed - Callback to call when the object changes\n * @param options - Watch options\n * @returns Cleanup function to stop watching\n */\nexport function watch<T extends object | any[]>(\n\tvalue: T,\n\tchanged: (value: T) => void,\n\toptions?: WatchOptions\n): ScopedCallback\n\nexport function watch(\n\tvalue: any, //object | ((dep: DependencyAccess) => object),\n\tchanged: (value?: object, oldValue?: object) => void,\n\toptions: any = {}\n) {\n\treturn typeof value === 'function'\n\t\t? watchCallBack(value, changed, options)\n\t\t: typeof value === 'object' && value !== null\n\t\t\t? watchObject(value, changed, options)\n\t\t\t: (() => {\n\t\t\t\t\tthrow new Error('watch: value must be a function or an object')\n\t\t\t\t})()\n}\n\nfunction watchObject(\n\tvalue: object,\n\tchanged: (value: object) => void,\n\t{ immediate = false, deep = false } = {}\n): ScopedCallback {\n\tif (deep) return deepWatch(value, changed, { immediate })!\n\treturn effect(function watchObjectEffect() {\n\t\tdependant(value)\n\t\tif (immediate) changed(value)\n\t\timmediate = true\n\t})\n}\n\nfunction watchCallBack<T>(\n\tvalue: (dep: DependencyAccess) => T,\n\tchanged: (value: T, oldValue?: T) => void,\n\t{ immediate = false, deep = false } = {}\n): ScopedCallback {\n\tlet oldValue: T | typeof unsetYet = unsetYet\n\tlet deepCleanup: ScopedCallback | undefined\n\tconst cbCleanup = effect(\n\t\tmarkWithRoot(function watchCallBackEffect(access) {\n\t\t\tconst newValue = value(access)\n\t\t\tif (oldValue !== newValue)\n\t\t\t\tif (oldValue === unsetYet) {\n\t\t\t\t\tif (immediate) changed(newValue)\n\t\t\t\t} else changed(newValue, oldValue)\n\t\t\t\toldValue = newValue\n\t\t\t\tif (deep) {\n\t\t\t\t\tif (deepCleanup) deepCleanup()\n\t\t\t\t\tdeepCleanup = deepWatch(newValue as object, (value) => changed(value as T, value as T))\n\t\t\t\t}\n\t\t}, value)\n\t)\n\treturn () => {\n\t\tcbCleanup()\n\t\tif (deepCleanup) deepCleanup()\n\t}\n}\n\n//#endregion\n\n//#region nonReactive\n\n/**\n * Mark an object as non-reactive. This object and all its properties will never be made reactive.\n * @param obj - The object to mark as non-reactive\n */\nfunction deepNonReactive<T>(obj: T): T {\n\tobj = unwrap(obj)\n\tif (isNonReactive(obj)) return obj\n\ttry {\n\t\tObject.defineProperty(obj as object, nonReactiveMark, {\n\t\t\tvalue: true,\n\t\t\twritable: false,\n\t\t\tenumerable: false,\n\t\t\tconfigurable: true,\n\t\t})\n\t} catch {}\n\tif (!(nonReactiveMark in (obj as object))) nonReactiveObjects.add(obj as object)\n\t// Finally, not deep\n\t//for (const key in obj) deepNonReactive(obj[key])\n\treturn obj\n}\nfunction unreactiveApplication<T extends object>(...args: (keyof T)[]): GenericClassDecorator<T>\nfunction unreactiveApplication<T extends object>(obj: T): T\nfunction unreactiveApplication<T extends object>(\n\targ1: T | keyof T,\n\t...args: (keyof T)[]\n): GenericClassDecorator<T> | T {\n\treturn typeof arg1 === 'object'\n\t\t? deepNonReactive(arg1)\n\t\t: (((original) => {\n\t\t\t\t// Copy the parent's unreactive properties if they exist\n\t\t\t\toriginal.prototype[unreactiveProperties] = new Set<PropertyKey>(\n\t\t\t\t\toriginal.prototype[unreactiveProperties] || []\n\t\t\t\t)\n\t\t\t\t// Add all arguments (including the first one)\n\t\t\t\toriginal.prototype[unreactiveProperties].add(arg1)\n\t\t\t\tfor (const arg of args) original.prototype[unreactiveProperties].add(arg)\n\t\t\t\treturn original // Return the class\n\t\t\t}) as GenericClassDecorator<T>)\n}\n/**\n * Decorator that marks classes or properties as non-reactive\n * Prevents objects from being made reactive\n */\nexport const unreactive = decorator({\n\tclass(original) {\n\t\t// Called without arguments, mark entire class as non-reactive\n\t\tnonReactiveClass(original)\n\t},\n\tdefault: unreactiveApplication,\n})\n\n//#endregion\n\nexport function cleanedBy<T extends object>(obj: T, cleanupFn: ScopedCallback) {\n\treturn Object.defineProperty(obj, cleanup, {\n\t\tvalue: cleanupFn,\n\t\twritable: false,\n\t\tenumerable: false,\n\t\tconfigurable: true,\n\t}) as T & { [cleanup]: ScopedCallback }\n}\n\n//#region greedy caching\n\n/**\n * Creates a derived value that automatically recomputes when dependencies change\n * @param compute - Function that computes the derived value\n * @returns Object with value and cleanup function\n */\nexport function derived<T>(compute: (dep: DependencyAccess) => T): {\n\tvalue: T\n\t[cleanup]: ScopedCallback\n} {\n\tconst rv = { value: undefined as unknown as T }\n\treturn cleanedBy(\n\t\trv,\n\t\tuntracked(() =>\n\t\t\teffect(function derivedEffect(access) {\n\t\t\t\trv.value = compute(access)\n\t\t\t})\n\t\t)\n\t)\n}\n","import { decorator } from '../decorator'\nimport { deepCompare, renamed } from '../utils'\nimport { touched1 } from './change'\nimport { effect, root, untracked } from './effects'\nimport { getRoot, markWithRoot } from './registry'\nimport { dependant } from './tracking'\nimport { options, rootFunction } from './types'\n\nexport type Memoizable = object | any[] | symbol | ((...args: any[]) => any)\n\ntype MemoCacheTree<Result> = {\n\tresult?: Result\n\tcleanup?: () => void\n\tbranches?: WeakMap<Memoizable, MemoCacheTree<Result>>\n}\n\nconst memoizedRegistry = new WeakMap<any, Function>()\nconst wrapperRegistry = new WeakMap<Function, Function>()\n\nfunction getBranch<Result>(tree: MemoCacheTree<Result>, key: Memoizable): MemoCacheTree<Result> {\n\ttree.branches ??= new WeakMap()\n\tlet branch = tree.branches.get(key)\n\tif (!branch) {\n\t\tbranch = {}\n\t\ttree.branches.set(key, branch)\n\t}\n\treturn branch\n}\n\nfunction memoizeFunction<Result, Args extends Memoizable[]>(\n\tfn: (...args: Args) => Result\n): (...args: Args) => Result {\n\tconst fnRoot = getRoot(fn)\n\tconst existing = memoizedRegistry.get(fnRoot)\n\tif (existing) return existing as (...args: Args) => Result\n\n\tconst cacheRoot: MemoCacheTree<Result> = {}\n\tconst memoized = markWithRoot((...args: Args): Result => {\n\t\tconst localArgs = args //: Args = maxArgs !== undefined ? (args.slice(0, maxArgs) as Args) : args\n\t\tif (localArgs.some((arg) => !(arg && ['object', 'symbol', 'function'].includes(typeof arg))))\n\t\t\tthrow new Error('memoize expects non-null object arguments')\n\n\t\tlet node: MemoCacheTree<Result> = cacheRoot\n\t\t// Note: decorators add `this` as first argument\n\t\tfor (const arg of localArgs) {\n\t\t\tnode = getBranch(node, arg)\n\t\t}\n\n\t\tdependant(node, 'memoize')\n\t\tif ('result' in node) {\n\t\t\tif (options.onMemoizationDiscrepancy) {\n\t\t\t\tconst wasVerification = options.isVerificationRun\n\t\t\t\toptions.isVerificationRun = true\n\t\t\t\ttry {\n\t\t\t\t\tconst fresh = untracked(() => fn(...localArgs))\n\t\t\t\t\tif (!deepCompare(node.result, fresh)) {\n\t\t\t\t\t\toptions.onMemoizationDiscrepancy(node.result, fresh, fn, localArgs, 'calculation')\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\toptions.isVerificationRun = wasVerification\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn node.result!\n\t\t}\n\n\t\t// Create memoize internal effect to track dependencies and invalidate cache\n\t\t// Use untracked to prevent the effect creation from being affected by parent effects\n\t\tnode.cleanup = root(() =>\n\t\t\teffect(\n\t\t\t\t() => {\n\t\t\t\t\t// Execute the function and track its dependencies\n\t\t\t\t\t// The function execution will automatically track dependencies on reactive objects\n\t\t\t\t\tnode.result = fn(...localArgs)\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\t// When dependencies change, clear the cache and notify consumers\n\t\t\t\t\t\tdelete node.result\n\t\t\t\t\t\ttouched1(node, { type: 'invalidate', prop: localArgs }, 'memoize')\n\t\t\t\t\t\t// Lazy memoization: stop the effect so it doesn't re-run immediately.\n\t\t\t\t\t\t// It will be re-created on next access.\n\t\t\t\t\t\tif (node.cleanup) {\n\t\t\t\t\t\t\tnode.cleanup()\n\t\t\t\t\t\t\tnode.cleanup = undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{ opaque: true }\n\t\t\t)\n\t\t)\n\n\t\tif (options.onMemoizationDiscrepancy) {\n\t\t\tconst wasVerification = options.isVerificationRun\n\t\t\toptions.isVerificationRun = true\n\t\t\ttry {\n\t\t\t\tconst fresh = untracked(() => fn(...localArgs))\n\t\t\t\tif (!deepCompare(node.result, fresh)) {\n\t\t\t\t\toptions.onMemoizationDiscrepancy(node.result, fresh, fn, localArgs, 'comparison')\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\toptions.isVerificationRun = wasVerification\n\t\t\t}\n\t\t}\n\n\t\treturn node.result!\n\t}, fn)\n\n\tmemoizedRegistry.set(fnRoot, memoized)\n\tmemoizedRegistry.set(memoized, memoized)\n\treturn memoized as (...args: Args) => Result\n}\n\nexport const memoize = decorator({\n\tgetter(original, target, propertyKey) {\n\t\treturn function (this: any) {\n\t\t\tlet wrapper = wrapperRegistry.get(original)\n\t\t\tif (!wrapper) {\n\t\t\t\twrapper = markWithRoot(\n\t\t\t\t\trenamed(\n\t\t\t\t\t\t(that: object) => {\n\t\t\t\t\t\t\treturn original.call(that)\n\t\t\t\t\t\t},\n\t\t\t\t\t\t`${String(target?.constructor?.name ?? target?.name ?? 'Object')}.${String(propertyKey)}`\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: original,\n\t\t\t\t\t\tpropertyKey,\n\t\t\t\t\t\t...((original as any)[rootFunction]\n\t\t\t\t\t\t\t? { [rootFunction]: (original as any)[rootFunction] }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t\twrapperRegistry.set(original, wrapper)\n\t\t\t}\n\t\t\tconst memoized = memoizeFunction(wrapper as any)\n\t\t\treturn memoized(this)\n\t\t}\n\t},\n\tmethod(original, target, name) {\n\t\treturn function (this: any, ...args: object[]) {\n\t\t\tlet wrapper = wrapperRegistry.get(original)\n\t\t\tif (!wrapper) {\n\t\t\t\twrapper = markWithRoot(\n\t\t\t\t\trenamed(\n\t\t\t\t\t\t(that: object, ...args: object[]) => {\n\t\t\t\t\t\t\treturn original.call(that, ...args)\n\t\t\t\t\t\t},\n\t\t\t\t\t\t`${String(target?.constructor?.name ?? target?.name ?? 'Object')}.${String(name)}`\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tmethod: original,\n\t\t\t\t\t\tpropertyKey: name,\n\t\t\t\t\t\t...((original as any)[rootFunction]\n\t\t\t\t\t\t\t? { [rootFunction]: (original as any)[rootFunction] }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t\twrapperRegistry.set(original, wrapper)\n\t\t\t}\n\t\t\tconst memoized = memoizeFunction(wrapper as any) as (...args: object[]) => unknown\n\t\t\treturn memoized(this, ...args)\n\t\t}\n\t},\n\tdefault: memoizeFunction,\n})\n","import {\n\tabsent,\n\timmutables,\n\tisNonReactive,\n\tnonReactive,\n\tnonReactiveClass,\n\tnonReactiveObjects,\n\tregisterNativeReactivity,\n} from './non-reactive-state'\nimport { reactive } from './proxy'\n\n/**\n * Converts an iterator to a generator that yields reactive values\n */\nexport function* makeReactiveIterator<T>(iterator: Iterator<T>): Generator<T> {\n\tlet result = iterator.next()\n\twhile (!result.done) {\n\t\tyield reactive(result.value)\n\t\tresult = iterator.next()\n\t}\n}\n\n/**\n * Converts an iterator of key-value pairs to a generator that yields reactive key-value pairs\n */\nexport function* makeReactiveEntriesIterator<K, V>(iterator: Iterator<[K, V]>): Generator<[K, V]> {\n\tlet result = iterator.next()\n\twhile (!result.done) {\n\t\tconst [key, value] = result.value\n\t\tyield [reactive(key), reactive(value)]\n\t\tresult = iterator.next()\n\t}\n}\n\nexport {\n\tabsent,\n\timmutables,\n\tisNonReactive,\n\tnonReactive,\n\tnonReactiveClass,\n\tnonReactiveObjects,\n\tregisterNativeReactivity,\n}\n","import { FunctionWrapper } from '../zone'\nimport { ArrayReadForward, forwardArray, getAt, Indexable, setAt } from '../indexable'\nimport { effect } from './effects'\nimport { unreactive } from './interface'\nimport { reactive } from './proxy'\nimport { type ScopedCallback } from './types'\n\n// TODO: use register in a real-world crud situation, have \"events\" for add, delete, update\n\ntype KeyFunction<T, K extends PropertyKey> = (item: T) => K\n\n// Helper to work around TypeScript limitation: base class expressions cannot reference class type parameters\nfunction getRegisterBase<T>() {\n\tclass RegisterBase extends Indexable(ArrayReadForward, {\n\t\tget(this: any, index: number) {\n\t\t\treturn this[getAt](index)\n\t\t},\n\t\tset(this: any, index: number, value: T) {\n\t\t\tthis[setAt](index, value)\n\t\t},\n\t\tgetLength(this: any) {\n\t\t\treturn this.length\n\t\t},\n\t\tsetLength(this: any, value: number) {\n\t\t\tthis.length = value\n\t\t},\n\t}) {\n\t\ttoArray(): T[] {\n\t\t\treturn Array.from(this)\n\t\t}\n\t}\n\treturn RegisterBase as new () => ArrayReadForward<T> & {\n\t\t[x: number]: T\n\t\ttoArray(): T[]\n\t}\n}\ninterface RegisterInstance<T> extends ArrayReadForward<T> {\n\t[index: number]: T\n}\n// TODO: What to do with prototype forwarding ?\n@unreactive\nclass RegisterClass<T, K extends PropertyKey = PropertyKey>\n\textends getRegisterBase<any>()\n\timplements RegisterInstance<T>\n{\n\tprotected get [forwardArray](): readonly T[] {\n\t\treturn this.toArray()\n\t}\n\treadonly #keyFn: KeyFunction<T, K>\n\treadonly #keys: K[]\n\treadonly #values: Map<K, T>\n\treadonly #usage = new Map<K, number>()\n\treadonly #valueInfo = new Map<T, { key: K; stop?: ScopedCallback }>()\n\treadonly #keyEffects = new Set<ScopedCallback>()\n\treadonly #ascend: FunctionWrapper\n\n\tconstructor(keyFn: KeyFunction<T, K>, initial?: Iterable<T>) {\n\t\tsuper()\n\t\t/* Moved below initialization */\n\t\tlet ascendGet: FunctionWrapper | undefined\n\t\teffect(({ ascend }) => {\n\t\t\tascendGet = ascend\n\t\t})\n\t\tthis.#ascend = ascendGet!\n\t\tif (typeof keyFn !== 'function') throw new Error('Register requires a key function')\n\t\tthis.#keyFn = keyFn\n\t\tthis.#keys = reactive([] as K[])\n\t\tthis.#values = reactive(new Map<K, T>())\n\t\tif (initial) this.push(...initial)\n\t}\n\n\tprivate ensureKey(value: T): K {\n\t\tlet info = this.#valueInfo.get(value)\n\t\tif (info) return info.key\n\t\tinfo = { key: undefined as unknown as K }\n\t\tthis.#valueInfo.set(value, info)\n\t\tthis.#ascend(() => {\n\t\t\tconst stop = effect(({ reaction }) => {\n\t\t\t\tconst nextKey = this.#keyFn(value)\n\t\t\t\tthis.assertValidKey(nextKey)\n\t\t\t\tconst previousKey = info!.key\n\t\t\t\tif (reaction && previousKey !== undefined && !Object.is(nextKey, previousKey))\n\t\t\t\t\tthis.#rekeyValue(value, previousKey, nextKey)\n\t\t\t\tinfo!.key = nextKey\n\t\t\t})\n\t\t\tinfo!.stop = stop\n\t\t\tthis.#keyEffects.add(stop)\n\t\t})\n\t\tif (info.key === undefined) throw new Error('Register key function must return a property key')\n\t\treturn info.key\n\t}\n\n\tprivate assertValidKey(key: unknown): asserts key is K {\n\t\tconst type = typeof key\n\t\tif (type !== 'string' && type !== 'number' && type !== 'symbol')\n\t\t\tthrow new Error('Register key function must return a property key')\n\t}\n\n\tprivate setKeyValue(key: K, value: T) {\n\t\tconst existing = this.#values.get(key)\n\t\tif (existing !== undefined && existing !== value) this.cleanupValue(existing)\n\t\tthis.#values.set(key, value)\n\t}\n\n\tprivate cleanupValue(value: T) {\n\t\tconst info = this.#valueInfo.get(value)\n\t\tif (!info) return\n\t\tconst stop = info.stop\n\t\tif (stop) {\n\t\t\tinfo.stop = undefined\n\t\t\tthis.#keyEffects.delete(stop)\n\t\t\tstop()\n\t\t}\n\t\tthis.#valueInfo.delete(value)\n\t}\n\n\tprivate disposeKeyEffects() {\n\t\tfor (const value of Array.from(this.#valueInfo.keys())) this.cleanupValue(value)\n\t\tthis.#keyEffects.clear()\n\t}\n\n\t#rekeyValue(value: T, oldKey: K, newKey: K) {\n\t\tif (Object.is(oldKey, newKey)) return\n\t\tconst existingValue = this.#values.get(newKey)\n\t\tif (existingValue !== undefined && existingValue !== value)\n\t\t\tthrow new Error(`Register key collision for key ${String(newKey)}`)\n\t\tconst count = this.#usage.get(oldKey)\n\t\tif (!count) return\n\t\tconst existingCount = this.#usage.get(newKey) ?? 0\n\t\tthis.setKeyValue(newKey, value)\n\t\tfor (let i = 0; i < this.#keys.length; i++)\n\t\t\tif (Object.is(this.#keys[i], oldKey)) this.#keys[i] = newKey\n\t\tthis.#usage.set(newKey, existingCount + count)\n\t\tthis.#usage.delete(oldKey)\n\t\tthis.#values.delete(oldKey)\n\t\tconst updatedInfo = this.#valueInfo.get(value)\n\t\tif (updatedInfo) updatedInfo.key = newKey\n\t}\n\n\tprivate incrementUsage(key: K) {\n\t\tconst count = this.#usage.get(key) ?? 0\n\t\tthis.#usage.set(key, count + 1)\n\t}\n\n\tprivate decrementUsage(key: K) {\n\t\tconst count = this.#usage.get(key)\n\t\tif (!count) return\n\t\tif (count <= 1) {\n\t\t\tconst value = this.#values.get(key)\n\t\t\tthis.#usage.delete(key)\n\t\t\tthis.#values.delete(key)\n\t\t\tif (value !== undefined) this.cleanupValue(value)\n\t\t} else {\n\t\t\tthis.#usage.set(key, count - 1)\n\t\t}\n\t}\n\n\tprivate normalizeIndex(index: number, allowEnd = false): number {\n\t\tconst length = this.length\n\t\tlet resolved = index\n\t\tif (resolved < 0) resolved = Math.max(length + resolved, 0)\n\t\tif (resolved > length) {\n\t\t\tif (allowEnd) resolved = length\n\t\t\telse throw new RangeError('Index out of bounds')\n\t\t}\n\t\tif (!allowEnd && resolved === length) throw new RangeError('Index out of bounds')\n\t\treturn resolved\n\t}\n\n\tprivate assignAt(index: number, key: K, value: T) {\n\t\tconst oldKey = this.#keys[index]\n\t\tif (oldKey !== undefined && Object.is(oldKey, key)) {\n\t\t\tthis.setKeyValue(key, value)\n\t\t\treturn\n\t\t}\n\t\tif (oldKey !== undefined) this.decrementUsage(oldKey as K)\n\t\tthis.#keys[index] = key\n\t\tthis.incrementUsage(key)\n\t\tthis.setKeyValue(key, value)\n\t}\n\n\tprivate insertKeyValue(index: number, key: K, value: T) {\n\t\tthis.#keys.splice(index, 0, key)\n\t\tthis.incrementUsage(key)\n\t\tthis.setKeyValue(key, value)\n\t}\n\n\tprivate rebuildFrom(values: T[]) {\n\t\tthis.disposeKeyEffects()\n\t\tthis.#keys.splice(0, this.#keys.length)\n\t\tthis.#usage.clear()\n\t\tthis.#values.clear()\n\t\tfor (const value of values) {\n\t\t\tconst key = this.ensureKey(value)\n\t\t\tthis.#keys.push(key)\n\t\t\tthis.incrementUsage(key)\n\t\t\tthis.#values.set(key, value)\n\t\t}\n\t}\n\n\tget length(): number {\n\t\treturn this.#keys.length\n\t}\n\n\t[getAt](index: number): T | undefined {\n\t\tconst key = this.#keys[index]\n\t\treturn key === undefined ? undefined : this.#values.get(key)\n\t}\n\n\t[setAt](index: number, value: T): void {\n\t\tconst key = this.ensureKey(value)\n\t\tif (index === this.length) {\n\t\t\tthis.insertKeyValue(index, key, value)\n\t\t\treturn\n\t\t}\n\t\tconst normalized = this.normalizeIndex(index)\n\t\tthis.assignAt(normalized, key, value)\n\t}\n\n\tpush(...items: T[]): number {\n\t\tfor (const item of items) {\n\t\t\tconst key = this.ensureKey(item)\n\t\t\tthis.insertKeyValue(this.length, key, item)\n\t\t}\n\t\treturn this.length\n\t}\n\n\tpop(): T | undefined {\n\t\tif (!this.length) return undefined\n\t\treturn this.removeAt(this.length - 1)\n\t}\n\n\tshift(): T | undefined {\n\t\tif (!this.length) return undefined\n\t\treturn this.removeAt(0)\n\t}\n\n\tunshift(...items: T[]): number {\n\t\tlet index = 0\n\t\tfor (const item of items) {\n\t\t\tconst key = this.ensureKey(item)\n\t\t\tthis.insertKeyValue(index++, key, item)\n\t\t}\n\t\treturn this.length\n\t}\n\n\tsplice(start: number, deleteCount?: number, ...items: T[]): T[] {\n\t\tconst normalizedStart = this.normalizeIndex(start, true)\n\t\tconst maxDeletions = this.length - normalizedStart\n\t\tconst actualDelete = Math.min(\n\t\t\tdeleteCount === undefined ? maxDeletions : Math.max(deleteCount, 0),\n\t\t\tmaxDeletions\n\t\t)\n\t\tconst keysToInsert: K[] = []\n\t\tfor (const item of items) keysToInsert.push(this.ensureKey(item))\n\t\tconst removedKeys = this.#keys.splice(normalizedStart, actualDelete, ...keysToInsert)\n\t\tconst removedValues: T[] = []\n\t\tfor (const key of removedKeys) {\n\t\t\tif (key === undefined) continue\n\t\t\tconst value = this.#values.get(key as K)\n\t\t\tthis.decrementUsage(key as K)\n\t\t\tremovedValues.push(value as T)\n\t\t}\n\t\tfor (let i = 0; i < keysToInsert.length; i++) {\n\t\t\tconst key = keysToInsert[i]\n\t\t\tconst value = items[i]\n\t\t\tthis.incrementUsage(key)\n\t\t\tthis.setKeyValue(key, value)\n\t\t}\n\t\treturn removedValues\n\t}\n\n\tclear(): void {\n\t\tthis.#keys.length = 0\n\t\tthis.#usage.clear()\n\t\tthis.#values.clear()\n\t\tthis.disposeKeyEffects()\n\t}\n\n\tget(key: K): T | undefined {\n\t\treturn this.#values.get(key)\n\t}\n\tset(key: K, value: T): void {\n\t\tif (this.#values.has(key)) this.setKeyValue(key, value)\n\t}\n\n\tremove(key: K) {\n\t\tlet index: number = this.indexOfKey(key)\n\t\twhile (index !== -1) {\n\t\t\tthis.removeAt(index)\n\t\t\tindex = this.indexOfKey(key)\n\t\t}\n\t}\n\n\tpublic removeAt(index: number): T | undefined {\n\t\tconst [key] = this.#keys.splice(index, 1)\n\t\tif (key === undefined) return undefined\n\t\tconst value = this.#values.get(key as K)\n\t\tthis.decrementUsage(key as K)\n\t\treturn value\n\t}\n\n\t/**\n\t * Keep only the items for which the predicate returns true.\n\t * Items for which the predicate returns false are removed.\n\t *\n\t * The predicate is evaluated once per distinct key; duplicate keys\n\t * will follow the same keep/remove decision.\n\t */\n\tpublic keep(predicate: (value: T) => boolean): void {\n\t\tconst decisions = new Map<K, boolean>()\n\t\tfor (const [index, key] of this.#keys.entries()) {\n\t\t\tif (decisions.has(key)) {\n\t\t\t\tif (!decisions.get(key)) this.removeAt(index)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst value = this.#values.get(key)\n\t\t\tconst shouldKeep = predicate(value as T)\n\t\t\tdecisions.set(key, shouldKeep)\n\t\t\tif (!shouldKeep) this.removeAt(index)\n\t\t}\n\t}\n\n\thasKey(key: K): boolean {\n\t\treturn this.#usage.has(key)\n\t}\n\n\tindexOfKey(key: K): number {\n\t\treturn this.#keys.indexOf(key)\n\t}\n\n\tmapKeys(): IterableIterator<K> {\n\t\treturn this.#values.keys()\n\t}\n\n\tupdate(...values: T[]): void {\n\t\tfor (const value of values) {\n\t\t\tconst key = this.ensureKey(value)\n\t\t\tif (this.#values.has(key)) this.setKeyValue(key, value)\n\t\t}\n\t}\n\n\tupsert(insert: (value: T) => void, ...values: T[]): void {\n\t\tfor (const value of values) {\n\t\t\tconst key = this.ensureKey(value)\n\t\t\tif (this.#values.has(key)) this.setKeyValue(key, value)\n\t\t\telse insert(value)\n\t\t}\n\t}\n\n\tentries(): IterableIterator<[number, T]> {\n\t\tconst self = this\n\t\tfunction* iterator(): IterableIterator<[number, T]> {\n\t\t\tfor (let i = 0; i < self.#keys.length; i++) {\n\t\t\t\tconst val = self.#values.get(self.#keys[i])\n\t\t\t\tif (val !== undefined) yield [i, val]\n\t\t\t}\n\t\t}\n\t\treturn iterator()\n\t}\n\n\t[Symbol.iterator](): IterableIterator<T> {\n\t\tconst self = this\n\t\tfunction* iterator(): IterableIterator<T> {\n\t\t\tfor (const key of self.#keys) {\n\t\t\t\tconst value = self.#values.get(key)\n\t\t\t\tif (value !== undefined) yield value\n\t\t\t}\n\t\t}\n\t\treturn iterator()\n\t}\n\n\ttoString(): string {\n\t\treturn `[Register length=${this.length}]`\n\t}\n\n\tat(index: number): T | undefined {\n\t\tconst resolved = index < 0 ? this.length + index : index\n\t\tif (resolved < 0 || resolved >= this.length) return undefined\n\t\treturn this[getAt](resolved)\n\t}\n\treverse(): this {\n\t\tthis.#keys.reverse()\n\t\treturn this\n\t}\n\tsort(compareFn?: ((a: T, b: T) => number) | undefined): this {\n\t\tconst fwdCompareFn = compareFn\n\t\t\t? (a: K, b: K) => compareFn(this.#values.get(a) as T, this.#values.get(b) as T)\n\t\t\t: undefined\n\t\tthis.#keys.sort(fwdCompareFn)\n\t\treturn this\n\t}\n\tfill(value: T, start = 0, end = this.length): this {\n\t\tconst values = this.toArray()\n\t\tvalues.fill(value, start, end)\n\t\tthis.rebuildFrom(values)\n\t\treturn this\n\t}\n\n\tcopyWithin(target: number, start: number, end?: number): this {\n\t\tconst values = this.toArray()\n\t\tvalues.copyWithin(target, start, end)\n\t\tthis.rebuildFrom(values)\n\t\treturn this\n\t}\n}\n\nexport type Register<T, K extends PropertyKey = PropertyKey> = RegisterClass<T, K> & T[]\nexport const Register = RegisterClass as new <T, K extends PropertyKey = PropertyKey>(\n\tkeyFn: KeyFunction<T, K>,\n\tinitial?: Iterable<T>\n) => Register<T, K>\n\nexport function register<T, K extends PropertyKey = PropertyKey>(\n\tkeyFn: KeyFunction<T, K>,\n\tinitial?: Iterable<T>\n): Register<T, K> {\n\treturn new RegisterClass(keyFn, initial) as Register<T, K>\n}\n","import { FoolProof } from '../utils'\nimport { setEffectName } from './debug'\nimport { getActiveEffect } from './effect-context'\nimport { effect, untracked } from './effects'\nimport { cleanedBy, cleanup } from './interface'\nimport { reactive } from './proxy'\nimport { Register } from './register'\nimport { type ProjectionContext, projectionInfo, type ScopedCallback } from './types'\n\n/**\n * Maps projection effects (item effects) to their projection context\n */\nexport const effectProjectionMetadata = new WeakMap<ScopedCallback, ProjectionContext>()\n\n/**\n * Returns the projection context of the currently running effect, if any.\n */\nexport function getActiveProjection(): ProjectionContext | undefined {\n\tconst active = getActiveEffect()\n\treturn active ? effectProjectionMetadata.get(active) : undefined\n}\n\n/* TODO\nIt seems to work and I feel like it's correct but I couldn't validate theoretically that `ascend`\nis the correct way to deal with nested effects.\n*/\n\ntype ProjectOldValue<Target> = Target extends readonly (infer Item)[]\n\t? Item\n\t: Target extends Map<any, infer Item>\n\t\t? Item\n\t\t: Target extends Record<PropertyKey, infer Item>\n\t\t\t? Item\n\t\t\t: unknown\n\nexport type ProjectAccess<SourceValue, Key, SourceType, Target> = {\n\treadonly key: Key\n\tget(): SourceValue\n\tset(value: SourceValue): boolean\n\treadonly source: SourceType\n\treadonly old?: ProjectOldValue<Target>\n\tvalue: SourceValue\n}\n\nexport type ProjectCallback<SourceValue, Key, Target extends object, SourceType, Result> = (\n\taccess: ProjectAccess<SourceValue, Key, SourceType, Target>,\n\ttarget: Target\n) => Result\n\nexport type ProjectResult<Target extends object> = Target & { [cleanup]: ScopedCallback }\n\nfunction defineAccessValue<Access extends { get(): unknown; set(value: unknown): boolean }>(\n\taccess: Access\n) {\n\tObject.defineProperty(access, 'value', {\n\t\tget: access.get,\n\t\tset: access.set,\n\t\tconfigurable: true,\n\t\tenumerable: true,\n\t})\n}\n\nfunction makeCleanup<Result extends object>(\n\ttarget: Result,\n\teffectMap: Map<unknown, ScopedCallback>,\n\tonDispose: () => void,\n\tmetadata?: any\n): ProjectResult<Result> {\n\tif (metadata) {\n\t\tObject.defineProperty(target, projectionInfo, {\n\t\t\tvalue: metadata,\n\t\t\twritable: false,\n\t\t\tenumerable: false,\n\t\t\tconfigurable: true,\n\t\t})\n\t}\n\treturn cleanedBy(target, () => {\n\t\tonDispose()\n\t\tfor (const stop of effectMap.values()) stop?.()\n\t\teffectMap.clear()\n\t}) as ProjectResult<Result>\n}\n\nfunction projectArray<SourceValue, ResultValue>(\n\tsource: readonly SourceValue[],\n\tapply: ProjectCallback<SourceValue, number, ResultValue[], readonly SourceValue[], ResultValue>\n): ProjectResult<ResultValue[]> {\n\tsource = reactive(source)\n\tconst target = reactive([] as ResultValue[])\n\tconst indexEffects = new Map<number, ScopedCallback>()\n\n\tfunction normalizeTargetLength(length: number) {\n\t\tFoolProof.set(target as unknown as object, 'length', length, target)\n\t}\n\n\tfunction disposeIndex(index: number) {\n\t\tconst stopEffect = indexEffects.get(index)\n\t\tif (stopEffect) {\n\t\t\tindexEffects.delete(index)\n\t\t\tstopEffect()\n\t\t\tReflect.deleteProperty(target as unknown as object, index)\n\t\t}\n\t}\n\n\tconst parent = getActiveProjection()\n\tconst depth = parent ? parent.depth + 1 : 0\n\n\tconst cleanupLength = effect(function projectArrayLengthEffect({ ascend }) {\n\t\tconst length = source.length\n\t\tnormalizeTargetLength(length)\n\t\tconst existing = Array.from(indexEffects.keys())\n\t\tfor (let i = 0; i < length; i++) {\n\t\t\tif (indexEffects.has(i)) continue\n\t\t\tascend(() => {\n\t\t\t\tconst index = i\n\t\t\t\tconst stop = effect(function projectArrayIndexEffect() {\n\t\t\t\t\tconst previous = untracked(() => target[index])\n\t\t\t\t\tconst accessBase = {\n\t\t\t\t\t\tkey: index,\n\t\t\t\t\t\tsource,\n\t\t\t\t\t\tget: () => FoolProof.get(source as any, index, source),\n\t\t\t\t\t\tset: (value: SourceValue) =>\n\t\t\t\t\t\t\tFoolProof.set(source as any, index, value, source),\n\t\t\t\t\t\told: previous,\n\t\t\t\t\t} as ProjectAccess<SourceValue, number, readonly SourceValue[], ResultValue[]>\n\t\t\t\t\tdefineAccessValue(accessBase)\n\t\t\t\t\tconst produced = apply(accessBase, target)\n\t\t\t\t\ttarget[index] = produced\n\t\t\t\t})\n\t\t\t\tsetEffectName(stop, `project[${depth}]:${index}`)\n\t\t\t\teffectProjectionMetadata.set(stop, {\n\t\t\t\t\tsource,\n\t\t\t\t\tkey: index,\n\t\t\t\t\ttarget,\n\t\t\t\t\tdepth,\n\t\t\t\t\tparent,\n\t\t\t\t})\n\t\t\t\tindexEffects.set(i, stop)\n\t\t\t})\n\t\t}\n\t\tfor (const index of existing) if (index >= length) disposeIndex(index)\n\t})\n\n\treturn makeCleanup(target, indexEffects, () => cleanupLength(), {\n\t\tsource,\n\t\ttarget,\n\t\tapply,\n\t\tdepth,\n\t\tparent,\n\t} as ProjectionContext)\n}\n\nfunction projectRegister<Key extends PropertyKey, SourceValue, ResultValue>(\n\tsource: Register<SourceValue, Key>,\n\tapply: ProjectCallback<\n\t\tSourceValue,\n\t\tKey,\n\t\tMap<Key, ResultValue>,\n\t\tRegister<SourceValue, Key>,\n\t\tResultValue\n\t>\n): ProjectResult<Map<Key, ResultValue>> {\n\tconst observedSource = reactive(source) as Register<SourceValue, Key>\n\tconst rawTarget = new Map<Key, ResultValue>()\n\tconst target = reactive(rawTarget) as Map<Key, ResultValue>\n\tconst keyEffects = new Map<Key, ScopedCallback>()\n\n\tfunction disposeKey(key: Key) {\n\t\tconst stopEffect = keyEffects.get(key)\n\t\tif (stopEffect) {\n\t\t\tstopEffect()\n\t\t\tkeyEffects.delete(key)\n\t\t\ttarget.delete(key)\n\t\t}\n\t}\n\n\tconst parent = getActiveProjection()\n\tconst depth = parent ? parent.depth + 1 : 0\n\n\tconst cleanupKeys = effect(function projectRegisterEffect({ ascend }) {\n\t\tconst keys = new Set<Key>()\n\t\tfor (const key of observedSource.mapKeys()) keys.add(key)\n\n\t\tfor (const key of keys) {\n\t\t\tif (keyEffects.has(key)) continue\n\t\t\tascend(() => {\n\t\t\t\tconst stop = effect(function projectRegisterKeyEffect() {\n\t\t\t\t\tconst previous = untracked(() => target.get(key))\n\t\t\t\t\tconst accessBase = {\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tsource: observedSource,\n\t\t\t\t\t\tget: () => observedSource.get(key) as SourceValue,\n\t\t\t\t\t\tset: (value: SourceValue) => {\n\t\t\t\t\t\t\tobservedSource.set(key, value)\n\t\t\t\t\t\t\treturn true\n\t\t\t\t\t\t},\n\t\t\t\t\t\told: previous,\n\t\t\t\t\t} as ProjectAccess<SourceValue, Key, Register<SourceValue, Key>, Map<Key, ResultValue>>\n\t\t\t\t\tdefineAccessValue(accessBase)\n\t\t\t\t\tconst produced = apply(accessBase, target)\n\t\t\t\t\ttarget.set(key, produced)\n\t\t\t\t})\n\t\t\t\tsetEffectName(stop, `project[${depth}]:${String(key)}`)\n\t\t\t\teffectProjectionMetadata.set(stop, {\n\t\t\t\t\tsource: observedSource,\n\t\t\t\t\tkey,\n\t\t\t\t\ttarget,\n\t\t\t\t\tdepth,\n\t\t\t\t\tparent,\n\t\t\t\t})\n\t\t\t\tkeyEffects.set(key, stop)\n\t\t\t})\n\t\t}\n\n\t\tfor (const key of Array.from(keyEffects.keys())) if (!keys.has(key)) disposeKey(key)\n\t})\n\n\treturn makeCleanup(target, keyEffects, () => cleanupKeys(), {\n\t\tsource: observedSource,\n\t\ttarget,\n\t\tapply,\n\t\tdepth,\n\t\tparent,\n\t} as ProjectionContext)\n}\n\nfunction projectRecord<Source extends Record<PropertyKey, any>, ResultValue>(\n\tsource: Source,\n\tapply: ProjectCallback<\n\t\tSource[keyof Source],\n\t\tkeyof Source,\n\t\tRecord<keyof Source, ResultValue>,\n\t\tSource,\n\t\tResultValue\n\t>\n): ProjectResult<Record<keyof Source, ResultValue>> {\n\tconst observedSource = reactive(source) as Source\n\tconst target = reactive({} as Record<keyof Source, ResultValue>)\n\tconst keyEffects = new Map<PropertyKey, ScopedCallback>()\n\n\tfunction disposeKey(key: PropertyKey) {\n\t\tconst stopEffect = keyEffects.get(key)\n\t\tif (stopEffect) {\n\t\t\tstopEffect()\n\t\t\tkeyEffects.delete(key)\n\t\t\tReflect.deleteProperty(target as Record<PropertyKey, unknown>, key)\n\t\t}\n\t}\n\n\tconst parent = getActiveProjection()\n\tconst depth = parent ? parent.depth + 1 : 0\n\n\tconst cleanupKeys = effect(function projectRecordEffect({ ascend }) {\n\t\tconst keys = new Set<PropertyKey>()\n\t\tfor (const key in observedSource) keys.add(key)\n\t\tconst observed = Reflect.ownKeys(observedSource)\n\t\tfor (const key of observed) keys.add(key)\n\n\t\tfor (const key of keys) {\n\t\t\tif (keyEffects.has(key)) continue\n\t\t\tascend(() => {\n\t\t\t\tconst stop = effect(function projectRecordKeyEffect() {\n\t\t\t\t\tconst sourceKey = key as keyof Source\n\t\t\t\t\tconst previous = untracked(\n\t\t\t\t\t\t() => (target as Record<PropertyKey, ResultValue | undefined>)[key]\n\t\t\t\t\t)\n\t\t\t\t\tconst accessBase = {\n\t\t\t\t\t\tkey: sourceKey,\n\t\t\t\t\t\tsource: observedSource,\n\t\t\t\t\t\tget: () => FoolProof.get(observedSource, sourceKey, observedSource),\n\t\t\t\t\t\tset: (value: Source[typeof sourceKey]) =>\n\t\t\t\t\t\t\tFoolProof.set(observedSource, sourceKey, value, observedSource),\n\t\t\t\t\t\told: previous,\n\t\t\t\t\t} as ProjectAccess<\n\t\t\t\t\t\tSource[typeof sourceKey],\n\t\t\t\t\t\tkeyof Source,\n\t\t\t\t\t\tSource,\n\t\t\t\t\t\tRecord<keyof Source, ResultValue>\n\t\t\t\t\t>\n\t\t\t\t\tdefineAccessValue(accessBase)\n\t\t\t\t\tconst produced = apply(accessBase, target)\n\t\t\t\t\t;(target as any)[sourceKey] = produced\n\t\t\t\t})\n\t\t\t\tsetEffectName(stop, `project[${depth}]:${String(key)}`)\n\t\t\t\teffectProjectionMetadata.set(stop, {\n\t\t\t\t\tsource: observedSource,\n\t\t\t\t\tkey,\n\t\t\t\t\ttarget,\n\t\t\t\t\tdepth,\n\t\t\t\t\tparent,\n\t\t\t\t})\n\t\t\t\tkeyEffects.set(key, stop)\n\t\t\t})\n\t\t}\n\n\t\tfor (const key of Array.from(keyEffects.keys())) if (!keys.has(key)) disposeKey(key)\n\t})\n\n\treturn makeCleanup(target, keyEffects, () => cleanupKeys(), {\n\t\tsource: observedSource,\n\t\ttarget,\n\t\tapply,\n\t\tdepth,\n\t\tparent,\n\t} as ProjectionContext)\n}\n\nfunction projectMap<Key, Value, ResultValue>(\n\tsource: Map<Key, Value>,\n\tapply: ProjectCallback<Value, Key, Map<Key, ResultValue>, Map<Key, Value>, ResultValue>\n): ProjectResult<Map<Key, ResultValue>> {\n\tconst observedSource = reactive(source) as Map<Key, Value>\n\tconst rawTarget = new Map<Key, ResultValue>()\n\tconst target = reactive(rawTarget) as Map<Key, ResultValue>\n\tconst keyEffects = new Map<Key, ScopedCallback>()\n\n\tfunction disposeKey(key: Key) {\n\t\tconst stopEffect = keyEffects.get(key)\n\t\tif (stopEffect) {\n\t\t\tstopEffect()\n\t\t\tkeyEffects.delete(key)\n\t\t\ttarget.delete(key)\n\t\t}\n\t}\n\n\tconst parent = getActiveProjection()\n\tconst depth = parent ? parent.depth + 1 : 0\n\n\tconst cleanupKeys = effect(function projectMapEffect({ ascend }) {\n\t\tconst keys = new Set<Key>()\n\t\tfor (const key of observedSource.keys()) keys.add(key)\n\n\t\tfor (const key of keys) {\n\t\t\tif (keyEffects.has(key)) continue\n\t\t\tascend(() => {\n\t\t\t\tconst stop = effect(function projectMapKeyEffect() {\n\t\t\t\t\tconst previous = untracked(() => target.get(key))\n\t\t\t\t\tconst accessBase = {\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tsource: observedSource,\n\t\t\t\t\t\tget: () => observedSource.get(key) as Value,\n\t\t\t\t\t\tset: (value: Value) => {\n\t\t\t\t\t\t\tobservedSource.set(key, value)\n\t\t\t\t\t\t\treturn true\n\t\t\t\t\t\t},\n\t\t\t\t\t\told: previous,\n\t\t\t\t\t} as ProjectAccess<Value, Key, Map<Key, Value>, Map<Key, ResultValue>>\n\t\t\t\t\tdefineAccessValue(accessBase)\n\t\t\t\t\tconst produced = apply(accessBase, target)\n\t\t\t\t\ttarget.set(key, produced)\n\t\t\t\t})\n\t\t\t\tsetEffectName(stop, `project[${depth}]:${String(key)}`)\n\t\t\t\teffectProjectionMetadata.set(stop, {\n\t\t\t\t\tsource: observedSource,\n\t\t\t\t\tkey,\n\t\t\t\t\ttarget,\n\t\t\t\t\tdepth,\n\t\t\t\t\tparent,\n\t\t\t\t})\n\t\t\t\tkeyEffects.set(key, stop)\n\t\t\t})\n\t\t}\n\n\t\tfor (const key of Array.from(keyEffects.keys())) if (!keys.has(key)) disposeKey(key)\n\t})\n\n\treturn makeCleanup(target, keyEffects, () => cleanupKeys(), {\n\t\tsource: observedSource,\n\t\ttarget,\n\t\tapply,\n\t\tdepth,\n\t\tparent,\n\t} as ProjectionContext)\n}\n\ntype ProjectOverload = {\n\t<SourceValue, ResultValue>(\n\t\tsource: readonly SourceValue[],\n\t\tapply: ProjectCallback<SourceValue, number, ResultValue[], readonly SourceValue[], ResultValue>\n\t): ProjectResult<ResultValue[]>\n\t<Key extends PropertyKey, SourceValue, ResultValue>(\n\t\tsource: Register<SourceValue, Key>,\n\t\tapply: ProjectCallback<\n\t\t\tSourceValue,\n\t\t\tKey,\n\t\t\tMap<Key, ResultValue>,\n\t\t\tRegister<SourceValue, Key>,\n\t\t\tResultValue\n\t\t>\n\t): ProjectResult<Map<Key, ResultValue>>\n\t<Source extends Record<PropertyKey, any>, ResultValue>(\n\t\tsource: Source,\n\t\tapply: ProjectCallback<\n\t\t\tSource[keyof Source],\n\t\t\tkeyof Source,\n\t\t\tRecord<keyof Source, ResultValue>,\n\t\t\tSource,\n\t\t\tResultValue\n\t\t>\n\t): ProjectResult<Record<keyof Source, ResultValue>>\n\t<Key, Value, ResultValue>(\n\t\tsource: Map<Key, Value>,\n\t\tapply: ProjectCallback<Value, Key, Map<Key, ResultValue>, Map<Key, Value>, ResultValue>\n\t): ProjectResult<Map<Key, ResultValue>>\n\tarray: typeof projectArray\n\tregister: typeof projectRegister\n\trecord: typeof projectRecord\n\tmap: typeof projectMap\n}\n\nfunction projectCore<SourceValue, ResultValue>(\n\tsource: readonly SourceValue[],\n\tapply: ProjectCallback<SourceValue, number, ResultValue[], readonly SourceValue[], ResultValue>\n): ProjectResult<ResultValue[]>\nfunction projectCore<Key extends PropertyKey, SourceValue, ResultValue>(\n\tsource: Register<SourceValue, Key>,\n\tapply: ProjectCallback<\n\t\tSourceValue,\n\t\tKey,\n\t\tMap<Key, ResultValue>,\n\t\tRegister<SourceValue, Key>,\n\t\tResultValue\n\t>\n): ProjectResult<Map<Key, ResultValue>>\nfunction projectCore<Source extends Record<PropertyKey, any>, ResultValue>(\n\tsource: Source,\n\tapply: ProjectCallback<\n\t\tSource[keyof Source],\n\t\tkeyof Source,\n\t\tRecord<keyof Source, ResultValue>,\n\t\tSource,\n\t\tResultValue\n\t>\n): ProjectResult<Record<keyof Source, ResultValue>>\nfunction projectCore<Key, Value, ResultValue>(\n\tsource: Map<Key, Value>,\n\tapply: ProjectCallback<Value, Key, Map<Key, ResultValue>, Map<Key, Value>, ResultValue>\n): ProjectResult<Map<Key, ResultValue>>\nfunction projectCore(source: any, apply: any): ProjectResult<any> {\n\tif (Array.isArray(source)) return projectArray(source, apply)\n\tif (source instanceof Map) return projectMap(source, apply)\n\tif (source instanceof Register) return projectRegister(source, apply)\n\tif (source && (source.constructor === Object || source.constructor === undefined))\n\t\treturn projectRecord(source, apply)\n\tthrow new Error('Unsupported source type')\n}\n\nexport const project: ProjectOverload = Object.assign(projectCore, {\n\tarray: projectArray,\n\tregister: projectRegister,\n\trecord: projectRecord,\n\tmap: projectMap,\n})\n","import { FoolProof } from '../utils'\nimport { touched } from './change'\nimport { makeReactiveEntriesIterator, makeReactiveIterator } from './non-reactive'\nimport { reactive } from './proxy'\nimport { unwrap } from './proxy-state'\nimport { dependant } from './tracking'\n\nfunction* index(i: number, { length = true } = {}): IterableIterator<number | 'length'> {\n\tif (length) yield 'length'\n\tyield i\n}\n\nfunction* range(\n\ta: number,\n\tb: number,\n\t{ length = false } = {}\n): IterableIterator<number | 'length'> {\n\tconst start = Math.min(a, b)\n\tconst end = Math.max(a, b)\n\tif (length) yield 'length'\n\tfor (let i = start; i <= end; i++) yield i\n}\nexport abstract class Indexer extends Array {\n\tget(i: number): any {\n\t\tdependant(this, i)\n\t\treturn reactive(this[i])\n\t}\n\tset(i: number, value: any) {\n\t\tconst added = i >= this.length\n\t\tthis[i] = value\n\t\ttouched(this, { type: 'set', prop: i }, index(i, { length: added }))\n\t}\n\tgetLength() {\n\t\tdependant(this, 'length')\n\t\treturn this.length\n\t}\n\tsetLength(value: number) {\n\t\tconst oldLength = this.length\n\t\ttry {\n\t\t\tthis.length = value\n\t\t} finally {\n\t\t\ttouched(this, { type: 'set', prop: 'length' }, range(oldLength, value, { length: true }))\n\t\t}\n\t}\n}\nconst indexLess = { get: FoolProof.get, set: FoolProof.set }\nObject.assign(FoolProof, {\n\tget(obj: any, prop: any, receiver: any) {\n\t\tif (obj instanceof Array && typeof prop === 'string') {\n\t\t\tif (prop === 'length') return Indexer.prototype.getLength.call(obj)\n\t\t\tconst index = parseInt(prop)\n\t\t\tif (!Number.isNaN(index)) return Indexer.prototype.get.call(obj, index)\n\t\t}\n\t\treturn indexLess.get(obj, prop, receiver)\n\t},\n\tset(obj: any, prop: any, value: any, receiver: any) {\n\t\tif (obj instanceof Array && typeof prop === 'string') {\n\t\t\tif (prop === 'length') return Indexer.prototype.setLength.call(obj, value)\n\t\t\tconst index = parseInt(prop)\n\t\t\tif (!Number.isNaN(index)) return Indexer.prototype.set.call(obj, index, value)\n\t\t}\n\t\treturn indexLess.set(obj, prop, value, receiver)\n\t},\n})\n\nexport abstract class ReactiveArray extends Array {\n\ttoJSON() {\n\t\treturn this\n\t}\n\tget [Symbol.toStringTag]() {\n\t\treturn 'ReactiveArray'\n\t}\n\t// Safe array access with negative indices\n\tat(index: number): any {\n\t\tconst actualIndex = index < 0 ? this.length + index : index\n\t\tdependant(this, actualIndex)\n\t\tif (index < 0) dependant(this, 'length')\n\t\tif (actualIndex < 0 || actualIndex >= this.length) return undefined\n\t\treturn reactive(this[actualIndex])\n\t}\n\n\t// Immutable versions of mutator methods\n\ttoReversed(): any[] {\n\t\tdependant(this)\n\t\treturn reactive(this.toReversed())\n\t}\n\n\ttoSorted(compareFn?: (a: any, b: any) => number): any[] {\n\t\tdependant(this)\n\t\treturn reactive(this.toSorted(compareFn))\n\t}\n\n\ttoSpliced(start: number, deleteCount?: number, ...items: any[]): any[] {\n\t\tdependant(this)\n\t\treturn deleteCount === undefined\n\t\t\t? this.toSpliced(start)\n\t\t\t: this.toSpliced(start, deleteCount, ...items)\n\t}\n\n\twith(index: number, value: any): any[] {\n\t\tdependant(this)\n\t\treturn reactive(this.with(index, value))\n\t}\n\n\t// Iterator methods with reactivity tracking\n\tentries() {\n\t\tdependant(this)\n\t\treturn makeReactiveEntriesIterator(this.entries())\n\t}\n\n\tkeys() {\n\t\tdependant(this, 'length')\n\t\treturn this.keys()\n\t}\n\n\tvalues() {\n\t\tdependant(this)\n\t\treturn makeReactiveIterator(this.values())\n\t}\n\n\t[Symbol.iterator](): ArrayIterator<any> {\n\t\tdependant(this)\n\t\tconst nativeIterator = this[Symbol.iterator]()\n\t\treturn {\n\t\t\tnext() {\n\t\t\t\tconst result = nativeIterator.next()\n\t\t\t\tif (result.done) {\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t\treturn { value: reactive(result.value), done: false }\n\t\t\t},\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn this\n\t\t\t},\n\t\t\t[Symbol.dispose]() {},\n\t\t} as any\n\t}\n\n\tindexOf(searchElement: any, fromIndex?: number): number {\n\t\tconst length = this.length\n\t\tlet i = fromIndex === undefined ? 0 : fromIndex\n\t\tif (i < 0) i = Math.max(length + i, 0)\n\t\t\n\t\tconst unwrappedSearch = unwrap(searchElement)\n\n\t\tfor (; i < length; i++) {\n\t\t\tdependant(this, i)\n\t\t\tconst item = this[i]\n\t\t\tif (item === searchElement || item === unwrappedSearch || unwrap(item) === unwrappedSearch) {\n\t\t\t\treturn i\n\t\t\t}\n\t\t}\n\n\t\tdependant(this, 'length')\n\t\treturn -1\n\t}\n\n\tlastIndexOf(searchElement: any, fromIndex?: number): number {\n\t\tconst length = this.length\n\t\tlet i = fromIndex === undefined ? length - 1 : fromIndex\n\t\tif (i >= length) i = length - 1\n\t\tif (i < 0) i = Math.max(length + i, -1) // -1 ensures loop condition i >= 0 works correctly\n\n\t\tconst unwrappedSearch = unwrap(searchElement)\n\n\t\tfor (; i >= 0; i--) {\n\t\t\tdependant(this, i)\n\t\t\tconst item = this[i]\n\t\t\tif (item === searchElement || item === unwrappedSearch || unwrap(item) === unwrappedSearch) {\n\t\t\t\treturn i\n\t\t\t}\n\t\t}\n\n\t\t// If we scanned the whole relevant part and didn't find it, we depend on length \n\t\t// (because adding elements might shift indices or add the element)\n\t\t// Actually for lastIndexOf, if we start from end, length dependency is implicit in the start index calculation?\n\t\t// But if we return -1, it means we didn't find it.\n\t\t// If we push an element, should lastIndexOf update?\n\t\t// Yes, if the new element is the one we are looking for.\n\t\tdependant(this, 'length')\n\t\treturn -1\n\t}\n\n\tincludes(searchElement: any, fromIndex?: number): boolean {\n\t\treturn this.indexOf(searchElement, fromIndex) !== -1\n\t}\n\n\tfind(predicate: (this: any, value: any, index: number, obj: any[]) => boolean, thisArg?: any): any\n\tfind(searchElement: any, fromIndex?: number): any\n\tfind(predicateOrElement: any, thisArg?: any): any {\n\t\tif (typeof predicateOrElement === 'function') {\n\t\t\tconst predicate = predicateOrElement as (\n\t\t\t\tthis: any,\n\t\t\t\tvalue: any,\n\t\t\t\tindex: number,\n\t\t\t\tobj: any[]\n\t\t\t) => boolean\n\t\t\tconst length = this.length\n\n\t\t\tfor (let i = 0; i < length; i++) {\n\t\t\t\tdependant(this, i)\n\t\t\t\tconst val = reactive(this[i])\n\t\t\t\tif (predicate.call(thisArg, val, i, this)) {\n\t\t\t\t\treturn val\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdependant(this, 'length')\n\t\t\treturn undefined\n\t\t}\n\t\tconst fromIndex = typeof thisArg === 'number' ? thisArg : undefined\n\t\tconst index = this.indexOf(predicateOrElement, fromIndex)\n\t\tif (index === -1) return undefined\n\t\treturn reactive(this[index])\n\t}\n\n\tfindIndex(\n\t\tpredicate: (this: any, value: any, index: number, obj: any[]) => boolean,\n\t\tthisArg?: any\n\t): number\n\tfindIndex(searchElement: any, fromIndex?: number): number\n\tfindIndex(predicateOrElement: any, thisArg?: any): number {\n\t\tif (typeof predicateOrElement === 'function') {\n\t\t\tconst predicate = predicateOrElement as (\n\t\t\t\tthis: any,\n\t\t\t\tvalue: any,\n\t\t\t\tindex: number,\n\t\t\t\tobj: any[]\n\t\t\t) => boolean\n\t\t\tconst length = this.length\n\n\t\t\tfor (let i = 0; i < length; i++) {\n\t\t\t\tdependant(this, i)\n\t\t\t\tconst val = reactive(this[i])\n\t\t\t\tif (predicate.call(thisArg, val, i, this)) {\n\t\t\t\t\treturn i\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdependant(this, 'length')\n\t\t\treturn -1\n\t\t}\n\t\tconst fromIndex = typeof thisArg === 'number' ? thisArg : undefined\n\t\treturn this.indexOf(predicateOrElement, fromIndex)\n\t}\n\n\tflat(depth?: number): any[] {\n\t\tdependant(this)\n\t\treturn reactive(depth === undefined ? this.flat() : this.flat(depth))\n\t}\n\n\tflatMap(\n\t\tcallbackfn: (this: any, value: any, index: number, array: any[]) => any[],\n\t\tthisArg?: any\n\t): any[] {\n\t\tdependant(this)\n\t\treturn reactive(\n\t\t\tthis.flatMap(\n\t\t\t\t(item, index, array) => callbackfn.call(thisArg, reactive(item), index, array),\n\t\t\t\tthisArg\n\t\t\t)\n\t\t)\n\t}\n\n\tfilter(callbackfn: (value: any, index: number, array: any[]) => boolean, thisArg?: any): any[] {\n\t\tdependant(this)\n\t\treturn reactive(\n\t\t\tthis.filter((item, index, array) => callbackfn(reactive(item), index, array), thisArg)\n\t\t)\n\t}\n\n\tmap(callbackfn: (value: any, index: number, array: any[]) => any, thisArg?: any): any[] {\n\t\tdependant(this)\n\t\treturn reactive(\n\t\t\tthis.map((item, index, array) => callbackfn(reactive(item), index, array), thisArg)\n\t\t)\n\t}\n\n\treduce(\n\t\tcallbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\tdependant(this)\n\t\tconst result =\n\t\t\tinitialValue === undefined\n\t\t\t\t? this.reduce(callbackfn as any)\n\t\t\t\t: this.reduce(callbackfn as any, initialValue)\n\t\treturn reactive(result)\n\t}\n\n\treduceRight(\n\t\tcallbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any,\n\t\tinitialValue?: any\n\t): any {\n\t\tdependant(this)\n\t\tconst result =\n\t\t\tinitialValue !== undefined\n\t\t\t\t? this.reduceRight(callbackfn as any, initialValue)\n\t\t\t\t: (this as any).reduceRight(callbackfn as any)\n\t\treturn reactive(result)\n\t}\n\n\tslice(start?: number, end?: number): any[] {\n\t\tfor (const i of range(start || 0, end || this.length - 1)) dependant(this, i)\n\t\treturn start === undefined\n\t\t\t? this.slice()\n\t\t\t: end === undefined\n\t\t\t\t? this.slice(start)\n\t\t\t\t: this.slice(start, end)\n\t}\n\n\tconcat(...items: any[]): any[] {\n\t\tdependant(this)\n\t\treturn reactive(this.concat(...items))\n\t}\n\n\tjoin(separator?: string): string {\n\t\tdependant(this)\n\t\treturn this.join(separator as any)\n\t}\n\n\tforEach(callbackfn: (value: any, index: number, array: any[]) => void, thisArg?: any): void {\n\t\tdependant(this)\n\t\tthis.forEach((value, index, array) => {\n\t\t\tcallbackfn.call(thisArg, reactive(value), index, array)\n\t\t})\n\t}\n\n\t// no need to make it dependant on indexes after the found one\n\tevery<S>(\n\t\tpredicate: (value: any, index: number, array: any[]) => value is S,\n\t\tthisArg?: any\n\t): this is S[]\n\tevery(callbackfn: (value: any, index: number, array: any[]) => boolean, thisArg?: any): boolean\n\tevery(callbackfn: (value: any, index: number, array: any[]) => boolean, thisArg?: any): boolean {\n\t\tconst length = this.length\n\n\t\tfor (let i = 0; i < length; i++) {\n\t\t\tdependant(this, i)\n\t\t\tif (!callbackfn.call(thisArg, reactive(this[i]), i, this)) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\n\t\tdependant(this, 'length')\n\t\treturn true\n\t}\n\n\tsome(callbackfn: (value: any, index: number, array: any[]) => boolean, thisArg?: any): boolean {\n\t\tconst length = this.length\n\n\t\tfor (let i = 0; i < length; i++) {\n\t\t\tdependant(this, i)\n\t\t\tif (callbackfn.call(thisArg, reactive(this[i]), i, this)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\n\t\tdependant(this, 'length')\n\t\treturn false\n\t}\n\t// Side-effectful\n\tpush(...items: any[]) {\n\t\tconst oldLength = this.length\n\t\ttry {\n\t\t\treturn this.push(...items)\n\t\t} finally {\n\t\t\ttouched(\n\t\t\t\tthis,\n\t\t\t\t{ type: 'bunch', method: 'push' },\n\t\t\t\trange(oldLength, oldLength + items.length - 1, { length: true })\n\t\t\t)\n\t\t}\n\t}\n\n\tpop() {\n\t\tif (this.length === 0) return undefined\n\t\ttry {\n\t\t\treturn reactive(this.pop())\n\t\t} finally {\n\t\t\ttouched(this, { type: 'bunch', method: 'pop' }, index(this.length))\n\t\t}\n\t}\n\n\tshift() {\n\t\tif (this.length === 0) return undefined\n\t\ttry {\n\t\t\treturn reactive(this.shift())\n\t\t} finally {\n\t\t\ttouched(this, { type: 'bunch', method: 'shift' }, range(0, this.length + 1, { length: true }))\n\t\t}\n\t}\n\n\tunshift(...items: any[]) {\n\t\ttry {\n\t\t\treturn this.unshift(...items)\n\t\t} finally {\n\t\t\ttouched(\n\t\t\t\tthis,\n\t\t\t\t{ type: 'bunch', method: 'unshift' },\n\t\t\t\trange(0, this.length - items.length, { length: true })\n\t\t\t)\n\t\t}\n\t}\n\n\tsplice(start: number, deleteCount?: number, ...items: any[]) {\n\t\tconst oldLength = this.length\n\n\t\t// Normalize start index\n\t\tlet actualStart = start\n\t\tif (actualStart < 0) actualStart = Math.max(oldLength + actualStart, 0)\n\t\telse actualStart = Math.min(actualStart, oldLength)\n\n\t\t// Normalize deleteCount\n\t\tlet actualDeleteCount = deleteCount\n\t\tif (actualDeleteCount === undefined) {\n\t\t\tactualDeleteCount = oldLength - actualStart\n\t\t} else {\n\t\t\tactualDeleteCount = Math.max(0, Math.min(actualDeleteCount, oldLength - actualStart))\n\t\t}\n\n\t\ttry {\n\t\t\tif (deleteCount === undefined) return reactive(this.splice(start))\n\t\t\treturn reactive(this.splice(start, deleteCount, ...items))\n\t\t} finally {\n\t\t\ttouched(\n\t\t\t\tthis,\n\t\t\t\t{ type: 'bunch', method: 'splice' },\n\t\t\t\tactualDeleteCount === items.length\n\t\t\t\t\t? range(actualStart, actualStart + actualDeleteCount - 1)\n\t\t\t\t\t: range(actualStart, oldLength + Math.max(items.length - actualDeleteCount, 0), {\n\t\t\t\t\t\t\tlength: true,\n\t\t\t\t\t\t})\n\t\t\t)\n\t\t}\n\t}\n\n\treverse() {\n\t\ttry {\n\t\t\treturn this.reverse()\n\t\t} finally {\n\t\t\ttouched(this, { type: 'bunch', method: 'reverse' }, range(0, this.length - 1))\n\t\t}\n\t}\n\n\tsort(compareFn?: (a: any, b: any) => number) {\n\t\tcompareFn = compareFn || ((a, b) => a.toString().localeCompare(b.toString()))\n\t\ttry {\n\t\t\treturn this.sort((a, b) => compareFn(reactive(a), reactive(b))) as any\n\t\t} finally {\n\t\t\ttouched(this, { type: 'bunch', method: 'sort' }, range(0, this.length - 1))\n\t\t}\n\t}\n\n\tfill(value: any, start?: number, end?: number) {\n\t\tconst len = this.length\n\t\tlet k = start === undefined ? 0 : start\n\t\tif (k < 0) k = Math.max(len + k, 0)\n\t\telse k = Math.min(k, len)\n\n\t\tlet final = end === undefined ? len : end\n\t\tif (final < 0) final = Math.max(len + final, 0)\n\t\telse final = Math.min(final, len)\n\n\t\ttry {\n\t\t\tif (start === undefined) return this.fill(value) as any\n\t\t\tif (end === undefined) return this.fill(value, start) as any\n\t\t\treturn this.fill(value, start, end) as any\n\t\t} finally {\n\t\t\tif (final > k) {\n\t\t\t\ttouched(this, { type: 'bunch', method: 'fill' }, range(k, final - 1))\n\t\t\t}\n\t\t}\n\t}\n\n\tcopyWithin(target: number, start: number, end?: number) {\n\t\ttry {\n\t\t\tif (end === undefined) return this.copyWithin(target, start) as any\n\t\t\treturn this.copyWithin(target, start, end) as any\n\t\t} finally {\n\t\t\tconst len = this.length\n\n\t\t\tlet to = target\n\t\t\tif (to < 0) to = Math.max(len + to, 0)\n\t\t\telse if (to >= len) to = len\n\n\t\t\tlet from = start\n\t\t\tif (from < 0) from = Math.max(len + from, 0)\n\t\t\telse if (from >= len) from = len\n\n\t\t\tlet final = end === undefined ? len : end\n\t\t\tif (final < 0) final = Math.max(len + final, 0)\n\t\t\telse if (final >= len) final = len\n\n\t\t\tconst count = Math.min(final - from, len - to)\n\n\t\t\tif (count > 0) {\n\t\t\t\ttouched(\n\t\t\t\t\tthis,\n\t\t\t\t\t{ type: 'bunch', method: 'copyWithin' },\n\t\t\t\t\trange(to, to + count - 1)\n\t\t\t\t)\n\t\t\t}\n\n\t\t}\n\t}\n}\n","import { contentRef } from '../utils'\nimport { touched, touched1 } from './change'\nimport { notifyPropertyChange } from './deep-touch'\nimport { makeReactiveEntriesIterator, makeReactiveIterator } from './non-reactive'\nimport { reactive } from './proxy'\nimport { dependant } from './tracking'\n\n/**\n * Reactive wrapper around JavaScript's WeakMap class\n * Only tracks individual key operations, no size tracking (WeakMap limitation)\n */\nexport abstract class ReactiveWeakMap<K extends object, V> extends WeakMap<K, V> {\n\tget [Symbol.toStringTag]() {\n\t\treturn 'ReactiveWeakMap'\n\t}\n\n\t// Implement WeakMap interface methods with reactivity\n\tdelete(key: K): boolean {\n\t\tconst hadKey = this.has(key)\n\t\tconst result = this.delete(key)\n\n\t\tif (hadKey) touched1(contentRef(this), { type: 'del', prop: key }, key)\n\n\t\treturn result\n\t}\n\n\tget(key: K): V | undefined {\n\t\tdependant(contentRef(this), key)\n\t\treturn reactive(this.get(key))\n\t}\n\n\thas(key: K): boolean {\n\t\tdependant(contentRef(this), key)\n\t\treturn this.has(key)\n\t}\n\n\tset(key: K, value: V): this {\n\t\tconst hadKey = this.has(key)\n\t\tconst oldValue = this.get(key)\n\t\tconst reactiveValue = reactive(value)\n\t\tthis.set(key, reactiveValue)\n\n\t\tif (!hadKey || oldValue !== reactiveValue) {\n\t\t\tnotifyPropertyChange(contentRef(this), key, oldValue, reactiveValue, hadKey)\n\t\t}\n\n\t\treturn this\n\t}\n}\n\n/**\n * Reactive wrapper around JavaScript's Map class\n * Tracks size changes, individual key operations, and collection-wide operations\n */\nexport abstract class ReactiveMap<K, V> extends Map<K, V> {\n\tget [Symbol.toStringTag]() {\n\t\treturn 'ReactiveMap'\n\t}\n\n\t// Implement Map interface methods with reactivity\n\tget size(): number {\n\t\tdependant(this, 'size') // The ReactiveMap instance still goes through proxy\n\t\treturn this.size\n\t}\n\n\tclear(): void {\n\t\tconst hadEntries = this.size > 0\n\t\tthis.clear()\n\n\t\tif (hadEntries) {\n\t\t\tconst evolution = { type: 'bunch', method: 'clear' } as const\n\t\t\t// Clear triggers all effects since all keys are affected\n\t\t\ttouched1(this, evolution, 'size')\n\t\t\ttouched(contentRef(this), evolution)\n\t\t}\n\t}\n\n\tentries(): Generator<[K, V]> {\n\t\tdependant(contentRef(this))\n\t\treturn makeReactiveEntriesIterator(this.entries())\n\t}\n\n\tforEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void {\n\t\tdependant(contentRef(this))\n\t\tthis.forEach(callbackfn, thisArg)\n\t}\n\n\tkeys(): MapIterator<K> {\n\t\tdependant(contentRef(this))\n\t\treturn this.keys()\n\t}\n\n\tvalues(): Generator<V> {\n\t\tdependant(contentRef(this))\n\t\treturn makeReactiveIterator(this.values())\n\t}\n\n\t[Symbol.iterator](): MapIterator<[K, V]> {\n\t\tdependant(contentRef(this))\n\t\tconst nativeIterator = this[Symbol.iterator]()\n\t\treturn {\n\t\t\tnext() {\n\t\t\t\tconst result = nativeIterator.next()\n\t\t\t\tif (result.done) {\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tvalue: [result.value[0], reactive(result.value[1])],\n\t\t\t\t\tdone: false,\n\t\t\t\t}\n\t\t\t},\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn this\n\t\t\t},\n\t\t\t[Symbol.dispose]() {},\n\t\t} as any // TODO: real iterator? (If easy)\n\t}\n\n\t// Implement Map methods with reactivity\n\tdelete(key: K): boolean {\n\t\tconst hadKey = this.has(key)\n\t\tconst result = this.delete(key)\n\n\t\tif (hadKey) {\n\t\t\tconst evolution = { type: 'del', prop: key } as const\n\t\t\ttouched1(contentRef(this), evolution, key)\n\t\t\ttouched1(this, evolution, 'size')\n\t\t}\n\n\t\treturn result\n\t}\n\n\tget(key: K): V | undefined {\n\t\tdependant(contentRef(this), key)\n\t\treturn reactive(this.get(key))\n\t}\n\n\thas(key: K): boolean {\n\t\tdependant(contentRef(this), key)\n\t\treturn this.has(key)\n\t}\n\n\tset(key: K, value: V): this {\n\t\tconst hadKey = this.has(key)\n\t\tconst oldValue = this.get(key)\n\t\tconst reactiveValue = reactive(value)\n\t\tthis.set(key, reactiveValue)\n\n\t\tif (!hadKey || oldValue !== reactiveValue) {\n\t\t\tnotifyPropertyChange(contentRef(this), key, oldValue, reactiveValue, hadKey)\n\t\t\t// Also notify size change for Map (WeakMap doesn't track size)\n\t\t\tconst evolution = { type: hadKey ? 'set' : 'add', prop: key } as const\n\t\t\ttouched1(this, evolution, 'size')\n\t\t}\n\n\t\treturn this\n\t}\n}\n","import { contentRef } from '../utils'\nimport { touched, touched1 } from './change'\nimport { makeReactiveEntriesIterator, makeReactiveIterator } from './non-reactive'\nimport { reactive } from './proxy'\nimport { dependant } from './tracking'\n\n/**\n * Reactive wrapper around JavaScript's WeakSet class\n * Only tracks individual value operations, no size tracking (WeakSet limitation)\n */\nexport abstract class ReactiveWeakSet<T extends object> extends WeakSet<T> {\n\tget [Symbol.toStringTag]() {\n\t\treturn 'ReactiveWeakSet'\n\t}\n\tadd(value: T): this {\n\t\tconst had = this.has(value)\n\t\tthis.add(value)\n\t\tif (!had) {\n\t\t\t// touch the specific value and the collection view\n\t\t\ttouched1(contentRef(this), { type: 'add', prop: value }, value)\n\t\t\t// no size/allProps for WeakSet\n\t\t}\n\t\treturn this\n\t}\n\n\tdelete(value: T): boolean {\n\t\tconst had = this.has(value)\n\t\tconst res = this.delete(value)\n\t\tif (had) touched1(contentRef(this), { type: 'del', prop: value }, value)\n\t\treturn res\n\t}\n\n\thas(value: T): boolean {\n\t\tdependant(contentRef(this), value)\n\t\treturn this.has(value)\n\t}\n}\n\n/**\n * Reactive wrapper around JavaScript's Set class\n * Tracks size changes, individual value operations, and collection-wide operations\n */\nexport abstract class ReactiveSet<T> extends Set<T> {\n\tget [Symbol.toStringTag]() {\n\t\treturn 'ReactiveSet'\n\t}\n\n\tget size(): number {\n\t\t// size depends on the wrapper instance, like Map counterpart\n\t\tdependant(this, 'size')\n\t\treturn this.size\n\t}\n\n\tadd(value: T): this {\n\t\tconst had = this.has(value)\n\t\tconst reactiveValue = reactive(value)\n\t\tthis.add(reactiveValue)\n\t\tif (!had) {\n\t\t\tconst evolution = { type: 'add', prop: reactiveValue } as const\n\t\t\t// touch for value-specific and aggregate dependencies\n\t\t\ttouched1(contentRef(this), evolution, reactiveValue)\n\t\t\ttouched1(this, evolution, 'size')\n\t\t}\n\t\treturn this\n\t}\n\n\tclear(): void {\n\t\tconst hadEntries = this.size > 0\n\t\tthis.clear()\n\t\tif (hadEntries) {\n\t\t\tconst evolution = { type: 'bunch', method: 'clear' } as const\n\t\t\ttouched1(this, evolution, 'size')\n\t\t\ttouched(contentRef(this), evolution)\n\t\t}\n\t}\n\n\tdelete(value: T): boolean {\n\t\tconst had = this.has(value)\n\t\tconst res = this.delete(value)\n\t\tif (had) {\n\t\t\tconst evolution = { type: 'del', prop: value } as const\n\t\t\ttouched1(contentRef(this), evolution, value)\n\t\t\ttouched1(this, evolution, 'size')\n\t\t}\n\t\treturn res\n\t}\n\n\thas(value: T): boolean {\n\t\tdependant(contentRef(this), value)\n\t\treturn this.has(value)\n\t}\n\n\tentries(): Generator<[T, T]> {\n\t\tdependant(contentRef(this))\n\t\treturn makeReactiveEntriesIterator(this.entries())\n\t}\n\n\tforEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void {\n\t\tdependant(contentRef(this))\n\t\tthis.forEach(callbackfn, thisArg)\n\t}\n\n\tkeys(): Generator<T> {\n\t\tdependant(contentRef(this))\n\t\treturn makeReactiveIterator(this.keys())\n\t}\n\n\tvalues(): Generator<T> {\n\t\tdependant(contentRef(this))\n\t\treturn makeReactiveIterator(this.values())\n\t}\n\n\t[Symbol.iterator](): SetIterator<T> {\n\t\tdependant(contentRef(this))\n\t\tconst nativeIterator = this[Symbol.iterator]()\n\t\treturn {\n\t\t\tnext() {\n\t\t\t\tconst result = nativeIterator.next()\n\t\t\t\tif (result.done) {\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t\treturn { value: reactive(result.value), done: false }\n\t\t\t},\n\t\t\t[Symbol.iterator]() {\n\t\t\t\treturn this\n\t\t\t},\n\t\t\t[Symbol.dispose]() {},\n\t\t} as any\t//TODO? (something easy)\n\t}\n}\n","export { getState, touched, touched1 } from './change'\nexport type { ReactivityGraph } from './debug'\nexport {\n\tbuildReactivityGraph,\n\tenableDevTools,\n\tisDevtoolsEnabled,\n\tregisterEffectForDebug,\n\tregisterObjectForDebug,\n\tsetEffectName,\n\tsetObjectName,\n} from './debug'\nexport { deepWatch } from './deep-watch'\nexport {\n\taddBatchCleanup,\n\tatomic,\n\tbiDi,\n\tdefer,\n\teffect,\n\tgetActivationLog,\n\troot,\n\ttrackEffect,\n\tuntracked,\n} from './effects'\nexport { cleanedBy, cleanup, derived, unreactive, watch } from './interface'\nexport { type Memoizable, memoize } from './memoize'\nexport { immutables, isNonReactive, registerNativeReactivity } from './non-reactive'\nexport { getActiveProjection, project } from './project'\nexport { isReactive, ReactiveBase, reactive, unwrap } from './proxy'\nexport { organize, organized } from './record'\nexport { scan, type ScanResult, resolve } from './buffer'\nexport { Register, register } from './register'\nexport { getActiveEffect, effectAggregator } from './effect-context'\nexport {\n\ttype DependencyAccess,\n\ttype Evolution,\n\toptions as reactiveOptions,\n\tReactiveError,\n\tReactiveErrorCode,\n\ttype ScopedCallback,\n} from './types'\n\nimport { ReactiveArray } from './array'\nimport {\n\tdeepWatchers,\n\teffectToDeepWatchedObjects,\n\tobjectParents,\n\tobjectsWithDeepWatchers,\n} from './deep-watch'\nimport { ReactiveMap, ReactiveWeakMap } from './map'\nimport { nonReactiveObjects } from './non-reactive-state'\nimport { metaProtos, objectToProxy, proxyToObject } from './proxy'\nimport { effectToReactiveObjects, watchers } from './registry'\nimport { ReactiveSet, ReactiveWeakSet } from './set'\n\n// Register native collection types to use specialized reactive wrappers\nmetaProtos.set(Array, ReactiveArray.prototype)\nmetaProtos.set(Set, ReactiveSet.prototype)\nmetaProtos.set(WeakSet, ReactiveWeakSet.prototype)\nmetaProtos.set(Map, ReactiveMap.prototype)\nmetaProtos.set(WeakMap, ReactiveWeakMap.prototype)\n\n/**\n * Object containing internal reactive system state for debugging and profiling\n */\nexport const profileInfo: any = {\n\tobjectToProxy,\n\tproxyToObject,\n\teffectToReactiveObjects,\n\twatchers,\n\tobjectParents,\n\tobjectsWithDeepWatchers,\n\tdeepWatchers,\n\teffectToDeepWatchedObjects,\n\tnonReactiveObjects,\n}\n","import { decorator, type GenericClassDecorator } from './decorator'\n\n// In order to avoid async re-entrance, we could use zone.js or something like that.\nconst syncCalculating: { object: object; prop: PropertyKey }[] = []\n/**\n * Decorator that caches the result of a getter method and only recomputes when dependencies change\n * Prevents circular dependencies and provides automatic cache invalidation\n */\nexport const cached = decorator({\n\tgetter(original, _target, propertyKey) {\n\t\treturn function (this: any) {\n\t\t\tconst alreadyCalculating = syncCalculating.findIndex(\n\t\t\t\t(c) => c.object === this && c.prop === propertyKey\n\t\t\t)\n\t\t\tif (alreadyCalculating > -1)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Circular dependency detected: ${syncCalculating\n\t\t\t\t\t\t.slice(alreadyCalculating)\n\t\t\t\t\t\t.map((c) => `${c.object.constructor.name}.${String(c.prop)}`)\n\t\t\t\t\t\t.join(' -> ')} -> again`\n\t\t\t\t)\n\t\t\tsyncCalculating.push({ object: this, prop: propertyKey })\n\t\t\ttry {\n\t\t\t\tconst rv = original.call(this)\n\t\t\t\tcache(this, propertyKey, rv)\n\t\t\t\treturn rv\n\t\t\t} finally {\n\t\t\t\tsyncCalculating.pop()\n\t\t\t}\n\t\t}\n\t},\n})\n\n/**\n * Checks if a property is cached (has a cached value)\n * @param object - The object to check\n * @param propertyKey - The property key to check\n * @returns True if the property has a cached value\n */\nexport function isCached(object: Object, propertyKey: PropertyKey) {\n\treturn !!Object.getOwnPropertyDescriptor(object, propertyKey)\n}\n\n/**\n * Caches a value for a property on an object\n * @param object - The object to cache the value on\n * @param propertyKey - The property key to cache\n * @param value - The value to cache\n */\nexport function cache(object: Object, propertyKey: PropertyKey, value: any) {\n\tObject.defineProperty(object, propertyKey, { value })\n}\n\n/**\n * Creates a decorator that modifies property descriptors for specified properties\n * @param descriptor - The descriptor properties to apply\n * @returns A class decorator that applies the descriptor to specified properties\n */\nexport function describe(descriptor: {\n\tenumerable?: boolean\n\tconfigurable?: boolean // Not modifiable once the property has been defined ?\n\twritable?: boolean\n}) {\n\treturn <T>(...properties: (keyof T)[]): GenericClassDecorator<T> =>\n\t\t(Base) => {\n\t\t\treturn class extends Base {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tfor (const key of properties) {\n\t\t\t\t\t\tObject.defineProperty(this, key, {\n\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptor(this, key),\n\t\t\t\t\t\t\t...descriptor,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n}\n\n/**\n * Decorator that marks methods, properties, or classes as deprecated\n * Provides warning messages when deprecated items are used\n */\nexport const deprecated = Object.assign(\n\tdecorator({\n\t\tmethod(original, _target, propertyKey) {\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.apply(this, args)\n\t\t\t}\n\t\t},\n\t\tgetter(original, _target, propertyKey) {\n\t\t\treturn function (this: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this)\n\t\t\t}\n\t\t},\n\t\tsetter(original, _target, propertyKey) {\n\t\t\treturn function (this: any, value: any) {\n\t\t\t\tdeprecated.warn(this, propertyKey)\n\t\t\t\treturn original.call(this, value)\n\t\t\t}\n\t\t},\n\t\tclass(original) {\n\t\t\treturn class extends original {\n\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\tsuper(...args)\n\t\t\t\t\tdeprecated.warn(this, 'constructor')\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tdefault(message: string) {\n\t\t\treturn decorator({\n\t\t\t\tmethod(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tgetter(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tsetter(original, _target, propertyKey) {\n\t\t\t\t\treturn function (this: any, value: any) {\n\t\t\t\t\t\tdeprecated.warn(this, propertyKey, message)\n\t\t\t\t\t\treturn original.call(this, value)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tclass(original) {\n\t\t\t\t\treturn class extends original {\n\t\t\t\t\t\tconstructor(...args: any[]) {\n\t\t\t\t\t\t\tsuper(...args)\n\t\t\t\t\t\t\tdeprecated.warn(this, 'constructor', message)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t})\n\t\t},\n\t}),\n\t{\n\t\twarn: (target: any, propertyKey: PropertyKey, message?: string) => {\n\t\t\t// biome-ignore lint/suspicious/noConsole: To be overridden\n\t\t\tconsole.warn(\n\t\t\t\t`${target.constructor.name}.${String(propertyKey)} is deprecated${message ? `: ${message}` : ''}`\n\t\t\t)\n\t\t},\n\t}\n)\n\n/**\n * Creates a debounced method decorator that delays execution until after the delay period has passed\n * @param delay - The delay in milliseconds\n * @returns A method decorator that debounces method calls\n */\nexport function debounce(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _target, _propertyKey) {\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\t// Clear existing timeout\n\t\t\t\tif (timeoutId) {\n\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t}\n\n\t\t\t\t// Set new timeout\n\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\toriginal.apply(this, args)\n\t\t\t\t\ttimeoutId = null\n\t\t\t\t}, delay)\n\t\t\t}\n\t\t},\n\t})\n}\n\n/**\n * Creates a throttled method decorator that limits execution to once per delay period\n * @param delay - The delay in milliseconds\n * @returns A method decorator that throttles method calls\n */\nexport function throttle(delay: number) {\n\treturn decorator({\n\t\tmethod(original, _target, _propertyKey) {\n\t\t\tlet lastCallTime = 0\n\t\t\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\t\t\treturn function (this: any, ...args: any[]) {\n\t\t\t\tconst now = Date.now()\n\n\t\t\t\t// If enough time has passed since last call, execute immediately\n\t\t\t\tif (now - lastCallTime >= delay) {\n\t\t\t\t\t// Clear any pending timeout since we're executing now\n\t\t\t\t\tif (timeoutId) {\n\t\t\t\t\t\tclearTimeout(timeoutId)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}\n\t\t\t\t\tlastCallTime = now\n\t\t\t\t\treturn original.apply(this, args)\n\t\t\t\t}\n\n\t\t\t\t// Otherwise, schedule execution for when the delay period ends\n\t\t\t\tif (!timeoutId) {\n\t\t\t\t\tconst remainingTime = delay - (now - lastCallTime)\n\t\t\t\t\tconst scheduledArgs = [...args] // Capture args at scheduling time\n\t\t\t\t\ttimeoutId = setTimeout(() => {\n\t\t\t\t\t\tlastCallTime = Date.now()\n\t\t\t\t\t\toriginal.apply(this, scheduledArgs)\n\t\t\t\t\t\ttimeoutId = null\n\t\t\t\t\t}, remainingTime)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t})\n}\n","export * from './decorator'\nexport * from './destroyable'\nexport * from './eventful'\nexport * from './indexable'\nexport * from './iterableWeak'\nexport * from './mixins'\nexport * from './promiseChain'\nexport * from './reactive'\nexport * from './std-decorators'\nexport * from './utils'\nexport * from './zone'\nexport * from './async'\n\nimport pkg from '../package.json'\n\nconst { version } = pkg\n\n// Singleton verification\nconst GLOBAL_MUTTS_KEY = '__MUTTS_INSTANCE__'\nconst globalScope = (\n\ttypeof globalThis !== 'undefined'\n\t\t? globalThis\n\t\t: typeof window !== 'undefined'\n\t\t\t? window\n\t\t\t: typeof global !== 'undefined'\n\t\t\t\t? global\n\t\t\t\t: false\n) as any\nif (globalScope) {\n\t// Detect the source of this instance safely across different environments\n\tlet source = 'mutts/index'\n\tconst viteEval = eval\n\ttry {\n\t\t// @ts-ignore\n\t\tif (typeof __filename !== 'undefined') source = __filename\n\t\telse {\n\t\t\t// Using eval to avoid SyntaxError in CJS environments where import.meta is not allowed\n\t\t\tconst meta = viteEval('import.meta')\n\t\t\tif (meta && meta.url) source = meta.url\n\t\t}\n\t} catch (e) {\n\t\t// Fallback for environments where neither is available or accessible\n\t}\n\n\tconst currentSourceInfo = {\n\t\tversion,\n\t\tsource,\n\t\ttimestamp: Date.now(),\n\t}\n\n\tif (globalScope[GLOBAL_MUTTS_KEY]) {\n\t\tconst existing = globalScope[GLOBAL_MUTTS_KEY]\n\t\tthrow new Error(\n\t\t\t`[Mutts] Multiple instances detected!\\n` +\n\t\t\t\t`Existing instance: ${JSON.stringify(existing, null, 2)}\\n` +\n\t\t\t\t`New instance: ${JSON.stringify(currentSourceInfo, null, 2)}\\n` +\n\t\t\t\t`This usually happens when 'mutts' is both installed as a dependency and bundled, ` +\n\t\t\t\t`or when different versions are loaded. ` +\n\t\t\t\t`Please check your build configuration (aliases, externals) to ensure a single source of truth.`\n\t\t)\n\t}\n\n\tglobalScope[GLOBAL_MUTTS_KEY] = currentSourceInfo\n}\n","/**\n * Base type for event maps - all event handlers must be functions\n */\nexport type EventsBase = Record<string, (...args: any[]) => void>\n/**\n * A type-safe event system that provides a clean API for event handling\n * @template Events - The event map defining event names and their handler signatures\n */\nexport class Eventful<Events extends EventsBase> {\n\treadonly #events = new Map<keyof Events, ((...args: any[]) => void)[]>()\n\treadonly #hooks = [] as ((...args: any[]) => void)[]\n\n\tpublic hook(\n\t\tcb: <EventType extends keyof Events>(\n\t\t\tevent: EventType,\n\t\t\t...args: Parameters<Events[EventType]>\n\t\t) => void\n\t): () => void {\n\t\tif (!this.#hooks.includes(cb)) this.#hooks.push(cb)\n\t\treturn () => {\n\t\t\tthis.#hooks.splice(this.#hooks.indexOf(cb), 1)\n\t\t}\n\t}\n\n\tpublic on(events: Partial<Events>): void\n\tpublic on<EventType extends keyof Events>(event: EventType, cb: Events[EventType]): () => void\n\tpublic on<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): () => void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.on(e, eventOrEvents[e]!)\n\t\t\t}\n\t\t} else if (cb !== undefined) {\n\t\t\tlet callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (!callbacks) {\n\t\t\t\tcallbacks = []\n\t\t\t\tthis.#events.set(eventOrEvents, callbacks)\n\t\t\t}\n\t\t\tcallbacks.push(cb)\n\t\t}\n\t\t// @ts-expect-error Generic case leads to generic case\n\t\treturn () => this.off(eventOrEvents, cb)\n\t}\n\tpublic off(events: Partial<Events>): void\n\tpublic off<EventType extends keyof Events>(event: EventType, cb?: Events[EventType]): void\n\tpublic off<EventType extends keyof Events>(\n\t\teventOrEvents: EventType | Partial<Events>,\n\t\tcb?: Events[EventType]\n\t): void {\n\t\tif (typeof eventOrEvents === 'object') {\n\t\t\tfor (const e of Object.keys(eventOrEvents) as (keyof Events)[]) {\n\t\t\t\tthis.off(e, eventOrEvents[e])\n\t\t\t}\n\t\t} else if (cb !== null && cb !== undefined) {\n\t\t\tconst callbacks = this.#events.get(eventOrEvents)\n\t\t\tif (callbacks) {\n\t\t\t\tthis.#events.set(\n\t\t\t\t\teventOrEvents,\n\t\t\t\t\tcallbacks.filter((c) => c !== cb)\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\t// Remove all listeners for this event\n\t\t\tthis.#events.delete(eventOrEvents)\n\t\t}\n\t}\n\tpublic emit<EventType extends keyof Events>(\n\t\tevent: EventType,\n\t\t...args: Parameters<Events[EventType]>\n\t) {\n\t\tconst callbacks = this.#events.get(event)\n\t\tif (callbacks) for (const cb of callbacks) cb.apply(this, args)\n\t\tfor (const cb of this.#hooks) cb.call(this, event, ...args)\n\t}\n}\n","import { FoolProof } from '../utils'\nimport { touched1 } from './change'\nimport { effect } from './effects'\nimport { cleanedBy, cleanup } from './interface'\nimport { reactive } from './proxy'\nimport { type ScopedCallback } from './types'\n\n/**\n * Provides type-safe access to a source object's property within the organized callback.\n * @template Source - The type of the source object\n * @template Key - The type of the property key in the source object\n */\nexport type OrganizedAccess<Source extends Record<PropertyKey, any>, Key extends keyof Source> = {\n\t/** The property key being accessed */\n\treadonly key: Key\n\n\t/**\n\t * Gets the current value of the property from the source object\n\t * @returns The current value of the property\n\t */\n\tget(): Source[Key]\n\n\t/**\n\t * Updates the property value in the source object\n\t * @param value - The new value to set\n\t * @returns {boolean} True if the update was successful\n\t */\n\tset(value: Source[Key]): boolean\n\n\t/**\n\t * The current value of the property (equivalent to using get()/set() directly)\n\t */\n\tvalue: Source[Key]\n}\n\n/**\n * Callback function type for the organized function that processes each source property.\n * @template Source - The type of the source object\n * @template Target - The type of the target object\n */\nexport type OrganizedCallback<Source extends Record<PropertyKey, any>, Target extends object> = <\n\tKey extends keyof Source,\n>(\n\t/**\n\t * Accessor object for the current source property\n\t */\n\taccess: OrganizedAccess<Source, Key>,\n\n\t/**\n\t * The target object where organized data will be stored\n\t */\n\ttarget: Target\n) => ScopedCallback | undefined\n\n/**\n * The result type of the organized function, combining the target object with cleanup capability.\n * @template Target - The type of the target object\n */\nexport type OrganizedResult<Target extends object> = Target & {\n\t/**\n\t * Cleanup function to dispose of all reactive bindings created by organized().\n\t * This is automatically called when the effect that created the organized binding is disposed.\n\t */\n\t[cleanup]: ScopedCallback\n}\n\n/**\n * Organizes a source object's properties into a target object using a callback function.\n * This creates a reactive mapping between source properties and a target object,\n * automatically handling property additions, updates, and removals.\n *\n * @template Source - The type of the source object\n * @template Target - The type of the target object (defaults to Record<PropertyKey, any>)\n *\n * @param {Source} source - The source object to organize\n * @param {OrganizedCallback<Source, Target>} apply - Callback function that defines how each source property is mapped to the target\n * @param {Target} [baseTarget={}] - Optional base target object to use (will be made reactive if not already)\n *\n * @returns {OrganizedResult<Target>} The target object with cleanup capability\n *\n * @example\n * // Organize user permissions into role-based access\n * const user = reactive({ isAdmin: true, canEdit: false });\n * const permissions = organized(\n * user,\n * (access, target) => {\n * if (access.key === 'isAdmin') {\n * target.hasFullAccess = access.value;\n * }\n * target[`can${access.key.charAt(0).toUpperCase() + access.key.slice(1)}`] = access.value;\n * }\n * );\n *\n * @example\n * // Transform object structure with cleanup\n * const source = reactive({ firstName: 'John', lastName: 'Doe' });\n * const formatted = organized(\n * source,\n * (access, target) => {\n * if (access.key === 'firstName' || access.key === 'lastName') {\n * target.fullName = `${source.firstName} ${source.lastName}`.trim();\n * }\n * }\n * );\n *\n * @example\n * // Using with cleanup in a component\n * effect(() => {\n * const data = fetchData();\n * const organizedData = organized(data, (access, target) => {\n * // Transform data\n * });\n *\n * // The cleanup will be called automatically when the effect is disposed\n * return () => organizedData[cleanup]();\n * });\n */\nexport function organized<\n\tSource extends Record<PropertyKey, any>,\n\tTarget extends object = Record<PropertyKey, any>,\n>(\n\tsource: Source,\n\tapply: OrganizedCallback<Source, Target>,\n\tbaseTarget: Target = {} as Target\n): OrganizedResult<Target> {\n\tconst observedSource = reactive(source) as Source\n\tconst target = reactive(baseTarget) as Target\n\tconst keyEffects = new Map<PropertyKey, ScopedCallback>()\n\n\tfunction disposeKey(key: PropertyKey) {\n\t\tconst stopEffect = keyEffects.get(key)\n\t\tif (stopEffect) {\n\t\t\tkeyEffects.delete(key)\n\t\t\tstopEffect()\n\t\t}\n\t}\n\n\tconst cleanupKeys = effect(function organizedKeysEffect({ ascend }) {\n\t\t//const keys = Reflect.ownKeys(observedSource) as PropertyKey[]\n\t\tconst keys = new Set<PropertyKey>()\n\t\tfor (const key in observedSource) keys.add(key)\n\n\t\tfor (const key of keys) {\n\t\t\tif (keyEffects.has(key)) continue\n\t\t\tascend(() => {\n\t\t\t\tconst stop = effect(function organizedKeyEffect() {\n\t\t\t\t\tconst sourceKey = key as keyof Source\n\t\t\t\t\tconst accessBase = {\n\t\t\t\t\t\tkey: sourceKey,\n\t\t\t\t\t\tget: () => FoolProof.get(observedSource, sourceKey, observedSource),\n\t\t\t\t\t\tset: (value: Source[typeof sourceKey]) =>\n\t\t\t\t\t\t\tFoolProof.set(observedSource, sourceKey, value, observedSource),\n\t\t\t\t\t}\n\t\t\t\t\tObject.defineProperty(accessBase, 'value', {\n\t\t\t\t\t\tget: accessBase.get,\n\t\t\t\t\t\tset: accessBase.set,\n\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t})\n\t\t\t\t\treturn apply(accessBase as OrganizedAccess<Source, typeof sourceKey>, target)\n\t\t\t\t})\n\t\t\t\tkeyEffects.set(key, stop)\n\t\t\t})\n\t\t}\n\n\t\tfor (const key of Array.from(keyEffects.keys())) if (!keys.has(key)) disposeKey(key)\n\t})\n\n\treturn cleanedBy(target, () => {\n\t\tcleanupKeys()\n\t\tfor (const key of Array.from(keyEffects.keys())) disposeKey(key)\n\t}) as OrganizedResult<Target>\n}\n\n/**\n * Organizes a property on a target object\n * Shortcut for defineProperty/delete with touched signal\n * @param target - The target object\n * @param property - The property to organize\n * @param access - The access object\n * @returns The property descriptor\n */\nexport function organize<T>(\n\ttarget: object,\n\tproperty: PropertyKey,\n\taccess: { get?(): T; set?(value: T): boolean }\n) {\n\tObject.defineProperty(target, property, {\n\t\tget: access.get,\n\t\tset: access.set,\n\t\tconfigurable: true,\n\t\tenumerable: true,\n\t})\n\ttouched1(target, { type: 'set', prop: property }, property)\n\treturn () => delete (target as any)[property]\n}\n","import { FoolProof } from '../utils'\nimport { effect, untracked } from './effects'\nimport { cleanedBy, cleanup } from './interface'\nimport { memoize } from './memoize'\nimport { reactive } from './proxy'\nimport type { ScopedCallback } from './types'\n\n/**\n * Result of a reactive scan, which is a reactive array of accumulated values\n * with an attached cleanup function.\n */\nexport type ScanResult<Output> = readonly Output[] & { [cleanup]: ScopedCallback }\n\n/**\n * Perform a reactive scan over an array of items.\n *\n * This implementation is highly optimized for performance and fine-grained reactivity:\n * - **Incremental Updates**: Changes to an item only trigger re-computation from that \n * point onwards in the result chain.\n * - **Move Optimization**: If items are moved within the array, their accumulated \n * values are reused as long as their predecessor remains the same.\n * - **Duplicate Support**: Correctly handles multiple occurrences of the same object \n * instance using an internal occurrence tracking mechanism.\n * - **Memory Efficient**: Uses `WeakMap` for caching intermediates, which are \n * automatically cleared when source items are garbage collected.\n *\n * @example\n * ```typescript\n * const source = reactive([{ val: 1 }, { val: 2 }, { val: 3 }])\n * const sum = scan(source, (acc, item) => acc + item.val, 0)\n * \n * expect([...sum]).toEqual([1, 3, 6])\n * \n * // Modifying an item only re-computes subsequent sums\n * source[1].val = 10\n * expect([...sum]).toEqual([1, 11, 14])\n * ```\n *\n * @param source The source array of objects (will be made reactive)\n * @param callback The accumulator function called with (accumulator, currentItem)\n * @param initialValue The starting value for the accumulation\n * @returns A reactive array of accumulated values, with a [cleanup] property to stop the tracking\n */\nexport function scan<Input extends object, Output>(\n\tsource: readonly Input[],\n\tcallback: (acc: Output, val: Input) => Output,\n\tinitialValue: Output\n): ScanResult<Output> {\n\tconst observedSource = reactive(source)\n\tconst result = reactive([] as Output[])\n\t\n\t// Track effects for each index to dispose them when the array shrinks\n\tconst indexEffects = new Map<number, ScopedCallback>()\n\t// Mapping from index to its current intermediate object\n\tconst indexToIntermediate = reactive([] as Intermediate[])\n\tconst intermediaries = new WeakMap<Input, Intermediate[]>()\n\n\tclass Intermediate {\n\t\tpublic prev: Intermediate | undefined\n\t\tconstructor(public val: Input, prev: Intermediate | undefined) {\n\t\t\tthis.prev = prev\n\t\t}\n\n\t\t@memoize\n\t\tget acc(): Output {\n\t\t\tconst prevAcc = this.prev ? this.prev.acc : initialValue\n\t\t\treturn callback(prevAcc, this.val)\n\t\t}\n\t}\n\n\tfunction disposeIndex(index: number) {\n\t\tconst stop = indexEffects.get(index)\n\t\tif (stop) {\n\t\t\tstop()\n\t\t\tindexEffects.delete(index)\n\t\t\tuntracked(() => {\n\t\t\t\tReflect.deleteProperty(indexToIntermediate as any, index)\n\t\t\t\tReflect.deleteProperty(result as any, index)\n\t\t\t})\n\t\t}\n\t}\n\n\tconst mainEffect = effect(function scanMainEffect({ ascend }) {\n\t\tconst length = observedSource.length\n\t\tconst occurrenceCount = new Map<Input, number>()\n\t\tlet prev: Intermediate | undefined = undefined\n\n\t\tfor (let i = 0; i < length; i++) {\n\t\t\tconst val = FoolProof.get(observedSource as any, i, observedSource) as Input\n\t\t\t\n\t\t\tif (!(val && (typeof val === 'object' || typeof val === 'function' || typeof val === 'symbol'))) {\n\t\t\t\tthrow new Error('scan: items must be objects (WeakKey) for intermediate caching')\n\t\t\t}\n\n\t\t\tconst count = occurrenceCount.get(val) ?? 0\n\t\t\toccurrenceCount.set(val, count + 1)\n\n\t\t\tlet list = intermediaries.get(val)\n\t\t\tif (!list) {\n\t\t\t\tlist = []\n\t\t\t\tintermediaries.set(val, list)\n\t\t\t}\n\n\t\t\tlet intermediate = list[count]\n\t\t\tif (!intermediate) {\n\t\t\t\tintermediate = reactive(new Intermediate(val, prev))\n\t\t\t\tlist[count] = intermediate\n\t\t\t} else {\n\t\t\t\t// Update the link. \n\t\t\t\tif (untracked(() => intermediate.prev) !== prev) {\n\t\t\t\t\tintermediate.prev = prev\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Update the reactive mapping for this index\n\t\t\tif (indexToIntermediate[i] !== intermediate) {\n\t\t\t\tindexToIntermediate[i] = intermediate\n\t\t\t}\n\n\t\t\t// If we don't have an effect for this index yet, create one\n\t\t\tif (!indexEffects.has(i)) {\n\t\t\t\tascend(() => {\n\t\t\t\t\tconst index = i\n\t\t\t\t\tconst stop = effect(function scanIndexSyncEffect() {\n\t\t\t\t\t\tconst inter = indexToIntermediate[index]\n\t\t\t\t\t\tif (inter) {\n\t\t\t\t\t\t\tconst accValue = inter.acc\n\t\t\t\t\t\t\tuntracked(() => {\n\t\t\t\t\t\t\t\tresult[index] = accValue\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\tindexEffects.set(index, stop)\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tprev = intermediate\n\t\t}\n\n\t\t// Cleanup trailing indices\n\t\tfor (const index of Array.from(indexEffects.keys())) {\n\t\t\tif (index >= length) disposeIndex(index)\n\t\t}\n\t\t\n\t\t// Ensure result length matches source length\n\t\tuntracked(() => {\n\t\t\tif (result.length !== length) {\n\t\t\t\tFoolProof.set(result as any, 'length', length, result)\n\t\t\t}\n\t\t})\n\t})\n\n\treturn cleanedBy(result, () => {\n\t\tmainEffect()\n\t\tfor (const stop of indexEffects.values()) stop()\n\t\tindexEffects.clear()\n\t}) as ScanResult<Output>\n}\n\nexport function resolve<Output>(cb: () => Output[]): Output[] & { [cleanup]: ScopedCallback } {\n\tconst result = reactive([] as Output[])\n\treturn cleanedBy(result, effect(() => {\n\t\tconst source = cb()\n\t\tif (result.length !== source.length) result.length = source.length\n\t\tfor (let i = 0; i < source.length; i++)\n\t\t\tif (result[i] !== source[i]) result[i] = source[i]\n\t}))\n}"],"names":["asyncHooks","addHook","_hook","sanitizePromise","p","hooks","Set","promiseContexts","WeakMap","captureRestorers","restorers","hook","restorer","add","wrap","fn","capturedRestorers","args","undoers","restore","push","apply","this","originals","queueMicrotask","call","globalThis","i","length","delete","res","then","Promise","resolve","reject","setTimeout","targetWrappers","patchOnProperties","proto","prop","Object","getOwnPropertyNames","startsWith","desc","getOwnPropertyDescriptor","set","configurable","nativeSet","defineProperty","EventTarget","addEventListener","removeEventListener","nativeAdd","nativeRemove","type","listener","options","types","get","Map","listeners","wrapped","patchEventTarget","prototype","prototypesToPatch","HTMLElement","Window","Document","MessagePort","XMLHttpRequest","IDBRequest","IDBTransaction","IDBDatabase","FileReader","AbortSignal","GLOBAL_ORIGINALS","Symbol","for","GLOBAL_PROMISE","OriginalPromise","patchedThen","onFulfilled","onRejected","context","nextPromise","size","PatchedPromise","executor","wrappedResolve","wrappedReject","catch","finally","all","allSettled","race","any","setInterval","setImmediate","requestAnimationFrame","assign","value","has","reason","values","onFinally","species","e","callback","nativeConstructors","Array","Date","Function","WeakSet","Error","TypeError","ReferenceError","SyntaxError","RangeError","URIError","EvalError","Reflect","Proxy","RegExp","String","Number","Boolean","isConstructor","toString","renamed","fct","name","defineProperties","FoolProof","obj","receiver","Node","writable","enumerable","isOwnAccessor","opd","deepCompare","a","b","cache","getPrototypeOf","compared","isArray","match","getTime","val","found","bVal","key","foundMatch","bKey","keysA","keys","keysB","hasOwn","contentRefs","contentRef","container","seal","create","contentOf","tag","toStringTag","named","DecoratorError","constructor","message","super","legacyDecorator","description","target","propertyKey","descriptor","undefined","class","includes","newGetter","getter","newSetter","setter","newMethod","method","default","modernDecorator","kind","rv","decorator","modern","legacy","contextOrKey","mode","_target","detectDecoratorMode","fr","FinalizationRegistry","f","destructor","allocatedValues","DestructionError","msg","destroyedHandler","throw","allocated","original","getAt","setAt","Indexable","base","accessor","index","setPrototypeOf","getLength","numProp","isNaN","setLength","ownKeys","len","v","forwardArray","ArrayReadForward","iterator","map","callbackfn","thisArg","filter","predicate","reduce","initialValue","reduceRight","forEach","find","findIndex","findLast","findLastIndex","searchElement","fromIndex","indexOf","lastIndexOf","slice","start","end","concat","items","every","some","join","separator","entries","toLocaleString","locales","at","flat","depth","flatMap","toReversed","reverse","toSorted","compareFn","sort","toSpliced","deleteCount","with","unscopables","IterableWeakMap","uuids","refs","_a","registry","uuid","k","createIterator","cb","keyRef","deref","clear","unregister","crypto","randomUUID","WeakRef","register","_value","_key","IterableWeakSet","_b","union","other","others","that","intersection","difference","symmetricDifference","isSubsetOf","isSupersetOf","isDisjointFrom","mixin","mixinFunction","unwrapFunction","mixinCache","MixedBase","_thisArg","baseClass","cached","usedBase","ProxiedBaseClass","originalPrototype","proxiedPrototype","mixedClass","forward","alreadyChained","promiseProxyHandler","chainPromise","r","promiseForward","objectProxyHandler","chainObject","given","chainable","x","t","chained","nativeReactive","nonReactiveMark","unreactiveProperties","allProps","projectionInfo","stopped","cleanup","rootFunction","ReactiveErrorCode","ReactiveError","debugInfo","code","cause","enter","_effect","leave","chain","_targets","_caller","beginChain","endChain","garbageCollected","_fn","touched","_obj","_evolution","_props","_deps","skipRunningEffect","maxEffectChain","maxTriggerPerBatch","maxEffectReaction","onMemoizationDiscrepancy","cycleHandling","isVerificationRun","maxDeepWatchDepth","instanceMembers","ignoreAccessors","recursiveTouching","asyncMode","warn","introspection","enableHistory","historySize","zones","effectToReactiveObjects","watchers","effectChildren","effectParent","reverseRoots","markWithRoot","root","existingRef","existing","rootName","existingName","fnName","getRoot","EXTERNAL_SOURCE","devtoolsEnabled","debugEffectRegistry","debugObjectRegistry","effectNames","objectNames","effectCounter","objectCounter","triggerGraph","ensureEffectName","effect","trim","ensureObjectName","ctorName","addEffectToRegistry","deps","documentObject","dbRegisterObject","ensureTriggerRecord","source","label","evolution","targetMap","ensureTriggerContainers","labelMap","record","object","count","lastTriggered","now","setEffectName","setObjectName","registerEffectForDebug","registerObjectForDebug","recordTriggerLink","id","mutationCounter","timestamp","objectName","mutationHistory","shift","addToMutationHistory","describeProp","getTriggerChain","limit","current","foundSource","foundReason","search","lastTime","buildReactivityGraph","nodes","edges","nodeIds","allEffects","effects","queue","from","parent","ensureParentChains","effectNodes","nodeByEffect","ordered","node","debugName","depthCache","computeDepth","parentNode","parentId","buildEffectNodes","externalId","effectId","objId","targetEffect","targetId","sourceId","meta","generatedAt","isDevtoolsEnabled","isu","z","AZone","prev","active","entered","zoned","Zone","ZoneHistory","history","controlled","self","present","getOwnPropertyDescriptors","added","ZoneAggregator","_ZoneAggregator_zones","__classPrivateFieldGet","asyncZone","zone","effectHistory","effectAggregator","isRunning","getActiveEffect","objectToProxy","proxyToObject","unwrap","findCycleInChain","roots","seen","formatRoots","names","activationRegistry","activationLog","recordActivation","effectData","objData","unshift","pop","effectName","MaxReactionExceeded","effectTrackers","opaqueEffects","effectTriggers","effectTriggeredBy","causesClosure","consequencesClosure","effectCreationStacks","getOrCreateClosure","closure","hasPathExcluding","exclude","visited","triggers","next","batchQueue","hasBatched","batchCleanups","findPath","startRoot","endRoot","path","newPath","targetRoot","result","getCyclePathForEdge","callerRoot","addToBatch","caller","immediate","cleanupSymbol","targetConsequences","wouldCreateCycle","cyclePath","cycleMessage","causalChain","creationStack","CycleDetected","cycle","details","newTriggers","triggeredBy","uConsequences","vCauses","uCausesSet","vConsequencesSet","y","xConsequences","addGraphEdge","addBatchCleanup","defer","findCycle","recursionStack","cycleStart","executeNext","effectuatedRoots","nextEffect","nextRoot","first","inDegrees","getCyclePath","consequences","consequence","consequenceConsequences","firstEffect","firstRoot","firstEffect2","firstRoot2","batch","executedRoot","consequenceRoot","currentDegree","decrementInDegreesForExecuted","firstReturn","activeEffect","activeRoot","inDegree","causes","causeRoot","computeAllInDegrees","trace","queued","MaxDepthExceeded","queuedCount","cleanups","error","BrokenEffects","atomic","atomicEffect","effectOptions","stack","cleanStack","split","tracked","runEffect","ascend","effectStopped","hasReacted","runningPromise","cancelPrevious","prevCleanup","untracked","reactionCleanup","reaction","originalPromise","cancelReject","cancelPromise","_","cancelError","effectObjects","reactiveObj","objectWatchers","children","childCleanup","augmentedRv","cleanup$1","opaque","stopEffect","rootCauses","rootConsequences","sourceRoot","causeConsequences","consequenceCauses","yCauses","cleanupEffectFromGraph","callIfCollected","subEffectCleanup","objectParents","objectsWithDeepWatchers","deepWatchers","effectToDeepWatchedObjects","addBackReference","child","parents","removeBackReference","entry","needsBackReferences","hasParentWithDeepWatchers","bubbleUpChange","changedObject","parentDeepWatchers","watcher","states","addState","state","getState","collectEffects","keyChains","sourceEffect","trackers","tracker","touched1","props","nonReactiveObjects","immutables","absent","nonReactiveClass","cls","c","isNonReactive","isObjectLike","isObject","getPrototypeToken","shouldRecurseTouch","oldValue","newValue","notifyPropertyChange","targetObj","hadProperty","origin","notifications","combinedEffects","allowedEffects","originWatchers","originEffects","currentEffects","propsArray","filteredEffects","hasAncestorInSet","dispatchNotifications","recursiveTouch","touchedOpaque","collectObjectKeys","oldObj","newObj","mapped","hasVisitedPair","oldArray","newArray","_visited","local","oldLength","newLength","max","Math","hasOld","hasNew","oldEntry","newEntry","is","diffArrayElements","oldKeys","newKeys","diffObjectProperties","allowedSet","dependant","currentActiveEffect","window","o","markNonReactive","document","Element","metaProtos","hasReentry","reactiveHandlers","metaProto","unwrappedObj","hasProp","isOwnProp","isInheritedAccess","shouldIgnoreAccessor","reactiveObject","reactiveValue","unwrappedReceiver","oldVal","deleteProperty","reactiveClasses","ReactiveBase","reactive","anyTarget","getExistingProxy","proxied","proxy","trackProxyObject","storeProxyRelationship","Reactive","deepWatch","wrappedCallback","traverseAndTrack","unsetYet","unreactive","arg1","deepNonReactive","arg","cleanedBy","cleanupFn","memoizedRegistry","wrapperRegistry","getBranch","tree","branches","branch","memoizeFunction","fnRoot","cacheRoot","memoized","localArgs","wasVerification","fresh","memoize","wrapper","makeReactiveIterator","done","makeReactiveEntriesIterator","RegisterClass","_classSuper","RegisterBase","toArray","getRegisterBase","_classThis","_RegisterClass_keyFn","_RegisterClass_keys","_RegisterClass_values","_RegisterClass_usage","_RegisterClass_valueInfo","_RegisterClass_keyEffects","_RegisterClass_ascend","_RegisterClass_instances","keyFn","initial","ascendGet","__classPrivateFieldSet","ensureKey","info","stop","nextKey","assertValidKey","previousKey","_RegisterClass_rekeyValue","setKeyValue","cleanupValue","disposeKeyEffects","incrementUsage","decrementUsage","normalizeIndex","allowEnd","resolved","assignAt","oldKey","insertKeyValue","splice","rebuildFrom","newKey","existingValue","existingCount","updatedInfo","normalized","item","removeAt","normalizedStart","maxDeletions","actualDelete","min","keysToInsert","removedKeys","removedValues","remove","indexOfKey","keep","decisions","shouldKeep","hasKey","mapKeys","update","upsert","insert","fwdCompareFn","fill","copyWithin","__esDecorate","_classDescriptor","_classDecorators","metadata","_metadata","_classExtraInitializers","__runInitializers","Register","effectProjectionMetadata","getActiveProjection","defineAccessValue","access","makeCleanup","effectMap","onDispose","projectArray","indexEffects","disposeIndex","cleanupLength","normalizeTargetLength","previous","accessBase","old","produced","projectRegister","observedSource","rawTarget","keyEffects","disposeKey","cleanupKeys","projectRecord","observed","sourceKey","projectMap","project","array","range","Indexer","indexLess","parseInt","ReactiveArray","toJSON","actualIndex","nativeIterator","dispose","unwrappedSearch","predicateOrElement","actualStart","actualDeleteCount","localeCompare","final","to","ReactiveWeakMap","hadKey","ReactiveMap","hadEntries","ReactiveWeakSet","had","ReactiveSet","profileInfo","syncCalculating","alreadyCalculating","deprecated","version","pkg","GLOBAL_MUTTS_KEY","globalScope","global","viteEval","eval","__filename","url","currentSourceInfo","JSON","stringify","destructorObj","destroy","destructors","isDestroyable","myDestructor","destruction","_Eventful_events","_Eventful_hooks","on","eventOrEvents","callbacks","off","emit","event","received","programatticallySetValue","called","delay","_propertyKey","timeoutId","clearTimeout","compute","properties","Base","__MUTTS_DEVTOOLS__","getGraph","registerEffect","registerObject","property","baseTarget","originalClass","reactiveClass","indexToIntermediate","intermediaries","Intermediate","_instanceExtraInitializers","acc","prevAcc","_get_acc_decorators","static","private","mainEffect","occurrenceCount","list","intermediate","inter","accValue","lastCallTime","remainingTime","scheduledArgs","onTouch","changed","deep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