@ansidev-oss/vitepress-theme-ansidev 1.0.12 → 1.2.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/dist/client/Donation-BBPb8v5p.js +66 -0
- package/dist/client/GoogleAnalytics-34XEM7eO.js +25 -0
- package/dist/client/Sharing-CpagX9oy.js +185 -0
- package/dist/client/Swetrix-GKEyGNrV.js +647 -0
- package/dist/client/components/PostDate.test.d.ts +1 -0
- package/dist/client/composables/index.d.ts +1 -0
- package/dist/client/composables/lang.d.ts +27 -0
- package/dist/client/composables/lang.test.d.ts +1 -0
- package/dist/client/index.js +3769 -9
- package/dist/client/medium-zoom-DPl0T7qn.js +266 -0
- package/dist/client/record-Cgv_fXDH.js +2739 -0
- package/dist/client/styles.css +2 -1
- package/dist/client/types/index.d.ts +8 -0
- package/dist/node/composables.d.mts +16 -17
- package/dist/node/composables.mjs +39 -15
- package/dist/node/config.d.mts +2 -17
- package/dist/node/config.mjs +9 -6
- package/package.json +27 -21
- package/src/client/components/DonationWidget.vue +9 -3
- package/src/client/components/Footer.vue +11 -4
- package/src/client/components/Link.vue +11 -5
- package/src/client/components/LocaleSwitcher.vue +5 -5
- package/src/client/components/PostDate.test.ts +82 -0
- package/src/client/components/PostDate.vue +32 -13
- package/src/client/components/PostItem.vue +17 -7
- package/src/client/components/PostList.vue +7 -4
- package/src/client/components/ProjectCard.vue +42 -14
- package/src/client/components/ProjectList.vue +12 -5
- package/src/client/components/RouterLink.vue +3 -3
- package/src/client/components/SharingWidget.vue +3 -1
- package/src/client/components/StatusBadge.vue +10 -10
- package/src/client/components/TermBadge.vue +11 -7
- package/src/client/components/TermLink.vue +4 -4
- package/src/client/composables/date.ts +1 -1
- package/src/client/composables/index.ts +1 -0
- package/src/client/composables/lang.test.ts +56 -0
- package/src/client/composables/lang.ts +65 -0
- package/src/client/composables/locale.ts +4 -1
- package/src/client/composables/project.ts +3 -3
- package/src/client/composables/rank.ts +5 -2
- package/src/client/index.ts +5 -0
- package/src/client/layouts/Layout.vue +2 -2
- package/src/client/pages/ArchivesPage.vue +10 -5
- package/src/client/pages/CategoriesPage.vue +13 -5
- package/src/client/pages/HomePage.vue +3 -3
- package/src/client/pages/Page.vue +13 -11
- package/src/client/pages/PostsPage.vue +4 -4
- package/src/client/pages/ProjectsPage.vue +10 -7
- package/src/client/pages/TagsPage.vue +10 -4
- package/src/client/plugins/donation/components/Donation.vue +5 -3
- package/src/client/plugins/donation/components/DonationButton.vue +3 -1
- package/src/client/plugins/donation/index.ts +11 -8
- package/src/client/plugins/i18n/index.ts +2 -2
- package/src/client/plugins/sharing/components/Sharing.vue +39 -15
- package/src/client/plugins/sharing/components/SharingButton.vue +34 -14
- package/src/client/plugins/sharing/index.ts +6 -2
- package/src/client/styles/base.css +30 -0
- package/src/client/styles/blog.css +376 -0
- package/src/client/styles/index.css +2 -30
- package/src/client/types/index.ts +8 -0
- package/src/node/composables/excerpt.test.ts +88 -0
- package/src/node/composables/excerpt.ts +57 -0
- package/src/node/composables/index.ts +1 -0
- package/src/node/composables/markdown.ts +8 -2
- package/src/node/composables/route.ts +15 -7
- package/src/node/composables/slug.ts +12 -4
- package/src/node/config.ts +20 -14
- package/src/shared/composables/useSlug.ts +2 -1
- package/src/vite-env.d.ts +1 -0
- package/dist/client/Donation-D9Xn0MPt.js +0 -76
- package/dist/client/GoogleAnalytics-Dp3EGn1x.js +0 -29
- package/dist/client/Sharing-ZrU7YF-x.js +0 -190
- package/dist/client/Swetrix-CM1mbD6X.js +0 -450
- package/dist/client/VPAlgoliaSearchBox-C18GEhLm.js +0 -126
- package/dist/client/VPCarbonAds-DwoamMao.js +0 -31
- package/dist/client/VPLocalSearchBox-DyteUinQ.js +0 -4086
- package/dist/client/index-BtT3qA6T.js +0 -12663
- package/dist/client/index-CCR5sUM8.js +0 -10688
- package/dist/client/index-CkmxezC0.js +0 -7616
- package/dist/client/index-DuYWs0vj.js +0 -265
- package/dist/node/composables/index.d.ts +0 -3
- package/dist/node/composables/markdown.d.ts +0 -2
- package/dist/node/composables/route.d.ts +0 -15
- package/dist/node/composables/slug.d.ts +0 -7
- package/dist/node/composables/types.d.ts +0 -7
- package/dist/node/config.d.ts +0 -45
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
import { defineComponent as e, onMounted as t } from "vue";
|
|
2
|
+
// ../../node_modules/.pnpm/swetrix@4.8.0/node_modules/swetrix/dist/esnext/utils.js
|
|
3
|
+
var n = (e) => {
|
|
4
|
+
let t = location.search.match(e);
|
|
5
|
+
return t && t[2] || void 0;
|
|
6
|
+
}, r = /[?&](ref|source|utm_source|gad_source)=([^?&]+)/, i = /[?&](utm_campaign|gad_campaignid)=([^?&]+)/, a = /[?&](utm_medium)=([^?&]+)/, o = /[?&](utm_term)=([^?&]+)/, s = /[?&](utm_content)=([^?&]+)/, c = /[?&](gclid)=([^?&]+)/, l = () => n(c) ? "<gclid>" : void 0, u = () => typeof window < "u", d = () => location?.hostname === "localhost" || location?.hostname === "127.0.0.1" || location?.hostname === "", f = () => navigator?.webdriver, p = () => navigator.languages === void 0 ? navigator.language : navigator.languages[0], m = () => {
|
|
7
|
+
try {
|
|
8
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
9
|
+
} catch {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
}, h = () => document.referrer || void 0, g = () => {
|
|
13
|
+
if (location.search && location.search.length > 1) return location.search.slice(1);
|
|
14
|
+
let e = location.hash.indexOf("?");
|
|
15
|
+
if (e > -1) {
|
|
16
|
+
let t = location.hash.slice(e + 1);
|
|
17
|
+
if (t) return t;
|
|
18
|
+
}
|
|
19
|
+
}, _ = () => n(r), v = () => n(a) || l(), y = () => n(i), b = () => n(o), x = () => n(s), S = (e, t) => {
|
|
20
|
+
if (t === !0) return e;
|
|
21
|
+
if (!Array.isArray(t) || !e) return "";
|
|
22
|
+
let n = new Set(t), r = e.slice(1).split("&").filter((e) => {
|
|
23
|
+
let t = e.indexOf("="), r = t === -1 ? e : e.slice(0, t);
|
|
24
|
+
try {
|
|
25
|
+
return n.has(decodeURIComponent(r.replace(/\+/g, " ")));
|
|
26
|
+
} catch {
|
|
27
|
+
return n.has(r);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return r.length ? `?${r.join("&")}` : "";
|
|
31
|
+
}, C = (e, t) => {
|
|
32
|
+
if (t === !0) return e;
|
|
33
|
+
if (!Array.isArray(t) || !e) return "";
|
|
34
|
+
let n = e.slice(1);
|
|
35
|
+
return t.some((e) => e.replace(/^#/, "") === n) ? e : "";
|
|
36
|
+
}, w = (e) => {
|
|
37
|
+
let t = location.pathname || "";
|
|
38
|
+
if (e.hash) {
|
|
39
|
+
let n = location.hash.indexOf("?"), r = n > -1 ? location.hash.substring(0, n) : location.hash;
|
|
40
|
+
t += C(r, e.hash);
|
|
41
|
+
}
|
|
42
|
+
if (e.search) {
|
|
43
|
+
let n = location.hash.indexOf("?"), r = location.search || (n > -1 ? location.hash.substring(n) : "");
|
|
44
|
+
t += S(r, e.search);
|
|
45
|
+
}
|
|
46
|
+
return t;
|
|
47
|
+
}, T = [
|
|
48
|
+
"total",
|
|
49
|
+
"normal",
|
|
50
|
+
"none"
|
|
51
|
+
], E = { stop() {} }, D = {
|
|
52
|
+
async stop() {},
|
|
53
|
+
async flush() {}
|
|
54
|
+
}, O = "https://api.swetrix.com/log", k = "https://api.swetrix.com", A = "usr_", j = (e) => `${A}${e.trim()}`, M = "replaylibrary.min.js", N = `https://cdn.jsdelivr.net/npm/swetrix@latest/dist/${M}`, P = 5e3, F = 100, I = 524288, L = 5242880, R = 18e5, z = "total", B = {
|
|
55
|
+
mousemove: 50,
|
|
56
|
+
scroll: 150,
|
|
57
|
+
input: "last"
|
|
58
|
+
}, V = {
|
|
59
|
+
script: !0,
|
|
60
|
+
comment: !0,
|
|
61
|
+
headFavicon: !0,
|
|
62
|
+
headWhitespace: !0,
|
|
63
|
+
headMetaDescKeywords: !0,
|
|
64
|
+
headMetaSocial: !0,
|
|
65
|
+
headMetaRobots: !0,
|
|
66
|
+
headMetaHttpEquiv: !0,
|
|
67
|
+
headMetaAuthorship: !0,
|
|
68
|
+
headMetaVerification: !0
|
|
69
|
+
}, H = 2, U = [
|
|
70
|
+
2e3,
|
|
71
|
+
5e3,
|
|
72
|
+
15e3
|
|
73
|
+
], W = 3, G = [
|
|
74
|
+
"click",
|
|
75
|
+
"keydown",
|
|
76
|
+
"mousedown",
|
|
77
|
+
"mousemove",
|
|
78
|
+
"scroll",
|
|
79
|
+
"touchstart"
|
|
80
|
+
], K = 3e5, q = (e) => typeof TextEncoder < "u" ? new TextEncoder().encode(e).length : typeof Blob < "u" ? new Blob([e]).size : e.length, J = class {
|
|
81
|
+
constructor(e, t) {
|
|
82
|
+
this.projectID = e, this.options = t, this.pageData = null, this.pageViewsOptions = null, this.errorsOptions = null, this.perfStatsCollected = !1, this.activePage = null, this.errorListenerExists = !1, this.cachedData = null, this.rrwebLoader = null, this.sessionReplayActions = null, this.sessionReplayInitPromise = null, this.identifiedProfileId = null, this.lastIdentifySent = null, this.trackPathChange = this.trackPathChange.bind(this), this.heartbeat = this.heartbeat.bind(this), this.captureError = this.captureError.bind(this), this.captureOutboundLink = this.captureOutboundLink.bind(this), this.options?.events?.outboundLinks && this.canTrack() && (document.addEventListener("click", this.captureOutboundLink, !0), document.addEventListener("auxclick", this.captureOutboundLink, !0)), this.getSessionReplayPreloadOption() && this.preloadSessionReplay().catch(() => void 0);
|
|
83
|
+
}
|
|
84
|
+
stopAutoCapture() {
|
|
85
|
+
u() && (document.removeEventListener("click", this.captureOutboundLink, !0), document.removeEventListener("auxclick", this.captureOutboundLink, !0));
|
|
86
|
+
}
|
|
87
|
+
captureOutboundLink(e) {
|
|
88
|
+
if (!this.canTrack() || (e.type === "click" ? e.button !== 0 : e.button !== 1)) return;
|
|
89
|
+
let t = e.composedPath?.() || [e.target], n = t.find((e) => e instanceof Element && e.matches("a[href], area[href]"));
|
|
90
|
+
if (!n || t.some((e) => e instanceof Element && e.hasAttribute("data-swetrix-ignore"))) return;
|
|
91
|
+
let r = this.options?.events?.outboundLinks, i = typeof r == "object" ? r : {};
|
|
92
|
+
try {
|
|
93
|
+
let e = new URL(n.getAttribute("href"), document.baseURI), t = e.hostname.replace(/^www\./, "");
|
|
94
|
+
if (!["http:", "https:"].includes(e.protocol) || t === window.location.hostname.replace(/^www\./, "") || i.ignoreDomains?.some((e) => t === e.toLowerCase().replace(/^www\./, "")) || (e.username = "", e.password = "", i.search || (e.search = ""), i.hash || (e.hash = ""), e.href.length > 2048)) return;
|
|
95
|
+
this.sendRequest("outbound", {
|
|
96
|
+
...this.getEventContext(),
|
|
97
|
+
qs: g()?.slice(0, 2048),
|
|
98
|
+
url: e.href,
|
|
99
|
+
title: document.title?.slice(0, 2048) || void 0
|
|
100
|
+
}).catch(() => void 0);
|
|
101
|
+
} catch {}
|
|
102
|
+
}
|
|
103
|
+
captureError(e) {
|
|
104
|
+
typeof this.errorsOptions?.sampleRate == "number" && this.errorsOptions.sampleRate >= Math.random() || this.submitError({
|
|
105
|
+
filename: e.filename,
|
|
106
|
+
lineno: e.lineno,
|
|
107
|
+
colno: e.colno,
|
|
108
|
+
name: e.error?.name || "Error",
|
|
109
|
+
message: e.error?.message || e.message,
|
|
110
|
+
stackTrace: e.error?.stack
|
|
111
|
+
}, !0);
|
|
112
|
+
}
|
|
113
|
+
trackErrors(e) {
|
|
114
|
+
return this.errorListenerExists || !this.canTrack() ? E : (this.errorsOptions = e, window.addEventListener("error", this.captureError), this.errorListenerExists = !0, { stop: () => {
|
|
115
|
+
window.removeEventListener("error", this.captureError), this.errorListenerExists = !1;
|
|
116
|
+
} });
|
|
117
|
+
}
|
|
118
|
+
submitError(e, t) {
|
|
119
|
+
let n = { pid: this.projectID }, r = {
|
|
120
|
+
pg: this.activePage || w({
|
|
121
|
+
hash: this.pageViewsOptions?.hash,
|
|
122
|
+
search: this.pageViewsOptions?.search
|
|
123
|
+
}),
|
|
124
|
+
lc: p(),
|
|
125
|
+
tz: m(),
|
|
126
|
+
...e
|
|
127
|
+
};
|
|
128
|
+
if (t && this.errorsOptions?.callback) {
|
|
129
|
+
let e = this.errorsOptions.callback(r);
|
|
130
|
+
if (e === !1) return;
|
|
131
|
+
e && typeof e == "object" && Object.assign(r, e);
|
|
132
|
+
}
|
|
133
|
+
Object.assign(r, n), this.sendRequest("error", r);
|
|
134
|
+
}
|
|
135
|
+
async track(e) {
|
|
136
|
+
this.canTrack() && await this.sendRequest("custom", {
|
|
137
|
+
...e,
|
|
138
|
+
...this.getEventContext(),
|
|
139
|
+
profileId: e.profileId ?? this.options?.profileId
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
getEventContext() {
|
|
143
|
+
return {
|
|
144
|
+
pid: this.projectID,
|
|
145
|
+
pg: this.activePage || w({
|
|
146
|
+
hash: this.pageViewsOptions?.hash,
|
|
147
|
+
search: this.pageViewsOptions?.search
|
|
148
|
+
}),
|
|
149
|
+
lc: p(),
|
|
150
|
+
tz: m(),
|
|
151
|
+
ref: h(),
|
|
152
|
+
so: _(),
|
|
153
|
+
me: v(),
|
|
154
|
+
ca: y(),
|
|
155
|
+
te: b(),
|
|
156
|
+
co: x(),
|
|
157
|
+
qs: g(),
|
|
158
|
+
profileId: this.options?.profileId
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
trackPageViews(e) {
|
|
162
|
+
if (!this.canTrack()) return E;
|
|
163
|
+
if (this.pageData) return this.pageData.actions;
|
|
164
|
+
this.pageViewsOptions = e;
|
|
165
|
+
let t;
|
|
166
|
+
e?.unique || (t = setInterval(this.trackPathChange, 2e3)), setTimeout(this.heartbeat, 3e3);
|
|
167
|
+
let n = setInterval(this.heartbeat, 28e3), r = w({
|
|
168
|
+
hash: e?.hash,
|
|
169
|
+
search: e?.search
|
|
170
|
+
});
|
|
171
|
+
return this.pageData = {
|
|
172
|
+
path: r,
|
|
173
|
+
actions: { stop: () => {
|
|
174
|
+
clearInterval(t), clearInterval(n);
|
|
175
|
+
} }
|
|
176
|
+
}, this.trackPage(r, e?.unique), this.pageData.actions;
|
|
177
|
+
}
|
|
178
|
+
getPerformanceStats() {
|
|
179
|
+
if (!this.canTrack() || this.perfStatsCollected || !window.performance?.getEntriesByType) return {};
|
|
180
|
+
let e = window.performance.getEntriesByType("navigation")[0];
|
|
181
|
+
return e ? (this.perfStatsCollected = !0, {
|
|
182
|
+
dns: e.domainLookupEnd - e.domainLookupStart,
|
|
183
|
+
tls: e.secureConnectionStart ? e.requestStart - e.secureConnectionStart : 0,
|
|
184
|
+
conn: e.secureConnectionStart ? e.secureConnectionStart - e.connectStart : e.connectEnd - e.connectStart,
|
|
185
|
+
response: e.responseEnd - e.responseStart,
|
|
186
|
+
render: e.domComplete - e.domContentLoadedEventEnd,
|
|
187
|
+
dom_load: e.domContentLoadedEventEnd - e.responseEnd,
|
|
188
|
+
page_load: e.loadEventStart,
|
|
189
|
+
ttfb: e.responseStart - e.requestStart
|
|
190
|
+
}) : {};
|
|
191
|
+
}
|
|
192
|
+
async getFeatureFlags(e, t) {
|
|
193
|
+
if (!u()) return {};
|
|
194
|
+
let n = e?.profileId ?? this.options?.profileId;
|
|
195
|
+
if (!t && this.cachedData) {
|
|
196
|
+
let e = Date.now();
|
|
197
|
+
if (this.cachedData.profileId === n && e - this.cachedData.timestamp < K) return this.cachedData.flags;
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
return await this.fetchFlagsAndExperiments(e), this.cachedData?.flags || {};
|
|
201
|
+
} catch (e) {
|
|
202
|
+
return console.warn("[Swetrix] Error fetching feature flags:", e), this.cachedData?.flags || {};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async fetchFlagsAndExperiments(e) {
|
|
206
|
+
let t = this.getApiBase(), n = { pid: this.projectID }, r = e?.profileId ?? this.options?.profileId;
|
|
207
|
+
r && (n.profileId = r);
|
|
208
|
+
let i = await fetch(`${t}/feature-flag/evaluate`, {
|
|
209
|
+
method: "POST",
|
|
210
|
+
headers: { "Content-Type": "application/json" },
|
|
211
|
+
body: JSON.stringify(n)
|
|
212
|
+
});
|
|
213
|
+
if (!i.ok) {
|
|
214
|
+
console.warn("[Swetrix] Failed to fetch feature flags and experiments:", i.status);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
let a = await i.json(), o = e?.profileId ?? this.options?.profileId;
|
|
218
|
+
this.cachedData = {
|
|
219
|
+
flags: a.flags || {},
|
|
220
|
+
experiments: a.experiments || {},
|
|
221
|
+
timestamp: Date.now(),
|
|
222
|
+
profileId: o
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
async getFeatureFlag(e, t, n = !1) {
|
|
226
|
+
return (await this.getFeatureFlags(t))[e] ?? n;
|
|
227
|
+
}
|
|
228
|
+
clearFeatureFlagsCache() {
|
|
229
|
+
this.cachedData = null;
|
|
230
|
+
}
|
|
231
|
+
async identify(e, t) {
|
|
232
|
+
if (typeof e != "string" || !e.trim()) {
|
|
233
|
+
console.error("[Swetrix] identify() expects a non-empty string profileId");
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
let n = e.trim();
|
|
237
|
+
this.options = {
|
|
238
|
+
...this.options,
|
|
239
|
+
profileId: n
|
|
240
|
+
};
|
|
241
|
+
let r = `${n}:${t ? JSON.stringify(t) : ""}`;
|
|
242
|
+
if (this.canTrack() && this.lastIdentifySent !== r) {
|
|
243
|
+
this.lastIdentifySent = r, this.clearFeatureFlagsCache();
|
|
244
|
+
try {
|
|
245
|
+
let e = this.getApiBase(), r = await fetch(`${e}/log/identify`, {
|
|
246
|
+
method: "POST",
|
|
247
|
+
headers: { "Content-Type": "application/json" },
|
|
248
|
+
body: JSON.stringify({
|
|
249
|
+
pid: this.projectID,
|
|
250
|
+
profileId: n,
|
|
251
|
+
traits: t
|
|
252
|
+
})
|
|
253
|
+
});
|
|
254
|
+
if (!r.ok) return;
|
|
255
|
+
let i = await r.json();
|
|
256
|
+
this.identifiedProfileId = i.profileId || null;
|
|
257
|
+
} catch {}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async setTraits(e) {
|
|
261
|
+
let t = this.options?.profileId;
|
|
262
|
+
t ? !e || typeof e != "object" || Array.isArray(e) ? console.error("[Swetrix] setTraits() expects an object of traits") : await this.identify(t, e) : console.error("[Swetrix] setTraits() requires the visitor to be identified via identify() first");
|
|
263
|
+
}
|
|
264
|
+
reset() {
|
|
265
|
+
this.options && delete this.options.profileId, this.identifiedProfileId = null, this.lastIdentifySent = null, this.clearFeatureFlagsCache();
|
|
266
|
+
}
|
|
267
|
+
async getExperiments(e, t) {
|
|
268
|
+
if (!u()) return {};
|
|
269
|
+
let n = e?.profileId ?? this.options?.profileId;
|
|
270
|
+
if (!t && this.cachedData) {
|
|
271
|
+
let e = Date.now();
|
|
272
|
+
if (this.cachedData.profileId === n && e - this.cachedData.timestamp < K) return this.cachedData.experiments;
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
return await this.fetchFlagsAndExperiments(e), this.cachedData?.experiments || {};
|
|
276
|
+
} catch (e) {
|
|
277
|
+
return console.warn("[Swetrix] Error fetching experiments:", e), this.cachedData?.experiments || {};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
async getExperiment(e, t, n = null) {
|
|
281
|
+
return (await this.getExperiments(t))[e] ?? n;
|
|
282
|
+
}
|
|
283
|
+
clearExperimentsCache() {
|
|
284
|
+
this.cachedData = null;
|
|
285
|
+
}
|
|
286
|
+
async getProfileId() {
|
|
287
|
+
if (this.identifiedProfileId) return this.identifiedProfileId;
|
|
288
|
+
if (this.options?.profileId) return j(this.options.profileId);
|
|
289
|
+
if (!u()) return null;
|
|
290
|
+
try {
|
|
291
|
+
let e = this.getApiBase(), t = await fetch(`${e}/log/profile-id`, {
|
|
292
|
+
method: "POST",
|
|
293
|
+
headers: { "Content-Type": "application/json" },
|
|
294
|
+
body: JSON.stringify({ pid: this.projectID })
|
|
295
|
+
});
|
|
296
|
+
return t.ok ? (await t.json()).profileId : null;
|
|
297
|
+
} catch {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
async getSessionId() {
|
|
302
|
+
if (!u()) return null;
|
|
303
|
+
try {
|
|
304
|
+
let e = this.getApiBase(), t = await fetch(`${e}/log/session-id`, {
|
|
305
|
+
method: "POST",
|
|
306
|
+
headers: { "Content-Type": "application/json" },
|
|
307
|
+
body: JSON.stringify({ pid: this.projectID })
|
|
308
|
+
});
|
|
309
|
+
return t.ok ? (await t.json()).sessionId : null;
|
|
310
|
+
} catch {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async startSessionReplay(e = {}) {
|
|
315
|
+
if (this.sessionReplayActions) return this.sessionReplayActions;
|
|
316
|
+
if (this.sessionReplayInitPromise) return this.sessionReplayInitPromise;
|
|
317
|
+
let t = this.initialiseSessionReplay(e);
|
|
318
|
+
this.sessionReplayInitPromise = t;
|
|
319
|
+
try {
|
|
320
|
+
return await t;
|
|
321
|
+
} finally {
|
|
322
|
+
this.sessionReplayInitPromise === t && (this.sessionReplayInitPromise = null);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
async initialiseSessionReplay(e) {
|
|
326
|
+
if (this.sessionReplayActions) return this.sessionReplayActions;
|
|
327
|
+
if (!this.canTrack()) return D;
|
|
328
|
+
let t = typeof e.maxDurationMs == "number" && e.maxDurationMs > 0 ? e.maxDurationMs : R;
|
|
329
|
+
if (!this.shouldSampleSessionReplay(e.sampleRate)) return D;
|
|
330
|
+
try {
|
|
331
|
+
await this.preloadSessionReplay();
|
|
332
|
+
} catch {
|
|
333
|
+
return D;
|
|
334
|
+
}
|
|
335
|
+
let n = this.getRrwebRecorder();
|
|
336
|
+
if (!n) return D;
|
|
337
|
+
let r = this.getSessionReplayPrivacy(e.privacy), i = this.createReplayId(), a = await this.sendSessionReplayStart(i, r);
|
|
338
|
+
if (!a) return D;
|
|
339
|
+
let o = a.replayId, s = typeof e.flushIntervalMs == "number" && e.flushIntervalMs > 0 ? e.flushIntervalMs : P, c = typeof e.maxEventsPerChunk == "number" && e.maxEventsPerChunk > 0 ? Math.floor(e.maxEventsPerChunk) : F, l = typeof e.maxBytesPerChunk == "number" ? Math.floor(e.maxBytesPerChunk) : NaN, u = l >= 1 ? l : I, d = typeof e.maxBytesPerEvent == "number" ? Math.floor(e.maxBytesPerEvent) : NaN, f = d >= 1 ? d : L, p = typeof e.idleTimeoutMs == "number" && e.idleTimeoutMs > 0 ? e.idleTimeoutMs : null, m = a.nextChunkIndex, h = 0, g = !1, _ = [], v = 0, y = Promise.resolve(), b, x, S = async (e = !1) => {
|
|
340
|
+
if (!_.length) return;
|
|
341
|
+
let t = _;
|
|
342
|
+
_ = [], v = 0;
|
|
343
|
+
let i = m++;
|
|
344
|
+
y = y.catch(() => void 0).then(async () => {
|
|
345
|
+
if (!await this.sendSessionReplayChunk(o, r, i, t, e) && !g && h < W && t.some((e) => e.type === H)) {
|
|
346
|
+
h += 1;
|
|
347
|
+
try {
|
|
348
|
+
n.takeFullSnapshot?.();
|
|
349
|
+
} catch {}
|
|
350
|
+
}
|
|
351
|
+
}), await y;
|
|
352
|
+
}, C = e.rrweb?.emit, w = n(this.getSessionReplayRecordOptions(r, e.rrweb, (e) => {
|
|
353
|
+
try {
|
|
354
|
+
C?.(e);
|
|
355
|
+
} catch {}
|
|
356
|
+
let t = 0;
|
|
357
|
+
try {
|
|
358
|
+
t = q(JSON.stringify(e));
|
|
359
|
+
} catch {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
t > f || (_.length && v + t > u && S(), _.push(e), v += t, (_.length >= c || v >= u) && S());
|
|
363
|
+
}, !!e.recordIframes, e.maskAllText)), T = setInterval(() => void S(), s), E = () => void S(!0), O = () => {
|
|
364
|
+
document.visibilityState === "hidden" && S(!0);
|
|
365
|
+
}, k = () => {
|
|
366
|
+
x &&= (clearTimeout(x), void 0);
|
|
367
|
+
}, A = async () => {
|
|
368
|
+
g || (g = !0, clearInterval(T), b && clearTimeout(b), k(), window.removeEventListener("pagehide", E), document.removeEventListener("visibilitychange", O), G.forEach((e) => {
|
|
369
|
+
window.removeEventListener(e, j);
|
|
370
|
+
}), w?.(), await S(), this.sessionReplayActions = null, this.sessionReplayInitPromise = null);
|
|
371
|
+
}, j = () => {
|
|
372
|
+
p && !g && (k(), x = setTimeout(() => void A(), p));
|
|
373
|
+
};
|
|
374
|
+
return window.addEventListener("pagehide", E), document.addEventListener("visibilitychange", O), b = setTimeout(() => void A(), t), p && (G.forEach((e) => {
|
|
375
|
+
window.addEventListener(e, j, { passive: !0 });
|
|
376
|
+
}), j()), this.sessionReplayActions = {
|
|
377
|
+
stop: A,
|
|
378
|
+
flush: async () => {
|
|
379
|
+
await S();
|
|
380
|
+
}
|
|
381
|
+
}, this.sessionReplayActions;
|
|
382
|
+
}
|
|
383
|
+
shouldSampleSessionReplay(e) {
|
|
384
|
+
return typeof e == "number" ? e <= 0 ? !1 : e >= 1 || Math.random() < e : !0;
|
|
385
|
+
}
|
|
386
|
+
getSessionReplayPrivacy(e) {
|
|
387
|
+
return T.includes(e) ? e : z;
|
|
388
|
+
}
|
|
389
|
+
getApiBase() {
|
|
390
|
+
return this.options?.apiURL ? this.options.apiURL.replace(/\/log\/?$/, "") : k;
|
|
391
|
+
}
|
|
392
|
+
heartbeat() {
|
|
393
|
+
if (!this.pageViewsOptions?.heartbeatOnBackground && document.visibilityState === "hidden") return;
|
|
394
|
+
let e = { pid: this.projectID };
|
|
395
|
+
this.options?.profileId && (e.profileId = this.options.profileId), this.sendRequest("hb", e);
|
|
396
|
+
}
|
|
397
|
+
trackPathChange() {
|
|
398
|
+
if (!this.pageData) return;
|
|
399
|
+
let e = w({
|
|
400
|
+
hash: this.pageViewsOptions?.hash,
|
|
401
|
+
search: this.pageViewsOptions?.search
|
|
402
|
+
}), { path: t } = this.pageData;
|
|
403
|
+
t !== e && this.trackPage(e, !1);
|
|
404
|
+
}
|
|
405
|
+
trackPage(e, t = !1) {
|
|
406
|
+
if (!this.pageData) return;
|
|
407
|
+
this.pageData.path = e;
|
|
408
|
+
let n = this.getPerformanceStats();
|
|
409
|
+
this.activePage = e, this.submitPageView({ pg: e }, t, n, !0);
|
|
410
|
+
}
|
|
411
|
+
submitPageView(e, t, n, r) {
|
|
412
|
+
let i = {
|
|
413
|
+
pid: this.projectID,
|
|
414
|
+
perf: n,
|
|
415
|
+
unique: t
|
|
416
|
+
}, a = {
|
|
417
|
+
title: u() ? document.title : void 0,
|
|
418
|
+
lc: p(),
|
|
419
|
+
tz: m(),
|
|
420
|
+
ref: h(),
|
|
421
|
+
so: _(),
|
|
422
|
+
me: v(),
|
|
423
|
+
ca: y(),
|
|
424
|
+
te: b(),
|
|
425
|
+
co: x(),
|
|
426
|
+
qs: g(),
|
|
427
|
+
profileId: this.options?.profileId,
|
|
428
|
+
...e
|
|
429
|
+
};
|
|
430
|
+
if (r && this.pageViewsOptions?.callback) {
|
|
431
|
+
let e = this.pageViewsOptions.callback(a);
|
|
432
|
+
if (e === !1) return;
|
|
433
|
+
e && typeof e == "object" && Object.assign(a, e);
|
|
434
|
+
}
|
|
435
|
+
r && (this.activePage = a.pg || null), typeof a.title == "string" && (a.title = a.title.slice(0, 2048)), Object.assign(a, i), this.sendRequest("", a);
|
|
436
|
+
}
|
|
437
|
+
canTrack() {
|
|
438
|
+
return !(this.options?.disabled || !u() || this.options?.respectDNT && window.navigator?.doNotTrack === "1" || !this.options?.devMode && d() || f());
|
|
439
|
+
}
|
|
440
|
+
getSessionReplayUrl() {
|
|
441
|
+
let e = this.getSessionReplayPreloadOption();
|
|
442
|
+
return e && typeof e == "object" && e.rrwebUrl ? e.rrwebUrl : this.getDefaultSessionReplayUrl();
|
|
443
|
+
}
|
|
444
|
+
getSessionReplayPreloadOption() {
|
|
445
|
+
return this.options?.preloadSessionReplay;
|
|
446
|
+
}
|
|
447
|
+
getDefaultSessionReplayUrl() {
|
|
448
|
+
if (!u()) return N;
|
|
449
|
+
let e = this.getTrackerScript();
|
|
450
|
+
if (e?.src) {
|
|
451
|
+
let { hostname: t, pathname: n } = new URL(e.src);
|
|
452
|
+
return t === "swetrix.org" && /^\/swetrix(\.min)?\.js$/i.test(n) ? N : new URL(M, e.src).toString();
|
|
453
|
+
}
|
|
454
|
+
return N;
|
|
455
|
+
}
|
|
456
|
+
getTrackerScript() {
|
|
457
|
+
return Array.from(document.scripts).find((e) => {
|
|
458
|
+
if (!e.src) return !1;
|
|
459
|
+
try {
|
|
460
|
+
let { pathname: t } = new URL(e.src);
|
|
461
|
+
return /(^|\/)swetrix(\.min)?\.js$/i.test(t);
|
|
462
|
+
} catch {
|
|
463
|
+
return !1;
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
getRrwebRecorder() {
|
|
468
|
+
if (!u()) return;
|
|
469
|
+
if (typeof window.rrweb?.record == "function") return window.rrweb.record;
|
|
470
|
+
let e = window.rrwebRecord;
|
|
471
|
+
if (typeof e == "function") return e;
|
|
472
|
+
if (e && typeof e.record == "function") return e.record;
|
|
473
|
+
}
|
|
474
|
+
preloadSessionReplay() {
|
|
475
|
+
if (!u() || this.getRrwebRecorder()) return Promise.resolve();
|
|
476
|
+
if (this.rrwebLoader) return this.rrwebLoader;
|
|
477
|
+
if (window.__SWETRIX_RRWEB_LOADING__) return this.rrwebLoader = window.__SWETRIX_RRWEB_LOADING__, this.rrwebLoader.catch(() => {
|
|
478
|
+
window.__SWETRIX_RRWEB_LOADING__ === this.rrwebLoader && delete window.__SWETRIX_RRWEB_LOADING__, this.rrwebLoader = null;
|
|
479
|
+
}), this.rrwebLoader;
|
|
480
|
+
this.rrwebLoader = this.loadSessionReplayRecorder(), window.__SWETRIX_RRWEB_LOADING__ = this.rrwebLoader;
|
|
481
|
+
let e = this.rrwebLoader;
|
|
482
|
+
return e.catch(() => {
|
|
483
|
+
window.__SWETRIX_RRWEB_LOADING__ === e && delete window.__SWETRIX_RRWEB_LOADING__, this.rrwebLoader === e && (this.rrwebLoader = null);
|
|
484
|
+
}), this.rrwebLoader;
|
|
485
|
+
}
|
|
486
|
+
async loadSessionReplayRecorder() {
|
|
487
|
+
let e = this.getSessionReplayPreloadOption();
|
|
488
|
+
e && typeof e == "object" && e.rrwebUrl || this.getTrackerScript() ? await this.loadSessionReplayScript(this.getSessionReplayUrl()) : await this.loadSessionReplayPackage() || await this.loadSessionReplayScript(this.getDefaultSessionReplayUrl());
|
|
489
|
+
}
|
|
490
|
+
async loadSessionReplayPackage() {
|
|
491
|
+
try {
|
|
492
|
+
let e = await import("./record-Cgv_fXDH.js"), t = e.record || e.default?.record;
|
|
493
|
+
return typeof t == "function" && (window.rrwebRecord = { record: t }, !0);
|
|
494
|
+
} catch {
|
|
495
|
+
return !1;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
loadSessionReplayScript(e) {
|
|
499
|
+
return new Promise((t, n) => {
|
|
500
|
+
let r = document.createElement("script");
|
|
501
|
+
r.async = !0, r.src = e, r.crossOrigin = "anonymous", r.onload = () => t(), r.onerror = () => n(/* @__PURE__ */ Error("Failed to load rrweb")), document.head.appendChild(r);
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
getSessionReplayRecordOptions(e, t, n, r, i) {
|
|
505
|
+
let a = t && Object.prototype.hasOwnProperty.call(t, "sampling"), o = t && Object.prototype.hasOwnProperty.call(t, "slimDOMOptions"), s = typeof t?.sampling == "object" && t.sampling !== null ? {
|
|
506
|
+
...B,
|
|
507
|
+
...t.sampling
|
|
508
|
+
} : a ? t?.sampling : B, c = typeof t?.slimDOMOptions == "object" && t.slimDOMOptions !== null ? {
|
|
509
|
+
...V,
|
|
510
|
+
...t.slimDOMOptions
|
|
511
|
+
} : o ? t?.slimDOMOptions : V, l = {
|
|
512
|
+
recordCanvas: !1,
|
|
513
|
+
recordCrossOriginIframes: !1,
|
|
514
|
+
collectFonts: !1,
|
|
515
|
+
inlineImages: !1,
|
|
516
|
+
...t,
|
|
517
|
+
sampling: s,
|
|
518
|
+
slimDOMOptions: c,
|
|
519
|
+
emit: n
|
|
520
|
+
}, u = typeof l.maskInputOptions == "object" && l.maskInputOptions !== null ? l.maskInputOptions : {}, d = this.getSessionReplayPrivacy(e), f = r ? void 0 : "iframe", p = (typeof i == "boolean" ? i : d === "total") ? { maskTextSelector: "*" } : {};
|
|
521
|
+
return d === "total" ? {
|
|
522
|
+
...l,
|
|
523
|
+
...p,
|
|
524
|
+
maskAllInputs: !0,
|
|
525
|
+
blockSelector: this.mergeSelectors(this.mergeSelectors(l.blockSelector, f), "img, picture, video, audio, canvas, svg"),
|
|
526
|
+
recordCanvas: !1,
|
|
527
|
+
inlineImages: !1,
|
|
528
|
+
emit: n
|
|
529
|
+
} : d === "normal" ? {
|
|
530
|
+
...l,
|
|
531
|
+
...p,
|
|
532
|
+
maskAllInputs: !0,
|
|
533
|
+
blockSelector: this.mergeSelectors(l.blockSelector, f),
|
|
534
|
+
emit: n
|
|
535
|
+
} : {
|
|
536
|
+
...l,
|
|
537
|
+
...p,
|
|
538
|
+
blockSelector: this.mergeSelectors(l.blockSelector, f),
|
|
539
|
+
maskInputOptions: {
|
|
540
|
+
...u,
|
|
541
|
+
password: !0
|
|
542
|
+
},
|
|
543
|
+
emit: n
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
mergeSelectors(e, t) {
|
|
547
|
+
return t ? typeof e == "string" && e.trim() ? `${e}, ${t}` : t : typeof e == "string" ? e : void 0;
|
|
548
|
+
}
|
|
549
|
+
createReplayId() {
|
|
550
|
+
return typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
551
|
+
}
|
|
552
|
+
async sendSessionReplayStart(e, t) {
|
|
553
|
+
try {
|
|
554
|
+
let n = this.getApiBase(), r = await fetch(`${n}/log/session-replay/start`, {
|
|
555
|
+
method: "POST",
|
|
556
|
+
headers: { "Content-Type": "application/json" },
|
|
557
|
+
body: JSON.stringify({
|
|
558
|
+
pid: this.projectID,
|
|
559
|
+
replayId: e,
|
|
560
|
+
privacy: t,
|
|
561
|
+
pg: this.activePage || w({
|
|
562
|
+
hash: this.pageViewsOptions?.hash,
|
|
563
|
+
search: this.pageViewsOptions?.search
|
|
564
|
+
}),
|
|
565
|
+
lc: p(),
|
|
566
|
+
tz: m(),
|
|
567
|
+
profileId: this.options?.profileId
|
|
568
|
+
})
|
|
569
|
+
});
|
|
570
|
+
if (!r.ok) return null;
|
|
571
|
+
try {
|
|
572
|
+
let t = await r.json();
|
|
573
|
+
return {
|
|
574
|
+
replayId: typeof t.replayId == "string" && t.replayId ? t.replayId : e,
|
|
575
|
+
nextChunkIndex: typeof t.nextChunkIndex == "number" && Number.isFinite(t.nextChunkIndex) && t.nextChunkIndex >= 0 ? Math.floor(t.nextChunkIndex) : 0
|
|
576
|
+
};
|
|
577
|
+
} catch {
|
|
578
|
+
return {
|
|
579
|
+
replayId: e,
|
|
580
|
+
nextChunkIndex: 0
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
} catch {
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
async sendSessionReplayChunk(e, t, n, r, i) {
|
|
588
|
+
let a = `${this.getApiBase()}/log/session-replay/chunk`, o = JSON.stringify({
|
|
589
|
+
pid: this.projectID,
|
|
590
|
+
replayId: e,
|
|
591
|
+
privacy: t,
|
|
592
|
+
chunkIndex: n,
|
|
593
|
+
events: r
|
|
594
|
+
});
|
|
595
|
+
if (i && typeof navigator.sendBeacon == "function" && navigator.sendBeacon(a, new Blob([o], { type: "application/json" }))) return !0;
|
|
596
|
+
let s = i ? 1 : U.length + 1;
|
|
597
|
+
for (let e = 0; e < s; e++) {
|
|
598
|
+
e > 0 && await new Promise((t) => setTimeout(t, U[e - 1]));
|
|
599
|
+
try {
|
|
600
|
+
let e = await fetch(a, {
|
|
601
|
+
method: "POST",
|
|
602
|
+
headers: { "Content-Type": "application/json" },
|
|
603
|
+
keepalive: i && o.length < 6e4,
|
|
604
|
+
body: o
|
|
605
|
+
});
|
|
606
|
+
if (e.ok) return !0;
|
|
607
|
+
if (e.status < 500 && e.status !== 408 && e.status !== 429) return !1;
|
|
608
|
+
} catch {}
|
|
609
|
+
}
|
|
610
|
+
return !1;
|
|
611
|
+
}
|
|
612
|
+
async sendRequest(e, t) {
|
|
613
|
+
let n = this.options?.apiURL || O, r = JSON.stringify(t);
|
|
614
|
+
await fetch(`${n}/${e}`, {
|
|
615
|
+
method: "POST",
|
|
616
|
+
headers: { "Content-Type": "application/json" },
|
|
617
|
+
keepalive: r.length < 6e4,
|
|
618
|
+
body: r
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
}, Y = null;
|
|
622
|
+
function X(e, t) {
|
|
623
|
+
return Y ||= new J(e, t), Y;
|
|
624
|
+
}
|
|
625
|
+
function Z(e) {
|
|
626
|
+
return new Promise((t) => {
|
|
627
|
+
Y ? typeof document > "u" || document.readyState === "complete" ? t(Y.trackPageViews(e)) : window.addEventListener("load", () => {
|
|
628
|
+
t(Y.trackPageViews(e));
|
|
629
|
+
}) : t(E);
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
function Q(e) {
|
|
633
|
+
return Y ? Y.trackErrors(e) : E;
|
|
634
|
+
}
|
|
635
|
+
// src/client/plugins/swetrix/components/Swetrix.vue
|
|
636
|
+
var $ = /* @__PURE__ */ e({
|
|
637
|
+
__name: "Swetrix",
|
|
638
|
+
props: { swetrix: {} },
|
|
639
|
+
setup(e) {
|
|
640
|
+
let n = e.swetrix, r = !1;
|
|
641
|
+
function i() {
|
|
642
|
+
typeof window < "u" && (r || (r = !0, X(n.id, n.options), Z(), Q()));
|
|
643
|
+
}
|
|
644
|
+
return n?.id && t(i), (e, t) => null;
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
export { $ as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ComputedRef } from 'vue';
|
|
2
|
+
import type { Locale } from 'vue-i18n';
|
|
3
|
+
/**
|
|
4
|
+
* Resolved language of the current page: `frontmatter.lang`, falling back to the site lang.
|
|
5
|
+
*/
|
|
6
|
+
export declare const usePageLang: () => ComputedRef<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Keeps `<html lang>` in sync with the resolved page lang.
|
|
9
|
+
* VitePress resets it to the site lang on mount, so re-apply it after mount and on navigation.
|
|
10
|
+
*/
|
|
11
|
+
export declare const useHtmlLang: () => void;
|
|
12
|
+
/**
|
|
13
|
+
* Picks the available locale matching `lang` exactly or by base language (`vi-VN` -> `vi`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const matchLocale: (lang: string, availableLocales: readonly Locale[]) => Locale | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Syncs the vue-i18n locale with the resolved page lang, synchronously so SSR renders the right strings.
|
|
18
|
+
* A manual `LocaleSwitcher` choice lasts until the page lang changes.
|
|
19
|
+
*/
|
|
20
|
+
export declare const usePageLocale: (i18n: {
|
|
21
|
+
global: {
|
|
22
|
+
locale: {
|
|
23
|
+
value: Locale;
|
|
24
|
+
};
|
|
25
|
+
availableLocales: Locale[];
|
|
26
|
+
};
|
|
27
|
+
}) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|