pubo-web 1.0.185 → 1.0.192

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.
Files changed (2) hide show
  1. package/dist/pubo-web.js +1 -1
  2. package/package.json +3 -3
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:()=>o,blob2file:()=>n,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 o=i;if(i){if("complete"===i._state)return s(e)}else o=document.createElement("script");for(const e of Object.keys(t))o[e]=t[e];const n=()=>{s(e),o.removeEventListener("load",n),o._state="complete"};return o.src=e,o.addEventListener("load",n),document.body.appendChild(o),"success"})),i=e=>new Promise((t=>{const s=new FileReader;s.onload=e=>t(e.target.result),s.readAsText(e)})),o=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("文件爲空!")})),n=(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])if("function"==typeof s)try{await s(t)}catch(e){console.log(e)}}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 o=null!==(i=e.pageX)&&void 0!==i?i:null===(t=e.touches[0])||void 0===t?void 0:t.pageX;var n;const r=null!==(n=e.pageY)&&void 0!==n?n:null===(s=e.touches[0])||void 0===s?void 0:s.pageY;this.onMove({offsetX:o-this.cache.pageX,offsetY:r-this.cache.pageY,pageX:o,pageY:r,startX:this.cache.pageX,startY:this.cache.pageY,key:this.key}),this.cache.pageX=o,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 o=null!==(i=e.pageX)&&void 0!==i?i:null===(t=e.touches[0])||void 0===t?void 0:t.pageX;var n;const r=null!==(n=e.pageY)&&void 0!==n?n:null===(s=e.touches[0])||void 0===s?void 0:s.pageY;this.cache.dragging=!0,this.cache.pageX=o,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 o=()=>{document.body.removeChild(s),window.removeEventListener("focus",o),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",o),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,o)=>{if(!this.db)return void o("not connect");const n=this.db.transaction([t],"readwrite").objectStore(t),r=e(n,...s);r.onerror=function(e){o(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})()));
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 o in s)e.o(s,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:s[o]})},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:()=>a,WebsocketClient:()=>h,blob2base64:()=>n,blob2file:()=>i,blob2text:()=>o,downloadFile:()=>c,getCookie:()=>p,getCookieValue:()=>d,loadScript:()=>s,pickFiles:()=>u,setCookieItem:()=>g});const s=(e,t={})=>new Promise((s=>{const o=(()=>{const t=document.getElementsByTagName("script");for(const s of t)if(s.src===e)return s;return null})();let n=o;if(o){if("complete"===o._state)return s(e)}else n=document.createElement("script");for(const e of Object.keys(t))n[e]=t[e];const i=()=>{s(e),n.removeEventListener("load",i),n._state="complete"};return n.src=e,n.addEventListener("load",i),document.body.appendChild(n),"success"})),o=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 o=new FileReader;e?(o.onload=e=>t(e.target.result),o.onabort=()=>s(),o.readAsDataURL(e)):s("文件爲空!")})),i=(e,t,s)=>new File(e,t,{type:s}),c=(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 a{_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 r{state={};ids={};on(e,t){if(this.state[e]||(this.state[e]={}),"function"!=typeof t)throw new Error("第二个参数必须为function!");const s=`${((e=8)=>{const t=e=>Math.random().toString(32).slice(2,2+e);if(e<=8)return t(e);let s="";for(let o=0;o<=e;o+=8)s+=t(e-o>8?8:e-o);return s})(40)}_${(new Date).valueOf()}`;return this.state[e][s]=t,this.ids[s]=e,s}cancel(e){if(!e)return void this.clear();const t=this.ids[e];t&&this.state[t]&&(delete this.state[t][e],0===Object.keys(this.state[t]).length&&delete this.state[t],delete this.ids[e])}clear(){this.state={},this.ids={}}emit(e,t){if(this.state[e])for(const s of Object.keys(this.state[e])){const o=this.state[e][s];"function"==typeof o&&o(t)}}async emitSync(e,t){if(this.state[e])for(const s of Object.keys(this.state[e])){const o=this.state[e][s];if("function"==typeof o)try{await o(t)}catch(e){console.log(e)}}}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 r;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 o=e;t&&(o=JSON.stringify(e)),null===(s=this.client)||void 0===s||s.send(o)}}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,o;if("function"!=typeof this.onMove)return;e.preventDefault?e.preventDefault():e.returnValue=!1;const n=null!==(o=e.pageX)&&void 0!==o?o:null===(t=e.touches[0])||void 0===t?void 0:t.pageX;var i;const c=null!==(i=e.pageY)&&void 0!==i?i:null===(s=e.touches[0])||void 0===s?void 0:s.pageY;this.onMove({offsetX:n-this.cache.pageX,offsetY:c-this.cache.pageY,pageX:n,pageY:c,startX:this.cache.pageX,startY:this.cache.pageY,key:this.key}),this.cache.pageX=n,this.cache.pageY=c}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,o;if(e.preventDefault&&e.pageX?e.preventDefault():e.returnValue=!1,"function"!=typeof this.onMove||this.cache.dragging)return;this.clearListener();const n=null!==(o=e.pageX)&&void 0!==o?o:null===(t=e.touches[0])||void 0===t?void 0:t.pageX;var i;const c=null!==(i=e.pageY)&&void 0!==i?i:null===(s=e.touches[0])||void 0===s?void 0:s.pageY;this.cache.dragging=!0,this.cache.pageX=n,this.cache.pageY=c,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 o=!1;const n=()=>{document.body.removeChild(s),window.removeEventListener("focus",n),setTimeout((()=>{o||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=>{o=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,o]=t.split("=");e[s]=o})),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 o=null===(s=this.indexedDB)||void 0===s?void 0:s.open(this.name,this.version);o.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},o.onsuccess=()=>{this.db||(this.db=o.result),e("success")},o.onerror=e=>{console.error("indexed db connect error: ",e),t(e)}}))}createTransaction(e){return(t,...s)=>new Promise(((o,n)=>{if(!this.db)return void n("not connect");const i=this.db.transaction([t],"readwrite").objectStore(t),c=e(i,...s);c.onerror=function(e){n(e)},c.onsuccess=function(){o(c.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-web",
3
- "version": "1.0.185",
3
+ "version": "1.0.192",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -19,9 +19,9 @@
19
19
  "node": ">=8.0.0"
20
20
  },
21
21
  "dependencies": {
22
- "pubo-utils": "^1.0.185"
22
+ "pubo-utils": "^1.0.192"
23
23
  },
24
- "gitHead": "870f649d5ade235140e5641d68dcd818cf3115f6",
24
+ "gitHead": "5916cce8a7b16eb69c0770a2075f1e7b1dcc1f85",
25
25
  "devDependencies": {
26
26
  "del": "^5.1.0",
27
27
  "eslint": "^8.42.0",