pubo-utils 1.0.206 → 1.0.210
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.
- package/es/index.d.ts +2 -1
- package/es/index.js +1 -1
- package/es/loop/index.js +14 -14
- package/es/random/index.js +10 -10
- package/es/sleep/index.js +5 -5
- package/lib/index.d.ts +2 -1
- package/lib/index.js +0 -6
- package/lib/sleep/index.js +5 -5
- package/package.json +4 -9
- package/dist/pubo-utils.js +0 -1
package/es/index.d.ts
CHANGED
|
@@ -21,4 +21,5 @@ export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree, reflection }
|
|
|
21
21
|
export * as UTM from './math/utm';
|
|
22
22
|
export { BufferSplit } from './buf';
|
|
23
23
|
export * as FP from './fp';
|
|
24
|
-
export {
|
|
24
|
+
export { ResourceHandler, ResourceManager } from './factory/resource-manager';
|
|
25
|
+
export type { ResourceHandlerParams, ResourceHandlerState } from './factory/resource-manager';
|
package/es/index.js
CHANGED
|
@@ -21,4 +21,4 @@ export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree, reflection }
|
|
|
21
21
|
export * as UTM from './math/utm';
|
|
22
22
|
export { BufferSplit } from './buf';
|
|
23
23
|
export * as FP from './fp';
|
|
24
|
-
export {
|
|
24
|
+
export { ResourceHandler, ResourceManager } from './factory/resource-manager';
|
package/es/loop/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { sleep } from '../sleep';
|
|
2
|
-
/**
|
|
3
|
-
* Executes the given callback function in a loop with the specified time interval.
|
|
4
|
-
*
|
|
5
|
-
* @param {Function} cb - The callback function to be executed in the loop. It takes a stop function as a parameter.
|
|
6
|
-
* @param {number} time - The time interval in milliseconds for the loop.
|
|
7
|
-
* @return {Function} The stop function that can be used to stop the loop.
|
|
2
|
+
/**
|
|
3
|
+
* Executes the given callback function in a loop with the specified time interval.
|
|
4
|
+
*
|
|
5
|
+
* @param {Function} cb - The callback function to be executed in the loop. It takes a stop function as a parameter.
|
|
6
|
+
* @param {number} time - The time interval in milliseconds for the loop.
|
|
7
|
+
* @return {Function} The stop function that can be used to stop the loop.
|
|
8
8
|
*/ export const loop = (cb, time)=>{
|
|
9
9
|
let onOff = true;
|
|
10
10
|
let stop = ()=>onOff = false;
|
|
@@ -20,14 +20,14 @@ import { sleep } from '../sleep';
|
|
|
20
20
|
})();
|
|
21
21
|
return stop;
|
|
22
22
|
};
|
|
23
|
-
/**
|
|
24
|
-
* Waits for a boolean condition to be true, with optional timeouts for the check and the overall wait.
|
|
25
|
-
*
|
|
26
|
-
* @param {WaitForBool} bool - the boolean condition to wait for
|
|
27
|
-
* @param {Object} options - optional parameters for checkTime and timeout
|
|
28
|
-
* @param {number} options.checkTime - the time interval for checking the boolean condition (default is 100)
|
|
29
|
-
* @param {number} options.timeout - the maximum time to wait for the boolean condition to be true
|
|
30
|
-
* @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
|
|
23
|
+
/**
|
|
24
|
+
* Waits for a boolean condition to be true, with optional timeouts for the check and the overall wait.
|
|
25
|
+
*
|
|
26
|
+
* @param {WaitForBool} bool - the boolean condition to wait for
|
|
27
|
+
* @param {Object} options - optional parameters for checkTime and timeout
|
|
28
|
+
* @param {number} options.checkTime - the time interval for checking the boolean condition (default is 100)
|
|
29
|
+
* @param {number} options.timeout - the maximum time to wait for the boolean condition to be true
|
|
30
|
+
* @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
|
|
31
31
|
*/ export const waitFor = (bool, { checkTime, timeout } = {})=>{
|
|
32
32
|
return new Promise((resolve, reject)=>{
|
|
33
33
|
let _timeout;
|
package/es/random/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
2
|
-
/**
|
|
3
|
-
* Generates a random string of specified length.
|
|
4
|
-
*
|
|
5
|
-
* @param {number} n - The length of the random string to generate
|
|
6
|
-
* @return {string} The randomly generated string
|
|
2
|
+
/**
|
|
3
|
+
* Generates a random string of specified length.
|
|
4
|
+
*
|
|
5
|
+
* @param {number} n - The length of the random string to generate
|
|
6
|
+
* @return {string} The randomly generated string
|
|
7
7
|
*/ export const random = (n = 8)=>{
|
|
8
8
|
let result = '';
|
|
9
9
|
for(let i = 0; i < n; i++){
|
|
@@ -11,11 +11,11 @@ const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
11
11
|
}
|
|
12
12
|
return result;
|
|
13
13
|
};
|
|
14
|
-
/**
|
|
15
|
-
* Generates a random number within the specified range.
|
|
16
|
-
*
|
|
17
|
-
* @param {number[]} range - The range within which to generate the random number.
|
|
18
|
-
* @return {number} The randomly generated number within the specified range.
|
|
14
|
+
/**
|
|
15
|
+
* Generates a random number within the specified range.
|
|
16
|
+
*
|
|
17
|
+
* @param {number[]} range - The range within which to generate the random number.
|
|
18
|
+
* @return {number} The randomly generated number within the specified range.
|
|
19
19
|
*/ export const randomRangeNum = (range)=>{
|
|
20
20
|
const [min, max] = range[0] < range[1] ? [
|
|
21
21
|
range[0],
|
package/es/sleep/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asynchronous function to sleep for a specified amount of time.
|
|
3
|
-
*
|
|
4
|
-
* @param {number} time - The duration in milliseconds to sleep
|
|
5
|
-
* @return {Promise<void>} A promise that resolves after the specified time
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronous function to sleep for a specified amount of time.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} time - The duration in milliseconds to sleep
|
|
5
|
+
* @return {Promise<void>} A promise that resolves after the specified time
|
|
6
6
|
*/ export const sleep = (time)=>{
|
|
7
7
|
return new Promise((resolve)=>setTimeout(resolve, time));
|
|
8
8
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -21,4 +21,5 @@ export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree, reflection }
|
|
|
21
21
|
export * as UTM from './math/utm';
|
|
22
22
|
export { BufferSplit } from './buf';
|
|
23
23
|
export * as FP from './fp';
|
|
24
|
-
export {
|
|
24
|
+
export { ResourceHandler, ResourceManager } from './factory/resource-manager';
|
|
25
|
+
export type { ResourceHandlerParams, ResourceHandlerState } from './factory/resource-manager';
|
package/lib/index.js
CHANGED
|
@@ -48,12 +48,6 @@ _export(exports, {
|
|
|
48
48
|
ResourceHandler: function() {
|
|
49
49
|
return _resourcemanager.ResourceHandler;
|
|
50
50
|
},
|
|
51
|
-
ResourceHandlerParams: function() {
|
|
52
|
-
return _resourcemanager.ResourceHandlerParams;
|
|
53
|
-
},
|
|
54
|
-
ResourceHandlerState: function() {
|
|
55
|
-
return _resourcemanager.ResourceHandlerState;
|
|
56
|
-
},
|
|
57
51
|
ResourceManager: function() {
|
|
58
52
|
return _resourcemanager.ResourceManager;
|
|
59
53
|
},
|
package/lib/sleep/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asynchronous function to sleep for a specified amount of time.
|
|
3
|
-
*
|
|
4
|
-
* @param {number} time - The duration in milliseconds to sleep
|
|
5
|
-
* @return {Promise<void>} A promise that resolves after the specified time
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronous function to sleep for a specified amount of time.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} time - The duration in milliseconds to sleep
|
|
5
|
+
* @return {Promise<void>} A promise that resolves after the specified time
|
|
6
6
|
*/ "use strict";
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
package/package.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.210",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
|
-
"unpkg": "dist/index.js",
|
|
8
7
|
"sideEffects": false,
|
|
9
8
|
"scripts": {
|
|
10
|
-
"build": "gulp
|
|
9
|
+
"build": "gulp"
|
|
11
10
|
},
|
|
12
11
|
"files": [
|
|
13
|
-
"dist",
|
|
14
12
|
"lib",
|
|
15
13
|
"es",
|
|
16
14
|
"package.json"
|
|
@@ -18,7 +16,7 @@
|
|
|
18
16
|
"engines": {
|
|
19
17
|
"node": ">=8.0.0"
|
|
20
18
|
},
|
|
21
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "aff7b585c4f83e46aa8838a337d448948caaee7d",
|
|
22
20
|
"devDependencies": {
|
|
23
21
|
"del": "^5.1.0",
|
|
24
22
|
"eslint": "^8.42.0",
|
|
@@ -27,9 +25,6 @@
|
|
|
27
25
|
"gulp-typescript": "^6.0.0-alpha.1",
|
|
28
26
|
"prettier": "^2.8.8",
|
|
29
27
|
"pretty-quick": "^2.0.1",
|
|
30
|
-
"typescript": "^4.9.5"
|
|
31
|
-
"webpack": "^5.75.0",
|
|
32
|
-
"webpack-cli": "^5.0.1",
|
|
33
|
-
"webpack-merge": "^5.8.0"
|
|
28
|
+
"typescript": "^4.9.5"
|
|
34
29
|
}
|
|
35
30
|
}
|
package/dist/pubo-utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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})()));
|