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