@aiquants/markdown-explorer 0.11.0 → 0.12.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 (40) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/README.md +64 -5
  3. package/dist/EditSurface-BTAhzvHi.js +509 -0
  4. package/dist/EditSurface-Dfj6Sxxb.cjs +2 -0
  5. package/dist/{ExplorerSplit-51frK8xf.cjs → ExplorerSplit-DekOjAUZ.cjs} +1 -1
  6. package/dist/{ExplorerSplit-DwlWWfRv.js → ExplorerSplit-MPHjw3nW.js} +52 -52
  7. package/dist/{MultiLayout-CeR_l6Rb.js → MultiLayout-DtSW4rEQ.js} +4 -4
  8. package/dist/{MultiLayout-B4PtS45V.cjs → MultiLayout-HMzVDYWq.cjs} +1 -1
  9. package/dist/{NativeScrollBar-Dp4YWBp7.cjs → NativeScrollBar-B0AkVF3E.cjs} +1 -1
  10. package/dist/{NativeScrollBar-CVWeTlHC.js → NativeScrollBar-CNQr7JY1.js} +1 -1
  11. package/dist/{TreeLayout-min5AOhr.js → TreeLayout-CJO9tOPq.js} +3 -3
  12. package/dist/{TreeLayout-D-NyhuVM.cjs → TreeLayout-_XQR-9tV.cjs} +1 -1
  13. package/dist/client/MarkdownExplorer.d.cts +3 -2
  14. package/dist/client/MarkdownExplorer.d.ts +3 -2
  15. package/dist/core/contracts.d.cts +16 -0
  16. package/dist/core/contracts.d.ts +16 -0
  17. package/dist/dataRoute-CH3yOKR0.cjs +1 -0
  18. package/dist/{dataRoute-CU9CKP44.js → dataRoute-Pm_0ue_4.js} +93 -92
  19. package/dist/{index-DJ_FUtYM.cjs → index-DpIVKG8Y.cjs} +8 -8
  20. package/dist/{index-BPj19kIo.js → index-o6OpR4ND.js} +963 -907
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.d.cts +1 -1
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +9 -9
  25. package/dist/{location-LNl0QOXI.cjs → location-BUNWJ4eB.cjs} +1 -1
  26. package/dist/{location-BT23fKeh.js → location-DWd6SQhN.js} +1 -1
  27. package/dist/{merge-AnqxGn__.cjs → merge-Bs7o3GyP.cjs} +1 -1
  28. package/dist/{merge-hyUGPGbJ.js → merge-DDJaJmMU.js} +1 -1
  29. package/dist/sanitizePolicy-BfUlXI5E.cjs +1 -0
  30. package/dist/sanitizePolicy-djLC3fRN.js +96 -0
  31. package/dist/sanitizeWorker.cjs +1 -1
  32. package/dist/sanitizeWorker.js +143 -226
  33. package/dist/server.cjs +1 -1
  34. package/dist/server.js +3 -3
  35. package/docs/behavior/dom-hooks.md +1 -1
  36. package/docs/behavior/security.md +2 -0
  37. package/package.json +3 -3
  38. package/dist/EditSurface-BK_Pz_LF.js +0 -371
  39. package/dist/EditSurface-CfbYYXrc.cjs +0 -2
  40. package/dist/dataRoute-CIFFX5bd.cjs +0 -1
