@aiquants/markdown-explorer 0.3.0 → 0.4.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 (57) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +45 -6
  3. package/dist/ExplorerSplit-rUVsf5i-.cjs +1 -0
  4. package/dist/ExplorerSplit-uX2ojZe8.js +1479 -0
  5. package/dist/MultiLayout-8s7q3-Hm.js +919 -0
  6. package/dist/MultiLayout-ZK2V9nms.cjs +1 -0
  7. package/dist/NativeScrollBar-D3VDRQqf.js +59 -0
  8. package/dist/NativeScrollBar-DqkutcGb.cjs +1 -0
  9. package/dist/{TreeLayout-D6hCSihW.js → TreeLayout-C7ZNnaOr.js} +3 -3
  10. package/dist/{TreeLayout-BQUfVNlA.cjs → TreeLayout-DkTVgxxb.cjs} +1 -1
  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 +8 -0
  14. package/dist/core/contracts.d.ts +8 -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-DYjYBiXF.cjs +1 -0
  20. package/dist/{dataRoute-zUX-oR9j.js → dataRoute-Dl6xmEFs.js} +41 -36
  21. package/dist/index-CLe6vRXs.cjs +3 -0
  22. package/dist/{index-BJTmp0lR.js → index-Dv9lUZqD.js} +530 -503
  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 +23 -22
  27. package/dist/location-2QZADLiv.cjs +1 -0
  28. package/dist/{location-V5BKeWNs.js → location-CaNtUswk.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 +725 -680
  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/package.json +7 -7
  51. package/dist/ExplorerSplit-B7pmzR8t.js +0 -1362
  52. package/dist/ExplorerSplit-Bi3yU6NG.cjs +0 -1
  53. package/dist/MultiLayout-BxeXOLX1.js +0 -909
  54. package/dist/MultiLayout-DtFrFRmS.cjs +0 -1
  55. package/dist/dataRoute-B9Wk-G7A.cjs +0 -1
  56. package/dist/index-DkiGlM7C.cjs +0 -3
  57. package/dist/location-DfYTzfFS.cjs +0 -1
@@ -0,0 +1,919 @@
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-CaNtUswk.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-Dv9lUZqD.js";
5
+ import { S as sn, a as an, b as cn } from "./ExplorerSplit-uX2ojZe8.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-Dl6xmEFs.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)), v = a[0];
76
+ v && (v[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 v of p) r.set(v, 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 v = (n[a] ?? []).filter((C) => l.has(C) && !s.has(C));
147
+ for (const C of v) s.add(C);
148
+ for (const [C, x] of zn(v, 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((v, C) => o[p]?.[C] === v)) ? 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 v = (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
+ }, w = (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) }), w(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
+ w(i, a.layout, "push");
259
+ },
260
+ observeLocation: (i) => {
261
+ const h = C(i.source, i);
262
+ if (h === x)
263
+ return d.length = 0, f = h, i.source !== a.source && g({ source: i.source }), M(), !1;
264
+ if (h === f) return !1;
265
+ f = h;
266
+ const N = d.indexOf(h);
267
+ if (N >= 0)
268
+ return d.splice(0, N + 1), i.source !== a.source && g({ source: i.source }), M(), !1;
269
+ d.length = 0, x = h, u = i.source;
270
+ const A = v(te({ docs: i.docs, maximized: i.maximized, stored: { columnOf: a.layout.columnOf, hidden: a.layout.hidden }, panelIds: a.layout.panelIds }, r));
271
+ return g({ layout: A, source: i.source, ...P(A) }), b(), M(), !0;
272
+ },
273
+ whenUrlRendered: (i) => {
274
+ E.push(i), M();
275
+ },
276
+ loadStored: (i) => {
277
+ g({ layout: v(te({ docs: a.layout.docs, maximized: a.layout.maximized, stored: i, panelIds: a.layout.panelIds }, r)), ready: !0 }), b();
278
+ },
279
+ setVisibleColumns: (i) => {
280
+ 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)}`);
281
+ p = !0;
282
+ const h = he(a.layout, { logical: l, visible: i });
283
+ i === a.visibleColumns && h === a.layout || (g({ visibleColumns: i, layout: h }), h !== a.layout && b());
284
+ },
285
+ setSplitDragging: (i) => {
286
+ i !== a.splitDragging && g({ splitDragging: i });
287
+ },
288
+ setTitle: (i, h) => {
289
+ !a.layout.docs.includes(i) || a.titles.get(i) === h || g({ titles: new Map(a.titles).set(i, h) });
290
+ },
291
+ titleOf: (i) => ae(a.titles, i),
292
+ setPendingHash: (i, h) => {
293
+ const N = a.pendingHashes.get(i);
294
+ if (h === null || h === "") {
295
+ if (N === void 0) return;
296
+ const A = new Map(a.pendingHashes);
297
+ A.delete(i), g({ pendingHashes: A });
298
+ return;
299
+ }
300
+ N !== h && g({ pendingHashes: new Map(a.pendingHashes).set(i, h) });
301
+ },
302
+ saveReadingPosition: (i, h, N) => {
303
+ a.layout.panelIds.get(h) === i && c.set(i, { doc: h, position: N });
304
+ },
305
+ readingPositionOf: (i, h) => {
306
+ const N = c.get(i);
307
+ return N === void 0 || N.doc !== h ? null : N.position;
308
+ },
309
+ saveImageView: (i, h, N) => {
310
+ m.set(i, { url: h, state: N });
311
+ },
312
+ imageViewOf: (i, h) => {
313
+ const N = m.get(i);
314
+ return N === void 0 || N.url !== h ? null : N.state;
315
+ }
316
+ };
317
+ }, z = (e, n) => {
318
+ const t = () => n(e.getSnapshot());
319
+ return We(e.subscribe, t, t);
320
+ }, jn = (e) => {
321
+ const { config: n, storageNamespace: t } = G(), o = pn(), r = B(o), l = hn(t).multiLayout, [s] = V(
322
+ () => Un({
323
+ config: n,
324
+ location: e,
325
+ writeUrl: (a, p) => {
326
+ r.current(a, nn(p === "replace" ? "browse" : "switch-source"));
327
+ },
328
+ persist: (a) => wn(l, a)
329
+ })
330
+ );
331
+ q(() => {
332
+ r.current = o;
333
+ }, [o]);
334
+ const c = gn(), m = _(() => ({ location: e, navigated: c }), [e, c]);
335
+ return q(() => {
336
+ s.observeLocation(m.location);
337
+ }, [s, m]), q(() => {
338
+ s.loadStored(Vn(vn(l), n.multiView.columns));
339
+ }, [s, l, n]), s;
340
+ }, Yn = (e) => {
341
+ const n = e.closest(Ie);
342
+ if (n === null) throw new Error("[markdown-explorer] a panel's document region is not inside the panel's scroll area");
343
+ return n;
344
+ }, Gn = ({ docPath: e, panelId: n, maximized: t, title: o, onContentShown: r }) => {
345
+ 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]), v = 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(
346
+ (y, M) => {
347
+ M.kind !== "failure" && l.setTitle(y, M.name), r(y);
348
+ },
349
+ [l, r]
350
+ ), u = D(
351
+ (y) => {
352
+ l.whenUrlRendered(() => m.announce(y));
353
+ },
354
+ [l, m]
355
+ ), f = _(() => ({ scrollerOf: Yn, reveal: (y) => c(n, y) }), [c, n]), d = _(
356
+ () => ({ kind: "panel", maximized: t, onDocumentLink: p, pendingHash: a, onHashConsumed: v, announceFailure: u, paneScroll: f }),
357
+ [t, p, a, v, u, f]
358
+ ), E = _(() => ({ kind: "panel", documentName: o }), [o]);
359
+ return /* @__PURE__ */ re(tn, { value: C, children: [
360
+ /* @__PURE__ */ T(on, { path: e, placement: E }),
361
+ /* @__PURE__ */ T(rn, { path: e, variant: d, onDocumentShown: x })
362
+ ] });
363
+ }, 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) => {
364
+ const t = e.querySelector(Q)?.firstElementChild, o = e.querySelector(`[${ce}]`), r = o instanceof HTMLElement ? o.getBoundingClientRect().width : Number.NaN;
365
+ if (!(t instanceof HTMLElement))
366
+ return { plan: { trackInlineSize: Number.NaN, gap: Number.NaN, minColumnInlineSize: r, logicalColumns: n }, stageBlockSize: Number.NaN };
367
+ const l = getComputedStyle(t), s = t.clientWidth - F(l.paddingLeft) - F(l.paddingRight), c = t.clientHeight - F(l.paddingTop) - F(l.paddingBottom);
368
+ return { plan: { trackInlineSize: s, gap: Wn(l.columnGap), minColumnInlineSize: r, logicalColumns: n }, stageBlockSize: c };
369
+ }, Jn = (e, n) => {
370
+ if (e.getClientRects().length === 0) return Number.NaN;
371
+ const t = getComputedStyle(e);
372
+ return n.getBoundingClientRect().top - e.getBoundingClientRect().top + F(t.paddingBottom) + F(t.borderBottomWidth);
373
+ }, X = "data-aqmx-panel-frame", ye = "--aqmx-multi-panel-pinned-block-size", Xn = (e) => {
374
+ const { docPath: n, panelId: t } = e;
375
+ if (typeof n != "string" || typeof t != "string") throw new TypeError("[markdown-explorer] a multi-view panel needs string docPath and panelId props");
376
+ return { docPath: n, panelId: t };
377
+ }, Zn = (e) => {
378
+ const n = getComputedStyle(e), t = Number.parseFloat(n.lineHeight);
379
+ return Number.isFinite(t) ? t : Number.parseFloat(n.fontSize);
380
+ }, 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) => {
381
+ const n = e.closest(Ie);
382
+ return n instanceof HTMLElement ? n : null;
383
+ }, Ve = (e) => {
384
+ const n = e.firstElementChild;
385
+ return n instanceof HTMLElement && getComputedStyle(n).position === "sticky" ? n : null;
386
+ }, $e = (e, n) => {
387
+ const t = n.getBoundingClientRect().top, o = Ve(e);
388
+ return o === null ? t : Math.max(t, o.getBoundingClientRect().bottom);
389
+ }, Se = (e, n) => {
390
+ let t = 0, o = e.length;
391
+ for (; t < o; ) {
392
+ const r = t + o >>> 1;
393
+ (e[r]?.getBoundingClientRect().bottom ?? Number.NEGATIVE_INFINITY) > n ? o = r : t = r + 1;
394
+ }
395
+ return t < e.length ? t : -1;
396
+ }, et = (e, n) => {
397
+ const t = $e(e, n), o = [];
398
+ let r = e;
399
+ for (let l = Se([...r.children], t); l >= 0; l = Se([...r.children], t)) {
400
+ const s = r.children[l];
401
+ if (s === void 0) break;
402
+ o.push(l), r = s;
403
+ }
404
+ return { scrollTop: n.scrollTop, anchor: o.length === 0 ? null : { path: o, offset: r.getBoundingClientRect().top - t } };
405
+ }, xe = (e, n, t) => {
406
+ if (n.scrollTop = t.scrollTop, t.anchor === null) return;
407
+ let o = e;
408
+ for (const r of t.anchor.path) o = o?.children[r];
409
+ o !== void 0 && (n.scrollTop += o.getBoundingClientRect().top - $e(e, n) - t.anchor.offset);
410
+ }, 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) => {
411
+ if (n === null || !e.contains(n)) return null;
412
+ const t = [];
413
+ for (let o = n; o !== e; ) {
414
+ const r = o.parentElement;
415
+ if (r === null) return null;
416
+ t.unshift([...r.children].indexOf(o)), o = r;
417
+ }
418
+ return { path: t, signature: Ue(n) };
419
+ }, ot = (e, n, t) => {
420
+ let o = e;
421
+ for (const r of t.path) o = o?.children[r];
422
+ o instanceof HTMLElement && Ue(o) === t.signature && ln(o) || n.focus({ preventScroll: !0 });
423
+ }, rt = (e, n, t) => {
424
+ if (e.shiftKey || Math.abs(e.deltaX) > Math.abs(e.deltaY)) return;
425
+ const o = e.ctrlKey || e.metaKey, r = o ? j(n) : n.closest(Q);
426
+ if (!(r instanceof HTMLElement)) return;
427
+ const l = Qn(e, r, t);
428
+ (o || lt(r, l)) && (e.preventDefault(), r.scrollTop += l);
429
+ }, 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) => {
430
+ let o = Number.NaN, r = Number.NaN;
431
+ const l = Ve(t), s = () => {
432
+ const a = Jn(e, n);
433
+ if (!Number.isFinite(a)) return;
434
+ const p = l === null ? 0 : l.getBoundingClientRect().height;
435
+ p !== r && (r = p, t.style.setProperty(ye, `${String(p)}px`));
436
+ const v = a + p;
437
+ v !== o && (o = v, e.style.setProperty(le, `${String(v)}px`));
438
+ };
439
+ s();
440
+ let c = null;
441
+ const m = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
442
+ c === null && (c = requestAnimationFrame(() => {
443
+ c = null, s();
444
+ }));
445
+ });
446
+ return m?.observe(e), m?.observe(n), l !== null && m?.observe(l), () => {
447
+ m?.disconnect(), c !== null && cancelAnimationFrame(c), e.style.removeProperty(le), t.style.removeProperty(ye);
448
+ };
449
+ }, at = (e) => {
450
+ 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), v = B(null);
451
+ $(() => {
452
+ const u = a.current, f = u === null ? null : j(u);
453
+ if (u === null || f === null || c) return;
454
+ const d = /* @__PURE__ */ new Map(), E = (w) => {
455
+ const P = d.get(w);
456
+ if (P !== void 0) return P;
457
+ const L = Zn(w);
458
+ return d.set(w, L), L;
459
+ }, y = (w) => rt(w, u, E);
460
+ let M = !1;
461
+ const g = () => {
462
+ const w = st(f);
463
+ w !== M && (M = w, w ? u.addEventListener("wheel", y, { capture: !0, passive: !1 }) : u.removeEventListener("wheel", y, { capture: !0 }));
464
+ };
465
+ g();
466
+ const b = typeof ResizeObserver > "u" ? null : new ResizeObserver(g);
467
+ return b?.observe(f), b?.observe(u), () => {
468
+ b?.disconnect(), u.removeEventListener("wheel", y, { capture: !0 });
469
+ };
470
+ }, [c]), q(() => {
471
+ const u = a.current, f = u === null ? null : j(u), d = u === null ? null : u.closest(`[${J}]`);
472
+ if (!(u === null || f === null || !(d instanceof HTMLElement)))
473
+ return it(d, f, u);
474
+ }, []), q(() => {
475
+ const u = a.current, f = u === null ? null : j(u);
476
+ if (u === null || f === null) return;
477
+ const d = o.readingPositionOf(t, n);
478
+ p.current = d === null ? null : { doc: n, position: d }, d !== null && xe(u, f, d);
479
+ let E = null;
480
+ const y = () => {
481
+ E === null && (E = requestAnimationFrame(() => {
482
+ E = null;
483
+ const M = v.current;
484
+ M !== null && o.saveReadingPosition(t, M, et(u, f));
485
+ }));
486
+ };
487
+ return f.addEventListener("scroll", y, { passive: !0 }), () => {
488
+ f.removeEventListener("scroll", y), E !== null && cancelAnimationFrame(E);
489
+ };
490
+ }, [o, t, n]), q(() => {
491
+ const u = a.current, f = u === null ? null : u.closest(`[${J}]`);
492
+ if (u === null || f === null) return;
493
+ const d = s.take(t);
494
+ return d !== null && ot(f, u, d), () => {
495
+ const E = tt(f, f.ownerDocument.activeElement);
496
+ E !== null && s.hold(t, E);
497
+ };
498
+ }, [s, t]);
499
+ const C = D((u) => {
500
+ const f = a.current, d = f === null ? null : j(f);
501
+ if (f === null || d === null) return;
502
+ const E = v.current;
503
+ v.current = u;
504
+ const y = p.current;
505
+ p.current = null, y !== null && y.doc === u ? xe(f, d, y.position) : E !== null && E !== u && (d.scrollTop = 0);
506
+ }, []), x = D(() => l(n), [l, n]);
507
+ return (
508
+ /* @__PURE__ */ T(
509
+ "div",
510
+ {
511
+ ref: a,
512
+ role: "group",
513
+ "aria-label": m,
514
+ className: "aqmx-multi-panel-frame",
515
+ tabIndex: -1,
516
+ "data-aqmx-panel-frame": t,
517
+ "data-aqmx-maximized": c ? "true" : "false",
518
+ "data-testid": "markdown-explorer-panel-frame",
519
+ onDoubleClick: c ? void 0 : x,
520
+ children: /* @__PURE__ */ T(r, { docPath: n, panelId: t, maximized: c, title: m, onContentShown: C })
521
+ }
522
+ )
523
+ );
524
+ }, ct = Ke(at), K = (e, n) => {
525
+ const t = e.panelIds.get(n);
526
+ if (t === void 0) throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);
527
+ return t;
528
+ }, Ee = (e) => Object.fromEntries(un(e).map((n) => [n, []])), ut = (e, n) => {
529
+ const t = _n(ne(e, n), n.visible);
530
+ return Object.fromEntries(t.map((o, r) => [De(r), o.map((l) => K(e, l))]));
531
+ }, dt = (e, n) => {
532
+ const t = W(e);
533
+ return Ae(Object.keys(n)).map(
534
+ (o) => (n[o] ?? []).flatMap((r) => {
535
+ const l = t.get(r);
536
+ return l === void 0 ? [] : [l];
537
+ })
538
+ );
539
+ }, mt = (e) => ({
540
+ switchToCustomDragMode: e.panelSwitchToCustomDrag,
541
+ switchToNormalDragMode: e.panelSwitchToNormalDrag,
542
+ hidePanel: e.panelHide,
543
+ maximizePanel: e.panelMaximize,
544
+ restorePanel: e.panelRestore,
545
+ closePanel: e.panelClose,
546
+ movePanelToPreviousColumn: e.panelMovePreviousColumn,
547
+ movePanelToNextColumn: e.panelMoveNextColumn,
548
+ movePanelUp: e.panelMoveUp,
549
+ movePanelDown: e.panelMoveDown,
550
+ customDragModeBadge: e.panelCustomDragBadge,
551
+ panelMoved: e.panelMoved,
552
+ panelMoveUnavailable: e.panelMoveUnavailable,
553
+ panelDragStarted: e.panelDragStarted,
554
+ panelDragCancelled: e.panelDragCancelled,
555
+ hiddenPanels: e.hiddenPanelsTitle,
556
+ hiddenPanelBadge: e.hiddenPanelBadge,
557
+ hiddenPanelNotice: e.hiddenPanelNotice,
558
+ emptyColumn: e.multiColumnEmpty,
559
+ dropZone: e.multiColumnRegion,
560
+ dropHere: e.panelDropHere
561
+ }), 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) => {
562
+ const t = Object.entries(e);
563
+ return t.length !== Object.keys(n).length ? !1 : t.every(([o, r]) => {
564
+ const l = n[o];
565
+ return l !== void 0 && l.length === r.length && l.every((s, c) => r[c] === s);
566
+ });
567
+ }, be = ["keydown", "pointerdown", "wheel", "touchstart"], Y = /* @__PURE__ */ new WeakMap(), Oe = (e, n, t) => {
568
+ for (let o = n; o !== null && o !== t; o = o.parentElement) {
569
+ e.observe(o);
570
+ for (let r = o.previousElementSibling; r !== null; r = r.previousElementSibling) e.observe(r);
571
+ }
572
+ }, Ot = (e) => {
573
+ const n = /* @__PURE__ */ new Map();
574
+ for (let t = e.parentElement; t !== null; t = t.parentElement) n.set(t, { top: t.scrollTop, left: t.scrollLeft });
575
+ return n;
576
+ }, Z = (e, n, t) => {
577
+ Y.get(e)?.();
578
+ const o = e.querySelector(`[${J}="${n}"]`);
579
+ if (!(o instanceof HTMLElement)) return;
580
+ const r = t !== null && o.contains(t) ? t : null;
581
+ let l = /* @__PURE__ */ new Map();
582
+ const s = () => {
583
+ if (!o.isConnected) return;
584
+ o.scrollIntoView({ block: "nearest", inline: "nearest", behavior: "instant" });
585
+ const v = r?.isConnected === !0 ? r : o;
586
+ v !== o && v.scrollIntoView({ block: "nearest", inline: "nearest", behavior: "instant" }), l = Ot(v);
587
+ };
588
+ if (s(), typeof ResizeObserver > "u") return;
589
+ const c = new ResizeObserver(s);
590
+ Oe(c, o, o.closest(Q)), r !== null && Oe(c, r, o);
591
+ const { ownerDocument: m } = e, a = (v) => {
592
+ const C = v.target === m ? m.scrollingElement : v.target;
593
+ if (!(C instanceof Element)) return;
594
+ const x = l.get(C);
595
+ x !== void 0 && (C.scrollTop !== x.top || C.scrollLeft !== x.left) && p();
596
+ }, p = () => {
597
+ c.disconnect();
598
+ for (const v of be) m.removeEventListener(v, p, !0);
599
+ m.removeEventListener("scroll", a, !0), Y.get(e) === p && Y.delete(e);
600
+ };
601
+ for (const v of be) m.addEventListener(v, p, { capture: !0, passive: !0 });
602
+ m.addEventListener("scroll", a, { capture: !0, passive: !0 }), Y.set(e, p);
603
+ }, je = (e, n) => {
604
+ const t = e.querySelector(`[${X}="${n}"]`);
605
+ return t instanceof HTMLElement ? (Z(e, n, null), t.focus({ preventScroll: !0 }), !0) : !1;
606
+ }, de = (e, n) => {
607
+ const t = e.querySelector(`[${J}="${n}"]`);
608
+ return t instanceof HTMLElement && t.contains(e.ownerDocument.activeElement);
609
+ }, Pe = (e, n) => {
610
+ if (!de(e, n)) return null;
611
+ const t = [...e.querySelectorAll(`[${X}]`)].map((s) => s.getAttribute(X)), o = t.indexOf(n), r = t[o + 1];
612
+ if (o >= 0 && typeof r == "string") return { kind: "panel", panelId: r };
613
+ const l = t[o - 1];
614
+ return o > 0 && typeof l == "string" ? { kind: "panel", panelId: l } : { kind: "stage" };
615
+ }, Ce = (e, n) => {
616
+ requestAnimationFrame(() => {
617
+ const t = e.current;
618
+ t !== null && (n.kind === "panel" && je(t, n.panelId) || t.focus({ preventScroll: !0 }));
619
+ });
620
+ }, Ye = (e, n) => {
621
+ requestAnimationFrame(() => {
622
+ const t = e.current;
623
+ t !== null && je(t, n);
624
+ });
625
+ }, Pt = (e, n, t) => {
626
+ requestAnimationFrame(() => {
627
+ const o = e.current;
628
+ if (o === null) return;
629
+ const { activeElement: r, body: l } = o.ownerDocument;
630
+ if (Z(o, n, t && de(o, n) ? r : null), !t || r !== null && r !== l && r.isConnected) return;
631
+ const s = o.querySelector(`[${X}="${n}"]`);
632
+ s instanceof HTMLElement && s.focus({ preventScroll: !0 });
633
+ });
634
+ }, Ct = ({ store: e, stageRef: n }) => {
635
+ 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), [v, C] = V(!1), [x] = V(() => Ee(m)), u = _(() => mt(o), [o]), f = D(
636
+ (S) => {
637
+ e.arrange(dt(e.getSnapshot().layout, S));
638
+ },
639
+ [e]
640
+ ), d = mn({ initialColumnPanels: x, initialPanelVisibility: {}, debugConfig: ge, onColumnPanelsChange: f }), { columnPanels: E, setColumnPanels: y } = d, M = B(p), g = B(E);
641
+ q(() => {
642
+ M.current = p, g.current = E;
643
+ }, [p, E]);
644
+ const b = D(
645
+ (S) => {
646
+ const O = n.current;
647
+ if (O === null) return;
648
+ const { plan: H, stageBlockSize: R } = Kn(O, s);
649
+ if (Number.isFinite(R) && R > 0 && O.style.setProperty(ue, `${String(R)}px`), M.current && !S) return;
650
+ const k = Xe(e.getSnapshot().visibleColumns, H);
651
+ k !== null && e.setVisibleColumns(k);
652
+ },
653
+ [e, n, s]
654
+ );
655
+ q(() => {
656
+ b(!0), C(!0);
657
+ }, [b]), $(() => {
658
+ const S = n.current;
659
+ if (S === null || typeof ResizeObserver > "u") return;
660
+ let O = null;
661
+ const H = new ResizeObserver(() => {
662
+ O === null && (O = requestAnimationFrame(() => {
663
+ O = null, b(!1);
664
+ }));
665
+ }), R = S.querySelector(Q)?.firstElementChild, k = S.querySelector(`[${ce}]`);
666
+ return R instanceof Element && H.observe(R), k instanceof Element && H.observe(k), () => {
667
+ H.disconnect(), O !== null && cancelAnimationFrame(O);
668
+ };
669
+ }, [n, b]), $(() => {
670
+ p || b(!1);
671
+ }, [p, b]);
672
+ const w = _(() => v ? ut(c, { logical: s, visible: m }) : Ee(m), [v, c, s, m]);
673
+ q(() => {
674
+ bt(g.current, w) || y(w);
675
+ }, [w, y]);
676
+ const P = _(() => Ae(Object.keys(E)).map((S) => ({ id: S, key: S, className: "aqmx-multi-column" })), [E]), L = _(
677
+ () => c.docs.map((S) => {
678
+ const O = K(c, S);
679
+ return { id: O, component: ct, title: ae(a, S), props: { docPath: S, panelId: O }, minHeight: xt, maxHeight: Et };
680
+ }),
681
+ [c, a]
682
+ ), 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(
683
+ (S) => {
684
+ const { layout: O } = e.getSnapshot();
685
+ for (const [H, R] of W(O)) {
686
+ const k = S[H];
687
+ if (k === void 0 || k !== O.hidden.has(R)) continue;
688
+ const me = e.titleOf(R);
689
+ if (k) {
690
+ if (!e.setHidden(R, !1)) continue;
691
+ r.announce(o.panelShown(me)), Ye(n, H);
692
+ continue;
693
+ }
694
+ const fe = n.current, pe = fe === null ? null : Pe(fe, H);
695
+ e.setHidden(R, !0) && (r.announce(o.panelHidden(me)), pe !== null && Ce(n, pe));
696
+ }
697
+ },
698
+ [e, n, r, o]
699
+ ), N = D(
700
+ (S) => {
701
+ const O = W(e.getSnapshot().layout).get(S);
702
+ if (O === void 0) return;
703
+ const H = e.titleOf(O), R = n.current, k = R === null ? null : Pe(R, S);
704
+ e.close(O) && (r.announce(o.panelClosed(H)), k !== null && Ce(n, k));
705
+ },
706
+ [e, n, r, o]
707
+ ), A = D(
708
+ (S) => {
709
+ if (S === null) {
710
+ l(null);
711
+ return;
712
+ }
713
+ const O = W(e.getSnapshot().layout).get(S);
714
+ O !== void 0 && l(O);
715
+ },
716
+ [e, l]
717
+ );
718
+ return /* @__PURE__ */ T("div", { className: "aqmx-multi-layout", "aria-busy": !v, children: /* @__PURE__ */ T(
719
+ fn,
720
+ {
721
+ columns: P,
722
+ panels: L,
723
+ columnPanels: E,
724
+ onColumnPanelsChange: f,
725
+ panelVisibility: I,
726
+ onPanelVisibilityChange: h,
727
+ dragState: d.dragState,
728
+ dragOverPosition: d.dragOverPosition,
729
+ originalPanelPosition: d.originalPanelPosition,
730
+ dragModes: d.dragModes,
731
+ debugConfig: ge,
732
+ panelSizes: d.panelSizes,
733
+ customDrag: d.customDrag,
734
+ setPanelRef: d.setPanelRef,
735
+ onDragStart: d.handleDragStart,
736
+ onDragEnd: d.handleDragEnd,
737
+ onPlaceholderDragEnter: d.handlePlaceholderDragEnter,
738
+ onPlaceholderDragLeave: d.handlePlaceholderDragLeave,
739
+ onDragOverWithInsert: d.handleDragOverWithInsert,
740
+ onDropWithInsert: d.handleDropWithInsert,
741
+ onColumnDragLeave: d.handleColumnDragLeave,
742
+ onPanelMouseDown: d.handleMouseDown,
743
+ onPanelSizeInfoClick: d.handlePanelSizeInfoClick,
744
+ onToggleDragMode: d.toggleDragMode,
745
+ onPanelClose: N,
746
+ onPanelMaximizeChange: A,
747
+ maximizedPanel: i,
748
+ dragHandle: "header",
749
+ labels: u,
750
+ panelClassName: "aqmx-multi-panel",
751
+ renderPanelScrollArea: wt,
752
+ renderStageScrollBar: yt
753
+ }
754
+ ) });
755
+ }, oe = { blockStart: "--aqmx-multi-toast-block-start", inlineEnd: "--aqmx-multi-toast-inline-end", room: "--aqmx-multi-toast-room" }, Nt = (e, n) => {
756
+ 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];
757
+ return o.some(
758
+ (l) => r.some((s) => {
759
+ const c = n.ownerDocument.elementsFromPoint(l, s), m = c.findIndex((p) => n.contains(p)), a = c.findIndex((p) => e.contains(p));
760
+ return m !== -1 && a !== -1 && a < m;
761
+ })
762
+ );
763
+ }, Mt = (e, n) => {
764
+ const t = n.getBoundingClientRect(), o = n.ownerDocument.documentElement.clientWidth, r = getComputedStyle(n).direction === "rtl";
765
+ 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(), () => {
766
+ e.isConnected && e.hidePopover();
767
+ };
768
+ }, Tt = ({ store: e, body: n, limitNotice: t, onLimitNoticeCovered: o, ref: r }) => {
769
+ const { config: l, labels: s, announcer: c } = G(), m = B(null), a = B(null), p = z(e, (g) => g.ready), v = z(e, (g) => g.layout.docs.length > 0), C = z(e, (g) => g.visibleColumns), x = Me(sn), u = D(
770
+ (g) => {
771
+ const { layout: b } = e.getSnapshot(), w = b.maximized, P = g === null && w !== null ? b.panelIds.get(w) : void 0, L = m.current, I = P !== void 0 && L !== null && de(L, P);
772
+ e.maximize(g) && (g !== null ? c.announce(s.panelMaximized(e.titleOf(g))) : w !== null && c.announce(s.panelRestored(e.titleOf(w))), P !== void 0 && Pt(m, P, I));
773
+ },
774
+ [e, c, s]
775
+ ), f = D(
776
+ (g, b, w, P) => {
777
+ if (w === b) {
778
+ e.setPendingHash(g, P);
779
+ return;
780
+ }
781
+ const L = e.navigate(b, w);
782
+ if (L === "navigated") {
783
+ e.setPendingHash(g, P);
784
+ return;
785
+ }
786
+ if (L !== "existing") return;
787
+ const { layout: I } = e.getSnapshot(), i = I.panelIds.get(w);
788
+ i !== void 0 && (c.announce(s.panelAlreadyOpen(e.titleOf(w))), I.maximized === null ? e.setHidden(w, !1) : u(w), e.setPendingHash(i, P), Ye(m, i));
789
+ },
790
+ [e, c, s, u]
791
+ );
792
+ q(() => {
793
+ if (t === null || x !== null || !we()) return;
794
+ const g = a.current, b = m.current;
795
+ if (g === null || b === null) throw new Error("[markdown-explorer] the panel-limit notice and the stage must be mounted together");
796
+ return Mt(g, b);
797
+ }, [t, x]), $(() => {
798
+ const g = a.current;
799
+ if (t === null || g === null) return;
800
+ const { ownerDocument: b } = g;
801
+ let w = null;
802
+ const P = (L) => {
803
+ const I = L.target;
804
+ I instanceof Element && (w !== null && cancelAnimationFrame(w), w = requestAnimationFrame(() => {
805
+ w = null, b.activeElement === I && g.isConnected && Nt(g, I) && o();
806
+ }));
807
+ };
808
+ return b.addEventListener("focusin", P, !0), () => {
809
+ b.removeEventListener("focusin", P, !0), w !== null && cancelAnimationFrame(w);
810
+ };
811
+ }, [t, x, o]), Je(
812
+ r,
813
+ () => ({
814
+ bringIntoView: (g) => {
815
+ requestAnimationFrame(() => {
816
+ const b = m.current, w = e.getSnapshot().layout.panelIds.get(g);
817
+ b !== null && w !== void 0 && Z(b, w, null);
818
+ });
819
+ }
820
+ }),
821
+ [e]
822
+ ), $(() => {
823
+ const g = m.current;
824
+ return () => {
825
+ g !== null && Y.get(g)?.();
826
+ };
827
+ }, []);
828
+ const d = D((g, b) => {
829
+ const w = m.current;
830
+ w !== null && Z(w, g, b);
831
+ }, []), [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]);
832
+ return (
833
+ /* @__PURE__ */ re("section", { ref: m, className: "aqmx-multi-stage", style: pt, tabIndex: -1, "aria-label": s.multiRegion, "aria-busy": v && !p, "data-testid": "markdown-explorer-stage", "data-aqmx-visible-columns": C, children: [
834
+ /* @__PURE__ */ T("span", { className: "aqmx-multi-probe", "aria-hidden": "true", [ce]: "" }),
835
+ v ? 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: [
836
+ /* @__PURE__ */ T("span", {}),
837
+ /* @__PURE__ */ T("span", {}),
838
+ /* @__PURE__ */ T("span", {})
839
+ ] }, g)) }) : /* @__PURE__ */ T("div", { className: "aqmx-empty", "data-testid": "markdown-explorer-multi-empty", children: /* @__PURE__ */ T("p", { className: "aqmx-empty-title", children: s.multiEmpty }) }),
840
+ t === null ? null : x !== null ? xn(
841
+ /* @__PURE__ */ T("div", { ref: a, className: "aqmx-toast aqmx-multi-toast", "data-testid": "markdown-explorer-panel-limit", children: t }),
842
+ x
843
+ ) : (
844
+ /* @__PURE__ */ T("div", { ref: a, popover: we() ? "manual" : void 0, className: "aqmx-toast aqmx-multi-toast", "data-testid": "markdown-explorer-panel-limit", children: t })
845
+ )
846
+ ] })
847
+ );
848
+ }, Lt = 3e3, It = (e, n) => {
849
+ if (n !== null) return n;
850
+ const [t] = e;
851
+ return t === void 0 ? null : t;
852
+ }, Ne = (e, n, t) => {
853
+ 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);
854
+ return l === void 0 ? null : l;
855
+ }, At = (e, n, t) => {
856
+ switch (n) {
857
+ case "opened":
858
+ return e.panelOpened(t);
859
+ case "shown":
860
+ return e.panelShown(t);
861
+ case "closed":
862
+ return e.panelClosed(t);
863
+ default: {
864
+ const o = n;
865
+ throw new RangeError(`[markdown-explorer] unknown toggle outcome ${JSON.stringify(o)}`);
866
+ }
867
+ }
868
+ }, jt = ({ location: e }) => {
869
+ 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) }));
870
+ m.docs !== l && a({ docs: l, latest: Ne(m.docs, l, m.latest) });
871
+ const p = s !== null ? s : m.latest, [v, C] = V(!1), x = B(null), [u, f] = V(0), d = B(null), E = B(null);
872
+ q(() => {
873
+ const P = d.current;
874
+ d.current = null, P !== null && (r.whenUrlRendered(() => o.announce(P.announcement)), E.current?.bringIntoView(P.doc));
875
+ }), $(
876
+ () => () => {
877
+ x.current !== null && clearTimeout(x.current);
878
+ },
879
+ []
880
+ );
881
+ const y = D(() => {
882
+ x.current !== null && clearTimeout(x.current), C(!0), x.current = setTimeout(() => {
883
+ x.current = null, C(!1);
884
+ }, Lt);
885
+ }, []), M = D(() => {
886
+ x.current !== null && clearTimeout(x.current), x.current = null, C(!1);
887
+ }, []), g = D(
888
+ (P) => {
889
+ const L = r.titleOf(P), I = r.toggle(P);
890
+ I === "rejected" && y();
891
+ const i = I === "rejected" ? t.panelLimit(n.multiView.maxPanels) : At(t, I, L);
892
+ if (I === "shown") {
893
+ d.current = { doc: P, announcement: i }, f((h) => h + 1);
894
+ return;
895
+ }
896
+ r.whenUrlRendered(() => {
897
+ o.announce(i), I === "opened" && E.current?.bringIntoView(P);
898
+ });
899
+ },
900
+ [r, y, o, t, n]
901
+ ), b = _(() => new Set(l), [l]), w = _(() => ({ href: Te(n, { view: "tree", source: c, doc: It(l, s) }), target: "tree" }), [n, c, l, s]);
902
+ return /* @__PURE__ */ T(
903
+ an,
904
+ {
905
+ view: "multi",
906
+ explorer: /* @__PURE__ */ T(cn, { mode: "multi", sourceId: c, currentPath: p, openPaths: b, onOpenDocument: g, onSourceChange: r.changeSource, viewSwitch: w }),
907
+ content: /* @__PURE__ */ T(Tt, { ref: E, store: r, body: Gn, limitNotice: v ? t.panelLimit(n.multiView.maxPanels) : null, onLimitNoticeCovered: M }),
908
+ contentCoversPage: s !== null,
909
+ sheetDismissals: u,
910
+ onDraggingChange: r.setSplitDragging
911
+ }
912
+ );
913
+ };
914
+ export {
915
+ jt as MultiLayout,
916
+ Lt as PANEL_LIMIT_NOTICE_MS,
917
+ Ne as latestOpenedDocument,
918
+ It as treeSwitchDocument
919
+ };