utils-lib-js 1.7.22 → 2.0.0

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/README.en.md CHANGED
@@ -213,7 +213,9 @@ export type IDefer = (timer: number) => IPromise
213
213
  * @param {Promise<any>} defer the delay function
214
214
  * @returns {Promise<any>} [error, result]
215
215
  * /
216
+
216
217
  export type ICatchAwait<T extends Promise<any>> = (defer: T) => T
218
+
217
219
  ##### array
218
220
 
219
221
  /** The array is out of order
@@ -235,6 +237,7 @@ export type IArrayUniq<T extends any[]> = (arr: T) => T
235
237
  * @returns {Array<any>} A flat array
236
238
  * /
237
239
 
240
+
238
241
  export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result? : T) => T
239
242
 
240
243
  ##### element
@@ -326,8 +329,8 @@ timer? : number
326
329
  }
327
330
  export type ILogLoop = (opts? : ILogLoopParams) => ILogLoopParams | void
328
331
 
329
- ##### request
330
-
332
+ ##### request module
333
+ ###### https://gitee.com/DieHunter/js-request
331
334
  export type IRequestParams<T> = T | IObject<any> | null
332
335
 
333
336
  // Request path
@@ -419,8 +422,11 @@ OPTIONS: IRequestFn
419
422
  HEAD: IRequestFn
420
423
  PATCH: IRequestFn
421
424
  } & IRequestBase
425
+
426
+
422
427
  <! -- News Center -->
423
- // Message Center
428
+ ##### News Center
429
+ ###### https://gitee.com/DieHunter/message-center
424
430
  export declare interface Handlers {
425
431
  [key: string]: Array<Function>
426
432
  }
@@ -438,10 +444,10 @@ watch: (type: string, handler: Function) => this
438
444
  invoke: (type: string, data? : any) => Promise<void>
439
445
  }
440
446
 
441
- https://gitee.com/DieHunter/message-center
442
447
 
443
448
  <! -- Task Queue -->
444
-
449
+ ##### Task queue
450
+ ###### https://gitee.com/DieHunter/task-queue
445
451
  / * *
446
452
  * Single queue
447
453
  * defer: asynchronous function to be run
@@ -499,7 +505,7 @@ run: (reject: any) => unknown
499
505
  clear: () => void
500
506
  }
501
507
 
502
- https://gitee.com/DieHunter/task-queue
508
+
503
509
 
504
510
  /** Single line output
505
511
  * @param {string} str Output character
package/README.md CHANGED
@@ -328,8 +328,8 @@ export type ILogLoopParams = {
328
328
  }
329
329
  export type ILogLoop = (opts?: ILogLoopParams) => ILogLoopParams | void
330
330
 
331
- ##### request
332
-
331
+ ##### request 模块
332
+ ###### https://gitee.com/DieHunter/js-request
333
333
  export type IRequestParams<T> = T | IObject<any> | null
334
334
 
335
335
  // 请求路径
@@ -424,7 +424,8 @@ export type IRequest = {
424
424
 
425
425
 
426
426
  <!-- 消息中心 -->
427
- // 消息中心
427
+ ##### 消息中心
428
+ ###### https://gitee.com/DieHunter/message-center
428
429
  export declare interface Handlers {
429
430
  [key: string]: Array<Function>
430
431
  }
@@ -442,10 +443,11 @@ export declare interface IMessageCenter {
442
443
  invoke: (type: string, data?: any) => Promise<void>
443
444
  }
444
445
 
445
- https://gitee.com/DieHunter/message-center
446
446
 
447
- <!-- 任务队列 -->
448
447
 
448
+ <!-- 任务队列 -->
449
+ ##### 任务队列
450
+ ###### https://gitee.com/DieHunter/task-queue
449
451
  /**
450
452
  * 单条队列
451
453
  * defer: 待运行的异步函数
@@ -503,7 +505,7 @@ export type ITaskQueue = {
503
505
  clear: () => void
504
506
  }
505
507
 
506
- https://gitee.com/DieHunter/task-queue
508
+
507
509
 
508
510
  /** 单行输出
509
511
  * @param {string} str 输出字符
@@ -5,7 +5,6 @@ export * from "./function";
5
5
  export * from "./element";
6
6
  export * from "./static";
7
7
  export * from "./types";
8
- export * from "./request";
9
8
  export * from "./event";
10
9
  export * from "./storage";
11
10
  export * from "./log";
@@ -33,7 +32,6 @@ declare const _default: {
33
32
  stopDefault: import("./types").IStopDefault;
34
33
  removeHandler: import("./types").IRemoveHandler;
35
34
  dispatchEvent: import("./types").IDispatchEvent;
36
- Request: typeof import("./request").Request;
37
35
  types: typeof import("./static").types;
38
36
  createElement: import("./types").ICreateElement<HTMLElement>;
39
37
  throttle: import("./types").IThrottle;
@@ -1 +1 @@
1
- var UtilsLib=function(e){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)};function n(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r,o=function(){return o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},o.apply(this,arguments)};function i(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function u(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}e.types=void 0,(r=e.types||(e.types={}))["[object Array]"]="array",r["[object Object]"]="object",r["[object Function]"]="function",r["[object Set]"]="set",r["[object Map]"]="map",r["[object WeakMap]"]="weakMap",r["[object WeakSet]"]="weakSet",r["[object Date]"]="date",r["[object RegExp]"]="regExp",r["[object Math]"]="math";var a,c,s,l,f={types:e.types},p=function(e,t,n){return void 0===n&&(n=!1),Math.floor(Math.random()*(t-e+(n?1:0))+e)},d=function(e){var t={};return e.includes("?")?(e.split("?")[1].split("&").forEach((function(e){var n=e.split("=")[0];t[n]=e.split("=")[1]})),t):t},h=function(e,t){void 0===t&&(t={});var n=Object.keys(t);if(0===n.length)return e;var r=n.map((function(e){return"".concat(e,"=").concat(t[e])}));return"".concat(e).concat(e.includes("?")?"&":"?").concat(r.join("&"))},v=function(t){var n=typeof t;if(null===t)return"null";if("object"===n){var r=Object.prototype.toString.call(t);return e.types[r]}return n},y=function(e,t){void 0===t&&(t=[]);var n=v(e);return t.indexOf(n)>0},m={randomNum:p,urlSplit:d,urlJoin:h,getType:v,getTypeByList:y},g=function(e,t,n){void 0===n&&(n="");for(var r=0,o=t.split(".");r<o.length;r++){if(void 0===(e=e[o[r]]))return n}return e},b=function(e,t,n){void 0===n&&(n={});for(var r=t.split("."),o=r[r.length-1],i=e,u=0,a=r;u<a.length;u++){var c=a[u];if("object"!=typeof i&&void 0!==i)return e;!i&&(i={}),!i[c]&&(i[c]={}),o===c&&(i[o]=n),i=i[c]}return e},w=function(e,t,n){var r;for(var o in void 0===t&&(t={}),void 0===n&&(n=!1),t)for(var i in t[o]){var u=null!==(r=e.prototype)&&void 0!==r?r:e;(void 0===e[i]||n)&&(u[i]=t[o][i])}return e},j=function(e){for(var t in e){var n=e[t];"string"!=typeof n||e[n]||(e[n]=t)}return e},q=function(e,t){return"object"!=typeof e||"null"===t},O=function(e){var t=v(e);if(q(e,t))return e;var n=E(t,e);return"map"===t?e.forEach((function(e,t){n.set(t,O(e))})):"set"===t?e.forEach((function(e){n.add(O(e))})):Reflect.ownKeys(e).forEach((function(t){var r=e[t];n[t]=O(r)})),n},E=function(e,t){switch(void 0===t&&(t={}),e){case"array":return[];case"function":return t;case"set":return new Set;case"map":return new Map;case"date":return new Date(t);case"regExp":return new RegExp(t);case"math":return Math;default:return{}}},T=function(e){function t(){}return t.prototype=e,new t},S=function(e,t){return void 0===t&&(t=function(){}),t.prototype=T(e.prototype),t.prototype.super=e,t.prototype.constructor=t,t},P=function(e,t){void 0===t&&(t=!1);for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return e._instance&&!t||(e._instance=new(e.bind.apply(e,u([void 0],n,!1)))),e._instance},x=function(e){return function(t){for(var n in e)Reflect.has(t.prototype,n)||(t.prototype[n]=e[n])}},k=function(e){if("string"!==v(e))return null;try{return JSON.parse(e)}catch(e){return null}},H=function(e){if(!y(e,["array","object","set","map"]))return"";try{return JSON.stringify(e)}catch(e){return""}},A=function(e){return e&&e===e.window},D={getValue:g,setValue:b,mixIn:w,enumInversion:j,isNotObject:q,cloneDeep:O,createObjectVariable:E,createObject:T,inherit:S,getInstance:P,classDecorator:x,stringToJson:k,jsonToString:H,isWindow:A},C=function(e){return e.sort((function(){return Math.random()-.5}))},L=function(e){return Array.from(new Set(e))},M=function(e,t){return void 0===t&&(t=[]),e.forEach((function(e){return"array"===v(e)?M(e,t):t.push(e)})),t},F={arrayRandom:C,arrayUniq:L,arrayDemote:M},B=void 0,I=function(e,t){var n=null;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n||(n=setTimeout((function(){e.call.apply(e,u([B],r,!1)),n=null}),t))}},R=function(e,t){var n=null;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n&&(clearTimeout(n),n=null),n=setTimeout((function(){e.call.apply(e,u([B],r,!1))}),t)}},_=function(e){var t,n;return void 0===e&&(e=0),e>0&&setTimeout(n,e),{promise:new Promise((function(e,r){t=e,n=r})),resolve:t,reject:n}},N=function(e){return e.then((function(e){return[null,e]})).catch((function(e){return[e]}))},W={throttle:I,debounce:R,defer:_,catchAwait:N},J=function(e){var t,n,r=e.ele,o=e.style,i=e.attr,u=e.parent,a=r instanceof HTMLElement?r:document.createElement(null!=r?r:"div");return o&&(null===(t=Object.keys(o))||void 0===t||t.forEach((function(e){return a.style[e]=o[e]}))),i&&(null===(n=Object.keys(i))||void 0===n||n.forEach((function(e){return a[e]=i[e]}))),u&&u.appendChild(a),a},U={createElement:J};"undefined"!=typeof require?(l=require("abort-controller"),a=require("http").request,c=require("https").request,s=require("url").parse):l="undefined"!=typeof AbortController?AbortController:function(){throw new Error("AbortController is not defined")};var V=function(e){function t(t){var n=e.call(this)||this;return n.chackUrl=function(e){return e.startsWith("/")},n.checkIsHttps=function(e){return e.startsWith("https")},n.fixOrigin=function(e){return n.chackUrl(e)?n.origin+e:e},n.envDesc=function(){return"undefined"!=typeof Window?"Window":"Node"},n.errorFn=function(e){return function(t){var r,o;return e(null!==(o=null===(r=n.errFn)||void 0===r?void 0:r.call(n,t))&&void 0!==o?o:t)}},n.clearTimer=function(e){return!!e.timer&&(clearTimeout(e.timer),e.timer=null)},n.initAbort=function(e){var t=e.controller,n=e.timer,r=e.timeout;return!n&&(e.timer=setTimeout((function(){return t.abort()}),r)),e},n.requestType=function(){switch(n.envDesc()){case"Window":return n.fetch;case"Node":return n.http}},n.getDataByType=function(e,t){switch(e){case"text":case"json":case"blob":case"formData":case"arrayBuffer":return t[e]();default:return t.json()}},n.formatBodyString=function(e){return{text:function(){return e},json:function(){var t;return null!==(t=k(e))&&void 0!==t?t:e},blob:function(){return k(e)},formData:function(){return k(e)},arrayBuffer:function(){return k(e)}}},n.origin=null!=t?t:"",n}return n(t,e),t}(function(){function e(){}return e.prototype.use=function(e,t){switch(e){case"request":this.requestSuccess=t;break;case"response":this.responseSuccess=t;break;case"error":this.error=t}return this},Object.defineProperty(e.prototype,"reqFn",{get:function(){return this.requestSuccess},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"resFn",{get:function(){return this.responseSuccess},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"errFn",{get:function(){return this.error},enumerable:!1,configurable:!0}),e}()),z=function(e){function t(t){var n=e.call(this,t)||this;return n.initDefaultParams=function(e,t){var r,u,a=t.method,c=void 0===a?"GET":a,s=t.query,f=void 0===s?{}:s,p=t.headers,d=void 0===p?{}:p,v=t.body,y=void 0===v?null:v,m=t.timeout,g=void 0===m?3e4:m,b=t.controller,w=void 0===b?new l:b,j=t.type,q=void 0===j?"json":j,O=i(t,["method","query","headers","body","timeout","controller","type"]),E=o({url:e,method:c,query:f,headers:d,body:"GET"===c?null:H(y),timeout:g,signal:null==w?void 0:w.signal,controller:w,type:q,timer:null},O),T=null!==(u=null===(r=n.reqFn)||void 0===r?void 0:r.call(n,E))&&void 0!==u?u:E;return T.url=h(n.fixOrigin(e),E.query),T},n.initFetchParams=function(e,t){return n.initAbort(n.initDefaultParams(e,t))},n.initHttpParams=function(e,t){var r=n.initAbort(n.initDefaultParams(e,t)),i=s(r.url,!0);return o(o({},r),i)},n}return n(t,e),t}(V),G=function(e){function t(t){var n=e.call(this,t)||this;return n.fetch=function(e,t){var r=_(),o=r.promise,u=r.resolve,a=r.reject,c=n.initFetchParams(e,t),s=c.url,l=i(c,["url"]),f=l.signal;return o.finally((function(){return n.clearTimer(l)})),f.addEventListener("abort",(function(){return n.errorFn(a)})),fetch(s,l).then((function(e){return(null==e?void 0:e.status)>=200&&(null==e?void 0:e.status)<300?n.getDataByType(l.type,e):n.errorFn(a)})).then((function(e){var t,r;return u(null!==(r=null===(t=n.resFn)||void 0===t?void 0:t.call(n,e))&&void 0!==r?r:e)})).catch(n.errorFn(a)),o},n.http=function(e,t){var r=_(),o=r.promise,i=r.resolve,u=r.reject,s=n.initHttpParams(e,t),l=s.signal,f=s.url;o.finally((function(){return n.clearTimer(s)}));var p=(n.checkIsHttps(f)?c:a)(s,(function(e){var t=e.statusCode,r=e.statusMessage,o="";return e.setEncoding("utf8"),e.on("data",(function(e){return o+=e})),e.on("end",(function(){var e,a,c=n.getDataByType(s.type,n.formatBodyString(o));return t>=200&&t<300?i(null!==(a=null===(e=n.resFn)||void 0===e?void 0:e.call(n,c))&&void 0!==a?a:c):n.errorFn(u)({statusCode:t,statusMessage:r,result:c,data:o})}))}));return l.addEventListener("abort",(function(){return n.errorFn(u)(p.destroy(new Error("request timeout")))})),p.write(s.body),p.on("error",n.errorFn(u)),p.end(),o},n.GET=function(e,t,r,i){return n.request(e,o({query:t,method:"GET"},i))},n.POST=function(e,t,r,i){return n.request(e,o({query:t,method:"POST",body:r},i))},n.PUT=function(e,t,r,i){return n.request(e,o({query:t,method:"PUT",body:r},i))},n.DELETE=function(e,t,r,i){return n.request(e,o({query:t,method:"DELETE",body:r},i))},n.OPTIONS=function(e,t,r,i){return n.request(e,o({query:t,method:"OPTIONS",body:r},i))},n.HEAD=function(e,t,r,i){return n.request(e,o({query:t,method:"HEAD",body:r},i))},n.PATCH=function(e,t,r,i){return n.request(e,o({query:t,method:"PATCH",body:r},i))},n.request=n.requestType(),n}return n(t,e),t}(z),Q={Request:G},K=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e["on"+t]=n},$=function(e){(e=e||window.event).stopPropagation?e.stopPropagation():e.cancelBubble=!1},X=function(e){(e=e||window.event).preventDefault?e.preventDefault():e.returnValue=!1},Y=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e["on"+t]=null},Z=function(e,t){var n=new Event(t);e.dispatchEvent(n)},ee={addHandler:K,stopBubble:$,stopDefault:X,removeHandler:Y,dispatchEvent:Z},te=function(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(e){console.error(e)}},ne=function(e){try{var t=localStorage.getItem(e);return null==t?null:JSON.parse(t)}catch(e){return console.error(e),null}},re=function(e){try{e&&localStorage.removeItem(e),!e&&localStorage.clear()}catch(e){console.error(e)}},oe={setStorage:te,getStorage:ne,clearStorage:re},ie=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n=!0),t&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(e),n&&process.stdout.write("\n")},ue=function(e){return ie(e,!0,!1)},ae=["\\","|","/","—","—"],ce=function(e){var t;void 0===e&&(e={});var n=e.loopList,r=void 0===n?ae:n,o=e.isStop,i=void 0!==o&&o,u=e.timer,a=void 0===u?100:u,c=e.index,s=void 0===c?0:c,l=null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0;if(!l)return e;if(i)return ue("\n");s>=l-1&&(s=0);var f=r[s++];return ue(f),setTimeout((function(){e.index=s,ce(e)}),a),e},se={logOneLine:ie,logLoop:ce},le=function(){function e(e){this.fn=e,this.id=null,this.duration=1/0,this.isActive=!1}return e.prototype.start=function(e){this.isActive||(this.duration=null!=e?e:1/0,this.isActive=!0,this.animate())},e.prototype.stop=function(){this.isActive=!1,cancelAnimationFrame(this.id)},e.prototype.animate=function(e){void 0===e&&(e=0),this.isActive&&this.duration-- >0&&(this.fn(e),this.id=requestAnimationFrame(this.animate.bind(this)))},e}();function fe(e,t,n){var r=1-n,o=n*n;return[2*r*n*e+o,2*r*n*t+o]}function pe(e,t,n,r,o){var i=3*e,u=3*t,a=3*(n-e)-i,c=3*(r-t)-u,s=1-u-c;return[(1-i-a)*Math.pow(o,3)+a*Math.pow(o,2)+i*o,s*Math.pow(o,3)+c*Math.pow(o,2)+u*o]}function de(e){return 0===e||1===e?1:e*de(e-1)}function he(e,t){return de(e)/(de(t)*de(e-t))}function ve(e,t){for(var n=e.length-1,r=[0,0],o=0;o<=n;o++){var i=he(n,o)*Math.pow(1-t,n-o)*Math.pow(t,o);r[0]+=i*e[o][0],r[1]+=i*e[o][1]}return r}var ye={AnimateFrame:le,quadraticBezier:fe,cubicBezier:pe,factorial:de,combination:he,NBezier:ve},me=function(){function e(e){void 0===e&&(e={}),this.options=e,this.events={}}return e.prototype.on=function(e,t){return this.checkHandler(e,t),this.getHandler(e,[]).push(t),this},e.prototype.emit=function(e,t){return this.has(e)&&this.runHandler(e,t),this},e.prototype.un=function(e,t){return this.unHandler(e,t),this},e.prototype.once=function(e,t){var n=this;this.checkHandler(e,t);var r=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return n.un(e,r),t.apply(void 0,o)};return this.on(e,r),this},e.prototype.clear=function(){return this.events={},this},e.prototype.has=function(e){return!!this.getHandler(e)},e.prototype.getHandler=function(e,t){var n;return"object"==typeof t&&(this.events[e]=null!==(n=this.events[e])&&void 0!==n?n:t),this.events[e]},e.prototype.handlerLength=function(e){var t,n;return null!==(n=null===(t=this.getHandler(e))||void 0===t?void 0:t.length)&&void 0!==n?n:0},e.prototype.watch=function(e,t){var n=this;this.checkHandler(e,t);return this.on(e,(function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n.emit(n.prefixStr(e),t.apply(void 0,r))})),this},e.prototype.invoke=function(e,t){var n=this;return new Promise((function(r){n.once(n.prefixStr(e),r),n.emit(e,t)}))},e.prototype.runHandler=function(e,t){for(var n=0,r=this.getHandler(e);n<r.length;n++){var o=r[n];o&&o(t)}},e.prototype.unHandler=function(e,t){var n=this.getHandler(e);!t&&(this.events[e]=[]),t&&this.checkHandler(e,t);for(var r=0;r<n.length;r++)n&&n[r]===t&&(n[r]=null)},e.prototype.prefixStr=function(e){return"@".concat(e)},e.prototype.checkHandler=function(e,t){var n=this.options,r=n.blackList,o=void 0===r?[]:r,i=n.maxLen,u=void 0===i?1/0:i,a=this.handlerLength(e);if(0===(null==e?void 0:e.length))throw new Error("type.length can not be 0");if(!t||!e)throw new ReferenceError("type or handler is not defined");if("function"!=typeof t||"string"!=typeof e)throw new TypeError("".concat(t," is not a function or ").concat(e," is not a string"));if(o.includes(e))throw new Error("".concat(e," is not allow"));if(u<=a)throw new Error("the number of ".concat(e," must be less than ").concat(u))},e.Instance=function(e){return e._instance||Object.defineProperty(e,"_instance",{value:new e}),e._instance},e}(),ge=me.Instance(me),be=function(e){return e.prototype.messageCenter||(e.prototype.messageCenter=new me),e},we=function(){return we=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},we.apply(this,arguments)},je=function(e,t,n,r){var o,i=arguments.length,u=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(u=(i<3?o(u):i>3?o(t,n,u):o(t,n))||u);return i>3&&u&&Object.defineProperty(t,n,u),u},qe=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Oe=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,a)}c((r=r.apply(e,t||[])).next())}))},Ee=function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Te=function(){function e(e){var t=this;this.fix="@~&$",this.init=function(){t.messageCenter.on("push:handler",t.run),t.messageCenter.on("run:success:handler",t.run),t.messageCenter.on("run:success:handler",t.finish),t.messageCenter.on("run:error:handler",t.run),t.messageCenter.on("run:error:handler",t.finish)},this.defineProps=function(e,n){Object.defineProperty(t,n,{value:e})},this.push=function(e){var n;t.checkHandler(e);var r=(n=t.defer()).resolve,o=n.reject,i=n.promise,u=t.fixStr(e.name);return t.queues=t.queues.concat(e.children.map((function(e){return{defer:e,name:u}}))),t.queueTemp[u]=we(we({},e),{result:[]}),t.messageCenter.emit("push:handler",o),t.messageCenter.on(u,r),i},this.unshift=function(e){return t.queues.splice(0,e)},this.run=function(e){var n=e.reject;return Oe(t,void 0,void 0,(function(){var e,t,r,o,i;return Ee(this,(function(u){switch(u.label){case 0:if("pending"===this.stateProxy())return[2,void 0];if(0===this.queues.length)return[2,this.stateProxy("idle")];this.stateProxy("pending"),e=this.unshift(null!==(i=null===(o=this.props)||void 0===o?void 0:o.maxLen)&&void 0!==i?i:10),u.label=1;case 1:return u.trys.push([1,3,,4]),[4,Promise.all(e.map((function(e,t){return e.defer().catch((function(e){return e}))})))];case 2:return t=u.sent(),[2,this.handlerSuccess({res:t,queues:e})];case 3:return r=u.sent(),[2,this.handlerError({reject:n,error:r,queues:e})];case 4:return[2]}}))}))},this.clear=function(){t.queues=[],t.queueTemp={},t.props=null,t.stateProxy("idle"),t.messageCenter.clear()},this.finish=function(e){var n=e.res,r=void 0===n?[]:n,o=e.queues,i=e.error,u=void 0===i?"err":i,a=t.queueTemp;o.forEach((function(e,n){var o,i,c,s=a[e.name];null==s||s.result.push(null!==(o=r[n])&&void 0!==o?o:u),(null===(i=null==s?void 0:s.result)||void 0===i?void 0:i.length)===(null===(c=null==s?void 0:s.children)||void 0===c?void 0:c.length)&&(t.messageCenter.emit(e.name,null==s?void 0:s.result),a[e.name]=null)}))},this.handlerSuccess=function(e){return t.stateProxy("fulfilled"),t.messageCenter.emit("run:success:handler",e)},this.handlerError=function(e){var n=e.reject,r=e.error;return t.stateProxy("rejected"),n&&"function"==typeof n&&n(r),t.messageCenter.emit("run:error:handler",e)},this.stateProxy=function(e){return e&&(t.state=e),t.state},this.defer=function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),resolve:e,reject:t}},this.clear(),e&&this.defineProps(e,"props"),this.init()}return e.prototype.checkHandler=function(e){var t,n;if(!e)throw new ReferenceError("queue is not defined");if(!(e.children instanceof Array)||"object"!=typeof e)throw new TypeError("queue should be an object and queue.children should be an array");if(0===(null===(t=e.children)||void 0===t?void 0:t.length))throw new Error("queue.children.length can not be 0");if(null===(n=e.children)||void 0===n?void 0:n.find((function(e){return function(e){return!e||"function"!=typeof e}(e)})))throw new Error("queueList should have defer")},e.prototype.fixStr=function(e){return"".concat(this.fix).concat(e)},e=je([be,qe("design:paramtypes",[Object])],e)}(),Se=o(o(o(o(o(o(o(o(o(o(o(o({},D),m),F),W),U),f),Q),ee),oe),se),ye),{eventMessageCenter:me,taskQueueLib:Te});return e.AnimateFrame=le,e.MessageCenter=me,e.NBezier=ve,e.Request=G,e.TaskQueue=Te,e.addHandler=K,e.arrayDemote=M,e.arrayRandom=C,e.arrayUniq=L,e.catchAwait=N,e.classDecorator=x,e.clearStorage=re,e.cloneDeep=O,e.combination=he,e.createElement=J,e.createObject=T,e.createObjectVariable=E,e.cubicBezier=pe,e.debounce=R,e.decoratorMessageCenter=be,e.decoratorTaskQueue=function(e){return function(t){t.prototype.taskQueue||(t.prototype.taskQueue=new Te(e))}},e.default=Se,e.defer=_,e.dispatchEvent=Z,e.enumInversion=j,e.factorial=de,e.getInstance=P,e.getStorage=ne,e.getType=v,e.getTypeByList=y,e.getValue=g,e.inherit=S,e.isNotObject=q,e.isWindow=A,e.jsonToString=H,e.logLoop=ce,e.logOneLine=ie,e.messageCenter=ge,e.mixIn=w,e.quadraticBezier=fe,e.randomNum=p,e.removeHandler=Y,e.setStorage=te,e.setValue=b,e.stopBubble=$,e.stopDefault=X,e.stringToJson=k,e.throttle=I,e.urlJoin=h,e.urlSplit=d,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
1
+ var UtilsLib=function(e){"use strict";var t,n=function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};function r(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}e.types=void 0,(t=e.types||(e.types={}))["[object Array]"]="array",t["[object Object]"]="object",t["[object Function]"]="function",t["[object Set]"]="set",t["[object Map]"]="map",t["[object WeakMap]"]="weakMap",t["[object WeakSet]"]="weakSet",t["[object Date]"]="date",t["[object RegExp]"]="regExp",t["[object Math]"]="math";var o={types:e.types},i=function(e,t,n){return void 0===n&&(n=!1),Math.floor(Math.random()*(t-e+(n?1:0))+e)},u=function(e){var t={};return e.includes("?")?(e.split("?")[1].split("&").forEach((function(e){var n=e.split("=")[0];t[n]=e.split("=")[1]})),t):t},a=function(e,t){void 0===t&&(t={});var n=Object.keys(t);if(0===n.length)return e;var r=n.map((function(e){return"".concat(e,"=").concat(t[e])}));return"".concat(e).concat(e.includes("?")?"&":"?").concat(r.join("&"))},c=function(t){var n=typeof t;if(null===t)return"null";if("object"===n){var r=Object.prototype.toString.call(t);return e.types[r]}return n},s=function(e,t){void 0===t&&(t=[]);var n=c(e);return t.indexOf(n)>0},l={randomNum:i,urlSplit:u,urlJoin:a,getType:c,getTypeByList:s},f=function(e,t,n){void 0===n&&(n="");for(var r=0,o=t.split(".");r<o.length;r++){if(void 0===(e=e[o[r]]))return n}return e},p=function(e,t,n){void 0===n&&(n={});for(var r=t.split("."),o=r[r.length-1],i=e,u=0,a=r;u<a.length;u++){var c=a[u];if("object"!=typeof i&&void 0!==i)return e;!i&&(i={}),!i[c]&&(i[c]={}),o===c&&(i[o]=n),i=i[c]}return e},h=function(e,t,n){var r;for(var o in void 0===t&&(t={}),void 0===n&&(n=!1),t)for(var i in t[o]){var u=null!==(r=e.prototype)&&void 0!==r?r:e;(void 0===e[i]||n)&&(u[i]=t[o][i])}return e},d=function(e){for(var t in e){var n=e[t];"string"!=typeof n||e[n]||(e[n]=t)}return e},v=function(e,t){return"object"!=typeof e||"null"===t},y=function(e){var t=c(e);if(v(e,t))return e;var n=g(t,e);return"map"===t?e.forEach((function(e,t){n.set(t,y(e))})):"set"===t?e.forEach((function(e){n.add(y(e))})):Reflect.ownKeys(e).forEach((function(t){var r=e[t];n[t]=y(r)})),n},g=function(e,t){switch(void 0===t&&(t={}),e){case"array":return[];case"function":return t;case"set":return new Set;case"map":return new Map;case"date":return new Date(t);case"regExp":return new RegExp(t);case"math":return Math;default:return{}}},m=function(e){function t(){}return t.prototype=e,new t},b=function(e,t){return void 0===t&&(t=function(){}),t.prototype=m(e.prototype),t.prototype.super=e,t.prototype.constructor=t,t},w=function(e,t){void 0===t&&(t=!1);for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];return e._instance&&!t||(e._instance=new(e.bind.apply(e,r([void 0],n,!1)))),e._instance},j=function(e){return function(t){for(var n in e)Reflect.has(t.prototype,n)||(t.prototype[n]=e[n])}},E=function(e){if("string"!==c(e))return null;try{return JSON.parse(e)}catch(e){return null}},S=function(e){if(!s(e,["array","object","set","map"]))return"";try{return JSON.stringify(e)}catch(e){return""}},O=function(e){return e&&e===e.window},x={getValue:f,setValue:p,mixIn:h,enumInversion:d,isNotObject:v,cloneDeep:y,createObjectVariable:g,createObject:m,inherit:b,getInstance:w,classDecorator:j,stringToJson:E,jsonToString:S,isWindow:O},k=function(e){return e.sort((function(){return Math.random()-.5}))},P=function(e){return Array.from(new Set(e))},T=function(e,t){return void 0===t&&(t=[]),e.forEach((function(e){return"array"===c(e)?T(e,t):t.push(e)})),t},H={arrayRandom:k,arrayUniq:P,arrayDemote:T},q=void 0,L=function(e,t){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n||(n=setTimeout((function(){e.call.apply(e,r([q],o,!1)),n=null}),t))}},M=function(e,t){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n&&(clearTimeout(n),n=null),n=setTimeout((function(){e.call.apply(e,r([q],o,!1))}),t)}},C=function(e){var t,n;return void 0===e&&(e=0),e>0&&setTimeout(n,e),{promise:new Promise((function(e,r){t=e,n=r})),resolve:t,reject:n}},A=function(e){return e.then((function(e){return[null,e]})).catch((function(e){return[e]}))},R={throttle:L,debounce:M,defer:C,catchAwait:A},D=function(e){var t,n,r=e.ele,o=e.style,i=e.attr,u=e.parent,a=r instanceof HTMLElement?r:document.createElement(null!=r?r:"div");return o&&(null===(t=Object.keys(o))||void 0===t||t.forEach((function(e){return a.style[e]=o[e]}))),i&&(null===(n=Object.keys(i))||void 0===n||n.forEach((function(e){return a[e]=i[e]}))),u&&u.appendChild(a),a},B={createElement:D},I=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e["on"+t]=n},N=function(e){(e=e||window.event).stopPropagation?e.stopPropagation():e.cancelBubble=!1},J=function(e){(e=e||window.event).preventDefault?e.preventDefault():e.returnValue=!1},_=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e["on"+t]=null},V=function(e,t){var n=new Event(t);e.dispatchEvent(n)},z={addHandler:I,stopBubble:N,stopDefault:J,removeHandler:_,dispatchEvent:V},F=function(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(e){console.error(e)}},Q=function(e){try{var t=localStorage.getItem(e);return null==t?null:JSON.parse(t)}catch(e){return console.error(e),null}},W=function(e){try{e&&localStorage.removeItem(e),!e&&localStorage.clear()}catch(e){console.error(e)}},U={setStorage:F,getStorage:Q,clearStorage:W},G=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n=!0),t&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(e),n&&process.stdout.write("\n")},K=function(e){return G(e,!0,!1)},$=["\\","|","/","—","—"],X=function(e){var t;void 0===e&&(e={});var n=e.loopList,r=void 0===n?$:n,o=e.isStop,i=void 0!==o&&o,u=e.timer,a=void 0===u?100:u,c=e.index,s=void 0===c?0:c,l=null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0;if(!l)return e;if(i)return K("\n");s>=l-1&&(s=0);var f=r[s++];return K(f),setTimeout((function(){e.index=s,X(e)}),a),e},Y={logOneLine:G,logLoop:X},Z=function(){function e(e){this.fn=e,this.id=null,this.duration=1/0,this.isActive=!1}return e.prototype.start=function(e){this.isActive||(this.duration=null!=e?e:1/0,this.isActive=!0,this.animate())},e.prototype.stop=function(){this.isActive=!1,cancelAnimationFrame(this.id)},e.prototype.animate=function(e){void 0===e&&(e=0),this.isActive&&this.duration-- >0&&(this.fn(e),this.id=requestAnimationFrame(this.animate.bind(this)))},e}();function ee(e,t,n){var r=1-n,o=n*n;return[2*r*n*e+o,2*r*n*t+o]}function te(e,t,n,r,o){var i=3*e,u=3*t,a=3*(n-e)-i,c=3*(r-t)-u,s=1-u-c;return[(1-i-a)*Math.pow(o,3)+a*Math.pow(o,2)+i*o,s*Math.pow(o,3)+c*Math.pow(o,2)+u*o]}function ne(e){return 0===e||1===e?1:e*ne(e-1)}function re(e,t){return ne(e)/(ne(t)*ne(e-t))}function oe(e,t){for(var n=e.length-1,r=[0,0],o=0;o<=n;o++){var i=re(n,o)*Math.pow(1-t,n-o)*Math.pow(t,o);r[0]+=i*e[o][0],r[1]+=i*e[o][1]}return r}var ie={AnimateFrame:Z,quadraticBezier:ee,cubicBezier:te,factorial:ne,combination:re,NBezier:oe},ue=function(){function e(e){void 0===e&&(e={}),this.options=e,this.events={}}return e.prototype.on=function(e,t){return this.checkHandler(e,t),this.getHandler(e,[]).push(t),this},e.prototype.emit=function(e,t){return this.has(e)&&this.runHandler(e,t),this},e.prototype.un=function(e,t){return this.unHandler(e,t),this},e.prototype.once=function(e,t){var n=this;this.checkHandler(e,t);var r=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return n.un(e,r),t.apply(void 0,o)};return this.on(e,r),this},e.prototype.clear=function(){return this.events={},this},e.prototype.has=function(e){return!!this.getHandler(e)},e.prototype.getHandler=function(e,t){var n;return"object"==typeof t&&(this.events[e]=null!==(n=this.events[e])&&void 0!==n?n:t),this.events[e]},e.prototype.handlerLength=function(e){var t,n;return null!==(n=null===(t=this.getHandler(e))||void 0===t?void 0:t.length)&&void 0!==n?n:0},e.prototype.watch=function(e,t){var n=this;this.checkHandler(e,t);return this.on(e,(function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n.emit(n.prefixStr(e),t.apply(void 0,r))})),this},e.prototype.invoke=function(e,t){var n=this;return new Promise((function(r){n.once(n.prefixStr(e),r),n.emit(e,t)}))},e.prototype.runHandler=function(e,t){for(var n=0,r=this.getHandler(e);n<r.length;n++){var o=r[n];o&&o(t)}},e.prototype.unHandler=function(e,t){var n=this.getHandler(e);!t&&(this.events[e]=[]),t&&this.checkHandler(e,t);for(var r=0;r<n.length;r++)n&&n[r]===t&&(n[r]=null)},e.prototype.prefixStr=function(e){return"@".concat(e)},e.prototype.checkHandler=function(e,t){var n=this.options,r=n.blackList,o=void 0===r?[]:r,i=n.maxLen,u=void 0===i?1/0:i,a=this.handlerLength(e);if(0===(null==e?void 0:e.length))throw new Error("type.length can not be 0");if(!t||!e)throw new ReferenceError("type or handler is not defined");if("function"!=typeof t||"string"!=typeof e)throw new TypeError("".concat(t," is not a function or ").concat(e," is not a string"));if(o.includes(e))throw new Error("".concat(e," is not allow"));if(u<=a)throw new Error("the number of ".concat(e," must be less than ").concat(u))},e.Instance=function(e){return e._instance||Object.defineProperty(e,"_instance",{value:new e}),e._instance},e}(),ae=ue.Instance(ue),ce=function(e){return e.prototype.messageCenter||(e.prototype.messageCenter=new ue),e},se=function(){return se=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},se.apply(this,arguments)},le=function(e,t,n,r){var o,i=arguments.length,u=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(u=(i<3?o(u):i>3?o(t,n,u):o(t,n))||u);return i>3&&u&&Object.defineProperty(t,n,u),u},fe=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},pe=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,a)}c((r=r.apply(e,t||[])).next())}))},he=function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},de=function(){function e(e){var t=this;this.fix="@~&$",this.init=function(){t.messageCenter.on("push:handler",t.run),t.messageCenter.on("run:success:handler",t.run),t.messageCenter.on("run:success:handler",t.finish),t.messageCenter.on("run:error:handler",t.run),t.messageCenter.on("run:error:handler",t.finish)},this.defineProps=function(e,n){Object.defineProperty(t,n,{value:e})},this.push=function(e){var n;t.checkHandler(e);var r=(n=t.defer()).resolve,o=n.reject,i=n.promise,u=t.fixStr(e.name);return t.queues=t.queues.concat(e.children.map((function(e){return{defer:e,name:u}}))),t.queueTemp[u]=se(se({},e),{result:[]}),t.messageCenter.emit("push:handler",o),t.messageCenter.on(u,r),i},this.unshift=function(e){return t.queues.splice(0,e)},this.run=function(e){var n=e.reject;return pe(t,void 0,void 0,(function(){var e,t,r,o,i;return he(this,(function(u){switch(u.label){case 0:if("pending"===this.stateProxy())return[2,void 0];if(0===this.queues.length)return[2,this.stateProxy("idle")];this.stateProxy("pending"),e=this.unshift(null!==(i=null===(o=this.props)||void 0===o?void 0:o.maxLen)&&void 0!==i?i:10),u.label=1;case 1:return u.trys.push([1,3,,4]),[4,Promise.all(e.map((function(e,t){return e.defer().catch((function(e){return e}))})))];case 2:return t=u.sent(),[2,this.handlerSuccess({res:t,queues:e})];case 3:return r=u.sent(),[2,this.handlerError({reject:n,error:r,queues:e})];case 4:return[2]}}))}))},this.clear=function(){t.queues=[],t.queueTemp={},t.props=null,t.stateProxy("idle"),t.messageCenter.clear()},this.finish=function(e){var n=e.res,r=void 0===n?[]:n,o=e.queues,i=e.error,u=void 0===i?"err":i,a=t.queueTemp;o.forEach((function(e,n){var o,i,c,s=a[e.name];null==s||s.result.push(null!==(o=r[n])&&void 0!==o?o:u),(null===(i=null==s?void 0:s.result)||void 0===i?void 0:i.length)===(null===(c=null==s?void 0:s.children)||void 0===c?void 0:c.length)&&(t.messageCenter.emit(e.name,null==s?void 0:s.result),a[e.name]=null)}))},this.handlerSuccess=function(e){return t.stateProxy("fulfilled"),t.messageCenter.emit("run:success:handler",e)},this.handlerError=function(e){var n=e.reject,r=e.error;return t.stateProxy("rejected"),n&&"function"==typeof n&&n(r),t.messageCenter.emit("run:error:handler",e)},this.stateProxy=function(e){return e&&(t.state=e),t.state},this.defer=function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),resolve:e,reject:t}},this.clear(),e&&this.defineProps(e,"props"),this.init()}return e.prototype.checkHandler=function(e){var t,n;if(!e)throw new ReferenceError("queue is not defined");if(!(e.children instanceof Array)||"object"!=typeof e)throw new TypeError("queue should be an object and queue.children should be an array");if(0===(null===(t=e.children)||void 0===t?void 0:t.length))throw new Error("queue.children.length can not be 0");if(null===(n=e.children)||void 0===n?void 0:n.find((function(e){return function(e){return!e||"function"!=typeof e}(e)})))throw new Error("queueList should have defer")},e.prototype.fixStr=function(e){return"".concat(this.fix).concat(e)},e=le([ce,fe("design:paramtypes",[Object])],e)}(),ve=n(n(n(n(n(n(n(n(n(n(n({},x),l),H),R),B),o),z),U),Y),ie),{eventMessageCenter:ue,taskQueueLib:de});return e.AnimateFrame=Z,e.MessageCenter=ue,e.NBezier=oe,e.TaskQueue=de,e.addHandler=I,e.arrayDemote=T,e.arrayRandom=k,e.arrayUniq=P,e.catchAwait=A,e.classDecorator=j,e.clearStorage=W,e.cloneDeep=y,e.combination=re,e.createElement=D,e.createObject=m,e.createObjectVariable=g,e.cubicBezier=te,e.debounce=M,e.decoratorMessageCenter=ce,e.decoratorTaskQueue=function(e){return function(t){t.prototype.taskQueue||(t.prototype.taskQueue=new de(e))}},e.default=ve,e.defer=C,e.dispatchEvent=V,e.enumInversion=d,e.factorial=ne,e.getInstance=w,e.getStorage=Q,e.getType=c,e.getTypeByList=s,e.getValue=f,e.inherit=b,e.isNotObject=v,e.isWindow=O,e.jsonToString=S,e.logLoop=X,e.logOneLine=G,e.messageCenter=ae,e.mixIn=h,e.quadraticBezier=ee,e.randomNum=i,e.removeHandler=_,e.setStorage=F,e.setValue=p,e.stopBubble=N,e.stopDefault=J,e.stringToJson=E,e.throttle=L,e.urlJoin=a,e.urlSplit=u,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
@@ -1,4 +1,3 @@
1
- import type { AbortController } from "abort-controller";
2
1
  export type IKey = string | symbol | number;
3
2
  export interface IObject<T> {
4
3
  [key: IKey]: T | IObject<any>;
@@ -57,59 +56,6 @@ export type ILogLoopParams = {
57
56
  timer?: number;
58
57
  };
59
58
  export type ILogLoop = (opts?: ILogLoopParams) => ILogLoopParams | void;
60
- export type IRequestParams<T> = T | IObject<any> | null;
61
- export type IUrl = string;
62
- export type IEnv = 'Window' | 'Node';
63
- export type IDataType = "text" | "json" | "blob" | "formData" | "arrayBuffer";
64
- export type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTION" | "HEAD" | "PATCH";
65
- export type IRequestBody = IRequestParams<BodyInit>;
66
- export type IRequestHeaders = IRequestParams<HeadersInit>;
67
- export type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>;
68
- export type IRequestFn = (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>;
69
- export type IRequestOptions = {
70
- method?: IRequestMethods;
71
- query?: IRequestParams<IObject<any>>;
72
- body?: IRequestBody;
73
- headers?: IRequestHeaders;
74
- controller?: AbortController;
75
- timeout?: number;
76
- timer?: number | unknown | null;
77
- [key: string]: any;
78
- };
79
- export type IInterceptors = {
80
- use(type: "request" | "response" | "error", fn: Function): IInterceptors;
81
- get reqFn(): Function;
82
- get resFn(): Function;
83
- get errFn(): Function;
84
- };
85
- export type IRequestBase = {
86
- readonly origin: string;
87
- chackUrl: (url: IUrl) => boolean;
88
- envDesc: () => IEnv;
89
- errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R;
90
- clearTimer: (opts: IRequestOptions) => void;
91
- initAbort: (opts: IRequestOptions) => IRequestOptions;
92
- requestType: () => IRequestBaseFn;
93
- fixOrigin: (fixStr: string) => string;
94
- fetch: IRequestBaseFn;
95
- http: IRequestBaseFn;
96
- getDataByType: (type: IDataType, response: Response) => Promise<any>;
97
- formatBodyString: (bodyString: string) => IObject<Function>;
98
- };
99
- export type IRequestInit = {
100
- initDefaultParams: (url: IUrl, opts: IRequestOptions) => any;
101
- initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
102
- initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
103
- };
104
- export type IRequest = {
105
- GET: IRequestFn;
106
- POST: IRequestFn;
107
- DELETE: IRequestFn;
108
- PUT: IRequestFn;
109
- OPTIONS: IRequestFn;
110
- HEAD: IRequestFn;
111
- PATCH: IRequestFn;
112
- } & IRequestBase;
113
59
  export type IAnimateFrame = {
114
60
  id: number | null;
115
61
  duration: number;
@@ -5,7 +5,6 @@ export * from "./function";
5
5
  export * from "./element";
6
6
  export * from "./static";
7
7
  export * from "./types";
8
- export * from "./request";
9
8
  export * from "./event";
10
9
  export * from "./storage";
11
10
  export * from "./log";
@@ -33,7 +32,6 @@ declare const _default: {
33
32
  stopDefault: import("./types").IStopDefault;
34
33
  removeHandler: import("./types").IRemoveHandler;
35
34
  dispatchEvent: import("./types").IDispatchEvent;
36
- Request: typeof import("./request").Request;
37
35
  types: typeof import("./static").types;
38
36
  createElement: import("./types").ICreateElement<HTMLElement>;
39
37
  throttle: import("./types").IThrottle;
package/dist/cjs/index.js CHANGED
@@ -16,22 +16,6 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
16
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
17
  PERFORMANCE OF THIS SOFTWARE.
18
18
  ***************************************************************************** */
