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