@aiquants/markdown-explorer 0.34.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.
Files changed (140) hide show
  1. package/CHANGELOG.md +515 -0
  2. package/README.md +90 -39
  3. package/dist/EditSurface-CLG70Vnn.cjs +6 -0
  4. package/dist/EditSurface-D2j1kCEE.js +990 -0
  5. package/dist/ExplorerSplit-CfP1smbT.js +1589 -0
  6. package/dist/ExplorerSplit-D_0VohOv.cjs +2 -0
  7. package/dist/{MultiLayout-kcZyVnvK.js → MultiLayout-BeJ5Lubb.js} +249 -248
  8. package/dist/MultiLayout-CxV5SI7f.cjs +1 -0
  9. package/dist/{NativeScrollBar-UNed10Na.js → NativeScrollBar-BM5NULzg.js} +2 -2
  10. package/dist/{NativeScrollBar-pUbA4Zq3.cjs → NativeScrollBar-RWXpVhbI.cjs} +1 -1
  11. package/dist/TreeLayout-AxLw-36S.js +103 -0
  12. package/dist/TreeLayout-Bg2YH-EY.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 +7 -0
  20. package/dist/core/config.d.ts +7 -0
  21. package/dist/core/contracts.d.cts +10 -4
  22. package/dist/core/contracts.d.ts +10 -4
  23. package/dist/core/draftAnswer.d.cts +23 -0
  24. package/dist/core/draftAnswer.d.ts +23 -0
  25. package/dist/core/labels.d.cts +68 -0
  26. package/dist/core/labels.d.ts +68 -0
  27. package/dist/core/location.d.cts +1 -2
  28. package/dist/core/location.d.ts +1 -2
  29. package/dist/core/ownUrls.d.cts +15 -0
  30. package/dist/core/ownUrls.d.ts +15 -0
  31. package/dist/core/treeSettings.d.cts +3 -2
  32. package/dist/core/treeSettings.d.ts +3 -2
  33. package/dist/core/viewSettings.d.cts +3 -1
  34. package/dist/core/viewSettings.d.ts +3 -1
  35. package/dist/describeValue-CLlVRO8d.js +17 -0
  36. package/dist/describeValue-Ccvhbt36.cjs +1 -0
  37. package/dist/explorerCore-DLpDuSev.js +998 -0
  38. package/dist/explorerCore-DYrxS9ez.cjs +1 -0
  39. package/dist/index-C1YMH-yI.js +5816 -0
  40. package/dist/index-LQWQfpAf.cjs +18 -0
  41. package/dist/index.cjs +1 -1
  42. package/dist/index.d.cts +7 -4
  43. package/dist/index.d.ts +7 -4
  44. package/dist/index.js +49 -44
  45. package/dist/licenses/@heroicons/react/LICENSE +21 -0
  46. package/dist/licenses/entities/LICENSE +11 -0
  47. package/dist/licenses/parse5/LICENSE +19 -0
  48. package/dist/location--KvTA0Ri.js +726 -0
  49. package/dist/location-D8DyDkuA.cjs +1 -0
  50. package/dist/lru-DC8GBmkX.js +39 -0
  51. package/dist/lru-SGmUyBQU.cjs +1 -0
  52. package/dist/{merge-C1MWvhCS.js → merge-Bb_HpPhe.js} +1 -1
  53. package/dist/{merge-BziXxZkE.cjs → merge-DQUYEGCx.cjs} +1 -1
  54. package/dist/nestingGuardWorker.js +5511 -0
  55. package/dist/ownUrls-B259RGgd.cjs +1 -0
  56. package/dist/ownUrls-Dh5g6ZJi.js +370 -0
  57. package/dist/sanitizeJob-BYRk17nr.js +21 -0
  58. package/dist/sanitizeJob-Cs9o3Vpl.cjs +1 -0
  59. package/dist/sanitizePolicy-CEMdaLUB.js +139 -0
  60. package/dist/sanitizePolicy-CiQfnxyd.cjs +2 -0
  61. package/dist/sanitizeWorker.cjs +1 -1
  62. package/dist/sanitizeWorker.js +134 -139
  63. package/dist/sanitizerService-BY4CPCoA.cjs +1 -0
  64. package/dist/sanitizerService-KWXv7bPm.js +240 -0
  65. package/dist/server/assetResponse.d.cts +60 -0
  66. package/dist/server/assetResponse.d.ts +60 -0
  67. package/dist/server/browser/browserPlatform.d.cts +12 -0
  68. package/dist/server/browser/browserPlatform.d.ts +12 -0
  69. package/dist/server/createMarkdownExplorer.d.cts +0 -10
  70. package/dist/server/createMarkdownExplorer.d.ts +0 -10
  71. package/dist/server/explorerCore.d.cts +12 -0
  72. package/dist/server/explorerCore.d.ts +12 -0
  73. package/dist/server/fileSystemSource.d.cts +1 -0
  74. package/dist/server/fileSystemSource.d.ts +1 -0
  75. package/dist/server/inProcessFetch.d.cts +5 -0
  76. package/dist/server/inProcessFetch.d.ts +5 -0
  77. package/dist/server/platform.d.cts +18 -0
  78. package/dist/server/platform.d.ts +18 -0
  79. package/dist/server/ports.d.cts +36 -5
  80. package/dist/server/ports.d.ts +36 -5
  81. package/dist/server/sanitizeProtocol.d.cts +3 -0
  82. package/dist/server/sanitizeProtocol.d.ts +3 -0
  83. package/dist/server/sanitizer.d.cts +5 -40
  84. package/dist/server/sanitizer.d.ts +5 -40
  85. package/dist/server/sanitizerOptions.d.cts +24 -0
  86. package/dist/server/sanitizerOptions.d.ts +24 -0
  87. package/dist/server/sanitizerService.d.cts +41 -0
  88. package/dist/server/sanitizerService.d.ts +41 -0
  89. package/dist/server/{workerPool.d.cts → workerJobs.d.cts} +0 -16
  90. package/dist/server/{workerPool.d.ts → workerJobs.d.ts} +0 -16
  91. package/dist/server.cjs +1 -1
  92. package/dist/server.d.cts +3 -1
  93. package/dist/server.d.ts +3 -1
  94. package/dist/server.js +270 -1343
  95. package/dist/serverBrowser.cjs +1 -0
  96. package/dist/serverBrowser.d.cts +1 -0
  97. package/dist/serverBrowser.d.ts +1 -0
  98. package/dist/serverBrowser.js +120 -0
  99. package/dist/serverCore.cjs +1 -0
  100. package/dist/serverCore.d.cts +14 -0
  101. package/dist/serverCore.d.ts +14 -0
  102. package/dist/serverCore.js +46 -0
  103. package/dist/storage-BpYsprog.cjs +1 -0
  104. package/dist/{storage-CmGHg7OA.js → storage-D1uSw-xj.js} +19 -18
  105. package/dist/storage.cjs +1 -1
  106. package/dist/storage.js +1 -1
  107. package/dist/styles/markdown-explorer.css +1 -1
  108. package/dist/{tapScrollCircle-D_BpaLwY.js → tapScrollCircle-BEydRn0y.js} +1 -1
  109. package/dist/{tapScrollCircle-DigcJCsu.cjs → tapScrollCircle-DdX0Wri0.cjs} +1 -1
  110. package/dist/testing.cjs +1 -0
  111. package/dist/testing.d.cts +6 -0
  112. package/dist/testing.d.ts +6 -0
  113. package/dist/testing.js +4 -0
  114. package/dist/useSplitPersistence-B2Fj508K.cjs +1 -0
  115. package/dist/useSplitPersistence-Fkqak8G8.js +44 -0
  116. package/docs/behavior/dom-hooks.md +2 -0
  117. package/docs/behavior/hosting.md +123 -0
  118. package/docs/behavior/layout.md +5 -3
  119. package/docs/behavior/localization.md +25 -8
  120. package/docs/behavior/security.md +32 -13
  121. package/docs/behavior/url-contract.md +4 -3
  122. package/package.json +48 -10
  123. package/dist/EditSurface-CF82jZQg.cjs +0 -6
  124. package/dist/EditSurface-CqHk2R3k.js +0 -982
  125. package/dist/ExplorerSplit-D325YGEf.cjs +0 -1
  126. package/dist/ExplorerSplit-DGH9bckm.js +0 -1500
  127. package/dist/MultiLayout-CzR7yJ0m.cjs +0 -1
  128. package/dist/TreeLayout-BnIU87HX.js +0 -96
  129. package/dist/TreeLayout-DtvIpuOe.cjs +0 -1
  130. package/dist/dataRoute-D6KiSHIc.js +0 -298
  131. package/dist/dataRoute-DwYtgyt6.cjs +0 -1
  132. package/dist/index-BDCbvHDs.cjs +0 -15
  133. package/dist/index-DR31S_-4.js +0 -5012
  134. package/dist/location-C44b9H1S.js +0 -676
  135. package/dist/location-hGLhCCg4.cjs +0 -1
  136. package/dist/sanitizePolicy-CwvyPpp5.js +0 -98
  137. package/dist/sanitizePolicy-T5T-3vV5.cjs +0 -1
  138. package/dist/storage-DM0EvkVf.cjs +0 -1
  139. package/dist/useSplitPersistence-DCeYbJMx.js +0 -38
  140. package/dist/useSplitPersistence-QGcvyMAa.cjs +0 -1
@@ -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-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();
@@ -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-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 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();
@@ -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;