@whitesev/pops 3.2.2 → 3.3.1

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 (63) hide show
  1. package/dist/index.amd.js +161 -325
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.amd.min.js +1 -1
  4. package/dist/index.amd.min.js.map +1 -1
  5. package/dist/index.cjs.js +161 -325
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/index.cjs.min.js +1 -1
  8. package/dist/index.cjs.min.js.map +1 -1
  9. package/dist/index.esm.js +161 -325
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/index.esm.min.js +1 -1
  12. package/dist/index.esm.min.js.map +1 -1
  13. package/dist/index.iife.js +161 -325
  14. package/dist/index.iife.js.map +1 -1
  15. package/dist/index.iife.min.js +1 -1
  16. package/dist/index.iife.min.js.map +1 -1
  17. package/dist/index.system.js +161 -325
  18. package/dist/index.system.js.map +1 -1
  19. package/dist/index.system.min.js +1 -1
  20. package/dist/index.system.min.js.map +1 -1
  21. package/dist/index.umd.js +161 -325
  22. package/dist/index.umd.js.map +1 -1
  23. package/dist/index.umd.min.js +1 -1
  24. package/dist/index.umd.min.js.map +1 -1
  25. package/dist/types/src/Pops.d.ts +5 -0
  26. package/dist/types/src/PopsCore.d.ts +16 -8
  27. package/dist/types/src/components/panel/handlerComponents.d.ts +8 -4
  28. package/dist/types/src/components/panel/types/components-switch.d.ts +12 -2
  29. package/dist/types/src/components/rightClickMenu/types/index.d.ts +1 -1
  30. package/dist/types/src/components/searchSuggestion/index.d.ts +1 -1
  31. package/dist/types/src/components/searchSuggestion/types/index.d.ts +1 -1
  32. package/dist/types/src/components/tooltip/index.d.ts +2 -0
  33. package/dist/types/src/components/tooltip/types/index.d.ts +1 -1
  34. package/dist/types/src/config/GlobalConfig.d.ts +2 -0
  35. package/dist/types/src/handler/PopsElementHandler.d.ts +13 -1
  36. package/dist/types/src/types/components.d.ts +12 -0
  37. package/package.json +5 -6
  38. package/src/PopsCore.ts +31 -15
  39. package/src/components/alert/defaultConfig.ts +2 -0
  40. package/src/components/alert/index.ts +2 -2
  41. package/src/components/confirm/defaultConfig.ts +2 -0
  42. package/src/components/drawer/defaultConfig.ts +2 -0
  43. package/src/components/folder/defaultConfig.ts +2 -0
  44. package/src/components/iframe/defaultConfig.ts +2 -0
  45. package/src/components/loading/defaultConfig.ts +2 -0
  46. package/src/components/panel/defaultConfig.ts +2 -0
  47. package/src/components/panel/handlerComponents.ts +38 -21
  48. package/src/components/panel/index.css +1 -0
  49. package/src/components/panel/types/components-switch.ts +12 -2
  50. package/src/components/prompt/defaultConfig.ts +2 -0
  51. package/src/components/rightClickMenu/defaultConfig.ts +2 -0
  52. package/src/components/rightClickMenu/index.ts +7 -12
  53. package/src/components/rightClickMenu/types/index.ts +1 -1
  54. package/src/components/searchSuggestion/defaultConfig.ts +2 -0
  55. package/src/components/searchSuggestion/index.ts +13 -13
  56. package/src/components/searchSuggestion/types/index.ts +1 -1
  57. package/src/components/tooltip/defaultConfig.ts +2 -0
  58. package/src/components/tooltip/index.ts +7 -8
  59. package/src/components/tooltip/types/index.ts +1 -1
  60. package/src/css/index.css +1 -0
  61. package/src/handler/PopsElementHandler.ts +64 -12
  62. package/src/types/components.d.ts +12 -0
  63. package/src/utils/PopsUtils.ts +5 -35
@@ -1,13 +1,14 @@
1
+ import { PopsCommonCSSClassName } from "../../config/CommonCSSClassName";
2
+ import { GlobalConfig } from "../../config/GlobalConfig";
3
+ import { PopsElementHandler } from "../../handler/PopsElementHandler";
1
4
  import { PopsHandler } from "../../handler/PopsHandler";
5
+ import { PopsCSS } from "../../PopsCSS";
6
+ import type { PopsType } from "../../types/main";
2
7
  import { popsDOMUtils } from "../../utils/PopsDOMUtils";
