pubo-utils 1.0.149 → 1.0.158

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:()=>k,Emitter:()=>m,HistoryStack:()=>N,Level:()=>C,RegExpList:()=>Y,SensorDataFilter:()=>tt,StringSplit:()=>nt,SyncQueue:()=>O,WatchDog:()=>U,callbackToPromise:()=>L,debounce:()=>r,degrees:()=>X,filterKeyPoints:()=>H,getAngle:()=>q,getBestPointIndex:()=>W,getCenter:()=>K,getDistance:()=>F,getPositionTheta:()=>V,getRotate:()=>Q,getVectorTheta:()=>J,hex2rgb:()=>i,loop:()=>P,lower2camel:()=>et,orderByDistance:()=>G,radians:()=>$,random:()=>o,randomRangeNum:()=>u,sleep:()=>b,superFactory:()=>y,throttle:()=>M,waitFor:()=>S});var e={};t.r(e),t.d(e,{EncoderMap:()=>E,toUnit8Array:()=>I});var r=function(t,n,e){if(void 0===e&&(e=!1),e){var r,i=!0;return function(){i&&(t.apply(void 0,arguments),i=!1),r&&clearTimeout(r),r=setTimeout((function(){clearTimeout(r),i=!0,r=null}),n)}}var o;return function(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];o&&(clearTimeout(o),o=null),o=setTimeout((function(){t.apply(void 0,r),clearTimeout(o),r=null,o=null}),n)}},i=function(t){var n=("string"==typeof t?function(t){return parseInt(t.replace("#",""),16)}(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)]},o=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},u=function(t){var n=Math.abs(t[1]-t[0]);return Math.random()*n+Math.min.apply(Math,t)};function a(){}function s(t){var n=t();if(n&&n.then)return n.then(a)}var c="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function f(t,n,e){if(!t.s){if(e instanceof l){if(!e.s)return void(e.o=f.bind(null,t,n));1&n&&(n=e.s),e=e.v}if(e&&e.then)return void e.then(f.bind(null,t,n),f.bind(null,t,2));t.s=n,t.v=e;var r=t.o;r&&r(t)}}var l=function(){function t(){}return t.prototype.then=function(n,e){var r=new t,i=this.s;if(i){var o=1&i?n:e;if(o){try{f(r,1,o(this.v))}catch(t){f(r,2,t)}return r}return this}return this.o=function(t){try{var i=t.v;1&t.s?f(r,1,n?n(i):i):e?f(r,1,e(i)):f(r,2,i)}catch(t){f(r,2,t)}},r},t}();function h(t){return t instanceof l&&1&t.s}function v(){return v=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},v.apply(this,arguments)}function p(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e<n;e++)r[e]=t[e];return r}var m=function(){function t(){this.state={},this.ids={}}var n=t.prototype;return n.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=o(40);return this.ids[r]={event:t,index:e},r},n.cancel=function(t){var n=this;if(t){var e=this.ids[t]||{},r=e.event,i=e.index;r&&Array.isArray(this.state[r])&&(this.state[r].splice(i,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){n.ids[t].event===r&&n.ids[t].index>i&&(n.ids[t].index=n.ids[t].index-1)})))}else this.clear()},n.clear=function(){this.state.length=0},n.emit=function(t,n){if(Array.isArray(this.state[t]))for(var e,r=function(t,n){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,n){if(t){if("string"==typeof t)return p(t,n);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?p(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){e&&(t=e);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this.state[t]);!(e=r()).done;){var i=e.value;"function"==typeof i&&i(n)}},n.emitSync=function(t,n){try{var e=this;return(r=s((function(){if(Array.isArray(e.state[t]))return function(t){if(t&&t.then)return t.then(a)}(function(t,n,e){if("function"==typeof t[c]){var r,i,o,u=t[c]();if(function t(a){try{for(;!((r=u.next()).done||e&&e());)if((a=n(r.value))&&a.then){if(!h(a))return void a.then(t,o||(o=f.bind(null,i=new l,2)));a=a.v}i?f(i,1,a):i=a}catch(t){f(i||(i=new l),2,t)}}(),u.return){var a=function(t){try{r.done||u.return()}catch(t){}return t};if(i&&i.then)return i.then(a,(function(t){throw a(t)}));a()}return i}if(!("length"in t))throw new TypeError("Object is not iterable");for(var s=[],v=0;v<t.length;v++)s.push(t[v]);return function(t,n,e){var r,i,o=-1;return function u(a){try{for(;++o<t.length&&(!e||!e());)if((a=n(o))&&a.then){if(!h(a))return void a.then(u,i||(i=f.bind(null,r=new l,2)));a=a.v}r?f(r,1,a):r=a}catch(t){f(r||(r=new l),2,t)}}(),r}(s,(function(t){return n(s[t])}),e)}(e.state[t],(function(t){return s((function(){if("function"==typeof t)return function(t,n){return t&&t.then?t.then(a):Promise.resolve()}(t(n))}))})))})))&&r.then||(r=Promise.resolve(r)),r}catch(t){return Promise.reject(t)}var r},n.clone=function(){return{state:v({},this.state),ids:v({},this.ids)}},n.restore=function(t){this.state=t.state,this.ids=t.ids},t}(),y=function(t){return function(n){for(var e={},r=0,i=Object.keys(n);r<i.length;r++){var o=i[r];e[o]=t(n[o],o)}return e}};function d(){}var g,b=(g=function(t){return(n=new Promise((function(n){var e=setTimeout((function(){n(),clearTimeout(e),e=null}),t)})))&&n.then?n.then(d):Promise.resolve();var n},function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return Promise.resolve(g.apply(this,t))}catch(t){return Promise.reject(t)}});function w(){}function j(t,n,e){if(e)return n?n(t()):t();try{var r=Promise.resolve(t());return n?r.then(n):r}catch(t){return Promise.reject(t)}}var P=function(t,n){var e=!0,r=function(){e=!1},i=function(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];try{return Promise.resolve(t.apply(this,n))}catch(t){return Promise.reject(t)}}}((function(){return u=function(){return u=function(){e?i():(i=null,t=null,r=null,e=null,n=null)},(o=b(n))&&o.then||(o=Promise.resolve(o)),u?o.then(u):o;var o,u},(o=function(n,e){try{var r=j(t,w,i)}catch(t){return e(t)}var i;return r&&r.then?r.then(void 0,e):r}(0,(function(t){console.log(t)})))&&o.then?o.then(u):u();var o,u}));return i(),r},S=function(t,n){var e=void 0===n?{}:n,r=e.checkTime,i=e.timeout;return new Promise((function(n,e){var o,u=P((function(){return j(t,(function(e){e&&("function"==typeof u&&u(),o&&(clearTimeout(o),o=null),n(e),u=null,t=null,n=null)}))}),r||100);i&&(o=setTimeout((function(){"function"==typeof u&&u(),o&&(clearTimeout(o),o=null),e("timeout"),e=null,u=null,t=null}),i))}))};function x(t,n,e){return e?n?n(t):t:(t&&t.then||(t=Promise.resolve(t)),n?t.then(n):t)}function T(){}function A(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,"symbol"==typeof(i=function(t,n){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key))?i:String(i)),r)}var i}var O=function(){function t(){this.cache=[],this.running=!1,this.len=0}var n,e,r=t.prototype;return r._run=function(t){var n,e,r=t.fn,i=t.promise;try{return x((n=function(t,n){try{var e=function(t,n,e){try{var r=Promise.resolve(t());return n?r.then(n):r}catch(t){return Promise.reject(t)}}(r,(function(t){i.resolve(t)}))}catch(t){return n(t)}return e&&e.then?e.then(void 0,n):e}(0,(function(t){i.reject(t)})),e=function(){r=null,i=null},n&&n.then?n.then(e):e()))}catch(t){return Promise.reject(t)}},r.run=function(){try{var t=this;if(t.cache.length<1)return t.running=!1,x();t.running=!0;var n=t.cache.shift();return t.len-=1,x((e=function(){t.run()},(r=function(){if("function"==typeof n.fn)return(e=t._run(n))&&e.then?e.then(T):Promise.resolve();var e}())&&r.then?r.then(e):e()))}catch(t){return Promise.reject(t)}var e,r},r.push=function(t){var n=this;return this.len+=1,new Promise((function(e,r){n.cache.push({fn:t,promise:{resolve:e,reject:r}}),n.running||n.run()}))},n=t,(e=[{key:"length",get:function(){return this.len}}])&&A(n.prototype,e),Object.defineProperty(n,"prototype",{writable:!1}),t}();function M(t,n){var e,r=!0;return function(){for(var i=arguments.length,o=new Array(i),u=0;u<i;u++)o[u]=arguments[u];e||(e=setTimeout((function(){clearTimeout(e),r=!0,e=null}),n)),r&&(r=!1,t.apply(void 0,o)),o=null}}function _(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,"symbol"==typeof(i=function(t,n){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key))?i:String(i)),r)}var i}var k=function(){function t(t){this.timeout=void 0,this._count=0,this.props=void 0,this.props=t}var n,e,r=t.prototype;return r.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()},r.clear=function(){clearTimeout(this.timeout),this._count=0,this.timeout=0},n=t,(e=[{key:"count",get:function(){return this._count}}])&&_(n.prototype,e),Object.defineProperty(n,"prototype",{writable:!1}),t}(),E=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function I(t){for(var n=new Uint8Array(6*t.length/8),e=0,r=0,i=0,o=0;o<t.length&&i<n.length;o+=1)if(r=(r<<6)+E[t.charAt(o)],(e+=6)>=8){var u=r>>>(e-=8);n[i++]=255&u,r-=u<<=e}return n}function R(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,"symbol"==typeof(i=function(t,n){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key))?i:String(i)),r)}var i}var N=function(){function t(t){void 0===t&&(t=10),this.stack=[],this.len=10,this.point=0,this.len=t}var n,e,r=t.prototype;return r.clear=function(){this.stack.length=0,this.point=0},r.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()},r.undo=function(){return this.point<this.stack.length-1&&(this.point+=1),this.current},r.redo=function(){return this.point>0&&(this.point-=1),this.current},n=t,(e=[{key:"current",get:function(){if(this.point<this.stack.length&&this.point>-1)return this.stack[this.point]}}])&&R(n.prototype,e),Object.defineProperty(n,"prototype",{writable:!1}),t}(),U=function(){function t(t){var n=this,e=t.limit,r=void 0===e?10:e,i=t.onTimeout;this.onTimeout=void 0,this.timeout=null,this._time=void 0,this._time=1e3*r,this.onTimeout=function(){n.timeout&&(clearTimeout(n.timeout),n.timeout=null),i()}}var n=t.prototype;return n.feed=function(){this.init()},n.init=function(){clearTimeout(this.timeout),this.timeout=null,delete this.timeout,this.timeout=setTimeout(this.onTimeout,this._time)},n.stop=function(){this.timeout&&clearTimeout(this.timeout),delete this.timeout},t}(),C=function(){function t(t){this.config=void 0,this.step=void 0,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){return function(){for(var n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return new Promise((function(n,r){t.apply(void 0,e.concat([function(t){t&&r(t);for(var e=arguments.length,i=new Array(e>1?e-1:0),o=1;o<e;o++)i[o-1]=arguments[o];i.length<2?n(i[0]):n([].concat(i))}])),t=null}))}};function z(){return z=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},z.apply(this,arguments)}function D(t,n){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,n){if(t){if("string"==typeof t)return B(t,n);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?B(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){e&&(t=e);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function B(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e<n;e++)r[e]=t[e];return r}var F=function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2))},X=function(t){return 180*t/Math.PI},$=function(t){return t*Math.PI/180},q=function(t){var n=t.w,e=t.h;return X(Math.atan2(e,n))};function H(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(r,i){return!(i>0&&F(e,r)<n||(e=t[i],0))}));var e}function K(t){for(var n,e=[0,0],r=D(t);!(n=r()).done;){var i=n.value;Array.isArray(i)?(e[0]+=i[0],e[1]+=i[1]):(e[0]+=i.x,e[1]+=i.y)}return{x:e[0]/t.length,y:e[1]/t.length}}function Q(t,n){return[Math.cos(n)*t[0]-Math.sin(n)*t[1],Math.sin(n)*t[0]+Math.cos(n)*t[1]]}var V=function(t,n){var e={x:n.x-t.x,y:n.y-t.y};return Math.atan2(e.y,e.x)},W=function(t,n){if(t.length<2)return 0;for(var e,r=[],i=1/0,o=0,u=D(t);!(e=u()).done;){var a=e.value,s=F(a,n),c=V(n,a)-n.theta;i>s&&(i=s),r.push(z({},a,{index:o,distance:s,theta:c})),o+=1}var f=r.filter((function(t){return t.distance-i<.1})).sort((function(t,n){return t.theta-n.theta}));return f[0].index},G=function(t,n){void 0===n&&(n={x:0,y:0,theta:0});for(var e=n,r=[],i=[].concat(t);i.length>0;){var o=W(i,e);r.push(i[o]),e=i[o],i.splice(o,1)}return r},J=function(t,n){return Math.atan2(n.y,n.x)-Math.atan2(t.y,t.x)},Y=function(){function t(t){this.list=void 0,this._RegExpList=null,this.list=t}var n=t.prototype;return n.getRegEXP=function(t){var n=t.replace("/","\\/").replace("*",".*");return new RegExp(n)},n.include=function(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((function(n){return n.test(t)}))},t}();function Z(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e<n;e++)r[e]=t[e];return r}var tt=function(){function t(t){var n=void 0===t?{}:t,e=n.size,r=void 0===e?5:e,i=n.step,o=void 0===i?5:i,u=n.min,a=void 0===u?-1/0:u,s=n.max,c=void 0===s?1/0:s;this.tmp=[],this.size=void 0,this.step=void 0,this.min=void 0,this.max=void 0,this.count=0,this.value=NaN,this.old=void 0,this.size=r,this.step=o,this.min=a,this.max=c}var n=t.prototype;return n.filter=function(t){return t<this.min||t>this.max||(this.tmp.push(t),this.old=this.calc(t)),this.old},n.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)},n.getMostNumberOfTmp=function(){for(var t,n,e={},r=0,i=function(t,n){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,n){if(t){if("string"==typeof t)return Z(t,n);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?Z(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){e&&(t=e);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this.tmp);!(n=i()).done;){var o=n.value;e[o]?e[o]+=1:e[o]=1,e[o]>r&&(r=e[o],t=o)}return{res:t,dic:e}},t}(),nt=function(){function t(t){this._splitSymbol=void 0,this._cache="",this._splitSymbol=t}return t.prototype.split=function(t){var n=(this._cache+t).split(this._splitSymbol);return this._cache=n.splice(n.length-1,1)[0],n},t}(),et=function(t){return t.split("_").map((function(t,n){return n>0?t.slice(0,1).toUpperCase()+t.slice(1):t})).join("")};return n})()));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.PuboUtils=e():t.PuboUtils=e()}(this,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Base64Utils:()=>i,ContinuousTrigger:()=>f,Emitter:()=>h,HistoryStack:()=>y,Level:()=>T,RegExpList:()=>I,SensorDataFilter:()=>N,StringSplit:()=>L,SyncQueue:()=>p,WatchDog:()=>x,callbackToPromise:()=>b,debounce:()=>s,degrees:()=>M,filterKeyPoints:()=>v,getAngle:()=>P,getBestPointIndex:()=>j,getCenter:()=>S,getDistance:()=>w,getPositionTheta:()=>A,getRotate:()=>k,getVectorTheta:()=>R,hex2rgb:()=>n,loop:()=>a,lower2camel:()=>O,orderByDistance:()=>E,radians:()=>_,random:()=>o,randomRangeNum:()=>r,sleep:()=>l,superFactory:()=>c,throttle:()=>m,waitFor:()=>u});var i={};t.r(i),t.d(i,{EncoderMap:()=>g,toUnit8Array:()=>d});const s=(t,e,i=!1)=>{if(i){let i,s=!0;return(...n)=>{s&&(t(...n),s=!1),i&&clearTimeout(i),i=setTimeout((()=>{clearTimeout(i),s=!0,i=null}),e)}}{let i;return(...s)=>{i&&(clearTimeout(i),i=null),i=setTimeout((()=>{t(...s),clearTimeout(i),s=null,i=null}),e)}}},n=t=>{let e;e="string"==typeof t?(t=>parseInt(t.replace("#",""),16))(t):t;const i=e.toString(2).padStart(24,"0");return[parseInt(i.slice(0,8),2),parseInt(i.slice(8,16),2),parseInt(i.slice(16,24),2)]},o=(t=8)=>{const e=t=>Math.random().toString(32).slice(2,2+t);if(t<=8)return e(t);let i="";for(let s=0;s<=t;s+=8)i+=e(t-s>8?8:t-s);return i},r=t=>{const e=Math.abs(t[1]-t[0]);return Math.random()*e+Math.min(...t)};class h{state={};ids={};on(t,e){if(this.state[t]||(this.state[t]=[]),"function"!=typeof e)throw new Error("第二个参数必须为function!");const i=this.state[t].push(e)-1,s=o(40);return this.ids[s]={event:t,index:i},s}cancel(t){if(!t)return void this.clear();const{event:e,index:i}=this.ids[t]||{};e&&Array.isArray(this.state[e])&&(this.state[e].splice(i,1),delete this.ids[t],Object.keys(this.ids).forEach((t=>{this.ids[t].event===e&&this.ids[t].index>i&&(this.ids[t].index=this.ids[t].index-1)})))}clear(){this.state.length=0}emit(t,e){if(Array.isArray(this.state[t]))for(const i of this.state[t])"function"==typeof i&&i(e)}async emitSync(t,e){if(Array.isArray(this.state[t]))for(const i of this.state[t])"function"==typeof i&&await i(e)}clone(){return{state:{...this.state},ids:{...this.ids}}}restore(t){this.state=t.state,this.ids=t.ids}}const c=t=>e=>{const i={};for(const s of Object.keys(e))i[s]=t(e[s],s);return i},l=async t=>{await new Promise((e=>{let i=setTimeout((()=>{e(),clearTimeout(i),i=null}),t)}))},a=(t,e)=>{let i=!0,s=()=>{i=!1},n=async()=>{try{await t()}catch(t){console.log(t)}await l(e),i?n():(n=null,t=null,s=null,i=null,e=null)};return n(),s},u=(t,{checkTime:e,timeout:i}={})=>new Promise(((s,n)=>{let o,r=a((async()=>{const e=await t();e&&("function"==typeof r&&r(),o&&(clearTimeout(o),o=null),s(e),r=null,t=null,s=null)}),e||100);i&&(o=setTimeout((()=>{"function"==typeof r&&r(),o&&(clearTimeout(o),o=null),n("timeout"),n=null,r=null,t=null}),i))}));class p{cache=[];running=!1;len=0;async _run({fn:t,promise:e}){try{const i=await t();e.resolve(i)}catch(t){e.reject(t)}t=null,e=null}async run(){if(this.cache.length<1)return void(this.running=!1);this.running=!0;const t=this.cache.shift();this.len-=1,"function"==typeof t.fn&&await this._run(t),this.run()}push(t){return this.len+=1,new Promise(((e,i)=>{this.cache.push({fn:t,promise:{resolve:e,reject:i}}),this.running||this.run()}))}get length(){return this.len}}function m(t,e){const i=new p;let s;return(...n)=>{if(s=n,!(i.length>0))return i.push((async()=>{await l(e),await t(...s),s=null}))}}class f{timeout;_count=0;props;constructor(t){this.props=t}get count(){return this._count}increment(){clearTimeout(this.timeout),this.timeout=setTimeout((()=>this.clear()),this.props.resetTime),this._count=this._count+1,this._count>this.props.count&&this.props.cb()}clear(){clearTimeout(this.timeout),this._count=0,this.timeout=0}}const g=function(){const t={};for(let e=0;e<64;e++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;return t}();function d(t){const e=new Uint8Array(6*t.length/8);let i=0,s=0,n=0;for(let o=0;o<t.length&&n<e.length;o+=1)if(s=(s<<6)+g[t.charAt(o)],i+=6,i>=8){i-=8;let t=s>>>i;e[n++]=255&t,t<<=i,s-=t}return e}class y{stack=[];len=10;point=0;constructor(t=10){this.len=t}get current(){if(this.point<this.stack.length&&this.point>-1)return this.stack[this.point]}clear(){this.stack.length=0,this.point=0}backup(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()}undo(){return this.point<this.stack.length-1&&(this.point+=1),this.current}redo(){return this.point>0&&(this.point-=1),this.current}}class x{onTimeout;timeout=null;_time;constructor({limit:t=10,onTimeout:e}){this._time=1e3*t,this.onTimeout=()=>{this.timeout&&(clearTimeout(this.timeout),this.timeout=null),e()}}feed(){this.init()}init(){clearTimeout(this.timeout),this.timeout=null,delete this.timeout,this.timeout=setTimeout(this.onTimeout,this._time)}stop(){this.timeout&&clearTimeout(this.timeout),delete this.timeout}}class T{config;step;constructor(t){this.config=t,this.step=(this.config.max-this.config.min)/(this.config.count-2)}get(t){if(t<=this.config.min)return 1;if(t>=this.config.max)return this.config.count;for(let e=2,i=this.config.min+this.step;i<this.config.max+this.step;i+=this.step,e+=1)if(t<i)return e;return this.config.count}}const b=t=>(...e)=>new Promise(((i,s)=>{t(...e,((t,...e)=>{t&&s(t),e.length<2?i(e[0]):i([...e])})),t=null})),w=(t,e)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),M=t=>180*t/Math.PI,_=t=>t*Math.PI/180,P=({w:t,h:e})=>M(Math.atan2(e,t));function v(t,e=.5){if(t.length<3||e<=0)return t;let i;return t.filter(((s,n)=>!(n>0&&w(i,s)<e||(i=t[n],0))))}function S(t){const e=[0,0];for(const i of t)Array.isArray(i)?(e[0]+=i[0],e[1]+=i[1]):(e[0]+=i.x,e[1]+=i.y);return{x:e[0]/t.length,y:e[1]/t.length}}function k(t,e){return[Math.cos(e)*t[0]-Math.sin(e)*t[1],Math.sin(e)*t[0]+Math.cos(e)*t[1]]}const A=(t,e)=>{const i={x:e.x-t.x,y:e.y-t.y};return Math.atan2(i.y,i.x)},j=(t,e)=>{if(t.length<2)return 0;const i=[];let s=1/0,n=0;for(const o of t){const t=w(o,e),r=A(e,o)-e.theta;s>t&&(s=t),i.push({...o,index:n,distance:t,theta:r}),n+=1}return i.filter((t=>t.distance-s<.1)).sort(((t,e)=>t.theta-e.theta))[0].index},E=(t,e={x:0,y:0,theta:0})=>{let i=e;const s=[],n=[...t];for(;n.length>0;){const t=j(n,i);s.push(n[t]),i=n[t],n.splice(t,1)}return s},R=(t,e)=>Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x),O=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join("");class I{list;_RegExpList=null;constructor(t){this.list=t}getRegEXP(t){const e=t.replace("/","\\/").replace("*",".*");return new RegExp(e)}include(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((e=>e.test(t)))}}class N{tmp=[];size;step;min;max;count=0;value=NaN;old;constructor({size:t=5,step:e=5,min:i=-1/0,max:s=1/0}={}){this.size=t,this.step=e,this.min=i,this.max=s}filter(t){return t<this.min||t>this.max||(this.tmp.push(t),this.old=this.calc(t)),this.old}calc(t){if(this.tmp.length<1)return t;this.tmp.length>this.size&&this.tmp.shift();const{res:e,dic:i}=this.getMostNumberOfTmp();return e!==t&&Math.abs(e-t)>this.step?(this.value!==t?this.count=1:this.count+=1,this.value=t,this.count>i[e]?(this.tmp.length=0,this.tmp.push(t),t):e):(this.count=0,this.value=NaN,t)}getMostNumberOfTmp(){const t={};let e,i=0;for(const s of this.tmp)t[s]?t[s]+=1:t[s]=1,t[s]>i&&(i=t[s],e=s);return{res:e,dic:t}}}class L{_splitSymbol;_cache="";constructor(t){this._splitSymbol=t}split(t){const e=(this._cache+t).split(this._splitSymbol);return this._cache=e.splice(e.length-1,1)[0],e}}return e})()));
@@ -1,11 +1,11 @@
1
- export var EncoderMap = function () {
2
- var S = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
3
- var e = {};
4
- for (var i = 0; i < 64; i++) {
5
- e[S.charAt(i)] = i;
6
- }
7
- return e;
8
- }();
1
+ export const EncoderMap = (function () {
2
+ const S = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
3
+ const e = {};
4
+ for (let i = 0; i < 64; i++) {
5
+ e[S.charAt(i)] = i;
6
+ }
7
+ return e;
8
+ })();
9
9
  /**
10
10
  * base64 转Uint8Array
11
11
  * @param input base64 字符串
@@ -13,29 +13,29 @@ export var EncoderMap = function () {
13
13
  * base64 6位的二进制, Uint8Array 8位的二进制,整体原理就是将 base64 的每个字符转成2进制然后拼接,再按每个八位为一个单位地取出
14
14
  */
