pubo-web 1.0.43 → 1.0.47

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 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)),c=u.next();!c.done;c=u.next()){var a=c.value;s[a]=e[a]}}catch(t){r={error:t}}finally{try{c&&!c.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})},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)},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=a(a({},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.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}()}])}));
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 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,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 f=a.value;u[f]=e[f]}}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)},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=a(a({},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.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}()}])}));
@@ -52,13 +52,14 @@ export var loadScript = function loadScript(url, options) {
52
52
  var e_2, _a;
53
53
 
54
54
  var old = findScript();
55
+ var el = old;
55
56
 
56
- if (old) {
57
+ if (!old) {
58
+ el = document.createElement('script');
59
+ } else if (old._state === 'complete') {
57
60
  return resolve(url);
58
61
  }
59
62
 
60
- var el = document.createElement('script');
61
-
62
63
  try {
63
64
  for (var _b = __values(Object.keys(options)), _c = _b.next(); !_c.done; _c = _b.next()) {
64
65
  var key = _c.value;
@@ -76,12 +77,14 @@ export var loadScript = function loadScript(url, options) {
76
77
  }
77
78
  }
78
79
 
79
- el.src = url;
80
-
81
- el.onload = function () {
82
- return resolve(url);
80
+ var onLoad = function onLoad() {
81
+ resolve(url);
82
+ el.removeEventListener('load', onLoad);
83
+ el._state = 'complete';
83
84
  };
84
85
 
86
+ el.src = url;
87
+ el.addEventListener('load', onLoad);
85
88
  document.body.appendChild(el);
86
89
  return 'success';
87
90
  });
@@ -59,13 +59,14 @@ exports.loadScript = function (url, options) {
59
59
  var e_2, _a;
60
60
 
61
61
  var old = findScript();
62
+ var el = old;
62
63
 
63
- if (old) {
64
+ if (!old) {
65
+ el = document.createElement('script');
66
+ } else if (old._state === 'complete') {
64
67
  return resolve(url);
65
68
  }
66
69
 
67
- var el = document.createElement('script');
68
-
69
70
  try {
70
71
  for (var _b = __values(Object.keys(options)), _c = _b.next(); !_c.done; _c = _b.next()) {
71
72
  var key = _c.value;
@@ -83,12 +84,14 @@ exports.loadScript = function (url, options) {
83
84
  }
84
85
  }
85
86
 
86
- el.src = url;
87
-
88
- el.onload = function () {
89
- return resolve(url);
87
+ var onLoad = function onLoad() {
88
+ resolve(url);
89
+ el.removeEventListener('load', onLoad);
90
+ el._state = 'complete';
90
91
  };
91
92
 
93
+ el.src = url;
94
+ el.addEventListener('load', onLoad);
92
95
  document.body.appendChild(el);
93
96
  return 'success';
94
97
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-web",
3
- "version": "1.0.43",
3
+ "version": "1.0.47",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "node": ">=8.0.0"
20
20
  },
21
21
  "dependencies": {
22
- "pubo-utils": "^1.0.43",
22
+ "pubo-utils": "^1.0.47",
23
23
  "roslib": "^1.2.0"
24
24
  },
25
- "gitHead": "648dc63c3e9866e0288aa6237c3c2df83235469b"
25
+ "gitHead": "9eea3d7ccae6ce8daa0232f2de24938095d15d4b"
26
26
  }