x-next 1.12.0 → 1.14.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 (226) hide show
  1. package/AI_CODING.md +6 -5
  2. package/AI_USAGE/catalog.md +106 -105
  3. package/AI_USAGE/components/alert-api.md +48 -0
  4. package/AI_USAGE/components/alert.md +222 -3
  5. package/AI_USAGE/components/bar-chart-api.md +177 -0
  6. package/AI_USAGE/components/bar-chart.md +297 -3
  7. package/AI_USAGE/components/boxicons.md +147 -0
  8. package/AI_USAGE/components/button-api.md +144 -0
  9. package/AI_USAGE/components/button.md +447 -3
  10. package/AI_USAGE/components/charts.md +81 -0
  11. package/AI_USAGE/components/checkbox-api.md +145 -0
  12. package/AI_USAGE/components/checkbox.md +365 -3
  13. package/AI_USAGE/components/color-picker-api.md +52 -0
  14. package/AI_USAGE/components/color-picker.md +211 -3
  15. package/AI_USAGE/components/config-provider-api.md +38 -0
  16. package/AI_USAGE/components/config-provider.md +250 -3
  17. package/AI_USAGE/components/date-picker-api.md +1114 -0
  18. package/AI_USAGE/components/date-picker.md +378 -3
  19. package/AI_USAGE/components/dialog-api.md +142 -0
  20. package/AI_USAGE/components/dialog.md +284 -3
  21. package/AI_USAGE/components/draggable-api.md +146 -0
  22. package/AI_USAGE/components/draggable.md +259 -0
  23. package/AI_USAGE/components/drawer-api.md +78 -0
  24. package/AI_USAGE/components/drawer.md +227 -0
  25. package/AI_USAGE/components/dropdown-api.md +529 -0
  26. package/AI_USAGE/components/dropdown.md +392 -3
  27. package/AI_USAGE/components/empty-api.md +36 -0
  28. package/AI_USAGE/components/empty.md +227 -3
  29. package/AI_USAGE/components/finicon.md +88 -0
  30. package/AI_USAGE/components/form-api.md +524 -0
  31. package/AI_USAGE/components/form.md +454 -0
  32. package/AI_USAGE/components/grid-api.md +527 -0
  33. package/AI_USAGE/components/grid.md +224 -0
  34. package/AI_USAGE/components/heatmap-api.md +122 -0
  35. package/AI_USAGE/components/heatmap.md +220 -0
  36. package/AI_USAGE/components/icon-api.md +4707 -0
  37. package/AI_USAGE/components/icon.md +257 -0
  38. package/AI_USAGE/components/image-api.md +440 -0
  39. package/AI_USAGE/components/image.md +465 -0
  40. package/AI_USAGE/components/input-api.md +184 -0
  41. package/AI_USAGE/components/input-number-api.md +66 -0
  42. package/AI_USAGE/components/input-number.md +294 -0
  43. package/AI_USAGE/components/input-tag-api.md +114 -0
  44. package/AI_USAGE/components/input-tag.md +482 -0
  45. package/AI_USAGE/components/input.md +293 -3
  46. package/AI_USAGE/components/layout-api.md +147 -0
  47. package/AI_USAGE/components/layout.md +230 -0
  48. package/AI_USAGE/components/line-chart-api.md +197 -0
  49. package/AI_USAGE/components/line-chart.md +279 -3
  50. package/AI_USAGE/components/link-api.md +42 -0
  51. package/AI_USAGE/components/link.md +197 -0
  52. package/AI_USAGE/components/menu-api.md +516 -0
  53. package/AI_USAGE/components/menu.md +268 -0
  54. package/AI_USAGE/components/message-api.md +215 -0
  55. package/AI_USAGE/components/message-box-api.md +108 -0
  56. package/AI_USAGE/components/message-box.md +268 -3
  57. package/AI_USAGE/components/message.md +231 -3
  58. package/AI_USAGE/components/network-api.md +91 -0
  59. package/AI_USAGE/components/network.md +378 -0
  60. package/AI_USAGE/components/notification-api.md +236 -0
  61. package/AI_USAGE/components/notification.md +275 -3
  62. package/AI_USAGE/components/pagination-api.md +62 -0
  63. package/AI_USAGE/components/pagination.md +386 -5
  64. package/AI_USAGE/components/pie-chart-api.md +109 -0
  65. package/AI_USAGE/components/pie-chart.md +245 -3
  66. package/AI_USAGE/components/popconfirm-api.md +75 -0
  67. package/AI_USAGE/components/popconfirm.md +231 -3
  68. package/AI_USAGE/components/popover-api.md +75 -0
  69. package/AI_USAGE/components/popover.md +208 -3
  70. package/AI_USAGE/components/popup-api.md +75 -0
  71. package/AI_USAGE/components/popup.md +52 -0
  72. package/AI_USAGE/components/progress-api.md +44 -0
  73. package/AI_USAGE/components/progress.md +248 -3
  74. package/AI_USAGE/components/radio-api.md +165 -0
  75. package/AI_USAGE/components/radio.md +259 -3
  76. package/AI_USAGE/components/rate-api.md +54 -0
  77. package/AI_USAGE/components/rate.md +233 -3
  78. package/AI_USAGE/components/resize-box-api.md +56 -0
  79. package/AI_USAGE/components/resize-box.md +231 -0
  80. package/AI_USAGE/components/scrollbar-api.md +77 -0
  81. package/AI_USAGE/components/scrollbar.md +218 -0
  82. package/AI_USAGE/components/select-api.md +758 -0
  83. package/AI_USAGE/components/select.md +640 -3
  84. package/AI_USAGE/components/skeleton-api.md +85 -0
  85. package/AI_USAGE/components/skeleton.md +150 -0
  86. package/AI_USAGE/components/slider-api.md +51 -0
  87. package/AI_USAGE/components/slider.md +233 -3
  88. package/AI_USAGE/components/space-api.md +38 -0
  89. package/AI_USAGE/components/space.md +145 -0
  90. package/AI_USAGE/components/spin-api.md +43 -0
  91. package/AI_USAGE/components/spin.md +205 -0
  92. package/AI_USAGE/components/steps-api.md +111 -0
  93. package/AI_USAGE/components/steps.md +201 -3
  94. package/AI_USAGE/components/switch-api.md +58 -0
  95. package/AI_USAGE/components/switch.md +290 -3
  96. package/AI_USAGE/components/table-api.md +2919 -0
  97. package/AI_USAGE/components/table.md +1414 -0
  98. package/AI_USAGE/components/tabs-api.md +135 -0
  99. package/AI_USAGE/components/tabs.md +308 -3
  100. package/AI_USAGE/components/tag-api.md +124 -0
  101. package/AI_USAGE/components/tag.md +292 -0
  102. package/AI_USAGE/components/textarea-api.md +55 -0
  103. package/AI_USAGE/components/textarea.md +326 -3
  104. package/AI_USAGE/components/time-picker-api.md +137 -0
  105. package/AI_USAGE/components/time-picker.md +271 -3
  106. package/AI_USAGE/components/time-range-selector-api.md +44 -0
  107. package/AI_USAGE/components/time-range-selector.md +355 -0
  108. package/AI_USAGE/components/timeline-api.md +93 -0
  109. package/AI_USAGE/components/timeline.md +312 -0
  110. package/AI_USAGE/components/tooltip-api.md +77 -0
  111. package/AI_USAGE/components/tooltip.md +182 -0
  112. package/AI_USAGE/components/trend-chart-api.md +119 -0
  113. package/AI_USAGE/components/trend-chart.md +335 -0
  114. package/AI_USAGE/components/trigger-api.md +124 -0
  115. package/AI_USAGE/components/trigger.md +185 -0
  116. package/AI_USAGE/components/upload-api.md +200 -0
  117. package/AI_USAGE/components/upload.md +711 -3
  118. package/AI_USAGE/components/watermark-api.md +87 -0
  119. package/AI_USAGE/components/watermark.md +200 -0
  120. package/AI_USAGE/core.md +1 -1
  121. package/AI_USAGE/index.md +35 -7
  122. package/AI_USAGE/recipes/form-on-demand.md +1 -1
  123. package/AI_USAGE.md +33657 -7
  124. package/CHANGELOG.md +40 -0
  125. package/dist/_utils/inherit-component-type.d.ts +11 -0
  126. package/dist/components/date-picker/index.d.ts +420 -5
  127. package/dist/components/form-input/index.d.ts +617 -2
  128. package/dist/components/layout/index.d.ts +689 -1
  129. package/dist/components/menu/index.d.ts +786 -1
  130. package/dist/components/network/Network.vue.d.ts +7 -3
  131. package/dist/components/network/index.d.ts +10 -2
  132. package/dist/components/network/props.d.ts +5 -0
  133. package/dist/components/network/utils.d.ts +3 -3
  134. package/dist/components/pagination/page-item-ellipsis.vue.d.ts +4 -1
  135. package/dist/components/pagination/page-item-step.vue.d.ts +101 -130
  136. package/dist/components/pagination/page-item.vue.d.ts +1 -0
  137. package/dist/components/pagination/page-jumper.vue.d.ts +1 -1
  138. package/dist/components/pagination/page-options.vue.d.ts +6 -4
  139. package/dist/components/pagination/utils.d.ts +3 -0
  140. package/dist/components/time-range-selector/index.d.ts +6 -6
  141. package/dist/es/_container/resize-observer-v2.js +1 -1
  142. package/dist/es/_container/resize-observer.js +1 -1
  143. package/dist/es/_hooks/use-resize-observer.js +1 -1
  144. package/dist/es/_styles/palette-aliases.js +4 -4
  145. package/dist/es/_utils/inherit-component-type.js +6 -0
  146. package/dist/es/_virtual/advancedFormat.js +1 -1
  147. package/dist/es/_virtual/customParseFormat.js +1 -1
  148. package/dist/es/_virtual/dayjs.min.js +1 -1
  149. package/dist/es/_virtual/isBetween.js +1 -1
  150. package/dist/es/_virtual/quarterOfYear.js +1 -1
  151. package/dist/es/_virtual/weekOfYear.js +1 -1
  152. package/dist/es/_virtual/weekYear.js +1 -1
  153. package/dist/es/_virtual/zh-cn.js +1 -1
  154. package/dist/es/components/button/Button.js +53 -42
  155. package/dist/es/components/date-picker/index.js +18 -17
  156. package/dist/es/components/draggable/useDraggable.js +1 -1
  157. package/dist/es/components/form/Form.vue2.js +1 -1
  158. package/dist/es/components/form/FormItem.vue2.js +1 -1
  159. package/dist/es/components/form-input/index.js +12 -11
  160. package/dist/es/components/form-input-number/InputNumber.js +1 -1
  161. package/dist/es/components/form-slider/Slider.vue2.js +1 -1
  162. package/dist/es/components/form-slider/slider-ticks.vue2.js +1 -1
  163. package/dist/es/components/form-slider/utils.js +1 -1
  164. package/dist/es/components/layout/index.js +10 -9
  165. package/dist/es/components/menu/MenuItem.js +1 -1
  166. package/dist/es/components/menu/hooks/use-level.js +5 -5
  167. package/dist/es/components/menu/index.js +13 -10
  168. package/dist/es/components/menu/overflow-wrap.js +1 -1
  169. package/dist/es/components/network/Network.vue.js +17 -12
  170. package/dist/es/components/network/Network.vue2.js +78 -70
  171. package/dist/es/components/network/utils.js +112 -71
  172. package/dist/es/components/pagination/Pagination.js +132 -123
  173. package/dist/es/components/pagination/page-item-ellipsis.vue.js +10 -10
  174. package/dist/es/components/pagination/page-item-ellipsis.vue2.js +24 -19
  175. package/dist/es/components/pagination/page-item-step.vue.js +14 -11
  176. package/dist/es/components/pagination/page-item-step.vue2.js +20 -22
  177. package/dist/es/components/pagination/page-item.vue.js +10 -9
  178. package/dist/es/components/pagination/page-item.vue2.js +24 -19
  179. package/dist/es/components/pagination/page-jumper.vue2.js +23 -23
  180. package/dist/es/components/pagination/page-options.vue.js +15 -10
  181. package/dist/es/components/pagination/page-options.vue2.js +21 -17
  182. package/dist/es/components/pagination/utils.js +4 -2
  183. package/dist/es/components/progress/circle.vue2.js +1 -1
  184. package/dist/es/components/progress/line.vue2.js +1 -1
  185. package/dist/es/components/progress/steps.vue2.js +1 -1
  186. package/dist/es/components/rate/Rate.js +1 -1
  187. package/dist/es/components/virtual-list-v2/virtual-list-item.js +1 -1
  188. package/dist/es/locale/en-US.js +2 -0
  189. package/dist/es/locale/zh-CN.js +2 -0
  190. 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
  191. 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
  192. 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
  193. 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
  194. 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
  195. 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
  196. 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
  197. 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
  198. package/dist/es/style.css +1 -1
  199. package/dist/index.cjs +3 -3
  200. package/dist/index.umd.js +3 -3
  201. package/dist/locale/interface.d.ts +3 -0
  202. package/dist/style/base.css +1 -1
  203. package/dist/style/button.css +1 -1
  204. package/dist/style/form-select.css +1 -1
  205. package/dist/style/network.css +1 -1
  206. package/dist/style/pagination.css +1 -1
  207. package/dist/style/table.css +1 -1
  208. package/dist/style.css +1 -1
  209. package/package.json +10 -5
  210. /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
  211. /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
  212. /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
  213. /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
  214. /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
  215. /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
  216. /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
  217. /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
  218. /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
  219. /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
  220. /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
  221. /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
  222. /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
  223. /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
  224. /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
  225. /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
  226. /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,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
  };