@whitesev/pops 1.4.0 → 1.5.0

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 (105) hide show
  1. package/dist/index.amd.js.map +1 -1
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.iife.js.map +1 -1
  5. package/dist/index.system.js.map +1 -1
  6. package/dist/index.umd.js.map +1 -1
  7. package/package.json +50 -48
  8. package/src/Config.ts +3 -0
  9. package/src/Core.ts +45 -0
  10. package/src/Pops.ts +340 -0
  11. package/src/components/alert/index.css +45 -0
  12. package/src/components/alert/index.ts +216 -0
  13. package/src/components/alert/indexType.ts +30 -0
  14. package/src/components/confirm/index.css +45 -0
  15. package/src/components/confirm/index.ts +264 -0
  16. package/src/components/confirm/indexType.ts +17 -0
  17. package/src/components/drawer/index.css +47 -0
  18. package/src/components/drawer/index.ts +338 -0
  19. package/src/components/drawer/indexType.ts +53 -0
  20. package/src/components/folder/folderIcon.ts +28 -0
  21. package/src/components/folder/index.css +291 -0
  22. package/src/components/folder/index.ts +1111 -0
  23. package/src/components/folder/indexType.ts +87 -0
  24. package/src/components/iframe/index.css +90 -0
  25. package/src/components/iframe/index.ts +415 -0
  26. package/src/components/iframe/indexType.ts +144 -0
  27. package/src/components/loading/index.css +60 -0
  28. package/src/components/loading/index.ts +123 -0
  29. package/src/components/loading/indexType.ts +31 -0
  30. package/src/components/panel/buttonType.ts +60 -0
  31. package/src/components/panel/commonType.ts +50 -0
  32. package/src/components/panel/deepMenuType.ts +59 -0
  33. package/src/components/panel/formsType.ts +32 -0
  34. package/src/components/panel/index.css +754 -0
  35. package/src/components/panel/index.ts +2435 -0
  36. package/src/components/panel/indexType.ts +107 -0
  37. package/src/components/panel/inputType.ts +65 -0
  38. package/src/components/panel/ownType.ts +28 -0
  39. package/src/components/panel/selectType.ts +80 -0
  40. package/src/components/panel/sliderType.ts +59 -0
  41. package/src/components/panel/switchType.ts +43 -0
  42. package/src/components/panel/textareaType.ts +54 -0
  43. package/src/components/prompt/index.css +60 -0
  44. package/src/components/prompt/index.ts +293 -0
  45. package/src/components/prompt/indexType.ts +47 -0
  46. package/src/components/rightClickMenu/index.ts +729 -0
  47. package/src/components/rightClickMenu/indexType.ts +89 -0
  48. package/src/components/searchSuggestion/index.css +0 -0
  49. package/src/components/searchSuggestion/index.ts +656 -0
  50. package/src/components/searchSuggestion/indexType.ts +238 -0
  51. package/src/components/tooltip/index.css +171 -0
  52. package/src/components/tooltip/index.ts +358 -0
  53. package/src/components/tooltip/indexType.ts +95 -0
  54. package/src/css/animation.css +2240 -0
  55. package/src/css/button.css +290 -0
  56. package/src/css/common.css +24 -0
  57. package/src/css/index.css +135 -0
  58. package/src/css/ninePalaceGridPosition.css +50 -0
  59. package/src/css/scrollbar.css +18 -0
  60. package/src/handler/PopsElementHandler.ts +353 -0
  61. package/src/handler/PopsHandler.ts +659 -0
  62. package/src/svg/arrowLeft.svg +4 -0
  63. package/src/svg/arrowRight.svg +4 -0
  64. package/src/svg/chromeFilled.svg +14 -0
  65. package/src/svg/circleClose.svg +8 -0
  66. package/src/svg/close.svg +5 -0
  67. package/src/svg/cpu.svg +8 -0
  68. package/src/svg/delete.svg +5 -0
  69. package/src/svg/documentCopy.svg +5 -0
  70. package/src/svg/edit.svg +8 -0
  71. package/src/svg/eleme.svg +5 -0
  72. package/src/svg/elemePlus.svg +5 -0
  73. package/src/svg/headset.svg +5 -0
  74. package/src/svg/hide.svg +8 -0
  75. package/src/svg/keyboard.svg +8 -0
  76. package/src/svg/loading.svg +5 -0
  77. package/src/svg/max.svg +5 -0
  78. package/src/svg/min.svg +5 -0
  79. package/src/svg/mise.svg +5 -0
  80. package/src/svg/monitor.svg +5 -0
  81. package/src/svg/next.svg +5 -0
  82. package/src/svg/picture.svg +8 -0
  83. package/src/svg/prev.svg +5 -0
  84. package/src/svg/search.svg +5 -0
  85. package/src/svg/share.svg +5 -0
  86. package/src/svg/upload.svg +5 -0
  87. package/src/svg/videoPause.svg +5 -0
  88. package/src/svg/videoPlay.svg +5 -0
  89. package/src/svg/view.svg +5 -0
  90. package/src/types/PopsDOMUtilsEventType.d.ts +246 -0
  91. package/src/types/animation.d.ts +19 -0
  92. package/src/types/button.d.ts +226 -0
  93. package/src/types/components.d.ts +197 -0
  94. package/src/types/event.d.ts +62 -0
  95. package/src/types/global.d.ts +11 -0
  96. package/src/types/icon.d.ts +32 -0
  97. package/src/types/layer.d.ts +20 -0
  98. package/src/types/main.d.ts +136 -0
  99. package/src/types/mask.d.ts +35 -0
  100. package/src/types/position.d.ts +60 -0
  101. package/src/utils/AnyTouch.js +1394 -0
  102. package/src/utils/PopsDOMUtils.ts +2013 -0
  103. package/src/utils/PopsInstanceUtils.ts +685 -0
  104. package/src/utils/PopsMathUtils.ts +77 -0
  105. package/src/utils/PopsUtils.ts +380 -0
