@whitesev/pops 2.4.5 → 2.4.7

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 (153) hide show
  1. package/README.md +117 -111
  2. package/dist/index.amd.js +1248 -1287
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.cjs.js +1248 -1287
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.esm.js +1248 -1287
  7. package/dist/index.esm.js.map +1 -1
  8. package/dist/index.iife.js +1248 -1287
  9. package/dist/index.iife.js.map +1 -1
  10. package/dist/index.system.js +1248 -1287
  11. package/dist/index.system.js.map +1 -1
  12. package/dist/index.umd.js +1248 -1287
  13. package/dist/index.umd.js.map +1 -1
  14. package/dist/types/src/Pops.d.ts +9 -10
  15. package/dist/types/src/components/panel/types/components-common.d.ts +26 -26
  16. package/dist/types/src/components/panel/types/index.d.ts +1 -1
  17. package/dist/types/src/components/rightClickMenu/index.d.ts +3 -4
  18. package/dist/types/src/components/searchSuggestion/index.d.ts +2 -2
  19. package/dist/types/src/components/searchSuggestion/types/index.d.ts +2 -2
  20. package/dist/types/src/handler/PopsHandler.d.ts +3 -3
  21. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +252 -256
  22. package/dist/types/src/types/animation.d.ts +19 -19
  23. package/dist/types/src/types/button.d.ts +187 -187
  24. package/dist/types/src/types/components.d.ts +210 -213
  25. package/dist/types/src/types/event.d.ts +63 -63
  26. package/dist/types/src/types/global.d.ts +25 -20
  27. package/dist/types/src/types/icon.d.ts +32 -32
  28. package/dist/types/src/types/inst.d.ts +24 -24
  29. package/dist/types/src/types/main.d.ts +111 -114
  30. package/dist/types/src/types/mask.d.ts +49 -49
  31. package/dist/types/src/types/position.d.ts +60 -60
  32. package/dist/types/src/utils/PopsDOMUtils.d.ts +1 -1
  33. package/dist/types/src/utils/PopsInstanceUtils.d.ts +1 -1
  34. package/dist/types/src/utils/PopsUtils.d.ts +16 -16
  35. package/index.ts +3 -0
  36. package/package.json +20 -9
  37. package/src/Pops.ts +206 -0
  38. package/src/PopsAnimation.ts +32 -0
  39. package/src/PopsCSS.ts +51 -0
  40. package/src/PopsCore.ts +64 -0
  41. package/src/PopsIcon.ts +95 -0
  42. package/src/PopsInst.ts +21 -0
  43. package/src/components/alert/config.ts +62 -0
  44. package/src/components/alert/index.css +0 -0
  45. package/src/components/alert/index.ts +163 -0
  46. package/src/components/alert/types/index.ts +23 -0
  47. package/src/components/confirm/config.ts +90 -0
  48. package/src/components/confirm/index.css +0 -0
  49. package/src/components/confirm/index.ts +166 -0
  50. package/src/components/confirm/types/index.ts +17 -0
  51. package/src/components/drawer/config.ts +89 -0
  52. package/src/components/drawer/index.css +37 -0
  53. package/src/components/drawer/index.ts +237 -0
  54. package/src/components/drawer/types/index.ts +61 -0
  55. package/src/components/folder/config.ts +147 -0
  56. package/src/components/folder/folderIcon.ts +28 -0
  57. package/src/components/folder/index.css +303 -0
  58. package/src/components/folder/index.ts +929 -0
  59. package/src/components/folder/types/index.ts +97 -0
  60. package/src/components/iframe/config.ts +60 -0
  61. package/src/components/iframe/index.css +76 -0
  62. package/src/components/iframe/index.ts +334 -0
  63. package/src/components/iframe/types/index.ts +139 -0
  64. package/src/components/loading/config.ts +29 -0
  65. package/src/components/loading/index.css +66 -0
  66. package/src/components/loading/index.ts +99 -0
  67. package/src/components/loading/types/index.ts +34 -0
  68. package/src/components/panel/config.ts +519 -0
  69. package/src/components/panel/handlerComponents.ts +2900 -0
  70. package/src/components/panel/index.css +1222 -0
  71. package/src/components/panel/index.ts +207 -0
  72. package/src/components/panel/types/components-button.ts +68 -0
  73. package/src/components/panel/types/components-common.ts +50 -0
  74. package/src/components/panel/types/components-deepMenu.ts +84 -0
  75. package/src/components/panel/types/components-forms.ts +44 -0
  76. package/src/components/panel/types/components-input.ts +78 -0
  77. package/src/components/panel/types/components-own.ts +30 -0
  78. package/src/components/panel/types/components-select.ts +93 -0
  79. package/src/components/panel/types/components-selectMultiple.ts +130 -0
  80. package/src/components/panel/types/components-slider.ts +77 -0
  81. package/src/components/panel/types/components-switch.ts +56 -0
  82. package/src/components/panel/types/components-textarea.ts +68 -0
  83. package/src/components/panel/types/index.ts +177 -0
  84. package/src/components/prompt/config.ts +94 -0
  85. package/src/components/prompt/index.css +34 -0
  86. package/src/components/prompt/index.ts +216 -0
  87. package/src/components/prompt/types/index.ts +55 -0
  88. package/src/components/rightClickMenu/config.ts +98 -0
  89. package/src/components/rightClickMenu/index.css +112 -0
  90. package/src/components/rightClickMenu/index.ts +602 -0
  91. package/src/components/rightClickMenu/types/index.ts +97 -0
  92. package/src/components/searchSuggestion/config.ts +56 -0
  93. package/src/components/searchSuggestion/index.ts +856 -0
  94. package/src/components/searchSuggestion/types/index.ts +239 -0
  95. package/src/components/tooltip/config.ts +34 -0
  96. package/src/components/tooltip/index.css +199 -0
  97. package/src/components/tooltip/index.ts +604 -0
  98. package/src/components/tooltip/types/index.ts +117 -0
  99. package/src/config/CommonCSSClassName.ts +17 -0
  100. package/src/config/GlobalConfig.ts +63 -0
  101. package/src/css/animation.css +987 -0
  102. package/src/css/button.css +551 -0
  103. package/src/css/common.css +48 -0
  104. package/src/css/index.css +253 -0
  105. package/src/css/ninePalaceGridPosition.css +50 -0
  106. package/src/css/scrollbar.css +22 -0
  107. package/src/handler/PopsElementHandler.ts +304 -0
  108. package/src/handler/PopsHandler.ts +589 -0
  109. package/src/svg/arrowLeft.svg +4 -0
  110. package/src/svg/arrowRight.svg +4 -0
  111. package/src/svg/chromeFilled.svg +11 -0
  112. package/src/svg/circleClose.svg +8 -0
  113. package/src/svg/close.svg +5 -0
  114. package/src/svg/cpu.svg +8 -0
  115. package/src/svg/delete.svg +5 -0
  116. package/src/svg/documentCopy.svg +5 -0
  117. package/src/svg/edit.svg +8 -0
  118. package/src/svg/eleme.svg +5 -0
  119. package/src/svg/elemePlus.svg +5 -0
  120. package/src/svg/headset.svg +5 -0
  121. package/src/svg/hide.svg +8 -0
  122. package/src/svg/keyboard.svg +8 -0
  123. package/src/svg/loading.svg +5 -0
  124. package/src/svg/max.svg +5 -0
  125. package/src/svg/min.svg +5 -0
  126. package/src/svg/mise.svg +5 -0
  127. package/src/svg/monitor.svg +5 -0
  128. package/src/svg/next.svg +5 -0
  129. package/src/svg/picture.svg +8 -0
  130. package/src/svg/prev.svg +5 -0
  131. package/src/svg/search.svg +5 -0
  132. package/src/svg/share.svg +5 -0
  133. package/src/svg/upload.svg +5 -0
  134. package/src/svg/videoPause.svg +5 -0
  135. package/src/svg/videoPlay.svg +5 -0
  136. package/src/svg/view.svg +5 -0
  137. package/src/types/PopsDOMUtilsEventType.d.ts +252 -0
  138. package/src/types/animation.d.ts +19 -0
  139. package/src/types/button.d.ts +187 -0
  140. package/src/types/components.d.ts +210 -0
  141. package/src/types/event.d.ts +63 -0
  142. package/src/types/global.d.ts +25 -0
  143. package/src/types/icon.d.ts +32 -0
  144. package/src/types/inst.d.ts +24 -0
  145. package/src/types/main.d.ts +111 -0
  146. package/src/types/mask.d.ts +49 -0
  147. package/src/types/position.d.ts +60 -0
  148. package/src/utils/PopsDOMUtils.ts +2408 -0
  149. package/src/utils/PopsDOMUtilsEventsConfig.ts +4 -0
  150. package/src/utils/PopsInstanceUtils.ts +688 -0
  151. package/src/utils/PopsMathUtils.ts +71 -0
  152. package/src/utils/PopsSafeUtils.ts +22 -0
  153. package/src/utils/PopsUtils.ts +406 -0
