@aiquants/markdown-explorer 0.33.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +795 -0
- package/README.md +119 -55
- package/dist/EditSurface-CLG70Vnn.cjs +6 -0
- package/dist/EditSurface-D2j1kCEE.js +990 -0
- package/dist/ExplorerSplit-CfP1smbT.js +1589 -0
- package/dist/ExplorerSplit-D_0VohOv.cjs +2 -0
- package/dist/{MultiLayout-DYNGlNy0.js → MultiLayout-BeJ5Lubb.js} +291 -290
- package/dist/MultiLayout-CxV5SI7f.cjs +1 -0
- package/dist/NativeScrollBar-BM5NULzg.js +62 -0
- package/dist/NativeScrollBar-RWXpVhbI.cjs +1 -0
- package/dist/TreeLayout-AxLw-36S.js +103 -0
- package/dist/TreeLayout-Bg2YH-EY.cjs +1 -0
- package/dist/client/MarkdownExplorer.d.cts +14 -1
- package/dist/client/MarkdownExplorer.d.ts +14 -1
- package/dist/client/edit/lineEndings.d.cts +4 -0
- package/dist/client/edit/lineEndings.d.ts +4 -0
- package/dist/client/hostContract.d.cts +67 -0
- package/dist/client/hostContract.d.ts +67 -0
- package/dist/core/config.d.cts +7 -0
- package/dist/core/config.d.ts +7 -0
- package/dist/core/contracts.d.cts +10 -4
- package/dist/core/contracts.d.ts +10 -4
- package/dist/core/draftAnswer.d.cts +23 -0
- package/dist/core/draftAnswer.d.ts +23 -0
- package/dist/core/geometry.d.cts +1 -0
- package/dist/core/geometry.d.ts +1 -0
- package/dist/core/labels.d.cts +78 -0
- package/dist/core/labels.d.ts +78 -0
- package/dist/core/location.d.cts +3 -2
- package/dist/core/location.d.ts +3 -2
- package/dist/core/ownUrls.d.cts +15 -0
- package/dist/core/ownUrls.d.ts +15 -0
- package/dist/core/treeSettings.d.cts +3 -2
- package/dist/core/treeSettings.d.ts +3 -2
- package/dist/core/viewSettings.d.cts +5 -1
- package/dist/core/viewSettings.d.ts +5 -1
- package/dist/describeValue-CLlVRO8d.js +17 -0
- package/dist/describeValue-Ccvhbt36.cjs +1 -0
- package/dist/explorerCore-DLpDuSev.js +998 -0
- package/dist/explorerCore-DYrxS9ez.cjs +1 -0
- package/dist/index-C1YMH-yI.js +5816 -0
- package/dist/index-LQWQfpAf.cjs +18 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +47 -42
- package/dist/licenses/@heroicons/react/LICENSE +21 -0
- package/dist/licenses/entities/LICENSE +11 -0
- package/dist/licenses/parse5/LICENSE +19 -0
- package/dist/location--KvTA0Ri.js +726 -0
- package/dist/location-D8DyDkuA.cjs +1 -0
- package/dist/lru-DC8GBmkX.js +39 -0
- package/dist/lru-SGmUyBQU.cjs +1 -0
- package/dist/{merge-D7L_pINl.js → merge-Bb_HpPhe.js} +1 -1
- package/dist/{merge-DZI4pkWI.cjs → merge-DQUYEGCx.cjs} +1 -1
- package/dist/nestingGuardWorker.js +5511 -0
- package/dist/ownUrls-B259RGgd.cjs +1 -0
- package/dist/ownUrls-Dh5g6ZJi.js +370 -0
- package/dist/sanitizeJob-BYRk17nr.js +21 -0
- package/dist/sanitizeJob-Cs9o3Vpl.cjs +1 -0
- package/dist/sanitizePolicy-CEMdaLUB.js +139 -0
- package/dist/sanitizePolicy-CiQfnxyd.cjs +2 -0
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +134 -139
- package/dist/sanitizerService-BY4CPCoA.cjs +1 -0
- package/dist/sanitizerService-KWXv7bPm.js +240 -0
- package/dist/server/assetResponse.d.cts +60 -0
- package/dist/server/assetResponse.d.ts +60 -0
- package/dist/server/browser/browserPlatform.d.cts +12 -0
- package/dist/server/browser/browserPlatform.d.ts +12 -0
- package/dist/server/createMarkdownExplorer.d.cts +0 -10
- package/dist/server/createMarkdownExplorer.d.ts +0 -10
- package/dist/server/explorerCore.d.cts +12 -0
- package/dist/server/explorerCore.d.ts +12 -0
- package/dist/server/fileSystemSource.d.cts +1 -0
- package/dist/server/fileSystemSource.d.ts +1 -0
- package/dist/server/inProcessFetch.d.cts +5 -0
- package/dist/server/inProcessFetch.d.ts +5 -0
- package/dist/server/platform.d.cts +18 -0
- package/dist/server/platform.d.ts +18 -0
- package/dist/server/ports.d.cts +36 -5
- package/dist/server/ports.d.ts +36 -5
- package/dist/server/sanitizeProtocol.d.cts +3 -0
- package/dist/server/sanitizeProtocol.d.ts +3 -0
- package/dist/server/sanitizer.d.cts +5 -40
- package/dist/server/sanitizer.d.ts +5 -40
- package/dist/server/sanitizerOptions.d.cts +24 -0
- package/dist/server/sanitizerOptions.d.ts +24 -0
- package/dist/server/sanitizerService.d.cts +41 -0
- package/dist/server/sanitizerService.d.ts +41 -0
- package/dist/server/{workerPool.d.cts → workerJobs.d.cts} +0 -16
- package/dist/server/{workerPool.d.ts → workerJobs.d.ts} +0 -16
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +3 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.js +270 -1343
- package/dist/serverBrowser.cjs +1 -0
- package/dist/serverBrowser.d.cts +1 -0
- package/dist/serverBrowser.d.ts +1 -0
- package/dist/serverBrowser.js +120 -0
- package/dist/serverCore.cjs +1 -0
- package/dist/serverCore.d.cts +14 -0
- package/dist/serverCore.d.ts +14 -0
- package/dist/serverCore.js +46 -0
- package/dist/storage-BpYsprog.cjs +1 -0
- package/dist/{storage-CmGHg7OA.js → storage-D1uSw-xj.js} +19 -18
- package/dist/storage.cjs +1 -1
- package/dist/storage.js +1 -1
- package/dist/styles/markdown-explorer.css +1 -1
- package/dist/tapScrollCircle-BEydRn0y.js +14 -0
- package/dist/tapScrollCircle-DdX0Wri0.cjs +1 -0
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +6 -0
- package/dist/testing.d.ts +6 -0
- package/dist/testing.js +4 -0
- package/dist/useSplitPersistence-B2Fj508K.cjs +1 -0
- package/dist/useSplitPersistence-Fkqak8G8.js +44 -0
- package/docs/behavior/dom-hooks.md +14 -3
- package/docs/behavior/hosting.md +123 -0
- package/docs/behavior/layout.md +69 -19
- package/docs/behavior/localization.md +28 -10
- package/docs/behavior/security.md +34 -14
- package/docs/behavior/url-contract.md +13 -6
- package/package.json +54 -16
- package/dist/EditSurface-BPqqykro.cjs +0 -6
- package/dist/EditSurface-CWq35IWQ.js +0 -972
- package/dist/ExplorerSplit-BRY4uy6x.js +0 -1493
- package/dist/ExplorerSplit-CQxr6b0v.cjs +0 -1
- package/dist/MultiLayout-TXbet9k3.cjs +0 -1
- package/dist/NativeScrollBar-BsWdvkHa.js +0 -64
- package/dist/NativeScrollBar-UpjxjLlB.cjs +0 -1
- package/dist/TreeLayout-BQEgZhz9.js +0 -72
- package/dist/TreeLayout-C0O1OGi4.cjs +0 -1
- package/dist/dataRoute-DLhQfdoW.js +0 -298
- package/dist/dataRoute-DwYtgyt6.cjs +0 -1
- package/dist/index-CO-RgTml.js +0 -4912
- package/dist/index-DSkK8iLE.cjs +0 -15
- package/dist/location-BxiJRTyw.cjs +0 -1
- package/dist/location-perTmwct.js +0 -663
- package/dist/sanitizePolicy-By0tKOpZ.js +0 -98
- package/dist/sanitizePolicy-T5T-3vV5.cjs +0 -1
- package/dist/storage-DM0EvkVf.cjs +0 -1
- package/dist/tapScrollCircle-CRKZremf.js +0 -12
- package/dist/tapScrollCircle-Cbf17x8g.cjs +0 -1
- package/dist/useSplitPersistence-Du01PHNg.js +0 -42
- package/dist/useSplitPersistence-pPmE4GTT.cjs +0 -1
package/dist/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-B259RGgd.cjs"),Z=require("./sanitizePolicy-CiQfnxyd.cjs"),T=require("parse5"),I=require("./describeValue-Ccvhbt36.cjs"),H=require("./sanitizeJob-Cs9o3Vpl.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-Dh5g6ZJi.js";
|
|
4
|
+
import { M as Y } from "./sanitizePolicy-CEMdaLUB.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-BYRk17nr.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();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const M=require("./describeValue-Ccvhbt36.cjs"),D=require("./lru-SGmUyBQU.cjs"),te=require("./ownUrls-B259RGgd.cjs"),Z=r=>Math.max(1,r-1),v=1024*1024,J=3e4,Y=4*v,X=64*v,Q=2**29,re=3,G=(r,o)=>r+Z(o)+re,V=4,z=512,oe=64,ne=4096,se=32,O=4096,q=(r,o)=>Math.floor(((o-oe)*v-r*se)/ne),R=(r,o,d,u)=>{if(o===void 0)return d;if(typeof o!="number")throw new TypeError(`[markdown-explorer] sanitizer.${r} must be a number; got ${M.describeValue(o)}`);if(!Number.isSafeInteger(o)||o<=0||o>u)throw new RangeError(`[markdown-explorer] sanitizer.${r} must be an integer in 1..${String(u)}; got ${M.describeValue(o)}`);return o},W=(r,o)=>{if(r.jobsPerScope<o)throw new RangeError(`[markdown-explorer] sanitizer.jobsPerScope must be at least multiView.maxPanels (${String(o)}), because a page sends the document of every panel to the sanitizer at once for one reader; got ${M.describeValue(r.jobsPerScope)}`);if(r.maxQueuedJobs<o)throw new RangeError(`[markdown-explorer] sanitizer.maxQueuedJobs must be at least multiView.maxPanels (${String(o)}), because a reader whose page finds every worker busy waits with the document of every panel; got ${M.describeValue(r.maxQueuedJobs)}`)},ae=Object.freeze(["workers","workerHeapMb"]),ie=(r,o)=>{if(r!==void 0&&!M.isPlainObject(r))throw new TypeError("[markdown-explorer] sanitizer must be a plain object of { deadlineMs, maxHtmlBytes, cacheBytes, jobsPerScope, maxQueuedJobs }");const d=r??{};for(const p of ae)if(d[p]!==void 0)throw new TypeError(`[markdown-explorer] sanitizer.${p} is an option of Node's worker threads; a browser runtime takes only { deadlineMs, maxHtmlBytes, cacheBytes, jobsPerScope, maxQueuedJobs }`);const{deadlineMs:u,maxHtmlBytes:S,cacheBytes:f,jobsPerScope:E,maxQueuedJobs:g}=d,l=R("jobsPerScope",E,G(o,1),Number.MAX_SAFE_INTEGER),_=Object.freeze({deadlineMs:R("deadlineMs",u,J,D.MAX_TIMER_MILLISECONDS),maxHtmlBytes:R("maxHtmlBytes",S,Y,Q),cacheBytes:R("cacheBytes",f,X,Number.MAX_SAFE_INTEGER),jobsPerScope:l,maxQueuedJobs:R("maxQueuedJobs",g,V*l,Number.MAX_SAFE_INTEGER)});if(W(_,o),q(_.maxHtmlBytes,z)<O)throw new RangeError(`[markdown-explorer] sanitizer.maxHtmlBytes (${String(_.maxHtmlBytes)} bytes) must leave room for ${String(O)} parsed nodes in the node budget, which a browser runtime counts in a worker heap of ${String(z)} MiB; lower maxHtmlBytes`);return _},U=Object.freeze({status:"aborted"}),I=(r,o,d)=>{const u=(r.get(o)??0)+d;u===0?r.delete(o):r.set(o,u)},L=(r,o,d)=>{if(!Number.isSafeInteger(o)||o<=0||o>d)throw new RangeError(`[markdown-explorer] a worker pool's ${r} must be an integer in 1..${String(d)}; got ${M.describeValue(o)}`)},ue=r=>r!==null&&typeof r=="object"&&r.ready===!0&&!("id"in r),K=(r,o)=>r!==null&&typeof r=="object"&&r.id===o&&"output"in r,ce=({start:r,size:o,deadlineMs:d,jobsPerScope:u,maxQueuedJobs:S})=>{L("size",o,Number.MAX_SAFE_INTEGER),L("deadline",d,D.MAX_TIMER_MILLISECONDS),L("jobsPerScope",u,Number.MAX_SAFE_INTEGER),L("maxQueuedJobs",S,Number.MAX_SAFE_INTEGER);const f=new Set,E=[],g=new Map,l=new Map,_=Z(o);let p=0;const h=(e,t)=>{const{job:n}=e;e.timer!==null&&clearTimeout(e.timer),e.timer=null,e.job=null,e.sent=!1,n!==null&&(I(g,n.scope,-1),I(l,n.scope,-1),n.settle(t))},T=e=>{const[t]=E.splice(e,1);t?.detach()},N=()=>{let e=-1,t=_,n=Number.POSITIVE_INFINITY;for(const[s,a]of E.entries()){const i=g.get(a.scope)??0,c=l.get(a.scope)??0;(i<t||i===t&&e>=0&&c<n)&&(e=s,t=i,n=c)}return e},w=(e,t)=>{f.has(e)&&(f.delete(e),h(e,t),e.worker.terminate().catch(()=>{}),A())},x=e=>{e.timer=setTimeout(()=>{w(e,{status:"timeout"})},d)},y=(e,t)=>e.sent?{status:"crashed",error:t}:{status:"unavailable",error:t},H=(e,t)=>{e.sent=!0,x(e);try{e.worker.postMessage({id:t.id,input:t.input})}catch(n){h(e,{status:"crashed",error:n}),e.worker.unref()}},B=()=>{const e={worker:r(),job:null,sent:!1,timer:null,ready:!1};return e.worker.unref(),e.timer=setTimeout(()=>{w(e,{status:"unavailable",error:new Error(`[markdown-explorer] a worker did not start within ${String(d)} ms`)})},d),e.worker.listen({message:t=>{if(!e.ready&&ue(t)){e.ready=!0,e.timer!==null&&clearTimeout(e.timer),e.timer=null,e.job===null?e.worker.unref():H(e,e.job),e.job===null&&A();return}const{job:n}=e;if(n===null||!K(t,n.id)){w(e,y(e,new Error("[markdown-explorer] a worker sent a message that answers no job")));return}h(e,{status:"done",output:t.output}),e.worker.unref(),A()},failure:t=>{w(e,y(e,t))}}),f.add(e),e},A=()=>{for(;;){const e=N(),t=E[e];if(t===void 0)return;let n;for(const a of f)if(a.job===null){n=a;break}if(n===void 0&&f.size<o)try{n=B()}catch(a){T(e),I(l,t.scope,-1),t.settle({status:"unavailable",error:a});continue}if(n===void 0)return;T(e),I(g,t.scope,1);const s=n;s.job=t,s.worker.ref(),s.ready&&H(s,t)}};return{run:(e,{scope:t,signal:n})=>new Promise(s=>{if(n.aborted){s(U);return}if((l.get(t)??0)>=u){s({status:"refused",limit:"scope"});return}p+=1;const a={id:p,input:e,scope:t,settle:s,detach:()=>{}};E.push(a),I(l,t,1),A();const i=E.indexOf(a);if(i<0)return;if(E.length>S){T(i),I(l,t,-1),s({status:"refused",limit:"queue"});return}const c=()=>{const m=E.indexOf(a);m<0||(T(m),I(l,t,-1),s(U))};n.addEventListener("abort",c,{once:!0}),a.detach=()=>{n.removeEventListener("abort",c)}}),workers:()=>f.size}},de=4,le=({maxHtmlBytes:r})=>r,me=({maxHtmlBytes:r})=>de*r,Ee=1024,fe=64,j=Object.freeze({status:"rejected",reason:"too-large",cause:null}),k=Object.freeze({status:"rejected",reason:"failed",cause:null}),we=r=>{if(r===null||typeof r!="object")return!1;const{status:o,html:d,message:u}=r;return o==="sanitized"&&typeof d=="string"||o==="too-large"||o==="error"&&typeof u=="string"},F=r=>({status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer could not measure a document",{cause:r})}),be=({iframeHosts:r,dataPath:o,ownUrls:d,limits:u,nodeBudget:S,measureHtml:f,classifyCrash:E,pool:g})=>{if(!Number.isSafeInteger(S)||S<=0)throw new RangeError(`[markdown-explorer] the HTML sanitizer's node budget must be a positive integer; got ${M.describeValue(S)}`);const l=Object.freeze([...r]),_=te.readOwnUrls(d),p=le(u),h=me(u),T=D.createLruCache(Ee,{max:u.cacheBytes,of:(e,t)=>2*e.length+(t.status==="sanitized"?2*t.html.length:fe)}),N=new Map,w=new Map,x=e=>{N.get(e.key)===e&&N.delete(e.key);const t=w.get(e.hash);t?.delete(e),t?.size===0&&w.delete(e.hash)},y=async(e,t,n)=>{const s=await g.run({html:e,iframeHosts:l,dataPath:o,ownUrls:_,maxNodes:S,maxAttributeChars:p,maxSanitizedChars:h},{scope:t,signal:n});if(s.status==="refused"){const i=s.limit==="scope"?`its reader already has ${String(u.jobsPerScope)} documents being sanitized or waiting`:`${String(u.maxQueuedJobs)} documents are already waiting`;return{outcome:{status:"rejected",reason:"failed",cause:new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${i}`)},lasting:!1}}if(s.status==="aborted")return{outcome:k,lasting:!1};if(s.status==="timeout")return{outcome:{status:"rejected",reason:"too-large",cause:new Error(`[markdown-explorer] the HTML sanitizer did not finish within ${String(u.deadlineMs)} ms`)},lasting:!0};if(s.status==="unavailable")return{outcome:{status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer worker could not start",{cause:s.error})},lasting:!1};if(s.status==="crashed"){const i=E(s.error);return i!==null?{outcome:{status:"rejected",reason:i.reason,cause:new Error(i.message,{cause:s.error})},lasting:!0}:{outcome:{status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer worker failed",{cause:s.error})},lasting:!0}}const{output:a}=s;return we(a)?a.status==="too-large"?{outcome:j,lasting:!0}:a.status==="error"?{outcome:{status:"rejected",reason:"failed",cause:new Error(`[markdown-explorer] the HTML sanitizer failed: ${a.message}`)},lasting:!0}:a.html.length>h?{outcome:{status:"rejected",reason:"too-large",cause:new Error(`[markdown-explorer] the HTML sanitizer's output of ${String(a.html.length)} characters exceeds its limit of ${String(h)}`)},lasting:!0}:{outcome:{status:"sanitized",html:a.html},lasting:!0}:{outcome:{status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer worker answered something that is not an outcome")},lasting:!0}},H=(e,t,n,s)=>{let a=()=>{};const i=new Promise(b=>{a=b}),c={hash:t,key:n,outcome:i,answer:a,controller:new AbortController,waiters:0};N.set(n,c);const m=w.get(t);return m===void 0?w.set(t,new Set([c])):m.add(c),y(e,s,c.controller.signal).catch(b=>({outcome:{status:"rejected",reason:"failed",cause:b instanceof Error?b:new Error(String(b))},lasting:!0})).then(({outcome:b,lasting:ee})=>{if(x(c),c.answer(b),!ee)return;const $=T.get(t),C=$??(b.status==="rejected"?{...b,cause:null}:b);$===void 0&&T.set(t,C);for(const P of w.get(t)??[])x(P),P.answer(C),P.controller.abort()}),c},B=(e,t)=>new Promise(n=>{e.waiters+=1;const s=()=>{e.waiters-=1,n(k),!(e.waiters>0)&&(x(e),e.controller.abort())};t.addEventListener("abort",s,{once:!0}),e.outcome.then(a=>{t.removeEventListener("abort",s),n(a)})}),A=(e,{utf8Bytes:t,hash:n},s,a)=>{if(t>u.maxHtmlBytes)return Promise.resolve(j);const i=T.get(n);if(i!==void 0)return Promise.resolve(i);if(a.aborted)return Promise.resolve(k);const c=`${n}\0${s}`,m=N.get(c);return B(m===void 0?H(e,n,c,s):m,a)};return(e,{scope:t,signal:n})=>{if(e.length>u.maxHtmlBytes)return Promise.resolve(j);let s;try{s=f(e)}catch(i){return Promise.resolve(F(i))}if(!(s instanceof Promise))return A(e,s,t,n);const a=s;return new Promise(i=>{const c=()=>i(k);n.addEventListener("abort",c,{once:!0}),a.then(m=>{n.removeEventListener("abort",c),i(A(e,m,t,n))},m=>{n.removeEventListener("abort",c),i(F(m))})})}};exports.DEFAULT_SANITIZER_CACHE_BYTES=X;exports.DEFAULT_SANITIZER_DEADLINE_MS=J;exports.DEFAULT_SANITIZER_MAX_HTML_BYTES=Y;exports.DEFAULT_SANITIZER_WORKER_HEAP_MB=z;exports.MAX_HTML_BYTES=Q;exports.MIN_HTML_NODE_BUDGET=O;exports.SANITIZER_QUEUED_READERS=V;exports.assertAdmissionCoversPanels=W;exports.assertPoolLimit=L;exports.createHtmlSanitizerService=be;exports.createWorkerPoolCore=ce;exports.defaultSanitizerJobsPerScope=G;exports.htmlNodeBudgetOf=q;exports.isReplyTo=K;exports.readLimit=R;exports.resolveBrowserSanitizerLimits=ie;
|