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