pubo-utils 1.0.7 → 1.0.12
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.d.ts +8 -0
- package/es/base64/index.js +43 -0
- package/es/color/utils.d.ts +1 -0
- package/es/color/utils.js +7 -0
- package/es/debounce/index.d.ts +1 -0
- package/es/debounce/index.js +82 -0
- package/es/emitter/index.d.ts +4 -2
- package/es/emitter/index.js +9 -0
- package/es/index.d.ts +4 -1
- package/es/index.js +4 -1
- package/lib/base64/index.d.ts +8 -0
- package/lib/base64/index.js +53 -0
- package/lib/color/utils.d.ts +1 -0
- package/lib/color/utils.js +14 -0
- package/lib/debounce/index.d.ts +1 -0
- package/lib/debounce/index.js +89 -0
- package/lib/emitter/index.d.ts +4 -2
- package/lib/emitter/index.js +9 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.js +58 -2
- 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,"random",(function(){return r})),e.d(n,"WatchDog",(function(){return k})),e.d(n,"superFactory",(function(){return s})),e.d(n,"Emitter",(function(){return l})),e.d(n,"SyncQueue",(function(){return g})),e.d(n,"sleep",(function(){return y})),e.d(n,"ContinuousTrigger",(function(){return j})),e.d(n,"throttle",(function(){return T})),e.d(n,"loop",(function(){return v}));var r=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=8;r<=t;r+=8)e+=n(t-r>8?8:t-r);return e},o=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())}))},i=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])}}},u=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.")},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},a=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(c(arguments[n]));return t},l=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,o=r(40);return this.ids[o]={event:t,index:e},o},t.prototype.cancel=function(t){var n=this.ids[t]||{},e=n.event,r=n.index;e&&Array.isArray(this.state[e])&&this.state[e].splice(r,1)},t.prototype.emit=function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return o(this,void 0,void 0,(function(){var e,r,o,c,l,f;return i(this,(function(i){switch(i.label){case 0:if(!Array.isArray(this.state[t]))return[3,8];i.label=1;case 1:i.trys.push([1,6,7,8]),e=u(this.state[t]),r=e.next(),i.label=2;case 2:return r.done?[3,5]:"function"!=typeof(o=r.value)?[3,4]:[4,o.apply(void 0,a(n))];case 3:i.sent(),i.label=4;case 4:return r=e.next(),[3,2];case 5:return[3,8];case 6:return c=i.sent(),l={error:c},[3,8];case 7:try{r&&!r.done&&(f=e.return)&&f.call(e)}finally{if(l)throw l.error}return[7];case 8:return[2]}}))}))},t}(),f=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){return function(n){var e,r,o={};try{for(var i=f(Object.keys(n)),u=i.next();!u.done;u=i.next()){var c=u.value;o[c]=t(n[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}},p=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())}))},h=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])}}},y=function(t){return p(void 0,void 0,void 0,(function(){return h(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]}}))}))},b=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())}))},d=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])}}},v=function(t,n){var e=!0,r=function(){e=!1};return function o(){return b(void 0,void 0,void 0,(function(){return d(this,(function(i){switch(i.label){case 0:return[4,t(r)];case 1:return i.sent(),[4,y(n)];case 2:return i.sent(),e&&o(),[2]}}))}))}(),r},m=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])}}},g=function(){function t(){this.cache=[],this.running=!1}return t.prototype._run=function(t){var n=t.fn,e=t.promise;return m(this,void 0,void 0,(function(){var t,r;return w(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 m(this,void 0,void 0,(function(){var t;return w(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}(),x=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},S=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(x(arguments[n]));return t};function T(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,S(o)))}}var j=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}(),k=function(){function t(t){var n=t.limit,e=void 0===n?1:n,r=t.onTimeout;this.count=0,this.i=null,this.limit=e,this.onTimeout=r}return t.prototype.onTimeout=function(){console.log("timeout!")},t.prototype.onTimer=function(){this.count>this.limit&&"function"==typeof this.onTimeout?(this.onTimeout(),this.count=0):this.count++},t.prototype.init=function(){var t=this;this.i=setInterval((function(){return t.onTimer()}),1e3)},t.prototype.feed=function(){this.count=0},t.prototype.stop=function(){this.i&&(clearInterval(this.i),this.count=0)},t}()}])}));
|
|
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,"random",(function(){return a})),e.d(n,"WatchDog",(function(){return A})),e.d(n,"superFactory",(function(){return d})),e.d(n,"Emitter",(function(){return y})),e.d(n,"SyncQueue",(function(){return k})),e.d(n,"sleep",(function(){return w})),e.d(n,"ContinuousTrigger",(function(){return E})),e.d(n,"throttle",(function(){return O})),e.d(n,"loop",(function(){return S})),e.d(n,"hex2rgb",(function(){return c})),e.d(n,"debounce",(function(){return u})),e.d(n,"Base64Utils",(function(){return r}));var r={};e.r(r),e.d(r,"EncoderMap",(function(){return M})),e.d(r,"toUnit8Array",(function(){return I}));var o=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},i=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(o(arguments[n]));return t},u=function(t,n,e){if(void 0===e&&(e=!0),e){var r,o=!0;return function(){for(var e=[],u=0;u<arguments.length;u++)e[u]=arguments[u];o&&(t.apply(void 0,i(e)),o=!1),r&&clearTimeout(r),r=setTimeout((function(){return o=!0}),n)}}var u;return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];u&&clearTimeout(u),u=setTimeout((function(){return t.apply(void 0,i(e))}),n)}},c=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)]},a=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=8;r<=t;r+=8)e+=n(t-r>8?8:t-r);return e},l=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())}))},f=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])}}},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.")},p=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},h=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(p(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 e=this.state[t].push(n)-1,r=a(40);return this.ids[r]={event:t,index:e},r},t.prototype.cancel=function(t){if(t){var n=this.ids[t]||{},e=n.event,r=n.index;e&&Array.isArray(this.state[e])&&this.state[e].splice(r,1)}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return l(this,void 0,void 0,(function(){var e,r,o,i,u,c;return f(this,(function(a){switch(a.label){case 0:if(!Array.isArray(this.state[t]))return[3,8];a.label=1;case 1:a.trys.push([1,6,7,8]),e=s(this.state[t]),r=e.next(),a.label=2;case 2:return r.done?[3,5]:"function"!=typeof(o=r.value)?[3,4]:[4,o.apply(void 0,h(n))];case 3:a.sent(),a.label=4;case 4:return r=e.next(),[3,2];case 5:return[3,8];case 6:return i=a.sent(),u={error:i},[3,8];case 7:try{r&&!r.done&&(c=e.return)&&c.call(e)}finally{if(u)throw u.error}return[7];case 8:return[2]}}))}))},t}(),v=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},d=function(t){return function(n){var e,r,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])}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o}},b=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())}))},m=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])}}},w=function(t){return b(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]}}))}))},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())}))},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(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])}}},S=function(t,n){var e=!0,r=function(){e=!1};return function o(){return g(void 0,void 0,void 0,(function(){return x(this,(function(i){switch(i.label){case 0:return[4,t(r)];case 1:return i.sent(),[4,w(n)];case 2:return i.sent(),e&&o(),[2]}}))}))}(),r},T=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())}))},j=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next: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])}}},k=function(){function t(){this.cache=[],this.running=!1}return t.prototype._run=function(t){var n=t.fn,e=t.promise;return T(this,void 0,void 0,(function(){var t,r;return j(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,n()];case 1:return t=o.sent(),e.resolve(t),[3,3];case 2:return r=o.sent(),e.reject(r),[3,3];case 3:return[2]}}))}))},t.prototype.run=function(){return 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(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}(),P=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},_=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(P(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,_(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}(),A=function(){function t(t){var n=t.limit,e=void 0===n?1:n,r=t.onTimeout;this.count=0,this.i=null,this.limit=e,this.onTimeout=r}return t.prototype.onTimeout=function(){console.log("timeout!")},t.prototype.onTimer=function(){this.count>this.limit&&"function"==typeof this.onTimeout?(this.onTimeout(),this.count=0):this.count++},t.prototype.init=function(){var t=this;this.i=setInterval((function(){return t.onTimer()}),1e3)},t.prototype.feed=function(){this.count=0},t.prototype.stop=function(){this.i&&(clearInterval(this.i),this.count=0)},t}(),M=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function I(t,n){for(var e=0,r=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(r=(r<<6)+M[t.charAt(i)],(e+=6)>=8){var u=r>>>(e-=8);n[o++]=255&u,r-=u<<=e}}}])}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const EncoderMap: {};
|
|
2
|
+
/**
|
|
3
|
+
* base64 转Uint8Array
|
|
4
|
+
* @param input base64 字符串
|
|
5
|
+
* @param output Uint8Array
|
|
6
|
+
* base64 6位的二进制, Uint8Array 8位的二进制,整体原理就是将 base64 的每个字符转成2进制然后拼接,再按每个八位为一个单位地取出
|
|
7
|
+
*/
|
|
8
|
+
export declare function toUnit8Array(input: any, output: any): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export var EncoderMap = function () {
|
|
2
|
+
var S = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
3
|
+
var e = {};
|
|
4
|
+
|
|
5
|
+
for (var i = 0; i < 64; i++) {
|
|
6
|
+
e[S.charAt(i)] = i;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return e;
|
|
10
|
+
}();
|
|
11
|
+
/**
|
|
12
|
+
* base64 转Uint8Array
|
|
13
|
+
* @param input base64 字符串
|
|
14
|
+
* @param output Uint8Array
|
|
15
|
+
* base64 6位的二进制, Uint8Array 8位的二进制,整体原理就是将 base64 的每个字符转成2进制然后拼接,再按每个八位为一个单位地取出
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export function toUnit8Array(input, output) {
|
|
19
|
+
// 当前二进制字符长度
|
|
20
|
+
var l = 0; // 二进制字符缓存值(格式为10进制)
|
|
21
|
+
|
|
22
|
+
var b = 0; // Uint8Array 的指针
|
|
23
|
+
|
|
24
|
+
var j = 0;
|
|
25
|
+
|
|
26
|
+
for (var x = 0; x < input.length && j < output.length; x += 1) {
|
|
27
|
+
b = (b << 6) + EncoderMap[input.charAt(x)]; // 为什么是6? base64 为64个字符,也就是 2^6,用二进制表示就是6位
|
|
28
|
+
|
|
29
|
+
l += 6; // 为什么是8? Uint8Array 是八位的二进制
|
|
30
|
+
|
|
31
|
+
if (l >= 8) {
|
|
32
|
+
// 取了前八位后剩余长度
|
|
33
|
+
l -= 8; // 前八位的值
|
|
34
|
+
|
|
35
|
+
var c = b >>> l;
|
|
36
|
+
output[j++] = c & 0xff; // 再将右移的值左移回来,除了前八位不变,后面的皆为0
|
|
37
|
+
|
|
38
|
+
c = c << l; // 通过减法得到第八位之后的值
|
|
39
|
+
|
|
40
|
+
b = b - c;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hex2rgb: (n: any) => number[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const debounce: (cb: any, time: number, first?: boolean) => (...args: any[]) => void;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __read = this && this.__read || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o),
|
|
5
|
+
r,
|
|
6
|
+
ar = [],
|
|
7
|
+
e;
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
11
|
+
ar.push(r.value);
|
|
12
|
+
}
|
|
13
|
+
} catch (error) {
|
|
14
|
+
e = {
|
|
15
|
+
error: error
|
|
16
|
+
};
|
|
17
|
+
} finally {
|
|
18
|
+
try {
|
|
19
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
20
|
+
} finally {
|
|
21
|
+
if (e) throw e.error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
var __spread = this && this.__spread || function () {
|
|
29
|
+
for (var ar = [], i = 0; i < arguments.length; i++) {
|
|
30
|
+
ar = ar.concat(__read(arguments[i]));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export var debounce = function debounce(cb, time, first) {
|
|
37
|
+
if (first === void 0) {
|
|
38
|
+
first = true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (first) {
|
|
42
|
+
var shouldRun_1 = true;
|
|
43
|
+
var t_1;
|
|
44
|
+
return function () {
|
|
45
|
+
var args = [];
|
|
46
|
+
|
|
47
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
48
|
+
args[_i] = arguments[_i];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (shouldRun_1) {
|
|
52
|
+
cb.apply(void 0, __spread(args));
|
|
53
|
+
shouldRun_1 = false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (t_1) {
|
|
57
|
+
clearTimeout(t_1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
t_1 = setTimeout(function () {
|
|
61
|
+
return shouldRun_1 = true;
|
|
62
|
+
}, time);
|
|
63
|
+
};
|
|
64
|
+
} else {
|
|
65
|
+
var t_2;
|
|
66
|
+
return function () {
|
|
67
|
+
var args = [];
|
|
68
|
+
|
|
69
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
70
|
+
args[_i] = arguments[_i];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (t_2) {
|
|
74
|
+
clearTimeout(t_2);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
t_2 = setTimeout(function () {
|
|
78
|
+
return cb.apply(void 0, __spread(args));
|
|
79
|
+
}, time);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
};
|
package/es/emitter/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
interface EmitterType {
|
|
2
2
|
on: (event: string, func: any) => string;
|
|
3
|
-
cancel: (id
|
|
3
|
+
cancel: (id?: string) => void;
|
|
4
4
|
emit: (event: string, ...args: any) => any;
|
|
5
|
+
clear: () => void;
|
|
5
6
|
}
|
|
6
7
|
export declare class Emitter implements EmitterType {
|
|
7
8
|
private readonly state;
|
|
8
9
|
private readonly ids;
|
|
9
10
|
on(event: string, func: any): string;
|
|
10
|
-
cancel(id
|
|
11
|
+
cancel(id?: string): void;
|
|
12
|
+
clear(): void;
|
|
11
13
|
emit(event: string, ...args: any): Promise<void>;
|
|
12
14
|
}
|
|
13
15
|
export {};
|
package/es/emitter/index.js
CHANGED
|
@@ -222,6 +222,11 @@ function () {
|
|
|
222
222
|
};
|
|
223
223
|
|
|
224
224
|
Emitter.prototype.cancel = function (id) {
|
|
225
|
+
if (!id) {
|
|
226
|
+
this.clear();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
225
230
|
var _a = this.ids[id] || {},
|
|
226
231
|
event = _a.event,
|
|
227
232
|
index = _a.index;
|
|
@@ -237,6 +242,10 @@ function () {
|
|
|
237
242
|
this.state[event].splice(index, 1);
|
|
238
243
|
};
|
|
239
244
|
|
|
245
|
+
Emitter.prototype.clear = function () {
|
|
246
|
+
this.state.length = 0;
|
|
247
|
+
};
|
|
248
|
+
|
|
240
249
|
Emitter.prototype.emit = function (event) {
|
|
241
250
|
var args = [];
|
|
242
251
|
|
package/es/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { debounce } from './debounce';
|
|
2
|
+
import { hex2rgb } from './color/utils';
|
|
1
3
|
import { Emitter } from './emitter';
|
|
2
4
|
import { superFactory } from './factory';
|
|
3
5
|
import { loop } from './loop';
|
|
@@ -7,4 +9,5 @@ import { sleep } from './sleep';
|
|
|
7
9
|
import { throttle } from './throttle';
|
|
8
10
|
import { ContinuousTrigger } from './trigger';
|
|
9
11
|
import { WatchDog } from './watch-dog';
|
|
10
|
-
|
|
12
|
+
import * as Base64Utils from './base64';
|
|
13
|
+
export { random, WatchDog, superFactory, Emitter, SyncQueue, sleep, ContinuousTrigger, throttle, loop, hex2rgb, debounce, Base64Utils, };
|
package/es/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { debounce } from './debounce';
|
|
2
|
+
import { hex2rgb } from './color/utils';
|
|
1
3
|
import { Emitter } from './emitter';
|
|
2
4
|
import { superFactory } from './factory';
|
|
3
5
|
import { loop } from './loop';
|
|
@@ -7,4 +9,5 @@ import { sleep } from './sleep';
|
|
|
7
9
|
import { throttle } from './throttle';
|
|
8
10
|
import { ContinuousTrigger } from './trigger';
|
|
9
11
|
import { WatchDog } from './watch-dog';
|
|
10
|
-
|
|
12
|
+
import * as Base64Utils from './base64';
|
|
13
|
+
export { random, WatchDog, superFactory, Emitter, SyncQueue, sleep, ContinuousTrigger, throttle, loop, hex2rgb, debounce, Base64Utils };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const EncoderMap: {};
|
|
2
|
+
/**
|
|
3
|
+
* base64 转Uint8Array
|
|
4
|
+
* @param input base64 字符串
|
|
5
|
+
* @param output Uint8Array
|
|
6
|
+
* base64 6位的二进制, Uint8Array 8位的二进制,整体原理就是将 base64 的每个字符转成2进制然后拼接,再按每个八位为一个单位地取出
|
|
7
|
+
*/
|
|
8
|
+
export declare function toUnit8Array(input: any, output: any): void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toUnit8Array = exports.EncoderMap = void 0;
|
|
7
|
+
|
|
8
|
+
exports.EncoderMap = function () {
|
|
9
|
+
var S = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
10
|
+
var e = {};
|
|
11
|
+
|
|
12
|
+
for (var i = 0; i < 64; i++) {
|
|
13
|
+
e[S.charAt(i)] = i;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return e;
|
|
17
|
+
}();
|
|
18
|
+
/**
|
|
19
|
+
* base64 转Uint8Array
|
|
20
|
+
* @param input base64 字符串
|
|
21
|
+
* @param output Uint8Array
|
|
22
|
+
* base64 6位的二进制, Uint8Array 8位的二进制,整体原理就是将 base64 的每个字符转成2进制然后拼接,再按每个八位为一个单位地取出
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function toUnit8Array(input, output) {
|
|
27
|
+
// 当前二进制字符长度
|
|
28
|
+
var l = 0; // 二进制字符缓存值(格式为10进制)
|
|
29
|
+
|
|
30
|
+
var b = 0; // Uint8Array 的指针
|
|
31
|
+
|
|
32
|
+
var j = 0;
|
|
33
|
+
|
|
34
|
+
for (var x = 0; x < input.length && j < output.length; x += 1) {
|
|
35
|
+
b = (b << 6) + exports.EncoderMap[input.charAt(x)]; // 为什么是6? base64 为64个字符,也就是 2^6,用二进制表示就是6位
|
|
36
|
+
|
|
37
|
+
l += 6; // 为什么是8? Uint8Array 是八位的二进制
|
|
38
|
+
|
|
39
|
+
if (l >= 8) {
|
|
40
|
+
// 取了前八位后剩余长度
|
|
41
|
+
l -= 8; // 前八位的值
|
|
42
|
+
|
|
43
|
+
var c = b >>> l;
|
|
44
|
+
output[j++] = c & 0xff; // 再将右移的值左移回来,除了前八位不变,后面的皆为0
|
|
45
|
+
|
|
46
|
+
c = c << l; // 通过减法得到第八位之后的值
|
|
47
|
+
|
|
48
|
+
b = b - c;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
exports.toUnit8Array = toUnit8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hex2rgb: (n: any) => number[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hex2rgb = void 0;
|
|
7
|
+
|
|
8
|
+
exports.hex2rgb = function (n) {
|
|
9
|
+
var str = n.toString(2).padStart(24, 0);
|
|
10
|
+
var r = parseInt(str.slice(0, 8), 2);
|
|
11
|
+
var g = parseInt(str.slice(8, 16), 2);
|
|
12
|
+
var b = parseInt(str.slice(16, 24), 2);
|
|
13
|
+
return [r, g, b];
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const debounce: (cb: any, time: number, first?: boolean) => (...args: any[]) => void;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __read = this && this.__read || function (o, n) {
|
|
4
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
5
|
+
if (!m) return o;
|
|
6
|
+
var i = m.call(o),
|
|
7
|
+
r,
|
|
8
|
+
ar = [],
|
|
9
|
+
e;
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
13
|
+
ar.push(r.value);
|
|
14
|
+
}
|
|
15
|
+
} catch (error) {
|
|
16
|
+
e = {
|
|
17
|
+
error: error
|
|
18
|
+
};
|
|
19
|
+
} finally {
|
|
20
|
+
try {
|
|
21
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
22
|
+
} finally {
|
|
23
|
+
if (e) throw e.error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var __spread = this && this.__spread || function () {
|
|
31
|
+
for (var ar = [], i = 0; i < arguments.length; i++) {
|
|
32
|
+
ar = ar.concat(__read(arguments[i]));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
Object.defineProperty(exports, "__esModule", {
|
|
39
|
+
value: true
|
|
40
|
+
});
|
|
41
|
+
exports.debounce = void 0;
|
|
42
|
+
|
|
43
|
+
exports.debounce = function (cb, time, first) {
|
|
44
|
+
if (first === void 0) {
|
|
45
|
+
first = true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (first) {
|
|
49
|
+
var shouldRun_1 = true;
|
|
50
|
+
var t_1;
|
|
51
|
+
return function () {
|
|
52
|
+
var args = [];
|
|
53
|
+
|
|
54
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
55
|
+
args[_i] = arguments[_i];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (shouldRun_1) {
|
|
59
|
+
cb.apply(void 0, __spread(args));
|
|
60
|
+
shouldRun_1 = false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (t_1) {
|
|
64
|
+
clearTimeout(t_1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
t_1 = setTimeout(function () {
|
|
68
|
+
return shouldRun_1 = true;
|
|
69
|
+
}, time);
|
|
70
|
+
};
|
|
71
|
+
} else {
|
|
72
|
+
var t_2;
|
|
73
|
+
return function () {
|
|
74
|
+
var args = [];
|
|
75
|
+
|
|
76
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
77
|
+
args[_i] = arguments[_i];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (t_2) {
|
|
81
|
+
clearTimeout(t_2);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
t_2 = setTimeout(function () {
|
|
85
|
+
return cb.apply(void 0, __spread(args));
|
|
86
|
+
}, time);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
package/lib/emitter/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
interface EmitterType {
|
|
2
2
|
on: (event: string, func: any) => string;
|
|
3
|
-
cancel: (id
|
|
3
|
+
cancel: (id?: string) => void;
|
|
4
4
|
emit: (event: string, ...args: any) => any;
|
|
5
|
+
clear: () => void;
|
|
5
6
|
}
|
|
6
7
|
export declare class Emitter implements EmitterType {
|
|
7
8
|
private readonly state;
|
|
8
9
|
private readonly ids;
|
|
9
10
|
on(event: string, func: any): string;
|
|
10
|
-
cancel(id
|
|
11
|
+
cancel(id?: string): void;
|
|
12
|
+
clear(): void;
|
|
11
13
|
emit(event: string, ...args: any): Promise<void>;
|
|
12
14
|
}
|
|
13
15
|
export {};
|
package/lib/emitter/index.js
CHANGED
|
@@ -229,6 +229,11 @@ function () {
|
|
|
229
229
|
};
|
|
230
230
|
|
|
231
231
|
Emitter.prototype.cancel = function (id) {
|
|
232
|
+
if (!id) {
|
|
233
|
+
this.clear();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
232
237
|
var _a = this.ids[id] || {},
|
|
233
238
|
event = _a.event,
|
|
234
239
|
index = _a.index;
|
|
@@ -244,6 +249,10 @@ function () {
|
|
|
244
249
|
this.state[event].splice(index, 1);
|
|
245
250
|
};
|
|
246
251
|
|
|
252
|
+
Emitter.prototype.clear = function () {
|
|
253
|
+
this.state.length = 0;
|
|
254
|
+
};
|
|
255
|
+
|
|
247
256
|
Emitter.prototype.emit = function (event) {
|
|
248
257
|
var args = [];
|
|
249
258
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { debounce } from './debounce';
|
|
2
|
+
import { hex2rgb } from './color/utils';
|
|
1
3
|
import { Emitter } from './emitter';
|
|
2
4
|
import { superFactory } from './factory';
|
|
3
5
|
import { loop } from './loop';
|
|
@@ -7,4 +9,5 @@ import { sleep } from './sleep';
|
|
|
7
9
|
import { throttle } from './throttle';
|
|
8
10
|
import { ContinuousTrigger } from './trigger';
|
|
9
11
|
import { WatchDog } from './watch-dog';
|
|
10
|
-
|
|
12
|
+
import * as Base64Utils from './base64';
|
|
13
|
+
export { random, WatchDog, superFactory, Emitter, SyncQueue, sleep, ContinuousTrigger, throttle, loop, hex2rgb, debounce, Base64Utils, };
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
Object.defineProperty(o, k2, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function get() {
|
|
8
|
+
return m[k];
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
} : function (o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
value: v
|
|
20
|
+
});
|
|
21
|
+
} : function (o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
var __importStar = this && this.__importStar || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) {
|
|
29
|
+
if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
|
|
3
37
|
Object.defineProperty(exports, "__esModule", {
|
|
4
38
|
value: true
|
|
5
39
|
});
|
|
6
|
-
exports.loop = exports.throttle = exports.ContinuousTrigger = exports.sleep = exports.SyncQueue = exports.Emitter = exports.superFactory = exports.WatchDog = exports.random = void 0;
|
|
40
|
+
exports.Base64Utils = exports.debounce = exports.hex2rgb = exports.loop = exports.throttle = exports.ContinuousTrigger = exports.sleep = exports.SyncQueue = exports.Emitter = exports.superFactory = exports.WatchDog = exports.random = void 0;
|
|
41
|
+
|
|
42
|
+
var debounce_1 = require("./debounce");
|
|
43
|
+
|
|
44
|
+
Object.defineProperty(exports, "debounce", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function get() {
|
|
47
|
+
return debounce_1.debounce;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
var utils_1 = require("./color/utils");
|
|
52
|
+
|
|
53
|
+
Object.defineProperty(exports, "hex2rgb", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function get() {
|
|
56
|
+
return utils_1.hex2rgb;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
7
59
|
|
|
8
60
|
var emitter_1 = require("./emitter");
|
|
9
61
|
|
|
@@ -84,4 +136,8 @@ Object.defineProperty(exports, "WatchDog", {
|
|
|
84
136
|
get: function get() {
|
|
85
137
|
return watch_dog_1.WatchDog;
|
|
86
138
|
}
|
|
87
|
-
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
var Base64Utils = __importStar(require("./base64"));
|
|
142
|
+
|
|
143
|
+
exports.Base64Utils = Base64Utils;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
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": "0eb9335b77c244b2a95c6978d9a15b7b1945b7ff"
|
|
22
22
|
}
|