@aiquants/markdown-explorer 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +63 -6
  3. package/dist/ExplorerSplit-CWcK1E4I.js +1495 -0
  4. package/dist/ExplorerSplit-ajN3GSdA.cjs +1 -0
  5. package/dist/MultiLayout-BtWtCzJV.js +922 -0
  6. package/dist/MultiLayout-DvkcdO9c.cjs +1 -0
  7. package/dist/NativeScrollBar-DbzyQ85y.cjs +1 -0
  8. package/dist/NativeScrollBar-apXjIKRW.js +59 -0
  9. package/dist/TreeLayout-BcHsv9G8.js +23 -0
  10. package/dist/TreeLayout-rwhJfLmU.cjs +1 -0
  11. package/dist/core/config.d.cts +11 -0
  12. package/dist/core/config.d.ts +11 -0
  13. package/dist/core/contracts.d.cts +21 -0
  14. package/dist/core/contracts.d.ts +21 -0
  15. package/dist/core/labels.d.cts +5 -1
  16. package/dist/core/labels.d.ts +5 -1
  17. package/dist/core/treeSettings.d.cts +4 -2
  18. package/dist/core/treeSettings.d.ts +4 -2
  19. package/dist/{dataRoute-zUX-oR9j.js → dataRoute-Btg4w3vO.js} +79 -69
  20. package/dist/dataRoute-DHpu0fg2.cjs +1 -0
  21. package/dist/{index-BJTmp0lR.js → index-CIZw73j9.js} +702 -655
  22. package/dist/index-Cie6WPiM.cjs +3 -0
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.d.cts +2 -2
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.js +22 -21
  27. package/dist/location-CSIhx-L4.cjs +1 -0
  28. package/dist/{location-V5BKeWNs.js → location-c1zdeySY.js} +202 -187
  29. package/dist/sanitizeWorker.cjs +1 -1
  30. package/dist/sanitizeWorker.js +1 -1
  31. package/dist/scrollBarGeometry-C46jBtmM.cjs +1 -0
  32. package/dist/scrollBarGeometry-DOBdGNV-.js +4 -0
  33. package/dist/server/errors.d.cts +1 -1
  34. package/dist/server/errors.d.ts +1 -1
  35. package/dist/server/fileSystemSource.d.cts +1 -0
  36. package/dist/server/fileSystemSource.d.ts +1 -0
  37. package/dist/server/ports.d.cts +4 -0
  38. package/dist/server/ports.d.ts +4 -0
  39. package/dist/server.cjs +1 -1
  40. package/dist/server.d.cts +1 -1
  41. package/dist/server.d.ts +1 -1
  42. package/dist/server.js +749 -696
  43. package/dist/styles/markdown-explorer.css +1 -1
  44. package/dist/tapScrollCircle-C5DGI-0H.cjs +1 -0
  45. package/dist/tapScrollCircle-u4EXeLhx.js +6 -0
  46. package/docs/behavior/dom-hooks.md +3 -1
  47. package/docs/behavior/layout.md +2 -0
  48. package/docs/behavior/localization.md +1 -0
  49. package/docs/behavior/security.md +1 -1
  50. package/docs/behavior/url-contract.md +1 -0
  51. package/package.json +7 -7
  52. package/dist/ExplorerSplit-B7pmzR8t.js +0 -1362
  53. package/dist/ExplorerSplit-Bi3yU6NG.cjs +0 -1
  54. package/dist/MultiLayout-BxeXOLX1.js +0 -909
  55. package/dist/MultiLayout-DtFrFRmS.cjs +0 -1
  56. package/dist/TreeLayout-BQUfVNlA.cjs +0 -1
  57. package/dist/TreeLayout-D6hCSihW.js +0 -22
  58. package/dist/dataRoute-B9Wk-G7A.cjs +0 -1
  59. package/dist/index-DkiGlM7C.cjs +0 -3
  60. package/dist/location-DfYTzfFS.cjs +0 -1