@@ -1,282 +1,199 @@
1
- import { parentPort as te } from "node:worker_threads";
2
- import { defaultTreeAdapter as N, parse as re, html as ne } from "parse5";
3
- import { allowedFrameUrlOf as oe, reduceFrameFeatures as se, EMBED_FRAME_REFERRER_POLICIES as ae, EMBED_LINK_ATTRIBUTE as H, placeholderLinkOf as ie } from "@aiquants/markdown/embeds";
4
- import { SOURCE_LINES_ATTRIBUTE as P, parseSourceLines as le } from "@aiquants/markdown/source-lines";
5
- import S from "isomorphic-dompurify";
6
- import { i as ce, e as ue } from "./dataRoute-CU9CKP44.js";
7
- const G = 512, fe = 4096, j = 1024, V = /* @__PURE__ */ Symbol("placement"), W = 2, de = 3, pe = /* @__PURE__ */ new Set(["html", "head", "body"]), w = 0, D = 1, M = 2, Q = 3, z = 4, O = 5, k = 6, b = 7, $ = 8, I = 9, X = 10, _ = -1, Ee = 0, me = 1, Te = 2, he = 3, Ae = 4, ge = 5, Y = 6, Se = 7, _e = (r) => {
8
- switch (r) {
1
+ import { parentPort as W } from "node:worker_threads";
2
+ import q from "isomorphic-dompurify";
3
+ import { M as D, c as K, H as Y } from "./sanitizePolicy-djLC3fRN.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) {
9
7
  case 9:
10
8
  case 10:
11
9
  case 12:
12
10
  case 13:
13
11
  case 32:
14
- return Ee;
12
+ return oe;
15
13
  case 47:
16
- return me;
14
+ return se;
17
15
  case 62:
18
- return Te;
16
+ return ae;
19
17
  case 61:
20
- return he;
18
+ return ie;
21
19
  case 34:
22
- return Ae;
20
+ return ce;
23
21
  case 39:
24
- return ge;
22
+ return le;
25
23
  default:
26
- return Y;
24
+ return j;
27
25
  }
28
- }, we = Uint8Array.from({ length: 128 }, (r, i) => _e(i)), B = 60, J = 47, Ne = /[\t\n\f\r />="'<]/g, be = /["<]/g, Oe = /['<]/g, A = -1 - M, ke = Int8Array.from(
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
27
  [
30
- [D, I, _, w, w, w, w],
31
- [D, I, _, A, A, A, A],
32
- [Q, I, _, z, M, M, M],
33
- [Q, I, _, z, A, A, A],
34
- [z, b, _, b, O, k, b],
35
- [O, O, O, O, $, O, O],
36
- [k, k, k, k, k, $, k],
37
- [D, b, _, b, b, b, b],
38
- [D, I, _, A, A, A, A],
39
- [D, I, _, A, A, A, A]
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]
40
38
  ].flat()
41
- ), K = (r) => r >= 65 && r <= 90 || r >= 97 && r <= 122, Le = (r, i) => {
42
- let u = new Int32Array(X), f = new Int32Array(X), l = 0, T = 0, n = 0;
43
- for (; n < r.length; ) {
44
- if (l === 0) {
45
- const p = r.indexOf("<", n);
46
- if (p < 0) return !1;
47
- n = p + 1, r.charCodeAt(n) === J && (n += 1), K(r.charCodeAt(n)) && (u[w] = 0, l = 1 << w, n += 1);
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);
48
46
  continue;
49
47
  }
50
- if ((l & -230) === 0 && n >= T) {
51
- const p = l === 1 << O ? be : l === 1 << k ? Oe : Ne;
52
- p.lastIndex = n;
53
- const a = p.exec(r);
54
- if (a === null) return !1;
55
- n = a.index, r.charCodeAt(n) === B && (T = n + 3);
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);
56
54
  }
57
- const m = r.charCodeAt(n), g = m < 128 ? we[m] : Y;
58
- let h = 0;
59
- for (let p = l; p !== 0; p &= p - 1) {
60
- const a = 31 - Math.clz32(p & -p);
61
- let e = ke[a * Se + g], o = u[a];
62
- if (e < _ && (e = -1 - e, o += 1, o > i))
55
+ const h = t.charCodeAt(n), m = h < 128 ? he[h] : j;
56
+ 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))
63
61
  return !0;
64
- if (e === _) continue;
65
- const E = 1 << e;
66
- ((h & E) === 0 || o > f[e]) && (f[e] = o), h |= E;
62
+ if (g === T) continue;
63
+ const v = 1 << g;
64
+ ((d & v) === 0 || E > l[g]) && (l[g] = E), d |= v;
67
65
  }
68
- K(m) && (r.charCodeAt(n - 1) === B || r.charCodeAt(n - 1) === J && r.charCodeAt(n - 2) === B) && (h & 1 << w) === 0 && (f[w] = 0, h |= 1 << w);
69
- const R = u;
70
- u = f, f = R, l = h, n += 1;
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;
71
69
  }
72
70
  return !1;
73
71
  };
