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