sculp-js 1.2.1 → 1.3.1
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/cjs/array.js +2 -2
- package/lib/cjs/async.js +2 -2
- package/lib/cjs/clipboard.js +2 -2
- package/lib/cjs/cookie.js +2 -2
- package/lib/cjs/date.js +2 -2
- package/lib/cjs/dom.js +2 -2
- package/lib/cjs/download.js +2 -2
- package/lib/cjs/easing.js +2 -2
- package/lib/cjs/file.js +126 -2
- package/lib/cjs/func.js +2 -2
- package/lib/cjs/index.js +9 -2
- package/lib/cjs/number.js +2 -2
- package/lib/cjs/object.js +2 -2
- package/lib/cjs/path.js +2 -2
- package/lib/cjs/qs.js +2 -2
- package/lib/cjs/random.js +2 -2
- package/lib/cjs/string.js +2 -2
- package/lib/cjs/tooltip.js +2 -2
- package/lib/cjs/tree.js +6 -8
- package/lib/cjs/type.js +6 -2
- package/lib/cjs/unique.js +2 -2
- package/lib/cjs/url.js +2 -2
- package/lib/cjs/watermark.js +2 -2
- package/lib/cjs/we-decode.js +107 -0
- package/lib/es/array.js +2 -2
- package/lib/es/async.js +2 -2
- package/lib/es/clipboard.js +2 -2
- package/lib/es/cookie.js +2 -2
- package/lib/es/date.js +2 -2
- package/lib/es/dom.js +2 -2
- package/lib/es/download.js +2 -2
- package/lib/es/easing.js +2 -2
- package/lib/es/file.js +125 -3
- package/lib/es/func.js +2 -2
- package/lib/es/index.js +5 -4
- package/lib/es/number.js +2 -2
- package/lib/es/object.js +2 -2
- package/lib/es/path.js +2 -2
- package/lib/es/qs.js +2 -2
- package/lib/es/random.js +2 -2
- package/lib/es/string.js +2 -2
- package/lib/es/tooltip.js +2 -2
- package/lib/es/tree.js +6 -8
- package/lib/es/type.js +6 -3
- package/lib/es/unique.js +2 -2
- package/lib/es/url.js +2 -2
- package/lib/es/watermark.js +2 -2
- package/lib/es/we-decode.js +103 -0
- package/lib/index.d.ts +35 -1
- package/lib/umd/index.js +231 -8
- package/package.json +3 -1
- package/lib/tsdoc-metadata.json +0 -11
package/lib/es/file.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.3.0
|
|
3
|
+
* (c) 2023-2024 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { weAtob } from './we-decode.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 判断是否支持canvas
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
function supportCanvas() {
|
|
14
|
+
return !!document.createElement('canvas').getContext;
|
|
15
|
+
}
|
|
7
16
|
/**
|
|
8
17
|
* 选择本地文件
|
|
9
18
|
* @param {string} accept 上传的文件类型,用于过滤
|
|
@@ -25,5 +34,118 @@ function chooseLocalFile(accept, changeCb) {
|
|
|
25
34
|
};
|
|
26
35
|
return inputObj;
|
|
27
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Web端:等比例压缩图片批量处理 (size小于200KB,不压缩)
|
|
39
|
+
* @param {File | FileList} file 文件
|
|
40
|
+
* @param {ICompressOptions} options
|
|
41
|
+
* @returns {Promise<object> | undefined}
|
|
42
|
+
*/
|
|
43
|
+
function compressImg(file, options) {
|
|
44
|
+
console.assert(file instanceof File || file instanceof FileList, `${file} 必须是File或FileList类型`);
|
|
45
|
+
console.assert(supportCanvas(), `当前环境不支持 Canvas`);
|
|
46
|
+
let targetQuality = 0.52;
|
|
47
|
+
if (file instanceof File) {
|
|
48
|
+
const sizeKB = +parseInt((file.size / 1024).toFixed(2));
|
|
49
|
+
if (sizeKB < 1 * 1024) {
|
|
50
|
+
targetQuality = 0.85;
|
|
51
|
+
}
|
|
52
|
+
else if (sizeKB >= 1 * 1024 && sizeKB < 5 * 1024) {
|
|
53
|
+
targetQuality = 0.62;
|
|
54
|
+
}
|
|
55
|
+
else if (sizeKB >= 5 * 1024) {
|
|
56
|
+
targetQuality = 0.52;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (options.quality) {
|
|
60
|
+
targetQuality = options.quality;
|
|
61
|
+
}
|
|
62
|
+
if (file instanceof FileList) {
|
|
63
|
+
return Promise.all(Array.from(file).map(el => compressImg(el, { mime: options.mime, quality: targetQuality }))); // 如果是 file 数组返回 Promise 数组
|
|
64
|
+
}
|
|
65
|
+
else if (file instanceof File) {
|
|
66
|
+
return new Promise(resolve => {
|
|
67
|
+
const sizeKB = +parseInt((file.size / 1024).toFixed(2));
|
|
68
|
+
if (+(file.size / 1024).toFixed(2) < 200) {
|
|
69
|
+
resolve({
|
|
70
|
+
file: file
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const reader = new FileReader(); // 创建 FileReader
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
reader.onload = ({ target: { result: src } }) => {
|
|
77
|
+
const image = new Image(); // 创建 img 元素
|
|
78
|
+
image.onload = () => {
|
|
79
|
+
const canvas = document.createElement('canvas'); // 创建 canvas 元素
|
|
80
|
+
const context = canvas.getContext('2d');
|
|
81
|
+
let targetWidth = image.width;
|
|
82
|
+
let targetHeight = image.height;
|
|
83
|
+
const originWidth = image.width;
|
|
84
|
+
const originHeight = image.height;
|
|
85
|
+
if (1 * 1024 <= sizeKB && sizeKB < 10 * 1024) {
|
|
86
|
+
const maxWidth = 1600, maxHeight = 1600;
|
|
87
|
+
targetWidth = originWidth;
|
|
88
|
+
targetHeight = originHeight;
|
|
89
|
+
// 图片尺寸超过的限制
|
|
90
|
+
if (originWidth > maxWidth || originHeight > maxHeight) {
|
|
91
|
+
if (originWidth / originHeight > maxWidth / maxHeight) {
|
|
92
|
+
// 更宽,按照宽度限定尺寸
|
|
93
|
+
targetWidth = maxWidth;
|
|
94
|
+
targetHeight = Math.round(maxWidth * (originHeight / originWidth));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
targetHeight = maxHeight;
|
|
98
|
+
targetWidth = Math.round(maxHeight * (originWidth / originHeight));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (10 * 1024 <= sizeKB && sizeKB <= 20 * 1024) {
|
|
103
|
+
const maxWidth = 1400, maxHeight = 1400;
|
|
104
|
+
targetWidth = originWidth;
|
|
105
|
+
targetHeight = originHeight;
|
|
106
|
+
// 图片尺寸超过的限制
|
|
107
|
+
if (originWidth > maxWidth || originHeight > maxHeight) {
|
|
108
|
+
if (originWidth / originHeight > maxWidth / maxHeight) {
|
|
109
|
+
// 更宽,按照宽度限定尺寸
|
|
110
|
+
targetWidth = maxWidth;
|
|
111
|
+
targetHeight = Math.round(maxWidth * (originHeight / originWidth));
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
targetHeight = maxHeight;
|
|
115
|
+
targetWidth = Math.round(maxHeight * (originWidth / originHeight));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
canvas.width = targetWidth;
|
|
120
|
+
canvas.height = targetHeight;
|
|
121
|
+
context.clearRect(0, 0, targetWidth, targetHeight);
|
|
122
|
+
context.drawImage(image, 0, 0, targetWidth, targetHeight); // 绘制 canvas
|
|
123
|
+
const canvasURL = canvas.toDataURL(options.mime, targetQuality);
|
|
124
|
+
const buffer = weAtob(canvasURL.split(',')[1]);
|
|
125
|
+
let length = buffer.length;
|
|
126
|
+
const bufferArray = new Uint8Array(new ArrayBuffer(length));
|
|
127
|
+
while (length--) {
|
|
128
|
+
bufferArray[length] = buffer.charCodeAt(length);
|
|
129
|
+
}
|
|
130
|
+
const miniFile = new File([bufferArray], file.name, {
|
|
131
|
+
type: options.mime
|
|
132
|
+
});
|
|
133
|
+
resolve({
|
|
134
|
+
file: miniFile,
|
|
135
|
+
bufferArray,
|
|
136
|
+
origin: file,
|
|
137
|
+
beforeSrc: src,
|
|
138
|
+
afterSrc: canvasURL,
|
|
139
|
+
beforeKB: Number((file.size / 1024).toFixed(2)),
|
|
140
|
+
afterKB: Number((miniFile.size / 1024).toFixed(2))
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
image.src = src;
|
|
144
|
+
};
|
|
145
|
+
reader.readAsDataURL(file);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
28
150
|
|
|
29
|
-
export { chooseLocalFile };
|
|
151
|
+
export { chooseLocalFile, compressImg, supportCanvas };
|
package/lib/es/func.js
CHANGED
package/lib/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.3.0
|
|
3
|
+
* (c) 2023-2024 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -14,10 +14,10 @@ export { cloneDeep, isPlainObject, objectAssign, objectEach, objectEachAsync, ob
|
|
|
14
14
|
export { pathJoin, pathNormalize } from './path.js';
|
|
15
15
|
export { qsParse, qsStringify } from './qs.js';
|
|
16
16
|
export { STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_UPPERCASE_ALPHA, getStrWidthPx, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase } from './string.js';
|
|
17
|
-
export { isArray, isBigInt, isBoolean, isDate, isError, isFunction, isNaN, isNull, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, typeIs } from './type.js';
|
|
17
|
+
export { isArray, isBigInt, isBoolean, isDate, isError, isFunction, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, typeIs } from './type.js';
|
|
18
18
|
export { urlDelParams, urlParse, urlSetParams, urlStringify } from './url.js';
|
|
19
19
|
export { asyncMap, wait } from './async.js';
|
|
20
|
-
export { chooseLocalFile } from './file.js';
|
|
20
|
+
export { chooseLocalFile, compressImg, supportCanvas } from './file.js';
|
|
21
21
|
export { genCanvasWM } from './watermark.js';
|
|
22
22
|
export { debounce, getGlobal, once, setGlobal, throttle } from './func.js';
|
|
23
23
|
export { STRING_POOL, randomNumber, randomString, randomUuid } from './random.js';
|
|
@@ -25,3 +25,4 @@ export { HEX_POOL, formatNumber, numberAbbr, numberToHex } from './number.js';
|
|
|
25
25
|
export { UNIQUE_NUMBER_SAFE_LENGTH, uniqueNumber, uniqueString } from './unique.js';
|
|
26
26
|
export { tooltipEvent } from './tooltip.js';
|
|
27
27
|
export { buildTree, forEachDeep, forEachMap, formatTree, searchTreeById } from './tree.js';
|
|
28
|
+
export { weAppJwtDecode, weAtob, weBtoa } from './we-decode.js';
|
package/lib/es/number.js
CHANGED
package/lib/es/object.js
CHANGED
package/lib/es/path.js
CHANGED
package/lib/es/qs.js
CHANGED
package/lib/es/random.js
CHANGED
package/lib/es/string.js
CHANGED
package/lib/es/tooltip.js
CHANGED
package/lib/es/tree.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.3.0
|
|
3
|
+
* (c) 2023-2024 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -14,8 +14,8 @@ const defaultFieldOptions = { keyField: 'key', childField: 'children', pidField:
|
|
|
14
14
|
* @returns {*}
|
|
15
15
|
*/
|
|
16
16
|
function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
|
|
17
|
-
let
|
|
18
|
-
const walk = (arr, parent) => {
|
|
17
|
+
let isBreak = false;
|
|
18
|
+
const walk = (arr, parent, level = 0) => {
|
|
19
19
|
if (isReverse) {
|
|
20
20
|
for (let i = arr.length - 1; i >= 0; i--) {
|
|
21
21
|
if (isBreak) {
|
|
@@ -31,9 +31,8 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
|
|
|
31
31
|
}
|
|
32
32
|
// @ts-ignore
|
|
33
33
|
if (arr[i] && Array.isArray(arr[i][children])) {
|
|
34
|
-
++level;
|
|
35
34
|
// @ts-ignore
|
|
36
|
-
walk(arr[i][children], arr[i]);
|
|
35
|
+
walk(arr[i][children], arr[i], level + 1);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
}
|
|
@@ -52,9 +51,8 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
|
|
|
52
51
|
}
|
|
53
52
|
// @ts-ignore
|
|
54
53
|
if (arr[i] && Array.isArray(arr[i][children])) {
|
|
55
|
-
++level;
|
|
56
54
|
// @ts-ignore
|
|
57
|
-
walk(arr[i][children], arr[i]);
|
|
55
|
+
walk(arr[i][children], arr[i], level + 1);
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
}
|
package/lib/es/type.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
3
|
-
* (c) 2023-
|
|
2
|
+
* sculp-js v1.3.0
|
|
3
|
+
* (c) 2023-2024 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -19,6 +19,9 @@ const isNumber = (any) => typeof any === 'number' && !Number.isNaN(any);
|
|
|
19
19
|
const isUndefined = (any) => typeof any === 'undefined';
|
|
20
20
|
const isNull = (any) => any === null;
|
|
21
21
|
const isPrimitive = (any) => any === null || typeof any !== 'object';
|
|
22
|
+
function isNullOrUnDef(val) {
|
|
23
|
+
return isUndefined(val) || isNull(val);
|
|
24
|
+
}
|
|
22
25
|
// 复合数据类型判断
|
|
23
26
|
const isObject = (any) => typeIs(any) === 'Object';
|
|
24
27
|
const isArray = (any) => Array.isArray(any);
|
|
@@ -34,4 +37,4 @@ const isDate = (any) => typeIs(any) === 'Date';
|
|
|
34
37
|
const isError = (any) => typeIs(any) === 'Error';
|
|
35
38
|
const isRegExp = (any) => typeIs(any) === 'RegExp';
|
|
36
39
|
|
|
37
|
-
export { typeIs as default, isArray, isBigInt, isBoolean, isDate, isError, isFunction, isNaN, isNull, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, typeIs };
|
|
40
|
+
export { typeIs as default, isArray, isBigInt, isBoolean, isDate, isError, isFunction, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, typeIs };
|
package/lib/es/unique.js
CHANGED
package/lib/es/url.js
CHANGED
package/lib/es/watermark.js
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* sculp-js v1.3.0
|
|
3
|
+
* (c) 2023-2024 chandq
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
8
|
+
// eslint-disable-next-line
|
|
9
|
+
const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
10
|
+
/**
|
|
11
|
+
* 字符串编码成Base64 (适用于任何环境,包括小程序)
|
|
12
|
+
* @param {string} string
|
|
13
|
+
* @return {string}
|
|
14
|
+
*/
|
|
15
|
+
function weBtoa(string) {
|
|
16
|
+
// 同window.btoa: 字符串编码成Base64
|
|
17
|
+
string = String(string);
|
|
18
|
+
let bitmap, a, b, c, result = '', i = 0;
|
|
19
|
+
const rest = string.length % 3;
|
|
20
|
+
for (; i < string.length;) {
|
|
21
|
+
if ((a = string.charCodeAt(i++)) > 255 || (b = string.charCodeAt(i++)) > 255 || (c = string.charCodeAt(i++)) > 255)
|
|
22
|
+
throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");
|
|
23
|
+
bitmap = (a << 16) | (b << 8) | c;
|
|
24
|
+
result +=
|
|
25
|
+
b64.charAt((bitmap >> 18) & 63) +
|
|
26
|
+
b64.charAt((bitmap >> 12) & 63) +
|
|
27
|
+
b64.charAt((bitmap >> 6) & 63) +
|
|
28
|
+
b64.charAt(bitmap & 63);
|
|
29
|
+
}
|
|
30
|
+
return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Base64解码为原始字符串(适用于任何环境,包括小程序)
|
|
34
|
+
* @param {string} string
|
|
35
|
+
* @return {string}
|
|
36
|
+
*/
|
|
37
|
+
function weAtob(string) {
|
|
38
|
+
// 同window.atob: Base64解码为原始字符串
|
|
39
|
+
string = String(string).replace(/[\t\n\f\r ]+/g, '');
|
|
40
|
+
if (!b64re.test(string))
|
|
41
|
+
throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
|
42
|
+
string += '=='.slice(2 - (string.length & 3));
|
|
43
|
+
let bitmap, result = '', r1, r2, i = 0;
|
|
44
|
+
for (; i < string.length;) {
|
|
45
|
+
bitmap =
|
|
46
|
+
(b64.indexOf(string.charAt(i++)) << 18) |
|
|
47
|
+
(b64.indexOf(string.charAt(i++)) << 12) |
|
|
48
|
+
((r1 = b64.indexOf(string.charAt(i++))) << 6) |
|
|
49
|
+
(r2 = b64.indexOf(string.charAt(i++)));
|
|
50
|
+
result +=
|
|
51
|
+
r1 === 64
|
|
52
|
+
? String.fromCharCode((bitmap >> 16) & 255)
|
|
53
|
+
: r2 === 64
|
|
54
|
+
? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
|
|
55
|
+
: String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
function b64DecodeUnicode(str) {
|
|
60
|
+
return decodeURIComponent(exports.weAtob(str).replace(/(.)/g, function (p) {
|
|
61
|
+
let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
62
|
+
if (code.length < 2) {
|
|
63
|
+
code = '0' + code;
|
|
64
|
+
}
|
|
65
|
+
return '%' + code;
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
function base64_url_decode(str) {
|
|
69
|
+
let output = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
70
|
+
switch (output.length % 4) {
|
|
71
|
+
case 0:
|
|
72
|
+
break;
|
|
73
|
+
case 2:
|
|
74
|
+
output += '==';
|
|
75
|
+
break;
|
|
76
|
+
case 3:
|
|
77
|
+
output += '=';
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
throw new Error('Illegal base64url string!');
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
return b64DecodeUnicode(output);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
return exports.weAtob(output);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function weAppJwtDecode(token, options) {
|
|
90
|
+
if (typeof token !== 'string') {
|
|
91
|
+
throw new Error('Invalid token specified');
|
|
92
|
+
}
|
|
93
|
+
options = options || {};
|
|
94
|
+
const pos = options.header === true ? 0 : 1;
|
|
95
|
+
try {
|
|
96
|
+
return JSON.parse(base64_url_decode(token.split('.')[pos]));
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
throw new Error('Invalid token specified: ' + e.message);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { weAppJwtDecode, weAtob, weBtoa };
|
package/lib/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ declare const isNumber: (any: unknown) => any is number;
|
|
|
23
23
|
declare const isUndefined: (any: unknown) => any is undefined;
|
|
24
24
|
declare const isNull: (any: unknown) => any is null;
|
|
25
25
|
declare const isPrimitive: (any: unknown) => boolean;
|
|
26
|
+
declare function isNullOrUnDef(val: unknown): val is null | undefined;
|
|
26
27
|
declare const isObject: (any: unknown) => any is Record<string, unknown>;
|
|
27
28
|
declare const isArray: (any: unknown) => any is unknown[];
|
|
28
29
|
/**
|
|
@@ -504,6 +505,11 @@ declare function wait(timeout?: number): Promise<void>;
|
|
|
504
505
|
*/
|
|
505
506
|
declare function asyncMap<T, R>(list: Array<T>, mapper: (val: T, idx: number, list: Array<T>) => Promise<R>, concurrency?: number): Promise<R[]>;
|
|
506
507
|
|
|
508
|
+
/**
|
|
509
|
+
* 判断是否支持canvas
|
|
510
|
+
* @returns {boolean}
|
|
511
|
+
*/
|
|
512
|
+
declare function supportCanvas(): boolean;
|
|
507
513
|
/**
|
|
508
514
|
* 选择本地文件
|
|
509
515
|
* @param {string} accept 上传的文件类型,用于过滤
|
|
@@ -511,6 +517,20 @@ declare function asyncMap<T, R>(list: Array<T>, mapper: (val: T, idx: number, li
|
|
|
511
517
|
* @returns {HTMLInputElement}
|
|
512
518
|
*/
|
|
513
519
|
declare function chooseLocalFile(accept: string, changeCb: (FileList: any) => any): HTMLInputElement;
|
|
520
|
+
type ImageType = 'image/jpeg' | 'image/png' | 'image/webp';
|
|
521
|
+
interface ICompressOptions {
|
|
522
|
+
/** 压缩质量 0 ~ 1 之间*/
|
|
523
|
+
quality?: number;
|
|
524
|
+
/** 图片类型 */
|
|
525
|
+
mime?: ImageType;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Web端:等比例压缩图片批量处理 (size小于200KB,不压缩)
|
|
529
|
+
* @param {File | FileList} file 文件
|
|
530
|
+
* @param {ICompressOptions} options
|
|
531
|
+
* @returns {Promise<object> | undefined}
|
|
532
|
+
*/
|
|
533
|
+
declare function compressImg(file: File | FileList, options: ICompressOptions): Promise<object> | undefined;
|
|
514
534
|
|
|
515
535
|
interface ICanvasWM {
|
|
516
536
|
container: HTMLElement;
|
|
@@ -767,4 +787,18 @@ declare function buildTree<ID extends string, PID extends string, T extends {
|
|
|
767
787
|
*/
|
|
768
788
|
declare function formatTree(list: any[], options?: IFieldOptions): any[];
|
|
769
789
|
|
|
770
|
-
|
|
790
|
+
/**
|
|
791
|
+
* 字符串编码成Base64 (适用于任何环境,包括小程序)
|
|
792
|
+
* @param {string} string
|
|
793
|
+
* @return {string}
|
|
794
|
+
*/
|
|
795
|
+
declare function weBtoa(string: string): string;
|
|
796
|
+
/**
|
|
797
|
+
* Base64解码为原始字符串(适用于任何环境,包括小程序)
|
|
798
|
+
* @param {string} string
|
|
799
|
+
* @return {string}
|
|
800
|
+
*/
|
|
801
|
+
declare function weAtob(string: string): string;
|
|
802
|
+
declare function weAppJwtDecode(token: any, options: any): any;
|
|
803
|
+
|
|
804
|
+
export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, type FileType, HEX_POOL, type ICanvasWM, type ICompressOptions, type IFieldOptions, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, type UniqueString, type Url, type WithChildren, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, dateParse, dateToEnd, dateToStart, debounce, downloadBlob, downloadData, downloadHref, downloadURL, forEachDeep, forEachMap, formatDate, formatNumber, formatTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDomReady, isError, isFunction, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isValidDate, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAppJwtDecode, weAtob, weBtoa };
|