@hansenexus/hud 0.4.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.
Files changed (157) hide show
  1. package/README.md +603 -9
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
  5. package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
  6. package/dist/access-panel-CEfTr9ZI.js +123 -0
  7. package/dist/adapter-BYoxPYTI.d.ts +33 -0
  8. package/dist/adapter-hcwmJtNx.js +65 -0
  9. package/dist/auto/runtime.d.ts +65 -0
  10. package/dist/auto/runtime.js +50 -0
  11. package/dist/auto.d.ts +15 -0
  12. package/dist/auto.js +33 -0
  13. package/dist/capabilities-rDSKjXpq.js +110 -0
  14. package/dist/capture-CwrIwLqi.js +300 -0
  15. package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
  16. package/dist/cli.d.ts +1 -0
  17. package/dist/cli.js +275 -0
  18. package/dist/data-panel-DhxAmP91.js +817 -0
  19. package/dist/data-store-ChF1td_P.js +164 -0
  20. package/dist/define-hud-CHPedaQ5.d.ts +50 -0
  21. package/dist/design-D0kGgPoP.js +87 -0
  22. package/dist/detect-BxHZ0pxW.d.ts +25 -0
  23. package/dist/detect-CHZiSeZs.js +63 -0
  24. package/dist/dispatch-panel-B-xr_Giy.js +279 -0
  25. package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
  26. package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
  27. package/dist/file-xdSaQ2uR.js +103 -0
  28. package/dist/flags-DVtaJ8pQ.d.ts +58 -0
  29. package/dist/flags.d.ts +2 -0
  30. package/dist/flags.js +82 -0
  31. package/dist/force-state-panel-_otVYh9i.js +97 -0
  32. package/dist/generate-C8lQl3Eh.js +53 -0
  33. package/dist/handler-BpVhxEmU.js +106 -0
  34. package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
  35. package/dist/index-BAV_1W8a.d.ts +43 -0
  36. package/dist/index-BJ26pse9.d.ts +70 -0
  37. package/dist/index-BnQ0dTZf.d.ts +19 -0
  38. package/dist/index-CwfX-W87.d.ts +72 -0
  39. package/dist/index-DcH9V3cU.d.ts +48 -0
  40. package/dist/index-DqOyNf1u.d.ts +65 -0
  41. package/dist/index-DstI_ike.d.ts +66 -0
  42. package/dist/index-Dxz4fn4j.d.ts +42 -0
  43. package/dist/index-Hhh7OXzU.d.ts +129 -0
  44. package/dist/index-ReFbhQ9p.d.ts +25 -0
  45. package/dist/index-RgXfMBuW.d.ts +48 -0
  46. package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.js +710 -69
  49. package/dist/inspect-C9Ft8fqn.js +142 -0
  50. package/dist/inspect-root-BkaupBMp.js +429 -0
  51. package/dist/meta-Bv0sEao3.js +6 -0
  52. package/dist/meta-C_G7MB5w.d.ts +49 -0
  53. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  54. package/dist/mocks-ESiRqk9o.js +150 -0
  55. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  56. package/dist/next/config.d.ts +52 -0
  57. package/dist/next/config.js +78 -0
  58. package/dist/next.d.ts +14 -4
  59. package/dist/next.js +5 -3
  60. package/dist/observe-CdDnDBRP.js +89 -0
  61. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  62. package/dist/ops-panel-CEqDe_UT.js +234 -0
  63. package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
  64. package/dist/plugins/a11y.d.ts +2 -0
  65. package/dist/plugins/a11y.js +2 -0
  66. package/dist/plugins/access/server.d.ts +5 -5
  67. package/dist/plugins/access/server.js +4 -3
  68. package/dist/plugins/access.d.ts +5 -5
  69. package/dist/plugins/access.js +16 -215
  70. package/dist/plugins/agent/server.d.ts +3 -38
  71. package/dist/plugins/agent/server.js +47 -21
  72. package/dist/plugins/agent.d.ts +4 -4
  73. package/dist/plugins/agent.js +6 -348
  74. package/dist/plugins/capture/server.d.ts +92 -0
  75. package/dist/plugins/capture/server.js +248 -0
  76. package/dist/plugins/capture.d.ts +24 -0
  77. package/dist/plugins/capture.js +70 -0
  78. package/dist/plugins/data/msw-browser.d.ts +2 -0
  79. package/dist/plugins/data/msw-browser.js +39 -0
  80. package/dist/plugins/data/msw-node.d.ts +36 -0
  81. package/dist/plugins/data/msw-node.js +68 -0
  82. package/dist/plugins/data/server.d.ts +257 -0
  83. package/dist/plugins/data/server.js +717 -0
  84. package/dist/plugins/data.d.ts +6 -0
  85. package/dist/plugins/data.js +51 -0
  86. package/dist/plugins/design/server.d.ts +54 -0
  87. package/dist/plugins/design/server.js +198 -0
  88. package/dist/plugins/design.d.ts +4 -124
  89. package/dist/plugins/design.js +4 -619
  90. package/dist/plugins/inspect/convex.d.ts +2 -0
  91. package/dist/plugins/inspect/convex.js +486 -0
  92. package/dist/plugins/inspect/react-query.d.ts +2 -0
  93. package/dist/plugins/inspect/react-query.js +225 -0
  94. package/dist/plugins/inspect/sockets.d.ts +51 -0
  95. package/dist/plugins/inspect/sockets.js +397 -0
  96. package/dist/plugins/inspect/swr.d.ts +2 -0
  97. package/dist/plugins/inspect/swr.js +218 -0
  98. package/dist/plugins/inspect.d.ts +4 -0
  99. package/dist/plugins/inspect.js +3 -0
  100. package/dist/plugins/observe.d.ts +4 -64
  101. package/dist/plugins/observe.js +1 -616
  102. package/dist/plugins/ops/server.d.ts +1 -1
  103. package/dist/plugins/ops/server.js +2 -1
  104. package/dist/plugins/ops.d.ts +2 -1
  105. package/dist/plugins/ops.js +15 -336
  106. package/dist/plugins/routes/server.d.ts +88 -0
  107. package/dist/plugins/routes/server.js +62 -0
  108. package/dist/plugins/routes.d.ts +3 -0
  109. package/dist/plugins/routes.js +216 -0
  110. package/dist/plugins/seo.d.ts +2 -0
  111. package/dist/plugins/seo.js +2 -0
  112. package/dist/plugins/vitals.d.ts +2 -25
  113. package/dist/plugins/vitals.js +3 -2
  114. package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
  115. package/dist/poll-CjKsWZi8.js +89 -0
  116. package/dist/requests-BwD6MKEq.js +282 -0
  117. package/dist/requests-CJrUf465.d.ts +50 -0
  118. package/dist/review.js +2 -2
  119. package/dist/same-origin-BGet22CC.js +21 -0
  120. package/dist/scan-DzJNXqOk.js +165 -0
  121. package/dist/seo-Dq9q_QkO.js +551 -0
  122. package/dist/seo-panel-CfiY-TnT.js +124 -0
  123. package/dist/server.d.ts +2 -2
  124. package/dist/server.js +2 -105
  125. package/dist/sessions-panel-COvhPAzv.js +98 -0
  126. package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
  127. package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
  128. package/dist/store/convex.d.ts +33 -0
  129. package/dist/store/convex.js +52 -0
  130. package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
  131. package/dist/store-Ync9eb1G.js +67 -0
  132. package/dist/store.d.ts +76 -0
  133. package/dist/store.js +188 -0
  134. package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
  135. package/dist/styles-DKU_P8MH.js +139 -0
  136. package/dist/styles-DPpDPmzi.js +68 -0
  137. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  138. package/dist/types-B-ulf2Jp.js +8 -0
  139. package/dist/types-BIgGf-0C.d.ts +25 -0
  140. package/dist/types-BIkI-qN8.js +30 -0
  141. package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
  142. package/dist/types-DIdPfjtV.js +6 -0
  143. package/dist/types-DaJcsEjO.d.ts +44 -0
  144. package/dist/types-Dn68psVz.d.ts +118 -0
  145. package/dist/types-szkr2QOF.d.ts +39 -0
  146. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  147. package/dist/variant-groups-TIfO3NIj.js +137 -0
  148. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  149. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  150. package/dist/variants-types-CcRf119M.d.ts +63 -0
  151. package/dist/variants.d.ts +43 -0
  152. package/dist/variants.js +83 -0
  153. package/dist/vitals-panel-BCmMUntW.js +30 -0
  154. package/dist/vite.d.ts +37 -0
  155. package/dist/vite.js +134 -0
  156. package/package.json +65 -5
  157. package/dist/define-hud-BBzsSl8b.d.ts +0 -36
