x-next 1.12.0 → 1.13.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 (127) hide show
  1. package/AI_USAGE/catalog.md +1 -1
  2. package/AI_USAGE/components/alert.md +1 -1
  3. package/AI_USAGE/components/bar-chart.md +1 -1
  4. package/AI_USAGE/components/button.md +1 -1
  5. package/AI_USAGE/components/checkbox.md +1 -1
  6. package/AI_USAGE/components/color-picker.md +1 -1
  7. package/AI_USAGE/components/config-provider.md +1 -1
  8. package/AI_USAGE/components/date-picker.md +1 -1
  9. package/AI_USAGE/components/dialog.md +1 -1
  10. package/AI_USAGE/components/dropdown.md +1 -1
  11. package/AI_USAGE/components/empty.md +1 -1
  12. package/AI_USAGE/components/input.md +1 -1
  13. package/AI_USAGE/components/line-chart.md +1 -1
  14. package/AI_USAGE/components/message-box.md +1 -1
  15. package/AI_USAGE/components/message.md +1 -1
  16. package/AI_USAGE/components/notification.md +1 -1
  17. package/AI_USAGE/components/pagination.md +7 -3
  18. package/AI_USAGE/components/pie-chart.md +1 -1
  19. package/AI_USAGE/components/popconfirm.md +1 -1
  20. package/AI_USAGE/components/popover.md +1 -1
  21. package/AI_USAGE/components/progress.md +1 -1
  22. package/AI_USAGE/components/radio.md +1 -1
  23. package/AI_USAGE/components/rate.md +1 -1
  24. package/AI_USAGE/components/select.md +1 -1
  25. package/AI_USAGE/components/slider.md +1 -1
  26. package/AI_USAGE/components/steps.md +1 -1
  27. package/AI_USAGE/components/switch.md +1 -1
  28. package/AI_USAGE/components/tabs.md +1 -1
  29. package/AI_USAGE/components/textarea.md +1 -1
  30. package/AI_USAGE/components/time-picker.md +1 -1
  31. package/AI_USAGE/components/upload.md +1 -1
  32. package/AI_USAGE/core.md +1 -1
  33. package/AI_USAGE/index.md +1 -1
  34. package/AI_USAGE/recipes/form-on-demand.md +1 -1
  35. package/AI_USAGE.md +8 -4
  36. package/CHANGELOG.md +22 -0
  37. package/dist/components/network/Network.vue.d.ts +7 -3
  38. package/dist/components/network/index.d.ts +10 -2
  39. package/dist/components/network/props.d.ts +5 -0
  40. package/dist/components/network/utils.d.ts +3 -3
  41. package/dist/components/pagination/page-item-ellipsis.vue.d.ts +4 -1
  42. package/dist/components/pagination/page-item-step.vue.d.ts +101 -130
  43. package/dist/components/pagination/page-item.vue.d.ts +1 -0
  44. package/dist/components/pagination/page-jumper.vue.d.ts +1 -1
  45. package/dist/components/pagination/page-options.vue.d.ts +6 -4
  46. package/dist/components/pagination/utils.d.ts +3 -0
  47. package/dist/components/time-range-selector/index.d.ts +6 -6
  48. package/dist/es/_container/resize-observer-v2.js +1 -1
  49. package/dist/es/_container/resize-observer.js +1 -1
  50. package/dist/es/_hooks/use-resize-observer.js +1 -1
  51. package/dist/es/_styles/palette-aliases.js +4 -4
  52. package/dist/es/_virtual/advancedFormat.js +1 -1
  53. package/dist/es/_virtual/customParseFormat.js +1 -1
  54. package/dist/es/_virtual/dayjs.min.js +1 -1
  55. package/dist/es/_virtual/isBetween.js +1 -1
  56. package/dist/es/_virtual/quarterOfYear.js +1 -1
  57. package/dist/es/_virtual/weekOfYear.js +1 -1
  58. package/dist/es/_virtual/weekYear.js +1 -1
  59. package/dist/es/_virtual/zh-cn.js +1 -1
  60. package/dist/es/components/button/Button.js +53 -42
  61. package/dist/es/components/draggable/useDraggable.js +1 -1
  62. package/dist/es/components/form/Form.vue2.js +1 -1
  63. package/dist/es/components/form/FormItem.vue2.js +1 -1
  64. package/dist/es/components/form-input-number/InputNumber.js +1 -1
  65. package/dist/es/components/form-slider/Slider.vue2.js +1 -1
  66. package/dist/es/components/form-slider/slider-ticks.vue2.js +1 -1
  67. package/dist/es/components/form-slider/utils.js +1 -1
  68. package/dist/es/components/menu/MenuItem.js +1 -1
  69. package/dist/es/components/menu/overflow-wrap.js +1 -1
  70. package/dist/es/components/network/Network.vue.js +17 -12
  71. package/dist/es/components/network/Network.vue2.js +78 -70
  72. package/dist/es/components/network/utils.js +112 -71
  73. package/dist/es/components/pagination/Pagination.js +132 -123
  74. package/dist/es/components/pagination/page-item-ellipsis.vue.js +10 -10
  75. package/dist/es/components/pagination/page-item-ellipsis.vue2.js +24 -19
  76. package/dist/es/components/pagination/page-item-step.vue.js +14 -11
  77. package/dist/es/components/pagination/page-item-step.vue2.js +20 -22
  78. package/dist/es/components/pagination/page-item.vue.js +10 -9
  79. package/dist/es/components/pagination/page-item.vue2.js +24 -19
  80. package/dist/es/components/pagination/page-jumper.vue2.js +23 -23
  81. package/dist/es/components/pagination/page-options.vue.js +15 -10
  82. package/dist/es/components/pagination/page-options.vue2.js +21 -17
  83. package/dist/es/components/pagination/utils.js +4 -2
  84. package/dist/es/components/progress/circle.vue2.js +1 -1
  85. package/dist/es/components/progress/line.vue2.js +1 -1
  86. package/dist/es/components/progress/steps.vue2.js +1 -1
  87. package/dist/es/components/rate/Rate.js +1 -1
  88. package/dist/es/components/virtual-list-v2/virtual-list-item.js +1 -1
  89. package/dist/es/locale/en-US.js +2 -0
  90. package/dist/es/locale/zh-CN.js +2 -0
  91. package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/dayjs.min.js +1 -1
  92. package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/locale/zh-cn.js +1 -1
  93. package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/advancedFormat.js +1 -1
  94. package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/customParseFormat.js +1 -1
  95. package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/isBetween.js +1 -1
  96. package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/quarterOfYear.js +1 -1
  97. package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/weekOfYear.js +1 -1
  98. package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/weekYear.js +1 -1
  99. package/dist/es/style.css +1 -1
  100. package/dist/index.cjs +3 -3
  101. package/dist/index.umd.js +3 -3
  102. package/dist/locale/interface.d.ts +3 -0
  103. package/dist/style/base.css +1 -1
  104. package/dist/style/button.css +1 -1
  105. package/dist/style/form-select.css +1 -1
  106. package/dist/style/network.css +1 -1
  107. package/dist/style/pagination.css +1 -1
  108. package/dist/style/table.css +1 -1
  109. package/dist/style.css +1 -1
  110. package/package.json +1 -1
  111. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/index.js +0 -0
  112. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/is.js +0 -0
  113. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/locale/en-US.js +0 -0
  114. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/array.js +0 -0
  115. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/base.js +0 -0
  116. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/boolean.js +0 -0
  117. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/custom.js +0 -0
  118. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/number.js +0 -0
  119. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/object.js +0 -0
  120. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/string.js +0 -0
  121. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/type.js +0 -0
  122. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/util.js +0 -0
  123. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/compute-scroll-into-view@3.1.1/node_modules/compute-scroll-into-view/dist/index.js +0 -0
  124. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/number-precision@1.6.0/node_modules/number-precision/build/index.es.js +0 -0
  125. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +0 -0
  126. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/scroll-into-view-if-needed@3.1.0/node_modules/scroll-into-view-if-needed/dist/index.js +0 -0
  127. /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/sortablejs@1.15.7/node_modules/sortablejs/modular/sortable.esm.js +0 -0
