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.
Files changed (119) hide show
  1. package/dist/cjs/_virtual/_commonjsHelpers.js +3 -3
  2. package/dist/cjs/array.js +36 -46
  3. package/dist/cjs/async.js +41 -43
  4. package/dist/cjs/base64.js +77 -66
  5. package/dist/cjs/clipboard.js +54 -53
  6. package/dist/cjs/cloneDeep.js +90 -91
  7. package/dist/cjs/cookie.js +27 -30
  8. package/dist/cjs/date.js +101 -98
  9. package/dist/cjs/dom.js +114 -121
  10. package/dist/cjs/download.js +77 -78
  11. package/dist/cjs/easing.js +29 -32
  12. package/dist/cjs/file.js +147 -152
  13. package/dist/cjs/func.js +64 -78
  14. package/dist/cjs/index.js +1 -3
  15. package/dist/cjs/math.js +32 -38
  16. package/dist/cjs/node_modules/bezier-easing/src/index.js +35 -23
  17. package/dist/cjs/number.js +58 -61
  18. package/dist/cjs/object.js +112 -126
  19. package/dist/cjs/path.js +39 -43
  20. package/dist/cjs/qs.js +34 -41
  21. package/dist/cjs/random.js +31 -34
  22. package/dist/cjs/string.js +62 -63
  23. package/dist/cjs/tooltip.js +66 -69
  24. package/dist/cjs/tree.js +265 -263
  25. package/dist/cjs/type.js +42 -46
  26. package/dist/cjs/unique.js +39 -42
  27. package/dist/cjs/url.js +47 -48
  28. package/dist/cjs/validator.js +38 -38
  29. package/dist/cjs/variable.js +27 -21
  30. package/dist/cjs/watermark.js +78 -67
  31. package/dist/esm/array.js +36 -46
  32. package/dist/esm/async.js +41 -43
  33. package/dist/esm/base64.js +77 -66
  34. package/dist/esm/clipboard.js +55 -54
  35. package/dist/esm/cloneDeep.js +90 -91
  36. package/dist/esm/cookie.js +27 -30
  37. package/dist/esm/date.js +101 -98
  38. package/dist/esm/dom.js +114 -121
  39. package/dist/esm/download.js +78 -79
  40. package/dist/esm/easing.js +29 -32
  41. package/dist/esm/file.js +147 -152
  42. package/dist/esm/func.js +64 -78
  43. package/dist/esm/index.js +96 -8
  44. package/dist/esm/math.js +32 -38
  45. package/dist/esm/number.js +58 -61
  46. package/dist/esm/object.js +124 -127
  47. package/dist/esm/path.js +39 -43
  48. package/dist/esm/qs.js +34 -41
  49. package/dist/esm/random.js +31 -34
  50. package/dist/esm/string.js +74 -64
  51. package/dist/esm/tooltip.js +66 -69
  52. package/dist/esm/tree.js +265 -263
  53. package/dist/esm/type.js +68 -47
  54. package/dist/esm/unique.js +39 -42
  55. package/dist/esm/url.js +47 -48
  56. package/dist/esm/validator.js +56 -39
  57. package/dist/esm/variable.js +27 -21
  58. package/dist/esm/watermark.js +79 -68
  59. package/dist/types/array.d.ts +0 -1
  60. package/dist/types/async.d.ts +0 -1
  61. package/dist/types/base64.d.ts +0 -1
  62. package/dist/types/clipboard.d.ts +0 -1
  63. package/dist/types/cloneDeep.d.ts +0 -1
  64. package/dist/types/cookie.d.ts +0 -1
  65. package/dist/types/date.d.ts +0 -1
  66. package/dist/types/dom.d.ts +0 -1
  67. package/dist/types/download.d.ts +0 -1
  68. package/dist/types/easing.d.ts +0 -1
  69. package/dist/types/file.d.ts +0 -1
  70. package/dist/types/func.d.ts +0 -1
  71. package/dist/types/index.d.ts +0 -1
  72. package/dist/types/math.d.ts +0 -1
  73. package/dist/types/number.d.ts +0 -1
  74. package/dist/types/object.d.ts +0 -1
  75. package/dist/types/path.d.ts +0 -1
  76. package/dist/types/qs.d.ts +0 -1
  77. package/dist/types/random.d.ts +0 -1
  78. package/dist/types/string.d.ts +0 -1
  79. package/dist/types/tooltip.d.ts +0 -1
  80. package/dist/types/tree.d.ts +2 -2
  81. package/dist/types/type.d.ts +0 -1
  82. package/dist/types/unique.d.ts +0 -1
  83. package/dist/types/url.d.ts +0 -1
  84. package/dist/types/validator.d.ts +0 -1
  85. package/dist/types/variable.d.ts +0 -1
  86. package/dist/types/watermark.d.ts +0 -1
  87. package/dist/umd/index.min.js +2 -2
  88. package/package.json +12 -6
  89. package/dist/types/array.d.ts.map +0 -1
  90. package/dist/types/async.d.ts.map +0 -1
  91. package/dist/types/base64.d.ts.map +0 -1
  92. package/dist/types/clipboard.d.ts.map +0 -1
  93. package/dist/types/cloneDeep.d.ts.map +0 -1
  94. package/dist/types/cookie.d.ts.map +0 -1
  95. package/dist/types/core-index.d.ts +0 -17
  96. package/dist/types/core-index.d.ts.map +0 -1
  97. package/dist/types/date.d.ts.map +0 -1
  98. package/dist/types/dom.d.ts.map +0 -1
  99. package/dist/types/download.d.ts.map +0 -1
  100. package/dist/types/easing.d.ts.map +0 -1
  101. package/dist/types/file.d.ts.map +0 -1
  102. package/dist/types/func.d.ts.map +0 -1
  103. package/dist/types/index.d.ts.map +0 -1
  104. package/dist/types/index.js +0 -3278
  105. package/dist/types/math.d.ts.map +0 -1
  106. package/dist/types/number.d.ts.map +0 -1
  107. package/dist/types/object.d.ts.map +0 -1
  108. package/dist/types/path.d.ts.map +0 -1
  109. package/dist/types/qs.d.ts.map +0 -1
  110. package/dist/types/random.d.ts.map +0 -1
  111. package/dist/types/string.d.ts.map +0 -1
  112. package/dist/types/tooltip.d.ts.map +0 -1
  113. package/dist/types/tree.d.ts.map +0 -1
  114. package/dist/types/type.d.ts.map +0 -1
  115. package/dist/types/unique.d.ts.map +0 -1
  116. package/dist/types/url.d.ts.map +0 -1
  117. package/dist/types/validator.d.ts.map +0 -1
  118. package/dist/types/variable.d.ts.map +0 -1
  119. package/dist/types/watermark.d.ts.map +0 -1
