pubo-utils 1.0.162 → 1.0.167
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/dist/pubo-utils.js +1 -1
- package/es/color/utils.d.ts +11 -0
- package/es/color/utils.js +100 -0
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/es/math/geometry.d.ts +1 -1
- package/es/math/geometry.js +4 -1
- package/es/queue/index.d.ts +1 -0
- package/es/queue/index.js +20 -0
- package/lib/color/utils.d.ts +11 -0
- package/lib/color/utils.js +103 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +9 -0
- package/lib/math/geometry.d.ts +1 -1
- package/lib/math/geometry.js +4 -1
- package/lib/queue/index.d.ts +1 -0
- package/lib/queue/index.js +31 -3
- package/package.json +2 -2
package/dist/pubo-utils.js
CHANGED
|
@@ -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,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:()=>g,Emitter:()=>c,HistoryStack:()=>x,Level:()=>w,RegExpList:()=>N,SensorDataFilter:()=>L,StringSplit:()=>U,SyncQueue:()=>m,WatchDog:()=>T,callbackToPromise:()=>b,cloneDeep:()=>D,debounce:()=>s,degrees:()=>_,filterKeyPoints:()=>k,getAngle:()=>S,getBestPointIndex:()=>E,getCenter:()=>P,getDistance:()=>M,getPositionTheta:()=>A,getRotate:()=>j,getVectorTheta:()=>R,hex2rgb:()=>n,loop:()=>l,lower2camel:()=>I,orderByDistance:()=>O,radians:()=>v,random:()=>o,randomRangeNum:()=>r,retry:()=>p,sleep:()=>a,superFactory:()=>h,throttle:()=>f,waitFor:()=>u});var i={};t.r(i),t.d(i,{EncoderMap:()=>y,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},a=async t=>{await new Promise((e=>{let i=setTimeout((()=>{e(),clearTimeout(i),i=null}),t)}))},l=(t,e)=>{let i=!0,s=()=>{i=!1},n=async()=>{try{await t()}catch(t){console.log(t)}await a(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=l((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))})),p=(t,{times:e=5,interval:i=1e3}={times:5,interval:1e3})=>{let s=1;const n=async(...o)=>{let r;if(s>e)throw new Error("retry times exceed");try{return r=await t(...o),r}catch(t){return console.log(`action error, times ${s}`),console.log(t),await a(i),s+=1,n(...o)}};return n};class m{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 f(t,e){const i=new m;let s=[];return(...n)=>{if(s=n,!(i.length>0))return i.push((async()=>{await a(e),await t(...s)}))}}class g{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 y=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)+y[t.charAt(o)],i+=6,i>=8){i-=8;let t=s>>>i;e[n++]=255&t,t<<=i,s-=t}return e}class x{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 T{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 w{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,v=t=>t*Math.PI/180,S=({w:t,h:e})=>_(Math.atan2(e,t));function k(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 P(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 j(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)},E=(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},O=(t,e={x:0,y:0,theta:0})=>{let i=e;const s=[],n=[...t];for(;n.length>0;){const t=E(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),I=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join("");class N{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 L{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 U{_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 D(t,e=new WeakMap){if("object"!=typeof t||null===t)return t;if(e.has(t))return e.get(t);const i={};return Object.keys(t).forEach((s=>{const n=t[s];"object"!=typeof n||null===n?i[s]=n:Array.isArray(n)?i[s]=n.map((t=>D(t,e))):n instanceof Set?i[s]=new Set([...n]):n instanceof Map?i[s]=new Map([...n]):(e.set(t,t),i[s]=D(n,e))})),i}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,ColorUtils:()=>h,ContinuousTrigger:()=>w,Emitter:()=>u,HistoryStack:()=>_,Level:()=>S,LinearColor:()=>a,RegExpList:()=>z,SensorDataFilter:()=>B,StringSplit:()=>F,SyncQueue:()=>d,WatchDog:()=>A,callbackToPromise:()=>k,cloneDeep:()=>W,debounce:()=>s,degrees:()=>P,filterKeyPoints:()=>R,getAngle:()=>E,getBestPointIndex:()=>N,getCenter:()=>O,getDistance:()=>v,getPositionTheta:()=>L,getRotate:()=>I,getVectorTheta:()=>C,hex2rgb:()=>r,loop:()=>f,lower2camel:()=>D,orderByDistance:()=>U,radians:()=>j,random:()=>c,randomRangeNum:()=>l,retry:()=>y,runAsyncTasks:()=>x,sleep:()=>p,superFactory:()=>m,throttle:()=>b,waitFor:()=>g});var i={};t.r(i),t.d(i,{EncoderMap:()=>T,toUnit8Array:()=>M});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=>parseInt(t.replace("#",""),16),r=t=>{let e;e="string"==typeof t?n(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=>"#"+[0,1,2].map((e=>t[e].toString(16))).join("");class h{int;constructor(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=n(t):Array.isArray(t)&&(this.int=n(o(t)))}getRgbArray(){return r(this.int)}get rgb(){return`rba(${this.getRgbArray().join(", ")})`}get hex(){return o(this.getRgbArray())}toString(t="hex"){return"rgb"===t?this.rgb:this.hex}}class a{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],i=this.base[1],s=this.base[2],n=t*this.intensity;return i=this.base[1]+n,i<this.max||(n=i-this.max,i=this.max,e=this.base[0]-n,e>this.min||(n=this.min-e,e=this.min,s=this.base[2]+n,s<this.max||(n=s-this.max,s=this.max,i-=n,i>this.min||(n=this.min-i,i=this.min,e+=n,e<this.max||(n=e-this.max,e=this.max,s-=n,s>this.min||(s=this.min)))))),[e,i,s]}}const c=(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},l=t=>{const e=Math.abs(t[1]-t[0]);return Math.random()*e+Math.min(...t)};class u{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=c(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 m=t=>e=>{const i={};for(const s of Object.keys(e))i[s]=t(e[s],s);return i},p=async t=>{await new Promise((e=>{let i=setTimeout((()=>{e(),clearTimeout(i),i=null}),t)}))},f=(t,e)=>{let i=!0,s=()=>{i=!1},n=async()=>{try{await t()}catch(t){console.log(t)}await p(e),i?n():(n=null,t=null,s=null,i=null,e=null)};return n(),s},g=(t,{checkTime:e,timeout:i}={})=>new Promise(((s,n)=>{let r,o=f((async()=>{const e=await t();e&&("function"==typeof o&&o(),r&&(clearTimeout(r),r=null),s(e),o=null,t=null,s=null)}),e||100);i&&(r=setTimeout((()=>{"function"==typeof o&&o(),r&&(clearTimeout(r),r=null),n("timeout"),n=null,o=null,t=null}),i))})),y=(t,{times:e=5,interval:i=1e3}={times:5,interval:1e3})=>{let s=1;const n=async(...r)=>{let o;if(s>e)throw new Error("retry times exceed");try{return o=await t(...r),o}catch(t){return console.log(`action error, times ${s}`),console.log(t),await p(i),s+=1,n(...r)}};return n};class d{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}}const x=async(t,e=4)=>{let i=-1;const s=[],n=async()=>{if(i+=1,t[i]){try{await t[i]()}catch(t){console.log(t)}await n()}};for(let t=0;t<e;t+=1)s.push(n());await Promise.all(s)};function b(t,e){const i=new d;let s=[];return(...n)=>{if(s=n,!(i.length>0))return i.push((async()=>{await p(e),await t(...s)}))}}class w{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 T=function(){const t={};for(let e=0;e<64;e++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;return t}();function M(t){const e=new Uint8Array(6*t.length/8);let i=0,s=0,n=0;for(let r=0;r<t.length&&n<e.length;r+=1)if(s=(s<<6)+T[t.charAt(r)],i+=6,i>=8){i-=8;let t=s>>>i;e[n++]=255&t,t<<=i,s-=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 A{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 S{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 k=t=>(...e)=>new Promise(((i,s)=>{t(...e,((t,...e)=>{t&&s(t),e.length<2?i(e[0]):i([...e])})),t=null})),v=(t,e)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),P=t=>180*t/Math.PI,j=t=>t*Math.PI/180,E=({w:t,h:e})=>P(Math.atan2(e,t));function R(t,e=.5){if(t.length<3||e<=0)return t;let i;return t.filter(((s,n)=>!(n>0&&v(i,s)<e||(i=t[n],0))))}function O(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 I(t,e,i){return i&&(e=j(e)),[Math.cos(e)*t[0]-Math.sin(e)*t[1],Math.sin(e)*t[0]+Math.cos(e)*t[1]]}const L=(t,e)=>{const i={x:e.x-t.x,y:e.y-t.y};return Math.atan2(i.y,i.x)},N=(t,e)=>{if(t.length<2)return 0;const i=[];let s=1/0,n=0;for(const r of t){const t=v(r,e),o=L(e,r)-e.theta;s>t&&(s=t),i.push({...r,index:n,distance:t,theta:o}),n+=1}return i.filter((t=>t.distance-s<.1)).sort(((t,e)=>t.theta-e.theta))[0].index},U=(t,e={x:0,y:0,theta:0})=>{let i=e;const s=[],n=[...t];for(;n.length>0;){const t=N(n,i);s.push(n[t]),i=n[t],n.splice(t,1)}return s},C=(t,e)=>Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x),D=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join("");class z{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 B{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 F{_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 W(t,e=new WeakMap){if("object"!=typeof t||null===t)return t;if(e.has(t))return e.get(t);const i={};return Object.keys(t).forEach((s=>{const n=t[s];"object"!=typeof n||null===n?i[s]=n:Array.isArray(n)?i[s]=n.map((t=>W(t,e))):n instanceof Set?i[s]=new Set([...n]):n instanceof Map?i[s]=new Map([...n]):(e.set(t,t),i[s]=W(n,e))})),i}return e})()));
|
package/es/color/utils.d.ts
CHANGED
|
@@ -8,3 +8,14 @@ export declare class ColorUtils {
|
|
|
8
8
|
get hex(): string;
|
|
9
9
|
toString(type?: string): string;
|
|
10
10
|
}
|
|
11
|
+
export declare class LinearColor {
|
|
12
|
+
private readonly base;
|
|
13
|
+
private intensity;
|
|
14
|
+
private readonly min;
|
|
15
|
+
private readonly max;
|
|
16
|
+
constructor({ base, intensity }?: {
|
|
17
|
+
base?: [number, number, number];
|
|
18
|
+
intensity?: number;
|
|
19
|
+
});
|
|
20
|
+
getColor(value: number): number[];
|
|
21
|
+
}
|
package/es/color/utils.js
CHANGED
|
@@ -50,3 +50,103 @@ export class ColorUtils {
|
|
|
50
50
|
return this.hex;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
export class LinearColor {
|
|
54
|
+
base = [
|
|
55
|
+
255,
|
|
56
|
+
0,
|
|
57
|
+
0
|
|
58
|
+
];
|
|
59
|
+
intensity = 1;
|
|
60
|
+
min;
|
|
61
|
+
max;
|
|
62
|
+
constructor({ base = [
|
|
63
|
+
255,
|
|
64
|
+
0,
|
|
65
|
+
0
|
|
66
|
+
], intensity = 1 } = {}){
|
|
67
|
+
this.base = base;
|
|
68
|
+
this.intensity = intensity;
|
|
69
|
+
if (this.intensity < 1) {
|
|
70
|
+
this.intensity = 1;
|
|
71
|
+
}
|
|
72
|
+
this.min = this.base[1];
|
|
73
|
+
this.max = this.base[0];
|
|
74
|
+
if (Math.abs(this.min - this.max) < 1) {
|
|
75
|
+
this.min = 0;
|
|
76
|
+
this.max = 255;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
getColor(value) {
|
|
80
|
+
if (value < 0) {
|
|
81
|
+
return this.base;
|
|
82
|
+
}
|
|
83
|
+
let r = this.base[0];
|
|
84
|
+
let g = this.base[1];
|
|
85
|
+
let b = this.base[2];
|
|
86
|
+
let n = value * this.intensity;
|
|
87
|
+
g = this.base[1] + n;
|
|
88
|
+
if (g < this.max) {
|
|
89
|
+
return [
|
|
90
|
+
r,
|
|
91
|
+
g,
|
|
92
|
+
b
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
n = g - this.max;
|
|
96
|
+
g = this.max;
|
|
97
|
+
r = this.base[0] - n;
|
|
98
|
+
if (r > this.min) {
|
|
99
|
+
return [
|
|
100
|
+
r,
|
|
101
|
+
g,
|
|
102
|
+
b
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
n = this.min - r;
|
|
106
|
+
r = this.min;
|
|
107
|
+
b = this.base[2] + n;
|
|
108
|
+
if (b < this.max) {
|
|
109
|
+
return [
|
|
110
|
+
r,
|
|
111
|
+
g,
|
|
112
|
+
b
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
n = b - this.max;
|
|
116
|
+
b = this.max;
|
|
117
|
+
g = g - n;
|
|
118
|
+
if (g > this.min) {
|
|
119
|
+
return [
|
|
120
|
+
r,
|
|
121
|
+
g,
|
|
122
|
+
b
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
n = this.min - g;
|
|
126
|
+
g = this.min;
|
|
127
|
+
r = r + n;
|
|
128
|
+
if (r < this.max) {
|
|
129
|
+
return [
|
|
130
|
+
r,
|
|
131
|
+
g,
|
|
132
|
+
b
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
n = r - this.max;
|
|
136
|
+
r = this.max;
|
|
137
|
+
b = b - n;
|
|
138
|
+
if (b > this.min) {
|
|
139
|
+
return [
|
|
140
|
+
r,
|
|
141
|
+
g,
|
|
142
|
+
b
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
b = this.min;
|
|
146
|
+
return [
|
|
147
|
+
r,
|
|
148
|
+
g,
|
|
149
|
+
b
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
}
|
package/es/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { debounce } from './debounce';
|
|
2
|
-
export { hex2rgb } from './color/utils';
|
|
2
|
+
export { hex2rgb, LinearColor, ColorUtils } from './color/utils';
|
|
3
3
|
export { Emitter } from './emitter';
|
|
4
4
|
export { superFactory } from './factory';
|
|
5
5
|
export { loop, waitFor, retry } from './loop';
|
|
6
|
-
export { SyncQueue } from './queue';
|
|
6
|
+
export { SyncQueue, runAsyncTasks } from './queue';
|
|
7
7
|
export { random, randomRangeNum } from './random';
|
|
8
8
|
export { sleep } from './sleep';
|
|
9
9
|
export { throttle } from './throttle';
|
package/es/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { debounce } from './debounce';
|
|
2
|
-
export { hex2rgb } from './color/utils';
|
|
2
|
+
export { hex2rgb, LinearColor, ColorUtils } from './color/utils';
|
|
3
3
|
export { Emitter } from './emitter';
|
|
4
4
|
export { superFactory } from './factory';
|
|
5
5
|
export { loop, waitFor, retry } from './loop';
|
|
6
|
-
export { SyncQueue } from './queue';
|
|
6
|
+
export { SyncQueue, runAsyncTasks } from './queue';
|
|
7
7
|
export { random, randomRangeNum } from './random';
|
|
8
8
|
export { sleep } from './sleep';
|
|
9
9
|
export { throttle } from './throttle';
|
package/es/math/geometry.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const getAngle: ({ w, h }: {
|
|
|
12
12
|
}) => number;
|
|
13
13
|
export declare function filterKeyPoints(list: Point2D[], len?: number): Point2D[];
|
|
14
14
|
export declare function getCenter(list: Point2D[] | [number, number][]): Point2D;
|
|
15
|
-
export declare function getRotate(data: Vector2D, theta: number): Vector2D;
|
|
15
|
+
export declare function getRotate(data: Vector2D, theta: number, isDeg?: boolean): Vector2D;
|
|
16
16
|
export declare const getPositionTheta: (a: Point2D, b: Point2D) => number;
|
|
17
17
|
export declare const getBestPointIndex: (points: Point2D[], pose: Point2D & {
|
|
18
18
|
theta: number;
|
package/es/math/geometry.js
CHANGED
|
@@ -49,7 +49,10 @@ export function getCenter(list) {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
// 2D旋转
|
|
52
|
-
export function getRotate(data, theta) {
|
|
52
|
+
export function getRotate(data, theta, isDeg) {
|
|
53
|
+
if (isDeg) {
|
|
54
|
+
theta = radians(theta);
|
|
55
|
+
}
|
|
53
56
|
const x = Math.cos(theta) * data[0] - Math.sin(theta) * data[1];
|
|
54
57
|
const y = Math.sin(theta) * data[0] + Math.cos(theta) * data[1];
|
|
55
58
|
return [
|
package/es/queue/index.d.ts
CHANGED
package/es/queue/index.js
CHANGED
|
@@ -45,3 +45,23 @@ export class SyncQueue {
|
|
|
45
45
|
return this.len;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
export const runAsyncTasks = async (list, j = 4)=>{
|
|
49
|
+
let i = -1;
|
|
50
|
+
const t = [];
|
|
51
|
+
const run = async ()=>{
|
|
52
|
+
i += 1;
|
|
53
|
+
if (!list[i]) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
await list[i]();
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.log(err);
|
|
60
|
+
}
|
|
61
|
+
await run();
|
|
62
|
+
};
|
|
63
|
+
for(let n = 0; n < j; n += 1){
|
|
64
|
+
t.push(run());
|
|
65
|
+
}
|
|
66
|
+
await Promise.all(t);
|
|
67
|
+
};
|
package/lib/color/utils.d.ts
CHANGED
|
@@ -8,3 +8,14 @@ export declare class ColorUtils {
|
|
|
8
8
|
get hex(): string;
|
|
9
9
|
toString(type?: string): string;
|
|
10
10
|
}
|
|
11
|
+
export declare class LinearColor {
|
|
12
|
+
private readonly base;
|
|
13
|
+
private intensity;
|
|
14
|
+
private readonly min;
|
|
15
|
+
private readonly max;
|
|
16
|
+
constructor({ base, intensity }?: {
|
|
17
|
+
base?: [number, number, number];
|
|
18
|
+
intensity?: number;
|
|
19
|
+
});
|
|
20
|
+
getColor(value: number): number[];
|
|
21
|
+
}
|
package/lib/color/utils.js
CHANGED
|
@@ -12,6 +12,9 @@ _export(exports, {
|
|
|
12
12
|
ColorUtils: function() {
|
|
13
13
|
return ColorUtils;
|
|
14
14
|
},
|
|
15
|
+
LinearColor: function() {
|
|
16
|
+
return LinearColor;
|
|
17
|
+
},
|
|
15
18
|
hex2rgb: function() {
|
|
16
19
|
return hex2rgb;
|
|
17
20
|
},
|
|
@@ -71,3 +74,103 @@ class ColorUtils {
|
|
|
71
74
|
return this.hex;
|
|
72
75
|
}
|
|
73
76
|
}
|
|
77
|
+
class LinearColor {
|
|
78
|
+
base = [
|
|
79
|
+
255,
|
|
80
|
+
0,
|
|
81
|
+
0
|
|
82
|
+
];
|
|
83
|
+
intensity = 1;
|
|
84
|
+
min;
|
|
85
|
+
max;
|
|
86
|
+
constructor({ base = [
|
|
87
|
+
255,
|
|
88
|
+
0,
|
|
89
|
+
0
|
|
90
|
+
], intensity = 1 } = {}){
|
|
91
|
+
this.base = base;
|
|
92
|
+
this.intensity = intensity;
|
|
93
|
+
if (this.intensity < 1) {
|
|
94
|
+
this.intensity = 1;
|
|
95
|
+
}
|
|
96
|
+
this.min = this.base[1];
|
|
97
|
+
this.max = this.base[0];
|
|
98
|
+
if (Math.abs(this.min - this.max) < 1) {
|
|
99
|
+
this.min = 0;
|
|
100
|
+
this.max = 255;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
getColor(value) {
|
|
104
|
+
if (value < 0) {
|
|
105
|
+
return this.base;
|
|
106
|
+
}
|
|
107
|
+
let r = this.base[0];
|
|
108
|
+
let g = this.base[1];
|
|
109
|
+
let b = this.base[2];
|
|
110
|
+
let n = value * this.intensity;
|
|
111
|
+
g = this.base[1] + n;
|
|
112
|
+
if (g < this.max) {
|
|
113
|
+
return [
|
|
114
|
+
r,
|
|
115
|
+
g,
|
|
116
|
+
b
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
n = g - this.max;
|
|
120
|
+
g = this.max;
|
|
121
|
+
r = this.base[0] - n;
|
|
122
|
+
if (r > this.min) {
|
|
123
|
+
return [
|
|
124
|
+
r,
|
|
125
|
+
g,
|
|
126
|
+
b
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
n = this.min - r;
|
|
130
|
+
r = this.min;
|
|
131
|
+
b = this.base[2] + n;
|
|
132
|
+
if (b < this.max) {
|
|
133
|
+
return [
|
|
134
|
+
r,
|
|
135
|
+
g,
|
|
136
|
+
b
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
n = b - this.max;
|
|
140
|
+
b = this.max;
|
|
141
|
+
g = g - n;
|
|
142
|
+
if (g > this.min) {
|
|
143
|
+
return [
|
|
144
|
+
r,
|
|
145
|
+
g,
|
|
146
|
+
b
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
n = this.min - g;
|
|
150
|
+
g = this.min;
|
|
151
|
+
r = r + n;
|
|
152
|
+
if (r < this.max) {
|
|
153
|
+
return [
|
|
154
|
+
r,
|
|
155
|
+
g,
|
|
156
|
+
b
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
n = r - this.max;
|
|
160
|
+
r = this.max;
|
|
161
|
+
b = b - n;
|
|
162
|
+
if (b > this.min) {
|
|
163
|
+
return [
|
|
164
|
+
r,
|
|
165
|
+
g,
|
|
166
|
+
b
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
b = this.min;
|
|
170
|
+
return [
|
|
171
|
+
r,
|
|
172
|
+
g,
|
|
173
|
+
b
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { debounce } from './debounce';
|
|
2
|
-
export { hex2rgb } from './color/utils';
|
|
2
|
+
export { hex2rgb, LinearColor, ColorUtils } from './color/utils';
|
|
3
3
|
export { Emitter } from './emitter';
|
|
4
4
|
export { superFactory } from './factory';
|
|
5
5
|
export { loop, waitFor, retry } from './loop';
|
|
6
|
-
export { SyncQueue } from './queue';
|
|
6
|
+
export { SyncQueue, runAsyncTasks } from './queue';
|
|
7
7
|
export { random, randomRangeNum } from './random';
|
|
8
8
|
export { sleep } from './sleep';
|
|
9
9
|
export { throttle } from './throttle';
|
package/lib/index.js
CHANGED
|
@@ -12,6 +12,9 @@ _export(exports, {
|
|
|
12
12
|
Base64Utils: function() {
|
|
13
13
|
return _base64;
|
|
14
14
|
},
|
|
15
|
+
ColorUtils: function() {
|
|
16
|
+
return _utils.ColorUtils;
|
|
17
|
+
},
|
|
15
18
|
ContinuousTrigger: function() {
|
|
16
19
|
return _trigger.ContinuousTrigger;
|
|
17
20
|
},
|
|
@@ -24,6 +27,9 @@ _export(exports, {
|
|
|
24
27
|
Level: function() {
|
|
25
28
|
return _level.Level;
|
|
26
29
|
},
|
|
30
|
+
LinearColor: function() {
|
|
31
|
+
return _utils.LinearColor;
|
|
32
|
+
},
|
|
27
33
|
RegExpList: function() {
|
|
28
34
|
return _regexplist.RegExpList;
|
|
29
35
|
},
|
|
@@ -99,6 +105,9 @@ _export(exports, {
|
|
|
99
105
|
retry: function() {
|
|
100
106
|
return _loop.retry;
|
|
101
107
|
},
|
|
108
|
+
runAsyncTasks: function() {
|
|
109
|
+
return _queue.runAsyncTasks;
|
|
110
|
+
},
|
|
102
111
|
sleep: function() {
|
|
103
112
|
return _sleep.sleep;
|
|
104
113
|
},
|
package/lib/math/geometry.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const getAngle: ({ w, h }: {
|
|
|
12
12
|
}) => number;
|
|
13
13
|
export declare function filterKeyPoints(list: Point2D[], len?: number): Point2D[];
|
|
14
14
|
export declare function getCenter(list: Point2D[] | [number, number][]): Point2D;
|
|
15
|
-
export declare function getRotate(data: Vector2D, theta: number): Vector2D;
|
|
15
|
+
export declare function getRotate(data: Vector2D, theta: number, isDeg?: boolean): Vector2D;
|
|
16
16
|
export declare const getPositionTheta: (a: Point2D, b: Point2D) => number;
|
|
17
17
|
export declare const getBestPointIndex: (points: Point2D[], pose: Point2D & {
|
|
18
18
|
theta: number;
|
package/lib/math/geometry.js
CHANGED
|
@@ -87,7 +87,10 @@ function getCenter(list) {
|
|
|
87
87
|
y: tmp[1] / list.length
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
-
function getRotate(data, theta) {
|
|
90
|
+
function getRotate(data, theta, isDeg) {
|
|
91
|
+
if (isDeg) {
|
|
92
|
+
theta = radians(theta);
|
|
93
|
+
}
|
|
91
94
|
const x = Math.cos(theta) * data[0] - Math.sin(theta) * data[1];
|
|
92
95
|
const y = Math.sin(theta) * data[0] + Math.cos(theta) * data[1];
|
|
93
96
|
return [
|
package/lib/queue/index.d.ts
CHANGED
package/lib/queue/index.js
CHANGED
|
@@ -2,10 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
SyncQueue: function() {
|
|
8
13
|
return SyncQueue;
|
|
14
|
+
},
|
|
15
|
+
runAsyncTasks: function() {
|
|
16
|
+
return runAsyncTasks;
|
|
9
17
|
}
|
|
10
18
|
});
|
|
11
19
|
class SyncQueue {
|
|
@@ -55,3 +63,23 @@ class SyncQueue {
|
|
|
55
63
|
return this.len;
|
|
56
64
|
}
|
|
57
65
|
}
|
|
66
|
+
const runAsyncTasks = async (list, j = 4)=>{
|
|
67
|
+
let i = -1;
|
|
68
|
+
const t = [];
|
|
69
|
+
const run = async ()=>{
|
|
70
|
+
i += 1;
|
|
71
|
+
if (!list[i]) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
await list[i]();
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.log(err);
|
|
78
|
+
}
|
|
79
|
+
await run();
|
|
80
|
+
};
|
|
81
|
+
for(let n = 0; n < j; n += 1){
|
|
82
|
+
t.push(run());
|
|
83
|
+
}
|
|
84
|
+
await Promise.all(t);
|
|
85
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.167",
|
|
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": "
|
|
21
|
+
"gitHead": "3e19f954e9f9cf7e8c358012818b9578007df8a0",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"del": "^5.1.0",
|
|
24
24
|
"eslint": "^8.42.0",
|