pubo-utils 1.0.80 → 1.0.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["pubo-utils"]=n():t["pubo-utils"]=n()}(this,(()=>(()=>{"use strict";var t={d:(n,e)=>{for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};t.r(n),t.d(n,{Base64Utils:()=>e,ContinuousTrigger:()=>E,Emitter:()=>v,HistoryStack:()=>_,Level:()=>L,RegExpList:()=>H,SensorDataFilter:()=>N,SyncQueue:()=>A,WatchDog:()=>R,callbackToPromise:()=>D,concatArray:()=>K,debounce:()=>i,degrees:()=>U,filterKeyPoints:()=>X,getAngle:()=>C,getCenter:()=>B,getDistance:()=>G,hex2rgb:()=>c,loop:()=>w,radians:()=>q,random:()=>s,randomRangeNum:()=>f,sleep:()=>b,superFactory:()=>d,throttle:()=>j,waitFor:()=>x});var e={};t.r(e),t.d(e,{EncoderMap:()=>M,toUnit8Array:()=>O});var r=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},o=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},i=function(t,n,e){if(void 0===e&&(e=!1),e){var i,u=!0;return function(){for(var e=[],c=0;c<arguments.length;c++)e[c]=arguments[c];u&&(t.apply(void 0,o([],r(e),!1)),u=!1),i&&clearTimeout(i),i=setTimeout((function(){return u=!0}),n)}}var c;return function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];c&&clearTimeout(c),c=setTimeout((function(){return t.apply(void 0,o([],r(e),!1))}),n)}},u=function(t){return parseInt(t.replace("#",""),16)},c=function(t){var n=("string"==typeof t?u(t):t).toString(2).padStart(24,"0");return[parseInt(n.slice(0,8),2),parseInt(n.slice(8,16),2),parseInt(n.slice(16,24),2)]},a=function(t){return"#"+[0,1,2].map((function(n){return t[n].toString(16)})).join("")},l=(function(){function t(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=u(t):Array.isArray(t)&&(this.int=u(a(t)))}t.prototype.getRgbArray=function(){return c(this.int)},Object.defineProperty(t.prototype,"rgb",{get:function(){return"rba(".concat(this.getRgbArray().join(", "),")")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hex",{get:function(){return a(this.getRgbArray())},enumerable:!1,configurable:!0}),t.prototype.toString=function(t){return void 0===t&&(t="hex"),"rgb"===t?this.rgb:this.hex}}(),function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}),s=function(t){void 0===t&&(t=8);var n=function(t){return Math.random().toString(32).slice(2,2+t)};if(t<=8)return n(t);for(var e="",r=0;r<=t;r+=8)e+=n(t-r>8?8:t-r);return e},f=function(t){var n=Math.abs(t[1]-t[0]);return Math.random()*n+Math.min.apply(Math,function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}([],l(t),!1))},h=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},p=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},y=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},v=function(){function t(){this.state={},this.ids={}}return t.prototype.on=function(t,n){if(this.state[t]||(this.state[t]=[]),"function"!=typeof n)throw new Error("第二个参数必须为function!");var e=this.state[t].push(n)-1,r=s(40);return this.ids[r]={event:t,index:e},r},t.prototype.cancel=function(t){var n=this;if(t){var e=this.ids[t]||{},r=e.event,o=e.index;r&&Array.isArray(this.state[r])&&(this.state[r].splice(o,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){n.ids[t].event===r&&n.ids[t].index>o&&(n.ids[t].index=n.ids[t].index-1)})))}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t){for(var n,e,r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];if(Array.isArray(this.state[t]))try{for(var i=h(this.state[t]),u=i.next();!u.done;u=i.next()){var c=u.value;"function"==typeof c&&c.apply(void 0,y([],p(r),!1))}}catch(t){n={error:t}}finally{try{u&&!u.done&&(e=i.return)&&e.call(i)}finally{if(n)throw n.error}}},t}(),d=function(t){return function(n){var e,r,o={};try{for(var i=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.keys(n)),u=i.next();!u.done;u=i.next()){var c=u.value;o[c]=t(n[c],c)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o}},b=function(t){return n=void 0,e=void 0,o=function(){return function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=n.call(t,u)}catch(t){c=[6,t],r=0}finally{e=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){return setTimeout((function(){return n()}),t)}))];case 1:return n.sent(),[2]}}))},new((r=void 0)||(r=Promise))((function(t,i){function u(t){try{a(o.next(t))}catch(t){i(t)}}function c(t){try{a(o.throw(t))}catch(t){i(t)}}function a(n){var e;n.done?t(n.value):(e=n.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,c)}a((o=o.apply(n,e||[])).next())}));var n,e,r,o},g=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},m=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=n.call(t,u)}catch(t){c=[6,t],r=0}finally{e=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}},w=function(t,n){var e=!0,r=function(){e=!1},o=function(){return g(void 0,void 0,void 0,(function(){return m(this,(function(i){switch(i.label){case 0:return[4,t(r)];case 1:return i.sent(),[4,b(n)];case 2:return i.sent(),e?o():o=null,[2]}}))}))};return o(),r},x=function(t,n){var e=void 0===n?{}:n,r=e.checkTime,o=e.timeout;return new Promise((function(n,e){var i=w((function(){return g(void 0,void 0,void 0,(function(){var e;return m(this,(function(r){switch(r.label){case 0:return[4,t()];case 1:return(e=r.sent())&&(i(),n(e)),[2]}}))}))}),r||100);o&&setTimeout((function(){i(),e("timeout")}),o)}))},S=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},k=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=n.call(t,u)}catch(t){c=[6,t],r=0}finally{e=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}},A=function(){function t(){this.cache=[],this.running=!1}return t.prototype._run=function(t){var n=t.fn,e=t.promise;return S(this,void 0,void 0,(function(){var t,r;return k(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,n()];case 1:return t=o.sent(),e.resolve(t),[3,3];case 2:return r=o.sent(),e.reject(r),[3,3];case 3:return[2]}}))}))},t.prototype.run=function(){return S(this,void 0,void 0,(function(){var t;return k(this,(function(n){switch(n.label){case 0:return this.cache.length<1?(this.running=!1,[2]):(this.running=!0,"function"!=typeof(t=this.cache.shift()).fn?[3,2]:[4,this._run(t)]);case 1:n.sent(),n.label=2;case 2:return this.run(),[2]}}))}))},t.prototype.push=function(t){var n=this;return new Promise((function(e,r){n.cache.push({fn:t,promise:{resolve:e,reject:r}}),n.running||n.run()}))},Object.defineProperty(t.prototype,"length",{get:function(){return this.cache.length},enumerable:!1,configurable:!0}),t}(),T=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},P=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))};function j(t,n){var e,r=!0;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];e||(e=setTimeout((function(){r=!0,e=null}),n)),r&&(r=!1,t.apply(void 0,P([],T(o),!1)))}}var E=function(){function t(t){this._count=0,this.props=t}return Object.defineProperty(t.prototype,"count",{get:function(){return this._count},enumerable:!1,configurable:!0}),t.prototype.increment=function(){var t=this;clearTimeout(this.timeout),this.timeout=setTimeout((function(){return t.clear()}),this.props.resetTime),this._count=this._count+1,this._count>this.props.count&&this.props.cb()},t.prototype.clear=function(){this._count=0},t}(),M=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function O(t){for(var n=new Uint8Array(6*t.length/8),e=0,r=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(r=(r<<6)+M[t.charAt(i)],(e+=6)>=8){var u=r>>>(e-=8);n[o++]=255&u,r-=u<<=e}return n}var _=function(){function t(t){void 0===t&&(t=10),this.stack=[],this.len=10,this.point=0,this.len=t}return Object.defineProperty(t.prototype,"current",{get:function(){if(this.point<this.stack.length&&this.point>-1)return this.stack[this.point]},enumerable:!1,configurable:!0}),t.prototype.clear=function(){this.stack.length=0,this.point=0},t.prototype.backup=function(t){this.point>0&&this.stack.length>0&&(this.stack.splice(0,this.point),this.point=0),this.stack.unshift(t),this.stack.length>this.len&&this.stack.pop()},t.prototype.undo=function(){return this.point<this.stack.length-1&&(this.point+=1),this.current},t.prototype.redo=function(){return this.point>0&&(this.point-=1),this.current},t}(),R=function(){function t(t){var n=t.limit,e=void 0===n?10:n,r=t.onTimeout;this.limit=10,this.timeout=null,this.limit=e,this.onTimeout=r}return t.prototype.feed=function(){clearTimeout(this.timeout),this.init()},t.prototype.init=function(){var t=this;this.timeout=setTimeout((function(){return t.onTimeout()}),1e3*this.limit)},t.prototype.stop=function(){this.timeout&&clearTimeout(this.timeout)},t}(),L=function(){function t(t){this.config=t,this.step=(this.config.max-this.config.min)/(this.config.count-2)}return t.prototype.get=function(t){if(t<=this.config.min)return 1;if(t>=this.config.max)return this.config.count;for(var n=2,e=this.config.min+this.step;e<this.config.max+this.step;e+=this.step,n+=1)if(t<e)return n;return this.config.count},t}(),I=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},z=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},D=function(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return new Promise((function(e,r){t.apply(void 0,z(z([],I(n),!1),[function(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];t&&r(t),n.length<2?e(n[0]):e(z([],I(n),!1))}],!1))}))}},F=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},G=function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2))},U=function(t){return 180*t/Math.PI},q=function(t){return t*Math.PI/180},C=function(t){var n,e=t.w,r=t.h,o=U(Math.asin(r/Math.sqrt(Math.pow(e,2)+Math.pow(r,2))));return(n=e<=0?180-o:o>0?o:360+o)<-180&&(n+=360),n>180&&(n-=360),n};function X(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(r,o){return!(o>0&&G(e,r)<n||(e=t[o],0))}));var e}function B(t){var n,e,r=[0,0];try{for(var o=F(t),i=o.next();!i.done;i=o.next()){var u=i.value;Array.isArray(u)?(r[0]+=u[0],r[1]+=u[1]):(r[0]+=u.x,r[1]+=u.y)}}catch(t){n={error:t}}finally{try{i&&!i.done&&(e=o.return)&&e.call(o)}finally{if(n)throw n.error}}return{x:r[0]/t.length,y:r[1]/t.length}}var H=function(){function t(t){this._RegExpList=null,this.list=t}return t.prototype.getRegEXP=function(t){var n=t.replace("/","\\/").replace("*",".*");return new RegExp(n,"g")},t.prototype.include=function(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((function(n){return n.test(t)}))},t}(),K=function(t,n){void 0===n&&(n=Array);for(var e=t.map((function(t){return t.length})).reduce((function(t,n){return t+n}),0),r=new n(e),o=0,i=0,u=0;u<e;)o<t[i].length?(r[u]=t[i][o],o+=1,u+=1):(i+=1,o=0);return r},N=function(){function t(t){var n=(void 0===t?{}:t).size,e=void 0===n?5:n;this.size=5,this.cache={last:{count:0,value:0},current:{value:0,count:0}},this.size=e}return t.prototype.filter=function(t){return this.cache.current.count<1?(this.cache.current.value=t,this.cache.current.count=1,t):(this.updateLast(t),this.cache.current.value!==t?(this.cache.last.count>this.cache.current.count||this.cache.last.count>this.size)&&(this.cache.current.value=t,this.cache.current.count=1):this.cache.current.count+=1,this.cache.current.value)},t.prototype.updateLast=function(t){this.cache.last.value!==t?this.cache.last.count=1:this.cache.last.count+=1,this.cache.last.value=t},t}();return n})()));
1
+ !function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["pubo-utils"]=n():t["pubo-utils"]=n()}(this,(()=>(()=>{"use strict";var t={d:(n,e)=>{for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};t.r(n),t.d(n,{Base64Utils:()=>e,ContinuousTrigger:()=>M,Emitter:()=>d,HistoryStack:()=>R,Level:()=>I,RegExpList:()=>H,SensorDataFilter:()=>Q,SyncQueue:()=>A,WatchDog:()=>N,callbackToPromise:()=>D,concatArray:()=>K,debounce:()=>i,degrees:()=>U,filterKeyPoints:()=>X,getAngle:()=>C,getCenter:()=>B,getDistance:()=>G,hex2rgb:()=>a,loop:()=>x,radians:()=>q,random:()=>s,randomRangeNum:()=>f,sleep:()=>g,superFactory:()=>b,throttle:()=>O,waitFor:()=>S});var e={};t.r(e),t.d(e,{EncoderMap:()=>E,toUnit8Array:()=>_});var r=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},o=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},i=function(t,n,e){if(void 0===e&&(e=!1),e){var i,u=!0;return function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];u&&(t.apply(void 0,o([],r(e),!1)),u=!1),i&&clearTimeout(i),i=setTimeout((function(){return u=!0}),n)}}var a;return function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];a&&clearTimeout(a),a=setTimeout((function(){return t.apply(void 0,o([],r(e),!1))}),n)}},u=function(t){return parseInt(t.replace("#",""),16)},a=function(t){var n=("string"==typeof t?u(t):t).toString(2).padStart(24,"0");return[parseInt(n.slice(0,8),2),parseInt(n.slice(8,16),2),parseInt(n.slice(16,24),2)]},c=function(t){return"#"+[0,1,2].map((function(n){return t[n].toString(16)})).join("")},l=(function(){function t(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=u(t):Array.isArray(t)&&(this.int=u(c(t)))}t.prototype.getRgbArray=function(){return a(this.int)},Object.defineProperty(t.prototype,"rgb",{get:function(){return"rba(".concat(this.getRgbArray().join(", "),")")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hex",{get:function(){return c(this.getRgbArray())},enumerable:!1,configurable:!0}),t.prototype.toString=function(t){return void 0===t&&(t="hex"),"rgb"===t?this.rgb:this.hex}}(),function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}),s=function(t){void 0===t&&(t=8);var n=function(t){return Math.random().toString(32).slice(2,2+t)};if(t<=8)return n(t);for(var e="",r=0;r<=t;r+=8)e+=n(t-r>8?8:t-r);return e},f=function(t){var n=Math.abs(t[1]-t[0]);return Math.random()*n+Math.min.apply(Math,function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}([],l(t),!1))},h=function(){return h=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},h.apply(this,arguments)},p=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},y=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},v=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},d=function(){function t(){this.state={},this.ids={}}return t.prototype.on=function(t,n){if(this.state[t]||(this.state[t]=[]),"function"!=typeof n)throw new Error("第二个参数必须为function!");var e=this.state[t].push(n)-1,r=s(40);return this.ids[r]={event:t,index:e},r},t.prototype.cancel=function(t){var n=this;if(t){var e=this.ids[t]||{},r=e.event,o=e.index;r&&Array.isArray(this.state[r])&&(this.state[r].splice(o,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){n.ids[t].event===r&&n.ids[t].index>o&&(n.ids[t].index=n.ids[t].index-1)})))}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t){for(var n,e,r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];if(Array.isArray(this.state[t]))try{for(var i=p(this.state[t]),u=i.next();!u.done;u=i.next()){var a=u.value;"function"==typeof a&&a.apply(void 0,v([],y(r),!1))}}catch(t){n={error:t}}finally{try{u&&!u.done&&(e=i.return)&&e.call(i)}finally{if(n)throw n.error}}},t.prototype.clone=function(){return{state:h({},this.state),ids:h({},this.ids)}},t.prototype.restore=function(t){this.state=t.state,this.ids=t.ids},t}(),b=function(t){return function(n){var e,r,o={};try{for(var i=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.keys(n)),u=i.next();!u.done;u=i.next()){var a=u.value;o[a]=t(n[a],a)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o}},g=function(t){return n=void 0,e=void 0,o=function(){return function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){return setTimeout((function(){return n()}),t)}))];case 1:return n.sent(),[2]}}))},new((r=void 0)||(r=Promise))((function(t,i){function u(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(n){var e;n.done?t(n.value):(e=n.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,a)}c((o=o.apply(n,e||[])).next())}));var n,e,r,o},m=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,a)}c((r=r.apply(t,n||[])).next())}))},w=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},x=function(t,n){var e=!0,r=function(){e=!1},o=function(){return m(void 0,void 0,void 0,(function(){return w(this,(function(i){switch(i.label){case 0:return[4,t(r)];case 1:return i.sent(),[4,g(n)];case 2:return i.sent(),e?o():o=null,[2]}}))}))};return o(),r},S=function(t,n){var e=void 0===n?{}:n,r=e.checkTime,o=e.timeout;return new Promise((function(n,e){var i=x((function(){return m(void 0,void 0,void 0,(function(){var e;return w(this,(function(r){switch(r.label){case 0:return[4,t()];case 1:return(e=r.sent())&&(i(),n(e)),[2]}}))}))}),r||100);o&&setTimeout((function(){i(),e("timeout")}),o)}))},T=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,a)}c((r=r.apply(t,n||[])).next())}))},k=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},A=function(){function t(){this.cache=[],this.running=!1}return t.prototype._run=function(t){var n=t.fn,e=t.promise;return T(this,void 0,void 0,(function(){var t,r;return k(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,n()];case 1:return t=o.sent(),e.resolve(t),[3,3];case 2:return r=o.sent(),e.reject(r),[3,3];case 3:return[2]}}))}))},t.prototype.run=function(){return T(this,void 0,void 0,(function(){var t;return k(this,(function(n){switch(n.label){case 0:return this.cache.length<1?(this.running=!1,[2]):(this.running=!0,"function"!=typeof(t=this.cache.shift()).fn?[3,2]:[4,this._run(t)]);case 1:n.sent(),n.label=2;case 2:return this.run(),[2]}}))}))},t.prototype.push=function(t){var n=this;return new Promise((function(e,r){n.cache.push({fn:t,promise:{resolve:e,reject:r}}),n.running||n.run()}))},Object.defineProperty(t.prototype,"length",{get:function(){return this.cache.length},enumerable:!1,configurable:!0}),t}(),j=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},P=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))};function O(t,n){var e,r=!0;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];e||(e=setTimeout((function(){r=!0,e=null}),n)),r&&(r=!1,t.apply(void 0,P([],j(o),!1)))}}var M=function(){function t(t){this._count=0,this.props=t}return Object.defineProperty(t.prototype,"count",{get:function(){return this._count},enumerable:!1,configurable:!0}),t.prototype.increment=function(){var t=this;clearTimeout(this.timeout),this.timeout=setTimeout((function(){return t.clear()}),this.props.resetTime),this._count=this._count+1,this._count>this.props.count&&this.props.cb()},t.prototype.clear=function(){this._count=0},t}(),E=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function _(t){for(var n=new Uint8Array(6*t.length/8),e=0,r=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(r=(r<<6)+E[t.charAt(i)],(e+=6)>=8){var u=r>>>(e-=8);n[o++]=255&u,r-=u<<=e}return n}var R=function(){function t(t){void 0===t&&(t=10),this.stack=[],this.len=10,this.point=0,this.len=t}return Object.defineProperty(t.prototype,"current",{get:function(){if(this.point<this.stack.length&&this.point>-1)return this.stack[this.point]},enumerable:!1,configurable:!0}),t.prototype.clear=function(){this.stack.length=0,this.point=0},t.prototype.backup=function(t){this.point>0&&this.stack.length>0&&(this.stack.splice(0,this.point),this.point=0),this.stack.unshift(t),this.stack.length>this.len&&this.stack.pop()},t.prototype.undo=function(){return this.point<this.stack.length-1&&(this.point+=1),this.current},t.prototype.redo=function(){return this.point>0&&(this.point-=1),this.current},t}(),N=function(){function t(t){var n=t.limit,e=void 0===n?10:n,r=t.onTimeout;this.limit=10,this.timeout=null,this.limit=e,this.onTimeout=r}return t.prototype.feed=function(){clearTimeout(this.timeout),this.init()},t.prototype.init=function(){var t=this;this.timeout=setTimeout((function(){return t.onTimeout()}),1e3*this.limit)},t.prototype.stop=function(){this.timeout&&clearTimeout(this.timeout)},t}(),I=function(){function t(t){this.config=t,this.step=(this.config.max-this.config.min)/(this.config.count-2)}return t.prototype.get=function(t){if(t<=this.config.min)return 1;if(t>=this.config.max)return this.config.count;for(var n=2,e=this.config.min+this.step;e<this.config.max+this.step;e+=this.step,n+=1)if(t<e)return n;return this.config.count},t}(),L=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},z=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},D=function(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return new Promise((function(e,r){t.apply(void 0,z(z([],L(n),!1),[function(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];t&&r(t),n.length<2?e(n[0]):e(z([],L(n),!1))}],!1))}))}},F=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},G=function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2))},U=function(t){return 180*t/Math.PI},q=function(t){return t*Math.PI/180},C=function(t){var n,e=t.w,r=t.h,o=U(Math.asin(r/Math.sqrt(Math.pow(e,2)+Math.pow(r,2))));return(n=e<=0?180-o:o>0?o:360+o)<-180&&(n+=360),n>180&&(n-=360),n};function X(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(r,o){return!(o>0&&G(e,r)<n||(e=t[o],0))}));var e}function B(t){var n,e,r=[0,0];try{for(var o=F(t),i=o.next();!i.done;i=o.next()){var u=i.value;Array.isArray(u)?(r[0]+=u[0],r[1]+=u[1]):(r[0]+=u.x,r[1]+=u.y)}}catch(t){n={error:t}}finally{try{i&&!i.done&&(e=o.return)&&e.call(o)}finally{if(n)throw n.error}}return{x:r[0]/t.length,y:r[1]/t.length}}var H=function(){function t(t){this._RegExpList=null,this.list=t}return t.prototype.getRegEXP=function(t){var n=t.replace("/","\\/").replace("*",".*");return new RegExp(n,"g")},t.prototype.include=function(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((function(n){return n.test(t)}))},t}(),K=function(t,n){void 0===n&&(n=Array);for(var e=t.map((function(t){return t.length})).reduce((function(t,n){return t+n}),0),r=new n(e),o=0,i=0,u=0;u<e;)o<t[i].length?(r[u]=t[i][o],o+=1,u+=1):(i+=1,o=0);return r},Q=function(){function t(t){var n=void 0===t?{}:t,e=n.size,r=void 0===e?5:e,o=n.step,i=void 0===o?5:o,u=n.min,a=void 0===u?-1/0:u,c=n.max,l=void 0===c?1/0:c;this.tmp=[],this.count=0,this.value=NaN,this.size=r,this.step=i,this.min=a,this.max=l}return t.prototype.filter=function(t){return t<this.min||t>this.max||(this.tmp.push(t),this.old=this.calc(t)),this.old},t.prototype.calc=function(t){if(this.tmp.length<1)return t;this.tmp.length>this.size&&this.tmp.shift();var n=this.getMostNumberOfTmp(),e=n.res,r=n.dic;return e!==t&&Math.abs(e-t)>this.step?(this.value!==t?this.count=1:this.count+=1,this.value=t,this.count>r[e]?(this.tmp.length=0,this.tmp.push(t),t):e):(this.count=0,this.value=NaN,t)},t.prototype.getMostNumberOfTmp=function(){var t,n,e,r={},o=0;try{for(var i=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.tmp),u=i.next();!u.done;u=i.next()){var a=u.value;r[a]?r[a]+=1:r[a]=1,r[a]>o&&(o=r[a],e=a)}}catch(n){t={error:n}}finally{try{u&&!u.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return{res:e,dic:r}},t}();return n})()));
@@ -3,13 +3,20 @@ interface EmitterType {
3
3
  cancel: (id?: string) => void;
4
4
  emit: (event: string, ...args: any) => any;
5
5
  clear: () => void;
6
+ clone: () => any;
7
+ restore: (snapshot: any) => void;
6
8
  }
7
9
  export declare class Emitter implements EmitterType {
8
- private readonly state;
9
- private readonly ids;
10
+ private state;
11
+ private ids;
10
12
  on(event: string, func: any): string;
11
13
  cancel(id?: string): void;
12
14
  clear(): void;
13
15
  emit(event: string, ...args: any): void;
16
+ clone(): {
17
+ state: any;
18
+ ids: any;
19
+ };
20
+ restore(snapshot: any): void;
14
21
  }
15
22
  export {};
@@ -1,3 +1,13 @@
1
+ var __assign = this && this.__assign || function () {
2
+ __assign = Object.assign || function (t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
6
+ }
7
+ return t;
8
+ };
9
+ return __assign.apply(this, arguments);
10
+ };
1
11
  var __values = this && this.__values || function (o) {
2
12
  var s = typeof Symbol === "function" && Symbol.iterator,
3
13
  m = s && o[s],
@@ -119,6 +129,16 @@ var Emitter = /** @class */function () {
119
129
  }
120
130
  }
121
131
  };
132
+ Emitter.prototype.clone = function () {
133
+ return {
134
+ state: __assign({}, this.state),
135
+ ids: __assign({}, this.ids)
136
+ };
137
+ };
138
+ Emitter.prototype.restore = function (snapshot) {
139
+ this.state = snapshot.state;
140
+ this.ids = snapshot.ids;
141
+ };
122
142
  return Emitter;
123
143
  }();
124
144
  export { Emitter };
@@ -1,12 +1,19 @@
1
- /**
2
- * @description 过滤传感器类型的跳变数据
3
- */
4
1
  export declare class SensorDataFilter {
2
+ private readonly tmp;
5
3
  private readonly size;
6
- private readonly cache;
7
- constructor({ size }?: {
4
+ private readonly step;
5
+ private readonly min;
6
+ private readonly max;
7
+ private count;
8
+ private value;
9
+ private old;
10
+ constructor({ size, step, min, max, }?: {
8
11
  size?: number;
12
+ step?: number;
13
+ max?: number;
14
+ min?: number;
9
15
  });
10
16
  filter(n: number): number;
11
- private updateLast;
17
+ private calc;
18
+ private getMostNumberOfTmp;
12
19
  }
@@ -1,48 +1,118 @@
1
- /**
2
- * @description 过滤传感器类型的跳变数据
3
- */
1
+ var __values = this && this.__values || function (o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator,
3
+ m = s && o[s],
4
+ i = 0;
5
+ if (m) return m.call(o);
6
+ if (o && typeof o.length === "number") return {
7
+ next: function next() {
8
+ if (o && i >= o.length) o = void 0;
9
+ return {
10
+ value: o && o[i++],
11
+ done: !o
12
+ };
13
+ }
14
+ };
15
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
16
+ };
17
+ // 过滤跳变数据
4
18
  var SensorDataFilter = /** @class */function () {
5
19
  function SensorDataFilter(_a) {
6
20
  var _b = _a === void 0 ? {} : _a,
7
21
  _c = _b.size,
8
- size = _c === void 0 ? 5 : _c;
9
- this.size = 5;
10
- this.cache = {
11
- last: {
12
- count: 0,
13
- value: 0
14
- },
15
- current: {
16
- value: 0,
17
- count: 0
18
- }
19
- };
22
+ size = _c === void 0 ? 5 : _c,
23
+ _d = _b.step,
24
+ step = _d === void 0 ? 5 : _d,
25
+ _e = _b.min,
26
+ min = _e === void 0 ? -Infinity : _e,
27
+ _f = _b.max,
28
+ max = _f === void 0 ? Infinity : _f;
29
+ // 缓冲区
30
+ this.tmp = [];
31
+ // 与缓冲区不一致的值连续出现的次数 (不一致指的是与缓冲区中数量最多的数值不同且差值大于步长)
32
+ this.count = 0;
33
+ // 与缓冲区不一致的值
34
+ this.value = NaN;
20
35
  this.size = size;
36
+ this.step = step;
37
+ this.min = min;
38
+ this.max = max;
21
39
  }
22
40
  SensorDataFilter.prototype.filter = function (n) {
23
- if (this.cache.current.count < 1) {
24
- this.cache.current.value = n;
25
- this.cache.current.count = 1;
41
+ // 溢出范围的值将被忽略
42
+ if (n < this.min || n > this.max) {
43
+ return this.old;
44
+ }
45
+ this.tmp.push(n);
46
+ this.old = this.calc(n);
47
+ return this.old;
48
+ };
49
+ SensorDataFilter.prototype.calc = function (n) {
50
+ // 缓冲区没有值时直接返回当前值
51
+ if (this.tmp.length < 1) {
26
52
  return n;
27
53
  }
28
- this.updateLast(n);
29
- if (this.cache.current.value !== n) {
30
- if (this.cache.last.count > this.cache.current.count || this.cache.last.count > this.size) {
31
- this.cache.current.value = n;
32
- this.cache.current.count = 1;
54
+ if (this.tmp.length > this.size) {
55
+ this.tmp.shift();
56
+ }
57
+ var _a = this.getMostNumberOfTmp(),
58
+ res = _a.res,
59
+ dic = _a.dic;
60
+ // 当前值与缓冲区数量最多的值不一致且差值大于步长
61
+ if (res !== n && Math.abs(res - n) > this.step) {
62
+ // 累计跳变数据连续出现的次数
63
+ if (this.value !== n) {
64
+ this.count = 1;
65
+ } else {
66
+ this.count += 1;
67
+ }
68
+ this.value = n;
69
+ // 跳变数据出现次数已经大于缓冲区最多的数量,表示数据确实已经改变
70
+ if (this.count > dic[res]) {
71
+ this.tmp.length = 0;
72
+ this.tmp.push(n);
73
+ return n;
33
74
  }
34
75
  } else {
35
- this.cache.current.count += 1;
76
+ // 清除跳变数据缓存
77
+ this.count = 0;
78
+ this.value = NaN;
79
+ return n;
36
80
  }
37
- return this.cache.current.value;
81
+ return res;
38
82
  };
39
- SensorDataFilter.prototype.updateLast = function (n) {
40
- if (this.cache.last.value !== n) {
41
- this.cache.last.count = 1;
42
- } else {
43
- this.cache.last.count += 1;
83
+ SensorDataFilter.prototype.getMostNumberOfTmp = function () {
84
+ var e_1, _a;
85
+ var a = {};
86
+ var max = 0;
87
+ var res;
88
+ try {
89
+ for (var _b = __values(this.tmp), _c = _b.next(); !_c.done; _c = _b.next()) {
90
+ var item = _c.value;
91
+ if (!a[item]) {
92
+ a[item] = 1;
93
+ } else {
94
+ a[item] += 1;
95
+ }
96
+ if (a[item] > max) {
97
+ max = a[item];
98
+ res = item;
99
+ }
100
+ }
101
+ } catch (e_1_1) {
102
+ e_1 = {
103
+ error: e_1_1
104
+ };
105
+ } finally {
106
+ try {
107
+ if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
108
+ } finally {
109
+ if (e_1) throw e_1.error;
110
+ }
44
111
  }
45
- this.cache.last.value = n;
112
+ return {
113
+ res: res,
114
+ dic: a
115
+ };
46
116
  };
47
117
  return SensorDataFilter;
48
118
  }();
@@ -3,13 +3,20 @@ interface EmitterType {
3
3
  cancel: (id?: string) => void;
4
4
  emit: (event: string, ...args: any) => any;
5
5
  clear: () => void;
6
+ clone: () => any;
7
+ restore: (snapshot: any) => void;
6
8
  }
7
9
  export declare class Emitter implements EmitterType {
8
- private readonly state;
9
- private readonly ids;
10
+ private state;
11
+ private ids;
10
12
  on(event: string, func: any): string;
11
13
  cancel(id?: string): void;
12
14
  clear(): void;
13
15
  emit(event: string, ...args: any): void;
16
+ clone(): {
17
+ state: any;
18
+ ids: any;
19
+ };
20
+ restore(snapshot: any): void;
14
21
  }
15
22
  export {};
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
2
 
3
+ var __assign = this && this.__assign || function () {
4
+ __assign = Object.assign || function (t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
3
13
  var __values = this && this.__values || function (o) {
4
14
  var s = typeof Symbol === "function" && Symbol.iterator,
5
15
  m = s && o[s],
@@ -125,6 +135,16 @@ var Emitter = /** @class */function () {
125
135
  }
126
136
  }
127
137
  };
138
+ Emitter.prototype.clone = function () {
139
+ return {
140
+ state: __assign({}, this.state),
141
+ ids: __assign({}, this.ids)
142
+ };
143
+ };
144
+ Emitter.prototype.restore = function (snapshot) {
145
+ this.state = snapshot.state;
146
+ this.ids = snapshot.ids;
147
+ };
128
148
  return Emitter;
129
149
  }();
130
150
  exports.Emitter = Emitter;
@@ -1,12 +1,19 @@
1
- /**
2
- * @description 过滤传感器类型的跳变数据
3
- */
4
1
  export declare class SensorDataFilter {
2
+ private readonly tmp;
5
3
  private readonly size;
6
- private readonly cache;
7
- constructor({ size }?: {
4
+ private readonly step;
5
+ private readonly min;
6
+ private readonly max;
7
+ private count;
8
+ private value;
9
+ private old;
10
+ constructor({ size, step, min, max, }?: {
8
11
  size?: number;
12
+ step?: number;
13
+ max?: number;
14
+ min?: number;
9
15
  });
10
16
  filter(n: number): number;
11
- private updateLast;
17
+ private calc;
18
+ private getMostNumberOfTmp;
12
19
  }
@@ -1,54 +1,124 @@
1
1
  "use strict";
2
2
 
3
+ var __values = this && this.__values || function (o) {
4
+ var s = typeof Symbol === "function" && Symbol.iterator,
5
+ m = s && o[s],
6
+ i = 0;
7
+ if (m) return m.call(o);
8
+ if (o && typeof o.length === "number") return {
9
+ next: function next() {
10
+ if (o && i >= o.length) o = void 0;
11
+ return {
12
+ value: o && o[i++],
13
+ done: !o
14
+ };
15
+ }
16
+ };
17
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
18
+ };
3
19
  Object.defineProperty(exports, "__esModule", {
4
20
  value: true
5
21
  });
6
22
  exports.SensorDataFilter = void 0;
7
- /**
8
- * @description 过滤传感器类型的跳变数据
9
- */
23
+ // 过滤跳变数据
10
24
  var SensorDataFilter = /** @class */function () {
11
25
  function SensorDataFilter(_a) {
12
26
  var _b = _a === void 0 ? {} : _a,
13
27
  _c = _b.size,
14
- size = _c === void 0 ? 5 : _c;
15
- this.size = 5;
16
- this.cache = {
17
- last: {
18
- count: 0,
19
- value: 0
20
- },
21
- current: {
22
- value: 0,
23
- count: 0
24
- }
25
- };
28
+ size = _c === void 0 ? 5 : _c,
29
+ _d = _b.step,
30
+ step = _d === void 0 ? 5 : _d,
31
+ _e = _b.min,
32
+ min = _e === void 0 ? -Infinity : _e,
33
+ _f = _b.max,
34
+ max = _f === void 0 ? Infinity : _f;
35
+ // 缓冲区
36
+ this.tmp = [];
37
+ // 与缓冲区不一致的值连续出现的次数 (不一致指的是与缓冲区中数量最多的数值不同且差值大于步长)
38
+ this.count = 0;
39
+ // 与缓冲区不一致的值
40
+ this.value = NaN;
26
41
  this.size = size;
42
+ this.step = step;
43
+ this.min = min;
44
+ this.max = max;
27
45
  }
28
46
  SensorDataFilter.prototype.filter = function (n) {
29
- if (this.cache.current.count < 1) {
30
- this.cache.current.value = n;
31
- this.cache.current.count = 1;
47
+ // 溢出范围的值将被忽略
48
+ if (n < this.min || n > this.max) {
49
+ return this.old;
50
+ }
51
+ this.tmp.push(n);
52
+ this.old = this.calc(n);
53
+ return this.old;
54
+ };
55
+ SensorDataFilter.prototype.calc = function (n) {
56
+ // 缓冲区没有值时直接返回当前值
57
+ if (this.tmp.length < 1) {
32
58
  return n;
33
59
  }
34
- this.updateLast(n);
35
- if (this.cache.current.value !== n) {
36
- if (this.cache.last.count > this.cache.current.count || this.cache.last.count > this.size) {
37
- this.cache.current.value = n;
38
- this.cache.current.count = 1;
60
+ if (this.tmp.length > this.size) {
61
+ this.tmp.shift();
62
+ }
63
+ var _a = this.getMostNumberOfTmp(),
64
+ res = _a.res,
65
+ dic = _a.dic;
66
+ // 当前值与缓冲区数量最多的值不一致且差值大于步长
67
+ if (res !== n && Math.abs(res - n) > this.step) {
68
+ // 累计跳变数据连续出现的次数
69
+ if (this.value !== n) {
70
+ this.count = 1;
71
+ } else {
72
+ this.count += 1;
73
+ }
74
+ this.value = n;
75
+ // 跳变数据出现次数已经大于缓冲区最多的数量,表示数据确实已经改变
76
+ if (this.count > dic[res]) {
77
+ this.tmp.length = 0;
78
+ this.tmp.push(n);
79
+ return n;
39
80
  }
40
81
  } else {
41
- this.cache.current.count += 1;
82
+ // 清除跳变数据缓存
83
+ this.count = 0;
84
+ this.value = NaN;
85
+ return n;
42
86
  }
43
- return this.cache.current.value;
87
+ return res;
44
88
  };
45
- SensorDataFilter.prototype.updateLast = function (n) {
46
- if (this.cache.last.value !== n) {
47
- this.cache.last.count = 1;
48
- } else {
49
- this.cache.last.count += 1;
89
+ SensorDataFilter.prototype.getMostNumberOfTmp = function () {
90
+ var e_1, _a;
91
+ var a = {};
92
+ var max = 0;
93
+ var res;
94
+ try {
95
+ for (var _b = __values(this.tmp), _c = _b.next(); !_c.done; _c = _b.next()) {
96
+ var item = _c.value;
97
+ if (!a[item]) {
98
+ a[item] = 1;
99
+ } else {
100
+ a[item] += 1;
101
+ }
102
+ if (a[item] > max) {
103
+ max = a[item];
104
+ res = item;
105
+ }
106
+ }
107
+ } catch (e_1_1) {
108
+ e_1 = {
109
+ error: e_1_1
110
+ };
111
+ } finally {
112
+ try {
113
+ if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
114
+ } finally {
115
+ if (e_1) throw e_1.error;
116
+ }
50
117
  }
51
- this.cache.last.value = n;
118
+ return {
119
+ res: res,
120
+ dic: a
121
+ };
52
122
  };
53
123
  return SensorDataFilter;
54
124
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-utils",
3
- "version": "1.0.80",
3
+ "version": "1.0.85",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -18,5 +18,5 @@
18
18
  "engines": {
19
19
  "node": ">=8.0.0"
20
20
  },
21
- "gitHead": "29c92b8f53b85afb98d47d6557a99e4ce236615e"
21
+ "gitHead": "285a872798f8841f283dfc502ec10f8de6abf9e2"
22
22
  }