@@ -0,0 +1,225 @@
1
+ import { a as preview, i as prettyPreview, o as useNow, r as oneLine, t as ago } from "../../adapter-hcwmJtNx.js";
2
+ import { useState, useSyncExternalStore } from "react";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ //#region src/plugins/inspect/react-query/index.tsx
5
+ const MAX_ROWS = 100;
6
+ /**
7
+ * React Query tab for the inspect plugin: every cache entry with its key,
8
+ * status, staleness, observer count and age, data redacted like a response
9
+ * body, and Invalidate / Remove per key. Subscribes to the query cache when
10
+ * called; `dispose()` unsubscribes.
11
+ */
12
+ function inspectReactQuery({ queryClient }) {
13
+ const cache = queryClient.getQueryCache();
14
+ let version = 0;
15
+ const listeners = /* @__PURE__ */ new Set();
16
+ const unsubscribe = cache.subscribe(() => {
17
+ version++;
18
+ for (const listener of listeners) listener();
19
+ });
20
+ const subscribe = (listener) => {
21
+ listeners.add(listener);
22
+ return () => listeners.delete(listener);
23
+ };
24
+ const getVersion = () => version;
25
+ const useQueries = () => {
26
+ useSyncExternalStore(subscribe, getVersion, getVersion);
27
+ return cache.getAll();
28
+ };
29
+ function Panel() {
30
+ const queries = useQueries();
31
+ const now = useNow();
32
+ const [selected, setSelected] = useState(null);
33
+ const rows = [...queries].sort((a, b) => b.state.dataUpdatedAt - a.state.dataUpdatedAt).slice(0, MAX_ROWS);
34
+ const current = selected === null ? void 0 : queries.find((q) => q.queryHash === selected);
35
+ const stale = queries.filter((q) => {
36
+ const label = freshness(q);
37
+ return label === "stale" || label === "invalidated";
38
+ }).length;
39
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
40
+ /* @__PURE__ */ jsxs("div", {
41
+ className: "insp-toolbar",
42
+ role: "toolbar",
43
+ "aria-label": "React Query",
44
+ children: [
45
+ /* @__PURE__ */ jsx("span", {
46
+ className: "insp-chip",
47
+ children: queries.length === 1 ? "1 query" : `${queries.length} queries`
48
+ }),
49
+ /* @__PURE__ */ jsxs("span", {
50
+ className: "insp-chip",
51
+ children: [stale, " stale"]
52
+ }),
53
+ /* @__PURE__ */ jsx("button", {
54
+ type: "button",
55
+ className: "insp-chip insp-clear",
56
+ onClick: () => void queryClient.invalidateQueries(),
57
+ children: "invalidate all"
58
+ })
59
+ ]
60
+ }),
61
+ /* @__PURE__ */ jsx("div", {
62
+ className: "insp-log",
63
+ role: "listbox",
64
+ "aria-label": "React Query cache",
65
+ children: rows.length === 0 ? /* @__PURE__ */ jsx("p", {
66
+ className: "empty",
67
+ children: "No queries in the cache yet."
68
+ }) : rows.map((query) => /* @__PURE__ */ jsx(QueryRow, {
69
+ query,
70
+ now,
71
+ selected: query.queryHash === selected,
72
+ onClick: () => setSelected((value) => value === query.queryHash ? null : query.queryHash)
73
+ }, query.queryHash))
74
+ }),
75
+ current && /* @__PURE__ */ jsx(QueryDetail, {
76
+ query: current,
77
+ now,
78
+ onInvalidate: () => void queryClient.invalidateQueries({
79
+ queryKey: current.queryKey,
80
+ exact: true
81
+ }),
82
+ onRemove: () => {
83
+ queryClient.removeQueries({
84
+ queryKey: current.queryKey,
85
+ exact: true
86
+ });
87
+ setSelected(null);
88
+ }
89
+ })
90
+ ] });
91
+ }
92
+ return {
93
+ id: "react-query",
94
+ title: "Query",
95
+ Panel,
96
+ useCount: () => useQueries().length,
97
+ dispose: unsubscribe
98
+ };
99
+ }
100
+ function statusLevel(query) {
101
+ if (query.state.status === "error") return "error";
102
+ return query.state.status === "success" ? "ok" : "pending";
103
+ }
104
+ function statusText(query) {
105
+ if (query.state.status === "error") return "ERR";
106
+ return query.state.status === "success" ? "ok" : "…";
107
+ }
108
+ /** The devtools' labels: fetching, inactive (no observers), stale, fresh; invalidated wins over stale. */
109
+ function freshness(query) {
110
+ if (query.state.fetchStatus === "fetching") return "fetching";
111
+ if (query.getObserversCount() === 0) return "inactive";
112
+ if (query.state.isInvalidated) return "invalidated";
113
+ return query.isStale() ? "stale" : "fresh";
114
+ }
115
+ function QueryRow({ query, now, selected, onClick }) {
116
+ const observers = query.getObserversCount();
117
+ const label = freshness(query);
118
+ return /* @__PURE__ */ jsxs("button", {
119
+ type: "button",
120
+ role: "option",
121
+ className: "insp-row",
122
+ "data-idle": observers === 0,
123
+ "aria-selected": selected,
124
+ onClick,
125
+ children: [
126
+ /* @__PURE__ */ jsx("span", {
127
+ className: "insp-method",
128
+ children: label === "fetching" ? "fetch" : "cache"
129
+ }),
130
+ /* @__PURE__ */ jsx("span", {
131
+ className: "insp-url",
132
+ title: query.queryHash,
133
+ children: query.queryHash
134
+ }),
135
+ label !== "fresh" && label !== "fetching" && /* @__PURE__ */ jsx("span", {
136
+ className: "insp-badge",
137
+ "data-kind": label === "invalidated" ? "action" : "replay",
138
+ children: label
139
+ }),
140
+ /* @__PURE__ */ jsx("span", {
141
+ className: "insp-status",
142
+ "data-level": statusLevel(query),
143
+ children: statusText(query)
144
+ }),
145
+ /* @__PURE__ */ jsxs("span", {
146
+ className: "insp-sub",
147
+ children: [
148
+ observers === 1 ? "1 observer" : `${observers} observers`,
149
+ " · ",
150
+ label,
151
+ " · updated",
152
+ " ",
153
+ ago(query.state.dataUpdatedAt, now)
154
+ ]
155
+ })
156
+ ]
157
+ });
158
+ }
159
+ function QueryDetail({ query, now, onInvalidate, onRemove }) {
160
+ const data = preview(query.state.data);
161
+ const error = query.state.error;
162
+ return /* @__PURE__ */ jsxs("section", {
163
+ className: "insp-detail",
164
+ "aria-label": "Query detail",
165
+ children: [
166
+ /* @__PURE__ */ jsxs("div", {
167
+ className: "insp-actions",
168
+ children: [/* @__PURE__ */ jsx("button", {
169
+ type: "button",
170
+ className: "insp-action",
171
+ onClick: onInvalidate,
172
+ children: "Invalidate"
173
+ }), /* @__PURE__ */ jsx("button", {
174
+ type: "button",
175
+ className: "insp-action",
176
+ onClick: onRemove,
177
+ children: "Remove"
178
+ })]
179
+ }),
180
+ /* @__PURE__ */ jsxs("dl", {
181
+ className: "insp-kv",
182
+ children: [
183
+ /* @__PURE__ */ jsx("dt", { children: "key" }),
184
+ /* @__PURE__ */ jsx("dd", { children: query.queryHash }),
185
+ /* @__PURE__ */ jsx("dt", { children: "status" }),
186
+ /* @__PURE__ */ jsxs("dd", { children: [
187
+ query.state.status,
188
+ " / ",
189
+ query.state.fetchStatus
190
+ ] }),
191
+ /* @__PURE__ */ jsx("dt", { children: "freshness" }),
192
+ /* @__PURE__ */ jsx("dd", { children: freshness(query) }),
193
+ /* @__PURE__ */ jsx("dt", { children: "observers" }),
194
+ /* @__PURE__ */ jsxs("dd", { children: [
195
+ query.getObserversCount(),
196
+ " ",
197
+ query.isActive() ? "(active)" : "(inactive)"
198
+ ] }),
199
+ /* @__PURE__ */ jsx("dt", { children: "updated" }),
200
+ /* @__PURE__ */ jsxs("dd", { children: [
201
+ ago(query.state.dataUpdatedAt, now),
202
+ " · ",
203
+ query.state.dataUpdateCount,
204
+ "×"
205
+ ] }),
206
+ error !== null && error !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", { children: "error" }), /* @__PURE__ */ jsx("dd", {
207
+ className: "insp-error",
208
+ children: oneLine(error instanceof Error ? error.message : error, 200)
209
+ })] })
210
+ ]
211
+ }),
212
+ query.state.data !== void 0 && /* @__PURE__ */ jsxs("details", {
213
+ className: "insp-section",
214
+ open: true,
215
+ children: [/* @__PURE__ */ jsx("summary", { children: "Data" }), /* @__PURE__ */ jsx("pre", {
216
+ className: "insp-body",
217
+ "data-section": "data",
218
+ children: prettyPreview(data)
219
+ })]
220
+ })
221
+ ]
222
+ });
223
+ }
224
+ //#endregion
225
+ export { inspectReactQuery };
@@ -0,0 +1,51 @@
1
+ import { t as InspectAdapter } from "../../adapter-BYoxPYTI.js";
2
+ import { i as Stamped } from "../../capture-buffer-Bbbo6omF.js";
3
+ //#region src/plugins/inspect/sockets/store.d.ts
4
+ type SocketKind = "ws" | "sse";
5
+ type SocketState = "connecting" | "open" | "closed" | "error";
6
+ interface SocketConnectionInput {
7
+ kind: SocketKind;
8
+ /** Query tokens redacted. */
9
+ url: string;
10
+ protocol?: string;
11
+ state: SocketState;
12
+ /** Time from construction to `open`. */
13
+ openMs?: number;
14
+ closeCode?: number;
15
+ closeReason?: string;
16
+ frames: number;
17
+ }
18
+ interface SocketConnection extends SocketConnectionInput, Stamped {}
19
+ interface SocketFrameInput {
20
+ connection: number;
21
+ direction: "in" | "out";
22
+ /** SSE event type (`message` unless named); undefined for WebSocket frames. */
23
+ event?: string;
24
+ bytes: number;
25
+ /** Redacted text, capped like a request body. */
26
+ text?: string;
27
+ textTruncated?: boolean;
28
+ /** Why there is no text: `[blob …]`, `[binary …]`. */
29
+ note?: string;
30
+ }
31
+ interface SocketFrame extends SocketFrameInput, Stamped {}
32
+ //#endregion
33
+ //#region src/plugins/inspect/sockets/index.d.ts
34
+ export interface InspectSocketsOptions {
35
+ /** Connections to leave out, by URL. Default: none. */
36
+ ignore?: (url: string) => boolean;
37
+ }
38
+ /**
39
+ * Sockets tab for the inspect plugin: every WebSocket and EventSource the
40
+ * page opens, with its state, time to open and close code, and every frame
41
+ * in both directions with size and redacted text.
42
+ *
43
+ * The global constructors are patched when the factory runs, so sockets
44
+ * opened before the HUD mounts are seen, and checked again when the HUD
45
+ * mounts: a mock layer that wrapped them in between (MSW's `worker.start()`)
46
+ * is wrapped in turn, so the app-facing socket is the one recorded. One
47
+ * `inspectSockets()` per page; `dispose()` restores the globals.
48
+ */
49
+ export declare function inspectSockets({ ignore }?: InspectSocketsOptions): InspectAdapter;
50
+ //#endregion
51
+ export type { SocketConnection, SocketFrame, SocketKind, SocketState };
@@ -0,0 +1,397 @@
1
+ import { g as RingBuffer, h as redactUrl, i as capturedText } from "../../requests-BwD6MKEq.js";
2
+ import { n as byteSize, o as useNow, t as ago } from "../../adapter-hcwmJtNx.js";
3
+ import { useState, useSyncExternalStore } from "react";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ /** Describes a sent or received payload: text is captured and redacted, binaries are noted. */
6
+ function describeFrame(data) {
7
+ const bytes = byteSize(data);
8
+ if (typeof data === "string") {
9
+ const { body, bodyTruncated } = capturedText(data);
10
+ return {
11
+ bytes,
12
+ text: body ?? "",
13
+ ...bodyTruncated ? { textTruncated: true } : {}
14
+ };
15
+ }
16
+ if (typeof Blob !== "undefined" && data instanceof Blob) return {
17
+ bytes,
18
+ note: `[blob ${data.type || "application/octet-stream"}, ${data.size} bytes]`
19
+ };
20
+ if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return {
21
+ bytes,
22
+ note: `[binary, ${data.byteLength} bytes]`
23
+ };
24
+ return {
25
+ bytes,
26
+ note: `[${typeof data}]`
27
+ };
28
+ }
29
+ /** Connections and frames of the sockets adapter, one store per adapter. */
30
+ var SocketStore = class {
31
+ connections = new RingBuffer(50);
32
+ frames = new RingBuffer(500);
33
+ open(kind, url, protocol) {
34
+ return this.connections.push({
35
+ kind,
36
+ url: redactUrl(url),
37
+ state: "connecting",
38
+ frames: 0,
39
+ ...protocol ? { protocol } : {}
40
+ });
41
+ }
42
+ update(id, patch) {
43
+ this.connections.update(id, patch);
44
+ }
45
+ frame(connection, direction, data, event) {
46
+ this.frames.push({
47
+ connection,
48
+ direction,
49
+ ...event !== void 0 ? { event } : {},
50
+ ...describeFrame(data)
51
+ });
52
+ const current = this.connections.getSnapshot().find((c) => c.id === connection);
53
+ if (current) this.connections.update(connection, { frames: current.frames + 1 });
54
+ }
55
+ /** Drops every frame; connections stay (their ids are held by the live sockets). */
56
+ clear() {
57
+ this.frames.clear();
58
+ for (const connection of this.connections.getSnapshot()) if (connection.frames > 0) this.connections.update(connection.id, { frames: 0 });
59
+ }
60
+ };
61
+ function useConnections(store) {
62
+ return useSyncExternalStore(store.connections.subscribe, store.connections.getSnapshot, store.connections.getSnapshot);
63
+ }
64
+ function useFrames(store) {
65
+ return useSyncExternalStore(store.frames.subscribe, store.frames.getSnapshot, store.frames.getSnapshot);
66
+ }
67
+ //#endregion
68
+ //#region src/plugins/inspect/sockets/panel.tsx
69
+ function shortUrl(url) {
70
+ if (typeof location === "undefined") return url;
71
+ const sameOrigin = url.replace(/^wss?:/, location.protocol);
72
+ return sameOrigin.startsWith(location.origin) ? sameOrigin.slice(location.origin.length) || "/" : url;
73
+ }
74
+ function stateLevel(connection) {
75
+ switch (connection.state) {
76
+ case "open": return "ok";
77
+ case "error": return "error";
78
+ case "closed": return "warn";
79
+ default: return "pending";
80
+ }
81
+ }
82
+ /** Connections, then the frames of the selected one (or of all), newest first. */
83
+ function SocketsPanel({ store }) {
84
+ const connections = useConnections(store);
85
+ const frames = useFrames(store);
86
+ const now = useNow();
87
+ const [selected, setSelected] = useState(null);
88
+ const [direction, setDirection] = useState("all");
89
+ const [openFrame, setOpenFrame] = useState(null);
90
+ const current = selected === null ? void 0 : connections.find((c) => c.id === selected);
91
+ const connectionRows = [...connections].slice(-100).reverse();
92
+ const frameRows = frames.filter((frame) => (current === void 0 || frame.connection === current.id) && (direction === "all" || frame.direction === direction)).slice(-100).reverse();
93
+ const frameOpen = openFrame === null ? void 0 : frames.find((f) => f.id === openFrame);
94
+ const live = connections.filter((c) => c.state === "open" || c.state === "connecting").length;
95
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
96
+ /* @__PURE__ */ jsxs("div", {
97
+ className: "insp-toolbar",
98
+ role: "toolbar",
99
+ "aria-label": "Sockets",
100
+ children: [
101
+ /* @__PURE__ */ jsx("span", {
102
+ className: "insp-chip",
103
+ children: live === 1 ? "1 open" : `${live} open`
104
+ }),
105
+ [
106
+ "all",
107
+ "in",
108
+ "out"
109
+ ].map((d) => /* @__PURE__ */ jsx("button", {
110
+ type: "button",
111
+ className: "insp-chip",
112
+ "aria-pressed": direction === d,
113
+ onClick: () => setDirection(d),
114
+ children: d
115
+ }, d)),
116
+ /* @__PURE__ */ jsx("button", {
117
+ type: "button",
118
+ className: "insp-chip insp-clear",
119
+ onClick: () => {
120
+ store.clear();
121
+ setOpenFrame(null);
122
+ },
123
+ children: "clear"
124
+ })
125
+ ]
126
+ }),
127
+ /* @__PURE__ */ jsx("p", {
128
+ className: "insp-heading",
129
+ children: "Connections"
130
+ }),
131
+ /* @__PURE__ */ jsx("div", {
132
+ className: "insp-log",
133
+ role: "listbox",
134
+ "aria-label": "Socket connections",
135
+ children: connectionRows.length === 0 ? /* @__PURE__ */ jsx("p", {
136
+ className: "empty",
137
+ children: "No sockets yet. WebSocket and EventSource connections land here."
138
+ }) : connectionRows.map((connection) => /* @__PURE__ */ jsxs("button", {
139
+ type: "button",
140
+ role: "option",
141
+ className: "insp-row",
142
+ "data-idle": connection.state === "closed",
143
+ "aria-selected": connection.id === selected,
144
+ onClick: () => setSelected((value) => value === connection.id ? null : connection.id),
145
+ children: [
146
+ /* @__PURE__ */ jsx("span", {
147
+ className: "insp-method",
148
+ children: connection.kind
149
+ }),
150
+ /* @__PURE__ */ jsx("span", {
151
+ className: "insp-url",
152
+ title: connection.url,
153
+ children: shortUrl(connection.url)
154
+ }),
155
+ /* @__PURE__ */ jsxs("span", {
156
+ className: "insp-status",
157
+ "data-level": stateLevel(connection),
158
+ children: [connection.state, connection.closeCode !== void 0 ? ` ${connection.closeCode}` : ""]
159
+ }),
160
+ connection.openMs !== void 0 && /* @__PURE__ */ jsxs("span", {
161
+ className: "insp-ms",
162
+ children: [connection.openMs, " ms"]
163
+ }),
164
+ /* @__PURE__ */ jsxs("span", {
165
+ className: "insp-sub",
166
+ children: [
167
+ connection.frames === 1 ? "1 frame" : `${connection.frames} frames`,
168
+ connection.protocol ? ` · ${connection.protocol}` : "",
169
+ " · opened",
170
+ " ",
171
+ ago(connection.ts, now),
172
+ connection.closeReason ? ` · ${connection.closeReason}` : ""
173
+ ]
174
+ })
175
+ ]
176
+ }, connection.id))
177
+ }),
178
+ /* @__PURE__ */ jsxs("p", {
179
+ className: "insp-heading",
180
+ children: ["Frames", current ? ` · ${shortUrl(current.url)}` : ""]
181
+ }),
182
+ /* @__PURE__ */ jsx("div", {
183
+ className: "insp-log",
184
+ role: "listbox",
185
+ "aria-label": "Socket frames",
186
+ children: frameRows.length === 0 ? /* @__PURE__ */ jsx("p", {
187
+ className: "empty",
188
+ children: "No frames yet."
189
+ }) : frameRows.map((frame) => /* @__PURE__ */ jsxs("button", {
190
+ type: "button",
191
+ role: "option",
192
+ className: "insp-row",
193
+ "aria-selected": frame.id === openFrame,
194
+ onClick: () => setOpenFrame((value) => value === frame.id ? null : frame.id),
195
+ children: [
196
+ /* @__PURE__ */ jsx("span", {
197
+ className: "insp-method",
198
+ "data-direction": frame.direction,
199
+ children: frame.direction === "in" ? "↓ in" : "↑ out"
200
+ }),
201
+ /* @__PURE__ */ jsxs("span", {
202
+ className: "insp-url",
203
+ title: frame.text ?? frame.note,
204
+ children: [frame.event !== void 0 && frame.event !== "message" ? `${frame.event}: ` : "", frame.text ?? frame.note]
205
+ }),
206
+ /* @__PURE__ */ jsxs("span", {
207
+ className: "insp-ms",
208
+ children: [frame.bytes, " B"]
209
+ })
210
+ ]
211
+ }, frame.id))
212
+ }),
213
+ frameOpen && /* @__PURE__ */ jsx(FrameDetail, { frame: frameOpen })
214
+ ] });
215
+ }
216
+ function pretty(text) {
217
+ if (!/^\s*[[{]/.test(text)) return text;
218
+ try {
219
+ return JSON.stringify(JSON.parse(text), null, 2);
220
+ } catch {
221
+ return text;
222
+ }
223
+ }
224
+ function FrameDetail({ frame }) {
225
+ return /* @__PURE__ */ jsxs("section", {
226
+ className: "insp-detail",
227
+ "aria-label": "Frame detail",
228
+ children: [/* @__PURE__ */ jsxs("div", {
229
+ className: "insp-meta",
230
+ children: [
231
+ /* @__PURE__ */ jsxs("span", { children: ["direction ", /* @__PURE__ */ jsx("b", { children: frame.direction })] }),
232
+ /* @__PURE__ */ jsxs("span", { children: ["size ", /* @__PURE__ */ jsxs("b", { children: [frame.bytes, " B"] })] }),
233
+ frame.event !== void 0 && /* @__PURE__ */ jsxs("span", { children: ["event ", /* @__PURE__ */ jsx("b", { children: frame.event })] }),
234
+ /* @__PURE__ */ jsxs("span", { children: ["at ", /* @__PURE__ */ jsx("b", { children: new Date(frame.ts).toLocaleTimeString() })] })
235
+ ]
236
+ }), frame.text !== void 0 ? /* @__PURE__ */ jsxs("pre", {
237
+ className: "insp-body",
238
+ "data-section": "frame",
239
+ children: [pretty(frame.text), frame.textTruncated ? "\n… (truncated)" : ""]
240
+ }) : /* @__PURE__ */ jsx("div", {
241
+ className: "insp-note",
242
+ children: frame.note
243
+ })]
244
+ });
245
+ }
246
+ //#endregion
247
+ //#region src/plugins/inspect/sockets/index.tsx
248
+ const isHudRoute = (url) => url.includes("/api/hud/");
249
+ let wsPatch = null;
250
+ let esPatch = null;
251
+ /**
252
+ * Sockets tab for the inspect plugin: every WebSocket and EventSource the
253
+ * page opens, with its state, time to open and close code, and every frame
254
+ * in both directions with size and redacted text.
255
+ *
256
+ * The global constructors are patched when the factory runs, so sockets
257
+ * opened before the HUD mounts are seen, and checked again when the HUD
258
+ * mounts: a mock layer that wrapped them in between (MSW's `worker.start()`)
259
+ * is wrapped in turn, so the app-facing socket is the one recorded. One
260
+ * `inspectSockets()` per page; `dispose()` restores the globals.
261
+ */
262
+ function inspectSockets({ ignore = isHudRoute } = {}) {
263
+ const store = new SocketStore();
264
+ const ensure = () => {
265
+ if (typeof window === "undefined") return;
266
+ if (!wsPatch || window.WebSocket !== wsPatch.cls) {
267
+ wsPatch?.deactivate();
268
+ wsPatch = patchWebSocket(store, ignore);
269
+ }
270
+ if (!esPatch || window.EventSource !== esPatch.cls) {
271
+ esPatch?.deactivate();
272
+ esPatch = patchEventSource(store, ignore);
273
+ }
274
+ };
275
+ ensure();
276
+ return {
277
+ id: "sockets",
278
+ title: "Sockets",
279
+ Panel: () => /* @__PURE__ */ jsx(SocketsPanel, { store }),
280
+ useCount: () => useConnections(store).filter((c) => c.state === "open" || c.state === "connecting").length,
281
+ install: ensure,
282
+ dispose: () => {
283
+ if (wsPatch?.store === store) {
284
+ wsPatch.deactivate();
285
+ if (window.WebSocket === wsPatch.cls) window.WebSocket = wsPatch.original;
286
+ wsPatch = null;
287
+ }
288
+ if (esPatch?.store === store) {
289
+ esPatch.deactivate();
290
+ if (window.EventSource === esPatch.cls) window.EventSource = esPatch.original;
291
+ esPatch = null;
292
+ }
293
+ }
294
+ };
295
+ }
296
+ function patchWebSocket(store, ignore) {
297
+ const Original = window.WebSocket;
298
+ if (!Original) return null;
299
+ let active = true;
300
+ class InspectedWebSocket extends Original {
301
+ constructor(url, protocols) {
302
+ super(url, protocols);
303
+ const href = String(url);
304
+ if (!active || ignore(href)) return;
305
+ const started = performance.now();
306
+ const protocol = Array.isArray(protocols) ? protocols.join(", ") : protocols;
307
+ const { id } = store.open("ws", href, protocol);
308
+ const originalSend = this.send;
309
+ this.send = (data) => {
310
+ store.frame(id, "out", data);
311
+ return originalSend.call(this, data);
312
+ };
313
+ this.addEventListener("open", () => {
314
+ store.update(id, {
315
+ state: "open",
316
+ openMs: Math.round(performance.now() - started),
317
+ ...this.protocol ? { protocol: this.protocol } : {}
318
+ });
319
+ });
320
+ this.addEventListener("message", (event) => store.frame(id, "in", event.data));
321
+ this.addEventListener("error", () => store.update(id, { state: "error" }));
322
+ this.addEventListener("close", (event) => {
323
+ store.update(id, {
324
+ state: event.wasClean || event.code === 1e3 ? "closed" : "error",
325
+ closeCode: event.code,
326
+ ...event.reason ? { closeReason: event.reason } : {}
327
+ });
328
+ });
329
+ }
330
+ }
331
+ window.WebSocket = InspectedWebSocket;
332
+ return {
333
+ store,
334
+ cls: InspectedWebSocket,
335
+ original: Original,
336
+ deactivate: () => {
337
+ active = false;
338
+ }
339
+ };
340
+ }
341
+ function patchEventSource(store, ignore) {
342
+ const Original = window.EventSource;
343
+ if (!Original) return null;
344
+ let active = true;
345
+ class InspectedEventSource extends Original {
346
+ constructor(url, init) {
347
+ super(url, init);
348
+ const href = String(url);
349
+ if (!active || ignore(href)) return;
350
+ const started = performance.now();
351
+ const { id } = store.open("sse", href);
352
+ const nativeAdd = EventTarget.prototype.addEventListener;
353
+ const watched = /* @__PURE__ */ new Set();
354
+ const watch = (type) => {
355
+ if (watched.has(type)) return;
356
+ watched.add(type);
357
+ nativeAdd.call(this, type, (event) => {
358
+ if ("data" in event) store.frame(id, "in", event.data, type);
359
+ });
360
+ };
361
+ watch("message");
362
+ const patchedAdd = (type, listener, options) => {
363
+ if (type !== "open" && type !== "error") watch(type);
364
+ nativeAdd.call(this, type, listener, options);
365
+ };
366
+ Object.defineProperty(this, "addEventListener", {
367
+ value: patchedAdd,
368
+ configurable: true
369
+ });
370
+ nativeAdd.call(this, "open", () => {
371
+ store.update(id, {
372
+ state: "open",
373
+ openMs: Math.round(performance.now() - started)
374
+ });
375
+ });
376
+ nativeAdd.call(this, "error", () => {
377
+ store.update(id, { state: this.readyState === EventSource.CLOSED ? "closed" : "error" });
378
+ });
379
+ const originalClose = this.close;
380
+ this.close = () => {
381
+ store.update(id, { state: "closed" });
382
+ originalClose.call(this);
383
+ };
384
+ }
385
+ }
386
+ window.EventSource = InspectedEventSource;
387
+ return {
388
+ store,
389
+ cls: InspectedEventSource,
390
+ original: Original,
391
+ deactivate: () => {
392
+ active = false;
393
+ }
394
+ };
395
+ }
396
+ //#endregion
397
+ export { inspectSockets };
@@ -0,0 +1,2 @@
1
+ import { a as SwrStateLike, i as SwrKey, n as SwrCacheLike, o as inspectSwr, r as SwrEntry, t as InspectSwrOptions } from "../../index-Dxz4fn4j.js";
2
+ export { InspectSwrOptions, SwrCacheLike, SwrEntry, SwrKey, SwrStateLike, inspectSwr };