@gx-design-vue/pro-utils 0.2.0-beta.86 → 0.2.0-beta.88

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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -2
  3. package/dist/array/index.d.ts +5 -0
  4. package/dist/array/index.js +6 -0
  5. package/dist/array/slice.d.ts +4 -0
  6. package/dist/array/slice.js +28 -0
  7. package/dist/array/sort.d.ts +7 -0
  8. package/dist/array/sort.js +65 -0
  9. package/dist/array/tree.d.ts +25 -0
  10. package/dist/array/tree.js +157 -0
  11. package/dist/array/unique.d.ts +6 -0
  12. package/dist/array/unique.js +14 -0
  13. package/dist/base64/index.d.ts +10 -19
  14. package/dist/base64/index.js +106 -0
  15. package/dist/class/index.d.ts +2 -0
  16. package/dist/class/index.js +3 -0
  17. package/dist/class/prefix.d.ts +15 -0
  18. package/dist/class/prefix.js +15 -0
  19. package/dist/clone/cloneDeep.d.ts +4 -0
  20. package/dist/clone/cloneDeep.js +35 -0
  21. package/dist/clone/cloneDeepWith.d.ts +6 -0
  22. package/dist/clone/cloneDeepWith.js +150 -0
  23. package/dist/clone/getTag.d.ts +4 -0
  24. package/dist/clone/getTag.js +13 -0
  25. package/dist/clone/index.d.ts +3 -0
  26. package/dist/clone/index.js +4 -0
  27. package/dist/clone/symbols.d.ts +4 -0
  28. package/dist/clone/symbols.js +13 -0
  29. package/dist/clone/tags.d.ts +25 -0
  30. package/dist/clone/tags.js +48 -0
  31. package/dist/dom/event.d.ts +5 -0
  32. package/dist/dom/event.js +26 -0
  33. package/dist/dom/index.d.ts +5 -0
  34. package/dist/dom/index.js +6 -0
  35. package/dist/dom/measure.d.ts +12 -0
  36. package/dist/dom/measure.js +42 -0
  37. package/dist/dom/raf.d.ts +7 -0
  38. package/dist/dom/raf.js +44 -0
  39. package/dist/dom/scroll.d.ts +10 -0
  40. package/dist/dom/scroll.js +74 -0
  41. package/dist/file/config.d.ts +10 -0
  42. package/dist/file/config.js +81 -0
  43. package/dist/file/convert.d.ts +8 -0
  44. package/dist/file/convert.js +69 -0
  45. package/dist/file/index.d.ts +5 -0
  46. package/dist/file/index.js +6 -0
  47. package/dist/file/media.d.ts +16 -0
  48. package/dist/file/media.js +161 -0
  49. package/dist/file/type.d.ts +6 -0
  50. package/dist/file/type.js +58 -0
  51. package/dist/function/copy.d.ts +6 -0
  52. package/dist/function/copy.js +13 -0
  53. package/dist/function/getValue.d.ts +5 -0
  54. package/dist/function/getValue.js +19 -0
  55. package/dist/function/index.d.ts +5 -0
  56. package/dist/function/index.js +6 -0
  57. package/dist/function/object.d.ts +6 -0
  58. package/dist/function/object.js +33 -0
  59. package/dist/function/run.d.ts +4 -0
  60. package/dist/function/run.js +15 -0
  61. package/dist/index.d.ts +58 -26
  62. package/dist/index.js +60 -0
  63. package/dist/is/base64.d.ts +5 -0
  64. package/dist/is/base64.js +27 -0
  65. package/dist/is/browser.d.ts +4 -0
  66. package/dist/is/browser.js +14 -0
  67. package/dist/is/deepEqual.d.ts +4 -0
  68. package/dist/is/deepEqual.js +62 -0
  69. package/dist/is/device.d.ts +6 -0
  70. package/dist/is/device.js +37 -0
  71. package/dist/is/equal.d.ts +4 -0
  72. package/dist/is/equal.js +34 -0
  73. package/dist/is/img.d.ts +4 -0
  74. package/dist/is/img.js +13 -0
  75. package/dist/is/index.d.ts +16 -0
  76. package/dist/is/index.js +17 -0
  77. package/dist/is/nil.d.ts +5 -0
  78. package/dist/is/nil.js +22 -0
  79. package/dist/is/plainObject.d.ts +5 -0
  80. package/dist/is/plainObject.js +30 -0
  81. package/dist/is/primitive.d.ts +4 -0
  82. package/dist/is/primitive.js +13 -0
  83. package/dist/is/server.d.ts +4 -0
  84. package/dist/is/server.js +10 -0
  85. package/dist/is/type.d.ts +11 -0
  86. package/dist/is/type.js +84 -0
  87. package/dist/is/typedArray.d.ts +4 -0
  88. package/dist/is/typedArray.js +33 -0
  89. package/dist/is/unsafeProperty.d.ts +4 -0
  90. package/dist/is/unsafeProperty.js +18 -0
  91. package/dist/is/url.d.ts +4 -0
  92. package/dist/is/url.js +20 -0
  93. package/dist/is/valid.d.ts +5 -0
  94. package/dist/is/valid.js +23 -0
  95. package/dist/merge/index.d.ts +6 -49
  96. package/dist/merge/index.js +41 -0
  97. package/dist/merge/mergeWith.d.ts +4 -49
  98. package/dist/merge/mergeWith.js +31 -0
  99. package/dist/number/chinese.d.ts +4 -0
  100. package/dist/number/chinese.js +46 -0
  101. package/dist/number/format.d.ts +13 -0
  102. package/dist/number/format.js +72 -0
  103. package/dist/number/index.d.ts +3 -0
  104. package/dist/number/index.js +4 -0
  105. package/dist/object/classNames.d.ts +4 -0
  106. package/dist/object/classNames.js +30 -0
  107. package/dist/object/index.d.ts +5 -0
  108. package/dist/object/index.js +6 -0
  109. package/dist/object/omitBoolean.d.ts +4 -0
  110. package/dist/object/omitBoolean.js +13 -0
  111. package/dist/object/omitUndefined.d.ts +6 -0
  112. package/dist/object/omitUndefined.js +18 -0
  113. package/dist/object/omitUndefinedAndEmptyArr.d.ts +4 -0
  114. package/dist/object/omitUndefinedAndEmptyArr.js +19 -0
  115. package/dist/pro-utils.js +1 -1166
  116. package/dist/string/duration.d.ts +4 -0
  117. package/dist/string/duration.js +25 -0
  118. package/dist/string/empty.d.ts +7 -0
  119. package/dist/string/empty.js +26 -0
  120. package/dist/string/index.d.ts +5 -0
  121. package/dist/string/index.js +6 -0
  122. package/dist/string/nanoid.d.ts +4 -0
  123. package/dist/string/nanoid.js +32 -0
  124. package/dist/string/uuid.d.ts +9 -0
  125. package/dist/string/uuid.js +57 -0
  126. package/dist/table/column.d.ts +13 -0
  127. package/dist/table/column.js +42 -0
  128. package/dist/table/index.d.ts +3 -0
  129. package/dist/table/index.js +4 -0
  130. package/dist/table/page.d.ts +6 -0
  131. package/dist/table/page.js +23 -0
  132. package/dist/typing.d.ts +37 -0
  133. package/dist/typing.js +1 -0
  134. package/dist/vue/index.d.ts +2 -0
  135. package/dist/vue/index.js +3 -0
  136. package/dist/vue/slots.d.ts +56 -0
  137. package/dist/vue/slots.js +89 -0
  138. package/package.json +48 -23
  139. package/dist/classNames/index.d.ts +0 -2
  140. package/dist/cloneDeep/cloneDeepWith.d.ts +0 -43
  141. package/dist/cloneDeep/index.d.ts +0 -47
  142. package/dist/getValueFromObjectByKey/index.d.ts +0 -3
  143. package/dist/isBrowser/index.d.ts +0 -1
  144. package/dist/isDeepEqualReact/index.d.ts +0 -1
  145. package/dist/isImg/index.d.ts +0 -2
  146. package/dist/isNil/index.d.ts +0 -1
  147. package/dist/isServer.d.ts +0 -2
  148. package/dist/isUrl/index.d.ts +0 -6
  149. package/dist/merge/useDeepMege.d.ts +0 -43
  150. package/dist/nanoid/index.d.ts +0 -6
  151. package/dist/omitBoolean/index.d.ts +0 -6
  152. package/dist/omitUndefined/index.d.ts +0 -2
  153. package/dist/omitUndefinedAndEmptyArr/index.d.ts +0 -1
  154. package/dist/pro-utils.umd.cjs +0 -13
  155. package/dist/scroll/easings.d.ts +0 -1
  156. package/dist/scroll/getScroll.d.ts +0 -2
  157. package/dist/scroll/index.d.ts +0 -4
  158. package/dist/scroll/scrollTo.d.ts +0 -10
  159. package/dist/scroll/throttleByAnimationFrame.d.ts +0 -5
  160. package/dist/slots/index.d.ts +0 -68
  161. package/dist/typings/index.d.ts +0 -40
  162. package/dist/utils/config.d.ts +0 -7
  163. package/dist/utils/getSymbols.d.ts +0 -1
  164. package/dist/utils/getTag.d.ts +0 -8
  165. package/dist/utils/index.d.ts +0 -333
  166. package/dist/utils/isEqual.d.ts +0 -9
  167. package/dist/utils/isNotNil.d.ts +0 -1
  168. package/dist/utils/isPlainObject.d.ts +0 -43
  169. package/dist/utils/isPrimitive.d.ts +0 -29
  170. package/dist/utils/isTypedArray.d.ts +0 -27
  171. package/dist/utils/isUnsafeProperty.d.ts +0 -11
  172. package/dist/utils/isValid.d.ts +0 -2
  173. package/dist/utils/raf.d.ts +0 -5
  174. package/dist/utils/tags.d.ts +0 -26
  175. package/dist/utils/validate.d.ts +0 -28
