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