@@ -0,0 +1,922 @@
1
+ import { jsxs as re, jsx as T } from "react/jsx-runtime";
2
+ import { createContext as Ge, use as Me, useRef as B, useState as V, useLayoutEffect as q, useMemo as _, useSyncExternalStore as We, useCallback as D, memo as Ke, useEffect as $, useImperativeHandle as Je } from "react";
3
+ import { g as se, e as Te, h as Xe, P as Ze, j as Qe } from "./location-c1zdeySY.js";
4
+ import { c as en, u as G, e as nn, I as tn, D as on, b as rn, f as ln, L as Le } from "./index-CIZw73j9.js";
5
+ import { S as sn, a as an, b as cn } from "./ExplorerSplit-CWcK1E4I.js";
6
+ import { SCROLL_AREA_SELECTOR as Ie, SCROLL_ROOT_SELECTOR as Q, generateColumnIds as un, sortColumnIds as Ae, generateColumnId as De, NO_PANEL_DRAG_ATTRIBUTE as dn, useDragDropColumns as mn, DEFAULT_DEBUG_CONFIG as ge, DragDropLayout as fn } from "@aiquants/drag-drop-panels";
7
+ import { useNavigate as pn, useLocation as gn } from "react-router";
8
+ import { s as hn, r as vn, w as wn } from "./storage-DA4ItHzl.js";
9
+ import { v as yn, i as Sn } from "./dataRoute-Btg4w3vO.js";
10
+ import { createPortal as xn } from "react-dom";
11
+ import { HostedScrollArea as En } from "@aiquants/markdown";
12
+ import { N as bn } from "./scrollBarGeometry-DOBdGNV-.js";
13
+ const On = () => {
14
+ const e = /* @__PURE__ */ new Map();
15
+ return {
16
+ hold: (n, t) => {
17
+ e.set(n, t), queueMicrotask(() => {
18
+ e.get(n) === t && e.delete(n);
19
+ });
20
+ },
21
+ take: (n) => {
22
+ const t = e.get(n);
23
+ return e.delete(n), t === void 0 ? null : t;
24
+ }
25
+ };
26
+ }, Re = Ge(null), ie = () => {
27
+ const e = Me(Re);
28
+ if (e === null) throw new Error("[markdown-explorer] multi-view panels must be rendered inside the multi-view stage");
29
+ return e;
30
+ }, Pn = (e, n) => {
31
+ const t = e.pendingHashes.get(n);
32
+ return t === void 0 ? null : t;
33
+ }, Cn = 0xcbf29ce484222325n, Nn = 0x100000001b3n, Mn = (1n << 64n) - 1n, Tn = (1n << 53n) - 1n, Ln = new TextEncoder(), In = (e) => {
34
+ let n = Cn;
35
+ for (const t of Ln.encode(e))
36
+ n = (n ^ BigInt(t)) * Nn & Mn;
37
+ return Number(n & Tn);
38
+ }, ee = 256, An = (e) => `aqmx-p-${In(e).toString(36)}`, _e = (e, n) => {
39
+ const t = An(e);
40
+ let o = t;
41
+ for (let r = 2; n.has(o); r += 1) o = `${t}-${String(r)}`;
42
+ return o;
43
+ }, Dn = /* @__PURE__ */ new Map(), Rn = (e, n = Dn) => {
44
+ const t = new Set(e.flatMap((r) => n.get(r) ?? [])), o = /* @__PURE__ */ new Map();
45
+ for (const r of e) {
46
+ const l = n.get(r) ?? _e(r, t);
47
+ t.add(l), o.set(r, l);
48
+ }
49
+ return o;
50
+ }, ze = (e, n, t) => {
51
+ const o = e.columnOf.get(n);
52
+ return o === void 0 ? void 0 : Math.min(t - 1, Math.max(0, o));
53
+ }, ke = (e, n) => {
54
+ const [t, ...o] = se(n.logical, n.visible);
55
+ if (t === void 0) throw new RangeError("[markdown-explorer] there must be at least one visible column");
56
+ const r = ([c, m]) => e.slice(c, m).reduce((a, p) => a + p.length, 0);
57
+ let l = t;
58
+ for (const c of o) r(c) < r(l) && (l = c);
59
+ let s = l[0];
60
+ for (let c = l[0]; c < l[1]; c += 1) (e[c]?.length ?? 0) < (e[s]?.length ?? 0) && (s = c);
61
+ return s;
62
+ }, ne = (e, n) => {
63
+ const t = Array.from({ length: n.logical }, () => []), o = [];
64
+ for (const r of e.docs) {
65
+ const l = ze(e, r, n.logical);
66
+ l === void 0 ? o.push(r) : t[l]?.push(r);
67
+ }
68
+ for (const r of o) t[ke(t, n)]?.push(r);
69
+ return t;
70
+ }, _n = (e, n) => se(e.length, n).map(([t, o]) => e.slice(t, o).flat()), zn = (e, n, t) => {
71
+ const [o, r] = n, l = r - o, s = e.length, c = Array.from({ length: l }, (u, f) => {
72
+ const d = [0];
73
+ for (const E of e) d.push((d.at(-1) ?? 0) + (t(E) === o + f ? 1 : 0));
74
+ return d;
75
+ }), m = (u, f, d) => (c[u]?.[d] ?? 0) - (c[u]?.[f] ?? 0), a = Array.from({ length: l + 1 }, () => Array.from({ length: s + 1 }, () => Number.NEGATIVE_INFINITY)), p = Array.from({ length: l + 1 }, () => Array.from({ length: s + 1 }, () => 0)), w = a[0];
76
+ w && (w[0] = 0);
77
+ for (let u = 0; u < l; u += 1)
78
+ for (let f = 0; f <= s; f += 1)
79
+ for (let d = 0; d <= f; d += 1) {
80
+ const E = (a[u]?.[d] ?? Number.NEGATIVE_INFINITY) + m(u, d, f), y = a[u + 1], M = p[u + 1];
81
+ y && M && E > (y[f] ?? Number.NEGATIVE_INFINITY) && (y[f] = E, M[f] = d);
82
+ }
83
+ const C = Array.from({ length: l }, () => []);
84
+ let x = s;
85
+ for (let u = l; u > 0; u -= 1) {
86
+ const f = p[u]?.[x] ?? 0;
87
+ C[u - 1] = e.slice(f, x), x = f;
88
+ }
89
+ return C;
90
+ }, He = (e, n) => {
91
+ const t = n.flat(), o = new Map(e.columnOf);
92
+ for (const [r, l] of n.entries())
93
+ for (const s of l)
94
+ o.delete(s), o.set(s, r);
95
+ for (const r of o.keys()) {
96
+ if (o.size <= ee) break;
97
+ o.delete(r);
98
+ }
99
+ return { docs: t, columnOf: o };
100
+ }, kn = (e, n, t, o) => {
101
+ if (e.docs.includes(n)) return { state: e, outcome: "existing" };
102
+ if (e.docs.length >= o) return { state: e, outcome: "rejected" };
103
+ const r = ne(e, t), l = ze(e, n, t.logical) ?? ke(r, t);
104
+ r[l]?.push(n);
105
+ const s = new Map(e.panelIds);
106
+ return s.set(n, _e(n, new Set(s.values()))), { state: { ...e, ...He(e, r), panelIds: s }, outcome: "opened" };
107
+ }, Be = (e, n) => {
108
+ if (!e.docs.includes(n)) return e;
109
+ const t = new Set(e.hidden);
110
+ t.delete(n);
111
+ const o = new Map(e.panelIds);
112
+ return o.delete(n), { ...e, docs: e.docs.filter((r) => r !== n), hidden: t, panelIds: o, maximized: e.maximized === n ? null : e.maximized };
113
+ }, Hn = (e, n, t, o) => {
114
+ if (e.hidden.has(n)) return { state: qe(e, n, !1), outcome: "shown" };
115
+ if (e.docs.includes(n)) return { state: Be(e, n), outcome: "closed" };
116
+ const r = kn(e, n, t, o);
117
+ return { state: r.state, outcome: r.outcome === "rejected" ? "rejected" : "opened" };
118
+ }, Bn = (e, n, t) => {
119
+ if (n === t || !e.docs.includes(n)) return { state: e, outcome: "ignored" };
120
+ if (e.docs.includes(t)) return { state: e, outcome: "existing" };
121
+ const o = new Map(e.columnOf), r = o.get(n);
122
+ r !== void 0 && (o.delete(t), o.set(t, r));
123
+ const l = new Set(e.hidden);
124
+ l.delete(n);
125
+ const s = new Map(e.panelIds), c = s.get(n);
126
+ if (c === void 0) throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);
127
+ return s.delete(n), s.set(t, c), {
128
+ state: { docs: e.docs.map((m) => m === n ? t : m), maximized: e.maximized === n ? t : e.maximized, columnOf: o, hidden: l, panelIds: s },
129
+ outcome: "navigated"
130
+ };
131
+ }, qe = (e, n, t) => {
132
+ if (!e.docs.includes(n) || e.hidden.has(n) === t) return e;
133
+ const o = new Set(e.hidden);
134
+ return t ? o.add(n) : o.delete(n), { ...e, hidden: o, maximized: t && e.maximized === n ? null : e.maximized };
135
+ }, qn = (e, n) => {
136
+ if (e.maximized === n || n !== null && !e.docs.includes(n)) return e;
137
+ if (n === null || !e.hidden.has(n)) return { ...e, maximized: n };
138
+ const t = new Set(e.hidden);
139
+ return t.delete(n), { ...e, maximized: n, hidden: t };
140
+ }, Fn = (e, n, t) => {
141
+ const o = ne(e, t), r = /* @__PURE__ */ new Map();
142
+ for (const [a, p] of o.entries())
143
+ for (const w of p) r.set(w, a);
144
+ const l = new Set(e.docs), s = /* @__PURE__ */ new Set(), c = se(t.logical, t.visible), m = Array.from({ length: t.logical }, () => []);
145
+ for (const [a, p] of c.entries()) {
146
+ const w = (n[a] ?? []).filter((C) => l.has(C) && !s.has(C));
147
+ for (const C of w) s.add(C);
148
+ for (const [C, x] of zn(w, p, (u) => r.get(u)).entries())
149
+ m[p[0] + C]?.push(...x);
150
+ }
151
+ for (const a of e.docs)
152
+ s.has(a) || m[r.get(a) ?? 0]?.push(a);
153
+ return m.every((a, p) => a.length === o[p]?.length && a.every((w, C) => o[p]?.[C] === w)) ? e : { ...e, ...He(e, m) };
154
+ }, te = (e, n) => {
155
+ const t = [...new Set(e.docs)].slice(0, n), o = new Set(t), r = e.maximized !== null && o.has(e.maximized) ? e.maximized : null;
156
+ return {
157
+ docs: t,
158
+ maximized: r,
159
+ columnOf: e.stored.columnOf,
160
+ hidden: new Set([...e.stored.hidden].filter((l) => o.has(l) && l !== r)),
161
+ panelIds: Rn(t, e.panelIds)
162
+ };
163
+ }, he = (e, n) => {
164
+ if (e.docs.every((o) => e.columnOf.has(o))) return e;
165
+ const t = new Map(e.columnOf);
166
+ for (const [o, r] of ne(e, n).entries())
167
+ for (const l of r)
168
+ t.delete(l), t.set(l, o);
169
+ for (const o of t.keys()) {
170
+ if (t.size <= ee) break;
171
+ t.delete(o);
172
+ }
173
+ return { ...e, columnOf: t };
174
+ }, Fe = 1, U = Object.freeze({ columnOf: /* @__PURE__ */ new Map(), hidden: /* @__PURE__ */ new Set() }), Vn = (e, n) => {
175
+ if (e === null || e === "") return U;
176
+ let t;
177
+ try {
178
+ t = JSON.parse(e);
179
+ } catch {
180
+ return U;
181
+ }
182
+ if (t === null || typeof t != "object" || Array.isArray(t)) return U;
183
+ const o = t;
184
+ if (o.v !== Fe) return U;
185
+ const r = /* @__PURE__ */ new Map();
186
+ if (Array.isArray(o.columnOf))
187
+ for (const s of o.columnOf.slice(-ee))
188
+ Array.isArray(s) && s.length === 2 && typeof s[0] == "string" && s[0] !== "" && Number.isInteger(s[1]) && s[1] >= 0 && s[1] < n && (r.delete(s[0]), r.set(s[0], s[1]));
189
+ const l = new Set(Array.isArray(o.hidden) ? o.hidden.filter((s) => typeof s == "string" && s !== "") : []);
190
+ return { columnOf: r, hidden: l };
191
+ }, $n = (e) => JSON.stringify({
192
+ v: Fe,
193
+ columnOf: [...e.columnOf.entries()].slice(-ee),
194
+ hidden: e.docs.filter((n) => e.hidden.has(n))
195
+ }), ae = (e, n) => {
196
+ const t = e.get(n);
197
+ return t === void 0 ? yn(n) : t;
198
+ }, W = (e) => {
199
+ const n = /* @__PURE__ */ new Map();
200
+ for (const [t, o] of e.panelIds) n.set(o, t);
201
+ return n;
202
+ }, ve = (e) => {
203
+ if (!Sn(e)) throw new RangeError(`[markdown-explorer] not an acceptable document path: ${JSON.stringify(e.slice(0, 80))}`);
204
+ }, Un = ({ config: e, location: n, writeUrl: t, persist: o }) => {
205
+ const { maxPanels: r, columns: l } = e.multiView, s = en(), c = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
206
+ let a = {
207
+ layout: te({ docs: n.docs, maximized: n.maximized, stored: U }, r),
208
+ source: n.source,
209
+ visibleColumns: l,
210
+ ready: !1,
211
+ splitDragging: !1,
212
+ titles: /* @__PURE__ */ new Map(),
213
+ pendingHashes: /* @__PURE__ */ new Map()
214
+ }, p = !1;
215
+ const w = (i) => p ? he(i, { logical: l, visible: a.visibleColumns }) : i, C = (i, h) => Te(e, { view: "multi", source: i, docs: h.docs, maximized: h.maximized });
216
+ let x = C(n.source, n), u = n.source, f = x;
217
+ const d = [], E = [];
218
+ let y = null;
219
+ const M = () => {
220
+ if (!(d.length > 0))
221
+ for (const i of E.splice(0)) i();
222
+ }, g = (i) => {
223
+ a = { ...a, ...i }, s.emit();
224
+ }, b = () => {
225
+ if (!a.ready) return;
226
+ const i = $n(a.layout);
227
+ i !== y && (y = i, o(i));
228
+ }, v = (i, h, N) => {
229
+ const A = C(i, h);
230
+ A !== x && (x = A, u = i, d.push(A), t(A, N));
231
+ }, P = (i) => {
232
+ const h = new Set(i.panelIds.values());
233
+ for (const O of [...c.keys()]) h.has(O) || c.delete(O);
234
+ for (const O of [...m.keys()]) h.has(O) || m.delete(O);
235
+ const N = new Set(i.docs), A = [...a.titles.keys()].every((O) => N.has(O)) ? a.titles : new Map([...a.titles].filter(([O]) => N.has(O))), S = [...a.pendingHashes.keys()].every((O) => h.has(O)) ? a.pendingHashes : new Map([...a.pendingHashes].filter(([O]) => h.has(O)));
236
+ return { titles: A, pendingHashes: S };
237
+ }, L = (i) => i === a.layout ? !1 : (g({ layout: i, ...P(i) }), v(u, i, "replace"), b(), !0), I = () => ({ logical: l, visible: a.visibleColumns });
238
+ return {
239
+ getSnapshot: () => a,
240
+ subscribe: s.subscribe,
241
+ toggle: (i) => {
242
+ ve(i);
243
+ const { state: h, outcome: N } = Hn(a.layout, i, I(), r);
244
+ return L(h), N;
245
+ },
246
+ close: (i) => L(Be(a.layout, i)),
247
+ navigate: (i, h) => {
248
+ ve(h);
249
+ const { state: N, outcome: A } = Bn(a.layout, i, h);
250
+ if (A !== "navigated") return A;
251
+ const S = N.panelIds.get(h);
252
+ return S !== void 0 && (c.delete(S), m.delete(S)), L(N), A;
253
+ },
254
+ setHidden: (i, h) => L(qe(a.layout, i, h)),
255
+ maximize: (i) => L(qn(a.layout, i)),
256
+ arrange: (i) => L(Fn(a.layout, i, { logical: l, visible: i.length })),
257
+ changeSource: (i) => {
258
+ v(i, a.layout, "push");
259
+ },
260
+ revealSource: (i) => {
261
+ v(i, a.layout, "replace");
262
+ },
263
+ observeLocation: (i) => {
264
+ const h = C(i.source, i);
265
+ if (h === x)
266
+ return d.length = 0, f = h, i.source !== a.source && g({ source: i.source }), M(), !1;
267
+ if (h === f) return !1;
268
+ f = h;
269
+ const N = d.indexOf(h);
270
+ if (N >= 0)
271
+ return d.splice(0, N + 1), i.source !== a.source && g({ source: i.source }), M(), !1;
272
+ d.length = 0, x = h, u = i.source;
273
+ const A = w(te({ docs: i.docs, maximized: i.maximized, stored: { columnOf: a.layout.columnOf, hidden: a.layout.hidden }, panelIds: a.layout.panelIds }, r));
274
+ return g({ layout: A, source: i.source, ...P(A) }), b(), M(), !0;
275
+ },
276
+ whenUrlRendered: (i) => {
277
+ E.push(i), M();
278
+ },
279
+ loadStored: (i) => {
280
+ g({ layout: w(te({ docs: a.layout.docs, maximized: a.layout.maximized, stored: i, panelIds: a.layout.panelIds }, r)), ready: !0 }), b();
281
+ },
282
+ setVisibleColumns: (i) => {
283
+ if (!Number.isInteger(i) || i < 1 || i > l) throw new RangeError(`[markdown-explorer] visible columns must be an integer in 1..${String(l)}; got ${String(i)}`);
284
+ p = !0;
285
+ const h = he(a.layout, { logical: l, visible: i });
286
+ i === a.visibleColumns && h === a.layout || (g({ visibleColumns: i, layout: h }), h !== a.layout && b());
287
+ },
288
+ setSplitDragging: (i) => {
289
+ i !== a.splitDragging && g({ splitDragging: i });
290
+ },
291
+ setTitle: (i, h) => {
292
+ !a.layout.docs.includes(i) || a.titles.get(i) === h || g({ titles: new Map(a.titles).set(i, h) });
293
+ },
294
+ titleOf: (i) => ae(a.titles, i),
295
+ setPendingHash: (i, h) => {
296
+ const N = a.pendingHashes.get(i);
297
+ if (h === null || h === "") {
298
+ if (N === void 0) return;
299
+ const A = new Map(a.pendingHashes);
300
+ A.delete(i), g({ pendingHashes: A });
301
+ return;
302
+ }
303
+ N !== h && g({ pendingHashes: new Map(a.pendingHashes).set(i, h) });
304
+ },
305
+ saveReadingPosition: (i, h, N) => {
306
+ a.layout.panelIds.get(h) === i && c.set(i, { doc: h, position: N });
307
+ },
308
+ readingPositionOf: (i, h) => {
309
+ const N = c.get(i);
310
+ return N === void 0 || N.doc !== h ? null : N.position;
311
+ },
312
+ saveImageView: (i, h, N) => {
313
+ m.set(i, { url: h, state: N });
314
+ },
315
+ imageViewOf: (i, h) => {
316
+ const N = m.get(i);
317
+ return N === void 0 || N.url !== h ? null : N.state;
318
+ }
319
+ };
320
+ }, z = (e, n) => {
321
+ const t = () => n(e.getSnapshot());
322
+ return We(e.subscribe, t, t);
323
+ }, jn = (e) => {
324
+ const { config: n, storageNamespace: t } = G(), o = pn(), r = B(o), l = hn(t).multiLayout, [s] = V(
325
+ () => Un({
326
+ config: n,
327
+ location: e,
328
+ writeUrl: (a, p) => {
329
+ r.current(a, nn(p === "replace" ? "browse" : "switch-source"));
330
+ },
331
+ persist: (a) => wn(l, a)
332
+ })
333
+ );
334
+ q(() => {
335
+ r.current = o;
336
+ }, [o]);
337
+ const c = gn(), m = _(() => ({ location: e, navigated: c }), [e, c]);
338
+ return q(() => {
339
+ s.observeLocation(m.location);
340
+ }, [s, m]), q(() => {
341
+ s.loadStored(Vn(vn(l), n.multiView.columns));
342
+ }, [s, l, n]), s;
343
+ }, Yn = (e) => {
344
+ const n = e.closest(Ie);
345
+ if (n === null) throw new Error("[markdown-explorer] a panel's document region is not inside the panel's scroll area");
346
+ return n;
347
+ }, Gn = ({ docPath: e, panelId: n, maximized: t, title: o, onContentShown: r }) => {
348
+ const { store: l, followLink: s, revealInPanel: c } = ie(), { announcer: m } = G(), a = z(l, (y) => Pn(y, n)), p = D((y, M) => s(n, e, y, M), [s, n, e]), w = D(() => l.setPendingHash(n, null), [l, n]), C = _(() => ({ read: (y) => l.imageViewOf(n, y), save: (y, M) => l.saveImageView(n, y, M) }), [l, n]), x = D(
349
+ (y, M) => {
350
+ M.kind !== "failure" && l.setTitle(y, M.name), r(y);
351
+ },
352
+ [l, r]
353
+ ), u = D(
354
+ (y) => {
355
+ l.whenUrlRendered(() => m.announce(y));
356
+ },
357
+ [l, m]
358
+ ), f = _(() => ({ scrollerOf: Yn, reveal: (y) => c(n, y) }), [c, n]), d = _(
359
+ () => ({ kind: "panel", maximized: t, onDocumentLink: p, pendingHash: a, onHashConsumed: w, announceFailure: u, paneScroll: f }),
360
+ [t, p, a, w, u, f]
361
+ ), E = _(() => ({ kind: "panel", documentName: o }), [o]);
362
+ return /* @__PURE__ */ re(tn, { value: C, children: [
363
+ /* @__PURE__ */ T(on, { path: e, placement: E }),
364
+ /* @__PURE__ */ T(rn, { path: e, variant: d, onDocumentShown: x })
365
+ ] });
366
+ }, we = () => typeof HTMLElement < "u" && typeof HTMLElement.prototype.showPopover == "function" && typeof HTMLElement.prototype.hidePopover == "function", ce = "data-aqmx-column-probe", J = "data-panel-id", le = "--aqmx-multi-panel-chrome", F = (e) => e.endsWith("px") ? Number.parseFloat(e) : Number.NaN, Wn = (e) => e === "normal" ? 0 : F(e), Kn = (e, n) => {
367
+ const t = e.querySelector(Q)?.firstElementChild, o = e.querySelector(`[${ce}]`), r = o instanceof HTMLElement ? o.getBoundingClientRect().width : Number.NaN;
368
+ if (!(t instanceof HTMLElement))
369
+ return { plan: { trackInlineSize: Number.NaN, gap: Number.NaN, minColumnInlineSize: r, logicalColumns: n }, stageBlockSize: Number.NaN };
370
+ const l = getComputedStyle(t), s = t.clientWidth - F(l.paddingLeft) - F(l.paddingRight), c = t.clientHeight - F(l.paddingTop) - F(l.paddingBottom);
371
+ return { plan: { trackInlineSize: s, gap: Wn(l.columnGap), minColumnInlineSize: r, logicalColumns: n }, stageBlockSize: c };
372
+ }, Jn = (e, n) => {
373
+ if (e.getClientRects().length === 0) return Number.NaN;
374
+ const t = getComputedStyle(e);
375
+ return n.getBoundingClientRect().top - e.getBoundingClientRect().top + F(t.paddingBottom) + F(t.borderBottomWidth);
376
+ }, X = "data-aqmx-panel-frame", ye = "--aqmx-multi-panel-pinned-block-size", Xn = (e) => {
377
+ const { docPath: n, panelId: t } = e;
378
+ if (typeof n != "string" || typeof t != "string") throw new TypeError("[markdown-explorer] a multi-view panel needs string docPath and panelId props");
379
+ return { docPath: n, panelId: t };
380
+ }, Zn = (e) => {
381
+ const n = getComputedStyle(e), t = Number.parseFloat(n.lineHeight);
382
+ return Number.isFinite(t) ? t : Number.parseFloat(n.fontSize);
383
+ }, Qn = (e, n, t) => e.deltaMode === WheelEvent.DOM_DELTA_PAGE ? e.deltaY * n.clientHeight : e.deltaMode !== WheelEvent.DOM_DELTA_LINE ? e.deltaY : e.deltaY * t(n), j = (e) => {
384
+ const n = e.closest(Ie);
385
+ return n instanceof HTMLElement ? n : null;
386
+ }, Ve = (e) => {
387
+ const n = e.firstElementChild;
388
+ return n instanceof HTMLElement && getComputedStyle(n).position === "sticky" ? n : null;
389
+ }, $e = (e, n) => {
390
+ const t = n.getBoundingClientRect().top, o = Ve(e);
391
+ return o === null ? t : Math.max(t, o.getBoundingClientRect().bottom);
392
+ }, Se = (e, n) => {
393
+ let t = 0, o = e.length;
394
+ for (; t < o; ) {
395
+ const r = t + o >>> 1;
396
+ (e[r]?.getBoundingClientRect().bottom ?? Number.NEGATIVE_INFINITY) > n ? o = r : t = r + 1;
397
+ }
398
+ return t < e.length ? t : -1;
399
+ }, et = (e, n) => {
400
+ const t = $e(e, n), o = [];
401
+ let r = e;
402
+ for (let l = Se([...r.children], t); l >= 0; l = Se([...r.children], t)) {
403
+ const s = r.children[l];
404
+ if (s === void 0) break;
405
+ o.push(l), r = s;
406
+ }
407
+ return { scrollTop: n.scrollTop, anchor: o.length === 0 ? null : { path: o, offset: r.getBoundingClientRect().top - t } };
408
+ }, xe = (e, n, t) => {
409
+ if (n.scrollTop = t.scrollTop, t.anchor === null) return;
410
+ let o = e;
411
+ for (const r of t.anchor.path) o = o?.children[r];
412
+ o !== void 0 && (n.scrollTop += o.getBoundingClientRect().top - $e(e, n) - t.anchor.offset);
413
+ }, nt = Object.freeze(["data-testid", "aria-label", "title", "href", "id", "name"]), Ue = (e) => JSON.stringify([e.tagName, ...nt.map((n) => e.getAttribute(n))]), tt = (e, n) => {
414
+ if (n === null || !e.contains(n)) return null;
415
+ const t = [];
416
+ for (let o = n; o !== e; ) {
417
+ const r = o.parentElement;
418
+ if (r === null) return null;
419
+ t.unshift([...r.children].indexOf(o)), o = r;
420
+ }
421
+ return { path: t, signature: Ue(n) };
422
+ }, ot = (e, n, t) => {
423
+ let o = e;
424
+ for (const r of t.path) o = o?.children[r];
425
+ o instanceof HTMLElement && Ue(o) === t.signature && ln(o) || n.focus({ preventScroll: !0 });
426
+ }, rt = (e, n, t) => {
427
+ if (e.shiftKey || Math.abs(e.deltaX) > Math.abs(e.deltaY)) return;
428
+ const o = e.ctrlKey || e.metaKey, r = o ? j(n) : n.closest(Q);
429
+ if (!(r instanceof HTMLElement)) return;
430
+ const l = Qn(e, r, t);
431
+ (o || lt(r, l)) && (e.preventDefault(), r.scrollTop += l);
432
+ }, lt = (e, n) => n < 0 ? e.scrollTop > 0 : n > 0 ? Math.ceil(e.scrollTop + e.clientHeight) < e.scrollHeight : !1, st = (e) => e.scrollHeight > e.clientHeight, it = (e, n, t) => {
433
+ let o = Number.NaN, r = Number.NaN;
434
+ const l = Ve(t), s = () => {
435
+ const a = Jn(e, n);
436
+ if (!Number.isFinite(a)) return;
437
+ const p = l === null ? 0 : l.getBoundingClientRect().height;
438
+ p !== r && (r = p, t.style.setProperty(ye, `${String(p)}px`));
439
+ const w = a + p;
440
+ w !== o && (o = w, e.style.setProperty(le, `${String(w)}px`));
441
+ };
442
+ s();
443
+ let c = null;
444
+ const m = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
445
+ c === null && (c = requestAnimationFrame(() => {
446
+ c = null, s();
447
+ }));
448
+ });
449
+ return m?.observe(e), m?.observe(n), l !== null && m?.observe(l), () => {
450
+ m?.disconnect(), c !== null && cancelAnimationFrame(c), e.style.removeProperty(le), t.style.removeProperty(ye);
451
+ };
452
+ }, at = (e) => {
453
+ const { docPath: n, panelId: t } = Xn(e), { store: o, Body: r, maximize: l, focusCarry: s } = ie(), c = z(o, (u) => u.layout.maximized === n), m = z(o, (u) => ae(u.titles, n)), a = B(null), p = B(null), w = B(null);
454
+ $(() => {
455
+ const u = a.current, f = u === null ? null : j(u);
456
+ if (u === null || f === null || c) return;
457
+ const d = /* @__PURE__ */ new Map(), E = (v) => {
458
+ const P = d.get(v);
459
+ if (P !== void 0) return P;
460
+ const L = Zn(v);
461
+ return d.set(v, L), L;
462
+ }, y = (v) => rt(v, u, E);
463
+ let M = !1;
464
+ const g = () => {
465
+ const v = st(f);
466
+ v !== M && (M = v, v ? u.addEventListener("wheel", y, { capture: !0, passive: !1 }) : u.removeEventListener("wheel", y, { capture: !0 }));
467
+ };
468
+ g();
469
+ const b = typeof ResizeObserver > "u" ? null : new ResizeObserver(g);
470
+ return b?.observe(f), b?.observe(u), () => {
471
+ b?.disconnect(), u.removeEventListener("wheel", y, { capture: !0 });
472
+ };
473
+ }, [c]), q(() => {
474
+ const u = a.current, f = u === null ? null : j(u), d = u === null ? null : u.closest(`[${J}]`);
475
+ if (!(u === null || f === null || !(d instanceof HTMLElement)))
476
+ return it(d, f, u);
477
+ }, []), q(() => {
478
+ const u = a.current, f = u === null ? null : j(u);
479
+ if (u === null || f === null) return;
480
+ const d = o.readingPositionOf(t, n);
481
+ p.current = d === null ? null : { doc: n, position: d }, d !== null && xe(u, f, d);
482
+ let E = null;
483
+ const y = () => {
484
+ E === null && (E = requestAnimationFrame(() => {
485
+ E = null;
486
+ const M = w.current;
487
+ M !== null && o.saveReadingPosition(t, M, et(u, f));
488
+ }));
489
+ };
490
+ return f.addEventListener("scroll", y, { passive: !0 }), () => {
491
+ f.removeEventListener("scroll", y), E !== null && cancelAnimationFrame(E);
492
+ };
493
+ }, [o, t, n]), q(() => {
494
+ const u = a.current, f = u === null ? null : u.closest(`[${J}]`);
495
+ if (u === null || f === null) return;
496
+ const d = s.take(t);
497
+ return d !== null && ot(f, u, d), () => {
498
+ const E = tt(f, f.ownerDocument.activeElement);
499
+ E !== null && s.hold(t, E);
500
+ };
501
+ }, [s, t]);
502
+ const C = D((u) => {
503
+ const f = a.current, d = f === null ? null : j(f);
504
+ if (f === null || d === null) return;
505
+ const E = w.current;
506
+ w.current = u;
507
+ const y = p.current;
508
+ p.current = null, y !== null && y.doc === u ? xe(f, d, y.position) : E !== null && E !== u && (d.scrollTop = 0);
509
+ }, []), x = D(() => l(n), [l, n]);
510
+ return (
511
+ /* @__PURE__ */ T(
512
+ "div",
513
+ {
514
+ ref: a,
515
+ role: "group",
516
+ "aria-label": m,
517
+ className: "aqmx-multi-panel-frame",
518
+ tabIndex: -1,
519
+ "data-aqmx-panel-frame": t,
520
+ "data-aqmx-maximized": c ? "true" : "false",
521
+ "data-testid": "markdown-explorer-panel-frame",
522
+ onDoubleClick: c ? void 0 : x,
523
+ children: /* @__PURE__ */ T(r, { docPath: n, panelId: t, maximized: c, title: m, onContentShown: C })
524
+ }
525
+ )
526
+ );
527
+ }, ct = Ke(at), K = (e, n) => {
528
+ const t = e.panelIds.get(n);
529
+ if (t === void 0) throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);
530
+ return t;
531
+ }, Ee = (e) => Object.fromEntries(un(e).map((n) => [n, []])), ut = (e, n) => {
532
+ const t = _n(ne(e, n), n.visible);
533
+ return Object.fromEntries(t.map((o, r) => [De(r), o.map((l) => K(e, l))]));
534
+ }, dt = (e, n) => {
535
+ const t = W(e);
536
+ return Ae(Object.keys(n)).map(
537
+ (o) => (n[o] ?? []).flatMap((r) => {
538
+ const l = t.get(r);
539
+ return l === void 0 ? [] : [l];
540
+ })
541
+ );
542
+ }, mt = (e) => ({
543
+ switchToCustomDragMode: e.panelSwitchToCustomDrag,
544
+ switchToNormalDragMode: e.panelSwitchToNormalDrag,
545
+ hidePanel: e.panelHide,
546
+ maximizePanel: e.panelMaximize,
547
+ restorePanel: e.panelRestore,
548
+ closePanel: e.panelClose,
549
+ movePanelToPreviousColumn: e.panelMovePreviousColumn,
550
+ movePanelToNextColumn: e.panelMoveNextColumn,
551
+ movePanelUp: e.panelMoveUp,
552
+ movePanelDown: e.panelMoveDown,
553
+ customDragModeBadge: e.panelCustomDragBadge,
554
+ panelMoved: e.panelMoved,
555
+ panelMoveUnavailable: e.panelMoveUnavailable,
556
+ panelDragStarted: e.panelDragStarted,
557
+ panelDragCancelled: e.panelDragCancelled,
558
+ hiddenPanels: e.hiddenPanelsTitle,
559
+ hiddenPanelBadge: e.hiddenPanelBadge,
560
+ hiddenPanelNotice: e.hiddenPanelNotice,
561
+ emptyColumn: e.multiColumnEmpty,
562
+ dropZone: e.multiColumnRegion,
563
+ dropHere: e.panelDropHere
564
+ }), ft = "--aqmx-multi-stage-bar-gutter", pt = Object.freeze({ [ft]: `${String(bn)}px` }), gt = Object.freeze({ blockSize: "100%" }), ht = Object.freeze({ [dn]: "", style: Object.freeze({ display: "flex" }) }), vt = (e) => /* @__PURE__ */ T("div", { ...ht, children: /* @__PURE__ */ T(Le, { scroller: e, withCircle: !0 }) }), wt = ({ props: e, children: n }) => /* @__PURE__ */ T(En, { scrollerProps: { ...e, style: gt }, renderScrollBar: vt, children: n }), yt = (e) => /* @__PURE__ */ T(Le, { scroller: e, withCircle: !1 }), ue = "--aqmx-stage-block", St = "--aqmx-multi-panel-body-floor", xt = `calc(var(${ue}) * ${String(Qe)})`, Et = `max(calc(var(${ue}) * ${String(Ze)}), calc(var(${le}) + var(${St})))`, bt = (e, n) => {
565
+ const t = Object.entries(e);
566
+ return t.length !== Object.keys(n).length ? !1 : t.every(([o, r]) => {
567
+ const l = n[o];
568
+ return l !== void 0 && l.length === r.length && l.every((s, c) => r[c] === s);
569
+ });
570
+ }, be = ["keydown", "pointerdown", "wheel", "touchstart"], Y = /* @__PURE__ */ new WeakMap(), Oe = (e, n, t) => {
571
+ for (let o = n; o !== null && o !== t; o = o.parentElement) {
572
+ e.observe(o);
573
+ for (let r = o.previousElementSibling; r !== null; r = r.previousElementSibling) e.observe(r);
574
+ }
575
+ }, Ot = (e) => {
576
+ const n = /* @__PURE__ */ new Map();
577
+ for (let t = e.parentElement; t !== null; t = t.parentElement) n.set(t, { top: t.scrollTop, left: t.scrollLeft });
578
+ return n;
579
+ }, Z = (e, n, t) => {
580
+ Y.get(e)?.();
581
+ const o = e.querySelector(`[${J}="${n}"]`);
582
+ if (!(o instanceof HTMLElement)) return;
583
+ const r = t !== null && o.contains(t) ? t : null;
584
+ let l = /* @__PURE__ */ new Map();
585
+ const s = () => {
586
+ if (!o.isConnected) return;
587
+ o.scrollIntoView({ block: "nearest", inline: "nearest", behavior: "instant" });
588
+ const w = r?.isConnected === !0 ? r : o;
589
+ w !== o && w.scrollIntoView({ block: "nearest", inline: "nearest", behavior: "instant" }), l = Ot(w);
590
+ };
591
+ if (s(), typeof ResizeObserver > "u") return;
592
+ const c = new ResizeObserver(s);
593
+ Oe(c, o, o.closest(Q)), r !== null && Oe(c, r, o);
594
+ const { ownerDocument: m } = e, a = (w) => {
595
+ const C = w.target === m ? m.scrollingElement : w.target;
596
+ if (!(C instanceof Element)) return;
597
+ const x = l.get(C);
598
+ x !== void 0 && (C.scrollTop !== x.top || C.scrollLeft !== x.left) && p();
599
+ }, p = () => {
600
+ c.disconnect();
601
+ for (const w of be) m.removeEventListener(w, p, !0);
602
+ m.removeEventListener("scroll", a, !0), Y.get(e) === p && Y.delete(e);
603
+ };
604
+ for (const w of be) m.addEventListener(w, p, { capture: !0, passive: !0 });
605
+ m.addEventListener("scroll", a, { capture: !0, passive: !0 }), Y.set(e, p);
606
+ }, je = (e, n) => {
607
+ const t = e.querySelector(`[${X}="${n}"]`);
608
+ return t instanceof HTMLElement ? (Z(e, n, null), t.focus({ preventScroll: !0 }), !0) : !1;
609
+ }, de = (e, n) => {
610
+ const t = e.querySelector(`[${J}="${n}"]`);
611
+ return t instanceof HTMLElement && t.contains(e.ownerDocument.activeElement);
612
+ }, Pe = (e, n) => {
613
+ if (!de(e, n)) return null;
614
+ const t = [...e.querySelectorAll(`[${X}]`)].map((s) => s.getAttribute(X)), o = t.indexOf(n), r = t[o + 1];
615
+ if (o >= 0 && typeof r == "string") return { kind: "panel", panelId: r };
616
+ const l = t[o - 1];
617
+ return o > 0 && typeof l == "string" ? { kind: "panel", panelId: l } : { kind: "stage" };
618
+ }, Ce = (e, n) => {
619
+ requestAnimationFrame(() => {
620
+ const t = e.current;
621
+ t !== null && (n.kind === "panel" && je(t, n.panelId) || t.focus({ preventScroll: !0 }));
622
+ });
623
+ }, Ye = (e, n) => {
624
+ requestAnimationFrame(() => {
625
+ const t = e.current;
626
+ t !== null && je(t, n);
627
+ });
628
+ }, Pt = (e, n, t) => {
629
+ requestAnimationFrame(() => {
630
+ const o = e.current;
631
+ if (o === null) return;
632
+ const { activeElement: r, body: l } = o.ownerDocument;
633
+ if (Z(o, n, t && de(o, n) ? r : null), !t || r !== null && r !== l && r.isConnected) return;
634
+ const s = o.querySelector(`[${X}="${n}"]`);
635
+ s instanceof HTMLElement && s.focus({ preventScroll: !0 });
636
+ });
637
+ }, Ct = ({ store: e, stageRef: n }) => {
638
+ const { config: t, labels: o, announcer: r } = G(), { maximize: l } = ie(), s = t.multiView.columns, c = z(e, (S) => S.layout), m = z(e, (S) => S.visibleColumns), a = z(e, (S) => S.titles), p = z(e, (S) => S.layout.maximized !== null || S.splitDragging), [w, C] = V(!1), [x] = V(() => Ee(m)), u = _(() => mt(o), [o]), f = D(
639
+ (S) => {
640
+ e.arrange(dt(e.getSnapshot().layout, S));
641
+ },
642
+ [e]
643
+ ), d = mn({ initialColumnPanels: x, initialPanelVisibility: {}, debugConfig: ge, onColumnPanelsChange: f }), { columnPanels: E, setColumnPanels: y } = d, M = B(p), g = B(E);
644
+ q(() => {
645
+ M.current = p, g.current = E;
646
+ }, [p, E]);
647
+ const b = D(
648
+ (S) => {
649
+ const O = n.current;
650
+ if (O === null) return;
651
+ const { plan: H, stageBlockSize: R } = Kn(O, s);
652
+ if (Number.isFinite(R) && R > 0 && O.style.setProperty(ue, `${String(R)}px`), M.current && !S) return;
653
+ const k = Xe(e.getSnapshot().visibleColumns, H);
654
+ k !== null && e.setVisibleColumns(k);
655
+ },
656
+ [e, n, s]
657
+ );
658
+ q(() => {
659
+ b(!0), C(!0);
660
+ }, [b]), $(() => {
661
+ const S = n.current;
662
+ if (S === null || typeof ResizeObserver > "u") return;
663
+ let O = null;
664
+ const H = new ResizeObserver(() => {
665
+ O === null && (O = requestAnimationFrame(() => {
666
+ O = null, b(!1);
667
+ }));
668
+ }), R = S.querySelector(Q)?.firstElementChild, k = S.querySelector(`[${ce}]`);
669
+ return R instanceof Element && H.observe(R), k instanceof Element && H.observe(k), () => {
670
+ H.disconnect(), O !== null && cancelAnimationFrame(O);
671
+ };
672
+ }, [n, b]), $(() => {
673
+ p || b(!1);
674
+ }, [p, b]);
675
+ const v = _(() => w ? ut(c, { logical: s, visible: m }) : Ee(m), [w, c, s, m]);
676
+ q(() => {
677
+ bt(g.current, v) || y(v);
678
+ }, [v, y]);
679
+ const P = _(() => Ae(Object.keys(E)).map((S) => ({ id: S, key: S, className: "aqmx-multi-column" })), [E]), L = _(
680
+ () => c.docs.map((S) => {
681
+ const O = K(c, S);
682
+ return { id: O, component: ct, title: ae(a, S), props: { docPath: S, panelId: O }, minHeight: xt, maxHeight: Et };
683
+ }),
684
+ [c, a]
685
+ ), I = _(() => Object.fromEntries(c.docs.map((S) => [K(c, S), !c.hidden.has(S)])), [c]), i = c.maximized === null ? null : K(c, c.maximized), h = D(
686
+ (S) => {
687
+ const { layout: O } = e.getSnapshot();
688
+ for (const [H, R] of W(O)) {
689
+ const k = S[H];
690
+ if (k === void 0 || k !== O.hidden.has(R)) continue;
691
+ const me = e.titleOf(R);
692
+ if (k) {
693
+ if (!e.setHidden(R, !1)) continue;
694
+ r.announce(o.panelShown(me)), Ye(n, H);
695
+ continue;
696
+ }
697
+ const fe = n.current, pe = fe === null ? null : Pe(fe, H);
698
+ e.setHidden(R, !0) && (r.announce(o.panelHidden(me)), pe !== null && Ce(n, pe));
699
+ }
700
+ },
701
+ [e, n, r, o]
702
+ ), N = D(
703
+ (S) => {
704
+ const O = W(e.getSnapshot().layout).get(S);
705
+ if (O === void 0) return;
706
+ const H = e.titleOf(O), R = n.current, k = R === null ? null : Pe(R, S);
707
+ e.close(O) && (r.announce(o.panelClosed(H)), k !== null && Ce(n, k));
708
+ },
709
+ [e, n, r, o]
710
+ ), A = D(
711
+ (S) => {
712
+ if (S === null) {
713
+ l(null);
714
+ return;
715
+ }
716
+ const O = W(e.getSnapshot().layout).get(S);
717
+ O !== void 0 && l(O);
718
+ },
719
+ [e, l]
720
+ );
721
+ return /* @__PURE__ */ T("div", { className: "aqmx-multi-layout", "aria-busy": !w, children: /* @__PURE__ */ T(
722
+ fn,
723
+ {
724
+ columns: P,
725
+ panels: L,
726
+ columnPanels: E,
727
+ onColumnPanelsChange: f,
728
+ panelVisibility: I,
729
+ onPanelVisibilityChange: h,
730
+ dragState: d.dragState,
731
+ dragOverPosition: d.dragOverPosition,
732
+ originalPanelPosition: d.originalPanelPosition,
733
+ dragModes: d.dragModes,
734
+ debugConfig: ge,
735
+ panelSizes: d.panelSizes,
736
+ customDrag: d.customDrag,
737
+ setPanelRef: d.setPanelRef,
738
+ onDragStart: d.handleDragStart,
739
+ onDragEnd: d.handleDragEnd,
740
+ onPlaceholderDragEnter: d.handlePlaceholderDragEnter,
741
+ onPlaceholderDragLeave: d.handlePlaceholderDragLeave,
742
+ onDragOverWithInsert: d.handleDragOverWithInsert,
743
+ onDropWithInsert: d.handleDropWithInsert,
744
+ onColumnDragLeave: d.handleColumnDragLeave,
745
+ onPanelMouseDown: d.handleMouseDown,
746
+ onPanelSizeInfoClick: d.handlePanelSizeInfoClick,
747
+ onToggleDragMode: d.toggleDragMode,
748
+ onPanelClose: N,
749
+ onPanelMaximizeChange: A,
750
+ maximizedPanel: i,
751
+ dragHandle: "header",
752
+ labels: u,
753
+ panelClassName: "aqmx-multi-panel",
754
+ renderPanelScrollArea: wt,
755
+ renderStageScrollBar: yt
756
+ }
757
+ ) });
758
+ }, oe = { blockStart: "--aqmx-multi-toast-block-start", inlineEnd: "--aqmx-multi-toast-inline-end", room: "--aqmx-multi-toast-room" }, Nt = (e, n) => {
759
+ const t = n.getBoundingClientRect(), o = [t.left + 1, t.left + t.width / 2, t.right - 1], r = [t.top + 1, t.top + t.height / 2, t.bottom - 1];
760
+ return o.some(
761
+ (l) => r.some((s) => {
762
+ const c = n.ownerDocument.elementsFromPoint(l, s), m = c.findIndex((p) => n.contains(p)), a = c.findIndex((p) => e.contains(p));
763
+ return m !== -1 && a !== -1 && a < m;
764
+ })
765
+ );
766
+ }, Mt = (e, n) => {
767
+ const t = n.getBoundingClientRect(), o = n.ownerDocument.documentElement.clientWidth, r = getComputedStyle(n).direction === "rtl";
768
+ return e.style.setProperty(oe.blockStart, `${String(t.top)}px`), e.style.setProperty(oe.inlineEnd, `${String(r ? t.left : o - t.right)}px`), e.style.setProperty(oe.room, `${String(t.width)}px`), e.showPopover(), () => {
769
+ e.isConnected && e.hidePopover();
770
+ };
771
+ }, Tt = ({ store: e, body: n, limitNotice: t, onLimitNoticeCovered: o, ref: r }) => {
772
+ const { config: l, labels: s, announcer: c } = G(), m = B(null), a = B(null), p = z(e, (g) => g.ready), w = z(e, (g) => g.layout.docs.length > 0), C = z(e, (g) => g.visibleColumns), x = Me(sn), u = D(
773
+ (g) => {
774
+ const { layout: b } = e.getSnapshot(), v = b.maximized, P = g === null && v !== null ? b.panelIds.get(v) : void 0, L = m.current, I = P !== void 0 && L !== null && de(L, P);
775
+ e.maximize(g) && (g !== null ? c.announce(s.panelMaximized(e.titleOf(g))) : v !== null && c.announce(s.panelRestored(e.titleOf(v))), P !== void 0 && Pt(m, P, I));
776
+ },
777
+ [e, c, s]
778
+ ), f = D(
779
+ (g, b, v, P) => {
780
+ if (v === b) {
781
+ e.setPendingHash(g, P);
782
+ return;
783
+ }
784
+ const L = e.navigate(b, v);
785
+ if (L === "navigated") {
786
+ e.setPendingHash(g, P);
787
+ return;
788
+ }
789
+ if (L !== "existing") return;
790
+ const { layout: I } = e.getSnapshot(), i = I.panelIds.get(v);
791
+ i !== void 0 && (c.announce(s.panelAlreadyOpen(e.titleOf(v))), I.maximized === null ? e.setHidden(v, !1) : u(v), e.setPendingHash(i, P), Ye(m, i));
792
+ },
793
+ [e, c, s, u]
794
+ );
795
+ q(() => {
796
+ if (t === null || x !== null || !we()) return;
797
+ const g = a.current, b = m.current;
798
+ if (g === null || b === null) throw new Error("[markdown-explorer] the panel-limit notice and the stage must be mounted together");
799
+ return Mt(g, b);
800
+ }, [t, x]), $(() => {
801
+ const g = a.current;
802
+ if (t === null || g === null) return;
803
+ const { ownerDocument: b } = g;
804
+ let v = null;
805
+ const P = (L) => {
806
+ const I = L.target;
807
+ I instanceof Element && (v !== null && cancelAnimationFrame(v), v = requestAnimationFrame(() => {
808
+ v = null, b.activeElement === I && g.isConnected && Nt(g, I) && o();
809
+ }));
810
+ };
811
+ return b.addEventListener("focusin", P, !0), () => {
812
+ b.removeEventListener("focusin", P, !0), v !== null && cancelAnimationFrame(v);
813
+ };
814
+ }, [t, x, o]), Je(
815
+ r,
816
+ () => ({
817
+ bringIntoView: (g) => {
818
+ requestAnimationFrame(() => {
819
+ const b = m.current, v = e.getSnapshot().layout.panelIds.get(g);
820
+ b !== null && v !== void 0 && Z(b, v, null);
821
+ });
822
+ }
823
+ }),
824
+ [e]
825
+ ), $(() => {
826
+ const g = m.current;
827
+ return () => {
828
+ g !== null && Y.get(g)?.();
829
+ };
830
+ }, []);
831
+ const d = D((g, b) => {
832
+ const v = m.current;
833
+ v !== null && Z(v, g, b);
834
+ }, []), [E] = V(On), y = _(() => ({ store: e, Body: n, followLink: f, maximize: u, revealInPanel: d, focusCarry: E }), [e, n, f, u, d, E]), M = _(() => Array.from({ length: l.multiView.columns }, (g, b) => De(b)), [l]);
835
+ return (
836
+ /* @__PURE__ */ re("section", { ref: m, className: "aqmx-multi-stage", style: pt, tabIndex: -1, "aria-label": s.multiRegion, "aria-busy": w && !p, "data-testid": "markdown-explorer-stage", "data-aqmx-visible-columns": C, children: [
837
+ /* @__PURE__ */ T("span", { className: "aqmx-multi-probe", "aria-hidden": "true", [ce]: "" }),
838
+ w ? p ? /* @__PURE__ */ T(Re, { value: y, children: /* @__PURE__ */ T(Ct, { store: e, stageRef: m }) }) : /* @__PURE__ */ T("div", { className: "aqmx-multi-skeleton", "aria-hidden": "true", "data-testid": "markdown-explorer-stage-skeleton", children: M.map((g) => /* @__PURE__ */ re("div", { className: "aqmx-skeleton aqmx-multi-skeleton-column", children: [
839
+ /* @__PURE__ */ T("span", {}),
840
+ /* @__PURE__ */ T("span", {}),
841
+ /* @__PURE__ */ T("span", {})
842
+ ] }, g)) }) : /* @__PURE__ */ T("div", { className: "aqmx-empty", "data-testid": "markdown-explorer-multi-empty", children: /* @__PURE__ */ T("p", { className: "aqmx-empty-title", children: s.multiEmpty }) }),
843
+ t === null ? null : x !== null ? xn(
844
+ /* @__PURE__ */ T("div", { ref: a, className: "aqmx-toast aqmx-multi-toast", "data-testid": "markdown-explorer-panel-limit", children: t }),
845
+ x
846
+ ) : (
847
+ /* @__PURE__ */ T("div", { ref: a, popover: we() ? "manual" : void 0, className: "aqmx-toast aqmx-multi-toast", "data-testid": "markdown-explorer-panel-limit", children: t })
848
+ )
849
+ ] })
850
+ );
851
+ }, Lt = 3e3, It = (e, n) => {
852
+ if (n !== null) return n;
853
+ const [t] = e;
854
+ return t === void 0 ? null : t;
855
+ }, Ne = (e, n, t) => {
856
+ const o = new Set(e), r = n.filter((s) => !o.has(s)), l = r.length > 0 ? r.at(-1) : t !== null && n.includes(t) ? t : n.at(-1);
857
+ return l === void 0 ? null : l;
858
+ }, At = (e, n, t) => {
859
+ switch (n) {
860
+ case "opened":
861
+ return e.panelOpened(t);
862
+ case "shown":
863
+ return e.panelShown(t);
864
+ case "closed":
865
+ return e.panelClosed(t);
866
+ default: {
867
+ const o = n;
868
+ throw new RangeError(`[markdown-explorer] unknown toggle outcome ${JSON.stringify(o)}`);
869
+ }
870
+ }
871
+ }, jt = ({ location: e }) => {
872
+ const { config: n, labels: t, announcer: o } = G(), r = jn(e), l = z(r, (P) => P.layout.docs), s = z(r, (P) => P.layout.maximized), c = z(r, (P) => P.source), [m, a] = V(() => ({ docs: l, latest: Ne([], l, null) }));
873
+ m.docs !== l && a({ docs: l, latest: Ne(m.docs, l, m.latest) });
874
+ const p = s !== null ? s : m.latest, [w, C] = V(!1), x = B(null), [u, f] = V(0), d = B(null), E = B(null);
875
+ q(() => {
876
+ const P = d.current;
877
+ d.current = null, P !== null && (r.whenUrlRendered(() => o.announce(P.announcement)), E.current?.bringIntoView(P.doc));
878
+ }), $(
879
+ () => () => {
880
+ x.current !== null && clearTimeout(x.current);
881
+ },
882
+ []
883
+ );
884
+ const y = D(() => {
885
+ x.current !== null && clearTimeout(x.current), C(!0), x.current = setTimeout(() => {
886
+ x.current = null, C(!1);
887
+ }, Lt);
888
+ }, []), M = D(() => {
889
+ x.current !== null && clearTimeout(x.current), x.current = null, C(!1);
890
+ }, []), g = D(
891
+ (P) => {
892
+ const L = r.titleOf(P), I = r.toggle(P);
893
+ I === "rejected" && y();
894
+ const i = I === "rejected" ? t.panelLimit(n.multiView.maxPanels) : At(t, I, L);
895
+ if (I === "shown") {
896
+ d.current = { doc: P, announcement: i }, f((h) => h + 1);
897
+ return;
898
+ }
899
+ r.whenUrlRendered(() => {
900
+ o.announce(i), I === "opened" && E.current?.bringIntoView(P);
901
+ });
902
+ },
903
+ [r, y, o, t, n]
904
+ ), b = _(() => new Set(l), [l]), v = _(() => ({ href: Te(n, { view: "tree", source: c, doc: It(l, s) }), target: "tree" }), [n, c, l, s]);
905
+ return /* @__PURE__ */ T(
906
+ an,
907
+ {
908
+ view: "multi",
909
+ explorer: /* @__PURE__ */ T(cn, { mode: "multi", sourceId: c, currentPath: p, openPaths: b, onOpenDocument: g, onSourceChange: r.changeSource, onRevealSource: r.revealSource, viewSwitch: v }),
910
+ content: /* @__PURE__ */ T(Tt, { ref: E, store: r, body: Gn, limitNotice: w ? t.panelLimit(n.multiView.maxPanels) : null, onLimitNoticeCovered: M }),
911
+ contentCoversPage: s !== null,
912
+ sheetDismissals: u,
913
+ onDraggingChange: r.setSplitDragging
914
+ }
915
+ );
916
+ };
917
+ export {
918
+ jt as MultiLayout,
919
+ Lt as PANEL_LIMIT_NOTICE_MS,
920
+ Ne as latestOpenedDocument,
921
+ It as treeSwitchDocument
922
+ };