sculp-js 1.13.3-beta.0 → 1.13.6
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/cjs/_virtual/_commonjsHelpers.js +3 -3
- package/dist/cjs/array.js +36 -46
- package/dist/cjs/async.js +41 -43
- package/dist/cjs/base64.js +77 -66
- package/dist/cjs/clipboard.js +54 -53
- package/dist/cjs/cloneDeep.js +90 -91
- package/dist/cjs/cookie.js +27 -30
- package/dist/cjs/date.js +101 -98
- package/dist/cjs/dom.js +114 -121
- package/dist/cjs/download.js +77 -78
- package/dist/cjs/easing.js +29 -32
- package/dist/cjs/file.js +147 -152
- package/dist/cjs/func.js +64 -78
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/math.js +32 -38
- package/dist/cjs/node_modules/bezier-easing/src/index.js +35 -23
- package/dist/cjs/number.js +58 -61
- package/dist/cjs/object.js +112 -126
- package/dist/cjs/path.js +39 -43
- package/dist/cjs/qs.js +34 -41
- package/dist/cjs/random.js +31 -34
- package/dist/cjs/string.js +62 -63
- package/dist/cjs/tooltip.js +66 -69
- package/dist/cjs/tree.js +265 -263
- package/dist/cjs/type.js +42 -46
- package/dist/cjs/unique.js +39 -42
- package/dist/cjs/url.js +47 -48
- package/dist/cjs/validator.js +38 -38
- package/dist/cjs/variable.js +27 -21
- package/dist/cjs/watermark.js +78 -67
- package/dist/esm/array.js +36 -46
- package/dist/esm/async.js +41 -43
- package/dist/esm/base64.js +77 -66
- package/dist/esm/clipboard.js +55 -54
- package/dist/esm/cloneDeep.js +90 -91
- package/dist/esm/cookie.js +27 -30
- package/dist/esm/date.js +101 -98
- package/dist/esm/dom.js +114 -121
- package/dist/esm/download.js +78 -79
- package/dist/esm/easing.js +29 -32
- package/dist/esm/file.js +147 -152
- package/dist/esm/func.js +64 -78
- package/dist/esm/index.js +96 -8
- package/dist/esm/math.js +32 -38
- package/dist/esm/number.js +58 -61
- package/dist/esm/object.js +124 -127
- package/dist/esm/path.js +39 -43
- package/dist/esm/qs.js +34 -41
- package/dist/esm/random.js +31 -34
- package/dist/esm/string.js +74 -64
- package/dist/esm/tooltip.js +66 -69
- package/dist/esm/tree.js +265 -263
- package/dist/esm/type.js +68 -47
- package/dist/esm/unique.js +39 -42
- package/dist/esm/url.js +47 -48
- package/dist/esm/validator.js +56 -39
- package/dist/esm/variable.js +27 -21
- package/dist/esm/watermark.js +79 -68
- package/dist/types/array.d.ts +0 -1
- package/dist/types/async.d.ts +0 -1
- package/dist/types/base64.d.ts +0 -1
- package/dist/types/clipboard.d.ts +0 -1
- package/dist/types/cloneDeep.d.ts +0 -1
- package/dist/types/cookie.d.ts +0 -1
- package/dist/types/date.d.ts +0 -1
- package/dist/types/dom.d.ts +0 -1
- package/dist/types/download.d.ts +0 -1
- package/dist/types/easing.d.ts +0 -1
- package/dist/types/file.d.ts +0 -1
- package/dist/types/func.d.ts +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/math.d.ts +0 -1
- package/dist/types/number.d.ts +0 -1
- package/dist/types/object.d.ts +0 -1
- package/dist/types/path.d.ts +0 -1
- package/dist/types/qs.d.ts +0 -1
- package/dist/types/random.d.ts +0 -1
- package/dist/types/string.d.ts +0 -1
- package/dist/types/tooltip.d.ts +0 -1
- package/dist/types/tree.d.ts +2 -2
- package/dist/types/type.d.ts +0 -1
- package/dist/types/unique.d.ts +0 -1
- package/dist/types/url.d.ts +0 -1
- package/dist/types/validator.d.ts +0 -1
- package/dist/types/variable.d.ts +0 -1
- package/dist/types/watermark.d.ts +0 -1
- package/dist/umd/index.min.js +2 -2
- package/package.json +12 -6
- package/dist/types/array.d.ts.map +0 -1
- package/dist/types/async.d.ts.map +0 -1
- package/dist/types/base64.d.ts.map +0 -1
- package/dist/types/clipboard.d.ts.map +0 -1
- package/dist/types/cloneDeep.d.ts.map +0 -1
- package/dist/types/cookie.d.ts.map +0 -1
- package/dist/types/core-index.d.ts +0 -17
- package/dist/types/core-index.d.ts.map +0 -1
- package/dist/types/date.d.ts.map +0 -1
- package/dist/types/dom.d.ts.map +0 -1
- package/dist/types/download.d.ts.map +0 -1
- package/dist/types/easing.d.ts.map +0 -1
- package/dist/types/file.d.ts.map +0 -1
- package/dist/types/func.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -3278
- package/dist/types/math.d.ts.map +0 -1
- package/dist/types/number.d.ts.map +0 -1
- package/dist/types/object.d.ts.map +0 -1
- package/dist/types/path.d.ts.map +0 -1
- package/dist/types/qs.d.ts.map +0 -1
- package/dist/types/random.d.ts.map +0 -1
- package/dist/types/string.d.ts.map +0 -1
- package/dist/types/tooltip.d.ts.map +0 -1
- package/dist/types/tree.d.ts.map +0 -1
- package/dist/types/type.d.ts.map +0 -1
- package/dist/types/unique.d.ts.map +0 -1
- package/dist/types/url.d.ts.map +0 -1
- package/dist/types/validator.d.ts.map +0 -1
- package/dist/types/variable.d.ts.map +0 -1
- package/dist/types/watermark.d.ts.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.13.
|
|
2
|
+
* sculp-js v1.13.6
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
function getDefaultExportFromCjs
|
|
10
|
-
|
|
9
|
+
function getDefaultExportFromCjs(x) {
|
|
10
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
|
package/dist/cjs/array.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.13.
|
|
2
|
+
* sculp-js v1.13.6
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -15,26 +15,21 @@
|
|
|
15
15
|
* @returns {*}
|
|
16
16
|
*/
|
|
17
17
|
function arrayEach(array, iterator, reverse = false) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
else if (re === true)
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
18
|
+
if (reverse) {
|
|
19
|
+
for (let idx = array.length - 1; idx >= 0; idx--) {
|
|
20
|
+
const re = iterator(array[idx], idx, array);
|
|
21
|
+
if (re === false) break;
|
|
22
|
+
else if (re === true) continue;
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else if (re === true)
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
24
|
+
} else {
|
|
25
|
+
for (let idx = 0, len = array.length; idx < len; idx++) {
|
|
26
|
+
const re = iterator(array[idx], idx, array);
|
|
27
|
+
if (re === false) break;
|
|
28
|
+
else if (re === true) continue;
|
|
35
29
|
}
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
}
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
array = null;
|
|
38
33
|
}
|
|
39
34
|
/**
|
|
40
35
|
* 异步遍历数组,返回 false 中断遍历
|
|
@@ -60,18 +55,15 @@ function arrayEach(array, iterator, reverse = false) {
|
|
|
60
55
|
* }
|
|
61
56
|
*/
|
|
62
57
|
async function arrayEachAsync(array, iterator, reverse = false) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
58
|
+
if (reverse) {
|
|
59
|
+
for (let idx = array.length - 1; idx >= 0; idx--) {
|
|
60
|
+
if ((await iterator(array[idx], idx)) === false) break;
|
|
68
61
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
62
|
+
} else {
|
|
63
|
+
for (let idx = 0, len = array.length; idx < len; idx++) {
|
|
64
|
+
if ((await iterator(array[idx], idx)) === false) break;
|
|
74
65
|
}
|
|
66
|
+
}
|
|
75
67
|
}
|
|
76
68
|
/**
|
|
77
69
|
* 插入到目标位置之前
|
|
@@ -81,11 +73,10 @@ async function arrayEachAsync(array, iterator, reverse = false) {
|
|
|
81
73
|
* @returns {*}
|
|
82
74
|
*/
|
|
83
75
|
function arrayInsertBefore(array, start, to) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
array.splice(insertIndex, 0, source);
|
|
76
|
+
if (start === to || start + 1 === to) return;
|
|
77
|
+
const [source] = array.splice(start, 1);
|
|
78
|
+
const insertIndex = to < start ? to : to - 1;
|
|
79
|
+
array.splice(insertIndex, 0, source);
|
|
89
80
|
}
|
|
90
81
|
/**
|
|
91
82
|
* 数组删除指定项目
|
|
@@ -94,18 +85,17 @@ function arrayInsertBefore(array, start, to) {
|
|
|
94
85
|
* @returns {V[]}
|
|
95
86
|
*/
|
|
96
87
|
function arrayRemove(array, expect) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return array;
|
|
88
|
+
const indexes = [];
|
|
89
|
+
// 这里重命名一下:是为了杜绝 jest 里的 expect 与之产生检查错误
|
|
90
|
+
// eslint 的 jest 语法检查是遇到 expect 函数就以为是单元测试
|
|
91
|
+
const _expect = expect;
|
|
92
|
+
arrayEach(array, (val, idx) => {
|
|
93
|
+
if (_expect(val, idx)) indexes.push(idx);
|
|
94
|
+
});
|
|
95
|
+
indexes.forEach((val, idx) => {
|
|
96
|
+
array.splice(val - idx, 1);
|
|
97
|
+
});
|
|
98
|
+
return array;
|
|
109
99
|
}
|
|
110
100
|
|
|
111
101
|
exports.arrayEach = arrayEach;
|
package/dist/cjs/async.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.13.
|
|
2
|
+
* sculp-js v1.13.6
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @returns {Promise<void>}
|
|
13
13
|
*/
|
|
14
14
|
function wait(timeout = 1) {
|
|
15
|
-
|
|
15
|
+
return new Promise(resolve => setTimeout(resolve, timeout));
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* 异步遍历
|
|
@@ -24,39 +24,37 @@ function wait(timeout = 1) {
|
|
|
24
24
|
* @returns {Promise<R[]>}
|
|
25
25
|
*/
|
|
26
26
|
function asyncMap(list, mapper, concurrency = Infinity) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
});
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const iterator = list[Symbol.iterator]();
|
|
29
|
+
const limit = Math.min(list.length, concurrency);
|
|
30
|
+
const resolves = [];
|
|
31
|
+
let resolvedLength = 0;
|
|
32
|
+
let rejected;
|
|
33
|
+
let index = 0;
|
|
34
|
+
const next = () => {
|
|
35
|
+
if (rejected) return reject(rejected);
|
|
36
|
+
const it = iterator.next();
|
|
37
|
+
if (it.done) {
|
|
38
|
+
if (resolvedLength === list.length) resolve(resolves);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const current = index++;
|
|
42
|
+
mapper(it.value, current, list)
|
|
43
|
+
.then(value => {
|
|
44
|
+
resolvedLength++;
|
|
45
|
+
resolves[current] = value;
|
|
46
|
+
next();
|
|
47
|
+
})
|
|
48
|
+
.catch(err => {
|
|
49
|
+
rejected = err;
|
|
50
|
+
next();
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
// 开始
|
|
54
|
+
for (let i = 0; i < limit; i++) {
|
|
55
|
+
next();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
60
58
|
}
|
|
61
59
|
/**
|
|
62
60
|
* Execute a promise safely
|
|
@@ -78,14 +76,14 @@ function asyncMap(list, mapper, concurrency = Infinity) {
|
|
|
78
76
|
}
|
|
79
77
|
*/
|
|
80
78
|
function safeAwait(promise, errorExt) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
return promise
|
|
80
|
+
.then(data => [null, data])
|
|
81
|
+
.catch(err => {
|
|
82
|
+
if (errorExt) {
|
|
83
|
+
const parsedError = Object.assign({}, err, errorExt);
|
|
84
|
+
return [parsedError, undefined];
|
|
85
|
+
}
|
|
86
|
+
return [err, undefined];
|
|
89
87
|
});
|
|
90
88
|
}
|
|
91
89
|
|
package/dist/cjs/base64.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.13.
|
|
2
|
+
* sculp-js v1.13.6
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -18,22 +18,29 @@ const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3
|
|
|
18
18
|
* @returns {string}
|
|
19
19
|
*/
|
|
20
20
|
function weBtoa(string) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
// 同window.btoa: 字符串编码成Base64
|
|
22
|
+
string = String(string);
|
|
23
|
+
let bitmap,
|
|
24
|
+
a,
|
|
25
|
+
b,
|
|
26
|
+
c,
|
|
27
|
+
result = '',
|
|
28
|
+
i = 0;
|
|
29
|
+
const strLen = string.length;
|
|
30
|
+
const rest = strLen % 3;
|
|
31
|
+
for (; i < strLen; ) {
|
|
32
|
+
if ((a = string.charCodeAt(i++)) > 255 || (b = string.charCodeAt(i++)) > 255 || (c = string.charCodeAt(i++)) > 255)
|
|
33
|
+
throw new TypeError(
|
|
34
|
+
"Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."
|
|
35
|
+
);
|
|
36
|
+
bitmap = (a << 16) | (b << 8) | c;
|
|
37
|
+
result +=
|
|
38
|
+
b64.charAt((bitmap >> 18) & 63) +
|
|
39
|
+
b64.charAt((bitmap >> 12) & 63) +
|
|
40
|
+
b64.charAt((bitmap >> 6) & 63) +
|
|
41
|
+
b64.charAt(bitmap & 63);
|
|
42
|
+
}
|
|
43
|
+
return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;
|
|
37
44
|
}
|
|
38
45
|
/**
|
|
39
46
|
* Base64解码为原始字符串,平替浏览器的atob, 不包含中文的处理(适用于任何环境,包括小程序)
|
|
@@ -41,38 +48,42 @@ function weBtoa(string) {
|
|
|
41
48
|
* @returns {string}
|
|
42
49
|
*/
|
|
43
50
|
function weAtob(string) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
// 同window.atob: Base64解码为原始字符串
|
|
52
|
+
string = String(string).replace(/[\t\n\f\r ]+/g, '');
|
|
53
|
+
if (!b64re.test(string))
|
|
54
|
+
throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
|
55
|
+
string += '=='.slice(2 - (string.length & 3));
|
|
56
|
+
let bitmap,
|
|
57
|
+
result = '',
|
|
58
|
+
r1,
|
|
59
|
+
r2,
|
|
60
|
+
i = 0;
|
|
61
|
+
for (const strLen = string.length; i < strLen; ) {
|
|
62
|
+
bitmap =
|
|
63
|
+
(b64.indexOf(string.charAt(i++)) << 18) |
|
|
64
|
+
(b64.indexOf(string.charAt(i++)) << 12) |
|
|
65
|
+
((r1 = b64.indexOf(string.charAt(i++))) << 6) |
|
|
66
|
+
(r2 = b64.indexOf(string.charAt(i++)));
|
|
67
|
+
result +=
|
|
68
|
+
r1 === 64
|
|
69
|
+
? String.fromCharCode((bitmap >> 16) & 255)
|
|
70
|
+
: r2 === 64
|
|
71
|
+
? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
|
|
72
|
+
: String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
64
75
|
}
|
|
65
76
|
function stringToUint8Array(str) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
const utf8 = encodeURIComponent(str); // 将字符串转换为 UTF-8 编码
|
|
78
|
+
const uint8Array = new Uint8Array(utf8.length); // 创建 Uint8Array
|
|
79
|
+
for (let i = 0; i < utf8.length; i++) {
|
|
80
|
+
uint8Array[i] = utf8.charCodeAt(i); // 填充 Uint8Array
|
|
81
|
+
}
|
|
82
|
+
return uint8Array;
|
|
72
83
|
}
|
|
73
84
|
function uint8ArrayToString(uint8Array) {
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
const utf8 = String.fromCharCode.apply(null, uint8Array); // 将 Uint8Array 转为字符串
|
|
86
|
+
return decodeURIComponent(utf8); // 将 UTF-8 字符串解码回正常字符串
|
|
76
87
|
}
|
|
77
88
|
/**
|
|
78
89
|
* 将base64编码的字符串转换为原始字符串,包括对中文内容的处理(高性能,且支持Web、Node、小程序等任意平台)
|
|
@@ -80,16 +91,16 @@ function uint8ArrayToString(uint8Array) {
|
|
|
80
91
|
* @returns 原始字符串,包括中文内容
|
|
81
92
|
*/
|
|
82
93
|
function b64decode(base64) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
const binaryString = !type.isNullOrUnDef(func.getGlobal('atob')) ? func.getGlobal('atob')(base64) : weAtob(base64);
|
|
95
|
+
const len = binaryString.length;
|
|
96
|
+
const bytes = new Uint8Array(len);
|
|
97
|
+
for (let i = 0; i < len; i++) {
|
|
98
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
99
|
+
}
|
|
100
|
+
// 使用TextDecoder将Uint8Array转换为原始字符串,包括中文内容
|
|
101
|
+
return !type.isNullOrUnDef(func.getGlobal('TextDecoder'))
|
|
102
|
+
? new (func.getGlobal('TextDecoder'))('utf-8').decode(bytes)
|
|
103
|
+
: uint8ArrayToString(bytes);
|
|
93
104
|
}
|
|
94
105
|
/**
|
|
95
106
|
* 将原始字符串,包括中文内容,转换为base64编码的字符串(高性能,且支持Web、Node、小程序等任意平台)
|
|
@@ -97,17 +108,17 @@ function b64decode(base64) {
|
|
|
97
108
|
* @returns base64编码的字符串
|
|
98
109
|
*/
|
|
99
110
|
function b64encode(rawStr) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
const utf8Array = !type.isNullOrUnDef(func.getGlobal('TextEncoder'))
|
|
112
|
+
? new (func.getGlobal('TextEncoder'))().encode(rawStr)
|
|
113
|
+
: stringToUint8Array(rawStr);
|
|
114
|
+
// 将 Uint8Array 转换为二进制字符串
|
|
115
|
+
let binaryString = '';
|
|
116
|
+
const len = utf8Array.length;
|
|
117
|
+
for (let i = 0; i < len; i++) {
|
|
118
|
+
binaryString += String.fromCharCode(utf8Array[i]);
|
|
119
|
+
}
|
|
120
|
+
// 将二进制字符串转换为base64编码的字符串
|
|
121
|
+
return !type.isNullOrUnDef(func.getGlobal('btoa')) ? func.getGlobal('btoa')(binaryString) : weBtoa(binaryString);
|
|
111
122
|
}
|
|
112
123
|
|
|
113
124
|
exports.b64decode = b64decode;
|
package/dist/cjs/clipboard.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.13.
|
|
2
|
+
* sculp-js v1.13.6
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -17,23 +17,22 @@ var type = require('./type.js');
|
|
|
17
17
|
* 解决脱离文档流的元素无法复制的问题,如Modal内复制操作)
|
|
18
18
|
*/
|
|
19
19
|
function copyText(text, options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
fallbackCopyText(text, options);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
// 使用旧版execCommand方法
|
|
20
|
+
const { successCallback = void 0, failCallback = void 0 } = type.isNullOrUnDef(options) ? {} : options;
|
|
21
|
+
if (navigator.clipboard) {
|
|
22
|
+
navigator.clipboard
|
|
23
|
+
.writeText(text)
|
|
24
|
+
.then(() => {
|
|
25
|
+
if (type.isFunction(successCallback)) {
|
|
26
|
+
successCallback();
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
.catch(err => {
|
|
35
30
|
fallbackCopyText(text, options);
|
|
36
|
-
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
// 使用旧版execCommand方法
|
|
34
|
+
fallbackCopyText(text, options);
|
|
35
|
+
}
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
38
|
* 使用execCommand方式复制文本
|
|
@@ -41,27 +40,29 @@ function copyText(text, options) {
|
|
|
41
40
|
* @param options
|
|
42
41
|
*/
|
|
43
42
|
function fallbackCopyText(text, options) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
failCallback(err);
|
|
57
|
-
}
|
|
43
|
+
const {
|
|
44
|
+
successCallback = void 0,
|
|
45
|
+
failCallback = void 0,
|
|
46
|
+
container = document.body
|
|
47
|
+
} = type.isNullOrUnDef(options) ? {} : options;
|
|
48
|
+
let textEl = createFakeElement(text);
|
|
49
|
+
container.appendChild(textEl);
|
|
50
|
+
dom.select(textEl);
|
|
51
|
+
try {
|
|
52
|
+
const res = document.execCommand('copy');
|
|
53
|
+
if (res && type.isFunction(successCallback)) {
|
|
54
|
+
successCallback();
|
|
58
55
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
textEl = null;
|
|
63
|
-
window.getSelection()?.removeAllRanges(); // 清除选区
|
|
56
|
+
} catch (err) {
|
|
57
|
+
if (type.isFunction(failCallback)) {
|
|
58
|
+
failCallback(err);
|
|
64
59
|
}
|
|
60
|
+
} finally {
|
|
61
|
+
container.removeChild(textEl);
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
textEl = null;
|
|
64
|
+
window.getSelection()?.removeAllRanges(); // 清除选区
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Creates a fake textarea element with a value.
|
|
@@ -69,23 +70,23 @@ function fallbackCopyText(text, options) {
|
|
|
69
70
|
* @return {HTMLElement}
|
|
70
71
|
*/
|
|
71
72
|
function createFakeElement(value) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
73
|
+
const isRTL = document.documentElement.getAttribute('dir') === 'rtl';
|
|
74
|
+
const fakeElement = document.createElement('textarea');
|
|
75
|
+
// Prevent zooming on iOS
|
|
76
|
+
fakeElement.style.fontSize = '12pt';
|
|
77
|
+
// Reset box model
|
|
78
|
+
fakeElement.style.border = '0';
|
|
79
|
+
fakeElement.style.padding = '0';
|
|
80
|
+
fakeElement.style.margin = '0';
|
|
81
|
+
// Move element out of screen horizontally
|
|
82
|
+
fakeElement.style.position = 'absolute';
|
|
83
|
+
fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px';
|
|
84
|
+
// Move element to the same position vertically
|
|
85
|
+
const yPosition = window.pageYOffset || document.documentElement.scrollTop;
|
|
86
|
+
fakeElement.style.top = `${yPosition}px`;
|
|
87
|
+
fakeElement.setAttribute('readonly', '');
|
|
88
|
+
fakeElement.value = value;
|
|
89
|
+
return fakeElement;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
exports.copyText = copyText;
|