pubo-web 1.0.158 → 1.0.160

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(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})()));
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:()=>u,loadScript:()=>s,pickFiles:()=>d,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){var s;let i=e;t&&(i=JSON.stringify(e)),null===(s=this.client)||void 0===s||s.send(i)}}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){var t,s,i;if("function"!=typeof this.onMove)return;e.preventDefault?e.preventDefault():e.returnValue=!1;const n=null!==(i=e.pageX)&&void 0!==i?i:null===(t=e.touches[0])||void 0===t?void 0:t.pageX;var o;const r=null!==(o=e.pageY)&&void 0!==o?o:null===(s=e.touches[0])||void 0===s?void 0:s.pageY;this.onMove({offsetX:n-this.cache.pageX,offsetY:r-this.cache.pageY,pageX:n,pageY:r,startX:this.cache.pageX,startY:this.cache.pageY,key:this.key}),this.cache.pageX=n,this.cache.pageY=r}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){var t,s,i;if(e.preventDefault&&e.pageX?e.preventDefault():e.returnValue=!1,"function"!=typeof this.onMove||this.cache.dragging)return;this.clearListener();const n=null!==(i=e.pageX)&&void 0!==i?i:null===(t=e.touches[0])||void 0===t?void 0:t.pageX;var o;const r=null!==(o=e.pageY)&&void 0!==o?o:null===(s=e.touches[0])||void 0===s?void 0:s.pageY;this.cache.dragging=!0,this.cache.pageX=n,this.cache.pageY=r,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 d=()=>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()})),u=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}`},v=async e=>{await new Promise((t=>{let s=setTimeout((()=>{t(),clearTimeout(s),s=null}),e)}))};class f{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)=>{var s;const i=null===(s=this.indexedDB)||void 0===s?void 0:s.open(this.name,this.version);i.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},i.onsuccess=()=>{this.db||(this.db=i.result),e("success")},i.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 m{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=null!=s?s:[]}register(e){this.tables.push(...e)}async connect(){if(!this.connected)if(this.connecting)for(;!this.connecting;)await v(100);else this.connecting=!0,this.utils=new f(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 m(this.utils,e)),this._cache[e]}}return t})()));
package/es/dom/drag.js CHANGED
@@ -1,16 +1,19 @@
1
1
  /**
2
2
  * Class for handling drag events in a UI.
3
- */
4
- export class DragMethod {
3
+ */ export class DragMethod {
5
4
  key = '';
6
- cache = { pageX: 0, pageY: 0, dragging: false };
5
+ cache = {
6
+ pageX: 0,
7
+ pageY: 0,
8
+ dragging: false
9
+ };
7
10
  onMouseMove;
8
11
  onMouseUp;
9
12
  onMouseDown;
10
13
  onTouchStart;
11
14
  onMove;
12
15
  onMoveEnd;
13
- constructor({ key = '', onMove, onMoveEnd } = {}) {
16
+ constructor({ key = '', onMove, onMoveEnd } = {}){
14
17
  this.key = key;
15
18
  this.onMouseDown = this._onMouseDown.bind(this);
16
19
  this.onTouchStart = this._onMouseDown.bind(this);
@@ -20,17 +23,19 @@ export class DragMethod {
20
23
  this.onMoveEnd = onMoveEnd;
21
24
  }
22
25
  _onMouseMove(e) {
26
+ var _e_touches_, _e_touches_1;
23
27
  if (typeof this.onMove !== 'function') {
24
28
  return;
25
29
  }
26
30
  if (e.preventDefault) {
27
31
  e.preventDefault();
28
- }
29
- else {
32
+ } else {
30
33
  e.returnValue = false;
31
34
  }
32
- const pageX = e.pageX ?? e.touches[0]?.pageX;
33
- const pageY = e.pageY ?? e.touches[0]?.pageY;
35
+ var _e_pageX;
36
+ const pageX = (_e_pageX = e.pageX) !== null && _e_pageX !== void 0 ? _e_pageX : (_e_touches_ = e.touches[0]) === null || _e_touches_ === void 0 ? void 0 : _e_touches_.pageX;
37
+ var _e_pageY;
38
+ const pageY = (_e_pageY = e.pageY) !== null && _e_pageY !== void 0 ? _e_pageY : (_e_touches_1 = e.touches[0]) === null || _e_touches_1 === void 0 ? void 0 : _e_touches_1.pageY;
34
39
  this.onMove({
35
40
  offsetX: pageX - this.cache.pageX,
36
41
  offsetY: pageY - this.cache.pageY,
@@ -38,7 +43,7 @@ export class DragMethod {
38
43
  pageY,
39
44
  startX: this.cache.pageX,
40
45
  startY: this.cache.pageY,
41
- key: this.key,
46
+ key: this.key
42
47
  });
43
48
  this.cache.pageX = pageX;
44
49
  this.cache.pageY = pageY;
@@ -57,24 +62,30 @@ export class DragMethod {
57
62
  }
58
63
  }
59
64
  _onMouseDown(e) {
65
+ var _e_touches_, _e_touches_1;
60
66
  if (e.preventDefault && e.pageX) {
61
67
  e.preventDefault();
62
- }
63
- else {
68
+ } else {
64
69
  e.returnValue = false;
65
70
  }
66
71
  if (typeof this.onMove !== 'function' || this.cache.dragging) {
67
72
  return;
68
73
  }
69
74
  this.clearListener();
70
- const pageX = e.pageX ?? e.touches[0]?.pageX;
71
- const pageY = e.pageY ?? e.touches[0]?.pageY;
75
+ var _e_pageX;
76
+ const pageX = (_e_pageX = e.pageX) !== null && _e_pageX !== void 0 ? _e_pageX : (_e_touches_ = e.touches[0]) === null || _e_touches_ === void 0 ? void 0 : _e_touches_.pageX;
77
+ var _e_pageY;
78
+ const pageY = (_e_pageY = e.pageY) !== null && _e_pageY !== void 0 ? _e_pageY : (_e_touches_1 = e.touches[0]) === null || _e_touches_1 === void 0 ? void 0 : _e_touches_1.pageY;
72
79
  this.cache.dragging = true;
73
80
  this.cache.pageX = pageX;
74
81
  this.cache.pageY = pageY;
75
82
  window.addEventListener('mousemove', this.onMouseMove);
76
- window.addEventListener('touchmove', this.onMouseMove, { passive: false });
83
+ window.addEventListener('touchmove', this.onMouseMove, {
84
+ passive: false
85
+ });
77
86
  window.addEventListener('mouseup', this.onMouseUp);
78
- window.addEventListener('touchend', this.onMouseUp, { passive: false });
87
+ window.addEventListener('touchend', this.onMouseUp, {
88
+ passive: false
89
+ });
79
90
  }
80
91
  }
@@ -1,4 +1,4 @@
1
- export const downloadFile = (uri, name) => {
1
+ export const downloadFile = (uri, name)=>{
2
2
  const a = document.createElement('a');
3
3
  a.href = uri;
4
4
  if (name) {
package/es/file/parser.js CHANGED
@@ -1,23 +1,24 @@
1
- export const blob2text = (blob) => {
2
- return new Promise((resolve) => {
1
+ export const blob2text = (blob)=>{
2
+ return new Promise((resolve)=>{
3
3
  const reader = new FileReader();
4
- reader.onload = (e) => resolve(e.target.result);
4
+ reader.onload = (e)=>resolve(e.target.result);
5
5
  reader.readAsText(blob);
6
6
  });
7
7
  };
8
- export const blob2base64 = (blob) => {
9
- return new Promise(function (resolve, reject) {
8
+ export const blob2base64 = (blob)=>{
9
+ return new Promise(function(resolve, reject) {
10
10
  const reader = new FileReader();
11
11
  if (!blob) {
12
12
  reject('文件爲空!');
13
- }
14
- else {
15
- reader.onload = (e) => resolve(e.target.result);
16
- reader.onabort = () => reject();
13
+ } else {
14
+ reader.onload = (e)=>resolve(e.target.result);
15
+ reader.onabort = ()=>reject();
17
16
  reader.readAsDataURL(blob);
18
17
  }
19
18
  });
20
19
  };
21
- export const blob2file = (blob, name, type) => {
22
- return new File(blob, name, { type });
20
+ export const blob2file = (blob, name, type)=>{
21
+ return new File(blob, name, {
22
+ type
23
+ });
23
24
  };
package/es/file/pick.js CHANGED
@@ -1,11 +1,11 @@
1
- export const pickFiles = () => {
2
- return new Promise((resolve, reject) => {
1
+ export const pickFiles = ()=>{
2
+ return new Promise((resolve, reject)=>{
3
3
  const el = document.createElement('input');
4
4
  let picked = false;
5
- const onFocus = () => {
5
+ const onFocus = ()=>{
6
6
  document.body.removeChild(el);
7
7
  window.removeEventListener('focus', onFocus);
8
- setTimeout(() => {
8
+ setTimeout(()=>{
9
9
  if (!picked) {
10
10
  reject('no files picked');
11
11
  }
@@ -17,7 +17,7 @@ export const pickFiles = () => {
17
17
  el.style.top = '0px';
18
18
  el.style.zIndex = '-1';
19
19
  window.addEventListener('focus', onFocus);
20
- el.onchange = (e) => {
20
+ el.onchange = (e)=>{
21
21
  picked = e.target.files.length > 0;
22
22
  resolve(e.target.files);
23
23
  };
@@ -4,30 +4,28 @@
4
4
  * @param {string} url - The URL of the script to load
5
5
  * @param {any} options - Additional options for loading the script
6
6
  * @return {Promise<any>} A Promise that resolves with the URL once the script is loaded
7
- */
8
- export const loadScript = (url, options = {}) => {
9
- const findScript = () => {
7
+ */ export const loadScript = (url, options = {})=>{
8
+ const findScript = ()=>{
10
9
  const list = document.getElementsByTagName('script');
11
- for (const item of list) {
10
+ for (const item of list){
12
11
  if (item.src === url) {
13
12
  return item;
14
13
  }
15
14
  }
16
15
  return null;
17
16
  };
18
- return new Promise((resolve) => {
17
+ return new Promise((resolve)=>{
19
18
  const old = findScript();
20
19
  let el = old;
21
20
  if (!old) {
22
21
  el = document.createElement('script');
23
- }
24
- else if (old._state === 'complete') {
22
+ } else if (old._state === 'complete') {
25
23
  return resolve(url);
26
24
  }
27
- for (const key of Object.keys(options)) {
25
+ for (const key of Object.keys(options)){
28
26
  el[key] = options[key];
29
27
  }
30
- const onLoad = () => {
28
+ const onLoad = ()=>{
31
29
  resolve(url);
32
30
  el.removeEventListener('load', onLoad);
33
31
  el._state = 'complete';
@@ -1,20 +1,20 @@
1
- export const getCookieValue = (key) => {
1
+ export const getCookieValue = (key)=>{
2
2
  const reg = new RegExp(`(^| )${key}=([^;]*)(;|$)`);
3
3
  const res = reg.exec(document.cookie);
4
4
  return res ? res[2] : '';
5
5
  };
6
- export const getCookie = () => {
6
+ export const getCookie = ()=>{
7
7
  const res = {};
8
8
  if (!document.cookie) {
9
9
  return res;
10
10
  }
11
11
  const tmp = document.cookie.split(';');
12
- tmp.forEach((item) => {
12
+ tmp.forEach((item)=>{
13
13
  const [key, value] = item.split('=');
14
14
  res[key] = value;
15
15
  });
16
16
  return res;
17
17
  };
18
- export const setCookieItem = (key, value) => {
18
+ export const setCookieItem = (key, value)=>{
19
19
  document.cookie = `${key}=${value}`;
20
20
  };
@@ -2,7 +2,7 @@ export class WebStorage {
2
2
  _key;
3
3
  storage;
4
4
  zip;
5
- constructor(props) {
5
+ constructor(props){
6
6
  const { type = 'sessionStorage', key } = props;
7
7
  this._key = key;
8
8
  this.storage = window[type];
@@ -15,8 +15,7 @@ export class WebStorage {
15
15
  }
16
16
  if (value) {
17
17
  return JSON.parse(value);
18
- }
19
- else {
18
+ } else {
20
19
  return null;
21
20
  }
22
21
  }
@@ -32,7 +31,10 @@ export class WebStorage {
32
31
  }
33
32
  merge(data) {
34
33
  const old = this.state;
35
- this.state = { ...old, ...data };
34
+ this.state = {
35
+ ...old,
36
+ ...data
37
+ };
36
38
  }
37
39
  clear() {
38
40
  this.storage.removeItem(this._key);
@@ -3,7 +3,7 @@ import { IndexedDBUtils } from './indexed-db-utils';
3
3
  export class Storage {
4
4
  utils;
5
5
  store;
6
- constructor(utils, store) {
6
+ constructor(utils, store){
7
7
  this.utils = utils;
8
8
  this.store = store;
9
9
  }
@@ -11,11 +11,18 @@ export class Storage {
11
11
  return this.utils.get(this.store, 1);
12
12
  }
13
13
  setState(values) {
14
- this.utils.put(this.store, { ...values, _id: 1 });
14
+ this.utils.put(this.store, {
15
+ ...values,
16
+ _id: 1
17
+ });
15
18
  }
16
19
  async merge(values) {
17
20
  const state = await this.getState();
18
- this.setState = { ...state, ...values, _id: 1 };
21
+ this.setState = {
22
+ ...state,
23
+ ...values,
24
+ _id: 1
25
+ };
19
26
  }
20
27
  }
21
28
  export class IndexedStorage {
@@ -26,10 +33,10 @@ export class IndexedStorage {
26
33
  tables = [];
27
34
  connected = false;
28
35
  connecting = false;
29
- constructor({ name, version, tables }) {
36
+ constructor({ name, version, tables }){
30
37
  this.name = name;
31
38
  this.version = version;
32
- this.tables = tables ?? [];
39
+ this.tables = tables !== null && tables !== void 0 ? tables : [];
33
40
  }
34
41
  register(tables) {
35
42
  this.tables.push(...tables);
@@ -39,7 +46,7 @@ export class IndexedStorage {
39
46
  return;
40
47
  }
41
48
  if (this.connecting) {
42
- while (!this.connecting) {
49
+ while(!this.connecting){
43
50
  await sleep(100);
44
51
  }
45
52
  return;
@@ -5,67 +5,73 @@ export class IndexedDBUtils {
5
5
  tables;
6
6
  db;
7
7
  transaction;
8
- constructor(name, version, tables) {
8
+ constructor(name, version, tables){
9
9
  this.name = name;
10
10
  this.version = version;
11
11
  this.tables = tables;
12
12
  }
13
13
  open() {
14
- return new Promise((resolve, reject) => {
15
- const request = this.indexedDB?.open(this.name, this.version);
16
- request.onupgradeneeded = async (event) => {
14
+ return new Promise((resolve, reject)=>{
15
+ var _this_indexedDB;
16
+ const request = (_this_indexedDB = this.indexedDB) === null || _this_indexedDB === void 0 ? void 0 : _this_indexedDB.open(this.name, this.version);
17
+ request.onupgradeneeded = async (event)=>{
17
18
  // @ts-ignore
18
19
  const db = event.target.result;
19
20
  // @ts-ignore
20
21
  this.transaction = event.target.transaction;
21
- this.transaction.oncomplete = async () => {
22
+ this.transaction.oncomplete = async ()=>{
22
23
  this.transaction = null;
23
- for (const table of this.tables) {
24
+ for (const table of this.tables){
24
25
  if (table.default) {
25
26
  await this.put(table.name, table.default);
26
27
  }
27
28
  }
28
29
  };
29
- for (const table of this.tables) {
30
+ for (const table of this.tables){
30
31
  if (!db.objectStoreNames.contains(table.name)) {
31
- db.createObjectStore(table.name, table.options || { keyPath: '_id', autoIncrement: true });
32
+ db.createObjectStore(table.name, table.options || {
33
+ keyPath: '_id',
34
+ autoIncrement: true
35
+ });
32
36
  }
33
37
  }
34
38
  this.db = db;
35
39
  };
36
- request.onsuccess = () => {
40
+ request.onsuccess = ()=>{
37
41
  if (!this.db) {
38
42
  this.db = request.result;
39
43
  }
40
44
  resolve('success');
41
45
  };
42
- request.onerror = (error) => {
46
+ request.onerror = (error)=>{
43
47
  console.error('indexed db connect error: ', error);
44
48
  reject(error);
45
49
  };
46
50
  });
47
51
  }
48
52
  createTransaction(getRequest) {
49
- return (store, ...args) => {
50
- return new Promise((resolve, reject) => {
53
+ return (store, ...args)=>{
54
+ return new Promise((resolve, reject)=>{
51
55
  if (!this.db) {
52
56
  reject('not connect');
53
57
  return;
54
58
  }
55
- const transaction = this.db.transaction([store], 'readwrite');
59
+ const transaction = this.db.transaction([
60
+ store
61
+ ], 'readwrite');
56
62
  const objectStore = transaction.objectStore(store);
57
63
  const request = getRequest(objectStore, ...args);
58
- request.onerror = function (event) {
64
+ request.onerror = function(event) {
59
65
  reject(event);
60
66
  };
61
- request.onsuccess = function () {
67
+ request.onsuccess = function() {
62
68
  resolve(request.result);
63
69
  };
64
70
  });
65
71
  };
66
72
  }
67
- get = this.createTransaction((objectStore, key) => objectStore.get(key));
68
- getAll = this.createTransaction((objectStore) => objectStore.getAll());
69
- delete = this.createTransaction((objectStore, key) => objectStore.delete(key));
70
- put = this.createTransaction((objectStore, values) => objectStore.put(values));
73
+ get = this.createTransaction((objectStore, key)=>objectStore.get(key));
74
+ getAll = this.createTransaction((objectStore)=>objectStore.getAll());
75
+ delete = this.createTransaction((objectStore, key)=>objectStore.delete(key));
76
+ put = this.createTransaction((objectStore, values)=>objectStore.put(values));
71
77
  }
@@ -1,10 +1,10 @@
1
1
  import { Emitter } from 'pubo-utils';
2
2
  export class WebsocketClient {
3
3
  client = null;
4
- _status = 0; // 0 默认 1 已连接 2 断开连接 3 重连
4
+ _status = 0;
5
5
  url;
6
6
  emitter = new Emitter();
7
- constructor({ url }) {
7
+ constructor({ url }){
8
8
  this.url = url;
9
9
  }
10
10
  reconnect() {
@@ -13,7 +13,7 @@ export class WebsocketClient {
13
13
  }
14
14
  this.client = null;
15
15
  if (this._status === 3) {
16
- setTimeout(() => this.connect(), 1000);
16
+ setTimeout(()=>this.connect(), 1000);
17
17
  }
18
18
  }
19
19
  onClose() {
@@ -35,7 +35,7 @@ export class WebsocketClient {
35
35
  this.client = new WebSocket(this.url);
36
36
  this.client.onclose = this.onClose.bind(this);
37
37
  this.client.onmessage = this.onMessage.bind(this);
38
- this.client.onopen = () => {
38
+ this.client.onopen = ()=>{
39
39
  this.emitter.emit('connect');
40
40
  this._status = 1;
41
41
  };
@@ -48,10 +48,11 @@ export class WebsocketClient {
48
48
  this.client = null;
49
49
  }
50
50
  send(data, isJson = false) {
51
+ var _this_client;
51
52
  let res = data;
52
53
  if (isJson) {
53
54
  res = JSON.stringify(data);
54
55
  }
55
- this.client?.send(res);
56
+ (_this_client = this.client) === null || _this_client === void 0 ? void 0 : _this_client.send(res);
56
57
  }
57
58
  }
package/lib/dom/drag.js CHANGED
@@ -1,19 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DragMethod = void 0;
4
- /**
5
- * Class for handling drag events in a UI.
6
- */
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "DragMethod", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return DragMethod;
9
+ }
10
+ });
7
11
  class DragMethod {
8
12
  key = '';
9
- cache = { pageX: 0, pageY: 0, dragging: false };
13
+ cache = {
14
+ pageX: 0,
15
+ pageY: 0,
16
+ dragging: false
17
+ };
10
18
  onMouseMove;
11
19
  onMouseUp;
12
20
  onMouseDown;
13
21
  onTouchStart;
14
22
  onMove;
15
23
  onMoveEnd;
16
- constructor({ key = '', onMove, onMoveEnd } = {}) {
24
+ constructor({ key = '', onMove, onMoveEnd } = {}){
17
25
  this.key = key;
18
26
  this.onMouseDown = this._onMouseDown.bind(this);
19
27
  this.onTouchStart = this._onMouseDown.bind(this);
@@ -23,17 +31,19 @@ class DragMethod {
23
31
  this.onMoveEnd = onMoveEnd;
24
32
  }
25
33
  _onMouseMove(e) {
34
+ var _e_touches_, _e_touches_1;
26
35
  if (typeof this.onMove !== 'function') {
27
36
  return;
28
37
  }
29
38
  if (e.preventDefault) {
30
39
  e.preventDefault();
31
- }
32
- else {
40
+ } else {
33
41
  e.returnValue = false;
34
42
  }
35
- const pageX = e.pageX ?? e.touches[0]?.pageX;
36
- const pageY = e.pageY ?? e.touches[0]?.pageY;
43
+ var _e_pageX;
44
+ const pageX = (_e_pageX = e.pageX) !== null && _e_pageX !== void 0 ? _e_pageX : (_e_touches_ = e.touches[0]) === null || _e_touches_ === void 0 ? void 0 : _e_touches_.pageX;
45
+ var _e_pageY;
46
+ const pageY = (_e_pageY = e.pageY) !== null && _e_pageY !== void 0 ? _e_pageY : (_e_touches_1 = e.touches[0]) === null || _e_touches_1 === void 0 ? void 0 : _e_touches_1.pageY;
37
47
  this.onMove({
38
48
  offsetX: pageX - this.cache.pageX,
39
49
  offsetY: pageY - this.cache.pageY,
@@ -41,7 +51,7 @@ class DragMethod {
41
51
  pageY,
42
52
  startX: this.cache.pageX,
43
53
  startY: this.cache.pageY,
44
- key: this.key,
54
+ key: this.key
45
55
  });
46
56
  this.cache.pageX = pageX;
47
57
  this.cache.pageY = pageY;
@@ -60,25 +70,30 @@ class DragMethod {
60
70
  }
61
71
  }
62
72
  _onMouseDown(e) {
73
+ var _e_touches_, _e_touches_1;
63
74
  if (e.preventDefault && e.pageX) {
64
75
  e.preventDefault();
65
- }
66
- else {
76
+ } else {
67
77
  e.returnValue = false;
68
78
  }
69
79
  if (typeof this.onMove !== 'function' || this.cache.dragging) {
70
80
  return;
71
81
  }
72
82
  this.clearListener();
73
- const pageX = e.pageX ?? e.touches[0]?.pageX;
74
- const pageY = e.pageY ?? e.touches[0]?.pageY;
83
+ var _e_pageX;
84
+ const pageX = (_e_pageX = e.pageX) !== null && _e_pageX !== void 0 ? _e_pageX : (_e_touches_ = e.touches[0]) === null || _e_touches_ === void 0 ? void 0 : _e_touches_.pageX;
85
+ var _e_pageY;
86
+ const pageY = (_e_pageY = e.pageY) !== null && _e_pageY !== void 0 ? _e_pageY : (_e_touches_1 = e.touches[0]) === null || _e_touches_1 === void 0 ? void 0 : _e_touches_1.pageY;
75
87
  this.cache.dragging = true;
76
88
  this.cache.pageX = pageX;
77
89
  this.cache.pageY = pageY;
78
90
  window.addEventListener('mousemove', this.onMouseMove);
79
- window.addEventListener('touchmove', this.onMouseMove, { passive: false });
91
+ window.addEventListener('touchmove', this.onMouseMove, {
92
+ passive: false
93
+ });
80
94
  window.addEventListener('mouseup', this.onMouseUp);
81
- window.addEventListener('touchend', this.onMouseUp, { passive: false });
95
+ window.addEventListener('touchend', this.onMouseUp, {
96
+ passive: false
97
+ });
82
98
  }
83
99
  }
84
- exports.DragMethod = DragMethod;
@@ -1,7 +1,14 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.downloadFile = void 0;
4
- const downloadFile = (uri, name) => {
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "downloadFile", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return downloadFile;
9
+ }
10
+ });
11
+ const downloadFile = (uri, name)=>{
5
12
  const a = document.createElement('a');
6
13
  a.href = uri;
7
14
  if (name) {
@@ -13,4 +20,3 @@ const downloadFile = (uri, name) => {
13
20
  a.click();
14
21
  document.body.removeChild(a);
15
22
  };
16
- exports.downloadFile = downloadFile;
@@ -1,29 +1,45 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.blob2file = exports.blob2base64 = exports.blob2text = void 0;
4
- const blob2text = (blob) => {
5
- return new Promise((resolve) => {
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ blob2base64: function() {
13
+ return blob2base64;
14
+ },
15
+ blob2file: function() {
16
+ return blob2file;
17
+ },
18
+ blob2text: function() {
19
+ return blob2text;
20
+ }
21
+ });
22
+ const blob2text = (blob)=>{
23
+ return new Promise((resolve)=>{
6
24
  const reader = new FileReader();
7
- reader.onload = (e) => resolve(e.target.result);
25
+ reader.onload = (e)=>resolve(e.target.result);
8
26
  reader.readAsText(blob);
9
27
  });
10
28
  };
11
- exports.blob2text = blob2text;
12
- const blob2base64 = (blob) => {
13
- return new Promise(function (resolve, reject) {
29
+ const blob2base64 = (blob)=>{
30
+ return new Promise(function(resolve, reject) {
14
31
  const reader = new FileReader();
15
32
  if (!blob) {
16
33
  reject('文件爲空!');
17
- }
18
- else {
19
- reader.onload = (e) => resolve(e.target.result);
20
- reader.onabort = () => reject();
34
+ } else {
35
+ reader.onload = (e)=>resolve(e.target.result);
36
+ reader.onabort = ()=>reject();
21
37
  reader.readAsDataURL(blob);
22
38
  }
23
39
  });
24
40
  };
25
- exports.blob2base64 = blob2base64;
26
- const blob2file = (blob, name, type) => {
27
- return new File(blob, name, { type });
41
+ const blob2file = (blob, name, type)=>{
42
+ return new File(blob, name, {
43
+ type
44
+ });
28
45
  };
29
- exports.blob2file = blob2file;
package/lib/file/pick.js CHANGED
@@ -1,14 +1,21 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pickFiles = void 0;
4
- const pickFiles = () => {
5
- return new Promise((resolve, reject) => {
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "pickFiles", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return pickFiles;
9
+ }
10
+ });
11
+ const pickFiles = ()=>{
12
+ return new Promise((resolve, reject)=>{
6
13
  const el = document.createElement('input');
7
14
  let picked = false;
8
- const onFocus = () => {
15
+ const onFocus = ()=>{
9
16
  document.body.removeChild(el);
10
17
  window.removeEventListener('focus', onFocus);
11
- setTimeout(() => {
18
+ setTimeout(()=>{
12
19
  if (!picked) {
13
20
  reject('no files picked');
14
21
  }
@@ -20,7 +27,7 @@ const pickFiles = () => {
20
27
  el.style.top = '0px';
21
28
  el.style.zIndex = '-1';
22
29
  window.addEventListener('focus', onFocus);
23
- el.onchange = (e) => {
30
+ el.onchange = (e)=>{
24
31
  picked = e.target.files.length > 0;
25
32
  resolve(e.target.files);
26
33
  };
@@ -28,4 +35,3 @@ const pickFiles = () => {
28
35
  el.click();
29
36
  });
30
37
  };
31
- exports.pickFiles = pickFiles;
package/lib/index.js CHANGED
@@ -1,25 +1,60 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IndexedStorage = exports.setCookieItem = exports.getCookie = exports.getCookieValue = exports.pickFiles = exports.DragMethod = exports.WebsocketClient = exports.WebStorage = exports.downloadFile = exports.blob2file = exports.blob2base64 = exports.blob2text = exports.loadScript = void 0;
4
- var load_script_1 = require("./load-script");
5
- Object.defineProperty(exports, "loadScript", { enumerable: true, get: function () { return load_script_1.loadScript; } });
6
- var parser_1 = require("./file/parser");
7
- Object.defineProperty(exports, "blob2text", { enumerable: true, get: function () { return parser_1.blob2text; } });
8
- Object.defineProperty(exports, "blob2base64", { enumerable: true, get: function () { return parser_1.blob2base64; } });
9
- Object.defineProperty(exports, "blob2file", { enumerable: true, get: function () { return parser_1.blob2file; } });
10
- var download_1 = require("./file/download");
11
- Object.defineProperty(exports, "downloadFile", { enumerable: true, get: function () { return download_1.downloadFile; } });
12
- var storage_1 = require("./storage");
13
- Object.defineProperty(exports, "WebStorage", { enumerable: true, get: function () { return storage_1.WebStorage; } });
14
- var client_1 = require("./websocket/client");
15
- Object.defineProperty(exports, "WebsocketClient", { enumerable: true, get: function () { return client_1.WebsocketClient; } });
16
- var drag_1 = require("./dom/drag");
17
- Object.defineProperty(exports, "DragMethod", { enumerable: true, get: function () { return drag_1.DragMethod; } });
18
- var pick_1 = require("./file/pick");
19
- Object.defineProperty(exports, "pickFiles", { enumerable: true, get: function () { return pick_1.pickFiles; } });
20
- var cookie_1 = require("./storage/cookie");
21
- Object.defineProperty(exports, "getCookieValue", { enumerable: true, get: function () { return cookie_1.getCookieValue; } });
22
- Object.defineProperty(exports, "getCookie", { enumerable: true, get: function () { return cookie_1.getCookie; } });
23
- Object.defineProperty(exports, "setCookieItem", { enumerable: true, get: function () { return cookie_1.setCookieItem; } });
24
- var indexed_db_storage_1 = require("./storage/indexed-db/indexed-db-storage");
25
- Object.defineProperty(exports, "IndexedStorage", { enumerable: true, get: function () { return indexed_db_storage_1.IndexedStorage; } });
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ DragMethod: function() {
13
+ return _drag.DragMethod;
14
+ },
15
+ IndexedStorage: function() {
16
+ return _indexeddbstorage.IndexedStorage;
17
+ },
18
+ WebStorage: function() {
19
+ return _storage.WebStorage;
20
+ },
21
+ WebsocketClient: function() {
22
+ return _client.WebsocketClient;
23
+ },
24
+ blob2base64: function() {
25
+ return _parser.blob2base64;
26
+ },
27
+ blob2file: function() {
28
+ return _parser.blob2file;
29
+ },
30
+ blob2text: function() {
31
+ return _parser.blob2text;
32
+ },
33
+ downloadFile: function() {
34
+ return _download.downloadFile;
35
+ },
36
+ getCookie: function() {
37
+ return _cookie.getCookie;
38
+ },
39
+ getCookieValue: function() {
40
+ return _cookie.getCookieValue;
41
+ },
42
+ loadScript: function() {
43
+ return _loadscript.loadScript;
44
+ },
45
+ pickFiles: function() {
46
+ return _pick.pickFiles;
47
+ },
48
+ setCookieItem: function() {
49
+ return _cookie.setCookieItem;
50
+ }
51
+ });
52
+ const _loadscript = require("./load-script");
53
+ const _parser = require("./file/parser");
54
+ const _download = require("./file/download");
55
+ const _storage = require("./storage");
56
+ const _client = require("./websocket/client");
57
+ const _drag = require("./dom/drag");
58
+ const _pick = require("./file/pick");
59
+ const _cookie = require("./storage/cookie");
60
+ const _indexeddbstorage = require("./storage/indexed-db/indexed-db-storage");
@@ -1,36 +1,41 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadScript = void 0;
4
1
  /**
5
2
  * Loads a script from the given URL with the provided options.
6
3
  *
7
4
  * @param {string} url - The URL of the script to load
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
- */
11
- const loadScript = (url, options = {}) => {
12
- const findScript = () => {
7
+ */ "use strict";
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ Object.defineProperty(exports, "loadScript", {
12
+ enumerable: true,
13
+ get: function() {
14
+ return loadScript;
15
+ }
16
+ });
17
+ const loadScript = (url, options = {})=>{
18
+ const findScript = ()=>{
13
19
  const list = document.getElementsByTagName('script');
14
- for (const item of list) {
20
+ for (const item of list){
15
21
  if (item.src === url) {
16
22
  return item;
17
23
  }
18
24
  }
19
25
  return null;
20
26
  };
21
- return new Promise((resolve) => {
27
+ return new Promise((resolve)=>{
22
28
  const old = findScript();
23
29
  let el = old;
24
30
  if (!old) {
25
31
  el = document.createElement('script');
26
- }
27
- else if (old._state === 'complete') {
32
+ } else if (old._state === 'complete') {
28
33
  return resolve(url);
29
34
  }
30
- for (const key of Object.keys(options)) {
35
+ for (const key of Object.keys(options)){
31
36
  el[key] = options[key];
32
37
  }
33
- const onLoad = () => {
38
+ const onLoad = ()=>{
34
39
  resolve(url);
35
40
  el.removeEventListener('load', onLoad);
36
41
  el._state = 'complete';
@@ -41,4 +46,3 @@ const loadScript = (url, options = {}) => {
41
46
  return 'success';
42
47
  });
43
48
  };
44
- exports.loadScript = loadScript;
@@ -1,26 +1,41 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setCookieItem = exports.getCookie = exports.getCookieValue = void 0;
4
- const getCookieValue = (key) => {
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ getCookie: function() {
13
+ return getCookie;
14
+ },
15
+ getCookieValue: function() {
16
+ return getCookieValue;
17
+ },
18
+ setCookieItem: function() {
19
+ return setCookieItem;
20
+ }
21
+ });
22
+ const getCookieValue = (key)=>{
5
23
  const reg = new RegExp(`(^| )${key}=([^;]*)(;|$)`);
6
24
  const res = reg.exec(document.cookie);
7
25
  return res ? res[2] : '';
8
26
  };
9
- exports.getCookieValue = getCookieValue;
10
- const getCookie = () => {
27
+ const getCookie = ()=>{
11
28
  const res = {};
12
29
  if (!document.cookie) {
13
30
  return res;
14
31
  }
15
32
  const tmp = document.cookie.split(';');
16
- tmp.forEach((item) => {
33
+ tmp.forEach((item)=>{
17
34
  const [key, value] = item.split('=');
18
35
  res[key] = value;
19
36
  });
20
37
  return res;
21
38
  };
22
- exports.getCookie = getCookie;
23
- const setCookieItem = (key, value) => {
39
+ const setCookieItem = (key, value)=>{
24
40
  document.cookie = `${key}=${value}`;
25
41
  };
26
- exports.setCookieItem = setCookieItem;
@@ -1,11 +1,18 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebStorage = void 0;
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "WebStorage", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return WebStorage;
9
+ }
10
+ });
4
11
  class WebStorage {
5
12
  _key;
6
13
  storage;
7
14
  zip;
8
- constructor(props) {
15
+ constructor(props){
9
16
  const { type = 'sessionStorage', key } = props;
10
17
  this._key = key;
11
18
  this.storage = window[type];
@@ -18,8 +25,7 @@ class WebStorage {
18
25
  }
19
26
  if (value) {
20
27
  return JSON.parse(value);
21
- }
22
- else {
28
+ } else {
23
29
  return null;
24
30
  }
25
31
  }
@@ -35,10 +41,12 @@ class WebStorage {
35
41
  }
36
42
  merge(data) {
37
43
  const old = this.state;
38
- this.state = { ...old, ...data };
44
+ this.state = {
45
+ ...old,
46
+ ...data
47
+ };
39
48
  }
40
49
  clear() {
41
50
  this.storage.removeItem(this._key);
42
51
  }
43
52
  }
44
- exports.WebStorage = WebStorage;
@@ -1,12 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IndexedStorage = exports.Storage = void 0;
4
- const pubo_utils_1 = require("pubo-utils");
5
- const indexed_db_utils_1 = require("./indexed-db-utils");
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ IndexedStorage: function() {
13
+ return IndexedStorage;
14
+ },
15
+ Storage: function() {
16
+ return Storage;
17
+ }
18
+ });
19
+ const _puboutils = require("pubo-utils");
20
+ const _indexeddbutils = require("./indexed-db-utils");
6
21
  class Storage {
7
22
  utils;
8
23
  store;
9
- constructor(utils, store) {
24
+ constructor(utils, store){
10
25
  this.utils = utils;
11
26
  this.store = store;
12
27
  }
@@ -14,14 +29,20 @@ class Storage {
14
29
  return this.utils.get(this.store, 1);
15
30
  }
16
31
  setState(values) {
17
- this.utils.put(this.store, { ...values, _id: 1 });
32
+ this.utils.put(this.store, {
33
+ ...values,
34
+ _id: 1
35
+ });
18
36
  }
19
37
  async merge(values) {
20
38
  const state = await this.getState();
21
- this.setState = { ...state, ...values, _id: 1 };
39
+ this.setState = {
40
+ ...state,
41
+ ...values,
42
+ _id: 1
43
+ };
22
44
  }
23
45
  }
24
- exports.Storage = Storage;
25
46
  class IndexedStorage {
26
47
  name;
27
48
  version;
@@ -30,10 +51,10 @@ class IndexedStorage {
30
51
  tables = [];
31
52
  connected = false;
32
53
  connecting = false;
33
- constructor({ name, version, tables }) {
54
+ constructor({ name, version, tables }){
34
55
  this.name = name;
35
56
  this.version = version;
36
- this.tables = tables ?? [];
57
+ this.tables = tables !== null && tables !== void 0 ? tables : [];
37
58
  }
38
59
  register(tables) {
39
60
  this.tables.push(...tables);
@@ -43,13 +64,13 @@ class IndexedStorage {
43
64
  return;
44
65
  }
45
66
  if (this.connecting) {
46
- while (!this.connecting) {
47
- await (0, pubo_utils_1.sleep)(100);
67
+ while(!this.connecting){
68
+ await (0, _puboutils.sleep)(100);
48
69
  }
49
70
  return;
50
71
  }
51
72
  this.connecting = true;
52
- this.utils = new indexed_db_utils_1.IndexedDBUtils(this.name, this.version, this.tables);
73
+ this.utils = new _indexeddbutils.IndexedDBUtils(this.name, this.version, this.tables);
53
74
  await this.utils.open();
54
75
  this.connected = true;
55
76
  this.connecting = false;
@@ -61,4 +82,3 @@ class IndexedStorage {
61
82
  return this._cache[store];
62
83
  }
63
84
  }
64
- exports.IndexedStorage = IndexedStorage;
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IndexedDBUtils = void 0;
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "IndexedDBUtils", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return IndexedDBUtils;
9
+ }
10
+ });
4
11
  class IndexedDBUtils {
5
12
  name;
6
13
  version;
@@ -8,68 +15,73 @@ class IndexedDBUtils {
8
15
  tables;
9
16
  db;
10
17
  transaction;
11
- constructor(name, version, tables) {
18
+ constructor(name, version, tables){
12
19
  this.name = name;
13
20
  this.version = version;
14
21
  this.tables = tables;
15
22
  }
16
23
  open() {
17
- return new Promise((resolve, reject) => {
18
- const request = this.indexedDB?.open(this.name, this.version);
19
- request.onupgradeneeded = async (event) => {
24
+ return new Promise((resolve, reject)=>{
25
+ var _this_indexedDB;
26
+ const request = (_this_indexedDB = this.indexedDB) === null || _this_indexedDB === void 0 ? void 0 : _this_indexedDB.open(this.name, this.version);
27
+ request.onupgradeneeded = async (event)=>{
20
28
  // @ts-ignore
21
29
  const db = event.target.result;
22
30
  // @ts-ignore
23
31
  this.transaction = event.target.transaction;
24
- this.transaction.oncomplete = async () => {
32
+ this.transaction.oncomplete = async ()=>{
25
33
  this.transaction = null;
26
- for (const table of this.tables) {
34
+ for (const table of this.tables){
27
35
  if (table.default) {
28
36
  await this.put(table.name, table.default);
29
37
  }
30
38
  }
31
39
  };
32
- for (const table of this.tables) {
40
+ for (const table of this.tables){
33
41
  if (!db.objectStoreNames.contains(table.name)) {
34
- db.createObjectStore(table.name, table.options || { keyPath: '_id', autoIncrement: true });
42
+ db.createObjectStore(table.name, table.options || {
43
+ keyPath: '_id',
44
+ autoIncrement: true
45
+ });
35
46
  }
36
47
  }
37
48
  this.db = db;
38
49
  };
39
- request.onsuccess = () => {
50
+ request.onsuccess = ()=>{
40
51
  if (!this.db) {
41
52
  this.db = request.result;
42
53
  }
43
54
  resolve('success');
44
55
  };
45
- request.onerror = (error) => {
56
+ request.onerror = (error)=>{
46
57
  console.error('indexed db connect error: ', error);
47
58
  reject(error);
48
59
  };
49
60
  });
50
61
  }
51
62
  createTransaction(getRequest) {
52
- return (store, ...args) => {
53
- return new Promise((resolve, reject) => {
63
+ return (store, ...args)=>{
64
+ return new Promise((resolve, reject)=>{
54
65
  if (!this.db) {
55
66
  reject('not connect');
56
67
  return;
57
68
  }
58
- const transaction = this.db.transaction([store], 'readwrite');
69
+ const transaction = this.db.transaction([
70
+ store
71
+ ], 'readwrite');
59
72
  const objectStore = transaction.objectStore(store);
60
73
  const request = getRequest(objectStore, ...args);
61
- request.onerror = function (event) {
74
+ request.onerror = function(event) {
62
75
  reject(event);
63
76
  };
64
- request.onsuccess = function () {
77
+ request.onsuccess = function() {
65
78
  resolve(request.result);
66
79
  };
67
80
  });
68
81
  };
69
82
  }
70
- get = this.createTransaction((objectStore, key) => objectStore.get(key));
71
- getAll = this.createTransaction((objectStore) => objectStore.getAll());
72
- delete = this.createTransaction((objectStore, key) => objectStore.delete(key));
73
- put = this.createTransaction((objectStore, values) => objectStore.put(values));
83
+ get = this.createTransaction((objectStore, key)=>objectStore.get(key));
84
+ getAll = this.createTransaction((objectStore)=>objectStore.getAll());
85
+ delete = this.createTransaction((objectStore, key)=>objectStore.delete(key));
86
+ put = this.createTransaction((objectStore, values)=>objectStore.put(values));
74
87
  }
75
- exports.IndexedDBUtils = IndexedDBUtils;
@@ -1,13 +1,20 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebsocketClient = void 0;
4
- const pubo_utils_1 = require("pubo-utils");
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "WebsocketClient", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return WebsocketClient;
9
+ }
10
+ });
11
+ const _puboutils = require("pubo-utils");
5
12
  class WebsocketClient {
6
13
  client = null;
7
- _status = 0; // 0 默认 1 已连接 2 断开连接 3 重连
14
+ _status = 0;
8
15
  url;
9
- emitter = new pubo_utils_1.Emitter();
10
- constructor({ url }) {
16
+ emitter = new _puboutils.Emitter();
17
+ constructor({ url }){
11
18
  this.url = url;
12
19
  }
13
20
  reconnect() {
@@ -16,7 +23,7 @@ class WebsocketClient {
16
23
  }
17
24
  this.client = null;
18
25
  if (this._status === 3) {
19
- setTimeout(() => this.connect(), 1000);
26
+ setTimeout(()=>this.connect(), 1000);
20
27
  }
21
28
  }
22
29
  onClose() {
@@ -38,7 +45,7 @@ class WebsocketClient {
38
45
  this.client = new WebSocket(this.url);
39
46
  this.client.onclose = this.onClose.bind(this);
40
47
  this.client.onmessage = this.onMessage.bind(this);
41
- this.client.onopen = () => {
48
+ this.client.onopen = ()=>{
42
49
  this.emitter.emit('connect');
43
50
  this._status = 1;
44
51
  };
@@ -51,11 +58,11 @@ class WebsocketClient {
51
58
  this.client = null;
52
59
  }
53
60
  send(data, isJson = false) {
61
+ var _this_client;
54
62
  let res = data;
55
63
  if (isJson) {
56
64
  res = JSON.stringify(data);
57
65
  }
58
- this.client?.send(res);
66
+ (_this_client = this.client) === null || _this_client === void 0 ? void 0 : _this_client.send(res);
59
67
  }
60
68
  }
61
- exports.WebsocketClient = WebsocketClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-web",
3
- "version": "1.0.158",
3
+ "version": "1.0.160",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -19,29 +19,17 @@
19
19
  "node": ">=8.0.0"
20
20
  },
21
21
  "dependencies": {
22
- "pubo-utils": "^1.0.158"
22
+ "pubo-utils": "^1.0.160"
23
23
  },
24
- "gitHead": "3d5dad6acb147bf7a844a51c348036968f9a33dc",
24
+ "gitHead": "0d4d8a1ca05d6907dd386d9f8bc4b120ec2c40a2",
25
25
  "devDependencies": {
26
- "@babel/cli": "^7.10.1",
27
- "@babel/core": "^7.10.2",
28
- "@babel/preset-env": "^7.20.2",
29
- "babel-loader": "^8.1.0",
30
- "babel-plugin-import": "^1.12.0",
31
- "babel-plugin-transform-async-to-promises": "^0.8.15",
32
26
  "del": "^5.1.0",
33
27
  "eslint": "^8.42.0",
34
28
  "eslint-plugin-react-hooks": "^4.0.8",
35
29
  "gulp": "^4.0.2",
36
- "gulp-babel": "^8.0.0",
37
30
  "gulp-typescript": "^6.0.0-alpha.1",
38
- "jest": "^26.0.1",
39
- "jest-fetch-mock": "^3.0.3",
40
- "jest-localstorage-mock": "^2.4.18",
41
31
  "prettier": "^2.8.8",
42
32
  "pretty-quick": "^2.0.1",
43
- "surge": "^0.21.3",
44
- "ts-jest": "^26.1.0",
45
33
  "typescript": "^4.9.5",
46
34
  "webpack": "^5.75.0",
47
35
  "webpack-cli": "^5.0.1",