@aiquants/markdown-explorer 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -1
  3. package/dist/{EditSurface-1Jf0CG-f.js → EditSurface-BK_Pz_LF.js} +1 -1
  4. package/dist/{EditSurface-B-l3Do_C.cjs → EditSurface-CfbYYXrc.cjs} +1 -1
  5. package/dist/ExplorerSplit-51frK8xf.cjs +1 -0
  6. package/dist/{ExplorerSplit-D0zf7Cr_.js → ExplorerSplit-DwlWWfRv.js} +216 -213
  7. package/dist/{MultiLayout-Bq10p3a3.cjs → MultiLayout-B4PtS45V.cjs} +1 -1
  8. package/dist/{MultiLayout-Jy9BKofx.js → MultiLayout-CeR_l6Rb.js} +4 -4
  9. package/dist/{NativeScrollBar-CyiyL47o.js → NativeScrollBar-CVWeTlHC.js} +1 -1
  10. package/dist/{NativeScrollBar-Dt6xH5Mb.cjs → NativeScrollBar-Dp4YWBp7.cjs} +1 -1
  11. package/dist/{TreeLayout-kVWFEKJD.cjs → TreeLayout-D-NyhuVM.cjs} +1 -1
  12. package/dist/{TreeLayout-8pRo1ANN.js → TreeLayout-min5AOhr.js} +3 -3
  13. package/dist/core/contracts.d.cts +1 -0
  14. package/dist/core/contracts.d.ts +1 -0
  15. package/dist/core/labels.d.cts +2 -0
  16. package/dist/core/labels.d.ts +2 -0
  17. package/dist/core/treeSettings.d.cts +2 -1
  18. package/dist/core/treeSettings.d.ts +2 -1
  19. package/dist/dataRoute-CIFFX5bd.cjs +1 -0
  20. package/dist/{dataRoute-Csl1WBDz.js → dataRoute-CU9CKP44.js} +54 -54
  21. package/dist/{index-CfcJEnrC.js → index-BPj19kIo.js} +10 -6
  22. package/dist/{index-sNJrKoGN.cjs → index-DJ_FUtYM.cjs} +4 -4
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +3 -3
  25. package/dist/{location-Dc1qNEGm.js → location-BT23fKeh.js} +123 -112
  26. package/dist/location-LNl0QOXI.cjs +1 -0
  27. package/dist/{merge-D0aGvFKC.cjs → merge-AnqxGn__.cjs} +1 -1
  28. package/dist/{merge-SRCxtHk2.js → merge-hyUGPGbJ.js} +1 -1
  29. package/dist/sanitizeWorker.cjs +1 -1
  30. package/dist/sanitizeWorker.js +1 -1
  31. package/dist/server.cjs +1 -1
  32. package/dist/server.js +548 -540
  33. package/docs/behavior/dom-hooks.md +1 -1
  34. package/docs/behavior/localization.md +1 -0
  35. package/package.json +1 -1
  36. package/dist/ExplorerSplit-WX8afxrQ.cjs +0 -1
  37. package/dist/dataRoute-8pyILcjL.cjs +0 -1
  38. package/dist/location-CRYkEWiC.cjs +0 -1