@@ -0,0 +1,71 @@
1
+ export const PopsMathFloatUtils = {
2
+ /**
3
+ * 判断数字是否是浮点数
4
+ * @param num
5
+ */
6
+ isFloat(num: number): boolean {
7
+ return Number(num) === num && num % 1 !== 0;
8
+ },
9
+ /**
10
+ * 浮点数加法
11
+ * @param number1
12
+ * @param number2
13
+ */
14
+ add(number1: number, number2: number) {
15
+ let number1length, number2length;
16
+ try {
17
+ number1length = number1.toString().split(".")[1].length;
18
+ } catch {
19
+ number1length = 0;
20
+ }
21
+ try {
22
+ number2length = number2.toString().split(".")[1].length;
23
+ } catch {
24
+ number2length = 0;
25
+ }
26
+ const powValue = Math.pow(10, Math.max(number1length, number2length));
27
+ return Math.round(number1 * powValue + number2 * powValue) / powValue;
28
+ },
29
+ /**
30
+ * 减法
31
+ * @param number1
32
+ * @param number2
33
+ */
34
+ sub(number1: number, number2: number) {
35
+ let number1length, number2length;
36
+ try {
37
+ number1length = number1.toString().split(".")[1].length;
38
+ } catch {
39
+ number1length = 0;
40
+ }
41
+ try {
42
+ number2length = number2.toString().split(".")[1].length;
43
+ } catch {
44
+ number2length = 0;
45
+ }
46
+ const powValue = Math.pow(10, Math.max(number1length, number2length));
47
+ const fixedValue = number1length >= number2length ? number1length : number2length;
48
+ return (Math.round(number1 * powValue - number2 * powValue) / powValue).toFixed(fixedValue);
49
+ },
50
+ /**
51
+ * 除法
52
+ * @param number1
53
+ * @param number2
54
+ */
55
+ division(number1: number, number2: number) {
56
+ let number1length, number2length;
57
+ try {
58
+ number1length = number1.toString().split(".")[1].length;
59
+ } catch {
60
+ number1length = 0;
61
+ }
62
+ try {
63
+ number2length = number2.toString().split(".")[1].length;
64
+ } catch {
65
+ number2length = 0;
66
+ }
67
+ const number1ReplaceValue = Number(number1.toString().replace(".", ""));
68
+ const number2ReplaceValue = Number(number2.toString().replace(".", ""));
69
+ return (number1ReplaceValue / number2ReplaceValue) * Math.pow(10, number2length - number1length);
70
+ },
71
+ };
@@ -0,0 +1,22 @@
1
+ export const PopsSafeUtils = {
2
+ /**
3
+ * 获取安全的html
4
+ */
5
+ getSafeHTML(text: string) {
6
+ if (window.trustedTypes) {
7
+ const policy = window.trustedTypes.createPolicy("safe-innerHTML", {
8
+ createHTML: (html: string) => html,
9
+ });
10
+ return policy.createHTML(text);
11
+ } else {
12
+ return text;
13
+ }
14
+ },
15
+ /**
16
+ * 设置安全的html
17
+ */
18
+ setSafeHTML($el: Element, text: string) {
19
+ // 创建 TrustedHTML 策略(需 CSP 允许)
20
+ $el.innerHTML = this.getSafeHTML(text);
21
+ },
22
+ };
@@ -0,0 +1,406 @@
1
+ import { PopsCore } from "../PopsCore";
2
+ import type { PopsUtilsOwnObject } from "../types/main";
3
+ import {
4
+ clearInterval as WorkerClearInterval,
5
+ clearTimeout as WorkerClearTimeout,
6
+ setInterval as WorkerSetInterval,
7
+ setTimeout as WorkerSetTimeout,
8
+ } from "worker-timers";
9
+ import AnyTouch from "any-touch";
10
+
11
+ class PopsUtils {
12
+ /**
13
+ * 判断是否是window,例如window、self、globalThis
14
+ * @param target
15
+ */
16
+ isWin(target: any) {
17
+ if (typeof target !== "object") {
18
+ return false;
19
+ }
20
+ if (target instanceof Node) {
21
+ return false;
22
+ }
23
+ if (target === globalThis) {
24
+ return true;
25
+ }
26
+ if (target === window) {
27
+ return true;
28
+ }
29
+ if (target === self) {
30
+ return true;
31
+ }
32
+ if (target === PopsCore.globalThis) {
33
+ return true;
34
+ }
35
+ if (target === PopsCore.window) {
36
+ return true;
37
+ }
38
+ if (target === PopsCore.self) {
39
+ return true;
40
+ }
41
+ if (typeof unsafeWindow !== "undefined" && target === unsafeWindow) {
42
+ return true;
43
+ }
44
+ if (target?.Math?.toString() !== "[object Math]") {
45
+ return false;
46
+ }
47
+ return true;
48
+ }
49
+ /**
50
+ * 判断对象是否是元素
51
+ * @param target
52
+ * @returns
53
+ * + true 是元素
54
+ * + false 不是元素
55
+ * @example
56
+ * Utils.isDOM(document.querySelector("a"))
57
+ * > true
58
+ */
59
+ isDOM(target: any): boolean;
60
+ isDOM(target: any): boolean {
61
+ return target instanceof Node;
62
+ }
63
+ /**
64
+ * 删除对象上的属性
65
+ * @param target
66
+ * @param propName
67
+ */
68
+ delete(target: any, propName: any) {
69
+ if (typeof Reflect === "object" && Reflect.deleteProperty) {
70
+ Reflect.deleteProperty(target, propName);
71
+ } else {
72
+ delete target[propName];
73
+ }
74
+ }
75
+ /**
76
+ * JSON数据从源端替换到目标端中,如果目标端存在该数据则替换,不添加,返回结果为目标端替换完毕的结果
77
+ * @param target 目标数据
78
+ * @param source 源数据
79
+ * @param isAdd 是否可以追加键,默认false
80
+ * @example
81
+ * Utils.assign({"1":1,"2":{"3":3}}, {"2":{"3":4}});
82
+ * >
83
+ * {
84
+ "1": 1,
85
+ "2": {
86
+ "3": 4
87
+ }
88
+ }
89
+ */
90
+ assign<T1, T2 extends object, T3 extends boolean>(target: T1, source: T2, isAdd?: T3): T3 extends true ? T1 & T2 : T1;
91
+ assign(target = {}, source = {}, isAdd = false) {
92
+ const UtilsContext = this;
93
+ if (source == null) {
94
+ return target;
95
+ }
96
+ if (target == null) {
97
+ target = {};
98
+ }
99
+ if (Array.isArray(source)) {
100
+ const canTraverse = source.filter((item) => {
101
+ return typeof item === "object";
102
+ });
103
+ if (!canTraverse.length) {
104
+ return source;
105
+ }
106
+ }
107
+ if (isAdd) {
108
+ for (const sourceKeyName in source) {
109
+ const targetKeyName = sourceKeyName;
110
+ const targetValue = (target as any)[targetKeyName];
111
+ const sourceValue = (source as any)[sourceKeyName];
112
+ if (
113
+ typeof sourceValue === "object" &&
114
+ sourceValue != null &&
115
+ sourceKeyName in target &&
116
+ !UtilsContext.isDOM(sourceValue)
117
+ ) {
118
+ /* 源端的值是object类型,且不是元素节点 */
119
+ (target as any)[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
120
+ continue;
121
+ }
122
+ (target as any)[sourceKeyName] = sourceValue;
123
+ }
124
+ } else {
125
+ for (const targetKeyName in target) {
126
+ if (targetKeyName in source) {
127
+ const targetValue = Reflect.get(target, targetKeyName);
128
+ const sourceValue = Reflect.get(source, targetKeyName);
129
+ if (
130
+ typeof sourceValue === "object" &&
131
+ sourceValue != null &&
132
+ !UtilsContext.isDOM(sourceValue) &&
133
+ Object.keys(sourceValue).length
134
+ ) {
135
+ /* 源端的值是object类型,且不是元素节点 */
136
+ const childObjectValue = UtilsContext.assign(targetValue, sourceValue, isAdd);
137
+ Reflect.set(target, targetKeyName, childObjectValue);
138
+ continue;
139
+ }
140
+ /* 直接赋值 */
141
+ Reflect.set(target, targetKeyName, sourceValue);
142
+ }
143
+ }
144
+ }
145
+
146
+ return target;
147
+ }
148
+ /**
149
+ * 生成uuid
150
+ */
151
+ getRandomGUID() {
152
+ if (typeof PopsCore.globalThis?.crypto?.randomUUID === "function") {
153
+ return PopsCore.globalThis.crypto.randomUUID();
154
+ } else {
155
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
156
+ const randomValue = (Math.random() * 16) | 0,
157
+ randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
158
+ return randomCharValue.toString(16);
159
+ });
160
+ }
161
+ }
162
+ /**
163
+ * 判断元素/页面中是否包含该元素
164
+ * @param target 需要判断的元素
165
+ * @param context 默认为body
166
+ */
167
+ contains(target: any): boolean;
168
+ contains(context: any, target?: any): boolean;
169
+ contains(...args: any[]): boolean {
170
+ const [context, target] = args;
171
+ if (args.length === 1) {
172
+ // 只判断该页面是否存在该元素
173
+ return this.contains(PopsCore.document.body || PopsCore.document.documentElement, args[0]);
174
+ } else {
175
+ if (target == null) {
176
+ return false;
177
+ }
178
+ if (typeof target[Symbol.iterator] === "function") {
179
+ // 可遍历的数组
180
+ let flag = true;
181
+ for (const targetNode of target as any) {
182
+ if (!context.contains(targetNode)) {
183
+ flag = false;
184
+ break;
185
+ }
186
+ }
187
+ return flag;
188
+ } else {
189
+ return context.contains(target);
190
+ }
191
+ }
192
+ }
193
+
194
+ /**
195
+ * 获取格式化后的时间
196
+ * @param text (可选)需要格式化的字符串或者时间戳,默认:new Date()
197
+ * @param formatType (可选)格式化成的显示类型,默认:yyyy-MM-dd HH:mm:ss
198
+ * + yyyy 年
199
+ * + MM 月
200
+ * + dd 天
201
+ * + HH 时 (24小时制)
202
+ * + hh 时 (12小时制)
203
+ * + mm 分
204
+ * + ss 秒
205
+ * @returns {string} 返回格式化后的时间
206
+ * @example
207
+ * Utils.formatTime("2022-08-21 23:59:00","HH:mm:ss");
208
+ * > '23:59:00'
209
+ * @example
210
+ * Utils.formatTime(1899187424988,"HH:mm:ss");
211
+ * > '15:10:13'
212
+ * @example
213
+ * Utils.formatTime()
214
+ * > '2023-1-1 00:00:00'
215
+ **/
216
+ formatTime(text?: string | number | Date, formatType?: string): string;
217
+ /**
218
+ * 获取格式化后的时间
219
+ * @param text (可选)需要格式化的字符串或者时间戳,默认:new Date()
220
+ * @param formatType (可选)格式化成的显示类型,默认:yyyy-MM-dd HH:mm:ss
221
+ * + yyyy 年
222
+ * + MM 月
223
+ * + dd 天
224
+ * + HH 时 (24小时制)
225
+ * + hh 时 (12小时制)
226
+ * + mm 分
227
+ * + ss 秒
228
+ * @returns {string} 返回格式化后的时间
229
+ * @example
230
+ * Utils.formatTime("2022-08-21 23:59:00","HH:mm:ss");
231
+ * > '23:59:00'
232
+ * @example
233
+ * Utils.formatTime(1899187424988,"HH:mm:ss");
234
+ * > '15:10:13'
235
+ * @example
236
+ * Utils.formatTime()
237
+ * > '2023-1-1 00:00:00'
238
+ **/
239
+ formatTime(
240
+ text?: string | number | Date,
241
+ formatType?:
242
+ | "yyyy-MM-dd HH:mm:ss"
243
+ | "yyyy/MM/dd HH:mm:ss"
244
+ | "yyyy_MM_dd_HH_mm_ss"
245
+ | "yyyy年MM月dd日 HH时mm分ss秒"
246
+ | "yyyy年MM月dd日 hh:mm:ss"
247
+ | "yyyy年MM月dd日 HH:mm:ss"
248
+ | "yyyy-MM-dd"
249
+ | "yyyyMMdd"
250
+ | "HH:mm:ss"
251
+ ): string;
252
+ formatTime(text = new Date(), formatType = "yyyy-MM-dd HH:mm:ss") {
253
+ const time = text == null ? new Date() : new Date(text);
254
+ /**
255
+ * 校验时间补0
256
+ * @param timeNum
257
+ * @returns
258
+ */
259
+ function checkTime(timeNum: number) {
260
+ if (timeNum < 10) return "0" + timeNum;
261
+ return timeNum;
262
+ }
263
+
264
+ /**
265
+ * 时间制修改 24小时制转12小时制
266
+ * @param hourNum 小时
267
+ * @returns
268
+ */
269
+ function timeSystemChange(hourNum: number) {
270
+ return hourNum > 12 ? hourNum - 12 : hourNum;
271
+ }
272
+
273
+ const timeRegexp = {
274
+ yyyy: time.getFullYear(),
275
+ /* 年 */
276
+ MM: checkTime(time.getMonth() + 1),
277
+ /* 月 */
278
+ dd: checkTime(time.getDate()),
279
+ /* 日 */
280
+ HH: checkTime(time.getHours()),
281
+ /* 时 (24小时制) */
282
+ hh: checkTime(timeSystemChange(time.getHours())),
283
+ /* 时 (12小时制) */
284
+ mm: checkTime(time.getMinutes()),
285
+ /* 分 */
286
+ ss: checkTime(time.getSeconds()),
287
+ /* 秒 */
288
+ };
289
+ Object.keys(timeRegexp).forEach(function (key) {
290
+ const replaecRegexp = new RegExp(key, "g");
291
+ formatType = formatType.replace(replaecRegexp, (timeRegexp as any)[key]);
292
+ });
293
+ return formatType;
294
+ }
295
+ /**
296
+ * 格式化byte为KB、MB、GB、TB、PB、EB、ZB、YB、BB、NB、DB
297
+ * @param byteSize 字节
298
+ * @param addType (可选)是否添加单位
299
+ * + true (默认) 添加单位
300
+ * + false 不添加单位
301
+ * @returns
302
+ * + {string} 当addType为true时,且保留小数点末尾2位
303
+ * + {number} 当addType为false时,且保留小数点末尾2位
304
+ * @example
305
+ * Utils.formatByteToSize("812304");
306
+ * > '793.27KB'
307
+ * @example
308
+ * Utils.formatByteToSize("812304",false);
309
+ * > 793.27
310
+ **/
311
+ formatByteToSize<T extends boolean>(byteSize: number | string, addType?: T): T extends true ? string : number;
312
+ formatByteToSize(byteSize: number | string, addType = true) {
313
+ byteSize = parseInt(byteSize.toString());
314
+ if (isNaN(byteSize)) {
315
+ throw new TypeError("Utils.formatByteToSize 参数 byteSize 格式不正确");
316
+ }
317
+ let result = 0;
318
+ let resultType = "KB";
319
+ const sizeData: PopsUtilsOwnObject<number> = {};
320
+ sizeData.B = 1;
321
+ sizeData.KB = 1024;
322
+ sizeData.MB = sizeData.KB * sizeData.KB;
323
+ sizeData.GB = sizeData.MB * sizeData.KB;
324
+ sizeData.TB = sizeData.GB * sizeData.KB;
325
+ sizeData.PB = sizeData.TB * sizeData.KB;
326
+ sizeData.EB = sizeData.PB * sizeData.KB;
327
+ sizeData.ZB = sizeData.EB * sizeData.KB;
328
+ sizeData.YB = sizeData.ZB * sizeData.KB;
329
+ sizeData.BB = sizeData.YB * sizeData.KB;
330
+ sizeData.NB = sizeData.BB * sizeData.KB;
331
+ sizeData.DB = sizeData.NB * sizeData.KB;
332
+ for (const key in sizeData) {
333
+ result = byteSize / (sizeData as any)[key];
334
+ resultType = key;
335
+ if (sizeData.KB >= result) {
336
+ break;
337
+ }
338
+ }
339
+ new Date();
340
+ result = result.toFixed(2) as any;
341
+ result = addType ? result + resultType.toString() : (parseFloat(result.toString()) as any);
342
+ return result;
343
+ }
344
+ AnyTouch = () => {
345
+ return AnyTouch;
346
+ };
347
+ /**
348
+ * 通过navigator.userAgent判断是否是手机访问
349
+ * @param userAgent
350
+ */
351
+ isPhone(userAgent = PopsCore.globalThis.navigator.userAgent): boolean {
352
+ return Boolean(/(iPhone|iPad|iPod|iOS|Android)/i.test(userAgent));
353
+ }
354
+ /**
355
+ * 自动使用 Worker 执行 setTimeout
356
+ */
357
+ setTimeout(callback: (...args: any[]) => any, timeout: number = 0) {
358
+ try {
359
+ return WorkerSetTimeout(callback, timeout);
360
+ } catch {
361
+ return PopsCore.setTimeout(callback, timeout);
362
+ }
363
+ }
364
+ /**
365
+ * 配合 .setTimeout 使用
366
+ */
367
+ clearTimeout(timeId: number | undefined) {
368
+ try {
369
+ if (timeId != null) {
370
+ WorkerClearTimeout(timeId);
371
+ }
372
+ } catch {
373
+ // TODO
374
+ } finally {
375
+ PopsCore.clearTimeout(timeId);
376
+ }
377
+ }
378
+ /**
379
+ * 自动使用 Worker 执行 setInterval
380
+ */
381
+ setInterval(callback: (...args: any[]) => any, timeout: number = 0) {
382
+ try {
383
+ return WorkerSetInterval(callback, timeout);
384
+ } catch {
385
+ return PopsCore.setInterval(callback, timeout);
386
+ }
387
+ }
388
+ /**
389
+ * 配合 .setInterval 使用
390
+ */
391
+ clearInterval(timeId: number | undefined) {
392
+ try {
393
+ if (timeId != null) {
394
+ WorkerClearInterval(timeId);
395
+ }
396
+ } catch {
397
+ // 忽略
398
+ } finally {
399
+ PopsCore.clearInterval(timeId);
400
+ }
401
+ }
402
+ }
403
+
404
+ const popsUtils = new PopsUtils();
405
+
406
+ export { popsUtils };