pubo-web 1.0.71 → 1.0.72

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._onMouseUp=function(){window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("mouseup",this.onMouseUp),this.cache.dragging=!1,"function"==typeof this.onMoveEnd&&this.onMoveEnd()},t.prototype._onMouseDown=function(t){"function"!=typeof this.onMove||this.cache.dragging||(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 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})()));
package/es/dom/drag.d.ts CHANGED
@@ -19,6 +19,7 @@ export declare class DragMethod {
19
19
  onMoveEnd?: OnMoveEnd;
20
20
  constructor({ key, onMove, onMoveEnd }?: DragMethodProps);
21
21
  private _onMouseMove;
22
+ private clearListener;
22
23
  private _onMouseUp;
23
24
  private _onMouseDown;
24
25
  }
package/es/dom/drag.js CHANGED
@@ -31,18 +31,27 @@ var DragMethod = /** @class */function () {
31
31
  this.cache.pageX = e.pageX;
32
32
  this.cache.pageY = e.pageY;
33
33
  };
34
- DragMethod.prototype._onMouseUp = function () {
34
+ DragMethod.prototype.clearListener = function () {
35
35
  window.removeEventListener('mousemove', this.onMouseMove);
36
36
  window.removeEventListener('mouseup', this.onMouseUp);
37
+ };
38
+ DragMethod.prototype._onMouseUp = function () {
39
+ this.clearListener();
37
40
  this.cache.dragging = false;
38
41
  if (typeof this.onMoveEnd === 'function') {
39
42
  this.onMoveEnd();
40
43
  }
41
44
  };
42
45
  DragMethod.prototype._onMouseDown = function (e) {
46
+ if (e.preventDefault) {
47
+ e.preventDefault();
48
+ } else {
49
+ e.returnValue = false;
50
+ }
43
51
  if (typeof this.onMove !== 'function' || this.cache.dragging) {
44
52
  return;
45
53
  }
54
+ this.clearListener();
46
55
  this.cache.dragging = true;
47
56
  this.cache.pageX = e.pageX;
48
57
  this.cache.pageY = e.pageY;
package/lib/dom/drag.d.ts CHANGED
@@ -19,6 +19,7 @@ export declare class DragMethod {
19
19
  onMoveEnd?: OnMoveEnd;
20
20
  constructor({ key, onMove, onMoveEnd }?: DragMethodProps);
21
21
  private _onMouseMove;
22
+ private clearListener;
22
23
  private _onMouseUp;
23
24
  private _onMouseDown;
24
25
  }
package/lib/dom/drag.js CHANGED
@@ -37,18 +37,27 @@ var DragMethod = /** @class */function () {
37
37
  this.cache.pageX = e.pageX;
38
38
  this.cache.pageY = e.pageY;
39
39
  };
40
- DragMethod.prototype._onMouseUp = function () {
40
+ DragMethod.prototype.clearListener = function () {
41
41
  window.removeEventListener('mousemove', this.onMouseMove);
42
42
  window.removeEventListener('mouseup', this.onMouseUp);
43
+ };
44
+ DragMethod.prototype._onMouseUp = function () {
45
+ this.clearListener();
43
46
  this.cache.dragging = false;
44
47
  if (typeof this.onMoveEnd === 'function') {
45
48
  this.onMoveEnd();
46
49
  }
47
50
  };
48
51
  DragMethod.prototype._onMouseDown = function (e) {
52
+ if (e.preventDefault) {
53
+ e.preventDefault();
54
+ } else {
55
+ e.returnValue = false;
56
+ }
49
57
  if (typeof this.onMove !== 'function' || this.cache.dragging) {
50
58
  return;
51
59
  }
60
+ this.clearListener();
52
61
  this.cache.dragging = true;
53
62
  this.cache.pageX = e.pageX;
54
63
  this.cache.pageY = e.pageY;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-web",
3
- "version": "1.0.71",
3
+ "version": "1.0.72",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -21,5 +21,5 @@
21
21
  "dependencies": {
22
22
  "pubo-utils": "^1.0.69"
23
23
  },
24
- "gitHead": "863dd647559583ea4262fc680496f24ef56a45e9"
24
+ "gitHead": "0dd3addce91d22983585ecd97d1f3750fc724c1a"
25
25
  }