@gx-design-vue/pro-utils 0.2.0-alpha.2 → 0.2.0-alpha.4
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/array/index.d.ts +2 -2
- package/dist/array/index.js +2 -3
- package/dist/array/slice.js +1 -4
- package/dist/array/sort.js +5 -8
- package/dist/array/tree.d.ts +6 -6
- package/dist/array/tree.js +15 -15
- package/dist/array/unique.d.ts +24 -2
- package/dist/array/unique.js +34 -3
- package/dist/class/index.js +1 -2
- package/dist/class/prefix.d.ts +2 -2
- package/dist/class/prefix.js +3 -4
- package/dist/clone/cloneDeep.js +1 -3
- package/dist/clone/cloneDeepWith.js +4 -7
- package/dist/clone/getTag.js +1 -2
- package/dist/clone/index.js +1 -2
- package/dist/clone/tags.js +1 -2
- package/dist/dom/event.js +1 -2
- package/dist/dom/index.d.ts +3 -2
- package/dist/dom/index.js +3 -3
- package/dist/dom/measure.js +9 -6
- package/dist/{file → dom}/media.d.ts +1 -1
- package/dist/{file → dom}/media.js +37 -20
- package/dist/dom/raf.d.ts +1 -1
- package/dist/dom/raf.js +1 -2
- package/dist/dom/scroll.js +5 -7
- package/dist/{base64/index.d.ts → encoding/base64.d.ts} +2 -2
- package/dist/{base64/index.js → encoding/base64.js} +29 -33
- package/dist/encoding/index.d.ts +2 -0
- package/dist/encoding/index.js +2 -0
- package/dist/file/config.js +6 -2
- package/dist/file/convert.d.ts +6 -2
- package/dist/file/convert.js +7 -3
- package/dist/file/index.d.ts +2 -3
- package/dist/file/index.js +2 -4
- package/dist/file/type.js +7 -10
- package/dist/function/copy.d.ts +7 -0
- package/dist/function/copy.js +8 -2
- package/dist/function/getValue.d.ts +2 -2
- package/dist/function/getValue.js +4 -5
- package/dist/function/index.js +1 -2
- package/dist/function/object.js +1 -2
- package/dist/function/run.js +1 -2
- package/dist/index.d.ts +11 -17
- package/dist/index.js +13 -22
- package/dist/is/base64.d.ts +7 -4
- package/dist/is/base64.js +9 -6
- package/dist/is/browser.js +2 -3
- package/dist/is/deepEqual.d.ts +10 -4
- package/dist/is/deepEqual.js +14 -9
- package/dist/is/device.js +4 -2
- package/dist/is/equal.js +1 -2
- package/dist/is/img.js +1 -2
- package/dist/is/index.d.ts +3 -3
- package/dist/is/index.js +3 -4
- package/dist/is/nil.js +1 -2
- package/dist/is/plainObject.js +2 -4
- package/dist/is/primitive.js +1 -2
- package/dist/is/server.js +1 -2
- package/dist/is/type.js +1 -2
- package/dist/is/typedArray.js +1 -2
- package/dist/is/unsafeProperty.js +1 -2
- package/dist/is/url.js +2 -4
- package/dist/is/valid.js +1 -2
- package/dist/merge/{useDeepMege.d.ts → deepCloneMerge.d.ts} +3 -1
- package/dist/merge/{useDeepMege.js → deepCloneMerge.js} +6 -6
- package/dist/merge/index.d.ts +1 -1
- package/dist/merge/index.js +26 -10
- package/dist/merge/mergeWith.js +1 -4
- package/dist/number/chinese.js +1 -4
- package/dist/number/format.js +7 -6
- package/dist/number/index.js +1 -2
- package/dist/object/classNames.js +1 -5
- package/dist/object/index.js +2 -3
- package/dist/object/omitBoolean.js +1 -2
- package/dist/object/omitUndefined.js +1 -2
- package/dist/object/omitUndefinedAndEmptyArr.js +1 -2
- package/dist/pro-utils.esm.js +625 -402
- package/dist/pro-utils.js +2 -1
- package/dist/{vue/slots.d.ts → slots/index.d.ts} +3 -3
- package/dist/{vue/slots.js → slots/index.js} +34 -20
- package/dist/string/duration.js +1 -2
- package/dist/string/empty.js +1 -2
- package/dist/string/index.d.ts +2 -2
- package/dist/string/index.js +2 -3
- package/dist/string/nanoid.js +1 -2
- package/dist/string/uuid.d.ts +10 -8
- package/dist/string/uuid.js +41 -30
- package/dist/table/column.js +6 -10
- package/dist/table/index.js +1 -2
- package/dist/table/page.js +1 -4
- package/dist/typing.d.ts +2 -2
- package/dist/typing.js +1 -1
- package/package.json +2 -1
- package/dist/clone/symbols.d.ts +0 -10
- package/dist/clone/symbols.js +0 -13
- package/dist/vue/index.d.ts +0 -2
- package/dist/vue/index.js +0 -3
package/dist/array/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { arraySlice } from "./slice.js";
|
|
2
2
|
import { compareArray, compareArraySort, compareArrayTimeSort, compareTime } from "./sort.js";
|
|
3
3
|
import { filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData } from "./tree.js";
|
|
4
|
-
import { arrayUnique } from "./unique.js";
|
|
5
|
-
export { arraySlice, arrayUnique, compareArray, compareArraySort, compareArrayTimeSort, compareTime, filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData };
|
|
4
|
+
import { arrayUnique, arrayUniqueBy } from "./unique.js";
|
|
5
|
+
export { arraySlice, arrayUnique, arrayUniqueBy, compareArray, compareArraySort, compareArrayTimeSort, compareTime, filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData };
|
package/dist/array/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { arraySlice } from "./slice.js";
|
|
2
2
|
import { compareArray, compareArraySort, compareArrayTimeSort, compareTime } from "./sort.js";
|
|
3
3
|
import { filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData } from "./tree.js";
|
|
4
|
-
import { arrayUnique } from "./unique.js";
|
|
5
|
-
|
|
6
|
-
export { arraySlice, arrayUnique, compareArray, compareArraySort, compareArrayTimeSort, compareTime, filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData };
|
|
4
|
+
import { arrayUnique, arrayUniqueBy } from "./unique.js";
|
|
5
|
+
export { arraySlice, arrayUnique, arrayUniqueBy, compareArray, compareArraySort, compareArrayTimeSort, compareTime, filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData };
|
package/dist/array/slice.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { isArray, isNumber } from "../is/type.js";
|
|
2
|
-
import "../is/index.js";
|
|
3
|
-
|
|
4
2
|
//#region src/array/slice.ts
|
|
5
3
|
/**
|
|
6
4
|
* 数组切片,根据范围筛选数组元素
|
|
@@ -24,6 +22,5 @@ function arraySlice(data, range) {
|
|
|
24
22
|
return true;
|
|
25
23
|
});
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
//#endregion
|
|
29
|
-
export { arraySlice };
|
|
26
|
+
export { arraySlice };
|
package/dist/array/sort.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { isNumber } from "../is/type.js";
|
|
2
|
-
import "../is/index.js";
|
|
3
|
-
|
|
4
2
|
//#region src/array/sort.ts
|
|
5
3
|
/**
|
|
6
4
|
* 比较数组元素(用于排序)
|
|
@@ -16,8 +14,8 @@ function compareArray(obj1, obj2, key, sort = 0) {
|
|
|
16
14
|
const prev = obj1[key];
|
|
17
15
|
const next = obj2[key];
|
|
18
16
|
let result = 0;
|
|
19
|
-
if (prev < next) result = newType === 0 ? -1 :
|
|
20
|
-
else if (prev > next) result = newType === 0 ?
|
|
17
|
+
if (prev < next) result = newType === 0 ? -1 : 1;
|
|
18
|
+
else if (prev > next) result = newType === 0 ? 1 : -1;
|
|
21
19
|
return result;
|
|
22
20
|
}
|
|
23
21
|
/**
|
|
@@ -34,8 +32,8 @@ function compareTime(obj1, obj2, key, sort = 0) {
|
|
|
34
32
|
const prev = new Date(obj1[key]);
|
|
35
33
|
const next = new Date(obj2[key]);
|
|
36
34
|
let result = 0;
|
|
37
|
-
if (prev < next) result = newType === 0 ? -1 :
|
|
38
|
-
else if (prev > next) result = newType === 0 ?
|
|
35
|
+
if (prev < next) result = newType === 0 ? -1 : 1;
|
|
36
|
+
else if (prev > next) result = newType === 0 ? 1 : -1;
|
|
39
37
|
return result;
|
|
40
38
|
}
|
|
41
39
|
/**
|
|
@@ -60,6 +58,5 @@ function compareArraySort(dataSource, key, sort = 0) {
|
|
|
60
58
|
function compareArrayTimeSort(dataSource, key, sort = 0) {
|
|
61
59
|
return dataSource.sort((a, b) => compareTime(a, b, key, sort));
|
|
62
60
|
}
|
|
63
|
-
|
|
64
61
|
//#endregion
|
|
65
|
-
export { compareArray, compareArraySort, compareArrayTimeSort, compareTime };
|
|
62
|
+
export { compareArray, compareArraySort, compareArrayTimeSort, compareTime };
|
package/dist/array/tree.d.ts
CHANGED
|
@@ -13,10 +13,10 @@ declare function getMaxFloor<T>(data: T[], childrenKey?: keyof T): number;
|
|
|
13
13
|
* 树形转平级
|
|
14
14
|
*
|
|
15
15
|
* @param data - 树形数据
|
|
16
|
-
* @param
|
|
16
|
+
* @param field - 子节点键名
|
|
17
17
|
* @returns 平级数组
|
|
18
18
|
*/
|
|
19
|
-
declare function getLevelData<T extends RecordType = RecordType>(data: T[],
|
|
19
|
+
declare function getLevelData<T extends RecordType = RecordType>(data: T[], field?: keyof T): T[];
|
|
20
20
|
/**
|
|
21
21
|
* 构造树型结构数据
|
|
22
22
|
*
|
|
@@ -48,8 +48,8 @@ declare function filterTree<T = any>(tree: T[], predicate: (val: T) => boolean):
|
|
|
48
48
|
* @returns 祖先节点值数组
|
|
49
49
|
*/
|
|
50
50
|
declare function findValueAndAncestors<T = any>(tree: T[], targetValue: any, fieldNames?: {
|
|
51
|
-
value:
|
|
52
|
-
children:
|
|
51
|
+
value: keyof T;
|
|
52
|
+
children: keyof T;
|
|
53
53
|
}): any[];
|
|
54
54
|
/**
|
|
55
55
|
* 树形数组递归查找指定对象
|
|
@@ -67,9 +67,9 @@ declare function findSourceByTree<T>(tree: T[], value: any, options?: {
|
|
|
67
67
|
* 获取数组最后一个元素
|
|
68
68
|
*
|
|
69
69
|
* @param data - 数组
|
|
70
|
-
* @returns
|
|
70
|
+
* @returns 最后一个元素,空数组或非数组返回 undefined
|
|
71
71
|
*/
|
|
72
|
-
declare function getArrayLast<T = any>(data: any): T;
|
|
72
|
+
declare function getArrayLast<T = any>(data: any): T | undefined;
|
|
73
73
|
/**
|
|
74
74
|
* 数组(树形)添加序号
|
|
75
75
|
*
|
package/dist/array/tree.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { isArray, isObject } from "../is/type.js";
|
|
2
|
-
import "../is/index.js";
|
|
3
|
-
|
|
4
2
|
//#region src/array/tree.ts
|
|
5
3
|
/**
|
|
6
4
|
* 获取树形结构最深的层级数
|
|
@@ -21,14 +19,14 @@ function getMaxFloor(data, childrenKey) {
|
|
|
21
19
|
* 树形转平级
|
|
22
20
|
*
|
|
23
21
|
* @param data - 树形数据
|
|
24
|
-
* @param
|
|
22
|
+
* @param field - 子节点键名
|
|
25
23
|
* @returns 平级数组
|
|
26
24
|
*/
|
|
27
|
-
function getLevelData(data,
|
|
25
|
+
function getLevelData(data, field = "children") {
|
|
28
26
|
let newData = [];
|
|
29
27
|
data.forEach((item) => {
|
|
30
28
|
newData.push(item);
|
|
31
|
-
if (isArray(item[
|
|
29
|
+
if (isArray(item[field]) && item[field].length > 0) newData = newData.concat(getLevelData(item[field], field));
|
|
32
30
|
});
|
|
33
31
|
return newData;
|
|
34
32
|
}
|
|
@@ -44,15 +42,19 @@ function treeData(source, options) {
|
|
|
44
42
|
const { id = "id", parentId = "parentId", children = "children", emptyChildren = true } = options || {};
|
|
45
43
|
const rootId = options?.rootId ?? 0;
|
|
46
44
|
const cloneData = structuredClone(source);
|
|
47
|
-
|
|
45
|
+
const childrenMap = /* @__PURE__ */ new Map();
|
|
46
|
+
cloneData.forEach((item) => {
|
|
48
47
|
if (!emptyChildren && item[children] && item[children]?.length === 0) delete item[children];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
const pid = item[parentId];
|
|
49
|
+
if (!childrenMap.has(pid)) childrenMap.set(pid, []);
|
|
50
|
+
childrenMap.get(pid).push(item);
|
|
51
|
+
});
|
|
52
|
+
cloneData.forEach((father) => {
|
|
53
|
+
const branchArr = childrenMap.get(father[id]);
|
|
54
|
+
if (branchArr && branchArr.length > 0) father[children] = branchArr;
|
|
53
55
|
else if (emptyChildren) father[children] = [];
|
|
54
|
-
return rootId === false ? true : father[parentId] === rootId;
|
|
55
56
|
});
|
|
57
|
+
return rootId === false ? cloneData : cloneData.filter((father) => father[parentId] === rootId);
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
60
|
* 树形数组按照条件过滤
|
|
@@ -120,11 +122,10 @@ function findSourceByTree(tree, value, options) {
|
|
|
120
122
|
* 获取数组最后一个元素
|
|
121
123
|
*
|
|
122
124
|
* @param data - 数组
|
|
123
|
-
* @returns
|
|
125
|
+
* @returns 最后一个元素,空数组或非数组返回 undefined
|
|
124
126
|
*/
|
|
125
127
|
function getArrayLast(data) {
|
|
126
128
|
if (data && isArray(data)) return data[data.length - 1];
|
|
127
|
-
return null;
|
|
128
129
|
}
|
|
129
130
|
/**
|
|
130
131
|
* 数组(树形)添加序号
|
|
@@ -152,6 +153,5 @@ function getSortIndex(data = [], pageConfig, childrenKey = "children") {
|
|
|
152
153
|
return item;
|
|
153
154
|
});
|
|
154
155
|
}
|
|
155
|
-
|
|
156
156
|
//#endregion
|
|
157
|
-
export { filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData };
|
|
157
|
+
export { filterTree, findSourceByTree, findValueAndAncestors, getArrayLast, getLevelData, getMaxFloor, getSortIndex, treeData };
|
package/dist/array/unique.d.ts
CHANGED
|
@@ -2,11 +2,33 @@ import { RecordType } from "../typing.js";
|
|
|
2
2
|
|
|
3
3
|
//#region src/array/unique.d.ts
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 数组去重(基于 Set,仅对基本类型或引用相同的元素有效)
|
|
6
|
+
*
|
|
7
|
+
* 由于使用 `Set` 判等,对象数组会因引用不同而无法去重,
|
|
8
|
+
* 对象场景请使用 {@link arrayUniqueBy} 按指定键去重。
|
|
6
9
|
*
|
|
7
10
|
* @param data - 源数组
|
|
8
11
|
* @returns 去重后的新数组
|
|
9
12
|
*/
|
|
10
13
|
declare function arrayUnique<T = RecordType>(data: T[]): T[];
|
|
14
|
+
/**
|
|
15
|
+
* 按指定键对对象数组去重(保留首次出现的元素)
|
|
16
|
+
*
|
|
17
|
+
* 相比 {@link arrayUnique},本函数通过键值判等,可正确对对象数组去重。
|
|
18
|
+
*
|
|
19
|
+
* @param data - 源数组
|
|
20
|
+
* @param by - 用于判断重复的键名,或返回去重键值的函数
|
|
21
|
+
* @returns 去重后的新数组
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const data = [{ id: 1, name: 'a' }, { id: 2, name: 'b' }, { id: 1, name: 'c' }]
|
|
26
|
+
* arrayUniqueBy(data, 'id')
|
|
27
|
+
* // => [{ id: 1, name: 'a' }, { id: 2, name: 'b' }]
|
|
28
|
+
* arrayUniqueBy(data, item => item.name)
|
|
29
|
+
* // => [{ id: 1, name: 'a' }, { id: 2, name: 'b' }]
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function arrayUniqueBy<T extends RecordType>(data: T[], by: keyof T | ((item: T) => any)): T[];
|
|
11
33
|
//#endregion
|
|
12
|
-
export { arrayUnique };
|
|
34
|
+
export { arrayUnique, arrayUniqueBy };
|
package/dist/array/unique.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
//#region src/array/unique.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* 数组去重(基于 Set,仅对基本类型或引用相同的元素有效)
|
|
4
|
+
*
|
|
5
|
+
* 由于使用 `Set` 判等,对象数组会因引用不同而无法去重,
|
|
6
|
+
* 对象场景请使用 {@link arrayUniqueBy} 按指定键去重。
|
|
4
7
|
*
|
|
5
8
|
* @param data - 源数组
|
|
6
9
|
* @returns 去重后的新数组
|
|
@@ -9,6 +12,34 @@ function arrayUnique(data) {
|
|
|
9
12
|
const set = new Set(data);
|
|
10
13
|
return Array.from(set);
|
|
11
14
|
}
|
|
12
|
-
|
|
15
|
+
/**
|
|
16
|
+
* 按指定键对对象数组去重(保留首次出现的元素)
|
|
17
|
+
*
|
|
18
|
+
* 相比 {@link arrayUnique},本函数通过键值判等,可正确对对象数组去重。
|
|
19
|
+
*
|
|
20
|
+
* @param data - 源数组
|
|
21
|
+
* @param by - 用于判断重复的键名,或返回去重键值的函数
|
|
22
|
+
* @returns 去重后的新数组
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const data = [{ id: 1, name: 'a' }, { id: 2, name: 'b' }, { id: 1, name: 'c' }]
|
|
27
|
+
* arrayUniqueBy(data, 'id')
|
|
28
|
+
* // => [{ id: 1, name: 'a' }, { id: 2, name: 'b' }]
|
|
29
|
+
* arrayUniqueBy(data, item => item.name)
|
|
30
|
+
* // => [{ id: 1, name: 'a' }, { id: 2, name: 'b' }]
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function arrayUniqueBy(data, by) {
|
|
34
|
+
if (!Array.isArray(data)) return [];
|
|
35
|
+
const seen = /* @__PURE__ */ new Set();
|
|
36
|
+
const getKey = typeof by === "function" ? by : (item) => item[by];
|
|
37
|
+
return data.filter((item) => {
|
|
38
|
+
const key = getKey(item);
|
|
39
|
+
if (seen.has(key)) return false;
|
|
40
|
+
seen.add(key);
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
13
44
|
//#endregion
|
|
14
|
-
export { arrayUnique };
|
|
45
|
+
export { arrayUnique, arrayUniqueBy };
|
package/dist/class/index.js
CHANGED
package/dist/class/prefix.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ interface PrefixCls {
|
|
|
5
5
|
/** 自定义前缀 */
|
|
6
6
|
customizePrefixCls?: string;
|
|
7
7
|
/** 是否为 pro 组件 */
|
|
8
|
-
|
|
8
|
+
isPro?: boolean;
|
|
9
9
|
/** 类名 */
|
|
10
10
|
className?: string;
|
|
11
11
|
}
|
|
@@ -18,7 +18,7 @@ interface PrefixCls {
|
|
|
18
18
|
declare function getPrefixCls({
|
|
19
19
|
suffixCls,
|
|
20
20
|
customizePrefixCls,
|
|
21
|
-
|
|
21
|
+
isPro,
|
|
22
22
|
className
|
|
23
23
|
}: PrefixCls): string;
|
|
24
24
|
//#endregion
|
package/dist/class/prefix.js
CHANGED
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* @param options - 配置选项
|
|
6
6
|
* @returns 完整类名
|
|
7
7
|
*/
|
|
8
|
-
function getPrefixCls({ suffixCls, customizePrefixCls,
|
|
9
|
-
const prefixCls = className || (
|
|
8
|
+
function getPrefixCls({ suffixCls, customizePrefixCls, isPro, className }) {
|
|
9
|
+
const prefixCls = className || (isPro ? "gx-pro" : "gx");
|
|
10
10
|
if (customizePrefixCls) return customizePrefixCls;
|
|
11
11
|
return suffixCls ? `${prefixCls}-${suffixCls}` : prefixCls;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
//#endregion
|
|
15
|
-
export { getPrefixCls };
|
|
14
|
+
export { getPrefixCls };
|
package/dist/clone/cloneDeep.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { cloneDeepWithImpl } from "./cloneDeepWith.js";
|
|
2
|
-
|
|
3
2
|
//#region src/clone/cloneDeep.ts
|
|
4
3
|
/**
|
|
5
4
|
* 深度克隆对象
|
|
@@ -30,6 +29,5 @@ import { cloneDeepWithImpl } from "./cloneDeepWith.js";
|
|
|
30
29
|
function cloneDeep(obj) {
|
|
31
30
|
return cloneDeepWithImpl(obj, void 0, obj, /* @__PURE__ */ new Map(), void 0);
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
//#endregion
|
|
35
|
-
export { cloneDeep };
|
|
33
|
+
export { cloneDeep };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
+
import { getSymbols } from "../function/object.js";
|
|
1
2
|
import { isPrimitive } from "../is/primitive.js";
|
|
2
3
|
import { isTypedArray } from "../is/typedArray.js";
|
|
3
|
-
import "../is/index.js";
|
|
4
4
|
import { getTag } from "./getTag.js";
|
|
5
|
-
import { getSymbols } from "./symbols.js";
|
|
6
5
|
import { argumentsTag, arrayBufferTag, arrayTag, booleanTag, dataViewTag, dateTag, float32ArrayTag, float64ArrayTag, int16ArrayTag, int32ArrayTag, int8ArrayTag, mapTag, numberTag, objectTag, regexpTag, setTag, stringTag, symbolTag, uint16ArrayTag, uint32ArrayTag, uint8ArrayTag, uint8ClampedArrayTag } from "./tags.js";
|
|
7
|
-
|
|
8
6
|
//#region src/clone/cloneDeepWith.ts
|
|
9
7
|
/**
|
|
10
8
|
* 深度克隆对象(带自定义处理)
|
|
@@ -26,8 +24,8 @@ function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = /* @
|
|
|
26
24
|
const result = Array.from({ length: valueToClone.length });
|
|
27
25
|
stack.set(valueToClone, result);
|
|
28
26
|
for (let i = 0; i < valueToClone.length; i++) result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
|
|
29
|
-
if (Object.
|
|
30
|
-
if (Object.
|
|
27
|
+
if (Object.hasOwn(valueToClone, "index")) result.index = valueToClone.index;
|
|
28
|
+
if (Object.hasOwn(valueToClone, "input")) result.input = valueToClone.input;
|
|
31
29
|
return result;
|
|
32
30
|
}
|
|
33
31
|
if (valueToClone instanceof Date) return new Date(valueToClone.getTime());
|
|
@@ -145,6 +143,5 @@ function isCloneableObject(object) {
|
|
|
145
143
|
default: return false;
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
|
-
|
|
149
146
|
//#endregion
|
|
150
|
-
export { cloneDeepWith, cloneDeepWithImpl, copyProperties };
|
|
147
|
+
export { cloneDeepWith, cloneDeepWithImpl, copyProperties };
|
package/dist/clone/getTag.js
CHANGED
package/dist/clone/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { cloneDeepWith, cloneDeepWithImpl, copyProperties } from "./cloneDeepWith.js";
|
|
2
2
|
import { cloneDeep } from "./cloneDeep.js";
|
|
3
|
-
|
|
4
|
-
export { cloneDeep, cloneDeepWith, cloneDeepWithImpl, copyProperties };
|
|
3
|
+
export { cloneDeep, cloneDeepWith, cloneDeepWithImpl, copyProperties };
|
package/dist/clone/tags.js
CHANGED
|
@@ -43,6 +43,5 @@ const uint8ClampedArrayTag = "[object Uint8ClampedArray]";
|
|
|
43
43
|
const uint16ArrayTag = "[object Uint16Array]";
|
|
44
44
|
/** Uint32 数组标签 */
|
|
45
45
|
const uint32ArrayTag = "[object Uint32Array]";
|
|
46
|
-
|
|
47
46
|
//#endregion
|
|
48
|
-
export { argumentsTag, arrayBufferTag, arrayTag, booleanTag, dataViewTag, dateTag, float32ArrayTag, float64ArrayTag, int16ArrayTag, int32ArrayTag, int8ArrayTag, mapTag, numberTag, objectTag, regexpTag, setTag, stringTag, symbolTag, uint16ArrayTag, uint32ArrayTag, uint8ArrayTag, uint8ClampedArrayTag };
|
|
47
|
+
export { argumentsTag, arrayBufferTag, arrayTag, booleanTag, dataViewTag, dateTag, float32ArrayTag, float64ArrayTag, int16ArrayTag, int32ArrayTag, int8ArrayTag, mapTag, numberTag, objectTag, regexpTag, setTag, stringTag, symbolTag, uint16ArrayTag, uint32ArrayTag, uint8ArrayTag, uint8ClampedArrayTag };
|
package/dist/dom/event.js
CHANGED
|
@@ -21,6 +21,5 @@ function on(element, event, handler, useCapture = false) {
|
|
|
21
21
|
function off(element, event, handler, useCapture = false) {
|
|
22
22
|
if (element && event && handler) element.removeEventListener(event, handler, useCapture);
|
|
23
23
|
}
|
|
24
|
-
|
|
25
24
|
//#endregion
|
|
26
|
-
export { off, on };
|
|
25
|
+
export { off, on };
|
package/dist/dom/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { off, on } from "./event.js";
|
|
2
2
|
import { getTextWidth } from "./measure.js";
|
|
3
|
-
import
|
|
3
|
+
import { generateVideoPicture, getMediaInfos, getVideoCoverPicture } from "./media.js";
|
|
4
|
+
import { wrapperRaf } from "./raf.js";
|
|
4
5
|
import { ScrollToOptions, easeInOutCubic, getScroll, getScrollContainer, isInContainer, isScroll, isWindow, scrollTo } from "./scroll.js";
|
|
5
|
-
export { ScrollToOptions, easeInOutCubic, getScroll, getScrollContainer, getTextWidth, isInContainer, isScroll, isWindow, off, on, wrapperRaf as raf, scrollTo };
|
|
6
|
+
export { ScrollToOptions, easeInOutCubic, generateVideoPicture, getMediaInfos, getScroll, getScrollContainer, getTextWidth, getVideoCoverPicture, isInContainer, isScroll, isWindow, off, on, wrapperRaf as raf, scrollTo };
|
package/dist/dom/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { off, on } from "./event.js";
|
|
2
2
|
import { getTextWidth } from "./measure.js";
|
|
3
|
-
import
|
|
3
|
+
import { generateVideoPicture, getMediaInfos, getVideoCoverPicture } from "./media.js";
|
|
4
|
+
import { wrapperRaf } from "./raf.js";
|
|
4
5
|
import { easeInOutCubic, getScroll, getScrollContainer, isInContainer, isScroll, isWindow, scrollTo } from "./scroll.js";
|
|
5
|
-
|
|
6
|
-
export { easeInOutCubic, getScroll, getScrollContainer, getTextWidth, isInContainer, isScroll, isWindow, off, on, wrapperRaf as raf, scrollTo };
|
|
6
|
+
export { easeInOutCubic, generateVideoPicture, getMediaInfos, getScroll, getScrollContainer, getTextWidth, getVideoCoverPicture, isInContainer, isScroll, isWindow, off, on, wrapperRaf as raf, scrollTo };
|
package/dist/dom/measure.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { isBoolean, isObject } from "../is/type.js";
|
|
2
|
-
import "../is/index.js";
|
|
3
|
-
|
|
4
2
|
//#region src/dom/measure.ts
|
|
5
3
|
/**
|
|
6
4
|
* 获取文字宽度或高度
|
|
@@ -10,6 +8,7 @@ import "../is/index.js";
|
|
|
10
8
|
* @returns 宽度或高度
|
|
11
9
|
*/
|
|
12
10
|
function getTextWidth(str, options) {
|
|
11
|
+
if (typeof document === "undefined") return 0;
|
|
13
12
|
let number = 0;
|
|
14
13
|
const removeAfter = isBoolean(options.removeAfter) ? options.removeAfter : true;
|
|
15
14
|
const targetElId = options.id || "hiddenElement";
|
|
@@ -22,11 +21,13 @@ function getTextWidth(str, options) {
|
|
|
22
21
|
left: 0
|
|
23
22
|
};
|
|
24
23
|
let targetEl = document.querySelector(`#${targetElId}`);
|
|
24
|
+
let containerCreatedByThisCall = false;
|
|
25
25
|
if (!targetEl) {
|
|
26
26
|
const el = document.createElement("div");
|
|
27
27
|
el.id = targetElId;
|
|
28
28
|
document.body.appendChild(el);
|
|
29
|
-
targetEl =
|
|
29
|
+
targetEl = el;
|
|
30
|
+
containerCreatedByThisCall = true;
|
|
30
31
|
}
|
|
31
32
|
Object.assign(targetEl.style, targetElStyle);
|
|
32
33
|
const sourceEl = document.createElement(options.createName || "span");
|
|
@@ -34,9 +35,11 @@ function getTextWidth(str, options) {
|
|
|
34
35
|
if (options.cssObject || isObject(options.cssObject)) Object.assign(sourceEl.style, options.cssObject);
|
|
35
36
|
targetEl.append(sourceEl);
|
|
36
37
|
number = sourceEl.getBoundingClientRect()[options.type || "width"];
|
|
37
|
-
if (removeAfter)
|
|
38
|
+
if (removeAfter) {
|
|
39
|
+
targetEl.removeChild(sourceEl);
|
|
40
|
+
if (containerCreatedByThisCall && targetEl.parentNode) targetEl.parentNode.removeChild(targetEl);
|
|
41
|
+
}
|
|
38
42
|
return number;
|
|
39
43
|
}
|
|
40
|
-
|
|
41
44
|
//#endregion
|
|
42
|
-
export { getTextWidth };
|
|
45
|
+
export { getTextWidth };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../is/
|
|
3
|
-
import { fileTypes } from "
|
|
4
|
-
import { checkFileType, getFileSuffix } from "
|
|
5
|
-
|
|
6
|
-
//#region src/file/media.ts
|
|
1
|
+
import { isMediaDataURI } from "../is/base64.js";
|
|
2
|
+
import { isServer } from "../is/server.js";
|
|
3
|
+
import { fileTypes } from "../file/config.js";
|
|
4
|
+
import { checkFileType, getFileSuffix } from "../file/type.js";
|
|
5
|
+
//#region src/dom/media.ts
|
|
7
6
|
/**
|
|
8
7
|
* 获取媒体信息(图片/视频/音频)
|
|
9
8
|
*
|
|
@@ -29,10 +28,12 @@ function getMediaInfos(mediaInfo) {
|
|
|
29
28
|
duration: 0
|
|
30
29
|
};
|
|
31
30
|
}
|
|
31
|
+
if (isServer) return Promise.resolve(result);
|
|
32
32
|
if (url instanceof File) mediaUrl = URL.createObjectURL(url);
|
|
33
|
-
else if (
|
|
33
|
+
else if (isMediaDataURI(url)) mediaUrl = url;
|
|
34
34
|
else if (url instanceof Blob) mediaUrl = URL.createObjectURL(url);
|
|
35
35
|
else if (url.includes("https") || url.includes("http")) mediaUrl = fileType === "1" ? url : url;
|
|
36
|
+
const shouldRevoke = url instanceof File || url instanceof Blob;
|
|
36
37
|
return new Promise((resolve) => {
|
|
37
38
|
let el;
|
|
38
39
|
if (fileType === "4") {
|
|
@@ -54,6 +55,7 @@ function getMediaInfos(mediaInfo) {
|
|
|
54
55
|
result.play = true;
|
|
55
56
|
result.width = el.width || 0;
|
|
56
57
|
result.height = el.height || 0;
|
|
58
|
+
if (shouldRevoke) URL.revokeObjectURL(mediaUrl);
|
|
57
59
|
resolve(result);
|
|
58
60
|
el = null;
|
|
59
61
|
};
|
|
@@ -63,11 +65,13 @@ function getMediaInfos(mediaInfo) {
|
|
|
63
65
|
result.width = el?.videoWidth || 0;
|
|
64
66
|
result.height = el?.videoHeight || 0;
|
|
65
67
|
result.duration = el?.duration || 0;
|
|
68
|
+
if (shouldRevoke) URL.revokeObjectURL(mediaUrl);
|
|
66
69
|
resolve(result);
|
|
67
70
|
el = null;
|
|
68
71
|
};
|
|
69
72
|
el.onerror = function() {
|
|
70
73
|
resetResult();
|
|
74
|
+
if (shouldRevoke) URL.revokeObjectURL(mediaUrl);
|
|
71
75
|
resolve(result);
|
|
72
76
|
el = null;
|
|
73
77
|
};
|
|
@@ -81,18 +85,22 @@ function getMediaInfos(mediaInfo) {
|
|
|
81
85
|
*/
|
|
82
86
|
async function getVideoCoverPicture(videoInfo) {
|
|
83
87
|
const { url = "", currentTime, videoSuffix = "", videoAllowPlay = false } = videoInfo;
|
|
88
|
+
if (isServer) return "";
|
|
84
89
|
let videoUrl = "";
|
|
85
90
|
let fileSuffix = videoSuffix;
|
|
86
91
|
let fileType = "1";
|
|
87
92
|
let videoPlayInfo;
|
|
93
|
+
let shouldRevoke = false;
|
|
88
94
|
if (url instanceof File) {
|
|
89
95
|
videoUrl = URL.createObjectURL(url);
|
|
96
|
+
shouldRevoke = true;
|
|
90
97
|
fileSuffix = getFileSuffix(url.name);
|
|
91
98
|
fileType = checkFileType(url.name);
|
|
92
99
|
} else if (url instanceof Blob) {
|
|
93
100
|
videoUrl = URL.createObjectURL(url);
|
|
101
|
+
shouldRevoke = true;
|
|
94
102
|
fileType = checkFileType(url);
|
|
95
|
-
} else if (
|
|
103
|
+
} else if (isMediaDataURI(url)) {
|
|
96
104
|
videoUrl = url;
|
|
97
105
|
fileType = checkFileType(url);
|
|
98
106
|
} else if (url.includes("https") || url.includes("http")) {
|
|
@@ -100,16 +108,25 @@ async function getVideoCoverPicture(videoInfo) {
|
|
|
100
108
|
fileSuffix = getFileSuffix(url);
|
|
101
109
|
fileType = checkFileType(url);
|
|
102
110
|
}
|
|
103
|
-
if (fileSuffix ? fileTypes.videoAllowType.includes(fileSuffix.toLowerCase()) : false) if (videoAllowPlay)
|
|
104
|
-
|
|
111
|
+
if (fileSuffix ? fileTypes.videoAllowType.includes(fileSuffix.toLowerCase()) : false) if (videoAllowPlay) {
|
|
112
|
+
const picture = await generateVideoPicture(videoUrl, currentTime);
|
|
113
|
+
if (shouldRevoke) URL.revokeObjectURL(videoUrl);
|
|
114
|
+
return picture;
|
|
115
|
+
} else {
|
|
105
116
|
videoPlayInfo = await getMediaInfos({
|
|
106
117
|
url: videoUrl,
|
|
107
118
|
fileType
|
|
108
119
|
});
|
|
109
|
-
if (videoPlayInfo.play)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
if (videoPlayInfo.play) {
|
|
121
|
+
const picture = await generateVideoPicture(videoUrl, currentTime);
|
|
122
|
+
if (shouldRevoke) URL.revokeObjectURL(videoUrl);
|
|
123
|
+
return picture;
|
|
124
|
+
} else {
|
|
125
|
+
if (shouldRevoke) URL.revokeObjectURL(videoUrl);
|
|
126
|
+
return new Promise((resolve) => {
|
|
127
|
+
resolve("");
|
|
128
|
+
});
|
|
129
|
+
}
|
|
113
130
|
}
|
|
114
131
|
else return new Promise((resolve) => {
|
|
115
132
|
resolve("");
|
|
@@ -123,6 +140,7 @@ async function getVideoCoverPicture(videoInfo) {
|
|
|
123
140
|
* @returns 截图 base64
|
|
124
141
|
*/
|
|
125
142
|
async function generateVideoPicture(videoUrl, currentTime = 0) {
|
|
143
|
+
if (isServer) return "";
|
|
126
144
|
return new Promise((resolve) => {
|
|
127
145
|
let video = document.createElement("video");
|
|
128
146
|
if (video) {
|
|
@@ -143,11 +161,11 @@ async function generateVideoPicture(videoUrl, currentTime = 0) {
|
|
|
143
161
|
const canvas = document.createElement("canvas");
|
|
144
162
|
const scale = .8;
|
|
145
163
|
const ctx = canvas.getContext("2d");
|
|
146
|
-
const w = video?.videoWidth || 0 * scale;
|
|
147
|
-
const h = video?.videoHeight || 0 * scale;
|
|
164
|
+
const w = (video?.videoWidth || 0) * scale;
|
|
165
|
+
const h = (video?.videoHeight || 0) * scale;
|
|
148
166
|
const space = 0;
|
|
149
|
-
canvas.width = video?.videoWidth || 0 * scale;
|
|
150
|
-
canvas.height = video?.videoHeight || 0 * scale;
|
|
167
|
+
canvas.width = (video?.videoWidth || 0) * scale;
|
|
168
|
+
canvas.height = (video?.videoHeight || 0) * scale;
|
|
151
169
|
if (video) ctx.drawImage(video, 0, 0, w + space, h + space);
|
|
152
170
|
video = null;
|
|
153
171
|
resolve(w === 0 || h === 0 ? "" : canvas.toDataURL("image/png", 1));
|
|
@@ -156,6 +174,5 @@ async function generateVideoPicture(videoUrl, currentTime = 0) {
|
|
|
156
174
|
}
|
|
157
175
|
});
|
|
158
176
|
}
|
|
159
|
-
|
|
160
177
|
//#endregion
|
|
161
|
-
export { generateVideoPicture, getMediaInfos, getVideoCoverPicture };
|
|
178
|
+
export { generateVideoPicture, getMediaInfos, getVideoCoverPicture };
|
package/dist/dom/raf.d.ts
CHANGED
package/dist/dom/raf.js
CHANGED
package/dist/dom/scroll.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { isServer } from "../is/server.js";
|
|
2
|
-
import "
|
|
3
|
-
import wrapperRaf from "./raf.js";
|
|
4
|
-
|
|
2
|
+
import { wrapperRaf } from "./raf.js";
|
|
5
3
|
//#region src/dom/scroll.ts
|
|
6
4
|
function easeInOutCubic(t, b, c, d) {
|
|
7
5
|
const cc = c - b;
|
|
@@ -77,8 +75,9 @@ function getScroll(target, top) {
|
|
|
77
75
|
return result;
|
|
78
76
|
}
|
|
79
77
|
function scrollTo(y, options = {}) {
|
|
80
|
-
const { getContainer
|
|
81
|
-
const container = getContainer();
|
|
78
|
+
const { getContainer, callback, duration = 450 } = options;
|
|
79
|
+
const container = getContainer?.() ?? (isServer ? void 0 : window);
|
|
80
|
+
if (isServer || !container) return;
|
|
82
81
|
const scrollTop = getScroll(container, true);
|
|
83
82
|
const startTime = Date.now();
|
|
84
83
|
const frameFunc = () => {
|
|
@@ -92,6 +91,5 @@ function scrollTo(y, options = {}) {
|
|
|
92
91
|
};
|
|
93
92
|
if (container) wrapperRaf(frameFunc);
|
|
94
93
|
}
|
|
95
|
-
|
|
96
94
|
//#endregion
|
|
97
|
-
export { easeInOutCubic, getScroll, getScrollContainer, isInContainer, isScroll, isWindow, scrollTo };
|
|
95
|
+
export { easeInOutCubic, getScroll, getScrollContainer, isInContainer, isScroll, isWindow, scrollTo };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/base64
|
|
1
|
+
//#region src/encoding/base64.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Base64 编解码类
|
|
4
4
|
*/
|
|
@@ -23,4 +23,4 @@ declare class Base64 {
|
|
|
23
23
|
decode(input: string): string;
|
|
24
24
|
}
|
|
25
25
|
//#endregion
|
|
26
|
-
export { Base64 as default };
|
|
26
|
+
export { Base64, Base64 as default };
|