pubo-utils 1.0.202 → 1.0.206

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.
Files changed (72) hide show
  1. package/dist/pubo-utils.js +1 -1
  2. package/es/base64/index.d.ts +2 -3
  3. package/es/base64/index.js +6 -9
  4. package/es/buf.d.ts +2 -2
  5. package/es/buf.js +11 -12
  6. package/es/color/utils.js +6 -11
  7. package/es/debounce/index.d.ts +3 -1
  8. package/es/debounce/index.js +2 -6
  9. package/es/emitter/index.d.ts +18 -16
  10. package/es/emitter/index.js +11 -12
  11. package/es/filter/sensor.d.ts +4 -9
  12. package/es/filter/sensor.js +15 -23
  13. package/es/fp/index.d.ts +20 -15
  14. package/es/fp/index.js +6 -4
  15. package/es/loop/index.d.ts +4 -4
  16. package/es/loop/index.js +4 -9
  17. package/es/math/geometry.js +3 -4
  18. package/es/math/utm.d.ts +1 -1
  19. package/es/math/utm.js +1 -2
  20. package/es/object/index.d.ts +1 -1
  21. package/es/object/index.js +21 -12
  22. package/es/promise/index.d.ts +6 -1
  23. package/es/promise/index.js +8 -11
  24. package/es/queue/index.d.ts +2 -3
  25. package/es/queue/index.js +19 -27
  26. package/es/random/index.d.ts +1 -1
  27. package/es/random/index.js +13 -14
  28. package/es/regexp-list/index.d.ts +4 -4
  29. package/es/regexp-list/index.js +11 -10
  30. package/es/sleep/index.d.ts +1 -1
  31. package/es/sleep/index.js +10 -28
  32. package/es/str.d.ts +1 -1
  33. package/es/throttle/index.d.ts +1 -1
  34. package/es/throttle/index.js +4 -2
  35. package/es/trigger/index.js +10 -6
  36. package/es/watch-dog/index.js +3 -8
  37. package/lib/base64/index.d.ts +2 -3
  38. package/lib/base64/index.js +8 -19
  39. package/lib/buf.d.ts +2 -2
  40. package/lib/buf.js +11 -12
  41. package/lib/color/utils.js +6 -11
  42. package/lib/debounce/index.d.ts +3 -1
  43. package/lib/debounce/index.js +2 -6
  44. package/lib/emitter/index.d.ts +18 -16
  45. package/lib/emitter/index.js +11 -12
  46. package/lib/filter/sensor.d.ts +4 -9
  47. package/lib/filter/sensor.js +14 -19
  48. package/lib/fp/index.d.ts +20 -15
  49. package/lib/fp/index.js +6 -4
  50. package/lib/loop/index.d.ts +4 -4
  51. package/lib/loop/index.js +4 -9
  52. package/lib/math/geometry.js +3 -4
  53. package/lib/math/utm.d.ts +1 -1
  54. package/lib/math/utm.js +1 -2
  55. package/lib/object/index.d.ts +1 -1
  56. package/lib/object/index.js +21 -12
  57. package/lib/promise/index.d.ts +6 -1
  58. package/lib/promise/index.js +5 -10
  59. package/lib/queue/index.d.ts +2 -3
  60. package/lib/queue/index.js +19 -27
  61. package/lib/random/index.d.ts +1 -1
  62. package/lib/random/index.js +14 -20
  63. package/lib/regexp-list/index.d.ts +4 -4
  64. package/lib/regexp-list/index.js +11 -10
  65. package/lib/sleep/index.d.ts +1 -1
  66. package/lib/sleep/index.js +10 -28
  67. package/lib/str.d.ts +1 -1
  68. package/lib/throttle/index.d.ts +1 -1
  69. package/lib/throttle/index.js +4 -2
  70. package/lib/trigger/index.js +10 -6
  71. package/lib/watch-dog/index.js +3 -8
  72. package/package.json +2 -2
