@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.
Files changed (146) hide show
  1. package/CHANGELOG.md +608 -0
  2. package/README.md +121 -41
  3. package/dist/EditSurface-B70iRFkG.cjs +6 -0
  4. package/dist/EditSurface-BCFJRyIM.js +990 -0
  5. package/dist/ExplorerSplit-BNrHrIus.cjs +2 -0
  6. package/dist/ExplorerSplit-Bgccz2nm.js +1589 -0
  7. package/dist/MultiLayout-Bo9LAXiY.cjs +1 -0
  8. package/dist/{MultiLayout-kcZyVnvK.js → MultiLayout-Dy5TIC2t.js} +249 -248
  9. package/dist/{NativeScrollBar-pUbA4Zq3.cjs → NativeScrollBar-Bj-LKej0.cjs} +1 -1
  10. package/dist/{NativeScrollBar-UNed10Na.js → NativeScrollBar-DpZMYhmf.js} +2 -2
  11. package/dist/TreeLayout-DsSKW_Qj.js +103 -0
  12. package/dist/TreeLayout-T8sc_wg7.cjs +1 -0
  13. package/dist/client/MarkdownExplorer.d.cts +14 -1
  14. package/dist/client/MarkdownExplorer.d.ts +14 -1
  15. package/dist/client/edit/lineEndings.d.cts +4 -0
  16. package/dist/client/edit/lineEndings.d.ts +4 -0
  17. package/dist/client/hostContract.d.cts +67 -0
  18. package/dist/client/hostContract.d.ts +67 -0
  19. package/dist/core/config.d.cts +13 -0
  20. package/dist/core/config.d.ts +13 -0
  21. package/dist/core/contracts.d.cts +31 -4
  22. package/dist/core/contracts.d.ts +31 -4
  23. package/dist/core/dataRoute.d.cts +5 -1
  24. package/dist/core/dataRoute.d.ts +5 -1
  25. package/dist/core/documentId.d.cts +6 -0
  26. package/dist/core/documentId.d.ts +6 -0
  27. package/dist/core/draftAnswer.d.cts +23 -0
  28. package/dist/core/draftAnswer.d.ts +23 -0
  29. package/dist/core/labels.d.cts +78 -0
  30. package/dist/core/labels.d.ts +78 -0
  31. package/dist/core/location.d.cts +22 -2
  32. package/dist/core/location.d.ts +22 -2
  33. package/dist/core/ownUrls.d.cts +15 -0
  34. package/dist/core/ownUrls.d.ts +15 -0
  35. package/dist/core/treeSettings.d.cts +3 -2
  36. package/dist/core/treeSettings.d.ts +3 -2
  37. package/dist/core/viewSettings.d.cts +3 -1
  38. package/dist/core/viewSettings.d.ts +3 -1
  39. package/dist/describeValue-CLlVRO8d.js +17 -0
  40. package/dist/describeValue-Ccvhbt36.cjs +1 -0
  41. package/dist/explorerCore-B3RGmMG6.js +1083 -0
  42. package/dist/explorerCore-CUkyKtm8.cjs +1 -0
  43. package/dist/index-D0l_BJqb.js +5980 -0
  44. package/dist/index-lpL7GltU.cjs +18 -0
  45. package/dist/index.cjs +1 -1
  46. package/dist/index.d.cts +8 -4
  47. package/dist/index.d.ts +8 -4
  48. package/dist/index.js +53 -43
  49. package/dist/licenses/@heroicons/react/LICENSE +21 -0
  50. package/dist/licenses/entities/LICENSE +11 -0
  51. package/dist/licenses/parse5/LICENSE +19 -0
  52. package/dist/location-Dh6K-y7w.js +761 -0
  53. package/dist/location-DrOP6t1F.cjs +1 -0
  54. package/dist/lru-DC8GBmkX.js +39 -0
  55. package/dist/lru-SGmUyBQU.cjs +1 -0
  56. package/dist/{merge-C1MWvhCS.js → merge-BwcqBd4c.js} +1 -1
  57. package/dist/{merge-BziXxZkE.cjs → merge-Dckw7r9T.cjs} +1 -1
  58. package/dist/nestingGuardWorker.js +5511 -0
  59. package/dist/ownUrls-BTPGNhBt.cjs +1 -0
  60. package/dist/ownUrls-DD0cSCsF.js +409 -0
  61. package/dist/sanitizeJob-BYqzjFJC.js +21 -0
  62. package/dist/sanitizeJob-CudE1RUP.cjs +1 -0
  63. package/dist/sanitizePolicy-C-ehd0J_.cjs +2 -0
  64. package/dist/sanitizePolicy-DAPnUUVm.js +139 -0
  65. package/dist/sanitizeWorker.cjs +1 -1
  66. package/dist/sanitizeWorker.js +134 -139
  67. package/dist/sanitizerService-B8v4ap9t.js +240 -0
  68. package/dist/sanitizerService-DomN7lwC.cjs +1 -0
  69. package/dist/server/assetResponse.d.cts +60 -0
  70. package/dist/server/assetResponse.d.ts +60 -0
  71. package/dist/server/browser/browserPlatform.d.cts +12 -0
  72. package/dist/server/browser/browserPlatform.d.ts +12 -0
  73. package/dist/server/createMarkdownExplorer.d.cts +0 -10
  74. package/dist/server/createMarkdownExplorer.d.ts +0 -10
  75. package/dist/server/errors.d.cts +1 -1
  76. package/dist/server/errors.d.ts +1 -1
  77. package/dist/server/explorerCore.d.cts +12 -0
  78. package/dist/server/explorerCore.d.ts +12 -0
  79. package/dist/server/fileSystemSource.d.cts +1 -0
  80. package/dist/server/fileSystemSource.d.ts +1 -0
  81. package/dist/server/inProcessFetch.d.cts +5 -0
  82. package/dist/server/inProcessFetch.d.ts +5 -0
  83. package/dist/server/platform.d.cts +18 -0
  84. package/dist/server/platform.d.ts +18 -0
  85. package/dist/server/ports.d.cts +55 -5
  86. package/dist/server/ports.d.ts +55 -5
  87. package/dist/server/sanitizeProtocol.d.cts +3 -0
  88. package/dist/server/sanitizeProtocol.d.ts +3 -0
  89. package/dist/server/sanitizer.d.cts +5 -40
  90. package/dist/server/sanitizer.d.ts +5 -40
  91. package/dist/server/sanitizerOptions.d.cts +24 -0
  92. package/dist/server/sanitizerOptions.d.ts +24 -0
  93. package/dist/server/sanitizerService.d.cts +41 -0
  94. package/dist/server/sanitizerService.d.ts +41 -0
  95. package/dist/server/{workerPool.d.cts → workerJobs.d.cts} +0 -16
  96. package/dist/server/{workerPool.d.ts → workerJobs.d.ts} +0 -16
  97. package/dist/server.cjs +1 -1
  98. package/dist/server.d.cts +3 -1
  99. package/dist/server.d.ts +3 -1
  100. package/dist/server.js +270 -1343
  101. package/dist/serverBrowser.cjs +1 -0
  102. package/dist/serverBrowser.d.cts +1 -0
  103. package/dist/serverBrowser.d.ts +1 -0
  104. package/dist/serverBrowser.js +120 -0
  105. package/dist/serverCore.cjs +1 -0
  106. package/dist/serverCore.d.cts +14 -0
  107. package/dist/serverCore.d.ts +14 -0
  108. package/dist/serverCore.js +46 -0
  109. package/dist/storage-BpYsprog.cjs +1 -0
  110. package/dist/{storage-CmGHg7OA.js → storage-D1uSw-xj.js} +19 -18
  111. package/dist/storage.cjs +1 -1
  112. package/dist/storage.js +1 -1
  113. package/dist/styles/markdown-explorer.css +1 -1
  114. package/dist/{tapScrollCircle-DigcJCsu.cjs → tapScrollCircle-DyLInGck.cjs} +1 -1
  115. package/dist/{tapScrollCircle-D_BpaLwY.js → tapScrollCircle-smKLgRa2.js} +1 -1
  116. package/dist/testing.cjs +1 -0
  117. package/dist/testing.d.cts +11 -0
  118. package/dist/testing.d.ts +11 -0
  119. package/dist/testing.js +82 -0
  120. package/dist/useSplitPersistence-BUa_KMsV.cjs +1 -0
  121. package/dist/useSplitPersistence-pnb21dsr.js +44 -0
  122. package/docs/behavior/dom-hooks.md +5 -1
  123. package/docs/behavior/hosting.md +123 -0
  124. package/docs/behavior/layout.md +5 -3
  125. package/docs/behavior/localization.md +25 -8
  126. package/docs/behavior/security.md +55 -15
  127. package/docs/behavior/url-contract.md +30 -3
  128. package/package.json +48 -10
  129. package/dist/EditSurface-CF82jZQg.cjs +0 -6
  130. package/dist/EditSurface-CqHk2R3k.js +0 -982
  131. package/dist/ExplorerSplit-D325YGEf.cjs +0 -1
  132. package/dist/ExplorerSplit-DGH9bckm.js +0 -1500
  133. package/dist/MultiLayout-CzR7yJ0m.cjs +0 -1
  134. package/dist/TreeLayout-BnIU87HX.js +0 -96
  135. package/dist/TreeLayout-DtvIpuOe.cjs +0 -1
  136. package/dist/dataRoute-D6KiSHIc.js +0 -298
  137. package/dist/dataRoute-DwYtgyt6.cjs +0 -1
  138. package/dist/index-BDCbvHDs.cjs +0 -15
  139. package/dist/index-DR31S_-4.js +0 -5012
  140. package/dist/location-C44b9H1S.js +0 -676
  141. package/dist/location-hGLhCCg4.cjs +0 -1
  142. package/dist/sanitizePolicy-CwvyPpp5.js +0 -98
  143. package/dist/sanitizePolicy-T5T-3vV5.cjs +0 -1
  144. package/dist/storage-DM0EvkVf.cjs +0 -1
  145. package/dist/useSplitPersistence-DCeYbJMx.js +0 -38
  146. 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