15
15
  export function toUnit8Array(input) {
16
- var output = new Uint8Array(input.length * 6 / 8);
17
- // 当前二进制字符长度
18
- var l = 0;
19
- // 二进制字符缓存值(格式为10进制)
20
- var b = 0;
21
- // Uint8Array 的指针
22
- var j = 0;
23
- for (var x = 0; x < input.length && j < output.length; x += 1) {
24
- b = (b << 6) + EncoderMap[input.charAt(x)];
25
- // 为什么是6? base64 为64个字符,也就是 2^6,用二进制表示就是6位
26
- l += 6;
27
- // 为什么是8? Uint8Array 是八位的二进制
28
- if (l >= 8) {
29
- // 取了前八位后剩余长度
30
- l -= 8;
31
- // 前八位的值
32
- var c = b >>> l;
33
- output[j++] = c & 0xff;
34
- // 再将右移的值左移回来,除了前八位不变,后面的皆为0
35
- c = c << l;
36
- // 通过减法得到第八位之后的值
37
- b = b - c;
16
+ const output = new Uint8Array((input.length * 6) / 8);
17
+ // 当前二进制字符长度
18
+ let l = 0;
19
+ // 二进制字符缓存值(格式为10进制)
20
+ let b = 0;
21
+ // Uint8Array 的指针
22
+ let j = 0;
23
+ for (let x = 0; x < input.length && j < output.length; x += 1) {
24
+ b = (b << 6) + EncoderMap[input.charAt(x)];
25
+ // 为什么是6? base64 为64个字符,也就是 2^6,用二进制表示就是6位
26
+ l += 6;
27
+ // 为什么是8? Uint8Array 是八位的二进制
28
+ if (l >= 8) {
29
+ // 取了前八位后剩余长度
30
+ l -= 8;
31
+ // 前八位的值
32
+ let c = b >>> l;
33
+ output[j++] = c & 0xff;
34
+ // 再将右移的值左移回来,除了前八位不变,后面的皆为0
35
+ c = c << l;
36
+ // 通过减法得到第八位之后的值
37
+ b = b - c;
38
+ }
38
39
  }
39
- }
40
- return output;
41
- }
40
+ return output;
41
+ }
@@ -1,14 +1,5 @@
1
1
  export declare const hex2rgb: (n: number | string) => [number, number, number];
