pubo-utils 1.0.62 → 1.0.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pubo-utils.js +1 -1
- package/es/color/utils.d.ts +10 -1
- package/es/color/utils.js +68 -2
- package/es/math/geometry.d.ts +1 -0
- package/es/math/geometry.js +53 -1
- package/lib/color/utils.d.ts +10 -1
- package/lib/color/utils.js +70 -3
- package/lib/math/geometry.d.ts +1 -0
- package/lib/math/geometry.js +57 -3
- package/package.json +2 -2
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,(function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=0)}([function(t,n,e){"use strict";e.r(n),e.d(n,"debounce",(function(){return c})),e.d(n,"hex2rgb",(function(){return a})),e.d(n,"Emitter",(function(){return p})),e.d(n,"superFactory",(function(){return d})),e.d(n,"loop",(function(){return x})),e.d(n,"waitFor",(function(){return S})),e.d(n,"SyncQueue",(function(){return P})),e.d(n,"random",(function(){return f})),e.d(n,"sleep",(function(){return m})),e.d(n,"throttle",(function(){return O})),e.d(n,"ContinuousTrigger",(function(){return _})),e.d(n,"Base64Utils",(function(){return r})),e.d(n,"HistoryStack",(function(){return I})),e.d(n,"WatchDog",(function(){return G})),e.d(n,"Level",(function(){return D})),e.d(n,"PuboGeometry",(function(){return o})),e.d(n,"callbackToPromise",(function(){return L})),e.d(n,"getAngle",(function(){return K})),e.d(n,"getDistance",(function(){return U})),e.d(n,"degrees",(function(){return q})),e.d(n,"radians",(function(){return F})),e.d(n,"filterKeyPoints",(function(){return B}));var r={};e.r(r),e.d(r,"EncoderMap",(function(){return A})),e.d(r,"toUnit8Array",(function(){return E}));var o={};e.r(o),e.d(o,"getDistance",(function(){return U})),e.d(o,"degrees",(function(){return q})),e.d(o,"radians",(function(){return F})),e.d(o,"getAngle",(function(){return K})),e.d(o,"filterKeyPoints",(function(){return B}));var i=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},u=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(i(arguments[n]));return t},c=function(t,n,e){if(void 0===e&&(e=!1),e){var r,o=!0;return function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];o&&(t.apply(void 0,u(e)),o=!1),r&&clearTimeout(r),r=setTimeout((function(){return o=!0}),n)}}var i;return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];i&&clearTimeout(i),i=setTimeout((function(){return t.apply(void 0,u(e))}),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 e="",r=0;r<=t;r+=8)e+=n(t-r>8?8:t-r);return e},l=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.")},s=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},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 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){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=l(this.state[t]),u=i.next();!u.done;u=i.next()){var c=u.value;"function"==typeof c&&c.apply(void 0,h(r))}}catch(t){n={error:t}}finally{try{u&&!u.done&&(e=i.return)&&e.call(i)}finally{if(n)throw n.error}}},t}(),y=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(t){return function(n){var e,r,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){e={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o}},v=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},b=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: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(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=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++,r=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],r=0}finally{e=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,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((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: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(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=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++,r=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],r=0}finally{e=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 e=!0,r=function(){e=!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(r)];case 1:return i.sent(),[4,m(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 g(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)}))},k=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},T=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: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(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=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++,r=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],r=0}finally{e=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,e=t.promise;return k(this,void 0,void 0,(function(){var t,r;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(),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 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(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.cache.length},enumerable:!1,configurable:!0}),t}(),j=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},M=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(j(arguments[n]));return t};function O(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,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),e=0,r=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(r=(r<<6)+A[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}(),G=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(){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,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}(),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,e=t.w,r=t.h,o=q(Math.asin(r/Math.sqrt(Math.pow(e,2)+Math.pow(r,2))));return(n=e<=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,r){return r<1||U(t[r-1],e)>=n}))}var 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},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=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return new Promise((function(e,r){t.apply(void 0,H(n,[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(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 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))}]))}))}}}])}));
|
package/es/color/utils.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
export declare const hex2rgb: (n:
|
|
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
|
|
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/math/geometry.d.ts
CHANGED
package/es/math/geometry.js
CHANGED
|
@@ -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
|
}; // 弧度转角度
|
|
@@ -43,7 +60,42 @@ export function filterKeyPoints(list, len) {
|
|
|
43
60
|
return list;
|
|
44
61
|
}
|
|
45
62
|
|
|
63
|
+
var last;
|
|
46
64
|
return list.filter(function (item, i) {
|
|
47
|
-
|
|
65
|
+
if (i > 0 && getDistance(last, item) < len) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
last = list[i];
|
|
70
|
+
return true;
|
|
48
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
|
+
};
|
|
49
101
|
}
|
package/lib/color/utils.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
export declare const hex2rgb: (n:
|
|
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/lib/color/utils.js
CHANGED
|
@@ -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
|
|
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/math/geometry.d.ts
CHANGED
package/lib/math/geometry.js
CHANGED
|
@@ -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));
|
|
@@ -54,9 +71,46 @@ function filterKeyPoints(list, len) {
|
|
|
54
71
|
return list;
|
|
55
72
|
}
|
|
56
73
|
|
|
74
|
+
var last;
|
|
57
75
|
return list.filter(function (item, i) {
|
|
58
|
-
|
|
76
|
+
if (i > 0 && exports.getDistance(last, item) < len) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
last = list[i];
|
|
81
|
+
return true;
|
|
59
82
|
});
|
|
60
83
|
}
|
|
61
84
|
|
|
62
|
-
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.
|
|
3
|
+
"version": "1.0.64",
|
|
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": "
|
|
21
|
+
"gitHead": "fc2cd238ec97c2ec76e71ed489bfe4353987b673"
|
|
22
22
|
}
|