chizu 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,12 @@
1
- (function(o,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("eventemitter3"),require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","eventemitter3","react","react-dom/client"],a):(o=typeof globalThis<"u"?globalThis:o||self,a(o.Chizu={},o.jsxRuntime,o.EventEmitter3,o.React,o.ReactDOM))})(this,function(o,a,f,j,N){"use strict";var $=o=>{throw TypeError(o)};var B=(o,a,f)=>a.has(o)||$("Cannot "+f);var p=(o,a,f)=>(B(o,a,"read from private field"),f?f.call(o):a.get(o)),y=(o,a,f)=>a.has(o)?$("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(o):a.set(o,f),g=(o,a,f,j)=>(B(o,a,"write to private field"),j?j.call(o,f):a.set(o,f),f);var w,b,E,M,R,v;function C(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const l=C(j),J=C(N),T=l.createContext({appEmitter:new f});function U(){return l.useContext(T)}function L(e){J.createRoot(document.body).render(a.jsx(Q,{tree:e}))}function Q({tree:e}){const t=l.useMemo(()=>({appEmitter:new f}),[]);return a.jsx(T.Provider,{value:t,children:a.jsx(e,{})})}function W(e){return e}function x(e){return e}var S=(e=>(e[e.Idle=0]="Idle",e[e.Pending=1]="Pending",e[e.Adding=2]="Adding",e[e.Removing=4]="Removing",e[e.Updating=8]="Updating",e[e.Moving=16]="Moving",e))(S||{}),h=(e=>(e.Mount="lifecycle/mount",e.Tree="lifecycle/tree",e.Derive="lifecycle/derive",e.Error="distributed/lifecycle/error",e.Unmount="lifecycle/unmount",e))(h||{});const A=Symbol("unwrap");class q{constructor(t,r,n){y(this,w);y(this,b);y(this,E);g(this,w,t),g(this,b,r),g(this,E,n)}value(){return p(this,w)}state(){return p(this,b)}process(){return p(this,E)}}w=new WeakMap,b=new WeakMap,E=new WeakMap;function F(e,t,r){return new q(e,t,r)}function z(e,t){return new Proxy(e,{get(r,n){const u=Reflect.get(r,n),c=u instanceof q?u.value():u;return n===A?r:typeof c=="object"?z(c,t):c},set(r,n,u){const s=u instanceof q,c=u,i=s?c.process():null,d=s?c.value():u,m=d==null?null:d[A]??d,P=/^\d+$/.test(String(n));return s&&i&&t.add({key:P?null:n,value:typeof m=="object"?m:r,process:i,state:c.state()}),Reflect.set(r,n,m)}})}function G(e,t){function r(n,u=""){return new Proxy(n,{get(s,c){const i=Reflect.get(s,c);if(typeof c=="symbol")return i;if(c==="is"){const d=[...t].filter(m=>m.value===s&&(m.key===u||!m.key));return m=>d.length===0?!1:!!([...new Set(d.map(_=>_.state))].reduce((_,ve)=>_|ve,S.Pending)&m)}return r(typeof i=="object"&&i!==null?i:s,c)}})}return r(e)}function H(e){return l.useMemo(()=>({controller:{get model(){return e.model.current},queue:[],events:e.options.props,actions:{io(t){return t},placeholder(t,r){return F(t,r,e.process.current)},produce(t){return r=>(t(z(r,e.mutations.current)),r)},dispatch([t,...r]){const n=Promise.withResolvers();return e.dispatchers.dispatch(t,r,n),n.promise}}},view:{get model(){return e.model.current},get validate(){return G(e.model.current,e.mutations.current)},events:e.options.props,actions:{dispatch([t,...r]){const n=Promise.withResolvers();return e.dispatchers.dispatch(t,r,n),n.promise}}}}),[])}function K(e){return l.useMemo(()=>{const t=e.options.controller(e.actions.controller);return Object.entries(t).forEach(([n,u])=>e.dispatchers.attach(n,u)),t},[])}function V(e){return(t,r)=>async(n=Promise.withResolvers(),u)=>{if(typeof r!="function")return;const s=Symbol(`process/${Math.random()}`);e.queue.current.add(n.promise);const c=new AbortController;try{const i={app:e.app,task:n,process:s,ƒ:r,abortController:c,payload:u,props:e},d=X(e,i);e.queue.current.size>1&&await Promise.allSettled([...e.queue.current].slice(0,-1)),d.size>0&&await Y(e,i,d),e.queue.current.delete(n.promise),n.resolve()}catch(i){console.log("hmm, error",i),e.app.appEmitter.emit(h.Error,n,[i])}}}function X(e,t){const r=new Set,n=t.ƒ(...t.payload);for(;;)try{const u=n.next();if(u.done&&typeof u.value=="function"){e.process.current=t.process;const s=u.value(t.props.model.current);return s&&(t.props.model.current=s),e.process.current=null,t.props.update.rerender(),r}e.process.current=t.process,typeof u.value=="function"&&r.add(u.value({signal:t.abortController.signal}).catch(s=>()=>{e.app.appEmitter.emit(h.Error,t.task,[s])})),e.process.current=null}catch(u){return e.app.appEmitter.emit(h.Error,t.task,[u]),new Set}}async function Y(e,t,r){(await Promise.allSettled(r)).forEach(n=>{if(e.process.current=t.process,n.status==="rejected")return;const u=typeof n.value=="function"?n.value(t.props.model.current):n;u&&(t.props.model.current=u),e.process.current=null,e.mutations.current=new Set([...e.mutations.current].filter(s=>s.process!==t.process)),t.props.update.rerender()})}function k(e){return e.startsWith("distributed")}class I extends Error{constructor(r,n=null){super(String(n));y(this,M);y(this,R);g(this,M,r),g(this,R,n)}get type(){return p(this,M)}get message(){return p(this,R)||""}}M=new WeakMap,R=new WeakMap;function Z(e){const t=U(),r=V(e);return l.useMemo(()=>{const n=new f,u=t.appEmitter;return{attach(s,c){const i=String(s);k(i)?u.on(i,r(s,c)):n.on(i,r(s,c))},dispatch(s,c,i){const d=String(s);k(d)?u.emit(d,i,c):n.emit(d,i,c)}}},[])}function ee(){const e=l.useRef(null);return l.useMemo(()=>({customElement:e}),[])}function te(e){const t=l.useRef(!1);l.useLayoutEffect(()=>{e.dispatchers.dispatch(h.Mount,[]),e.dispatchers.dispatch(h.Tree,[e.elements.customElement.current]),e.dispatchers.dispatch(h.Derive,[e.options.props])},[e.options.props]),l.useLayoutEffect(()=>{if(!t.current)return t.current=!0,()=>e.dispatchers.dispatch(h.Unmount,[])},[])}function re(e){return l.useMemo(()=>({output(t){const r=e.elements.customElement.current;console.groupCollapsed("%cRendered","background: rgb(217, 235, 240); color: rgb(0, 51, 102); border-radius: 2px; padding: 0 5px",r),console.groupEnd()}}),[])}function ne(e){return l.useRef(e.options.model)}function oe(){return l.useRef(new Set)}function ue(){return l.useRef(null)}function se(){return l.useRef(new Set)}function ce(){const[e,t]=l.useReducer(r=>r+1,0);return l.useMemo(()=>({hash:e,rerender:t}),[e])}function ie({options:e}){const t=U(),r=ce(),n=se(),u=oe(),s=ee(),c=ue(),i=ne({options:e}),d=re({options:e,elements:s}),m=Z({app:t,options:e,update:r,model:i,logger:d,queue:n,mutations:u,process:c}),P=H({app:t,options:e,model:i,dispatchers:m,mutations:u,process:c});return K({options:e,dispatchers:m,actions:P}),te({options:e,dispatchers:m,elements:s}),l.useMemo(()=>(d.output({}),l.createElement(e.name,{ref:s.customElement,children:e.view(P.view)})),[r.hash])}function le(e){return t=>l.memo(r=>ie({options:{...t,name:e.join(""),props:r}}),(r,n)=>JSON.stringify(r)===JSON.stringify(n))}function ae(e){return e}const D=class D{constructor(t){y(this,v);g(this,v,t)}static of(t){return new D(t)}map(t=n=>n,r=n=>n){return p(this,v)==null||p(this,v)instanceof Error?r(p(this,v)):t(p(this,v))}};v=new WeakMap;let O=D;function de(e){return new Promise(t=>setTimeout(t,e))}function fe(e){return e?!!(e&&typeof e!="symbol"):Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`)}function me(e){return e instanceof I}const pe=Object.freeze(Object.defineProperty({__proto__:null,isEventError:me,maybe:O,pk:fe,sleep:de},Symbol.toStringTag,{value:"Module"})),he={app:L,module:le,model:x,view:ae,controller:W};o.EventError=I,o.Lifecycle=h,o.Maybe=O,o.State=S,o.create=he,o.utils=pe,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(R,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("react/jsx-runtime"),require("eventemitter3"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","eventemitter3","react"],E):(R=typeof globalThis<"u"?globalThis:R||self,E(R.Chizu={},R.jsxRuntime,R.EventEmitter3,R.React))})(this,function(R,E,O,se){"use strict";var Yo=Object.defineProperty;var Zn=R=>{throw TypeError(R)};var Xo=(R,E,O)=>E in R?Yo(R,E,{enumerable:!0,configurable:!0,writable:!0,value:O}):R[E]=O;var nr=(R,E,O)=>Xo(R,typeof E!="symbol"?E+"":E,O),Qn=(R,E,O)=>E.has(R)||Zn("Cannot "+O);var ar=(R,E,O)=>(Qn(R,E,"read from private field"),O?O.call(R):E.get(R)),ir=(R,E,O)=>E.has(R)?Zn("Cannot add the same private member more than once"):E instanceof WeakSet?E.add(R):E.set(R,O),or=(R,E,O,se)=>(Qn(R,E,"write to private field"),se?se.call(R,O):E.set(R,O),O);var ie,oe;function ea(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const f=ea(se),ur=f.createContext({appEmitter:new O});function sr(){return f.useContext(ur)}function ta(e){return()=>{const t=f.useMemo(()=>({appEmitter:new O}),[]);return E.jsx(ur.Provider,{value:t,children:E.jsx(e,{})})}}function ra(e){return e}function na(e){return e}class lr{constructor(t){this.value=t}}class cr{static Draft(t){return new lr(t)}}nr(cr,"Op",{Add:1,Remove:2,Update:4,Move:8,Replace:16});var V=(e=>(e.Mount="lifecycle/mount",e.Tree="lifecycle/tree",e.Derive="lifecycle/derive",e.Error="distributed/lifecycle/error",e.Unmount="lifecycle/unmount",e))(V||{}),fr=Symbol.for("immer-nothing"),dr=Symbol.for("immer-draftable"),j=Symbol.for("immer-state"),aa=process.env.NODE_ENV!=="production"?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function I(e,...t){if(process.env.NODE_ENV!=="production"){const r=aa[e],n=typeof r=="function"?r.apply(null,t):r;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var J=Object.getPrototypeOf;function Y(e){return!!e&&!!e[j]}function B(e){var t;return e?hr(e)||Array.isArray(e)||!!e[dr]||!!((t=e.constructor)!=null&&t[dr])||fe(e)||de(e):!1}var ia=Object.prototype.constructor.toString();function hr(e){if(!e||typeof e!="object")return!1;const t=J(e);if(t===null)return!0;const r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object?!0:typeof r=="function"&&Function.toString.call(r)===ia}function le(e,t){ce(e)===0?Reflect.ownKeys(e).forEach(r=>{t(r,e[r],e)}):e.forEach((r,n)=>t(n,r,e))}function ce(e){const t=e[j];return t?t.type_:Array.isArray(e)?1:fe(e)?2:de(e)?3:0}function Oe(e,t){return ce(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function pr(e,t,r){const n=ce(e);n===2?e.set(t,r):n===3?e.add(r):e[t]=r}function oa(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function fe(e){return e instanceof Map}function de(e){return e instanceof Set}function W(e){return e.copy_||e.base_}function Te(e,t){if(fe(e))return new Map(e);if(de(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const r=hr(e);if(t===!0||t==="class_only"&&!r){const n=Object.getOwnPropertyDescriptors(e);delete n[j];let a=Reflect.ownKeys(n);for(let i=0;i<a.length;i++){const o=a[i],u=n[o];u.writable===!1&&(u.writable=!0,u.configurable=!0),(u.get||u.set)&&(n[o]={configurable:!0,writable:!0,enumerable:u.enumerable,value:e[o]})}return Object.create(J(e),n)}else{const n=J(e);if(n!==null&&r)return{...e};const a=Object.create(n);return Object.assign(a,e)}}function qe(e,t=!1){return he(e)||Y(e)||!B(e)||(ce(e)>1&&(e.set=e.add=e.clear=e.delete=ua),Object.freeze(e),t&&Object.entries(e).forEach(([r,n])=>qe(n,!0))),e}function ua(){I(2)}function he(e){return Object.isFrozen(e)}var sa={};function K(e){const t=sa[e];return t||I(0,e),t}var Z;function mr(){return Z}function la(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function yr(e,t){t&&(K("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function De(e){ke(e),e.drafts_.forEach(ca),e.drafts_=null}function ke(e){e===Z&&(Z=e.parent_)}function vr(e){return Z=la(Z,e)}function ca(e){const t=e[j];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function gr(e,t){t.unfinalizedDrafts_=t.drafts_.length;const r=t.drafts_[0];return e!==void 0&&e!==r?(r[j].modified_&&(De(t),I(4)),B(e)&&(e=pe(t,e),t.parent_||me(t,e)),t.patches_&&K("Patches").generateReplacementPatches_(r[j].base_,e,t.patches_,t.inversePatches_)):e=pe(t,r,[]),De(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==fr?e:void 0}function pe(e,t,r){if(he(t))return t;const n=t[j];if(!n)return le(t,(a,i)=>_r(e,n,t,a,i,r)),t;if(n.scope_!==e)return t;if(!n.modified_)return me(e,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;const a=n.copy_;let i=a,o=!1;n.type_===3&&(i=new Set(a),a.clear(),o=!0),le(i,(u,s)=>_r(e,n,a,u,s,r,o)),me(e,a,!1),r&&e.patches_&&K("Patches").generatePatches_(n,r,e.patches_,e.inversePatches_)}return n.copy_}function _r(e,t,r,n,a,i,o){if(process.env.NODE_ENV!=="production"&&a===r&&I(5),Y(a)){const u=i&&t&&t.type_!==3&&!Oe(t.assigned_,n)?i.concat(n):void 0,s=pe(e,a,u);if(pr(r,n,s),Y(s))e.canAutoFreeze_=!1;else return}else o&&r.add(a);if(B(a)&&!he(a)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;pe(e,a),(!t||!t.scope_.parent_)&&typeof n!="symbol"&&Object.prototype.propertyIsEnumerable.call(r,n)&&me(e,a)}}function me(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&qe(t,r)}function fa(e,t){const r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:mr(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let a=n,i=Ie;r&&(a=[n],i=Q);const{revoke:o,proxy:u}=Proxy.revocable(a,i);return n.draft_=u,n.revoke_=o,u}var Ie={get(e,t){if(t===j)return e;const r=W(e);if(!Oe(r,t))return da(e,r,t);const n=r[t];return e.finalized_||!B(n)?n:n===je(e.base_,t)?(Ae(e),e.copy_[t]=Le(n,e)):n},has(e,t){return t in W(e)},ownKeys(e){return Reflect.ownKeys(W(e))},set(e,t,r){const n=br(W(e),t);if(n!=null&&n.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){const a=je(W(e),t),i=a==null?void 0:a[j];if(i&&i.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(oa(r,a)&&(r!==void 0||Oe(e.base_,t)))return!0;Ae(e),Me(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty(e,t){return je(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,Ae(e),Me(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const r=W(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:n.enumerable,value:r[t]}},defineProperty(){I(11)},getPrototypeOf(e){return J(e.base_)},setPrototypeOf(){I(12)}},Q={};le(Ie,(e,t)=>{Q[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}}),Q.deleteProperty=function(e,t){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(t))&&I(13),Q.set.call(this,e,t,void 0)},Q.set=function(e,t,r){return process.env.NODE_ENV!=="production"&&t!=="length"&&isNaN(parseInt(t))&&I(14),Ie.set.call(this,e[0],t,r,e[0])};function je(e,t){const r=e[j];return(r?W(r):e)[t]}function da(e,t,r){var a;const n=br(t,r);return n?"value"in n?n.value:(a=n.get)==null?void 0:a.call(e.draft_):void 0}function br(e,t){if(!(t in e))return;let r=J(e);for(;r;){const n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=J(r)}}function Me(e){e.modified_||(e.modified_=!0,e.parent_&&Me(e.parent_))}function Ae(e){e.copy_||(e.copy_=Te(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var wr=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,r,n)=>{if(typeof t=="function"&&typeof r!="function"){const i=r;r=t;const o=this;return function(s=i,...l){return o.produce(s,m=>r.call(this,m,...l))}}typeof r!="function"&&I(6),n!==void 0&&typeof n!="function"&&I(7);let a;if(B(t)){const i=vr(this),o=Le(t,void 0);let u=!0;try{a=r(o),u=!1}finally{u?De(i):ke(i)}return yr(i,n),gr(a,i)}else if(!t||typeof t!="object"){if(a=r(t),a===void 0&&(a=t),a===fr&&(a=void 0),this.autoFreeze_&&qe(a,!0),n){const i=[],o=[];K("Patches").generateReplacementPatches_(t,a,i,o),n(i,o)}return a}else I(1,t)},this.produceWithPatches=(t,r)=>{if(typeof t=="function")return(o,...u)=>this.produceWithPatches(o,s=>t(s,...u));let n,a;return[this.produce(t,r,(o,u)=>{n=o,a=u}),n,a]},typeof(e==null?void 0:e.autoFreeze)=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof(e==null?void 0:e.useStrictShallowCopy)=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){B(e)||I(8),Y(e)&&(e=ha(e));const t=vr(this),r=Le(e,void 0);return r[j].isManual_=!0,ke(t),r}finishDraft(e,t){const r=e&&e[j];(!r||!r.isManual_)&&I(9);const{scope_:n}=r;return yr(n,t),gr(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){const a=t[r];if(a.path.length===0&&a.op==="replace"){e=a.value;break}}r>-1&&(t=t.slice(r+1));const n=K("Patches").applyPatches_;return Y(e)?n(e,t):this.produce(e,a=>n(a,t))}};function Le(e,t){const r=fe(e)?K("MapSet").proxyMap_(e,t):de(e)?K("MapSet").proxySet_(e,t):fa(e,t);return(t?t.scope_:mr()).drafts_.push(r),r}function ha(e){return Y(e)||I(10,e),Cr(e)}function Cr(e){if(!B(e)||he(e))return e;const t=e[j];let r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=Te(e,t.scope_.immer_.useStrictShallowCopy_)}else r=Te(e,!0);return le(r,(n,a)=>{pr(r,n,Cr(a))}),t&&(t.finalized_=!1),r}var M=new wr;M.produce,M.produceWithPatches.bind(M),M.setAutoFreeze.bind(M),M.setUseStrictShallowCopy.bind(M),M.applyPatches.bind(M),M.createDraft.bind(M),M.finishDraft.bind(M);const A={immer:new wr,annotations:Symbol("annotations")};A.immer.setAutoFreeze(!1);class Ne{constructor(t,r,n=null){nr(this,"process");this.value=t,this.operations=r,this.field=n,this.process=null}attach(t){return this.process=t,this}}function pa(e,t=[]){return new Ne(e,t)}var ye=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Sr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Fe,Rr;function $e(){if(Rr)return Fe;Rr=1;var e=Array.isArray;return Fe=e,Fe}var ze,Er;function ma(){if(Er)return ze;Er=1;var e=typeof ye=="object"&&ye&&ye.Object===Object&&ye;return ze=e,ze}var He,Pr;function Ue(){if(Pr)return He;Pr=1;var e=ma(),t=typeof self=="object"&&self&&self.Object===Object&&self,r=e||t||Function("return this")();return He=r,He}var Ge,xr;function Be(){if(xr)return Ge;xr=1;var e=Ue(),t=e.Symbol;return Ge=t,Ge}var We,Or;function ya(){if(Or)return We;Or=1;var e=Be(),t=Object.prototype,r=t.hasOwnProperty,n=t.toString,a=e?e.toStringTag:void 0;function i(o){var u=r.call(o,a),s=o[a];try{o[a]=void 0;var l=!0}catch{}var m=n.call(o);return l&&(u?o[a]=s:delete o[a]),m}return We=i,We}var Ke,Tr;function va(){if(Tr)return Ke;Tr=1;var e=Object.prototype,t=e.toString;function r(n){return t.call(n)}return Ke=r,Ke}var Ve,qr;function Dr(){if(qr)return Ve;qr=1;var e=Be(),t=ya(),r=va(),n="[object Null]",a="[object Undefined]",i=e?e.toStringTag:void 0;function o(u){return u==null?u===void 0?a:n:i&&i in Object(u)?t(u):r(u)}return Ve=o,Ve}var Je,kr;function ga(){if(kr)return Je;kr=1;function e(t){return t!=null&&typeof t=="object"}return Je=e,Je}var Ye,Ir;function Xe(){if(Ir)return Ye;Ir=1;var e=Dr(),t=ga(),r="[object Symbol]";function n(a){return typeof a=="symbol"||t(a)&&e(a)==r}return Ye=n,Ye}var Ze,jr;function _a(){if(jr)return Ze;jr=1;var e=$e(),t=Xe(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,n=/^\w*$/;function a(i,o){if(e(i))return!1;var u=typeof i;return u=="number"||u=="symbol"||u=="boolean"||i==null||t(i)?!0:n.test(i)||!r.test(i)||o!=null&&i in Object(o)}return Ze=a,Ze}var Qe,Mr;function Ar(){if(Mr)return Qe;Mr=1;function e(t){var r=typeof t;return t!=null&&(r=="object"||r=="function")}return Qe=e,Qe}var et,Lr;function ba(){if(Lr)return et;Lr=1;var e=Dr(),t=Ar(),r="[object AsyncFunction]",n="[object Function]",a="[object GeneratorFunction]",i="[object Proxy]";function o(u){if(!t(u))return!1;var s=e(u);return s==n||s==a||s==r||s==i}return et=o,et}var tt,Nr;function wa(){if(Nr)return tt;Nr=1;var e=Ue(),t=e["__core-js_shared__"];return tt=t,tt}var rt,Fr;function Ca(){if(Fr)return rt;Fr=1;var e=wa(),t=function(){var n=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""}();function r(n){return!!t&&t in n}return rt=r,rt}var nt,$r;function Sa(){if($r)return nt;$r=1;var e=Function.prototype,t=e.toString;function r(n){if(n!=null){try{return t.call(n)}catch{}try{return n+""}catch{}}return""}return nt=r,nt}var at,zr;function Ra(){if(zr)return at;zr=1;var e=ba(),t=Ca(),r=Ar(),n=Sa(),a=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,o=Function.prototype,u=Object.prototype,s=o.toString,l=u.hasOwnProperty,m=RegExp("^"+s.call(l).replace(a,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function v(h){if(!r(h)||t(h))return!1;var _=e(h)?m:i;return _.test(n(h))}return at=v,at}var it,Hr;function Ea(){if(Hr)return it;Hr=1;function e(t,r){return t==null?void 0:t[r]}return it=e,it}var ot,Ur;function Gr(){if(Ur)return ot;Ur=1;var e=Ra(),t=Ea();function r(n,a){var i=t(n,a);return e(i)?i:void 0}return ot=r,ot}var ut,Br;function ve(){if(Br)return ut;Br=1;var e=Gr(),t=e(Object,"create");return ut=t,ut}var st,Wr;function Pa(){if(Wr)return st;Wr=1;var e=ve();function t(){this.__data__=e?e(null):{},this.size=0}return st=t,st}var lt,Kr;function xa(){if(Kr)return lt;Kr=1;function e(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r}return lt=e,lt}var ct,Vr;function Oa(){if(Vr)return ct;Vr=1;var e=ve(),t="__lodash_hash_undefined__",r=Object.prototype,n=r.hasOwnProperty;function a(i){var o=this.__data__;if(e){var u=o[i];return u===t?void 0:u}return n.call(o,i)?o[i]:void 0}return ct=a,ct}var ft,Jr;function Ta(){if(Jr)return ft;Jr=1;var e=ve(),t=Object.prototype,r=t.hasOwnProperty;function n(a){var i=this.__data__;return e?i[a]!==void 0:r.call(i,a)}return ft=n,ft}var dt,Yr;function qa(){if(Yr)return dt;Yr=1;var e=ve(),t="__lodash_hash_undefined__";function r(n,a){var i=this.__data__;return this.size+=this.has(n)?0:1,i[n]=e&&a===void 0?t:a,this}return dt=r,dt}var ht,Xr;function Da(){if(Xr)return ht;Xr=1;var e=Pa(),t=xa(),r=Oa(),n=Ta(),a=qa();function i(o){var u=-1,s=o==null?0:o.length;for(this.clear();++u<s;){var l=o[u];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=a,ht=i,ht}var pt,Zr;function ka(){if(Zr)return pt;Zr=1;function e(){this.__data__=[],this.size=0}return pt=e,pt}var mt,Qr;function Ia(){if(Qr)return mt;Qr=1;function e(t,r){return t===r||t!==t&&r!==r}return mt=e,mt}var yt,en;function ge(){if(en)return yt;en=1;var e=Ia();function t(r,n){for(var a=r.length;a--;)if(e(r[a][0],n))return a;return-1}return yt=t,yt}var vt,tn;function ja(){if(tn)return vt;tn=1;var e=ge(),t=Array.prototype,r=t.splice;function n(a){var i=this.__data__,o=e(i,a);if(o<0)return!1;var u=i.length-1;return o==u?i.pop():r.call(i,o,1),--this.size,!0}return vt=n,vt}var gt,rn;function Ma(){if(rn)return gt;rn=1;var e=ge();function t(r){var n=this.__data__,a=e(n,r);return a<0?void 0:n[a][1]}return gt=t,gt}var _t,nn;function Aa(){if(nn)return _t;nn=1;var e=ge();function t(r){return e(this.__data__,r)>-1}return _t=t,_t}var bt,an;function La(){if(an)return bt;an=1;var e=ge();function t(r,n){var a=this.__data__,i=e(a,r);return i<0?(++this.size,a.push([r,n])):a[i][1]=n,this}return bt=t,bt}var wt,on;function Na(){if(on)return wt;on=1;var e=ka(),t=ja(),r=Ma(),n=Aa(),a=La();function i(o){var u=-1,s=o==null?0:o.length;for(this.clear();++u<s;){var l=o[u];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=a,wt=i,wt}var Ct,un;function Fa(){if(un)return Ct;un=1;var e=Gr(),t=Ue(),r=e(t,"Map");return Ct=r,Ct}var St,sn;function $a(){if(sn)return St;sn=1;var e=Da(),t=Na(),r=Fa();function n(){this.size=0,this.__data__={hash:new e,map:new(r||t),string:new e}}return St=n,St}var Rt,ln;function za(){if(ln)return Rt;ln=1;function e(t){var r=typeof t;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?t!=="__proto__":t===null}return Rt=e,Rt}var Et,cn;function _e(){if(cn)return Et;cn=1;var e=za();function t(r,n){var a=r.__data__;return e(n)?a[typeof n=="string"?"string":"hash"]:a.map}return Et=t,Et}var Pt,fn;function Ha(){if(fn)return Pt;fn=1;var e=_e();function t(r){var n=e(this,r).delete(r);return this.size-=n?1:0,n}return Pt=t,Pt}var xt,dn;function Ua(){if(dn)return xt;dn=1;var e=_e();function t(r){return e(this,r).get(r)}return xt=t,xt}var Ot,hn;function Ga(){if(hn)return Ot;hn=1;var e=_e();function t(r){return e(this,r).has(r)}return Ot=t,Ot}var Tt,pn;function Ba(){if(pn)return Tt;pn=1;var e=_e();function t(r,n){var a=e(this,r),i=a.size;return a.set(r,n),this.size+=a.size==i?0:1,this}return Tt=t,Tt}var qt,mn;function Wa(){if(mn)return qt;mn=1;var e=$a(),t=Ha(),r=Ua(),n=Ga(),a=Ba();function i(o){var u=-1,s=o==null?0:o.length;for(this.clear();++u<s;){var l=o[u];this.set(l[0],l[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=r,i.prototype.has=n,i.prototype.set=a,qt=i,qt}var Dt,yn;function Ka(){if(yn)return Dt;yn=1;var e=Wa(),t="Expected a function";function r(n,a){if(typeof n!="function"||a!=null&&typeof a!="function")throw new TypeError(t);var i=function(){var o=arguments,u=a?a.apply(this,o):o[0],s=i.cache;if(s.has(u))return s.get(u);var l=n.apply(this,o);return i.cache=s.set(u,l)||s,l};return i.cache=new(r.Cache||e),i}return r.Cache=e,Dt=r,Dt}var kt,vn;function Va(){if(vn)return kt;vn=1;var e=Ka(),t=500;function r(n){var a=e(n,function(o){return i.size===t&&i.clear(),o}),i=a.cache;return a}return kt=r,kt}var It,gn;function Ja(){if(gn)return It;gn=1;var e=Va(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,n=e(function(a){var i=[];return a.charCodeAt(0)===46&&i.push(""),a.replace(t,function(o,u,s,l){i.push(s?l.replace(r,"$1"):u||o)}),i});return It=n,It}var jt,_n;function Ya(){if(_n)return jt;_n=1;function e(t,r){for(var n=-1,a=t==null?0:t.length,i=Array(a);++n<a;)i[n]=r(t[n],n,t);return i}return jt=e,jt}var Mt,bn;function Xa(){if(bn)return Mt;bn=1;var e=Be(),t=Ya(),r=$e(),n=Xe(),a=e?e.prototype:void 0,i=a?a.toString:void 0;function o(u){if(typeof u=="string")return u;if(r(u))return t(u,o)+"";if(n(u))return i?i.call(u):"";var s=u+"";return s=="0"&&1/u==-1/0?"-0":s}return Mt=o,Mt}var At,wn;function Za(){if(wn)return At;wn=1;var e=Xa();function t(r){return r==null?"":e(r)}return At=t,At}var Lt,Cn;function Qa(){if(Cn)return Lt;Cn=1;var e=$e(),t=_a(),r=Ja(),n=Za();function a(i,o){return e(i)?i:t(i,o)?[i]:r(n(i))}return Lt=a,Lt}var Nt,Sn;function ei(){if(Sn)return Nt;Sn=1;var e=Xe();function t(r){if(typeof r=="string"||e(r))return r;var n=r+"";return n=="0"&&1/r==-1/0?"-0":n}return Nt=t,Nt}var Ft,Rn;function ti(){if(Rn)return Ft;Rn=1;var e=Qa(),t=ei();function r(n,a){a=e(a,n);for(var i=0,o=a.length;n!=null&&i<o;)n=n[t(a[i++])];return i&&i==o?n:void 0}return Ft=r,Ft}var $t,En;function ri(){if(En)return $t;En=1;var e=ti();function t(r,n,a){var i=r==null?void 0:e(r,n);return i===void 0?a:i}return $t=t,$t}var ni=ri();const ee=Sr(ni);class zt{constructor(t,r=t){this.stateless=t,this.stateful=r}get validatable(){return Pn(this.stateful)}}function Pn(e,t=[]){return new Proxy(e,{get(r,n){switch(n){case"is":return a=>{const i=Ht(e,t);if(!i)return!1;const o=new Set(i.flatMap(s=>s.operations));return!!(Array.from(o).reduce((s,l)=>s|(l??0),0)&a)};case"pending":return()=>!!Ht(e,t);case"draft":return()=>{const a=Ht(e,t);if(!a)return ee(e,t);const i=a.flatMap(o=>o.operations).find(o=>o instanceof lr);return i?i.value:ee(e,t)}}return Pn(e,[...t,String(n)])}})}function Ht(e,t){const n=typeof ee(e,t)=="object"?t:t.slice(0,-1),a=n.length===0?e:ee(e,n),i=(a==null?void 0:a[A.annotations])??[];return i.length>0?i:null}var Ut,xn;function ai(){if(xn)return Ut;xn=1;function e(c){return Object.prototype.toString.call(c)}function t(c){return e(c)==="[object Date]"}function r(c){return e(c)==="[object RegExp]"}function n(c){return e(c)==="[object Error]"}function a(c){return e(c)==="[object Boolean]"}function i(c){return e(c)==="[object Number]"}function o(c){return e(c)==="[object String]"}var u=Array.isArray||function(p){return Object.prototype.toString.call(p)==="[object Array]"};function s(c,p){if(c.forEach)return c.forEach(p);for(var b=0;b<c.length;b++)p(c[b],b,c)}var l=Object.keys||function(p){var b=[];for(var g in p)b.push(g);return b},m=Object.prototype.propertyIsEnumerable,v=Object.getOwnPropertySymbols;function h(c){var p=l(c);if(v)for(var b=v(c),g=0;g<b.length;g++)m.call(c,b[g])&&p.push(b[g]);return p}var _=Object.prototype.hasOwnProperty||function(c,p){return p in c};function d(c){if(typeof c=="object"&&c!==null){var p;if(u(c))p=[];else if(t(c))p=new Date(c.getTime?c.getTime():c);else if(r(c))p=new RegExp(c);else if(n(c))p={message:c.message};else if(a(c)||i(c)||o(c))p=Object(c);else if(Object.create&&Object.getPrototypeOf)p=Object.create(Object.getPrototypeOf(c));else if(c.constructor===Object)p={};else{var b=c.constructor&&c.constructor.prototype||c.__proto__||{},g=function(){};g.prototype=b,p=new g}return s(h(c),function(P){p[P]=c[P]}),p}return c}function S(c,p,b){var g=[],P=[],D=!0;return function L(T){var $=b?d(T):T,k={},ue=!0,w={node:$,node_:T,path:[].concat(g),parent:P[P.length-1],parents:P,key:g[g.length-1],isRoot:g.length===0,level:g.length,circular:null,update:function(x,Pe){w.isRoot||(w.parent.node[w.key]=x),w.node=x,Pe&&(ue=!1)},delete:function(x){delete w.parent.node[w.key],x&&(ue=!1)},remove:function(x){u(w.parent.node)?w.parent.node.splice(w.key,1):delete w.parent.node[w.key],x&&(ue=!1)},keys:null,before:function(x){k.before=x},after:function(x){k.after=x},pre:function(x){k.pre=x},post:function(x){k.post=x},stop:function(){D=!1},block:function(){ue=!1}};if(!D)return w;function Yn(){if(typeof w.node=="object"&&w.node!==null){(!w.keys||w.node_!==w.node)&&(w.keys=h(w.node)),w.isLeaf=w.keys.length===0;for(var x=0;x<P.length;x++)if(P[x].node_===T){w.circular=P[x];break}}else w.isLeaf=!0,w.keys=null;w.notLeaf=!w.isLeaf,w.notRoot=!w.isRoot}Yn();var Xn=p.call(w,w.node);return Xn!==void 0&&w.update&&w.update(Xn),k.before&&k.before.call(w,w.node),ue&&(typeof w.node=="object"&&w.node!==null&&!w.circular&&(P.push(w),Yn(),s(w.keys,function(x,Pe){g.push(x),k.pre&&k.pre.call(w,w.node[x],x);var xe=L(w.node[x]);b&&_.call(w.node,x)&&(w.node[x]=xe.node),xe.isLast=Pe===w.keys.length-1,xe.isFirst=Pe===0,k.post&&k.post.call(w,xe),g.pop()}),P.pop()),k.after&&k.after.call(w,w.node)),w}(c).node}function C(c){this.value=c}C.prototype.get=function(c){for(var p=this.value,b=0;b<c.length;b++){var g=c[b];if(!p||!_.call(p,g))return;p=p[g]}return p},C.prototype.has=function(c){for(var p=this.value,b=0;b<c.length;b++){var g=c[b];if(!p||!_.call(p,g))return!1;p=p[g]}return!0},C.prototype.set=function(c,p){for(var b=this.value,g=0;g<c.length-1;g++){var P=c[g];_.call(b,P)||(b[P]={}),b=b[P]}return b[c[g]]=p,p},C.prototype.map=function(c){return S(this.value,c,!0)},C.prototype.forEach=function(c){return this.value=S(this.value,c,!1),this.value},C.prototype.reduce=function(c,p){var b=arguments.length===1,g=b?this.value:p;return this.forEach(function(P){(!this.isRoot||!b)&&(g=c.call(this,g,P))}),g},C.prototype.paths=function(){var c=[];return this.forEach(function(){c.push(this.path)}),c},C.prototype.nodes=function(){var c=[];return this.forEach(function(){c.push(this.node)}),c},C.prototype.clone=function(){var c=[],p=[];return function b(g){for(var P=0;P<c.length;P++)if(c[P]===g)return p[P];if(typeof g=="object"&&g!==null){var D=d(g);return c.push(g),p.push(D),s(h(g),function(L){D[L]=b(g[L])}),c.pop(),p.pop(),D}return g}(this.value)};function y(c){return new C(c)}return s(h(C.prototype),function(c){y[c]=function(p){var b=[].slice.call(arguments,1),g=new C(p);return g[c].apply(g,b)}}),Ut=y,Ut}var ii=ai();const Gt=Sr(ii);function oi(e,t,r){function n(i){return Gt(i).forEach(function(){if(this.key===A.annotations){this.block();return}this.node instanceof Ne&&this.update(this.node.value)})}function a(i){return Gt(i).forEach(function(){if(this.key===A.annotations){this.block();return}if(this.node instanceof Ne){const o=typeof this.node.value=="object",u=[...o?this.path:this.path.slice(0,-1),A.annotations],s=ee(e.stateful,u)??[],l=this.node.attach(t);o?this.update({...this.node.value,[A.annotations]:[l,...s]},!0):(this.parent&&(this.parent.node[A.annotations]=[l,...s]),this.update(this.node.value,!0))}})}return new zt(n(A.immer.produce(e.stateless,r)),a(A.immer.produce(e.stateful,r)))}function ui(e,t){const r=Gt(e.stateful).forEach(function(){if(this.key===A.annotations){this.block();return}if(this.node&&this.node[A.annotations]){const n=this.node[A.annotations];this.update({...this.node,[A.annotations]:n.filter(a=>a.process!==t)},!0)}});return new zt(e.stateless,r)}function si(e){return f.useMemo(()=>({controller:{get model(){return e.model.current.stateful},get router(){return e.router.current},queue:[],events:e.options.props,actions:{annotate(t,r){return pa(t,r)},produce(t){return(r,n)=>oi(r,n,t)},dispatch([t,...r]){const n=Promise.withResolvers();return e.dispatchers.dispatch(t,r,n),n.promise}}},view:{get model(){return e.model.current.stateless},get validate(){return e.model.current.validatable},get router(){return e.router.current},events:e.options.props,actions:{dispatch([t,...r]){const n=Promise.withResolvers();return e.dispatchers.dispatch(t,r,n),n.promise}}}}),[])}function li(e){return f.useMemo(()=>{const t=e.options.controller(e.actions.controller);return Object.entries(t).forEach(([n,a])=>e.dispatchers.attach(n,a)),t},[])}function ci(e){return(t,r)=>async(n=Promise.withResolvers(),a)=>{if(typeof r!="function")return;const i=Symbol("process"),o=r(...a);for(;;){const{value:u,done:s}=await o.next();if(s){const m=u(e.model.current,i);e.model.current=ui(m,i),e.update.rerender();break}const l=u;e.model.current=l(e.model.current,i),e.update.rerender()}n.resolve()}}function On(e){return e.startsWith("distributed")}class Tn extends Error{constructor(r,n=null){super(String(n));ir(this,ie);ir(this,oe);or(this,ie,r),or(this,oe,n)}get type(){return ar(this,ie)}get message(){return ar(this,oe)||""}}ie=new WeakMap,oe=new WeakMap;function fi(e){const t=sr(),r=ci(e);return f.useMemo(()=>{const n=new O,a=t.appEmitter;return{attach(i,o){const u=String(i);On(u)?a.on(u,r(i,o)):n.on(u,r(i,o))},dispatch(i,o,u){const s=String(i);On(s)?a.emit(s,u,o):n.emit(s,u,o)}}},[])}function di(){const e=f.useRef(null);return f.useMemo(()=>({customElement:e}),[])}function hi(e){const t=f.useRef(!1);f.useLayoutEffect(()=>{e.dispatchers.dispatch(V.Derive,[e.options.props])},[e.options.props]),f.useLayoutEffect(()=>{if(!t.current)return t.current=!0,e.dispatchers.dispatch(V.Mount,[]),e.dispatchers.dispatch(V.Tree,[e.elements.customElement.current]),()=>e.dispatchers.dispatch(V.Unmount,[])},[])}function pi(e){return f.useMemo(()=>({output(t){const r=e.elements.customElement.current;console.groupCollapsed("%cRendered","background: rgb(217, 235, 240); color: rgb(0, 51, 102); border-radius: 2px; padding: 0 5px",r),console.groupEnd()}}),[])}function mi(e){return f.useRef(new zt(e.options.model,e.options.model))}function yi(){return f.useRef(new Set)}var te={},qn;function vi(){if(qn)return te;qn=1,Object.defineProperty(te,"__esModule",{value:!0}),te.parse=o,te.serialize=l;const e=/^[\u0021-\u003A\u003C\u003E-\u007E]+$/,t=/^[\u0021-\u003A\u003C-\u007E]*$/,r=/^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i,n=/^[\u0020-\u003A\u003D-\u007E]*$/,a=Object.prototype.toString,i=(()=>{const h=function(){};return h.prototype=Object.create(null),h})();function o(h,_){const d=new i,S=h.length;if(S<2)return d;const C=(_==null?void 0:_.decode)||m;let y=0;do{const c=h.indexOf("=",y);if(c===-1)break;const p=h.indexOf(";",y),b=p===-1?S:p;if(c>b){y=h.lastIndexOf(";",c-1)+1;continue}const g=u(h,y,c),P=s(h,c,g),D=h.slice(g,P);if(d[D]===void 0){let L=u(h,c+1,b),T=s(h,b,L);const $=C(h.slice(L,T));d[D]=$}y=b+1}while(y<S);return d}function u(h,_,d){do{const S=h.charCodeAt(_);if(S!==32&&S!==9)return _}while(++_<d);return d}function s(h,_,d){for(;_>d;){const S=h.charCodeAt(--_);if(S!==32&&S!==9)return _+1}return d}function l(h,_,d){const S=(d==null?void 0:d.encode)||encodeURIComponent;if(!e.test(h))throw new TypeError(`argument name is invalid: ${h}`);const C=S(_);if(!t.test(C))throw new TypeError(`argument val is invalid: ${_}`);let y=h+"="+C;if(!d)return y;if(d.maxAge!==void 0){if(!Number.isInteger(d.maxAge))throw new TypeError(`option maxAge is invalid: ${d.maxAge}`);y+="; Max-Age="+d.maxAge}if(d.domain){if(!r.test(d.domain))throw new TypeError(`option domain is invalid: ${d.domain}`);y+="; Domain="+d.domain}if(d.path){if(!n.test(d.path))throw new TypeError(`option path is invalid: ${d.path}`);y+="; Path="+d.path}if(d.expires){if(!v(d.expires)||!Number.isFinite(d.expires.valueOf()))throw new TypeError(`option expires is invalid: ${d.expires}`);y+="; Expires="+d.expires.toUTCString()}if(d.httpOnly&&(y+="; HttpOnly"),d.secure&&(y+="; Secure"),d.partitioned&&(y+="; Partitioned"),d.priority)switch(typeof d.priority=="string"?d.priority.toLowerCase():void 0){case"low":y+="; Priority=Low";break;case"medium":y+="; Priority=Medium";break;case"high":y+="; Priority=High";break;default:throw new TypeError(`option priority is invalid: ${d.priority}`)}if(d.sameSite)switch(typeof d.sameSite=="string"?d.sameSite.toLowerCase():d.sameSite){case!0:case"strict":y+="; SameSite=Strict";break;case"lax":y+="; SameSite=Lax";break;case"none":y+="; SameSite=None";break;default:throw new TypeError(`option sameSite is invalid: ${d.sameSite}`)}return y}function m(h){if(h.indexOf("%")===-1)return h;try{return decodeURIComponent(h)}catch{return h}}function v(h){return a.call(h)==="[object Date]"}return te}vi();/**
2
+ * react-router v7.6.0
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */function q(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}function N(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function Bt({pathname:e="/",search:t="",hash:r=""}){return t&&t!=="?"&&(e+=t.charAt(0)==="?"?t:"?"+t),r&&r!=="#"&&(e+=r.charAt(0)==="#"?r:"#"+r),e}function Wt(e){let t={};if(e){let r=e.indexOf("#");r>=0&&(t.hash=e.substring(r),e=e.substring(0,r));let n=e.indexOf("?");n>=0&&(t.search=e.substring(n),e=e.substring(0,n)),e&&(t.pathname=e)}return t}function Dn(e,t,r="/"){return gi(e,t,r,!1)}function gi(e,t,r,n){let a=typeof t=="string"?Wt(t):t,i=G(a.pathname||"/",r);if(i==null)return null;let o=kn(e);_i(o);let u=null;for(let s=0;u==null&&s<o.length;++s){let l=qi(i);u=Oi(o[s],l,n)}return u}function kn(e,t=[],r=[],n=""){let a=(i,o,u)=>{let s={relativePath:u===void 0?i.path||"":u,caseSensitive:i.caseSensitive===!0,childrenIndex:o,route:i};s.relativePath.startsWith("/")&&(q(s.relativePath.startsWith(n),`Absolute route path "${s.relativePath}" nested under path "${n}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),s.relativePath=s.relativePath.slice(n.length));let l=z([n,s.relativePath]),m=r.concat(s);i.children&&i.children.length>0&&(q(i.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${l}".`),kn(i.children,t,m,l)),!(i.path==null&&!i.index)&&t.push({path:l,score:Pi(l,i.index),routesMeta:m})};return e.forEach((i,o)=>{var u;if(i.path===""||!((u=i.path)!=null&&u.includes("?")))a(i,o);else for(let s of In(i.path))a(i,o,s)}),t}function In(e){let t=e.split("/");if(t.length===0)return[];let[r,...n]=t,a=r.endsWith("?"),i=r.replace(/\?$/,"");if(n.length===0)return a?[i,""]:[i];let o=In(n.join("/")),u=[];return u.push(...o.map(s=>s===""?i:[i,s].join("/"))),a&&u.push(...o),u.map(s=>e.startsWith("/")&&s===""?"/":s)}function _i(e){e.sort((t,r)=>t.score!==r.score?r.score-t.score:xi(t.routesMeta.map(n=>n.childrenIndex),r.routesMeta.map(n=>n.childrenIndex)))}var bi=/^:[\w-]+$/,wi=3,Ci=2,Si=1,Ri=10,Ei=-2,jn=e=>e==="*";function Pi(e,t){let r=e.split("/"),n=r.length;return r.some(jn)&&(n+=Ei),t&&(n+=Ci),r.filter(a=>!jn(a)).reduce((a,i)=>a+(bi.test(i)?wi:i===""?Si:Ri),n)}function xi(e,t){return e.length===t.length&&e.slice(0,-1).every((n,a)=>n===t[a])?e[e.length-1]-t[t.length-1]:0}function Oi(e,t,r=!1){let{routesMeta:n}=e,a={},i="/",o=[];for(let u=0;u<n.length;++u){let s=n[u],l=u===n.length-1,m=i==="/"?t:t.slice(i.length)||"/",v=be({path:s.relativePath,caseSensitive:s.caseSensitive,end:l},m),h=s.route;if(!v&&l&&r&&!n[n.length-1].route.index&&(v=be({path:s.relativePath,caseSensitive:s.caseSensitive,end:!1},m)),!v)return null;Object.assign(a,v.params),o.push({params:a,pathname:z([i,v.pathname]),pathnameBase:ji(z([i,v.pathnameBase])),route:h}),v.pathnameBase!=="/"&&(i=z([i,v.pathnameBase]))}return o}function be(e,t){typeof e=="string"&&(e={path:e,caseSensitive:!1,end:!0});let[r,n]=Ti(e.path,e.caseSensitive,e.end),a=t.match(r);if(!a)return null;let i=a[0],o=i.replace(/(.)\/+$/,"$1"),u=a.slice(1);return{params:n.reduce((l,{paramName:m,isOptional:v},h)=>{if(m==="*"){let d=u[h]||"";o=i.slice(0,i.length-d.length).replace(/(.)\/+$/,"$1")}const _=u[h];return v&&!_?l[m]=void 0:l[m]=(_||"").replace(/%2F/g,"/"),l},{}),pathname:i,pathnameBase:o,pattern:e}}function Ti(e,t=!1,r=!0){N(e==="*"||!e.endsWith("*")||e.endsWith("/*"),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,"/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,"/*")}".`);let n=[],a="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(o,u,s)=>(n.push({paramName:u,isOptional:s!=null}),s?"/?([^\\/]+)?":"/([^\\/]+)"));return e.endsWith("*")?(n.push({paramName:"*"}),a+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):r?a+="\\/*$":e!==""&&e!=="/"&&(a+="(?:(?=\\/|$))"),[new RegExp(a,t?void 0:"i"),n]}function qi(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return N(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`),e}}function G(e,t){if(t==="/")return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let r=t.endsWith("/")?t.length-1:t.length,n=e.charAt(r);return n&&n!=="/"?null:e.slice(r)||"/"}function Di(e,t="/"){let{pathname:r,search:n="",hash:a=""}=typeof e=="string"?Wt(e):e;return{pathname:r?r.startsWith("/")?r:ki(r,t):t,search:Mi(n),hash:Ai(a)}}function ki(e,t){let r=t.replace(/\/+$/,"").split("/");return e.split("/").forEach(a=>{a===".."?r.length>1&&r.pop():a!=="."&&r.push(a)}),r.length>1?r.join("/"):"/"}function Kt(e,t,r,n){return`Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(n)}]. Please separate it out to the \`to.${r}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function Ii(e){return e.filter((t,r)=>r===0||t.route.path&&t.route.path.length>0)}function Mn(e){let t=Ii(e);return t.map((r,n)=>n===t.length-1?r.pathname:r.pathnameBase)}function An(e,t,r,n=!1){let a;typeof e=="string"?a=Wt(e):(a={...e},q(!a.pathname||!a.pathname.includes("?"),Kt("?","pathname","search",a)),q(!a.pathname||!a.pathname.includes("#"),Kt("#","pathname","hash",a)),q(!a.search||!a.search.includes("#"),Kt("#","search","hash",a)));let i=e===""||a.pathname==="",o=i?"/":a.pathname,u;if(o==null)u=r;else{let v=t.length-1;if(!n&&o.startsWith("..")){let h=o.split("/");for(;h[0]==="..";)h.shift(),v-=1;a.pathname=h.join("/")}u=v>=0?t[v]:"/"}let s=Di(a,u),l=o&&o!=="/"&&o.endsWith("/"),m=(i||o===".")&&r.endsWith("/");return!s.pathname.endsWith("/")&&(l||m)&&(s.pathname+="/"),s}var z=e=>e.join("/").replace(/\/\/+/g,"/"),ji=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),Mi=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,Ai=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e;function Li(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}var Ln=["POST","PUT","PATCH","DELETE"];new Set(Ln);var Ni=["GET",...Ln];new Set(Ni);var X=f.createContext(null);X.displayName="DataRouter";var we=f.createContext(null);we.displayName="DataRouterState";var Nn=f.createContext({isTransitioning:!1});Nn.displayName="ViewTransition";var Fi=f.createContext(new Map);Fi.displayName="Fetchers";var $i=f.createContext(null);$i.displayName="Await";var H=f.createContext(null);H.displayName="Navigation";var Vt=f.createContext(null);Vt.displayName="Location";var F=f.createContext({outlet:null,matches:[],isDataRoute:!1});F.displayName="Route";var Jt=f.createContext(null);Jt.displayName="RouteError";function zi(e,{relative:t}={}){q(re(),"useHref() may be used only in the context of a <Router> component.");let{basename:r,navigator:n}=f.useContext(H),{hash:a,pathname:i,search:o}=ne(e,{relative:t}),u=i;return r!=="/"&&(u=i==="/"?r:z([r,i])),n.createHref({pathname:u,search:o,hash:a})}function re(){return f.useContext(Vt)!=null}function U(){return q(re(),"useLocation() may be used only in the context of a <Router> component."),f.useContext(Vt).location}var Fn="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function $n(e){f.useContext(H).static||f.useLayoutEffect(e)}function Yt(){let{isDataRoute:e}=f.useContext(F);return e?to():Hi()}function Hi(){q(re(),"useNavigate() may be used only in the context of a <Router> component.");let e=f.useContext(X),{basename:t,navigator:r}=f.useContext(H),{matches:n}=f.useContext(F),{pathname:a}=U(),i=JSON.stringify(Mn(n)),o=f.useRef(!1);return $n(()=>{o.current=!0}),f.useCallback((s,l={})=>{if(N(o.current,Fn),!o.current)return;if(typeof s=="number"){r.go(s);return}let m=An(s,JSON.parse(i),a,l.relative==="path");e==null&&t!=="/"&&(m.pathname=m.pathname==="/"?t:z([t,m.pathname])),(l.replace?r.replace:r.push)(m,l.state,l)},[t,r,i,a,e])}f.createContext(null);function Ui(){let{matches:e}=f.useContext(F),t=e[e.length-1];return t?t.params:{}}function ne(e,{relative:t}={}){let{matches:r}=f.useContext(F),{pathname:n}=U(),a=JSON.stringify(Mn(r));return f.useMemo(()=>An(e,JSON.parse(a),n,t==="path"),[e,a,n,t])}function Gi(e,t,r,n){q(re(),"useRoutes() may be used only in the context of a <Router> component.");let{navigator:a,static:i}=f.useContext(H),{matches:o}=f.useContext(F),u=o[o.length-1],s=u?u.params:{},l=u?u.pathname:"/",m=u?u.pathnameBase:"/",v=u&&u.route;{let c=v&&v.path||"";Hn(l,!v||c.endsWith("*")||c.endsWith("*?"),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${l}" (under <Route path="${c}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
11
+
12
+ Please change the parent <Route path="${c}"> to <Route path="${c==="/"?"*":`${c}/*`}">.`)}let h=U(),_;_=h;let d=_.pathname||"/",S=d;if(m!=="/"){let c=m.replace(/^\//,"").split("/");S="/"+d.replace(/^\//,"").split("/").slice(c.length).join("/")}let C=!i&&r&&r.matches&&r.matches.length>0?r.matches:Dn(e,{pathname:S});return N(v||C!=null,`No routes matched location "${_.pathname}${_.search}${_.hash}" `),N(C==null||C[C.length-1].route.element!==void 0||C[C.length-1].route.Component!==void 0||C[C.length-1].route.lazy!==void 0,`Matched leaf route at location "${_.pathname}${_.search}${_.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`),Ji(C&&C.map(c=>Object.assign({},c,{params:Object.assign({},s,c.params),pathname:z([m,a.encodeLocation?a.encodeLocation(c.pathname).pathname:c.pathname]),pathnameBase:c.pathnameBase==="/"?m:z([m,a.encodeLocation?a.encodeLocation(c.pathnameBase).pathname:c.pathnameBase])})),o,r,n)}function Bi(){let e=eo(),t=Li(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),r=e instanceof Error?e.stack:null,n="rgba(200,200,200, 0.5)",a={padding:"0.5rem",backgroundColor:n},i={padding:"2px 4px",backgroundColor:n},o=null;return console.error("Error handled by React Router default ErrorBoundary:",e),o=f.createElement(f.Fragment,null,f.createElement("p",null,"💿 Hey developer 👋"),f.createElement("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",f.createElement("code",{style:i},"ErrorBoundary")," or"," ",f.createElement("code",{style:i},"errorElement")," prop on your route.")),f.createElement(f.Fragment,null,f.createElement("h2",null,"Unexpected Application Error!"),f.createElement("h3",{style:{fontStyle:"italic"}},t),r?f.createElement("pre",{style:a},r):null,o)}var Wi=f.createElement(Bi,null),Ki=class extends f.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!=="idle"&&e.revalidation==="idle"?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error!==void 0?e.error:t.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){console.error("React Router caught the following error during render",e,t)}render(){return this.state.error!==void 0?f.createElement(F.Provider,{value:this.props.routeContext},f.createElement(Jt.Provider,{value:this.state.error,children:this.props.component})):this.props.children}};function Vi({routeContext:e,match:t,children:r}){let n=f.useContext(X);return n&&n.static&&n.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(n.staticContext._deepestRenderedBoundaryId=t.route.id),f.createElement(F.Provider,{value:e},r)}function Ji(e,t=[],r=null,n=null){if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let a=e,i=r==null?void 0:r.errors;if(i!=null){let s=a.findIndex(l=>l.route.id&&(i==null?void 0:i[l.route.id])!==void 0);q(s>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(i).join(",")}`),a=a.slice(0,Math.min(a.length,s+1))}let o=!1,u=-1;if(r)for(let s=0;s<a.length;s++){let l=a[s];if((l.route.HydrateFallback||l.route.hydrateFallbackElement)&&(u=s),l.route.id){let{loaderData:m,errors:v}=r,h=l.route.loader&&!m.hasOwnProperty(l.route.id)&&(!v||v[l.route.id]===void 0);if(l.route.lazy||h){o=!0,u>=0?a=a.slice(0,u+1):a=[a[0]];break}}}return a.reduceRight((s,l,m)=>{let v,h=!1,_=null,d=null;r&&(v=i&&l.route.id?i[l.route.id]:void 0,_=l.route.errorElement||Wi,o&&(u<0&&m===0?(Hn("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),h=!0,d=null):u===m&&(h=!0,d=l.route.hydrateFallbackElement||null)));let S=t.concat(a.slice(0,m+1)),C=()=>{let y;return v?y=_:h?y=d:l.route.Component?y=f.createElement(l.route.Component,null):l.route.element?y=l.route.element:y=s,f.createElement(Vi,{match:l,routeContext:{outlet:s,matches:S,isDataRoute:r!=null},children:y})};return r&&(l.route.ErrorBoundary||l.route.errorElement||m===0)?f.createElement(Ki,{location:r.location,revalidation:r.revalidation,component:_,error:v,children:C(),routeContext:{outlet:null,matches:S,isDataRoute:!0}}):C()},null)}function Xt(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Yi(e){let t=f.useContext(X);return q(t,Xt(e)),t}function Xi(e){let t=f.useContext(we);return q(t,Xt(e)),t}function Zi(e){let t=f.useContext(F);return q(t,Xt(e)),t}function Zt(e){let t=Zi(e),r=t.matches[t.matches.length-1];return q(r.route.id,`${e} can only be used on routes that contain a unique "id"`),r.route.id}function Qi(){return Zt("useRouteId")}function eo(){var n;let e=f.useContext(Jt),t=Xi("useRouteError"),r=Zt("useRouteError");return e!==void 0?e:(n=t.errors)==null?void 0:n[r]}function to(){let{router:e}=Yi("useNavigate"),t=Zt("useNavigate"),r=f.useRef(!1);return $n(()=>{r.current=!0}),f.useCallback(async(a,i={})=>{N(r.current,Fn),r.current&&(typeof a=="number"?e.navigate(a):await e.navigate(a,{fromRouteId:t,...i}))},[e,t])}var zn={};function Hn(e,t,r){!t&&!zn[e]&&(zn[e]=!0,N(!1,r))}f.memo(ro);function ro({routes:e,future:t,state:r}){return Gi(e,void 0,r,t)}var Ce="get",Se="application/x-www-form-urlencoded";function Re(e){return e!=null&&typeof e.tagName=="string"}function no(e){return Re(e)&&e.tagName.toLowerCase()==="button"}function ao(e){return Re(e)&&e.tagName.toLowerCase()==="form"}function io(e){return Re(e)&&e.tagName.toLowerCase()==="input"}function oo(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function uo(e,t){return e.button===0&&(!t||t==="_self")&&!oo(e)}function Qt(e=""){return new URLSearchParams(typeof e=="string"||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,r)=>{let n=e[r];return t.concat(Array.isArray(n)?n.map(a=>[r,a]):[[r,n]])},[]))}function so(e,t){let r=Qt(e);return t&&t.forEach((n,a)=>{r.has(a)||t.getAll(a).forEach(i=>{r.append(a,i)})}),r}var Ee=null;function lo(){if(Ee===null)try{new FormData(document.createElement("form"),0),Ee=!1}catch{Ee=!0}return Ee}var co=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function er(e){return e!=null&&!co.has(e)?(N(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Se}"`),null):e}function fo(e,t){let r,n,a,i,o;if(ao(e)){let u=e.getAttribute("action");n=u?G(u,t):null,r=e.getAttribute("method")||Ce,a=er(e.getAttribute("enctype"))||Se,i=new FormData(e)}else if(no(e)||io(e)&&(e.type==="submit"||e.type==="image")){let u=e.form;if(u==null)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');let s=e.getAttribute("formaction")||u.getAttribute("action");if(n=s?G(s,t):null,r=e.getAttribute("formmethod")||u.getAttribute("method")||Ce,a=er(e.getAttribute("formenctype"))||er(u.getAttribute("enctype"))||Se,i=new FormData(u,e),!lo()){let{name:l,type:m,value:v}=e;if(m==="image"){let h=l?`${l}.`:"";i.append(`${h}x`,"0"),i.append(`${h}y`,"0")}else l&&i.append(l,v)}}else{if(Re(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');r=Ce,n=null,a=Se,o=e}return i&&a==="text/plain"&&(o=i,i=void 0),{action:n,method:r.toLowerCase(),encType:a,formData:i,body:o}}function tr(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}async function ho(e,t){if(e.id in t)return t[e.id];try{let r=await import(e.module);return t[e.id]=r,r}catch(r){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(r),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function po(e){return e==null?!1:e.href==null?e.rel==="preload"&&typeof e.imageSrcSet=="string"&&typeof e.imageSizes=="string":typeof e.rel=="string"&&typeof e.href=="string"}async function mo(e,t,r){let n=await Promise.all(e.map(async a=>{let i=t.routes[a.route.id];if(i){let o=await ho(i,r);return o.links?o.links():[]}return[]}));return _o(n.flat(1).filter(po).filter(a=>a.rel==="stylesheet"||a.rel==="preload").map(a=>a.rel==="stylesheet"?{...a,rel:"prefetch",as:"style"}:{...a,rel:"prefetch"}))}function Un(e,t,r,n,a,i){let o=(s,l)=>r[l]?s.route.id!==r[l].route.id:!0,u=(s,l)=>{var m;return r[l].pathname!==s.pathname||((m=r[l].route.path)==null?void 0:m.endsWith("*"))&&r[l].params["*"]!==s.params["*"]};return i==="assets"?t.filter((s,l)=>o(s,l)||u(s,l)):i==="data"?t.filter((s,l)=>{var v;let m=n.routes[s.route.id];if(!m||!m.hasLoader)return!1;if(o(s,l)||u(s,l))return!0;if(s.route.shouldRevalidate){let h=s.route.shouldRevalidate({currentUrl:new URL(a.pathname+a.search+a.hash,window.origin),currentParams:((v=r[0])==null?void 0:v.params)||{},nextUrl:new URL(e,window.origin),nextParams:s.params,defaultShouldRevalidate:!0});if(typeof h=="boolean")return h}return!0}):[]}function yo(e,t,{includeHydrateFallback:r}={}){return vo(e.map(n=>{let a=t.routes[n.route.id];if(!a)return[];let i=[a.module];return a.clientActionModule&&(i=i.concat(a.clientActionModule)),a.clientLoaderModule&&(i=i.concat(a.clientLoaderModule)),r&&a.hydrateFallbackModule&&(i=i.concat(a.hydrateFallbackModule)),a.imports&&(i=i.concat(a.imports)),i}).flat(1))}function vo(e){return[...new Set(e)]}function go(e){let t={},r=Object.keys(e).sort();for(let n of r)t[n]=e[n];return t}function _o(e,t){let r=new Set;return new Set(t),e.reduce((n,a)=>{let i=JSON.stringify(go(a));return r.has(i)||(r.add(i),n.push({key:i,link:a})),n},[])}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");var bo=new Set([100,101,204,205]);function wo(e,t){let r=typeof e=="string"?new URL(e,typeof window>"u"?"server://singlefetch/":window.location.origin):e;return r.pathname==="/"?r.pathname="_root.data":t&&G(r.pathname,t)==="/"?r.pathname=`${t.replace(/\/$/,"")}/_root.data`:r.pathname=`${r.pathname.replace(/\/$/,"")}.data`,r}function Gn(){let e=f.useContext(X);return tr(e,"You must render this element inside a <DataRouterContext.Provider> element"),e}function Co(){let e=f.useContext(we);return tr(e,"You must render this element inside a <DataRouterStateContext.Provider> element"),e}var rr=f.createContext(void 0);rr.displayName="FrameworkContext";function Bn(){let e=f.useContext(rr);return tr(e,"You must render this element inside a <HydratedRouter> element"),e}function So(e,t){let r=f.useContext(rr),[n,a]=f.useState(!1),[i,o]=f.useState(!1),{onFocus:u,onBlur:s,onMouseEnter:l,onMouseLeave:m,onTouchStart:v}=t,h=f.useRef(null);f.useEffect(()=>{if(e==="render"&&o(!0),e==="viewport"){let S=y=>{y.forEach(c=>{o(c.isIntersecting)})},C=new IntersectionObserver(S,{threshold:.5});return h.current&&C.observe(h.current),()=>{C.disconnect()}}},[e]),f.useEffect(()=>{if(n){let S=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(S)}}},[n]);let _=()=>{a(!0)},d=()=>{a(!1),o(!1)};return r?e!=="intent"?[i,h,{}]:[i,h,{onFocus:ae(u,_),onBlur:ae(s,d),onMouseEnter:ae(l,_),onMouseLeave:ae(m,d),onTouchStart:ae(v,_)}]:[!1,h,{}]}function ae(e,t){return r=>{e&&e(r),r.defaultPrevented||t(r)}}function Ro({page:e,...t}){let{router:r}=Gn(),n=f.useMemo(()=>Dn(r.routes,e,r.basename),[r.routes,e,r.basename]);return n?f.createElement(Po,{page:e,matches:n,...t}):null}function Eo(e){let{manifest:t,routeModules:r}=Bn(),[n,a]=f.useState([]);return f.useEffect(()=>{let i=!1;return mo(e,t,r).then(o=>{i||a(o)}),()=>{i=!0}},[e,t,r]),n}function Po({page:e,matches:t,...r}){let n=U(),{manifest:a,routeModules:i}=Bn(),{basename:o}=Gn(),{loaderData:u,matches:s}=Co(),l=f.useMemo(()=>Un(e,t,s,a,n,"data"),[e,t,s,a,n]),m=f.useMemo(()=>Un(e,t,s,a,n,"assets"),[e,t,s,a,n]),v=f.useMemo(()=>{if(e===n.pathname+n.search+n.hash)return[];let d=new Set,S=!1;if(t.forEach(y=>{var p;let c=a.routes[y.route.id];!c||!c.hasLoader||(!l.some(b=>b.route.id===y.route.id)&&y.route.id in u&&((p=i[y.route.id])!=null&&p.shouldRevalidate)||c.hasClientLoader?S=!0:d.add(y.route.id))}),d.size===0)return[];let C=wo(e,o);return S&&d.size>0&&C.searchParams.set("_routes",t.filter(y=>d.has(y.route.id)).map(y=>y.route.id).join(",")),[C.pathname+C.search]},[o,u,n,a,l,t,e,i]),h=f.useMemo(()=>yo(m,a),[m,a]),_=Eo(m);return f.createElement(f.Fragment,null,v.map(d=>f.createElement("link",{key:d,rel:"prefetch",as:"fetch",href:d,...r})),h.map(d=>f.createElement("link",{key:d,rel:"modulepreload",href:d,...r})),_.map(({key:d,link:S})=>f.createElement("link",{key:d,...S})))}function xo(...e){return t=>{e.forEach(r=>{typeof r=="function"?r(t):r!=null&&(r.current=t)})}}var Wn=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";try{Wn&&(window.__reactRouterVersion="7.6.0")}catch{}var Kn=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Vn=f.forwardRef(function({onClick:t,discover:r="render",prefetch:n="none",relative:a,reloadDocument:i,replace:o,state:u,target:s,to:l,preventScrollReset:m,viewTransition:v,...h},_){let{basename:d}=f.useContext(H),S=typeof l=="string"&&Kn.test(l),C,y=!1;if(typeof l=="string"&&S&&(C=l,Wn))try{let T=new URL(window.location.href),$=l.startsWith("//")?new URL(T.protocol+l):new URL(l),k=G($.pathname,d);$.origin===T.origin&&k!=null?l=k+$.search+$.hash:y=!0}catch{N(!1,`<Link to="${l}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}let c=zi(l,{relative:a}),[p,b,g]=So(n,h),P=Do(l,{replace:o,state:u,target:s,preventScrollReset:m,relative:a,viewTransition:v});function D(T){t&&t(T),T.defaultPrevented||P(T)}let L=f.createElement("a",{...h,...g,href:C||c,onClick:y||i?t:D,ref:xo(_,b),target:s,"data-discover":!S&&r==="render"?"true":void 0});return p&&!S?f.createElement(f.Fragment,null,L,f.createElement(Ro,{page:c})):L});Vn.displayName="Link";var Oo=f.forwardRef(function({"aria-current":t="page",caseSensitive:r=!1,className:n="",end:a=!1,style:i,to:o,viewTransition:u,children:s,...l},m){let v=ne(o,{relative:l.relative}),h=U(),_=f.useContext(we),{navigator:d,basename:S}=f.useContext(H),C=_!=null&&Lo(v)&&u===!0,y=d.encodeLocation?d.encodeLocation(v).pathname:v.pathname,c=h.pathname,p=_&&_.navigation&&_.navigation.location?_.navigation.location.pathname:null;r||(c=c.toLowerCase(),p=p?p.toLowerCase():null,y=y.toLowerCase()),p&&S&&(p=G(p,S)||p);const b=y!=="/"&&y.endsWith("/")?y.length-1:y.length;let g=c===y||!a&&c.startsWith(y)&&c.charAt(b)==="/",P=p!=null&&(p===y||!a&&p.startsWith(y)&&p.charAt(y.length)==="/"),D={isActive:g,isPending:P,isTransitioning:C},L=g?t:void 0,T;typeof n=="function"?T=n(D):T=[n,g?"active":null,P?"pending":null,C?"transitioning":null].filter(Boolean).join(" ");let $=typeof i=="function"?i(D):i;return f.createElement(Vn,{...l,"aria-current":L,className:T,ref:m,style:$,to:o,viewTransition:u},typeof s=="function"?s(D):s)});Oo.displayName="NavLink";var To=f.forwardRef(({discover:e="render",fetcherKey:t,navigate:r,reloadDocument:n,replace:a,state:i,method:o=Ce,action:u,onSubmit:s,relative:l,preventScrollReset:m,viewTransition:v,...h},_)=>{let d=Mo(),S=Ao(u,{relative:l}),C=o.toLowerCase()==="get"?"get":"post",y=typeof u=="string"&&Kn.test(u),c=p=>{if(s&&s(p),p.defaultPrevented)return;p.preventDefault();let b=p.nativeEvent.submitter,g=(b==null?void 0:b.getAttribute("formmethod"))||o;d(b||p.currentTarget,{fetcherKey:t,method:g,navigate:r,replace:a,state:i,relative:l,preventScrollReset:m,viewTransition:v})};return f.createElement("form",{ref:_,method:C,action:S,onSubmit:n?s:c,...h,"data-discover":!y&&e==="render"?"true":void 0})});To.displayName="Form";function qo(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Jn(e){let t=f.useContext(X);return q(t,qo(e)),t}function Do(e,{target:t,replace:r,state:n,preventScrollReset:a,relative:i,viewTransition:o}={}){let u=Yt(),s=U(),l=ne(e,{relative:i});return f.useCallback(m=>{if(uo(m,t)){m.preventDefault();let v=r!==void 0?r:Bt(s)===Bt(l);u(e,{replace:v,state:n,preventScrollReset:a,relative:i,viewTransition:o})}},[s,u,l,r,n,t,e,a,i,o])}function ko(e){N(typeof URLSearchParams<"u","You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=f.useRef(Qt(e)),r=f.useRef(!1),n=U(),a=f.useMemo(()=>so(n.search,r.current?null:t.current),[n.search]),i=Yt(),o=f.useCallback((u,s)=>{const l=Qt(typeof u=="function"?u(a):u);r.current=!0,i("?"+l,s)},[i,a]);return[a,o]}var Io=0,jo=()=>`__${String(++Io)}__`;function Mo(){let{router:e}=Jn("useSubmit"),{basename:t}=f.useContext(H),r=Qi();return f.useCallback(async(n,a={})=>{let{action:i,method:o,encType:u,formData:s,body:l}=fo(n,t);if(a.navigate===!1){let m=a.fetcherKey||jo();await e.fetch(m,r,a.action||i,{preventScrollReset:a.preventScrollReset,formData:s,body:l,formMethod:a.method||o,formEncType:a.encType||u,flushSync:a.flushSync})}else await e.navigate(a.action||i,{preventScrollReset:a.preventScrollReset,formData:s,body:l,formMethod:a.method||o,formEncType:a.encType||u,replace:a.replace,state:a.state,fromRouteId:r,flushSync:a.flushSync,viewTransition:a.viewTransition})},[e,t,r])}function Ao(e,{relative:t}={}){let{basename:r}=f.useContext(H),n=f.useContext(F);q(n,"useFormAction must be used inside a RouteContext");let[a]=n.matches.slice(-1),i={...ne(e||".",{relative:t})},o=U();if(e==null){i.search=o.search;let u=new URLSearchParams(i.search),s=u.getAll("index");if(s.some(m=>m==="")){u.delete("index"),s.filter(v=>v).forEach(v=>u.append("index",v));let m=u.toString();i.search=m?`?${m}`:""}}return(!e||e===".")&&a.route.index&&(i.search=i.search?i.search.replace(/^\?/,"?index&"):"?index"),r!=="/"&&(i.pathname=i.pathname==="/"?r:z([r,i.pathname])),Bt(i)}function Lo(e,t={}){let r=f.useContext(Nn);q(r!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:n}=Jn("useViewTransitionState"),a=ne(e,{relative:t.relative});if(!r.isTransitioning)return!1;let i=G(r.currentLocation.pathname,n)||r.currentLocation.pathname,o=G(r.nextLocation.pathname,n)||r.nextLocation.pathname;return be(a.pathname,o)!=null||be(a.pathname,i)!=null}[...bo];function No(){return f.useRef(null)}function Fo({using:e}){return re()?E.jsx($o,{using:e}):null}function $o({using:e}){const t=Yt(),r=U(),n=Ui(),a=ko();return e.current={navigate:t,location:r,params:n,searchParams:a},null}function zo(){const[e,t]=f.useReducer(r=>r+1,0);return f.useMemo(()=>({hash:e,rerender:t}),[e])}function Ho({options:e}){const t=sr(),r=zo(),n=yi(),a=di(),i=No(),o=mi({options:e}),u=pi({options:e,elements:a}),s=fi({app:t,options:e,update:r,model:o,logger:u,queue:n}),l=si({app:t,options:e,model:o,dispatchers:s,router:i});return li({options:e,dispatchers:s,actions:l}),hi({options:e,dispatchers:s,elements:a}),f.useMemo(()=>(u.output({}),f.createElement(e.name,{ref:a.customElement,children:E.jsxs(E.Fragment,{children:[E.jsx(Fo,{using:i}),e.view(l.view)]})})),[r.hash])}function Uo(e){return t=>f.memo(r=>Ho({options:{...t,name:e.join(""),props:r}}),(r,n)=>JSON.stringify(r)===JSON.stringify(n))}function Go(e){return e}function Bo(e){return new Promise(t=>setTimeout(t,e))}function Wo(e){return e?!!(e&&typeof e!="symbol"):Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`)}function Ko(e){return e instanceof Tn}const Vo=Object.freeze(Object.defineProperty({__proto__:null,isEventError:Ko,pk:Wo,sleep:Bo},Symbol.toStringTag,{value:"Module"})),Jo={app:ta,module:Uo,model:na,view:Go,controller:ra};R.EventError=Tn,R.Lifecycle=V,R.State=cr,R.create=Jo,R.utils=Vo,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});
@@ -1,14 +1,10 @@
1
1
  import { EventError } from '../module/renderer/dispatchers/utils.ts';
2
+ import { Models } from '../module/renderer/model/utils.ts';
2
3
  import { Head } from '../module/renderer/types.ts';
3
- import { Actions, Events, Lifecycle, ModuleDefinition, Queue, State, Values } from '../types/index.ts';
4
- export type Produce<M extends ModuleDefinition> = void | ((model: M["Model"]) => M["Model"]);
5
- export type IoHelpers = {
6
- signal: AbortSignal;
7
- };
4
+ import { Actions, Draft, Events, Lifecycle, ModuleDefinition, Op, Queue, Values } from '../types/index.ts';
8
5
  export type ControllerActions<M extends ModuleDefinition> = {
9
- io<T>(ƒ: (helpers: IoHelpers) => T): T;
10
- placeholder<T>(value: T, state: State): T;
11
- produce(ƒ: (draft: M["Model"]) => void): void;
6
+ annotate<T>(value: T, operations?: (Op | Draft<T>)[]): T;
7
+ produce(ƒ: (model: M["Model"]) => void): (models: Models<M["Model"]>, process: Symbol) => Models<M["Model"]>;
12
8
  dispatch(event: M["Actions"]): Promise<void>;
13
9
  };
14
10
  export type ControllerArgs<M extends ModuleDefinition> = Readonly<{
@@ -17,17 +13,18 @@ export type ControllerArgs<M extends ModuleDefinition> = Readonly<{
17
13
  events: Readonly<Events<M["Props"]>>;
18
14
  actions: Readonly<ControllerActions<M>>;
19
15
  }>;
20
- export type ActionGenerator = Generator<void | Promise<void>, void, void>;
16
+ export type ActionEvent<M extends ModuleDefinition> = (...args: M["Actions"][number]) => ActionGenerator<M>;
17
+ export type ActionGenerator<M extends ModuleDefinition> = AsyncGenerator<(models: Models<M["Model"]>, process: Symbol) => Models<M["Model"]>, (models: Models<M["Model"]>, process: Symbol) => Models<M["Model"]>, unknown>;
21
18
  export type ControllerDefinition<M extends ModuleDefinition> = (controller: ControllerArgs<M>) => ControllerInstance<M>;
22
19
  export type ControllerInstance<M extends ModuleDefinition> = {
23
- [Lifecycle.Mount]?(): ActionGenerator;
24
- [Lifecycle.Derive]?(props: Values<M["Props"]>): ActionGenerator;
25
- [Lifecycle.Tree]?(tree: HTMLElement): ActionGenerator;
26
- [Lifecycle.Error]?(error: Error | EventError): ActionGenerator;
27
- [Lifecycle.Unmount]?(): ActionGenerator;
20
+ [Lifecycle.Mount]?(): ActionGenerator<M>;
21
+ [Lifecycle.Derive]?(props: Values<M["Props"]>): ActionGenerator<M>;
22
+ [Lifecycle.Tree]?(tree: HTMLElement): ActionGenerator<M>;
23
+ [Lifecycle.Error]?(error: Error | EventError): ActionGenerator<M>;
24
+ [Lifecycle.Unmount]?(): ActionGenerator<M>;
28
25
  } & Partial<Handlers<M>>;
29
26
  type Handlers<M extends ModuleDefinition> = {
30
- [K in Head<M["Actions"]>]: (payload: Payload<M["Actions"], K>) => ActionGenerator;
27
+ [K in Head<M["Actions"]>]: (payload: Payload<M["Actions"], K>) => ActionGenerator<M>;
31
28
  };
32
29
  type Payload<A extends Actions, K> = A extends [K, infer P] ? P : never;
33
30
  export {};
package/dist/index.d.ts CHANGED
@@ -3,8 +3,7 @@ import { default as controller } from './controller/index.ts';
3
3
  import { default as model } from './model/index.ts';
4
4
  import { default as module } from './module/index.tsx';
5
5
  import { default as view } from './view/index.ts';
6
- export { State, Lifecycle } from './types/index.ts';
7
- export { default as Maybe } from './utils/maybe/index.ts';
6
+ export { Lifecycle, State } from './types/index.ts';
8
7
  export * as utils from './utils/index.ts';
9
8
  export declare const create: {
10
9
  app: typeof app;
@@ -4,16 +4,14 @@ import { ModuleDefinition } from '../../../types/index.ts';
4
4
  import { ViewArgs } from '../../../view/types.ts';
5
5
  import { UseDispatchers } from '../dispatchers/types.ts';
6
6
  import { UseModel } from '../model/types.ts';
7
- import { UseMutations } from '../mutations/types.ts';
8
- import { UseProcess } from '../process/types.ts';
7
+ import { UseRouter } from '../router/types.ts';
9
8
  import { UseOptions } from '../types.ts';
10
9
  export type Props<M extends ModuleDefinition> = {
11
10
  app: UseApp;
12
11
  options: UseOptions<M>;
13
12
  model: UseModel;
14
13
  dispatchers: UseDispatchers;
15
- mutations: UseMutations;
16
- process: UseProcess;
14
+ router: UseRouter;
17
15
  };
18
16
  export type UseActions<M extends ModuleDefinition> = {
19
17
  controller: ControllerArgs<M>;
@@ -1,11 +1,12 @@
1
+ import { ActionEvent } from '../../../controller/types.ts';
1
2
  import { ModuleDefinition, Task } from '../../../types/index.ts';
2
3
  import { Head, Tail } from '../types.ts';
3
- import { GeneratorFn, Props } from './types.ts';
4
+ import { Props } from './types.ts';
4
5
  /**
5
6
  * @param props {Props<M>}
6
7
  * @returns { attach: (action: Head<M["Actions"]>, ƒ: F) => void; dispatch: (action: Head<M["Actions"]>, data: Tail<M["Actions"]>) => void; }
7
8
  */
8
9
  export default function useDispatchers<M extends ModuleDefinition>(props: Props<M>): {
9
- attach<F extends GeneratorFn<M>>(action: Head<M["Actions"]>, ƒ: F): void;
10
+ attach<F extends ActionEvent<M>>(action: Head<M["Actions"]>, ƒ: F): void;
10
11
  dispatch(action: Head<M["Actions"]>, data: Tail<M["Actions"]>, task?: Task): void;
11
12
  };
@@ -1,12 +1,9 @@
1
1
  import { UseApp } from '../../../app/types.ts';
2
- import { Produce } from '../../../controller/types.ts';
3
2
  import { ModuleDefinition } from '../../../types/index.ts';
4
3
  import { UseLogger } from '../logger/types.ts';
5
4
  import { UseModel } from '../model/types.ts';
6
- import { UseMutations } from '../mutations/types.ts';
7
- import { UseProcess } from '../process/types.ts';
8
5
  import { UseQueue } from '../queue/types.ts';
9
- import { Tail, UseOptions } from '../types.ts';
6
+ import { UseOptions } from '../types.ts';
10
7
  import { UseUpdate } from '../update/types.ts';
11
8
  import { default as useDispatchers } from './index.ts';
12
9
  export type Props<M extends ModuleDefinition> = {
@@ -16,19 +13,7 @@ export type Props<M extends ModuleDefinition> = {
16
13
  model: UseModel;
17
14
  logger: UseLogger;
18
15
  queue: UseQueue;
19
- mutations: UseMutations;
20
- process: UseProcess;
21
16
  };
22
17
  export type UseDispatchers = ReturnType<typeof useDispatchers>;
23
18
  export type UseDispatchHandlerProps<M extends ModuleDefinition> = Props<M>;
24
19
  export type Fn = (...args: any[]) => void;
25
- export type GeneratorFn<M extends ModuleDefinition> = (...args: any[]) => Generator<any, Produce<M>, any>;
26
- export type Context<M extends ModuleDefinition> = {
27
- app: UseApp;
28
- task: PromiseWithResolvers<void>;
29
- process: Symbol;
30
- ƒ: GeneratorFn<M>;
31
- abortController: AbortController;
32
- payload: Tail<M["Actions"]>;
33
- props: UseDispatchHandlerProps<M>;
34
- };
@@ -1,11 +1,12 @@
1
+ import { ActionEvent } from '../../../controller/types.ts';
1
2
  import { ModuleDefinition, Task } from '../../../types/index.ts';
2
3
  import { Head, Tail } from '../types.ts';
3
- import { GeneratorFn, UseDispatchHandlerProps } from './types.ts';
4
+ import { UseDispatchHandlerProps } from './types.ts';
4
5
  /**
5
6
  * @param props {UseDispatchHandlerProps<M>}
6
7
  * @returns {(name: Head<M["Actions"]>, ƒ: GeneratorFn<M>) => (payload: Tail<M["Actions"]>) => Promise<void>}
7
8
  */
8
- export declare function useDispatcher<M extends ModuleDefinition>(props: UseDispatchHandlerProps<M>): (_name: Head<M["Actions"]>, ƒ: GeneratorFn<M>) => (task: Task | undefined, payload: Tail<M["Actions"]>) => Promise<void>;
9
+ export declare function useDispatcher<M extends ModuleDefinition>(props: UseDispatchHandlerProps<M>): (_name: Head<M["Actions"]>, ƒ: ActionEvent<M>) => (task: Task | undefined, payload: Tail<M["Actions"]>) => Promise<void>;
9
10
  /**
10
11
  * Check if the name is a broadcast event.
11
12
  *
@@ -1,4 +1,5 @@
1
1
  import { ModuleDefinition } from '../../../types/index.ts';
2
2
  import { Props } from './types.ts';
3
+ import { Models } from './utils.ts';
3
4
  import * as React from "react";
4
- export default function useModel<M extends ModuleDefinition>(props: Props<M>): React.RefObject<M["Model"]>;
5
+ export default function useModel<M extends ModuleDefinition>(props: Props<M>): React.RefObject<Models<M["Model"]>>;
@@ -1,7 +1,15 @@
1
1
  import { default as useModel } from '.';
2
- import { ModuleDefinition } from '../../../types/index.ts';
2
+ import { ModuleDefinition, State } from '../../../types/index.ts';
3
3
  import { UseOptions } from '../types.ts';
4
4
  export type Props<M extends ModuleDefinition> = {
5
5
  options: UseOptions<M>;
6
6
  };
7
7
  export type UseModel = ReturnType<typeof useModel>;
8
+ export type Validate = {
9
+ pending(): boolean;
10
+ is(operation: State): boolean;
11
+ draft<T>(): T;
12
+ };
13
+ export type Validatable<M> = {
14
+ [K in keyof M]: M[K] extends object ? M[K] extends Array<infer U> ? Array<Validatable<U> & Validate> & Validate : Validatable<M[K]> & Validate : M[K] & Validate;
15
+ } & Validate;
@@ -0,0 +1,8 @@
1
+ import { ModuleDefinition } from '../../../types/index.ts';
2
+ import { Validatable } from './types.ts';
3
+ export declare class Models<M extends ModuleDefinition["Model"]> {
4
+ stateless: M;
5
+ stateful: M;
6
+ constructor(stateless: M, stateful?: M);
7
+ get validatable(): Validatable<M>;
8
+ }
@@ -0,0 +1,5 @@
1
+ import { Context, Props } from './types.ts';
2
+ import * as React from "react";
3
+ export declare function useRouter(): React.RefObject<Context | null>;
4
+ export declare function Router({ using }: Props): null | React.ReactElement;
5
+ export declare function Setup({ using }: Props): null;
@@ -0,0 +1,12 @@
1
+ import { useRouter } from './index.ts';
2
+ import * as ReactRouterDOM from "react-router-dom";
3
+ export type Props = {
4
+ using: UseRouter;
5
+ };
6
+ export type UseRouter = ReturnType<typeof useRouter>;
7
+ export type Context = {
8
+ navigate: ReactRouterDOM.NavigateFunction;
9
+ location: ReactRouterDOM.Location;
10
+ params: Readonly<ReactRouterDOM.Params<string>>;
11
+ searchParams: [URLSearchParams, ReactRouterDOM.SetURLSearchParams];
12
+ };
@@ -1,23 +1,29 @@
1
1
  import { Head } from '../module/renderer/types.ts';
2
- export declare const enum Transmit {
2
+ export declare enum Transmit {
3
3
  Unicast = "unicast",
4
4
  Multicast = "multicast",
5
5
  Broadcast = "broadcast"
6
6
  }
7
- export declare const enum State {
8
- Idle = 0,
9
- Pending = 1,
10
- Adding = 2,
11
- Removing = 4,
12
- Updating = 8,
13
- Moving = 16
7
+ export declare class Draft<T> {
8
+ value: T;
9
+ constructor(value: T);
10
+ }
11
+ export declare class State {
12
+ static Op: {
13
+ Add: number;
14
+ Remove: number;
15
+ Update: number;
16
+ Move: number;
17
+ Replace: number;
18
+ };
19
+ static Draft<T>(value: T): Draft<T>;
14
20
  }
15
21
  export type ActionName = Lifecycle | string | number;
16
22
  type ActionPayload = [any, ...any[]];
17
23
  export type Actions = [ActionName] | [ActionName, ...ActionPayload];
18
24
  export type Model = Record<string, any>;
19
25
  export type Parameters = undefined | string;
20
- export declare const enum Lifecycle {
26
+ export declare enum Lifecycle {
21
27
  Mount = "lifecycle/mount",
22
28
  Tree = "lifecycle/tree",
23
29
  Derive = "lifecycle/derive",
@@ -56,4 +62,6 @@ export type Queue<A extends ModuleDefinition["Actions"]> = {
56
62
  };
57
63
  }[];
58
64
  export type Task = PromiseWithResolvers<void>;
65
+ export type Process = Symbol;
66
+ export type Op = number;
59
67
  export {};
@@ -1,7 +1,6 @@
1
1
  import { EventError } from '../module/renderer/dispatchers/utils.ts';
2
2
  import { Pk } from '../types/index.ts';
3
3
  export { default as sleep } from './sleep/index.ts';
4
- export { default as maybe } from './maybe/index.ts';
5
4
  export declare function pk<T>(): Symbol;
6
5
  export declare function pk<T>(id: Pk<T>): boolean;
7
6
  export declare function isEventError(error: Error | EventError): error is EventError;
@@ -0,0 +1,23 @@
1
+ import { Models } from '../../module/renderer/model/utils.ts';
2
+ import { ModuleDefinition, Process } from '../../types/index.ts';
3
+ /**
4
+ * Produces a new model by applying a series of patches to the given model.
5
+ * This function uses Immer to handle immutable updates and applies additional
6
+ * processing for `State` instances within the patches.
7
+ *
8
+ * @template M - The type of the model, extending `ModuleDefinition["Model"]`.
9
+ * @param model - The initial model to be updated.
10
+ * @param process - The process associated with the `State` instances, or `null` if no process is provided.
11
+ * @param ƒ - A function that mutates the model draft to produce the desired changes.
12
+ * @returns {Models<M>} A `Models` instance containing the updated model and its draft.
13
+ */
14
+ export declare function update<M extends ModuleDefinition["Model"]>(models: Models<M>, process: Process, ƒ: (model: M) => void): Models<M>;
15
+ /**
16
+ * Cleans up the model by removing states associated with a specific process.
17
+ *
18
+ * @template M - The type of the model, extending `ModuleDefinition["Model"]`.
19
+ * @param models - The `Models` instance containing the model and its draft.
20
+ * @param process - The process whose associated states should be removed.
21
+ * @returns {Models<M>} The updated `Models` instance with the states cleaned up.
22
+ */
23
+ export declare function cleanup<M extends ModuleDefinition["Model"]>(models: Models<M>, process: Process): Models<M>;
@@ -0,0 +1,15 @@
1
+ import { Process, State } from '../../types/index.ts';
2
+ import { Immer } from 'immer';
3
+ export declare const config: {
4
+ immer: Immer;
5
+ annotations: string;
6
+ };
7
+ export declare class Annotation<M> {
8
+ value: M;
9
+ operations: State[];
10
+ field: null | number | string;
11
+ process: null | Process;
12
+ constructor(value: M, operations: State[], field?: null | number | string);
13
+ attach(process: Process): Annotation<M>;
14
+ }
15
+ export declare function annotate<M>(value: M, operations?: State[]): M;
@@ -1,17 +1,15 @@
1
- import { Events, Model, ModuleDefinition, State } from '../types/index.ts';
1
+ import { Validatable } from '../module/renderer/model/types.ts';
2
+ import { Events, ModuleDefinition } from '../types/index.ts';
3
+ import * as Router from "../module/renderer/router/types.ts";
2
4
  import * as React from "react";
3
- export type Validator<M extends Model> = {
4
- [P in keyof M]: Validator<M[P]> & {
5
- is(state: State): boolean;
6
- };
7
- };
8
5
  export type ViewActions<M extends ModuleDefinition> = {
9
6
  dispatch(event: M["Actions"]): Promise<void>;
10
7
  };
11
8
  export type ViewArgs<M extends ModuleDefinition> = Readonly<{
12
9
  model: Readonly<M["Model"]>;
10
+ router: Readonly<Router.Context>;
11
+ validate: Readonly<Validatable<M["Model"]>>;
13
12
  events: Readonly<Events<M["Props"]>>;
14
- validate: Readonly<Validator<M["Model"]>>;
15
13
  actions: Readonly<ViewActions<M>>;
16
14
  }>;
17
15
  export type ViewDefinition<M extends ModuleDefinition> = (actions: ViewArgs<M>) => React.ReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chizu",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "main": "./dist/chizu.js",
6
6
  "types": "./dist/index.d.ts",
@@ -16,8 +16,8 @@
16
16
  "immer": "^10.1.1",
17
17
  "lodash": "^4.17.21",
18
18
  "react": "^19.0.0",
19
- "traverse": "0.6.8",
20
- "react-router-dom": "^7.6.0"
19
+ "react-router-dom": "^7.6.0",
20
+ "traverse": "0.6.8"
21
21
  },
22
22
  "files": [
23
23
  "dist"
@@ -38,6 +38,7 @@
38
38
  "@types/react": "^19.0.8",
39
39
  "@types/react-dom": "^19.0.3",
40
40
  "@types/traverse": "^0.6.37",
41
+ "commit-and-tag-version": "^12.5.1",
41
42
  "dayjs": "^1.11.13",
42
43
  "dexie": "^4.0.11",
43
44
  "get-port-cli": "^3.0.0",
@@ -1,6 +0,0 @@
1
- export default class Optimistic<T> {
2
- #private;
3
- constructor(actual: () => T, optimistic: T);
4
- get optimistic(): T;
5
- get actual(): () => T;
6
- }
@@ -1,3 +0,0 @@
1
- import { Mutations } from './types';
2
- import * as React from "react";
3
- export default function useMutations(): React.RefObject<Mutations>;
@@ -1,11 +0,0 @@
1
- import { State } from '../../../types/index.ts';
2
- import { Process } from '../process/types.ts';
3
- import { default as useMutations } from './index.ts';
4
- export type UseMutations = ReturnType<typeof useMutations>;
5
- export type Mutation<T> = {
6
- key: null | symbol | string;
7
- value: T;
8
- state: State;
9
- process: Process;
10
- };
11
- export type Mutations = Set<Mutation<unknown>>;
@@ -1,2 +0,0 @@
1
- import * as React from "react";
2
- export default function useProcess(): React.RefObject<Symbol | null>;
@@ -1,3 +0,0 @@
1
- import { default as useProcess } from '.';
2
- export type Process = Symbol;
3
- export type UseProcess = ReturnType<typeof useProcess>;
@@ -1,11 +0,0 @@
1
- type Otherwise = null | undefined | Error;
2
- type Value<T> = Exclude<T, Otherwise>;
3
- export default class Maybe<T> {
4
- #private;
5
- static of<T>(value: T): Maybe<T>;
6
- constructor(value: T);
7
- map<U>(unwrap?: never, otherwise?: never): T;
8
- map<U>(unwrap?: (value: Value<T>) => U, otherwise?: never): T | U;
9
- map<U, V>(unwrap?: (value: Value<T>) => U, otherwise?: (value: Otherwise) => V): U | V;
10
- }
11
- export {};
@@ -1,30 +0,0 @@
1
- import { Mutations } from '../../module/renderer/mutations/types.ts';
2
- import { Process } from '../../module/renderer/process/types.ts';
3
- import { ModuleDefinition, State } from '../../types/index.ts';
4
- import { Validator } from '../../view/types.ts';
5
- /**
6
- * Create a placeholder for a value that is being processed.
7
- *
8
- * @param value {T}
9
- * @param state {State}
10
- * @param process {null | Process}
11
- * @returns {T}
12
- */
13
- export declare function placeholder<T>(value: T, state: State, process: null | Process): T;
14
- /**
15
- * Observe a model for changes and track mutations to determine the state of a mutation.
16
- *
17
- * @param model {M}
18
- * @param mutations {Mutations}
19
- * @returns {M}
20
- */
21
- export declare function observe<M extends ModuleDefinition["Model"]>(model: M, mutations: Mutations): M;
22
- /**
23
- * Validate a model against mutations to determine the state of a mutation and provide
24
- * immediate feedback in the form of optimistic updates.
25
- *
26
- * @param model {M}
27
- * @param mutations {Mutations}
28
- * @returns {Validator<M>}
29
- */
30
- export declare function validate<M extends ModuleDefinition["Model"]>(model: M, mutations: Mutations): Validator<M>;