UNPKG

@turbox3d/reactivity

Version:

Large-scale reactive state management library

2 lines 47.1 kB
/*! For license information please see index.min.js.LICENSE.txt */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("THREE")):"function"==typeof define&&define.amd?define(["THREE"],t):"object"==typeof exports?exports["@turbox3d/reactivity"]=t(require("THREE")):e.Reactivity=t(e.THREE)}(self,(e=>(()=>{var t={498:(e,t,r)=>{var n=r(553).default;function o(){"use strict";e.exports=o=function(){return r},e.exports.__esModule=!0,e.exports.default=e.exports;var t,r={},i=Object.prototype,a=i.hasOwnProperty,c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",u=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function d(e,t,r,n){Object.defineProperty(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n})}try{d({},"")}catch(t){d=function(e,t,r){return e[t]=r}}function f(e,r,n,o){var i=r&&r.prototype instanceof y?r:y,a=Object.create(i.prototype);return d(a,"_invoke",function(e,r,n){var o=1;return function(i,a){if(3===o)throw Error("Generator is already running");if(4===o){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var s=w(c,n);if(s){if(s===h)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(1===o)throw o=4,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=3;var u=p(e,r,n);if("normal"===u.type){if(o=n.done?4:2,u.arg===h)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(o=4,n.method="throw",n.arg=u.arg)}}}(e,n,new S(o||[])),!0),a}function p(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}r.wrap=f;var h={};function y(){}function v(){}function g(){}var m={};d(m,s,(function(){return this}));var b=Object.getPrototypeOf,T=b&&b(b(P([])));T&&T!==i&&a.call(T,s)&&(m=T);var E=g.prototype=y.prototype=Object.create(m);function O(e){["next","throw","return"].forEach((function(t){d(e,t,(function(e){return this._invoke(t,e)}))}))}function k(e,t){function r(o,i,c,s){var u=p(e[o],e,i);if("throw"!==u.type){var l=u.arg,d=l.value;return d&&"object"==n(d)&&a.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,c,s)}),(function(e){r("throw",e,c,s)})):t.resolve(d).then((function(e){l.value=e,c(l)}),(function(e){return r("throw",e,c,s)}))}s(u.arg)}var o;d(this,"_invoke",(function(e,n){function i(){return new t((function(t,o){r(e,n,t,o)}))}return o=o?o.then(i,i):i()}),!0)}function w(e,r){var n=r.method,o=e.i[n];if(o===t)return r.delegate=null,"throw"===n&&e.i.return&&(r.method="return",r.arg=t,w(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),h;var i=p(o,e.i,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,h;var a=i.arg;return a?a.done?(r[e.r]=a.value,r.next=e.n,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,h):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,h)}function A(e){this.tryEntries.push(e)}function N(e){var r=e[4]||{};r.type="normal",r.arg=t,e[4]=r}function S(e){this.tryEntries=[[-1]],e.forEach(A,this),this.reset(!0)}function P(e){if(null!=e){var r=e[s];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(a.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(n(e)+" is not iterable")}return v.prototype=g,d(E,"constructor",g),d(g,"constructor",v),d(g,l,v.displayName="GeneratorFunction"),r.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,g):(e.__proto__=g,d(e,l,"GeneratorFunction")),e.prototype=Object.create(E),e},r.awrap=function(e){return{__await:e}},O(k.prototype),d(k.prototype,u,(function(){return this})),r.AsyncIterator=k,r.async=function(e,t,n,o,i){void 0===i&&(i=Promise);var a=new k(f(e,t,n,o),i);return r.isGeneratorFunction(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},O(E),d(E,l,"Generator"),d(E,s,(function(){return this})),d(E,"toString",(function(){return"[object Generator]"})),r.keys=function(e){var t=Object(e),r=[];for(var n in t)r.unshift(n);return function e(){for(;r.length;)if((n=r.pop())in t)return e.value=n,e.done=!1,e;return e.done=!0,e}},r.values=P,S.prototype={constructor:S,reset:function(e){if(this.prev=this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(N),!e)for(var r in this)"t"===r.charAt(0)&&a.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0][4];if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(t){a.type="throw",a.arg=e,r.next=t}for(var o=r.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i[4],c=this.prev,s=i[1],u=i[2];if(-1===i[0])return n("end"),!1;if(!s&&!u)throw Error("try statement without catch or finally");if(null!=i[0]&&i[0]<=c){if(c<s)return this.method="next",this.arg=t,n(s),!0;if(c<u)return n(u),!1}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n[0]>-1&&n[0]<=this.prev&&this.prev<n[2]){var o=n;break}}o&&("break"===e||"continue"===e)&&o[0]<=t&&t<=o[2]&&(o=null);var i=o?o[4]:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o[2],h):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),h},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r[2]===e)return this.complete(r[4],r[3]),N(r),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r[0]===e){var n=r[4];if("throw"===n.type){var o=n.arg;N(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={i:P(e),r,n},"next"===this.method&&(this.arg=t),h}},r}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports},553:e=>{function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},713:(e,t,r)=>{var n=r(498)();e.exports=n;try{regeneratorRuntime=n}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}},858:t=>{"use strict";t.exports=e}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t){var r=function(t){if("object"!=e(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==e(r)?r:r+""}function r(e,r,n){return(r=t(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function a(e){return function(e){if(Array.isArray(e))return i(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}n.r(o),n.d(o,{Action:()=>xe,ActionStatus:()=>z,Domain:()=>be,EEventName:()=>Q,REACTIVE_COMPONENT_NAME:()=>$,Reaction:()=>re,TimeTravel:()=>J,UNSUBSCRIBE_HANDLER:()=>F,action:()=>ue,computed:()=>ie,config:()=>q,createDomain:()=>Te,depCollector:()=>Oe,emitter:()=>te,init:()=>ze,mutation:()=>ce,reactive:()=>oe,reactor:()=>ee,registerExternalBatchUpdate:()=>Se,store:()=>Ee,use:()=>Ue});var c="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),s=new Array(36);function u(){for(var e=0,t=0;t<36;t++)if(8===t||13===t||18===t||23===t)s[t]="-";else if(14===t)s[t]="7";else{e<=2&&(e=33554432+16777216*Math.random()|0);var r=15&e;e>>=4,s[t]=c[19===t?3&r|8:r]}return s.join("")}function l(){return"undefined"!=typeof Symbol}var d=/^\[object (?:Object|Array|Map|Set|WeakMap|WeakSet)\]$/;function f(t){return null!==t&&"object"===e(t)}function p(e){return e&&"function"==typeof e.then}function h(t){if(null===t||"object"!==e(t))return!1;var r=Object.getPrototypeOf(t);return r===Object.prototype||null===r}function y(e,t){return e.indexOf(t)>-1}function v(e,t){var r=e.indexOf(t);r>-1&&e.splice(r,1)}function g(e,t){t.forEach((function(t){e.delete(t)}))}function m(t){return"symbol"!==e(t)?t.toString():t.toString()+u()}var b,T=Promise.resolve();function E(e){return e?T.then(e):T}function O(e,t){return function(r){var n=arguments.length;return n?n>1?e.apply(t,arguments):e.call(t,r):e.call(t)}}function k(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function w(e,r){for(var n=0;n<r.length;n++){var o=r[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,t(o.key),o)}}function A(e,t,r){return t&&w(e.prototype,t),r&&w(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}!function(e){e[e.UserAction=0]="UserAction",e[e.UpdateState=1]="UpdateState",e[e.RenderReact=2]="RenderReact",e[e.RenderScene=-1]="RenderScene"}(b||(b={})),n(713),n(858),new(function(){return A((function e(){k(this,e),this.listeners={}}),[{key:"on",value:function(e,t){var r=this.listeners[e]||[];r.push(t),this.listeners[e]=r}},{key:"emit",value:function(e){for(var t=this,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];var i=this.listeners[e];Array.isArray(i)&&i.forEach((function(e){try{e.apply(t,n)}catch(e){console.error(e)}}))}},{key:"off",value:function(e){this.listeners[e]&&(this.listeners[e]=[])}}])}());var N="An invariant failed, however the error is obfuscated because this is an production build.";function S(e,t){if(!e)throw new Error("[turbox]: ".concat(t||N))}function P(e){throw S(!1,e),"X"}function R(t){return t&&"object"===e(t)&&"[object RegExp]"!==Object.prototype.toString.call(t)&&"[object Date]"!==Object.prototype.toString.call(t)}function x(e,t){var r;return t&&!0===t.clone&&R(e)?D((r=e,Array.isArray(r)?[]:{}),e,t):e}function C(e,t,r){var n=e.slice();return t.forEach((function(t,o){void 0===n[o]?n[o]=x(t,r):R(t)?n[o]=D(e[o],t,r):-1===e.indexOf(t)&&n.push(x(t,r))})),n}function D(e,t,r){var n=Array.isArray(t),o=(r||{arrayMerge:C}).arrayMerge||C;return n?Array.isArray(e)?o(e,t,r):x(t,r):function(e,t,r){var n={};return R(e)&&Object.keys(e).forEach((function(t){n[t]=x(e[t],r)})),Object.keys(t).forEach((function(o){R(t[o])&&e[o]?n[o]=D(e[o],t[o],r):n[o]=x(t[o],r)})),n}(e,t,r)}function M(e){return(2===e.length||3===e.length)&&"string"==typeof e[1]}function U(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce((function(e,t){return function(){return e(t.apply(void 0,arguments))}}))}Date.now;var I="@@TURBOX__";function _(e){return l()?Symbol(e):"".concat(I).concat(e)}var j,H,L,G,z,B=_("namespace"),$=_("reactive-component-name"),F=_("unsubscribe-handler"),W="".concat(I,"materialType"),V="".concat(I,"empty"),K="".concat(I,"field"),X=!1,Y={middleware:{logger:X,diffLogger:!0,effect:!1,perf:X,skipNestLog:!0,skipNestPerfLog:!0},timeTravel:{isActive:!1,isNeedRecord:!1,maxStepNumber:20,keepActionChain:X},disableReactive:!1,strictMode:X,devTool:!1,batchUpdateOnFinish:void 0};function q(e){Y=D(Y,e)}!function(e){e.NOT_OBSERVED="notObserved",e.OBSERVED="observed",e.LATEST="latest"}(j||(j={})),function(e){e.ARRAY_LENGTH="length",e.ITERATE="iterate",e.COMPUTED="computed"}(H||(H={})),function(e){e.SET="set",e.MAP_SET="map-set",e.ADD="add",e.SET_ADD="set-add",e.DELETE="delete",e.MAP_DELETE="map-delete",e.SET_DELETE="set-delete"}(L||(L={})),function(e){e.DEFAULT="default",e.MUTATION="mutation",e.ACTION="action",e.UPDATE="update",e.EFFECT="effect",e.UNDO="undo",e.REDO="redo"}(G||(G={})),function(e){e.WORKING="working",e.COMPLETED="completed",e.ABORT="abort"}(z||(z={}));var J=function(){function e(){k(this,e),this.currentHistory=new Map,this.transactionHistories=[],this.cursor=-1}return A(e,[{key:"undoable",get:function(){return this.cursor>=0}},{key:"redoable",get:function(){return this.cursor<this.transactionHistories.length-1}},{key:"onChange",value:function(e,t,r,n){}},{key:"undo",value:function(){var t=this;if(this.undoable){var r=this.transactionHistories[this.cursor];Ee||P("store is not ready, please init first.");var n=r.actionChain[0]||{name:"",displayName:""};Ee.dispatch({name:"".concat(I,"UNDO_").concat(n.name),displayName:"UNDO_".concat(n.displayName),payload:[],original:function(){e.undoHandler(r.history)},type:G.UNDO,isInner:!0}),this.cursor-=1,E((function(){t.onChange(t.undoable,t.redoable,"undo")}))}}},{key:"redo",value:function(){var t=this;if(this.redoable){this.cursor+=1;var r=this.transactionHistories[this.cursor];Ee||P("store is not ready, please init first.");var n=r.actionChain[0]||{name:"",displayName:""};Ee.dispatch({name:"".concat(I,"REDO_").concat(n.name),displayName:"REDO_".concat(n.displayName),payload:[],original:function(){e.redoHandler(r.history)},type:G.REDO,isInner:!0}),E((function(){t.onChange(t.undoable,t.redoable,"redo")}))}}},{key:"clear",value:function(){var e=this;this.currentHistory=new Map,this.transactionHistories.length=0,this.cursor=-1,E((function(){e.onChange(e.undoable,e.redoable,"clear")}))}}],[{key:"undoable",get:function(){return e.currentTimeTravel&&e.currentTimeTravel.undoable}},{key:"redoable",get:function(){return e.currentTimeTravel&&e.currentTimeTravel.redoable}},{key:"undoHandler",value:function(e){e.forEach((function(e,t){e&&e.forEach((function(e,r){e&&e.beforeUpdate!==e.didUpdate&&(e.type===L.MAP_SET||e.type===L.MAP_DELETE?void 0===e.beforeUpdate?t.delete(r):t.set(r,e.beforeUpdate):e.type===L.SET_ADD?t.delete(r):e.type===L.SET_DELETE?t.add(r):Array.isArray(t)&&void 0===e.beforeUpdate?delete t[r]:t[r]=e.beforeUpdate)}))}))}},{key:"redoHandler",value:function(e){e.forEach((function(e,t){e&&e.forEach((function(e,r){e&&e.beforeUpdate!==e.didUpdate&&(e.type===L.MAP_SET?t.set(r,e.didUpdate):e.type===L.SET_ADD?t.add(r):e.type===L.SET_DELETE||e.type===L.MAP_DELETE?t.delete(r):t[r]=e.didUpdate)}))}))}}])}();J.timeTravels={},J.processing=!1,J.switch=function(e){J.currentTimeTravel=J.get(e)},J.create=function(e){var t=new J;return J.timeTravels[e]=t,t},J.get=function(e){return J.timeTravels[e]},J.pause=function(){Y.timeTravel.isActive=!1},J.resume=function(){Y.timeTravel.isActive=!0},J.undo=function(){J.currentTimeTravel&&J.currentTimeTravel.undo()},J.redo=function(){J.currentTimeTravel&&J.currentTimeTravel.redo()},J.clear=function(){J.currentTimeTravel&&J.currentTimeTravel.clear()};var Q,Z={freeze:!1};function ee(){for(var e={deepProxy:!0,displayName:""},t=function(t,r,n){var o={enumerable:!0,configurable:!0,get:function(){var t=this;e.callback&&!Z.freeze&&(Z.freeze=!0,e.callback&&e.callback.call(t,t,r),Z.freeze=!1);var o=n&&n.initializer&&n.initializer();return t.propertyGet(r,e,!(!n||!n.initializer),o)},set:function(t){this.propertySet(r,t,e)}};return void 0===n?Object.defineProperty(t,r,o):o},r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];if(h(n[0])||Array.isArray(n[0])||n[0]&&n[0].constructor&&y(me,n[0].constructor)){var i=n[1];i&&(void 0!==i.displayName&&(e.displayName=i.displayName),void 0!==i.isNeedRecord&&(e.isNeedRecord=i.isNeedRecord),void 0!==i.callback&&(e.callback=i.callback));var a=new be,c=e.displayName||K,s=t(a,c);return s[c]=n[0],s[c]}return M(n)?t.apply(null,n):(e.deepProxy=void 0===n[0]||n[0],void 0!==n[1]&&(e.isNeedRecord=n[1]),e.callback=n[2],t)}!function(e){e.storeOnActive="storeOnActive",e.beforeStoreChange="beforeStoreChange",e.afterStoreChange="afterStoreChange",e.asyncAfterStoreChange="asyncAfterStoreChange",e.setProperty="setProperty",e.materialCallStackChange="materialCallStackChange"}(Q||(Q={}));var te=new(function(){return A((function e(){k(this,e),this.listeners={}}),[{key:"on",value:function(e,t){var r=this.listeners[e]||[];r.push(t),this.listeners[e]=r}},{key:"emit",value:function(e,t){var r=this;Y.devTool&&window&&window.__TURBOX_DEVTOOL_GLOBAL_HOOKS__&&window.__TURBOX_DEVTOOL_GLOBAL_HOOKS__.emit(e,t);var n=this.listeners[e];Array.isArray(n)&&n.forEach((function(e){try{e.apply(r,[t])}catch(e){P(e)}}))}},{key:"off",value:function(e){this.listeners[e]&&(this.listeners[e]=[])}}])}()),re=function(){return A((function e(t,r,n,o,i,a){k(this,e),this.name=t,this.runner=r,this.computed=n,this.lazy=o,this.deps=i,this.immediately=a}),[{key:"dispose",value:function(){void 0!==this.unsubscribeHandler&&this.unsubscribeHandler(),Oe.clear(this)}}])}();function ne(e,t){var r=t&&t.name||e.name||"".concat(I,"REACTIVE_").concat(u()),n=!(!t||void 0===t.lazy)&&t.lazy,o=t&&t.deps||[],i=!t||void 0===t.immediately||t.immediately,a=!0,c=new re(r,(function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{if(Oe.start(c),c.deps.length>0){var r=[];c.deps.forEach((function(e){var t=e();r.push(t)})),Oe.end(),!a&&e.call.apply(e,[null].concat(r))}else e.call(null),Oe.end();a&&(a=!1)}catch(e){if(Oe.end(),a&&(a=!1),!t)throw e}}),!(!t||!t.computed),n,o,i),s=function(){c.unsubscribeHandler=Ee.subscribe((function(e){c.runner(e)}),c),c.runner()};return Ee?s():te.on(Q.storeOnActive,(function(){s()})),c}function oe(e,t){return ne(e,t)}function ie(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];if("function"==typeof t[0]){var n,o,i=!0,a=!1,c=!1,s=t[0],u=t[1],l=ne((function(){i=!0,a&&(n=s()),c&&we.trigger(o,H.COMPUTED,{type:L.SET,beforeUpdate:void 0,didUpdate:void 0})}),{name:"computed",computed:!0,lazy:!(!u||void 0===u.lazy)&&u.lazy});return o={get:function(){return i&&(a=!0,c=!1,l.runner(),i=!1,a=!1,c=!0),Oe.collect(o,H.COMPUTED),n},dispose:function(){l.dispose()}}}var d,f,p=function(e,t,r){return d={enumerable:!0,configurable:!0,get:function(){return this.computedPropertyGet(t,f)},set:function(e){this.computedPropertySet(t,e)}},void 0===r?Object.defineProperty(e,t,d):d={enumerable:!0,configurable:!0,get:function(){return this.computedPropertyGet(t,f,r)},set:r.set}};return M(t)?p.apply(null,t):(f=t[0],p)}function ae(e,t,r,n){var o=m(t),i=function(){var t=this;e||(t=new be),Ee||P("store is not ready, please init first.");for(var i=arguments.length,a=new Array(i),c=0;c<i;c++)a[c]=arguments[c];var s=Ee.dispatch({name:o,displayName:n.displayName||V,payload:a,type:G.MUTATION,domain:t,original:O(r,t),immediately:!!n.immediately,forceSaveHistory:!!n.forceSaveHistory,isNeedRecord:!!n.isNeedRecord});if(p(s))return new Promise((function(e,t){s.then((function(t){e(t)}),(function(e){t(e)}))}));if(s&&s instanceof Error)throw s;return s};return i[W]=G.MUTATION,i}function ce(){for(var e={immediately:!1,displayName:"",forceSaveHistory:!1,isNeedRecord:!0},t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];if("string"==typeof r[0]&&"function"==typeof r[1]){void 0!==r[2]&&(e.displayName=r[2].displayName,e.immediately=r[2].immediately,e.forceSaveHistory=!!r[2].forceSaveHistory,e.isNeedRecord=!!r[2].isNeedRecord);var o=r[0],i=r[1];return i[W]===G.MUTATION?i:ae(void 0,o,i,e)}var a=function(t,r,n){var o;if(void 0===n)return Object.defineProperty(t,r,{enumerable:!0,configurable:!0,get:function(){return o},set:function(n){o=n[W]===G.MUTATION?n:ae(t,r,n,e)}});if(void 0!==n.value){var i=n.value;return i[W]===G.MUTATION?n.value=i:n.value=ae(t,r,i,e),n}var a=n.initializer;return n.initializer=function(){S(!!a,"The initializer of the descriptor doesn't exist, please compile it by using babel and correspond decorator plugin.");var n=a&&a.call(this);return n[W]===G.MUTATION?n:ae(t,r,n,e)},n};return M(r)?a.apply(null,r):(e.displayName=r[0]||"",e.immediately=void 0!==r[1]&&r[1],e.forceSaveHistory=void 0!==r[2]&&r[2],e.isNeedRecord=void 0===r[3]||r[3],a)}function se(e,t,r,n){var o=m(t),i=function(){var e,i=xe.create(o,n.displayName),a=O(r,this);e=n.isWrapMutation?ce(t,a,n.mutationConfig):a;for(var c=arguments.length,s=new Array(c),u=0;u<c;u++)s[u]=arguments[u];var l=i.execute(e,s);return p(l)?new Promise((function(e,t){l.then((function(t){i.complete(),e(t)}),(function(e){i.abort(),t(e)}))})):(i.complete(),l)};return i[W]=G.ACTION,i}function ue(){for(var e={displayName:"",isWrapMutation:!0,mutationConfig:void 0},t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];if("string"==typeof r[0]&&"function"==typeof r[1]){void 0!==r[2]&&(e.displayName=r[2].displayName,e.isWrapMutation=r[2].isWrapMutation,e.mutationConfig=r[2].mutationConfig);var o=r[0],i=r[1];return i[W]===G.ACTION?i:se(0,o,i,e)}var a=function(t,r,n){var o;if(void 0===n)return Object.defineProperty(t,r,{enumerable:!0,configurable:!0,get:function(){return o},set:function(t){o=t[W]===G.ACTION?t:se(0,r,t,e)}});if(void 0!==n.value){var i=n.value;return i[W]===G.ACTION?n.value=i:n.value=se(0,r,i,e),n}var a=n.initializer;return n.initializer=function(){S(!!a,"The initializer of the descriptor doesn't exist, please compile it by using babel and correspond decorator plugin.");var t=a&&a.call(this);return t[W]===G.ACTION?t:se(0,r,t,e)},n};return M(r)?a.apply(null,r):(e.displayName=r[0]||"",e.isWrapMutation=void 0===r[1]||r[1],e.mutationConfig=void 0!==r[2]?r[2]:void 0,a)}function le(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function de(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?le(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):le(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var fe,pe=new(function(){return A((function e(){k(this,e),this.stack=[],this.pendingToPopStack=[],this.stackId=0}),[{key:"push",value:function(e){this.stackId+=1;var t=de(de({},e),{},{stackId:this.stackId});return this.currentStack=t,this.stack.push(t),Y.devTool&&te.emit(Q.materialCallStackChange,{stack:a(this.stack),action:"PUSH",time:Date.now(),currentStack:t}),this.stackId}},{key:"pop",value:function(e){var t;if(0!==this.stack.length){if(this.stack[this.stack.length-1].stackId!==e)this.pendingToPopStack.unshift(e);else{this.currentStack=void 0;var r=this.stack.pop();Y.devTool&&te.emit(Q.materialCallStackChange,{stack:a(this.stack),action:"POP",time:Date.now(),currentStack:r})}for(var n=a(this.pendingToPopStack),o=0;o<this.pendingToPopStack.length;o+=1){var i=this.pendingToPopStack[o];if((null===(t=this.stack[this.stack.length-1])||void 0===t?void 0:t.stackId)!==i)break;var c=this.stack.pop();n.splice(o,1),this.currentStack=this.stack[this.stack.length-1],Y.devTool&&te.emit(Q.materialCallStackChange,{stack:a(this.stack),action:"POP",time:Date.now(),currentStack:c})}this.pendingToPopStack=n,0===this.pendingToPopStack.length&&(this.currentStack=void 0)}}}])}());function he(e){return e instanceof be}!function(e){e.property="property",e.index="index"}(fe||(fe={}));var ye=new WeakMap,ve=new WeakMap,ge=new WeakMap,me=[Map,Set,WeakMap,WeakSet],be=function(){return A((function e(){var t=this;k(this,e),this.$$turboxProperties={},this.reactorConfigMap={},this.computedProperties={},this.getCollectionHandlerMap=function(e,n){return r(r(r(r(r({get size(){var t=Reflect.getPrototypeOf(e);return Oe.collect(e,H.ITERATE),Reflect.get(t,n,e)},get:function(t){var r=Reflect.getPrototypeOf(e).get;return Oe.collect(e,t),r.call(e,t)},has:function(t){var r=Reflect.getPrototypeOf(e).has;return Oe.collect(e,t),r.call(e,t)},forEach:function(t){var r=Reflect.getPrototypeOf(e).forEach;return Oe.collect(e,H.ITERATE),r.call(e,t)},values:function(){var t=Reflect.getPrototypeOf(e).values;return Oe.collect(e,H.ITERATE),t.call(e)},keys:function(){var t=Reflect.getPrototypeOf(e).keys;return Oe.collect(e,H.ITERATE),t.call(e)},entries:function(){var t=Reflect.getPrototypeOf(e).entries;return Oe.collect(e,H.ITERATE),t.call(e)}},Symbol.iterator,(function(){return e.constructor===Set?t.getCollectionHandlerMap(e,"values").values():e.constructor===Map?t.getCollectionHandlerMap(e,"entries").entries():void 0})),"add",(function(r){var n=Reflect.getPrototypeOf(e),o=n.add,i=n.has,a=ge.get(e),c=a[0].value;return i.call(e,r)||(we.trigger(e,r,{type:L.SET_ADD,beforeUpdate:void 0,didUpdate:r},t.reactorConfigMap[c].isNeedRecord,{keyPath:a,domain:t.constructor.name}),we.trigger(e,H.ITERATE,{type:L.SET_ADD},t.reactorConfigMap[c].isNeedRecord)),o.call(e,r)})),"set",(function(r,n){var o=Reflect.getPrototypeOf(e),i=o.set,a=o.get,c=o.has,s=ge.get(e),u=s[0].value,l=c.call(e,r),d=a.call(e,r);return n!==d&&we.trigger(e,r,{type:L.MAP_SET,beforeUpdate:d,didUpdate:n},t.reactorConfigMap[u].isNeedRecord,{keyPath:s,domain:t.constructor.name}),l||we.trigger(e,H.ITERATE,{type:L.MAP_SET},t.reactorConfigMap[u].isNeedRecord),i.call(e,r,n)})),"delete",(function(r){var n=Reflect.getPrototypeOf(e),o=ge.get(e),i=o[0].value;if(!n.has.call(e,r))return n.delete.call(e,r);if(n.constructor===Map||n.constructor===WeakMap){var a=n.get.call(e,r);we.trigger(e,r,{type:L.MAP_DELETE,beforeUpdate:a},t.reactorConfigMap[i].isNeedRecord,{keyPath:o,domain:t.constructor.name}),we.trigger(e,H.ITERATE,{type:L.MAP_DELETE},t.reactorConfigMap[i].isNeedRecord)}return n.constructor!==Set&&n.constructor!==WeakSet||(we.trigger(e,r,{type:L.SET_DELETE,beforeUpdate:r},t.reactorConfigMap[i].isNeedRecord,{keyPath:o,domain:t.constructor.name}),we.trigger(e,H.ITERATE,{type:L.SET_DELETE},t.reactorConfigMap[i].isNeedRecord)),n.delete.call(e,r)})),"clear",(function(){var r=Reflect.getPrototypeOf(e),n=r.clear;return r.forEach.call(e,(function(r,n){t.getCollectionHandlerMap(e,n).delete(n)})),n.call(e)}))};var n=Object.getPrototypeOf(this).constructor.name||"TURBOX_DOMAIN",o="".concat(n,"_").concat(u());this[B]=o,this.context=this.initDomainContext()}),[{key:"initDomainContext",value:function(){return{isNeedRecord:Y.timeTravel.isNeedRecord}}},{key:"propertyGet",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3?arguments[3]:void 0,o=e in this.$$turboxProperties,i=r&&!o,a=i?n:this.$$turboxProperties[e];i&&this.propertySet(e,a,t);var c=Object.assign({},{isNeedRecord:this.context.isNeedRecord},t);return this.reactorConfigMap[e]=c,Oe.collect(this,e),f(a)&&!he(a)&&c.deepProxy?this.proxyReactive(a,[{type:fe.property,value:e}]):a}},{key:"propertySet",value:function(e,t,r){Y.strictMode&&this.illegalAssignmentCheck(this,e);var n=this.$$turboxProperties[e],o=Object.assign({},{isNeedRecord:this.context.isNeedRecord},r);this.reactorConfigMap[e]=o,n!==t&&(this.$$turboxProperties[e]=t,we.trigger(this,e,{type:L.SET,beforeUpdate:n,didUpdate:t},o.isNeedRecord,{keyPath:[{type:fe.property,value:e}],domain:this.constructor.name}))}},{key:"computedPropertyGet",value:function(e,t,r){var n=this;this.computedProperties[e]||(this.computedProperties[e]={dirty:!0,needReComputed:!1,needTrigger:!1});var o=this.computedProperties[e],i=!(!t||void 0===t.lazy)&&t.lazy;if(o.reaction||(o.reaction=ne((function(){o.dirty=!0,o.needReComputed&&(o.value=o.computeRunner()),o.needTrigger&&we.trigger(n,e,{type:L.SET,beforeUpdate:void 0,didUpdate:void 0},!1)}),{name:e,computed:!0,lazy:i})),!o.computeRunner&&r&&(o.computeRunner=O(r.get,this)),o.dirty){o.needReComputed=!0,o.needTrigger=!1;try{o.reaction.runner()}finally{o.dirty=!1,o.needReComputed=!1,o.needTrigger=!0}}return Oe.collect(this,e),o.value}},{key:"computedPropertySet",value:function(e,t){this.computedProperties[e]||(this.computedProperties[e]={dirty:!0,needReComputed:!1,needTrigger:!1}),this.computedProperties[e].computeRunner||(this.computedProperties[e].computeRunner=O(t,this))}},{key:"$update",value:function(e,t,r,n,o,i){S(h(e),"resetState(...) param type error. Param should be a plain object."),this.dispatch(e,t,r,n,o,i)}},{key:"proxySet",value:function(e,t,r,n){Array.isArray(e)&&e!==this.currentTarget&&(this.currentTarget=e,this.originalArrayLength=e[H.ARRAY_LENGTH]),Y.strictMode&&this.illegalAssignmentCheck(e,t);var o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t),i=e[t],a=ge.get(e)[0].value;return e===ye.get(n)&&(t!==H.ARRAY_LENGTH&&r===i||(we.trigger(e,t,{type:L.SET,beforeUpdate:t===H.ARRAY_LENGTH?this.originalArrayLength:i,didUpdate:r},this.reactorConfigMap[a].isNeedRecord,{keyPath:[{type:fe.property,value:t}],domain:this.constructor.name}),t===H.ARRAY_LENGTH&&(this.currentTarget=void 0,this.originalArrayLength=void 0)),o||we.trigger(e,t,{type:L.ADD,beforeUpdate:i,didUpdate:r},this.reactorConfigMap[a].isNeedRecord,{keyPath:[{type:fe.property,value:t}],domain:this.constructor.name}),Reflect.set(e,t,r,n))}},{key:"proxyGet",value:function(e,t,r){var n=this,o=Reflect.get(e,t,r),i=ge.get(e),c=i[0].value;return Oe.collect(e,t),this.reactorConfigMap[c].callback&&!Z.freeze&&(Z.freeze=!0,n.reactorConfigMap[c].callback&&n.reactorConfigMap[c].callback.call(n,e,t),Z.freeze=!1),f(o)&&!he(o)?this.proxyReactive(o,[].concat(a(i),[{type:Array.isArray(e)?fe.index:fe.property,value:t}])):o}},{key:"proxyDeleteProperty",value:function(e,t){var r=ge.get(e)[0].value,n=e[t];return we.trigger(e,t,{type:L.DELETE,beforeUpdate:n,didUpdate:void 0},this.reactorConfigMap[r].isNeedRecord,{keyPath:[{type:fe.property,value:t}],domain:this.constructor.name}),Reflect.deleteProperty(e,t)}},{key:"proxyOwnKeys",value:function(e){return Oe.collect(e,H.ITERATE),Reflect.ownKeys(e)}},{key:"proxyReactive",value:function(e,t){var r=this;ge.set(e,t);var n,o=ve.get(e);if(void 0!==o)return o;if(ye.has(e))return e;if(n=e,!d.test(function(e){return Object.prototype.toString.call(e)}(n)))return e;var i=y(me,e.constructor)?{get:O(r.collectionProxyHandler,r)}:{get:O(r.proxyGet,r),set:O(r.proxySet,r),ownKeys:O(r.proxyOwnKeys,r),deleteProperty:O(r.proxyDeleteProperty,r)},a=new Proxy(e,i);return ye.set(a,e),ve.set(e,a),a}},{key:"collectionProxyHandler",value:function(e,t){var r=this.getCollectionHandlerMap(e,t),n=t in e&&r[t]?r:e;return Reflect.get(n,t)}},{key:"illegalAssignmentCheck",value:function(e,t){if(Oe.isObserved(e,t)){var r=pe.stack.length,n=pe.stack[r-1]||G.DEFAULT;S(n.type===G.MUTATION||n.type===G.UPDATE||n.type===G.UNDO||n.type===G.REDO,"You cannot update value to observed '@reactor property' directly. Please use mutation or $update({}).")}}},{key:"dispatch",value:function(e,t,r,n,o,i){var a=function(){for(var t=Object.keys(e),r=0,n=t.length;r<n;r++){var o=t[r];this[o]=e[o]}};if(void 0===Ee)return a.call(this),void pe.pop(-1);Ee.dispatch({name:t||"".concat(I,"UPDATE"),displayName:r||V,payload:[],type:G.UPDATE,domain:this,original:O(a,this),forceSaveHistory:n,isNeedRecord:o,immediately:i})}}])}();function Te(e){var t=e.reactor,r=e.mutation,n=e.computed,o=e.action,i=new be,a={deepProxy:!0,displayName:"",isNeedRecord:!0};return Object.keys(t).forEach((function(e){var r=t[e];Object.defineProperty(i,e,{enumerable:!0,configurable:!0,get:function(){return this.propertyGet(e,a)},set:function(t){this.propertySet(e,t,a)}}),i[e]=r})),Object.keys(r).forEach((function(e){var t=ce(e,O(r[e],i));i[e]=t})),n&&Object.keys(n).forEach((function(e){var t=ie(O(n[e],i));i[e]=t})),o&&Object.keys(o).forEach((function(e){var t=ue(e,O(o[e],i));i[e]=t})),i}var Ee,Oe=new(function(){return A((function e(){k(this,e),this.dependencyGraph=new Map,this.reactionIdDeps=new Map,this.reactionIdStack=[]}),[{key:"start",value:function(e){this.reactionIdStack.push(e)}},{key:"collect",value:function(e,t){if(!{constructor:!0,$$turboxProperties:!0,context:!0,currentTarget:!0,originalArrayLength:!0,reactorConfigMap:!0,computedProperties:!0,propertyGet:!0,propertySet:!0,proxyDeleteProperty:!0,proxyOwnKeys:!0,proxySet:!0,proxyGet:!0,proxyReactive:!0,$update:!0,illegalAssignmentCheck:!0,dispatch:!0}[t]){var r=this.reactionIdStack.length;if(0!==r){var n=this.reactionIdStack[r-1],o=this.dependencyGraph.get(e);if(void 0!==o){var i=o.get(t);void 0!==i?i.add(n):o.set(t,new Set([n]))}else{var a=new Map([[t,new Set([n])]]);this.dependencyGraph.set(e,a)}var c=this.reactionIdDeps.get(n);if(void 0!==c){var s=c.get(e);void 0!==s?s.set(t,j.LATEST):c.set(e,new Map([[t,j.LATEST]]))}else this.reactionIdDeps.set(n,new Map([[e,new Map([[t,j.LATEST]])]]))}}}},{key:"end",value:function(){var e=this,t=this.reactionIdStack.pop();if(t){var r=this.reactionIdDeps.get(t);r&&r.forEach((function(r,n){r.forEach((function(o,i){if(o===j.OBSERVED){var a=e.dependencyGraph.get(n);if(a){var c=a.get(i);c&&c.delete(t),r.set(i,j.NOT_OBSERVED)}}o===j.LATEST&&r.set(i,j.OBSERVED)}))}))}}},{key:"clear",value:function(e){var t=this,r=this.reactionIdDeps.get(e);r&&(r.forEach((function(r,n){r.forEach((function(r,o){var i=t.dependencyGraph.get(n);if(i){var a=i.get(o);a&&a.delete(e)}}))})),this.reactionIdDeps.delete(e))}},{key:"isObserved",value:function(e,t){var r=this.dependencyGraph.get(e);return void 0!==r&&r.has(t)&&(r.get(t)||new Set).size>0}}])}()),ke=function(){return A((function e(){k(this,e),this.waitTriggerIds=new Set}),[{key:"trigger",value:function(e,t,r){var n,o,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],a=arguments.length>4?arguments[4]:void 0,c=r.type,s=r.beforeUpdate,u=r.didUpdate;if(Y.devTool&&a)try{var l=null!==(n=window&&window.__TURBOX_DEVTOOL_GOLBAL_STRINGIFY__)&&void 0!==n?n:JSON.stringify,d={time:Date.now(),stackId:null===(o=pe.currentStack)||void 0===o?void 0:o.stackId,domain:a.domain,keyPath:a.keyPath,newValue:l(u),oldValue:l(s),type:c};te.emit(Q.setProperty,d),console.log(d)}catch(e){P(e)}var f=c===L.ADD?H.ITERATE:t;this.collectComponentId(e,f),Y.timeTravel.isActive&&J.currentTimeTravel&&i&&!J.processing&&f!==H.ITERATE&&f!==H.COMPUTED&&(xe.context?this.recordDiff(e,f,r,xe.context.historyNode.history):this.recordDiff(e,f,r,J.currentTimeTravel.currentHistory))}},{key:"endBatch",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=arguments.length>1?arguments[1]:void 0;if(t||this.waitTriggerIds.clear(),Y.timeTravel.isActive&&J.currentTimeTravel&&e){if(t)return t.historyNode.actionChain.length=0,t.historyNode.history.clear(),void E((function(){var e=J.currentTimeTravel;e&&e.onChange(e.undoable,e.redoable,"clear",t)}));Ae.length=0,J.currentTimeTravel.currentHistory.clear()}}},{key:"save",value:function(e){if(Y.timeTravel.isActive&&J.currentTimeTravel&&!xe.context){var t=J.currentTimeTravel;e?this.saveHistory(t,e.historyNode.actionChain,e.historyNode.history,e):this.saveHistory(t,Ae,t.currentHistory)}}},{key:"collectComponentId",value:function(e,t){var r=this,n=Oe.dependencyGraph.get(e);if(void 0!==n){var o=n.get(t);void 0!==o&&o.size>0&&o.forEach((function(e){return r.waitTriggerIds.add(e)}))}}},{key:"recordDiff",value:function(e,t,r,n){var o,i=r.type,a=r.beforeUpdate,c=r.didUpdate;if(o=he(e)?e:ve.get(e)){var s=n.get(o);if(void 0!==s){var u=s.get(t);void 0!==u?u.didUpdate=c:s.set(t,{type:i,beforeUpdate:a,didUpdate:c})}else n.set(o,new Map([[t,{type:i,beforeUpdate:a,didUpdate:c}]]))}}},{key:"saveHistory",value:function(e,t,r,n){if(r&&0!==r.size){var o=Y.timeTravel.keepActionChain?t.slice():[],i=new Map(r);e.cursor===e.transactionHistories.length-1?(e.transactionHistories.push({actionChain:o,history:i}),e.cursor+=1):e.cursor<e.transactionHistories.length-1&&(e.transactionHistories=e.transactionHistories.slice(0,e.cursor+1),e.transactionHistories.push({actionChain:o,history:i}),e.cursor+=1),e.transactionHistories.length>Y.timeTravel.maxStepNumber&&(e.transactionHistories.shift(),e.cursor-=1),E((function(){e.onChange(e.undoable,e.redoable,"save",n)}))}}}])}(),we=new ke,Ae=[],Ne=[],Se=function(e){Ne.push(e)};function Pe(e){if(void 0!==e)return Ee=e(Pe);var t,r=new WeakMap,n=0,o=!1,i=function(e,t,n){if(e.length&&!Y.disableReactive){for(var o=[],i=0;i<e.length;i++){var a=e[i],c=r.get(a);c&&o.push(c)}var s=function(e){return function(){for(var t=0;t<o.length;t++){var r=o[t];if(r.idCustomType===e)for(var i=r.listeners,a=0;a<i.length;a++)(0,i[a])(n)}}};t?Ne.forEach((function(e){(0,e.handler)(s(e.idCustomType),(function(){Y.batchUpdateOnFinish&&Y.batchUpdateOnFinish()}))})):s()()}},c=function(e){var t=a(we.waitTriggerIds.values()).filter((function(e){return e instanceof re&&!e.lazy&&e.computed}));t.length&&(Y.devTool&&console.log("keepAlive computed",t),i(t,!1,e),g(we.waitTriggerIds,t))},s=function(e){var t=a(we.waitTriggerIds.values()).filter((function(e){return e instanceof re&&!e.computed&&e.immediately}));t.length&&(g(we.waitTriggerIds,t),Y.devTool&&console.log("immediately reactive",t),i(t,!1,e))},u=[],l=function(){if(!o){o=!0;var e=function(){E((function(){if(n>0)return o=!1,void u.shift();0!==u.length&&t&&t()}))};u.push(e),e()}},d=function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];o=!1,t=void 0,u.shift(),Ae.length=0,e&&we.endBatch()};return{dispatch:function(e){var r,o,u,f,h=e.payload,y=e.type,v=e.original,g=e.immediately,m=e.isInner,b=void 0!==m&&m,T=e.domain,E=e.name,O=e.forceSaveHistory,k=void 0!==O&&O,w=e.isNeedRecord,A=void 0===w||w;b&&(J.processing=!0);var N=pe.push({type:y,method:E,domain:null==T?void 0:T.constructor.name});if(b||y===G.MUTATION||y===G.UPDATE){var S;if(n+=1,(b||g&&we.waitTriggerIds.size>0)&&t&&t(),void 0===t&&(t=function(){var e=a(we.waitTriggerIds.values());if(e.length||k){!b&&A&&we.save();var t=e.filter((function(e){return e instanceof re&&e.lazy&&e.computed}));Y.devTool&&console.log("lazy computed",t),i(t,!1,b);var r=a(we.waitTriggerIds.values()).filter((function(e){return e instanceof re&&!e.computed&&!e.immediately})),n=a(we.waitTriggerIds.values()).filter((function(e){return!(e instanceof re)}));d(),Y.devTool&&console.log("lazy reactive",r),i(r,!1,b),Y.devTool&&console.log("custom view Reactive",n),i(n,!0,b)}else d(!1)}),Y.devTool){var P={domain:null!==(r=null==T?void 0:T.constructor.name)&&void 0!==r?r:"UNKNOWN",method:E,args:h,state:null==T?void 0:T.$$turboxProperties,time:Date.now(),stackId:null===(o=pe.currentStack)||void 0===o?void 0:o.stackId};te.emit(Q.beforeStoreChange,P)}try{S=v.apply(void 0,a(h))}catch(e){return e}if(Y.devTool){var R={domain:null!==(u=null==T?void 0:T.constructor.name)&&void 0!==u?u:"UNKNOWN",method:E,args:h,state:null==T?void 0:T.$$turboxProperties,async:!1,time:Date.now(),stackId:null===(f=pe.currentStack)||void 0===f?void 0:f.stackId};te.emit(Q.afterStoreChange,R)}return p(S)?(pe.pop(N),new Promise((function(e,r){var o;Promise.resolve().then((function(){o=pe.push({type:y,method:E,domain:null==T?void 0:T.constructor.name,syncStackId:N})})),S.then((function(r){var i,a;Y.devTool&&te.emit(Q.asyncAfterStoreChange,{domain:null!==(i=null==T?void 0:T.constructor.name)&&void 0!==i?i:"UNKNOWN",method:E,args:h,state:null==T?void 0:T.$$turboxProperties,async:!0,time:Date.now(),stackId:null===(a=pe.currentStack)||void 0===a?void 0:a.stackId}),c(b),s(b),n-=1,g?t&&t():l(),pe.pop(o),e(r)})).catch((function(e){r(e)}))}))):(c(b),s(b),n-=1,b||g?(t&&t(),J.processing=!1):l(),pe.pop(N),S)}},subscribe:function(e,t,n){var o=!0,i=r.get(t);return void 0===i||void 0===i.listeners?r.set(t,{idCustomType:n,listeners:[e]}):y(i.listeners,e)||r.set(t,{idCustomType:n,listeners:i.listeners.concat(e)}),function(){o&&(o=!1,r.has(t)&&r.delete(t))}}}}var Re=[],xe=function(){function e(){k(this,e),this.displayName=V,this.status=z.WORKING,this.historyNode={actionChain:[],history:new Map}}return A(e,[{key:"execute",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o=arguments.length>3?arguments[3]:void 0;if(this.status!==z.ABORT){e.context=this;var i=(n?ce(this.name,t,o):t).apply(void 0,a(r));if(p(i))return i.then((function(){e.context=void 0}),(function(){e.context=void 0}));e.context=void 0}}},{key:"complete",value:function(){this.status!==z.ABORT&&(this.status=z.COMPLETED,we.save(this),we.endBatch(!0,this),v(Re,this))}},{key:"undo",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];Ee||P("store is not ready, please init first.");var r=this.historyNode.actionChain[0]||{name:"",displayName:""};Ee.dispatch({name:"".concat(I,"UNDO_").concat(r.name),displayName:"UNDO_".concat(r.displayName),payload:[],original:function(){J.undoHandler(e.historyNode.history)},type:G.UNDO,isInner:!0}),t||(this.historyNode={actionChain:[],history:new Map},E((function(){var t=J.currentTimeTravel;t&&t.onChange(t.undoable,t.redoable,"undo",e)})))}},{key:"redo",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];Ee||P("store is not ready, please init first.");var r=this.historyNode.actionChain[0]||{name:"",displayName:""};Ee.dispatch({name:"".concat(I,"REDO_").concat(r.name),displayName:"REDO_".concat(r.displayName),payload:[],original:function(){J.redoHandler(e.historyNode.history)},type:G.REDO,isInner:!0}),t||(this.historyNode={actionChain:[],history:new Map},E((function(){var t=J.currentTimeTravel;t&&t.onChange(t.undoable,t.redoable,"redo",e)})))}},{key:"abort",value:function(){(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&this.undo(),this.status=z.ABORT,we.endBatch(!0,this),v(Re,this)}}],[{key:"create",value:function(t,r){var n=new e;return n.name=t,r&&(n.displayName=r),n.historyNode.actionChain.push({name:t,displayName:n.displayName}),Re.push(n),n}},{key:"abortAll",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];Re.forEach((function(t){t.abort(e)}))}},{key:"get",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.length?1===t.length?Re.filter((function(e){return e.name===t[0]})):Re.filter((function(e){return y(t,e.name)})):Re}}])}();function Ce(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function De(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ce(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ce(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var Me=[];function Ue(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=Array.isArray(e)?e:[e];t?Me.unshift.apply(Me,a(r)):Me.push.apply(Me,a(r))}function Ie(e,t,r,n){var o=e(t);return p(o)?new Promise((function(e,t){o.then((function(t){r&&r(),e(t)})).catch((function(e){n&&n(e.stack||e.message),t(e)}))})):(o&&o instanceof Error?n&&n(o.stack||o.message):r&&r(),o)}const _e=function(){return function(e){return function(t){var r=t.name,n=t.displayName,o=t.type;return t.isInner||o!==G.MUTATION&&o!==G.UPDATE||(xe.context?xe.context.historyNode.actionChain.push({name:r,displayName:n}):Ae.push({name:r,displayName:n})),Ie(e,t)}}},je=function(){return function(e){return function(t){var r=t.name,n=t.displayName,o=t.domain;if(!o||!Y.middleware.logger)return Ie(e,t);var i=pe.stack.length;return Y.middleware.skipNestLog&&1!==i?Ie(e,t):Y.middleware.diffLogger?Ie(e,t,(function(){if(o){var e=new Map;xe.context?e=new Map(xe.context.historyNode.history):J.currentTimeTravel&&(e=new Map(J.currentTimeTravel.currentHistory));var t=[];e.forEach((function(e,r){e.forEach((function(e,n){t.push({name:r.constructor.name,target:he(r)?r.$$turboxProperties:r,property:n,before:e.beforeUpdate,after:e.didUpdate})}))})),t.length&&(console.group("%c[TURBOX LOG]: DIFF ".concat(o.constructor.name," ").concat(r," ").concat(n!==V?n:""),"background: #FF5F0F; color: #fff; font-weight: bold; padding: 3px 5px;"),console.table(t),console.groupEnd())}})):(console.group("%c[TURBOX LOG]: PREV ".concat(o.constructor.name," ").concat(r," ").concat(n!==V?n:""),"background: #929493; color: #fff; font-weight: bold; padding: 3px 5px;"),console.dir(D({},o.$$turboxProperties,{clone:!0})),console.groupEnd(),Ie(e,t,(function(){o&&(console.group("%c[TURBOX LOG]: NEXT ".concat(o.constructor.name," ").concat(r," ").concat(n!==V?n:""),"background: #218D41; color: #fff; font-weight: bold; padding: 3px 5px;"),console.dir(D({},o.$$turboxProperties,{clone:!0})),console.groupEnd())})))}}},He=function(){return function(e){return function(t){if(!Y.middleware.perf)return Ie(e,t);var r=t.name,n=t.displayName,o=performance.now(),i=pe.stack.length;return Y.middleware.skipNestPerfLog&&1!==i?Ie(e,t):Ie(e,t,(function(){var e=performance.now();console.log("%c[TURBOX PERF]: ".concat(r," ").concat(n!==V?n:""," ").concat((e-o).toFixed(3),"ms"),"background: #FA54FF; color: #fff; font-weight: bold; padding: 3px 5px;")}))}}};var Le=!1;function Ge(){we.endBatch(),J.clear()}function ze(e){if(Ge(),S("undefined"!=typeof Proxy&&l(),"Proxy or Symbol is not supported, please add polyfill."),!Le){Ue(He),Ue(_e),Ue(je);var t=[function(e){var t=e(),r=function(){P("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},n={getActionChain:function(){return xe.context?xe.context.historyNode.actionChain.slice():Ae.slice()},getDependencyGraph:function(){return new Map(Oe.dependencyGraph)},dispatch:function(){return r.apply(void 0,arguments)}},o=Me.map((function(e){return e(n)}));return r=U.apply(void 0,a(o))(t.dispatch),De(De({},t),{},{dispatch:r})}];Pe(U.apply(void 0,t)),te.emit(Q.storeOnActive)}if(Le=!0,e){var r=ce("".concat(I,"init"),e,{immediately:!0,displayName:""})();if(p(r))return r.then((function(){Ge()}),(function(){Ge()}));Ge()}}ze()})(),o})()));