sculp-js 1.13.1 → 1.13.2

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 (127) hide show
  1. package/README.md +10 -11
  2. package/dist/cjs/_virtual/_commonjsHelpers.js +13 -0
  3. package/{lib → dist}/cjs/array.js +1 -1
  4. package/{lib → dist}/cjs/async.js +1 -1
  5. package/{lib/cjs/we-decode.js → dist/cjs/base64.js} +53 -44
  6. package/{lib → dist}/cjs/clipboard.js +1 -1
  7. package/{lib → dist}/cjs/cloneDeep.js +1 -1
  8. package/{lib → dist}/cjs/cookie.js +1 -1
  9. package/{lib → dist}/cjs/date.js +1 -1
  10. package/{lib → dist}/cjs/dom.js +1 -1
  11. package/{lib → dist}/cjs/download.js +1 -1
  12. package/dist/cjs/easing.js +75 -0
  13. package/{lib → dist}/cjs/file.js +1 -1
  14. package/{lib → dist}/cjs/func.js +1 -1
  15. package/{lib → dist}/cjs/index.js +10 -8
  16. package/{lib → dist}/cjs/math.js +1 -1
  17. package/dist/cjs/node_modules/bezier-easing/src/index.js +123 -0
  18. package/{lib → dist}/cjs/number.js +1 -1
  19. package/{lib → dist}/cjs/object.js +1 -1
  20. package/{lib → dist}/cjs/path.js +1 -1
  21. package/{lib → dist}/cjs/qs.js +1 -1
  22. package/{lib → dist}/cjs/random.js +1 -1
  23. package/{lib → dist}/cjs/string.js +1 -1
  24. package/{lib → dist}/cjs/tooltip.js +1 -1
  25. package/{lib → dist}/cjs/tree.js +1 -16
  26. package/{lib → dist}/cjs/type.js +1 -1
  27. package/{lib → dist}/cjs/unique.js +1 -1
  28. package/{lib → dist}/cjs/url.js +1 -1
  29. package/{lib → dist}/cjs/validator.js +1 -1
  30. package/{lib → dist}/cjs/variable.js +1 -1
  31. package/{lib → dist}/cjs/watermark.js +1 -1
  32. package/{lib/es → dist/esm}/array.js +1 -1
  33. package/{lib/es → dist/esm}/async.js +1 -1
  34. package/{lib/es/we-decode.js → dist/esm/base64.js} +52 -45
  35. package/{lib/es → dist/esm}/clipboard.js +1 -1
  36. package/{lib/es → dist/esm}/cloneDeep.js +1 -1
  37. package/{lib/es → dist/esm}/cookie.js +1 -1
  38. package/{lib/es → dist/esm}/date.js +1 -1
  39. package/{lib/es → dist/esm}/dom.js +1 -1
  40. package/{lib/es → dist/esm}/download.js +1 -1
  41. package/{lib/es → dist/esm}/easing.js +34 -2
  42. package/{lib/es → dist/esm}/file.js +1 -1
  43. package/{lib/es → dist/esm}/func.js +1 -1
  44. package/{lib/es → dist/esm}/index.js +3 -4
  45. package/{lib/es → dist/esm}/math.js +1 -1
  46. package/{lib/es → dist/esm}/number.js +1 -1
  47. package/{lib/es → dist/esm}/object.js +1 -1
  48. package/{lib/es → dist/esm}/path.js +1 -1
  49. package/{lib/es → dist/esm}/qs.js +1 -1
  50. package/{lib/es → dist/esm}/random.js +1 -1
  51. package/{lib/es → dist/esm}/string.js +1 -1
  52. package/{lib/es → dist/esm}/tooltip.js +1 -1
  53. package/{lib/es → dist/esm}/tree.js +1 -16
  54. package/{lib/es → dist/esm}/type.js +1 -1
  55. package/{lib/es → dist/esm}/unique.js +1 -1
  56. package/{lib/es → dist/esm}/url.js +1 -1
  57. package/{lib/es → dist/esm}/validator.js +1 -1
  58. package/{lib/es → dist/esm}/variable.js +1 -1
  59. package/{lib/es → dist/esm}/watermark.js +1 -1
  60. package/dist/types/array.d.ts +50 -0
  61. package/dist/types/array.d.ts.map +1 -0
  62. package/dist/types/async.d.ts +37 -0
  63. package/dist/types/async.d.ts.map +1 -0
  64. package/dist/types/base64.d.ts +25 -0
  65. package/dist/types/base64.d.ts.map +1 -0
  66. package/dist/types/clipboard.d.ts +20 -0
  67. package/dist/types/clipboard.d.ts.map +1 -0
  68. package/dist/types/cloneDeep.d.ts +12 -0
  69. package/dist/types/cloneDeep.d.ts.map +1 -0
  70. package/dist/types/cookie.d.ts +19 -0
  71. package/dist/types/cookie.d.ts.map +1 -0
  72. package/dist/types/core-index.d.ts +17 -0
  73. package/dist/types/core-index.d.ts.map +1 -0
  74. package/dist/types/date.d.ts +74 -0
  75. package/dist/types/date.d.ts.map +1 -0
  76. package/dist/types/dom.d.ts +74 -0
  77. package/dist/types/dom.d.ts.map +1 -0
  78. package/dist/types/download.d.ts +47 -0
  79. package/dist/types/download.d.ts.map +1 -0
  80. package/dist/types/easing.d.ts +32 -0
  81. package/dist/types/easing.d.ts.map +1 -0
  82. package/dist/types/file.d.ts +44 -0
  83. package/dist/types/file.d.ts.map +1 -0
  84. package/dist/types/func.d.ts +50 -0
  85. package/dist/types/func.d.ts.map +1 -0
  86. package/dist/types/index.d.ts +28 -0
  87. package/dist/types/index.d.ts.map +1 -0
  88. package/dist/types/index.js +3258 -0
  89. package/dist/types/math.d.ts +36 -0
  90. package/dist/types/math.d.ts.map +1 -0
  91. package/dist/types/number.d.ts +49 -0
  92. package/dist/types/number.d.ts.map +1 -0
  93. package/dist/types/object.d.ts +70 -0
  94. package/dist/types/object.d.ts.map +1 -0
  95. package/dist/types/path.d.ts +14 -0
  96. package/dist/types/path.d.ts.map +1 -0
  97. package/dist/types/qs.d.ts +22 -0
  98. package/dist/types/qs.d.ts.map +1 -0
  99. package/dist/types/random.d.ts +27 -0
  100. package/dist/types/random.d.ts.map +1 -0
  101. package/dist/types/string.d.ts +67 -0
  102. package/dist/types/string.d.ts.map +1 -0
  103. package/dist/types/tooltip.d.ts +36 -0
  104. package/dist/types/tooltip.d.ts.map +1 -0
  105. package/dist/types/tree.d.ts +98 -0
  106. package/dist/types/tree.d.ts.map +1 -0
  107. package/dist/types/type.d.ts +124 -0
  108. package/dist/types/type.d.ts.map +1 -0
  109. package/dist/types/unique.d.ts +21 -0
  110. package/dist/types/unique.d.ts.map +1 -0
  111. package/dist/types/url.d.ts +46 -0
  112. package/dist/types/url.d.ts.map +1 -0
  113. package/dist/types/validator.d.ts +67 -0
  114. package/dist/types/validator.d.ts.map +1 -0
  115. package/dist/types/variable.d.ts +71 -0
  116. package/dist/types/variable.d.ts.map +1 -0
  117. package/dist/types/watermark.d.ts +19 -0
  118. package/dist/types/watermark.d.ts.map +1 -0
  119. package/dist/umd/index.min.js +6 -0
  120. package/package.json +234 -17
  121. package/lib/cjs/base64.js +0 -62
  122. package/lib/cjs/easing.js +0 -40
  123. package/lib/cjs/isEqual.js +0 -133
  124. package/lib/es/base64.js +0 -59
  125. package/lib/es/isEqual.js +0 -131
  126. package/lib/index.d.ts +0 -1214
  127. package/lib/umd/index.js +0 -6
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,9 +1,12 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
+ import { getGlobal } from './func.js';
8
+ import { isNullOrUnDef } from './type.js';
9
+
7
10
  const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