74
- class L extends Error {
72
+ class O extends Error {
75
73
  status;
76
74
  constructor(i) {
77
75
  super(`[markdown-explorer] the nesting guard stopped the parse: ${i}`), this.name = "ParseStop", this.status = i;
78
76
  }
79
77
  }
80
- const Re = (r, i, u, f) => {
78
+ const Te = (t, i, c, l) => {
81
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)}`);
82
- if (!Number.isSafeInteger(u) || u <= 0) throw new RangeError(`[markdown-explorer] the nesting guard's node budget must be a positive safe integer; got ${String(u)}`);
83
- 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 ${String(f)}`);
84
- if (Le(r, j)) return { status: "too-many-attributes" };
85
- const l = i + W, T = r.length + de;
86
- let n = null, m = 0, g = 0, h = 0, R = 0;
87
- const p = (t) => {
88
- if (g += t, g > u) throw new L("too-many-nodes");
89
- }, a = (t) => {
90
- for (const s of t) R += s.name.length + s.value.length;
91
- if (R > f) throw new L("too-many-attribute-characters");
92
- }, e = (t, s, c, d) => {
93
- const F = { node: t, above: null, levels: s, height: 0, keepsChildren: c, attributes: d, first: null, next: null, previous: null }, ee = t;
94
- return ee[V] = F, F;
95
- }, o = (t) => {
96
- const c = t[V];
97
- if (c === void 0) throw new Error("[markdown-explorer] the nesting guard was handed a node it did not create");
98
- return c;
99
- }, E = (t, s) => {
100
- let c = s;
101
- for (let d = t; d !== null && c > d.height; d = d.above)
102
- d.height = c, c += d.levels;
103
- if (n !== null && n.height > l) throw new L("too-deep");
104
- }, y = (t) => {
105
- const s = t.above;
106
- s?.keepsChildren && (t.previous === null ? s.first = t.next : t.previous.next = t.next, t.next !== null && (t.next.previous = t.previous)), t.above = null, t.next = null, t.previous = null;
107
- }, C = (t, s) => {
108
- if (!N.isElementNode(s)) return;
109
- const c = o(s), d = o(t);
110
- y(c), c.above = d, d.keepsChildren && (c.next = d.first, d.first !== null && (d.first.previous = c), d.first = c), s.parentNode = t, E(d, c.height + c.levels);
111
- }, x = {
112
- ...N,
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;
93
+ }, 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);
109
+ }, X = {
110
+ ...w,
113
111
  createDocument: () => {
114
- const t = N.createDocument();
115
- return n = e(t, 0, !1, 0), t;
112
+ const e = w.createDocument();
113
+ return n = g(e, 0, !1, 0), e;
116
114
  },
117
115
  createDocumentFragment: () => {
118
- const t = N.createDocumentFragment();
119
- return e(t, 0, !1, 0), t;
116
+ const e = w.createDocumentFragment();
117
+ return g(e, 0, !1, 0), e;
120
118
  },
121
- createElement: (t, s, c) => {
122
- if (m += 1, m > T) throw new L("too-many-elements");
123
- p(1 + c.length), a(c);
124
- const d = N.createElement(t, s, c);
125
- return e(d, 1, !(s === ne.NS.HTML && pe.has(t)), c.length), d;
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;
126
124
  },
127
- createCommentNode: (t) => {
128
- if (h += 1, h > fe) throw new L("too-many-comments");
129
- return p(1), N.createCommentNode(t);
125
+ createCommentNode: (e) => {
126
+ if (d += 1, d > te) throw new O("too-many-comments");
127
+ return u(1), w.createCommentNode(e);
130
128
  },
131
- setTemplateContent: (t, s) => {
132
- N.setTemplateContent(t, s);
133
- const c = o(s);
134
- c.above = o(t), E(c.above, c.height);
129
+ setTemplateContent: (e, r) => {
130
+ w.setTemplateContent(e, r);
131
+ const o = E(r);
132
+ o.above = E(e), v(o.above, o.height);
135
133
  },
136
- appendChild: C,
137
- insertBefore: (t, s) => C(t, s),
138
- detachNode: (t) => {
139
- N.isElementNode(t) && (y(o(t)), t.parentNode = null);
134
+ appendChild: R,
135
+ insertBefore: (e, r) => R(e, r),
136
+ detachNode: (e) => {
137
+ w.isElementNode(e) && (x(E(e)), e.parentNode = null);
140
138
  },
141
- getFirstChild: (t) => {
142
- const s = o(t);
143
- if (!s.keepsChildren) throw new Error("[markdown-explorer] the nesting guard was asked for the children of a node whose children it does not keep");
144
- return s.first === null ? null : s.first.node;
139
+ 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;
145
143
  },
146
144
  getChildNodes: () => {
147
145
  throw new Error("[markdown-explorer] the nesting guard keeps no child lists for source locations");
148
146
  },
149
- onItemPop: (t) => {
150
- const s = o(t);
151
- s.keepsChildren = !1, s.first = null;
147
+ onItemPop: (e) => {
148
+ const r = E(e);
149
+ r.keepsChildren = !1, r.first = null;
152
150
  },
153
151
  insertText: () => {
154
152
  },
155
153
  insertTextBefore: () => {
156
154
  },
157
- adoptAttributes: (t, s) => {
158
- p(s.length), a(s);
159
- const c = o(t);
160
- if (c.attributes += s.length, c.attributes > j) throw new L("too-many-attributes");
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");
161
159
  }
162
160
  };
163
- let v;
161
+ let k;
164
162
  try {
165
- v = re(r, { scriptingEnabled: !1, treeAdapter: x });
166
- } catch (t) {
167
- if (t instanceof L) return { status: t.status };
168
- throw t;
163
+ k = Z(t, { scriptingEnabled: !1, treeAdapter: X });
164
+ } catch (e) {
165
+ if (e instanceof O) return { status: e.status };
166
+ throw e;
169
167
  }
170
- return { status: "within", depth: o(v).height - W, elements: m, nodes: g };
171
- };
172
- class q extends RangeError {
173
- constructor(i) {
174
- super(`[markdown-explorer] the HTML nests deeper than ${String(i)} levels`), this.name = "HtmlNestingLimitError";
175
- }
176
- }
177
- const Ce = ["script", "style", "noscript", "template", "form", "button", "textarea", "select", "option", "object", "embed", "base", "meta", "link", "frame", "frameset"], Ie = ["srcdoc", "formaction"], ye = /^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu, De = /* @__PURE__ */ new Set(["left", "right", "center", "justify", "start", "end"]), Me = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]), U = 1, Ue = 3, xe = 7, He = 8, Z = Object.freeze({
178
- a: Object.freeze(["target", "data-link-kind", "data-doc-path", "data-doc-exists", "data-footnote-ref", "data-footnote-backref"]),
179
- area: Object.freeze(["target"]),
180
- img: Object.freeze(["data-asset-src", "data-asset-exists"]),
181
- section: Object.freeze(["data-footnotes"]),
182
- iframe: Object.freeze(["allow", "allowfullscreen", "frameborder", "referrerpolicy"])
183
- }), ze = [.../* @__PURE__ */ new Set([...Object.values(Z).flatMap((r) => r.filter((i) => i.startsWith("data-"))), P])], Be = /* @__PURE__ */ new Set(["src", "href", "xlink:href"]), Pe = /^data:/iu, ve = Object.freeze({
184
- FORBID_TAGS: Ce,
185
- FORBID_ATTR: Ie,
186
- ADD_TAGS: ["iframe"],
187
- ADD_ATTR: (r, i) => r === P || Z[i]?.includes(r) === !0,
188
- ADD_URI_SAFE_ATTR: ze,
189
- ALLOWED_URI_REGEXP: ye,
190
- ALLOW_DATA_ATTR: !1
191
- }), Fe = (r) => {
192
- let i = null;
193
- for (const u of r.split(";")) {
194
- const f = u.indexOf(":");
195
- if (f < 0 || u.slice(0, f).trim().toLowerCase() !== "text-align") continue;
196
- const l = u.slice(f + 1).trim().toLowerCase();
197
- De.has(l) && (i = l);
198
- }
199
- return i === null ? null : `text-align: ${i}`;
200
- }, Ge = (r) => r.nodeType === Ue ? { kind: "text", text: r.nodeValue ?? "" } : r.nodeType === He || r.nodeType === xe ? { kind: "ignored" } : r.nodeType === U && r.nodeName.toLowerCase() === "a" ? { kind: "link", href: r.getAttribute("href") } : { kind: "element" }, je = (r) => {
201
- const i = r.getAttribute("type");
202
- return i !== null && i.trim().toLowerCase() === "checkbox" && r.hasAttribute("disabled");
203
- }, Ve = (r, i, u) => {
204
- if (S.isSupported !== !0) throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");
205
- if (!Number.isSafeInteger(u) || u <= 0) throw new RangeError(`[markdown-explorer] the HTML sanitizer's depth limit must be a positive integer; got ${String(u)}`);
206
- const f = Object.freeze([...r]);
207
- let l = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap();
208
- const n = (a) => {
209
- const e = a.parentNode === null ? void 0 : l.get(a.parentNode), o = e === void 0 ? 0 : e + 1;
210
- if (l.set(a, o), a.nodeType === U && o > u) throw new q(u);
211
- }, m = (a, e) => {
212
- if (a.nodeType !== U) return;
213
- const o = a;
214
- (e.tagName === "input" && !je(o) || e.tagName === "iframe" && oe(o.getAttribute("src")?.trim(), f) === null) && o.parentNode?.removeChild(o);
215
- }, g = (a, e) => {
216
- const o = a.nodeName.toLowerCase();
217
- if (e.attrName === "style") {
218
- const E = Fe(e.attrValue);
219
- E === null ? e.keepAttr = !1 : e.attrValue = E;
220
- } else if (e.attrName === "allow" && o === "iframe") {
221
- const E = se(e.attrValue);
222
- E === null ? e.keepAttr = !1 : e.attrValue = E;
223
- } else if (e.attrName === "referrerpolicy" && o === "iframe") {
224
- const E = e.attrValue.trim().toLowerCase();
225
- ae.has(E) ? e.attrValue = E : e.keepAttr = !1;
226
- } else e.attrName === H && o === "p" ? T.set(a, a.getAttribute(H)) : Be.has(e.attrName) && Pe.test(e.attrValue) || e.attrName === P && le(e.attrValue) === null ? e.keepAttr = !1 : e.attrName === "id" && Me.has(o) && (e.forceKeepAttr = !0);
227
- }, h = (a) => {
228
- const e = a.getAttribute("data-asset-src");
229
- e !== null && (a.getAttribute("data-asset-exists") !== "false" && ce(e) ? a.setAttribute("src", ue(i, e, null)) : a.removeAttribute("src"));
230
- }, R = (a) => {
231
- const e = a.parentNode;
232
- if (e === null) return;
233
- const o = T.get(e);
234
- o != null && ie(o, [...e.childNodes].map(Ge)) !== null && e.setAttribute(H, o);
235
- }, p = (a) => {
236
- if (a.nodeType !== U) return;
237
- const e = a, o = e.nodeName.toLowerCase();
238
- o === "img" ? h(e) : o === "a" && R(e);
239
- const E = e.getAttribute("target");
240
- if (E === null || E.trim().toLowerCase() === "_self") return;
241
- const y = e.getAttribute("rel"), C = new Set(y === null ? [] : y.split(/\s+/u).filter((x) => x !== ""));
242
- C.add("noopener"), C.add("noreferrer"), e.setAttribute("rel", [...C].join(" "));
243
- };
244
- return (a) => {
245
- l = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap(), S.addHook("beforeSanitizeElements", n), S.addHook("uponSanitizeElement", m), S.addHook("uponSanitizeAttribute", g), S.addHook("afterSanitizeAttributes", p);
246
- try {
247
- return S.sanitize(a, ve);
248
- } finally {
249
- S.removeHook("beforeSanitizeElements", n), S.removeHook("uponSanitizeElement", m), S.removeHook("uponSanitizeAttribute", g), S.removeHook("afterSanitizeAttributes", p);
250
- }
251
- };
252
- }, We = (r) => {
253
- if (r === null || typeof r != "object") return !1;
254
- const { id: i, input: u } = r;
255
- if (typeof i != "number" || u === null || typeof u != "object") return !1;
256
- const { html: f, iframeHosts: l, dataPath: T, maxNodes: n, maxAttributeChars: m, maxSanitizedChars: g } = u;
257
- return typeof f == "string" && Array.isArray(l) && l.every((h) => typeof h == "string") && typeof T == "string" && T !== "" && [n, m, g].every((h) => Number.isSafeInteger(h) && h > 0);
258
- }, Qe = () => {
259
- const r = te;
260
- if (r === null) throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");
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");
261
178
  const i = /* @__PURE__ */ new Map();
262
- r.on("message", (u) => {
263
- if (!We(u)) throw new TypeError("[markdown-explorer] the sanitizer worker received a message that is not a job");
264
- const { id: f, input: l } = u;
265
- let T;
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;
266
183
  try {
267
- if (Re(l.html, G, l.maxNodes, l.maxAttributeChars).status !== "within") {
268
- r.postMessage({ id: f, output: { status: "too-large" } });
184
+ if (Te(s.html, D, s.maxNodes, s.maxAttributeChars).status !== "within") {
185
+ t.postMessage({ id: l, output: { status: "too-large" } });
269
186
  return;
270
187
  }
271
- const n = JSON.stringify([l.iframeHosts, l.dataPath]);
272
- let m = i.get(n);
273
- m === void 0 && (m = Ve(l.iframeHosts, l.dataPath, G), i.set(n, m));
274
- const g = m(l.html);
275
- T = g.length > l.maxSanitizedChars ? { status: "too-large" } : { status: "sanitized", html: g };
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 };
276
193
  } catch (n) {
277
- T = n instanceof q ? { status: "too-large" } : { status: "error", message: n instanceof Error ? `${n.name}: ${n.message}` : String(n) };
194
+ p = n instanceof Y ? { status: "too-large" } : { status: "error", message: n instanceof Error ? `${n.name}: ${n.message}` : String(n) };
278
195
  }
279
- r.postMessage({ id: f, output: T });
280
- }), r.postMessage({ ready: !0 });
196
+ t.postMessage({ id: l, output: p });
197
+ }), t.postMessage({ ready: !0 });
281
198
  };
282
- Qe();
199
+ Se();