@estjs/signals 0.0.17-beta.1 → 0.0.17-beta.2

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/dist/signals.cjs CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';var shared=require('@estjs/shared');var Ze=Object.defineProperty;var Se=Object.getOwnPropertySymbols;var et=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable;var Ee=(e,t,n)=>t in e?Ze(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,ge=(e,t)=>{for(var n in t||(t={}))et.call(t,n)&&Ee(e,n,t[n]);if(Se)for(var n of Se(t))tt.call(t,n)&&Ee(e,n,t[n]);return e};var T={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var P=Symbol(""),g=Symbol(""),N=Symbol(""),ve=Symbol("");var L=Symbol("");var K=0,_,G=false,ie=class{constructor(t,n){this.map=t;this.key=n;this.isDep=true;this.flag=0;}get subLink(){return this._subLink}set subLink(t){this._subLink=t,t===void 0&&this.map.delete(this.key);}};function re(e){e.notify();}function D(e,t){if(G)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let i=n?n.nextDepLink:t.depLink;if(i&&i.depNode===e)return i.version=K,t.depLinkTail=i,i;let r=e.subLinkTail;if(r&&r.version===K&&r.subNode===t)return t.depLinkTail=r,r;let o={version:K,depNode:e,subNode:t,prevSubLink:r,nextSubLink:void 0,prevDepLink:n,nextDepLink:i};return i&&(i.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,r?r.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function R(e,t=e.subNode){let n=e.depNode,i=e.prevSubLink,r=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,r?r.prevSubLink=i:n.subLinkTail=i,i)i.nextSubLink=r;else if(n.subLink=r,r===void 0){let c=n.depLink;for(;c;)c=R(c,n);n.depLinkTail=void 0,n.isDep||(n.flag|=16);}return s}function U(e,t){let n,i=0,r=false;e:do{let o=false;if(t.flag&16)o=true;else {let s=e.depNode,c=s.flag;if((c&17)===17){let u=s.subLink;u&&u.nextSubLink&&O(u),o=true;}else if((c&33)===33)if(s.depLink){n={link:e,prev:n},e=s.depLink,t=s,++i;continue e}else s.flag&=-33;else c&32&&(s.flag&=-33);}if(!o&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}for(r=o;i--;){e=n.link,n=n.prev,t=e.subNode;let s=e.depNode;if(r?s.flag=s.flag&-33|16:s.flag&=-33,s.flag&16&&(r=true),!r&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}}return r?t.flag=t.flag&-33|16:t.flag&=-33,r}while(true)}function O(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16,(n&6)===2&&re(t)),e=e.nextSubLink;}}function j(e){let t=e.nextSubLink,n;e:do{let i=e.subNode,r=i.flag&2,o=i.flag;if(o&60?o&12?o&4?!(o&48)&&rt(e,i)?(i.flag=o|40,r&&re(i),o&=1):o=0:i.flag=o&-9|32:o=0:(i.flag=o|32,r&&re(i)),o&1){let s=i.subLink;if(s!==void 0){let c=s.nextSubLink;c!==void 0&&(n={value:t,prev:n},t=c),e=s;continue}}if((e=t)!==void 0){t=e.nextSubLink;continue}for(;n!==void 0;)if(e=n.value,n=n.prev,e!==void 0){t=e.nextSubLink;continue e}break}while(true)}function oe(e){let t=_;return _=e,t}function W(e){return K++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,oe(e)}function H(e,t){_=t;let n=e.depLinkTail,i=n?n.nextDepLink:e.depLink;for(;i;)i=R(i,e);e.flag&=-5;}function it(e){let t=oe(void 0),n=G;G=true;try{return e()}finally{G=n,oe(t);}}function rt(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var se=new WeakMap,ot=0;function ne(e,t,n){if(e)for(let i=e.subLink;i;i=i.nextSubLink){let r=i.subNode;r._triggerVersion!==n&&(r._triggerVersion=n,t.push(r));}}function l(e,t){if(!_||G)return;let n=se.get(e);n||(n=new Map,se.set(e,n));let i=n.get(t);i||(i=new ie(n,t),n.set(t,i)),D(i,_);}function S(e,t,n,i){var c;let r=se.get(e);if(!r)return;let o=[],s=++ot;if(n!==void 0)if(Array.isArray(n))for(let u of n)ne(r.get(u),o,s);else ne(r.get(n),o,s);if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let u=Array.isArray(e)?L:ve;ne(r.get(u),o,s);}for(let u of o)u.flag&2?(c=u.notify)==null||c.call(u):u.flag&1&&(u.flag|=16,u.subLink&&j(u.subLink));}var lt=new WeakMap,pt=new WeakMap;function a(e){if(!e||!shared.isObject(e))return e;let t=e._RAW;return t?a(t):h(e)?a(e.peek()):e}var be=dt();function dt(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let i=a(this);l(i,L);let r=i[t](...n);if((r===-1||r===false)&&n.length>0){let o=n.map(s=>a(s));r=i[t](...o);}return r};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let i=a(this),r=y(this);l(i,L);let o=i[t](...n);return (t==="find"||t==="findLast")&&shared.isObject(o)&&!r?d(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let i=a(this),r=Array.prototype[t].apply(i,n);return S(i,T.SET,[P,L]),r};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let i=a(this),r=y(this);if(l(i,L),t==="toSpliced")for(let s=0,c=i.length;s<c;s++)l(i,`${s}`);let o=Array.prototype[t].apply(i,n);return Array.isArray(o)?o.map(s=>shared.isObject(s)?d(s,r):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,L),Array.prototype[t].apply(this,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,L),Array.prototype[t].apply(i,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=a(this),i=y(this);l(n,P);let r=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=r.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(c=>shared.isObject(c)?d(c,i):c),done:s}:{value:shared.isObject(o)?d(o,i):o,done:s}},[Symbol.iterator](){return this}}};}),e}function Le(e,t){let n=h(t)?t:a(t);return shared.hasChanged(e,n)}var we=e=>({get:(t,n,i)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(shared.hasOwn(be,n))return be[n];let r=Reflect.get(t,n,i);return shared.isStringNumber(n)&&l(t,n),l(t,P),shared.isObject(r)&&!e?d(r):r},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return Le(s,o)&&(shared.isStringNumber(n)?S(t,T.SET,[n,L,P]):S(t,T.SET,n)),c}}),ht=we(true),Tt=we(false),Re=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(shared.hasOwn(me,n)?me:t,n,t)}}),xe=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(shared.hasOwn(ke,n)&&n in t?ke:t,n,t)}}),St=Re(true),Et=Re(false),gt=xe(true),vt=xe(false),me={get(e){let t=a(this);l(t,g);let n=t.get(e);return shared.isUndefined(n)&&!t.has(e)&&b(e)&&(n=t.get(a(e))),shared.isObject(n)&&!y(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||shared.hasChanged(o,s))&&S(n,T.SET,g),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,g),this},has(e){let t=a(this);l(t,g);let n=t.has(e);return !n&&shared.isObject(e)?t.has(a(e)):n},delete(e){let t=a(this),n=t.has(e),i=t.delete(e);return !i&&shared.isObject(e)&&(i=t.delete(a(e))),(n||i)&&S(t,T.DELETE,g),i},clear(){let e=a(this),t=e.size>0,n=e.clear();return t&&S(e,T.CLEAR,g),n},forEach(e,t){let n=a(this),i=y(this);l(n,g),n.forEach((r,o)=>{let s=i||!shared.isObject(r)?r:d(r),c=i||!shared.isObject(o)?o:d(o);e.call(t,s,c,this);});},[Symbol.iterator](){let e=a(this),t=y(this);l(e,g);let n=e[Symbol.iterator]();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:Array.isArray(i)?{value:i.map(o=>shared.isObject(o)?d(o):o),done:r}:{value:shared.isObject(i)?d(i):i,done:r}},[Symbol.iterator](){return this}}},get size(){let e=a(this);return l(e,g),e.size},keys(){let e=a(this),t=y(this);l(e,g);let n=e.keys();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!shared.isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},values(){let e=a(this),t=y(this);l(e,g);let n=e.values();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!shared.isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},entries(){let e=a(this),t=y(this);l(e,g);let n=e.entries();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:{value:i.map(o=>shared.isObject(o)?d(o):o),done:r}},[Symbol.iterator](){return this}}}},ke={get(e){let t=a(this);l(t,N);let n=t.get(e);return shared.isUndefined(n)&&!t.has(e)&&b(e)&&(n=t.get(a(e))),shared.isObject(n)&&!y(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||shared.hasChanged(o,s))&&S(n,T.SET,N),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,N),this},has(e){let t=a(this);l(t,N);let n=t.has(e);return !n&&b(e)&&(n=t.has(a(e))),n},delete(e){let t=a(this),n=a(e),i=t.has(n),r=t.delete(n);return (i||r)&&S(t,T.DELETE,N),r}},De=e=>({get(t,n,i){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let r=Reflect.get(t,n,i),o=h(r)?r.value:r;return l(t,n),shared.isObject(o)&&!e?d(o):o},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return Le(s,o)&&S(t,T.SET,n),c},deleteProperty:(t,n)=>{let i=shared.hasOwn(t,n),r=Reflect.deleteProperty(t,n);return i&&r&&S(t,T.DELETE,n),r}}),_t=De(true),bt=De(false);function d(e,t=false){if(!shared.isObject(e)||b(e))return e;let n=t?pt:lt,i=n.get(e);if(i)return i;let r;shared.isArray(e)?r=t?ht:Tt:shared.isSet(e)||shared.isMap(e)?r=t?St:Et:shared.isWeakMap(e)||shared.isWeakSet(e)?r=t?gt:vt:r=t?_t:bt;let o=new Proxy(e,r);return n.set(e,o),o}function b(e){return !!(e&&e._IS_REACTIVE)}function I(e){return b(e)||h(e)?e:d(e)}function q(e){return b(e)||h(e)?e:d(e,true)}function y(e){return !!(e&&e._IS_SHALLOW)}var mt=e=>shared.isObject(e)?I(e):e;var Ae;Ae="_IS_SIGNAL";var V=class{constructor(t,n=false){this.flag=1;this[Ae]=true;let i=a(t);this._rawValue=i,this._IS_SHALLOW=n,Ce(i)?b(t)?this._value=t:this._value=n?q(i):I(i):this._value=i;}get dep(){return this}get value(){let t=_;if(t&&D(this,t),this.flag&16&&this.shouldUpdate()){let i=this.subLink;i&&O(i);}return this._value}set value(t){h(t)&&(t=t.peek());let n=t,i=a(t);if(!shared.hasChanged(this._rawValue,i))return;if(this._oldValue=this._rawValue,this._rawValue=i,this.flag|=16,!Ce(i))this._value=i;else if(b(n))this._value=n;else {let o=this._IS_SHALLOW;this._value=o?q(i):I(i);}let r=this.subLink;r&&j(r);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=shared.hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());h(n)?this.value=n.peek():this.value=n;}};function Ce(e){return shared.isObject(e)?shared.isArray(e)||shared.isMap(e)||shared.isSet(e)||shared.isWeakMap(e)||shared.isWeakSet(e)||shared.isPlainObject(e):false}function It(e){return h(e)?e:new V(e)}function Ct(e){return h(e)&&(e=e.peek()),new V(e,true)}function h(e){return !!e&&!!e._IS_SIGNAL}var B=new Set,ce=new Set,Ne=Promise.resolve(),ue=false;function Ve(e){return e?Ne.then(e):Ne}function C(e){B.add(e),Pe();}function Pe(){ue||(ue=true,Ve(fe));}function Ge(e){ce.add(e),Pe();}function fe(){for(ue=false,At();B.size>0;){for(let e of B)try{e();}catch(t){}B.clear();}}function At(){let e=Array.from(ce);ce.clear();for(let t of e)try{t();}catch(n){}}function Oe(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>Ge(e);case "post":return ()=>C(e);default:return ()=>C(e)}}var Y=0;function $(e){je();try{return e()}finally{Ye();}}function je(){Y++;}function Ye(){Y--,Y===0&&fe();}function le(){return Y>0}function Nt(){return Y}var m,J=class{constructor(t=false,n=void 0){this.detached=t;this.parent=n;this._active=true;this.effects=[];this.scopes=[];this.cleanups=[];!t&&m&&(this.parent=m,m.scopes.push(this));}get active(){return this._active}pause(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].pause();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).pause)==null||n.call(t);}}resume(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].resume();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).resume)==null||n.call(t);}}run(t){if(!this._active)return;let n=m;m=this;try{return t()}finally{m=n;}}stop(t=false){if(!this._active)return;this._active=false;for(let i=0;i<this.scopes.length;i++)this.scopes[i].stop(true);this.scopes.length=0;let n=this.effects.slice();this.effects.length=0;for(let i of n)i.stop();for(let i=0;i<this.cleanups.length;i++)this.cleanups[i]();if(this.cleanups.length=0,!t&&this.parent){let i=this.parent.scopes.indexOf(this);i>=0&&this.parent.scopes.splice(i,1);}this.parent=void 0;}_record(t){this.effects.push(t),t.scope=this;}_remove(t){let n=this.effects.indexOf(t);n>=0&&this.effects.splice(n,1);}_pushCleanup(t){this.cleanups.push(t);}};function Vt(e=false){return new J(e)}function Pt(){return m}function Gt(e){let t=m;return m=e,t}function Ot(e,t=false){m&&m._pushCleanup(e);}function z(e,t=m){t&&t.active&&t._record(e);}function Q(e){let t=e.scope;t&&(e.scope=void 0,t._remove(e));}var Ke;Ke="_IS_EFFECT";var pe=class{constructor(t,n){this.flag=18;this[Ke]=true;this._active=true;if(this.fn=t,n){this.options=n;let i=n.flush||n.scheduler;i&&!shared.isFunction(i)&&(this._flushScheduler=Oe(()=>this.run(),i));}z(this);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&U(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let i=(n&16)!==0,r=(n&32)!==0;(i||r)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-49|512;let n=W(this);try{return this.fn()}catch(i){throw this.flag|=16,i}finally{this.flag&=-513,H(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){var r,o,s;let t=this.flag;if(!this._active||t&784)return;this.flag=t|16;let n=((r=this.options)==null?void 0:r.flush)||((o=this.options)==null?void 0:o.scheduler);n?shared.isFunction(n)?n(this):(s=this._flushScheduler)==null||s.call(this):le()?C(this.getJob()):this.run();}stop(){var i;if(!this._active)return;this._active=false,Q(this);let t=this.depLink;for(;t;)t=R(t,this);let n=this.subLink;for(;n;)n=R(n);this._job=void 0,this._flushScheduler=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,(i=this.options)!=null&&i.onStop&&this.options.onStop();}};function X(e,t){let n=new pe(e,t);try{n.run();}catch(r){throw n.stop(),r}let i=()=>n.run();return i.effect=n,i.stop=()=>n.stop(),i}function jt(e){e.effect.stop();}function Yt(e){return !!(e&&e._IS_EFFECT)}function Mt(e,t,n){let i=t;return X(()=>{i=e(i);},n)}var w=Symbol("computed-no-value"),He;He="_IS_COMPUTED";var Z=class{constructor(t,n,i,r){this.flag=17;this[He]=true;this._value=w;this._active=true;this.getter=t,this.setter=n,this.onTrack=i,this.onTrigger=r,this.flag|=16,z(this);}get value(){if(!this.active)return this._value===w?this.getter():this._value;_&&D(this,_);let t=this.flag,n=this._value!==w;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&U(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this.active?(this._value===w&&this.recompute(),this._value):this._value===w?this.getter():this._value}get active(){return this._active}recompute(){if(!this._active){this._value===w&&(this._value=this.getter());return}let t=this._value,n=t!==w,i=W(this);try{let r=this.getter(),o=this.flag,s=this.subLink,c=-49;!n||shared.hasChanged(t,r)?(this._value=r,this.flag=o&c,s&&O(s)):this.flag=o&c;}catch(r){let o=-49;throw this.flag&=o,this._value=w,r}finally{H(this,i);}}shouldUpdate(){let t=this._value!==w,n=this._value;return this.recompute(),t?shared.hasChanged(this._value,n):true}stop(){if(!this._active)return;this._active=false,Q(this);let t=this.depLink;for(;t;)t=R(t,this);let n=this.subLink;for(;n;)n=R(n);this.depLinkTail=void 0,this.subLinkTail=void 0,this.flag&=-49;}};function de(e){if(M(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(shared.isFunction(e))return new Z(e);if(shared.isPlainObject(e)){let{get:t,set:n,onTrack:i,onTrigger:r}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
1
+ 'use strict';var shared=require('@estjs/shared');var st=Object.defineProperty;var we=Object.getOwnPropertySymbols;var at=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable;var Le=(e,t,n)=>t in e?st(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,Re=(e,t)=>{for(var n in t||(t={}))at.call(t,n)&&Le(e,n,t[n]);if(we)for(var n of we(t))ct.call(t,n)&&Le(e,n,t[n]);return e};var T={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var G=Symbol(""),g=Symbol(""),N=Symbol(""),xe=Symbol("");var L=Symbol("");var q=0,b,O=false,ce=class{constructor(t,n){this.map=t;this.key=n;this.isDep=true;this.flag=0;}get subLink(){return this._subLink}set subLink(t){this._subLink=t,t===void 0&&this.map.delete(this.key);}};function ue(e){e.notify();}function C(e,t){if(O)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let i=n?n.nextDepLink:t.depLink;if(i&&i.depNode===e)return i.version=q,t.depLinkTail=i,i;let r=e.subLinkTail;if(r&&r.version===q&&r.subNode===t)return t.depLinkTail=r,r;let o={version:q,depNode:e,subNode:t,prevSubLink:r,nextSubLink:void 0,prevDepLink:n,nextDepLink:i};return i&&(i.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,r?r.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function D(e,t=e.subNode){let n=e.depNode,i=e.prevSubLink,r=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,r?r.prevSubLink=i:n.subLinkTail=i,i)i.nextSubLink=r;else if(n.subLink=r,r===void 0){let c=n.depLink;for(;c;)c=D(c,n);n.depLinkTail=void 0,n.isDep||(n.flag|=16);}return s}function B(e,t){let n,i=0,r=false;e:do{let o=false;if(t.flag&16)o=true;else {let s=e.depNode,c=s.flag;if((c&17)===17){let u=s.subLink;u&&u.nextSubLink&&j(u),o=true;}else if((c&33)===33)if(s.depLink){n={link:e,prev:n},e=s.depLink,t=s,++i;continue e}else s.flag&=-33;else c&32&&(s.flag&=-33);}if(!o&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}for(r=o;i--;){e=n.link,n=n.prev,t=e.subNode;let s=e.depNode;if(r?s.flag=s.flag&-33|16:s.flag&=-33,s.flag&16&&(r=true),!r&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}}return r?t.flag=t.flag&-33|16:t.flag&=-33,r}while(true)}function j(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16,(n&6)===2&&ue(t)),e=e.nextSubLink;}}function Y(e){let t=e.nextSubLink,n;e:do{let i=e.subNode,r=i.flag&2,o=i.flag;if(o&60?o&12?o&4?!(o&48)&&lt(e,i)?(i.flag=o|40,r&&ue(i),o&=1):o=0:i.flag=o&-9|32:o=0:(i.flag=o|32,r&&ue(i)),o&1){let s=i.subLink;if(s!==void 0){let c=s.nextSubLink;c!==void 0&&(n={value:t,prev:n},t=c),e=s;continue}}if((e=t)!==void 0){t=e.nextSubLink;continue}for(;n!==void 0;)if(e=n.value,n=n.prev,e!==void 0){t=e.nextSubLink;continue e}break}while(true)}function fe(e){let t=b;return b=e,t}function $(e){return q++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,fe(e)}function J(e,t){b=t;let n=e.depLinkTail,i=n?n.nextDepLink:e.depLink;for(;i;)i=D(i,e);e.flag&=-5;}function ft(e){let t=fe(void 0),n=O;O=true;try{return e()}finally{O=n,fe(t);}}function lt(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var le=new WeakMap,pt=0;function ae(e,t,n){if(e)for(let i=e.subLink;i;i=i.nextSubLink){let r=i.subNode;r._triggerVersion!==n&&(r._triggerVersion=n,t.push(r));}}function l(e,t){if(!b||O)return;let n=le.get(e);n||(n=new Map,le.set(e,n));let i=n.get(t);i||(i=new ce(n,t),n.set(t,i)),C(i,b);}function S(e,t,n,i){var c;let r=le.get(e);if(!r)return;let o=[],s=++pt;if(n!==void 0)if(Array.isArray(n))for(let u of n)ae(r.get(u),o,s);else ae(r.get(n),o,s);if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let u=Array.isArray(e)?L:xe;ae(r.get(u),o,s);}for(let u of o)u.flag&2?(c=u.notify)==null||c.call(u):u.flag&1&&(u.flag|=16,u.subLink&&Y(u.subLink));}var gt=new WeakMap,vt=new WeakMap;function a(e){if(!e||!shared.isObject(e))return e;let t=e._RAW;return t?a(t):h(e)?a(e.peek()):e}var Ce=_t();function _t(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let i=a(this);l(i,L);let r=i[t](...n);if((r===-1||r===false)&&n.length>0){let o=n.map(s=>a(s));r=i[t](...o);}return r};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let i=a(this),r=k(this);l(i,L);let o=i[t](...n);return (t==="find"||t==="findLast")&&shared.isObject(o)&&!r?d(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let i=a(this),r=Array.prototype[t].apply(i,n);return S(i,T.SET,[G,L]),r};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let i=a(this),r=k(this);if(l(i,L),t==="toSpliced")for(let s=0,c=i.length;s<c;s++)l(i,`${s}`);let o=Array.prototype[t].apply(i,n);return Array.isArray(o)?o.map(s=>shared.isObject(s)?d(s,r):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,L),Array.prototype[t].apply(this,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,L),Array.prototype[t].apply(i,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=a(this),i=k(this);l(n,G);let r=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=r.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(c=>shared.isObject(c)?d(c,i):c),done:s}:{value:shared.isObject(o)?d(o,i):o,done:s}},[Symbol.iterator](){return this}}};}),e}function Ve(e,t){let n=h(t)?t:a(t);return shared.hasChanged(e,n)}var Pe=e=>({get:(t,n,i)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(shared.hasOwn(Ce,n))return Ce[n];let r=Reflect.get(t,n,i);return shared.isStringNumber(n)&&l(t,n),l(t,G),shared.isObject(r)&&!e?d(r):r},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return Ve(s,o)&&(shared.isStringNumber(n)?S(t,T.SET,[n,L,G]):S(t,T.SET,n)),c}}),bt=Pe(true),mt=Pe(false),Ge=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(shared.hasOwn(Ie,n)?Ie:t,n,t)}}),Oe=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(shared.hasOwn(Ae,n)&&n in t?Ae:t,n,t)}}),yt=Ge(true),kt=Ge(false),wt=Oe(true),Lt=Oe(false),Ie={get(e){let t=a(this);l(t,g);let n=t.get(e);return shared.isUndefined(n)&&!t.has(e)&&v(e)&&(n=t.get(a(e))),shared.isObject(n)&&!k(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||shared.hasChanged(o,s))&&S(n,T.SET,g),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,g),this},has(e){let t=a(this);l(t,g);let n=t.has(e);return !n&&shared.isObject(e)?t.has(a(e)):n},delete(e){let t=a(this),n=t.has(e),i=t.delete(e);return !i&&shared.isObject(e)&&(i=t.delete(a(e))),(n||i)&&S(t,T.DELETE,g),i},clear(){let e=a(this),t=e.size>0,n=e.clear();return t&&S(e,T.CLEAR,g),n},forEach(e,t){let n=a(this),i=k(this);l(n,g),n.forEach((r,o)=>{let s=i||!shared.isObject(r)?r:d(r),c=i||!shared.isObject(o)?o:d(o);e.call(t,s,c,this);});},[Symbol.iterator](){let e=a(this),t=k(this);l(e,g);let n=e[Symbol.iterator]();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:Array.isArray(i)?{value:i.map(o=>shared.isObject(o)?d(o):o),done:r}:{value:shared.isObject(i)?d(i):i,done:r}},[Symbol.iterator](){return this}}},get size(){let e=a(this);return l(e,g),e.size},keys(){let e=a(this),t=k(this);l(e,g);let n=e.keys();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!shared.isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},values(){let e=a(this),t=k(this);l(e,g);let n=e.values();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!shared.isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},entries(){let e=a(this),t=k(this);l(e,g);let n=e.entries();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:{value:i.map(o=>shared.isObject(o)?d(o):o),done:r}},[Symbol.iterator](){return this}}}},Ae={get(e){let t=a(this);l(t,N);let n=t.get(e);return shared.isUndefined(n)&&!t.has(e)&&v(e)&&(n=t.get(a(e))),shared.isObject(n)&&!k(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||shared.hasChanged(o,s))&&S(n,T.SET,N),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,N),this},has(e){let t=a(this);l(t,N);let n=t.has(e);return !n&&v(e)&&(n=t.has(a(e))),n},delete(e){let t=a(this),n=a(e),i=t.has(n),r=t.delete(n);return (i||r)&&S(t,T.DELETE,N),r}},je=e=>({get(t,n,i){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let r=Reflect.get(t,n,i),o=h(r)?r.value:r;return l(t,n),shared.isObject(o)&&!e?d(o):o},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return Ve(s,o)&&S(t,T.SET,n),c},deleteProperty:(t,n)=>{let i=shared.hasOwn(t,n),r=Reflect.deleteProperty(t,n);return i&&r&&S(t,T.DELETE,n),r}}),Rt=je(true),xt=je(false);function d(e,t=false){if(!shared.isObject(e)||v(e))return e;let n=t?vt:gt,i=n.get(e);if(i)return i;let r;shared.isArray(e)?r=t?bt:mt:shared.isSet(e)||shared.isMap(e)?r=t?yt:kt:shared.isWeakMap(e)||shared.isWeakSet(e)?r=t?wt:Lt:r=t?Rt:xt;let o=new Proxy(e,r);return n.set(e,o),o}function v(e){return !!(e&&e._IS_REACTIVE)}function I(e){return v(e)||h(e)?e:d(e)}function Q(e){return v(e)||h(e)?e:d(e,true)}function k(e){return !!(e&&e._IS_SHALLOW)}var Dt=e=>shared.isObject(e)?I(e):e;var Ke;Ke="_IS_SIGNAL";var V=class{constructor(t,n=false){this.flag=1;this[Ke]=true;let i=a(t);this._rawValue=i,this._IS_SHALLOW=n,Me(i)?v(t)?this._value=t:this._value=n?Q(i):I(i):this._value=i;}get dep(){return this}get value(){let t=b;if(t&&C(this,t),this.flag&16&&this.shouldUpdate()){let i=this.subLink;i&&j(i);}return this._value}set value(t){h(t)&&(t=t.peek());let n=t,i=a(t);if(!shared.hasChanged(this._rawValue,i))return;if(this._oldValue=this._rawValue,this._rawValue=i,this.flag|=16,!Me(i))this._value=i;else if(v(n))this._value=n;else {let o=this._IS_SHALLOW;this._value=o?Q(i):I(i);}let r=this.subLink;r&&Y(r);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=shared.hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());h(n)?this.value=n.peek():this.value=n;}};function Me(e){return shared.isObject(e)?shared.isArray(e)||shared.isMap(e)||shared.isSet(e)||shared.isWeakMap(e)||shared.isWeakSet(e)||shared.isPlainObject(e):false}function Ot(e){return h(e)?e:new V(e)}function jt(e){return h(e)&&(e=e.peek()),new V(e,true)}function h(e){return !!e&&!!e._IS_SIGNAL}var M=new Set,de=new Set,Ue=Promise.resolve(),he=false,Yt=100;function We(e){return e?Ue.then(e):Ue}function K(e){M.add(e),He();}function He(){he||(he=true,We(Te));}function Fe(e){de.add(e),He();}function Te(){he=false,Mt();let e=0;for(;M.size>0;){if(++e>Yt){M.clear();return}let t=[...M];M.clear();for(let n of t)try{n();}catch(i){}}}function Mt(){let e=Array.from(de);de.clear();for(let t of e)try{t();}catch(n){}}function X(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>Fe(e);case "post":return ()=>K(e);default:return ()=>K(e)}}var U=0;function Z(e){qe();try{return e()}finally{Be();}}function qe(){U++;}function Be(){U--,U===0&&Te();}function Se(){return U>0}function Kt(){return U}var m,ee=class{constructor(t=false,n=void 0){this.detached=t;this.parent=n;this._active=true;this.effects=[];this.scopes=[];this.cleanups=[];!t&&m&&(this.parent=m,m.scopes.push(this));}get active(){return this._active}pause(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].pause();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).pause)==null||n.call(t);}}resume(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].resume();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).resume)==null||n.call(t);}}run(t){if(!this._active)return;let n=m;m=this;try{return t()}finally{m=n;}}stop(t=false){if(!this._active)return;this._active=false;for(let i=0;i<this.scopes.length;i++)this.scopes[i].stop(true);this.scopes.length=0;let n=this.effects.slice();this.effects.length=0;for(let i of n)i.stop();for(let i=0;i<this.cleanups.length;i++)this.cleanups[i]();if(this.cleanups.length=0,!t&&this.parent){let i=this.parent.scopes.indexOf(this);i>=0&&this.parent.scopes.splice(i,1);}this.parent=void 0;}_record(t){this.effects.push(t),t.scope=this;}_remove(t){let n=this.effects.indexOf(t);n>=0&&this.effects.splice(n,1);}_pushCleanup(t){this.cleanups.push(t);}};function Ut(e=false){return new ee(e)}function Wt(){return m}function Ht(e){let t=m;return m=e,t}function Ft(e,t=false){m&&m._pushCleanup(e);}function te(e,t=m){t&&t.active&&t._record(e);}function ne(e){let t=e.scope;t&&(e.scope=void 0,t._remove(e));}var Je;Je="_IS_EFFECT";var Ee=class{constructor(t,n){this.flag=18;this[Je]=true;this._active=true;if(this.fn=t,n){this.options=n;let i=n.flush||n.scheduler;i&&!shared.isFunction(i)&&(this._flushScheduler=X(()=>this.run(),i));}te(this);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&B(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let i=(n&16)!==0,r=(n&32)!==0;(i||r)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-49|512;let n=$(this);try{return this.fn()}catch(i){throw this.flag|=16,i}finally{this.flag&=-513,J(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){var r,o,s;let t=this.flag;if(!this._active||t&784)return;this.flag=t|16;let n=((r=this.options)==null?void 0:r.flush)||((o=this.options)==null?void 0:o.scheduler);n?shared.isFunction(n)?n(this):(s=this._flushScheduler)==null||s.call(this):Se()?K(this.getJob()):this.run();}stop(){var i;if(!this._active)return;this._active=false,ne(this);let t=this.depLink;for(;t;)t=D(t,this);let n=this.subLink;for(;n;)n=D(n);this._job=void 0,this._flushScheduler=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,(i=this.options)!=null&&i.onStop&&this.options.onStop();}};function ie(e,t){let n=new Ee(e,t);try{n.run();}catch(r){throw n.stop(),r}let i=()=>n.run();return i.effect=n,i.stop=()=>n.stop(),i}function qt(e){e.effect.stop();}function Bt(e){return !!(e&&e._IS_EFFECT)}function $t(e,t,n){let i=t;return ie(()=>{i=e(i);},n)}var R=Symbol("computed-no-value"),Xe;Xe="_IS_COMPUTED";var re=class{constructor(t,n,i,r){this.flag=17;this[Xe]=true;this._value=R;this._active=true;this.getter=t,this.setter=n,this.onTrack=i,this.onTrigger=r,this.flag|=16,te(this);}get value(){if(!this.active)return this._value===R?this.getter():this._value;b&&C(this,b);let t=this.flag,n=this._value!==R;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&B(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this.active?(this._value===R&&this.recompute(),this._value):this._value===R?this.getter():this._value}get active(){return this._active}recompute(){if(!this._active){this._value===R&&(this._value=this.getter());return}let t=this._value,n=t!==R,i=$(this);try{let r=this.getter(),o=this.flag,s=this.subLink,c=-49;!n||shared.hasChanged(t,r)?(this._value=r,this.flag=o&c,s&&j(s)):this.flag=o&c;}catch(r){let o=-49;throw this.flag&=o,this._value=R,r}finally{J(this,i);}}shouldUpdate(){let t=this._value!==R,n=this._value;return this.recompute(),t?shared.hasChanged(this._value,n):true}stop(){if(!this._active)return;this._active=false,ne(this);let t=this.depLink;for(;t;)t=D(t,this);let n=this.subLink;for(;n;)n=D(n);this.depLinkTail=void 0,this.subLinkTail=void 0,this.flag&=-49;}};function ge(e){if(W(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(shared.isFunction(e))return new re(e);if(shared.isPlainObject(e)){let{get:t,set:n,onTrack:i,onTrigger:r}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
2
2
  Usage: computed({ get: () => value, set: (v) => { ... } })`);if(!shared.isFunction(t))throw new TypeError(`[Computed] Invalid options: getter must be a function.
3
- Received: ${typeof t}`);return new Z(t,n,i,r)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
4
- Received: ${typeof e}`)}function M(e){return !!e&&!!e._IS_COMPUTED}function Ut(e){let{state:t,getters:n,actions:i}=e,r=ge({},t),o=I(t),s=new Set,c=new Set,u=f=>{s.forEach(k=>k(f)),c.forEach(k=>k(f));},x={patch$(f){$(()=>{Object.assign(o,f);}),u(o);},subscribe$(f){s.add(f);},unsubscribe$(f){s.delete(f);},onAction$(f){c.add(f);},offAction$(f){c.delete(f);},reset$(){$(()=>{Object.assign(o,r);}),u(o);}},E={};for(let f of Object.keys(r))Object.defineProperty(E,f,{get:()=>o[f],set:k=>{o[f]=k;},enumerable:true,configurable:true});if(Object.defineProperty(E,"state",{value:o,enumerable:true,configurable:true,writable:true}),Object.assign(E,x),n)for(let f in n){let k=n[f];if(!k)continue;let te=de(()=>k.call(E,o));Object.defineProperty(E,f,{get:()=>te.value,enumerable:true,configurable:true});}if(i)for(let f in i){let k=i[f];k&&(E[f]=(...te)=>{let Qe=k.apply(E,te);return c.forEach(Xe=>Xe(o)),Qe});}return E}function Wt(e){let t=new e,n=Object.create(null),i={},r={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let s=Object.getOwnPropertyDescriptor(e.prototype,o);s&&(shared.isFunction(s.get)?i[o]=function(){return s.get.call(this)}:shared.isFunction(s.value)&&o!=="constructor"&&(r[o]=function(...c){return s.value.apply(this,c)}));}),{state:n,getters:i,actions:r}}function Ht(e){return ()=>{let t;return shared.isFunction(e)?t=Wt(e):t=e,Ut(t)}}var Fe,qe,ee=class extends(qe=V,Fe="_IS_REF",qe){constructor(n){super(n,true);this[Fe]=true;}get value(){let n=_;return n&&D(this,n),this._value}set value(n){h(n)&&(n=n.peek()),Te(n)&&(n=n.value),shared.hasChanged(this._value,n)&&(this._rawValue=n,this._value=n,this.flag|=16,this.subLink&&j(this.subLink));}};function qt(e=void 0){return Te(e)?e:h(e)?new ee(e.peek()):new ee(e)}function Te(e){return !!e&&!!e._IS_REF}var Be={},$e=new Set;function A(e,t){if(t||($e.clear(),t=$e),!shared.isObject(e)||t.has(e))return e;if(t.add(e),h(e)||M(e))return A(e.value,t);if(Array.isArray(e))for(let n of e)A(n,t);else shared.isMap(e)?(e.forEach(n=>{A(n,t);}),e.keys(),e.values()):shared.isSet(e)?(e.forEach(n=>{A(n,t);}),e.values()):Object.keys(e).forEach(n=>{A(e[n],t);});return e}function Je(e){return shared.isFunction(e)?e:h(e)||M(e)?()=>e.value:b(e)?()=>A(e):()=>e}function Qt(e){if(Array.isArray(e)){let t=e.map(n=>Je(n));return ()=>t.map(n=>n())}return Je(e)}function Xt(e,t,n={}){let{immediate:i=false,deep:r=false}=n,o=Be,s=Qt(e),c=()=>{let x=u.effect;if(!x.run)return;let E=x.run();(r||shared.isObject(E)||shared.hasChanged(E,o))&&(t(E,o===Be?void 0:o),o=E);},u=X(()=>{let x=s();return r&&A(x),x},{scheduler:()=>C(c)});return i?c():o=u.effect.run(),()=>{u.stop();}}exports.EffectScope=J;exports.TriggerOpTypes=T;exports.batch=$;exports.computed=de;exports.createStore=Ht;exports.effect=X;exports.effectScope=Vt;exports.endBatch=Ye;exports.getBatchDepth=Nt;exports.getCurrentScope=Pt;exports.isBatching=le;exports.isComputed=M;exports.isEffect=Yt;exports.isReactive=b;exports.isRef=Te;exports.isShallow=y;exports.isSignal=h;exports.memoEffect=Mt;exports.nextTick=Ve;exports.onScopeDispose=Ot;exports.queueJob=C;exports.queuePreFlushCb=Ge;exports.reactive=I;exports.ref=qt;exports.setCurrentScope=Gt;exports.shallowReactive=q;exports.shallowSignal=Ct;exports.signal=It;exports.startBatch=je;exports.stop=jt;exports.toRaw=a;exports.toReactive=mt;exports.trigger=S;exports.untrack=it;exports.watch=Xt;
3
+ Received: ${typeof t}`);return new re(t,n,i,r)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
4
+ Received: ${typeof e}`)}function W(e){return !!e&&!!e._IS_COMPUTED}function zt(e){let{state:t,getters:n,actions:i}=e,r=Re({},t),o=I(t),s=new Set,c=new Set,u=f=>{s.forEach(E=>E(f)),c.forEach(E=>E(f));},P={patch$(f){Z(()=>{Object.assign(o,f);}),u(o);},subscribe$(f){s.add(f);},unsubscribe$(f){s.delete(f);},onAction$(f){c.add(f);},offAction$(f){c.delete(f);},reset$(){Z(()=>{Object.assign(o,r);}),u(o);}},w={};for(let f of Object.keys(r))Object.defineProperty(w,f,{get:()=>o[f],set:E=>{o[f]=E;},enumerable:true,configurable:true});if(Object.defineProperty(w,"state",{value:o,enumerable:true,configurable:true,writable:true}),Object.assign(w,P),n)for(let f in n){let E=n[f];if(!E)continue;let x=ge(()=>E.call(w,o));Object.defineProperty(w,f,{get:()=>x.value,enumerable:true,configurable:true});}if(i)for(let f in i){let E=i[f];E&&(w[f]=(...x)=>{let se=E.apply(w,x);return c.forEach(H=>H(o)),se});}return w}function Qt(e){let t=new e,n=Object.create(null),i={},r={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let s=Object.getOwnPropertyDescriptor(e.prototype,o);s&&(shared.isFunction(s.get)?i[o]=function(){return s.get.call(this)}:shared.isFunction(s.value)&&o!=="constructor"&&(r[o]=function(...c){return s.value.apply(this,c)}));}),{state:n,getters:i,actions:r}}function Xt(e){return ()=>{let t;return shared.isFunction(e)?t=Qt(e):t=e,zt(t)}}var Ze,et,oe=class extends(et=V,Ze="_IS_REF",et){constructor(n){super(n,true);this[Ze]=true;}get value(){let n=b;return n&&C(this,n),this._value}set value(n){h(n)&&(n=n.peek()),_e(n)&&(n=n.value),shared.hasChanged(this._value,n)&&(this._rawValue=n,this._value=n,this.flag|=16,this.subLink&&Y(this.subLink));}};function en(e=void 0){return _e(e)?e:h(e)?new oe(e.peek()):new oe(e)}function _e(e){return !!e&&!!e._IS_REF}var tt={},nt=new Set,be=false;function A(e,t){if(!shared.isObject(e)||t.has(e))return e;if(t.add(e),h(e)||W(e))A(e.value,t);else if(Array.isArray(e))for(let n of e)A(n,t);else if(shared.isMap(e))e.forEach(n=>{A(n,t);}),e.keys(),e.values();else if(shared.isSet(e))e.forEach(n=>{A(n,t);}),e.values();else for(let n of Object.keys(e))A(e[n],t);return e}function ot(e){if(be)return A(e,new Set);be=true,nt.clear();try{return A(e,nt)}finally{be=false;}}function it(e){return shared.isFunction(e)?e:h(e)||W(e)?()=>e.value:v(e)?()=>ot(e):()=>e}function sn(e){if(Array.isArray(e)){let t=e.map(n=>it(n));return ()=>t.map(n=>n())}return it(e)}function an(e,t,n={}){let{immediate:i=false,deep:r=false,flush:o="post",once:s=false}=n,c=tt,u,P=true,w=!Array.isArray(e)&&v(e),f=r&&!w,E=sn(e),x,se=y=>{x=()=>{x=void 0;try{y();}catch(F){}};},H=()=>{x&&x();},me=y=>{H(),t(y,c===tt?void 0:c,se),c=y,s&&ke();},ye=ie(()=>{let y=E();return f&&ot(y),u=y,y},{scheduler:X(()=>{if(!P)return;let y=ye.effect;if(!y.active)return;let F=y.run();(r||shared.isObject(F)||shared.hasChanged(F,c))&&me(F);},o)});function ke(){P&&(P=false,H(),ye.stop());}return i?me(u):c=u,ke}exports.EffectScope=ee;exports.TriggerOpTypes=T;exports.batch=Z;exports.computed=ge;exports.createStore=Xt;exports.effect=ie;exports.effectScope=Ut;exports.endBatch=Be;exports.getBatchDepth=Kt;exports.getCurrentScope=Wt;exports.isBatching=Se;exports.isComputed=W;exports.isEffect=Bt;exports.isReactive=v;exports.isRef=_e;exports.isShallow=k;exports.isSignal=h;exports.memoEffect=$t;exports.nextTick=We;exports.onScopeDispose=Ft;exports.queueJob=K;exports.queuePreFlushCb=Fe;exports.reactive=I;exports.ref=en;exports.setCurrentScope=Ht;exports.shallowReactive=Q;exports.shallowSignal=jt;exports.signal=Ot;exports.startBatch=qe;exports.stop=qt;exports.toRaw=a;exports.toReactive=Dt;exports.trigger=S;exports.untrack=ft;exports.watch=an;
@@ -1040,19 +1040,72 @@ declare function ref<T>(value?: T): Ref<T>;
1040
1040
  declare function isRef<T>(value: unknown): value is Ref<T>;
1041
1041
 
1042
1042
  interface WatchOptions {
1043
+ /** Whether to execute the callback immediately once on setup. */
1043
1044
  immediate?: boolean;
1045
+ /** Whether to deeply traverse the source to track nested changes. */
1044
1046
  deep?: boolean;
1047
+ /**
1048
+ * When the callback fires relative to the reactive flush cycle.
1049
+ * - `'post'` (default) — queued on the microtask job queue (essor's historical
1050
+ * behavior). NOTE: Vue defaults `watch` to `'pre'`; essor keeps `'post'`.
1051
+ * - `'pre'` — queued before the main job queue.
1052
+ * - `'sync'` — run synchronously the instant the source changes. Use sparingly:
1053
+ * a callback that mutates a tracked dependency can recurse.
1054
+ */
1055
+ flush?: FlushTiming;
1056
+ /** Stop the watcher automatically after the callback fires once. */
1057
+ once?: boolean;
1045
1058
  }
1046
1059
  type WatchSource<T = any> = T | {
1047
1060
  value: T;
1048
1061
  } | (() => T);
1049
- type WatchCallback<T = any> = (newValue: T, oldValue: T | undefined) => void;
1062
+ /**
1063
+ * Register a cleanup handler that runs right before the next callback invocation
1064
+ * and when the watcher stops. Mirrors Vue's `onCleanup`/`onInvalidate` — use it
1065
+ * to cancel stale async work (timers, fetches, subscriptions).
1066
+ */
1067
+ type OnCleanup = (cleanupFn: () => void) => void;
1068
+ type WatchCallback<T = any> = (newValue: T, oldValue: T | undefined, onCleanup: OnCleanup) => void;
1050
1069
  /**
1051
1070
  * Watch one or more reactive data sources and execute callback when sources change.
1052
1071
  *
1072
+ * ⚠️ **`oldValue` caveat for object / reactive sources.** For performance,
1073
+ * `watch` does NOT deep-clone the watched value between runs (deep cloning
1074
+ * every tick is prohibitively expensive). The `newValue` and `oldValue` passed
1075
+ * to your callback are therefore the *same reference* whenever the source is a
1076
+ * reactive object, array, Map/Set, or a getter that returns one — i.e.
1077
+ * `newValue === oldValue` and reading `oldValue.foo` yields the already-mutated
1078
+ * value. This differs from Vue, which snapshots primitives but likewise shares
1079
+ * the reference for deep/reactive sources.
1080
+ *
1081
+ * To capture a previous snapshot for object sources, derive the specific
1082
+ * primitive you care about in a getter:
1083
+ *
1084
+ * ```ts
1085
+ * // ❌ old === new — both point at the mutated object
1086
+ * watch(state, (n, o) => { ... });
1087
+ *
1088
+ * // ✅ watch a derived primitive; oldValue is a real previous value
1089
+ * watch(() => state.count, (n, o) => { ... }); // o is the prior count
1090
+ * ```
1091
+ *
1092
+ * For primitive sources (signals/computed/getters returning primitives),
1093
+ * `oldValue` behaves as expected.
1094
+ *
1095
+ * **Cleanup for async side effects.** The callback receives a third argument,
1096
+ * `onCleanup`, to cancel stale work before the next run (and on stop):
1097
+ *
1098
+ * ```ts
1099
+ * watch(id, async (id, _old, onCleanup) => {
1100
+ * const controller = new AbortController();
1101
+ * onCleanup(() => controller.abort());
1102
+ * const data = await fetch(`/api/${id}`, { signal: controller.signal });
1103
+ * });
1104
+ * ```
1105
+ *
1053
1106
  * @param source - The source(s) to watch.
1054
1107
  * @param callback - The callback function to execute when source changes.
1055
- * @param options - Configuration options like immediate and deep.
1108
+ * @param options - Configuration options (`immediate`, `deep`, `flush`, `once`).
1056
1109
  * @returns {Function} A function to stop watching.
1057
1110
  */
1058
1111
  declare function watch<T = any>(source: WatchSource<T>, callback: WatchCallback<T>, options?: WatchOptions): () => void;
package/dist/signals.d.ts CHANGED
@@ -1040,19 +1040,72 @@ declare function ref<T>(value?: T): Ref<T>;
1040
1040
  declare function isRef<T>(value: unknown): value is Ref<T>;
1041
1041
 
1042
1042
  interface WatchOptions {
1043
+ /** Whether to execute the callback immediately once on setup. */
1043
1044
  immediate?: boolean;
1045
+ /** Whether to deeply traverse the source to track nested changes. */
1044
1046
  deep?: boolean;
1047
+ /**
1048
+ * When the callback fires relative to the reactive flush cycle.
1049
+ * - `'post'` (default) — queued on the microtask job queue (essor's historical
1050
+ * behavior). NOTE: Vue defaults `watch` to `'pre'`; essor keeps `'post'`.
1051
+ * - `'pre'` — queued before the main job queue.
1052
+ * - `'sync'` — run synchronously the instant the source changes. Use sparingly:
1053
+ * a callback that mutates a tracked dependency can recurse.
1054
+ */
1055
+ flush?: FlushTiming;
1056
+ /** Stop the watcher automatically after the callback fires once. */
1057
+ once?: boolean;
1045
1058
  }
1046
1059
  type WatchSource<T = any> = T | {
1047
1060
  value: T;
1048
1061
  } | (() => T);
1049
- type WatchCallback<T = any> = (newValue: T, oldValue: T | undefined) => void;
1062
+ /**
1063
+ * Register a cleanup handler that runs right before the next callback invocation
1064
+ * and when the watcher stops. Mirrors Vue's `onCleanup`/`onInvalidate` — use it
1065
+ * to cancel stale async work (timers, fetches, subscriptions).
1066
+ */
1067
+ type OnCleanup = (cleanupFn: () => void) => void;
1068
+ type WatchCallback<T = any> = (newValue: T, oldValue: T | undefined, onCleanup: OnCleanup) => void;
1050
1069
  /**
1051
1070
  * Watch one or more reactive data sources and execute callback when sources change.
1052
1071
  *
1072
+ * ⚠️ **`oldValue` caveat for object / reactive sources.** For performance,
1073
+ * `watch` does NOT deep-clone the watched value between runs (deep cloning
1074
+ * every tick is prohibitively expensive). The `newValue` and `oldValue` passed
1075
+ * to your callback are therefore the *same reference* whenever the source is a
1076
+ * reactive object, array, Map/Set, or a getter that returns one — i.e.
1077
+ * `newValue === oldValue` and reading `oldValue.foo` yields the already-mutated
1078
+ * value. This differs from Vue, which snapshots primitives but likewise shares
1079
+ * the reference for deep/reactive sources.
1080
+ *
1081
+ * To capture a previous snapshot for object sources, derive the specific
1082
+ * primitive you care about in a getter:
1083
+ *
1084
+ * ```ts
1085
+ * // ❌ old === new — both point at the mutated object
1086
+ * watch(state, (n, o) => { ... });
1087
+ *
1088
+ * // ✅ watch a derived primitive; oldValue is a real previous value
1089
+ * watch(() => state.count, (n, o) => { ... }); // o is the prior count
1090
+ * ```
1091
+ *
1092
+ * For primitive sources (signals/computed/getters returning primitives),
1093
+ * `oldValue` behaves as expected.
1094
+ *
1095
+ * **Cleanup for async side effects.** The callback receives a third argument,
1096
+ * `onCleanup`, to cancel stale work before the next run (and on stop):
1097
+ *
1098
+ * ```ts
1099
+ * watch(id, async (id, _old, onCleanup) => {
1100
+ * const controller = new AbortController();
1101
+ * onCleanup(() => controller.abort());
1102
+ * const data = await fetch(`/api/${id}`, { signal: controller.signal });
1103
+ * });
1104
+ * ```
1105
+ *
1053
1106
  * @param source - The source(s) to watch.
1054
1107
  * @param callback - The callback function to execute when source changes.
1055
- * @param options - Configuration options like immediate and deep.
1108
+ * @param options - Configuration options (`immediate`, `deep`, `flush`, `once`).
1056
1109
  * @returns {Function} A function to stop watching.
1057
1110
  */
1058
1111
  declare function watch<T = any>(source: WatchSource<T>, callback: WatchCallback<T>, options?: WatchOptions): () => void;
@@ -1173,6 +1173,7 @@ var queue = /* @__PURE__ */ new Set();
1173
1173
  var activePreFlushCbs = /* @__PURE__ */ new Set();
1174
1174
  var p = Promise.resolve();
1175
1175
  var isFlushPending = false;
1176
+ var RECURSION_LIMIT = 100;
1176
1177
  function nextTick(fn) {
1177
1178
  return fn ? p.then(fn) : p;
1178
1179
  }
@@ -1193,8 +1194,20 @@ function queuePreFlushCb(cb) {
1193
1194
  function flushJobs() {
1194
1195
  isFlushPending = false;
1195
1196
  flushPreFlushCbs();
1197
+ let drainCount = 0;
1196
1198
  while (queue.size > 0) {
1197
- for (const job of queue) {
1199
+ if (++drainCount > RECURSION_LIMIT) {
1200
+ queue.clear();
1201
+ {
1202
+ shared.warn(
1203
+ `[Scheduler] Maximum recursive flush count (${RECURSION_LIMIT}) exceeded. This usually means an effect or watch callback is mutating a reactive dependency it also reads, causing an infinite update loop. The remaining queued jobs have been dropped to keep the app responsive.`
1204
+ );
1205
+ }
1206
+ return;
1207
+ }
1208
+ const jobs = [...queue];
1209
+ queue.clear();
1210
+ for (const job of jobs) {
1198
1211
  try {
1199
1212
  job();
1200
1213
  } catch (_error) {
@@ -1203,7 +1216,6 @@ function flushJobs() {
1203
1216
  }
1204
1217
  }
1205
1218
  }
1206
- queue.clear();
1207
1219
  }
1208
1220
  }
1209
1221
  function flushPreFlushCbs() {
@@ -2092,40 +2104,48 @@ function isRef(value) {
2092
2104
  }
2093
2105
  var INITIAL_WATCHER_VALUE = {};
2094
2106
  var _traverseSeen = /* @__PURE__ */ new Set();
2095
- function traverse(value, seen) {
2096
- if (!seen) {
2097
- _traverseSeen.clear();
2098
- seen = _traverseSeen;
2099
- }
2107
+ var _traverseBusy = false;
2108
+ function traverseValue(value, seen) {
2100
2109
  if (!shared.isObject(value) || seen.has(value)) {
2101
2110
  return value;
2102
2111
  }
2103
2112
  seen.add(value);
2104
2113
  if (isSignal(value) || isComputed(value)) {
2105
- return traverse(value.value, seen);
2106
- }
2107
- if (Array.isArray(value)) {
2114
+ traverseValue(value.value, seen);
2115
+ } else if (Array.isArray(value)) {
2108
2116
  for (const element of value) {
2109
- traverse(element, seen);
2117
+ traverseValue(element, seen);
2110
2118
  }
2111
2119
  } else if (shared.isMap(value)) {
2112
2120
  value.forEach((v) => {
2113
- traverse(v, seen);
2121
+ traverseValue(v, seen);
2114
2122
  });
2115
2123
  value.keys();
2116
2124
  value.values();
2117
2125
  } else if (shared.isSet(value)) {
2118
2126
  value.forEach((v) => {
2119
- traverse(v, seen);
2127
+ traverseValue(v, seen);
2120
2128
  });
2121
2129
  value.values();
2122
2130
  } else {
2123
- Object.keys(value).forEach((key) => {
2124
- traverse(value[key], seen);
2125
- });
2131
+ for (const key of Object.keys(value)) {
2132
+ traverseValue(value[key], seen);
2133
+ }
2126
2134
  }
2127
2135
  return value;
2128
2136
  }
2137
+ function traverse(value) {
2138
+ if (_traverseBusy) {
2139
+ return traverseValue(value, /* @__PURE__ */ new Set());
2140
+ }
2141
+ _traverseBusy = true;
2142
+ _traverseSeen.clear();
2143
+ try {
2144
+ return traverseValue(value, _traverseSeen);
2145
+ } finally {
2146
+ _traverseBusy = false;
2147
+ }
2148
+ }
2129
2149
  function cloneValue(value) {
2130
2150
  return value;
2131
2151
  }
@@ -2149,41 +2169,67 @@ function resolveSource(source) {
2149
2169
  return resolveSingleSource(source);
2150
2170
  }
2151
2171
  function watch(source, callback, options = {}) {
2152
- const { immediate = false, deep = false } = options;
2172
+ const { immediate = false, deep = false, flush = "post", once = false } = options;
2153
2173
  let oldValue = INITIAL_WATCHER_VALUE;
2174
+ let lastValue;
2175
+ let active = true;
2176
+ const isSingleReactive = !Array.isArray(source) && isReactive(source);
2177
+ const needTraverse = deep && !isSingleReactive;
2154
2178
  const getter = resolveSource(source);
2179
+ let cleanup;
2180
+ const onCleanup = (fn) => {
2181
+ cleanup = () => {
2182
+ cleanup = void 0;
2183
+ try {
2184
+ fn();
2185
+ } catch (error5) {
2186
+ shared.warn("[watch] cleanup handler threw:", error5);
2187
+ }
2188
+ };
2189
+ };
2190
+ const runCleanup = () => {
2191
+ if (cleanup) cleanup();
2192
+ };
2193
+ const invoke = (newValue) => {
2194
+ runCleanup();
2195
+ callback(newValue, oldValue === INITIAL_WATCHER_VALUE ? void 0 : oldValue, onCleanup);
2196
+ oldValue = cloneValue(newValue);
2197
+ if (once) stop2();
2198
+ };
2155
2199
  const job = () => {
2200
+ if (!active) return;
2156
2201
  const currentEffect = runner.effect;
2157
- if (!currentEffect.run) {
2158
- return;
2159
- }
2202
+ if (!currentEffect.active) return;
2160
2203
  const newValue = currentEffect.run();
2161
2204
  if (deep || shared.isObject(newValue) || shared.hasChanged(newValue, oldValue)) {
2162
- callback(newValue, oldValue === INITIAL_WATCHER_VALUE ? void 0 : oldValue);
2163
- oldValue = cloneValue(newValue);
2205
+ invoke(newValue);
2164
2206
  }
2165
2207
  };
2166
2208
  const runner = effect(
2167
2209
  () => {
2168
2210
  const value = getter();
2169
- if (deep) {
2211
+ if (needTraverse) {
2170
2212
  traverse(value);
2171
2213
  }
2214
+ lastValue = value;
2172
2215
  return value;
2173
2216
  },
2174
2217
  {
2175
- // Use scheduler to queue job, implementing async and debouncing.
2176
- scheduler: () => queueJob(job)
2218
+ scheduler: createScheduler(job, flush)
2177
2219
  }
2178
2220
  );
2221
+ function stop2() {
2222
+ if (!active) return;
2223
+ active = false;
2224
+ runCleanup();
2225
+ runner.stop();
2226
+ }
2179
2227
  if (immediate) {
2180
- job();
2228
+ invoke(lastValue);
2181
2229
  } else {
2182
- oldValue = cloneValue(runner.effect.run());
2230
+ oldValue = cloneValue(lastValue);
2183
2231
  }
2184
- return () => {
2185
- runner.stop();
2186
- };
2232
+ return stop2;
2187
2233
  }
2188
2234
 
2189
2235
  exports.EffectScope = EffectScope;
@@ -1,4 +1,4 @@
1
- import { isFunction, isObject, warn, error, isPlainObject, hasChanged, isArray, isSet, isMap, isWeakMap, isWeakSet, isStringNumber, hasOwn, isUndefined } from '@estjs/shared';
1
+ import { isFunction, isObject, warn, error, isPlainObject, isArray, isSet, isMap, isWeakMap, isWeakSet, hasChanged, isStringNumber, hasOwn, isUndefined } from '@estjs/shared';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -1171,6 +1171,7 @@ var queue = /* @__PURE__ */ new Set();
1171
1171
  var activePreFlushCbs = /* @__PURE__ */ new Set();
1172
1172
  var p = Promise.resolve();
1173
1173
  var isFlushPending = false;
1174
+ var RECURSION_LIMIT = 100;
1174
1175
  function nextTick(fn) {
1175
1176
  return fn ? p.then(fn) : p;
1176
1177
  }
@@ -1191,8 +1192,20 @@ function queuePreFlushCb(cb) {
1191
1192
  function flushJobs() {
1192
1193
  isFlushPending = false;
1193
1194
  flushPreFlushCbs();
1195
+ let drainCount = 0;
1194
1196
  while (queue.size > 0) {
1195
- for (const job of queue) {
1197
+ if (++drainCount > RECURSION_LIMIT) {
1198
+ queue.clear();
1199
+ {
1200
+ warn(
1201
+ `[Scheduler] Maximum recursive flush count (${RECURSION_LIMIT}) exceeded. This usually means an effect or watch callback is mutating a reactive dependency it also reads, causing an infinite update loop. The remaining queued jobs have been dropped to keep the app responsive.`
1202
+ );
1203
+ }
1204
+ return;
1205
+ }
1206
+ const jobs = [...queue];
1207
+ queue.clear();
1208
+ for (const job of jobs) {
1196
1209
  try {
1197
1210
  job();
1198
1211
  } catch (_error) {
@@ -1201,7 +1214,6 @@ function flushJobs() {
1201
1214
  }
1202
1215
  }
1203
1216
  }
1204
- queue.clear();
1205
1217
  }
1206
1218
  }
1207
1219
  function flushPreFlushCbs() {
@@ -2090,40 +2102,48 @@ function isRef(value) {
2090
2102
  }
2091
2103
  var INITIAL_WATCHER_VALUE = {};
2092
2104
  var _traverseSeen = /* @__PURE__ */ new Set();
2093
- function traverse(value, seen) {
2094
- if (!seen) {
2095
- _traverseSeen.clear();
2096
- seen = _traverseSeen;
2097
- }
2105
+ var _traverseBusy = false;
2106
+ function traverseValue(value, seen) {
2098
2107
  if (!isObject(value) || seen.has(value)) {
2099
2108
  return value;
2100
2109
  }
2101
2110
  seen.add(value);
2102
2111
  if (isSignal(value) || isComputed(value)) {
2103
- return traverse(value.value, seen);
2104
- }
2105
- if (Array.isArray(value)) {
2112
+ traverseValue(value.value, seen);
2113
+ } else if (Array.isArray(value)) {
2106
2114
  for (const element of value) {
2107
- traverse(element, seen);
2115
+ traverseValue(element, seen);
2108
2116
  }
2109
2117
  } else if (isMap(value)) {
2110
2118
  value.forEach((v) => {
2111
- traverse(v, seen);
2119
+ traverseValue(v, seen);
2112
2120
  });
2113
2121
  value.keys();
2114
2122
  value.values();
2115
2123
  } else if (isSet(value)) {
2116
2124
  value.forEach((v) => {
2117
- traverse(v, seen);
2125
+ traverseValue(v, seen);
2118
2126
  });
2119
2127
  value.values();
2120
2128
  } else {
2121
- Object.keys(value).forEach((key) => {
2122
- traverse(value[key], seen);
2123
- });
2129
+ for (const key of Object.keys(value)) {
2130
+ traverseValue(value[key], seen);
2131
+ }
2124
2132
  }
2125
2133
  return value;
2126
2134
  }
2135
+ function traverse(value) {
2136
+ if (_traverseBusy) {
2137
+ return traverseValue(value, /* @__PURE__ */ new Set());
2138
+ }
2139
+ _traverseBusy = true;
2140
+ _traverseSeen.clear();
2141
+ try {
2142
+ return traverseValue(value, _traverseSeen);
2143
+ } finally {
2144
+ _traverseBusy = false;
2145
+ }
2146
+ }
2127
2147
  function cloneValue(value) {
2128
2148
  return value;
2129
2149
  }
@@ -2147,41 +2167,67 @@ function resolveSource(source) {
2147
2167
  return resolveSingleSource(source);
2148
2168
  }
2149
2169
  function watch(source, callback, options = {}) {
2150
- const { immediate = false, deep = false } = options;
2170
+ const { immediate = false, deep = false, flush = "post", once = false } = options;
2151
2171
  let oldValue = INITIAL_WATCHER_VALUE;
2172
+ let lastValue;
2173
+ let active = true;
2174
+ const isSingleReactive = !Array.isArray(source) && isReactive(source);
2175
+ const needTraverse = deep && !isSingleReactive;
2152
2176
  const getter = resolveSource(source);
2177
+ let cleanup;
2178
+ const onCleanup = (fn) => {
2179
+ cleanup = () => {
2180
+ cleanup = void 0;
2181
+ try {
2182
+ fn();
2183
+ } catch (error5) {
2184
+ warn("[watch] cleanup handler threw:", error5);
2185
+ }
2186
+ };
2187
+ };
2188
+ const runCleanup = () => {
2189
+ if (cleanup) cleanup();
2190
+ };
2191
+ const invoke = (newValue) => {
2192
+ runCleanup();
2193
+ callback(newValue, oldValue === INITIAL_WATCHER_VALUE ? void 0 : oldValue, onCleanup);
2194
+ oldValue = cloneValue(newValue);
2195
+ if (once) stop2();
2196
+ };
2153
2197
  const job = () => {
2198
+ if (!active) return;
2154
2199
  const currentEffect = runner.effect;
2155
- if (!currentEffect.run) {
2156
- return;
2157
- }
2200
+ if (!currentEffect.active) return;
2158
2201
  const newValue = currentEffect.run();
2159
2202
  if (deep || isObject(newValue) || hasChanged(newValue, oldValue)) {
2160
- callback(newValue, oldValue === INITIAL_WATCHER_VALUE ? void 0 : oldValue);
2161
- oldValue = cloneValue(newValue);
2203
+ invoke(newValue);
2162
2204
  }
2163
2205
  };
2164
2206
  const runner = effect(
2165
2207
  () => {
2166
2208
  const value = getter();
2167
- if (deep) {
2209
+ if (needTraverse) {
2168
2210
  traverse(value);
2169
2211
  }
2212
+ lastValue = value;
2170
2213
  return value;
2171
2214
  },
2172
2215
  {
2173
- // Use scheduler to queue job, implementing async and debouncing.
2174
- scheduler: () => queueJob(job)
2216
+ scheduler: createScheduler(job, flush)
2175
2217
  }
2176
2218
  );
2219
+ function stop2() {
2220
+ if (!active) return;
2221
+ active = false;
2222
+ runCleanup();
2223
+ runner.stop();
2224
+ }
2177
2225
  if (immediate) {
2178
- job();
2226
+ invoke(lastValue);
2179
2227
  } else {
2180
- oldValue = cloneValue(runner.effect.run());
2228
+ oldValue = cloneValue(lastValue);
2181
2229
  }
2182
- return () => {
2183
- runner.stop();
2184
- };
2230
+ return stop2;
2185
2231
  }
2186
2232
 
2187
2233
  export { EffectScope, TriggerOpTypes, batch, computed, createStore, effect, effectScope, endBatch, getBatchDepth, getCurrentScope, isBatching, isComputed, isEffect, isReactive, isRef, isShallow, isSignal, memoEffect, nextTick, onScopeDispose, queueJob, queuePreFlushCb, reactive, ref, setCurrentScope, shallowReactive, shallowSignal, signal, startBatch, stop, toRaw, toReactive, trigger, untrack, watch };
package/dist/signals.js CHANGED
@@ -1,4 +1,4 @@
1
- import {isObject,isFunction,isPlainObject,hasChanged,isArray,isSet,isMap,isWeakMap,isWeakSet,isStringNumber,hasOwn,isUndefined}from'@estjs/shared';var et=Object.defineProperty;var Ee=Object.getOwnPropertySymbols;var tt=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable;var ge=(e,t,n)=>t in e?et(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,ve=(e,t)=>{for(var n in t||(t={}))tt.call(t,n)&&ge(e,n,t[n]);if(Ee)for(var n of Ee(t))nt.call(t,n)&&ge(e,n,t[n]);return e};var T={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var G=Symbol(""),g=Symbol(""),V=Symbol(""),_e=Symbol("");var w=Symbol("");var U=0,b,O=false,re=class{constructor(t,n){this.map=t;this.key=n;this.isDep=true;this.flag=0;}get subLink(){return this._subLink}set subLink(t){this._subLink=t,t===void 0&&this.map.delete(this.key);}};function oe(e){e.notify();}function I(e,t){if(O)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let i=n?n.nextDepLink:t.depLink;if(i&&i.depNode===e)return i.version=U,t.depLinkTail=i,i;let r=e.subLinkTail;if(r&&r.version===U&&r.subNode===t)return t.depLinkTail=r,r;let o={version:U,depNode:e,subNode:t,prevSubLink:r,nextSubLink:void 0,prevDepLink:n,nextDepLink:i};return i&&(i.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,r?r.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function x(e,t=e.subNode){let n=e.depNode,i=e.prevSubLink,r=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,r?r.prevSubLink=i:n.subLinkTail=i,i)i.nextSubLink=r;else if(n.subLink=r,r===void 0){let c=n.depLink;for(;c;)c=x(c,n);n.depLinkTail=void 0,n.isDep||(n.flag|=16);}return s}function W(e,t){let n,i=0,r=false;e:do{let o=false;if(t.flag&16)o=true;else {let s=e.depNode,c=s.flag;if((c&17)===17){let u=s.subLink;u&&u.nextSubLink&&j(u),o=true;}else if((c&33)===33)if(s.depLink){n={link:e,prev:n},e=s.depLink,t=s,++i;continue e}else s.flag&=-33;else c&32&&(s.flag&=-33);}if(!o&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}for(r=o;i--;){e=n.link,n=n.prev,t=e.subNode;let s=e.depNode;if(r?s.flag=s.flag&-33|16:s.flag&=-33,s.flag&16&&(r=true),!r&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}}return r?t.flag=t.flag&-33|16:t.flag&=-33,r}while(true)}function j(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16,(n&6)===2&&oe(t)),e=e.nextSubLink;}}function Y(e){let t=e.nextSubLink,n;e:do{let i=e.subNode,r=i.flag&2,o=i.flag;if(o&60?o&12?o&4?!(o&48)&&ot(e,i)?(i.flag=o|40,r&&oe(i),o&=1):o=0:i.flag=o&-9|32:o=0:(i.flag=o|32,r&&oe(i)),o&1){let s=i.subLink;if(s!==void 0){let c=s.nextSubLink;c!==void 0&&(n={value:t,prev:n},t=c),e=s;continue}}if((e=t)!==void 0){t=e.nextSubLink;continue}for(;n!==void 0;)if(e=n.value,n=n.prev,e!==void 0){t=e.nextSubLink;continue e}break}while(true)}function se(e){let t=b;return b=e,t}function H(e){return U++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,se(e)}function F(e,t){b=t;let n=e.depLinkTail,i=n?n.nextDepLink:e.depLink;for(;i;)i=x(i,e);e.flag&=-5;}function rt(e){let t=se(void 0),n=O;O=true;try{return e()}finally{O=n,se(t);}}function ot(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var ae=new WeakMap,st=0;function ie(e,t,n){if(e)for(let i=e.subLink;i;i=i.nextSubLink){let r=i.subNode;r._triggerVersion!==n&&(r._triggerVersion=n,t.push(r));}}function l(e,t){if(!b||O)return;let n=ae.get(e);n||(n=new Map,ae.set(e,n));let i=n.get(t);i||(i=new re(n,t),n.set(t,i)),I(i,b);}function S(e,t,n,i){var c;let r=ae.get(e);if(!r)return;let o=[],s=++st;if(n!==void 0)if(Array.isArray(n))for(let u of n)ie(r.get(u),o,s);else ie(r.get(n),o,s);if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let u=Array.isArray(e)?w:_e;ie(r.get(u),o,s);}for(let u of o)u.flag&2?(c=u.notify)==null||c.call(u):u.flag&1&&(u.flag|=16,u.subLink&&Y(u.subLink));}var pt=new WeakMap,dt=new WeakMap;function a(e){if(!e||!isObject(e))return e;let t=e._RAW;return t?a(t):h(e)?a(e.peek()):e}var me=ht();function ht(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let i=a(this);l(i,w);let r=i[t](...n);if((r===-1||r===false)&&n.length>0){let o=n.map(s=>a(s));r=i[t](...o);}return r};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let i=a(this),r=L(this);l(i,w);let o=i[t](...n);return (t==="find"||t==="findLast")&&isObject(o)&&!r?d(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let i=a(this),r=Array.prototype[t].apply(i,n);return S(i,T.SET,[G,w]),r};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let i=a(this),r=L(this);if(l(i,w),t==="toSpliced")for(let s=0,c=i.length;s<c;s++)l(i,`${s}`);let o=Array.prototype[t].apply(i,n);return Array.isArray(o)?o.map(s=>isObject(s)?d(s,r):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,w),Array.prototype[t].apply(this,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,w),Array.prototype[t].apply(i,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=a(this),i=L(this);l(n,G);let r=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=r.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(c=>isObject(c)?d(c,i):c),done:s}:{value:isObject(o)?d(o,i):o,done:s}},[Symbol.iterator](){return this}}};}),e}function we(e,t){let n=h(t)?t:a(t);return hasChanged(e,n)}var Re=e=>({get:(t,n,i)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(hasOwn(me,n))return me[n];let r=Reflect.get(t,n,i);return isStringNumber(n)&&l(t,n),l(t,G),isObject(r)&&!e?d(r):r},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return we(s,o)&&(isStringNumber(n)?S(t,T.SET,[n,w,G]):S(t,T.SET,n)),c}}),Tt=Re(true),St=Re(false),xe=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(hasOwn(ke,n)?ke:t,n,t)}}),De=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(hasOwn(ye,n)&&n in t?ye:t,n,t)}}),Et=xe(true),gt=xe(false),vt=De(true),_t=De(false),ke={get(e){let t=a(this);l(t,g);let n=t.get(e);return isUndefined(n)&&!t.has(e)&&m(e)&&(n=t.get(a(e))),isObject(n)&&!L(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||hasChanged(o,s))&&S(n,T.SET,g),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,g),this},has(e){let t=a(this);l(t,g);let n=t.has(e);return !n&&isObject(e)?t.has(a(e)):n},delete(e){let t=a(this),n=t.has(e),i=t.delete(e);return !i&&isObject(e)&&(i=t.delete(a(e))),(n||i)&&S(t,T.DELETE,g),i},clear(){let e=a(this),t=e.size>0,n=e.clear();return t&&S(e,T.CLEAR,g),n},forEach(e,t){let n=a(this),i=L(this);l(n,g),n.forEach((r,o)=>{let s=i||!isObject(r)?r:d(r),c=i||!isObject(o)?o:d(o);e.call(t,s,c,this);});},[Symbol.iterator](){let e=a(this),t=L(this);l(e,g);let n=e[Symbol.iterator]();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:Array.isArray(i)?{value:i.map(o=>isObject(o)?d(o):o),done:r}:{value:isObject(i)?d(i):i,done:r}},[Symbol.iterator](){return this}}},get size(){let e=a(this);return l(e,g),e.size},keys(){let e=a(this),t=L(this);l(e,g);let n=e.keys();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},values(){let e=a(this),t=L(this);l(e,g);let n=e.values();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},entries(){let e=a(this),t=L(this);l(e,g);let n=e.entries();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:{value:i.map(o=>isObject(o)?d(o):o),done:r}},[Symbol.iterator](){return this}}}},ye={get(e){let t=a(this);l(t,V);let n=t.get(e);return isUndefined(n)&&!t.has(e)&&m(e)&&(n=t.get(a(e))),isObject(n)&&!L(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||hasChanged(o,s))&&S(n,T.SET,V),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,V),this},has(e){let t=a(this);l(t,V);let n=t.has(e);return !n&&m(e)&&(n=t.has(a(e))),n},delete(e){let t=a(this),n=a(e),i=t.has(n),r=t.delete(n);return (i||r)&&S(t,T.DELETE,V),r}},Ie=e=>({get(t,n,i){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let r=Reflect.get(t,n,i),o=h(r)?r.value:r;return l(t,n),isObject(o)&&!e?d(o):o},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return we(s,o)&&S(t,T.SET,n),c},deleteProperty:(t,n)=>{let i=hasOwn(t,n),r=Reflect.deleteProperty(t,n);return i&&r&&S(t,T.DELETE,n),r}}),bt=Ie(true),mt=Ie(false);function d(e,t=false){if(!isObject(e)||m(e))return e;let n=t?dt:pt,i=n.get(e);if(i)return i;let r;isArray(e)?r=t?Tt:St:isSet(e)||isMap(e)?r=t?Et:gt:isWeakMap(e)||isWeakSet(e)?r=t?vt:_t:r=t?bt:mt;let o=new Proxy(e,r);return n.set(e,o),o}function m(e){return !!(e&&e._IS_REACTIVE)}function C(e){return m(e)||h(e)?e:d(e)}function B(e){return m(e)||h(e)?e:d(e,true)}function L(e){return !!(e&&e._IS_SHALLOW)}var kt=e=>isObject(e)?C(e):e;var Ne;Ne="_IS_SIGNAL";var P=class{constructor(t,n=false){this.flag=1;this[Ne]=true;let i=a(t);this._rawValue=i,this._IS_SHALLOW=n,Ae(i)?m(t)?this._value=t:this._value=n?B(i):C(i):this._value=i;}get dep(){return this}get value(){let t=b;if(t&&I(this,t),this.flag&16&&this.shouldUpdate()){let i=this.subLink;i&&j(i);}return this._value}set value(t){h(t)&&(t=t.peek());let n=t,i=a(t);if(!hasChanged(this._rawValue,i))return;if(this._oldValue=this._rawValue,this._rawValue=i,this.flag|=16,!Ae(i))this._value=i;else if(m(n))this._value=n;else {let o=this._IS_SHALLOW;this._value=o?B(i):C(i);}let r=this.subLink;r&&Y(r);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());h(n)?this.value=n.peek():this.value=n;}};function Ae(e){return isObject(e)?isArray(e)||isMap(e)||isSet(e)||isWeakMap(e)||isWeakSet(e)||isPlainObject(e):false}function Ct(e){return h(e)?e:new P(e)}function At(e){return h(e)&&(e=e.peek()),new P(e,true)}function h(e){return !!e&&!!e._IS_SIGNAL}var $=new Set,ue=new Set,Ve=Promise.resolve(),fe=false;function Pe(e){return e?Ve.then(e):Ve}function A(e){$.add(e),Ge();}function Ge(){fe||(fe=true,Pe(le));}function Oe(e){ue.add(e),Ge();}function le(){for(fe=false,Nt();$.size>0;){for(let e of $)try{e();}catch(t){}$.clear();}}function Nt(){let e=Array.from(ue);ue.clear();for(let t of e)try{t();}catch(n){}}function je(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>Oe(e);case "post":return ()=>A(e);default:return ()=>A(e)}}var M=0;function J(e){Ye();try{return e()}finally{Me();}}function Ye(){M++;}function Me(){M--,M===0&&le();}function pe(){return M>0}function Vt(){return M}var k,z=class{constructor(t=false,n=void 0){this.detached=t;this.parent=n;this._active=true;this.effects=[];this.scopes=[];this.cleanups=[];!t&&k&&(this.parent=k,k.scopes.push(this));}get active(){return this._active}pause(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].pause();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).pause)==null||n.call(t);}}resume(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].resume();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).resume)==null||n.call(t);}}run(t){if(!this._active)return;let n=k;k=this;try{return t()}finally{k=n;}}stop(t=false){if(!this._active)return;this._active=false;for(let i=0;i<this.scopes.length;i++)this.scopes[i].stop(true);this.scopes.length=0;let n=this.effects.slice();this.effects.length=0;for(let i of n)i.stop();for(let i=0;i<this.cleanups.length;i++)this.cleanups[i]();if(this.cleanups.length=0,!t&&this.parent){let i=this.parent.scopes.indexOf(this);i>=0&&this.parent.scopes.splice(i,1);}this.parent=void 0;}_record(t){this.effects.push(t),t.scope=this;}_remove(t){let n=this.effects.indexOf(t);n>=0&&this.effects.splice(n,1);}_pushCleanup(t){this.cleanups.push(t);}};function Pt(e=false){return new z(e)}function Gt(){return k}function Ot(e){let t=k;return k=e,t}function jt(e,t=false){k&&k._pushCleanup(e);}function Q(e,t=k){t&&t.active&&t._record(e);}function X(e){let t=e.scope;t&&(e.scope=void 0,t._remove(e));}var Ue;Ue="_IS_EFFECT";var de=class{constructor(t,n){this.flag=18;this[Ue]=true;this._active=true;if(this.fn=t,n){this.options=n;let i=n.flush||n.scheduler;i&&!isFunction(i)&&(this._flushScheduler=je(()=>this.run(),i));}Q(this);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&W(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let i=(n&16)!==0,r=(n&32)!==0;(i||r)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-49|512;let n=H(this);try{return this.fn()}catch(i){throw this.flag|=16,i}finally{this.flag&=-513,F(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){var r,o,s;let t=this.flag;if(!this._active||t&784)return;this.flag=t|16;let n=((r=this.options)==null?void 0:r.flush)||((o=this.options)==null?void 0:o.scheduler);n?isFunction(n)?n(this):(s=this._flushScheduler)==null||s.call(this):pe()?A(this.getJob()):this.run();}stop(){var i;if(!this._active)return;this._active=false,X(this);let t=this.depLink;for(;t;)t=x(t,this);let n=this.subLink;for(;n;)n=x(n);this._job=void 0,this._flushScheduler=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,(i=this.options)!=null&&i.onStop&&this.options.onStop();}};function Z(e,t){let n=new de(e,t);try{n.run();}catch(r){throw n.stop(),r}let i=()=>n.run();return i.effect=n,i.stop=()=>n.stop(),i}function Yt(e){e.effect.stop();}function Mt(e){return !!(e&&e._IS_EFFECT)}function Kt(e,t,n){let i=t;return Z(()=>{i=e(i);},n)}var R=Symbol("computed-no-value"),Fe;Fe="_IS_COMPUTED";var ee=class{constructor(t,n,i,r){this.flag=17;this[Fe]=true;this._value=R;this._active=true;this.getter=t,this.setter=n,this.onTrack=i,this.onTrigger=r,this.flag|=16,Q(this);}get value(){if(!this.active)return this._value===R?this.getter():this._value;b&&I(this,b);let t=this.flag,n=this._value!==R;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&W(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this.active?(this._value===R&&this.recompute(),this._value):this._value===R?this.getter():this._value}get active(){return this._active}recompute(){if(!this._active){this._value===R&&(this._value=this.getter());return}let t=this._value,n=t!==R,i=H(this);try{let r=this.getter(),o=this.flag,s=this.subLink,c=-49;!n||hasChanged(t,r)?(this._value=r,this.flag=o&c,s&&j(s)):this.flag=o&c;}catch(r){let o=-49;throw this.flag&=o,this._value=R,r}finally{F(this,i);}}shouldUpdate(){let t=this._value!==R,n=this._value;return this.recompute(),t?hasChanged(this._value,n):true}stop(){if(!this._active)return;this._active=false,X(this);let t=this.depLink;for(;t;)t=x(t,this);let n=this.subLink;for(;n;)n=x(n);this.depLinkTail=void 0,this.subLinkTail=void 0,this.flag&=-49;}};function he(e){if(K(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(isFunction(e))return new ee(e);if(isPlainObject(e)){let{get:t,set:n,onTrack:i,onTrigger:r}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
1
+ import {isObject,isFunction,isPlainObject,isArray,isSet,isMap,isWeakMap,isWeakSet,hasChanged,isStringNumber,hasOwn,isUndefined}from'@estjs/shared';var at=Object.defineProperty;var Le=Object.getOwnPropertySymbols;var ct=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable;var Re=(e,t,n)=>t in e?at(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,xe=(e,t)=>{for(var n in t||(t={}))ct.call(t,n)&&Re(e,n,t[n]);if(Le)for(var n of Le(t))ut.call(t,n)&&Re(e,n,t[n]);return e};var T={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var O=Symbol(""),g=Symbol(""),V=Symbol(""),De=Symbol("");var R=Symbol("");var B=0,m,j=false,ue=class{constructor(t,n){this.map=t;this.key=n;this.isDep=true;this.flag=0;}get subLink(){return this._subLink}set subLink(t){this._subLink=t,t===void 0&&this.map.delete(this.key);}};function fe(e){e.notify();}function I(e,t){if(j)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let i=n?n.nextDepLink:t.depLink;if(i&&i.depNode===e)return i.version=B,t.depLinkTail=i,i;let r=e.subLinkTail;if(r&&r.version===B&&r.subNode===t)return t.depLinkTail=r,r;let o={version:B,depNode:e,subNode:t,prevSubLink:r,nextSubLink:void 0,prevDepLink:n,nextDepLink:i};return i&&(i.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,r?r.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function C(e,t=e.subNode){let n=e.depNode,i=e.prevSubLink,r=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,r?r.prevSubLink=i:n.subLinkTail=i,i)i.nextSubLink=r;else if(n.subLink=r,r===void 0){let c=n.depLink;for(;c;)c=C(c,n);n.depLinkTail=void 0,n.isDep||(n.flag|=16);}return s}function $(e,t){let n,i=0,r=false;e:do{let o=false;if(t.flag&16)o=true;else {let s=e.depNode,c=s.flag;if((c&17)===17){let u=s.subLink;u&&u.nextSubLink&&Y(u),o=true;}else if((c&33)===33)if(s.depLink){n={link:e,prev:n},e=s.depLink,t=s,++i;continue e}else s.flag&=-33;else c&32&&(s.flag&=-33);}if(!o&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}for(r=o;i--;){e=n.link,n=n.prev,t=e.subNode;let s=e.depNode;if(r?s.flag=s.flag&-33|16:s.flag&=-33,s.flag&16&&(r=true),!r&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}}return r?t.flag=t.flag&-33|16:t.flag&=-33,r}while(true)}function Y(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16,(n&6)===2&&fe(t)),e=e.nextSubLink;}}function M(e){let t=e.nextSubLink,n;e:do{let i=e.subNode,r=i.flag&2,o=i.flag;if(o&60?o&12?o&4?!(o&48)&&pt(e,i)?(i.flag=o|40,r&&fe(i),o&=1):o=0:i.flag=o&-9|32:o=0:(i.flag=o|32,r&&fe(i)),o&1){let s=i.subLink;if(s!==void 0){let c=s.nextSubLink;c!==void 0&&(n={value:t,prev:n},t=c),e=s;continue}}if((e=t)!==void 0){t=e.nextSubLink;continue}for(;n!==void 0;)if(e=n.value,n=n.prev,e!==void 0){t=e.nextSubLink;continue e}break}while(true)}function le(e){let t=m;return m=e,t}function J(e){return B++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,le(e)}function z(e,t){m=t;let n=e.depLinkTail,i=n?n.nextDepLink:e.depLink;for(;i;)i=C(i,e);e.flag&=-5;}function lt(e){let t=le(void 0),n=j;j=true;try{return e()}finally{j=n,le(t);}}function pt(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var pe=new WeakMap,dt=0;function ce(e,t,n){if(e)for(let i=e.subLink;i;i=i.nextSubLink){let r=i.subNode;r._triggerVersion!==n&&(r._triggerVersion=n,t.push(r));}}function l(e,t){if(!m||j)return;let n=pe.get(e);n||(n=new Map,pe.set(e,n));let i=n.get(t);i||(i=new ue(n,t),n.set(t,i)),I(i,m);}function S(e,t,n,i){var c;let r=pe.get(e);if(!r)return;let o=[],s=++dt;if(n!==void 0)if(Array.isArray(n))for(let u of n)ce(r.get(u),o,s);else ce(r.get(n),o,s);if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let u=Array.isArray(e)?R:De;ce(r.get(u),o,s);}for(let u of o)u.flag&2?(c=u.notify)==null||c.call(u):u.flag&1&&(u.flag|=16,u.subLink&&M(u.subLink));}var vt=new WeakMap,_t=new WeakMap;function a(e){if(!e||!isObject(e))return e;let t=e._RAW;return t?a(t):h(e)?a(e.peek()):e}var Ie=bt();function bt(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let i=a(this);l(i,R);let r=i[t](...n);if((r===-1||r===false)&&n.length>0){let o=n.map(s=>a(s));r=i[t](...o);}return r};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let i=a(this),r=w(this);l(i,R);let o=i[t](...n);return (t==="find"||t==="findLast")&&isObject(o)&&!r?d(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let i=a(this),r=Array.prototype[t].apply(i,n);return S(i,T.SET,[O,R]),r};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let i=a(this),r=w(this);if(l(i,R),t==="toSpliced")for(let s=0,c=i.length;s<c;s++)l(i,`${s}`);let o=Array.prototype[t].apply(i,n);return Array.isArray(o)?o.map(s=>isObject(s)?d(s,r):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,R),Array.prototype[t].apply(this,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,R),Array.prototype[t].apply(i,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=a(this),i=w(this);l(n,O);let r=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=r.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(c=>isObject(c)?d(c,i):c),done:s}:{value:isObject(o)?d(o,i):o,done:s}},[Symbol.iterator](){return this}}};}),e}function Pe(e,t){let n=h(t)?t:a(t);return hasChanged(e,n)}var Ge=e=>({get:(t,n,i)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(hasOwn(Ie,n))return Ie[n];let r=Reflect.get(t,n,i);return isStringNumber(n)&&l(t,n),l(t,O),isObject(r)&&!e?d(r):r},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return Pe(s,o)&&(isStringNumber(n)?S(t,T.SET,[n,R,O]):S(t,T.SET,n)),c}}),mt=Ge(true),yt=Ge(false),Oe=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(hasOwn(Ae,n)?Ae:t,n,t)}}),je=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(hasOwn(Ne,n)&&n in t?Ne:t,n,t)}}),kt=Oe(true),wt=Oe(false),Lt=je(true),Rt=je(false),Ae={get(e){let t=a(this);l(t,g);let n=t.get(e);return isUndefined(n)&&!t.has(e)&&v(e)&&(n=t.get(a(e))),isObject(n)&&!w(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||hasChanged(o,s))&&S(n,T.SET,g),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,g),this},has(e){let t=a(this);l(t,g);let n=t.has(e);return !n&&isObject(e)?t.has(a(e)):n},delete(e){let t=a(this),n=t.has(e),i=t.delete(e);return !i&&isObject(e)&&(i=t.delete(a(e))),(n||i)&&S(t,T.DELETE,g),i},clear(){let e=a(this),t=e.size>0,n=e.clear();return t&&S(e,T.CLEAR,g),n},forEach(e,t){let n=a(this),i=w(this);l(n,g),n.forEach((r,o)=>{let s=i||!isObject(r)?r:d(r),c=i||!isObject(o)?o:d(o);e.call(t,s,c,this);});},[Symbol.iterator](){let e=a(this),t=w(this);l(e,g);let n=e[Symbol.iterator]();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:Array.isArray(i)?{value:i.map(o=>isObject(o)?d(o):o),done:r}:{value:isObject(i)?d(i):i,done:r}},[Symbol.iterator](){return this}}},get size(){let e=a(this);return l(e,g),e.size},keys(){let e=a(this),t=w(this);l(e,g);let n=e.keys();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},values(){let e=a(this),t=w(this);l(e,g);let n=e.values();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},entries(){let e=a(this),t=w(this);l(e,g);let n=e.entries();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:{value:i.map(o=>isObject(o)?d(o):o),done:r}},[Symbol.iterator](){return this}}}},Ne={get(e){let t=a(this);l(t,V);let n=t.get(e);return isUndefined(n)&&!t.has(e)&&v(e)&&(n=t.get(a(e))),isObject(n)&&!w(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||hasChanged(o,s))&&S(n,T.SET,V),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,V),this},has(e){let t=a(this);l(t,V);let n=t.has(e);return !n&&v(e)&&(n=t.has(a(e))),n},delete(e){let t=a(this),n=a(e),i=t.has(n),r=t.delete(n);return (i||r)&&S(t,T.DELETE,V),r}},Ye=e=>({get(t,n,i){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let r=Reflect.get(t,n,i),o=h(r)?r.value:r;return l(t,n),isObject(o)&&!e?d(o):o},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return Pe(s,o)&&S(t,T.SET,n),c},deleteProperty:(t,n)=>{let i=hasOwn(t,n),r=Reflect.deleteProperty(t,n);return i&&r&&S(t,T.DELETE,n),r}}),xt=Ye(true),Dt=Ye(false);function d(e,t=false){if(!isObject(e)||v(e))return e;let n=t?_t:vt,i=n.get(e);if(i)return i;let r;isArray(e)?r=t?mt:yt:isSet(e)||isMap(e)?r=t?kt:wt:isWeakMap(e)||isWeakSet(e)?r=t?Lt:Rt:r=t?xt:Dt;let o=new Proxy(e,r);return n.set(e,o),o}function v(e){return !!(e&&e._IS_REACTIVE)}function A(e){return v(e)||h(e)?e:d(e)}function X(e){return v(e)||h(e)?e:d(e,true)}function w(e){return !!(e&&e._IS_SHALLOW)}var Ct=e=>isObject(e)?A(e):e;var Ue;Ue="_IS_SIGNAL";var P=class{constructor(t,n=false){this.flag=1;this[Ue]=true;let i=a(t);this._rawValue=i,this._IS_SHALLOW=n,Ke(i)?v(t)?this._value=t:this._value=n?X(i):A(i):this._value=i;}get dep(){return this}get value(){let t=m;if(t&&I(this,t),this.flag&16&&this.shouldUpdate()){let i=this.subLink;i&&Y(i);}return this._value}set value(t){h(t)&&(t=t.peek());let n=t,i=a(t);if(!hasChanged(this._rawValue,i))return;if(this._oldValue=this._rawValue,this._rawValue=i,this.flag|=16,!Ke(i))this._value=i;else if(v(n))this._value=n;else {let o=this._IS_SHALLOW;this._value=o?X(i):A(i);}let r=this.subLink;r&&M(r);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());h(n)?this.value=n.peek():this.value=n;}};function Ke(e){return isObject(e)?isArray(e)||isMap(e)||isSet(e)||isWeakMap(e)||isWeakSet(e)||isPlainObject(e):false}function jt(e){return h(e)?e:new P(e)}function Yt(e){return h(e)&&(e=e.peek()),new P(e,true)}function h(e){return !!e&&!!e._IS_SIGNAL}var K=new Set,he=new Set,We=Promise.resolve(),Te=false,Mt=100;function He(e){return e?We.then(e):We}function U(e){K.add(e),Fe();}function Fe(){Te||(Te=true,He(Se));}function qe(e){he.add(e),Fe();}function Se(){Te=false,Kt();let e=0;for(;K.size>0;){if(++e>Mt){K.clear();return}let t=[...K];K.clear();for(let n of t)try{n();}catch(i){}}}function Kt(){let e=Array.from(he);he.clear();for(let t of e)try{t();}catch(n){}}function Z(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>qe(e);case "post":return ()=>U(e);default:return ()=>U(e)}}var W=0;function ee(e){Be();try{return e()}finally{$e();}}function Be(){W++;}function $e(){W--,W===0&&Se();}function Ee(){return W>0}function Ut(){return W}var y,te=class{constructor(t=false,n=void 0){this.detached=t;this.parent=n;this._active=true;this.effects=[];this.scopes=[];this.cleanups=[];!t&&y&&(this.parent=y,y.scopes.push(this));}get active(){return this._active}pause(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].pause();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).pause)==null||n.call(t);}}resume(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].resume();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).resume)==null||n.call(t);}}run(t){if(!this._active)return;let n=y;y=this;try{return t()}finally{y=n;}}stop(t=false){if(!this._active)return;this._active=false;for(let i=0;i<this.scopes.length;i++)this.scopes[i].stop(true);this.scopes.length=0;let n=this.effects.slice();this.effects.length=0;for(let i of n)i.stop();for(let i=0;i<this.cleanups.length;i++)this.cleanups[i]();if(this.cleanups.length=0,!t&&this.parent){let i=this.parent.scopes.indexOf(this);i>=0&&this.parent.scopes.splice(i,1);}this.parent=void 0;}_record(t){this.effects.push(t),t.scope=this;}_remove(t){let n=this.effects.indexOf(t);n>=0&&this.effects.splice(n,1);}_pushCleanup(t){this.cleanups.push(t);}};function Wt(e=false){return new te(e)}function Ht(){return y}function Ft(e){let t=y;return y=e,t}function qt(e,t=false){y&&y._pushCleanup(e);}function ne(e,t=y){t&&t.active&&t._record(e);}function ie(e){let t=e.scope;t&&(e.scope=void 0,t._remove(e));}var ze;ze="_IS_EFFECT";var ge=class{constructor(t,n){this.flag=18;this[ze]=true;this._active=true;if(this.fn=t,n){this.options=n;let i=n.flush||n.scheduler;i&&!isFunction(i)&&(this._flushScheduler=Z(()=>this.run(),i));}ne(this);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&$(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let i=(n&16)!==0,r=(n&32)!==0;(i||r)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-49|512;let n=J(this);try{return this.fn()}catch(i){throw this.flag|=16,i}finally{this.flag&=-513,z(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){var r,o,s;let t=this.flag;if(!this._active||t&784)return;this.flag=t|16;let n=((r=this.options)==null?void 0:r.flush)||((o=this.options)==null?void 0:o.scheduler);n?isFunction(n)?n(this):(s=this._flushScheduler)==null||s.call(this):Ee()?U(this.getJob()):this.run();}stop(){var i;if(!this._active)return;this._active=false,ie(this);let t=this.depLink;for(;t;)t=C(t,this);let n=this.subLink;for(;n;)n=C(n);this._job=void 0,this._flushScheduler=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,(i=this.options)!=null&&i.onStop&&this.options.onStop();}};function re(e,t){let n=new ge(e,t);try{n.run();}catch(r){throw n.stop(),r}let i=()=>n.run();return i.effect=n,i.stop=()=>n.stop(),i}function Bt(e){e.effect.stop();}function $t(e){return !!(e&&e._IS_EFFECT)}function Jt(e,t,n){let i=t;return re(()=>{i=e(i);},n)}var x=Symbol("computed-no-value"),Ze;Ze="_IS_COMPUTED";var oe=class{constructor(t,n,i,r){this.flag=17;this[Ze]=true;this._value=x;this._active=true;this.getter=t,this.setter=n,this.onTrack=i,this.onTrigger=r,this.flag|=16,ne(this);}get value(){if(!this.active)return this._value===x?this.getter():this._value;m&&I(this,m);let t=this.flag,n=this._value!==x;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&$(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this.active?(this._value===x&&this.recompute(),this._value):this._value===x?this.getter():this._value}get active(){return this._active}recompute(){if(!this._active){this._value===x&&(this._value=this.getter());return}let t=this._value,n=t!==x,i=J(this);try{let r=this.getter(),o=this.flag,s=this.subLink,c=-49;!n||hasChanged(t,r)?(this._value=r,this.flag=o&c,s&&Y(s)):this.flag=o&c;}catch(r){let o=-49;throw this.flag&=o,this._value=x,r}finally{z(this,i);}}shouldUpdate(){let t=this._value!==x,n=this._value;return this.recompute(),t?hasChanged(this._value,n):true}stop(){if(!this._active)return;this._active=false,ie(this);let t=this.depLink;for(;t;)t=C(t,this);let n=this.subLink;for(;n;)n=C(n);this.depLinkTail=void 0,this.subLinkTail=void 0,this.flag&=-49;}};function ve(e){if(H(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(isFunction(e))return new oe(e);if(isPlainObject(e)){let{get:t,set:n,onTrack:i,onTrigger:r}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
2
2
  Usage: computed({ get: () => value, set: (v) => { ... } })`);if(!isFunction(t))throw new TypeError(`[Computed] Invalid options: getter must be a function.
3
- Received: ${typeof t}`);return new ee(t,n,i,r)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
4
- Received: ${typeof e}`)}function K(e){return !!e&&!!e._IS_COMPUTED}function Wt(e){let{state:t,getters:n,actions:i}=e,r=ve({},t),o=C(t),s=new Set,c=new Set,u=f=>{s.forEach(y=>y(f)),c.forEach(y=>y(f));},D={patch$(f){J(()=>{Object.assign(o,f);}),u(o);},subscribe$(f){s.add(f);},unsubscribe$(f){s.delete(f);},onAction$(f){c.add(f);},offAction$(f){c.delete(f);},reset$(){J(()=>{Object.assign(o,r);}),u(o);}},E={};for(let f of Object.keys(r))Object.defineProperty(E,f,{get:()=>o[f],set:y=>{o[f]=y;},enumerable:true,configurable:true});if(Object.defineProperty(E,"state",{value:o,enumerable:true,configurable:true,writable:true}),Object.assign(E,D),n)for(let f in n){let y=n[f];if(!y)continue;let ne=he(()=>y.call(E,o));Object.defineProperty(E,f,{get:()=>ne.value,enumerable:true,configurable:true});}if(i)for(let f in i){let y=i[f];y&&(E[f]=(...ne)=>{let Xe=y.apply(E,ne);return c.forEach(Ze=>Ze(o)),Xe});}return E}function Ht(e){let t=new e,n=Object.create(null),i={},r={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let s=Object.getOwnPropertyDescriptor(e.prototype,o);s&&(isFunction(s.get)?i[o]=function(){return s.get.call(this)}:isFunction(s.value)&&o!=="constructor"&&(r[o]=function(...c){return s.value.apply(this,c)}));}),{state:n,getters:i,actions:r}}function Ft(e){return ()=>{let t;return isFunction(e)?t=Ht(e):t=e,Wt(t)}}var qe,Be,te=class extends(Be=P,qe="_IS_REF",Be){constructor(n){super(n,true);this[qe]=true;}get value(){let n=b;return n&&I(this,n),this._value}set value(n){h(n)&&(n=n.peek()),Se(n)&&(n=n.value),hasChanged(this._value,n)&&(this._rawValue=n,this._value=n,this.flag|=16,this.subLink&&Y(this.subLink));}};function Bt(e=void 0){return Se(e)?e:h(e)?new te(e.peek()):new te(e)}function Se(e){return !!e&&!!e._IS_REF}var $e={},Je=new Set;function N(e,t){if(t||(Je.clear(),t=Je),!isObject(e)||t.has(e))return e;if(t.add(e),h(e)||K(e))return N(e.value,t);if(Array.isArray(e))for(let n of e)N(n,t);else isMap(e)?(e.forEach(n=>{N(n,t);}),e.keys(),e.values()):isSet(e)?(e.forEach(n=>{N(n,t);}),e.values()):Object.keys(e).forEach(n=>{N(e[n],t);});return e}function ze(e){return isFunction(e)?e:h(e)||K(e)?()=>e.value:m(e)?()=>N(e):()=>e}function Xt(e){if(Array.isArray(e)){let t=e.map(n=>ze(n));return ()=>t.map(n=>n())}return ze(e)}function Zt(e,t,n={}){let{immediate:i=false,deep:r=false}=n,o=$e,s=Xt(e),c=()=>{let D=u.effect;if(!D.run)return;let E=D.run();(r||isObject(E)||hasChanged(E,o))&&(t(E,o===$e?void 0:o),o=E);},u=Z(()=>{let D=s();return r&&N(D),D},{scheduler:()=>A(c)});return i?c():o=u.effect.run(),()=>{u.stop();}}export{z as EffectScope,T as TriggerOpTypes,J as batch,he as computed,Ft as createStore,Z as effect,Pt as effectScope,Me as endBatch,Vt as getBatchDepth,Gt as getCurrentScope,pe as isBatching,K as isComputed,Mt as isEffect,m as isReactive,Se as isRef,L as isShallow,h as isSignal,Kt as memoEffect,Pe as nextTick,jt as onScopeDispose,A as queueJob,Oe as queuePreFlushCb,C as reactive,Bt as ref,Ot as setCurrentScope,B as shallowReactive,At as shallowSignal,Ct as signal,Ye as startBatch,Yt as stop,a as toRaw,kt as toReactive,S as trigger,rt as untrack,Zt as watch};
3
+ Received: ${typeof t}`);return new oe(t,n,i,r)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
4
+ Received: ${typeof e}`)}function H(e){return !!e&&!!e._IS_COMPUTED}function Qt(e){let{state:t,getters:n,actions:i}=e,r=xe({},t),o=A(t),s=new Set,c=new Set,u=f=>{s.forEach(E=>E(f)),c.forEach(E=>E(f));},G={patch$(f){ee(()=>{Object.assign(o,f);}),u(o);},subscribe$(f){s.add(f);},unsubscribe$(f){s.delete(f);},onAction$(f){c.add(f);},offAction$(f){c.delete(f);},reset$(){ee(()=>{Object.assign(o,r);}),u(o);}},L={};for(let f of Object.keys(r))Object.defineProperty(L,f,{get:()=>o[f],set:E=>{o[f]=E;},enumerable:true,configurable:true});if(Object.defineProperty(L,"state",{value:o,enumerable:true,configurable:true,writable:true}),Object.assign(L,G),n)for(let f in n){let E=n[f];if(!E)continue;let D=ve(()=>E.call(L,o));Object.defineProperty(L,f,{get:()=>D.value,enumerable:true,configurable:true});}if(i)for(let f in i){let E=i[f];E&&(L[f]=(...D)=>{let ae=E.apply(L,D);return c.forEach(F=>F(o)),ae});}return L}function Xt(e){let t=new e,n=Object.create(null),i={},r={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let s=Object.getOwnPropertyDescriptor(e.prototype,o);s&&(isFunction(s.get)?i[o]=function(){return s.get.call(this)}:isFunction(s.value)&&o!=="constructor"&&(r[o]=function(...c){return s.value.apply(this,c)}));}),{state:n,getters:i,actions:r}}function Zt(e){return ()=>{let t;return isFunction(e)?t=Xt(e):t=e,Qt(t)}}var et,tt,se=class extends(tt=P,et="_IS_REF",tt){constructor(n){super(n,true);this[et]=true;}get value(){let n=m;return n&&I(this,n),this._value}set value(n){h(n)&&(n=n.peek()),be(n)&&(n=n.value),hasChanged(this._value,n)&&(this._rawValue=n,this._value=n,this.flag|=16,this.subLink&&M(this.subLink));}};function tn(e=void 0){return be(e)?e:h(e)?new se(e.peek()):new se(e)}function be(e){return !!e&&!!e._IS_REF}var nt={},it=new Set,me=false;function N(e,t){if(!isObject(e)||t.has(e))return e;if(t.add(e),h(e)||H(e))N(e.value,t);else if(Array.isArray(e))for(let n of e)N(n,t);else if(isMap(e))e.forEach(n=>{N(n,t);}),e.keys(),e.values();else if(isSet(e))e.forEach(n=>{N(n,t);}),e.values();else for(let n of Object.keys(e))N(e[n],t);return e}function st(e){if(me)return N(e,new Set);me=true,it.clear();try{return N(e,it)}finally{me=false;}}function rt(e){return isFunction(e)?e:h(e)||H(e)?()=>e.value:v(e)?()=>st(e):()=>e}function an(e){if(Array.isArray(e)){let t=e.map(n=>rt(n));return ()=>t.map(n=>n())}return rt(e)}function cn(e,t,n={}){let{immediate:i=false,deep:r=false,flush:o="post",once:s=false}=n,c=nt,u,G=true,L=!Array.isArray(e)&&v(e),f=r&&!L,E=an(e),D,ae=k=>{D=()=>{D=void 0;try{k();}catch(q){}};},F=()=>{D&&D();},ye=k=>{F(),t(k,c===nt?void 0:c,ae),c=k,s&&we();},ke=re(()=>{let k=E();return f&&st(k),u=k,k},{scheduler:Z(()=>{if(!G)return;let k=ke.effect;if(!k.active)return;let q=k.run();(r||isObject(q)||hasChanged(q,c))&&ye(q);},o)});function we(){G&&(G=false,F(),ke.stop());}return i?ye(u):c=u,we}export{te as EffectScope,T as TriggerOpTypes,ee as batch,ve as computed,Zt as createStore,re as effect,Wt as effectScope,$e as endBatch,Ut as getBatchDepth,Ht as getCurrentScope,Ee as isBatching,H as isComputed,$t as isEffect,v as isReactive,be as isRef,w as isShallow,h as isSignal,Jt as memoEffect,He as nextTick,qt as onScopeDispose,U as queueJob,qe as queuePreFlushCb,A as reactive,tn as ref,Ft as setCurrentScope,X as shallowReactive,Yt as shallowSignal,jt as signal,Be as startBatch,Bt as stop,a as toRaw,Ct as toReactive,S as trigger,lt as untrack,cn as watch};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estjs/signals",
3
- "version": "0.0.17-beta.1",
3
+ "version": "0.0.17-beta.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -52,7 +52,7 @@
52
52
  "unpkg": "dist/signals.js",
53
53
  "jsdelivr": "dist/signals.js",
54
54
  "dependencies": {
55
- "@estjs/shared": "0.0.17-beta.1"
55
+ "@estjs/shared": "0.0.17-beta.2"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsup && cross-env NODE_ENV=production tsup --clean=false",