pubo-web 1.0.78 → 1.0.80

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 o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},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={};t.r(e),t.d(e,{DragMethod:()=>g,WebStorage:()=>u,WebsocketClient:()=>p,blob2base64:()=>r,blob2file:()=>s,blob2text:()=>i,downloadFile:()=>a,loadScript:()=>o,pickFiles:()=>m});var n=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],o=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},o=function(t,e){return void 0===e&&(e={}),new Promise((function(o){var i,r,s=function(){var e,o,i=document.getElementsByTagName("script");try{for(var r=n(i),s=r.next();!s.done;s=r.next()){var a=s.value;if(a.src===t)return a}}catch(t){e={error:t}}finally{try{s&&!s.done&&(o=r.return)&&o.call(r)}finally{if(e)throw e.error}}return null}(),a=s;if(s){if("complete"===s._state)return o(t)}else a=document.createElement("script");try{for(var c=n(Object.keys(e)),u=c.next();!u.done;u=c.next()){var l=u.value;a[l]=e[l]}}catch(t){i={error:t}}finally{try{u&&!u.done&&(r=c.return)&&r.call(c)}finally{if(i)throw i.error}}return a.src=t,a.addEventListener("load",(function e(){o(t),a.removeEventListener("load",e),a._state="complete"})),document.body.appendChild(a),"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)}))},r=function(t){return new Promise((function(e,n){var o=new FileReader;t?(o.onload=function(t){return e(t.target.result)},o.onabort=function(){return n()},o.readAsDataURL(t)):n("文件爲空!")}))},s=function(t,e,n){return new File(t,e,{type:n})},a=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)},c=function(){return c=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},c.apply(this,arguments)},u=function(){function t(t){var e=t.type,n=void 0===e?"sessionStorage":e,o=t.key;this._key=o,this.storage=window[n],this.zip=t.zip}return Object.defineProperty(t.prototype,"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)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"key",{get:function(){return this._key},enumerable:!1,configurable:!0}),t.prototype.merge=function(t){var e=this.state;this.state=c(c({},e),t)},t.prototype.clear=function(){this.storage.removeItem(this._key)},t}(),l=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],o=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},f=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,i,r=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s},h=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(f(arguments[e]));return t},d=function(){function t(){this.state={},this.ids={}}return t.prototype.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,o=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="",o=0;o<=t;o+=8)n+=e(t-o>8?8:t-o);return n}(40);return this.ids[o]={event:t,index:n},o},t.prototype.cancel=function(t){var e=this;if(t){var n=this.ids[t]||{},o=n.event,i=n.index;o&&Array.isArray(this.state[o])&&(this.state[o].splice(i,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){e.ids[t].event===o&&e.ids[t].index>i&&(e.ids[t].index=e.ids[t].index-1)})))}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t){for(var e,n,o=[],i=1;i<arguments.length;i++)o[i-1]=arguments[i];if(Array.isArray(this.state[t]))try{for(var r=l(this.state[t]),s=r.next();!s.done;s=r.next()){var a=s.value;"function"==typeof a&&a.apply(void 0,h(o))}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},t}();const p=function(){function t(t){var e=t.url;this.client=null,this._status=0,this.emitter=new d,this.url=e,this.connect()}return t.prototype.reconnect=function(){var t=this;this.client&&this.client.close(),this.client=null,3===this._status&&setTimeout((function(){return t.connect()}),1e3)},t.prototype.onClose=function(){2!==this._status&&(this._status=3),this.reconnect()},t.prototype.onMessage=function(t){this.emitter.emit("message",t.data)},t.prototype.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._status=1})},t.prototype.close=function(){this.client&&(this.client.close(),this.client=null,this._status=2)},t.prototype.send=function(t,e){var n;void 0===e&&(e=!1);var o=t;e&&(o=JSON.stringify(t)),null===(n=this.client)||void 0===n||n.send(o)},t}();var y=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,i,r=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s},v=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(y(arguments[e]));return t},g=function(){function t(t){var e,n,o,i,r=void 0===t?{}:t,s=r.key,a=void 0===s?"":s,c=r.onMove,u=r.onMoveEnd;this.key="",this.cache={pageX:0,pageY:0,dragging:!1},this.key=a,this.onMouseDown=this._onMouseDown.bind(this),this.onMouseMove=(e=this._onMouseMove.bind(this),n=10,i=!0,function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];o||(o=setTimeout((function(){i=!0,o=null}),n)),i&&(i=!1,e.apply(void 0,v(t)))}),this.onMouseUp=this._onMouseUp.bind(this),this.onMove=c,this.onMoveEnd=u}return t.prototype._onMouseMove=function(t){"function"==typeof this.onMove&&(this.onMove({offsetX:t.pageX-this.cache.pageX,offsetY:t.pageY-this.cache.pageY,key:this.key}),this.cache.pageX=t.pageX,this.cache.pageY=t.pageY)},t.prototype.clearListener=function(){window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("mouseup",this.onMouseUp)},t.prototype._onMouseUp=function(){this.clearListener(),this.cache.dragging=!1,"function"==typeof this.onMoveEnd&&this.onMoveEnd()},t.prototype._onMouseDown=function(t){t.preventDefault?t.preventDefault():t.returnValue=!1,"function"!=typeof this.onMove||this.cache.dragging||(this.clearListener(),this.cache.dragging=!0,this.cache.pageX=t.pageX,this.cache.pageY=t.pageY,window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("mouseup",this.onMouseUp))},t}(),m=function(){return new Promise((function(t){var e=document.createElement("input");e.type="file",e.style.visibility="hidden",e.style.position="fixed",e.style.top="0px",e.style.zIndex="-1",window.addEventListener("focus",(function t(){document.body.removeChild(e),window.removeEventListener("focus",t)})),e.onchange=function(e){t(e.target.files)},document.body.appendChild(e),e.click()}))};return e})()));
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={};t.r(e),t.d(e,{DragMethod:()=>b,IndexedStorage:()=>T,WebStorage:()=>u,WebsocketClient:()=>d,blob2base64:()=>i,blob2file:()=>a,blob2text:()=>o,downloadFile:()=>c,getCookieValue:()=>P,loadScript:()=>r,pickFiles:()=>g});var n=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},r=function(t,e){return void 0===e&&(e={}),new Promise((function(r){var o,i,a=function(){var e,r,o=document.getElementsByTagName("script");try{for(var i=n(o),a=i.next();!a.done;a=i.next()){var c=a.value;if(c.src===t)return c}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return null}(),c=a;if(a){if("complete"===a._state)return r(t)}else c=document.createElement("script");try{for(var s=n(Object.keys(e)),u=s.next();!u.done;u=s.next()){var l=u.value;c[l]=e[l]}}catch(t){o={error:t}}finally{try{u&&!u.done&&(i=s.return)&&i.call(s)}finally{if(o)throw o.error}}return c.src=t,c.addEventListener("load",(function e(){r(t),c.removeEventListener("load",e),c._state="complete"})),document.body.appendChild(c),"success"}))},o=function(t){return new Promise((function(e){var n=new FileReader;n.onload=function(t){return e(t.target.result)},n.readAsText(t)}))},i=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("文件爲空!")}))},a=function(t,e,n){return new File(t,e,{type:n})},c=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)},s=function(){return s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},s.apply(this,arguments)},u=function(){function t(t){var e=t.type,n=void 0===e?"sessionStorage":e,r=t.key;this._key=r,this.storage=window[n],this.zip=t.zip}return Object.defineProperty(t.prototype,"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)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"key",{get:function(){return this._key},enumerable:!1,configurable:!0}),t.prototype.merge=function(t){var e=this.state;this.state=s(s({},e),t)},t.prototype.clear=function(){this.storage.removeItem(this._key)},t}(),l=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},f=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},h=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},p=function(){function t(){this.state={},this.ids={}}return t.prototype.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},t.prototype.cancel=function(t){var e=this;if(t){var n=this.ids[t]||{},r=n.event,o=n.index;r&&Array.isArray(this.state[r])&&(this.state[r].splice(o,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){e.ids[t].event===r&&e.ids[t].index>o&&(e.ids[t].index=e.ids[t].index-1)})))}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t){for(var e,n,r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];if(Array.isArray(this.state[t]))try{for(var i=l(this.state[t]),a=i.next();!a.done;a=i.next()){var c=a.value;"function"==typeof c&&c.apply(void 0,h([],f(r),!1))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},t}();const d=function(){function t(t){var e=t.url;this.client=null,this._status=0,this.emitter=new p,this.url=e,this.connect()}return t.prototype.reconnect=function(){var t=this;this.client&&this.client.close(),this.client=null,3===this._status&&setTimeout((function(){return t.connect()}),1e3)},t.prototype.onClose=function(){2!==this._status&&(this._status=3),this.reconnect()},t.prototype.onMessage=function(t){this.emitter.emit("message",t.data)},t.prototype.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._status=1})},t.prototype.close=function(){this.client&&(this.client.close(),this.client=null,this._status=2)},t.prototype.send=function(t,e){var n;void 0===e&&(e=!1);var r=t;e&&(r=JSON.stringify(t)),null===(n=this.client)||void 0===n||n.send(r)},t}();var y=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},v=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},b=function(){function t(t){var e,n,r,o,i=void 0===t?{}:t,a=i.key,c=void 0===a?"":a,s=i.onMove,u=i.onMoveEnd;this.key="",this.cache={pageX:0,pageY:0,dragging:!1},this.key=c,this.onMouseDown=this._onMouseDown.bind(this),this.onMouseMove=(e=this._onMouseMove.bind(this),n=10,o=!0,function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];r||(r=setTimeout((function(){o=!0,r=null}),n)),o&&(o=!1,e.apply(void 0,v([],y(t),!1)))}),this.onMouseUp=this._onMouseUp.bind(this),this.onMove=s,this.onMoveEnd=u}return t.prototype._onMouseMove=function(t){"function"==typeof this.onMove&&(this.onMove({offsetX:t.pageX-this.cache.pageX,offsetY:t.pageY-this.cache.pageY,key:this.key}),this.cache.pageX=t.pageX,this.cache.pageY=t.pageY)},t.prototype.clearListener=function(){window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("mouseup",this.onMouseUp)},t.prototype._onMouseUp=function(){this.clearListener(),this.cache.dragging=!1,"function"==typeof this.onMoveEnd&&this.onMoveEnd()},t.prototype._onMouseDown=function(t){t.preventDefault?t.preventDefault():t.returnValue=!1,"function"!=typeof this.onMove||this.cache.dragging||(this.clearListener(),this.cache.dragging=!0,this.cache.pageX=t.pageX,this.cache.pageY=t.pageY,window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("mouseup",this.onMouseUp))},t}(),g=function(){return new Promise((function(t){var e=document.createElement("input");e.type="file",e.style.visibility="hidden",e.style.position="fixed",e.style.top="0px",e.style.zIndex="-1",window.addEventListener("focus",(function t(){document.body.removeChild(e),window.removeEventListener("focus",t)})),e.onchange=function(e){t(e.target.files)},document.body.appendChild(e),e.click()}))},m=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function c(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}s((r=r.apply(t,e||[])).next())}))},w=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=e.call(t,a)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}},x=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},S=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},k=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},M=function(){function t(t,e,n){this.indexedDB=self.indexedDB,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}return t.prototype.open=function(){var t=this;return new Promise((function(e,n){var r,o=null===(r=t.indexedDB)||void 0===r?void 0:r.open(t.name,t.version);o.onupgradeneeded=function(n){return m(t,void 0,void 0,(function(){var t,r,o,i,a,c=this;return w(this,(function(s){this.db=n.target.result,this.transaction=n.target.transaction,this.transaction.oncomplete=function(){return m(c,void 0,void 0,(function(){var t,e,n,r,o,i;return w(this,(function(a){switch(a.label){case 0:this.transaction=null,a.label=1;case 1:a.trys.push([1,6,7,8]),t=x(this.tables),e=t.next(),a.label=2;case 2:return e.done?[3,5]:(n=e.value).default?[4,this.put(n.name,n.default)]:[3,4];case 3:a.sent(),a.label=4;case 4:return e=t.next(),[3,2];case 5:return[3,8];case 6:return r=a.sent(),o={error:r},[3,8];case 7:try{e&&!e.done&&(i=t.return)&&i.call(t)}finally{if(o)throw o.error}return[7];case 8:return[2]}}))}))};try{for(t=x(this.tables),r=t.next();!r.done;r=t.next())o=r.value,this.createTable(o)}catch(t){i={error:t}}finally{try{r&&!r.done&&(a=t.return)&&a.call(t)}finally{if(i)throw i.error}}return e("success"),[2]}))}))},o.onsuccess=function(){t.db=o.result,e("success")},o.onerror=function(t){console.error("indexed db connect error: ",t),n(t)}}))},t.prototype.createTable=function(t){this.db.objectStoreNames.contains(t.name)||this.db.createObjectStore(t.name,t.options||{keyPath:"_id",autoIncrement:!0})},t.prototype.createTransaction=function(t){var e=this;return function(n){for(var r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];return new Promise((function(o,i){if(e.db){var a=e.db.transaction([n],"readwrite").objectStore(n),c=t.apply(void 0,k([a],S(r),!1));c.onerror=function(t){i(t)},c.onsuccess=function(){o(c.result)}}else i("not connect")}))}},t}(),_=function(){return _=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},_.apply(this,arguments)},E=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function c(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}s((r=r.apply(t,e||[])).next())}))},O=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=e.call(t,a)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}},j=function(){function t(t,e){this.utils=t,this.store=e}return t.prototype.getState=function(){return E(this,void 0,void 0,(function(){return O(this,(function(t){return[2,this.utils.get(this.store,1)]}))}))},t.prototype.setState=function(t){this.utils.put(this.store,_(_({},t),{_id:1}))},t.prototype.merge=function(t){return E(this,void 0,void 0,(function(){var e;return O(this,(function(n){switch(n.label){case 0:return[4,this.getState()];case 1:return e=n.sent(),this.setState=_(_(_({},e),t),{_id:1}),[2]}}))}))},t}(),T=function(){function t(t){var e=t.name,n=t.version,r=t.tables;this._cache={},this.tables=[],this.connected=!1,this.connecting=!1,this.name=e,this.version=n,this.tables=null!=r?r:[]}return t.prototype.register=function(t){var e;(e=this.tables).push.apply(e,function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}(t),!1))},t.prototype.connect=function(){return E(this,void 0,void 0,(function(){return O(this,(function(t){switch(t.label){case 0:if(this.connected)return[2];if(!this.connecting)return[3,4];t.label=1;case 1:return this.connecting?[3,3]:[4,(100,e=void 0,n=void 0,r=void 0,o=function(){return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=e.call(t,a)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}}(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t){return setTimeout((function(){return t()}),100)}))];case 1:return t.sent(),[2]}}))},new(r||(r=Promise))((function(t,i){function a(t){try{s(o.next(t))}catch(t){i(t)}}function c(t){try{s(o.throw(t))}catch(t){i(t)}}function s(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(t){t(n)}))).then(a,c)}s((o=o.apply(e,n||[])).next())})))];case 2:return t.sent(),[3,1];case 3:return[2];case 4:return this.connecting=!0,this.utils=new M(this.name,this.version,this.tables),[4,this.utils.open()];case 5:return t.sent(),this.connected=!0,this.connecting=!1,[2]}var e,n,r,o}))}))},t.prototype.get=function(t){return!this._cache[t]&&this.utils&&(this._cache[t]=new j(this.utils,t)),this._cache[t]},t}(),P=function(t){var e=new RegExp("(^| )".concat(t,"=([^;]*)(;|$)")).exec(document.cookie);return e?e[2]:""};return e})()));
package/es/index.d.ts CHANGED
@@ -5,3 +5,5 @@ export { WebStorage } from './storage';
5
5
  export { default as 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
+ export { getCookieValue } from './storage/cookie';
package/es/index.js CHANGED
@@ -4,4 +4,6 @@ export { downloadFile } from './file/download';
4
4
  export { WebStorage } from './storage';
5
5
  export { default as WebsocketClient } from './websocket/client';
6
6
  export { DragMethod } from './dom/drag';
7
- export { pickFiles } from './file/pick';
7
+ export { pickFiles } from './file/pick';
8
+ export { IndexedStorage } from './storage/indexed-db/indexed-db-storage';
9
+ export { getCookieValue } from './storage/cookie';
@@ -0,0 +1 @@
1
+ export declare const getCookieValue: (key: string) => string;
@@ -0,0 +1,5 @@
1
+ export var getCookieValue = function getCookieValue(key) {
2
+ var reg = new RegExp("(^| )".concat(key, "=([^;]*)(;|$)"));
3
+ var res = reg.exec(document.cookie);
4
+ return res ? res[2] : '';
5
+ };
@@ -0,0 +1,27 @@
1
+ import { IndexedDBUtils, IndexedTable } from './indexed-db-utils';
2
+ export declare class Storage {
3
+ private readonly utils;
4
+ private readonly store;
5
+ constructor(utils: IndexedDBUtils, store: string);
6
+ getState(): Promise<any>;
7
+ setState(values: any): void;
8
+ merge(values: any): Promise<void>;
9
+ }
10
+ export interface StorageFactoryType {
11
+ name: string;
12
+ version: number;
13
+ tables?: IndexedTable[];
14
+ }
15
+ export declare class IndexedStorage {
16
+ private readonly name;
17
+ private readonly version;
18
+ utils: IndexedDBUtils;
19
+ private _cache;
20
+ private readonly tables;
21
+ private connected;
22
+ private connecting;
23
+ constructor({ name, version, tables }: StorageFactoryType);
24
+ register(tables: IndexedTable[]): void;
25
+ connect(): Promise<void>;
26
+ get(store: string): Storage;
27
+ }
@@ -0,0 +1,255 @@
1
+ var __assign = this && this.__assign || function () {
2
+ __assign = Object.assign || function (t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
6
+ }
7
+ return t;
8
+ };
9
+ return __assign.apply(this, arguments);
10
+ };
11
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) {
13
+ return value instanceof P ? value : new P(function (resolve) {
14
+ resolve(value);
15
+ });
16
+ }
17
+ return new (P || (P = Promise))(function (resolve, reject) {
18
+ function fulfilled(value) {
19
+ try {
20
+ step(generator.next(value));
21
+ } catch (e) {
22
+ reject(e);
23
+ }
24
+ }
25
+ function rejected(value) {
26
+ try {
27
+ step(generator["throw"](value));
28
+ } catch (e) {
29
+ reject(e);
30
+ }
31
+ }
32
+ function step(result) {
33
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
34
+ }
35
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
36
+ });
37
+ };
38
+ var __generator = this && this.__generator || function (thisArg, body) {
39
+ var _ = {
40
+ label: 0,
41
+ sent: function sent() {
42
+ if (t[0] & 1) throw t[1];
43
+ return t[1];
44
+ },
45
+ trys: [],
46
+ ops: []
47
+ },
48
+ f,
49
+ y,
50
+ t,
51
+ g;
52
+ return g = {
53
+ next: verb(0),
54
+ "throw": verb(1),
55
+ "return": verb(2)
56
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
57
+ return this;
58
+ }), g;
59
+ function verb(n) {
60
+ return function (v) {
61
+ return step([n, v]);
62
+ };
63
+ }
64
+ function step(op) {
65
+ if (f) throw new TypeError("Generator is already executing.");
66
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
67
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
68
+ if (y = 0, t) op = [op[0] & 2, t.value];
69
+ switch (op[0]) {
70
+ case 0:
71
+ case 1:
72
+ t = op;
73
+ break;
74
+ case 4:
75
+ _.label++;
76
+ return {
77
+ value: op[1],
78
+ done: false
79
+ };
80
+ case 5:
81
+ _.label++;
82
+ y = op[1];
83
+ op = [0];
84
+ continue;
85
+ case 7:
86
+ op = _.ops.pop();
87
+ _.trys.pop();
88
+ continue;
89
+ default:
90
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
91
+ _ = 0;
92
+ continue;
93
+ }
94
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
95
+ _.label = op[1];
96
+ break;
97
+ }
98
+ if (op[0] === 6 && _.label < t[1]) {
99
+ _.label = t[1];
100
+ t = op;
101
+ break;
102
+ }
103
+ if (t && _.label < t[2]) {
104
+ _.label = t[2];
105
+ _.ops.push(op);
106
+ break;
107
+ }
108
+ if (t[2]) _.ops.pop();
109
+ _.trys.pop();
110
+ continue;
111
+ }
112
+ op = body.call(thisArg, _);
113
+ } catch (e) {
114
+ op = [6, e];
115
+ y = 0;
116
+ } finally {
117
+ f = t = 0;
118
+ }
119
+ if (op[0] & 5) throw op[1];
120
+ return {
121
+ value: op[0] ? op[1] : void 0,
122
+ done: true
123
+ };
124
+ }
125
+ };
126
+ var __read = this && this.__read || function (o, n) {
127
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
128
+ if (!m) return o;
129
+ var i = m.call(o),
130
+ r,
131
+ ar = [],
132
+ e;
133
+ try {
134
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
135
+ } catch (error) {
136
+ e = {
137
+ error: error
138
+ };
139
+ } finally {
140
+ try {
141
+ if (r && !r.done && (m = i["return"])) m.call(i);
142
+ } finally {
143
+ if (e) throw e.error;
144
+ }
145
+ }
146
+ return ar;
147
+ };
148
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
149
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
150
+ if (ar || !(i in from)) {
151
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
152
+ ar[i] = from[i];
153
+ }
154
+ }
155
+ return to.concat(ar || Array.prototype.slice.call(from));
156
+ };
157
+ import { sleep } from 'pubo-utils';
158
+ import { IndexedDBUtils } from './indexed-db-utils';
159
+ var Storage = /** @class */function () {
160
+ function Storage(utils, store) {
161
+ this.utils = utils;
162
+ this.store = store;
163
+ }
164
+ Storage.prototype.getState = function () {
165
+ return __awaiter(this, void 0, void 0, function () {
166
+ return __generator(this, function (_a) {
167
+ return [2 /*return*/, this.utils.get(this.store, 1)];
168
+ });
169
+ });
170
+ };
171
+ Storage.prototype.setState = function (values) {
172
+ this.utils.put(this.store, __assign(__assign({}, values), {
173
+ _id: 1
174
+ }));
175
+ };
176
+ Storage.prototype.merge = function (values) {
177
+ return __awaiter(this, void 0, void 0, function () {
178
+ var state;
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0:
182
+ return [4 /*yield*/, this.getState()];
183
+ case 1:
184
+ state = _a.sent();
185
+ this.setState = __assign(__assign(__assign({}, state), values), {
186
+ _id: 1
187
+ });
188
+ return [2 /*return*/];
189
+ }
190
+ });
191
+ });
192
+ };
193
+
194
+ return Storage;
195
+ }();
196
+ export { Storage };
197
+ var IndexedStorage = /** @class */function () {
198
+ function IndexedStorage(_a) {
199
+ var name = _a.name,
200
+ version = _a.version,
201
+ tables = _a.tables;
202
+ this._cache = {};
203
+ this.tables = [];
204
+ this.connected = false;
205
+ this.connecting = false;
206
+ this.name = name;
207
+ this.version = version;
208
+ this.tables = tables !== null && tables !== void 0 ? tables : [];
209
+ }
210
+ IndexedStorage.prototype.register = function (tables) {
211
+ var _a;
212
+ (_a = this.tables).push.apply(_a, __spreadArray([], __read(tables), false));
213
+ };
214
+ IndexedStorage.prototype.connect = function () {
215
+ return __awaiter(this, void 0, void 0, function () {
216
+ return __generator(this, function (_a) {
217
+ switch (_a.label) {
218
+ case 0:
219
+ if (this.connected) {
220
+ return [2 /*return*/];
221
+ }
222
+
223
+ if (!this.connecting) return [3 /*break*/, 4];
224
+ _a.label = 1;
225
+ case 1:
226
+ if (!!this.connecting) return [3 /*break*/, 3];
227
+ return [4 /*yield*/, sleep(100)];
228
+ case 2:
229
+ _a.sent();
230
+ return [3 /*break*/, 1];
231
+ case 3:
232
+ return [2 /*return*/];
233
+ case 4:
234
+ this.connecting = true;
235
+ this.utils = new IndexedDBUtils(this.name, this.version, this.tables);
236
+ return [4 /*yield*/, this.utils.open()];
237
+ case 5:
238
+ _a.sent();
239
+ this.connected = true;
240
+ this.connecting = false;
241
+ return [2 /*return*/];
242
+ }
243
+ });
244
+ });
245
+ };
246
+
247
+ IndexedStorage.prototype.get = function (store) {
248
+ if (!this._cache[store] && this.utils) {
249
+ this._cache[store] = new Storage(this.utils, store);
250
+ }
251
+ return this._cache[store];
252
+ };
253
+ return IndexedStorage;
254
+ }();
255
+ export { IndexedStorage };
@@ -0,0 +1,21 @@
1
+ export interface IndexedTable {
2
+ name: string;
3
+ options?: any;
4
+ default?: any;
5
+ }
6
+ export declare class IndexedDBUtils {
7
+ private readonly name;
8
+ private readonly version;
9
+ private readonly indexedDB;
10
+ private readonly tables;
11
+ private db;
12
+ private transaction;
13
+ constructor(name: string, version: number, tables: IndexedTable[]);
14
+ open(): Promise<unknown>;
15
+ private createTable;
16
+ private createTransaction;
17
+ get: (store: string, values?: any) => Promise<any>;
18
+ getAll: (store: string, values?: any) => Promise<any>;
19
+ delete: (store: string, values?: any) => Promise<any>;
20
+ put: (store: string, values?: any) => Promise<any>;
21
+ }