@hansenexus/hud 0.3.0 → 0.5.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/README.md +782 -6
- package/dist/a11y-B5DUaiCs.js +246 -0
- package/dist/a11y-panel-p_t4eD7p.js +207 -0
- package/dist/access-C7zlaqj6.js +100 -0
- package/dist/access-D_ewAEJG.d.ts +61 -0
- 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-CApnbI0r.d.ts +19 -0
- package/dist/env-CaiFPIhF.js +31 -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-BaqWsmrf.js +153 -0
- package/dist/force-state-CCqoTfVB.d.ts +23 -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-DtYVCZY6.d.ts +39 -0
- 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-gCZBO53s.d.ts +73 -0
- package/dist/index.d.ts +6 -36
- package/dist/index.js +798 -240
- package/dist/inspect-C9Ft8fqn.js +142 -0
- package/dist/inspect-root-BkaupBMp.js +429 -0
- package/dist/marker-C66LxOhJ.d.ts +9 -0
- package/dist/marker-CMrvxPmS.d.ts +12 -0
- package/dist/marker-DjeGvL-F.js +9 -0
- package/dist/marker-uZYPOJ4M.js +12 -0
- package/dist/markers.d.ts +3 -0
- package/dist/markers.js +3 -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.d.ts +52 -0
- package/dist/next/config.js +78 -0
- package/dist/next.d.ts +14 -19
- package/dist/next.js +7 -30
- 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-MUQ9ciER.d.ts +92 -0
- package/dist/plugins/a11y.d.ts +2 -0
- package/dist/plugins/a11y.js +2 -0
- package/dist/plugins/access/server.d.ts +122 -0
- package/dist/plugins/access/server.js +340 -0
- package/dist/plugins/access.d.ts +41 -0
- package/dist/plugins/access.js +51 -0
- package/dist/plugins/agent/server.d.ts +94 -0
- package/dist/plugins/agent/server.js +455 -0
- package/dist/plugins/agent.d.ts +37 -0
- package/dist/plugins/agent.js +69 -0
- 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 +5 -0
- package/dist/plugins/design.js +4 -0
- 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 +225 -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 -0
- package/dist/plugins/observe.js +2 -0
- package/dist/plugins/ops/server.d.ts +82 -0
- package/dist/plugins/ops/server.js +381 -0
- package/dist/plugins/ops.d.ts +27 -0
- package/dist/plugins/ops.js +41 -0
- 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 +4 -86
- package/dist/plugins-BZvDqGx5.d.ts +144 -0
- package/dist/{plugins-CzUiTn_r.js → plugins-DVy_vaYr.js} +3 -1
- 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.d.ts +181 -0
- package/dist/review.js +1017 -0
- package/dist/same-origin-BGet22CC.js +21 -0
- package/dist/scan-DzJNXqOk.js +165 -0
- package/dist/selector-NSYSe7AZ.js +28 -0
- package/dist/seo-Dq9q_QkO.js +551 -0
- package/dist/seo-panel-CfiY-TnT.js +124 -0
- package/dist/server.d.ts +3 -39
- package/dist/server.js +2 -105
- package/dist/sessions-panel-COvhPAzv.js +98 -0
- package/dist/shortcut-s_mjGeU8.js +179 -0
- package/dist/state-CjjZPjPJ.js +40 -0
- package/dist/state-boundary.d.ts +26 -0
- package/dist/state-boundary.js +61 -0
- package/dist/store/convex.d.ts +33 -0
- package/dist/store/convex.js +52 -0
- package/dist/store-CQqIIKTc.js +59 -0
- package/dist/store-Ync9eb1G.js +67 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +188 -0
- package/dist/styles-BA8ueHoV.js +342 -0
- 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-Cxh4twqc.d.ts +50 -0
- 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-f3jlNxzw.d.ts +92 -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 +85 -5
- package/dist/define-hud-BHQR8Lbv.d.ts +0 -31
- package/dist/plugins-1QmTmZyL.d.ts +0 -76
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { n as HUD_HOST_TAG } from "./marker-uZYPOJ4M.js";
|
|
2
|
+
import { i as definePlugin } from "./plugins-DVy_vaYr.js";
|
|
3
|
+
import { lazy, useSyncExternalStore } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/plugins/a11y/axe.ts
|
|
6
|
+
/** The axe-core release the default `axeUrl` fetches. */
|
|
7
|
+
const AXE_VERSION = "4.14.0";
|
|
8
|
+
const AXE_URL = `https://cdn.jsdelivr.net/npm/axe-core@${AXE_VERSION}/axe.min.js`;
|
|
9
|
+
const IMPACT_ORDER = [
|
|
10
|
+
"critical",
|
|
11
|
+
"serious",
|
|
12
|
+
"moderate",
|
|
13
|
+
"minor"
|
|
14
|
+
];
|
|
15
|
+
function isAxe(value) {
|
|
16
|
+
if (value === null || typeof value !== "object") return false;
|
|
17
|
+
return typeof value.run === "function";
|
|
18
|
+
}
|
|
19
|
+
/** Accepts a module namespace (`import("axe-core")`), its default export, or the axe object itself. */
|
|
20
|
+
function toAxe(loaded) {
|
|
21
|
+
if (isAxe(loaded)) return loaded;
|
|
22
|
+
const def = loaded?.default;
|
|
23
|
+
if (isAxe(def)) return def;
|
|
24
|
+
throw new Error("hud: the a11y loader did not resolve to axe-core (no `run` function)");
|
|
25
|
+
}
|
|
26
|
+
const SCRIPT_ATTR = "data-hud-axe";
|
|
27
|
+
/**
|
|
28
|
+
* Loads axe-core by appending a `<script>` to the host document and resolves
|
|
29
|
+
* the global it defines. A global that already exists (the app ships axe) is
|
|
30
|
+
* reused; a script already in flight is awaited, never duplicated.
|
|
31
|
+
*/
|
|
32
|
+
function loadAxeFromUrl(url, doc = document) {
|
|
33
|
+
const win = doc.defaultView;
|
|
34
|
+
if (win && isAxe(win.axe)) return Promise.resolve(win.axe);
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const settle = () => {
|
|
37
|
+
const axe = win?.axe;
|
|
38
|
+
if (isAxe(axe)) resolve(axe);
|
|
39
|
+
else reject(/* @__PURE__ */ new Error(`hud: ${url} loaded but defined no \`axe\` global`));
|
|
40
|
+
};
|
|
41
|
+
const existing = doc.head.querySelector(`script[${SCRIPT_ATTR}]`);
|
|
42
|
+
const script = existing ?? doc.createElement("script");
|
|
43
|
+
script.addEventListener("load", settle, { once: true });
|
|
44
|
+
script.addEventListener("error", () => reject(/* @__PURE__ */ new Error(`hud: could not load axe-core from ${url}`)), { once: true });
|
|
45
|
+
if (existing) return;
|
|
46
|
+
script.src = url;
|
|
47
|
+
script.async = true;
|
|
48
|
+
script.setAttribute(SCRIPT_ATTR, "");
|
|
49
|
+
doc.head.appendChild(script);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function impactRank(impact) {
|
|
53
|
+
const index = impact ? IMPACT_ORDER.indexOf(impact) : -1;
|
|
54
|
+
return index === -1 ? IMPACT_ORDER.length : index;
|
|
55
|
+
}
|
|
56
|
+
/** Flattens violations to findings, highest impact first; axe's order breaks ties. */
|
|
57
|
+
function toFindings(violations) {
|
|
58
|
+
return violations.flatMap((violation) => violation.nodes.map((node, index) => ({
|
|
59
|
+
key: `${violation.id}#${index}`,
|
|
60
|
+
rule: violation.id,
|
|
61
|
+
impact: violation.impact ?? null,
|
|
62
|
+
help: violation.help,
|
|
63
|
+
helpUrl: violation.helpUrl,
|
|
64
|
+
target: node.target,
|
|
65
|
+
html: node.html,
|
|
66
|
+
summary: node.failureSummary ?? violation.description
|
|
67
|
+
}))).sort((a, b) => impactRank(a.impact) - impactRank(b.impact));
|
|
68
|
+
}
|
|
69
|
+
function queryIn(root, selector) {
|
|
70
|
+
try {
|
|
71
|
+
return root.querySelector(selector);
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Resolves an axe target back to its element. A string hop selects in the
|
|
78
|
+
* current root; the root moves into an iframe's document or, for an array
|
|
79
|
+
* hop, through shadow roots.
|
|
80
|
+
*/
|
|
81
|
+
function resolveTarget(target, doc = document) {
|
|
82
|
+
let root = doc;
|
|
83
|
+
let element = null;
|
|
84
|
+
for (const hop of target) {
|
|
85
|
+
const selectors = typeof hop === "string" ? [hop] : hop;
|
|
86
|
+
for (const [index, selector] of selectors.entries()) {
|
|
87
|
+
if (index > 0) {
|
|
88
|
+
const shadow = element?.shadowRoot;
|
|
89
|
+
if (!shadow) return null;
|
|
90
|
+
root = shadow;
|
|
91
|
+
}
|
|
92
|
+
element = queryIn(root, selector);
|
|
93
|
+
if (!element) return null;
|
|
94
|
+
}
|
|
95
|
+
if (element instanceof HTMLIFrameElement) {
|
|
96
|
+
const inner = element.contentDocument;
|
|
97
|
+
if (!inner) return null;
|
|
98
|
+
root = inner;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return element;
|
|
102
|
+
}
|
|
103
|
+
/** Short selector for a finding row: the last hop of the target. */
|
|
104
|
+
function targetLabel(target) {
|
|
105
|
+
const last = target[target.length - 1];
|
|
106
|
+
if (last === void 0) return "";
|
|
107
|
+
return typeof last === "string" ? last : last[last.length - 1] ?? "";
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/plugins/a11y/store.ts
|
|
111
|
+
const NO_COUNTS = {
|
|
112
|
+
critical: 0,
|
|
113
|
+
serious: 0,
|
|
114
|
+
moderate: 0,
|
|
115
|
+
minor: 0
|
|
116
|
+
};
|
|
117
|
+
let snapshot = {
|
|
118
|
+
status: "idle",
|
|
119
|
+
findings: [],
|
|
120
|
+
counts: NO_COUNTS,
|
|
121
|
+
error: null,
|
|
122
|
+
ranAt: null
|
|
123
|
+
};
|
|
124
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
125
|
+
let axePromise = null;
|
|
126
|
+
let run = 0;
|
|
127
|
+
function set(next) {
|
|
128
|
+
snapshot = {
|
|
129
|
+
...snapshot,
|
|
130
|
+
...next
|
|
131
|
+
};
|
|
132
|
+
for (const listener of listeners) listener();
|
|
133
|
+
}
|
|
134
|
+
function count(findings) {
|
|
135
|
+
const counts = { ...NO_COUNTS };
|
|
136
|
+
for (const finding of findings) if (finding.impact) counts[finding.impact]++;
|
|
137
|
+
return counts;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Fetches axe-core on the first run, never earlier, and audits the document
|
|
141
|
+
* minus the HUD's own host. A run that is overtaken by a newer one discards
|
|
142
|
+
* its result.
|
|
143
|
+
*/
|
|
144
|
+
async function runAudit({ axeUrl = AXE_URL, load, runOptions } = {}) {
|
|
145
|
+
const id = ++run;
|
|
146
|
+
if (!axePromise) {
|
|
147
|
+
set({
|
|
148
|
+
status: "loading",
|
|
149
|
+
error: null
|
|
150
|
+
});
|
|
151
|
+
axePromise = load ? load().then(toAxe) : loadAxeFromUrl(axeUrl);
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
const axe = await axePromise;
|
|
155
|
+
if (id !== run) return;
|
|
156
|
+
set({
|
|
157
|
+
status: "running",
|
|
158
|
+
error: null
|
|
159
|
+
});
|
|
160
|
+
const results = await axe.run({ exclude: [[HUD_HOST_TAG]] }, { ...runOptions });
|
|
161
|
+
if (id !== run) return;
|
|
162
|
+
const findings = toFindings(results.violations);
|
|
163
|
+
set({
|
|
164
|
+
status: "done",
|
|
165
|
+
findings,
|
|
166
|
+
counts: count(findings),
|
|
167
|
+
ranAt: Date.now()
|
|
168
|
+
});
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (id !== run) return;
|
|
171
|
+
if (snapshot.status === "loading") axePromise = null;
|
|
172
|
+
set({
|
|
173
|
+
status: "error",
|
|
174
|
+
error: error instanceof Error ? error.message : String(error)
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function getA11y() {
|
|
179
|
+
return snapshot;
|
|
180
|
+
}
|
|
181
|
+
function subscribeA11y(listener) {
|
|
182
|
+
listeners.add(listener);
|
|
183
|
+
return () => listeners.delete(listener);
|
|
184
|
+
}
|
|
185
|
+
function useA11y() {
|
|
186
|
+
return useSyncExternalStore(subscribeA11y, getA11y, getA11y);
|
|
187
|
+
}
|
|
188
|
+
/** Pill rating from the worst impact present. */
|
|
189
|
+
function worstImpact(counts) {
|
|
190
|
+
return IMPACT_ORDER.find((impact) => counts[impact] > 0) ?? null;
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/plugins/a11y/pill.ts
|
|
194
|
+
/** Short text for the pill: the finding count once a run finished, an ellipsis meanwhile. */
|
|
195
|
+
function pillText({ status, findings }) {
|
|
196
|
+
if (status === "loading" || status === "running") return "A11y …";
|
|
197
|
+
if (status !== "done") return "A11y";
|
|
198
|
+
return `A11y ${findings.length}`;
|
|
199
|
+
}
|
|
200
|
+
function pillRating(snapshot) {
|
|
201
|
+
if (snapshot.status !== "done") return void 0;
|
|
202
|
+
const worst = worstImpact(snapshot.counts);
|
|
203
|
+
if (!worst) return "good";
|
|
204
|
+
return worst === "critical" || worst === "serious" ? "poor" : "needs-improvement";
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/plugins/a11y/index.tsx
|
|
208
|
+
const A11yPanel = lazy(() => import("./a11y-panel-p_t4eD7p.js"));
|
|
209
|
+
/**
|
|
210
|
+
* On-demand axe-core audit. Nothing is fetched until Run: axe-core comes from
|
|
211
|
+
* `axeUrl` (jsDelivr, pinned) or your own `load` (`() => import("axe-core")`).
|
|
212
|
+
* Findings list by impact; clicking one outlines the element with the grabber
|
|
213
|
+
* overlay. Client only.
|
|
214
|
+
*/
|
|
215
|
+
function a11y(options = {}) {
|
|
216
|
+
function A11yPill() {
|
|
217
|
+
const snapshot = useA11y();
|
|
218
|
+
const rating = pillRating(snapshot);
|
|
219
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [rating && /* @__PURE__ */ jsx("span", {
|
|
220
|
+
className: "dot",
|
|
221
|
+
"data-rating": rating
|
|
222
|
+
}), pillText(snapshot)] });
|
|
223
|
+
}
|
|
224
|
+
function Panel({ ctx }) {
|
|
225
|
+
return /* @__PURE__ */ jsx(A11yPanel, {
|
|
226
|
+
ctx,
|
|
227
|
+
options
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return definePlugin({
|
|
231
|
+
id: "a11y",
|
|
232
|
+
title: "A11y",
|
|
233
|
+
pill: A11yPill,
|
|
234
|
+
panel: Panel,
|
|
235
|
+
commands: [{
|
|
236
|
+
id: "run",
|
|
237
|
+
title: "Run accessibility audit",
|
|
238
|
+
run: (ctx) => {
|
|
239
|
+
ctx.open();
|
|
240
|
+
runAudit(options);
|
|
241
|
+
}
|
|
242
|
+
}]
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
export { AXE_VERSION as a, targetLabel as c, AXE_URL as i, runAudit as n, IMPACT_ORDER as o, useA11y as r, resolveTarget as s, a11y as t };
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { n as useGrab } from "./store-Ync9eb1G.js";
|
|
2
|
+
import { c as targetLabel, n as runAudit, o as IMPACT_ORDER, r as useA11y, s as resolveTarget } from "./a11y-B5DUaiCs.js";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/plugins/a11y/styles.ts
|
|
6
|
+
/**
|
|
7
|
+
* The a11y panel's styles. Rendered in the panel's own `<style>` inside the
|
|
8
|
+
* HUD's shadow root, so they ship only with this plugin and build on the
|
|
9
|
+
* shell's `--hud-*` tokens.
|
|
10
|
+
*/
|
|
11
|
+
const A11Y_CSS = `
|
|
12
|
+
.a11y { display: flex; flex-direction: column; gap: 8px; width: 396px; max-width: 100%; }
|
|
13
|
+
|
|
14
|
+
.a11y-toolbar { display: flex; align-items: center; gap: 8px; }
|
|
15
|
+
.hud .a11y-run {
|
|
16
|
+
padding: 2px 10px;
|
|
17
|
+
border: 1px solid var(--hud-border);
|
|
18
|
+
border-radius: 4px;
|
|
19
|
+
font-weight: 600;
|
|
20
|
+
}
|
|
21
|
+
.hud .a11y-run:hover:not(:disabled) { background: var(--hud-bg-subtle); }
|
|
22
|
+
.hud .a11y-run:disabled { opacity: 0.5; cursor: default; }
|
|
23
|
+
.a11y-summary { flex: 1; min-width: 0; color: var(--hud-fg-muted); }
|
|
24
|
+
.a11y-summary[data-level="error"] { color: var(--hud-poor); }
|
|
25
|
+
|
|
26
|
+
.a11y-list { max-height: 360px; overflow: auto; margin: 0; padding: 0; list-style: none; border: 1px solid var(--hud-border); border-radius: 4px; }
|
|
27
|
+
.a11y-impact {
|
|
28
|
+
position: sticky;
|
|
29
|
+
top: 0;
|
|
30
|
+
padding: 3px 8px;
|
|
31
|
+
background: var(--hud-bg-subtle);
|
|
32
|
+
font-size: 10px;
|
|
33
|
+
font-weight: 600;
|
|
34
|
+
letter-spacing: 0.06em;
|
|
35
|
+
text-transform: uppercase;
|
|
36
|
+
color: var(--hud-fg-muted);
|
|
37
|
+
}
|
|
38
|
+
.a11y-impact[data-impact="critical"], .a11y-impact[data-impact="serious"] { color: var(--hud-poor); }
|
|
39
|
+
.a11y-impact[data-impact="moderate"], .a11y-impact[data-impact="minor"] { color: var(--hud-warn); }
|
|
40
|
+
.a11y-row { display: flex; align-items: stretch; border-top: 1px solid var(--hud-border); }
|
|
41
|
+
.hud .a11y-finding {
|
|
42
|
+
flex: 1;
|
|
43
|
+
min-width: 0;
|
|
44
|
+
display: flex;
|
|
45
|
+
flex-direction: column;
|
|
46
|
+
gap: 1px;
|
|
47
|
+
padding: 4px 8px;
|
|
48
|
+
text-align: left;
|
|
49
|
+
}
|
|
50
|
+
.hud .a11y-finding:hover { background: var(--hud-bg-subtle); }
|
|
51
|
+
.hud .a11y-finding[aria-pressed="true"] { background: var(--hud-bg-subtle); box-shadow: inset 2px 0 var(--hud-accent); }
|
|
52
|
+
.a11y-help { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
53
|
+
.a11y-meta { display: flex; gap: 8px; min-width: 0; font-family: var(--hud-mono); font-size: 10px; color: var(--hud-fg-muted); }
|
|
54
|
+
.a11y-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
55
|
+
.a11y-rule { flex-shrink: 0; }
|
|
56
|
+
.a11y-gone { color: var(--hud-warn); }
|
|
57
|
+
.hud .a11y-doc {
|
|
58
|
+
display: flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
padding: 0 8px;
|
|
61
|
+
color: var(--hud-fg-muted);
|
|
62
|
+
text-decoration: none;
|
|
63
|
+
font-family: var(--hud-mono);
|
|
64
|
+
font-size: 11px;
|
|
65
|
+
}
|
|
66
|
+
.hud .a11y-doc:hover { color: var(--hud-accent); }
|
|
67
|
+
.a11y .empty { margin: 0; }
|
|
68
|
+
`;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/plugins/a11y/a11y-panel.tsx
|
|
71
|
+
function summary({ status, findings, counts, error, ranAt }) {
|
|
72
|
+
if (status === "idle") return "Fetches axe-core and audits the page, HUD excluded.";
|
|
73
|
+
if (status === "loading") return "Loading axe-core…";
|
|
74
|
+
if (status === "running") return "Auditing…";
|
|
75
|
+
if (status === "error") return error ?? "Audit failed";
|
|
76
|
+
const parts = IMPACT_ORDER.filter((impact) => counts[impact] > 0).map((impact) => `${counts[impact]} ${impact}`);
|
|
77
|
+
const at = ranAt ? new Date(ranAt).toLocaleTimeString(void 0, { hour12: false }) : "";
|
|
78
|
+
const head = findings.length === 1 ? "1 issue" : `${findings.length} issues`;
|
|
79
|
+
return [parts.length > 0 ? `${head}: ${parts.join(", ")}` : head, at].filter(Boolean).join(" · ");
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Run button, a summary line and the findings grouped by impact. A finding
|
|
83
|
+
* outlines its element with the grabber overlay; the outline follows the
|
|
84
|
+
* panel: closing it clears the outline.
|
|
85
|
+
*/
|
|
86
|
+
function A11yPanel({ ctx, options }) {
|
|
87
|
+
const snapshot = useA11y();
|
|
88
|
+
const { highlight } = useGrab(ctx.grab);
|
|
89
|
+
const [gone, setGone] = useState(null);
|
|
90
|
+
const own = useRef(null);
|
|
91
|
+
const activeKey = own.current && highlight?.element === own.current.element ? own.current.key : null;
|
|
92
|
+
useEffect(() => () => {
|
|
93
|
+
if (own.current && ctx.grab.getState().highlight?.element === own.current.element) ctx.grab.clearHighlight();
|
|
94
|
+
}, [ctx]);
|
|
95
|
+
const show = (finding) => {
|
|
96
|
+
const element = resolveTarget(finding.target);
|
|
97
|
+
if (!element) {
|
|
98
|
+
setGone(finding.key);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
setGone(null);
|
|
102
|
+
own.current = {
|
|
103
|
+
key: finding.key,
|
|
104
|
+
element
|
|
105
|
+
};
|
|
106
|
+
ctx.grab.highlight(element, `${finding.rule} · ${finding.impact ?? "n/a"}`);
|
|
107
|
+
};
|
|
108
|
+
const busy = snapshot.status === "loading" || snapshot.status === "running";
|
|
109
|
+
const groups = IMPACT_ORDER.map((impact) => ({
|
|
110
|
+
impact,
|
|
111
|
+
findings: snapshot.findings.filter((finding) => finding.impact === impact)
|
|
112
|
+
})).filter((group) => group.findings.length > 0);
|
|
113
|
+
const unrated = snapshot.findings.filter((finding) => finding.impact === null);
|
|
114
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
115
|
+
className: "a11y",
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ jsx("style", { children: A11Y_CSS }),
|
|
118
|
+
/* @__PURE__ */ jsxs("div", {
|
|
119
|
+
className: "a11y-toolbar",
|
|
120
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
121
|
+
type: "button",
|
|
122
|
+
className: "a11y-run",
|
|
123
|
+
disabled: busy,
|
|
124
|
+
onClick: () => void runAudit(options),
|
|
125
|
+
children: snapshot.status === "done" ? "Re-run" : "Run"
|
|
126
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
127
|
+
className: "a11y-summary",
|
|
128
|
+
role: "status",
|
|
129
|
+
"data-level": snapshot.status === "error" ? "error" : void 0,
|
|
130
|
+
children: summary(snapshot)
|
|
131
|
+
})]
|
|
132
|
+
}),
|
|
133
|
+
snapshot.status === "done" && snapshot.findings.length === 0 && /* @__PURE__ */ jsx("p", {
|
|
134
|
+
className: "empty",
|
|
135
|
+
children: "No violations. axe checks what it can see; test with a reader too."
|
|
136
|
+
}),
|
|
137
|
+
snapshot.findings.length > 0 && /* @__PURE__ */ jsxs("ul", {
|
|
138
|
+
className: "a11y-list",
|
|
139
|
+
"aria-label": "Accessibility findings",
|
|
140
|
+
children: [groups.map((group) => /* @__PURE__ */ jsx(Group, {
|
|
141
|
+
impact: group.impact,
|
|
142
|
+
findings: group.findings,
|
|
143
|
+
activeKey,
|
|
144
|
+
gone,
|
|
145
|
+
onShow: show
|
|
146
|
+
}, group.impact)), unrated.length > 0 && /* @__PURE__ */ jsx(Group, {
|
|
147
|
+
impact: null,
|
|
148
|
+
findings: unrated,
|
|
149
|
+
activeKey,
|
|
150
|
+
gone,
|
|
151
|
+
onShow: show
|
|
152
|
+
})]
|
|
153
|
+
})
|
|
154
|
+
]
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function Group({ impact, findings, activeKey, gone, onShow }) {
|
|
158
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("li", {
|
|
159
|
+
className: "a11y-impact",
|
|
160
|
+
"data-impact": impact ?? "none",
|
|
161
|
+
children: [
|
|
162
|
+
impact ?? "unrated",
|
|
163
|
+
" (",
|
|
164
|
+
findings.length,
|
|
165
|
+
")"
|
|
166
|
+
]
|
|
167
|
+
}), findings.map((finding) => {
|
|
168
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
169
|
+
className: "a11y-row",
|
|
170
|
+
"data-impact": finding.impact ?? "none",
|
|
171
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
172
|
+
type: "button",
|
|
173
|
+
className: "a11y-finding",
|
|
174
|
+
"aria-pressed": activeKey === finding.key,
|
|
175
|
+
title: finding.summary,
|
|
176
|
+
onClick: () => onShow(finding),
|
|
177
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
178
|
+
className: "a11y-help",
|
|
179
|
+
children: finding.help
|
|
180
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
181
|
+
className: "a11y-meta",
|
|
182
|
+
children: [
|
|
183
|
+
/* @__PURE__ */ jsx("span", {
|
|
184
|
+
className: "a11y-rule",
|
|
185
|
+
children: finding.rule
|
|
186
|
+
}),
|
|
187
|
+
/* @__PURE__ */ jsx("span", { children: targetLabel(finding.target) }),
|
|
188
|
+
gone === finding.key && /* @__PURE__ */ jsx("span", {
|
|
189
|
+
className: "a11y-gone",
|
|
190
|
+
children: "element gone"
|
|
191
|
+
})
|
|
192
|
+
]
|
|
193
|
+
})]
|
|
194
|
+
}), /* @__PURE__ */ jsx("a", {
|
|
195
|
+
className: "a11y-doc",
|
|
196
|
+
href: finding.helpUrl,
|
|
197
|
+
target: "_blank",
|
|
198
|
+
rel: "noreferrer",
|
|
199
|
+
title: `${finding.rule}: rule documentation`,
|
|
200
|
+
"aria-label": `${finding.rule}: rule documentation`,
|
|
201
|
+
children: "?"
|
|
202
|
+
})]
|
|
203
|
+
}, finding.key);
|
|
204
|
+
})] });
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
export { A11yPanel, A11yPanel as default };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//#region src/plugins/access/access.ts
|
|
2
|
+
/**
|
|
3
|
+
* httpOnly cookie holding the signed unlock token. `__Host-` makes browsers
|
|
4
|
+
* refuse it unless it is Secure, host-only and on `/`, so a sibling subdomain
|
|
5
|
+
* cannot set or shadow it.
|
|
6
|
+
*/
|
|
7
|
+
const HUD_UNLOCK_COOKIE = "__Host-hud-unlock";
|
|
8
|
+
/** Unlock lifetime per tier. Production is deliberately the shortest window. */
|
|
9
|
+
const HUD_UNLOCK_TTL_MS = {
|
|
10
|
+
open: 0,
|
|
11
|
+
password: 432e5,
|
|
12
|
+
flag: 72e5,
|
|
13
|
+
denied: 0
|
|
14
|
+
};
|
|
15
|
+
function resolveHudAccess(env) {
|
|
16
|
+
if (env === "disabled") return "denied";
|
|
17
|
+
if (env === "development") return "open";
|
|
18
|
+
if (env === "production") return "flag";
|
|
19
|
+
return "password";
|
|
20
|
+
}
|
|
21
|
+
/** Whether this tier needs a valid unlock cookie before any HUD data flows. */
|
|
22
|
+
function hudRequiresUnlock(access) {
|
|
23
|
+
return access === "password" || access === "flag";
|
|
24
|
+
}
|
|
25
|
+
function hudUnlockTtlMs(access) {
|
|
26
|
+
return HUD_UNLOCK_TTL_MS[access];
|
|
27
|
+
}
|
|
28
|
+
const encoder = new TextEncoder();
|
|
29
|
+
/**
|
|
30
|
+
* The HMAC key is never the secret itself: HKDF derives one per tier, so a
|
|
31
|
+
* cookie minted on staging does not verify on production even when both
|
|
32
|
+
* share a password.
|
|
33
|
+
*/
|
|
34
|
+
async function signingKey(secret, env) {
|
|
35
|
+
const material = await crypto.subtle.importKey("raw", encoder.encode(secret), "HKDF", false, ["deriveKey"]);
|
|
36
|
+
return crypto.subtle.deriveKey({
|
|
37
|
+
name: "HKDF",
|
|
38
|
+
hash: "SHA-256",
|
|
39
|
+
salt: encoder.encode("@hansenexus/hud"),
|
|
40
|
+
info: encoder.encode(`hud-unlock:${env}`)
|
|
41
|
+
}, material, {
|
|
42
|
+
name: "HMAC",
|
|
43
|
+
hash: "SHA-256",
|
|
44
|
+
length: 256
|
|
45
|
+
}, false, ["sign"]);
|
|
46
|
+
}
|
|
47
|
+
async function hmacHex(secret, env, issuedAt) {
|
|
48
|
+
const key = await signingKey(secret, env);
|
|
49
|
+
const signature = await crypto.subtle.sign("HMAC", key, encoder.encode(`${env}.${issuedAt}`));
|
|
50
|
+
return Array.from(new Uint8Array(signature)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
51
|
+
}
|
|
52
|
+
/** Length-independent, constant-time comparison of two strings. */
|
|
53
|
+
function timingSafeEqual(a, b) {
|
|
54
|
+
const length = Math.max(a.length, b.length);
|
|
55
|
+
let diff = a.length ^ b.length;
|
|
56
|
+
for (let i = 0; i < length; i++) diff |= (a.charCodeAt(i) || 0) ^ (b.charCodeAt(i) || 0);
|
|
57
|
+
return diff === 0;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Mints an unlock token for `env`, `<issuedAt>.<hmac>`. The issue time is in
|
|
61
|
+
* the clear so expiry is verifiable without server state, and covered by the
|
|
62
|
+
* signature so it cannot be back-dated. `secret` is `HUD_ACCESS_SECRET` when
|
|
63
|
+
* set, the password otherwise.
|
|
64
|
+
*/
|
|
65
|
+
async function signHudUnlockToken(secret, env, issuedAt = Date.now()) {
|
|
66
|
+
return `${issuedAt}.${await hmacHex(secret, env, String(issuedAt))}`;
|
|
67
|
+
}
|
|
68
|
+
async function verifyHudUnlockToken(token, secret, env, options = {}) {
|
|
69
|
+
if (!token || !secret) return false;
|
|
70
|
+
const separator = token.indexOf(".");
|
|
71
|
+
if (separator <= 0) return false;
|
|
72
|
+
const issuedAtRaw = token.slice(0, separator);
|
|
73
|
+
const signature = token.slice(separator + 1);
|
|
74
|
+
const issuedAt = Number(issuedAtRaw);
|
|
75
|
+
if (!Number.isSafeInteger(issuedAt) || issuedAt <= 0) return false;
|
|
76
|
+
const now = options.now ?? Date.now();
|
|
77
|
+
const ttlMs = options.ttlMs ?? HUD_UNLOCK_TTL_MS.flag;
|
|
78
|
+
const age = now - issuedAt;
|
|
79
|
+
if (age < 0 || age > ttlMs) return false;
|
|
80
|
+
return timingSafeEqual(signature, await hmacHex(secret, env, issuedAtRaw));
|
|
81
|
+
}
|
|
82
|
+
/** Parses one cookie out of a raw `Cookie:` header. */
|
|
83
|
+
function readCookie(header, name) {
|
|
84
|
+
if (!header) return void 0;
|
|
85
|
+
for (const part of header.split(";")) {
|
|
86
|
+
const trimmed = part.trim();
|
|
87
|
+
if (trimmed.startsWith(`${name}=`)) try {
|
|
88
|
+
return decodeURIComponent(trimmed.slice(name.length + 1));
|
|
89
|
+
} catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Serialized `Set-Cookie` value for the unlock token, or its removal. */
|
|
95
|
+
function hudUnlockCookieString(token, ttlMs) {
|
|
96
|
+
const base = `${HUD_UNLOCK_COOKIE}=${token ?? ""}; Path=/; HttpOnly; SameSite=Strict; Secure`;
|
|
97
|
+
return token ? `${base}; Max-Age=${Math.floor(ttlMs / 1e3)}` : `${base}; Max-Age=0`;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { readCookie as a, timingSafeEqual as c, hudUnlockTtlMs as i, verifyHudUnlockToken as l, hudRequiresUnlock as n, resolveHudAccess as o, hudUnlockCookieString as r, signHudUnlockToken as s, HUD_UNLOCK_COOKIE as t };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { r as HudCapability } from "./plugins-BZvDqGx5.js";
|
|
2
|
+
import { t as HudEnv } from "./env-CApnbI0r.js";
|
|
3
|
+
//#region src/plugins/access/capabilities.d.ts
|
|
4
|
+
/** The capability vocabulary of the default matrix. Development grants these and any other. */
|
|
5
|
+
declare const HUD_CAPABILITIES: readonly ["observe.app", "observe.estate", "cicd.read", "cicd.trigger", "inject.seed", "mock.toggle", "auth.impersonate", "dispatch.local", "dispatch.hermes", "variants.switch", "variants.vote", "variants.generate", "state.force", "routes.read", "inspect.read", "data.read", "data.write", "capture.screenshot"];
|
|
6
|
+
/**
|
|
7
|
+
* Capabilities no production matrix may grant. `data.*` switches who the
|
|
8
|
+
* page is signed in as and what the app reads: on production that is a
|
|
9
|
+
* breach, not a tool, so `hasCapability` denies it there whatever an app's
|
|
10
|
+
* `matrix` says, and `resolveMatrix` strips it from a production override.
|
|
11
|
+
*/
|
|
12
|
+
declare function isProductionDenied(capability: HudCapability): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The access plugin's own capability. The guard lets the unlock route through
|
|
15
|
+
* on every enabled tier, so it never needs a matrix entry; nothing else may use it.
|
|
16
|
+
*/
|
|
17
|
+
declare const ACCESS_UNLOCK_CAPABILITY = "access.unlock";
|
|
18
|
+
/** Tiers whose grants an app may replace. Development grants all, disabled nothing. */
|
|
19
|
+
type DeployedTier = "preview" | "staging" | "production";
|
|
20
|
+
/** Per-tier replacement lists, for apps whose plugins bring capabilities of their own. */
|
|
21
|
+
type CapabilityMatrixOverride = Partial<Record<DeployedTier, readonly HudCapability[]>>;
|
|
22
|
+
type CapabilityMatrix = Record<HudEnv, readonly HudCapability[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Default-deny capability matrix. Client filtering is convenience only: the
|
|
25
|
+
* guard re-checks every route against the same matrix server side.
|
|
26
|
+
* Staging's `auth.impersonate` is further flag-gated by the plugin that uses it.
|
|
27
|
+
*/
|
|
28
|
+
declare const CAPABILITY_MATRIX: CapabilityMatrix;
|
|
29
|
+
/** Core assumes development, so development grants every capability, listed or not. */
|
|
30
|
+
declare function hasCapability(env: HudEnv, capability: HudCapability, matrix?: CapabilityMatrix): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the HUD exists at all. Outside development a deployed tier also
|
|
33
|
+
* needs its overlay to set `NEXT_PUBLIC_HUD_ENABLED=true`.
|
|
34
|
+
*/
|
|
35
|
+
declare function isHudVisible(env: HudEnv, enabled?: boolean): boolean;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/plugins/access/access.d.ts
|
|
38
|
+
type HudAccess = "open" | "password" | "flag" | "denied";
|
|
39
|
+
/**
|
|
40
|
+
* httpOnly cookie holding the signed unlock token. `__Host-` makes browsers
|
|
41
|
+
* refuse it unless it is Secure, host-only and on `/`, so a sibling subdomain
|
|
42
|
+
* cannot set or shadow it.
|
|
43
|
+
*/
|
|
44
|
+
declare const HUD_UNLOCK_COOKIE = "__Host-hud-unlock";
|
|
45
|
+
declare function resolveHudAccess(env: HudEnv): HudAccess;
|
|
46
|
+
/** Whether this tier needs a valid unlock cookie before any HUD data flows. */
|
|
47
|
+
declare function hudRequiresUnlock(access: HudAccess): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Mints an unlock token for `env`, `<issuedAt>.<hmac>`. The issue time is in
|
|
50
|
+
* the clear so expiry is verifiable without server state, and covered by the
|
|
51
|
+
* signature so it cannot be back-dated. `secret` is `HUD_ACCESS_SECRET` when
|
|
52
|
+
* set, the password otherwise.
|
|
53
|
+
*/
|
|
54
|
+
declare function signHudUnlockToken(secret: string, env: HudEnv, issuedAt?: number): Promise<string>;
|
|
55
|
+
interface HudUnlockVerifyOptions {
|
|
56
|
+
now?: number;
|
|
57
|
+
ttlMs?: number;
|
|
58
|
+
}
|
|
59
|
+
declare function verifyHudUnlockToken(token: string | undefined, secret: string | undefined, env: HudEnv, options?: HudUnlockVerifyOptions): Promise<boolean>;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { signHudUnlockToken as a, CAPABILITY_MATRIX as c, hasCapability as d, isHudVisible as f, resolveHudAccess as i, CapabilityMatrixOverride as l, HudAccess as n, verifyHudUnlockToken as o, isProductionDenied as p, hudRequiresUnlock as r, ACCESS_UNLOCK_CAPABILITY as s, HUD_UNLOCK_COOKIE as t, HUD_CAPABILITIES as u };
|