sia-reactor 0.0.3 → 0.0.4

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.
@@ -0,0 +1 @@
1
+ var p=/^([^\[\]]+)\[(\d+)\]$/;function m(e){return e!==void 0}function d(e){return Array.isArray(e)}function f(e,n=!0){return typeof e=="object"&&e!==null&&(n?!Array.isArray(e):!0)}function b(e,n=!1,s=!0){return(s?f(e,!1):!0)&&(n?Object.prototype.toString.call(e)==="[object Object]":e.constructor===Object)}function P(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function j(e,n){return e?.includes?.(n)??e}function x(e,n,s,r=".",o){var c,u;if(!n.includes(r))return void(e[o?o(n):n]=s);let t=n.split(r),i=e;for(let a=0;a<t.length;a++){let l=o?o(t[a]):t[a],h=l.includes("[")&&l.match(p);if(h){let[,T,y]=h;d(i[T])||(i[T]=[]),a===t.length-1?i[T][Number(y)]=s:((c=i[T])[u=Number(y)]||(c[u]={}),i=i[T][Number(y)])}else a===t.length-1?i[l]=s:(i[l]||(i[l]={}),i=i[l])}}function A(e,n,s=".",r){if(!n.includes(s))return e[r?r(n):n];let o=n.split(s),t=e;for(let i=0;i<o.length;i++){let c=r?r(o[i]):o[i],u=c.includes("[")&&c.match(p);if(u){let[,a,l]=u;if(!d(t[a])||!(a in t))return;t=t[a][Number(l)]}else{if(!f(t)||!(c in t))return;t=t[c]}}return t}function W(e,n,s=".",r){if(!n.includes(s))return void delete e[r?r(n):n];let o=n.split(s),t=e;for(let i=0;i<o.length;i++){let c=r?r(o[i]):o[i],u=c.includes("[")&&c.match(p);if(u){let[,a,l]=u;if(!d(t[a])||!(a in t))return;i===o.length-1?delete t[a][Number(l)]:t=t[a][Number(l)]}else{if(!f(t)||!(c in t))return;i===o.length-1?delete t[c]:t=t[c]}}}function N(e,n,s=".",r){if(!n.includes(s))return n in e;let o=n.split(s),t=e;for(let i=0;i<o.length;i++){let c=r?r(o[i]):o[i],u=c.includes("[")&&c.match(p);if(u){let[,a,l]=u;if(!d(t[a])||!(a in t))return!1;if(i===o.length-1)return!0;t=t[a][Number(l)]}else{if(!f(t)||!(c in t))return!1;if(i===o.length-1)return!0;t=t[c]}}return!0}function g(e,n=".",s=o=>o,r=new WeakSet){if(!f(e)||r.has(e))return e;r.add(e);let o={};return Object.keys(e).forEach(t=>t.includes(n)?x(o,t,g(e[t],n,s,r),n,s):o[t]=f(e[t])?g(e[t],n,s,r):e[t]),o}function R(e,n,s=n[0],r={}){return Object.assign(r,typeof e=="boolean"?{[s]:e}:e),r}function S(e={},n={}){let s={...e||{},...n||{}};return Object.keys(s).forEach(r=>f(e?.[r])&&f(n?.[r])&&(s[r]=S(e[r],n[r]))),s}function w(e,n=!0){let s=e.split("."),r=["*"],o="";for(let t=0;t<s.length;t++)o+=(t===0?"":".")+s[t],r.push(o);return n?r.reverse():r}function D(e,n){let s=n.split("."),r=[["*",e,e]],o="",t=e;for(let i=0;i<s.length;i++)o+=(i===0?"":".")+s[i],r.push([o,t,t=t?.[s[i]]]);return r}function O(e,n,s=new WeakMap){if(!(b(e,n)||d(e))||s.has(e))return e;let r=d(e)?[]:{};s.set(e,r);let o=Object.keys(e);for(let t=0;t<o.length;t++)r[o[t]]=O(e[o[t]],n,s);return r}function V(e){let n=e;for(;n&&n!==Object.prototype;){for(let s of Object.getOwnPropertyNames(n)){if(s==="constructor")continue;let r=Object.getOwnPropertyDescriptor(n,s);typeof r?.value!="function"&&(r?.get||r?.set||(n[s]=null))}n=Object.getPrototypeOf(n)}}export{m as a,d as b,f as c,b as d,P as e,j as f,x as g,A as h,W as i,N as j,g as k,R as l,S as m,w as n,D as o,O as p,V as q};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var q=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var be=(a,e)=>{for(var t in e)q(a,t,{get:e[t],enumerable:!0})},xe=(a,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Pe(e))!ye.call(a,n)&&n!==t&&q(a,n,{get:()=>e[n],enumerable:!(s=ge(e,n))||s.enumerable});return a};var Se=a=>xe(q({},"__esModule",{value:!0}),a);var me={};be(me,{Reactor:()=>w,ReactorEvent:()=>v,getSnapshotVersion:()=>Te,getVersion:()=>ue,inert:()=>ne,intent:()=>ae,isInert:()=>re,isIntent:()=>ce,isVolatile:()=>de,live:()=>ie,methods:()=>J,reactive:()=>se,stable:()=>he,state:()=>oe,volatile:()=>le});module.exports=Se(me);var B=/^([^\[\]]+)\[(\d+)\]$/;function G(a){return Array.isArray(a)}function M(a,e=!0){return typeof a=="object"&&a!==null&&(e?!Array.isArray(a):!0)}function I(a,e=!1,t=!0){return(t?M(a,!1):!0)&&(e?Object.prototype.toString.call(a)==="[object Object]":a.constructor===Object)}function U(a,e,t,s=".",n){var c,h;if(!e.includes(s))return void(a[n?n(e):e]=t);let i=e.split(s),r=a;for(let o=0;o<i.length;o++){let l=n?n(i[o]):i[o],d=l.includes("[")&&l.match(B);if(d){let[,u,T]=d;G(r[u])||(r[u]=[]),o===i.length-1?r[u][Number(T)]=t:((c=r[u])[h=Number(T)]||(c[h]={}),r=r[u][Number(T)])}else o===i.length-1?r[l]=t:(r[l]||(r[l]={}),r=r[l])}}function k(a,e,t=".",s){if(!e.includes(t))return a[s?s(e):e];let n=e.split(t),i=a;for(let r=0;r<n.length;r++){let c=s?s(n[r]):n[r],h=c.includes("[")&&c.match(B);if(h){let[,o,l]=h;if(!G(i[o])||!(o in i))return;i=i[o][Number(l)]}else{if(!M(i)||!(c in i))return;i=i[c]}}return i}function Q(a,e,t=".",s){if(!e.includes(t))return void delete a[s?s(e):e];let n=e.split(t),i=a;for(let r=0;r<n.length;r++){let c=s?s(n[r]):n[r],h=c.includes("[")&&c.match(B);if(h){let[,o,l]=h;if(!G(i[o])||!(o in i))return;r===n.length-1?delete i[o][Number(l)]:i=i[o][Number(l)]}else{if(!M(i)||!(c in i))return;r===n.length-1?delete i[c]:i=i[c]}}}function V(a,e,t=".",s){if(!e.includes(t))return e in a;let n=e.split(t),i=a;for(let r=0;r<n.length;r++){let c=s?s(n[r]):n[r],h=c.includes("[")&&c.match(B);if(h){let[,o,l]=h;if(!G(i[o])||!(o in i))return!1;if(r===n.length-1)return!0;i=i[o][Number(l)]}else{if(!M(i)||!(c in i))return!1;if(r===n.length-1)return!0;i=i[c]}}return!0}function O(a,e,t=e[0],s={}){return Object.assign(s,typeof a=="boolean"?{[t]:a}:a),s}function H(a={},e={}){let t={...a||{},...e||{}};return Object.keys(t).forEach(s=>M(a?.[s])&&M(e?.[s])&&(t[s]=H(a[s],e[s]))),t}function Y(a,e=!0){let t=a.split("."),s=["*"],n="";for(let i=0;i<t.length;i++)n+=(i===0?"":".")+t[i],s.push(n);return e?s.reverse():s}function Z(a,e){let t=e.split("."),s=[["*",a,a]],n="",i=a;for(let r=0;r<t.length;r++)n+=(r===0?"":".")+t[r],s.push([n,i,i=i?.[t[r]]]);return s}function F(a){let e=a;for(;e&&e!==Object.prototype;){for(let t of Object.getOwnPropertyNames(e)){if(t==="constructor")continue;let s=Object.getOwnPropertyDescriptor(e,t);typeof s?.value!="function"&&(s?.get||s?.set||(e[t]=null))}e=Object.getPrototypeOf(e)}}var E=Symbol.for("S.I.A_RAW"),L=Symbol.for("S.I.A_INERTIA"),D=Symbol.for("S.I.A_REJECTABLE"),N=Symbol.for("S.I.A_INDIFFABLE"),z=Symbol.for("S.I.A_TERMINATOR"),C=Symbol.for("S.I.A_VERSION"),K=Symbol.for("S.I.A_SNAPSHOT_VERSION"),X=()=>{},Re=(typeof queueMicrotask<"u"?queueMicrotask:setTimeout).bind(window),ee=console.log.bind(console,"[S.I.A Reactor]"),te=console.warn.bind(console,"[S.I.A Event]"),W={LISTENER:["capture","depth","once","signal","immediate"],MEDIATOR:["lazy","signal","immediate"]},A=class A{constructor(e,t=!1,s=!0){this.eventPhase=A.NONE;this._propagationStopped=!1;this._immediatePropagationStopped=!1;this._resolved="";this._rejected="";this._warn=X;this.type=this.staticType=e.type,this.target=e.target,this.currentTarget=e.currentTarget,this.root=e.root,this.value=e.target.value,this.oldValue=e.target.oldValue,this.path=e.target.path,this.rejectable=e.rejectable,this.bubbles=t,s&&(this._warn=te)}get propagationStopped(){return this._propagationStopped}stopPropagation(){this._propagationStopped=!0}get immediatePropagationStopped(){return this._immediatePropagationStopped}stopImmediatePropagation(){this._propagationStopped=!0,this._immediatePropagationStopped=!0}get resolved(){return this._resolved}resolve(e){if(!this.rejectable)return this._warn(`Ignored resolve() call on a non-rejectable ${this.staticType} at "${this.path}"`);this.eventPhase!==A.CAPTURING_PHASE&&this._warn(`Resolving an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`),this.rejectable&&(this._resolved=e||`Could ${this.staticType} intended value at "${this.path}"`)}get rejected(){return this._rejected}reject(e){if(!this.rejectable)return this._warn(`Ignored reject() call on a non-rejectable ${this.staticType} at "${this.path}"`);this.eventPhase!==A.CAPTURING_PHASE&&this._warn(`Rejecting an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`),this.rejectable&&(this._rejected=e||`Couldn't ${this.staticType} intended value at "${this.path}"`)}composedPath(){return Y(this.path)}get canWarn(){return this._warn===te}};A.NONE=0,A.CAPTURING_PHASE=1,A.AT_TARGET=2,A.BUBBLING_PHASE=3;var v=A,w=class{constructor(e={},t){this.proxyCache=new WeakMap;this.log=X;this.isLogging=!1;this.isTracing=!1;this.isTracking=!1;this.isSCloning=!1;this.isBatching=!1;this[L]=!0,this.config={crossRealms:!1,eventBubbling:!0,batchingFunction:Re,...t},this.core=this.proxied(e),t&&(this.canLog=!!t.debug,(this.isTracking=!!t.referenceTracking)&&(this.lineage=new WeakMap),(this.isSCloning=this.isTracking&&!!t.smartCloning)&&(this.snapshotCache=new WeakMap),this.isTracing=this.isTracking&&!!t.lineageTracing)}proxied(e,t=!1,s=!1,n,i,r){if(!e||typeof e!="object"||!(I(e,this.config.crossRealms,!1)||Array.isArray(e))||e[L])return e;if(e=e[E]||e,this.isTracking&&n&&i&&this.link(e,n,i,!1),this.proxyCache.has(e))return this.proxyCache.get(e);t||(t=e[D]),s||(s=e[N]);let c=new Proxy(e,{get:(h,o,l)=>{if(o===E)return h;let d=h[o],u=String(o),T=this.isTracing?void 0:r?r+"."+u:u,y=this.isTracing?this.trace(h,u):T;if(this.log(`\u{1F440} [GET Trap] Initiated for "${u}" on "${y}"`),this.config.get&&(d=this.config.get(h,o,d,l,y)),this.getters){let f=this.getters.get("*");for(let g=0,S=this.isTracing?y.length:1;g<S;g++){let p=this.isTracing?y[g]:T,x=this.getters.get(p);if(!x&&!f)continue;let P={path:p,value:d,key:u,object:l},b={type:"get",target:P,currentTarget:P,root:this.core,rejectable:t};x&&(d=this.mediate(p,b,"get",x)),f&&(P.value=d,d=this.mediate("*",b,"get",f))}}return this.proxied(d,t,s,h,u,T)},set:(h,o,l,d)=>{let u,T,y,f=!1,g=String(o),S=this.isTracing?void 0:r?r+"."+g:g,p=this.isTracing?this.trace(h,g):S,x=this.isTracing?p.length:1,P=h[o];if((this.isTracking||!s)&&(y=P?.[E]||P,T=l?.[E]||l,u=Object.is(T,y)),!s&&u)return!0;if(this.log(`\u270F\uFE0F [SET Trap] Initiated for "${g}" on "${p}"`),this.config.set&&(f=(l=this.config.set(h,o,l,P,d,p))===z),this.setters){let b=this.setters.get("*");for(let m=0;m<x;m++){let R=this.isTracking?p[m]:S,j=this.setters.get(R);if(!j&&!b)continue;let _={path:R,value:l,oldValue:P,key:g,object:d},$={type:"set",target:_,currentTarget:_,root:this.core,terminated:f,rejectable:t};if(j){let pe=this.mediate(R,$,"set",j);f||(f=$.terminated)||(l=pe)}if(!b)continue;_.value=l;let fe=this.mediate("*",$,"set",b);f||(f=$.terminated)||(l=fe)}}if(f)return this.log(`\u{1F6E1}\uFE0F [SET Mediator] Terminated on "${p}"`),!0;if(h[o]=l,this.isTracking&&!u&&(this.isSCloning&&this.stamp(h),this.unlink(y,h,g),this.link(T,h,g)),this.watchers||this.listeners)for(let b=0;b<x;b++){let m=this.isTracking?p[b]:S,R={path:m,value:l,oldValue:P,key:g,object:d};this.notify(m,{type:"set",target:R,currentTarget:R,root:this.core,terminated:f,rejectable:t})}return!0},deleteProperty:(h,o)=>{let l,d=this.proxyCache.get(h),u=!1,T=String(o),y=this.isTracing?void 0:r?r+"."+T:T,f=this.isTracing?this.trace(h,T):y,g=this.isTracing?f.length:1,S=h[o];if(this.log(`\u{1F5D1}\uFE0F [DELETE Trap] Initiated for "${T}" on "${f}"`),this.config.delete&&(u=(l=this.config.delete(h,o,S,d,f))===z),this.deleters){let p=this.deleters.get("*");for(let x=0;x<g;x++){let P=this.isTracking?f[x]:y,b=this.deleters.get(P);if(!b&&!p)continue;let m={path:P,value:l,oldValue:S,key:T,object:d},R={type:"delete",target:m,currentTarget:m,root:this.core,rejectable:t};if(b){let _=this.mediate(P,R,"delete",b);u||(u=R.terminated)||(l=_)}if(!p)continue;let j=this.mediate("*",R,"delete",p);u||(u=R.terminated)||(l=j)}}if(u)return this.log(`\u{1F6E1}\uFE0F [DELETE Mediator] Terminated on "${f}"`),!0;if(delete h[o],this.isTracking&&(this.isSCloning&&this.stamp(h),this.unlink(S?.[E]||S,h,T)),this.watchers||this.listeners)for(let p=0;p<g;p++){let x=this.isTracking?f[p]:y,P={path:x,value:l,oldValue:S,key:T,object:d};this.notify(x,{type:"delete",target:P,currentTarget:P,root:this.core,rejectable:t})}return!0}});return this.proxyCache.set(e,c),c}trace(e,t,s=[],n=new WeakSet){if(Object.is(e,this.core[E]||this.core))return s.push(t),s;if(n.has(e))return s;n.add(e);let i=this.lineage.get(e);if(!i)return s;for(let r=0,c=i.length;r<c;r+=2)this.trace(i[r],i[r+1]?i[r+1]+"."+t:t,s,n);return s}link(e,t,s,n=!0,i){if(!(n&&!(I(e,this.config.crossRealms)||Array.isArray(e)))){i=this.lineage.get(e)??(this.lineage.set(e,i=[]),i);for(let r=0,c=i.length;r<c;r+=2)if(Object.is(i[r],t)&&i[r+1]===s)return;i.push(t,s)}}unlink(e,t,s){if(!(I(e,this.config.crossRealms)||Array.isArray(e)))return;let n=this.lineage.get(e);if(n){for(let i=0,r=n.length;i<r;i+=2)if(Object.is(n[i],t)&&n[i+1]===s)return void n.splice(i,2)}}stamp(e,t=!0){if(t&&typeof e!="object")return;e[C]=(e[C]||0)+1;let s=this.lineage?.get(e);if(s)for(let n=0,i=s.length;n<i;n+=2)this.stamp(s[n])}mediate(e,t,s,n){let i=!1,r=t.target.value,c=s==="get",h=s==="set",o=c?this.getters:h?this.setters:this.deleters;for(let l=c?n.length-1:0,d=c?-1:n.length;l!==d;l+=c?-1:1){let u=c?n[l].cb(r,t):h?n[l].cb(r,i,t):n[l].cb(i,t);(c||!(i||(i=t.terminated=u===z)))&&(r=u),n[l].once&&(n.splice(l--,1),!n.length&&o.delete(e))}return r}notify(e,t){if(this.watchers){let s=this.watchers.get("*"),n=this.watchers.get(e);if(n)for(let i=0,r=n.length;i<r;i++)n[i].cb(t.target.value,t),n[i].once&&(n.splice(i--,1),!n.length&&this.watchers.delete(e));if(s)for(let i=0,r=s.length;i<r;i++)s[i].cb(t.target.value,t),s[i].once&&(s.splice(i--,1),!s.length&&this.watchers.delete("*"))}this.listeners&&this.schedule(e,t)}schedule(e,t){this.batch??(this.batch=new Map),this.batch.set(e,t),!this.isBatching&&this.initBatching()}initBatching(){this.isBatching=!0,this.config.batchingFunction(()=>this.flush())}flush(){if(this.isBatching=!1,this.batch&&this.tick(this.batch.keys()),this.queue?.size)for(let e of this.queue)e(),this.queue.delete(e)}wave(e,t){let s=new v(t,this.config.eventBubbling,this.isLogging),n=Z(this.core,e);s.eventPhase=v.CAPTURING_PHASE;for(let i=0;i<=n.length-2&&!s.propagationStopped;i++)this.fire(n[i],s,!0);if(!s.propagationStopped&&(s.eventPhase=v.AT_TARGET,this.fire(n[n.length-1],s,!0),!s.immediatePropagationStopped&&this.fire(n[n.length-1],s,!1),!!s.bubbles)){s.eventPhase=v.BUBBLING_PHASE;for(let i=n.length-2;i>=0&&!s.propagationStopped;i--)this.fire(n[i],s,!1)}}fire([e,t,s],n,i,r=this.listeners.get(e)){if(!r)return;n.type=e!==n.target.path?"update":n.staticType,n.currentTarget={path:e,value:s,oldValue:n.type!=="update"?n.target.oldValue:void 0,key:n.type!=="update"?e:e.slice(e.lastIndexOf(".")+1)||"",object:t};let c,h;for(let o=0,l=r.length;o<l&&!n.immediatePropagationStopped;o++)r[o].capture===i&&(r[o].depth!==void 0&&(c??(c=this.getDepth(n.target.path)),h??(h=this.getDepth(e)),c>h+r[o].depth)||(r[o].cb(n),r[o].once&&(r.splice(o--,1),!r.length&&this.listeners.delete(e))))}tick(e){if(!e)return this.flush();if(typeof e=="string"){let t=this.batch?.get(e);t&&(this.wave(e,t),this.batch.delete(e))}else for(let t of e){let s=this.batch.get(t);s&&(this.wave(t,s),this.batch.delete(t))}}stall(e){this.queue??(this.queue=new Set),this.queue.add(e),!this.isBatching&&this.initBatching()}nostall(e){return this.queue?.delete(e)}bind(e,t){return t?.aborted?e.clup():t?.addEventListener("abort",e.clup,{once:!0}),t&&!t.aborted&&(e.sclup=()=>t.removeEventListener("abort",e.clup)),e.clup}clone(e,t,s=new WeakMap){if(!(I(e,this.config.crossRealms)||Array.isArray(e))||s.has(e))return e;let n=e[C]||0,i=!t&&this.isSCloning&&this.snapshotCache.get(e);if(i&&e[K]===n)return i;let r=t?e[E]||e:Array.isArray(e)?[]:{};s.set(e,r);let c=Object.keys(e);for(let h=0,o=c.length;h<o;h++)r[c[h]]=this.clone(e[c[h]],t,s);return!t&&this.isSCloning&&(this.snapshotCache.set(e,r),e[K]=n),r}getDepth(e,t=e?1:0){for(let s=0,n=e.length;s<n;s++)e.charCodeAt(s)===46&&t++;return t}getContext(e){let t=e.lastIndexOf("."),s=e==="*"?this.core:k(this.core,e),n=t===-1?this.core:k(this.core,e.slice(0,t));return{path:e,value:s,key:e.slice(t+1)||"",object:n}}syncAdd(e,t,s,n,i){var y;let{lazy:r=!1,once:c=!1,signal:h,immediate:o=!1}=O(n,W.MEDIATOR),l=this[y=`${e}${e.endsWith("t")?"t":""}ers`]??(this[y]=new Map),d=l.get(t),u;if(d){for(let f=0,g=d.length;f<g;f++)if(Object.is(d[f].cb,s)){u=d[f];break}}if(u)return u.clup;let T;return u={cb:s,once:c,clup:()=>(r&&this.nostall(T),this[`no${e}`](t,s))},o&&i?.(o),T=()=>(d??(l.set(t,d=[]),d)).push(u),r?this.stall(T):T(),this.bind(u,h)}syncDrop(e,t,s){let n=e?.get(t);if(n){for(let i=0,r=n.length;i<r;i++)if(Object.is(n[i].cb,s))return n[i].sclup?.(),n.splice(i--,1),!n.length&&e.delete(t),!0;return!1}}get(e,t,s){return this.syncAdd("get",e,t,s,n=>(n!=="auto"||V(this.core,e))&&k(this.core,e))}gonce(e,t,s){return this.get(e,t,{...O(s,W.MEDIATOR),once:!0})}noget(e,t){return this.syncDrop(this.getters,e,t)}set(e,t,s){return this.syncAdd("set",e,t,s,n=>(n!=="auto"||V(this.core,e))&&U(this.core,e,k(this.core,e)))}sonce(e,t,s){return this.set(e,t,Object.assign(O(s,W.MEDIATOR),{once:!0}))}noset(e,t){return this.syncDrop(this.setters,e,t)}delete(e,t,s){return this.syncAdd("delete",e,t,s,n=>(n!=="auto"||V(this.core,e))&&Q(this.core,e,void 0))}donce(e,t,s){return this.delete(e,t,Object.assign(O(s,W.MEDIATOR),{once:!0}))}nodelete(e,t){return this.syncDrop(this.deleters,e,t)}watch(e,t,s){return this.syncAdd("watch",e,t,s,n=>n!=="auto"&&V(this.core,e)&&(i=>t(i.value,{type:"init",target:i,currentTarget:i,root:this.core,rejectable:!1}))(this.getContext(e)))}wonce(e,t,s){return this.watch(e,t,Object.assign(O(s,W.MEDIATOR),{once:!0}))}nowatch(e,t){return this.syncDrop(this.watchers,e,t)}on(e,t,s){this.listeners??(this.listeners=new Map);let{capture:n=!1,once:i=!1,signal:r,immediate:c=!1,depth:h}=O(s,W.LISTENER),o=this.listeners.get(e),l;if(o){for(let d=0,u=o.length;d<u;d++)if(Object.is(o[d].cb,t)&&n===o[d].capture){l=o[d];break}}if(l)return l.clup;if(l={cb:t,capture:n,depth:h,once:i,clup:()=>this.off(e,t,s)},c&&(c!=="auto"||V(this.core,e))){let d=this.getContext(e);t(new v({type:"init",target:d,currentTarget:d,root:this.core,rejectable:!1},this.config.eventBubbling,this.isLogging))}return(o??(this.listeners.set(e,o=[]),o)).push(l),this.bind(l,r)}once(e,t,s){return this.on(e,t,Object.assign(O(s,W.LISTENER),{once:!0}))}off(e,t,s){let n=this.listeners?.get(e);if(!n)return;let{capture:i}=O(s,W.LISTENER);for(let r=0,c=n.length;r<c;r++)if(Object.is(n[r].cb,t)&&n[r].capture===i)return n[r].sclup?.(),n.splice(r--,1),!n.length&&this.listeners.delete(e),!0;return!1}snapshot(e=!this.isSCloning,t=this.core){return this.clone(t,e)}cascade({type:e,currentTarget:{path:t,value:s,oldValue:n}},i=!0){if(e!=="set"&&e!=="delete"||!(I(s,this.config.crossRealms)||Array.isArray(s))||i&&!(I(n,this.config.crossRealms)||Array.isArray(n)))return;let r=i?H(n,s):s,c=Object.keys(r);for(let h=0,o=c.length;h<o;h++)U(this.core,t+"."+c[h],r[c[h]])}reset(){this.getters?.clear(),this.setters?.clear(),this.deleters?.clear(),this.watchers?.clear(),this.listeners?.clear(),this.queue?.clear(),this.batch?.clear(),this.isBatching=!1,this.proxyCache=new WeakMap}destroy(){this.reset(),F(this)}get canLog(){return this.log===ee}set canLog(e){this.log=(this.isLogging=e)?ee:X}get canTrackReferences(){return this.isTracking}get canTraceLineage(){return this.isTracing}get canSmartClone(){return this.isSCloning}};var J=["tick","stall","nostall","get","gonce","noget","set","sonce","noset","delete","donce","nodelete","watch","wonce","nowatch","on","once","off","cascade","snapshot","reset","destroy"];function se(a,e,t){let s={},n=a instanceof w?a:new w(a,e),i={enumerable:!1,configurable:!0,writable:!1},r=!!(t?.prefix||t?.suffix);for(let c of J){if(r)(t?.whitelist?.includes(c)??!0)&&(c=`${t?.prefix||""}${c}${t?.suffix||""}`);else if(t?.whitelist?.includes(c))continue;s[c]={value:n[c].bind(n),...i}}return s.__Reactor__={value:n,...i},Object.defineProperties(n.core,s),n.core}function ne(a){return a[L]=!0,a}function ie(a){return delete a[L],a}function re(a){return!!a[L]}function ae(a){return a[D]=!0,a}function oe(a){return delete a[D],a}function ce(a){return!!a[D]}function le(a){return a[N]=!0,a}function he(a){return delete a[N],a}function de(a){return!!a[N]}function ue(a){return a[C]||0}function Te(a){return a[K]||0}0&&(module.exports={Reactor,ReactorEvent,getSnapshotVersion,getVersion,inert,intent,isInert,isIntent,isVolatile,live,methods,reactive,stable,state,volatile});
1
+ "use strict";var X=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var be=(a,e)=>{for(var t in e)X(a,t,{get:e[t],enumerable:!0})},xe=(a,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Pe(e))!ye.call(a,n)&&n!==t&&X(a,n,{get:()=>e[n],enumerable:!(s=ge(e,n))||s.enumerable});return a};var Se=a=>xe(X({},"__esModule",{value:!0}),a);var me={};be(me,{Reactor:()=>V,ReactorEvent:()=>v,TERMINATOR:()=>k,getSnapshotVersion:()=>Te,getVersion:()=>ue,inert:()=>ne,intent:()=>ae,isInert:()=>re,isIntent:()=>ce,isVolatile:()=>de,live:()=>ie,methods:()=>F,reactive:()=>se,stable:()=>he,state:()=>oe,volatile:()=>le});module.exports=Se(me);var G=/^([^\[\]]+)\[(\d+)\]$/;function _(a){return Array.isArray(a)}function E(a,e=!0){return typeof a=="object"&&a!==null&&(e?!Array.isArray(a):!0)}function W(a,e=!1,t=!0){return(t?E(a,!1):!0)&&(e?Object.prototype.toString.call(a)==="[object Object]":a.constructor===Object)}function q(a,e,t,s=".",n){var c,h;if(!e.includes(s))return void(a[n?n(e):e]=t);let i=e.split(s),r=a;for(let o=0;o<i.length;o++){let l=n?n(i[o]):i[o],d=l.includes("[")&&l.match(G);if(d){let[,u,T]=d;_(r[u])||(r[u]=[]),o===i.length-1?r[u][Number(T)]=t:((c=r[u])[h=Number(T)]||(c[h]={}),r=r[u][Number(T)])}else o===i.length-1?r[l]=t:(r[l]||(r[l]={}),r=r[l])}}function M(a,e,t=".",s){if(!e.includes(t))return a[s?s(e):e];let n=e.split(t),i=a;for(let r=0;r<n.length;r++){let c=s?s(n[r]):n[r],h=c.includes("[")&&c.match(G);if(h){let[,o,l]=h;if(!_(i[o])||!(o in i))return;i=i[o][Number(l)]}else{if(!E(i)||!(c in i))return;i=i[c]}}return i}function z(a,e,t=".",s){if(!e.includes(t))return void delete a[s?s(e):e];let n=e.split(t),i=a;for(let r=0;r<n.length;r++){let c=s?s(n[r]):n[r],h=c.includes("[")&&c.match(G);if(h){let[,o,l]=h;if(!_(i[o])||!(o in i))return;r===n.length-1?delete i[o][Number(l)]:i=i[o][Number(l)]}else{if(!E(i)||!(c in i))return;r===n.length-1?delete i[c]:i=i[c]}}}function w(a,e,t=".",s){if(!e.includes(t))return e in a;let n=e.split(t),i=a;for(let r=0;r<n.length;r++){let c=s?s(n[r]):n[r],h=c.includes("[")&&c.match(G);if(h){let[,o,l]=h;if(!_(i[o])||!(o in i))return!1;if(r===n.length-1)return!0;i=i[o][Number(l)]}else{if(!E(i)||!(c in i))return!1;if(r===n.length-1)return!0;i=i[c]}}return!0}function m(a,e,t=e[0],s={}){return Object.assign(s,typeof a=="boolean"?{[t]:a}:a),s}function U(a={},e={}){let t={...a||{},...e||{}};return Object.keys(t).forEach(s=>E(a?.[s])&&E(e?.[s])&&(t[s]=U(a[s],e[s]))),t}function J(a,e=!0){let t=a.split("."),s=["*"],n="";for(let i=0;i<t.length;i++)n+=(i===0?"":".")+t[i],s.push(n);return e?s.reverse():s}function Q(a,e){let t=e.split("."),s=[["*",a,a]],n="",i=a;for(let r=0;r<t.length;r++)n+=(r===0?"":".")+t[r],s.push([n,i,i=i?.[t[r]]]);return s}function Y(a){let e=a;for(;e&&e!==Object.prototype;){for(let t of Object.getOwnPropertyNames(e)){if(t==="constructor")continue;let s=Object.getOwnPropertyDescriptor(e,t);typeof s?.value!="function"&&(s?.get||s?.set||(e[t]=null))}e=Object.getPrototypeOf(e)}}var L=Symbol.for("S.I.A_RAW"),D=Symbol.for("S.I.A_INERTIA"),B=Symbol.for("S.I.A_REJECTABLE"),$=Symbol.for("S.I.A_INDIFFABLE"),k=Symbol.for("S.I.A_TERMINATOR"),N=Symbol.for("S.I.A_VERSION"),H=Symbol.for("S.I.A_SNAPSHOT_VERSION"),Z=()=>{},Re=(typeof queueMicrotask<"u"?queueMicrotask:setTimeout).bind(window),ee=console.log.bind(console,"[S.I.A Reactor]"),te=console.warn.bind(console,"[S.I.A Event]"),I={LISTENER:["capture","depth","once","signal","immediate"],MEDIATOR:["lazy","signal","immediate"]},A=class A{constructor(e,t=!1,s=!0){this.eventPhase=A.NONE;this._propagationStopped=!1;this._immediatePropagationStopped=!1;this._resolved="";this._rejected="";this._warn=Z;this.type=this.staticType=e.type,this.target=e.target,this.currentTarget=e.currentTarget,this.root=e.root,this.value=e.target.value,this.oldValue=e.target.oldValue,this.path=e.target.path,this.rejectable=e.rejectable,this.bubbles=t,s&&(this._warn=te)}get propagationStopped(){return this._propagationStopped}stopPropagation(){this._propagationStopped=!0}get immediatePropagationStopped(){return this._immediatePropagationStopped}stopImmediatePropagation(){this._propagationStopped=!0,this._immediatePropagationStopped=!0}get resolved(){return this._resolved}resolve(e){if(!this.rejectable)return this._warn(`Ignored resolve() call on a non-rejectable ${this.staticType} at "${this.path}"`);this.eventPhase!==A.CAPTURING_PHASE&&this._warn(`Resolving an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`),this.rejectable&&(this._resolved=e||`Could ${this.staticType} intended value at "${this.path}"`)}get rejected(){return this._rejected}reject(e){if(!this.rejectable)return this._warn(`Ignored reject() call on a non-rejectable ${this.staticType} at "${this.path}"`);this.eventPhase!==A.CAPTURING_PHASE&&this._warn(`Rejecting an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`),this.rejectable&&(this._rejected=e||`Couldn't ${this.staticType} intended value at "${this.path}"`)}composedPath(){return J(this.path)}get canWarn(){return this._warn===te}};A.NONE=0,A.CAPTURING_PHASE=1,A.AT_TARGET=2,A.BUBBLING_PHASE=3;var v=A,V=class{constructor(e={},t){this.proxyCache=new WeakMap;this.log=Z;this.isLogging=!1;this.isTracing=!1;this.isTracking=!1;this.isSCloning=!1;this.isBatching=!1;this[D]=!0,this.config={crossRealms:!1,eventBubbling:!0,batchingFunction:Re,...t},this.core=this.proxied(e),t&&(this.canLog=!!t.debug,(this.isTracking=!!t.referenceTracking)&&(this.lineage=new WeakMap),(this.isSCloning=this.isTracking&&!!t.smartCloning)&&(this.snapshotCache=new WeakMap),this.isTracing=this.isTracking&&!!t.lineageTracing)}proxied(e,t=!1,s=!1,n,i,r){if(!e||typeof e!="object"||!(W(e,this.config.crossRealms,!1)||Array.isArray(e))||e[D])return e;if(e=e[L]||e,this.isTracking&&n&&i&&this.link(e,n,i,!1),this.proxyCache.has(e))return this.proxyCache.get(e);t||(t=e[B]),s||(s=e[$]);let c=new Proxy(e,{get:(h,o,l)=>{if(o===L)return h;let d=h[o],u=String(o),T=this.isTracing?void 0:r?r+"."+u:u,y=this.isTracing?this.trace(h,u):T;if(this.log(`\u{1F440} [GET Trap] Initiated for "${u}" on "${y}"`),this.config.get&&(d=this.config.get(h,o,d,l,y)),this.getters){let f=this.getters.get("*");for(let g=0,S=this.isTracing?y.length:1;g<S;g++){let p=this.isTracing?y[g]:T,x=this.getters.get(p);if(!x&&!f)continue;let P={path:p,value:d,key:u,object:l},b={type:"get",target:P,currentTarget:P,root:this.core,rejectable:t};x&&(d=this.mediate(p,b,"get",x)),f&&(P.value=d,d=this.mediate("*",b,"get",f))}}return this.proxied(d,t,s,h,u,T)},set:(h,o,l,d)=>{let u,T,y,f=!1,g=String(o),S=this.isTracing?void 0:r?r+"."+g:g,p=this.isTracing?this.trace(h,g):S,x=this.isTracing?p.length:1,P=h[o];if((this.isTracking||!s)&&(y=P?.[L]||P,T=l?.[L]||l,u=Object.is(T,y)),!s&&u)return!0;if(this.log(`\u270F\uFE0F [SET Trap] Initiated for "${g}" on "${p}"`),this.config.set&&(f=(l=this.config.set(h,o,l,P,d,p))===k),this.setters){let b=this.setters.get("*");for(let O=0;O<x;O++){let R=this.isTracking?p[O]:S,j=this.setters.get(R);if(!j&&!b)continue;let C={path:R,value:l,oldValue:P,key:g,object:d},K={type:"set",target:C,currentTarget:C,root:this.core,terminated:f,rejectable:t};if(j){let pe=this.mediate(R,K,"set",j);f||(f=K.terminated)||(l=pe)}if(!b)continue;C.value=l;let fe=this.mediate("*",K,"set",b);f||(f=K.terminated)||(l=fe)}}if(f)return this.log(`\u{1F6E1}\uFE0F [SET Mediator] Terminated on "${p}"`),!0;if(h[o]=l,this.isTracking&&!u&&(this.isSCloning&&this.stamp(h),this.unlink(y,h,g),this.link(T,h,g)),this.watchers||this.listeners)for(let b=0;b<x;b++){let O=this.isTracking?p[b]:S,R={path:O,value:l,oldValue:P,key:g,object:d};this.notify(O,{type:"set",target:R,currentTarget:R,root:this.core,terminated:f,rejectable:t})}return!0},deleteProperty:(h,o)=>{let l,d=this.proxyCache.get(h),u=!1,T=String(o),y=this.isTracing?void 0:r?r+"."+T:T,f=this.isTracing?this.trace(h,T):y,g=this.isTracing?f.length:1,S=h[o];if(this.log(`\u{1F5D1}\uFE0F [DELETE Trap] Initiated for "${T}" on "${f}"`),this.config.delete&&(u=(l=this.config.delete(h,o,S,d,f))===k),this.deleters){let p=this.deleters.get("*");for(let x=0;x<g;x++){let P=this.isTracking?f[x]:y,b=this.deleters.get(P);if(!b&&!p)continue;let O={path:P,value:l,oldValue:S,key:T,object:d},R={type:"delete",target:O,currentTarget:O,root:this.core,rejectable:t};if(b){let C=this.mediate(P,R,"delete",b);u||(u=R.terminated)||(l=C)}if(!p)continue;let j=this.mediate("*",R,"delete",p);u||(u=R.terminated)||(l=j)}}if(u)return this.log(`\u{1F6E1}\uFE0F [DELETE Mediator] Terminated on "${f}"`),!0;if(delete h[o],this.isTracking&&(this.isSCloning&&this.stamp(h),this.unlink(S?.[L]||S,h,T)),this.watchers||this.listeners)for(let p=0;p<g;p++){let x=this.isTracking?f[p]:y,P={path:x,value:l,oldValue:S,key:T,object:d};this.notify(x,{type:"delete",target:P,currentTarget:P,root:this.core,rejectable:t})}return!0}});return this.proxyCache.set(e,c),c}trace(e,t,s=[],n=new WeakSet){if(Object.is(e,this.core[L]||this.core))return s.push(t),s;if(n.has(e))return s;n.add(e);let i=this.lineage.get(e);if(!i)return s;for(let r=0,c=i.length;r<c;r+=2)this.trace(i[r],i[r+1]?i[r+1]+"."+t:t,s,n);return s}link(e,t,s,n=!0,i){if(!(n&&!(W(e,this.config.crossRealms)||Array.isArray(e)))){i=this.lineage.get(e)??(this.lineage.set(e,i=[]),i);for(let r=0,c=i.length;r<c;r+=2)if(Object.is(i[r],t)&&i[r+1]===s)return;i.push(t,s)}}unlink(e,t,s){if(!(W(e,this.config.crossRealms)||Array.isArray(e)))return;let n=this.lineage.get(e);if(n){for(let i=0,r=n.length;i<r;i+=2)if(Object.is(n[i],t)&&n[i+1]===s)return void n.splice(i,2)}}stamp(e,t=!0){if(t&&typeof e!="object")return;e[N]=(e[N]||0)+1;let s=this.lineage?.get(e);if(s)for(let n=0,i=s.length;n<i;n+=2)this.stamp(s[n])}mediate(e,t,s,n){let i=!1,r=t.target.value,c=s==="get",h=s==="set",o=c?this.getters:h?this.setters:this.deleters;for(let l=c?n.length-1:0,d=c?-1:n.length;l!==d;l+=c?-1:1){let u=c?n[l].cb(r,t):h?n[l].cb(r,i,t):n[l].cb(i,t);(c||!(i||(i=t.terminated=u===k)))&&(r=u),n[l].once&&(n.splice(l--,1),!n.length&&o.delete(e))}return r}notify(e,t){if(this.watchers){let s=this.watchers.get("*"),n=this.watchers.get(e);if(n)for(let i=0,r=n.length;i<r;i++)n[i].cb(t.target.value,t),n[i].once&&(n.splice(i--,1),!n.length&&this.watchers.delete(e));if(s)for(let i=0,r=s.length;i<r;i++)s[i].cb(t.target.value,t),s[i].once&&(s.splice(i--,1),!s.length&&this.watchers.delete("*"))}this.listeners&&this.schedule(e,t)}schedule(e,t){this.batch??(this.batch=new Map),this.batch.set(e,t),!this.isBatching&&this.initBatching()}initBatching(){this.isBatching=!0,this.config.batchingFunction(()=>this.flush())}flush(){if(this.isBatching=!1,this.batch&&this.tick(this.batch.keys()),this.queue?.size)for(let e of this.queue)e(),this.queue.delete(e)}wave(e,t){let s=new v(t,this.config.eventBubbling,this.isLogging),n=Q(this.core,e);s.eventPhase=v.CAPTURING_PHASE;for(let i=0;i<=n.length-2&&!s.propagationStopped;i++)this.fire(n[i],s,!0);if(!s.propagationStopped&&(s.eventPhase=v.AT_TARGET,this.fire(n[n.length-1],s,!0),!s.immediatePropagationStopped&&this.fire(n[n.length-1],s,!1),!!s.bubbles)){s.eventPhase=v.BUBBLING_PHASE;for(let i=n.length-2;i>=0&&!s.propagationStopped;i--)this.fire(n[i],s,!1)}}fire([e,t,s],n,i,r=this.listeners.get(e)){if(!r)return;n.type=e!==n.target.path?"update":n.staticType,n.currentTarget={path:e,value:s,oldValue:n.type!=="update"?n.target.oldValue:void 0,key:n.type!=="update"?e:e.slice(e.lastIndexOf(".")+1)||"",object:t};let c,h;for(let o=0,l=r.length;o<l&&!n.immediatePropagationStopped;o++)r[o].capture===i&&(r[o].depth!==void 0&&(c??(c=this.getDepth(n.target.path)),h??(h=this.getDepth(e)),c>h+r[o].depth)||(r[o].cb(n),r[o].once&&(r.splice(o--,1),!r.length&&this.listeners.delete(e))))}tick(e){if(!e)return this.flush();if(typeof e=="string"){let t=this.batch?.get(e);t&&(this.wave(e,t),this.batch.delete(e))}else for(let t of e){let s=this.batch.get(t);s&&(this.wave(t,s),this.batch.delete(t))}}stall(e){this.queue??(this.queue=new Set),this.queue.add(e),!this.isBatching&&this.initBatching()}nostall(e){return this.queue?.delete(e)}bind(e,t){return t?.aborted?e.clup():t?.addEventListener("abort",e.clup,{once:!0}),t&&!t.aborted&&(e.sclup=()=>t.removeEventListener("abort",e.clup)),e.clup}clone(e,t,s=new WeakMap){if(!(W(e,this.config.crossRealms)||Array.isArray(e))||s.has(e))return e;let n=e[N]||0,i=!t&&this.isSCloning&&this.snapshotCache.get(e);if(i&&e[H]===n)return i;let r=t?e[L]||e:Array.isArray(e)?[]:{};s.set(e,r);let c=Object.keys(e);for(let h=0,o=c.length;h<o;h++)r[c[h]]=this.clone(e[c[h]],t,s);return!t&&this.isSCloning&&(this.snapshotCache.set(e,r),e[H]=n),r}getDepth(e,t=e?1:0){for(let s=0,n=e.length;s<n;s++)e.charCodeAt(s)===46&&t++;return t}getContext(e){let t=e.lastIndexOf("."),s=e==="*"?this.core:M(this.core,e),n=t===-1?this.core:M(this.core,e.slice(0,t));return{path:e,value:s,key:e.slice(t+1)||"",object:n}}syncAdd(e,t,s,n,i){var y;let{lazy:r=!1,once:c=!1,signal:h,immediate:o=!1}=m(n,I.MEDIATOR),l=this[y=`${e}${e.endsWith("t")?"t":""}ers`]??(this[y]=new Map),d=l.get(t),u;if(d){for(let f=0,g=d.length;f<g;f++)if(Object.is(d[f].cb,s)){u=d[f];break}}if(u)return u.clup;let T;return u={cb:s,once:c,clup:()=>(r&&this.nostall(T),this[`no${e}`](t,s))},o&&i?.(o),T=()=>(d??(l.set(t,d=[]),d)).push(u),r?this.stall(T):T(),this.bind(u,h)}syncDrop(e,t,s){let n=e?.get(t);if(n){for(let i=0,r=n.length;i<r;i++)if(Object.is(n[i].cb,s))return n[i].sclup?.(),n.splice(i--,1),!n.length&&e.delete(t),!0;return!1}}get(e,t,s){return this.syncAdd("get",e,t,s,n=>(n!=="auto"||w(this.core,e))&&M(this.core,e))}gonce(e,t,s){return this.get(e,t,{...m(s,I.MEDIATOR),once:!0})}noget(e,t){return this.syncDrop(this.getters,e,t)}set(e,t,s){return this.syncAdd("set",e,t,s,n=>(n!=="auto"||w(this.core,e))&&q(this.core,e,M(this.core,e)))}sonce(e,t,s){return this.set(e,t,Object.assign(m(s,I.MEDIATOR),{once:!0}))}noset(e,t){return this.syncDrop(this.setters,e,t)}delete(e,t,s){return this.syncAdd("delete",e,t,s,n=>(n!=="auto"||w(this.core,e))&&z(this.core,e,void 0))}donce(e,t,s){return this.delete(e,t,Object.assign(m(s,I.MEDIATOR),{once:!0}))}nodelete(e,t){return this.syncDrop(this.deleters,e,t)}watch(e,t,s){return this.syncAdd("watch",e,t,s,n=>n!=="auto"&&w(this.core,e)&&(i=>t(i.value,{type:"init",target:i,currentTarget:i,root:this.core,rejectable:!1}))(this.getContext(e)))}wonce(e,t,s){return this.watch(e,t,Object.assign(m(s,I.MEDIATOR),{once:!0}))}nowatch(e,t){return this.syncDrop(this.watchers,e,t)}on(e,t,s){this.listeners??(this.listeners=new Map);let{capture:n=!1,once:i=!1,signal:r,immediate:c=!1,depth:h}=m(s,I.LISTENER),o=this.listeners.get(e),l;if(o){for(let d=0,u=o.length;d<u;d++)if(Object.is(o[d].cb,t)&&n===o[d].capture){l=o[d];break}}if(l)return l.clup;if(l={cb:t,capture:n,depth:h,once:i,clup:()=>this.off(e,t,s)},c&&(c!=="auto"||w(this.core,e))){let d=this.getContext(e);t(new v({type:"init",target:d,currentTarget:d,root:this.core,rejectable:!1},this.config.eventBubbling,this.isLogging))}return(o??(this.listeners.set(e,o=[]),o)).push(l),this.bind(l,r)}once(e,t,s){return this.on(e,t,Object.assign(m(s,I.LISTENER),{once:!0}))}off(e,t,s){let n=this.listeners?.get(e);if(!n)return;let{capture:i}=m(s,I.LISTENER);for(let r=0,c=n.length;r<c;r++)if(Object.is(n[r].cb,t)&&n[r].capture===i)return n[r].sclup?.(),n.splice(r--,1),!n.length&&this.listeners.delete(e),!0;return!1}snapshot(e=!this.isSCloning,t=this.core){return this.clone(t,e)}cascade({type:e,currentTarget:{path:t,value:s,oldValue:n}},i=!0){if(e!=="set"&&e!=="delete"||!(W(s,this.config.crossRealms)||Array.isArray(s))||i&&!(W(n,this.config.crossRealms)||Array.isArray(n)))return;let r=i?U(n,s):s,c=Object.keys(r);for(let h=0,o=c.length;h<o;h++)q(this.core,t+"."+c[h],r[c[h]])}reset(){this.getters?.clear(),this.setters?.clear(),this.deleters?.clear(),this.watchers?.clear(),this.listeners?.clear(),this.queue?.clear(),this.batch?.clear(),this.isBatching=!1,this.proxyCache=new WeakMap}destroy(){this.reset(),Y(this)}get canLog(){return this.log===ee}set canLog(e){this.log=(this.isLogging=e)?ee:Z}get canTrackReferences(){return this.isTracking}get canTraceLineage(){return this.isTracing}get canSmartClone(){return this.isSCloning}};var F=["tick","stall","nostall","get","gonce","noget","set","sonce","noset","delete","donce","nodelete","watch","wonce","nowatch","on","once","off","cascade","snapshot","reset","destroy"];function se(a,e,t){let s={},n=a instanceof V?a:new V(a,e),i={enumerable:!1,configurable:!0,writable:!1},r=!!(t?.prefix||t?.suffix);for(let c of F){if(r)(t?.whitelist?.includes(c)??!0)&&(c=`${t?.prefix||""}${c}${t?.suffix||""}`);else if(t?.whitelist?.includes(c))continue;s[c]={value:n[c].bind(n),...i}}return s.__Reactor__={value:n,...i},Object.defineProperties(n.core,s),n.core}function ne(a){return a[D]=!0,a}function ie(a){return delete a[D],a}function re(a){return!!a[D]}function ae(a){return a[B]=!0,a}function oe(a){return delete a[B],a}function ce(a){return!!a[B]}function le(a){return a[$]=!0,a}function he(a){return delete a[$],a}function de(a){return!!a[$]}function ue(a){return a[N]||0}function Te(a){return a[H]||0}0&&(module.exports={Reactor,ReactorEvent,TERMINATOR,getSnapshotVersion,getVersion,inert,intent,isInert,isIntent,isVolatile,live,methods,reactive,stable,state,volatile});
package/dist/index.d.cts CHANGED
@@ -1 +1 @@
1
- export { N as Payload, R as REvent, a4 as Reactive, a5 as ReactivePrefs, a6 as Reactor, a7 as ReactorEvent, O as ReactorOptions, a8 as getSnapshotVersion, a9 as getVersion, aa as inert, ab as intent, ac as isInert, ad as isIntent, ae as isVolatile, af as live, ag as methods, ah as reactive, ai as stable, aj as state, ak as volatile } from './index-DBfVdpnb.cjs';
1
+ export { C as ChildPaths, D as DeepKeys, a as DeepMerge, b as DeepPartial, c as DeepRequired, d as Deleter, e as DeleterRecord, f as DirectPayload, G as Getter, g as GetterRecord, I as Inert, h as Intent, L as Listener, i as ListenerOptions, j as ListenerOptionsTuple, k as ListenerRecord, l as Live, P as PathBranch, m as PathBranchValue, n as PathKey, o as PathLeaf, p as PathValue, q as Paths, r as Payload, R as REvent, s as Reactive, t as ReactivePrefs, u as Reactor, v as ReactorEvent, w as ReactorOptions, S as Setter, x as SetterRecord, y as Stable, z as State, A as StrictPathKey, B as SyncOptions, E as SyncOptionsTuple, T as TERMINATOR, F as Target, U as Unflatten, H as UnionToIntersection, J as UpdatePayload, V as Volatile, W as Watcher, K as WatcherRecord, M as WildPaths, N as getSnapshotVersion, O as getVersion, Q as inert, X as intent, Y as isInert, Z as isIntent, _ as isVolatile, $ as live, a0 as methods, a1 as reactive, a2 as stable, a3 as state, a4 as volatile } from './utils.cjs';
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { N as Payload, R as REvent, a4 as Reactive, a5 as ReactivePrefs, a6 as Reactor, a7 as ReactorEvent, O as ReactorOptions, a8 as getSnapshotVersion, a9 as getVersion, aa as inert, ab as intent, ac as isInert, ad as isIntent, ae as isVolatile, af as live, ag as methods, ah as reactive, ai as stable, aj as state, ak as volatile } from './index-DBfVdpnb.js';
1
+ export { C as ChildPaths, D as DeepKeys, a as DeepMerge, b as DeepPartial, c as DeepRequired, d as Deleter, e as DeleterRecord, f as DirectPayload, G as Getter, g as GetterRecord, I as Inert, h as Intent, L as Listener, i as ListenerOptions, j as ListenerOptionsTuple, k as ListenerRecord, l as Live, P as PathBranch, m as PathBranchValue, n as PathKey, o as PathLeaf, p as PathValue, q as Paths, r as Payload, R as REvent, s as Reactive, t as ReactivePrefs, u as Reactor, v as ReactorEvent, w as ReactorOptions, S as Setter, x as SetterRecord, y as Stable, z as State, A as StrictPathKey, B as SyncOptions, E as SyncOptionsTuple, T as TERMINATOR, F as Target, U as Unflatten, H as UnionToIntersection, J as UpdatePayload, V as Volatile, W as Watcher, K as WatcherRecord, M as WildPaths, N as getSnapshotVersion, O as getVersion, Q as inert, X as intent, Y as isInert, Z as isIntent, _ as isVolatile, $ as live, a0 as methods, a1 as reactive, a2 as stable, a3 as state, a4 as volatile } from './utils.js';
@@ -0,0 +1 @@
1
+ "use strict";var sia=(()=>{var X=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var be=(a,e)=>{for(var t in e)X(a,t,{get:e[t],enumerable:!0})},xe=(a,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Pe(e))!ye.call(a,n)&&n!==t&&X(a,n,{get:()=>e[n],enumerable:!(s=ge(e,n))||s.enumerable});return a};var Se=a=>xe(X({},"__esModule",{value:!0}),a);var me={};be(me,{Reactor:()=>V,ReactorEvent:()=>v,TERMINATOR:()=>k,getSnapshotVersion:()=>Te,getVersion:()=>ue,inert:()=>ne,intent:()=>ae,isInert:()=>re,isIntent:()=>ce,isVolatile:()=>de,live:()=>ie,methods:()=>F,reactive:()=>se,stable:()=>he,state:()=>oe,volatile:()=>le});var G=/^([^\[\]]+)\[(\d+)\]$/;function _(a){return Array.isArray(a)}function E(a,e=!0){return typeof a=="object"&&a!==null&&(e?!Array.isArray(a):!0)}function W(a,e=!1,t=!0){return(t?E(a,!1):!0)&&(e?Object.prototype.toString.call(a)==="[object Object]":a.constructor===Object)}function q(a,e,t,s=".",n){var c,h;if(!e.includes(s))return void(a[n?n(e):e]=t);let i=e.split(s),r=a;for(let o=0;o<i.length;o++){let l=n?n(i[o]):i[o],d=l.includes("[")&&l.match(G);if(d){let[,u,T]=d;_(r[u])||(r[u]=[]),o===i.length-1?r[u][Number(T)]=t:((c=r[u])[h=Number(T)]||(c[h]={}),r=r[u][Number(T)])}else o===i.length-1?r[l]=t:(r[l]||(r[l]={}),r=r[l])}}function M(a,e,t=".",s){if(!e.includes(t))return a[s?s(e):e];let n=e.split(t),i=a;for(let r=0;r<n.length;r++){let c=s?s(n[r]):n[r],h=c.includes("[")&&c.match(G);if(h){let[,o,l]=h;if(!_(i[o])||!(o in i))return;i=i[o][Number(l)]}else{if(!E(i)||!(c in i))return;i=i[c]}}return i}function z(a,e,t=".",s){if(!e.includes(t))return void delete a[s?s(e):e];let n=e.split(t),i=a;for(let r=0;r<n.length;r++){let c=s?s(n[r]):n[r],h=c.includes("[")&&c.match(G);if(h){let[,o,l]=h;if(!_(i[o])||!(o in i))return;r===n.length-1?delete i[o][Number(l)]:i=i[o][Number(l)]}else{if(!E(i)||!(c in i))return;r===n.length-1?delete i[c]:i=i[c]}}}function w(a,e,t=".",s){if(!e.includes(t))return e in a;let n=e.split(t),i=a;for(let r=0;r<n.length;r++){let c=s?s(n[r]):n[r],h=c.includes("[")&&c.match(G);if(h){let[,o,l]=h;if(!_(i[o])||!(o in i))return!1;if(r===n.length-1)return!0;i=i[o][Number(l)]}else{if(!E(i)||!(c in i))return!1;if(r===n.length-1)return!0;i=i[c]}}return!0}function m(a,e,t=e[0],s={}){return Object.assign(s,typeof a=="boolean"?{[t]:a}:a),s}function U(a={},e={}){let t={...a||{},...e||{}};return Object.keys(t).forEach(s=>E(a?.[s])&&E(e?.[s])&&(t[s]=U(a[s],e[s]))),t}function J(a,e=!0){let t=a.split("."),s=["*"],n="";for(let i=0;i<t.length;i++)n+=(i===0?"":".")+t[i],s.push(n);return e?s.reverse():s}function Q(a,e){let t=e.split("."),s=[["*",a,a]],n="",i=a;for(let r=0;r<t.length;r++)n+=(r===0?"":".")+t[r],s.push([n,i,i=i?.[t[r]]]);return s}function Y(a){let e=a;for(;e&&e!==Object.prototype;){for(let t of Object.getOwnPropertyNames(e)){if(t==="constructor")continue;let s=Object.getOwnPropertyDescriptor(e,t);typeof s?.value!="function"&&(s?.get||s?.set||(e[t]=null))}e=Object.getPrototypeOf(e)}}var L=Symbol.for("S.I.A_RAW"),D=Symbol.for("S.I.A_INERTIA"),B=Symbol.for("S.I.A_REJECTABLE"),$=Symbol.for("S.I.A_INDIFFABLE"),k=Symbol.for("S.I.A_TERMINATOR"),N=Symbol.for("S.I.A_VERSION"),H=Symbol.for("S.I.A_SNAPSHOT_VERSION"),Z=()=>{},Re=(typeof queueMicrotask<"u"?queueMicrotask:setTimeout).bind(window),ee=console.log.bind(console,"[S.I.A Reactor]"),te=console.warn.bind(console,"[S.I.A Event]"),I={LISTENER:["capture","depth","once","signal","immediate"],MEDIATOR:["lazy","signal","immediate"]},A=class A{constructor(e,t=!1,s=!0){this.eventPhase=A.NONE;this._propagationStopped=!1;this._immediatePropagationStopped=!1;this._resolved="";this._rejected="";this._warn=Z;this.type=this.staticType=e.type,this.target=e.target,this.currentTarget=e.currentTarget,this.root=e.root,this.value=e.target.value,this.oldValue=e.target.oldValue,this.path=e.target.path,this.rejectable=e.rejectable,this.bubbles=t,s&&(this._warn=te)}get propagationStopped(){return this._propagationStopped}stopPropagation(){this._propagationStopped=!0}get immediatePropagationStopped(){return this._immediatePropagationStopped}stopImmediatePropagation(){this._propagationStopped=!0,this._immediatePropagationStopped=!0}get resolved(){return this._resolved}resolve(e){if(!this.rejectable)return this._warn(`Ignored resolve() call on a non-rejectable ${this.staticType} at "${this.path}"`);this.eventPhase!==A.CAPTURING_PHASE&&this._warn(`Resolving an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`),this.rejectable&&(this._resolved=e||`Could ${this.staticType} intended value at "${this.path}"`)}get rejected(){return this._rejected}reject(e){if(!this.rejectable)return this._warn(`Ignored reject() call on a non-rejectable ${this.staticType} at "${this.path}"`);this.eventPhase!==A.CAPTURING_PHASE&&this._warn(`Rejecting an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`),this.rejectable&&(this._rejected=e||`Couldn't ${this.staticType} intended value at "${this.path}"`)}composedPath(){return J(this.path)}get canWarn(){return this._warn===te}};A.NONE=0,A.CAPTURING_PHASE=1,A.AT_TARGET=2,A.BUBBLING_PHASE=3;var v=A,V=class{constructor(e={},t){this.proxyCache=new WeakMap;this.log=Z;this.isLogging=!1;this.isTracing=!1;this.isTracking=!1;this.isSCloning=!1;this.isBatching=!1;this[D]=!0,this.config={crossRealms:!1,eventBubbling:!0,batchingFunction:Re,...t},this.core=this.proxied(e),t&&(this.canLog=!!t.debug,(this.isTracking=!!t.referenceTracking)&&(this.lineage=new WeakMap),(this.isSCloning=this.isTracking&&!!t.smartCloning)&&(this.snapshotCache=new WeakMap),this.isTracing=this.isTracking&&!!t.lineageTracing)}proxied(e,t=!1,s=!1,n,i,r){if(!e||typeof e!="object"||!(W(e,this.config.crossRealms,!1)||Array.isArray(e))||e[D])return e;if(e=e[L]||e,this.isTracking&&n&&i&&this.link(e,n,i,!1),this.proxyCache.has(e))return this.proxyCache.get(e);t||(t=e[B]),s||(s=e[$]);let c=new Proxy(e,{get:(h,o,l)=>{if(o===L)return h;let d=h[o],u=String(o),T=this.isTracing?void 0:r?r+"."+u:u,y=this.isTracing?this.trace(h,u):T;if(this.log(`\u{1F440} [GET Trap] Initiated for "${u}" on "${y}"`),this.config.get&&(d=this.config.get(h,o,d,l,y)),this.getters){let f=this.getters.get("*");for(let g=0,S=this.isTracing?y.length:1;g<S;g++){let p=this.isTracing?y[g]:T,x=this.getters.get(p);if(!x&&!f)continue;let P={path:p,value:d,key:u,object:l},b={type:"get",target:P,currentTarget:P,root:this.core,rejectable:t};x&&(d=this.mediate(p,b,"get",x)),f&&(P.value=d,d=this.mediate("*",b,"get",f))}}return this.proxied(d,t,s,h,u,T)},set:(h,o,l,d)=>{let u,T,y,f=!1,g=String(o),S=this.isTracing?void 0:r?r+"."+g:g,p=this.isTracing?this.trace(h,g):S,x=this.isTracing?p.length:1,P=h[o];if((this.isTracking||!s)&&(y=P?.[L]||P,T=l?.[L]||l,u=Object.is(T,y)),!s&&u)return!0;if(this.log(`\u270F\uFE0F [SET Trap] Initiated for "${g}" on "${p}"`),this.config.set&&(f=(l=this.config.set(h,o,l,P,d,p))===k),this.setters){let b=this.setters.get("*");for(let O=0;O<x;O++){let R=this.isTracking?p[O]:S,j=this.setters.get(R);if(!j&&!b)continue;let C={path:R,value:l,oldValue:P,key:g,object:d},K={type:"set",target:C,currentTarget:C,root:this.core,terminated:f,rejectable:t};if(j){let pe=this.mediate(R,K,"set",j);f||(f=K.terminated)||(l=pe)}if(!b)continue;C.value=l;let fe=this.mediate("*",K,"set",b);f||(f=K.terminated)||(l=fe)}}if(f)return this.log(`\u{1F6E1}\uFE0F [SET Mediator] Terminated on "${p}"`),!0;if(h[o]=l,this.isTracking&&!u&&(this.isSCloning&&this.stamp(h),this.unlink(y,h,g),this.link(T,h,g)),this.watchers||this.listeners)for(let b=0;b<x;b++){let O=this.isTracking?p[b]:S,R={path:O,value:l,oldValue:P,key:g,object:d};this.notify(O,{type:"set",target:R,currentTarget:R,root:this.core,terminated:f,rejectable:t})}return!0},deleteProperty:(h,o)=>{let l,d=this.proxyCache.get(h),u=!1,T=String(o),y=this.isTracing?void 0:r?r+"."+T:T,f=this.isTracing?this.trace(h,T):y,g=this.isTracing?f.length:1,S=h[o];if(this.log(`\u{1F5D1}\uFE0F [DELETE Trap] Initiated for "${T}" on "${f}"`),this.config.delete&&(u=(l=this.config.delete(h,o,S,d,f))===k),this.deleters){let p=this.deleters.get("*");for(let x=0;x<g;x++){let P=this.isTracking?f[x]:y,b=this.deleters.get(P);if(!b&&!p)continue;let O={path:P,value:l,oldValue:S,key:T,object:d},R={type:"delete",target:O,currentTarget:O,root:this.core,rejectable:t};if(b){let C=this.mediate(P,R,"delete",b);u||(u=R.terminated)||(l=C)}if(!p)continue;let j=this.mediate("*",R,"delete",p);u||(u=R.terminated)||(l=j)}}if(u)return this.log(`\u{1F6E1}\uFE0F [DELETE Mediator] Terminated on "${f}"`),!0;if(delete h[o],this.isTracking&&(this.isSCloning&&this.stamp(h),this.unlink(S?.[L]||S,h,T)),this.watchers||this.listeners)for(let p=0;p<g;p++){let x=this.isTracking?f[p]:y,P={path:x,value:l,oldValue:S,key:T,object:d};this.notify(x,{type:"delete",target:P,currentTarget:P,root:this.core,rejectable:t})}return!0}});return this.proxyCache.set(e,c),c}trace(e,t,s=[],n=new WeakSet){if(Object.is(e,this.core[L]||this.core))return s.push(t),s;if(n.has(e))return s;n.add(e);let i=this.lineage.get(e);if(!i)return s;for(let r=0,c=i.length;r<c;r+=2)this.trace(i[r],i[r+1]?i[r+1]+"."+t:t,s,n);return s}link(e,t,s,n=!0,i){if(!(n&&!(W(e,this.config.crossRealms)||Array.isArray(e)))){i=this.lineage.get(e)??(this.lineage.set(e,i=[]),i);for(let r=0,c=i.length;r<c;r+=2)if(Object.is(i[r],t)&&i[r+1]===s)return;i.push(t,s)}}unlink(e,t,s){if(!(W(e,this.config.crossRealms)||Array.isArray(e)))return;let n=this.lineage.get(e);if(n){for(let i=0,r=n.length;i<r;i+=2)if(Object.is(n[i],t)&&n[i+1]===s)return void n.splice(i,2)}}stamp(e,t=!0){if(t&&typeof e!="object")return;e[N]=(e[N]||0)+1;let s=this.lineage?.get(e);if(s)for(let n=0,i=s.length;n<i;n+=2)this.stamp(s[n])}mediate(e,t,s,n){let i=!1,r=t.target.value,c=s==="get",h=s==="set",o=c?this.getters:h?this.setters:this.deleters;for(let l=c?n.length-1:0,d=c?-1:n.length;l!==d;l+=c?-1:1){let u=c?n[l].cb(r,t):h?n[l].cb(r,i,t):n[l].cb(i,t);(c||!(i||(i=t.terminated=u===k)))&&(r=u),n[l].once&&(n.splice(l--,1),!n.length&&o.delete(e))}return r}notify(e,t){if(this.watchers){let s=this.watchers.get("*"),n=this.watchers.get(e);if(n)for(let i=0,r=n.length;i<r;i++)n[i].cb(t.target.value,t),n[i].once&&(n.splice(i--,1),!n.length&&this.watchers.delete(e));if(s)for(let i=0,r=s.length;i<r;i++)s[i].cb(t.target.value,t),s[i].once&&(s.splice(i--,1),!s.length&&this.watchers.delete("*"))}this.listeners&&this.schedule(e,t)}schedule(e,t){this.batch??(this.batch=new Map),this.batch.set(e,t),!this.isBatching&&this.initBatching()}initBatching(){this.isBatching=!0,this.config.batchingFunction(()=>this.flush())}flush(){if(this.isBatching=!1,this.batch&&this.tick(this.batch.keys()),this.queue?.size)for(let e of this.queue)e(),this.queue.delete(e)}wave(e,t){let s=new v(t,this.config.eventBubbling,this.isLogging),n=Q(this.core,e);s.eventPhase=v.CAPTURING_PHASE;for(let i=0;i<=n.length-2&&!s.propagationStopped;i++)this.fire(n[i],s,!0);if(!s.propagationStopped&&(s.eventPhase=v.AT_TARGET,this.fire(n[n.length-1],s,!0),!s.immediatePropagationStopped&&this.fire(n[n.length-1],s,!1),!!s.bubbles)){s.eventPhase=v.BUBBLING_PHASE;for(let i=n.length-2;i>=0&&!s.propagationStopped;i--)this.fire(n[i],s,!1)}}fire([e,t,s],n,i,r=this.listeners.get(e)){if(!r)return;n.type=e!==n.target.path?"update":n.staticType,n.currentTarget={path:e,value:s,oldValue:n.type!=="update"?n.target.oldValue:void 0,key:n.type!=="update"?e:e.slice(e.lastIndexOf(".")+1)||"",object:t};let c,h;for(let o=0,l=r.length;o<l&&!n.immediatePropagationStopped;o++)r[o].capture===i&&(r[o].depth!==void 0&&(c??(c=this.getDepth(n.target.path)),h??(h=this.getDepth(e)),c>h+r[o].depth)||(r[o].cb(n),r[o].once&&(r.splice(o--,1),!r.length&&this.listeners.delete(e))))}tick(e){if(!e)return this.flush();if(typeof e=="string"){let t=this.batch?.get(e);t&&(this.wave(e,t),this.batch.delete(e))}else for(let t of e){let s=this.batch.get(t);s&&(this.wave(t,s),this.batch.delete(t))}}stall(e){this.queue??(this.queue=new Set),this.queue.add(e),!this.isBatching&&this.initBatching()}nostall(e){return this.queue?.delete(e)}bind(e,t){return t?.aborted?e.clup():t?.addEventListener("abort",e.clup,{once:!0}),t&&!t.aborted&&(e.sclup=()=>t.removeEventListener("abort",e.clup)),e.clup}clone(e,t,s=new WeakMap){if(!(W(e,this.config.crossRealms)||Array.isArray(e))||s.has(e))return e;let n=e[N]||0,i=!t&&this.isSCloning&&this.snapshotCache.get(e);if(i&&e[H]===n)return i;let r=t?e[L]||e:Array.isArray(e)?[]:{};s.set(e,r);let c=Object.keys(e);for(let h=0,o=c.length;h<o;h++)r[c[h]]=this.clone(e[c[h]],t,s);return!t&&this.isSCloning&&(this.snapshotCache.set(e,r),e[H]=n),r}getDepth(e,t=e?1:0){for(let s=0,n=e.length;s<n;s++)e.charCodeAt(s)===46&&t++;return t}getContext(e){let t=e.lastIndexOf("."),s=e==="*"?this.core:M(this.core,e),n=t===-1?this.core:M(this.core,e.slice(0,t));return{path:e,value:s,key:e.slice(t+1)||"",object:n}}syncAdd(e,t,s,n,i){var y;let{lazy:r=!1,once:c=!1,signal:h,immediate:o=!1}=m(n,I.MEDIATOR),l=this[y=`${e}${e.endsWith("t")?"t":""}ers`]??(this[y]=new Map),d=l.get(t),u;if(d){for(let f=0,g=d.length;f<g;f++)if(Object.is(d[f].cb,s)){u=d[f];break}}if(u)return u.clup;let T;return u={cb:s,once:c,clup:()=>(r&&this.nostall(T),this[`no${e}`](t,s))},o&&i?.(o),T=()=>(d??(l.set(t,d=[]),d)).push(u),r?this.stall(T):T(),this.bind(u,h)}syncDrop(e,t,s){let n=e?.get(t);if(n){for(let i=0,r=n.length;i<r;i++)if(Object.is(n[i].cb,s))return n[i].sclup?.(),n.splice(i--,1),!n.length&&e.delete(t),!0;return!1}}get(e,t,s){return this.syncAdd("get",e,t,s,n=>(n!=="auto"||w(this.core,e))&&M(this.core,e))}gonce(e,t,s){return this.get(e,t,{...m(s,I.MEDIATOR),once:!0})}noget(e,t){return this.syncDrop(this.getters,e,t)}set(e,t,s){return this.syncAdd("set",e,t,s,n=>(n!=="auto"||w(this.core,e))&&q(this.core,e,M(this.core,e)))}sonce(e,t,s){return this.set(e,t,Object.assign(m(s,I.MEDIATOR),{once:!0}))}noset(e,t){return this.syncDrop(this.setters,e,t)}delete(e,t,s){return this.syncAdd("delete",e,t,s,n=>(n!=="auto"||w(this.core,e))&&z(this.core,e,void 0))}donce(e,t,s){return this.delete(e,t,Object.assign(m(s,I.MEDIATOR),{once:!0}))}nodelete(e,t){return this.syncDrop(this.deleters,e,t)}watch(e,t,s){return this.syncAdd("watch",e,t,s,n=>n!=="auto"&&w(this.core,e)&&(i=>t(i.value,{type:"init",target:i,currentTarget:i,root:this.core,rejectable:!1}))(this.getContext(e)))}wonce(e,t,s){return this.watch(e,t,Object.assign(m(s,I.MEDIATOR),{once:!0}))}nowatch(e,t){return this.syncDrop(this.watchers,e,t)}on(e,t,s){this.listeners??(this.listeners=new Map);let{capture:n=!1,once:i=!1,signal:r,immediate:c=!1,depth:h}=m(s,I.LISTENER),o=this.listeners.get(e),l;if(o){for(let d=0,u=o.length;d<u;d++)if(Object.is(o[d].cb,t)&&n===o[d].capture){l=o[d];break}}if(l)return l.clup;if(l={cb:t,capture:n,depth:h,once:i,clup:()=>this.off(e,t,s)},c&&(c!=="auto"||w(this.core,e))){let d=this.getContext(e);t(new v({type:"init",target:d,currentTarget:d,root:this.core,rejectable:!1},this.config.eventBubbling,this.isLogging))}return(o??(this.listeners.set(e,o=[]),o)).push(l),this.bind(l,r)}once(e,t,s){return this.on(e,t,Object.assign(m(s,I.LISTENER),{once:!0}))}off(e,t,s){let n=this.listeners?.get(e);if(!n)return;let{capture:i}=m(s,I.LISTENER);for(let r=0,c=n.length;r<c;r++)if(Object.is(n[r].cb,t)&&n[r].capture===i)return n[r].sclup?.(),n.splice(r--,1),!n.length&&this.listeners.delete(e),!0;return!1}snapshot(e=!this.isSCloning,t=this.core){return this.clone(t,e)}cascade({type:e,currentTarget:{path:t,value:s,oldValue:n}},i=!0){if(e!=="set"&&e!=="delete"||!(W(s,this.config.crossRealms)||Array.isArray(s))||i&&!(W(n,this.config.crossRealms)||Array.isArray(n)))return;let r=i?U(n,s):s,c=Object.keys(r);for(let h=0,o=c.length;h<o;h++)q(this.core,t+"."+c[h],r[c[h]])}reset(){this.getters?.clear(),this.setters?.clear(),this.deleters?.clear(),this.watchers?.clear(),this.listeners?.clear(),this.queue?.clear(),this.batch?.clear(),this.isBatching=!1,this.proxyCache=new WeakMap}destroy(){this.reset(),Y(this)}get canLog(){return this.log===ee}set canLog(e){this.log=(this.isLogging=e)?ee:Z}get canTrackReferences(){return this.isTracking}get canTraceLineage(){return this.isTracing}get canSmartClone(){return this.isSCloning}};var F=["tick","stall","nostall","get","gonce","noget","set","sonce","noset","delete","donce","nodelete","watch","wonce","nowatch","on","once","off","cascade","snapshot","reset","destroy"];function se(a,e,t){let s={},n=a instanceof V?a:new V(a,e),i={enumerable:!1,configurable:!0,writable:!1},r=!!(t?.prefix||t?.suffix);for(let c of F){if(r)(t?.whitelist?.includes(c)??!0)&&(c=`${t?.prefix||""}${c}${t?.suffix||""}`);else if(t?.whitelist?.includes(c))continue;s[c]={value:n[c].bind(n),...i}}return s.__Reactor__={value:n,...i},Object.defineProperties(n.core,s),n.core}function ne(a){return a[D]=!0,a}function ie(a){return delete a[D],a}function re(a){return!!a[D]}function ae(a){return a[B]=!0,a}function oe(a){return delete a[B],a}function ce(a){return!!a[B]}function le(a){return a[$]=!0,a}function he(a){return delete a[$],a}function de(a){return!!a[$]}function ue(a){return a[N]||0}function Te(a){return a[H]||0}return Se(me);})();
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{d as W,g as G,h as _,i as q,j as w,l as v,m as F,n as H,o as U,q as X}from"./chunk-5BPIJBLB.js";var E=Symbol.for("S.I.A_RAW"),k=Symbol.for("S.I.A_INERTIA"),D=Symbol.for("S.I.A_REJECTABLE"),$=Symbol.for("S.I.A_INDIFFABLE"),K=Symbol.for("S.I.A_TERMINATOR"),C=Symbol.for("S.I.A_VERSION"),N=Symbol.for("S.I.A_SNAPSHOT_VERSION"),j=()=>{},ee=(typeof queueMicrotask<"u"?queueMicrotask:setTimeout).bind(window),z=console.log.bind(console,"[S.I.A Reactor]"),J=console.warn.bind(console,"[S.I.A Event]"),O={LISTENER:["capture","depth","once","signal","immediate"],MEDIATOR:["lazy","signal","immediate"]},A=class A{constructor(e,t=!1,i=!0){this.eventPhase=A.NONE;this._propagationStopped=!1;this._immediatePropagationStopped=!1;this._resolved="";this._rejected="";this._warn=j;this.type=this.staticType=e.type,this.target=e.target,this.currentTarget=e.currentTarget,this.root=e.root,this.value=e.target.value,this.oldValue=e.target.oldValue,this.path=e.target.path,this.rejectable=e.rejectable,this.bubbles=t,i&&(this._warn=J)}get propagationStopped(){return this._propagationStopped}stopPropagation(){this._propagationStopped=!0}get immediatePropagationStopped(){return this._immediatePropagationStopped}stopImmediatePropagation(){this._propagationStopped=!0,this._immediatePropagationStopped=!0}get resolved(){return this._resolved}resolve(e){if(!this.rejectable)return this._warn(`Ignored resolve() call on a non-rejectable ${this.staticType} at "${this.path}"`);this.eventPhase!==A.CAPTURING_PHASE&&this._warn(`Resolving an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`),this.rejectable&&(this._resolved=e||`Could ${this.staticType} intended value at "${this.path}"`)}get rejected(){return this._rejected}reject(e){if(!this.rejectable)return this._warn(`Ignored reject() call on a non-rejectable ${this.staticType} at "${this.path}"`);this.eventPhase!==A.CAPTURING_PHASE&&this._warn(`Rejecting an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`),this.rejectable&&(this._rejected=e||`Couldn't ${this.staticType} intended value at "${this.path}"`)}composedPath(){return H(this.path)}get canWarn(){return this._warn===J}};A.NONE=0,A.CAPTURING_PHASE=1,A.AT_TARGET=2,A.BUBBLING_PHASE=3;var I=A,L=class{constructor(e={},t){this.proxyCache=new WeakMap;this.log=j;this.isLogging=!1;this.isTracing=!1;this.isTracking=!1;this.isSCloning=!1;this.isBatching=!1;this[k]=!0,this.config={crossRealms:!1,eventBubbling:!0,batchingFunction:ee,...t},this.core=this.proxied(e),t&&(this.canLog=!!t.debug,(this.isTracking=!!t.referenceTracking)&&(this.lineage=new WeakMap),(this.isSCloning=this.isTracking&&!!t.smartCloning)&&(this.snapshotCache=new WeakMap),this.isTracing=this.isTracking&&!!t.lineageTracing)}proxied(e,t=!1,i=!1,s,n,r){if(!e||typeof e!="object"||!(W(e,this.config.crossRealms,!1)||Array.isArray(e))||e[k])return e;if(e=e[E]||e,this.isTracking&&s&&n&&this.link(e,s,n,!1),this.proxyCache.has(e))return this.proxyCache.get(e);t||(t=e[D]),i||(i=e[$]);let l=new Proxy(e,{get:(a,o,c)=>{if(o===E)return a;let h=a[o],u=String(o),f=this.isTracing?void 0:r?r+"."+u:u,y=this.isTracing?this.trace(a,u):f;if(this.log(`\u{1F440} [GET Trap] Initiated for "${u}" on "${y}"`),this.config.get&&(h=this.config.get(a,o,h,c,y)),this.getters){let T=this.getters.get("*");for(let g=0,x=this.isTracing?y.length:1;g<x;g++){let P=this.isTracing?y[g]:f,R=this.getters.get(P);if(!R&&!T)continue;let p={path:P,value:h,key:u,object:c},b={type:"get",target:p,currentTarget:p,root:this.core,rejectable:t};R&&(h=this.mediate(P,b,"get",R)),T&&(p.value=h,h=this.mediate("*",b,"get",T))}}return this.proxied(h,t,i,a,u,f)},set:(a,o,c,h)=>{let u,f,y,T=!1,g=String(o),x=this.isTracing?void 0:r?r+"."+g:g,P=this.isTracing?this.trace(a,g):x,R=this.isTracing?P.length:1,p=a[o];if((this.isTracking||!i)&&(y=p?.[E]||p,f=c?.[E]||c,u=Object.is(f,y)),!i&&u)return!0;if(this.log(`\u270F\uFE0F [SET Trap] Initiated for "${g}" on "${P}"`),this.config.set&&(T=(c=this.config.set(a,o,c,p,h,P))===K),this.setters){let b=this.setters.get("*");for(let m=0;m<R;m++){let S=this.isTracking?P[m]:x,M=this.setters.get(S);if(!M&&!b)continue;let V={path:S,value:c,oldValue:p,key:g,object:h},B={type:"set",target:V,currentTarget:V,root:this.core,terminated:T,rejectable:t};if(M){let Z=this.mediate(S,B,"set",M);T||(T=B.terminated)||(c=Z)}if(!b)continue;V.value=c;let Y=this.mediate("*",B,"set",b);T||(T=B.terminated)||(c=Y)}}if(T)return this.log(`\u{1F6E1}\uFE0F [SET Mediator] Terminated on "${P}"`),!0;if(a[o]=c,this.isTracking&&!u&&(this.isSCloning&&this.stamp(a),this.unlink(y,a,g),this.link(f,a,g)),this.watchers||this.listeners)for(let b=0;b<R;b++){let m=this.isTracking?P[b]:x,S={path:m,value:c,oldValue:p,key:g,object:h};this.notify(m,{type:"set",target:S,currentTarget:S,root:this.core,terminated:T,rejectable:t})}return!0},deleteProperty:(a,o)=>{let c,h=this.proxyCache.get(a),u=!1,f=String(o),y=this.isTracing?void 0:r?r+"."+f:f,T=this.isTracing?this.trace(a,f):y,g=this.isTracing?T.length:1,x=a[o];if(this.log(`\u{1F5D1}\uFE0F [DELETE Trap] Initiated for "${f}" on "${T}"`),this.config.delete&&(u=(c=this.config.delete(a,o,x,h,T))===K),this.deleters){let P=this.deleters.get("*");for(let R=0;R<g;R++){let p=this.isTracking?T[R]:y,b=this.deleters.get(p);if(!b&&!P)continue;let m={path:p,value:c,oldValue:x,key:f,object:h},S={type:"delete",target:m,currentTarget:m,root:this.core,rejectable:t};if(b){let V=this.mediate(p,S,"delete",b);u||(u=S.terminated)||(c=V)}if(!P)continue;let M=this.mediate("*",S,"delete",P);u||(u=S.terminated)||(c=M)}}if(u)return this.log(`\u{1F6E1}\uFE0F [DELETE Mediator] Terminated on "${T}"`),!0;if(delete a[o],this.isTracking&&(this.isSCloning&&this.stamp(a),this.unlink(x?.[E]||x,a,f)),this.watchers||this.listeners)for(let P=0;P<g;P++){let R=this.isTracking?T[P]:y,p={path:R,value:c,oldValue:x,key:f,object:h};this.notify(R,{type:"delete",target:p,currentTarget:p,root:this.core,rejectable:t})}return!0}});return this.proxyCache.set(e,l),l}trace(e,t,i=[],s=new WeakSet){if(Object.is(e,this.core[E]||this.core))return i.push(t),i;if(s.has(e))return i;s.add(e);let n=this.lineage.get(e);if(!n)return i;for(let r=0,l=n.length;r<l;r+=2)this.trace(n[r],n[r+1]?n[r+1]+"."+t:t,i,s);return i}link(e,t,i,s=!0,n){if(!(s&&!(W(e,this.config.crossRealms)||Array.isArray(e)))){n=this.lineage.get(e)??(this.lineage.set(e,n=[]),n);for(let r=0,l=n.length;r<l;r+=2)if(Object.is(n[r],t)&&n[r+1]===i)return;n.push(t,i)}}unlink(e,t,i){if(!(W(e,this.config.crossRealms)||Array.isArray(e)))return;let s=this.lineage.get(e);if(s){for(let n=0,r=s.length;n<r;n+=2)if(Object.is(s[n],t)&&s[n+1]===i)return void s.splice(n,2)}}stamp(e,t=!0){if(t&&typeof e!="object")return;e[C]=(e[C]||0)+1;let i=this.lineage?.get(e);if(i)for(let s=0,n=i.length;s<n;s+=2)this.stamp(i[s])}mediate(e,t,i,s){let n=!1,r=t.target.value,l=i==="get",a=i==="set",o=l?this.getters:a?this.setters:this.deleters;for(let c=l?s.length-1:0,h=l?-1:s.length;c!==h;c+=l?-1:1){let u=l?s[c].cb(r,t):a?s[c].cb(r,n,t):s[c].cb(n,t);(l||!(n||(n=t.terminated=u===K)))&&(r=u),s[c].once&&(s.splice(c--,1),!s.length&&o.delete(e))}return r}notify(e,t){if(this.watchers){let i=this.watchers.get("*"),s=this.watchers.get(e);if(s)for(let n=0,r=s.length;n<r;n++)s[n].cb(t.target.value,t),s[n].once&&(s.splice(n--,1),!s.length&&this.watchers.delete(e));if(i)for(let n=0,r=i.length;n<r;n++)i[n].cb(t.target.value,t),i[n].once&&(i.splice(n--,1),!i.length&&this.watchers.delete("*"))}this.listeners&&this.schedule(e,t)}schedule(e,t){this.batch??(this.batch=new Map),this.batch.set(e,t),!this.isBatching&&this.initBatching()}initBatching(){this.isBatching=!0,this.config.batchingFunction(()=>this.flush())}flush(){if(this.isBatching=!1,this.batch&&this.tick(this.batch.keys()),this.queue?.size)for(let e of this.queue)e(),this.queue.delete(e)}wave(e,t){let i=new I(t,this.config.eventBubbling,this.isLogging),s=U(this.core,e);i.eventPhase=I.CAPTURING_PHASE;for(let n=0;n<=s.length-2&&!i.propagationStopped;n++)this.fire(s[n],i,!0);if(!i.propagationStopped&&(i.eventPhase=I.AT_TARGET,this.fire(s[s.length-1],i,!0),!i.immediatePropagationStopped&&this.fire(s[s.length-1],i,!1),!!i.bubbles)){i.eventPhase=I.BUBBLING_PHASE;for(let n=s.length-2;n>=0&&!i.propagationStopped;n--)this.fire(s[n],i,!1)}}fire([e,t,i],s,n,r=this.listeners.get(e)){if(!r)return;s.type=e!==s.target.path?"update":s.staticType,s.currentTarget={path:e,value:i,oldValue:s.type!=="update"?s.target.oldValue:void 0,key:s.type!=="update"?e:e.slice(e.lastIndexOf(".")+1)||"",object:t};let l,a;for(let o=0,c=r.length;o<c&&!s.immediatePropagationStopped;o++)r[o].capture===n&&(r[o].depth!==void 0&&(l??(l=this.getDepth(s.target.path)),a??(a=this.getDepth(e)),l>a+r[o].depth)||(r[o].cb(s),r[o].once&&(r.splice(o--,1),!r.length&&this.listeners.delete(e))))}tick(e){if(!e)return this.flush();if(typeof e=="string"){let t=this.batch?.get(e);t&&(this.wave(e,t),this.batch.delete(e))}else for(let t of e){let i=this.batch.get(t);i&&(this.wave(t,i),this.batch.delete(t))}}stall(e){this.queue??(this.queue=new Set),this.queue.add(e),!this.isBatching&&this.initBatching()}nostall(e){return this.queue?.delete(e)}bind(e,t){return t?.aborted?e.clup():t?.addEventListener("abort",e.clup,{once:!0}),t&&!t.aborted&&(e.sclup=()=>t.removeEventListener("abort",e.clup)),e.clup}clone(e,t,i=new WeakMap){if(!(W(e,this.config.crossRealms)||Array.isArray(e))||i.has(e))return e;let s=e[C]||0,n=!t&&this.isSCloning&&this.snapshotCache.get(e);if(n&&e[N]===s)return n;let r=t?e[E]||e:Array.isArray(e)?[]:{};i.set(e,r);let l=Object.keys(e);for(let a=0,o=l.length;a<o;a++)r[l[a]]=this.clone(e[l[a]],t,i);return!t&&this.isSCloning&&(this.snapshotCache.set(e,r),e[N]=s),r}getDepth(e,t=e?1:0){for(let i=0,s=e.length;i<s;i++)e.charCodeAt(i)===46&&t++;return t}getContext(e){let t=e.lastIndexOf("."),i=e==="*"?this.core:_(this.core,e),s=t===-1?this.core:_(this.core,e.slice(0,t));return{path:e,value:i,key:e.slice(t+1)||"",object:s}}syncAdd(e,t,i,s,n){var y;let{lazy:r=!1,once:l=!1,signal:a,immediate:o=!1}=v(s,O.MEDIATOR),c=this[y=`${e}${e.endsWith("t")?"t":""}ers`]??(this[y]=new Map),h=c.get(t),u;if(h){for(let T=0,g=h.length;T<g;T++)if(Object.is(h[T].cb,i)){u=h[T];break}}if(u)return u.clup;let f;return u={cb:i,once:l,clup:()=>(r&&this.nostall(f),this[`no${e}`](t,i))},o&&n?.(o),f=()=>(h??(c.set(t,h=[]),h)).push(u),r?this.stall(f):f(),this.bind(u,a)}syncDrop(e,t,i){let s=e?.get(t);if(s){for(let n=0,r=s.length;n<r;n++)if(Object.is(s[n].cb,i))return s[n].sclup?.(),s.splice(n--,1),!s.length&&e.delete(t),!0;return!1}}get(e,t,i){return this.syncAdd("get",e,t,i,s=>(s!=="auto"||w(this.core,e))&&_(this.core,e))}gonce(e,t,i){return this.get(e,t,{...v(i,O.MEDIATOR),once:!0})}noget(e,t){return this.syncDrop(this.getters,e,t)}set(e,t,i){return this.syncAdd("set",e,t,i,s=>(s!=="auto"||w(this.core,e))&&G(this.core,e,_(this.core,e)))}sonce(e,t,i){return this.set(e,t,Object.assign(v(i,O.MEDIATOR),{once:!0}))}noset(e,t){return this.syncDrop(this.setters,e,t)}delete(e,t,i){return this.syncAdd("delete",e,t,i,s=>(s!=="auto"||w(this.core,e))&&q(this.core,e,void 0))}donce(e,t,i){return this.delete(e,t,Object.assign(v(i,O.MEDIATOR),{once:!0}))}nodelete(e,t){return this.syncDrop(this.deleters,e,t)}watch(e,t,i){return this.syncAdd("watch",e,t,i,s=>s!=="auto"&&w(this.core,e)&&(n=>t(n.value,{type:"init",target:n,currentTarget:n,root:this.core,rejectable:!1}))(this.getContext(e)))}wonce(e,t,i){return this.watch(e,t,Object.assign(v(i,O.MEDIATOR),{once:!0}))}nowatch(e,t){return this.syncDrop(this.watchers,e,t)}on(e,t,i){this.listeners??(this.listeners=new Map);let{capture:s=!1,once:n=!1,signal:r,immediate:l=!1,depth:a}=v(i,O.LISTENER),o=this.listeners.get(e),c;if(o){for(let h=0,u=o.length;h<u;h++)if(Object.is(o[h].cb,t)&&s===o[h].capture){c=o[h];break}}if(c)return c.clup;if(c={cb:t,capture:s,depth:a,once:n,clup:()=>this.off(e,t,i)},l&&(l!=="auto"||w(this.core,e))){let h=this.getContext(e);t(new I({type:"init",target:h,currentTarget:h,root:this.core,rejectable:!1},this.config.eventBubbling,this.isLogging))}return(o??(this.listeners.set(e,o=[]),o)).push(c),this.bind(c,r)}once(e,t,i){return this.on(e,t,Object.assign(v(i,O.LISTENER),{once:!0}))}off(e,t,i){let s=this.listeners?.get(e);if(!s)return;let{capture:n}=v(i,O.LISTENER);for(let r=0,l=s.length;r<l;r++)if(Object.is(s[r].cb,t)&&s[r].capture===n)return s[r].sclup?.(),s.splice(r--,1),!s.length&&this.listeners.delete(e),!0;return!1}snapshot(e=!this.isSCloning,t=this.core){return this.clone(t,e)}cascade({type:e,currentTarget:{path:t,value:i,oldValue:s}},n=!0){if(e!=="set"&&e!=="delete"||!(W(i,this.config.crossRealms)||Array.isArray(i))||n&&!(W(s,this.config.crossRealms)||Array.isArray(s)))return;let r=n?F(s,i):i,l=Object.keys(r);for(let a=0,o=l.length;a<o;a++)G(this.core,t+"."+l[a],r[l[a]])}reset(){this.getters?.clear(),this.setters?.clear(),this.deleters?.clear(),this.watchers?.clear(),this.listeners?.clear(),this.queue?.clear(),this.batch?.clear(),this.isBatching=!1,this.proxyCache=new WeakMap}destroy(){this.reset(),X(this)}get canLog(){return this.log===z}set canLog(e){this.log=(this.isLogging=e)?z:j}get canTrackReferences(){return this.isTracking}get canTraceLineage(){return this.isTracing}get canSmartClone(){return this.isSCloning}};var Q=["tick","stall","nostall","get","gonce","noget","set","sonce","noset","delete","donce","nodelete","watch","wonce","nowatch","on","once","off","cascade","snapshot","reset","destroy"];function te(d,e,t){let i={},s=d instanceof L?d:new L(d,e),n={enumerable:!1,configurable:!0,writable:!1},r=!!(t?.prefix||t?.suffix);for(let l of Q){if(r)(t?.whitelist?.includes(l)??!0)&&(l=`${t?.prefix||""}${l}${t?.suffix||""}`);else if(t?.whitelist?.includes(l))continue;i[l]={value:s[l].bind(s),...n}}return i.__Reactor__={value:s,...n},Object.defineProperties(s.core,i),s.core}function se(d){return d[k]=!0,d}function ie(d){return delete d[k],d}function ne(d){return!!d[k]}function re(d){return d[D]=!0,d}function ae(d){return delete d[D],d}function oe(d){return!!d[D]}function ce(d){return d[$]=!0,d}function le(d){return delete d[$],d}function he(d){return!!d[$]}function de(d){return d[C]||0}function ue(d){return d[N]||0}export{L as Reactor,I as ReactorEvent,ue as getSnapshotVersion,de as getVersion,se as inert,re as intent,ne as isInert,oe as isIntent,he as isVolatile,ie as live,Q as methods,te as reactive,le as stable,ae as state,ce as volatile};
1
+ import{d as W,g as G,h as D,i as q,j as w,l as v,m as U,n as F,o as H,q as X}from"./chunk-N5UMAYCJ.js";var E=Symbol.for("S.I.A_RAW"),L=Symbol.for("S.I.A_INERTIA"),C=Symbol.for("S.I.A_REJECTABLE"),B=Symbol.for("S.I.A_INDIFFABLE"),$=Symbol.for("S.I.A_TERMINATOR"),_=Symbol.for("S.I.A_VERSION"),K=Symbol.for("S.I.A_SNAPSHOT_VERSION"),j=()=>{},ee=(typeof queueMicrotask<"u"?queueMicrotask:setTimeout).bind(window),z=console.log.bind(console,"[S.I.A Reactor]"),J=console.warn.bind(console,"[S.I.A Event]"),O={LISTENER:["capture","depth","once","signal","immediate"],MEDIATOR:["lazy","signal","immediate"]},A=class A{constructor(e,t=!1,i=!0){this.eventPhase=A.NONE;this._propagationStopped=!1;this._immediatePropagationStopped=!1;this._resolved="";this._rejected="";this._warn=j;this.type=this.staticType=e.type,this.target=e.target,this.currentTarget=e.currentTarget,this.root=e.root,this.value=e.target.value,this.oldValue=e.target.oldValue,this.path=e.target.path,this.rejectable=e.rejectable,this.bubbles=t,i&&(this._warn=J)}get propagationStopped(){return this._propagationStopped}stopPropagation(){this._propagationStopped=!0}get immediatePropagationStopped(){return this._immediatePropagationStopped}stopImmediatePropagation(){this._propagationStopped=!0,this._immediatePropagationStopped=!0}get resolved(){return this._resolved}resolve(e){if(!this.rejectable)return this._warn(`Ignored resolve() call on a non-rejectable ${this.staticType} at "${this.path}"`);this.eventPhase!==A.CAPTURING_PHASE&&this._warn(`Resolving an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`),this.rejectable&&(this._resolved=e||`Could ${this.staticType} intended value at "${this.path}"`)}get rejected(){return this._rejected}reject(e){if(!this.rejectable)return this._warn(`Ignored reject() call on a non-rejectable ${this.staticType} at "${this.path}"`);this.eventPhase!==A.CAPTURING_PHASE&&this._warn(`Rejecting an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`),this.rejectable&&(this._rejected=e||`Couldn't ${this.staticType} intended value at "${this.path}"`)}composedPath(){return F(this.path)}get canWarn(){return this._warn===J}};A.NONE=0,A.CAPTURING_PHASE=1,A.AT_TARGET=2,A.BUBBLING_PHASE=3;var I=A,k=class{constructor(e={},t){this.proxyCache=new WeakMap;this.log=j;this.isLogging=!1;this.isTracing=!1;this.isTracking=!1;this.isSCloning=!1;this.isBatching=!1;this[L]=!0,this.config={crossRealms:!1,eventBubbling:!0,batchingFunction:ee,...t},this.core=this.proxied(e),t&&(this.canLog=!!t.debug,(this.isTracking=!!t.referenceTracking)&&(this.lineage=new WeakMap),(this.isSCloning=this.isTracking&&!!t.smartCloning)&&(this.snapshotCache=new WeakMap),this.isTracing=this.isTracking&&!!t.lineageTracing)}proxied(e,t=!1,i=!1,s,r,n){if(!e||typeof e!="object"||!(W(e,this.config.crossRealms,!1)||Array.isArray(e))||e[L])return e;if(e=e[E]||e,this.isTracking&&s&&r&&this.link(e,s,r,!1),this.proxyCache.has(e))return this.proxyCache.get(e);t||(t=e[C]),i||(i=e[B]);let l=new Proxy(e,{get:(a,o,c)=>{if(o===E)return a;let h=a[o],u=String(o),f=this.isTracing?void 0:n?n+"."+u:u,y=this.isTracing?this.trace(a,u):f;if(this.log(`\u{1F440} [GET Trap] Initiated for "${u}" on "${y}"`),this.config.get&&(h=this.config.get(a,o,h,c,y)),this.getters){let T=this.getters.get("*");for(let p=0,x=this.isTracing?y.length:1;p<x;p++){let P=this.isTracing?y[p]:f,R=this.getters.get(P);if(!R&&!T)continue;let g={path:P,value:h,key:u,object:c},b={type:"get",target:g,currentTarget:g,root:this.core,rejectable:t};R&&(h=this.mediate(P,b,"get",R)),T&&(g.value=h,h=this.mediate("*",b,"get",T))}}return this.proxied(h,t,i,a,u,f)},set:(a,o,c,h)=>{let u,f,y,T=!1,p=String(o),x=this.isTracing?void 0:n?n+"."+p:p,P=this.isTracing?this.trace(a,p):x,R=this.isTracing?P.length:1,g=a[o];if((this.isTracking||!i)&&(y=g?.[E]||g,f=c?.[E]||c,u=Object.is(f,y)),!i&&u)return!0;if(this.log(`\u270F\uFE0F [SET Trap] Initiated for "${p}" on "${P}"`),this.config.set&&(T=(c=this.config.set(a,o,c,g,h,P))===$),this.setters){let b=this.setters.get("*");for(let m=0;m<R;m++){let S=this.isTracking?P[m]:x,M=this.setters.get(S);if(!M&&!b)continue;let V={path:S,value:c,oldValue:g,key:p,object:h},N={type:"set",target:V,currentTarget:V,root:this.core,terminated:T,rejectable:t};if(M){let Z=this.mediate(S,N,"set",M);T||(T=N.terminated)||(c=Z)}if(!b)continue;V.value=c;let Y=this.mediate("*",N,"set",b);T||(T=N.terminated)||(c=Y)}}if(T)return this.log(`\u{1F6E1}\uFE0F [SET Mediator] Terminated on "${P}"`),!0;if(a[o]=c,this.isTracking&&!u&&(this.isSCloning&&this.stamp(a),this.unlink(y,a,p),this.link(f,a,p)),this.watchers||this.listeners)for(let b=0;b<R;b++){let m=this.isTracking?P[b]:x,S={path:m,value:c,oldValue:g,key:p,object:h};this.notify(m,{type:"set",target:S,currentTarget:S,root:this.core,terminated:T,rejectable:t})}return!0},deleteProperty:(a,o)=>{let c,h=this.proxyCache.get(a),u=!1,f=String(o),y=this.isTracing?void 0:n?n+"."+f:f,T=this.isTracing?this.trace(a,f):y,p=this.isTracing?T.length:1,x=a[o];if(this.log(`\u{1F5D1}\uFE0F [DELETE Trap] Initiated for "${f}" on "${T}"`),this.config.delete&&(u=(c=this.config.delete(a,o,x,h,T))===$),this.deleters){let P=this.deleters.get("*");for(let R=0;R<p;R++){let g=this.isTracking?T[R]:y,b=this.deleters.get(g);if(!b&&!P)continue;let m={path:g,value:c,oldValue:x,key:f,object:h},S={type:"delete",target:m,currentTarget:m,root:this.core,rejectable:t};if(b){let V=this.mediate(g,S,"delete",b);u||(u=S.terminated)||(c=V)}if(!P)continue;let M=this.mediate("*",S,"delete",P);u||(u=S.terminated)||(c=M)}}if(u)return this.log(`\u{1F6E1}\uFE0F [DELETE Mediator] Terminated on "${T}"`),!0;if(delete a[o],this.isTracking&&(this.isSCloning&&this.stamp(a),this.unlink(x?.[E]||x,a,f)),this.watchers||this.listeners)for(let P=0;P<p;P++){let R=this.isTracking?T[P]:y,g={path:R,value:c,oldValue:x,key:f,object:h};this.notify(R,{type:"delete",target:g,currentTarget:g,root:this.core,rejectable:t})}return!0}});return this.proxyCache.set(e,l),l}trace(e,t,i=[],s=new WeakSet){if(Object.is(e,this.core[E]||this.core))return i.push(t),i;if(s.has(e))return i;s.add(e);let r=this.lineage.get(e);if(!r)return i;for(let n=0,l=r.length;n<l;n+=2)this.trace(r[n],r[n+1]?r[n+1]+"."+t:t,i,s);return i}link(e,t,i,s=!0,r){if(!(s&&!(W(e,this.config.crossRealms)||Array.isArray(e)))){r=this.lineage.get(e)??(this.lineage.set(e,r=[]),r);for(let n=0,l=r.length;n<l;n+=2)if(Object.is(r[n],t)&&r[n+1]===i)return;r.push(t,i)}}unlink(e,t,i){if(!(W(e,this.config.crossRealms)||Array.isArray(e)))return;let s=this.lineage.get(e);if(s){for(let r=0,n=s.length;r<n;r+=2)if(Object.is(s[r],t)&&s[r+1]===i)return void s.splice(r,2)}}stamp(e,t=!0){if(t&&typeof e!="object")return;e[_]=(e[_]||0)+1;let i=this.lineage?.get(e);if(i)for(let s=0,r=i.length;s<r;s+=2)this.stamp(i[s])}mediate(e,t,i,s){let r=!1,n=t.target.value,l=i==="get",a=i==="set",o=l?this.getters:a?this.setters:this.deleters;for(let c=l?s.length-1:0,h=l?-1:s.length;c!==h;c+=l?-1:1){let u=l?s[c].cb(n,t):a?s[c].cb(n,r,t):s[c].cb(r,t);(l||!(r||(r=t.terminated=u===$)))&&(n=u),s[c].once&&(s.splice(c--,1),!s.length&&o.delete(e))}return n}notify(e,t){if(this.watchers){let i=this.watchers.get("*"),s=this.watchers.get(e);if(s)for(let r=0,n=s.length;r<n;r++)s[r].cb(t.target.value,t),s[r].once&&(s.splice(r--,1),!s.length&&this.watchers.delete(e));if(i)for(let r=0,n=i.length;r<n;r++)i[r].cb(t.target.value,t),i[r].once&&(i.splice(r--,1),!i.length&&this.watchers.delete("*"))}this.listeners&&this.schedule(e,t)}schedule(e,t){this.batch??(this.batch=new Map),this.batch.set(e,t),!this.isBatching&&this.initBatching()}initBatching(){this.isBatching=!0,this.config.batchingFunction(()=>this.flush())}flush(){if(this.isBatching=!1,this.batch&&this.tick(this.batch.keys()),this.queue?.size)for(let e of this.queue)e(),this.queue.delete(e)}wave(e,t){let i=new I(t,this.config.eventBubbling,this.isLogging),s=H(this.core,e);i.eventPhase=I.CAPTURING_PHASE;for(let r=0;r<=s.length-2&&!i.propagationStopped;r++)this.fire(s[r],i,!0);if(!i.propagationStopped&&(i.eventPhase=I.AT_TARGET,this.fire(s[s.length-1],i,!0),!i.immediatePropagationStopped&&this.fire(s[s.length-1],i,!1),!!i.bubbles)){i.eventPhase=I.BUBBLING_PHASE;for(let r=s.length-2;r>=0&&!i.propagationStopped;r--)this.fire(s[r],i,!1)}}fire([e,t,i],s,r,n=this.listeners.get(e)){if(!n)return;s.type=e!==s.target.path?"update":s.staticType,s.currentTarget={path:e,value:i,oldValue:s.type!=="update"?s.target.oldValue:void 0,key:s.type!=="update"?e:e.slice(e.lastIndexOf(".")+1)||"",object:t};let l,a;for(let o=0,c=n.length;o<c&&!s.immediatePropagationStopped;o++)n[o].capture===r&&(n[o].depth!==void 0&&(l??(l=this.getDepth(s.target.path)),a??(a=this.getDepth(e)),l>a+n[o].depth)||(n[o].cb(s),n[o].once&&(n.splice(o--,1),!n.length&&this.listeners.delete(e))))}tick(e){if(!e)return this.flush();if(typeof e=="string"){let t=this.batch?.get(e);t&&(this.wave(e,t),this.batch.delete(e))}else for(let t of e){let i=this.batch.get(t);i&&(this.wave(t,i),this.batch.delete(t))}}stall(e){this.queue??(this.queue=new Set),this.queue.add(e),!this.isBatching&&this.initBatching()}nostall(e){return this.queue?.delete(e)}bind(e,t){return t?.aborted?e.clup():t?.addEventListener("abort",e.clup,{once:!0}),t&&!t.aborted&&(e.sclup=()=>t.removeEventListener("abort",e.clup)),e.clup}clone(e,t,i=new WeakMap){if(!(W(e,this.config.crossRealms)||Array.isArray(e))||i.has(e))return e;let s=e[_]||0,r=!t&&this.isSCloning&&this.snapshotCache.get(e);if(r&&e[K]===s)return r;let n=t?e[E]||e:Array.isArray(e)?[]:{};i.set(e,n);let l=Object.keys(e);for(let a=0,o=l.length;a<o;a++)n[l[a]]=this.clone(e[l[a]],t,i);return!t&&this.isSCloning&&(this.snapshotCache.set(e,n),e[K]=s),n}getDepth(e,t=e?1:0){for(let i=0,s=e.length;i<s;i++)e.charCodeAt(i)===46&&t++;return t}getContext(e){let t=e.lastIndexOf("."),i=e==="*"?this.core:D(this.core,e),s=t===-1?this.core:D(this.core,e.slice(0,t));return{path:e,value:i,key:e.slice(t+1)||"",object:s}}syncAdd(e,t,i,s,r){var y;let{lazy:n=!1,once:l=!1,signal:a,immediate:o=!1}=v(s,O.MEDIATOR),c=this[y=`${e}${e.endsWith("t")?"t":""}ers`]??(this[y]=new Map),h=c.get(t),u;if(h){for(let T=0,p=h.length;T<p;T++)if(Object.is(h[T].cb,i)){u=h[T];break}}if(u)return u.clup;let f;return u={cb:i,once:l,clup:()=>(n&&this.nostall(f),this[`no${e}`](t,i))},o&&r?.(o),f=()=>(h??(c.set(t,h=[]),h)).push(u),n?this.stall(f):f(),this.bind(u,a)}syncDrop(e,t,i){let s=e?.get(t);if(s){for(let r=0,n=s.length;r<n;r++)if(Object.is(s[r].cb,i))return s[r].sclup?.(),s.splice(r--,1),!s.length&&e.delete(t),!0;return!1}}get(e,t,i){return this.syncAdd("get",e,t,i,s=>(s!=="auto"||w(this.core,e))&&D(this.core,e))}gonce(e,t,i){return this.get(e,t,{...v(i,O.MEDIATOR),once:!0})}noget(e,t){return this.syncDrop(this.getters,e,t)}set(e,t,i){return this.syncAdd("set",e,t,i,s=>(s!=="auto"||w(this.core,e))&&G(this.core,e,D(this.core,e)))}sonce(e,t,i){return this.set(e,t,Object.assign(v(i,O.MEDIATOR),{once:!0}))}noset(e,t){return this.syncDrop(this.setters,e,t)}delete(e,t,i){return this.syncAdd("delete",e,t,i,s=>(s!=="auto"||w(this.core,e))&&q(this.core,e,void 0))}donce(e,t,i){return this.delete(e,t,Object.assign(v(i,O.MEDIATOR),{once:!0}))}nodelete(e,t){return this.syncDrop(this.deleters,e,t)}watch(e,t,i){return this.syncAdd("watch",e,t,i,s=>s!=="auto"&&w(this.core,e)&&(r=>t(r.value,{type:"init",target:r,currentTarget:r,root:this.core,rejectable:!1}))(this.getContext(e)))}wonce(e,t,i){return this.watch(e,t,Object.assign(v(i,O.MEDIATOR),{once:!0}))}nowatch(e,t){return this.syncDrop(this.watchers,e,t)}on(e,t,i){this.listeners??(this.listeners=new Map);let{capture:s=!1,once:r=!1,signal:n,immediate:l=!1,depth:a}=v(i,O.LISTENER),o=this.listeners.get(e),c;if(o){for(let h=0,u=o.length;h<u;h++)if(Object.is(o[h].cb,t)&&s===o[h].capture){c=o[h];break}}if(c)return c.clup;if(c={cb:t,capture:s,depth:a,once:r,clup:()=>this.off(e,t,i)},l&&(l!=="auto"||w(this.core,e))){let h=this.getContext(e);t(new I({type:"init",target:h,currentTarget:h,root:this.core,rejectable:!1},this.config.eventBubbling,this.isLogging))}return(o??(this.listeners.set(e,o=[]),o)).push(c),this.bind(c,n)}once(e,t,i){return this.on(e,t,Object.assign(v(i,O.LISTENER),{once:!0}))}off(e,t,i){let s=this.listeners?.get(e);if(!s)return;let{capture:r}=v(i,O.LISTENER);for(let n=0,l=s.length;n<l;n++)if(Object.is(s[n].cb,t)&&s[n].capture===r)return s[n].sclup?.(),s.splice(n--,1),!s.length&&this.listeners.delete(e),!0;return!1}snapshot(e=!this.isSCloning,t=this.core){return this.clone(t,e)}cascade({type:e,currentTarget:{path:t,value:i,oldValue:s}},r=!0){if(e!=="set"&&e!=="delete"||!(W(i,this.config.crossRealms)||Array.isArray(i))||r&&!(W(s,this.config.crossRealms)||Array.isArray(s)))return;let n=r?U(s,i):i,l=Object.keys(n);for(let a=0,o=l.length;a<o;a++)G(this.core,t+"."+l[a],n[l[a]])}reset(){this.getters?.clear(),this.setters?.clear(),this.deleters?.clear(),this.watchers?.clear(),this.listeners?.clear(),this.queue?.clear(),this.batch?.clear(),this.isBatching=!1,this.proxyCache=new WeakMap}destroy(){this.reset(),X(this)}get canLog(){return this.log===z}set canLog(e){this.log=(this.isLogging=e)?z:j}get canTrackReferences(){return this.isTracking}get canTraceLineage(){return this.isTracing}get canSmartClone(){return this.isSCloning}};var Q=["tick","stall","nostall","get","gonce","noget","set","sonce","noset","delete","donce","nodelete","watch","wonce","nowatch","on","once","off","cascade","snapshot","reset","destroy"];function te(d,e,t){let i={},s=d instanceof k?d:new k(d,e),r={enumerable:!1,configurable:!0,writable:!1},n=!!(t?.prefix||t?.suffix);for(let l of Q){if(n)(t?.whitelist?.includes(l)??!0)&&(l=`${t?.prefix||""}${l}${t?.suffix||""}`);else if(t?.whitelist?.includes(l))continue;i[l]={value:s[l].bind(s),...r}}return i.__Reactor__={value:s,...r},Object.defineProperties(s.core,i),s.core}function se(d){return d[L]=!0,d}function ie(d){return delete d[L],d}function re(d){return!!d[L]}function ne(d){return d[C]=!0,d}function ae(d){return delete d[C],d}function oe(d){return!!d[C]}function ce(d){return d[B]=!0,d}function le(d){return delete d[B],d}function he(d){return!!d[B]}function de(d){return d[_]||0}function ue(d){return d[K]||0}export{k as Reactor,I as ReactorEvent,$ as TERMINATOR,ue as getSnapshotVersion,de as getVersion,se as inert,ne as intent,re as isInert,oe as isIntent,he as isVolatile,ie as live,Q as methods,te as reactive,le as stable,ae as state,ce as volatile};
package/dist/utils.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var h=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var L=(e,t)=>{for(var s in t)h(e,s,{get:t[s],enumerable:!0})},M=(e,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of $(t))!v.call(e,i)&&i!==s&&h(e,i,{get:()=>t[i],enumerable:!(r=I(t,i))||r.enumerable});return e};var _=e=>M(h({},"__esModule",{value:!0}),e);var B={};L(B,{camelize:()=>E,capitalize:()=>D,deepClone:()=>S,deleteAny:()=>w,getAny:()=>A,getTrailPaths:()=>z,getTrailRecords:()=>R,inAny:()=>W,inBoolArrOpt:()=>C,isArr:()=>T,isDef:()=>P,isIter:()=>j,isObj:()=>f,isStrictObj:()=>x,mergeObjs:()=>b,nuke:()=>U,parseAnyObj:()=>d,parseEvOpts:()=>N,setAny:()=>m,uncamelize:()=>V});module.exports=_(B);var g=/^([^\[\]]+)\[(\d+)\]$/;function P(e){return e!==void 0}function T(e){return Array.isArray(e)}function f(e,t=!0){return typeof e=="object"&&e!==null&&(t?!Array.isArray(e):!0)}function x(e,t=!1,s=!0){return(s?f(e,!1):!0)&&(t?Object.prototype.toString.call(e)==="[object Object]":e.constructor===Object)}function j(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function C(e,t){return e?.includes?.(t)??e}function m(e,t,s,r=".",i){var l,u;if(!t.includes(r))return void(e[i?i(t):t]=s);let n=t.split(r),o=e;for(let a=0;a<n.length;a++){let c=i?i(n[a]):n[a],O=c.includes("[")&&c.match(g);if(O){let[,p,y]=O;T(o[p])||(o[p]=[]),a===n.length-1?o[p][Number(y)]=s:((l=o[p])[u=Number(y)]||(l[u]={}),o=o[p][Number(y)])}else a===n.length-1?o[c]=s:(o[c]||(o[c]={}),o=o[c])}}function A(e,t,s=".",r){if(!t.includes(s))return e[r?r(t):t];let i=t.split(s),n=e;for(let o=0;o<i.length;o++){let l=r?r(i[o]):i[o],u=l.includes("[")&&l.match(g);if(u){let[,a,c]=u;if(!T(n[a])||!(a in n))return;n=n[a][Number(c)]}else{if(!f(n)||!(l in n))return;n=n[l]}}return n}function w(e,t,s=".",r){if(!t.includes(s))return void delete e[r?r(t):t];let i=t.split(s),n=e;for(let o=0;o<i.length;o++){let l=r?r(i[o]):i[o],u=l.includes("[")&&l.match(g);if(u){let[,a,c]=u;if(!T(n[a])||!(a in n))return;o===i.length-1?delete n[a][Number(c)]:n=n[a][Number(c)]}else{if(!f(n)||!(l in n))return;o===i.length-1?delete n[l]:n=n[l]}}}function W(e,t,s=".",r){if(!t.includes(s))return t in e;let i=t.split(s),n=e;for(let o=0;o<i.length;o++){let l=r?r(i[o]):i[o],u=l.includes("[")&&l.match(g);if(u){let[,a,c]=u;if(!T(n[a])||!(a in n))return!1;if(o===i.length-1)return!0;n=n[a][Number(c)]}else{if(!f(n)||!(l in n))return!1;if(o===i.length-1)return!0;n=n[l]}}return!0}function d(e,t=".",s=i=>i,r=new WeakSet){if(!f(e)||r.has(e))return e;r.add(e);let i={};return Object.keys(e).forEach(n=>n.includes(t)?m(i,n,d(e[n],t,s,r),t,s):i[n]=f(e[n])?d(e[n],t,s,r):e[n]),i}function N(e,t,s=t[0],r={}){return Object.assign(r,typeof e=="boolean"?{[s]:e}:e),r}function b(e={},t={}){let s={...e||{},...t||{}};return Object.keys(s).forEach(r=>f(e?.[r])&&f(t?.[r])&&(s[r]=b(e[r],t[r]))),s}function z(e,t=!0){let s=e.split("."),r=["*"],i="";for(let n=0;n<s.length;n++)i+=(n===0?"":".")+s[n],r.push(i);return t?r.reverse():r}function R(e,t){let s=t.split("."),r=[["*",e,e]],i="",n=e;for(let o=0;o<s.length;o++)i+=(o===0?"":".")+s[o],r.push([i,n,n=n?.[s[o]]]);return r}function S(e,t,s=new WeakMap){if(!(x(e,t)||T(e))||s.has(e))return e;let r=T(e)?[]:{};s.set(e,r);let i=Object.keys(e);for(let n=0;n<i.length;n++)r[i[n]]=S(e[i[n]],t,s);return r}function U(e){let t=e;for(;t&&t!==Object.prototype;){for(let s of Object.getOwnPropertyNames(t)){if(s==="constructor")continue;let r=Object.getOwnPropertyDescriptor(t,s);typeof r?.value!="function"&&(r?.get||r?.set||(t[s]=null))}t=Object.getPrototypeOf(t)}}function D(e=""){return e.replace(/^(\s*)([a-z])/i,(t,s,r)=>s+r.toUpperCase())}function E(e="",{source:t}=/[\s_-]+/,{preserveInnerCase:s=!0,upperFirst:r=!1}={}){return(s?e:e.toLowerCase()).replace(new RegExp(t+"(\\w)","g"),(i,n)=>n.toUpperCase()).replace(/^\w/,i=>i[r?"toUpperCase":"toLowerCase"]())}function V(e,t=" "){return e.replace(/([a-z])([A-Z])/g,`$1${t}$2`).toLowerCase()}0&&(module.exports={camelize,capitalize,deepClone,deleteAny,getAny,getTrailPaths,getTrailRecords,inAny,inBoolArrOpt,isArr,isDef,isIter,isObj,isStrictObj,mergeObjs,nuke,parseAnyObj,parseEvOpts,setAny,uncamelize});
1
+ "use strict";var h=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var s in t)h(e,s,{get:t[s],enumerable:!0})},B=(e,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of I(t))!M.call(e,i)&&i!==s&&h(e,i,{get:()=>t[i],enumerable:!(r=U(t,i))||r.enumerable});return e};var C=e=>B(h({},"__esModule",{value:!0}),e);var $={};v($,{deepClone:()=>O,deleteAny:()=>N,getAny:()=>W,getTrailPaths:()=>D,getTrailRecords:()=>V,inAny:()=>R,inBoolArrOpt:()=>A,isArr:()=>d,isDef:()=>P,isIter:()=>j,isObj:()=>f,isStrictObj:()=>b,mergeObjs:()=>S,nuke:()=>E,parseAnyObj:()=>p,parseEvOpts:()=>w,setAny:()=>x});module.exports=C($);var y=/^([^\[\]]+)\[(\d+)\]$/;function P(e){return e!==void 0}function d(e){return Array.isArray(e)}function f(e,t=!0){return typeof e=="object"&&e!==null&&(t?!Array.isArray(e):!0)}function b(e,t=!1,s=!0){return(s?f(e,!1):!0)&&(t?Object.prototype.toString.call(e)==="[object Object]":e.constructor===Object)}function j(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function A(e,t){return e?.includes?.(t)??e}function x(e,t,s,r=".",i){var c,u;if(!t.includes(r))return void(e[i?i(t):t]=s);let n=t.split(r),o=e;for(let a=0;a<n.length;a++){let l=i?i(n[a]):n[a],m=l.includes("[")&&l.match(y);if(m){let[,T,g]=m;d(o[T])||(o[T]=[]),a===n.length-1?o[T][Number(g)]=s:((c=o[T])[u=Number(g)]||(c[u]={}),o=o[T][Number(g)])}else a===n.length-1?o[l]=s:(o[l]||(o[l]={}),o=o[l])}}function W(e,t,s=".",r){if(!t.includes(s))return e[r?r(t):t];let i=t.split(s),n=e;for(let o=0;o<i.length;o++){let c=r?r(i[o]):i[o],u=c.includes("[")&&c.match(y);if(u){let[,a,l]=u;if(!d(n[a])||!(a in n))return;n=n[a][Number(l)]}else{if(!f(n)||!(c in n))return;n=n[c]}}return n}function N(e,t,s=".",r){if(!t.includes(s))return void delete e[r?r(t):t];let i=t.split(s),n=e;for(let o=0;o<i.length;o++){let c=r?r(i[o]):i[o],u=c.includes("[")&&c.match(y);if(u){let[,a,l]=u;if(!d(n[a])||!(a in n))return;o===i.length-1?delete n[a][Number(l)]:n=n[a][Number(l)]}else{if(!f(n)||!(c in n))return;o===i.length-1?delete n[c]:n=n[c]}}}function R(e,t,s=".",r){if(!t.includes(s))return t in e;let i=t.split(s),n=e;for(let o=0;o<i.length;o++){let c=r?r(i[o]):i[o],u=c.includes("[")&&c.match(y);if(u){let[,a,l]=u;if(!d(n[a])||!(a in n))return!1;if(o===i.length-1)return!0;n=n[a][Number(l)]}else{if(!f(n)||!(c in n))return!1;if(o===i.length-1)return!0;n=n[c]}}return!0}function p(e,t=".",s=i=>i,r=new WeakSet){if(!f(e)||r.has(e))return e;r.add(e);let i={};return Object.keys(e).forEach(n=>n.includes(t)?x(i,n,p(e[n],t,s,r),t,s):i[n]=f(e[n])?p(e[n],t,s,r):e[n]),i}function w(e,t,s=t[0],r={}){return Object.assign(r,typeof e=="boolean"?{[s]:e}:e),r}function S(e={},t={}){let s={...e||{},...t||{}};return Object.keys(s).forEach(r=>f(e?.[r])&&f(t?.[r])&&(s[r]=S(e[r],t[r]))),s}function D(e,t=!0){let s=e.split("."),r=["*"],i="";for(let n=0;n<s.length;n++)i+=(n===0?"":".")+s[n],r.push(i);return t?r.reverse():r}function V(e,t){let s=t.split("."),r=[["*",e,e]],i="",n=e;for(let o=0;o<s.length;o++)i+=(o===0?"":".")+s[o],r.push([i,n,n=n?.[s[o]]]);return r}function O(e,t,s=new WeakMap){if(!(b(e,t)||d(e))||s.has(e))return e;let r=d(e)?[]:{};s.set(e,r);let i=Object.keys(e);for(let n=0;n<i.length;n++)r[i[n]]=O(e[i[n]],t,s);return r}function E(e){let t=e;for(;t&&t!==Object.prototype;){for(let s of Object.getOwnPropertyNames(t)){if(s==="constructor")continue;let r=Object.getOwnPropertyDescriptor(t,s);typeof r?.value!="function"&&(r?.get||r?.set||(t[s]=null))}t=Object.getPrototypeOf(t)}}0&&(module.exports={deepClone,deleteAny,getAny,getTrailPaths,getTrailRecords,inAny,inBoolArrOpt,isArr,isDef,isIter,isObj,isStrictObj,mergeObjs,nuke,parseAnyObj,parseEvOpts,setAny});