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