@hansenexus/hud 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +634 -12
- package/dist/a11y-B5DUaiCs.js +246 -0
- package/dist/a11y-panel-p_t4eD7p.js +207 -0
- package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
- package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
- package/dist/access-panel-CEfTr9ZI.js +123 -0
- package/dist/adapter-BYoxPYTI.d.ts +33 -0
- package/dist/adapter-hcwmJtNx.js +65 -0
- package/dist/auto/runtime.d.ts +65 -0
- package/dist/auto/runtime.js +50 -0
- package/dist/auto.d.ts +15 -0
- package/dist/auto.js +33 -0
- package/dist/capabilities-rDSKjXpq.js +110 -0
- package/dist/capture-CwrIwLqi.js +300 -0
- package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +275 -0
- package/dist/data-panel-DhxAmP91.js +817 -0
- package/dist/data-store-ChF1td_P.js +164 -0
- package/dist/define-hud-CHPedaQ5.d.ts +50 -0
- package/dist/design-D0kGgPoP.js +87 -0
- package/dist/detect-BxHZ0pxW.d.ts +25 -0
- package/dist/detect-CHZiSeZs.js +63 -0
- package/dist/dispatch-panel-B-xr_Giy.js +279 -0
- package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
- package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
- package/dist/file-xdSaQ2uR.js +103 -0
- package/dist/flags-DVtaJ8pQ.d.ts +58 -0
- package/dist/flags.d.ts +2 -0
- package/dist/flags.js +82 -0
- package/dist/force-state-panel-_otVYh9i.js +97 -0
- package/dist/generate-C8lQl3Eh.js +53 -0
- package/dist/handler-BpVhxEmU.js +106 -0
- package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
- package/dist/index-BAV_1W8a.d.ts +43 -0
- package/dist/index-BJ26pse9.d.ts +70 -0
- package/dist/index-BnQ0dTZf.d.ts +19 -0
- package/dist/index-CwfX-W87.d.ts +72 -0
- package/dist/index-DcH9V3cU.d.ts +48 -0
- package/dist/index-DqOyNf1u.d.ts +65 -0
- package/dist/index-DstI_ike.d.ts +66 -0
- package/dist/index-Dxz4fn4j.d.ts +42 -0
- package/dist/index-Hhh7OXzU.d.ts +129 -0
- package/dist/index-ReFbhQ9p.d.ts +25 -0
- package/dist/index-RgXfMBuW.d.ts +48 -0
- package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +710 -69
- package/dist/inspect-C9Ft8fqn.js +142 -0
- package/dist/inspect-root-BkaupBMp.js +429 -0
- package/dist/meta-Bv0sEao3.js +6 -0
- package/dist/meta-C_G7MB5w.d.ts +49 -0
- package/dist/mocks-CA-wM2SB.d.ts +109 -0
- package/dist/mocks-ESiRqk9o.js +150 -0
- package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
- package/dist/next/config.cjs +201 -0
- package/dist/next/config.d.cts +87 -0
- package/dist/next/config.d.ts +64 -0
- package/dist/next/config.js +84 -0
- package/dist/next.d.ts +14 -4
- package/dist/next.js +5 -3
- package/dist/observe-CdDnDBRP.js +89 -0
- package/dist/observe-panel-Cgp1M8oT.js +347 -0
- package/dist/ops-panel-CEqDe_UT.js +234 -0
- package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
- package/dist/plugins/a11y.d.ts +2 -0
- package/dist/plugins/a11y.js +2 -0
- package/dist/plugins/access/server.d.ts +5 -5
- package/dist/plugins/access/server.js +4 -3
- package/dist/plugins/access.d.ts +5 -5
- package/dist/plugins/access.js +16 -215
- package/dist/plugins/agent/server.d.ts +3 -38
- package/dist/plugins/agent/server.js +47 -21
- package/dist/plugins/agent.d.ts +4 -4
- package/dist/plugins/agent.js +6 -348
- package/dist/plugins/capture/server.d.ts +92 -0
- package/dist/plugins/capture/server.js +248 -0
- package/dist/plugins/capture.d.ts +24 -0
- package/dist/plugins/capture.js +70 -0
- package/dist/plugins/data/msw-browser.d.ts +2 -0
- package/dist/plugins/data/msw-browser.js +39 -0
- package/dist/plugins/data/msw-node.d.ts +36 -0
- package/dist/plugins/data/msw-node.js +68 -0
- package/dist/plugins/data/server.d.ts +257 -0
- package/dist/plugins/data/server.js +717 -0
- package/dist/plugins/data.d.ts +6 -0
- package/dist/plugins/data.js +51 -0
- package/dist/plugins/design/server.d.ts +54 -0
- package/dist/plugins/design/server.js +198 -0
- package/dist/plugins/design.d.ts +4 -124
- package/dist/plugins/design.js +4 -619
- package/dist/plugins/inspect/convex.d.ts +2 -0
- package/dist/plugins/inspect/convex.js +486 -0
- package/dist/plugins/inspect/react-query.d.ts +2 -0
- package/dist/plugins/inspect/react-query.js +237 -0
- package/dist/plugins/inspect/sockets.d.ts +51 -0
- package/dist/plugins/inspect/sockets.js +397 -0
- package/dist/plugins/inspect/swr.d.ts +2 -0
- package/dist/plugins/inspect/swr.js +218 -0
- package/dist/plugins/inspect.d.ts +4 -0
- package/dist/plugins/inspect.js +3 -0
- package/dist/plugins/observe.d.ts +4 -64
- package/dist/plugins/observe.js +1 -616
- package/dist/plugins/ops/server.d.ts +1 -1
- package/dist/plugins/ops/server.js +2 -1
- package/dist/plugins/ops.d.ts +2 -1
- package/dist/plugins/ops.js +15 -336
- package/dist/plugins/routes/server.d.ts +88 -0
- package/dist/plugins/routes/server.js +62 -0
- package/dist/plugins/routes.d.ts +3 -0
- package/dist/plugins/routes.js +216 -0
- package/dist/plugins/seo.d.ts +2 -0
- package/dist/plugins/seo.js +2 -0
- package/dist/plugins/vitals.d.ts +2 -25
- package/dist/plugins/vitals.js +3 -2
- package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
- package/dist/poll-CjKsWZi8.js +89 -0
- package/dist/requests-BwD6MKEq.js +282 -0
- package/dist/requests-CJrUf465.d.ts +50 -0
- package/dist/review.js +2 -2
- package/dist/same-origin-BGet22CC.js +21 -0
- package/dist/scan-DzJNXqOk.js +165 -0
- package/dist/seo-Dq9q_QkO.js +551 -0
- package/dist/seo-panel-CfiY-TnT.js +124 -0
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -105
- package/dist/sessions-panel-COvhPAzv.js +98 -0
- package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
- package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
- package/dist/store/convex.d.ts +33 -0
- package/dist/store/convex.js +52 -0
- package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
- package/dist/store-Ync9eb1G.js +67 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +188 -0
- package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
- package/dist/styles-DKU_P8MH.js +139 -0
- package/dist/styles-DPpDPmzi.js +68 -0
- package/dist/tokens-panel-CbMQfasZ.js +142 -0
- package/dist/types-B-ulf2Jp.js +8 -0
- package/dist/types-BIgGf-0C.d.ts +25 -0
- package/dist/types-BIkI-qN8.js +30 -0
- package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
- package/dist/types-DIdPfjtV.js +6 -0
- package/dist/types-DaJcsEjO.d.ts +44 -0
- package/dist/types-Dn68psVz.d.ts +118 -0
- package/dist/types-szkr2QOF.d.ts +39 -0
- package/dist/unlock-store-4V3vR4Eg.js +96 -0
- package/dist/variant-groups-TIfO3NIj.js +137 -0
- package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
- package/dist/variants-panel-BDoSkwBJ.js +457 -0
- package/dist/variants-types-CcRf119M.d.ts +63 -0
- package/dist/variants.d.ts +43 -0
- package/dist/variants.js +83 -0
- package/dist/vitals-panel-BCmMUntW.js +30 -0
- package/dist/vite.d.ts +37 -0
- package/dist/vite.js +134 -0
- package/package.json +72 -5
- package/dist/define-hud-BBzsSl8b.d.ts +0 -36
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
import { i as definePlugin } from "./plugins-DVy_vaYr.js";
|
|
2
|
+
import { lazy, useEffect, useSyncExternalStore } from "react";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region src/plugins/seo/pill.ts
|
|
5
|
+
/** Pill text: the error count once checked. */
|
|
6
|
+
function pillText({ errors, checkedAt }) {
|
|
7
|
+
return checkedAt === null ? "SEO" : `SEO ${errors}`;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/plugins/seo/checks.ts
|
|
11
|
+
const SEO_GROUPS = [
|
|
12
|
+
{
|
|
13
|
+
id: "title",
|
|
14
|
+
label: "Title"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "description",
|
|
18
|
+
label: "Description"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "canonical",
|
|
22
|
+
label: "Canonical"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "og",
|
|
26
|
+
label: "Open Graph"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "json-ld",
|
|
30
|
+
label: "JSON-LD"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "hreflang",
|
|
34
|
+
label: "hreflang"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "robots",
|
|
38
|
+
label: "Robots"
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
const TITLE_MIN = 10;
|
|
42
|
+
const TITLE_MAX = 60;
|
|
43
|
+
const DESCRIPTION_MIN = 50;
|
|
44
|
+
const DESCRIPTION_MAX = 160;
|
|
45
|
+
const OG_REQUIRED = [
|
|
46
|
+
"og:title",
|
|
47
|
+
"og:description",
|
|
48
|
+
"og:image"
|
|
49
|
+
];
|
|
50
|
+
const OG_RECOMMENDED = ["og:url", "og:type"];
|
|
51
|
+
/** `de`, `de-DE`, `zh-Hant`, `sr-Latn-RS`, or `x-default`. */
|
|
52
|
+
const HREFLANG = /^(x-default|[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|\d{3}))?)$/i;
|
|
53
|
+
function text(element) {
|
|
54
|
+
return (element?.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
55
|
+
}
|
|
56
|
+
function content(element) {
|
|
57
|
+
return (element?.getAttribute("content") ?? "").trim();
|
|
58
|
+
}
|
|
59
|
+
function excerpt(value, max = 90) {
|
|
60
|
+
return value.length > max ? `${value.slice(0, max - 1)}…` : value;
|
|
61
|
+
}
|
|
62
|
+
function parseUrl(value, base) {
|
|
63
|
+
try {
|
|
64
|
+
return new URL(value, base);
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function isAbsolute(value) {
|
|
70
|
+
return /^https?:\/\//i.test(value);
|
|
71
|
+
}
|
|
72
|
+
/** Same page: origin and path, ignoring the hash and a trailing slash. */
|
|
73
|
+
function samePage(a, b) {
|
|
74
|
+
const norm = (url) => `${url.origin}${url.pathname.replace(/\/+$/, "") || "/"}${url.search}`;
|
|
75
|
+
return norm(a) === norm(b);
|
|
76
|
+
}
|
|
77
|
+
function checkTitle(doc) {
|
|
78
|
+
const titles = doc.querySelectorAll("head > title, title");
|
|
79
|
+
const value = text(titles[0] ?? null);
|
|
80
|
+
const base = {
|
|
81
|
+
id: "title",
|
|
82
|
+
group: "title",
|
|
83
|
+
label: "Title"
|
|
84
|
+
};
|
|
85
|
+
if (titles.length === 0) return [{
|
|
86
|
+
...base,
|
|
87
|
+
level: "error",
|
|
88
|
+
detail: "No <title>"
|
|
89
|
+
}];
|
|
90
|
+
if (!value) return [{
|
|
91
|
+
...base,
|
|
92
|
+
level: "error",
|
|
93
|
+
detail: "<title> is empty"
|
|
94
|
+
}];
|
|
95
|
+
const checks = [];
|
|
96
|
+
if (value.length < TITLE_MIN) checks.push({
|
|
97
|
+
...base,
|
|
98
|
+
level: "warn",
|
|
99
|
+
detail: `“${value}” is short (${value.length} chars)`
|
|
100
|
+
});
|
|
101
|
+
else if (value.length > TITLE_MAX) checks.push({
|
|
102
|
+
...base,
|
|
103
|
+
level: "warn",
|
|
104
|
+
detail: `${value.length} chars; results cut around ${TITLE_MAX}: “${excerpt(value)}”`
|
|
105
|
+
});
|
|
106
|
+
else checks.push({
|
|
107
|
+
...base,
|
|
108
|
+
level: "ok",
|
|
109
|
+
detail: `“${value}” (${value.length} chars)`
|
|
110
|
+
});
|
|
111
|
+
if (titles.length > 1) checks.push({
|
|
112
|
+
id: "title:count",
|
|
113
|
+
group: "title",
|
|
114
|
+
label: "Title count",
|
|
115
|
+
level: "warn",
|
|
116
|
+
detail: `${titles.length} <title> elements`
|
|
117
|
+
});
|
|
118
|
+
return checks;
|
|
119
|
+
}
|
|
120
|
+
function checkDescription(doc) {
|
|
121
|
+
const metas = doc.querySelectorAll("meta[name=\"description\" i]");
|
|
122
|
+
const value = content(metas[0] ?? null);
|
|
123
|
+
const base = {
|
|
124
|
+
id: "description",
|
|
125
|
+
group: "description",
|
|
126
|
+
label: "Description"
|
|
127
|
+
};
|
|
128
|
+
if (metas.length === 0) return [{
|
|
129
|
+
...base,
|
|
130
|
+
level: "error",
|
|
131
|
+
detail: "No <meta name=\"description\">"
|
|
132
|
+
}];
|
|
133
|
+
if (!value) return [{
|
|
134
|
+
...base,
|
|
135
|
+
level: "error",
|
|
136
|
+
detail: "Description is empty"
|
|
137
|
+
}];
|
|
138
|
+
const checks = [];
|
|
139
|
+
if (value.length < DESCRIPTION_MIN) checks.push({
|
|
140
|
+
...base,
|
|
141
|
+
level: "warn",
|
|
142
|
+
detail: `“${value}” is short (${value.length} chars)`
|
|
143
|
+
});
|
|
144
|
+
else if (value.length > DESCRIPTION_MAX) checks.push({
|
|
145
|
+
...base,
|
|
146
|
+
level: "warn",
|
|
147
|
+
detail: `${value.length} chars; snippets cut around ${DESCRIPTION_MAX}: “${excerpt(value)}”`
|
|
148
|
+
});
|
|
149
|
+
else checks.push({
|
|
150
|
+
...base,
|
|
151
|
+
level: "ok",
|
|
152
|
+
detail: `“${excerpt(value)}” (${value.length} chars)`
|
|
153
|
+
});
|
|
154
|
+
if (metas.length > 1) checks.push({
|
|
155
|
+
id: "description:count",
|
|
156
|
+
group: "description",
|
|
157
|
+
label: "Description count",
|
|
158
|
+
level: "warn",
|
|
159
|
+
detail: `${metas.length} description metas`
|
|
160
|
+
});
|
|
161
|
+
return checks;
|
|
162
|
+
}
|
|
163
|
+
function checkCanonical(doc, page) {
|
|
164
|
+
const links = doc.querySelectorAll("link[rel=\"canonical\" i]");
|
|
165
|
+
const base = {
|
|
166
|
+
id: "canonical",
|
|
167
|
+
group: "canonical",
|
|
168
|
+
label: "Canonical"
|
|
169
|
+
};
|
|
170
|
+
if (links.length === 0) return [{
|
|
171
|
+
...base,
|
|
172
|
+
level: "warn",
|
|
173
|
+
detail: "No <link rel=\"canonical\">"
|
|
174
|
+
}];
|
|
175
|
+
const href = (links[0]?.getAttribute("href") ?? "").trim();
|
|
176
|
+
const checks = [];
|
|
177
|
+
const url = parseUrl(href, page);
|
|
178
|
+
if (!href || !url) checks.push({
|
|
179
|
+
...base,
|
|
180
|
+
level: "error",
|
|
181
|
+
detail: href ? `Invalid URL “${href}”` : "Empty href"
|
|
182
|
+
});
|
|
183
|
+
else if (!isAbsolute(href)) checks.push({
|
|
184
|
+
...base,
|
|
185
|
+
level: "error",
|
|
186
|
+
detail: `“${href}” is relative; canonical must be an absolute URL`
|
|
187
|
+
});
|
|
188
|
+
else if (!samePage(url, page)) checks.push({
|
|
189
|
+
...base,
|
|
190
|
+
level: "warn",
|
|
191
|
+
detail: `Points elsewhere: ${href}`
|
|
192
|
+
});
|
|
193
|
+
else checks.push({
|
|
194
|
+
...base,
|
|
195
|
+
level: "ok",
|
|
196
|
+
detail: href
|
|
197
|
+
});
|
|
198
|
+
if (links.length > 1) checks.push({
|
|
199
|
+
id: "canonical:count",
|
|
200
|
+
group: "canonical",
|
|
201
|
+
label: "Canonical count",
|
|
202
|
+
level: "error",
|
|
203
|
+
detail: `${links.length} canonical links; crawlers ignore conflicting ones`
|
|
204
|
+
});
|
|
205
|
+
return checks;
|
|
206
|
+
}
|
|
207
|
+
function og(doc, property) {
|
|
208
|
+
return content(doc.querySelector(`meta[property="${property}" i]`));
|
|
209
|
+
}
|
|
210
|
+
function checkOpenGraph(doc, page) {
|
|
211
|
+
const checks = [];
|
|
212
|
+
for (const property of OG_REQUIRED) {
|
|
213
|
+
const value = og(doc, property);
|
|
214
|
+
const base = {
|
|
215
|
+
id: property,
|
|
216
|
+
group: "og",
|
|
217
|
+
label: property
|
|
218
|
+
};
|
|
219
|
+
if (!value) checks.push({
|
|
220
|
+
...base,
|
|
221
|
+
level: "error",
|
|
222
|
+
detail: "missing"
|
|
223
|
+
});
|
|
224
|
+
else if (property === "og:image" && !isAbsolute(value)) checks.push({
|
|
225
|
+
...base,
|
|
226
|
+
level: "error",
|
|
227
|
+
detail: `“${excerpt(value)}” must be an absolute URL`
|
|
228
|
+
});
|
|
229
|
+
else checks.push({
|
|
230
|
+
...base,
|
|
231
|
+
level: "ok",
|
|
232
|
+
detail: excerpt(value)
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
for (const property of OG_RECOMMENDED) {
|
|
236
|
+
const value = og(doc, property);
|
|
237
|
+
const base = {
|
|
238
|
+
id: property,
|
|
239
|
+
group: "og",
|
|
240
|
+
label: property
|
|
241
|
+
};
|
|
242
|
+
if (!value) checks.push({
|
|
243
|
+
...base,
|
|
244
|
+
level: "warn",
|
|
245
|
+
detail: "missing"
|
|
246
|
+
});
|
|
247
|
+
else if (property === "og:url" && (!parseUrl(value, page) || !isAbsolute(value))) checks.push({
|
|
248
|
+
...base,
|
|
249
|
+
level: "error",
|
|
250
|
+
detail: `“${excerpt(value)}” must be an absolute URL`
|
|
251
|
+
});
|
|
252
|
+
else checks.push({
|
|
253
|
+
...base,
|
|
254
|
+
level: "ok",
|
|
255
|
+
detail: excerpt(value)
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return checks;
|
|
259
|
+
}
|
|
260
|
+
function describeJsonLd(data) {
|
|
261
|
+
if (data === null || typeof data !== "object") return {
|
|
262
|
+
type: "",
|
|
263
|
+
problem: "Top level is not an object"
|
|
264
|
+
};
|
|
265
|
+
const items = Array.isArray(data) ? data : [data];
|
|
266
|
+
const first = items[0];
|
|
267
|
+
const root = data;
|
|
268
|
+
if (!("@context" in root || first !== void 0 && "@context" in first)) return {
|
|
269
|
+
type: "",
|
|
270
|
+
problem: "No @context"
|
|
271
|
+
};
|
|
272
|
+
const types = ((Array.isArray(root["@graph"]) ? root["@graph"] : null) ?? items).map((item) => item !== null && typeof item === "object" ? item["@type"] : null).map((type) => Array.isArray(type) ? type.join("/") : type).filter((type) => typeof type === "string" && type.length > 0);
|
|
273
|
+
if (types.length === 0) return {
|
|
274
|
+
type: "",
|
|
275
|
+
problem: "No @type"
|
|
276
|
+
};
|
|
277
|
+
return {
|
|
278
|
+
type: types.join(", "),
|
|
279
|
+
problem: null
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function checkJsonLd(doc) {
|
|
283
|
+
const scripts = doc.querySelectorAll("script[type=\"application/ld+json\" i]");
|
|
284
|
+
if (scripts.length === 0) return [{
|
|
285
|
+
id: "json-ld",
|
|
286
|
+
group: "json-ld",
|
|
287
|
+
label: "JSON-LD",
|
|
288
|
+
level: "warn",
|
|
289
|
+
detail: "None found"
|
|
290
|
+
}];
|
|
291
|
+
return [...scripts].map((script, index) => {
|
|
292
|
+
const base = {
|
|
293
|
+
id: scripts.length === 1 ? "json-ld" : `json-ld#${index + 1}`,
|
|
294
|
+
group: "json-ld",
|
|
295
|
+
label: scripts.length === 1 ? "JSON-LD" : `JSON-LD #${index + 1}`
|
|
296
|
+
};
|
|
297
|
+
let data;
|
|
298
|
+
try {
|
|
299
|
+
data = JSON.parse(script.textContent ?? "");
|
|
300
|
+
} catch (error) {
|
|
301
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
302
|
+
return {
|
|
303
|
+
...base,
|
|
304
|
+
level: "error",
|
|
305
|
+
detail: `Invalid JSON: ${message}`
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
const { type, problem } = describeJsonLd(data);
|
|
309
|
+
if (problem) return {
|
|
310
|
+
...base,
|
|
311
|
+
level: "error",
|
|
312
|
+
detail: problem
|
|
313
|
+
};
|
|
314
|
+
return {
|
|
315
|
+
...base,
|
|
316
|
+
level: "ok",
|
|
317
|
+
detail: type
|
|
318
|
+
};
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function checkHreflang(doc, page) {
|
|
322
|
+
const links = [...doc.querySelectorAll("link[rel=\"alternate\" i][hreflang]")];
|
|
323
|
+
const base = {
|
|
324
|
+
id: "hreflang",
|
|
325
|
+
group: "hreflang",
|
|
326
|
+
label: "hreflang"
|
|
327
|
+
};
|
|
328
|
+
if (links.length === 0) return [{
|
|
329
|
+
...base,
|
|
330
|
+
level: "ok",
|
|
331
|
+
detail: "None (single language)"
|
|
332
|
+
}];
|
|
333
|
+
const checks = [];
|
|
334
|
+
const seen = /* @__PURE__ */ new Map();
|
|
335
|
+
let hasDefault = false;
|
|
336
|
+
let hasSelf = false;
|
|
337
|
+
for (const link of links) {
|
|
338
|
+
const lang = (link.getAttribute("hreflang") ?? "").trim();
|
|
339
|
+
const href = (link.getAttribute("href") ?? "").trim();
|
|
340
|
+
const id = `hreflang:${lang || "?"}`;
|
|
341
|
+
const url = parseUrl(href, page);
|
|
342
|
+
const entry = {
|
|
343
|
+
id,
|
|
344
|
+
group: "hreflang",
|
|
345
|
+
label: `hreflang ${lang || "(empty)"}`
|
|
346
|
+
};
|
|
347
|
+
seen.set(lang.toLowerCase(), (seen.get(lang.toLowerCase()) ?? 0) + 1);
|
|
348
|
+
if (lang.toLowerCase() === "x-default") hasDefault = true;
|
|
349
|
+
if (url && samePage(url, page)) hasSelf = true;
|
|
350
|
+
if (!HREFLANG.test(lang)) checks.push({
|
|
351
|
+
...entry,
|
|
352
|
+
level: "error",
|
|
353
|
+
detail: `“${lang}” is not a language tag`
|
|
354
|
+
});
|
|
355
|
+
else if (!href || !url) checks.push({
|
|
356
|
+
...entry,
|
|
357
|
+
level: "error",
|
|
358
|
+
detail: href ? `Invalid URL “${href}”` : "Empty href"
|
|
359
|
+
});
|
|
360
|
+
else if (!isAbsolute(href)) checks.push({
|
|
361
|
+
...entry,
|
|
362
|
+
level: "error",
|
|
363
|
+
detail: `“${href}” is relative; must be absolute`
|
|
364
|
+
});
|
|
365
|
+
else checks.push({
|
|
366
|
+
...entry,
|
|
367
|
+
level: "ok",
|
|
368
|
+
detail: href
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
for (const [lang, count] of seen) if (count > 1) checks.push({
|
|
372
|
+
id: `hreflang:${lang}:dup`,
|
|
373
|
+
group: "hreflang",
|
|
374
|
+
label: `hreflang ${lang}`,
|
|
375
|
+
level: "error",
|
|
376
|
+
detail: `Listed ${count} times`
|
|
377
|
+
});
|
|
378
|
+
if (!hasDefault) checks.push({
|
|
379
|
+
...base,
|
|
380
|
+
id: "hreflang:x-default",
|
|
381
|
+
level: "warn",
|
|
382
|
+
detail: "No x-default"
|
|
383
|
+
});
|
|
384
|
+
if (!hasSelf) checks.push({
|
|
385
|
+
...base,
|
|
386
|
+
id: "hreflang:self",
|
|
387
|
+
level: "warn",
|
|
388
|
+
detail: "No entry points at this page (self-reference)"
|
|
389
|
+
});
|
|
390
|
+
return checks;
|
|
391
|
+
}
|
|
392
|
+
function checkRobots(doc) {
|
|
393
|
+
const metas = [...doc.querySelectorAll("meta[name=\"robots\" i], meta[name=\"googlebot\" i]")];
|
|
394
|
+
const base = {
|
|
395
|
+
id: "robots",
|
|
396
|
+
group: "robots",
|
|
397
|
+
label: "Robots"
|
|
398
|
+
};
|
|
399
|
+
if (metas.length === 0) return [{
|
|
400
|
+
...base,
|
|
401
|
+
level: "ok",
|
|
402
|
+
detail: "index, follow (default)"
|
|
403
|
+
}];
|
|
404
|
+
return metas.map((meta, index) => {
|
|
405
|
+
const name = (meta.getAttribute("name") ?? "robots").toLowerCase();
|
|
406
|
+
const value = content(meta);
|
|
407
|
+
const blocking = value.split(",").map((d) => d.trim().toLowerCase()).filter((d) => d === "noindex" || d === "nofollow" || d === "none");
|
|
408
|
+
const id = metas.length === 1 ? "robots" : `robots#${index + 1}`;
|
|
409
|
+
const label = name === "robots" ? "Robots" : `Robots (${name})`;
|
|
410
|
+
if (!value) return {
|
|
411
|
+
...base,
|
|
412
|
+
id,
|
|
413
|
+
label,
|
|
414
|
+
level: "error",
|
|
415
|
+
detail: "Empty content"
|
|
416
|
+
};
|
|
417
|
+
if (blocking.length > 0) return {
|
|
418
|
+
...base,
|
|
419
|
+
id,
|
|
420
|
+
label,
|
|
421
|
+
level: "warn",
|
|
422
|
+
detail: `${value} — ${blocking.join(", ")} keeps the page out of results`
|
|
423
|
+
};
|
|
424
|
+
return {
|
|
425
|
+
...base,
|
|
426
|
+
id,
|
|
427
|
+
label,
|
|
428
|
+
level: "ok",
|
|
429
|
+
detail: value
|
|
430
|
+
};
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
/** Every SEO check for `doc`, with `page` as the page's own URL (for canonical and hreflang). */
|
|
434
|
+
function runSeoChecks(doc, page) {
|
|
435
|
+
return [
|
|
436
|
+
...checkTitle(doc),
|
|
437
|
+
...checkDescription(doc),
|
|
438
|
+
...checkCanonical(doc, page),
|
|
439
|
+
...checkOpenGraph(doc, page),
|
|
440
|
+
...checkJsonLd(doc),
|
|
441
|
+
...checkHreflang(doc, page),
|
|
442
|
+
...checkRobots(doc)
|
|
443
|
+
];
|
|
444
|
+
}
|
|
445
|
+
function countLevel(checks, level) {
|
|
446
|
+
return checks.filter((check) => check.level === level).length;
|
|
447
|
+
}
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/plugins/seo/store.ts
|
|
450
|
+
const EMPTY = {
|
|
451
|
+
checks: [],
|
|
452
|
+
errors: 0,
|
|
453
|
+
warnings: 0,
|
|
454
|
+
checkedAt: null,
|
|
455
|
+
url: ""
|
|
456
|
+
};
|
|
457
|
+
/** Head mutations from one render land as a burst; one check per burst. */
|
|
458
|
+
const DEBOUNCE_MS = 100;
|
|
459
|
+
let snapshot = EMPTY;
|
|
460
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
461
|
+
let stop = null;
|
|
462
|
+
let timer = null;
|
|
463
|
+
function emit() {
|
|
464
|
+
for (const listener of listeners) listener();
|
|
465
|
+
}
|
|
466
|
+
/** Runs the checks against the live document now. */
|
|
467
|
+
function checkSeo() {
|
|
468
|
+
if (typeof document === "undefined") return snapshot;
|
|
469
|
+
const checks = runSeoChecks(document, new URL(window.location.href));
|
|
470
|
+
snapshot = {
|
|
471
|
+
checks,
|
|
472
|
+
errors: countLevel(checks, "error"),
|
|
473
|
+
warnings: countLevel(checks, "warn"),
|
|
474
|
+
checkedAt: Date.now(),
|
|
475
|
+
url: window.location.href
|
|
476
|
+
};
|
|
477
|
+
emit();
|
|
478
|
+
return snapshot;
|
|
479
|
+
}
|
|
480
|
+
function schedule() {
|
|
481
|
+
if (timer !== null) clearTimeout(timer);
|
|
482
|
+
timer = setTimeout(() => {
|
|
483
|
+
timer = null;
|
|
484
|
+
checkSeo();
|
|
485
|
+
}, DEBOUNCE_MS);
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Checks once and keeps checking: `<head>` mutations (a client-side router
|
|
489
|
+
* swapping metadata, `document.title` writes) and history navigation re-run
|
|
490
|
+
* the checks after a short debounce. Idempotent; the pill calls it on mount.
|
|
491
|
+
*/
|
|
492
|
+
function startSeo() {
|
|
493
|
+
if (stop || typeof document === "undefined") return;
|
|
494
|
+
checkSeo();
|
|
495
|
+
const observer = new MutationObserver(schedule);
|
|
496
|
+
observer.observe(document.head, {
|
|
497
|
+
childList: true,
|
|
498
|
+
subtree: true,
|
|
499
|
+
attributes: true,
|
|
500
|
+
characterData: true
|
|
501
|
+
});
|
|
502
|
+
window.addEventListener("popstate", schedule);
|
|
503
|
+
window.addEventListener("hashchange", schedule);
|
|
504
|
+
stop = () => {
|
|
505
|
+
observer.disconnect();
|
|
506
|
+
window.removeEventListener("popstate", schedule);
|
|
507
|
+
window.removeEventListener("hashchange", schedule);
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function getSeo() {
|
|
511
|
+
return snapshot;
|
|
512
|
+
}
|
|
513
|
+
function subscribeSeo(listener) {
|
|
514
|
+
listeners.add(listener);
|
|
515
|
+
return () => listeners.delete(listener);
|
|
516
|
+
}
|
|
517
|
+
function useSeo() {
|
|
518
|
+
return useSyncExternalStore(subscribeSeo, getSeo, getSeo);
|
|
519
|
+
}
|
|
520
|
+
//#endregion
|
|
521
|
+
//#region src/plugins/seo/index.tsx
|
|
522
|
+
const SeoPanel = lazy(() => import("./seo-panel-CfiY-TnT.js"));
|
|
523
|
+
/**
|
|
524
|
+
* Checks the page's title, description, canonical, Open Graph, JSON-LD,
|
|
525
|
+
* hreflang and robots meta, from mount on and again whenever `<head>` changes.
|
|
526
|
+
* The pill shows the error count. Client only.
|
|
527
|
+
*/
|
|
528
|
+
function seo() {
|
|
529
|
+
function SeoPill() {
|
|
530
|
+
useEffect(() => startSeo(), []);
|
|
531
|
+
const snapshot = useSeo();
|
|
532
|
+
const rating = snapshot.checkedAt === null ? void 0 : snapshot.errors > 0 ? "poor" : "good";
|
|
533
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [rating && /* @__PURE__ */ jsx("span", {
|
|
534
|
+
className: "dot",
|
|
535
|
+
"data-rating": rating
|
|
536
|
+
}), pillText(snapshot)] });
|
|
537
|
+
}
|
|
538
|
+
return definePlugin({
|
|
539
|
+
id: "seo",
|
|
540
|
+
title: "SEO",
|
|
541
|
+
pill: SeoPill,
|
|
542
|
+
panel: SeoPanel,
|
|
543
|
+
commands: [{
|
|
544
|
+
id: "recheck",
|
|
545
|
+
title: "Re-check SEO meta",
|
|
546
|
+
run: () => void checkSeo()
|
|
547
|
+
}]
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
//#endregion
|
|
551
|
+
export { runSeoChecks as a, SEO_GROUPS as i, checkSeo as n, useSeo as r, seo as t };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { i as SEO_GROUPS, n as checkSeo, r as useSeo } from "./seo-Dq9q_QkO.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
//#region src/plugins/seo/styles.ts
|
|
4
|
+
/**
|
|
5
|
+
* The seo panel's styles. Rendered in the panel's own `<style>` inside the
|
|
6
|
+
* HUD's shadow root, so they ship only with this plugin and build on the
|
|
7
|
+
* shell's `--hud-*` tokens.
|
|
8
|
+
*/
|
|
9
|
+
const SEO_CSS = `
|
|
10
|
+
.seo { display: flex; flex-direction: column; gap: 8px; width: 396px; max-width: 100%; }
|
|
11
|
+
|
|
12
|
+
.seo-toolbar { display: flex; align-items: center; gap: 8px; }
|
|
13
|
+
.seo-summary { flex: 1; min-width: 0; color: var(--hud-fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
14
|
+
.seo-summary[data-level="error"] { color: var(--hud-poor); }
|
|
15
|
+
.seo-summary[data-level="warn"] { color: var(--hud-warn); }
|
|
16
|
+
.hud .seo-recheck {
|
|
17
|
+
padding: 2px 10px;
|
|
18
|
+
border: 1px solid var(--hud-border);
|
|
19
|
+
border-radius: 4px;
|
|
20
|
+
}
|
|
21
|
+
.hud .seo-recheck:hover { background: var(--hud-bg-subtle); }
|
|
22
|
+
|
|
23
|
+
.seo-list { max-height: 360px; overflow: auto; margin: 0; padding: 0; list-style: none; border: 1px solid var(--hud-border); border-radius: 4px; }
|
|
24
|
+
.seo-group {
|
|
25
|
+
position: sticky;
|
|
26
|
+
top: 0;
|
|
27
|
+
padding: 3px 8px;
|
|
28
|
+
background: var(--hud-bg-subtle);
|
|
29
|
+
font-size: 10px;
|
|
30
|
+
font-weight: 600;
|
|
31
|
+
letter-spacing: 0.06em;
|
|
32
|
+
text-transform: uppercase;
|
|
33
|
+
color: var(--hud-fg-muted);
|
|
34
|
+
}
|
|
35
|
+
.seo-row {
|
|
36
|
+
display: grid;
|
|
37
|
+
grid-template-columns: 10px 96px minmax(0, 1fr);
|
|
38
|
+
align-items: baseline;
|
|
39
|
+
gap: 6px;
|
|
40
|
+
padding: 3px 8px;
|
|
41
|
+
border-top: 1px solid var(--hud-border);
|
|
42
|
+
}
|
|
43
|
+
.seo-row .dot { position: relative; top: -1px; }
|
|
44
|
+
.seo-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--hud-fg-muted); font-family: var(--hud-mono); font-size: 11px; }
|
|
45
|
+
.seo-detail { min-width: 0; overflow-wrap: anywhere; }
|
|
46
|
+
.seo-row[data-level="error"] .seo-detail { color: var(--hud-poor); }
|
|
47
|
+
.seo-row[data-level="warn"] .seo-detail { color: var(--hud-warn); }
|
|
48
|
+
`;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/plugins/seo/seo-panel.tsx
|
|
51
|
+
const RATING = {
|
|
52
|
+
ok: "good",
|
|
53
|
+
warn: "needs-improvement",
|
|
54
|
+
error: "poor"
|
|
55
|
+
};
|
|
56
|
+
function summary({ errors, warnings, checks, checkedAt }) {
|
|
57
|
+
if (checkedAt === null) return "Checking…";
|
|
58
|
+
const parts = [
|
|
59
|
+
errors === 1 ? "1 error" : `${errors} errors`,
|
|
60
|
+
warnings === 1 ? "1 warning" : `${warnings} warnings`,
|
|
61
|
+
`${checks.length - errors - warnings} ok`
|
|
62
|
+
];
|
|
63
|
+
const at = new Date(checkedAt).toLocaleTimeString(void 0, { hour12: false });
|
|
64
|
+
return `${parts.join(", ")} · ${at}`;
|
|
65
|
+
}
|
|
66
|
+
/** Every check grouped, worst level first in the summary; head changes re-check automatically. */
|
|
67
|
+
function SeoPanel() {
|
|
68
|
+
const snapshot = useSeo();
|
|
69
|
+
const level = snapshot.errors > 0 ? "error" : snapshot.warnings > 0 ? "warn" : "ok";
|
|
70
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
71
|
+
className: "seo",
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ jsx("style", { children: SEO_CSS }),
|
|
74
|
+
/* @__PURE__ */ jsxs("div", {
|
|
75
|
+
className: "seo-toolbar",
|
|
76
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
77
|
+
className: "seo-summary",
|
|
78
|
+
role: "status",
|
|
79
|
+
"data-level": level,
|
|
80
|
+
title: snapshot.url,
|
|
81
|
+
children: summary(snapshot)
|
|
82
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
83
|
+
type: "button",
|
|
84
|
+
className: "seo-recheck",
|
|
85
|
+
onClick: () => checkSeo(),
|
|
86
|
+
children: "Re-check"
|
|
87
|
+
})]
|
|
88
|
+
}),
|
|
89
|
+
/* @__PURE__ */ jsx("ul", {
|
|
90
|
+
className: "seo-list",
|
|
91
|
+
"aria-label": "SEO checks",
|
|
92
|
+
children: SEO_GROUPS.map((group) => {
|
|
93
|
+
const rows = snapshot.checks.filter((check) => check.group === group.id);
|
|
94
|
+
if (rows.length === 0) return null;
|
|
95
|
+
return [/* @__PURE__ */ jsx("li", {
|
|
96
|
+
className: "seo-group",
|
|
97
|
+
children: group.label
|
|
98
|
+
}, `group:${group.id}`), ...rows.map((check) => /* @__PURE__ */ jsxs("li", {
|
|
99
|
+
className: "seo-row",
|
|
100
|
+
"data-level": check.level,
|
|
101
|
+
"data-check": check.id,
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ jsx("span", {
|
|
104
|
+
className: "dot",
|
|
105
|
+
"data-rating": RATING[check.level]
|
|
106
|
+
}),
|
|
107
|
+
/* @__PURE__ */ jsx("span", {
|
|
108
|
+
className: "seo-label",
|
|
109
|
+
title: check.label,
|
|
110
|
+
children: check.label
|
|
111
|
+
}),
|
|
112
|
+
/* @__PURE__ */ jsx("span", {
|
|
113
|
+
className: "seo-detail",
|
|
114
|
+
children: check.detail
|
|
115
|
+
})
|
|
116
|
+
]
|
|
117
|
+
}, check.id))];
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { SeoPanel, SeoPanel as default };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as HudHttpMethod, d as HudRoutes, l as HudRouteContext, o as HudPlugin, p as definePlugin, u as HudRouteHandler } from "./plugins-
|
|
2
|
-
import { a as createHudHandler, i as HudRequestHandler, n as HudHandler, o as developmentOnly, r as HudHandlerOptions, t as HudGuard } from "./handler-
|
|
1
|
+
import { a as HudHttpMethod, d as HudRoutes, l as HudRouteContext, o as HudPlugin, p as definePlugin, u as HudRouteHandler } from "./plugins-BZvDqGx5.js";
|
|
2
|
+
import { a as createHudHandler, i as HudRequestHandler, n as HudHandler, o as developmentOnly, r as HudHandlerOptions, t as HudGuard } from "./handler-DtYVCZY6.js";
|
|
3
3
|
export { type HudGuard, type HudHandler, type HudHandlerOptions, type HudHttpMethod, type HudPlugin, type HudRequestHandler, type HudRouteContext, type HudRouteHandler, type HudRoutes, createHudHandler, definePlugin, developmentOnly };
|