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.
- package/dist/pubo-web.js +1 -1
- 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
|
|
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.
|
|
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.
|
|
22
|
+
"pubo-utils": "^1.0.192"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "5916cce8a7b16eb69c0770a2075f1e7b1dcc1f85",
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"del": "^5.1.0",
|
|
27
27
|
"eslint": "^8.42.0",
|