@aiquants/markdown-explorer 0.21.0 → 0.23.0

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