pubo-utils 1.0.63 → 1.0.66

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 a})),r.d(n,"Emitter",(function(){return p})),r.d(n,"superFactory",(function(){return d})),r.d(n,"loop",(function(){return x})),r.d(n,"waitFor",(function(){return S})),r.d(n,"SyncQueue",(function(){return P})),r.d(n,"random",(function(){return f})),r.d(n,"sleep",(function(){return m})),r.d(n,"throttle",(function(){return O})),r.d(n,"ContinuousTrigger",(function(){return _})),r.d(n,"Base64Utils",(function(){return e})),r.d(n,"HistoryStack",(function(){return I})),r.d(n,"WatchDog",(function(){return G})),r.d(n,"Level",(function(){return D})),r.d(n,"PuboGeometry",(function(){return o})),r.d(n,"callbackToPromise",(function(){return L})),r.d(n,"getAngle",(function(){return K})),r.d(n,"getDistance",(function(){return U})),r.d(n,"degrees",(function(){return q})),r.d(n,"radians",(function(){return F})),r.d(n,"filterKeyPoints",(function(){return B}));var e={};r.r(e),r.d(e,"EncoderMap",(function(){return A})),r.d(e,"toUnit8Array",(function(){return E}));var o={};r.r(o),r.d(o,"getDistance",(function(){return U})),r.d(o,"degrees",(function(){return q})),r.d(o,"radians",(function(){return F})),r.d(o,"getAngle",(function(){return K})),r.d(o,"filterKeyPoints",(function(){return B}));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){var n=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){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},l=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.")},s=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},h=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(s(arguments[n]));return t},p=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=f(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=l(this.state[t]),u=i.next();!u.done;u=i.next()){var c=u.value;"function"==typeof c&&c.apply(void 0,h(e))}}catch(t){n={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},t}(),y=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.")},d=function(t){return function(n){var r,e,o={};try{for(var i=y(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}},v=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())}))},b=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 v(void 0,void 0,void 0,(function(){return b(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]}}))}))},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())}))},w=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])}}},x=function(t,n){var r=!0,e=function(){r=!1},o=function(){return g(void 0,void 0,void 0,(function(){return w(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},S=function(t,n){var r=void 0===n?{}:n,e=r.checkTime,o=r.timeout;return new Promise((function(n,r){var i=x((function(){return g(void 0,void 0,void 0,(function(){var r;return w(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)}))},k=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())}))},T=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 k(this,void 0,void 0,(function(){var t,e;return T(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 k(this,void 0,void 0,(function(){var t;return T(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}(),j=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(j(arguments[n]));return t};function O(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 _=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}(),A=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function E(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)+A[t.charAt(i)],(r+=6)>=8){var u=e>>>(r-=8);n[o++]=255&u,e-=u<<=r}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}(),G=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}(),D=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}(),U=function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2))},q=function(t){return 180*t/Math.PI},F=function(t){return t*Math.PI/180},K=function(t){var n,r=t.w,e=t.h,o=q(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 B(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(e,o){return!(o>0&&U(r,e)<n)&&(r=t[o],!0)}));var r}var C=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},H=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(C(arguments[n]));return t},L=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,H(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(H(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 A})),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},M=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(O(arguments[n]));return t};function A(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 _=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;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}}}])}));
@@ -1 +1,10 @@
1
- export declare const hex2rgb: (n: any) => number[];
1
+ export declare const hex2rgb: (n: number | string) => [number, number, number];
2
+ export declare const rgb2hex: (color: [number, number, number] | [number, number, number, number]) => string;
3
+ export declare class ColorUtils {
4
+ int: number;
5
+ constructor(n: number | string | [number, number, number]);
6
+ getRgbArray(): [number, number, number];
7
+ get rgb(): string;
8
+ get hex(): string;
9
+ toString(type?: string): string;
10
+ }
package/es/color/utils.js CHANGED
@@ -1,7 +1,73 @@
1
+ var str2int = function str2int(str) {
2
+ return parseInt(str.replace('#', ''), 16);
3
+ };
4
+
1
5
  export var hex2rgb = function hex2rgb(n) {
2
- var str = n.toString(2).padStart(24, 0);
6
+ var v;
7
+
8
+ if (typeof n === 'string') {
9
+ v = str2int(n);
10
+ } else {
11
+ v = n;
12
+ }
13
+
14
+ var str = v.toString(2).padStart(24, '0');
3
15
  var r = parseInt(str.slice(0, 8), 2);
4
16
  var g = parseInt(str.slice(8, 16), 2);
5
17
  var b = parseInt(str.slice(16, 24), 2);
6
18
  return [r, g, b];
7
- };
19
+ };
20
+ export var rgb2hex = function rgb2hex(color) {
21
+ return '#' + [0, 1, 2].map(function (i) {
22
+ return color[i].toString(16);
23
+ }).join('');
24
+ };
25
+
26
+ var ColorUtils =
27
+ /** @class */
28
+ function () {
29
+ function ColorUtils(n) {
30
+ if (typeof n === 'number') {
31
+ this["int"] = n;
32
+ } else if (typeof n === 'string') {
33
+ this["int"] = str2int(n);
34
+ } else if (Array.isArray(n)) {
35
+ this["int"] = str2int(rgb2hex(n));
36
+ }
37
+ }
38
+
39
+ ColorUtils.prototype.getRgbArray = function () {
40
+ return hex2rgb(this["int"]);
41
+ };
42
+
43
+ Object.defineProperty(ColorUtils.prototype, "rgb", {
44
+ get: function get() {
45
+ return "rba(" + this.getRgbArray().join(', ') + ")";
46
+ },
47
+ enumerable: false,
48
+ configurable: true
49
+ });
50
+ Object.defineProperty(ColorUtils.prototype, "hex", {
51
+ get: function get() {
52
+ return rgb2hex(this.getRgbArray());
53
+ },
54
+ enumerable: false,
55
+ configurable: true
56
+ });
57
+
58
+ ColorUtils.prototype.toString = function (type) {
59
+ if (type === void 0) {
60
+ type = 'hex';
61
+ }
62
+
63
+ if (type === 'rgb') {
64
+ return this.rgb;
65
+ }
66
+
67
+ return this.hex;
68
+ };
69
+
70
+ return ColorUtils;
71
+ }();
72
+
73
+ export { ColorUtils };
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,4 +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
14
  export {};
