@gx-design-vue/pro-utils 0.2.0-alpha.3 → 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 -2
- package/dist/array/slice.js +0 -1
- package/dist/array/sort.js +4 -5
- package/dist/array/tree.d.ts +4 -4
- package/dist/array/tree.js +14 -12
- package/dist/array/unique.d.ts +24 -2
- package/dist/array/unique.js +34 -2
- package/dist/class/prefix.d.ts +2 -2
- package/dist/class/prefix.js +2 -2
- package/dist/clone/cloneDeepWith.js +3 -4
- package/dist/dom/index.d.ts +3 -2
- package/dist/dom/index.js +3 -2
- package/dist/dom/measure.js +8 -3
- package/dist/{file → dom}/media.d.ts +1 -1
- package/dist/{file → dom}/media.js +36 -17
- package/dist/dom/raf.d.ts +1 -1
- package/dist/dom/raf.js +1 -1
- package/dist/dom/scroll.js +4 -4
- package/dist/{base64/index.d.ts → encoding/base64.d.ts} +2 -2
- package/dist/{base64/index.js → encoding/base64.js} +29 -32
- package/dist/encoding/index.d.ts +2 -0
- package/dist/encoding/index.js +2 -0
- package/dist/file/convert.d.ts +6 -2
- package/dist/file/convert.js +7 -2
- package/dist/file/index.d.ts +2 -3
- package/dist/file/index.js +2 -3
- package/dist/file/type.js +6 -7
- package/dist/function/copy.d.ts +7 -0
- package/dist/function/copy.js +7 -0
- package/dist/function/getValue.d.ts +2 -2
- package/dist/function/getValue.js +3 -3
- package/dist/index.d.ts +11 -10
- package/dist/index.js +12 -20
- package/dist/is/base64.d.ts +7 -4
- package/dist/is/base64.js +9 -5
- package/dist/is/browser.js +1 -1
- package/dist/is/deepEqual.d.ts +10 -4
- package/dist/is/deepEqual.js +14 -8
- package/dist/is/device.js +3 -0
- package/dist/is/index.d.ts +3 -3
- package/dist/is/index.js +3 -3
- package/dist/is/plainObject.js +1 -1
- package/dist/is/url.js +1 -2
- package/dist/merge/{useDeepMege.d.ts → deepCloneMerge.d.ts} +3 -1
- package/dist/merge/{useDeepMege.js → deepCloneMerge.js} +5 -3
- package/dist/merge/index.d.ts +1 -1
- package/dist/merge/index.js +1 -3
- package/dist/merge/mergeWith.js +0 -1
- package/dist/number/chinese.js +0 -1
- package/dist/number/format.js +6 -3
- package/dist/object/classNames.js +0 -1
- package/dist/pro-utils.esm.js +486 -387
- package/dist/pro-utils.js +2 -1
- package/dist/{vue/slots.d.ts → slots/index.d.ts} +1 -1
- package/dist/{vue/slots.js → slots/index.js} +33 -17
- package/dist/string/index.d.ts +2 -2
- package/dist/string/index.js +2 -2
- package/dist/string/uuid.d.ts +10 -8
- package/dist/string/uuid.js +23 -33
- package/dist/table/column.js +5 -7
- package/dist/table/page.js +0 -1
- package/dist/typing.d.ts +2 -2
- package/package.json +2 -1
- package/dist/clone/symbols.d.ts +0 -10
- package/dist/clone/symbols.js +0 -12
- package/dist/vue/index.d.ts +0 -2
- package/dist/vue/index.js +0 -2
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,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/slice.js
CHANGED
package/dist/array/sort.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isNumber } from "../is/type.js";
|
|
2
|
-
import "../is/index.js";
|
|
3
2
|
//#region src/array/sort.ts
|
|
4
3
|
/**
|
|
5
4
|
* 比较数组元素(用于排序)
|
|
@@ -15,8 +14,8 @@ function compareArray(obj1, obj2, key, sort = 0) {
|
|
|
15
14
|
const prev = obj1[key];
|
|
16
15
|
const next = obj2[key];
|
|
17
16
|
let result = 0;
|
|
18
|
-
if (prev < next) result = newType === 0 ? -1 :
|
|
19
|
-
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;
|
|
20
19
|
return result;
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
@@ -33,8 +32,8 @@ function compareTime(obj1, obj2, key, sort = 0) {
|
|
|
33
32
|
const prev = new Date(obj1[key]);
|
|
34
33
|
const next = new Date(obj2[key]);
|
|
35
34
|
let result = 0;
|
|
36
|
-
if (prev < next) result = newType === 0 ? -1 :
|
|
37
|
-
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;
|
|
38
37
|
return result;
|
|
39
38
|
}
|
|
40
39
|
/**
|
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
|
*
|
|
@@ -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,5 +1,4 @@
|
|
|
1
1
|
import { isArray, isObject } from "../is/type.js";
|
|
2
|
-
import "../is/index.js";
|
|
3
2
|
//#region src/array/tree.ts
|
|
4
3
|
/**
|
|
5
4
|
* 获取树形结构最深的层级数
|
|
@@ -20,14 +19,14 @@ function getMaxFloor(data, childrenKey) {
|
|
|
20
19
|
* 树形转平级
|
|
21
20
|
*
|
|
22
21
|
* @param data - 树形数据
|
|
23
|
-
* @param
|
|
22
|
+
* @param field - 子节点键名
|
|
24
23
|
* @returns 平级数组
|
|
25
24
|
*/
|
|
26
|
-
function getLevelData(data,
|
|
25
|
+
function getLevelData(data, field = "children") {
|
|
27
26
|
let newData = [];
|
|
28
27
|
data.forEach((item) => {
|
|
29
28
|
newData.push(item);
|
|
30
|
-
if (isArray(item[
|
|
29
|
+
if (isArray(item[field]) && item[field].length > 0) newData = newData.concat(getLevelData(item[field], field));
|
|
31
30
|
});
|
|
32
31
|
return newData;
|
|
33
32
|
}
|
|
@@ -43,15 +42,19 @@ function treeData(source, options) {
|
|
|
43
42
|
const { id = "id", parentId = "parentId", children = "children", emptyChildren = true } = options || {};
|
|
44
43
|
const rootId = options?.rootId ?? 0;
|
|
45
44
|
const cloneData = structuredClone(source);
|
|
46
|
-
|
|
45
|
+
const childrenMap = /* @__PURE__ */ new Map();
|
|
46
|
+
cloneData.forEach((item) => {
|
|
47
47
|
if (!emptyChildren && item[children] && item[children]?.length === 0) delete item[children];
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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;
|
|
52
55
|
else if (emptyChildren) father[children] = [];
|
|
53
|
-
return rootId === false ? true : father[parentId] === rootId;
|
|
54
56
|
});
|
|
57
|
+
return rootId === false ? cloneData : cloneData.filter((father) => father[parentId] === rootId);
|
|
55
58
|
}
|
|
56
59
|
/**
|
|
57
60
|
* 树形数组按照条件过滤
|
|
@@ -119,11 +122,10 @@ function findSourceByTree(tree, value, options) {
|
|
|
119
122
|
* 获取数组最后一个元素
|
|
120
123
|
*
|
|
121
124
|
* @param data - 数组
|
|
122
|
-
* @returns
|
|
125
|
+
* @returns 最后一个元素,空数组或非数组返回 undefined
|
|
123
126
|
*/
|
|
124
127
|
function getArrayLast(data) {
|
|
125
128
|
if (data && isArray(data)) return data[data.length - 1];
|
|
126
|
-
return null;
|
|
127
129
|
}
|
|
128
130
|
/**
|
|
129
131
|
* 数组(树形)添加序号
|
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,5 +12,34 @@ function arrayUnique(data) {
|
|
|
9
12
|
const set = new Set(data);
|
|
10
13
|
return Array.from(set);
|
|
11
14
|
}
|
|
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
|
+
}
|
|
12
44
|
//#endregion
|
|
13
|
-
export { arrayUnique };
|
|
45
|
+
export { arrayUnique, arrayUniqueBy };
|
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,8 +5,8 @@
|
|
|
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
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
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
6
|
//#region src/clone/cloneDeepWith.ts
|
|
8
7
|
/**
|
|
@@ -25,8 +24,8 @@ function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = /* @
|
|
|
25
24
|
const result = Array.from({ length: valueToClone.length });
|
|
26
25
|
stack.set(valueToClone, result);
|
|
27
26
|
for (let i = 0; i < valueToClone.length; i++) result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
|
|
28
|
-
if (Object.
|
|
29
|
-
if (Object.
|
|
27
|
+
if (Object.hasOwn(valueToClone, "index")) result.index = valueToClone.index;
|
|
28
|
+
if (Object.hasOwn(valueToClone, "input")) result.input = valueToClone.input;
|
|
30
29
|
return result;
|
|
31
30
|
}
|
|
32
31
|
if (valueToClone instanceof Date) return new Date(valueToClone.getTime());
|
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,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 { easeInOutCubic, getScroll, getScrollContainer, isInContainer, isScroll, isWindow, scrollTo } from "./scroll.js";
|
|
5
|
-
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,5 +1,4 @@
|
|
|
1
1
|
import { isBoolean, isObject } from "../is/type.js";
|
|
2
|
-
import "../is/index.js";
|
|
3
2
|
//#region src/dom/measure.ts
|
|
4
3
|
/**
|
|
5
4
|
* 获取文字宽度或高度
|
|
@@ -9,6 +8,7 @@ import "../is/index.js";
|
|
|
9
8
|
* @returns 宽度或高度
|
|
10
9
|
*/
|
|
11
10
|
function getTextWidth(str, options) {
|
|
11
|
+
if (typeof document === "undefined") return 0;
|
|
12
12
|
let number = 0;
|
|
13
13
|
const removeAfter = isBoolean(options.removeAfter) ? options.removeAfter : true;
|
|
14
14
|
const targetElId = options.id || "hiddenElement";
|
|
@@ -21,11 +21,13 @@ function getTextWidth(str, options) {
|
|
|
21
21
|
left: 0
|
|
22
22
|
};
|
|
23
23
|
let targetEl = document.querySelector(`#${targetElId}`);
|
|
24
|
+
let containerCreatedByThisCall = false;
|
|
24
25
|
if (!targetEl) {
|
|
25
26
|
const el = document.createElement("div");
|
|
26
27
|
el.id = targetElId;
|
|
27
28
|
document.body.appendChild(el);
|
|
28
|
-
targetEl =
|
|
29
|
+
targetEl = el;
|
|
30
|
+
containerCreatedByThisCall = true;
|
|
29
31
|
}
|
|
30
32
|
Object.assign(targetEl.style, targetElStyle);
|
|
31
33
|
const sourceEl = document.createElement(options.createName || "span");
|
|
@@ -33,7 +35,10 @@ function getTextWidth(str, options) {
|
|
|
33
35
|
if (options.cssObject || isObject(options.cssObject)) Object.assign(sourceEl.style, options.cssObject);
|
|
34
36
|
targetEl.append(sourceEl);
|
|
35
37
|
number = sourceEl.getBoundingClientRect()[options.type || "width"];
|
|
36
|
-
if (removeAfter)
|
|
38
|
+
if (removeAfter) {
|
|
39
|
+
targetEl.removeChild(sourceEl);
|
|
40
|
+
if (containerCreatedByThisCall && targetEl.parentNode) targetEl.parentNode.removeChild(targetEl);
|
|
41
|
+
}
|
|
37
42
|
return number;
|
|
38
43
|
}
|
|
39
44
|
//#endregion
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../is/
|
|
3
|
-
import { fileTypes } from "
|
|
4
|
-
import { checkFileType, getFileSuffix } from "
|
|
5
|
-
//#region src/
|
|
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
|
|
6
6
|
/**
|
|
7
7
|
* 获取媒体信息(图片/视频/音频)
|
|
8
8
|
*
|
|
@@ -28,10 +28,12 @@ function getMediaInfos(mediaInfo) {
|
|
|
28
28
|
duration: 0
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
+
if (isServer) return Promise.resolve(result);
|
|
31
32
|
if (url instanceof File) mediaUrl = URL.createObjectURL(url);
|
|
32
|
-
else if (
|
|
33
|
+
else if (isMediaDataURI(url)) mediaUrl = url;
|
|
33
34
|
else if (url instanceof Blob) mediaUrl = URL.createObjectURL(url);
|
|
34
35
|
else if (url.includes("https") || url.includes("http")) mediaUrl = fileType === "1" ? url : url;
|
|
36
|
+
const shouldRevoke = url instanceof File || url instanceof Blob;
|
|
35
37
|
return new Promise((resolve) => {
|
|
36
38
|
let el;
|
|
37
39
|
if (fileType === "4") {
|
|
@@ -53,6 +55,7 @@ function getMediaInfos(mediaInfo) {
|
|
|
53
55
|
result.play = true;
|
|
54
56
|
result.width = el.width || 0;
|
|
55
57
|
result.height = el.height || 0;
|
|
58
|
+
if (shouldRevoke) URL.revokeObjectURL(mediaUrl);
|
|
56
59
|
resolve(result);
|
|
57
60
|
el = null;
|
|
58
61
|
};
|
|
@@ -62,11 +65,13 @@ function getMediaInfos(mediaInfo) {
|
|
|
62
65
|
result.width = el?.videoWidth || 0;
|
|
63
66
|
result.height = el?.videoHeight || 0;
|
|
64
67
|
result.duration = el?.duration || 0;
|
|
68
|
+
if (shouldRevoke) URL.revokeObjectURL(mediaUrl);
|
|
65
69
|
resolve(result);
|
|
66
70
|
el = null;
|
|
67
71
|
};
|
|
68
72
|
el.onerror = function() {
|
|
69
73
|
resetResult();
|
|
74
|
+
if (shouldRevoke) URL.revokeObjectURL(mediaUrl);
|
|
70
75
|
resolve(result);
|
|
71
76
|
el = null;
|
|
72
77
|
};
|
|
@@ -80,18 +85,22 @@ function getMediaInfos(mediaInfo) {
|
|
|
80
85
|
*/
|
|
81
86
|
async function getVideoCoverPicture(videoInfo) {
|
|
82
87
|
const { url = "", currentTime, videoSuffix = "", videoAllowPlay = false } = videoInfo;
|
|
88
|
+
if (isServer) return "";
|
|
83
89
|
let videoUrl = "";
|
|
84
90
|
let fileSuffix = videoSuffix;
|
|
85
91
|
let fileType = "1";
|
|
86
92
|
let videoPlayInfo;
|
|
93
|
+
let shouldRevoke = false;
|
|
87
94
|
if (url instanceof File) {
|
|
88
95
|
videoUrl = URL.createObjectURL(url);
|
|
96
|
+
shouldRevoke = true;
|
|
89
97
|
fileSuffix = getFileSuffix(url.name);
|
|
90
98
|
fileType = checkFileType(url.name);
|
|
91
99
|
} else if (url instanceof Blob) {
|
|
92
100
|
videoUrl = URL.createObjectURL(url);
|
|
101
|
+
shouldRevoke = true;
|
|
93
102
|
fileType = checkFileType(url);
|
|
94
|
-
} else if (
|
|
103
|
+
} else if (isMediaDataURI(url)) {
|
|
95
104
|
videoUrl = url;
|
|
96
105
|
fileType = checkFileType(url);
|
|
97
106
|
} else if (url.includes("https") || url.includes("http")) {
|
|
@@ -99,16 +108,25 @@ async function getVideoCoverPicture(videoInfo) {
|
|
|
99
108
|
fileSuffix = getFileSuffix(url);
|
|
100
109
|
fileType = checkFileType(url);
|
|
101
110
|
}
|
|
102
|
-
if (fileSuffix ? fileTypes.videoAllowType.includes(fileSuffix.toLowerCase()) : false) if (videoAllowPlay)
|
|
103
|
-
|
|
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 {
|
|
104
116
|
videoPlayInfo = await getMediaInfos({
|
|
105
117
|
url: videoUrl,
|
|
106
118
|
fileType
|
|
107
119
|
});
|
|
108
|
-
if (videoPlayInfo.play)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
+
}
|
|
112
130
|
}
|
|
113
131
|
else return new Promise((resolve) => {
|
|
114
132
|
resolve("");
|
|
@@ -122,6 +140,7 @@ async function getVideoCoverPicture(videoInfo) {
|
|
|
122
140
|
* @returns 截图 base64
|
|
123
141
|
*/
|
|
124
142
|
async function generateVideoPicture(videoUrl, currentTime = 0) {
|
|
143
|
+
if (isServer) return "";
|
|
125
144
|
return new Promise((resolve) => {
|
|
126
145
|
let video = document.createElement("video");
|
|
127
146
|
if (video) {
|
|
@@ -142,11 +161,11 @@ async function generateVideoPicture(videoUrl, currentTime = 0) {
|
|
|
142
161
|
const canvas = document.createElement("canvas");
|
|
143
162
|
const scale = .8;
|
|
144
163
|
const ctx = canvas.getContext("2d");
|
|
145
|
-
const w = video?.videoWidth || 0 * scale;
|
|
146
|
-
const h = video?.videoHeight || 0 * scale;
|
|
164
|
+
const w = (video?.videoWidth || 0) * scale;
|
|
165
|
+
const h = (video?.videoHeight || 0) * scale;
|
|
147
166
|
const space = 0;
|
|
148
|
-
canvas.width = video?.videoWidth || 0 * scale;
|
|
149
|
-
canvas.height = video?.videoHeight || 0 * scale;
|
|
167
|
+
canvas.width = (video?.videoWidth || 0) * scale;
|
|
168
|
+
canvas.height = (video?.videoHeight || 0) * scale;
|
|
150
169
|
if (video) ctx.drawImage(video, 0, 0, w + space, h + space);
|
|
151
170
|
video = null;
|
|
152
171
|
resolve(w === 0 || h === 0 ? "" : canvas.toDataURL("image/png", 1));
|
package/dist/dom/raf.d.ts
CHANGED
package/dist/dom/raf.js
CHANGED
package/dist/dom/scroll.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isServer } from "../is/server.js";
|
|
2
|
-
import "
|
|
3
|
-
import wrapperRaf from "./raf.js";
|
|
2
|
+
import { wrapperRaf } from "./raf.js";
|
|
4
3
|
//#region src/dom/scroll.ts
|
|
5
4
|
function easeInOutCubic(t, b, c, d) {
|
|
6
5
|
const cc = c - b;
|
|
@@ -76,8 +75,9 @@ function getScroll(target, top) {
|
|
|
76
75
|
return result;
|
|
77
76
|
}
|
|
78
77
|
function scrollTo(y, options = {}) {
|
|
79
|
-
const { getContainer
|
|
80
|
-
const container = getContainer();
|
|
78
|
+
const { getContainer, callback, duration = 450 } = options;
|
|
79
|
+
const container = getContainer?.() ?? (isServer ? void 0 : window);
|
|
80
|
+
if (isServer || !container) return;
|
|
81
81
|
const scrollTop = getScroll(container, true);
|
|
82
82
|
const startTime = Date.now();
|
|
83
83
|
const frameFunc = () => {
|
|
@@ -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 };
|
|
@@ -1,52 +1,50 @@
|
|
|
1
|
-
//#region src/base64
|
|
1
|
+
//#region src/encoding/base64.ts
|
|
2
|
+
const BASE64_KEY_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
2
3
|
/**
|
|
3
4
|
* Base64 编解码类
|
|
4
5
|
*/
|
|
5
6
|
var Base64 = class {
|
|
6
7
|
_keyStr;
|
|
7
8
|
constructor() {
|
|
8
|
-
this._keyStr =
|
|
9
|
+
this._keyStr = BASE64_KEY_STR;
|
|
9
10
|
}
|
|
10
11
|
_utf8_encode(string) {
|
|
11
12
|
string = string.replace(/\r\n/g, "\n");
|
|
12
|
-
|
|
13
|
+
const utftext = [];
|
|
13
14
|
for (let n = 0; n < string.length; n++) {
|
|
14
15
|
const c = string.charCodeAt(n);
|
|
15
|
-
if (c < 128) utftext
|
|
16
|
+
if (c < 128) utftext.push(c);
|
|
16
17
|
else if (c > 127 && c < 2048) {
|
|
17
|
-
utftext
|
|
18
|
-
utftext
|
|
18
|
+
utftext.push(c >> 6 | 192);
|
|
19
|
+
utftext.push(c & 63 | 128);
|
|
19
20
|
} else {
|
|
20
|
-
utftext
|
|
21
|
-
utftext
|
|
22
|
-
utftext
|
|
21
|
+
utftext.push(c >> 12 | 224);
|
|
22
|
+
utftext.push(c >> 6 & 63 | 128);
|
|
23
|
+
utftext.push(c & 63 | 128);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
return utftext;
|
|
26
|
+
return String.fromCharCode(...utftext);
|
|
26
27
|
}
|
|
27
28
|
_utf8_decode(utftext) {
|
|
28
|
-
|
|
29
|
+
const chars = [];
|
|
29
30
|
let i = 0;
|
|
30
|
-
let c = 0;
|
|
31
|
-
let c1 = 0;
|
|
32
|
-
let c2 = 0;
|
|
33
31
|
while (i < utftext.length) {
|
|
34
|
-
c = utftext.charCodeAt(i);
|
|
32
|
+
const c = utftext.charCodeAt(i);
|
|
35
33
|
if (c < 128) {
|
|
36
|
-
|
|
34
|
+
chars.push(c);
|
|
37
35
|
i++;
|
|
38
36
|
} else if (c > 191 && c < 224) {
|
|
39
|
-
c1 = utftext.charCodeAt(i + 1);
|
|
40
|
-
|
|
37
|
+
const c1 = utftext.charCodeAt(i + 1);
|
|
38
|
+
chars.push((c & 31) << 6 | c1 & 63);
|
|
41
39
|
i += 2;
|
|
42
40
|
} else {
|
|
43
|
-
c1 = utftext.charCodeAt(i + 1);
|
|
44
|
-
c2 = utftext.charCodeAt(i + 2);
|
|
45
|
-
|
|
41
|
+
const c1 = utftext.charCodeAt(i + 1);
|
|
42
|
+
const c2 = utftext.charCodeAt(i + 2);
|
|
43
|
+
chars.push((c & 15) << 12 | (c1 & 63) << 6 | c2 & 63);
|
|
46
44
|
i += 3;
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
|
-
return
|
|
47
|
+
return String.fromCharCode(...chars);
|
|
50
48
|
}
|
|
51
49
|
/**
|
|
52
50
|
* 加密方法
|
|
@@ -55,7 +53,7 @@ var Base64 = class {
|
|
|
55
53
|
* @returns Base64 编码后的字符串
|
|
56
54
|
*/
|
|
57
55
|
encode(input) {
|
|
58
|
-
|
|
56
|
+
const output = [];
|
|
59
57
|
let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
|
60
58
|
let i = 0;
|
|
61
59
|
input = this._utf8_encode(input);
|
|
@@ -69,9 +67,9 @@ var Base64 = class {
|
|
|
69
67
|
enc4 = chr3 & 63;
|
|
70
68
|
if (Number.isNaN(chr2)) enc3 = enc4 = 64;
|
|
71
69
|
else if (Number.isNaN(chr3)) enc4 = 64;
|
|
72
|
-
output
|
|
70
|
+
output.push(this._keyStr.charAt(enc1), this._keyStr.charAt(enc2), this._keyStr.charAt(enc3), this._keyStr.charAt(enc4));
|
|
73
71
|
}
|
|
74
|
-
return output;
|
|
72
|
+
return output.join("");
|
|
75
73
|
}
|
|
76
74
|
/**
|
|
77
75
|
* 解密方法
|
|
@@ -80,7 +78,7 @@ var Base64 = class {
|
|
|
80
78
|
* @returns 解码后的字符串
|
|
81
79
|
*/
|
|
82
80
|
decode(input) {
|
|
83
|
-
|
|
81
|
+
const output = [];
|
|
84
82
|
let chr1, chr2, chr3;
|
|
85
83
|
let enc1, enc2, enc3, enc4;
|
|
86
84
|
let i = 0;
|
|
@@ -93,13 +91,12 @@ var Base64 = class {
|
|
|
93
91
|
chr1 = enc1 << 2 | enc2 >> 4;
|
|
94
92
|
chr2 = (enc2 & 15) << 4 | enc3 >> 2;
|
|
95
93
|
chr3 = (enc3 & 3) << 6 | enc4;
|
|
96
|
-
output
|
|
97
|
-
if (enc3 !== 64) output
|
|
98
|
-
if (enc4 !== 64) output
|
|
94
|
+
output.push(chr1);
|
|
95
|
+
if (enc3 !== 64) output.push(chr2);
|
|
96
|
+
if (enc4 !== 64) output.push(chr3);
|
|
99
97
|
}
|
|
100
|
-
|
|
101
|
-
return output;
|
|
98
|
+
return this._utf8_decode(String.fromCharCode(...output));
|
|
102
99
|
}
|
|
103
100
|
};
|
|
104
101
|
//#endregion
|
|
105
|
-
export { Base64 as default };
|
|
102
|
+
export { Base64, Base64 as default };
|