pubo-web 1.0.149 → 1.0.157

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-web.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["pubo-web"]=e():t["pubo-web"]=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}t.r(e),t.d(e,{DragMethod:()=>M,IndexedStorage:()=>B,WebStorage:()=>f,WebsocketClient:()=>S,blob2base64:()=>o,blob2file:()=>s,blob2text:()=>i,downloadFile:()=>u,getCookie:()=>$,getCookieValue:()=>R,loadScript:()=>r,pickFiles:()=>j,setCookieItem:()=>J});var r=function(t,e){return void 0===e&&(e={}),new Promise((function(r){var i=function(){for(var e,r=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(document.getElementsByTagName("script"));!(e=r()).done;){var i=e.value;if(i.src===t)return i}return null}(),o=i;if(i){if("complete"===i._state)return r(t)}else o=document.createElement("script");for(var s=0,u=Object.keys(e);s<u.length;s++){var a=u[s];o[a]=e[a]}return o.src=t,o.addEventListener("load",(function e(){r(t),o.removeEventListener("load",e),o._state="complete"})),document.body.appendChild(o),"success"}))},i=function(t){return new Promise((function(e){var n=new FileReader;n.onload=function(t){return e(t.target.result)},n.readAsText(t)}))},o=function(t){return new Promise((function(e,n){var r=new FileReader;t?(r.onload=function(t){return e(t.target.result)},r.onabort=function(){return n()},r.readAsDataURL(t)):n("文件爲空!")}))},s=function(t,e,n){return new File(t,e,{type:n})},u=function(t,e){var n=document.createElement("a");n.href=t,e&&(n.download=e),n.style.position="fixed",n.style.visibility="hidden",document.body.appendChild(n),n.click(),document.body.removeChild(n)};function a(){return a=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},a.apply(this,arguments)}function c(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,"symbol"==typeof(i=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key))?i:String(i)),r)}var i}var f=function(){function t(t){this._key=void 0,this.storage=void 0,this.zip=void 0;var e=t.type,n=void 0===e?"sessionStorage":e,r=t.key;this._key=r,this.storage=window[n],this.zip=t.zip}var e,n,r=t.prototype;return r.merge=function(t){var e=this.state;this.state=a({},e,t)},r.clear=function(){this.storage.removeItem(this._key)},e=t,(n=[{key:"state",get:function(){var t=this.storage.getItem(this._key);return this.zip&&t&&(t=this.zip.inflate(t)),t?JSON.parse(t):null},set:function(t){var e=JSON.stringify(t);this.zip&&(e=this.zip.deflate(e)),this.storage.setItem(this._key,e)}},{key:"key",get:function(){return this._key}}])&&c(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();function h(){}function l(t){var e=t();if(e&&e.then)return e.then(h)}var v="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function d(t,e,n){if(!t.s){if(n instanceof p){if(!n.s)return void(n.o=d.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(d.bind(null,t,e),d.bind(null,t,2));t.s=e,t.v=n;var r=t.o;r&&r(t)}}var p=function(){function t(){}return t.prototype.then=function(e,n){var r=new t,i=this.s;if(i){var o=1&i?e:n;if(o){try{d(r,1,o(this.v))}catch(t){d(r,2,t)}return r}return this}return this.o=function(t){try{var i=t.v;1&t.s?d(r,1,e?e(i):i):n?d(r,1,n(i)):d(r,2,i)}catch(t){d(r,2,t)}},r},t}();function y(t){return t instanceof p&&1&t.s}function b(){return b=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},b.apply(this,arguments)}function m(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var g=function(){function t(){this.state={},this.ids={}}var e=t.prototype;return e.on=function(t,e){if(this.state[t]||(this.state[t]=[]),"function"!=typeof e)throw new Error("第二个参数必须为function!");var n=this.state[t].push(e)-1,r=function(t){void 0===t&&(t=8);var e=function(t){return Math.random().toString(32).slice(2,2+t)};if(t<=8)return e(t);for(var n="",r=0;r<=t;r+=8)n+=e(t-r>8?8:t-r);return n}(40);return this.ids[r]={event:t,index:n},r},e.cancel=function(t){var e=this;if(t){var n=this.ids[t]||{},r=n.event,i=n.index;r&&Array.isArray(this.state[r])&&(this.state[r].splice(i,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){e.ids[t].event===r&&e.ids[t].index>i&&(e.ids[t].index=e.ids[t].index-1)})))}else this.clear()},e.clear=function(){this.state.length=0},e.emit=function(t,e){if(Array.isArray(this.state[t]))for(var n,r=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return m(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?m(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this.state[t]);!(n=r()).done;){var i=n.value;"function"==typeof i&&i(e)}},e.emitSync=function(t,e){try{var n=this;return(r=l((function(){if(Array.isArray(n.state[t]))return function(t){if(t&&t.then)return t.then(h)}(function(t,e,n){if("function"==typeof t[v]){var r,i,o,s=t[v]();if(function t(u){try{for(;!((r=s.next()).done||n&&n());)if((u=e(r.value))&&u.then){if(!y(u))return void u.then(t,o||(o=d.bind(null,i=new p,2)));u=u.v}i?d(i,1,u):i=u}catch(t){d(i||(i=new p),2,t)}}(),s.return){var u=function(t){try{r.done||s.return()}catch(t){}return t};if(i&&i.then)return i.then(u,(function(t){throw u(t)}));u()}return i}if(!("length"in t))throw new TypeError("Object is not iterable");for(var a=[],c=0;c<t.length;c++)a.push(t[c]);return function(t,e,n){var r,i,o=-1;return function s(u){try{for(;++o<t.length&&(!n||!n());)if((u=e(o))&&u.then){if(!y(u))return void u.then(s,i||(i=d.bind(null,r=new p,2)));u=u.v}r?d(r,1,u):r=u}catch(t){d(r||(r=new p),2,t)}}(),r}(a,(function(t){return e(a[t])}),n)}(n.state[t],(function(t){return l((function(){if("function"==typeof t)return function(t,e){return t&&t.then?t.then(h):Promise.resolve()}(t(e))}))})))})))&&r.then||(r=Promise.resolve(r)),r}catch(t){return Promise.reject(t)}var r},e.clone=function(){return{state:b({},this.state),ids:b({},this.ids)}},e.restore=function(t){this.state=t.state,this.ids=t.ids},t}();function w(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,"symbol"==typeof(i=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key))?i:String(i)),r)}var i}var S=function(){function t(t){var e=t.url;this.client=null,this._status=0,this.url=void 0,this.emitter=new g,this.url=e}var e,n,r=t.prototype;return r.reconnect=function(){var t=this;this.client&&this.client.close(),this.client=null,3===this._status&&setTimeout((function(){return t.connect()}),1e3)},r.onClose=function(){2!==this._status&&(this._status=3),this.reconnect()},r.onMessage=function(t){this.emitter.emit("message",t.data)},r.connect=function(){var t=this;this.client||(this.client=new WebSocket(this.url),this.client.onclose=this.onClose.bind(this),this.client.onmessage=this.onMessage.bind(this),this.client.onopen=function(){t.emitter.emit("connect"),t._status=1})},r.close=function(){this._status=2,this.client&&this.client.close(),this.client=null},r.send=function(t,e){var n;void 0===e&&(e=!1);var r=t;e&&(r=JSON.stringify(t)),null==(n=this.client)||n.send(r)},e=t,(n=[{key:"status",get:function(){return this._status}}])&&w(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}(),M=function(){function t(t){var e=void 0===t?{}:t,n=e.key,r=void 0===n?"":n,i=e.onMove,o=e.onMoveEnd;this.key="",this.cache={pageX:0,pageY:0,dragging:!1},this.onMouseMove=void 0,this.onMouseUp=void 0,this.onMouseDown=void 0,this.onTouchStart=void 0,this.onMove=void 0,this.onMoveEnd=void 0,this.key=r,this.onMouseDown=this._onMouseDown.bind(this),this.onTouchStart=this._onMouseDown.bind(this),this.onMouseMove=this._onMouseMove.bind(this),this.onMouseUp=this._onMouseUp.bind(this),this.onMove=i,this.onMoveEnd=o}var e=t.prototype;return e._onMouseMove=function(t){var e,n,r,i;if("function"==typeof this.onMove){t.preventDefault?t.preventDefault():t.returnValue=!1;var o=null!=(e=t.pageX)?e:null==(n=t.touches[0])?void 0:n.pageX,s=null!=(r=t.pageY)?r:null==(i=t.touches[0])?void 0:i.pageY;this.onMove({offsetX:o-this.cache.pageX,offsetY:s-this.cache.pageY,pageX:o,pageY:s,startX:this.cache.pageX,startY:this.cache.pageY,key:this.key}),this.cache.pageX=o,this.cache.pageY=s}},e.clearListener=function(){window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("touchmove",this.onMouseMove),window.removeEventListener("mouseup",this.onMouseUp),window.removeEventListener("touchend",this.onMouseUp)},e._onMouseUp=function(){this.clearListener(),this.cache.dragging=!1,"function"==typeof this.onMoveEnd&&this.onMoveEnd()},e._onMouseDown=function(t){var e,n,r,i;if(t.preventDefault&&t.pageX?t.preventDefault():t.returnValue=!1,"function"==typeof this.onMove&&!this.cache.dragging){this.clearListener();var o=null!=(e=t.pageX)?e:null==(n=t.touches[0])?void 0:n.pageX,s=null!=(r=t.pageY)?r:null==(i=t.touches[0])?void 0:i.pageY;this.cache.dragging=!0,this.cache.pageX=o,this.cache.pageY=s,window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("touchmove",this.onMouseMove,{passive:!1}),window.addEventListener("mouseup",this.onMouseUp),window.addEventListener("touchend",this.onMouseUp,{passive:!1})}},t}(),j=function(){return new Promise((function(t,e){var n=document.createElement("input"),r=!1;n.type="file",n.style.visibility="hidden",n.style.position="fixed",n.style.top="0px",n.style.zIndex="-1",window.addEventListener("focus",(function t(){document.body.removeChild(n),window.removeEventListener("focus",t),setTimeout((function(){r||e("no files picked")}),1e3)})),n.onchange=function(e){r=e.target.files.length>0,t(e.target.files)},document.body.appendChild(n),n.click()}))};function P(){}var k,O=(k=function(t){return(e=new Promise((function(e){var n=setTimeout((function(){e(),clearTimeout(n),n=null}),t)})))&&e.then?e.then(P):Promise.resolve();var e},function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return Promise.resolve(k.apply(this,t))}catch(t){return Promise.reject(t)}});function E(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];try{return Promise.resolve(t.apply(this,e))}catch(t){return Promise.reject(t)}}}function _(){}var A="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function x(t,e,n){if(!t.s){if(n instanceof T){if(!n.s)return void(n.o=x.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(x.bind(null,t,e),x.bind(null,t,2));t.s=e,t.v=n;var r=t.o;r&&r(t)}}var T=function(){function t(){}return t.prototype.then=function(e,n){var r=new t,i=this.s;if(i){var o=1&i?e:n;if(o){try{x(r,1,o(this.v))}catch(t){x(r,2,t)}return r}return this}return this.o=function(t){try{var i=t.v;1&t.s?x(r,1,e?e(i):i):n?x(r,1,n(i)):x(r,2,i)}catch(t){x(r,2,t)}},r},t}();function I(t){return t instanceof T&&1&t.s}function L(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var C=function(){function t(t,e,n){this.name=void 0,this.version=void 0,this.indexedDB=self.indexedDB,this.tables=void 0,this.db=void 0,this.transaction=void 0,this.get=this.createTransaction((function(t,e){return t.get(e)})),this.getAll=this.createTransaction((function(t){return t.getAll()})),this.delete=this.createTransaction((function(t,e){return t.delete(e)})),this.put=this.createTransaction((function(t,e){return t.put(e)})),this.name=t,this.version=e,this.tables=n}var e=t.prototype;return e.open=function(){var t=this;return new Promise((function(e,n){var r,i=null==(r=t.indexedDB)?void 0:r.open(t.name,t.version);i.onupgradeneeded=E((function(e){var n,r=e.target.result;t.transaction=e.target.transaction,t.transaction.oncomplete=E((function(){return t.transaction=null,function(t){if(t&&t.then)return t.then(_)}(function(t,e,n){if("function"==typeof t[A]){var r,i,o,s=t[A]();if(function t(u){try{for(;!((r=s.next()).done||n&&n());)if((u=e(r.value))&&u.then){if(!I(u))return void u.then(t,o||(o=x.bind(null,i=new T,2)));u=u.v}i?x(i,1,u):i=u}catch(t){x(i||(i=new T),2,t)}}(),s.return){var u=function(t){try{r.done||s.return()}catch(t){}return t};if(i&&i.then)return i.then(u,(function(t){throw u(t)}));u()}return i}if(!("length"in t))throw new TypeError("Object is not iterable");for(var a=[],c=0;c<t.length;c++)a.push(t[c]);return function(t,e,n){var r,i,o=-1;return function s(u){try{for(;++o<t.length&&(!n||!n());)if((u=e(o))&&u.then){if(!I(u))return void u.then(s,i||(i=x.bind(null,r=new T,2)));u=u.v}r?x(r,1,u):r=u}catch(t){x(r||(r=new T),2,t)}}(),r}(a,(function(t){return e(a[t])}),n)}(t.tables,(function(e){return function(n){var r=function(){if(e.default)return function(t,e){if(!void 0)return t&&t.then?t.then(_):Promise.resolve()}(t.put(e.name,e.default))}();if(r&&r.then)return r.then(_)}()})))}));for(var i,o=function(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return L(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?L(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t.tables);!(i=o()).done;){var s=i.value;r.objectStoreNames.contains(s.name)||r.createObjectStore(s.name,s.options||{keyPath:"_id",autoIncrement:!0})}return t.db=r,n&&n.then||(n=Promise.resolve(n)),n})),i.onsuccess=function(){t.db||(t.db=i.result),e("success")},i.onerror=function(t){console.error("indexed db connect error: ",t),n(t)}}))},e.createTransaction=function(t){var e=this;return function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),o=1;o<r;o++)i[o-1]=arguments[o];return new Promise((function(r,o){if(e.db){var s=e.db.transaction([n],"readwrite").objectStore(n),u=t.apply(void 0,[s].concat(i));u.onerror=function(t){o(t)},u.onsuccess=function(){r(u.result)}}else o("not connect")}))}},t}();function D(t,e,n){return n?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function X(){}function U(t,e,n){if(!t.s){if(n instanceof Y){if(!n.s)return void(n.o=U.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(U.bind(null,t,e),U.bind(null,t,2));t.s=e,t.v=n;var r=t.o;r&&r(t)}}var Y=function(){function t(){}return t.prototype.then=function(e,n){var r=new t,i=this.s;if(i){var o=1&i?e:n;if(o){try{U(r,1,o(this.v))}catch(t){U(r,2,t)}return r}return this}return this.o=function(t){try{var i=t.v;1&t.s?U(r,1,e?e(i):i):n?U(r,1,n(i)):U(r,2,i)}catch(t){U(r,2,t)}},r},t}();function z(t){return t instanceof Y&&1&t.s}function F(){return F=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},F.apply(this,arguments)}var N=function(){function t(t,e){this.utils=void 0,this.store=void 0,this.utils=t,this.store=e}var e=t.prototype;return e.getState=function(){try{return D(this.utils.get(this.store,1))}catch(t){return Promise.reject(t)}},e.setState=function(t){this.utils.put(this.store,F({},t,{_id:1}))},e.merge=function(t){try{var e=this;return D(e.getState(),(function(n){e.setState=F({},n,t,{_id:1})}))}catch(t){return Promise.reject(t)}},t}(),B=function(){function t(t){var e=t.name,n=t.version,r=t.tables;this.name=void 0,this.version=void 0,this.utils=void 0,this._cache={},this.tables=[],this.connected=!1,this.connecting=!1,this.name=e,this.version=n,this.tables=null!=r?r:[]}var e=t.prototype;return e.register=function(t){var e;(e=this.tables).push.apply(e,t)},e.connect=function(){try{var t=!1,e=this;return e.connected?D():D((n=function(){if(e.connecting)return n=function(t,e,n){for(var r;;){var i=t();if(z(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!z(o)){r=1;break}o=o.s}if(e){var s=e();if(s&&s.then&&!z(s)){r=2;break}}}var u=new Y,a=U.bind(null,u,2);return(0===r?i.then(f):1===r?o.then(c):s.then(h)).then(void 0,a),u;function c(r){o=r;do{if(e&&(s=e())&&s.then&&!z(s))return void s.then(h).then(void 0,a);if(!(i=t())||z(i)&&!i.v)return void U(u,1,o);if(i.then)return void i.then(f).then(void 0,a);z(o=n())&&(o=o.v)}while(!o||!o.then);o.then(c).then(void 0,a)}function f(t){t?(o=n())&&o.then?o.then(c).then(void 0,a):c(o):U(u,1,o)}function h(){(i=t())?i.then?i.then(f).then(void 0,a):f(i):U(u,1,o)}}((function(){return!e.connecting}),void 0,(function(){return function(t,e){return t&&t.then?t.then(X):Promise.resolve()}(O(100))})),r=function(){t=!0},n&&n.then?n.then(r):r();var n,r},r=function(n){return t?n:(e.connecting=!0,e.utils=new C(e.name,e.version,e.tables),D(e.utils.open(),(function(){e.connected=!0,e.connecting=!1})))},(i=n())&&i.then?i.then(r):r(i)))}catch(t){return Promise.reject(t)}var n,r,i},e.get=function(t){return!this._cache[t]&&this.utils&&(this._cache[t]=new N(this.utils,t)),this._cache[t]},t}(),R=function(t){var e=new RegExp("(^| )"+t+"=([^;]*)(;|$)").exec(document.cookie);return e?e[2]:""},$=function(){var t={};return document.cookie?(document.cookie.split(";").forEach((function(e){var n=e.split("="),r=n[0],i=n[1];t[r]=i})),t):t},J=function(t,e){document.cookie=t+"="+e};return e})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["pubo-web"]=t():e["pubo-web"]=t()}(this,(()=>(()=>{"use strict";var e={d:(t,s)=>{for(var i in s)e.o(s,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:s[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{DragMethod:()=>l,IndexedStorage:()=>y,WebStorage:()=>c,WebsocketClient:()=>h,blob2base64:()=>n,blob2file:()=>o,blob2text:()=>i,downloadFile:()=>r,getCookie:()=>p,getCookieValue:()=>d,loadScript:()=>s,pickFiles:()=>u,setCookieItem:()=>g});const s=(e,t={})=>new Promise((s=>{const i=(()=>{const t=document.getElementsByTagName("script");for(const s of t)if(s.src===e)return s;return null})();let n=i;if(i){if("complete"===i._state)return s(e)}else n=document.createElement("script");for(const e of Object.keys(t))n[e]=t[e];const o=()=>{s(e),n.removeEventListener("load",o),n._state="complete"};return n.src=e,n.addEventListener("load",o),document.body.appendChild(n),"success"})),i=e=>new Promise((t=>{const s=new FileReader;s.onload=e=>t(e.target.result),s.readAsText(e)})),n=e=>new Promise((function(t,s){const i=new FileReader;e?(i.onload=e=>t(e.target.result),i.onabort=()=>s(),i.readAsDataURL(e)):s("文件爲空!")})),o=(e,t,s)=>new File(e,t,{type:s}),r=(e,t)=>{const s=document.createElement("a");s.href=e,t&&(s.download=t),s.style.position="fixed",s.style.visibility="hidden",document.body.appendChild(s),s.click(),document.body.removeChild(s)};class c{_key;storage;zip;constructor(e){const{type:t="sessionStorage",key:s}=e;this._key=s,this.storage=window[t],this.zip=e.zip}get state(){let e=this.storage.getItem(this._key);return this.zip&&e&&(e=this.zip.inflate(e)),e?JSON.parse(e):null}set state(e){let t=JSON.stringify(e);this.zip&&(t=this.zip.deflate(t)),this.storage.setItem(this._key,t)}get key(){return this._key}merge(e){const t=this.state;this.state={...t,...e}}clear(){this.storage.removeItem(this._key)}}class a{state={};ids={};on(e,t){if(this.state[e]||(this.state[e]=[]),"function"!=typeof t)throw new Error("第二个参数必须为function!");const s=this.state[e].push(t)-1,i=((e=8)=>{const t=e=>Math.random().toString(32).slice(2,2+e);if(e<=8)return t(e);let s="";for(let i=0;i<=e;i+=8)s+=t(e-i>8?8:e-i);return s})(40);return this.ids[i]={event:e,index:s},i}cancel(e){if(!e)return void this.clear();const{event:t,index:s}=this.ids[e]||{};t&&Array.isArray(this.state[t])&&(this.state[t].splice(s,1),delete this.ids[e],Object.keys(this.ids).forEach((e=>{this.ids[e].event===t&&this.ids[e].index>s&&(this.ids[e].index=this.ids[e].index-1)})))}clear(){this.state.length=0}emit(e,t){if(Array.isArray(this.state[e]))for(const s of this.state[e])"function"==typeof s&&s(t)}async emitSync(e,t){if(Array.isArray(this.state[e]))for(const s of this.state[e])"function"==typeof s&&await s(t)}clone(){return{state:{...this.state},ids:{...this.ids}}}restore(e){this.state=e.state,this.ids=e.ids}}class h{client=null;_status=0;url;emitter=new a;constructor({url:e}){this.url=e}reconnect(){this.client&&this.client.close(),this.client=null,3===this._status&&setTimeout((()=>this.connect()),1e3)}onClose(){2!==this._status&&(this._status=3),this.reconnect()}onMessage(e){this.emitter.emit("message",e.data)}get status(){return this._status}connect(){this.client||(this.client=new WebSocket(this.url),this.client.onclose=this.onClose.bind(this),this.client.onmessage=this.onMessage.bind(this),this.client.onopen=()=>{this.emitter.emit("connect"),this._status=1})}close(){this._status=2,this.client&&this.client.close(),this.client=null}send(e,t=!1){let s=e;t&&(s=JSON.stringify(e)),this.client?.send(s)}}class l{key="";cache={pageX:0,pageY:0,dragging:!1};onMouseMove;onMouseUp;onMouseDown;onTouchStart;onMove;onMoveEnd;constructor({key:e="",onMove:t,onMoveEnd:s}={}){this.key=e,this.onMouseDown=this._onMouseDown.bind(this),this.onTouchStart=this._onMouseDown.bind(this),this.onMouseMove=this._onMouseMove.bind(this),this.onMouseUp=this._onMouseUp.bind(this),this.onMove=t,this.onMoveEnd=s}_onMouseMove(e){if("function"!=typeof this.onMove)return;e.preventDefault?e.preventDefault():e.returnValue=!1;const t=e.pageX??e.touches[0]?.pageX,s=e.pageY??e.touches[0]?.pageY;this.onMove({offsetX:t-this.cache.pageX,offsetY:s-this.cache.pageY,pageX:t,pageY:s,startX:this.cache.pageX,startY:this.cache.pageY,key:this.key}),this.cache.pageX=t,this.cache.pageY=s}clearListener(){window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("touchmove",this.onMouseMove),window.removeEventListener("mouseup",this.onMouseUp),window.removeEventListener("touchend",this.onMouseUp)}_onMouseUp(){this.clearListener(),this.cache.dragging=!1,"function"==typeof this.onMoveEnd&&this.onMoveEnd()}_onMouseDown(e){if(e.preventDefault&&e.pageX?e.preventDefault():e.returnValue=!1,"function"!=typeof this.onMove||this.cache.dragging)return;this.clearListener();const t=e.pageX??e.touches[0]?.pageX,s=e.pageY??e.touches[0]?.pageY;this.cache.dragging=!0,this.cache.pageX=t,this.cache.pageY=s,window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("touchmove",this.onMouseMove,{passive:!1}),window.addEventListener("mouseup",this.onMouseUp),window.addEventListener("touchend",this.onMouseUp,{passive:!1})}}const u=()=>new Promise(((e,t)=>{const s=document.createElement("input");let i=!1;const n=()=>{document.body.removeChild(s),window.removeEventListener("focus",n),setTimeout((()=>{i||t("no files picked")}),1e3)};s.type="file",s.style.visibility="hidden",s.style.position="fixed",s.style.top="0px",s.style.zIndex="-1",window.addEventListener("focus",n),s.onchange=t=>{i=t.target.files.length>0,e(t.target.files)},document.body.appendChild(s),s.click()})),d=e=>{const t=new RegExp(`(^| )${e}=([^;]*)(;|$)`).exec(document.cookie);return t?t[2]:""},p=()=>{const e={};return document.cookie?(document.cookie.split(";").forEach((t=>{const[s,i]=t.split("=");e[s]=i})),e):e},g=(e,t)=>{document.cookie=`${e}=${t}`},f=async e=>{await new Promise((t=>{let s=setTimeout((()=>{t(),clearTimeout(s),s=null}),e)}))};class m{name;version;indexedDB=self.indexedDB;tables;db;transaction;constructor(e,t,s){this.name=e,this.version=t,this.tables=s}open(){return new Promise(((e,t)=>{const s=this.indexedDB?.open(this.name,this.version);s.onupgradeneeded=async e=>{const t=e.target.result;this.transaction=e.target.transaction,this.transaction.oncomplete=async()=>{this.transaction=null;for(const e of this.tables)e.default&&await this.put(e.name,e.default)};for(const e of this.tables)t.objectStoreNames.contains(e.name)||t.createObjectStore(e.name,e.options||{keyPath:"_id",autoIncrement:!0});this.db=t},s.onsuccess=()=>{this.db||(this.db=s.result),e("success")},s.onerror=e=>{console.error("indexed db connect error: ",e),t(e)}}))}createTransaction(e){return(t,...s)=>new Promise(((i,n)=>{if(!this.db)return void n("not connect");const o=this.db.transaction([t],"readwrite").objectStore(t),r=e(o,...s);r.onerror=function(e){n(e)},r.onsuccess=function(){i(r.result)}}))}get=this.createTransaction(((e,t)=>e.get(t)));getAll=this.createTransaction((e=>e.getAll()));delete=this.createTransaction(((e,t)=>e.delete(t)));put=this.createTransaction(((e,t)=>e.put(t)))}class v{utils;store;constructor(e,t){this.utils=e,this.store=t}async getState(){return this.utils.get(this.store,1)}setState(e){this.utils.put(this.store,{...e,_id:1})}async merge(e){const t=await this.getState();this.setState={...t,...e,_id:1}}}class y{name;version;utils;_cache={};tables=[];connected=!1;connecting=!1;constructor({name:e,version:t,tables:s}){this.name=e,this.version=t,this.tables=s??[]}register(e){this.tables.push(...e)}async connect(){if(!this.connected)if(this.connecting)for(;!this.connecting;)await f(100);else this.connecting=!0,this.utils=new m(this.name,this.version,this.tables),await this.utils.open(),this.connected=!0,this.connecting=!1}get(e){return!this._cache[e]&&this.utils&&(this._cache[e]=new v(this.utils,e)),this._cache[e]}}return t})()));
package/es/dom/drag.js CHANGED
@@ -1,95 +1,80 @@
1
1
  /**
2
2
  * Class for handling drag events in a UI.
3
3
  */
4
- export var DragMethod = /*#__PURE__*/function () {
5
- function DragMethod(_temp) {
6
- var _ref = _temp === void 0 ? {} : _temp,
7
- _ref$key = _ref.key,
8
- key = _ref$key === void 0 ? '' : _ref$key,
9
- onMove = _ref.onMove,
10
- onMoveEnd = _ref.onMoveEnd;
11
- this.key = '';
12
- this.cache = {
13
- pageX: 0,
14
- pageY: 0,
15
- dragging: false
16
- };
17
- this.onMouseMove = void 0;
18
- this.onMouseUp = void 0;
19
- this.onMouseDown = void 0;
20
- this.onTouchStart = void 0;
21
- this.onMove = void 0;
22
- this.onMoveEnd = void 0;
23
- this.key = key;
24
- this.onMouseDown = this._onMouseDown.bind(this);
25
- this.onTouchStart = this._onMouseDown.bind(this);
26
- this.onMouseMove = this._onMouseMove.bind(this);
27
- this.onMouseUp = this._onMouseUp.bind(this);
28
- this.onMove = onMove;
29
- this.onMoveEnd = onMoveEnd;
30
- }
31
- var _proto = DragMethod.prototype;
32
- _proto._onMouseMove = function _onMouseMove(e) {
33
- var _e$pageX, _e$touches$, _e$pageY, _e$touches$2;
34
- if (typeof this.onMove !== 'function') {
35
- return;
4
+ export class DragMethod {
5
+ key = '';
6
+ cache = { pageX: 0, pageY: 0, dragging: false };
7
+ onMouseMove;
8
+ onMouseUp;
9
+ onMouseDown;
10
+ onTouchStart;
11
+ onMove;
12
+ onMoveEnd;
13
+ constructor({ key = '', onMove, onMoveEnd } = {}) {
14
+ this.key = key;
15
+ this.onMouseDown = this._onMouseDown.bind(this);
16
+ this.onTouchStart = this._onMouseDown.bind(this);
17
+ this.onMouseMove = this._onMouseMove.bind(this);
18
+ this.onMouseUp = this._onMouseUp.bind(this);
19
+ this.onMove = onMove;
20
+ this.onMoveEnd = onMoveEnd;
36
21
  }
37
- if (e.preventDefault) {
38
- e.preventDefault();
39
- } else {
40
- e.returnValue = false;
22
+ _onMouseMove(e) {
23
+ if (typeof this.onMove !== 'function') {
24
+ return;
25
+ }
26
+ if (e.preventDefault) {
27
+ e.preventDefault();
28
+ }
29
+ else {
30
+ e.returnValue = false;
31
+ }
32
+ const pageX = e.pageX ?? e.touches[0]?.pageX;
33
+ const pageY = e.pageY ?? e.touches[0]?.pageY;
34
+ this.onMove({
35
+ offsetX: pageX - this.cache.pageX,
36
+ offsetY: pageY - this.cache.pageY,
37
+ pageX,
38
+ pageY,
39
+ startX: this.cache.pageX,
40
+ startY: this.cache.pageY,
41
+ key: this.key,
42
+ });
43
+ this.cache.pageX = pageX;
44
+ this.cache.pageY = pageY;
41
45
  }
42
- var pageX = (_e$pageX = e.pageX) != null ? _e$pageX : (_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.pageX;
43
- var pageY = (_e$pageY = e.pageY) != null ? _e$pageY : (_e$touches$2 = e.touches[0]) == null ? void 0 : _e$touches$2.pageY;
44
- this.onMove({
45
- offsetX: pageX - this.cache.pageX,
46
- offsetY: pageY - this.cache.pageY,
47
- pageX: pageX,
48
- pageY: pageY,
49
- startX: this.cache.pageX,
50
- startY: this.cache.pageY,
51
- key: this.key
52
- });
53
- this.cache.pageX = pageX;
54
- this.cache.pageY = pageY;
55
- };
56
- _proto.clearListener = function clearListener() {
57
- window.removeEventListener('mousemove', this.onMouseMove);
58
- window.removeEventListener('touchmove', this.onMouseMove);
59
- window.removeEventListener('mouseup', this.onMouseUp);
60
- window.removeEventListener('touchend', this.onMouseUp);
61
- };
62
- _proto._onMouseUp = function _onMouseUp() {
63
- this.clearListener();
64
- this.cache.dragging = false;
65
- if (typeof this.onMoveEnd === 'function') {
66
- this.onMoveEnd();
46
+ clearListener() {
47
+ window.removeEventListener('mousemove', this.onMouseMove);
48
+ window.removeEventListener('touchmove', this.onMouseMove);
49
+ window.removeEventListener('mouseup', this.onMouseUp);
50
+ window.removeEventListener('touchend', this.onMouseUp);
67
51
  }
68
- };
69
- _proto._onMouseDown = function _onMouseDown(e) {
70
- var _e$pageX2, _e$touches$3, _e$pageY2, _e$touches$4;
71
- if (e.preventDefault && e.pageX) {
72
- e.preventDefault();
73
- } else {
74
- e.returnValue = false;
52
+ _onMouseUp() {
53
+ this.clearListener();
54
+ this.cache.dragging = false;
55
+ if (typeof this.onMoveEnd === 'function') {
56
+ this.onMoveEnd();
57
+ }
75
58
  }
76
- if (typeof this.onMove !== 'function' || this.cache.dragging) {
77
- return;
59
+ _onMouseDown(e) {
60
+ if (e.preventDefault && e.pageX) {
61
+ e.preventDefault();
62
+ }
63
+ else {
64
+ e.returnValue = false;
65
+ }
66
+ if (typeof this.onMove !== 'function' || this.cache.dragging) {
67
+ return;
68
+ }
69
+ this.clearListener();
70
+ const pageX = e.pageX ?? e.touches[0]?.pageX;
71
+ const pageY = e.pageY ?? e.touches[0]?.pageY;
72
+ this.cache.dragging = true;
73
+ this.cache.pageX = pageX;
74
+ this.cache.pageY = pageY;
75
+ window.addEventListener('mousemove', this.onMouseMove);
76
+ window.addEventListener('touchmove', this.onMouseMove, { passive: false });
77
+ window.addEventListener('mouseup', this.onMouseUp);
78
+ window.addEventListener('touchend', this.onMouseUp, { passive: false });
78
79
  }
79
- this.clearListener();
80
- var pageX = (_e$pageX2 = e.pageX) != null ? _e$pageX2 : (_e$touches$3 = e.touches[0]) == null ? void 0 : _e$touches$3.pageX;
81
- var pageY = (_e$pageY2 = e.pageY) != null ? _e$pageY2 : (_e$touches$4 = e.touches[0]) == null ? void 0 : _e$touches$4.pageY;
82
- this.cache.dragging = true;
83
- this.cache.pageX = pageX;
84
- this.cache.pageY = pageY;
85
- window.addEventListener('mousemove', this.onMouseMove);
86
- window.addEventListener('touchmove', this.onMouseMove, {
87
- passive: false
88
- });
89
- window.addEventListener('mouseup', this.onMouseUp);
90
- window.addEventListener('touchend', this.onMouseUp, {
91
- passive: false
92
- });
93
- };
94
- return DragMethod;
95
- }();
80
+ }
@@ -1,12 +1,12 @@
1
- export var downloadFile = function downloadFile(uri, name) {
2
- var a = document.createElement('a');
3
- a.href = uri;
4
- if (name) {
5
- a.download = name;
6
- }
7
- a.style.position = 'fixed';
8
- a.style.visibility = 'hidden';
9
- document.body.appendChild(a);
10
- a.click();
11
- document.body.removeChild(a);
12
- };
1
+ export const downloadFile = (uri, name) => {
2
+ const a = document.createElement('a');
3
+ a.href = uri;
4
+ if (name) {
5
+ a.download = name;
6
+ }
7
+ a.style.position = 'fixed';
8
+ a.style.visibility = 'hidden';
9
+ document.body.appendChild(a);
10
+ a.click();
11
+ document.body.removeChild(a);
12
+ };
package/es/file/parser.js CHANGED
@@ -1,30 +1,23 @@
1
- export var blob2text = function blob2text(blob) {
2
- return new Promise(function (resolve) {
3
- var reader = new FileReader();
4
- reader.onload = function (e) {
5
- return resolve(e.target.result);
6
- };
7
- reader.readAsText(blob);
8
- });
1
+ export const blob2text = (blob) => {
2
+ return new Promise((resolve) => {
3
+ const reader = new FileReader();
4
+ reader.onload = (e) => resolve(e.target.result);
5
+ reader.readAsText(blob);
6
+ });
9
7
  };
10
- export var blob2base64 = function blob2base64(blob) {
11
- return new Promise(function (resolve, reject) {
12
- var reader = new FileReader();
13
- if (!blob) {
14
- reject('文件爲空!');
15
- } else {
16
- reader.onload = function (e) {
17
- return resolve(e.target.result);
18
- };
19
- reader.onabort = function () {
20
- return reject();
21
- };
22
- reader.readAsDataURL(blob);
23
- }
24
- });
8
+ export const blob2base64 = (blob) => {
9
+ return new Promise(function (resolve, reject) {
10
+ const reader = new FileReader();
11
+ if (!blob) {
12
+ reject('文件爲空!');
13
+ }
14
+ else {
15
+ reader.onload = (e) => resolve(e.target.result);
16
+ reader.onabort = () => reject();
17
+ reader.readAsDataURL(blob);
18
+ }
19
+ });
20
+ };
21
+ export const blob2file = (blob, name, type) => {
22
+ return new File(blob, name, { type });
25
23
  };
26
- export var blob2file = function blob2file(blob, name, type) {
27
- return new File(blob, name, {
28
- type: type
29
- });
30
- };
package/es/file/pick.js CHANGED
@@ -1,27 +1,27 @@
1
- export var pickFiles = function pickFiles() {
2
- return new Promise(function (resolve, reject) {
3
- var el = document.createElement('input');
4
- var picked = false;
5
- var onFocus = function onFocus() {
6
- document.body.removeChild(el);
7
- window.removeEventListener('focus', onFocus);
8
- setTimeout(function () {
9
- if (!picked) {
10
- reject('no files picked');
11
- }
12
- }, 1000);
13
- };
14
- el.type = 'file';
15
- el.style.visibility = 'hidden';
16
- el.style.position = 'fixed';
17
- el.style.top = '0px';
18
- el.style.zIndex = '-1';
19
- window.addEventListener('focus', onFocus);
20
- el.onchange = function (e) {
21
- picked = e.target.files.length > 0;
22
- resolve(e.target.files);
23
- };
24
- document.body.appendChild(el);
25
- el.click();
26
- });
27
- };
1
+ export const pickFiles = () => {
2
+ return new Promise((resolve, reject) => {
3
+ const el = document.createElement('input');
4
+ let picked = false;
5
+ const onFocus = () => {
6
+ document.body.removeChild(el);
7
+ window.removeEventListener('focus', onFocus);
8
+ setTimeout(() => {
9
+ if (!picked) {
10
+ reject('no files picked');
11
+ }
12
+ }, 1000);
13
+ };
14
+ el.type = 'file';
15
+ el.style.visibility = 'hidden';
16
+ el.style.position = 'fixed';
17
+ el.style.top = '0px';
18
+ el.style.zIndex = '-1';
19
+ window.addEventListener('focus', onFocus);
20
+ el.onchange = (e) => {
21
+ picked = e.target.files.length > 0;
22
+ resolve(e.target.files);
23
+ };
24
+ document.body.appendChild(el);
25
+ el.click();
26
+ });
27
+ };
package/es/index.d.ts CHANGED
@@ -5,5 +5,5 @@ export { WebStorage } from './storage';
5
5
  export { WebsocketClient } from './websocket/client';
6
6
  export { DragMethod } from './dom/drag';
7
7
  export { pickFiles } from './file/pick';
8
- export { IndexedStorage } from './storage/indexed-db/indexed-db-storage';
9
8
  export { getCookieValue, getCookie, setCookieItem } from './storage/cookie';
9
+ export { IndexedStorage } from './storage/indexed-db/indexed-db-storage';
package/es/index.js CHANGED
@@ -5,5 +5,5 @@ export { WebStorage } from './storage';
5
5
  export { WebsocketClient } from './websocket/client';
6
6
  export { DragMethod } from './dom/drag';
7
7
  export { pickFiles } from './file/pick';
8
+ export { getCookieValue, getCookie, setCookieItem } from './storage/cookie';
8
9
  export { IndexedStorage } from './storage/indexed-db/indexed-db-storage';
9
- export { getCookieValue, getCookie, setCookieItem } from './storage/cookie';
@@ -1,6 +1,3 @@
1
- function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
1
  /**
5
2
  * Loads a script from the given URL with the provided options.
6
3
  *
@@ -8,40 +5,36 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
8
5
  * @param {any} options - Additional options for loading the script
9
6
  * @return {Promise<any>} A Promise that resolves with the URL once the script is loaded
10
7
  */
11
- export var loadScript = function loadScript(url, options) {
12
- if (options === void 0) {
13
- options = {};
14
- }
15
- var findScript = function findScript() {
16
- var list = document.getElementsByTagName('script');
17
- for (var _iterator = _createForOfIteratorHelperLoose(list), _step; !(_step = _iterator()).done;) {
18
- var item = _step.value;
19
- if (item.src === url) {
20
- return item;
21
- }
22
- }
23
- return null;
24
- };
25
- return new Promise(function (resolve) {
26
- var old = findScript();
27
- var el = old;
28
- if (!old) {
29
- el = document.createElement('script');
30
- } else if (old._state === 'complete') {
31
- return resolve(url);
32
- }
33
- for (var _i = 0, _Object$keys = Object.keys(options); _i < _Object$keys.length; _i++) {
34
- var key = _Object$keys[_i];
35
- el[key] = options[key];
36
- }
37
- var onLoad = function onLoad() {
38
- resolve(url);
39
- el.removeEventListener('load', onLoad);
40
- el._state = 'complete';
8
+ export const loadScript = (url, options = {}) => {
9
+ const findScript = () => {
10
+ const list = document.getElementsByTagName('script');
11
+ for (const item of list) {
12
+ if (item.src === url) {
13
+ return item;
14
+ }
15
+ }
16
+ return null;
41
17
  };
42
- el.src = url;
43
- el.addEventListener('load', onLoad);
44
- document.body.appendChild(el);
45
- return 'success';
46
- });
47
- };
18
+ return new Promise((resolve) => {
19
+ const old = findScript();
20
+ let el = old;
21
+ if (!old) {
22
+ el = document.createElement('script');
23
+ }
24
+ else if (old._state === 'complete') {
25
+ return resolve(url);
26
+ }
27
+ for (const key of Object.keys(options)) {
28
+ el[key] = options[key];
29
+ }
30
+ const onLoad = () => {
31
+ resolve(url);
32
+ el.removeEventListener('load', onLoad);
33
+ el._state = 'complete';
34
+ };
35
+ el.src = url;
36
+ el.addEventListener('load', onLoad);
37
+ document.body.appendChild(el);
38
+ return 'success';
39
+ });
40
+ };
@@ -1,22 +1,20 @@
1
- export var getCookieValue = function getCookieValue(key) {
2
- var reg = new RegExp("(^| )" + key + "=([^;]*)(;|$)");
3
- var res = reg.exec(document.cookie);
4
- return res ? res[2] : '';
1
+ export const getCookieValue = (key) => {
2
+ const reg = new RegExp(`(^| )${key}=([^;]*)(;|$)`);
3
+ const res = reg.exec(document.cookie);
4
+ return res ? res[2] : '';
5
5
  };
6
- export var getCookie = function getCookie() {
7
- var res = {};
8
- if (!document.cookie) {
6
+ export const getCookie = () => {
7
+ const res = {};
8
+ if (!document.cookie) {
9
+ return res;
10
+ }
11
+ const tmp = document.cookie.split(';');
12
+ tmp.forEach((item) => {
13
+ const [key, value] = item.split('=');
14
+ res[key] = value;
15
+ });
9
16
  return res;
10
- }
11
- var tmp = document.cookie.split(';');
12
- tmp.forEach(function (item) {
13
- var _item$split = item.split('='),
14
- key = _item$split[0],
15
- value = _item$split[1];
16
- res[key] = value;
17
- });
18
- return res;
19
17
  };
20
- export var setCookieItem = function setCookieItem(key, value) {
21
- document.cookie = key + "=" + value;
22
- };
18
+ export const setCookieItem = (key, value) => {
19
+ document.cookie = `${key}=${value}`;
20
+ };
@@ -1,53 +1,40 @@
1
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
3
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
5
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
6
- export var WebStorage = /*#__PURE__*/function () {
7
- function WebStorage(props) {
8
- this._key = void 0;
9
- this.storage = void 0;
10
- this.zip = void 0;
11
- var _props$type = props.type,
12
- type = _props$type === void 0 ? 'sessionStorage' : _props$type,
13
- key = props.key;
14
- this._key = key;
15
- this.storage = window[type];
16
- this.zip = props.zip;
17
- }
18
- var _proto = WebStorage.prototype;
19
- _proto.merge = function merge(data) {
20
- var old = this.state;
21
- this.state = _extends({}, old, data);
22
- };
23
- _proto.clear = function clear() {
24
- this.storage.removeItem(this._key);
25
- };
26
- _createClass(WebStorage, [{
27
- key: "state",
28
- get: function get() {
29
- var value = this.storage.getItem(this._key);
30
- if (this.zip && value) {
31
- value = this.zip.inflate(value);
32
- }
33
- if (value) {
34
- return JSON.parse(value);
35
- } else {
36
- return null;
37
- }
38
- },
39
- set: function set(data) {
40
- var temp = JSON.stringify(data);
41
- if (this.zip) {
42
- temp = this.zip.deflate(temp);
43
- }
44
- this.storage.setItem(this._key, temp);
1
+ export class WebStorage {
2
+ _key;
3
+ storage;
4
+ zip;
5
+ constructor(props) {
6
+ const { type = 'sessionStorage', key } = props;
7
+ this._key = key;
8
+ this.storage = window[type];
9
+ this.zip = props.zip;
45
10
  }
46
- }, {
47
- key: "key",
48
- get: function get() {
49
- return this._key;
11
+ get state() {
12
+ let value = this.storage.getItem(this._key);
13
+ if (this.zip && value) {
14
+ value = this.zip.inflate(value);
15
+ }
16
+ if (value) {
17
+ return JSON.parse(value);
18
+ }
19
+ else {
20
+ return null;
21
+ }
50
22
  }
51
- }]);
52
- return WebStorage;
53
- }();
23
+ set state(data) {
24
+ let temp = JSON.stringify(data);
25
+ if (this.zip) {
26
+ temp = this.zip.deflate(temp);
27
+ }
28
+ this.storage.setItem(this._key, temp);
29
+ }
30
+ get key() {
31
+ return this._key;
32
+ }
33
+ merge(data) {
34
+ const old = this.state;
35
+ this.state = { ...old, ...data };
36
+ }
37
+ clear() {
38
+ this.storage.removeItem(this._key);
39
+ }
40
+ }