@@ -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.PuboUtils=e():t.PuboUtils=e()}(this,(()=>(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},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:()=>s,BufferSplit:()=>vt,CacheEmitter:()=>d,ColorUtils:()=>l,ContinuousTrigger:()=>A,Emitter:()=>f,FP:()=>n,HistoryStack:()=>C,Level:()=>O,LinearColor:()=>u,RegExpList:()=>$,RemoteControl:()=>E,ResourceHandler:()=>r.ResourceHandler,ResourceHandlerParams:()=>r.ResourceHandlerParams,ResourceHandlerState:()=>Lt,ResourceManager:()=>kt,RetryPlus:()=>x,SensorDataFilter:()=>K,StringSplit:()=>Q,SyncQueue:()=>S,UTM:()=>i,WatchDog:()=>P,callbackToPromise:()=>R,cloneDeep:()=>V,debounce:()=>o,degrees:()=>L,filterKeyPoints:()=>F,filterTree:()=>tt,fixNum:()=>X,flatTree:()=>J,getAngle:()=>j,getBestPointIndex:()=>H,getCenter:()=>z,getDistance:()=>D,getPositionTheta:()=>G,getRotate:()=>U,getTreeItem:()=>Y,getVectorTheta:()=>B,hex2rgb:()=>h,loop:()=>b,lower2camel:()=>q,orderByDistance:()=>W,radians:()=>k,random:()=>m,randomRangeNum:()=>p,reflection:()=>et,retry:()=>T,runAsyncTasks:()=>_,searchTree:()=>Z,sleep:()=>y,superFactory:()=>g,throttle:()=>N,timeout:()=>w,waitFor:()=>M});var s={};t.r(s),t.d(s,{EncoderMap:()=>v,toUnit8Array:()=>I});var i={};t.r(i),t.d(i,{fromLatLon:()=>St,latLonToZoneNumber:()=>Nt,latitudeToZoneLetter:()=>_t,toLatLon:()=>Et});var n={};t.r(n),t.d(n,{Command:()=>Pt,Failure:()=>Ct,Success:()=>It,effectPipe:()=>Rt,runEffect:()=>Dt});var r={};t.r(r),t.d(r,{x:()=>Lt,f:()=>kt});const o=(t,e,s=!1)=>{if(s){let s,i=!0;return(...n)=>{i&&(t(...n),i=!1),s&&clearTimeout(s),s=setTimeout((()=>{clearTimeout(s),i=!0,s=null}),e)}}{let s;return(...i)=>{s&&(clearTimeout(s),s=null),s=setTimeout((()=>{t(...i),clearTimeout(s),i=null,s=null}),e)}}},a=t=>parseInt(t.replace("#",""),16),h=t=>{let e;e="string"==typeof t?a(t):t;const s=e.toString(2).padStart(24,"0");return[parseInt(s.slice(0,8),2),parseInt(s.slice(8,16),2),parseInt(s.slice(16,24),2)]},c=t=>"#"+[0,1,2].map((e=>t[e].toString(16))).join("");class l{int;constructor(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=a(t):Array.isArray(t)&&(this.int=a(c(t)))}getRgbArray(){return h(this.int)}get rgb(){return`rba(${this.getRgbArray().join(", ")})`}get hex(){return c(this.getRgbArray())}toString(t="hex"){return"rgb"===t?this.rgb:this.hex}}class u{base=[255,0,0];intensity=1;min;max;constructor({base:t=[255,0,0],intensity:e=1}={}){this.base=t,this.intensity=e,this.intensity<1&&(this.intensity=1),this.min=this.base[1],this.max=this.base[0],Math.abs(this.min-this.max)<1&&(this.min=0,this.max=255)}getColor(t){if(t<0)return this.base;let e=this.base[0],s=this.base[1],i=this.base[2],n=t*this.intensity;return s=this.base[1]+n,s<this.max||(n=s-this.max,s=this.max,e=this.base[0]-n,e>this.min||(n=this.min-e,e=this.min,i=this.base[2]+n,i<this.max||(n=i-this.max,i=this.max,s-=n,s>this.min||(n=this.min-s,s=this.min,e+=n,e<this.max||(n=e-this.max,e=this.max,i-=n,i>this.min||(i=this.min)))))),[e,s,i]}}const m=(t=8)=>{const e=t=>Math.random().toString(32).slice(2,2+t);if(t<=8)return e(t);let s="";for(let i=0;i<=t;i+=8)s+=e(t-i>8?8:t-i);return s},p=t=>{const e=Math.abs(t[1]-t[0]);return Math.random()*e+Math.min(...t)};class f{state={};ids={};on(t,e){if(this.state[t]||(this.state[t]={}),"function"!=typeof e)throw new Error("第二个参数必须为function!");const s=`${m(40)}_${(new Date).valueOf()}`;return this.state[t][s]=e,this.ids[s]=t,s}cancel(t){if(!t)return;const e=this.ids[t];e&&this.state[e]&&(delete this.state[e][t],0===Object.keys(this.state[e]).length&&delete this.state[e],delete this.ids[t])}clear(){this.state={},this.ids={}}emit(t,e){if(this.state[t])for(const s of Object.keys(this.state[t])){const i=this.state[t][s];"function"==typeof i&&i(e)}}async emitSync(t,e){if(this.state[t])for(const s of Object.keys(this.state[t])){const i=this.state[t][s];if("function"==typeof i)try{await i(e)}catch(t){console.log(t)}}}clone(){return{state:{...this.state},ids:{...this.ids}}}restore(t){this.state=t.state,this.ids=t.ids}}class d extends f{_cache={};emit(t,e){this._cache[t]=e,super.emit(t,e)}getState(t){return this._cache[t]}}const g=t=>e=>{const s={};for(const i of Object.keys(e))s[i]=t(e[i],i);return s},y=async t=>{await new Promise((e=>{let s=setTimeout((()=>{e(),clearTimeout(s),s=null}),t)}))},w=async(t,e=1e4)=>new Promise((async(s,i)=>{let n=!1;const r=setTimeout((()=>{n=!0,i(new Error("Timeout"))}),e);let o;try{o=await t(),clearTimeout(r)}catch(t){console.log(t),clearTimeout(r),n||i(t)}n||s(o)})),b=(t,e)=>{let s=!0;return(async()=>{for(;s;){try{await t()}catch(t){console.log(t)}await y(e)}})(),()=>s=!1},M=(t,{checkTime:e,timeout:s}={})=>new Promise(((i,n)=>{let r,o=b((async()=>{const e=await t();e&&("function"==typeof o&&o(),r&&(clearTimeout(r),r=null),i(e),o=null,t=null,i=null)}),e||100);s&&(r=setTimeout((()=>{"function"==typeof o&&o(),r&&(clearTimeout(r),r=null),n("timeout"),n=null,o=null,t=null}),s))})),T=async(t,{times:e=5,interval:s=1e3}={times:5,interval:1e3})=>{let i=1;const n=async()=>{let r;if(i>e)throw new Error("retry times exceed");try{return r=await t(),r}catch(t){console.log(`action error, times ${i}`),console.log(t),await y(s),i+=1,await n()}};await n()};class x{times;interval;action;count=1;args=[];result;canceled=!1;constructor(t,{times:e=5,interval:s=1e3}={times:5,interval:1e3}){this.interval=s,this.times=e,this.action=t}async _run(){if(this.canceled)throw new Error("retry canceled");if(this.count>this.times)throw new Error("retry times exceed");try{this.result=await this.action(...this.args)}catch(t){console.log(`action error, times ${this.count}`),console.log(t),await y(this.interval),this.count+=1,await this._run()}}async run(...t){return this.canceled=!1,this.result=null,this.count=1,this.args=t,await this._run(),this.args=[],this.count=1,this.result}async cancel(){this.canceled=!0}}class E{timeout;_start;_stop;fps;payload;constructor({start:t,stop:e,fps:s=5}){this._start=t,this._stop=e,this.fps=s}send(){this.payload&&this._start(this.payload)}control(t){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.payload=t,this.send(),this.timeout=setTimeout((()=>this.stop()),1e3/this.fps)}stop(){this.payload=null,clearTimeout(this.timeout),this.timeout=null,this._stop()}}class S{cache=[];running=!1;len=0;async _run({fn:t,promise:e}){try{const s=await t();e.resolve(s)}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,s)=>{this.cache.push({fn:t,promise:{resolve:e,reject:s}}),this.running||this.run()}))}get length(){return this.len}}const _=async(t,e=4)=>{let s=-1;const i=[],n=async()=>{if(s+=1,t[s]){try{await t[s]()}catch(t){console.log(t)}await n()}};for(let t=0;t<e;t+=1)i.push(n());await Promise.all(i)};function N(t,e){const s=new S;let i=[];return(...n)=>{if(i=n,!(s.length>0))return s.push((async()=>{await y(e),await t(...i)}))}}class A{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 v=function(){const t={};for(let e=0;e<64;e++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;return t}();function I(t){const e=new Uint8Array(6*t.length/8);let s=0,i=0,n=0;for(let r=0;r<t.length&&n<e.length;r+=1)if(i=(i<<6)+v[t.charAt(r)],s+=6,s>=8){s-=8;let t=i>>>s;e[n++]=255&t,t<<=s,i-=t}return e}class C{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 P{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 O{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,s=this.config.min+this.step;s<this.config.max+this.step;s+=this.step,e+=1)if(t<s)return e;return this.config.count}}const R=t=>(...e)=>new Promise(((s,i)=>{t(...e,((t,...e)=>{t&&i(t),e.length<2?s(e[0]):s([...e])})),t=null})),D=(t,e)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),L=t=>180*t/Math.PI,k=t=>t*Math.PI/180,j=({w:t,h:e})=>L(Math.atan2(e,t));function F(t,e=.5){if(t.length<3||e<=0)return t;let s;return t.filter(((i,n)=>!(n>0&&D(s,i)<e||(s=t[n],0))))}function z(t){const e=[0,0];for(const s of t)Array.isArray(s)?(e[0]+=s[0],e[1]+=s[1]):(e[0]+=s.x,e[1]+=s.y);return{x:e[0]/t.length,y:e[1]/t.length}}function U(t,e,s){return s&&(e=k(e)),[Math.cos(e)*t[0]-Math.sin(e)*t[1],Math.sin(e)*t[0]+Math.cos(e)*t[1]]}const G=(t,e)=>{const s={x:e.x-t.x,y:e.y-t.y};return Math.atan2(s.y,s.x)},H=(t,e)=>{if(t.length<2)return 0;const s=[];let i=1/0,n=0;for(const r of t){const t=D(r,e),o=G(e,r)-e.theta;i>t&&(i=t),s.push({...r,index:n,distance:t,theta:o}),n+=1}return s.filter((t=>t.distance-i<.1)).sort(((t,e)=>t.theta-e.theta))[0].index},W=(t,e={x:0,y:0,theta:0})=>{let s=e;const i=[],n=[...t];for(;n.length>0;){const t=H(n,s);i.push(n[t]),s=n[t],n.splice(t,1)}return i},B=(t,e)=>Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x),q=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join(""),X=(t,e=2)=>null==t||"NaN"===t?"N/A":("number"!=typeof t&&(t=parseFloat(t)),isNaN(t)?"N/A":t.toFixed(e));class ${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 K{tmp=[];size;step;min;max;count=0;value=NaN;old;constructor({size:t=5,step:e=5,min:s=-1/0,max:i=1/0}={}){this.size=t,this.step=e,this.min=s,this.max=i,this.old=this.min}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:s}=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>s[e]?(this.tmp.length=0,this.tmp.push(t),this.count=0,this.value=NaN,t):e):(this.count=0,this.value=NaN,t)}getMostNumberOfTmp(){const t={};let e,s=0;for(const i of this.tmp)t[i]?t[i]+=1:t[i]=1,t[i]>=s&&(s=t[i],e=i);return{res:e,dic:t}}}class Q{_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}}function V(t,e=new WeakMap){if("object"!=typeof t||null===t)return t;if(e.has(t))return e.get(t);if(Array.isArray(t)){const s=t.map((t=>V(t,e)));return e.set(t,s),s}if(t instanceof Set){const s=new Set([...t].map((t=>V(t,e))));return e.set(t,s),s}if(t instanceof Map){const s=new Map;for(const[i,n]of t.entries())s.set(V(i,e),V(n,e));return e.set(t,s),s}{const s={};e.set(t,s);for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(s[i]=V(t[i],e));return s}}function Y(t,e){if(e.length<1)return null;let s;Array.isArray(t)&&(s={children:t});for(const t of e)s=s.children[t];return V(s)}function Z(t,e,s="children"){const i=[];let n=!1;const r=t=>{for(let o=0;o<t.length;o+=1){const a=t[o];if(e(a)){n=!0,i.push(o);break}if(Array.isArray(a[s])){if(i.push(o),r(a[s]),n)break;i.pop()}}};return Array.isArray(t)?r(t):Array.isArray(t[s])&&r(t[s]),n?i:[]}const J=(t,e="children",s=[],i=[])=>{let n=[];return Array.isArray(t[e])?n=t[e]:Array.isArray(t)&&(n=t),n.forEach(((t,n)=>{const r={...t};delete r[e],i.push(r),r.__indexes=[...s,n]})),n.forEach(((t,n)=>J(t,e,[...s,n],i))),i},tt=(t,e,s="children")=>{const i=[];let n=[];return Array.isArray(t[s])?n=t[s]:Array.isArray(t)&&(n=t),n.forEach((t=>{var n;t[s]&&(t[s]=tt(t[s],e)),((null===(n=t[s])||void 0===n?void 0:n.length)>0||e(t))&&i.push(t)})),i},et=t=>{const e={};for(const s of Object.keys(t))e[t[s]]=s;return e},st=.9996,it=.00669438,nt=Math.pow(it,2),rt=Math.pow(it,3),ot=it/(1-it),at=Math.sqrt(1-it),ht=(1-at)/(1+at),ct=Math.pow(ht,2),lt=Math.pow(ht,3),ut=Math.pow(ht,4),mt=Math.pow(ht,5),pt=1-it/4-3*nt/64-5*rt/256,ft=3*it/8+3*nt/32+45*rt/1024,dt=15*nt/256+45*rt/1024,gt=35*rt/3072,yt=1.5*ht-27/32*lt+269/512*mt,wt=21/16*ct-55/32*ut,bt=151/96*lt-417/128*mt,Mt=1097/512*ut,Tt=6378137,xt="CDEFGHJKLMNPQRSTUVWXX";function Et(t){const{zoneNum:e,strict:s=!0}=t;let{zoneLetter:i,northern:n}=t;const r=t.x,o=t.y;if(!i&&void 0===n)throw new Error("either zoneLetter or northern needs to be set");if(i&&void 0!==n)throw new Error("set either zoneLetter or northern, but not both");if(s){if(r<1e5||1e6<=r)throw new RangeError("easting out of range (must be between 100 000 m and 999 999 m)");if(o<0||o>1e7)throw new RangeError("northing out of range (must be between 0 m and 10 000 000 m)")}if(e<1||e>60)throw new RangeError("zone number out of range (must be between 1 and 60)");if(i){if(i=i.toUpperCase(),1!==i.length||-1===xt.indexOf(i))throw new RangeError("zone letter out of range (must be between C and X)");n=i>="N"}const a=r-5e5;let h=o;n||(h-=1e7);const c=h/st/(Tt*pt),l=c+yt*Math.sin(2*c)+wt*Math.sin(4*c)+bt*Math.sin(6*c)+Mt*Math.sin(8*c),u=Math.sin(l),m=Math.pow(u,2),p=Math.cos(l),f=Math.tan(l),d=Math.pow(f,2),g=Math.pow(f,4),y=1-it*m,w=Math.sqrt(y),b=(1-it)/y,M=ht*p*p,T=M*M,x=a/(Tt/w*st),E=Math.pow(x,2),S=Math.pow(x,3),_=Math.pow(x,4),N=Math.pow(x,5),A=Math.pow(x,6),v=(x-S/6*(1+2*d+M)+N/120*(5-2*M+28*d-3*T+8*ot+24*g))/p;return{latitude:L(l-f/b*(E/2-_/24*(5+3*d+10*M-4*T-9*ot))+A/720*(61+90*d+298*M+45*g-252*ot-3*T)),longitude:L(v)+At(e)}}function St({latitude:t,longitude:e},s){if(t>84||t<-80)throw new RangeError("latitude out of range (must be between 80 deg S and 84 deg N)");if(e>180||e<-180)throw new RangeError("longitude out of range (must be between 180 deg W and 180 deg E)");const i=k(t),n=Math.sin(i),r=Math.cos(i),o=Math.tan(i),a=Math.pow(o,2),h=Math.pow(o,4);let c;c=void 0===s?Nt({latitude:t,longitude:e}):s;const l=_t(t),u=k(e),m=At(c),p=k(m),f=Tt/Math.sqrt(1-it*n*n),d=ot*r*r,g=r*(u-p),y=Math.pow(g,2),w=Math.pow(g,3),b=Math.pow(g,4),M=Math.pow(g,5),T=Math.pow(g,6),x=Tt*(pt*i-ft*Math.sin(2*i)+dt*Math.sin(4*i)-gt*Math.sin(6*i));let E=st*(x+f*o*(y/2+b/24*(5-a+9*d+4*d*d)+T/720*(61-58*a+h+600*d-330*ot)));return t<0&&(E+=1e7),{x:st*f*(g+w/6*(1-a+d)+M/120*(5-18*a+h+72*d-58*ot))+5e5,y:E,zoneNum:c,zoneLetter:l}}function _t(t){return-80<=t&&t<=84?xt[Math.floor((t+80)/8)]:null}function Nt({latitude:t,longitude:e}){if(56<=t&&t<64&&3<=e&&e<12)return 32;if(72<=t&&t<=84&&e>=0){if(e<9)return 31;if(e<21)return 33;if(e<33)return 35;if(e<42)return 37}return Math.floor((e+180)/6)+1}function At(t){return 6*(t-1)-180+3}class vt{cache=Buffer.alloc(0);c;constructor(t){this.c=t}push(t){const e=Buffer.concat([this.cache,t]),s=[];let i=0;for(let t=this.cache.byteLength;t<=e.byteLength-this.c.byteLength;t+=1)if(this.c.equals(e.subarray(t,this.c.byteLength+t))){const n=e.subarray(i,t);s.push(n),i=this.c.byteLength+t,t=this.c.byteLength+t}return this.cache=e.subarray(i),s}}const It=t=>({type:"Success",value:t}),Ct=t=>({type:"Failure",error:t}),Pt=(t,e)=>({type:"Command",cmd:t,next:e}),Ot=(t,e)=>{switch(t.type){case"Success":return e(t.value);case"Failure":return t;case"Command":const s=s=>Ot(t.next(s),e);return Pt(t.cmd,s)}},Rt=(...t)=>e=>t.reduce(Ot,It(e));async function Dt(t){for(;"Command"===t.type;)try{t=t.next(await t.cmd())}catch(t){return Ct(t)}return t}var Lt=function(t){return t[t.DISCONNECTED=0]="DISCONNECTED",t[t.CONNECTING=1]="CONNECTING",t[t.CONNECTED=2]="CONNECTED",t[t.DISPOSING=3]="DISPOSING",t[t.DISPOSED=4]="DISPOSED",t}({});class kt{options;handler;handlerInstance=null;connections=0;disposeTimer=null;static WAIT_CONFIG={checkTime:500,timeout:3e4};static DISPOSE_DELAY=6e4;constructor(t,e){this.handler=t,this.options=e}async run(t){this.clearDisposeTimer(),this.connections++;try{return await this.ensureConnected(),await this.handlerInstance.run(t)}finally{this.handleConnectionEnd()}}async ensureConnected(){var t;4===(null===(t=this.handlerInstance)||void 0===t?void 0:t.getState())&&(this.handlerInstance=null),this.handlerInstance?await M((()=>3!==this.handlerInstance.getState()),kt.WAIT_CONFIG):this.handlerInstance=new this.handler(this.options),await M((()=>2===this.handlerInstance.getState()),kt.WAIT_CONFIG)}clearDisposeTimer(){this.disposeTimer&&(clearTimeout(this.disposeTimer),this.disposeTimer=null)}handleConnectionEnd(){this.connections=Math.max(0,this.connections-1),0===this.connections&&(this.clearDisposeTimer(),this.disposeTimer=setTimeout((()=>this.dispose()),kt.DISPOSE_DELAY))}dispose(){this.handlerInstance&&(this.handlerInstance.dispose(),this.handlerInstance=null),this.disposeTimer=null}}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,s)=>{for(var n in s)t.o(s,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:s[n]})},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:()=>s,BufferSplit:()=>Ct,CacheEmitter:()=>g,ColorUtils:()=>l,ContinuousTrigger:()=>v,Emitter:()=>d,FP:()=>i,HistoryStack:()=>_,Level:()=>D,LinearColor:()=>u,RegExpList:()=>K,RemoteControl:()=>S,ResourceHandler:()=>r.ResourceHandler,ResourceHandlerParams:()=>r.ResourceHandlerParams,ResourceHandlerState:()=>Lt,ResourceManager:()=>jt,RetryPlus:()=>E,SensorDataFilter:()=>Q,StringSplit:()=>V,SyncQueue:()=>A,UTM:()=>n,WatchDog:()=>O,callbackToPromise:()=>k,cloneDeep:()=>Y,debounce:()=>o,degrees:()=>L,filterKeyPoints:()=>z,filterTree:()=>et,fixNum:()=>X,flatTree:()=>tt,getAngle:()=>F,getBestPointIndex:()=>W,getCenter:()=>U,getDistance:()=>R,getPositionTheta:()=>H,getRotate:()=>G,getTreeItem:()=>Z,getVectorTheta:()=>B,hex2rgb:()=>h,loop:()=>M,lower2camel:()=>q,orderByDistance:()=>$,radians:()=>j,random:()=>p,randomRangeNum:()=>f,reflection:()=>st,retry:()=>x,runAsyncTasks:()=>N,searchTree:()=>J,sleep:()=>w,superFactory:()=>y,throttle:()=>P,timeout:()=>b,waitFor:()=>T});var s={};t.r(s),t.d(s,{toUnit8Array:()=>I});var n={};t.r(n),t.d(n,{fromLatLon:()=>At,latLonToZoneNumber:()=>Pt,latitudeToZoneLetter:()=>Nt,toLatLon:()=>St});var i={};t.r(i),t.d(i,{Command:()=>Ot,Failure:()=>_t,Success:()=>It,effectPipe:()=>kt,runEffect:()=>Rt});var r={};t.r(r),t.d(r,{x:()=>Lt,f:()=>jt});const o=(t,e,s=!1)=>{if(s){let s=!0,n=null;return(...i)=>{s&&(t(...i),s=!1),n&&clearTimeout(n),n=setTimeout((()=>{s=!0,n=null}),e)}}{let s=null;return(...n)=>{s&&clearTimeout(s),s=setTimeout((()=>{t(...n),s=null}),e)}}},a=t=>parseInt(t.replace("#",""),16),h=t=>{const e="string"==typeof t?a(t):t;return[e>>16&255,e>>8&255,255&e]},c=t=>"#"+[0,1,2].map((e=>t[e].toString(16))).join("");class l{int;constructor(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=a(t):Array.isArray(t)&&(this.int=a(c(t)))}getRgbArray(){return h(this.int)}get rgb(){return`rgb(${this.getRgbArray().join(", ")})`}get hex(){return c(this.getRgbArray())}toString(t="hex"){return"rgb"===t?this.rgb:this.hex}}class u{base=[255,0,0];intensity=1;min;max;constructor({base:t=[255,0,0],intensity:e=1}={}){this.base=t,this.intensity=e,this.intensity<1&&(this.intensity=1),this.min=this.base[1],this.max=this.base[0],Math.abs(this.min-this.max)<1&&(this.min=0,this.max=255)}getColor(t){if(t<0)return this.base;let e=this.base[0],s=this.base[1],n=this.base[2],i=t*this.intensity;return s=this.base[1]+i,s<this.max||(i=s-this.max,s=this.max,e=this.base[0]-i,e>this.min||(i=this.min-e,e=this.min,n=this.base[2]+i,n<this.max||(i=n-this.max,n=this.max,s-=i,s>this.min||(i=this.min-s,s=this.min,e+=i,e<this.max||(i=e-this.max,e=this.max,n-=i,n>this.min||(n=this.min)))))),[e,s,n]}}const m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",p=(t=8)=>{let e="";for(let s=0;s<t;s++)e+=m.charAt(Math.floor(Math.random()*m.length));return e},f=t=>{const[e,s]=t[0]<t[1]?[t[0],t[1]]:[t[1],t[0]];return Math.random()*(s-e)+e};class d{state={};ids={};on(t,e){if(this.state[t]||(this.state[t]={}),"function"!=typeof e)throw new Error("第二个参数必须为function!");const s=`${p(40)}_${Date.now()}`;return this.state[t][s]=e,this.ids[s]=t,s}cancel(t){if(!t)return;const e=this.ids[t];e&&this.state[e]&&(delete this.state[e][t],0===Object.keys(this.state[e]).length&&delete this.state[e],delete this.ids[t])}clear(){this.state={},this.ids={}}emit(t,e){const s=this.state[t];if(s)for(const t of Object.keys(s)){const n=s[t];"function"==typeof n&&n(e)}}async emitAsync(t,e){const s=this.state[t];if(s)for(const t of Object.keys(s)){const n=s[t];if("function"==typeof n)try{await n(e)}catch(t){console.log(t)}}}clone(){return{state:{...this.state},ids:{...this.ids}}}restore(t){this.state=t.state,this.ids=t.ids}}class g extends d{_cache={};emit(t,e){this._cache[t]=e,super.emit(t,e)}getState(t){return this._cache[t]}}const y=t=>e=>{const s={};for(const n of Object.keys(e))s[n]=t(e[n],n);return s},w=t=>new Promise((e=>setTimeout(e,t))),b=(t,e=1e4)=>new Promise(((s,n)=>{const i=setTimeout((()=>n(new Error("Timeout"))),e);t().then((t=>{clearTimeout(i),s(t)})).catch((t=>{clearTimeout(i),n(t)}))})),M=(t,e)=>{let s=!0;return(async()=>{for(;s;){try{await t()}catch(t){console.log(t)}await w(e)}})(),()=>s=!1},T=(t,{checkTime:e,timeout:s}={})=>new Promise(((n,i)=>{let r,o=M((async()=>{const e=await t();e&&("function"==typeof o&&o(),r&&(clearTimeout(r),r=null),n(e),o=null,t=null,n=null)}),e||100);s&&(r=setTimeout((()=>{"function"==typeof o&&o(),r&&(clearTimeout(r),r=null),i("timeout"),i=null,o=null,t=null}),s))})),x=async(t,{times:e=5,interval:s=1e3}={})=>{let n=1;const i=async()=>{if(n>e)throw new Error("retry times exceed");try{return await t()}catch(t){return console.log(`action error, times ${n}`),console.log(t),await w(s),n+=1,i()}};return i()};class E{times;interval;action;count=1;args=[];result;canceled=!1;constructor(t,{times:e=5,interval:s=1e3}={times:5,interval:1e3}){this.interval=s,this.times=e,this.action=t}async _run(){if(this.canceled)throw new Error("retry canceled");if(this.count>this.times)throw new Error("retry times exceed");try{this.result=await this.action(...this.args)}catch(t){console.log(`action error, times ${this.count}`),console.log(t),await w(this.interval),this.count+=1,await this._run()}}async run(...t){return this.canceled=!1,this.result=null,this.count=1,this.args=t,await this._run(),this.args=[],this.count=1,this.result}async cancel(){this.canceled=!0}}class S{timeout;_start;_stop;fps;payload;constructor({start:t,stop:e,fps:s=5}){this._start=t,this._stop=e,this.fps=s}send(){this.payload&&this._start(this.payload)}control(t){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.payload=t,this.send(),this.timeout=setTimeout((()=>this.stop()),1e3/this.fps)}stop(){this.payload=null,clearTimeout(this.timeout),this.timeout=null,this._stop()}}class A{cache=[];running=!1;async _run(t){try{const e=await t.fn();t.resolve(e)}catch(e){t.reject(e)}}async run(){if(this.cache.length<1)return void(this.running=!1);this.running=!0;const t=this.cache.shift();t&&await this._run(t),this.run()}push(t){return new Promise(((e,s)=>{this.cache.push({fn:t,resolve:e,reject:s}),this.running||this.run()}))}get length(){return this.cache.length}}const N=async(t,e=4)=>{let s=-1;const n=async()=>{s+=1;const e=t[s];if(e){try{await e()}catch(t){console.log(t)}await n()}},i=Array.from({length:e},(()=>n()));await Promise.all(i)};function P(t,e){const s=new A;let n=null;return(...i)=>{if(n=i,!(s.length>0))return s.push((async()=>{await w(e),n&&await t(...n)}))}}class v{timeout=null;_count=0;props;constructor(t){this.props=t}get count(){return this._count}increment(){this.timeout&&clearTimeout(this.timeout),this.timeout=setTimeout((()=>this.clear()),this.props.resetTime),this._count+=1,this._count>=this.props.count&&this.props.cb()}clear(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this._count=0}}const C={};for(let t=0;t<64;t++)C["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(t)]=t;function I(t){const e=new Uint8Array(6*t.length/8);let s=0,n=0,i=0;for(let r=0;r<t.length&&i<e.length;r+=1)if(n=(n<<6)+C[t.charAt(r)],s+=6,s>=8){s-=8;let t=n>>>s;e[i++]=255&t,t<<=s,n-=t}return e}class _{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 O{onTimeout;timeout=null;_time;constructor({limit:t=10,onTimeout:e}){this._time=1e3*t,this.onTimeout=()=>{this.stop(),e()}}feed(){this.init()}init(){this.stop(),this.timeout=setTimeout(this.onTimeout,this._time)}stop(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null)}}class D{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,s=this.config.min+this.step;s<this.config.max+this.step;s+=this.step,e+=1)if(t<s)return e;return this.config.count}}const k=t=>(...e)=>new Promise(((s,n)=>{t(...e,((t,e)=>{t?n(t):s(e)}))})),R=(t,e)=>Math.hypot(t.x-e.x,t.y-e.y),L=t=>180*t/Math.PI,j=t=>t*Math.PI/180,F=({w:t,h:e})=>L(Math.atan2(e,t));function z(t,e=.5){if(t.length<3||e<=0)return t;let s;return t.filter(((n,i)=>!(i>0&&R(s,n)<e||(s=t[i],0))))}function U(t){const e=[0,0];for(const s of t)Array.isArray(s)?(e[0]+=s[0],e[1]+=s[1]):(e[0]+=s.x,e[1]+=s.y);return{x:e[0]/t.length,y:e[1]/t.length}}function G(t,e,s){return s&&(e=j(e)),[Math.cos(e)*t[0]-Math.sin(e)*t[1],Math.sin(e)*t[0]+Math.cos(e)*t[1]]}const H=(t,e)=>{const s={x:e.x-t.x,y:e.y-t.y};return Math.atan2(s.y,s.x)},W=(t,e)=>{if(t.length<2)return 0;const s=[];let n=1/0;for(let i=0;i<t.length;i++){const r=t[i],o=R(r,e),a=H(e,r)-e.theta;n>o&&(n=o),s.push({...r,index:i,distance:o,theta:a})}return s.filter((t=>t.distance-n<.1)).sort(((t,e)=>t.theta-e.theta))[0].index},$=(t,e={x:0,y:0,theta:0})=>{let s=e;const n=[],i=[...t];for(;i.length>0;){const t=W(i,s);n.push(i[t]),s=i[t],i.splice(t,1)}return n},B=(t,e)=>Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x),q=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join(""),X=(t,e=2)=>null==t||"NaN"===t?"N/A":("number"!=typeof t&&(t=parseFloat(t)),isNaN(t)?"N/A":t.toFixed(e));class K{patterns;compiledPatterns=null;constructor(t){this.patterns=t}compilePattern(t){const e=t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\//g,"\\/");return new RegExp(`^${e}$`)}include(t){return this.compiledPatterns||(this.compiledPatterns=this.patterns.map((t=>this.compilePattern(t)))),this.compiledPatterns.some((e=>e.test(t)))}}class Q{tmp=[];size;step;min;max;count=0;value=NaN;old;constructor({size:t=5,step:e=5,min:s=-1/0,max:n=1/0}={}){this.size=t,this.step=e,this.min=s,this.max=n,this.old=this.min}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:s}=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>s[e]?(this.tmp.length=0,this.tmp.push(t),this.count=0,this.value=NaN,t):e):(this.count=0,this.value=NaN,t)}getMostNumberOfTmp(){const t={};let e=0,s=0;for(const n of this.tmp){const i=String(n);t[i]=(t[i]||0)+1,t[i]>=e&&(e=t[i],s=n)}return{res:s,dic:t}}}class V{splitSymbol;cache="";constructor(t){this.splitSymbol=t}split(t){const e=(this.cache+t).split(this.splitSymbol);return this.cache=e.pop()||"",e}}function Y(t,e=new WeakMap){if("object"!=typeof t||null===t)return t;if(e.has(t))return e.get(t);if(Array.isArray(t)){const s=t.map((t=>Y(t,e)));return e.set(t,s),s}if(t instanceof Set){const s=new Set([...t].map((t=>Y(t,e))));return e.set(t,s),s}if(t instanceof Map){const s=new Map;for(const[n,i]of t.entries())s.set(Y(n,e),Y(i,e));return e.set(t,s),s}if(t instanceof Date)return new Date(t);if(t instanceof RegExp)return new RegExp(t.source,t.flags);const s={};e.set(t,s);for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=Y(t[n],e));return s}function Z(t,e){if(e.length<1)return null;let s;Array.isArray(t)&&(s={children:t});for(const t of e)s=s.children[t];return Y(s)}function J(t,e,s="children"){const n=[];let i=!1;const r=t=>{for(let o=0;o<t.length;o+=1){const a=t[o];if(e(a)){i=!0,n.push(o);break}if(Array.isArray(a[s])){if(n.push(o),r(a[s]),i)break;n.pop()}}};return Array.isArray(t)?r(t):Array.isArray(t[s])&&r(t[s]),i?n:[]}const tt=(t,e="children",s=[],n=[])=>{let i=[];return Array.isArray(t[e])?i=t[e]:Array.isArray(t)&&(i=t),i.forEach(((t,i)=>{const r={...t};delete r[e],n.push(r),r.__indexes=[...s,i]})),i.forEach(((t,i)=>tt(t,e,[...s,i],n))),n},et=(t,e,s="children")=>{const n=[];let i=[];return Array.isArray(t[s])?i=t[s]:Array.isArray(t)&&(i=t),i.forEach((t=>{var i;t[s]&&(t[s]=et(t[s],e)),((null===(i=t[s])||void 0===i?void 0:i.length)>0||e(t))&&n.push(t)})),n},st=t=>{const e={};for(const s of Object.keys(t))e[t[s]]=s;return e},nt=.9996,it=.00669438,rt=Math.pow(it,2),ot=Math.pow(it,3),at=it/(1-it),ht=Math.sqrt(1-it),ct=(1-ht)/(1+ht),lt=Math.pow(ct,2),ut=Math.pow(ct,3),mt=Math.pow(ct,4),pt=Math.pow(ct,5),ft=1-it/4-3*rt/64-5*ot/256,dt=3*it/8+3*rt/32+45*ot/1024,gt=15*rt/256+45*ot/1024,yt=35*ot/3072,wt=1.5*ct-27/32*ut+269/512*pt,bt=21/16*lt-55/32*mt,Mt=151/96*ut-417/128*pt,Tt=1097/512*mt,xt=6378137,Et="CDEFGHJKLMNPQRSTUVWXX";function St(t){const{zoneNum:e,strict:s=!0}=t;let{zoneLetter:n,northern:i}=t;const r=t.x,o=t.y;if(!n&&void 0===i)throw new Error("either zoneLetter or northern needs to be set");if(n&&void 0!==i)throw new Error("set either zoneLetter or northern, but not both");if(s){if(r<1e5||1e6<=r)throw new RangeError("easting out of range (must be between 100 000 m and 999 999 m)");if(o<0||o>1e7)throw new RangeError("northing out of range (must be between 0 m and 10 000 000 m)")}if(e<1||e>60)throw new RangeError("zone number out of range (must be between 1 and 60)");if(n){if(n=n.toUpperCase(),1!==n.length||-1===Et.indexOf(n))throw new RangeError("zone letter out of range (must be between C and X)");i=n>="N"}const a=r-5e5;let h=o;i||(h-=1e7);const c=h/nt/(xt*ft),l=c+wt*Math.sin(2*c)+bt*Math.sin(4*c)+Mt*Math.sin(6*c)+Tt*Math.sin(8*c),u=Math.sin(l),m=Math.pow(u,2),p=Math.cos(l),f=Math.tan(l),d=Math.pow(f,2),g=Math.pow(f,4),y=1-it*m,w=Math.sqrt(y),b=(1-it)/y,M=ct*p*p,T=M*M,x=a/(xt/w*nt),E=Math.pow(x,2),S=Math.pow(x,3),A=Math.pow(x,4),N=Math.pow(x,5),P=Math.pow(x,6),v=(x-S/6*(1+2*d+M)+N/120*(5-2*M+28*d-3*T+8*at+24*g))/p;return{latitude:L(l-f/b*(E/2-A/24*(5+3*d+10*M-4*T-9*at))+P/720*(61+90*d+298*M+45*g-252*at-3*T)),longitude:L(v)+vt(e)}}function At({latitude:t,longitude:e},s){if(t>84||t<-80)throw new RangeError("latitude out of range (must be between 80 deg S and 84 deg N)");if(e>180||e<-180)throw new RangeError("longitude out of range (must be between 180 deg W and 180 deg E)");const n=j(t),i=Math.sin(n),r=Math.cos(n),o=Math.tan(n),a=Math.pow(o,2),h=Math.pow(o,4);let c;c=void 0===s?Pt({latitude:t,longitude:e}):s;const l=Nt(t),u=j(e),m=vt(c),p=j(m),f=xt/Math.sqrt(1-it*i*i),d=at*r*r,g=r*(u-p),y=Math.pow(g,2),w=Math.pow(g,3),b=Math.pow(g,4),M=Math.pow(g,5),T=Math.pow(g,6),x=xt*(ft*n-dt*Math.sin(2*n)+gt*Math.sin(4*n)-yt*Math.sin(6*n));let E=nt*(x+f*o*(y/2+b/24*(5-a+9*d+4*d*d)+T/720*(61-58*a+h+600*d-330*at)));return t<0&&(E+=1e7),{x:nt*f*(g+w/6*(1-a+d)+M/120*(5-18*a+h+72*d-58*at))+5e5,y:E,zoneNum:c,zoneLetter:l}}function Nt(t){return-80<=t&&t<=84?Et[Math.floor((t+80)/8)]:null}function Pt({latitude:t,longitude:e}){if(56<=t&&t<64&&3<=e&&e<12)return 32;if(72<=t&&t<=84&&e>=0){if(e<9)return 31;if(e<21)return 33;if(e<33)return 35;if(e<42)return 37}return Math.floor((e+180)/6)+1}function vt(t){return 6*(t-1)-180+3}class Ct{cache=Buffer.alloc(0);delimiter;constructor(t){this.delimiter=t}push(t){const e=Buffer.concat([this.cache,t]),s=[];let n=0;for(let t=this.cache.byteLength;t<=e.byteLength-this.delimiter.byteLength;t+=1)this.delimiter.equals(e.subarray(t,this.delimiter.byteLength+t))&&(s.push(e.subarray(n,t)),n=this.delimiter.byteLength+t,t=this.delimiter.byteLength+t-1);return this.cache=e.subarray(n),s}}const It=t=>({type:"Success",value:t}),_t=t=>({type:"Failure",error:t}),Ot=(t,e)=>({type:"Command",cmd:t,next:e}),Dt=(t,e)=>{switch(t.type){case"Success":return e(t.value);case"Failure":return t;case"Command":const s=s=>Dt(t.next(s),e);return Ot(t.cmd,s)}},kt=(...t)=>e=>t.reduce(((t,e)=>Dt(t,e)),It(e));async function Rt(t){let e=t;for(;"Command"===e.type;)try{const t=await e.cmd();e=e.next(t)}catch(t){return _t(t)}return e}var Lt=function(t){return t[t.DISCONNECTED=0]="DISCONNECTED",t[t.CONNECTING=1]="CONNECTING",t[t.CONNECTED=2]="CONNECTED",t[t.DISPOSING=3]="DISPOSING",t[t.DISPOSED=4]="DISPOSED",t}({});class jt{options;handler;handlerInstance=null;connections=0;disposeTimer=null;static WAIT_CONFIG={checkTime:500,timeout:3e4};static DISPOSE_DELAY=6e4;constructor(t,e){this.handler=t,this.options=e}async run(t){this.clearDisposeTimer(),this.connections++;try{return await this.ensureConnected(),await this.handlerInstance.run(t)}finally{this.handleConnectionEnd()}}async ensureConnected(){var t;4===(null===(t=this.handlerInstance)||void 0===t?void 0:t.getState())&&(this.handlerInstance=null),this.handlerInstance?await T((()=>3!==this.handlerInstance.getState()),jt.WAIT_CONFIG):this.handlerInstance=new this.handler(this.options),await T((()=>2===this.handlerInstance.getState()),jt.WAIT_CONFIG)}clearDisposeTimer(){this.disposeTimer&&(clearTimeout(this.disposeTimer),this.disposeTimer=null)}handleConnectionEnd(){this.connections=Math.max(0,this.connections-1),0===this.connections&&(this.clearDisposeTimer(),this.disposeTimer=setTimeout((()=>this.dispose()),jt.DISPOSE_DELAY))}dispose(){this.handlerInstance&&(this.handlerInstance.dispose(),this.handlerInstance=null),this.disposeTimer=null}}return e})()));
@@ -1,8 +1,7 @@
1
- export declare const EncoderMap: {};
2
1
  /**
3
2
  * base64 转Uint8Array
4
3
  * @param input base64 字符串
5
- * @param output Uint8Array
4
+ * @returns Uint8Array
6
5
  * base64 6位的二进制, Uint8Array 8位的二进制,整体原理就是将 base64 的每个字符转成2进制然后拼接,再按每个八位为一个单位地取出
7
6
  */
8
- export declare function toUnit8Array(input: any): Uint8Array;
7
+ export declare function toUnit8Array(input: string): Uint8Array;
@@ -1,15 +1,12 @@
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
- }();
1
+ const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
2
+ const EncoderMap = {};
3
+ for(let i = 0; i < 64; i++){
4
+ EncoderMap[BASE64_CHARS.charAt(i)] = i;
5
+ }
9
6
  /**
10
7
  * base64 转Uint8Array
11
8
  * @param input base64 字符串
12
- * @param output Uint8Array
9
+ * @returns Uint8Array
13
10
  * base64 6位的二进制, Uint8Array 8位的二进制,整体原理就是将 base64 的每个字符转成2进制然后拼接,再按每个八位为一个单位地取出
14
11
  */ export function toUnit8Array(input) {
15
12
  const output = new Uint8Array(input.length * 6 / 8);
package/es/buf.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export declare class BufferSplit {
2
2
  private cache;
3
- private c;
4
- constructor(buf: Buffer);
3
+ private readonly delimiter;
4
+ constructor(delimiter: Buffer);
5
5
  push(buf: Buffer): Buffer[];
6
6
  }
package/es/buf.js CHANGED
@@ -1,25 +1,24 @@
1
1
  export class BufferSplit {
2
2
  cache = Buffer.alloc(0);
3
- c;
4
- constructor(buf){
5
- this.c = buf;
3
+ delimiter;
4
+ constructor(delimiter){
5
+ this.delimiter = delimiter;
6
6
  }
7
7
  push(buf) {
8
- // @ts-ignore
8
+ //@ts-ignore
9
9
  const tmp = Buffer.concat([
10
10
  this.cache,
11
11
  buf
12
12
  ]);
13
13
  const arr = [];
14
14
  let n = 0;
15
- for(let i = this.cache.byteLength; i <= tmp.byteLength - this.c.byteLength; i += 1){
16
- // @ts-ignore
17
- const bool = this.c.equals(tmp.subarray(i, this.c.byteLength + i));
18
- if (bool) {
19
- const res = tmp.subarray(n, i);
20
- arr.push(res);
21
- n = this.c.byteLength + i;
22
- i = this.c.byteLength + i;
15
+ for(let i = this.cache.byteLength; i <= tmp.byteLength - this.delimiter.byteLength; i += 1){
16
+ //@ts-ignore
17
+ const isMatch = this.delimiter.equals(tmp.subarray(i, this.delimiter.byteLength + i));
18
+ if (isMatch) {
19
+ arr.push(tmp.subarray(n, i));
20
+ n = this.delimiter.byteLength + i;
21
+ i = this.delimiter.byteLength + i - 1; // -1 因为循环会 +1
23
22
  }
24
23
  }
25
24
  this.cache = tmp.subarray(n);
package/es/color/utils.js CHANGED
@@ -1,15 +1,10 @@
1
1
  const str2int = (str)=>parseInt(str.replace('#', ''), 16);
2
2
  export const hex2rgb = (n)=>{
3
- let v;
4
- if (typeof n === 'string') {
5
- v = str2int(n);
6
- } else {
7
- v = n;
8
- }
9
- const str = v.toString(2).padStart(24, '0');
10
- const r = parseInt(str.slice(0, 8), 2);
11
- const g = parseInt(str.slice(8, 16), 2);
12
- const b = parseInt(str.slice(16, 24), 2);
3
+ const v = typeof n === 'string' ? str2int(n) : n;
4
+ // 使用位运算优化性能
5
+ const r = v >> 16 & 0xff;
6
+ const g = v >> 8 & 0xff;
7
+ const b = v & 0xff;
13
8
  return [
14
9
  r,
15
10
  g,
@@ -38,7 +33,7 @@ export class ColorUtils {
38
33
  return hex2rgb(this.int);
39
34
  }
40
35
  get rgb() {
41
- return `rba(${this.getRgbArray().join(', ')})`;
36
+ return `rgb(${this.getRgbArray().join(', ')})`;
42
37
  }
43
38
  get hex() {
44
39
  return rgb2hex(this.getRgbArray());
@@ -1 +1,3 @@
1
- export declare const debounce: (cb: any, time: number, first?: boolean) => (...args: any[]) => void;
1
+ type DebounceFunction<T extends (...args: unknown[]) => void> = (...args: Parameters<T>) => void;
2
+ export declare const debounce: <T extends (...args: unknown[]) => void>(cb: T, time: number, first?: boolean) => DebounceFunction<T>;
3
+ export {};
@@ -1,7 +1,7 @@
1
1
  export const debounce = (cb, time, first = false)=>{
2
2
  if (first) {
3
3
  let shouldRun = true;
4
- let t;
4
+ let t = null;
5
5
  return (...args)=>{
6
6
  if (shouldRun) {
7
7
  cb(...args);
@@ -11,22 +11,18 @@ export const debounce = (cb, time, first = false)=>{
11
11
  clearTimeout(t);
12
12
  }
13
13
  t = setTimeout(()=>{
14
- clearTimeout(t);
15
14
  shouldRun = true;
16
15
  t = null;
17
16
  }, time);
18
17
  };
19
18
  } else {
20
- let t;
19
+ let t = null;
21
20
  return (...args)=>{
22
21
  if (t) {
23
22
  clearTimeout(t);
24
- t = null;
25
23
  }
26
24
  t = setTimeout(()=>{
27
25
  cb(...args);
28
- clearTimeout(t);
29
- args = null;
30
26
  t = null;
31
27
  }, time);
32
28
  };
@@ -1,29 +1,31 @@
1
+ type Callback<T = unknown> = (payload: T) => void | Promise<void>;
2
+ interface EmitterSnapshot {
3
+ state: Record<string, Record<string, Callback>>;
4
+ ids: Record<string, string>;
5
+ }
1
6
  interface EmitterType {
2
- on: (event: string, func: any) => string;
7
+ on: <T = unknown>(event: string, func: Callback<T>) => string;
3
8
  cancel: (id?: string) => void;
4
- emit: (event: string, payload?: any) => any;
5
- emitSync: (event: string, payload?: any) => Promise<any>;
9
+ emit: <T = unknown>(event: string, payload?: T) => void;
10
+ emitAsync: <T = unknown>(event: string, payload?: T) => Promise<void>;
6
11
  clear: () => void;
7
- clone: () => any;
8
- restore: (snapshot: any) => void;
12
+ clone: () => EmitterSnapshot;
13
+ restore: (snapshot: EmitterSnapshot) => void;
9
14
  }
10
15
  export declare class Emitter implements EmitterType {
11
16
  private state;
12
- ids: any;
13
- on(event: string, func: any): string;
17
+ private ids;
18
+ on<T = unknown>(event: string, func: Callback<T>): string;
14
19
  cancel(id?: string): void;
15
20
  clear(): void;
16
- emit(event: string, payload?: any): void;
17
- emitSync(event: string, payload?: any): Promise<void>;
18
- clone(): {
19
- state: any;
20
- ids: any;
21
- };
22
- restore(snapshot: any): void;
21
+ emit<T = unknown>(event: string, payload?: T): void;
22
+ emitAsync<T = unknown>(event: string, payload?: T): Promise<void>;
23
+ clone(): EmitterSnapshot;
24
+ restore(snapshot: EmitterSnapshot): void;
23
25
  }
24
26
  export declare class CacheEmitter extends Emitter {
25
27
  private readonly _cache;
26
- emit(event: string, payload?: any): void;
27
- getState(event: string): any;
28
+ emit<T = unknown>(event: string, payload?: T): void;
29
+ getState<T = unknown>(event: string): T | undefined;
28
30
  }
29
31
  export {};
@@ -9,7 +9,7 @@ export class Emitter {
9
9
  if (typeof func !== 'function') {
10
10
  throw new Error('第二个参数必须为function!');
11
11
  }
12
- const key = `${random(40)}_${new Date().valueOf()}`;
12
+ const key = `${random(40)}_${Date.now()}`;
13
13
  this.state[event][key] = func;
14
14
  this.ids[key] = event;
15
15
  return key;
@@ -19,10 +19,7 @@ export class Emitter {
19
19
  return;
20
20
  }
21
21
  const event = this.ids[id];
22
- if (!event) {
23
- return;
24
- }
25
- if (!this.state[event]) {
22
+ if (!event || !this.state[event]) {
26
23
  return;
27
24
  }
28
25
  delete this.state[event][id];
@@ -36,19 +33,21 @@ export class Emitter {
36
33
  this.ids = {};
37
34
  }
38
35
  emit(event, payload) {
39
- if (this.state[event]) {
40
- for (const key of Object.keys(this.state[event])){
41
- const func = this.state[event][key];
36
+ const handlers = this.state[event];
37
+ if (handlers) {
38
+ for (const key of Object.keys(handlers)){
39
+ const func = handlers[key];
42
40
  if (typeof func === 'function') {
43
41
  func(payload);
44
42
  }
45
43
  }
46
44
  }
47
45
  }
48
- async emitSync(event, payload) {
49
- if (this.state[event]) {
50
- for (const key of Object.keys(this.state[event])){
51
- const func = this.state[event][key];
46
+ async emitAsync(event, payload) {
47
+ const handlers = this.state[event];
48
+ if (handlers) {
49
+ for (const key of Object.keys(handlers)){
50
+ const func = handlers[key];
52
51
  if (typeof func === 'function') {
53
52
  try {
54
53
  await func(payload);
@@ -16,21 +16,16 @@ export declare class SensorDataFilter {
16
16
  filter(n: number): number;
17
17
  private calc;
18
18
  /**
19
- * A function to calculate the most frequent element in the 'tmp' array and its frequency.
20
- *
21
- * @return {object} An object containing the most frequent element and its frequency.
19
+ * 计算缓冲区中出现次数最多的值及其频率
22
20
  */
23
21
  private getMostNumberOfTmp;
24
22
  }
25
23
  /**
26
- * Splits the input string using the specified split symbol and returns an array of substrings.
27
- *
28
- * @param {string} str - the input string to be split
29
- * @return {string[]} an array of substrings
24
+ * 字符串分割器,按指定分隔符分割字符串并缓存未完成部分
30
25
  */
31
26
  export declare class StringSplit {
32
- private readonly _splitSymbol;
33
- private _cache;
27
+ private readonly splitSymbol;
28
+ private cache;
34
29
  constructor(splitSymbol: string);
35
30
  split(str: string): string[];
36
31
  }
@@ -67,45 +67,37 @@ export class SensorDataFilter {
67
67
  return res;
68
68
  }
69
69
  /**
70
- * A function to calculate the most frequent element in the 'tmp' array and its frequency.
71
- *
72
- * @return {object} An object containing the most frequent element and its frequency.
70
+ * 计算缓冲区中出现次数最多的值及其频率
73
71
  */ getMostNumberOfTmp() {
74
- const a = {};
72
+ const dic = {};
75
73
  let max = 0;
76
- let res;
74
+ let res = 0;
77
75
  for (const item of this.tmp){
78
- if (!a[item]) {
79
- a[item] = 1;
80
- } else {
81
- a[item] += 1;
82
- }
83
- if (a[item] >= max) {
84
- max = a[item];
76
+ const key = String(item);
77
+ dic[key] = (dic[key] || 0) + 1;
78
+ if (dic[key] >= max) {
79
+ max = dic[key];
85
80
  res = item;
86
81
  }
87
82
  }
88
83
  return {
89
84
  res,
90
- dic: a
85
+ dic
91
86
  };
92
87
  }
93
88
  }
94
89
  /**
95
- * Splits the input string using the specified split symbol and returns an array of substrings.
96
- *
97
- * @param {string} str - the input string to be split
98
- * @return {string[]} an array of substrings
90
+ * 字符串分割器,按指定分隔符分割字符串并缓存未完成部分
99
91
  */ export class StringSplit {
100
- _splitSymbol;
101
- _cache = '';
92
+ splitSymbol;
93
+ cache = '';
102
94
  constructor(splitSymbol){
103
- this._splitSymbol = splitSymbol;
95
+ this.splitSymbol = splitSymbol;
104
96
  }
105
97
  split(str) {
106
- const tmp = this._cache + str;
107
- const arr = tmp.split(this._splitSymbol);
108
- this._cache = arr.splice(arr.length - 1, 1)[0];
98
+ const tmp = this.cache + str;
99
+ const arr = tmp.split(this.splitSymbol);
100
+ this.cache = arr.pop() || '';
109
101
  return arr;
110
102
  }
111
103
  }
package/es/fp/index.d.ts CHANGED
@@ -1,15 +1,20 @@
1
- export declare const Success: (value: any) => {
2
- type: string;
3
- value: any;
4
- };
5
- export declare const Failure: (error: any) => {
6
- type: string;
7
- error: any;
8
- };
9
- export declare const Command: (cmd: any, next: any) => {
10
- type: string;
11
- cmd: any;
12
- next: any;
13
- };
14
- export declare const effectPipe: (...fns: any[]) => (start: any) => any;
15
- export declare function runEffect(effect: any): Promise<any>;
1
+ interface Success<T> {
2
+ type: 'Success';
3
+ value: T;
4
+ }
5
+ interface Failure {
6
+ type: 'Failure';
7
+ error: unknown;
8
+ }
9
+ interface Command<T> {
10
+ type: 'Command';
11
+ cmd: () => Promise<T>;
12
+ next: (result: T) => Effect<unknown>;
13
+ }
14
+ type Effect<T> = Success<T> | Failure | Command<unknown>;
15
+ export declare const Success: <T>(value: T) => Success<T>;
16
+ export declare const Failure: (error: unknown) => Failure;
17
+ export declare const Command: <T>(cmd: () => Promise<T>, next: (result: T) => Effect<unknown>) => Command<T>;
18
+ export declare const effectPipe: (...fns: Array<(value: unknown) => Effect<unknown>>) => <T>(start: T) => Effect<unknown>;
19
+ export declare function runEffect<T>(effect: Effect<T>): Promise<Effect<T>>;
20
+ export {};
package/es/fp/index.js CHANGED
@@ -23,15 +23,17 @@ const chain = (effect, fn)=>{
23
23
  }
24
24
  };
25
25
  export const effectPipe = (...fns)=>{
26
- return (start)=>fns.reduce(chain, Success(start));
26
+ return (start)=>fns.reduce((effect, fn)=>chain(effect, fn), Success(start));
27
27
  };
28
28
  export async function runEffect(effect) {
29
- while(effect.type === 'Command'){
29
+ let current = effect;
30
+ while(current.type === 'Command'){
30
31
  try {
31
- effect = effect.next(await effect.cmd());
32
+ const result = await current.cmd();
33
+ current = current.next(result);
32
34
  } catch (e) {
33
35
  return Failure(e);
34
36
  }
35
37
  }
36
- return effect;
38
+ return current;
37
39
  }
@@ -20,10 +20,10 @@ export declare const waitFor: (bool: WaitForBool, { checkTime, timeout }?: {
20
20
  checkTime?: number;
21
21
  timeout?: number;
22
22
  }) => Promise<unknown>;
23
- export declare const retry: (action: any, { times, interval }?: {
24
- times: number;
25
- interval: number;
26
- }) => Promise<void>;
23
+ export declare const retry: <T>(action: () => Promise<T>, { times, interval }?: {
24
+ times?: number;
25
+ interval?: number;
26
+ }) => Promise<T>;
27
27
  export declare class RetryPlus {
28
28
  times: number;
29
29
  interval: number;
package/es/loop/index.js CHANGED
@@ -64,28 +64,23 @@ import { sleep } from '../sleep';
64
64
  }
65
65
  });
66
66
  };
67
- export const retry = async (action, { times = 5, interval = 1000 } = {
68
- times: 5,
69
- interval: 1000
70
- })=>{
67
+ export const retry = async (action, { times = 5, interval = 1000 } = {})=>{
71
68
  let count = 1;
72
69
  const fn = async ()=>{
73
- let result;
74
70
  if (count > times) {
75
71
  throw new Error('retry times exceed');
76
72
  }
77
73
  try {
78
- result = await action();
79
- return result;
74
+ return await action();
80
75
  } catch (err) {
81
76
  console.log(`action error, times ${count}`);
82
77
  console.log(err);
83
78
  await sleep(interval);
84
79
  count += 1;
85
- await fn();
80
+ return fn();
86
81
  }
87
82
  };
88
- await fn();
83
+ return fn();
89
84
  };
90
85
  export class RetryPlus {
91
86
  times;
@@ -1,6 +1,6 @@
1
1
  // 获取两点的距离
2
2
  export const getDistance = (a, b)=>{
3
- return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
3
+ return Math.hypot(a.x - b.x, a.y - b.y);
4
4
  };
5
5
  // 弧度转角度
6
6
  export const degrees = (rad)=>{
@@ -75,8 +75,8 @@ export const getBestPointIndex = (points, pose)=>{
75
75
  }
76
76
  const temp = [];
77
77
  let minDistance = Infinity;
78
- let index = 0;
79
- for (const item of points){
78
+ for(let index = 0; index < points.length; index++){
79
+ const item = points[index];
80
80
  const distance = getDistance(item, pose);
81
81
  const theta = getPositionTheta(pose, item) - pose.theta;
82
82
  if (minDistance > distance) {
@@ -88,7 +88,6 @@ export const getBestPointIndex = (points, pose)=>{
88
88
  distance,
89
89
  theta
90
90
  });
91
- index += 1;
92
91
  }
93
92
  const results = temp.filter((item)=>item.distance - minDistance < 0.1).sort((a, b)=>a.theta - b.theta);
94
93
  return results[0].index;
package/es/math/utm.d.ts CHANGED
@@ -18,5 +18,5 @@ export interface UTMPosition {
18
18
  }
19
19
  export declare function toLatLon(options: LatLonOptions): WGS84Position;
20
20
  export declare function fromLatLon({ latitude, longitude }: WGS84Position, forceZoneNum?: number): UTMPosition;
21
- export declare function latitudeToZoneLetter(latitude: any): string | null;
21
+ export declare function latitudeToZoneLetter(latitude: number): string | null;
22
22
  export declare function latLonToZoneNumber({ latitude, longitude }: WGS84Position): number;
package/es/math/utm.js CHANGED
@@ -127,9 +127,8 @@ export function fromLatLon({ latitude, longitude }, forceZoneNum) {
127
127
  export function latitudeToZoneLetter(latitude) {
128
128
  if (-80 <= latitude && latitude <= 84) {
129
129
  return ZONE_LETTERS[Math.floor((latitude + 80) / 8)];
130
- } else {
131
- return null;
132
130
  }
131
+ return null;
133
132
  }
134
133
  export function latLonToZoneNumber({ latitude, longitude }) {
135
134
  if (56 <= latitude && latitude < 64 && 3 <= longitude && longitude < 12) return 32;
@@ -1,4 +1,4 @@
1
- export declare function cloneDeep(data: any, hash?: WeakMap<WeakKey, any>): any;
1
+ export declare function cloneDeep<T>(data: T, hash?: WeakMap<object, unknown>): T;
2
2
  export declare function getTreeItem(tree: any, indexes: number[]): any;
3
3
  export declare function searchTree(tree: any, cb: (item: any) => boolean, key?: string): number[];
4
4
  export declare const flatTree: (tree: any, key?: string, indexes?: number[], tmp?: any[]) => any[];