pubo-web 1.0.143 → 1.0.146
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/lib/dom/drag.js +74 -92
- package/lib/file/download.js +13 -16
- package/lib/file/parser.js +22 -32
- package/lib/file/pick.js +28 -31
- package/lib/index.js +14 -82
- package/lib/load-script/index.js +33 -43
- package/lib/storage/cookie.js +18 -23
- package/lib/storage/index.js +40 -56
- package/lib/storage/indexed-db/indexed-db-storage.js +52 -267
- package/lib/storage/indexed-db/indexed-db-utils.js +69 -290
- package/lib/websocket/client.js +59 -82
- package/package.json +3 -3
package/lib/dom/drag.js
CHANGED
|
@@ -1,102 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.DragMethod = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* Class for handling drag events in a UI.
|
|
9
6
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.onMove = void 0;
|
|
28
|
-
this.onMoveEnd = void 0;
|
|
29
|
-
this.key = key;
|
|
30
|
-
this.onMouseDown = this._onMouseDown.bind(this);
|
|
31
|
-
this.onTouchStart = this._onMouseDown.bind(this);
|
|
32
|
-
this.onMouseMove = this._onMouseMove.bind(this);
|
|
33
|
-
this.onMouseUp = this._onMouseUp.bind(this);
|
|
34
|
-
this.onMove = onMove;
|
|
35
|
-
this.onMoveEnd = onMoveEnd;
|
|
36
|
-
}
|
|
37
|
-
var _proto = DragMethod.prototype;
|
|
38
|
-
_proto._onMouseMove = function _onMouseMove(e) {
|
|
39
|
-
var _e$pageX, _e$touches$, _e$pageY, _e$touches$2;
|
|
40
|
-
if (typeof this.onMove !== 'function') {
|
|
41
|
-
return;
|
|
7
|
+
class DragMethod {
|
|
8
|
+
key = '';
|
|
9
|
+
cache = { pageX: 0, pageY: 0, dragging: false };
|
|
10
|
+
onMouseMove;
|
|
11
|
+
onMouseUp;
|
|
12
|
+
onMouseDown;
|
|
13
|
+
onTouchStart;
|
|
14
|
+
onMove;
|
|
15
|
+
onMoveEnd;
|
|
16
|
+
constructor({ key = '', onMove, onMoveEnd } = {}) {
|
|
17
|
+
this.key = key;
|
|
18
|
+
this.onMouseDown = this._onMouseDown.bind(this);
|
|
19
|
+
this.onTouchStart = this._onMouseDown.bind(this);
|
|
20
|
+
this.onMouseMove = this._onMouseMove.bind(this);
|
|
21
|
+
this.onMouseUp = this._onMouseUp.bind(this);
|
|
22
|
+
this.onMove = onMove;
|
|
23
|
+
this.onMoveEnd = onMoveEnd;
|
|
42
24
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
25
|
+
_onMouseMove(e) {
|
|
26
|
+
if (typeof this.onMove !== 'function') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (e.preventDefault) {
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
e.returnValue = false;
|
|
34
|
+
}
|
|
35
|
+
const pageX = e.pageX ?? e.touches[0]?.pageX;
|
|
36
|
+
const pageY = e.pageY ?? e.touches[0]?.pageY;
|
|
37
|
+
this.onMove({
|
|
38
|
+
offsetX: pageX - this.cache.pageX,
|
|
39
|
+
offsetY: pageY - this.cache.pageY,
|
|
40
|
+
pageX,
|
|
41
|
+
pageY,
|
|
42
|
+
startX: this.cache.pageX,
|
|
43
|
+
startY: this.cache.pageY,
|
|
44
|
+
key: this.key,
|
|
45
|
+
});
|
|
46
|
+
this.cache.pageX = pageX;
|
|
47
|
+
this.cache.pageY = pageY;
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
pageX: pageX,
|
|
54
|
-
pageY: pageY,
|
|
55
|
-
startX: this.cache.pageX,
|
|
56
|
-
startY: this.cache.pageY,
|
|
57
|
-
key: this.key
|
|
58
|
-
});
|
|
59
|
-
this.cache.pageX = pageX;
|
|
60
|
-
this.cache.pageY = pageY;
|
|
61
|
-
};
|
|
62
|
-
_proto.clearListener = function clearListener() {
|
|
63
|
-
window.removeEventListener('mousemove', this.onMouseMove);
|
|
64
|
-
window.removeEventListener('touchmove', this.onMouseMove);
|
|
65
|
-
window.removeEventListener('mouseup', this.onMouseUp);
|
|
66
|
-
window.removeEventListener('touchend', this.onMouseUp);
|
|
67
|
-
};
|
|
68
|
-
_proto._onMouseUp = function _onMouseUp() {
|
|
69
|
-
this.clearListener();
|
|
70
|
-
this.cache.dragging = false;
|
|
71
|
-
if (typeof this.onMoveEnd === 'function') {
|
|
72
|
-
this.onMoveEnd();
|
|
49
|
+
clearListener() {
|
|
50
|
+
window.removeEventListener('mousemove', this.onMouseMove);
|
|
51
|
+
window.removeEventListener('touchmove', this.onMouseMove);
|
|
52
|
+
window.removeEventListener('mouseup', this.onMouseUp);
|
|
53
|
+
window.removeEventListener('touchend', this.onMouseUp);
|
|
73
54
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
e.returnValue = false;
|
|
55
|
+
_onMouseUp() {
|
|
56
|
+
this.clearListener();
|
|
57
|
+
this.cache.dragging = false;
|
|
58
|
+
if (typeof this.onMoveEnd === 'function') {
|
|
59
|
+
this.onMoveEnd();
|
|
60
|
+
}
|
|
81
61
|
}
|
|
82
|
-
|
|
83
|
-
|
|
62
|
+
_onMouseDown(e) {
|
|
63
|
+
if (e.preventDefault && e.pageX) {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
e.returnValue = false;
|
|
68
|
+
}
|
|
69
|
+
if (typeof this.onMove !== 'function' || this.cache.dragging) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.clearListener();
|
|
73
|
+
const pageX = e.pageX ?? e.touches[0]?.pageX;
|
|
74
|
+
const pageY = e.pageY ?? e.touches[0]?.pageY;
|
|
75
|
+
this.cache.dragging = true;
|
|
76
|
+
this.cache.pageX = pageX;
|
|
77
|
+
this.cache.pageY = pageY;
|
|
78
|
+
window.addEventListener('mousemove', this.onMouseMove);
|
|
79
|
+
window.addEventListener('touchmove', this.onMouseMove, { passive: false });
|
|
80
|
+
window.addEventListener('mouseup', this.onMouseUp);
|
|
81
|
+
window.addEventListener('touchend', this.onMouseUp, { passive: false });
|
|
84
82
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
var pageY = (_e$pageY2 = e.pageY) != null ? _e$pageY2 : (_e$touches$4 = e.touches[0]) == null ? void 0 : _e$touches$4.pageY;
|
|
88
|
-
this.cache.dragging = true;
|
|
89
|
-
this.cache.pageX = pageX;
|
|
90
|
-
this.cache.pageY = pageY;
|
|
91
|
-
window.addEventListener('mousemove', this.onMouseMove);
|
|
92
|
-
window.addEventListener('touchmove', this.onMouseMove, {
|
|
93
|
-
passive: false
|
|
94
|
-
});
|
|
95
|
-
window.addEventListener('mouseup', this.onMouseUp);
|
|
96
|
-
window.addEventListener('touchend', this.onMouseUp, {
|
|
97
|
-
passive: false
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
return DragMethod;
|
|
101
|
-
}();
|
|
102
|
-
exports.DragMethod = DragMethod;
|
|
83
|
+
}
|
|
84
|
+
exports.DragMethod = DragMethod;
|
package/lib/file/download.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.downloadFile = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
const downloadFile = (uri, name) => {
|
|
5
|
+
const a = document.createElement('a');
|
|
6
|
+
a.href = uri;
|
|
7
|
+
if (name) {
|
|
8
|
+
a.download = name;
|
|
9
|
+
}
|
|
10
|
+
a.style.position = 'fixed';
|
|
11
|
+
a.style.visibility = 'hidden';
|
|
12
|
+
document.body.appendChild(a);
|
|
13
|
+
a.click();
|
|
14
|
+
document.body.removeChild(a);
|
|
18
15
|
};
|
|
19
|
-
exports.downloadFile = downloadFile;
|
|
16
|
+
exports.downloadFile = downloadFile;
|
package/lib/file/parser.js
CHANGED
|
@@ -1,39 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.blob2file = exports.blob2base64 = exports.blob2text = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
reader.readAsText(blob);
|
|
14
|
-
});
|
|
4
|
+
const blob2text = (blob) => {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const reader = new FileReader();
|
|
7
|
+
reader.onload = (e) => resolve(e.target.result);
|
|
8
|
+
reader.readAsText(blob);
|
|
9
|
+
});
|
|
15
10
|
};
|
|
16
11
|
exports.blob2text = blob2text;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
reader.readAsDataURL(blob);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
12
|
+
const blob2base64 = (blob) => {
|
|
13
|
+
return new Promise(function (resolve, reject) {
|
|
14
|
+
const reader = new FileReader();
|
|
15
|
+
if (!blob) {
|
|
16
|
+
reject('文件爲空!');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
reader.onload = (e) => resolve(e.target.result);
|
|
20
|
+
reader.onabort = () => reject();
|
|
21
|
+
reader.readAsDataURL(blob);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
32
24
|
};
|
|
33
25
|
exports.blob2base64 = blob2base64;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
type: type
|
|
37
|
-
});
|
|
26
|
+
const blob2file = (blob, name, type) => {
|
|
27
|
+
return new File(blob, name, { type });
|
|
38
28
|
};
|
|
39
|
-
exports.blob2file = blob2file;
|
|
29
|
+
exports.blob2file = blob2file;
|
package/lib/file/pick.js
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.pickFiles = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
4
|
+
const pickFiles = () => {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const el = document.createElement('input');
|
|
7
|
+
let picked = false;
|
|
8
|
+
const onFocus = () => {
|
|
9
|
+
document.body.removeChild(el);
|
|
10
|
+
window.removeEventListener('focus', onFocus);
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
if (!picked) {
|
|
13
|
+
reject('no files picked');
|
|
14
|
+
}
|
|
15
|
+
}, 1000);
|
|
16
|
+
};
|
|
17
|
+
el.type = 'file';
|
|
18
|
+
el.style.visibility = 'hidden';
|
|
19
|
+
el.style.position = 'fixed';
|
|
20
|
+
el.style.top = '0px';
|
|
21
|
+
el.style.zIndex = '-1';
|
|
22
|
+
window.addEventListener('focus', onFocus);
|
|
23
|
+
el.onchange = (e) => {
|
|
24
|
+
picked = e.target.files.length > 0;
|
|
25
|
+
resolve(e.target.files);
|
|
26
|
+
};
|
|
27
|
+
document.body.appendChild(el);
|
|
28
|
+
el.click();
|
|
29
|
+
});
|
|
33
30
|
};
|
|
34
|
-
exports.pickFiles = pickFiles;
|
|
31
|
+
exports.pickFiles = pickFiles;
|
package/lib/index.js
CHANGED
|
@@ -1,93 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.setCookieItem = exports.getCookie = exports.getCookieValue = exports.IndexedStorage = exports.pickFiles = exports.DragMethod = exports.WebsocketClient = exports.WebStorage = exports.downloadFile = exports.blob2file = exports.blob2base64 = exports.blob2text = exports.loadScript = void 0;
|
|
7
4
|
var load_script_1 = require("./load-script");
|
|
8
|
-
Object.defineProperty(exports, "loadScript", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function get() {
|
|
11
|
-
return load_script_1.loadScript;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
5
|
+
Object.defineProperty(exports, "loadScript", { enumerable: true, get: function () { return load_script_1.loadScript; } });
|
|
14
6
|
var parser_1 = require("./file/parser");
|
|
15
|
-
Object.defineProperty(exports, "blob2text", {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return parser_1.blob2text;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(exports, "blob2base64", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return parser_1.blob2base64;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(exports, "blob2file", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function get() {
|
|
30
|
-
return parser_1.blob2file;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
7
|
+
Object.defineProperty(exports, "blob2text", { enumerable: true, get: function () { return parser_1.blob2text; } });
|
|
8
|
+
Object.defineProperty(exports, "blob2base64", { enumerable: true, get: function () { return parser_1.blob2base64; } });
|
|
9
|
+
Object.defineProperty(exports, "blob2file", { enumerable: true, get: function () { return parser_1.blob2file; } });
|
|
33
10
|
var download_1 = require("./file/download");
|
|
34
|
-
Object.defineProperty(exports, "downloadFile", {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
get: function get() {
|
|
37
|
-
return download_1.downloadFile;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
11
|
+
Object.defineProperty(exports, "downloadFile", { enumerable: true, get: function () { return download_1.downloadFile; } });
|
|
40
12
|
var storage_1 = require("./storage");
|
|
41
|
-
Object.defineProperty(exports, "WebStorage", {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
get: function get() {
|
|
44
|
-
return storage_1.WebStorage;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
13
|
+
Object.defineProperty(exports, "WebStorage", { enumerable: true, get: function () { return storage_1.WebStorage; } });
|
|
47
14
|
var client_1 = require("./websocket/client");
|
|
48
|
-
Object.defineProperty(exports, "WebsocketClient", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function get() {
|
|
51
|
-
return client_1.WebsocketClient;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
15
|
+
Object.defineProperty(exports, "WebsocketClient", { enumerable: true, get: function () { return client_1.WebsocketClient; } });
|
|
54
16
|
var drag_1 = require("./dom/drag");
|
|
55
|
-
Object.defineProperty(exports, "DragMethod", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
get: function get() {
|
|
58
|
-
return drag_1.DragMethod;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
17
|
+
Object.defineProperty(exports, "DragMethod", { enumerable: true, get: function () { return drag_1.DragMethod; } });
|
|
61
18
|
var pick_1 = require("./file/pick");
|
|
62
|
-
Object.defineProperty(exports, "pickFiles", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function get() {
|
|
65
|
-
return pick_1.pickFiles;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
19
|
+
Object.defineProperty(exports, "pickFiles", { enumerable: true, get: function () { return pick_1.pickFiles; } });
|
|
68
20
|
var indexed_db_storage_1 = require("./storage/indexed-db/indexed-db-storage");
|
|
69
|
-
Object.defineProperty(exports, "IndexedStorage", {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
get: function get() {
|
|
72
|
-
return indexed_db_storage_1.IndexedStorage;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
21
|
+
Object.defineProperty(exports, "IndexedStorage", { enumerable: true, get: function () { return indexed_db_storage_1.IndexedStorage; } });
|
|
75
22
|
var cookie_1 = require("./storage/cookie");
|
|
76
|
-
Object.defineProperty(exports, "getCookieValue", {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return cookie_1.getCookieValue;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
Object.defineProperty(exports, "getCookie", {
|
|
83
|
-
enumerable: true,
|
|
84
|
-
get: function get() {
|
|
85
|
-
return cookie_1.getCookie;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
Object.defineProperty(exports, "setCookieItem", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
get: function get() {
|
|
91
|
-
return cookie_1.setCookieItem;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
23
|
+
Object.defineProperty(exports, "getCookieValue", { enumerable: true, get: function () { return cookie_1.getCookieValue; } });
|
|
24
|
+
Object.defineProperty(exports, "getCookie", { enumerable: true, get: function () { return cookie_1.getCookie; } });
|
|
25
|
+
Object.defineProperty(exports, "setCookieItem", { enumerable: true, get: function () { return cookie_1.setCookieItem; } });
|
package/lib/load-script/index.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
6
|
-
Object.defineProperty(exports, "__esModule", {
|
|
7
|
-
value: true
|
|
8
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
3
|
exports.loadScript = void 0;
|
|
10
4
|
/**
|
|
11
5
|
* Loads a script from the given URL with the provided options.
|
|
@@ -14,41 +8,37 @@ exports.loadScript = void 0;
|
|
|
14
8
|
* @param {any} options - Additional options for loading the script
|
|
15
9
|
* @return {Promise<any>} A Promise that resolves with the URL once the script is loaded
|
|
16
10
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return item;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
};
|
|
31
|
-
return new Promise(function (resolve) {
|
|
32
|
-
var old = findScript();
|
|
33
|
-
var el = old;
|
|
34
|
-
if (!old) {
|
|
35
|
-
el = document.createElement('script');
|
|
36
|
-
} else if (old._state === 'complete') {
|
|
37
|
-
return resolve(url);
|
|
38
|
-
}
|
|
39
|
-
for (var _i = 0, _Object$keys = Object.keys(options); _i < _Object$keys.length; _i++) {
|
|
40
|
-
var key = _Object$keys[_i];
|
|
41
|
-
el[key] = options[key];
|
|
42
|
-
}
|
|
43
|
-
var onLoad = function onLoad() {
|
|
44
|
-
resolve(url);
|
|
45
|
-
el.removeEventListener('load', onLoad);
|
|
46
|
-
el._state = 'complete';
|
|
11
|
+
const loadScript = (url, options = {}) => {
|
|
12
|
+
const findScript = () => {
|
|
13
|
+
const list = document.getElementsByTagName('script');
|
|
14
|
+
for (const item of list) {
|
|
15
|
+
if (item.src === url) {
|
|
16
|
+
return item;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
47
20
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
const old = findScript();
|
|
23
|
+
let el = old;
|
|
24
|
+
if (!old) {
|
|
25
|
+
el = document.createElement('script');
|
|
26
|
+
}
|
|
27
|
+
else if (old._state === 'complete') {
|
|
28
|
+
return resolve(url);
|
|
29
|
+
}
|
|
30
|
+
for (const key of Object.keys(options)) {
|
|
31
|
+
el[key] = options[key];
|
|
32
|
+
}
|
|
33
|
+
const onLoad = () => {
|
|
34
|
+
resolve(url);
|
|
35
|
+
el.removeEventListener('load', onLoad);
|
|
36
|
+
el._state = 'complete';
|
|
37
|
+
};
|
|
38
|
+
el.src = url;
|
|
39
|
+
el.addEventListener('load', onLoad);
|
|
40
|
+
document.body.appendChild(el);
|
|
41
|
+
return 'success';
|
|
42
|
+
});
|
|
53
43
|
};
|
|
54
|
-
exports.loadScript = loadScript;
|
|
44
|
+
exports.loadScript = loadScript;
|
package/lib/storage/cookie.js
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.setCookieItem = exports.getCookie = exports.getCookieValue = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const getCookieValue = (key) => {
|
|
5
|
+
const reg = new RegExp(`(^| )${key}=([^;]*)(;|$)`);
|
|
6
|
+
const res = reg.exec(document.cookie);
|
|
7
|
+
return res ? res[2] : '';
|
|
11
8
|
};
|
|
12
9
|
exports.getCookieValue = getCookieValue;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const getCookie = () => {
|
|
11
|
+
const res = {};
|
|
12
|
+
if (!document.cookie) {
|
|
13
|
+
return res;
|
|
14
|
+
}
|
|
15
|
+
const tmp = document.cookie.split(';');
|
|
16
|
+
tmp.forEach((item) => {
|
|
17
|
+
const [key, value] = item.split('=');
|
|
18
|
+
res[key] = value;
|
|
19
|
+
});
|
|
16
20
|
return res;
|
|
17
|
-
}
|
|
18
|
-
var tmp = document.cookie.split(';');
|
|
19
|
-
tmp.forEach(function (item) {
|
|
20
|
-
var _item$split = item.split('='),
|
|
21
|
-
key = _item$split[0],
|
|
22
|
-
value = _item$split[1];
|
|
23
|
-
res[key] = value;
|
|
24
|
-
});
|
|
25
|
-
return res;
|
|
26
21
|
};
|
|
27
22
|
exports.getCookie = getCookie;
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const setCookieItem = (key, value) => {
|
|
24
|
+
document.cookie = `${key}=${value}`;
|
|
30
25
|
};
|
|
31
|
-
exports.setCookieItem = setCookieItem;
|
|
26
|
+
exports.setCookieItem = setCookieItem;
|