@peasant-labs/fairtrade 0.0.7 → 0.0.10

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.
@@ -0,0 +1,3394 @@
1
+ import { Fragment as e, useCallback as t, useEffect as n, useId as r, useLayoutEffect as i, useMemo as a, useRef as o, useState as s } from "react";
2
+ import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
3
+ import { Check as d, ChevronDown as f, ChevronLeft as p, ChevronRight as m, Eye as h, EyeOff as g, FileCode as ee, Folder as _, GitMerge as v, Maximize as te, Minus as y, Plus as b, ScrollText as x, Search as ne, Star as re, TriangleAlert as ie, Users as ae, Waypoints as oe } from "lucide-react";
4
+ import { AllChangeBindings as se, AllDiffLineKinds as S, AllEdgeViolationKinds as ce, AllFileChangeStatuses as le, AllInsightKinds as ue, AllInsightProvenances as de, AllMapNodeKinds as C, AllReadAttributionStates as fe, AllReadStateGrades as w, Harness as T, isChangeBinding as E, isDiffLineKind as pe, isEdgeViolationKind as D, isFileChangeStatus as me, isHarness as he, isInsightKind as ge, isInsightProvenance as _e, isMapNodeKind as ve, isReadAttributionState as ye, isReadStateGrade as be } from "@peasant-labs/schema";
5
+ //#region src/ui/BrandMark.jsx
6
+ var xe = {
7
+ claude: "m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z",
8
+ gemini: "M11.04 19.32Q12 21.51 12 24q0-2.49.93-4.68.96-2.19 2.58-3.81t3.81-2.55Q21.51 12 24 12q-2.49 0-4.68-.93a12.3 12.3 0 0 1-3.81-2.58 12.3 12.3 0 0 1-2.58-3.81Q12 2.49 12 0q0 2.49-.96 4.68-.93 2.19-2.55 3.81a12.3 12.3 0 0 1-3.81 2.58Q2.49 12 0 12q2.49 0 4.68.96 2.19.93 3.81 2.55t2.55 3.81",
9
+ openai: "M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z",
10
+ opencode: "M22 24H2V0h20zM17 4.8H7v14.4h10z",
11
+ cursor: "M11.503.131 1.891 5.678a.84.84 0 0 0-.42.726v11.188c0 .3.162.575.42.724l9.609 5.55a1 1 0 0 0 .998 0l9.61-5.55a.84.84 0 0 0 .42-.724V6.404a.84.84 0 0 0-.42-.726L12.497.131a1.01 1.01 0 0 0-.996 0M2.657 6.338h18.55c.263 0 .43.287.297.515L12.23 22.918c-.062.107-.229.064-.229-.06V12.335a.59.59 0 0 0-.295-.51l-9.11-5.257c-.109-.063-.064-.23.061-.23",
12
+ strike: "M18.5 6L11 17.5h5.2L13.5 26 21 14.5h-5.2L18.5 6z"
13
+ }, O = { strike: "6 6 20 20" }, Se = {
14
+ anthropic: "claude",
15
+ "claude-code": "claude",
16
+ google: "gemini",
17
+ googlegemini: "gemini",
18
+ "gemini-cli": "gemini",
19
+ codex: "openai",
20
+ "codex-cli": "openai",
21
+ chatgpt: "openai",
22
+ gpt: "openai"
23
+ }, Ce = {
24
+ claude: "Claude",
25
+ gemini: "Gemini",
26
+ openai: "OpenAI",
27
+ cursor: "Cursor",
28
+ opencode: "opencode",
29
+ strike: "Strike"
30
+ };
31
+ function we(e) {
32
+ if (!e) return null;
33
+ let t = String(e).toLowerCase().trim(), n = Se[t] || t;
34
+ return xe[n] ? n : null;
35
+ }
36
+ function Te({ name: e, size: t, label: n, className: r = "", ...i }) {
37
+ let a = we(e);
38
+ if (!a) return null;
39
+ let o = ["brand", r].filter(Boolean).join(" "), s = t == null ? {} : {
40
+ width: t,
41
+ height: t,
42
+ style: {
43
+ width: t,
44
+ height: t
45
+ }
46
+ }, c = n ? {
47
+ role: "img",
48
+ "aria-label": n === !0 ? Ce[a] : n,
49
+ focusable: "false"
50
+ } : {
51
+ "aria-hidden": "true",
52
+ focusable: "false"
53
+ };
54
+ return /* @__PURE__ */ l("svg", {
55
+ className: o,
56
+ viewBox: O[a] ?? "0 0 24 24",
57
+ ...s,
58
+ ...c,
59
+ ...i,
60
+ "data-brand": a,
61
+ children: /* @__PURE__ */ l("path", { d: xe[a] })
62
+ });
63
+ }
64
+ //#endregion
65
+ //#region src/ui/provider-policy.js
66
+ var Ee = Object.freeze(Object.values(T)), De = Object.freeze({
67
+ "claude-code": "Claude Code",
68
+ "gemini-cli": "Gemini CLI",
69
+ codex: "Codex",
70
+ opencode: "opencode",
71
+ cursor: "Cursor",
72
+ antigravity: "Google Antigravity",
73
+ strike: "Strike"
74
+ }), Oe = Object.freeze({
75
+ "claude-code": "claude",
76
+ "gemini-cli": "gemini",
77
+ codex: "openai",
78
+ opencode: "opencode",
79
+ cursor: "cursor",
80
+ antigravity: "gemini",
81
+ strike: "strike"
82
+ }), ke = Object.freeze({
83
+ "claude-code": "amber",
84
+ "gemini-cli": "teal",
85
+ codex: "olive",
86
+ opencode: "mauve",
87
+ cursor: "clay",
88
+ antigravity: "teal",
89
+ strike: "clay"
90
+ });
91
+ function k(e, t) {
92
+ if (he(e)) return;
93
+ let n;
94
+ try {
95
+ n = JSON.stringify(e);
96
+ } catch {
97
+ n = String(e);
98
+ }
99
+ throw TypeError(`Provider harness validation failed for ${n} at src/ui/provider-policy.js during ${t}: the value is outside the canonical @peasant-labs/schema Harness, so Fairtrade cannot select a trustworthy provider identity; the caller must validate its wire boundary and pass one of ${Ee.join(", ")}.`);
100
+ }
101
+ function A(e) {
102
+ return k(e, "provider display-name resolution"), De[e];
103
+ }
104
+ function j(e) {
105
+ return k(e, "provider brand resolution"), Oe[e];
106
+ }
107
+ function M(e) {
108
+ return k(e, "provider accent resolution"), ke[e];
109
+ }
110
+ //#endregion
111
+ //#region src/ui/Intensity.jsx
112
+ function Ae(e) {
113
+ let t = Math.round(Number(e) || 0);
114
+ return Math.max(0, Math.min(4, t));
115
+ }
116
+ function je(e, t) {
117
+ if (!t || t <= 0 || e <= 0) return 0;
118
+ let n = Math.min(e / t, 1);
119
+ return n < .25 ? 1 : n < .5 ? 2 : n < .9 ? 3 : 4;
120
+ }
121
+ function Me(e) {
122
+ if (!e || e <= 0) return 0;
123
+ let t = Math.min(e, 1);
124
+ return t <= .25 ? 1 : t <= .5 ? 2 : t <= .75 ? 3 : 4;
125
+ }
126
+ function Ne(e, t) {
127
+ if (e <= 0 || t <= 0) return 0;
128
+ let n = Math.min(e / t, 1);
129
+ return n <= .25 ? 1 : n <= .5 ? 2 : n <= .75 ? 3 : 4;
130
+ }
131
+ function Pe(e) {
132
+ let t = Number(e) || 0;
133
+ return t < 60 ? "xs" : t < 200 ? "sm" : t < 600 ? "md" : t < 1500 ? "lg" : "xl";
134
+ }
135
+ var Fe = [
136
+ "none",
137
+ "low",
138
+ "some",
139
+ "most",
140
+ "full"
141
+ ];
142
+ function N({ level: e = 0, accent: t, size: n, label: r, className: i = "", ...a }) {
143
+ let o = Ae(e);
144
+ return /* @__PURE__ */ l("span", {
145
+ className: `ir-swatch${n === "lg" ? " ir-swatch--lg" : ""}${i ? ` ${i}` : ""}`,
146
+ "data-level": o,
147
+ "data-accent": t || void 0,
148
+ role: "img",
149
+ "aria-label": r || `intensity ${o} of 4 (${Fe[o]})`,
150
+ ...a
151
+ });
152
+ }
153
+ function Ie({ title: e = "coverage", words: t = Fe, className: n = "" }) {
154
+ return /* @__PURE__ */ u("div", {
155
+ className: `ir-scope ir-legend${n ? ` ${n}` : ""}`,
156
+ children: [
157
+ /* @__PURE__ */ l("span", {
158
+ className: "ir-legend__title",
159
+ children: e
160
+ }),
161
+ /* @__PURE__ */ l("div", {
162
+ className: "ir-legend__steps",
163
+ children: [
164
+ 0,
165
+ 1,
166
+ 2,
167
+ 3,
168
+ 4
169
+ ].map((e) => /* @__PURE__ */ u("div", {
170
+ className: "ir-legend__step",
171
+ children: [
172
+ /* @__PURE__ */ l("span", {
173
+ className: "ir-legend__cell",
174
+ "data-level": e,
175
+ "aria-hidden": "true"
176
+ }),
177
+ /* @__PURE__ */ l("span", {
178
+ className: "ir-legend__num",
179
+ children: e
180
+ }),
181
+ /* @__PURE__ */ l("span", {
182
+ className: "ir-legend__label",
183
+ children: t[e]
184
+ })
185
+ ]
186
+ }, e))
187
+ }),
188
+ /* @__PURE__ */ u("div", {
189
+ className: "ir-legend__ends",
190
+ children: [/* @__PURE__ */ l("span", { children: "none" }), /* @__PURE__ */ l("span", { children: "full" })]
191
+ })
192
+ ]
193
+ });
194
+ }
195
+ function Le({ values: e, levels: t, max: n, labels: r, ariaLabel: i = "intensity heatmap", className: a = "" }) {
196
+ let o = t ? t.map(Ae) : (e || []).map((t) => Ne(t, n ?? Math.max(1, ...e || [1])));
197
+ return /* @__PURE__ */ l("div", {
198
+ className: `ir-scope ir-heatmap${a ? ` ${a}` : ""}`,
199
+ role: "img",
200
+ "aria-label": i,
201
+ children: o.map((e, t) => /* @__PURE__ */ l("span", {
202
+ className: "ir-heatmap__cell",
203
+ "data-level": e,
204
+ title: `${r?.[t] ?? `cell ${t + 1}`}: ${Fe[e]} (${e}/4)`
205
+ }, t))
206
+ });
207
+ }
208
+ function Re({ label: e, loc: t, coverage: n = 0, recorded: r, total: i, selected: a = !1, violation: o = 0, effortPct: s, size: c, as: f = "button", onClick: p, className: m = "", ...h }) {
209
+ let g = i == null ? Ae(n) : je(r ?? 0, i), ee = c || Pe(t), _ = Math.max(0, Math.round(Number(o) || 0)), v = s != null && s > 0, te = v ? Me(s > 1 ? s / 100 : s) : 0, y = [
210
+ e,
211
+ i == null ? `coverage ${g} of 4` : `${r ?? 0} of ${i} recorded`,
212
+ t == null ? null : `${t} loc`,
213
+ _ > 0 ? `${_} violation${_ === 1 ? "" : "s"}` : null,
214
+ a ? "selected" : null
215
+ ].filter(Boolean).join(" · "), b = f, x = b === "button";
216
+ return /* @__PURE__ */ u(b, {
217
+ className: `ir-node ir-node--${ee}${m ? ` ${m}` : ""}`,
218
+ "data-coverage": g,
219
+ "data-selected": a ? "true" : void 0,
220
+ type: x ? "button" : void 0,
221
+ "aria-pressed": x ? a : void 0,
222
+ "aria-label": y,
223
+ onClick: p,
224
+ ...h,
225
+ children: [
226
+ /* @__PURE__ */ u("span", {
227
+ className: "ir-node__head",
228
+ children: [/* @__PURE__ */ l("span", {
229
+ className: "ir-node__label",
230
+ children: e
231
+ }), _ > 0 && /* @__PURE__ */ u("span", {
232
+ className: "ir-node__badge",
233
+ "aria-hidden": "true",
234
+ children: [/* @__PURE__ */ l(ie, { "aria-hidden": "true" }), /* @__PURE__ */ l("span", {
235
+ className: "tnum",
236
+ children: _
237
+ })]
238
+ })]
239
+ }),
240
+ /* @__PURE__ */ u("span", {
241
+ className: "ir-node__count",
242
+ children: [i == null ? `cov ${g}/4` : `${r ?? 0}/${i}`, t == null ? "" : ` · ${t} loc`]
243
+ }),
244
+ a && /* @__PURE__ */ l("span", {
245
+ className: "ir-node__mark",
246
+ "aria-hidden": "true",
247
+ children: /* @__PURE__ */ l(d, { "aria-hidden": "true" })
248
+ }),
249
+ v && /* @__PURE__ */ l("span", {
250
+ className: "ir-node__effort",
251
+ "data-level": te,
252
+ "aria-hidden": "true"
253
+ })
254
+ ]
255
+ });
256
+ }
257
+ function ze({ children: e, className: t = "", ...n }) {
258
+ return /* @__PURE__ */ l("div", {
259
+ className: `ir-scope${t ? ` ${t}` : ""}`,
260
+ ...n,
261
+ children: e
262
+ });
263
+ }
264
+ //#endregion
265
+ //#region src/ui/ProviderIcon.jsx
266
+ var Be = Ee, P = ke;
267
+ function F(e) {
268
+ return `var(--${M(e)})`;
269
+ }
270
+ function I({ harness: e, size: t, accent: n = !1, label: r, className: i = "", ...a }) {
271
+ k(e, "ProviderIcon render in src/ui/ProviderIcon.jsx");
272
+ let o = j(e), s = ["pv-icon", i].filter(Boolean).join(" "), c = n ? { color: F(e) } : void 0, u = r === !0 ? A(e) : r;
273
+ return /* @__PURE__ */ l("span", {
274
+ className: s,
275
+ style: c,
276
+ ...a,
277
+ children: /* @__PURE__ */ l(Te, {
278
+ name: o,
279
+ size: t,
280
+ label: u
281
+ })
282
+ });
283
+ }
284
+ function Ve({ harness: e, accent: t = !1, className: n = "", ...r }) {
285
+ return k(e, "ProviderTag render in src/ui/ProviderIcon.jsx"), /* @__PURE__ */ u("span", {
286
+ className: ["pv-tag", n].filter(Boolean).join(" "),
287
+ ...r,
288
+ children: [/* @__PURE__ */ l(I, {
289
+ harness: e,
290
+ accent: t
291
+ }), /* @__PURE__ */ l("span", {
292
+ className: "pv-tag-label",
293
+ children: e
294
+ })]
295
+ });
296
+ }
297
+ function L({ harness: e, accent: t = !1, className: n = "", ...r }) {
298
+ return k(e, "ProviderName render in src/ui/ProviderIcon.jsx"), /* @__PURE__ */ u("span", {
299
+ className: ["pv-name", n].filter(Boolean).join(" "),
300
+ style: t ? { color: F(e) } : void 0,
301
+ ...r,
302
+ children: [/* @__PURE__ */ l(I, { harness: e }), /* @__PURE__ */ l("span", {
303
+ className: "pv-name-label",
304
+ children: e
305
+ })]
306
+ });
307
+ }
308
+ function R({ className: e = "", ...t }) {
309
+ return /* @__PURE__ */ l("ul", {
310
+ className: ["pv-legend", e].filter(Boolean).join(" "),
311
+ ...t,
312
+ children: Be.map((e) => {
313
+ let t = M(e);
314
+ return /* @__PURE__ */ u("li", {
315
+ className: "pv-legend-row",
316
+ children: [
317
+ /* @__PURE__ */ l(I, {
318
+ harness: e,
319
+ accent: !0,
320
+ className: "pv-legend-mark"
321
+ }),
322
+ /* @__PURE__ */ l("span", {
323
+ className: "pv-legend-name",
324
+ children: e
325
+ }),
326
+ /* @__PURE__ */ l("span", {
327
+ className: "pv-swatch",
328
+ style: { background: `var(--${t})` },
329
+ "aria-hidden": "true"
330
+ }),
331
+ /* @__PURE__ */ l("span", {
332
+ className: "pv-legend-token",
333
+ children: t
334
+ })
335
+ ]
336
+ }, e);
337
+ })
338
+ });
339
+ }
340
+ //#endregion
341
+ //#region src/ui/graph/GhostCommitNode.jsx
342
+ var He = Object.freeze({
343
+ hash: "matched by hash",
344
+ patch_id: "matched by patch content",
345
+ author_identity: "matched by author and time",
346
+ message_embedded: "matched by message text",
347
+ temporal: "matched by nearby time only",
348
+ none: "no match found"
349
+ });
350
+ function Ue({ ghostHash: e, subject: t, resolution: n, method: r, confidence: i, className: a = "", ...o }) {
351
+ let s = n === "unresolved" ? "session-era commit, no longer in history; not enough recorded metadata to map it" : `${He[r] ?? r}, ${i} confidence`;
352
+ return /* @__PURE__ */ l("span", {
353
+ className: `tlp-ghost-node tlp-terminal-${i}${a ? ` ${a}` : ""}`,
354
+ role: "img",
355
+ "aria-label": `rewritten commit ${e.slice(0, 8)}${t ? `: ${t}` : ""}: ${s}`,
356
+ title: s,
357
+ ...o,
358
+ children: /* @__PURE__ */ l("svg", {
359
+ className: "tlp-ghost-diamond",
360
+ viewBox: "0 0 9 9",
361
+ width: "9",
362
+ height: "9",
363
+ "aria-hidden": "true",
364
+ children: /* @__PURE__ */ l("rect", {
365
+ x: "1.3",
366
+ y: "1.3",
367
+ width: "6.4",
368
+ height: "6.4",
369
+ transform: "rotate(45 4.5 4.5)"
370
+ })
371
+ })
372
+ });
373
+ }
374
+ //#endregion
375
+ //#region src/ui/graph/SessionLane.jsx
376
+ function z({ sessionId: e, title: t, harness: n, hovered: r = !1, selected: i = !1, onHover: a, onSelect: o, unresolvedGhosts: s = [], className: c = "", ...d }) {
377
+ let f = [
378
+ "tlp-session-lane",
379
+ r && "tlp-session-lane-hover",
380
+ i && "tlp-session-lane-sel",
381
+ c
382
+ ].filter(Boolean).join(" "), p = t || e, m = i ? `${p} selected` : "";
383
+ return /* @__PURE__ */ u("span", {
384
+ className: "tlp-session-lane-group",
385
+ children: [/* @__PURE__ */ u("button", {
386
+ type: "button",
387
+ className: f,
388
+ "aria-pressed": i,
389
+ onMouseEnter: () => a?.(e),
390
+ onMouseLeave: () => a?.(null),
391
+ onFocus: () => a?.(e),
392
+ onBlur: () => a?.(null),
393
+ onClick: () => o?.(e),
394
+ ...d,
395
+ children: [
396
+ n && /* @__PURE__ */ l(I, {
397
+ harness: n,
398
+ label: !0
399
+ }),
400
+ /* @__PURE__ */ l("span", {
401
+ className: "tlp-session-lane-title",
402
+ children: p
403
+ }),
404
+ /* @__PURE__ */ l("span", {
405
+ className: "tlp-sr",
406
+ role: "status",
407
+ "aria-live": "polite",
408
+ children: m
409
+ })
410
+ ]
411
+ }), s.length > 0 && /* @__PURE__ */ l("span", {
412
+ className: "tlp-session-lane-ghosts",
413
+ role: "group",
414
+ "aria-label": "session-era commits with no recorded mapping",
415
+ children: s.map((e) => /* @__PURE__ */ l(Ue, {
416
+ ghostHash: e.ghostHash,
417
+ subject: e.subject,
418
+ resolution: e.resolution,
419
+ method: e.method,
420
+ confidence: e.confidence
421
+ }, e.ghostHash))
422
+ })]
423
+ });
424
+ }
425
+ //#endregion
426
+ //#region src/ui/graph/GhostGroup.jsx
427
+ function We({ successorHash: e, ghosts: t, expanded: n, onToggle: r, className: i = "", ...a }) {
428
+ let o = `${t.length} session-era commit${t.length === 1 ? "" : "s"}`;
429
+ return /* @__PURE__ */ u("div", {
430
+ className: `tlp-ghost-group${i ? ` ${i}` : ""}`,
431
+ ...a,
432
+ children: [/* @__PURE__ */ u("button", {
433
+ type: "button",
434
+ className: "tlp-ghost-group-toggle",
435
+ "aria-expanded": n,
436
+ "aria-label": `${o}, mapped to ${e.slice(0, 8)}`,
437
+ onClick: () => r(e),
438
+ children: [
439
+ /* @__PURE__ */ l(m, {
440
+ className: `tlp-ghost-group-chevron${n ? " tlp-ghost-group-chevron-open" : ""}`,
441
+ "aria-hidden": "true"
442
+ }),
443
+ /* @__PURE__ */ l("span", {
444
+ className: "tlp-ghost-group-stack",
445
+ "aria-hidden": "true",
446
+ children: /* @__PURE__ */ l("svg", {
447
+ viewBox: "0 0 9 9",
448
+ width: "9",
449
+ height: "9",
450
+ children: /* @__PURE__ */ l("rect", {
451
+ x: "1.3",
452
+ y: "1.3",
453
+ width: "6.4",
454
+ height: "6.4",
455
+ transform: "rotate(45 4.5 4.5)"
456
+ })
457
+ })
458
+ }),
459
+ /* @__PURE__ */ l("span", {
460
+ className: "tnum tlp-ghost-group-count",
461
+ children: t.length
462
+ }),
463
+ /* @__PURE__ */ l("span", {
464
+ className: "tlp-ghost-group-label",
465
+ children: o
466
+ }),
467
+ /* @__PURE__ */ l("span", {
468
+ className: "tlp-sr",
469
+ role: "status",
470
+ "aria-live": "polite",
471
+ children: n ? `${o} expanded` : `${o} collapsed`
472
+ })
473
+ ]
474
+ }), n && /* @__PURE__ */ l("ul", {
475
+ className: "tlp-ghost-group-list",
476
+ children: t.map((e) => /* @__PURE__ */ u("li", { children: [/* @__PURE__ */ l(Ue, {
477
+ ghostHash: e.ghostHash,
478
+ subject: e.subject,
479
+ resolution: e.resolution,
480
+ method: e.method,
481
+ confidence: e.confidence
482
+ }), e.subject && /* @__PURE__ */ l("span", {
483
+ className: "tlp-ghost-subject",
484
+ children: e.subject
485
+ })] }, e.ghostHash))
486
+ })]
487
+ });
488
+ }
489
+ //#endregion
490
+ //#region src/ui/graph/SessionOverflowDisclosure.jsx
491
+ function B({ commitHash: e, overflow: t, expanded: n, onToggle: r, onSelect: i, itemLabel: a = "sessions", className: o = "", ...s }) {
492
+ return t.length === 0 ? null : /* @__PURE__ */ u("span", {
493
+ className: `tlp-overflow${o ? ` ${o}` : ""}`,
494
+ ...s,
495
+ children: [
496
+ /* @__PURE__ */ u("button", {
497
+ type: "button",
498
+ className: "tlp-overflow-toggle",
499
+ "aria-expanded": n,
500
+ "aria-label": `${t.length} more ${a}`,
501
+ onClick: () => r(e),
502
+ children: [
503
+ /* @__PURE__ */ u("span", {
504
+ className: "tnum",
505
+ children: ["+", t.length]
506
+ }),
507
+ " more ",
508
+ a
509
+ ]
510
+ }),
511
+ /* @__PURE__ */ l("span", {
512
+ className: "tlp-sr",
513
+ role: "status",
514
+ "aria-live": "polite",
515
+ children: n ? `${t.length} more ${a} expanded` : ""
516
+ }),
517
+ n && /* @__PURE__ */ l("span", {
518
+ className: "tlp-overflow-list",
519
+ role: "group",
520
+ "aria-label": `all ${a}`,
521
+ children: t.map((e) => /* @__PURE__ */ u("button", {
522
+ type: "button",
523
+ className: "tlp-overflow-item",
524
+ "data-session-id": e.sessionId,
525
+ onClick: () => i?.(e.sessionId),
526
+ children: [e.harness && /* @__PURE__ */ l(I, {
527
+ harness: e.harness,
528
+ label: !0
529
+ }), e.title || e.sessionId]
530
+ }, e.sessionId))
531
+ })
532
+ ]
533
+ });
534
+ }
535
+ //#endregion
536
+ //#region src/ui/graph/HighlightEdge.jsx
537
+ function V({ weight: e, geometry: t, className: n = "", ...r }) {
538
+ return /* @__PURE__ */ l("line", {
539
+ className: [
540
+ "tlp-highlight-edge",
541
+ `tlp-highlight-edge-${e}`,
542
+ n
543
+ ].filter(Boolean).join(" "),
544
+ x1: t.x1,
545
+ y1: t.y1,
546
+ x2: t.x2,
547
+ y2: t.y2,
548
+ "aria-hidden": "true",
549
+ ...r
550
+ });
551
+ }
552
+ //#endregion
553
+ //#region src/ui/graph/TouchedFileCluster.jsx
554
+ var H = 8;
555
+ function U({ commitHash: e, files: t, expanded: n, onToggle: r, onOpenDiff: i, className: a = "", ...o }) {
556
+ let s = t.slice(0, H), c = t.slice(H).map((e) => ({
557
+ sessionId: e,
558
+ title: e
559
+ }));
560
+ return /* @__PURE__ */ u("div", {
561
+ className: `tlp-file-cluster${a ? ` ${a}` : ""}`,
562
+ role: "group",
563
+ "aria-label": "touched files",
564
+ ...o,
565
+ children: [s.map((e) => /* @__PURE__ */ l("button", {
566
+ type: "button",
567
+ className: "tlp-file-cluster-item",
568
+ onClick: () => i?.(e),
569
+ children: e
570
+ }, e)), /* @__PURE__ */ l(B, {
571
+ commitHash: e,
572
+ overflow: c,
573
+ expanded: n,
574
+ onToggle: r,
575
+ onSelect: i,
576
+ itemLabel: "files"
577
+ })]
578
+ });
579
+ }
580
+ //#endregion
581
+ //#region src/ui/CommitGraph.jsx
582
+ var Ge = 14, Ke = 9, qe = 7, Je = 9, Ye = "3 3", W = (e) => Ke + e * Ge, Xe = (e) => W(Math.max(e - 1, 0)) + qe;
583
+ function Ze({ commits: e = [], selectedId: t, onNavigate: n, onSelect: r, onOpenSession: c, hasMore: d = !1, onShowOlder: p, label: m = "commit history", className: h = "", sessionLanes: g, hoveredSessionId: ee = null, selectedSessionId: _ = null, onHoverSession: v, onSelectSession: te, highlightSelected: y, highlightHovered: b, ghostGroupsByCommit: x, expandedGhostGroups: ne, onToggleGhostGroup: re, expandedCommitSessions: ie, onToggleCommitSessions: ae, touchedFilesByCommit: oe, onOpenTouchedFile: se, ...S }) {
584
+ let ce = a(() => new Set(ne ?? []), [ne]), le = a(() => new Set(ie ?? []), [ie]), ue = a(() => /* @__PURE__ */ new Set([...y?.commitHashes ?? [], ...y?.ghostHashes ?? []]), [y]), de = a(() => /* @__PURE__ */ new Set([...b?.commitHashes ?? [], ...b?.ghostHashes ?? []]), [b]), C = a(() => e.reduce((e, t) => Math.max(e, (t.lane ?? 0) + 1), 1), [e]), fe = a(() => {
585
+ let t = new Map(e.map((e) => [e.id, e.lane ?? 0])), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
586
+ return e.forEach((e, t) => {
587
+ let i = e.lane ?? 0;
588
+ n.has(i) || n.set(i, t), r.set(i, t);
589
+ }), e.map((e, i) => {
590
+ let a = e.lane ?? 0, o = (e.parents ?? []).map((e) => t.get(e)).filter((e) => e !== void 0 && e !== a).map((e) => ({
591
+ from: a,
592
+ to: e
593
+ })), s = [];
594
+ for (let [e, t] of n) e !== a && i >= t && i <= r.get(e) && s.push(e);
595
+ let c = r.get(a);
596
+ return {
597
+ commit: e,
598
+ lane: a,
599
+ joins: o,
600
+ passLanes: s,
601
+ laneUp: i > n.get(a),
602
+ laneDown: i < c
603
+ };
604
+ });
605
+ }, [e]), w = a(() => {
606
+ let e = new Set(fe.map((e) => e.commit.id)), t = new Set((g ?? []).map((e) => e.sessionId)), n = [...(y?.edges ?? []).map((e) => ({
607
+ ...e,
608
+ weight: "primary"
609
+ })), ...(b?.edges ?? []).map((e) => ({
610
+ ...e,
611
+ weight: "secondary"
612
+ }))], r = /* @__PURE__ */ new Set();
613
+ return n.flatMap((n) => {
614
+ if (n.ghost) return [];
615
+ let i = `${n.sessionId}:${n.commitHash}`;
616
+ return !e.has(n.commitHash) || !t.has(n.sessionId) || r.has(i) ? [] : (r.add(i), [{
617
+ ...n,
618
+ key: i,
619
+ weight: n.weight
620
+ }]);
621
+ });
622
+ }, [
623
+ fe,
624
+ g,
625
+ y,
626
+ b
627
+ ]), T = o(null), [E, pe] = s([]);
628
+ i(() => {
629
+ let e = T.current;
630
+ if (!e || w.length === 0) {
631
+ pe([]);
632
+ return;
633
+ }
634
+ let t = () => {
635
+ let t = e.querySelector(".cg-history");
636
+ if (!t) return;
637
+ let n = t.getBoundingClientRect(), r = new Map([...e.querySelectorAll("[data-timeline-session-id]")].map((e) => [e.getAttribute("data-timeline-session-id"), e])), i = new Map([...e.querySelectorAll(".cg-history-row[data-commit-hash]")].map((e) => [e.getAttribute("data-commit-hash"), e]));
638
+ pe(w.flatMap((e) => {
639
+ let t = r.get(e.sessionId)?.getBoundingClientRect(), a = i.get(e.commitHash)?.querySelector(".cg-dot")?.getBoundingClientRect();
640
+ return !t || !a ? [] : [{
641
+ ...e,
642
+ geometry: {
643
+ x1: t.left + t.width / 2 - n.left,
644
+ y1: t.bottom - n.top,
645
+ x2: a.left + a.width / 2 - n.left,
646
+ y2: a.top + a.height / 2 - n.top
647
+ }
648
+ }];
649
+ }));
650
+ };
651
+ if (t(), typeof ResizeObserver > "u") return;
652
+ let n = new ResizeObserver(t);
653
+ return n.observe(e), () => n.disconnect();
654
+ }, [w]);
655
+ let D = Xe(C), me = ["cg", h].filter(Boolean).join(" ");
656
+ return e.length === 0 ? /* @__PURE__ */ l("div", {
657
+ className: me,
658
+ ...S,
659
+ children: /* @__PURE__ */ l("p", {
660
+ className: "cg-empty",
661
+ children: "no commits to show."
662
+ })
663
+ }) : /* @__PURE__ */ u("div", {
664
+ ref: T,
665
+ className: me,
666
+ role: "list",
667
+ "aria-label": m,
668
+ ...S,
669
+ children: [
670
+ g && g.length > 0 && /* @__PURE__ */ l("div", {
671
+ className: "cg-session-spine",
672
+ role: "group",
673
+ "aria-label": "recorded sessions",
674
+ style: { gridTemplateColumns: `repeat(${g.length}, minmax(0, 1fr))` },
675
+ children: g.map((e) => /* @__PURE__ */ l(z, {
676
+ sessionId: e.sessionId,
677
+ title: e.title,
678
+ harness: e.harness,
679
+ hovered: ee === e.sessionId,
680
+ selected: _ === e.sessionId,
681
+ onHover: v,
682
+ onSelect: te,
683
+ unresolvedGhosts: e.unresolvedGhosts,
684
+ "data-timeline-session-id": e.sessionId
685
+ }, e.sessionId))
686
+ }),
687
+ /* @__PURE__ */ u("div", {
688
+ className: "cg-history",
689
+ children: [E.length > 0 && /* @__PURE__ */ l("svg", {
690
+ className: "cg-highlight-layer",
691
+ "aria-hidden": "true",
692
+ children: E.map((e) => /* @__PURE__ */ l(V, {
693
+ weight: e.weight,
694
+ geometry: e.geometry,
695
+ "data-session-id": e.sessionId,
696
+ "data-commit-hash": e.commitHash
697
+ }, e.key))
698
+ }), fe.map((e) => /* @__PURE__ */ u("div", {
699
+ className: "cg-history-row",
700
+ "data-commit-hash": e.commit.id,
701
+ children: [/* @__PURE__ */ l(G, {
702
+ row: e,
703
+ width: D,
704
+ selected: e.commit.id === t,
705
+ onNavigate: n,
706
+ onSelect: r,
707
+ onOpenSession: c,
708
+ highlightWeight: ue.has(e.commit.id) ? "primary" : de.has(e.commit.id) ? "secondary" : null,
709
+ expandedSessions: le.has(e.commit.id),
710
+ onToggleSessions: ae,
711
+ touchedFiles: oe?.[e.commit.id] ?? [],
712
+ expandedFiles: le.has(`files:${e.commit.id}`),
713
+ onOpenTouchedFile: se
714
+ }), x?.[e.commit.id] && /* @__PURE__ */ l("div", {
715
+ className: "cg-ghost-row",
716
+ style: { marginLeft: D },
717
+ children: /* @__PURE__ */ l(We, {
718
+ successorHash: e.commit.id,
719
+ ghosts: x[e.commit.id],
720
+ expanded: ce.has(e.commit.id),
721
+ onToggle: re
722
+ })
723
+ })]
724
+ }, e.commit.id))]
725
+ }),
726
+ d && /* @__PURE__ */ u("div", {
727
+ className: "cg-older-band",
728
+ children: [/* @__PURE__ */ l("span", {
729
+ className: "cg-gutter cg-gutter-older",
730
+ style: { width: D },
731
+ "aria-hidden": "true",
732
+ children: /* @__PURE__ */ l("svg", {
733
+ className: "cg-svg",
734
+ width: D,
735
+ height: "100%",
736
+ preserveAspectRatio: "none",
737
+ children: /* @__PURE__ */ l("line", {
738
+ className: "cg-stroke-lane0",
739
+ x1: W(0),
740
+ y1: "0",
741
+ x2: W(0),
742
+ y2: "60%",
743
+ strokeDasharray: Ye
744
+ })
745
+ })
746
+ }), /* @__PURE__ */ u("button", {
747
+ type: "button",
748
+ className: "cg-older",
749
+ onClick: () => {
750
+ n ? n({ type: "show-older" }) : p?.();
751
+ },
752
+ children: [/* @__PURE__ */ l(f, {
753
+ className: "cg-older-ic",
754
+ "aria-hidden": "true"
755
+ }), "show older"]
756
+ })]
757
+ })
758
+ ]
759
+ });
760
+ }
761
+ function G({ row: e, width: t, selected: n, onNavigate: r, onSelect: i, onOpenSession: a, highlightWeight: o = null, expandedSessions: s = !1, onToggleSessions: c, touchedFiles: d = [], expandedFiles: f = !1, onOpenTouchedFile: p }) {
762
+ let { commit: m, lane: h, joins: g, passLanes: ee, laneUp: _, laneDown: te } = e, y = !!m.session, b = [
763
+ "cg-dot",
764
+ y ? "cg-dot-filled" : "cg-dot-hollow",
765
+ n && "cg-dot-sel",
766
+ o && `cg-dot-highlight-${o}`
767
+ ].filter(Boolean).join(" "), x = m.sessionRefs?.slice(0, 2) ?? [], ne = m.sessionRefs?.slice(2) ?? [], ie = ["cg-row", n && "cg-row-sel"].filter(Boolean).join(" ");
768
+ return /* @__PURE__ */ u("div", {
769
+ className: "cg-band",
770
+ role: "listitem",
771
+ children: [/* @__PURE__ */ u("span", {
772
+ className: "cg-gutter",
773
+ style: { width: t },
774
+ "aria-hidden": "true",
775
+ children: [
776
+ /* @__PURE__ */ u("svg", {
777
+ className: "cg-svg",
778
+ width: t,
779
+ height: "100%",
780
+ preserveAspectRatio: "none",
781
+ children: [
782
+ _ && /* @__PURE__ */ l("line", {
783
+ className: "cg-stroke-self",
784
+ x1: W(h),
785
+ y1: "0",
786
+ x2: W(h),
787
+ y2: "50%"
788
+ }),
789
+ te && /* @__PURE__ */ l("line", {
790
+ className: "cg-stroke-self",
791
+ x1: W(h),
792
+ y1: "50%",
793
+ x2: W(h),
794
+ y2: "100%"
795
+ }),
796
+ ee.map((e) => /* @__PURE__ */ l("line", {
797
+ className: e === 0 ? "cg-stroke-lane0" : "cg-stroke-branch",
798
+ x1: W(e),
799
+ y1: "0",
800
+ x2: W(e),
801
+ y2: "100%"
802
+ }, e)),
803
+ g.map((e, t) => /* @__PURE__ */ u("g", {
804
+ className: "cg-elbow",
805
+ children: [/* @__PURE__ */ l("line", {
806
+ className: "cg-stroke-branch",
807
+ x1: W(e.to),
808
+ y1: "50%",
809
+ x2: W(e.to),
810
+ y2: "100%"
811
+ }), /* @__PURE__ */ l("line", {
812
+ className: "cg-stroke-branch",
813
+ x1: W(e.to),
814
+ y1: "50%",
815
+ x2: W(e.from),
816
+ y2: "50%"
817
+ })]
818
+ }, t))
819
+ ]
820
+ }),
821
+ /* @__PURE__ */ l("span", {
822
+ className: b,
823
+ style: {
824
+ left: W(h),
825
+ width: Je,
826
+ height: Je
827
+ },
828
+ "data-has-session": y || void 0
829
+ }),
830
+ y && /* @__PURE__ */ l(re, {
831
+ className: "cg-spark",
832
+ style: { left: W(h) },
833
+ "aria-hidden": "true"
834
+ })
835
+ ]
836
+ }), /* @__PURE__ */ u("div", {
837
+ className: "cg-content",
838
+ children: [
839
+ /* @__PURE__ */ u("button", {
840
+ type: "button",
841
+ className: ie,
842
+ onClick: () => {
843
+ r ? r({
844
+ type: "open-change",
845
+ change: {
846
+ id: m.id,
847
+ branch: m.branch ?? null
848
+ }
849
+ }) : i?.(m);
850
+ },
851
+ children: [/* @__PURE__ */ l("span", {
852
+ className: "cg-msg",
853
+ title: m.message,
854
+ children: m.message
855
+ }), /* @__PURE__ */ u("span", {
856
+ className: "cg-meta",
857
+ children: [
858
+ m.merged && /* @__PURE__ */ u("span", {
859
+ className: "cg-merged",
860
+ children: [/* @__PURE__ */ l(v, {
861
+ className: "cg-merged-ic",
862
+ "aria-hidden": "true"
863
+ }), "merged"]
864
+ }),
865
+ m.tip && /* @__PURE__ */ l("span", {
866
+ className: "cg-tip",
867
+ children: "tip"
868
+ }),
869
+ m.branch && /* @__PURE__ */ l("span", {
870
+ className: "cg-branch",
871
+ children: m.branch
872
+ }),
873
+ y && /* @__PURE__ */ l("span", {
874
+ className: "cg-sr",
875
+ children: "session"
876
+ }),
877
+ m.time && /* @__PURE__ */ l("span", {
878
+ className: "cg-time tnum",
879
+ children: m.time
880
+ })
881
+ ]
882
+ })]
883
+ }),
884
+ m.sessionRefs?.length > 0 && /* @__PURE__ */ u("div", {
885
+ className: "cg-sessions",
886
+ role: "group",
887
+ "aria-label": `sessions linked to ${m.message}`,
888
+ children: [x.map((e) => /* @__PURE__ */ u("button", {
889
+ type: "button",
890
+ className: "cg-session",
891
+ onClick: () => {
892
+ r ? r({
893
+ type: "open-session",
894
+ sessionId: e.sessionId,
895
+ source: {
896
+ kind: "commit",
897
+ commit: {
898
+ id: m.id,
899
+ branch: m.branch ?? null
900
+ }
901
+ }
902
+ }) : a?.(e.sessionId);
903
+ },
904
+ children: [
905
+ /* @__PURE__ */ l(L, { harness: e.harness }),
906
+ /* @__PURE__ */ l("span", {
907
+ className: "cg-session-title",
908
+ children: e.title || e.sessionId
909
+ }),
910
+ e.startMs != null && /* @__PURE__ */ l("time", {
911
+ className: "cg-session-time tnum",
912
+ dateTime: new Date(e.startMs).toISOString(),
913
+ children: new Date(e.startMs).toLocaleDateString(void 0, {
914
+ month: "short",
915
+ day: "numeric"
916
+ }).toLowerCase()
917
+ })
918
+ ]
919
+ }, e.sessionId)), ne.length > 0 && /* @__PURE__ */ l(B, {
920
+ commitHash: m.id,
921
+ overflow: ne,
922
+ expanded: s,
923
+ onToggle: c ?? (() => {}),
924
+ onSelect: (e) => {
925
+ r ? r({
926
+ type: "open-session",
927
+ sessionId: e,
928
+ source: {
929
+ kind: "commit",
930
+ commit: {
931
+ id: m.id,
932
+ branch: m.branch ?? null
933
+ }
934
+ }
935
+ }) : a?.(e);
936
+ }
937
+ })]
938
+ }),
939
+ d.length > 0 && /* @__PURE__ */ l("div", {
940
+ className: "cg-touched-files",
941
+ children: /* @__PURE__ */ l(U, {
942
+ commitHash: `files:${m.id}`,
943
+ files: d,
944
+ expanded: f,
945
+ onToggle: c ?? (() => {}),
946
+ onOpenDiff: p
947
+ })
948
+ })
949
+ ]
950
+ })]
951
+ });
952
+ }
953
+ //#endregion
954
+ //#region src/ui/DiffView.jsx
955
+ function Qe(e) {
956
+ let t = 0, n = 0;
957
+ for (let r of e) for (let e of r.lines) e.type === "add" ? t++ : e.type === "del" && n++;
958
+ return {
959
+ adds: t,
960
+ dels: n
961
+ };
962
+ }
963
+ function $e({ line: e }) {
964
+ let { type: t, oldNo: n, newNo: r, text: i } = e, a = t === "add" ? b : t === "del" ? y : null;
965
+ return /* @__PURE__ */ u("div", {
966
+ className: `dv-line dv-${t}`,
967
+ role: "row",
968
+ children: [
969
+ /* @__PURE__ */ l("span", {
970
+ className: "dv-rail",
971
+ "aria-hidden": "true"
972
+ }),
973
+ /* @__PURE__ */ l("span", {
974
+ className: "dv-num dv-num-old tnum",
975
+ role: "cell",
976
+ children: n ?? ""
977
+ }),
978
+ /* @__PURE__ */ l("span", {
979
+ className: "dv-num dv-num-new tnum",
980
+ role: "cell",
981
+ children: r ?? ""
982
+ }),
983
+ /* @__PURE__ */ l("span", {
984
+ className: "dv-sign",
985
+ role: "cell",
986
+ "aria-hidden": "true",
987
+ children: a ? /* @__PURE__ */ l(a, { "aria-hidden": "true" }) : null
988
+ }),
989
+ /* @__PURE__ */ u("span", {
990
+ className: "dv-text",
991
+ role: "cell",
992
+ children: [/* @__PURE__ */ l("span", {
993
+ className: "dv-sr",
994
+ children: t === "add" ? "added: " : t === "del" ? "removed: " : ""
995
+ }), i || "\xA0"]
996
+ })
997
+ ]
998
+ });
999
+ }
1000
+ function et({ match: e }) {
1001
+ let { category: t, confidence: n, original: r, replacement: i, oldNo: a, newNo: o } = e, [c, d] = s(!1), f = n < .7, p = n.toFixed(2);
1002
+ return /* @__PURE__ */ u("div", {
1003
+ className: `dv-match${c ? " dv-match-kept" : ""}`,
1004
+ children: [/* @__PURE__ */ u("div", {
1005
+ className: "dv-match-head",
1006
+ children: [
1007
+ /* @__PURE__ */ u("span", {
1008
+ className: `dv-badge${f ? " dv-badge-low" : ""}`,
1009
+ children: [
1010
+ /* @__PURE__ */ l("span", {
1011
+ className: "dv-badge-cat",
1012
+ children: t
1013
+ }),
1014
+ /* @__PURE__ */ l("span", {
1015
+ className: "dv-badge-dot",
1016
+ "aria-hidden": "true",
1017
+ children: "·"
1018
+ }),
1019
+ /* @__PURE__ */ l("span", {
1020
+ className: "dv-badge-conf tnum",
1021
+ children: p
1022
+ })
1023
+ ]
1024
+ }),
1025
+ c && /* @__PURE__ */ u("span", {
1026
+ className: "dv-kept-flag",
1027
+ children: [/* @__PURE__ */ l(g, { "aria-hidden": "true" }), "un-redacted"]
1028
+ }),
1029
+ /* @__PURE__ */ u("button", {
1030
+ type: "button",
1031
+ className: "dv-keep",
1032
+ "aria-pressed": c,
1033
+ onClick: () => d((e) => !e),
1034
+ children: [l(c ? h : g, { "aria-hidden": "true" }), c ? "revert" : "keep"]
1035
+ })
1036
+ ]
1037
+ }), /* @__PURE__ */ u("div", {
1038
+ className: "dv-match-pair",
1039
+ role: "rowgroup",
1040
+ children: [/* @__PURE__ */ u("div", {
1041
+ className: `dv-line dv-del${c ? " dv-line-muted" : ""}`,
1042
+ role: "row",
1043
+ children: [
1044
+ /* @__PURE__ */ l("span", {
1045
+ className: "dv-rail",
1046
+ "aria-hidden": "true"
1047
+ }),
1048
+ /* @__PURE__ */ l("span", {
1049
+ className: "dv-num dv-num-old tnum",
1050
+ role: "cell",
1051
+ children: a ?? ""
1052
+ }),
1053
+ /* @__PURE__ */ l("span", {
1054
+ className: "dv-num dv-num-new tnum",
1055
+ role: "cell"
1056
+ }),
1057
+ /* @__PURE__ */ l("span", {
1058
+ className: "dv-sign",
1059
+ role: "cell",
1060
+ "aria-hidden": "true",
1061
+ children: /* @__PURE__ */ l(y, { "aria-hidden": "true" })
1062
+ }),
1063
+ /* @__PURE__ */ u("span", {
1064
+ className: "dv-text",
1065
+ role: "cell",
1066
+ children: [/* @__PURE__ */ l("span", {
1067
+ className: "dv-sr",
1068
+ children: "original: "
1069
+ }), /* @__PURE__ */ l("span", {
1070
+ className: "dv-strike",
1071
+ children: r
1072
+ })]
1073
+ })
1074
+ ]
1075
+ }), /* @__PURE__ */ u("div", {
1076
+ className: `dv-line dv-add${c ? " dv-line-muted" : ""}`,
1077
+ role: "row",
1078
+ children: [
1079
+ /* @__PURE__ */ l("span", {
1080
+ className: "dv-rail",
1081
+ "aria-hidden": "true"
1082
+ }),
1083
+ /* @__PURE__ */ l("span", {
1084
+ className: "dv-num dv-num-old tnum",
1085
+ role: "cell"
1086
+ }),
1087
+ /* @__PURE__ */ l("span", {
1088
+ className: "dv-num dv-num-new tnum",
1089
+ role: "cell",
1090
+ children: o ?? ""
1091
+ }),
1092
+ /* @__PURE__ */ l("span", {
1093
+ className: "dv-sign",
1094
+ role: "cell",
1095
+ "aria-hidden": "true",
1096
+ children: /* @__PURE__ */ l(b, { "aria-hidden": "true" })
1097
+ }),
1098
+ /* @__PURE__ */ u("span", {
1099
+ className: "dv-text",
1100
+ role: "cell",
1101
+ children: [/* @__PURE__ */ l("span", {
1102
+ className: "dv-sr",
1103
+ children: "redacted to: "
1104
+ }), i]
1105
+ })
1106
+ ]
1107
+ })]
1108
+ })]
1109
+ });
1110
+ }
1111
+ function tt({ file: e, hunks: t = [], matches: n = [], variant: r = "default", className: i = "", ...a }) {
1112
+ let o = r === "redaction", s = o ? null : Qe(t);
1113
+ return /* @__PURE__ */ u("figure", {
1114
+ className: [
1115
+ "dv",
1116
+ o && "dv-redaction",
1117
+ i
1118
+ ].filter(Boolean).join(" "),
1119
+ ...a,
1120
+ children: [/* @__PURE__ */ u("figcaption", {
1121
+ className: "dv-head",
1122
+ children: [/* @__PURE__ */ l("span", {
1123
+ className: "dv-file",
1124
+ children: e
1125
+ }), o ? /* @__PURE__ */ u("span", {
1126
+ className: "dv-churn",
1127
+ children: [/* @__PURE__ */ l("span", {
1128
+ className: "dv-churn-r tnum",
1129
+ children: n.length
1130
+ }), /* @__PURE__ */ l("span", {
1131
+ className: "dv-churn-label",
1132
+ children: "redacted"
1133
+ })]
1134
+ }) : /* @__PURE__ */ u("span", {
1135
+ className: "dv-churn",
1136
+ children: [/* @__PURE__ */ u("span", {
1137
+ className: "dv-churn-add tnum",
1138
+ children: ["+", s.adds]
1139
+ }), /* @__PURE__ */ u("span", {
1140
+ className: "dv-churn-del tnum",
1141
+ children: ["−", s.dels]
1142
+ })]
1143
+ })]
1144
+ }), o ? /* @__PURE__ */ l("div", {
1145
+ className: "dv-body dv-matches",
1146
+ role: "table",
1147
+ "aria-label": `redactions in ${e}`,
1148
+ children: n.length === 0 ? /* @__PURE__ */ l("p", {
1149
+ className: "dv-empty",
1150
+ children: "no sensitive content detected. safe to share as-is."
1151
+ }) : n.map((e, t) => /* @__PURE__ */ l(et, { match: e }, e.id ?? t))
1152
+ }) : /* @__PURE__ */ l("div", {
1153
+ className: "dv-body",
1154
+ role: "table",
1155
+ "aria-label": `diff of ${e}`,
1156
+ children: t.length === 0 ? /* @__PURE__ */ l("p", {
1157
+ className: "dv-empty",
1158
+ children: "no line changes."
1159
+ }) : t.map((e, t) => /* @__PURE__ */ u("div", {
1160
+ className: "dv-hunk",
1161
+ children: [/* @__PURE__ */ u("div", {
1162
+ className: "dv-hunk-head",
1163
+ children: [
1164
+ /* @__PURE__ */ l("span", {
1165
+ className: "dv-hunk-at",
1166
+ "aria-hidden": "true",
1167
+ children: "@@"
1168
+ }),
1169
+ /* @__PURE__ */ l("span", {
1170
+ className: "dv-hunk-range tnum",
1171
+ children: e.header
1172
+ }),
1173
+ /* @__PURE__ */ l("span", {
1174
+ className: "dv-hunk-at",
1175
+ "aria-hidden": "true",
1176
+ children: "@@"
1177
+ })
1178
+ ]
1179
+ }), /* @__PURE__ */ l("div", {
1180
+ className: "dv-hunk-pair",
1181
+ role: "rowgroup",
1182
+ children: e.lines.map((e, t) => /* @__PURE__ */ l($e, { line: e }, t))
1183
+ })]
1184
+ }, t))
1185
+ })]
1186
+ });
1187
+ }
1188
+ //#endregion
1189
+ //#region src/ui/graph/types.js
1190
+ var nt = C, rt = se, it = ce, at = le, ot = S;
1191
+ function K(e, t, n, r, i) {
1192
+ if (e(t)) return;
1193
+ let a;
1194
+ try {
1195
+ a = JSON.stringify(t);
1196
+ } catch {
1197
+ a = String(t);
1198
+ }
1199
+ throw TypeError(`Graph contract validation failed for ${a} at src/ui/graph/types.js during ${r}: ${n} is outside the canonical @peasant-labs/schema value domain (${i.join(", ")}), so Fairtrade cannot safely render this graph payload; the caller must validate and normalize the local API response before passing it to the cooked graph surface.`);
1200
+ }
1201
+ function q(e) {
1202
+ for (let [t, n] of e.nodes.entries()) K(ve, n.kind, `nodes[${t}].kind`, "code-map payload rendering", C);
1203
+ for (let [t, n] of e.violations.entries()) K(D, n.kind, `violations[${t}].kind`, "code-map payload rendering", ce);
1204
+ }
1205
+ function st(e) {
1206
+ for (let [t, n] of e.files.entries()) K(me, n.status, `files[${t}].status`, "change-detail payload rendering", le);
1207
+ for (let [t, n] of e.work.entries()) K(E, n.binding, `work[${t}].binding`, "change-detail payload rendering", se);
1208
+ for (let [t, n] of e.slice.nodes.entries()) K(ve, n.kind, `slice.nodes[${t}].kind`, "change-detail payload rendering", C);
1209
+ for (let [t, n] of e.violations.entries()) K(D, n.kind, `violations[${t}].kind`, "change-detail payload rendering", ce);
1210
+ }
1211
+ function ct(e) {
1212
+ K(me, e.status, "status", "change-diff payload rendering", le);
1213
+ for (let [t, n] of e.hunks.entries()) for (let [e, r] of n.lines.entries()) K(pe, r.kind, `hunks[${t}].lines[${e}].kind`, "change-diff payload rendering", S);
1214
+ }
1215
+ //#endregion
1216
+ //#region src/ui/graph/graphContractPolicy.js
1217
+ var J = Object.freeze({
1218
+ decision: "decisions",
1219
+ friction: "friction",
1220
+ unusual: "unusual signals",
1221
+ retry_loop: "retry loops"
1222
+ }), lt = Object.freeze({
1223
+ mechanical: Object.freeze({ markerClass: "tlp-insight-provenance-mechanical" }),
1224
+ mined: Object.freeze({ markerClass: "tlp-insight-provenance-mined" })
1225
+ });
1226
+ ft(), pt();
1227
+ function ut(e) {
1228
+ let t = e.findIndex((e) => !ge(e.kind) || !_e(e.provenance));
1229
+ if (t !== -1) throw mt("validate insight values", `insights[${t}]`, `the insight kind or provenance is outside the canonical @peasant-labs/schema value domain (kinds: ${ue.join(", ")}; provenances: ${de.join(", ")})`, "validate and normalize the local API response to the published @peasant-labs/schema contract before rendering");
1230
+ }
1231
+ function dt(e) {
1232
+ let t = e.findIndex((e) => !ye(e.readAttribution) || !be(e.readState));
1233
+ if (t !== -1) throw mt("validate ranking values", `nodes[${t}]`, `the read-attribution state or read-state grade is outside the canonical @peasant-labs/schema value domain (attribution states: ${fe.join(", ")}; read-state grades: ${w.join(", ")})`, "validate and normalize the local API response to the published @peasant-labs/schema contract before ranking");
1234
+ }
1235
+ function ft() {
1236
+ let e = Object.keys(J), t = ue.filter((e) => typeof J[e] != "string" || J[e].trim() === ""), n = e.filter((e) => !ge(e));
1237
+ if (!(t.length === 0 && n.length === 0 && e.length === ue.length)) throw mt("validate insight labels", "INSIGHT_KIND_LABELS", `the Fairtrade label map does not exactly cover the canonical @peasant-labs/schema insight kinds (missing: ${t.join(", ") || "none"}; unknown: ${n.join(", ") || "none"})`, "add one non-empty Fairtrade UI label for each published insight kind and remove labels that are no longer in the schema contract");
1238
+ }
1239
+ function pt() {
1240
+ let e = Object.keys(lt), t = de.filter((e) => {
1241
+ let t = lt[e];
1242
+ return !t || typeof t.markerClass != "string" || t.markerClass.trim() === "";
1243
+ }), n = e.filter((e) => !_e(e));
1244
+ if (!(t.length === 0 && n.length === 0 && e.length === de.length)) throw mt("validate insight provenance presentations", "INSIGHT_PROVENANCE_PRESENTATIONS", `the Fairtrade provenance presentation map does not exactly cover the canonical @peasant-labs/schema insight provenances (missing: ${t.join(", ") || "none"}; unknown: ${n.join(", ") || "none"})`, "add one explicit Fairtrade marker class for each published insight provenance and remove presentations that are no longer in the schema contract");
1245
+ }
1246
+ function mt(e, t, n, r) {
1247
+ return /* @__PURE__ */ Error(`Fairtrade graph contract ${e} failed: what went wrong: invalid ${t}; why: ${n}; where: src/ui/graph/graphContractPolicy.js ${t}; when: ${e}; what it means: Fairtrade cannot render the graph value without guessing; how to fix: ${r}.`);
1248
+ }
1249
+ //#endregion
1250
+ //#region src/ui/graph/ranking.js
1251
+ var ht = Object.freeze({
1252
+ touch: .35,
1253
+ effortDensity: .25,
1254
+ debt: .25,
1255
+ recency: .15
1256
+ }), gt = .5, _t = .9, vt = 14, yt = 5, bt = 25, xt = Object.freeze([
1257
+ "agent wrote: no recorded read",
1258
+ "agent wrote: viewed, not reviewed",
1259
+ "agent wrote: read state unknown",
1260
+ "heavy churn",
1261
+ "edited this session",
1262
+ "high effort density",
1263
+ "near your focus"
1264
+ ]), St = .75, Ct = .75, wt = 1, Tt = /* @__PURE__ */ new Set([
1265
+ "relevance",
1266
+ "debt",
1267
+ "churn"
1268
+ ]), Et = "Use this as a prompt to inspect recorded evidence, not as a verdict about the reader.";
1269
+ function Dt(e) {
1270
+ if (e.agentEditedCount === 0) return "none";
1271
+ if (e.readAttribution === "unavailable") return "unknown";
1272
+ let t = e.changedRegionCount > e.attributedRegionCount, n = e.attributedRegionCount > 0 ? e.reviewedRegionCount / e.attributedRegionCount : 0, r = e.attributedRegionCount > 0 && n === 1 && !t;
1273
+ return e.readState === "reviewed" || e.readState === "reviewed_in_detail" || r ? "reviewed" : e.attributedRegionCount > 0 && e.reviewedRegionCount > 0 ? "partial-read" : e.readState === "viewed" ? "viewed" : e.readCount === 0 ? "no-recorded-read" : "partial-read";
1274
+ }
1275
+ function Ot(e, t) {
1276
+ if (t === "no-recorded-read") return 1;
1277
+ if (t === "partial-read") {
1278
+ if (e.attributedRegionCount > 0) {
1279
+ let t = kt(e), n = e.agentEditedCount > 0 ? e.readCount / e.agentEditedCount : 0;
1280
+ return Rt(1 - Math.max(t, n));
1281
+ }
1282
+ return Rt(1 - (e.agentEditedCount > 0 ? e.readCount / e.agentEditedCount : 0));
1283
+ }
1284
+ return t === "viewed" ? gt : 0;
1285
+ }
1286
+ function kt(e) {
1287
+ let t = e.changedRegionCount > e.attributedRegionCount, n = e.attributedRegionCount > 0 ? e.reviewedRegionCount / e.attributedRegionCount : 0;
1288
+ return Rt(t ? Math.min(n, _t) : n);
1289
+ }
1290
+ function At(e) {
1291
+ let t = e.changedRegionCount > e.attributedRegionCount, n = e.attributedRegionCount > 0 ? e.reviewedRegionCount / e.attributedRegionCount : 0;
1292
+ return e.attributedRegionCount > 0 && n === 1 && !t;
1293
+ }
1294
+ function jt(e) {
1295
+ if (Dt(e) !== "partial-read") return null;
1296
+ let t = e.attributedRegionCount;
1297
+ if (t > 0 && e.reviewedRegionCount > 0) {
1298
+ let n = e.reviewedRegionCount, r = t;
1299
+ return e.changedRegionCount > t ? `${n} of ${r} attributed regions reviewed; ${e.changedRegionCount - t} regions could not be attributed` : `${n} of ${r} changed regions reviewed`;
1300
+ }
1301
+ return "some sessions that edited this file were read; per-region coverage is not available";
1302
+ }
1303
+ function Mt(e, t) {
1304
+ if (t === "no-recorded-read") return `No read evidence was recorded for sessions that edited this file. ${Et}`;
1305
+ if (t === "viewed") return `A view was recorded, but no explicit review was recorded. ${Et}`;
1306
+ if (t === "unknown") return `No read events were recorded for the sessions that edited this file, so its read state is unknown. ${Et}`;
1307
+ if (t === "partial-read") {
1308
+ let t = jt(e);
1309
+ return t ? `${t}. ${Et}` : Et;
1310
+ }
1311
+ return null;
1312
+ }
1313
+ function Nt(e, t, n = {}) {
1314
+ let r = [];
1315
+ if (t === "no-recorded-read" ? r.push("agent wrote: no recorded read") : t === "unknown" ? r.push("agent wrote: read state unknown") : (t === "viewed" || t === "partial-read") && r.push("agent wrote: viewed, not reviewed"), n.hoveredOrSelectedSessionId && e.recentSessionId === n.hoveredOrSelectedSessionId && r.length < 2 && r.push("edited this session"), n.maxTouch && n.maxTouch > 0 && e.touchCount / n.maxTouch >= St && r.length < 2 && r.push("heavy churn"), e.effortDensity >= Ct && r.length < 2 && r.push("high effort density"), n.focusId && n.parentOf) {
1316
+ let t = n.distanceToFocus === void 0 ? Pt(e.id, n.focusId, n.parentOf) : n.distanceToFocus;
1317
+ t !== null && t <= wt && r.length < 2 && r.push("near your focus");
1318
+ }
1319
+ return r.slice(0, 2);
1320
+ }
1321
+ function Pt(e, t, n) {
1322
+ if (e === t) return 0;
1323
+ let r = Ft(e, n), i = Ft(t, n), a = new Map(r.map((e, t) => [e, t]));
1324
+ for (let [e, t] of i.entries()) if (a.has(t)) return (a.get(t) ?? 0) + e;
1325
+ return null;
1326
+ }
1327
+ function Ft(e, t) {
1328
+ let n = [e], r = t.get(e) ?? null, i = 0;
1329
+ for (; r && i < 1e4;) n.push(r), r = t.get(r) ?? null, i += 1;
1330
+ return n;
1331
+ }
1332
+ function It(e) {
1333
+ let t = Math.min(...e), n = Math.max(...e);
1334
+ return !Number.isFinite(t) || !Number.isFinite(n) || n === t ? e.map(() => 0) : e.map((e) => (e - t) / (n - t));
1335
+ }
1336
+ function Lt(e, t) {
1337
+ return e.lastTouchMs == null || !Number.isFinite(t) ? 0 : Rt(.5 ** (Math.max(0, t - e.lastTouchMs) / (336 * 60 * 60 * 1e3)));
1338
+ }
1339
+ function Rt(e) {
1340
+ return Math.round(Math.max(0, Math.min(1, e)) * 1e9) / 1e9;
1341
+ }
1342
+ function zt(e) {
1343
+ if (e === "relevance") return ht;
1344
+ let t = e === "debt" ? "debt" : "touch", n = Object.keys(ht).filter((e) => e !== t), r = n.reduce((e, t) => e + ht[t], 0), i = r > 0 ? .3 / r : 0, a = { [t]: .7 };
1345
+ for (let e of n) a[e] = ht[e] * i;
1346
+ return a;
1347
+ }
1348
+ function Bt(e) {
1349
+ return e === "no-recorded-read" || e === "partial-read" || e === "viewed" ? 0 : e === "unknown" ? 1 : 2;
1350
+ }
1351
+ function Vt(e, t = {}) {
1352
+ let n = t.rankMode ?? "relevance";
1353
+ if (!Tt.has(n)) throw Kt("compute intrinsic ranking", "rankMode", `value ${JSON.stringify(n)} is unsupported`, "use relevance, debt, or churn");
1354
+ dt(e);
1355
+ let r = t.nowMs ?? Date.now(), i = zt(n), a = new Map(e.map((e) => [e.id, e.parent ?? null])), o = e.reduce((e, t) => Math.max(e, t.touchCount), 0), s = It(e.map((e) => Math.log1p(Math.max(0, e.touchCount))));
1356
+ return {
1357
+ rankMode: n,
1358
+ rows: e.map((e, t) => {
1359
+ let n = Dt(e), a = Ot(e, n);
1360
+ return {
1361
+ node: e,
1362
+ intrinsic: i.touch * s[t] + i.effortDensity * Rt(e.effortDensity) + i.debt * a + i.recency * Lt(e, r),
1363
+ debtState: n,
1364
+ debt: a,
1365
+ coverage: kt(e),
1366
+ hunkClears: At(e),
1367
+ hoverText: Mt(e, n)
1368
+ };
1369
+ }),
1370
+ parentOf: a,
1371
+ maxTouch: o
1372
+ };
1373
+ }
1374
+ function Ht(e, t = {}) {
1375
+ if (t.scentFilter != null && !xt.includes(t.scentFilter)) throw Kt("derive ranked rows", "scentFilter", `value ${JSON.stringify(t.scentFilter)} is unsupported`, `use null or one of ${xt.join(", ")}`);
1376
+ let { rankMode: n, parentOf: r, maxTouch: i } = e, a = t.focusId ? Ut(t.focusId, r) : null, o = e.rows.map((e) => {
1377
+ let { node: n } = e, o = 0;
1378
+ if (t.focusId) {
1379
+ let e = a?.get(n.id) ?? null;
1380
+ o = e === null ? 0 : Math.min(1, e / 4) * .5;
1381
+ }
1382
+ return {
1383
+ id: n.id,
1384
+ name: n.name,
1385
+ doi: Rt(e.intrinsic - o),
1386
+ debtState: e.debtState,
1387
+ debt: e.debt,
1388
+ coverage: e.coverage,
1389
+ hunkClears: e.hunkClears,
1390
+ scentTags: Nt(n, e.debtState, {
1391
+ focusId: t.focusId,
1392
+ parentOf: r,
1393
+ distanceToFocus: a?.get(n.id) ?? null,
1394
+ maxTouch: i,
1395
+ hoveredOrSelectedSessionId: t.hoveredOrSelectedSessionId
1396
+ }),
1397
+ hoverText: e.hoverText
1398
+ };
1399
+ });
1400
+ o.sort((e, t) => {
1401
+ if (n === "debt") {
1402
+ let n = Bt(e.debtState) - Bt(t.debtState);
1403
+ if (n !== 0) return n;
1404
+ }
1405
+ return t.doi - e.doi || (e.id < t.id ? -1 : +(e.id > t.id));
1406
+ });
1407
+ let s = t.scentFilter;
1408
+ return s ? o.filter((e) => e.scentTags.includes(s)) : o;
1409
+ }
1410
+ function Ut(e, t) {
1411
+ let n = /* @__PURE__ */ new Map();
1412
+ for (let [e, r] of t) {
1413
+ if (n.has(e) || n.set(e, []), !r) continue;
1414
+ let t = n.get(r) ?? [];
1415
+ t.push(e), n.set(r, t), n.get(e)?.push(r);
1416
+ }
1417
+ let r = /* @__PURE__ */ new Map();
1418
+ if (!n.has(e)) return r;
1419
+ let i = [e];
1420
+ r.set(e, 0);
1421
+ for (let e = 0; e < i.length; e += 1) {
1422
+ let t = i[e], a = (r.get(t) ?? 0) + 1;
1423
+ for (let e of n.get(t) ?? []) r.has(e) || (r.set(e, a), i.push(e));
1424
+ }
1425
+ return r;
1426
+ }
1427
+ function Wt(e, t = {}) {
1428
+ return Ht(Vt(e, t), t);
1429
+ }
1430
+ function Gt(e, t = {}) {
1431
+ let n = e.reduce((e, t) => Math.max(e, t.doi), 0), r = Math.max(.25, .5 * n), i = new Set(e.filter((e) => e.doi >= r).map((e) => e.id)), a = t.rankMode === "debt" ? new Set(e.filter((e) => Bt(e.debtState) === 0).map((e) => e.id)) : /* @__PURE__ */ new Set(), o = e.filter((e) => i.has(e.id) || a.has(e.id));
1432
+ o.length < 5 && (o = e.slice(0, Math.min(5, e.length)));
1433
+ let s = o.slice(0, 25);
1434
+ return {
1435
+ visible: t.expanded ? e : s,
1436
+ total: e.length,
1437
+ overflowCount: t.expanded ? 0 : Math.max(0, e.length - s.length)
1438
+ };
1439
+ }
1440
+ function Kt(e, t, n, r) {
1441
+ return /* @__PURE__ */ Error(`Code map ranking ${e} failed: what went wrong: invalid ${t}; why: ${n}; where: src/ui/graph/ranking.js ${t}; when: ${e}; what it means: the ranked list cannot be derived safely; how to fix: ${r}.`);
1442
+ }
1443
+ //#endregion
1444
+ //#region src/ui/graph/codeMapState.js
1445
+ var qt = 1, Y = Object.freeze({
1446
+ min: .35,
1447
+ max: 2.4
1448
+ });
1449
+ function Jt(e) {
1450
+ return typeof e == "number" && Number.isFinite(e) && e >= Y.min && e <= Y.max;
1451
+ }
1452
+ var Yt = Object.freeze({
1453
+ version: 1,
1454
+ presentation: "navigator",
1455
+ selectedId: null,
1456
+ grain: "package",
1457
+ expandedIds: Object.freeze([]),
1458
+ navigatorFilter: "",
1459
+ navigatorFocusedId: null,
1460
+ viewport: null,
1461
+ hoveredSessionId: null,
1462
+ selectedSessionId: null,
1463
+ expandedCommitSessions: Object.freeze([]),
1464
+ expandedGhostGroups: Object.freeze([]),
1465
+ rankMode: "relevance",
1466
+ scentFilter: null
1467
+ }), Xt = /* @__PURE__ */ new Set(["navigator", "canvas"]), Zt = /* @__PURE__ */ new Set([
1468
+ "project",
1469
+ "package",
1470
+ "file"
1471
+ ]), Qt = /* @__PURE__ */ new Set([
1472
+ "relevance",
1473
+ "debt",
1474
+ "churn"
1475
+ ]), $t = new Set(xt), en = Object.freeze({
1476
+ project: 0,
1477
+ package: 1,
1478
+ file: 1
1479
+ }), tn = en, nn = Object.freeze([
1480
+ "version",
1481
+ "presentation",
1482
+ "selectedId",
1483
+ "grain",
1484
+ "expandedIds",
1485
+ "navigatorFilter",
1486
+ "navigatorFocusedId",
1487
+ "viewport",
1488
+ "hoveredSessionId",
1489
+ "selectedSessionId",
1490
+ "expandedCommitSessions",
1491
+ "expandedGhostGroups",
1492
+ "rankMode",
1493
+ "scentFilter"
1494
+ ]), rn = Object.freeze({
1495
+ replace: ["type", "state"],
1496
+ hydrate: ["type", "state"],
1497
+ "set-presentation": ["type", "presentation"],
1498
+ select: ["type", "id"],
1499
+ "clear-selection": ["type"],
1500
+ focus: ["type", "id"],
1501
+ "set-filter": ["type", "filter"],
1502
+ "set-expanded": ["type", "ids"],
1503
+ "toggle-expanded": ["type", "id"],
1504
+ "set-grain": ["type", "grain"],
1505
+ "set-viewport": ["type", "viewport"],
1506
+ "open-in-map": ["type", "id"],
1507
+ reveal: [
1508
+ "type",
1509
+ "id",
1510
+ "grain",
1511
+ "expandedIds"
1512
+ ],
1513
+ "hover-session": ["type", "sessionId"],
1514
+ "select-session": ["type", "sessionId"],
1515
+ "toggle-commit-sessions": ["type", "commitHash"],
1516
+ "toggle-ghost-group": ["type", "successorHash"],
1517
+ "set-rank-mode": ["type", "rankMode"],
1518
+ "set-scent-filter": ["type", "scentFilter"],
1519
+ "set-rank-expanded": ["type", "expanded"]
1520
+ });
1521
+ function X(e = null) {
1522
+ if (e !== null && !pn(e)) throw Z("create state", "seed", "the seed is not an object", "pass an object or omit the seed");
1523
+ let t = e ?? {};
1524
+ if (mn(t, nn, "create state", "seed"), t.version !== void 0 && t.version !== 1) throw Z("create state", "version", `version ${String(t.version)} is unsupported`, "use version 1");
1525
+ return {
1526
+ version: 1,
1527
+ presentation: Tn(t.presentation, Xt, Yt.presentation, "presentation"),
1528
+ selectedId: vn(t.selectedId, "selectedId"),
1529
+ grain: Tn(t.grain, Zt, Yt.grain, "grain"),
1530
+ expandedIds: yn(t.expandedIds, "expandedIds"),
1531
+ navigatorFilter: Cn(t.navigatorFilter, "", "navigatorFilter"),
1532
+ navigatorFocusedId: vn(t.navigatorFocusedId, "navigatorFocusedId"),
1533
+ viewport: Dn(t.viewport),
1534
+ hoveredSessionId: vn(t.hoveredSessionId, "hoveredSessionId"),
1535
+ selectedSessionId: vn(t.selectedSessionId, "selectedSessionId"),
1536
+ expandedCommitSessions: yn(t.expandedCommitSessions, "expandedCommitSessions"),
1537
+ expandedGhostGroups: yn(t.expandedGhostGroups, "expandedGhostGroups"),
1538
+ rankMode: Tn(t.rankMode, Qt, Yt.rankMode, "rankMode"),
1539
+ scentFilter: An(t.scentFilter)
1540
+ };
1541
+ }
1542
+ function an(e, t) {
1543
+ let n = X(e), r = X(t);
1544
+ return n.version === r.version && n.presentation === r.presentation && n.selectedId === r.selectedId && n.grain === r.grain && n.expandedIds.length === r.expandedIds.length && n.expandedIds.every((e, t) => e === r.expandedIds[t]) && n.navigatorFilter === r.navigatorFilter && n.navigatorFocusedId === r.navigatorFocusedId && kn(n.viewport, r.viewport) && n.hoveredSessionId === r.hoveredSessionId && n.selectedSessionId === r.selectedSessionId && on(n.expandedCommitSessions, r.expandedCommitSessions) && on(n.expandedGhostGroups, r.expandedGhostGroups) && n.rankMode === r.rankMode && n.scentFilter === r.scentFilter;
1545
+ }
1546
+ function on(e, t) {
1547
+ return e.length === t.length && e.every((e, n) => e === t[n]);
1548
+ }
1549
+ function sn(e, t) {
1550
+ let n = X(e);
1551
+ switch (fn(t), t.type) {
1552
+ case "replace":
1553
+ case "hydrate": return X(t.state);
1554
+ case "set-presentation": return X({
1555
+ ...n,
1556
+ presentation: En(t.presentation, Xt, "presentation")
1557
+ });
1558
+ case "select": return X({
1559
+ ...n,
1560
+ selectedId: Q(t.id, "id"),
1561
+ navigatorFocusedId: Q(t.id, "id")
1562
+ });
1563
+ case "clear-selection": return X({
1564
+ ...n,
1565
+ selectedId: null
1566
+ });
1567
+ case "focus": return X({
1568
+ ...n,
1569
+ navigatorFocusedId: vn(t.id, "id")
1570
+ });
1571
+ case "set-filter": return X({
1572
+ ...n,
1573
+ navigatorFilter: Cn(t.filter, "", "filter")
1574
+ });
1575
+ case "set-expanded": return X({
1576
+ ...n,
1577
+ expandedIds: yn(t.ids, "ids")
1578
+ });
1579
+ case "toggle-expanded": {
1580
+ let e = Q(t.id, "id"), r = new Set(n.expandedIds);
1581
+ return r.has(e) ? r.delete(e) : r.add(e), X({
1582
+ ...n,
1583
+ expandedIds: [...r]
1584
+ });
1585
+ }
1586
+ case "set-grain": return X({
1587
+ ...n,
1588
+ grain: En(t.grain, Zt, "grain"),
1589
+ expandedIds: []
1590
+ });
1591
+ case "set-viewport": return X({
1592
+ ...n,
1593
+ viewport: Dn(t.viewport)
1594
+ });
1595
+ case "open-in-map": {
1596
+ let e = Q(t.id, "id");
1597
+ return X({
1598
+ ...n,
1599
+ presentation: "canvas",
1600
+ selectedId: e,
1601
+ navigatorFocusedId: e
1602
+ });
1603
+ }
1604
+ case "reveal": {
1605
+ let e = Q(t.id, "id");
1606
+ return X({
1607
+ ...n,
1608
+ grain: En(t.grain, Zt, "grain"),
1609
+ expandedIds: yn(t.expandedIds, "expandedIds"),
1610
+ selectedId: e,
1611
+ navigatorFocusedId: e
1612
+ });
1613
+ }
1614
+ case "hover-session": return X({
1615
+ ...n,
1616
+ hoveredSessionId: _n(t.sessionId, "sessionId")
1617
+ });
1618
+ case "select-session": return X({
1619
+ ...n,
1620
+ selectedSessionId: _n(t.sessionId, "sessionId")
1621
+ });
1622
+ case "toggle-commit-sessions": {
1623
+ let e = Q(t.commitHash, "commitHash"), r = new Set(n.expandedCommitSessions);
1624
+ return r.has(e) ? r.delete(e) : r.add(e), X({
1625
+ ...n,
1626
+ expandedCommitSessions: [...r]
1627
+ });
1628
+ }
1629
+ case "toggle-ghost-group": {
1630
+ let e = Q(t.successorHash, "successorHash"), r = new Set(n.expandedGhostGroups);
1631
+ return r.has(e) ? r.delete(e) : r.add(e), X({
1632
+ ...n,
1633
+ expandedGhostGroups: [...r]
1634
+ });
1635
+ }
1636
+ case "set-rank-mode": return X({
1637
+ ...n,
1638
+ rankMode: En(t.rankMode, Qt, "rankMode")
1639
+ });
1640
+ case "set-scent-filter": return X({
1641
+ ...n,
1642
+ scentFilter: jn(t.scentFilter, "scentFilter")
1643
+ });
1644
+ case "set-rank-expanded": {
1645
+ let e = wn(t.expanded, "expanded"), r = new Set(n.expandedCommitSessions);
1646
+ return e ? r.add("ranked:all") : r.delete("ranked:all"), X({
1647
+ ...n,
1648
+ expandedCommitSessions: [...r]
1649
+ });
1650
+ }
1651
+ default: throw Z("reduce state", "action.type", "the action is unsupported", "use a documented CodeMapAction");
1652
+ }
1653
+ }
1654
+ function cn(e, t) {
1655
+ let n = X(t), r = un(e), i = (e) => {
1656
+ if (!e) return {
1657
+ sessionId: null,
1658
+ commitHashes: [],
1659
+ ghostHashes: [],
1660
+ edges: []
1661
+ };
1662
+ let t = r.filter((t) => t.sessionId === e);
1663
+ return {
1664
+ sessionId: e,
1665
+ commitHashes: [...new Set(t.filter((e) => !e.ghost).map((e) => e.commitHash))].sort(gn),
1666
+ ghostHashes: [...new Set(t.filter((e) => e.ghost).map((e) => e.commitHash))].sort(gn),
1667
+ edges: t.map((e) => ({ ...e }))
1668
+ };
1669
+ };
1670
+ return {
1671
+ selected: i(n.selectedSessionId),
1672
+ hovered: i(n.hoveredSessionId)
1673
+ };
1674
+ }
1675
+ function ln(e) {
1676
+ let t = X(e);
1677
+ return t.hoveredSessionId === null ? t.selectedSessionId === null ? null : {
1678
+ type: "select-session",
1679
+ sessionId: null
1680
+ } : {
1681
+ type: "hover-session",
1682
+ sessionId: null
1683
+ };
1684
+ }
1685
+ function un(e) {
1686
+ let t = e?.edges ?? [];
1687
+ if (!Array.isArray(t)) throw Z("derive timeline highlight", "payload.edges", "edges is not an array", "provide a payload with an edges array");
1688
+ return t.map((e, t) => {
1689
+ if (!pn(e)) throw Z("derive timeline highlight", `payload.edges[${t}]`, "the edge is not an object", "provide an edge object");
1690
+ return {
1691
+ sessionId: Q(e.sessionId, `payload.edges[${t}].sessionId`),
1692
+ commitHash: Q(e.commitHash, `payload.edges[${t}].commitHash`),
1693
+ ghost: e.ghost === !0
1694
+ };
1695
+ });
1696
+ }
1697
+ function dn(e, t) {
1698
+ e && q(e);
1699
+ let n = X(t), r = e?.nodes ?? [];
1700
+ if (!Array.isArray(r)) throw Z("derive view", "payload.nodes", "nodes is not an array", "provide a CodeMapPayload with a nodes array");
1701
+ let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
1702
+ r.forEach((e, t) => {
1703
+ if (!pn(e)) throw Z("derive view", `payload.nodes[${t}]`, "the node is not an object", "provide a node object");
1704
+ let n = Q(e.id, `payload.nodes[${t}].id`);
1705
+ if (i.has(n)) throw Z("derive view", `payload.nodes[${t}].id`, `duplicate node id ${JSON.stringify(n)}`, "give every node one unique nonempty id");
1706
+ let r = {
1707
+ ...e,
1708
+ id: n
1709
+ };
1710
+ r.parent !== void 0 && r.parent !== null && r.parent !== "" ? r.parent = Q(r.parent, `payload.nodes[${t}].parent`) : delete r.parent, i.set(n, r), a.set(n, t);
1711
+ });
1712
+ for (let e of i.values()) if (e.parent && !i.has(e.parent)) throw Z("derive view", `node ${JSON.stringify(e.id)} parent`, `parent ${JSON.stringify(e.parent)} does not exist`, "add the parent node or remove the parent reference to make this node a root");
1713
+ let o = /* @__PURE__ */ new Map(), s = [];
1714
+ for (let e of i.values()) if (e.parent) {
1715
+ let t = o.get(e.parent) ?? [];
1716
+ t.push(e), o.set(e.parent, t);
1717
+ } else s.push(e);
1718
+ let c = (e, t) => (Number.isFinite(e.order) ? Number(e.order) : a.get(e.id) ?? 0) - (Number.isFinite(t.order) ? Number(t.order) : a.get(t.id) ?? 0) || gn(e.id, t.id);
1719
+ s.sort(c);
1720
+ for (let e of o.values()) e.sort(c);
1721
+ let l = /* @__PURE__ */ new Map(), u = [], d = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set();
1722
+ function p(e, t) {
1723
+ if (d.has(e.id)) throw Z("derive view", `node ${JSON.stringify(e.id)}`, "the parent graph contains a cycle", "remove the cyclic parent reference");
1724
+ if (!f.has(e.id)) {
1725
+ d.add(e.id), u.push(e.id), l.set(e.id, t);
1726
+ for (let n of o.get(e.id) ?? []) p(n, t + 1);
1727
+ d.delete(e.id), f.add(e.id);
1728
+ }
1729
+ }
1730
+ for (let e of s) p(e, 0);
1731
+ if (f.size !== i.size) {
1732
+ let e = [...i.keys()].find((e) => !f.has(e)), t = e ? i.get(e) : void 0;
1733
+ t && p(t, 0);
1734
+ }
1735
+ let m = new Set(n.expandedIds.filter((e) => i.has(e))), h = n.navigatorFilter.trim().toLowerCase(), g = /* @__PURE__ */ new Set();
1736
+ if (h) for (let e of i.values()) {
1737
+ if (!e.id.toLowerCase().includes(h) && !String(e.name ?? "").toLowerCase().includes(h)) continue;
1738
+ let t = e;
1739
+ for (; t;) g.add(t.id), t = t.parent ? i.get(t.parent) : null;
1740
+ }
1741
+ let ee = en[n.grain], _ = [];
1742
+ function v(e, t, n = null) {
1743
+ if (h && !g.has(e.id)) return;
1744
+ let r = o.get(e.id) ?? [], i = r.filter((e) => !h || g.has(e.id)).map((e) => e.id), a = r.length > 0, s = a && (t < ee || m.has(e.id)), c = !!h && i.length > 0;
1745
+ if (_.push({
1746
+ node: { ...e },
1747
+ depth: t,
1748
+ parentId: n,
1749
+ childIds: i,
1750
+ hasChildren: a,
1751
+ canExpand: s,
1752
+ forcedOpen: c,
1753
+ expanded: c || s && m.has(e.id)
1754
+ }), h || t < ee || m.has(e.id)) for (let n of r) v(n, t + 1, e.id);
1755
+ }
1756
+ for (let e of s) v(e, 0);
1757
+ let te = [];
1758
+ function y(e, t) {
1759
+ let n = o.get(e.id) ?? [];
1760
+ if (n.length > 0 && (t < ee || m.has(e.id))) for (let e of n) y(e, t + 1);
1761
+ else te.push({ ...e });
1762
+ }
1763
+ for (let e of s) y(e, 0);
1764
+ let b = n.selectedId ? i.get(n.selectedId) ?? null : null, x = new Set(_.map((e) => e.node.id));
1765
+ return {
1766
+ state: n,
1767
+ rows: _,
1768
+ focusedId: n.navigatorFocusedId && x.has(n.navigatorFocusedId) ? n.navigatorFocusedId : _[0]?.node.id ?? null,
1769
+ selected: b ? { ...b } : null,
1770
+ staleSelectedId: n.selectedId && !b ? n.selectedId : null,
1771
+ canvas: {
1772
+ allNodes: [...i.values()].map((e) => ({ ...e })),
1773
+ nodes: te,
1774
+ visibleIds: te.map((e) => e.id),
1775
+ selectedId: b?.id ?? null,
1776
+ grain: n.grain,
1777
+ expandedIds: [...m].sort(gn),
1778
+ viewport: n.viewport ? { ...n.viewport } : null,
1779
+ hierarchy: {
1780
+ orderedIds: u,
1781
+ rootIds: s.map((e) => e.id),
1782
+ childIdsByParent: Object.fromEntries([...o].map(([e, t]) => [e, t.map((e) => e.id)])),
1783
+ depthById: Object.fromEntries(l)
1784
+ }
1785
+ }
1786
+ };
1787
+ }
1788
+ function fn(e) {
1789
+ if (!pn(e) || typeof e.type != "string") throw Z("reduce state", "action.type", "the action has no string type", "pass a supported action object");
1790
+ let t = rn[e.type];
1791
+ if (!t) throw Z("reduce state", "action.type", `action ${JSON.stringify(e.type)} is not supported`, `use one of ${Object.keys(rn).join(", ")}`);
1792
+ switch (hn(e, t, "reduce state", `action ${e.type}`), e.type) {
1793
+ case "replace":
1794
+ case "hydrate":
1795
+ xn(e.state, "state");
1796
+ break;
1797
+ case "set-presentation":
1798
+ En(e.presentation, Xt, "presentation");
1799
+ break;
1800
+ case "select":
1801
+ case "toggle-expanded":
1802
+ case "open-in-map":
1803
+ Q(e.id, "id");
1804
+ break;
1805
+ case "focus":
1806
+ _n(e.id, "id");
1807
+ break;
1808
+ case "set-filter":
1809
+ Sn(e.filter, "filter");
1810
+ break;
1811
+ case "set-expanded":
1812
+ bn(e.ids, "ids");
1813
+ break;
1814
+ case "set-grain":
1815
+ En(e.grain, Zt, "grain");
1816
+ break;
1817
+ case "set-viewport":
1818
+ On(e.viewport, "viewport");
1819
+ break;
1820
+ case "reveal":
1821
+ Q(e.id, "id"), En(e.grain, Zt, "grain"), bn(e.expandedIds, "expandedIds");
1822
+ break;
1823
+ case "clear-selection": break;
1824
+ case "hover-session":
1825
+ case "select-session":
1826
+ _n(e.sessionId, "sessionId");
1827
+ break;
1828
+ case "toggle-commit-sessions":
1829
+ Q(e.commitHash, "commitHash");
1830
+ break;
1831
+ case "toggle-ghost-group":
1832
+ Q(e.successorHash, "successorHash");
1833
+ break;
1834
+ case "set-rank-mode":
1835
+ En(e.rankMode, Qt, "rankMode");
1836
+ break;
1837
+ case "set-scent-filter":
1838
+ jn(e.scentFilter, "scentFilter");
1839
+ break;
1840
+ case "set-rank-expanded":
1841
+ wn(e.expanded, "expanded");
1842
+ break;
1843
+ }
1844
+ }
1845
+ function Z(e, t, n, r) {
1846
+ return /* @__PURE__ */ Error(`Code map ${e} failed: what went wrong: invalid ${t}; why: ${n}; where: @peasant-labs/fairtrade/graph ${t}; when: ${e}; what it means: the requested code-map state cannot be used safely; how to fix: ${r}.`);
1847
+ }
1848
+ function pn(e) {
1849
+ return typeof e == "object" && !!e && !Array.isArray(e);
1850
+ }
1851
+ function mn(e, t, n, r) {
1852
+ let i = new Set(t), a = Object.keys(e).find((e) => !i.has(e));
1853
+ if (a) throw Z(n, `${r}.${a}`, `field ${JSON.stringify(a)} is not allowed`, `remove ${JSON.stringify(a)} and use only ${t.join(", ")}`);
1854
+ }
1855
+ function hn(e, t, n, r) {
1856
+ mn(e, t, n, r);
1857
+ let i = t.find((t) => !(t in e));
1858
+ if (i) throw Z(n, `${r}.${i}`, `required field ${JSON.stringify(i)} is missing`, `provide ${JSON.stringify(i)} for this action`);
1859
+ }
1860
+ function gn(e, t) {
1861
+ return e < t ? -1 : +(e > t);
1862
+ }
1863
+ function Q(e, t) {
1864
+ if (typeof e != "string" || e.length === 0) throw Z("normalize state", t, "the id is not a nonempty string", "provide a nonempty string id");
1865
+ return e;
1866
+ }
1867
+ function _n(e, t) {
1868
+ return e === null ? null : Q(e, t);
1869
+ }
1870
+ function vn(e, t) {
1871
+ return e == null ? null : Q(e, t);
1872
+ }
1873
+ function yn(e, t) {
1874
+ if (e === void 0) return [];
1875
+ if (e === null || typeof e == "string" || typeof e[Symbol.iterator] != "function") throw Z("normalize state", t, "the value is not an iterable of ids", "provide an array or other iterable of nonempty string ids");
1876
+ let n = [...e];
1877
+ return [...new Set(n.map((e, n) => Q(e, `${t}[${n}]`)))].sort(gn);
1878
+ }
1879
+ function bn(e, t) {
1880
+ if (e === void 0) throw Z("normalize action", t, "the required id iterable is undefined", "provide a non-string iterable of nonempty ids");
1881
+ return yn(e, t);
1882
+ }
1883
+ function xn(e, t) {
1884
+ if (!pn(e)) throw Z("normalize action", t, "the required value is not an object", "provide an object");
1885
+ return e;
1886
+ }
1887
+ function Sn(e, t) {
1888
+ if (typeof e != "string") throw Z("normalize action", t, "the required value is not a string", "provide a string");
1889
+ return e;
1890
+ }
1891
+ function Cn(e, t, n) {
1892
+ if (e === void 0) return t;
1893
+ if (typeof e != "string") throw Z("normalize state", n, "the value is not a string", "provide a string");
1894
+ return e;
1895
+ }
1896
+ function wn(e, t) {
1897
+ if (typeof e != "boolean") throw Z("normalize state", t, "the value is not a boolean", "provide true or false");
1898
+ return e;
1899
+ }
1900
+ function Tn(e, t, n, r) {
1901
+ return e === void 0 ? n : En(e, t, r);
1902
+ }
1903
+ function En(e, t, n) {
1904
+ if (typeof e != "string" || !t.has(e)) throw Z("normalize state", n, `value ${JSON.stringify(e)} is unsupported`, `use one of ${[...t].join(", ")}`);
1905
+ return e;
1906
+ }
1907
+ function Dn(e) {
1908
+ if (e == null) return null;
1909
+ if (!pn(e)) throw Z("normalize state", "viewport", "the viewport is not an object or null", "provide {scale, panX, panY} or null");
1910
+ let { scale: t, panX: n, panY: r } = e;
1911
+ if (!Jt(t) || typeof n != "number" || typeof r != "number" || !Number.isFinite(n) || !Number.isFinite(r)) throw Z("normalize state", "viewport", `scale must be within ${Y.min}..${Y.max} and pan values must be finite`, `provide finite panX and panY values and a scale within ${Y.min}..${Y.max}`);
1912
+ return {
1913
+ scale: t,
1914
+ panX: n,
1915
+ panY: r
1916
+ };
1917
+ }
1918
+ function On(e, t) {
1919
+ if (e === null) return null;
1920
+ if (e === void 0) throw Z("normalize action", t, "the required viewport is undefined", "provide null or a bounded viewport object");
1921
+ return Dn(e);
1922
+ }
1923
+ function kn(e, t) {
1924
+ return e === null || t === null ? e === t : e.scale === t.scale && e.panX === t.panX && e.panY === t.panY;
1925
+ }
1926
+ function An(e) {
1927
+ if (e == null) return null;
1928
+ if (typeof e != "string" || !$t.has(e)) throw Z("normalize state", "scentFilter", `value ${JSON.stringify(e)} is unsupported`, `use null or one of ${[...$t].join(", ")}`);
1929
+ return e;
1930
+ }
1931
+ function jn(e, t) {
1932
+ if (e === void 0) throw Z("normalize action", t, "the required scent filter is undefined", "provide null or a SCENT_TAGS member");
1933
+ return An(e);
1934
+ }
1935
+ //#endregion
1936
+ //#region src/ui/MapCanvas.jsx
1937
+ var Mn = 56, Nn = 104, Pn = 248, Fn = 132, In = 28, Ln = 48, Rn = 1200, zn = 1.25, Bn = {
1938
+ overview: "project",
1939
+ folders: "package",
1940
+ files: "file"
1941
+ }, Vn = Object.fromEntries(Object.entries(Bn).map(([e, t]) => [e, tn[t]])), Hn = [
1942
+ {
1943
+ id: "overview",
1944
+ label: "overview"
1945
+ },
1946
+ {
1947
+ id: "folders",
1948
+ label: "folders"
1949
+ },
1950
+ {
1951
+ id: "files",
1952
+ label: "files"
1953
+ }
1954
+ ], Un = 500, Wn = 1e4, Gn = 3;
1955
+ function Kn(e) {
1956
+ let t = Math.round(Number(e) || 0);
1957
+ return t < 0 ? 0 : t > 4 ? 4 : t;
1958
+ }
1959
+ function qn(e) {
1960
+ let t = String(e ?? ""), n = t.lastIndexOf("/");
1961
+ return n >= 0 ? t.slice(n + 1) : t;
1962
+ }
1963
+ function Jn(e, t) {
1964
+ return e._order === t._order ? e.id < t.id ? -1 : +(e.id > t.id) : e._order - t._order;
1965
+ }
1966
+ function Yn(e) {
1967
+ let t = /* @__PURE__ */ new Map();
1968
+ e.forEach((e, n) => {
1969
+ let r = Number.isFinite(e.order) ? e.order : n;
1970
+ t.set(e.id, {
1971
+ ...e,
1972
+ _order: r
1973
+ });
1974
+ });
1975
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = [];
1976
+ for (let e of t.values()) {
1977
+ let a = e.parent && t.has(e.parent) ? e.parent : null;
1978
+ if (a) {
1979
+ r.set(e.id, a);
1980
+ let t = n.get(a);
1981
+ t ? t.push(e) : n.set(a, [e]);
1982
+ } else i.push(e);
1983
+ }
1984
+ for (let e of n.values()) e.sort(Jn);
1985
+ i.sort(Jn);
1986
+ let a = /* @__PURE__ */ new Map(), o = [], s = (e, t) => {
1987
+ a.set(e.id, t), o.push(e.id);
1988
+ for (let r of n.get(e.id) ?? []) s(r, t + 1);
1989
+ };
1990
+ for (let e of i) s(e, 0);
1991
+ return {
1992
+ byId: t,
1993
+ children: n,
1994
+ roots: i,
1995
+ parentIdByChild: r,
1996
+ depthById: a,
1997
+ orderedIds: o,
1998
+ canonical: !1
1999
+ };
2000
+ }
2001
+ function Xn(e, t) {
2002
+ let n = new Map(t.orderedIds.map((e, t) => [e, t])), r = new Map(e.map((e) => [e.id, {
2003
+ ...e,
2004
+ _order: n.get(e.id) ?? 2 ** 53 - 1
2005
+ }])), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
2006
+ for (let [e, n] of Object.entries(t.childIdsByParent)) {
2007
+ i.set(e, n.map((e) => r.get(e)).filter(Boolean));
2008
+ for (let t of n) a.set(t, e);
2009
+ }
2010
+ return {
2011
+ byId: r,
2012
+ children: i,
2013
+ roots: t.rootIds.map((e) => r.get(e)).filter(Boolean),
2014
+ parentIdByChild: a,
2015
+ depthById: new Map(Object.entries(t.depthById)),
2016
+ orderedIds: [...t.orderedIds],
2017
+ canonical: !0
2018
+ };
2019
+ }
2020
+ function Zn(e, t) {
2021
+ return t.canonical ? t.depthById.get(e.id) ?? 0 : Number.isFinite(e.layer) ? e.layer : t.depthById.get(e.id) ?? 0;
2022
+ }
2023
+ function Qn(e, t, n) {
2024
+ let { children: r, roots: i } = e, a = [], o = (e, i) => {
2025
+ let s = r.get(e.id);
2026
+ if (s && s.length > 0 && (i < t || n.has(e.id))) for (let e of s) o(e, i + 1);
2027
+ else a.push(e);
2028
+ };
2029
+ for (let e of i) o(e, 0);
2030
+ return a;
2031
+ }
2032
+ function $n(e, t) {
2033
+ if (e.length === 0) return {
2034
+ positioned: [],
2035
+ width: 0,
2036
+ height: 0
2037
+ };
2038
+ let n = 0;
2039
+ for (let t of e) n = Math.max(n, Math.max(0, Number(t.loc) || 0));
2040
+ let r = (e) => {
2041
+ if (n <= 0) return Nn;
2042
+ let t = Math.max(0, Number(e.loc) || 0) / n;
2043
+ return Math.round(Nn + t * (Pn - Nn));
2044
+ }, i = /* @__PURE__ */ new Map();
2045
+ for (let n of e) {
2046
+ let e = Zn(n, t), r = i.get(e);
2047
+ r ? r.push(n) : i.set(e, [n]);
2048
+ }
2049
+ let a = Array.from(i.keys()).sort((e, t) => e - t);
2050
+ for (let e of a) i.get(e).sort(Jn);
2051
+ let o = (e) => e.reduce((e, t) => e + r(t), 0) + In * (e.length - 1), s = (e) => {
2052
+ let t = [], n = [], i = 0;
2053
+ for (let a of e) {
2054
+ let e = r(a), o = n.length === 0 ? e : e + In;
2055
+ n.length > 0 && i + o > Rn ? (t.push(n), n = [a], i = e) : (n.push(a), i += o);
2056
+ }
2057
+ return n.length > 0 && t.push(n), t;
2058
+ }, c = /* @__PURE__ */ new Map();
2059
+ for (let e of a) c.set(e, s(i.get(e)));
2060
+ let l = 0;
2061
+ for (let e of a) for (let t of c.get(e)) l = Math.max(l, o(t));
2062
+ let u = [], d = 0;
2063
+ for (let e of a) for (let t of c.get(e)) {
2064
+ let e = Ln + (l - o(t)) / 2, n = Ln + d * Fn;
2065
+ for (let i of t) {
2066
+ let t = r(i);
2067
+ u.push({
2068
+ node: i,
2069
+ x: e,
2070
+ y: n,
2071
+ w: t,
2072
+ h: Mn
2073
+ }), e += t + In;
2074
+ }
2075
+ d += 1;
2076
+ }
2077
+ return {
2078
+ positioned: u,
2079
+ width: l + Ln * 2,
2080
+ height: (d - 1) * Fn + Mn + Ln * 2
2081
+ };
2082
+ }
2083
+ function er(e, t) {
2084
+ let n = /* @__PURE__ */ new Map();
2085
+ return (r) => {
2086
+ if (n.has(r)) return n.get(r);
2087
+ let i = r;
2088
+ for (; i != null && !t.has(i);) i = e.get(i) ?? null;
2089
+ return n.set(r, i ?? null), i ?? null;
2090
+ };
2091
+ }
2092
+ function tr(e, t, n) {
2093
+ let r = er(t, n), i = /* @__PURE__ */ new Map();
2094
+ for (let t of e) {
2095
+ let e = r(t.from), n = r(t.to);
2096
+ if (!e || !n || e === n) continue;
2097
+ let a = t.kind === "activity" ? "activity" : "structure", o = `${a}|${e}→${n}`, s = Math.max(0, Number(t.weight) || 1), c = i.get(o);
2098
+ c ? c.weight += s : i.set(o, {
2099
+ from: e,
2100
+ to: n,
2101
+ kind: a,
2102
+ weight: s
2103
+ });
2104
+ }
2105
+ return Array.from(i.values()).sort((e, t) => e.from === t.from ? e.to < t.to ? -1 : +(e.to > t.to) : e.from < t.from ? -1 : 1);
2106
+ }
2107
+ function nr(e, t, n) {
2108
+ let r = er(t, n), i = /* @__PURE__ */ new Map();
2109
+ for (let t of e) {
2110
+ let e = Math.max(0, Number(t.violations) || 0);
2111
+ if (e <= 0) continue;
2112
+ let n = r(t.id);
2113
+ n && i.set(n, (i.get(n) || 0) + e);
2114
+ }
2115
+ return i;
2116
+ }
2117
+ function rr(e) {
2118
+ let t;
2119
+ for (let n of e) (!t || n.y < t.y || n.y === t.y && n.x < t.x) && (t = n);
2120
+ return t;
2121
+ }
2122
+ function ir(e, t, n) {
2123
+ let r = e.filter((e) => e.y === t.y).sort((e, t) => e.x - t.x), i = r.findIndex((e) => e.node.id === t.node.id);
2124
+ if (i !== -1) return r[i + n];
2125
+ }
2126
+ function ar(e, t, n) {
2127
+ let r;
2128
+ for (let i of e) (i.y - t.y) * n <= 0 || (r === void 0 || (i.y - r) * n < 0) && (r = i.y);
2129
+ if (r === void 0) return;
2130
+ let i = t.x + t.w / 2, a;
2131
+ for (let t of e) if (t.y === r) {
2132
+ if (!a) {
2133
+ a = t;
2134
+ continue;
2135
+ }
2136
+ Math.abs(t.x + t.w / 2 - i) < Math.abs(a.x + a.w / 2 - i) && (a = t);
2137
+ }
2138
+ return a;
2139
+ }
2140
+ function or({ data: i = {
2141
+ nodes: [],
2142
+ edges: []
2143
+ }, grain: f = "folders", expandedIds: p, visibleIds: h, hierarchy: g, selectedId: v, highlightedIds: x, nodeDeltas: re = {}, edgeDeltas: ae = {}, onSelect: oe, onGrainChange: se, onExpandedIdsChange: S, onExpand: ce, height: le = 520, ariaLabel: ue = "code map", className: de = "", viewport: C, onViewportChange: fe, onStateAction: w, canonicalControlled: T = !1 }) {
2144
+ let E = i?.nodes ?? [], pe = i?.edges ?? [], D = r().replace(/[:]/g, ""), me = `${D}-live`, he = `${D}-list`, [ge, _e] = s(Vn[f] === void 0 ? "folders" : f), [ve, ye] = s(() => cr(p)), [be, xe] = s(v ?? null), [O, Se] = s(null), [Ce, we] = s(() => lr(C?.scale) ? C.scale : 1), [Te, Ee] = s(() => ({
2145
+ x: $(C?.panX, 0),
2146
+ y: $(C?.panY, 0)
2147
+ })), [De, Oe] = s(""), [ke, k] = s(!1), A = o(null), j = o(null), [M, Ae] = s(null), je = o(null), Me = o(!1), Ne = o(C != null), Pe = C && lr(C.scale) ? `${C.scale}|${$(C.panX, 0)}|${$(C.panY, 0)}` : "", Fe = o(Pe), N = o(Pe), Ie = o(!1), Le = o(f), Re = o(v), ze = ur(p), Be = ur(x), P = T ? Vn[f] === void 0 ? "folders" : f : ge, F = a(() => T ? cr(p) : ve, [
2148
+ T,
2149
+ ze,
2150
+ ve
2151
+ ]), I = T ? v ?? null : be, Ve = T && C != null && lr(C.scale), L = M ? M.scale : Ve ? C.scale : Ce, R = M ? {
2152
+ x: M.panX,
2153
+ y: M.panY
2154
+ } : Ve ? {
2155
+ x: $(C.panX, 0),
2156
+ y: $(C.panY, 0)
2157
+ } : Te, He = o(L), Ue = o(R);
2158
+ He.current = L, Ue.current = R, n(() => {
2159
+ if (M && !j.current) {
2160
+ if (Ve && C.scale === M.scale && $(C.panX, 0) === M.panX && $(C.panY, 0) === M.panY) {
2161
+ Ae(null);
2162
+ return;
2163
+ }
2164
+ return je.current = setTimeout(() => Ae(null), Un), () => clearTimeout(je.current);
2165
+ }
2166
+ }, [
2167
+ M,
2168
+ Ve,
2169
+ C?.scale,
2170
+ C?.panX,
2171
+ C?.panY
2172
+ ]), n(() => {
2173
+ T || f !== Le.current && (Le.current = f, Vn[f] !== void 0 && _e(f));
2174
+ }, [T, f]), n(() => {
2175
+ !T && p !== void 0 && ye(cr(p));
2176
+ }, [T, ze]), n(() => {
2177
+ T || v !== Re.current && (Re.current = v, v !== void 0 && xe(v));
2178
+ }, [T, v]), n(() => {
2179
+ if (T) {
2180
+ if (!C && N.current !== "") N.current = "", Ne.current = !1, Me.current = !1, we(1), Ee({
2181
+ x: 0,
2182
+ y: 0
2183
+ });
2184
+ else if (C && lr(C.scale)) {
2185
+ let e = `${C.scale}|${$(C.panX, 0)}|${$(C.panY, 0)}`;
2186
+ e !== N.current && (N.current = e, Ne.current = !0);
2187
+ }
2188
+ return;
2189
+ }
2190
+ if (!C) {
2191
+ if (N.current === "") return;
2192
+ N.current = "", Fe.current = "1|0|0", Ne.current = !1, we(1), Ee({
2193
+ x: 0,
2194
+ y: 0
2195
+ });
2196
+ return;
2197
+ }
2198
+ if (!lr(C.scale)) return;
2199
+ let e = `${C.scale}|${$(C.panX, 0)}|${$(C.panY, 0)}`;
2200
+ e !== N.current && (N.current = e, Ne.current = !0, Fe.current = e, we(C.scale), Ee({
2201
+ x: $(C.panX, 0),
2202
+ y: $(C.panY, 0)
2203
+ }));
2204
+ }, [
2205
+ T,
2206
+ C,
2207
+ C?.scale,
2208
+ C?.panX,
2209
+ C?.panY
2210
+ ]), n(() => {
2211
+ if (T || !fe && !w) return;
2212
+ let e = `${L}|${R.x}|${R.y}`;
2213
+ Fe.current !== e && (Fe.current = e, fe?.({
2214
+ scale: L,
2215
+ panX: R.x,
2216
+ panY: R.y
2217
+ }), Ie.current && (Ie.current = !1, w?.({
2218
+ type: "set-viewport",
2219
+ viewport: {
2220
+ scale: L,
2221
+ panX: R.x,
2222
+ panY: R.y
2223
+ }
2224
+ })));
2225
+ }, [
2226
+ T,
2227
+ w,
2228
+ fe,
2229
+ R.x,
2230
+ R.y,
2231
+ L
2232
+ ]);
2233
+ let z = a(() => g ? Xn(E, g) : Yn(E), [E, g]), We = a(() => h === void 0 ? Qn(z, Vn[P], F) : Array.from(h, (e) => z.byId.get(e)).filter(Boolean), [
2234
+ z,
2235
+ P,
2236
+ F,
2237
+ ur(h)
2238
+ ]), B = a(() => new Set(We.map((e) => e.id)), [We]), { positioned: V, width: H, height: U } = a(() => $n(We, z), [We, z]), Ge = a(() => {
2239
+ let e = /* @__PURE__ */ new Map();
2240
+ for (let t of V) e.set(t.node.id, t);
2241
+ return e;
2242
+ }, [V]), Ke = a(() => {
2243
+ let e = /* @__PURE__ */ new Map();
2244
+ for (let [t, n] of z.children) e.set(t, n.length);
2245
+ return e;
2246
+ }, [z]), qe = a(() => tr(pe, z.parentIdByChild, B), [
2247
+ pe,
2248
+ z.parentIdByChild,
2249
+ B
2250
+ ]), Je = a(() => qe.reduce((e, t) => Math.max(e, t.weight), 1), [qe]), Ye = a(() => nr(E, z.parentIdByChild, B), [
2251
+ E,
2252
+ z.parentIdByChild,
2253
+ B
2254
+ ]), W = a(() => {
2255
+ let e = cr(x);
2256
+ if (e.size === 0) return e;
2257
+ let t = er(z.parentIdByChild, B), n = /* @__PURE__ */ new Set();
2258
+ for (let r of e) {
2259
+ let e = t(r);
2260
+ e && n.add(e);
2261
+ }
2262
+ return n;
2263
+ }, [
2264
+ Be,
2265
+ z.parentIdByChild,
2266
+ B
2267
+ ]), Xe = a(() => {
2268
+ let e = De.trim().toLowerCase();
2269
+ return e ? E.filter((t) => t.id.toLowerCase().includes(e) || (t.label || "").toLowerCase().includes(e)).slice(0, 8) : [];
2270
+ }, [E, De]), Ze = t((e) => {
2271
+ fe?.(e), w?.({
2272
+ type: "set-viewport",
2273
+ viewport: e
2274
+ });
2275
+ }, [w, fe]), G = t((e, t) => {
2276
+ if (T && t) {
2277
+ Ze(e);
2278
+ return;
2279
+ }
2280
+ t && (Ie.current = !0), we(e.scale), Ee({
2281
+ x: e.panX,
2282
+ y: e.panY
2283
+ });
2284
+ }, [T, Ze]), Qe = t((e = !1) => {
2285
+ let t = A.current;
2286
+ if (!t || H <= 0 || U <= 0) return;
2287
+ let n = t.clientWidth, r = t.clientHeight;
2288
+ if (n <= 0 || r <= 0) return;
2289
+ let i = Math.min(n / H, r / U), a = Math.max(Y.min, Math.min(Y.max, i));
2290
+ G({
2291
+ scale: a,
2292
+ panX: (n - H * a) / 2,
2293
+ panY: (r - U * a) / 2
2294
+ }, e);
2295
+ }, [
2296
+ G,
2297
+ H,
2298
+ U
2299
+ ]), $e = t((e, t = !1) => {
2300
+ let n = A.current;
2301
+ if (!n) return !1;
2302
+ let r = n.clientWidth, i = n.clientHeight;
2303
+ if (r <= 0 || i <= 0) return !1;
2304
+ let a = V.filter((t) => e.has(t.node.id));
2305
+ if (a.length === 0) return !1;
2306
+ let o = Math.min(...a.map((e) => e.x)), s = Math.min(...a.map((e) => e.y)), c = Math.max(...a.map((e) => e.x + e.w)), l = Math.max(...a.map((e) => e.y + e.h)), u = c - o, d = l - s;
2307
+ if (u <= 0 || d <= 0) return !1;
2308
+ let f = Math.min(r / u, i / d), p = Math.max(Y.min, Math.min(Y.max, f));
2309
+ return G({
2310
+ scale: p,
2311
+ panX: r / 2 - (o + u / 2) * p,
2312
+ panY: i / 2 - (s + d / 2) * p
2313
+ }, t), !0;
2314
+ }, [G, V]), [et, tt] = s(!1);
2315
+ n(() => {
2316
+ if (!et) return;
2317
+ let e = window.setTimeout(() => tt(!1), 200);
2318
+ return () => window.clearTimeout(e);
2319
+ }, [et]);
2320
+ let nt = a(() => V.map((e) => e.node.id).join("|"), [V]), rt = Ve ? `canonical|${C.scale}|${$(C.panX, 0)}|${$(C.panY, 0)}` : T ? "canonical|auto-fit" : "legacy", it = o(F);
2321
+ n(() => {
2322
+ let e = it.current;
2323
+ if (it.current = F, Ne.current) {
2324
+ Ne.current = !1, Me.current = !0;
2325
+ return;
2326
+ }
2327
+ if (!Me.current) {
2328
+ Me.current = !0, Qe(Ve);
2329
+ return;
2330
+ }
2331
+ let t = null;
2332
+ for (let n of F) if (!e.has(n)) {
2333
+ t = n;
2334
+ break;
2335
+ }
2336
+ if (t) {
2337
+ let e = /* @__PURE__ */ new Set([t]), n = [t];
2338
+ for (; n.length > 0;) {
2339
+ let t = n.pop();
2340
+ for (let r of z.children.get(t) ?? []) e.add(r.id), n.push(r.id);
2341
+ }
2342
+ let r = [...e].filter((e) => B.has(e));
2343
+ if (tt(!0), r.length > 0 && $e(new Set(r), !0)) return;
2344
+ }
2345
+ Qe(Ve);
2346
+ }, [nt, rt]);
2347
+ let at = t((e) => {
2348
+ let t = A.current, n = t ? t.clientWidth / 2 : 0, r = t ? t.clientHeight / 2 : 0, i = He.current, a = Math.max(Y.min, Math.min(Y.max, i * e));
2349
+ if (a === i) return;
2350
+ let o = Ue.current;
2351
+ G({
2352
+ scale: a,
2353
+ panX: n - (n - o.x) / i * a,
2354
+ panY: r - (r - o.y) / i * a
2355
+ }, !0);
2356
+ }, [G]), ot = t((e) => {
2357
+ if (!(e.ctrlKey || e.metaKey)) return;
2358
+ e.preventDefault();
2359
+ let t = A.current;
2360
+ if (!t) return;
2361
+ let n = t.getBoundingClientRect(), r = e.clientX - n.left, i = e.clientY - n.top, a = He.current, o = Math.exp(-e.deltaY * .01), s = Math.max(1 / zn, Math.min(zn, o)), c = Math.max(Y.min, Math.min(Y.max, a * s));
2362
+ if (c === a) return;
2363
+ let l = Ue.current;
2364
+ G({
2365
+ scale: c,
2366
+ panX: r - (r - l.x) / a * c,
2367
+ panY: i - (i - l.y) / a * c
2368
+ }, !0);
2369
+ }, [G]);
2370
+ n(() => {
2371
+ let e = A.current;
2372
+ if (e) return e.addEventListener("wheel", ot, { passive: !1 }), () => e.removeEventListener("wheel", ot);
2373
+ }, [ot]);
2374
+ let K = t((e) => {
2375
+ let t = Ge.get(e), n = A.current;
2376
+ if (!t || !n) return;
2377
+ let r = Math.max(L, 1);
2378
+ G({
2379
+ scale: r,
2380
+ panX: n.clientWidth / 2 - (t.x + t.w / 2) * r,
2381
+ panY: n.clientHeight / 2 - (t.y + t.h / 2) * r
2382
+ }, !0);
2383
+ }, [
2384
+ G,
2385
+ Ge,
2386
+ L
2387
+ ]), q = t((e) => {
2388
+ if (T && e === I) return;
2389
+ T || xe(e), w?.(e ? {
2390
+ type: "select",
2391
+ id: e
2392
+ } : { type: "clear-selection" });
2393
+ let t = e ? z.byId.get(e) : null;
2394
+ oe?.(e, t ? sr(t) : null);
2395
+ }, [
2396
+ T,
2397
+ oe,
2398
+ w,
2399
+ I,
2400
+ z.byId
2401
+ ]), st = t((e) => {
2402
+ T || (_e(e), ye(/* @__PURE__ */ new Set())), w?.({
2403
+ type: "set-grain",
2404
+ grain: Bn[e]
2405
+ }), se?.(e), T || S?.([]);
2406
+ }, [
2407
+ T,
2408
+ S,
2409
+ se,
2410
+ w
2411
+ ]), [ct, J] = s(null), [lt, ut] = s("");
2412
+ n(() => {
2413
+ ct && !F.has(ct) && J(null);
2414
+ }, [ct, F]);
2415
+ let dt = t((e) => {
2416
+ if ((Ke.get(e) || 0) === 0) return;
2417
+ let t = z.byId.get(e), n = new Set(F);
2418
+ if (n.has(e)) n.delete(e), J((t) => {
2419
+ if (t !== e) return t;
2420
+ let r = z.parentIdByChild.get(e) ?? null;
2421
+ return r && n.has(r) ? r : null;
2422
+ }), ut(`closed ${qn(t?.label || e)}`);
2423
+ else {
2424
+ n.add(e), ce?.(e), J(e);
2425
+ let r = Ke.get(e) || 0;
2426
+ ut(`opened ${qn(t?.label || e)}, showing ${r} item${r === 1 ? "" : "s"}`);
2427
+ }
2428
+ T || ye(n), w?.({
2429
+ type: "set-expanded",
2430
+ ids: Array.from(n)
2431
+ }), S?.(Array.from(n));
2432
+ }, [
2433
+ T,
2434
+ Ke,
2435
+ F,
2436
+ ce,
2437
+ S,
2438
+ w,
2439
+ z.byId,
2440
+ z.parentIdByChild
2441
+ ]), ft = a(() => {
2442
+ if (!ct) return [];
2443
+ let e = [], t = ct;
2444
+ for (; t;) {
2445
+ let n = z.byId.get(t);
2446
+ if (!n) break;
2447
+ e.unshift(n), t = z.parentIdByChild.get(t) ?? null;
2448
+ }
2449
+ return e;
2450
+ }, [ct, z]), pt = t(() => {
2451
+ T || ye(/* @__PURE__ */ new Set()), w?.({
2452
+ type: "set-expanded",
2453
+ ids: []
2454
+ }), S?.([]), J(null), ut("back to the top level");
2455
+ }, [
2456
+ T,
2457
+ S,
2458
+ w
2459
+ ]), mt = t((e) => {
2460
+ let t = ft.slice(0, e + 1), n = t.map((e) => e.id), r = new Set(n);
2461
+ T || ye(r), w?.({
2462
+ type: "set-expanded",
2463
+ ids: n
2464
+ }), S?.(n);
2465
+ let i = t[t.length - 1] ?? null;
2466
+ J(i?.id ?? null), ut(i ? `back to ${qn(i.label || i.id)}` : "back to the top level");
2467
+ }, [
2468
+ ft,
2469
+ T,
2470
+ S,
2471
+ w
2472
+ ]), ht = t((e) => {
2473
+ let t = e.key;
2474
+ if (t === "+" || t === "=") {
2475
+ e.preventDefault(), at(zn);
2476
+ return;
2477
+ }
2478
+ if (t === "-" || t === "_") {
2479
+ e.preventDefault(), at(1 / zn);
2480
+ return;
2481
+ }
2482
+ if (t === "0") {
2483
+ e.preventDefault(), Qe(!0);
2484
+ return;
2485
+ }
2486
+ if (t === "ArrowLeft" || t === "ArrowRight" || t === "ArrowUp" || t === "ArrowDown") {
2487
+ e.preventDefault();
2488
+ let n = O ? Ge.get(O) : void 0;
2489
+ if (!n) {
2490
+ let e = rr(V);
2491
+ e && Se(e.node.id);
2492
+ return;
2493
+ }
2494
+ let r;
2495
+ r = t === "ArrowLeft" ? ir(V, n, -1) : t === "ArrowRight" ? ir(V, n, 1) : t === "ArrowUp" ? ar(V, n, -1) : ar(V, n, 1), r && (Se(r.node.id), mr(r, A.current, L, R, (e) => {
2496
+ G({
2497
+ scale: L,
2498
+ panX: e.x,
2499
+ panY: e.y
2500
+ }, !0);
2501
+ }));
2502
+ return;
2503
+ }
2504
+ if (t === "Enter") {
2505
+ if (!O) return;
2506
+ e.preventDefault(), e.shiftKey ? dt(O) : T ? I !== O && q(O) : q(I === O ? null : O);
2507
+ return;
2508
+ }
2509
+ if (t === "e" || t === "E") {
2510
+ if (!O) return;
2511
+ e.preventDefault(), dt(O);
2512
+ return;
2513
+ }
2514
+ t === "Escape" && I && (e.preventDefault(), q(null));
2515
+ }, [
2516
+ O,
2517
+ V,
2518
+ Ge,
2519
+ I,
2520
+ L,
2521
+ R,
2522
+ T,
2523
+ G,
2524
+ at,
2525
+ Qe,
2526
+ dt,
2527
+ q
2528
+ ]), gt = t((e) => {
2529
+ let t = j.current;
2530
+ if (!t || e !== t.pointerId) return;
2531
+ j.current = null;
2532
+ let n = A.current;
2533
+ try {
2534
+ n?.releasePointerCapture?.(e);
2535
+ } catch {}
2536
+ T && Ae(null);
2537
+ }, [T]), _t = t((e) => {
2538
+ if (e.button !== 0 || e.target instanceof Element && e.target.closest("button, a, input, select, textarea")) return;
2539
+ if (j.current) {
2540
+ if (Date.now() - j.current.startedAt < Wn) return;
2541
+ gt(j.current.pointerId);
2542
+ }
2543
+ let t = A.current;
2544
+ t && t.setPointerCapture?.(e.pointerId), j.current = {
2545
+ pointerId: e.pointerId,
2546
+ startX: e.clientX,
2547
+ startY: e.clientY,
2548
+ panX: R.x,
2549
+ panY: R.y,
2550
+ moved: !1,
2551
+ nextPan: null,
2552
+ startedAt: Date.now()
2553
+ };
2554
+ }, [R, gt]), vt = t((e) => {
2555
+ let t = j.current;
2556
+ if (!t || e.pointerId !== t.pointerId) return;
2557
+ let n = e.clientX - t.startX, r = e.clientY - t.startY;
2558
+ !t.moved && Math.abs(n) + Math.abs(r) > 3 && (t.moved = !0), t.moved && (t.nextPan = {
2559
+ scale: He.current,
2560
+ panX: t.panX + n,
2561
+ panY: t.panY + r
2562
+ }, T ? Ae(t.nextPan) : G(t.nextPan, !0));
2563
+ }, [G, T]), yt = t((e) => {
2564
+ let t = j.current;
2565
+ if (!t || e.pointerId !== t.pointerId) return;
2566
+ j.current = null;
2567
+ let n = A.current;
2568
+ try {
2569
+ n?.releasePointerCapture?.(e.pointerId);
2570
+ } catch {}
2571
+ t.moved && T && t.nextPan && (G(t.nextPan, !0), Ae({ ...t.nextPan })), !t.moved && e.target === e.currentTarget && q(null);
2572
+ }, [
2573
+ G,
2574
+ T,
2575
+ q
2576
+ ]), bt = t((e) => gt(e.pointerId), [gt]), xt = t((e) => gt(e.pointerId), [gt]), St = a(() => {
2577
+ if (!O) return "";
2578
+ let e = z.byId.get(O);
2579
+ return e ? pr(e, {
2580
+ selected: I === O,
2581
+ expanded: F.has(O),
2582
+ violations: Ye.get(O) || 0
2583
+ }) : "";
2584
+ }, [
2585
+ O,
2586
+ z.byId,
2587
+ I,
2588
+ F,
2589
+ Ye
2590
+ ]), Ct = a(() => {
2591
+ let e = A.current;
2592
+ if (!e || H <= 0 || U <= 0) return null;
2593
+ let t = e.clientWidth, n = e.clientHeight;
2594
+ return {
2595
+ graphW: H,
2596
+ graphH: U,
2597
+ viewX: -R.x / L,
2598
+ viewY: -R.y / L,
2599
+ viewW: t / L,
2600
+ viewH: n / L
2601
+ };
2602
+ }, [
2603
+ R,
2604
+ L,
2605
+ H,
2606
+ U
2607
+ ]), wt = V.length === 0, Tt = (e) => `${D}-grain-${e}`;
2608
+ return /* @__PURE__ */ u("div", {
2609
+ className: ["mc", de].filter(Boolean).join(" "),
2610
+ style: { height: le },
2611
+ role: "application",
2612
+ "aria-label": ue,
2613
+ "aria-roledescription": "code structure map",
2614
+ children: [
2615
+ /* @__PURE__ */ l("div", {
2616
+ id: me,
2617
+ className: "mc-sr",
2618
+ role: "status",
2619
+ "aria-live": "polite",
2620
+ children: St
2621
+ }),
2622
+ /* @__PURE__ */ u("div", {
2623
+ className: "mc-toolbar",
2624
+ children: [/* @__PURE__ */ l("div", {
2625
+ className: "mc-seg",
2626
+ role: "radiogroup",
2627
+ "aria-label": "detail grain",
2628
+ children: Hn.map((e) => /* @__PURE__ */ u("button", {
2629
+ id: Tt(e.id),
2630
+ type: "button",
2631
+ role: "radio",
2632
+ "aria-checked": P === e.id,
2633
+ className: "mc-seg-btn mono",
2634
+ "data-active": P === e.id ? "true" : void 0,
2635
+ onClick: () => st(e.id),
2636
+ children: [P === e.id && /* @__PURE__ */ l(d, {
2637
+ className: "lucide",
2638
+ "aria-hidden": "true"
2639
+ }), e.label]
2640
+ }, e.id))
2641
+ }), /* @__PURE__ */ u("div", {
2642
+ className: "mc-search",
2643
+ role: "combobox",
2644
+ "aria-expanded": ke && Xe.length > 0,
2645
+ "aria-haspopup": "listbox",
2646
+ "aria-owns": he,
2647
+ children: [
2648
+ /* @__PURE__ */ l(ne, {
2649
+ className: "lucide mc-search-ico",
2650
+ "aria-hidden": "true"
2651
+ }),
2652
+ /* @__PURE__ */ l("input", {
2653
+ className: "mc-search-input mono",
2654
+ type: "text",
2655
+ placeholder: "find a node",
2656
+ "aria-label": "find a node",
2657
+ "aria-controls": he,
2658
+ "aria-autocomplete": "list",
2659
+ value: De,
2660
+ onChange: (e) => {
2661
+ Oe(e.target.value), k(!0);
2662
+ },
2663
+ onFocus: () => k(!0),
2664
+ onBlur: () => {
2665
+ window.setTimeout(() => k(!1), 120);
2666
+ },
2667
+ onKeyDown: (e) => {
2668
+ e.key === "Enter" && Xe[0] ? (e.preventDefault(), Et(Xe[0])) : e.key === "Escape" && k(!1);
2669
+ }
2670
+ }),
2671
+ ke && Xe.length > 0 && /* @__PURE__ */ l("ul", {
2672
+ className: "mc-results",
2673
+ id: he,
2674
+ role: "listbox",
2675
+ "aria-label": "search results",
2676
+ children: Xe.map((e) => /* @__PURE__ */ u("li", {
2677
+ role: "option",
2678
+ "aria-selected": e.id === I,
2679
+ className: "mc-result mono",
2680
+ onMouseDown: (t) => {
2681
+ t.preventDefault(), Et(e);
2682
+ },
2683
+ children: [e.kind === "folder" ? /* @__PURE__ */ l(_, {
2684
+ className: "lucide",
2685
+ "aria-hidden": "true"
2686
+ }) : /* @__PURE__ */ l(ee, {
2687
+ className: "lucide",
2688
+ "aria-hidden": "true"
2689
+ }), /* @__PURE__ */ l("span", {
2690
+ className: "mc-result-path",
2691
+ children: e.id
2692
+ })]
2693
+ }, e.id))
2694
+ })
2695
+ ]
2696
+ })]
2697
+ }),
2698
+ /* @__PURE__ */ l("div", {
2699
+ className: "mc-sr",
2700
+ role: "status",
2701
+ "aria-live": "polite",
2702
+ children: lt
2703
+ }),
2704
+ ft.length > 0 && /* @__PURE__ */ u("nav", {
2705
+ className: "mc-breadcrumb mono",
2706
+ "aria-label": "folder path",
2707
+ children: [/* @__PURE__ */ l("button", {
2708
+ type: "button",
2709
+ className: "mc-breadcrumb-crumb",
2710
+ onClick: pt,
2711
+ children: "top level"
2712
+ }), ft.map((t, n) => /* @__PURE__ */ u(e, { children: [/* @__PURE__ */ l(m, {
2713
+ className: "lucide mc-breadcrumb-sep",
2714
+ "aria-hidden": "true"
2715
+ }), n === ft.length - 1 ? /* @__PURE__ */ l("span", {
2716
+ className: "mc-breadcrumb-crumb mc-breadcrumb-current",
2717
+ "aria-current": "location",
2718
+ children: qn(t.label || t.id)
2719
+ }) : /* @__PURE__ */ l("button", {
2720
+ type: "button",
2721
+ className: "mc-breadcrumb-crumb",
2722
+ onClick: () => mt(n),
2723
+ children: qn(t.label || t.id)
2724
+ })] }, t.id))]
2725
+ }),
2726
+ /* @__PURE__ */ l("div", {
2727
+ className: "mc-viewport",
2728
+ ref: A,
2729
+ tabIndex: 0,
2730
+ role: "group",
2731
+ "aria-label": "map canvas: arrow keys move focus, enter selects, plus and minus zoom, ctrl or cmd plus wheel to zoom",
2732
+ "aria-activedescendant": O && B.has(O) ? `${D}-node-${fr(O)}` : void 0,
2733
+ onKeyDown: ht,
2734
+ onPointerDown: _t,
2735
+ onPointerMove: vt,
2736
+ onPointerUp: yt,
2737
+ onPointerCancel: bt,
2738
+ onLostPointerCapture: xt,
2739
+ children: wt ? /* @__PURE__ */ l("p", {
2740
+ className: "mc-empty mono",
2741
+ children: "no nodes to map"
2742
+ }) : /* @__PURE__ */ u(c, { children: [
2743
+ /* @__PURE__ */ u("div", {
2744
+ className: ["mc-stage", et ? "mc-stage--auto-fit" : ""].filter(Boolean).join(" "),
2745
+ style: {
2746
+ transform: `translate(${R.x}px, ${R.y}px) scale(${L})`,
2747
+ width: H,
2748
+ height: U
2749
+ },
2750
+ children: [/* @__PURE__ */ l("svg", {
2751
+ className: "mc-edges",
2752
+ width: H,
2753
+ height: U,
2754
+ viewBox: `0 0 ${H} ${U}`,
2755
+ "aria-hidden": "true",
2756
+ children: qe.map((e) => {
2757
+ let t = Ge.get(e.from), n = Ge.get(e.to);
2758
+ if (!t || !n) return null;
2759
+ let r = ae[dr(e.from, e.to)] ?? ae[dr(e.from, e.to, "arrow")];
2760
+ return /* @__PURE__ */ l(gr, {
2761
+ a: t,
2762
+ b: n,
2763
+ kind: e.kind,
2764
+ weight: e.weight,
2765
+ maxWeight: Je,
2766
+ delta: r
2767
+ }, `${e.kind}:${e.from}->${e.to}`);
2768
+ })
2769
+ }), V.map((t) => {
2770
+ let n = (Ke.get(t.node.id) || 0) > 0, r = F.has(t.node.id);
2771
+ return /* @__PURE__ */ u(e, { children: [/* @__PURE__ */ l(hr, {
2772
+ domId: `${D}-node-${fr(t.node.id)}`,
2773
+ p: t,
2774
+ selected: I === t.node.id,
2775
+ focused: O === t.node.id,
2776
+ highlighted: W.has(t.node.id),
2777
+ delta: re[t.node.id],
2778
+ expandable: n,
2779
+ expanded: r,
2780
+ violations: Ye.get(t.node.id) || 0,
2781
+ onClick: (e) => {
2782
+ e >= 2 || (Se(t.node.id), T ? I !== t.node.id && q(t.node.id) : q(I === t.node.id ? null : t.node.id));
2783
+ },
2784
+ onDoubleClick: () => {
2785
+ n && dt(t.node.id);
2786
+ }
2787
+ }), n ? /* @__PURE__ */ l("button", {
2788
+ type: "button",
2789
+ className: "mc-node-disclosure",
2790
+ "aria-label": `${r ? "hide" : "show"} children for ${qn(t.node.label || t.node.id)}`,
2791
+ "aria-expanded": r,
2792
+ style: {
2793
+ left: t.x + t.w,
2794
+ top: t.y + t.h
2795
+ },
2796
+ onPointerDown: (e) => e.stopPropagation(),
2797
+ onKeyDown: (e) => e.stopPropagation(),
2798
+ onClick: (e) => {
2799
+ e.stopPropagation(), dt(t.node.id);
2800
+ },
2801
+ children: /* @__PURE__ */ l(m, { "aria-hidden": "true" })
2802
+ }) : null] }, t.node.id);
2803
+ })]
2804
+ }),
2805
+ /* @__PURE__ */ u("div", {
2806
+ className: "mc-zoom",
2807
+ role: "group",
2808
+ "aria-label": "map zoom",
2809
+ children: [
2810
+ /* @__PURE__ */ l("button", {
2811
+ type: "button",
2812
+ className: "mc-zoom-btn",
2813
+ "aria-label": "zoom in",
2814
+ onClick: () => at(zn),
2815
+ children: /* @__PURE__ */ l(b, {
2816
+ className: "lucide",
2817
+ "aria-hidden": "true"
2818
+ })
2819
+ }),
2820
+ /* @__PURE__ */ l("button", {
2821
+ type: "button",
2822
+ className: "mc-zoom-btn",
2823
+ "aria-label": "zoom out",
2824
+ onClick: () => at(1 / zn),
2825
+ children: /* @__PURE__ */ l(y, {
2826
+ className: "lucide",
2827
+ "aria-hidden": "true"
2828
+ })
2829
+ }),
2830
+ /* @__PURE__ */ l("button", {
2831
+ type: "button",
2832
+ className: "mc-zoom-btn",
2833
+ "aria-label": "fit map to view",
2834
+ onClick: () => Qe(!0),
2835
+ children: /* @__PURE__ */ l(te, {
2836
+ className: "lucide",
2837
+ "aria-hidden": "true"
2838
+ })
2839
+ })
2840
+ ]
2841
+ }),
2842
+ Ct && /* @__PURE__ */ l("div", {
2843
+ className: "mc-minimap",
2844
+ "aria-hidden": "true",
2845
+ children: /* @__PURE__ */ u("svg", {
2846
+ className: "mc-minimap-svg",
2847
+ viewBox: `0 0 ${Ct.graphW} ${Ct.graphH}`,
2848
+ preserveAspectRatio: "xMidYMid meet",
2849
+ children: [V.map((e) => /* @__PURE__ */ l("rect", {
2850
+ className: "mc-mini-node",
2851
+ "data-cov": Kn(e.node.coverage),
2852
+ x: e.x,
2853
+ y: e.y,
2854
+ width: e.w,
2855
+ height: e.h
2856
+ }, e.node.id)), /* @__PURE__ */ l("rect", {
2857
+ className: "mc-mini-view",
2858
+ x: Ct.viewX,
2859
+ y: Ct.viewY,
2860
+ width: Ct.viewW,
2861
+ height: Ct.viewH
2862
+ })]
2863
+ })
2864
+ }),
2865
+ /* @__PURE__ */ u("div", {
2866
+ className: "mc-legend mono",
2867
+ "aria-hidden": "true",
2868
+ children: [
2869
+ /* @__PURE__ */ u("span", {
2870
+ className: "mc-legend-item",
2871
+ children: [/* @__PURE__ */ l(_, { className: "lucide" }), " folder"]
2872
+ }),
2873
+ /* @__PURE__ */ u("span", {
2874
+ className: "mc-legend-item",
2875
+ children: [/* @__PURE__ */ l(ee, { className: "lucide" }), " file"]
2876
+ }),
2877
+ /* @__PURE__ */ u("span", {
2878
+ className: "mc-legend-item mc-legend-ramp",
2879
+ children: [
2880
+ /* @__PURE__ */ l("span", {
2881
+ className: "mc-ramp-sw",
2882
+ "data-cov": "0"
2883
+ }),
2884
+ /* @__PURE__ */ l("span", {
2885
+ className: "mc-ramp-sw",
2886
+ "data-cov": "1"
2887
+ }),
2888
+ /* @__PURE__ */ l("span", {
2889
+ className: "mc-ramp-sw",
2890
+ "data-cov": "2"
2891
+ }),
2892
+ /* @__PURE__ */ l("span", {
2893
+ className: "mc-ramp-sw",
2894
+ "data-cov": "3"
2895
+ }),
2896
+ /* @__PURE__ */ l("span", {
2897
+ className: "mc-ramp-sw",
2898
+ "data-cov": "4"
2899
+ }),
2900
+ "coverage"
2901
+ ]
2902
+ }),
2903
+ /* @__PURE__ */ u("span", {
2904
+ className: "mc-legend-item mc-legend-viol",
2905
+ children: [/* @__PURE__ */ l(ie, { className: "lucide" }), " violation"]
2906
+ })
2907
+ ]
2908
+ })
2909
+ ] })
2910
+ })
2911
+ ]
2912
+ });
2913
+ function Et(e) {
2914
+ let t = e.kind === "file" && P !== "files" ? "files" : P, n = new Set(t === P ? F : []), r = z.parentIdByChild.get(e.id);
2915
+ for (; r && z.byId.has(r);) n.has(r) || (n.add(r), ce?.(r)), r = z.parentIdByChild.get(r);
2916
+ let i = Array.from(n);
2917
+ T || (_e(t), ye(n)), w?.({
2918
+ type: "reveal",
2919
+ id: e.id,
2920
+ grain: Bn[t],
2921
+ expandedIds: i
2922
+ }), t !== P && se?.(t), S?.(i), Oe(""), k(!1), Se(e.id), T || xe(e.id), oe?.(e.id, sr(e)), window.requestAnimationFrame(() => {
2923
+ window.requestAnimationFrame(() => K(e.id));
2924
+ });
2925
+ }
2926
+ }
2927
+ function sr(e) {
2928
+ let { _order: t, ...n } = e;
2929
+ return n;
2930
+ }
2931
+ function cr(e) {
2932
+ return e ? e instanceof Set ? new Set(e) : new Set(Array.from(e)) : /* @__PURE__ */ new Set();
2933
+ }
2934
+ function lr(e) {
2935
+ return Jt(e);
2936
+ }
2937
+ function $(e, t) {
2938
+ return Number.isFinite(e) ? e : t;
2939
+ }
2940
+ function ur(e) {
2941
+ return e ? Array.from(e).map(String).sort().join("\0") : "";
2942
+ }
2943
+ function dr(e, t, n = "plain") {
2944
+ return n === "arrow" ? `${e}->${t}` : `${e}→${t}`;
2945
+ }
2946
+ function fr(e) {
2947
+ return String(e).replace(/[^a-zA-Z0-9_-]/g, "_");
2948
+ }
2949
+ function pr(e, t = {}) {
2950
+ let { selected: n, expanded: r, violations: i = 0 } = t, a = Kn(e.coverage), o = `${qn(e.label || e.id)}: ${e.kind} · coverage ${a} of 4`;
2951
+ return e.loc && (o += ` · ${e.loc} loc`), i > 0 && (o += ` · ${i} violation${i === 1 ? "" : "s"}`), n && (o += " · selected"), r && (o += " · expanded"), o;
2952
+ }
2953
+ function mr(e, t, n, r, i) {
2954
+ if (!t) return;
2955
+ let a = e.x * n + r.x, o = e.y * n + r.y, s = (e.x + e.w) * n + r.x, c = (e.y + e.h) * n + r.y, l = 0, u = 0;
2956
+ a < 24 ? l = 24 - a : s > t.clientWidth - 24 && (l = t.clientWidth - 24 - s), o < 24 ? u = 24 - o : c > t.clientHeight - 24 && (u = t.clientHeight - 24 - c), (l !== 0 || u !== 0) && i({
2957
+ x: r.x + l,
2958
+ y: r.y + u
2959
+ });
2960
+ }
2961
+ function hr({ domId: e, p: t, selected: n, focused: r, highlighted: i, delta: a, expandable: o, expanded: s, violations: c, onClick: d, onDoubleClick: f }) {
2962
+ let p = t.node, m = Kn(p.coverage);
2963
+ return /* @__PURE__ */ u("button", {
2964
+ id: e,
2965
+ type: "button",
2966
+ className: "mc-node",
2967
+ "data-cov": m,
2968
+ "data-selected": n ? "true" : void 0,
2969
+ "data-focused": r ? "true" : void 0,
2970
+ "data-highlighted": i ? "true" : void 0,
2971
+ "data-delta": a || void 0,
2972
+ "data-ink-flip": m >= Gn ? "true" : void 0,
2973
+ "aria-label": pr(p, {
2974
+ selected: n,
2975
+ expanded: s,
2976
+ violations: c
2977
+ }),
2978
+ "aria-pressed": n,
2979
+ "aria-expanded": o ? s : void 0,
2980
+ style: {
2981
+ left: t.x,
2982
+ top: t.y,
2983
+ width: t.w,
2984
+ height: t.h
2985
+ },
2986
+ onPointerDown: (e) => e.stopPropagation(),
2987
+ onClick: (e) => {
2988
+ e.stopPropagation(), d(e.detail);
2989
+ },
2990
+ onDoubleClick: (e) => {
2991
+ e.stopPropagation(), f();
2992
+ },
2993
+ children: [
2994
+ n && /* @__PURE__ */ l("span", {
2995
+ className: "mc-node-marker",
2996
+ "aria-hidden": "true"
2997
+ }),
2998
+ /* @__PURE__ */ u("span", {
2999
+ className: "mc-node-head",
3000
+ children: [
3001
+ p.kind === "folder" ? /* @__PURE__ */ l(_, {
3002
+ className: "lucide mc-node-ico",
3003
+ "aria-hidden": "true"
3004
+ }) : /* @__PURE__ */ l(ee, {
3005
+ className: "lucide mc-node-ico",
3006
+ "aria-hidden": "true"
3007
+ }),
3008
+ /* @__PURE__ */ l("span", {
3009
+ className: "mc-node-name mono",
3010
+ children: qn(p.label || p.id)
3011
+ }),
3012
+ c > 0 && /* @__PURE__ */ u("span", {
3013
+ className: "mc-node-viol mono tnum",
3014
+ "aria-hidden": "true",
3015
+ children: [/* @__PURE__ */ l(ie, {
3016
+ className: "lucide",
3017
+ "aria-hidden": "true"
3018
+ }), c]
3019
+ })
3020
+ ]
3021
+ }),
3022
+ /* @__PURE__ */ u("span", {
3023
+ className: "mc-node-meta mono tnum",
3024
+ children: [
3025
+ p.kind === "folder" && o ? s ? "open" : "folder" : "file",
3026
+ p.loc ? ` · ${p.loc} loc` : "",
3027
+ ` · cov ${m}/4`
3028
+ ]
3029
+ })
3030
+ ]
3031
+ });
3032
+ }
3033
+ function gr({ a: e, b: t, kind: n, weight: r, maxWeight: i, delta: a }) {
3034
+ let o = e.x + e.w / 2, s = e.y + e.h, c = t.x + t.w / 2, d = t.y, f = (s + d) / 2, p = `M ${o} ${s} L ${o} ${f} L ${c} ${f} L ${c} ${d}`, m = 1 + Math.min(r, i) / i * 2;
3035
+ return /* @__PURE__ */ u("g", {
3036
+ className: "mc-edge",
3037
+ "data-kind": n,
3038
+ "data-delta": a || void 0,
3039
+ children: [/* @__PURE__ */ l("path", {
3040
+ className: "mc-edge-path",
3041
+ d: p,
3042
+ style: { strokeWidth: m }
3043
+ }), n === "structure" && /* @__PURE__ */ l("path", {
3044
+ className: "mc-edge-head",
3045
+ d: `M ${c - 4} ${d - 6} L ${c + 4} ${d - 6} L ${c} ${d} Z`
3046
+ })]
3047
+ });
3048
+ }
3049
+ //#endregion
3050
+ //#region src/ui/RailShell.jsx
3051
+ function _r({ toolbar: e, children: t, rail: n, railSide: i = "right", sheetTitle: a = "details", sheetMeta: o, className: c = "" }) {
3052
+ let [d, p] = s(!1), m = `rs-sheet-${r()}`;
3053
+ return /* @__PURE__ */ u("div", {
3054
+ className: `rs rs--${i}${c ? ` ${c}` : ""}`,
3055
+ "data-sheet-open": d ? "true" : "false",
3056
+ children: [/* @__PURE__ */ u("div", {
3057
+ className: "rs-frame",
3058
+ children: [/* @__PURE__ */ u("div", {
3059
+ className: "rs-main",
3060
+ children: [e && /* @__PURE__ */ l("div", {
3061
+ className: "rs-toolbar",
3062
+ children: e
3063
+ }), /* @__PURE__ */ l("div", {
3064
+ className: "rs-canvas",
3065
+ children: t
3066
+ })]
3067
+ }), /* @__PURE__ */ l("aside", {
3068
+ className: "rs-rail",
3069
+ "aria-label": a,
3070
+ children: /* @__PURE__ */ l("div", {
3071
+ className: "rs-rail-card",
3072
+ children: n
3073
+ })
3074
+ })]
3075
+ }), /* @__PURE__ */ u("div", {
3076
+ className: "rs-sheet",
3077
+ "aria-label": a,
3078
+ children: [/* @__PURE__ */ u("button", {
3079
+ type: "button",
3080
+ className: "rs-sheet-toggle",
3081
+ "aria-expanded": d,
3082
+ "aria-controls": m,
3083
+ onClick: () => p((e) => !e),
3084
+ children: [/* @__PURE__ */ l("span", {
3085
+ className: "rs-sheet-grip",
3086
+ "aria-hidden": "true"
3087
+ }), /* @__PURE__ */ u("span", {
3088
+ className: "rs-sheet-row",
3089
+ children: [/* @__PURE__ */ l("span", {
3090
+ className: "rs-sheet-title",
3091
+ children: a
3092
+ }), /* @__PURE__ */ u("span", {
3093
+ className: "rs-sheet-end",
3094
+ children: [o && /* @__PURE__ */ l("span", {
3095
+ className: "rs-sheet-meta",
3096
+ children: o
3097
+ }), /* @__PURE__ */ l(f, {
3098
+ className: "rs-sheet-chevron lucide",
3099
+ "aria-hidden": "true"
3100
+ })]
3101
+ })]
3102
+ })]
3103
+ }), /* @__PURE__ */ l("div", {
3104
+ id: m,
3105
+ role: "region",
3106
+ "aria-label": a,
3107
+ className: "rs-sheet-body",
3108
+ hidden: !d,
3109
+ children: n
3110
+ })]
3111
+ })]
3112
+ });
3113
+ }
3114
+ function vr({ title: e, icon: t, meta: n, children: i, collapsible: a = !1, defaultOpen: o = !0, className: d = "" }) {
3115
+ let [f, p] = s(o), h = `rs-sec-${r()}`, g = /* @__PURE__ */ u(c, { children: [
3116
+ t && /* @__PURE__ */ l(t, {
3117
+ className: "rs-sec-icon lucide",
3118
+ "aria-hidden": "true"
3119
+ }),
3120
+ e && /* @__PURE__ */ l("span", {
3121
+ className: "rs-sec-title",
3122
+ children: e
3123
+ }),
3124
+ /* @__PURE__ */ u("span", {
3125
+ className: "rs-sec-end",
3126
+ children: [n && /* @__PURE__ */ l("span", {
3127
+ className: "rs-sec-meta",
3128
+ children: n
3129
+ }), a && /* @__PURE__ */ l(m, {
3130
+ className: "rs-sec-chevron lucide",
3131
+ "aria-hidden": "true"
3132
+ })]
3133
+ })
3134
+ ] });
3135
+ return /* @__PURE__ */ u("section", {
3136
+ className: `rs-sec${a ? " rs-sec--collapsible" : ""}${f ? " is-open" : ""}${d ? ` ${d}` : ""}`,
3137
+ children: [a ? /* @__PURE__ */ l("button", {
3138
+ type: "button",
3139
+ className: "rs-sec-head rs-sec-head--button",
3140
+ "aria-expanded": f,
3141
+ "aria-controls": h,
3142
+ onClick: () => p((e) => !e),
3143
+ children: g
3144
+ }) : /* @__PURE__ */ l("div", {
3145
+ className: "rs-sec-head",
3146
+ children: g
3147
+ }), /* @__PURE__ */ l("div", {
3148
+ id: a ? h : void 0,
3149
+ className: "rs-sec-body",
3150
+ hidden: a ? !f : void 0,
3151
+ children: i
3152
+ })]
3153
+ });
3154
+ }
3155
+ function yr({ title: e, icon: t, meta: n, children: i, defaultOpen: a = !0 }) {
3156
+ let [o, c] = s(a), d = `rs-split-${r()}`;
3157
+ return /* @__PURE__ */ u("section", {
3158
+ className: `rs-split-panel${o ? " is-open" : ""}`,
3159
+ children: [/* @__PURE__ */ u("button", {
3160
+ type: "button",
3161
+ className: "rs-split-head",
3162
+ "aria-expanded": o,
3163
+ "aria-controls": d,
3164
+ onClick: () => c((e) => !e),
3165
+ children: [
3166
+ t && /* @__PURE__ */ l(t, {
3167
+ className: "rs-sec-icon lucide",
3168
+ "aria-hidden": "true"
3169
+ }),
3170
+ e && /* @__PURE__ */ l("span", {
3171
+ className: "rs-sec-title",
3172
+ children: e
3173
+ }),
3174
+ /* @__PURE__ */ u("span", {
3175
+ className: "rs-sec-end",
3176
+ children: [n && /* @__PURE__ */ l("span", {
3177
+ className: "rs-sec-meta",
3178
+ children: n
3179
+ }), /* @__PURE__ */ l(m, {
3180
+ className: "rs-sec-chevron lucide",
3181
+ "aria-hidden": "true"
3182
+ })]
3183
+ })
3184
+ ]
3185
+ }), /* @__PURE__ */ l("div", {
3186
+ id: d,
3187
+ className: "rs-split-body",
3188
+ hidden: !o,
3189
+ children: i
3190
+ })]
3191
+ });
3192
+ }
3193
+ function br({ left: e, right: t, leftTitle: n = "outline", rightTitle: r = "filters", leftIcon: i, rightIcon: a, leftMeta: o, rightMeta: s, className: c = "" }) {
3194
+ return /* @__PURE__ */ u("div", {
3195
+ className: `rs-split${c ? ` ${c}` : ""}`,
3196
+ children: [/* @__PURE__ */ l(yr, {
3197
+ title: n,
3198
+ icon: i,
3199
+ meta: o,
3200
+ children: e
3201
+ }), /* @__PURE__ */ l(yr, {
3202
+ title: r,
3203
+ icon: a,
3204
+ meta: s,
3205
+ children: t
3206
+ })]
3207
+ });
3208
+ }
3209
+ //#endregion
3210
+ //#region src/ui/inuse/InUseShell.jsx
3211
+ var xr = Object.freeze([
3212
+ {
3213
+ id: "transcript",
3214
+ mark: "transcript-browser",
3215
+ icon: x
3216
+ },
3217
+ {
3218
+ id: "commons",
3219
+ mark: "village",
3220
+ icon: ae
3221
+ },
3222
+ {
3223
+ id: "graph",
3224
+ mark: "peasant",
3225
+ icon: oe
3226
+ }
3227
+ ]), Sr = Object.freeze([
3228
+ {
3229
+ id: "analytics",
3230
+ label: "analytics"
3231
+ },
3232
+ {
3233
+ id: "changes",
3234
+ label: "changes"
3235
+ },
3236
+ {
3237
+ id: "map",
3238
+ label: "code map"
3239
+ }
3240
+ ]);
3241
+ function Cr(e) {
3242
+ return e && (/(INPUT|TEXTAREA|SELECT)/.test(e.tagName) || e.isContentEditable);
3243
+ }
3244
+ function wr({ apps: e = xr, defaultApp: t, activeApp: n, onAppChange: r, renderApp: i, brand: a = "fairtrade", ariaLabel: c = "the design system in use" }) {
3245
+ let [d, f] = s(t ?? e[0]?.id), p = n ?? d, m = o({}), h = (e) => {
3246
+ n === void 0 && f(e), r?.(e);
3247
+ }, g = e.find((e) => e.id === p) ?? e[0];
3248
+ return /* @__PURE__ */ u("section", {
3249
+ className: "iu",
3250
+ id: "inuse",
3251
+ "aria-label": c,
3252
+ onKeyDown: (t) => {
3253
+ if (Cr(t.target)) return;
3254
+ let n = {
3255
+ 1: 0,
3256
+ 2: 1,
3257
+ 3: 2
3258
+ }[t.key];
3259
+ n != null && e[n] && (t.preventDefault(), h(e[n].id));
3260
+ },
3261
+ children: [/* @__PURE__ */ u("div", {
3262
+ className: "iu-bar",
3263
+ children: [/* @__PURE__ */ u("div", {
3264
+ className: "iu-bar-brand",
3265
+ children: [/* @__PURE__ */ l("svg", {
3266
+ className: "logo",
3267
+ width: "18",
3268
+ height: "18",
3269
+ viewBox: "0 0 32 32",
3270
+ "aria-hidden": "true",
3271
+ children: /* @__PURE__ */ l("use", { href: "#logo" })
3272
+ }), /* @__PURE__ */ l("span", { children: a })]
3273
+ }), /* @__PURE__ */ l("div", {
3274
+ className: "iu-switch",
3275
+ role: "tablist",
3276
+ "aria-label": "apps",
3277
+ "aria-orientation": "horizontal",
3278
+ onKeyDown: (t) => {
3279
+ let n = e.map((e) => e.id), r = n.indexOf(g?.id);
3280
+ if (r < 0) return;
3281
+ let i = r;
3282
+ if (t.key === "ArrowRight" || t.key === "ArrowDown") i = (r + 1) % n.length;
3283
+ else if (t.key === "ArrowLeft" || t.key === "ArrowUp") i = (r - 1 + n.length) % n.length;
3284
+ else if (t.key === "Home") i = 0;
3285
+ else if (t.key === "End") i = n.length - 1;
3286
+ else return;
3287
+ t.preventDefault(), h(n[i]), m.current[n[i]]?.focus();
3288
+ },
3289
+ children: e.map((e, t) => {
3290
+ let n = e.icon, r = e.id === g?.id;
3291
+ return /* @__PURE__ */ u("button", {
3292
+ type: "button",
3293
+ role: "tab",
3294
+ id: "iu-tab-" + e.id,
3295
+ "aria-selected": r ? "true" : "false",
3296
+ "aria-controls": "inuse-stage",
3297
+ tabIndex: r ? 0 : -1,
3298
+ ref: (t) => {
3299
+ m.current[e.id] = t;
3300
+ },
3301
+ className: "iu-opt" + (r ? " iu-opt-on" : ""),
3302
+ onClick: () => h(e.id),
3303
+ children: [
3304
+ n ? /* @__PURE__ */ l("span", {
3305
+ className: "iu-opt-ico",
3306
+ children: /* @__PURE__ */ l(n, {
3307
+ size: 16,
3308
+ "aria-hidden": "true"
3309
+ })
3310
+ }) : null,
3311
+ /* @__PURE__ */ l("span", {
3312
+ className: "iu-opt-label",
3313
+ children: e.mark
3314
+ }),
3315
+ /* @__PURE__ */ l("span", {
3316
+ className: "iu-opt-key",
3317
+ "aria-hidden": "true",
3318
+ children: t + 1
3319
+ })
3320
+ ]
3321
+ }, e.id);
3322
+ })
3323
+ })]
3324
+ }), /* @__PURE__ */ l("div", {
3325
+ className: "iu-stage",
3326
+ id: "inuse-stage",
3327
+ role: "tabpanel",
3328
+ "aria-labelledby": "iu-tab-" + g?.id,
3329
+ tabIndex: -1,
3330
+ children: /* @__PURE__ */ l("div", {
3331
+ className: "iu-screen",
3332
+ children: g ? i?.(g.id) : null
3333
+ }, g?.id)
3334
+ })]
3335
+ });
3336
+ }
3337
+ function Tr({ sections: e = Sr, activeId: t, activePrimaryId: n, onSectionChange: r, backTo: i, onBack: a, children: o, ariaLabel: s = "peasant sections" }) {
3338
+ let c = n ?? t;
3339
+ return /* @__PURE__ */ u("div", {
3340
+ className: "iu-app-root",
3341
+ children: [/* @__PURE__ */ u("nav", {
3342
+ className: "iu-subnav",
3343
+ "aria-label": s,
3344
+ children: [i ? /* @__PURE__ */ u("button", {
3345
+ type: "button",
3346
+ className: "iu-subnav-back",
3347
+ onClick: () => a ? a(i) : r?.(i),
3348
+ children: [/* @__PURE__ */ l(p, {
3349
+ size: 14,
3350
+ "aria-hidden": "true"
3351
+ }), " back"]
3352
+ }) : null, e.map((e) => /* @__PURE__ */ l("button", {
3353
+ type: "button",
3354
+ className: "iu-subnav-item" + (c === e.id ? " active" : ""),
3355
+ "aria-current": t === e.id ? "page" : void 0,
3356
+ onClick: () => r?.(e.id),
3357
+ children: e.label
3358
+ }, e.id))]
3359
+ }), /* @__PURE__ */ l("div", {
3360
+ className: "iu-view",
3361
+ children: o
3362
+ })]
3363
+ });
3364
+ }
3365
+ function Er({ sections: e = Sr, activeId: t = void 0, hrefFor: n = void 0, LinkComponent: r = void 0, onSectionChange: i = void 0, className: a = "iu-subnav", itemClassName: o = "iu-subnav-item", activeItemClassName: s = "active", activeMarker: d = null, ariaLabel: f = "peasant sections" }) {
3366
+ return /* @__PURE__ */ l("nav", {
3367
+ className: a,
3368
+ "aria-label": f,
3369
+ children: e.map((e) => {
3370
+ let a = t === e.id, f = o + (a && s ? " " + s : ""), p = /* @__PURE__ */ u(c, { children: [e.label, a ? d : null] }), m = n?.(e);
3371
+ return m && r ? /* @__PURE__ */ l(r, {
3372
+ href: m,
3373
+ className: f,
3374
+ "aria-current": a ? "page" : void 0,
3375
+ title: e.title,
3376
+ children: p
3377
+ }, e.id) : m ? /* @__PURE__ */ l("a", {
3378
+ href: m,
3379
+ className: f,
3380
+ "aria-current": a ? "page" : void 0,
3381
+ title: e.title,
3382
+ children: p
3383
+ }, e.id) : /* @__PURE__ */ l("button", {
3384
+ type: "button",
3385
+ className: f,
3386
+ "aria-current": a ? "page" : void 0,
3387
+ onClick: () => i?.(e.id),
3388
+ children: p
3389
+ }, e.id);
3390
+ })
3391
+ });
3392
+ }
3393
+ //#endregion
3394
+ export { We as $, Ht as A, rt as B, yt as C, Ot as D, kt as E, Vt as F, st as G, it as H, Nt as I, tt as J, ct as K, J as L, At as M, jt as N, Mt as O, Wt as P, B as Q, lt as R, bt as S, xt as T, at as U, ot as V, nt as W, U as X, Ze as Y, V as Z, sn as _, Te as _t, wr as a, L as at, gt as b, br as c, ze as ct, Y as d, Ie as dt, z as et, an as f, je as ft, Jt as g, A as gt, cn as h, M as ht, xr as i, I as it, Gt as j, Dt as k, or as l, N as lt, dn as m, Pe as mt, Tr as n, R as nt, vr as o, Ve as ot, X as p, Me as pt, q, Er as r, P as rt, _r as s, Le as st, Sr as t, Ue as tt, qt as u, Re as ut, ln as v, we as vt, vt as w, ht as x, _t as y, ut as z };