@whitesev/pops 2.2.7 → 2.2.9

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