@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,4 @@
1
+ /**
2
+ * 存储在元素属性上的事件名
3
+ */
4
+ export const SymbolEvents = Symbol("events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1));
@@ -0,0 +1,688 @@
1
+ import type { PopsAlertDetails } from "../components/alert/types";
2
+ import type { PopsConfirmDetails } from "../components/confirm/types";
3
+ import type { PopsDrawerDetails } from "../components/drawer/types";
4
+ import type { PopsFolderDetails } from "../components/folder/types";
5
+ import type { PopsIframeDetails } from "../components/iframe/types";
6
+ import type { PopsLoadingDetails } from "../components/loading/types";
7
+ import type { PopsPanelDetails } from "../components/panel/types";
8
+ import type { PopsPromptDetails } from "../components/prompt/types/index";
9
+ import type { PopsInstCommonConfig } from "../types/inst";
10
+ import type { PopsInstStoreType } from "../types/main";
11
+ import { popsDOMUtils } from "./PopsDOMUtils";
12
+ import { popsUtils } from "./PopsUtils";
13
+ import { PopsCore } from "../PopsCore";
14
+ import { PopsInstData } from "../PopsInst";
15
+ import { PopsAnimation } from "../PopsAnimation";
16
+
17
+ export const PopsInstanceUtils = {
18
+ /**
19
+ * 获取页面中最大的z-index的元素信息
20
+ * @param deviation 获取最大的z-index值的偏移,默认是+1
21
+ * @param node 进行判断的元素,默认是document
22
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
23
+ * @example
24
+ * Utils.getMaxZIndexNodeInfo();
25
+ * > {
26
+ * node: ...,
27
+ * zIndex: 1001
28
+ * }
29
+ **/
30
+ getMaxZIndexNodeInfo(
31
+ deviation = 1,
32
+ target: Element | ShadowRoot | Document = PopsCore.document,
33
+ ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
34
+ ): {
35
+ node: Element;
36
+ zIndex: number;
37
+ } {
38
+ deviation = Number.isNaN(deviation) ? 1 : deviation;
39
+ // 最大值 2147483647
40
+ // const maxZIndex = Math.pow(2, 31) - 1;
41
+ // 比较值 2000000000
42
+ const maxZIndexCompare = 2 * Math.pow(10, 9);
43
+ // 当前页面最大的z-index
44
+ let zIndex = 0;
45
+ // 当前的最大z-index的元素,调试使用
46
+ let maxZIndexNode: Element | null = null;
47
+ /**
48
+ * 元素是否可见
49
+ * @param $css
50
+ */
51
+ function isVisibleNode($css: CSSStyleDeclaration): boolean {
52
+ return $css.position !== "static" && $css.display !== "none";
53
+ }
54
+ /**
55
+ * 查询元素的z-index
56
+ * 并比较值是否是已获取的最大值
57
+ * @param $ele
58
+ */
59
+ function queryMaxZIndex($ele: Element) {
60
+ if (typeof ignoreCallBack === "function") {
61
+ const ignoreResult = ignoreCallBack($ele);
62
+ if (typeof ignoreResult === "boolean" && !ignoreResult) {
63
+ return;
64
+ }
65
+ }
66
+ /** 元素的样式 */
67
+ const nodeStyle = PopsCore.window.getComputedStyle($ele);
68
+ /* 不对position为static和display为none的元素进行获取它们的z-index */
69
+ if (isVisibleNode(nodeStyle)) {
70
+ const nodeZIndex = parseInt(nodeStyle.zIndex);
71
+ if (!isNaN(nodeZIndex)) {
72
+ if (nodeZIndex > zIndex) {
73
+ // 赋值到全局
74
+ zIndex = nodeZIndex;
75
+ maxZIndexNode = $ele;
76
+ }
77
+ }
78
+ // 判断shadowRoot
79
+ if ($ele.shadowRoot != null && $ele instanceof ShadowRoot) {
80
+ $ele.shadowRoot.querySelectorAll("*").forEach(($shadowEle) => {
81
+ queryMaxZIndex($shadowEle);
82
+ });
83
+ }
84
+ }
85
+ }
86
+ target.querySelectorAll("*").forEach(($ele) => {
87
+ queryMaxZIndex($ele);
88
+ });
89
+ zIndex += deviation;
90
+ if (zIndex >= maxZIndexCompare) {
91
+ // 最好不要超过最大值
92
+ zIndex = maxZIndexCompare;
93
+ }
94
+ return {
95
+ node: maxZIndexNode!,
96
+ zIndex: zIndex,
97
+ };
98
+ },
99
+ /**
100
+ * 获取pops所有弹窗中的最大的z-index
101
+ * @param deviation
102
+ */
103
+ getPopsMaxZIndex(deviation: number = 1) {
104
+ deviation = Number.isNaN(deviation) ? 1 : deviation;
105
+ // 最大值 2147483647
106
+ // const browserMaxZIndex = Math.pow(2, 31) - 1;
107
+ // 比较值 2000000000
108
+ const maxZIndex = 2 * Math.pow(10, 9);
109
+ // 当前页面最大的z-index
110
+ let zIndex = 0;
111
+ // 当前的最大z-index的元素,调试使用
112
+ let maxZIndexNode = null as HTMLDivElement | null;
113
+
114
+ /**
115
+ * 元素是否可见
116
+ * @param $css
117
+ */
118
+ function isVisibleNode($css: CSSStyleDeclaration): boolean {
119
+ return $css.position !== "static" && $css.display !== "none";
120
+ }
121
+ Object.keys(PopsInstData).forEach((instKeyName) => {
122
+ const instData = PopsInstData[instKeyName as PopsInstStoreType];
123
+ for (let index = 0; index < instData.length; index++) {
124
+ const inst = instData[index];
125
+ const nodeStyle = window.getComputedStyle(inst.animElement);
126
+ /* 不对position为static和display为none的元素进行获取它们的z-index */
127
+ if (isVisibleNode(nodeStyle)) {
128
+ const nodeZIndex = parseInt(nodeStyle.zIndex);
129
+ if (!isNaN(nodeZIndex)) {
130
+ if (nodeZIndex > zIndex) {
131
+ zIndex = nodeZIndex;
132
+ maxZIndexNode = inst.animElement;
133
+ }
134
+ }
135
+ }
136
+ }
137
+ });
138
+ zIndex += deviation;
139
+ const isOverMaxZIndex = zIndex >= maxZIndex;
140
+ if (isOverMaxZIndex) {
141
+ // 超出z-index最大值
142
+ zIndex = maxZIndex;
143
+ }
144
+ return { zIndex: zIndex, animElement: maxZIndexNode, isOverMaxZIndex };
145
+ },
146
+ /**
147
+ * 获取页面中最大的z-index
148
+ * @param deviation 获取最大的z-index值的偏移,默认是+1
149
+ * @example
150
+ * getMaxZIndex();
151
+ * > 1001
152
+ **/
153
+ getMaxZIndex(deviation = 1): number {
154
+ return this.getMaxZIndexNodeInfo(deviation).zIndex;
155
+ },
156
+ /**
157
+ * 删除配置中对应的对象
158
+ * @param instConfigList 配置实例列表
159
+ * @param guid 唯一标识
160
+ * @param isAll 是否全部删除
161
+ */
162
+ removeInstance(instConfigList: PopsInstCommonConfig[][], guid: string, isAll = false) {
163
+ /**
164
+ * 移除元素实例
165
+ * @param instCommonConfig
166
+ */
167
+ function removeItem(instCommonConfig: PopsInstCommonConfig) {
168
+ if (typeof instCommonConfig.beforeRemoveCallBack === "function") {
169
+ // 调用移除签的回调
170
+ instCommonConfig.beforeRemoveCallBack(instCommonConfig);
171
+ }
172
+ instCommonConfig?.animElement?.remove();
173
+ instCommonConfig?.popsElement?.remove();
174
+ instCommonConfig?.maskElement?.remove();
175
+ instCommonConfig?.$shadowContainer?.remove();
176
+ }
177
+ // [ inst[], inst[],...]
178
+ instConfigList.forEach((instConfigList) => {
179
+ // inst[]
180
+ instConfigList.forEach((instConfigItem, index) => {
181
+ // 移除全部或者guid相同
182
+ if (isAll || instConfigItem["guid"] === guid) {
183
+ // 判断是否有动画
184
+ const animName = instConfigItem.animElement.getAttribute("anim") as string;
185
+ if (PopsAnimation.hasAnim(animName)) {
186
+ const reverseAnimName = animName + "-reverse";
187
+ instConfigItem.animElement.style.width = "100%";
188
+ instConfigItem.animElement.style.height = "100%";
189
+ (instConfigItem.animElement.style as any)["animation-name"] = reverseAnimName;
190
+ if (PopsAnimation.hasAnim((instConfigItem.animElement.style as any)["animation-name"])) {
191
+ popsDOMUtils.on(
192
+ instConfigItem.animElement,
193
+ popsDOMUtils.getAnimationEndNameList(),
194
+ function () {
195
+ removeItem(instConfigItem);
196
+ },
197
+ {
198
+ capture: true,
199
+ }
200
+ );
201
+ } else {
202
+ removeItem(instConfigItem);
203
+ }
204
+ } else {
205
+ removeItem(instConfigItem);
206
+ }
207
+ instConfigList.splice(index, 1);
208
+ }
209
+ });
210
+ });
211
+
212
+ return instConfigList;
213
+ },
214
+ /**
215
+ * 隐藏
216
+ * @param popsType
217
+ * @param instConfigList
218
+ * @param guid
219
+ * @param config
220
+ * @param animElement
221
+ * @param maskElement
222
+ */
223
+ hide(
224
+ popsType: PopsInstStoreType,
225
+ instConfigList: PopsInstCommonConfig[],
226
+ guid: string,
227
+ config:
228
+ | PopsAlertDetails
229
+ | PopsDrawerDetails
230
+ | PopsPromptDetails
231
+ | PopsConfirmDetails
232
+ | PopsIframeDetails
233
+ | PopsLoadingDetails
234
+ | PopsPanelDetails
235
+ | PopsFolderDetails,
236
+ animElement: HTMLElement,
237
+ maskElement: HTMLElement
238
+ ) {
239
+ return new Promise<void>((resolve) => {
240
+ const popsElement = animElement.querySelector<HTMLDivElement>(".pops[type-value]")!;
241
+ if (popsType === "drawer") {
242
+ const drawerConfig = config as Required<PopsDrawerDetails>;
243
+ popsUtils.setTimeout(() => {
244
+ maskElement.style.setProperty("display", "none");
245
+ if (["top", "bottom"].includes(drawerConfig.direction)) {
246
+ popsElement.style.setProperty("height", "0");
247
+ } else if (["left", "right"].includes(drawerConfig.direction)) {
248
+ popsElement.style.setProperty("width", "0");
249
+ } else {
250
+ console.error("未知direction:", drawerConfig.direction);
251
+ }
252
+ resolve();
253
+ }, drawerConfig.closeDelay);
254
+ } else {
255
+ const fintInst = instConfigList.find((instConfigItem) => instConfigItem.guid === guid);
256
+ if (fintInst) {
257
+ /* 存在动画 */
258
+ const instConfigItem = fintInst;
259
+ instConfigItem.animElement.style.width = "100%";
260
+ instConfigItem.animElement.style.height = "100%";
261
+ Reflect.set(
262
+ instConfigItem.animElement.style,
263
+ "animation-name",
264
+ instConfigItem.animElement.getAttribute("anim") + "-reverse"
265
+ );
266
+ if (PopsAnimation.hasAnim(Reflect.get(instConfigItem.animElement.style, "animation-name"))) {
267
+ /**
268
+ * 动画结束的回调
269
+ */
270
+ function animationendCallBack() {
271
+ instConfigItem.animElement.style.display = "none";
272
+ if (instConfigItem.maskElement) {
273
+ instConfigItem.maskElement.style.display = "none";
274
+ }
275
+ popsDOMUtils.off(
276
+ instConfigItem.animElement,
277
+ popsDOMUtils.getAnimationEndNameList(),
278
+ animationendCallBack,
279
+ {
280
+ capture: true,
281
+ }
282
+ );
283
+ resolve();
284
+ }
285
+ popsDOMUtils.on(instConfigItem.animElement, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
286
+ capture: true,
287
+ });
288
+ } else {
289
+ instConfigItem.animElement.style.display = "none";
290
+ if (instConfigItem.maskElement) {
291
+ instConfigItem.maskElement.style.display = "none";
292
+ }
293
+
294
+ resolve();
295
+ }
296
+ }
297
+ }
298
+ });
299
+ },
300
+ /**
301
+ * 显示
302
+ * @param popsType
303
+ * @param instConfigList
304
+ * @param guid
305
+ * @param config
306
+ * @param animElement
307
+ * @param maskElement
308
+ */
309
+ show(
310
+ popsType: PopsInstStoreType,
311
+ instConfigList: PopsInstCommonConfig[],
312
+ guid: string,
313
+ config:
314
+ | PopsAlertDetails
315
+ | PopsDrawerDetails
316
+ | PopsPromptDetails
317
+ | PopsConfirmDetails
318
+ | PopsIframeDetails
319
+ | PopsLoadingDetails
320
+ | PopsPanelDetails
321
+ | PopsFolderDetails,
322
+ animElement: HTMLElement,
323
+ maskElement?: HTMLElement
324
+ ) {
325
+ return new Promise<void>((resolve) => {
326
+ const popsElement = animElement.querySelector<HTMLDivElement>(".pops[type-value]")!;
327
+ if (popsType === "drawer") {
328
+ const drawerConfig = config as PopsDrawerDetails;
329
+ popsUtils.setTimeout(() => {
330
+ popsDOMUtils.css(maskElement!, "display", "");
331
+ const direction = drawerConfig.direction!;
332
+ const size = drawerConfig.size!.toString();
333
+ if (["top", "bottom"].includes(direction)) {
334
+ popsElement.style.setProperty("height", size);
335
+ } else if (["left", "right"].includes(direction)) {
336
+ popsElement.style.setProperty("width", size);
337
+ } else {
338
+ console.error("未知direction:", direction);
339
+ }
340
+ resolve();
341
+ }, drawerConfig.openDelay ?? 0);
342
+ } else {
343
+ const fintInst = instConfigList.find((instConfigItem) => instConfigItem.guid === guid);
344
+ if (fintInst) {
345
+ const instConfigItem = fintInst;
346
+ instConfigItem.animElement.style.width = "";
347
+ instConfigItem.animElement.style.height = "";
348
+ Reflect.set(
349
+ instConfigItem.animElement.style,
350
+ "animation-name",
351
+ instConfigItem.animElement!.getAttribute("anim")!.replace("-reverse", "")
352
+ );
353
+ if (PopsAnimation.hasAnim(Reflect.get(instConfigItem.animElement.style, "animation-name"))) {
354
+ /**
355
+ * 动画结束的回调
356
+ */
357
+ function animationendCallBack() {
358
+ popsDOMUtils.off(
359
+ instConfigItem.animElement,
360
+ popsDOMUtils.getAnimationEndNameList(),
361
+ animationendCallBack,
362
+ {
363
+ capture: true,
364
+ }
365
+ );
366
+ resolve();
367
+ }
368
+ instConfigItem.animElement.style.display = "";
369
+ if (instConfigItem.maskElement) {
370
+ instConfigItem.maskElement.style.display = "";
371
+ }
372
+ popsDOMUtils.on(instConfigItem.animElement, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
373
+ capture: true,
374
+ });
375
+ } else {
376
+ instConfigItem.animElement.style.display = "";
377
+ if (instConfigItem.maskElement) {
378
+ instConfigItem.maskElement.style.display = "";
379
+ }
380
+ resolve();
381
+ }
382
+ }
383
+ }
384
+ });
385
+ },
386
+ /**
387
+ * 关闭
388
+ * @param popsType
389
+ * @param instConfigList
390
+ * @param guid
391
+ * @param config
392
+ * @param animElement
393
+ */
394
+ close(
395
+ popsType: string,
396
+ instConfigList: PopsInstCommonConfig[],
397
+ guid: string,
398
+ config:
399
+ | PopsAlertDetails
400
+ | PopsDrawerDetails
401
+ | PopsPromptDetails
402
+ | PopsConfirmDetails
403
+ | PopsIframeDetails
404
+ | PopsLoadingDetails
405
+ | PopsPanelDetails
406
+ | PopsFolderDetails,
407
+ animElement: HTMLElement
408
+ ) {
409
+ return new Promise<void>((resolve) => {
410
+ const popsElement = animElement.querySelector<HTMLDivElement>(".pops[type-value]")!;
411
+ const drawerConfig = config as Required<PopsDrawerDetails>;
412
+ /**
413
+ * 动画结束事件
414
+ */
415
+ function transitionendEvent() {
416
+ /**
417
+ * 弹窗已关闭的回调
418
+ */
419
+ function closeCallBack(event: Event) {
420
+ if ((event as TransitionEvent).propertyName !== "transform") {
421
+ return;
422
+ }
423
+ popsDOMUtils.off(popsElement, popsDOMUtils.getTransitionEndNameList(), void 0, closeCallBack);
424
+ PopsInstanceUtils.removeInstance([instConfigList], guid);
425
+ resolve();
426
+ }
427
+ /* 监听过渡结束 */
428
+ popsDOMUtils.on(popsElement, popsDOMUtils.getTransitionEndNameList(), closeCallBack);
429
+ const popsTransForm = getComputedStyle(popsElement).transform;
430
+ if (popsTransForm !== "none") {
431
+ popsDOMUtils.trigger(popsElement, popsDOMUtils.getTransitionEndNameList(), void 0, true);
432
+ return;
433
+ }
434
+ if (["top"].includes(drawerConfig.direction)) {
435
+ popsElement.style.setProperty("transform", "translateY(-100%)");
436
+ } else if (["bottom"].includes(drawerConfig.direction)) {
437
+ popsElement.style.setProperty("transform", "translateY(100%)");
438
+ } else if (["left"].includes(drawerConfig.direction)) {
439
+ popsElement.style.setProperty("transform", "translateX(-100%)");
440
+ } else if (["right"].includes(drawerConfig.direction)) {
441
+ popsElement.style.setProperty("transform", "translateX(100%)");
442
+ } else {
443
+ console.error("未知direction:", drawerConfig.direction);
444
+ }
445
+ }
446
+
447
+ if (popsType === "drawer") {
448
+ popsUtils.setTimeout(() => {
449
+ transitionendEvent();
450
+ }, drawerConfig.closeDelay);
451
+ } else {
452
+ PopsInstanceUtils.removeInstance([instConfigList], guid);
453
+ resolve();
454
+ }
455
+ });
456
+ },
457
+ /**
458
+ * 拖拽元素
459
+ * 说明:
460
+ * + 元素的position为absolute或者fixed
461
+ * + 会为元素的
462
+ * @param moveElement 需要拖拽的元素
463
+ * @param options 配置
464
+ */
465
+ drag(
466
+ moveElement: HTMLElement,
467
+ options: {
468
+ dragElement: HTMLElement;
469
+ limit: boolean;
470
+ triggerClick?: boolean;
471
+ extraDistance: number;
472
+ container?: Window | typeof globalThis | HTMLElement;
473
+ moveCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
474
+ endCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
475
+ preventEvent?: (event: TouchEvent | PointerEvent) => boolean;
476
+ }
477
+ ) {
478
+ options = Object.assign(
479
+ {
480
+ limit: true,
481
+ extraDistance: 3,
482
+ container: PopsCore.globalThis,
483
+ triggerClick: true,
484
+ },
485
+ options
486
+ );
487
+ let isMove = false;
488
+ /* 点击元素,left偏移 */
489
+ let clickElementLeftOffset = 0;
490
+ /* 点击元素,top偏移 */
491
+ let clickElementTopOffset = 0;
492
+ const AnyTouch = popsUtils.AnyTouch();
493
+ const anyTouchElement = new AnyTouch(options.dragElement, {
494
+ preventDefault(event: Event) {
495
+ if (typeof options.preventEvent === "function") {
496
+ return options.preventEvent(event as any);
497
+ } else {
498
+ // 返回true阻止滑动
499
+ return true;
500
+ }
501
+ },
502
+ });
503
+ popsDOMUtils.css(options.dragElement, {
504
+ cursor: "move",
505
+ });
506
+ /**
507
+ * 修改移动的元素的style
508
+ */
509
+ function changeMoveElementStyle(element: HTMLElement) {
510
+ const old_transitionDuration = element.style.transitionDuration;
511
+ if (globalThis.getComputedStyle(element).transitionDuration !== "0s") {
512
+ element.style.transitionDuration = "0s";
513
+ }
514
+ return () => {
515
+ element.style.transitionDuration = old_transitionDuration;
516
+ };
517
+ }
518
+ /**
519
+ * 获取容器的高度、宽度,一般是window为容器
520
+ */
521
+ function getContainerWidthOrHeight(container: HTMLElement | Window | typeof globalThis) {
522
+ container = container ?? globalThis;
523
+ return {
524
+ width: popsDOMUtils.width(container),
525
+ height: popsDOMUtils.height(container),
526
+ };
527
+ }
528
+ /**
529
+ * 获取容器的最小left、top偏移
530
+ */
531
+
532
+ function getContainerTopOrLeft(container: HTMLElement | Window | typeof globalThis) {
533
+ container = container ?? globalThis;
534
+ if (popsUtils.isWin(container)) {
535
+ return {
536
+ left: 0,
537
+ top: 0,
538
+ };
539
+ } else {
540
+ const rect = (container as HTMLElement).getBoundingClientRect();
541
+ return {
542
+ left: rect.left,
543
+ top: rect.top,
544
+ };
545
+ }
546
+ }
547
+ // 获取transform偏移
548
+ let transformInfo = popsDOMUtils.getTransform(moveElement);
549
+
550
+ let resumeMoveElementStyle: ((...args: any[]) => any) | null = null;
551
+
552
+ anyTouchElement.on("pan", function (event) {
553
+ if (!isMove) {
554
+ isMove = true;
555
+ const rect = options.dragElement.getBoundingClientRect();
556
+ clickElementLeftOffset = event.x - rect.left;
557
+ clickElementTopOffset = event.y - rect.top;
558
+ transformInfo = popsDOMUtils.getTransform(moveElement);
559
+ //if (event.nativeEvent.offsetX) {
560
+ // clickElementLeftOffset = parseInt(event.nativeEvent.offsetX);
561
+ //} else {
562
+ // clickElementLeftOffset = parseInt(event.getOffset().x);
563
+ //}
564
+ //if (event.nativeEvent.offsetY) {
565
+ // clickElementTopOffset = parseInt(event.nativeEvent.offsetY);
566
+ //} else {
567
+ // clickElementTopOffset = parseInt(event.getOffset().y);
568
+ //}
569
+ resumeMoveElementStyle = changeMoveElementStyle(moveElement);
570
+ }
571
+
572
+ /** 当前移动的left偏移 */
573
+ let currentMoveLeftOffset = event.x - clickElementLeftOffset + transformInfo.transformLeft;
574
+ /** 当前移动的top偏移 */
575
+ let currentMoveTopOffset = event.y - clickElementTopOffset + transformInfo.transformTop;
576
+ /* 拖拽移动 */
577
+ if (event.phase === "move") {
578
+ if (options.limit) {
579
+ /* 限制在容器内移动 */
580
+ /* left偏移最大值 */
581
+ const maxLeftOffset =
582
+ getContainerWidthOrHeight(options.container!).width -
583
+ popsDOMUtils.width(moveElement) +
584
+ transformInfo.transformLeft;
585
+ const { left: minLeftOffset, top: minTopOffset } = getContainerTopOrLeft(options.container!);
586
+ /* top偏移的最大值 */
587
+ const maxTopOffset =
588
+ getContainerWidthOrHeight(options.container!).height -
589
+ popsDOMUtils.height(moveElement) +
590
+ transformInfo.transformTop;
591
+ if (currentMoveLeftOffset > maxLeftOffset) {
592
+ /* 不允许超过容器的最大宽度 */
593
+ currentMoveLeftOffset = maxLeftOffset;
594
+ }
595
+ if (currentMoveTopOffset > maxTopOffset) {
596
+ /* 不允许超过容器的最大高度 */
597
+ currentMoveTopOffset = maxTopOffset;
598
+ }
599
+ if (currentMoveLeftOffset - options.extraDistance * 2 < minLeftOffset + transformInfo.transformLeft) {
600
+ /* 不允许left偏移小于容器最小值 */
601
+ currentMoveLeftOffset = minLeftOffset + transformInfo.transformLeft;
602
+ /* 最左边 +额外距离 */
603
+ currentMoveLeftOffset += options.extraDistance;
604
+ } else {
605
+ /* 最右边 -额外距离 */
606
+ currentMoveLeftOffset -= options.extraDistance;
607
+ }
608
+ if (currentMoveTopOffset - options.extraDistance * 2 < minTopOffset + transformInfo.transformTop) {
609
+ /* 不允许top偏移小于容器最小值 */
610
+ currentMoveTopOffset = minTopOffset + transformInfo.transformTop;
611
+ /* 最上面 +额外距离 */
612
+ currentMoveTopOffset += options.extraDistance;
613
+ } else {
614
+ /* 最下面 -额外距离 */
615
+ currentMoveTopOffset -= options.extraDistance;
616
+ }
617
+ }
618
+ if (typeof options.moveCallBack === "function") {
619
+ options.moveCallBack(moveElement, currentMoveLeftOffset, currentMoveTopOffset);
620
+ }
621
+
622
+ popsDOMUtils.css(moveElement, {
623
+ left: currentMoveLeftOffset + "px",
624
+ top: currentMoveTopOffset + "px",
625
+ });
626
+ }
627
+
628
+ /* 停止拖拽 */
629
+ if (event.phase === "end") {
630
+ isMove = false;
631
+ if (typeof resumeMoveElementStyle === "function") {
632
+ resumeMoveElementStyle();
633
+ resumeMoveElementStyle = null;
634
+ }
635
+ if (typeof options.endCallBack === "function") {
636
+ options.endCallBack(moveElement, currentMoveLeftOffset, currentMoveTopOffset);
637
+ }
638
+ }
639
+ });
640
+ if (options.triggerClick) {
641
+ /* 因为会覆盖上面的点击事件,主动触发一下 */
642
+ anyTouchElement.on(["tap"], function (event) {
643
+ event.changedPoints.forEach((item) => {
644
+ popsDOMUtils.trigger(item.target! as HTMLElement, "click", void 0, true);
645
+ });
646
+ });
647
+ }
648
+ },
649
+ /**
650
+ * 排序数组
651
+ * @param getBeforeValueFun
652
+ * @param getAfterValueFun
653
+ * @param sortByDesc 排序是否降序,默认降序
654
+ */
655
+ sortElementListByProperty<T, R>(
656
+ getBeforeValueFun: (value: T) => R,
657
+ getAfterValueFun: (value: T) => R,
658
+ sortByDesc = true
659
+ ) {
660
+ if (typeof sortByDesc !== "boolean") {
661
+ throw new TypeError("参数 sortByDesc 必须为boolean类型");
662
+ }
663
+ if (getBeforeValueFun == null || getAfterValueFun == null) {
664
+ throw new Error("获取前面的值或后面的值的方法不能为空");
665
+ }
666
+ return function (after_obj: T, before_obj: T) {
667
+ const beforeValue = getBeforeValueFun(before_obj); /* 前 */
668
+ const afterValue = getAfterValueFun(after_obj); /* 后 */
669
+ if (sortByDesc) {
670
+ if (afterValue > beforeValue) {
671
+ return -1;
672
+ } else if (afterValue < beforeValue) {
673
+ return 1;
674
+ } else {
675
+ return 0;
676
+ }
677
+ } else {
678
+ if (afterValue < beforeValue) {
679
+ return -1;
680
+ } else if (afterValue > beforeValue) {
681
+ return 1;
682
+ } else {
683
+ return 0;
684
+ }
685
+ }
686
+ };
687
+ },
688
+ };