+ };
@@ -1 +1 @@
1
- "use strict";const J=require("node:worker_threads"),W=require("isomorphic-dompurify"),M=require("./sanitizePolicy-T5T-3vV5.cjs"),A=require("parse5"),K=4096,P=1024,B=Symbol("placement"),G=2,Y=3,Z=new Set(["html","head","body"]),S=0,v=1,I=2,z=3,U=4,C=5,N=6,w=7,F=8,b=9,Q=10,m=-1,ee=0,te=1,re=2,ne=3,se=4,oe=5,q=6,ae=7,ie=t=>{switch(t){case 9:case 10:case 12:case 13:case 32:return ee;case 47:return te;case 62:return re;case 61:return ne;case 34:return se;case 39:return oe;default:return q}},ce=Uint8Array.from({length:128},(t,i)=>ie(i)),x=60,V=47,le=/[\t\n\f\r />="'<]/g,ue=/["<]/g,fe=/['<]/g,f=-1-I,de=Int8Array.from([[v,b,m,S,S,S,S],[v,b,m,f,f,f,f],[z,b,m,U,I,I,I],[z,b,m,U,f,f,f],[U,w,m,w,C,N,w],[C,C,C,C,F,C,C],[N,N,N,N,N,F,N],[v,w,m,w,w,w,w],[v,b,m,f,f,f,f],[v,b,m,f,f,f,f]].flat()),$=t=>t>=65&&t<=90||t>=97&&t<=122,Ee=(t,i)=>{let c=new Int32Array(Q),l=new Int32Array(Q),o=0,p=0,n=0;for(;n<t.length;){if(o===0){const u=t.indexOf("<",n);if(u<0)return!1;n=u+1,t.charCodeAt(n)===V&&(n+=1),$(t.charCodeAt(n))&&(c[S]=0,o=1<<S,n+=1);continue}if((o&-230)===0&&n>=p){const u=o===1<<C?ue:o===1<<N?fe:le;u.lastIndex=n;const _=u.exec(t);if(_===null)return!1;n=_.index,t.charCodeAt(n)===x&&(p=n+3)}const d=t.charCodeAt(n),g=d<128?ce[d]:q;let h=0;for(let u=o;u!==0;u&=u-1){const _=31-Math.clz32(u&-u);let T=de[_*ae+g],E=c[_];if(T<m&&(T=-1-T,E+=1,E>i))return!0;if(T===m)continue;const L=1<<T;((h&L)===0||E>l[T])&&(l[T]=E),h|=L}$(d)&&(t.charCodeAt(n-1)===x||t.charCodeAt(n-1)===V&&t.charCodeAt(n-2)===x)&&(h&1<<S)===0&&(l[S]=0,h|=1<<S);const y=c;c=l,l=y,o=h,n+=1}return!1};class O extends Error{status;constructor(i){super(`[markdown-explorer] the nesting guard stopped the parse: ${i}`),this.name="ParseStop",this.status=i}}const he=(t,i,c,l)=>{if(!Number.isSafeInteger(i)||i<=0)throw new RangeError(`[markdown-explorer] the nesting guard's depth limit must be a positive safe integer; got ${String(i)}`);if(!Number.isSafeInteger(c)||c<=0)throw new RangeError(`[markdown-explorer] the nesting guard's node budget must be a positive safe integer; got ${String(c)}`);if(!Number.isSafeInteger(l)||l<=0)throw new RangeError(`[markdown-explorer] the nesting guard's attribute character budget must be a positive safe integer; got ${String(l)}`);if(Ee(t,P))return{status:"too-many-attributes"};const o=i+G,p=t.length+Y;let n=null,d=0,g=0,h=0,y=0;const u=e=>{if(g+=e,g>c)throw new O("too-many-nodes")},_=e=>{for(const r of e)y+=r.name.length+r.value.length;if(y>l)throw new O("too-many-attribute-characters")},T=(e,r,s,a)=>{const D={node:e,above:null,levels:r,height:0,keepsChildren:s,attributes:a,first:null,next:null,previous:null},j=e;return j[B]=D,D},E=e=>{const s=e[B];if(s===void 0)throw new Error("[markdown-explorer] the nesting guard was handed a node it did not create");return s},L=(e,r)=>{let s=r;for(let a=e;a!==null&&s>a.height;a=a.above)a.height=s,s+=a.levels;if(n!==null&&n.height>o)throw new O("too-deep")},k=e=>{const r=e.above;r?.keepsChildren&&(e.previous===null?r.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},R=(e,r)=>{if(!A.defaultTreeAdapter.isElementNode(r))return;const s=E(r),a=E(e);k(s),s.above=a,a.keepsChildren&&(s.next=a.first,a.first!==null&&(a.first.previous=s),a.first=s),r.parentNode=e,L(a,s.height+s.levels)},X={...A.defaultTreeAdapter,createDocument:()=>{const e=A.defaultTreeAdapter.createDocument();return n=T(e,0,!1,0),e},createDocumentFragment:()=>{const e=A.defaultTreeAdapter.createDocumentFragment();return T(e,0,!1,0),e},createElement:(e,r,s)=>{if(d+=1,d>p)throw new O("too-many-elements");u(1+s.length),_(s);const a=A.defaultTreeAdapter.createElement(e,r,s);return T(a,1,!(r===A.html.NS.HTML&&Z.has(e)),s.length),a},createCommentNode:e=>{if(h+=1,h>K)throw new O("too-many-comments");return u(1),A.defaultTreeAdapter.createCommentNode(e)},setTemplateContent:(e,r)=>{A.defaultTreeAdapter.setTemplateContent(e,r);const s=E(r);s.above=E(e),L(s.above,s.height)},appendChild:R,insertBefore:(e,r)=>R(e,r),detachNode:e=>{A.defaultTreeAdapter.isElementNode(e)&&(k(E(e)),e.parentNode=null)},getFirstChild:e=>{const r=E(e);if(!r.keepsChildren)throw new Error("[markdown-explorer] the nesting guard was asked for the children of a node whose children it does not keep");return r.first===null?null:r.first.node},getChildNodes:()=>{throw new Error("[markdown-explorer] the nesting guard keeps no child lists for source locations")},onItemPop:e=>{const r=E(e);r.keepsChildren=!1,r.first=null},insertText:()=>{},insertTextBefore:()=>{},adoptAttributes:(e,r)=>{u(r.length),_(r);const s=E(e);if(s.attributes+=r.length,s.attributes>P)throw new O("too-many-attributes")}};let H;try{H=A.parse(t,{scriptingEnabled:!1,treeAdapter:X})}catch(e){if(e instanceof O)return{status:e.status};throw e}return{status:"within",depth:E(H).height-G,elements:d,nodes:g}},pe=t=>{if(t===null||typeof t!="object")return!1;const{id:i,input:c}=t;if(typeof i!="number"||c===null||typeof c!="object")return!1;const{html:l,iframeHosts:o,dataPath:p,maxNodes:n,maxAttributeChars:d,maxSanitizedChars:g}=c;return typeof l=="string"&&Array.isArray(o)&&o.every(h=>typeof h=="string")&&typeof p=="string"&&p!==""&&[n,d,g].every(h=>Number.isSafeInteger(h)&&h>0)},Te=()=>{const t=J.parentPort;if(t===null)throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");const i=new Map;t.on("message",c=>{if(!pe(c))throw new TypeError("[markdown-explorer] the sanitizer worker received a message that is not a job");const{id:l,input:o}=c;let p;try{if(he(o.html,M.MAX_HTML_NESTING_DEPTH,o.maxNodes,o.maxAttributeChars).status!=="within"){t.postMessage({id:l,output:{status:"too-large"}});return}const n=JSON.stringify([o.iframeHosts,o.dataPath]);let d=i.get(n);d===void 0&&(d=M.createHtmlSanitizer(W,o.iframeHosts,o.dataPath,M.MAX_HTML_NESTING_DEPTH),i.set(n,d));const g=d(o.html);p=g.length>o.maxSanitizedChars?{status:"too-large"}:{status:"sanitized",html:g}}catch(n){p=n instanceof M.HtmlNestingLimitError?{status:"too-large"}:{status:"error",message:n instanceof Error?`${n.name}: ${n.message}`:String(n)}}t.postMessage({id:l,output:p})}),t.postMessage({ready:!0})};Te();
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();
@@ -1,199 +1,194 @@
1
- import { parentPort as W } from "node:worker_threads";
1
+ import { parentPort as $ } from "node:worker_threads";
2
2
  import q from "isomorphic-dompurify";
3
- import { M as D, c as K, H as Y } from "./sanitizePolicy-CwvyPpp5.js";
4
- import { defaultTreeAdapter as w, parse as Z, html as ee } from "parse5";
5
- const te = 4096, P = 1024, B = /* @__PURE__ */ Symbol("placement"), G = 2, re = 3, ne = /* @__PURE__ */ new Set(["html", "head", "body"]), A = 0, L = 1, M = 2, z = 3, U = 4, C = 5, N = 6, _ = 7, F = 8, b = 9, Q = 10, T = -1, oe = 0, se = 1, ae = 2, ie = 3, ce = 4, le = 5, j = 6, ue = 7, fe = (t) => {
6
- switch (t) {
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 oe;
15
+ return ae;
13
16
  case 47:
14
- return se;
17
+ return ie;
15
18
  case 62:
16
- return ae;
19
+ return ce;
17
20
  case 61:
18
- return ie;
21
+ return le;
19
22
  case 34:
20
- return ce;
23
+ return ue;
21
24
  case 39:
22
- return le;
25
+ return fe;
23
26
  default:
24
27
  return j;
25
28
  }
26
- }, he = Uint8Array.from({ length: 128 }, (t, i) => fe(i)), I = 60, V = 47, Ee = /[\t\n\f\r />="'<]/g, de = /["<]/g, pe = /['<]/g, f = -1 - M, ge = Int8Array.from(
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
- [L, b, T, A, A, A, A],
29
- [L, b, T, f, f, f, f],
30
- [z, b, T, U, M, M, M],
31
- [z, b, T, U, f, f, f],
32
- [U, _, T, _, C, N, _],
33
- [C, C, C, C, F, C, C],
34
- [N, N, N, N, N, F, N],
35
- [L, _, T, _, _, _, _],
36
- [L, b, T, f, f, f, f],
37
- [L, b, T, f, f, f, f]
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
- ), $ = (t) => t >= 65 && t <= 90 || t >= 97 && t <= 122, me = (t, i) => {
40
- let c = new Int32Array(Q), l = new Int32Array(Q), s = 0, p = 0, n = 0;
41
- for (; n < t.length; ) {
42
- if (s === 0) {
43
- const u = t.indexOf("<", n);
44
- if (u < 0) return !1;
45
- n = u + 1, t.charCodeAt(n) === V && (n += 1), $(t.charCodeAt(n)) && (c[A] = 0, s = 1 << A, n += 1);
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 ((s & -230) === 0 && n >= p) {
49
- const u = s === 1 << C ? de : s === 1 << N ? pe : Ee;
50
- u.lastIndex = n;
51
- const S = u.exec(t);
52
- if (S === null) return !1;
53
- n = S.index, t.charCodeAt(n) === I && (p = n + 3);
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 h = t.charCodeAt(n), m = h < 128 ? he[h] : j;
58
+ const m = r.charCodeAt(o), O = m < 128 ? pe[m] : j;
56
59
  let d = 0;
57
- for (let u = s; u !== 0; u &= u - 1) {
58
- const S = 31 - Math.clz32(u & -u);
59
- let g = ge[S * ue + m], E = c[S];
60
- if (g < T && (g = -1 - g, E += 1, E > i))
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 (g === T) continue;
63
- const v = 1 << g;
64
- ((d & v) === 0 || E > l[g]) && (l[g] = E), d |= v;
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
- $(h) && (t.charCodeAt(n - 1) === I || t.charCodeAt(n - 1) === V && t.charCodeAt(n - 2) === I) && (d & 1 << A) === 0 && (l[A] = 0, d |= 1 << A);
67
- const y = c;
68
- c = l, l = y, s = d, n += 1;
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 O extends Error {
75
+ class N extends Error {
73
76
  status;
74
- constructor(i) {
75
- super(`[markdown-explorer] the nesting guard stopped the parse: ${i}`), this.name = "ParseStop", this.status = i;
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 Te = (t, i, c, l) => {
79
- if (!Number.isSafeInteger(i) || i <= 0) throw new RangeError(`[markdown-explorer] the nesting guard's depth limit must be a positive safe integer; got ${String(i)}`);
80
- if (!Number.isSafeInteger(c) || c <= 0) throw new RangeError(`[markdown-explorer] the nesting guard's node budget must be a positive safe integer; got ${String(c)}`);
81
- if (!Number.isSafeInteger(l) || l <= 0) throw new RangeError(`[markdown-explorer] the nesting guard's attribute character budget must be a positive safe integer; got ${String(l)}`);
82
- if (me(t, P)) return { status: "too-many-attributes" };
83
- const s = i + G, p = t.length + re;
84
- let n = null, h = 0, m = 0, d = 0, y = 0;
85
- const u = (e) => {
86
- if (m += e, m > c) throw new O("too-many-nodes");
87
- }, S = (e) => {
88
- for (const r of e) y += r.name.length + r.value.length;
89
- if (y > l) throw new O("too-many-attribute-characters");
90
- }, g = (e, r, o, a) => {
91
- const H = { node: e, above: null, levels: r, height: 0, keepsChildren: o, attributes: a, first: null, next: null, previous: null }, J = e;
92
- return J[B] = H, H;
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 o = e[B];
95
- if (o === void 0) throw new Error("[markdown-explorer] the nesting guard was handed a node it did not create");
96
- return o;
97
- }, v = (e, r) => {
98
- let o = r;
99
- for (let a = e; a !== null && o > a.height; a = a.above)
100
- a.height = o, o += a.levels;
101
- if (n !== null && n.height > s) throw new O("too-deep");
102
- }, x = (e) => {
103
- const r = e.above;
104
- r?.keepsChildren && (e.previous === null ? r.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;
105
- }, R = (e, r) => {
106
- if (!w.isElementNode(r)) return;
107
- const o = E(r), a = E(e);
108
- x(o), o.above = a, a.keepsChildren && (o.next = a.first, a.first !== null && (a.first.previous = o), a.first = o), r.parentNode = e, v(a, o.height + o.levels);
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
- ...w,
113
+ ...S,
111
114
  createDocument: () => {
112
- const e = w.createDocument();
113
- return n = g(e, 0, !1, 0), e;
115
+ const e = S.createDocument();
116
+ return o = p(e, 0, !1, 0), e;
114
117
  },
115
118
  createDocumentFragment: () => {
116
- const e = w.createDocumentFragment();
117
- return g(e, 0, !1, 0), e;
119
+ const e = S.createDocumentFragment();
120
+ return p(e, 0, !1, 0), e;
118
121
  },
119
- createElement: (e, r, o) => {
120
- if (h += 1, h > p) throw new O("too-many-elements");
121
- u(1 + o.length), S(o);
122
- const a = w.createElement(e, r, o);
123
- return g(a, 1, !(r === ee.NS.HTML && ne.has(e)), o.length), a;
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 > te) throw new O("too-many-comments");
127
- return u(1), w.createCommentNode(e);
129
+ if (d += 1, d > ne) throw new N("too-many-comments");
130
+ return l(1), S.createCommentNode(e);
128
131
  },
129
- setTemplateContent: (e, r) => {
130
- w.setTemplateContent(e, r);
131
- const o = E(r);
132
- o.above = E(e), v(o.above, o.height);
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: R,
135
- insertBefore: (e, r) => R(e, r),
137
+ appendChild: k,
138
+ insertBefore: (e, t) => k(e, t),
136
139
  detachNode: (e) => {
137
- w.isElementNode(e) && (x(E(e)), e.parentNode = null);
140
+ S.isElementNode(e) && (R(E(e)), e.parentNode = null);
138
141
  },
139
142
  getFirstChild: (e) => {
140
- const r = E(e);
141
- if (!r.keepsChildren) throw new Error("[markdown-explorer] the nesting guard was asked for the children of a node whose children it does not keep");
142
- return r.first === null ? null : r.first.node;
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 r = E(e);
149
- r.keepsChildren = !1, r.first = null;
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, r) => {
156
- u(r.length), S(r);
157
- const o = E(e);
158
- if (o.attributes += r.length, o.attributes > P) throw new O("too-many-attributes");
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 k;
164
+ let D;
162
165
  try {
163
- k = Z(t, { scriptingEnabled: !1, treeAdapter: X });
166
+ D = Z(r, { scriptingEnabled: !1, treeAdapter: X });
164
167
  } catch (e) {
165
- if (e instanceof O) return { status: e.status };
168
+ if (e instanceof N) return { status: e.status };
166
169
  throw e;
167
170
  }
168
- return { status: "within", depth: E(k).height - G, elements: h, nodes: m };
169
- }, Ae = (t) => {
170
- if (t === null || typeof t != "object") return !1;
171
- const { id: i, input: c } = t;
172
- if (typeof i != "number" || c === null || typeof c != "object") return !1;
173
- const { html: l, iframeHosts: s, dataPath: p, maxNodes: n, maxAttributeChars: h, maxSanitizedChars: m } = c;
174
- return typeof l == "string" && Array.isArray(s) && s.every((d) => typeof d == "string") && typeof p == "string" && p !== "" && [n, h, m].every((d) => Number.isSafeInteger(d) && d > 0);
175
- }, Se = () => {
176
- const t = W;
177
- if (t === null) throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");
178
- const i = /* @__PURE__ */ new Map();
179
- t.on("message", (c) => {
180
- if (!Ae(c)) throw new TypeError("[markdown-explorer] the sanitizer worker received a message that is not a job");
181
- const { id: l, input: s } = c;
182
- let p;
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
- if (Te(s.html, D, s.maxNodes, s.maxAttributeChars).status !== "within") {
185
- t.postMessage({ id: l, output: { status: "too-large" } });
186
- return;
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
- t.postMessage({ id: l, output: p });
197
- }), t.postMessage({ ready: !0 });
191
+ r.postMessage({ id: f, output: h });
192
+ }), r.postMessage({ ready: !0 });
198
193
  };
199
- Se();
194
+ _e();