@@ -1,13 +1,13 @@
1
1
  /*!
2
- * sculp-js v1.13.3-beta.0
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 (x) {
10
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
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.3-beta.0
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
- if (reverse) {
19
- for (let idx = array.length - 1; idx >= 0; idx--) {
20
- const re = iterator(array[idx], idx, array);
21
- if (re === false)
22
- break;
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
- else {
28
- for (let idx = 0, len = array.length; idx < len; idx++) {
29
- const re = iterator(array[idx], idx, array);
30
- if (re === false)
31
- break;
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
- // @ts-ignore
37
- array = null;
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
- if (reverse) {
64
- for (let idx = array.length - 1; idx >= 0; idx--) {
65
- if ((await iterator(array[idx], idx)) === false)
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
- else {
70
- for (let idx = 0, len = array.length; idx < len; idx++) {
71
- if ((await iterator(array[idx], idx)) === false)
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
- if (start === to || start + 1 === to)
85
- return;
86
- const [source] = array.splice(start, 1);
87
- const insertIndex = to < start ? to : to - 1;
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
- const indexes = [];
98
- // 这里重命名一下:是为了杜绝 jest 里的 expect 与之产生检查错误
99
- // eslint 的 jest 语法检查是遇到 expect 函数就以为是单元测试
100
- const _expect = expect;
101
- arrayEach(array, (val, idx) => {
102
- if (_expect(val, idx))
103
- indexes.push(idx);
104
- });
105
- indexes.forEach((val, idx) => {
106
- array.splice(val - idx, 1);
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.3-beta.0
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
- return new Promise(resolve => setTimeout(resolve, timeout));
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
- 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)
36
- return reject(rejected);
37
- const it = iterator.next();
38
- if (it.done) {
39
- if (resolvedLength === list.length)
40
- resolve(resolves);
41
- return;
42
- }
43
- const current = index++;
44
- mapper(it.value, current, list)
45
- .then(value => {
46
- resolvedLength++;
47
- resolves[current] = value;
48
- next();
49
- })
50
- .catch(err => {
51
- rejected = err;
52
- next();
53
- });
54
- };
55
- // 开始
56
- for (let i = 0; i < limit; i++) {
57
- next();
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
- return promise
82
- .then((data) => [null, data])
83
- .catch((err) => {
84
- if (errorExt) {
85
- const parsedError = Object.assign({}, err, errorExt);
86
- return [parsedError, undefined];
87
- }
88
- return [err, undefined];
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
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.3-beta.0
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
- // 同window.btoa: 字符串编码成Base64
22
- string = String(string);
23
- let bitmap, a, b, c, result = '', i = 0;
24
- const strLen = string.length;
25
- const rest = strLen % 3;
26
- for (; i < strLen;) {
27
- if ((a = string.charCodeAt(i++)) > 255 || (b = string.charCodeAt(i++)) > 255 || (c = string.charCodeAt(i++)) > 255)
28
- throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");
29
- bitmap = (a << 16) | (b << 8) | c;
30
- result +=
31
- b64.charAt((bitmap >> 18) & 63) +
32
- b64.charAt((bitmap >> 12) & 63) +
33
- b64.charAt((bitmap >> 6) & 63) +
34
- b64.charAt(bitmap & 63);
35
- }
36
- return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;
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
- // 同window.atob: Base64解码为原始字符串
45
- string = String(string).replace(/[\t\n\f\r ]+/g, '');
46
- if (!b64re.test(string))
47
- throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
48
- string += '=='.slice(2 - (string.length & 3));
49
- let bitmap, result = '', r1, r2, i = 0;
50
- for (const strLen = string.length; i < strLen;) {
51
- bitmap =
52
- (b64.indexOf(string.charAt(i++)) << 18) |
53
- (b64.indexOf(string.charAt(i++)) << 12) |
54
- ((r1 = b64.indexOf(string.charAt(i++))) << 6) |
55
- (r2 = b64.indexOf(string.charAt(i++)));
56
- result +=
57
- r1 === 64
58
- ? String.fromCharCode((bitmap >> 16) & 255)
59
- : r2 === 64
60
- ? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
61
- : String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
62
- }
63
- return result;
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
- const utf8 = encodeURIComponent(str); // 将字符串转换为 UTF-8 编码
67
- const uint8Array = new Uint8Array(utf8.length); // 创建 Uint8Array
68
- for (let i = 0; i < utf8.length; i++) {
69
- uint8Array[i] = utf8.charCodeAt(i); // 填充 Uint8Array
70
- }
71
- return uint8Array;
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
- const utf8 = String.fromCharCode.apply(null, uint8Array); // 将 Uint8Array 转为字符串
75
- return decodeURIComponent(utf8); // 将 UTF-8 字符串解码回正常字符串
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
- const binaryString = !type.isNullOrUnDef(func.getGlobal('atob')) ? func.getGlobal('atob')(base64) : weAtob(base64);
84
- const len = binaryString.length;
85
- const bytes = new Uint8Array(len);
86
- for (let i = 0; i < len; i++) {
87
- bytes[i] = binaryString.charCodeAt(i);
88
- }
89
- // 使用TextDecoder将Uint8Array转换为原始字符串,包括中文内容
90
- return !type.isNullOrUnDef(func.getGlobal('TextDecoder'))
91
- ? new (func.getGlobal('TextDecoder'))('utf-8').decode(bytes)
92
- : uint8ArrayToString(bytes);
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
- const utf8Array = !type.isNullOrUnDef(func.getGlobal('TextEncoder'))
101
- ? new (func.getGlobal('TextEncoder'))().encode(rawStr)
102
- : stringToUint8Array(rawStr);
103
- // 将 Uint8Array 转换为二进制字符串
104
- let binaryString = '';
105
- const len = utf8Array.length;
106
- for (let i = 0; i < len; i++) {
107
- binaryString += String.fromCharCode(utf8Array[i]);
108
- }
109
- // 将二进制字符串转换为base64编码的字符串
110
- return !type.isNullOrUnDef(func.getGlobal('btoa')) ? func.getGlobal('btoa')(binaryString) : weBtoa(binaryString);
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;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.3-beta.0
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
- 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 => {
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
- const { successCallback = void 0, failCallback = void 0, container = document.body } = type.isNullOrUnDef(options) ? {} : options;
45
- let textEl = createFakeElement(text);
46
- container.appendChild(textEl);
47
- dom.select(textEl);
48
- try {
49
- const res = document.execCommand('copy');
50
- if (res && type.isFunction(successCallback)) {
51
- successCallback();
52
- }
53
- }
54
- catch (err) {
55
- if (type.isFunction(failCallback)) {
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
- finally {
60
- container.removeChild(textEl);
61
- // @ts-ignore
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
- const isRTL = document.documentElement.getAttribute('dir') === 'rtl';
73
- const fakeElement = document.createElement('textarea');
74
- // Prevent zooming on iOS
75
- fakeElement.style.fontSize = '12pt';
76
- // Reset box model
77
- fakeElement.style.border = '0';
78
- fakeElement.style.padding = '0';
79
- fakeElement.style.margin = '0';
80
- // Move element out of screen horizontally
81
- fakeElement.style.position = 'absolute';
82
- fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px';
83
- // Move element to the same position vertically
84
- const yPosition = window.pageYOffset || document.documentElement.scrollTop;
85
- fakeElement.style.top = `${yPosition}px`;
86
- fakeElement.setAttribute('readonly', '');
87
- fakeElement.value = value;
88
- return fakeElement;
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;