@@ -1,3 +1,20 @@
1
+ var __values = this && this.__values || function (o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator,
3
+ m = s && o[s],
4
+ i = 0;
5
+ if (m) return m.call(o);
6
+ if (o && typeof o.length === "number") return {
7
+ next: function next() {
8
+ if (o && i >= o.length) o = void 0;
9
+ return {
10
+ value: o && o[i++],
11
+ done: !o
12
+ };
13
+ }
14
+ };
15
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
16
+ };
17
+
1
18
  export var getDistance = function getDistance(a, b) {
2
19
  return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
3
20
  }; // 弧度转角度
@@ -52,4 +69,33 @@ export function filterKeyPoints(list, len) {
52
69
  last = list[i];
53
70
  return true;
54
71
  });
72
+ } // 获取中心点坐标
73
+
74
+ export function getCenter(list) {
75
+ var e_1, _a;
76
+
77
+ var tmp = [0, 0];
78
+
79
+ try {
80
+ for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
81
+ var item = list_1_1.value;
82
+ tmp[0] += item.x;
83
+ tmp[1] += item.y;
84
+ }
85
+ } catch (e_1_1) {
86
+ e_1 = {
87
+ error: e_1_1
88
+ };
89
+ } finally {
90
+ try {
91
+ if (list_1_1 && !list_1_1.done && (_a = list_1["return"])) _a.call(list_1);
92
+ } finally {
93
+ if (e_1) throw e_1.error;
94
+ }
95
+ }
96
+
97
+ return {
98
+ x: tmp[0] / list.length,
99
+ y: tmp[0] / list.length
100
+ };
55
101
  }
@@ -1 +1,10 @@
1
- export declare const hex2rgb: (n: any) => number[];
1
+ export declare const hex2rgb: (n: number | string) => [number, number, number];
2
+ export declare const rgb2hex: (color: [number, number, number] | [number, number, number, number]) => string;
3
+ export declare class ColorUtils {
4
+ int: number;
5
+ constructor(n: number | string | [number, number, number]);
6
+ getRgbArray(): [number, number, number];
7
+ get rgb(): string;
8
+ get hex(): string;
9
+ toString(type?: string): string;
10
+ }
@@ -3,12 +3,79 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.hex2rgb = void 0;
6
+ exports.ColorUtils = exports.rgb2hex = exports.hex2rgb = void 0;
7
+
8
+ var str2int = function str2int(str) {
9
+ return parseInt(str.replace('#', ''), 16);
10
+ };
7
11
 
