@jucie.io/reactive 1.0.21 → 1.0.24

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.
package/README.md CHANGED
@@ -5,7 +5,8 @@ Fine-grained reactive programming with signals, computed values, and reactive su
5
5
  ## Features
6
6
 
7
7
  - **Signals**: Simple reactive values with automatic dependency tracking
8
- - **Reactors**: Computed values that update when dependencies change
8
+ - **Computed**: Computed values that auto-track and update when dependencies change
9
+ - **Bindings**: Reactive values with explicit dependencies and context support
9
10
  - **Surfaces**: Component-like reactive contexts with state management
10
11
  - **Subscribers**: Side effects that run when reactive values change
11
12
  - **Async Support**: Native support for async computations
@@ -37,9 +38,9 @@ count(n => n + 1);
37
38
  console.log(count()); // 6
38
39
  ```
39
40
 
40
- ### Reactors (Computed Values)
41
+ ### Computed Values
41
42
 
42
- Automatically computed values:
43
+ Automatically computed values that track dependencies:
43
44
 
44
45
  ```javascript
45
46
  import { createSignal, createComputed } from '@jucie.io/reactive';
@@ -95,7 +96,76 @@ count(2); // Logs: "Count changed: 2"
95
96
 
96
97
  ## Advanced Features
97
98
 
98
- ### Async Reactors
99
+ ### Bindings
100
+
101
+ Reactive values with explicit dependencies:
102
+
103
+ ```javascript
104
+ import { createSignal, createBinding } from '@jucie.io/reactive';
105
+
106
+ const firstName = createSignal('John');
107
+ const lastName = createSignal('Doe');
108
+
109
+ // Explicit dependencies - function receives (context, previousValue)
110
+ const fullName = createBinding(
111
+ (ctx, prev) => `${firstName()} ${lastName()}`,
112
+ [firstName, lastName]
113
+ );
114
+
115
+ console.log(fullName()); // "John Doe"
116
+ lastName('Smith');
117
+ console.log(fullName()); // "John Smith"
118
+ ```
119
+
120
+ ### Async Bindings
121
+
122
+ Bindings work seamlessly with async functions:
123
+
124
+ ```javascript
125
+ import { createSignal, createBinding } from '@jucie.io/reactive';
126
+
127
+ const userId = createSignal(1);
128
+
129
+ const userData = createBinding(
130
+ async (ctx, prev) => {
131
+ const response = await fetch(`/api/users/${userId()}`);
132
+ return response.json();
133
+ },
134
+ [userId]
135
+ );
136
+
137
+ // Returns a promise
138
+ const data = await userData();
139
+ ```
140
+
141
+ ### Binding with Previous Value
142
+
143
+ Access the previous computed value:
144
+
145
+ ```javascript
146
+ import { createSignal, createBinding } from '@jucie.io/reactive';
147
+
148
+ const count = createSignal(0);
149
+
150
+ const delta = createBinding(
151
+ (ctx, prev) => {
152
+ const current = count();
153
+ return prev !== undefined ? current - prev : 0;
154
+ },
155
+ [count],
156
+ { initialValue: 0 }
157
+ );
158
+
159
+ console.log(delta()); // 0
160
+ count(5);
161
+ console.log(delta()); // 5 (5 - 0)
162
+ count(8);
163
+ console.log(delta()); // 3 (8 - 5)
164
+ ```
165
+
166
+ ### Async Computed
167
+
168
+ Computed values also support async:
99
169
 
100
170
  ```javascript
101
171
  import { createSignal, createComputed } from '@jucie.io/reactive';
@@ -161,12 +231,21 @@ count(1); // Logs: "Effect: 1"
161
231
  - `createSignal(initialValue)` - Create a reactive signal
162
232
  - `destroySignal(signal)` - Destroy a signal
163
233
  - `isSignal(value)` - Check if value is a signal
234
+ - `isDirtySignal(signal)` - Check if signal needs recomputation
164
235
 
165
- ### Reactors
236
+ ### Computed
166
237
 
167
- - `createComputed(fn, config)` - Create a computed value
238
+ - `createComputed(fn, config)` - Create a computed value with auto-tracked dependencies
168
239
  - `destroyComputed(computed)` - Destroy a computed
169
240
  - `isComputed(value)` - Check if value is a computed
241
+ - `isDirtyComputed(computed)` - Check if computed needs recomputation
242
+
243
+ ### Bindings
244
+
245
+ - `createBinding(fn, dependencies, config)` - Create a binding with explicit dependencies
246
+ - `destroyBinding(binding)` - Destroy a binding
247
+ - `isBinding(value)` - Check if value is a binding
248
+ - `isDirtyBinding(binding)` - Check if binding needs recomputation
170
249
 
171
250
  ### Surfaces
172
251
 
@@ -189,7 +268,7 @@ count(1); // Logs: "Effect: 1"
189
268
 
190
269
  ## Configuration Options
191
270
 
192
- ### Signal/Reactor Config
271
+ ### Signal/Computed Config
193
272
 
194
273
  ```javascript
195
274
  {
@@ -201,6 +280,20 @@ count(1); // Logs: "Effect: 1"
201
280
  }
202
281
  ```
203
282
 
283
+ ### Binding Config
284
+
285
+ ```javascript
286
+ {
287
+ debounce: 100, // Debounce updates (ms)
288
+ immediate: true, // Compute immediately
289
+ effects: [fn], // Initial effects
290
+ detatched: false, // Skip dependency tracking
291
+ onAccess: (value) => {}, // Callback on access
292
+ context: () => ctx, // Custom context provider
293
+ initialValue: value // Initial cached value
294
+ }
295
+ ```
296
+
204
297
  ### Surface Options
205
298
 
206
299
  ```javascript