8
11
  // eslint-disable-next-line
9
12
  const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
@@ -57,48 +60,52 @@ function weAtob(string) {
57
60
  }
58
61
  return result;
59
62
  }
60
- // function b64DecodeUnicode(str) {
61
- // return decodeURIComponent(
62
- // exports.weAtob(str).replace(/(.)/g, function (p) {
63
- // let code = p.charCodeAt(0).toString(16).toUpperCase();
64
- // if (code.length < 2) {
65
- // code = '0' + code;
66
- // }
67
- // return '%' + code;
68
- // })
69
- // );
70
- // }
71
- // function base64_url_decode(str) {
72
- // let output = str.replace(/-/g, '+').replace(/_/g, '/');
73
- // switch (output.length % 4) {
74
- // case 0:
75
- // break;
76
- // case 2:
77
- // output += '==';
78
- // break;
79
- // case 3:
80
- // output += '=';
81
- // break;
82
- // default:
83
- // throw new Error('Illegal base64url string!');
84
- // }
85
- // try {
86
- // return b64DecodeUnicode(output);
87
- // } catch (err) {
88
- // return exports.weAtob(output);
89
- // }
90
- // }
91
- // export function weAppJwtDecode(token, options) {
92
- // if (typeof token !== 'string') {
93
- // throw new Error('Invalid token specified');
94
- // }
95
- // options = options || {};
96
- // const pos = options.header === true ? 0 : 1;
97
- // try {
98
- // return JSON.parse(base64_url_decode(token.split('.')[pos]));
99
- // } catch (e) {
100
- // throw new Error('Invalid token specified: ' + (e as Error).message);
101
- // }
102
- // }
63
+ function stringToUint8Array(str) {
64
+ const utf8 = encodeURIComponent(str); // 将字符串转换为 UTF-8 编码
65
+ const uint8Array = new Uint8Array(utf8.length); // 创建 Uint8Array
66
+ for (let i = 0; i < utf8.length; i++) {
67
+ uint8Array[i] = utf8.charCodeAt(i); // 填充 Uint8Array
68
+ }
69
+ return uint8Array;
70
+ }
71
+ function uint8ArrayToString(uint8Array) {
72
+ const utf8 = String.fromCharCode.apply(null, uint8Array); // 将 Uint8Array 转为字符串
73
+ return decodeURIComponent(utf8); // 将 UTF-8 字符串解码回正常字符串
74
+ }
75
+ /**
76
+ * 将base64编码的字符串转换为原始字符串,包括对中文内容的处理(高性能,且支持Web、Node、小程序等任意平台)
77
+ * @param base64 base64编码的字符串
78
+ * @returns 原始字符串,包括中文内容
79
+ */
80
+ function b64decode(base64) {
81
+ const binaryString = !isNullOrUnDef(getGlobal('atob')) ? getGlobal('atob')(base64) : weAtob(base64);
82
+ const len = binaryString.length;
83
+ const bytes = new Uint8Array(len);
84
+ for (let i = 0; i < len; i++) {
85
+ bytes[i] = binaryString.charCodeAt(i);
86
+ }
87
+ // 使用TextDecoder将Uint8Array转换为原始字符串,包括中文内容
88
+ return !isNullOrUnDef(getGlobal('TextDecoder'))
89
+ ? new (getGlobal('TextDecoder'))('utf-8').decode(bytes)
90
+ : uint8ArrayToString(bytes);
91
+ }
92
+ /**
93
+ * 将原始字符串,包括中文内容,转换为base64编码的字符串(高性能,且支持Web、Node、小程序等任意平台)
94
+ * @param rawStr 原始字符串,包括中文内容
95
+ * @returns base64编码的字符串
96
+ */
97
+ function b64encode(rawStr) {
98
+ const utf8Array = !isNullOrUnDef(getGlobal('TextEncoder'))
99
+ ? new (getGlobal('TextEncoder'))().encode(rawStr)
100
+ : stringToUint8Array(rawStr);
101
+ // 将 Uint8Array 转换为二进制字符串
102
+ let binaryString = '';
103
+ const len = utf8Array.length;
104
+ for (let i = 0; i < len; i++) {
105
+ binaryString += String.fromCharCode(utf8Array[i]);
106
+ }
107
+ // 将二进制字符串转换为base64编码的字符串
108
+ return !isNullOrUnDef(getGlobal('btoa')) ? getGlobal('btoa')(binaryString) : weBtoa(binaryString);
109
+ }
103
110
 
