@aiquants/markdown-explorer 0.35.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +165 -0
- package/README.md +105 -13
- package/dist/{EditSurface-D2j1kCEE.js → EditSurface-BQgwRUrR.js} +250 -245
- package/dist/EditSurface-Xvk5wZu7.cjs +6 -0
- package/dist/ExplorerSplit-C_3FChSt.cjs +2 -0
- package/dist/ExplorerSplit-C_kaEnyM.js +1619 -0
- package/dist/{MultiLayout-CxV5SI7f.cjs → MultiLayout-BZNj1GYo.cjs} +1 -1
- package/dist/{MultiLayout-BeJ5Lubb.js → MultiLayout-DROxkTdD.js} +24 -24
- package/dist/{NativeScrollBar-RWXpVhbI.cjs → NativeScrollBar-BDF9A1sc.cjs} +1 -1
- package/dist/{NativeScrollBar-BM5NULzg.js → NativeScrollBar-DvdOpwIW.js} +2 -2
- package/dist/TreeLayout-Cc-ykewY.js +103 -0
- package/dist/TreeLayout-D_DYV64_.cjs +1 -0
- package/dist/client/MarkdownExplorer.d.cts +4 -5
- package/dist/client/MarkdownExplorer.d.ts +4 -5
- package/dist/client/hostContract.d.cts +1 -8
- package/dist/client/hostContract.d.ts +1 -8
- package/dist/core/config.d.cts +6 -0
- package/dist/core/config.d.ts +6 -0
- package/dist/core/contracts.d.cts +21 -0
- package/dist/core/contracts.d.ts +21 -0
- package/dist/core/dataRoute.d.cts +5 -1
- package/dist/core/dataRoute.d.ts +5 -1
- package/dist/core/documentId.d.cts +6 -0
- package/dist/core/documentId.d.ts +6 -0
- package/dist/core/labels.d.cts +10 -9
- package/dist/core/labels.d.ts +10 -9
- package/dist/core/location.d.cts +21 -0
- package/dist/core/location.d.ts +21 -0
- package/dist/explorerCore-DivWkFQF.cjs +1 -0
- package/dist/explorerCore-EkU0mwdW.js +1085 -0
- package/dist/index-BmOU3xcK.cjs +18 -0
- package/dist/{index-C1YMH-yI.js → index-dtjghDWY.js} +2647 -2466
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +49 -45
- package/dist/location-Dh6K-y7w.js +761 -0
- package/dist/location-DrOP6t1F.cjs +1 -0
- package/dist/{merge-DQUYEGCx.cjs → merge-BCFCL1cF.cjs} +1 -1
- package/dist/{merge-Bb_HpPhe.js → merge-DC_h-t31.js} +1 -1
- package/dist/ownUrls-BTPGNhBt.cjs +1 -0
- package/dist/ownUrls-DD0cSCsF.js +409 -0
- package/dist/{sanitizeJob-BYRk17nr.js → sanitizeJob-BYqzjFJC.js} +1 -1
- package/dist/{sanitizeJob-Cs9o3Vpl.cjs → sanitizeJob-CudE1RUP.cjs} +1 -1
- package/dist/{sanitizePolicy-CiQfnxyd.cjs → sanitizePolicy-C-ehd0J_.cjs} +1 -1
- package/dist/{sanitizePolicy-CEMdaLUB.js → sanitizePolicy-DAPnUUVm.js} +1 -1
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +3 -3
- package/dist/{sanitizerService-KWXv7bPm.js → sanitizerService-B8v4ap9t.js} +1 -1
- package/dist/{sanitizerService-BY4CPCoA.cjs → sanitizerService-DomN7lwC.cjs} +1 -1
- package/dist/server/anonymous.d.cts +2 -2
- package/dist/server/anonymous.d.ts +2 -2
- package/dist/server/errors.d.cts +1 -1
- package/dist/server/errors.d.ts +1 -1
- package/dist/server/ports.d.cts +24 -2
- package/dist/server/ports.d.ts +24 -2
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +16 -16
- package/dist/serverBrowser.cjs +1 -1
- package/dist/serverBrowser.js +3 -3
- package/dist/serverCore.cjs +1 -1
- package/dist/serverCore.d.cts +1 -1
- package/dist/serverCore.d.ts +1 -1
- package/dist/serverCore.js +4 -4
- package/dist/styles/markdown-explorer.css +1 -1
- package/dist/{tapScrollCircle-BEydRn0y.js → tapScrollCircle-CqMZzWjo.js} +1 -1
- package/dist/{tapScrollCircle-DdX0Wri0.cjs → tapScrollCircle-DVNlszeF.cjs} +1 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +5 -0
- package/dist/testing.d.ts +5 -0
- package/dist/testing.js +80 -2
- package/dist/{useSplitPersistence-B2Fj508K.cjs → useSplitPersistence-BUa_KMsV.cjs} +1 -1
- package/dist/{useSplitPersistence-Fkqak8G8.js → useSplitPersistence-pnb21dsr.js} +1 -1
- package/docs/behavior/dom-hooks.md +11 -2
- package/docs/behavior/hosting.md +1 -1
- package/docs/behavior/localization.md +2 -2
- package/docs/behavior/security.md +24 -3
- package/docs/behavior/url-contract.md +26 -0
- package/package.json +6 -4
- package/dist/EditSurface-CLG70Vnn.cjs +0 -6
- package/dist/ExplorerSplit-CfP1smbT.js +0 -1589
- package/dist/ExplorerSplit-D_0VohOv.cjs +0 -2
- package/dist/TreeLayout-AxLw-36S.js +0 -103
- package/dist/TreeLayout-Bg2YH-EY.cjs +0 -1
- package/dist/explorerCore-DLpDuSev.js +0 -998
- package/dist/explorerCore-DYrxS9ez.cjs +0 -1
- package/dist/index-LQWQfpAf.cjs +0 -18
- package/dist/location--KvTA0Ri.js +0 -726
- package/dist/location-D8DyDkuA.cjs +0 -1
- package/dist/ownUrls-B259RGgd.cjs +0 -1
- package/dist/ownUrls-Dh5g6ZJi.js +0 -370
|
@@ -1,998 +0,0 @@
|
|
|
1
|
-
import { crossOriginRefusal as et, NO_CROSS_ORIGIN_NAVIGATION as tt } from "@aiquants/request-isolation";
|
|
2
|
-
import { data as Le, redirect as Xt } from "react-router";
|
|
3
|
-
import { t as rt, b as Vt, w as Gt, o as Wt, f as Yt, g as Kt, i as Jt, h as Qt, p as Zt } from "./location--KvTA0Ri.js";
|
|
4
|
-
import { h as nt, j as qt, k as se, m as er, n as tr, s as rr, b as nr, o as sr, p as or, q as ar, t as ir, E as st, u as Z, v as cr, w as dr, i as U, x as ur, y as lr, z as fr, f as pr, A as hr, B as wr, C as be, F as yr, G as mr, H as gr, I as z, g as B, e as De, J as br, K as Er } from "./ownUrls-Dh5g6ZJi.js";
|
|
5
|
-
import { d as O, i as Tr } from "./describeValue-CLlVRO8d.js";
|
|
6
|
-
import { c as kr, i as Rr, M as xr } from "./lru-DC8GBmkX.js";
|
|
7
|
-
const ot = "application/octet-stream", at = "application/pdf", Or = /* @__PURE__ */ new Set([
|
|
8
|
-
"image/png",
|
|
9
|
-
"image/apng",
|
|
10
|
-
"image/jpeg",
|
|
11
|
-
"image/gif",
|
|
12
|
-
"image/webp",
|
|
13
|
-
"image/avif",
|
|
14
|
-
"image/bmp",
|
|
15
|
-
"image/x-icon",
|
|
16
|
-
"image/vnd.microsoft.icon",
|
|
17
|
-
"audio/mpeg",
|
|
18
|
-
"audio/mp4",
|
|
19
|
-
"audio/aac",
|
|
20
|
-
"audio/ogg",
|
|
21
|
-
"audio/opus",
|
|
22
|
-
"audio/wav",
|
|
23
|
-
"audio/wave",
|
|
24
|
-
"audio/x-wav",
|
|
25
|
-
"audio/webm",
|
|
26
|
-
"audio/flac",
|
|
27
|
-
"audio/x-flac",
|
|
28
|
-
"audio/x-m4a",
|
|
29
|
-
"video/mp4",
|
|
30
|
-
"video/webm",
|
|
31
|
-
"video/ogg",
|
|
32
|
-
"video/quicktime",
|
|
33
|
-
at
|
|
34
|
-
]), je = "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'", we = Object.freeze({
|
|
35
|
-
sandboxed: `${je}; sandbox`,
|
|
36
|
-
mediaDocument: `${je}; sandbox allow-same-origin`
|
|
37
|
-
}), Me = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u, vr = /^[\t\n\r ]+|[\t\n\r ]+$/gu, ye = /^[\t ]+|[\t ]+$/gu, Ar = (e) => {
|
|
38
|
-
const t = [];
|
|
39
|
-
let r = "", s = 0;
|
|
40
|
-
for (; ; ) {
|
|
41
|
-
for (; s < e.length && e[s] !== '"' && e[s] !== ","; )
|
|
42
|
-
r += e[s], s += 1;
|
|
43
|
-
if (s < e.length && e[s] === '"') {
|
|
44
|
-
const a = s;
|
|
45
|
-
for (s += 1; s < e.length && e[s] !== '"'; )
|
|
46
|
-
s += e[s] === "\\" ? 2 : 1;
|
|
47
|
-
if (s = Math.min(s + 1, e.length), r += e.slice(a, s), s < e.length) continue;
|
|
48
|
-
}
|
|
49
|
-
if (t.push(r.replace(ye, "")), r = "", s >= e.length) return t;
|
|
50
|
-
s += 1;
|
|
51
|
-
}
|
|
52
|
-
}, Sr = (e) => {
|
|
53
|
-
const t = e.replace(vr, ""), r = t.indexOf("/");
|
|
54
|
-
if (r < 0) return null;
|
|
55
|
-
const s = t.slice(0, r), a = t.indexOf(";", r + 1), d = t.slice(r + 1, a < 0 ? t.length : a).replace(/[\t\n\r ]+$/u, "");
|
|
56
|
-
return Me.test(s) && Me.test(d) ? `${s}/${d}`.toLowerCase() : null;
|
|
57
|
-
}, Pr = (e) => {
|
|
58
|
-
let t = null;
|
|
59
|
-
for (const r of Ar(e)) {
|
|
60
|
-
const s = Sr(r);
|
|
61
|
-
s !== null && s !== "*/*" && (t = s);
|
|
62
|
-
}
|
|
63
|
-
return t;
|
|
64
|
-
}, _r = /['()*]/gu, it = (e) => encodeURIComponent(e).replace(_r, (t) => `%${t.charCodeAt(0).toString(16).toUpperCase()}`), Ee = Object.freeze({
|
|
65
|
-
"Cache-Control": "private, max-age=60, stale-while-revalidate=600, no-transform",
|
|
66
|
-
Vary: "Cookie"
|
|
67
|
-
}), ct = (e, t) => {
|
|
68
|
-
const r = Pr(e), s = r !== null && Or.has(r), a = s && (r.startsWith("audio/") || r.startsWith("video/"));
|
|
69
|
-
return {
|
|
70
|
-
contentType: r === null ? ot : r,
|
|
71
|
-
inline: s,
|
|
72
|
-
headers: {
|
|
73
|
-
"X-Content-Type-Options": "nosniff",
|
|
74
|
-
"Content-Disposition": `${s ? "inline" : "attachment"}; filename*=UTF-8''${it(t)}`,
|
|
75
|
-
...r === at ? {} : { "Content-Security-Policy": a ? we.mediaDocument : we.sandboxed },
|
|
76
|
-
"Cross-Origin-Resource-Policy": "same-origin"
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}, ne = 64 * 1024, dt = (e) => `text/plain; charset=${e}`, $r = (e) => ({
|
|
80
|
-
"X-Content-Type-Options": "nosniff",
|
|
81
|
-
"Content-Disposition": `inline; filename*=UTF-8''${it(e)}`,
|
|
82
|
-
"Content-Security-Policy": we.sandboxed,
|
|
83
|
-
"Cross-Origin-Resource-Policy": "same-origin"
|
|
84
|
-
}), Ir = (e, t) => `${t === null ? "" : t};${e}`, Nr = /^bytes=(?:(\d+)-(\d*)|-(\d+))$/iu, te = Object.freeze({ kind: "whole" }), Ce = Object.freeze({ kind: "unsatisfiable" }), ut = (e, t, r, s) => {
|
|
85
|
-
const a = e.get("Range");
|
|
86
|
-
if (a === null) return te;
|
|
87
|
-
const d = e.get("If-Range");
|
|
88
|
-
if (d !== null && d !== r) return te;
|
|
89
|
-
const l = Nr.exec(a);
|
|
90
|
-
if (l === null) return te;
|
|
91
|
-
const [, f, h, T] = l;
|
|
92
|
-
if (T !== void 0) {
|
|
93
|
-
const b = Number(T);
|
|
94
|
-
if (b === 0) return Ce;
|
|
95
|
-
const x = Math.max(0, t - b);
|
|
96
|
-
return ze(x, t - x, s);
|
|
97
|
-
}
|
|
98
|
-
const w = Number(f), g = h === "" ? Number.POSITIVE_INFINITY : Number(h);
|
|
99
|
-
return g < w ? te : w >= t ? Ce : ze(w, Math.min(g, t - 1) - w + 1, s);
|
|
100
|
-
}, ze = (e, t, r) => ({ kind: "partial", range: { offset: e, length: r === null ? t : Math.min(t, r) } }), Fe = "W/", Lr = (e) => {
|
|
101
|
-
const t = [];
|
|
102
|
-
let r = 0, s = !1;
|
|
103
|
-
for (let a = 0; a < e.length; a += 1)
|
|
104
|
-
e[a] === '"' ? s = !s : e[a] === "," && !s && (t.push(e.slice(r, a).replace(ye, "")), r = a + 1);
|
|
105
|
-
return t.push(e.slice(r).replace(ye, "")), t;
|
|
106
|
-
}, Ue = (e) => e.startsWith(Fe) ? e.slice(Fe.length) : e, Te = (e, t) => {
|
|
107
|
-
if (e === null) return !1;
|
|
108
|
-
const r = Lr(e);
|
|
109
|
-
if (r.length === 1 && r[0] === "*") return !0;
|
|
110
|
-
const s = Ue(t);
|
|
111
|
-
return r.some((a) => Ue(a) === s);
|
|
112
|
-
}, Dr = (e, t) => {
|
|
113
|
-
let r = t;
|
|
114
|
-
return e.pipeThrough(
|
|
115
|
-
new TransformStream({
|
|
116
|
-
transform: (s, a) => {
|
|
117
|
-
const d = s.byteLength > r ? s.subarray(0, r) : s;
|
|
118
|
-
r -= d.byteLength, a.enqueue(d), r === 0 && a.terminate();
|
|
119
|
-
},
|
|
120
|
-
flush: (s) => {
|
|
121
|
-
r > 0 && s.error(new RangeError("[markdown-explorer] the asset ended before its declared length"));
|
|
122
|
-
}
|
|
123
|
-
})
|
|
124
|
-
);
|
|
125
|
-
}, V = (e, t, r, s, a) => (a !== null && r.set("Content-Length", String(a)), { head: e.method.toUpperCase() === "HEAD", status: t, headers: r, range: s, length: a }), Q = ({ head: e, status: t, headers: r, range: s, length: a }) => e ? { kind: "respond", response: new Response(null, { status: t, headers: r }) } : { kind: "stream", status: t, headers: r, range: s, length: a }, oe = async (e, t) => {
|
|
126
|
-
if (e.kind === "respond") return e.response;
|
|
127
|
-
const r = await t(e.range);
|
|
128
|
-
return new Response(e.length === null ? r : Dr(r, e.length), { status: e.status, headers: e.headers });
|
|
129
|
-
}, lt = (e, t) => {
|
|
130
|
-
const r = new Headers(e);
|
|
131
|
-
for (const [s, a] of Object.entries({ "Accept-Ranges": "bytes", "Content-Range": `bytes */${t}`, "Cache-Control": "private, no-store", "X-Content-Type-Options": "nosniff" })) r.set(s, a);
|
|
132
|
-
return new Response(null, { status: 416, headers: r });
|
|
133
|
-
}, ft = (e, t, r, s) => {
|
|
134
|
-
const a = `"${t.version}"`, d = ct(t.contentType, t.name), l = new Headers(r);
|
|
135
|
-
for (const [T, w] of Object.entries({ ...d.headers, ...Ee, ETag: a })) l.set(T, w);
|
|
136
|
-
if (Te(e.headers.get("If-None-Match"), a)) return { kind: "respond", response: new Response(null, { status: 304, headers: l }) };
|
|
137
|
-
if (l.set("Content-Type", d.contentType), t.size === null) return Q(V(e, 200, l, null, null));
|
|
138
|
-
if (t.size === 0)
|
|
139
|
-
return l.set("Content-Length", "0"), { kind: "respond", response: new Response(null, { status: 200, headers: l }) };
|
|
140
|
-
l.set("Accept-Ranges", "bytes");
|
|
141
|
-
const f = ut(e.headers, t.size, a, s);
|
|
142
|
-
if (f.kind === "unsatisfiable") return { kind: "respond", response: lt(r, t.size) };
|
|
143
|
-
if (f.kind === "whole") return Q(V(e, 200, l, null, t.size));
|
|
144
|
-
const { range: h } = f;
|
|
145
|
-
return l.set("Content-Range", `bytes ${h.offset}-${h.offset + h.length - 1}/${t.size}`), Q(V(e, 206, l, h, h.length));
|
|
146
|
-
}, jr = async (e, t, r, s) => oe(ft(e, t, r, s), (a) => t.open(a)), Mr = (e, t) => {
|
|
147
|
-
const r = new Uint8Array(t);
|
|
148
|
-
let s = 0;
|
|
149
|
-
for (const a of e) {
|
|
150
|
-
if (s === t) break;
|
|
151
|
-
const d = a.subarray(0, t - s);
|
|
152
|
-
r.set(d, s), s += d.byteLength;
|
|
153
|
-
}
|
|
154
|
-
return r;
|
|
155
|
-
}, Cr = (e, t, r) => new ReadableStream(
|
|
156
|
-
{
|
|
157
|
-
start: (s) => {
|
|
158
|
-
for (const a of e) s.enqueue(a);
|
|
159
|
-
t && s.close();
|
|
160
|
-
},
|
|
161
|
-
pull: async (s) => {
|
|
162
|
-
const { done: a, value: d } = await r.read();
|
|
163
|
-
a ? s.close() : s.enqueue(d);
|
|
164
|
-
},
|
|
165
|
-
cancel: (s) => r.cancel(s)
|
|
166
|
-
},
|
|
167
|
-
{ highWaterMark: 0 }
|
|
168
|
-
), pt = async (e, t, r) => {
|
|
169
|
-
const s = e.getReader(), a = t === null ? ne : Math.min(t, ne), d = t === null ? a + 1 : a, l = [];
|
|
170
|
-
let f = 0, h = !1;
|
|
171
|
-
try {
|
|
172
|
-
for (; f < d; ) {
|
|
173
|
-
const { done: g, value: b } = await s.read();
|
|
174
|
-
if (g) {
|
|
175
|
-
h = !0;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
l.push(b), f += b.byteLength;
|
|
179
|
-
}
|
|
180
|
-
if (h && t !== null && f < a) throw new RangeError("[markdown-explorer] the asset ended before its declared length");
|
|
181
|
-
const T = t === null ? h : t <= ne;
|
|
182
|
-
return { encoding: rt(Mr(l, Math.min(f, a)), T, r), body: Cr(l, h, s) };
|
|
183
|
-
} catch (T) {
|
|
184
|
-
throw s.cancel(T).catch(() => {
|
|
185
|
-
}), T;
|
|
186
|
-
}
|
|
187
|
-
}, ht = async (e, t) => {
|
|
188
|
-
const r = await pt(await e.open(e.size === null ? null : { offset: 0, length: Math.min(e.size, ne) }), e.size, t);
|
|
189
|
-
return r.body.cancel().catch(() => {
|
|
190
|
-
}), r.encoding;
|
|
191
|
-
}, wt = (e, t, r, s, a) => {
|
|
192
|
-
const d = `"${Ir(t.version, s)}"`, l = new Headers(r);
|
|
193
|
-
for (const [T, w] of Object.entries({ ...$r(t.name), ...Ee, ETag: d })) l.set(T, w);
|
|
194
|
-
if (Te(e.headers.get("If-None-Match"), d)) return { kind: "respond", response: new Response(null, { status: 304, headers: l }) };
|
|
195
|
-
if (t.size === 0)
|
|
196
|
-
return l.set("Content-Type", dt(rt(new Uint8Array(0), !0, s))), l.set("Content-Length", "0"), { kind: "respond", response: new Response(null, { status: 200, headers: l }) };
|
|
197
|
-
if (t.size === null) return { kind: "needs-encoding", selection: V(e, 200, l, null, null) };
|
|
198
|
-
l.set("Accept-Ranges", "bytes");
|
|
199
|
-
const f = ut(e.headers, t.size, d, a);
|
|
200
|
-
if (f.kind === "unsatisfiable") return { kind: "respond", response: lt(r, t.size) };
|
|
201
|
-
if (f.kind === "whole") return { kind: "needs-encoding", selection: V(e, 200, l, null, t.size) };
|
|
202
|
-
const { range: h } = f;
|
|
203
|
-
return l.set("Content-Range", `bytes ${h.offset}-${h.offset + h.length - 1}/${t.size}`), { kind: "needs-encoding", selection: V(e, 206, l, h, h.length) };
|
|
204
|
-
}, me = (e, t) => {
|
|
205
|
-
const r = new Headers(e.headers);
|
|
206
|
-
return r.set("Content-Type", dt(t)), Q({ ...e, headers: r });
|
|
207
|
-
}, zr = async (e, t, r, s, a) => {
|
|
208
|
-
const d = wt(e, t, r, s, a);
|
|
209
|
-
if (d.kind === "respond") return d.response;
|
|
210
|
-
const { selection: l } = d;
|
|
211
|
-
if (l.head || l.range !== null) return oe(me(l, await ht(t, s)), (h) => t.open(h));
|
|
212
|
-
const f = await pt(await t.open(null), t.size, s);
|
|
213
|
-
return oe(me(l, f.encoding), async () => f.body);
|
|
214
|
-
}, Fr = (e) => `workbook;${e}`, Ur = async (e, t, r) => {
|
|
215
|
-
const s = `"${Fr(t.version)}"`, a = ct(ot, t.name), d = new Headers(r);
|
|
216
|
-
for (const [l, f] of Object.entries({ ...a.headers, ...Ee, ETag: s })) d.set(l, f);
|
|
217
|
-
return Te(e.headers.get("If-None-Match"), s) ? new Response(null, { status: 304, headers: d }) : (d.set("Content-Type", a.contentType), oe(Q(V(e, 200, d, null, t.size)), (l) => t.open(l)));
|
|
218
|
-
}, Hr = Object.freeze({
|
|
219
|
-
"Cache-Control": "private, no-store",
|
|
220
|
-
"Referrer-Policy": "no-referrer"
|
|
221
|
-
}), Br = (e, t) => {
|
|
222
|
-
const r = new Headers(t);
|
|
223
|
-
for (const [s, a] of Object.entries(Hr)) r.set(s, a);
|
|
224
|
-
return r.set("Location", e), new Response(null, { status: 302, headers: r });
|
|
225
|
-
}, le = (e, t) => {
|
|
226
|
-
const r = new AbortController(), s = t(AbortSignal.any([e.signal, r.signal]));
|
|
227
|
-
return new Promise((a) => {
|
|
228
|
-
let d;
|
|
229
|
-
const l = setTimeout(() => {
|
|
230
|
-
a(e.late), d = setTimeout(() => r.abort(), e.handOverMs);
|
|
231
|
-
}, e.timeoutMs), f = () => {
|
|
232
|
-
clearTimeout(l), clearTimeout(d);
|
|
233
|
-
};
|
|
234
|
-
s.then(
|
|
235
|
-
(h) => {
|
|
236
|
-
f(), a(h);
|
|
237
|
-
},
|
|
238
|
-
() => {
|
|
239
|
-
f(), a(e.late);
|
|
240
|
-
}
|
|
241
|
-
);
|
|
242
|
-
});
|
|
243
|
-
}, Xr = Object.freeze({
|
|
244
|
-
error: (e, t) => {
|
|
245
|
-
console.error(e, t);
|
|
246
|
-
}
|
|
247
|
-
}), yt = /* @__PURE__ */ Symbol.for("@aiquants/markdown-explorer:ExplorerError");
|
|
248
|
-
class Bn extends Error {
|
|
249
|
-
reason;
|
|
250
|
-
code;
|
|
251
|
-
constructor(t, r = {}) {
|
|
252
|
-
if (!nt(t)) throw new RangeError(`[markdown-explorer] ExplorerError needs a failure reason; got ${O(t)}`);
|
|
253
|
-
if (r.code !== void 0 && !qt(r.code)) throw new RangeError(`[markdown-explorer] an ExplorerError code must be 1 to 64 lowercase letters, digits or hyphens; got ${O(r.code)}`);
|
|
254
|
-
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, yt, { value: !0 });
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
const Vr = (e) => e instanceof Error && Object.hasOwn(e, yt) && nt(e.reason), Gr = (e) => typeof e == "object" && e !== null && e.name === "AbortError", ke = (e, t, r) => {
|
|
258
|
-
try {
|
|
259
|
-
e.error(t, r);
|
|
260
|
-
} catch (s) {
|
|
261
|
-
console.error("[markdown-explorer] the logger threw while reporting a failure", { operation: r.operation, error: s });
|
|
262
|
-
}
|
|
263
|
-
}, D = (e, t) => ke(e, `[markdown-explorer] ${t.operation} failed`, t), Wr = (e, t) => ke(e, `[markdown-explorer] ${t.operation} left out an entry`, t), fe = (e, t) => ke(e, `[markdown-explorer] ${t.operation} refused a path the deny rules match`, { ...t, error: new RangeError("[markdown-explorer] the path matches a deny rule") }), He = (e, t) => {
|
|
264
|
-
e === null || typeof e != "object" && typeof e != "function" || Promise.resolve(e).then(void 0, t);
|
|
265
|
-
}, A = (e, t, r, s) => Vr(e) ? se(e.reason, e.code) : (Gr(e) || r.aborted || D(s, { ...t, error: e }), { reason: "failed" }), Be = 2 * 1024 * 1024, Xe = 256 * 1024 * 1024, Yr = async (e, t) => {
|
|
266
|
-
const r = e.getReader(), s = new Uint8Array(t);
|
|
267
|
-
let a = 0;
|
|
268
|
-
for (; a < t; ) {
|
|
269
|
-
const { done: d, value: l } = await r.read();
|
|
270
|
-
if (d) return s.subarray(0, a);
|
|
271
|
-
const f = l.subarray(0, t - a);
|
|
272
|
-
s.set(f, a), a += f.byteLength;
|
|
273
|
-
}
|
|
274
|
-
return r.cancel().catch(() => {
|
|
275
|
-
}), s;
|
|
276
|
-
}, Kr = async (e, t, r) => {
|
|
277
|
-
if (e.size === 0) return { text: "", truncated: !1 };
|
|
278
|
-
const s = e.size !== null && e.size > t, a = e.size === null ? t + 1 : Math.min(e.size, t), d = await Yr(await e.open(s ? { offset: 0, length: t } : null), a);
|
|
279
|
-
if (e.size !== null && d.byteLength < a) throw new RangeError("[markdown-explorer] the file ended before the length its asset port reported");
|
|
280
|
-
const l = s || d.byteLength > t, f = l ? d.subarray(0, t) : d, h = Vt(f, !l, r);
|
|
281
|
-
return h.includes("\0") ? null : { text: h, truncated: l };
|
|
282
|
-
}, ae = (e) => ({ result: e, json: JSON.stringify(e) }), pe = Object.freeze(ae(Object.freeze({ status: "error", failure: Object.freeze({ reason: "failed" }) }))), Jr = (e) => e.status === "ok" && e.entries.length > 0, Qr = ({ ttlMs: e, maxEntries: t, maxBytes: r, now: s }) => {
|
|
283
|
-
const a = kr(t, { max: r, of: (w, g) => 2 * g.tree.json.length }), d = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), f = (w, g) => {
|
|
284
|
-
const b = new AbortController(), x = { waiters: 0, superseded: !1, started: !1, loadTree: g }, _ = l.get(w), C = (M, q) => {
|
|
285
|
-
const K = ae(M);
|
|
286
|
-
return !(x.superseded || b.signal.aborted) && Jr(M) && a.set(w, { tree: K, loadedAt: q }), K;
|
|
287
|
-
}, H = (async () => {
|
|
288
|
-
if (_ !== void 0 && await _, b.signal.aborted) return pe;
|
|
289
|
-
const M = s();
|
|
290
|
-
return x.started = !0, C(await x.loadTree(b.signal, M), M);
|
|
291
|
-
})().finally(() => {
|
|
292
|
-
d.get(w) === j && d.delete(w);
|
|
293
|
-
}), j = { promise: H, controller: b, state: x };
|
|
294
|
-
d.set(w, j);
|
|
295
|
-
const L = H.then(
|
|
296
|
-
() => {
|
|
297
|
-
},
|
|
298
|
-
() => {
|
|
299
|
-
}
|
|
300
|
-
);
|
|
301
|
-
return l.set(w, L), L.then(() => {
|
|
302
|
-
l.get(w) === L && l.delete(w);
|
|
303
|
-
}), j;
|
|
304
|
-
}, h = (w, g, b) => {
|
|
305
|
-
g.state.waiters += 1;
|
|
306
|
-
const x = () => {
|
|
307
|
-
g.state.waiters -= 1, !(g.state.waiters > 0) && (d.get(w) === g && d.delete(w), g.controller.abort());
|
|
308
|
-
};
|
|
309
|
-
return b.addEventListener("abort", x, { once: !0 }), g.promise.finally(() => {
|
|
310
|
-
b.removeEventListener("abort", x);
|
|
311
|
-
});
|
|
312
|
-
}, T = (w) => {
|
|
313
|
-
a.delete(w);
|
|
314
|
-
const g = d.get(w);
|
|
315
|
-
g?.state.started && (g.state.superseded = !0, d.delete(w));
|
|
316
|
-
};
|
|
317
|
-
return {
|
|
318
|
-
load: (w, g, b) => {
|
|
319
|
-
if (g.aborted) return Promise.resolve(pe);
|
|
320
|
-
const x = a.get(w);
|
|
321
|
-
if (x !== void 0) {
|
|
322
|
-
if (s() - x.loadedAt < e) return Promise.resolve(x.tree);
|
|
323
|
-
a.delete(w);
|
|
324
|
-
}
|
|
325
|
-
const _ = d.get(w);
|
|
326
|
-
return h(w, _ === void 0 ? f(w, b) : _, g);
|
|
327
|
-
},
|
|
328
|
-
refresh: (w, g, b) => {
|
|
329
|
-
if (g.aborted) return Promise.resolve(pe);
|
|
330
|
-
T(w);
|
|
331
|
-
const x = d.get(w);
|
|
332
|
-
return x === void 0 ? h(w, f(w, b), g) : (x.state.loadTree = b, h(w, x, g));
|
|
333
|
-
},
|
|
334
|
-
forget: T
|
|
335
|
-
};
|
|
336
|
-
}, Zr = (e) => ({
|
|
337
|
-
load: (t, r, s) => s(r, e()).then(ae),
|
|
338
|
-
refresh: (t, r, s) => s(r, e()).then(ae),
|
|
339
|
-
forget: () => {
|
|
340
|
-
}
|
|
341
|
-
}), m = (e) => {
|
|
342
|
-
throw new TypeError(`[markdown-explorer] ${e}`);
|
|
343
|
-
}, qr = (e) => {
|
|
344
|
-
if (e === null || typeof e != "object") return null;
|
|
345
|
-
const { name: t, path: r } = e;
|
|
346
|
-
return typeof t != "string" || typeof r != "string" ? null : t === "" ? { path: r, reason: "an empty name" } : U(r) ? null : { path: r, reason: "a path the browser cannot address (empty, too long, a lone surrogate, a control character or a backslash)" };
|
|
347
|
-
}, en = (e, t, r, s) => {
|
|
348
|
-
if (e === null) return null;
|
|
349
|
-
if (!Array.isArray(e)) throw new TypeError(`[markdown-explorer] a source's ancestors must be null or an array of folder paths; got ${O(e)}`);
|
|
350
|
-
const a = /* @__PURE__ */ new Set();
|
|
351
|
-
for (const d of e) {
|
|
352
|
-
if (typeof d != "string" || !U(d)) throw new TypeError("[markdown-explorer] a source's ancestors held a path the explorer does not accept");
|
|
353
|
-
if (r.deniesPath(d)) throw new TypeError("[markdown-explorer] a source's ancestors held a denied path");
|
|
354
|
-
if (!s(d)) throw new TypeError("[markdown-explorer] a source's ancestors held a path outside the source's boundary");
|
|
355
|
-
if (d === t) throw new TypeError("[markdown-explorer] a source's ancestors held the document itself");
|
|
356
|
-
if (a.has(d)) throw new TypeError("[markdown-explorer] a source's ancestors held a path twice");
|
|
357
|
-
a.add(d);
|
|
358
|
-
}
|
|
359
|
-
return Object.freeze([...a]);
|
|
360
|
-
}, tn = (e, t, r, s, a) => {
|
|
361
|
-
const d = /* @__PURE__ */ new Set(), l = (h) => {
|
|
362
|
-
if (!Array.isArray(h)) return m("a source returned entries that are not an array");
|
|
363
|
-
const T = [];
|
|
364
|
-
for (const w of h) {
|
|
365
|
-
const g = f(w);
|
|
366
|
-
g !== null && T.push(g);
|
|
367
|
-
}
|
|
368
|
-
return T;
|
|
369
|
-
}, f = (h) => {
|
|
370
|
-
const T = qr(h);
|
|
371
|
-
if (T !== null)
|
|
372
|
-
return s(T), null;
|
|
373
|
-
const w = lr(h);
|
|
374
|
-
if (w !== null) return m(w);
|
|
375
|
-
const g = h;
|
|
376
|
-
if (d.has(g)) return m("a source returned entries that contain themselves");
|
|
377
|
-
const { name: b, path: x, type: _, mimeType: C, modifiedAt: G, children: H, lazy: j } = g;
|
|
378
|
-
if (t.deniesName(b) || t.deniesPath(x)) return null;
|
|
379
|
-
if (!a(x))
|
|
380
|
-
return s({ path: x, reason: "a path outside the source's boundary" }), null;
|
|
381
|
-
const L = { name: b, path: x, ...C === void 0 ? {} : { mimeType: C }, ...G === void 0 ? {} : { modifiedAt: G } };
|
|
382
|
-
if (_ === "file") return { ...L, type: _ };
|
|
383
|
-
if (j === !0)
|
|
384
|
-
return r ? { ...L, type: _, lazy: !0, children: [] } : m("a lazy directory came from a source without a children function");
|
|
385
|
-
if (H === void 0) return { ...L, type: _ };
|
|
386
|
-
d.add(g);
|
|
387
|
-
const M = l(H);
|
|
388
|
-
return d.delete(g), { ...L, type: _, children: M };
|
|
389
|
-
};
|
|
390
|
-
return l(e);
|
|
391
|
-
}, rn = /^[\x21\x23-\x7E]{1,256}$/u, mt = (e) => typeof e == "string" && rn.test(e), nn = /* @__PURE__ */ new Set(["text", "image", "media", "spreadsheet", "file"]), sn = (e) => typeof e == "string" && nn.has(e), on = (e, t, r) => {
|
|
392
|
-
if (e !== null && typeof e == "object") {
|
|
393
|
-
const d = e, { kind: l } = d;
|
|
394
|
-
if (sn(l)) {
|
|
395
|
-
if (Object.hasOwn(d, "url")) return m(`a ${l} document carries its version, not a url`);
|
|
396
|
-
if (typeof d.name != "string") return m("a document needs a name string");
|
|
397
|
-
if (!mt(d.version)) return m(`a ${l} document needs a version of 1 to 256 visible ASCII characters other than '"'`);
|
|
398
|
-
const f = t(d.version);
|
|
399
|
-
switch (l) {
|
|
400
|
-
case "image": {
|
|
401
|
-
const { imageType: h } = d;
|
|
402
|
-
return ar(h) ? { kind: l, name: d.name, url: f, imageType: h } : m(`unknown image type ${O(h)}`);
|
|
403
|
-
}
|
|
404
|
-
case "file":
|
|
405
|
-
return { kind: l, name: d.name, url: f };
|
|
406
|
-
case "media": {
|
|
407
|
-
const { mediaType: h } = d;
|
|
408
|
-
return or(h) ? { kind: l, name: d.name, url: f, mediaType: h } : m(`unknown media type ${O(h)}`);
|
|
409
|
-
}
|
|
410
|
-
case "text": {
|
|
411
|
-
const { text: h, truncated: T, lang: w } = d;
|
|
412
|
-
return typeof h != "string" || typeof T != "boolean" ? m("a text document needs text and truncated") : nr(w) ? { kind: l, name: d.name, text: h, truncated: T, lang: w, url: f } : m(sr(l, w));
|
|
413
|
-
}
|
|
414
|
-
case "spreadsheet": {
|
|
415
|
-
const h = rr(d);
|
|
416
|
-
if (h !== null) return m(h);
|
|
417
|
-
const { format: T, firstSheetText: w, edit: g } = d;
|
|
418
|
-
return { kind: l, name: d.name, url: f, format: T, firstSheetText: w, edit: cn(g) };
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
const s = ir(e);
|
|
424
|
-
if (s !== null) return m(s);
|
|
425
|
-
const a = e;
|
|
426
|
-
switch (a.kind) {
|
|
427
|
-
case "failure": {
|
|
428
|
-
const { reason: d, code: l } = a.failure;
|
|
429
|
-
return { kind: "failure", failure: se(d, l) };
|
|
430
|
-
}
|
|
431
|
-
case "markdown":
|
|
432
|
-
return a.headings.length > st ? { kind: "failure", failure: se("too-large") } : (a.edit?.kind === "inline" || a.edit?.kind === "draft") && !r ? m(`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: d, depth: l, id: f }) => ({ text: d, depth: l, id: f })), lang: a.lang, edit: an(a.edit) };
|
|
433
|
-
}
|
|
434
|
-
}, an = (e) => {
|
|
435
|
-
if (e === null) return null;
|
|
436
|
-
switch (e.kind) {
|
|
437
|
-
case "inline":
|
|
438
|
-
return { kind: "inline" };
|
|
439
|
-
case "draft":
|
|
440
|
-
return { kind: "draft" };
|
|
441
|
-
case "external":
|
|
442
|
-
return { kind: "external", href: e.href };
|
|
443
|
-
}
|
|
444
|
-
}, cn = (e) => e === null ? null : { kind: "external", href: e.href }, ie = (e, t, r) => typeof e != "string" ? m(`${r} needs a text string`) : e.includes("\0") ? m(`${r} holds NUL, which no text editor can keep`) : new TextEncoder().encode(e).byteLength > t ? m(`${r} is over editMaxBytes (${t} bytes); refuse a longer source with ExplorerError "too-large"`) : e, gt = (e) => ur(e.href) ? { kind: "grant", href: e.href } : m("a grant needs a root-relative href"), dn = (e, t) => {
|
|
445
|
-
if (e === null || typeof e != "object") return m("an edit source must be an object");
|
|
446
|
-
const r = e;
|
|
447
|
-
return r.kind === "grant" ? gt(r) : r.kind === "draft" ? { kind: "draft", text: ie(r.text, t, "a draft source") } : r.kind !== "edit" ? m(`an edit source's kind must be "edit", "draft" or "grant"`) : Z(r.version) ? typeof r.history != "boolean" ? m("an edit source needs history") : { kind: "edit", text: ie(r.text, t, "an edit source"), version: r.version, history: r.history } : m("an edit source needs a version of 1 to 1024 characters");
|
|
448
|
-
}, un = (e, t) => {
|
|
449
|
-
if (e === null || typeof e != "object") return m("a save result must be an object");
|
|
450
|
-
const r = e;
|
|
451
|
-
switch (r.kind) {
|
|
452
|
-
case "grant":
|
|
453
|
-
return gt(r);
|
|
454
|
-
case "saved":
|
|
455
|
-
return Z(r.version) ? { kind: "saved", version: r.version } : m("a saved result needs a version of 1 to 1024 characters");
|
|
456
|
-
case "conflict":
|
|
457
|
-
return Z(r.version) ? { kind: "conflict", version: r.version, text: ie(r.text, t, "a conflict's current text") } : m("a conflict needs the current version of 1 to 1024 characters");
|
|
458
|
-
default:
|
|
459
|
-
return m(`a save result's kind must be "saved", "conflict" or "grant"`);
|
|
460
|
-
}
|
|
461
|
-
}, ln = (e) => {
|
|
462
|
-
if (e === null || typeof e != "object") return m("a preview must be an object");
|
|
463
|
-
const { htmlContent: t, headings: r } = e;
|
|
464
|
-
if (typeof t != "string" || !Array.isArray(r)) return m("a preview needs htmlContent and headings");
|
|
465
|
-
if (r.length > st) return { kind: "failure", failure: se("too-large") };
|
|
466
|
-
for (const s of r) {
|
|
467
|
-
const a = dr(s);
|
|
468
|
-
if (a !== null) return m(a);
|
|
469
|
-
}
|
|
470
|
-
return { html: t, headings: r.map(({ text: s, depth: a, id: d }) => ({ text: s, depth: a, id: d })) };
|
|
471
|
-
}, fn = (e) => {
|
|
472
|
-
if (!Array.isArray(e)) return m("revisions must be an array");
|
|
473
|
-
const t = /* @__PURE__ */ new Set();
|
|
474
|
-
return e.map((r) => {
|
|
475
|
-
const s = cr(r);
|
|
476
|
-
if (s !== null) return m(s);
|
|
477
|
-
const { id: a, modifiedAt: d, size: l, author: f, kept: h, current: T } = r;
|
|
478
|
-
return t.has(a) ? m(`two revisions share the id ${O(a)}`) : (t.add(a), { id: a, modifiedAt: d, size: l, author: f, kept: h, current: T });
|
|
479
|
-
});
|
|
480
|
-
}, pn = (e, t) => ie(e, t, "a revision"), ge = (e) => {
|
|
481
|
-
if (e === null || typeof e != "object") return m("an asset file must be an object");
|
|
482
|
-
const { name: t, contentType: r, size: s, version: a, open: d, kind: l, bridge: f } = e;
|
|
483
|
-
if (l !== void 0) return m(l === "redirect" ? "an asset redirect answers only a request for the stored file (options.delivery file), never one that reads the bytes" : 'an asset file has no kind (the only kind is "redirect")');
|
|
484
|
-
if (typeof t != "string" || t === "") return m("an asset file needs a non-empty name");
|
|
485
|
-
if (typeof r != "string") return m("an asset file needs a contentType string ('' when unknown)");
|
|
486
|
-
if (s !== null && !(typeof s == "number" && Number.isSafeInteger(s) && s >= 0)) return m("an asset file's size must be null or a non-negative safe integer");
|
|
487
|
-
if (!mt(a)) return m(`an asset file needs a version of 1 to 256 visible ASCII characters other than '"'`);
|
|
488
|
-
if (typeof d != "function") return m("an asset file needs an open function");
|
|
489
|
-
const h = { name: t, contentType: r, size: s, version: a, open: d };
|
|
490
|
-
return Object.freeze(f === void 0 ? h : { ...h, bridge: hn(f) });
|
|
491
|
-
}, hn = (e) => {
|
|
492
|
-
if (e === null || typeof e != "object") return m("an asset file's bridge must be an object when present");
|
|
493
|
-
const { uri: t, storageVersion: r, readFailure: s } = e;
|
|
494
|
-
return typeof t != "string" || t === "" ? m("an asset file's bridge needs a non-empty uri") : r !== null && (typeof r != "string" || r === "") ? m("an asset file's bridge needs a storageVersion that is a non-empty string, or null when the storage keeps none") : typeof s != "function" ? m("an asset file's bridge needs a readFailure function") : Object.freeze({ uri: t, storageVersion: r, readFailure: s });
|
|
495
|
-
}, wn = (e) => {
|
|
496
|
-
if (e === null || typeof e != "object" || e.kind !== "redirect") return ge(e);
|
|
497
|
-
const { url: t } = e;
|
|
498
|
-
if (typeof t != "string" || !URL.canParse(t)) return m("an asset redirect needs an absolute https URL");
|
|
499
|
-
const r = new URL(t);
|
|
500
|
-
return r.protocol !== "https:" || r.username !== "" || r.password !== "" ? m("an asset redirect's URL must be https and carry no credentials") : Object.freeze({ kind: "redirect", url: r.href });
|
|
501
|
-
}, yn = (e) => Array.isArray(e) ? e.map((t) => {
|
|
502
|
-
if (t === null || typeof t != "object") return m("a notice must be an object");
|
|
503
|
-
const { id: r, tone: s, title: a, body: d, action: l } = t;
|
|
504
|
-
if (typeof r != "string" || r === "" || typeof a != "string") return m("a notice needs an id and a title");
|
|
505
|
-
if (!er(s)) return m(`unknown notice tone ${O(s)}`);
|
|
506
|
-
if (d !== void 0 && typeof d != "string") return m("a notice body must be a string");
|
|
507
|
-
const h = { id: r, tone: s, title: a, ...d === void 0 ? {} : { body: d } };
|
|
508
|
-
if (l === void 0) return h;
|
|
509
|
-
if (l === null || typeof l != "object") return m("a notice action must be an object");
|
|
510
|
-
const { label: T, href: w } = l;
|
|
511
|
-
return typeof T != "string" || !tr(w, fr) ? m("a notice action needs a label and an http(s), mailto or relative href") : { ...h, action: { label: T, href: w } };
|
|
512
|
-
}) : m("notices must be an array"), mn = 4e3, re = Object.freeze({ ttlMs: 3e5, maxEntries: 64, maxBytes: 64 * 1024 * 1024 }), bt = "private, no-store", gn = Object.freeze({
|
|
513
|
-
"Content-Type": "application/json; charset=utf-8",
|
|
514
|
-
"Cache-Control": bt,
|
|
515
|
-
"X-Content-Type-Options": "nosniff",
|
|
516
|
-
"Content-Security-Policy": "default-src 'none'; frame-ancestors 'none'; sandbox",
|
|
517
|
-
"Cross-Origin-Resource-Policy": "same-origin"
|
|
518
|
-
}), he = Object.freeze([]), bn = Object.freeze({ status: "ok", source: null, ancestors: null }), Ve = Object.freeze(["contains", "confirm"]), Ge = Object.freeze({ readOnly: !1 }), En = Object.freeze({ readOnly: !0 }), Tn = /* @__PURE__ */ new Set(["file", "text", "workbook"]), kn = /* @__PURE__ */ new Set(["file", "text"]), P = (e, t, r) => {
|
|
519
|
-
if (!(r && t === void 0) && typeof t != "function")
|
|
520
|
-
throw new TypeError(`[markdown-explorer] ${e} must be a function; got ${O(t)}`);
|
|
521
|
-
}, X = (e, t, r) => {
|
|
522
|
-
if (typeof t != "number") throw new TypeError(`[markdown-explorer] ${e} must be a number; got ${O(t)}`);
|
|
523
|
-
if (!Number.isSafeInteger(t) || t <= 0 || t > r) throw new RangeError(`[markdown-explorer] ${e} must be an integer in 1..${String(r)}; got ${O(t)}`);
|
|
524
|
-
return t;
|
|
525
|
-
}, Rn = (e) => {
|
|
526
|
-
if (e === null || typeof e != "object" || !Object.isFrozen(e)) throw new TypeError("[markdown-explorer] config must be the value returned by defineExplorerConfig");
|
|
527
|
-
return Kt(e);
|
|
528
|
-
}, We = (e) => {
|
|
529
|
-
try {
|
|
530
|
-
return new Headers(e);
|
|
531
|
-
} catch {
|
|
532
|
-
throw new TypeError("[markdown-explorer] authenticate returned headers that are not a valid headers init (their values are not logged)");
|
|
533
|
-
}
|
|
534
|
-
}, Ye = (e) => e instanceof Response ? new TypeError(`[markdown-explorer] authenticate threw a Response (status ${String(e.status)}), which a data request does not follow`) : e, xn = (e, t) => {
|
|
535
|
-
if (!Tr(t)) throw new TypeError(`[markdown-explorer] ${e}.boundary must be a plain object { contains, confirm? }`);
|
|
536
|
-
for (const r of Object.keys(t))
|
|
537
|
-
if (!Ve.includes(r)) throw new RangeError(`[markdown-explorer] ${e}.boundary.${r} is not an option; expected ${Ve.join(", ")}`);
|
|
538
|
-
P(`${e}.boundary.contains`, t.contains, !1), P(`${e}.boundary.confirm`, t.confirm, !0);
|
|
539
|
-
}, On = (e) => {
|
|
540
|
-
if (!Array.isArray(e)) throw new TypeError("[markdown-explorer] sources must be an array");
|
|
541
|
-
const t = e;
|
|
542
|
-
if (t.length === 0) throw new RangeError("[markdown-explorer] sources must hold at least one source");
|
|
543
|
-
const r = /* @__PURE__ */ new Set();
|
|
544
|
-
for (const [s, a] of t.entries()) {
|
|
545
|
-
if (a === null || typeof a != "object") throw new TypeError(`[markdown-explorer] sources[${String(s)}] must be an object`);
|
|
546
|
-
const { id: d, label: l, boundary: f, tree: h, children: T, ancestors: w, cacheScope: g } = a;
|
|
547
|
-
if (!Jt(d))
|
|
548
|
-
throw new RangeError(`[markdown-explorer] sources[${String(s)}].id must use lowercase letters, digits and "-" and start with a letter or digit; got ${O(d)}`);
|
|
549
|
-
const b = `source ${O(d)}`;
|
|
550
|
-
if (r.has(d)) throw new RangeError(`[markdown-explorer] source ids must be unique; ${O(d)} repeats at sources[${String(s)}]`);
|
|
551
|
-
if (r.add(d), typeof l != "string" && typeof l != "function") throw new TypeError(`[markdown-explorer] ${b}.label must be a string or a function`);
|
|
552
|
-
if (typeof l == "string" && l.trim() === "") throw new RangeError(`[markdown-explorer] ${b}.label must not be blank`);
|
|
553
|
-
if (xn(b, f), P(`${b}.tree`, h, !1), P(`${b}.children`, T, !0), P(`${b}.ancestors`, w, !0), g !== void 0 && g !== "principal" && g !== "shared") throw new RangeError(`[markdown-explorer] ${b}.cacheScope must be "principal" or "shared"; got ${O(g)}`);
|
|
554
|
-
}
|
|
555
|
-
return t;
|
|
556
|
-
}, vn = (e) => {
|
|
557
|
-
if (e === !1) return !1;
|
|
558
|
-
if (e === void 0) return re;
|
|
559
|
-
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] treeCache must be { ttlMs, maxEntries, maxBytes } or false");
|
|
560
|
-
const { ttlMs: t, maxEntries: r, maxBytes: s } = e;
|
|
561
|
-
return {
|
|
562
|
-
ttlMs: t === void 0 ? re.ttlMs : X("treeCache.ttlMs", t, Number.MAX_SAFE_INTEGER),
|
|
563
|
-
maxEntries: r === void 0 ? re.maxEntries : X("treeCache.maxEntries", r, Number.MAX_SAFE_INTEGER),
|
|
564
|
-
maxBytes: s === void 0 ? re.maxBytes : X("treeCache.maxBytes", s, Number.MAX_SAFE_INTEGER)
|
|
565
|
-
};
|
|
566
|
-
}, Ke = (e) => {
|
|
567
|
-
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] authenticate must resolve to { status, ... }");
|
|
568
|
-
const { status: t } = e;
|
|
569
|
-
if (t !== "signed-in" && t !== "signed-out" && t !== "forbidden") throw new TypeError(`[markdown-explorer] authenticate resolved to an unknown status ${O(t)}`);
|
|
570
|
-
return e;
|
|
571
|
-
}, Je = (e, t) => {
|
|
572
|
-
if (!(t instanceof Response)) throw new TypeError(`[markdown-explorer] ${e} must return a Response`);
|
|
573
|
-
return t;
|
|
574
|
-
}, Qe = (e, t) => {
|
|
575
|
-
if (typeof t != "string" || t === "") throw new TypeError("[markdown-explorer] principalKey must return a non-empty string");
|
|
576
|
-
const r = e(t);
|
|
577
|
-
if (!Rr(r)) throw new TypeError("[markdown-explorer] the platform's scope must be 22 base64url characters");
|
|
578
|
-
return r;
|
|
579
|
-
}, An = (e, t) => {
|
|
580
|
-
try {
|
|
581
|
-
return e(t);
|
|
582
|
-
} catch (r) {
|
|
583
|
-
return r;
|
|
584
|
-
}
|
|
585
|
-
}, Sn = (e, t) => {
|
|
586
|
-
const r = e(t);
|
|
587
|
-
if (r !== void 0 && typeof r != "string") throw new TypeError(`[markdown-explorer] readSettings must return a string or undefined; got ${r === null ? "null" : typeof r}`);
|
|
588
|
-
return r;
|
|
589
|
-
}, Pn = (e) => e.view === "multi" ? e.docs : e.doc === null ? [] : [e.doc], F = (e, t) => {
|
|
590
|
-
const r = e.getAll(t), [s] = r;
|
|
591
|
-
return r.length === 1 && s !== void 0 && s !== "" ? s : null;
|
|
592
|
-
}, I = (e, t, r, s = {}) => {
|
|
593
|
-
const a = new Headers(r);
|
|
594
|
-
for (const [d, l] of Object.entries({ ...gn, ...s })) a.set(d, l);
|
|
595
|
-
return new Response(t, { status: e, headers: a });
|
|
596
|
-
}, R = (e, t, r) => I(wr[e.reason], JSON.stringify({ failure: e }), t, r), _n = /* @__PURE__ */ new Set(["refresh", "save", "preview"]), $n = /* @__PURE__ */ new Set(["edit", "save", "preview", "revisions", "revision"]), Ze = (e, t) => {
|
|
597
|
-
const r = _n.has(t) ? ["POST"] : ["GET", "HEAD"];
|
|
598
|
-
return r.includes(e.method.toUpperCase()) ? null : I(405, JSON.stringify({ failure: { reason: "invalid" } }), void 0, { Allow: r.join(", ") });
|
|
599
|
-
}, qe = (e) => e.headers.get(be) === yr && et(e, tt) === void 0, In = (e) => e.headers.get(be) === mr && et(e, tt) === void 0, Nn = async (e, t) => {
|
|
600
|
-
const [r, ...s] = (e.headers.get("Content-Type") ?? "").split(";").map((b) => b.trim().toLowerCase()), a = s.find((b) => b.startsWith("charset="));
|
|
601
|
-
if (r !== Er || a !== void 0 && a !== "charset=utf-8") return { status: "error", failure: { reason: "invalid" } };
|
|
602
|
-
const d = Number(e.headers.get("Content-Length") ?? "0");
|
|
603
|
-
if (Number.isFinite(d) && d > t) return { status: "error", failure: { reason: "too-large" } };
|
|
604
|
-
if (e.body === null) return { status: "ok", text: "" };
|
|
605
|
-
const l = e.body.getReader(), f = [];
|
|
606
|
-
let h = 0;
|
|
607
|
-
for (; ; ) {
|
|
608
|
-
const { done: b, value: x } = await l.read();
|
|
609
|
-
if (b) break;
|
|
610
|
-
if (h += x.byteLength, h > t)
|
|
611
|
-
return await l.cancel(), { status: "error", failure: { reason: "too-large" } };
|
|
612
|
-
f.push(x);
|
|
613
|
-
}
|
|
614
|
-
const T = new Uint8Array(h);
|
|
615
|
-
let w = 0;
|
|
616
|
-
for (const b of f)
|
|
617
|
-
T.set(b, w), w += b.byteLength;
|
|
618
|
-
let g;
|
|
619
|
-
try {
|
|
620
|
-
g = new TextDecoder("utf-8", { fatal: !0 }).decode(T);
|
|
621
|
-
} catch {
|
|
622
|
-
return { status: "error", failure: { reason: "invalid" } };
|
|
623
|
-
}
|
|
624
|
-
return g.includes("\0") ? { status: "error", failure: { reason: "invalid" } } : { status: "ok", text: g };
|
|
625
|
-
}, Ln = (e) => {
|
|
626
|
-
if (e === void 0) return;
|
|
627
|
-
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] edit must be an object of the editor's ports");
|
|
628
|
-
const t = e;
|
|
629
|
-
for (const r of ["source", "save", "preview", "revisions", "revision"]) P(`edit.${r}`, t[r], !1);
|
|
630
|
-
return e;
|
|
631
|
-
}, Dn = ({ parentHeaders: e, loaderHeaders: t, errorHeaders: r }) => {
|
|
632
|
-
const s = new Headers(), a = r === void 0 ? [e, t] : [e, t, r];
|
|
633
|
-
for (const d of a)
|
|
634
|
-
for (const [l, f] of d)
|
|
635
|
-
l !== "set-cookie" && s.set(l, f);
|
|
636
|
-
return s;
|
|
637
|
-
}, Xn = (e, t) => {
|
|
638
|
-
if (e === null || typeof e != "object") throw new TypeError("[markdown-explorer] the server configuration must be an object");
|
|
639
|
-
const r = Rn(e.config), s = t.prepareScope();
|
|
640
|
-
P("authenticate", e.authenticate, !1), P("principalKey", e.principalKey, !1), P("document", e.document, !1), P("asset", e.asset, !1), P("signedOutPage", e.signedOutPage, !1), P("forbiddenPage", e.forbiddenPage, !0), P("notices", e.notices, !0), P("onTreeRefreshed", e.onTreeRefreshed, !0), P("readSettings", e.readSettings, !1);
|
|
641
|
-
const a = On(e.sources), d = Gt(
|
|
642
|
-
r,
|
|
643
|
-
a.map((n) => n.id)
|
|
644
|
-
), l = e.logger;
|
|
645
|
-
if (l !== void 0 && (l === null || typeof l != "object" || typeof l.error != "function"))
|
|
646
|
-
throw new TypeError("[markdown-explorer] logger must be an object with an error function");
|
|
647
|
-
const f = e.logger === void 0 ? Xr : e.logger, h = pr(e.deny), T = e.deferredTimeoutMs === void 0 ? mn : X("deferredTimeoutMs", e.deferredTimeoutMs, xr), w = e.textMaxBytes === void 0 ? Be : X("textMaxBytes", e.textMaxBytes, Xe), g = Ln(e.edit);
|
|
648
|
-
if (g === void 0 && e.editMaxBytes !== void 0) throw new TypeError("[markdown-explorer] editMaxBytes needs the edit ports");
|
|
649
|
-
const b = e.editMaxBytes === void 0 ? Be : X("editMaxBytes", e.editMaxBytes, Xe), x = vn(e.treeCache), _ = () => Date.now(), C = x === !1 ? Zr(_) : Qr({ ...x, now: _ }), G = t.createSanitizer({ options: e.sanitizer, maxPanels: r.multiView.maxPanels, iframeHosts: r.iframeHosts, dataPath: r.dataPath, ownUrls: Wt(r) }), H = e.readSettings, j = e.assetMaxRangeBytes === null ? null : X("assetMaxRangeBytes", e.assetMaxRangeBytes, Number.MAX_SAFE_INTEGER), L = new Map(a.map((n) => [n.id, n])), M = Yt(r), { authenticate: q, principalKey: K, signedOutPage: Et, forbiddenPage: Re, onTreeRefreshed: xe } = e, Tt = (n, i) => {
|
|
650
|
-
if (typeof n.label == "string") return n.label;
|
|
651
|
-
const o = n.label(i);
|
|
652
|
-
if (typeof o != "string" || o.trim() === "") throw new TypeError(`[markdown-explorer] the label of source ${O(n.id)} must be a non-blank string`);
|
|
653
|
-
return o;
|
|
654
|
-
}, ce = (n, i) => n.cacheScope === "shared" ? n.id : `${n.id}\0${i}`, W = (n, i) => {
|
|
655
|
-
const o = (u) => D(f, { operation: "boundary", sourceId: n.id, path: i, error: u });
|
|
656
|
-
let c;
|
|
657
|
-
try {
|
|
658
|
-
c = n.boundary.contains(i);
|
|
659
|
-
} catch (u) {
|
|
660
|
-
return o(u), !1;
|
|
661
|
-
}
|
|
662
|
-
return typeof c == "boolean" ? c : (He(c, o), o(new TypeError(`[markdown-explorer] boundary.contains of source ${O(n.id)} must return a boolean; got ${O(c)}`)), !1);
|
|
663
|
-
}, de = async (n, i, o) => {
|
|
664
|
-
const { confirm: c } = n.boundary;
|
|
665
|
-
if (c === void 0) return { status: "inside", readPath: o };
|
|
666
|
-
let u;
|
|
667
|
-
try {
|
|
668
|
-
u = await c(i, o);
|
|
669
|
-
} catch (k) {
|
|
670
|
-
return { status: "error", failure: A(k, { operation: "boundary", sourceId: n.id, path: o }, i.signal, f) };
|
|
671
|
-
}
|
|
672
|
-
const p = (k) => (D(f, { operation: "boundary", sourceId: n.id, path: o, error: new TypeError(`[markdown-explorer] boundary.confirm of source ${O(n.id)} ${k}`) }), { status: "outside" });
|
|
673
|
-
if (u === null || typeof u != "object") return p(`must resolve to { inside, readPath? }; got ${u === null ? "null" : typeof u}`);
|
|
674
|
-
const { inside: y, readPath: E } = u;
|
|
675
|
-
return y === !1 ? { status: "outside" } : y !== !0 || typeof E != "string" ? p("must resolve to { inside: false } or { inside: true, readPath: string }") : !U(E) || h.deniesPath(E) ? (D(f, { operation: "boundary", sourceId: n.id, path: o, error: new RangeError(`[markdown-explorer] boundary.confirm of source ${O(n.id)} answered a readPath the explorer does not serve (unacceptable or denied)`) }), { status: "error", failure: { reason: "failed" } }) : { status: "inside", readPath: E };
|
|
676
|
-
}, ee = async (n, i) => {
|
|
677
|
-
const o = a.filter((u) => W(u, i));
|
|
678
|
-
if (o.length === 0) return { status: "error", failure: { reason: "forbidden" } };
|
|
679
|
-
if (o.some((u) => u.boundary.confirm === void 0)) return { status: "inside", readPath: i };
|
|
680
|
-
let c = null;
|
|
681
|
-
for (const u of o) {
|
|
682
|
-
const p = await de(u, n, i);
|
|
683
|
-
if (p.status === "inside") return p;
|
|
684
|
-
p.status === "error" && c === null && (c = p.failure);
|
|
685
|
-
}
|
|
686
|
-
return { status: "error", failure: c === null ? { reason: "forbidden" } : c };
|
|
687
|
-
}, Oe = (n, i, o) => {
|
|
688
|
-
const c = ({ path: u, reason: p }) => Wr(f, { operation: o.operation, sourceId: o.sourceId, path: u, error: new TypeError(`[markdown-explorer] an entry with ${p} was left out`) });
|
|
689
|
-
try {
|
|
690
|
-
return { status: "ok", entries: tn(n, h, i.children !== void 0, c, (u) => W(i, u)) };
|
|
691
|
-
} catch (u) {
|
|
692
|
-
return D(f, { ...o, error: u }), { status: "error", failure: { reason: "failed" } };
|
|
693
|
-
}
|
|
694
|
-
}, kt = async (n, i, o) => {
|
|
695
|
-
let c;
|
|
696
|
-
try {
|
|
697
|
-
c = await n.tree(i);
|
|
698
|
-
} catch (p) {
|
|
699
|
-
return { status: "error", failure: A(p, { operation: "tree", sourceId: n.id }, i.signal, f) };
|
|
700
|
-
}
|
|
701
|
-
const u = Oe(c, n, { operation: "tree", sourceId: n.id });
|
|
702
|
-
return u.status === "ok" ? { status: "ok", entries: u.entries, loadedAt: o } : u;
|
|
703
|
-
}, ve = (n, i, o, c) => (u, p) => kt(n, { principal: i, request: o, signal: u, refresh: c }, p), Ae = (n, i, o, c, u) => C.load(ce(n, o), u, ve(n, i, c, !1)), Rt = (n, i, o, c) => C.refresh(ce(n, o), c.signal, ve(n, i, c, !0)), xt = (n, i) => {
|
|
704
|
-
if (xe === void 0) return;
|
|
705
|
-
const o = (c) => D(f, { operation: "refresh", sourceId: n.id, error: c });
|
|
706
|
-
try {
|
|
707
|
-
He(xe(i), o);
|
|
708
|
-
} catch (c) {
|
|
709
|
-
o(c);
|
|
710
|
-
}
|
|
711
|
-
}, Ot = async (n, i, o, c) => {
|
|
712
|
-
if (h.deniesPath(c) || !W(n, c)) return { status: "error", failure: { reason: "forbidden" } };
|
|
713
|
-
const u = await de(n, o, c);
|
|
714
|
-
if (u.status === "outside") return { status: "error", failure: { reason: "forbidden" } };
|
|
715
|
-
if (u.status === "error") return { status: "error", failure: u.failure };
|
|
716
|
-
let p;
|
|
717
|
-
try {
|
|
718
|
-
p = await i(o, c, u.readPath);
|
|
719
|
-
} catch (y) {
|
|
720
|
-
return { status: "error", failure: A(y, { operation: "children", sourceId: n.id, path: c }, o.signal, f) };
|
|
721
|
-
}
|
|
722
|
-
return Oe(p, n, { operation: "children", sourceId: n.id, path: c });
|
|
723
|
-
}, Se = async (n, i, o, c) => {
|
|
724
|
-
const u = await de(n, o, c);
|
|
725
|
-
if (u.status === "outside") return { status: "ok", ancestors: null };
|
|
726
|
-
if (u.status === "error") return { status: "error", failure: u.failure };
|
|
727
|
-
let p;
|
|
728
|
-
try {
|
|
729
|
-
p = await i(o, c, u.readPath, { maxDepth: r.revealDocument.maxDepth });
|
|
730
|
-
} catch (y) {
|
|
731
|
-
return { status: "error", failure: A(y, { operation: "ancestors", sourceId: n.id, path: c }, o.signal, f) };
|
|
732
|
-
}
|
|
733
|
-
if (Array.isArray(p) && p.length > r.revealDocument.maxDepth) return { status: "ok", ancestors: null };
|
|
734
|
-
try {
|
|
735
|
-
return { status: "ok", ancestors: en(p, c, h, (y) => W(n, y)) };
|
|
736
|
-
} catch (y) {
|
|
737
|
-
return D(f, { operation: "ancestors", sourceId: n.id, path: c, error: y }), { status: "error", failure: { reason: "failed" } };
|
|
738
|
-
}
|
|
739
|
-
}, vt = async (n, i, o, c) => h.deniesPath(c) ? { status: "error", failure: { reason: "forbidden" } } : W(n, c) ? Se(n, i, o, c) : { status: "ok", ancestors: null }, At = async (n, i, o) => {
|
|
740
|
-
if (h.deniesPath(o)) return { status: "error", failure: { reason: "forbidden" } };
|
|
741
|
-
for (const c of [n, ...a.filter((u) => u !== n)]) {
|
|
742
|
-
if (i.signal.aborted) break;
|
|
743
|
-
const u = c.ancestors;
|
|
744
|
-
if (u === void 0 || !W(c, o)) continue;
|
|
745
|
-
const p = await Se(c, u, i, o);
|
|
746
|
-
if (p.status === "ok" && p.ancestors !== null) return { status: "ok", source: c.id, ancestors: p.ancestors };
|
|
747
|
-
}
|
|
748
|
-
return bn;
|
|
749
|
-
}, Pe = async (n, i, o) => {
|
|
750
|
-
if (h.deniesPath(o)) return B("forbidden");
|
|
751
|
-
const c = await ee(n, o);
|
|
752
|
-
if (c.status === "error") return { kind: "failure", failure: c.failure };
|
|
753
|
-
let u;
|
|
754
|
-
try {
|
|
755
|
-
u = await e.document(n, o, c.readPath);
|
|
756
|
-
} catch (E) {
|
|
757
|
-
return { kind: "failure", failure: A(E, { operation: "document", path: o }, n.signal, f) };
|
|
758
|
-
}
|
|
759
|
-
let p;
|
|
760
|
-
try {
|
|
761
|
-
p = on(u, (E) => De(r.dataPath, o, E), g !== void 0);
|
|
762
|
-
} catch (E) {
|
|
763
|
-
return D(f, { operation: "document", path: o, error: E }), B("failed");
|
|
764
|
-
}
|
|
765
|
-
if (p.kind !== "unsanitized-markdown") return p;
|
|
766
|
-
const y = await G(p.html, { scope: i, signal: n.signal });
|
|
767
|
-
return y.status === "sanitized" ? { kind: "markdown", name: p.name, htmlContent: y.html, headings: p.headings, lang: p.lang, edit: p.edit } : (y.cause !== null && D(f, { operation: "document", path: o, error: y.cause }), B(y.reason));
|
|
768
|
-
}, St = async (n) => {
|
|
769
|
-
if (e.notices === void 0) return he;
|
|
770
|
-
try {
|
|
771
|
-
return yn(await e.notices(n));
|
|
772
|
-
} catch (i) {
|
|
773
|
-
return A(i, { operation: "notices" }, n.signal, f), he;
|
|
774
|
-
}
|
|
775
|
-
}, _e = async (n, i, o, c) => {
|
|
776
|
-
const u = F(i, z.path);
|
|
777
|
-
if (u === null || !U(u)) return { status: "answered", response: R({ reason: "invalid" }, o) };
|
|
778
|
-
const p = br(i);
|
|
779
|
-
if (p === null || !c.has(p)) return { status: "answered", response: R({ reason: "invalid" }, o) };
|
|
780
|
-
if (h.deniesPath(u))
|
|
781
|
-
return fe(f, { operation: "asset", path: u }), { status: "answered", response: R({ reason: "forbidden" }, o) };
|
|
782
|
-
const y = await ee(n, u);
|
|
783
|
-
if (y.status === "error") return { status: "answered", response: R(y.failure, o) };
|
|
784
|
-
try {
|
|
785
|
-
const E = await e.asset(n, u, y.readPath, { delivery: p }), k = p === "file" ? wn(E) : ge(E);
|
|
786
|
-
return "kind" in k ? { status: "answered", response: Br(k.url, o) } : { status: "admitted", path: u, display: p, file: k };
|
|
787
|
-
} catch (E) {
|
|
788
|
-
return { status: "answered", response: R(A(E, { operation: "asset", path: u }, n.signal, f), o) };
|
|
789
|
-
}
|
|
790
|
-
}, Pt = async (n, i, o) => {
|
|
791
|
-
const c = await _e(n, i, o, Tn);
|
|
792
|
-
if (c.status === "answered") return c.response;
|
|
793
|
-
const { path: u, display: p, file: y } = c;
|
|
794
|
-
try {
|
|
795
|
-
return p === "text" ? await zr(n.request, y, o, r.legacyTextEncoding, j) : p === "workbook" ? await Ur(n.request, y, o) : await jr(n.request, y, o, j);
|
|
796
|
-
} catch (E) {
|
|
797
|
-
return R(A(E, { operation: "asset", path: u }, n.signal, f), o);
|
|
798
|
-
}
|
|
799
|
-
}, _t = async (n, i, o) => {
|
|
800
|
-
const c = wt(n, i, o, r.legacyTextEncoding, j);
|
|
801
|
-
return c.kind === "respond" ? c : me(c.selection, await ht(i, r.legacyTextEncoding));
|
|
802
|
-
}, $t = async (n, i, o) => {
|
|
803
|
-
const c = await _e(n, i, o, kn);
|
|
804
|
-
if (c.status === "answered") return { kind: "response", response: c.response };
|
|
805
|
-
const { path: u, display: p, file: y } = c, E = (S) => R(A(S, { operation: "asset", path: u }, n.signal, f), o);
|
|
806
|
-
let k;
|
|
807
|
-
try {
|
|
808
|
-
k = p === "text" ? await _t(n.request, y, o) : ft(n.request, y, o, j);
|
|
809
|
-
} catch (S) {
|
|
810
|
-
return { kind: "response", response: E(S) };
|
|
811
|
-
}
|
|
812
|
-
if (k.kind === "respond") return { kind: "response", response: k.response };
|
|
813
|
-
const { bridge: N } = y;
|
|
814
|
-
return N === void 0 ? (D(f, { operation: "asset", path: u, error: new TypeError("[markdown-explorer] the asset port must attach a bridge to a file the host streams itself") }), { kind: "response", response: R({ reason: "failed" }, o) }) : { kind: "file", status: k.status, headers: k.headers, bridge: { uri: N.uri, storageVersion: N.storageVersion }, range: k.range, length: k.length, fail: (S) => E(An(N.readFailure, S)) };
|
|
815
|
-
}, It = async (n, i) => {
|
|
816
|
-
if (h.deniesPath(i))
|
|
817
|
-
return fe(f, { operation: "text", path: i }), B("forbidden");
|
|
818
|
-
const o = await ee(n, i);
|
|
819
|
-
if (o.status === "error") return { kind: "failure", failure: o.failure };
|
|
820
|
-
try {
|
|
821
|
-
const c = ge(await e.asset(n, i, o.readPath, { delivery: "text" })), u = await Kr(c, w, r.legacyTextEncoding);
|
|
822
|
-
return u === null ? B("unsupported") : { kind: "text", name: c.name, text: u.text, truncated: u.truncated, url: De(r.dataPath, i, c.version) };
|
|
823
|
-
} catch (c) {
|
|
824
|
-
return { kind: "failure", failure: A(c, { operation: "text", path: i }, n.signal, f) };
|
|
825
|
-
}
|
|
826
|
-
}, J = async (n, i, o) => h.deniesPath(o) ? (fe(f, { operation: i, path: o }), { status: "error", failure: { reason: "forbidden" } }) : ee(n, o), Nt = async (n, i, o) => {
|
|
827
|
-
const c = await J(i, "edit", o);
|
|
828
|
-
if (c.status === "error") return { kind: "failure", failure: c.failure };
|
|
829
|
-
try {
|
|
830
|
-
return dn(await n.source(i, o, c.readPath), b);
|
|
831
|
-
} catch (u) {
|
|
832
|
-
return { kind: "failure", failure: A(u, { operation: "edit", path: o }, i.signal, f) };
|
|
833
|
-
}
|
|
834
|
-
}, Lt = async (n, i, o, c, u) => {
|
|
835
|
-
const p = await J(i, "save", o);
|
|
836
|
-
if (p.status === "error") return { kind: "failure", failure: p.failure };
|
|
837
|
-
try {
|
|
838
|
-
return un(await n.save(i, o, p.readPath, { text: u, baseVersion: c }), b);
|
|
839
|
-
} catch (y) {
|
|
840
|
-
return { kind: "failure", failure: A(y, { operation: "save", path: o }, i.signal, f) };
|
|
841
|
-
}
|
|
842
|
-
}, Dt = async (n, i, o, c, u) => {
|
|
843
|
-
const p = await J(i, "preview", c);
|
|
844
|
-
if (p.status === "error") return { kind: "failure", failure: p.failure };
|
|
845
|
-
let y;
|
|
846
|
-
try {
|
|
847
|
-
y = ln(await n.preview(i, c, p.readPath, u));
|
|
848
|
-
} catch (k) {
|
|
849
|
-
return { kind: "failure", failure: A(k, { operation: "preview", path: c }, i.signal, f) };
|
|
850
|
-
}
|
|
851
|
-
if ("kind" in y) return y.kind === "failure" ? y : B("failed");
|
|
852
|
-
const E = await G(y.html, { scope: o, signal: i.signal });
|
|
853
|
-
return E.status === "sanitized" ? { kind: "preview", htmlContent: E.html, headings: y.headings } : (E.cause !== null && D(f, { operation: "preview", path: c, error: E.cause }), B(E.reason));
|
|
854
|
-
}, jt = async (n, i, o) => {
|
|
855
|
-
const c = await J(i, "revisions", o);
|
|
856
|
-
if (c.status === "error") return { kind: "failure", failure: c.failure };
|
|
857
|
-
try {
|
|
858
|
-
return { kind: "revisions", revisions: fn(await n.revisions(i, o, c.readPath)) };
|
|
859
|
-
} catch (u) {
|
|
860
|
-
return { kind: "failure", failure: A(u, { operation: "revisions", path: o }, i.signal, f) };
|
|
861
|
-
}
|
|
862
|
-
}, Mt = async (n, i, o, c) => {
|
|
863
|
-
const u = await J(i, "revision", o);
|
|
864
|
-
if (u.status === "error") return { kind: "failure", failure: u.failure };
|
|
865
|
-
try {
|
|
866
|
-
return { kind: "revision", id: c, text: pn(await n.revision(i, o, u.readPath, c), b) };
|
|
867
|
-
} catch (p) {
|
|
868
|
-
return { kind: "failure", failure: A(p, { operation: "revision", path: o }, i.signal, f) };
|
|
869
|
-
}
|
|
870
|
-
}, Ct = async (n, i, o, c, u, p) => {
|
|
871
|
-
const y = F(u, z.path);
|
|
872
|
-
if (y === null || !U(y)) return R({ reason: "invalid" }, p);
|
|
873
|
-
if (i === "edit") return I(200, JSON.stringify(await Nt(n, o, y)), p);
|
|
874
|
-
if (i === "revisions") return I(200, JSON.stringify(await jt(n, o, y)), p);
|
|
875
|
-
if (i === "revision") {
|
|
876
|
-
const N = F(u, z.revision);
|
|
877
|
-
return Z(N) ? I(200, JSON.stringify(await Mt(n, o, y, N)), p) : R({ reason: "invalid" }, p);
|
|
878
|
-
}
|
|
879
|
-
const E = F(u, z.base);
|
|
880
|
-
if (i === "save" && !Z(E)) return R({ reason: "invalid" }, p);
|
|
881
|
-
const k = await Nn(o.request, b);
|
|
882
|
-
return k.status === "error" ? R(k.failure, p) : i === "preview" ? I(200, JSON.stringify(await Dt(n, o, c, y, k.text)), p) : I(200, JSON.stringify(await Lt(n, o, y, E, k.text)), p);
|
|
883
|
-
}, zt = async ({ request: n, url: i, params: o }) => {
|
|
884
|
-
const c = Ke(await q(n, Ge)), u = We(c.headers);
|
|
885
|
-
if (u.set("Cache-Control", bt), c.status === "signed-out") throw Je("signedOutPage", Et(n, u));
|
|
886
|
-
if (c.status === "forbidden") throw Re === void 0 ? Le(null, { status: 403, headers: u }) : Je("forbiddenPage", Re(n, u));
|
|
887
|
-
const p = Qt(d, o["*"], i.searchParams);
|
|
888
|
-
if (p.kind === "redirect") throw Xt(p.href, { headers: u });
|
|
889
|
-
const { location: y } = p, { principal: E } = c, k = Qe(s, K(E)), N = L.get(y.source);
|
|
890
|
-
if (N === void 0) throw new RangeError(`[markdown-explorer] no source for ${O(y.source)}`);
|
|
891
|
-
const S = { signal: n.signal, timeoutMs: T, late: null, handOverMs: T }, $ = {
|
|
892
|
-
scope: k,
|
|
893
|
-
sources: a.map((v) => ({ id: v.id, label: Tt(v, E) })),
|
|
894
|
-
settings: Zt(Sn(H, n), M),
|
|
895
|
-
tree: y.view === "single" ? null : {
|
|
896
|
-
sourceId: y.source,
|
|
897
|
-
result: le(S, (v) => Ae(N, E, k, n, v).then((Y) => Y.result))
|
|
898
|
-
},
|
|
899
|
-
documents: Pn(y).map((v) => ({ path: v, document: le(S, (Y) => Pe({ principal: E, request: n, signal: Y, refresh: !1 }, k, v)) })),
|
|
900
|
-
notices: le({ signal: n.signal, timeoutMs: T, late: he, handOverMs: 0 }, (v) => St({ principal: E, request: n, signal: v, refresh: !1 }))
|
|
901
|
-
};
|
|
902
|
-
return Le($, { headers: u });
|
|
903
|
-
}, $e = async (n, i) => {
|
|
904
|
-
const o = Ke(await q(n, i));
|
|
905
|
-
return { authentication: o, headers: We(o.headers) };
|
|
906
|
-
}, Ie = async (n) => {
|
|
907
|
-
let i;
|
|
908
|
-
try {
|
|
909
|
-
i = await $e(n, Ge);
|
|
910
|
-
} catch (u) {
|
|
911
|
-
return { status: "answered", response: R(A(Ye(u), { operation: "authenticate" }, n.signal, f)) };
|
|
912
|
-
}
|
|
913
|
-
const { authentication: o, headers: c } = i;
|
|
914
|
-
return o.status === "signed-out" ? { status: "answered", response: R({ reason: "unauthorized" }, c) } : o.status === "forbidden" ? { status: "answered", response: R({ reason: "forbidden" }, c) } : { status: "signed-in", principal: o.principal, headers: c };
|
|
915
|
-
}, Ft = async (n, i, o) => {
|
|
916
|
-
const c = await Ie(i);
|
|
917
|
-
if (c.status === "answered") return c.response;
|
|
918
|
-
const { principal: u, headers: p } = c;
|
|
919
|
-
if (n === "asset") return Pt({ principal: u, request: i, signal: i.signal, refresh: !1 }, o, p);
|
|
920
|
-
const y = Qe(s, K(u));
|
|
921
|
-
p.set(gr, y);
|
|
922
|
-
const E = { principal: u, request: i, signal: i.signal, refresh: !1 }, k = () => R({ reason: "invalid" }, p);
|
|
923
|
-
if (n === "document") {
|
|
924
|
-
const v = F(o, z.path);
|
|
925
|
-
if (v === null || !U(v)) return k();
|
|
926
|
-
const Y = i.headers.has(be);
|
|
927
|
-
return Y && !qe(i) ? R({ reason: "forbidden" }, p) : I(200, JSON.stringify(await Pe({ ...E, refresh: Y }, y, v)), p);
|
|
928
|
-
}
|
|
929
|
-
if (n === "text") {
|
|
930
|
-
const v = F(o, z.path);
|
|
931
|
-
return v === null || !U(v) ? k() : I(200, JSON.stringify(await It(E, v)), p);
|
|
932
|
-
}
|
|
933
|
-
if (n === "edit" || n === "save" || n === "preview" || n === "revisions" || n === "revision")
|
|
934
|
-
return g === void 0 ? R({ reason: "not-found" }, p) : Ct(g, n, E, y, o, p);
|
|
935
|
-
const N = F(o, z.source), S = F(o, z.path);
|
|
936
|
-
if (N === null || (n === "children" || n === "ancestors" || n === "reveal") && (S === null || !U(S))) return k();
|
|
937
|
-
const $ = L.get(N);
|
|
938
|
-
if ($ === void 0) return R({ reason: "not-found" }, p);
|
|
939
|
-
if (n === "tree") return I(200, (await Ae($, u, y, i, i.signal)).json, p);
|
|
940
|
-
if (n === "refresh") {
|
|
941
|
-
const v = await Rt($, u, y, i);
|
|
942
|
-
return i.signal.aborted || xt($, ce($, y)), I(200, v.json, p);
|
|
943
|
-
}
|
|
944
|
-
return n === "ancestors" ? $.ancestors === void 0 || S === null ? R({ reason: "not-found" }, p) : I(200, JSON.stringify(await vt($, $.ancestors, E, S)), p) : n === "reveal" ? S === null ? k() : I(200, JSON.stringify(await At($, E, S)), p) : $.children === void 0 || S === null ? R({ reason: "not-found" }, p) : I(200, JSON.stringify(await Ot($, $.children, E, S)), p);
|
|
945
|
-
}, Ut = async (n) => {
|
|
946
|
-
const { authentication: i, headers: o } = await $e(n, En);
|
|
947
|
-
if (!o.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)");
|
|
948
|
-
return i.status === "signed-in";
|
|
949
|
-
}, Ne = r.embeds.linkCardEndpoint === null ? null : t.createLinkCardHandler({ authorize: Ut }), Ht = async (n, i) => {
|
|
950
|
-
try {
|
|
951
|
-
return await n(i);
|
|
952
|
-
} catch (o) {
|
|
953
|
-
return R(A(Ye(o), { operation: "authenticate" }, i.signal, f));
|
|
954
|
-
}
|
|
955
|
-
}, ue = async (n, i, o) => {
|
|
956
|
-
if (new URL(n.url).pathname.endsWith(".data")) return R({ reason: "not-found" });
|
|
957
|
-
if (!hr(o)) return R({ reason: "not-found" });
|
|
958
|
-
if (o === "link-card") {
|
|
959
|
-
if (Ne === null) return R({ reason: "not-found" });
|
|
960
|
-
const u = Ze(n, o);
|
|
961
|
-
return u !== null ? u : Ht(Ne, n);
|
|
962
|
-
}
|
|
963
|
-
if ($n.has(o) && g === void 0) return R({ reason: "not-found" });
|
|
964
|
-
const c = Ze(n, o);
|
|
965
|
-
if (c !== null) return c;
|
|
966
|
-
if (o === "refresh" && !qe(n)) return R({ reason: "forbidden" });
|
|
967
|
-
if ((o === "save" || o === "preview") && !In(n)) return R({ reason: "forbidden" });
|
|
968
|
-
try {
|
|
969
|
-
return await Ft(o, n, i.searchParams);
|
|
970
|
-
} catch (u) {
|
|
971
|
-
return R(A(u, { operation: o }, n.signal, f));
|
|
972
|
-
}
|
|
973
|
-
}, Bt = async (n, i, o) => {
|
|
974
|
-
if (o !== "asset" || n.method.toUpperCase() !== "GET" || new URL(n.url).pathname.endsWith(".data")) return { kind: "response", response: await ue(n, i, o) };
|
|
975
|
-
try {
|
|
976
|
-
const c = await Ie(n);
|
|
977
|
-
return c.status === "answered" ? { kind: "response", response: c.response } : await $t({ principal: c.principal, request: n, signal: n.signal, refresh: !1 }, i.searchParams, c.headers);
|
|
978
|
-
} catch (c) {
|
|
979
|
-
return { kind: "response", response: R(A(c, { operation: "asset" }, n.signal, f)) };
|
|
980
|
-
}
|
|
981
|
-
};
|
|
982
|
-
return Object.freeze({
|
|
983
|
-
loader: zt,
|
|
984
|
-
headers: Dn,
|
|
985
|
-
dataLoader: ({ request: n, url: i, params: o }) => ue(n, i, o["*"]),
|
|
986
|
-
dataAction: ({ request: n, url: i, params: o }) => ue(n, i, o["*"]),
|
|
987
|
-
planData: ({ request: n, url: i, params: o }) => Bt(n, i, o["*"]),
|
|
988
|
-
forgetTree: (n) => {
|
|
989
|
-
if (typeof n != "string") throw new TypeError(`[markdown-explorer] forgetTree needs the string key onTreeRefreshed received; got ${O(n)}`);
|
|
990
|
-
C.forget(n);
|
|
991
|
-
}
|
|
992
|
-
});
|
|
993
|
-
};
|
|
994
|
-
export {
|
|
995
|
-
we as A,
|
|
996
|
-
Bn as E,
|
|
997
|
-
Xn as c
|
|
998
|
-
};
|