8
12
  exports.hex2rgb = function (n) {
9
- var str = n.toString(2).padStart(24, 0);
13
+ var v;
14
+
15
+ if (typeof n === 'string') {
16
+ v = str2int(n);
17
+ } else {
18
+ v = n;
19
+ }
20
+
21
+ var str = v.toString(2).padStart(24, '0');
10
22
  var r = parseInt(str.slice(0, 8), 2);
11
23
  var g = parseInt(str.slice(8, 16), 2);
12
24
  var b = parseInt(str.slice(16, 24), 2);
13
25
  return [r, g, b];
14
- };
26
+ };
27
+
28
+ exports.rgb2hex = function (color) {
29
+ return '#' + [0, 1, 2].map(function (i) {
30
+ return color[i].toString(16);
31
+ }).join('');
32
+ };
33
+
34
+ var ColorUtils =
35
+ /** @class */
36
+ function () {
37
+ function ColorUtils(n) {
38
+ if (typeof n === 'number') {
39
+ this["int"] = n;
40
+ } else if (typeof n === 'string') {
41
+ this["int"] = str2int(n);
42
+ } else if (Array.isArray(n)) {
43
+ this["int"] = str2int(exports.rgb2hex(n));
44
+ }
45
+ }
46
+
47
+ ColorUtils.prototype.getRgbArray = function () {
48
+ return exports.hex2rgb(this["int"]);
49
+ };
50
+
51
+ Object.defineProperty(ColorUtils.prototype, "rgb", {
52
+ get: function get() {
53
+ return "rba(" + this.getRgbArray().join(', ') + ")";
54
+ },
55
+ enumerable: false,
56
+ configurable: true
57
+ });
58
+ Object.defineProperty(ColorUtils.prototype, "hex", {
59
+ get: function get() {
60
+ return exports.rgb2hex(this.getRgbArray());
61
+ },
62
+ enumerable: false,
63
+ configurable: true
64
+ });
65
+
66
+ ColorUtils.prototype.toString = function (type) {
67
+ if (type === void 0) {
68
+ type = 'hex';
69
+ }
70
+
71
+ if (type === 'rgb') {
72
+ return this.rgb;
73
+ }
74
+
75
+ return this.hex;
76
+ };
77
+
78
+ return ColorUtils;
79
+ }();
80
+
81
+ exports.ColorUtils = ColorUtils;
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,4 +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
14
  export {};
@@ -1,9 +1,26 @@
1
1
  "use strict";
2
2
 
3
+ var __values = this && this.__values || function (o) {
4
+ var s = typeof Symbol === "function" && Symbol.iterator,
5
+ m = s && o[s],
6
+ i = 0;
7
+ if (m) return m.call(o);
8
+ if (o && typeof o.length === "number") return {
9
+ next: function next() {
10
+ if (o && i >= o.length) o = void 0;
11
+ return {
12
+ value: o && o[i++],
13
+ done: !o
14
+ };
15
+ }
16
+ };
17
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
18
+ };
19
+
3
20
  Object.defineProperty(exports, "__esModule", {
4
21
  value: true
5
22
  });
6
- exports.filterKeyPoints = exports.getAngle = exports.radians = exports.degrees = exports.getDistance = void 0;
23
+ exports.getCenter = exports.filterKeyPoints = exports.getAngle = exports.radians = exports.degrees = exports.getDistance = void 0;
7
24
 
8
25
  exports.getDistance = function (a, b) {
9
26
  return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
@@ -65,4 +82,35 @@ function filterKeyPoints(list, len) {
65
82
  });
66
83
  }
67
84
 
68
- exports.filterKeyPoints = filterKeyPoints;
85
+ exports.filterKeyPoints = filterKeyPoints; // 获取中心点坐标
86
+
87
+ function getCenter(list) {
88
+ var e_1, _a;
89
+
90
+ var tmp = [0, 0];
91
+
92
+ try {
93
+ for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
94
+ var item = list_1_1.value;
95
+ tmp[0] += item.x;
96
+ tmp[1] += item.y;
97
+ }
98
+ } catch (e_1_1) {
99
+ e_1 = {
100
+ error: e_1_1
101
+ };
102
+ } finally {
103
+ try {
104
+ if (list_1_1 && !list_1_1.done && (_a = list_1["return"])) _a.call(list_1);
105
+ } finally {
106
+ if (e_1) throw e_1.error;
107
+ }
108
+ }
109
+
110
+ return {
111
+ x: tmp[0] / list.length,
112
+ y: tmp[0] / list.length
113
+ };
114
+ }
115
+
116
+ exports.getCenter = getCenter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-utils",
3
- "version": "1.0.63",
3
+ "version": "1.0.66",
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": "df1dcdd2ad36f4b5022088af306b6d71314c5de0"
21
+ "gitHead": "c426ff977160010b6b3af440963c31b92a543952"
22
22
  }