package/dist/main.js CHANGED
@@ -1,2 +1,2 @@
1
- function j(t){return typeof window<"u"&&window.requestIdleCallback?window.requestIdleCallback(t,{timeout:100}):typeof window<"u"?window.requestAnimationFrame?window.requestAnimationFrame(()=>{setTimeout(t,0)}):setTimeout(t,0):(typeof t=="function"&&t(),null)}var l=class{constructor(){this.roots=new Map,this.pending=new Set,this.onCompleteCallbacks=new Set,this.onNextIdle=new Set,this.idleScheduled=!1}markAsDirty(e){if(!e.isDirty&&(e.isDirty=!0,e.isAsync||e.immediate||e.effects&&e.effects.size>0?this.scheduleRecomputation(e):(this.onNextIdle.add(e),this.idleScheduled||(this.idleScheduled=!0,j(()=>{for(let s of this.onNextIdle)this.pending.add(s);this.flush(null),this.onNextIdle.clear(),this.idleScheduled=!1}))),e.dependants&&e.dependants.size>0)){let s=[],r=new Set;e.dependants.forEach(i=>{let c=i.deref();c?(this.markAsDirty(c),r.add(c.id)):s.push(i)}),s.forEach(i=>e.dependants.delete(i)),e.dependantIds=r}}scheduleRecomputation(e){if(!e.debounce)return this.recompute(e);let s=Date.now(),r=e.lastComputeTime?s-e.lastComputeTime:1/0;return!e.hasPendingDebounce||r>=e.debounce?(clearTimeout(e.debounceTimer),e.hasPendingDebounce=!0,e.lastComputeTime=s,e.debounceTimer=setTimeout(()=>{e.hasPendingDebounce=!1,e.debounceTimer=null},e.debounce),this.recompute(e)):e.cachedValue}removeReactive(e){this.pending.delete(e),this.onNextIdle.delete(e)}recompute(e){return this.pending.add(e),this.flush(e)}flush(e){let s=Array.from(this.pending);this.pending.clear();let r=this.sortByDependencies(s);for(let i of r)this.onNextIdle.delete(i),i.compute();for(let i of this.onCompleteCallbacks)try{i()}catch(c){console.error("Error in batch completion callback:",c)}if(e)return r.includes(e)||e.compute(),e.cachedValue}sortByDependencies(e){let s=[],r=new Set,i=new Set,c=o=>{if(i.has(o)||r.has(o))return;i.add(o);let a=o.dependants;a&&a.size>0&&a.forEach(u=>{let w=u.deref();w&&e.includes(w)&&c(w)}),i.delete(o),r.add(o),s.unshift(o)};for(let o of e)r.has(o)||c(o);return s}};var g=Symbol.for("@jucie.io/reactive/system");globalThis[g]||(globalThis[g]={computationManager:new l,awaitingRecomputation:new Set,reactives:new WeakMap,subscribers:new Set,currentlyComputing:null,computationStack:[],currentDepth:0,effectsCache:new Set,processingEffects:!1,_nextId:1,config:{maxDepth:2e3},ctx:{}});var n=class t{static get system(){return globalThis[g]}constructor(){this.id=t.nextId(),this.isDirty=!0,this.dependants=new Set,this.dependantIds=new Set}static nextId(){return t.system._nextId++}static addReactive(e,s){t.system.reactives.set(e,s),t.system.subscribers.add(e)}static addSubscriber(e,s){return t.system.reactives.set(e,s),t.system.subscribers.add(e),()=>t.removeSubscriber(e)}static removeSubscriber(e){t.system.subscribers.delete(e),t.system.reactives.delete(e)}static addContext(e,s){if(!e||typeof e!="string")throw new Error("Invalid context key");if(typeof s>"u")throw new Error("Invalid context value");if(e in t.system.ctx)throw new Error("Context key already exists");t.system.ctx[e]=s}static useContext(e){if(!e||e.length===0)return t.system.ctx;if(e.length===1)return t.system.ctx[e[0]];let s=new Array(e.length);for(let r=0;r<e.length;r++)s[r]=t.system.ctx[e[r]];return s}static hasContext(e){if(!e||e.length===0)return Object.keys(t.system.ctx).length>0;if(e.length===1)return e[0]in t.system.ctx;for(let s of e)if(!(s in t.system.ctx))return!1;return!0}static clearContext(){t.system.ctx={}}static resetSystem(){t.system.awaitingRecomputation.clear(),t.system.currentlyComputing=null,t.system.computationStack=[],t.system.currentDepth=0,t.system.effectsCache.clear(),t.system.processingEffects=!1,t.system.ctx={}}begin(){t.system.awaitingRecomputation.has(this)&&t.system.awaitingRecomputation.delete(this);let e=t.system.computationStack.indexOf(this);if(e!==-1){let s=t.system.computationStack.slice(e).concat(this),r=new Error(`Circular dependency detected: ${s.map(i=>i).join(" -> ")}`);throw r.name="CircularDependencyError",r.displayed=!1,r}if(t.system.currentDepth>=t.system.config.maxDepth)throw new Error(`Maximum reactive depth of ${t.system.config.maxDepth} exceeded`);t.system.computationStack.push(this),t.system.currentlyComputing=this,t.system.currentDepth++}end(){t.system.computationStack.pop(),t.system.currentlyComputing=t.system.computationStack[t.system.computationStack.length-1]||null,t.system.currentDepth--}recompute(){return t.system.awaitingRecomputation.has(this)||t.system.awaitingRecomputation.add(this),t.system.computationManager.scheduleRecomputation(this)}static addDependant(e,s){let r=t.system.reactives.get(e);r&&(r.dependants.add(new WeakRef(s)),r.dependantIds.add(s.id))}static addEffect(e,s){let r=t.system.reactives.get(e);return r.isDirty&&t.system.computationManager.scheduleRecomputation(r),r.effects||(r.effects=new Set),r.effects.add(s),t.system.subscribers.add(e),()=>t.removeEffect(e,s)}static removeEffect(e,s){let r=t.system.reactives.get(e);t.system.subscribers.delete(e),r&&r.effects&&r.effects.delete(s)}callEffects(){t.system.effectsCache.add(this),t.system.processingEffects||(t.system.processingEffects=!0,setTimeout(()=>{t.processEffectsCache(),t.system.processingEffects=!1},0))}static processEffectsCache(){let e=new Set(t.system.effectsCache);t.system.effectsCache.clear();for(let s of e)try{(s.effects||new Set).forEach(i=>{i&&i(s.cachedValue)})}catch(r){console.error(`Error in reactive ${s.id} effect:`,r)}t.system.effectsCache.size>0&&setTimeout(()=>{t.processEffectsCache()},0)}markAsDirty(){if(!this.isDirty){this.isDirty=!0,(this.immediate||this.effects&&this.effects.size>0)&&t.system.computationManager.scheduleRecomputation(this);let e=[],s=new Set;this.dependants.forEach(r=>{let i=r.deref();i?(i.markAsDirty(),s.add(i.id)):e.push(r)}),e.forEach(r=>this.dependants.delete(r)),this.dependantIds=s}}static destroy(e){t.system.subscribers.has(e)&&t.system.subscribers.delete(e);let s=t.system.reactives.get(e);s&&t.system.computationManager.removeReactive(s),t.system.reactives.delete(e)}};var h=t=>n.system.reactives.has(t),m=(t,e)=>{if(!h(t))throw new Error("Invalid effect getter");if(!e||typeof e!="function")throw new Error("Invalid effect function");return n.addEffect(t,e)},I=(t,e)=>{if(h(t))return n.removeEffect(t,e)};var V=(t,e)=>n.addContext(t,e),R=(...t)=>t.length===0?n.system.ctx:t.length===1?n.system.ctx[t[0]]:t.map(e=>n.system.ctx[e]),T=(...t)=>n.hasContext(t),k=(t,e=[])=>{if(!h(t))throw new Error("Invalid adapter getter");let s,r=null,i=new Set,c=()=>{if(s!==void 0)return s;let a=e&&e.length>0?traverse(t(),e):t();if(Array.isArray(a))s=a.slice();else if(typeof a=="object"&&a!==null){let u=Object.create(Object.getPrototypeOf(a));Object.defineProperties(u,Object.getOwnPropertyDescriptors(a)),s=Object.freeze(u)}else s=a;return s};return[c,a=>(r||(r=m(t,()=>{s=void 0;for(let u of i)u(c)})),i.add(a),()=>{i.delete(a),i.size===0&&(r(),r=null)})]};var p=class t extends n{static create(e,s={}){let r=new t(e,s);return n.addReactive(r.getter,r),r.getter}constructor(e,s={}){if(s.context&&typeof s.context!="function")throw new Error("Computed context must be a function");super(),this.fn=e,this.effects=new Set(Array.isArray(s.effects)?s.effects:[]),this.cachedValue=s.initialValue||void 0,this.isDirty=s.initialValue===void 0,this.debounce=s.debounce||0,this.onAccess=s.onAccess||void 0,this.detatched=s.detatched||!1,this.immediate=s.immediate||!1,this.useContext=s.context||(n.hasContext()?()=>n.useContext():()=>{}),this.lastComputeTime=void 0,this.hasPendingDebounce=!1,this.debounceTimer=void 0,this.computationId=0,this.getter=this.#e.bind(this),this.immediate&&this.compute()}compute(){this.begin();try{let e=this.useContext?this.useContext():void 0;return this.cachedValue=this.fn(e,this.cachedValue),this.isDirty=!1,this.cachedValue}finally{this.end(),this.callEffects()}}#e(){try{return!this.detatched&&n.system.currentlyComputing&&n.system.currentlyComputing!==this&&!this.dependantIds.has(n.system.currentlyComputing.id)&&(this.dependantIds.add(n.system.currentlyComputing.id),this.dependants.add(new WeakRef(n.system.currentlyComputing))),this.isDirty?this.recompute():this.cachedValue}catch(e){throw e}finally{this.onAccess&&this.onAccess(this.cachedValue)}}},C=(t,e={})=>p.create(t,e),S=t=>{D(t)&&n.destroy(t)},D=t=>{let e=n.system.reactives.get(t);return e?e instanceof p:!1},$=t=>{let e=n.system.reactives.get(t);return e?e.isDirty:!1};var y=class t extends n{static create(e,s={}){let r=new t(e,s);return n.addReactive(r.getter,r),r.getter}constructor(e,s={}){super(),this.cachedValue=void 0,this.roots=new Set,this.effects=new Set(Array.isArray(s.effects)?s.effects:[]),this.debounce=s.debounce||0,this.onAccess=s.onAccess||null,this.detatched=s.detatched||!1,this.immediate=s.immediate||!1,this.pendingChange=e,this.lastComputeTime=null,this.hasPendingDebounce=!1,this.debounceTimer=null,this.getter=(...r)=>this.#e(...r)}compute(){this.begin();try{return this.cachedValue=this.pendingChange,this.pendingChange=void 0,this.isDirty=!1,this.cachedValue}finally{this.end(),this.callEffects()}}#e(...e){try{if(!this.detatched&&n.system.currentlyComputing&&n.system.currentlyComputing!==this&&!this.dependantIds.has(n.system.currentlyComputing.id)&&(this.dependantIds.add(n.system.currentlyComputing.id),this.dependants.add(new WeakRef(n.system.currentlyComputing))),e.length>0){let s=e[0];this.pendingChange=typeof s=="function"?s(this.cachedValue):s,this.markAsDirty();return}return this.isDirty?this.recompute():this.cachedValue}catch(s){throw s}finally{this.onAccess&&this.onAccess(this.cachedValue)}}},v=(t,e={})=>y.create(t,e),M=t=>{O(t)&&n.destroy(t)},O=t=>{let e=n.system.reactives.get(t);return e?e instanceof y:!1},z=t=>{let e=n.system.reactives.get(t);return e?e.isDirty:!1};var b=class t extends n{static create(e,s,r={}){let i=new t(e,s,r);return n.system.reactives.set(i.getter,i),n.system.subscribers.add(i.getter),()=>n.destroy(i.getter)}constructor(e,s,r={}){super(),this.getter=e,this.isDirty=!1,this.subscriber=s,this.debounce=r.debounce||0,this.onAccess=r.onAccess||null,this.immediate=!0,this.hasPendingDebounce=!1,this.lastComputeTime=null,this.debounceTimer=null,this.begin(),this.cachedValue=this.getter(),this.subscriber(this.cachedValue),this.end()}compute(){try{this.cachedValue=this.getter(),this.subscriber(this.cachedValue),this.isDirty=!1}catch(e){throw e}}},N=(t,e,s={})=>b.create(t,e,s),W=t=>{A(t)&&n.destroy(t)},A=t=>{let e=n.system.reactives.get(t);return e?e instanceof b:!1};var d=[null,null,(t,e)=>t?.[e[0]]?.[e[1]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]]?.[e[6]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]]?.[e[6]]?.[e[7]]];function q(t){let s="obj"+Array.from({length:t},(i,c)=>`?.[path[${c}]]`).join(""),r=new Function("obj","path",`return ${s}`);return d[t]=r,r}function P(t,e){let s=e.length;return s===0?t:s===1?t[e[0]]:s<d.length&&d[s]||d[s]?d[s](t,e):q(s)(t,e)}var x=Symbol(),f=class t{static surfaces=new WeakMap;static plugins=new Map;static registerPlugin(e,s){if(t.plugins.has(e))throw new Error(`Plugin "${e}" already registered`);t.plugins.set(e,s())}static resetPlugins(){t.plugins.clear()}static create(e,s={}){let r=new t(s),i=r.setup(e);return t.surfaces.set(i,r),i}static createPlugin(e,s,r={}){let i=t.create(s,r);return t.registerPlugin(e,i),i}constructor(e={}){this.options=e,this.setupFn=null,this.subscribers=new Set,this.subscribersQueued=!1,this.destroyCallback=null,this.values=new Set,this.computeds=new Set,this.actions=new Set,this.extensions=new Set,this.snapshotCache=x,this.surface=this.#i(),this.useSurface=()=>this.surface}setup(e){if(!e)return null;this.setupFn=e,this.reset();let s=new Set;try{let r;if(typeof e=="function")r=this.#e(e,s);else if(typeof e=="object"&&e!==null)r=this.#o(e,s);else throw new Error("setupFn must be a function or object configuration");return this.#h(r),s.forEach(i=>m(i,()=>this.#r())),this.#r(),this.useSurface}catch(r){throw console.error("Error in setup function",r),r}}reset(){this.subscribers.clear(),this.subscribersQueued=!1,this.values.clear(),this.computeds.clear(),this.actions.clear(),this.extensions.clear(),this.snapshotCache=x,this.surface=this.#i()}createValue(e=void 0,s){let r=v(e),i=Object.create(null);return Object.defineProperty(i,"value",{get:()=>r(),set:c=>r(c),enumerable:!0}),this.values.add(i),s?.(r),i}createComputed(e,s){let r=C(e,{context:()=>this.surface}),i=Object.create(null);return Object.defineProperty(i,"value",{get:()=>r(),enumerable:!0}),this.computeds.add(i),s?.(r),i}createAction(e){let s=e.bind(this.surface,this.surface);return this.actions.add(s),s}extend(e){if(!e)throw new Error("No source surface provided");if(!E(e))throw new Error("Cannot extend non-surface");let s=e();return this.extensions.add(s),s}#e(e,s){return e({value:(r=void 0)=>this.createValue(r,i=>s.add(i)),computed:(r=()=>{})=>this.createComputed(r,i=>s.add(i)),action:(r=()=>{})=>this.createAction(r),extend:r=>this.extend(r),destroy:()=>this.#n(),...Object.fromEntries(t.plugins.entries())})||{}}#c(e,s,r){if(typeof e!="object"||e===null)return typeof e=="function"?e():e;if(!("default"in e))return s&&"dummy"in e&&console.warn(`State "${r}" has dummy value but no default value`),typeof e=="function"?e():e;let i=s&&"dummy"in e?e.dummy:e.default;return typeof i=="function"?i():i}#o(e,s){let r={},i=this.options.mode==="development"||this.options.mode==="dev";if(e.extend&&Array.isArray(e.extend))for(let c of e.extend)this.extend(c);if(e.state&&typeof e.state=="object")for(let[c,o]of Object.entries(e.state)){let a=this.#c(o,i,c);r[c]=this.createValue(a,u=>s.add(u))}if(e.computed&&typeof e.computed=="object")for(let[c,o]of Object.entries(e.computed))typeof o=="function"&&(r[c]=this.createComputed(o,a=>s.add(a)));if(e.actions&&typeof e.actions=="object")for(let[c,o]of Object.entries(e.actions))typeof o=="function"&&(r[c]=this.createAction(o));return e.onInit&&typeof e.onInit=="function"&&Promise.resolve().then(()=>{try{e.onInit(this.surface)}catch(c){console.error("Error in onInit callback",c)}}),e.onDestroy&&typeof e.onDestroy=="function"&&(this.destroyCallback=e.onDestroy),r}#a(){return[()=>this.#t(),e=>this.#s(e)]}#t(){if(this.snapshotCache!==x)return this.snapshotCache;let e=Object.create(Object.getPrototypeOf(this.surface));return Object.defineProperties(e,Object.getOwnPropertyDescriptors(this.surface)),this.snapshotCache=Object.freeze(e),this.snapshotCache}#s(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}#u(e){for(let s of this.subscribers)s(e)}#r(){this.subscribers.size===0||this.subscribersQueued||(this.subscribersQueued=!0,Promise.resolve().then(()=>{this.subscribersQueued=!1,this.snapshotCache=x,this.#u(this.#t())}))}#i(e=Object.create(null)){return Object.defineProperty(e,"$get",{value:s=>this.#d(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$set",{value:(s,r)=>this.#f(s,r),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$dispatch",{value:s=>this.#l(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$inject",{value:s=>Object.assign({},this.surface,s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$snapshot",{value:()=>this.#t(),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$subscribe",{value:s=>this.#s(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$adapter",{value:()=>this.#a(),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$destroy",{value:()=>this.#n(),writable:!1,enumerable:!1,configurable:!1}),e}#n(){if(this.destroyCallback&&typeof this.destroyCallback=="function")try{this.destroyCallback(this.surface)}catch(s){console.error("Error in onDestroy callback",s)}let e=this.surfaceComputed;this.surfaceComputed=null,t.surfaces.delete(e),S(e)}#d(e=[]){return P(this.surface,e)}#f(e,s){let r=this.values?.get?.(e);return r.value=s,this.surface}#l(e,...s){let r=this.actions.has(e)?this.actions.get(e):this.surface[e];return typeof r=="function"?r(...s):this.surfaceComputed()}#h(e={}){let s=Object.keys(this.surface);for(;s.length>0;){let i=s.shift();i in this.surface&&delete this.surface[i]}for(let[i,c]of t.plugins)Object.defineProperty(this.surface,i,{value:c});for(let i of this.extensions){let c=Object.getOwnPropertyDescriptors(i),o=Object.fromEntries(Object.entries(c).filter(([a])=>!a.startsWith("$")));Object.defineProperties(this.surface,o)}let r=Object.entries(e);for(let[i,c]of r){if(this.values.has(c)){Object.defineProperty(this.surface,i,{get:()=>c.value,set:o=>c.value=o});continue}if(this.computeds.has(c)){Object.defineProperty(this.surface,i,{get:()=>c.value});continue}if(this.actions.has(c)){Object.defineProperty(this.surface,i,{value:c});continue}this.surface[i]=c}return this.surface}},F=(...t)=>f.create(...t),Q=t=>{if(E(t)){let e=f.surfaces.get(t);e&&e.setup()}},B=(...t)=>f.createPlugin(...t),E=t=>f.surfaces.has(t);export{n as Reactive,V as addContext,m as addEffect,k as createAdapter,C as createComputed,v as createSignal,N as createSubscriber,B as definePlugin,F as defineSurface,S as destroyComputed,M as destroySignal,W as destroySubscriber,T as hasContext,D as isComputed,$ as isDirtyComputed,z as isDirtySignal,h as isReactive,O as isSignal,A as isSubscriber,E as isSurface,Q as refreshSurface,I as removeEffect,R as useContext};
1
+ function A(t){return typeof window<"u"&&window.requestIdleCallback?window.requestIdleCallback(t,{timeout:100}):typeof window<"u"?window.requestAnimationFrame?window.requestAnimationFrame(()=>{setTimeout(t,0)}):setTimeout(t,0):(typeof t=="function"&&t(),null)}var l=class{constructor(){this.roots=new Map,this.pending=new Set,this.onCompleteCallbacks=new Set,this.onNextIdle=new Set,this.idleScheduled=!1}markAsDirty(e){if(!e.isDirty&&(e.isDirty=!0,e.isAsync||e.immediate||e.effects&&e.effects.size>0?this.scheduleRecomputation(e):(this.onNextIdle.add(e),this.idleScheduled||(this.idleScheduled=!0,A(()=>{for(let s of this.onNextIdle)this.pending.add(s);this.flush(null),this.onNextIdle.clear(),this.idleScheduled=!1}))),e.dependants&&e.dependants.size>0)){let s=[],i=new Set;e.dependants.forEach(r=>{let c=r.deref();c?(this.markAsDirty(c),i.add(c.id)):s.push(r)}),s.forEach(r=>e.dependants.delete(r)),e.dependantIds=i}}scheduleRecomputation(e){if(!e.debounce)return this.recompute(e);let s=Date.now(),i=e.lastComputeTime?s-e.lastComputeTime:1/0;return!e.hasPendingDebounce||i>=e.debounce?(clearTimeout(e.debounceTimer),e.hasPendingDebounce=!0,e.lastComputeTime=s,e.debounceTimer=setTimeout(()=>{e.hasPendingDebounce=!1,e.debounceTimer=null},e.debounce),this.recompute(e)):e.cachedValue}removeReactive(e){this.pending.delete(e),this.onNextIdle.delete(e)}recompute(e){return this.pending.add(e),this.flush(e)}flush(e){let s=Array.from(this.pending);this.pending.clear();let i=this.sortByDependencies(s);for(let r of i)this.onNextIdle.delete(r),r.compute();for(let r of this.onCompleteCallbacks)try{r()}catch(c){console.error("Error in batch completion callback:",c)}if(e)return i.includes(e)||e.compute(),e.cachedValue}sortByDependencies(e){let s=[],i=new Set,r=new Set,c=o=>{if(r.has(o)||i.has(o))return;r.add(o);let a=o.dependants;a&&a.size>0&&a.forEach(u=>{let w=u.deref();w&&e.includes(w)&&c(w)}),r.delete(o),i.add(o),s.unshift(o)};for(let o of e)i.has(o)||c(o);return s}};var C=Symbol.for("@jucie.io/reactive/system");globalThis[C]||(globalThis[C]={computationManager:new l,awaitingRecomputation:new Set,reactives:new WeakMap,subscribers:new Set,currentlyComputing:null,computationStack:[],currentDepth:0,effectsCache:new Set,processingEffects:!1,_nextId:1,config:{maxDepth:2e3},ctx:{}});var n=class t{static get system(){return globalThis[C]}static nextId(){return t.system._nextId++}static addReactive(e,s){t.system.reactives.set(e,s),t.system.subscribers.add(e)}static addSubscriber(e,s){return t.system.reactives.set(e,s),t.system.subscribers.add(e),()=>t.removeSubscriber(e)}static removeSubscriber(e){t.system.subscribers.delete(e),t.system.reactives.delete(e)}static addContext(e,s){if(!e||typeof e!="string")throw new Error("Invalid context key");if(typeof s>"u")throw new Error("Invalid context value");if(e in t.system.ctx)throw new Error("Context key already exists");t.system.ctx[e]=s}static useContext(e){if(!e||e.length===0)return t.system.ctx;if(e.length===1)return t.system.ctx[e[0]];let s=new Array(e.length);for(let i=0;i<e.length;i++)s[i]=t.system.ctx[e[i]];return s}static hasContext(e){if(!e||e.length===0)return Object.keys(t.system.ctx).length>0;if(e.length===1)return e[0]in t.system.ctx;for(let s of e)if(!(s in t.system.ctx))return!1;return!0}static clearContext(){t.system.ctx={}}static resetSystem(){t.system.awaitingRecomputation.clear(),t.system.currentlyComputing=null,t.system.computationStack=[],t.system.currentDepth=0,t.system.effectsCache.clear(),t.system.processingEffects=!1,t.system.ctx={}}static addDependant(e,s){let i=t.system.reactives.get(e);i&&(i.dependants.add(new WeakRef(s)),i.dependantIds.add(s.id))}static addEffect(e,s){let i=t.system.reactives.get(e);return i.isDirty&&t.system.computationManager.scheduleRecomputation(i),i.effects||(i.effects=new Set),i.effects.add(s),t.system.subscribers.add(e),()=>t.removeEffect(e,s)}static removeEffect(e,s){let i=t.system.reactives.get(e);t.system.subscribers.delete(e),i&&i.effects&&i.effects.delete(s)}static processEffectsCache(){let e=new Set(t.system.effectsCache);t.system.effectsCache.clear();for(let s of e)try{(s.effects||new Set).forEach(r=>{r&&r(s.cachedValue)})}catch(i){console.error(`Error in reactive ${s.id} effect:`,i)}t.system.effectsCache.size>0&&setTimeout(()=>{t.processEffectsCache()},0)}static destroy(e){t.system.subscribers.has(e)&&t.system.subscribers.delete(e);let s=t.system.reactives.get(e);s&&t.system.computationManager.removeReactive(s),t.system.reactives.delete(e)}constructor(){this.id=t.nextId(),this.isDirty=!0,this.dependants=new Set,this.dependantIds=new Set}begin(){t.system.awaitingRecomputation.has(this)&&t.system.awaitingRecomputation.delete(this);let e=t.system.computationStack.indexOf(this);if(e!==-1){let s=t.system.computationStack.slice(e).concat(this),i=new Error(`Circular dependency detected: ${s.map(r=>r).join(" -> ")}`);throw i.name="CircularDependencyError",i.displayed=!1,i}if(t.system.currentDepth>=t.system.config.maxDepth)throw new Error(`Maximum reactive depth of ${t.system.config.maxDepth} exceeded`);t.system.computationStack.push(this),t.system.currentlyComputing=this,t.system.currentDepth++}end(){t.system.computationStack.pop(),t.system.currentlyComputing=t.system.computationStack[t.system.computationStack.length-1]||null,t.system.currentDepth--}recompute(){return t.system.awaitingRecomputation.has(this)||t.system.awaitingRecomputation.add(this),t.system.computationManager.scheduleRecomputation(this)}callEffects(){t.system.effectsCache.add(this),t.system.processingEffects||(t.system.processingEffects=!0,setTimeout(()=>{t.processEffectsCache(),t.system.processingEffects=!1},0))}markAsDirty(){if(!this.isDirty){this.isDirty=!0,(this.immediate||this.effects&&this.effects.size>0)&&t.system.computationManager.scheduleRecomputation(this);let e=[],s=new Set;this.dependants.forEach(i=>{let r=i.deref();r?(r.markAsDirty(),s.add(r.id)):e.push(i)}),e.forEach(i=>this.dependants.delete(i)),this.dependantIds=s}}};var f=t=>n.system.reactives.has(t),k=t=>f(t)&&n.system.reactives.get(t)?.isDirty||!1,m=(t,e)=>{if(!f(t))throw new Error("Invalid effect getter");if(!e||typeof e!="function")throw new Error("Invalid effect function");return n.addEffect(t,e)},$=(t,e)=>{if(f(t))return n.removeEffect(t,e)};var B=(t,e)=>n.addContext(t,e),M=(...t)=>t.length===0?n.system.ctx:t.length===1?n.system.ctx[t[0]]:t.map(e=>n.system.ctx[e]),z=(...t)=>n.hasContext(t),F=(t,e=[])=>{if(!f(t))throw new Error("Invalid adapter getter");let s,i=null,r=new Set,c=()=>{if(s!==void 0)return s;let a=e&&e.length>0?traverse(t(),e):t();if(Array.isArray(a))s=a.slice();else if(typeof a=="object"&&a!==null){let u=Object.create(Object.getPrototypeOf(a));Object.defineProperties(u,Object.getOwnPropertyDescriptors(a)),s=Object.freeze(u)}else s=a;return s};return[c,a=>(i||(i=m(t,()=>{s=void 0;for(let u of r)u(c)})),r.add(a),()=>{r.delete(a),r.size===0&&(i(),i=null)})]};var p=class t extends n{static create(e,s={}){let i=new t(e,s);return n.addReactive(i.getter,i),i.getter}constructor(e,s={}){if(s.context&&typeof s.context!="function")throw new Error("Computed context must be a function");super(),this.fn=e,this.effects=new Set(Array.isArray(s.effects)?s.effects:[]),this.cachedValue=s.initialValue||void 0,this.isDirty=s.initialValue===void 0,this.debounce=s.debounce||0,this.onAccess=s.onAccess||void 0,this.detatched=s.detatched||!1,this.immediate=s.immediate||!1,this.useContext=s.context||(n.hasContext()?()=>n.useContext():()=>{}),this.lastComputeTime=void 0,this.hasPendingDebounce=!1,this.debounceTimer=void 0,this.computationId=0,this.getter=this.#e.bind(this),this.immediate&&this.compute()}compute(){this.begin();try{let e=this.useContext?this.useContext():void 0;return this.cachedValue=this.fn(e,this.cachedValue),this.isDirty=!1,this.cachedValue}finally{this.end(),this.callEffects()}}#e(){try{return!this.detatched&&n.system.currentlyComputing&&n.system.currentlyComputing!==this&&!this.dependantIds.has(n.system.currentlyComputing.id)&&(this.dependantIds.add(n.system.currentlyComputing.id),this.dependants.add(new WeakRef(n.system.currentlyComputing))),this.isDirty?this.recompute():this.cachedValue}catch(e){throw e}finally{this.onAccess&&this.onAccess(this.cachedValue)}}},S=(t,e={})=>p.create(t,e),D=t=>{I(t)&&n.destroy(t)},I=t=>{let e=n.system.reactives.get(t);return e?e instanceof p:!1},N=t=>{let e=n.system.reactives.get(t);return e?e.isDirty:!1};var y=class t extends n{static create(e,s={}){let i=new t(e,s);return n.addReactive(i.getter,i),i.getter}constructor(e,s={}){super(),this.cachedValue=void 0,this.roots=new Set,this.effects=new Set(Array.isArray(s.effects)?s.effects:[]),this.debounce=s.debounce||0,this.onAccess=s.onAccess||null,this.detatched=s.detatched||!1,this.immediate=s.immediate||!1,this.pendingChange=e,this.lastComputeTime=null,this.hasPendingDebounce=!1,this.debounceTimer=null,this.getter=(...i)=>this.#e(...i)}compute(){this.begin();try{return this.cachedValue=this.pendingChange,this.pendingChange=void 0,this.isDirty=!1,this.cachedValue}finally{this.end(),this.callEffects()}}#e(...e){try{if(!this.detatched&&n.system.currentlyComputing&&n.system.currentlyComputing!==this&&!this.dependantIds.has(n.system.currentlyComputing.id)&&(this.dependantIds.add(n.system.currentlyComputing.id),this.dependants.add(new WeakRef(n.system.currentlyComputing))),e.length>0){let s=e[0];this.pendingChange=typeof s=="function"?s(this.cachedValue):s,this.markAsDirty();return}return this.isDirty?this.recompute():this.cachedValue}catch(s){throw s}finally{this.onAccess&&this.onAccess(this.cachedValue)}}},E=(t,e={})=>y.create(t,e),W=t=>{O(t)&&n.destroy(t)},O=t=>{let e=n.system.reactives.get(t);return e?e instanceof y:!1},q=t=>{let e=n.system.reactives.get(t);return e?e.isDirty:!1};var b=class t extends n{static create(e,s,i={}){let r=new t(e,s,i);return n.system.reactives.set(r.getter,r),n.system.subscribers.add(r.getter),()=>n.destroy(r.getter)}constructor(e,s,i={}){super(),this.getter=e,this.isDirty=!1,this.subscriber=s,this.debounce=i.debounce||0,this.onAccess=i.onAccess||null,this.immediate=!0,this.hasPendingDebounce=!1,this.lastComputeTime=null,this.debounceTimer=null,this.begin(),this.cachedValue=this.getter(),this.subscriber(this.cachedValue),this.end()}compute(){try{this.cachedValue=this.getter(),this.subscriber(this.cachedValue),this.isDirty=!1}catch(e){throw e}}},Q=(t,e,s={})=>b.create(t,e,s),Y=t=>{P(t)&&n.destroy(t)},P=t=>{let e=n.system.reactives.get(t);return e?e instanceof b:!1};var V=t=>typeof t=="function"&&(t.constructor.name==="AsyncFunction"||t.constructor.name==="AsyncGeneratorFunction");var x=class t extends n{static create(e,s=[],i={}){let r=new t(e,s,i);return n.addReactive(r.getter,r),r.getter}constructor(e,s=[],i={}){if(i.context&&typeof i.context!="function")throw new Error("Binding context must be a function");super(),this.fn=e,this.isAsync=V(e),this.pendingResolve=void 0,this.effects=new Set(Array.isArray(i.effects)?i.effects:[]),this.cachedValue=i.initialValue||void 0,this.isDirty=i.initialValue===void 0,this.debounce=i.debounce||0,this.onAccess=i.onAccess||void 0,this.detatched=i.detatched||!1,this.immediate=i.immediate||!1,this.useContext=i.context||(n.hasContext()?()=>n.useContext():()=>{}),this.resolvers=[],this.rejectors=[],this.lastComputeTime=void 0,this.hasPendingDebounce=!1,this.debounceTimer=void 0,this.computationId=0,this.getter=this.#e.bind(this);for(let r of s)n.addDependant(r,this);this.immediate&&this.compute()}compute(){try{if(!this.isAsync){let i=this.useContext?this.useContext():void 0;return this.cachedValue=this.fn(i,this.cachedValue),this.isDirty=!1,this.cachedValue}this.computationId=(this.computationId||0)+1;let e=this.computationId,s=this.useContext?this.useContext():void 0;return this.pendingResolve=this.fn(s,this.cachedValue),this.pendingResolve.then(i=>(this.computationId===e&&(this.resolvers.forEach(r=>r(i)),this.resolvers=[],this.cachedValue=i,this.isDirty=!1),i)).catch(i=>{this.computationId===e&&(this.rejectors.forEach(r=>r(i)),this.rejectors=[])}).finally(()=>{this.pendingResolve=null,this.computationId===e&&this.callEffects()}),this.cachedValue=new Promise((i,r)=>{this.resolvers.push(i),this.rejectors.push(r)}),this.cachedValue}finally{this.isAsync||this.callEffects()}}#e(){try{return!this.detatched&&n.system.currentlyComputing&&n.system.currentlyComputing!==this&&!this.dependantIds.has(n.system.currentlyComputing.id)&&(this.dependantIds.add(n.system.currentlyComputing.id),this.dependants.add(new WeakRef(n.system.currentlyComputing))),this.isDirty?this.recompute():this.isAsync?Promise.resolve(this.cachedValue):this.cachedValue}catch(e){throw e}finally{this.onAccess&&this.onAccess(this.cachedValue)}}},v=(t,e=[],s={})=>x.create(t,e,s),G=t=>{R(t)&&n.destroy(t)},R=t=>{let e=n.system.reactives.get(t);return e?e instanceof x:!1},H=t=>{let e=n.system.reactives.get(t);return e?e.isDirty:!1};var d=[null,null,(t,e)=>t?.[e[0]]?.[e[1]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]]?.[e[6]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]]?.[e[6]]?.[e[7]]];function K(t){let s="obj"+Array.from({length:t},(r,c)=>`?.[path[${c}]]`).join(""),i=new Function("obj","path",`return ${s}`);return d[t]=i,i}function T(t,e){let s=e.length;return s===0?t:s===1?t[e[0]]:s<d.length&&d[s]||d[s]?d[s](t,e):K(s)(t,e)}var g=Symbol(),h=class t{static surfaces=new WeakMap;static plugins=new Map;static registerPlugin(e,s){if(t.plugins.has(e))throw new Error(`Plugin "${e}" already registered`);t.plugins.set(e,s())}static resetPlugins(){t.plugins.clear()}static create(e,s={}){let i=new t(s),r=i.setup(e);return t.surfaces.set(r,i),r}static createPlugin(e,s,i={}){let r=t.create(s,i);return t.registerPlugin(e,r),r}constructor(e={}){this.options=e,this.setupFn=null,this.subscribers=new Set,this.subscribersQueued=!1,this.destroyCallback=null,this.signals=new Set,this.computeds=new Set,this.bindings=new Set,this.actions=new Set,this.extensions=new Set,this.snapshotCache=g,this.surface=this.#r(),this.useSurface=()=>this.surface}setup(e){if(!e)return null;this.setupFn=e,this.reset();let s=new Set;try{let i;if(typeof e=="function")i=this.#e(e,s);else if(typeof e=="object"&&e!==null)i=this.#o(e,s);else throw new Error("setupFn must be a function or object configuration");return this.#l(i),s.forEach(r=>m(r,()=>this.#i())),this.#i(),this.useSurface}catch(i){throw console.error("Error in setup function",i),i}}reset(){this.subscribers.clear(),this.subscribersQueued=!1,this.signals.clear(),this.computeds.clear(),this.actions.clear(),this.bindings.clear(),this.extensions.clear(),this.snapshotCache=g,this.surface=this.#r()}createSignal(e=void 0,s){let i=E(e);return this.signals.add(i),s?.(i),i}createComputed(e,s){let i=S(e,{context:()=>this.surface});return this.computeds.add(i),s?.(i),i}createBinding(e,s=[],i){let r=v(e,s,{context:()=>this.surface});return this.bindings.add(r),i?.(r),r}createAction(e){let s=e.bind(this.surface,this.surface);return this.actions.add(s),s}extend(e){if(!e)throw new Error("No source surface provided");if(!j(e))throw new Error("Cannot extend non-surface");let s=e();return this.extensions.add(s),s}#e(e,s){return e({signal:(i=void 0)=>this.createSignal(i,r=>s.add(r)),computed:(i=()=>{})=>this.createComputed(i,r=>s.add(r)),binding:(i=()=>{},r=[])=>this.createBinding(i,r,c=>s.add(c)),action:(i=()=>{})=>this.createAction(i),extend:i=>this.extend(i),destroy:()=>this.#n(),...Object.fromEntries(t.plugins.entries())})||{}}#c(e,s,i){if(typeof e!="object"||e===null)return typeof e=="function"?e():e;if(!("default"in e))return s&&"dummy"in e&&console.warn(`State "${i}" has dummy value but no default value`),typeof e=="function"?e():e;let r=s&&"dummy"in e?e.dummy:e.default;return typeof r=="function"?r():r}#o(e,s){let i={},r=this.options.mode==="development"||this.options.mode==="dev";if(e.extend&&Array.isArray(e.extend))for(let c of e.extend)this.extend(c);if(e.state&&typeof e.state=="object")for(let[c,o]of Object.entries(e.state)){let a=this.#c(o,r,c);i[c]=this.createSignal(a,u=>s.add(u))}if(e.computed&&typeof e.computed=="object")for(let[c,o]of Object.entries(e.computed))typeof o=="function"&&(i[c]=this.createComputed(o,a=>s.add(a)));if(e.actions&&typeof e.actions=="object")for(let[c,o]of Object.entries(e.actions))typeof o=="function"&&(i[c]=this.createAction(o));return e.onInit&&typeof e.onInit=="function"&&Promise.resolve().then(()=>{try{e.onInit(this.surface)}catch(c){console.error("Error in onInit callback",c)}}),e.onDestroy&&typeof e.onDestroy=="function"&&(this.destroyCallback=e.onDestroy),i}#a(){return[()=>this.#t(),e=>this.#s(e)]}#t(){if(this.snapshotCache!==g)return this.snapshotCache;let e=Object.create(Object.getPrototypeOf(this.surface));return Object.defineProperties(e,Object.getOwnPropertyDescriptors(this.surface)),this.snapshotCache=Object.freeze(e),this.snapshotCache}#s(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}#u(e){for(let s of this.subscribers)s(e)}#i(){this.subscribers.size===0||this.subscribersQueued||(this.subscribersQueued=!0,Promise.resolve().then(()=>{this.subscribersQueued=!1,this.snapshotCache=g,this.#u(this.#t())}))}#r(e=Object.create(null)){return Object.defineProperty(e,"$get",{value:s=>this.#d(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$set",{value:(s,i)=>this.#h(s,i),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$dispatch",{value:s=>this.#f(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$inject",{value:s=>Object.assign({},this.surface,s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$snapshot",{value:()=>this.#t(),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$subscribe",{value:s=>this.#s(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$adapter",{value:()=>this.#a(),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$destroy",{value:()=>this.#n(),writable:!1,enumerable:!1,configurable:!1}),e}#n(){if(this.destroyCallback&&typeof this.destroyCallback=="function")try{this.destroyCallback(this.surface)}catch(s){console.error("Error in onDestroy callback",s)}let e=this.surfaceComputed;this.surfaceComputed=null,t.surfaces.delete(e),D(e)}#d(e=[]){return T(this.surface,e)}#h(e,s){let i=this.signals?.get?.(e);return i&&i(s),this.surface}#f(e,...s){let i=this.actions.has(e)?this.actions.get(e):this.surface[e];return typeof i=="function"?i(...s):this.surfaceComputed()}#l(e={}){let s=Object.keys(this.surface);for(;s.length>0;){let r=s.shift();r in this.surface&&delete this.surface[r]}for(let[r,c]of t.plugins)Object.defineProperty(this.surface,r,{value:c});for(let r of this.extensions){let c=Object.getOwnPropertyDescriptors(r),o=Object.fromEntries(Object.entries(c).filter(([a])=>!a.startsWith("$")));Object.defineProperties(this.surface,o)}let i=Object.entries(e);for(let[r,c]of i){if(this.signals.has(c)){Object.defineProperty(this.surface,r,{get:()=>c(),set:o=>c(o)});continue}if(this.computeds.has(c)){Object.defineProperty(this.surface,r,{get:()=>c()});continue}if(this.bindings.has(c)){Object.defineProperty(this.surface,r,{get:()=>c()});continue}if(this.actions.has(c)){Object.defineProperty(this.surface,r,{value:c});continue}this.surface[r]=c}return this.surface}},J=(...t)=>h.create(...t),L=t=>{if(j(t)){let e=h.surfaces.get(t);e&&e.setup()}},U=(...t)=>h.createPlugin(...t),j=t=>h.surfaces.has(t);export{n as Reactive,B as addContext,m as addEffect,F as createAdapter,v as createBinding,S as createComputed,E as createSignal,Q as createSubscriber,U as definePlugin,J as defineSurface,G as destroyBinding,D as destroyComputed,W as destroySignal,Y as destroySubscriber,z as hasContext,R as isBinding,I as isComputed,k as isDirty,H as isDirtyBinding,N as isDirtyComputed,q as isDirtySignal,f as isReactive,O as isSignal,P as isSubscriber,j as isSurface,L as refreshSurface,$ as removeEffect,M as useContext};
2
2
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/utils/nextIdleTick.js", "../src/ComputationManager.js", "../src/Reactive.js", "../src/Computed.js", "../src/Signal.js", "../src/Subscriber.js", "../src/lib/traverse.js", "../src/Surface.js"],
4
- "sourcesContent": ["export function nextIdleTick(callback) {\n if (typeof window !== 'undefined' && window.requestIdleCallback) {\n return window.requestIdleCallback(callback, { timeout: 100 });\n }\n\n // Fallback for browsers without requestIdleCallback (Safari/WebKit)\n if (typeof window !== 'undefined') {\n // Use requestAnimationFrame + setTimeout for better idle approximation\n if (window.requestAnimationFrame) {\n return window.requestAnimationFrame(() => {\n setTimeout(callback, 0);\n });\n }\n // Final fallback to setTimeout\n return setTimeout(callback, 0);\n }\n\n // Server-side or no window object - execute immediately\n if (typeof callback === 'function') {\n callback();\n }\n return null;\n}\n", "import { nextIdleTick } from './utils/nextIdleTick.js';\n\nexport class ComputationManager {\n constructor() {\n this.roots = new Map();\n this.pending = new Set();\n this.onCompleteCallbacks = new Set();\n this.onNextIdle = new Set();\n this.idleScheduled = false;\n }\n\n markAsDirty(reactive) {\n if (!reactive.isDirty) {\n reactive.isDirty = true;\n \n if (reactive.isAsync || reactive.immediate || (reactive.effects && reactive.effects.size > 0)) {\n this.scheduleRecomputation(reactive);\n } else {\n this.onNextIdle.add(reactive);\n\n if (!this.idleScheduled) {\n this.idleScheduled = true;\n nextIdleTick(() => {\n for (const reactive of this.onNextIdle) {\n this.pending.add(reactive);\n }\n this.flush(null);\n this.onNextIdle.clear();\n this.idleScheduled = false; // \u2190 Reset flag\n });\n }\n }\n\n if (reactive.dependants && reactive.dependants.size > 0) {\n // Process WeakRefs and rebuild ID set with only alive IDs\n const deadRefs = [];\n const ids = new Set();\n reactive.dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant) {\n this.markAsDirty(dependant);\n ids.add(dependant.id);\n } else {\n deadRefs.push(weakRef);\n }\n });\n // Clean up dead WeakRefs and sync IDs\n deadRefs.forEach(ref => reactive.dependants.delete(ref));\n reactive.dependantIds = ids;\n }\n }\n }\n\n scheduleRecomputation(reactive) {\n if (!reactive.debounce) {\n return this.recompute(reactive);\n }\n\n // Check if we can recompute (either first time or cooldown expired)\n const now = Date.now();\n const timeElapsed = reactive.lastComputeTime ? now - reactive.lastComputeTime : Infinity;\n const canRecompute = !reactive.hasPendingDebounce || timeElapsed >= reactive.debounce;\n\n if (canRecompute) {\n // Clear any existing timer and set up new cooldown period\n clearTimeout(reactive.debounceTimer);\n reactive.hasPendingDebounce = true;\n reactive.lastComputeTime = now;\n \n reactive.debounceTimer = setTimeout(() => {\n reactive.hasPendingDebounce = false;\n reactive.debounceTimer = null;\n }, reactive.debounce);\n \n return this.recompute(reactive);\n }\n\n // Still in cooldown period, return cached value\n return reactive.cachedValue;\n }\n\n removeReactive(reactive) {\n this.pending.delete(reactive);\n this.onNextIdle.delete(reactive);\n }\n\n recompute(reactive) {\n this.pending.add(reactive);\n return this.flush(reactive);\n }\n\n flush(reactive) {\n const reactives = Array.from(this.pending);\n this.pending.clear();\n\n // Sort by dependencies\n const sortedReactives = this.sortByDependencies(reactives);\n \n // Process in reverse order (dependencies first)\n for (const reactive of sortedReactives) {\n this.onNextIdle.delete(reactive);\n reactive.compute()\n }\n\n // Notify completion callbacks\n for (const callback of this.onCompleteCallbacks) {\n try {\n callback();\n } catch (error) {\n console.error('Error in batch completion callback:', error);\n }\n }\n\n // If we have a target ID, ensure it's computed and return its value\n if (reactive) {\n // Make sure the target computed is evaluated if it wasn't in the batch\n if (!sortedReactives.includes(reactive)) {\n reactive.compute();\n }\n return reactive.cachedValue;\n }\n \n return undefined;\n }\n\n sortByDependencies(reactives) {\n const sorted = [];\n const visited = new Set();\n const visiting = new Set();\n\n const visit = (reactive) => {\n if (visiting.has(reactive)) return;\n if (visited.has(reactive)) return;\n\n visiting.add(reactive);\n\n // Get dependant computed values (handle WeakRefs)\n const dependants = reactive.dependants;\n if (dependants && dependants.size > 0) {\n dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant && reactives.includes(dependant)) {\n visit(dependant); // Visit dependants first\n }\n });\n }\n\n visiting.delete(reactive);\n visited.add(reactive);\n sorted.unshift(reactive); // Add to start of array instead of end\n };\n\n // Process all nodes\n for (const reactive of reactives) {\n if (!visited.has(reactive)) {\n visit(reactive);\n }\n }\n\n return sorted;\n }\n}", "import { ComputationManager } from './ComputationManager.js';\n\nconst REACTIVE_SYSTEM = Symbol.for('@jucie.io/reactive/system');\n\nif (!globalThis[REACTIVE_SYSTEM]) {\n globalThis[REACTIVE_SYSTEM] = {\n computationManager: new ComputationManager(),\n awaitingRecomputation: new Set(),\n reactives: new WeakMap(),\n subscribers: new Set(),\n currentlyComputing: null,\n computationStack: [],\n currentDepth: 0,\n effectsCache: new Set(),\n processingEffects: false,\n _nextId: 1,\n config: {\n maxDepth: 2000,\n },\n ctx: {},\n };\n}\n\nexport class Reactive {\n static get system() {\n return globalThis[REACTIVE_SYSTEM];\n }\n \n // // Backwards compatibility getters/setters for direct property access\n // static get ctx() {\n // return Reactive.system.ctx;\n // }\n \n // static set ctx(value) {\n // Reactive.system.ctx = value;\n // }\n \n constructor() {\n this.id = Reactive.nextId();\n this.isDirty = true;\n this.dependants = new Set();\n this.dependantIds = new Set();\n }\n \n static nextId() {\n return Reactive.system._nextId++;\n }\n\n static addReactive(getter, reactive) {\n Reactive.system.reactives.set(getter, reactive);\n Reactive.system.subscribers.add(getter);\n }\n\n static addSubscriber(getter, subscriber) {\n Reactive.system.reactives.set(getter, subscriber);\n Reactive.system.subscribers.add(getter);\n return () => Reactive.removeSubscriber(getter);\n }\n\n static removeSubscriber(getter) {\n Reactive.system.subscribers.delete(getter);\n Reactive.system.reactives.delete(getter);\n }\n\n static addContext(key, value) {\n if (!key || typeof key !== 'string') {\n throw new Error('Invalid context key');\n }\n \n if (typeof value === 'undefined') {\n throw new Error('Invalid context value');\n }\n \n if (key in Reactive.system.ctx) {\n throw new Error('Context key already exists');\n }\n \n Reactive.system.ctx[key] = value;\n }\n\n static useContext(keys) { \n if (!keys || keys.length === 0) return Reactive.system.ctx;\n if (keys.length === 1) return Reactive.system.ctx[keys[0]];\n\n const out = new Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n out[i] = Reactive.system.ctx[keys[i]];\n }\n return out;\n }\n\n static hasContext(keys) {\n if (!keys || keys.length === 0) return Object.keys(Reactive.system.ctx).length > 0;\n if (keys.length === 1) return keys[0] in Reactive.system.ctx;\n for (const key of keys) {\n if (!(key in Reactive.system.ctx)) return false;\n }\n return true;\n }\n\n static clearContext() {\n Reactive.system.ctx = {};\n }\n \n static resetSystem() {\n // Reset all system state (useful for testing)\n Reactive.system.awaitingRecomputation.clear();\n Reactive.system.currentlyComputing = null;\n Reactive.system.computationStack = [];\n Reactive.system.currentDepth = 0;\n Reactive.system.effectsCache.clear();\n Reactive.system.processingEffects = false;\n Reactive.system.ctx = {};\n // Note: We don't reset reactives WeakMap, subscribers Set, or _nextId as they may be in use\n }\n\n begin() {\n if (Reactive.system.awaitingRecomputation.has(this)) {\n Reactive.system.awaitingRecomputation.delete(this);\n }\n\n const reactorIndex = Reactive.system.computationStack.indexOf(this);\n\n if (reactorIndex !== -1) {\n const cycle = Reactive.system.computationStack.slice(reactorIndex).concat(this);\n const error = new Error(`Circular dependency detected: ${cycle.map(r => r).join(' -> ')}`);\n error.name = 'CircularDependencyError';\n error.displayed = false;\n throw error;\n }\n \n if (Reactive.system.currentDepth >= Reactive.system.config.maxDepth) {\n throw new Error(`Maximum reactive depth of ${Reactive.system.config.maxDepth} exceeded`);\n }\n \n Reactive.system.computationStack.push(this);\n Reactive.system.currentlyComputing = this;\n Reactive.system.currentDepth++;\n }\n \n end() {\n Reactive.system.computationStack.pop();\n Reactive.system.currentlyComputing = Reactive.system.computationStack[Reactive.system.computationStack.length - 1] || null;\n Reactive.system.currentDepth--;\n }\n\n recompute() {\n if (!Reactive.system.awaitingRecomputation.has(this)) {\n Reactive.system.awaitingRecomputation.add(this);\n }\n\n \n return Reactive.system.computationManager.scheduleRecomputation(this);\n }\n\n static addDependant(getter, dependant) {\n const reactive = Reactive.system.reactives.get(getter);\n if (reactive) {\n reactive.dependants.add(new WeakRef(dependant));\n reactive.dependantIds.add(dependant.id);\n }\n }\n\n static addEffect(getter, effect) {\n const reactive = Reactive.system.reactives.get(getter);\n \n // Compute if needed and notify with current value\n if (reactive.isDirty) {\n Reactive.system.computationManager.scheduleRecomputation(reactive);\n }\n \n if (!reactive.effects) {\n reactive.effects = new Set();\n }\n \n // Store the WeakRef instead of the raw effect\n reactive.effects.add(effect);\n Reactive.system.subscribers.add(getter);\n \n // Return unsubscribe function\n return () => Reactive.removeEffect(getter, effect);;\n }\n\n static removeEffect(getter, effect) {\n const reactive = Reactive.system.reactives.get(getter);\n Reactive.system.subscribers.delete(getter);\n if (reactive && reactive.effects) {\n reactive.effects.delete(effect);\n }\n }\n\n callEffects() { \n Reactive.system.effectsCache.add(this);\n \n // Use a single setTimeout for batching\n if (!Reactive.system.processingEffects) {\n Reactive.system.processingEffects = true;\n setTimeout(() => {\n Reactive.processEffectsCache();\n Reactive.system.processingEffects = false;\n }, 0);\n }\n }\n\n static processEffectsCache() {\n const reactives = new Set(Reactive.system.effectsCache);\n Reactive.system.effectsCache.clear();\n \n for (const reactive of reactives) {\n try {\n // Process effects using WeakRefs\n const effects = reactive.effects || new Set();\n effects.forEach(effect => {\n if (effect) {\n effect(reactive.cachedValue);\n }\n });\n } catch (error) {\n console.error(`Error in reactive ${reactive.id} effect:`, error);\n }\n }\n \n // If new effects were added during processing, schedule another batch\n if (Reactive.system.effectsCache.size > 0) {\n setTimeout(() => {\n Reactive.processEffectsCache();\n }, 0);\n }\n }\n\n markAsDirty() {\n if (!this.isDirty) {\n this.isDirty = true;\n \n if (this.immediate || (this.effects && this.effects.size > 0)) {\n Reactive.system.computationManager.scheduleRecomputation(this);\n }\n \n // Process WeakRefs and clean up dead ones\n const deadRefs = [];\n const ids = new Set();\n this.dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant) {\n dependant.markAsDirty();\n ids.add(dependant.id);\n } else {\n deadRefs.push(weakRef);\n }\n });\n // Clean up dead WeakRefs and sync IDs\n deadRefs.forEach(ref => this.dependants.delete(ref));\n this.dependantIds = ids;\n }\n }\n\n static destroy(getter) {\n if (Reactive.system.subscribers.has(getter)) {\n Reactive.system.subscribers.delete(getter);\n }\n const reactive = Reactive.system.reactives.get(getter);\n if (reactive) {\n Reactive.system.computationManager.removeReactive(reactive);\n }\n Reactive.system.reactives.delete(getter);\n }\n}\n\nexport const markAsDirty = (getter) => {\n if (isReactive(getter)) {\n const reactiveInstance = Reactive.system.reactives.get(getter);\n if (reactiveInstance) {\n return reactiveInstance.markAsDirty();\n }\n }\n}\n\nexport const isReactive = (getter) => {\n return Reactive.system.reactives.has(getter);\n}\n\nexport const addEffect = (getter, effect) => {\n if (!isReactive(getter)) {\n throw new Error('Invalid effect getter');\n \n }\n\n if (!effect || typeof effect !== 'function') {\n throw new Error('Invalid effect function');\n }\n\n return Reactive.addEffect(getter, effect);\n}\n\nexport const removeEffect = (getter, effect) => {\n if (isReactive(getter)) {\n return Reactive.removeEffect(getter, effect);\n }\n}\n\nexport const destroyReactive = (getter) => {\n if (isReactive(getter)) {\n return Reactive.destroy(getter);\n }\n}\n\nexport const addContext = (key, value) => Reactive.addContext(key, value)\n\nexport const useContext = (...keys) => {\n if (keys.length === 0) return Reactive.system.ctx;\n if (keys.length === 1) return Reactive.system.ctx[keys[0]];\n return keys.map(key => Reactive.system.ctx[key]);\n}\n\nexport const hasContext = (...keys) => Reactive.hasContext(keys)\n\nexport const createAdapter = (getter, path = []) => {\n if (!isReactive(getter)) {\n throw new Error('Invalid adapter getter');\n }\n\n let snapshotCache = undefined;\n let unsubscribeAll = null;\n const subscribers = new Set();\n\n const getSnapshot = () => {\n if (snapshotCache !== undefined) {\n return snapshotCache;\n }\n\n const value = path && path.length > 0 ? traverse(getter(), path) : getter();\n\n if (Array.isArray(value)) {\n snapshotCache = value.slice();\n } else if (typeof value === 'object' && value !== null) {\n const clone = Object.create(Object.getPrototypeOf(value));\n Object.defineProperties(clone, Object.getOwnPropertyDescriptors(value));\n snapshotCache = Object.freeze(clone);\n } else {\n snapshotCache = value;\n }\n \n return snapshotCache;\n };\n\n const subscribe = (listener) => {\n if (!unsubscribeAll) {\n unsubscribeAll = addEffect(getter, () => {\n snapshotCache = undefined;\n for (const subscriber of subscribers) {\n subscriber(getSnapshot);\n }\n });\n }\n \n subscribers.add(listener);\n return () => {\n subscribers.delete(listener);\n if (subscribers.size === 0) {\n unsubscribeAll();\n unsubscribeAll = null;\n }\n };\n };\n\n return [getSnapshot, subscribe];\n}", "import { Reactive } from './Reactive.js';\n\nexport class Computed extends Reactive {\n static create(fn, config = {}) {\n const computed = new Computed(fn, config);\n Reactive.addReactive(computed.getter, computed);\n return computed.getter;\n }\n\n // Super\n // props: id, isDirty, dependants, dependantIds\n // methods: begin(), end(), recompute(), callEffects(), addDependant(), markAsDirty()\n\n constructor(fn, config = {}) {\n // Validate context must be a function if provided\n if (config.context && typeof config.context !== 'function') {\n throw new Error('Computed context must be a function');\n }\n super(); // Sets id, isDirty, dependants, dependantIds\n \n this.fn = fn;\n this.effects = new Set(Array.isArray(config.effects) ? config.effects : []);\n this.cachedValue = config.initialValue || undefined;\n this.isDirty = config.initialValue === undefined;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || undefined;\n this.detatched = config.detatched || false;\n this.immediate = config.immediate || false; \n this.useContext = config.context || (Reactive.hasContext() ? () => Reactive.useContext() : () => undefined);\n this.lastComputeTime = undefined;\n this.hasPendingDebounce = false;\n this.debounceTimer = undefined;\n this.computationId = 0; // Track computation version\n this.getter = this.#getter.bind(this);\n \n\n if (this.immediate) {\n this.compute();\n }\n }\n\n compute() {\n this.begin();\n try { \n const contextValue = this.useContext ? this.useContext() : undefined;\n this.cachedValue = this.fn(contextValue, this.cachedValue);\n this.isDirty = false;\n return this.cachedValue;\n } finally {\n this.end();\n this.callEffects();\n }\n }\n\n #getter() {\n try {\n if (!this.detatched && Reactive.system.currentlyComputing && Reactive.system.currentlyComputing !== this && !this.dependantIds.has(Reactive.system.currentlyComputing.id)) {\n this.dependantIds.add(Reactive.system.currentlyComputing.id);\n this.dependants.add(new WeakRef(Reactive.system.currentlyComputing));\n }\n\n return !this.isDirty ? this.cachedValue : this.recompute();\n } catch (error) {\n throw error;\n } finally {\n if (this.onAccess) {\n this.onAccess(this.cachedValue);\n }\n }\n }\n}\n\nexport const createComputed = (fn, config = {}) => Computed.create(fn, config);\n\nexport const destroyComputed = (target) => {\n if (isComputed(target)) {\n Reactive.destroy(target);\n }\n}\n\nexport const isComputed = (getter) => {\n const computed = Reactive.system.reactives.get(getter);\n if (!computed) {\n return false;\n }\n\n return computed instanceof Computed;\n}\n\nexport const isDirtyComputed = (getter) => {\n const computed = Reactive.system.reactives.get(getter);\n if (!computed) {\n return false;\n }\n\n return computed.isDirty;\n}\n", "import { Reactive } from './Reactive.js';\n\nexport class Signal extends Reactive {\n static create(initialValue, config = {}) {\n const signal = new Signal(initialValue, config);\n Reactive.addReactive(signal.getter, signal);\n return signal.getter;\n }\n\n constructor(initialValue, config = {}) {\n super(); // Sets id, isDirty, dependants, dependantIds\n this.cachedValue = undefined;\n // dependants and dependantIds set by super()\n this.roots = new Set();\n this.effects = new Set(Array.isArray(config.effects) ? config.effects : []);\n // isDirty set by super()\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || null;\n this.detatched = config.detatched || false;\n this.immediate = config.immediate || false;\n this.pendingChange = initialValue;\n this.lastComputeTime = null;\n this.hasPendingDebounce = false;\n this.debounceTimer = null;\n this.getter = (...args) => this.#getter(...args);\n }\n\n compute() {\n this.begin();\n try {\n this.cachedValue = this.pendingChange;\n this.pendingChange = undefined;\n this.isDirty = false;\n return this.cachedValue;\n } finally {\n this.end();\n this.callEffects();\n }\n }\n\n #getter(...args) {\n try {\n if (!this.detatched && Reactive.system.currentlyComputing && Reactive.system.currentlyComputing !== this && !this.dependantIds.has(Reactive.system.currentlyComputing.id)) {\n this.dependantIds.add(Reactive.system.currentlyComputing.id);\n this.dependants.add(new WeakRef(Reactive.system.currentlyComputing));\n }\n\n if (args.length > 0) {\n const signal = args[0];\n this.pendingChange = typeof signal === 'function' ? signal(this.cachedValue) : signal;\n this.markAsDirty();\n return;\n }\n\n if (this.isDirty) {\n return this.recompute();\n }\n\n return this.cachedValue;\n \n } catch (error) {\n throw error;\n } finally {\n if (this.onAccess) {\n this.onAccess(this.cachedValue);\n }\n }\n }\n}\n\nexport const createSignal = (initialValue, config = {}) => Signal.create(initialValue, config);\n\nexport const destroySignal = (getter) => {\n if (isSignal(getter)) {\n Reactive.destroy(getter);\n }\n}\n\nexport const isSignal = (getter) => {\n const signal = Reactive.system.reactives.get(getter);\n if (!signal) {\n return false;\n }\n\n return signal instanceof Signal;\n}\n\nexport const isDirtySignal = (getter) => {\n const signal = Reactive.system.reactives.get(getter);\n if (!signal) {\n return false;\n }\n\n return signal.isDirty;\n}", "import { Reactive } from './Reactive.js';\n\nexport class Subscriber extends Reactive {\n static create(getter, fn, config = {}) {\n const subscriber = new Subscriber(getter, fn, config);\n Reactive.system.reactives.set(subscriber.getter, subscriber);\n Reactive.system.subscribers.add(subscriber.getter);\n return () => Reactive.destroy(subscriber.getter);\n }\n\n constructor(getter, subscriber, config = {}) {\n super(); // Sets id, isDirty, dependants, dependantIds\n this.getter = getter;\n this.isDirty = false; // Override base class default\n this.subscriber = subscriber;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || null;\n this.immediate = true;\n this.hasPendingDebounce = false;\n this.lastComputeTime = null;\n this.debounceTimer = null;\n // dependants and dependantIds set by super()\n this.begin();\n this.cachedValue = this.getter();\n this.subscriber(this.cachedValue); // Call subscriber with initial value\n this.end();\n }\n\n compute() {\n try {\n this.cachedValue = this.getter();\n this.subscriber(this.cachedValue);\n this.isDirty = false;\n } catch (error) {\n throw error;\n }\n }\n}\n\nexport const createSubscriber = (getter, fn, config = {}) => Subscriber.create(getter, fn, config);\n\nexport const destroySubscriber = (getter) => {\n if (isSubscriber(getter)) {\n Reactive.destroy(getter);\n }\n}\n\nexport const isSubscriber = (getter) => {\n const subscriber = Reactive.system.reactives.get(getter);\n if (!subscriber) {\n return false;\n }\n\n return subscriber instanceof Subscriber;\n}", "const traversalFunctions = [\n null, // index 0 (unused)\n null, // index 1 (single property access doesn't need optimization)\n (obj, path) => obj?.[path[0]]?.[path[1]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]]?.[path[6]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]]?.[path[6]]?.[path[7]]\n]\n\nfunction createTraversalFunction(length) {\n const accessors = Array.from({ length }, (_, i) => `?.[path[${i}]]`);\n const expr = \"obj\" + accessors.join(\"\");\n const fn = new Function(\"obj\", \"path\", `return ${expr}`);\n traversalFunctions[length] = fn;\n return fn;\n}\n\nexport function traverse(state, path) {\n const len = path.length;\n if (len === 0) return state;\n if (len === 1) return state[path[0]];\n \n // Use existing function if available\n if (len < traversalFunctions.length && traversalFunctions[len]) {\n return traversalFunctions[len](state, path);\n }\n \n // Create and cache new function if needed\n if (!traversalFunctions[len]) {\n return createTraversalFunction(len)(state, path);\n }\n \n return traversalFunctions[len](state, path);\n}\n", "// Surface.js\nimport { createComputed, destroyComputed } from './Computed.js';\nimport { addEffect } from './Reactive.js';\nimport { createSignal } from './Signal.js';\nimport { traverse } from './lib/traverse.js';\n\nconst EMPTY_CACHE = Symbol();\n\nexport class Surface {\n static surfaces = new WeakMap();\n static plugins = new Map();\n\n static registerPlugin(name, plugin) {\n if (Surface.plugins.has(name)) {\n throw new Error(`Plugin \"${name}\" already registered`);\n }\n Surface.plugins.set(name, plugin());\n }\n\n static resetPlugins() {\n Surface.plugins.clear();\n }\n\n static create(setupFn, options = {}) {\n const instance = new Surface(options);\n const useSurface = instance.setup(setupFn);\n Surface.surfaces.set(useSurface, instance);\n return useSurface;\n }\n\n static createPlugin(name, fn, options = {}) {\n const plugin = Surface.create(fn, options);\n Surface.registerPlugin(name, plugin);\n return plugin;\n }\n\n constructor(options = {}) {\n this.options = options;\n this.setupFn = null;\n this.subscribers = new Set();\n this.subscribersQueued = false;\n this.destroyCallback = null;\n\n // Values, computeds, actions, and extensions that are pending to be bound to the surface\n this.values = new Set();\n this.computeds = new Set();\n this.actions = new Set();\n this.extensions = new Set();\n\n this.snapshotCache = EMPTY_CACHE;\n this.surface = this.#createSurface();\n this.useSurface = () => this.surface;\n }\n\n setup(setupFn) {\n if (!setupFn) {\n return null;\n }\n\n this.setupFn = setupFn;\n this.reset();\n\n const pendingReactives = new Set();\n\n try {\n let result;\n \n if (typeof setupFn === 'function') {\n result = this.#setupFromFunction(setupFn, pendingReactives);\n } else if (typeof setupFn === 'object' && setupFn !== null) {\n result = this.#setupFromObject(setupFn, pendingReactives);\n } else {\n throw new Error('setupFn must be a function or object configuration');\n }\n \n this.#bindSurface(result);\n pendingReactives.forEach(reactive => addEffect(reactive, () => this.#queueSubscribers()));\n this.#queueSubscribers(); \n return this.useSurface;\n } catch (error) {\n console.error('Error in setup function', error);\n throw error;\n }\n }\n\n reset() {\n this.subscribers.clear();\n this.subscribersQueued = false;\n this.values.clear();\n this.computeds.clear();\n this.actions.clear();\n this.extensions.clear();\n this.snapshotCache = EMPTY_CACHE;\n this.surface = this.#createSurface();\n }\n\n createValue(initial = undefined, cb) {\n const signal = createSignal(initial);\n const value = Object.create(null);\n Object.defineProperty(value, 'value', {\n get: () => signal(),\n set: (newValue) => signal(newValue),\n enumerable: true,\n });\n this.values.add(value);\n cb?.(signal);\n return value;\n }\n\n createComputed(fn, cb) {\n const computed = createComputed(fn, { context: () => this.surface });\n const computedValue = Object.create(null);\n Object.defineProperty(computedValue, 'value', {\n get: () => computed(),\n enumerable: true,\n });\n this.computeds.add(computedValue);\n cb?.(computed);\n return computedValue;\n }\n\n createAction(fn) {\n const action = fn.bind(this.surface, this.surface)\n this.actions.add(action);\n return action;\n }\n\n extend(useSurface) {\n \n if (!useSurface) throw new Error('No source surface provided');\n \n if (!isSurface(useSurface)) {\n throw new Error('Cannot extend non-surface');\n }\n const surface = useSurface();\n this.extensions.add(surface);\n return surface;\n }\n\n #setupFromFunction(setupFn, pendingReactives) {\n return setupFn({\n value: (initial = undefined) => this.createValue(initial, (signal) => pendingReactives.add(signal)),\n computed: (fn = () => {}) => this.createComputed(fn, (reactor) => pendingReactives.add(reactor)),\n action: (fn = () => {}) => this.createAction(fn),\n extend: (useSurface) => this.extend(useSurface),\n destroy: () => this.#destroy(),\n ...Object.fromEntries(Surface.plugins.entries())\n }) || {};\n }\n\n #processStateValue(stateConfig, isDev, key) {\n // Support shorthand: state: { count: 0 } instead of { count: { default: 0 } }\n if (typeof stateConfig !== 'object' || stateConfig === null) {\n return typeof stateConfig === 'function' ? stateConfig() : stateConfig;\n }\n \n // If it's an object but doesn't have 'default', treat as shorthand\n if (!('default' in stateConfig)) {\n // Validate state config in dev mode\n if (isDev && 'dummy' in stateConfig) {\n console.warn(`State \"${key}\" has dummy value but no default value`);\n }\n return typeof stateConfig === 'function' ? stateConfig() : stateConfig;\n }\n \n // Full config with default/dummy\n let value = isDev && 'dummy' in stateConfig ? stateConfig.dummy : stateConfig.default;\n return typeof value === 'function' ? value() : value;\n }\n\n #setupFromObject(config, pendingReactives) {\n const result = {};\n const isDev = this.options.mode === 'development' || this.options.mode === 'dev';\n\n // 1. Process extend array first (so extended properties are available)\n if (config.extend && Array.isArray(config.extend)) {\n for (const useSurface of config.extend) {\n this.extend(useSurface);\n }\n }\n\n // 2. Process plugins (if specified) - handled in #bindSurface via Surface.plugins\n // Note: Plugins are automatically added to all surfaces, so we don't need to add them to result\n // If you want selective plugin inclusion, you'd need to modify #bindSurface\n\n // 3. Process state definitions\n if (config.state && typeof config.state === 'object') {\n for (const [key, stateConfig] of Object.entries(config.state)) {\n const initialValue = this.#processStateValue(stateConfig, isDev, key);\n result[key] = this.createValue(initialValue, (signal) => pendingReactives.add(signal));\n }\n }\n\n // 4. Process computed properties\n if (config.computed && typeof config.computed === 'object') {\n for (const [key, fn] of Object.entries(config.computed)) {\n if (typeof fn === 'function') {\n result[key] = this.createComputed(fn, (reactor) => pendingReactives.add(reactor));\n }\n }\n }\n\n // 5. Process actions\n if (config.actions && typeof config.actions === 'object') {\n for (const [key, fn] of Object.entries(config.actions)) {\n if (typeof fn === 'function') {\n result[key] = this.createAction(fn);\n }\n }\n }\n\n // 6. Handle lifecycle hooks\n if (config.onInit && typeof config.onInit === 'function') {\n // Execute after setup is complete\n Promise.resolve().then(() => {\n try {\n config.onInit(this.surface);\n } catch (error) {\n console.error('Error in onInit callback', error);\n }\n });\n }\n\n if (config.onDestroy && typeof config.onDestroy === 'function') {\n // Store for later execution\n this.destroyCallback = config.onDestroy;\n }\n\n return result;\n }\n\n #createAdapter () { \n return [() => this.#getSnapshot(), (subscriber) => this.#subscribe(subscriber)];\n }\n\n #getSnapshot() {\n if (this.snapshotCache !== EMPTY_CACHE) {\n return this.snapshotCache;\n }\n\n const clone = Object.create(Object.getPrototypeOf(this.surface));\n Object.defineProperties(clone, Object.getOwnPropertyDescriptors(this.surface));\n this.snapshotCache = Object.freeze(clone);\n \n return this.snapshotCache;\n };\n\n #subscribe(listener) {\n this.subscribers.add(listener);\n return () => this.subscribers.delete(listener);\n }\n\n #callSubscribers(snapshot) {\n for (const subscriber of this.subscribers) {\n subscriber(snapshot);\n }\n }\n\n #queueSubscribers() {\n if (this.subscribers.size === 0 || this.subscribersQueued) return;\n this.subscribersQueued = true;\n Promise.resolve().then(() => {\n this.subscribersQueued = false;\n this.snapshotCache = EMPTY_CACHE;\n this.#callSubscribers(this.#getSnapshot());\n });\n }\n\n #createSurface(surface = Object.create(null)) {\n Object.defineProperty(surface, '$get', {\n value: (path) => this.#get(path),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$set', {\n value: (path, newValue) => this.#set(path, newValue),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$dispatch', {\n value: (name) => this.#dispatch(name),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$inject', {\n value: (overrides) => Object.assign({}, this.surface, overrides),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$snapshot', {\n value: () => this.#getSnapshot(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$subscribe', {\n value: (listener) => this.#subscribe(listener),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$adapter', {\n value: () => this.#createAdapter(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$destroy', {\n value: () => this.#destroy(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n return surface;\n }\n\n #destroy() {\n // Call onDestroy callback if defined\n if (this.destroyCallback && typeof this.destroyCallback === 'function') {\n try {\n this.destroyCallback(this.surface);\n } catch (error) {\n console.error('Error in onDestroy callback', error);\n }\n }\n \n const surfaceComputed = this.surfaceComputed;\n this.surfaceComputed = null;\n Surface.surfaces.delete(surfaceComputed);\n destroyComputed(surfaceComputed);\n }\n\n #get(path = []) {\n return traverse(this.surface, path);\n }\n\n #set(name, newValue) {\n const value = this.values?.get?.(name);\n value.value = newValue;\n return this.surface;\n }\n\n #dispatch(name, ...args) {\n const action = this.actions.has(name)\n ? this.actions.get(name)\n : this.surface[name];\n\n if (typeof action === 'function') {\n return action(...args);\n }\n return this.surfaceComputed();\n }\n\n #bindSurface(result = {}) {\n const oldKeys = Object.keys(this.surface);\n\n while (oldKeys.length > 0) {\n const key = oldKeys.shift();\n if (key in this.surface) {\n delete this.surface[key];\n }\n }\n\n for (const [key, plugin] of Surface.plugins) {\n Object.defineProperty(this.surface, key, {\n value: plugin\n });\n }\n\n for (const extension of this.extensions) {\n const descriptors = Object.getOwnPropertyDescriptors(extension);\n // Filter out the special $ methods if you don't want to inherit those\n const filteredDescriptors = Object.fromEntries(\n Object.entries(descriptors).filter(([key]) => !key.startsWith('$'))\n );\n Object.defineProperties(this.surface, filteredDescriptors);\n }\n\n const entries = Object.entries(result);\n \n for (const [key, value] of entries) {\n if (this.values.has(value)) {\n Object.defineProperty(this.surface, key, {\n get: () => value.value,\n set: (newValue) => value.value = newValue\n });\n\n continue;\n }\n\n if (this.computeds.has(value)) {\n Object.defineProperty(this.surface, key, {\n get: () => value.value\n });\n continue;\n }\n \n if (this.actions.has(value)) {\n Object.defineProperty(this.surface, key, { value });\n continue;\n }\n\n this.surface[key] = value;\n }\n\n return this.surface;\n }\n}\n\nexport const defineSurface = (...args) => Surface.create(...args);\nexport const refreshSurface = (surfaceComputed) => {\n if (isSurface(surfaceComputed)) {\n const surfaceInstance = Surface.surfaces.get(surfaceComputed);\n if (surfaceInstance) {\n surfaceInstance.setup();\n }\n }\n}\nexport const definePlugin = (...args) => Surface.createPlugin(...args);\nexport const isSurface = (surfaceComputed) => Surface.surfaces.has(surfaceComputed);\n\nexport const destroySurface = (surfaceComputed) => {\n if (isSurface(surfaceComputed)) {\n Surface.surfaces.delete(surfaceComputed);\n }\n}\n"],
5
- "mappings": "AAAO,SAASA,EAAaC,EAAU,CACrC,OAAI,OAAO,OAAW,KAAe,OAAO,oBACnC,OAAO,oBAAoBA,EAAU,CAAE,QAAS,GAAI,CAAC,EAI1D,OAAO,OAAW,IAEhB,OAAO,sBACF,OAAO,sBAAsB,IAAM,CACxC,WAAWA,EAAU,CAAC,CACxB,CAAC,EAGI,WAAWA,EAAU,CAAC,GAI3B,OAAOA,GAAa,YACtBA,EAAS,EAEJ,KACT,CCpBO,IAAMC,EAAN,KAAyB,CAC9B,aAAc,CACZ,KAAK,MAAQ,IAAI,IACjB,KAAK,QAAU,IAAI,IACnB,KAAK,oBAAsB,IAAI,IAC/B,KAAK,WAAa,IAAI,IACtB,KAAK,cAAgB,EACvB,CAEA,YAAYC,EAAU,CACpB,GAAI,CAACA,EAAS,UACZA,EAAS,QAAU,GAEfA,EAAS,SAAWA,EA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GuD,CAAI,EACnDO,EAAkBV,GAAoB,CACjD,GAAIvB,EAAUuB,CAAe,EAAG,CAC9B,IAAMW,EAAkB/D,EAAQ,SAAS,IAAIoD,CAAe,EACxDW,GACFA,EAAgB,MAAM,CAE1B,CACF,EACaC,EAAe,IAAIT,IAASvD,EAAQ,aAAa,GAAGuD,CAAI,EACxD1B,EAAauB,GAAoBpD,EAAQ,SAAS,IAAIoD,CAAe",
6
- "names": ["nextIdleTick", "callback", "ComputationManager", "reactive", "nextIdleTick", "deadRefs", "ids", "weakRef", "dependant", "ref", "now", "timeElapsed", "reactives", "sortedReactives", "callback", "error", "sorted", "visited", "visiting", "visit", "dependants", "REACTIVE_SYSTEM", "ComputationManager", "Reactive", "_Reactive", "getter", "reactive", "subscriber", "key", "value", "keys", "out", "i", "reactorIndex", "cycle", "error", "r", "dependant", "effect", "reactives", "deadRefs", "ids", "weakRef", "ref", "isReactive", "getter", "Reactive", "addEffect", "effect", "removeEffect", "addContext", "key", "value", "Reactive", "useContext", "keys", "hasContext", "createAdapter", "getter", "path", "isReactive", "snapshotCache", "unsubscribeAll", "subscribers", "getSnapshot", "clone", "listener", "addEffect", "subscriber", "Computed", "_Computed", "Reactive", "fn", "config", "computed", "#getter", "contextValue", "error", "createComputed", "destroyComputed", "target", "isComputed", "getter", "isDirtyComputed", "Signal", "_Signal", "Reactive", "initialValue", "config", "signal", "args", "#getter", "error", "createSignal", "destroySignal", "getter", "isSignal", "isDirtySignal", "Subscriber", "_Subscriber", "Reactive", "getter", "fn", "config", "subscriber", "error", "createSubscriber", "destroySubscriber", "isSubscriber", "traversalFunctions", "obj", "path", "createTraversalFunction", "length", "expr", "_", "i", "fn", "traverse", "state", "len", "EMPTY_CACHE", "Surface", "_Surface", "name", "plugin", "setupFn", "options", "instance", "useSurface", "fn", "#createSurface", "pendingReactives", "result", "#setupFromFunction", "#setupFromObject", "#bindSurface", "reactive", "addEffect", "#queueSubscribers", "error", "initial", "cb", "signal", "createSignal", "value", "newValue", "computed", "createComputed", "computedValue", "action", "isSurface", "surface", "reactor", "#destroy", "#processStateValue", "stateConfig", "isDev", "key", "config", "initialValue", "#createAdapter", "#getSnapshot", "subscriber", "#subscribe", "clone", "listener", "#callSubscribers", "snapshot", "path", "#get", "#set", "#dispatch", "overrides", "surfaceComputed", "destroyComputed", "traverse", "args", "oldKeys", "extension", "descriptors", "filteredDescriptors", "entries", "defineSurface", "refreshSurface", "surfaceInstance", "definePlugin"]
3
+ "sources": ["../src/utils/nextIdleTick.js", "../src/ComputationManager.js", "../src/Reactive.js", "../src/Computed.js", "../src/Signal.js", "../src/Subscriber.js", "../src/utils/isAsync.js", "../src/Binding.js", "../src/lib/traverse.js", "../src/Surface.js"],
4
+ "sourcesContent": ["export function nextIdleTick(callback) {\n if (typeof window !== 'undefined' && window.requestIdleCallback) {\n return window.requestIdleCallback(callback, { timeout: 100 });\n }\n\n // Fallback for browsers without requestIdleCallback (Safari/WebKit)\n if (typeof window !== 'undefined') {\n // Use requestAnimationFrame + setTimeout for better idle approximation\n if (window.requestAnimationFrame) {\n return window.requestAnimationFrame(() => {\n setTimeout(callback, 0);\n });\n }\n // Final fallback to setTimeout\n return setTimeout(callback, 0);\n }\n\n // Server-side or no window object - execute immediately\n if (typeof callback === 'function') {\n callback();\n }\n return null;\n}\n", "import { nextIdleTick } from './utils/nextIdleTick.js';\n\nexport class ComputationManager {\n constructor() {\n this.roots = new Map();\n this.pending = new Set();\n this.onCompleteCallbacks = new Set();\n this.onNextIdle = new Set();\n this.idleScheduled = false;\n }\n\n markAsDirty(reactive) {\n if (!reactive.isDirty) {\n reactive.isDirty = true;\n \n if (reactive.isAsync || reactive.immediate || (reactive.effects && reactive.effects.size > 0)) {\n this.scheduleRecomputation(reactive);\n } else {\n this.onNextIdle.add(reactive);\n\n if (!this.idleScheduled) {\n this.idleScheduled = true;\n nextIdleTick(() => {\n for (const reactive of this.onNextIdle) {\n this.pending.add(reactive);\n }\n this.flush(null);\n this.onNextIdle.clear();\n this.idleScheduled = false; // \u2190 Reset flag\n });\n }\n }\n\n if (reactive.dependants && reactive.dependants.size > 0) {\n // Process WeakRefs and rebuild ID set with only alive IDs\n const deadRefs = [];\n const ids = new Set();\n reactive.dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant) {\n this.markAsDirty(dependant);\n ids.add(dependant.id);\n } else {\n deadRefs.push(weakRef);\n }\n });\n // Clean up dead WeakRefs and sync IDs\n deadRefs.forEach(ref => reactive.dependants.delete(ref));\n reactive.dependantIds = ids;\n }\n }\n }\n\n scheduleRecomputation(reactive) {\n if (!reactive.debounce) {\n return this.recompute(reactive);\n }\n\n // Check if we can recompute (either first time or cooldown expired)\n const now = Date.now();\n const timeElapsed = reactive.lastComputeTime ? now - reactive.lastComputeTime : Infinity;\n const canRecompute = !reactive.hasPendingDebounce || timeElapsed >= reactive.debounce;\n\n if (canRecompute) {\n // Clear any existing timer and set up new cooldown period\n clearTimeout(reactive.debounceTimer);\n reactive.hasPendingDebounce = true;\n reactive.lastComputeTime = now;\n \n reactive.debounceTimer = setTimeout(() => {\n reactive.hasPendingDebounce = false;\n reactive.debounceTimer = null;\n }, reactive.debounce);\n \n return this.recompute(reactive);\n }\n\n // Still in cooldown period, return cached value\n return reactive.cachedValue;\n }\n\n removeReactive(reactive) {\n this.pending.delete(reactive);\n this.onNextIdle.delete(reactive);\n }\n\n recompute(reactive) {\n this.pending.add(reactive);\n return this.flush(reactive);\n }\n\n flush(reactive) {\n const reactives = Array.from(this.pending);\n this.pending.clear();\n\n // Sort by dependencies\n const sortedReactives = this.sortByDependencies(reactives);\n \n // Process in reverse order (dependencies first)\n for (const reactive of sortedReactives) {\n this.onNextIdle.delete(reactive);\n reactive.compute()\n }\n\n // Notify completion callbacks\n for (const callback of this.onCompleteCallbacks) {\n try {\n callback();\n } catch (error) {\n console.error('Error in batch completion callback:', error);\n }\n }\n\n // If we have a target ID, ensure it's computed and return its value\n if (reactive) {\n // Make sure the target computed is evaluated if it wasn't in the batch\n if (!sortedReactives.includes(reactive)) {\n reactive.compute();\n }\n return reactive.cachedValue;\n }\n \n return undefined;\n }\n\n sortByDependencies(reactives) {\n const sorted = [];\n const visited = new Set();\n const visiting = new Set();\n\n const visit = (reactive) => {\n if (visiting.has(reactive)) return;\n if (visited.has(reactive)) return;\n\n visiting.add(reactive);\n\n // Get dependant computed values (handle WeakRefs)\n const dependants = reactive.dependants;\n if (dependants && dependants.size > 0) {\n dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant && reactives.includes(dependant)) {\n visit(dependant); // Visit dependants first\n }\n });\n }\n\n visiting.delete(reactive);\n visited.add(reactive);\n sorted.unshift(reactive); // Add to start of array instead of end\n };\n\n // Process all nodes\n for (const reactive of reactives) {\n if (!visited.has(reactive)) {\n visit(reactive);\n }\n }\n\n return sorted;\n }\n}", "import { ComputationManager } from './ComputationManager.js';\n\nconst REACTIVE_SYSTEM = Symbol.for('@jucie.io/reactive/system');\n\nif (!globalThis[REACTIVE_SYSTEM]) {\n globalThis[REACTIVE_SYSTEM] = {\n computationManager: new ComputationManager(),\n awaitingRecomputation: new Set(),\n reactives: new WeakMap(),\n subscribers: new Set(),\n currentlyComputing: null,\n computationStack: [],\n currentDepth: 0,\n effectsCache: new Set(),\n processingEffects: false,\n _nextId: 1,\n config: {\n maxDepth: 2000,\n },\n ctx: {},\n };\n}\n\nexport class Reactive {\n static get system() {\n return globalThis[REACTIVE_SYSTEM];\n }\n\n static nextId() {\n return Reactive.system._nextId++;\n }\n\n static addReactive(getter, reactive) {\n Reactive.system.reactives.set(getter, reactive);\n Reactive.system.subscribers.add(getter);\n }\n\n static addSubscriber(getter, subscriber) {\n Reactive.system.reactives.set(getter, subscriber);\n Reactive.system.subscribers.add(getter);\n return () => Reactive.removeSubscriber(getter);\n }\n\n static removeSubscriber(getter) {\n Reactive.system.subscribers.delete(getter);\n Reactive.system.reactives.delete(getter);\n }\n\n static addContext(key, value) {\n if (!key || typeof key !== 'string') {\n throw new Error('Invalid context key');\n }\n \n if (typeof value === 'undefined') {\n throw new Error('Invalid context value');\n }\n \n if (key in Reactive.system.ctx) {\n throw new Error('Context key already exists');\n }\n \n Reactive.system.ctx[key] = value;\n }\n\n static useContext(keys) { \n if (!keys || keys.length === 0) return Reactive.system.ctx;\n if (keys.length === 1) return Reactive.system.ctx[keys[0]];\n\n const out = new Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n out[i] = Reactive.system.ctx[keys[i]];\n }\n return out;\n }\n\n static hasContext(keys) {\n if (!keys || keys.length === 0) return Object.keys(Reactive.system.ctx).length > 0;\n if (keys.length === 1) return keys[0] in Reactive.system.ctx;\n for (const key of keys) {\n if (!(key in Reactive.system.ctx)) return false;\n }\n return true;\n }\n\n static clearContext() {\n Reactive.system.ctx = {};\n }\n \n static resetSystem() {\n // Reset all system state (useful for testing)\n Reactive.system.awaitingRecomputation.clear();\n Reactive.system.currentlyComputing = null;\n Reactive.system.computationStack = [];\n Reactive.system.currentDepth = 0;\n Reactive.system.effectsCache.clear();\n Reactive.system.processingEffects = false;\n Reactive.system.ctx = {};\n // Note: We don't reset reactives WeakMap, subscribers Set, or _nextId as they may be in use\n }\n\n static addDependant(getter, dependant) {\n const reactive = Reactive.system.reactives.get(getter);\n if (reactive) {\n reactive.dependants.add(new WeakRef(dependant));\n reactive.dependantIds.add(dependant.id);\n }\n }\n\n static addEffect(getter, effect) {\n const reactive = Reactive.system.reactives.get(getter);\n \n // Compute if needed and notify with current value\n if (reactive.isDirty) {\n Reactive.system.computationManager.scheduleRecomputation(reactive);\n }\n \n if (!reactive.effects) {\n reactive.effects = new Set();\n }\n \n // Store the WeakRef instead of the raw effect\n reactive.effects.add(effect);\n Reactive.system.subscribers.add(getter);\n \n // Return unsubscribe function\n return () => Reactive.removeEffect(getter, effect);;\n }\n\n static removeEffect(getter, effect) {\n const reactive = Reactive.system.reactives.get(getter);\n Reactive.system.subscribers.delete(getter);\n if (reactive && reactive.effects) {\n reactive.effects.delete(effect);\n }\n }\n\n static processEffectsCache() {\n const reactives = new Set(Reactive.system.effectsCache);\n Reactive.system.effectsCache.clear();\n \n for (const reactive of reactives) {\n try {\n // Process effects using WeakRefs\n const effects = reactive.effects || new Set();\n effects.forEach(effect => {\n if (effect) {\n effect(reactive.cachedValue);\n }\n });\n } catch (error) {\n console.error(`Error in reactive ${reactive.id} effect:`, error);\n }\n }\n \n // If new effects were added during processing, schedule another batch\n if (Reactive.system.effectsCache.size > 0) {\n setTimeout(() => {\n Reactive.processEffectsCache();\n }, 0);\n }\n }\n\n static destroy(getter) {\n if (Reactive.system.subscribers.has(getter)) {\n Reactive.system.subscribers.delete(getter);\n }\n const reactive = Reactive.system.reactives.get(getter);\n if (reactive) {\n Reactive.system.computationManager.removeReactive(reactive);\n }\n Reactive.system.reactives.delete(getter);\n }\n \n constructor() {\n this.id = Reactive.nextId();\n this.isDirty = true;\n this.dependants = new Set();\n this.dependantIds = new Set();\n }\n \n begin() {\n if (Reactive.system.awaitingRecomputation.has(this)) {\n Reactive.system.awaitingRecomputation.delete(this);\n }\n\n const reactorIndex = Reactive.system.computationStack.indexOf(this);\n\n if (reactorIndex !== -1) {\n const cycle = Reactive.system.computationStack.slice(reactorIndex).concat(this);\n const error = new Error(`Circular dependency detected: ${cycle.map(r => r).join(' -> ')}`);\n error.name = 'CircularDependencyError';\n error.displayed = false;\n throw error;\n }\n \n if (Reactive.system.currentDepth >= Reactive.system.config.maxDepth) {\n throw new Error(`Maximum reactive depth of ${Reactive.system.config.maxDepth} exceeded`);\n }\n \n Reactive.system.computationStack.push(this);\n Reactive.system.currentlyComputing = this;\n Reactive.system.currentDepth++;\n }\n \n end() {\n Reactive.system.computationStack.pop();\n Reactive.system.currentlyComputing = Reactive.system.computationStack[Reactive.system.computationStack.length - 1] || null;\n Reactive.system.currentDepth--;\n }\n\n recompute() {\n if (!Reactive.system.awaitingRecomputation.has(this)) {\n Reactive.system.awaitingRecomputation.add(this);\n }\n\n \n return Reactive.system.computationManager.scheduleRecomputation(this);\n }\n\n callEffects() { \n Reactive.system.effectsCache.add(this);\n \n // Use a single setTimeout for batching\n if (!Reactive.system.processingEffects) {\n Reactive.system.processingEffects = true;\n setTimeout(() => {\n Reactive.processEffectsCache();\n Reactive.system.processingEffects = false;\n }, 0);\n }\n }\n\n markAsDirty() {\n if (!this.isDirty) {\n this.isDirty = true;\n \n if (this.immediate || (this.effects && this.effects.size > 0)) {\n Reactive.system.computationManager.scheduleRecomputation(this);\n }\n \n // Process WeakRefs and clean up dead ones\n const deadRefs = [];\n const ids = new Set();\n this.dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant) {\n dependant.markAsDirty();\n ids.add(dependant.id);\n } else {\n deadRefs.push(weakRef);\n }\n });\n // Clean up dead WeakRefs and sync IDs\n deadRefs.forEach(ref => this.dependants.delete(ref));\n this.dependantIds = ids;\n }\n }\n}\n\nexport const markAsDirty = (getter) => {\n if (isReactive(getter)) {\n const reactiveInstance = Reactive.system.reactives.get(getter);\n if (reactiveInstance) {\n return reactiveInstance.markAsDirty();\n }\n }\n}\n\nexport const isReactive = (getter) => {\n return Reactive.system.reactives.has(getter);\n}\n\nexport const isDirty = (getter) => {\n if (isReactive(getter)) {\n return Reactive.system.reactives.get(getter)?.isDirty || false;\n }\n return false;\n}\n\nexport const addEffect = (getter, effect) => {\n if (!isReactive(getter)) {\n throw new Error('Invalid effect getter');\n \n }\n\n if (!effect || typeof effect !== 'function') {\n throw new Error('Invalid effect function');\n }\n\n return Reactive.addEffect(getter, effect);\n}\n\nexport const removeEffect = (getter, effect) => {\n if (isReactive(getter)) {\n return Reactive.removeEffect(getter, effect);\n }\n}\n\nexport const destroyReactive = (getter) => {\n if (isReactive(getter)) {\n return Reactive.destroy(getter);\n }\n}\n\nexport const addContext = (key, value) => Reactive.addContext(key, value)\n\nexport const useContext = (...keys) => {\n if (keys.length === 0) return Reactive.system.ctx;\n if (keys.length === 1) return Reactive.system.ctx[keys[0]];\n return keys.map(key => Reactive.system.ctx[key]);\n}\n\nexport const hasContext = (...keys) => Reactive.hasContext(keys)\n\nexport const createAdapter = (getter, path = []) => {\n if (!isReactive(getter)) {\n throw new Error('Invalid adapter getter');\n }\n\n let snapshotCache = undefined;\n let unsubscribeAll = null;\n const subscribers = new Set();\n\n const getSnapshot = () => {\n if (snapshotCache !== undefined) {\n return snapshotCache;\n }\n\n const value = path && path.length > 0 ? traverse(getter(), path) : getter();\n\n if (Array.isArray(value)) {\n snapshotCache = value.slice();\n } else if (typeof value === 'object' && value !== null) {\n const clone = Object.create(Object.getPrototypeOf(value));\n Object.defineProperties(clone, Object.getOwnPropertyDescriptors(value));\n snapshotCache = Object.freeze(clone);\n } else {\n snapshotCache = value;\n }\n \n return snapshotCache;\n };\n\n const subscribe = (listener) => {\n if (!unsubscribeAll) {\n unsubscribeAll = addEffect(getter, () => {\n snapshotCache = undefined;\n for (const subscriber of subscribers) {\n subscriber(getSnapshot);\n }\n });\n }\n \n subscribers.add(listener);\n return () => {\n subscribers.delete(listener);\n if (subscribers.size === 0) {\n unsubscribeAll();\n unsubscribeAll = null;\n }\n };\n };\n\n return [getSnapshot, subscribe];\n}", "import { Reactive } from './Reactive.js';\n\nexport class Computed extends Reactive {\n static create(fn, config = {}) {\n const computed = new Computed(fn, config);\n Reactive.addReactive(computed.getter, computed);\n return computed.getter;\n }\n\n // Super\n // props: id, isDirty, dependants, dependantIds\n // methods: begin(), end(), recompute(), callEffects(), addDependant(), markAsDirty()\n\n constructor(fn, config = {}) {\n // Validate context must be a function if provided\n if (config.context && typeof config.context !== 'function') {\n throw new Error('Computed context must be a function');\n }\n super(); // Sets id, isDirty, dependants, dependantIds\n \n this.fn = fn;\n this.effects = new Set(Array.isArray(config.effects) ? config.effects : []);\n this.cachedValue = config.initialValue || undefined;\n this.isDirty = config.initialValue === undefined;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || undefined;\n this.detatched = config.detatched || false;\n this.immediate = config.immediate || false; \n this.useContext = config.context || (Reactive.hasContext() ? () => Reactive.useContext() : () => undefined);\n this.lastComputeTime = undefined;\n this.hasPendingDebounce = false;\n this.debounceTimer = undefined;\n this.computationId = 0; // Track computation version\n this.getter = this.#getter.bind(this);\n \n\n if (this.immediate) {\n this.compute();\n }\n }\n\n compute() {\n this.begin();\n try { \n const contextValue = this.useContext ? this.useContext() : undefined;\n this.cachedValue = this.fn(contextValue, this.cachedValue);\n this.isDirty = false;\n return this.cachedValue;\n } finally {\n this.end();\n this.callEffects();\n }\n }\n\n #getter() {\n try {\n if (!this.detatched && Reactive.system.currentlyComputing && Reactive.system.currentlyComputing !== this && !this.dependantIds.has(Reactive.system.currentlyComputing.id)) {\n this.dependantIds.add(Reactive.system.currentlyComputing.id);\n this.dependants.add(new WeakRef(Reactive.system.currentlyComputing));\n }\n\n return !this.isDirty ? this.cachedValue : this.recompute();\n } catch (error) {\n throw error;\n } finally {\n if (this.onAccess) {\n this.onAccess(this.cachedValue);\n }\n }\n }\n}\n\nexport const createComputed = (fn, config = {}) => Computed.create(fn, config);\n\nexport const destroyComputed = (target) => {\n if (isComputed(target)) {\n Reactive.destroy(target);\n }\n}\n\nexport const isComputed = (getter) => {\n const computed = Reactive.system.reactives.get(getter);\n if (!computed) {\n return false;\n }\n\n return computed instanceof Computed;\n}\n\nexport const isDirtyComputed = (getter) => {\n const computed = Reactive.system.reactives.get(getter);\n if (!computed) {\n return false;\n }\n\n return computed.isDirty;\n}\n", "import { Reactive } from './Reactive.js';\n\nexport class Signal extends Reactive {\n static create(initialValue, config = {}) {\n const signal = new Signal(initialValue, config);\n Reactive.addReactive(signal.getter, signal);\n return signal.getter;\n }\n\n constructor(initialValue, config = {}) {\n super(); // Sets id, isDirty, dependants, dependantIds\n this.cachedValue = undefined;\n // dependants and dependantIds set by super()\n this.roots = new Set();\n this.effects = new Set(Array.isArray(config.effects) ? config.effects : []);\n // isDirty set by super()\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || null;\n this.detatched = config.detatched || false;\n this.immediate = config.immediate || false;\n this.pendingChange = initialValue;\n this.lastComputeTime = null;\n this.hasPendingDebounce = false;\n this.debounceTimer = null;\n this.getter = (...args) => this.#getter(...args);\n }\n\n compute() {\n this.begin();\n try {\n this.cachedValue = this.pendingChange;\n this.pendingChange = undefined;\n this.isDirty = false;\n return this.cachedValue;\n } finally {\n this.end();\n this.callEffects();\n }\n }\n\n #getter(...args) {\n try {\n if (!this.detatched && Reactive.system.currentlyComputing && Reactive.system.currentlyComputing !== this && !this.dependantIds.has(Reactive.system.currentlyComputing.id)) {\n this.dependantIds.add(Reactive.system.currentlyComputing.id);\n this.dependants.add(new WeakRef(Reactive.system.currentlyComputing));\n }\n\n if (args.length > 0) {\n const signal = args[0];\n this.pendingChange = typeof signal === 'function' ? signal(this.cachedValue) : signal;\n this.markAsDirty();\n return;\n }\n\n if (this.isDirty) {\n return this.recompute();\n }\n\n return this.cachedValue;\n \n } catch (error) {\n throw error;\n } finally {\n if (this.onAccess) {\n this.onAccess(this.cachedValue);\n }\n }\n }\n}\n\nexport const createSignal = (initialValue, config = {}) => Signal.create(initialValue, config);\n\nexport const destroySignal = (getter) => {\n if (isSignal(getter)) {\n Reactive.destroy(getter);\n }\n}\n\nexport const isSignal = (getter) => {\n const signal = Reactive.system.reactives.get(getter);\n if (!signal) {\n return false;\n }\n\n return signal instanceof Signal;\n}\n\nexport const isDirtySignal = (getter) => {\n const signal = Reactive.system.reactives.get(getter);\n if (!signal) {\n return false;\n }\n\n return signal.isDirty;\n}", "import { Reactive } from './Reactive.js';\n\nexport class Subscriber extends Reactive {\n static create(getter, fn, config = {}) {\n const subscriber = new Subscriber(getter, fn, config);\n Reactive.system.reactives.set(subscriber.getter, subscriber);\n Reactive.system.subscribers.add(subscriber.getter);\n return () => Reactive.destroy(subscriber.getter);\n }\n\n constructor(getter, subscriber, config = {}) {\n super(); // Sets id, isDirty, dependants, dependantIds\n this.getter = getter;\n this.isDirty = false; // Override base class default\n this.subscriber = subscriber;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || null;\n this.immediate = true;\n this.hasPendingDebounce = false;\n this.lastComputeTime = null;\n this.debounceTimer = null;\n // dependants and dependantIds set by super()\n this.begin();\n this.cachedValue = this.getter();\n this.subscriber(this.cachedValue); // Call subscriber with initial value\n this.end();\n }\n\n compute() {\n try {\n this.cachedValue = this.getter();\n this.subscriber(this.cachedValue);\n this.isDirty = false;\n } catch (error) {\n throw error;\n }\n }\n}\n\nexport const createSubscriber = (getter, fn, config = {}) => Subscriber.create(getter, fn, config);\n\nexport const destroySubscriber = (getter) => {\n if (isSubscriber(getter)) {\n Reactive.destroy(getter);\n }\n}\n\nexport const isSubscriber = (getter) => {\n const subscriber = Reactive.system.reactives.get(getter);\n if (!subscriber) {\n return false;\n }\n\n return subscriber instanceof Subscriber;\n}", "export const isAsyncFunction = fn =>\n typeof fn === 'function' &&\n (fn.constructor.name === 'AsyncFunction' ||\n fn.constructor.name === 'AsyncGeneratorFunction');\n", "import { Reactive } from './Reactive.js';\nimport { isAsyncFunction } from './utils/isAsync.js';\n\nexport class Binding extends Reactive {\n static create(fn, dependencies = [], config = {}) {\n const binding = new Binding(fn, dependencies, config);\n Reactive.addReactive(binding.getter, binding);\n return binding.getter;\n }\n\n constructor(fn, dependencies = [], config = {}) {\n // Validate context must be a function if provided\n if (config.context && typeof config.context !== 'function') {\n throw new Error('Binding context must be a function');\n }\n super(); // Sets id, isDirty, dependants, dependantIds\n \n this.fn = fn;\n this.isAsync = isAsyncFunction(fn);\n this.pendingResolve = undefined;\n this.effects = new Set(Array.isArray(config.effects) ? config.effects : []);\n this.cachedValue = config.initialValue || undefined;\n this.isDirty = config.initialValue === undefined;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || undefined;\n this.detatched = config.detatched || false;\n this.immediate = config.immediate || false; \n this.useContext = config.context || (Reactive.hasContext() ? () => Reactive.useContext() : () => undefined);\n this.resolvers = [];\n this.rejectors = [];\n this.lastComputeTime = undefined;\n this.hasPendingDebounce = false;\n this.debounceTimer = undefined;\n this.computationId = 0; // Track computation version\n this.getter = this.#getter.bind(this);\n\n for (const dependency of dependencies) {\n Reactive.addDependant(dependency, this);\n }\n \n if (this.immediate) {\n this.compute();\n }\n }\n\n compute() {\n try { \n if (!this.isAsync) {\n // Call context function if provided, otherwise use useContext\n const contextValue = this.useContext ? this.useContext() : undefined;\n this.cachedValue = this.fn(contextValue, this.cachedValue);\n this.isDirty = false;\n return this.cachedValue;\n }\n\n // Track this specific computation\n this.computationId = (this.computationId || 0) + 1;\n const computationId = this.computationId;\n\n const contextValue = this.useContext ? this.useContext() : undefined;\n this.pendingResolve = this.fn(contextValue, this.cachedValue);\n this.pendingResolve.then(value => {\n // Only update if this is still the latest computation\n if (this.computationId === computationId) {\n this.resolvers.forEach(resolve => resolve(value));\n this.resolvers = [];\n this.cachedValue = value;\n this.isDirty = false;\n }\n return value;\n }).catch(error => {\n if (this.computationId === computationId) {\n this.rejectors.forEach(reject => reject(error));\n this.rejectors = [];\n }\n }).finally(() => {\n this.pendingResolve = null; // Always clear pending promise\n // Only call end/effects if this is still the latest computation\n if (this.computationId === computationId) {\n this.callEffects();\n }\n });\n\n this.cachedValue = new Promise((resolve, reject) => {\n this.resolvers.push(resolve);\n this.rejectors.push(reject);\n });\n \n return this.cachedValue;\n } finally {\n if (!this.isAsync) {\n this.callEffects();\n }\n }\n }\n\n #getter() {\n try {\n if (!this.detatched && Reactive.system.currentlyComputing && Reactive.system.currentlyComputing !== this && !this.dependantIds.has(Reactive.system.currentlyComputing.id)) {\n this.dependantIds.add(Reactive.system.currentlyComputing.id);\n this.dependants.add(new WeakRef(Reactive.system.currentlyComputing));\n }\n \n if (!this.isDirty) {\n if (this.isAsync) {\n return Promise.resolve(this.cachedValue);\n }\n\n return this.cachedValue;\n }\n\n // If dirty, always start new computation (even if previous pending)\n return this.recompute();\n } catch (error) {\n throw error;\n } finally {\n if (this.onAccess) {\n this.onAccess(this.cachedValue);\n }\n }\n }\n}\n\nexport const createBinding = (fn, dependencies = [], config = {}) => Binding.create(fn, dependencies, config);\n\nexport const destroyBinding = (target) => {\n if (isBinding(target)) {\n Reactive.destroy(target);\n }\n}\n\nexport const isBinding = (getter) => {\n const binding = Reactive.system.reactives.get(getter);\n if (!binding) {\n return false;\n }\n\n return binding instanceof Binding;\n}\n\nexport const isDirtyBinding = (getter) => {\n const binding = Reactive.system.reactives.get(getter);\n if (!binding) {\n return false;\n }\n return binding.isDirty;\n}", "const traversalFunctions = [\n null, // index 0 (unused)\n null, // index 1 (single property access doesn't need optimization)\n (obj, path) => obj?.[path[0]]?.[path[1]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]]?.[path[6]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]]?.[path[6]]?.[path[7]]\n]\n\nfunction createTraversalFunction(length) {\n const accessors = Array.from({ length }, (_, i) => `?.[path[${i}]]`);\n const expr = \"obj\" + accessors.join(\"\");\n const fn = new Function(\"obj\", \"path\", `return ${expr}`);\n traversalFunctions[length] = fn;\n return fn;\n}\n\nexport function traverse(state, path) {\n const len = path.length;\n if (len === 0) return state;\n if (len === 1) return state[path[0]];\n \n // Use existing function if available\n if (len < traversalFunctions.length && traversalFunctions[len]) {\n return traversalFunctions[len](state, path);\n }\n \n // Create and cache new function if needed\n if (!traversalFunctions[len]) {\n return createTraversalFunction(len)(state, path);\n }\n \n return traversalFunctions[len](state, path);\n}\n", "// Surface.js\nimport { createComputed, destroyComputed } from './Computed.js';\nimport { addEffect } from './Reactive.js';\nimport { createSignal } from './Signal.js';\nimport { createBinding } from './Binding.js';\nimport { traverse } from './lib/traverse.js';\n\nconst EMPTY_CACHE = Symbol();\n\nexport class Surface {\n static surfaces = new WeakMap();\n static plugins = new Map();\n\n static registerPlugin(name, plugin) {\n if (Surface.plugins.has(name)) {\n throw new Error(`Plugin \"${name}\" already registered`);\n }\n Surface.plugins.set(name, plugin());\n }\n\n static resetPlugins() {\n Surface.plugins.clear();\n }\n\n static create(setupFn, options = {}) {\n const instance = new Surface(options);\n const useSurface = instance.setup(setupFn);\n Surface.surfaces.set(useSurface, instance);\n return useSurface;\n }\n\n static createPlugin(name, fn, options = {}) {\n const plugin = Surface.create(fn, options);\n Surface.registerPlugin(name, plugin);\n return plugin;\n }\n\n constructor(options = {}) {\n this.options = options;\n this.setupFn = null;\n this.subscribers = new Set();\n this.subscribersQueued = false;\n this.destroyCallback = null;\n\n // Track signals, computeds, bindings, actions, and extensions\n this.signals = new Set();\n this.computeds = new Set();\n this.bindings = new Set();\n this.actions = new Set();\n this.extensions = new Set();\n\n this.snapshotCache = EMPTY_CACHE;\n this.surface = this.#createSurface();\n this.useSurface = () => this.surface;\n }\n\n setup(setupFn) {\n if (!setupFn) {\n return null;\n }\n\n this.setupFn = setupFn;\n this.reset();\n\n const pendingReactives = new Set();\n\n try {\n let result;\n \n if (typeof setupFn === 'function') {\n result = this.#setupFromFunction(setupFn, pendingReactives);\n } else if (typeof setupFn === 'object' && setupFn !== null) {\n result = this.#setupFromObject(setupFn, pendingReactives);\n } else {\n throw new Error('setupFn must be a function or object configuration');\n }\n \n this.#bindSurface(result);\n pendingReactives.forEach(reactive => addEffect(reactive, () => this.#queueSubscribers()));\n this.#queueSubscribers(); \n return this.useSurface;\n } catch (error) {\n console.error('Error in setup function', error);\n throw error;\n }\n }\n\n reset() {\n this.subscribers.clear();\n this.subscribersQueued = false;\n this.signals.clear();\n this.computeds.clear();\n this.actions.clear();\n this.bindings.clear();\n this.extensions.clear();\n this.snapshotCache = EMPTY_CACHE;\n this.surface = this.#createSurface();\n }\n\n createSignal(initial = undefined, cb) {\n const signal = createSignal(initial);\n this.signals.add(signal);\n cb?.(signal);\n return signal;\n }\n\n createComputed(fn, cb) {\n const computed = createComputed(fn, { context: () => this.surface });\n this.computeds.add(computed);\n cb?.(computed);\n return computed;\n }\n\n createBinding(fn, dependencies = [], cb) {\n // Dependencies should already be functions (signals, computeds, bindings)\n // No need to unwrap anything!\n const binding = createBinding(fn, dependencies, { context: () => this.surface });\n this.bindings.add(binding);\n cb?.(binding);\n return binding;\n }\n\n createAction(fn) {\n const action = fn.bind(this.surface, this.surface)\n this.actions.add(action);\n return action;\n }\n\n extend(useSurface) {\n \n if (!useSurface) throw new Error('No source surface provided');\n \n if (!isSurface(useSurface)) {\n throw new Error('Cannot extend non-surface');\n }\n const surface = useSurface();\n this.extensions.add(surface);\n return surface;\n }\n\n #setupFromFunction(setupFn, pendingReactives) {\n return setupFn({\n signal: (initial = undefined) => this.createSignal(initial, (signal) => pendingReactives.add(signal)),\n computed: (fn = () => {}) => this.createComputed(fn, (computed) => pendingReactives.add(computed)),\n binding: (fn = () => {}, dependencies = []) => this.createBinding(fn, dependencies, (binding) => pendingReactives.add(binding)),\n action: (fn = () => {}) => this.createAction(fn),\n extend: (useSurface) => this.extend(useSurface),\n destroy: () => this.#destroy(),\n ...Object.fromEntries(Surface.plugins.entries())\n }) || {};\n }\n\n #processStateValue(stateConfig, isDev, key) {\n // Support shorthand: state: { count: 0 } instead of { count: { default: 0 } }\n if (typeof stateConfig !== 'object' || stateConfig === null) {\n return typeof stateConfig === 'function' ? stateConfig() : stateConfig;\n }\n \n // If it's an object but doesn't have 'default', treat as shorthand\n if (!('default' in stateConfig)) {\n // Validate state config in dev mode\n if (isDev && 'dummy' in stateConfig) {\n console.warn(`State \"${key}\" has dummy value but no default value`);\n }\n return typeof stateConfig === 'function' ? stateConfig() : stateConfig;\n }\n \n // Full config with default/dummy\n let value = isDev && 'dummy' in stateConfig ? stateConfig.dummy : stateConfig.default;\n return typeof value === 'function' ? value() : value;\n }\n\n #setupFromObject(config, pendingReactives) {\n const result = {};\n const isDev = this.options.mode === 'development' || this.options.mode === 'dev';\n\n // 1. Process extend array first (so extended properties are available)\n if (config.extend && Array.isArray(config.extend)) {\n for (const useSurface of config.extend) {\n this.extend(useSurface);\n }\n }\n\n // 2. Process plugins (if specified) - handled in #bindSurface via Surface.plugins\n // Note: Plugins are automatically added to all surfaces, so we don't need to add them to result\n // If you want selective plugin inclusion, you'd need to modify #bindSurface\n\n // 3. Process state definitions\n if (config.state && typeof config.state === 'object') {\n for (const [key, stateConfig] of Object.entries(config.state)) {\n const initialValue = this.#processStateValue(stateConfig, isDev, key);\n result[key] = this.createSignal(initialValue, (signal) => pendingReactives.add(signal));\n }\n }\n\n // 4. Process computed properties\n if (config.computed && typeof config.computed === 'object') {\n for (const [key, fn] of Object.entries(config.computed)) {\n if (typeof fn === 'function') {\n result[key] = this.createComputed(fn, (reactor) => pendingReactives.add(reactor));\n }\n }\n }\n\n // 5. Process actions\n if (config.actions && typeof config.actions === 'object') {\n for (const [key, fn] of Object.entries(config.actions)) {\n if (typeof fn === 'function') {\n result[key] = this.createAction(fn);\n }\n }\n }\n\n // 6. Handle lifecycle hooks\n if (config.onInit && typeof config.onInit === 'function') {\n // Execute after setup is complete\n Promise.resolve().then(() => {\n try {\n config.onInit(this.surface);\n } catch (error) {\n console.error('Error in onInit callback', error);\n }\n });\n }\n\n if (config.onDestroy && typeof config.onDestroy === 'function') {\n // Store for later execution\n this.destroyCallback = config.onDestroy;\n }\n\n return result;\n }\n\n #createAdapter () { \n return [() => this.#getSnapshot(), (subscriber) => this.#subscribe(subscriber)];\n }\n\n #getSnapshot() {\n if (this.snapshotCache !== EMPTY_CACHE) {\n return this.snapshotCache;\n }\n\n const clone = Object.create(Object.getPrototypeOf(this.surface));\n Object.defineProperties(clone, Object.getOwnPropertyDescriptors(this.surface));\n this.snapshotCache = Object.freeze(clone);\n \n return this.snapshotCache;\n };\n\n #subscribe(listener) {\n this.subscribers.add(listener);\n return () => this.subscribers.delete(listener);\n }\n\n #callSubscribers(snapshot) {\n for (const subscriber of this.subscribers) {\n subscriber(snapshot);\n }\n }\n\n #queueSubscribers() {\n if (this.subscribers.size === 0 || this.subscribersQueued) return;\n this.subscribersQueued = true;\n Promise.resolve().then(() => {\n this.subscribersQueued = false;\n this.snapshotCache = EMPTY_CACHE;\n this.#callSubscribers(this.#getSnapshot());\n });\n }\n\n #createSurface(surface = Object.create(null)) {\n Object.defineProperty(surface, '$get', {\n value: (path) => this.#get(path),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$set', {\n value: (path, newValue) => this.#set(path, newValue),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$dispatch', {\n value: (name) => this.#dispatch(name),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$inject', {\n value: (overrides) => Object.assign({}, this.surface, overrides),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$snapshot', {\n value: () => this.#getSnapshot(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$subscribe', {\n value: (listener) => this.#subscribe(listener),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$adapter', {\n value: () => this.#createAdapter(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$destroy', {\n value: () => this.#destroy(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n return surface;\n }\n\n #destroy() {\n // Call onDestroy callback if defined\n if (this.destroyCallback && typeof this.destroyCallback === 'function') {\n try {\n this.destroyCallback(this.surface);\n } catch (error) {\n console.error('Error in onDestroy callback', error);\n }\n }\n \n const surfaceComputed = this.surfaceComputed;\n this.surfaceComputed = null;\n Surface.surfaces.delete(surfaceComputed);\n destroyComputed(surfaceComputed);\n }\n\n #get(path = []) {\n return traverse(this.surface, path);\n }\n\n #set(name, newValue) {\n const signal = this.signals?.get?.(name);\n if (signal) {\n signal(newValue);\n }\n return this.surface;\n }\n\n #dispatch(name, ...args) {\n const action = this.actions.has(name)\n ? this.actions.get(name)\n : this.surface[name];\n\n if (typeof action === 'function') {\n return action(...args);\n }\n return this.surfaceComputed();\n }\n\n #bindSurface(result = {}) {\n const oldKeys = Object.keys(this.surface);\n\n while (oldKeys.length > 0) {\n const key = oldKeys.shift();\n if (key in this.surface) {\n delete this.surface[key];\n }\n }\n\n for (const [key, plugin] of Surface.plugins) {\n Object.defineProperty(this.surface, key, {\n value: plugin\n });\n }\n\n for (const extension of this.extensions) {\n const descriptors = Object.getOwnPropertyDescriptors(extension);\n // Filter out the special $ methods if you don't want to inherit those\n const filteredDescriptors = Object.fromEntries(\n Object.entries(descriptors).filter(([key]) => !key.startsWith('$'))\n );\n Object.defineProperties(this.surface, filteredDescriptors);\n }\n\n const entries = Object.entries(result);\n \n for (const [key, value] of entries) {\n // Signals - add getter/setter\n if (this.signals.has(value)) {\n Object.defineProperty(this.surface, key, {\n get: () => value(),\n set: (newValue) => value(newValue)\n });\n continue;\n }\n\n // Computeds - add getter only\n if (this.computeds.has(value)) {\n Object.defineProperty(this.surface, key, {\n get: () => value()\n });\n continue;\n }\n \n // Bindings - add getter only (returns promise or value)\n if (this.bindings.has(value)) {\n Object.defineProperty(this.surface, key, {\n get: () => value()\n });\n continue;\n }\n \n // Actions - just assign\n if (this.actions.has(value)) {\n Object.defineProperty(this.surface, key, { value });\n continue;\n }\n\n // Everything else - assign as-is\n this.surface[key] = value;\n }\n\n return this.surface;\n }\n}\n\nexport const defineSurface = (...args) => Surface.create(...args);\nexport const refreshSurface = (surfaceComputed) => {\n if (isSurface(surfaceComputed)) {\n const surfaceInstance = Surface.surfaces.get(surfaceComputed);\n if (surfaceInstance) {\n surfaceInstance.setup();\n }\n }\n}\nexport const definePlugin = (...args) => Surface.createPlugin(...args);\nexport const isSurface = (surfaceComputed) => Surface.surfaces.has(surfaceComputed);\n\nexport const destroySurface = (surfaceComput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,CAAK,EAAG,CAC3B,OAAO,eAAe,KAAK,QAASD,EAAK,CAAE,MAAAC,CAAM,CAAC,EAClD,QACF,CAGA,KAAK,QAAQD,CAAG,EAAIC,CACtB,CAEA,OAAO,KAAK,OACd,CACF,EAEa2B,EAAgB,IAAIN,IAASzD,EAAQ,OAAO,GAAGyD,CAAI,EACnDO,EAAkBV,GAAoB,CACjD,GAAIzB,EAAUyB,CAAe,EAAG,CAC9B,IAAMW,EAAkBjE,EAAQ,SAAS,IAAIsD,CAAe,EACxDW,GACFA,EAAgB,MAAM,CAE1B,CACF,EACaC,EAAe,IAAIT,IAASzD,EAAQ,aAAa,GAAGyD,CAAI,EACxD5B,EAAayB,GAAoBtD,EAAQ,SAAS,IAAIsD,CAAe",
6
+ "names": ["nextIdleTick", "callback", "ComputationManager", "reactive", "nextIdleTick", "deadRefs", "ids", "weakRef", "dependant", "ref", "now", "timeElapsed", "reactives", "sortedReactives", "callback", "error", "sorted", "visited", "visiting", "visit", "dependants", "REACTIVE_SYSTEM", "ComputationManager", "Reactive", "_Reactive", "getter", "reactive", "subscriber", "key", "value", "keys", "out", "dependant", "effect", "reactives", "error", "reactorIndex", "cycle", "deadRefs", "ids", "weakRef", "ref", "isReactive", "getter", "Reactive", "isDirty", "addEffect", "effect", "removeEffect", "addContext", "key", "value", "Reactive", "useContext", "keys", "hasContext", "createAdapter", "getter", "path", "isReactive", "snapshotCache", "unsubscribeAll", "subscribers", "getSnapshot", "clone", "listener", "addEffect", "subscriber", "Computed", "_Computed", "Reactive", "fn", "config", "computed", "#getter", "contextValue", "error", "createComputed", "destroyComputed", "target", "isComputed", "getter", "isDirtyComputed", "Signal", "_Signal", "Reactive", "initialValue", "config", "signal", "args", "#getter", "error", "createSignal", "destroySignal", "getter", "isSignal", "isDirtySignal", "Subscriber", "_Subscriber", "Reactive", "getter", "fn", "config", "subscriber", "error", "createSubscriber", "destroySubscriber", "isSubscriber", "isAsyncFunction", "fn", "Binding", "_Binding", "Reactive", "fn", "dependencies", "config", "binding", "isAsyncFunction", "#getter", "dependency", "contextValue", "computationId", "value", "resolve", "error", "reject", "createBinding", "destroyBinding", "target", "isBinding", "getter", "isDirtyBinding", "traversalFunctions", "obj", "path", "createTraversalFunction", "length", "expr", "_", "i", "fn", "traverse", "state", "len", "EMPTY_CACHE", "Surface", "_Surface", "name", "plugin", "setupFn", "options", "instance", "useSurface", "fn", "#createSurface", "pendingReactives", "result", "#setupFromFunction", "#setupFromObject", "#bindSurface", "reactive", "addEffect", "#queueSubscribers", "error", "initial", "cb", "signal", "createSignal", "computed", "createComputed", "dependencies", "binding", "createBinding", "action", "isSurface", "surface", "#destroy", "#processStateValue", "stateConfig", "isDev", "key", "value", "config", "initialValue", "reactor", "#createAdapter", "#getSnapshot", "subscriber", "#subscribe", "clone", "listener", "#callSubscribers", "snapshot", "path", "#get", "newValue", "#set", "#dispatch", "overrides", "surfaceComputed", "destroyComputed", "traverse", "args", "oldKeys", "extension", "descriptors", "filteredDescriptors", "entries", "defineSurface", "refreshSurface", "surfaceInstance", "definePlugin"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jucie.io/reactive",
3
- "version": "1.0.21",
3
+ "version": "1.0.24",
4
4
  "description": "Fine-grained reactivity with signals, computed values, and effects (includes core + extensions)",
5
5
  "type": "module",
6
6
  "main": "./dist/main.js",