@aiquants/markdown-explorer 0.29.0 → 0.30.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.
@@ -0,0 +1,952 @@
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 R, memo as Qe, useEffect as U, useImperativeHandle as Ze } from "react";
3
+ import { n as ce, e as Me, o as en, P as nn, q as tn } from "./location-CKuabtKl.js";
4
+ import { L as on, u as J, M as rn, O as ln, D as sn, i as an, f as cn, Q as V, h as Ae, R as un, N as dn, S as ke, U as mn, V as Ie, W as fn, X as Le, Y as pn } from "./index-auQVKY4M.js";
5
+ import { S as gn, a as hn, b as vn } from "./ExplorerSplit-D3f1FiZ7.js";
6
+ import { SCROLL_AREA_SELECTOR as Re, SCROLL_ROOT_SELECTOR as te, PANEL_ACTION_ATTRIBUTE as he, generateColumnIds as wn, sortColumnIds as De, generateColumnId as _e, NO_PANEL_DRAG_ATTRIBUTE as yn, useDragDropColumns as Sn, DEFAULT_DEBUG_CONFIG as ve, DragDropLayout as xn } from "@aiquants/drag-drop-panels";
7
+ import { useNavigate as En, useLocation as On } from "react-router";
8
+ import { s as Pn, r as bn, w as Cn } from "./storage-CmGHg7OA.js";
9
+ import { H as Tn, i as Nn } from "./dataRoute-DLhQfdoW.js";
10
+ import { createPortal as Mn } from "react-dom";
11
+ import { HostedScrollArea as An } from "@aiquants/markdown";
12
+ const kn = () => {
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
+ }, In = (e, n) => {
30
+ const t = e.pendingHashes.get(n);
31
+ return t === void 0 ? null : t;
32
+ }, Ln = 0xcbf29ce484222325n, Rn = 0x100000001b3n, Dn = (1n << 64n) - 1n, _n = (1n << 53n) - 1n, zn = new TextEncoder(), Hn = (e) => {
33
+ let n = Ln;
34
+ for (const t of zn.encode(e))
35
+ n = (n ^ BigInt(t)) * Rn & Dn;
36
+ return Number(n & _n);
37
+ }, oe = 256, Bn = (e) => `aqmx-p-${Hn(e).toString(36)}`, He = (e, n) => {
38
+ const t = Bn(e);
39
+ let o = t;
40
+ for (let r = 2; n.has(o); r += 1) o = `${t}-${String(r)}`;
41
+ return o;
42
+ }, qn = /* @__PURE__ */ new Map(), Fn = (e, n = qn) => {
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 = ([u, p]) => e.slice(u, p).reduce((i, y) => i + y.length, 0);
56
+ let l = t;
57
+ for (const u of o) r(u) < r(l) && (l = u);
58
+ let a = l[0];
59
+ for (let u = l[0]; u < l[1]; u += 1) (e[u]?.length ?? 0) < (e[a]?.length ?? 0) && (a = u);
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
+ }, Vn = (e, n) => ce(e.length, n).map(([t, o]) => e.slice(t, o).flat()), $n = (e, n, t) => {
70
+ const [o, r] = n, l = r - o, a = e.length, u = Array.from({ length: l }, (w, d) => {
71
+ const v = [0];
72
+ for (const g of e) v.push((v.at(-1) ?? 0) + (t(g) === o + d ? 1 : 0));
73
+ return v;
74
+ }), p = (w, d, v) => (u[w]?.[v] ?? 0) - (u[w]?.[d] ?? 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 d = 0; d <= a; d += 1)
78
+ for (let v = 0; v <= d; v += 1) {
79
+ const g = (i[w]?.[v] ?? Number.NEGATIVE_INFINITY) + p(w, v, d), O = i[w + 1], C = y[w + 1];
80
+ O && C && g > (O[d] ?? Number.NEGATIVE_INFINITY) && (O[d] = g, C[d] = v);
81
+ }
82
+ const b = Array.from({ length: l }, () => []);
83
+ let k = a;
84
+ for (let w = l; w > 0; w -= 1) {
85
+ const d = y[w]?.[k] ?? 0;
86
+ b[w - 1] = e.slice(d, k), k = d;
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
+ }, Un = (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
+ }, jn = (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 = Un(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), u = a.get(n);
127
+ if (u === void 0) throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);
128
+ a.delete(n), a.set(t, u);
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
+ }, Gn = (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
+ }, Wn = (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
+ }, Kn = (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(), u = ce(t.logical, t.visible), p = Array.from({ length: t.logical }, () => []);
152
+ for (const [i, y] of u.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 $n(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: Fn(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, G = Object.freeze({ columnOf: /* @__PURE__ */ new Map(), hidden: /* @__PURE__ */ new Set() }), Jn = (e, n) => {
183
+ if (e === null || e === "") return G;
184
+ let t;
185
+ try {
186
+ t = JSON.parse(e);
187
+ } catch {
188
+ return G;
189
+ }
190
+ if (t === null || typeof t != "object" || Array.isArray(t)) return G;
191
+ const o = t;
192
+ if (o.v !== Ue) return G;
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
+ }, Xn = (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 ? Tn(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 (!Nn(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(), u = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
214
+ let i = {
215
+ layout: le({ docs: n.docs, maximized: n.maximized, markup: n.markup, stored: G }, 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), d = 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 = Xn(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, d = s, g.push(I), t(I, P));
239
+ }, m = (s) => {
240
+ const h = new Set(s.panelIds.values());
241
+ for (const x of [...u.keys()]) h.has(x) || u.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(d, s, "replace"), c(), !0), L = () => ({ 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 } = jn(i.layout, s, L(), 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 && (u.delete(S), p.delete(S)), T(P), I;
261
+ },
262
+ setHidden: (s, h) => T($e(i.layout, s, h)),
263
+ maximize: (s) => T(Wn(i.layout, s)),
264
+ setMarkup: (s, h) => T(Gn(i.layout, s, h)),
265
+ arrange: (s) => T(Kn(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, d = 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 && u.set(s, { doc: h, position: P });
316
+ },
317
+ readingPositionOf: (s, h) => {
318
+ const P = u.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
+ }, Zn = (e) => {
333
+ const { config: n, storageNamespace: t } = J(), o = En(), r = q(o), l = Pn(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) => Cn(l, i)
341
+ })
342
+ );
343
+ F(() => {
344
+ r.current = o;
345
+ }, [o]);
346
+ const u = On(), p = D(() => ({ location: e, navigated: u }), [e, u]);
347
+ return F(() => {
348
+ a.observeLocation(p.location);
349
+ }, [a, p]), F(() => {
350
+ a.loadStored(Jn(bn(l), n.multiView.columns));
351
+ }, [a, l, n]), a;
352
+ }, et = (e) => {
353
+ const n = e.closest(Re);
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
+ }, nt = ({ docPath: e, panelId: n, maximized: t, title: o, onContentShown: r }) => {
357
+ const { store: l, followLink: a, revealInPanel: u, keepAtStartInPanel: p } = ue(), { announcer: i } = J(), y = _(l, (c) => In(c, n)), E = _(l, (c) => c.layout.markup.has(e)), b = R((c, f) => a(n, e, c, f), [a, n, e]), k = R(() => l.setPendingHash(n, null), [l, n]), w = D(() => ({ read: (c) => l.imageViewOf(n, c), save: (c, f) => l.saveImageView(n, c, f) }), [l, n]), d = R(
358
+ (c, f) => {
359
+ f.kind !== "failure" && l.setTitle(c, f.name), r(c);
360
+ },
361
+ [l, r]
362
+ ), v = R(
363
+ (c) => {
364
+ l.whenUrlRendered(() => i.announce(c));
365
+ },
366
+ [l, i]
367
+ ), g = D(
368
+ () => ({
369
+ scrollerOf: et,
370
+ reveal: (c) => u(n, c),
371
+ keepAtStart: (c, f) => p(n, c, f)
372
+ }),
373
+ [u, 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 = R(() => 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: d })
381
+ ] });
382
+ }, Se = () => typeof HTMLElement < "u" && typeof HTMLElement.prototype.showPopover == "function" && typeof HTMLElement.prototype.hidePopover == "function", me = "data-aqmx-column-probe", Z = "data-panel-id", ae = "--aqmx-multi-panel-chrome", tt = (e) => e === "normal" ? 0 : V(e), ot = (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), u = t.clientHeight - V(l.paddingTop) - V(l.paddingBottom);
387
+ return { plan: { trackInlineSize: a, gap: tt(l.columnGap), minColumnInlineSize: r, logicalColumns: n }, stageBlockSize: u };
388
+ }, rt = (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", lt = (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
+ }, st = (e) => {
397
+ const n = getComputedStyle(e), t = Number.parseFloat(n.lineHeight);
398
+ return Number.isFinite(t) ? t : Number.parseFloat(n.fontSize);
399
+ }, it = (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(Re);
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
+ }, Ye = (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
+ }, at = (e, n) => {
416
+ const t = Ye(e, n), o = [];
417
+ let r = e;
418
+ for (let a = Ee([...r.children], t); a >= 0; a = Ee([...r.children], t)) {
419
+ const u = r.children[a];
420
+ if (u === void 0) break;
421
+ o.push(a), r = u;
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, u = l < 0 && a > 0 ? l / a * r.height : l;
431
+ n.scrollTop += r.top - Ye(e, n) - u;
432
+ }, ct = Object.freeze(["data-testid", "aria-label", "title", "href", "id", "name"]), Ge = (e) => {
433
+ const n = e.getAttribute(he);
434
+ return JSON.stringify(n === null ? [e.tagName, ...ct.map((t) => e.getAttribute(t))] : [e.tagName, he, n]);
435
+ }, ut = (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: Ge(n) };
444
+ }, dt = (e, n, t) => {
445
+ let o = e;
446
+ for (const r of t.path) o = o?.children[r];
447
+ o instanceof HTMLElement && Ge(o) === t.signature && un(o) || n.focus({ preventScroll: !0 });
448
+ }, mt = (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 = it(e, r, t);
453
+ (o || ft(r, l)) && (e.preventDefault(), r.scrollTop += l);
454
+ }, ft = (e, n) => n < 0 ? e.scrollTop > 0 : n > 0 ? Math.ceil(e.scrollTop + e.clientHeight) < e.scrollHeight : !1, pt = (e) => e.scrollHeight > e.clientHeight, gt = (e, n, t) => {
455
+ let o = Number.NaN, r = Number.NaN;
456
+ const l = je(t), a = () => {
457
+ const i = rt(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 u = null;
466
+ const p = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
467
+ u === null && (u = requestAnimationFrame(() => {
468
+ u = null, a();
469
+ }));
470
+ });
471
+ return p?.observe(e), p?.observe(n), l !== null && p?.observe(l), () => {
472
+ p?.disconnect(), u !== null && cancelAnimationFrame(u), e.style.removeProperty(ae), t.style.removeProperty(xe);
473
+ };
474
+ }, ht = (e) => {
475
+ const { docPath: n, panelId: t } = lt(e), { store: o, Body: r, maximize: l, focusCarry: a } = ue(), u = _(o, (d) => d.layout.maximized === n), p = _(o, (d) => de(d.titles, n)), i = q(null), y = q(null), E = q(null), b = q(null);
476
+ U(() => {
477
+ const d = i.current, v = d === null ? null : W(d);
478
+ if (d === null || v === null || u) 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 = st(f);
483
+ return g.set(f, T), T;
484
+ }, C = (f) => mt(f, d, O);
485
+ let A = !1;
486
+ const N = () => {
487
+ const f = pt(v);
488
+ f !== A && (A = f, f ? d.addEventListener("wheel", C, { capture: !0, passive: !1 }) : d.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(d), () => {
493
+ c?.disconnect(), d.removeEventListener("wheel", C, { capture: !0 });
494
+ };
495
+ }, [u]), F(() => {
496
+ const d = i.current, v = d === null ? null : W(d), g = d === null ? null : d.closest(`[${Z}]`);
497
+ if (!(d === null || v === null || !(g instanceof HTMLElement)))
498
+ return gt(g, v, d);
499
+ }, []), F(() => {
500
+ const d = i.current, v = d === null ? null : W(d);
501
+ if (d === null || v === null) return;
502
+ const g = (f) => {
503
+ Oe(d, 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 = d.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 || d.getBoundingClientRect().width !== A) return;
512
+ const m = E.current;
513
+ m !== null && o.saveReadingPosition(t, m, at(d, v));
514
+ }));
515
+ };
516
+ v.addEventListener("scroll", N, { passive: !0 });
517
+ const c = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
518
+ const f = d.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(d), () => {
525
+ v.removeEventListener("scroll", N), c?.disconnect(), C !== null && cancelAnimationFrame(C);
526
+ };
527
+ }, [o, t, n]), F(() => {
528
+ const d = i.current, v = d === null ? null : d.closest(`[${Z}]`);
529
+ if (d === null || v === null) return;
530
+ const g = a.take(t);
531
+ return g !== null && dt(v, d, g), () => {
532
+ const O = ut(v, v.ownerDocument.activeElement);
533
+ O !== null && a.hold(t, O);
534
+ };
535
+ }, [a, t]);
536
+ const k = R((d) => {
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 = d;
541
+ const C = y.current;
542
+ y.current = null, C !== null && C.doc === d ? (Oe(v, g, C.position), b.current = g.scrollTop) : O !== null && O !== d && (g.scrollTop = 0);
543
+ }, []), w = R(() => l(n), [l, n]);
544
+ return (
545
+ /* @__PURE__ */ M(
546
+ "div",
547
+ {
548
+ ref: i,
549
+ role: "group",
550
+ "aria-label": p,
551
+ className: "aqmx-multi-panel-frame",
552
+ tabIndex: -1,
553
+ "data-aqmx-panel-frame": t,
554
+ "data-aqmx-maximized": u ? "true" : "false",
555
+ "data-testid": "markdown-explorer-panel-frame",
556
+ ...u ? Ae : {},
557
+ onDoubleClick: u ? void 0 : w,
558
+ children: /* @__PURE__ */ M(r, { docPath: n, panelId: t, maximized: u, title: p, onContentShown: k })
559
+ }
560
+ )
561
+ );
562
+ }, vt = Qe(ht), Q = (e, n) => {
563
+ const t = e.panelIds.get(n);
564
+ if (t === void 0) throw new Error(`[markdown-explorer] the open document ${JSON.stringify(n)} has no panel id`);
565
+ return t;
566
+ }, Pe = (e) => Object.fromEntries(wn(e).map((n) => [n, []])), wt = (e, n) => {
567
+ const t = Vn(re(e, n), n.visible);
568
+ return Object.fromEntries(t.map((o, r) => [_e(r), o.map((l) => Q(e, l))]));
569
+ }, yt = (e, n) => {
570
+ const t = X(e);
571
+ return De(Object.keys(n)).map(
572
+ (o) => (n[o] ?? []).flatMap((r) => {
573
+ const l = t.get(r);
574
+ return l === void 0 ? [] : [l];
575
+ })
576
+ );
577
+ }, St = (e) => ({
578
+ switchToCustomDragMode: e.panelSwitchToCustomDrag,
579
+ switchToNormalDragMode: e.panelSwitchToNormalDrag,
580
+ hidePanel: e.panelHide,
581
+ maximizePanel: e.panelMaximize,
582
+ restorePanel: e.panelRestore,
583
+ closePanel: e.panelClose,
584
+ movePanel: e.panelMove,
585
+ movePanelToPreviousColumn: e.panelMovePreviousColumn,
586
+ movePanelToNextColumn: e.panelMoveNextColumn,
587
+ movePanelUp: e.panelMoveUp,
588
+ movePanelDown: e.panelMoveDown,
589
+ customDragModeBadge: e.panelCustomDragBadge,
590
+ panelMoved: e.panelMoved,
591
+ panelMoveUnavailable: e.panelMoveUnavailable,
592
+ panelDragStarted: e.panelDragStarted,
593
+ panelDragCancelled: e.panelDragCancelled,
594
+ hiddenPanels: e.hiddenPanelsTitle,
595
+ hiddenPanelBadge: e.hiddenPanelBadge,
596
+ hiddenPanelNotice: e.hiddenPanelNotice,
597
+ emptyColumn: e.multiColumnEmpty,
598
+ dropZone: e.multiColumnRegion,
599
+ dropHere: e.panelDropHere
600
+ }), xt = "--aqmx-multi-stage-bar-gutter", Et = Object.freeze({ [xt]: `${String(dn)}px` }), Ot = Object.freeze({ blockSize: "100%", paddingInlineEnd: `${String(mn)}px` }), Pt = Object.freeze({ [yn]: "", style: Object.freeze({ display: "flex" }) }), bt = (e) => /* @__PURE__ */ M("div", { ...Pt, children: /* @__PURE__ */ M(ke, { scroller: e, withCircle: !0 }) }), Ct = ({ props: e, children: n }) => /* @__PURE__ */ M(An, { scrollerProps: { ...e, style: Ot }, renderScrollBar: bt, children: n }), Tt = (e) => /* @__PURE__ */ M(ke, { scroller: e, withCircle: !1 }), fe = "--aqmx-stage-block", Nt = "--aqmx-multi-panel-body-floor", Mt = `calc(var(${fe}) * ${String(tn)})`, At = `max(calc(var(${fe}) * ${String(nn)}), calc(var(${ae}) + var(${Nt})))`, kt = (e, n) => {
601
+ const t = Object.entries(e);
602
+ return t.length !== Object.keys(n).length ? !1 : t.every(([o, r]) => {
603
+ const l = n[o];
604
+ return l !== void 0 && l.length === r.length && l.every((a, u) => r[u] === a);
605
+ });
606
+ }, K = (e, n, t, o) => {
607
+ Ie(e);
608
+ const r = e.querySelector(`[${Z}="${n}"]`);
609
+ if (!(r instanceof HTMLElement)) return;
610
+ const l = t !== null && r.contains(t) ? t : null, a = [{ element: r, boundary: r.closest(te) }];
611
+ l !== null && a.push({ element: l, boundary: r }), fn(
612
+ e,
613
+ () => r.isConnected ? (r.scrollIntoView(Le), l?.isConnected !== !0 ? r : (o(l), l)) : null,
614
+ a
615
+ );
616
+ }, ne = (e) => {
617
+ e.scrollIntoView(Le);
618
+ }, We = (e, n) => {
619
+ const t = e.querySelector(`[${ee}="${n}"]`);
620
+ return t instanceof HTMLElement ? (K(e, n, null, ne), t.focus({ preventScroll: !0 }), !0) : !1;
621
+ }, pe = (e, n) => {
622
+ const t = e.querySelector(`[${Z}="${n}"]`);
623
+ return t instanceof HTMLElement && t.contains(e.ownerDocument.activeElement);
624
+ }, be = (e, n) => {
625
+ if (!pe(e, n)) return null;
626
+ const t = [...e.querySelectorAll(`[${ee}]`)].map((a) => a.getAttribute(ee)), o = t.indexOf(n), r = t[o + 1];
627
+ if (o >= 0 && typeof r == "string") return { kind: "panel", panelId: r };
628
+ const l = t[o - 1];
629
+ return o > 0 && typeof l == "string" ? { kind: "panel", panelId: l } : { kind: "stage" };
630
+ }, Ce = (e, n) => {
631
+ requestAnimationFrame(() => {
632
+ const t = e.current;
633
+ t !== null && (n.kind === "panel" && We(t, n.panelId) || t.focus({ preventScroll: !0 }));
634
+ });
635
+ }, Ke = (e, n) => {
636
+ requestAnimationFrame(() => {
637
+ const t = e.current;
638
+ t !== null && We(t, n);
639
+ });
640
+ }, It = (e, n, t) => {
641
+ requestAnimationFrame(() => {
642
+ const o = e.current;
643
+ if (o === null) return;
644
+ const { activeElement: r, body: l } = o.ownerDocument;
645
+ if (K(o, n, t && pe(o, n) ? r : null, ne), !t || r !== null && r !== l && r.isConnected) return;
646
+ const a = o.querySelector(`[${ee}="${n}"]`);
647
+ a instanceof HTMLElement && a.focus({ preventScroll: !0 });
648
+ });
649
+ }, Lt = ({ store: e, stageRef: n }) => {
650
+ const { config: t, labels: o, announcer: r, edits: l } = J(), { maximize: a } = ue(), u = 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)), d = D(() => St(o), [o]), v = R(
651
+ (S) => {
652
+ e.arrange(yt(e.getSnapshot().layout, S));
653
+ },
654
+ [e]
655
+ ), g = Sn({ initialColumnPanels: w, initialPanelVisibility: {}, debugConfig: ve, onColumnPanelsChange: v }), { columnPanels: O, setColumnPanels: C } = g, A = q(E), N = q(O);
656
+ F(() => {
657
+ A.current = E, N.current = O;
658
+ }, [E, O]);
659
+ const c = R(
660
+ (S) => {
661
+ const x = n.current;
662
+ if (x === null) return;
663
+ const { plan: B, stageBlockSize: z } = ot(x, u);
664
+ if (Number.isFinite(z) && z > 0 && x.style.setProperty(fe, `${String(z)}px`), A.current && !S) return;
665
+ const H = en(e.getSnapshot().visibleColumns, B);
666
+ H !== null && e.setVisibleColumns(H);
667
+ },
668
+ [e, n, u]
669
+ );
670
+ F(() => {
671
+ c(!0), k(!0);
672
+ }, [c]), U(() => {
673
+ const S = n.current;
674
+ if (S === null || typeof ResizeObserver > "u") return;
675
+ let x = null;
676
+ const B = new ResizeObserver(() => {
677
+ x === null && (x = requestAnimationFrame(() => {
678
+ x = null, c(!1);
679
+ }));
680
+ }), z = S.querySelector(te)?.firstElementChild, H = S.querySelector(`[${me}]`);
681
+ return z instanceof Element && B.observe(z), H instanceof Element && B.observe(H), () => {
682
+ B.disconnect(), x !== null && cancelAnimationFrame(x);
683
+ };
684
+ }, [n, c]), U(() => {
685
+ E || c(!1);
686
+ }, [E, c]);
687
+ const f = D(() => b ? wt(p, { logical: u, visible: i }) : Pe(i), [b, p, u, i]);
688
+ F(() => {
689
+ kt(N.current, f) || C(f);
690
+ }, [f, C]);
691
+ const m = D(() => De(Object.keys(O)).map((S) => ({ id: S, key: S, className: "aqmx-multi-column" })), [O]), T = D(
692
+ () => p.docs.map((S) => {
693
+ const x = Q(p, S);
694
+ return { id: x, component: vt, title: de(y, S), props: { docPath: S, panelId: x }, minHeight: Mt, maxHeight: At };
695
+ }),
696
+ [p, y]
697
+ ), L = D(() => Object.fromEntries(p.docs.map((S) => [Q(p, S), !p.hidden.has(S)])), [p]), s = p.maximized === null ? null : Q(p, p.maximized), h = R(
698
+ (S) => {
699
+ const { layout: x } = e.getSnapshot();
700
+ for (const [B, z] of X(x)) {
701
+ const H = S[B];
702
+ if (H === void 0 || H !== x.hidden.has(z)) continue;
703
+ const j = e.titleOf(z);
704
+ if (H) {
705
+ if (!e.setHidden(z, !1)) continue;
706
+ r.announce(o.panelShown(j)), Ke(n, B);
707
+ continue;
708
+ }
709
+ const Y = n.current, ge = Y === null ? null : be(Y, B);
710
+ e.setHidden(z, !0) && (r.announce(o.panelHidden(j)), ge !== null && Ce(n, ge));
711
+ }
712
+ },
713
+ [e, n, r, o]
714
+ ), P = R(
715
+ (S) => {
716
+ const x = X(e.getSnapshot().layout).get(S);
717
+ if (x === void 0) return;
718
+ const B = () => {
719
+ const H = e.titleOf(x), j = n.current, Y = j === null ? null : be(j, S);
720
+ e.close(x) && (r.announce(o.panelClosed(H)), Y !== null && Ce(n, Y));
721
+ }, z = l.unsavedAmong([x]);
722
+ z.length === 0 ? B() : l.askToDiscard(z).then((H) => {
723
+ H && B();
724
+ });
725
+ },
726
+ [e, n, r, o, l]
727
+ ), I = R(
728
+ (S) => {
729
+ if (S === null) {
730
+ a(null);
731
+ return;
732
+ }
733
+ const x = X(e.getSnapshot().layout).get(S);
734
+ x !== void 0 && a(x);
735
+ },
736
+ [e, a]
737
+ );
738
+ return /* @__PURE__ */ M("div", { className: "aqmx-multi-layout", "aria-busy": !b, children: /* @__PURE__ */ M(
739
+ xn,
740
+ {
741
+ columns: m,
742
+ panels: T,
743
+ columnPanels: O,
744
+ onColumnPanelsChange: v,
745
+ panelVisibility: L,
746
+ onPanelVisibilityChange: h,
747
+ dragState: g.dragState,
748
+ dragOverPosition: g.dragOverPosition,
749
+ originalPanelPosition: g.originalPanelPosition,
750
+ dragModes: g.dragModes,
751
+ debugConfig: ve,
752
+ panelSizes: g.panelSizes,
753
+ customDrag: g.customDrag,
754
+ setPanelRef: g.setPanelRef,
755
+ onDragStart: g.handleDragStart,
756
+ onDragEnd: g.handleDragEnd,
757
+ onPlaceholderDragEnter: g.handlePlaceholderDragEnter,
758
+ onPlaceholderDragLeave: g.handlePlaceholderDragLeave,
759
+ onDragOverWithInsert: g.handleDragOverWithInsert,
760
+ onDropWithInsert: g.handleDropWithInsert,
761
+ onColumnDragLeave: g.handleColumnDragLeave,
762
+ onPanelMouseDown: g.handleMouseDown,
763
+ onPanelSizeInfoClick: g.handlePanelSizeInfoClick,
764
+ onToggleDragMode: g.toggleDragMode,
765
+ onPanelClose: P,
766
+ onPanelMaximizeChange: I,
767
+ maximizedPanel: s,
768
+ dragHandle: "header",
769
+ labels: d,
770
+ panelClassName: "aqmx-multi-panel",
771
+ renderPanelScrollArea: Ct,
772
+ renderStageScrollBar: Tt
773
+ }
774
+ ) });
775
+ }, se = { blockStart: "--aqmx-multi-toast-block-start", inlineEnd: "--aqmx-multi-toast-inline-end", room: "--aqmx-multi-toast-room" }, Rt = (e, n) => {
776
+ 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];
777
+ return o.some(
778
+ (l) => r.some((a) => {
779
+ const u = n.ownerDocument.elementsFromPoint(l, a), p = u.findIndex((y) => n.contains(y)), i = u.findIndex((y) => e.contains(y));
780
+ return p !== -1 && i !== -1 && i < p;
781
+ })
782
+ );
783
+ }, Dt = (e, n) => {
784
+ const t = n.getBoundingClientRect(), o = n.ownerDocument.documentElement.clientWidth, r = getComputedStyle(n).direction === "rtl";
785
+ 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(), () => {
786
+ e.isConnected && e.hidePopover();
787
+ };
788
+ }, _t = ({ store: e, body: n, limitNotice: t, onLimitNoticeCovered: o, ref: r }) => {
789
+ const { config: l, labels: a, announcer: u, 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(gn), d = R(
790
+ (c) => {
791
+ const { layout: f } = e.getSnapshot(), m = f.maximized, T = c === null && m !== null ? f.panelIds.get(m) : void 0, L = i.current, s = T !== void 0 && L !== null && pe(L, T);
792
+ e.maximize(c) && (c !== null ? u.announce(a.panelMaximized(e.titleOf(c))) : m !== null && u.announce(a.panelRestored(e.titleOf(m))), T !== void 0 && It(i, T, s));
793
+ },
794
+ [e, u, a]
795
+ ), v = R(
796
+ (c, f, m, T) => {
797
+ if (m === f) {
798
+ e.setPendingHash(c, T);
799
+ return;
800
+ }
801
+ const L = p.unsavedAmong([f]);
802
+ if (L.length > 0) {
803
+ p.askToDiscard(L).then((I) => {
804
+ I && v(c, f, m, T);
805
+ });
806
+ return;
807
+ }
808
+ const s = e.navigate(f, m);
809
+ if (s === "navigated") {
810
+ e.setPendingHash(c, T);
811
+ return;
812
+ }
813
+ if (s !== "existing") return;
814
+ const { layout: h } = e.getSnapshot(), P = h.panelIds.get(m);
815
+ P !== void 0 && (u.announce(a.panelAlreadyOpen(e.titleOf(m))), h.maximized === null ? e.setHidden(m, !1) : d(m), e.setPendingHash(P, T), Ke(i, P));
816
+ },
817
+ [e, u, a, d, p]
818
+ );
819
+ F(() => {
820
+ if (t === null || w !== null || !Se()) return;
821
+ const c = y.current, f = i.current;
822
+ if (c === null || f === null) throw new Error("[markdown-explorer] the panel-limit notice and the stage must be mounted together");
823
+ return Dt(c, f);
824
+ }, [t, w]), U(() => {
825
+ const c = y.current;
826
+ if (t === null || c === null) return;
827
+ const { ownerDocument: f } = c;
828
+ let m = null;
829
+ const T = (L) => {
830
+ const s = L.target;
831
+ s instanceof Element && (m !== null && cancelAnimationFrame(m), m = requestAnimationFrame(() => {
832
+ m = null, f.activeElement === s && c.isConnected && Rt(c, s) && o();
833
+ }));
834
+ };
835
+ return f.addEventListener("focusin", T, !0), () => {
836
+ f.removeEventListener("focusin", T, !0), m !== null && cancelAnimationFrame(m);
837
+ };
838
+ }, [t, w, o]), Ze(
839
+ r,
840
+ () => ({
841
+ bringIntoView: (c) => {
842
+ requestAnimationFrame(() => {
843
+ const f = i.current, m = e.getSnapshot().layout.panelIds.get(c);
844
+ f !== null && m !== void 0 && K(f, m, null, ne);
845
+ });
846
+ }
847
+ }),
848
+ [e]
849
+ ), U(() => {
850
+ const c = i.current;
851
+ return () => {
852
+ c !== null && Ie(c);
853
+ };
854
+ }, []);
855
+ const g = R((c, f) => {
856
+ const m = i.current;
857
+ m !== null && K(m, c, f, ne);
858
+ }, []), O = R((c, f, m) => {
859
+ const T = i.current;
860
+ T !== null && K(T, c, m, (L) => pn(f, L));
861
+ }, []), [C] = $(kn), A = D(() => ({ store: e, Body: n, followLink: v, maximize: d, revealInPanel: g, keepAtStartInPanel: O, focusCarry: C }), [e, n, v, d, g, O, C]), N = D(() => Array.from({ length: l.multiView.columns }, (c, f) => _e(f)), [l]);
862
+ return (
863
+ /* @__PURE__ */ ie("section", { ref: i, className: "aqmx-multi-stage", style: Et, tabIndex: -1, "aria-label": a.multiRegion, "aria-busy": b && !E, "data-testid": "markdown-explorer-stage", "data-aqmx-visible-columns": k, ...Ae, children: [
864
+ /* @__PURE__ */ M("span", { className: "aqmx-multi-probe", "aria-hidden": "true", [me]: "" }),
865
+ 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: [
866
+ /* @__PURE__ */ M("span", {}),
867
+ /* @__PURE__ */ M("span", {}),
868
+ /* @__PURE__ */ M("span", {})
869
+ ] }, c)) }) : /* @__PURE__ */ M("div", { className: "aqmx-empty", "data-testid": "markdown-explorer-multi-empty", children: /* @__PURE__ */ M("p", { className: "aqmx-empty-title", children: a.multiEmpty }) }),
870
+ t === null ? null : w !== null ? Mn(
871
+ /* @__PURE__ */ M("div", { ref: y, className: "aqmx-toast aqmx-multi-toast", "data-testid": "markdown-explorer-panel-limit", children: t }),
872
+ w
873
+ ) : (
874
+ /* @__PURE__ */ M("div", { ref: y, popover: Se() ? "manual" : void 0, className: "aqmx-toast aqmx-multi-toast", "data-testid": "markdown-explorer-panel-limit", children: t })
875
+ )
876
+ ] })
877
+ );
878
+ }, zt = 3e3, Ht = (e, n) => {
879
+ if (n !== null) return n;
880
+ const [t] = e;
881
+ return t === void 0 ? null : t;
882
+ }, Te = (e, n, t) => {
883
+ 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);
884
+ return l === void 0 ? null : l;
885
+ }, Bt = (e, n, t) => {
886
+ switch (n) {
887
+ case "opened":
888
+ return e.panelOpened(t);
889
+ case "shown":
890
+ return e.panelShown(t);
891
+ case "closed":
892
+ return e.panelClosed(t);
893
+ default: {
894
+ const o = n;
895
+ throw new RangeError(`[markdown-explorer] unknown toggle outcome ${JSON.stringify(o)}`);
896
+ }
897
+ }
898
+ }, Xt = ({ location: e }) => {
899
+ const { config: n, labels: t, announcer: o } = J(), r = Zn(e), l = _(r, (m) => m.layout.docs), a = _(r, (m) => m.layout.maximized), u = _(r, (m) => m.layout.markup), p = _(r, (m) => m.source), [i, y] = $(() => ({ docs: l, latest: Te([], l, null) }));
900
+ i.docs !== l && y({ docs: l, latest: Te(i.docs, l, i.latest) });
901
+ const E = a !== null ? a : i.latest, [b, k] = $(!1), w = q(null), [d, v] = $(0), g = q(null), O = q(null);
902
+ F(() => {
903
+ const m = g.current;
904
+ g.current = null, m !== null && (r.whenUrlRendered(() => o.announce(m.announcement)), O.current?.bringIntoView(m.doc));
905
+ }), U(
906
+ () => () => {
907
+ w.current !== null && clearTimeout(w.current);
908
+ },
909
+ []
910
+ );
911
+ const C = R(() => {
912
+ w.current !== null && clearTimeout(w.current), k(!0), w.current = setTimeout(() => {
913
+ w.current = null, k(!1);
914
+ }, zt);
915
+ }, []), A = R(() => {
916
+ w.current !== null && clearTimeout(w.current), w.current = null, k(!1);
917
+ }, []), N = R(
918
+ (m) => {
919
+ const T = r.titleOf(m), L = r.toggle(m);
920
+ L === "rejected" && C();
921
+ const s = L === "rejected" ? t.panelLimit(n.multiView.maxPanels) : Bt(t, L, T);
922
+ if (L === "shown") {
923
+ g.current = { doc: m, announcement: s }, v((h) => h + 1);
924
+ return;
925
+ }
926
+ r.whenUrlRendered(() => {
927
+ o.announce(s), L === "opened" && O.current?.bringIntoView(m);
928
+ });
929
+ },
930
+ [r, C, o, t, n]
931
+ ), c = D(() => new Set(l), [l]), f = D(() => {
932
+ const m = Ht(l, a);
933
+ return { href: Me(n, { view: "tree", source: p, doc: m, markup: m !== null && u.has(m) }), target: "tree" };
934
+ }, [n, p, l, a, u]);
935
+ return /* @__PURE__ */ M(
936
+ hn,
937
+ {
938
+ view: "multi",
939
+ explorer: /* @__PURE__ */ M(vn, { mode: "multi", sourceId: p, currentPath: E, openPaths: c, onOpenDocument: N, onSourceChange: r.changeSource, onRevealSource: r.revealSource, viewSwitch: f }),
940
+ content: /* @__PURE__ */ M(_t, { ref: O, store: r, body: nt, limitNotice: b ? t.panelLimit(n.multiView.maxPanels) : null, onLimitNoticeCovered: A }),
941
+ contentCoversPage: a !== null,
942
+ sheetDismissals: d,
943
+ onDraggingChange: r.setSplitDragging
944
+ }
945
+ );
946
+ };
947
+ export {
948
+ Xt as MultiLayout,
949
+ zt as PANEL_LIMIT_NOTICE_MS,
950
+ Te as latestOpenedDocument,
951
+ Ht as treeSwitchDocument
952
+ };