+***************************************************************************** */function t(e,n){var h="function"==typeof Symbol&&e[Symbol.iterator];if(!h)return e;var _,b,p=h.call(e),d=[];try{for(;(void 0===n||n-- >0)&&!(_=p.next()).done;)d.push(_.value)}catch(e){b={error:e}}finally{try{_&&!_.done&&(h=p.return)&&h.call(p)}finally{if(b)throw b.error}}return d}var b;!function(e){e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped"}(b||(b={}));var p={type:"xstate.init"};function r(e){return void 0===e?[]:[].concat(e)}function i(e){return{type:"xstate.assign",assignment:e}}function o(e,n){return"string"==typeof(e="string"==typeof e&&n&&n[e]?n[e]:e)?{type:e}:"function"==typeof e?{type:e.name,exec:e}:e}function a(e){return function(n){return e===n}}function u(e){return"string"==typeof e?{type:e}:e}function c(e,n){return{value:e,context:n,actions:[],changed:!1,matches:a(e)}}function f(e,n,h){var _=n,b=!1;return[e.filter((function(e){if("xstate.assign"===e.type){b=!0;var n=Object.assign({},_);return"function"==typeof e.assignment?n=e.assignment(_,h):Object.keys(e.assignment).forEach((function(b){n[b]="function"==typeof e.assignment[b]?e.assignment[b](_,h):e.assignment[b]})),_=n,!1}return!0})),_,b]}function s(e,n){void 0===n&&(n={});var h=t(f(r(e.states[e.initial].entry).map((function(e){return o(e,n.actions)})),e.context,p),2),_=h[0],b=h[1],d={config:e,_options:n,initialState:{value:e.initial,actions:_,context:b,matches:a(e.initial)},transition:function(n,h){var _,b,p="string"==typeof n?{value:n,context:e.context}:n,S=p.value,g=p.context,m=u(h),v=e.states[S];if(v.on){var y=r(v.on[m.type]);try{for(var T=function(e){var n="function"==typeof Symbol&&Symbol.iterator,h=n&&e[n],_=0;if(h)return h.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&_>=e.length&&(e=void 0),{value:e&&e[_++],done:!e}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(y),j=T.next();!j.done;j=T.next()){var x=j.value;if(void 0===x)return c(S,g);var w="string"==typeof x?{target:x}:x,k=w.target,C=w.actions,I=void 0===C?[]:C,N=w.cond,O=void 0===N?function(){return!0}:N,M=void 0===k,U=null!=k?k:S,D=e.states[U];if(O(g,m)){var E=t(f((M?r(I):[].concat(v.exit,I,D.entry).filter((function(e){return e}))).map((function(e){return o(e,d._options.actions)})),g,m),3),R=E[0],X=E[1],F=E[2],A=null!=k?k:S;return{value:A,context:X,actions:R,changed:k!==S||R.length>0||F,matches:a(A)}}}}catch(e){_={error:e}}finally{try{j&&!j.done&&(b=T.return)&&b.call(T)}finally{if(_)throw _.error}}}return c(S,g)}};return d}var l=function(e,n){return e.actions.forEach((function(h){var _=h.exec;return _&&_(e.context,n)}))};function interpret(e,n){const h=wrapXStateService(function(e){var n=e.initialState,h=b.NotStarted,_=new Set,d={_machine:e,send:function(p){h===b.Running&&(n=e.transition(n,p),l(n,u(p)),_.forEach((function(e){return e(n)})))},subscribe:function(e){return _.add(e),e(n),{unsubscribe:function(){return _.delete(e)}}},start:function(_){if(_){var S="object"==typeof _?_:{context:e.config.context,value:_};n={value:S.value,actions:[],context:S.context,matches:a(S.value)}}else n=e.initialState;return h=b.Running,l(n,p),d},stop:function(){return h=b.Stopped,_.clear(),d},get state(){return n},get status(){return h}};return d}(e));return n?function(e,n){return e._getterCache={},e.getters=new Proxy(n,{get(n,h){if(!e._getterCache[h]){const _=n[h](e._xstateService.state.context);e._getterCache[h]=_}return e._getterCache[h]}}),e.subscribe((()=>{e._getterCache={}})),e}(h,n):h}function createXStateService(e,n,h){const _=interpret(n,h);return globalThis.__ficusjs__=globalThis.__ficusjs__||{},globalThis.__ficusjs__.xstate=globalThis.__ficusjs__.xstate||{},globalThis.__ficusjs__.xstate[e]=_,_}function addXStateService(e,n){return globalThis.__ficusjs__=globalThis.__ficusjs__||{},globalThis.__ficusjs__.xstate=globalThis.__ficusjs__.xstate||{},globalThis.__ficusjs__.xstate[e]=n,n}function getXStateService(e){if(globalThis.__ficusjs__&&globalThis.__ficusjs__.xstate&&globalThis.__ficusjs__.xstate[e])return globalThis.__ficusjs__.xstate[e]}export{e as BasePersist,n as Store,addXStateService,i as assign,createAppState,s as createMachine,createPersist,createStateMachine,createXStateService,getAppState,getXStateService,interpret,withLocalState,withStateMachine,withStore,withWorkerStore,withXStateService,wrapXStateService};
0 commit comments