pubo-utils 1.0.157 → 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,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["pubo-utils"]=e():t["pubo-utils"]=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:()=>c,HistoryStack:()=>y,Level:()=>T,RegExpList:()=>I,SensorDataFilter:()=>N,StringSplit:()=>L,SyncQueue:()=>p,WatchDog:()=>x,callbackToPromise:()=>b,debounce:()=>s,degrees:()=>_,filterKeyPoints:()=>S,getAngle:()=>v,getBestPointIndex:()=>j,getCenter:()=>k,getDistance:()=>M,getPositionTheta:()=>A,getRotate:()=>P,getVectorTheta:()=>R,hex2rgb:()=>n,loop:()=>u,lower2camel:()=>O,orderByDistance:()=>E,radians:()=>w,random:()=>o,randomRangeNum:()=>r,sleep:()=>l,superFactory:()=>h,throttle:()=>m,waitFor:()=>a});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 c{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 h=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)}))},u=(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},a=(t,{checkTime:e,timeout:i}={})=>new Promise(((s,n)=>{let o,r=u((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){let i,s=!0;return(...n)=>{i||(i=setTimeout((()=>{clearTimeout(i),s=!0,i=null}),e)),s&&(s=!1,t(...n)),n=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})),M=(t,e)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),_=t=>180*t/Math.PI,w=t=>t*Math.PI/180,v=({w:t,h:e})=>_(Math.atan2(e,t));function S(t,e=.5){if(t.length<3||e<=0)return t;let i;return t.filter(((s,n)=>!(n>0&&M(i,s)<e||(i=t[n],0))))}function k(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 P(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=M(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
+ !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,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]);
@@ -17,7 +17,7 @@ type WaitForBool = () => boolean | Promise<boolean>;
17
17
  * @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
18
18
  */
19
19
  export declare const waitFor: (bool: WaitForBool, { checkTime, timeout }?: {
20
- checkTime?: number | undefined;
21
- timeout?: number | undefined;
20
+ checkTime?: number;
21
+ timeout?: number;
22
22
  }) => Promise<unknown>;
23
23
  export {};
@@ -1 +1 @@
1
- export declare function throttle(cb: any, time: number): (...args: any[]) => void;
1
+ export declare function throttle(cb: any, time: number): (...args: any[]) => Promise<unknown> | undefined;
@@ -1,18 +1,17 @@
1
+ import { SyncQueue } from '../queue';
2
+ import { sleep } from '../sleep';
1
3
  export function throttle(cb, time) {
2
- let t;
3
- let onOff = true;
4
+ const queue = new SyncQueue();
5
+ let payload;
4
6
  return (...args) => {
5
- if (!t) {
6
- t = setTimeout(() => {
7
- clearTimeout(t);
8
- onOff = true;
9
- t = null;
10
- }, time);
7
+ payload = args;
8
+ if (queue.length > 0) {
9
+ return;
11
10
  }
12
- if (onOff) {
13
- onOff = false;
14
- cb(...args);
15
- }
16
- args = null;
11
+ return queue.push(async () => {
12
+ await sleep(time);
13
+ await cb(...payload);
14
+ payload = null;
15
+ });
17
16
  };
18
17
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toUnit8Array = exports.EncoderMap = void 0;
3
+ exports.EncoderMap = void 0;
4
+ exports.toUnit8Array = toUnit8Array;
4
5
  exports.EncoderMap = (function () {
5
6
  const S = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
6
7
  const e = {};
@@ -42,4 +43,3 @@ function toUnit8Array(input) {
42
43
  }
43
44
  return output;
44
45
  }
45
- exports.toUnit8Array = toUnit8Array;
@@ -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]);
@@ -17,7 +17,7 @@ type WaitForBool = () => boolean | Promise<boolean>;
17
17
  * @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
18
18
  */
19
19
  export declare const waitFor: (bool: WaitForBool, { checkTime, timeout }?: {
20
- checkTime?: number | undefined;
21
- timeout?: number | undefined;
20
+ checkTime?: number;
21
+ timeout?: number;
22
22
  }) => Promise<unknown>;
23
23
  export {};
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVectorTheta = exports.orderByDistance = exports.getBestPointIndex = exports.getPositionTheta = exports.getRotate = exports.getCenter = exports.filterKeyPoints = exports.getAngle = exports.radians = exports.degrees = exports.getDistance = void 0;
3
+ exports.getVectorTheta = exports.orderByDistance = exports.getBestPointIndex = exports.getPositionTheta = exports.getAngle = exports.radians = exports.degrees = exports.getDistance = void 0;
4
+ exports.filterKeyPoints = filterKeyPoints;
5
+ exports.getCenter = getCenter;
6
+ exports.getRotate = getRotate;
4
7
  // 获取两点的距离
5
8
  const getDistance = (a, b) => {
6
9
  return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
@@ -35,7 +38,6 @@ function filterKeyPoints(list, len = 0.5) {
35
38
  return true;
36
39
  });
37
40
  }
38
- exports.filterKeyPoints = filterKeyPoints;
39
41
  // 获取中心点坐标
40
42
  function getCenter(list) {
41
43
  const tmp = [0, 0];
@@ -51,14 +53,12 @@ function getCenter(list) {
51
53
  }
52
54
  return { x: tmp[0] / list.length, y: tmp[1] / list.length };
53
55
  }
54
- exports.getCenter = getCenter;
55
56
  // 2D旋转
56
57
  function getRotate(data, theta) {
57
58
  const x = Math.cos(theta) * data[0] - Math.sin(theta) * data[1];
58
59
  const y = Math.sin(theta) * data[0] + Math.cos(theta) * data[1];
59
60
  return [x, y];
60
61
  }
61
- exports.getRotate = getRotate;
62
62
  // 获取A点到B点的方向角
63
63
  const getPositionTheta = (a, b) => {
64
64
  const vector = { x: b.x - a.x, y: b.y - a.y };
@@ -1 +1 @@
1
- export declare function throttle(cb: any, time: number): (...args: any[]) => void;
1
+ export declare function throttle(cb: any, time: number): (...args: any[]) => Promise<unknown> | undefined;
@@ -1,22 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throttle = void 0;
3
+ exports.throttle = throttle;
4
+ const queue_1 = require("../queue");
5
+ const sleep_1 = require("../sleep");
4
6
  function throttle(cb, time) {
5
- let t;
6
- let onOff = true;
7
+ const queue = new queue_1.SyncQueue();
8
+ let payload;
7
9
  return (...args) => {
8
- if (!t) {
9
- t = setTimeout(() => {
10
- clearTimeout(t);
11
- onOff = true;
12
- t = null;
13
- }, time);
14
- }
15
- if (onOff) {
16
- onOff = false;
17
- cb(...args);
10
+ payload = args;
11
+ if (queue.length > 0) {
12
+ return;
18
13
  }
19
- args = null;
14
+ return queue.push(async () => {
15
+ await (0, sleep_1.sleep)(time);
16
+ await cb(...payload);
17
+ payload = null;
18
+ });
20
19
  };
21
20
  }
22
- exports.throttle = throttle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-utils",
3
- "version": "1.0.157",
3
+ "version": "1.0.158",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "engines": {
19
19
  "node": ">=8.0.0"
20
20
  },
21
- "gitHead": "600ac18384c1b657522eee9f2c80dba805443de3",
21
+ "gitHead": "3d5dad6acb147bf7a844a51c348036968f9a33dc",
22
22
  "devDependencies": {
23
23
  "@babel/cli": "^7.10.1",
24
24
  "@babel/core": "^7.10.2",