@aiquants/markdown-explorer 0.34.0 → 0.36.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 +608 -0
- package/README.md +121 -41
- package/dist/EditSurface-B70iRFkG.cjs +6 -0
- package/dist/EditSurface-BCFJRyIM.js +990 -0
- package/dist/ExplorerSplit-BNrHrIus.cjs +2 -0
- package/dist/ExplorerSplit-Bgccz2nm.js +1589 -0
- package/dist/MultiLayout-Bo9LAXiY.cjs +1 -0
- package/dist/{MultiLayout-kcZyVnvK.js → MultiLayout-Dy5TIC2t.js} +249 -248
- package/dist/{NativeScrollBar-pUbA4Zq3.cjs → NativeScrollBar-Bj-LKej0.cjs} +1 -1
- package/dist/{NativeScrollBar-UNed10Na.js → NativeScrollBar-DpZMYhmf.js} +2 -2
- package/dist/TreeLayout-DsSKW_Qj.js +103 -0
- package/dist/TreeLayout-T8sc_wg7.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 +13 -0
- package/dist/core/config.d.ts +13 -0
- package/dist/core/contracts.d.cts +31 -4
- package/dist/core/contracts.d.ts +31 -4
- package/dist/core/dataRoute.d.cts +5 -1
- package/dist/core/dataRoute.d.ts +5 -1
- package/dist/core/documentId.d.cts +6 -0
- package/dist/core/documentId.d.ts +6 -0
- package/dist/core/draftAnswer.d.cts +23 -0
- package/dist/core/draftAnswer.d.ts +23 -0
- package/dist/core/labels.d.cts +78 -0
- package/dist/core/labels.d.ts +78 -0
- package/dist/core/location.d.cts +22 -2
- package/dist/core/location.d.ts +22 -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 +3 -1
- package/dist/core/viewSettings.d.ts +3 -1
- package/dist/describeValue-CLlVRO8d.js +17 -0
- package/dist/describeValue-Ccvhbt36.cjs +1 -0
- package/dist/explorerCore-B3RGmMG6.js +1083 -0
- package/dist/explorerCore-CUkyKtm8.cjs +1 -0
- package/dist/index-D0l_BJqb.js +5980 -0
- package/dist/index-lpL7GltU.cjs +18 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +53 -43
- 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-Dh6K-y7w.js +761 -0
- package/dist/location-DrOP6t1F.cjs +1 -0
- package/dist/lru-DC8GBmkX.js +39 -0
- package/dist/lru-SGmUyBQU.cjs +1 -0
- package/dist/{merge-C1MWvhCS.js → merge-BwcqBd4c.js} +1 -1
- package/dist/{merge-BziXxZkE.cjs → merge-Dckw7r9T.cjs} +1 -1
- package/dist/nestingGuardWorker.js +5511 -0
- package/dist/ownUrls-BTPGNhBt.cjs +1 -0
- package/dist/ownUrls-DD0cSCsF.js +409 -0
- package/dist/sanitizeJob-BYqzjFJC.js +21 -0
- package/dist/sanitizeJob-CudE1RUP.cjs +1 -0
- package/dist/sanitizePolicy-C-ehd0J_.cjs +2 -0
- package/dist/sanitizePolicy-DAPnUUVm.js +139 -0
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +134 -139
- package/dist/sanitizerService-B8v4ap9t.js +240 -0
- package/dist/sanitizerService-DomN7lwC.cjs +1 -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/errors.d.cts +1 -1
- package/dist/server/errors.d.ts +1 -1
- 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 +55 -5
- package/dist/server/ports.d.ts +55 -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-DigcJCsu.cjs → tapScrollCircle-DyLInGck.cjs} +1 -1
- package/dist/{tapScrollCircle-D_BpaLwY.js → tapScrollCircle-smKLgRa2.js} +1 -1
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +11 -0
- package/dist/testing.d.ts +11 -0
- package/dist/testing.js +82 -0
- package/dist/useSplitPersistence-BUa_KMsV.cjs +1 -0
- package/dist/useSplitPersistence-pnb21dsr.js +44 -0
- package/docs/behavior/dom-hooks.md +5 -1
- package/docs/behavior/hosting.md +123 -0
- package/docs/behavior/layout.md +5 -3
- package/docs/behavior/localization.md +25 -8
- package/docs/behavior/security.md +55 -15
- package/docs/behavior/url-contract.md +30 -3
- package/package.json +48 -10
- package/dist/EditSurface-CF82jZQg.cjs +0 -6
- package/dist/EditSurface-CqHk2R3k.js +0 -982
- package/dist/ExplorerSplit-D325YGEf.cjs +0 -1
- package/dist/ExplorerSplit-DGH9bckm.js +0 -1500
- package/dist/MultiLayout-CzR7yJ0m.cjs +0 -1
- package/dist/TreeLayout-BnIU87HX.js +0 -96
- package/dist/TreeLayout-DtvIpuOe.cjs +0 -1
- package/dist/dataRoute-D6KiSHIc.js +0 -298
- package/dist/dataRoute-DwYtgyt6.cjs +0 -1
- package/dist/index-BDCbvHDs.cjs +0 -15
- package/dist/index-DR31S_-4.js +0 -5012
- package/dist/location-C44b9H1S.js +0 -676
- package/dist/location-hGLhCCg4.cjs +0 -1
- package/dist/sanitizePolicy-CwvyPpp5.js +0 -98
- package/dist/sanitizePolicy-T5T-3vV5.cjs +0 -1
- package/dist/storage-DM0EvkVf.cjs +0 -1
- package/dist/useSplitPersistence-DCeYbJMx.js +0 -38
- package/dist/useSplitPersistence-QGcvyMAa.cjs +0 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { CODE_META_ATTRIBUTE as D } from "@aiquants/markdown/code-blocks";
|
|
2
|
+
import { allowedFrameUrlOf as U, reduceFrameFeatures as z, EMBED_FRAME_REFERRER_POLICIES as C, EMBED_LINK_ATTRIBUTE as E, placeholderLinkOf as M } from "@aiquants/markdown/embeds";
|
|
3
|
+
import { SOURCE_LINES_ATTRIBUTE as h, parseSourceLines as x } from "@aiquants/markdown/source-lines";
|
|
4
|
+
import { c as H, i as j, e as B } from "./ownUrls-DD0cSCsF.js";
|
|
5
|
+
import { d as F } from "./describeValue-CLlVRO8d.js";
|
|
6
|
+
const be = 256;
|
|
7
|
+
class G extends RangeError {
|
|
8
|
+
constructor(s) {
|
|
9
|
+
super(`[markdown-explorer] the HTML nests deeper than ${String(s)} levels`), this.name = "HtmlNestingLimitError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const y = ["script", "style", "noscript", "template", "form", "button", "textarea", "select", "option", "object", "embed", "base", "meta", "link", "frame", "frameset"], P = ["srcdoc", "formaction"], V = /^(?:(?:https?|mailto|tel):|[^a-z]|[a-z][a-z\d+.-]*(?:[^a-z\d+.:-]|$))/iu, W = /* @__PURE__ */ new Set(["left", "right", "center", "justify", "start", "end"]), v = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]), T = 1, $ = 3, X = 7, K = 8, Y = "http://www.w3.org/1999/xhtml", Z = "http://www.w3.org/2000/svg", q = Object.freeze(["src", "poster", "background", "href", "xlink:href"]), J = /* @__PURE__ */ new Set(["video", "audio", "source"]), Q = Object.freeze(["clip-path", "color-profile", "cursor", "fill", "filter", "marker-end", "marker-mid", "marker-start", "mask", "stroke"]), ee = Object.freeze(["image-set(", "image(", "src(", "element(", "cross-fade("]), te = /url\([\t\n\f\r ]*["']?(#?)/gu, re = /* @__PURE__ */ new Set([" ", `
|
|
13
|
+
`, "\f", "\r", " "]), w = Object.freeze({
|
|
14
|
+
a: Object.freeze(["target", "data-link-kind", "data-doc-path", "data-doc-exists", "data-footnote-ref", "data-footnote-backref"]),
|
|
15
|
+
area: Object.freeze(["target"]),
|
|
16
|
+
img: Object.freeze(["data-asset-src", "data-asset-exists"]),
|
|
17
|
+
section: Object.freeze(["data-footnotes"]),
|
|
18
|
+
code: Object.freeze([D]),
|
|
19
|
+
iframe: Object.freeze(["allow", "allowfullscreen", "frameborder", "referrerpolicy"])
|
|
20
|
+
}), se = [.../* @__PURE__ */ new Set([...Object.values(w).flatMap((t) => t.filter((s) => s.startsWith("data-"))), h])], oe = /* @__PURE__ */ new Set(["src", "href", "xlink:href"]), ae = /^data:/iu, ne = Object.freeze({
|
|
21
|
+
FORBID_TAGS: y,
|
|
22
|
+
FORBID_ATTR: P,
|
|
23
|
+
ADD_TAGS: ["iframe"],
|
|
24
|
+
ADD_ATTR: (t, s) => t === h || w[s]?.includes(t) === !0,
|
|
25
|
+
ADD_URI_SAFE_ATTR: se,
|
|
26
|
+
ALLOWED_URI_REGEXP: V,
|
|
27
|
+
ALLOW_DATA_ATTR: !1
|
|
28
|
+
}), ie = (t) => {
|
|
29
|
+
let s = null;
|
|
30
|
+
for (const i of t.split(";")) {
|
|
31
|
+
const n = i.indexOf(":");
|
|
32
|
+
if (n < 0 || i.slice(0, n).trim().toLowerCase() !== "text-align") continue;
|
|
33
|
+
const c = i.slice(n + 1).trim().toLowerCase();
|
|
34
|
+
W.has(c) && (s = c);
|
|
35
|
+
}
|
|
36
|
+
return s === null ? null : `text-align: ${s}`;
|
|
37
|
+
}, le = (t) => t.nodeType === $ ? { kind: "text", text: t.nodeValue ?? "" } : t.nodeType === K || t.nodeType === X ? { kind: "ignored" } : t.nodeType === T && t.nodeName.toLowerCase() === "a" ? { kind: "link", href: t.getAttribute("href") } : { kind: "element" }, ce = (t) => {
|
|
38
|
+
const s = t.getAttribute("type");
|
|
39
|
+
return s !== null && s.trim().toLowerCase() === "checkbox" && t.hasAttribute("disabled");
|
|
40
|
+
}, N = (t) => t.replace(/[A-Z]/gu, (s) => s.toLowerCase()), ue = (t) => {
|
|
41
|
+
const s = [], i = (c) => re.has(t.charAt(c));
|
|
42
|
+
let n = 0;
|
|
43
|
+
for (; n < t.length; ) {
|
|
44
|
+
if (i(n) || t.charAt(n) === ",") {
|
|
45
|
+
n += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const c = n;
|
|
49
|
+
for (; n < t.length && !i(n); ) n += 1;
|
|
50
|
+
const d = t.slice(c, n);
|
|
51
|
+
if (s.push(d.replace(/,+$/u, "")), d.endsWith(",")) continue;
|
|
52
|
+
let A = !1;
|
|
53
|
+
for (; n < t.length; ) {
|
|
54
|
+
const u = t.charAt(n);
|
|
55
|
+
if (n += 1, A) A = u !== ")";
|
|
56
|
+
else if (u === "(") A = !0;
|
|
57
|
+
else if (u === ",") break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return s;
|
|
61
|
+
}, fe = (t) => {
|
|
62
|
+
if (t.includes("\\")) return !1;
|
|
63
|
+
const s = N(t);
|
|
64
|
+
return !ee.some((i) => s.includes(i)) && [...s.matchAll(te)].every((i) => i[1] === "#");
|
|
65
|
+
}, de = (t, s, i) => i === "src" ? J.has(s) ? "media" : "resource" : i !== "href" && i !== "xlink:href" ? "resource" : t.namespaceURI === Z ? s === "image" ? "resource" : s === "a" && i === "href" ? "link" : "svg-reference" : i === "xlink:href" ? "resource" : s === "a" && t.namespaceURI === Y && t.getAttribute("data-link-kind") === "doc" ? "document-link" : "link", Ae = (t) => {
|
|
66
|
+
const s = t.getAttribute("preload");
|
|
67
|
+
t.setAttribute("preload", s !== null && N(s) === "none" ? "none" : "metadata");
|
|
68
|
+
}, Se = (t, s, i, n, c) => {
|
|
69
|
+
if (t.isSupported !== !0) throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");
|
|
70
|
+
if (!Number.isSafeInteger(n) || n <= 0) throw new RangeError(`[markdown-explorer] the HTML sanitizer's depth limit must be a positive integer; got ${F(n)}`);
|
|
71
|
+
const d = H(c), A = Object.freeze([...s]);
|
|
72
|
+
let u = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), m;
|
|
73
|
+
const b = (r) => {
|
|
74
|
+
const e = r.parentNode === null ? void 0 : u.get(r.parentNode), o = e === void 0 ? 0 : e + 1;
|
|
75
|
+
if (u.set(r, o), r.nodeType === T && o > n) throw new G(n);
|
|
76
|
+
}, S = (r, e) => {
|
|
77
|
+
if (r.nodeType !== T) return;
|
|
78
|
+
const o = r;
|
|
79
|
+
(e.tagName === "input" && !ce(o) || e.tagName === "iframe" && U(o.getAttribute("src")?.trim(), A) === null) && o.parentNode?.removeChild(o);
|
|
80
|
+
}, k = (r, e) => {
|
|
81
|
+
const o = r.nodeName.toLowerCase();
|
|
82
|
+
if (e.attrName === "style") {
|
|
83
|
+
const a = ie(e.attrValue);
|
|
84
|
+
a === null ? e.keepAttr = !1 : e.attrValue = a;
|
|
85
|
+
} else if (e.attrName === "allow" && o === "iframe") {
|
|
86
|
+
const a = z(e.attrValue);
|
|
87
|
+
a === null ? e.keepAttr = !1 : e.attrValue = a;
|
|
88
|
+
} else if (e.attrName === "referrerpolicy" && o === "iframe") {
|
|
89
|
+
const a = e.attrValue.trim().toLowerCase();
|
|
90
|
+
C.has(a) ? e.attrValue = a : e.keepAttr = !1;
|
|
91
|
+
} else e.attrName === E && o === "p" ? p.set(r, r.getAttribute(E)) : oe.has(e.attrName) && ae.test(e.attrValue) || e.attrName === h && x(e.attrValue) === null ? e.keepAttr = !1 : e.attrName === "id" && v.has(o) && (e.forceKeepAttr = !0);
|
|
92
|
+
}, R = (r) => {
|
|
93
|
+
const e = r.getAttribute("data-asset-src");
|
|
94
|
+
e !== null && (r.getAttribute("data-asset-exists") !== "false" && j(e) ? r.setAttribute("src", B(i, e, null)) : r.removeAttribute("src"));
|
|
95
|
+
}, _ = (r, e, o, a) => {
|
|
96
|
+
if (m === void 0) return;
|
|
97
|
+
const l = r.getAttribute(o);
|
|
98
|
+
if (l === null) return;
|
|
99
|
+
const f = m({ kind: e, path: l });
|
|
100
|
+
f !== void 0 && r.setAttribute(a, String(f));
|
|
101
|
+
}, O = (r) => {
|
|
102
|
+
const e = r.parentNode;
|
|
103
|
+
if (e === null) return;
|
|
104
|
+
const o = p.get(e);
|
|
105
|
+
o != null && M(o, [...e.childNodes].map(le)) !== null && e.setAttribute(E, o);
|
|
106
|
+
}, I = (r, e) => {
|
|
107
|
+
for (const a of q) {
|
|
108
|
+
const l = r.getAttribute(a);
|
|
109
|
+
l !== null && !d(l, de(r, e, a)) && r.removeAttribute(a);
|
|
110
|
+
}
|
|
111
|
+
const o = r.getAttribute("srcset");
|
|
112
|
+
o !== null && !ue(o).every((a) => d(a, "resource")) && r.removeAttribute("srcset");
|
|
113
|
+
for (const a of Q) {
|
|
114
|
+
const l = r.getAttribute(a);
|
|
115
|
+
l !== null && !fe(l) && r.removeAttribute(a);
|
|
116
|
+
}
|
|
117
|
+
}, g = (r) => {
|
|
118
|
+
if (r.nodeType !== T) return;
|
|
119
|
+
const e = r, o = e.nodeName.toLowerCase();
|
|
120
|
+
o === "img" && (_(e, "asset", "data-asset-src", "data-asset-exists"), R(e)), I(e, o), o === "a" ? (_(e, "doc", "data-doc-path", "data-doc-exists"), O(e)) : (o === "video" || o === "audio") && Ae(e);
|
|
121
|
+
const a = e.getAttribute("target");
|
|
122
|
+
if (a === null || a.trim().toLowerCase() === "_self") return;
|
|
123
|
+
const l = e.getAttribute("rel"), f = new Set(l === null ? [] : l.split(/\s+/u).filter((L) => L !== ""));
|
|
124
|
+
f.add("noopener"), f.add("noreferrer"), e.setAttribute("rel", [...f].join(" "));
|
|
125
|
+
};
|
|
126
|
+
return (r, e) => {
|
|
127
|
+
u = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), m = e, t.addHook("beforeSanitizeElements", b), t.addHook("uponSanitizeElement", S), t.addHook("uponSanitizeAttribute", k), t.addHook("afterSanitizeAttributes", g);
|
|
128
|
+
try {
|
|
129
|
+
return t.sanitize(r, ne);
|
|
130
|
+
} finally {
|
|
131
|
+
t.removeHook("beforeSanitizeElements", b), t.removeHook("uponSanitizeElement", S), t.removeHook("uponSanitizeAttribute", k), t.removeHook("afterSanitizeAttributes", g), m = void 0;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
export {
|
|
136
|
+
G as H,
|
|
137
|
+
be as M,
|
|
138
|
+
Se as c
|
|
139
|
+
};
|
package/dist/sanitizeWorker.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const W=require("node:worker_threads"),K=require("isomorphic-dompurify"),Y=require("./ownUrls-BTPGNhBt.cjs"),Z=require("./sanitizePolicy-C-ehd0J_.cjs"),T=require("parse5"),I=require("./describeValue-Ccvhbt36.cjs"),H=require("./sanitizeJob-CudE1RUP.cjs"),ee=4096,B=1024,V=Symbol("placement"),F=2,te=3,re=new Set(["html","head","body"]),w=0,L=1,y=2,G=3,x=4,b=5,C=6,S=7,z=8,U=9,Q=10,A=-1,ne=0,oe=1,se=2,ae=3,ie=4,ce=5,J=6,le=7,ue=r=>{switch(r){case 9:case 10:case 12:case 13:case 32:return ne;case 47:return oe;case 62:return se;case 61:return ae;case 34:return ie;case 39:return ce;default:return J}},fe=Uint8Array.from({length:128},(r,c)=>ue(c)),M=60,q=47,de=/[\t\n\f\r />="'<]/g,Ee=/["<]/g,he=/['<]/g,u=-1-y,pe=Int8Array.from([[L,U,A,w,w,w,w],[L,U,A,u,u,u,u],[G,U,A,x,y,y,y],[G,U,A,x,u,u,u],[x,S,A,S,b,C,S],[b,b,b,b,z,b,b],[C,C,C,C,C,z,C],[L,S,A,S,S,S,S],[L,U,A,u,u,u,u],[L,U,A,u,u,u,u]].flat()),$=r=>r>=65&&r<=90||r>=97&&r<=122,Te=(r,c)=>{let i=new Int32Array(Q),f=new Int32Array(Q),a=0,E=0,o=0;for(;o<r.length;){if(a===0){const l=r.indexOf("<",o);if(l<0)return!1;o=l+1,r.charCodeAt(o)===q&&(o+=1),$(r.charCodeAt(o))&&(i[w]=0,a=1<<w,o+=1);continue}if((a&-230)===0&&o>=E){const l=a===1<<b?Ee:a===1<<C?he:de;l.lastIndex=o;const _=l.exec(r);if(_===null)return!1;o=_.index,r.charCodeAt(o)===M&&(E=o+3)}const g=r.charCodeAt(o),O=g<128?fe[g]:J;let p=0;for(let l=a;l!==0;l&=l-1){const _=31-Math.clz32(l&-l);let h=pe[_*le+O],d=i[_];if(h<A&&(h=-1-h,d+=1,d>c))return!0;if(h===A)continue;const v=1<<h;((p&v)===0||d>f[h])&&(f[h]=d),p|=v}$(g)&&(r.charCodeAt(o-1)===M||r.charCodeAt(o-1)===q&&r.charCodeAt(o-2)===M)&&(p&1<<w)===0&&(f[w]=0,p|=1<<w);const m=i;i=f,f=m,a=p,o+=1}return!1};class N extends Error{status;constructor(c){super(`[markdown-explorer] the nesting guard stopped the parse: ${c}`),this.name="ParseStop",this.status=c}}const Ae=(r,c,i,f)=>{if(!Number.isSafeInteger(c)||c<=0)throw new RangeError(`[markdown-explorer] the nesting guard's depth limit must be a positive safe integer; got ${I.describeValue(c)}`);if(!Number.isSafeInteger(i)||i<=0)throw new RangeError(`[markdown-explorer] the nesting guard's node budget must be a positive safe integer; got ${I.describeValue(i)}`);if(!Number.isSafeInteger(f)||f<=0)throw new RangeError(`[markdown-explorer] the nesting guard's attribute character budget must be a positive safe integer; got ${I.describeValue(f)}`);if(Te(r,B))return{status:"too-many-attributes"};const a=c+F,E=r.length+te;let o=null,g=0,O=0,p=0,m=0;const l=e=>{if(O+=e,O>i)throw new N("too-many-nodes")},_=e=>{for(const t of e)m+=t.name.length+t.value.length;if(m>f)throw new N("too-many-attribute-characters")},h=(e,t,n,s)=>{const P={node:e,above:null,levels:t,height:0,keepsChildren:n,attributes:s,first:null,next:null,previous:null},X=e;return X[V]=P,P},d=e=>{const n=e[V];if(n===void 0)throw new Error("[markdown-explorer] the nesting guard was handed a node it did not create");return n},v=(e,t)=>{let n=t;for(let s=e;s!==null&&n>s.height;s=s.above)s.height=n,n+=s.levels;if(o!==null&&o.height>a)throw new N("too-deep")},R=e=>{const t=e.above;t?.keepsChildren&&(e.previous===null?t.first=e.next:e.previous.next=e.next,e.next!==null&&(e.next.previous=e.previous)),e.above=null,e.next=null,e.previous=null},k=(e,t)=>{if(!T.defaultTreeAdapter.isElementNode(t))return;const n=d(t),s=d(e);R(n),n.above=s,s.keepsChildren&&(n.next=s.first,s.first!==null&&(s.first.previous=n),s.first=n),t.parentNode=e,v(s,n.height+n.levels)},j={...T.defaultTreeAdapter,createDocument:()=>{const e=T.defaultTreeAdapter.createDocument();return o=h(e,0,!1,0),e},createDocumentFragment:()=>{const e=T.defaultTreeAdapter.createDocumentFragment();return h(e,0,!1,0),e},createElement:(e,t,n)=>{if(g+=1,g>E)throw new N("too-many-elements");l(1+n.length),_(n);const s=T.defaultTreeAdapter.createElement(e,t,n);return h(s,1,!(t===T.html.NS.HTML&&re.has(e)),n.length),s},createCommentNode:e=>{if(p+=1,p>ee)throw new N("too-many-comments");return l(1),T.defaultTreeAdapter.createCommentNode(e)},setTemplateContent:(e,t)=>{T.defaultTreeAdapter.setTemplateContent(e,t);const n=d(t);n.above=d(e),v(n.above,n.height)},appendChild:k,insertBefore:(e,t)=>k(e,t),detachNode:e=>{T.defaultTreeAdapter.isElementNode(e)&&(R(d(e)),e.parentNode=null)},getFirstChild:e=>{const t=d(e);if(!t.keepsChildren)throw new Error("[markdown-explorer] the nesting guard was asked for the children of a node whose children it does not keep");return t.first===null?null:t.first.node},getChildNodes:()=>{throw new Error("[markdown-explorer] the nesting guard keeps no child lists for source locations")},onItemPop:e=>{const t=d(e);t.keepsChildren=!1,t.first=null},insertText:()=>{},insertTextBefore:()=>{},adoptAttributes:(e,t)=>{l(t.length),_(t);const n=d(e);if(n.attributes+=t.length,n.attributes>B)throw new N("too-many-attributes")}};let D;try{D=T.parse(r,{scriptingEnabled:!1,treeAdapter:j})}catch(e){if(e instanceof N)return{status:e.status};throw e}return{status:"within",depth:d(D).height-F,elements:g,nodes:O}},ge=r=>{if(r===null||typeof r!="object")return!1;const{id:c,input:i}=r;if(typeof c!="number"||i===null||typeof i!="object")return!1;const{html:f,iframeHosts:a,dataPath:E,ownUrls:o,maxNodes:g,maxAttributeChars:O,maxSanitizedChars:p}=i;return typeof f=="string"&&Array.isArray(a)&&a.every(m=>typeof m=="string")&&typeof E=="string"&&E!==""&&Y.isExplorerOwnUrls(o)&&[g,O,p].every(m=>Number.isSafeInteger(m)&&m>0)},me=()=>{const r=W.parentPort;if(r===null)throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");const c=H.createJobSanitizer(K);r.on("message",i=>{if(!ge(i))throw new TypeError("[markdown-explorer] the sanitizer worker received a message that is not a job");const{id:f,input:a}=i;let E;try{E=Ae(a.html,Z.MAX_HTML_NESTING_DEPTH,a.maxNodes,a.maxAttributeChars).status==="within"?c(a):{status:"too-large"}}catch(o){E=H.sanitizeJobFailureOf(o)}r.postMessage({id:f,output:E})}),r.postMessage({ready:!0})};me();
|
package/dist/sanitizeWorker.js
CHANGED
|
@@ -1,199 +1,194 @@
|
|
|
1
|
-
import { parentPort as
|
|
1
|
+
import { parentPort as $ } from "node:worker_threads";
|
|
2
2
|
import q from "isomorphic-dompurify";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { d as K } from "./ownUrls-DD0cSCsF.js";
|
|
4
|
+
import { M as Y } from "./sanitizePolicy-DAPnUUVm.js";
|
|
5
|
+
import { defaultTreeAdapter as S, parse as Z, html as ee } from "parse5";
|
|
6
|
+
import { d as I } from "./describeValue-CLlVRO8d.js";
|
|
7
|
+
import { s as te, c as re } from "./sanitizeJob-BYqzjFJC.js";
|
|
8
|
+
const ne = 4096, H = 1024, B = /* @__PURE__ */ Symbol("placement"), F = 2, oe = 3, se = /* @__PURE__ */ new Set(["html", "head", "body"]), A = 0, U = 1, y = 2, G = 3, M = 4, C = 5, b = 6, _ = 7, Q = 8, v = 9, V = 10, T = -1, ae = 0, ie = 1, ce = 2, le = 3, ue = 4, fe = 5, j = 6, Ee = 7, he = (r) => {
|
|
9
|
+
switch (r) {
|
|
7
10
|
case 9:
|
|
8
11
|
case 10:
|
|
9
12
|
case 12:
|
|
10
13
|
case 13:
|
|
11
14
|
case 32:
|
|
12
|
-
return
|
|
15
|
+
return ae;
|
|
13
16
|
case 47:
|
|
14
|
-
return
|
|
17
|
+
return ie;
|
|
15
18
|
case 62:
|
|
16
|
-
return
|
|
19
|
+
return ce;
|
|
17
20
|
case 61:
|
|
18
|
-
return
|
|
21
|
+
return le;
|
|
19
22
|
case 34:
|
|
20
|
-
return
|
|
23
|
+
return ue;
|
|
21
24
|
case 39:
|
|
22
|
-
return
|
|
25
|
+
return fe;
|
|
23
26
|
default:
|
|
24
27
|
return j;
|
|
25
28
|
}
|
|
26
|
-
},
|
|
29
|
+
}, pe = Uint8Array.from({ length: 128 }, (r, c) => he(c)), x = 60, z = 47, de = /[\t\n\f\r />="'<]/g, Te = /["<]/g, me = /['<]/g, u = -1 - y, ge = Int8Array.from(
|
|
27
30
|
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[C, C, C, C,
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
[
|
|
37
|
-
[
|
|
31
|
+
[U, v, T, A, A, A, A],
|
|
32
|
+
[U, v, T, u, u, u, u],
|
|
33
|
+
[G, v, T, M, y, y, y],
|
|
34
|
+
[G, v, T, M, u, u, u],
|
|
35
|
+
[M, _, T, _, C, b, _],
|
|
36
|
+
[C, C, C, C, Q, C, C],
|
|
37
|
+
[b, b, b, b, b, Q, b],
|
|
38
|
+
[U, _, T, _, _, _, _],
|
|
39
|
+
[U, v, T, u, u, u, u],
|
|
40
|
+
[U, v, T, u, u, u, u]
|
|
38
41
|
].flat()
|
|
39
|
-
),
|
|
40
|
-
let
|
|
41
|
-
for (;
|
|
42
|
-
if (
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
|
|
42
|
+
), J = (r) => r >= 65 && r <= 90 || r >= 97 && r <= 122, Ae = (r, c) => {
|
|
43
|
+
let i = new Int32Array(V), f = new Int32Array(V), a = 0, h = 0, o = 0;
|
|
44
|
+
for (; o < r.length; ) {
|
|
45
|
+
if (a === 0) {
|
|
46
|
+
const l = r.indexOf("<", o);
|
|
47
|
+
if (l < 0) return !1;
|
|
48
|
+
o = l + 1, r.charCodeAt(o) === z && (o += 1), J(r.charCodeAt(o)) && (i[A] = 0, a = 1 << A, o += 1);
|
|
46
49
|
continue;
|
|
47
50
|
}
|
|
48
|
-
if ((
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
53
|
-
|
|
51
|
+
if ((a & -230) === 0 && o >= h) {
|
|
52
|
+
const l = a === 1 << C ? Te : a === 1 << b ? me : de;
|
|
53
|
+
l.lastIndex = o;
|
|
54
|
+
const w = l.exec(r);
|
|
55
|
+
if (w === null) return !1;
|
|
56
|
+
o = w.index, r.charCodeAt(o) === x && (h = o + 3);
|
|
54
57
|
}
|
|
55
|
-
const
|
|
58
|
+
const m = r.charCodeAt(o), O = m < 128 ? pe[m] : j;
|
|
56
59
|
let d = 0;
|
|
57
|
-
for (let
|
|
58
|
-
const
|
|
59
|
-
let
|
|
60
|
-
if (
|
|
60
|
+
for (let l = a; l !== 0; l &= l - 1) {
|
|
61
|
+
const w = 31 - Math.clz32(l & -l);
|
|
62
|
+
let p = ge[w * Ee + O], E = i[w];
|
|
63
|
+
if (p < T && (p = -1 - p, E += 1, E > c))
|
|
61
64
|
return !0;
|
|
62
|
-
if (
|
|
63
|
-
const
|
|
64
|
-
((d &
|
|
65
|
+
if (p === T) continue;
|
|
66
|
+
const L = 1 << p;
|
|
67
|
+
((d & L) === 0 || E > f[p]) && (f[p] = E), d |= L;
|
|
65
68
|
}
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
+
J(m) && (r.charCodeAt(o - 1) === x || r.charCodeAt(o - 1) === z && r.charCodeAt(o - 2) === x) && (d & 1 << A) === 0 && (f[A] = 0, d |= 1 << A);
|
|
70
|
+
const g = i;
|
|
71
|
+
i = f, f = g, a = d, o += 1;
|
|
69
72
|
}
|
|
70
73
|
return !1;
|
|
71
74
|
};
|
|
72
|
-
class
|
|
75
|
+
class N extends Error {
|
|
73
76
|
status;
|
|
74
|
-
constructor(
|
|
75
|
-
super(`[markdown-explorer] the nesting guard stopped the parse: ${
|
|
77
|
+
constructor(c) {
|
|
78
|
+
super(`[markdown-explorer] the nesting guard stopped the parse: ${c}`), this.name = "ParseStop", this.status = c;
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
|
-
const
|
|
79
|
-
if (!Number.isSafeInteger(
|
|
80
|
-
if (!Number.isSafeInteger(
|
|
81
|
-
if (!Number.isSafeInteger(
|
|
82
|
-
if (
|
|
83
|
-
const
|
|
84
|
-
let
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
},
|
|
88
|
-
for (const
|
|
89
|
-
if (
|
|
90
|
-
},
|
|
91
|
-
const
|
|
92
|
-
return
|
|
81
|
+
const we = (r, c, i, f) => {
|
|
82
|
+
if (!Number.isSafeInteger(c) || c <= 0) throw new RangeError(`[markdown-explorer] the nesting guard's depth limit must be a positive safe integer; got ${I(c)}`);
|
|
83
|
+
if (!Number.isSafeInteger(i) || i <= 0) throw new RangeError(`[markdown-explorer] the nesting guard's node budget must be a positive safe integer; got ${I(i)}`);
|
|
84
|
+
if (!Number.isSafeInteger(f) || f <= 0) throw new RangeError(`[markdown-explorer] the nesting guard's attribute character budget must be a positive safe integer; got ${I(f)}`);
|
|
85
|
+
if (Ae(r, H)) return { status: "too-many-attributes" };
|
|
86
|
+
const a = c + F, h = r.length + oe;
|
|
87
|
+
let o = null, m = 0, O = 0, d = 0, g = 0;
|
|
88
|
+
const l = (e) => {
|
|
89
|
+
if (O += e, O > i) throw new N("too-many-nodes");
|
|
90
|
+
}, w = (e) => {
|
|
91
|
+
for (const t of e) g += t.name.length + t.value.length;
|
|
92
|
+
if (g > f) throw new N("too-many-attribute-characters");
|
|
93
|
+
}, p = (e, t, n, s) => {
|
|
94
|
+
const P = { node: e, above: null, levels: t, height: 0, keepsChildren: n, attributes: s, first: null, next: null, previous: null }, W = e;
|
|
95
|
+
return W[B] = P, P;
|
|
93
96
|
}, E = (e) => {
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
return
|
|
97
|
-
},
|
|
98
|
-
let
|
|
99
|
-
for (let
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
},
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
},
|
|
106
|
-
if (!
|
|
107
|
-
const
|
|
108
|
-
|
|
97
|
+
const n = e[B];
|
|
98
|
+
if (n === void 0) throw new Error("[markdown-explorer] the nesting guard was handed a node it did not create");
|
|
99
|
+
return n;
|
|
100
|
+
}, L = (e, t) => {
|
|
101
|
+
let n = t;
|
|
102
|
+
for (let s = e; s !== null && n > s.height; s = s.above)
|
|
103
|
+
s.height = n, n += s.levels;
|
|
104
|
+
if (o !== null && o.height > a) throw new N("too-deep");
|
|
105
|
+
}, R = (e) => {
|
|
106
|
+
const t = e.above;
|
|
107
|
+
t?.keepsChildren && (e.previous === null ? t.first = e.next : e.previous.next = e.next, e.next !== null && (e.next.previous = e.previous)), e.above = null, e.next = null, e.previous = null;
|
|
108
|
+
}, k = (e, t) => {
|
|
109
|
+
if (!S.isElementNode(t)) return;
|
|
110
|
+
const n = E(t), s = E(e);
|
|
111
|
+
R(n), n.above = s, s.keepsChildren && (n.next = s.first, s.first !== null && (s.first.previous = n), s.first = n), t.parentNode = e, L(s, n.height + n.levels);
|
|
109
112
|
}, X = {
|
|
110
|
-
...
|
|
113
|
+
...S,
|
|
111
114
|
createDocument: () => {
|
|
112
|
-
const e =
|
|
113
|
-
return
|
|
115
|
+
const e = S.createDocument();
|
|
116
|
+
return o = p(e, 0, !1, 0), e;
|
|
114
117
|
},
|
|
115
118
|
createDocumentFragment: () => {
|
|
116
|
-
const e =
|
|
117
|
-
return
|
|
119
|
+
const e = S.createDocumentFragment();
|
|
120
|
+
return p(e, 0, !1, 0), e;
|
|
118
121
|
},
|
|
119
|
-
createElement: (e,
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
return
|
|
122
|
+
createElement: (e, t, n) => {
|
|
123
|
+
if (m += 1, m > h) throw new N("too-many-elements");
|
|
124
|
+
l(1 + n.length), w(n);
|
|
125
|
+
const s = S.createElement(e, t, n);
|
|
126
|
+
return p(s, 1, !(t === ee.NS.HTML && se.has(e)), n.length), s;
|
|
124
127
|
},
|
|
125
128
|
createCommentNode: (e) => {
|
|
126
|
-
if (d += 1, d >
|
|
127
|
-
return
|
|
129
|
+
if (d += 1, d > ne) throw new N("too-many-comments");
|
|
130
|
+
return l(1), S.createCommentNode(e);
|
|
128
131
|
},
|
|
129
|
-
setTemplateContent: (e,
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
132
|
+
setTemplateContent: (e, t) => {
|
|
133
|
+
S.setTemplateContent(e, t);
|
|
134
|
+
const n = E(t);
|
|
135
|
+
n.above = E(e), L(n.above, n.height);
|
|
133
136
|
},
|
|
134
|
-
appendChild:
|
|
135
|
-
insertBefore: (e,
|
|
137
|
+
appendChild: k,
|
|
138
|
+
insertBefore: (e, t) => k(e, t),
|
|
136
139
|
detachNode: (e) => {
|
|
137
|
-
|
|
140
|
+
S.isElementNode(e) && (R(E(e)), e.parentNode = null);
|
|
138
141
|
},
|
|
139
142
|
getFirstChild: (e) => {
|
|
140
|
-
const
|
|
141
|
-
if (!
|
|
142
|
-
return
|
|
143
|
+
const t = E(e);
|
|
144
|
+
if (!t.keepsChildren) throw new Error("[markdown-explorer] the nesting guard was asked for the children of a node whose children it does not keep");
|
|
145
|
+
return t.first === null ? null : t.first.node;
|
|
143
146
|
},
|
|
144
147
|
getChildNodes: () => {
|
|
145
148
|
throw new Error("[markdown-explorer] the nesting guard keeps no child lists for source locations");
|
|
146
149
|
},
|
|
147
150
|
onItemPop: (e) => {
|
|
148
|
-
const
|
|
149
|
-
|
|
151
|
+
const t = E(e);
|
|
152
|
+
t.keepsChildren = !1, t.first = null;
|
|
150
153
|
},
|
|
151
154
|
insertText: () => {
|
|
152
155
|
},
|
|
153
156
|
insertTextBefore: () => {
|
|
154
157
|
},
|
|
155
|
-
adoptAttributes: (e,
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
158
|
+
adoptAttributes: (e, t) => {
|
|
159
|
+
l(t.length), w(t);
|
|
160
|
+
const n = E(e);
|
|
161
|
+
if (n.attributes += t.length, n.attributes > H) throw new N("too-many-attributes");
|
|
159
162
|
}
|
|
160
163
|
};
|
|
161
|
-
let
|
|
164
|
+
let D;
|
|
162
165
|
try {
|
|
163
|
-
|
|
166
|
+
D = Z(r, { scriptingEnabled: !1, treeAdapter: X });
|
|
164
167
|
} catch (e) {
|
|
165
|
-
if (e instanceof
|
|
168
|
+
if (e instanceof N) return { status: e.status };
|
|
166
169
|
throw e;
|
|
167
170
|
}
|
|
168
|
-
return { status: "within", depth: E(
|
|
169
|
-
},
|
|
170
|
-
if (
|
|
171
|
-
const { id:
|
|
172
|
-
if (typeof
|
|
173
|
-
const { html:
|
|
174
|
-
return typeof
|
|
175
|
-
},
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
if (!
|
|
181
|
-
const { id:
|
|
182
|
-
let
|
|
171
|
+
return { status: "within", depth: E(D).height - F, elements: m, nodes: O };
|
|
172
|
+
}, Se = (r) => {
|
|
173
|
+
if (r === null || typeof r != "object") return !1;
|
|
174
|
+
const { id: c, input: i } = r;
|
|
175
|
+
if (typeof c != "number" || i === null || typeof i != "object") return !1;
|
|
176
|
+
const { html: f, iframeHosts: a, dataPath: h, ownUrls: o, maxNodes: m, maxAttributeChars: O, maxSanitizedChars: d } = i;
|
|
177
|
+
return typeof f == "string" && Array.isArray(a) && a.every((g) => typeof g == "string") && typeof h == "string" && h !== "" && K(o) && [m, O, d].every((g) => Number.isSafeInteger(g) && g > 0);
|
|
178
|
+
}, _e = () => {
|
|
179
|
+
const r = $;
|
|
180
|
+
if (r === null) throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");
|
|
181
|
+
const c = re(q);
|
|
182
|
+
r.on("message", (i) => {
|
|
183
|
+
if (!Se(i)) throw new TypeError("[markdown-explorer] the sanitizer worker received a message that is not a job");
|
|
184
|
+
const { id: f, input: a } = i;
|
|
185
|
+
let h;
|
|
183
186
|
try {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
const n = JSON.stringify([s.iframeHosts, s.dataPath]);
|
|
189
|
-
let h = i.get(n);
|
|
190
|
-
h === void 0 && (h = K(q, s.iframeHosts, s.dataPath, D), i.set(n, h));
|
|
191
|
-
const m = h(s.html);
|
|
192
|
-
p = m.length > s.maxSanitizedChars ? { status: "too-large" } : { status: "sanitized", html: m };
|
|
193
|
-
} catch (n) {
|
|
194
|
-
p = n instanceof Y ? { status: "too-large" } : { status: "error", message: n instanceof Error ? `${n.name}: ${n.message}` : String(n) };
|
|
187
|
+
h = we(a.html, Y, a.maxNodes, a.maxAttributeChars).status === "within" ? c(a) : { status: "too-large" };
|
|
188
|
+
} catch (o) {
|
|
189
|
+
h = te(o);
|
|
195
190
|
}
|
|
196
|
-
|
|
197
|
-
}),
|
|
191
|
+
r.postMessage({ id: f, output: h });
|
|
192
|
+
}), r.postMessage({ ready: !0 });
|
|
198
193
|
};
|
|
199
|
-
|
|
194
|
+
_e();
|