@unicom-cloud/utils 0.1.3 → 0.1.5
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/class-name/index.js +5 -6
- package/constant/keyboardCode.js +41 -40
- package/constant/platform.js +14 -16
- package/cookie/src/index.js +46 -46
- package/dayjs/index.js +15 -0
- package/decimal/decimal.js +56 -56
- package/event-emitter/index.js +14 -23
- package/file/fileToURL.js +8 -9
- package/file/saveAs.js +1 -1
- package/mock/MockWebSocket.js +67 -90
- package/mock/MockXMLHttpRequest.js +51 -61
- package/package.json +1 -1
- package/random/address.js +10 -10
- package/screenfull/index.js +43 -43
- package/snapdom/src/api/preCache.js +34 -24
- package/snapdom/src/api/snapdom.js +56 -56
- package/snapdom/src/core/cache.js +3 -2
- package/snapdom/src/core/capture.js +32 -32
- package/snapdom/src/core/clone.js +39 -38
- package/snapdom/src/core/prepare.js +10 -11
- package/snapdom/src/modules/background.js +45 -22
- package/snapdom/src/modules/fonts.js +148 -45
- package/snapdom/src/modules/images.js +7 -7
- package/snapdom/src/modules/pseudo.js +75 -45
- package/snapdom/src/modules/styles.js +7 -8
- package/snapdom/src/utils/helpers.js +56 -53
- package/tree/index.js +31 -32
- package/turbo-stream/src/encode.js +149 -152
- package/turbo-stream/src/shared.js +155 -173
package/class-name/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return a(e).join(i);
|
|
1
|
+
import o from "lodash/isPlainObject";
|
|
2
|
+
function s(...e) {
|
|
3
|
+
const n = " ", i = e.flat(1 / 0).map((t, r, f) => o(t) ? Object.keys(t).filter((a) => t[a]) : t).flat(1 / 0).filter(Boolean).join(n).split(n).filter(Boolean);
|
|
4
|
+
return [...new Set(i)].join(n);
|
|
6
5
|
}
|
|
7
6
|
export {
|
|
8
|
-
|
|
7
|
+
s as default
|
|
9
8
|
};
|
package/constant/keyboardCode.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const
|
|
1
|
+
const o = {
|
|
2
2
|
key: "Enter",
|
|
3
3
|
code: "Enter",
|
|
4
4
|
keyCode: 13
|
|
5
|
-
},
|
|
5
|
+
}, e = {
|
|
6
6
|
key: "Escape",
|
|
7
7
|
code: "Escape",
|
|
8
8
|
keyCode: 27
|
|
9
|
-
}, t = {
|
|
9
|
+
}, t = e, c = {
|
|
10
10
|
key: "Backspace",
|
|
11
11
|
code: "Backspace",
|
|
12
12
|
keyCode: 8
|
|
13
|
-
},
|
|
13
|
+
}, k = {
|
|
14
14
|
key: "Tab",
|
|
15
15
|
code: "Tab",
|
|
16
16
|
keyCode: 9
|
|
17
|
-
},
|
|
17
|
+
}, y = {
|
|
18
18
|
key: " ",
|
|
19
19
|
code: "Space",
|
|
20
20
|
keyCode: 32
|
|
21
|
-
},
|
|
21
|
+
}, n = {
|
|
22
22
|
key: "ArrowLeft",
|
|
23
23
|
code: "ArrowLeft",
|
|
24
24
|
keyCode: 37
|
|
@@ -26,80 +26,81 @@ const e = {
|
|
|
26
26
|
key: "ArrowUp",
|
|
27
27
|
code: "ArrowUp",
|
|
28
28
|
keyCode: 38
|
|
29
|
-
},
|
|
29
|
+
}, r = {
|
|
30
30
|
key: "ArrowRight",
|
|
31
31
|
code: "ArrowRight",
|
|
32
32
|
keyCode: 39
|
|
33
|
-
},
|
|
33
|
+
}, s = {
|
|
34
34
|
key: "ArrowDown",
|
|
35
35
|
code: "ArrowDown",
|
|
36
36
|
keyCode: 40
|
|
37
|
-
},
|
|
37
|
+
}, C = {
|
|
38
38
|
key: "CapsLock",
|
|
39
39
|
code: "CapsLock",
|
|
40
40
|
keyCode: 20
|
|
41
|
-
}, C = {
|
|
42
|
-
key: "Meta"
|
|
43
41
|
}, a = {
|
|
42
|
+
key: "Meta"
|
|
43
|
+
}, A = {
|
|
44
44
|
key: "Meta",
|
|
45
45
|
code: "MetaLeft",
|
|
46
46
|
keyCode: 91
|
|
47
|
-
},
|
|
47
|
+
}, f = {
|
|
48
48
|
key: "Meta",
|
|
49
49
|
code: "MetaRight",
|
|
50
50
|
keyCode: 93
|
|
51
|
-
}, f = {
|
|
52
|
-
key: "Control"
|
|
53
51
|
}, h = {
|
|
52
|
+
key: "Control"
|
|
53
|
+
}, i = {
|
|
54
54
|
key: "Control",
|
|
55
55
|
code: "ControlLeft",
|
|
56
56
|
keyCode: 17
|
|
57
|
-
},
|
|
57
|
+
}, l = {
|
|
58
58
|
key: "Control",
|
|
59
59
|
code: "ControlRight",
|
|
60
60
|
keyCode: 17
|
|
61
|
-
},
|
|
61
|
+
}, p = {
|
|
62
62
|
key: "Alt"
|
|
63
63
|
}, w = {
|
|
64
64
|
key: "Alt",
|
|
65
65
|
code: "AltLeft",
|
|
66
66
|
keyCode: 18
|
|
67
|
-
},
|
|
67
|
+
}, L = {
|
|
68
68
|
key: "Alt",
|
|
69
69
|
code: "AltRight",
|
|
70
70
|
keyCode: 18
|
|
71
|
-
}, L = {
|
|
72
|
-
key: "Shift"
|
|
73
71
|
}, g = {
|
|
72
|
+
key: "Shift"
|
|
73
|
+
}, R = {
|
|
74
74
|
key: "Shift",
|
|
75
75
|
code: "ShiftLeft",
|
|
76
76
|
keyCode: 16
|
|
77
|
-
},
|
|
77
|
+
}, S = {
|
|
78
78
|
key: "Shift",
|
|
79
79
|
code: "ShiftRight",
|
|
80
80
|
keyCode: 16
|
|
81
81
|
};
|
|
82
82
|
export {
|
|
83
|
-
|
|
83
|
+
p as Alt,
|
|
84
84
|
w as AltLeft,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
L as AltRight,
|
|
86
|
+
s as ArrowDown,
|
|
87
|
+
n as ArrowLeft,
|
|
88
|
+
r as ArrowRight,
|
|
89
89
|
d as ArrowUp,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
a as
|
|
99
|
-
A as
|
|
100
|
-
|
|
101
|
-
g as
|
|
102
|
-
R as
|
|
103
|
-
|
|
104
|
-
|
|
90
|
+
c as Backspace,
|
|
91
|
+
C as CapsLock,
|
|
92
|
+
h as Control,
|
|
93
|
+
i as ControlLeft,
|
|
94
|
+
l as ControlRight,
|
|
95
|
+
o as Enter,
|
|
96
|
+
e as Esc,
|
|
97
|
+
t as Escape,
|
|
98
|
+
a as Meta,
|
|
99
|
+
A as MetaLeft,
|
|
100
|
+
f as MetaRight,
|
|
101
|
+
g as Shift,
|
|
102
|
+
R as ShiftLeft,
|
|
103
|
+
S as ShiftRight,
|
|
104
|
+
y as Space,
|
|
105
|
+
k as Tab
|
|
105
106
|
};
|
package/constant/platform.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
const i = navigator.userAgent.toLowerCase()
|
|
2
|
-
var n;
|
|
3
|
-
const e = window.__wxjs_environment === "miniprogram" || !!((n = window.wx) != null && n.getSystemInfoSync), a = /micromessenger/i.test(i), r = /dingtalk/i.test(i), w = /alipay|aliapp/i.test(i), s = /ipad|iphone|ipod/i.test(i), t = /android/i.test(i), c = /openharmony/i.test(i), d = /macintosh|mac os x/i.test(i), m = /windows|win32|win64|wow64/i.test(
|
|
1
|
+
const i = navigator.userAgent.toLowerCase(), t = window.__wxjs_environment === "miniprogram" || !!window.wx?.getSystemInfoSync, e = /micromessenger/i.test(i), a = /dingtalk/i.test(i), r = /alipay|aliapp/i.test(i), o = /ipad|iphone|ipod/i.test(i), s = /android/i.test(i), w = /openharmony/i.test(i), c = /macintosh|mac os x/i.test(i), d = /windows|win32|win64|wow64/i.test(
|
|
4
2
|
i
|
|
5
|
-
),
|
|
3
|
+
), m = (o || s || /windows phone|blackberry|mobile|webos|iemobile|opera (mini|mobi)/i.test(
|
|
6
4
|
i
|
|
7
|
-
)) && ("ontouchend" in document || "ontouchend" in window),
|
|
5
|
+
)) && ("ontouchend" in document || "ontouchend" in window), l = ["fullscreen", "standalone", "minimal-ui"].some((n) => window.matchMedia(`(display-mode: ${n})`).matches) || window.navigator.standalone === !0;
|
|
8
6
|
export {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
r as isAlipayBrowser,
|
|
8
|
+
s as isAndroidOS,
|
|
9
|
+
a as isDingtalkBrowser,
|
|
10
|
+
w as isHarmony,
|
|
11
|
+
o as isIOS_OS,
|
|
12
|
+
c as isMacOS,
|
|
13
|
+
m as isMobileDevice,
|
|
14
|
+
l as isPWA,
|
|
15
|
+
e as isWeChatBrowser,
|
|
16
|
+
t as isWeChatMiniProgram,
|
|
17
|
+
d as isWindowsOS
|
|
20
18
|
};
|
package/cookie/src/index.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
const w = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/, g = /^[\u0021-\u003A\u003C-\u007E]*$/,
|
|
2
|
-
const
|
|
1
|
+
const w = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/, g = /^[\u0021-\u003A\u003C-\u007E]*$/, p = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i, S = /^[\u0020-\u003A\u003D-\u007E]*$/, E = Object.prototype.toString, v = /* @__PURE__ */ (() => {
|
|
2
|
+
const t = function() {
|
|
3
3
|
};
|
|
4
|
-
return
|
|
4
|
+
return t.prototype = /* @__PURE__ */ Object.create(null), t;
|
|
5
5
|
})();
|
|
6
|
-
function k(
|
|
7
|
-
const e = new
|
|
6
|
+
function k(t, i) {
|
|
7
|
+
const e = new v(), a = t.length;
|
|
8
8
|
if (a < 2) return e;
|
|
9
|
-
const c =
|
|
10
|
-
let
|
|
9
|
+
const c = i?.decode || b;
|
|
10
|
+
let r = 0;
|
|
11
11
|
do {
|
|
12
|
-
const n =
|
|
12
|
+
const n = t.indexOf("=", r);
|
|
13
13
|
if (n === -1) break;
|
|
14
|
-
const
|
|
15
|
-
if (n >
|
|
16
|
-
|
|
14
|
+
const u = t.indexOf(";", r), o = u === -1 ? a : u;
|
|
15
|
+
if (n > o) {
|
|
16
|
+
r = t.lastIndexOf(";", n - 1) + 1;
|
|
17
17
|
continue;
|
|
18
18
|
}
|
|
19
|
-
const
|
|
19
|
+
const d = s(t, r, n), x = m(t, n, d), l = t.slice(d, x);
|
|
20
20
|
if (e[l] === void 0) {
|
|
21
|
-
const f =
|
|
22
|
-
e[l] =
|
|
21
|
+
const f = s(t, n + 1, o), h = m(t, o, f), y = c(t.slice(f, h));
|
|
22
|
+
e[l] = y;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
} while (
|
|
24
|
+
r = o + 1;
|
|
25
|
+
} while (r < a);
|
|
26
26
|
return e;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function s(t, i, e) {
|
|
29
29
|
do {
|
|
30
|
-
const a =
|
|
30
|
+
const a = t.charCodeAt(i);
|
|
31
31
|
if (a !== 32 && a !== 9) return i;
|
|
32
32
|
} while (++i < e);
|
|
33
33
|
return e;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function m(t, i, e) {
|
|
36
36
|
for (; i > e; ) {
|
|
37
|
-
const a =
|
|
37
|
+
const a = t.charCodeAt(--i);
|
|
38
38
|
if (a !== 32 && a !== 9) return i + 1;
|
|
39
39
|
}
|
|
40
40
|
return e;
|
|
41
41
|
}
|
|
42
|
-
function $(
|
|
43
|
-
const a =
|
|
44
|
-
if (!w.test(
|
|
45
|
-
throw new TypeError(`argument name is invalid: ${
|
|
42
|
+
function $(t, i, e) {
|
|
43
|
+
const a = e?.encode || encodeURIComponent;
|
|
44
|
+
if (!w.test(t))
|
|
45
|
+
throw new TypeError(`argument name is invalid: ${t}`);
|
|
46
46
|
const c = a(i);
|
|
47
47
|
if (!g.test(c))
|
|
48
48
|
throw new TypeError(`argument val is invalid: ${i}`);
|
|
49
|
-
let
|
|
50
|
-
if (!e) return
|
|
49
|
+
let r = t + "=" + c;
|
|
50
|
+
if (!e) return r;
|
|
51
51
|
if (e.maxAge !== void 0) {
|
|
52
52
|
if (!Number.isInteger(e.maxAge))
|
|
53
53
|
throw new TypeError(`option maxAge is invalid: ${e.maxAge}`);
|
|
54
|
-
|
|
54
|
+
r += "; Max-Age=" + e.maxAge;
|
|
55
55
|
}
|
|
56
56
|
if (e.domain) {
|
|
57
|
-
if (!
|
|
57
|
+
if (!p.test(e.domain))
|
|
58
58
|
throw new TypeError(`option domain is invalid: ${e.domain}`);
|
|
59
|
-
|
|
59
|
+
r += "; Domain=" + e.domain;
|
|
60
60
|
}
|
|
61
61
|
if (e.path) {
|
|
62
|
-
if (!
|
|
62
|
+
if (!S.test(e.path))
|
|
63
63
|
throw new TypeError(`option path is invalid: ${e.path}`);
|
|
64
|
-
|
|
64
|
+
r += "; Path=" + e.path;
|
|
65
65
|
}
|
|
66
66
|
if (e.expires) {
|
|
67
67
|
if (!I(e.expires) || !Number.isFinite(e.expires.valueOf()))
|
|
68
68
|
throw new TypeError(`option expires is invalid: ${e.expires}`);
|
|
69
|
-
|
|
69
|
+
r += "; Expires=" + e.expires.toUTCString();
|
|
70
70
|
}
|
|
71
|
-
if (e.httpOnly && (
|
|
71
|
+
if (e.httpOnly && (r += "; HttpOnly"), e.secure && (r += "; Secure"), e.partitioned && (r += "; Partitioned"), e.priority)
|
|
72
72
|
switch (typeof e.priority == "string" ? e.priority.toLowerCase() : void 0) {
|
|
73
73
|
case "low":
|
|
74
|
-
|
|
74
|
+
r += "; Priority=Low";
|
|
75
75
|
break;
|
|
76
76
|
case "medium":
|
|
77
|
-
|
|
77
|
+
r += "; Priority=Medium";
|
|
78
78
|
break;
|
|
79
79
|
case "high":
|
|
80
|
-
|
|
80
|
+
r += "; Priority=High";
|
|
81
81
|
break;
|
|
82
82
|
default:
|
|
83
83
|
throw new TypeError(`option priority is invalid: ${e.priority}`);
|
|
@@ -86,29 +86,29 @@ function $(r, i, e) {
|
|
|
86
86
|
switch (typeof e.sameSite == "string" ? e.sameSite.toLowerCase() : e.sameSite) {
|
|
87
87
|
case !0:
|
|
88
88
|
case "strict":
|
|
89
|
-
|
|
89
|
+
r += "; SameSite=Strict";
|
|
90
90
|
break;
|
|
91
91
|
case "lax":
|
|
92
|
-
|
|
92
|
+
r += "; SameSite=Lax";
|
|
93
93
|
break;
|
|
94
94
|
case "none":
|
|
95
|
-
|
|
95
|
+
r += "; SameSite=None";
|
|
96
96
|
break;
|
|
97
97
|
default:
|
|
98
98
|
throw new TypeError(`option sameSite is invalid: ${e.sameSite}`);
|
|
99
99
|
}
|
|
100
|
-
return
|
|
100
|
+
return r;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
if (
|
|
102
|
+
function b(t) {
|
|
103
|
+
if (t.indexOf("%") === -1) return t;
|
|
104
104
|
try {
|
|
105
|
-
return decodeURIComponent(
|
|
105
|
+
return decodeURIComponent(t);
|
|
106
106
|
} catch {
|
|
107
|
-
return
|
|
107
|
+
return t;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function I(
|
|
111
|
-
return
|
|
110
|
+
function I(t) {
|
|
111
|
+
return E.call(t) === "[object Date]";
|
|
112
112
|
}
|
|
113
113
|
export {
|
|
114
114
|
k as parse,
|
package/dayjs/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import a from "dayjs";
|
|
2
|
+
function s(e, n) {
|
|
3
|
+
let t = a.duration(e, n || "minutes");
|
|
4
|
+
return [
|
|
5
|
+
{ value: t.years(), unit: "年" },
|
|
6
|
+
{ value: t.months(), unit: "个月" },
|
|
7
|
+
{ value: t.days(), unit: "天" },
|
|
8
|
+
{ value: t.hours(), unit: "小时" },
|
|
9
|
+
{ value: t.minutes(), unit: "分钟" },
|
|
10
|
+
{ value: t.seconds(), unit: "秒" }
|
|
11
|
+
].filter((u) => u.value > 0).map((u, o, r) => Math.floor(u.value) + u.unit).join("");
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
s as convertToDurationBasedOnTimeUnits
|
|
15
|
+
};
|