8
+ import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
3
9
  import { popsUtils } from "../../utils/PopsUtils";
4
10
  import { PopsSearchSuggestionDefaultConfig } from "./defaultConfig";
5
- import { GlobalConfig } from "../../config/GlobalConfig";
6
- import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
7
- import type { PopsSearchSuggestionData, PopsSearchSuggestionConfig } from "./types/index";
8
- import { PopsCSS } from "../../PopsCSS";
9
- import type { PopsType } from "../../types/main";
10
- import { PopsCommonCSSClassName } from "../../config/CommonCSSClassName";
11
+ import type { PopsSearchSuggestionConfig, PopsSearchSuggestionData } from "./types/index";
11
12
 
12
13
  export const PopsSearchSuggestion = {
13
14
  init<T>(__config__: PopsSearchSuggestionConfig<T>) {
@@ -39,13 +40,12 @@ export const PopsSearchSuggestion = {
39
40
  },
40
41
  ]);
41
42
 
42
- if (config.style != null) {
43
- const $css = popsDOMUtils.createElement("style", {
44
- type: "text/css",
45
- innerHTML: config.style,
46
- });
47
- $shadowRoot.appendChild($css);
48
- }
43
+ // 添加自定义style
44
+ PopsElementHandler.addStyle($shadowRoot, config.style);
45
+ // 添加自定义浅色style
46
+ PopsElementHandler.addLightStyle($shadowRoot, config.lightStyle);
47
+ // 添加自定义深色style
48
+ PopsElementHandler.addDarkStyle($shadowRoot, config.darkStyle);
49
49
  /**
50
50
  * 监听器的默认配置
51
51
  */
