@aiquants/markdown-explorer 0.6.0 → 0.7.1

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