104
- export { weAtob, weBtoa };
111
+ export { b64decode, b64encode, weAtob, weBtoa };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -15,6 +15,19 @@ const easingDefines = {
15
15
  'ease-out': [0, 0, 0.58, 1],
16
16
  'ease-in-out': [0.42, 0, 0.58, 1]
17
17
  };
18
+ /**
19
+ * 设置缓存定义
20
+ * @param {string} name
21
+ * @param {EasingDefine} define
22
+ */
23
+ function setEasing(name, define) {
24
+ easingDefines[name] = define;
25
+ }
26
+ function getEasing(name) {
27
+ if (name)
28
+ return easingDefines[name];
29
+ return easingDefines;
30
+ }
18
31
  /**
19
32
  * 缓冲函数化,用于 js 计算缓冲进度
20
33
  * @param {EasingNameOrDefine} [name=linear]
@@ -34,5 +47,24 @@ function easingFunctional(name) {
34
47
  }
35
48
  return (input) => fn(Math.max(0, Math.min(input, 1)));
36
49
  }
50
+ /**
51
+ * 缓冲字符化,用于 css 设置缓冲属性
52
+ * @param {EasingNameOrDefine} name
53
+ * @returns {string}
54
+ */
55
+ function easingStringify(name) {
56
+ let bezierDefine;
57
+ if (isArray(name)) {
58
+ bezierDefine = name;
59
+ }
60
+ else {
61
+ const define = easingDefines[name];
62
+ if (!define) {
63
+ throw new Error(`${name} 缓冲函数未定义`);
64
+ }
65
+ bezierDefine = define;
66
+ }
67
+ return `cubic-bezier(${bezierDefine.join(',')})`;
68
+ }
37
69
 