19
- /* global Reflect, Promise */
20
-
21
- var extendStatics = function(d, b) {
22
- extendStatics = Object.setPrototypeOf ||
23
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
24
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
25
- return extendStatics(d, b);
26
- };
27
-
28
- function __extends(d, b) {
29
- if (typeof b !== "function" && b !== null)
30
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
31
- extendStatics(d, b);
32
- function __() { this.constructor = d; }
33
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
- }
35
19
 
36
20
  var __assign$1 = function() {
37
21
  __assign$1 = Object.assign || function __assign(t) {
@@ -44,18 +28,6 @@ var __assign$1 = function() {
44
28
  return __assign$1.apply(this, arguments);
45
29
  };
46
30
 
47
- function __rest(s, e) {
48
- var t = {};
49
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
50
- t[p] = s[p];
51
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
52
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
53
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
54
- t[p[i]] = s[p[i]];
55
- }
56
- return t;
57
- }
58
-
59
31
  function __spreadArray(to, from, pack) {
60
32
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
61
33
  if (ar || !(i in from)) {
@@ -378,206 +350,6 @@ var element = {
378
350
  createElement: createElement
379
351
  };
380
352
 
381
- var httpRequest, httpsRequest, parse, CustomAbortController;
382
- if (typeof require !== "undefined") {
383
- CustomAbortController = require("abort-controller");
384
- httpRequest = require("http").request;
385
- httpsRequest = require("https").request;
386
- parse = require("url").parse;
387
- }
388
- else if (typeof AbortController !== "undefined") {
389
- CustomAbortController = AbortController;
390
- }
391
- else {
392
- CustomAbortController = function () {
393
- throw new Error('AbortController is not defined');
394
- };
395
- }
396
- var Interceptors = (function () {
397
- function Interceptors() {
398
- }
399
- Interceptors.prototype.use = function (type, fn) {
400
- switch (type) {
401
- case "request":
402
- this.requestSuccess = fn;
403
- break;
404
- case "response":
405
- this.responseSuccess = fn;
406
- break;
407
- case "error":
408
- this.error = fn;
409
- break;
410
- }
411
- return this;
412
- };
413
- Object.defineProperty(Interceptors.prototype, "reqFn", {
414
- get: function () {
415
- return this.requestSuccess;
416
- },
417
- enumerable: false,
418
- configurable: true
419
- });
420
- Object.defineProperty(Interceptors.prototype, "resFn", {
421
- get: function () {
422
- return this.responseSuccess;
423
- },
424
- enumerable: false,
425
- configurable: true
426
- });
427
- Object.defineProperty(Interceptors.prototype, "errFn", {
428
- get: function () {
429
- return this.error;
430
- },
431
- enumerable: false,
432
- configurable: true
433
- });
434
- return Interceptors;
435
- }());
436
- var RequestBase = (function (_super) {
437
- __extends(RequestBase, _super);
438
- function RequestBase(origin) {
439
- var _this = _super.call(this) || this;
440
- _this.chackUrl = function (url) {
441
- return url.startsWith('/');
442
- };
443
- _this.checkIsHttps = function (url) {
444
- return url.startsWith('https');
445
- };
446
- _this.fixOrigin = function (fixStr) {
447
- if (_this.chackUrl(fixStr))
448
- return _this.origin + fixStr;
449
- return fixStr;
450
- };
451
- _this.envDesc = function () {
452
- if (typeof Window !== "undefined") {
453
- return "Window";
454
- }
455
- return "Node";
456
- };
457
- _this.errorFn = function (reject) { return function (err) { var _a, _b; return reject((_b = (_a = _this.errFn) === null || _a === void 0 ? void 0 : _a.call(_this, err)) !== null && _b !== void 0 ? _b : err); }; };
458
- _this.clearTimer = function (opts) { return !!opts.timer && (clearTimeout(opts.timer), opts.timer = null); };
459
- _this.initAbort = function (params) {
460
- var controller = params.controller, timer = params.timer, timeout = params.timeout;
461
- !!!timer && (params.timer = setTimeout(function () { return controller.abort(); }, timeout));
462
- return params;
463
- };
464
- _this.requestType = function () {
465
- switch (_this.envDesc()) {
466
- case "Window":
467
- return _this.fetch;
468
- case "Node":
469
- return _this.http;
470
- }
471
- };
472
- _this.getDataByType = function (type, response) {
473
- switch (type) {
474
- case "text":
475
- case "json":
476
- case "blob":
477
- case "formData":
478
- case "arrayBuffer":
479
- return response[type]();
480
- default:
481
- return response['json']();
482
- }
483
- };
484
- _this.formatBodyString = function (bodyString) {
485
- return {
486
- text: function () { return bodyString; },
487
- json: function () { var _a; return (_a = stringToJson(bodyString)) !== null && _a !== void 0 ? _a : bodyString; },
488
- blob: function () { return stringToJson(bodyString); },
489
- formData: function () { return stringToJson(bodyString); },
490
- arrayBuffer: function () { return stringToJson(bodyString); },
491
- };
492
- };
493
- _this.origin = origin !== null && origin !== void 0 ? origin : '';
494
- return _this;
495
- }
496
- return RequestBase;
497
- }(Interceptors));
498
- var RequestInit = (function (_super) {
499
- __extends(RequestInit, _super);
500
- function RequestInit(origin) {
501
- var _this = _super.call(this, origin) || this;
502
- _this.initDefaultParams = function (url, _a) {
503
- var _b, _c;
504
- var _d = _a.method, method = _d === void 0 ? "GET" : _d, _e = _a.query, query = _e === void 0 ? {} : _e, _f = _a.headers, headers = _f === void 0 ? {} : _f, _g = _a.body, body = _g === void 0 ? null : _g, _h = _a.timeout, timeout = _h === void 0 ? 30 * 1000 : _h, _j = _a.controller, controller = _j === void 0 ? new CustomAbortController() : _j, _k = _a.type, type = _k === void 0 ? "json" : _k, others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
505
- var __params = __assign$1({ url: url, method: method, query: query, headers: headers, body: method === "GET" ? null : jsonToString(body), timeout: timeout, signal: controller === null || controller === void 0 ? void 0 : controller.signal, controller: controller, type: type, timer: null }, others);
506
- var params = (_c = (_b = _this.reqFn) === null || _b === void 0 ? void 0 : _b.call(_this, __params)) !== null && _c !== void 0 ? _c : __params;
507
- params.url = urlJoin(_this.fixOrigin(url), __params.query);
508
- return params;
509
- };
510
- _this.initFetchParams = function (url, opts) {
511
- var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
512
- return _temp;
513
- };
514
- _this.initHttpParams = function (url, opts) {
515
- var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
516
- var options = parse(_temp.url, true);
517
- return __assign$1(__assign$1({}, _temp), options);
518
- };
519
- return _this;
520
- }
521
- return RequestInit;
522
- }(RequestBase));
523
- var Request = (function (_super) {
524
- __extends(Request, _super);
525
- function Request(origin) {
526
- var _this = _super.call(this, origin) || this;
527
- _this.fetch = function (_url, _opts) {
528
- var _a = defer(), promise = _a.promise, resolve = _a.resolve, reject = _a.reject;
529
- var _b = _this.initFetchParams(_url, _opts), url = _b.url, opts = __rest(_b, ["url"]);
530
- var signal = opts.signal;
531
- promise.finally(function () { return _this.clearTimer(opts); });
532
- signal.addEventListener('abort', function () { return _this.errorFn(reject); });
533
- fetch(url, opts).then(function (response) {
534
- if ((response === null || response === void 0 ? void 0 : response.status) >= 200 && (response === null || response === void 0 ? void 0 : response.status) < 300) {
535
- return _this.getDataByType(opts.type, response);
536
- }
537
- return _this.errorFn(reject);
538
- }).then(function (res) { var _a, _b; return resolve((_b = (_a = _this.resFn) === null || _a === void 0 ? void 0 : _a.call(_this, res)) !== null && _b !== void 0 ? _b : res); }).catch(_this.errorFn(reject));
539
- return promise;
540
- };
541
- _this.http = function (_url, _opts) {
542
- var _a = defer(), promise = _a.promise, resolve = _a.resolve, reject = _a.reject;
543
- var params = _this.initHttpParams(_url, _opts);
544
- var signal = params.signal, url = params.url;
545
- promise.finally(function () { return _this.clearTimer(params); });
546
- var request = _this.checkIsHttps(url) ? httpsRequest : httpRequest;
547
- var req = request(params, function (response) {
548
- var statusCode = response.statusCode, statusMessage = response.statusMessage;
549
- var data = "";
550
- response.setEncoding('utf8');
551
- response.on('data', function (chunk) { return data += chunk; });
552
- return response.on("end", function () {
553
- var _a, _b;
554
- var result = _this.getDataByType(params.type, _this.formatBodyString(data));
555
- if (statusCode >= 200 && statusCode < 300) {
556
- return resolve((_b = (_a = _this.resFn) === null || _a === void 0 ? void 0 : _a.call(_this, result)) !== null && _b !== void 0 ? _b : result);
557
- }
558
- return _this.errorFn(reject)({ statusCode: statusCode, statusMessage: statusMessage, result: result, data: data });
559
- });
560
- });
561
- signal.addEventListener('abort', function () { return _this.errorFn(reject)(req.destroy(new Error('request timeout'))); });
562
- req.write(params.body);
563
- req.on('error', _this.errorFn(reject));
564
- req.end();
565
- return promise;
566
- };
567
- _this.GET = function (url, query, _, opts) { return _this.request(url, __assign$1({ query: query, method: "GET" }, opts)); };
568
- _this.POST = function (url, query, body, opts) { return _this.request(url, __assign$1({ query: query, method: "POST", body: body }, opts)); };
569
- _this.PUT = function (url, query, body, opts) { return _this.request(url, __assign$1({ query: query, method: "PUT", body: body }, opts)); };
570
- _this.DELETE = function (url, query, body, opts) { return _this.request(url, __assign$1({ query: query, method: "DELETE", body: body }, opts)); };
571
- _this.OPTIONS = function (url, query, body, opts) { return _this.request(url, __assign$1({ query: query, method: "OPTIONS", body: body }, opts)); };
572
- _this.HEAD = function (url, query, body, opts) { return _this.request(url, __assign$1({ query: query, method: "HEAD", body: body }, opts)); };
573
- _this.PATCH = function (url, query, body, opts) { return _this.request(url, __assign$1({ query: query, method: "PATCH", body: body }, opts)); };
574
- _this.request = _this.requestType();
575
- return _this;
576
- }
577
- return Request;
578
- }(RequestInit));
579
- var request = { Request: Request };
580
-
581
353
  var addHandler = function (ele, type, handler) {
582
354
  if (ele.addEventListener) {
583
355
  ele.addEventListener(type, handler, false);
@@ -1092,12 +864,11 @@ var decoratorTaskQueue = function (opts) {
1092
864
  };
1093
865
  };
1094
866
 
1095
- var index = __assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1({}, object), base), array), __function), element), __static), request), event), storage), log), animate), { eventMessageCenter: MessageCenter, taskQueueLib: TaskQueue });
867
+ var index = __assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1({}, object), base), array), __function), element), __static), event), storage), log), animate), { eventMessageCenter: MessageCenter, taskQueueLib: TaskQueue });
1096
868
 