@@ -0,0 +1,358 @@
1
+ import { PopsHandler } from "../../handler/PopsHandler";
2
+ import { pops } from "../../Pops";
3
+ import { popsDOMUtils } from "../../utils/PopsDOMUtils";
4
+ import { popsUtils } from "../../utils/PopsUtils";
5
+ import type { PopsToolTipDetails, PopsTooltipPosition } from "./indexType";
6
+
7
+ export class PopsTooltip {
8
+ constructor(details: PopsToolTipDetails) {
9
+ const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow();
10
+ PopsHandler.handleInit($shadowRoot, [
11
+ pops.config.cssText.index,
12
+ pops.config.cssText.anim,
13
+ pops.config.cssText.common,
14
+ pops.config.cssText.tooltipCSS,
15
+ ]);
16
+
17
+ let config: Required<PopsToolTipDetails> = {
18
+ // @ts-ignore
19
+ target: null,
20
+ content: "默认文字",
21
+
22
+ position: "top",
23
+ className: "",
24
+ alwaysShow: false,
25
+ triggerShowEventName: "mouseenter touchstart",
26
+ triggerCloseEventName: "mouseleave touchend",
27
+ zIndex: 10000,
28
+ only: false,
29
+ eventOption: {
30
+ passive: false,
31
+ capture: true,
32
+ once: false,
33
+ },
34
+ showBeforeCallBack() {},
35
+ showAfterCallBack() {},
36
+ closeBeforeCallBack() {},
37
+ closeAfterCallBack() {},
38
+ arrowDistance: 12.5,
39
+ otherDistance: 0,
40
+
41
+ style: "",
42
+ beforeAppendToPageCallBack() {},
43
+ };
44
+ config = popsUtils.assign(config, details);
45
+ if (!(config.target instanceof HTMLElement)) {
46
+ throw "config.target 必须是HTMLElement类型";
47
+ }
48
+ let guid = popsUtils.getRandomGUID();
49
+ const PopsType = "tooltip";
50
+
51
+ config = PopsHandler.handleOnly(PopsType, config);
52
+ function getContent() {
53
+ return typeof config.content === "function"
54
+ ? config.content()
55
+ : config.content;
56
+ }
57
+ /**
58
+ * 获取悬浮提示的元素信息
59
+ */
60
+ function getToolTipElementInfo() {
61
+ let _toolTipHTML_ = `<div class="pops-tip"></div>`;
62
+ let _toolTipElement_ =
63
+ popsUtils.parseTextToDOM<HTMLDivElement>(_toolTipHTML_);
64
+ if (
65
+ typeof config.className === "string" &&
66
+ config.className.trim() !== ""
67
+ ) {
68
+ popsDOMUtils.addClassName(_toolTipElement_, config.className);
69
+ }
70
+ _toolTipElement_.setAttribute("data-guid", guid);
71
+
72
+ _toolTipElement_.style.zIndex = config.zIndex.toString();
73
+ _toolTipElement_.innerHTML = `<div style="text-align: center;">${getContent()}</div>`;
74
+ /* 箭头元素 */
75
+ let _toolTipArrowHTML_ = '<div class="pops-tip-arrow"></div>';
76
+ let _toolTipArrowNode_ =
77
+ popsUtils.parseTextToDOM<HTMLDivElement>(_toolTipArrowHTML_);
78
+ _toolTipElement_.appendChild(_toolTipArrowNode_);
79
+ if (config.style != null) {
80
+ /* 添加自定义style */
81
+ let cssNode = document.createElement("style");
82
+ cssNode.setAttribute("type", "text/css");
83
+ cssNode.innerHTML = config.style;
84
+ _toolTipElement_.appendChild(cssNode);
85
+ }
86
+ return {
87
+ toolTipElement: _toolTipElement_,
88
+ toolTipArrowElement: _toolTipArrowNode_,
89
+ toolTipHTML: _toolTipHTML_,
90
+ toolTipArrowHTML: _toolTipArrowHTML_,
91
+ };
92
+ }
93
+
94
+ config.position =
95
+ config.position.toLowerCase() as any as PopsTooltipPosition;
96
+ let { toolTipElement } = getToolTipElementInfo();
97
+
98
+ /**
99
+ * 设置 提示框的位置
100
+ */
101
+ function setToolTipPosition(positionDetails: any) {
102
+ let positionDetail = positionDetails[config.position.toUpperCase()];
103
+ if (positionDetail) {
104
+ toolTipElement.style.left = positionDetail.left + "px";
105
+ toolTipElement.style.top = positionDetail.top + "px";
106
+ toolTipElement.setAttribute("data-motion", positionDetail.motion);
107
+
108
+ toolTipElement
109
+ .querySelector<HTMLDivElement>(".pops-tip-arrow")
110
+ ?.setAttribute("data-position", positionDetail.arrow);
111
+ } else {
112
+ console.error("不存在该位置", config.position);
113
+ }
114
+ }
115
+
116
+ /**
117
+ * 获取 提示框的位置
118
+ * @param targetElement 目标元素
119
+ * @param arrowDistance 箭头和目标元素的距离
120
+ * @param otherDistance 其它位置的偏移
121
+ */
122
+ function getToolTipPosition(
123
+ targetElement: HTMLElement,
124
+ arrowDistance: number,
125
+ otherDistance: number
126
+ ) {
127
+ let targetElement_width = popsDOMUtils.offset(targetElement).width;
128
+ let targetElement_height = popsDOMUtils.offset(targetElement).height;
129
+ let targetElement_top = popsDOMUtils.offset(targetElement).top;
130
+
131
+ // let targetElement_bottom = popsDOMUtils.offset(targetElement).bottom;
132
+ let targetElement_left = popsDOMUtils.offset(targetElement).left;
133
+
134
+ // let targetElement_right = popsDOMUtils.offset(targetElement).right;
135
+
136
+ let toolTipElement_width = popsDOMUtils.outerWidth(toolTipElement);
137
+ let toolTipElement_height = popsDOMUtils.outerHeight(toolTipElement);
138
+ /* 目标元素的x轴的中间位置 */
139
+ let targetElement_X_center_pos =
140
+ targetElement_left + targetElement_width / 2 - toolTipElement_width / 2;
141
+ /* 目标元素的Y轴的中间位置 */
142
+ let targetElement_Y_center_pos =
143
+ targetElement_top +
144
+ targetElement_height / 2 -
145
+ toolTipElement_height / 2;
146
+ return {
147
+ TOP: {
148
+ left: targetElement_X_center_pos - otherDistance,
149
+ top: targetElement_top - toolTipElement_height - arrowDistance,
150
+ arrow: "bottom",
151
+ motion: "fadeInTop",
152
+ },
153
+ RIGHT: {
154
+ left: targetElement_left + targetElement_width + arrowDistance,
155
+ top: targetElement_Y_center_pos + otherDistance,
156
+ arrow: "left",
157
+ motion: "fadeInRight",
158
+ },
159
+ BOTTOM: {
160
+ left: targetElement_X_center_pos - otherDistance,
161
+ top: targetElement_top + targetElement_height + arrowDistance,
162
+ arrow: "top",
163
+ motion: "fadeInBottom",
164
+ },
165
+ LEFT: {
166
+ left: targetElement_left - toolTipElement_width - arrowDistance,
167
+ top: targetElement_Y_center_pos + otherDistance,
168
+ arrow: "right",
169
+ motion: "fadeInLeft",
170
+ },
171
+ };
172
+ }
173
+
174
+ /**
175
+ * 显示提示框
176
+ */
177
+ function showToolTipNode() {
178
+ if (typeof config.showBeforeCallBack === "function") {
179
+ let result = config.showBeforeCallBack();
180
+ if (typeof result === "boolean" && !result) {
181
+ return;
182
+ }
183
+ }
184
+
185
+ if (!popsUtils.contains($shadowRoot, toolTipElement)) {
186
+ popsDOMUtils.append($shadowRoot, toolTipElement);
187
+ }
188
+
189
+ if (!popsUtils.contains($shadowContainer)) {
190
+ if (typeof config.beforeAppendToPageCallBack === "function") {
191
+ config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
192
+ }
193
+ popsDOMUtils.append(document.body, $shadowContainer);
194
+ }
195
+ setToolTipPosition(
196
+ getToolTipPosition(
197
+ config.target,
198
+ config.arrowDistance,
199
+ config.otherDistance
200
+ )
201
+ );
202
+ if (typeof config.showAfterCallBack === "function") {
203
+ config.showAfterCallBack(toolTipElement);
204
+ }
205
+ }
206
+ /**
207
+ * 关闭提示框
208
+ */
209
+ function closeToolTipNode() {
210
+ if (typeof config.closeBeforeCallBack === "function") {
211
+ let result = config.closeBeforeCallBack(toolTipElement);
212
+ if (typeof result === "boolean" && !result) {
213
+ return;
214
+ }
215
+ }
216
+ toolTipElement.setAttribute(
217
+ "data-motion",
218
+ toolTipElement.getAttribute("data-motion")!.replace("fadeIn", "fadeOut")
219
+ );
220
+ if (typeof config.closeAfterCallBack === "function") {
221
+ config.closeAfterCallBack(toolTipElement);
222
+ }
223
+ }
224
+ /**
225
+ * 绑定 显示事件
226
+ */
227
+ function onShowEvent() {
228
+ popsDOMUtils.on(
229
+ config.target,
230
+ config.triggerShowEventName,
231
+ showToolTipNode,
232
+ config.eventOption
233
+ );
234
+ }
235
+ /**
236
+ * 绑定 关闭事件
237
+ */
238
+ function onCloseEvent() {
239
+ popsDOMUtils.on(
240
+ config.target,
241
+ config.triggerCloseEventName,
242
+ closeToolTipNode,
243
+ config.eventOption
244
+ );
245
+ }
246
+ /**
247
+ * 取消绑定 显示事件
248
+ */
249
+ function offShowEvent() {
250
+ popsDOMUtils.off(
251
+ config.target,
252
+ config.triggerShowEventName,
253
+ showToolTipNode,
254
+ {
255
+ capture: true,
256
+ }
257
+ );
258
+ }
259
+ /**
260
+ * 取消绑定 关闭事件
261
+ */
262
+ function offCloseEvent() {
263
+ popsDOMUtils.off(
264
+ config.target,
265
+ config.triggerCloseEventName,
266
+ closeToolTipNode,
267
+ {
268
+ capture: true,
269
+ }
270
+ );
271
+ }
272
+
273
+ /**
274
+ * 即使存在动画属性,但是当前设置的动画Out结束后移除元素
275
+ */
276
+ function endEvent() {
277
+ if (toolTipElement.getAttribute("data-motion")!.includes("In")) {
278
+ return;
279
+ }
280
+ toolTipElement.remove();
281
+ }
282
+ if (config.alwaysShow) {
283
+ /* 总是显示 */
284
+ showToolTipNode();
285
+ return {
286
+ guid: guid,
287
+ config: config,
288
+ toolTipNode: toolTipElement,
289
+ show: showToolTipNode,
290
+ close() {
291
+ popsDOMUtils.on(
292
+ toolTipElement,
293
+ popsDOMUtils.getAnimationEndNameList(),
294
+ endEvent,
295
+ config.eventOption
296
+ );
297
+ closeToolTipNode();
298
+ },
299
+ off: null,
300
+ on: null,
301
+ };
302
+ } else {
303
+ /* 事件触发才显示 */
304
+
305
+ /**
306
+ * 当鼠标|手触摸,暂停当前动画
307
+ */
308
+ popsDOMUtils.on(
309
+ toolTipElement,
310
+ "mouseenter touchstart",
311
+ () => {
312
+ toolTipElement.style.animationPlayState = "paused";
313
+ // if (parseInt(getComputedStyle(toolTipElement)) > 0.5) {
314
+ // toolTipElement.style.animationPlayState = "paused";
315
+ // }
316
+ },
317
+ config.eventOption
318
+ );
319
+ /**
320
+ * 当鼠标|手离开,开始当前动画
321
+ */
322
+ popsDOMUtils.on(
323
+ toolTipElement,
324
+ "mouseleave touchend",
325
+ () => {
326
+ toolTipElement.style.animationPlayState = "running";
327
+ },
328
+ config.eventOption
329
+ );
330
+ popsDOMUtils.on(
331
+ toolTipElement,
332
+ popsDOMUtils.getAnimationEndNameList(),
333
+ endEvent,
334
+ config.eventOption
335
+ );
336
+
337
+ onShowEvent();
338
+ onCloseEvent();
339
+ return {
340
+ guid: guid,
341
+ $shadowContainer: $shadowContainer,
342
+ $shadowRoot: $shadowRoot,
343
+ config: config,
344
+ toolTipNode: toolTipElement,
345
+ show: showToolTipNode,
346
+ close: closeToolTipNode,
347
+ off() {
348
+ offShowEvent();
349
+ offCloseEvent();
350
+ },
351
+ on() {
352
+ onShowEvent();
353
+ onCloseEvent();
354
+ },
355
+ };
356
+ }
357
+ }
358
+ }
@@ -0,0 +1,95 @@
1
+ /** tooltip的出现位置 */
2
+ export type PopsTooltipPosition = "top" | "right" | "bottom" | "left";
3
+
4
+ /**
5
+ * pops.tooltip
6
+ */
7
+ export interface PopsToolTipDetails {
8
+ /**
9
+ * 目标元素
10
+ */
11
+ target: HTMLElement;
12
+ /**
13
+ * 显示的文字
14
+ */
15
+ content: string | (() => string);
16
+ /**
17
+ * 位置,默认top
18
+ */
19
+ position?: PopsTooltipPosition;
20
+ /**
21
+ * 自定义className,默认为空
22
+ * + github-tooltip
23
+ */
24
+ className?: string;
25
+ /**
26
+ * 是否总是显示,默认为false
27
+ * + true 设置的triggerShowEventName、triggerCloseEventName将无效
28
+ * 返回提供show和close函数,取消on和off
29
+ * + false 返回提供on和off,取消close函数
30
+ */
31
+ alwaysShow?: boolean;
32
+ /**
33
+ * 触发显示事件的名称,默认mouseenter touchstart,如果是多个事件,按空格分割
34
+ */
35
+ triggerShowEventName?: string;
36
+ /**
37
+ * 触发关闭事件的名称,默认mouseleave touchend,如果是多个事件,按空格分割
38
+ */
39
+ triggerCloseEventName?: string;
40
+ /**
41
+ * z-index,默认10000
42
+ */
43
+ zIndex?: number;
44
+ /**
45
+ * 是否唯一,默认false
46
+ */
47
+ only?: boolean;
48
+ /**
49
+ * 监听的事件配置
50
+ */
51
+ eventOption?: AddEventListenerOptions;
52
+ /**
53
+ * 触发显示前的回调
54
+ * 返回值为false可阻止显示
55
+ */
56
+ showBeforeCallBack?: () => boolean | void;
57
+ /**
58
+ * 触发显示后的回调
59
+ */
60
+ showAfterCallBack?: (toolTipElement: HTMLElement) => void;
61
+ /**
62
+ * 触发关闭前的回调
63
+ * 返回值为false可阻止关闭
64
+ */
65
+ closeBeforeCallBack?: (toolTipElement: HTMLElement) => boolean | void;
66
+ /**
67
+ * 触发关闭后的回调
68
+ */
69
+ closeAfterCallBack?: (toolTipElement: HTMLElement) => void;
70
+ /**
71
+ * 箭头与目标的的距离,默认12.5(px)
72
+ */
73
+ arrowDistance?: number;
74
+ /**
75
+ * 其它的距离,默认0(px)
76
+ * + 当position为left或者right,这个距离是上、下距离
77
+ * + 当position为top或者bottom,这个距离是左、右距离
78
+ */
79
+ otherDistance?: number;
80
+ /**
81
+ * (可选)自定义style
82
+ */
83
+ style?: string;
84
+ /**
85
+ * 在元素添加到页面前的事件
86
+ *
87
+ * 当tooltip添加到ShadowRoot内时也会触发
88
+ * @param $shadowRoot 根元素
89
+ * @param $shadowContainer 容器
90
+ */
91
+ beforeAppendToPageCallBack?: (
92
+ $shadowRoot: ShadowRoot,
93
+ $shadowContainer: HTMLDivElement
94
+ ) => void;
95
+ }