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