38
- export { easingFunctional };
70
+ export { easingFunctional, easingStringify, getEasing, setEasing };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -26,9 +26,8 @@ export { UNIQUE_NUMBER_SAFE_LENGTH, uniqueNumber, uniqueString } from './unique.
26
26
  export { tooltipEvent } from './tooltip.js';
27
27
  export { flatTree, forEachDeep, formatTree, fuzzySearchTree, mapDeep, searchTreeById } from './tree.js';
28
28
  export { add, divide, multiply, strip, subtract } from './math.js';
29
- export { weAtob, weBtoa } from './we-decode.js';
30
- export { decodeFromBase64, encodeToBase64 } from './base64.js';
29
+ export { b64decode, b64encode, weAtob, weBtoa } from './base64.js';
31
30
  export { EMAIL_REGEX, HTTP_URL_REGEX, IPV4_REGEX, IPV6_REGEX, PHONE_REGEX, URL_REGEX, isDigit, isEmail, isFloat, isIdNo, isInteger, isIpV4, isIpV6, isNumerical, isPhone, isUrl } from './validator.js';
32
31
  export { escapeRegExp, executeInScope, parseVarFromString, replaceVarFromString, uniqueSymbol } from './variable.js';
33
32
  export { cloneDeep } from './cloneDeep.js';