1097
869
  exports.AnimateFrame = AnimateFrame;
1098
870
  exports.MessageCenter = MessageCenter;
1099
871
  exports.NBezier = NBezier;
1100
- exports.Request = Request;
1101
872
  exports.TaskQueue = TaskQueue;
1102
873
  exports.addHandler = addHandler;
1103
874
  exports.arrayDemote = arrayDemote;
@@ -1,4 +1,3 @@
1
- import type { AbortController } from "abort-controller";
2
1
  export type IKey = string | symbol | number;
3
2
  export interface IObject<T> {
4
3
  [key: IKey]: T | IObject<any>;
@@ -57,59 +56,6 @@ export type ILogLoopParams = {
57
56
  timer?: number;
58
57
  };
59
58
  export type ILogLoop = (opts?: ILogLoopParams) => ILogLoopParams | void;
60
- export type IRequestParams<T> = T | IObject<any> | null;
61
- export type IUrl = string;
62
- export type IEnv = 'Window' | 'Node';
63
- export type IDataType = "text" | "json" | "blob" | "formData" | "arrayBuffer";
64
- export type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTION" | "HEAD" | "PATCH";
65
- export type IRequestBody = IRequestParams<BodyInit>;
66
- export type IRequestHeaders = IRequestParams<HeadersInit>;
67
- export type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>;
68
- export type IRequestFn = (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>;
69
- export type IRequestOptions = {
70
- method?: IRequestMethods;
71
- query?: IRequestParams<IObject<any>>;
72
- body?: IRequestBody;
73
- headers?: IRequestHeaders;
74
- controller?: AbortController;
75
- timeout?: number;
76
- timer?: number | unknown | null;
77
- [key: string]: any;
78
- };
79
- export type IInterceptors = {
80
- use(type: "request" | "response" | "error", fn: Function): IInterceptors;
81
- get reqFn(): Function;
82
- get resFn(): Function;
83
- get errFn(): Function;
84
- };
85
- export type IRequestBase = {
86
- readonly origin: string;
87
- chackUrl: (url: IUrl) => boolean;
88
- envDesc: () => IEnv;
89
- errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R;
90
- clearTimer: (opts: IRequestOptions) => void;
91
- initAbort: (opts: IRequestOptions) => IRequestOptions;
92
- requestType: () => IRequestBaseFn;
93
- fixOrigin: (fixStr: string) => string;
94
- fetch: IRequestBaseFn;
95
- http: IRequestBaseFn;
96
- getDataByType: (type: IDataType, response: Response) => Promise<any>;
97
- formatBodyString: (bodyString: string) => IObject<Function>;
98
- };
99
- export type IRequestInit = {
100
- initDefaultParams: (url: IUrl, opts: IRequestOptions) => any;
101
- initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
102
- initHttpParams: (url: IUrl, opts: IRequestOptions) => any;
103
- };
104
- export type IRequest = {
105
- GET: IRequestFn;
106
- POST: IRequestFn;
107
- DELETE: IRequestFn;
108
- PUT: IRequestFn;
109
- OPTIONS: IRequestFn;
110
- HEAD: IRequestFn;
111
- PATCH: IRequestFn;
112
- } & IRequestBase;
113
59
  export type IAnimateFrame = {
114
60
  id: number | null;
115
61
  duration: number;
@@ -5,7 +5,6 @@ export * from "./function";
5
5
  export * from "./element";
6
6
  export * from "./static";
7
7
  export * from "./types";
8
- export * from "./request";
9
8
  export * from "./event";
10
9
  export * from "./storage";
11
10
  export * from "./log";
@@ -33,7 +32,6 @@ declare const _default: {
33
32
  stopDefault: import("./types").IStopDefault;
34
33
  removeHandler: import("./types").IRemoveHandler;
35
34
  dispatchEvent: import("./types").IDispatchEvent;
36
- Request: typeof import("./request").Request;
37
35
  types: typeof import("./static").types;
38
36
  createElement: import("./types").ICreateElement<HTMLElement>;
39
37
  throttle: import("./types").IThrottle;