pubo-web 1.0.39 → 1.0.41

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 a})),n.d(e,"WebStorage",(function(){return f})),n.d(e,"WebsocketClient",(function(){return y})),n.d(e,"DragMethod",(function(){return m}));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;if(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}())return n(t);var s=document.createElement("script");try{for(var u=o(Object.keys(e)),a=u.next();!a.done;a=u.next()){var c=a.value;s[c]=e[c]}}catch(t){r={error:t}}finally{try{a&&!a.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}return s.src=t,s.onload=function(){return n(t)},document.body.appendChild(s),"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})},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 r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)},f=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.")},h=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},d=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(h(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=l(this.state[t]),s=i.next();!s.done;s=i.next()){var u=s.value;"function"==typeof u&&u.apply(void 0,d(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._status=0,this.url="",this.emitter=new p,this.url=e,this.connect()}return t.prototype.reconnect=function(){var t=this;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=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,a=i.onMove,c=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=a,this.onMoveEnd=c}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}()}])}));
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 a})),n.d(e,"WebStorage",(function(){return f})),n.d(e,"WebsocketClient",(function(){return y})),n.d(e,"DragMethod",(function(){return m}));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;if(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}())return n(t);var s=document.createElement("script");try{for(var u=o(Object.keys(e)),a=u.next();!a.done;a=u.next()){var c=a.value;s[c]=e[c]}}catch(t){r={error:t}}finally{try{a&&!a.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}return s.src=t,s.onload=function(){return n(t)},document.body.appendChild(s),"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})},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 r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)},f=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.")},h=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},d=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(h(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=l(this.state[t]),s=i.next();!s.done;s=i.next()){var u=s.value;"function"==typeof u&&u.apply(void 0,d(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.close(),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,a=i.onMove,c=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=a,this.onMoveEnd=c}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}()}])}));
@@ -5,7 +5,7 @@ export default class WebsocketClient {
5
5
  private readonly url;
6
6
  emitter: Emitter;
7
7
  constructor({ url }: {
8
- url: any;
8
+ url: string;
9
9
  });
10
10
  private reconnect;
11
11
  private onClose;
@@ -5,8 +5,8 @@ var WebsocketClient =
5
5
  function () {
6
6
  function WebsocketClient(_a) {
7
7
  var url = _a.url;
8
+ this.client = null;
8
9
  this._status = 0;
9
- this.url = '';
10
10
  this.emitter = new Emitter();
11
11
  this.url = url;
12
12
  this.connect();
@@ -15,6 +15,8 @@ function () {
15
15
  WebsocketClient.prototype.reconnect = function () {
16
16
  var _this = this;
17
17
 
18
+ this.close();
19
+
18
20
  if (this._status === 3) {
19
21
  setTimeout(function () {
20
22
  return _this.connect();
@@ -37,6 +39,10 @@ function () {
37
39
  WebsocketClient.prototype.connect = function () {
38
40
  var _this = this;
39
41
 
42
+ if (this.client) {
43
+ return;
44
+ }
45
+
40
46
  this.client = new WebSocket(this.url);
41
47
  this.client.onclose = this.onClose.bind(this);
42
48
  this.client.onmessage = this.onMessage.bind(this);
@@ -5,7 +5,7 @@ export default class WebsocketClient {
5
5
  private readonly url;
6
6
  emitter: Emitter;
7
7
  constructor({ url }: {
8
- url: any;
8
+ url: string;
9
9
  });
10
10
  private reconnect;
11
11
  private onClose;
@@ -11,8 +11,8 @@ var WebsocketClient =
11
11
  function () {
12
12
  function WebsocketClient(_a) {
13
13
  var url = _a.url;
14
+ this.client = null;
14
15
  this._status = 0;
15
- this.url = '';
16
16
  this.emitter = new pubo_utils_1.Emitter();
17
17
  this.url = url;
18
18
  this.connect();
@@ -21,6 +21,8 @@ function () {
21
21
  WebsocketClient.prototype.reconnect = function () {
22
22
  var _this = this;
23
23
 
24
+ this.close();
25
+
24
26
  if (this._status === 3) {
25
27
  setTimeout(function () {
26
28
  return _this.connect();
@@ -43,6 +45,10 @@ function () {
43
45
  WebsocketClient.prototype.connect = function () {
44
46
  var _this = this;
45
47
 
48
+ if (this.client) {
49
+ return;
50
+ }
51
+
46
52
  this.client = new WebSocket(this.url);
47
53
  this.client.onclose = this.onClose.bind(this);
48
54
  this.client.onmessage = this.onMessage.bind(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-web",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -22,5 +22,5 @@
22
22
  "pubo-utils": "^1.0.39",
23
23
  "roslib": "^1.2.0"
24
24
  },
25
- "gitHead": "5883283214a258ed8fc87e5608e8c5886710212d"
25
+ "gitHead": "a07e968c1d4e3469b382abad1b2b6295e1968baa"
26
26
  }