@aiquants/markdown-explorer 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +10 -2
- package/dist/{ExplorerSplit-CWcK1E4I.js → ExplorerSplit-CN5TvRj6.js} +2 -2
- package/dist/{ExplorerSplit-ajN3GSdA.cjs → ExplorerSplit-CUIbSLQm.cjs} +1 -1
- package/dist/{MultiLayout-DvkcdO9c.cjs → MultiLayout-BDcQSpa6.cjs} +1 -1
- package/dist/{MultiLayout-BtWtCzJV.js → MultiLayout-hPmV-bae.js} +4 -4
- package/dist/{NativeScrollBar-DbzyQ85y.cjs → NativeScrollBar-CHEQgaVx.cjs} +1 -1
- package/dist/{NativeScrollBar-apXjIKRW.js → NativeScrollBar-DYEv2GLV.js} +1 -1
- package/dist/{TreeLayout-rwhJfLmU.cjs → TreeLayout-BDaIyoGT.cjs} +1 -1
- package/dist/{TreeLayout-BcHsv9G8.js → TreeLayout-CqzxLpoM.js} +3 -3
- package/dist/core/contracts.d.cts +10 -7
- package/dist/core/contracts.d.ts +10 -7
- package/dist/core/labels.d.cts +4 -0
- package/dist/core/labels.d.ts +4 -0
- package/dist/dataRoute-CUXlMhUJ.cjs +1 -0
- package/dist/{dataRoute-Btg4w3vO.js → dataRoute-Ce6EIuu4.js} +41 -40
- package/dist/index-B3nShkkt.cjs +3 -0
- package/dist/{index-CIZw73j9.js → index-gJp1iXTc.js} +987 -903
- package/dist/index.cjs +1 -1
- package/dist/index.js +5 -5
- package/dist/{location-c1zdeySY.js → location-CtM94G0O.js} +1 -1
- package/dist/{location-CSIhx-L4.cjs → location-FavgY_gB.cjs} +1 -1
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +1 -1
- package/dist/server/errors.d.cts +1 -1
- package/dist/server/errors.d.ts +1 -1
- package/dist/server/ports.d.cts +1 -0
- package/dist/server/ports.d.ts +1 -0
- package/dist/server.cjs +1 -1
- package/dist/server.js +670 -641
- package/dist/styles/markdown-explorer.css +1 -1
- package/docs/behavior/dom-hooks.md +6 -3
- package/docs/behavior/layout.md +6 -0
- package/docs/behavior/localization.md +4 -1
- package/docs/behavior/security.md +11 -4
- package/package.json +4 -3
- package/dist/dataRoute-DHpu0fg2.cjs +0 -1
- package/dist/index-Cie6WPiM.cjs +0 -3
package/dist/server.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { b as
|
|
2
|
-
import { D as
|
|
3
|
-
import { createHash as
|
|
4
|
-
import { createLinkCardHandler as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { b as mt, c as Lt, f as Re, d as jt, g as zt, h as Dt, j as Ct, E as Ht, i as ee, k as Bt, l as Ft, r as pt, m as Ut, n as Xt, o as wt, p as Gt, q as Jt, s as de, t as te, e as je } from "./dataRoute-Ce6EIuu4.js";
|
|
2
|
+
import { D as Oo, M as _o, u as Ro } from "./dataRoute-Ce6EIuu4.js";
|
|
3
|
+
import { createHash as Yt, createHmac as Wt } from "node:crypto";
|
|
4
|
+
import { createLinkCardHandler as Kt } from "@aiquants/markdown/server";
|
|
5
|
+
import { crossOriginRefusal as Vt, NO_CROSS_ORIGIN_NAVIGATION as Zt } from "@aiquants/request-isolation";
|
|
6
|
+
import { data as ze, redirect as Qt } from "react-router";
|
|
7
|
+
import { w as qt, d as er, r as tr, i as rr, a as nr, p as or, b as sr, f as ar, N as ir } from "./location-CtM94G0O.js";
|
|
8
|
+
import { existsSync as cr, statSync as ur, realpathSync as lr, constants as ue } from "node:fs";
|
|
9
|
+
import { extname as dr, isAbsolute as De, relative as Ce, sep as He, join as fr, resolve as mr } from "node:path";
|
|
9
10
|
import { fileURLToPath as Se } from "node:url";
|
|
10
|
-
import { Worker as
|
|
11
|
-
import { open as
|
|
12
|
-
import { Readable as
|
|
13
|
-
const
|
|
14
|
-
authenticate: async () => ({ status: "signed-in", principal:
|
|
15
|
-
principalKey: () =>
|
|
11
|
+
import { Worker as pr } from "node:worker_threads";
|
|
12
|
+
import { open as ht, lstat as wr, realpath as hr, readdir as gr } from "node:fs/promises";
|
|
13
|
+
import { Readable as yr } from "node:stream";
|
|
14
|
+
const Be = Object.freeze({ kind: "anonymous" }), bo = Object.freeze({
|
|
15
|
+
authenticate: async () => ({ status: "signed-in", principal: Be }),
|
|
16
|
+
principalKey: () => Be.kind,
|
|
16
17
|
signedOutPage: (e, t) => new Response(null, { status: 401, headers: t })
|
|
17
|
-
}),
|
|
18
|
+
}), Er = "application/octet-stream", gt = "application/pdf", br = /* @__PURE__ */ new Set([
|
|
18
19
|
"image/png",
|
|
19
20
|
"image/apng",
|
|
20
21
|
"image/jpeg",
|
|
@@ -40,8 +41,8 @@ const He = Object.freeze({ kind: "anonymous" }), lo = Object.freeze({
|
|
|
40
41
|
"video/webm",
|
|
41
42
|
"video/ogg",
|
|
42
43
|
"video/quicktime",
|
|
43
|
-
|
|
44
|
-
]),
|
|
44
|
+
gt
|
|
45
|
+
]), yt = "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'", Sr = `${yt}; sandbox`, Tr = `${yt}; sandbox allow-same-origin`, Fe = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u, xr = /^[\t\n\r ]+|[\t\n\r ]+$/gu, Ae = /^[\t ]+|[\t ]+$/gu, kr = (e) => {
|
|
45
46
|
const t = [];
|
|
46
47
|
let r = "", n = 0;
|
|
47
48
|
for (; ; ) {
|
|
@@ -53,65 +54,65 @@ const He = Object.freeze({ kind: "anonymous" }), lo = Object.freeze({
|
|
|
53
54
|
n += e[n] === "\\" ? 2 : 1;
|
|
54
55
|
if (n = Math.min(n + 1, e.length), r += e.slice(a, n), n < e.length) continue;
|
|
55
56
|
}
|
|
56
|
-
if (t.push(r.replace(
|
|
57
|
+
if (t.push(r.replace(Ae, "")), r = "", n >= e.length) return t;
|
|
57
58
|
n += 1;
|
|
58
59
|
}
|
|
59
|
-
},
|
|
60
|
-
const t = e.replace(
|
|
60
|
+
}, Or = (e) => {
|
|
61
|
+
const t = e.replace(xr, ""), r = t.indexOf("/");
|
|
61
62
|
if (r < 0) return null;
|
|
62
63
|
const n = t.slice(0, r), a = t.indexOf(";", r + 1), s = t.slice(r + 1, a < 0 ? t.length : a).replace(/[\t\n\r ]+$/u, "");
|
|
63
|
-
return
|
|
64
|
-
},
|
|
64
|
+
return Fe.test(n) && Fe.test(s) ? `${n}/${s}`.toLowerCase() : null;
|
|
65
|
+
}, _r = (e) => {
|
|
65
66
|
let t = null;
|
|
66
|
-
for (const r of
|
|
67
|
-
const n =
|
|
67
|
+
for (const r of kr(e)) {
|
|
68
|
+
const n = Or(r);
|
|
68
69
|
n !== null && n !== "*/*" && (t = n);
|
|
69
70
|
}
|
|
70
71
|
return t;
|
|
71
|
-
},
|
|
72
|
+
}, Rr = /['()*]/gu, Ar = (e) => encodeURIComponent(e).replace(Rr, (t) => `%${t.charCodeAt(0).toString(16).toUpperCase()}`), Nr = Object.freeze({
|
|
72
73
|
"Cache-Control": "private, max-age=60, stale-while-revalidate=600, no-transform",
|
|
73
74
|
Vary: "Cookie"
|
|
74
|
-
}),
|
|
75
|
-
const r =
|
|
75
|
+
}), Ir = (e, t) => {
|
|
76
|
+
const r = _r(e), n = r !== null && br.has(r), a = n && (r.startsWith("audio/") || r.startsWith("video/"));
|
|
76
77
|
return {
|
|
77
|
-
contentType: r === null ?
|
|
78
|
+
contentType: r === null ? Er : r,
|
|
78
79
|
inline: n,
|
|
79
80
|
headers: {
|
|
80
81
|
"X-Content-Type-Options": "nosniff",
|
|
81
|
-
"Content-Disposition": `${n ? "inline" : "attachment"}; filename*=UTF-8''${
|
|
82
|
-
...r ===
|
|
82
|
+
"Content-Disposition": `${n ? "inline" : "attachment"}; filename*=UTF-8''${Ar(t)}`,
|
|
83
|
+
...r === gt ? {} : { "Content-Security-Policy": a ? Tr : Sr },
|
|
83
84
|
"Cross-Origin-Resource-Policy": "same-origin"
|
|
84
85
|
}
|
|
85
86
|
};
|
|
86
|
-
},
|
|
87
|
+
}, Mr = /^bytes=(?:(\d+)-(\d*)|-(\d+))$/iu, we = Object.freeze({ kind: "whole" }), Ue = Object.freeze({ kind: "unsatisfiable" }), vr = (e, t, r) => {
|
|
87
88
|
const n = e.get("Range");
|
|
88
|
-
if (n === null) return
|
|
89
|
+
if (n === null) return we;
|
|
89
90
|
const a = e.get("If-Range");
|
|
90
|
-
if (a !== null && a !== r) return
|
|
91
|
-
const s =
|
|
92
|
-
if (s === null) return
|
|
93
|
-
const [, c, f,
|
|
94
|
-
if (
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
98
|
-
return { kind: "partial", range: { offset:
|
|
91
|
+
if (a !== null && a !== r) return we;
|
|
92
|
+
const s = Mr.exec(n);
|
|
93
|
+
if (s === null) return we;
|
|
94
|
+
const [, c, f, y] = s;
|
|
95
|
+
if (y !== void 0) {
|
|
96
|
+
const h = Number(y);
|
|
97
|
+
if (h === 0) return Ue;
|
|
98
|
+
const x = Math.max(0, t - h);
|
|
99
|
+
return { kind: "partial", range: { offset: x, length: t - x } };
|
|
99
100
|
}
|
|
100
|
-
const
|
|
101
|
-
return p <
|
|
102
|
-
},
|
|
101
|
+
const k = Number(c), p = f === "" ? Number.POSITIVE_INFINITY : Number(f);
|
|
102
|
+
return p < k ? we : k >= t ? Ue : { kind: "partial", range: { offset: k, length: Math.min(p, t - 1) - k + 1 } };
|
|
103
|
+
}, Xe = "W/", Pr = (e) => {
|
|
103
104
|
const t = [];
|
|
104
105
|
let r = 0, n = !1;
|
|
105
106
|
for (let a = 0; a < e.length; a += 1)
|
|
106
|
-
e[a] === '"' ? n = !n : e[a] === "," && !n && (t.push(e.slice(r, a).replace(
|
|
107
|
-
return t.push(e.slice(r).replace(
|
|
108
|
-
},
|
|
107
|
+
e[a] === '"' ? n = !n : e[a] === "," && !n && (t.push(e.slice(r, a).replace(Ae, "")), r = a + 1);
|
|
108
|
+
return t.push(e.slice(r).replace(Ae, "")), t;
|
|
109
|
+
}, Ge = (e) => e.startsWith(Xe) ? e.slice(Xe.length) : e, $r = (e, t) => {
|
|
109
110
|
if (e === null) return !1;
|
|
110
|
-
const r =
|
|
111
|
+
const r = Pr(e);
|
|
111
112
|
if (r.length === 1 && r[0] === "*") return !0;
|
|
112
|
-
const n =
|
|
113
|
-
return r.some((a) =>
|
|
114
|
-
},
|
|
113
|
+
const n = Ge(t);
|
|
114
|
+
return r.some((a) => Ge(a) === n);
|
|
115
|
+
}, Lr = (e, t) => {
|
|
115
116
|
let r = t;
|
|
116
117
|
return e.pipeThrough(
|
|
117
118
|
new TransformStream({
|
|
@@ -127,21 +128,21 @@ const He = Object.freeze({ kind: "anonymous" }), lo = Object.freeze({
|
|
|
127
128
|
}, Te = async (e, t, r, n, a) => {
|
|
128
129
|
if (n !== null && r.set("Content-Length", String(n)), e.method.toUpperCase() === "HEAD") return new Response(null, { status: t, headers: r });
|
|
129
130
|
const s = await a();
|
|
130
|
-
return new Response(n === null ? s :
|
|
131
|
-
},
|
|
131
|
+
return new Response(n === null ? s : Lr(s, n), { status: t, headers: r });
|
|
132
|
+
}, jr = (e, t) => {
|
|
132
133
|
const r = new Headers(e);
|
|
133
134
|
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);
|
|
134
135
|
return new Response(null, { status: 416, headers: r });
|
|
135
|
-
},
|
|
136
|
-
const n = `"${t.version}"`, a =
|
|
137
|
-
for (const [
|
|
138
|
-
if (
|
|
136
|
+
}, zr = async (e, t, r) => {
|
|
137
|
+
const n = `"${t.version}"`, a = Ir(t.contentType, t.name), s = new Headers(r);
|
|
138
|
+
for (const [y, k] of Object.entries({ ...a.headers, ...Nr, ETag: n })) s.set(y, k);
|
|
139
|
+
if ($r(e.headers.get("If-None-Match"), n)) return new Response(null, { status: 304, headers: s });
|
|
139
140
|
if (s.set("Content-Type", a.contentType), t.size === null) return Te(e, 200, s, null, () => t.open(null));
|
|
140
141
|
if (t.size === 0)
|
|
141
142
|
return s.set("Content-Length", "0"), new Response(null, { status: 200, headers: s });
|
|
142
143
|
s.set("Accept-Ranges", "bytes");
|
|
143
|
-
const c =
|
|
144
|
-
if (c.kind === "unsatisfiable") return
|
|
144
|
+
const c = vr(e.headers, t.size, n);
|
|
145
|
+
if (c.kind === "unsatisfiable") return jr(r, t.size);
|
|
145
146
|
if (c.kind === "whole") return Te(e, 200, s, t.size, () => t.open(null));
|
|
146
147
|
const { range: f } = c;
|
|
147
148
|
return s.set("Content-Range", `bytes ${f.offset}-${f.offset + f.length - 1}/${t.size}`), Te(e, 206, s, f.length, () => t.open(f));
|
|
@@ -155,40 +156,57 @@ const He = Object.freeze({ kind: "anonymous" }), lo = Object.freeze({
|
|
|
155
156
|
clearTimeout(c), clearTimeout(s);
|
|
156
157
|
};
|
|
157
158
|
n.then(
|
|
158
|
-
(
|
|
159
|
-
f(), a(
|
|
159
|
+
(y) => {
|
|
160
|
+
f(), a(y);
|
|
160
161
|
},
|
|
161
162
|
() => {
|
|
162
163
|
f(), a(e.late);
|
|
163
164
|
}
|
|
164
165
|
);
|
|
165
166
|
});
|
|
166
|
-
},
|
|
167
|
+
}, Dr = Object.freeze({
|
|
167
168
|
error: (e, t) => {
|
|
168
169
|
console.error(e, t);
|
|
169
170
|
}
|
|
170
|
-
}),
|
|
171
|
+
}), Et = /* @__PURE__ */ Symbol.for("@aiquants/markdown-explorer:ExplorerError");
|
|
171
172
|
class Ee extends Error {
|
|
172
173
|
reason;
|
|
173
174
|
code;
|
|
174
175
|
constructor(t, r = {}) {
|
|
175
|
-
if (!
|
|
176
|
-
if (r.code !== void 0 && !
|
|
177
|
-
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,
|
|
176
|
+
if (!mt(t)) throw new RangeError(`[markdown-explorer] ExplorerError needs a failure reason; got ${JSON.stringify(t)}`);
|
|
177
|
+
if (r.code !== void 0 && !Lt(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)}`);
|
|
178
|
+
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, Et, { value: !0 });
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
|
-
const
|
|
181
|
+
const Cr = (e) => e instanceof Error && Object.hasOwn(e, Et) && mt(e.reason), Hr = (e) => typeof e == "object" && e !== null && e.name === "AbortError", Ie = (e, t, r) => {
|
|
181
182
|
try {
|
|
182
183
|
e.error(t, r);
|
|
183
184
|
} catch (n) {
|
|
184
185
|
console.error("[markdown-explorer] the logger threw while reporting a failure", { operation: r.operation, error: n });
|
|
185
186
|
}
|
|
186
|
-
},
|
|
187
|
+
}, ne = (e, t) => Ie(e, `[markdown-explorer] ${t.operation} failed`, t), Br = (e, t) => Ie(e, `[markdown-explorer] ${t.operation} left out an entry`, t), Je = (e, t) => Ie(e, `[markdown-explorer] ${t.operation} refused a path the deny rules match`, { ...t, error: new RangeError("[markdown-explorer] the path matches a deny rule") }), Ye = (e, t) => {
|
|
187
188
|
e === null || typeof e != "object" && typeof e != "function" || Promise.resolve(e).then(void 0, t);
|
|
188
|
-
},
|
|
189
|
+
}, Z = (e, t, r, n) => Cr(e) ? Re(e.reason, e.code) : (Hr(e) || r.aborted || ne(n, { ...t, error: e }), { reason: "failed" }), Fr = 2 * 1024 * 1024, Ur = 256 * 1024 * 1024, Xr = async (e, t) => {
|
|
190
|
+
const r = e.getReader(), n = new Uint8Array(t);
|
|
191
|
+
let a = 0;
|
|
192
|
+
for (; a < t; ) {
|
|
193
|
+
const { done: s, value: c } = await r.read();
|
|
194
|
+
if (s) return n.subarray(0, a);
|
|
195
|
+
const f = c.subarray(0, t - a);
|
|
196
|
+
n.set(f, a), a += f.byteLength;
|
|
197
|
+
}
|
|
198
|
+
return r.cancel().catch(() => {
|
|
199
|
+
}), n;
|
|
200
|
+
}, Gr = async (e, t) => {
|
|
201
|
+
if (e.size === 0) return { text: "", truncated: !1 };
|
|
202
|
+
const r = e.size !== null && e.size > t, n = e.size === null ? t + 1 : Math.min(e.size, t), a = await Xr(await e.open(r ? { offset: 0, length: t } : null), n);
|
|
203
|
+
if (e.size !== null && a.byteLength < n) throw new RangeError("[markdown-explorer] the file ended before the length its asset port reported");
|
|
204
|
+
const s = r || a.byteLength > t, c = s ? a.subarray(0, t) : a;
|
|
205
|
+
return c.includes(0) ? null : { text: new TextDecoder("utf-8").decode(c, { stream: s }), truncated: s };
|
|
206
|
+
}, We = (e, t) => {
|
|
189
207
|
if (!Number.isSafeInteger(t) || t <= 0) throw new RangeError(`[markdown-explorer] a cache ${e} must be a positive integer; got ${String(t)}`);
|
|
190
|
-
},
|
|
191
|
-
|
|
208
|
+
}, bt = (e, t) => {
|
|
209
|
+
We("capacity", e), t !== void 0 && We("weight budget", t.max);
|
|
192
210
|
const r = /* @__PURE__ */ new Map();
|
|
193
211
|
let n = 0;
|
|
194
212
|
const a = (s) => {
|
|
@@ -206,9 +224,9 @@ const Pr = (e) => e instanceof Error && Object.hasOwn(e, ht) && lt(e.reason), $r
|
|
|
206
224
|
const f = t === void 0 ? 0 : t.of(s, c);
|
|
207
225
|
if (!(t !== void 0 && f > t.max)) {
|
|
208
226
|
r.set(s, { value: c, weight: f }), n += f;
|
|
209
|
-
for (const
|
|
227
|
+
for (const y of r.keys()) {
|
|
210
228
|
if (r.size <= e && (t === void 0 || n <= t.max)) break;
|
|
211
|
-
a(
|
|
229
|
+
a(y);
|
|
212
230
|
}
|
|
213
231
|
}
|
|
214
232
|
},
|
|
@@ -216,286 +234,286 @@ const Pr = (e) => e instanceof Error && Object.hasOwn(e, ht) && lt(e.reason), $r
|
|
|
216
234
|
size: () => r.size,
|
|
217
235
|
weight: () => n
|
|
218
236
|
};
|
|
219
|
-
},
|
|
237
|
+
}, St = (e) => Math.max(1, e - 1), Jr = 2147483647, Ke = Object.freeze({ status: "aborted" }), ae = (e, t, r) => {
|
|
220
238
|
const n = (e.get(t) ?? 0) + r;
|
|
221
239
|
n === 0 ? e.delete(t) : e.set(t, n);
|
|
222
240
|
}, ce = (e, t, r) => {
|
|
223
241
|
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)}`);
|
|
224
|
-
},
|
|
225
|
-
ce("size", t, Number.MAX_SAFE_INTEGER), ce("deadline", r,
|
|
226
|
-
const c = Object.freeze({ maxOldGenerationSizeMb: s.maxOldGenerationSizeMb, maxYoungGenerationSizeMb: s.maxYoungGenerationSizeMb }), f = /* @__PURE__ */ new Set(),
|
|
227
|
-
let
|
|
228
|
-
const
|
|
229
|
-
const { job:
|
|
230
|
-
|
|
231
|
-
},
|
|
232
|
-
const [
|
|
233
|
-
|
|
234
|
-
},
|
|
235
|
-
let
|
|
236
|
-
for (const [T, b] of
|
|
237
|
-
const
|
|
238
|
-
(
|
|
242
|
+
}, Yr = (e) => e !== null && typeof e == "object" && e.ready === !0 && !("id" in e), Wr = (e, t) => e !== null && typeof e == "object" && e.id === t && "output" in e, Kr = ({ url: e, size: t, deadlineMs: r, jobsPerScope: n, maxQueuedJobs: a, heapLimits: s }) => {
|
|
243
|
+
ce("size", t, Number.MAX_SAFE_INTEGER), ce("deadline", r, Jr), ce("jobsPerScope", n, Number.MAX_SAFE_INTEGER), ce("maxQueuedJobs", a, Number.MAX_SAFE_INTEGER), ce("maxOldGenerationSizeMb", s.maxOldGenerationSizeMb, Number.MAX_SAFE_INTEGER), ce("maxYoungGenerationSizeMb", s.maxYoungGenerationSizeMb, Number.MAX_SAFE_INTEGER);
|
|
244
|
+
const c = Object.freeze({ maxOldGenerationSizeMb: s.maxOldGenerationSizeMb, maxYoungGenerationSizeMb: s.maxYoungGenerationSizeMb }), f = /* @__PURE__ */ new Set(), y = [], k = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), h = St(t);
|
|
245
|
+
let x = 0;
|
|
246
|
+
const R = (d, E) => {
|
|
247
|
+
const { job: w } = d;
|
|
248
|
+
d.timer !== null && clearTimeout(d.timer), d.timer = null, d.job = null, d.sent = !1, w !== null && (ae(k, w.scope, -1), ae(p, w.scope, -1), w.settle(E));
|
|
249
|
+
}, v = (d) => {
|
|
250
|
+
const [E] = y.splice(d, 1);
|
|
251
|
+
E?.detach();
|
|
252
|
+
}, _ = () => {
|
|
253
|
+
let d = -1, E = h, w = Number.POSITIVE_INFINITY;
|
|
254
|
+
for (const [T, b] of y.entries()) {
|
|
255
|
+
const A = k.get(b.scope) ?? 0, P = p.get(b.scope) ?? 0;
|
|
256
|
+
(A < E || A === E && d >= 0 && P < w) && (d = T, E = A, w = P);
|
|
239
257
|
}
|
|
240
|
-
return
|
|
241
|
-
},
|
|
242
|
-
f.has(
|
|
243
|
-
}),
|
|
244
|
-
},
|
|
245
|
-
|
|
246
|
-
|
|
258
|
+
return d;
|
|
259
|
+
}, O = (d, E) => {
|
|
260
|
+
f.has(d) && (f.delete(d), R(d, E), d.worker.terminate().catch(() => {
|
|
261
|
+
}), j());
|
|
262
|
+
}, L = (d) => {
|
|
263
|
+
d.timer = setTimeout(() => {
|
|
264
|
+
O(d, { status: "timeout" });
|
|
247
265
|
}, r);
|
|
248
|
-
}, S = (
|
|
249
|
-
|
|
266
|
+
}, S = (d, E) => d.sent ? { status: "crashed", error: E } : { status: "unavailable", error: E }, N = (d, E) => {
|
|
267
|
+
d.sent = !0, L(d);
|
|
250
268
|
try {
|
|
251
|
-
|
|
252
|
-
} catch (
|
|
253
|
-
|
|
269
|
+
d.worker.postMessage({ id: E.id, input: E.input });
|
|
270
|
+
} catch (w) {
|
|
271
|
+
R(d, { status: "crashed", error: w }), d.worker.unref();
|
|
254
272
|
}
|
|
255
|
-
},
|
|
256
|
-
const
|
|
257
|
-
return
|
|
258
|
-
|
|
259
|
-
}, r),
|
|
260
|
-
if (!
|
|
261
|
-
|
|
273
|
+
}, H = () => {
|
|
274
|
+
const d = { worker: new pr(e, { resourceLimits: c }), job: null, sent: !1, timer: null, ready: !1 };
|
|
275
|
+
return d.worker.unref(), d.timer = setTimeout(() => {
|
|
276
|
+
O(d, { status: "unavailable", error: new Error(`[markdown-explorer] a worker did not start within ${String(r)} ms`) });
|
|
277
|
+
}, r), d.worker.on("message", (E) => {
|
|
278
|
+
if (!d.ready && Yr(E)) {
|
|
279
|
+
d.ready = !0, d.timer !== null && clearTimeout(d.timer), d.timer = null, d.job === null ? d.worker.unref() : N(d, d.job), d.job === null && j();
|
|
262
280
|
return;
|
|
263
281
|
}
|
|
264
|
-
const { job:
|
|
265
|
-
if (
|
|
266
|
-
|
|
282
|
+
const { job: w } = d;
|
|
283
|
+
if (w === null || !Wr(E, w.id)) {
|
|
284
|
+
O(d, S(d, new Error("[markdown-explorer] a worker sent a message that answers no job")));
|
|
267
285
|
return;
|
|
268
286
|
}
|
|
269
|
-
|
|
270
|
-
}),
|
|
271
|
-
|
|
272
|
-
}),
|
|
273
|
-
|
|
274
|
-
}),
|
|
275
|
-
|
|
276
|
-
}), f.add(
|
|
277
|
-
},
|
|
287
|
+
R(d, { status: "done", output: E.output }), d.worker.unref(), j();
|
|
288
|
+
}), d.worker.on("error", (E) => {
|
|
289
|
+
O(d, S(d, E));
|
|
290
|
+
}), d.worker.on("messageerror", (E) => {
|
|
291
|
+
O(d, S(d, E));
|
|
292
|
+
}), d.worker.on("exit", (E) => {
|
|
293
|
+
O(d, S(d, new Error(`[markdown-explorer] a worker exited with code ${String(E)}`)));
|
|
294
|
+
}), f.add(d), d;
|
|
295
|
+
}, j = () => {
|
|
278
296
|
for (; ; ) {
|
|
279
|
-
const
|
|
280
|
-
if (
|
|
281
|
-
let
|
|
297
|
+
const d = _(), E = y[d];
|
|
298
|
+
if (E === void 0) return;
|
|
299
|
+
let w;
|
|
282
300
|
for (const b of f)
|
|
283
301
|
if (b.job === null) {
|
|
284
|
-
|
|
302
|
+
w = b;
|
|
285
303
|
break;
|
|
286
304
|
}
|
|
287
|
-
if (
|
|
305
|
+
if (w === void 0 && f.size < t)
|
|
288
306
|
try {
|
|
289
|
-
|
|
307
|
+
w = H();
|
|
290
308
|
} catch (b) {
|
|
291
|
-
|
|
309
|
+
v(d), ae(p, E.scope, -1), E.settle({ status: "unavailable", error: b });
|
|
292
310
|
continue;
|
|
293
311
|
}
|
|
294
|
-
if (
|
|
295
|
-
|
|
296
|
-
const T =
|
|
297
|
-
T.job =
|
|
312
|
+
if (w === void 0) return;
|
|
313
|
+
v(d), ae(k, E.scope, 1);
|
|
314
|
+
const T = w;
|
|
315
|
+
T.job = E, T.worker.ref(), T.ready && N(T, E);
|
|
298
316
|
}
|
|
299
317
|
};
|
|
300
318
|
return {
|
|
301
|
-
run: (
|
|
302
|
-
if (
|
|
303
|
-
T(
|
|
319
|
+
run: (d, { scope: E, signal: w }) => new Promise((T) => {
|
|
320
|
+
if (w.aborted) {
|
|
321
|
+
T(Ke);
|
|
304
322
|
return;
|
|
305
323
|
}
|
|
306
|
-
if ((p.get(
|
|
324
|
+
if ((p.get(E) ?? 0) >= n) {
|
|
307
325
|
T({ status: "refused", limit: "scope" });
|
|
308
326
|
return;
|
|
309
327
|
}
|
|
310
|
-
|
|
311
|
-
const b = { id:
|
|
328
|
+
x += 1;
|
|
329
|
+
const b = { id: x, input: d, scope: E, settle: T, detach: () => {
|
|
312
330
|
} };
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
if (
|
|
316
|
-
if (
|
|
317
|
-
|
|
331
|
+
y.push(b), ae(p, E, 1), j();
|
|
332
|
+
const A = y.indexOf(b);
|
|
333
|
+
if (A < 0) return;
|
|
334
|
+
if (y.length > a) {
|
|
335
|
+
v(A), ae(p, E, -1), T({ status: "refused", limit: "queue" });
|
|
318
336
|
return;
|
|
319
337
|
}
|
|
320
338
|
const P = () => {
|
|
321
|
-
const B =
|
|
322
|
-
B < 0 || (
|
|
339
|
+
const B = y.indexOf(b);
|
|
340
|
+
B < 0 || (v(B), ae(p, E, -1), T(Ke));
|
|
323
341
|
};
|
|
324
|
-
|
|
325
|
-
|
|
342
|
+
w.addEventListener("abort", P, { once: !0 }), b.detach = () => {
|
|
343
|
+
w.removeEventListener("abort", P);
|
|
326
344
|
};
|
|
327
345
|
}),
|
|
328
346
|
workers: () => f.size
|
|
329
347
|
};
|
|
330
|
-
},
|
|
348
|
+
}, Me = 1024 * 1024, Vr = 3e4, Zr = 4 * Me, Qr = 64 * Me, qr = 3, en = 2, tn = (e, t) => e + St(t) + qr, rn = 4, nn = 32, on = 512, sn = 64, an = 4096, cn = 32, Ve = 4096, un = 4, Tt = ({ workerHeapMb: e, maxHtmlBytes: t }) => Math.floor(((e - sn) * Me - t * cn) / an), ln = ({ maxHtmlBytes: e }) => e, dn = ({ maxHtmlBytes: e }) => un * e, fn = 1024, mn = 2147483647, pn = 64, wn = 2 ** 29, hn = 1024 * 1024, gn = 64, Ze = Object.freeze({ status: "rejected", reason: "too-large", cause: null }), ke = Object.freeze({ status: "rejected", reason: "failed", cause: null }), ie = (e, t, r, n) => {
|
|
331
349
|
if (t === void 0) return r;
|
|
332
350
|
if (typeof t != "number") throw new TypeError(`[markdown-explorer] sanitizer.${e} must be a number; got ${typeof t}`);
|
|
333
351
|
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)}`);
|
|
334
352
|
return t;
|
|
335
|
-
},
|
|
353
|
+
}, yn = (e, t) => {
|
|
336
354
|
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 }");
|
|
337
|
-
const { workers: r, deadlineMs: n, maxHtmlBytes: a, cacheBytes: s, workerHeapMb: c, jobsPerScope: f, maxQueuedJobs:
|
|
338
|
-
workers:
|
|
339
|
-
deadlineMs:
|
|
340
|
-
maxHtmlBytes:
|
|
341
|
-
cacheBytes:
|
|
342
|
-
workerHeapMb:
|
|
355
|
+
const { workers: r, deadlineMs: n, maxHtmlBytes: a, cacheBytes: s, workerHeapMb: c, jobsPerScope: f, maxQueuedJobs: y } = e ?? {}, k = ie("workers", r, en, pn), p = ie("jobsPerScope", f, tn(t, k), Number.MAX_SAFE_INTEGER), h = Object.freeze({
|
|
356
|
+
workers: k,
|
|
357
|
+
deadlineMs: ie("deadlineMs", n, Vr, mn),
|
|
358
|
+
maxHtmlBytes: ie("maxHtmlBytes", a, Zr, wn),
|
|
359
|
+
cacheBytes: ie("cacheBytes", s, Qr, Number.MAX_SAFE_INTEGER),
|
|
360
|
+
workerHeapMb: ie("workerHeapMb", c, on, hn),
|
|
343
361
|
jobsPerScope: p,
|
|
344
|
-
maxQueuedJobs:
|
|
362
|
+
maxQueuedJobs: ie("maxQueuedJobs", y, rn * p, Number.MAX_SAFE_INTEGER)
|
|
345
363
|
});
|
|
346
|
-
if (
|
|
347
|
-
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(
|
|
348
|
-
if (
|
|
349
|
-
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(
|
|
350
|
-
if (
|
|
364
|
+
if (h.jobsPerScope < t)
|
|
365
|
+
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(h.jobsPerScope)}`);
|
|
366
|
+
if (h.maxQueuedJobs < t)
|
|
367
|
+
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(h.maxQueuedJobs)}`);
|
|
368
|
+
if (Tt(h) < Ve)
|
|
351
369
|
throw new RangeError(
|
|
352
|
-
`[markdown-explorer] sanitizer.workerHeapMb (${String(
|
|
370
|
+
`[markdown-explorer] sanitizer.workerHeapMb (${String(h.workerHeapMb)} MiB) must leave room for ${String(Ve)} parsed nodes beside HTML of sanitizer.maxHtmlBytes (${String(h.maxHtmlBytes)} bytes); raise workerHeapMb or lower maxHtmlBytes`
|
|
353
371
|
);
|
|
354
|
-
return
|
|
355
|
-
},
|
|
356
|
-
const e = import.meta.url, t = new URL(`./sanitizeWorker${
|
|
357
|
-
if (!
|
|
372
|
+
return h;
|
|
373
|
+
}, En = () => {
|
|
374
|
+
const e = import.meta.url, t = new URL(`./sanitizeWorker${dr(Se(e))}`, e);
|
|
375
|
+
if (!cr(Se(t))) throw new Error(`[markdown-explorer] the HTML sanitizer worker is missing: ${Se(t)}`);
|
|
358
376
|
return t;
|
|
359
|
-
},
|
|
377
|
+
}, Qe = /* @__PURE__ */ new Map(), bn = (e, t) => {
|
|
360
378
|
const r = [e.href, t.workers, t.deadlineMs, t.workerHeapMb, t.jobsPerScope, t.maxQueuedJobs].map(String).join("\0");
|
|
361
|
-
let n =
|
|
362
|
-
return n === void 0 && (n =
|
|
379
|
+
let n = Qe.get(r);
|
|
380
|
+
return n === void 0 && (n = Kr({
|
|
363
381
|
url: e,
|
|
364
382
|
size: t.workers,
|
|
365
383
|
deadlineMs: t.deadlineMs,
|
|
366
384
|
jobsPerScope: t.jobsPerScope,
|
|
367
385
|
maxQueuedJobs: t.maxQueuedJobs,
|
|
368
|
-
heapLimits: { maxOldGenerationSizeMb: t.workerHeapMb, maxYoungGenerationSizeMb:
|
|
369
|
-
}),
|
|
370
|
-
},
|
|
386
|
+
heapLimits: { maxOldGenerationSizeMb: t.workerHeapMb, maxYoungGenerationSizeMb: nn }
|
|
387
|
+
}), Qe.set(r, n)), n;
|
|
388
|
+
}, Sn = (e) => {
|
|
371
389
|
if (e === null || typeof e != "object") return !1;
|
|
372
390
|
const { status: t, html: r, message: n } = e;
|
|
373
391
|
return t === "sanitized" && typeof r == "string" || t === "too-large" || t === "error" && typeof n == "string";
|
|
374
|
-
},
|
|
375
|
-
const a = Object.freeze([...e]), s =
|
|
392
|
+
}, Tn = (e) => e instanceof Error && e.code === "ERR_WORKER_OUT_OF_MEMORY", xn = ({ iframeHosts: e, dataPath: t, options: r, pool: n }) => {
|
|
393
|
+
const a = Object.freeze([...e]), s = Tt(r), c = ln(r), f = dn(r), y = bt(fn, {
|
|
376
394
|
max: r.cacheBytes,
|
|
377
|
-
of: (
|
|
378
|
-
}),
|
|
379
|
-
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
},
|
|
383
|
-
const S = await n.run({ html:
|
|
395
|
+
of: (_, O) => 2 * _.length + (O.status === "sanitized" ? 2 * O.html.length : gn)
|
|
396
|
+
}), k = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), h = (_) => {
|
|
397
|
+
k.get(_.key) === _ && k.delete(_.key);
|
|
398
|
+
const O = p.get(_.hash);
|
|
399
|
+
O?.delete(_), O?.size === 0 && p.delete(_.hash);
|
|
400
|
+
}, x = async (_, O, L) => {
|
|
401
|
+
const S = await n.run({ html: _, iframeHosts: a, dataPath: t, maxNodes: s, maxAttributeChars: c, maxSanitizedChars: f }, { scope: O, signal: L });
|
|
384
402
|
if (S.status === "refused") {
|
|
385
|
-
const
|
|
386
|
-
return { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${
|
|
403
|
+
const H = S.limit === "scope" ? `its reader already has ${String(r.jobsPerScope)} documents being sanitized or waiting` : `${String(r.maxQueuedJobs)} documents are already waiting`;
|
|
404
|
+
return { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${H}`) }, lasting: !1 };
|
|
387
405
|
}
|
|
388
406
|
if (S.status === "aborted") return { outcome: ke, lasting: !1 };
|
|
389
407
|
if (S.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 };
|
|
390
408
|
if (S.status === "unavailable") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker could not start", { cause: S.error }) }, lasting: !1 };
|
|
391
|
-
if (S.status === "crashed" &&
|
|
409
|
+
if (S.status === "crashed" && Tn(S.error))
|
|
392
410
|
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: S.error }) }, lasting: !0 };
|
|
393
411
|
if (S.status === "crashed") return { outcome: { status: "rejected", reason: "failed", cause: new Error("[markdown-explorer] the HTML sanitizer worker failed", { cause: S.error }) }, lasting: !0 };
|
|
394
|
-
const { output:
|
|
395
|
-
return
|
|
396
|
-
},
|
|
397
|
-
let
|
|
412
|
+
const { output: N } = S;
|
|
413
|
+
return Sn(N) ? N.status === "too-large" ? { outcome: Ze, lasting: !0 } : N.status === "error" ? { outcome: { status: "rejected", reason: "failed", cause: new Error(`[markdown-explorer] the HTML sanitizer failed: ${N.message}`) }, lasting: !0 } : N.html.length > f ? { outcome: { status: "rejected", reason: "too-large", cause: new Error(`[markdown-explorer] the HTML sanitizer's output of ${String(N.html.length)} characters exceeds its limit of ${String(f)}`) }, lasting: !0 } : { outcome: { status: "sanitized", html: N.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 };
|
|
414
|
+
}, R = (_, O, L, S) => {
|
|
415
|
+
let N = () => {
|
|
398
416
|
};
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
}),
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
return
|
|
405
|
-
if (
|
|
406
|
-
const T =
|
|
407
|
-
T === void 0 &&
|
|
408
|
-
for (const
|
|
409
|
-
|
|
410
|
-
}),
|
|
411
|
-
},
|
|
412
|
-
|
|
417
|
+
const H = new Promise((E) => {
|
|
418
|
+
N = E;
|
|
419
|
+
}), j = { hash: O, key: L, outcome: H, answer: N, controller: new AbortController(), waiters: 0 };
|
|
420
|
+
k.set(L, j);
|
|
421
|
+
const d = p.get(O);
|
|
422
|
+
return d === void 0 ? p.set(O, /* @__PURE__ */ new Set([j])) : d.add(j), x(_, S, j.controller.signal).catch((E) => ({ outcome: { status: "rejected", reason: "failed", cause: E instanceof Error ? E : new Error(String(E)) }, lasting: !0 })).then(({ outcome: E, lasting: w }) => {
|
|
423
|
+
if (h(j), j.answer(E), !w) return;
|
|
424
|
+
const T = y.get(O), b = T ?? (E.status === "rejected" ? { ...E, cause: null } : E);
|
|
425
|
+
T === void 0 && y.set(O, b);
|
|
426
|
+
for (const A of p.get(O) ?? [])
|
|
427
|
+
h(A), A.answer(b), A.controller.abort();
|
|
428
|
+
}), j;
|
|
429
|
+
}, v = (_, O) => new Promise((L) => {
|
|
430
|
+
_.waiters += 1;
|
|
413
431
|
const S = () => {
|
|
414
|
-
|
|
432
|
+
_.waiters -= 1, L(ke), !(_.waiters > 0) && (h(_), _.controller.abort());
|
|
415
433
|
};
|
|
416
|
-
|
|
417
|
-
|
|
434
|
+
O.addEventListener("abort", S, { once: !0 }), _.outcome.then((N) => {
|
|
435
|
+
O.removeEventListener("abort", S), L(N);
|
|
418
436
|
});
|
|
419
437
|
});
|
|
420
|
-
return (
|
|
421
|
-
if (
|
|
422
|
-
const S =
|
|
423
|
-
if (
|
|
424
|
-
if (
|
|
425
|
-
const
|
|
426
|
-
return
|
|
438
|
+
return (_, { scope: O, signal: L }) => {
|
|
439
|
+
if (_.length > r.maxHtmlBytes || Buffer.byteLength(_, "utf8") > r.maxHtmlBytes) return Promise.resolve(Ze);
|
|
440
|
+
const S = Yt("sha256").update(_, "utf8").digest("base64"), N = y.get(S);
|
|
441
|
+
if (N !== void 0) return Promise.resolve(N);
|
|
442
|
+
if (L.aborted) return Promise.resolve(ke);
|
|
443
|
+
const H = `${S}\0${O}`, j = k.get(H);
|
|
444
|
+
return v(j === void 0 ? R(_, S, H, O) : j, L);
|
|
427
445
|
};
|
|
428
|
-
}, be = (e) => ({ result: e, json: JSON.stringify(e) }), Oe = Object.freeze(be(Object.freeze({ status: "error", failure: Object.freeze({ reason: "failed" }) }))),
|
|
429
|
-
const a =
|
|
430
|
-
const
|
|
431
|
-
const
|
|
432
|
-
return !(
|
|
433
|
-
},
|
|
434
|
-
if (
|
|
435
|
-
const
|
|
436
|
-
return
|
|
446
|
+
}, be = (e) => ({ result: e, json: JSON.stringify(e) }), Oe = Object.freeze(be(Object.freeze({ status: "error", failure: Object.freeze({ reason: "failed" }) }))), kn = (e) => e.status === "ok" && e.entries.length > 0, On = ({ ttlMs: e, maxEntries: t, maxBytes: r, now: n }) => {
|
|
447
|
+
const a = bt(t, { max: r, of: (p, h) => 2 * h.tree.json.length }), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), f = (p, h) => {
|
|
448
|
+
const x = new AbortController(), R = { waiters: 0, superseded: !1, started: !1, loadTree: h }, v = c.get(p), _ = (H, j) => {
|
|
449
|
+
const d = be(H);
|
|
450
|
+
return !(R.superseded || x.signal.aborted) && kn(H) && a.set(p, { tree: d, loadedAt: j }), d;
|
|
451
|
+
}, L = (async () => {
|
|
452
|
+
if (v !== void 0 && await v, x.signal.aborted) return Oe;
|
|
453
|
+
const H = n();
|
|
454
|
+
return R.started = !0, _(await R.loadTree(x.signal, H), H);
|
|
437
455
|
})().finally(() => {
|
|
438
456
|
s.get(p) === S && s.delete(p);
|
|
439
|
-
}), S = { promise:
|
|
457
|
+
}), S = { promise: L, controller: x, state: R };
|
|
440
458
|
s.set(p, S);
|
|
441
|
-
const
|
|
459
|
+
const N = L.then(
|
|
442
460
|
() => {
|
|
443
461
|
},
|
|
444
462
|
() => {
|
|
445
463
|
}
|
|
446
464
|
);
|
|
447
|
-
return c.set(p,
|
|
448
|
-
c.get(p) ===
|
|
465
|
+
return c.set(p, N), N.then(() => {
|
|
466
|
+
c.get(p) === N && c.delete(p);
|
|
449
467
|
}), S;
|
|
450
|
-
},
|
|
451
|
-
|
|
452
|
-
const
|
|
453
|
-
|
|
468
|
+
}, y = (p, h, x) => {
|
|
469
|
+
h.state.waiters += 1;
|
|
470
|
+
const R = () => {
|
|
471
|
+
h.state.waiters -= 1, !(h.state.waiters > 0) && (s.get(p) === h && s.delete(p), h.controller.abort());
|
|
454
472
|
};
|
|
455
|
-
return
|
|
456
|
-
|
|
473
|
+
return x.addEventListener("abort", R, { once: !0 }), h.promise.finally(() => {
|
|
474
|
+
x.removeEventListener("abort", R);
|
|
457
475
|
});
|
|
458
|
-
},
|
|
476
|
+
}, k = (p) => {
|
|
459
477
|
a.delete(p);
|
|
460
|
-
const
|
|
461
|
-
|
|
478
|
+
const h = s.get(p);
|
|
479
|
+
h?.state.started && (h.state.superseded = !0, s.delete(p));
|
|
462
480
|
};
|
|
463
481
|
return {
|
|
464
|
-
load: (p,
|
|
465
|
-
if (
|
|
466
|
-
const
|
|
467
|
-
if (
|
|
468
|
-
if (n() -
|
|
482
|
+
load: (p, h, x) => {
|
|
483
|
+
if (h.aborted) return Promise.resolve(Oe);
|
|
484
|
+
const R = a.get(p);
|
|
485
|
+
if (R !== void 0) {
|
|
486
|
+
if (n() - R.loadedAt < e) return Promise.resolve(R.tree);
|
|
469
487
|
a.delete(p);
|
|
470
488
|
}
|
|
471
|
-
const
|
|
472
|
-
return
|
|
489
|
+
const v = s.get(p);
|
|
490
|
+
return y(p, v === void 0 ? f(p, x) : v, h);
|
|
473
491
|
},
|
|
474
|
-
refresh: (p,
|
|
475
|
-
if (
|
|
476
|
-
|
|
477
|
-
const
|
|
478
|
-
return
|
|
492
|
+
refresh: (p, h, x) => {
|
|
493
|
+
if (h.aborted) return Promise.resolve(Oe);
|
|
494
|
+
k(p);
|
|
495
|
+
const R = s.get(p);
|
|
496
|
+
return R === void 0 ? y(p, f(p, x), h) : (R.state.loadTree = x, y(p, R, h));
|
|
479
497
|
},
|
|
480
|
-
forget:
|
|
498
|
+
forget: k
|
|
481
499
|
};
|
|
482
|
-
},
|
|
500
|
+
}, _n = (e) => ({
|
|
483
501
|
load: (t, r, n) => n(r, e()).then(be),
|
|
484
502
|
refresh: (t, r, n) => n(r, e()).then(be),
|
|
485
503
|
forget: () => {
|
|
486
504
|
}
|
|
487
505
|
}), $ = (e) => {
|
|
488
506
|
throw new TypeError(`[markdown-explorer] ${e}`);
|
|
489
|
-
},
|
|
507
|
+
}, Rn = (e) => {
|
|
490
508
|
if (e === null || typeof e != "object") return null;
|
|
491
509
|
const { name: t, path: r } = e;
|
|
492
|
-
return typeof t != "string" || typeof r != "string" ? null : t === "" ? { path: r, reason: "an empty name" } :
|
|
493
|
-
},
|
|
510
|
+
return typeof t != "string" || typeof r != "string" ? null : t === "" ? { path: r, reason: "an empty name" } : ee(r) ? null : { path: r, reason: "a path the browser cannot address (empty, too long, a lone surrogate, a control character or a backslash)" };
|
|
511
|
+
}, An = (e, t, r, n) => {
|
|
494
512
|
if (e === null) return null;
|
|
495
513
|
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}`);
|
|
496
514
|
const a = /* @__PURE__ */ new Set();
|
|
497
515
|
for (const s of e) {
|
|
498
|
-
if (typeof s != "string" || !
|
|
516
|
+
if (typeof s != "string" || !ee(s)) throw new TypeError("[markdown-explorer] a source's ancestors held a path the explorer does not accept");
|
|
499
517
|
if (r.deniesPath(s)) throw new TypeError("[markdown-explorer] a source's ancestors held a denied path");
|
|
500
518
|
if (!n(s)) throw new TypeError("[markdown-explorer] a source's ancestors held a path outside the source's boundary");
|
|
501
519
|
if (s === t) throw new TypeError("[markdown-explorer] a source's ancestors held the document itself");
|
|
@@ -503,44 +521,44 @@ const Pr = (e) => e instanceof Error && Object.hasOwn(e, ht) && lt(e.reason), $r
|
|
|
503
521
|
a.add(s);
|
|
504
522
|
}
|
|
505
523
|
return Object.freeze([...a]);
|
|
506
|
-
},
|
|
507
|
-
const s = /* @__PURE__ */ new Set(), c = (
|
|
508
|
-
if (!Array.isArray(
|
|
509
|
-
const
|
|
510
|
-
for (const p of
|
|
511
|
-
const
|
|
512
|
-
|
|
524
|
+
}, Nn = (e, t, r, n, a) => {
|
|
525
|
+
const s = /* @__PURE__ */ new Set(), c = (y) => {
|
|
526
|
+
if (!Array.isArray(y)) return $("a source returned entries that are not an array");
|
|
527
|
+
const k = [];
|
|
528
|
+
for (const p of y) {
|
|
529
|
+
const h = f(p);
|
|
530
|
+
h !== null && k.push(h);
|
|
513
531
|
}
|
|
514
|
-
return
|
|
515
|
-
}, f = (
|
|
516
|
-
const
|
|
517
|
-
if (
|
|
518
|
-
return n(
|
|
519
|
-
const p =
|
|
532
|
+
return k;
|
|
533
|
+
}, f = (y) => {
|
|
534
|
+
const k = Rn(y);
|
|
535
|
+
if (k !== null)
|
|
536
|
+
return n(k), null;
|
|
537
|
+
const p = Bt(y);
|
|
520
538
|
if (p !== null) return $(p);
|
|
521
|
-
const
|
|
522
|
-
if (s.has(
|
|
523
|
-
const { name:
|
|
524
|
-
if (t.deniesName(
|
|
525
|
-
if (!a(
|
|
526
|
-
return n({ path:
|
|
527
|
-
const S =
|
|
528
|
-
if (
|
|
529
|
-
if (
|
|
530
|
-
return r ? { ...S, type:
|
|
531
|
-
if (
|
|
532
|
-
s.add(
|
|
533
|
-
const
|
|
534
|
-
return s.delete(
|
|
539
|
+
const h = y;
|
|
540
|
+
if (s.has(h)) return $("a source returned entries that contain themselves");
|
|
541
|
+
const { name: x, path: R, type: v, mimeType: _, children: O, lazy: L } = h;
|
|
542
|
+
if (t.deniesName(x) || t.deniesPath(R)) return null;
|
|
543
|
+
if (!a(R))
|
|
544
|
+
return n({ path: R, reason: "a path outside the source's boundary" }), null;
|
|
545
|
+
const S = _ === void 0 ? { name: x, path: R } : { name: x, path: R, mimeType: _ };
|
|
546
|
+
if (v === "file") return { ...S, type: v };
|
|
547
|
+
if (L === !0)
|
|
548
|
+
return r ? { ...S, type: v, lazy: !0, children: [] } : $("a lazy directory came from a source without a children function");
|
|
549
|
+
if (O === void 0) return { ...S, type: v };
|
|
550
|
+
s.add(h);
|
|
551
|
+
const N = c(O);
|
|
552
|
+
return s.delete(h), { ...S, type: v, children: N };
|
|
535
553
|
};
|
|
536
554
|
return c(e);
|
|
537
|
-
},
|
|
555
|
+
}, In = /^[\x21\x23-\x7E]{1,256}$/u, xt = (e) => typeof e == "string" && In.test(e), Mn = /* @__PURE__ */ new Set(["text", "image", "media", "file"]), vn = (e) => typeof e == "string" && Mn.has(e), Pn = (e, t) => {
|
|
538
556
|
if (e !== null && typeof e == "object") {
|
|
539
557
|
const a = e, { kind: s } = a;
|
|
540
|
-
if (
|
|
558
|
+
if (vn(s)) {
|
|
541
559
|
if (Object.hasOwn(a, "url")) return $(`a ${s} document carries its version, not a url`);
|
|
542
560
|
if (typeof a.name != "string") return $("a document needs a name string");
|
|
543
|
-
if (!
|
|
561
|
+
if (!xt(a.version)) return $(`a ${s} document needs a version of 1 to 256 visible ASCII characters other than '"'`);
|
|
544
562
|
const c = t(a.version);
|
|
545
563
|
switch (s) {
|
|
546
564
|
case "image":
|
|
@@ -548,369 +566,380 @@ const Pr = (e) => e instanceof Error && Object.hasOwn(e, ht) && lt(e.reason), $r
|
|
|
548
566
|
return { kind: s, name: a.name, url: c };
|
|
549
567
|
case "media": {
|
|
550
568
|
const { mediaType: f } = a;
|
|
551
|
-
return
|
|
569
|
+
return Dt(f) ? { kind: s, name: a.name, url: c, mediaType: f } : $(`unknown media type ${typeof f == "string" ? JSON.stringify(f.slice(0, 64)) : typeof f}`);
|
|
552
570
|
}
|
|
553
571
|
case "text":
|
|
554
572
|
return typeof a.text != "string" || typeof a.truncated != "boolean" ? $("a text document needs text and truncated") : { kind: s, name: a.name, text: a.text, truncated: a.truncated, url: c };
|
|
555
573
|
}
|
|
556
574
|
}
|
|
557
575
|
}
|
|
558
|
-
const r =
|
|
576
|
+
const r = Ct(e);
|
|
559
577
|
if (r !== null) return $(r);
|
|
560
578
|
const n = e;
|
|
561
579
|
switch (n.kind) {
|
|
562
580
|
case "failure": {
|
|
563
581
|
const { reason: a, code: s } = n.failure;
|
|
564
|
-
return { kind: "failure", failure:
|
|
582
|
+
return { kind: "failure", failure: Re(a, s) };
|
|
565
583
|
}
|
|
566
584
|
case "markdown":
|
|
567
|
-
return n.headings.length >
|
|
585
|
+
return n.headings.length > Ht ? { kind: "failure", failure: Re("too-large") } : { kind: "unsanitized-markdown", name: n.name, html: n.htmlContent, headings: n.headings.map(({ text: a, depth: s, id: c }) => ({ text: a, depth: s, id: c })) };
|
|
568
586
|
}
|
|
569
|
-
},
|
|
587
|
+
}, qe = (e) => {
|
|
570
588
|
if (e === null || typeof e != "object") return $("an asset file must be an object");
|
|
571
589
|
const { name: t, contentType: r, size: n, version: a, open: s } = e;
|
|
572
|
-
return typeof t != "string" || t === "" ? $("an asset file needs a non-empty name") : typeof r != "string" ? $("an asset file needs a contentType string ('' when unknown)") : n !== null && !(typeof n == "number" && Number.isSafeInteger(n) && n >= 0) ? $("an asset file's size must be null or a non-negative safe integer") :
|
|
573
|
-
},
|
|
590
|
+
return typeof t != "string" || t === "" ? $("an asset file needs a non-empty name") : typeof r != "string" ? $("an asset file needs a contentType string ('' when unknown)") : n !== null && !(typeof n == "number" && Number.isSafeInteger(n) && n >= 0) ? $("an asset file's size must be null or a non-negative safe integer") : xt(a) ? typeof s != "function" ? $("an asset file needs an open function") : Object.freeze({ name: t, contentType: r, size: n, version: a, open: s }) : $(`an asset file needs a version of 1 to 256 visible ASCII characters other than '"'`);
|
|
591
|
+
}, $n = (e) => Array.isArray(e) ? e.map((t) => {
|
|
574
592
|
if (t === null || typeof t != "object") return $("a notice must be an object");
|
|
575
593
|
const { id: r, tone: n, title: a, body: s, action: c } = t;
|
|
576
594
|
if (typeof r != "string" || r === "" || typeof a != "string") return $("a notice needs an id and a title");
|
|
577
|
-
if (!
|
|
595
|
+
if (!jt(n)) return $(`unknown notice tone ${typeof n == "string" ? JSON.stringify(n.slice(0, 64)) : typeof n}`);
|
|
578
596
|
if (s !== void 0 && typeof s != "string") return $("a notice body must be a string");
|
|
579
|
-
const
|
|
580
|
-
if (c === void 0) return
|
|
597
|
+
const y = { id: r, tone: n, title: a, ...s === void 0 ? {} : { body: s } };
|
|
598
|
+
if (c === void 0) return y;
|
|
581
599
|
if (c === null || typeof c != "object") return $("a notice action must be an object");
|
|
582
|
-
const { label:
|
|
583
|
-
return typeof
|
|
584
|
-
}) : $("notices must be an array"),
|
|
600
|
+
const { label: k, href: p } = c;
|
|
601
|
+
return typeof k != "string" || !zt(p, Ft) ? $("a notice action needs a label and an http(s), mailto or relative href") : { ...y, action: { label: k, href: p } };
|
|
602
|
+
}) : $("notices must be an array"), Ln = 4e3, he = Object.freeze({ ttlMs: 3e5, maxEntries: 64, maxBytes: 64 * 1024 * 1024 }), et = 32, kt = "private, no-store", jn = Object.freeze({
|
|
585
603
|
"Content-Type": "application/json; charset=utf-8",
|
|
586
|
-
"Cache-Control":
|
|
604
|
+
"Cache-Control": kt,
|
|
587
605
|
"X-Content-Type-Options": "nosniff",
|
|
588
606
|
"Content-Security-Policy": "default-src 'none'; frame-ancestors 'none'; sandbox",
|
|
589
607
|
"Cross-Origin-Resource-Policy": "same-origin"
|
|
590
|
-
}),
|
|
608
|
+
}), zn = 22, Dn = 2147483647, _e = Object.freeze([]), Cn = Object.freeze({ status: "ok", source: null, ancestors: null }), tt = Object.freeze(["contains", "confirm"]), rt = Object.freeze({ readOnly: !1 }), Hn = Object.freeze({ readOnly: !0 }), Y = (e, t, r) => {
|
|
591
609
|
if (!(r && t === void 0) && typeof t != "function")
|
|
592
610
|
throw new TypeError(`[markdown-explorer] ${e} must be a function; got ${typeof t}`);
|
|
593
|
-
},
|
|
611
|
+
}, me = (e, t, r) => {
|
|
594
612
|
if (typeof t != "number") throw new TypeError(`[markdown-explorer] ${e} must be a number; got ${typeof t}`);
|
|
595
613
|
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)}`);
|
|
596
614
|
return t;
|
|
597
|
-
},
|
|
615
|
+
}, Bn = (e) => {
|
|
598
616
|
if (e === null || typeof e != "object" || !Object.isFrozen(e)) throw new TypeError("[markdown-explorer] config must be the value returned by defineExplorerConfig");
|
|
599
|
-
return
|
|
600
|
-
},
|
|
617
|
+
return tr(e);
|
|
618
|
+
}, nt = (e) => {
|
|
601
619
|
try {
|
|
602
620
|
return new Headers(e);
|
|
603
621
|
} catch {
|
|
604
622
|
throw new TypeError("[markdown-explorer] authenticate returned headers that are not a valid headers init (their values are not logged)");
|
|
605
623
|
}
|
|
606
|
-
},
|
|
624
|
+
}, ot = (e) => e instanceof Response ? new TypeError(`[markdown-explorer] authenticate threw a Response (status ${String(e.status)}), which a data request does not follow`) : e, Fn = (e) => {
|
|
607
625
|
if (typeof e != "string") throw new TypeError(`[markdown-explorer] scopeSecret must be a string; got ${typeof e}`);
|
|
608
|
-
if (e.length <
|
|
626
|
+
if (e.length < et) throw new RangeError(`[markdown-explorer] scopeSecret must have at least ${String(et)} characters; got ${String(e.length)}`);
|
|
609
627
|
return e;
|
|
610
|
-
},
|
|
611
|
-
if (!
|
|
628
|
+
}, Un = (e, t) => {
|
|
629
|
+
if (!ar(t)) throw new TypeError(`[markdown-explorer] ${e}.boundary must be a plain object { contains, confirm? }`);
|
|
612
630
|
for (const r of Object.keys(t))
|
|
613
|
-
if (!
|
|
614
|
-
|
|
615
|
-
},
|
|
631
|
+
if (!tt.includes(r)) throw new RangeError(`[markdown-explorer] ${e}.boundary.${r} is not an option; expected ${tt.join(", ")}`);
|
|
632
|
+
Y(`${e}.boundary.contains`, t.contains, !1), Y(`${e}.boundary.confirm`, t.confirm, !0);
|
|
633
|
+
}, Xn = (e) => {
|
|
616
634
|
if (!Array.isArray(e)) throw new TypeError("[markdown-explorer] sources must be an array");
|
|
617
635
|
const t = e;
|
|
618
636
|
if (t.length === 0) throw new RangeError("[markdown-explorer] sources must hold at least one source");
|
|
619
637
|
const r = /* @__PURE__ */ new Set();
|
|
620
638
|
for (const [n, a] of t.entries()) {
|
|
621
639
|
if (a === null || typeof a != "object") throw new TypeError(`[markdown-explorer] sources[${String(n)}] must be an object`);
|
|
622
|
-
const { id: s, label: c, boundary: f, tree:
|
|
623
|
-
if (!
|
|
640
|
+
const { id: s, label: c, boundary: f, tree: y, children: k, ancestors: p, cacheScope: h } = a;
|
|
641
|
+
if (!rr(s))
|
|
624
642
|
throw new RangeError(`[markdown-explorer] sources[${String(n)}].id must use lowercase letters, digits and "-" and start with a letter or digit; got ${typeof s == "string" ? JSON.stringify(s) : typeof s}`);
|
|
625
|
-
const
|
|
643
|
+
const x = `source ${JSON.stringify(s)}`;
|
|
626
644
|
if (r.has(s)) throw new RangeError(`[markdown-explorer] source ids must be unique; ${JSON.stringify(s)} repeats at sources[${String(n)}]`);
|
|
627
|
-
if (r.add(s), typeof c != "string" && typeof c != "function") throw new TypeError(`[markdown-explorer] ${
|
|
628
|
-
if (typeof c == "string" && c.trim() === "") throw new RangeError(`[markdown-explorer] ${
|
|
629
|
-
if (
|
|
645
|
+
if (r.add(s), typeof c != "string" && typeof c != "function") throw new TypeError(`[markdown-explorer] ${x}.label must be a string or a function`);
|
|
646
|
+
if (typeof c == "string" && c.trim() === "") throw new RangeError(`[markdown-explorer] ${x}.label must not be blank`);
|
|
647
|
+
if (Un(x, f), Y(`${x}.tree`, y, !1), Y(`${x}.children`, k, !0), Y(`${x}.ancestors`, p, !0), h !== void 0 && h !== "principal" && h !== "shared") throw new RangeError(`[markdown-explorer] ${x}.cacheScope must be "principal" or "shared"; got ${JSON.stringify(h)}`);
|
|
630
648
|
}
|
|
631
649
|
return t;
|
|
632
|
-
},
|
|
650
|
+
}, Gn = (e) => {
|
|
633
651
|
if (e === !1) return !1;
|
|
634
|
-
if (e === void 0) return
|
|
652
|
+
if (e === void 0) return he;
|
|
635
653
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] treeCache must be { ttlMs, maxEntries, maxBytes } or false");
|
|
636
654
|
const { ttlMs: t, maxEntries: r, maxBytes: n } = e;
|
|
637
655
|
return {
|
|
638
|
-
ttlMs: t === void 0 ?
|
|
639
|
-
maxEntries: r === void 0 ?
|
|
640
|
-
maxBytes: n === void 0 ?
|
|
656
|
+
ttlMs: t === void 0 ? he.ttlMs : me("treeCache.ttlMs", t, Number.MAX_SAFE_INTEGER),
|
|
657
|
+
maxEntries: r === void 0 ? he.maxEntries : me("treeCache.maxEntries", r, Number.MAX_SAFE_INTEGER),
|
|
658
|
+
maxBytes: n === void 0 ? he.maxBytes : me("treeCache.maxBytes", n, Number.MAX_SAFE_INTEGER)
|
|
641
659
|
};
|
|
642
|
-
},
|
|
660
|
+
}, st = (e) => {
|
|
643
661
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] authenticate must resolve to { status, ... }");
|
|
644
662
|
const { status: t } = e;
|
|
645
663
|
if (t !== "signed-in" && t !== "signed-out" && t !== "forbidden") throw new TypeError(`[markdown-explorer] authenticate resolved to an unknown status ${JSON.stringify(t)}`);
|
|
646
664
|
return e;
|
|
647
|
-
},
|
|
665
|
+
}, at = (e, t) => {
|
|
648
666
|
if (!(t instanceof Response)) throw new TypeError(`[markdown-explorer] ${e} must return a Response`);
|
|
649
667
|
return t;
|
|
650
|
-
},
|
|
668
|
+
}, it = (e, t) => {
|
|
651
669
|
if (typeof t != "string" || t === "") throw new TypeError("[markdown-explorer] principalKey must return a non-empty string");
|
|
652
|
-
return
|
|
653
|
-
},
|
|
670
|
+
return Wt("sha256", e).update(t, "utf8").digest("base64url").slice(0, zn);
|
|
671
|
+
}, Jn = (e) => e.view === "multi" ? e.docs : e.doc === null ? [] : [e.doc], fe = (e, t) => {
|
|
654
672
|
const r = e.getAll(t), [n] = r;
|
|
655
673
|
return r.length === 1 && n !== void 0 && n !== "" ? n : null;
|
|
656
|
-
},
|
|
674
|
+
}, oe = (e, t, r, n = {}) => {
|
|
657
675
|
const a = new Headers(r);
|
|
658
|
-
for (const [s, c] of Object.entries({ ...
|
|
676
|
+
for (const [s, c] of Object.entries({ ...jn, ...n })) a.set(s, c);
|
|
659
677
|
return new Response(t, { status: e, headers: a });
|
|
660
|
-
}, F = (e, t, r) =>
|
|
678
|
+
}, F = (e, t, r) => oe(Xt[e.reason], JSON.stringify({ failure: e }), t, r), ct = (e, t) => {
|
|
661
679
|
const r = t === "refresh" ? ["POST"] : ["GET", "HEAD"];
|
|
662
|
-
return r.includes(e.method.toUpperCase()) ? null :
|
|
663
|
-
},
|
|
664
|
-
if (e.headers.get(ft) !== Ht) return !1;
|
|
665
|
-
const t = e.headers.get("Sec-Fetch-Site");
|
|
666
|
-
return t === null || t === "same-origin";
|
|
667
|
-
}, Cn = ({ parentHeaders: e, loaderHeaders: t, errorHeaders: r }) => {
|
|
680
|
+
return r.includes(e.method.toUpperCase()) ? null : oe(405, JSON.stringify({ failure: { reason: "invalid" } }), void 0, { Allow: r.join(", ") });
|
|
681
|
+
}, ut = (e) => e.headers.get(wt) === Gt && Vt(e, Zt) === void 0, Yn = ({ parentHeaders: e, loaderHeaders: t, errorHeaders: r }) => {
|
|
668
682
|
const n = new Headers(), a = r === void 0 ? [e, t] : [e, t, r];
|
|
669
683
|
for (const s of a)
|
|
670
684
|
for (const [c, f] of s)
|
|
671
685
|
c !== "set-cookie" && n.set(c, f);
|
|
672
686
|
return n;
|
|
673
|
-
},
|
|
687
|
+
}, So = (e) => {
|
|
674
688
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] the server configuration must be an object");
|
|
675
|
-
const t =
|
|
676
|
-
|
|
677
|
-
const n =
|
|
689
|
+
const t = Bn(e.config), r = Fn(e.scopeSecret);
|
|
690
|
+
Y("authenticate", e.authenticate, !1), Y("principalKey", e.principalKey, !1), Y("document", e.document, !1), Y("asset", e.asset, !1), Y("signedOutPage", e.signedOutPage, !1), Y("forbiddenPage", e.forbiddenPage, !0), Y("notices", e.notices, !0), Y("onTreeRefreshed", e.onTreeRefreshed, !0);
|
|
691
|
+
const n = Xn(e.sources), a = qt(
|
|
678
692
|
t,
|
|
679
693
|
n.map((o) => o.id)
|
|
680
694
|
), s = e.logger;
|
|
681
695
|
if (s !== void 0 && (s === null || typeof s != "object" || typeof s.error != "function"))
|
|
682
696
|
throw new TypeError("[markdown-explorer] logger must be an object with an error function");
|
|
683
|
-
const c = e.logger === void 0 ?
|
|
697
|
+
const c = e.logger === void 0 ? Dr : e.logger, f = pt(e.deny), y = e.deferredTimeoutMs === void 0 ? Ln : me("deferredTimeoutMs", e.deferredTimeoutMs, Dn), k = e.textMaxBytes === void 0 ? Fr : me("textMaxBytes", e.textMaxBytes, Ur), p = Gn(e.treeCache), h = () => Date.now(), x = p === !1 ? _n(h) : On({ ...p, now: h }), R = yn(e.sanitizer, t.multiView.maxPanels), v = xn({ iframeHosts: t.iframeHosts, dataPath: t.dataPath, options: R, pool: bn(En(), R) }), _ = new Map(n.map((o) => [o.id, o])), O = er(t), { authenticate: L, principalKey: S, signedOutPage: N, forbiddenPage: H, onTreeRefreshed: j } = e, d = (o, l) => {
|
|
684
698
|
if (typeof o.label == "string") return o.label;
|
|
685
|
-
const i = o.label(
|
|
699
|
+
const i = o.label(l);
|
|
686
700
|
if (typeof i != "string" || i.trim() === "") throw new TypeError(`[markdown-explorer] the label of source ${JSON.stringify(o.id)} must be a non-blank string`);
|
|
687
701
|
return i;
|
|
688
|
-
},
|
|
689
|
-
const i = (m) =>
|
|
690
|
-
let
|
|
702
|
+
}, E = (o, l) => o.cacheScope === "shared" ? o.id : `${o.id}\0${l}`, w = (o, l) => {
|
|
703
|
+
const i = (m) => ne(c, { operation: "boundary", sourceId: o.id, path: l, error: m });
|
|
704
|
+
let u;
|
|
691
705
|
try {
|
|
692
|
-
|
|
706
|
+
u = o.boundary.contains(l);
|
|
693
707
|
} catch (m) {
|
|
694
708
|
return i(m), !1;
|
|
695
709
|
}
|
|
696
|
-
return typeof
|
|
697
|
-
},
|
|
698
|
-
const { confirm:
|
|
699
|
-
if (
|
|
710
|
+
return typeof u == "boolean" ? u : (Ye(u, i), i(new TypeError(`[markdown-explorer] boundary.contains of source ${JSON.stringify(o.id)} must return a boolean; got ${typeof u}`)), !1);
|
|
711
|
+
}, T = async (o, l, i) => {
|
|
712
|
+
const { confirm: u } = o.boundary;
|
|
713
|
+
if (u === void 0) return { status: "inside", readPath: i };
|
|
700
714
|
let m;
|
|
701
715
|
try {
|
|
702
|
-
m = await l
|
|
703
|
-
} catch (
|
|
704
|
-
return { status: "error", failure:
|
|
716
|
+
m = await u(l, i);
|
|
717
|
+
} catch (J) {
|
|
718
|
+
return { status: "error", failure: Z(J, { operation: "boundary", sourceId: o.id, path: i }, l.signal, c) };
|
|
705
719
|
}
|
|
706
|
-
const
|
|
707
|
-
if (m === null || typeof m != "object") return
|
|
708
|
-
const { inside:
|
|
709
|
-
return
|
|
710
|
-
},
|
|
711
|
-
const i = n.filter((m) =>
|
|
720
|
+
const g = (J) => (ne(c, { operation: "boundary", sourceId: o.id, path: i, error: new TypeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} ${J}`) }), { status: "outside" });
|
|
721
|
+
if (m === null || typeof m != "object") return g(`must resolve to { inside, readPath? }; got ${m === null ? "null" : typeof m}`);
|
|
722
|
+
const { inside: M, readPath: D } = m;
|
|
723
|
+
return M === !1 ? { status: "outside" } : M !== !0 || typeof D != "string" ? g("must resolve to { inside: false } or { inside: true, readPath: string }") : !ee(D) || f.deniesPath(D) ? (ne(c, { operation: "boundary", sourceId: o.id, path: i, error: new RangeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} answered a readPath the explorer does not serve (unacceptable or denied)`) }), { status: "error", failure: { reason: "failed" } }) : { status: "inside", readPath: D };
|
|
724
|
+
}, b = async (o, l) => {
|
|
725
|
+
const i = n.filter((m) => w(m, l));
|
|
712
726
|
if (i.length === 0) return { status: "error", failure: { reason: "forbidden" } };
|
|
713
|
-
if (i.some((m) => m.boundary.confirm === void 0)) return { status: "inside", readPath:
|
|
714
|
-
let
|
|
727
|
+
if (i.some((m) => m.boundary.confirm === void 0)) return { status: "inside", readPath: l };
|
|
728
|
+
let u = null;
|
|
715
729
|
for (const m of i) {
|
|
716
|
-
const
|
|
717
|
-
if (
|
|
718
|
-
|
|
730
|
+
const g = await T(m, o, l);
|
|
731
|
+
if (g.status === "inside") return g;
|
|
732
|
+
g.status === "error" && u === null && (u = g.failure);
|
|
719
733
|
}
|
|
720
|
-
return { status: "error", failure:
|
|
721
|
-
},
|
|
722
|
-
const
|
|
734
|
+
return { status: "error", failure: u === null ? { reason: "forbidden" } : u };
|
|
735
|
+
}, A = (o, l, i) => {
|
|
736
|
+
const u = ({ path: m, reason: g }) => Br(c, { operation: i.operation, sourceId: i.sourceId, path: m, error: new TypeError(`[markdown-explorer] an entry with ${g} was left out`) });
|
|
723
737
|
try {
|
|
724
|
-
return { status: "ok", entries:
|
|
738
|
+
return { status: "ok", entries: Nn(o, f, l.children !== void 0, u, (m) => w(l, m)) };
|
|
725
739
|
} catch (m) {
|
|
726
|
-
return
|
|
740
|
+
return ne(c, { ...i, error: m }), { status: "error", failure: { reason: "failed" } };
|
|
727
741
|
}
|
|
728
|
-
},
|
|
729
|
-
let
|
|
742
|
+
}, P = async (o, l, i) => {
|
|
743
|
+
let u;
|
|
730
744
|
try {
|
|
731
|
-
|
|
732
|
-
} catch (
|
|
733
|
-
return { status: "error", failure:
|
|
745
|
+
u = await o.tree(l);
|
|
746
|
+
} catch (g) {
|
|
747
|
+
return { status: "error", failure: Z(g, { operation: "tree", sourceId: o.id }, l.signal, c) };
|
|
734
748
|
}
|
|
735
|
-
const m =
|
|
749
|
+
const m = A(u, o, { operation: "tree", sourceId: o.id });
|
|
736
750
|
return m.status === "ok" ? { status: "ok", entries: m.entries, loadedAt: i } : m;
|
|
737
|
-
},
|
|
738
|
-
if (
|
|
739
|
-
const i = (
|
|
751
|
+
}, B = (o, l, i, u) => (m, g) => P(o, { principal: l, request: i, signal: m, refresh: u }, g), I = (o, l, i, u, m) => x.load(E(o, i), m, B(o, l, u, !1)), X = (o, l, i, u) => x.refresh(E(o, i), u.signal, B(o, l, u, !0)), W = (o, l) => {
|
|
752
|
+
if (j === void 0) return;
|
|
753
|
+
const i = (u) => ne(c, { operation: "refresh", sourceId: o.id, error: u });
|
|
740
754
|
try {
|
|
741
|
-
|
|
742
|
-
} catch (
|
|
743
|
-
i(
|
|
755
|
+
Ye(j(l), i);
|
|
756
|
+
} catch (u) {
|
|
757
|
+
i(u);
|
|
744
758
|
}
|
|
745
|
-
},
|
|
746
|
-
if (f.deniesPath(
|
|
747
|
-
const m = await
|
|
759
|
+
}, U = async (o, l, i, u) => {
|
|
760
|
+
if (f.deniesPath(u) || !w(o, u)) return { status: "error", failure: { reason: "forbidden" } };
|
|
761
|
+
const m = await T(o, i, u);
|
|
748
762
|
if (m.status === "outside") return { status: "error", failure: { reason: "forbidden" } };
|
|
749
763
|
if (m.status === "error") return { status: "error", failure: m.failure };
|
|
750
|
-
let
|
|
764
|
+
let g;
|
|
751
765
|
try {
|
|
752
|
-
|
|
753
|
-
} catch (
|
|
754
|
-
return { status: "error", failure:
|
|
766
|
+
g = await l(i, u, m.readPath);
|
|
767
|
+
} catch (M) {
|
|
768
|
+
return { status: "error", failure: Z(M, { operation: "children", sourceId: o.id, path: u }, i.signal, c) };
|
|
755
769
|
}
|
|
756
|
-
return
|
|
757
|
-
},
|
|
758
|
-
const m = await
|
|
770
|
+
return A(g, o, { operation: "children", sourceId: o.id, path: u });
|
|
771
|
+
}, re = async (o, l, i, u) => {
|
|
772
|
+
const m = await T(o, i, u);
|
|
759
773
|
if (m.status === "outside") return { status: "ok", ancestors: null };
|
|
760
774
|
if (m.status === "error") return { status: "error", failure: m.failure };
|
|
761
|
-
let
|
|
775
|
+
let g;
|
|
762
776
|
try {
|
|
763
|
-
|
|
764
|
-
} catch (
|
|
765
|
-
return { status: "error", failure:
|
|
777
|
+
g = await l(i, u, m.readPath, { maxDepth: t.revealDocument.maxDepth });
|
|
778
|
+
} catch (M) {
|
|
779
|
+
return { status: "error", failure: Z(M, { operation: "ancestors", sourceId: o.id, path: u }, i.signal, c) };
|
|
766
780
|
}
|
|
767
|
-
if (Array.isArray(
|
|
781
|
+
if (Array.isArray(g) && g.length > t.revealDocument.maxDepth) return { status: "ok", ancestors: null };
|
|
768
782
|
try {
|
|
769
|
-
return { status: "ok", ancestors:
|
|
770
|
-
} catch (
|
|
771
|
-
return
|
|
783
|
+
return { status: "ok", ancestors: An(g, u, f, (M) => w(o, M)) };
|
|
784
|
+
} catch (M) {
|
|
785
|
+
return ne(c, { operation: "ancestors", sourceId: o.id, path: u, error: M }), { status: "error", failure: { reason: "failed" } };
|
|
772
786
|
}
|
|
773
|
-
},
|
|
787
|
+
}, z = async (o, l, i, u) => f.deniesPath(u) ? { status: "error", failure: { reason: "forbidden" } } : w(o, u) ? re(o, l, i, u) : { status: "ok", ancestors: null }, K = async (o, l, i) => {
|
|
774
788
|
if (f.deniesPath(i)) return { status: "error", failure: { reason: "forbidden" } };
|
|
775
|
-
for (const
|
|
776
|
-
if (
|
|
777
|
-
const m =
|
|
778
|
-
if (m === void 0 || !
|
|
779
|
-
const
|
|
780
|
-
if (
|
|
789
|
+
for (const u of [o, ...n.filter((m) => m !== o)]) {
|
|
790
|
+
if (l.signal.aborted) break;
|
|
791
|
+
const m = u.ancestors;
|
|
792
|
+
if (m === void 0 || !w(u, i)) continue;
|
|
793
|
+
const g = await re(u, m, l, i);
|
|
794
|
+
if (g.status === "ok" && g.ancestors !== null) return { status: "ok", source: u.id, ancestors: g.ancestors };
|
|
781
795
|
}
|
|
782
|
-
return
|
|
783
|
-
},
|
|
784
|
-
if (f.deniesPath(i)) return
|
|
785
|
-
const
|
|
786
|
-
if (
|
|
796
|
+
return Cn;
|
|
797
|
+
}, V = async (o, l, i) => {
|
|
798
|
+
if (f.deniesPath(i)) return te("forbidden");
|
|
799
|
+
const u = await b(o, i);
|
|
800
|
+
if (u.status === "error") return { kind: "failure", failure: u.failure };
|
|
787
801
|
let m;
|
|
788
802
|
try {
|
|
789
|
-
m = await e.document(o, i,
|
|
790
|
-
} catch (
|
|
791
|
-
return { kind: "failure", failure:
|
|
803
|
+
m = await e.document(o, i, u.readPath);
|
|
804
|
+
} catch (D) {
|
|
805
|
+
return { kind: "failure", failure: Z(D, { operation: "document", path: i }, o.signal, c) };
|
|
792
806
|
}
|
|
793
|
-
let
|
|
807
|
+
let g;
|
|
794
808
|
try {
|
|
795
|
-
|
|
796
|
-
} catch (
|
|
797
|
-
return
|
|
809
|
+
g = Pn(m, (D) => je(t.dataPath, i, D));
|
|
810
|
+
} catch (D) {
|
|
811
|
+
return ne(c, { operation: "document", path: i, error: D }), te("failed");
|
|
798
812
|
}
|
|
799
|
-
if (
|
|
800
|
-
const
|
|
801
|
-
return
|
|
802
|
-
},
|
|
803
|
-
if (e.notices === void 0) return
|
|
813
|
+
if (g.kind !== "unsanitized-markdown") return g;
|
|
814
|
+
const M = await v(g.html, { scope: l, signal: o.signal });
|
|
815
|
+
return M.status === "sanitized" ? { kind: "markdown", name: g.name, htmlContent: M.html, headings: g.headings } : (M.cause !== null && ne(c, { operation: "document", path: i, error: M.cause }), te(M.reason));
|
|
816
|
+
}, Q = async (o) => {
|
|
817
|
+
if (e.notices === void 0) return _e;
|
|
804
818
|
try {
|
|
805
|
-
return
|
|
806
|
-
} catch (
|
|
807
|
-
return
|
|
819
|
+
return $n(await e.notices(o));
|
|
820
|
+
} catch (l) {
|
|
821
|
+
return Z(l, { operation: "notices" }, o.signal, c), _e;
|
|
808
822
|
}
|
|
809
|
-
},
|
|
810
|
-
const
|
|
811
|
-
if (
|
|
812
|
-
if (f.deniesPath(
|
|
813
|
-
return
|
|
814
|
-
const m = await
|
|
823
|
+
}, pe = async (o, l, i) => {
|
|
824
|
+
const u = fe(l, de.path);
|
|
825
|
+
if (u === null || !ee(u)) return F({ reason: "invalid" }, i);
|
|
826
|
+
if (f.deniesPath(u))
|
|
827
|
+
return Je(c, { operation: "asset", path: u }), F({ reason: "forbidden" }, i);
|
|
828
|
+
const m = await b(o, u);
|
|
815
829
|
if (m.status === "error") return F(m.failure, i);
|
|
816
830
|
try {
|
|
817
|
-
const
|
|
818
|
-
return await
|
|
819
|
-
} catch (
|
|
820
|
-
return F(
|
|
831
|
+
const g = qe(await e.asset(o, u, m.readPath));
|
|
832
|
+
return await zr(o.request, g, i);
|
|
833
|
+
} catch (g) {
|
|
834
|
+
return F(Z(g, { operation: "asset", path: u }, o.signal, c), i);
|
|
835
|
+
}
|
|
836
|
+
}, It = async (o, l) => {
|
|
837
|
+
if (f.deniesPath(l))
|
|
838
|
+
return Je(c, { operation: "text", path: l }), te("forbidden");
|
|
839
|
+
const i = await b(o, l);
|
|
840
|
+
if (i.status === "error") return { kind: "failure", failure: i.failure };
|
|
841
|
+
try {
|
|
842
|
+
const u = qe(await e.asset(o, l, i.readPath)), m = await Gr(u, k);
|
|
843
|
+
return m === null ? te("unsupported") : { kind: "text", name: u.name, text: m.text, truncated: m.truncated, url: je(t.dataPath, l, u.version) };
|
|
844
|
+
} catch (u) {
|
|
845
|
+
return { kind: "failure", failure: Z(u, { operation: "text", path: l }, o.signal, c) };
|
|
821
846
|
}
|
|
822
|
-
},
|
|
823
|
-
const
|
|
824
|
-
if (m.set("Cache-Control",
|
|
825
|
-
if (
|
|
826
|
-
const
|
|
827
|
-
if (
|
|
828
|
-
const { location:
|
|
829
|
-
if (
|
|
830
|
-
const le = { signal: o.signal, timeoutMs:
|
|
831
|
-
scope:
|
|
832
|
-
sources: n.map((
|
|
833
|
-
settings:
|
|
834
|
-
tree:
|
|
835
|
-
sourceId:
|
|
836
|
-
result: xe(le, (
|
|
847
|
+
}, Mt = async ({ request: o, url: l, params: i }) => {
|
|
848
|
+
const u = st(await L(o, rt)), m = nt(u.headers);
|
|
849
|
+
if (m.set("Cache-Control", kt), u.status === "signed-out") throw at("signedOutPage", N(o, m));
|
|
850
|
+
if (u.status === "forbidden") throw H === void 0 ? ze(null, { status: 403, headers: m }) : at("forbiddenPage", H(o, m));
|
|
851
|
+
const g = nr(a, i["*"], l.searchParams);
|
|
852
|
+
if (g.kind === "redirect") throw Qt(g.href, { headers: m });
|
|
853
|
+
const { location: M } = g, { principal: D } = u, J = it(r, S(D)), se = _.get(M.source);
|
|
854
|
+
if (se === void 0) throw new RangeError(`[markdown-explorer] no source for ${JSON.stringify(M.source)}`);
|
|
855
|
+
const le = { signal: o.signal, timeoutMs: y, late: null, handOverMs: y }, q = {
|
|
856
|
+
scope: J,
|
|
857
|
+
sources: n.map((C) => ({ id: C.id, label: d(C, D) })),
|
|
858
|
+
settings: or(sr(o.headers.get("Cookie"), t.settingsCookie), O),
|
|
859
|
+
tree: M.view === "single" ? null : {
|
|
860
|
+
sourceId: M.source,
|
|
861
|
+
result: xe(le, (C) => I(se, D, J, o, C).then((G) => G.result))
|
|
837
862
|
},
|
|
838
|
-
documents:
|
|
839
|
-
notices: xe({ signal: o.signal, timeoutMs:
|
|
863
|
+
documents: Jn(M).map((C) => ({ path: C, document: xe(le, (G) => V({ principal: D, request: o, signal: G, refresh: !1 }, J, C)) })),
|
|
864
|
+
notices: xe({ signal: o.signal, timeoutMs: y, late: _e, handOverMs: 0 }, (C) => Q({ principal: D, request: o, signal: C, refresh: !1 }))
|
|
840
865
|
};
|
|
841
|
-
return
|
|
842
|
-
},
|
|
843
|
-
const i =
|
|
844
|
-
return { authentication: i, headers:
|
|
845
|
-
},
|
|
846
|
-
let
|
|
866
|
+
return ze(q, { headers: m });
|
|
867
|
+
}, ve = async (o, l) => {
|
|
868
|
+
const i = st(await L(o, l));
|
|
869
|
+
return { authentication: i, headers: nt(i.headers) };
|
|
870
|
+
}, vt = async (o, l, i) => {
|
|
871
|
+
let u;
|
|
847
872
|
try {
|
|
848
|
-
|
|
849
|
-
} catch (
|
|
850
|
-
return F(
|
|
873
|
+
u = await ve(l, rt);
|
|
874
|
+
} catch (G) {
|
|
875
|
+
return F(Z(ot(G), { operation: "authenticate" }, l.signal, c));
|
|
851
876
|
}
|
|
852
|
-
const { authentication: m, headers:
|
|
853
|
-
if (m.status === "signed-out") return F({ reason: "unauthorized" },
|
|
854
|
-
if (m.status === "forbidden") return F({ reason: "forbidden" },
|
|
855
|
-
const { principal:
|
|
856
|
-
if (o === "asset") return
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
const
|
|
877
|
+
const { authentication: m, headers: g } = u;
|
|
878
|
+
if (m.status === "signed-out") return F({ reason: "unauthorized" }, g);
|
|
879
|
+
if (m.status === "forbidden") return F({ reason: "forbidden" }, g);
|
|
880
|
+
const { principal: M } = m;
|
|
881
|
+
if (o === "asset") return pe({ principal: M, request: l, signal: l.signal, refresh: !1 }, i, g);
|
|
882
|
+
const D = it(r, S(M));
|
|
883
|
+
g.set(Jt, D);
|
|
884
|
+
const J = { principal: M, request: l, signal: l.signal, refresh: !1 }, se = () => F({ reason: "invalid" }, g);
|
|
860
885
|
if (o === "document") {
|
|
861
|
-
const
|
|
862
|
-
if (
|
|
863
|
-
const
|
|
864
|
-
return
|
|
886
|
+
const G = fe(i, de.path);
|
|
887
|
+
if (G === null || !ee(G)) return se();
|
|
888
|
+
const Le = l.headers.has(wt);
|
|
889
|
+
return Le && !ut(l) ? F({ reason: "forbidden" }, g) : oe(200, JSON.stringify(await V({ ...J, refresh: Le }, D, G)), g);
|
|
890
|
+
}
|
|
891
|
+
if (o === "text") {
|
|
892
|
+
const G = fe(i, de.path);
|
|
893
|
+
return G === null || !ee(G) ? se() : oe(200, JSON.stringify(await It(J, G)), g);
|
|
865
894
|
}
|
|
866
|
-
const le =
|
|
867
|
-
if (le === null || (o === "children" || o === "ancestors" || o === "reveal") && (
|
|
868
|
-
const
|
|
869
|
-
if (
|
|
870
|
-
if (o === "tree") return
|
|
895
|
+
const le = fe(i, de.source), q = fe(i, de.path);
|
|
896
|
+
if (le === null || (o === "children" || o === "ancestors" || o === "reveal") && (q === null || !ee(q))) return se();
|
|
897
|
+
const C = _.get(le);
|
|
898
|
+
if (C === void 0) return F({ reason: "not-found" }, g);
|
|
899
|
+
if (o === "tree") return oe(200, (await I(C, M, D, l, l.signal)).json, g);
|
|
871
900
|
if (o === "refresh") {
|
|
872
|
-
const
|
|
873
|
-
return
|
|
901
|
+
const G = await X(C, M, D, l);
|
|
902
|
+
return l.signal.aborted || W(C, E(C, D)), oe(200, G.json, g);
|
|
874
903
|
}
|
|
875
|
-
return o === "ancestors" ?
|
|
876
|
-
},
|
|
877
|
-
const { authentication:
|
|
904
|
+
return o === "ancestors" ? C.ancestors === void 0 || q === null ? F({ reason: "not-found" }, g) : oe(200, JSON.stringify(await z(C, C.ancestors, J, q)), g) : o === "reveal" ? q === null ? se() : oe(200, JSON.stringify(await K(C, J, q)), g) : C.children === void 0 || q === null ? F({ reason: "not-found" }, g) : oe(200, JSON.stringify(await U(C, C.children, J, q)), g);
|
|
905
|
+
}, Pt = async (o) => {
|
|
906
|
+
const { authentication: l, headers: i } = await ve(o, Hn);
|
|
878
907
|
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)");
|
|
879
|
-
return
|
|
880
|
-
}, Pe = t.embeds.linkCardEndpoint === null ? null :
|
|
908
|
+
return l.status === "signed-in";
|
|
909
|
+
}, Pe = t.embeds.linkCardEndpoint === null ? null : Kt({ authorize: Pt }), $t = async (o, l) => {
|
|
881
910
|
try {
|
|
882
|
-
return await o(
|
|
911
|
+
return await o(l);
|
|
883
912
|
} catch (i) {
|
|
884
|
-
return F(
|
|
913
|
+
return F(Z(ot(i), { operation: "authenticate" }, l.signal, c));
|
|
885
914
|
}
|
|
886
|
-
}, $e = async (o,
|
|
915
|
+
}, $e = async (o, l, i) => {
|
|
887
916
|
if (new URL(o.url).pathname.endsWith(".data")) return F({ reason: "not-found" });
|
|
888
|
-
if (!
|
|
917
|
+
if (!Ut(i)) return F({ reason: "not-found" });
|
|
889
918
|
if (i === "link-card") {
|
|
890
919
|
if (Pe === null) return F({ reason: "not-found" });
|
|
891
|
-
const m =
|
|
892
|
-
return m !== null ? m :
|
|
920
|
+
const m = ct(o, i);
|
|
921
|
+
return m !== null ? m : $t(Pe, o);
|
|
893
922
|
}
|
|
894
|
-
const
|
|
895
|
-
if (
|
|
896
|
-
if (i === "refresh" && !
|
|
923
|
+
const u = ct(o, i);
|
|
924
|
+
if (u !== null) return u;
|
|
925
|
+
if (i === "refresh" && !ut(o)) return F({ reason: "forbidden" });
|
|
897
926
|
try {
|
|
898
|
-
return await
|
|
927
|
+
return await vt(i, o, l.searchParams);
|
|
899
928
|
} catch (m) {
|
|
900
|
-
return F(
|
|
929
|
+
return F(Z(m, { operation: i }, o.signal, c));
|
|
901
930
|
}
|
|
902
931
|
};
|
|
903
932
|
return Object.freeze({
|
|
904
|
-
loader:
|
|
905
|
-
headers:
|
|
906
|
-
dataLoader: ({ request: o, url:
|
|
907
|
-
dataAction: ({ request: o, url:
|
|
933
|
+
loader: Mt,
|
|
934
|
+
headers: Yn,
|
|
935
|
+
dataLoader: ({ request: o, url: l, params: i }) => $e(o, l, i["*"]),
|
|
936
|
+
dataAction: ({ request: o, url: l, params: i }) => $e(o, l, i["*"]),
|
|
908
937
|
forgetTree: (o) => {
|
|
909
938
|
if (typeof o != "string") throw new TypeError(`[markdown-explorer] forgetTree needs the string key onTreeRefreshed received; got ${typeof o}`);
|
|
910
|
-
|
|
939
|
+
x.forget(o);
|
|
911
940
|
}
|
|
912
941
|
});
|
|
913
|
-
},
|
|
942
|
+
}, ge = Object.freeze({ maxEntries: 2e4, maxDocumentBytes: 2 * 1024 * 1024, textPreviewBytes: 8 * 1024, walkConcurrency: 8 }), Wn = /* @__PURE__ */ new Set(["md", "markdown", "mdx"]), Ot = new Map([
|
|
914
943
|
...[
|
|
915
944
|
["png", "image/png"],
|
|
916
945
|
["jpg", "image/jpeg"],
|
|
@@ -945,7 +974,7 @@ const Pr = (e) => e instanceof Error && Object.hasOwn(e, ht) && lt(e.reason), $r
|
|
|
945
974
|
["wma", "audio/x-ms-wma"]
|
|
946
975
|
].map(([e, t]) => [e, { kind: "media", mediaType: "audio", contentType: t }]),
|
|
947
976
|
["pdf", { kind: "media", mediaType: "pdf", contentType: "application/pdf" }]
|
|
948
|
-
]),
|
|
977
|
+
]), Kn = /* @__PURE__ */ new Set([
|
|
949
978
|
"txt",
|
|
950
979
|
"text",
|
|
951
980
|
"log",
|
|
@@ -1070,7 +1099,7 @@ const Pr = (e) => e instanceof Error && Object.hasOwn(e, ht) && lt(e.reason), $r
|
|
|
1070
1099
|
"eslintrc",
|
|
1071
1100
|
"babelrc",
|
|
1072
1101
|
"mailmap"
|
|
1073
|
-
]),
|
|
1102
|
+
]), Vn = /* @__PURE__ */ new Set([
|
|
1074
1103
|
"readme",
|
|
1075
1104
|
"license",
|
|
1076
1105
|
"licence",
|
|
@@ -1091,17 +1120,17 @@ const Pr = (e) => e instanceof Error && Object.hasOwn(e, ht) && lt(e.reason), $r
|
|
|
1091
1120
|
"jenkinsfile",
|
|
1092
1121
|
"brewfile",
|
|
1093
1122
|
"codeowners"
|
|
1094
|
-
]),
|
|
1123
|
+
]), _t = typeof ue.O_NOFOLLOW == "number" ? ue.O_NOFOLLOW : 0, Rt = typeof ue.O_NONBLOCK == "number" ? ue.O_NONBLOCK : 0, lt = (e) => `${e.size}-${e.mtimeNs}`, Zn = (e) => e !== "" && e !== "." && e !== ".." && !e.includes(":") && !e.endsWith(".") && !e.endsWith(" "), dt = (e) => ee(e) && e === e.normalize("NFC") && e.split("/").every(Zn), At = (e) => {
|
|
1095
1124
|
const t = e.toLowerCase(), r = t.lastIndexOf(".");
|
|
1096
1125
|
return r < 0 ? "" : t.slice(r + 1);
|
|
1097
|
-
},
|
|
1098
|
-
const t =
|
|
1099
|
-
if (
|
|
1100
|
-
const r =
|
|
1126
|
+
}, Qn = (e) => {
|
|
1127
|
+
const t = At(e);
|
|
1128
|
+
if (Wn.has(t)) return { kind: "markdown" };
|
|
1129
|
+
const r = Ot.get(t);
|
|
1101
1130
|
if (r !== void 0) return r.kind === "image" ? { kind: "image" } : { kind: "media", mediaType: r.mediaType };
|
|
1102
1131
|
const n = e.toLowerCase();
|
|
1103
|
-
return
|
|
1104
|
-
},
|
|
1132
|
+
return Kn.has(t) || !n.includes(".") && Vn.has(n) ? { kind: "text" } : { kind: "file" };
|
|
1133
|
+
}, Ne = (e) => {
|
|
1105
1134
|
switch (typeof e == "object" && e !== null ? e.code : void 0) {
|
|
1106
1135
|
case "ENOENT":
|
|
1107
1136
|
case "ENOTDIR":
|
|
@@ -1117,34 +1146,34 @@ const Pr = (e) => e instanceof Error && Object.hasOwn(e, ht) && lt(e.reason), $r
|
|
|
1117
1146
|
default:
|
|
1118
1147
|
return null;
|
|
1119
1148
|
}
|
|
1120
|
-
},
|
|
1121
|
-
const t =
|
|
1149
|
+
}, Nt = (e) => {
|
|
1150
|
+
const t = Ne(e);
|
|
1122
1151
|
return t === null ? e : new Ee(t);
|
|
1123
|
-
},
|
|
1152
|
+
}, qn = (e) => {
|
|
1124
1153
|
const t = typeof e == "object" && e !== null ? e.code : void 0;
|
|
1125
1154
|
return t === "EACCES" || t === "EPERM" || t === "ENOENT" || t === "ENOTDIR";
|
|
1126
|
-
},
|
|
1155
|
+
}, ft = async (e, t) => {
|
|
1127
1156
|
const r = [];
|
|
1128
1157
|
for await (const n of e.createReadStream({ start: 0, end: t - 1, autoClose: !1 }))
|
|
1129
1158
|
r.push(n);
|
|
1130
1159
|
return Buffer.concat(r);
|
|
1131
|
-
},
|
|
1160
|
+
}, eo = (e, t) => e !== null ? { start: e.offset, end: e.offset + e.length - 1 } : t === 0n ? {} : { start: 0, end: Number(t) - 1 }, to = async (e, t, r, n) => {
|
|
1132
1161
|
let a;
|
|
1133
1162
|
try {
|
|
1134
|
-
a = await
|
|
1135
|
-
const
|
|
1136
|
-
if (!
|
|
1137
|
-
} catch (
|
|
1138
|
-
throw await a?.close(),
|
|
1163
|
+
a = await ht(e, ue.O_RDONLY | _t | Rt);
|
|
1164
|
+
const y = await a.stat({ bigint: !0 });
|
|
1165
|
+
if (!y.isFile() || y.ino !== t.ino || y.dev !== t.dev || y.size !== t.size || y.mtimeNs !== t.mtimeNs) throw new Ee("not-found");
|
|
1166
|
+
} catch (y) {
|
|
1167
|
+
throw await a?.close(), Nt(y);
|
|
1139
1168
|
}
|
|
1140
|
-
const s = a.createReadStream(
|
|
1169
|
+
const s = a.createReadStream(eo(r, t.size)), c = yr.toWeb(s), f = () => {
|
|
1141
1170
|
s.destroy(n.reason);
|
|
1142
1171
|
};
|
|
1143
1172
|
return n.aborted ? f() : n.addEventListener("abort", f, { once: !0 }), c;
|
|
1144
|
-
},
|
|
1145
|
-
const r =
|
|
1173
|
+
}, ro = (e, t) => {
|
|
1174
|
+
const r = ir.compare(e, t);
|
|
1146
1175
|
return r !== 0 ? r : e === t ? 0 : e < t ? -1 : 1;
|
|
1147
|
-
},
|
|
1176
|
+
}, no = (e) => {
|
|
1148
1177
|
let t = 0;
|
|
1149
1178
|
const r = [];
|
|
1150
1179
|
return async (n) => {
|
|
@@ -1156,179 +1185,179 @@ const Pr = (e) => e instanceof Error && Object.hasOwn(e, ht) && lt(e.reason), $r
|
|
|
1156
1185
|
a === void 0 ? t -= 1 : a();
|
|
1157
1186
|
}
|
|
1158
1187
|
};
|
|
1159
|
-
},
|
|
1188
|
+
}, oo = (e, t) => {
|
|
1160
1189
|
if (e.isSymbolicLink()) return "symbolic-link";
|
|
1161
1190
|
if (!(e.isDirectory() || e.isFile())) return "special-file";
|
|
1162
1191
|
const { name: r } = e;
|
|
1163
|
-
return r !== r.normalize("NFC") ? "not-nfc" : r.includes(":") ? "colon" : r.endsWith(".") || r.endsWith(" ") ? "trailing-dot-or-space" :
|
|
1164
|
-
},
|
|
1192
|
+
return r !== r.normalize("NFC") ? "not-nfc" : r.includes(":") ? "colon" : r.endsWith(".") || r.endsWith(" ") ? "trailing-dot-or-space" : ee(r) ? ee(t) ? null : "path-too-long" : "control-character-or-backslash";
|
|
1193
|
+
}, so = /* @__PURE__ */ new Set(["id", "label", "root", "pathPrefix", "parse", "deny", "maxEntries", "maxDocumentBytes", "textPreviewBytes", "walkConcurrency", "cacheScope", "reportSkipped"]), ye = (e, t, r) => {
|
|
1165
1194
|
if (t === void 0) return r;
|
|
1166
1195
|
if (typeof t != "number" || !Number.isSafeInteger(t) || t <= 0) throw new RangeError(`[markdown-explorer] ${e} must be a positive integer; got ${String(t)}`);
|
|
1167
1196
|
return t;
|
|
1168
|
-
},
|
|
1197
|
+
}, To = (e) => {
|
|
1169
1198
|
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] createFileSystemSource needs an options object");
|
|
1170
|
-
for (const
|
|
1171
|
-
if (!
|
|
1199
|
+
for (const w of Object.keys(e))
|
|
1200
|
+
if (!so.has(w)) throw new TypeError(`[markdown-explorer] createFileSystemSource does not know the option ${JSON.stringify(w)}`);
|
|
1172
1201
|
const { id: t, label: r, root: n, parse: a } = e;
|
|
1173
1202
|
if (typeof t != "string" || t === "") throw new TypeError("[markdown-explorer] a file-system source needs a non-empty id");
|
|
1174
1203
|
if (typeof r != "string" || r.trim() === "") throw new TypeError("[markdown-explorer] a file-system source needs a non-blank label");
|
|
1175
1204
|
if (typeof a != "function") throw new TypeError("[markdown-explorer] a file-system source needs a parse function");
|
|
1176
|
-
if (typeof n != "string" || !
|
|
1205
|
+
if (typeof n != "string" || !De(n)) throw new RangeError(`[markdown-explorer] root must be an absolute path; got ${JSON.stringify(n)}`);
|
|
1177
1206
|
let s;
|
|
1178
1207
|
try {
|
|
1179
|
-
s =
|
|
1180
|
-
} catch (
|
|
1181
|
-
throw new RangeError(`[markdown-explorer] root does not exist: ${n}`, { cause:
|
|
1208
|
+
s = ur(n).isDirectory();
|
|
1209
|
+
} catch (w) {
|
|
1210
|
+
throw new RangeError(`[markdown-explorer] root does not exist: ${n}`, { cause: w });
|
|
1182
1211
|
}
|
|
1183
1212
|
if (!s) throw new RangeError(`[markdown-explorer] root is not a directory: ${n}`);
|
|
1184
|
-
const c =
|
|
1213
|
+
const c = lr(n), f = e.pathPrefix;
|
|
1185
1214
|
if (typeof f != "string") throw new TypeError('[markdown-explorer] pathPrefix is required: "" for a source over the whole root, or relative segments ending with "/"');
|
|
1186
|
-
if (f !== "" && !(f.endsWith("/") &&
|
|
1215
|
+
if (f !== "" && !(f.endsWith("/") && dt(f.slice(0, -1))))
|
|
1187
1216
|
throw new RangeError(`[markdown-explorer] pathPrefix must be empty or relative segments ending with "/"; got ${JSON.stringify(f)}`);
|
|
1188
|
-
const
|
|
1189
|
-
if (
|
|
1190
|
-
const
|
|
1191
|
-
if (
|
|
1192
|
-
const
|
|
1193
|
-
console.warn(`[markdown-explorer] the file-system source ${JSON.stringify(
|
|
1194
|
-
} :
|
|
1195
|
-
const T =
|
|
1196
|
-
return b === "" || b === ".." || b.startsWith(`..${
|
|
1197
|
-
}, S = (
|
|
1198
|
-
const b = `${T}\0${
|
|
1199
|
-
|
|
1200
|
-
},
|
|
1201
|
-
|
|
1217
|
+
const y = pt(e.deny), k = ye("maxEntries", e.maxEntries, ge.maxEntries), p = ye("maxDocumentBytes", e.maxDocumentBytes, ge.maxDocumentBytes), h = ye("textPreviewBytes", e.textPreviewBytes, ge.textPreviewBytes), x = ye("walkConcurrency", e.walkConcurrency, ge.walkConcurrency), R = e.cacheScope === void 0 ? "principal" : e.cacheScope;
|
|
1218
|
+
if (R !== "principal" && R !== "shared") throw new RangeError(`[markdown-explorer] cacheScope must be "principal" or "shared"; got ${JSON.stringify(R)}`);
|
|
1219
|
+
const v = e.reportSkipped;
|
|
1220
|
+
if (v !== void 0 && typeof v != "function") throw new TypeError("[markdown-explorer] reportSkipped must be a function");
|
|
1221
|
+
const _ = v === void 0 ? (w) => {
|
|
1222
|
+
console.warn(`[markdown-explorer] the file-system source ${JSON.stringify(w.sourceId)} does not list ${JSON.stringify(w.path)}: ${w.reason}`);
|
|
1223
|
+
} : v, O = /* @__PURE__ */ new Set(), L = (w) => {
|
|
1224
|
+
const T = mr(c, ...w.split("/")), b = Ce(c, T);
|
|
1225
|
+
return b === "" || b === ".." || b.startsWith(`..${He}`) || De(b) ? null : T;
|
|
1226
|
+
}, S = (w, T) => {
|
|
1227
|
+
const b = `${T}\0${w}`;
|
|
1228
|
+
O.has(b) || O.size >= k || (O.add(b), _({ sourceId: t, path: w, reason: T }));
|
|
1229
|
+
}, N = async ({ signal: w }) => {
|
|
1230
|
+
w.throwIfAborted();
|
|
1202
1231
|
const T = new AbortController(), b = () => {
|
|
1203
|
-
T.abort(
|
|
1232
|
+
T.abort(w.reason);
|
|
1204
1233
|
};
|
|
1205
|
-
|
|
1206
|
-
const
|
|
1234
|
+
w.addEventListener("abort", b, { once: !0 });
|
|
1235
|
+
const A = no(x);
|
|
1207
1236
|
let P = 0;
|
|
1208
|
-
const B = async (
|
|
1209
|
-
const
|
|
1237
|
+
const B = async (I, X) => {
|
|
1238
|
+
const W = await A(async () => {
|
|
1210
1239
|
T.signal.throwIfAborted();
|
|
1211
1240
|
try {
|
|
1212
|
-
return await
|
|
1213
|
-
} catch (
|
|
1214
|
-
if (
|
|
1241
|
+
return await gr(I, { withFileTypes: !0 });
|
|
1242
|
+
} catch (z) {
|
|
1243
|
+
if (X === "" || !qn(z)) throw z;
|
|
1215
1244
|
return null;
|
|
1216
1245
|
}
|
|
1217
1246
|
});
|
|
1218
|
-
if (T.signal.throwIfAborted(),
|
|
1219
|
-
return S(`${f}${
|
|
1247
|
+
if (T.signal.throwIfAborted(), W === null)
|
|
1248
|
+
return S(`${f}${X}`, "unreadable-directory"), null;
|
|
1220
1249
|
const U = [];
|
|
1221
|
-
for (const
|
|
1222
|
-
if (
|
|
1223
|
-
const
|
|
1224
|
-
if (
|
|
1225
|
-
S(V,
|
|
1250
|
+
for (const z of W) {
|
|
1251
|
+
if (y.deniesName(z.name)) continue;
|
|
1252
|
+
const K = X === "" ? z.name : `${X}/${z.name}`, V = `${f}${K}`, Q = oo(z, V);
|
|
1253
|
+
if (Q !== null) {
|
|
1254
|
+
S(V, Q);
|
|
1226
1255
|
continue;
|
|
1227
1256
|
}
|
|
1228
|
-
U.push({ dirent:
|
|
1257
|
+
U.push({ dirent: z, relativePath: K, path: V });
|
|
1229
1258
|
}
|
|
1230
|
-
if (P += U.length, P >
|
|
1231
|
-
return U.sort((
|
|
1232
|
-
U.map(async ({ dirent:
|
|
1233
|
-
if (!
|
|
1234
|
-
const
|
|
1235
|
-
return
|
|
1259
|
+
if (P += U.length, P > k) throw new Ee("too-large");
|
|
1260
|
+
return U.sort((z, K) => ro(z.dirent.name, K.dirent.name)), (await Promise.all(
|
|
1261
|
+
U.map(async ({ dirent: z, relativePath: K, path: V }) => {
|
|
1262
|
+
if (!z.isDirectory()) return { name: z.name, path: V, type: "file" };
|
|
1263
|
+
const Q = await B(fr(I, z.name), K);
|
|
1264
|
+
return Q === null ? null : { name: z.name, path: V, type: "directory", children: Q };
|
|
1236
1265
|
})
|
|
1237
|
-
)).filter((
|
|
1266
|
+
)).filter((z) => z !== null);
|
|
1238
1267
|
};
|
|
1239
1268
|
try {
|
|
1240
|
-
const
|
|
1241
|
-
if (
|
|
1242
|
-
return
|
|
1243
|
-
} catch (
|
|
1244
|
-
throw T.abort(),
|
|
1269
|
+
const I = await B(c, "");
|
|
1270
|
+
if (I === null) throw new Error("[markdown-explorer] the source's root could not be listed");
|
|
1271
|
+
return I;
|
|
1272
|
+
} catch (I) {
|
|
1273
|
+
throw T.abort(), I;
|
|
1245
1274
|
} finally {
|
|
1246
|
-
|
|
1275
|
+
w.removeEventListener("abort", b);
|
|
1247
1276
|
}
|
|
1248
|
-
},
|
|
1249
|
-
if (!
|
|
1250
|
-
const T =
|
|
1251
|
-
if (!
|
|
1252
|
-
if (
|
|
1253
|
-
const b =
|
|
1277
|
+
}, H = async (w) => {
|
|
1278
|
+
if (!w.startsWith(f)) return { status: "refused", reason: "not-found" };
|
|
1279
|
+
const T = w.slice(f.length);
|
|
1280
|
+
if (!dt(T)) return { status: "refused", reason: "invalid" };
|
|
1281
|
+
if (y.deniesPath(T)) return { status: "refused", reason: "forbidden" };
|
|
1282
|
+
const b = L(T);
|
|
1254
1283
|
if (b === null) return { status: "refused", reason: "forbidden" };
|
|
1255
|
-
const
|
|
1256
|
-
if (
|
|
1257
|
-
if (!
|
|
1258
|
-
const P = await
|
|
1259
|
-
return P !== b ||
|
|
1260
|
-
},
|
|
1261
|
-
let
|
|
1284
|
+
const A = await wr(b, { bigint: !0 });
|
|
1285
|
+
if (A.isSymbolicLink()) return { status: "refused", reason: "forbidden" };
|
|
1286
|
+
if (!A.isFile()) return { status: "refused", reason: "unsupported" };
|
|
1287
|
+
const P = await hr(b);
|
|
1288
|
+
return P !== b || y.deniesPath(Ce(c, P).split(He).join("/")) ? { status: "refused", reason: "forbidden" } : { status: "file", target: b, name: T.slice(T.lastIndexOf("/") + 1), stats: A };
|
|
1289
|
+
}, j = async (w, T, b) => {
|
|
1290
|
+
let A;
|
|
1262
1291
|
try {
|
|
1263
|
-
const P = await
|
|
1264
|
-
if (P.status === "refused") return
|
|
1265
|
-
const { target: B, name:
|
|
1266
|
-
if (
|
|
1267
|
-
if (
|
|
1268
|
-
if (
|
|
1269
|
-
|
|
1270
|
-
const re = await
|
|
1271
|
-
if (!re.isFile() || re.ino !==
|
|
1272
|
-
if (
|
|
1273
|
-
if (re.size > BigInt(p)) return
|
|
1274
|
-
const
|
|
1275
|
-
if (
|
|
1276
|
-
const
|
|
1277
|
-
return { kind: "markdown", name:
|
|
1292
|
+
const P = await H(b);
|
|
1293
|
+
if (P.status === "refused") return te(P.reason);
|
|
1294
|
+
const { target: B, name: I, stats: X } = P, W = Qn(I), U = lt(X);
|
|
1295
|
+
if (W.kind === "image") return { kind: "image", name: I, version: U };
|
|
1296
|
+
if (W.kind === "media") return { kind: "media", name: I, mediaType: W.mediaType, version: U };
|
|
1297
|
+
if (W.kind === "file") return { kind: "file", name: I, version: U };
|
|
1298
|
+
A = await ht(B, ue.O_RDONLY | _t | Rt);
|
|
1299
|
+
const re = await A.stat({ bigint: !0 });
|
|
1300
|
+
if (!re.isFile() || re.ino !== X.ino || re.dev !== X.dev) return te("forbidden");
|
|
1301
|
+
if (W.kind === "markdown") {
|
|
1302
|
+
if (re.size > BigInt(p)) return te("too-large");
|
|
1303
|
+
const Q = await ft(A, p + 1);
|
|
1304
|
+
if (Q.length > p) return te("too-large");
|
|
1305
|
+
const pe = await a(new TextDecoder("utf-8").decode(Q), T);
|
|
1306
|
+
return { kind: "markdown", name: I, htmlContent: pe.htmlContent, headings: pe.headings };
|
|
1278
1307
|
}
|
|
1279
|
-
const
|
|
1280
|
-
if (
|
|
1281
|
-
const
|
|
1282
|
-
return { kind: "text", name:
|
|
1308
|
+
const z = await ft(A, h);
|
|
1309
|
+
if (z.includes(0)) return { kind: "file", name: I, version: U };
|
|
1310
|
+
const K = re.size > BigInt(h), V = new TextDecoder("utf-8").decode(z, { stream: K });
|
|
1311
|
+
return { kind: "text", name: I, text: V, truncated: K, version: U };
|
|
1283
1312
|
} catch (P) {
|
|
1284
|
-
const B =
|
|
1313
|
+
const B = Ne(P);
|
|
1285
1314
|
if (B === null) throw P;
|
|
1286
|
-
return
|
|
1315
|
+
return te(B);
|
|
1287
1316
|
} finally {
|
|
1288
|
-
await
|
|
1317
|
+
await A?.close();
|
|
1289
1318
|
}
|
|
1290
|
-
},
|
|
1291
|
-
let
|
|
1319
|
+
}, d = async (w, T, b) => {
|
|
1320
|
+
let A;
|
|
1292
1321
|
try {
|
|
1293
|
-
|
|
1322
|
+
A = await H(b);
|
|
1294
1323
|
} catch (U) {
|
|
1295
|
-
throw
|
|
1324
|
+
throw Nt(U);
|
|
1296
1325
|
}
|
|
1297
|
-
if (
|
|
1298
|
-
const { target: P, name: B, stats:
|
|
1299
|
-
return { name: B, contentType:
|
|
1300
|
-
},
|
|
1301
|
-
let
|
|
1326
|
+
if (A.status === "refused") throw new Ee(A.reason);
|
|
1327
|
+
const { target: P, name: B, stats: I } = A, X = Ot.get(At(B)), W = X === void 0 ? "" : X.contentType;
|
|
1328
|
+
return { name: B, contentType: W, size: Number(I.size), version: lt(I), open: (U) => to(P, I, U, w.signal) };
|
|
1329
|
+
}, E = async (w, T, b) => {
|
|
1330
|
+
let A;
|
|
1302
1331
|
try {
|
|
1303
|
-
|
|
1304
|
-
} catch (
|
|
1305
|
-
if (
|
|
1306
|
-
throw
|
|
1332
|
+
A = await H(b);
|
|
1333
|
+
} catch (I) {
|
|
1334
|
+
if (Ne(I) !== null) return null;
|
|
1335
|
+
throw I;
|
|
1307
1336
|
}
|
|
1308
|
-
if (
|
|
1337
|
+
if (A.status === "refused") return null;
|
|
1309
1338
|
const P = b.slice(f.length).split("/");
|
|
1310
|
-
if (P.some((
|
|
1339
|
+
if (P.some((I) => y.deniesName(I))) return null;
|
|
1311
1340
|
const B = P.slice(0, -1);
|
|
1312
|
-
return B.map((
|
|
1341
|
+
return B.map((I, X) => `${f}${B.slice(0, X + 1).join("/")}`);
|
|
1313
1342
|
};
|
|
1314
1343
|
return Object.freeze({
|
|
1315
1344
|
id: t,
|
|
1316
1345
|
label: r,
|
|
1317
|
-
cacheScope:
|
|
1318
|
-
boundary: Object.freeze({ contains: (
|
|
1319
|
-
tree:
|
|
1320
|
-
ancestors:
|
|
1321
|
-
document:
|
|
1322
|
-
asset:
|
|
1346
|
+
cacheScope: R,
|
|
1347
|
+
boundary: Object.freeze({ contains: (w) => w.startsWith(f) }),
|
|
1348
|
+
tree: N,
|
|
1349
|
+
ancestors: E,
|
|
1350
|
+
document: j,
|
|
1351
|
+
asset: d
|
|
1323
1352
|
});
|
|
1324
1353
|
};
|
|
1325
1354
|
export {
|
|
1326
|
-
|
|
1355
|
+
Oo as DEFAULT_DENIED_PATH_SEGMENTS,
|
|
1327
1356
|
Ee as ExplorerError,
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1357
|
+
_o as MAX_DOCUMENT_PATH_LENGTH,
|
|
1358
|
+
bo as anonymousAccess,
|
|
1359
|
+
To as createFileSystemSource,
|
|
1360
|
+
So as createMarkdownExplorer,
|
|
1361
|
+
ee as isAcceptableDocumentPath,
|
|
1362
|
+
Ro as isDeniedPath
|
|
1334
1363
|
};
|