34
- export { isEqual } from './isEqual.js';
33
+ export { easingFunctional, easingStringify, getEasing, setEasing } from './easing.js';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -53,9 +53,7 @@ function forEachDeep(tree, iterator, options = {
53
53
  else if (re === true) {
54
54
  continue;
55
55
  }
56
- // @ts-ignore
57
56
  if (item && Array.isArray(item[childField])) {
58
- // @ts-ignore
59
57
  walk(item[childField], item, level + 1);
60
58
  }
61
59
  }
@@ -64,8 +62,6 @@ function forEachDeep(tree, iterator, options = {
64
62
  // Process queue
65
63
  while (queue.length > 0 && !isBreak) {
66
64
  const current = queue.shift();
67
- // iterate(info);
68
- // @ts-ignore
69
65
  const { item, index, array, tree, parent, level } = current;
70
66
  const re = iterator(item, index, array, tree, parent, level);
71
67
  if (re === false) {
@@ -75,9 +71,7 @@ function forEachDeep(tree, iterator, options = {
75
71
  else if (re === true) {
76
72
  continue;
77
73
  }
78
- // @ts-ignore
79
74
  if (item && Array.isArray(item[childField])) {
80
- // @ts-ignore
81
75
  walk(item[childField], item, level + 1);
82
76
  }
83
77
  }
@@ -103,9 +97,7 @@ function forEachDeep(tree, iterator, options = {
103
97
  else if (re === true) {
104
98
  continue;
105
99
  }
106
- // @ts-ignore
107
100
  if (item && Array.isArray(item[childField])) {
108
- // @ts-ignore
109
101
  walk(item[childField], item, level + 1);
110
102
  }
111
103
  }
@@ -115,7 +107,6 @@ function forEachDeep(tree, iterator, options = {
115
107
  const current = queue.shift();
116
108
  if (!current)
117
109
  break;
118
- // @ts-ignore
119
110
  const { item, index, array, tree, parent, level } = current;
120
111
  const re = iterator(item, index, array, tree, parent, level);
121
112
  if (re === false) {
@@ -125,9 +116,7 @@ function forEachDeep(tree, iterator, options = {
125
116
  else if (re === true) {
126
117
  continue;
127
118
  }
128
- // @ts-ignore
129
119
  if (item && Array.isArray(item[childField])) {
130
- // @ts-ignore
131
120
  walk(item[childField], item, level + 1);
132
121
  }
133
122
  }
@@ -173,10 +162,8 @@ function mapDeep(tree, iterator, options = {
173
162
  continue;
174
163
  }
175
164
  newTree.push(objectOmit(re, [childField]));
176
- // @ts-ignore
177
165
  if (item && Array.isArray(item[childField])) {
178
166
  newTree[newTree.length - 1][childField] = [];
179
- // @ts-ignore
180
167
  walk(item[childField], item, newTree[newTree.length - 1][childField], level + 1);
181
168
  }
182
169
  else {
@@ -200,10 +187,8 @@ function mapDeep(tree, iterator, options = {
200
187
  continue;
201
188
  }
202
189
  newTree.push(objectOmit(re, [childField]));
203
- // @ts-ignore
204
190
  if (item && Array.isArray(item[childField])) {
205
191
  newTree[newTree.length - 1][childField] = [];
206
- // @ts-ignore
207
192
  walk(item[childField], item, newTree[newTree.length - 1][childField], level + 1);
208
193
  }
209
194
  else {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.1
2
+ * sculp-js v1.13.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -0,0 +1,50 @@
1
+ import { AnyArray } from './type';
2
+ /**
3
+ * 遍历数组,返回 false 中断遍历(支持continue和break操作)
4
+ *
5
+ * @param {ArrayLike<V>} array
6
+ * @param {(val: V, idx: number) => any} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
7
+ * @param {boolean} reverse 是否倒序
8
+ * @returns {*}
9
+ */
10
+ export declare function arrayEach<V>(array: ArrayLike<V>, iterator: (val: V, idx: number, arr: ArrayLike<V>) => boolean | void, reverse?: boolean): void;
11
+ /**
12
+ * 异步遍历数组,返回 false 中断遍历
13
+ * @param {ArrayLike<V>} array 数组
14
+ * @param {(val: V, idx: number) => Promise<any>} iterator 支持Promise类型的回调函数
15
+ * @param {boolean} reverse 是否反向遍历
16
+ * @example
17
+ * 使用范例如下:
18
+ * const start = async () => {
19
+ * await arrayEachAsync(result, async (item) => {
20
+ * await request(item);
21
+ * count++;
22
+ * })
23
+ * console.log('发送次数', count);
24
+ * }
25
+
26
+ * for await...of 使用范例如下
27
+ * const loadImages = async (images) => {
28
+ * for await (const item of images) {
29
+ * await request(item);
30
+ * count++;
31
+ * }
32
+ * }
33
+ */
34
+ export declare function arrayEachAsync<V>(array: ArrayLike<V>, iterator: (val: V, idx: number) => Promise<any> | any, reverse?: boolean): Promise<void>;
35
+ /**
36
+ * 插入到目标位置之前
37
+ * @param {AnyArray} array
38
+ * @param {number} start
39
+ * @param {number} to
40
+ * @returns {*}
41
+ */
42
+ export declare function arrayInsertBefore(array: AnyArray, start: number, to: number): void;
43
+ /**
44
+ * 数组删除指定项目
45
+ * @param {V[]} array
46
+ * @param {(val: V, idx: number) => boolean} expect
47
+ * @returns {V[]}
48
+ */
49
+ export declare function arrayRemove<V>(array: V[], expect: (val: V, idx: number) => boolean): V[];
50
+ //# sourceMappingURL=array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAqB,MAAM,QAAQ,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,OAAO,GAAG,IAAI,EACpE,OAAO,UAAQ,GACd,IAAI,CAgBN;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,EACrD,OAAO,UAAQ,GACd,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAOlF;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,GAAG,CAAC,EAAE,CAexF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 等待一段时间
3
+ * @param {number} timeout 等待时间,单位毫秒
4
+ * @returns {Promise<void>}
5
+ */
6
+ export declare function wait(timeout?: number): Promise<void>;
7
+ /**
8
+ * 异步遍历
9
+ * @ref https://github.com/Kevnz/async-tools/blob/master/src/mapper.js
10
+ * @ref https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/@@iterator
11
+ * @param {Array<T>} list
12
+ * @param {(val: T, idx: number, list: ArrayLike<T>) => Promise<R>} mapper
13
+ * @param {number} concurrency 并发数量,默认无限
14
+ * @returns {Promise<R[]>}
15
+ */
16
+ export declare function asyncMap<T, R>(list: Array<T>, mapper: (val: T, idx: number, list: Array<T>) => Promise<R>, concurrency?: number): Promise<R[]>;
17
+ /**
18
+ * Execute a promise safely
19
+ *
20
+ * @param { Promise } promise
21
+ * @param { Object= } errorExt - Additional Information you can pass safeAwait the err object
22
+ * @return { Promise }
23
+ * @example
24
+ * async function asyncTaskWithCb(cb) {
25
+ let err, user, savedTask, notification;
26
+
27
+ [ err, user ] = await safeAwait(UserModel.findById(1));
28
+ if(!user) return cb('No user found');
29
+
30
+ [ err, savedTask ] = await safeAwait(TaskModel({userId: user.id, name: 'Demo Task'}));
31
+ if(err) return cb('Error occurred while saving task')
32
+
33
+ cb(null, savedTask);
34
+ }
35
+ */
36
+ export declare function safeAwait<T, U = Error>(promise: Promise<T>, errorExt?: object): Promise<[U, undefined] | [null, T]>;
37
+ //# sourceMappingURL=async.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/async.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,OAAO,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAC3D,WAAW,SAAW,GACrB,OAAO,CAAC,CAAC,EAAE,CAAC,CAsCd;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAWnH"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 字符串编码成Base64, 平替浏览器的btoa, 不包含中文的处理 (适用于任何环境,包括小程序)
3
+ * @param {string} string
4
+ * @returns {string}
5
+ */
6
+ export declare function weBtoa(string: string): string;
7
+ /**
8
+ * Base64解码为原始字符串,平替浏览器的atob, 不包含中文的处理(适用于任何环境,包括小程序)
9
+ * @param {string} string
10
+ * @returns {string}
11
+ */
12
+ export declare function weAtob(string: string): string;
13
+ /**
14
+ * 将base64编码的字符串转换为原始字符串,包括对中文内容的处理(高性能,且支持Web、Node、小程序等任意平台)
15
+ * @param base64 base64编码的字符串
16
+ * @returns 原始字符串,包括中文内容
17
+ */
18
+ export declare function b64decode(base64: string): string;
19
+ /**
20
+ * 将原始字符串,包括中文内容,转换为base64编码的字符串(高性能,且支持Web、Node、小程序等任意平台)
21
+ * @param rawStr 原始字符串,包括中文内容
22
+ * @returns base64编码的字符串
23
+ */
24
+ export declare function b64encode(rawStr: string): string;
25
+ //# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAwB7C;AACD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAyB7C;AAcD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAYhD;AACD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAahD"}
@@ -0,0 +1,20 @@
1
+ import { AsyncCallback } from './type';
2
+ type CopyTextOptions = AsyncCallback & {
3
+ container?: HTMLElement;
4
+ };
5
+ /**
6
+ * 复制文本,优先使用navigator.clipboard,仅在安全上下文(HTTPS/localhost)下生效,若不支持则回退使用execCommand方式
7
+ * @param {string} text
8
+ * @param {CopyTextOptions} options 可选参数:成功回调successCallback、失败回调failCallback、容器元素container
9
+ * (默认document.body, 当不支持clipboard时必须传复制按钮元素,包裹模拟选择操作的临时元素,
10
+ * 解决脱离文档流的元素无法复制的问题,如Modal内复制操作)
11
+ */
12
+ export declare function copyText(text: string, options?: CopyTextOptions): void;
13
+ /**
14
+ * 使用execCommand方式复制文本
15
+ * @param text
16
+ * @param options
17
+ */
18
+ export declare function fallbackCopyText(text: string, options?: CopyTextOptions): void;
19
+ export {};
20
+ //# sourceMappingURL=clipboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/clipboard.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAyB,MAAM,QAAQ,CAAC;AAE9D,KAAK,eAAe,GAAG,aAAa,GAAG;IAAE,SAAS,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAEnE;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAiBtE;AACD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAyB9E"}