@@ -106,7 +106,7 @@ export type PopsSearchSuggestionData<T> = {
106
106
  */
107
107
  export interface PopsSearchSuggestionConfig<T = any> extends Pick<
108
108
  PopsGeneralConfig,
109
- "useShadowRoot" | "zIndex" | "style"
109
+ "useShadowRoot" | "zIndex" | "style" | "lightStyle" | "darkStyle"
110
110
  > {
111
111
  /**
112
112
  * 当前的环境,可以是document,可以是shadowroot,默认是document
@@ -28,6 +28,8 @@ export const PopsTooltipDefaultConfig = (): DeepRequired<PopsToolTipConfig> => {
28
28
  arrowDistance: 12.5,
29
29
  otherDistance: 0,
30
30
  style: "",
31
+ lightStyle: null,
32
+ darkStyle: null,
31
33
  beforeAppendToPageCallBack() {},
32
34
  };
33
35
  };
@@ -1,4 +1,5 @@
1
1
  import { GlobalConfig } from "../../config/GlobalConfig";
2
+ import { PopsElementHandler } from "../../handler/PopsElementHandler";
2
3
  import { PopsHandler } from "../../handler/PopsHandler";
3
4
  import { PopsCSS } from "../../PopsCSS";
4
5
  import type { PopsType } from "../../types/main";
@@ -85,14 +86,12 @@ export class ToolTip {
85
86
  popsDOMUtils.addClassName($toolTipContainer, this.$data.config.className);
86
87
  // 添加z-index
87
88
  $toolTipContainer.style.zIndex = PopsHandler.handleZIndex(this.$data.config.zIndex).toString();
88
- if (this.$data.config.style != null) {
89
- // 添加自定义style
90
- const cssNode = popsDOMUtils.createElement("style", {
91
- type: "text/css",
92
- innerHTML: this.$data.config.style,
93
- });
94
- $toolTipContainer.appendChild(cssNode);
95
- }
89
+ // 添加自定义style
90
+ PopsElementHandler.addStyle($toolTipContainer, this.$data.config.style);
91
+ // 添加自定义浅色style
92
+ PopsElementHandler.addLightStyle($toolTipContainer, this.$data.config.lightStyle);
93
+ // 添加自定义深色style
94
+ PopsElementHandler.addDarkStyle($toolTipContainer, this.$data.config.darkStyle);
96
95
  // 处理是否显示箭头元素
97
96
  if (!this.$data.config.showArrow) {
98
97
  $toolTipArrow.remove();
@@ -9,7 +9,7 @@ export type PopsTooltipPosition = "top" | "right" | "bottom" | "left" | "follow"
9
9
  */
10
10
  export interface PopsToolTipConfig extends Pick<
11
11
  PopsGeneralConfig,
12
- "useShadowRoot" | "only" | "zIndex" | "style" | "beforeAppendToPageCallBack"
12
+ "useShadowRoot" | "only" | "zIndex" | "style" | "lightStyle" | "darkStyle" | "beforeAppendToPageCallBack"
13
13
  > {
14
14
  /**
15
15
  * 目标元素
package/src/css/index.css CHANGED
@@ -28,6 +28,7 @@
28
28
  .pops {
29
29
  --pops-mask-bg-opacity: 0.8;
30
30
  --pops-color: #ffffff;
31
+ --pops-dark-color: #262626;
31
32
  --pops-bg-color: rgb(17, 17, 17, var(--pops-bg-opacity));
32
33
  --pops-bd-color: rgb(55, 55, 55, var(--pops-bd-opacity));
33
34
  --pops-box-shadow-color: rgba(81, 81, 81, 0.12);
@@ -1,18 +1,18 @@
1
1
  import type { PopsAlertConfig } from "../components/alert/types";
2
2
  import type { PopsConfirmConfig } from "../components/confirm/types";
3
3
  import type { PopsIframeConfig } from "../components/iframe/types";
4
+ import { PopsIcon } from "../PopsIcon";
4
5
  import type { PopsIconType } from "../types/icon";
5
6
  import type {
6
7
  PopsSupportAnimConfig,
7
- PopsSupportBottomButtonConfig,
8
- PopsSupportContentConfig,
9
- PopsSupportHeaderTitleConfig,
10
8
  PopsSupportAnimConfigType,
9
+ PopsSupportBottomButtonConfig,
11
10
  PopsSupportBottomButtonConfigType,
11
+ PopsSupportContentConfig,
12
12
  PopsSupportContentConfigType,
13
+ PopsSupportHeaderTitleConfig,
13
14
  PopsSupportHeaderTitleConfigType,
14
15
  } from "../types/main";
15
- import { PopsIcon } from "../PopsIcon";
16
16
  import { popsDOMUtils } from "../utils/PopsDOMUtils";
17
17
 
18
18
  export const PopsElementHandler = {
@@ -46,25 +46,27 @@ export const PopsElementHandler = {
46
46
  bottomBtnHTML = "",
47
47
  zIndex: number
48
48
  ) {
49
- const __config = config as PopsAlertConfig;
49
+ const __config__ = config as PopsAlertConfig;
50
50
  let popsAnimStyle = "";
51
51
  let popsStyle = "";
52
- const popsPosition = __config.position || "";
52
+ const popsPosition = __config__.position || "";
53
53
  if (config.zIndex != null) {
54
54
  popsAnimStyle += `z-index: ${zIndex};`;
55
55
  popsStyle += `z-index: ${zIndex};`;
56
56
  }
57
- if (__config.width != null) {
58
- popsStyle += `width: ${__config.width};`;
57
+ if (__config__.width != null) {
58
+ popsStyle += `width: ${__config__.width};`;
59
59
  }
60
- if (__config.height != null) {
61
- popsStyle += `height: ${__config.height};`;
60
+ if (__config__.height != null) {
61
+ popsStyle += `height: ${__config__.height};`;
62
62
  }
63
63
  const hasBottomBtn = bottomBtnHTML.trim() === "" ? false : true;
64
64
  return /*html*/ `
65
- <div class="pops-anim" anim="${__config.animation || ""}" style="${popsAnimStyle}" data-guid="${guid}">${
66
- config.style != null ? `<style tyle="text/css">${config.style}</style>` : ""
65
+ <div class="pops-anim" anim="${__config__.animation || ""}" style="${popsAnimStyle}" data-guid="${guid}">${
66
+ config.style != null ? /*html*/ `<style tyle="text/css" data-name="style">${config.style}</style>` : ""
67
67
  }
68
+ ${config.lightStyle != null ? /*html*/ `<style tyle="text/css" data-name="lightStyle">@media (prefers-color-scheme: light) {${config.lightStyle}}</style>` : ""}
69
+ ${config.darkStyle != null ? /*html*/ `<style tyle="text/css" data-name="darkStyle">@media (prefers-color-scheme: dark) {${config.darkStyle}}</style>` : ""}
68
70
  <div class="pops ${
69
71
  config.class || ""
70
72
  }" data-bottom-btn="${hasBottomBtn}" type-value="${type}" style="${popsStyle}" position="${popsPosition}" data-guid="${guid}">${html}</div>
@@ -300,4 +302,54 @@ export const PopsElementHandler = {
300
302
  parseElement<T extends HTMLElement>(html: string): T {
301
303
  return popsDOMUtils.parseTextToDOM(html);
302
304
  },
305
+ /**
306
+ * 添加样式元素
307
+ */
308
+ addStyle($parent: HTMLElement | ShadowRoot, style?: string | null) {
309
+ if (style == null) return;
310
+ const $css = popsDOMUtils.createElement(
311
+ "style",
312
+ {
313
+ innerHTML: style,
314
+ },
315
+ {
316
+ type: "text/css",
317
+ "data-name": "general",
318
+ }
319
+ );
320
+ $parent.appendChild($css);
321
+ return $css;
322
+ },
323
+ /**
324
+ * 添加在浅色模式下生效的style元素
325
+ */
326
+ addLightStyle($parent: HTMLElement | ShadowRoot, style?: string | null) {
327
+ const darkCSS = /*css*/ `
328
+ @media (prefers-color-scheme: light) {
329
+ ${style}
330
+ }
331
+ `;
332
+ const $css = this.addStyle($parent, darkCSS);
333
+ if (!$css) {
334
+ return;
335
+ }
336
+ $css.setAttribute("data-name", "light");
337
+ return $css;
338
+ },
339
+ /**
340
+ * 添加在深色模式下生效的style元素
341
+ */
342
+ addDarkStyle($parent: HTMLElement | ShadowRoot, style?: string | null) {
343
+ const darkCSS = /*css*/ `
344
+ @media (prefers-color-scheme: dark) {
345
+ ${style}
346
+ }
347
+ `;
348
+ const $css = this.addStyle($parent, darkCSS);
349
+ if (!$css) {
350
+ return;
351
+ }
352
+ $css.setAttribute("data-name", "dark");
353
+ return $css;
354
+ },
303
355
  };
@@ -202,6 +202,18 @@ export interface PopsGeneralConfig {
202
202
  * @default ""
203
203
  */
204
204
  style?: string | null;
205
+ /**
206
+ * (可选)自定义浅色模式的style
207
+ *
208
+ * 传入的css都在dark内
209
+ */
210
+ lightStyle?: string | null;
211
+ /**
212
+ * (可选)自定义深色模式的style
213
+ *
214
+ * 传入的css都在dark内
215
+ */
216
+ darkStyle?: string | null;
205
217
  /**
206
218
  * 在元素添加到页面前的事件
207
219
  * @param $shadowRoot 根元素
@@ -1,12 +1,6 @@
1
+ import AnyTouch from "any-touch";
1
2
  import { PopsCore } from "../PopsCore";
2
3
  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
4
 
11
5
  class PopsUtils {
12
6
  /**
@@ -356,49 +350,25 @@ class PopsUtils {
356
350
  * 自动使用 Worker 执行 setTimeout
357
351
  */
358
352
  setTimeout(callback: (...args: any[]) => any, timeout: number = 0) {
359
- try {
360
- return WorkerSetTimeout(callback, timeout);
361
- } catch {
362
- return setTimeout(callback, timeout);
363
- }
353
+ return PopsCore.setTimeout(callback, timeout);
364
354
  }
365
355
  /**
366
356
  * 配合 .setTimeout 使用
367
357
  */
368
358
  clearTimeout(timeId: number | undefined) {
369
- try {
370
- if (timeId != null) {
371
- WorkerClearTimeout(timeId);
372
- }
373
- } catch {
374
- // TODO
375
- } finally {
376
- clearTimeout(timeId);
377
- }
359
+ return PopsCore.clearTimeout(timeId);
378
360
  }
379
361
  /**
380
362
  * 自动使用 Worker 执行 setInterval
381
363
  */
382
364
  setInterval(callback: (...args: any[]) => any, timeout: number = 0) {
383
- try {
384
- return WorkerSetInterval(callback, timeout);
385
- } catch {
386
- return setInterval(callback, timeout);
387
- }
365
+ return PopsCore.setInterval(callback, timeout);
388
366
  }
389
367
  /**
390
368
  * 配合 .setInterval 使用
391
369
  */
392
370
  clearInterval(timeId: number | undefined) {
393
- try {
394
- if (timeId != null) {
395
- WorkerClearInterval(timeId);
396
- }
397
- } catch {
398
- // 忽略
399
- } finally {
400
- clearInterval(timeId);
401
- }
371
+ return PopsCore.clearInterval(timeId);
402
372
  }
403
373
  /**
404
374
  * 覆盖对象中的数组新值