pubo-utils 1.0.67 → 1.0.68
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/base64/index.js +16 -21
- package/es/color/utils.d.ts +10 -1
- package/es/color/utils.js +2 -15
- package/es/debounce/index.js +13 -25
- package/es/emitter/index.js +17 -42
- package/es/factory/index.d.ts +5 -5
- package/es/factory/index.js +2 -6
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/es/level/index.js +1 -9
- package/es/loop/index.d.ts +1 -1
- package/es/loop/index.js +67 -118
- package/es/math/geometry.js +11 -23
- package/es/promise/index.js +16 -25
- package/es/queue/index.js +70 -129
- package/es/random/index.js +0 -5
- package/es/regexp-list/index.d.ts +7 -0
- package/es/regexp-list/index.js +20 -0
- package/es/sleep/index.js +62 -96
- package/es/stack/index.js +1 -16
- package/es/throttle/index.js +12 -19
- package/es/trigger/index.js +1 -10
- package/es/watch-dog/index.js +3 -11
- package/lib/base64/index.js +16 -24
- package/lib/color/utils.d.ts +10 -1
- package/lib/color/utils.js +9 -22
- package/lib/debounce/index.js +16 -28
- package/lib/emitter/index.js +18 -44
- package/lib/factory/index.d.ts +5 -5
- package/lib/factory/index.js +5 -9
- package/lib/index.d.ts +1 -0
- package/lib/index.js +19 -44
- package/lib/level/index.js +1 -10
- package/lib/loop/index.d.ts +1 -1
- package/lib/loop/index.js +73 -125
- package/lib/math/geometry.js +21 -36
- package/lib/promise/index.js +19 -27
- package/lib/queue/index.js +70 -130
- package/lib/random/index.js +3 -8
- package/lib/regexp-list/index.d.ts +7 -0
- package/lib/regexp-list/index.js +26 -0
- package/lib/sleep/index.js +66 -99
- package/lib/stack/index.js +1 -17
- package/lib/throttle/index.js +12 -21
- package/lib/trigger/index.js +1 -11
- package/lib/watch-dog/index.js +3 -12
- 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 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}}}])}));
|
|
1
|
+
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["pubo-utils"]=n():t["pubo-utils"]=n()}(this,(()=>(()=>{"use strict";var t={d:(n,e)=>{for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};t.r(n),t.d(n,{Base64Utils:()=>e,ContinuousTrigger:()=>P,Emitter:()=>p,HistoryStack:()=>O,Level:()=>_,RegExpList:()=>B,SyncQueue:()=>S,WatchDog:()=>M,callbackToPromise:()=>L,debounce:()=>i,degrees:()=>q,filterKeyPoints:()=>F,getAngle:()=>D,getCenter:()=>X,getDistance:()=>U,hex2rgb:()=>c,loop:()=>g,radians:()=>C,random:()=>l,sleep:()=>v,superFactory:()=>y,throttle:()=>A,waitFor:()=>m});var e={};t.r(e),t.d(e,{EncoderMap:()=>j,toUnit8Array:()=>E});var r=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},o=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},i=function(t,n,e){if(void 0===e&&(e=!1),e){var i,u=!0;return function(){for(var e=[],c=0;c<arguments.length;c++)e[c]=arguments[c];u&&(t.apply(void 0,o([],r(e),!1)),u=!1),i&&clearTimeout(i),i=setTimeout((function(){return u=!0}),n)}}var c;return function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];c&&clearTimeout(c),c=setTimeout((function(){return t.apply(void 0,o([],r(e),!1))}),n)}},u=function(t){return parseInt(t.replace("#",""),16)},c=function(t){var n=("string"==typeof t?u(t):t).toString(2).padStart(24,"0");return[parseInt(n.slice(0,8),2),parseInt(n.slice(8,16),2),parseInt(n.slice(16,24),2)]},a=function(t){return"#"+[0,1,2].map((function(n){return t[n].toString(16)})).join("")},l=(function(){function t(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=u(t):Array.isArray(t)&&(this.int=u(a(t)))}t.prototype.getRgbArray=function(){return c(this.int)},Object.defineProperty(t.prototype,"rgb",{get:function(){return"rba(".concat(this.getRgbArray().join(", "),")")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hex",{get:function(){return a(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 e="",r=0;r<=t;r+=8)e+=n(t-r>8?8:t-r);return e}),s=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},f=function(t,n){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(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},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=l(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=s(this.state[t]),u=i.next();!u.done;u=i.next()){var c=u.value;"function"==typeof c&&c.apply(void 0,h([],f(r),!1))}}catch(t){n={error:t}}finally{try{u&&!u.done&&(e=i.return)&&e.call(i)}finally{if(n)throw n.error}}},t}(),y=function(t){return function(n){var e,r,o={};try{for(var i=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.keys(n)),u=i.next();!u.done;u=i.next()){var 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){return n=void 0,e=void 0,o=function(){return function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=n.call(t,u)}catch(t){c=[6,t],r=0}finally{e=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){return setTimeout((function(){return n()}),t)}))];case 1:return n.sent(),[2]}}))},new((r=void 0)||(r=Promise))((function(t,i){function u(t){try{a(o.next(t))}catch(t){i(t)}}function c(t){try{a(o.throw(t))}catch(t){i(t)}}function a(n){var e;n.done?t(n.value):(e=n.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,c)}a((o=o.apply(n,e||[])).next())}));var n,e,r,o},d=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(c){return function(a){return function(c){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=n.call(t,u)}catch(t){c=[6,t],r=0}finally{e=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}},g=function(t,n){var e=!0,r=function(){e=!1},o=function(){return d(void 0,void 0,void 0,(function(){return b(this,(function(i){switch(i.label){case 0:return[4,t(r)];case 1:return i.sent(),[4,v(n)];case 2:return i.sent(),e?o():o=null,[2]}}))}))};return o(),r},m=function(t,n){var e=void 0===n?{}:n,r=e.checkTime,o=e.timeout;return new Promise((function(n,e){var i=g((function(){return d(void 0,void 0,void 0,(function(){var e;return b(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)}))},w=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())}))},x=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=n.call(t,u)}catch(t){c=[6,t],r=0}finally{e=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}},S=function(){function t(){this.cache=[],this.running=!1}return t.prototype._run=function(t){var n=t.fn,e=t.promise;return w(this,void 0,void 0,(function(){var t,r;return x(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 w(this,void 0,void 0,(function(){var t;return x(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}(),k=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},T=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))};function A(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,T([],k(o),!1)))}}var P=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}(),j=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)+j[t.charAt(i)],(e+=6)>=8){var u=r>>>(e-=8);n[o++]=255&u,r-=u<<=e}return n}var O=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}(),M=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}(),_=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}(),R=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},I=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},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,I(I([],R(n),!1),[function(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];t&&r(t),n.length<2?e(n[0]):e(I([],R(n),!1))}],!1))}))}},G=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.")},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},C=function(t){return t*Math.PI/180},D=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 F(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(r,o){return!(o>0&&U(e,r)<n||(e=t[o],0))}));var e}function X(t){var n,e,r=[0,0];try{for(var o=G(t),i=o.next();!i.done;i=o.next()){var u=i.value;Array.isArray(u)?(r[0]+=u[0],r[1]+=u[1]):(r[0]+=u.x,r[1]+=u.y)}}catch(t){n={error:t}}finally{try{i&&!i.done&&(e=o.return)&&e.call(o)}finally{if(n)throw n.error}}return{x:r[0]/t.length,y:r[1]/t.length}}var B=function(){function t(t){this._RegExpList=null,this.list=t}return t.prototype.getRegEXP=function(t){var n=t.replace("/","\\/").replace("*",".*");return new RegExp(n,"g")},t.prototype.include=function(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((function(n){return n.test(t)}))},t}();return n})()));
|
package/es/base64/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export var EncoderMap = function () {
|
|
2
2
|
var S = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
3
3
|
var e = {};
|
|
4
|
-
|
|
5
4
|
for (var i = 0; i < 64; i++) {
|
|
6
5
|
e[S.charAt(i)] = i;
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
return e;
|
|
10
8
|
}();
|
|
11
9
|
/**
|
|
@@ -14,33 +12,30 @@ export var EncoderMap = function () {
|
|
|
14
12
|
* @param output Uint8Array
|
|
15
13
|
* base64 6位的二进制, Uint8Array 8位的二进制,整体原理就是将 base64 的每个字符转成2进制然后拼接,再按每个八位为一个单位地取出
|
|
16
14
|
*/
|
|
17
|
-
|
|
18
15
|
export function toUnit8Array(input) {
|
|
19
|
-
var output = new Uint8Array(input.length * 6 / 8);
|
|
20
|
-
|
|
21
|
-
var l = 0;
|
|
22
|
-
|
|
23
|
-
var b = 0;
|
|
24
|
-
|
|
16
|
+
var output = new Uint8Array(input.length * 6 / 8);
|
|
17
|
+
// 当前二进制字符长度
|
|
18
|
+
var l = 0;
|
|
19
|
+
// 二进制字符缓存值(格式为10进制)
|
|
20
|
+
var b = 0;
|
|
21
|
+
// Uint8Array 的指针
|
|
25
22
|
var j = 0;
|
|
26
|
-
|
|
27
23
|
for (var x = 0; x < input.length && j < output.length; x += 1) {
|
|
28
|
-
b = (b << 6) + EncoderMap[input.charAt(x)];
|
|
29
|
-
|
|
30
|
-
l += 6;
|
|
31
|
-
|
|
24
|
+
b = (b << 6) + EncoderMap[input.charAt(x)];
|
|
25
|
+
// 为什么是6? base64 为64个字符,也就是 2^6,用二进制表示就是6位
|
|
26
|
+
l += 6;
|
|
27
|
+
// 为什么是8? Uint8Array 是八位的二进制
|
|
32
28
|
if (l >= 8) {
|
|
33
29
|
// 取了前八位后剩余长度
|
|
34
|
-
l -= 8;
|
|
35
|
-
|
|
30
|
+
l -= 8;
|
|
31
|
+
// 前八位的值
|
|
36
32
|
var c = b >>> l;
|
|
37
|
-
output[j++] = c & 0xff;
|
|
38
|
-
|
|
39
|
-
c = c << l;
|
|
40
|
-
|
|
33
|
+
output[j++] = c & 0xff;
|
|
34
|
+
// 再将右移的值左移回来,除了前八位不变,后面的皆为0
|
|
35
|
+
c = c << l;
|
|
36
|
+
// 通过减法得到第八位之后的值
|
|
41
37
|
b = b - c;
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
|
-
|
|
45
40
|
return output;
|
|
46
41
|
}
|
package/es/color/utils.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
export declare const hex2rgb: (n: number | string) => [number, number, number];
|
|
2
|
-
export declare const rgb2hex: (color: [
|
|
2
|
+
export declare const rgb2hex: (color: [
|
|
3
|
+
number,
|
|
4
|
+
number,
|
|
5
|
+
number
|
|
6
|
+
] | [
|
|
7
|
+
number,
|
|
8
|
+
number,
|
|
9
|
+
number,
|
|
10
|
+
number
|
|
11
|
+
]) => string;
|
|
3
12
|
export declare class ColorUtils {
|
|
4
13
|
int: number;
|
|
5
14
|
constructor(n: number | string | [number, number, number]);
|
package/es/color/utils.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
var str2int = function str2int(str) {
|
|
2
2
|
return parseInt(str.replace('#', ''), 16);
|
|
3
3
|
};
|
|
4
|
-
|
|
5
4
|
export var hex2rgb = function hex2rgb(n) {
|
|
6
5
|
var v;
|
|
7
|
-
|
|
8
6
|
if (typeof n === 'string') {
|
|
9
7
|
v = str2int(n);
|
|
10
8
|
} else {
|
|
11
9
|
v = n;
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
var str = v.toString(2).padStart(24, '0');
|
|
15
12
|
var r = parseInt(str.slice(0, 8), 2);
|
|
16
13
|
var g = parseInt(str.slice(8, 16), 2);
|
|
@@ -22,10 +19,7 @@ export var rgb2hex = function rgb2hex(color) {
|
|
|
22
19
|
return color[i].toString(16);
|
|
23
20
|
}).join('');
|
|
24
21
|
};
|
|
25
|
-
|
|
26
|
-
var ColorUtils =
|
|
27
|
-
/** @class */
|
|
28
|
-
function () {
|
|
22
|
+
var ColorUtils = /** @class */function () {
|
|
29
23
|
function ColorUtils(n) {
|
|
30
24
|
if (typeof n === 'number') {
|
|
31
25
|
this["int"] = n;
|
|
@@ -35,14 +29,12 @@ function () {
|
|
|
35
29
|
this["int"] = str2int(rgb2hex(n));
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
ColorUtils.prototype.getRgbArray = function () {
|
|
40
33
|
return hex2rgb(this["int"]);
|
|
41
34
|
};
|
|
42
|
-
|
|
43
35
|
Object.defineProperty(ColorUtils.prototype, "rgb", {
|
|
44
36
|
get: function get() {
|
|
45
|
-
return "rba("
|
|
37
|
+
return "rba(".concat(this.getRgbArray().join(', '), ")");
|
|
46
38
|
},
|
|
47
39
|
enumerable: false,
|
|
48
40
|
configurable: true
|
|
@@ -54,20 +46,15 @@ function () {
|
|
|
54
46
|
enumerable: false,
|
|
55
47
|
configurable: true
|
|
56
48
|
});
|
|
57
|
-
|
|
58
49
|
ColorUtils.prototype.toString = function (type) {
|
|
59
50
|
if (type === void 0) {
|
|
60
51
|
type = 'hex';
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
if (type === 'rgb') {
|
|
64
54
|
return this.rgb;
|
|
65
55
|
}
|
|
66
|
-
|
|
67
56
|
return this.hex;
|
|
68
57
|
};
|
|
69
|
-
|
|
70
58
|
return ColorUtils;
|
|
71
59
|
}();
|
|
72
|
-
|
|
73
60
|
export { ColorUtils };
|
package/es/debounce/index.js
CHANGED
|
@@ -2,14 +2,11 @@ var __read = this && this.__read || function (o, n) {
|
|
|
2
2
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
3
|
if (!m) return o;
|
|
4
4
|
var i = m.call(o),
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
r,
|
|
6
|
+
ar = [],
|
|
7
|
+
e;
|
|
9
8
|
try {
|
|
10
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
11
|
-
ar.push(r.value);
|
|
12
|
-
}
|
|
9
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
13
10
|
} catch (error) {
|
|
14
11
|
e = {
|
|
15
12
|
error: error
|
|
@@ -21,42 +18,36 @@ var __read = this && this.__read || function (o, n) {
|
|
|
21
18
|
if (e) throw e.error;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
return ar;
|
|
26
22
|
};
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
24
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
25
|
+
if (ar || !(i in from)) {
|
|
26
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
27
|
+
ar[i] = from[i];
|
|
28
|
+
}
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
return ar;
|
|
30
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
34
31
|
};
|
|
35
|
-
|
|
36
32
|
export var debounce = function debounce(cb, time, first) {
|
|
37
33
|
if (first === void 0) {
|
|
38
34
|
first = false;
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
if (first) {
|
|
42
37
|
var shouldRun_1 = true;
|
|
43
38
|
var t_1;
|
|
44
39
|
return function () {
|
|
45
40
|
var args = [];
|
|
46
|
-
|
|
47
41
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
48
42
|
args[_i] = arguments[_i];
|
|
49
43
|
}
|
|
50
|
-
|
|
51
44
|
if (shouldRun_1) {
|
|
52
|
-
cb.apply(void 0,
|
|
45
|
+
cb.apply(void 0, __spreadArray([], __read(args), false));
|
|
53
46
|
shouldRun_1 = false;
|
|
54
47
|
}
|
|
55
|
-
|
|
56
48
|
if (t_1) {
|
|
57
49
|
clearTimeout(t_1);
|
|
58
50
|
}
|
|
59
|
-
|
|
60
51
|
t_1 = setTimeout(function () {
|
|
61
52
|
return shouldRun_1 = true;
|
|
62
53
|
}, time);
|
|
@@ -65,17 +56,14 @@ export var debounce = function debounce(cb, time, first) {
|
|
|
65
56
|
var t_2;
|
|
66
57
|
return function () {
|
|
67
58
|
var args = [];
|
|
68
|
-
|
|
69
59
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
70
60
|
args[_i] = arguments[_i];
|
|
71
61
|
}
|
|
72
|
-
|
|
73
62
|
if (t_2) {
|
|
74
63
|
clearTimeout(t_2);
|
|
75
64
|
}
|
|
76
|
-
|
|
77
65
|
t_2 = setTimeout(function () {
|
|
78
|
-
return cb.apply(void 0,
|
|
66
|
+
return cb.apply(void 0, __spreadArray([], __read(args), false));
|
|
79
67
|
}, time);
|
|
80
68
|
};
|
|
81
69
|
}
|
package/es/emitter/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __values = this && this.__values || function (o) {
|
|
2
2
|
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
m = s && o[s],
|
|
4
|
+
i = 0;
|
|
5
5
|
if (m) return m.call(o);
|
|
6
6
|
if (o && typeof o.length === "number") return {
|
|
7
7
|
next: function next() {
|
|
@@ -14,19 +14,15 @@ var __values = this && this.__values || function (o) {
|
|
|
14
14
|
};
|
|
15
15
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
16
16
|
};
|
|
17
|
-
|
|
18
17
|
var __read = this && this.__read || function (o, n) {
|
|
19
18
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
20
19
|
if (!m) return o;
|
|
21
20
|
var i = m.call(o),
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
r,
|
|
22
|
+
ar = [],
|
|
23
|
+
e;
|
|
26
24
|
try {
|
|
27
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
28
|
-
ar.push(r.value);
|
|
29
|
-
}
|
|
25
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
26
|
} catch (error) {
|
|
31
27
|
e = {
|
|
32
28
|
error: error
|
|
@@ -38,37 +34,30 @@ var __read = this && this.__read || function (o, n) {
|
|
|
38
34
|
if (e) throw e.error;
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
|
-
|
|
42
37
|
return ar;
|
|
43
38
|
};
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
40
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
41
|
+
if (ar || !(i in from)) {
|
|
42
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
43
|
+
ar[i] = from[i];
|
|
44
|
+
}
|
|
48
45
|
}
|
|
49
|
-
|
|
50
|
-
return ar;
|
|
46
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
51
47
|
};
|
|
52
|
-
|
|
53
48
|
import { random } from '../random';
|
|
54
|
-
|
|
55
|
-
var Emitter =
|
|
56
|
-
/** @class */
|
|
57
|
-
function () {
|
|
49
|
+
var Emitter = /** @class */function () {
|
|
58
50
|
function Emitter() {
|
|
59
51
|
this.state = {};
|
|
60
52
|
this.ids = {};
|
|
61
53
|
}
|
|
62
|
-
|
|
63
54
|
Emitter.prototype.on = function (event, func) {
|
|
64
55
|
if (!this.state[event]) {
|
|
65
56
|
this.state[event] = [];
|
|
66
57
|
}
|
|
67
|
-
|
|
68
58
|
if (typeof func !== 'function') {
|
|
69
59
|
throw new Error('第二个参数必须为function!');
|
|
70
60
|
}
|
|
71
|
-
|
|
72
61
|
var index = this.state[event].push(func) - 1;
|
|
73
62
|
var key = random(40);
|
|
74
63
|
this.ids[key] = {
|
|
@@ -77,27 +66,21 @@ function () {
|
|
|
77
66
|
};
|
|
78
67
|
return key;
|
|
79
68
|
};
|
|
80
|
-
|
|
81
69
|
Emitter.prototype.cancel = function (id) {
|
|
82
70
|
var _this = this;
|
|
83
|
-
|
|
84
71
|
if (!id) {
|
|
85
72
|
this.clear();
|
|
86
73
|
return;
|
|
87
74
|
}
|
|
88
|
-
|
|
89
75
|
var _a = this.ids[id] || {},
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
76
|
+
event = _a.event,
|
|
77
|
+
index = _a.index;
|
|
93
78
|
if (!event) {
|
|
94
79
|
return;
|
|
95
80
|
}
|
|
96
|
-
|
|
97
81
|
if (!Array.isArray(this.state[event])) {
|
|
98
82
|
return;
|
|
99
83
|
}
|
|
100
|
-
|
|
101
84
|
this.state[event].splice(index, 1);
|
|
102
85
|
delete this.ids[id];
|
|
103
86
|
Object.keys(this.ids).forEach(function (key) {
|
|
@@ -106,27 +89,21 @@ function () {
|
|
|
106
89
|
}
|
|
107
90
|
});
|
|
108
91
|
};
|
|
109
|
-
|
|
110
92
|
Emitter.prototype.clear = function () {
|
|
111
93
|
this.state.length = 0;
|
|
112
94
|
};
|
|
113
|
-
|
|
114
95
|
Emitter.prototype.emit = function (event) {
|
|
115
96
|
var e_1, _a;
|
|
116
|
-
|
|
117
97
|
var args = [];
|
|
118
|
-
|
|
119
98
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
120
99
|
args[_i - 1] = arguments[_i];
|
|
121
100
|
}
|
|
122
|
-
|
|
123
101
|
if (Array.isArray(this.state[event])) {
|
|
124
102
|
try {
|
|
125
103
|
for (var _b = __values(this.state[event]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
126
104
|
var func = _c.value;
|
|
127
|
-
|
|
128
105
|
if (typeof func === 'function') {
|
|
129
|
-
func.apply(void 0,
|
|
106
|
+
func.apply(void 0, __spreadArray([], __read(args), false));
|
|
130
107
|
}
|
|
131
108
|
}
|
|
132
109
|
} catch (e_1_1) {
|
|
@@ -142,8 +119,6 @@ function () {
|
|
|
142
119
|
}
|
|
143
120
|
}
|
|
144
121
|
};
|
|
145
|
-
|
|
146
122
|
return Emitter;
|
|
147
123
|
}();
|
|
148
|
-
|
|
149
124
|
export { Emitter };
|
package/es/factory/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
type OptionsObject<T, C> = {
|
|
2
2
|
[key in keyof T]: C;
|
|
3
3
|
};
|
|
4
|
-
|
|
4
|
+
type ProductsObject<T, F> = {
|
|
5
5
|
[key in keyof T]: F;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
export
|
|
7
|
+
type Factory<C> = (config: C, key: string) => any;
|
|
8
|
+
export type CreateFactory<C, F> = <T>(apis: OptionsObject<T, C>) => ProductsObject<T, F>;
|
|
9
|
+
export type SuperFactory = <C, F>(factory: Factory<C>) => CreateFactory<C, F>;
|
|
10
10
|
export declare const superFactory: SuperFactory;
|
|
11
11
|
export {};
|
package/es/factory/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __values = this && this.__values || function (o) {
|
|
2
2
|
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
m = s && o[s],
|
|
4
|
+
i = 0;
|
|
5
5
|
if (m) return m.call(o);
|
|
6
6
|
if (o && typeof o.length === "number") return {
|
|
7
7
|
next: function next() {
|
|
@@ -14,13 +14,10 @@ var __values = this && this.__values || function (o) {
|
|
|
14
14
|
};
|
|
15
15
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
16
16
|
};
|
|
17
|
-
|
|
18
17
|
export var superFactory = function superFactory(factory) {
|
|
19
18
|
return function (options) {
|
|
20
19
|
var e_1, _a;
|
|
21
|
-
|
|
22
20
|
var product = {};
|
|
23
|
-
|
|
24
21
|
try {
|
|
25
22
|
for (var _b = __values(Object.keys(options)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
26
23
|
var key = _c.value;
|
|
@@ -37,7 +34,6 @@ export var superFactory = function superFactory(factory) {
|
|
|
37
34
|
if (e_1) throw e_1.error;
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
return product;
|
|
42
38
|
};
|
|
43
39
|
};
|
package/es/index.d.ts
CHANGED
|
@@ -14,3 +14,4 @@ export { WatchDog } from './watch-dog';
|
|
|
14
14
|
export { Level } from './level';
|
|
15
15
|
export { callbackToPromise } from './promise';
|
|
16
16
|
export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints } from './math/geometry';
|
|
17
|
+
export { RegExpList } from './regexp-list';
|
package/es/index.js
CHANGED
|
@@ -14,4 +14,5 @@ export { HistoryStack } from './stack';
|
|
|
14
14
|
export { WatchDog } from './watch-dog';
|
|
15
15
|
export { Level } from './level';
|
|
16
16
|
export { callbackToPromise } from './promise';
|
|
17
|
-
export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints } from './math/geometry';
|
|
17
|
+
export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints } from './math/geometry';
|
|
18
|
+
export { RegExpList } from './regexp-list';
|
package/es/level/index.js
CHANGED
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
var Level =
|
|
2
|
-
/** @class */
|
|
3
|
-
function () {
|
|
1
|
+
var Level = /** @class */function () {
|
|
4
2
|
function Level(props) {
|
|
5
3
|
this.config = props;
|
|
6
4
|
this.step = (this.config.max - this.config.min) / (this.config.count - 2);
|
|
7
5
|
}
|
|
8
|
-
|
|
9
6
|
Level.prototype.get = function (value) {
|
|
10
7
|
if (value <= this.config.min) {
|
|
11
8
|
return 1;
|
|
12
9
|
}
|
|
13
|
-
|
|
14
10
|
if (value >= this.config.max) {
|
|
15
11
|
return this.config.count;
|
|
16
12
|
}
|
|
17
|
-
|
|
18
13
|
for (var i = 2, v = this.config.min + this.step; v < this.config.max + this.step; v += this.step, i += 1) {
|
|
19
14
|
if (value < v) {
|
|
20
15
|
return i;
|
|
21
16
|
}
|
|
22
17
|
}
|
|
23
|
-
|
|
24
18
|
return this.config.count;
|
|
25
19
|
};
|
|
26
|
-
|
|
27
20
|
return Level;
|
|
28
21
|
}();
|
|
29
|
-
|
|
30
22
|
export { Level };
|
package/es/loop/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const loop: (cb: (stop: () => void) => Promise<void>, time: number) => () => void;
|
|
2
|
-
|
|
2
|
+
type WaitForBool = () => boolean | Promise<boolean>;
|
|
3
3
|
export declare const waitFor: (bool: WaitForBool, { checkTime, timeout }?: {
|
|
4
4
|
checkTime?: number | undefined;
|
|
5
5
|
timeout?: number | undefined;
|