@doeixd/machine 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cjs/development/core.js +4 -2
- package/dist/cjs/development/core.js.map +2 -2
- package/dist/cjs/development/index.js +17 -7
- package/dist/cjs/development/index.js.map +2 -2
- package/dist/cjs/development/minimal.js +13 -5
- package/dist/cjs/development/minimal.js.map +2 -2
- package/dist/cjs/development/react.js +4 -2
- package/dist/cjs/development/react.js.map +2 -2
- package/dist/cjs/production/core.js +1 -1
- package/dist/cjs/production/index.js +2 -2
- package/dist/cjs/production/minimal.js +1 -1
- package/dist/cjs/production/react.js +1 -1
- package/dist/esm/development/core.js +4 -2
- package/dist/esm/development/core.js.map +2 -2
- package/dist/esm/development/index.js +17 -7
- package/dist/esm/development/index.js.map +2 -2
- package/dist/esm/development/minimal.js +13 -5
- package/dist/esm/development/minimal.js.map +2 -2
- package/dist/esm/development/react.js +4 -2
- package/dist/esm/development/react.js.map +2 -2
- package/dist/esm/production/core.js +1 -1
- package/dist/esm/production/index.js +2 -2
- package/dist/esm/production/minimal.js +1 -1
- package/dist/esm/production/react.js +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/minimal.d.ts +5 -28
- package/dist/types/minimal.d.ts.map +1 -1
- package/dist/types/types.d.ts +2 -2
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -2
- package/src/minimal.ts +20 -38
- package/src/types.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
var V=Symbol.for("__machine_transitions__");function A(e,t){return Object.defineProperty(e,V,{value:t,enumerable:!1,configurable:!1}),e}function F(e){if(!(!e||typeof e!="object"))return e[V]}function S(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function U(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function ye(e){return function*(){return yield e}()}function ue(e){return e}function le(e,t){return t.reduce((n,r)=>U(r,n),e)}function Me(e){return e}function xe(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,i=0;for(n(i,o);;){let{value:a,done:s}=r.next(o);if(s)return console.log("Final:",a),a;o=a,i++,n(i,o)}}async function he(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=await n.next(r);if(i)return o;r=o}}async function*fe(e){return yield e}var pe=Symbol("MachineMeta"),q=Symbol("__machine_runtime_meta__");function b(e,t){let n=e[q]||{},r={...n,...t};t.guards&&n.guards?r.guards=[...t.guards,...n.guards]:t.guards&&(r.guards=[...t.guards]),t.actions&&n.actions?r.actions=[...t.actions,...n.actions]:t.actions&&(r.actions=[...t.actions]),Object.defineProperty(e,q,{value:r,enumerable:!1,writable:!1,configurable:!0})}function ge(e,t){return b(t,{target:e.name||e.toString()}),t}function Ce(e,t){return b(t,{description:e}),t}function me(e,t){return b(t,{guards:[e]}),t}function Te(e,t){return b(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function be(e,t){return b(t,{actions:[e]}),t}function j(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(e(d,...u)){let l=c?this:{context:this};return t.apply(l,u)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,u);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),b(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function v(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(await Promise.resolve(e(d,...u))){let l=c?this:{context:this};return t.apply(l,u)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,u);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),b(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"Runtime condition check"}]}),s}function we(e){return{do(t){let n=j(e,t);return n.else=function(r){return j(e,t,{onFail:r})},n}}}function Ee(e){return{do(t){let n=v(e,t);return n.else=function(r){return v(e,t,{onFail:r})},n}}}function Ae(e,t){return t}function Fe(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...i}=e,a=new Proxy({},{get(s,u){let c=n[u];if(typeof c=="function")return(...d)=>{let M=c.apply(n,d),l=Object.assign({context:M.context},i);return r(l),l}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function Se(e,t,n){let r=()=>{let i=e.getContext(),a=n(i),s=t[a];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(a)}".`);return s(i)},o=new Proxy({},{get(i,a){let s=r(),u=s[a];if(typeof u!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...c)=>u.apply(s,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function Qe(e,t){return function(r){return Se(e,r,t)}}function Xe(e,t){let n=Fe(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function Ze(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var Y=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function et(e,t){let n=new e(t);return new Proxy({},{get(r,o){let i=t.getContext();if(o in i)return i[o];let a=n[o];if(typeof a=="function")return(...s)=>a.apply(n,s)},set(r,o,i){let a=t.getContext();if(o in a){let s={...a,[o]:i};return t.setContext(s),!0}return!1},has(r,o){let i=t.getContext();return o in i||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),i=Object.keys(o),a=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...i,...a]))},getOwnPropertyDescriptor(r,o){let i=t.getContext();if(o in i||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function tt(e,t,n){let r=()=>{let o=n(e),i=t[o];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return i(e)};return new Proxy(e,{get(o,i,a){if(i in o)return o[i];let s=r(),u=s[i];if(typeof u=="function")return(...c)=>{let d=u.apply(s,c);if(typeof d!="object"||d===null){console.warn(`[MutableMachine] Transition "${String(i)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(M=>delete o[M]),Object.assign(o,d)}},set(o,i,a,s){return o[i]=a,!0},has(o,i){let a=r();return i in o||typeof a[i]=="function"}})}function ct(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return E(this,{...this.context,child:r})}return this}}function dt(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),E(this,{...this.context,[e]:!this.context[e]})}}var P=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}},w=class extends m{constructor(n,r,o){super({status:"loading",abortController:new AbortController,attempts:o});this.config=n;this.params=r;this.succeed=n=>{var r,o;return(o=(r=this.config).onSuccess)==null||o.call(r,n),new B(this.config,{status:"success",data:n})};this.fail=n=>{var o,i,a;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new O(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new k(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new K(this.config));this.execute()}async execute(){}},O=class extends m{constructor(n,r,o,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new w(this.config,n!=null?n:this.params,this.context.attempts+1)}},B=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}},k=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}},K=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}};function yt(e){return new P(e)}function J(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let i={};for(let a in r){let s=r[a];i[a]=(...u)=>{let c=s.apply(e,u);return J(c,t)}}for(let a in o){let s=o[a];i[a]=(...u)=>{let c=s.apply(t,u);return J(e,c)}}return{context:n,...i}}var Q=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:i}=n,a={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(a[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let u=e[s];typeof u=="function"&&s!=="context"&&(a[s]=function(...c){let d=s,M=a.context,l=()=>{let y;try{y=u.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:d,context:M,args:[...c],error:h})}catch(f){if(!r)throw f;o&&console.error(`Middleware error hook error for ${d}:`,f),i==null||i(f,"error",{transitionName:d,context:M,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in a)Object.prototype.hasOwnProperty.call(a,f)&&f!=="context"&&!(f in h)&&(h[f]=a[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&a[f]&&(h[f]=a[f])}}return h};if(y&&typeof y.then=="function")return y.then(f=>{if(x(f),t.after)try{let g=t.after({transitionName:d,prevContext:M,nextContext:f.context,args:[...c]});if(g&&typeof g.then=="function")return g.then(()=>f)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${d}:`,g),i==null||i(g,"after",{transitionName:d,prevContext:M,nextContext:f.context,args:c})}return f});if(x(y),t.after)try{let h=t.after({transitionName:d,prevContext:M,nextContext:y.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>y).catch(f=>{if(!r)throw f;return o&&console.error(`Middleware after hook error for ${d}:`,f),i==null||i(f,"after",{transitionName:d,prevContext:M,nextContext:y.context,args:c}),y})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${d}:`,h),i==null||i(h,"after",{transitionName:d,prevContext:M,nextContext:y.context,args:c})}return y};if(t.before)try{let y=t.before({transitionName:d,context:M,args:[...c]});if(y&&typeof y=="object"&&y&&"then"in y)return y.then(x=>x===Q?a:l()).catch(x=>{if(!r)throw x;return o&&console.error(`Middleware before hook error for ${d}:`,x),i==null||i(x,"before",{transitionName:d,context:M,args:c}),l()});if(y===Q)return a}catch(y){if(!r)throw y;o&&console.error(`Middleware before hook error for ${d}:`,y),i==null||i(y,"before",{transitionName:d,context:M,args:c})}return l()})}return a}function X(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:i,args:a})=>{let s=r?`→ ${i} [${a.join(", ")}]`:`→ ${i}`;n(s)},after:({transitionName:i,nextContext:a})=>{let s=o?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)},error:({transitionName:i,error:a})=>{console.error(`[Machine] ${i} failed:`,a)}})}function Z(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return C(e,{after:({transitionName:a,prevContext:s,nextContext:u,args:c})=>{let d=`${r}.${a}`,M={transition:a};o&&(M.from=s),M.to=u,i&&(M.args=c),t(d,M)}})}function ee(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function te(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function ne(e,t,n={}){let{includeArgs:r=!1}=n;return C(e,{error:o=>{let i={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,i)}})}function re(e,t){let n=new Map;return C(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let i=Date.now()-o;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};t(a)}}})}function oe(e,t={}){var u,c;let{maxAttempts:n=(u=t.maxRetries)!=null?u:3,shouldRetry:r=()=>!0,backoffMs:o=(c=t.delay)!=null?c:100,backoffMultiplier:i=2,onRetry:a}=t,s={...e};for(let d in e){if(!Object.prototype.hasOwnProperty.call(e,d))continue;let M=e[d];typeof M=="function"&&d!=="context"&&(s[d]=async function(...l){let y,x=0;for(;x<n;)try{return await M.apply(this,l)}catch(h){if(y=h,x++,x<n&&r(y,x)){a==null||a(y,x);let g=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(T=>setTimeout(T,g))}else throw y}throw y})}return s}function lt(e,t){return n=>C(n,e,t)}function N(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,i=[],a=0,s=C(e,{before:({transitionName:u,args:c})=>{let d={id:`entry-${a++}`,transitionName:u,args:[...c],timestamp:Date.now()};if(r)try{d.serializedArgs=r.serialize(c)}catch(M){console.error("Failed to serialize history args:",M)}i.push(d),n&&i.length>n&&i.shift(),o==null||o(d)}});return Object.assign(s,{history:i,clearHistory:()=>{i.length=0,a=0}})}function z(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,u=C(e,{after:({transitionName:d,prevContext:M,nextContext:l})=>{if(i&&JSON.stringify(M)===JSON.stringify(l))return;let y={id:`snapshot-${s++}`,transitionName:d,before:{...M},after:{...l},timestamp:Date.now()};if(r)try{y.serializedBefore=r.serialize(M),y.serializedAfter=r.serialize(l)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{y.diff=o(M,l)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(y),n&&a.length>n&&a.shift()}});return Object.assign(u,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:d=>{let M=Object.fromEntries(Object.entries(e).filter(([l])=>l!=="context"&&l!=="snapshots"&&l!=="clearSnapshots"&&l!=="restoreSnapshot"&&typeof e[l]=="function"));return Object.assign({context:d},M)}})}function _(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,u=0,c=C(e,{before:({transitionName:l,args:y})=>{let x={id:`entry-${s++}`,transitionName:l,args:[...y],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(y)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),n&&i.length>n&&i.shift(),o==null||o("history",x)},after:({transitionName:l,prevContext:y,nextContext:x})=>{let h={id:`snapshot-${u++}`,transitionName:l,before:{...y},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(y),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}a.push(h),n&&a.length>n&&a.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,u=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,u=0},restoreSnapshot:l=>{let y=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="history"&&x!=="snapshots"&&x!=="clearHistory"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&x!=="clearTimeTravel"&&x!=="replayFrom"&&typeof e[x]=="function"));return Object.assign({context:l},y)},replayFrom:l=>{var g;if(l<0||l>=i.length)throw new Error(`Invalid replay start index: ${l}`);let y=(g=a[l])==null?void 0:g.before;if(!y)throw new Error(`No snapshot available for index ${l}`);let x=i.slice(l),f=Object.assign({context:y},Object.fromEntries(Object.entries(e).filter(([T])=>T!=="context"&&typeof e[T]=="function")));for(let T of x){let L=f[T.transitionName];L&&(f=L.apply(f,T.args))}return f}})}function Et(e,...t){return t.reduce((n,r)=>r(n),e)}function G(e,...t){return t.reduce((n,r)=>r(n),e)}var W=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function At(e){return new W(e)}function $(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Ft(e){return $(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function St(e,t,n){return $(n,r=>r.context[e]===t)}function Rt(){let e=new Map;return{register(t,n,r,o){if(e.has(t))throw new Error(`Middleware '${t}' is already registered`);return e.set(t,{name:t,middleware:n,description:r,priority:o}),this},unregister(t){return e.delete(t)},has(t){return e.has(t)},get(t){return e.get(t)},list(){return Array.from(e.values()).sort((t,n)=>{var r,o;return((r=t.priority)!=null?r:0)-((o=n.priority)!=null?o:0)})},apply(t,n){let r=n.map(o=>{let i=e.get(o);if(!i)throw new Error(`Middleware '${o}' is not registered`);return i}).sort((o,i)=>{var a,s;return((a=o.priority)!=null?a:0)-((s=i.priority)!=null?s:0)});return G(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return G(t,...n.map(r=>r.middleware))}}}function jt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,s=[],u=!0;for(let c=0;c<i.length;c++){let d=i[c];try{if("middleware"in d&&"when"in d){if(!d.when(a))continue;a=d.middleware(a)}else a=d(a)}catch(M){if(u=!1,!t)throw M;s.push({error:M,middlewareIndex:c,middlewareName:d.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,M),r==null||r(M,c,d.name)}}return{machine:a,errors:s,success:u}}}function vt(...e){return t=>G(t,...e)}function Pt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function ie(e){return typeof e=="function"&&e.length===1}function Ot(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ie(e.middleware)&&typeof e.when=="function"}function Bt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||R(e.prevContext,t)&&R(e.nextContext,t))}function kt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||R(e.context,t))}function Kt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!t||R(e.context,t))}function Nt(e,t){if(e===null||typeof e!="object")return!1;let n=e;return!("before"in n&&n.before!==void 0&&typeof n.before!="function"||"after"in n&&n.after!==void 0&&typeof n.after!="function"||"error"in n&&n.error!==void 0&&typeof n.error!="function")}function zt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function R(e,t){return e!==null&&typeof e=="object"}function _t(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ie(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function Gt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var H=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>X(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>Z(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>ee(r,t)),this}withPermissions(t){return this.middlewares.push(n=>te(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>ne(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>re(r,t)),this}withRetry(t){return this.middlewares.push(n=>oe(n,t)),this}withHistory(t){return this.middlewares.push(n=>N(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>z(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>_(n,t)),this}withDebugging(){return this.middlewares.push(t=>je(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push($(t,n)),this}build(){let t=this.machine;for(let n of this.middlewares)t=n(t);return t}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function Re(e){return new H(e)}function Wt(e={}){return{create:t=>{let n=Re(t);return e.logging&&n.withLogging(e.logging),e.analytics&&n.withAnalytics(e.analytics.track,e.analytics.options),e.history&&n.withHistory(e.history),e.snapshot&&n.withSnapshot(e.snapshot),e.timeTravel&&n.withTimeTravel(e.timeTravel),e.retry&&n.withRetry(e.retry),n}}}function je(e){return _(z(N(e)))}function ve(e,t){return e instanceof t}function Pe(e,...t){return{type:e,args:t}}function Oe(e,t){return E(e,n=>({...n,...t}))}async function Be(e,...t){let n=e;for(let r of t)n=await r(n);return n}function ke(e,t){return t?console.log(t,e.context):console.log(e.context),e}function Ke(e,t){return function(...n){let r=t(this.context,...n);return p(r,e())}}function Ne(e,t,...n){return e.apply(t,n)}function ae(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?ae(i):i}:r}})}var D=class e{constructor(t){return this.wrappedMachine=t,new Proxy(this,{get:(n,r)=>{if(r==="wrappedMachine")return Reflect.get(n,r);if(r==="context")return this.wrappedMachine.context;let o=this.wrappedMachine[r];return typeof o=="function"?(...i)=>{let a=o.apply(this.wrappedMachine,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function ze(){return function(t){return function(...n){let r=t(this.context,...n);return p(r,this)}}}function se(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=I(e,{[t]:r});return se(o)}}}function ce(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let u=a(this.context,...s);return p(u,r)}]));return Object.assign(r,o),p(e,r)}}function _e(e,t){return t!==void 0?p(e,t):ce(e)}function p(e,t){if(typeof t=="function"){let i;return i=t(s=>p(s,i)),A(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?S(t):t,o=Object.assign({context:e},r);return A(o,r)}function de(e,t){if(typeof t=="function"){let i;return i=t(s=>de(s,i)),A(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?S(t):t,o=Object.assign({context:e},r);return A(o,r)}function Ge(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let i=r(this.context,...o);return p(i,t)}]));return n=>p(n,t)}}function E(e,t){var i;let n=e.context,r=(i=F(e))!=null?i:S(e),o=typeof t=="function"?t(n):t;return p(o,r)}function We(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function I(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function He(e,t){return(...n)=>{let r=e(...n),o=t(),i={...r.context,...o.context},{context:a,...s}=r,{context:u,...c}=o,d={...s,...c};return p(i,d)}}function $e(e){let{context:t,...n}=e;return r=>p(r,n)}function De(e,t,n){let r=e.context[t],o=n[r];if(!o)throw new Error(`No handler found for state: ${String(r)}`);return o(e.context)}function Ie(e,t,n){return e.context[t]===n}function Le(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n,[...i.args,{signal:s.signal}]);return s.signal.aborted||(n=c,t==null||t(n)),n}finally{r===s&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}function Ve(e,t){return E(e,n=>t(n))}export{D as BoundMachine,Q as CANCEL,pe as META_KEY,m as MachineBase,H as MiddlewareBuilder,Y as MultiMachineBase,be as action,ae as bindTransitions,Pt as branch,Ne as call,At as chain,vt as combine,He as combineFactories,Et as compose,G as composeTyped,de as createAsyncMachine,lt as createCustomMiddleware,Se as createEnsemble,Qe as createEnsembleFactory,Pe as createEvent,yt as createFetchMachine,Me as createFlow,ce as createFunctionalMachine,p as createMachine,$e as createMachineBuilder,Ge as createMachineFactory,C as createMiddleware,Wt as createMiddlewareFactory,Rt as createMiddlewareRegistry,et as createMultiMachine,tt as createMutableMachine,J as createParallelMachine,jt as createPipeline,Fe as createRunner,Ke as createTransition,se as createTransitionExtender,ze as createTransitionFactory,ct as delegateToChild,Ce as describe,I as extendTransitions,j as guard,v as guardAsync,me as guarded,Ie as hasState,Ft as inDevelopment,Te as invoke,Ot as isConditionalMiddleware,kt as isMiddlewareContext,Kt as isMiddlewareError,ie as isMiddlewareFn,Nt as isMiddlewareHooks,zt as isMiddlewareOptions,Bt as isMiddlewareResult,_t as isNamedMiddleware,Gt as isPipelineConfig,ve as isState,ke as logState,De as matchMachine,Oe as mergeContext,Ae as metadata,Re as middlewareBuilder,Ve as next,We as overrideTransitions,Be as pipeTransitions,U as run,he as runAsync,Le as runMachine,le as runSequence,xe as runWithDebug,Ze as runWithEnsemble,Xe as runWithRunner,E as setContext,_e as state,ye as step,fe as stepAsync,dt as toggle,ge as transitionTo,$ as when,St as whenContext,we as whenGuard,Ee as whenGuardAsync,Z as withAnalytics,je as withDebugging,ne as withErrorReporting,N as withHistory,X as withLogging,re as withPerformanceMonitoring,te as withPermissions,oe as withRetry,z as withSnapshot,_ as withTimeTravel,ee as withValidation,ue as yieldMachine};
|
|
1
|
+
var V=Symbol.for("__machine_transitions__");function A(e,t){return Object.defineProperty(e,V,{value:t,enumerable:!1,configurable:!1}),e}function F(e){if(!(!e||typeof e!="object"))return e[V]}function S(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function U(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function ye(e){return function*(){return yield e}()}function ue(e){return e}function le(e,t){return t.reduce((n,r)=>U(r,n),e)}function Me(e){return e}function xe(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,i=0;for(n(i,o);;){let{value:a,done:s}=r.next(o);if(s)return console.log("Final:",a),a;o=a,i++,n(i,o)}}async function he(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=await n.next(r);if(i)return o;r=o}}async function*fe(e){return yield e}var pe=Symbol("MachineMeta"),q=Symbol("__machine_runtime_meta__");function b(e,t){let n=e[q]||{},r={...n,...t};t.guards&&n.guards?r.guards=[...t.guards,...n.guards]:t.guards&&(r.guards=[...t.guards]),t.actions&&n.actions?r.actions=[...t.actions,...n.actions]:t.actions&&(r.actions=[...t.actions]),Object.defineProperty(e,q,{value:r,enumerable:!1,writable:!1,configurable:!0})}function ge(e,t){return b(t,{target:e.name||e.toString()}),t}function Ce(e,t){return b(t,{description:e}),t}function me(e,t){return b(t,{guards:[e]}),t}function Te(e,t){return b(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function be(e,t){return b(t,{actions:[e]}),t}function j(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...y){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(e(d,...y)){let l=c?this:{context:this};return t.apply(l,y)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,y);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),b(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function v(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...y){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(await Promise.resolve(e(d,...y))){let l=c?this:{context:this};return t.apply(l,y)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,y);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),b(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"Runtime condition check"}]}),s}function we(e){return{do(t){let n=j(e,t);return n.else=function(r){return j(e,t,{onFail:r})},n}}}function Ee(e){return{do(t){let n=v(e,t);return n.else=function(r){return v(e,t,{onFail:r})},n}}}function Ae(e,t){return t}function Fe(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...i}=e,a=new Proxy({},{get(s,y){let c=n[y];if(typeof c=="function")return(...d)=>{let M=c.apply(n,d),l=Object.assign({context:M.context},i);return r(l),l}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function Se(e,t,n){let r=()=>{let i=e.getContext(),a=n(i),s=t[a];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(a)}".`);return s(i)},o=new Proxy({},{get(i,a){let s=r(),y=s[a];if(typeof y!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...c)=>y.apply(s,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function Qe(e,t){return function(r){return Se(e,r,t)}}function Xe(e,t){let n=Fe(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function Ze(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var Y=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function et(e,t){let n=new e(t);return new Proxy({},{get(r,o){let i=t.getContext();if(o in i)return i[o];let a=n[o];if(typeof a=="function")return(...s)=>a.apply(n,s)},set(r,o,i){let a=t.getContext();if(o in a){let s={...a,[o]:i};return t.setContext(s),!0}return!1},has(r,o){let i=t.getContext();return o in i||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),i=Object.keys(o),a=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...i,...a]))},getOwnPropertyDescriptor(r,o){let i=t.getContext();if(o in i||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function tt(e,t,n){let r=()=>{let o=n(e),i=t[o];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return i(e)};return new Proxy(e,{get(o,i,a){if(i in o)return o[i];let s=r(),y=s[i];if(typeof y=="function")return(...c)=>{let d=y.apply(s,c);if(typeof d!="object"||d===null){console.warn(`[MutableMachine] Transition "${String(i)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(M=>delete o[M]),Object.assign(o,d)}},set(o,i,a,s){return o[i]=a,!0},has(o,i){let a=r();return i in o||typeof a[i]=="function"}})}function ct(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return E(this,{...this.context,child:r})}return this}}function dt(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),E(this,{...this.context,[e]:!this.context[e]})}}var P=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}},w=class extends m{constructor(n,r,o){super({status:"loading",abortController:new AbortController,attempts:o});this.config=n;this.params=r;this.succeed=n=>{var r,o;return(o=(r=this.config).onSuccess)==null||o.call(r,n),new B(this.config,{status:"success",data:n})};this.fail=n=>{var o,i,a;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new O(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new k(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new K(this.config));this.execute()}async execute(){}},O=class extends m{constructor(n,r,o,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new w(this.config,n!=null?n:this.params,this.context.attempts+1)}},B=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}},k=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}},K=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new w(this.config,n!=null?n:this.config.initialParams,1)}};function yt(e){return new P(e)}function J(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let i={};for(let a in r){let s=r[a];i[a]=(...y)=>{let c=s.apply(e,y);return J(c,t)}}for(let a in o){let s=o[a];i[a]=(...y)=>{let c=s.apply(t,y);return J(e,c)}}return{context:n,...i}}var Q=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:i}=n,a={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(a[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let y=e[s];typeof y=="function"&&s!=="context"&&(a[s]=function(...c){let d=s,M=a.context,l=()=>{let u;try{u=y.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:d,context:M,args:[...c],error:h})}catch(f){if(!r)throw f;o&&console.error(`Middleware error hook error for ${d}:`,f),i==null||i(f,"error",{transitionName:d,context:M,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in a)Object.prototype.hasOwnProperty.call(a,f)&&f!=="context"&&!(f in h)&&(h[f]=a[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&a[f]&&(h[f]=a[f])}}return h};if(u&&typeof u.then=="function")return u.then(f=>{if(x(f),t.after)try{let g=t.after({transitionName:d,prevContext:M,nextContext:f.context,args:[...c]});if(g&&typeof g.then=="function")return g.then(()=>f)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${d}:`,g),i==null||i(g,"after",{transitionName:d,prevContext:M,nextContext:f.context,args:c})}return f});if(x(u),t.after)try{let h=t.after({transitionName:d,prevContext:M,nextContext:u.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>u).catch(f=>{if(!r)throw f;return o&&console.error(`Middleware after hook error for ${d}:`,f),i==null||i(f,"after",{transitionName:d,prevContext:M,nextContext:u.context,args:c}),u})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${d}:`,h),i==null||i(h,"after",{transitionName:d,prevContext:M,nextContext:u.context,args:c})}return u};if(t.before)try{let u=t.before({transitionName:d,context:M,args:[...c]});if(u&&typeof u=="object"&&u&&"then"in u)return u.then(x=>x===Q?a:l()).catch(x=>{if(!r)throw x;return o&&console.error(`Middleware before hook error for ${d}:`,x),i==null||i(x,"before",{transitionName:d,context:M,args:c}),l()});if(u===Q)return a}catch(u){if(!r)throw u;o&&console.error(`Middleware before hook error for ${d}:`,u),i==null||i(u,"before",{transitionName:d,context:M,args:c})}return l()})}return a}function X(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:i,args:a})=>{let s=r?`→ ${i} [${a.join(", ")}]`:`→ ${i}`;n(s)},after:({transitionName:i,nextContext:a})=>{let s=o?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)},error:({transitionName:i,error:a})=>{console.error(`[Machine] ${i} failed:`,a)}})}function Z(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return C(e,{after:({transitionName:a,prevContext:s,nextContext:y,args:c})=>{let d=`${r}.${a}`,M={transition:a};o&&(M.from=s),M.to=y,i&&(M.args=c),t(d,M)}})}function ee(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function te(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function ne(e,t,n={}){let{includeArgs:r=!1}=n;return C(e,{error:o=>{let i={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,i)}})}function re(e,t){let n=new Map;return C(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let i=Date.now()-o;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};t(a)}}})}function oe(e,t={}){var y,c;let{maxAttempts:n=(y=t.maxRetries)!=null?y:3,shouldRetry:r=()=>!0,backoffMs:o=(c=t.delay)!=null?c:100,backoffMultiplier:i=2,onRetry:a}=t,s={...e};for(let d in e){if(!Object.prototype.hasOwnProperty.call(e,d))continue;let M=e[d];typeof M=="function"&&d!=="context"&&(s[d]=async function(...l){let u,x=0;for(;x<n;)try{return await M.apply(this,l)}catch(h){if(u=h,x++,x<n&&r(u,x)){a==null||a(u,x);let g=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(T=>setTimeout(T,g))}else throw u}throw u})}return s}function lt(e,t){return n=>C(n,e,t)}function N(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,i=[],a=0,s=C(e,{before:({transitionName:y,args:c})=>{let d={id:`entry-${a++}`,transitionName:y,args:[...c],timestamp:Date.now()};if(r)try{d.serializedArgs=r.serialize(c)}catch(M){console.error("Failed to serialize history args:",M)}i.push(d),n&&i.length>n&&i.shift(),o==null||o(d)}});return Object.assign(s,{history:i,clearHistory:()=>{i.length=0,a=0}})}function z(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,y=C(e,{after:({transitionName:d,prevContext:M,nextContext:l})=>{if(i&&JSON.stringify(M)===JSON.stringify(l))return;let u={id:`snapshot-${s++}`,transitionName:d,before:{...M},after:{...l},timestamp:Date.now()};if(r)try{u.serializedBefore=r.serialize(M),u.serializedAfter=r.serialize(l)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{u.diff=o(M,l)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(u),n&&a.length>n&&a.shift()}});return Object.assign(y,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:d=>{let M=Object.fromEntries(Object.entries(e).filter(([l])=>l!=="context"&&l!=="snapshots"&&l!=="clearSnapshots"&&l!=="restoreSnapshot"&&typeof e[l]=="function"));return Object.assign({context:d},M)}})}function _(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,y=0,c=C(e,{before:({transitionName:l,args:u})=>{let x={id:`entry-${s++}`,transitionName:l,args:[...u],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(u)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),n&&i.length>n&&i.shift(),o==null||o("history",x)},after:({transitionName:l,prevContext:u,nextContext:x})=>{let h={id:`snapshot-${y++}`,transitionName:l,before:{...u},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(u),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}a.push(h),n&&a.length>n&&a.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,y=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,y=0},restoreSnapshot:l=>{let u=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="history"&&x!=="snapshots"&&x!=="clearHistory"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&x!=="clearTimeTravel"&&x!=="replayFrom"&&typeof e[x]=="function"));return Object.assign({context:l},u)},replayFrom:l=>{var g;if(l<0||l>=i.length)throw new Error(`Invalid replay start index: ${l}`);let u=(g=a[l])==null?void 0:g.before;if(!u)throw new Error(`No snapshot available for index ${l}`);let x=i.slice(l),f=Object.assign({context:u},Object.fromEntries(Object.entries(e).filter(([T])=>T!=="context"&&typeof e[T]=="function")));for(let T of x){let L=f[T.transitionName];L&&(f=L.apply(f,T.args))}return f}})}function Et(e,...t){return t.reduce((n,r)=>r(n),e)}function G(e,...t){return t.reduce((n,r)=>r(n),e)}var W=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function At(e){return new W(e)}function $(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Ft(e){return $(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function St(e,t,n){return $(n,r=>r.context[e]===t)}function Rt(){let e=new Map;return{register(t,n,r,o){if(e.has(t))throw new Error(`Middleware '${t}' is already registered`);return e.set(t,{name:t,middleware:n,description:r,priority:o}),this},unregister(t){return e.delete(t)},has(t){return e.has(t)},get(t){return e.get(t)},list(){return Array.from(e.values()).sort((t,n)=>{var r,o;return((r=t.priority)!=null?r:0)-((o=n.priority)!=null?o:0)})},apply(t,n){let r=n.map(o=>{let i=e.get(o);if(!i)throw new Error(`Middleware '${o}' is not registered`);return i}).sort((o,i)=>{var a,s;return((a=o.priority)!=null?a:0)-((s=i.priority)!=null?s:0)});return G(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return G(t,...n.map(r=>r.middleware))}}}function jt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,s=[],y=!0;for(let c=0;c<i.length;c++){let d=i[c];try{if("middleware"in d&&"when"in d){if(!d.when(a))continue;a=d.middleware(a)}else a=d(a)}catch(M){if(y=!1,!t)throw M;s.push({error:M,middlewareIndex:c,middlewareName:d.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,M),r==null||r(M,c,d.name)}}return{machine:a,errors:s,success:y}}}function vt(...e){return t=>G(t,...e)}function Pt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function ie(e){return typeof e=="function"&&e.length===1}function Ot(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ie(e.middleware)&&typeof e.when=="function"}function Bt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||R(e.prevContext,t)&&R(e.nextContext,t))}function kt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||R(e.context,t))}function Kt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!t||R(e.context,t))}function Nt(e,t){if(e===null||typeof e!="object")return!1;let n=e;return!("before"in n&&n.before!==void 0&&typeof n.before!="function"||"after"in n&&n.after!==void 0&&typeof n.after!="function"||"error"in n&&n.error!==void 0&&typeof n.error!="function")}function zt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function R(e,t){return e!==null&&typeof e=="object"}function _t(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ie(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function Gt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var H=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>X(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>Z(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>ee(r,t)),this}withPermissions(t){return this.middlewares.push(n=>te(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>ne(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>re(r,t)),this}withRetry(t){return this.middlewares.push(n=>oe(n,t)),this}withHistory(t){return this.middlewares.push(n=>N(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>z(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>_(n,t)),this}withDebugging(){return this.middlewares.push(t=>je(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push($(t,n)),this}build(){let t=this.machine;for(let n of this.middlewares)t=n(t);return t}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function Re(e){return new H(e)}function Wt(e={}){return{create:t=>{let n=Re(t);return e.logging&&n.withLogging(e.logging),e.analytics&&n.withAnalytics(e.analytics.track,e.analytics.options),e.history&&n.withHistory(e.history),e.snapshot&&n.withSnapshot(e.snapshot),e.timeTravel&&n.withTimeTravel(e.timeTravel),e.retry&&n.withRetry(e.retry),n}}}function je(e){return _(z(N(e)))}function ve(e,t){return e instanceof t}function Pe(e,...t){return{type:e,args:t}}function Oe(e,t){return E(e,n=>({...n,...t}))}async function Be(e,...t){let n=e;for(let r of t)n=await r(n);return n}function ke(e,t){return t?console.log(t,e.context):console.log(e.context),e}function Ke(e,t){return function(...n){let r=t(this.context,...n);return p(r,e())}}function Ne(e,t,...n){return e.apply(t,n)}function ae(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?ae(i):i}:r}})}var D=class e{constructor(t){return this.wrappedMachine=t,new Proxy(this,{get:(n,r)=>{if(r==="wrappedMachine")return Reflect.get(n,r);if(r==="context")return this.wrappedMachine.context;let o=this.wrappedMachine[r];return typeof o=="function"?(...i)=>{let a=o.apply(this.wrappedMachine,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function ze(){return function(t){return function(...n){let r=t(this.context,...n);return p(r,this)}}}function se(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=I(e,{[t]:r});return se(o)}}}function ce(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let y=a(this.context,...s);return p(y,r)}]));return Object.assign(r,o),p(e,r)}}function _e(e,t){return t!==void 0?p(e,t):ce(e)}function p(e,t){if(typeof t=="function"){let i,a;return a=t(y=>y===e?i:p(y,a)),i=A(Object.assign({context:e},a),a),i}let n=F(t),r=n!=null?n:"context"in t?S(t):t,o=Object.assign({context:e},r);return A(o,r)}function de(e,t){if(typeof t=="function"){let i;return i=t(s=>de(s,i)),A(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?S(t):t,o=Object.assign({context:e},r);return A(o,r)}function Ge(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let i=r(this.context,...o);return p(i,t)}]));return n=>p(n,t)}}function E(e,t){var i;let n=e.context,r=(i=F(e))!=null?i:S(e),o=typeof t=="function"?t(n):t;return p(o,r)}function We(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function I(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function He(e,t){return(...n)=>{let r=e(...n),o=t(),i={...r.context,...o.context},{context:a,...s}=r,{context:y,...c}=o,d={...s,...c};return p(i,d)}}function $e(e){let{context:t,...n}=e;return r=>p(r,n)}function De(e,t,n){let r=e.context[t],o=n[r];if(!o)throw new Error(`No handler found for state: ${String(r)}`);return o(e.context)}function Ie(e,t,n){return e.context[t]===n}function Le(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n,[...i.args,{signal:s.signal}]);return s.signal.aborted||(n=c,t==null||t(n)),n}finally{r===s&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}function Ve(e,t){return E(e,n=>t(n))}export{D as BoundMachine,Q as CANCEL,pe as META_KEY,m as MachineBase,H as MiddlewareBuilder,Y as MultiMachineBase,be as action,ae as bindTransitions,Pt as branch,Ne as call,At as chain,vt as combine,He as combineFactories,Et as compose,G as composeTyped,de as createAsyncMachine,lt as createCustomMiddleware,Se as createEnsemble,Qe as createEnsembleFactory,Pe as createEvent,yt as createFetchMachine,Me as createFlow,ce as createFunctionalMachine,p as createMachine,$e as createMachineBuilder,Ge as createMachineFactory,C as createMiddleware,Wt as createMiddlewareFactory,Rt as createMiddlewareRegistry,et as createMultiMachine,tt as createMutableMachine,J as createParallelMachine,jt as createPipeline,Fe as createRunner,Ke as createTransition,se as createTransitionExtender,ze as createTransitionFactory,ct as delegateToChild,Ce as describe,I as extendTransitions,j as guard,v as guardAsync,me as guarded,Ie as hasState,Ft as inDevelopment,Te as invoke,Ot as isConditionalMiddleware,kt as isMiddlewareContext,Kt as isMiddlewareError,ie as isMiddlewareFn,Nt as isMiddlewareHooks,zt as isMiddlewareOptions,Bt as isMiddlewareResult,_t as isNamedMiddleware,Gt as isPipelineConfig,ve as isState,ke as logState,De as matchMachine,Oe as mergeContext,Ae as metadata,Re as middlewareBuilder,Ve as next,We as overrideTransitions,Be as pipeTransitions,U as run,he as runAsync,Le as runMachine,le as runSequence,xe as runWithDebug,Ze as runWithEnsemble,Xe as runWithRunner,E as setContext,_e as state,ye as step,fe as stepAsync,dt as toggle,ge as transitionTo,$ as when,St as whenContext,we as whenGuard,Ee as whenGuardAsync,Z as withAnalytics,je as withDebugging,ne as withErrorReporting,N as withHistory,X as withLogging,re as withPerformanceMonitoring,te as withPermissions,oe as withRetry,z as withSnapshot,_ as withTimeTravel,ee as withValidation,ue as yieldMachine};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Ee=Object.defineProperty;var te=(e,t)=>{for(var n in t)Ee(e,n,{get:t[n],enumerable:!0})};var ne=Symbol.for("__machine_transitions__");function b(e,t){return Object.defineProperty(e,ne,{value:t,enumerable:!1,configurable:!1}),e}function A(e){if(!(!e||typeof e!="object"))return e[ne]}function F(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function re(e,t){let n=e(t),r=t;for(;;){let{value:o,done:a}=n.next(r);if(a)return o;r=o}}function ve(e){return function*(){return yield e}()}function Re(e){return e}function je(e,t){return t.reduce((n,r)=>re(r,n),e)}function Ae(e){return e}function Fe(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,a=0;for(n(a,o);;){let{value:s,done:i}=r.next(o);if(i)return console.log("Final:",s),s;o=s,a++,n(a,o)}}async function Se(e,t){let n=e(t),r=t;for(;;){let{value:o,done:a}=await n.next(r);if(a)return o;r=o}}async function*Oe(e){return yield e}var Pe=Symbol("MachineMeta"),oe=Symbol("__machine_runtime_meta__");function w(e,t){let n=e[oe]||{},r={...n,...t};t.guards&&n.guards?r.guards=[...t.guards,...n.guards]:t.guards&&(r.guards=[...t.guards]),t.actions&&n.actions?r.actions=[...t.actions,...n.actions]:t.actions&&(r.actions=[...t.actions]),Object.defineProperty(e,oe,{value:r,enumerable:!1,writable:!1,configurable:!0})}function ke(e,t){return w(t,{target:e.name||e.toString()}),t}function Ke(e,t){return w(t,{description:e}),t}function _e(e,t){return w(t,{guards:[e]}),t}function Be(e,t){return w(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function Ne(e,t){return w(t,{actions:[e]}),t}function _(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:a}=n,s={...n,onFail:r,errorMessage:o,description:a},i=function(...c){let d=typeof this=="object"&&"context"in this,y=d?this.context:this;if(e(y,...c)){let x=d?this:{context:this};return t.apply(x,c)}else if(r==="throw"){let x=o||"Guard condition failed";throw new Error(x)}else if(r==="ignore"){if(d)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(d)return r.apply(this,c);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(i,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(i,"condition",{value:e,enumerable:!1}),Object.defineProperty(i,"transition",{value:t,enumerable:!1}),Object.defineProperty(i,"options",{value:s,enumerable:!1}),w(i,{description:a||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:a||"Synchronous condition check"}]}),i}function B(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:a}=n,s={...n,onFail:r,errorMessage:o,description:a},i=async function(...c){let d=typeof this=="object"&&"context"in this,y=d?this.context:this;if(await Promise.resolve(e(y,...c))){let x=d?this:{context:this};return t.apply(x,c)}else if(r==="throw"){let x=o||"Guard condition failed";throw new Error(x)}else if(r==="ignore"){if(d)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(d)return r.apply(this,c);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(i,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(i,"condition",{value:e,enumerable:!1}),Object.defineProperty(i,"transition",{value:t,enumerable:!1}),Object.defineProperty(i,"options",{value:s,enumerable:!1}),w(i,{description:a||"Runtime guarded transition",guards:[{name:"runtime_guard",description:a||"Runtime condition check"}]}),i}function He(e){return{do(t){let n=_(e,t);return n.else=function(r){return _(e,t,{onFail:r})},n}}}function Ie(e){return{do(t){let n=B(e,t);return n.else=function(r){return B(e,t,{onFail:r})},n}}}function ze(e,t){return t}function De(e,t){let n=e,r=i=>{n=i,t==null||t(i)},{context:o,...a}=e,s=new Proxy({},{get(i,c){let d=n[c];if(typeof d=="function")return(...y)=>{let u=d.apply(n,y),x=Object.assign({context:u.context},a);return r(x),x}}});return{get state(){return n},get context(){return n.context},actions:s,setState:r}}function $e(e,t,n){let r=()=>{let a=e.getContext(),s=n(a),i=t[s];if(!i)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(s)}".`);return i(a)},o=new Proxy({},{get(a,s){let i=r(),c=i[s];if(typeof c!="function")throw new Error(`[Ensemble] Transition "${s}" is not valid in the current state.`);return(...d)=>c.apply(i,d)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function jt(e,t){return function(r){return $e(e,r,t)}}function At(e,t){let n=De(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function Ft(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var ae=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function St(e,t){let n=new e(t);return new Proxy({},{get(r,o){let a=t.getContext();if(o in a)return a[o];let s=n[o];if(typeof s=="function")return(...i)=>s.apply(n,i)},set(r,o,a){let s=t.getContext();if(o in s){let i={...s,[o]:a};return t.setContext(i),!0}return!1},has(r,o){let a=t.getContext();return o in a||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),a=Object.keys(o),s=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(i=>i!=="constructor"&&typeof n[i]=="function");return Array.from(new Set([...a,...s]))},getOwnPropertyDescriptor(r,o){let a=t.getContext();if(o in a||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function Ot(e,t,n){let r=()=>{let o=n(e),a=t[o];if(!a)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return a(e)};return new Proxy(e,{get(o,a,s){if(a in o)return o[a];let i=r(),c=i[a];if(typeof c=="function")return(...d)=>{let y=c.apply(i,d);if(typeof y!="object"||y===null){console.warn(`[MutableMachine] Transition "${String(a)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(u=>delete o[u]),Object.assign(o,y)}},set(o,a,s,i){return o[a]=s,!0},has(o,a){let s=r();return a in o||typeof s[a]=="function"}})}function Ht(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return v(this,{...this.context,child:r})}return this}}function It(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),v(this,{...this.context,[e]:!this.context[e]})}}var N=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=class extends m{constructor(n,r,o){super({status:"loading",abortController:new AbortController,attempts:o});this.config=n;this.params=r;this.succeed=n=>{var r,o;return(o=(r=this.config).onSuccess)==null||o.call(r,n),new I(this.config,{status:"success",data:n})};this.fail=n=>{var o,a,s;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new H(this.config,this.params,n,this.context.attempts):((s=(a=this.config).onError)==null||s.call(a,n),new z(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new D(this.config));this.execute()}async execute(){}},H=class extends m{constructor(n,r,o,a){super({status:"retrying",error:o,attempts:a});this.config=n;this.params=r;this.retry=n=>new E(this.config,n!=null?n:this.params,this.context.attempts+1)}},I=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},z=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},D=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}};function zt(e){return new N(e)}function se(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let a={};for(let s in r){let i=r[s];a[s]=(...c)=>{let d=i.apply(e,c);return se(d,t)}}for(let s in o){let i=o[s];a[s]=(...c)=>{let d=i.apply(t,c);return se(e,d)}}return{context:n,...a}}var ie=Symbol("CANCEL");function g(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:a}=n,s={...e};for(let i in e)Object.prototype.hasOwnProperty.call(e,i)&&i!=="context"&&typeof e[i]!="function"&&(s[i]=e[i]);for(let i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;let c=e[i];typeof c=="function"&&i!=="context"&&(s[i]=function(...d){let y=i,u=s.context,x=()=>{let l;try{l=c.apply(this,d)}catch(f){if(t.error)try{t.error({transitionName:y,context:u,args:[...d],error:f})}catch(p){if(!r)throw p;o&&console.error(`Middleware error hook error for ${y}:`,p),a==null||a(p,"error",{transitionName:y,context:u,args:d,error:f})}throw f}let M=f=>{if(f&&typeof f=="object"&&f.context){for(let p in s)Object.prototype.hasOwnProperty.call(s,p)&&p!=="context"&&!(p in f)&&(f[p]=s[p]);for(let p in f){if(!Object.prototype.hasOwnProperty.call(f,p))continue;typeof f[p]=="function"&&p!=="context"&&s[p]&&(f[p]=s[p])}}return f};if(l&&typeof l.then=="function")return l.then(p=>{if(M(p),t.after)try{let C=t.after({transitionName:y,prevContext:u,nextContext:p.context,args:[...d]});if(C&&typeof C.then=="function")return C.then(()=>p)}catch(C){if(!r)throw C;o&&console.error(`Middleware after hook error for ${y}:`,C),a==null||a(C,"after",{transitionName:y,prevContext:u,nextContext:p.context,args:d})}return p});if(M(l),t.after)try{let f=t.after({transitionName:y,prevContext:u,nextContext:l.context,args:[...d]});if(f&&typeof f=="object"&&f&&"then"in f)return f.then(()=>l).catch(p=>{if(!r)throw p;return o&&console.error(`Middleware after hook error for ${y}:`,p),a==null||a(p,"after",{transitionName:y,prevContext:u,nextContext:l.context,args:d}),l})}catch(f){if(!r)throw f;o&&console.error(`Middleware after hook error for ${y}:`,f),a==null||a(f,"after",{transitionName:y,prevContext:u,nextContext:l.context,args:d})}return l};if(t.before)try{let l=t.before({transitionName:y,context:u,args:[...d]});if(l&&typeof l=="object"&&l&&"then"in l)return l.then(M=>M===ie?s:x()).catch(M=>{if(!r)throw M;return o&&console.error(`Middleware before hook error for ${y}:`,M),a==null||a(M,"before",{transitionName:y,context:u,args:d}),x()});if(l===ie)return s}catch(l){if(!r)throw l;o&&console.error(`Middleware before hook error for ${y}:`,l),a==null||a(l,"before",{transitionName:y,context:u,args:d})}return x()})}return s}function ce(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return g(e,{before:({transitionName:a,args:s})=>{let i=r?`→ ${a} [${s.join(", ")}]`:`→ ${a}`;n(i)},after:({transitionName:a,nextContext:s})=>{let i=o?` ${JSON.stringify(s)}`:"";n(`✓ ${a}${i}`)},error:({transitionName:a,error:s})=>{console.error(`[Machine] ${a} failed:`,s)}})}function de(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:a=!1}=n;return g(e,{after:({transitionName:s,prevContext:i,nextContext:c,args:d})=>{let y=`${r}.${s}`,u={transition:s};o&&(u.from=i),u.to=c,a&&(u.args=d),t(y,u)}})}function ye(e,t){return g(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function ue(e,t){return g(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function le(e,t,n={}){let{includeArgs:r=!1}=n;return g(e,{error:o=>{let a={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,a)}})}function xe(e,t){let n=new Map;return g(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let a=Date.now()-o;n.delete(r.transitionName);let s={transitionName:r.transitionName,duration:a,context:r.nextContext||r.prevContext};t(s)}}})}function Me(e,t={}){var c,d;let{maxAttempts:n=(c=t.maxRetries)!=null?c:3,shouldRetry:r=()=>!0,backoffMs:o=(d=t.delay)!=null?d:100,backoffMultiplier:a=2,onRetry:s}=t,i={...e};for(let y in e){if(!Object.prototype.hasOwnProperty.call(e,y))continue;let u=e[y];typeof u=="function"&&y!=="context"&&(i[y]=async function(...x){let l,M=0;for(;M<n;)try{return await u.apply(this,x)}catch(f){if(l=f,M++,M<n&&r(l,M)){s==null||s(l,M);let C=(typeof o=="function"?o(M):o)*Math.pow(a,M-1);await new Promise(T=>setTimeout(T,C))}else throw l}throw l})}return i}function $t(e,t){return n=>g(n,e,t)}function $(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,a=[],s=0,i=g(e,{before:({transitionName:c,args:d})=>{let y={id:`entry-${s++}`,transitionName:c,args:[...d],timestamp:Date.now()};if(r)try{y.serializedArgs=r.serialize(d)}catch(u){console.error("Failed to serialize history args:",u)}a.push(y),n&&a.length>n&&a.shift(),o==null||o(y)}});return Object.assign(i,{history:a,clearHistory:()=>{a.length=0,s=0}})}function W(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:a=!1}=t,s=[],i=0,c=g(e,{after:({transitionName:y,prevContext:u,nextContext:x})=>{if(a&&JSON.stringify(u)===JSON.stringify(x))return;let l={id:`snapshot-${i++}`,transitionName:y,before:{...u},after:{...x},timestamp:Date.now()};if(r)try{l.serializedBefore=r.serialize(u),l.serializedAfter=r.serialize(x)}catch(M){console.error("Failed to serialize snapshot:",M)}if(o)try{l.diff=o(u,x)}catch(M){console.error("Failed to capture snapshot:",M)}s.push(l),n&&s.length>n&&s.shift()}});return Object.assign(c,{snapshots:s,clearSnapshots:()=>{s.length=0,i=0},restoreSnapshot:y=>{let u=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="snapshots"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&typeof e[x]=="function"));return Object.assign({context:y},u)}})}function G(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,a=[],s=[],i=0,c=0,d=g(e,{before:({transitionName:x,args:l})=>{let M={id:`entry-${i++}`,transitionName:x,args:[...l],timestamp:Date.now()};if(r)try{M.serializedArgs=r.serialize(l)}catch(f){console.error("Failed to serialize history args:",f)}a.push(M),n&&a.length>n&&a.shift(),o==null||o("history",M)},after:({transitionName:x,prevContext:l,nextContext:M})=>{let f={id:`snapshot-${c++}`,transitionName:x,before:{...l},after:{...M},timestamp:Date.now()};if(r)try{f.serializedBefore=r.serialize(l),f.serializedAfter=r.serialize(M)}catch(p){console.error("Failed to serialize snapshot:",p)}s.push(f),n&&s.length>n&&s.shift(),o==null||o("snapshot",f)}});return Object.assign(d,{history:a,snapshots:s,clearHistory:()=>{a.length=0,i=0},clearSnapshots:()=>{s.length=0,c=0},clearTimeTravel:()=>{a.length=0,s.length=0,i=0,c=0},restoreSnapshot:x=>{let l=Object.fromEntries(Object.entries(e).filter(([M])=>M!=="context"&&M!=="history"&&M!=="snapshots"&&M!=="clearHistory"&&M!=="clearSnapshots"&&M!=="restoreSnapshot"&&M!=="clearTimeTravel"&&M!=="replayFrom"&&typeof e[M]=="function"));return Object.assign({context:x},l)},replayFrom:x=>{var C;if(x<0||x>=a.length)throw new Error(`Invalid replay start index: ${x}`);let l=(C=s[x])==null?void 0:C.before;if(!l)throw new Error(`No snapshot available for index ${x}`);let M=a.slice(x),p=Object.assign({context:l},Object.fromEntries(Object.entries(e).filter(([T])=>T!=="context"&&typeof e[T]=="function")));for(let T of M){let ee=p[T.transitionName];ee&&(p=ee.apply(p,T.args))}return p}})}function en(e,...t){return t.reduce((n,r)=>r(n),e)}function U(e,...t){return t.reduce((n,r)=>r(n),e)}var L=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function tn(e){return new L(e)}function q(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function nn(e){return q(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function rn(e,t,n){return q(n,r=>r.context[e]===t)}function on(){let e=new Map;return{register(t,n,r,o){if(e.has(t))throw new Error(`Middleware '${t}' is already registered`);return e.set(t,{name:t,middleware:n,description:r,priority:o}),this},unregister(t){return e.delete(t)},has(t){return e.has(t)},get(t){return e.get(t)},list(){return Array.from(e.values()).sort((t,n)=>{var r,o;return((r=t.priority)!=null?r:0)-((o=n.priority)!=null?o:0)})},apply(t,n){let r=n.map(o=>{let a=e.get(o);if(!a)throw new Error(`Middleware '${o}' is not registered`);return a}).sort((o,a)=>{var s,i;return((s=o.priority)!=null?s:0)-((i=a.priority)!=null?i:0)});return U(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return U(t,...n.map(r=>r.middleware))}}}function an(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...a)=>{let s=o,i=[],c=!0;for(let d=0;d<a.length;d++){let y=a[d];try{if("middleware"in y&&"when"in y){if(!y.when(s))continue;s=y.middleware(s)}else s=y(s)}catch(u){if(c=!1,!t)throw u;i.push({error:u,middlewareIndex:d,middlewareName:y.name}),n&&console.error(`Pipeline middleware error at index ${d}:`,u),r==null||r(u,d,y.name)}}return{machine:s,errors:i,success:c}}}function sn(...e){return t=>U(t,...e)}function cn(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function fe(e){return typeof e=="function"&&e.length===1}function dn(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&fe(e.middleware)&&typeof e.when=="function"}function yn(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||S(e.prevContext,t)&&S(e.nextContext,t))}function un(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||S(e.context,t))}function ln(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!t||S(e.context,t))}function xn(e,t){if(e===null||typeof e!="object")return!1;let n=e;return!("before"in n&&n.before!==void 0&&typeof n.before!="function"||"after"in n&&n.after!==void 0&&typeof n.after!="function"||"error"in n&&n.error!==void 0&&typeof n.error!="function")}function Mn(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function S(e,t){return e!==null&&typeof e=="object"}function fn(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&fe(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function pn(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var V=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>ce(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>de(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>ye(r,t)),this}withPermissions(t){return this.middlewares.push(n=>ue(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>le(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>xe(r,t)),this}withRetry(t){return this.middlewares.push(n=>Me(n,t)),this}withHistory(t){return this.middlewares.push(n=>$(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>W(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>G(n,t)),this}withDebugging(){return this.middlewares.push(t=>Ge(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(q(t,n)),this}build(){let t=this.machine;for(let n of this.middlewares)t=n(t);return t}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function We(e){return new V(e)}function hn(e={}){return{create:t=>{let n=We(t);return e.logging&&n.withLogging(e.logging),e.analytics&&n.withAnalytics(e.analytics.track,e.analytics.options),e.history&&n.withHistory(e.history),e.snapshot&&n.withSnapshot(e.snapshot),e.timeTravel&&n.withTimeTravel(e.timeTravel),e.retry&&n.withRetry(e.retry),n}}}function Ge(e){return G(W($(e)))}function Y(e){let t={},n=e;for(;n&&n!==Object.prototype;){let r=Object.getOwnPropertyDescriptors(n);for(let[o,a]of Object.entries(r))o!=="constructor"&&(o in t||(t[o]=a));n=Object.getPrototypeOf(n)}return t}function Ue(...e){let t=e[0];class n extends t{constructor(a){super(a)}}let r=o=>function(...a){let s=o.apply(this,a);if(s&&typeof s=="object"&&"context"in s){let i={...this.context,...s.context};return new n(i)}return s};for(let o of e){let a=Y(o.prototype);for(let[s,i]of Object.entries(a))if(s!=="constructor")if(typeof i.value=="function"){let c=i.value,d=r(c);Object.defineProperty(n.prototype,s,{...i,value:d})}else Object.defineProperty(n.prototype,s,i)}return n}function Le(e,...t){class n extends m{constructor(a){super(a)}}let r=Y(e.prototype);for(let[o,a]of Object.entries(r))if(o!=="constructor")if(typeof a.value=="function"){let s=a.value,i=function(...c){let d=s.apply(this,c);return d&&typeof d=="object"&&"context"in d?new n({...this.context,...d.context}):d};Object.defineProperty(n.prototype,o,{...a,value:i})}else Object.defineProperty(n.prototype,o,a);for(let o of t){let a=Y(o.prototype);for(let s of Object.keys(a))Object.prototype.hasOwnProperty.call(n.prototype,s)&&delete n.prototype[s]}return n}function mn(...e){let t=e.map(a=>a.constructor),n=e.map(a=>a.context),r=Object.assign({},...n),o=Ue(...t);return new o(r)}function Tn(e,...t){let n=e.constructor,r=t.map(a=>a.constructor),o=Le(n,...r);return new o(e.context)}function Ve(e,t){return e instanceof t}function qe(e,...t){return{type:e,args:t}}function Ye(e,t){return v(e,n=>({...n,...t}))}async function Je(e,...t){let n=e;for(let r of t)n=await r(n);return n}function Qe(e,t){return t?console.log(t,e.context):console.log(e.context),e}function Xe(e,t){return function(...n){let r=t(this.context,...n);return h(r,e())}}function Ze(e,t,...n){return e.apply(t,n)}function pe(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let a=r.apply(t,o);return a&&typeof a=="object"&&"context"in a?pe(a):a}:r}})}var J=class e{constructor(t){return this.wrappedMachine=t,new Proxy(this,{get:(n,r)=>{if(r==="wrappedMachine")return Reflect.get(n,r);if(r==="context")return this.wrappedMachine.context;let o=this.wrappedMachine[r];return typeof o=="function"?(...a)=>{let s=o.apply(this.wrappedMachine,a);return s&&typeof s=="object"&&"context"in s?new e(s):s}:o}})}};function et(){return function(t){return function(...n){let r=t(this.context,...n);return h(r,this)}}}function he(e){return{machine:e,addTransition:function(t,n){let r=function(...a){let s=n(this.context,...a);return h(s,this)},o=ge(e,{[t]:r});return he(o)}}}function Ce(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([a,s])=>[a,function(...i){let c=s(this.context,...i);return h(c,r)}]));return Object.assign(r,o),h(e,r)}}function tt(e,t){return t!==void 0?h(e,t):Ce(e)}function nt(...e){let t=new Map;for(let[i,c,d]of e){if(t.has(i))throw new Error(`Duplicate matcher case name: "${i}"`);t.set(i,{predicate:d})}let n=new Proxy({},{get(i,c){return function(y){let u=t.get(c);if(!u){let x=Array.from(t.keys()).join(", ");throw new Error(`Unknown matcher case: "${c}". Available cases: ${x}`)}return u.predicate(y)}}}),r=new Proxy({},{get(i,c){return function(y){if(!t.has(c)){let u=Array.from(t.keys()).join(", ");throw new Error(`Unknown matcher case: "${c}". Available cases: ${u}`)}return{__brand:"CaseHandler",__name:c,__machine:void 0,__return:void 0,handler:y}}}}),o={__exhaustive:!0};function a(i){return{is(...c){if(c.length===0)throw new Error("Pattern match requires at least one handler and exhaustiveness marker");let d=c[c.length-1];if(!d||typeof d!="object"||!("__exhaustive"in d))throw new Error("Pattern match must end with match.exhaustive for compile-time exhaustiveness checking");let y=c.slice(0,-1);for(let l of y){let M=l.__name,f=t.get(M);if(!f)throw new Error(`Internal error: Unknown matcher case in handler: ${M}`);if(f.predicate(i))return l.handler(i)}let u=y.map(l=>l.__name).join(", "),x=Array.from(t.keys()).join(", ");throw new Error(`Non-exhaustive pattern match at runtime: no handler matched the machine.
|
|
1
|
+
var Ee=Object.defineProperty;var te=(e,t)=>{for(var n in t)Ee(e,n,{get:t[n],enumerable:!0})};var ne=Symbol.for("__machine_transitions__");function b(e,t){return Object.defineProperty(e,ne,{value:t,enumerable:!1,configurable:!1}),e}function A(e){if(!(!e||typeof e!="object"))return e[ne]}function F(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function re(e,t){let n=e(t),r=t;for(;;){let{value:o,done:a}=n.next(r);if(a)return o;r=o}}function Re(e){return function*(){return yield e}()}function ve(e){return e}function je(e,t){return t.reduce((n,r)=>re(r,n),e)}function Ae(e){return e}function Fe(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,a=0;for(n(a,o);;){let{value:s,done:i}=r.next(o);if(i)return console.log("Final:",s),s;o=s,a++,n(a,o)}}async function Se(e,t){let n=e(t),r=t;for(;;){let{value:o,done:a}=await n.next(r);if(a)return o;r=o}}async function*Oe(e){return yield e}var Pe=Symbol("MachineMeta"),oe=Symbol("__machine_runtime_meta__");function w(e,t){let n=e[oe]||{},r={...n,...t};t.guards&&n.guards?r.guards=[...t.guards,...n.guards]:t.guards&&(r.guards=[...t.guards]),t.actions&&n.actions?r.actions=[...t.actions,...n.actions]:t.actions&&(r.actions=[...t.actions]),Object.defineProperty(e,oe,{value:r,enumerable:!1,writable:!1,configurable:!0})}function ke(e,t){return w(t,{target:e.name||e.toString()}),t}function Ke(e,t){return w(t,{description:e}),t}function _e(e,t){return w(t,{guards:[e]}),t}function Be(e,t){return w(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function Ne(e,t){return w(t,{actions:[e]}),t}function _(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:a}=n,s={...n,onFail:r,errorMessage:o,description:a},i=function(...c){let d=typeof this=="object"&&"context"in this,y=d?this.context:this;if(e(y,...c)){let x=d?this:{context:this};return t.apply(x,c)}else if(r==="throw"){let x=o||"Guard condition failed";throw new Error(x)}else if(r==="ignore"){if(d)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(d)return r.apply(this,c);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(i,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(i,"condition",{value:e,enumerable:!1}),Object.defineProperty(i,"transition",{value:t,enumerable:!1}),Object.defineProperty(i,"options",{value:s,enumerable:!1}),w(i,{description:a||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:a||"Synchronous condition check"}]}),i}function B(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:a}=n,s={...n,onFail:r,errorMessage:o,description:a},i=async function(...c){let d=typeof this=="object"&&"context"in this,y=d?this.context:this;if(await Promise.resolve(e(y,...c))){let x=d?this:{context:this};return t.apply(x,c)}else if(r==="throw"){let x=o||"Guard condition failed";throw new Error(x)}else if(r==="ignore"){if(d)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(d)return r.apply(this,c);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(i,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(i,"condition",{value:e,enumerable:!1}),Object.defineProperty(i,"transition",{value:t,enumerable:!1}),Object.defineProperty(i,"options",{value:s,enumerable:!1}),w(i,{description:a||"Runtime guarded transition",guards:[{name:"runtime_guard",description:a||"Runtime condition check"}]}),i}function He(e){return{do(t){let n=_(e,t);return n.else=function(r){return _(e,t,{onFail:r})},n}}}function Ie(e){return{do(t){let n=B(e,t);return n.else=function(r){return B(e,t,{onFail:r})},n}}}function ze(e,t){return t}function De(e,t){let n=e,r=i=>{n=i,t==null||t(i)},{context:o,...a}=e,s=new Proxy({},{get(i,c){let d=n[c];if(typeof d=="function")return(...y)=>{let u=d.apply(n,y),x=Object.assign({context:u.context},a);return r(x),x}}});return{get state(){return n},get context(){return n.context},actions:s,setState:r}}function $e(e,t,n){let r=()=>{let a=e.getContext(),s=n(a),i=t[s];if(!i)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(s)}".`);return i(a)},o=new Proxy({},{get(a,s){let i=r(),c=i[s];if(typeof c!="function")throw new Error(`[Ensemble] Transition "${s}" is not valid in the current state.`);return(...d)=>c.apply(i,d)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function jt(e,t){return function(r){return $e(e,r,t)}}function At(e,t){let n=De(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function Ft(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var ae=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function St(e,t){let n=new e(t);return new Proxy({},{get(r,o){let a=t.getContext();if(o in a)return a[o];let s=n[o];if(typeof s=="function")return(...i)=>s.apply(n,i)},set(r,o,a){let s=t.getContext();if(o in s){let i={...s,[o]:a};return t.setContext(i),!0}return!1},has(r,o){let a=t.getContext();return o in a||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),a=Object.keys(o),s=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(i=>i!=="constructor"&&typeof n[i]=="function");return Array.from(new Set([...a,...s]))},getOwnPropertyDescriptor(r,o){let a=t.getContext();if(o in a||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function Ot(e,t,n){let r=()=>{let o=n(e),a=t[o];if(!a)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return a(e)};return new Proxy(e,{get(o,a,s){if(a in o)return o[a];let i=r(),c=i[a];if(typeof c=="function")return(...d)=>{let y=c.apply(i,d);if(typeof y!="object"||y===null){console.warn(`[MutableMachine] Transition "${String(a)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(u=>delete o[u]),Object.assign(o,y)}},set(o,a,s,i){return o[a]=s,!0},has(o,a){let s=r();return a in o||typeof s[a]=="function"}})}function Ht(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return R(this,{...this.context,child:r})}return this}}function It(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),R(this,{...this.context,[e]:!this.context[e]})}}var N=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=class extends m{constructor(n,r,o){super({status:"loading",abortController:new AbortController,attempts:o});this.config=n;this.params=r;this.succeed=n=>{var r,o;return(o=(r=this.config).onSuccess)==null||o.call(r,n),new I(this.config,{status:"success",data:n})};this.fail=n=>{var o,a,s;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new H(this.config,this.params,n,this.context.attempts):((s=(a=this.config).onError)==null||s.call(a,n),new z(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new D(this.config));this.execute()}async execute(){}},H=class extends m{constructor(n,r,o,a){super({status:"retrying",error:o,attempts:a});this.config=n;this.params=r;this.retry=n=>new E(this.config,n!=null?n:this.params,this.context.attempts+1)}},I=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},z=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},D=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}};function zt(e){return new N(e)}function se(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let a={};for(let s in r){let i=r[s];a[s]=(...c)=>{let d=i.apply(e,c);return se(d,t)}}for(let s in o){let i=o[s];a[s]=(...c)=>{let d=i.apply(t,c);return se(e,d)}}return{context:n,...a}}var ie=Symbol("CANCEL");function g(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:a}=n,s={...e};for(let i in e)Object.prototype.hasOwnProperty.call(e,i)&&i!=="context"&&typeof e[i]!="function"&&(s[i]=e[i]);for(let i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;let c=e[i];typeof c=="function"&&i!=="context"&&(s[i]=function(...d){let y=i,u=s.context,x=()=>{let l;try{l=c.apply(this,d)}catch(f){if(t.error)try{t.error({transitionName:y,context:u,args:[...d],error:f})}catch(p){if(!r)throw p;o&&console.error(`Middleware error hook error for ${y}:`,p),a==null||a(p,"error",{transitionName:y,context:u,args:d,error:f})}throw f}let M=f=>{if(f&&typeof f=="object"&&f.context){for(let p in s)Object.prototype.hasOwnProperty.call(s,p)&&p!=="context"&&!(p in f)&&(f[p]=s[p]);for(let p in f){if(!Object.prototype.hasOwnProperty.call(f,p))continue;typeof f[p]=="function"&&p!=="context"&&s[p]&&(f[p]=s[p])}}return f};if(l&&typeof l.then=="function")return l.then(p=>{if(M(p),t.after)try{let C=t.after({transitionName:y,prevContext:u,nextContext:p.context,args:[...d]});if(C&&typeof C.then=="function")return C.then(()=>p)}catch(C){if(!r)throw C;o&&console.error(`Middleware after hook error for ${y}:`,C),a==null||a(C,"after",{transitionName:y,prevContext:u,nextContext:p.context,args:d})}return p});if(M(l),t.after)try{let f=t.after({transitionName:y,prevContext:u,nextContext:l.context,args:[...d]});if(f&&typeof f=="object"&&f&&"then"in f)return f.then(()=>l).catch(p=>{if(!r)throw p;return o&&console.error(`Middleware after hook error for ${y}:`,p),a==null||a(p,"after",{transitionName:y,prevContext:u,nextContext:l.context,args:d}),l})}catch(f){if(!r)throw f;o&&console.error(`Middleware after hook error for ${y}:`,f),a==null||a(f,"after",{transitionName:y,prevContext:u,nextContext:l.context,args:d})}return l};if(t.before)try{let l=t.before({transitionName:y,context:u,args:[...d]});if(l&&typeof l=="object"&&l&&"then"in l)return l.then(M=>M===ie?s:x()).catch(M=>{if(!r)throw M;return o&&console.error(`Middleware before hook error for ${y}:`,M),a==null||a(M,"before",{transitionName:y,context:u,args:d}),x()});if(l===ie)return s}catch(l){if(!r)throw l;o&&console.error(`Middleware before hook error for ${y}:`,l),a==null||a(l,"before",{transitionName:y,context:u,args:d})}return x()})}return s}function ce(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return g(e,{before:({transitionName:a,args:s})=>{let i=r?`→ ${a} [${s.join(", ")}]`:`→ ${a}`;n(i)},after:({transitionName:a,nextContext:s})=>{let i=o?` ${JSON.stringify(s)}`:"";n(`✓ ${a}${i}`)},error:({transitionName:a,error:s})=>{console.error(`[Machine] ${a} failed:`,s)}})}function de(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:a=!1}=n;return g(e,{after:({transitionName:s,prevContext:i,nextContext:c,args:d})=>{let y=`${r}.${s}`,u={transition:s};o&&(u.from=i),u.to=c,a&&(u.args=d),t(y,u)}})}function ye(e,t){return g(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function ue(e,t){return g(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function le(e,t,n={}){let{includeArgs:r=!1}=n;return g(e,{error:o=>{let a={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,a)}})}function xe(e,t){let n=new Map;return g(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let a=Date.now()-o;n.delete(r.transitionName);let s={transitionName:r.transitionName,duration:a,context:r.nextContext||r.prevContext};t(s)}}})}function Me(e,t={}){var c,d;let{maxAttempts:n=(c=t.maxRetries)!=null?c:3,shouldRetry:r=()=>!0,backoffMs:o=(d=t.delay)!=null?d:100,backoffMultiplier:a=2,onRetry:s}=t,i={...e};for(let y in e){if(!Object.prototype.hasOwnProperty.call(e,y))continue;let u=e[y];typeof u=="function"&&y!=="context"&&(i[y]=async function(...x){let l,M=0;for(;M<n;)try{return await u.apply(this,x)}catch(f){if(l=f,M++,M<n&&r(l,M)){s==null||s(l,M);let C=(typeof o=="function"?o(M):o)*Math.pow(a,M-1);await new Promise(T=>setTimeout(T,C))}else throw l}throw l})}return i}function $t(e,t){return n=>g(n,e,t)}function $(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,a=[],s=0,i=g(e,{before:({transitionName:c,args:d})=>{let y={id:`entry-${s++}`,transitionName:c,args:[...d],timestamp:Date.now()};if(r)try{y.serializedArgs=r.serialize(d)}catch(u){console.error("Failed to serialize history args:",u)}a.push(y),n&&a.length>n&&a.shift(),o==null||o(y)}});return Object.assign(i,{history:a,clearHistory:()=>{a.length=0,s=0}})}function W(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:a=!1}=t,s=[],i=0,c=g(e,{after:({transitionName:y,prevContext:u,nextContext:x})=>{if(a&&JSON.stringify(u)===JSON.stringify(x))return;let l={id:`snapshot-${i++}`,transitionName:y,before:{...u},after:{...x},timestamp:Date.now()};if(r)try{l.serializedBefore=r.serialize(u),l.serializedAfter=r.serialize(x)}catch(M){console.error("Failed to serialize snapshot:",M)}if(o)try{l.diff=o(u,x)}catch(M){console.error("Failed to capture snapshot:",M)}s.push(l),n&&s.length>n&&s.shift()}});return Object.assign(c,{snapshots:s,clearSnapshots:()=>{s.length=0,i=0},restoreSnapshot:y=>{let u=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="snapshots"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&typeof e[x]=="function"));return Object.assign({context:y},u)}})}function U(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,a=[],s=[],i=0,c=0,d=g(e,{before:({transitionName:x,args:l})=>{let M={id:`entry-${i++}`,transitionName:x,args:[...l],timestamp:Date.now()};if(r)try{M.serializedArgs=r.serialize(l)}catch(f){console.error("Failed to serialize history args:",f)}a.push(M),n&&a.length>n&&a.shift(),o==null||o("history",M)},after:({transitionName:x,prevContext:l,nextContext:M})=>{let f={id:`snapshot-${c++}`,transitionName:x,before:{...l},after:{...M},timestamp:Date.now()};if(r)try{f.serializedBefore=r.serialize(l),f.serializedAfter=r.serialize(M)}catch(p){console.error("Failed to serialize snapshot:",p)}s.push(f),n&&s.length>n&&s.shift(),o==null||o("snapshot",f)}});return Object.assign(d,{history:a,snapshots:s,clearHistory:()=>{a.length=0,i=0},clearSnapshots:()=>{s.length=0,c=0},clearTimeTravel:()=>{a.length=0,s.length=0,i=0,c=0},restoreSnapshot:x=>{let l=Object.fromEntries(Object.entries(e).filter(([M])=>M!=="context"&&M!=="history"&&M!=="snapshots"&&M!=="clearHistory"&&M!=="clearSnapshots"&&M!=="restoreSnapshot"&&M!=="clearTimeTravel"&&M!=="replayFrom"&&typeof e[M]=="function"));return Object.assign({context:x},l)},replayFrom:x=>{var C;if(x<0||x>=a.length)throw new Error(`Invalid replay start index: ${x}`);let l=(C=s[x])==null?void 0:C.before;if(!l)throw new Error(`No snapshot available for index ${x}`);let M=a.slice(x),p=Object.assign({context:l},Object.fromEntries(Object.entries(e).filter(([T])=>T!=="context"&&typeof e[T]=="function")));for(let T of M){let ee=p[T.transitionName];ee&&(p=ee.apply(p,T.args))}return p}})}function en(e,...t){return t.reduce((n,r)=>r(n),e)}function G(e,...t){return t.reduce((n,r)=>r(n),e)}var L=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function tn(e){return new L(e)}function q(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function nn(e){return q(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function rn(e,t,n){return q(n,r=>r.context[e]===t)}function on(){let e=new Map;return{register(t,n,r,o){if(e.has(t))throw new Error(`Middleware '${t}' is already registered`);return e.set(t,{name:t,middleware:n,description:r,priority:o}),this},unregister(t){return e.delete(t)},has(t){return e.has(t)},get(t){return e.get(t)},list(){return Array.from(e.values()).sort((t,n)=>{var r,o;return((r=t.priority)!=null?r:0)-((o=n.priority)!=null?o:0)})},apply(t,n){let r=n.map(o=>{let a=e.get(o);if(!a)throw new Error(`Middleware '${o}' is not registered`);return a}).sort((o,a)=>{var s,i;return((s=o.priority)!=null?s:0)-((i=a.priority)!=null?i:0)});return G(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return G(t,...n.map(r=>r.middleware))}}}function an(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...a)=>{let s=o,i=[],c=!0;for(let d=0;d<a.length;d++){let y=a[d];try{if("middleware"in y&&"when"in y){if(!y.when(s))continue;s=y.middleware(s)}else s=y(s)}catch(u){if(c=!1,!t)throw u;i.push({error:u,middlewareIndex:d,middlewareName:y.name}),n&&console.error(`Pipeline middleware error at index ${d}:`,u),r==null||r(u,d,y.name)}}return{machine:s,errors:i,success:c}}}function sn(...e){return t=>G(t,...e)}function cn(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function fe(e){return typeof e=="function"&&e.length===1}function dn(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&fe(e.middleware)&&typeof e.when=="function"}function yn(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||S(e.prevContext,t)&&S(e.nextContext,t))}function un(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||S(e.context,t))}function ln(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!t||S(e.context,t))}function xn(e,t){if(e===null||typeof e!="object")return!1;let n=e;return!("before"in n&&n.before!==void 0&&typeof n.before!="function"||"after"in n&&n.after!==void 0&&typeof n.after!="function"||"error"in n&&n.error!==void 0&&typeof n.error!="function")}function Mn(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function S(e,t){return e!==null&&typeof e=="object"}function fn(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&fe(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function pn(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var V=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>ce(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>de(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>ye(r,t)),this}withPermissions(t){return this.middlewares.push(n=>ue(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>le(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>xe(r,t)),this}withRetry(t){return this.middlewares.push(n=>Me(n,t)),this}withHistory(t){return this.middlewares.push(n=>$(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>W(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>U(n,t)),this}withDebugging(){return this.middlewares.push(t=>Ue(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(q(t,n)),this}build(){let t=this.machine;for(let n of this.middlewares)t=n(t);return t}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function We(e){return new V(e)}function hn(e={}){return{create:t=>{let n=We(t);return e.logging&&n.withLogging(e.logging),e.analytics&&n.withAnalytics(e.analytics.track,e.analytics.options),e.history&&n.withHistory(e.history),e.snapshot&&n.withSnapshot(e.snapshot),e.timeTravel&&n.withTimeTravel(e.timeTravel),e.retry&&n.withRetry(e.retry),n}}}function Ue(e){return U(W($(e)))}function Y(e){let t={},n=e;for(;n&&n!==Object.prototype;){let r=Object.getOwnPropertyDescriptors(n);for(let[o,a]of Object.entries(r))o!=="constructor"&&(o in t||(t[o]=a));n=Object.getPrototypeOf(n)}return t}function Ge(...e){let t=e[0];class n extends t{constructor(a){super(a)}}let r=o=>function(...a){let s=o.apply(this,a);if(s&&typeof s=="object"&&"context"in s){let i={...this.context,...s.context};return new n(i)}return s};for(let o of e){let a=Y(o.prototype);for(let[s,i]of Object.entries(a))if(s!=="constructor")if(typeof i.value=="function"){let c=i.value,d=r(c);Object.defineProperty(n.prototype,s,{...i,value:d})}else Object.defineProperty(n.prototype,s,i)}return n}function Le(e,...t){class n extends m{constructor(a){super(a)}}let r=Y(e.prototype);for(let[o,a]of Object.entries(r))if(o!=="constructor")if(typeof a.value=="function"){let s=a.value,i=function(...c){let d=s.apply(this,c);return d&&typeof d=="object"&&"context"in d?new n({...this.context,...d.context}):d};Object.defineProperty(n.prototype,o,{...a,value:i})}else Object.defineProperty(n.prototype,o,a);for(let o of t){let a=Y(o.prototype);for(let s of Object.keys(a))Object.prototype.hasOwnProperty.call(n.prototype,s)&&delete n.prototype[s]}return n}function mn(...e){let t=e.map(a=>a.constructor),n=e.map(a=>a.context),r=Object.assign({},...n),o=Ge(...t);return new o(r)}function Tn(e,...t){let n=e.constructor,r=t.map(a=>a.constructor),o=Le(n,...r);return new o(e.context)}function Ve(e,t){return e instanceof t}function qe(e,...t){return{type:e,args:t}}function Ye(e,t){return R(e,n=>({...n,...t}))}async function Je(e,...t){let n=e;for(let r of t)n=await r(n);return n}function Qe(e,t){return t?console.log(t,e.context):console.log(e.context),e}function Xe(e,t){return function(...n){let r=t(this.context,...n);return h(r,e())}}function Ze(e,t,...n){return e.apply(t,n)}function pe(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let a=r.apply(t,o);return a&&typeof a=="object"&&"context"in a?pe(a):a}:r}})}var J=class e{constructor(t){return this.wrappedMachine=t,new Proxy(this,{get:(n,r)=>{if(r==="wrappedMachine")return Reflect.get(n,r);if(r==="context")return this.wrappedMachine.context;let o=this.wrappedMachine[r];return typeof o=="function"?(...a)=>{let s=o.apply(this.wrappedMachine,a);return s&&typeof s=="object"&&"context"in s?new e(s):s}:o}})}};function et(){return function(t){return function(...n){let r=t(this.context,...n);return h(r,this)}}}function he(e){return{machine:e,addTransition:function(t,n){let r=function(...a){let s=n(this.context,...a);return h(s,this)},o=ge(e,{[t]:r});return he(o)}}}function Ce(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([a,s])=>[a,function(...i){let c=s(this.context,...i);return h(c,r)}]));return Object.assign(r,o),h(e,r)}}function tt(e,t){return t!==void 0?h(e,t):Ce(e)}function nt(...e){let t=new Map;for(let[i,c,d]of e){if(t.has(i))throw new Error(`Duplicate matcher case name: "${i}"`);t.set(i,{predicate:d})}let n=new Proxy({},{get(i,c){return function(y){let u=t.get(c);if(!u){let x=Array.from(t.keys()).join(", ");throw new Error(`Unknown matcher case: "${c}". Available cases: ${x}`)}return u.predicate(y)}}}),r=new Proxy({},{get(i,c){return function(y){if(!t.has(c)){let u=Array.from(t.keys()).join(", ");throw new Error(`Unknown matcher case: "${c}". Available cases: ${u}`)}return{__brand:"CaseHandler",__name:c,__machine:void 0,__return:void 0,handler:y}}}}),o={__exhaustive:!0};function a(i){return{is(...c){if(c.length===0)throw new Error("Pattern match requires at least one handler and exhaustiveness marker");let d=c[c.length-1];if(!d||typeof d!="object"||!("__exhaustive"in d))throw new Error("Pattern match must end with match.exhaustive for compile-time exhaustiveness checking");let y=c.slice(0,-1);for(let l of y){let M=l.__name,f=t.get(M);if(!f)throw new Error(`Internal error: Unknown matcher case in handler: ${M}`);if(f.predicate(i))return l.handler(i)}let u=y.map(l=>l.__name).join(", "),x=Array.from(t.keys()).join(", ");throw new Error(`Non-exhaustive pattern match at runtime: no handler matched the machine.
|
|
2
2
|
Handled cases: [${u}]
|
|
3
3
|
All cases: [${x}]
|
|
4
|
-
This may occur if predicates don't cover all runtime possibilities.`)}}}function s(i){for(let[c,d,y]of e)if(y(i))return c;return null}return Object.assign(s,{is:n,when:a,case:r,exhaustive:o})}function rt(e,t){return[e,void 0,n=>n instanceof t]}function ot(e,t,n){return[e,void 0,r=>Q(r,t,n)]}function at(e,t){return[e,void 0,t]}function st(){return{case(e,t,n){return[e,void 0,r=>Q(r,t,n)]}}}var
|
|
4
|
+
This may occur if predicates don't cover all runtime possibilities.`)}}}function s(i){for(let[c,d,y]of e)if(y(i))return c;return null}return Object.assign(s,{is:n,when:a,case:r,exhaustive:o})}function rt(e,t){return[e,void 0,n=>n instanceof t]}function ot(e,t,n){return[e,void 0,r=>Q(r,t,n)]}function at(e,t){return[e,void 0,t]}function st(){return{case(e,t,n){return[e,void 0,r=>Q(r,t,n)]}}}var v=class v{constructor(t){this._observers=new Set;this._queue=[];this._processing=!1;this._state=t,this.ref={send:n=>this.dispatch(n)},this.send=new Proxy({},{get:(n,r)=>(...o)=>{this.dispatch({type:r,args:o})}})}static inspect(t){v._inspector=t}getSnapshot(){return this._state}subscribe(t){return this._observers.add(t),()=>{this._observers.delete(t)}}select(t){return t(this._state)}start(){return this}stop(){this._observers.clear()}dispatch(t){if(v._inspector&&v._inspector({type:"@actor/send",actor:this,event:t,snapshot:this._state}),this._processing){this._queue.push(t);return}this._processing=!0,this._queue.push(t),this._flush()}_flush(){for(;this._queue.length>0;){let t=this._queue[0];this._queue.shift();let r=this._state[t.type];if(typeof r!="function"){console.warn(`[Actor] Transition '${String(t.type)}' not found.`);continue}let o;try{o=r.apply(this._state,t.args)}catch(a){console.error(`[Actor] Error in transition '${String(t.type)}':`,a);continue}if(o instanceof Promise){o.then(a=>{this._state=a,this._notify(),this._flush()}).catch(a=>{console.error(`[Actor] Async error in transition '${String(t.type)}':`,a),this._flush()});return}else this._state=o,this._notify()}this._processing=!1}_notify(){let t=this.getSnapshot();this._observers.forEach(n=>n(t))}};v._inspector=null;var O=v;function P(e){return new O(e)}function it(e){return P(e)}function ct(e){let n=h({status:"pending",data:void 0,error:void 0},o=>({resolve(a){return o({status:"resolved",data:a,error:void 0})},reject(a){return o({status:"rejected",error:a,data:void 0})}})),r=P(n);return e().then(o=>r.send.resolve(o)).catch(o=>r.send.reject(o)),r}function dt(e){let n=h({status:"active",value:void 0,error:void 0},o=>({next(a){return o({status:"active",value:a,error:void 0})},error(a){return o({status:"error",error:a,value:void 0})},complete(){return o({status:"done",value:void 0,error:void 0})}})),r=P(n);return e.subscribe(o=>r.send.next(o),o=>r.send.error(o),()=>r.send.complete()),r}function me(e,t){let n=t,r=Object.fromEntries(Object.entries(t).map(([o,a])=>[o,function(...s){let i={context:this.context},c=a.apply(i,s);return me(c,n)}]));return Object.values(r).forEach(o=>{typeof o=="function"&&Object.defineProperty(o,"__contextBound",{value:!0,enumerable:!1})}),b(Object.assign({context:e},r),r)}function yt(e,t,...n){let r=e[t],o={context:e.context};return r.apply(o,n)}function ut(e){let t=Object.values(e).find(n=>typeof n=="function");return t?t.__contextBound===!0:!1}var X={};te(X,{factory:()=>pt,freeze:()=>Te,isState:()=>lt,machine:()=>K,match:()=>xt,run:()=>ft,runnable:()=>Mt,tag:()=>k,union:()=>ht,withChildren:()=>be});function k(e,t){return typeof e=="object"?e:t?{...t,tag:e}:{tag:e}}(t=>{function e(n){return n?r=>t(n,r):r=>o=>t(r,o)}t.factory=e})(k||(k={}));function lt(e,t){return e.tag===t}function Te(e){if(Object.freeze(e),typeof Object.values=="function")for(let t of Object.values(e))t&&typeof t=="object"&&Te(t);return e}function K(e,t){let n;return n=Object.assign({},e,t(e,o=>o===e?n:K(o,t))),n}function xt(e,t){let n=t[e.tag];return n(e)}var j=Symbol("lifecycle");function Mt(e,t){let n={...e};return n[j]=t,n}function ft(e){let t=e,n=null,r=new Set,o=()=>{r.forEach(i=>i(t))},a=()=>{n&&(n(),n=null);let i=t[j],c=t.tag,d=i==null?void 0:i[c];d!=null&&d.onEnter&&(n=d.onEnter(s))},s=(i,...c)=>{let d=t[i];if(typeof d=="function"){let y=d(...c);if(y&&typeof y=="object"&&"tag"in y){let u=y;!u[j]&&t[j]&&(u[j]=t[j]),t=u,a(),o()}}};return a(),{get:()=>t,send:s,stop:()=>{n&&(n(),n=null),r.clear()},subscribe:i=>(r.add(i),()=>r.delete(i))}}function be(e,t){let n={...e};for(let r of Object.keys(t)){let o=t[r],a=new Proxy(o,{get(s,i){let c=s[i];return typeof c=="function"?(...d)=>{let y=c(...d);return be({...e},{...t,[r]:y})}:c}});n[r]=a}return n}function pt(){return e=>{let t=n=>{let r=o=>t(o);return K(n,o=>e(o,r))};return t}}function ht(){return e=>{let t=n=>{let r=e[n.tag],o=a=>t(a);return K(n,a=>r(a,o))};return t}}var Z={};te(Z,{createDelegate:()=>Ct,delegate:()=>we,delegateAll:()=>gt,renameMap:()=>mt});function we(e,t,n,r){let o=e[t],a={},s=Object.keys(o).filter(c=>typeof o[c]=="function"),i;if(!r)i=Object.fromEntries(s.map(c=>[c,c]));else if("pick"in r)i=Object.fromEntries(r.pick.filter(c=>s.includes(c)).map(c=>[c,c]));else if("omit"in r){let c=new Set(r.omit);i=Object.fromEntries(s.filter(d=>!c.has(d)).map(d=>[d,d]))}else"rename"in r?i=Object.fromEntries(Object.entries(r.rename).filter(([c])=>s.includes(c))):i={};for(let[c,d]of Object.entries(i)){let y=o[c];a[d]=(...u)=>{let x=y.apply(o,u);return n({...e,[t]:x})}}return a}function Ct(e,t){return(n,r)=>we(e,n,t,r)}function gt(e,t,n,r=!1){let o={};for(let a of t){let s=e[a],i=Object.keys(s).filter(c=>typeof s[c]=="function");for(let c of i){let d=r?`${String(a)}_${c}`:c,y=s[c];o[d]=(...u)=>{let x=y.apply(s,u);return n({...e,[a]:x})}}}return o}function mt(){return e=>e}function h(e,t){if(typeof t=="function"){let a,s;return s=t(c=>c===e?a:h(c,s)),a=b(Object.assign({context:e},s),s),a}let n=A(t),r=n!=null?n:"context"in t?F(t):t,o=Object.assign({context:e},r);return b(o,r)}function Tt(e,t){if(typeof t=="function"){let a;return a=t(i=>Tt(i,a)),b(Object.assign({context:e},a),a)}let n=A(t),r=n!=null?n:"context"in t?F(t):t,o=Object.assign({context:e},r);return b(o,r)}function Jn(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let a=r(this.context,...o);return h(a,t)}]));return n=>h(n,t)}}function R(e,t){var a;let n=e.context,r=(a=A(e))!=null?a:F(e),o=typeof t=="function"?t(n):t;return h(o,r)}function Qn(e){return{context:e}}function Xn(e,t){let{context:n,...r}=e,o={...r,...t};return h(n,o)}function ge(e,t){let{context:n,...r}=e,o={...r,...t};return h(n,o)}function Zn(e,t){return(...n)=>{let r=e(...n),o=t(),a={...r.context,...o.context},{context:s,...i}=r,{context:c,...d}=o,y={...i,...d};return h(a,y)}}function er(e){let{context:t,...n}=e;return r=>h(r,n)}function tr(e,t,n){let r=e.context[t],o=n[r];if(!o)throw new Error(`No handler found for state: ${String(r)}`);return o(e.context)}function Q(e,t,n){return e.context[t]===n}function nr(e,t){let n=e,r=null;async function o(a){r&&(r.abort(),r=null);let s=n[a.type];if(typeof s!="function")throw new Error(`[Machine] Unknown event type '${String(a.type)}' on current state.`);let i=new AbortController;r=i;try{let d=await s.apply(n,[...a.args,{signal:i.signal}]);return i.signal.aborted||(n=d,t==null||t(n)),n}finally{r===i&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}function rr(e,t){return R(e,n=>t(n))}export{O as Actor,J as BoundMachine,ie as CANCEL,Pe as META_KEY,m as MachineBase,Le as MachineExclude,Ge as MachineUnion,V as MiddlewareBuilder,ae as MultiMachineBase,Ne as action,pe as bindTransitions,cn as branch,Ze as call,yt as callWithContext,tn as chain,rt as classCase,sn as combine,Zn as combineFactories,en as compose,G as composeTyped,P as createActor,Tt as createAsyncMachine,Qn as createContext,me as createContextBoundMachine,$t as createCustomMiddleware,$e as createEnsemble,jt as createEnsembleFactory,qe as createEvent,zt as createFetchMachine,Ae as createFlow,Ce as createFunctionalMachine,h as createMachine,er as createMachineBuilder,Jn as createMachineFactory,nt as createMatcher,g as createMiddleware,hn as createMiddlewareFactory,on as createMiddlewareRegistry,St as createMultiMachine,Ot as createMutableMachine,se as createParallelMachine,an as createPipeline,De as createRunner,Xe as createTransition,he as createTransitionExtender,et as createTransitionFactory,at as customCase,Z as delegate,Ht as delegateToChild,Ke as describe,ot as discriminantCase,ge as extendTransitions,st as forContext,Te as freeze,dt as fromObservable,ct as fromPromise,_ as guard,B as guardAsync,_e as guarded,Q as hasState,nn as inDevelopment,Be as invoke,dn as isConditionalMiddleware,ut as isContextBound,un as isMiddlewareContext,ln as isMiddlewareError,fe as isMiddlewareFn,xn as isMiddlewareHooks,Mn as isMiddlewareOptions,yn as isMiddlewareResult,fn as isNamedMiddleware,pn as isPipelineConfig,Ve as isState,Qe as logState,Tn as machineExclude,mn as machineUnion,tr as matchMachine,Ye as mergeContext,ze as metadata,We as middlewareBuilder,X as minimal,rr as next,Xn as overrideTransitions,Je as pipeTransitions,re as run,Se as runAsync,nr as runMachine,je as runSequence,Fe as runWithDebug,Ft as runWithEnsemble,At as runWithRunner,R as setContext,it as spawn,tt as state,Re as step,Oe as stepAsync,k as tag,It as toggle,ke as transitionTo,q as when,rn as whenContext,He as whenGuard,Ie as whenGuardAsync,de as withAnalytics,Ue as withDebugging,le as withErrorReporting,$ as withHistory,ce as withLogging,xe as withPerformanceMonitoring,ue as withPermissions,Me as withRetry,W as withSnapshot,U as withTimeTravel,ye as withValidation,ve as yieldMachine};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function u(t,e){return typeof t=="object"?t:e?{...e,tag:t}:{tag:t}}(e=>{function t(n){return n?a=>e(n,a):a=>
|
|
1
|
+
function u(t,e){return typeof t=="object"?t:e?{...e,tag:t}:{tag:t}}(e=>{function t(n){return n?a=>e(n,a):a=>r=>e(a,r)}e.factory=t})(u||(u={}));function C(t,e){return t.tag===e}function T(t){if(Object.freeze(t),typeof Object.values=="function")for(let e of Object.values(t))e&&typeof e=="object"&&T(e);return t}function f(t,e){let n;return n=Object.assign({},t,e(t,r=>r===t?n:f(r,e))),n}function M(t,e){let n=e[t.tag];return n(t)}var x=Symbol("lifecycle");function b(t,e){let n={...t};return n[x]=e,n}function h(t){let e=t,n=null,a=new Set,r=()=>{a.forEach(s=>s(e))},c=()=>{n&&(n(),n=null);let s=e[x],i=e.tag,o=s==null?void 0:s[i];o!=null&&o.onEnter&&(n=o.onEnter(d))},d=(s,...i)=>{let o=e[s];if(typeof o=="function"){let g=o(...i);if(g&&typeof g=="object"&&"tag"in g){let y=g;!y[x]&&e[x]&&(y[x]=e[x]),e=y,c(),r()}}};return c(),{get:()=>e,send:d,stop:()=>{n&&(n(),n=null),a.clear()},subscribe:s=>(a.add(s),()=>a.delete(s))}}function p(t,e){let n={...t};for(let a of Object.keys(e)){let r=e[a],c=new Proxy(r,{get(d,s){let i=d[s];return typeof i=="function"?(...o)=>{let g=i(...o);return p({...t},{...e,[a]:g})}:i}});n[a]=c}return n}function K(){return t=>{let e=n=>{let a=r=>e(r);return f(n,r=>t(r,a))};return e}}function R(){return t=>{let e=n=>{let a=t[n.tag],r=c=>e(c);return f(n,c=>a(c,r))};return e}}export{K as factory,T as freeze,C as isState,f as machine,M as match,h as run,b as runnable,u as tag,R as union,p as withChildren};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var Q=Symbol.for("__machine_transitions__");function S(e,t){return Object.defineProperty(e,Q,{value:t,enumerable:!1,configurable:!1}),e}function F(e){if(!(!e||typeof e!="object"))return e[Q]}function R(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function X(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function pe(e){return function*(){return yield e}()}function ge(e){return e}function Ce(e,t){return t.reduce((n,r)=>X(r,n),e)}function me(e){return e}function Te(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,i=0;for(n(i,o);;){let{value:a,done:s}=r.next(o);if(s)return console.log("Final:",a),a;o=a,i++,n(i,o)}}async function be(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=await n.next(r);if(i)return o;r=o}}async function*we(e){return yield e}var Ee=Symbol("MachineMeta"),Z=Symbol("__machine_runtime_meta__");function w(e,t){let n=e[Z]||{},r={...n,...t};t.guards&&n.guards?r.guards=[...t.guards,...n.guards]:t.guards&&(r.guards=[...t.guards]),t.actions&&n.actions?r.actions=[...t.actions,...n.actions]:t.actions&&(r.actions=[...t.actions]),Object.defineProperty(e,Z,{value:r,enumerable:!1,writable:!1,configurable:!0})}function Ae(e,t){return w(t,{target:e.name||e.toString()}),t}function Se(e,t){return w(t,{description:e}),t}function Fe(e,t){return w(t,{guards:[e]}),t}function Re(e,t){return w(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function je(e,t){return w(t,{actions:[e]}),t}function P(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(e(d,...u)){let y=c?this:{context:this};return t.apply(y,u)}else if(r==="throw"){let y=o||"Guard condition failed";throw new Error(y)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,u);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),w(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function O(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...u){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(await Promise.resolve(e(d,...u))){let y=c?this:{context:this};return t.apply(y,u)}else if(r==="throw"){let y=o||"Guard condition failed";throw new Error(y)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,u);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),w(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"Runtime condition check"}]}),s}function ve(e){return{do(t){let n=P(e,t);return n.else=function(r){return P(e,t,{onFail:r})},n}}}function Pe(e){return{do(t){let n=O(e,t);return n.else=function(r){return O(e,t,{onFail:r})},n}}}function Oe(e,t){return t}function Be(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...i}=e,a=new Proxy({},{get(s,u){let c=n[u];if(typeof c=="function")return(...d)=>{let l=c.apply(n,d),y=Object.assign({context:l.context},i);return r(y),y}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function B(e,t,n){let r=()=>{let i=e.getContext(),a=n(i),s=t[a];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(a)}".`);return s(i)},o=new Proxy({},{get(i,a){let s=r(),u=s[a];if(typeof u!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...c)=>u.apply(s,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function Mt(e,t){return function(r){return B(e,r,t)}}function yt(e,t){let n=Be(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function lt(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var ee=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function xt(e,t){let n=new e(t);return new Proxy({},{get(r,o){let i=t.getContext();if(o in i)return i[o];let a=n[o];if(typeof a=="function")return(...s)=>a.apply(n,s)},set(r,o,i){let a=t.getContext();if(o in a){let s={...a,[o]:i};return t.setContext(s),!0}return!1},has(r,o){let i=t.getContext();return o in i||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),i=Object.keys(o),a=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...i,...a]))},getOwnPropertyDescriptor(r,o){let i=t.getContext();if(o in i||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function ht(e,t,n){let r=()=>{let o=n(e),i=t[o];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return i(e)};return new Proxy(e,{get(o,i,a){if(i in o)return o[i];let s=r(),u=s[i];if(typeof u=="function")return(...c)=>{let d=u.apply(s,c);if(typeof d!="object"||d===null){console.warn(`[MutableMachine] Transition "${String(i)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(l=>delete o[l]),Object.assign(o,d)}},set(o,i,a,s){return o[i]=a,!0},has(o,i){let a=r();return i in o||typeof a[i]=="function"}})}function bt(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return A(this,{...this.context,child:r})}return this}}function wt(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),A(this,{...this.context,[e]:!this.context[e]})}}var k=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=class extends m{constructor(n,r,o){super({status:"loading",abortController:new AbortController,attempts:o});this.config=n;this.params=r;this.succeed=n=>{var r,o;return(o=(r=this.config).onSuccess)==null||o.call(r,n),new N(this.config,{status:"success",data:n})};this.fail=n=>{var o,i,a;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new K(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new z(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new _(this.config));this.execute()}async execute(){}},K=class extends m{constructor(n,r,o,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new E(this.config,n!=null?n:this.params,this.context.attempts+1)}},N=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},z=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},_=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}};function Et(e){return new k(e)}function te(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let i={};for(let a in r){let s=r[a];i[a]=(...u)=>{let c=s.apply(e,u);return te(c,t)}}for(let a in o){let s=o[a];i[a]=(...u)=>{let c=s.apply(t,u);return te(e,c)}}return{context:n,...i}}var ne=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:i}=n,a={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(a[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let u=e[s];typeof u=="function"&&s!=="context"&&(a[s]=function(...c){let d=s,l=a.context,y=()=>{let M;try{M=u.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:d,context:l,args:[...c],error:h})}catch(f){if(!r)throw f;o&&console.error(`Middleware error hook error for ${d}:`,f),i==null||i(f,"error",{transitionName:d,context:l,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in a)Object.prototype.hasOwnProperty.call(a,f)&&f!=="context"&&!(f in h)&&(h[f]=a[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&a[f]&&(h[f]=a[f])}}return h};if(M&&typeof M.then=="function")return M.then(f=>{if(x(f),t.after)try{let g=t.after({transitionName:d,prevContext:l,nextContext:f.context,args:[...c]});if(g&&typeof g.then=="function")return g.then(()=>f)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${d}:`,g),i==null||i(g,"after",{transitionName:d,prevContext:l,nextContext:f.context,args:c})}return f});if(x(M),t.after)try{let h=t.after({transitionName:d,prevContext:l,nextContext:M.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>M).catch(f=>{if(!r)throw f;return o&&console.error(`Middleware after hook error for ${d}:`,f),i==null||i(f,"after",{transitionName:d,prevContext:l,nextContext:M.context,args:c}),M})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${d}:`,h),i==null||i(h,"after",{transitionName:d,prevContext:l,nextContext:M.context,args:c})}return M};if(t.before)try{let M=t.before({transitionName:d,context:l,args:[...c]});if(M&&typeof M=="object"&&M&&"then"in M)return M.then(x=>x===ne?a:y()).catch(x=>{if(!r)throw x;return o&&console.error(`Middleware before hook error for ${d}:`,x),i==null||i(x,"before",{transitionName:d,context:l,args:c}),y()});if(M===ne)return a}catch(M){if(!r)throw M;o&&console.error(`Middleware before hook error for ${d}:`,M),i==null||i(M,"before",{transitionName:d,context:l,args:c})}return y()})}return a}function re(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:i,args:a})=>{let s=r?`→ ${i} [${a.join(", ")}]`:`→ ${i}`;n(s)},after:({transitionName:i,nextContext:a})=>{let s=o?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)},error:({transitionName:i,error:a})=>{console.error(`[Machine] ${i} failed:`,a)}})}function oe(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return C(e,{after:({transitionName:a,prevContext:s,nextContext:u,args:c})=>{let d=`${r}.${a}`,l={transition:a};o&&(l.from=s),l.to=u,i&&(l.args=c),t(d,l)}})}function ie(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function ae(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function se(e,t,n={}){let{includeArgs:r=!1}=n;return C(e,{error:o=>{let i={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,i)}})}function ce(e,t){let n=new Map;return C(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let i=Date.now()-o;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};t(a)}}})}function de(e,t={}){var u,c;let{maxAttempts:n=(u=t.maxRetries)!=null?u:3,shouldRetry:r=()=>!0,backoffMs:o=(c=t.delay)!=null?c:100,backoffMultiplier:i=2,onRetry:a}=t,s={...e};for(let d in e){if(!Object.prototype.hasOwnProperty.call(e,d))continue;let l=e[d];typeof l=="function"&&d!=="context"&&(s[d]=async function(...y){let M,x=0;for(;x<n;)try{return await l.apply(this,y)}catch(h){if(M=h,x++,x<n&&r(M,x)){a==null||a(M,x);let g=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(b=>setTimeout(b,g))}else throw M}throw M})}return s}function St(e,t){return n=>C(n,e,t)}function G(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,i=[],a=0,s=C(e,{before:({transitionName:u,args:c})=>{let d={id:`entry-${a++}`,transitionName:u,args:[...c],timestamp:Date.now()};if(r)try{d.serializedArgs=r.serialize(c)}catch(l){console.error("Failed to serialize history args:",l)}i.push(d),n&&i.length>n&&i.shift(),o==null||o(d)}});return Object.assign(s,{history:i,clearHistory:()=>{i.length=0,a=0}})}function W(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,u=C(e,{after:({transitionName:d,prevContext:l,nextContext:y})=>{if(i&&JSON.stringify(l)===JSON.stringify(y))return;let M={id:`snapshot-${s++}`,transitionName:d,before:{...l},after:{...y},timestamp:Date.now()};if(r)try{M.serializedBefore=r.serialize(l),M.serializedAfter=r.serialize(y)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{M.diff=o(l,y)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(M),n&&a.length>n&&a.shift()}});return Object.assign(u,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:d=>{let l=Object.fromEntries(Object.entries(e).filter(([y])=>y!=="context"&&y!=="snapshots"&&y!=="clearSnapshots"&&y!=="restoreSnapshot"&&typeof e[y]=="function"));return Object.assign({context:d},l)}})}function H(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,u=0,c=C(e,{before:({transitionName:y,args:M})=>{let x={id:`entry-${s++}`,transitionName:y,args:[...M],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(M)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),n&&i.length>n&&i.shift(),o==null||o("history",x)},after:({transitionName:y,prevContext:M,nextContext:x})=>{let h={id:`snapshot-${u++}`,transitionName:y,before:{...M},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(M),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}a.push(h),n&&a.length>n&&a.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,u=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,u=0},restoreSnapshot:y=>{let M=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="history"&&x!=="snapshots"&&x!=="clearHistory"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&x!=="clearTimeTravel"&&x!=="replayFrom"&&typeof e[x]=="function"));return Object.assign({context:y},M)},replayFrom:y=>{var g;if(y<0||y>=i.length)throw new Error(`Invalid replay start index: ${y}`);let M=(g=a[y])==null?void 0:g.before;if(!M)throw new Error(`No snapshot available for index ${y}`);let x=i.slice(y),f=Object.assign({context:M},Object.fromEntries(Object.entries(e).filter(([b])=>b!=="context"&&typeof e[b]=="function")));for(let b of x){let J=f[b.transitionName];J&&(f=J.apply(f,b.args))}return f}})}function _t(e,...t){return t.reduce((n,r)=>r(n),e)}function $(e,...t){return t.reduce((n,r)=>r(n),e)}var D=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function Gt(e){return new D(e)}function V(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Wt(e){return V(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function Ht(e,t,n){return V(n,r=>r.context[e]===t)}function $t(){let e=new Map;return{register(t,n,r,o){if(e.has(t))throw new Error(`Middleware '${t}' is already registered`);return e.set(t,{name:t,middleware:n,description:r,priority:o}),this},unregister(t){return e.delete(t)},has(t){return e.has(t)},get(t){return e.get(t)},list(){return Array.from(e.values()).sort((t,n)=>{var r,o;return((r=t.priority)!=null?r:0)-((o=n.priority)!=null?o:0)})},apply(t,n){let r=n.map(o=>{let i=e.get(o);if(!i)throw new Error(`Middleware '${o}' is not registered`);return i}).sort((o,i)=>{var a,s;return((a=o.priority)!=null?a:0)-((s=i.priority)!=null?s:0)});return $(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return $(t,...n.map(r=>r.middleware))}}}function Dt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,s=[],u=!0;for(let c=0;c<i.length;c++){let d=i[c];try{if("middleware"in d&&"when"in d){if(!d.when(a))continue;a=d.middleware(a)}else a=d(a)}catch(l){if(u=!1,!t)throw l;s.push({error:l,middlewareIndex:c,middlewareName:d.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,l),r==null||r(l,c,d.name)}}return{machine:a,errors:s,success:u}}}function It(...e){return t=>$(t,...e)}function Vt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function ue(e){return typeof e=="function"&&e.length===1}function Lt(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ue(e.middleware)&&typeof e.when=="function"}function Ut(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||j(e.prevContext,t)&&j(e.nextContext,t))}function qt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||j(e.context,t))}function Yt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!t||j(e.context,t))}function Jt(e,t){if(e===null||typeof e!="object")return!1;let n=e;return!("before"in n&&n.before!==void 0&&typeof n.before!="function"||"after"in n&&n.after!==void 0&&typeof n.after!="function"||"error"in n&&n.error!==void 0&&typeof n.error!="function")}function Qt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function j(e,t){return e!==null&&typeof e=="object"}function Xt(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ue(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function Zt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var I=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>re(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>oe(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>ie(r,t)),this}withPermissions(t){return this.middlewares.push(n=>ae(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>se(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>ce(r,t)),this}withRetry(t){return this.middlewares.push(n=>de(n,t)),this}withHistory(t){return this.middlewares.push(n=>G(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>W(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>H(n,t)),this}withDebugging(){return this.middlewares.push(t=>Ke(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(V(t,n)),this}build(){let t=this.machine;for(let n of this.middlewares)t=n(t);return t}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function ke(e){return new I(e)}function en(e={}){return{create:t=>{let n=ke(t);return e.logging&&n.withLogging(e.logging),e.analytics&&n.withAnalytics(e.analytics.track,e.analytics.options),e.history&&n.withHistory(e.history),e.snapshot&&n.withSnapshot(e.snapshot),e.timeTravel&&n.withTimeTravel(e.timeTravel),e.retry&&n.withRetry(e.retry),n}}}function Ke(e){return H(W(G(e)))}function Ne(e,t){return e instanceof t}function ze(e,...t){return{type:e,args:t}}function _e(e,t){return A(e,n=>({...n,...t}))}async function Ge(e,...t){let n=e;for(let r of t)n=await r(n);return n}function We(e,t){return t?console.log(t,e.context):console.log(e.context),e}function He(e,t){return function(...n){let r=t(this.context,...n);return p(r,e())}}function $e(e,t,...n){return e.apply(t,n)}function Me(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?Me(i):i}:r}})}var L=class e{constructor(t){return this.wrappedMachine=t,new Proxy(this,{get:(n,r)=>{if(r==="wrappedMachine")return Reflect.get(n,r);if(r==="context")return this.wrappedMachine.context;let o=this.wrappedMachine[r];return typeof o=="function"?(...i)=>{let a=o.apply(this.wrappedMachine,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function De(){return function(t){return function(...n){let r=t(this.context,...n);return p(r,this)}}}function ye(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=U(e,{[t]:r});return ye(o)}}}function le(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let u=a(this.context,...s);return p(u,r)}]));return Object.assign(r,o),p(e,r)}}function Ie(e,t){return t!==void 0?p(e,t):le(e)}function p(e,t){if(typeof t=="function"){let i;return i=t(s=>p(s,i)),S(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?R(t):t,o=Object.assign({context:e},r);return S(o,r)}function xe(e,t){if(typeof t=="function"){let i;return i=t(s=>xe(s,i)),S(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?R(t):t,o=Object.assign({context:e},r);return S(o,r)}function Ve(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let i=r(this.context,...o);return p(i,t)}]));return n=>p(n,t)}}function A(e,t){var i;let n=e.context,r=(i=F(e))!=null?i:R(e),o=typeof t=="function"?t(n):t;return p(o,r)}function Le(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function U(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function Ue(e,t){return(...n)=>{let r=e(...n),o=t(),i={...r.context,...o.context},{context:a,...s}=r,{context:u,...c}=o,d={...s,...c};return p(i,d)}}function qe(e){let{context:t,...n}=e;return r=>p(r,n)}function Ye(e,t,n){let r=e.context[t],o=n[r];if(!o)throw new Error(`No handler found for state: ${String(r)}`);return o(e.context)}function Je(e,t,n){return e.context[t]===n}function q(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n,[...i.args,{signal:s.signal}]);return s.signal.aborted||(n=c,t==null||t(n)),n}finally{r===s&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}function Qe(e,t){return A(e,n=>t(n))}import{useState as v,useRef as Y,useEffect as he,useMemo as T,createContext as Xe,useContext as Ze,createElement as et,useSyncExternalStore as tt}from"react";function nt(e){let[t,n]=v(e),r=T(()=>q(t,i=>{n(i)}),[]),o=T(()=>new Proxy({},{get:(i,a)=>(...s)=>{r.dispatch({type:a,args:s})}}),[r]);return[t,o]}function fe(e,t,n=Object.is){let[r,o]=v(()=>t(e)),i=Y(t),a=Y(n);return i.current=t,a.current=n,he(()=>{let s=i.current(e);a.current(r,s)||o(s)},[e,r]),r}function rt(e,t,n){let[r,o]=v(e),i=Y(r);i.current=r;let a=T(()=>({getContext:()=>i.current,setContext:u=>{o(u)}}),[]);return T(()=>B(a,t,n),[a,t,n])}function ot(){let e=Xe(null),t=({machine:a,actions:s,children:u})=>{let c=T(()=>[a,s],[a,s]);return et(e.Provider,{value:c},u)},n=()=>{let a=Ze(e);if(!a)throw new Error("useMachineContext must be used within a Machine.Provider");return a},r=()=>n()[0];return{Provider:t,useMachineContext:n,useMachineState:r,useMachineActions:()=>n()[1],useSelector:(a,s)=>{let u=r();return fe(u,a,s)}}}function it(e){let t=T(()=>e.subscribe.bind(e),[e]),n=T(()=>e.getSnapshot.bind(e),[e]);return tt(t,n)}function at(e,t,n=Object.is){let r=T(()=>e.getSnapshot.bind(e),[e]),o=()=>t(r()),[i,a]=v(o);return he(()=>{let s=()=>{let u=t(e.getSnapshot());a(c=>n(c,u)?c:u)};return s(),e.subscribe(()=>{s()})},[e,t,n]),i}export{L as BoundMachine,ne as CANCEL,Ee as META_KEY,m as MachineBase,I as MiddlewareBuilder,ee as MultiMachineBase,je as action,Me as bindTransitions,Vt as branch,$e as call,Gt as chain,It as combine,Ue as combineFactories,_t as compose,$ as composeTyped,xe as createAsyncMachine,St as createCustomMiddleware,B as createEnsemble,Mt as createEnsembleFactory,ze as createEvent,Et as createFetchMachine,me as createFlow,le as createFunctionalMachine,p as createMachine,qe as createMachineBuilder,ot as createMachineContext,Ve as createMachineFactory,C as createMiddleware,en as createMiddlewareFactory,$t as createMiddlewareRegistry,xt as createMultiMachine,ht as createMutableMachine,te as createParallelMachine,Dt as createPipeline,Be as createRunner,He as createTransition,ye as createTransitionExtender,De as createTransitionFactory,bt as delegateToChild,Se as describe,U as extendTransitions,P as guard,O as guardAsync,Fe as guarded,Je as hasState,Wt as inDevelopment,Re as invoke,Lt as isConditionalMiddleware,qt as isMiddlewareContext,Yt as isMiddlewareError,ue as isMiddlewareFn,Jt as isMiddlewareHooks,Qt as isMiddlewareOptions,Ut as isMiddlewareResult,Xt as isNamedMiddleware,Zt as isPipelineConfig,Ne as isState,We as logState,Ye as matchMachine,_e as mergeContext,Oe as metadata,ke as middlewareBuilder,Qe as next,Le as overrideTransitions,Ge as pipeTransitions,X as run,be as runAsync,q as runMachine,Ce as runSequence,Te as runWithDebug,lt as runWithEnsemble,yt as runWithRunner,A as setContext,Ie as state,pe as step,we as stepAsync,wt as toggle,Ae as transitionTo,it as useActor,at as useActorSelector,rt as useEnsemble,nt as useMachine,fe as useMachineSelector,V as when,Ht as whenContext,ve as whenGuard,Pe as whenGuardAsync,oe as withAnalytics,Ke as withDebugging,se as withErrorReporting,G as withHistory,re as withLogging,ce as withPerformanceMonitoring,ae as withPermissions,de as withRetry,W as withSnapshot,H as withTimeTravel,ie as withValidation,ge as yieldMachine};
|
|
1
|
+
var Q=Symbol.for("__machine_transitions__");function S(e,t){return Object.defineProperty(e,Q,{value:t,enumerable:!1,configurable:!1}),e}function F(e){if(!(!e||typeof e!="object"))return e[Q]}function R(e){if(!e||typeof e!="object")return{};let t=Object.entries(e).filter(([n,r])=>n!=="context"&&typeof r=="function");return Object.fromEntries(t)}var m=class{constructor(t){this.context=t}};function X(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function pe(e){return function*(){return yield e}()}function ge(e){return e}function Ce(e,t){return t.reduce((n,r)=>X(r,n),e)}function me(e){return e}function Te(e,t,n=(r,o)=>{console.log(`Step ${r}:`,o.context)}){let r=e(t),o=t,i=0;for(n(i,o);;){let{value:a,done:s}=r.next(o);if(s)return console.log("Final:",a),a;o=a,i++,n(i,o)}}async function be(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=await n.next(r);if(i)return o;r=o}}async function*we(e){return yield e}var Ee=Symbol("MachineMeta"),Z=Symbol("__machine_runtime_meta__");function w(e,t){let n=e[Z]||{},r={...n,...t};t.guards&&n.guards?r.guards=[...t.guards,...n.guards]:t.guards&&(r.guards=[...t.guards]),t.actions&&n.actions?r.actions=[...t.actions,...n.actions]:t.actions&&(r.actions=[...t.actions]),Object.defineProperty(e,Z,{value:r,enumerable:!1,writable:!1,configurable:!0})}function Ae(e,t){return w(t,{target:e.name||e.toString()}),t}function Se(e,t){return w(t,{description:e}),t}function Fe(e,t){return w(t,{guards:[e]}),t}function Re(e,t){return w(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function je(e,t){return w(t,{actions:[e]}),t}function P(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...d){let c=typeof this=="object"&&"context"in this,u=c?this.context:this;if(e(u,...d)){let l=c?this:{context:this};return t.apply(l,d)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),w(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function O(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...d){let c=typeof this=="object"&&"context"in this,u=c?this.context:this;if(await Promise.resolve(e(u,...d))){let l=c?this:{context:this};return t.apply(l,d)}else if(r==="throw"){let l=o||"Guard condition failed";throw new Error(l)}else if(r==="ignore"){if(c)return this;throw new Error('Cannot use "ignore" mode with context-only binding. Use full machine binding or provide fallback.')}else if(typeof r=="function"){if(c)return r.apply(this,d);throw new Error("Cannot use function fallback with context-only binding. Use full machine binding.")}else return r};return Object.defineProperty(s,"__guard",{value:!0,enumerable:!1}),Object.defineProperty(s,"condition",{value:e,enumerable:!1}),Object.defineProperty(s,"transition",{value:t,enumerable:!1}),Object.defineProperty(s,"options",{value:a,enumerable:!1}),w(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"Runtime condition check"}]}),s}function ve(e){return{do(t){let n=P(e,t);return n.else=function(r){return P(e,t,{onFail:r})},n}}}function Pe(e){return{do(t){let n=O(e,t);return n.else=function(r){return O(e,t,{onFail:r})},n}}}function Oe(e,t){return t}function Be(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...i}=e,a=new Proxy({},{get(s,d){let c=n[d];if(typeof c=="function")return(...u)=>{let y=c.apply(n,u),l=Object.assign({context:y.context},i);return r(l),l}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function B(e,t,n){let r=()=>{let i=e.getContext(),a=n(i),s=t[a];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(a)}".`);return s(i)},o=new Proxy({},{get(i,a){let s=r(),d=s[a];if(typeof d!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...c)=>d.apply(s,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function Mt(e,t){return function(r){return B(e,r,t)}}function lt(e,t){let n=Be(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function yt(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var ee=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function xt(e,t){let n=new e(t);return new Proxy({},{get(r,o){let i=t.getContext();if(o in i)return i[o];let a=n[o];if(typeof a=="function")return(...s)=>a.apply(n,s)},set(r,o,i){let a=t.getContext();if(o in a){let s={...a,[o]:i};return t.setContext(s),!0}return!1},has(r,o){let i=t.getContext();return o in i||typeof n[o]=="function"},ownKeys(r){let o=t.getContext(),i=Object.keys(o),a=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...i,...a]))},getOwnPropertyDescriptor(r,o){let i=t.getContext();if(o in i||typeof n[o]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function ht(e,t,n){let r=()=>{let o=n(e),i=t[o];if(!i)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(o)}".`);return i(e)};return new Proxy(e,{get(o,i,a){if(i in o)return o[i];let s=r(),d=s[i];if(typeof d=="function")return(...c)=>{let u=d.apply(s,c);if(typeof u!="object"||u===null){console.warn(`[MutableMachine] Transition "${String(i)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(o).forEach(y=>delete o[y]),Object.assign(o,u)}},set(o,i,a,s){return o[i]=a,!0},has(o,i){let a=r();return i in o||typeof a[i]=="function"}})}function bt(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return A(this,{...this.context,child:r})}return this}}function wt(e){return function(){return typeof this.context[e]!="boolean"&&console.warn(`[toggle primitive] Property '${String(e)}' is not a boolean. Toggling may have unexpected results.`),A(this,{...this.context,[e]:!this.context[e]})}}var k=class extends m{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},E=class extends m{constructor(n,r,o){super({status:"loading",abortController:new AbortController,attempts:o});this.config=n;this.params=r;this.succeed=n=>{var r,o;return(o=(r=this.config).onSuccess)==null||o.call(r,n),new N(this.config,{status:"success",data:n})};this.fail=n=>{var o,i,a;let r=(o=this.config.maxRetries)!=null?o:3;return this.context.attempts<r?new K(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new z(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new _(this.config));this.execute()}async execute(){}},K=class extends m{constructor(n,r,o,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new E(this.config,n!=null?n:this.params,this.context.attempts+1)}},N=class extends m{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},z=class extends m{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},_=class extends m{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}};function Et(e){return new k(e)}function te(e,t){let n={...e.context,...t.context},r={...e},o={...t};delete r.context,delete o.context;let i={};for(let a in r){let s=r[a];i[a]=(...d)=>{let c=s.apply(e,d);return te(c,t)}}for(let a in o){let s=o[a];i[a]=(...d)=>{let c=s.apply(t,d);return te(e,c)}}return{context:n,...i}}var ne=Symbol("CANCEL");function C(e,t,n={}){let{continueOnError:r=!1,logErrors:o=!0,onError:i}=n,a={...e};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&s!=="context"&&typeof e[s]!="function"&&(a[s]=e[s]);for(let s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;let d=e[s];typeof d=="function"&&s!=="context"&&(a[s]=function(...c){let u=s,y=a.context,l=()=>{let M;try{M=d.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:u,context:y,args:[...c],error:h})}catch(f){if(!r)throw f;o&&console.error(`Middleware error hook error for ${u}:`,f),i==null||i(f,"error",{transitionName:u,context:y,args:c,error:h})}throw h}let x=h=>{if(h&&typeof h=="object"&&h.context){for(let f in a)Object.prototype.hasOwnProperty.call(a,f)&&f!=="context"&&!(f in h)&&(h[f]=a[f]);for(let f in h){if(!Object.prototype.hasOwnProperty.call(h,f))continue;typeof h[f]=="function"&&f!=="context"&&a[f]&&(h[f]=a[f])}}return h};if(M&&typeof M.then=="function")return M.then(f=>{if(x(f),t.after)try{let g=t.after({transitionName:u,prevContext:y,nextContext:f.context,args:[...c]});if(g&&typeof g.then=="function")return g.then(()=>f)}catch(g){if(!r)throw g;o&&console.error(`Middleware after hook error for ${u}:`,g),i==null||i(g,"after",{transitionName:u,prevContext:y,nextContext:f.context,args:c})}return f});if(x(M),t.after)try{let h=t.after({transitionName:u,prevContext:y,nextContext:M.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>M).catch(f=>{if(!r)throw f;return o&&console.error(`Middleware after hook error for ${u}:`,f),i==null||i(f,"after",{transitionName:u,prevContext:y,nextContext:M.context,args:c}),M})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${u}:`,h),i==null||i(h,"after",{transitionName:u,prevContext:y,nextContext:M.context,args:c})}return M};if(t.before)try{let M=t.before({transitionName:u,context:y,args:[...c]});if(M&&typeof M=="object"&&M&&"then"in M)return M.then(x=>x===ne?a:l()).catch(x=>{if(!r)throw x;return o&&console.error(`Middleware before hook error for ${u}:`,x),i==null||i(x,"before",{transitionName:u,context:y,args:c}),l()});if(M===ne)return a}catch(M){if(!r)throw M;o&&console.error(`Middleware before hook error for ${u}:`,M),i==null||i(M,"before",{transitionName:u,context:y,args:c})}return l()})}return a}function re(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:o=!0}=t;return C(e,{before:({transitionName:i,args:a})=>{let s=r?`→ ${i} [${a.join(", ")}]`:`→ ${i}`;n(s)},after:({transitionName:i,nextContext:a})=>{let s=o?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)},error:({transitionName:i,error:a})=>{console.error(`[Machine] ${i} failed:`,a)}})}function oe(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!1}=n;return C(e,{after:({transitionName:a,prevContext:s,nextContext:d,args:c})=>{let u=`${r}.${a}`,y={transition:a};o&&(y.from=s),y.to=d,i&&(y.args=c),t(u,y)}})}function ie(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function ae(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function se(e,t,n={}){let{includeArgs:r=!1}=n;return C(e,{error:o=>{let i={transition:o.transitionName,context:o.context,...r&&{args:o.args}};t(o.error,i)}})}function ce(e,t){let n=new Map;return C(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let o=n.get(r.transitionName);if(o){let i=Date.now()-o;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:i,context:r.nextContext||r.prevContext};t(a)}}})}function de(e,t={}){var d,c;let{maxAttempts:n=(d=t.maxRetries)!=null?d:3,shouldRetry:r=()=>!0,backoffMs:o=(c=t.delay)!=null?c:100,backoffMultiplier:i=2,onRetry:a}=t,s={...e};for(let u in e){if(!Object.prototype.hasOwnProperty.call(e,u))continue;let y=e[u];typeof y=="function"&&u!=="context"&&(s[u]=async function(...l){let M,x=0;for(;x<n;)try{return await y.apply(this,l)}catch(h){if(M=h,x++,x<n&&r(M,x)){a==null||a(M,x);let g=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(b=>setTimeout(b,g))}else throw M}throw M})}return s}function St(e,t){return n=>C(n,e,t)}function G(e,t={}){let{maxSize:n,serializer:r,onEntry:o}=t,i=[],a=0,s=C(e,{before:({transitionName:d,args:c})=>{let u={id:`entry-${a++}`,transitionName:d,args:[...c],timestamp:Date.now()};if(r)try{u.serializedArgs=r.serialize(c)}catch(y){console.error("Failed to serialize history args:",y)}i.push(u),n&&i.length>n&&i.shift(),o==null||o(u)}});return Object.assign(s,{history:i,clearHistory:()=>{i.length=0,a=0}})}function W(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,d=C(e,{after:({transitionName:u,prevContext:y,nextContext:l})=>{if(i&&JSON.stringify(y)===JSON.stringify(l))return;let M={id:`snapshot-${s++}`,transitionName:u,before:{...y},after:{...l},timestamp:Date.now()};if(r)try{M.serializedBefore=r.serialize(y),M.serializedAfter=r.serialize(l)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{M.diff=o(y,l)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(M),n&&a.length>n&&a.shift()}});return Object.assign(d,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:u=>{let y=Object.fromEntries(Object.entries(e).filter(([l])=>l!=="context"&&l!=="snapshots"&&l!=="clearSnapshots"&&l!=="restoreSnapshot"&&typeof e[l]=="function"));return Object.assign({context:u},y)}})}function H(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,d=0,c=C(e,{before:({transitionName:l,args:M})=>{let x={id:`entry-${s++}`,transitionName:l,args:[...M],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(M)}catch(h){console.error("Failed to serialize history args:",h)}i.push(x),n&&i.length>n&&i.shift(),o==null||o("history",x)},after:({transitionName:l,prevContext:M,nextContext:x})=>{let h={id:`snapshot-${d++}`,transitionName:l,before:{...M},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(M),h.serializedAfter=r.serialize(x)}catch(f){console.error("Failed to serialize snapshot:",f)}a.push(h),n&&a.length>n&&a.shift(),o==null||o("snapshot",h)}});return Object.assign(c,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,d=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,d=0},restoreSnapshot:l=>{let M=Object.fromEntries(Object.entries(e).filter(([x])=>x!=="context"&&x!=="history"&&x!=="snapshots"&&x!=="clearHistory"&&x!=="clearSnapshots"&&x!=="restoreSnapshot"&&x!=="clearTimeTravel"&&x!=="replayFrom"&&typeof e[x]=="function"));return Object.assign({context:l},M)},replayFrom:l=>{var g;if(l<0||l>=i.length)throw new Error(`Invalid replay start index: ${l}`);let M=(g=a[l])==null?void 0:g.before;if(!M)throw new Error(`No snapshot available for index ${l}`);let x=i.slice(l),f=Object.assign({context:M},Object.fromEntries(Object.entries(e).filter(([b])=>b!=="context"&&typeof e[b]=="function")));for(let b of x){let J=f[b.transitionName];J&&(f=J.apply(f,b.args))}return f}})}function _t(e,...t){return t.reduce((n,r)=>r(n),e)}function $(e,...t){return t.reduce((n,r)=>r(n),e)}var D=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function Gt(e){return new D(e)}function V(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Wt(e){return V(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function Ht(e,t,n){return V(n,r=>r.context[e]===t)}function $t(){let e=new Map;return{register(t,n,r,o){if(e.has(t))throw new Error(`Middleware '${t}' is already registered`);return e.set(t,{name:t,middleware:n,description:r,priority:o}),this},unregister(t){return e.delete(t)},has(t){return e.has(t)},get(t){return e.get(t)},list(){return Array.from(e.values()).sort((t,n)=>{var r,o;return((r=t.priority)!=null?r:0)-((o=n.priority)!=null?o:0)})},apply(t,n){let r=n.map(o=>{let i=e.get(o);if(!i)throw new Error(`Middleware '${o}' is not registered`);return i}).sort((o,i)=>{var a,s;return((a=o.priority)!=null?a:0)-((s=i.priority)!=null?s:0)});return $(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return $(t,...n.map(r=>r.middleware))}}}function Dt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,s=[],d=!0;for(let c=0;c<i.length;c++){let u=i[c];try{if("middleware"in u&&"when"in u){if(!u.when(a))continue;a=u.middleware(a)}else a=u(a)}catch(y){if(d=!1,!t)throw y;s.push({error:y,middlewareIndex:c,middlewareName:u.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,y),r==null||r(y,c,u.name)}}return{machine:a,errors:s,success:d}}}function It(...e){return t=>$(t,...e)}function Vt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function ue(e){return typeof e=="function"&&e.length===1}function Lt(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ue(e.middleware)&&typeof e.when=="function"}function Ut(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"prevContext"in e&&"nextContext"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||j(e.prevContext,t)&&j(e.nextContext,t))}function qt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&(!t||j(e.context,t))}function Yt(e,t){return e!==null&&typeof e=="object"&&"transitionName"in e&&"context"in e&&"args"in e&&"error"in e&&typeof e.transitionName=="string"&&Array.isArray(e.args)&&e.error instanceof Error&&(!t||j(e.context,t))}function Jt(e,t){if(e===null||typeof e!="object")return!1;let n=e;return!("before"in n&&n.before!==void 0&&typeof n.before!="function"||"after"in n&&n.after!==void 0&&typeof n.after!="function"||"error"in n&&n.error!==void 0&&typeof n.error!="function")}function Qt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}function j(e,t){return e!==null&&typeof e=="object"}function Xt(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ue(e.middleware)&&("description"in e?typeof e.description=="string"||e.description===void 0:!0)&&("priority"in e?typeof e.priority=="number"||e.priority===void 0:!0)}function Zt(e){return e===void 0||e!==null&&typeof e=="object"&&("continueOnError"in e?typeof e.continueOnError=="boolean":!0)&&("logErrors"in e?typeof e.logErrors=="boolean":!0)&&("onError"in e?typeof e.onError=="function"||e.onError===void 0:!0)}var I=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>re(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>oe(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>ie(r,t)),this}withPermissions(t){return this.middlewares.push(n=>ae(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>se(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>ce(r,t)),this}withRetry(t){return this.middlewares.push(n=>de(n,t)),this}withHistory(t){return this.middlewares.push(n=>G(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>W(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>H(n,t)),this}withDebugging(){return this.middlewares.push(t=>Ke(t)),this}withCustom(t){return this.middlewares.push(t),this}withConditional(t,n){return this.middlewares.push(V(t,n)),this}build(){let t=this.machine;for(let n of this.middlewares)t=n(t);return t}getChain(){return[...this.middlewares]}clear(){return this.middlewares=[],this}};function ke(e){return new I(e)}function en(e={}){return{create:t=>{let n=ke(t);return e.logging&&n.withLogging(e.logging),e.analytics&&n.withAnalytics(e.analytics.track,e.analytics.options),e.history&&n.withHistory(e.history),e.snapshot&&n.withSnapshot(e.snapshot),e.timeTravel&&n.withTimeTravel(e.timeTravel),e.retry&&n.withRetry(e.retry),n}}}function Ke(e){return H(W(G(e)))}function Ne(e,t){return e instanceof t}function ze(e,...t){return{type:e,args:t}}function _e(e,t){return A(e,n=>({...n,...t}))}async function Ge(e,...t){let n=e;for(let r of t)n=await r(n);return n}function We(e,t){return t?console.log(t,e.context):console.log(e.context),e}function He(e,t){return function(...n){let r=t(this.context,...n);return p(r,e())}}function $e(e,t,...n){return e.apply(t,n)}function Me(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t,o);return i&&typeof i=="object"&&"context"in i?Me(i):i}:r}})}var L=class e{constructor(t){return this.wrappedMachine=t,new Proxy(this,{get:(n,r)=>{if(r==="wrappedMachine")return Reflect.get(n,r);if(r==="context")return this.wrappedMachine.context;let o=this.wrappedMachine[r];return typeof o=="function"?(...i)=>{let a=o.apply(this.wrappedMachine,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function De(){return function(t){return function(...n){let r=t(this.context,...n);return p(r,this)}}}function le(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=U(e,{[t]:r});return le(o)}}}function ye(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let d=a(this.context,...s);return p(d,r)}]));return Object.assign(r,o),p(e,r)}}function Ie(e,t){return t!==void 0?p(e,t):ye(e)}function p(e,t){if(typeof t=="function"){let i,a;return a=t(d=>d===e?i:p(d,a)),i=S(Object.assign({context:e},a),a),i}let n=F(t),r=n!=null?n:"context"in t?R(t):t,o=Object.assign({context:e},r);return S(o,r)}function xe(e,t){if(typeof t=="function"){let i;return i=t(s=>xe(s,i)),S(Object.assign({context:e},i),i)}let n=F(t),r=n!=null?n:"context"in t?R(t):t,o=Object.assign({context:e},r);return S(o,r)}function Ve(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let i=r(this.context,...o);return p(i,t)}]));return n=>p(n,t)}}function A(e,t){var i;let n=e.context,r=(i=F(e))!=null?i:R(e),o=typeof t=="function"?t(n):t;return p(o,r)}function Le(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function U(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function Ue(e,t){return(...n)=>{let r=e(...n),o=t(),i={...r.context,...o.context},{context:a,...s}=r,{context:d,...c}=o,u={...s,...c};return p(i,u)}}function qe(e){let{context:t,...n}=e;return r=>p(r,n)}function Ye(e,t,n){let r=e.context[t],o=n[r];if(!o)throw new Error(`No handler found for state: ${String(r)}`);return o(e.context)}function Je(e,t,n){return e.context[t]===n}function q(e,t){let n=e,r=null;async function o(i){r&&(r.abort(),r=null);let a=n[i.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(i.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n,[...i.args,{signal:s.signal}]);return s.signal.aborted||(n=c,t==null||t(n)),n}finally{r===s&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}function Qe(e,t){return A(e,n=>t(n))}import{useState as v,useRef as Y,useEffect as he,useMemo as T,createContext as Xe,useContext as Ze,createElement as et,useSyncExternalStore as tt}from"react";function nt(e){let[t,n]=v(e),r=T(()=>q(t,i=>{n(i)}),[]),o=T(()=>new Proxy({},{get:(i,a)=>(...s)=>{r.dispatch({type:a,args:s})}}),[r]);return[t,o]}function fe(e,t,n=Object.is){let[r,o]=v(()=>t(e)),i=Y(t),a=Y(n);return i.current=t,a.current=n,he(()=>{let s=i.current(e);a.current(r,s)||o(s)},[e,r]),r}function rt(e,t,n){let[r,o]=v(e),i=Y(r);i.current=r;let a=T(()=>({getContext:()=>i.current,setContext:d=>{o(d)}}),[]);return T(()=>B(a,t,n),[a,t,n])}function ot(){let e=Xe(null),t=({machine:a,actions:s,children:d})=>{let c=T(()=>[a,s],[a,s]);return et(e.Provider,{value:c},d)},n=()=>{let a=Ze(e);if(!a)throw new Error("useMachineContext must be used within a Machine.Provider");return a},r=()=>n()[0];return{Provider:t,useMachineContext:n,useMachineState:r,useMachineActions:()=>n()[1],useSelector:(a,s)=>{let d=r();return fe(d,a,s)}}}function it(e){let t=T(()=>e.subscribe.bind(e),[e]),n=T(()=>e.getSnapshot.bind(e),[e]);return tt(t,n)}function at(e,t,n=Object.is){let r=T(()=>e.getSnapshot.bind(e),[e]),o=()=>t(r()),[i,a]=v(o);return he(()=>{let s=()=>{let d=t(e.getSnapshot());a(c=>n(c,d)?c:d)};return s(),e.subscribe(()=>{s()})},[e,t,n]),i}export{L as BoundMachine,ne as CANCEL,Ee as META_KEY,m as MachineBase,I as MiddlewareBuilder,ee as MultiMachineBase,je as action,Me as bindTransitions,Vt as branch,$e as call,Gt as chain,It as combine,Ue as combineFactories,_t as compose,$ as composeTyped,xe as createAsyncMachine,St as createCustomMiddleware,B as createEnsemble,Mt as createEnsembleFactory,ze as createEvent,Et as createFetchMachine,me as createFlow,ye as createFunctionalMachine,p as createMachine,qe as createMachineBuilder,ot as createMachineContext,Ve as createMachineFactory,C as createMiddleware,en as createMiddlewareFactory,$t as createMiddlewareRegistry,xt as createMultiMachine,ht as createMutableMachine,te as createParallelMachine,Dt as createPipeline,Be as createRunner,He as createTransition,le as createTransitionExtender,De as createTransitionFactory,bt as delegateToChild,Se as describe,U as extendTransitions,P as guard,O as guardAsync,Fe as guarded,Je as hasState,Wt as inDevelopment,Re as invoke,Lt as isConditionalMiddleware,qt as isMiddlewareContext,Yt as isMiddlewareError,ue as isMiddlewareFn,Jt as isMiddlewareHooks,Qt as isMiddlewareOptions,Ut as isMiddlewareResult,Xt as isNamedMiddleware,Zt as isPipelineConfig,Ne as isState,We as logState,Ye as matchMachine,_e as mergeContext,Oe as metadata,ke as middlewareBuilder,Qe as next,Le as overrideTransitions,Ge as pipeTransitions,X as run,be as runAsync,q as runMachine,Ce as runSequence,Te as runWithDebug,yt as runWithEnsemble,lt as runWithRunner,A as setContext,Ie as state,pe as step,we as stepAsync,wt as toggle,Ae as transitionTo,it as useActor,at as useActorSelector,rt as useEnsemble,nt as useMachine,fe as useMachineSelector,V as when,Ht as whenContext,ve as whenGuard,Pe as whenGuardAsync,oe as withAnalytics,Ke as withDebugging,se as withErrorReporting,G as withHistory,re as withLogging,ce as withPerformanceMonitoring,ae as withPermissions,de as withRetry,W as withSnapshot,H as withTimeTravel,ie as withValidation,ge as yieldMachine};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,OAAO,CACjB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,GAAG,EAAE,IACnB;IACF,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;CACrB,GAAG,CAAC,CAAC;AAEN;;;;GAIG;AACH,MAAM,MAAM,YAAY,CACtB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,GAAG,EAAE,IACnB;IACF,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;CACrB,GAAG,CAAC,CAAC;AAEN;;;GAGG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,IAC1F,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,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AM,YAAY,CAAC;AAMvC,cAAc,SAAS,CAAC"}
|
package/dist/types/minimal.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ type ChildProxy<P extends object, C extends Record<string, object>, Child extend
|
|
|
53
53
|
[K in keyof Child]: Child[K] extends (...args: infer A) => unknown ? (...args: A) => ParentMachine<P, C> : Child[K];
|
|
54
54
|
};
|
|
55
55
|
export declare function withChildren<P extends object, C extends Record<string, object>>(parent: P, children: C): ParentMachine<P, C>;
|
|
56
|
-
export declare function factory<C extends object>(): <T
|
|
56
|
+
export declare function factory<C extends object>(): <T extends Record<string, Function>>(transitionFactory: (ctx: C, next: (context: C) => C & T) => T) => (context: C) => C & T;
|
|
57
57
|
/**
|
|
58
58
|
* Extracts the union of all possible machine states from a union factory.
|
|
59
59
|
*/
|
|
@@ -61,35 +61,12 @@ export type UnionOf<F extends (...args: any[]) => any> = ReturnType<F>;
|
|
|
61
61
|
/**
|
|
62
62
|
* Creates a union factory that routes to different transition factories based on a tag.
|
|
63
63
|
* This is the primary way to define multi-state machines (Type-States) in the minimal API.
|
|
64
|
-
*
|
|
65
|
-
* @param factories - A map of tags to transition factories.
|
|
66
|
-
* @returns A single factory function that produces the correct machine based on the input context's tag.
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* const auth = union({
|
|
70
|
-
* idle: (ctx, next) => ({ login: () => next({ tag: 'loggedIn', user: 'alice' }) }),
|
|
71
|
-
* loggedIn: (ctx, next) => ({ logout: () => next({ tag: 'idle' }) })
|
|
72
|
-
* });
|
|
73
|
-
*
|
|
74
|
-
* const m = auth({ tag: 'idle' });
|
|
75
|
-
* const next = m.login(); // Transition to loggedIn state
|
|
76
|
-
*/
|
|
77
|
-
/**
|
|
78
|
-
* Creates a union factory that routes to different transition factories based on a tag.
|
|
79
|
-
* This is the primary way to define multi-state machines (Type-States) in the minimal API.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* const auth = union<AuthState>()({
|
|
83
|
-
* idle: (ctx, next) => ({ login: () => next({ tag: 'loggedIn', user: 'alice' }) }),
|
|
84
|
-
* loggedIn: (ctx, next) => ({ logout: () => next({ tag: 'idle' }) })
|
|
85
|
-
* });
|
|
86
|
-
*
|
|
87
|
-
* const m = auth({ tag: 'idle' });
|
|
88
|
-
* const next = m.login(); // Transition to loggedIn state
|
|
89
64
|
*/
|
|
90
65
|
export declare function union<C extends Tagged>(): <F extends { [K in TagOf<C>]: (ctx: Extract<C, {
|
|
91
66
|
tag: K;
|
|
92
|
-
}>, next: (c: C) => any) => any; }>(factories: F) => <T extends C>(context: T) => { [K in TagOf<C> & keyof F]:
|
|
67
|
+
}>, next: (c: C) => any) => any; }>(factories: F) => <T extends C>(context: T) => Extract<{ [K in TagOf<C> & keyof F]: Extract<C, {
|
|
93
68
|
tag: K;
|
|
94
|
-
}> &
|
|
69
|
+
}> & ReturnType<F[K]>; }[TagOf<C> & keyof F], {
|
|
70
|
+
tag: T["tag"];
|
|
71
|
+
}>;
|
|
95
72
|
//# sourceMappingURL=minimal.d.ts.map
|