package/dist/server.js CHANGED
@@ -1,21 +1,21 @@
1
- import { b as Et, c as er, f as Te, d as tr, g as rr, h as nr, j as or, E as bt, k as he, r as sr, l as ir, i as q, m as ar, n as cr, o as ur, p as Tt, q as dr, s as lr, t as Me, u as fr, v as mr, w as pr, x as ie, y as Q, e as He, z as wr, A as hr } from "./dataRoute-Csl1WBDz.js";
2
- import { D as rs, M as ns, B as os } from "./dataRoute-Csl1WBDz.js";
3
- import { createHash as yr, createHmac as gr } from "node:crypto";
4
- import { createLinkCardHandler as Er } from "@aiquants/markdown/server";
5
- import { crossOriginRefusal as kt, NO_CROSS_ORIGIN_NAVIGATION as St } from "@aiquants/request-isolation";
6
- import { data as Fe, redirect as br } from "react-router";
7
- import { w as Tr, d as kr, r as Sr, i as xr, a as Or, p as Rr, b as vr, f as _r, N as Nr } from "./location-Dc1qNEGm.js";
8
- import { existsSync as Ar, statSync as Ir, realpathSync as Pr, constants as fe } from "node:fs";
9
- import { extname as Mr, isAbsolute as Ue, relative as Xe, sep as Je, join as $r, resolve as Lr } from "node:path";
10
- import { fileURLToPath as xe } from "node:url";
11
- import { Worker as jr } from "node:worker_threads";
12
- import { open as xt, lstat as zr, realpath as Dr, readdir as Cr } from "node:fs/promises";
13
- import { Readable as Br } from "node:stream";
14
- const Ge = Object.freeze({ kind: "anonymous" }), Zo = Object.freeze({
15
- authenticate: async () => ({ status: "signed-in", principal: Ge }),
16
- principalKey: () => Ge.kind,
1
+ import { b as Tt, c as nr, f as ke, d as or, g as sr, h as ir, j as ar, E as kt, k as he, r as cr, l as ur, i as q, m as dr, n as lr, o as fr, p as St, q as mr, s as pr, t as $e, u as wr, v as hr, w as yr, x as ae, y as Q, e as Fe, z as gr, A as Er } from "./dataRoute-CU9CKP44.js";
2
+ import { D as ns, M as os, B as ss } from "./dataRoute-CU9CKP44.js";
3
+ import { createHash as br, createHmac as Tr } from "node:crypto";
4
+ import { createLinkCardHandler as kr } from "@aiquants/markdown/server";
5
+ import { crossOriginRefusal as xt, NO_CROSS_ORIGIN_NAVIGATION as Ot } from "@aiquants/request-isolation";
6
+ import { data as Ue, redirect as Sr } from "react-router";
7
+ import { w as xr, d as Or, r as Rr, i as vr, a as _r, p as Ar, b as Nr, f as Ir, N as Pr } from "./location-BT23fKeh.js";
8
+ import { existsSync as Mr, statSync as $r, realpathSync as Lr, constants as me } from "node:fs";
9
+ import { extname as jr, isAbsolute as Xe, relative as Je, sep as Ge, join as Ye, resolve as zr } from "node:path";
10
+ import { fileURLToPath as Oe } from "node:url";
11
+ import { Worker as Dr } from "node:worker_threads";
12
+ import { open as Rt, lstat as vt, realpath as Cr, readdir as Br } from "node:fs/promises";
13
+ import { Readable as Hr } from "node:stream";
14
+ const We = Object.freeze({ kind: "anonymous" }), Qo = Object.freeze({
15
+ authenticate: async () => ({ status: "signed-in", principal: We }),
16
+ principalKey: () => We.kind,
17
17
  signedOutPage: (e, t) => new Response(null, { status: 401, headers: t })
18
- }), Hr = "application/octet-stream", Ot = "application/pdf", Fr = /* @__PURE__ */ new Set([
18
+ }), Fr = "application/octet-stream", _t = "application/pdf", Ur = /* @__PURE__ */ new Set([
19
19
  "image/png",
20
20
  "image/apng",
21
21
  "image/jpeg",
@@ -41,8 +41,8 @@ const Ge = Object.freeze({ kind: "anonymous" }), Zo = Object.freeze({
41
41
  "video/webm",
42
42
  "video/ogg",
43
43
  "video/quicktime",
44
- Ot
45
- ]), Rt = "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'", vt = `${Rt}; sandbox`, Ur = `${Rt}; sandbox allow-same-origin`, Ye = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u, Xr = /^[\t\n\r ]+|[\t\n\r ]+$/gu, Ie = /^[\t ]+|[\t ]+$/gu, Jr = (e) => {
44
+ _t
45
+ ]), At = "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'", Nt = `${At}; sandbox`, Xr = `${At}; sandbox allow-same-origin`, Ke = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u, Jr = /^[\t\n\r ]+|[\t\n\r ]+$/gu, Pe = /^[\t ]+|[\t ]+$/gu, Gr = (e) => {
46
46
  const t = [];
47
47
  let r = "", n = 0;
48
48
  for (; ; ) {
@@ -54,74 +54,74 @@ const Ge = Object.freeze({ kind: "anonymous" }), Zo = Object.freeze({
54
54
  n += e[n] === "\\" ? 2 : 1;
55
55
  if (n = Math.min(n + 1, e.length), r += e.slice(a, n), n < e.length) continue;
56
56
  }
57
- if (t.push(r.replace(Ie, "")), r = "", n >= e.length) return t;
57
+ if (t.push(r.replace(Pe, "")), r = "", n >= e.length) return t;
58
58
  n += 1;
59
59
  }
60
- }, Gr = (e) => {
61
- const t = e.replace(Xr, ""), r = t.indexOf("/");
60
+ }, Yr = (e) => {
61
+ const t = e.replace(Jr, ""), r = t.indexOf("/");
62
62
  if (r < 0) return null;
63
63
  const n = t.slice(0, r), a = t.indexOf(";", r + 1), i = t.slice(r + 1, a < 0 ? t.length : a).replace(/[\t\n\r ]+$/u, "");
64
- return Ye.test(n) && Ye.test(i) ? `${n}/${i}`.toLowerCase() : null;
65
- }, Yr = (e) => {
64
+ return Ke.test(n) && Ke.test(i) ? `${n}/${i}`.toLowerCase() : null;
65
+ }, Wr = (e) => {
66
66
  let t = null;
67
- for (const r of Jr(e)) {
68
- const n = Gr(r);
67
+ for (const r of Gr(e)) {
68
+ const n = Yr(r);
69
69
  n !== null && n !== "*/*" && (t = n);
70
70
  }
71
71
  return t;
72
- }, Wr = /['()*]/gu, _t = (e) => encodeURIComponent(e).replace(Wr, (t) => `%${t.charCodeAt(0).toString(16).toUpperCase()}`), Kr = Object.freeze({
72
+ }, Kr = /['()*]/gu, It = (e) => encodeURIComponent(e).replace(Kr, (t) => `%${t.charCodeAt(0).toString(16).toUpperCase()}`), Vr = Object.freeze({
73
73
  "Cache-Control": "private, max-age=60, stale-while-revalidate=600, no-transform",
74
74
  Vary: "Cookie"
75
- }), Vr = (e, t) => {
76
- const r = Yr(e), n = r !== null && Fr.has(r), a = n && (r.startsWith("audio/") || r.startsWith("video/"));
75
+ }), Zr = (e, t) => {
76
+ const r = Wr(e), n = r !== null && Ur.has(r), a = n && (r.startsWith("audio/") || r.startsWith("video/"));
77
77
  return {
78
- contentType: r === null ? Hr : r,
78
+ contentType: r === null ? Fr : r,
79
79
  inline: n,
80
80
  headers: {
81
81
  "X-Content-Type-Options": "nosniff",
82
- "Content-Disposition": `${n ? "inline" : "attachment"}; filename*=UTF-8''${_t(t)}`,
83
- ...r === Ot ? {} : { "Content-Security-Policy": a ? Ur : vt },
82
+ "Content-Disposition": `${n ? "inline" : "attachment"}; filename*=UTF-8''${It(t)}`,
83
+ ...r === _t ? {} : { "Content-Security-Policy": a ? Xr : Nt },
84
84
  "Cross-Origin-Resource-Policy": "same-origin"
85
85
  }
86
86
  };
87
- }, Zr = "text/plain; charset=utf-8", Qr = (e) => ({
88
- contentType: Zr,
87
+ }, Qr = "text/plain; charset=utf-8", qr = (e) => ({
88
+ contentType: Qr,
89
89
  inline: !0,
90
90
  headers: {
91
91
  "X-Content-Type-Options": "nosniff",
92
- "Content-Disposition": `inline; filename*=UTF-8''${_t(e)}`,
93
- "Content-Security-Policy": vt,
92
+ "Content-Disposition": `inline; filename*=UTF-8''${It(e)}`,
93
+ "Content-Security-Policy": Nt,
94
94
  "Cross-Origin-Resource-Policy": "same-origin"
95
95
  }
96
- }), qr = /^bytes=(?:(\d+)-(\d*)|-(\d+))$/iu, ye = Object.freeze({ kind: "whole" }), We = Object.freeze({ kind: "unsatisfiable" }), en = (e, t, r) => {
96
+ }), en = /^bytes=(?:(\d+)-(\d*)|-(\d+))$/iu, ge = Object.freeze({ kind: "whole" }), Ve = Object.freeze({ kind: "unsatisfiable" }), tn = (e, t, r) => {
97
97
  const n = e.get("Range");
98
- if (n === null) return ye;
98
+ if (n === null) return ge;
99
99
  const a = e.get("If-Range");
100
- if (a !== null && a !== r) return ye;
101
- const i = qr.exec(n);
102
- if (i === null) return ye;
100
+ if (a !== null && a !== r) return ge;
101
+ const i = en.exec(n);
102
+ if (i === null) return ge;
103
103
  const [, c, m, h] = i;
104
104
  if (h !== void 0) {
105
105
  const y = Number(h);
106
- if (y === 0) return We;
107
- const T = Math.max(0, t - y);
108
- return { kind: "partial", range: { offset: T, length: t - T } };
106
+ if (y === 0) return Ve;
107
+ const k = Math.max(0, t - y);
108
+ return { kind: "partial", range: { offset: k, length: t - k } };
109
109
  }
110
110
  const S = Number(c), w = m === "" ? Number.POSITIVE_INFINITY : Number(m);
111
- return w < S ? ye : S >= t ? We : { kind: "partial", range: { offset: S, length: Math.min(w, t - 1) - S + 1 } };
112
- }, Ke = "W/", tn = (e) => {
111
+ return w < S ? ge : S >= t ? Ve : { kind: "partial", range: { offset: S, length: Math.min(w, t - 1) - S + 1 } };
112
+ }, Ze = "W/", rn = (e) => {
113
113
  const t = [];
114
114
  let r = 0, n = !1;
115
115
  for (let a = 0; a < e.length; a += 1)
116
- e[a] === '"' ? n = !n : e[a] === "," && !n && (t.push(e.slice(r, a).replace(Ie, "")), r = a + 1);
117
- return t.push(e.slice(r).replace(Ie, "")), t;
118
- }, Ve = (e) => e.startsWith(Ke) ? e.slice(Ke.length) : e, rn = (e, t) => {
116
+ e[a] === '"' ? n = !n : e[a] === "," && !n && (t.push(e.slice(r, a).replace(Pe, "")), r = a + 1);
117
+ return t.push(e.slice(r).replace(Pe, "")), t;
118
+ }, Qe = (e) => e.startsWith(Ze) ? e.slice(Ze.length) : e, nn = (e, t) => {
119
119
  if (e === null) return !1;
120
- const r = tn(e);
120
+ const r = rn(e);
121
121
  if (r.length === 1 && r[0] === "*") return !0;
122
- const n = Ve(t);
123
- return r.some((a) => Ve(a) === n);
124
- }, nn = (e, t) => {
122
+ const n = Qe(t);
123
+ return r.some((a) => Qe(a) === n);
124
+ }, on = (e, t) => {
125
125
  let r = t;
126
126
  return e.pipeThrough(
127
127
  new TransformStream({
@@ -134,28 +134,28 @@ const Ge = Object.freeze({ kind: "anonymous" }), Zo = Object.freeze({
134
134
  }
135
135
  })
136
136
  );
137
- }, Oe = async (e, t, r, n, a) => {
137
+ }, Re = async (e, t, r, n, a) => {
138
138
  if (n !== null && r.set("Content-Length", String(n)), e.method.toUpperCase() === "HEAD") return new Response(null, { status: t, headers: r });
139
139
  const i = await a();
140
- return new Response(n === null ? i : nn(i, n), { status: t, headers: r });
141
- }, on = (e, t) => {
140
+ return new Response(n === null ? i : on(i, n), { status: t, headers: r });
141
+ }, sn = (e, t) => {
142
142
  const r = new Headers(e);
143
143
  for (const [n, a] of Object.entries({ "Accept-Ranges": "bytes", "Content-Range": `bytes */${t}`, "Cache-Control": "private, no-store", "X-Content-Type-Options": "nosniff" })) r.set(n, a);
144
144
  return new Response(null, { status: 416, headers: r });
145
- }, sn = async (e, t, r, n) => {
146
- const a = `"${t.version}"`, i = n === "text" ? Qr(t.name) : Vr(t.contentType, t.name), c = new Headers(r);
147
- for (const [S, w] of Object.entries({ ...i.headers, ...Kr, ETag: a })) c.set(S, w);
148
- if (rn(e.headers.get("If-None-Match"), a)) return new Response(null, { status: 304, headers: c });
149
- if (c.set("Content-Type", i.contentType), t.size === null) return Oe(e, 200, c, null, () => t.open(null));
145
+ }, an = async (e, t, r, n) => {
146
+ const a = `"${t.version}"`, i = n === "text" ? qr(t.name) : Zr(t.contentType, t.name), c = new Headers(r);
147
+ for (const [S, w] of Object.entries({ ...i.headers, ...Vr, ETag: a })) c.set(S, w);
148
+ if (nn(e.headers.get("If-None-Match"), a)) return new Response(null, { status: 304, headers: c });
149
+ if (c.set("Content-Type", i.contentType), t.size === null) return Re(e, 200, c, null, () => t.open(null));
150
150
  if (t.size === 0)
151
151
  return c.set("Content-Length", "0"), new Response(null, { status: 200, headers: c });
152
152
  c.set("Accept-Ranges", "bytes");
153
- const m = en(e.headers, t.size, a);
154
- if (m.kind === "unsatisfiable") return on(r, t.size);
155
- if (m.kind === "whole") return Oe(e, 200, c, t.size, () => t.open(null));
153
+ const m = tn(e.headers, t.size, a);
154
+ if (m.kind === "unsatisfiable") return sn(r, t.size);
155
+ if (m.kind === "whole") return Re(e, 200, c, t.size, () => t.open(null));
156
156
  const { range: h } = m;
157
- return c.set("Content-Range", `bytes ${h.offset}-${h.offset + h.length - 1}/${t.size}`), Oe(e, 206, c, h.length, () => t.open(h));
158
- }, Re = (e, t) => {
157
+ return c.set("Content-Range", `bytes ${h.offset}-${h.offset + h.length - 1}/${t.size}`), Re(e, 206, c, h.length, () => t.open(h));
158
+ }, ve = (e, t) => {
159
159
  const r = new AbortController(), n = t(AbortSignal.any([e.signal, r.signal]));
160
160
  return new Promise((a) => {
161
161
  let i;
@@ -173,29 +173,29 @@ const Ge = Object.freeze({ kind: "anonymous" }), Zo = Object.freeze({
173
173
  }
174
174
  );
175
175
  });
176
- }, an = Object.freeze({
176
+ }, cn = Object.freeze({
177
177
  error: (e, t) => {
178
178
  console.error(e, t);
179
179
  }
180
- }), Nt = /* @__PURE__ */ Symbol.for("@aiquants/markdown-explorer:ExplorerError");
181
- class ke extends Error {
180
+ }), Pt = /* @__PURE__ */ Symbol.for("@aiquants/markdown-explorer:ExplorerError");
181
+ class Se extends Error {
182
182
  reason;
183
183
  code;
184
184
  constructor(t, r = {}) {
185
- if (!Et(t)) throw new RangeError(`[markdown-explorer] ExplorerError needs a failure reason; got ${JSON.stringify(t)}`);
186
- if (r.code !== void 0 && !er(r.code)) throw new RangeError(`[markdown-explorer] an ExplorerError code must be 1 to 64 lowercase letters, digits or hyphens; got ${JSON.stringify(r.code)}`);
187
- super(`[markdown-explorer] ${t}`, r.cause === void 0 ? void 0 : { cause: r.cause }), this.name = "ExplorerError", this.reason = t, this.code = r.code, Object.defineProperty(this, Nt, { value: !0 });
185
+ if (!Tt(t)) throw new RangeError(`[markdown-explorer] ExplorerError needs a failure reason; got ${JSON.stringify(t)}`);
186
+ if (r.code !== void 0 && !nr(r.code)) throw new RangeError(`[markdown-explorer] an ExplorerError code must be 1 to 64 lowercase letters, digits or hyphens; got ${JSON.stringify(r.code)}`);
187
+ super(`[markdown-explorer] ${t}`, r.cause === void 0 ? void 0 : { cause: r.cause }), this.name = "ExplorerError", this.reason = t, this.code = r.code, Object.defineProperty(this, Pt, { value: !0 });
188
188
  }
189
189
  }
190
- const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un = (e) => typeof e == "object" && e !== null && e.name === "AbortError", $e = (e, t, r) => {
190
+ const un = (e) => e instanceof Error && Object.hasOwn(e, Pt) && Tt(e.reason), dn = (e) => typeof e == "object" && e !== null && e.name === "AbortError", Le = (e, t, r) => {
191
191
  try {
192
192
  e.error(t, r);
193
193
  } catch (n) {
194
194
  console.error("[markdown-explorer] the logger threw while reporting a failure", { operation: r.operation, error: n });
195
195
  }
196
- }, oe = (e, t) => $e(e, `[markdown-explorer] ${t.operation} failed`, t), dn = (e, t) => $e(e, `[markdown-explorer] ${t.operation} left out an entry`, t), ve = (e, t) => $e(e, `[markdown-explorer] ${t.operation} refused a path the deny rules match`, { ...t, error: new RangeError("[markdown-explorer] the path matches a deny rule") }), Ze = (e, t) => {
196
+ }, oe = (e, t) => Le(e, `[markdown-explorer] ${t.operation} failed`, t), ln = (e, t) => Le(e, `[markdown-explorer] ${t.operation} left out an entry`, t), _e = (e, t) => Le(e, `[markdown-explorer] ${t.operation} refused a path the deny rules match`, { ...t, error: new RangeError("[markdown-explorer] the path matches a deny rule") }), qe = (e, t) => {
197
197
  e === null || typeof e != "object" && typeof e != "function" || Promise.resolve(e).then(void 0, t);
198
- }, G = (e, t, r, n) => cn(e) ? Te(e.reason, e.code) : (un(e) || r.aborted || oe(n, { ...t, error: e }), { reason: "failed" }), Qe = 2 * 1024 * 1024, qe = 256 * 1024 * 1024, ln = async (e, t) => {
198
+ }, G = (e, t, r, n) => un(e) ? ke(e.reason, e.code) : (dn(e) || r.aborted || oe(n, { ...t, error: e }), { reason: "failed" }), et = 2 * 1024 * 1024, tt = 256 * 1024 * 1024, fn = async (e, t) => {
199
199
  const r = e.getReader(), n = new Uint8Array(t);
200
200
  let a = 0;
201
201
  for (; a < t; ) {
@@ -206,16 +206,16 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
206
206
  }
207
207
  return r.cancel().catch(() => {
208
208
  }), n;
209
- }, fn = async (e, t) => {
209
+ }, mn = async (e, t) => {
210
210
  if (e.size === 0) return { text: "", truncated: !1 };
211
- const r = e.size !== null && e.size > t, n = e.size === null ? t + 1 : Math.min(e.size, t), a = await ln(await e.open(r ? { offset: 0, length: t } : null), n);
211
+ const r = e.size !== null && e.size > t, n = e.size === null ? t + 1 : Math.min(e.size, t), a = await fn(await e.open(r ? { offset: 0, length: t } : null), n);
212
212
  if (e.size !== null && a.byteLength < n) throw new RangeError("[markdown-explorer] the file ended before the length its asset port reported");
213
213
  const i = r || a.byteLength > t, c = i ? a.subarray(0, t) : a;
214
214
  return c.includes(0) ? null : { text: new TextDecoder("utf-8").decode(c, { stream: i }), truncated: i };
215
- }, et = (e, t) => {
215
+ }, rt = (e, t) => {
216
216
  if (!Number.isSafeInteger(t) || t <= 0) throw new RangeError(`[markdown-explorer] a cache ${e} must be a positive integer; got ${String(t)}`);
217
- }, At = (e, t) => {
218
- et("capacity", e), t !== void 0 && et("weight budget", t.max);
217
+ }, Mt = (e, t) => {
218
+ rt("capacity", e), t !== void 0 && rt("weight budget", t.max);
219
219
  const r = /* @__PURE__ */ new Map();
220
220
  let n = 0;
221
221
  const a = (i) => {
@@ -243,244 +243,244 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
243
243
  size: () => r.size,
244
244
  weight: () => n
245
245
  };
246
- }, It = (e) => Math.max(1, e - 1), mn = 2147483647, tt = Object.freeze({ status: "aborted" }), ce = (e, t, r) => {
246
+ }, $t = (e) => Math.max(1, e - 1), pn = 2147483647, nt = Object.freeze({ status: "aborted" }), ue = (e, t, r) => {
247
247
  const n = (e.get(t) ?? 0) + r;
248
248
  n === 0 ? e.delete(t) : e.set(t, n);
249
- }, de = (e, t, r) => {
249
+ }, le = (e, t, r) => {
250
250
  if (!Number.isSafeInteger(t) || t <= 0 || t > r) throw new RangeError(`[markdown-explorer] a worker pool's ${e} must be an integer in 1..${String(r)}; got ${String(t)}`);
251
- }, pn = (e) => e !== null && typeof e == "object" && e.ready === !0 && !("id" in e), wn = (e, t) => e !== null && typeof e == "object" && e.id === t && "output" in e, hn = ({ url: e, size: t, deadlineMs: r, jobsPerScope: n, maxQueuedJobs: a, heapLimits: i }) => {
252
- de("size", t, Number.MAX_SAFE_INTEGER), de("deadline", r, mn), de("jobsPerScope", n, Number.MAX_SAFE_INTEGER), de("maxQueuedJobs", a, Number.MAX_SAFE_INTEGER), de("maxOldGenerationSizeMb", i.maxOldGenerationSizeMb, Number.MAX_SAFE_INTEGER), de("maxYoungGenerationSizeMb", i.maxYoungGenerationSizeMb, Number.MAX_SAFE_INTEGER);
253
- const c = Object.freeze({ maxOldGenerationSizeMb: i.maxOldGenerationSizeMb, maxYoungGenerationSizeMb: i.maxYoungGenerationSizeMb }), m = /* @__PURE__ */ new Set(), h = [], S = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), y = It(t);
254
- let T = 0;
251
+ }, wn = (e) => e !== null && typeof e == "object" && e.ready === !0 && !("id" in e), hn = (e, t) => e !== null && typeof e == "object" && e.id === t && "output" in e, yn = ({ url: e, size: t, deadlineMs: r, jobsPerScope: n, maxQueuedJobs: a, heapLimits: i }) => {
252
+ le("size", t, Number.MAX_SAFE_INTEGER), le("deadline", r, pn), le("jobsPerScope", n, Number.MAX_SAFE_INTEGER), le("maxQueuedJobs", a, Number.MAX_SAFE_INTEGER), le("maxOldGenerationSizeMb", i.maxOldGenerationSizeMb, Number.MAX_SAFE_INTEGER), le("maxYoungGenerationSizeMb", i.maxYoungGenerationSizeMb, Number.MAX_SAFE_INTEGER);
253
+ const c = Object.freeze({ maxOldGenerationSizeMb: i.maxOldGenerationSizeMb, maxYoungGenerationSizeMb: i.maxYoungGenerationSizeMb }), m = /* @__PURE__ */ new Set(), h = [], S = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), y = $t(t);
254
+ let k = 0;
255
255
  const v = (p, g) => {
256
256
  const { job: E } = p;
257
- p.timer !== null && clearTimeout(p.timer), p.timer = null, p.job = null, p.sent = !1, E !== null && (ce(S, E.scope, -1), ce(w, E.scope, -1), E.settle(g));
258
- }, $ = (p) => {
257
+ p.timer !== null && clearTimeout(p.timer), p.timer = null, p.job = null, p.sent = !1, E !== null && (ue(S, E.scope, -1), ue(w, E.scope, -1), E.settle(g));
258
+ }, L = (p) => {
259
259
  const [g] = h.splice(p, 1);
260
260
  g?.detach();
261
- }, N = () => {
261
+ }, A = () => {
262
262
  let p = -1, g = y, E = Number.POSITIVE_INFINITY;
263
- for (const [R, k] of h.entries()) {
264
- const A = S.get(k.scope) ?? 0, M = w.get(k.scope) ?? 0;
265
- (A < g || A === g && p >= 0 && M < E) && (p = R, g = A, E = M);
263
+ for (const [O, T] of h.entries()) {
264
+ const N = S.get(T.scope) ?? 0, M = w.get(T.scope) ?? 0;
265
+ (N < g || N === g && p >= 0 && M < E) && (p = O, g = N, E = M);
266
266
  }
267
267
  return p;
268
- }, _ = (p, g) => {
268
+ }, R = (p, g) => {
269
269
  m.has(p) && (m.delete(p), v(p, g), p.worker.terminate().catch(() => {
270
270
  }), H());
271
271
  }, z = (p) => {
272
272
  p.timer = setTimeout(() => {
273
- _(p, { status: "timeout" });
273
+ R(p, { status: "timeout" });
274
274
  }, r);
275
- }, O = (p, g) => p.sent ? { status: "crashed", error: g } : { status: "unavailable", error: g }, P = (p, g) => {
275
+ }, _ = (p, g) => p.sent ? { status: "crashed", error: g } : { status: "unavailable", error: g }, I = (p, g) => {
276
276
  p.sent = !0, z(p);
277
277
  try {
278
278
  p.worker.postMessage({ id: g.id, input: g.input });
279
279
  } catch (E) {
280
280
  v(p, { status: "crashed", error: E }), p.worker.unref();
281
281
  }
282
- }, B = () => {
283
- const p = { worker: new jr(e, { resourceLimits: c }), job: null, sent: !1, timer: null, ready: !1 };
282
+ }, D = () => {
283
+ const p = { worker: new Dr(e, { resourceLimits: c }), job: null, sent: !1, timer: null, ready: !1 };
284
284
  return p.worker.unref(), p.timer = setTimeout(() => {
285
- _(p, { status: "unavailable", error: new Error(`[markdown-explorer] a worker did not start within ${String(r)} ms`) });
285
+ R(p, { status: "unavailable", error: new Error(`[markdown-explorer] a worker did not start within ${String(r)} ms`) });
286
286
  }, r), p.worker.on("message", (g) => {
287
- if (!p.ready && pn(g)) {
288
- p.ready = !0, p.timer !== null && clearTimeout(p.timer), p.timer = null, p.job === null ? p.worker.unref() : P(p, p.job), p.job === null && H();
287
+ if (!p.ready && wn(g)) {
288
+ p.ready = !0, p.timer !== null && clearTimeout(p.timer), p.timer = null, p.job === null ? p.worker.unref() : I(p, p.job), p.job === null && H();
289
289
  return;
290
290
  }
291
291
  const { job: E } = p;
292
- if (E === null || !wn(g, E.id)) {
293
- _(p, O(p, new Error("[markdown-explorer] a worker sent a message that answers no job")));
292
+ if (E === null || !hn(g, E.id)) {
293
+ R(p, _(p, new Error("[markdown-explorer] a worker sent a message that answers no job")));
294
294
  return;
295
295
  }
296
296
  v(p, { status: "done", output: g.output }), p.worker.unref(), H();
297
297
  }), p.worker.on("error", (g) => {
298
- _(p, O(p, g));
298
+ R(p, _(p, g));
299
299
  }), p.worker.on("messageerror", (g) => {
300
- _(p, O(p, g));
300
+ R(p, _(p, g));
301
301
  }), p.worker.on("exit", (g) => {
302
- _(p, O(p, new Error(`[markdown-explorer] a worker exited with code ${String(g)}`)));
302
+ R(p, _(p, new Error(`[markdown-explorer] a worker exited with code ${String(g)}`)));
303
303
  }), m.add(p), p;
304
304
  }, H = () => {
305
305
  for (; ; ) {
306
- const p = N(), g = h[p];
306
+ const p = A(), g = h[p];
307
307
  if (g === void 0) return;
308
308
  let E;
309
- for (const k of m)
310
- if (k.job === null) {
311
- E = k;
309
+ for (const T of m)
310
+ if (T.job === null) {
311
+ E = T;
312
312
  break;
313
313
  }
314
314
  if (E === void 0 && m.size < t)
315
315
  try {
316
- E = B();
317
- } catch (k) {
318
- $(p), ce(w, g.scope, -1), g.settle({ status: "unavailable", error: k });
316
+ E = D();
317
+ } catch (T) {
318
+ L(p), ue(w, g.scope, -1), g.settle({ status: "unavailable", error: T });
319
319
  continue;
320
320
  }
321
321
  if (E === void 0) return;
322
- $(p), ce(S, g.scope, 1);
323
- const R = E;
324
- R.job = g, R.worker.ref(), R.ready && P(R, g);
322
+ L(p), ue(S, g.scope, 1);
323
+ const O = E;
324
+ O.job = g, O.worker.ref(), O.ready && I(O, g);
325
325
  }
326
326
  };
327
327
  return {
328
- run: (p, { scope: g, signal: E }) => new Promise((R) => {
328
+ run: (p, { scope: g, signal: E }) => new Promise((O) => {
329
329
  if (E.aborted) {
330
- R(tt);
330
+ O(nt);
331
331
  return;
332
332
  }
333
333
  if ((w.get(g) ?? 0) >= n) {
334
- R({ status: "refused", limit: "scope" });
334
+ O({ status: "refused", limit: "scope" });
335
335
  return;
336
336
  }
337
- T += 1;
338
- const k = { id: T, input: p, scope: g, settle: R, detach: () => {
337
+ k += 1;
338
+ const T = { id: k, input: p, scope: g, settle: O, detach: () => {
339
339
  } };
340
- h.push(k), ce(w, g, 1), H();
341
- const A = h.indexOf(k);
342
- if (A < 0) return;
340
+ h.push(T), ue(w, g, 1), H();
341
+ const N = h.indexOf(T);
342
+ if (N < 0) return;
343
343
  if (h.length > a) {
344
- $(A), ce(w, g, -1), R({ status: "refused", limit: "queue" });
344
+ L(N), ue(w, g, -1), O({ status: "refused", limit: "queue" });
345
345
  return;
346
346
  }
347
347
  const M = () => {
348
- const U = h.indexOf(k);
349
- U < 0 || ($(U), ce(w, g, -1), R(tt));
348
+ const U = h.indexOf(T);
349
+ U < 0 || (L(U), ue(w, g, -1), O(nt));
350
350
  };
351
- E.addEventListener("abort", M, { once: !0 }), k.detach = () => {
351
+ E.addEventListener("abort", M, { once: !0 }), T.detach = () => {
352
352
  E.removeEventListener("abort", M);
353
353
  };
354
354
  }),
355
355
  workers: () => m.size
356
356
  };
357
- }, Le = 1024 * 1024, yn = 3e4, gn = 4 * Le, En = 64 * Le, bn = 3, Tn = 2, kn = (e, t) => e + It(t) + bn, Sn = 4, xn = 32, On = 512, Rn = 64, vn = 4096, _n = 32, rt = 4096, Nn = 4, Pt = ({ workerHeapMb: e, maxHtmlBytes: t }) => Math.floor(((e - Rn) * Le - t * _n) / vn), An = ({ maxHtmlBytes: e }) => e, In = ({ maxHtmlBytes: e }) => Nn * e, Pn = 1024, Mn = 2147483647, $n = 64, Ln = 2 ** 29, jn = 1024 * 1024, zn = 64, nt = Object.freeze({ status: "rejected", reason: "too-large", cause: null }), _e = Object.freeze({ status: "rejected", reason: "failed", cause: null }), ue = (e, t, r, n) => {
357
+ }, je = 1024 * 1024, gn = 3e4, En = 4 * je, bn = 64 * je, Tn = 3, kn = 2, Sn = (e, t) => e + $t(t) + Tn, xn = 4, On = 32, Rn = 512, vn = 64, _n = 4096, An = 32, ot = 4096, Nn = 4, Lt = ({ workerHeapMb: e, maxHtmlBytes: t }) => Math.floor(((e - vn) * je - t * An) / _n), In = ({ maxHtmlBytes: e }) => e, Pn = ({ maxHtmlBytes: e }) => Nn * e, Mn = 1024, $n = 2147483647, Ln = 64, jn = 2 ** 29, zn = 1024 * 1024, Dn = 64, st = Object.freeze({ status: "rejected", reason: "too-large", cause: null }), Ae = Object.freeze({ status: "rejected", reason: "failed", cause: null }), de = (e, t, r, n) => {
358
358
  if (t === void 0) return r;
359
359
  if (typeof t != "number") throw new TypeError(`[markdown-explorer] sanitizer.${e} must be a number; got ${typeof t}`);
360
360
  if (!Number.isSafeInteger(t) || t <= 0 || t > n) throw new RangeError(`[markdown-explorer] sanitizer.${e} must be an integer in 1..${String(n)}; got ${String(t)}`);
361
361
  return t;
362
- }, Dn = (e, t) => {
362
+ }, Cn = (e, t) => {
363
363
  if (e !== void 0 && (e === null || typeof e != "object")) throw new TypeError("[markdown-explorer] sanitizer must be an object of { workers, deadlineMs, maxHtmlBytes, cacheBytes, workerHeapMb, jobsPerScope, maxQueuedJobs }");
364
- const { workers: r, deadlineMs: n, maxHtmlBytes: a, cacheBytes: i, workerHeapMb: c, jobsPerScope: m, maxQueuedJobs: h } = e ?? {}, S = ue("workers", r, Tn, $n), w = ue("jobsPerScope", m, kn(t, S), Number.MAX_SAFE_INTEGER), y = Object.freeze({
364
+ const { workers: r, deadlineMs: n, maxHtmlBytes: a, cacheBytes: i, workerHeapMb: c, jobsPerScope: m, maxQueuedJobs: h } = e ?? {}, S = de("workers", r, kn, Ln), w = de("jobsPerScope", m, Sn(t, S), Number.MAX_SAFE_INTEGER), y = Object.freeze({
365
365
  workers: S,
366
- deadlineMs: ue("deadlineMs", n, yn, Mn),
367
- maxHtmlBytes: ue("maxHtmlBytes", a, gn, Ln),
368
- cacheBytes: ue("cacheBytes", i, En, Number.MAX_SAFE_INTEGER),
369
- workerHeapMb: ue("workerHeapMb", c, On, jn),
366
+ deadlineMs: de("deadlineMs", n, gn, $n),
367
+ maxHtmlBytes: de("maxHtmlBytes", a, En, jn),
368
+ cacheBytes: de("cacheBytes", i, bn, Number.MAX_SAFE_INTEGER),
369
+ workerHeapMb: de("workerHeapMb", c, Rn, zn),
370
370
  jobsPerScope: w,
371
- maxQueuedJobs: ue("maxQueuedJobs", h, Sn * w, Number.MAX_SAFE_INTEGER)
371
+ maxQueuedJobs: de("maxQueuedJobs", h, xn * w, Number.MAX_SAFE_INTEGER)
372
372
  });
373
373
  if (y.jobsPerScope < t)
374
374
  throw new RangeError(`[markdown-explorer] sanitizer.jobsPerScope must be at least multiView.maxPanels (${String(t)}), because a page sends the document of every panel to the sanitizer at once for one reader; got ${String(y.jobsPerScope)}`);
375
375
  if (y.maxQueuedJobs < t)
376
376
  throw new RangeError(`[markdown-explorer] sanitizer.maxQueuedJobs must be at least multiView.maxPanels (${String(t)}), because a reader whose page finds every worker busy waits with the document of every panel; got ${String(y.maxQueuedJobs)}`);
377
- if (Pt(y) < rt)
377
+ if (Lt(y) < ot)
378
378
  throw new RangeError(
379
- `[markdown-explorer] sanitizer.workerHeapMb (${String(y.workerHeapMb)} MiB) must leave room for ${String(rt)} parsed nodes beside HTML of sanitizer.maxHtmlBytes (${String(y.maxHtmlBytes)} bytes); raise workerHeapMb or lower maxHtmlBytes`
379
+ `[markdown-explorer] sanitizer.workerHeapMb (${String(y.workerHeapMb)} MiB) must leave room for ${String(ot)} parsed nodes beside HTML of sanitizer.maxHtmlBytes (${String(y.maxHtmlBytes)} bytes); raise workerHeapMb or lower maxHtmlBytes`
380
380
  );
381
381
  return y;
382
- }, Cn = () => {
383
- const e = import.meta.url, t = new URL(`./sanitizeWorker${Mr(xe(e))}`, e);
384
- if (!Ar(xe(t))) throw new Error(`[markdown-explorer] the HTML sanitizer worker is missing: ${xe(t)}`);
382
+ }, Bn = () => {
383
+ const e = import.meta.url, t = new URL(`./sanitizeWorker${jr(Oe(e))}`, e);
384
+ if (!Mr(Oe(t))) throw new Error(`[markdown-explorer] the HTML sanitizer worker is missing: ${Oe(t)}`);
385
385
  return t;
386
- }, ot = /* @__PURE__ */ new Map(), Bn = (e, t) => {
386
+ }, it = /* @__PURE__ */ new Map(), Hn = (e, t) => {
387
387
  const r = [e.href, t.workers, t.deadlineMs, t.workerHeapMb, t.jobsPerScope, t.maxQueuedJobs].map(String).join("\0");
388
- let n = ot.get(r);
389
- return n === void 0 && (n = hn({
388
+ let n = it.get(r);
389
+ return n === void 0 && (n = yn({
390
390
  url: e,
391
391
  size: t.workers,
392
392
  deadlineMs: t.deadlineMs,
393
393
  jobsPerScope: t.jobsPerScope,
394
394
  maxQueuedJobs: t.maxQueuedJobs,
395
- heapLimits: { maxOldGenerationSizeMb: t.workerHeapMb, maxYoungGenerationSizeMb: xn }
396
- }), ot.set(r, n)), n;
397
- }, Hn = (e) => {
395
+ heapLimits: { maxOldGenerationSizeMb: t.workerHeapMb, maxYoungGenerationSizeMb: On }
396
+ }), it.set(r, n)), n;
397
+ }, Fn = (e) => {
398
398
  if (e === null || typeof e != "object") return !1;
399
399
  const { status: t, html: r, message: n } = e;
400
400
  return t === "sanitized" && typeof r == "string" || t === "too-large" || t === "error" && typeof n == "string";
401
- }, Fn = (e) => e instanceof Error && e.code === "ERR_WORKER_OUT_OF_MEMORY", Un = ({ iframeHosts: e, dataPath: t, options: r, pool: n }) => {
402
- const a = Object.freeze([...e]), i = Pt(r), c = An(r), m = In(r), h = At(Pn, {
401
+ }, Un = (e) => e instanceof Error && e.code === "ERR_WORKER_OUT_OF_MEMORY", Xn = ({ iframeHosts: e, dataPath: t, options: r, pool: n }) => {
402
+ const a = Object.freeze([...e]), i = Lt(r), c = In(r), m = Pn(r), h = Mt(Mn, {
403
403
  max: r.cacheBytes,
404
- of: (N, _) => 2 * N.length + (_.status === "sanitized" ? 2 * _.html.length : zn)
405
- }), S = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), y = (N) => {
406
- S.get(N.key) === N && S.delete(N.key);
407
- const _ = w.get(N.hash);
408
- _?.delete(N), _?.size === 0 && w.delete(N.hash);
409
- }, T = async (N, _, z) => {
410
- const O = await n.run({ html: N, iframeHosts: a, dataPath: t, maxNodes: i, maxAttributeChars: c, maxSanitizedChars: m }, { scope: _, signal: z });
411
- if (O.status === "refused") {
412
- const B = O.limit === "scope" ? `its reader already has ${String(r.jobsPerScope)} documents being sanitized or waiting` : `${String(r.maxQueuedJobs)} documents are already waiting`;
413
- return { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${B}`) }, lasting: !1 };
404
+ of: (A, R) => 2 * A.length + (R.status === "sanitized" ? 2 * R.html.length : Dn)
405
+ }), S = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), y = (A) => {
406
+ S.get(A.key) === A && S.delete(A.key);
407
+ const R = w.get(A.hash);
408
+ R?.delete(A), R?.size === 0 && w.delete(A.hash);
409
+ }, k = async (A, R, z) => {
410
+ const _ = await n.run({ html: A, iframeHosts: a, dataPath: t, maxNodes: i, maxAttributeChars: c, maxSanitizedChars: m }, { scope: R, signal: z });
411
+ if (_.status === "refused") {
412
+ const D = _.limit === "scope" ? `its reader already has ${String(r.jobsPerScope)} documents being sanitized or waiting` : `${String(r.maxQueuedJobs)} documents are already waiting`;
413
+ return { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${D}`) }, lasting: !1 };
414
414
  }
415
- if (O.status === "aborted") return { outcome: _e, lasting: !1 };
416
- if (O.status === "timeout") return { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer did not finish within ${String(r.deadlineMs)} ms`) }, lasting: !0 };
417
- if (O.status === "unavailable") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker could not start", { cause: O.error }) }, lasting: !1 };
418
- if (O.status === "crashed" && Fn(O.error))
419
- return { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer ran out of its ${String(r.workerHeapMb)} MiB worker heap`, { cause: O.error }) }, lasting: !0 };
420
- if (O.status === "crashed") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker failed", { cause: O.error }) }, lasting: !0 };
421
- const { output: P } = O;
422
- return Hn(P) ? P.status === "too-large" ? { outcome: nt, lasting: !0 } : P.status === "error" ? { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer failed: ${P.message}`) }, lasting: !0 } : P.html.length > m ? { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer's output of ${String(P.html.length)} characters exceeds its limit of ${String(m)}`) }, lasting: !0 } : { outcome: { status: "sanitized", html: P.html }, lasting: !0 } : { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker answered something that is not an outcome") }, lasting: !0 };
423
- }, v = (N, _, z, O) => {
424
- let P = () => {
415
+ if (_.status === "aborted") return { outcome: Ae, lasting: !1 };
416
+ if (_.status === "timeout") return { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer did not finish within ${String(r.deadlineMs)} ms`) }, lasting: !0 };
417
+ if (_.status === "unavailable") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker could not start", { cause: _.error }) }, lasting: !1 };
418
+ if (_.status === "crashed" && Un(_.error))
419
+ return { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer ran out of its ${String(r.workerHeapMb)} MiB worker heap`, { cause: _.error }) }, lasting: !0 };
420
+ if (_.status === "crashed") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker failed", { cause: _.error }) }, lasting: !0 };
421
+ const { output: I } = _;
422
+ return Fn(I) ? I.status === "too-large" ? { outcome: st, lasting: !0 } : I.status === "error" ? { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer failed: ${I.message}`) }, lasting: !0 } : I.html.length > m ? { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer's output of ${String(I.html.length)} characters exceeds its limit of ${String(m)}`) }, lasting: !0 } : { outcome: { status: "sanitized", html: I.html }, lasting: !0 } : { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker answered something that is not an outcome") }, lasting: !0 };
423
+ }, v = (A, R, z, _) => {
424
+ let I = () => {
425
425
  };
426
- const B = new Promise((g) => {
427
- P = g;
428
- }), H = { hash: _, key: z, outcome: B, answer: P, controller: new AbortController(), waiters: 0 };
426
+ const D = new Promise((g) => {
427
+ I = g;
428
+ }), H = { hash: R, key: z, outcome: D, answer: I, controller: new AbortController(), waiters: 0 };
429
429
  S.set(z, H);
430
- const p = w.get(_);
431
- return p === void 0 ? w.set(_, /* @__PURE__ */ new Set([H])) : p.add(H), T(N, O, H.controller.signal).catch((g) => ({ outcome: { status: "rejected", reason: "failed", cause: g instanceof Error ? g : new Error(String(g)) }, lasting: !0 })).then(({ outcome: g, lasting: E }) => {
430
+ const p = w.get(R);
431
+ return p === void 0 ? w.set(R, /* @__PURE__ */ new Set([H])) : p.add(H), k(A, _, H.controller.signal).catch((g) => ({ outcome: { status: "rejected", reason: "failed", cause: g instanceof Error ? g : new Error(String(g)) }, lasting: !0 })).then(({ outcome: g, lasting: E }) => {
432
432
  if (y(H), H.answer(g), !E) return;
433
- const R = h.get(_), k = R ?? (g.status === "rejected" ? { ...g, cause: null } : g);
434
- R === void 0 && h.set(_, k);
435
- for (const A of w.get(_) ?? [])
436
- y(A), A.answer(k), A.controller.abort();
433
+ const O = h.get(R), T = O ?? (g.status === "rejected" ? { ...g, cause: null } : g);
434
+ O === void 0 && h.set(R, T);
435
+ for (const N of w.get(R) ?? [])
436
+ y(N), N.answer(T), N.controller.abort();
437
437
  }), H;
438
- }, $ = (N, _) => new Promise((z) => {
439
- N.waiters += 1;
440
- const O = () => {
441
- N.waiters -= 1, z(_e), !(N.waiters > 0) && (y(N), N.controller.abort());
438
+ }, L = (A, R) => new Promise((z) => {
439
+ A.waiters += 1;
440
+ const _ = () => {
441
+ A.waiters -= 1, z(Ae), !(A.waiters > 0) && (y(A), A.controller.abort());
442
442
  };
443
- _.addEventListener("abort", O, { once: !0 }), N.outcome.then((P) => {
444
- _.removeEventListener("abort", O), z(P);
443
+ R.addEventListener("abort", _, { once: !0 }), A.outcome.then((I) => {
444
+ R.removeEventListener("abort", _), z(I);
445
445
  });
446
446
  });
447
- return (N, { scope: _, signal: z }) => {
448
- if (N.length > r.maxHtmlBytes || Buffer.byteLength(N, "utf8") > r.maxHtmlBytes) return Promise.resolve(nt);
449
- const O = yr("sha256").update(N, "utf8").digest("base64"), P = h.get(O);
450
- if (P !== void 0) return Promise.resolve(P);
451
- if (z.aborted) return Promise.resolve(_e);
452
- const B = `${O}\0${_}`, H = S.get(B);
453
- return $(H === void 0 ? v(N, O, B, _) : H, z);
447
+ return (A, { scope: R, signal: z }) => {
448
+ if (A.length > r.maxHtmlBytes || Buffer.byteLength(A, "utf8") > r.maxHtmlBytes) return Promise.resolve(st);
449
+ const _ = br("sha256").update(A, "utf8").digest("base64"), I = h.get(_);
450
+ if (I !== void 0) return Promise.resolve(I);
451
+ if (z.aborted) return Promise.resolve(Ae);
452
+ const D = `${_}\0${R}`, H = S.get(D);
453
+ return L(H === void 0 ? v(A, _, D, R) : H, z);
454
454
  };
455
- }, Se = (e) => ({ result: e, json: JSON.stringify(e) }), Ne = Object.freeze(Se(Object.freeze({ status: "error", failure: Object.freeze({ reason: "failed" }) }))), Xn = (e) => e.status === "ok" && e.entries.length > 0, Jn = ({ ttlMs: e, maxEntries: t, maxBytes: r, now: n }) => {
456
- const a = At(t, { max: r, of: (w, y) => 2 * y.tree.json.length }), i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), m = (w, y) => {
457
- const T = new AbortController(), v = { waiters: 0, superseded: !1, started: !1, loadTree: y }, $ = c.get(w), N = (B, H) => {
458
- const p = Se(B);
459
- return !(v.superseded || T.signal.aborted) && Xn(B) && a.set(w, { tree: p, loadedAt: H }), p;
455
+ }, xe = (e) => ({ result: e, json: JSON.stringify(e) }), Ne = Object.freeze(xe(Object.freeze({ status: "error", failure: Object.freeze({ reason: "failed" }) }))), Jn = (e) => e.status === "ok" && e.entries.length > 0, Gn = ({ ttlMs: e, maxEntries: t, maxBytes: r, now: n }) => {
456
+ const a = Mt(t, { max: r, of: (w, y) => 2 * y.tree.json.length }), i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), m = (w, y) => {
457
+ const k = new AbortController(), v = { waiters: 0, superseded: !1, started: !1, loadTree: y }, L = c.get(w), A = (D, H) => {
458
+ const p = xe(D);
459
+ return !(v.superseded || k.signal.aborted) && Jn(D) && a.set(w, { tree: p, loadedAt: H }), p;
460
460
  }, z = (async () => {
461
- if ($ !== void 0 && await $, T.signal.aborted) return Ne;
462
- const B = n();
463
- return v.started = !0, N(await v.loadTree(T.signal, B), B);
461
+ if (L !== void 0 && await L, k.signal.aborted) return Ne;
462
+ const D = n();
463
+ return v.started = !0, A(await v.loadTree(k.signal, D), D);
464
464
  })().finally(() => {
465
- i.get(w) === O && i.delete(w);
466
- }), O = { promise: z, controller: T, state: v };
467
- i.set(w, O);
468
- const P = z.then(
465
+ i.get(w) === _ && i.delete(w);
466
+ }), _ = { promise: z, controller: k, state: v };
467
+ i.set(w, _);
468
+ const I = z.then(
469
469
  () => {
470
470
  },
471
471
  () => {
472
472
  }
473
473
  );
474
- return c.set(w, P), P.then(() => {
475
- c.get(w) === P && c.delete(w);
476
- }), O;
477
- }, h = (w, y, T) => {
474
+ return c.set(w, I), I.then(() => {
475
+ c.get(w) === I && c.delete(w);
476
+ }), _;
477
+ }, h = (w, y, k) => {
478
478
  y.state.waiters += 1;
479
479
  const v = () => {
480
480
  y.state.waiters -= 1, !(y.state.waiters > 0) && (i.get(w) === y && i.delete(w), y.controller.abort());
481
481
  };
482
- return T.addEventListener("abort", v, { once: !0 }), y.promise.finally(() => {
483
- T.removeEventListener("abort", v);
482
+ return k.addEventListener("abort", v, { once: !0 }), y.promise.finally(() => {
483
+ k.removeEventListener("abort", v);
484
484
  });
485
485
  }, S = (w) => {
486
486
  a.delete(w);
@@ -488,36 +488,36 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
488
488
  y?.state.started && (y.state.superseded = !0, i.delete(w));
489
489
  };
490
490
  return {
491
- load: (w, y, T) => {
491
+ load: (w, y, k) => {
492
492
  if (y.aborted) return Promise.resolve(Ne);
493
493
  const v = a.get(w);
494
494
  if (v !== void 0) {
495
495
  if (n() - v.loadedAt < e) return Promise.resolve(v.tree);
496
496
  a.delete(w);
497
497
  }
498
- const $ = i.get(w);
499
- return h(w, $ === void 0 ? m(w, T) : $, y);
498
+ const L = i.get(w);
499
+ return h(w, L === void 0 ? m(w, k) : L, y);
500
500
  },
501
- refresh: (w, y, T) => {
501
+ refresh: (w, y, k) => {
502
502
  if (y.aborted) return Promise.resolve(Ne);
503
503
  S(w);
504
504
  const v = i.get(w);
505
- return v === void 0 ? h(w, m(w, T), y) : (v.state.loadTree = T, h(w, v, y));
505
+ return v === void 0 ? h(w, m(w, k), y) : (v.state.loadTree = k, h(w, v, y));
506
506
  },
507
507
  forget: S
508
508
  };
509
- }, Gn = (e) => ({
510
- load: (t, r, n) => n(r, e()).then(Se),
511
- refresh: (t, r, n) => n(r, e()).then(Se),
509
+ }, Yn = (e) => ({
510
+ load: (t, r, n) => n(r, e()).then(xe),
511
+ refresh: (t, r, n) => n(r, e()).then(xe),
512
512
  forget: () => {
513
513
  }
514
514
  }), x = (e) => {
515
515
  throw new TypeError(`[markdown-explorer] ${e}`);
516
- }, Yn = (e) => {
516
+ }, Wn = (e) => {
517
517
  if (e === null || typeof e != "object") return null;
518
518
  const { name: t, path: r } = e;
519
519
  return typeof t != "string" || typeof r != "string" ? null : t === "" ? { path: r, reason: "an empty name" } : q(r) ? null : { path: r, reason: "a path the browser cannot address (empty, too long, a lone surrogate, a control character or a backslash)" };
520
- }, Wn = (e, t, r, n) => {
520
+ }, Kn = (e, t, r, n) => {
521
521
  if (e === null) return null;
522
522
  if (!Array.isArray(e)) throw new TypeError(`[markdown-explorer] a source's ancestors must be null or an array of folder paths; got ${typeof e}`);
523
523
  const a = /* @__PURE__ */ new Set();
@@ -530,7 +530,7 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
530
530
  a.add(i);
531
531
  }
532
532
  return Object.freeze([...a]);
533
- }, Kn = (e, t, r, n, a) => {
533
+ }, Vn = (e, t, r, n, a) => {
534
534
  const i = /* @__PURE__ */ new Set(), c = (h) => {
535
535
  if (!Array.isArray(h)) return x("a source returned entries that are not an array");
536
536
  const S = [];
@@ -540,34 +540,34 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
540
540
  }
541
541
  return S;
542
542
  }, m = (h) => {
543
- const S = Yn(h);
543
+ const S = Wn(h);
544
544
  if (S !== null)
545
545
  return n(S), null;
546
- const w = cr(h);
546
+ const w = lr(h);
547
547
  if (w !== null) return x(w);
548
548
  const y = h;
549
549
  if (i.has(y)) return x("a source returned entries that contain themselves");
550
- const { name: T, path: v, type: $, mimeType: N, children: _, lazy: z } = y;
551
- if (t.deniesName(T) || t.deniesPath(v)) return null;
550
+ const { name: k, path: v, type: L, mimeType: A, modifiedAt: R, children: z, lazy: _ } = y;
551
+ if (t.deniesName(k) || t.deniesPath(v)) return null;
552
552
  if (!a(v))
553
553
  return n({ path: v, reason: "a path outside the source's boundary" }), null;
554
- const O = N === void 0 ? { name: T, path: v } : { name: T, path: v, mimeType: N };
555
- if ($ === "file") return { ...O, type: $ };
556
- if (z === !0)
557
- return r ? { ...O, type: $, lazy: !0, children: [] } : x("a lazy directory came from a source without a children function");
558
- if (_ === void 0) return { ...O, type: $ };
554
+ const I = { name: k, path: v, ...A === void 0 ? {} : { mimeType: A }, ...R === void 0 ? {} : { modifiedAt: R } };
555
+ if (L === "file") return { ...I, type: L };
556
+ if (_ === !0)
557
+ return r ? { ...I, type: L, lazy: !0, children: [] } : x("a lazy directory came from a source without a children function");
558
+ if (z === void 0) return { ...I, type: L };
559
559
  i.add(y);
560
- const P = c(_);
561
- return i.delete(y), { ...O, type: $, children: P };
560
+ const D = c(z);
561
+ return i.delete(y), { ...I, type: L, children: D };
562
562
  };
563
563
  return c(e);
564
- }, Vn = /^[\x21\x23-\x7E]{1,256}$/u, Mt = (e) => typeof e == "string" && Vn.test(e), Zn = /* @__PURE__ */ new Set(["text", "image", "media", "file"]), Qn = (e) => typeof e == "string" && Zn.has(e), qn = (e, t, r) => {
564
+ }, Zn = /^[\x21\x23-\x7E]{1,256}$/u, jt = (e) => typeof e == "string" && Zn.test(e), Qn = /* @__PURE__ */ new Set(["text", "image", "media", "file"]), qn = (e) => typeof e == "string" && Qn.has(e), eo = (e, t, r) => {
565
565
  if (e !== null && typeof e == "object") {
566
566
  const i = e, { kind: c } = i;
567
- if (Qn(c)) {
567
+ if (qn(c)) {
568
568
  if (Object.hasOwn(i, "url")) return x(`a ${c} document carries its version, not a url`);
569
569
  if (typeof i.name != "string") return x("a document needs a name string");
570
- if (!Mt(i.version)) return x(`a ${c} document needs a version of 1 to 256 visible ASCII characters other than '"'`);
570
+ if (!jt(i.version)) return x(`a ${c} document needs a version of 1 to 256 visible ASCII characters other than '"'`);
571
571
  const m = t(i.version);
572
572
  switch (c) {
573
573
  case "image":
@@ -575,107 +575,107 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
575
575
  return { kind: c, name: i.name, url: m };
576
576
  case "media": {
577
577
  const { mediaType: h } = i;
578
- return nr(h) ? { kind: c, name: i.name, url: m, mediaType: h } : x(`unknown media type ${typeof h == "string" ? JSON.stringify(h.slice(0, 64)) : typeof h}`);
578
+ return ir(h) ? { kind: c, name: i.name, url: m, mediaType: h } : x(`unknown media type ${typeof h == "string" ? JSON.stringify(h.slice(0, 64)) : typeof h}`);
579
579
  }
580
580
  case "text":
581
581
  return typeof i.text != "string" || typeof i.truncated != "boolean" ? x("a text document needs text and truncated") : { kind: c, name: i.name, text: i.text, truncated: i.truncated, url: m };
582
582
  }
583
583
  }
584
584
  }
585
- const n = or(e);
585
+ const n = ar(e);
586
586
  if (n !== null) return x(n);
587
587
  const a = e;
588
588
  switch (a.kind) {
589
589
  case "failure": {
590
590
  const { reason: i, code: c } = a.failure;
591
- return { kind: "failure", failure: Te(i, c) };
591
+ return { kind: "failure", failure: ke(i, c) };
592
592
  }
593
593
  case "markdown":
594
- return a.headings.length > bt ? { kind: "failure", failure: Te("too-large") } : a.edit?.kind === "inline" && !r ? x("a markdown document offers inline editing, but the server has no edit ports") : { kind: "unsanitized-markdown", name: a.name, html: a.htmlContent, headings: a.headings.map(({ text: i, depth: c, id: m }) => ({ text: i, depth: c, id: m })), edit: eo(a.edit) };
594
+ return a.headings.length > kt ? { kind: "failure", failure: ke("too-large") } : a.edit?.kind === "inline" && !r ? x("a markdown document offers inline editing, but the server has no edit ports") : { kind: "unsanitized-markdown", name: a.name, html: a.htmlContent, headings: a.headings.map(({ text: i, depth: c, id: m }) => ({ text: i, depth: c, id: m })), edit: to(a.edit) };
595
595
  }
596
- }, eo = (e) => e === null ? null : e.kind === "inline" ? { kind: "inline" } : { kind: "external", href: e.href }, je = (e, t, r) => typeof e != "string" ? x(`${r} needs a text string`) : e.includes("\0") ? x(`${r} holds NUL, which no text editor can keep`) : new TextEncoder().encode(e).byteLength > t ? x(`${r} is over editMaxBytes (${t} bytes); refuse a longer source with ExplorerError "too-large"`) : e, $t = (e) => ar(e.href) ? { kind: "grant", href: e.href } : x("a grant needs a root-relative href"), to = (e, t) => {
596
+ }, to = (e) => e === null ? null : e.kind === "inline" ? { kind: "inline" } : { kind: "external", href: e.href }, ze = (e, t, r) => typeof e != "string" ? x(`${r} needs a text string`) : e.includes("\0") ? x(`${r} holds NUL, which no text editor can keep`) : new TextEncoder().encode(e).byteLength > t ? x(`${r} is over editMaxBytes (${t} bytes); refuse a longer source with ExplorerError "too-large"`) : e, zt = (e) => dr(e.href) ? { kind: "grant", href: e.href } : x("a grant needs a root-relative href"), ro = (e, t) => {
597
597
  if (e === null || typeof e != "object") return x("an edit source must be an object");
598
598
  const r = e;
599
- return r.kind === "grant" ? $t(r) : r.kind !== "edit" ? x(`an edit source's kind must be "edit" or "grant"`) : he(r.version) ? typeof r.history != "boolean" ? x("an edit source needs history") : { kind: "edit", text: je(r.text, t, "an edit source"), version: r.version, history: r.history } : x("an edit source needs a version of 1 to 1024 characters");
600
- }, ro = (e, t) => {
599
+ return r.kind === "grant" ? zt(r) : r.kind !== "edit" ? x(`an edit source's kind must be "edit" or "grant"`) : he(r.version) ? typeof r.history != "boolean" ? x("an edit source needs history") : { kind: "edit", text: ze(r.text, t, "an edit source"), version: r.version, history: r.history } : x("an edit source needs a version of 1 to 1024 characters");
600
+ }, no = (e, t) => {
601
601
  if (e === null || typeof e != "object") return x("a save result must be an object");
602
602
  const r = e;
603
603
  switch (r.kind) {
604
604
  case "grant":
605
- return $t(r);
605
+ return zt(r);
606
606
  case "saved":
607
607
  return he(r.version) ? { kind: "saved", version: r.version } : x("a saved result needs a version of 1 to 1024 characters");
608
608
  case "conflict":
609
- return he(r.version) ? { kind: "conflict", version: r.version, text: je(r.text, t, "a conflict's current text") } : x("a conflict needs the current version of 1 to 1024 characters");
609
+ return he(r.version) ? { kind: "conflict", version: r.version, text: ze(r.text, t, "a conflict's current text") } : x("a conflict needs the current version of 1 to 1024 characters");
610
610
  default:
611
611
  return x(`a save result's kind must be "saved", "conflict" or "grant"`);
612
612
  }
613
- }, no = (e) => {
613
+ }, oo = (e) => {
614
614
  if (e === null || typeof e != "object") return x("a preview must be an object");
615
615
  const { htmlContent: t, headings: r } = e;
616
616
  if (typeof t != "string" || !Array.isArray(r)) return x("a preview needs htmlContent and headings");
617
- if (r.length > bt) return { kind: "failure", failure: Te("too-large") };
617
+ if (r.length > kt) return { kind: "failure", failure: ke("too-large") };
618
618
  for (const n of r) {
619
- const a = ir(n);
619
+ const a = ur(n);
620
620
  if (a !== null) return x(a);
621
621
  }
622
622
  return { html: t, headings: r.map(({ text: n, depth: a, id: i }) => ({ text: n, depth: a, id: i })) };
623
- }, oo = (e) => {
623
+ }, so = (e) => {
624
624
  if (!Array.isArray(e)) return x("revisions must be an array");
625
625
  const t = /* @__PURE__ */ new Set();
626
626
  return e.map((r) => {
627
- const n = sr(r);
627
+ const n = cr(r);
628
628
  if (n !== null) return x(n);
629
629
  const { id: a, modifiedAt: i, size: c, author: m, kept: h, current: S } = r;
630
630
  return t.has(a) ? x(`two revisions share the id ${JSON.stringify(a.slice(0, 64))}`) : (t.add(a), { id: a, modifiedAt: i, size: c, author: m, kept: h, current: S });
631
631
  });
632
- }, so = (e, t) => je(e, t, "a revision"), st = (e) => {
632
+ }, io = (e, t) => ze(e, t, "a revision"), at = (e) => {
633
633
  if (e === null || typeof e != "object") return x("an asset file must be an object");
634
634
  const { name: t, contentType: r, size: n, version: a, open: i } = e;
635
- return typeof t != "string" || t === "" ? x("an asset file needs a non-empty name") : typeof r != "string" ? x("an asset file needs a contentType string ('' when unknown)") : n !== null && !(typeof n == "number" && Number.isSafeInteger(n) && n >= 0) ? x("an asset file's size must be null or a non-negative safe integer") : Mt(a) ? typeof i != "function" ? x("an asset file needs an open function") : Object.freeze({ name: t, contentType: r, size: n, version: a, open: i }) : x(`an asset file needs a version of 1 to 256 visible ASCII characters other than '"'`);
636
- }, io = (e) => Array.isArray(e) ? e.map((t) => {
635
+ return typeof t != "string" || t === "" ? x("an asset file needs a non-empty name") : typeof r != "string" ? x("an asset file needs a contentType string ('' when unknown)") : n !== null && !(typeof n == "number" && Number.isSafeInteger(n) && n >= 0) ? x("an asset file's size must be null or a non-negative safe integer") : jt(a) ? typeof i != "function" ? x("an asset file needs an open function") : Object.freeze({ name: t, contentType: r, size: n, version: a, open: i }) : x(`an asset file needs a version of 1 to 256 visible ASCII characters other than '"'`);
636
+ }, ao = (e) => Array.isArray(e) ? e.map((t) => {
637
637
  if (t === null || typeof t != "object") return x("a notice must be an object");
638
638
  const { id: r, tone: n, title: a, body: i, action: c } = t;
639
639
  if (typeof r != "string" || r === "" || typeof a != "string") return x("a notice needs an id and a title");
640
- if (!tr(n)) return x(`unknown notice tone ${typeof n == "string" ? JSON.stringify(n.slice(0, 64)) : typeof n}`);
640
+ if (!or(n)) return x(`unknown notice tone ${typeof n == "string" ? JSON.stringify(n.slice(0, 64)) : typeof n}`);
641
641
  if (i !== void 0 && typeof i != "string") return x("a notice body must be a string");
642
642
  const h = { id: r, tone: n, title: a, ...i === void 0 ? {} : { body: i } };
643
643
  if (c === void 0) return h;
644
644
  if (c === null || typeof c != "object") return x("a notice action must be an object");
645
645
  const { label: S, href: w } = c;
646
- return typeof S != "string" || !rr(w, ur) ? x("a notice action needs a label and an http(s), mailto or relative href") : { ...h, action: { label: S, href: w } };
647
- }) : x("notices must be an array"), ao = 4e3, ge = Object.freeze({ ttlMs: 3e5, maxEntries: 64, maxBytes: 64 * 1024 * 1024 }), it = 32, Lt = "private, no-store", co = Object.freeze({
646
+ return typeof S != "string" || !sr(w, fr) ? x("a notice action needs a label and an http(s), mailto or relative href") : { ...h, action: { label: S, href: w } };
647
+ }) : x("notices must be an array"), co = 4e3, Ee = Object.freeze({ ttlMs: 3e5, maxEntries: 64, maxBytes: 64 * 1024 * 1024 }), ct = 32, Dt = "private, no-store", uo = Object.freeze({
648
648
  "Content-Type": "application/json; charset=utf-8",
649
- "Cache-Control": Lt,
649
+ "Cache-Control": Dt,
650
650
  "X-Content-Type-Options": "nosniff",
651
651
  "Content-Security-Policy": "default-src 'none'; frame-ancestors 'none'; sandbox",
652
652
  "Cross-Origin-Resource-Policy": "same-origin"
653
- }), uo = 22, lo = 2147483647, Ae = Object.freeze([]), fo = Object.freeze({ status: "ok", source: null, ancestors: null }), at = Object.freeze(["contains", "confirm"]), ct = Object.freeze({ readOnly: !1 }), mo = Object.freeze({ readOnly: !0 }), K = (e, t, r) => {
653
+ }), lo = 22, fo = 2147483647, Ie = Object.freeze([]), mo = Object.freeze({ status: "ok", source: null, ancestors: null }), ut = Object.freeze(["contains", "confirm"]), dt = Object.freeze({ readOnly: !1 }), po = Object.freeze({ readOnly: !0 }), K = (e, t, r) => {
654
654
  if (!(r && t === void 0) && typeof t != "function")
655
655
  throw new TypeError(`[markdown-explorer] ${e} must be a function; got ${typeof t}`);
656
- }, le = (e, t, r) => {
656
+ }, fe = (e, t, r) => {
657
657
  if (typeof t != "number") throw new TypeError(`[markdown-explorer] ${e} must be a number; got ${typeof t}`);
658
658
  if (!Number.isSafeInteger(t) || t <= 0 || t > r) throw new RangeError(`[markdown-explorer] ${e} must be an integer in 1..${String(r)}; got ${String(t)}`);
659
659
  return t;
660
- }, po = (e) => {
660
+ }, wo = (e) => {
661
661
  if (e === null || typeof e != "object" || !Object.isFrozen(e)) throw new TypeError("[markdown-explorer] config must be the value returned by defineExplorerConfig");
662
- return Sr(e);
663
- }, ut = (e) => {
662
+ return Rr(e);
663
+ }, lt = (e) => {
664
664
  try {
665
665
  return new Headers(e);
666
666
  } catch {
667
667
  throw new TypeError("[markdown-explorer] authenticate returned headers that are not a valid headers init (their values are not logged)");
668
668
  }
669
- }, dt = (e) => e instanceof Response ? new TypeError(`[markdown-explorer] authenticate threw a Response (status ${String(e.status)}), which a data request does not follow`) : e, wo = (e) => {
669
+ }, ft = (e) => e instanceof Response ? new TypeError(`[markdown-explorer] authenticate threw a Response (status ${String(e.status)}), which a data request does not follow`) : e, ho = (e) => {
670
670
  if (typeof e != "string") throw new TypeError(`[markdown-explorer] scopeSecret must be a string; got ${typeof e}`);
671
- if (e.length < it) throw new RangeError(`[markdown-explorer] scopeSecret must have at least ${String(it)} characters; got ${String(e.length)}`);
671
+ if (e.length < ct) throw new RangeError(`[markdown-explorer] scopeSecret must have at least ${String(ct)} characters; got ${String(e.length)}`);
672
672
  return e;
673
- }, ho = (e, t) => {
674
- if (!_r(t)) throw new TypeError(`[markdown-explorer] ${e}.boundary must be a plain object { contains, confirm? }`);
673
+ }, yo = (e, t) => {
674
+ if (!Ir(t)) throw new TypeError(`[markdown-explorer] ${e}.boundary must be a plain object { contains, confirm? }`);
675
675
  for (const r of Object.keys(t))
676
- if (!at.includes(r)) throw new RangeError(`[markdown-explorer] ${e}.boundary.${r} is not an option; expected ${at.join(", ")}`);
676
+ if (!ut.includes(r)) throw new RangeError(`[markdown-explorer] ${e}.boundary.${r} is not an option; expected ${ut.join(", ")}`);
677
677
  K(`${e}.boundary.contains`, t.contains, !1), K(`${e}.boundary.confirm`, t.confirm, !0);
678
- }, yo = (e) => {
678
+ }, go = (e) => {
679
679
  if (!Array.isArray(e)) throw new TypeError("[markdown-explorer] sources must be an array");
680
680
  const t = e;
681
681
  if (t.length === 0) throw new RangeError("[markdown-explorer] sources must hold at least one source");
@@ -683,65 +683,65 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
683
683
  for (const [n, a] of t.entries()) {
684
684
  if (a === null || typeof a != "object") throw new TypeError(`[markdown-explorer] sources[${String(n)}] must be an object`);
685
685
  const { id: i, label: c, boundary: m, tree: h, children: S, ancestors: w, cacheScope: y } = a;
686
- if (!xr(i))
686
+ if (!vr(i))
687
687
  throw new RangeError(`[markdown-explorer] sources[${String(n)}].id must use lowercase letters, digits and "-" and start with a letter or digit; got ${typeof i == "string" ? JSON.stringify(i) : typeof i}`);
688
- const T = `source ${JSON.stringify(i)}`;
688
+ const k = `source ${JSON.stringify(i)}`;
689
689
  if (r.has(i)) throw new RangeError(`[markdown-explorer] source ids must be unique; ${JSON.stringify(i)} repeats at sources[${String(n)}]`);
690
- if (r.add(i), typeof c != "string" && typeof c != "function") throw new TypeError(`[markdown-explorer] ${T}.label must be a string or a function`);
691
- if (typeof c == "string" && c.trim() === "") throw new RangeError(`[markdown-explorer] ${T}.label must not be blank`);
692
- if (ho(T, m), K(`${T}.tree`, h, !1), K(`${T}.children`, S, !0), K(`${T}.ancestors`, w, !0), y !== void 0 && y !== "principal" && y !== "shared") throw new RangeError(`[markdown-explorer] ${T}.cacheScope must be "principal" or "shared"; got ${JSON.stringify(y)}`);
690
+ if (r.add(i), typeof c != "string" && typeof c != "function") throw new TypeError(`[markdown-explorer] ${k}.label must be a string or a function`);
691
+ if (typeof c == "string" && c.trim() === "") throw new RangeError(`[markdown-explorer] ${k}.label must not be blank`);
692
+ if (yo(k, m), K(`${k}.tree`, h, !1), K(`${k}.children`, S, !0), K(`${k}.ancestors`, w, !0), y !== void 0 && y !== "principal" && y !== "shared") throw new RangeError(`[markdown-explorer] ${k}.cacheScope must be "principal" or "shared"; got ${JSON.stringify(y)}`);
693
693
  }
694
694
  return t;
695
- }, go = (e) => {
695
+ }, Eo = (e) => {
696
696
  if (e === !1) return !1;
697
- if (e === void 0) return ge;
697
+ if (e === void 0) return Ee;
698
698
  if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] treeCache must be { ttlMs, maxEntries, maxBytes } or false");
699
699
  const { ttlMs: t, maxEntries: r, maxBytes: n } = e;
700
700
  return {
701
- ttlMs: t === void 0 ? ge.ttlMs : le("treeCache.ttlMs", t, Number.MAX_SAFE_INTEGER),
702
- maxEntries: r === void 0 ? ge.maxEntries : le("treeCache.maxEntries", r, Number.MAX_SAFE_INTEGER),
703
- maxBytes: n === void 0 ? ge.maxBytes : le("treeCache.maxBytes", n, Number.MAX_SAFE_INTEGER)
701
+ ttlMs: t === void 0 ? Ee.ttlMs : fe("treeCache.ttlMs", t, Number.MAX_SAFE_INTEGER),
702
+ maxEntries: r === void 0 ? Ee.maxEntries : fe("treeCache.maxEntries", r, Number.MAX_SAFE_INTEGER),
703
+ maxBytes: n === void 0 ? Ee.maxBytes : fe("treeCache.maxBytes", n, Number.MAX_SAFE_INTEGER)
704
704
  };
705
- }, lt = (e) => {
705
+ }, mt = (e) => {
706
706
  if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] authenticate must resolve to { status, ... }");
707
707
  const { status: t } = e;
708
708
  if (t !== "signed-in" && t !== "signed-out" && t !== "forbidden") throw new TypeError(`[markdown-explorer] authenticate resolved to an unknown status ${JSON.stringify(t)}`);
709
709
  return e;
710
- }, ft = (e, t) => {
710
+ }, pt = (e, t) => {
711
711
  if (!(t instanceof Response)) throw new TypeError(`[markdown-explorer] ${e} must return a Response`);
712
712
  return t;
713
- }, mt = (e, t) => {
713
+ }, wt = (e, t) => {
714
714
  if (typeof t != "string" || t === "") throw new TypeError("[markdown-explorer] principalKey must return a non-empty string");
715
- return gr("sha256", e).update(t, "utf8").digest("base64url").slice(0, uo);
716
- }, Eo = (e) => e.view === "multi" ? e.docs : e.doc === null ? [] : [e.doc], ae = (e, t) => {
715
+ return Tr("sha256", e).update(t, "utf8").digest("base64url").slice(0, lo);
716
+ }, bo = (e) => e.view === "multi" ? e.docs : e.doc === null ? [] : [e.doc], ce = (e, t) => {
717
717
  const r = e.getAll(t), [n] = r;
718
718
  return r.length === 1 && n !== void 0 && n !== "" ? n : null;
719
719
  }, W = (e, t, r, n = {}) => {
720
720
  const a = new Headers(r);
721
- for (const [i, c] of Object.entries({ ...co, ...n })) a.set(i, c);
721
+ for (const [i, c] of Object.entries({ ...uo, ...n })) a.set(i, c);
722
722
  return new Response(t, { status: e, headers: a });
723
- }, j = (e, t, r) => W(lr[e.reason], JSON.stringify({ failure: e }), t, r), bo = /* @__PURE__ */ new Set(["refresh", "save", "preview"]), To = /* @__PURE__ */ new Set(["edit", "save", "preview", "revisions", "revision"]), pt = (e, t) => {
724
- const r = bo.has(t) ? ["POST"] : ["GET", "HEAD"];
723
+ }, j = (e, t, r) => W(pr[e.reason], JSON.stringify({ failure: e }), t, r), To = /* @__PURE__ */ new Set(["refresh", "save", "preview"]), ko = /* @__PURE__ */ new Set(["edit", "save", "preview", "revisions", "revision"]), ht = (e, t) => {
724
+ const r = To.has(t) ? ["POST"] : ["GET", "HEAD"];
725
725
  return r.includes(e.method.toUpperCase()) ? null : W(405, JSON.stringify({ failure: { reason: "invalid" } }), void 0, { Allow: r.join(", ") });
726
- }, wt = (e) => e.headers.get(Me) === fr && kt(e, St) === void 0, ko = (e) => e.headers.get(Me) === mr && kt(e, St) === void 0, So = async (e, t) => {
727
- const [r, ...n] = (e.headers.get("Content-Type") ?? "").split(";").map((T) => T.trim().toLowerCase()), a = n.find((T) => T.startsWith("charset="));
728
- if (r !== hr || a !== void 0 && a !== "charset=utf-8") return { status: "error", failure: { reason: "invalid" } };
726
+ }, yt = (e) => e.headers.get($e) === wr && xt(e, Ot) === void 0, So = (e) => e.headers.get($e) === hr && xt(e, Ot) === void 0, xo = async (e, t) => {
727
+ const [r, ...n] = (e.headers.get("Content-Type") ?? "").split(";").map((k) => k.trim().toLowerCase()), a = n.find((k) => k.startsWith("charset="));
728
+ if (r !== Er || a !== void 0 && a !== "charset=utf-8") return { status: "error", failure: { reason: "invalid" } };
729
729
  const i = Number(e.headers.get("Content-Length") ?? "0");
730
730
  if (Number.isFinite(i) && i > t) return { status: "error", failure: { reason: "too-large" } };
731
731
  if (e.body === null) return { status: "ok", text: "" };
732
732
  const c = e.body.getReader(), m = [];
733
733
  let h = 0;
734
734
  for (; ; ) {
735
- const { done: T, value: v } = await c.read();
736
- if (T) break;
735
+ const { done: k, value: v } = await c.read();
736
+ if (k) break;
737
737
  if (h += v.byteLength, h > t)
738
738
  return await c.cancel(), { status: "error", failure: { reason: "too-large" } };
739
739
  m.push(v);
740
740
  }
741
741
  const S = new Uint8Array(h);
742
742
  let w = 0;
743
- for (const T of m)
744
- S.set(T, w), w += T.byteLength;
743
+ for (const k of m)
744
+ S.set(k, w), w += k.byteLength;
745
745
  let y;
746
746
  try {
747
747
  y = new TextDecoder("utf-8", { fatal: !0 }).decode(S);
@@ -749,36 +749,36 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
749
749
  return { status: "error", failure: { reason: "invalid" } };
750
750
  }
751
751
  return y.includes("\0") ? { status: "error", failure: { reason: "invalid" } } : { status: "ok", text: y };
752
- }, xo = (e) => {
752
+ }, Oo = (e) => {
753
753
  if (e === void 0) return;
754
754
  if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] edit must be an object of the editor's ports");
755
755
  const t = e;
756
756
  for (const r of ["source", "save", "preview", "revisions", "revision"]) K(`edit.${r}`, t[r], !1);
757
757
  return e;
758
- }, Oo = ({ parentHeaders: e, loaderHeaders: t, errorHeaders: r }) => {
758
+ }, Ro = ({ parentHeaders: e, loaderHeaders: t, errorHeaders: r }) => {
759
759
  const n = new Headers(), a = r === void 0 ? [e, t] : [e, t, r];
760
760
  for (const i of a)
761
761
  for (const [c, m] of i)
762
762
  c !== "set-cookie" && n.set(c, m);
763
763
  return n;
764
- }, Qo = (e) => {
764
+ }, qo = (e) => {
765
765
  if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] the server configuration must be an object");
766
- const t = po(e.config), r = wo(e.scopeSecret);
766
+ const t = wo(e.config), r = ho(e.scopeSecret);
767
767
  K("authenticate", e.authenticate, !1), K("principalKey", e.principalKey, !1), K("document", e.document, !1), K("asset", e.asset, !1), K("signedOutPage", e.signedOutPage, !1), K("forbiddenPage", e.forbiddenPage, !0), K("notices", e.notices, !0), K("onTreeRefreshed", e.onTreeRefreshed, !0);
768
- const n = yo(e.sources), a = Tr(
768
+ const n = go(e.sources), a = xr(
769
769
  t,
770
770
  n.map((o) => o.id)
771
771
  ), i = e.logger;
772
772
  if (i !== void 0 && (i === null || typeof i != "object" || typeof i.error != "function"))
773
773
  throw new TypeError("[markdown-explorer] logger must be an object with an error function");
774
- const c = e.logger === void 0 ? an : e.logger, m = Tt(e.deny), h = e.deferredTimeoutMs === void 0 ? ao : le("deferredTimeoutMs", e.deferredTimeoutMs, lo), S = e.textMaxBytes === void 0 ? Qe : le("textMaxBytes", e.textMaxBytes, qe), w = xo(e.edit);
774
+ const c = e.logger === void 0 ? cn : e.logger, m = St(e.deny), h = e.deferredTimeoutMs === void 0 ? co : fe("deferredTimeoutMs", e.deferredTimeoutMs, fo), S = e.textMaxBytes === void 0 ? et : fe("textMaxBytes", e.textMaxBytes, tt), w = Oo(e.edit);
775
775
  if (w === void 0 && e.editMaxBytes !== void 0) throw new TypeError("[markdown-explorer] editMaxBytes needs the edit ports");
776
- const y = e.editMaxBytes === void 0 ? Qe : le("editMaxBytes", e.editMaxBytes, qe), T = go(e.treeCache), v = () => Date.now(), $ = T === !1 ? Gn(v) : Jn({ ...T, now: v }), N = Dn(e.sanitizer, t.multiView.maxPanels), _ = Un({ iframeHosts: t.iframeHosts, dataPath: t.dataPath, options: N, pool: Bn(Cn(), N) }), z = new Map(n.map((o) => [o.id, o])), O = kr(t), { authenticate: P, principalKey: B, signedOutPage: H, forbiddenPage: p, onTreeRefreshed: g } = e, E = (o, u) => {
776
+ const y = e.editMaxBytes === void 0 ? et : fe("editMaxBytes", e.editMaxBytes, tt), k = Eo(e.treeCache), v = () => Date.now(), L = k === !1 ? Yn(v) : Gn({ ...k, now: v }), A = Cn(e.sanitizer, t.multiView.maxPanels), R = Xn({ iframeHosts: t.iframeHosts, dataPath: t.dataPath, options: A, pool: Hn(Bn(), A) }), z = new Map(n.map((o) => [o.id, o])), _ = Or(t), { authenticate: I, principalKey: D, signedOutPage: H, forbiddenPage: p, onTreeRefreshed: g } = e, E = (o, u) => {
777
777
  if (typeof o.label == "string") return o.label;
778
778
  const s = o.label(u);
779
779
  if (typeof s != "string" || s.trim() === "") throw new TypeError(`[markdown-explorer] the label of source ${JSON.stringify(o.id)} must be a non-blank string`);
780
780
  return s;
781
- }, R = (o, u) => o.cacheScope === "shared" ? o.id : `${o.id}\0${u}`, k = (o, u) => {
781
+ }, O = (o, u) => o.cacheScope === "shared" ? o.id : `${o.id}\0${u}`, T = (o, u) => {
782
782
  const s = (l) => oe(c, { operation: "boundary", sourceId: o.id, path: u, error: l });
783
783
  let d;
784
784
  try {
@@ -786,8 +786,8 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
786
786
  } catch (l) {
787
787
  return s(l), !1;
788
788
  }
789
- return typeof d == "boolean" ? d : (Ze(d, s), s(new TypeError(`[markdown-explorer] boundary.contains of source ${JSON.stringify(o.id)} must return a boolean; got ${typeof d}`)), !1);
790
- }, A = async (o, u, s) => {
789
+ return typeof d == "boolean" ? d : (qe(d, s), s(new TypeError(`[markdown-explorer] boundary.contains of source ${JSON.stringify(o.id)} must return a boolean; got ${typeof d}`)), !1);
790
+ }, N = async (o, u, s) => {
791
791
  const { confirm: d } = o.boundary;
792
792
  if (d === void 0) return { status: "inside", readPath: s };
793
793
  let l;
@@ -798,27 +798,27 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
798
798
  }
799
799
  const f = (F) => (oe(c, { operation: "boundary", sourceId: o.id, path: s, error: new TypeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} ${F}`) }), { status: "outside" });
800
800
  if (l === null || typeof l != "object") return f(`must resolve to { inside, readPath? }; got ${l === null ? "null" : typeof l}`);
801
- const { inside: b, readPath: I } = l;
802
- return b === !1 ? { status: "outside" } : b !== !0 || typeof I != "string" ? f("must resolve to { inside: false } or { inside: true, readPath: string }") : !q(I) || m.deniesPath(I) ? (oe(c, { operation: "boundary", sourceId: o.id, path: s, error: new RangeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} answered a readPath the explorer does not serve (unacceptable or denied)`) }), { status: "error", failure: { reason: "failed" } }) : { status: "inside", readPath: I };
801
+ const { inside: b, readPath: P } = l;
802
+ return b === !1 ? { status: "outside" } : b !== !0 || typeof P != "string" ? f("must resolve to { inside: false } or { inside: true, readPath: string }") : !q(P) || m.deniesPath(P) ? (oe(c, { operation: "boundary", sourceId: o.id, path: s, error: new RangeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} answered a readPath the explorer does not serve (unacceptable or denied)`) }), { status: "error", failure: { reason: "failed" } }) : { status: "inside", readPath: P };
803
803
  }, M = async (o, u) => {
804
- const s = n.filter((l) => k(l, u));
804
+ const s = n.filter((l) => T(l, u));
805
805
  if (s.length === 0) return { status: "error", failure: { reason: "forbidden" } };
806
806
  if (s.some((l) => l.boundary.confirm === void 0)) return { status: "inside", readPath: u };
807
807
  let d = null;
808
808
  for (const l of s) {
809
- const f = await A(l, o, u);
809
+ const f = await N(l, o, u);
810
810
  if (f.status === "inside") return f;
811
811
  f.status === "error" && d === null && (d = f.failure);
812
812
  }
813
813
  return { status: "error", failure: d === null ? { reason: "forbidden" } : d };
814
814
  }, U = (o, u, s) => {
815
- const d = ({ path: l, reason: f }) => dn(c, { operation: s.operation, sourceId: s.sourceId, path: l, error: new TypeError(`[markdown-explorer] an entry with ${f} was left out`) });
815
+ const d = ({ path: l, reason: f }) => ln(c, { operation: s.operation, sourceId: s.sourceId, path: l, error: new TypeError(`[markdown-explorer] an entry with ${f} was left out`) });
816
816
  try {
817
- return { status: "ok", entries: Kn(o, m, u.children !== void 0, d, (l) => k(u, l)) };
817
+ return { status: "ok", entries: Vn(o, m, u.children !== void 0, d, (l) => T(u, l)) };
818
818
  } catch (l) {
819
819
  return oe(c, { ...s, error: l }), { status: "error", failure: { reason: "failed" } };
820
820
  }
821
- }, L = async (o, u, s) => {
821
+ }, $ = async (o, u, s) => {
822
822
  let d;
823
823
  try {
824
824
  d = await o.tree(u);
@@ -827,17 +827,17 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
827
827
  }
828
828
  const l = U(d, o, { operation: "tree", sourceId: o.id });
829
829
  return l.status === "ok" ? { status: "ok", entries: l.entries, loadedAt: s } : l;
830
- }, X = (o, u, s, d) => (l, f) => L(o, { principal: u, request: s, signal: l, refresh: d }, f), V = (o, u, s, d, l) => $.load(R(o, s), l, X(o, u, d, !1)), J = (o, u, s, d) => $.refresh(R(o, s), d.signal, X(o, u, d, !0)), se = (o, u) => {
830
+ }, X = (o, u, s, d) => (l, f) => $(o, { principal: u, request: s, signal: l, refresh: d }, f), V = (o, u, s, d, l) => L.load(O(o, s), l, X(o, u, d, !1)), J = (o, u, s, d) => L.refresh(O(o, s), d.signal, X(o, u, d, !0)), se = (o, u) => {
831
831
  if (g === void 0) return;
832
832
  const s = (d) => oe(c, { operation: "refresh", sourceId: o.id, error: d });
833
833
  try {
834
- Ze(g(u), s);
834
+ qe(g(u), s);
835
835
  } catch (d) {
836
836
  s(d);
837
837
  }
838
- }, D = async (o, u, s, d) => {
839
- if (m.deniesPath(d) || !k(o, d)) return { status: "error", failure: { reason: "forbidden" } };
840
- const l = await A(o, s, d);
838
+ }, C = async (o, u, s, d) => {
839
+ if (m.deniesPath(d) || !T(o, d)) return { status: "error", failure: { reason: "forbidden" } };
840
+ const l = await N(o, s, d);
841
841
  if (l.status === "outside") return { status: "error", failure: { reason: "forbidden" } };
842
842
  if (l.status === "error") return { status: "error", failure: l.failure };
843
843
  let f;
@@ -848,7 +848,7 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
848
848
  }
849
849
  return U(f, o, { operation: "children", sourceId: o.id, path: d });
850
850
  }, Z = async (o, u, s, d) => {
851
- const l = await A(o, s, d);
851
+ const l = await N(o, s, d);
852
852
  if (l.status === "outside") return { status: "ok", ancestors: null };
853
853
  if (l.status === "error") return { status: "error", failure: l.failure };
854
854
  let f;
@@ -859,229 +859,229 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
859
859
  }
860
860
  if (Array.isArray(f) && f.length > t.revealDocument.maxDepth) return { status: "ok", ancestors: null };
861
861
  try {
862
- return { status: "ok", ancestors: Wn(f, d, m, (b) => k(o, b)) };
862
+ return { status: "ok", ancestors: Kn(f, d, m, (b) => T(o, b)) };
863
863
  } catch (b) {
864
864
  return oe(c, { operation: "ancestors", sourceId: o.id, path: d, error: b }), { status: "error", failure: { reason: "failed" } };
865
865
  }
866
- }, ee = async (o, u, s, d) => m.deniesPath(d) ? { status: "error", failure: { reason: "forbidden" } } : k(o, d) ? Z(o, u, s, d) : { status: "ok", ancestors: null }, te = async (o, u, s) => {
866
+ }, ee = async (o, u, s, d) => m.deniesPath(d) ? { status: "error", failure: { reason: "forbidden" } } : T(o, d) ? Z(o, u, s, d) : { status: "ok", ancestors: null }, te = async (o, u, s) => {
867
867
  if (m.deniesPath(s)) return { status: "error", failure: { reason: "forbidden" } };
868
868
  for (const d of [o, ...n.filter((l) => l !== o)]) {
869
869
  if (u.signal.aborted) break;
870
870
  const l = d.ancestors;
871
- if (l === void 0 || !k(d, s)) continue;
871
+ if (l === void 0 || !T(d, s)) continue;
872
872
  const f = await Z(d, l, u, s);
873
873
  if (f.status === "ok" && f.ancestors !== null) return { status: "ok", source: d.id, ancestors: f.ancestors };
874
874
  }
875
- return fo;
876
- }, me = async (o, u, s) => {
875
+ return mo;
876
+ }, ie = async (o, u, s) => {
877
877
  if (m.deniesPath(s)) return Q("forbidden");
878
878
  const d = await M(o, s);
879
879
  if (d.status === "error") return { kind: "failure", failure: d.failure };
880
880
  let l;
881
881
  try {
882
882
  l = await e.document(o, s, d.readPath);
883
- } catch (I) {
884
- return { kind: "failure", failure: G(I, { operation: "document", path: s }, o.signal, c) };
883
+ } catch (P) {
884
+ return { kind: "failure", failure: G(P, { operation: "document", path: s }, o.signal, c) };
885
885
  }
886
886
  let f;
887
887
  try {
888
- f = qn(l, (I) => He(t.dataPath, s, I), w !== void 0);
889
- } catch (I) {
890
- return oe(c, { operation: "document", path: s, error: I }), Q("failed");
888
+ f = eo(l, (P) => Fe(t.dataPath, s, P), w !== void 0);
889
+ } catch (P) {
890
+ return oe(c, { operation: "document", path: s, error: P }), Q("failed");
891
891
  }
892
892
  if (f.kind !== "unsanitized-markdown") return f;
893
- const b = await _(f.html, { scope: u, signal: o.signal });
893
+ const b = await R(f.html, { scope: u, signal: o.signal });
894
894
  return b.status === "sanitized" ? { kind: "markdown", name: f.name, htmlContent: b.html, headings: f.headings, edit: f.edit } : (b.cause !== null && oe(c, { operation: "document", path: s, error: b.cause }), Q(b.reason));
895
- }, Ht = async (o) => {
896
- if (e.notices === void 0) return Ae;
895
+ }, ye = async (o) => {
896
+ if (e.notices === void 0) return Ie;
897
897
  try {
898
- return io(await e.notices(o));
898
+ return ao(await e.notices(o));
899
899
  } catch (u) {
900
- return G(u, { operation: "notices" }, o.signal, c), Ae;
900
+ return G(u, { operation: "notices" }, o.signal, c), Ie;
901
901
  }
902
- }, Ft = async (o, u, s) => {
903
- const d = ae(u, ie.path);
902
+ }, Jt = async (o, u, s) => {
903
+ const d = ce(u, ae.path);
904
904
  if (d === null || !q(d)) return j({ reason: "invalid" }, s);
905
- const l = wr(u);
905
+ const l = gr(u);
906
906
  if (l === null) return j({ reason: "invalid" }, s);
907
907
  if (m.deniesPath(d))
908
- return ve(c, { operation: "asset", path: d }), j({ reason: "forbidden" }, s);
908
+ return _e(c, { operation: "asset", path: d }), j({ reason: "forbidden" }, s);
909
909
  const f = await M(o, d);
910
910
  if (f.status === "error") return j(f.failure, s);
911
911
  try {
912
- const b = st(await e.asset(o, d, f.readPath));
913
- return await sn(o.request, b, s, l);
912
+ const b = at(await e.asset(o, d, f.readPath));
913
+ return await an(o.request, b, s, l);
914
914
  } catch (b) {
915
915
  return j(G(b, { operation: "asset", path: d }, o.signal, c), s);
916
916
  }
917
- }, Ut = async (o, u) => {
917
+ }, Gt = async (o, u) => {
918
918
  if (m.deniesPath(u))
919
- return ve(c, { operation: "text", path: u }), Q("forbidden");
919
+ return _e(c, { operation: "text", path: u }), Q("forbidden");
920
920
  const s = await M(o, u);
921
921
  if (s.status === "error") return { kind: "failure", failure: s.failure };
922
922
  try {
923
- const d = st(await e.asset(o, u, s.readPath)), l = await fn(d, S);
924
- return l === null ? Q("unsupported") : { kind: "text", name: d.name, text: l.text, truncated: l.truncated, url: He(t.dataPath, u, d.version) };
923
+ const d = at(await e.asset(o, u, s.readPath)), l = await mn(d, S);
924
+ return l === null ? Q("unsupported") : { kind: "text", name: d.name, text: l.text, truncated: l.truncated, url: Fe(t.dataPath, u, d.version) };
925
925
  } catch (d) {
926
926
  return { kind: "failure", failure: G(d, { operation: "text", path: u }, o.signal, c) };
927
927
  }
928
- }, pe = async (o, u, s) => m.deniesPath(s) ? (ve(c, { operation: u, path: s }), { status: "error", failure: { reason: "forbidden" } }) : M(o, s), Xt = async (o, u, s) => {
928
+ }, pe = async (o, u, s) => m.deniesPath(s) ? (_e(c, { operation: u, path: s }), { status: "error", failure: { reason: "forbidden" } }) : M(o, s), Yt = async (o, u, s) => {
929
929
  const d = await pe(u, "edit", s);
930
930
  if (d.status === "error") return { kind: "failure", failure: d.failure };
931
931
  try {
932
- return to(await o.source(u, s, d.readPath), y);
932
+ return ro(await o.source(u, s, d.readPath), y);
933
933
  } catch (l) {
934
934
  return { kind: "failure", failure: G(l, { operation: "edit", path: s }, u.signal, c) };
935
935
  }
936
- }, Jt = async (o, u, s, d, l) => {
936
+ }, Wt = async (o, u, s, d, l) => {
937
937
  const f = await pe(u, "save", s);
938
938
  if (f.status === "error") return { kind: "failure", failure: f.failure };
939
939
  try {
940
- return ro(await o.save(u, s, f.readPath, { text: l, baseVersion: d }), y);
940
+ return no(await o.save(u, s, f.readPath, { text: l, baseVersion: d }), y);
941
941
  } catch (b) {
942
942
  return { kind: "failure", failure: G(b, { operation: "save", path: s }, u.signal, c) };
943
943
  }
944
- }, Gt = async (o, u, s, d, l) => {
944
+ }, Kt = async (o, u, s, d, l) => {
945
945
  const f = await pe(u, "preview", d);
946
946
  if (f.status === "error") return { kind: "failure", failure: f.failure };
947
947
  let b;
948
948
  try {
949
- b = no(await o.preview(u, d, f.readPath, l));
949
+ b = oo(await o.preview(u, d, f.readPath, l));
950
950
  } catch (F) {
951
951
  return { kind: "failure", failure: G(F, { operation: "preview", path: d }, u.signal, c) };
952
952
  }
953
953
  if ("kind" in b) return b.kind === "failure" ? b : Q("failed");
954
- const I = await _(b.html, { scope: s, signal: u.signal });
955
- return I.status === "sanitized" ? { kind: "preview", htmlContent: I.html, headings: b.headings } : (I.cause !== null && oe(c, { operation: "preview", path: d, error: I.cause }), Q(I.reason));
956
- }, Yt = async (o, u, s) => {
954
+ const P = await R(b.html, { scope: s, signal: u.signal });
955
+ return P.status === "sanitized" ? { kind: "preview", htmlContent: P.html, headings: b.headings } : (P.cause !== null && oe(c, { operation: "preview", path: d, error: P.cause }), Q(P.reason));
956
+ }, Vt = async (o, u, s) => {
957
957
  const d = await pe(u, "revisions", s);
958
958
  if (d.status === "error") return { kind: "failure", failure: d.failure };
959
959
  try {
960
- return { kind: "revisions", revisions: oo(await o.revisions(u, s, d.readPath)) };
960
+ return { kind: "revisions", revisions: so(await o.revisions(u, s, d.readPath)) };
961
961
  } catch (l) {
962
962
  return { kind: "failure", failure: G(l, { operation: "revisions", path: s }, u.signal, c) };
963
963
  }
964
- }, Wt = async (o, u, s, d) => {
964
+ }, Zt = async (o, u, s, d) => {
965
965
  const l = await pe(u, "revision", s);
966
966
  if (l.status === "error") return { kind: "failure", failure: l.failure };
967
967
  try {
968
- return { kind: "revision", id: d, text: so(await o.revision(u, s, l.readPath, d), y) };
968
+ return { kind: "revision", id: d, text: io(await o.revision(u, s, l.readPath, d), y) };
969
969
  } catch (f) {
970
970
  return { kind: "failure", failure: G(f, { operation: "revision", path: s }, u.signal, c) };
971
971
  }
972
- }, Kt = async (o, u, s, d, l, f) => {
973
- const b = ae(l, ie.path);
972
+ }, Qt = async (o, u, s, d, l, f) => {
973
+ const b = ce(l, ae.path);
974
974
  if (b === null || !q(b)) return j({ reason: "invalid" }, f);
975
- if (u === "edit") return W(200, JSON.stringify(await Xt(o, s, b)), f);
976
- if (u === "revisions") return W(200, JSON.stringify(await Yt(o, s, b)), f);
975
+ if (u === "edit") return W(200, JSON.stringify(await Yt(o, s, b)), f);
976
+ if (u === "revisions") return W(200, JSON.stringify(await Vt(o, s, b)), f);
977
977
  if (u === "revision") {
978
- const re = ae(l, ie.revision);
979
- return he(re) ? W(200, JSON.stringify(await Wt(o, s, b, re)), f) : j({ reason: "invalid" }, f);
978
+ const re = ce(l, ae.revision);
979
+ return he(re) ? W(200, JSON.stringify(await Zt(o, s, b, re)), f) : j({ reason: "invalid" }, f);
980
980
  }
981
- const I = ae(l, ie.base);
982
- if (u === "save" && !he(I)) return j({ reason: "invalid" }, f);
983
- const F = await So(s.request, y);
984
- return F.status === "error" ? j(F.failure, f) : u === "preview" ? W(200, JSON.stringify(await Gt(o, s, d, b, F.text)), f) : W(200, JSON.stringify(await Jt(o, s, b, I, F.text)), f);
985
- }, Vt = async ({ request: o, url: u, params: s }) => {
986
- const d = lt(await P(o, ct)), l = ut(d.headers);
987
- if (l.set("Cache-Control", Lt), d.status === "signed-out") throw ft("signedOutPage", H(o, l));
988
- if (d.status === "forbidden") throw p === void 0 ? Fe(null, { status: 403, headers: l }) : ft("forbiddenPage", p(o, l));
989
- const f = Or(a, s["*"], u.searchParams);
990
- if (f.kind === "redirect") throw br(f.href, { headers: l });
991
- const { location: b } = f, { principal: I } = d, F = mt(r, B(I)), re = z.get(b.source);
981
+ const P = ce(l, ae.base);
982
+ if (u === "save" && !he(P)) return j({ reason: "invalid" }, f);
983
+ const F = await xo(s.request, y);
984
+ return F.status === "error" ? j(F.failure, f) : u === "preview" ? W(200, JSON.stringify(await Kt(o, s, d, b, F.text)), f) : W(200, JSON.stringify(await Wt(o, s, b, P, F.text)), f);
985
+ }, qt = async ({ request: o, url: u, params: s }) => {
986
+ const d = mt(await I(o, dt)), l = lt(d.headers);
987
+ if (l.set("Cache-Control", Dt), d.status === "signed-out") throw pt("signedOutPage", H(o, l));
988
+ if (d.status === "forbidden") throw p === void 0 ? Ue(null, { status: 403, headers: l }) : pt("forbiddenPage", p(o, l));
989
+ const f = _r(a, s["*"], u.searchParams);
990
+ if (f.kind === "redirect") throw Sr(f.href, { headers: l });
991
+ const { location: b } = f, { principal: P } = d, F = wt(r, D(P)), re = z.get(b.source);
992
992
  if (re === void 0) throw new RangeError(`[markdown-explorer] no source for ${JSON.stringify(b.source)}`);
993
993
  const we = { signal: o.signal, timeoutMs: h, late: null, handOverMs: h }, ne = {
994
994
  scope: F,
995
- sources: n.map((C) => ({ id: C.id, label: E(C, I) })),
996
- settings: Rr(vr(o.headers.get("Cookie"), t.settingsCookie), O),
995
+ sources: n.map((B) => ({ id: B.id, label: E(B, P) })),
996
+ settings: Ar(Nr(o.headers.get("Cookie"), t.settingsCookie), _),
997
997
  tree: b.view === "single" ? null : {
998
998
  sourceId: b.source,
999
- result: Re(we, (C) => V(re, I, F, o, C).then((Y) => Y.result))
999
+ result: ve(we, (B) => V(re, P, F, o, B).then((Y) => Y.result))
1000
1000
  },
1001
- documents: Eo(b).map((C) => ({ path: C, document: Re(we, (Y) => me({ principal: I, request: o, signal: Y, refresh: !1 }, F, C)) })),
1002
- notices: Re({ signal: o.signal, timeoutMs: h, late: Ae, handOverMs: 0 }, (C) => Ht({ principal: I, request: o, signal: C, refresh: !1 }))
1001
+ documents: bo(b).map((B) => ({ path: B, document: ve(we, (Y) => ie({ principal: P, request: o, signal: Y, refresh: !1 }, F, B)) })),
1002
+ notices: ve({ signal: o.signal, timeoutMs: h, late: Ie, handOverMs: 0 }, (B) => ye({ principal: P, request: o, signal: B, refresh: !1 }))
1003
1003
  };
1004
- return Fe(ne, { headers: l });
1005
- }, ze = async (o, u) => {
1006
- const s = lt(await P(o, u));
1007
- return { authentication: s, headers: ut(s.headers) };
1008
- }, Zt = async (o, u, s) => {
1004
+ return Ue(ne, { headers: l });
1005
+ }, De = async (o, u) => {
1006
+ const s = mt(await I(o, u));
1007
+ return { authentication: s, headers: lt(s.headers) };
1008
+ }, er = async (o, u, s) => {
1009
1009
  let d;
1010
1010
  try {
1011
- d = await ze(u, ct);
1011
+ d = await De(u, dt);
1012
1012
  } catch (Y) {
1013
- return j(G(dt(Y), { operation: "authenticate" }, u.signal, c));
1013
+ return j(G(ft(Y), { operation: "authenticate" }, u.signal, c));
1014
1014
  }
1015
1015
  const { authentication: l, headers: f } = d;
1016
1016
  if (l.status === "signed-out") return j({ reason: "unauthorized" }, f);
1017
1017
  if (l.status === "forbidden") return j({ reason: "forbidden" }, f);
1018
1018
  const { principal: b } = l;
1019
- if (o === "asset") return Ft({ principal: b, request: u, signal: u.signal, refresh: !1 }, s, f);
1020
- const I = mt(r, B(b));
1021
- f.set(pr, I);
1019
+ if (o === "asset") return Jt({ principal: b, request: u, signal: u.signal, refresh: !1 }, s, f);
1020
+ const P = wt(r, D(b));
1021
+ f.set(yr, P);
1022
1022
  const F = { principal: b, request: u, signal: u.signal, refresh: !1 }, re = () => j({ reason: "invalid" }, f);
1023
1023
  if (o === "document") {
1024
- const Y = ae(s, ie.path);
1024
+ const Y = ce(s, ae.path);
1025
1025
  if (Y === null || !q(Y)) return re();
1026
- const Be = u.headers.has(Me);
1027
- return Be && !wt(u) ? j({ reason: "forbidden" }, f) : W(200, JSON.stringify(await me({ ...F, refresh: Be }, I, Y)), f);
1026
+ const He = u.headers.has($e);
1027
+ return He && !yt(u) ? j({ reason: "forbidden" }, f) : W(200, JSON.stringify(await ie({ ...F, refresh: He }, P, Y)), f);
1028
1028
  }
1029
1029
  if (o === "text") {
1030
- const Y = ae(s, ie.path);
1031
- return Y === null || !q(Y) ? re() : W(200, JSON.stringify(await Ut(F, Y)), f);
1030
+ const Y = ce(s, ae.path);
1031
+ return Y === null || !q(Y) ? re() : W(200, JSON.stringify(await Gt(F, Y)), f);
1032
1032
  }
1033
1033
  if (o === "edit" || o === "save" || o === "preview" || o === "revisions" || o === "revision")
1034
- return w === void 0 ? j({ reason: "not-found" }, f) : Kt(w, o, F, I, s, f);
1035
- const we = ae(s, ie.source), ne = ae(s, ie.path);
1034
+ return w === void 0 ? j({ reason: "not-found" }, f) : Qt(w, o, F, P, s, f);
1035
+ const we = ce(s, ae.source), ne = ce(s, ae.path);
1036
1036
  if (we === null || (o === "children" || o === "ancestors" || o === "reveal") && (ne === null || !q(ne))) return re();
1037
- const C = z.get(we);
1038
- if (C === void 0) return j({ reason: "not-found" }, f);
1039
- if (o === "tree") return W(200, (await V(C, b, I, u, u.signal)).json, f);
1037
+ const B = z.get(we);
1038
+ if (B === void 0) return j({ reason: "not-found" }, f);
1039
+ if (o === "tree") return W(200, (await V(B, b, P, u, u.signal)).json, f);
1040
1040
  if (o === "refresh") {
1041
- const Y = await J(C, b, I, u);
1042
- return u.signal.aborted || se(C, R(C, I)), W(200, Y.json, f);
1041
+ const Y = await J(B, b, P, u);
1042
+ return u.signal.aborted || se(B, O(B, P)), W(200, Y.json, f);
1043
1043
  }
1044
- return o === "ancestors" ? C.ancestors === void 0 || ne === null ? j({ reason: "not-found" }, f) : W(200, JSON.stringify(await ee(C, C.ancestors, F, ne)), f) : o === "reveal" ? ne === null ? re() : W(200, JSON.stringify(await te(C, F, ne)), f) : C.children === void 0 || ne === null ? j({ reason: "not-found" }, f) : W(200, JSON.stringify(await D(C, C.children, F, ne)), f);
1045
- }, Qt = async (o) => {
1046
- const { authentication: u, headers: s } = await ze(o, mo);
1044
+ return o === "ancestors" ? B.ancestors === void 0 || ne === null ? j({ reason: "not-found" }, f) : W(200, JSON.stringify(await ee(B, B.ancestors, F, ne)), f) : o === "reveal" ? ne === null ? re() : W(200, JSON.stringify(await te(B, F, ne)), f) : B.children === void 0 || ne === null ? j({ reason: "not-found" }, f) : W(200, JSON.stringify(await C(B, B.children, F, ne)), f);
1045
+ }, tr = async (o) => {
1046
+ const { authentication: u, headers: s } = await De(o, po);
1047
1047
  if (!s.keys().next().done) throw new TypeError("[markdown-explorer] authenticate returned headers in read-only mode; a read-only authentication must only read the session (none was forwarded)");
1048
1048
  return u.status === "signed-in";
1049
- }, De = t.embeds.linkCardEndpoint === null ? null : Er({ authorize: Qt }), qt = async (o, u) => {
1049
+ }, Ce = t.embeds.linkCardEndpoint === null ? null : kr({ authorize: tr }), rr = async (o, u) => {
1050
1050
  try {
1051
1051
  return await o(u);
1052
1052
  } catch (s) {
1053
- return j(G(dt(s), { operation: "authenticate" }, u.signal, c));
1053
+ return j(G(ft(s), { operation: "authenticate" }, u.signal, c));
1054
1054
  }
1055
- }, Ce = async (o, u, s) => {
1055
+ }, Be = async (o, u, s) => {
1056
1056
  if (new URL(o.url).pathname.endsWith(".data")) return j({ reason: "not-found" });
1057
- if (!dr(s)) return j({ reason: "not-found" });
1057
+ if (!mr(s)) return j({ reason: "not-found" });
1058
1058
  if (s === "link-card") {
1059
- if (De === null) return j({ reason: "not-found" });
1060
- const l = pt(o, s);
1061
- return l !== null ? l : qt(De, o);
1059
+ if (Ce === null) return j({ reason: "not-found" });
1060
+ const l = ht(o, s);
1061
+ return l !== null ? l : rr(Ce, o);
1062
1062
  }
1063
- if (To.has(s) && w === void 0) return j({ reason: "not-found" });
1064
- const d = pt(o, s);
1063
+ if (ko.has(s) && w === void 0) return j({ reason: "not-found" });
1064
+ const d = ht(o, s);
1065
1065
  if (d !== null) return d;
1066
- if (s === "refresh" && !wt(o)) return j({ reason: "forbidden" });
1067
- if ((s === "save" || s === "preview") && !ko(o)) return j({ reason: "forbidden" });
1066
+ if (s === "refresh" && !yt(o)) return j({ reason: "forbidden" });
1067
+ if ((s === "save" || s === "preview") && !So(o)) return j({ reason: "forbidden" });
1068
1068
  try {
1069
- return await Zt(s, o, u.searchParams);
1069
+ return await er(s, o, u.searchParams);
1070
1070
  } catch (l) {
1071
1071
  return j(G(l, { operation: s }, o.signal, c));
1072
1072
  }
1073
1073
  };
1074
1074
  return Object.freeze({
1075
- loader: Vt,
1076
- headers: Oo,
1077
- dataLoader: ({ request: o, url: u, params: s }) => Ce(o, u, s["*"]),
1078
- dataAction: ({ request: o, url: u, params: s }) => Ce(o, u, s["*"]),
1075
+ loader: qt,
1076
+ headers: Ro,
1077
+ dataLoader: ({ request: o, url: u, params: s }) => Be(o, u, s["*"]),
1078
+ dataAction: ({ request: o, url: u, params: s }) => Be(o, u, s["*"]),
1079
1079
  forgetTree: (o) => {
1080
1080
  if (typeof o != "string") throw new TypeError(`[markdown-explorer] forgetTree needs the string key onTreeRefreshed received; got ${typeof o}`);
1081
- $.forget(o);
1081
+ L.forget(o);
1082
1082
  }
1083
1083
  });
1084
- }, Ee = Object.freeze({ maxEntries: 2e4, maxDocumentBytes: 2 * 1024 * 1024, textPreviewBytes: 8 * 1024, walkConcurrency: 8 }), Ro = /* @__PURE__ */ new Set(["md", "markdown", "mdx"]), jt = new Map([
1084
+ }, be = Object.freeze({ maxEntries: 2e4, maxDocumentBytes: 2 * 1024 * 1024, textPreviewBytes: 8 * 1024, walkConcurrency: 8 }), vo = /* @__PURE__ */ new Set(["md", "markdown", "mdx"]), Ct = new Map([
1085
1085
  ...[
1086
1086
  ["png", "image/png"],
1087
1087
  ["jpg", "image/jpeg"],
@@ -1116,7 +1116,7 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
1116
1116
  ["wma", "audio/x-ms-wma"]
1117
1117
  ].map(([e, t]) => [e, { kind: "media", mediaType: "audio", contentType: t }]),
1118
1118
  ["pdf", { kind: "media", mediaType: "pdf", contentType: "application/pdf" }]
1119
- ]), vo = /* @__PURE__ */ new Set([
1119
+ ]), _o = /* @__PURE__ */ new Set([
1120
1120
  "txt",
1121
1121
  "text",
1122
1122
  "log",
@@ -1241,7 +1241,7 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
1241
1241
  "eslintrc",
1242
1242
  "babelrc",
1243
1243
  "mailmap"
1244
- ]), _o = /* @__PURE__ */ new Set([
1244
+ ]), Ao = /* @__PURE__ */ new Set([
1245
1245
  "readme",
1246
1246
  "license",
1247
1247
  "licence",
@@ -1262,17 +1262,17 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
1262
1262
  "jenkinsfile",
1263
1263
  "brewfile",
1264
1264
  "codeowners"
1265
- ]), zt = typeof fe.O_NOFOLLOW == "number" ? fe.O_NOFOLLOW : 0, Dt = typeof fe.O_NONBLOCK == "number" ? fe.O_NONBLOCK : 0, ht = (e) => `${e.size}-${e.mtimeNs}`, No = (e) => e !== "" && e !== "." && e !== ".." && !e.includes(":") && !e.endsWith(".") && !e.endsWith(" "), yt = (e) => q(e) && e === e.normalize("NFC") && e.split("/").every(No), Ct = (e) => {
1265
+ ]), Bt = typeof me.O_NOFOLLOW == "number" ? me.O_NOFOLLOW : 0, Ht = typeof me.O_NONBLOCK == "number" ? me.O_NONBLOCK : 0, gt = (e) => `${e.size}-${e.mtimeNs}`, No = (e) => e !== "" && e !== "." && e !== ".." && !e.includes(":") && !e.endsWith(".") && !e.endsWith(" "), Et = (e) => q(e) && e === e.normalize("NFC") && e.split("/").every(No), Ft = (e) => {
1266
1266
  const t = e.toLowerCase(), r = t.lastIndexOf(".");
1267
1267
  return r < 0 ? "" : t.slice(r + 1);
1268
- }, Ao = (e) => {
1269
- const t = Ct(e);
1270
- if (Ro.has(t)) return { kind: "markdown" };
1271
- const r = jt.get(t);
1268
+ }, Io = (e) => {
1269
+ const t = Ft(e);
1270
+ if (vo.has(t)) return { kind: "markdown" };
1271
+ const r = Ct.get(t);
1272
1272
  if (r !== void 0) return r.kind === "image" ? { kind: "image" } : { kind: "media", mediaType: r.mediaType };
1273
1273
  const n = e.toLowerCase();
1274
- return vo.has(t) || !n.includes(".") && _o.has(n) ? { kind: "text" } : { kind: "file" };
1275
- }, Pe = (e) => {
1274
+ return _o.has(t) || !n.includes(".") && Ao.has(n) ? { kind: "text" } : { kind: "file" };
1275
+ }, Me = (e) => {
1276
1276
  switch (typeof e == "object" && e !== null ? e.code : void 0) {
1277
1277
  case "ENOENT":
1278
1278
  case "ENOTDIR":
@@ -1288,34 +1288,41 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
1288
1288
  default:
1289
1289
  return null;
1290
1290
  }
1291
- }, Bt = (e) => {
1292
- const t = Pe(e);
1293
- return t === null ? e : new ke(t);
1294
- }, Io = (e) => {
1291
+ }, Ut = (e) => {
1292
+ const t = Me(e);
1293
+ return t === null ? e : new Se(t);
1294
+ }, Xt = (e) => {
1295
1295
  const t = typeof e == "object" && e !== null ? e.code : void 0;
1296
1296
  return t === "EACCES" || t === "EPERM" || t === "ENOENT" || t === "ENOTDIR";
1297
- }, gt = async (e, t) => {
1297
+ }, Po = async (e) => {
1298
+ try {
1299
+ return Math.trunc((await vt(e)).mtimeMs);
1300
+ } catch (t) {
1301
+ if (Xt(t)) return;
1302
+ throw t;
1303
+ }
1304
+ }, bt = async (e, t) => {
1298
1305
  const r = [];
1299
1306
  for await (const n of e.createReadStream({ start: 0, end: t - 1, autoClose: !1 }))
1300
1307
  r.push(n);
1301
1308
  return Buffer.concat(r);
1302
- }, Po = (e, t) => e !== null ? { start: e.offset, end: e.offset + e.length - 1 } : t === 0n ? {} : { start: 0, end: Number(t) - 1 }, Mo = async (e, t, r, n) => {
1309
+ }, Mo = (e, t) => e !== null ? { start: e.offset, end: e.offset + e.length - 1 } : t === 0n ? {} : { start: 0, end: Number(t) - 1 }, $o = async (e, t, r, n) => {
1303
1310
  let a;
1304
1311
  try {
1305
- a = await xt(e, fe.O_RDONLY | zt | Dt);
1312
+ a = await Rt(e, me.O_RDONLY | Bt | Ht);
1306
1313
  const h = await a.stat({ bigint: !0 });
1307
- if (!h.isFile() || h.ino !== t.ino || h.dev !== t.dev || h.size !== t.size || h.mtimeNs !== t.mtimeNs) throw new ke("not-found");
1314
+ if (!h.isFile() || h.ino !== t.ino || h.dev !== t.dev || h.size !== t.size || h.mtimeNs !== t.mtimeNs) throw new Se("not-found");
1308
1315
  } catch (h) {
1309
- throw await a?.close(), Bt(h);
1316
+ throw await a?.close(), Ut(h);
1310
1317
  }
1311
- const i = a.createReadStream(Po(r, t.size)), c = Br.toWeb(i), m = () => {
1318
+ const i = a.createReadStream(Mo(r, t.size)), c = Hr.toWeb(i), m = () => {
1312
1319
  i.destroy(n.reason);
1313
1320
  };
1314
1321
  return n.aborted ? m() : n.addEventListener("abort", m, { once: !0 }), c;
1315
- }, $o = (e, t) => {
1316
- const r = Nr.compare(e, t);
1322
+ }, Lo = (e, t) => {
1323
+ const r = Pr.compare(e, t);
1317
1324
  return r !== 0 ? r : e === t ? 0 : e < t ? -1 : 1;
1318
- }, Lo = (e) => {
1325
+ }, jo = (e) => {
1319
1326
  let t = 0;
1320
1327
  const r = [];
1321
1328
  return async (n) => {
@@ -1327,179 +1334,180 @@ const cn = (e) => e instanceof Error && Object.hasOwn(e, Nt) && Et(e.reason), un
1327
1334
  a === void 0 ? t -= 1 : a();
1328
1335
  }
1329
1336
  };
1330
- }, jo = (e, t) => {
1337
+ }, zo = (e, t) => {
1331
1338
  if (e.isSymbolicLink()) return "symbolic-link";
1332
1339
  if (!(e.isDirectory() || e.isFile())) return "special-file";
1333
1340
  const { name: r } = e;
1334
1341
  return r !== r.normalize("NFC") ? "not-nfc" : r.includes(":") ? "colon" : r.endsWith(".") || r.endsWith(" ") ? "trailing-dot-or-space" : q(r) ? q(t) ? null : "path-too-long" : "control-character-or-backslash";
1335
- }, zo = /* @__PURE__ */ new Set(["id", "label", "root", "pathPrefix", "parse", "deny", "maxEntries", "maxDocumentBytes", "textPreviewBytes", "walkConcurrency", "cacheScope", "reportSkipped"]), be = (e, t, r) => {
1342
+ }, Do = /* @__PURE__ */ new Set(["id", "label", "root", "pathPrefix", "parse", "deny", "maxEntries", "maxDocumentBytes", "textPreviewBytes", "walkConcurrency", "cacheScope", "reportSkipped"]), Te = (e, t, r) => {
1336
1343
  if (t === void 0) return r;
1337
1344
  if (typeof t != "number" || !Number.isSafeInteger(t) || t <= 0) throw new RangeError(`[markdown-explorer] ${e} must be a positive integer; got ${String(t)}`);
1338
1345
  return t;
1339
- }, qo = (e) => {
1346
+ }, es = (e) => {
1340
1347
  if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] createFileSystemSource needs an options object");
1341
1348
  for (const E of Object.keys(e))
1342
- if (!zo.has(E)) throw new TypeError(`[markdown-explorer] createFileSystemSource does not know the option ${JSON.stringify(E)}`);
1349
+ if (!Do.has(E)) throw new TypeError(`[markdown-explorer] createFileSystemSource does not know the option ${JSON.stringify(E)}`);
1343
1350
  const { id: t, label: r, root: n, parse: a } = e;
1344
1351
  if (typeof t != "string" || t === "") throw new TypeError("[markdown-explorer] a file-system source needs a non-empty id");
1345
1352
  if (typeof r != "string" || r.trim() === "") throw new TypeError("[markdown-explorer] a file-system source needs a non-blank label");
1346
1353
  if (typeof a != "function") throw new TypeError("[markdown-explorer] a file-system source needs a parse function");
1347
- if (typeof n != "string" || !Ue(n)) throw new RangeError(`[markdown-explorer] root must be an absolute path; got ${JSON.stringify(n)}`);
1354
+ if (typeof n != "string" || !Xe(n)) throw new RangeError(`[markdown-explorer] root must be an absolute path; got ${JSON.stringify(n)}`);
1348
1355
  let i;
1349
1356
  try {
1350
- i = Ir(n).isDirectory();
1357
+ i = $r(n).isDirectory();
1351
1358
  } catch (E) {
1352
1359
  throw new RangeError(`[markdown-explorer] root does not exist: ${n}`, { cause: E });
1353
1360
  }
1354
1361
  if (!i) throw new RangeError(`[markdown-explorer] root is not a directory: ${n}`);
1355
- const c = Pr(n), m = e.pathPrefix;
1362
+ const c = Lr(n), m = e.pathPrefix;
1356
1363
  if (typeof m != "string") throw new TypeError('[markdown-explorer] pathPrefix is required: "" for a source over the whole root, or relative segments ending with "/"');
1357
- if (m !== "" && !(m.endsWith("/") && yt(m.slice(0, -1))))
1364
+ if (m !== "" && !(m.endsWith("/") && Et(m.slice(0, -1))))
1358
1365
  throw new RangeError(`[markdown-explorer] pathPrefix must be empty or relative segments ending with "/"; got ${JSON.stringify(m)}`);
1359
- const h = Tt(e.deny), S = be("maxEntries", e.maxEntries, Ee.maxEntries), w = be("maxDocumentBytes", e.maxDocumentBytes, Ee.maxDocumentBytes), y = be("textPreviewBytes", e.textPreviewBytes, Ee.textPreviewBytes), T = be("walkConcurrency", e.walkConcurrency, Ee.walkConcurrency), v = e.cacheScope === void 0 ? "principal" : e.cacheScope;
1366
+ const h = St(e.deny), S = Te("maxEntries", e.maxEntries, be.maxEntries), w = Te("maxDocumentBytes", e.maxDocumentBytes, be.maxDocumentBytes), y = Te("textPreviewBytes", e.textPreviewBytes, be.textPreviewBytes), k = Te("walkConcurrency", e.walkConcurrency, be.walkConcurrency), v = e.cacheScope === void 0 ? "principal" : e.cacheScope;
1360
1367
  if (v !== "principal" && v !== "shared") throw new RangeError(`[markdown-explorer] cacheScope must be "principal" or "shared"; got ${JSON.stringify(v)}`);
1361
- const $ = e.reportSkipped;
1362
- if ($ !== void 0 && typeof $ != "function") throw new TypeError("[markdown-explorer] reportSkipped must be a function");
1363
- const N = $ === void 0 ? (E) => {
1368
+ const L = e.reportSkipped;
1369
+ if (L !== void 0 && typeof L != "function") throw new TypeError("[markdown-explorer] reportSkipped must be a function");
1370
+ const A = L === void 0 ? (E) => {
1364
1371
  console.warn(`[markdown-explorer] the file-system source ${JSON.stringify(E.sourceId)} does not list ${JSON.stringify(E.path)}: ${E.reason}`);
1365
- } : $, _ = /* @__PURE__ */ new Set(), z = (E) => {
1366
- const R = Lr(c, ...E.split("/")), k = Xe(c, R);
1367
- return k === "" || k === ".." || k.startsWith(`..${Je}`) || Ue(k) ? null : R;
1368
- }, O = (E, R) => {
1369
- const k = `${R}\0${E}`;
1370
- _.has(k) || _.size >= S || (_.add(k), N({ sourceId: t, path: E, reason: R }));
1371
- }, P = async ({ signal: E }) => {
1372
+ } : L, R = /* @__PURE__ */ new Set(), z = (E) => {
1373
+ const O = zr(c, ...E.split("/")), T = Je(c, O);
1374
+ return T === "" || T === ".." || T.startsWith(`..${Ge}`) || Xe(T) ? null : O;
1375
+ }, _ = (E, O) => {
1376
+ const T = `${O}\0${E}`;
1377
+ R.has(T) || R.size >= S || (R.add(T), A({ sourceId: t, path: E, reason: O }));
1378
+ }, I = async ({ signal: E }) => {
1372
1379
  E.throwIfAborted();
1373
- const R = new AbortController(), k = () => {
1374
- R.abort(E.reason);
1380
+ const O = new AbortController(), T = () => {
1381
+ O.abort(E.reason);
1375
1382
  };
1376
- E.addEventListener("abort", k, { once: !0 });
1377
- const A = Lo(T);
1383
+ E.addEventListener("abort", T, { once: !0 });
1384
+ const N = jo(k);
1378
1385
  let M = 0;
1379
- const U = async (L, X) => {
1380
- const V = await A(async () => {
1381
- R.signal.throwIfAborted();
1386
+ const U = async ($, X) => {
1387
+ const V = await N(async () => {
1388
+ O.signal.throwIfAborted();
1382
1389
  try {
1383
- return await Cr(L, { withFileTypes: !0 });
1384
- } catch (D) {
1385
- if (X === "" || !Io(D)) throw D;
1390
+ return await Br($, { withFileTypes: !0 });
1391
+ } catch (C) {
1392
+ if (X === "" || !Xt(C)) throw C;
1386
1393
  return null;
1387
1394
  }
1388
1395
  });
1389
- if (R.signal.throwIfAborted(), V === null)
1390
- return O(`${m}${X}`, "unreadable-directory"), null;
1396
+ if (O.signal.throwIfAborted(), V === null)
1397
+ return _(`${m}${X}`, "unreadable-directory"), null;
1391
1398
  const J = [];
1392
- for (const D of V) {
1393
- if (h.deniesName(D.name)) continue;
1394
- const Z = X === "" ? D.name : `${X}/${D.name}`, ee = `${m}${Z}`, te = jo(D, ee);
1399
+ for (const C of V) {
1400
+ if (h.deniesName(C.name)) continue;
1401
+ const Z = X === "" ? C.name : `${X}/${C.name}`, ee = `${m}${Z}`, te = zo(C, ee);
1395
1402
  if (te !== null) {
1396
- O(ee, te);
1403
+ _(ee, te);
1397
1404
  continue;
1398
1405
  }
1399
- J.push({ dirent: D, relativePath: Z, path: ee });
1406
+ J.push({ dirent: C, relativePath: Z, path: ee });
1400
1407
  }
1401
- if (M += J.length, M > S) throw new ke("too-large");
1402
- return J.sort((D, Z) => $o(D.dirent.name, Z.dirent.name)), (await Promise.all(
1403
- J.map(async ({ dirent: D, relativePath: Z, path: ee }) => {
1404
- if (!D.isDirectory()) return { name: D.name, path: ee, type: "file" };
1405
- const te = await U($r(L, D.name), Z);
1406
- return te === null ? null : { name: D.name, path: ee, type: "directory", children: te };
1408
+ if (M += J.length, M > S) throw new Se("too-large");
1409
+ return J.sort((C, Z) => Lo(C.dirent.name, Z.dirent.name)), (await Promise.all(
1410
+ J.map(async ({ dirent: C, relativePath: Z, path: ee }) => {
1411
+ const te = await Po(Ye($, C.name)), ie = te === void 0 ? {} : { modifiedAt: te };
1412
+ if (!C.isDirectory()) return { name: C.name, path: ee, type: "file", ...ie };
1413
+ const ye = await U(Ye($, C.name), Z);
1414
+ return ye === null ? null : { name: C.name, path: ee, type: "directory", ...ie, children: ye };
1407
1415
  })
1408
- )).filter((D) => D !== null);
1416
+ )).filter((C) => C !== null);
1409
1417
  };
1410
1418
  try {
1411
- const L = await U(c, "");
1412
- if (L === null) throw new Error("[markdown-explorer] the source's root could not be listed");
1413
- return L;
1414
- } catch (L) {
1415
- throw R.abort(), L;
1419
+ const $ = await U(c, "");
1420
+ if ($ === null) throw new Error("[markdown-explorer] the source's root could not be listed");
1421
+ return $;
1422
+ } catch ($) {
1423
+ throw O.abort(), $;
1416
1424
  } finally {
1417
- E.removeEventListener("abort", k);
1425
+ E.removeEventListener("abort", T);
1418
1426
  }
1419
- }, B = async (E) => {
1427
+ }, D = async (E) => {
1420
1428
  if (!E.startsWith(m)) return { status: "refused", reason: "not-found" };
1421
- const R = E.slice(m.length);
1422
- if (!yt(R)) return { status: "refused", reason: "invalid" };
1423
- if (h.deniesPath(R)) return { status: "refused", reason: "forbidden" };
1424
- const k = z(R);
1425
- if (k === null) return { status: "refused", reason: "forbidden" };
1426
- const A = await zr(k, { bigint: !0 });
1427
- if (A.isSymbolicLink()) return { status: "refused", reason: "forbidden" };
1428
- if (!A.isFile()) return { status: "refused", reason: "unsupported" };
1429
- const M = await Dr(k);
1430
- return M !== k || h.deniesPath(Xe(c, M).split(Je).join("/")) ? { status: "refused", reason: "forbidden" } : { status: "file", target: k, name: R.slice(R.lastIndexOf("/") + 1), stats: A };
1431
- }, H = async (E, R, k) => {
1432
- let A;
1429
+ const O = E.slice(m.length);
1430
+ if (!Et(O)) return { status: "refused", reason: "invalid" };
1431
+ if (h.deniesPath(O)) return { status: "refused", reason: "forbidden" };
1432
+ const T = z(O);
1433
+ if (T === null) return { status: "refused", reason: "forbidden" };
1434
+ const N = await vt(T, { bigint: !0 });
1435
+ if (N.isSymbolicLink()) return { status: "refused", reason: "forbidden" };
1436
+ if (!N.isFile()) return { status: "refused", reason: "unsupported" };
1437
+ const M = await Cr(T);
1438
+ return M !== T || h.deniesPath(Je(c, M).split(Ge).join("/")) ? { status: "refused", reason: "forbidden" } : { status: "file", target: T, name: O.slice(O.lastIndexOf("/") + 1), stats: N };
1439
+ }, H = async (E, O, T) => {
1440
+ let N;
1433
1441
  try {
1434
- const M = await B(k);
1442
+ const M = await D(T);
1435
1443
  if (M.status === "refused") return Q(M.reason);
1436
- const { target: U, name: L, stats: X } = M, V = Ao(L), J = ht(X);
1437
- if (V.kind === "image") return { kind: "image", name: L, version: J };
1438
- if (V.kind === "media") return { kind: "media", name: L, mediaType: V.mediaType, version: J };
1439
- if (V.kind === "file") return { kind: "file", name: L, version: J };
1440
- A = await xt(U, fe.O_RDONLY | zt | Dt);
1441
- const se = await A.stat({ bigint: !0 });
1444
+ const { target: U, name: $, stats: X } = M, V = Io($), J = gt(X);
1445
+ if (V.kind === "image") return { kind: "image", name: $, version: J };
1446
+ if (V.kind === "media") return { kind: "media", name: $, mediaType: V.mediaType, version: J };
1447
+ if (V.kind === "file") return { kind: "file", name: $, version: J };
1448
+ N = await Rt(U, me.O_RDONLY | Bt | Ht);
1449
+ const se = await N.stat({ bigint: !0 });
1442
1450
  if (!se.isFile() || se.ino !== X.ino || se.dev !== X.dev) return Q("forbidden");
1443
1451
  if (V.kind === "markdown") {
1444
1452
  if (se.size > BigInt(w)) return Q("too-large");
1445
- const te = await gt(A, w + 1);
1453
+ const te = await bt(N, w + 1);
1446
1454
  if (te.length > w) return Q("too-large");
1447
- const me = await a(new TextDecoder("utf-8").decode(te), R);
1448
- return { kind: "markdown", name: L, htmlContent: me.htmlContent, headings: me.headings, edit: null };
1455
+ const ie = await a(new TextDecoder("utf-8").decode(te), O);
1456
+ return { kind: "markdown", name: $, htmlContent: ie.htmlContent, headings: ie.headings, edit: null };
1449
1457
  }
1450
- const D = await gt(A, y);
1451
- if (D.includes(0)) return { kind: "file", name: L, version: J };
1452
- const Z = se.size > BigInt(y), ee = new TextDecoder("utf-8").decode(D, { stream: Z });
1453
- return { kind: "text", name: L, text: ee, truncated: Z, version: J };
1458
+ const C = await bt(N, y);
1459
+ if (C.includes(0)) return { kind: "file", name: $, version: J };
1460
+ const Z = se.size > BigInt(y), ee = new TextDecoder("utf-8").decode(C, { stream: Z });
1461
+ return { kind: "text", name: $, text: ee, truncated: Z, version: J };
1454
1462
  } catch (M) {
1455
- const U = Pe(M);
1463
+ const U = Me(M);
1456
1464
  if (U === null) throw M;
1457
1465
  return Q(U);
1458
1466
  } finally {
1459
- await A?.close();
1467
+ await N?.close();
1460
1468
  }
1461
- }, p = async (E, R, k) => {
1462
- let A;
1469
+ }, p = async (E, O, T) => {
1470
+ let N;
1463
1471
  try {
1464
- A = await B(k);
1472
+ N = await D(T);
1465
1473
  } catch (J) {
1466
- throw Bt(J);
1474
+ throw Ut(J);
1467
1475
  }
1468
- if (A.status === "refused") throw new ke(A.reason);
1469
- const { target: M, name: U, stats: L } = A, X = jt.get(Ct(U)), V = X === void 0 ? "" : X.contentType;
1470
- return { name: U, contentType: V, size: Number(L.size), version: ht(L), open: (J) => Mo(M, L, J, E.signal) };
1471
- }, g = async (E, R, k) => {
1472
- let A;
1476
+ if (N.status === "refused") throw new Se(N.reason);
1477
+ const { target: M, name: U, stats: $ } = N, X = Ct.get(Ft(U)), V = X === void 0 ? "" : X.contentType;
1478
+ return { name: U, contentType: V, size: Number($.size), version: gt($), open: (J) => $o(M, $, J, E.signal) };
1479
+ }, g = async (E, O, T) => {
1480
+ let N;
1473
1481
  try {
1474
- A = await B(k);
1475
- } catch (L) {
1476
- if (Pe(L) !== null) return null;
1477
- throw L;
1482
+ N = await D(T);
1483
+ } catch ($) {
1484
+ if (Me($) !== null) return null;
1485
+ throw $;
1478
1486
  }
1479
- if (A.status === "refused") return null;
1480
- const M = k.slice(m.length).split("/");
1481
- if (M.some((L) => h.deniesName(L))) return null;
1487
+ if (N.status === "refused") return null;
1488
+ const M = T.slice(m.length).split("/");
1489
+ if (M.some(($) => h.deniesName($))) return null;
1482
1490
  const U = M.slice(0, -1);
1483
- return U.map((L, X) => `${m}${U.slice(0, X + 1).join("/")}`);
1491
+ return U.map(($, X) => `${m}${U.slice(0, X + 1).join("/")}`);
1484
1492
  };
1485
1493
  return Object.freeze({
1486
1494
  id: t,
1487
1495
  label: r,
1488
1496
  cacheScope: v,
1489
1497
  boundary: Object.freeze({ contains: (E) => E.startsWith(m) }),
1490
- tree: P,
1498
+ tree: I,
1491
1499
  ancestors: g,
1492
1500
  document: H,
1493
1501
  asset: p
1494
1502
  });
1495
1503
  };
1496
1504
  export {
1497
- rs as DEFAULT_DENIED_PATH_SEGMENTS,
1498
- ke as ExplorerError,
1499
- ns as MAX_DOCUMENT_PATH_LENGTH,
1500
- Zo as anonymousAccess,
1501
- qo as createFileSystemSource,
1502
- Qo as createMarkdownExplorer,
1505
+ ns as DEFAULT_DENIED_PATH_SEGMENTS,
1506
+ Se as ExplorerError,
1507
+ os as MAX_DOCUMENT_PATH_LENGTH,
1508
+ Qo as anonymousAccess,
1509
+ es as createFileSystemSource,
1510
+ qo as createMarkdownExplorer,
1503
1511
  q as isAcceptableDocumentPath,
1504
- os as isDeniedPath
1512
+ ss as isDeniedPath
1505
1513
  };