pubo-web 1.0.67 → 1.0.69

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,(function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([,function(t,e,n){"use strict";n.r(e),n.d(e,"loadScript",(function(){return r})),n.d(e,"blob2text",(function(){return i})),n.d(e,"blob2base64",(function(){return s})),n.d(e,"blob2file",(function(){return u})),n.d(e,"downloadFile",(function(){return c})),n.d(e,"WebStorage",(function(){return l})),n.d(e,"WebsocketClient",(function(){return y})),n.d(e,"DragMethod",(function(){return m})),n.d(e,"pickFiles",(function(){return g}));var o=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.")},r=function(t,e){void 0===e&&(e={});return new Promise((function(n){var r,i,s=function(){var e,n,r=document.getElementsByTagName("script");try{for(var i=o(r),s=i.next();!s.done;s=i.next()){var u=s.value;if(u.src===t)return u}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return null}(),u=s;if(s){if("complete"===s._state)return n(t)}else u=document.createElement("script");try{for(var c=o(Object.keys(e)),a=c.next();!a.done;a=c.next()){var l=a.value;u[l]=e[l]}}catch(t){r={error:t}}finally{try{a&&!a.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}return u.src=t,u.addEventListener("load",(function e(){n(t),u.removeEventListener("load",e),u._state="complete"})),document.body.appendChild(u),"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)}))},s=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("文件爲空!")}))},u=function(t,e,n){return new File(t,e,{type:n})},c=function(t,e){var n=document.createElement("a");n.href=t,e&&(n.download=e),n.style.position="fixed",n.style.visibility="hidden",document.body.appendChild(n),n.click(),document.body.removeChild(n)},a=function(){return(a=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)},l=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=a(a({},e),t)},t.prototype.clear=function(){this.storage.removeItem(this._key)},t}(),f=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.")},d=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,r,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)s.push(o.value)}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s},h=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(d(arguments[e]));return t},p=function(){function t(){this.state={},this.ids={}}return t.prototype.on=function(t,e){if(this.state[t]||(this.state[t]=[]),"function"!=typeof e)throw new Error("第二个参数必须为function!");var n=this.state[t].push(e)-1,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,r=n.index;o&&Array.isArray(this.state[o])&&(this.state[o].splice(r,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){e.ids[t].event===o&&e.ids[t].index>r&&(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=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];if(Array.isArray(this.state[t]))try{for(var i=f(this.state[t]),s=i.next();!s.done;s=i.next()){var u=s.value;"function"==typeof u&&u.apply(void 0,h(o))}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},t}(),y=function(){function t(t){var e=t.url;this.client=null,this._status=0,this.emitter=new p,this.url=e,this.connect()}return t.prototype.reconnect=function(){var t=this;this.client&&this.client.close(),this.client=null,3===this._status&&setTimeout((function(){return t.connect()}),1e3)},t.prototype.onClose=function(){2!==this._status&&(this._status=3),this.reconnect()},t.prototype.onMessage=function(t){this.emitter.emit("message",t.data)},t.prototype.connect=function(){var t=this;this.client||(this.client=new WebSocket(this.url),this.client.onclose=this.onClose.bind(this),this.client.onmessage=this.onMessage.bind(this),this.client.onopen=function(){t._status=1})},t.prototype.close=function(){this.client&&(this.client.close(),this.client=null,this._status=2)},t.prototype.send=function(t,e){var n;void 0===e&&(e=!1);var o=t;e&&(o=JSON.stringify(t)),null===(n=this.client)||void 0===n||n.send(o)},t}(),v=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,r,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)s.push(o.value)}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s},b=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(v(arguments[e]));return t};var m=function(){function t(t){var e,n,o,r,i=void 0===t?{}:t,s=i.key,u=void 0===s?"":s,c=i.onMove,a=i.onMoveEnd;this.key="",this.cache={pageX:0,pageY:0},this.key=u,this.onMouseDown=this._onMouseDown.bind(this),this.onMouseMove=(e=this._onMouseMove.bind(this),n=10,r=!0,function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];o||(o=setTimeout((function(){r=!0,o=null}),n)),r&&(r=!1,e.apply(void 0,b(t)))}),this.onMouseUp=this._onMouseUp.bind(this),this.onMove=c,this.onMoveEnd=a}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),"function"==typeof this.onMoveEnd&&this.onMoveEnd()},t.prototype._onMouseDown=function(t){"function"==typeof this.onMove&&(this.cache.pageX=t.pageX,this.cache.pageY=t.pageY,window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("mouseup",this.onMouseUp))},t}(),g=function(){return new Promise((function(t){var e=document.createElement("input");e.type="file",e.style.visibility="hidden",e.style.position="fixed",e.style.top="0px",e.style.zIndex="-1",window.addEventListener("focus",(function t(){document.body.removeChild(e),window.removeEventListener("focus",t)})),e.onchange=function(e){t(e.target.files)},document.body.appendChild(e),e.click()}))}}])}));
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:()=>m,WebStorage:()=>u,WebsocketClient:()=>p,blob2base64:()=>r,blob2file:()=>s,blob2text:()=>i,downloadFile:()=>a,loadScript:()=>o,pickFiles:()=>b});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},m=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},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),"function"==typeof this.onMoveEnd&&this.onMoveEnd()},t.prototype._onMouseDown=function(t){"function"==typeof this.onMove&&(this.cache.pageX=t.pageX,this.cache.pageY=t.pageY,window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("mouseup",this.onMouseUp))},t}(),b=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
@@ -1,9 +1,9 @@
1
- declare type OnMove = (n: {
1
+ type OnMove = (n: {
2
2
  offsetX: number;
3
3
  offsetY: number;
4
4
  key?: string;
5
5
  }) => void;
6
- declare type OnMoveEnd = () => void;
6
+ type OnMoveEnd = () => void;
7
7
  interface DragMethodProps {
8
8
  key?: string;
9
9
  onMove?: OnMove;
package/es/dom/drag.js CHANGED
@@ -1,15 +1,11 @@
1
1
  import { throttle } from 'pubo-utils';
2
-
3
- var DragMethod =
4
- /** @class */
5
- function () {
2
+ var DragMethod = /** @class */function () {
6
3
  function DragMethod(_a) {
7
4
  var _b = _a === void 0 ? {} : _a,
8
- _c = _b.key,
9
- key = _c === void 0 ? '' : _c,
10
- onMove = _b.onMove,
11
- onMoveEnd = _b.onMoveEnd;
12
-
5
+ _c = _b.key,
6
+ key = _c === void 0 ? '' : _c,
7
+ onMove = _b.onMove,
8
+ onMoveEnd = _b.onMoveEnd;
13
9
  this.key = '';
14
10
  this.cache = {
15
11
  pageX: 0,
@@ -22,12 +18,10 @@ function () {
22
18
  this.onMove = onMove;
23
19
  this.onMoveEnd = onMoveEnd;
24
20
  }
25
-
26
21
  DragMethod.prototype._onMouseMove = function (e) {
27
22
  if (typeof this.onMove !== 'function') {
28
23
  return;
29
24
  }
30
-
31
25
  this.onMove({
32
26
  offsetX: e.pageX - this.cache.pageX,
33
27
  offsetY: e.pageY - this.cache.pageY,
@@ -36,28 +30,22 @@ function () {
36
30
  this.cache.pageX = e.pageX;
37
31
  this.cache.pageY = e.pageY;
38
32
  };
39
-
40
33
  DragMethod.prototype._onMouseUp = function () {
41
34
  window.removeEventListener('mousemove', this.onMouseMove);
42
35
  window.removeEventListener('mouseup', this.onMouseUp);
43
-
44
36
  if (typeof this.onMoveEnd === 'function') {
45
37
  this.onMoveEnd();
46
38
  }
47
39
  };
48
-
49
40
  DragMethod.prototype._onMouseDown = function (e) {
50
41
  if (typeof this.onMove !== 'function') {
51
42
  return;
52
43
  }
53
-
54
44
  this.cache.pageX = e.pageX;
55
45
  this.cache.pageY = e.pageY;
56
46
  window.addEventListener('mousemove', this.onMouseMove);
57
47
  window.addEventListener('mouseup', this.onMouseUp);
58
48
  };
59
-
60
49
  return DragMethod;
61
50
  }();
62
-
63
51
  export { DragMethod };
@@ -1,11 +1,9 @@
1
1
  export var downloadFile = function downloadFile(uri, name) {
2
2
  var a = document.createElement('a');
3
3
  a.href = uri;
4
-
5
4
  if (name) {
6
5
  a.download = name;
7
6
  }
8
-
9
7
  a.style.position = 'fixed';
10
8
  a.style.visibility = 'hidden';
11
9
  document.body.appendChild(a);
package/es/file/parser.js CHANGED
@@ -1,29 +1,24 @@
1
1
  export var blob2text = function blob2text(blob) {
2
2
  return new Promise(function (resolve) {
3
3
  var reader = new FileReader();
4
-
5
4
  reader.onload = function (e) {
6
5
  return resolve(e.target.result);
7
6
  };
8
-
9
7
  reader.readAsText(blob);
10
8
  });
11
9
  };
12
10
  export var blob2base64 = function blob2base64(blob) {
13
11
  return new Promise(function (resolve, reject) {
14
12
  var reader = new FileReader();
15
-
16
13
  if (!blob) {
17
14
  reject('文件爲空!');
18
15
  } else {
19
16
  reader.onload = function (e) {
20
17
  return resolve(e.target.result);
21
18
  };
22
-
23
19
  reader.onabort = function () {
24
20
  return reject();
25
21
  };
26
-
27
22
  reader.readAsDataURL(blob);
28
23
  }
29
24
  });
package/es/file/pick.js CHANGED
@@ -1,23 +1,19 @@
1
1
  export var pickFiles = function pickFiles() {
2
2
  return new Promise(function (resolve) {
3
3
  var el = document.createElement('input');
4
-
5
4
  var onFocus = function onFocus() {
6
5
  document.body.removeChild(el);
7
6
  window.removeEventListener('focus', onFocus);
8
7
  };
9
-
10
8
  el.type = 'file';
11
9
  el.style.visibility = 'hidden';
12
10
  el.style.position = 'fixed';
13
11
  el.style.top = '0px';
14
12
  el.style.zIndex = '-1';
15
13
  window.addEventListener('focus', onFocus);
16
-
17
14
  el.onchange = function (e) {
18
15
  resolve(e.target.files);
19
16
  };
20
-
21
17
  document.body.appendChild(el);
22
18
  el.click();
23
19
  });
@@ -1,7 +1,7 @@
1
1
  var __values = this && this.__values || function (o) {
2
2
  var s = typeof Symbol === "function" && Symbol.iterator,
3
- m = s && o[s],
4
- i = 0;
3
+ m = s && o[s],
4
+ i = 0;
5
5
  if (m) return m.call(o);
6
6
  if (o && typeof o.length === "number") return {
7
7
  next: function next() {
@@ -14,21 +14,16 @@ var __values = this && this.__values || function (o) {
14
14
  };
15
15
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
16
16
  };
17
-
18
17
  export var loadScript = function loadScript(url, options) {
19
18
  if (options === void 0) {
20
19
  options = {};
21
20
  }
22
-
23
21
  var findScript = function findScript() {
24
22
  var e_1, _a;
25
-
26
23
  var list = document.getElementsByTagName('script');
27
-
28
24
  try {
29
25
  for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
30
26
  var item = list_1_1.value;
31
-
32
27
  if (item.src === url) {
33
28
  return item;
34
29
  }
@@ -44,22 +39,17 @@ export var loadScript = function loadScript(url, options) {
44
39
  if (e_1) throw e_1.error;
45
40
  }
46
41
  }
47
-
48
42
  return null;
49
43
  };
50
-
51
44
  return new Promise(function (resolve) {
52
45
  var e_2, _a;
53
-
54
46
  var old = findScript();
55
47
  var el = old;
56
-
57
48
  if (!old) {
58
49
  el = document.createElement('script');
59
50
  } else if (old._state === 'complete') {
60
51
  return resolve(url);
61
52
  }
62
-
63
53
  try {
64
54
  for (var _b = __values(Object.keys(options)), _c = _b.next(); !_c.done; _c = _b.next()) {
65
55
  var key = _c.value;
@@ -76,13 +66,11 @@ export var loadScript = function loadScript(url, options) {
76
66
  if (e_2) throw e_2.error;
77
67
  }
78
68
  }
79
-
80
69
  var onLoad = function onLoad() {
81
70
  resolve(url);
82
71
  el.removeEventListener('load', onLoad);
83
72
  el._state = 'complete';
84
73
  };
85
-
86
74
  el.src = url;
87
75
  el.addEventListener('load', onLoad);
88
76
  document.body.appendChild(el);
@@ -1,4 +1,4 @@
1
- declare type StorageType = 'sessionStorage' | 'localStorage';
1
+ type StorageType = 'sessionStorage' | 'localStorage';
2
2
  interface Zip {
3
3
  deflate: (data: string) => string;
4
4
  inflate: (data: string) => string;
@@ -2,38 +2,27 @@ var __assign = this && this.__assign || function () {
2
2
  __assign = Object.assign || function (t) {
3
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
4
4
  s = arguments[i];
5
-
6
- for (var p in s) {
7
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
- }
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
9
6
  }
10
-
11
7
  return t;
12
8
  };
13
-
14
9
  return __assign.apply(this, arguments);
15
10
  };
16
-
17
- var WebStorage =
18
- /** @class */
19
- function () {
11
+ var WebStorage = /** @class */function () {
20
12
  function WebStorage(props) {
21
13
  var _a = props.type,
22
- type = _a === void 0 ? 'sessionStorage' : _a,
23
- key = props.key;
14
+ type = _a === void 0 ? 'sessionStorage' : _a,
15
+ key = props.key;
24
16
  this._key = key;
25
17
  this.storage = window[type];
26
18
  this.zip = props.zip;
27
19
  }
28
-
29
20
  Object.defineProperty(WebStorage.prototype, "state", {
30
21
  get: function get() {
31
22
  var value = this.storage.getItem(this._key);
32
-
33
23
  if (this.zip && value) {
34
24
  value = this.zip.inflate(value);
35
25
  }
36
-
37
26
  if (value) {
38
27
  return JSON.parse(value);
39
28
  } else {
@@ -42,11 +31,9 @@ function () {
42
31
  },
43
32
  set: function set(data) {
44
33
  var temp = JSON.stringify(data);
45
-
46
34
  if (this.zip) {
47
35
  temp = this.zip.deflate(temp);
48
36
  }
49
-
50
37
  this.storage.setItem(this._key, temp);
51
38
  },
52
39
  enumerable: false,
@@ -59,17 +46,13 @@ function () {
59
46
  enumerable: false,
60
47
  configurable: true
61
48
  });
62
-
63
49
  WebStorage.prototype.merge = function (data) {
64
50
  var old = this.state;
65
51
  this.state = __assign(__assign({}, old), data);
66
52
  };
67
-
68
53
  WebStorage.prototype.clear = function () {
69
54
  this.storage.removeItem(this._key);
70
55
  };
71
-
72
56
  return WebStorage;
73
57
  }();
74
-
75
58
  export { WebStorage };
@@ -1,8 +1,5 @@
1
1
  import { Emitter } from 'pubo-utils';
2
-
3
- var WebsocketClient =
4
- /** @class */
5
- function () {
2
+ var WebsocketClient = /** @class */function () {
6
3
  function WebsocketClient(_a) {
7
4
  var url = _a.url;
8
5
  this.client = null;
@@ -11,51 +8,39 @@ function () {
11
8
  this.url = url;
12
9
  this.connect();
13
10
  }
14
-
15
11
  WebsocketClient.prototype.reconnect = function () {
16
12
  var _this = this;
17
-
18
13
  if (this.client) {
19
14
  this.client.close();
20
15
  }
21
-
22
16
  this.client = null;
23
-
24
17
  if (this._status === 3) {
25
18
  setTimeout(function () {
26
19
  return _this.connect();
27
20
  }, 1000);
28
21
  }
29
22
  };
30
-
31
23
  WebsocketClient.prototype.onClose = function () {
32
24
  if (this._status !== 2) {
33
25
  this._status = 3;
34
26
  }
35
-
36
27
  this.reconnect();
37
28
  };
38
-
39
29
  WebsocketClient.prototype.onMessage = function (e) {
40
30
  this.emitter.emit('message', e.data);
41
31
  };
42
-
43
32
  WebsocketClient.prototype.connect = function () {
44
33
  var _this = this;
45
-
46
34
  if (this.client) {
47
35
  return;
48
36
  }
49
-
50
37
  this.client = new WebSocket(this.url);
51
38
  this.client.onclose = this.onClose.bind(this);
52
39
  this.client.onmessage = this.onMessage.bind(this);
53
-
54
40
  this.client.onopen = function () {
55
41
  _this._status = 1;
56
42
  };
57
43
  };
58
-
59
44
  WebsocketClient.prototype.close = function () {
60
45
  if (this.client) {
61
46
  this.client.close();
@@ -63,24 +48,17 @@ function () {
63
48
  this._status = 2;
64
49
  }
65
50
  };
66
-
67
51
  WebsocketClient.prototype.send = function (data, isJson) {
68
52
  var _a;
69
-
70
53
  if (isJson === void 0) {
71
54
  isJson = false;
72
55
  }
73
-
74
56
  var res = data;
75
-
76
57
  if (isJson) {
77
58
  res = JSON.stringify(data);
78
59
  }
79
-
80
60
  (_a = this.client) === null || _a === void 0 ? void 0 : _a.send(res);
81
61
  };
82
-
83
62
  return WebsocketClient;
84
63
  }();
85
-
86
64
  export default WebsocketClient;
package/lib/dom/drag.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- declare type OnMove = (n: {
1
+ type OnMove = (n: {
2
2
  offsetX: number;
3
3
  offsetY: number;
4
4
  key?: string;
5
5
  }) => void;
6
- declare type OnMoveEnd = () => void;
6
+ type OnMoveEnd = () => void;
7
7
  interface DragMethodProps {
8
8
  key?: string;
9
9
  onMove?: OnMove;
package/lib/dom/drag.js CHANGED
@@ -4,19 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DragMethod = void 0;
7
-
8
7
  var pubo_utils_1 = require("pubo-utils");
9
-
10
- var DragMethod =
11
- /** @class */
12
- function () {
8
+ var DragMethod = /** @class */function () {
13
9
  function DragMethod(_a) {
14
10
  var _b = _a === void 0 ? {} : _a,
15
- _c = _b.key,
16
- key = _c === void 0 ? '' : _c,
17
- onMove = _b.onMove,
18
- onMoveEnd = _b.onMoveEnd;
19
-
11
+ _c = _b.key,
12
+ key = _c === void 0 ? '' : _c,
13
+ onMove = _b.onMove,
14
+ onMoveEnd = _b.onMoveEnd;
20
15
  this.key = '';
21
16
  this.cache = {
22
17
  pageX: 0,
@@ -24,17 +19,15 @@ function () {
24
19
  };
25
20
  this.key = key;
26
21
  this.onMouseDown = this._onMouseDown.bind(this);
27
- this.onMouseMove = pubo_utils_1.throttle(this._onMouseMove.bind(this), 1000 / 100);
22
+ this.onMouseMove = (0, pubo_utils_1.throttle)(this._onMouseMove.bind(this), 1000 / 100);
28
23
  this.onMouseUp = this._onMouseUp.bind(this);
29
24
  this.onMove = onMove;
30
25
  this.onMoveEnd = onMoveEnd;
31
26
  }
32
-
33
27
  DragMethod.prototype._onMouseMove = function (e) {
34
28
  if (typeof this.onMove !== 'function') {
35
29
  return;
36
30
  }
37
-
38
31
  this.onMove({
39
32
  offsetX: e.pageX - this.cache.pageX,
40
33
  offsetY: e.pageY - this.cache.pageY,
@@ -43,28 +36,22 @@ function () {
43
36
  this.cache.pageX = e.pageX;
44
37
  this.cache.pageY = e.pageY;
45
38
  };
46
-
47
39
  DragMethod.prototype._onMouseUp = function () {
48
40
  window.removeEventListener('mousemove', this.onMouseMove);
49
41
  window.removeEventListener('mouseup', this.onMouseUp);
50
-
51
42
  if (typeof this.onMoveEnd === 'function') {
52
43
  this.onMoveEnd();
53
44
  }
54
45
  };
55
-
56
46
  DragMethod.prototype._onMouseDown = function (e) {
57
47
  if (typeof this.onMove !== 'function') {
58
48
  return;
59
49
  }
60
-
61
50
  this.cache.pageX = e.pageX;
62
51
  this.cache.pageY = e.pageY;
63
52
  window.addEventListener('mousemove', this.onMouseMove);
64
53
  window.addEventListener('mouseup', this.onMouseUp);
65
54
  };
66
-
67
55
  return DragMethod;
68
56
  }();
69
-
70
57
  exports.DragMethod = DragMethod;
@@ -4,18 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.downloadFile = void 0;
7
-
8
- exports.downloadFile = function (uri, name) {
7
+ var downloadFile = function downloadFile(uri, name) {
9
8
  var a = document.createElement('a');
10
9
  a.href = uri;
11
-
12
10
  if (name) {
13
11
  a.download = name;
14
12
  }
15
-
16
13
  a.style.position = 'fixed';
17
14
  a.style.visibility = 'hidden';
18
15
  document.body.appendChild(a);
19
16
  a.click();
20
17
  document.body.removeChild(a);
21
- };
18
+ };
19
+ exports.downloadFile = downloadFile;
@@ -4,41 +4,36 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.blob2file = exports.blob2base64 = exports.blob2text = void 0;
7
-
8
- exports.blob2text = function (blob) {
7
+ var blob2text = function blob2text(blob) {
9
8
  return new Promise(function (resolve) {
10
9
  var reader = new FileReader();
11
-
12
10
  reader.onload = function (e) {
13
11
  return resolve(e.target.result);
14
12
  };
15
-
16
13
  reader.readAsText(blob);
17
14
  });
18
15
  };
19
-
20
- exports.blob2base64 = function (blob) {
16
+ exports.blob2text = blob2text;
17
+ var blob2base64 = function blob2base64(blob) {
21
18
  return new Promise(function (resolve, reject) {
22
19
  var reader = new FileReader();
23
-
24
20
  if (!blob) {
25
21
  reject('文件爲空!');
26
22
  } else {
27
23
  reader.onload = function (e) {
28
24
  return resolve(e.target.result);
29
25
  };
30
-
31
26
  reader.onabort = function () {
32
27
  return reject();
33
28
  };
34
-
35
29
  reader.readAsDataURL(blob);
36
30
  }
37
31
  });
38
32
  };
39
-
40
- exports.blob2file = function (blob, name, type) {
33
+ exports.blob2base64 = blob2base64;
34
+ var blob2file = function blob2file(blob, name, type) {
41
35
  return new File(blob, name, {
42
36
  type: type
43
37
  });
44
- };
38
+ };
39
+ exports.blob2file = blob2file;
package/lib/file/pick.js CHANGED
@@ -4,28 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.pickFiles = void 0;
7
-
8
- exports.pickFiles = function () {
7
+ var pickFiles = function pickFiles() {
9
8
  return new Promise(function (resolve) {
10
9
  var el = document.createElement('input');
11
-
12
10
  var onFocus = function onFocus() {
13
11
  document.body.removeChild(el);
14
12
  window.removeEventListener('focus', onFocus);
15
13
  };
16
-
17
14
  el.type = 'file';
18
15
  el.style.visibility = 'hidden';
19
16
  el.style.position = 'fixed';
20
17
  el.style.top = '0px';
21
18
  el.style.zIndex = '-1';
22
19
  window.addEventListener('focus', onFocus);
23
-
24
20
  el.onchange = function (e) {
25
21
  resolve(e.target.files);
26
22
  };
27
-
28
23
  document.body.appendChild(el);
29
24
  el.click();
30
25
  });
31
- };
26
+ };
27
+ exports.pickFiles = pickFiles;
package/lib/index.js CHANGED
@@ -1,20 +1,22 @@
1
1
  "use strict";
2
2
 
3
+ var __importDefault = this && this.__importDefault || function (mod) {
4
+ return mod && mod.__esModule ? mod : {
5
+ "default": mod
6
+ };
7
+ };
3
8
  Object.defineProperty(exports, "__esModule", {
4
9
  value: true
5
10
  });
6
-
11
+ exports.pickFiles = exports.DragMethod = exports.WebsocketClient = exports.WebStorage = exports.downloadFile = exports.blob2file = exports.blob2base64 = exports.blob2text = exports.loadScript = void 0;
7
12
  var load_script_1 = require("./load-script");
8
-
9
13
  Object.defineProperty(exports, "loadScript", {
10
14
  enumerable: true,
11
15
  get: function get() {
12
16
  return load_script_1.loadScript;
13
17
  }
14
18
  });
15
-
16
19
  var parser_1 = require("./file/parser");
17
-
18
20
  Object.defineProperty(exports, "blob2text", {
19
21
  enumerable: true,
20
22
  get: function get() {
@@ -33,45 +35,35 @@ Object.defineProperty(exports, "blob2file", {
33
35
  return parser_1.blob2file;
34
36
  }
35
37
  });
36
-
37
38
  var download_1 = require("./file/download");
38
-
39
39
  Object.defineProperty(exports, "downloadFile", {
40
40
  enumerable: true,
41
41
  get: function get() {
42
42
  return download_1.downloadFile;
43
43
  }
44
44
  });
45
-
46
45
  var storage_1 = require("./storage");
47
-
48
46
  Object.defineProperty(exports, "WebStorage", {
49
47
  enumerable: true,
50
48
  get: function get() {
51
49
  return storage_1.WebStorage;
52
50
  }
53
51
  });
54
-
55
52
  var client_1 = require("./websocket/client");
56
-
57
53
  Object.defineProperty(exports, "WebsocketClient", {
58
54
  enumerable: true,
59
55
  get: function get() {
60
- return client_1["default"];
56
+ return __importDefault(client_1)["default"];
61
57
  }
62
58
  });
63
-
64
59
  var drag_1 = require("./dom/drag");
65
-
66
60
  Object.defineProperty(exports, "DragMethod", {
67
61
  enumerable: true,
68
62
  get: function get() {
69
63
  return drag_1.DragMethod;
70
64
  }
71
65
  });
72
-
73
66
  var pick_1 = require("./file/pick");
74
-
75
67
  Object.defineProperty(exports, "pickFiles", {
76
68
  enumerable: true,
77
69
  get: function get() {
@@ -2,8 +2,8 @@
2
2
 
3
3
  var __values = this && this.__values || function (o) {
4
4
  var s = typeof Symbol === "function" && Symbol.iterator,
5
- m = s && o[s],
6
- i = 0;
5
+ m = s && o[s],
6
+ i = 0;
7
7
  if (m) return m.call(o);
8
8
  if (o && typeof o.length === "number") return {
9
9
  next: function next() {
@@ -16,26 +16,20 @@ var __values = this && this.__values || function (o) {
16
16
  };
17
17
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
18
18
  };
19
-
20
19
  Object.defineProperty(exports, "__esModule", {
21
20
  value: true
22
21
  });
23
22
  exports.loadScript = void 0;
24
-
25
- exports.loadScript = function (url, options) {
23
+ var loadScript = function loadScript(url, options) {
26
24
  if (options === void 0) {
27
25
  options = {};
28
26
  }
29
-
30
27
  var findScript = function findScript() {
31
28
  var e_1, _a;
32
-
33
29
  var list = document.getElementsByTagName('script');
34
-
35
30
  try {
36
31
  for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
37
32
  var item = list_1_1.value;
38
-
39
33
  if (item.src === url) {
40
34
  return item;
41
35
  }
@@ -51,22 +45,17 @@ exports.loadScript = function (url, options) {
51
45
  if (e_1) throw e_1.error;
52
46
  }
53
47
  }
54
-
55
48
  return null;
56
49
  };
57
-
58
50
  return new Promise(function (resolve) {
59
51
  var e_2, _a;
60
-
61
52
  var old = findScript();
62
53
  var el = old;
63
-
64
54
  if (!old) {
65
55
  el = document.createElement('script');
66
56
  } else if (old._state === 'complete') {
67
57
  return resolve(url);
68
58
  }
69
-
70
59
  try {
71
60
  for (var _b = __values(Object.keys(options)), _c = _b.next(); !_c.done; _c = _b.next()) {
72
61
  var key = _c.value;
@@ -83,16 +72,15 @@ exports.loadScript = function (url, options) {
83
72
  if (e_2) throw e_2.error;
84
73
  }
85
74
  }
86
-
87
75
  var onLoad = function onLoad() {
88
76
  resolve(url);
89
77
  el.removeEventListener('load', onLoad);
90
78
  el._state = 'complete';
91
79
  };
92
-
93
80
  el.src = url;
94
81
  el.addEventListener('load', onLoad);
95
82
  document.body.appendChild(el);
96
83
  return 'success';
97
84
  });
98
- };
85
+ };
86
+ exports.loadScript = loadScript;
@@ -1,4 +1,4 @@
1
- declare type StorageType = 'sessionStorage' | 'localStorage';
1
+ type StorageType = 'sessionStorage' | 'localStorage';
2
2
  interface Zip {
3
3
  deflate: (data: string) => string;
4
4
  inflate: (data: string) => string;
@@ -4,43 +4,31 @@ var __assign = this && this.__assign || function () {
4
4
  __assign = Object.assign || function (t) {
5
5
  for (var s, i = 1, n = arguments.length; i < n; i++) {
6
6
  s = arguments[i];
7
-
8
- for (var p in s) {
9
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
10
- }
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
11
8
  }
12
-
13
9
  return t;
14
10
  };
15
-
16
11
  return __assign.apply(this, arguments);
17
12
  };
18
-
19
13
  Object.defineProperty(exports, "__esModule", {
20
14
  value: true
21
15
  });
22
16
  exports.WebStorage = void 0;
23
-
24
- var WebStorage =
25
- /** @class */
26
- function () {
17
+ var WebStorage = /** @class */function () {
27
18
  function WebStorage(props) {
28
19
  var _a = props.type,
29
- type = _a === void 0 ? 'sessionStorage' : _a,
30
- key = props.key;
20
+ type = _a === void 0 ? 'sessionStorage' : _a,
21
+ key = props.key;
31
22
  this._key = key;
32
23
  this.storage = window[type];
33
24
  this.zip = props.zip;
34
25
  }
35
-
36
26
  Object.defineProperty(WebStorage.prototype, "state", {
37
27
  get: function get() {
38
28
  var value = this.storage.getItem(this._key);
39
-
40
29
  if (this.zip && value) {
41
30
  value = this.zip.inflate(value);
42
31
  }
43
-
44
32
  if (value) {
45
33
  return JSON.parse(value);
46
34
  } else {
@@ -49,11 +37,9 @@ function () {
49
37
  },
50
38
  set: function set(data) {
51
39
  var temp = JSON.stringify(data);
52
-
53
40
  if (this.zip) {
54
41
  temp = this.zip.deflate(temp);
55
42
  }
56
-
57
43
  this.storage.setItem(this._key, temp);
58
44
  },
59
45
  enumerable: false,
@@ -66,17 +52,13 @@ function () {
66
52
  enumerable: false,
67
53
  configurable: true
68
54
  });
69
-
70
55
  WebStorage.prototype.merge = function (data) {
71
56
  var old = this.state;
72
57
  this.state = __assign(__assign({}, old), data);
73
58
  };
74
-
75
59
  WebStorage.prototype.clear = function () {
76
60
  this.storage.removeItem(this._key);
77
61
  };
78
-
79
62
  return WebStorage;
80
63
  }();
81
-
82
64
  exports.WebStorage = WebStorage;
@@ -3,12 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var pubo_utils_1 = require("pubo-utils");
8
-
9
- var WebsocketClient =
10
- /** @class */
11
- function () {
7
+ var WebsocketClient = /** @class */function () {
12
8
  function WebsocketClient(_a) {
13
9
  var url = _a.url;
14
10
  this.client = null;
@@ -17,51 +13,39 @@ function () {
17
13
  this.url = url;
18
14
  this.connect();
19
15
  }
20
-
21
16
  WebsocketClient.prototype.reconnect = function () {
22
17
  var _this = this;
23
-
24
18
  if (this.client) {
25
19
  this.client.close();
26
20
  }
27
-
28
21
  this.client = null;
29
-
30
22
  if (this._status === 3) {
31
23
  setTimeout(function () {
32
24
  return _this.connect();
33
25
  }, 1000);
34
26
  }
35
27
  };
36
-
37
28
  WebsocketClient.prototype.onClose = function () {
38
29
  if (this._status !== 2) {
39
30
  this._status = 3;
40
31
  }
41
-
42
32
  this.reconnect();
43
33
  };
44
-
45
34
  WebsocketClient.prototype.onMessage = function (e) {
46
35
  this.emitter.emit('message', e.data);
47
36
  };
48
-
49
37
  WebsocketClient.prototype.connect = function () {
50
38
  var _this = this;
51
-
52
39
  if (this.client) {
53
40
  return;
54
41
  }
55
-
56
42
  this.client = new WebSocket(this.url);
57
43
  this.client.onclose = this.onClose.bind(this);
58
44
  this.client.onmessage = this.onMessage.bind(this);
59
-
60
45
  this.client.onopen = function () {
61
46
  _this._status = 1;
62
47
  };
63
48
  };
64
-
65
49
  WebsocketClient.prototype.close = function () {
66
50
  if (this.client) {
67
51
  this.client.close();
@@ -69,24 +53,17 @@ function () {
69
53
  this._status = 2;
70
54
  }
71
55
  };
72
-
73
56
  WebsocketClient.prototype.send = function (data, isJson) {
74
57
  var _a;
75
-
76
58
  if (isJson === void 0) {
77
59
  isJson = false;
78
60
  }
79
-
80
61
  var res = data;
81
-
82
62
  if (isJson) {
83
63
  res = JSON.stringify(data);
84
64
  }
85
-
86
65
  (_a = this.client) === null || _a === void 0 ? void 0 : _a.send(res);
87
66
  };
88
-
89
67
  return WebsocketClient;
90
68
  }();
91
-
92
69
  exports["default"] = WebsocketClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-web",
3
- "version": "1.0.67",
3
+ "version": "1.0.69",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -19,8 +19,7 @@
19
19
  "node": ">=8.0.0"
20
20
  },
21
21
  "dependencies": {
22
- "pubo-utils": "^1.0.67",
23
- "roslib": "^1.2.0"
22
+ "pubo-utils": "^1.0.69"
24
23
  },
25
- "gitHead": "16e383170f644fddb2732f1767f2b424b2b9effb"
24
+ "gitHead": "1d63c277c36fc7e451e0a685e9d29f9082efc483"
26
25
  }