pubo-utils 1.0.64 → 1.0.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(t,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,(function(){return function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)r.d(e,o,function(n){return t[n]}.bind(null,o));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p="",r(r.s=0)}([function(t,n,r){"use strict";r.r(n),r.d(n,"debounce",(function(){return c})),r.d(n,"hex2rgb",(function(){return f})),r.d(n,"Emitter",(function(){return d})),r.d(n,"superFactory",(function(){return b})),r.d(n,"loop",(function(){return k})),r.d(n,"waitFor",(function(){return T})),r.d(n,"SyncQueue",(function(){return O})),r.d(n,"random",(function(){return s})),r.d(n,"sleep",(function(){return w})),r.d(n,"throttle",(function(){return _})),r.d(n,"ContinuousTrigger",(function(){return E})),r.d(n,"Base64Utils",(function(){return e})),r.d(n,"HistoryStack",(function(){return D})),r.d(n,"WatchDog",(function(){return R})),r.d(n,"Level",(function(){return U})),r.d(n,"PuboGeometry",(function(){return o})),r.d(n,"callbackToPromise",(function(){return z})),r.d(n,"getAngle",(function(){return B})),r.d(n,"getDistance",(function(){return C})),r.d(n,"degrees",(function(){return F})),r.d(n,"radians",(function(){return K})),r.d(n,"filterKeyPoints",(function(){return H}));var e={};r.r(e),r.d(e,"EncoderMap",(function(){return I})),r.d(e,"toUnit8Array",(function(){return G}));var o={};r.r(o),r.d(o,"getDistance",(function(){return C})),r.d(o,"degrees",(function(){return F})),r.d(o,"radians",(function(){return K})),r.d(o,"getAngle",(function(){return B})),r.d(o,"filterKeyPoints",(function(){return H})),r.d(o,"getCenter",(function(){return L}));var i=function(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var e,o,i=r.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(e=i.next()).done;)u.push(e.value)}catch(t){o={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},u=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(i(arguments[n]));return t},c=function(t,n,r){if(void 0===r&&(r=!1),r){var e,o=!0;return function(){for(var r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];o&&(t.apply(void 0,u(r)),o=!1),e&&clearTimeout(e),e=setTimeout((function(){return o=!0}),n)}}var i;return function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];i&&clearTimeout(i),i=setTimeout((function(){return t.apply(void 0,u(r))}),n)}},a=function(t){return parseInt(t.replace("#",""),16)},f=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 f(this.int)},Object.defineProperty(t.prototype,"rgb",{get:function(){return"rba("+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){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 r="",e=0;e<=t;e+=8)r+=n(t-e>8?8:t-e);return r}),h=function(t){var n="function"==typeof Symbol&&Symbol.iterator,r=n&&t[n],e=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},p=function(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var e,o,i=r.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(e=i.next()).done;)u.push(e.value)}catch(t){o={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},y=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(p(arguments[n]));return t},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 r=this.state[t].push(n)-1,e=s(40);return this.ids[e]={event:t,index:r},e},t.prototype.cancel=function(t){var n=this;if(t){var r=this.ids[t]||{},e=r.event,o=r.index;e&&Array.isArray(this.state[e])&&(this.state[e].splice(o,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){n.ids[t].event===e&&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,r,e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];if(Array.isArray(this.state[t]))try{for(var i=h(this.state[t]),u=i.next();!u.done;u=i.next()){var c=u.value;"function"==typeof c&&c.apply(void 0,y(e))}}catch(t){n={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},t}(),v=function(t){var n="function"==typeof Symbol&&Symbol.iterator,r=n&&t[n],e=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},b=function(t){return function(n){var r,e,o={};try{for(var i=v(Object.keys(n)),u=i.next();!u.done;u=i.next()){var c=u.value;o[c]=t(n[c],c)}}catch(t){r={error:t}}finally{try{u&&!u.done&&(e=i.return)&&e.call(i)}finally{if(r)throw r.error}}return o}},g=function(t,n,r,e){return new(r||(r=Promise))((function(o,i){function u(t){try{a(e.next(t))}catch(t){i(t)}}function c(t){try{a(e.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(u,c)}a((e=e.apply(t,n||[])).next())}))},m=function(t,n){var r,e,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,e&&(o=2&i[0]?e.return:i[0]?e.throw||((o=e.return)&&o.call(e),0):e.next)&&!(o=o.call(e,i[1])).done)return o;switch(e=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,e=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],e=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},w=function(t){return g(void 0,void 0,void 0,(function(){return m(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]}}))}))},x=function(t,n,r,e){return new(r||(r=Promise))((function(o,i){function u(t){try{a(e.next(t))}catch(t){i(t)}}function c(t){try{a(e.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(u,c)}a((e=e.apply(t,n||[])).next())}))},S=function(t,n){var r,e,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,e&&(o=2&i[0]?e.return:i[0]?e.throw||((o=e.return)&&o.call(e),0):e.next)&&!(o=o.call(e,i[1])).done)return o;switch(e=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,e=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],e=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},k=function(t,n){var r=!0,e=function(){r=!1},o=function(){return x(void 0,void 0,void 0,(function(){return S(this,(function(i){switch(i.label){case 0:return[4,t(e)];case 1:return i.sent(),[4,w(n)];case 2:return i.sent(),r?o():o=null,[2]}}))}))};return o(),e},T=function(t,n){var r=void 0===n?{}:n,e=r.checkTime,o=r.timeout;return new Promise((function(n,r){var i=k((function(){return x(void 0,void 0,void 0,(function(){var r;return S(this,(function(e){switch(e.label){case 0:return[4,t()];case 1:return(r=e.sent())&&(i(),n(r)),[2]}}))}))}),e||100);o&&setTimeout((function(){i(),r("timeout")}),o)}))},j=function(t,n,r,e){return new(r||(r=Promise))((function(o,i){function u(t){try{a(e.next(t))}catch(t){i(t)}}function c(t){try{a(e.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(u,c)}a((e=e.apply(t,n||[])).next())}))},P=function(t,n){var r,e,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,e&&(o=2&i[0]?e.return:i[0]?e.throw||((o=e.return)&&o.call(e),0):e.next)&&!(o=o.call(e,i[1])).done)return o;switch(e=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,e=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],e=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},O=function(){function t(){this.cache=[],this.running=!1}return t.prototype._run=function(t){var n=t.fn,r=t.promise;return j(this,void 0,void 0,(function(){var t,e;return P(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,n()];case 1:return t=o.sent(),r.resolve(t),[3,3];case 2:return e=o.sent(),r.reject(e),[3,3];case 3:return[2]}}))}))},t.prototype.run=function(){return j(this,void 0,void 0,(function(){var t;return P(this,(function(n){switch(n.label){case 0:return this.cache.length<1?(this.running=!1,[2]):(this.running=!0,"function"!=typeof(t=this.cache.shift()).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 new Promise((function(r,e){n.cache.push({fn:t,promise:{resolve:r,reject:e}}),n.running||n.run()}))},Object.defineProperty(t.prototype,"length",{get:function(){return this.cache.length},enumerable:!1,configurable:!0}),t}(),A=function(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var e,o,i=r.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(e=i.next()).done;)u.push(e.value)}catch(t){o={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},M=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(A(arguments[n]));return t};function _(t,n){var r,e=!0;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];r||(r=setTimeout((function(){e=!0,r=null}),n)),e&&(e=!1,t.apply(void 0,M(o)))}}var E=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}(),I=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function G(t){for(var n=new Uint8Array(6*t.length/8),r=0,e=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(e=(e<<6)+I[t.charAt(i)],(r+=6)>=8){var u=e>>>(r-=8);n[o++]=255&u,e-=u<<=r}return n}var D=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}(),R=function(){function t(t){var n=t.limit,r=void 0===n?10:n,e=t.onTimeout;this.limit=10,this.timeout=null,this.limit=r,this.onTimeout=e}return t.prototype.feed=function(){clearTimeout(this.timeout),this.init()},t.prototype.init=function(){var t=this;this.timeout=setTimeout((function(){return t.onTimeout()}),1e3*this.limit)},t.prototype.stop=function(){this.timeout&&clearTimeout(this.timeout)},t}(),U=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,r=this.config.min+this.step;r<this.config.max+this.step;r+=this.step,n+=1)if(t<r)return n;return this.config.count},t}(),q=function(t){var n="function"==typeof Symbol&&Symbol.iterator,r=n&&t[n],e=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},C=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},K=function(t){return t*Math.PI/180},B=function(t){var n,r=t.w,e=t.h,o=F(Math.asin(e/Math.sqrt(Math.pow(r,2)+Math.pow(e,2))));return(n=r<=0?180-o:o>0?o:360+o)<-180&&(n+=360),n>180&&(n-=360),n};function H(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(e,o){return!(o>0&&C(r,e)<n)&&(r=t[o],!0)}));var r}function L(t){var n,r,e=[0,0];try{for(var o=q(t),i=o.next();!i.done;i=o.next()){var u=i.value;e[0]+=u.x,e[1]+=u.y}}catch(t){n={error:t}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return{x:e[0]/t.length,y:e[0]/t.length}}var Q=function(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var e,o,i=r.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(e=i.next()).done;)u.push(e.value)}catch(t){o={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},W=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Q(arguments[n]));return t},z=function(t){return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return new Promise((function(r,e){t.apply(void 0,W(n,[function(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];t&&e(t),n.length<2?r(n[0]):r(W(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,(function(){return function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)r.d(e,o,function(n){return t[n]}.bind(null,o));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p="",r(r.s=0)}([function(t,n,r){"use strict";r.r(n),r.d(n,"debounce",(function(){return u})),r.d(n,"hex2rgb",(function(){return a})),r.d(n,"Emitter",(function(){return y})),r.d(n,"superFactory",(function(){return v})),r.d(n,"loop",(function(){return S})),r.d(n,"waitFor",(function(){return k})),r.d(n,"SyncQueue",(function(){return P})),r.d(n,"random",(function(){return l})),r.d(n,"sleep",(function(){return m})),r.d(n,"throttle",(function(){return M})),r.d(n,"ContinuousTrigger",(function(){return _})),r.d(n,"Base64Utils",(function(){return e})),r.d(n,"HistoryStack",(function(){return G})),r.d(n,"WatchDog",(function(){return R})),r.d(n,"Level",(function(){return U})),r.d(n,"callbackToPromise",(function(){return D})),r.d(n,"getAngle",(function(){return L})),r.d(n,"getDistance",(function(){return B})),r.d(n,"getCenter",(function(){return W})),r.d(n,"degrees",(function(){return H})),r.d(n,"radians",(function(){return K})),r.d(n,"filterKeyPoints",(function(){return Q}));var e={};r.r(e),r.d(e,"EncoderMap",(function(){return E})),r.d(e,"toUnit8Array",(function(){return I}));var o=function(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var e,o,i=r.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(e=i.next()).done;)u.push(e.value)}catch(t){o={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},i=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(o(arguments[n]));return t},u=function(t,n,r){if(void 0===r&&(r=!1),r){var e,o=!0;return function(){for(var r=[],u=0;u<arguments.length;u++)r[u]=arguments[u];o&&(t.apply(void 0,i(r)),o=!1),e&&clearTimeout(e),e=setTimeout((function(){return o=!0}),n)}}var u;return function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];u&&clearTimeout(u),u=setTimeout((function(){return t.apply(void 0,i(r))}),n)}},c=function(t){return parseInt(t.replace("#",""),16)},a=function(t){var n=("string"==typeof t?c(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)]},f=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=c(t):Array.isArray(t)&&(this.int=c(f(t)))}t.prototype.getRgbArray=function(){return a(this.int)},Object.defineProperty(t.prototype,"rgb",{get:function(){return"rba("+this.getRgbArray().join(", ")+")"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hex",{get:function(){return f(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){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 r="",e=0;e<=t;e+=8)r+=n(t-e>8?8:t-e);return r}),s=function(t){var n="function"==typeof Symbol&&Symbol.iterator,r=n&&t[n],e=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},h=function(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var e,o,i=r.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(e=i.next()).done;)u.push(e.value)}catch(t){o={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},p=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(h(arguments[n]));return t},y=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 r=this.state[t].push(n)-1,e=l(40);return this.ids[e]={event:t,index:r},e},t.prototype.cancel=function(t){var n=this;if(t){var r=this.ids[t]||{},e=r.event,o=r.index;e&&Array.isArray(this.state[e])&&(this.state[e].splice(o,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){n.ids[t].event===e&&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,r,e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];if(Array.isArray(this.state[t]))try{for(var i=s(this.state[t]),u=i.next();!u.done;u=i.next()){var c=u.value;"function"==typeof c&&c.apply(void 0,p(e))}}catch(t){n={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},t}(),d=function(t){var n="function"==typeof Symbol&&Symbol.iterator,r=n&&t[n],e=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},v=function(t){return function(n){var r,e,o={};try{for(var i=d(Object.keys(n)),u=i.next();!u.done;u=i.next()){var c=u.value;o[c]=t(n[c],c)}}catch(t){r={error:t}}finally{try{u&&!u.done&&(e=i.return)&&e.call(i)}finally{if(r)throw r.error}}return o}},b=function(t,n,r,e){return new(r||(r=Promise))((function(o,i){function u(t){try{a(e.next(t))}catch(t){i(t)}}function c(t){try{a(e.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(u,c)}a((e=e.apply(t,n||[])).next())}))},g=function(t,n){var r,e,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,e&&(o=2&i[0]?e.return:i[0]?e.throw||((o=e.return)&&o.call(e),0):e.next)&&!(o=o.call(e,i[1])).done)return o;switch(e=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,e=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],e=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},m=function(t){return b(void 0,void 0,void 0,(function(){return g(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]}}))}))},w=function(t,n,r,e){return new(r||(r=Promise))((function(o,i){function u(t){try{a(e.next(t))}catch(t){i(t)}}function c(t){try{a(e.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(u,c)}a((e=e.apply(t,n||[])).next())}))},x=function(t,n){var r,e,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,e&&(o=2&i[0]?e.return:i[0]?e.throw||((o=e.return)&&o.call(e),0):e.next)&&!(o=o.call(e,i[1])).done)return o;switch(e=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,e=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],e=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},S=function(t,n){var r=!0,e=function(){r=!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(e)];case 1:return i.sent(),[4,m(n)];case 2:return i.sent(),r?o():o=null,[2]}}))}))};return o(),e},k=function(t,n){var r=void 0===n?{}:n,e=r.checkTime,o=r.timeout;return new Promise((function(n,r){var i=S((function(){return w(void 0,void 0,void 0,(function(){var r;return x(this,(function(e){switch(e.label){case 0:return[4,t()];case 1:return(r=e.sent())&&(i(),n(r)),[2]}}))}))}),e||100);o&&setTimeout((function(){i(),r("timeout")}),o)}))},T=function(t,n,r,e){return new(r||(r=Promise))((function(o,i){function u(t){try{a(e.next(t))}catch(t){i(t)}}function c(t){try{a(e.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(u,c)}a((e=e.apply(t,n||[])).next())}))},j=function(t,n){var r,e,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,e&&(o=2&i[0]?e.return:i[0]?e.throw||((o=e.return)&&o.call(e),0):e.next)&&!(o=o.call(e,i[1])).done)return o;switch(e=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,e=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],e=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},P=function(){function t(){this.cache=[],this.running=!1}return t.prototype._run=function(t){var n=t.fn,r=t.promise;return T(this,void 0,void 0,(function(){var t,e;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(),r.resolve(t),[3,3];case 2:return e=o.sent(),r.reject(e),[3,3];case 3:return[2]}}))}))},t.prototype.run=function(){return T(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,"function"!=typeof(t=this.cache.shift()).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 new Promise((function(r,e){n.cache.push({fn:t,promise:{resolve:r,reject:e}}),n.running||n.run()}))},Object.defineProperty(t.prototype,"length",{get:function(){return this.cache.length},enumerable:!1,configurable:!0}),t}(),O=function(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var e,o,i=r.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(e=i.next()).done;)u.push(e.value)}catch(t){o={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},A=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(O(arguments[n]));return t};function M(t,n){var r,e=!0;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];r||(r=setTimeout((function(){e=!0,r=null}),n)),e&&(e=!1,t.apply(void 0,A(o)))}}var _=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 I(t){for(var n=new Uint8Array(6*t.length/8),r=0,e=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(e=(e<<6)+E[t.charAt(i)],(r+=6)>=8){var u=e>>>(r-=8);n[o++]=255&u,e-=u<<=r}return n}var G=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}(),R=function(){function t(t){var n=t.limit,r=void 0===n?10:n,e=t.onTimeout;this.limit=10,this.timeout=null,this.limit=r,this.onTimeout=e}return t.prototype.feed=function(){clearTimeout(this.timeout),this.init()},t.prototype.init=function(){var t=this;this.timeout=setTimeout((function(){return t.onTimeout()}),1e3*this.limit)},t.prototype.stop=function(){this.timeout&&clearTimeout(this.timeout)},t}(),U=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,r=this.config.min+this.step;r<this.config.max+this.step;r+=this.step,n+=1)if(t<r)return n;return this.config.count},t}(),q=function(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var e,o,i=r.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(e=i.next()).done;)u.push(e.value)}catch(t){o={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},C=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(q(arguments[n]));return t},D=function(t){return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return new Promise((function(r,e){t.apply(void 0,C(n,[function(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];t&&e(t),n.length<2?r(n[0]):r(C(n))}]))}))}},F=function(t){var n="function"==typeof Symbol&&Symbol.iterator,r=n&&t[n],e=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],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))},H=function(t){return 180*t/Math.PI},K=function(t){return t*Math.PI/180},L=function(t){var n,r=t.w,e=t.h,o=H(Math.asin(e/Math.sqrt(Math.pow(r,2)+Math.pow(e,2))));return(n=r<=0?180-o:o>0?o:360+o)<-180&&(n+=360),n>180&&(n-=360),n};function Q(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(e,o){return!(o>0&&B(r,e)<n)&&(r=t[o],!0)}));var r}function W(t){var n,r,e=[0,0];try{for(var o=F(t),i=o.next();!i.done;i=o.next()){var u=i.value;Array.isArray(u)?(e[0]+=u[0],e[1]+=u[1]):(e[0]+=u.x,e[1]+=u.y)}}catch(t){n={error:t}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return{x:e[0]/t.length,y:e[1]/t.length}}}])}));
package/es/index.d.ts CHANGED
@@ -12,6 +12,5 @@ export * as Base64Utils from './base64';
12
12
  export { HistoryStack } from './stack';
13
13
  export { WatchDog } from './watch-dog';
14
14
  export { Level } from './level';
15
- export * as PuboGeometry from './math/geometry';
16
15
  export { callbackToPromise } from './promise';
17
- export { getAngle, getDistance, degrees, radians, filterKeyPoints } from './math/geometry';
16
+ export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints } from './math/geometry';
package/es/index.js CHANGED
@@ -13,7 +13,5 @@ export { _Base64Utils as Base64Utils };
13
13
  export { HistoryStack } from './stack';
14
14
  export { WatchDog } from './watch-dog';
15
15
  export { Level } from './level';
16
- import * as _PuboGeometry from './math/geometry';
17
- export { _PuboGeometry as PuboGeometry };
18
16
  export { callbackToPromise } from './promise';
19
- export { getAngle, getDistance, degrees, radians, filterKeyPoints } from './math/geometry';
17
+ export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints } from './math/geometry';
@@ -10,5 +10,5 @@ interface Point2D {
10
10
  y: number;
11
11
  }
12
12
  export declare function filterKeyPoints(list: Point2D[], len?: number): Point2D[];
13
- export declare function getCenter(list: Point2D[]): Point2D;
13
+ export declare function getCenter(list: Point2D[] | [number, number][]): Point2D;
14
14
  export {};
@@ -79,8 +79,14 @@ export function getCenter(list) {
79
79
  try {
80
80
  for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
81
81
  var item = list_1_1.value;
82
- tmp[0] += item.x;
83
- tmp[1] += item.y;
82
+
83
+ if (Array.isArray(item)) {
84
+ tmp[0] += item[0];
85
+ tmp[1] += item[1];
86
+ } else {
87
+ tmp[0] += item.x;
88
+ tmp[1] += item.y;
89
+ }
84
90
  }
85
91
  } catch (e_1_1) {
86
92
  e_1 = {
@@ -96,6 +102,6 @@ export function getCenter(list) {
96
102
 
97
103
  return {
98
104
  x: tmp[0] / list.length,
99
- y: tmp[0] / list.length
105
+ y: tmp[1] / list.length
100
106
  };
101
107
  }
package/lib/index.d.ts CHANGED
@@ -12,6 +12,5 @@ export * as Base64Utils from './base64';
12
12
  export { HistoryStack } from './stack';
13
13
  export { WatchDog } from './watch-dog';
14
14
  export { Level } from './level';
15
- export * as PuboGeometry from './math/geometry';
16
15
  export { callbackToPromise } from './promise';
17
- export { getAngle, getDistance, degrees, radians, filterKeyPoints } from './math/geometry';
16
+ export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints } from './math/geometry';
package/lib/index.js CHANGED
@@ -161,7 +161,6 @@ Object.defineProperty(exports, "Level", {
161
161
  return level_1.Level;
162
162
  }
163
163
  });
164
- exports.PuboGeometry = __importStar(require("./math/geometry"));
165
164
 
166
165
  var promise_1 = require("./promise");
167
166
 
@@ -186,6 +185,12 @@ Object.defineProperty(exports, "getDistance", {
186
185
  return geometry_1.getDistance;
187
186
  }
188
187
  });
188
+ Object.defineProperty(exports, "getCenter", {
189
+ enumerable: true,
190
+ get: function get() {
191
+ return geometry_1.getCenter;
192
+ }
193
+ });
189
194
  Object.defineProperty(exports, "degrees", {
190
195
  enumerable: true,
191
196
  get: function get() {
@@ -10,5 +10,5 @@ interface Point2D {
10
10
  y: number;
11
11
  }
12
12
  export declare function filterKeyPoints(list: Point2D[], len?: number): Point2D[];
13
- export declare function getCenter(list: Point2D[]): Point2D;
13
+ export declare function getCenter(list: Point2D[] | [number, number][]): Point2D;
14
14
  export {};
@@ -92,8 +92,14 @@ function getCenter(list) {
92
92
  try {
93
93
  for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
94
94
  var item = list_1_1.value;
95
- tmp[0] += item.x;
96
- tmp[1] += item.y;
95
+
96
+ if (Array.isArray(item)) {
97
+ tmp[0] += item[0];
98
+ tmp[1] += item[1];
99
+ } else {
100
+ tmp[0] += item.x;
101
+ tmp[1] += item.y;
102
+ }
97
103
  }
98
104
  } catch (e_1_1) {
99
105
  e_1 = {
@@ -109,7 +115,7 @@ function getCenter(list) {
109
115
 
110
116
  return {
111
117
  x: tmp[0] / list.length,
112
- y: tmp[0] / list.length
118
+ y: tmp[1] / list.length
113
119
  };
114
120
  }
115
121
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-utils",
3
- "version": "1.0.64",
3
+ "version": "1.0.67",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -18,5 +18,5 @@
18
18
  "engines": {
19
19
  "node": ">=8.0.0"
20
20
  },
21
- "gitHead": "fc2cd238ec97c2ec76e71ed489bfe4353987b673"
21
+ "gitHead": "16e383170f644fddb2732f1767f2b424b2b9effb"
22
22
  }