x-next 1.5.0 → 1.7.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.
- package/AI_USAGE.md +57 -4
- package/CHANGELOG.md +72 -0
- package/dist/_utils/color.d.ts +53 -0
- package/dist/components/color-picker/ColorPicker.d.ts +239 -0
- package/dist/components/color-picker/gradient-slider.d.ts +52 -0
- package/dist/components/color-picker/index.d.ts +238 -0
- package/dist/components/color-picker/panel.d.ts +721 -0
- package/dist/components/color-picker/sv-panel.d.ts +48 -0
- package/dist/components/date-picker/DatePicker.vue.d.ts +3 -3
- package/dist/components/date-picker/index.d.ts +6 -6
- package/dist/components/draggable/Draggable.d.ts +1 -1
- package/dist/components/draggable/index.d.ts +2 -2
- package/dist/components/drawer/index.d.ts +6 -6
- package/dist/components/drawer/src/Drawer.vue.d.ts +3 -3
- package/dist/components/dropdown/Dropdown.vue.d.ts +34 -4
- package/dist/components/dropdown/DropdownButton.vue.d.ts +35 -5
- package/dist/components/dropdown/DropdownSubmenu.vue.d.ts +34 -4
- package/dist/components/dropdown/dropdown-panel.vue.d.ts +30 -0
- package/dist/components/dropdown/index.d.ts +209 -29
- package/dist/components/form/FormItem.vue.d.ts +12 -12
- package/dist/components/form/form-item-label.vue.d.ts +3 -3
- package/dist/components/form/index.d.ts +24 -24
- package/dist/components/form-select/Select.d.ts +3 -3
- package/dist/components/form-select/SelectDropdown.vue.d.ts +30 -0
- package/dist/components/form-select/index.d.ts +66 -6
- package/dist/components/form-slider/Slider.vue.d.ts +3 -3
- package/dist/components/form-slider/index.d.ts +6 -6
- package/dist/components/form-slider/slider-button.vue.d.ts +3 -3
- package/dist/components/grid/Row.vue.d.ts +3 -3
- package/dist/components/grid/index.d.ts +9 -9
- package/dist/components/heatmap/Heatmap.d.ts +311 -0
- package/dist/components/heatmap/helpers/matrix.d.ts +58 -0
- package/dist/components/heatmap/index.d.ts +372 -0
- package/dist/components/heatmap/interface.d.ts +57 -0
- package/dist/components/image/Image.vue.d.ts +125 -17
- package/dist/components/image/ImagePreview.vue.d.ts +97 -7
- package/dist/components/image/ImagePreviewAction.d.ts +3 -3
- package/dist/components/image/ImagePreviewGroup.vue.d.ts +100 -7
- package/dist/components/image/hooks/use-image-drag.d.ts +2 -2
- package/dist/components/image/index.d.ts +712 -124
- package/dist/components/image/interface.d.ts +9 -1
- package/dist/components/image/preview-toolbar.vue.d.ts +3 -3
- package/dist/components/index.d.ts +3 -0
- package/dist/components/menu/sub-menu-pop.vue.d.ts +3 -3
- package/dist/components/network/Network.vue.d.ts +1 -1
- package/dist/components/network/index.d.ts +3 -3
- package/dist/components/network/utils.d.ts +2 -0
- package/dist/components/pagination/page-item-ellipsis.vue.d.ts +9 -0
- package/dist/components/pagination/page-jumper.vue.d.ts +6 -0
- package/dist/components/pagination/page-options.vue.d.ts +6 -6
- package/dist/components/popconfirm/src/popup.vue.d.ts +3 -3
- package/dist/components/popover/Popover.d.ts +1 -1
- package/dist/components/popover/index.d.ts +3 -3
- package/dist/components/popup/Popup.d.ts +1 -1
- package/dist/components/popup/index.d.ts +3 -3
- package/dist/components/skeleton/SkeletonShape.vue.d.ts +3 -3
- package/dist/components/skeleton/index.d.ts +6 -6
- package/dist/components/space/Space.d.ts +1 -1
- package/dist/components/space/index.d.ts +3 -3
- package/dist/components/spin/Spin.d.ts +38 -0
- package/dist/components/spin/index.d.ts +30 -0
- package/dist/components/table/Table.d.ts +1 -1
- package/dist/components/table/index.d.ts +3 -3
- package/dist/components/tabs/Tabs.d.ts +1 -1
- package/dist/components/tabs/index.d.ts +3 -3
- package/dist/components/time-picker/TimePicker.vue.d.ts +3 -3
- package/dist/components/time-picker/index.d.ts +6 -6
- package/dist/components/tooltip/Tooltip.vue.d.ts +1 -1
- package/dist/components/tooltip/index.d.ts +3 -3
- package/dist/components/trigger/Trigger.d.ts +1 -1
- package/dist/components/trigger/index.d.ts +3 -3
- package/dist/components/upload/Upload.d.ts +372 -0
- package/dist/components/upload/context.d.ts +28 -0
- package/dist/components/upload/index.d.ts +656 -0
- package/dist/components/upload/interface.d.ts +110 -0
- package/dist/components/upload/props.d.ts +321 -0
- package/dist/components/upload/upload-list-item.d.ts +15 -0
- package/dist/components/upload/upload-list.d.ts +11 -0
- package/dist/components/upload/upload-picture-item.d.ts +20 -0
- package/dist/components/upload/upload-trigger.d.ts +8 -0
- package/dist/components/upload/utils.d.ts +48 -0
- package/dist/components/watermark/Watermark.d.ts +1 -1
- package/dist/components/watermark/index.d.ts +3 -3
- package/dist/es/_styles/palette-aliases.js +10 -4
- package/dist/es/_utils/color.js +73 -0
- package/dist/es/components/button/Button.js +2 -2
- package/dist/es/components/color-picker/ColorPicker.js +239 -0
- package/dist/es/components/color-picker/gradient-slider.js +79 -0
- package/dist/es/components/color-picker/index.js +8 -0
- package/dist/es/components/color-picker/panel.js +307 -0
- package/dist/es/components/color-picker/sv-panel.js +99 -0
- package/dist/es/components/dropdown/dropdown-panel.vue.js +17 -17
- package/dist/es/components/form-input/Input.js +7 -7
- package/dist/es/components/form-input/InputPassword.vue2.js +2 -2
- package/dist/es/components/form-input/InputSearch.js +2 -2
- package/dist/es/components/form-input-number/InputNumber.js +12 -12
- package/dist/es/components/heatmap/Heatmap.js +334 -0
- package/dist/es/components/heatmap/helpers/matrix.js +106 -0
- package/dist/es/components/heatmap/index.js +8 -0
- package/dist/es/components/image/Image.vue.js +55 -45
- package/dist/es/components/image/Image.vue2.js +113 -92
- package/dist/es/components/image/ImagePreview.vue.js +66 -53
- package/dist/es/components/image/ImagePreview.vue2.js +219 -171
- package/dist/es/components/image/ImagePreviewAction.js +12 -15
- package/dist/es/components/image/ImagePreviewGroup.vue.js +21 -20
- package/dist/es/components/image/ImagePreviewGroup.vue2.js +45 -39
- package/dist/es/components/image/hooks/use-image-drag.js +16 -14
- package/dist/es/components/index.js +123 -117
- package/dist/es/components/menu/sub-menu-pop.vue2.js +12 -12
- package/dist/es/components/network/Network.vue2.js +72 -72
- package/dist/es/components/network/utils.js +44 -35
- package/dist/es/components/pagination/Pagination.js +113 -104
- package/dist/es/components/pagination/page-item-ellipsis.vue.js +13 -12
- package/dist/es/components/pagination/page-item-ellipsis.vue2.js +19 -15
- package/dist/es/components/pagination/page-jumper.vue.js +13 -12
- package/dist/es/components/pagination/page-jumper.vue2.js +7 -4
- package/dist/es/components/pagination/page-options.vue.js +4 -3
- package/dist/es/components/pagination/page-options.vue2.js +17 -15
- package/dist/es/components/skeleton/Skeleton.vue.js +11 -9
- package/dist/es/components/skeleton/SkeletonLine.vue.js +9 -8
- package/dist/es/components/skeleton/SkeletonShape.vue.js +8 -7
- package/dist/es/components/spin/Spin.js +124 -60
- package/dist/es/components/table/Table.js +3 -1
- package/dist/es/components/trigger/Trigger.js +19 -19
- package/dist/es/components/upload/Upload.js +420 -0
- package/dist/es/components/upload/context.js +4 -0
- package/dist/es/components/upload/index.js +8 -0
- package/dist/es/components/upload/props.js +321 -0
- package/dist/es/components/upload/upload-list-item.js +138 -0
- package/dist/es/components/upload/upload-list.js +48 -0
- package/dist/es/components/upload/upload-picture-item.js +109 -0
- package/dist/es/components/upload/upload-trigger.js +89 -0
- package/dist/es/components/upload/utils.js +195 -0
- package/dist/es/icons/_self/empty-better.js +25 -8
- package/dist/es/icons/_self/upload-icons.js +103 -0
- package/dist/es/index.js +168 -162
- package/dist/es/locale/en-US.js +39 -1
- package/dist/es/locale/zh-CN.js +39 -1
- package/dist/es/style.css +1 -1
- package/dist/icons/_self/upload-icons.d.ts +523 -0
- package/dist/index.cjs +4 -4
- package/dist/index.umd.js +4 -4
- package/dist/locale/interface.d.ts +60 -0
- package/dist/style/base.css +1 -1
- package/dist/style/button.css +1 -1
- package/dist/style/color-picker.css +1 -0
- package/dist/style/color-picker.js +2 -0
- package/dist/style/date-picker.css +1 -1
- package/dist/style/empty.css +1 -1
- package/dist/style/form-checkbox.css +1 -1
- package/dist/style/form-input-tag.css +1 -1
- package/dist/style/form-input.css +1 -1
- package/dist/style/form-radio.css +1 -1
- package/dist/style/form-textarea.css +1 -1
- package/dist/style/form.css +1 -1
- package/dist/style/heatmap.css +1 -0
- package/dist/style/heatmap.js +2 -0
- package/dist/style/image.css +1 -1
- package/dist/style/menu.css +1 -1
- package/dist/style/pagination.css +1 -1
- package/dist/style/skeleton.css +1 -1
- package/dist/style/spin.css +1 -1
- package/dist/style/steps.css +1 -1
- package/dist/style/table.css +1 -1
- package/dist/style/upload.css +1 -0
- package/dist/style/upload.js +2 -0
- package/dist/style.css +1 -1
- package/dist/types.d.ts +3 -0
- package/package.json +1 -1
- package/volar.d.ts +3 -0
- package/dist/es/_hooks/use-popup-overflow-hidden.js +0 -29
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { useLocale as
|
|
2
|
-
import { defineComponent as
|
|
3
|
-
import { getClassNameMixin as
|
|
4
|
-
import { Network as
|
|
5
|
-
const
|
|
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 = {
|
|
6
6
|
online: !0,
|
|
7
7
|
quality: "unknown",
|
|
8
8
|
source: "manual",
|
|
9
9
|
reason: "initial",
|
|
10
10
|
lastCheckedAt: 0
|
|
11
|
-
},
|
|
11
|
+
}, B = {
|
|
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
|
-
},
|
|
17
|
+
}, F = ["unknown", "good", "medium", "poor", "offline"], Y = U({
|
|
18
18
|
name: "Network",
|
|
19
19
|
props: {
|
|
20
20
|
size: {
|
|
@@ -40,7 +40,7 @@ const y = {
|
|
|
40
40
|
*/
|
|
41
41
|
status: {
|
|
42
42
|
type: String,
|
|
43
|
-
validator: (
|
|
43
|
+
validator: (t) => F.includes(t)
|
|
44
44
|
},
|
|
45
45
|
/**
|
|
46
46
|
* @zh 主动探测 URL,需要支持 CORS。
|
|
@@ -85,94 +85,94 @@ const y = {
|
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
87
|
emits: {
|
|
88
|
-
change: (
|
|
89
|
-
online: (
|
|
90
|
-
offline: (
|
|
91
|
-
probe: (
|
|
88
|
+
change: (t) => !0,
|
|
89
|
+
online: (t) => !0,
|
|
90
|
+
offline: (t) => !0,
|
|
91
|
+
probe: (t) => !0
|
|
92
92
|
},
|
|
93
|
-
setup(
|
|
94
|
-
const a =
|
|
95
|
-
...
|
|
96
|
-
online:
|
|
97
|
-
quality:
|
|
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,
|
|
96
|
+
online: e !== "offline",
|
|
97
|
+
quality: e,
|
|
98
98
|
source: "manual",
|
|
99
99
|
lastCheckedAt: Date.now()
|
|
100
|
-
}),
|
|
101
|
-
() =>
|
|
102
|
-
),
|
|
103
|
-
const [o,
|
|
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 = {
|
|
104
104
|
unknown: "var(--x-network-color-unknown)",
|
|
105
105
|
good: o || "var(--x-network-color-good)",
|
|
106
|
-
medium:
|
|
107
|
-
poor:
|
|
106
|
+
medium: t.statusColors.medium || "var(--x-network-color-medium)",
|
|
107
|
+
poor: h || "var(--x-network-color-poor)",
|
|
108
108
|
offline: "var(--x-network-color-offline)"
|
|
109
109
|
};
|
|
110
|
-
return
|
|
111
|
-
},
|
|
112
|
-
const
|
|
113
|
-
return Array.from({ length: s.value }, (
|
|
114
|
-
const
|
|
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;
|
|
115
115
|
return {
|
|
116
|
-
active:
|
|
117
|
-
color:
|
|
116
|
+
active: y,
|
|
117
|
+
color: y ? o : "var(--x-network-color-inactive)"
|
|
118
118
|
};
|
|
119
119
|
});
|
|
120
|
-
}),
|
|
121
|
-
if (
|
|
122
|
-
const o =
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
var
|
|
126
|
-
if ((
|
|
127
|
-
|
|
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
128
|
return;
|
|
129
129
|
}
|
|
130
|
-
r.value = new
|
|
131
|
-
ping:
|
|
132
|
-
interval:
|
|
133
|
-
timeout:
|
|
134
|
-
}),
|
|
135
|
-
},
|
|
136
|
-
var
|
|
137
|
-
if (
|
|
138
|
-
const o =
|
|
139
|
-
return
|
|
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 () => {
|
|
136
|
+
var e;
|
|
137
|
+
if (t.status) {
|
|
138
|
+
const o = f(t.status);
|
|
139
|
+
return l("change", o), o;
|
|
140
140
|
}
|
|
141
|
-
return (
|
|
141
|
+
return await ((e = r.value) == null ? void 0 : e.refresh()) ?? i.value;
|
|
142
142
|
};
|
|
143
|
-
|
|
144
|
-
() => [
|
|
143
|
+
K(
|
|
144
|
+
() => [t.status, t.ping, t.interval, t.timeout],
|
|
145
145
|
() => {
|
|
146
|
-
|
|
146
|
+
k();
|
|
147
147
|
}
|
|
148
|
-
),
|
|
149
|
-
|
|
150
|
-
}),
|
|
151
|
-
var
|
|
152
|
-
(
|
|
153
|
-
}),
|
|
154
|
-
const
|
|
148
|
+
), D(() => {
|
|
149
|
+
k();
|
|
150
|
+
}), I(() => {
|
|
151
|
+
var e;
|
|
152
|
+
(e = r.value) == null || e.destroy(), r.value = void 0;
|
|
153
|
+
}), x({ refresh: S });
|
|
154
|
+
const b = n(() => [
|
|
155
155
|
a.block,
|
|
156
|
-
|
|
157
|
-
a.modifier(`status-${
|
|
156
|
+
t.size && a.modifier(t.size),
|
|
157
|
+
a.modifier(`status-${u.value.quality}`),
|
|
158
158
|
{
|
|
159
|
-
[a.is("with-text")]:
|
|
160
|
-
[a.is("with-metrics")]:
|
|
159
|
+
[a.is("with-text")]: d.value,
|
|
160
|
+
[a.is("with-metrics")]: d.value
|
|
161
161
|
}
|
|
162
162
|
]);
|
|
163
163
|
return {
|
|
164
164
|
className: a,
|
|
165
|
-
cls:
|
|
166
|
-
lineItems:
|
|
167
|
-
mergedStatus:
|
|
168
|
-
statusText:
|
|
169
|
-
mergedAriaLabel:
|
|
170
|
-
formattedDownloadSpeed:
|
|
171
|
-
mergedShowMetrics:
|
|
172
|
-
refresh:
|
|
165
|
+
cls: b,
|
|
166
|
+
lineItems: q,
|
|
167
|
+
mergedStatus: u,
|
|
168
|
+
statusText: g,
|
|
169
|
+
mergedAriaLabel: M,
|
|
170
|
+
formattedDownloadSpeed: T,
|
|
171
|
+
mergedShowMetrics: d,
|
|
172
|
+
refresh: S
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
});
|
|
176
176
|
export {
|
|
177
|
-
|
|
177
|
+
Y as default
|
|
178
178
|
};
|
|
@@ -1,60 +1,67 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (
|
|
4
|
-
const
|
|
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 = {
|
|
5
5
|
online: !0,
|
|
6
6
|
quality: "unknown",
|
|
7
7
|
source: "manual",
|
|
8
8
|
reason: "initial",
|
|
9
9
|
lastCheckedAt: 0
|
|
10
|
-
},
|
|
10
|
+
}, f = () => Date.now(), d = () => typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now(), m = () => {
|
|
11
11
|
if (!(typeof navigator > "u"))
|
|
12
12
|
return navigator.connection;
|
|
13
|
-
}, l = () => typeof navigator < "u" && navigator.onLine === !1, k = (
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
}, l = () => typeof navigator < "u" && navigator.onLine === !1, k = (t) => {
|
|
14
|
+
const { effectiveType: e } = t;
|
|
15
|
+
if (e === "slow-2g" || e === "2g") return "poor";
|
|
16
|
+
if (e === "3g") return "medium";
|
|
17
|
+
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) => ({
|
|
17
22
|
online: !1,
|
|
18
23
|
quality: "offline",
|
|
19
|
-
source:
|
|
24
|
+
source: t,
|
|
20
25
|
reason: e,
|
|
21
|
-
lastCheckedAt:
|
|
22
|
-
}), c = (
|
|
26
|
+
lastCheckedAt: f()
|
|
27
|
+
}), c = (t) => {
|
|
23
28
|
if (typeof navigator > "u")
|
|
24
29
|
return {
|
|
25
30
|
online: !0,
|
|
26
31
|
quality: "unknown",
|
|
27
32
|
source: "navigator",
|
|
28
33
|
reason: "unsupported",
|
|
29
|
-
lastCheckedAt:
|
|
34
|
+
lastCheckedAt: f()
|
|
30
35
|
};
|
|
31
36
|
if (l())
|
|
32
37
|
return w("navigator", "browser-offline");
|
|
33
38
|
const e = m();
|
|
34
39
|
return e ? {
|
|
35
40
|
online: !0,
|
|
36
|
-
quality: k(e),
|
|
41
|
+
quality: k(e) ?? "unknown",
|
|
37
42
|
downlink: e.downlink,
|
|
38
43
|
rtt: e.rtt,
|
|
39
44
|
effectiveType: e.effectiveType,
|
|
40
45
|
source: "connection",
|
|
41
|
-
reason:
|
|
42
|
-
lastCheckedAt:
|
|
46
|
+
reason: t,
|
|
47
|
+
lastCheckedAt: f()
|
|
43
48
|
} : {
|
|
44
49
|
online: !0,
|
|
45
50
|
quality: "good",
|
|
46
51
|
source: "navigator",
|
|
47
|
-
reason:
|
|
48
|
-
lastCheckedAt:
|
|
52
|
+
reason: t,
|
|
53
|
+
lastCheckedAt: f()
|
|
49
54
|
};
|
|
50
55
|
};
|
|
51
56
|
class L {
|
|
52
|
-
constructor(e,
|
|
57
|
+
constructor(e, n = {}) {
|
|
53
58
|
o(this, "callback");
|
|
54
59
|
o(this, "options");
|
|
55
60
|
o(this, "timer");
|
|
56
61
|
o(this, "initialTimer");
|
|
57
62
|
o(this, "connection");
|
|
63
|
+
/** 不支持 addEventListener 时保存 connection.onchange 的原处理器,销毁时归还 */
|
|
64
|
+
o(this, "previousConnectionOnChange");
|
|
58
65
|
o(this, "controller");
|
|
59
66
|
o(this, "destroyed", !1);
|
|
60
67
|
o(this, "pendingRefresh");
|
|
@@ -65,51 +72,51 @@ class L {
|
|
|
65
72
|
o(this, "handleConnectionChange", () => {
|
|
66
73
|
this.refresh("connection-change");
|
|
67
74
|
});
|
|
68
|
-
this.callback = e, this.options =
|
|
75
|
+
this.callback = e, this.options = n, this.boot();
|
|
69
76
|
}
|
|
70
77
|
checkNetworkQuality() {
|
|
71
78
|
return c().quality;
|
|
72
79
|
}
|
|
73
80
|
getSnapshot() {
|
|
74
|
-
return typeof window > "u" || typeof navigator > "u" ?
|
|
81
|
+
return typeof window > "u" || typeof navigator > "u" ? y : c();
|
|
75
82
|
}
|
|
76
83
|
async refresh(e) {
|
|
77
84
|
if (this.pendingRefresh) return this.pendingRefresh;
|
|
78
|
-
const
|
|
79
|
-
return this.pendingRefresh = this.resolveStatus(e).then((i) => (!this.destroyed &&
|
|
85
|
+
const n = ++this.sequence;
|
|
86
|
+
return this.pendingRefresh = this.resolveStatus(e).then((i) => (!this.destroyed && n === this.sequence && this.emitCallback(i), i)).finally(() => {
|
|
80
87
|
this.pendingRefresh = void 0;
|
|
81
88
|
}), this.pendingRefresh;
|
|
82
89
|
}
|
|
83
90
|
async resolveStatus(e) {
|
|
84
|
-
return typeof window > "u" || typeof navigator > "u" ?
|
|
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);
|
|
85
92
|
}
|
|
86
|
-
async pingNetworkQuality(e,
|
|
93
|
+
async pingNetworkQuality(e, n = 5e3) {
|
|
87
94
|
var p;
|
|
88
95
|
const i = d();
|
|
89
96
|
(p = this.controller) == null || p.abort();
|
|
90
97
|
const r = typeof AbortController < "u" ? new AbortController() : void 0;
|
|
91
98
|
this.controller = r;
|
|
92
|
-
const
|
|
99
|
+
const h = r ? setTimeout(() => r.abort(), Math.max(n, 1)) : void 0;
|
|
93
100
|
try {
|
|
94
101
|
const s = await fetch(e, {
|
|
95
102
|
cache: "no-cache",
|
|
96
103
|
method: "GET",
|
|
97
104
|
mode: "cors",
|
|
98
105
|
signal: r == null ? void 0 : r.signal
|
|
99
|
-
}), a = Math.round(d() - i),
|
|
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;
|
|
100
107
|
return s.ok ? {
|
|
101
108
|
...c(),
|
|
102
|
-
quality:
|
|
109
|
+
quality: q(a),
|
|
103
110
|
latency: a,
|
|
104
|
-
downloadSpeed:
|
|
105
|
-
speedSource:
|
|
111
|
+
downloadSpeed: u,
|
|
112
|
+
speedSource: u ? "probe" : void 0,
|
|
106
113
|
source: "probe"
|
|
107
114
|
} : {
|
|
108
115
|
...c("http-error"),
|
|
109
116
|
quality: "poor",
|
|
110
117
|
latency: a,
|
|
111
|
-
downloadSpeed:
|
|
112
|
-
speedSource:
|
|
118
|
+
downloadSpeed: u,
|
|
119
|
+
speedSource: u ? "probe" : void 0,
|
|
113
120
|
source: "probe",
|
|
114
121
|
reason: "http-error"
|
|
115
122
|
};
|
|
@@ -123,7 +130,7 @@ class L {
|
|
|
123
130
|
reason: a ? "probe-timeout" : "probe-error"
|
|
124
131
|
};
|
|
125
132
|
} finally {
|
|
126
|
-
|
|
133
|
+
h && clearTimeout(h), this.controller === r && (this.controller = void 0);
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
136
|
boot() {
|
|
@@ -131,7 +138,9 @@ class L {
|
|
|
131
138
|
return;
|
|
132
139
|
window.addEventListener("online", this.handleWindowChange), window.addEventListener("offline", this.handleWindowChange);
|
|
133
140
|
const e = m();
|
|
134
|
-
e && (this.connection = e, e.addEventListener ? e.addEventListener("change", this.handleConnectionChange) :
|
|
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(() => {
|
|
135
144
|
this.refresh();
|
|
136
145
|
}, 0), this.scheduleNextRefresh();
|
|
137
146
|
}
|
|
@@ -145,7 +154,7 @@ class L {
|
|
|
145
154
|
}
|
|
146
155
|
destroy() {
|
|
147
156
|
var e;
|
|
148
|
-
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
|
|
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);
|
|
149
158
|
}
|
|
150
159
|
}
|
|
151
160
|
export {
|