@doeixd/machine 0.0.12 → 0.0.17

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.
Files changed (50) hide show
  1. package/README.md +90 -15
  2. package/dist/cjs/development/core.js +1852 -0
  3. package/dist/cjs/development/core.js.map +7 -0
  4. package/dist/cjs/development/index.js +1348 -1374
  5. package/dist/cjs/development/index.js.map +4 -4
  6. package/dist/cjs/production/core.js +1 -0
  7. package/dist/cjs/production/index.js +5 -5
  8. package/dist/esm/development/core.js +1829 -0
  9. package/dist/esm/development/core.js.map +7 -0
  10. package/dist/esm/development/index.js +1348 -1374
  11. package/dist/esm/development/index.js.map +4 -4
  12. package/dist/esm/production/core.js +1 -0
  13. package/dist/esm/production/index.js +5 -5
  14. package/dist/types/core.d.ts +18 -0
  15. package/dist/types/core.d.ts.map +1 -0
  16. package/dist/types/functional-combinators.d.ts +60 -5
  17. package/dist/types/functional-combinators.d.ts.map +1 -1
  18. package/dist/types/index.d.ts +242 -19
  19. package/dist/types/index.d.ts.map +1 -1
  20. package/dist/types/middleware/composition.d.ts +460 -0
  21. package/dist/types/middleware/composition.d.ts.map +1 -0
  22. package/dist/types/middleware/core.d.ts +196 -0
  23. package/dist/types/middleware/core.d.ts.map +1 -0
  24. package/dist/types/middleware/history.d.ts +54 -0
  25. package/dist/types/middleware/history.d.ts.map +1 -0
  26. package/dist/types/middleware/index.d.ts +10 -0
  27. package/dist/types/middleware/index.d.ts.map +1 -0
  28. package/dist/types/middleware/snapshot.d.ts +63 -0
  29. package/dist/types/middleware/snapshot.d.ts.map +1 -0
  30. package/dist/types/middleware/time-travel.d.ts +81 -0
  31. package/dist/types/middleware/time-travel.d.ts.map +1 -0
  32. package/package.json +19 -6
  33. package/src/core.ts +167 -0
  34. package/src/entry-react.ts +9 -0
  35. package/src/entry-solid.ts +9 -0
  36. package/src/functional-combinators.ts +76 -3
  37. package/src/index.ts +376 -102
  38. package/src/middleware/composition.ts +944 -0
  39. package/src/middleware/core.ts +573 -0
  40. package/src/middleware/history.ts +104 -0
  41. package/src/middleware/index.ts +13 -0
  42. package/src/middleware/snapshot.ts +153 -0
  43. package/src/middleware/time-travel.ts +236 -0
  44. package/src/middleware.ts +735 -1614
  45. package/src/prototype_functional.ts +46 -0
  46. package/src/reproduce_issue.ts +26 -0
  47. package/dist/types/middleware.d.ts +0 -1048
  48. package/dist/types/middleware.d.ts.map +0 -1
  49. package/dist/types/runtime-extract.d.ts +0 -53
  50. package/dist/types/runtime-extract.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ function D(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function ae(e){return function*(){return yield e}()}function se(e){return e}function ce(e,t){return t.reduce((n,r)=>D(r,n),e)}function de(e){return e}function ue(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 le(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*ye(e){return yield e}var Me=Symbol("MachineMeta"),I=Symbol("__machine_runtime_meta__");function b(e,t){let n=e[I]||{},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,I,{value:r,enumerable:!1,writable:!1,configurable:!0})}function xe(e,t){return b(t,{target:e.name||e.toString()}),t}function he(e,t){return b(t,{description:e}),t}function fe(e,t){return b(t,{guards:[e]}),t}function pe(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 ge(e,t){return b(t,{actions:[e]}),t}function A(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 M=c?this.context:this;return t.apply(M,u)}else if(r==="throw"){let M=o||"Guard condition failed";throw new Error(M)}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 S(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 M=c?this.context:this;return t.apply(M,u)}else if(r==="throw"){let M=o||"Guard condition failed";throw new Error(M)}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 Ce(e){return{do(t){let n=A(e,t);return n.else=function(r){return A(e,t,{onFail:r})},n}}}function me(e){return{do(t){let n=S(e,t);return n.else=function(r){return S(e,t,{onFail:r})},n}}}function Te(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 y=c.apply(n.context,d),M=Object.assign({context:y.context},i);return r(M),M}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function we(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.context,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function Le(e,t){return function(r){return we(e,r,t)}}function Ve(e,t){let n=be(t),r=e(n),o=r.next();for(;!o.done;)o=r.next();return o.value}function Ue(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var L=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function qe(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 Ye(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.context,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(y=>delete o[y]),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 tt(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 nt(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 R=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 v(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 j(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new O(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new P(this.config));this.execute()}async execute(){}},j=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)}},v=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)}},O=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)}},P=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 rt(e){return new R(e)}function V(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.context,u);return V(c,t)}}for(let a in o){let s=o[a];i[a]=(...u)=>{let c=s.apply(t.context,u);return V(e,c)}}return{context:n,...i}}var U=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,y=a.context,M=()=>{let l;try{l=u.apply(this,c)}catch(h){if(t.error)try{t.error({transitionName:d,context:y,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: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(l&&typeof l.then=="function")return l.then(f=>{if(x(f),t.after)try{let g=t.after({transitionName:d,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 ${d}:`,g),i==null||i(g,"after",{transitionName:d,prevContext:y,nextContext:f.context,args:c})}return f});if(x(l),t.after)try{let h=t.after({transitionName:d,prevContext:y,nextContext:l.context,args:[...c]});if(h&&typeof h=="object"&&h&&"then"in h)return h.then(()=>l).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:y,nextContext:l.context,args:c}),l})}catch(h){if(!r)throw h;o&&console.error(`Middleware after hook error for ${d}:`,h),i==null||i(h,"after",{transitionName:d,prevContext:y,nextContext:l.context,args:c})}return l};if(t.before)try{let l=t.before({transitionName:d,context:y,args:[...c]});if(l&&typeof l=="object"&&l&&"then"in l)return l.then(x=>x===U?a:M()).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:y,args:c}),M()});if(l===U)return a}catch(l){if(!r)throw l;o&&console.error(`Middleware before hook error for ${d}:`,l),i==null||i(l,"before",{transitionName:d,context:y,args:c})}return M()})}return a}function q(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 Y(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}`,y={transition:a};o&&(y.from=s),y.to=u,i&&(y.args=c),t(d,y)}})}function J(e,t){return C(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function Q(e,t){return C(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function X(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 Z(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 ee(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 y=e[d];typeof y=="function"&&d!=="context"&&(s[d]=async function(...M){let l,x=0;for(;x<n;)try{return await y.apply(this,M)}catch(h){if(l=h,x++,x<n&&r(l,x)){a==null||a(l,x);let g=(typeof o=="function"?o(x):o)*Math.pow(i,x-1);await new Promise(T=>setTimeout(T,g))}else throw l}throw l})}return s}function it(e,t){return n=>C(n,e,t)}function B(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(y){console.error("Failed to serialize history args:",y)}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 k(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyOnChange:i=!1}=t,a=[],s=0,u=C(e,{after:({transitionName:d,prevContext:y,nextContext:M})=>{if(i&&JSON.stringify(y)===JSON.stringify(M))return;let l={id:`snapshot-${s++}`,transitionName:d,before:{...y},after:{...M},timestamp:Date.now()};if(r)try{l.serializedBefore=r.serialize(y),l.serializedAfter=r.serialize(M)}catch(x){console.error("Failed to serialize snapshot:",x)}if(o)try{l.diff=o(y,M)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(l),n&&a.length>n&&a.shift()}});return Object.assign(u,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:d=>{let y=Object.fromEntries(Object.entries(e).filter(([M])=>M!=="context"&&M!=="snapshots"&&M!=="clearSnapshots"&&M!=="restoreSnapshot"&&typeof e[M]=="function"));return Object.assign({context:d},y)}})}function K(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,u=0,c=C(e,{before:({transitionName:M,args:l})=>{let x={id:`entry-${s++}`,transitionName:M,args:[...l],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(l)}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:M,prevContext:l,nextContext:x})=>{let h={id:`snapshot-${u++}`,transitionName:M,before:{...l},after:{...x},timestamp:Date.now()};if(r)try{h.serializedBefore=r.serialize(l),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:M=>{let l=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:M},l)},replayFrom:M=>{var g;if(M<0||M>=i.length)throw new Error(`Invalid replay start index: ${M}`);let l=(g=a[M])==null?void 0:g.before;if(!l)throw new Error(`No snapshot available for index ${M}`);let x=i.slice(M),f=Object.assign({context:l},Object.fromEntries(Object.entries(e).filter(([T])=>T!=="context"&&typeof e[T]=="function")));for(let T of x){let $=f[T.transitionName];$&&(f=$.apply(f.context,T.args))}return f}})}function pt(e,...t){return t.reduce((n,r)=>r(n),e)}function N(e,...t){return t.reduce((n,r)=>r(n),e)}var z=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 z(e)}function _(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Ct(e){return _(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function mt(e,t,n){return _(n,r=>r.context[e]===t)}function Tt(){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 N(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return N(t,...n.map(r=>r.middleware))}}}function bt(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(y){if(u=!1,!t)throw y;s.push({error:y,middlewareIndex:c,middlewareName:d.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,y),r==null||r(y,c,d.name)}}return{machine:a,errors:s,success:u}}}function wt(...e){return t=>N(t,...e)}function Et(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function te(e){return typeof e=="function"&&e.length===1}function Ft(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&te(e.middleware)&&typeof e.when=="function"}function At(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||F(e.prevContext,t)&&F(e.nextContext,t))}function St(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||F(e.context,t))}function Rt(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||F(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 vt(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 F(e,t){return e!==null&&typeof e=="object"}function Ot(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&te(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 Pt(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 G=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>q(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>Y(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>J(r,t)),this}withPermissions(t){return this.middlewares.push(n=>Q(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>X(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>Z(r,t)),this}withRetry(t){return this.middlewares.push(n=>ee(n,t)),this}withHistory(t){return this.middlewares.push(n=>B(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>k(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>K(n,t)),this}withDebugging(){return this.middlewares.push(t=>Fe(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 Ee(e){return new G(e)}function Bt(e={}){return{create:t=>{let n=Ee(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 Fe(e){return K(k(B(e)))}function Ae(e,t){return e instanceof t}function Se(e,...t){return{type:e,args:t}}function Re(e,t){return E(e,n=>({...n,...t}))}async function je(e,...t){let n=e;for(let r of t)n=await r(n);return n}function ve(e,t){return t?console.log(t,e.context):console.log(e.context),e}function Oe(e,t){return function(...n){let r=t(this.context,...n);return p(r,e())}}function Pe(e,t,...n){return e.apply(t,n)}function ne(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t.context,o);return i&&typeof i=="object"&&"context"in i?ne(i):i}:r}})}var W=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.context,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function Be(){return function(t){return function(...n){let r=t(this.context,...n);return p(r,this)}}}function re(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return p(a,this)},o=H(e,{[t]:r});return re(o)}}}function oe(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 ke(e,t){return t!==void 0?p(e,t):oe(e)}function p(e,t){if(typeof t=="function"){let o;o=t(s=>{let u=p(s,o),c=Object.fromEntries(Object.entries(o).map(([d,y])=>[d,y.bind(s)]));return Object.assign(u,c)});let a=Object.fromEntries(Object.entries(o).map(([s,u])=>[s,u.bind(e)]));return Object.assign({context:e},a)}let n="context"in t?Object.fromEntries(Object.entries(t).filter(([o])=>o!=="context")):t;return Object.assign({context:e},n)}function ie(e,t){if(typeof t=="function"){let o;o=t(s=>{let u=ie(s,o),c=Object.fromEntries(Object.entries(o).map(([d,y])=>[d,y.bind(s)]));return Object.assign(u,c)});let a=Object.fromEntries(Object.entries(o).map(([s,u])=>[s,u.bind(e)]));return Object.assign({context:e},a)}let n="context"in t?Object.fromEntries(Object.entries(t).filter(([o])=>o!=="context")):t;return Object.assign({context:e},n)}function Ke(){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){let{context:n,...r}=e,o=typeof t=="function"?t(n):t;return p(o,r)}function Ne(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function H(e,t){let{context:n,...r}=e,o={...r,...t};return p(n,o)}function ze(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 Ge(e){let{context:t,...n}=e;return r=>p(r,n)}function _e(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 We(e,t,n){return e.context[t]===n}function He(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.context,[...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)}}}var m=class{constructor(t){this.context=t}};function $e(e,t){let{context:n,...r}=e;return p(t(n),r)}export{W as BoundMachine,U as CANCEL,Me as META_KEY,m as MachineBase,G as MiddlewareBuilder,L as MultiMachineBase,ge as action,ne as bindTransitions,Et as branch,Pe as call,gt as chain,wt as combine,ze as combineFactories,pt as compose,N as composeTyped,ie as createAsyncMachine,it as createCustomMiddleware,we as createEnsemble,Le as createEnsembleFactory,Se as createEvent,rt as createFetchMachine,de as createFlow,oe as createFunctionalMachine,p as createMachine,Ge as createMachineBuilder,Ke as createMachineFactory,C as createMiddleware,Bt as createMiddlewareFactory,Tt as createMiddlewareRegistry,qe as createMultiMachine,Ye as createMutableMachine,V as createParallelMachine,bt as createPipeline,be as createRunner,Oe as createTransition,re as createTransitionExtender,Be as createTransitionFactory,tt as delegateToChild,he as describe,H as extendTransitions,A as guard,S as guardAsync,fe as guarded,We as hasState,Ct as inDevelopment,pe as invoke,Ft as isConditionalMiddleware,St as isMiddlewareContext,Rt as isMiddlewareError,te as isMiddlewareFn,jt as isMiddlewareHooks,vt as isMiddlewareOptions,At as isMiddlewareResult,Ot as isNamedMiddleware,Pt as isPipelineConfig,Ae as isState,ve as logState,_e as matchMachine,Re as mergeContext,Te as metadata,Ee as middlewareBuilder,$e as next,Ne as overrideTransitions,je as pipeTransitions,D as run,le as runAsync,He as runMachine,ce as runSequence,ue as runWithDebug,Ue as runWithEnsemble,Ve as runWithRunner,E as setContext,ke as state,ae as step,ye as stepAsync,nt as toggle,xe as transitionTo,_ as when,mt as whenContext,Ce as whenGuard,me as whenGuardAsync,Y as withAnalytics,Fe as withDebugging,X as withErrorReporting,B as withHistory,q as withLogging,Z as withPerformanceMonitoring,Q as withPermissions,ee as withRetry,k as withSnapshot,K as withTimeTravel,J as withValidation,se as yieldMachine};
@@ -1,5 +1,5 @@
1
- var Q=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(t,n)=>(typeof require!="undefined"?require:t)[n]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});function Z(e,t){let n=e(t),r=t;for(;;){let{value:o,done:i}=n.next(r);if(i)return o;r=o}}function he(e){return function*(){return yield e}()}function pe(e){return e}function ge(e,t){return t.reduce((n,r)=>Z(r,n),e)}function Ce(e){return e}function me(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 we(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*Te(e){return yield e}var be=Symbol("MachineMeta"),O=Symbol("__machine_runtime_meta__");function S(e,t){let n=e[O]||{},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,O,{value:r,enumerable:!1,writable:!1,configurable:!0})}function Ee(e,t){return S(t,{target:e.name||e.toString()}),t}function Se(e,t){return S(t,{description:e}),t}function Fe(e,t){return S(t,{guards:[e]}),t}function Pe(e,t){return S(t,{invoke:{src:e.src,onDone:e.onDone.name||e.onDone.toString(),onError:e.onError.name||e.onError.toString(),description:e.description}}),t}function Re(e,t){return S(t,{actions:[e]}),t}function _(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=function(...c){let l=typeof this=="object"&&"context"in this,u=l?this.context:this;if(e(u,...c)){let y=l?this.context:this;return t.apply(y,c)}else if(r==="throw"){let y=o||"Guard condition failed";throw new Error(y)}else if(r==="ignore"){if(l)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(l)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(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}),S(s,{description:i||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:i||"Synchronous condition check"}]}),s}function K(e,t,n={}){let{onFail:r="throw",errorMessage:o,description:i}=n,a={...n,onFail:r,errorMessage:o,description:i},s=async function(...c){let l=typeof this=="object"&&"context"in this,u=l?this.context:this;if(await Promise.resolve(e(u,...c))){let y=l?this.context:this;return t.apply(y,c)}else if(r==="throw"){let y=o||"Guard condition failed";throw new Error(y)}else if(r==="ignore"){if(l)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(l)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(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}),S(s,{description:i||"Runtime guarded transition",guards:[{name:"runtime_guard",description:i||"Runtime condition check"}]}),s}function Ae(e){return{do(t){let n=_(e,t);return n.else=function(r){return _(e,t,{onFail:r})},n}}}function ve(e){return{do(t){let n=K(e,t);return n.else=function(r){return K(e,t,{onFail:r})},n}}}function je(e,t){return t}import{Project as ee,Node as g}from"ts-morph";function te(e){return g.isIdentifier(e)?e.getText():g.isTypeOfExpression(e)?e.getExpression().getText():"unknown"}function A(e){if(!g.isObjectLiteralExpression(e))return{};let t={};for(let n of e.getProperties())if(g.isPropertyAssignment(n)){let r=n.getName(),o=n.getInitializer();o&&(g.isStringLiteral(o)||g.isNumericLiteral(o)?t[r]=o.getLiteralValue():o.getText()==="true"||o.getText()==="false"?t[r]=o.getText()==="true":g.isIdentifier(o)?t[r]=o.getText():g.isObjectLiteralExpression(o)?t[r]=A(o):g.isArrayLiteralExpression(o)&&(t[r]=o.getElements().map(i=>g.isObjectLiteralExpression(i)?A(i):i.getText())))}return t}function Oe(e){if(!g.isObjectLiteralExpression(e))return{};let t={};for(let n of e.getProperties())if(g.isPropertyAssignment(n)){let r=n.getName(),o=n.getInitializer();if(!o)continue;r==="onDone"||r==="onError"?t[r]=te(o):g.isStringLiteral(o)?t[r]=o.getLiteralValue():g.isIdentifier(o)&&(t[r]=o.getText())}return t}function R(e,t=!1){if(!g.isCallExpression(e))return null;let n=e.getExpression(),r=g.isIdentifier(n)?n.getText():null;if(!r)return null;let o={},i=e.getArguments();switch(r){case"transitionTo":i[0]&&(o.target=te(i[0]));break;case"describe":if(i[0]&&g.isStringLiteral(i[0])&&(o.description=i[0].getLiteralValue()),i[1]&&g.isCallExpression(i[1])){let a=R(i[1],t);a&&Object.assign(o,a)}break;case"guarded":if(i[0]){let a=A(i[0]);Object.keys(a).length>0&&(o.guards=[a])}if(i[1]&&g.isCallExpression(i[1])){let a=R(i[1],t);a&&Object.assign(o,a)}break;case"invoke":if(i[0]){let a=Oe(i[0]);Object.keys(a).length>0&&(o.invoke=a)}break;case"action":if(i[0]){let a=A(i[0]);Object.keys(a).length>0&&(o.actions=[a])}if(i[1]&&g.isCallExpression(i[1])){let a=R(i[1],t);a&&Object.assign(o,a)}break;case"guard":if(i[2]){let a=A(i[2]);a.description&&(o.description=a.description)}if(o.guards=[{name:"runtime_guard",description:o.description||"Synchronous condition check"}],i[1]&&g.isCallExpression(i[1])){let a=R(i[1],t);a&&Object.assign(o,a)}break;case"guardAsync":if(i[2]){let a=A(i[2]);a.description&&(o.description=a.description)}if(o.guards=[{name:"runtime_guard_async",description:o.description||"Asynchronous condition check"}],i[1]&&g.isCallExpression(i[1])){let a=R(i[1],t);a&&Object.assign(o,a)}break;default:return null}return Object.keys(o).length>0?o:null}function ke(e,t=!1){if(!g.isPropertyDeclaration(e))return t&&console.error(" ⚠️ Not a property declaration"),null;let n=e.getInitializer();if(!n)return t&&console.error(" ⚠️ No initializer"),null;if(!g.isCallExpression(n))return t&&console.error(" ⚠️ Initializer is not a call expression"),null;let r=R(n,t);return r&&t&&console.error(" ✅ Extracted metadata:",JSON.stringify(r,null,2)),r}function D(e,t=!1){let n={on:{}},r=e.getDeclarations()[0];if(!r||!g.isClassDeclaration(r))return t&&console.error(`⚠️ Warning: Could not get class declaration for ${e.getName()}`),n;let o=e.getName();t&&console.error(` Analyzing state: ${o}`);for(let i of r.getInstanceMembers()){let a=i.getName();t&&console.error(` Checking member: ${a}`);let s=ke(i,t);if(!s)continue;t&&console.error(` Found transition: ${a}`);let{invoke:c,actions:l,guards:u,...M}=s;if(c&&(n.invoke||(n.invoke=[]),n.invoke.push({src:c.src,onDone:{target:c.onDone},onError:{target:c.onError},description:c.description}),t&&console.error(` → Invoke: ${c.src}`)),M.target){let y={target:M.target};M.description&&(y.description=M.description),u&&(y.cond=u.map(x=>x.name).join(" && "),t&&console.error(` → Guard: ${y.cond}`)),l&&l.length>0&&(y.actions=l.map(x=>x.name),t&&console.error(` → Actions: ${y.actions.join(", ")}`)),n.on[a]=y,t&&console.error(` → Target: ${M.target}`)}}return n}function Ne(e,t,n,r,o=!1){let i=D(t,o);if(r){o&&console.error(` 👪 Analyzing children for state: ${e}`),i.initial=r.initialState,i.states={};for(let a of r.classes){let s=n.getClass(a);if(s){let c=s.getSymbolOrThrow();i.states[a]=D(c,o)}else console.warn(`⚠️ Warning: Child class '${a}' not found.`)}}return i}function W(e,t,n=!1){n&&(console.error(`
2
- 🔍 Analyzing machine: ${e.id}`),console.error(` Source: ${e.input}`));let r=t.getSourceFile(e.input);if(!r)throw new Error(`Source file not found: ${e.input}`);if(e.parallel){n&&console.error(" ⏹️ Parallel machine detected. Analyzing regions.");let i={id:e.id,type:"parallel",states:{}};e.description&&(i.description=e.description);for(let a of e.parallel.regions){n&&console.error(` 📍 Analyzing region: ${a.name}`);let s={};for(let c of a.classes){let l=r.getClass(c);if(l){let u=l.getSymbolOrThrow();s[c]=D(u,n)}else console.warn(`⚠️ Warning: Class '${c}' not found for region '${a.name}'.`)}i.states[a.name]={initial:a.initialState,states:s}}return n&&console.error(` ✅ Extracted ${e.parallel.regions.length} parallel regions`),i}if(!e.initialState||!e.classes)throw new Error(`Machine config for '${e.id}' must have either 'parallel' or 'initialState'/'classes'.`);let o={id:e.id,initial:e.initialState,states:{}};e.description&&(o.description=e.description);for(let i of e.classes){let a=r.getClass(i);if(!a){console.warn(`⚠️ Warning: Class '${i}' not found in '${e.input}'. Skipping.`);continue}let s=a.getSymbolOrThrow(),c=i===e.initialState&&e.children,l=Ne(i,s,r,c?e.children:void 0,n);o.states[i]=l}return n&&console.error(` ✅ Extracted ${e.classes.length} states`),o}function ze(e){var o;let t=(o=e.verbose)!=null?o:!1;t&&(console.error(`
3
- 📊 Starting statechart extraction`),console.error(` Machines to extract: ${e.machines.length}`));let n=new ee;n.addSourceFilesAtPaths("src/**/*.ts"),n.addSourceFilesAtPaths("examples/**/*.ts");let r=[];for(let i of e.machines)try{let a=W(i,n,t);r.push(a)}catch(a){console.error(`❌ Error extracting machine '${i.id}':`,a),t||console.error(" Run with --verbose for more details")}return t&&console.error(`
4
- ✅ Extraction complete: ${r.length}/${e.machines.length} machines extracted`),r}function ne(){let e={input:"examples/authMachine.ts",classes:["LoggedOutMachine","LoggingInMachine","LoggedInMachine","SessionExpiredMachine","ErrorMachine"],id:"auth",initialState:"LoggedOutMachine",description:"Authentication state machine"};console.error("🔍 Using legacy generateChart function"),console.error(`⚠️ Consider using extractMachines() with a config file instead
5
- `);let t=new ee;t.addSourceFilesAtPaths("src/**/*.ts"),t.addSourceFilesAtPaths("examples/**/*.ts");try{let n=W(e,t,!0);console.log(JSON.stringify(n,null,2))}catch(n){console.error("❌ Error:",n),process.exit(1)}}var Ct={hierarchical:{input:"examples/dashboardMachine.ts",id:"dashboard",classes:["DashboardMachine","LoggedOutMachine"],initialState:"DashboardMachine",children:{contextProperty:"child",initialState:"ViewingChildMachine",classes:["ViewingChildMachine","EditingChildMachine"]}},parallel:{input:"examples/editorMachine.ts",id:"editor",parallel:{regions:[{name:"fontWeight",initialState:"NormalWeight",classes:["NormalWeight","BoldWeight"]},{name:"textDecoration",initialState:"NoDecoration",classes:["NoDecoration","UnderlineState"]}]}}};Q.main===module&&ne();function re(e){return typeof e!="function"?null:e[O]||null}function G(e){let t={on:{}},n=[];for(let r in e){let o=e[r];if(typeof o!="function")continue;let i=re(o);if(i){if(i.invoke&&n.push({src:i.invoke.src,onDone:{target:i.invoke.onDone},onError:{target:i.invoke.onError},description:i.invoke.description}),i.target){let a={target:i.target};i.description&&(a.description=i.description),i.guards&&i.guards.length>0&&(a.cond=i.guards.map(s=>s.name).join(" && ")),i.actions&&i.actions.length>0&&(a.actions=i.actions.map(s=>s.name)),t.on[r]=a}else if(i.guards&&i.guards.length>0){let a={target:"GuardedTransition",cond:i.guards.map(s=>s.name).join(" && ")};i.description&&(a.description=i.description),t.on[r]=a}}}return n.length>0&&(t.invoke=n),t}function Be(e,t){let n={id:t.id,initial:t.initial,states:{}};t.description&&(n.description=t.description);for(let[r,o]of Object.entries(e))n.states[r]=G(o);return n}function $e(e,t){let n=t.stateName||e.constructor.name||"State";return{id:t.id,initial:n,states:{[n]:G(e)}}}function _e(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:o,...i}=e,a=new Proxy({},{get(s,c){let l=n[c];if(typeof l=="function")return(...u)=>{let M=l.apply(n.context,u),y=Object.assign({context:M.context},i);return r(y),y}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function Ke(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(),c=s[a];if(typeof c!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...l)=>c.apply(s.context,l)}});return{get context(){return e.getContext()},get state(){return r()},actions:o}}function Et(e,t){return function(r){return Ke(e,r,t)}}function St(e,t){let n=_e(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 oe=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function Pt(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 Rt(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(),c=s[i];if(typeof c=="function")return(...l)=>{let u=c.apply(s.context,l);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(M=>delete o[M]),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 Nt(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return k(this,{...this.context,child:r})}return this}}function zt(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.`),k(this,{...this.context,[e]:!this.context[e]})}}var H=class extends E{constructor(n){super({status:"idle"});this.config=n;this.fetch=n=>new F(this.config,n!=null?n:this.config.initialParams,1)}},F=class extends E{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 L(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 I(this.config,this.params,n,this.context.attempts):((a=(i=this.config).onError)==null||a.call(i,n),new V(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new U(this.config));this.execute()}async execute(){}},I=class extends E{constructor(n,r,o,i){super({status:"retrying",error:o,attempts:i});this.config=n;this.params=r;this.retry=n=>new F(this.config,n!=null?n:this.params,this.context.attempts+1)}},L=class extends E{constructor(n,r){super(r);this.config=n;this.refetch=n=>new F(this.config,n!=null?n:this.config.initialParams,1)}},V=class extends E{constructor(n,r){super(r);this.config=n;this.retry=n=>new F(this.config,n!=null?n:this.config.initialParams,1)}},U=class extends E{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new F(this.config,n!=null?n:this.config.initialParams,1)}};function Bt(e){return new H(e)}function ie(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]=(...c)=>{let l=s.apply(e.context,c);return ie(l,t)}}for(let a in o){let s=o[a];i[a]=(...c)=>{let l=s.apply(t.context,c);return ie(e,l)}}return{context:n,...i}}var ae=Symbol("CANCEL");function T(e,t,n={}){let{mode:r="auto",exclude:o=["context"]}=n,i={};for(let a in e){if(!Object.prototype.hasOwnProperty.call(e,a))continue;let s=e[a];if(a==="context"){i.context=s;continue}if(o.includes(a)){i[a]=s;continue}if(typeof s!="function"||a.startsWith("_")){i[a]=s;continue}i[a]=De(a,s,e,t,r)}return i}function De(e,t,n,r,o){return function(...a){let s=n.context,c={transitionName:e,context:s,args:a},l=()=>{try{if(r.before){let x=r.before(c);if(x===ae)return n;if(x instanceof Promise)throw new Error(`Middleware mode is 'sync' but before hook returned Promise for transition: ${e}`)}let y=t.call(this,...a);if(y instanceof Promise)return u(y,s);if(r.after){let x={transitionName:e,prevContext:s,nextContext:y.context,args:a};if(r.after(x)instanceof Promise)throw new Error(`Middleware mode is 'sync' but after hook returned Promise for transition: ${e}`)}return y}catch(y){if(r.error){let x={transitionName:e,context:s,args:a,error:y},d=r.error(x);if(d instanceof Promise)throw d.catch(()=>{}),y;if(d&&typeof d=="object"&&"context"in d)return d}throw y}},u=async(y,x)=>{try{let d=await y;if(r.after){let p={transitionName:e,prevContext:x,nextContext:d.context,args:a};await r.after(p)}return d}catch(d){if(r.error){let p={transitionName:e,context:x,args:a,error:d},f=await r.error(p);if(f&&typeof f=="object"&&"context"in f)return f}throw d}},M=async()=>{try{if(r.before&&await r.before(c)===ae)return n;let y=await t.call(this,...a);if(r.after){let x={transitionName:e,prevContext:s,nextContext:y.context,args:a};await r.after(x)}return y}catch(y){if(r.error){let x={transitionName:e,context:s,args:a,error:y},d=await r.error(x);if(d&&typeof d=="object"&&"context"in d)return d}throw y}};return o==="async"?M():l()}}function We(e,t={}){let{logger:n=console.log,includeContext:r=!0,includeArgs:o=!0}=t;return T(e,{before:({transitionName:i,args:a})=>{let s=o&&a.length>0?` ${JSON.stringify(a)}`:"";n(`→ ${i}${s}`)},after:({transitionName:i,nextContext:a})=>{let s=r?` ${JSON.stringify(a)}`:"";n(`✓ ${i}${s}`)}})}function Ge(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:o=!1,includeArgs:i=!0}=n;return T(e,{after:async({transitionName:a,prevContext:s,nextContext:c,args:l})=>{let u={transition:a,to:c};o&&(u.from=s),i&&l.length>0&&(u.args=l),await t(`${r}.${a}`,u)}},{mode:"async"})}function He(e,t,n){return T(e,{before:r=>{let o=t(r);if(o instanceof Promise)return o.then(i=>{if(i===!1)throw new Error(`Validation failed for transition: ${r.transitionName}`)});if(o===!1)throw new Error(`Validation failed for transition: ${r.transitionName}`)}},{mode:"auto",...n})}function Ie(e,t,n){return T(e,{before:r=>{let o=t(r);if(o instanceof Promise)return o.then(i=>{if(!i)throw new Error(`Unauthorized transition: ${r.transitionName}`)});if(!o)throw new Error(`Unauthorized transition: ${r.transitionName}`)}},{mode:"auto",...n})}function Le(e,t,n={}){let{includeContext:r=!0,includeArgs:o=!0,mode:i}=n;return T(e,{error:async({transitionName:a,context:s,args:c,error:l})=>{let u={transition:a};r&&(u.context=s),o&&c.length>0&&(u.args=c),await Promise.resolve(t(l,u))}},{mode:i})}function Ve(e,t){let n=new Map;return T(e,{before:({transitionName:r})=>{n.set(r,performance.now())},after:({transitionName:r,nextContext:o})=>{let i=n.get(r);if(i){let a=performance.now()-i;n.delete(r);let s=t({transitionName:r,duration:a,context:o});if(s instanceof Promise)return s}}},{mode:"auto"})}function Ue(e,t={}){let{maxRetries:n=3,delay:r=1e3,backoffMultiplier:o=1,shouldRetry:i=()=>!0,onRetry:a}=t,s={};for(let c in e){if(!Object.prototype.hasOwnProperty.call(e,c))continue;let l=e[c];if(c==="context"||typeof l!="function"){s[c]=l;continue}s[c]=async function(...M){let y;for(let x=0;x<=n;x++)try{return await l.call(this,...M)}catch(d){if(y=d,x===n||!i(y))break;a==null||a(x+1,y);let p=r*Math.pow(o,x);await new Promise(f=>setTimeout(f,p))}throw y}}return s}function se(e,t={}){let{maxSize:n,serializer:r,filter:o,onEntry:i,_isRewrap:a=!1}=t,s=[],c=0,l=T(e,{before:({transitionName:u,args:M})=>{if(o&&!o(u,M))return;let y={id:`entry-${c++}`,transitionName:u,args:[...M],timestamp:Date.now()};if(r)try{y.serializedArgs=r.serialize(M)}catch(x){console.error("Failed to serialize history args:",x)}s.push(y),n&&s.length>n&&s.shift(),i==null||i(y)}},{exclude:["context","history","clearHistory"]});if(!a)for(let u in l){if(!Object.prototype.hasOwnProperty.call(l,u))continue;let M=l[u];if(typeof M=="function"&&!u.startsWith("_")&&u!=="context"&&!["history","clearHistory"].includes(u)){let y=M;l[u]=function(...x){let d=y.apply(this,x);if(d&&typeof d=="object"&&"context"in d&&!("history"in d)){let p=T(d,{before:({transitionName:f,args:C})=>{if(o&&!o(f,C))return;let h={id:`entry-${c++}`,transitionName:f,args:[...C],timestamp:Date.now()};if(r)try{h.serializedArgs=r.serialize(C)}catch(b){console.error("Failed to serialize history args:",b)}s.push(h),n&&s.length>n&&s.shift(),i==null||i(h)}},{exclude:["context","history","clearHistory"]});return Object.assign(p,{history:s,clearHistory:()=>{s.length=0,c=0}})}return d}}}return Object.assign(l,{history:s,clearHistory:()=>{s.length=0,c=0}})}function ce(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:o,onlyIfChanged:i=!1,filter:a,onSnapshot:s,_extraExclusions:c=[],_isRewrap:l=!1}=t,u=[],M=0,y=T(e,{after:({transitionName:d,prevContext:p,nextContext:f})=>{if(a&&!a(d)||i&&!(JSON.stringify(p)!==JSON.stringify(f)))return;let C={id:`snapshot-${M++}`,transitionName:d,before:{...p},after:{...f},timestamp:Date.now()};if(r)try{C.serializedBefore=r.serialize(p),C.serializedAfter=r.serialize(f)}catch(h){console.error("Failed to serialize snapshot:",h)}if(o)try{C.diff=o(p,f)}catch(h){console.error("Failed to capture snapshot:",h)}u.push(C),n&&u.length>n&&u.shift(),s==null||s(C)}},{exclude:["context","snapshots","clearSnapshots","restoreSnapshot",...c]}),x=d=>{let{context:p,...f}=e;return{context:d,...f}};if(!l)for(let d in y){if(!Object.prototype.hasOwnProperty.call(y,d))continue;let p=y[d];if(typeof p=="function"&&!d.startsWith("_")&&d!=="context"&&!["snapshots","clearSnapshots","restoreSnapshot","history","clearHistory"].includes(d)){let f=p;y[d]=function(...C){let h=f.apply(this,C);if(h&&typeof h=="object"&&"context"in h&&!("snapshots"in h)){for(let m in h){if(!Object.prototype.hasOwnProperty.call(h,m))continue;let v=h[m];if(typeof v=="function"&&!m.startsWith("_")&&m!=="context"&&!["snapshots","clearSnapshots","restoreSnapshot","history","clearHistory"].includes(m)){let Me=v;h[m]=function(...xe){let N=h.context,j=Me.apply(this,xe);if(j&&typeof j=="object"&&"context"in j){let z=j.context;if(!(a&&!a(m))){let X=!0;if(i&&(X=JSON.stringify(N)!==JSON.stringify(z)),X){let P={id:`snapshot-${M++}`,transitionName:m,before:{...N},after:{...z},timestamp:Date.now()};if(r)try{P.serializedBefore=r.serialize(N),P.serializedAfter=r.serialize(z)}catch($){console.error("Failed to serialize snapshot:",$)}if(o)try{P.diff=o(N,z)}catch($){console.error("Failed to capture snapshot:",$)}u.push(P),n&&u.length>n&&u.shift(),s==null||s(P)}}}return j}}}let b=Object.assign(h,{snapshots:u,clearSnapshots:()=>{u.length=0,M=0},restoreSnapshot:x});return e.history&&(b.history=e.history,b.clearHistory=e.clearHistory),b}return h}}}return Object.assign(y,{snapshots:u,clearSnapshots:()=>{u.length=0,M=0},restoreSnapshot:x})}function le(e,t={}){let{maxSize:n,serializer:r,onRecord:o}=t,i=[],a=[],s=0,c=0,l=(d,p)=>{let f={id:`entry-${s++}`,transitionName:d,args:[...p],timestamp:Date.now()};if(r)try{f.serializedArgs=r.serialize(p)}catch(C){console.error("Failed to serialize history args:",C)}i.push(f),n&&i.length>n&&i.shift(),o==null||o("history",f)},u=(d,p,f)=>{let C={id:`snapshot-${c++}`,transitionName:d,before:{...p},after:{...f},timestamp:Date.now()};if(r)try{C.serializedBefore=r.serialize(p),C.serializedAfter=r.serialize(f)}catch(h){console.error("Failed to serialize snapshot:",h)}a.push(C),n&&a.length>n&&a.shift(),o==null||o("snapshot",C)},M=d=>{let{context:p,...f}=e;return Object.assign({context:d},d,f)},y=(d=0)=>{if(d<0||d>=a.length)throw new Error(`Invalid snapshot index: ${d}`);let p=M(a[d].before),f=a[d],C=i.findIndex(h=>h.transitionName===f.transitionName&&h.timestamp===f.timestamp);if(C===-1)throw new Error("Could not find matching history entry for snapshot");for(let h=C;h<i.length;h++){let b=i[h],m=p[b.transitionName];if(typeof m=="function")try{p=m.apply(p.context,b.args)}catch(v){throw console.error(`Replay failed at step ${h}:`,v),v}}return p},x=d=>{let p={...d};for(let f in d){if(!Object.prototype.hasOwnProperty.call(d,f))continue;let C=d[f];typeof C=="function"&&!f.startsWith("_")&&f!=="context"&&!["history","snapshots","clearHistory","clearSnapshots","clearTimeTravel","restoreSnapshot","replayFrom"].includes(f)&&(p[f]=function(...h){l(f,h);let b=p.context,m=C.apply(this,h);return m&&typeof m=="object"&&"context"in m&&u(f,b,m.context),m&&typeof m=="object"&&"context"in m?x(m):m})}return Object.assign(p,{history:i,snapshots:a,clearHistory:()=>{i.length=0,s=0},clearSnapshots:()=>{a.length=0,c=0},clearTimeTravel:()=>{i.length=0,a.length=0,s=0,c=0},restoreSnapshot:M,replayFrom:y})};return x(e)}function Je(e,...t){return t.reduce((n,r)=>r(n),e)}function qe(e,t){return n=>T(n,e,t)}function B(e,...t){return t.reduce((n,r)=>r(n),e)}function Ye(e){return new J(e)}var J=class e{constructor(t){this.machine=t}with(t){let n=t(this.machine);return new e(n)}build(){return this.machine}};function Xe(e){return le(ce(se(e)))}function Qe(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(o,...i)=>{let a=o,s=[];for(let c=0;c<i.length;c++){let l=i[c];try{if("middleware"in l&&"when"in l){if(!l.when(a))continue;a=l.middleware(a)}else a=l(a)}catch(u){let M=u instanceof Error?u:new Error(String(u));if(s.push({error:M,middlewareIndex:c}),n&&console.error(`Middleware pipeline error at index ${c}:`,M),r==null||r(M,`middleware-${c}`),!t)break}}return{machine:a,errors:s,success:s.length===0}}}function Ze(){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 B(t,...r.map(o=>o.middleware))},applyAll(t){let n=this.list();return B(t,...n.map(r=>r.middleware))}}}function q(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function et(e){return q(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function tt(e,t,n){return q(n,r=>r.context[e]===t)}function nt(...e){return t=>B(t,...e)}function rt(e,t){return n=>{for(let[r,o]of e)if(r(n))return o(n);return t?t(n):n}}function de(e){return typeof e=="function"&&e.length===1}function ot(e){return e!==null&&"middleware"in e&&"when"in e&&de(e.middleware)&&typeof e.when=="function"}function it(e,t){return e instanceof t}function at(e,...t){return{type:e,args:t}}function st(e,t){return k(e,n=>({...n,...t}))}async function ct(e,...t){let n=e;for(let r of t)n=await r(n);return n}function lt(e,t){return t?console.log(t,e.context):console.log(e.context),e}function dt(e,t){return function(...n){let r=t(this.context,...n);return w(r,e())}}function ut(e,t,...n){return e.apply(t,n)}function ue(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...o){let i=r.apply(t.context,o);return i&&typeof i=="object"&&"context"in i?ue(i):i}:r}})}var Y=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.context,i);return a&&typeof a=="object"&&"context"in a?new e(a):a}:o}})}};function yt(){return function(t){return function(...n){let r=t(this.context,...n);return w(r,this)}}}function ye(e){return{machine:e,addTransition:function(t,n){let r=function(...i){let a=n(this.context,...i);return w(a,this)},o=fe(e,{[t]:r});return ye(o)}}}function ft(e){return function(n){let r={},o=Object.fromEntries(Object.entries(n).map(([i,a])=>[i,function(...s){let c=a(this.context,...s);return w(c,r)}]));return Object.assign(r,o),w(e,r)}}function w(e,t){let n="context"in t?Object.fromEntries(Object.entries(t).filter(([o])=>o!=="context")):t;return Object.assign({context:e},n)}function Xt(e,t){return Object.assign({context:e},t)}function Qt(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...o){let i=r(this,...o);return w(i,t)}]));return n=>w(n,t)}}function k(e,t){let{context:n,...r}=e,o=typeof t=="function"?t(n):t;return w(o,r)}function Zt(e,t){let{context:n,...r}=e,o={...r,...t};return w(n,o)}function fe(e,t){let{context:n,...r}=e,o={...r,...t};return w(n,o)}function en(e,t){return(...n)=>{let r=e(...n),o=t(),i={...r.context,...o.context},{context:a,...s}=r,{context:c,...l}=o,u={...s,...l};return w(i,u)}}function tn(e){let{context:t,...n}=e;return r=>w(r,n)}function nn(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 rn(e,t,n){return e.context[t]===n}function on(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 l=await a.apply(n.context,[...i.args,{signal:s.signal}]);return s.signal.aborted||(n=l,t==null||t(n)),n}finally{r===s&&(r=null)}}return{get state(){return n.context},dispatch:o,stop:()=>{r&&(r.abort(),r=null)}}}var E=class{constructor(t){this.context=t}};function an(e,t){let{context:n,...r}=e;return w(t(n),r)}export{Ct as ADVANCED_CONFIG_EXAMPLES,Y as BoundMachine,be as META_KEY,E as MachineBase,oe as MultiMachineBase,O as RUNTIME_META,Re as action,ue as bindTransitions,rt as branch,ut as call,Ye as chain,nt as combine,en as combineFactories,Je as compose,B as composeTyped,Xt as createAsyncMachine,qe as createCustomMiddleware,Ke as createEnsemble,Et as createEnsembleFactory,at as createEvent,Bt as createFetchMachine,Ce as createFlow,ft as createFunctionalMachine,w as createMachine,tn as createMachineBuilder,Qt as createMachineFactory,T as createMiddleware,Ze as createMiddlewareRegistry,Pt as createMultiMachine,Rt as createMutableMachine,ie as createParallelMachine,Qe as createPipeline,_e as createRunner,dt as createTransition,ye as createTransitionExtender,yt as createTransitionFactory,Nt as delegateToChild,Se as describe,fe as extendTransitions,$e as extractFromInstance,re as extractFunctionMetadata,W as extractMachine,ze as extractMachines,G as extractStateNode,ne as generateChart,Be as generateStatechart,_ as guard,K as guardAsync,Fe as guarded,rn as hasState,et as inDevelopment,Pe as invoke,ot as isConditionalMiddleware,de as isMiddlewareFn,it as isState,lt as logState,nn as matchMachine,st as mergeContext,je as metadata,an as next,Zt as overrideTransitions,ct as pipeTransitions,Z as run,we as runAsync,on as runMachine,ge as runSequence,me as runWithDebug,Ft as runWithEnsemble,St as runWithRunner,k as setContext,he as step,Te as stepAsync,zt as toggle,Ee as transitionTo,q as when,tt as whenContext,Ae as whenGuard,ve as whenGuardAsync,Ge as withAnalytics,Xe as withDebugging,Le as withErrorReporting,se as withHistory,We as withLogging,Ve as withPerformanceMonitoring,Ie as withPermissions,Ue as withRetry,ce as withSnapshot,le as withTimeTravel,He as withValidation,pe as yieldMachine};
1
+ var V=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(t,n)=>(typeof require!="undefined"?require:t)[n]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});function U(e,t){let n=e(t),r=t;for(;;){let{value:i,done:o}=n.next(r);if(o)return i;r=i}}function Me(e){return function*(){return yield e}()}function xe(e){return e}function fe(e,t){return t.reduce((n,r)=>U(r,n),e)}function he(e){return e}function pe(e,t,n=(r,i)=>{console.log(`Step ${r}:`,i.context)}){let r=e(t),i=t,o=0;for(n(o,i);;){let{value:a,done:s}=r.next(i);if(s)return console.log("Final:",a),a;i=a,o++,n(o,i)}}async function ge(e,t){let n=e(t),r=t;for(;;){let{value:i,done:o}=await n.next(r);if(o)return i;r=i}}async function*Ce(e){return yield e}var me=Symbol("MachineMeta"),q=Symbol("__machine_runtime_meta__");function w(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 Te(e,t){return w(t,{target:e.name||e.toString()}),t}function be(e,t){return w(t,{description:e}),t}function we(e,t){return w(t,{guards:[e]}),t}function Ee(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 Se(e,t){return w(t,{actions:[e]}),t}function R(e,t,n={}){let{onFail:r="throw",errorMessage:i,description:o}=n,a={...n,onFail:r,errorMessage:i,description:o},s=function(...l){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(e(d,...l)){let M=c?this.context:this;return t.apply(M,l)}else if(r==="throw"){let M=i||"Guard condition failed";throw new Error(M)}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,l);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:o||"Synchronous guarded transition",guards:[{name:"runtime_guard",description:o||"Synchronous condition check"}]}),s}function O(e,t,n={}){let{onFail:r="throw",errorMessage:i,description:o}=n,a={...n,onFail:r,errorMessage:i,description:o},s=async function(...l){let c=typeof this=="object"&&"context"in this,d=c?this.context:this;if(await Promise.resolve(e(d,...l))){let M=c?this.context:this;return t.apply(M,l)}else if(r==="throw"){let M=i||"Guard condition failed";throw new Error(M)}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,l);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:o||"Runtime guarded transition",guards:[{name:"runtime_guard",description:o||"Runtime condition check"}]}),s}function Ae(e){return{do(t){let n=R(e,t);return n.else=function(r){return R(e,t,{onFail:r})},n}}}function Fe(e){return{do(t){let n=O(e,t);return n.else=function(r){return O(e,t,{onFail:r})},n}}}function je(e,t){return t}function Re(e,t){let n=e,r=s=>{n=s,t==null||t(s)},{context:i,...o}=e,a=new Proxy({},{get(s,l){let c=n[l];if(typeof c=="function")return(...d)=>{let u=c.apply(n.context,d),M=Object.assign({context:u.context},o);return r(M),M}}});return{get state(){return n},get context(){return n.context},actions:a,setState:r}}function Oe(e,t,n){let r=()=>{let o=e.getContext(),a=n(o),s=t[a];if(!s)throw new Error(`[Ensemble] Invalid state: No factory found for state "${String(a)}".`);return s(o)},i=new Proxy({},{get(o,a){let s=r(),l=s[a];if(typeof l!="function")throw new Error(`[Ensemble] Transition "${a}" is not valid in the current state.`);return(...c)=>l.apply(s.context,c)}});return{get context(){return e.getContext()},get state(){return r()},actions:i}}function Ye(e,t){return function(r){return Oe(e,r,t)}}function Xe(e,t){let n=Re(t),r=e(n),i=r.next();for(;!i.done;)i=r.next();return i.value}function Qe(e,t){let n=e(t),r=n.next();for(;!r.done;)r=n.next();return r.value}var J=class{constructor(t){this.store=t}get context(){return this.store.getContext()}setContext(t){this.store.setContext(t)}};function Ze(e,t){let n=new e(t);return new Proxy({},{get(r,i){let o=t.getContext();if(i in o)return o[i];let a=n[i];if(typeof a=="function")return(...s)=>a.apply(n,s)},set(r,i,o){let a=t.getContext();if(i in a){let s={...a,[i]:o};return t.setContext(s),!0}return!1},has(r,i){let o=t.getContext();return i in o||typeof n[i]=="function"},ownKeys(r){let i=t.getContext(),o=Object.keys(i),a=Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter(s=>s!=="constructor"&&typeof n[s]=="function");return Array.from(new Set([...o,...a]))},getOwnPropertyDescriptor(r,i){let o=t.getContext();if(i in o||typeof n[i]=="function")return{value:void 0,writable:!0,enumerable:!0,configurable:!0}}})}function et(e,t,n){let r=()=>{let i=n(e),o=t[i];if(!o)throw new Error(`[MutableMachine] Invalid state: No factory for state "${String(i)}".`);return o(e)};return new Proxy(e,{get(i,o,a){if(o in i)return i[o];let s=r(),l=s[o];if(typeof l=="function")return(...c)=>{let d=l.apply(s.context,c);if(typeof d!="object"||d===null){console.warn(`[MutableMachine] Transition "${String(o)}" did not return a valid context object. State may be inconsistent.`);return}Object.keys(i).forEach(u=>delete i[u]),Object.assign(i,d)}},set(i,o,a,s){return i[o]=a,!0},has(i,o){let a=r();return o in i||typeof a[o]=="function"}})}function at(e){return function(...t){let n=this.context.child;if(typeof n[e]=="function"){let r=n[e](...t);return F(this,{...this.context,child:r})}return this}}function st(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.`),F(this,{...this.context,[e]:!this.context[e]})}}var P=class extends T{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 T{constructor(n,r,i){super({status:"loading",abortController:new AbortController,attempts:i});this.config=n;this.params=r;this.succeed=n=>{var r,i;return(i=(r=this.config).onSuccess)==null||i.call(r,n),new v(this.config,{status:"success",data:n})};this.fail=n=>{var i,o,a;let r=(i=this.config.maxRetries)!=null?i:3;return this.context.attempts<r?new k(this.config,this.params,n,this.context.attempts):((a=(o=this.config).onError)==null||a.call(o,n),new N(this.config,{status:"error",error:n}))};this.cancel=()=>(this.context.abortController.abort(),new B(this.config));this.execute()}async execute(){}},k=class extends T{constructor(n,r,i,o){super({status:"retrying",error:i,attempts:o});this.config=n;this.params=r;this.retry=n=>new E(this.config,n!=null?n:this.params,this.context.attempts+1)}},v=class extends T{constructor(n,r){super(r);this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},N=class extends T{constructor(n,r){super(r);this.config=n;this.retry=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}},B=class extends T{constructor(n){super({status:"canceled"});this.config=n;this.refetch=n=>new E(this.config,n!=null?n:this.config.initialParams,1)}};function ct(e){return new P(e)}function Y(e,t){let n={...e.context,...t.context},r={...e},i={...t};delete r.context,delete i.context;let o={};for(let a in r){let s=r[a];o[a]=(...l)=>{let c=s.apply(e.context,l);return Y(c,t)}}for(let a in i){let s=i[a];o[a]=(...l)=>{let c=s.apply(t.context,l);return Y(e,c)}}return{context:n,...o}}import{Project as X,Node as p}from"ts-morph";function Q(e){return p.isIdentifier(e)?e.getText():p.isTypeOfExpression(e)?e.getExpression().getText():"unknown"}function A(e){if(!p.isObjectLiteralExpression(e))return{};let t={};for(let n of e.getProperties())if(p.isPropertyAssignment(n)){let r=n.getName(),i=n.getInitializer();i&&(p.isStringLiteral(i)||p.isNumericLiteral(i)?t[r]=i.getLiteralValue():i.getText()==="true"||i.getText()==="false"?t[r]=i.getText()==="true":p.isIdentifier(i)?t[r]=i.getText():p.isObjectLiteralExpression(i)?t[r]=A(i):p.isArrayLiteralExpression(i)&&(t[r]=i.getElements().map(o=>p.isObjectLiteralExpression(o)?A(o):o.getText())))}return t}function Pe(e){if(!p.isObjectLiteralExpression(e))return{};let t={};for(let n of e.getProperties())if(p.isPropertyAssignment(n)){let r=n.getName(),i=n.getInitializer();if(!i)continue;r==="onDone"||r==="onError"?t[r]=Q(i):p.isStringLiteral(i)?t[r]=i.getLiteralValue():p.isIdentifier(i)&&(t[r]=i.getText())}return t}function S(e,t=!1){if(!p.isCallExpression(e))return null;let n=e.getExpression(),r=p.isIdentifier(n)?n.getText():null;if(!r)return null;let i={},o=e.getArguments();switch(r){case"transitionTo":o[0]&&(i.target=Q(o[0]));break;case"describe":if(o[0]&&p.isStringLiteral(o[0])&&(i.description=o[0].getLiteralValue()),o[1]&&p.isCallExpression(o[1])){let a=S(o[1],t);a&&Object.assign(i,a)}break;case"guarded":if(o[0]){let a=A(o[0]);Object.keys(a).length>0&&(i.guards=[a])}if(o[1]&&p.isCallExpression(o[1])){let a=S(o[1],t);a&&Object.assign(i,a)}break;case"invoke":if(o[0]){let a=Pe(o[0]);Object.keys(a).length>0&&(i.invoke=a)}break;case"action":if(o[0]){let a=A(o[0]);Object.keys(a).length>0&&(i.actions=[a])}if(o[1]&&p.isCallExpression(o[1])){let a=S(o[1],t);a&&Object.assign(i,a)}break;case"guard":if(o[2]){let a=A(o[2]);a.description&&(i.description=a.description)}if(i.guards=[{name:"runtime_guard",description:i.description||"Synchronous condition check"}],o[1]&&p.isCallExpression(o[1])){let a=S(o[1],t);a&&Object.assign(i,a)}break;case"guardAsync":if(o[2]){let a=A(o[2]);a.description&&(i.description=a.description)}if(i.guards=[{name:"runtime_guard_async",description:i.description||"Asynchronous condition check"}],o[1]&&p.isCallExpression(o[1])){let a=S(o[1],t);a&&Object.assign(i,a)}break;default:return null}return Object.keys(i).length>0?i:null}function ke(e,t=!1){if(!p.isPropertyDeclaration(e))return t&&console.error(" ⚠️ Not a property declaration"),null;let n=e.getInitializer();if(!n)return t&&console.error(" ⚠️ No initializer"),null;if(!p.isCallExpression(n))return t&&console.error(" ⚠️ Initializer is not a call expression"),null;let r=S(n,t);return r&&t&&console.error(" ✅ Extracted metadata:",JSON.stringify(r,null,2)),r}function K(e,t=!1){let n={on:{}},r=e.getDeclarations()[0];if(!r||!p.isClassDeclaration(r))return t&&console.error(`⚠️ Warning: Could not get class declaration for ${e.getName()}`),n;let i=e.getName();t&&console.error(` Analyzing state: ${i}`);for(let o of r.getInstanceMembers()){let a=o.getName();t&&console.error(` Checking member: ${a}`);let s=ke(o,t);if(!s)continue;t&&console.error(` Found transition: ${a}`);let{invoke:l,actions:c,guards:d,...u}=s;if(l&&(n.invoke||(n.invoke=[]),n.invoke.push({src:l.src,onDone:{target:l.onDone},onError:{target:l.onError},description:l.description}),t&&console.error(` → Invoke: ${l.src}`)),u.target){let M={target:u.target};u.description&&(M.description=u.description),d&&(M.cond=d.map(y=>y.name).join(" && "),t&&console.error(` → Guard: ${M.cond}`)),c&&c.length>0&&(M.actions=c.map(y=>y.name),t&&console.error(` → Actions: ${M.actions.join(", ")}`)),n.on[a]=M,t&&console.error(` → Target: ${u.target}`)}}return n}function ve(e,t,n,r,i=!1){let o=K(t,i);if(r){i&&console.error(` 👪 Analyzing children for state: ${e}`),o.initial=r.initialState,o.states={};for(let a of r.classes){let s=n.getClass(a);if(s){let l=s.getSymbolOrThrow();o.states[a]=K(l,i)}else console.warn(`⚠️ Warning: Child class '${a}' not found.`)}}return o}function Z(e,t,n=!1){n&&(console.error(`
2
+ 🔍 Analyzing machine: ${e.id}`),console.error(` Source: ${e.input}`));let r=t.getSourceFile(e.input);if(!r)throw new Error(`Source file not found: ${e.input}`);if(e.parallel){n&&console.error(" ⏹️ Parallel machine detected. Analyzing regions.");let o={id:e.id,type:"parallel",states:{}};e.description&&(o.description=e.description);for(let a of e.parallel.regions){n&&console.error(` 📍 Analyzing region: ${a.name}`);let s={};for(let l of a.classes){let c=r.getClass(l);if(c){let d=c.getSymbolOrThrow();s[l]=K(d,n)}else console.warn(`⚠️ Warning: Class '${l}' not found for region '${a.name}'.`)}o.states[a.name]={initial:a.initialState,states:s}}return n&&console.error(` ✅ Extracted ${e.parallel.regions.length} parallel regions`),o}if(!e.initialState||!e.classes)throw new Error(`Machine config for '${e.id}' must have either 'parallel' or 'initialState'/'classes'.`);let i={id:e.id,initial:e.initialState,states:{}};e.description&&(i.description=e.description);for(let o of e.classes){let a=r.getClass(o);if(!a){console.warn(`⚠️ Warning: Class '${o}' not found in '${e.input}'. Skipping.`);continue}let s=a.getSymbolOrThrow(),l=o===e.initialState&&e.children,c=ve(o,s,r,l?e.children:void 0,n);i.states[o]=c}return n&&console.error(` ✅ Extracted ${e.classes.length} states`),i}function yt(e){var i;let t=(i=e.verbose)!=null?i:!1;t&&(console.error(`
3
+ 📊 Starting statechart extraction`),console.error(` Machines to extract: ${e.machines.length}`));let n=new X;n.addSourceFilesAtPaths("src/**/*.ts"),n.addSourceFilesAtPaths("examples/**/*.ts");let r=[];for(let o of e.machines)try{let a=Z(o,n,t);r.push(a)}catch(a){console.error(`❌ Error extracting machine '${o.id}':`,a),t||console.error(" Run with --verbose for more details")}return t&&console.error(`
4
+ ✅ Extraction complete: ${r.length}/${e.machines.length} machines extracted`),r}function Ne(){let e={input:"examples/authMachine.ts",classes:["LoggedOutMachine","LoggingInMachine","LoggedInMachine","SessionExpiredMachine","ErrorMachine"],id:"auth",initialState:"LoggedOutMachine",description:"Authentication state machine"};console.error("🔍 Using legacy generateChart function"),console.error(`⚠️ Consider using extractMachines() with a config file instead
5
+ `);let t=new X;t.addSourceFilesAtPaths("src/**/*.ts"),t.addSourceFilesAtPaths("examples/**/*.ts");try{let n=Z(e,t,!0);console.log(JSON.stringify(n,null,2))}catch(n){console.error("❌ Error:",n),process.exit(1)}}var Mt={hierarchical:{input:"examples/dashboardMachine.ts",id:"dashboard",classes:["DashboardMachine","LoggedOutMachine"],initialState:"DashboardMachine",children:{contextProperty:"child",initialState:"ViewingChildMachine",classes:["ViewingChildMachine","EditingChildMachine"]}},parallel:{input:"examples/editorMachine.ts",id:"editor",parallel:{regions:[{name:"fontWeight",initialState:"NormalWeight",classes:["NormalWeight","BoldWeight"]},{name:"textDecoration",initialState:"NoDecoration",classes:["NoDecoration","UnderlineState"]}]}}};V.main===module&&Ne();var ee=Symbol("CANCEL");function m(e,t,n={}){let{continueOnError:r=!1,logErrors:i=!0,onError:o}=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 l=e[s];typeof l=="function"&&s!=="context"&&(a[s]=function(...c){let d=s,u=a.context,M=()=>{let y;try{y=l.apply(this,c)}catch(f){if(t.error)try{t.error({transitionName:d,context:u,args:[...c],error:f})}catch(h){if(!r)throw h;i&&console.error(`Middleware error hook error for ${d}:`,h),o==null||o(h,"error",{transitionName:d,context:u,args:c,error:f})}throw f}let x=f=>{if(f&&typeof f=="object"&&f.context){for(let h in a)Object.prototype.hasOwnProperty.call(a,h)&&h!=="context"&&!(h in f)&&(f[h]=a[h]);for(let h in f){if(!Object.prototype.hasOwnProperty.call(f,h))continue;typeof f[h]=="function"&&h!=="context"&&a[h]&&(f[h]=a[h])}}return f};if(y&&typeof y.then=="function")return y.then(h=>{if(x(h),t.after)try{let C=t.after({transitionName:d,prevContext:u,nextContext:h.context,args:[...c]});if(C&&typeof C.then=="function")return C.then(()=>h)}catch(C){if(!r)throw C;i&&console.error(`Middleware after hook error for ${d}:`,C),o==null||o(C,"after",{transitionName:d,prevContext:u,nextContext:h.context,args:c})}return h});if(x(y),t.after)try{let f=t.after({transitionName:d,prevContext:u,nextContext:y.context,args:[...c]});if(f&&typeof f=="object"&&f&&"then"in f)return f.then(()=>y).catch(h=>{if(!r)throw h;return i&&console.error(`Middleware after hook error for ${d}:`,h),o==null||o(h,"after",{transitionName:d,prevContext:u,nextContext:y.context,args:c}),y})}catch(f){if(!r)throw f;i&&console.error(`Middleware after hook error for ${d}:`,f),o==null||o(f,"after",{transitionName:d,prevContext:u,nextContext:y.context,args:c})}return y};if(t.before)try{let y=t.before({transitionName:d,context:u,args:[...c]});if(y&&typeof y=="object"&&y&&"then"in y)return y.then(x=>x===ee?a:M()).catch(x=>{if(!r)throw x;return i&&console.error(`Middleware before hook error for ${d}:`,x),o==null||o(x,"before",{transitionName:d,context:u,args:c}),M()});if(y===ee)return a}catch(y){if(!r)throw y;i&&console.error(`Middleware before hook error for ${d}:`,y),o==null||o(y,"before",{transitionName:d,context:u,args:c})}return M()})}return a}function te(e,t={}){let{logger:n=console.log,includeArgs:r=!1,includeContext:i=!0}=t;return m(e,{before:({transitionName:o,args:a})=>{let s=r?`→ ${o} [${a.join(", ")}]`:`→ ${o}`;n(s)},after:({transitionName:o,nextContext:a})=>{let s=i?` ${JSON.stringify(a)}`:"";n(`✓ ${o}${s}`)},error:({transitionName:o,error:a})=>{console.error(`[Machine] ${o} failed:`,a)}})}function ne(e,t,n={}){let{eventPrefix:r="state_transition",includePrevContext:i=!1,includeArgs:o=!1}=n;return m(e,{after:({transitionName:a,prevContext:s,nextContext:l,args:c})=>{let d=`${r}.${a}`,u={transition:a};i&&(u.from=s),u.to=l,o&&(u.args=c),t(d,u)}})}function re(e,t){return m(e,{before:n=>{if(t(n)===!1)throw new Error(`Validation failed for transition: ${n.transitionName}`)}})}function ie(e,t){return m(e,{before:n=>{if(!t(n))throw new Error(`Unauthorized transition: ${n.transitionName}`)}})}function oe(e,t,n={}){let{includeArgs:r=!1}=n;return m(e,{error:i=>{let o={transition:i.transitionName,context:i.context,...r&&{args:i.args}};t(i.error,o)}})}function ae(e,t){let n=new Map;return m(e,{before:r=>{n.set(r.transitionName,Date.now())},after:r=>{let i=n.get(r.transitionName);if(i){let o=Date.now()-i;n.delete(r.transitionName);let a={transitionName:r.transitionName,duration:o,context:r.nextContext||r.prevContext};t(a)}}})}function se(e,t={}){var l,c;let{maxAttempts:n=(l=t.maxRetries)!=null?l:3,shouldRetry:r=()=>!0,backoffMs:i=(c=t.delay)!=null?c:100,backoffMultiplier:o=2,onRetry:a}=t,s={...e};for(let d in e){if(!Object.prototype.hasOwnProperty.call(e,d))continue;let u=e[d];typeof u=="function"&&d!=="context"&&(s[d]=async function(...M){let y,x=0;for(;x<n;)try{return await u.apply(this,M)}catch(f){if(y=f,x++,x<n&&r(y,x)){a==null||a(y,x);let C=(typeof i=="function"?i(x):i)*Math.pow(o,x-1);await new Promise(b=>setTimeout(b,C))}else throw y}throw y})}return s}function ht(e,t){return n=>m(n,e,t)}function z(e,t={}){let{maxSize:n,serializer:r,onEntry:i}=t,o=[],a=0,s=m(e,{before:({transitionName:l,args:c})=>{let d={id:`entry-${a++}`,transitionName:l,args:[...c],timestamp:Date.now()};if(r)try{d.serializedArgs=r.serialize(c)}catch(u){console.error("Failed to serialize history args:",u)}o.push(d),n&&o.length>n&&o.shift(),i==null||i(d)}});return Object.assign(s,{history:o,clearHistory:()=>{o.length=0,a=0}})}function $(e,t={}){let{maxSize:n,serializer:r,captureSnapshot:i,onlyOnChange:o=!1}=t,a=[],s=0,l=m(e,{after:({transitionName:d,prevContext:u,nextContext:M})=>{if(o&&JSON.stringify(u)===JSON.stringify(M))return;let y={id:`snapshot-${s++}`,transitionName:d,before:{...u},after:{...M},timestamp:Date.now()};if(r)try{y.serializedBefore=r.serialize(u),y.serializedAfter=r.serialize(M)}catch(x){console.error("Failed to serialize snapshot:",x)}if(i)try{y.diff=i(u,M)}catch(x){console.error("Failed to capture snapshot:",x)}a.push(y),n&&a.length>n&&a.shift()}});return Object.assign(l,{snapshots:a,clearSnapshots:()=>{a.length=0,s=0},restoreSnapshot:d=>{let u=Object.fromEntries(Object.entries(e).filter(([M])=>M!=="context"&&M!=="snapshots"&&M!=="clearSnapshots"&&M!=="restoreSnapshot"&&typeof e[M]=="function"));return Object.assign({context:d},u)}})}function D(e,t={}){let{maxSize:n,serializer:r,onRecord:i}=t,o=[],a=[],s=0,l=0,c=m(e,{before:({transitionName:M,args:y})=>{let x={id:`entry-${s++}`,transitionName:M,args:[...y],timestamp:Date.now()};if(r)try{x.serializedArgs=r.serialize(y)}catch(f){console.error("Failed to serialize history args:",f)}o.push(x),n&&o.length>n&&o.shift(),i==null||i("history",x)},after:({transitionName:M,prevContext:y,nextContext:x})=>{let f={id:`snapshot-${l++}`,transitionName:M,before:{...y},after:{...x},timestamp:Date.now()};if(r)try{f.serializedBefore=r.serialize(y),f.serializedAfter=r.serialize(x)}catch(h){console.error("Failed to serialize snapshot:",h)}a.push(f),n&&a.length>n&&a.shift(),i==null||i("snapshot",f)}});return Object.assign(c,{history:o,snapshots:a,clearHistory:()=>{o.length=0,s=0},clearSnapshots:()=>{a.length=0,l=0},clearTimeTravel:()=>{o.length=0,a.length=0,s=0,l=0},restoreSnapshot:M=>{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:M},y)},replayFrom:M=>{var C;if(M<0||M>=o.length)throw new Error(`Invalid replay start index: ${M}`);let y=(C=a[M])==null?void 0:C.before;if(!y)throw new Error(`No snapshot available for index ${M}`);let x=o.slice(M),h=Object.assign({context:y},Object.fromEntries(Object.entries(e).filter(([b])=>b!=="context"&&typeof e[b]=="function")));for(let b of x){let I=h[b.transitionName];I&&(h=I.apply(h.context,b.args))}return h}})}function jt(e,...t){return t.reduce((n,r)=>r(n),e)}function _(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 Rt(e){return new W(e)}function G(e,t){let n=function(r){return t(r)?e(r):r};return n.middleware=e,n.when=t,n}function Ot(e){return G(e,()=>typeof process!="undefined"?!1:typeof window!="undefined"?!window.location.hostname.includes("production"):!1)}function Pt(e,t,n){return G(n,r=>r.context[e]===t)}function kt(){let e=new Map;return{register(t,n,r,i){if(e.has(t))throw new Error(`Middleware '${t}' is already registered`);return e.set(t,{name:t,middleware:n,description:r,priority:i}),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,i;return((r=t.priority)!=null?r:0)-((i=n.priority)!=null?i:0)})},apply(t,n){let r=n.map(i=>{let o=e.get(i);if(!o)throw new Error(`Middleware '${i}' is not registered`);return o}).sort((i,o)=>{var a,s;return((a=i.priority)!=null?a:0)-((s=o.priority)!=null?s:0)});return _(t,...r.map(i=>i.middleware))},applyAll(t){let n=this.list();return _(t,...n.map(r=>r.middleware))}}}function vt(e={}){let{continueOnError:t=!1,logErrors:n=!0,onError:r}=e;return(i,...o)=>{let a=i,s=[],l=!0;for(let c=0;c<o.length;c++){let d=o[c];try{if("middleware"in d&&"when"in d){if(!d.when(a))continue;a=d.middleware(a)}else a=d(a)}catch(u){if(l=!1,!t)throw u;s.push({error:u,middlewareIndex:c,middlewareName:d.name}),n&&console.error(`Pipeline middleware error at index ${c}:`,u),r==null||r(u,c,d.name)}}return{machine:a,errors:s,success:l}}}function Nt(...e){return t=>_(t,...e)}function Bt(e,t){return n=>{for(let[r,i]of e)if(r(n))return i(n);return t?t(n):n}}function ce(e){return typeof e=="function"&&e.length===1}function Kt(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&"middleware"in e&&"when"in e&&ce(e.middleware)&&typeof e.when=="function"}function zt(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 $t(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 Dt(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 _t(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 Wt(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 Lt(e){return e!==null&&typeof e=="object"&&"name"in e&&"middleware"in e&&typeof e.name=="string"&&ce(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 L=class{constructor(t){this.machine=t;this.middlewares=[]}withLogging(t){return this.middlewares.push(n=>te(n,t)),this}withAnalytics(t,n){return this.middlewares.push(r=>ne(r,t,n)),this}withValidation(t,n){return this.middlewares.push(r=>re(r,t)),this}withPermissions(t){return this.middlewares.push(n=>ie(n,t)),this}withErrorReporting(t,n){return this.middlewares.push(r=>oe(r,t,n)),this}withPerformanceMonitoring(t,n){return this.middlewares.push(r=>ae(r,t)),this}withRetry(t){return this.middlewares.push(n=>se(n,t)),this}withHistory(t){return this.middlewares.push(n=>z(n,t)),this}withSnapshot(t){return this.middlewares.push(n=>$(n,t)),this}withTimeTravel(t){return this.middlewares.push(n=>D(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(G(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 Be(e){return new L(e)}function Ht(e={}){return{create:t=>{let n=Be(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 D($(z(e)))}function ze(e,t){return e instanceof t}function $e(e,...t){return{type:e,args:t}}function De(e,t){return F(e,n=>({...n,...t}))}async function _e(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 Le(e,t){return function(...n){let r=t(this.context,...n);return g(r,e())}}function Ge(e,t,...n){return e.apply(t,n)}function le(e){return new Proxy(e,{get(t,n){let r=t[n];return typeof r=="function"?function(...i){let o=r.apply(t.context,i);return o&&typeof o=="object"&&"context"in o?le(o):o}:r}})}var H=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 i=this.wrappedMachine[r];return typeof i=="function"?(...o)=>{let a=i.apply(this.wrappedMachine.context,o);return a&&typeof a=="object"&&"context"in a?new e(a):a}:i}})}};function He(){return function(t){return function(...n){let r=t(this.context,...n);return g(r,this)}}}function de(e){return{machine:e,addTransition:function(t,n){let r=function(...o){let a=n(this.context,...o);return g(a,this)},i=ye(e,{[t]:r});return de(i)}}}function ue(e){return function(n){let r={},i=Object.fromEntries(Object.entries(n).map(([o,a])=>[o,function(...s){let l=a(this.context,...s);return g(l,r)}]));return Object.assign(r,i),g(e,r)}}function Ie(e,t){return t!==void 0?g(e,t):ue(e)}function g(e,t){if(typeof t=="function"){let i;i=t(s=>{let l=g(s,i),c=Object.fromEntries(Object.entries(i).map(([d,u])=>[d,u.bind(s)]));return Object.assign(l,c)});let a=Object.fromEntries(Object.entries(i).map(([s,l])=>[s,l.bind(e)]));return Object.assign({context:e},a)}let n="context"in t?Object.fromEntries(Object.entries(t).filter(([i])=>i!=="context")):t;return Object.assign({context:e},n)}function Ve(e,t){if(typeof t=="function"){let i;i=t(s=>{let l=Ve(s,i),c=Object.fromEntries(Object.entries(i).map(([d,u])=>[d,u.bind(s)]));return Object.assign(l,c)});let a=Object.fromEntries(Object.entries(i).map(([s,l])=>[s,l.bind(e)]));return Object.assign({context:e},a)}let n="context"in t?Object.fromEntries(Object.entries(t).filter(([i])=>i!=="context")):t;return Object.assign({context:e},n)}function an(){return e=>{let t=Object.fromEntries(Object.entries(e).map(([n,r])=>[n,function(...i){let o=r(this.context,...i);return g(o,t)}]));return n=>g(n,t)}}function F(e,t){let{context:n,...r}=e,i=typeof t=="function"?t(n):t;return g(i,r)}function sn(e,t){let{context:n,...r}=e,i={...r,...t};return g(n,i)}function ye(e,t){let{context:n,...r}=e,i={...r,...t};return g(n,i)}function cn(e,t){return(...n)=>{let r=e(...n),i=t(),o={...r.context,...i.context},{context:a,...s}=r,{context:l,...c}=i,d={...s,...c};return g(o,d)}}function ln(e){let{context:t,...n}=e;return r=>g(r,n)}function dn(e,t,n){let r=e.context[t],i=n[r];if(!i)throw new Error(`No handler found for state: ${String(r)}`);return i(e.context)}function un(e,t,n){return e.context[t]===n}function yn(e,t){let n=e,r=null;async function i(o){r&&(r.abort(),r=null);let a=n[o.type];if(typeof a!="function")throw new Error(`[Machine] Unknown event type '${String(o.type)}' on current state.`);let s=new AbortController;r=s;try{let c=await a.apply(n.context,[...o.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:i,stop:()=>{r&&(r.abort(),r=null)}}}var T=class{constructor(t){this.context=t}};function Mn(e,t){let{context:n,...r}=e;return g(t(n),r)}export{Mt as ADVANCED_CONFIG_EXAMPLES,H as BoundMachine,ee as CANCEL,me as META_KEY,T as MachineBase,L as MiddlewareBuilder,J as MultiMachineBase,Se as action,le as bindTransitions,Bt as branch,Ge as call,Rt as chain,Nt as combine,cn as combineFactories,jt as compose,_ as composeTyped,Ve as createAsyncMachine,ht as createCustomMiddleware,Oe as createEnsemble,Ye as createEnsembleFactory,$e as createEvent,ct as createFetchMachine,he as createFlow,ue as createFunctionalMachine,g as createMachine,ln as createMachineBuilder,an as createMachineFactory,m as createMiddleware,Ht as createMiddlewareFactory,kt as createMiddlewareRegistry,Ze as createMultiMachine,et as createMutableMachine,Y as createParallelMachine,vt as createPipeline,Re as createRunner,Le as createTransition,de as createTransitionExtender,He as createTransitionFactory,at as delegateToChild,be as describe,ye as extendTransitions,Z as extractMachine,yt as extractMachines,Ne as generateChart,R as guard,O as guardAsync,we as guarded,un as hasState,Ot as inDevelopment,Ee as invoke,Kt as isConditionalMiddleware,$t as isMiddlewareContext,Dt as isMiddlewareError,ce as isMiddlewareFn,_t as isMiddlewareHooks,Wt as isMiddlewareOptions,zt as isMiddlewareResult,Lt as isNamedMiddleware,Gt as isPipelineConfig,ze as isState,We as logState,dn as matchMachine,De as mergeContext,je as metadata,Be as middlewareBuilder,Mn as next,sn as overrideTransitions,_e as pipeTransitions,U as run,ge as runAsync,yn as runMachine,fe as runSequence,pe as runWithDebug,Qe as runWithEnsemble,Xe as runWithRunner,F as setContext,Ie as state,Me as step,Ce as stepAsync,st as toggle,Te as transitionTo,G as when,Pt as whenContext,Ae as whenGuard,Fe as whenGuardAsync,ne as withAnalytics,Ke as withDebugging,oe as withErrorReporting,z as withHistory,te as withLogging,ae as withPerformanceMonitoring,ie as withPermissions,se as withRetry,$ as withSnapshot,D as withTimeTravel,re as withValidation,xe as yieldMachine};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @file Core library exports without framework integrations
3
+ * @description Minimal bundle for users who don't need React/Solid.js
4
+ */
5
+ export type { MaybePromise, Machine, AsyncMachine, AsyncTransitionArgs, TransitionOptions, BaseMachine, DeepReadonly, InferMachine, Event, MachineLike, MachineResult } from './index';
6
+ export type { Context, Transitions, TransitionArgs, TransitionNames } from './index';
7
+ export { createMachine, createAsyncMachine, createMachineFactory, createMachineBuilder, MachineBase, next, matchMachine, hasState } from './index';
8
+ export { setContext, overrideTransitions, extendTransitions, combineFactories } from './index';
9
+ export { runMachine } from './index';
10
+ export { run, step, yieldMachine, runSequence, createFlow, runWithDebug, runAsync, stepAsync } from './generators';
11
+ export { transitionTo, describe, guarded, guard, guardAsync, whenGuard, whenGuardAsync, invoke, action, metadata, META_KEY, type TransitionMeta, type GuardMeta, type InvokeMeta, type ActionMeta, type ClassConstructor, type WithMeta, type GuardOptions, type GuardFallback, type GuardedTransition } from './primitives';
12
+ export type { MachineConfig, ExtractionConfig } from './extract';
13
+ export * from './middleware/index';
14
+ export { isState, createEvent, createTransition, mergeContext, pipeTransitions, logState, call, bindTransitions, BoundMachine } from './utils';
15
+ export { createTransitionFactory, createTransitionExtender, createFunctionalMachine, state } from './functional-combinators';
16
+ export * from './multi';
17
+ export * from './higher-order';
18
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,YAAY,EACV,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,WAAW,EACX,aAAa,EACd,MAAM,SAAS,CAAC;AAMjB,YAAY,EACV,OAAO,EACP,WAAW,EACX,cAAc,EACd,eAAe,EAChB,MAAM,SAAS,CAAC;AAMjB,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,IAAI,EACJ,YAAY,EACZ,QAAQ,EACT,MAAM,SAAS,CAAC;AAMjB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAMjB,OAAO,EACL,UAAU,EACX,MAAM,SAAS,CAAC;AAMjB,OAAO,EACL,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,SAAS,EACV,MAAM,cAAc,CAAC;AAMtB,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,KAAK,EACL,UAAU,EACV,SAAS,EACT,cAAc,EACd,MAAM,EACN,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAUtB,YAAY,EACV,aAAa,EACb,gBAAgB,EACjB,MAAM,WAAW,CAAC;AAMnB,cAAc,oBAAoB,CAAC;AAMnC,OAAO,EACL,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,IAAI,EACJ,eAAe,EACf,YAAY,EACb,MAAM,SAAS,CAAC;AAMjB,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,EACN,MAAM,0BAA0B,CAAC;AAMlC,cAAc,SAAS,CAAC;AAMxB,cAAc,gBAAgB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { Machine } from './index';
1
+ import { Machine, BaseMachine } from './index';
2
2
  /**
3
3
  * Creates a factory for building type-safe transitions for a specific machine.
4
4
  * This higher-order function captures the machine's `transitions` object in a closure,
@@ -38,7 +38,7 @@ import { Machine } from './index';
38
38
  * const incremented = incrementBy.call(counter, 5); // Using factory
39
39
  * ```
40
40
  */
41
- export declare function createTransitionFactory<C extends object>(): <TArgs extends any[]>(transformer: (ctx: C, ...args: TArgs) => C) => (this: Machine<C>, ...args: TArgs) => Machine<C>;
41
+ export declare function createTransitionFactory<C extends object>(): <TArgs extends any[]>(transformer: (ctx: C, ...args: TArgs) => C) => (this: BaseMachine<C>, ...args: TArgs) => Machine<C>;
42
42
  /**
43
43
  * Creates a factory for adding new, type-safe transitions to an existing machine instance.
44
44
  * This enables a functional, compositional approach to building up a machine's capabilities
@@ -96,9 +96,7 @@ export declare function createTransitionExtender<M extends Machine<any>>(machine
96
96
  * the correct return type.
97
97
  */
98
98
  type MachineTransitions<T extends Record<string, (ctx: C, ...args: any[]) => C>, C extends object> = {
99
- [K in keyof T]: T[K] extends (ctx: C, ...args: infer A) => C ? (this: {
100
- context: C;
101
- } & T, ...args: A) => Machine<C> : never;
99
+ [K in keyof T]: T[K] extends (ctx: C, ...args: infer A) => C ? (this: Machine<C>, ...args: A) => Machine<C> : never;
102
100
  };
103
101
  /**
104
102
  * Creates a complete, type-safe, functional state machine using a curried, two-step
@@ -112,5 +110,62 @@ type MachineTransitions<T extends Record<string, (ctx: C, ...args: any[]) => C>,
112
110
  * functions and returns a fully-formed machine instance.
113
111
  */
114
112
  export declare function createFunctionalMachine<C extends object>(initialContext: C): <T extends Record<string, (ctx: C, ...args: any[]) => C>>(transformers: T) => Machine<C> & MachineTransitions<T, C>;
113
+ /**
114
+ * A smart, type-safe function that creates state machines using either the traditional
115
+ * `createMachine` pattern or the functional `createFunctionalMachine` pattern, automatically
116
+ * detecting which approach to use based on the arguments provided.
117
+ *
118
+ * **Two Usage Patterns:**
119
+ *
120
+ * 1. **Traditional Pattern** (with transitions object):
121
+ * ```typescript
122
+ * const machine = state({ count: 0 }, {
123
+ * increment() { return createMachine({ count: this.count + 1 }, this); }
124
+ * });
125
+ * ```
126
+ *
127
+ * 2. **Functional Pattern** (curried, with transformers):
128
+ * ```typescript
129
+ * const createCounter = state({ count: 0 });
130
+ * const machine = createCounter({
131
+ * increment: ctx => ({ count: ctx.count + 1 }),
132
+ * add: (ctx, n: number) => ({ count: ctx.count + n })
133
+ * });
134
+ * ```
135
+ *
136
+ * **How it works:**
137
+ * - When called with 2 arguments: Uses `createMachine` (traditional pattern)
138
+ * - When called with 1 argument: Uses `createFunctionalMachine` (functional pattern)
139
+ *
140
+ * **Edge Cases Handled:**
141
+ * - Empty transitions object: Falls back to functional pattern
142
+ * - Context with function properties: Properly typed as transitions vs transformers
143
+ * - Type inference: Maintains full type safety in both patterns
144
+ *
145
+ * @template C The context type
146
+ * @template T The transitions/transformers type
147
+ * @param context The initial context object
148
+ * @param transitions Optional transitions object (traditional pattern)
149
+ * @returns Either a machine (traditional) or a factory function (functional)
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * // Traditional pattern
154
+ * const counter1 = state({ count: 0 }, {
155
+ * increment() { return createMachine({ count: this.count + 1 }, this); },
156
+ * decrement() { return createMachine({ count: this.count - 1 }, this); }
157
+ * });
158
+ *
159
+ * // Functional pattern
160
+ * const createCounter = state({ count: 0 });
161
+ * const counter2 = createCounter({
162
+ * increment: ctx => ({ count: ctx.count + 1 }),
163
+ * decrement: ctx => ({ count: ctx.count - 1 }),
164
+ * reset: ctx => ({ count: 0 })
165
+ * });
166
+ * ```
167
+ */
168
+ export declare function state<C extends object>(context: C): ReturnType<typeof createFunctionalMachine<C>>;
169
+ export declare function state<C extends object, T extends Record<string, any>>(context: C, transitions: T): Machine<C> & T;
115
170
  export {};
116
171
  //# sourceMappingURL=functional-combinators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"functional-combinators.d.ts","sourceRoot":"","sources":["../../src/functional-combinators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,OAAO,EAAqB,MAAM,SAAS,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,MAiCrB,KAAK,SAAS,GAAG,EAAE,EAClD,aAAa,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,CAAC,MAEzB,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,KAAK,KAAG,OAAO,CAAC,CAAC,CAAC,CAMjE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC;;oBAqCrE,KAAK,SAAS,MAAM,EACpB,KAAK,SAAS,GAAG,EAAE,QAEb,KAAK,eACE,CAAC,GAAG,cAAG,EAAE,GAAG,IAAI,EAAE,KAAK,iBAAM;;wCAJ5B,MAAM,kBACN,GAAG,EAAE;;EAmBxB;AAED;;;;GAIG;AACH,KAAK,kBAAkB,CACrB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,EACvD,CAAC,SAAS,MAAM,IACd;KACD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GACxD,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC,CAAA;KAAE,GAAG,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GACpD,KAAK;CACV,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,cAAc,EAAE,CAAC,IA0BvE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,EAEvD,cAAc,CAAC,KACd,OAAO,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAwBzC"}
1
+ {"version":3,"file":"functional-combinators.d.ts","sourceRoot":"","sources":["../../src/functional-combinators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,OAAO,EAAE,WAAW,EAAqB,MAAM,SAAS,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,MAiCrB,KAAK,SAAS,GAAG,EAAE,EAClD,aAAa,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,CAAC,MAEzB,MAAM,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,KAAK,KAAG,OAAO,CAAC,CAAC,CAAC,CAMrE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC;;oBAqCrE,KAAK,SAAS,MAAM,EACpB,KAAK,SAAS,GAAG,EAAE,QAEb,KAAK,eACE,CAAC,GAAG,cAAG,EAAE,GAAG,IAAI,EAAE,KAAK,iBAAM;;wCAJ5B,MAAM,kBACN,GAAG,EAAE;;EAmBxB;AAED;;;;GAIG;AACH,KAAK,kBAAkB,CACrB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,EACvD,CAAC,SAAS,MAAM,IACd;KACD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GACxD,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC5C,KAAK;CACV,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,cAAc,EAAE,CAAC,IA0BvE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,EAEvD,cAAc,CAAC,KACd,OAAO,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAwBzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;AACnG,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnE,OAAO,EAAE,CAAC,EACV,WAAW,EAAE,CAAC,GACb,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC"}