pubo-utils 1.0.117 → 1.0.129
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/LICENSE.md +21 -0
- package/dist/pubo-utils.js +1 -1
- package/es/emitter/index.d.ts +9 -3
- package/es/emitter/index.js +42 -44
- package/es/index.d.ts +1 -1
- package/es/index.js +2 -2
- package/es/math/geometry.d.ts +7 -6
- package/es/math/geometry.js +2 -0
- package/es/str.d.ts +1 -0
- package/es/str.js +6 -0
- package/lib/emitter/index.d.ts +9 -3
- package/lib/emitter/index.js +43 -45
- package/lib/index.d.ts +1 -1
- package/lib/index.js +8 -8
- package/lib/math/geometry.d.ts +7 -6
- package/lib/math/geometry.js +2 -0
- package/lib/str.d.ts +1 -0
- package/lib/str.js +13 -0
- package/package.json +2 -2
- package/es/array/index.d.ts +0 -1
- package/es/array/index.js +0 -25
- package/lib/array/index.d.ts +0 -1
- package/lib/array/index.js +0 -32
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2024] [pubo]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/pubo-utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["pubo-utils"]=n():t["pubo-utils"]=n()}(this,(()=>(()=>{"use strict";var t={d:(n,e)=>{for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};t.r(n),t.d(n,{Base64Utils:()=>e,ContinuousTrigger:()=>O,Emitter:()=>d,HistoryStack:()=>R,Level:()=>N,RegExpList:()=>Y,SensorDataFilter:()=>$,StringSplit:()=>tt,SyncQueue:()=>A,WatchDog:()=>I,callbackToPromise:()=>G,concatArray:()=>Z,debounce:()=>i,degrees:()=>U,filterKeyPoints:()=>q,getAngle:()=>X,getBestPointIndex:()=>V,getCenter:()=>H,getDistance:()=>F,getPositionTheta:()=>Q,getRotate:()=>K,getVectorTheta:()=>J,hex2rgb:()=>a,loop:()=>x,orderByDistance:()=>W,radians:()=>C,random:()=>s,randomRangeNum:()=>f,sleep:()=>g,superFactory:()=>b,throttle:()=>M,waitFor:()=>S});var e={};t.r(e),t.d(e,{EncoderMap:()=>E,toUnit8Array:()=>_});var r=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},o=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},i=function(t,n,e){if(void 0===e&&(e=!1),e){var i,u=!0;return function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];u&&(t.apply(void 0,o([],r(e),!1)),u=!1),i&&clearTimeout(i),i=setTimeout((function(){return u=!0}),n)}}var a;return function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];a&&clearTimeout(a),a=setTimeout((function(){return t.apply(void 0,o([],r(e),!1))}),n)}},u=function(t){return parseInt(t.replace("#",""),16)},a=function(t){var n=("string"==typeof t?u(t):t).toString(2).padStart(24,"0");return[parseInt(n.slice(0,8),2),parseInt(n.slice(8,16),2),parseInt(n.slice(16,24),2)]},c=function(t){return"#"+[0,1,2].map((function(n){return t[n].toString(16)})).join("")},l=(function(){function t(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=u(t):Array.isArray(t)&&(this.int=u(c(t)))}t.prototype.getRgbArray=function(){return a(this.int)},Object.defineProperty(t.prototype,"rgb",{get:function(){return"rba(".concat(this.getRgbArray().join(", "),")")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hex",{get:function(){return c(this.getRgbArray())},enumerable:!1,configurable:!0}),t.prototype.toString=function(t){return void 0===t&&(t="hex"),"rgb"===t?this.rgb:this.hex}}(),function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}),s=function(t){void 0===t&&(t=8);var n=function(t){return Math.random().toString(32).slice(2,2+t)};if(t<=8)return n(t);for(var e="",r=0;r<=t;r+=8)e+=n(t-r>8?8:t-r);return e},f=function(t){var n=Math.abs(t[1]-t[0]);return Math.random()*n+Math.min.apply(Math,function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}([],l(t),!1))},h=function(){return h=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},h.apply(this,arguments)},p=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},y=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},v=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},d=function(){function t(){this.state={},this.ids={}}return t.prototype.on=function(t,n){if(this.state[t]||(this.state[t]=[]),"function"!=typeof n)throw new Error("第二个参数必须为function!");var e=this.state[t].push(n)-1,r=s(40);return this.ids[r]={event:t,index:e},r},t.prototype.cancel=function(t){var n=this;if(t){var e=this.ids[t]||{},r=e.event,o=e.index;r&&Array.isArray(this.state[r])&&(this.state[r].splice(o,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){n.ids[t].event===r&&n.ids[t].index>o&&(n.ids[t].index=n.ids[t].index-1)})))}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t){for(var n,e,r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];if(Array.isArray(this.state[t]))try{for(var i=p(this.state[t]),u=i.next();!u.done;u=i.next()){var a=u.value;"function"==typeof a&&a.apply(void 0,v([],y(r),!1))}}catch(t){n={error:t}}finally{try{u&&!u.done&&(e=i.return)&&e.call(i)}finally{if(n)throw n.error}}},t.prototype.emitSync=function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return r=this,o=void 0,u=function(){var e,r,o,i,u,a;return function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,(function(c){switch(c.label){case 0:if(!Array.isArray(this.state[t]))return[3,8];c.label=1;case 1:c.trys.push([1,6,7,8]),e=p(this.state[t]),r=e.next(),c.label=2;case 2:return r.done?[3,5]:"function"!=typeof(o=r.value)?[3,4]:[4,o.apply(void 0,v([],y(n),!1))];case 3:c.sent(),c.label=4;case 4:return r=e.next(),[3,2];case 5:return[3,8];case 6:return i=c.sent(),u={error:i},[3,8];case 7:try{r&&!r.done&&(a=e.return)&&a.call(e)}finally{if(u)throw u.error}return[7];case 8:return[2]}}))},new((i=void 0)||(i=Promise))((function(t,n){function e(t){try{c(u.next(t))}catch(t){n(t)}}function a(t){try{c(u.throw(t))}catch(t){n(t)}}function c(n){var r;n.done?t(n.value):(r=n.value,r instanceof i?r:new i((function(t){t(r)}))).then(e,a)}c((u=u.apply(r,o||[])).next())}));var r,o,i,u},t.prototype.clone=function(){return{state:h({},this.state),ids:h({},this.ids)}},t.prototype.restore=function(t){this.state=t.state,this.ids=t.ids},t}(),b=function(t){return function(n){var e,r,o={};try{for(var i=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.keys(n)),u=i.next();!u.done;u=i.next()){var a=u.value;o[a]=t(n[a],a)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o}},g=function(t){return n=void 0,e=void 0,o=function(){return function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){return setTimeout((function(){return n()}),t)}))];case 1:return n.sent(),[2]}}))},new((r=void 0)||(r=Promise))((function(t,i){function u(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(n){var e;n.done?t(n.value):(e=n.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,a)}c((o=o.apply(n,e||[])).next())}));var n,e,r,o},m=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,a)}c((r=r.apply(t,n||[])).next())}))},w=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},x=function(t,n){var e=!0,r=function(){e=!1},o=function(){return m(void 0,void 0,void 0,(function(){return w(this,(function(i){switch(i.label){case 0:return[4,t(r)];case 1:return i.sent(),[4,g(n)];case 2:return i.sent(),e?o():o=null,[2]}}))}))};return o(),r},S=function(t,n){var e=void 0===n?{}:n,r=e.checkTime,o=e.timeout;return new Promise((function(n,e){var i=x((function(){return m(void 0,void 0,void 0,(function(){var e;return w(this,(function(r){switch(r.label){case 0:return[4,t()];case 1:return(e=r.sent())&&(i(),n(e)),[2]}}))}))}),r||100);o&&setTimeout((function(){i(),e("timeout")}),o)}))},T=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,a)}c((r=r.apply(t,n||[])).next())}))},k=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},A=function(){function t(){this.cache=[],this.running=!1,this.len=0}return t.prototype._run=function(t){var n=t.fn,e=t.promise;return T(this,void 0,void 0,(function(){var t,r;return k(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,n()];case 1:return t=o.sent(),e.resolve(t),[3,3];case 2:return r=o.sent(),e.reject(r),[3,3];case 3:return[2]}}))}))},t.prototype.run=function(){return T(this,void 0,void 0,(function(){var t;return k(this,(function(n){switch(n.label){case 0:return this.cache.length<1?(this.running=!1,[2]):(this.running=!0,t=this.cache.shift(),this.len-=1,"function"!=typeof t.fn?[3,2]:[4,this._run(t)]);case 1:n.sent(),n.label=2;case 2:return this.run(),[2]}}))}))},t.prototype.push=function(t){var n=this;return this.len+=1,new Promise((function(e,r){n.cache.push({fn:t,promise:{resolve:e,reject:r}}),n.running||n.run()}))},Object.defineProperty(t.prototype,"length",{get:function(){return this.len},enumerable:!1,configurable:!0}),t}(),P=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},j=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))};function M(t,n){var e,r=!0;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];e||(e=setTimeout((function(){r=!0,e=null}),n)),r&&(r=!1,t.apply(void 0,j([],P(o),!1)))}}var O=function(){function t(t){this._count=0,this.props=t}return Object.defineProperty(t.prototype,"count",{get:function(){return this._count},enumerable:!1,configurable:!0}),t.prototype.increment=function(){var t=this;clearTimeout(this.timeout),this.timeout=setTimeout((function(){return t.clear()}),this.props.resetTime),this._count=this._count+1,this._count>this.props.count&&this.props.cb()},t.prototype.clear=function(){this._count=0},t}(),E=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function _(t){for(var n=new Uint8Array(6*t.length/8),e=0,r=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(r=(r<<6)+E[t.charAt(i)],(e+=6)>=8){var u=r>>>(e-=8);n[o++]=255&u,r-=u<<=e}return n}var R=function(){function t(t){void 0===t&&(t=10),this.stack=[],this.len=10,this.point=0,this.len=t}return Object.defineProperty(t.prototype,"current",{get:function(){if(this.point<this.stack.length&&this.point>-1)return this.stack[this.point]},enumerable:!1,configurable:!0}),t.prototype.clear=function(){this.stack.length=0,this.point=0},t.prototype.backup=function(t){this.point>0&&this.stack.length>0&&(this.stack.splice(0,this.point),this.point=0),this.stack.unshift(t),this.stack.length>this.len&&this.stack.pop()},t.prototype.undo=function(){return this.point<this.stack.length-1&&(this.point+=1),this.current},t.prototype.redo=function(){return this.point>0&&(this.point-=1),this.current},t}(),I=function(){function t(t){var n=t.limit,e=void 0===n?10:n,r=t.onTimeout;this.limit=10,this.timeout=null,this.limit=e,this.onTimeout=r}return t.prototype.feed=function(){this.init()},t.prototype.init=function(){var t=this;clearTimeout(this.timeout),this.timeout=setTimeout((function(){return t.onTimeout()}),1e3*this.limit)},t.prototype.stop=function(){this.timeout&&clearTimeout(this.timeout)},t}(),N=function(){function t(t){this.config=t,this.step=(this.config.max-this.config.min)/(this.config.count-2)}return t.prototype.get=function(t){if(t<=this.config.min)return 1;if(t>=this.config.max)return this.config.count;for(var n=2,e=this.config.min+this.step;e<this.config.max+this.step;e+=this.step,n+=1)if(t<e)return n;return this.config.count},t}(),L=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},D=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},G=function(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return new Promise((function(e,r){t.apply(void 0,D(D([],L(n),!1),[function(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];t&&r(t),n.length<2?e(n[0]):e(D([],L(n),!1))}],!1))}))}},z=function(){return z=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},z.apply(this,arguments)},B=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},F=function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2))},U=function(t){return 180*t/Math.PI},C=function(t){return t*Math.PI/180},X=function(t){var n=t.w,e=t.h;return U(Math.atan2(e,n))};function q(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(r,o){return!(o>0&&F(e,r)<n||(e=t[o],0))}));var e}function H(t){var n,e,r=[0,0];try{for(var o=B(t),i=o.next();!i.done;i=o.next()){var u=i.value;Array.isArray(u)?(r[0]+=u[0],r[1]+=u[1]):(r[0]+=u.x,r[1]+=u.y)}}catch(t){n={error:t}}finally{try{i&&!i.done&&(e=o.return)&&e.call(o)}finally{if(n)throw n.error}}return{x:r[0]/t.length,y:r[1]/t.length}}function K(t,n){return[Math.cos(n)*t[0]-Math.sin(n)*t[1],Math.sin(n)*t[0]+Math.cos(n)*t[1]]}var Q=function(t,n){var e={x:n.x-t.x,y:n.y-t.y};return Math.atan2(e.y,e.x)},V=function(t,n){var e,r;if(t.length<2)return 0;var o=[],i=1/0,u=0;try{for(var a=B(t),c=a.next();!c.done;c=a.next()){var l=c.value,s=F(l,n),f=Q(n,l)-n.theta;i>s&&(i=s),o.push(z(z({},l),{index:u,distance:s,theta:f})),u+=1}}catch(t){e={error:t}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}var h=o.filter((function(t){return t.distance-i<.1})).sort((function(t,n){return t.theta-n.theta}));return h[0].index},W=function(t,n){void 0===n&&(n={x:0,y:0,theta:0});for(var e=n,r=[],o=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}([],function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}(t),!1);o.length>0;){var i=V(o,e);r.push(o[i]),e=o[i],o.splice(i,1)}return r},J=function(t,n){return Math.atan2(n.y,n.x)-Math.atan2(t.y,t.x)},Y=function(){function t(t){this._RegExpList=null,this.list=t}return t.prototype.getRegEXP=function(t){var n=t.replace("/","\\/").replace("*",".*");return new RegExp(n)},t.prototype.include=function(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((function(n){return n.test(t)}))},t}(),Z=function(t,n){void 0===n&&(n=Array);for(var e=t.map((function(t){return t.length})).reduce((function(t,n){return t+n}),0),r=new n(e),o=0,i=0,u=0;u<e;)o<t[i].length?(r[u]=t[i][o],o+=1,u+=1):(i+=1,o=0);return r},$=function(){function t(t){var n=void 0===t?{}:t,e=n.size,r=void 0===e?5:e,o=n.step,i=void 0===o?5:o,u=n.min,a=void 0===u?-1/0:u,c=n.max,l=void 0===c?1/0:c;this.tmp=[],this.count=0,this.value=NaN,this.size=r,this.step=i,this.min=a,this.max=l}return t.prototype.filter=function(t){return t<this.min||t>this.max||(this.tmp.push(t),this.old=this.calc(t)),this.old},t.prototype.calc=function(t){if(this.tmp.length<1)return t;this.tmp.length>this.size&&this.tmp.shift();var n=this.getMostNumberOfTmp(),e=n.res,r=n.dic;return e!==t&&Math.abs(e-t)>this.step?(this.value!==t?this.count=1:this.count+=1,this.value=t,this.count>r[e]?(this.tmp.length=0,this.tmp.push(t),t):e):(this.count=0,this.value=NaN,t)},t.prototype.getMostNumberOfTmp=function(){var t,n,e,r={},o=0;try{for(var i=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.tmp),u=i.next();!u.done;u=i.next()){var a=u.value;r[a]?r[a]+=1:r[a]=1,r[a]>o&&(o=r[a],e=a)}}catch(n){t={error:n}}finally{try{u&&!u.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return{res:e,dic:r}},t}(),tt=function(){function t(t){this._cache="",this._splitSymbol=t}return t.prototype.split=function(t){var n=(this._cache+t).split(this._splitSymbol);return this._cache=n.splice(n.length-1,1)[0],n},t}();return n})()));
|
|
1
|
+
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["pubo-utils"]=n():t["pubo-utils"]=n()}(this,(()=>(()=>{"use strict";var t={d:(n,e)=>{for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};t.r(n),t.d(n,{Base64Utils:()=>e,ContinuousTrigger:()=>M,Emitter:()=>d,HistoryStack:()=>I,Level:()=>L,RegExpList:()=>Z,SensorDataFilter:()=>$,StringSplit:()=>tt,SyncQueue:()=>_,WatchDog:()=>N,callbackToPromise:()=>G,debounce:()=>u,degrees:()=>F,filterKeyPoints:()=>H,getAngle:()=>q,getBestPointIndex:()=>W,getCenter:()=>K,getDistance:()=>B,getPositionTheta:()=>V,getRotate:()=>Q,getVectorTheta:()=>Y,hex2rgb:()=>c,loop:()=>S,lower2camel:()=>nt,orderByDistance:()=>J,radians:()=>X,random:()=>f,randomRangeNum:()=>h,sleep:()=>m,superFactory:()=>g,throttle:()=>P,waitFor:()=>T});var e={};t.r(e),t.d(e,{EncoderMap:()=>E,toUnit8Array:()=>R});var r,o=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},i=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},u=function(t,n,e){if(void 0===e&&(e=!1),e){var r,u=!0;return function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];u&&(t.apply(void 0,i([],o(e),!1)),u=!1),r&&clearTimeout(r),r=setTimeout((function(){return u=!0}),n)}}var a;return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];a&&clearTimeout(a),a=setTimeout((function(){return t.apply(void 0,i([],o(e),!1))}),n)}},a=function(t){return parseInt(t.replace("#",""),16)},c=function(t){var n=("string"==typeof t?a(t):t).toString(2).padStart(24,"0");return[parseInt(n.slice(0,8),2),parseInt(n.slice(8,16),2),parseInt(n.slice(16,24),2)]},l=function(t){return"#"+[0,1,2].map((function(n){return t[n].toString(16)})).join("")},s=(function(){function t(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=a(t):Array.isArray(t)&&(this.int=a(l(t)))}t.prototype.getRgbArray=function(){return c(this.int)},Object.defineProperty(t.prototype,"rgb",{get:function(){return"rba(".concat(this.getRgbArray().join(", "),")")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hex",{get:function(){return l(this.getRgbArray())},enumerable:!1,configurable:!0}),t.prototype.toString=function(t){return void 0===t&&(t="hex"),"rgb"===t?this.rgb:this.hex}}(),function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}),f=function(t){void 0===t&&(t=8);var n=function(t){return Math.random().toString(32).slice(2,2+t)};if(t<=8)return n(t);for(var e="",r=0;r<=t;r+=8)e+=n(t-r>8?8:t-r);return e},h=function(t){var n=Math.abs(t[1]-t[0]);return Math.random()*n+Math.min.apply(Math,function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}([],s(t),!1))},p=(r=function(t,n){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])},r(t,n)},function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function e(){this.constructor=t}r(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}),y=function(){return y=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},y.apply(this,arguments)},v=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},d=function(){function t(){this.state={},this.ids={}}return t.prototype.on=function(t,n){if(this.state[t]||(this.state[t]=[]),"function"!=typeof n)throw new Error("第二个参数必须为function!");var e=this.state[t].push(n)-1,r=f(40);return this.ids[r]={event:t,index:e},r},t.prototype.cancel=function(t){var n=this;if(t){var e=this.ids[t]||{},r=e.event,o=e.index;r&&Array.isArray(this.state[r])&&(this.state[r].splice(o,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){n.ids[t].event===r&&n.ids[t].index>o&&(n.ids[t].index=n.ids[t].index-1)})))}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t,n){var e,r;if(Array.isArray(this.state[t]))try{for(var o=v(this.state[t]),i=o.next();!i.done;i=o.next()){var u=i.value;"function"==typeof u&&u(n)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}},t.prototype.emitSync=function(t,n){return e=this,r=void 0,i=function(){var e,r,o,i,u,a;return function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,(function(c){switch(c.label){case 0:if(!Array.isArray(this.state[t]))return[3,8];c.label=1;case 1:c.trys.push([1,6,7,8]),e=v(this.state[t]),r=e.next(),c.label=2;case 2:return r.done?[3,5]:"function"!=typeof(o=r.value)?[3,4]:[4,o(n)];case 3:c.sent(),c.label=4;case 4:return r=e.next(),[3,2];case 5:return[3,8];case 6:return i=c.sent(),u={error:i},[3,8];case 7:try{r&&!r.done&&(a=e.return)&&a.call(e)}finally{if(u)throw u.error}return[7];case 8:return[2]}}))},new((o=void 0)||(o=Promise))((function(t,n){function u(t){try{c(i.next(t))}catch(t){n(t)}}function a(t){try{c(i.throw(t))}catch(t){n(t)}}function c(n){var e;n.done?t(n.value):(e=n.value,e instanceof o?e:new o((function(t){t(e)}))).then(u,a)}c((i=i.apply(e,r||[])).next())}));var e,r,o,i},t.prototype.clone=function(){return{state:y({},this.state),ids:y({},this.ids)}},t.prototype.restore=function(t){this.state=t.state,this.ids=t.ids},t}(),b=(function(t){function n(){var n=null!==t&&t.apply(this,arguments)||this;return n._cache={},n}p(n,t),n.prototype.emit=function(n,e){this._cache[n]=e,t.prototype.emit.call(this,n,e)},n.prototype.getState=function(t){return this._cache[t]}}(d),function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}),g=function(t){return function(n){var e,r,o={};try{for(var i=b(Object.keys(n)),u=i.next();!u.done;u=i.next()){var a=u.value;o[a]=t(n[a],a)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o}},m=function(t){return n=void 0,e=void 0,o=function(){return function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){return setTimeout((function(){return n()}),t)}))];case 1:return n.sent(),[2]}}))},new((r=void 0)||(r=Promise))((function(t,i){function u(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(n){var e;n.done?t(n.value):(e=n.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,a)}c((o=o.apply(n,e||[])).next())}));var n,e,r,o},w=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,a)}c((r=r.apply(t,n||[])).next())}))},x=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},S=function(t,n){var e=!0,r=function(){e=!1},o=function(){return w(void 0,void 0,void 0,(function(){return x(this,(function(i){switch(i.label){case 0:return[4,t(r)];case 1:return i.sent(),[4,m(n)];case 2:return i.sent(),e?o():o=null,[2]}}))}))};return o(),r},T=function(t,n){var e=void 0===n?{}:n,r=e.checkTime,o=e.timeout;return new Promise((function(n,e){var i=S((function(){return w(void 0,void 0,void 0,(function(){var e;return x(this,(function(r){switch(r.label){case 0:return[4,t()];case 1:return(e=r.sent())&&(i(),n(e)),[2]}}))}))}),r||100);o&&setTimeout((function(){i(),e("timeout")}),o)}))},k=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,a)}c((r=r.apply(t,n||[])).next())}))},j=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},_=function(){function t(){this.cache=[],this.running=!1,this.len=0}return t.prototype._run=function(t){var n=t.fn,e=t.promise;return k(this,void 0,void 0,(function(){var t,r;return j(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,n()];case 1:return t=o.sent(),e.resolve(t),[3,3];case 2:return r=o.sent(),e.reject(r),[3,3];case 3:return[2]}}))}))},t.prototype.run=function(){return k(this,void 0,void 0,(function(){var t;return j(this,(function(n){switch(n.label){case 0:return this.cache.length<1?(this.running=!1,[2]):(this.running=!0,t=this.cache.shift(),this.len-=1,"function"!=typeof t.fn?[3,2]:[4,this._run(t)]);case 1:n.sent(),n.label=2;case 2:return this.run(),[2]}}))}))},t.prototype.push=function(t){var n=this;return this.len+=1,new Promise((function(e,r){n.cache.push({fn:t,promise:{resolve:e,reject:r}}),n.running||n.run()}))},Object.defineProperty(t.prototype,"length",{get:function(){return this.len},enumerable:!1,configurable:!0}),t}(),A=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},O=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))};function P(t,n){var e,r=!0;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];e||(e=setTimeout((function(){r=!0,e=null}),n)),r&&(r=!1,t.apply(void 0,O([],A(o),!1)))}}var M=function(){function t(t){this._count=0,this.props=t}return Object.defineProperty(t.prototype,"count",{get:function(){return this._count},enumerable:!1,configurable:!0}),t.prototype.increment=function(){var t=this;clearTimeout(this.timeout),this.timeout=setTimeout((function(){return t.clear()}),this.props.resetTime),this._count=this._count+1,this._count>this.props.count&&this.props.cb()},t.prototype.clear=function(){this._count=0},t}(),E=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function R(t){for(var n=new Uint8Array(6*t.length/8),e=0,r=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(r=(r<<6)+E[t.charAt(i)],(e+=6)>=8){var u=r>>>(e-=8);n[o++]=255&u,r-=u<<=e}return n}var I=function(){function t(t){void 0===t&&(t=10),this.stack=[],this.len=10,this.point=0,this.len=t}return Object.defineProperty(t.prototype,"current",{get:function(){if(this.point<this.stack.length&&this.point>-1)return this.stack[this.point]},enumerable:!1,configurable:!0}),t.prototype.clear=function(){this.stack.length=0,this.point=0},t.prototype.backup=function(t){this.point>0&&this.stack.length>0&&(this.stack.splice(0,this.point),this.point=0),this.stack.unshift(t),this.stack.length>this.len&&this.stack.pop()},t.prototype.undo=function(){return this.point<this.stack.length-1&&(this.point+=1),this.current},t.prototype.redo=function(){return this.point>0&&(this.point-=1),this.current},t}(),N=function(){function t(t){var n=t.limit,e=void 0===n?10:n,r=t.onTimeout;this.limit=10,this.timeout=null,this.limit=e,this.onTimeout=r}return t.prototype.feed=function(){this.init()},t.prototype.init=function(){var t=this;clearTimeout(this.timeout),this.timeout=setTimeout((function(){return t.onTimeout()}),1e3*this.limit)},t.prototype.stop=function(){this.timeout&&clearTimeout(this.timeout)},t}(),L=function(){function t(t){this.config=t,this.step=(this.config.max-this.config.min)/(this.config.count-2)}return t.prototype.get=function(t){if(t<=this.config.min)return 1;if(t>=this.config.max)return this.config.count;for(var n=2,e=this.config.min+this.step;e<this.config.max+this.step;e+=this.step,n+=1)if(t<e)return n;return this.config.count},t}(),C=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},D=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},G=function(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return new Promise((function(e,r){t.apply(void 0,D(D([],C(n),!1),[function(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];t&&r(t),n.length<2?e(n[0]):e(D([],C(n),!1))}],!1))}))}},U=function(){return U=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},U.apply(this,arguments)},z=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},B=function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2))},F=function(t){return 180*t/Math.PI},X=function(t){return t*Math.PI/180},q=function(t){var n=t.w,e=t.h;return F(Math.atan2(e,n))};function H(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(r,o){return!(o>0&&B(e,r)<n||(e=t[o],0))}));var e}function K(t){var n,e,r=[0,0];try{for(var o=z(t),i=o.next();!i.done;i=o.next()){var u=i.value;Array.isArray(u)?(r[0]+=u[0],r[1]+=u[1]):(r[0]+=u.x,r[1]+=u.y)}}catch(t){n={error:t}}finally{try{i&&!i.done&&(e=o.return)&&e.call(o)}finally{if(n)throw n.error}}return{x:r[0]/t.length,y:r[1]/t.length}}function Q(t,n){return[Math.cos(n)*t[0]-Math.sin(n)*t[1],Math.sin(n)*t[0]+Math.cos(n)*t[1]]}var V=function(t,n){var e={x:n.x-t.x,y:n.y-t.y};return Math.atan2(e.y,e.x)},W=function(t,n){var e,r;if(t.length<2)return 0;var o=[],i=1/0,u=0;try{for(var a=z(t),c=a.next();!c.done;c=a.next()){var l=c.value,s=B(l,n),f=V(n,l)-n.theta;i>s&&(i=s),o.push(U(U({},l),{index:u,distance:s,theta:f})),u+=1}}catch(t){e={error:t}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}var h=o.filter((function(t){return t.distance-i<.1})).sort((function(t,n){return t.theta-n.theta}));return h[0].index},J=function(t,n){void 0===n&&(n={x:0,y:0,theta:0});for(var e=n,r=[],o=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}([],function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}(t),!1);o.length>0;){var i=W(o,e);r.push(o[i]),e=o[i],o.splice(i,1)}return r},Y=function(t,n){return Math.atan2(n.y,n.x)-Math.atan2(t.y,t.x)},Z=function(){function t(t){this._RegExpList=null,this.list=t}return t.prototype.getRegEXP=function(t){var n=t.replace("/","\\/").replace("*",".*");return new RegExp(n)},t.prototype.include=function(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((function(n){return n.test(t)}))},t}(),$=function(){function t(t){var n=void 0===t?{}:t,e=n.size,r=void 0===e?5:e,o=n.step,i=void 0===o?5:o,u=n.min,a=void 0===u?-1/0:u,c=n.max,l=void 0===c?1/0:c;this.tmp=[],this.count=0,this.value=NaN,this.size=r,this.step=i,this.min=a,this.max=l}return t.prototype.filter=function(t){return t<this.min||t>this.max||(this.tmp.push(t),this.old=this.calc(t)),this.old},t.prototype.calc=function(t){if(this.tmp.length<1)return t;this.tmp.length>this.size&&this.tmp.shift();var n=this.getMostNumberOfTmp(),e=n.res,r=n.dic;return e!==t&&Math.abs(e-t)>this.step?(this.value!==t?this.count=1:this.count+=1,this.value=t,this.count>r[e]?(this.tmp.length=0,this.tmp.push(t),t):e):(this.count=0,this.value=NaN,t)},t.prototype.getMostNumberOfTmp=function(){var t,n,e,r={},o=0;try{for(var i=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.tmp),u=i.next();!u.done;u=i.next()){var a=u.value;r[a]?r[a]+=1:r[a]=1,r[a]>o&&(o=r[a],e=a)}}catch(n){t={error:n}}finally{try{u&&!u.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return{res:e,dic:r}},t}(),tt=function(){function t(t){this._cache="",this._splitSymbol=t}return t.prototype.split=function(t){var n=(this._cache+t).split(this._splitSymbol);return this._cache=n.splice(n.length-1,1)[0],n},t}(),nt=function(t){return t.split("_").map((function(t,n){return n>0?t.slice(0,1).toUpperCase()+t.slice(1):t})).join("")};return n})()));
|
package/es/emitter/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
interface EmitterType {
|
|
2
2
|
on: (event: string, func: any) => string;
|
|
3
3
|
cancel: (id?: string) => void;
|
|
4
|
-
emit: (event: string,
|
|
4
|
+
emit: (event: string, payload?: any) => any;
|
|
5
|
+
emitSync: (event: string, payload?: any) => Promise<any>;
|
|
5
6
|
clear: () => void;
|
|
6
7
|
clone: () => any;
|
|
7
8
|
restore: (snapshot: any) => void;
|
|
@@ -12,12 +13,17 @@ export declare class Emitter implements EmitterType {
|
|
|
12
13
|
on(event: string, func: any): string;
|
|
13
14
|
cancel(id?: string): void;
|
|
14
15
|
clear(): void;
|
|
15
|
-
emit(event: string,
|
|
16
|
-
emitSync(event: string,
|
|
16
|
+
emit(event: string, payload?: any): void;
|
|
17
|
+
emitSync(event: string, payload?: any): Promise<void>;
|
|
17
18
|
clone(): {
|
|
18
19
|
state: any;
|
|
19
20
|
ids: any;
|
|
20
21
|
};
|
|
21
22
|
restore(snapshot: any): void;
|
|
22
23
|
}
|
|
24
|
+
export declare class CacheEmitter extends Emitter {
|
|
25
|
+
private readonly _cache;
|
|
26
|
+
emit(event: string, payload?: any): void;
|
|
27
|
+
getState(event: string): any;
|
|
28
|
+
}
|
|
23
29
|
export {};
|
package/es/emitter/index.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
var __extends = this && this.__extends || function () {
|
|
2
|
+
var _extendStatics = function extendStatics(d, b) {
|
|
3
|
+
_extendStatics = Object.setPrototypeOf || {
|
|
4
|
+
__proto__: []
|
|
5
|
+
} instanceof Array && function (d, b) {
|
|
6
|
+
d.__proto__ = b;
|
|
7
|
+
} || function (d, b) {
|
|
8
|
+
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
9
|
+
};
|
|
10
|
+
return _extendStatics(d, b);
|
|
11
|
+
};
|
|
12
|
+
return function (d, b) {
|
|
13
|
+
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
14
|
+
_extendStatics(d, b);
|
|
15
|
+
function __() {
|
|
16
|
+
this.constructor = d;
|
|
17
|
+
}
|
|
18
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
19
|
+
};
|
|
20
|
+
}();
|
|
1
21
|
var __assign = this && this.__assign || function () {
|
|
2
22
|
__assign = Object.assign || function (t) {
|
|
3
23
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -139,37 +159,6 @@ var __values = this && this.__values || function (o) {
|
|
|
139
159
|
};
|
|
140
160
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
141
161
|
};
|
|
142
|
-
var __read = this && this.__read || function (o, n) {
|
|
143
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
144
|
-
if (!m) return o;
|
|
145
|
-
var i = m.call(o),
|
|
146
|
-
r,
|
|
147
|
-
ar = [],
|
|
148
|
-
e;
|
|
149
|
-
try {
|
|
150
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
151
|
-
} catch (error) {
|
|
152
|
-
e = {
|
|
153
|
-
error: error
|
|
154
|
-
};
|
|
155
|
-
} finally {
|
|
156
|
-
try {
|
|
157
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
158
|
-
} finally {
|
|
159
|
-
if (e) throw e.error;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return ar;
|
|
163
|
-
};
|
|
164
|
-
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
165
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
166
|
-
if (ar || !(i in from)) {
|
|
167
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
168
|
-
ar[i] = from[i];
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
172
|
-
};
|
|
173
162
|
import { random } from '../random';
|
|
174
163
|
var Emitter = /** @class */function () {
|
|
175
164
|
function Emitter() {
|
|
@@ -217,18 +206,14 @@ var Emitter = /** @class */function () {
|
|
|
217
206
|
Emitter.prototype.clear = function () {
|
|
218
207
|
this.state.length = 0;
|
|
219
208
|
};
|
|
220
|
-
Emitter.prototype.emit = function (event) {
|
|
209
|
+
Emitter.prototype.emit = function (event, payload) {
|
|
221
210
|
var e_1, _a;
|
|
222
|
-
var args = [];
|
|
223
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
224
|
-
args[_i - 1] = arguments[_i];
|
|
225
|
-
}
|
|
226
211
|
if (Array.isArray(this.state[event])) {
|
|
227
212
|
try {
|
|
228
213
|
for (var _b = __values(this.state[event]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
229
214
|
var func = _c.value;
|
|
230
215
|
if (typeof func === 'function') {
|
|
231
|
-
func
|
|
216
|
+
func(payload);
|
|
232
217
|
}
|
|
233
218
|
}
|
|
234
219
|
} catch (e_1_1) {
|
|
@@ -244,11 +229,7 @@ var Emitter = /** @class */function () {
|
|
|
244
229
|
}
|
|
245
230
|
}
|
|
246
231
|
};
|
|
247
|
-
Emitter.prototype.emitSync = function (event) {
|
|
248
|
-
var args = [];
|
|
249
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
250
|
-
args[_i - 1] = arguments[_i];
|
|
251
|
-
}
|
|
232
|
+
Emitter.prototype.emitSync = function (event, payload) {
|
|
252
233
|
return __awaiter(this, void 0, void 0, function () {
|
|
253
234
|
var _a, _b, func, e_2_1;
|
|
254
235
|
var e_2, _c;
|
|
@@ -265,7 +246,7 @@ var Emitter = /** @class */function () {
|
|
|
265
246
|
if (!!_b.done) return [3 /*break*/, 5];
|
|
266
247
|
func = _b.value;
|
|
267
248
|
if (!(typeof func === 'function')) return [3 /*break*/, 4];
|
|
268
|
-
return [4 /*yield*/, func
|
|
249
|
+
return [4 /*yield*/, func(payload)];
|
|
269
250
|
case 3:
|
|
270
251
|
_d.sent();
|
|
271
252
|
_d.label = 4;
|
|
@@ -306,4 +287,21 @@ var Emitter = /** @class */function () {
|
|
|
306
287
|
};
|
|
307
288
|
return Emitter;
|
|
308
289
|
}();
|
|
309
|
-
export { Emitter };
|
|
290
|
+
export { Emitter };
|
|
291
|
+
var CacheEmitter = /** @class */function (_super) {
|
|
292
|
+
__extends(CacheEmitter, _super);
|
|
293
|
+
function CacheEmitter() {
|
|
294
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
295
|
+
_this._cache = {};
|
|
296
|
+
return _this;
|
|
297
|
+
}
|
|
298
|
+
CacheEmitter.prototype.emit = function (event, payload) {
|
|
299
|
+
this._cache[event] = payload;
|
|
300
|
+
_super.prototype.emit.call(this, event, payload);
|
|
301
|
+
};
|
|
302
|
+
CacheEmitter.prototype.getState = function (event) {
|
|
303
|
+
return this._cache[event];
|
|
304
|
+
};
|
|
305
|
+
return CacheEmitter;
|
|
306
|
+
}(Emitter);
|
|
307
|
+
export { CacheEmitter };
|
package/es/index.d.ts
CHANGED
|
@@ -15,5 +15,5 @@ export { Level } from './level';
|
|
|
15
15
|
export { callbackToPromise } from './promise';
|
|
16
16
|
export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints, getRotate, getPositionTheta, getBestPointIndex, orderByDistance, getVectorTheta, } from './math/geometry';
|
|
17
17
|
export { RegExpList } from './regexp-list';
|
|
18
|
-
export { concatArray } from './array';
|
|
19
18
|
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
19
|
+
export { lower2camel } from './str';
|
package/es/index.js
CHANGED
|
@@ -16,5 +16,5 @@ export { Level } from './level';
|
|
|
16
16
|
export { callbackToPromise } from './promise';
|
|
17
17
|
export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints, getRotate, getPositionTheta, getBestPointIndex, orderByDistance, getVectorTheta } from './math/geometry';
|
|
18
18
|
export { RegExpList } from './regexp-list';
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
19
|
+
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
20
|
+
export { lower2camel } from './str';
|
package/es/math/geometry.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface Point2D {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
export type Vector2D = [number, number];
|
|
6
|
+
export declare const getDistance: (a: Point2D, b: Point2D) => number;
|
|
2
7
|
export declare const degrees: (rad: number) => number;
|
|
3
8
|
export declare const radians: (deg: number) => number;
|
|
4
9
|
export declare const getAngle: ({ w, h }: {
|
|
5
10
|
w: number;
|
|
6
11
|
h: number;
|
|
7
12
|
}) => number;
|
|
8
|
-
export interface Point2D {
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
}
|
|
12
13
|
export declare function filterKeyPoints(list: Point2D[], len?: number): Point2D[];
|
|
13
14
|
export declare function getCenter(list: Point2D[] | [number, number][]): Point2D;
|
|
14
|
-
export declare function getRotate(data:
|
|
15
|
+
export declare function getRotate(data: Vector2D, theta: number): Vector2D;
|
|
15
16
|
export declare const getPositionTheta: (a: Point2D, b: Point2D) => number;
|
|
16
17
|
export declare const getBestPointIndex: (points: Point2D[], pose: Point2D & {
|
|
17
18
|
theta: number;
|
package/es/math/geometry.js
CHANGED
|
@@ -55,6 +55,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
|
55
55
|
}
|
|
56
56
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
57
|
};
|
|
58
|
+
// 获取两点的距离
|
|
58
59
|
export var getDistance = function getDistance(a, b) {
|
|
59
60
|
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
60
61
|
};
|
|
@@ -72,6 +73,7 @@ export var getAngle = function getAngle(_a) {
|
|
|
72
73
|
h = _a.h;
|
|
73
74
|
return degrees(Math.atan2(h, w));
|
|
74
75
|
};
|
|
76
|
+
// 关键点过滤
|
|
75
77
|
export function filterKeyPoints(list, len) {
|
|
76
78
|
if (len === void 0) {
|
|
77
79
|
len = 0.5;
|
package/es/str.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const lower2camel: (str: any) => any;
|
package/es/str.js
ADDED
package/lib/emitter/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
interface EmitterType {
|
|
2
2
|
on: (event: string, func: any) => string;
|
|
3
3
|
cancel: (id?: string) => void;
|
|
4
|
-
emit: (event: string,
|
|
4
|
+
emit: (event: string, payload?: any) => any;
|
|
5
|
+
emitSync: (event: string, payload?: any) => Promise<any>;
|
|
5
6
|
clear: () => void;
|
|
6
7
|
clone: () => any;
|
|
7
8
|
restore: (snapshot: any) => void;
|
|
@@ -12,12 +13,17 @@ export declare class Emitter implements EmitterType {
|
|
|
12
13
|
on(event: string, func: any): string;
|
|
13
14
|
cancel(id?: string): void;
|
|
14
15
|
clear(): void;
|
|
15
|
-
emit(event: string,
|
|
16
|
-
emitSync(event: string,
|
|
16
|
+
emit(event: string, payload?: any): void;
|
|
17
|
+
emitSync(event: string, payload?: any): Promise<void>;
|
|
17
18
|
clone(): {
|
|
18
19
|
state: any;
|
|
19
20
|
ids: any;
|
|
20
21
|
};
|
|
21
22
|
restore(snapshot: any): void;
|
|
22
23
|
}
|
|
24
|
+
export declare class CacheEmitter extends Emitter {
|
|
25
|
+
private readonly _cache;
|
|
26
|
+
emit(event: string, payload?: any): void;
|
|
27
|
+
getState(event: string): any;
|
|
28
|
+
}
|
|
23
29
|
export {};
|
package/lib/emitter/index.js
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __extends = this && this.__extends || function () {
|
|
4
|
+
var _extendStatics = function extendStatics(d, b) {
|
|
5
|
+
_extendStatics = Object.setPrototypeOf || {
|
|
6
|
+
__proto__: []
|
|
7
|
+
} instanceof Array && function (d, b) {
|
|
8
|
+
d.__proto__ = b;
|
|
9
|
+
} || function (d, b) {
|
|
10
|
+
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
11
|
+
};
|
|
12
|
+
return _extendStatics(d, b);
|
|
13
|
+
};
|
|
14
|
+
return function (d, b) {
|
|
15
|
+
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
16
|
+
_extendStatics(d, b);
|
|
17
|
+
function __() {
|
|
18
|
+
this.constructor = d;
|
|
19
|
+
}
|
|
20
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
21
|
+
};
|
|
22
|
+
}();
|
|
3
23
|
var __assign = this && this.__assign || function () {
|
|
4
24
|
__assign = Object.assign || function (t) {
|
|
5
25
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -141,41 +161,10 @@ var __values = this && this.__values || function (o) {
|
|
|
141
161
|
};
|
|
142
162
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
143
163
|
};
|
|
144
|
-
var __read = this && this.__read || function (o, n) {
|
|
145
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
146
|
-
if (!m) return o;
|
|
147
|
-
var i = m.call(o),
|
|
148
|
-
r,
|
|
149
|
-
ar = [],
|
|
150
|
-
e;
|
|
151
|
-
try {
|
|
152
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
153
|
-
} catch (error) {
|
|
154
|
-
e = {
|
|
155
|
-
error: error
|
|
156
|
-
};
|
|
157
|
-
} finally {
|
|
158
|
-
try {
|
|
159
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
160
|
-
} finally {
|
|
161
|
-
if (e) throw e.error;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return ar;
|
|
165
|
-
};
|
|
166
|
-
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
167
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
168
|
-
if (ar || !(i in from)) {
|
|
169
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
170
|
-
ar[i] = from[i];
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
174
|
-
};
|
|
175
164
|
Object.defineProperty(exports, "__esModule", {
|
|
176
165
|
value: true
|
|
177
166
|
});
|
|
178
|
-
exports.Emitter = void 0;
|
|
167
|
+
exports.CacheEmitter = exports.Emitter = void 0;
|
|
179
168
|
var random_1 = require("../random");
|
|
180
169
|
var Emitter = /** @class */function () {
|
|
181
170
|
function Emitter() {
|
|
@@ -223,18 +212,14 @@ var Emitter = /** @class */function () {
|
|
|
223
212
|
Emitter.prototype.clear = function () {
|
|
224
213
|
this.state.length = 0;
|
|
225
214
|
};
|
|
226
|
-
Emitter.prototype.emit = function (event) {
|
|
215
|
+
Emitter.prototype.emit = function (event, payload) {
|
|
227
216
|
var e_1, _a;
|
|
228
|
-
var args = [];
|
|
229
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
230
|
-
args[_i - 1] = arguments[_i];
|
|
231
|
-
}
|
|
232
217
|
if (Array.isArray(this.state[event])) {
|
|
233
218
|
try {
|
|
234
219
|
for (var _b = __values(this.state[event]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
235
220
|
var func = _c.value;
|
|
236
221
|
if (typeof func === 'function') {
|
|
237
|
-
func
|
|
222
|
+
func(payload);
|
|
238
223
|
}
|
|
239
224
|
}
|
|
240
225
|
} catch (e_1_1) {
|
|
@@ -250,11 +235,7 @@ var Emitter = /** @class */function () {
|
|
|
250
235
|
}
|
|
251
236
|
}
|
|
252
237
|
};
|
|
253
|
-
Emitter.prototype.emitSync = function (event) {
|
|
254
|
-
var args = [];
|
|
255
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
256
|
-
args[_i - 1] = arguments[_i];
|
|
257
|
-
}
|
|
238
|
+
Emitter.prototype.emitSync = function (event, payload) {
|
|
258
239
|
return __awaiter(this, void 0, void 0, function () {
|
|
259
240
|
var _a, _b, func, e_2_1;
|
|
260
241
|
var e_2, _c;
|
|
@@ -271,7 +252,7 @@ var Emitter = /** @class */function () {
|
|
|
271
252
|
if (!!_b.done) return [3 /*break*/, 5];
|
|
272
253
|
func = _b.value;
|
|
273
254
|
if (!(typeof func === 'function')) return [3 /*break*/, 4];
|
|
274
|
-
return [4 /*yield*/, func
|
|
255
|
+
return [4 /*yield*/, func(payload)];
|
|
275
256
|
case 3:
|
|
276
257
|
_d.sent();
|
|
277
258
|
_d.label = 4;
|
|
@@ -312,4 +293,21 @@ var Emitter = /** @class */function () {
|
|
|
312
293
|
};
|
|
313
294
|
return Emitter;
|
|
314
295
|
}();
|
|
315
|
-
exports.Emitter = Emitter;
|
|
296
|
+
exports.Emitter = Emitter;
|
|
297
|
+
var CacheEmitter = /** @class */function (_super) {
|
|
298
|
+
__extends(CacheEmitter, _super);
|
|
299
|
+
function CacheEmitter() {
|
|
300
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
301
|
+
_this._cache = {};
|
|
302
|
+
return _this;
|
|
303
|
+
}
|
|
304
|
+
CacheEmitter.prototype.emit = function (event, payload) {
|
|
305
|
+
this._cache[event] = payload;
|
|
306
|
+
_super.prototype.emit.call(this, event, payload);
|
|
307
|
+
};
|
|
308
|
+
CacheEmitter.prototype.getState = function (event) {
|
|
309
|
+
return this._cache[event];
|
|
310
|
+
};
|
|
311
|
+
return CacheEmitter;
|
|
312
|
+
}(Emitter);
|
|
313
|
+
exports.CacheEmitter = CacheEmitter;
|
package/lib/index.d.ts
CHANGED
|
@@ -15,5 +15,5 @@ export { Level } from './level';
|
|
|
15
15
|
export { callbackToPromise } from './promise';
|
|
16
16
|
export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints, getRotate, getPositionTheta, getBestPointIndex, orderByDistance, getVectorTheta, } from './math/geometry';
|
|
17
17
|
export { RegExpList } from './regexp-list';
|
|
18
|
-
export { concatArray } from './array';
|
|
19
18
|
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
19
|
+
export { lower2camel } from './str';
|
package/lib/index.js
CHANGED
|
@@ -34,7 +34,7 @@ var __importStar = this && this.__importStar || function (mod) {
|
|
|
34
34
|
Object.defineProperty(exports, "__esModule", {
|
|
35
35
|
value: true
|
|
36
36
|
});
|
|
37
|
-
exports.
|
|
37
|
+
exports.lower2camel = exports.StringSplit = exports.SensorDataFilter = exports.RegExpList = exports.getVectorTheta = exports.orderByDistance = exports.getBestPointIndex = exports.getPositionTheta = exports.getRotate = exports.filterKeyPoints = exports.radians = exports.degrees = exports.getCenter = exports.getDistance = exports.getAngle = exports.callbackToPromise = exports.Level = exports.WatchDog = exports.HistoryStack = exports.Base64Utils = exports.ContinuousTrigger = exports.throttle = exports.sleep = exports.randomRangeNum = exports.random = exports.SyncQueue = exports.waitFor = exports.loop = exports.superFactory = exports.Emitter = exports.hex2rgb = exports.debounce = void 0;
|
|
38
38
|
var debounce_1 = require("./debounce");
|
|
39
39
|
Object.defineProperty(exports, "debounce", {
|
|
40
40
|
enumerable: true,
|
|
@@ -220,13 +220,6 @@ Object.defineProperty(exports, "RegExpList", {
|
|
|
220
220
|
return regexp_list_1.RegExpList;
|
|
221
221
|
}
|
|
222
222
|
});
|
|
223
|
-
var array_1 = require("./array");
|
|
224
|
-
Object.defineProperty(exports, "concatArray", {
|
|
225
|
-
enumerable: true,
|
|
226
|
-
get: function get() {
|
|
227
|
-
return array_1.concatArray;
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
223
|
var sensor_1 = require("./filter/sensor");
|
|
231
224
|
Object.defineProperty(exports, "SensorDataFilter", {
|
|
232
225
|
enumerable: true,
|
|
@@ -239,4 +232,11 @@ Object.defineProperty(exports, "StringSplit", {
|
|
|
239
232
|
get: function get() {
|
|
240
233
|
return sensor_1.StringSplit;
|
|
241
234
|
}
|
|
235
|
+
});
|
|
236
|
+
var str_1 = require("./str");
|
|
237
|
+
Object.defineProperty(exports, "lower2camel", {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
get: function get() {
|
|
240
|
+
return str_1.lower2camel;
|
|
241
|
+
}
|
|
242
242
|
});
|
package/lib/math/geometry.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface Point2D {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
export type Vector2D = [number, number];
|
|
6
|
+
export declare const getDistance: (a: Point2D, b: Point2D) => number;
|
|
2
7
|
export declare const degrees: (rad: number) => number;
|
|
3
8
|
export declare const radians: (deg: number) => number;
|
|
4
9
|
export declare const getAngle: ({ w, h }: {
|
|
5
10
|
w: number;
|
|
6
11
|
h: number;
|
|
7
12
|
}) => number;
|
|
8
|
-
export interface Point2D {
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
}
|
|
12
13
|
export declare function filterKeyPoints(list: Point2D[], len?: number): Point2D[];
|
|
13
14
|
export declare function getCenter(list: Point2D[] | [number, number][]): Point2D;
|
|
14
|
-
export declare function getRotate(data:
|
|
15
|
+
export declare function getRotate(data: Vector2D, theta: number): Vector2D;
|
|
15
16
|
export declare const getPositionTheta: (a: Point2D, b: Point2D) => number;
|
|
16
17
|
export declare const getBestPointIndex: (points: Point2D[], pose: Point2D & {
|
|
17
18
|
theta: number;
|
package/lib/math/geometry.js
CHANGED
|
@@ -61,6 +61,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
61
61
|
value: true
|
|
62
62
|
});
|
|
63
63
|
exports.getVectorTheta = exports.orderByDistance = exports.getBestPointIndex = exports.getPositionTheta = exports.getRotate = exports.getCenter = exports.filterKeyPoints = exports.getAngle = exports.radians = exports.degrees = exports.getDistance = void 0;
|
|
64
|
+
// 获取两点的距离
|
|
64
65
|
var getDistance = function getDistance(a, b) {
|
|
65
66
|
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
66
67
|
};
|
|
@@ -82,6 +83,7 @@ var getAngle = function getAngle(_a) {
|
|
|
82
83
|
return (0, exports.degrees)(Math.atan2(h, w));
|
|
83
84
|
};
|
|
84
85
|
exports.getAngle = getAngle;
|
|
86
|
+
// 关键点过滤
|
|
85
87
|
function filterKeyPoints(list, len) {
|
|
86
88
|
if (len === void 0) {
|
|
87
89
|
len = 0.5;
|
package/lib/str.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const lower2camel: (str: any) => any;
|
package/lib/str.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.lower2camel = void 0;
|
|
7
|
+
// 下划线转驼峰
|
|
8
|
+
var lower2camel = function lower2camel(str) {
|
|
9
|
+
return str.split('_').map(function (item, i) {
|
|
10
|
+
return i > 0 ? item.slice(0, 1).toUpperCase() + item.slice(1) : item;
|
|
11
|
+
}).join('');
|
|
12
|
+
};
|
|
13
|
+
exports.lower2camel = lower2camel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.129",
|
|
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": "49ff87b8c7333f1e5861c4f83fd0f743d498ae1e",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@babel/cli": "^7.10.1",
|
|
24
24
|
"@babel/core": "^7.10.2",
|
package/es/array/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const concatArray: (list: any[], Type?: any) => any;
|
package/es/array/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export var concatArray = function concatArray(list, Type) {
|
|
2
|
-
if (Type === void 0) {
|
|
3
|
-
Type = Array;
|
|
4
|
-
}
|
|
5
|
-
var size = list.map(function (item) {
|
|
6
|
-
return item.length;
|
|
7
|
-
}).reduce(function (v, n) {
|
|
8
|
-
return v + n;
|
|
9
|
-
}, 0);
|
|
10
|
-
var res = new Type(size);
|
|
11
|
-
var j = 0;
|
|
12
|
-
var k = 0;
|
|
13
|
-
var i = 0;
|
|
14
|
-
while (i < size) {
|
|
15
|
-
if (j < list[k].length) {
|
|
16
|
-
res[i] = list[k][j];
|
|
17
|
-
j += 1;
|
|
18
|
-
i += 1;
|
|
19
|
-
} else {
|
|
20
|
-
k += 1;
|
|
21
|
-
j = 0;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return res;
|
|
25
|
-
};
|
package/lib/array/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const concatArray: (list: any[], Type?: any) => any;
|
package/lib/array/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.concatArray = void 0;
|
|
7
|
-
var concatArray = function concatArray(list, Type) {
|
|
8
|
-
if (Type === void 0) {
|
|
9
|
-
Type = Array;
|
|
10
|
-
}
|
|
11
|
-
var size = list.map(function (item) {
|
|
12
|
-
return item.length;
|
|
13
|
-
}).reduce(function (v, n) {
|
|
14
|
-
return v + n;
|
|
15
|
-
}, 0);
|
|
16
|
-
var res = new Type(size);
|
|
17
|
-
var j = 0;
|
|
18
|
-
var k = 0;
|
|
19
|
-
var i = 0;
|
|
20
|
-
while (i < size) {
|
|
21
|
-
if (j < list[k].length) {
|
|
22
|
-
res[i] = list[k][j];
|
|
23
|
-
j += 1;
|
|
24
|
-
i += 1;
|
|
25
|
-
} else {
|
|
26
|
-
k += 1;
|
|
27
|
-
j = 0;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return res;
|
|
31
|
-
};
|
|
32
|
-
exports.concatArray = concatArray;
|