@@ -1,5 +1,5 @@
1
1
  import { defineComponent as re, computed as c, toRefs as oe, toRef as me, ref as B, watch as ce } from "vue";
2
- import C from "../../Users/xuyu/Code/x-next/node_modules/.pnpm/number-precision@1.6.0/node_modules/number-precision/build/index.es.js";
2
+ import C from "../../node_modules/.pnpm/number-precision@1.6.0/node_modules/number-precision/build/index.es.js";
3
3
  import de from "./slider-button.vue.js";
4
4
  import fe from "./slider-dots.vue.js";
5
5
  import se from "./slider-marks.vue.js";
@@ -1,5 +1,5 @@
1
1
  import { defineComponent as s, computed as a } from "vue";
2
- import o from "../../Users/xuyu/Code/x-next/node_modules/.pnpm/number-precision@1.6.0/node_modules/number-precision/build/index.es.js";
2
+ import o from "../../node_modules/.pnpm/number-precision@1.6.0/node_modules/number-precision/build/index.es.js";
3
3
  import { getPositionStyle as l, getOffsetPercent as c } from "./utils.js";
4
4
  import { getClassNameMixin as d } from "../../_utils/config.js";
5
5
  const S = s({
@@ -1,4 +1,4 @@
1
- import o from "../../Users/xuyu/Code/x-next/node_modules/.pnpm/number-precision@1.6.0/node_modules/number-precision/build/index.es.js";
1
+ import o from "../../node_modules/.pnpm/number-precision@1.6.0/node_modules/number-precision/build/index.es.js";
2
2
  const l = (e, [t, r]) => {
3
3
  if (r <= t)
4
4
  return "0%";
@@ -1,5 +1,5 @@
1
1
  import { defineComponent as T, createVNode as i, mergeProps as $, ref as E, computed as S, onMounted as h, onUnmounted as I, watch as K } from "vue";
2
- import N from "../../Users/xuyu/Code/x-next/node_modules/.pnpm/scroll-into-view-if-needed@3.1.0/node_modules/scroll-into-view-if-needed/dist/index.js";
2
+ import N from "../../node_modules/.pnpm/scroll-into-view-if-needed@3.1.0/node_modules/scroll-into-view-if-needed/dist/index.js";
3
3
  import { Tooltip as _ } from "../tooltip/index.js";
4
4
  import B from "./hooks/use-menu.js";
5
5
  import A from "./hooks/use-level.js";
@@ -1,5 +1,5 @@
1
1
  import { defineComponent as V, ref as w, onMounted as _, onUnmounted as $, createVNode as h, cloneVNode as g, mergeProps as L, createTextVNode as E } from "vue";
2
- import k from "../../Users/xuyu/Code/x-next/node_modules/.pnpm/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js";
2
+ import k from "../../node_modules/.pnpm/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js";
3
3
  import { getStyle as N } from "../../_utils/style.js";
4
4
  import F from "./hooks/use-menu-context.js";
5
5
  import P from "./MenuSubMenu.js";
@@ -1,13 +1,14 @@
1
1
  import d from "./Network.vue2.js";
2
- import { openBlock as s, createElementBlock as r, normalizeClass as a, renderSlot as u, createElementVNode as l, Fragment as p, renderList as g, normalizeStyle as S, toDisplayString as i, createCommentVNode as m } from "vue";
2
+ import { openBlock as s, createElementBlock as r, normalizeClass as a, renderSlot as u, createElementVNode as l, toDisplayString as t, Fragment as p, renderList as g, normalizeStyle as S, createCommentVNode as m } from "vue";
3
3
  import y from "../../_virtual/_plugin-vue_export-helper.js";
4
- const f = ["aria-label", "aria-live", "title"];
5
- function c(e, t, v, N, h, k) {
4
+ const c = ["aria-label", "aria-live", "title"];
5
+ function f(e, n, v, N, h, k) {
6
6
  return s(), r("div", {
7
7
  class: a(e.cls),
8
8
  role: "status",
9
9
  "aria-label": e.mergedAriaLabel,
10
10
  "aria-live": e.ariaLive,
11
+ "aria-atomic": "true",
11
12
  title: e.showTooltip ? e.mergedAriaLabel : void 0
12
13
  }, [
13
14
  u(e.$slots, "default", {
@@ -21,40 +22,44 @@ function c(e, t, v, N, h, k) {
21
22
  reason: e.mergedStatus.reason,
22
23
  refresh: e.refresh
23
24
  }, () => [
25
+ l("span", {
26
+ class: a(e.className.element("status-text"))
27
+ }, t(e.mergedAriaLabel), 3),
24
28
  l("div", {
25
29
  class: a(e.className.element("signal")),
26
30
  "aria-hidden": "true"
27
31
  }, [
28
- (s(!0), r(p, null, g(e.lineItems, (o, n) => (s(), r("div", {
29
- key: n,
32
+ (s(!0), r(p, null, g(e.lineItems, (o, i) => (s(), r("div", {
33
+ key: i,
30
34
  class: a([
31
35
  e.className.element("signal--item"),
32
36
  o.active && e.className.is("active")
33
37
  ]),
34
38
  style: S({
35
- height: `${100 / e.lineItems.length * (n + 1)}%`,
39
+ height: `${100 / e.lineItems.length * (i + 1)}%`,
36
40
  "--x-network-line-color": o.color
37
41
  })
38
- }, [...t[0] || (t[0] = [
42
+ }, [...n[0] || (n[0] = [
39
43
  l("i", null, null, -1)
40
44
  ])], 6))), 128))
41
45
  ], 2),
42
46
  e.mergedShowMetrics ? (s(), r("span", {
43
47
  key: 0,
44
- class: a(e.className.element("metrics"))
48
+ class: a(e.className.element("metrics")),
49
+ "aria-hidden": "true"
45
50
  }, [
46
51
  e.mergedStatus.latency !== void 0 ? (s(), r("span", {
47
52
  key: 0,
48
53
  class: a(e.className.element("latency"))
49
- }, i(e.mergedStatus.latency) + "ms ", 3)) : m("", !0),
54
+ }, t(e.mergedStatus.latency) + "ms ", 3)) : m("", !0),
50
55
  l("span", {
51
56
  class: a(e.className.element("speed"))
52
- }, i(e.formattedDownloadSpeed), 3)
57
+ }, t(e.formattedDownloadSpeed), 3)
53
58
  ], 2)) : m("", !0)
54
59
  ])
55
- ], 10, f);
60
+ ], 10, c);
56
61
  }
57
- const L = /* @__PURE__ */ y(d, [["render", c]]);
62
+ const L = /* @__PURE__ */ y(d, [["render", f]]);
58
63
  export {
59
64
  L as default
60
65
  };
@@ -1,25 +1,27 @@
1
- import { useLocale as E } from "../../locale/index.js";
2
- import { defineComponent as U, ref as m, computed as n, watch as K, onMounted as D, onUnmounted as I } from "vue";
3
- import { getClassNameMixin as O } from "../../_utils/config.js";
4
- import { Network as $ } from "./utils.js";
5
- const C = {
1
+ import { useLocale as I } from "../../locale/index.js";
2
+ import { defineComponent as D, shallowRef as R, ref as p, computed as n, watch as $, onMounted as j, onUnmounted as B } from "vue";
3
+ import { getClassNameMixin as F } from "../../_utils/config.js";
4
+ import { Network as Q } from "./utils.js";
5
+ const M = {
6
6
  online: !0,
7
7
  quality: "unknown",
8
8
  source: "manual",
9
9
  reason: "initial",
10
10
  lastCheckedAt: 0
11
- }, B = {
11
+ }, W = {
12
12
  unknown: "network.checking",
13
13
  good: "network.good",
14
14
  medium: "network.fair",
15
15
  poor: "network.poor",
16
16
  offline: "network.offline"
17
- }, F = ["unknown", "good", "medium", "poor", "offline"], Y = U({
17
+ }, T = ["unknown", "good", "medium", "poor", "offline"], A = ["mini", "small", "medium", "large"], J = D({
18
18
  name: "Network",
19
+ slots: Object,
19
20
  props: {
20
21
  size: {
21
22
  type: String,
22
- default: "medium"
23
+ default: "medium",
24
+ validator: (o) => A.includes(o)
23
25
  },
24
26
  /**
25
27
  * @zh 兼容旧版强/弱信号颜色配置
@@ -40,7 +42,7 @@ const C = {
40
42
  */
41
43
  status: {
42
44
  type: String,
43
- validator: (t) => F.includes(t)
45
+ validator: (o) => T.includes(o)
44
46
  },
45
47
  /**
46
48
  * @zh 主动探测 URL,需要支持 CORS。
@@ -85,94 +87,100 @@ const C = {
85
87
  }
86
88
  },
87
89
  emits: {
88
- change: (t) => !0,
89
- online: (t) => !0,
90
- offline: (t) => !0,
91
- probe: (t) => !0
90
+ change: (o) => !0,
91
+ online: (o) => !0,
92
+ offline: (o) => !0,
93
+ probe: (o) => !0
92
94
  },
93
- setup(t, { emit: l, expose: x }) {
94
- const a = O("network"), r = m(), i = m(C), s = n(() => t.size === "small" || t.size === "mini" ? 3 : t.size === "medium" ? 4 : 5), f = (e) => ({
95
- ...C,
95
+ setup(o, { emit: c, expose: L }) {
96
+ const l = F("network"), r = R(), i = p(M);
97
+ let d = !1;
98
+ const a = n(
99
+ () => o.status == null ? void 0 : T.includes(o.status) ? o.status : "unknown"
100
+ ), f = n(() => A.includes(o.size) ? o.size : "medium"), v = n(() => f.value === "small" || f.value === "mini" ? 3 : f.value === "medium" ? 4 : 5), m = (e) => ({
101
+ ...M,
96
102
  online: e !== "offline",
97
103
  quality: e,
98
104
  source: "manual",
99
105
  lastCheckedAt: Date.now()
100
- }), u = n(() => t.status ? f(t.status) : i.value), { t: w } = E(), g = n(() => w(B[u.value.quality])), M = n(
101
- () => t.ariaLabel || w("network.ariaLabel", { status: g.value })
102
- ), A = (e, o = "--") => e === void 0 ? o : e <= 0 ? "0K/s" : e >= 1024 * 1024 ? `${(e / 1024 / 1024).toFixed(1)}M/s` : `${Math.max(1, Math.round(e / 1024))}K/s`, T = n(() => A(u.value.downloadSpeed)), d = n(() => t.showMetrics), L = (e) => {
103
- const [o, h] = t.signalStrengthColor, v = {
106
+ }), u = n(() => a.value !== void 0 ? m(a.value) : i.value), { t: S } = I(), k = n(() => S(W[u.value.quality])), N = n(
107
+ () => o.ariaLabel || S("network.ariaLabel", { status: k.value })
108
+ ), _ = (e, t = "--") => e === void 0 ? t : e <= 0 ? "0K/s" : e >= 1024 * 1024 ? `${(e / 1024 / 1024).toFixed(1)}M/s` : `${Math.max(1, Math.round(e / 1024))}K/s`, q = n(() => _(u.value.downloadSpeed)), w = n(() => o.showMetrics), E = (e) => {
109
+ const [t, C] = o.signalStrengthColor, g = {
104
110
  unknown: "var(--x-network-color-unknown)",
105
- good: o || "var(--x-network-color-good)",
106
- medium: t.statusColors.medium || "var(--x-network-color-medium)",
107
- poor: h || "var(--x-network-color-poor)",
111
+ good: t || "var(--x-network-color-good)",
112
+ medium: o.statusColors.medium || "var(--x-network-color-medium)",
113
+ poor: C || "var(--x-network-color-poor)",
108
114
  offline: "var(--x-network-color-offline)"
109
115
  };
110
- return t.statusColors[e] || v[e];
111
- }, N = (e) => e === "good" ? s.value : e === "medium" ? Math.max(2, Math.ceil(s.value * 0.6)) : e === "poor" ? Math.max(1, Math.ceil(s.value * 0.4)) : 0, q = n(() => {
112
- const e = N(u.value.quality), o = L(u.value.quality);
113
- return Array.from({ length: s.value }, (h, v) => {
114
- const y = v < e;
116
+ return o.statusColors[e] || g[e];
117
+ }, z = (e) => e === "good" ? v.value : e === "medium" ? Math.max(2, Math.ceil(v.value * 0.6)) : e === "poor" ? Math.max(1, Math.ceil(v.value * 0.4)) : 0, K = n(() => {
118
+ const e = z(u.value.quality), t = E(u.value.quality);
119
+ return Array.from({ length: v.value }, (C, g) => {
120
+ const x = g < e;
115
121
  return {
116
- active: y,
117
- color: y ? o : "var(--x-network-color-inactive)"
122
+ active: x,
123
+ color: x || e === 0 ? t : "var(--x-network-color-inactive)"
118
124
  };
119
125
  });
120
- }), z = (e, o) => e.online === o.online && e.quality === o.quality && e.source === o.source && e.reason === o.reason && e.latency === o.latency && e.downloadSpeed === o.downloadSpeed && e.effectiveType === o.effectiveType, c = m(void 0), _ = (e) => {
121
- if (t.status) return;
122
- const o = c.value ?? i.value;
123
- i.value = e, (!c.value || !z(c.value, e)) && (c.value = e, l("change", e)), e.source === "probe" && l("probe", e), o.quality !== "offline" && e.quality === "offline" && l("offline", e), o.quality === "offline" && e.quality !== "offline" && l("online", e);
124
- }, k = () => {
125
- var e;
126
- if ((e = r.value) == null || e.destroy(), r.value = void 0, t.status) {
127
- i.value = f(t.status);
128
- return;
126
+ }), O = (e, t) => e.online === t.online && e.quality === t.quality && e.source === t.source && e.reason === t.reason && e.latency === t.latency && e.downloadSpeed === t.downloadSpeed && e.speedSource === t.speedSource && e.downlink === t.downlink && e.rtt === t.rtt && e.effectiveType === t.effectiveType, s = p(void 0), U = (e) => {
127
+ if (!d || a.value !== void 0) return;
128
+ const t = s.value ?? i.value;
129
+ i.value = e, (!s.value || !O(s.value, e)) && (s.value = e, c("change", e)), e.source === "probe" && c("probe", e), t.quality !== "offline" && e.quality === "offline" && c("offline", e), t.quality === "offline" && e.quality !== "offline" && c("online", e);
130
+ }, h = (e = !1) => {
131
+ var t;
132
+ if ((t = r.value) == null || t.destroy(), r.value = void 0, e && (s.value = void 0), !!d) {
133
+ if (a.value !== void 0) {
134
+ i.value = m(a.value);
135
+ return;
136
+ }
137
+ r.value = new Q(U, {
138
+ ping: o.ping,
139
+ interval: o.interval,
140
+ timeout: o.timeout
141
+ }), s.value || (i.value = r.value.getSnapshot());
129
142
  }
130
- r.value = new $(_, {
131
- ping: t.ping,
132
- interval: t.interval,
133
- timeout: t.timeout
134
- }), i.value = r.value.getSnapshot();
135
- }, S = async () => {
143
+ }, y = async () => {
136
144
  var e;
137
- if (t.status) {
138
- const o = f(t.status);
139
- return l("change", o), o;
145
+ if (a.value !== void 0) {
146
+ const t = m(a.value);
147
+ return d && c("change", t), t;
140
148
  }
141
149
  return await ((e = r.value) == null ? void 0 : e.refresh()) ?? i.value;
142
150
  };
143
- K(
144
- () => [t.status, t.ping, t.interval, t.timeout],
145
- () => {
146
- k();
151
+ $(
152
+ () => [o.status, o.ping, o.interval, o.timeout],
153
+ (e, t) => {
154
+ h(e[0] !== t[0]);
147
155
  }
148
- ), D(() => {
149
- k();
150
- }), I(() => {
156
+ ), j(() => {
157
+ d = !0, h();
158
+ }), B(() => {
151
159
  var e;
152
- (e = r.value) == null || e.destroy(), r.value = void 0;
153
- }), x({ refresh: S });
160
+ d = !1, (e = r.value) == null || e.destroy(), r.value = void 0;
161
+ }), L({ refresh: y });
154
162
  const b = n(() => [
155
- a.block,
156
- t.size && a.modifier(t.size),
157
- a.modifier(`status-${u.value.quality}`),
163
+ l.block,
164
+ l.modifier(f.value),
165
+ l.modifier(`status-${u.value.quality}`),
158
166
  {
159
- [a.is("with-text")]: d.value,
160
- [a.is("with-metrics")]: d.value
167
+ [l.is("with-text")]: w.value,
168
+ [l.is("with-metrics")]: w.value
161
169
  }
162
170
  ]);
163
171
  return {
164
- className: a,
172
+ className: l,
165
173
  cls: b,
166
- lineItems: q,
174
+ lineItems: K,
167
175
  mergedStatus: u,
168
- statusText: g,
169
- mergedAriaLabel: M,
170
- formattedDownloadSpeed: T,
171
- mergedShowMetrics: d,
172
- refresh: S
176
+ statusText: k,
177
+ mergedAriaLabel: N,
178
+ formattedDownloadSpeed: q,
179
+ mergedShowMetrics: w,
180
+ refresh: y
173
181
  };
174
182
  }
175
183
  });
176
184
  export {
177
- Y as default
185
+ J as default
178
186
  };
@@ -1,162 +1,203 @@
1
- var b = Object.defineProperty;
2
- var T = (t, e, n) => e in t ? b(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var o = (t, e, n) => T(t, typeof e != "symbol" ? e + "" : e, n);
4
- const y = {
1
+ var M = Object.defineProperty;
2
+ var N = (t, e, n) => e in t ? M(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var o = (t, e, n) => N(t, typeof e != "symbol" ? e + "" : e, n);
4
+ const k = {
5
5
  online: !0,
6
6
  quality: "unknown",
7
7
  source: "manual",
8
8
  reason: "initial",
9
9
  lastCheckedAt: 0
10
- }, f = () => Date.now(), d = () => typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now(), m = () => {
10
+ }, g = () => Date.now(), l = () => typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now(), L = () => {
11
11
  if (!(typeof navigator > "u"))
12
12
  return navigator.connection;
13
- }, l = () => typeof navigator < "u" && navigator.onLine === !1, k = (t) => {
13
+ }, c = () => typeof navigator < "u" && navigator.onLine === !1, w = (t) => typeof t == "number" && Number.isFinite(t) && t >= 0 ? t : void 0, E = (t) => typeof t == "number" && Number.isFinite(t) && t > 0 ? Math.min(2147483647, Math.max(1, t)) : void 0, p = /* @__PURE__ */ new WeakMap(), R = (t, e) => {
14
+ if (t.addEventListener && t.removeEventListener)
15
+ return t.addEventListener("change", e), () => t.removeEventListener("change", e);
16
+ let n = p.get(t);
17
+ if (!n || t.onchange !== n.dispatch) {
18
+ const i = t.onchange, s = /* @__PURE__ */ new Set();
19
+ n = {
20
+ previous: i,
21
+ listeners: s,
22
+ dispatch(f) {
23
+ try {
24
+ i == null || i.call(t, f);
25
+ } finally {
26
+ for (const u of [...s]) u();
27
+ }
28
+ }
29
+ }, p.set(t, n), t.onchange = n.dispatch;
30
+ }
31
+ const r = n;
32
+ return r.listeners.add(e), () => {
33
+ r.listeners.delete(e), !r.listeners.size && (t.onchange === r.dispatch && (t.onchange = r.previous ?? null), p.get(t) === r && p.delete(t));
34
+ };
35
+ }, P = (t) => {
14
36
  const { effectiveType: e } = t;
15
37
  if (e === "slow-2g" || e === "2g") return "poor";
16
38
  if (e === "3g") return "medium";
17
39
  if (e === "4g") return "good";
18
- const { downlink: n, rtt: i } = t, r = typeof n == "number" && Number.isFinite(n), h = typeof i == "number" && Number.isFinite(i);
19
- if (!(!r || !h))
20
- return n > 2 && i <= 100 ? "good" : n > 1 && i <= 300 ? "medium" : "poor";
21
- }, q = (t) => t < 500 ? "good" : t < 1500 ? "medium" : "poor", w = (t, e) => ({
40
+ const n = w(t.downlink), r = w(t.rtt);
41
+ if (!(n === void 0 || r === void 0))
42
+ return n > 2 && r <= 100 ? "good" : n > 1 && r <= 300 ? "medium" : "poor";
43
+ }, D = (t) => t < 500 ? "good" : t < 1500 ? "medium" : "poor", y = (t, e) => ({
22
44
  online: !1,
23
45
  quality: "offline",
24
46
  source: t,
25
47
  reason: e,
26
- lastCheckedAt: f()
27
- }), c = (t) => {
48
+ lastCheckedAt: g()
49
+ }), d = (t) => {
28
50
  if (typeof navigator > "u")
29
51
  return {
30
52
  online: !0,
31
53
  quality: "unknown",
32
54
  source: "navigator",
33
55
  reason: "unsupported",
34
- lastCheckedAt: f()
56
+ lastCheckedAt: g()
35
57
  };
36
- if (l())
37
- return w("navigator", "browser-offline");
38
- const e = m();
58
+ if (c())
59
+ return y("navigator", "browser-offline");
60
+ const e = L();
39
61
  return e ? {
40
62
  online: !0,
41
- quality: k(e) ?? "unknown",
42
- downlink: e.downlink,
43
- rtt: e.rtt,
63
+ quality: P(e) ?? "unknown",
64
+ downlink: w(e.downlink),
65
+ rtt: w(e.rtt),
44
66
  effectiveType: e.effectiveType,
45
67
  source: "connection",
46
68
  reason: t,
47
- lastCheckedAt: f()
69
+ lastCheckedAt: g()
48
70
  } : {
49
71
  online: !0,
50
72
  quality: "good",
51
73
  source: "navigator",
52
74
  reason: t,
53
- lastCheckedAt: f()
75
+ lastCheckedAt: g()
54
76
  };
55
77
  };
56
- class L {
78
+ class F {
57
79
  constructor(e, n = {}) {
58
80
  o(this, "callback");
59
81
  o(this, "options");
60
82
  o(this, "timer");
61
83
  o(this, "initialTimer");
62
- o(this, "connection");
63
- /** 不支持 addEventListener 时保存 connection.onchange 的原处理器,销毁时归还 */
64
- o(this, "previousConnectionOnChange");
84
+ o(this, "unsubscribeConnection");
65
85
  o(this, "controller");
86
+ o(this, "cancelProbe");
66
87
  o(this, "destroyed", !1);
67
88
  o(this, "pendingRefresh");
68
89
  o(this, "sequence", 0);
69
90
  o(this, "handleWindowChange", () => {
70
- this.refresh(l() ? "browser-offline" : void 0);
91
+ this.refreshAfterBrowserChange(c() ? "browser-offline" : void 0);
71
92
  });
72
93
  o(this, "handleConnectionChange", () => {
73
- this.refresh("connection-change");
94
+ this.refreshAfterBrowserChange("connection-change");
74
95
  });
75
96
  this.callback = e, this.options = n, this.boot();
76
97
  }
77
98
  checkNetworkQuality() {
78
- return c().quality;
99
+ return d().quality;
79
100
  }
80
101
  getSnapshot() {
81
- return typeof window > "u" || typeof navigator > "u" ? y : c();
102
+ return typeof window > "u" || typeof navigator > "u" ? k : d();
82
103
  }
83
104
  async refresh(e) {
105
+ if (this.destroyed) return this.getSnapshot();
84
106
  if (this.pendingRefresh) return this.pendingRefresh;
85
- const n = ++this.sequence;
86
- return this.pendingRefresh = this.resolveStatus(e).then((i) => (!this.destroyed && n === this.sequence && this.emitCallback(i), i)).finally(() => {
87
- this.pendingRefresh = void 0;
88
- }), this.pendingRefresh;
107
+ const n = ++this.sequence, r = this.resolveStatus(e).then((i) => (!this.destroyed && n === this.sequence && this.emitCallback(i), i)).finally(() => {
108
+ this.pendingRefresh === r && (this.pendingRefresh = void 0);
109
+ });
110
+ return this.pendingRefresh = r, r;
111
+ }
112
+ refreshAfterBrowserChange(e) {
113
+ var n;
114
+ this.destroyed || (this.sequence += 1, (n = this.cancelProbe) == null || n.call(this), this.pendingRefresh = void 0, this.refresh(e));
89
115
  }
90
116
  async resolveStatus(e) {
91
- return typeof window > "u" || typeof navigator > "u" ? y : l() ? w("navigator", "browser-offline") : this.options.ping ? this.pingNetworkQuality(this.options.ping, this.options.timeout) : c(e);
117
+ return typeof window > "u" || typeof navigator > "u" ? k : c() ? y("navigator", "browser-offline") : this.options.ping ? this.pingNetworkQuality(this.options.ping, this.options.timeout) : d(e);
92
118
  }
93
119
  async pingNetworkQuality(e, n = 5e3) {
94
- var p;
95
- const i = d();
96
- (p = this.controller) == null || p.abort();
97
- const r = typeof AbortController < "u" ? new AbortController() : void 0;
98
- this.controller = r;
99
- const h = r ? setTimeout(() => r.abort(), Math.max(n, 1)) : void 0;
120
+ const r = l(), i = typeof AbortController < "u" ? new AbortController() : void 0;
121
+ this.controller = i;
122
+ let s = !1, f = !1, u, b;
123
+ const A = new Promise((m, a) => {
124
+ u = () => {
125
+ f = !0, a(new Error("Network probe cancelled")), i == null || i.abort();
126
+ }, b = setTimeout(() => {
127
+ s = !0, a(new Error("Network probe timeout")), i == null || i.abort();
128
+ }, E(n) ?? 5e3);
129
+ });
130
+ this.cancelProbe = u;
100
131
  try {
101
- const s = await fetch(e, {
102
- cache: "no-cache",
103
- method: "GET",
104
- mode: "cors",
105
- signal: r == null ? void 0 : r.signal
106
- }), a = Math.round(d() - i), C = await s.arrayBuffer(), g = Math.round(d() - i), v = C.byteLength || Number(s.headers.get("content-length") || 0), u = v > 0 && g > 0 ? v / g * 1e3 : void 0;
107
- return s.ok ? {
108
- ...c(),
109
- quality: q(a),
132
+ const { response: m, headerLatency: a, buffer: v, duration: T } = await Promise.race([
133
+ (async () => {
134
+ const C = await fetch(e, {
135
+ cache: "no-cache",
136
+ method: "GET",
137
+ mode: "cors",
138
+ signal: i == null ? void 0 : i.signal
139
+ }), q = Math.round(l() - r), S = await C.arrayBuffer();
140
+ return { response: C, headerLatency: q, buffer: S, duration: l() - r };
141
+ })(),
142
+ A
143
+ ]);
144
+ if (c()) return y("navigator", "browser-offline");
145
+ const h = v.byteLength > 0 && T > 0 ? v.byteLength / T * 1e3 : void 0;
146
+ return m.ok ? {
147
+ ...d(),
148
+ quality: D(a),
110
149
  latency: a,
111
- downloadSpeed: u,
112
- speedSource: u ? "probe" : void 0,
150
+ downloadSpeed: h,
151
+ speedSource: h ? "probe" : void 0,
113
152
  source: "probe"
114
153
  } : {
115
- ...c("http-error"),
154
+ ...d("http-error"),
116
155
  quality: "poor",
117
156
  latency: a,
118
- downloadSpeed: u,
119
- speedSource: u ? "probe" : void 0,
157
+ downloadSpeed: h,
158
+ speedSource: h ? "probe" : void 0,
120
159
  source: "probe",
121
160
  reason: "http-error"
122
161
  };
123
- } catch (s) {
124
- const a = typeof DOMException < "u" && s instanceof DOMException && s.name === "AbortError";
125
- return {
126
- ...c(a ? "probe-timeout" : "probe-error"),
162
+ } catch {
163
+ return c() ? y("navigator", "browser-offline") : f ? this.getSnapshot() : {
164
+ ...d(s ? "probe-timeout" : "probe-error"),
127
165
  quality: "poor",
128
- latency: Math.round(d() - i),
166
+ latency: Math.round(l() - r),
129
167
  source: "probe",
130
- reason: a ? "probe-timeout" : "probe-error"
168
+ reason: s ? "probe-timeout" : "probe-error"
131
169
  };
132
170
  } finally {
133
- h && clearTimeout(h), this.controller === r && (this.controller = void 0);
171
+ clearTimeout(b), this.cancelProbe === u && (this.cancelProbe = void 0), this.controller === i && (this.controller = void 0);
134
172
  }
135
173
  }
136
174
  boot() {
137
175
  if (typeof window > "u" || typeof navigator > "u")
138
176
  return;
139
177
  window.addEventListener("online", this.handleWindowChange), window.addEventListener("offline", this.handleWindowChange);
140
- const e = m();
141
- e && (this.connection = e, e.addEventListener ? e.addEventListener("change", this.handleConnectionChange) : (this.previousConnectionOnChange = e.onchange, e.onchange = (n) => {
142
- typeof this.previousConnectionOnChange == "function" && this.previousConnectionOnChange.call(e, n), this.handleConnectionChange();
143
- })), this.initialTimer = setTimeout(() => {
178
+ const e = L();
179
+ e && (this.unsubscribeConnection = R(e, this.handleConnectionChange)), this.initialTimer = setTimeout(() => {
144
180
  this.refresh();
145
181
  }, 0), this.scheduleNextRefresh();
146
182
  }
147
183
  scheduleNextRefresh() {
148
- !this.options.interval || this.options.interval <= 0 || this.destroyed || (this.timer = setTimeout(async () => {
149
- await this.refresh(), this.scheduleNextRefresh();
150
- }, this.options.interval));
184
+ const e = E(this.options.interval);
185
+ e === void 0 || this.destroyed || (this.timer = setTimeout(async () => {
186
+ try {
187
+ await this.refresh();
188
+ } finally {
189
+ this.scheduleNextRefresh();
190
+ }
191
+ }, e));
151
192
  }
152
193
  emitCallback(e) {
153
194
  this.callback(e);
154
195
  }
155
196
  destroy() {
156
- var e;
157
- this.destroyed = !0, this.sequence += 1, (e = this.controller) == null || e.abort(), this.controller = void 0, this.initialTimer && (clearTimeout(this.initialTimer), this.initialTimer = void 0), this.timer && (clearTimeout(this.timer), this.timer = void 0), typeof window < "u" && (window.removeEventListener("online", this.handleWindowChange), window.removeEventListener("offline", this.handleWindowChange)), this.connection && (this.connection.removeEventListener ? this.connection.removeEventListener("change", this.handleConnectionChange) : this.connection.onchange = this.previousConnectionOnChange ?? null, this.connection = void 0, this.previousConnectionOnChange = void 0);
197
+ var e, n, r;
198
+ this.destroyed || (this.destroyed = !0, this.sequence += 1, (e = this.cancelProbe) == null || e.call(this), this.cancelProbe = void 0, (n = this.controller) == null || n.abort(), this.controller = void 0, this.initialTimer !== void 0 && (clearTimeout(this.initialTimer), this.initialTimer = void 0), this.timer !== void 0 && (clearTimeout(this.timer), this.timer = void 0), typeof window < "u" && (window.removeEventListener("online", this.handleWindowChange), window.removeEventListener("offline", this.handleWindowChange)), (r = this.unsubscribeConnection) == null || r.call(this), this.unsubscribeConnection = void 0);
158
199
  }
159
200
  }
160
201
  export {
161
- L as Network
202
+ F as Network
162
203
  };