@@ -0,0 +1,150 @@
1
+ import { isPrimitive } from "../is/primitive.js";
2
+ import { isTypedArray } from "../is/typedArray.js";
3
+ import "../is/index.js";
4
+ import { getTag } from "./getTag.js";
5
+ import { getSymbols } from "./symbols.js";
6
+ 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
+ //#region src/clone/cloneDeepWith.ts
9
+ /**
10
+ * 深度克隆对象(带自定义处理)
11
+ *
12
+ * @template T - 对象类型
13
+ * @param obj - 要克隆的对象
14
+ * @param cloneValue - 自定义克隆函数
15
+ * @returns 克隆后的对象
16
+ */
17
+ function cloneDeepWith(obj, cloneValue) {
18
+ return cloneDeepWithImpl(obj, void 0, obj, /* @__PURE__ */ new Map(), cloneValue);
19
+ }
20
+ function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = /* @__PURE__ */ new Map(), cloneValue = void 0) {
21
+ const cloned = cloneValue?.(valueToClone, keyToClone, objectToClone, stack);
22
+ if (cloned !== void 0) return cloned;
23
+ if (isPrimitive(valueToClone)) return valueToClone;
24
+ if (stack.has(valueToClone)) return stack.get(valueToClone);
25
+ if (Array.isArray(valueToClone)) {
26
+ const result = Array.from({ length: valueToClone.length });
27
+ stack.set(valueToClone, result);
28
+ for (let i = 0; i < valueToClone.length; i++) result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
29
+ if (Object.hasOwn(valueToClone, "index")) result.index = valueToClone.index;
30
+ if (Object.hasOwn(valueToClone, "input")) result.input = valueToClone.input;
31
+ return result;
32
+ }
33
+ if (valueToClone instanceof Date) return new Date(valueToClone.getTime());
34
+ if (valueToClone instanceof RegExp) {
35
+ const result = new RegExp(valueToClone.source, valueToClone.flags);
36
+ result.lastIndex = valueToClone.lastIndex;
37
+ return result;
38
+ }
39
+ if (valueToClone instanceof Map) {
40
+ const result = /* @__PURE__ */ new Map();
41
+ stack.set(valueToClone, result);
42
+ for (const [key, value] of valueToClone) result.set(key, cloneDeepWithImpl(value, key, objectToClone, stack, cloneValue));
43
+ return result;
44
+ }
45
+ if (valueToClone instanceof Set) {
46
+ const result = /* @__PURE__ */ new Set();
47
+ stack.set(valueToClone, result);
48
+ for (const value of valueToClone) result.add(cloneDeepWithImpl(value, void 0, objectToClone, stack, cloneValue));
49
+ return result;
50
+ }
51
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(valueToClone)) return valueToClone.subarray();
52
+ if (isTypedArray(valueToClone)) {
53
+ const result = new (Object.getPrototypeOf(valueToClone)).constructor(valueToClone.length);
54
+ stack.set(valueToClone, result);
55
+ for (let i = 0; i < valueToClone.length; i++) result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
56
+ return result;
57
+ }
58
+ if (valueToClone instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && valueToClone instanceof SharedArrayBuffer) return valueToClone.slice(0);
59
+ if (valueToClone instanceof DataView) {
60
+ const result = new DataView(valueToClone.buffer.slice(0), valueToClone.byteOffset, valueToClone.byteLength);
61
+ stack.set(valueToClone, result);
62
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
63
+ return result;
64
+ }
65
+ if (typeof File !== "undefined" && valueToClone instanceof File) {
66
+ const result = new File([valueToClone], valueToClone.name, { type: valueToClone.type });
67
+ stack.set(valueToClone, result);
68
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
69
+ return result;
70
+ }
71
+ if (typeof Blob !== "undefined" && valueToClone instanceof Blob) {
72
+ const result = new Blob([valueToClone], { type: valueToClone.type });
73
+ stack.set(valueToClone, result);
74
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
75
+ return result;
76
+ }
77
+ if (valueToClone instanceof Error) {
78
+ const result = new valueToClone.constructor();
79
+ stack.set(valueToClone, result);
80
+ result.message = valueToClone.message;
81
+ result.name = valueToClone.name;
82
+ result.stack = valueToClone.stack;
83
+ result.cause = valueToClone.cause;
84
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
85
+ return result;
86
+ }
87
+ if (typeof valueToClone === "boolean") {
88
+ const result = Boolean(valueToClone.valueOf());
89
+ stack.set(valueToClone, result);
90
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
91
+ return result;
92
+ }
93
+ if (typeof valueToClone === "number") {
94
+ const result = Number(valueToClone.valueOf());
95
+ stack.set(valueToClone, result);
96
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
97
+ return result;
98
+ }
99
+ if (typeof valueToClone === "string") {
100
+ const result = String(valueToClone.valueOf());
101
+ stack.set(valueToClone, result);
102
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
103
+ return result;
104
+ }
105
+ if (typeof valueToClone === "object" && isCloneableObject(valueToClone)) {
106
+ const result = Object.create(Object.getPrototypeOf(valueToClone));
107
+ stack.set(valueToClone, result);
108
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
109
+ return result;
110
+ }
111
+ return valueToClone;
112
+ }
113
+ function copyProperties(target, source, objectToClone = target, stack, cloneValue) {
114
+ const keys = [...Object.keys(source), ...getSymbols(source)];
115
+ for (let i = 0; i < keys.length; i++) {
116
+ const key = keys[i];
117
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
118
+ if (descriptor == null || descriptor.writable) target[key] = cloneDeepWithImpl(source[key], key, objectToClone, stack, cloneValue);
119
+ }
120
+ }
121
+ function isCloneableObject(object) {
122
+ switch (getTag(object)) {
123
+ case argumentsTag:
124
+ case arrayTag:
125
+ case arrayBufferTag:
126
+ case dataViewTag:
127
+ case booleanTag:
128
+ case dateTag:
129
+ case float32ArrayTag:
130
+ case float64ArrayTag:
131
+ case int8ArrayTag:
132
+ case int16ArrayTag:
133
+ case int32ArrayTag:
134
+ case mapTag:
135
+ case numberTag:
136
+ case objectTag:
137
+ case regexpTag:
138
+ case setTag:
139
+ case stringTag:
140
+ case symbolTag:
141
+ case uint8ArrayTag:
142
+ case uint8ClampedArrayTag:
143
+ case uint16ArrayTag:
144
+ case uint32ArrayTag: return true;
145
+ default: return false;
146
+ }
147
+ }
148
+
149
+ //#endregion
150
+ export { cloneDeepWith, cloneDeepWithImpl, copyProperties };
@@ -0,0 +1,4 @@
1
+ //#region src/clone/getTag.d.ts
2
+ declare function getTag(value: any): string;
3
+ //#endregion
4
+ export { getTag };
@@ -0,0 +1,13 @@
1
+ //#region src/clone/getTag.ts
2
+ /**
3
+ * 获取对象的类型标签
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 类型标签
7
+ */
8
+ function getTag(value) {
9
+ return Object.prototype.toString.call(value);
10
+ }
11
+
12
+ //#endregion
13
+ export { getTag };
@@ -0,0 +1,3 @@
1
+ import { cloneDeep } from "./cloneDeep.js";
2
+ import { cloneDeepWith, cloneDeepWithImpl, copyProperties } from "./cloneDeepWith.js";
3
+ export { cloneDeep, cloneDeepWith, cloneDeepWithImpl, copyProperties };
@@ -0,0 +1,4 @@
1
+ import { cloneDeepWith, cloneDeepWithImpl, copyProperties } from "./cloneDeepWith.js";
2
+ import { cloneDeep } from "./cloneDeep.js";
3
+
4
+ export { cloneDeep, cloneDeepWith, cloneDeepWithImpl, copyProperties };
@@ -0,0 +1,4 @@
1
+ //#region src/clone/symbols.d.ts
2
+ declare function getSymbols(object: any): symbol[];
3
+ //#endregion
4
+ export { getSymbols };
@@ -0,0 +1,13 @@
1
+ //#region src/clone/symbols.ts
2
+ /**
3
+ * 获取对象的 Symbol 属性
4
+ *
5
+ * @param object - 目标对象
6
+ * @returns Symbol 属性数组
7
+ */
8
+ function getSymbols(object) {
9
+ return Object.getOwnPropertySymbols(object);
10
+ }
11
+
12
+ //#endregion
13
+ export { getSymbols };
@@ -0,0 +1,25 @@
1
+ //#region src/clone/tags.d.ts
2
+ declare const argumentsTag = "[object Arguments]";
3
+ declare const arrayTag = "[object Array]";
4
+ declare const arrayBufferTag = "[object ArrayBuffer]";
5
+ declare const booleanTag = "[object Boolean]";
6
+ declare const dataViewTag = "[object DataView]";
7
+ declare const dateTag = "[object Date]";
8
+ declare const float32ArrayTag = "[object Float32Array]";
9
+ declare const float64ArrayTag = "[object Float64Array]";
10
+ declare const int8ArrayTag = "[object Int8Array]";
11
+ declare const int16ArrayTag = "[object Int16Array]";
12
+ declare const int32ArrayTag = "[object Int32Array]";
13
+ declare const mapTag = "[object Map]";
14
+ declare const numberTag = "[object Number]";
15
+ declare const objectTag = "[object Object]";
16
+ declare const regexpTag = "[object RegExp]";
17
+ declare const setTag = "[object Set]";
18
+ declare const stringTag = "[object String]";
19
+ declare const symbolTag = "[object Symbol]";
20
+ declare const uint8ArrayTag = "[object Uint8Array]";
21
+ declare const uint8ClampedArrayTag = "[object Uint8ClampedArray]";
22
+ declare const uint16ArrayTag = "[object Uint16Array]";
23
+ declare const uint32ArrayTag = "[object Uint32Array]";
24
+ //#endregion
25
+ export { argumentsTag, arrayBufferTag, arrayTag, booleanTag, dataViewTag, dateTag, float32ArrayTag, float64ArrayTag, int16ArrayTag, int32ArrayTag, int8ArrayTag, mapTag, numberTag, objectTag, regexpTag, setTag, stringTag, symbolTag, uint16ArrayTag, uint32ArrayTag, uint8ArrayTag, uint8ClampedArrayTag };
@@ -0,0 +1,48 @@
1
+ //#region src/clone/tags.ts
2
+ /** 参数标签 */
3
+ const argumentsTag = "[object Arguments]";
4
+ /** 数组标签 */
5
+ const arrayTag = "[object Array]";
6
+ /** 数组缓冲区标签 */
7
+ const arrayBufferTag = "[object ArrayBuffer]";
8
+ /** 布尔标签 */
9
+ const booleanTag = "[object Boolean]";
10
+ /** 数据视图标签 */
11
+ const dataViewTag = "[object DataView]";
12
+ /** 日期标签 */
13
+ const dateTag = "[object Date]";
14
+ /** Float32 数组标签 */
15
+ const float32ArrayTag = "[object Float32Array]";
16
+ /** Float64 数组标签 */
17
+ const float64ArrayTag = "[object Float64Array]";
18
+ /** Int8 数组标签 */
19
+ const int8ArrayTag = "[object Int8Array]";
20
+ /** Int16 数组标签 */
21
+ const int16ArrayTag = "[object Int16Array]";
22
+ /** Int32 数组标签 */
23
+ const int32ArrayTag = "[object Int32Array]";
24
+ /** Map 标签 */
25
+ const mapTag = "[object Map]";
26
+ /** 数字标签 */
27
+ const numberTag = "[object Number]";
28
+ /** 对象标签 */
29
+ const objectTag = "[object Object]";
30
+ /** 正则标签 */
31
+ const regexpTag = "[object RegExp]";
32
+ /** Set 标签 */
33
+ const setTag = "[object Set]";
34
+ /** 字符串标签 */
35
+ const stringTag = "[object String]";
36
+ /** Symbol 标签 */
37
+ const symbolTag = "[object Symbol]";
38
+ /** Uint8 数组标签 */
39
+ const uint8ArrayTag = "[object Uint8Array]";
40
+ /** Uint8Clamped 数组标签 */
41
+ const uint8ClampedArrayTag = "[object Uint8ClampedArray]";
42
+ /** Uint16 数组标签 */
43
+ const uint16ArrayTag = "[object Uint16Array]";
44
+ /** Uint32 数组标签 */
45
+ const uint32ArrayTag = "[object Uint32Array]";
46
+
47
+ //#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 };
@@ -0,0 +1,5 @@
1
+ //#region src/dom/event.d.ts
2
+ declare function on(element: HTMLElement | Document | Window | null, event: string, handler: EventListenerOrEventListenerObject, useCapture?: boolean): void;
3
+ declare function off(element: HTMLElement | Document | Window | null, event: string, handler: EventListenerOrEventListenerObject, useCapture?: boolean): void;
4
+ //#endregion
5
+ export { off, on };
@@ -0,0 +1,26 @@
1
+ //#region src/dom/event.ts
2
+ /**
3
+ * 绑定事件
4
+ *
5
+ * @param element - DOM 元素
6
+ * @param event - 事件名
7
+ * @param handler - 事件处理函数
8
+ * @param useCapture - 是否捕获阶段
9
+ */
10
+ function on(element, event, handler, useCapture = false) {
11
+ if (element && event && handler) element.addEventListener(event, handler, useCapture);
12
+ }
13
+ /**
14
+ * 解绑事件
15
+ *
16
+ * @param element - DOM 元素
17
+ * @param event - 事件名
18
+ * @param handler - 事件处理函数
19
+ * @param useCapture - 是否捕获阶段
20
+ */
21
+ function off(element, event, handler, useCapture = false) {
22
+ if (element && event && handler) element.removeEventListener(event, handler, useCapture);
23
+ }
24
+
25
+ //#endregion
26
+ export { off, on };
@@ -0,0 +1,5 @@
1
+ import { off, on } from "./event.js";
2
+ import { getTextWidth } from "./measure.js";
3
+ import wrapperRaf from "./raf.js";
4
+ import { getScroll, getScrollContainer, isInContainer, isScroll, isWindow } from "./scroll.js";
5
+ export { getScroll, getScrollContainer, getTextWidth, isInContainer, isScroll, isWindow, off, on, wrapperRaf as raf };
@@ -0,0 +1,6 @@
1
+ import { off, on } from "./event.js";
2
+ import { getTextWidth } from "./measure.js";
3
+ import wrapperRaf from "./raf.js";
4
+ import { getScroll, getScrollContainer, isInContainer, isScroll, isWindow } from "./scroll.js";
5
+
6
+ export { getScroll, getScrollContainer, getTextWidth, isInContainer, isScroll, isWindow, off, on, wrapperRaf as raf };
@@ -0,0 +1,12 @@
1
+ import { CSSProperties } from "vue";
2
+
3
+ //#region src/dom/measure.d.ts
4
+ declare function getTextWidth(str: string, options: {
5
+ id?: string;
6
+ type?: 'width' | 'height';
7
+ createName?: string;
8
+ removeAfter?: boolean;
9
+ cssObject?: CSSProperties;
10
+ }): number;
11
+ //#endregion
12
+ export { getTextWidth };
@@ -0,0 +1,42 @@
1
+ import { isBoolean, isObject } from "../is/type.js";
2
+ import "../is/index.js";
3
+
4
+ //#region src/dom/measure.ts
5
+ /**
6
+ * 获取文字宽度或高度
7
+ *
8
+ * @param str - 文字内容
9
+ * @param options - 配置选项
10
+ * @returns 宽度或高度
11
+ */
12
+ function getTextWidth(str, options) {
13
+ let number = 0;
14
+ const removeAfter = isBoolean(options.removeAfter) ? options.removeAfter : true;
15
+ const targetElId = options.id || "hiddenElement";
16
+ const targetElStyle = {
17
+ opacity: 0,
18
+ visibility: "hidden",
19
+ position: "fixed",
20
+ zIndex: -1,
21
+ top: 0,
22
+ left: 0
23
+ };
24
+ let targetEl = document.querySelector(`#${targetElId}`);
25
+ if (!targetEl) {
26
+ const el = document.createElement("div");
27
+ el.id = targetElId;
28
+ document.body.appendChild(el);
29
+ targetEl = document.querySelector(`#${targetElId}`);
30
+ }
31
+ Object.assign(targetEl.style, targetElStyle);
32
+ const sourceEl = document.createElement(options.createName || "span");
33
+ sourceEl.innerHTML = str;
34
+ if (options.cssObject || isObject(options.cssObject)) Object.assign(sourceEl.style, options.cssObject);
35
+ targetEl.append(sourceEl);
36
+ number = sourceEl.getBoundingClientRect()[options.type || "width"];
37
+ if (removeAfter) targetEl.removeChild(sourceEl);
38
+ return number;
39
+ }
40
+
41
+ //#endregion
42
+ export { getTextWidth };
@@ -0,0 +1,7 @@
1
+ //#region src/dom/raf.d.ts
2
+ declare function wrapperRaf(callback: () => void, times?: number): number;
3
+ declare namespace wrapperRaf {
4
+ var cancel: (id: number) => void;
5
+ }
6
+ //#endregion
7
+ export { wrapperRaf as default };
@@ -0,0 +1,44 @@
1
+ //#region src/dom/raf.ts
2
+ let raf = (callback) => setTimeout(callback, 16);
3
+ let caf = (num) => clearTimeout(num);
4
+ if (typeof window !== "undefined" && "requestAnimationFrame" in window) {
5
+ raf = (callback) => window.requestAnimationFrame(callback);
6
+ caf = (handle) => window.cancelAnimationFrame(handle);
7
+ }
8
+ let rafUUID = 0;
9
+ const rafIds = /* @__PURE__ */ new Map();
10
+ function cleanup(id) {
11
+ rafIds.delete(id);
12
+ }
13
+ /**
14
+ * requestAnimationFrame 封装
15
+ *
16
+ * @param callback - 回调函数
17
+ * @param times - 执行次数
18
+ * @returns 任务 ID
19
+ */
20
+ function wrapperRaf(callback, times = 1) {
21
+ rafUUID += 1;
22
+ const id = rafUUID;
23
+ function callRef(leftTimes) {
24
+ if (leftTimes === 0) {
25
+ cleanup(id);
26
+ callback();
27
+ } else {
28
+ const realId = raf(() => {
29
+ callRef(leftTimes - 1);
30
+ });
31
+ rafIds.set(id, realId);
32
+ }
33
+ }
34
+ callRef(times);
35
+ return id;
36
+ }
37
+ wrapperRaf.cancel = (id) => {
38
+ const realId = rafIds.get(id);
39
+ cleanup(realId);
40
+ return caf(realId);
41
+ };
42
+
43
+ //#endregion
44
+ export { wrapperRaf as default };
@@ -0,0 +1,10 @@
1
+ import { Nullable } from "../typing.js";
2
+
3
+ //#region src/dom/scroll.d.ts
4
+ declare function isScroll(el: HTMLElement, isVertical?: Nullable<boolean>): RegExpMatchArray | null | undefined;
5
+ declare function getScrollContainer(el: HTMLElement, isVertical?: Nullable<boolean>): (Window & typeof globalThis) | HTMLElement | undefined;
6
+ declare function isInContainer(el: HTMLElement, container: HTMLElement): boolean;
7
+ declare function isWindow(obj: any): boolean;
8
+ declare function getScroll(target: HTMLElement | Window | Document | null, top: boolean): number;
9
+ //#endregion
10
+ export { getScroll, getScrollContainer, isInContainer, isScroll, isWindow };
@@ -0,0 +1,74 @@
1
+ import { isServer } from "../is/server.js";
2
+ import "../is/index.js";
3
+
4
+ //#region src/dom/scroll.ts
5
+ function camelize(str) {
6
+ return str.replace(/[-_](.)/g, (_, char) => char.toUpperCase());
7
+ }
8
+ function getStyle(element, styleName) {
9
+ if (isServer) return "";
10
+ if (!element || !styleName) return "";
11
+ styleName = camelize(styleName);
12
+ if (styleName === "float") styleName = "cssFloat";
13
+ try {
14
+ const style = element.style[styleName];
15
+ if (style) return style;
16
+ const computed = document?.defaultView?.getComputedStyle(element, "");
17
+ return computed ? computed[styleName] : "";
18
+ } catch {
19
+ return element.style[styleName];
20
+ }
21
+ }
22
+ function isScroll(el, isVertical) {
23
+ if (isServer) return;
24
+ return (isVertical === null || isVertical === void 0 ? getStyle(el, "overflow") : isVertical ? getStyle(el, "overflow-y") : getStyle(el, "overflow-x")).match(/(scroll|auto|overlay)/);
25
+ }
26
+ function getScrollContainer(el, isVertical) {
27
+ if (isServer) return;
28
+ let parent = el;
29
+ while (parent) {
30
+ if ([
31
+ window,
32
+ document,
33
+ document.documentElement
34
+ ].includes(parent)) return window;
35
+ if (isScroll(parent, isVertical)) return parent;
36
+ parent = parent.parentNode;
37
+ }
38
+ return parent;
39
+ }
40
+ function isInContainer(el, container) {
41
+ if (isServer || !el || !container) return false;
42
+ const elRect = el.getBoundingClientRect();
43
+ let containerRect;
44
+ if ([
45
+ window,
46
+ document,
47
+ document.documentElement,
48
+ null,
49
+ void 0
50
+ ].includes(container)) containerRect = {
51
+ top: 0,
52
+ right: window.innerWidth,
53
+ bottom: window.innerHeight,
54
+ left: 0
55
+ };
56
+ else containerRect = container.getBoundingClientRect();
57
+ return elRect.top < containerRect.bottom && elRect.bottom > containerRect.top && elRect.right > containerRect.left && elRect.left < containerRect.right;
58
+ }
59
+ function isWindow(obj) {
60
+ return obj !== null && obj !== void 0 && obj === obj.window;
61
+ }
62
+ function getScroll(target, top) {
63
+ if (typeof window === "undefined") return 0;
64
+ const method = top ? "scrollTop" : "scrollLeft";
65
+ let result = 0;
66
+ if (isWindow(target)) result = target[top ? "pageYOffset" : "pageXOffset"];
67
+ else if (target instanceof Document) result = target.documentElement[method];
68
+ else if (target) result = target[method];
69
+ if (target && !isWindow(target) && typeof result !== "number") result = (target.ownerDocument || target).documentElement?.[method];
70
+ return result;
71
+ }
72
+
73
+ //#endregion
74
+ export { getScroll, getScrollContainer, isInContainer, isScroll, isWindow };
@@ -0,0 +1,10 @@
1
+ //#region src/file/config.d.ts
2
+ declare const fileTypes: {
3
+ videoAllowType: string[];
4
+ audioAllowType: string[];
5
+ imageType: string[];
6
+ videoType: string[];
7
+ audioType: string[];
8
+ };
9
+ //#endregion
10
+ export { fileTypes };
@@ -0,0 +1,81 @@
1
+ //#region src/file/config.ts
2
+ /**
3
+ * 文件类型配置
4
+ */
5
+ const fileTypes = {
6
+ videoAllowType: [
7
+ "mp4",
8
+ "webm",
9
+ "ogg"
10
+ ],
11
+ audioAllowType: [
12
+ "mp3",
13
+ "ogg",
14
+ "wav",
15
+ "aac",
16
+ "m4a",
17
+ "webm"
18
+ ],
19
+ imageType: [
20
+ "jpeg",
21
+ "jpg",
22
+ "png",
23
+ "gif",
24
+ "bmp",
25
+ "tiff",
26
+ "tif",
27
+ "webp",
28
+ "heic",
29
+ "heif",
30
+ "svg",
31
+ "ico",
32
+ "raw",
33
+ "cr2",
34
+ "nef",
35
+ "arw",
36
+ "dng",
37
+ "psd",
38
+ "eps"
39
+ ],
40
+ videoType: [
41
+ "mp4",
42
+ "avi",
43
+ "mov",
44
+ "wmv",
45
+ "mkv",
46
+ "flv",
47
+ "webm",
48
+ "mpeg",
49
+ "mpg",
50
+ "3gp",
51
+ "ogv",
52
+ "mxf",
53
+ "vob",
54
+ "rm",
55
+ "rmvb",
56
+ "ts",
57
+ "mts",
58
+ "m2ts",
59
+ "divx",
60
+ "xvid"
61
+ ],
62
+ audioType: [
63
+ "mp3",
64
+ "wav",
65
+ "aac",
66
+ "flac",
67
+ "ogg",
68
+ "wma",
69
+ "m4a",
70
+ "alac",
71
+ "opus",
72
+ "amr",
73
+ "aiff",
74
+ "au",
75
+ "pcm",
76
+ "ape"
77
+ ]
78
+ };
79
+
80
+ //#endregion
81
+ export { fileTypes };
@@ -0,0 +1,8 @@
1
+ //#region src/file/convert.d.ts
2
+ declare function getBlobUrl(blob: Blob): string;
3
+ declare function getBase64(file: File): Promise<string | ArrayBuffer | null>;
4
+ declare function dataURLtoBlob(url: any): Blob;
5
+ declare function dataURLtoFile(url: string, filename: string): File;
6
+ declare function blobToDataURL(blob: Blob, fileName: string, fileType: string): File;
7
+ //#endregion
8
+ export { blobToDataURL, dataURLtoBlob, dataURLtoFile, getBase64, getBlobUrl };