2
- export declare const rgb2hex: (color: [
3
- number,
4
- number,
5
- number
6
- ] | [
7
- number,
8
- number,
9
- number,
10
- number
11
- ]) => string;
2
+ export declare const rgb2hex: (color: [number, number, number] | [number, number, number, number]) => string;
12
3
  export declare class ColorUtils {
13
4
  int: number;
14
5
  constructor(n: number | string | [number, number, number]);
package/es/color/utils.js CHANGED
@@ -1,62 +1,47 @@
1
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
2
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
3
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
4
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
- var str2int = function str2int(str) {
6
- return parseInt(str.replace('#', ''), 16);
7
- };
8
- export var hex2rgb = function hex2rgb(n) {
9
- var v;
10
- if (typeof n === 'string') {
11
- v = str2int(n);
12
- } else {
13
- v = n;
14
- }
15
- var str = v.toString(2).padStart(24, '0');
16
- var r = parseInt(str.slice(0, 8), 2);
17
- var g = parseInt(str.slice(8, 16), 2);
18
- var b = parseInt(str.slice(16, 24), 2);
19
- return [r, g, b];
1
+ const str2int = (str) => parseInt(str.replace('#', ''), 16);
2
+ export const hex2rgb = (n) => {
3
+ let v;
4
+ if (typeof n === 'string') {
5
+ v = str2int(n);
6
+ }
7
+ else {
8
+ v = n;
9
+ }
10
+ const str = v.toString(2).padStart(24, '0');
11
+ const r = parseInt(str.slice(0, 8), 2);
12
+ const g = parseInt(str.slice(8, 16), 2);
13
+ const b = parseInt(str.slice(16, 24), 2);
14
+ return [r, g, b];
20
15
  };
21
- export var rgb2hex = function rgb2hex(color) {
22
- return '#' + [0, 1, 2].map(function (i) {
23
- return color[i].toString(16);
24
- }).join('');
16
+ export const rgb2hex = (color) => {
17
+ return '#' + [0, 1, 2].map((i) => color[i].toString(16)).join('');
25
18
  };
26
- export var ColorUtils = /*#__PURE__*/function () {
27
- function ColorUtils(n) {
28
- this["int"] = void 0;
29
- if (typeof n === 'number') {
30
- this["int"] = n;
31
- } else if (typeof n === 'string') {
32
- this["int"] = str2int(n);
33
- } else if (Array.isArray(n)) {
34
- this["int"] = str2int(rgb2hex(n));
19
+ export class ColorUtils {
20
+ int;
21
+ constructor(n) {
22
+ if (typeof n === 'number') {
23
+ this.int = n;
24
+ }
25
+ else if (typeof n === 'string') {
26
+ this.int = str2int(n);
27
+ }
28
+ else if (Array.isArray(n)) {
29
+ this.int = str2int(rgb2hex(n));
30
+ }
35
31
  }
36
- }
37
- var _proto = ColorUtils.prototype;
38
- _proto.getRgbArray = function getRgbArray() {
39
- return hex2rgb(this["int"]);
40
- };
41
- _proto.toString = function toString(type) {
42
- if (type === void 0) {
43
- type = 'hex';
32
+ getRgbArray() {
33
+ return hex2rgb(this.int);
44
34
  }
45
- if (type === 'rgb') {
46
- return this.rgb;
35
+ get rgb() {
36
+ return `rba(${this.getRgbArray().join(', ')})`;
47
37
  }
48
- return this.hex;
49
- };
50
- _createClass(ColorUtils, [{
51
- key: "rgb",
52
- get: function get() {
53
- return "rba(" + this.getRgbArray().join(', ') + ")";
38
+ get hex() {
39
+ return rgb2hex(this.getRgbArray());
54
40
  }
55
- }, {
56
- key: "hex",
57
- get: function get() {
58
- return rgb2hex(this.getRgbArray());
41
+ toString(type = 'hex') {
42
+ if (type === 'rgb') {
43
+ return this.rgb;
44
+ }
45
+ return this.hex;
59
46
  }
60
- }]);
61
- return ColorUtils;
62
- }();
47
+ }
@@ -1,40 +1,35 @@
1
- export var debounce = function debounce(cb, time, first) {
2
- if (first === void 0) {
3
- first = false;
4
- }
5
- if (first) {
6
- var shouldRun = true;
7
- var t;
8
- return function () {
9
- if (shouldRun) {
10
- cb.apply(void 0, arguments);
11
- shouldRun = false;
12
- }
13
- if (t) {
14
- clearTimeout(t);
15
- }
16
- t = setTimeout(function () {
17
- clearTimeout(t);
18
- shouldRun = true;
19
- t = null;
20
- }, time);
21
- };
22
- } else {
23
- var _t;
24
- return function () {
25
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
26
- args[_key] = arguments[_key];
27
- }
28
- if (_t) {
29
- clearTimeout(_t);
30
- _t = null;
31
- }
32
- _t = setTimeout(function () {
33
- cb.apply(void 0, args);
34
- clearTimeout(_t);
35
- args = null;
36
- _t = null;
37
- }, time);
38
- };
39
- }
40
- };
1
+ export const debounce = (cb, time, first = false) => {
2
+ if (first) {
3
+ let shouldRun = true;
4
+ let t;
5
+ return (...args) => {
6
+ if (shouldRun) {
7
+ cb(...args);
8
+ shouldRun = false;
9
+ }
10
+ if (t) {
11
+ clearTimeout(t);
12
+ }
13
+ t = setTimeout(() => {
14
+ clearTimeout(t);
15
+ shouldRun = true;
16
+ t = null;
17
+ }, time);
18
+ };
19
+ }
20
+ else {
21
+ let t;
22
+ return (...args) => {
23
+ if (t) {
24
+ clearTimeout(t);
25
+ t = null;
26
+ }
27
+ t = setTimeout(() => {
28
+ cb(...args);
29
+ clearTimeout(t);
30
+ args = null;
31
+ t = null;
32
+ }, time);
33
+ };
34
+ }
35
+ };