@aiquants/markdown-explorer 0.11.0 → 0.12.1

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 (42) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +65 -6
  3. package/dist/EditSurface-By6NPcD7.js +633 -0
  4. package/dist/EditSurface-BztcpQPW.cjs +2 -0
  5. package/dist/{ExplorerSplit-DwlWWfRv.js → ExplorerSplit-BjjqNRtj.js} +52 -52
  6. package/dist/{ExplorerSplit-51frK8xf.cjs → ExplorerSplit-CqmbUSZ7.cjs} +1 -1
  7. package/dist/{MultiLayout-CeR_l6Rb.js → MultiLayout-BYXoD1aS.js} +4 -4
  8. package/dist/{MultiLayout-B4PtS45V.cjs → MultiLayout-BZbEl73E.cjs} +1 -1
  9. package/dist/{NativeScrollBar-Dp4YWBp7.cjs → NativeScrollBar-B7jTbQmn.cjs} +1 -1
  10. package/dist/{NativeScrollBar-CVWeTlHC.js → NativeScrollBar-RP37nwmY.js} +1 -1
  11. package/dist/{TreeLayout-D-NyhuVM.cjs → TreeLayout-CEp5oKly.cjs} +1 -1
  12. package/dist/{TreeLayout-min5AOhr.js → TreeLayout-Uo6RG7lq.js} +3 -3
  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-CGBl3fYT.cjs} +8 -8
  20. package/dist/{index-BPj19kIo.js → index-CjCr8czx.js} +962 -908
  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-DRGBbLuR.cjs} +1 -1
  28. package/dist/{merge-hyUGPGbJ.js → merge-q-5i8qsn.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/dist/styles/markdown-explorer.css +1 -1
  36. package/docs/behavior/dom-hooks.md +1 -1
  37. package/docs/behavior/layout.md +4 -1
  38. package/docs/behavior/security.md +2 -0
  39. package/package.json +3 -3
  40. package/dist/EditSurface-BK_Pz_LF.js +0 -371
  41. package/dist/EditSurface-CfbYYXrc.cjs +0 -2
  42. package/dist/dataRoute-CIFFX5bd.cjs +0 -1
package/dist/server.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./dataRoute-CIFFX5bd.cjs"),wt=require("node:crypto"),Jt=require("@aiquants/markdown/server"),ke=require("@aiquants/request-isolation"),xe=require("react-router"),se=require("./location-LNl0QOXI.cjs"),ie=require("node:fs"),ne=require("node:path"),Re=require("node:url"),Yt=require("node:worker_threads"),me=require("node:fs/promises"),Wt=require("node:stream");var _e=typeof document<"u"?document.currentScript:null;const Ue=Object.freeze({kind:"anonymous"}),Kt=Object.freeze({authenticate:async()=>({status:"signed-in",principal:Ue}),principalKey:()=>Ue.kind,signedOutPage:(e,t)=>new Response(null,{status:401,headers:t})}),Vt="application/octet-stream",yt="application/pdf",Qt=new Set(["image/png","image/apng","image/jpeg","image/gif","image/webp","image/avif","image/bmp","image/x-icon","image/vnd.microsoft.icon","audio/mpeg","audio/mp4","audio/aac","audio/ogg","audio/opus","audio/wav","audio/wave","audio/x-wav","audio/webm","audio/flac","audio/x-flac","audio/x-m4a","video/mp4","video/webm","video/ogg","video/quicktime",yt]),gt="default-src 'none'; media-src 'self'; style-src 'unsafe-inline'",Et=`${gt}; sandbox`,Zt=`${gt}; sandbox allow-same-origin`,Xe=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u,qt=/^[\t\n\r ]+|[\t\n\r ]+$/gu,Le=/^[\t ]+|[\t ]+$/gu,er=e=>{const t=[];let r="",n=0;for(;;){for(;n<e.length&&e[n]!=='"'&&e[n]!==",";)r+=e[n],n+=1;if(n<e.length&&e[n]==='"'){const a=n;for(n+=1;n<e.length&&e[n]!=='"';)n+=e[n]==="\\"?2:1;if(n=Math.min(n+1,e.length),r+=e.slice(a,n),n<e.length)continue}if(t.push(r.replace(Le,"")),r="",n>=e.length)return t;n+=1}},tr=e=>{const t=e.replace(qt,""),r=t.indexOf("/");if(r<0)return null;const n=t.slice(0,r),a=t.indexOf(";",r+1),i=t.slice(r+1,a<0?t.length:a).replace(/[\t\n\r ]+$/u,"");return Xe.test(n)&&Xe.test(i)?`${n}/${i}`.toLowerCase():null},rr=e=>{let t=null;for(const r of er(e)){const n=tr(r);n!==null&&n!=="*/*"&&(t=n)}return t},nr=/['()*]/gu,bt=e=>encodeURIComponent(e).replace(nr,t=>`%${t.charCodeAt(0).toString(16).toUpperCase()}`),or=Object.freeze({"Cache-Control":"private, max-age=60, stale-while-revalidate=600, no-transform",Vary:"Cookie"}),sr=(e,t)=>{const r=rr(e),n=r!==null&&Qt.has(r),a=n&&(r.startsWith("audio/")||r.startsWith("video/"));return{contentType:r===null?Vt:r,inline:n,headers:{"X-Content-Type-Options":"nosniff","Content-Disposition":`${n?"inline":"attachment"}; filename*=UTF-8''${bt(t)}`,...r===yt?{}:{"Content-Security-Policy":a?Zt:Et},"Cross-Origin-Resource-Policy":"same-origin"}}},ir="text/plain; charset=utf-8",ar=e=>({contentType:ir,inline:!0,headers:{"X-Content-Type-Options":"nosniff","Content-Disposition":`inline; filename*=UTF-8''${bt(e)}`,"Content-Security-Policy":Et,"Cross-Origin-Resource-Policy":"same-origin"}}),cr=/^bytes=(?:(\d+)-(\d*)|-(\d+))$/iu,Ee=Object.freeze({kind:"whole"}),Ge=Object.freeze({kind:"unsatisfiable"}),ur=(e,t,r)=>{const n=e.get("Range");if(n===null)return Ee;const a=e.get("If-Range");if(a!==null&&a!==r)return Ee;const i=cr.exec(n);if(i===null)return Ee;const[,c,m,y]=i;if(y!==void 0){const g=Number(y);if(g===0)return Ge;const k=Math.max(0,t-g);return{kind:"partial",range:{offset:k,length:t-k}}}const O=Number(c),h=m===""?Number.POSITIVE_INFINITY:Number(m);return h<O?Ee:O>=t?Ge:{kind:"partial",range:{offset:O,length:Math.min(h,t-1)-O+1}}},Je="W/",lr=e=>{const t=[];let r=0,n=!1;for(let a=0;a<e.length;a+=1)e[a]==='"'?n=!n:e[a]===","&&!n&&(t.push(e.slice(r,a).replace(Le,"")),r=a+1);return t.push(e.slice(r).replace(Le,"")),t},Ye=e=>e.startsWith(Je)?e.slice(Je.length):e,dr=(e,t)=>{if(e===null)return!1;const r=lr(e);if(r.length===1&&r[0]==="*")return!0;const n=Ye(t);return r.some(a=>Ye(a)===n)},fr=(e,t)=>{let r=t;return e.pipeThrough(new TransformStream({transform:(n,a)=>{const i=n.byteLength>r?n.subarray(0,r):n;r-=i.byteLength,a.enqueue(i),r===0&&a.terminate()},flush:n=>{r>0&&n.error(new RangeError("[markdown-explorer] the asset ended before its declared length"))}}))},Ae=async(e,t,r,n,a)=>{if(n!==null&&r.set("Content-Length",String(n)),e.method.toUpperCase()==="HEAD")return new Response(null,{status:t,headers:r});const i=await a();return new Response(n===null?i:fr(i,n),{status:t,headers:r})},mr=(e,t)=>{const r=new Headers(e);for(const[n,a]of Object.entries({"Accept-Ranges":"bytes","Content-Range":`bytes */${t}`,"Cache-Control":"private, no-store","X-Content-Type-Options":"nosniff"}))r.set(n,a);return new Response(null,{status:416,headers:r})},pr=async(e,t,r,n)=>{const a=`"${t.version}"`,i=n==="text"?ar(t.name):sr(t.contentType,t.name),c=new Headers(r);for(const[O,h]of Object.entries({...i.headers,...or,ETag:a}))c.set(O,h);if(dr(e.headers.get("If-None-Match"),a))return new Response(null,{status:304,headers:c});if(c.set("Content-Type",i.contentType),t.size===null)return Ae(e,200,c,null,()=>t.open(null));if(t.size===0)return c.set("Content-Length","0"),new Response(null,{status:200,headers:c});c.set("Accept-Ranges","bytes");const m=ur(e.headers,t.size,a);if(m.kind==="unsatisfiable")return mr(r,t.size);if(m.kind==="whole")return Ae(e,200,c,t.size,()=>t.open(null));const{range:y}=m;return c.set("Content-Range",`bytes ${y.offset}-${y.offset+y.length-1}/${t.size}`),Ae(e,206,c,y.length,()=>t.open(y))},ve=(e,t)=>{const r=new AbortController,n=t(AbortSignal.any([e.signal,r.signal]));return new Promise(a=>{let i;const c=setTimeout(()=>{a(e.late),i=setTimeout(()=>r.abort(),e.handOverMs)},e.timeoutMs),m=()=>{clearTimeout(c),clearTimeout(i)};n.then(y=>{m(),a(y)},()=>{m(),a(e.late)})})},hr=Object.freeze({error:(e,t)=>{console.error(e,t)}}),Tt=Symbol.for("@aiquants/markdown-explorer:ExplorerError");class ye extends Error{reason;code;constructor(t,r={}){if(!w.isExplorerFailureReason(t))throw new RangeError(`[markdown-explorer] ExplorerError needs a failure reason; got ${JSON.stringify(t)}`);if(r.code!==void 0&&!w.isExplorerFailureCode(r.code))throw new RangeError(`[markdown-explorer] an ExplorerError code must be 1 to 64 lowercase letters, digits or hyphens; got ${JSON.stringify(r.code)}`);super(`[markdown-explorer] ${t}`,r.cause===void 0?void 0:{cause:r.cause}),this.name="ExplorerError",this.reason=t,this.code=r.code,Object.defineProperty(this,Tt,{value:!0})}}const wr=e=>e instanceof Error&&Object.hasOwn(e,Tt)&&w.isExplorerFailureReason(e.reason),yr=e=>typeof e=="object"&&e!==null&&e.name==="AbortError",$e=(e,t,r)=>{try{e.error(t,r)}catch(n){console.error("[markdown-explorer] the logger threw while reporting a failure",{operation:r.operation,error:n})}},oe=(e,t)=>$e(e,`[markdown-explorer] ${t.operation} failed`,t),gr=(e,t)=>$e(e,`[markdown-explorer] ${t.operation} left out an entry`,t),Ne=(e,t)=>$e(e,`[markdown-explorer] ${t.operation} refused a path the deny rules match`,{...t,error:new RangeError("[markdown-explorer] the path matches a deny rule")}),We=(e,t)=>{e===null||typeof e!="object"&&typeof e!="function"||Promise.resolve(e).then(void 0,t)},Y=(e,t,r,n)=>wr(e)?w.failureOf(e.reason,e.code):(yr(e)||r.aborted||oe(n,{...t,error:e}),{reason:"failed"}),Ke=2*1024*1024,Ve=256*1024*1024,Er=async(e,t)=>{const r=e.getReader(),n=new Uint8Array(t);let a=0;for(;a<t;){const{done:i,value:c}=await r.read();if(i)return n.subarray(0,a);const m=c.subarray(0,t-a);n.set(m,a),a+=m.byteLength}return r.cancel().catch(()=>{}),n},br=async(e,t)=>{if(e.size===0)return{text:"",truncated:!1};const r=e.size!==null&&e.size>t,n=e.size===null?t+1:Math.min(e.size,t),a=await Er(await e.open(r?{offset:0,length:t}:null),n);if(e.size!==null&&a.byteLength<n)throw new RangeError("[markdown-explorer] the file ended before the length its asset port reported");const i=r||a.byteLength>t,c=i?a.subarray(0,t):a;return c.includes(0)?null:{text:new TextDecoder("utf-8").decode(c,{stream:i}),truncated:i}},Qe=(e,t)=>{if(!Number.isSafeInteger(t)||t<=0)throw new RangeError(`[markdown-explorer] a cache ${e} must be a positive integer; got ${String(t)}`)},St=(e,t)=>{Qe("capacity",e),t!==void 0&&Qe("weight budget",t.max);const r=new Map;let n=0;const a=i=>{const c=r.get(i);c!==void 0&&(r.delete(i),n-=c.weight)};return{get:i=>{const c=r.get(i);if(c!==void 0)return r.delete(i),r.set(i,c),c.value},set:(i,c)=>{a(i);const m=t===void 0?0:t.of(i,c);if(!(t!==void 0&&m>t.max)){r.set(i,{value:c,weight:m}),n+=m;for(const y of r.keys()){if(r.size<=e&&(t===void 0||n<=t.max))break;a(y)}}},delete:a,size:()=>r.size,weight:()=>n}},kt=e=>Math.max(1,e-1),Tr=2147483647,Ze=Object.freeze({status:"aborted"}),le=(e,t,r)=>{const n=(e.get(t)??0)+r;n===0?e.delete(t):e.set(t,n)},fe=(e,t,r)=>{if(!Number.isSafeInteger(t)||t<=0||t>r)throw new RangeError(`[markdown-explorer] a worker pool's ${e} must be an integer in 1..${String(r)}; got ${String(t)}`)},Sr=e=>e!==null&&typeof e=="object"&&e.ready===!0&&!("id"in e),kr=(e,t)=>e!==null&&typeof e=="object"&&e.id===t&&"output"in e,Or=({url:e,size:t,deadlineMs:r,jobsPerScope:n,maxQueuedJobs:a,heapLimits:i})=>{fe("size",t,Number.MAX_SAFE_INTEGER),fe("deadline",r,Tr),fe("jobsPerScope",n,Number.MAX_SAFE_INTEGER),fe("maxQueuedJobs",a,Number.MAX_SAFE_INTEGER),fe("maxOldGenerationSizeMb",i.maxOldGenerationSizeMb,Number.MAX_SAFE_INTEGER),fe("maxYoungGenerationSizeMb",i.maxYoungGenerationSizeMb,Number.MAX_SAFE_INTEGER);const c=Object.freeze({maxOldGenerationSizeMb:i.maxOldGenerationSizeMb,maxYoungGenerationSizeMb:i.maxYoungGenerationSizeMb}),m=new Set,y=[],O=new Map,h=new Map,g=kt(t);let k=0;const A=(p,E)=>{const{job:b}=p;p.timer!==null&&clearTimeout(p.timer),p.timer=null,p.job=null,p.sent=!1,b!==null&&(le(O,b.scope,-1),le(h,b.scope,-1),b.settle(E))},$=p=>{const[E]=y.splice(p,1);E?.detach()},N=()=>{let p=-1,E=g,b=Number.POSITIVE_INFINITY;for(const[R,S]of y.entries()){const P=O.get(S.scope)??0,L=h.get(S.scope)??0;(P<E||P===E&&p>=0&&L<b)&&(p=R,E=P,b=L)}return p},_=(p,E)=>{m.has(p)&&(m.delete(p),A(p,E),p.worker.terminate().catch(()=>{}),F())},z=p=>{p.timer=setTimeout(()=>{_(p,{status:"timeout"})},r)},v=(p,E)=>p.sent?{status:"crashed",error:E}:{status:"unavailable",error:E},I=(p,E)=>{p.sent=!0,z(p);try{p.worker.postMessage({id:E.id,input:E.input})}catch(b){A(p,{status:"crashed",error:b}),p.worker.unref()}},C=()=>{const p={worker:new Yt.Worker(e,{resourceLimits:c}),job:null,sent:!1,timer:null,ready:!1};return p.worker.unref(),p.timer=setTimeout(()=>{_(p,{status:"unavailable",error:new Error(`[markdown-explorer] a worker did not start within ${String(r)} ms`)})},r),p.worker.on("message",E=>{if(!p.ready&&Sr(E)){p.ready=!0,p.timer!==null&&clearTimeout(p.timer),p.timer=null,p.job===null?p.worker.unref():I(p,p.job),p.job===null&&F();return}const{job:b}=p;if(b===null||!kr(E,b.id)){_(p,v(p,new Error("[markdown-explorer] a worker sent a message that answers no job")));return}A(p,{status:"done",output:E.output}),p.worker.unref(),F()}),p.worker.on("error",E=>{_(p,v(p,E))}),p.worker.on("messageerror",E=>{_(p,v(p,E))}),p.worker.on("exit",E=>{_(p,v(p,new Error(`[markdown-explorer] a worker exited with code ${String(E)}`)))}),m.add(p),p},F=()=>{for(;;){const p=N(),E=y[p];if(E===void 0)return;let b;for(const S of m)if(S.job===null){b=S;break}if(b===void 0&&m.size<t)try{b=C()}catch(S){$(p),le(h,E.scope,-1),E.settle({status:"unavailable",error:S});continue}if(b===void 0)return;$(p),le(O,E.scope,1);const R=b;R.job=E,R.worker.ref(),R.ready&&I(R,E)}};return{run:(p,{scope:E,signal:b})=>new Promise(R=>{if(b.aborted){R(Ze);return}if((h.get(E)??0)>=n){R({status:"refused",limit:"scope"});return}k+=1;const S={id:k,input:p,scope:E,settle:R,detach:()=>{}};y.push(S),le(h,E,1),F();const P=y.indexOf(S);if(P<0)return;if(y.length>a){$(P),le(h,E,-1),R({status:"refused",limit:"queue"});return}const L=()=>{const X=y.indexOf(S);X<0||($(X),le(h,E,-1),R(Ze))};b.addEventListener("abort",L,{once:!0}),S.detach=()=>{b.removeEventListener("abort",L)}}),workers:()=>m.size}},je=1024*1024,xr=3e4,Rr=4*je,_r=64*je,Ar=3,vr=2,Nr=(e,t)=>e+kt(t)+Ar,Pr=4,Ir=32,Mr=512,Lr=64,Dr=4096,$r=32,qe=4096,jr=4,Ot=({workerHeapMb:e,maxHtmlBytes:t})=>Math.floor(((e-Lr)*je-t*$r)/Dr),zr=({maxHtmlBytes:e})=>e,Cr=({maxHtmlBytes:e})=>jr*e,Hr=1024,Br=2147483647,Fr=64,Ur=2**29,Xr=1024*1024,Gr=64,et=Object.freeze({status:"rejected",reason:"too-large",cause:null}),Pe=Object.freeze({status:"rejected",reason:"failed",cause:null}),de=(e,t,r,n)=>{if(t===void 0)return r;if(typeof t!="number")throw new TypeError(`[markdown-explorer] sanitizer.${e} must be a number; got ${typeof t}`);if(!Number.isSafeInteger(t)||t<=0||t>n)throw new RangeError(`[markdown-explorer] sanitizer.${e} must be an integer in 1..${String(n)}; got ${String(t)}`);return t},Jr=(e,t)=>{if(e!==void 0&&(e===null||typeof e!="object"))throw new TypeError("[markdown-explorer] sanitizer must be an object of { workers, deadlineMs, maxHtmlBytes, cacheBytes, workerHeapMb, jobsPerScope, maxQueuedJobs }");const{workers:r,deadlineMs:n,maxHtmlBytes:a,cacheBytes:i,workerHeapMb:c,jobsPerScope:m,maxQueuedJobs:y}=e??{},O=de("workers",r,vr,Fr),h=de("jobsPerScope",m,Nr(t,O),Number.MAX_SAFE_INTEGER),g=Object.freeze({workers:O,deadlineMs:de("deadlineMs",n,xr,Br),maxHtmlBytes:de("maxHtmlBytes",a,Rr,Ur),cacheBytes:de("cacheBytes",i,_r,Number.MAX_SAFE_INTEGER),workerHeapMb:de("workerHeapMb",c,Mr,Xr),jobsPerScope:h,maxQueuedJobs:de("maxQueuedJobs",y,Pr*h,Number.MAX_SAFE_INTEGER)});if(g.jobsPerScope<t)throw new RangeError(`[markdown-explorer] sanitizer.jobsPerScope must be at least multiView.maxPanels (${String(t)}), because a page sends the document of every panel to the sanitizer at once for one reader; got ${String(g.jobsPerScope)}`);if(g.maxQueuedJobs<t)throw new RangeError(`[markdown-explorer] sanitizer.maxQueuedJobs must be at least multiView.maxPanels (${String(t)}), because a reader whose page finds every worker busy waits with the document of every panel; got ${String(g.maxQueuedJobs)}`);if(Ot(g)<qe)throw new RangeError(`[markdown-explorer] sanitizer.workerHeapMb (${String(g.workerHeapMb)} MiB) must leave room for ${String(qe)} parsed nodes beside HTML of sanitizer.maxHtmlBytes (${String(g.maxHtmlBytes)} bytes); raise workerHeapMb or lower maxHtmlBytes`);return g},Yr=()=>{const e=typeof document>"u"?require("url").pathToFileURL(__filename).href:_e&&_e.tagName.toUpperCase()==="SCRIPT"&&_e.src||new URL("server.cjs",document.baseURI).href,t=new URL(`./sanitizeWorker${ne.extname(Re.fileURLToPath(e))}`,e);if(!ie.existsSync(Re.fileURLToPath(t)))throw new Error(`[markdown-explorer] the HTML sanitizer worker is missing: ${Re.fileURLToPath(t)}`);return t},tt=new Map,Wr=(e,t)=>{const r=[e.href,t.workers,t.deadlineMs,t.workerHeapMb,t.jobsPerScope,t.maxQueuedJobs].map(String).join("\0");let n=tt.get(r);return n===void 0&&(n=Or({url:e,size:t.workers,deadlineMs:t.deadlineMs,jobsPerScope:t.jobsPerScope,maxQueuedJobs:t.maxQueuedJobs,heapLimits:{maxOldGenerationSizeMb:t.workerHeapMb,maxYoungGenerationSizeMb:Ir}}),tt.set(r,n)),n},Kr=e=>{if(e===null||typeof e!="object")return!1;const{status:t,html:r,message:n}=e;return t==="sanitized"&&typeof r=="string"||t==="too-large"||t==="error"&&typeof n=="string"},Vr=e=>e instanceof Error&&e.code==="ERR_WORKER_OUT_OF_MEMORY",Qr=({iframeHosts:e,dataPath:t,options:r,pool:n})=>{const a=Object.freeze([...e]),i=Ot(r),c=zr(r),m=Cr(r),y=St(Hr,{max:r.cacheBytes,of:(N,_)=>2*N.length+(_.status==="sanitized"?2*_.html.length:Gr)}),O=new Map,h=new Map,g=N=>{O.get(N.key)===N&&O.delete(N.key);const _=h.get(N.hash);_?.delete(N),_?.size===0&&h.delete(N.hash)},k=async(N,_,z)=>{const v=await n.run({html:N,iframeHosts:a,dataPath:t,maxNodes:i,maxAttributeChars:c,maxSanitizedChars:m},{scope:_,signal:z});if(v.status==="refused"){const C=v.limit==="scope"?`its reader already has ${String(r.jobsPerScope)} documents being sanitized or waiting`:`${String(r.maxQueuedJobs)} documents are already waiting`;return{outcome:{status:"rejected",reason:"failed",cause:new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${C}`)},lasting:!1}}if(v.status==="aborted")return{outcome:Pe,lasting:!1};if(v.status==="timeout")return{outcome:{status:"rejected",reason:"too-large",cause:new Error(`[markdown-explorer] the HTML sanitizer did not finish within ${String(r.deadlineMs)} ms`)},lasting:!0};if(v.status==="unavailable")return{outcome:{status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer worker could not start",{cause:v.error})},lasting:!1};if(v.status==="crashed"&&Vr(v.error))return{outcome:{status:"rejected",reason:"too-large",cause:new Error(`[markdown-explorer] the HTML sanitizer ran out of its ${String(r.workerHeapMb)} MiB worker heap`,{cause:v.error})},lasting:!0};if(v.status==="crashed")return{outcome:{status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer worker failed",{cause:v.error})},lasting:!0};const{output:I}=v;return Kr(I)?I.status==="too-large"?{outcome:et,lasting:!0}:I.status==="error"?{outcome:{status:"rejected",reason:"failed",cause:new Error(`[markdown-explorer] the HTML sanitizer failed: ${I.message}`)},lasting:!0}:I.html.length>m?{outcome:{status:"rejected",reason:"too-large",cause:new Error(`[markdown-explorer] the HTML sanitizer's output of ${String(I.html.length)} characters exceeds its limit of ${String(m)}`)},lasting:!0}:{outcome:{status:"sanitized",html:I.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}},A=(N,_,z,v)=>{let I=()=>{};const C=new Promise(E=>{I=E}),F={hash:_,key:z,outcome:C,answer:I,controller:new AbortController,waiters:0};O.set(z,F);const p=h.get(_);return p===void 0?h.set(_,new Set([F])):p.add(F),k(N,v,F.controller.signal).catch(E=>({outcome:{status:"rejected",reason:"failed",cause:E instanceof Error?E:new Error(String(E))},lasting:!0})).then(({outcome:E,lasting:b})=>{if(g(F),F.answer(E),!b)return;const R=y.get(_),S=R??(E.status==="rejected"?{...E,cause:null}:E);R===void 0&&y.set(_,S);for(const P of h.get(_)??[])g(P),P.answer(S),P.controller.abort()}),F},$=(N,_)=>new Promise(z=>{N.waiters+=1;const v=()=>{N.waiters-=1,z(Pe),!(N.waiters>0)&&(g(N),N.controller.abort())};_.addEventListener("abort",v,{once:!0}),N.outcome.then(I=>{_.removeEventListener("abort",v),z(I)})});return(N,{scope:_,signal:z})=>{if(N.length>r.maxHtmlBytes||Buffer.byteLength(N,"utf8")>r.maxHtmlBytes)return Promise.resolve(et);const v=wt.createHash("sha256").update(N,"utf8").digest("base64"),I=y.get(v);if(I!==void 0)return Promise.resolve(I);if(z.aborted)return Promise.resolve(Pe);const C=`${v}\0${_}`,F=O.get(C);return $(F===void 0?A(N,v,C,_):F,z)}},Oe=e=>({result:e,json:JSON.stringify(e)}),Ie=Object.freeze(Oe(Object.freeze({status:"error",failure:Object.freeze({reason:"failed"})}))),Zr=e=>e.status==="ok"&&e.entries.length>0,qr=({ttlMs:e,maxEntries:t,maxBytes:r,now:n})=>{const a=St(t,{max:r,of:(h,g)=>2*g.tree.json.length}),i=new Map,c=new Map,m=(h,g)=>{const k=new AbortController,A={waiters:0,superseded:!1,started:!1,loadTree:g},$=c.get(h),N=(C,F)=>{const p=Oe(C);return!(A.superseded||k.signal.aborted)&&Zr(C)&&a.set(h,{tree:p,loadedAt:F}),p},z=(async()=>{if($!==void 0&&await $,k.signal.aborted)return Ie;const C=n();return A.started=!0,N(await A.loadTree(k.signal,C),C)})().finally(()=>{i.get(h)===v&&i.delete(h)}),v={promise:z,controller:k,state:A};i.set(h,v);const I=z.then(()=>{},()=>{});return c.set(h,I),I.then(()=>{c.get(h)===I&&c.delete(h)}),v},y=(h,g,k)=>{g.state.waiters+=1;const A=()=>{g.state.waiters-=1,!(g.state.waiters>0)&&(i.get(h)===g&&i.delete(h),g.controller.abort())};return k.addEventListener("abort",A,{once:!0}),g.promise.finally(()=>{k.removeEventListener("abort",A)})},O=h=>{a.delete(h);const g=i.get(h);g?.state.started&&(g.state.superseded=!0,i.delete(h))};return{load:(h,g,k)=>{if(g.aborted)return Promise.resolve(Ie);const A=a.get(h);if(A!==void 0){if(n()-A.loadedAt<e)return Promise.resolve(A.tree);a.delete(h)}const $=i.get(h);return y(h,$===void 0?m(h,k):$,g)},refresh:(h,g,k)=>{if(g.aborted)return Promise.resolve(Ie);O(h);const A=i.get(h);return A===void 0?y(h,m(h,k),g):(A.state.loadTree=k,y(h,A,g))},forget:O}},en=e=>({load:(t,r,n)=>n(r,e()).then(Oe),refresh:(t,r,n)=>n(r,e()).then(Oe),forget:()=>{}}),x=e=>{throw new TypeError(`[markdown-explorer] ${e}`)},tn=e=>{if(e===null||typeof e!="object")return null;const{name:t,path:r}=e;return typeof t!="string"||typeof r!="string"?null:t===""?{path:r,reason:"an empty name"}:w.isAcceptableDocumentPath(r)?null:{path:r,reason:"a path the browser cannot address (empty, too long, a lone surrogate, a control character or a backslash)"}},rn=(e,t,r,n)=>{if(e===null)return null;if(!Array.isArray(e))throw new TypeError(`[markdown-explorer] a source's ancestors must be null or an array of folder paths; got ${typeof e}`);const a=new Set;for(const i of e){if(typeof i!="string"||!w.isAcceptableDocumentPath(i))throw new TypeError("[markdown-explorer] a source's ancestors held a path the explorer does not accept");if(r.deniesPath(i))throw new TypeError("[markdown-explorer] a source's ancestors held a denied path");if(!n(i))throw new TypeError("[markdown-explorer] a source's ancestors held a path outside the source's boundary");if(i===t)throw new TypeError("[markdown-explorer] a source's ancestors held the document itself");if(a.has(i))throw new TypeError("[markdown-explorer] a source's ancestors held a path twice");a.add(i)}return Object.freeze([...a])},nn=(e,t,r,n,a)=>{const i=new Set,c=y=>{if(!Array.isArray(y))return x("a source returned entries that are not an array");const O=[];for(const h of y){const g=m(h);g!==null&&O.push(g)}return O},m=y=>{const O=tn(y);if(O!==null)return n(O),null;const h=w.entryViolation(y);if(h!==null)return x(h);const g=y;if(i.has(g))return x("a source returned entries that contain themselves");const{name:k,path:A,type:$,mimeType:N,modifiedAt:_,children:z,lazy:v}=g;if(t.deniesName(k)||t.deniesPath(A))return null;if(!a(A))return n({path:A,reason:"a path outside the source's boundary"}),null;const I={name:k,path:A,...N===void 0?{}:{mimeType:N},..._===void 0?{}:{modifiedAt:_}};if($==="file")return{...I,type:$};if(v===!0)return r?{...I,type:$,lazy:!0,children:[]}:x("a lazy directory came from a source without a children function");if(z===void 0)return{...I,type:$};i.add(g);const C=c(z);return i.delete(g),{...I,type:$,children:C}};return c(e)},on=/^[\x21\x23-\x7E]{1,256}$/u,xt=e=>typeof e=="string"&&on.test(e),sn=new Set(["text","image","media","file"]),an=e=>typeof e=="string"&&sn.has(e),cn=(e,t,r)=>{if(e!==null&&typeof e=="object"){const i=e,{kind:c}=i;if(an(c)){if(Object.hasOwn(i,"url"))return x(`a ${c} document carries its version, not a url`);if(typeof i.name!="string")return x("a document needs a name string");if(!xt(i.version))return x(`a ${c} document needs a version of 1 to 256 visible ASCII characters other than '"'`);const m=t(i.version);switch(c){case"image":case"file":return{kind:c,name:i.name,url:m};case"media":{const{mediaType:y}=i;return w.isExplorerMediaType(y)?{kind:c,name:i.name,url:m,mediaType:y}:x(`unknown media type ${typeof y=="string"?JSON.stringify(y.slice(0,64)):typeof y}`)}case"text":return typeof i.text!="string"||typeof i.truncated!="boolean"?x("a text document needs text and truncated"):{kind:c,name:i.name,text:i.text,truncated:i.truncated,url:m}}}}const n=w.documentViolation(e);if(n!==null)return x(n);const a=e;switch(a.kind){case"failure":{const{reason:i,code:c}=a.failure;return{kind:"failure",failure:w.failureOf(i,c)}}case"markdown":return a.headings.length>w.EXPLORER_MAX_HEADINGS?{kind:"failure",failure:w.failureOf("too-large")}:a.edit?.kind==="inline"&&!r?x("a markdown document offers inline editing, but the server has no edit ports"):{kind:"unsanitized-markdown",name:a.name,html:a.htmlContent,headings:a.headings.map(({text:i,depth:c,id:m})=>({text:i,depth:c,id:m})),edit:un(a.edit)}}},un=e=>e===null?null:e.kind==="inline"?{kind:"inline"}:{kind:"external",href:e.href},ze=(e,t,r)=>typeof e!="string"?x(`${r} needs a text string`):e.includes("\0")?x(`${r} holds NUL, which no text editor can keep`):new TextEncoder().encode(e).byteLength>t?x(`${r} is over editMaxBytes (${t} bytes); refuse a longer source with ExplorerError "too-large"`):e,Rt=e=>w.isRootRelativeUrl(e.href)?{kind:"grant",href:e.href}:x("a grant needs a root-relative href"),ln=(e,t)=>{if(e===null||typeof e!="object")return x("an edit source must be an object");const r=e;return r.kind==="grant"?Rt(r):r.kind!=="edit"?x(`an edit source's kind must be "edit" or "grant"`):w.isExplorerEditToken(r.version)?typeof r.history!="boolean"?x("an edit source needs history"):{kind:"edit",text:ze(r.text,t,"an edit source"),version:r.version,history:r.history}:x("an edit source needs a version of 1 to 1024 characters")},dn=(e,t)=>{if(e===null||typeof e!="object")return x("a save result must be an object");const r=e;switch(r.kind){case"grant":return Rt(r);case"saved":return w.isExplorerEditToken(r.version)?{kind:"saved",version:r.version}:x("a saved result needs a version of 1 to 1024 characters");case"conflict":return w.isExplorerEditToken(r.version)?{kind:"conflict",version:r.version,text:ze(r.text,t,"a conflict's current text")}:x("a conflict needs the current version of 1 to 1024 characters");default:return x(`a save result's kind must be "saved", "conflict" or "grant"`)}},fn=e=>{if(e===null||typeof e!="object")return x("a preview must be an object");const{htmlContent:t,headings:r}=e;if(typeof t!="string"||!Array.isArray(r))return x("a preview needs htmlContent and headings");if(r.length>w.EXPLORER_MAX_HEADINGS)return{kind:"failure",failure:w.failureOf("too-large")};for(const n of r){const a=w.headingViolation(n);if(a!==null)return x(a)}return{html:t,headings:r.map(({text:n,depth:a,id:i})=>({text:n,depth:a,id:i}))}},mn=e=>{if(!Array.isArray(e))return x("revisions must be an array");const t=new Set;return e.map(r=>{const n=w.revisionViolation(r);if(n!==null)return x(n);const{id:a,modifiedAt:i,size:c,author:m,kept:y,current:O}=r;return t.has(a)?x(`two revisions share the id ${JSON.stringify(a.slice(0,64))}`):(t.add(a),{id:a,modifiedAt:i,size:c,author:m,kept:y,current:O})})},pn=(e,t)=>ze(e,t,"a revision"),rt=e=>{if(e===null||typeof e!="object")return x("an asset file must be an object");const{name:t,contentType:r,size:n,version:a,open:i}=e;return typeof t!="string"||t===""?x("an asset file needs a non-empty name"):typeof r!="string"?x("an asset file needs a contentType string ('' when unknown)"):n!==null&&!(typeof n=="number"&&Number.isSafeInteger(n)&&n>=0)?x("an asset file's size must be null or a non-negative safe integer"):xt(a)?typeof i!="function"?x("an asset file needs an open function"):Object.freeze({name:t,contentType:r,size:n,version:a,open:i}):x(`an asset file needs a version of 1 to 256 visible ASCII characters other than '"'`)},hn=e=>Array.isArray(e)?e.map(t=>{if(t===null||typeof t!="object")return x("a notice must be an object");const{id:r,tone:n,title:a,body:i,action:c}=t;if(typeof r!="string"||r===""||typeof a!="string")return x("a notice needs an id and a title");if(!w.isExplorerNoticeTone(n))return x(`unknown notice tone ${typeof n=="string"?JSON.stringify(n.slice(0,64)):typeof n}`);if(i!==void 0&&typeof i!="string")return x("a notice body must be a string");const y={id:r,tone:n,title:a,...i===void 0?{}:{body:i}};if(c===void 0)return y;if(c===null||typeof c!="object")return x("a notice action must be an object");const{label:O,href:h}=c;return typeof O!="string"||!w.isAcceptableUrl(h,w.EXPLORER_LINK_PROTOCOLS)?x("a notice action needs a label and an http(s), mailto or relative href"):{...y,action:{label:O,href:h}}}):x("notices must be an array"),wn=4e3,be=Object.freeze({ttlMs:3e5,maxEntries:64,maxBytes:64*1024*1024}),nt=32,_t="private, no-store",yn=Object.freeze({"Content-Type":"application/json; charset=utf-8","Cache-Control":_t,"X-Content-Type-Options":"nosniff","Content-Security-Policy":"default-src 'none'; frame-ancestors 'none'; sandbox","Cross-Origin-Resource-Policy":"same-origin"}),gn=22,En=2147483647,Me=Object.freeze([]),bn=Object.freeze({status:"ok",source:null,ancestors:null}),ot=Object.freeze(["contains","confirm"]),st=Object.freeze({readOnly:!1}),Tn=Object.freeze({readOnly:!0}),V=(e,t,r)=>{if(!(r&&t===void 0)&&typeof t!="function")throw new TypeError(`[markdown-explorer] ${e} must be a function; got ${typeof t}`)},pe=(e,t,r)=>{if(typeof t!="number")throw new TypeError(`[markdown-explorer] ${e} must be a number; got ${typeof t}`);if(!Number.isSafeInteger(t)||t<=0||t>r)throw new RangeError(`[markdown-explorer] ${e} must be an integer in 1..${String(r)}; got ${String(t)}`);return t},Sn=e=>{if(e===null||typeof e!="object"||!Object.isFrozen(e))throw new TypeError("[markdown-explorer] config must be the value returned by defineExplorerConfig");return se.revalidateExplorerConfig(e)},it=e=>{try{return new Headers(e)}catch{throw new TypeError("[markdown-explorer] authenticate returned headers that are not a valid headers init (their values are not logged)")}},at=e=>e instanceof Response?new TypeError(`[markdown-explorer] authenticate threw a Response (status ${String(e.status)}), which a data request does not follow`):e,kn=e=>{if(typeof e!="string")throw new TypeError(`[markdown-explorer] scopeSecret must be a string; got ${typeof e}`);if(e.length<nt)throw new RangeError(`[markdown-explorer] scopeSecret must have at least ${String(nt)} characters; got ${String(e.length)}`);return e},On=(e,t)=>{if(!se.isPlainObject(t))throw new TypeError(`[markdown-explorer] ${e}.boundary must be a plain object { contains, confirm? }`);for(const r of Object.keys(t))if(!ot.includes(r))throw new RangeError(`[markdown-explorer] ${e}.boundary.${r} is not an option; expected ${ot.join(", ")}`);V(`${e}.boundary.contains`,t.contains,!1),V(`${e}.boundary.confirm`,t.confirm,!0)},xn=e=>{if(!Array.isArray(e))throw new TypeError("[markdown-explorer] sources must be an array");const t=e;if(t.length===0)throw new RangeError("[markdown-explorer] sources must hold at least one source");const r=new Set;for(const[n,a]of t.entries()){if(a===null||typeof a!="object")throw new TypeError(`[markdown-explorer] sources[${String(n)}] must be an object`);const{id:i,label:c,boundary:m,tree:y,children:O,ancestors:h,cacheScope:g}=a;if(!se.isExplorerSourceId(i))throw new RangeError(`[markdown-explorer] sources[${String(n)}].id must use lowercase letters, digits and "-" and start with a letter or digit; got ${typeof i=="string"?JSON.stringify(i):typeof i}`);const k=`source ${JSON.stringify(i)}`;if(r.has(i))throw new RangeError(`[markdown-explorer] source ids must be unique; ${JSON.stringify(i)} repeats at sources[${String(n)}]`);if(r.add(i),typeof c!="string"&&typeof c!="function")throw new TypeError(`[markdown-explorer] ${k}.label must be a string or a function`);if(typeof c=="string"&&c.trim()==="")throw new RangeError(`[markdown-explorer] ${k}.label must not be blank`);if(On(k,m),V(`${k}.tree`,y,!1),V(`${k}.children`,O,!0),V(`${k}.ancestors`,h,!0),g!==void 0&&g!=="principal"&&g!=="shared")throw new RangeError(`[markdown-explorer] ${k}.cacheScope must be "principal" or "shared"; got ${JSON.stringify(g)}`)}return t},Rn=e=>{if(e===!1)return!1;if(e===void 0)return be;if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] treeCache must be { ttlMs, maxEntries, maxBytes } or false");const{ttlMs:t,maxEntries:r,maxBytes:n}=e;return{ttlMs:t===void 0?be.ttlMs:pe("treeCache.ttlMs",t,Number.MAX_SAFE_INTEGER),maxEntries:r===void 0?be.maxEntries:pe("treeCache.maxEntries",r,Number.MAX_SAFE_INTEGER),maxBytes:n===void 0?be.maxBytes:pe("treeCache.maxBytes",n,Number.MAX_SAFE_INTEGER)}},ct=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] authenticate must resolve to { status, ... }");const{status:t}=e;if(t!=="signed-in"&&t!=="signed-out"&&t!=="forbidden")throw new TypeError(`[markdown-explorer] authenticate resolved to an unknown status ${JSON.stringify(t)}`);return e},ut=(e,t)=>{if(!(t instanceof Response))throw new TypeError(`[markdown-explorer] ${e} must return a Response`);return t},lt=(e,t)=>{if(typeof t!="string"||t==="")throw new TypeError("[markdown-explorer] principalKey must return a non-empty string");return wt.createHmac("sha256",e).update(t,"utf8").digest("base64url").slice(0,gn)},_n=e=>e.view==="multi"?e.docs:e.doc===null?[]:[e.doc],ue=(e,t)=>{const r=e.getAll(t),[n]=r;return r.length===1&&n!==void 0&&n!==""?n:null},K=(e,t,r,n={})=>{const a=new Headers(r);for(const[i,c]of Object.entries({...yn,...n}))a.set(i,c);return new Response(t,{status:e,headers:a})},j=(e,t,r)=>K(w.EXPLORER_FAILURE_STATUS[e.reason],JSON.stringify({failure:e}),t,r),An=new Set(["refresh","save","preview"]),vn=new Set(["edit","save","preview","revisions","revision"]),dt=(e,t)=>{const r=An.has(t)?["POST"]:["GET","HEAD"];return r.includes(e.method.toUpperCase())?null:K(405,JSON.stringify({failure:{reason:"invalid"}}),void 0,{Allow:r.join(", ")})},ft=e=>e.headers.get(w.EXPLORER_PROOF_HEADER)===w.EXPLORER_REFRESH_PROOF&&ke.crossOriginRefusal(e,ke.NO_CROSS_ORIGIN_NAVIGATION)===void 0,Nn=e=>e.headers.get(w.EXPLORER_PROOF_HEADER)===w.EXPLORER_EDIT_PROOF&&ke.crossOriginRefusal(e,ke.NO_CROSS_ORIGIN_NAVIGATION)===void 0,Pn=async(e,t)=>{const[r,...n]=(e.headers.get("Content-Type")??"").split(";").map(k=>k.trim().toLowerCase()),a=n.find(k=>k.startsWith("charset="));if(r!==w.EXPLORER_DRAFT_MEDIA_TYPE||a!==void 0&&a!=="charset=utf-8")return{status:"error",failure:{reason:"invalid"}};const i=Number(e.headers.get("Content-Length")??"0");if(Number.isFinite(i)&&i>t)return{status:"error",failure:{reason:"too-large"}};if(e.body===null)return{status:"ok",text:""};const c=e.body.getReader(),m=[];let y=0;for(;;){const{done:k,value:A}=await c.read();if(k)break;if(y+=A.byteLength,y>t)return await c.cancel(),{status:"error",failure:{reason:"too-large"}};m.push(A)}const O=new Uint8Array(y);let h=0;for(const k of m)O.set(k,h),h+=k.byteLength;let g;try{g=new TextDecoder("utf-8",{fatal:!0}).decode(O)}catch{return{status:"error",failure:{reason:"invalid"}}}return g.includes("\0")?{status:"error",failure:{reason:"invalid"}}:{status:"ok",text:g}},In=e=>{if(e===void 0)return;if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] edit must be an object of the editor's ports");const t=e;for(const r of["source","save","preview","revisions","revision"])V(`edit.${r}`,t[r],!1);return e},Mn=({parentHeaders:e,loaderHeaders:t,errorHeaders:r})=>{const n=new Headers,a=r===void 0?[e,t]:[e,t,r];for(const i of a)for(const[c,m]of i)c!=="set-cookie"&&n.set(c,m);return n},Ln=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] the server configuration must be an object");const t=Sn(e.config),r=kn(e.scopeSecret);V("authenticate",e.authenticate,!1),V("principalKey",e.principalKey,!1),V("document",e.document,!1),V("asset",e.asset,!1),V("signedOutPage",e.signedOutPage,!1),V("forbiddenPage",e.forbiddenPage,!0),V("notices",e.notices,!0),V("onTreeRefreshed",e.onTreeRefreshed,!0);const n=xn(e.sources),a=se.withExplorerSources(t,n.map(o=>o.id)),i=e.logger;if(i!==void 0&&(i===null||typeof i!="object"||typeof i.error!="function"))throw new TypeError("[markdown-explorer] logger must be an object with an error function");const c=e.logger===void 0?hr:e.logger,m=w.resolvePathRules(e.deny),y=e.deferredTimeoutMs===void 0?wn:pe("deferredTimeoutMs",e.deferredTimeoutMs,En),O=e.textMaxBytes===void 0?Ke:pe("textMaxBytes",e.textMaxBytes,Ve),h=In(e.edit);if(h===void 0&&e.editMaxBytes!==void 0)throw new TypeError("[markdown-explorer] editMaxBytes needs the edit ports");const g=e.editMaxBytes===void 0?Ke:pe("editMaxBytes",e.editMaxBytes,Ve),k=Rn(e.treeCache),A=()=>Date.now(),$=k===!1?en(A):qr({...k,now:A}),N=Jr(e.sanitizer,t.multiView.maxPanels),_=Qr({iframeHosts:t.iframeHosts,dataPath:t.dataPath,options:N,pool:Wr(Yr(),N)}),z=new Map(n.map(o=>[o.id,o])),v=se.documentStyleNames(t),{authenticate:I,principalKey:C,signedOutPage:F,forbiddenPage:p,onTreeRefreshed:E}=e,b=(o,u)=>{if(typeof o.label=="string")return o.label;const s=o.label(u);if(typeof s!="string"||s.trim()==="")throw new TypeError(`[markdown-explorer] the label of source ${JSON.stringify(o.id)} must be a non-blank string`);return s},R=(o,u)=>o.cacheScope==="shared"?o.id:`${o.id}\0${u}`,S=(o,u)=>{const s=d=>oe(c,{operation:"boundary",sourceId:o.id,path:u,error:d});let l;try{l=o.boundary.contains(u)}catch(d){return s(d),!1}return typeof l=="boolean"?l:(We(l,s),s(new TypeError(`[markdown-explorer] boundary.contains of source ${JSON.stringify(o.id)} must return a boolean; got ${typeof l}`)),!1)},P=async(o,u,s)=>{const{confirm:l}=o.boundary;if(l===void 0)return{status:"inside",readPath:s};let d;try{d=await l(u,s)}catch(U){return{status:"error",failure:Y(U,{operation:"boundary",sourceId:o.id,path:s},u.signal,c)}}const f=U=>(oe(c,{operation:"boundary",sourceId:o.id,path:s,error:new TypeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} ${U}`)}),{status:"outside"});if(d===null||typeof d!="object")return f(`must resolve to { inside, readPath? }; got ${d===null?"null":typeof d}`);const{inside:T,readPath:M}=d;return T===!1?{status:"outside"}:T!==!0||typeof M!="string"?f("must resolve to { inside: false } or { inside: true, readPath: string }"):!w.isAcceptableDocumentPath(M)||m.deniesPath(M)?(oe(c,{operation:"boundary",sourceId:o.id,path:s,error:new RangeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} answered a readPath the explorer does not serve (unacceptable or denied)`)}),{status:"error",failure:{reason:"failed"}}):{status:"inside",readPath:M}},L=async(o,u)=>{const s=n.filter(d=>S(d,u));if(s.length===0)return{status:"error",failure:{reason:"forbidden"}};if(s.some(d=>d.boundary.confirm===void 0))return{status:"inside",readPath:u};let l=null;for(const d of s){const f=await P(d,o,u);if(f.status==="inside")return f;f.status==="error"&&l===null&&(l=f.failure)}return{status:"error",failure:l===null?{reason:"forbidden"}:l}},X=(o,u,s)=>{const l=({path:d,reason:f})=>gr(c,{operation:s.operation,sourceId:s.sourceId,path:d,error:new TypeError(`[markdown-explorer] an entry with ${f} was left out`)});try{return{status:"ok",entries:nn(o,m,u.children!==void 0,l,d=>S(u,d))}}catch(d){return oe(c,{...s,error:d}),{status:"error",failure:{reason:"failed"}}}},D=async(o,u,s)=>{let l;try{l=await o.tree(u)}catch(f){return{status:"error",failure:Y(f,{operation:"tree",sourceId:o.id},u.signal,c)}}const d=X(l,o,{operation:"tree",sourceId:o.id});return d.status==="ok"?{status:"ok",entries:d.entries,loadedAt:s}:d},G=(o,u,s,l)=>(d,f)=>D(o,{principal:u,request:s,signal:d,refresh:l},f),Q=(o,u,s,l,d)=>$.load(R(o,s),d,G(o,u,l,!1)),J=(o,u,s,l)=>$.refresh(R(o,s),l.signal,G(o,u,l,!0)),ae=(o,u)=>{if(E===void 0)return;const s=l=>oe(c,{operation:"refresh",sourceId:o.id,error:l});try{We(E(u),s)}catch(l){s(l)}},H=async(o,u,s,l)=>{if(m.deniesPath(l)||!S(o,l))return{status:"error",failure:{reason:"forbidden"}};const d=await P(o,s,l);if(d.status==="outside")return{status:"error",failure:{reason:"forbidden"}};if(d.status==="error")return{status:"error",failure:d.failure};let f;try{f=await u(s,l,d.readPath)}catch(T){return{status:"error",failure:Y(T,{operation:"children",sourceId:o.id,path:l},s.signal,c)}}return X(f,o,{operation:"children",sourceId:o.id,path:l})},Z=async(o,u,s,l)=>{const d=await P(o,s,l);if(d.status==="outside")return{status:"ok",ancestors:null};if(d.status==="error")return{status:"error",failure:d.failure};let f;try{f=await u(s,l,d.readPath,{maxDepth:t.revealDocument.maxDepth})}catch(T){return{status:"error",failure:Y(T,{operation:"ancestors",sourceId:o.id,path:l},s.signal,c)}}if(Array.isArray(f)&&f.length>t.revealDocument.maxDepth)return{status:"ok",ancestors:null};try{return{status:"ok",ancestors:rn(f,l,m,T=>S(o,T))}}catch(T){return oe(c,{operation:"ancestors",sourceId:o.id,path:l,error:T}),{status:"error",failure:{reason:"failed"}}}},q=async(o,u,s,l)=>m.deniesPath(l)?{status:"error",failure:{reason:"forbidden"}}:S(o,l)?Z(o,u,s,l):{status:"ok",ancestors:null},ee=async(o,u,s)=>{if(m.deniesPath(s))return{status:"error",failure:{reason:"forbidden"}};for(const l of[o,...n.filter(d=>d!==o)]){if(u.signal.aborted)break;const d=l.ancestors;if(d===void 0||!S(l,s))continue;const f=await Z(l,d,u,s);if(f.status==="ok"&&f.ancestors!==null)return{status:"ok",source:l.id,ancestors:f.ancestors}}return bn},ce=async(o,u,s)=>{if(m.deniesPath(s))return w.failureDocument("forbidden");const l=await L(o,s);if(l.status==="error")return{kind:"failure",failure:l.failure};let d;try{d=await e.document(o,s,l.readPath)}catch(M){return{kind:"failure",failure:Y(M,{operation:"document",path:s},o.signal,c)}}let f;try{f=cn(d,M=>w.explorerAssetHref(t.dataPath,s,M),h!==void 0)}catch(M){return oe(c,{operation:"document",path:s,error:M}),w.failureDocument("failed")}if(f.kind!=="unsanitized-markdown")return f;const T=await _(f.html,{scope:u,signal:o.signal});return T.status==="sanitized"?{kind:"markdown",name:f.name,htmlContent:T.html,headings:f.headings,edit:f.edit}:(T.cause!==null&&oe(c,{operation:"document",path:s,error:T.cause}),w.failureDocument(T.reason))},ge=async o=>{if(e.notices===void 0)return Me;try{return hn(await e.notices(o))}catch(u){return Y(u,{operation:"notices"},o.signal,c),Me}},Lt=async(o,u,s)=>{const l=ue(u,w.EXPLORER_DATA_QUERY.path);if(l===null||!w.isAcceptableDocumentPath(l))return j({reason:"invalid"},s);const d=w.readExplorerAssetDisplay(u);if(d===null)return j({reason:"invalid"},s);if(m.deniesPath(l))return Ne(c,{operation:"asset",path:l}),j({reason:"forbidden"},s);const f=await L(o,l);if(f.status==="error")return j(f.failure,s);try{const T=rt(await e.asset(o,l,f.readPath));return await pr(o.request,T,s,d)}catch(T){return j(Y(T,{operation:"asset",path:l},o.signal,c),s)}},Dt=async(o,u)=>{if(m.deniesPath(u))return Ne(c,{operation:"text",path:u}),w.failureDocument("forbidden");const s=await L(o,u);if(s.status==="error")return{kind:"failure",failure:s.failure};try{const l=rt(await e.asset(o,u,s.readPath)),d=await br(l,O);return d===null?w.failureDocument("unsupported"):{kind:"text",name:l.name,text:d.text,truncated:d.truncated,url:w.explorerAssetHref(t.dataPath,u,l.version)}}catch(l){return{kind:"failure",failure:Y(l,{operation:"text",path:u},o.signal,c)}}},he=async(o,u,s)=>m.deniesPath(s)?(Ne(c,{operation:u,path:s}),{status:"error",failure:{reason:"forbidden"}}):L(o,s),$t=async(o,u,s)=>{const l=await he(u,"edit",s);if(l.status==="error")return{kind:"failure",failure:l.failure};try{return ln(await o.source(u,s,l.readPath),g)}catch(d){return{kind:"failure",failure:Y(d,{operation:"edit",path:s},u.signal,c)}}},jt=async(o,u,s,l,d)=>{const f=await he(u,"save",s);if(f.status==="error")return{kind:"failure",failure:f.failure};try{return dn(await o.save(u,s,f.readPath,{text:d,baseVersion:l}),g)}catch(T){return{kind:"failure",failure:Y(T,{operation:"save",path:s},u.signal,c)}}},zt=async(o,u,s,l,d)=>{const f=await he(u,"preview",l);if(f.status==="error")return{kind:"failure",failure:f.failure};let T;try{T=fn(await o.preview(u,l,f.readPath,d))}catch(U){return{kind:"failure",failure:Y(U,{operation:"preview",path:l},u.signal,c)}}if("kind"in T)return T.kind==="failure"?T:w.failureDocument("failed");const M=await _(T.html,{scope:s,signal:u.signal});return M.status==="sanitized"?{kind:"preview",htmlContent:M.html,headings:T.headings}:(M.cause!==null&&oe(c,{operation:"preview",path:l,error:M.cause}),w.failureDocument(M.reason))},Ct=async(o,u,s)=>{const l=await he(u,"revisions",s);if(l.status==="error")return{kind:"failure",failure:l.failure};try{return{kind:"revisions",revisions:mn(await o.revisions(u,s,l.readPath))}}catch(d){return{kind:"failure",failure:Y(d,{operation:"revisions",path:s},u.signal,c)}}},Ht=async(o,u,s,l)=>{const d=await he(u,"revision",s);if(d.status==="error")return{kind:"failure",failure:d.failure};try{return{kind:"revision",id:l,text:pn(await o.revision(u,s,d.readPath,l),g)}}catch(f){return{kind:"failure",failure:Y(f,{operation:"revision",path:s},u.signal,c)}}},Bt=async(o,u,s,l,d,f)=>{const T=ue(d,w.EXPLORER_DATA_QUERY.path);if(T===null||!w.isAcceptableDocumentPath(T))return j({reason:"invalid"},f);if(u==="edit")return K(200,JSON.stringify(await $t(o,s,T)),f);if(u==="revisions")return K(200,JSON.stringify(await Ct(o,s,T)),f);if(u==="revision"){const te=ue(d,w.EXPLORER_DATA_QUERY.revision);return w.isExplorerEditToken(te)?K(200,JSON.stringify(await Ht(o,s,T,te)),f):j({reason:"invalid"},f)}const M=ue(d,w.EXPLORER_DATA_QUERY.base);if(u==="save"&&!w.isExplorerEditToken(M))return j({reason:"invalid"},f);const U=await Pn(s.request,g);return U.status==="error"?j(U.failure,f):u==="preview"?K(200,JSON.stringify(await zt(o,s,l,T,U.text)),f):K(200,JSON.stringify(await jt(o,s,T,M,U.text)),f)},Ft=async({request:o,url:u,params:s})=>{const l=ct(await I(o,st)),d=it(l.headers);if(d.set("Cache-Control",_t),l.status==="signed-out")throw ut("signedOutPage",F(o,d));if(l.status==="forbidden")throw p===void 0?xe.data(null,{status:403,headers:d}):ut("forbiddenPage",p(o,d));const f=se.resolveExplorerLocation(a,s["*"],u.searchParams);if(f.kind==="redirect")throw xe.redirect(f.href,{headers:d});const{location:T}=f,{principal:M}=l,U=lt(r,C(M)),te=z.get(T.source);if(te===void 0)throw new RangeError(`[markdown-explorer] no source for ${JSON.stringify(T.source)}`);const we={signal:o.signal,timeoutMs:y,late:null,handOverMs:y},re={scope:U,sources:n.map(B=>({id:B.id,label:b(B,M)})),settings:se.parseViewSettings(se.readCookieValue(o.headers.get("Cookie"),t.settingsCookie),v),tree:T.view==="single"?null:{sourceId:T.source,result:ve(we,B=>Q(te,M,U,o,B).then(W=>W.result))},documents:_n(T).map(B=>({path:B,document:ve(we,W=>ce({principal:M,request:o,signal:W,refresh:!1},U,B))})),notices:ve({signal:o.signal,timeoutMs:y,late:Me,handOverMs:0},B=>ge({principal:M,request:o,signal:B,refresh:!1}))};return xe.data(re,{headers:d})},Ce=async(o,u)=>{const s=ct(await I(o,u));return{authentication:s,headers:it(s.headers)}},Ut=async(o,u,s)=>{let l;try{l=await Ce(u,st)}catch(W){return j(Y(at(W),{operation:"authenticate"},u.signal,c))}const{authentication:d,headers:f}=l;if(d.status==="signed-out")return j({reason:"unauthorized"},f);if(d.status==="forbidden")return j({reason:"forbidden"},f);const{principal:T}=d;if(o==="asset")return Lt({principal:T,request:u,signal:u.signal,refresh:!1},s,f);const M=lt(r,C(T));f.set(w.EXPLORER_SCOPE_HEADER,M);const U={principal:T,request:u,signal:u.signal,refresh:!1},te=()=>j({reason:"invalid"},f);if(o==="document"){const W=ue(s,w.EXPLORER_DATA_QUERY.path);if(W===null||!w.isAcceptableDocumentPath(W))return te();const Fe=u.headers.has(w.EXPLORER_PROOF_HEADER);return Fe&&!ft(u)?j({reason:"forbidden"},f):K(200,JSON.stringify(await ce({...U,refresh:Fe},M,W)),f)}if(o==="text"){const W=ue(s,w.EXPLORER_DATA_QUERY.path);return W===null||!w.isAcceptableDocumentPath(W)?te():K(200,JSON.stringify(await Dt(U,W)),f)}if(o==="edit"||o==="save"||o==="preview"||o==="revisions"||o==="revision")return h===void 0?j({reason:"not-found"},f):Bt(h,o,U,M,s,f);const we=ue(s,w.EXPLORER_DATA_QUERY.source),re=ue(s,w.EXPLORER_DATA_QUERY.path);if(we===null||(o==="children"||o==="ancestors"||o==="reveal")&&(re===null||!w.isAcceptableDocumentPath(re)))return te();const B=z.get(we);if(B===void 0)return j({reason:"not-found"},f);if(o==="tree")return K(200,(await Q(B,T,M,u,u.signal)).json,f);if(o==="refresh"){const W=await J(B,T,M,u);return u.signal.aborted||ae(B,R(B,M)),K(200,W.json,f)}return o==="ancestors"?B.ancestors===void 0||re===null?j({reason:"not-found"},f):K(200,JSON.stringify(await q(B,B.ancestors,U,re)),f):o==="reveal"?re===null?te():K(200,JSON.stringify(await ee(B,U,re)),f):B.children===void 0||re===null?j({reason:"not-found"},f):K(200,JSON.stringify(await H(B,B.children,U,re)),f)},Xt=async o=>{const{authentication:u,headers:s}=await Ce(o,Tn);if(!s.keys().next().done)throw new TypeError("[markdown-explorer] authenticate returned headers in read-only mode; a read-only authentication must only read the session (none was forwarded)");return u.status==="signed-in"},He=t.embeds.linkCardEndpoint===null?null:Jt.createLinkCardHandler({authorize:Xt}),Gt=async(o,u)=>{try{return await o(u)}catch(s){return j(Y(at(s),{operation:"authenticate"},u.signal,c))}},Be=async(o,u,s)=>{if(new URL(o.url).pathname.endsWith(".data"))return j({reason:"not-found"});if(!w.isExplorerDataOperation(s))return j({reason:"not-found"});if(s==="link-card"){if(He===null)return j({reason:"not-found"});const d=dt(o,s);return d!==null?d:Gt(He,o)}if(vn.has(s)&&h===void 0)return j({reason:"not-found"});const l=dt(o,s);if(l!==null)return l;if(s==="refresh"&&!ft(o))return j({reason:"forbidden"});if((s==="save"||s==="preview")&&!Nn(o))return j({reason:"forbidden"});try{return await Ut(s,o,u.searchParams)}catch(d){return j(Y(d,{operation:s},o.signal,c))}};return Object.freeze({loader:Ft,headers:Mn,dataLoader:({request:o,url:u,params:s})=>Be(o,u,s["*"]),dataAction:({request:o,url:u,params:s})=>Be(o,u,s["*"]),forgetTree:o=>{if(typeof o!="string")throw new TypeError(`[markdown-explorer] forgetTree needs the string key onTreeRefreshed received; got ${typeof o}`);$.forget(o)}})},Te=Object.freeze({maxEntries:2e4,maxDocumentBytes:2*1024*1024,textPreviewBytes:8*1024,walkConcurrency:8}),Dn=new Set(["md","markdown","mdx"]),At=new Map([...[["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"],["svg","image/svg+xml"],["webp","image/webp"],["ico","image/x-icon"],["bmp","image/bmp"],["tif","image/tiff"],["tiff","image/tiff"],["avif","image/avif"]].map(([e,t])=>[e,{kind:"image",contentType:t}]),...[["mp4","video/mp4"],["m4v","video/mp4"],["webm","video/webm"],["mov","video/quicktime"],["avi","video/x-msvideo"],["mkv","video/x-matroska"],["ogv","video/ogg"]].map(([e,t])=>[e,{kind:"media",mediaType:"video",contentType:t}]),...[["mp3","audio/mpeg"],["wav","audio/wav"],["ogg","audio/ogg"],["oga","audio/ogg"],["opus","audio/ogg"],["m4a","audio/mp4"],["flac","audio/flac"],["aac","audio/aac"],["wma","audio/x-ms-wma"]].map(([e,t])=>[e,{kind:"media",mediaType:"audio",contentType:t}]),["pdf",{kind:"media",mediaType:"pdf",contentType:"application/pdf"}]]),$n=new Set(["txt","text","log","csv","tsv","json","jsonc","json5","ndjson","yaml","yml","toml","ini","cfg","conf","properties","xml","xsl","xsd","dtd","html","htm","xhtml","css","scss","sass","less","styl","js","mjs","cjs","jsx","ts","mts","cts","tsx","vue","svelte","astro","py","pyi","rb","go","rs","java","kt","kts","scala","groovy","gradle","c","h","cc","cpp","cxx","hpp","hh","hxx","cs","fs","vb","swift","m","mm","php","pl","pm","r","jl","lua","dart","ex","exs","erl","hrl","hs","ml","mli","clj","cljs","elm","nim","zig","v","sol","tf","hcl","nix","sh","bash","zsh","fish","ps1","psm1","bat","cmd","sql","graphql","gql","proto","thrift","avsc","rst","adoc","asciidoc","tex","bib","org","textile","diff","patch","srt","vtt","ics","vcf","gitignore","gitattributes","editorconfig","dockerignore","npmignore","prettierrc","eslintrc","babelrc","mailmap"]),jn=new Set(["readme","license","licence","copying","notice","authors","contributors","changelog","changes","todo","makefile","dockerfile","containerfile","procfile","gemfile","rakefile","vagrantfile","jenkinsfile","brewfile","codeowners"]),vt=typeof ie.constants.O_NOFOLLOW=="number"?ie.constants.O_NOFOLLOW:0,Nt=typeof ie.constants.O_NONBLOCK=="number"?ie.constants.O_NONBLOCK:0,mt=e=>`${e.size}-${e.mtimeNs}`,zn=e=>e!==""&&e!=="."&&e!==".."&&!e.includes(":")&&!e.endsWith(".")&&!e.endsWith(" "),pt=e=>w.isAcceptableDocumentPath(e)&&e===e.normalize("NFC")&&e.split("/").every(zn),Pt=e=>{const t=e.toLowerCase(),r=t.lastIndexOf(".");return r<0?"":t.slice(r+1)},Cn=e=>{const t=Pt(e);if(Dn.has(t))return{kind:"markdown"};const r=At.get(t);if(r!==void 0)return r.kind==="image"?{kind:"image"}:{kind:"media",mediaType:r.mediaType};const n=e.toLowerCase();return $n.has(t)||!n.includes(".")&&jn.has(n)?{kind:"text"}:{kind:"file"}},De=e=>{switch(typeof e=="object"&&e!==null?e.code:void 0){case"ENOENT":case"ENOTDIR":return"not-found";case"ELOOP":case"EACCES":case"EPERM":return"forbidden";case"ENAMETOOLONG":return"invalid";case"EISDIR":return"unsupported";default:return null}},It=e=>{const t=De(e);return t===null?e:new ye(t)},Mt=e=>{const t=typeof e=="object"&&e!==null?e.code:void 0;return t==="EACCES"||t==="EPERM"||t==="ENOENT"||t==="ENOTDIR"},Hn=async e=>{try{return Math.trunc((await me.lstat(e)).mtimeMs)}catch(t){if(Mt(t))return;throw t}},ht=async(e,t)=>{const r=[];for await(const n of e.createReadStream({start:0,end:t-1,autoClose:!1}))r.push(n);return Buffer.concat(r)},Bn=(e,t)=>e!==null?{start:e.offset,end:e.offset+e.length-1}:t===0n?{}:{start:0,end:Number(t)-1},Fn=async(e,t,r,n)=>{let a;try{a=await me.open(e,ie.constants.O_RDONLY|vt|Nt);const y=await a.stat({bigint:!0});if(!y.isFile()||y.ino!==t.ino||y.dev!==t.dev||y.size!==t.size||y.mtimeNs!==t.mtimeNs)throw new ye("not-found")}catch(y){throw await a?.close(),It(y)}const i=a.createReadStream(Bn(r,t.size)),c=Wt.Readable.toWeb(i),m=()=>{i.destroy(n.reason)};return n.aborted?m():n.addEventListener("abort",m,{once:!0}),c},Un=(e,t)=>{const r=se.NAME_COLLATOR.compare(e,t);return r!==0?r:e===t?0:e<t?-1:1},Xn=e=>{let t=0;const r=[];return async n=>{t<e?t+=1:await new Promise(a=>r.push(a));try{return await n()}finally{const a=r.shift();a===void 0?t-=1:a()}}},Gn=(e,t)=>{if(e.isSymbolicLink())return"symbolic-link";if(!(e.isDirectory()||e.isFile()))return"special-file";const{name:r}=e;return r!==r.normalize("NFC")?"not-nfc":r.includes(":")?"colon":r.endsWith(".")||r.endsWith(" ")?"trailing-dot-or-space":w.isAcceptableDocumentPath(r)?w.isAcceptableDocumentPath(t)?null:"path-too-long":"control-character-or-backslash"},Jn=new Set(["id","label","root","pathPrefix","parse","deny","maxEntries","maxDocumentBytes","textPreviewBytes","walkConcurrency","cacheScope","reportSkipped"]),Se=(e,t,r)=>{if(t===void 0)return r;if(typeof t!="number"||!Number.isSafeInteger(t)||t<=0)throw new RangeError(`[markdown-explorer] ${e} must be a positive integer; got ${String(t)}`);return t},Yn=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] createFileSystemSource needs an options object");for(const b of Object.keys(e))if(!Jn.has(b))throw new TypeError(`[markdown-explorer] createFileSystemSource does not know the option ${JSON.stringify(b)}`);const{id:t,label:r,root:n,parse:a}=e;if(typeof t!="string"||t==="")throw new TypeError("[markdown-explorer] a file-system source needs a non-empty id");if(typeof r!="string"||r.trim()==="")throw new TypeError("[markdown-explorer] a file-system source needs a non-blank label");if(typeof a!="function")throw new TypeError("[markdown-explorer] a file-system source needs a parse function");if(typeof n!="string"||!ne.isAbsolute(n))throw new RangeError(`[markdown-explorer] root must be an absolute path; got ${JSON.stringify(n)}`);let i;try{i=ie.statSync(n).isDirectory()}catch(b){throw new RangeError(`[markdown-explorer] root does not exist: ${n}`,{cause:b})}if(!i)throw new RangeError(`[markdown-explorer] root is not a directory: ${n}`);const c=ie.realpathSync(n),m=e.pathPrefix;if(typeof m!="string")throw new TypeError('[markdown-explorer] pathPrefix is required: "" for a source over the whole root, or relative segments ending with "/"');if(m!==""&&!(m.endsWith("/")&&pt(m.slice(0,-1))))throw new RangeError(`[markdown-explorer] pathPrefix must be empty or relative segments ending with "/"; got ${JSON.stringify(m)}`);const y=w.resolvePathRules(e.deny),O=Se("maxEntries",e.maxEntries,Te.maxEntries),h=Se("maxDocumentBytes",e.maxDocumentBytes,Te.maxDocumentBytes),g=Se("textPreviewBytes",e.textPreviewBytes,Te.textPreviewBytes),k=Se("walkConcurrency",e.walkConcurrency,Te.walkConcurrency),A=e.cacheScope===void 0?"principal":e.cacheScope;if(A!=="principal"&&A!=="shared")throw new RangeError(`[markdown-explorer] cacheScope must be "principal" or "shared"; got ${JSON.stringify(A)}`);const $=e.reportSkipped;if($!==void 0&&typeof $!="function")throw new TypeError("[markdown-explorer] reportSkipped must be a function");const N=$===void 0?b=>{console.warn(`[markdown-explorer] the file-system source ${JSON.stringify(b.sourceId)} does not list ${JSON.stringify(b.path)}: ${b.reason}`)}:$,_=new Set,z=b=>{const R=ne.resolve(c,...b.split("/")),S=ne.relative(c,R);return S===""||S===".."||S.startsWith(`..${ne.sep}`)||ne.isAbsolute(S)?null:R},v=(b,R)=>{const S=`${R}\0${b}`;_.has(S)||_.size>=O||(_.add(S),N({sourceId:t,path:b,reason:R}))},I=async({signal:b})=>{b.throwIfAborted();const R=new AbortController,S=()=>{R.abort(b.reason)};b.addEventListener("abort",S,{once:!0});const P=Xn(k);let L=0;const X=async(D,G)=>{const Q=await P(async()=>{R.signal.throwIfAborted();try{return await me.readdir(D,{withFileTypes:!0})}catch(H){if(G===""||!Mt(H))throw H;return null}});if(R.signal.throwIfAborted(),Q===null)return v(`${m}${G}`,"unreadable-directory"),null;const J=[];for(const H of Q){if(y.deniesName(H.name))continue;const Z=G===""?H.name:`${G}/${H.name}`,q=`${m}${Z}`,ee=Gn(H,q);if(ee!==null){v(q,ee);continue}J.push({dirent:H,relativePath:Z,path:q})}if(L+=J.length,L>O)throw new ye("too-large");return J.sort((H,Z)=>Un(H.dirent.name,Z.dirent.name)),(await Promise.all(J.map(async({dirent:H,relativePath:Z,path:q})=>{const ee=await Hn(ne.join(D,H.name)),ce=ee===void 0?{}:{modifiedAt:ee};if(!H.isDirectory())return{name:H.name,path:q,type:"file",...ce};const ge=await X(ne.join(D,H.name),Z);return ge===null?null:{name:H.name,path:q,type:"directory",...ce,children:ge}}))).filter(H=>H!==null)};try{const D=await X(c,"");if(D===null)throw new Error("[markdown-explorer] the source's root could not be listed");return D}catch(D){throw R.abort(),D}finally{b.removeEventListener("abort",S)}},C=async b=>{if(!b.startsWith(m))return{status:"refused",reason:"not-found"};const R=b.slice(m.length);if(!pt(R))return{status:"refused",reason:"invalid"};if(y.deniesPath(R))return{status:"refused",reason:"forbidden"};const S=z(R);if(S===null)return{status:"refused",reason:"forbidden"};const P=await me.lstat(S,{bigint:!0});if(P.isSymbolicLink())return{status:"refused",reason:"forbidden"};if(!P.isFile())return{status:"refused",reason:"unsupported"};const L=await me.realpath(S);return L!==S||y.deniesPath(ne.relative(c,L).split(ne.sep).join("/"))?{status:"refused",reason:"forbidden"}:{status:"file",target:S,name:R.slice(R.lastIndexOf("/")+1),stats:P}},F=async(b,R,S)=>{let P;try{const L=await C(S);if(L.status==="refused")return w.failureDocument(L.reason);const{target:X,name:D,stats:G}=L,Q=Cn(D),J=mt(G);if(Q.kind==="image")return{kind:"image",name:D,version:J};if(Q.kind==="media")return{kind:"media",name:D,mediaType:Q.mediaType,version:J};if(Q.kind==="file")return{kind:"file",name:D,version:J};P=await me.open(X,ie.constants.O_RDONLY|vt|Nt);const ae=await P.stat({bigint:!0});if(!ae.isFile()||ae.ino!==G.ino||ae.dev!==G.dev)return w.failureDocument("forbidden");if(Q.kind==="markdown"){if(ae.size>BigInt(h))return w.failureDocument("too-large");const ee=await ht(P,h+1);if(ee.length>h)return w.failureDocument("too-large");const ce=await a(new TextDecoder("utf-8").decode(ee),R);return{kind:"markdown",name:D,htmlContent:ce.htmlContent,headings:ce.headings,edit:null}}const H=await ht(P,g);if(H.includes(0))return{kind:"file",name:D,version:J};const Z=ae.size>BigInt(g),q=new TextDecoder("utf-8").decode(H,{stream:Z});return{kind:"text",name:D,text:q,truncated:Z,version:J}}catch(L){const X=De(L);if(X===null)throw L;return w.failureDocument(X)}finally{await P?.close()}},p=async(b,R,S)=>{let P;try{P=await C(S)}catch(J){throw It(J)}if(P.status==="refused")throw new ye(P.reason);const{target:L,name:X,stats:D}=P,G=At.get(Pt(X)),Q=G===void 0?"":G.contentType;return{name:X,contentType:Q,size:Number(D.size),version:mt(D),open:J=>Fn(L,D,J,b.signal)}},E=async(b,R,S)=>{let P;try{P=await C(S)}catch(D){if(De(D)!==null)return null;throw D}if(P.status==="refused")return null;const L=S.slice(m.length).split("/");if(L.some(D=>y.deniesName(D)))return null;const X=L.slice(0,-1);return X.map((D,G)=>`${m}${X.slice(0,G+1).join("/")}`)};return Object.freeze({id:t,label:r,cacheScope:A,boundary:Object.freeze({contains:b=>b.startsWith(m)}),tree:I,ancestors:E,document:F,asset:p})};exports.DEFAULT_DENIED_PATH_SEGMENTS=w.DEFAULT_DENIED_PATH_SEGMENTS;exports.MAX_DOCUMENT_PATH_LENGTH=w.MAX_DOCUMENT_PATH_LENGTH;exports.isAcceptableDocumentPath=w.isAcceptableDocumentPath;exports.isDeniedPath=w.isDeniedPath;exports.ExplorerError=ye;exports.anonymousAccess=Kt;exports.createFileSystemSource=Yn;exports.createMarkdownExplorer=Ln;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./dataRoute-CH3yOKR0.cjs"),wt=require("node:crypto"),Jt=require("@aiquants/markdown/server"),ke=require("@aiquants/request-isolation"),xe=require("react-router"),se=require("./location-BUNWJ4eB.cjs"),ie=require("node:fs"),ne=require("node:path"),Re=require("node:url"),Yt=require("node:worker_threads"),me=require("node:fs/promises"),Wt=require("node:stream");var _e=typeof document<"u"?document.currentScript:null;const Ue=Object.freeze({kind:"anonymous"}),Kt=Object.freeze({authenticate:async()=>({status:"signed-in",principal:Ue}),principalKey:()=>Ue.kind,signedOutPage:(e,t)=>new Response(null,{status:401,headers:t})}),Vt="application/octet-stream",yt="application/pdf",Qt=new Set(["image/png","image/apng","image/jpeg","image/gif","image/webp","image/avif","image/bmp","image/x-icon","image/vnd.microsoft.icon","audio/mpeg","audio/mp4","audio/aac","audio/ogg","audio/opus","audio/wav","audio/wave","audio/x-wav","audio/webm","audio/flac","audio/x-flac","audio/x-m4a","video/mp4","video/webm","video/ogg","video/quicktime",yt]),gt="default-src 'none'; media-src 'self'; style-src 'unsafe-inline'",Et=`${gt}; sandbox`,Zt=`${gt}; sandbox allow-same-origin`,Xe=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u,qt=/^[\t\n\r ]+|[\t\n\r ]+$/gu,Le=/^[\t ]+|[\t ]+$/gu,er=e=>{const t=[];let r="",n=0;for(;;){for(;n<e.length&&e[n]!=='"'&&e[n]!==",";)r+=e[n],n+=1;if(n<e.length&&e[n]==='"'){const a=n;for(n+=1;n<e.length&&e[n]!=='"';)n+=e[n]==="\\"?2:1;if(n=Math.min(n+1,e.length),r+=e.slice(a,n),n<e.length)continue}if(t.push(r.replace(Le,"")),r="",n>=e.length)return t;n+=1}},tr=e=>{const t=e.replace(qt,""),r=t.indexOf("/");if(r<0)return null;const n=t.slice(0,r),a=t.indexOf(";",r+1),i=t.slice(r+1,a<0?t.length:a).replace(/[\t\n\r ]+$/u,"");return Xe.test(n)&&Xe.test(i)?`${n}/${i}`.toLowerCase():null},rr=e=>{let t=null;for(const r of er(e)){const n=tr(r);n!==null&&n!=="*/*"&&(t=n)}return t},nr=/['()*]/gu,bt=e=>encodeURIComponent(e).replace(nr,t=>`%${t.charCodeAt(0).toString(16).toUpperCase()}`),or=Object.freeze({"Cache-Control":"private, max-age=60, stale-while-revalidate=600, no-transform",Vary:"Cookie"}),sr=(e,t)=>{const r=rr(e),n=r!==null&&Qt.has(r),a=n&&(r.startsWith("audio/")||r.startsWith("video/"));return{contentType:r===null?Vt:r,inline:n,headers:{"X-Content-Type-Options":"nosniff","Content-Disposition":`${n?"inline":"attachment"}; filename*=UTF-8''${bt(t)}`,...r===yt?{}:{"Content-Security-Policy":a?Zt:Et},"Cross-Origin-Resource-Policy":"same-origin"}}},ir="text/plain; charset=utf-8",ar=e=>({contentType:ir,inline:!0,headers:{"X-Content-Type-Options":"nosniff","Content-Disposition":`inline; filename*=UTF-8''${bt(e)}`,"Content-Security-Policy":Et,"Cross-Origin-Resource-Policy":"same-origin"}}),cr=/^bytes=(?:(\d+)-(\d*)|-(\d+))$/iu,Ee=Object.freeze({kind:"whole"}),Ge=Object.freeze({kind:"unsatisfiable"}),ur=(e,t,r)=>{const n=e.get("Range");if(n===null)return Ee;const a=e.get("If-Range");if(a!==null&&a!==r)return Ee;const i=cr.exec(n);if(i===null)return Ee;const[,c,m,y]=i;if(y!==void 0){const g=Number(y);if(g===0)return Ge;const k=Math.max(0,t-g);return{kind:"partial",range:{offset:k,length:t-k}}}const O=Number(c),h=m===""?Number.POSITIVE_INFINITY:Number(m);return h<O?Ee:O>=t?Ge:{kind:"partial",range:{offset:O,length:Math.min(h,t-1)-O+1}}},Je="W/",lr=e=>{const t=[];let r=0,n=!1;for(let a=0;a<e.length;a+=1)e[a]==='"'?n=!n:e[a]===","&&!n&&(t.push(e.slice(r,a).replace(Le,"")),r=a+1);return t.push(e.slice(r).replace(Le,"")),t},Ye=e=>e.startsWith(Je)?e.slice(Je.length):e,dr=(e,t)=>{if(e===null)return!1;const r=lr(e);if(r.length===1&&r[0]==="*")return!0;const n=Ye(t);return r.some(a=>Ye(a)===n)},fr=(e,t)=>{let r=t;return e.pipeThrough(new TransformStream({transform:(n,a)=>{const i=n.byteLength>r?n.subarray(0,r):n;r-=i.byteLength,a.enqueue(i),r===0&&a.terminate()},flush:n=>{r>0&&n.error(new RangeError("[markdown-explorer] the asset ended before its declared length"))}}))},Ae=async(e,t,r,n,a)=>{if(n!==null&&r.set("Content-Length",String(n)),e.method.toUpperCase()==="HEAD")return new Response(null,{status:t,headers:r});const i=await a();return new Response(n===null?i:fr(i,n),{status:t,headers:r})},mr=(e,t)=>{const r=new Headers(e);for(const[n,a]of Object.entries({"Accept-Ranges":"bytes","Content-Range":`bytes */${t}`,"Cache-Control":"private, no-store","X-Content-Type-Options":"nosniff"}))r.set(n,a);return new Response(null,{status:416,headers:r})},pr=async(e,t,r,n)=>{const a=`"${t.version}"`,i=n==="text"?ar(t.name):sr(t.contentType,t.name),c=new Headers(r);for(const[O,h]of Object.entries({...i.headers,...or,ETag:a}))c.set(O,h);if(dr(e.headers.get("If-None-Match"),a))return new Response(null,{status:304,headers:c});if(c.set("Content-Type",i.contentType),t.size===null)return Ae(e,200,c,null,()=>t.open(null));if(t.size===0)return c.set("Content-Length","0"),new Response(null,{status:200,headers:c});c.set("Accept-Ranges","bytes");const m=ur(e.headers,t.size,a);if(m.kind==="unsatisfiable")return mr(r,t.size);if(m.kind==="whole")return Ae(e,200,c,t.size,()=>t.open(null));const{range:y}=m;return c.set("Content-Range",`bytes ${y.offset}-${y.offset+y.length-1}/${t.size}`),Ae(e,206,c,y.length,()=>t.open(y))},ve=(e,t)=>{const r=new AbortController,n=t(AbortSignal.any([e.signal,r.signal]));return new Promise(a=>{let i;const c=setTimeout(()=>{a(e.late),i=setTimeout(()=>r.abort(),e.handOverMs)},e.timeoutMs),m=()=>{clearTimeout(c),clearTimeout(i)};n.then(y=>{m(),a(y)},()=>{m(),a(e.late)})})},hr=Object.freeze({error:(e,t)=>{console.error(e,t)}}),Tt=Symbol.for("@aiquants/markdown-explorer:ExplorerError");class ye extends Error{reason;code;constructor(t,r={}){if(!w.isExplorerFailureReason(t))throw new RangeError(`[markdown-explorer] ExplorerError needs a failure reason; got ${JSON.stringify(t)}`);if(r.code!==void 0&&!w.isExplorerFailureCode(r.code))throw new RangeError(`[markdown-explorer] an ExplorerError code must be 1 to 64 lowercase letters, digits or hyphens; got ${JSON.stringify(r.code)}`);super(`[markdown-explorer] ${t}`,r.cause===void 0?void 0:{cause:r.cause}),this.name="ExplorerError",this.reason=t,this.code=r.code,Object.defineProperty(this,Tt,{value:!0})}}const wr=e=>e instanceof Error&&Object.hasOwn(e,Tt)&&w.isExplorerFailureReason(e.reason),yr=e=>typeof e=="object"&&e!==null&&e.name==="AbortError",$e=(e,t,r)=>{try{e.error(t,r)}catch(n){console.error("[markdown-explorer] the logger threw while reporting a failure",{operation:r.operation,error:n})}},oe=(e,t)=>$e(e,`[markdown-explorer] ${t.operation} failed`,t),gr=(e,t)=>$e(e,`[markdown-explorer] ${t.operation} left out an entry`,t),Ne=(e,t)=>$e(e,`[markdown-explorer] ${t.operation} refused a path the deny rules match`,{...t,error:new RangeError("[markdown-explorer] the path matches a deny rule")}),We=(e,t)=>{e===null||typeof e!="object"&&typeof e!="function"||Promise.resolve(e).then(void 0,t)},Y=(e,t,r,n)=>wr(e)?w.failureOf(e.reason,e.code):(yr(e)||r.aborted||oe(n,{...t,error:e}),{reason:"failed"}),Ke=2*1024*1024,Ve=256*1024*1024,Er=async(e,t)=>{const r=e.getReader(),n=new Uint8Array(t);let a=0;for(;a<t;){const{done:i,value:c}=await r.read();if(i)return n.subarray(0,a);const m=c.subarray(0,t-a);n.set(m,a),a+=m.byteLength}return r.cancel().catch(()=>{}),n},br=async(e,t)=>{if(e.size===0)return{text:"",truncated:!1};const r=e.size!==null&&e.size>t,n=e.size===null?t+1:Math.min(e.size,t),a=await Er(await e.open(r?{offset:0,length:t}:null),n);if(e.size!==null&&a.byteLength<n)throw new RangeError("[markdown-explorer] the file ended before the length its asset port reported");const i=r||a.byteLength>t,c=i?a.subarray(0,t):a;return c.includes(0)?null:{text:new TextDecoder("utf-8").decode(c,{stream:i}),truncated:i}},Qe=(e,t)=>{if(!Number.isSafeInteger(t)||t<=0)throw new RangeError(`[markdown-explorer] a cache ${e} must be a positive integer; got ${String(t)}`)},St=(e,t)=>{Qe("capacity",e),t!==void 0&&Qe("weight budget",t.max);const r=new Map;let n=0;const a=i=>{const c=r.get(i);c!==void 0&&(r.delete(i),n-=c.weight)};return{get:i=>{const c=r.get(i);if(c!==void 0)return r.delete(i),r.set(i,c),c.value},set:(i,c)=>{a(i);const m=t===void 0?0:t.of(i,c);if(!(t!==void 0&&m>t.max)){r.set(i,{value:c,weight:m}),n+=m;for(const y of r.keys()){if(r.size<=e&&(t===void 0||n<=t.max))break;a(y)}}},delete:a,size:()=>r.size,weight:()=>n}},kt=e=>Math.max(1,e-1),Tr=2147483647,Ze=Object.freeze({status:"aborted"}),le=(e,t,r)=>{const n=(e.get(t)??0)+r;n===0?e.delete(t):e.set(t,n)},fe=(e,t,r)=>{if(!Number.isSafeInteger(t)||t<=0||t>r)throw new RangeError(`[markdown-explorer] a worker pool's ${e} must be an integer in 1..${String(r)}; got ${String(t)}`)},Sr=e=>e!==null&&typeof e=="object"&&e.ready===!0&&!("id"in e),kr=(e,t)=>e!==null&&typeof e=="object"&&e.id===t&&"output"in e,Or=({url:e,size:t,deadlineMs:r,jobsPerScope:n,maxQueuedJobs:a,heapLimits:i})=>{fe("size",t,Number.MAX_SAFE_INTEGER),fe("deadline",r,Tr),fe("jobsPerScope",n,Number.MAX_SAFE_INTEGER),fe("maxQueuedJobs",a,Number.MAX_SAFE_INTEGER),fe("maxOldGenerationSizeMb",i.maxOldGenerationSizeMb,Number.MAX_SAFE_INTEGER),fe("maxYoungGenerationSizeMb",i.maxYoungGenerationSizeMb,Number.MAX_SAFE_INTEGER);const c=Object.freeze({maxOldGenerationSizeMb:i.maxOldGenerationSizeMb,maxYoungGenerationSizeMb:i.maxYoungGenerationSizeMb}),m=new Set,y=[],O=new Map,h=new Map,g=kt(t);let k=0;const A=(p,E)=>{const{job:b}=p;p.timer!==null&&clearTimeout(p.timer),p.timer=null,p.job=null,p.sent=!1,b!==null&&(le(O,b.scope,-1),le(h,b.scope,-1),b.settle(E))},$=p=>{const[E]=y.splice(p,1);E?.detach()},N=()=>{let p=-1,E=g,b=Number.POSITIVE_INFINITY;for(const[R,S]of y.entries()){const P=O.get(S.scope)??0,L=h.get(S.scope)??0;(P<E||P===E&&p>=0&&L<b)&&(p=R,E=P,b=L)}return p},_=(p,E)=>{m.has(p)&&(m.delete(p),A(p,E),p.worker.terminate().catch(()=>{}),F())},z=p=>{p.timer=setTimeout(()=>{_(p,{status:"timeout"})},r)},v=(p,E)=>p.sent?{status:"crashed",error:E}:{status:"unavailable",error:E},I=(p,E)=>{p.sent=!0,z(p);try{p.worker.postMessage({id:E.id,input:E.input})}catch(b){A(p,{status:"crashed",error:b}),p.worker.unref()}},C=()=>{const p={worker:new Yt.Worker(e,{resourceLimits:c}),job:null,sent:!1,timer:null,ready:!1};return p.worker.unref(),p.timer=setTimeout(()=>{_(p,{status:"unavailable",error:new Error(`[markdown-explorer] a worker did not start within ${String(r)} ms`)})},r),p.worker.on("message",E=>{if(!p.ready&&Sr(E)){p.ready=!0,p.timer!==null&&clearTimeout(p.timer),p.timer=null,p.job===null?p.worker.unref():I(p,p.job),p.job===null&&F();return}const{job:b}=p;if(b===null||!kr(E,b.id)){_(p,v(p,new Error("[markdown-explorer] a worker sent a message that answers no job")));return}A(p,{status:"done",output:E.output}),p.worker.unref(),F()}),p.worker.on("error",E=>{_(p,v(p,E))}),p.worker.on("messageerror",E=>{_(p,v(p,E))}),p.worker.on("exit",E=>{_(p,v(p,new Error(`[markdown-explorer] a worker exited with code ${String(E)}`)))}),m.add(p),p},F=()=>{for(;;){const p=N(),E=y[p];if(E===void 0)return;let b;for(const S of m)if(S.job===null){b=S;break}if(b===void 0&&m.size<t)try{b=C()}catch(S){$(p),le(h,E.scope,-1),E.settle({status:"unavailable",error:S});continue}if(b===void 0)return;$(p),le(O,E.scope,1);const R=b;R.job=E,R.worker.ref(),R.ready&&I(R,E)}};return{run:(p,{scope:E,signal:b})=>new Promise(R=>{if(b.aborted){R(Ze);return}if((h.get(E)??0)>=n){R({status:"refused",limit:"scope"});return}k+=1;const S={id:k,input:p,scope:E,settle:R,detach:()=>{}};y.push(S),le(h,E,1),F();const P=y.indexOf(S);if(P<0)return;if(y.length>a){$(P),le(h,E,-1),R({status:"refused",limit:"queue"});return}const L=()=>{const X=y.indexOf(S);X<0||($(X),le(h,E,-1),R(Ze))};b.addEventListener("abort",L,{once:!0}),S.detach=()=>{b.removeEventListener("abort",L)}}),workers:()=>m.size}},je=1024*1024,xr=3e4,Rr=4*je,_r=64*je,Ar=3,vr=2,Nr=(e,t)=>e+kt(t)+Ar,Pr=4,Ir=32,Mr=512,Lr=64,Dr=4096,$r=32,qe=4096,jr=4,Ot=({workerHeapMb:e,maxHtmlBytes:t})=>Math.floor(((e-Lr)*je-t*$r)/Dr),zr=({maxHtmlBytes:e})=>e,Cr=({maxHtmlBytes:e})=>jr*e,Hr=1024,Br=2147483647,Fr=64,Ur=2**29,Xr=1024*1024,Gr=64,et=Object.freeze({status:"rejected",reason:"too-large",cause:null}),Pe=Object.freeze({status:"rejected",reason:"failed",cause:null}),de=(e,t,r,n)=>{if(t===void 0)return r;if(typeof t!="number")throw new TypeError(`[markdown-explorer] sanitizer.${e} must be a number; got ${typeof t}`);if(!Number.isSafeInteger(t)||t<=0||t>n)throw new RangeError(`[markdown-explorer] sanitizer.${e} must be an integer in 1..${String(n)}; got ${String(t)}`);return t},Jr=(e,t)=>{if(e!==void 0&&(e===null||typeof e!="object"))throw new TypeError("[markdown-explorer] sanitizer must be an object of { workers, deadlineMs, maxHtmlBytes, cacheBytes, workerHeapMb, jobsPerScope, maxQueuedJobs }");const{workers:r,deadlineMs:n,maxHtmlBytes:a,cacheBytes:i,workerHeapMb:c,jobsPerScope:m,maxQueuedJobs:y}=e??{},O=de("workers",r,vr,Fr),h=de("jobsPerScope",m,Nr(t,O),Number.MAX_SAFE_INTEGER),g=Object.freeze({workers:O,deadlineMs:de("deadlineMs",n,xr,Br),maxHtmlBytes:de("maxHtmlBytes",a,Rr,Ur),cacheBytes:de("cacheBytes",i,_r,Number.MAX_SAFE_INTEGER),workerHeapMb:de("workerHeapMb",c,Mr,Xr),jobsPerScope:h,maxQueuedJobs:de("maxQueuedJobs",y,Pr*h,Number.MAX_SAFE_INTEGER)});if(g.jobsPerScope<t)throw new RangeError(`[markdown-explorer] sanitizer.jobsPerScope must be at least multiView.maxPanels (${String(t)}), because a page sends the document of every panel to the sanitizer at once for one reader; got ${String(g.jobsPerScope)}`);if(g.maxQueuedJobs<t)throw new RangeError(`[markdown-explorer] sanitizer.maxQueuedJobs must be at least multiView.maxPanels (${String(t)}), because a reader whose page finds every worker busy waits with the document of every panel; got ${String(g.maxQueuedJobs)}`);if(Ot(g)<qe)throw new RangeError(`[markdown-explorer] sanitizer.workerHeapMb (${String(g.workerHeapMb)} MiB) must leave room for ${String(qe)} parsed nodes beside HTML of sanitizer.maxHtmlBytes (${String(g.maxHtmlBytes)} bytes); raise workerHeapMb or lower maxHtmlBytes`);return g},Yr=()=>{const e=typeof document>"u"?require("url").pathToFileURL(__filename).href:_e&&_e.tagName.toUpperCase()==="SCRIPT"&&_e.src||new URL("server.cjs",document.baseURI).href,t=new URL(`./sanitizeWorker${ne.extname(Re.fileURLToPath(e))}`,e);if(!ie.existsSync(Re.fileURLToPath(t)))throw new Error(`[markdown-explorer] the HTML sanitizer worker is missing: ${Re.fileURLToPath(t)}`);return t},tt=new Map,Wr=(e,t)=>{const r=[e.href,t.workers,t.deadlineMs,t.workerHeapMb,t.jobsPerScope,t.maxQueuedJobs].map(String).join("\0");let n=tt.get(r);return n===void 0&&(n=Or({url:e,size:t.workers,deadlineMs:t.deadlineMs,jobsPerScope:t.jobsPerScope,maxQueuedJobs:t.maxQueuedJobs,heapLimits:{maxOldGenerationSizeMb:t.workerHeapMb,maxYoungGenerationSizeMb:Ir}}),tt.set(r,n)),n},Kr=e=>{if(e===null||typeof e!="object")return!1;const{status:t,html:r,message:n}=e;return t==="sanitized"&&typeof r=="string"||t==="too-large"||t==="error"&&typeof n=="string"},Vr=e=>e instanceof Error&&e.code==="ERR_WORKER_OUT_OF_MEMORY",Qr=({iframeHosts:e,dataPath:t,options:r,pool:n})=>{const a=Object.freeze([...e]),i=Ot(r),c=zr(r),m=Cr(r),y=St(Hr,{max:r.cacheBytes,of:(N,_)=>2*N.length+(_.status==="sanitized"?2*_.html.length:Gr)}),O=new Map,h=new Map,g=N=>{O.get(N.key)===N&&O.delete(N.key);const _=h.get(N.hash);_?.delete(N),_?.size===0&&h.delete(N.hash)},k=async(N,_,z)=>{const v=await n.run({html:N,iframeHosts:a,dataPath:t,maxNodes:i,maxAttributeChars:c,maxSanitizedChars:m},{scope:_,signal:z});if(v.status==="refused"){const C=v.limit==="scope"?`its reader already has ${String(r.jobsPerScope)} documents being sanitized or waiting`:`${String(r.maxQueuedJobs)} documents are already waiting`;return{outcome:{status:"rejected",reason:"failed",cause:new Error(`[markdown-explorer] the HTML sanitizer refused a document: ${C}`)},lasting:!1}}if(v.status==="aborted")return{outcome:Pe,lasting:!1};if(v.status==="timeout")return{outcome:{status:"rejected",reason:"too-large",cause:new Error(`[markdown-explorer] the HTML sanitizer did not finish within ${String(r.deadlineMs)} ms`)},lasting:!0};if(v.status==="unavailable")return{outcome:{status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer worker could not start",{cause:v.error})},lasting:!1};if(v.status==="crashed"&&Vr(v.error))return{outcome:{status:"rejected",reason:"too-large",cause:new Error(`[markdown-explorer] the HTML sanitizer ran out of its ${String(r.workerHeapMb)} MiB worker heap`,{cause:v.error})},lasting:!0};if(v.status==="crashed")return{outcome:{status:"rejected",reason:"failed",cause:new Error("[markdown-explorer] the HTML sanitizer worker failed",{cause:v.error})},lasting:!0};const{output:I}=v;return Kr(I)?I.status==="too-large"?{outcome:et,lasting:!0}:I.status==="error"?{outcome:{status:"rejected",reason:"failed",cause:new Error(`[markdown-explorer] the HTML sanitizer failed: ${I.message}`)},lasting:!0}:I.html.length>m?{outcome:{status:"rejected",reason:"too-large",cause:new Error(`[markdown-explorer] the HTML sanitizer's output of ${String(I.html.length)} characters exceeds its limit of ${String(m)}`)},lasting:!0}:{outcome:{status:"sanitized",html:I.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}},A=(N,_,z,v)=>{let I=()=>{};const C=new Promise(E=>{I=E}),F={hash:_,key:z,outcome:C,answer:I,controller:new AbortController,waiters:0};O.set(z,F);const p=h.get(_);return p===void 0?h.set(_,new Set([F])):p.add(F),k(N,v,F.controller.signal).catch(E=>({outcome:{status:"rejected",reason:"failed",cause:E instanceof Error?E:new Error(String(E))},lasting:!0})).then(({outcome:E,lasting:b})=>{if(g(F),F.answer(E),!b)return;const R=y.get(_),S=R??(E.status==="rejected"?{...E,cause:null}:E);R===void 0&&y.set(_,S);for(const P of h.get(_)??[])g(P),P.answer(S),P.controller.abort()}),F},$=(N,_)=>new Promise(z=>{N.waiters+=1;const v=()=>{N.waiters-=1,z(Pe),!(N.waiters>0)&&(g(N),N.controller.abort())};_.addEventListener("abort",v,{once:!0}),N.outcome.then(I=>{_.removeEventListener("abort",v),z(I)})});return(N,{scope:_,signal:z})=>{if(N.length>r.maxHtmlBytes||Buffer.byteLength(N,"utf8")>r.maxHtmlBytes)return Promise.resolve(et);const v=wt.createHash("sha256").update(N,"utf8").digest("base64"),I=y.get(v);if(I!==void 0)return Promise.resolve(I);if(z.aborted)return Promise.resolve(Pe);const C=`${v}\0${_}`,F=O.get(C);return $(F===void 0?A(N,v,C,_):F,z)}},Oe=e=>({result:e,json:JSON.stringify(e)}),Ie=Object.freeze(Oe(Object.freeze({status:"error",failure:Object.freeze({reason:"failed"})}))),Zr=e=>e.status==="ok"&&e.entries.length>0,qr=({ttlMs:e,maxEntries:t,maxBytes:r,now:n})=>{const a=St(t,{max:r,of:(h,g)=>2*g.tree.json.length}),i=new Map,c=new Map,m=(h,g)=>{const k=new AbortController,A={waiters:0,superseded:!1,started:!1,loadTree:g},$=c.get(h),N=(C,F)=>{const p=Oe(C);return!(A.superseded||k.signal.aborted)&&Zr(C)&&a.set(h,{tree:p,loadedAt:F}),p},z=(async()=>{if($!==void 0&&await $,k.signal.aborted)return Ie;const C=n();return A.started=!0,N(await A.loadTree(k.signal,C),C)})().finally(()=>{i.get(h)===v&&i.delete(h)}),v={promise:z,controller:k,state:A};i.set(h,v);const I=z.then(()=>{},()=>{});return c.set(h,I),I.then(()=>{c.get(h)===I&&c.delete(h)}),v},y=(h,g,k)=>{g.state.waiters+=1;const A=()=>{g.state.waiters-=1,!(g.state.waiters>0)&&(i.get(h)===g&&i.delete(h),g.controller.abort())};return k.addEventListener("abort",A,{once:!0}),g.promise.finally(()=>{k.removeEventListener("abort",A)})},O=h=>{a.delete(h);const g=i.get(h);g?.state.started&&(g.state.superseded=!0,i.delete(h))};return{load:(h,g,k)=>{if(g.aborted)return Promise.resolve(Ie);const A=a.get(h);if(A!==void 0){if(n()-A.loadedAt<e)return Promise.resolve(A.tree);a.delete(h)}const $=i.get(h);return y(h,$===void 0?m(h,k):$,g)},refresh:(h,g,k)=>{if(g.aborted)return Promise.resolve(Ie);O(h);const A=i.get(h);return A===void 0?y(h,m(h,k),g):(A.state.loadTree=k,y(h,A,g))},forget:O}},en=e=>({load:(t,r,n)=>n(r,e()).then(Oe),refresh:(t,r,n)=>n(r,e()).then(Oe),forget:()=>{}}),x=e=>{throw new TypeError(`[markdown-explorer] ${e}`)},tn=e=>{if(e===null||typeof e!="object")return null;const{name:t,path:r}=e;return typeof t!="string"||typeof r!="string"?null:t===""?{path:r,reason:"an empty name"}:w.isAcceptableDocumentPath(r)?null:{path:r,reason:"a path the browser cannot address (empty, too long, a lone surrogate, a control character or a backslash)"}},rn=(e,t,r,n)=>{if(e===null)return null;if(!Array.isArray(e))throw new TypeError(`[markdown-explorer] a source's ancestors must be null or an array of folder paths; got ${typeof e}`);const a=new Set;for(const i of e){if(typeof i!="string"||!w.isAcceptableDocumentPath(i))throw new TypeError("[markdown-explorer] a source's ancestors held a path the explorer does not accept");if(r.deniesPath(i))throw new TypeError("[markdown-explorer] a source's ancestors held a denied path");if(!n(i))throw new TypeError("[markdown-explorer] a source's ancestors held a path outside the source's boundary");if(i===t)throw new TypeError("[markdown-explorer] a source's ancestors held the document itself");if(a.has(i))throw new TypeError("[markdown-explorer] a source's ancestors held a path twice");a.add(i)}return Object.freeze([...a])},nn=(e,t,r,n,a)=>{const i=new Set,c=y=>{if(!Array.isArray(y))return x("a source returned entries that are not an array");const O=[];for(const h of y){const g=m(h);g!==null&&O.push(g)}return O},m=y=>{const O=tn(y);if(O!==null)return n(O),null;const h=w.entryViolation(y);if(h!==null)return x(h);const g=y;if(i.has(g))return x("a source returned entries that contain themselves");const{name:k,path:A,type:$,mimeType:N,modifiedAt:_,children:z,lazy:v}=g;if(t.deniesName(k)||t.deniesPath(A))return null;if(!a(A))return n({path:A,reason:"a path outside the source's boundary"}),null;const I={name:k,path:A,...N===void 0?{}:{mimeType:N},..._===void 0?{}:{modifiedAt:_}};if($==="file")return{...I,type:$};if(v===!0)return r?{...I,type:$,lazy:!0,children:[]}:x("a lazy directory came from a source without a children function");if(z===void 0)return{...I,type:$};i.add(g);const C=c(z);return i.delete(g),{...I,type:$,children:C}};return c(e)},on=/^[\x21\x23-\x7E]{1,256}$/u,xt=e=>typeof e=="string"&&on.test(e),sn=new Set(["text","image","media","file"]),an=e=>typeof e=="string"&&sn.has(e),cn=(e,t,r)=>{if(e!==null&&typeof e=="object"){const i=e,{kind:c}=i;if(an(c)){if(Object.hasOwn(i,"url"))return x(`a ${c} document carries its version, not a url`);if(typeof i.name!="string")return x("a document needs a name string");if(!xt(i.version))return x(`a ${c} document needs a version of 1 to 256 visible ASCII characters other than '"'`);const m=t(i.version);switch(c){case"image":case"file":return{kind:c,name:i.name,url:m};case"media":{const{mediaType:y}=i;return w.isExplorerMediaType(y)?{kind:c,name:i.name,url:m,mediaType:y}:x(`unknown media type ${typeof y=="string"?JSON.stringify(y.slice(0,64)):typeof y}`)}case"text":return typeof i.text!="string"||typeof i.truncated!="boolean"?x("a text document needs text and truncated"):{kind:c,name:i.name,text:i.text,truncated:i.truncated,url:m}}}}const n=w.documentViolation(e);if(n!==null)return x(n);const a=e;switch(a.kind){case"failure":{const{reason:i,code:c}=a.failure;return{kind:"failure",failure:w.failureOf(i,c)}}case"markdown":return a.headings.length>w.EXPLORER_MAX_HEADINGS?{kind:"failure",failure:w.failureOf("too-large")}:a.edit?.kind==="inline"&&!r?x("a markdown document offers inline editing, but the server has no edit ports"):{kind:"unsanitized-markdown",name:a.name,html:a.htmlContent,headings:a.headings.map(({text:i,depth:c,id:m})=>({text:i,depth:c,id:m})),edit:un(a.edit)}}},un=e=>e===null?null:e.kind==="inline"?{kind:"inline"}:{kind:"external",href:e.href},ze=(e,t,r)=>typeof e!="string"?x(`${r} needs a text string`):e.includes("\0")?x(`${r} holds NUL, which no text editor can keep`):new TextEncoder().encode(e).byteLength>t?x(`${r} is over editMaxBytes (${t} bytes); refuse a longer source with ExplorerError "too-large"`):e,Rt=e=>w.isRootRelativeUrl(e.href)?{kind:"grant",href:e.href}:x("a grant needs a root-relative href"),ln=(e,t)=>{if(e===null||typeof e!="object")return x("an edit source must be an object");const r=e;return r.kind==="grant"?Rt(r):r.kind!=="edit"?x(`an edit source's kind must be "edit" or "grant"`):w.isExplorerEditToken(r.version)?typeof r.history!="boolean"?x("an edit source needs history"):{kind:"edit",text:ze(r.text,t,"an edit source"),version:r.version,history:r.history}:x("an edit source needs a version of 1 to 1024 characters")},dn=(e,t)=>{if(e===null||typeof e!="object")return x("a save result must be an object");const r=e;switch(r.kind){case"grant":return Rt(r);case"saved":return w.isExplorerEditToken(r.version)?{kind:"saved",version:r.version}:x("a saved result needs a version of 1 to 1024 characters");case"conflict":return w.isExplorerEditToken(r.version)?{kind:"conflict",version:r.version,text:ze(r.text,t,"a conflict's current text")}:x("a conflict needs the current version of 1 to 1024 characters");default:return x(`a save result's kind must be "saved", "conflict" or "grant"`)}},fn=e=>{if(e===null||typeof e!="object")return x("a preview must be an object");const{htmlContent:t,headings:r}=e;if(typeof t!="string"||!Array.isArray(r))return x("a preview needs htmlContent and headings");if(r.length>w.EXPLORER_MAX_HEADINGS)return{kind:"failure",failure:w.failureOf("too-large")};for(const n of r){const a=w.headingViolation(n);if(a!==null)return x(a)}return{html:t,headings:r.map(({text:n,depth:a,id:i})=>({text:n,depth:a,id:i}))}},mn=e=>{if(!Array.isArray(e))return x("revisions must be an array");const t=new Set;return e.map(r=>{const n=w.revisionViolation(r);if(n!==null)return x(n);const{id:a,modifiedAt:i,size:c,author:m,kept:y,current:O}=r;return t.has(a)?x(`two revisions share the id ${JSON.stringify(a.slice(0,64))}`):(t.add(a),{id:a,modifiedAt:i,size:c,author:m,kept:y,current:O})})},pn=(e,t)=>ze(e,t,"a revision"),rt=e=>{if(e===null||typeof e!="object")return x("an asset file must be an object");const{name:t,contentType:r,size:n,version:a,open:i}=e;return typeof t!="string"||t===""?x("an asset file needs a non-empty name"):typeof r!="string"?x("an asset file needs a contentType string ('' when unknown)"):n!==null&&!(typeof n=="number"&&Number.isSafeInteger(n)&&n>=0)?x("an asset file's size must be null or a non-negative safe integer"):xt(a)?typeof i!="function"?x("an asset file needs an open function"):Object.freeze({name:t,contentType:r,size:n,version:a,open:i}):x(`an asset file needs a version of 1 to 256 visible ASCII characters other than '"'`)},hn=e=>Array.isArray(e)?e.map(t=>{if(t===null||typeof t!="object")return x("a notice must be an object");const{id:r,tone:n,title:a,body:i,action:c}=t;if(typeof r!="string"||r===""||typeof a!="string")return x("a notice needs an id and a title");if(!w.isExplorerNoticeTone(n))return x(`unknown notice tone ${typeof n=="string"?JSON.stringify(n.slice(0,64)):typeof n}`);if(i!==void 0&&typeof i!="string")return x("a notice body must be a string");const y={id:r,tone:n,title:a,...i===void 0?{}:{body:i}};if(c===void 0)return y;if(c===null||typeof c!="object")return x("a notice action must be an object");const{label:O,href:h}=c;return typeof O!="string"||!w.isAcceptableUrl(h,w.EXPLORER_LINK_PROTOCOLS)?x("a notice action needs a label and an http(s), mailto or relative href"):{...y,action:{label:O,href:h}}}):x("notices must be an array"),wn=4e3,be=Object.freeze({ttlMs:3e5,maxEntries:64,maxBytes:64*1024*1024}),nt=32,_t="private, no-store",yn=Object.freeze({"Content-Type":"application/json; charset=utf-8","Cache-Control":_t,"X-Content-Type-Options":"nosniff","Content-Security-Policy":"default-src 'none'; frame-ancestors 'none'; sandbox","Cross-Origin-Resource-Policy":"same-origin"}),gn=22,En=2147483647,Me=Object.freeze([]),bn=Object.freeze({status:"ok",source:null,ancestors:null}),ot=Object.freeze(["contains","confirm"]),st=Object.freeze({readOnly:!1}),Tn=Object.freeze({readOnly:!0}),V=(e,t,r)=>{if(!(r&&t===void 0)&&typeof t!="function")throw new TypeError(`[markdown-explorer] ${e} must be a function; got ${typeof t}`)},pe=(e,t,r)=>{if(typeof t!="number")throw new TypeError(`[markdown-explorer] ${e} must be a number; got ${typeof t}`);if(!Number.isSafeInteger(t)||t<=0||t>r)throw new RangeError(`[markdown-explorer] ${e} must be an integer in 1..${String(r)}; got ${String(t)}`);return t},Sn=e=>{if(e===null||typeof e!="object"||!Object.isFrozen(e))throw new TypeError("[markdown-explorer] config must be the value returned by defineExplorerConfig");return se.revalidateExplorerConfig(e)},it=e=>{try{return new Headers(e)}catch{throw new TypeError("[markdown-explorer] authenticate returned headers that are not a valid headers init (their values are not logged)")}},at=e=>e instanceof Response?new TypeError(`[markdown-explorer] authenticate threw a Response (status ${String(e.status)}), which a data request does not follow`):e,kn=e=>{if(typeof e!="string")throw new TypeError(`[markdown-explorer] scopeSecret must be a string; got ${typeof e}`);if(e.length<nt)throw new RangeError(`[markdown-explorer] scopeSecret must have at least ${String(nt)} characters; got ${String(e.length)}`);return e},On=(e,t)=>{if(!se.isPlainObject(t))throw new TypeError(`[markdown-explorer] ${e}.boundary must be a plain object { contains, confirm? }`);for(const r of Object.keys(t))if(!ot.includes(r))throw new RangeError(`[markdown-explorer] ${e}.boundary.${r} is not an option; expected ${ot.join(", ")}`);V(`${e}.boundary.contains`,t.contains,!1),V(`${e}.boundary.confirm`,t.confirm,!0)},xn=e=>{if(!Array.isArray(e))throw new TypeError("[markdown-explorer] sources must be an array");const t=e;if(t.length===0)throw new RangeError("[markdown-explorer] sources must hold at least one source");const r=new Set;for(const[n,a]of t.entries()){if(a===null||typeof a!="object")throw new TypeError(`[markdown-explorer] sources[${String(n)}] must be an object`);const{id:i,label:c,boundary:m,tree:y,children:O,ancestors:h,cacheScope:g}=a;if(!se.isExplorerSourceId(i))throw new RangeError(`[markdown-explorer] sources[${String(n)}].id must use lowercase letters, digits and "-" and start with a letter or digit; got ${typeof i=="string"?JSON.stringify(i):typeof i}`);const k=`source ${JSON.stringify(i)}`;if(r.has(i))throw new RangeError(`[markdown-explorer] source ids must be unique; ${JSON.stringify(i)} repeats at sources[${String(n)}]`);if(r.add(i),typeof c!="string"&&typeof c!="function")throw new TypeError(`[markdown-explorer] ${k}.label must be a string or a function`);if(typeof c=="string"&&c.trim()==="")throw new RangeError(`[markdown-explorer] ${k}.label must not be blank`);if(On(k,m),V(`${k}.tree`,y,!1),V(`${k}.children`,O,!0),V(`${k}.ancestors`,h,!0),g!==void 0&&g!=="principal"&&g!=="shared")throw new RangeError(`[markdown-explorer] ${k}.cacheScope must be "principal" or "shared"; got ${JSON.stringify(g)}`)}return t},Rn=e=>{if(e===!1)return!1;if(e===void 0)return be;if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] treeCache must be { ttlMs, maxEntries, maxBytes } or false");const{ttlMs:t,maxEntries:r,maxBytes:n}=e;return{ttlMs:t===void 0?be.ttlMs:pe("treeCache.ttlMs",t,Number.MAX_SAFE_INTEGER),maxEntries:r===void 0?be.maxEntries:pe("treeCache.maxEntries",r,Number.MAX_SAFE_INTEGER),maxBytes:n===void 0?be.maxBytes:pe("treeCache.maxBytes",n,Number.MAX_SAFE_INTEGER)}},ct=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] authenticate must resolve to { status, ... }");const{status:t}=e;if(t!=="signed-in"&&t!=="signed-out"&&t!=="forbidden")throw new TypeError(`[markdown-explorer] authenticate resolved to an unknown status ${JSON.stringify(t)}`);return e},ut=(e,t)=>{if(!(t instanceof Response))throw new TypeError(`[markdown-explorer] ${e} must return a Response`);return t},lt=(e,t)=>{if(typeof t!="string"||t==="")throw new TypeError("[markdown-explorer] principalKey must return a non-empty string");return wt.createHmac("sha256",e).update(t,"utf8").digest("base64url").slice(0,gn)},_n=e=>e.view==="multi"?e.docs:e.doc===null?[]:[e.doc],ue=(e,t)=>{const r=e.getAll(t),[n]=r;return r.length===1&&n!==void 0&&n!==""?n:null},K=(e,t,r,n={})=>{const a=new Headers(r);for(const[i,c]of Object.entries({...yn,...n}))a.set(i,c);return new Response(t,{status:e,headers:a})},j=(e,t,r)=>K(w.EXPLORER_FAILURE_STATUS[e.reason],JSON.stringify({failure:e}),t,r),An=new Set(["refresh","save","preview"]),vn=new Set(["edit","save","preview","revisions","revision"]),dt=(e,t)=>{const r=An.has(t)?["POST"]:["GET","HEAD"];return r.includes(e.method.toUpperCase())?null:K(405,JSON.stringify({failure:{reason:"invalid"}}),void 0,{Allow:r.join(", ")})},ft=e=>e.headers.get(w.EXPLORER_PROOF_HEADER)===w.EXPLORER_REFRESH_PROOF&&ke.crossOriginRefusal(e,ke.NO_CROSS_ORIGIN_NAVIGATION)===void 0,Nn=e=>e.headers.get(w.EXPLORER_PROOF_HEADER)===w.EXPLORER_EDIT_PROOF&&ke.crossOriginRefusal(e,ke.NO_CROSS_ORIGIN_NAVIGATION)===void 0,Pn=async(e,t)=>{const[r,...n]=(e.headers.get("Content-Type")??"").split(";").map(k=>k.trim().toLowerCase()),a=n.find(k=>k.startsWith("charset="));if(r!==w.EXPLORER_DRAFT_MEDIA_TYPE||a!==void 0&&a!=="charset=utf-8")return{status:"error",failure:{reason:"invalid"}};const i=Number(e.headers.get("Content-Length")??"0");if(Number.isFinite(i)&&i>t)return{status:"error",failure:{reason:"too-large"}};if(e.body===null)return{status:"ok",text:""};const c=e.body.getReader(),m=[];let y=0;for(;;){const{done:k,value:A}=await c.read();if(k)break;if(y+=A.byteLength,y>t)return await c.cancel(),{status:"error",failure:{reason:"too-large"}};m.push(A)}const O=new Uint8Array(y);let h=0;for(const k of m)O.set(k,h),h+=k.byteLength;let g;try{g=new TextDecoder("utf-8",{fatal:!0}).decode(O)}catch{return{status:"error",failure:{reason:"invalid"}}}return g.includes("\0")?{status:"error",failure:{reason:"invalid"}}:{status:"ok",text:g}},In=e=>{if(e===void 0)return;if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] edit must be an object of the editor's ports");const t=e;for(const r of["source","save","preview","revisions","revision"])V(`edit.${r}`,t[r],!1);return e},Mn=({parentHeaders:e,loaderHeaders:t,errorHeaders:r})=>{const n=new Headers,a=r===void 0?[e,t]:[e,t,r];for(const i of a)for(const[c,m]of i)c!=="set-cookie"&&n.set(c,m);return n},Ln=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] the server configuration must be an object");const t=Sn(e.config),r=kn(e.scopeSecret);V("authenticate",e.authenticate,!1),V("principalKey",e.principalKey,!1),V("document",e.document,!1),V("asset",e.asset,!1),V("signedOutPage",e.signedOutPage,!1),V("forbiddenPage",e.forbiddenPage,!0),V("notices",e.notices,!0),V("onTreeRefreshed",e.onTreeRefreshed,!0);const n=xn(e.sources),a=se.withExplorerSources(t,n.map(o=>o.id)),i=e.logger;if(i!==void 0&&(i===null||typeof i!="object"||typeof i.error!="function"))throw new TypeError("[markdown-explorer] logger must be an object with an error function");const c=e.logger===void 0?hr:e.logger,m=w.resolvePathRules(e.deny),y=e.deferredTimeoutMs===void 0?wn:pe("deferredTimeoutMs",e.deferredTimeoutMs,En),O=e.textMaxBytes===void 0?Ke:pe("textMaxBytes",e.textMaxBytes,Ve),h=In(e.edit);if(h===void 0&&e.editMaxBytes!==void 0)throw new TypeError("[markdown-explorer] editMaxBytes needs the edit ports");const g=e.editMaxBytes===void 0?Ke:pe("editMaxBytes",e.editMaxBytes,Ve),k=Rn(e.treeCache),A=()=>Date.now(),$=k===!1?en(A):qr({...k,now:A}),N=Jr(e.sanitizer,t.multiView.maxPanels),_=Qr({iframeHosts:t.iframeHosts,dataPath:t.dataPath,options:N,pool:Wr(Yr(),N)}),z=new Map(n.map(o=>[o.id,o])),v=se.documentStyleNames(t),{authenticate:I,principalKey:C,signedOutPage:F,forbiddenPage:p,onTreeRefreshed:E}=e,b=(o,u)=>{if(typeof o.label=="string")return o.label;const s=o.label(u);if(typeof s!="string"||s.trim()==="")throw new TypeError(`[markdown-explorer] the label of source ${JSON.stringify(o.id)} must be a non-blank string`);return s},R=(o,u)=>o.cacheScope==="shared"?o.id:`${o.id}\0${u}`,S=(o,u)=>{const s=d=>oe(c,{operation:"boundary",sourceId:o.id,path:u,error:d});let l;try{l=o.boundary.contains(u)}catch(d){return s(d),!1}return typeof l=="boolean"?l:(We(l,s),s(new TypeError(`[markdown-explorer] boundary.contains of source ${JSON.stringify(o.id)} must return a boolean; got ${typeof l}`)),!1)},P=async(o,u,s)=>{const{confirm:l}=o.boundary;if(l===void 0)return{status:"inside",readPath:s};let d;try{d=await l(u,s)}catch(U){return{status:"error",failure:Y(U,{operation:"boundary",sourceId:o.id,path:s},u.signal,c)}}const f=U=>(oe(c,{operation:"boundary",sourceId:o.id,path:s,error:new TypeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} ${U}`)}),{status:"outside"});if(d===null||typeof d!="object")return f(`must resolve to { inside, readPath? }; got ${d===null?"null":typeof d}`);const{inside:T,readPath:M}=d;return T===!1?{status:"outside"}:T!==!0||typeof M!="string"?f("must resolve to { inside: false } or { inside: true, readPath: string }"):!w.isAcceptableDocumentPath(M)||m.deniesPath(M)?(oe(c,{operation:"boundary",sourceId:o.id,path:s,error:new RangeError(`[markdown-explorer] boundary.confirm of source ${JSON.stringify(o.id)} answered a readPath the explorer does not serve (unacceptable or denied)`)}),{status:"error",failure:{reason:"failed"}}):{status:"inside",readPath:M}},L=async(o,u)=>{const s=n.filter(d=>S(d,u));if(s.length===0)return{status:"error",failure:{reason:"forbidden"}};if(s.some(d=>d.boundary.confirm===void 0))return{status:"inside",readPath:u};let l=null;for(const d of s){const f=await P(d,o,u);if(f.status==="inside")return f;f.status==="error"&&l===null&&(l=f.failure)}return{status:"error",failure:l===null?{reason:"forbidden"}:l}},X=(o,u,s)=>{const l=({path:d,reason:f})=>gr(c,{operation:s.operation,sourceId:s.sourceId,path:d,error:new TypeError(`[markdown-explorer] an entry with ${f} was left out`)});try{return{status:"ok",entries:nn(o,m,u.children!==void 0,l,d=>S(u,d))}}catch(d){return oe(c,{...s,error:d}),{status:"error",failure:{reason:"failed"}}}},D=async(o,u,s)=>{let l;try{l=await o.tree(u)}catch(f){return{status:"error",failure:Y(f,{operation:"tree",sourceId:o.id},u.signal,c)}}const d=X(l,o,{operation:"tree",sourceId:o.id});return d.status==="ok"?{status:"ok",entries:d.entries,loadedAt:s}:d},G=(o,u,s,l)=>(d,f)=>D(o,{principal:u,request:s,signal:d,refresh:l},f),Q=(o,u,s,l,d)=>$.load(R(o,s),d,G(o,u,l,!1)),J=(o,u,s,l)=>$.refresh(R(o,s),l.signal,G(o,u,l,!0)),ae=(o,u)=>{if(E===void 0)return;const s=l=>oe(c,{operation:"refresh",sourceId:o.id,error:l});try{We(E(u),s)}catch(l){s(l)}},H=async(o,u,s,l)=>{if(m.deniesPath(l)||!S(o,l))return{status:"error",failure:{reason:"forbidden"}};const d=await P(o,s,l);if(d.status==="outside")return{status:"error",failure:{reason:"forbidden"}};if(d.status==="error")return{status:"error",failure:d.failure};let f;try{f=await u(s,l,d.readPath)}catch(T){return{status:"error",failure:Y(T,{operation:"children",sourceId:o.id,path:l},s.signal,c)}}return X(f,o,{operation:"children",sourceId:o.id,path:l})},Z=async(o,u,s,l)=>{const d=await P(o,s,l);if(d.status==="outside")return{status:"ok",ancestors:null};if(d.status==="error")return{status:"error",failure:d.failure};let f;try{f=await u(s,l,d.readPath,{maxDepth:t.revealDocument.maxDepth})}catch(T){return{status:"error",failure:Y(T,{operation:"ancestors",sourceId:o.id,path:l},s.signal,c)}}if(Array.isArray(f)&&f.length>t.revealDocument.maxDepth)return{status:"ok",ancestors:null};try{return{status:"ok",ancestors:rn(f,l,m,T=>S(o,T))}}catch(T){return oe(c,{operation:"ancestors",sourceId:o.id,path:l,error:T}),{status:"error",failure:{reason:"failed"}}}},q=async(o,u,s,l)=>m.deniesPath(l)?{status:"error",failure:{reason:"forbidden"}}:S(o,l)?Z(o,u,s,l):{status:"ok",ancestors:null},ee=async(o,u,s)=>{if(m.deniesPath(s))return{status:"error",failure:{reason:"forbidden"}};for(const l of[o,...n.filter(d=>d!==o)]){if(u.signal.aborted)break;const d=l.ancestors;if(d===void 0||!S(l,s))continue;const f=await Z(l,d,u,s);if(f.status==="ok"&&f.ancestors!==null)return{status:"ok",source:l.id,ancestors:f.ancestors}}return bn},ce=async(o,u,s)=>{if(m.deniesPath(s))return w.failureDocument("forbidden");const l=await L(o,s);if(l.status==="error")return{kind:"failure",failure:l.failure};let d;try{d=await e.document(o,s,l.readPath)}catch(M){return{kind:"failure",failure:Y(M,{operation:"document",path:s},o.signal,c)}}let f;try{f=cn(d,M=>w.explorerAssetHref(t.dataPath,s,M),h!==void 0)}catch(M){return oe(c,{operation:"document",path:s,error:M}),w.failureDocument("failed")}if(f.kind!=="unsanitized-markdown")return f;const T=await _(f.html,{scope:u,signal:o.signal});return T.status==="sanitized"?{kind:"markdown",name:f.name,htmlContent:T.html,headings:f.headings,edit:f.edit}:(T.cause!==null&&oe(c,{operation:"document",path:s,error:T.cause}),w.failureDocument(T.reason))},ge=async o=>{if(e.notices===void 0)return Me;try{return hn(await e.notices(o))}catch(u){return Y(u,{operation:"notices"},o.signal,c),Me}},Lt=async(o,u,s)=>{const l=ue(u,w.EXPLORER_DATA_QUERY.path);if(l===null||!w.isAcceptableDocumentPath(l))return j({reason:"invalid"},s);const d=w.readExplorerAssetDisplay(u);if(d===null)return j({reason:"invalid"},s);if(m.deniesPath(l))return Ne(c,{operation:"asset",path:l}),j({reason:"forbidden"},s);const f=await L(o,l);if(f.status==="error")return j(f.failure,s);try{const T=rt(await e.asset(o,l,f.readPath));return await pr(o.request,T,s,d)}catch(T){return j(Y(T,{operation:"asset",path:l},o.signal,c),s)}},Dt=async(o,u)=>{if(m.deniesPath(u))return Ne(c,{operation:"text",path:u}),w.failureDocument("forbidden");const s=await L(o,u);if(s.status==="error")return{kind:"failure",failure:s.failure};try{const l=rt(await e.asset(o,u,s.readPath)),d=await br(l,O);return d===null?w.failureDocument("unsupported"):{kind:"text",name:l.name,text:d.text,truncated:d.truncated,url:w.explorerAssetHref(t.dataPath,u,l.version)}}catch(l){return{kind:"failure",failure:Y(l,{operation:"text",path:u},o.signal,c)}}},he=async(o,u,s)=>m.deniesPath(s)?(Ne(c,{operation:u,path:s}),{status:"error",failure:{reason:"forbidden"}}):L(o,s),$t=async(o,u,s)=>{const l=await he(u,"edit",s);if(l.status==="error")return{kind:"failure",failure:l.failure};try{return ln(await o.source(u,s,l.readPath),g)}catch(d){return{kind:"failure",failure:Y(d,{operation:"edit",path:s},u.signal,c)}}},jt=async(o,u,s,l,d)=>{const f=await he(u,"save",s);if(f.status==="error")return{kind:"failure",failure:f.failure};try{return dn(await o.save(u,s,f.readPath,{text:d,baseVersion:l}),g)}catch(T){return{kind:"failure",failure:Y(T,{operation:"save",path:s},u.signal,c)}}},zt=async(o,u,s,l,d)=>{const f=await he(u,"preview",l);if(f.status==="error")return{kind:"failure",failure:f.failure};let T;try{T=fn(await o.preview(u,l,f.readPath,d))}catch(U){return{kind:"failure",failure:Y(U,{operation:"preview",path:l},u.signal,c)}}if("kind"in T)return T.kind==="failure"?T:w.failureDocument("failed");const M=await _(T.html,{scope:s,signal:u.signal});return M.status==="sanitized"?{kind:"preview",htmlContent:M.html,headings:T.headings}:(M.cause!==null&&oe(c,{operation:"preview",path:l,error:M.cause}),w.failureDocument(M.reason))},Ct=async(o,u,s)=>{const l=await he(u,"revisions",s);if(l.status==="error")return{kind:"failure",failure:l.failure};try{return{kind:"revisions",revisions:mn(await o.revisions(u,s,l.readPath))}}catch(d){return{kind:"failure",failure:Y(d,{operation:"revisions",path:s},u.signal,c)}}},Ht=async(o,u,s,l)=>{const d=await he(u,"revision",s);if(d.status==="error")return{kind:"failure",failure:d.failure};try{return{kind:"revision",id:l,text:pn(await o.revision(u,s,d.readPath,l),g)}}catch(f){return{kind:"failure",failure:Y(f,{operation:"revision",path:s},u.signal,c)}}},Bt=async(o,u,s,l,d,f)=>{const T=ue(d,w.EXPLORER_DATA_QUERY.path);if(T===null||!w.isAcceptableDocumentPath(T))return j({reason:"invalid"},f);if(u==="edit")return K(200,JSON.stringify(await $t(o,s,T)),f);if(u==="revisions")return K(200,JSON.stringify(await Ct(o,s,T)),f);if(u==="revision"){const te=ue(d,w.EXPLORER_DATA_QUERY.revision);return w.isExplorerEditToken(te)?K(200,JSON.stringify(await Ht(o,s,T,te)),f):j({reason:"invalid"},f)}const M=ue(d,w.EXPLORER_DATA_QUERY.base);if(u==="save"&&!w.isExplorerEditToken(M))return j({reason:"invalid"},f);const U=await Pn(s.request,g);return U.status==="error"?j(U.failure,f):u==="preview"?K(200,JSON.stringify(await zt(o,s,l,T,U.text)),f):K(200,JSON.stringify(await jt(o,s,T,M,U.text)),f)},Ft=async({request:o,url:u,params:s})=>{const l=ct(await I(o,st)),d=it(l.headers);if(d.set("Cache-Control",_t),l.status==="signed-out")throw ut("signedOutPage",F(o,d));if(l.status==="forbidden")throw p===void 0?xe.data(null,{status:403,headers:d}):ut("forbiddenPage",p(o,d));const f=se.resolveExplorerLocation(a,s["*"],u.searchParams);if(f.kind==="redirect")throw xe.redirect(f.href,{headers:d});const{location:T}=f,{principal:M}=l,U=lt(r,C(M)),te=z.get(T.source);if(te===void 0)throw new RangeError(`[markdown-explorer] no source for ${JSON.stringify(T.source)}`);const we={signal:o.signal,timeoutMs:y,late:null,handOverMs:y},re={scope:U,sources:n.map(B=>({id:B.id,label:b(B,M)})),settings:se.parseViewSettings(se.readCookieValue(o.headers.get("Cookie"),t.settingsCookie),v),tree:T.view==="single"?null:{sourceId:T.source,result:ve(we,B=>Q(te,M,U,o,B).then(W=>W.result))},documents:_n(T).map(B=>({path:B,document:ve(we,W=>ce({principal:M,request:o,signal:W,refresh:!1},U,B))})),notices:ve({signal:o.signal,timeoutMs:y,late:Me,handOverMs:0},B=>ge({principal:M,request:o,signal:B,refresh:!1}))};return xe.data(re,{headers:d})},Ce=async(o,u)=>{const s=ct(await I(o,u));return{authentication:s,headers:it(s.headers)}},Ut=async(o,u,s)=>{let l;try{l=await Ce(u,st)}catch(W){return j(Y(at(W),{operation:"authenticate"},u.signal,c))}const{authentication:d,headers:f}=l;if(d.status==="signed-out")return j({reason:"unauthorized"},f);if(d.status==="forbidden")return j({reason:"forbidden"},f);const{principal:T}=d;if(o==="asset")return Lt({principal:T,request:u,signal:u.signal,refresh:!1},s,f);const M=lt(r,C(T));f.set(w.EXPLORER_SCOPE_HEADER,M);const U={principal:T,request:u,signal:u.signal,refresh:!1},te=()=>j({reason:"invalid"},f);if(o==="document"){const W=ue(s,w.EXPLORER_DATA_QUERY.path);if(W===null||!w.isAcceptableDocumentPath(W))return te();const Fe=u.headers.has(w.EXPLORER_PROOF_HEADER);return Fe&&!ft(u)?j({reason:"forbidden"},f):K(200,JSON.stringify(await ce({...U,refresh:Fe},M,W)),f)}if(o==="text"){const W=ue(s,w.EXPLORER_DATA_QUERY.path);return W===null||!w.isAcceptableDocumentPath(W)?te():K(200,JSON.stringify(await Dt(U,W)),f)}if(o==="edit"||o==="save"||o==="preview"||o==="revisions"||o==="revision")return h===void 0?j({reason:"not-found"},f):Bt(h,o,U,M,s,f);const we=ue(s,w.EXPLORER_DATA_QUERY.source),re=ue(s,w.EXPLORER_DATA_QUERY.path);if(we===null||(o==="children"||o==="ancestors"||o==="reveal")&&(re===null||!w.isAcceptableDocumentPath(re)))return te();const B=z.get(we);if(B===void 0)return j({reason:"not-found"},f);if(o==="tree")return K(200,(await Q(B,T,M,u,u.signal)).json,f);if(o==="refresh"){const W=await J(B,T,M,u);return u.signal.aborted||ae(B,R(B,M)),K(200,W.json,f)}return o==="ancestors"?B.ancestors===void 0||re===null?j({reason:"not-found"},f):K(200,JSON.stringify(await q(B,B.ancestors,U,re)),f):o==="reveal"?re===null?te():K(200,JSON.stringify(await ee(B,U,re)),f):B.children===void 0||re===null?j({reason:"not-found"},f):K(200,JSON.stringify(await H(B,B.children,U,re)),f)},Xt=async o=>{const{authentication:u,headers:s}=await Ce(o,Tn);if(!s.keys().next().done)throw new TypeError("[markdown-explorer] authenticate returned headers in read-only mode; a read-only authentication must only read the session (none was forwarded)");return u.status==="signed-in"},He=t.embeds.linkCardEndpoint===null?null:Jt.createLinkCardHandler({authorize:Xt}),Gt=async(o,u)=>{try{return await o(u)}catch(s){return j(Y(at(s),{operation:"authenticate"},u.signal,c))}},Be=async(o,u,s)=>{if(new URL(o.url).pathname.endsWith(".data"))return j({reason:"not-found"});if(!w.isExplorerDataOperation(s))return j({reason:"not-found"});if(s==="link-card"){if(He===null)return j({reason:"not-found"});const d=dt(o,s);return d!==null?d:Gt(He,o)}if(vn.has(s)&&h===void 0)return j({reason:"not-found"});const l=dt(o,s);if(l!==null)return l;if(s==="refresh"&&!ft(o))return j({reason:"forbidden"});if((s==="save"||s==="preview")&&!Nn(o))return j({reason:"forbidden"});try{return await Ut(s,o,u.searchParams)}catch(d){return j(Y(d,{operation:s},o.signal,c))}};return Object.freeze({loader:Ft,headers:Mn,dataLoader:({request:o,url:u,params:s})=>Be(o,u,s["*"]),dataAction:({request:o,url:u,params:s})=>Be(o,u,s["*"]),forgetTree:o=>{if(typeof o!="string")throw new TypeError(`[markdown-explorer] forgetTree needs the string key onTreeRefreshed received; got ${typeof o}`);$.forget(o)}})},Te=Object.freeze({maxEntries:2e4,maxDocumentBytes:2*1024*1024,textPreviewBytes:8*1024,walkConcurrency:8}),Dn=new Set(["md","markdown","mdx"]),At=new Map([...[["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"],["svg","image/svg+xml"],["webp","image/webp"],["ico","image/x-icon"],["bmp","image/bmp"],["tif","image/tiff"],["tiff","image/tiff"],["avif","image/avif"]].map(([e,t])=>[e,{kind:"image",contentType:t}]),...[["mp4","video/mp4"],["m4v","video/mp4"],["webm","video/webm"],["mov","video/quicktime"],["avi","video/x-msvideo"],["mkv","video/x-matroska"],["ogv","video/ogg"]].map(([e,t])=>[e,{kind:"media",mediaType:"video",contentType:t}]),...[["mp3","audio/mpeg"],["wav","audio/wav"],["ogg","audio/ogg"],["oga","audio/ogg"],["opus","audio/ogg"],["m4a","audio/mp4"],["flac","audio/flac"],["aac","audio/aac"],["wma","audio/x-ms-wma"]].map(([e,t])=>[e,{kind:"media",mediaType:"audio",contentType:t}]),["pdf",{kind:"media",mediaType:"pdf",contentType:"application/pdf"}]]),$n=new Set(["txt","text","log","csv","tsv","json","jsonc","json5","ndjson","yaml","yml","toml","ini","cfg","conf","properties","xml","xsl","xsd","dtd","html","htm","xhtml","css","scss","sass","less","styl","js","mjs","cjs","jsx","ts","mts","cts","tsx","vue","svelte","astro","py","pyi","rb","go","rs","java","kt","kts","scala","groovy","gradle","c","h","cc","cpp","cxx","hpp","hh","hxx","cs","fs","vb","swift","m","mm","php","pl","pm","r","jl","lua","dart","ex","exs","erl","hrl","hs","ml","mli","clj","cljs","elm","nim","zig","v","sol","tf","hcl","nix","sh","bash","zsh","fish","ps1","psm1","bat","cmd","sql","graphql","gql","proto","thrift","avsc","rst","adoc","asciidoc","tex","bib","org","textile","diff","patch","srt","vtt","ics","vcf","gitignore","gitattributes","editorconfig","dockerignore","npmignore","prettierrc","eslintrc","babelrc","mailmap"]),jn=new Set(["readme","license","licence","copying","notice","authors","contributors","changelog","changes","todo","makefile","dockerfile","containerfile","procfile","gemfile","rakefile","vagrantfile","jenkinsfile","brewfile","codeowners"]),vt=typeof ie.constants.O_NOFOLLOW=="number"?ie.constants.O_NOFOLLOW:0,Nt=typeof ie.constants.O_NONBLOCK=="number"?ie.constants.O_NONBLOCK:0,mt=e=>`${e.size}-${e.mtimeNs}`,zn=e=>e!==""&&e!=="."&&e!==".."&&!e.includes(":")&&!e.endsWith(".")&&!e.endsWith(" "),pt=e=>w.isAcceptableDocumentPath(e)&&e===e.normalize("NFC")&&e.split("/").every(zn),Pt=e=>{const t=e.toLowerCase(),r=t.lastIndexOf(".");return r<0?"":t.slice(r+1)},Cn=e=>{const t=Pt(e);if(Dn.has(t))return{kind:"markdown"};const r=At.get(t);if(r!==void 0)return r.kind==="image"?{kind:"image"}:{kind:"media",mediaType:r.mediaType};const n=e.toLowerCase();return $n.has(t)||!n.includes(".")&&jn.has(n)?{kind:"text"}:{kind:"file"}},De=e=>{switch(typeof e=="object"&&e!==null?e.code:void 0){case"ENOENT":case"ENOTDIR":return"not-found";case"ELOOP":case"EACCES":case"EPERM":return"forbidden";case"ENAMETOOLONG":return"invalid";case"EISDIR":return"unsupported";default:return null}},It=e=>{const t=De(e);return t===null?e:new ye(t)},Mt=e=>{const t=typeof e=="object"&&e!==null?e.code:void 0;return t==="EACCES"||t==="EPERM"||t==="ENOENT"||t==="ENOTDIR"},Hn=async e=>{try{return Math.trunc((await me.lstat(e)).mtimeMs)}catch(t){if(Mt(t))return;throw t}},ht=async(e,t)=>{const r=[];for await(const n of e.createReadStream({start:0,end:t-1,autoClose:!1}))r.push(n);return Buffer.concat(r)},Bn=(e,t)=>e!==null?{start:e.offset,end:e.offset+e.length-1}:t===0n?{}:{start:0,end:Number(t)-1},Fn=async(e,t,r,n)=>{let a;try{a=await me.open(e,ie.constants.O_RDONLY|vt|Nt);const y=await a.stat({bigint:!0});if(!y.isFile()||y.ino!==t.ino||y.dev!==t.dev||y.size!==t.size||y.mtimeNs!==t.mtimeNs)throw new ye("not-found")}catch(y){throw await a?.close(),It(y)}const i=a.createReadStream(Bn(r,t.size)),c=Wt.Readable.toWeb(i),m=()=>{i.destroy(n.reason)};return n.aborted?m():n.addEventListener("abort",m,{once:!0}),c},Un=(e,t)=>{const r=se.NAME_COLLATOR.compare(e,t);return r!==0?r:e===t?0:e<t?-1:1},Xn=e=>{let t=0;const r=[];return async n=>{t<e?t+=1:await new Promise(a=>r.push(a));try{return await n()}finally{const a=r.shift();a===void 0?t-=1:a()}}},Gn=(e,t)=>{if(e.isSymbolicLink())return"symbolic-link";if(!(e.isDirectory()||e.isFile()))return"special-file";const{name:r}=e;return r!==r.normalize("NFC")?"not-nfc":r.includes(":")?"colon":r.endsWith(".")||r.endsWith(" ")?"trailing-dot-or-space":w.isAcceptableDocumentPath(r)?w.isAcceptableDocumentPath(t)?null:"path-too-long":"control-character-or-backslash"},Jn=new Set(["id","label","root","pathPrefix","parse","deny","maxEntries","maxDocumentBytes","textPreviewBytes","walkConcurrency","cacheScope","reportSkipped"]),Se=(e,t,r)=>{if(t===void 0)return r;if(typeof t!="number"||!Number.isSafeInteger(t)||t<=0)throw new RangeError(`[markdown-explorer] ${e} must be a positive integer; got ${String(t)}`);return t},Yn=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] createFileSystemSource needs an options object");for(const b of Object.keys(e))if(!Jn.has(b))throw new TypeError(`[markdown-explorer] createFileSystemSource does not know the option ${JSON.stringify(b)}`);const{id:t,label:r,root:n,parse:a}=e;if(typeof t!="string"||t==="")throw new TypeError("[markdown-explorer] a file-system source needs a non-empty id");if(typeof r!="string"||r.trim()==="")throw new TypeError("[markdown-explorer] a file-system source needs a non-blank label");if(typeof a!="function")throw new TypeError("[markdown-explorer] a file-system source needs a parse function");if(typeof n!="string"||!ne.isAbsolute(n))throw new RangeError(`[markdown-explorer] root must be an absolute path; got ${JSON.stringify(n)}`);let i;try{i=ie.statSync(n).isDirectory()}catch(b){throw new RangeError(`[markdown-explorer] root does not exist: ${n}`,{cause:b})}if(!i)throw new RangeError(`[markdown-explorer] root is not a directory: ${n}`);const c=ie.realpathSync(n),m=e.pathPrefix;if(typeof m!="string")throw new TypeError('[markdown-explorer] pathPrefix is required: "" for a source over the whole root, or relative segments ending with "/"');if(m!==""&&!(m.endsWith("/")&&pt(m.slice(0,-1))))throw new RangeError(`[markdown-explorer] pathPrefix must be empty or relative segments ending with "/"; got ${JSON.stringify(m)}`);const y=w.resolvePathRules(e.deny),O=Se("maxEntries",e.maxEntries,Te.maxEntries),h=Se("maxDocumentBytes",e.maxDocumentBytes,Te.maxDocumentBytes),g=Se("textPreviewBytes",e.textPreviewBytes,Te.textPreviewBytes),k=Se("walkConcurrency",e.walkConcurrency,Te.walkConcurrency),A=e.cacheScope===void 0?"principal":e.cacheScope;if(A!=="principal"&&A!=="shared")throw new RangeError(`[markdown-explorer] cacheScope must be "principal" or "shared"; got ${JSON.stringify(A)}`);const $=e.reportSkipped;if($!==void 0&&typeof $!="function")throw new TypeError("[markdown-explorer] reportSkipped must be a function");const N=$===void 0?b=>{console.warn(`[markdown-explorer] the file-system source ${JSON.stringify(b.sourceId)} does not list ${JSON.stringify(b.path)}: ${b.reason}`)}:$,_=new Set,z=b=>{const R=ne.resolve(c,...b.split("/")),S=ne.relative(c,R);return S===""||S===".."||S.startsWith(`..${ne.sep}`)||ne.isAbsolute(S)?null:R},v=(b,R)=>{const S=`${R}\0${b}`;_.has(S)||_.size>=O||(_.add(S),N({sourceId:t,path:b,reason:R}))},I=async({signal:b})=>{b.throwIfAborted();const R=new AbortController,S=()=>{R.abort(b.reason)};b.addEventListener("abort",S,{once:!0});const P=Xn(k);let L=0;const X=async(D,G)=>{const Q=await P(async()=>{R.signal.throwIfAborted();try{return await me.readdir(D,{withFileTypes:!0})}catch(H){if(G===""||!Mt(H))throw H;return null}});if(R.signal.throwIfAborted(),Q===null)return v(`${m}${G}`,"unreadable-directory"),null;const J=[];for(const H of Q){if(y.deniesName(H.name))continue;const Z=G===""?H.name:`${G}/${H.name}`,q=`${m}${Z}`,ee=Gn(H,q);if(ee!==null){v(q,ee);continue}J.push({dirent:H,relativePath:Z,path:q})}if(L+=J.length,L>O)throw new ye("too-large");return J.sort((H,Z)=>Un(H.dirent.name,Z.dirent.name)),(await Promise.all(J.map(async({dirent:H,relativePath:Z,path:q})=>{const ee=await Hn(ne.join(D,H.name)),ce=ee===void 0?{}:{modifiedAt:ee};if(!H.isDirectory())return{name:H.name,path:q,type:"file",...ce};const ge=await X(ne.join(D,H.name),Z);return ge===null?null:{name:H.name,path:q,type:"directory",...ce,children:ge}}))).filter(H=>H!==null)};try{const D=await X(c,"");if(D===null)throw new Error("[markdown-explorer] the source's root could not be listed");return D}catch(D){throw R.abort(),D}finally{b.removeEventListener("abort",S)}},C=async b=>{if(!b.startsWith(m))return{status:"refused",reason:"not-found"};const R=b.slice(m.length);if(!pt(R))return{status:"refused",reason:"invalid"};if(y.deniesPath(R))return{status:"refused",reason:"forbidden"};const S=z(R);if(S===null)return{status:"refused",reason:"forbidden"};const P=await me.lstat(S,{bigint:!0});if(P.isSymbolicLink())return{status:"refused",reason:"forbidden"};if(!P.isFile())return{status:"refused",reason:"unsupported"};const L=await me.realpath(S);return L!==S||y.deniesPath(ne.relative(c,L).split(ne.sep).join("/"))?{status:"refused",reason:"forbidden"}:{status:"file",target:S,name:R.slice(R.lastIndexOf("/")+1),stats:P}},F=async(b,R,S)=>{let P;try{const L=await C(S);if(L.status==="refused")return w.failureDocument(L.reason);const{target:X,name:D,stats:G}=L,Q=Cn(D),J=mt(G);if(Q.kind==="image")return{kind:"image",name:D,version:J};if(Q.kind==="media")return{kind:"media",name:D,mediaType:Q.mediaType,version:J};if(Q.kind==="file")return{kind:"file",name:D,version:J};P=await me.open(X,ie.constants.O_RDONLY|vt|Nt);const ae=await P.stat({bigint:!0});if(!ae.isFile()||ae.ino!==G.ino||ae.dev!==G.dev)return w.failureDocument("forbidden");if(Q.kind==="markdown"){if(ae.size>BigInt(h))return w.failureDocument("too-large");const ee=await ht(P,h+1);if(ee.length>h)return w.failureDocument("too-large");const ce=await a(new TextDecoder("utf-8").decode(ee),R);return{kind:"markdown",name:D,htmlContent:ce.htmlContent,headings:ce.headings,edit:null}}const H=await ht(P,g);if(H.includes(0))return{kind:"file",name:D,version:J};const Z=ae.size>BigInt(g),q=new TextDecoder("utf-8").decode(H,{stream:Z});return{kind:"text",name:D,text:q,truncated:Z,version:J}}catch(L){const X=De(L);if(X===null)throw L;return w.failureDocument(X)}finally{await P?.close()}},p=async(b,R,S)=>{let P;try{P=await C(S)}catch(J){throw It(J)}if(P.status==="refused")throw new ye(P.reason);const{target:L,name:X,stats:D}=P,G=At.get(Pt(X)),Q=G===void 0?"":G.contentType;return{name:X,contentType:Q,size:Number(D.size),version:mt(D),open:J=>Fn(L,D,J,b.signal)}},E=async(b,R,S)=>{let P;try{P=await C(S)}catch(D){if(De(D)!==null)return null;throw D}if(P.status==="refused")return null;const L=S.slice(m.length).split("/");if(L.some(D=>y.deniesName(D)))return null;const X=L.slice(0,-1);return X.map((D,G)=>`${m}${X.slice(0,G+1).join("/")}`)};return Object.freeze({id:t,label:r,cacheScope:A,boundary:Object.freeze({contains:b=>b.startsWith(m)}),tree:I,ancestors:E,document:F,asset:p})};exports.DEFAULT_DENIED_PATH_SEGMENTS=w.DEFAULT_DENIED_PATH_SEGMENTS;exports.MAX_DOCUMENT_PATH_LENGTH=w.MAX_DOCUMENT_PATH_LENGTH;exports.isAcceptableDocumentPath=w.isAcceptableDocumentPath;exports.isDeniedPath=w.isDeniedPath;exports.ExplorerError=ye;exports.anonymousAccess=Kt;exports.createFileSystemSource=Yn;exports.createMarkdownExplorer=Ln;
package/dist/server.js CHANGED
@@ -1,10 +1,10 @@
1
- import { b as Tt, c as nr, f as ke, d as or, g as sr, h as ir, j as ar, E as kt, k as he, r as cr, l as ur, i as q, m as dr, n as lr, o as fr, p as St, q as mr, s as pr, t as $e, u as wr, v as hr, w as yr, x as ae, y as Q, e as Fe, z as gr, A as Er } from "./dataRoute-CU9CKP44.js";
2
- import { D as ns, M as os, B as ss } from "./dataRoute-CU9CKP44.js";
1
+ import { b as Tt, c as nr, f as ke, g as or, h as sr, j as ir, k as ar, E as kt, l as he, r as cr, m as ur, i as q, n as dr, o as lr, p as fr, q as St, s as mr, t as pr, u as $e, v as wr, w as hr, x as yr, y as ae, z as Q, e as Fe, A as gr, B as Er } from "./dataRoute-Pm_0ue_4.js";
2
+ import { D as ns, M as os, C as ss } from "./dataRoute-Pm_0ue_4.js";
3
3
  import { createHash as br, createHmac as Tr } from "node:crypto";
4
4
  import { createLinkCardHandler as kr } from "@aiquants/markdown/server";
5
5
  import { crossOriginRefusal as xt, NO_CROSS_ORIGIN_NAVIGATION as Ot } from "@aiquants/request-isolation";
6
6
  import { data as Ue, redirect as Sr } from "react-router";
7
- import { w as xr, d as Or, r as Rr, i as vr, a as _r, p as Ar, b as Nr, f as Ir, N as Pr } from "./location-BT23fKeh.js";
7
+ import { w as xr, d as Or, r as Rr, i as vr, a as _r, p as Ar, b as Nr, f as Ir, N as Pr } from "./location-DWd6SQhN.js";
8
8
  import { existsSync as Mr, statSync as $r, realpathSync as Lr, constants as me } from "node:fs";
9
9
  import { extname as jr, isAbsolute as Xe, relative as Je, sep as Ge, join as Ye, resolve as zr } from "node:path";
10
10
  import { fileURLToPath as Oe } from "node:url";
@@ -1,3 +1,3 @@
1
1
  /*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */
2
2
  /*! @aiquants/markdown-explorer — component styles, layered in `components`. The layer order is pinned first (theme, base, components, utilities, as Tailwind CSS declares it), so a Tailwind host's preflight in `base` cannot override the explorer when this sheet is the first to name a layer. */
3
- @layer theme,base;@layer components{.aqmx-root{--aqmx-space-1:.0625rem;--aqmx-space-2:.125rem;--aqmx-space-3:.1875rem;--aqmx-space-4:.3125rem;--aqmx-space-5:.5rem;--aqmx-space-6:.8125rem;--aqmx-space-7:1.3125rem;--aqmx-space-8:2.125rem;--aqmx-space-9:3.4375rem;--aqmx-control:2.125rem;--aqmx-focus-ring-width:var(--aqmx-space-2);--aqmx-focus-ring-offset:var(--aqmx-space-2);--aqmx-icon:1rem;--aqmx-radius-s:.3125rem;--aqmx-radius-m:.5rem;--aqmx-radius-l:.8125rem;--aqmx-duration-1:89ms;--aqmx-duration-2:.144s;--aqmx-duration-3:.233s;--aqmx-duration-4:.377s;--aqmx-delay-progress:.233s;--aqmx-ease:cubic-bezier(.2, 0, 0, 1);--aqmx-font-size-body:.8125rem;--aqmx-font-size-title:1rem;--aqmx-font-size-display:1.3125rem;--aqmx-line-height-compact:1.382;--aqmx-line-height-prose:1.618;--aqmx-column-measure:40ch;--aqmx-surface:#fff;--aqmx-surface-raised:#f8fafc;--aqmx-surface-sunken:#f1f5f9;--aqmx-border:#cbd5e1;--aqmx-border-strong:#94a3b8;--aqmx-text:#0f172a;--aqmx-text-muted:#475569;--aqmx-accent:#1d4ed8;--aqmx-accent-surface:#dbeafe;--aqmx-tree-line:#64748b;--aqmx-tree-row-tint:#0f172a0f;--aqmx-tree-row-accent-tint:#2563eb29;--aqmx-focus:#2563eb;--aqmx-info-surface:#eff6ff;--aqmx-info-border:#93c5fd;--aqmx-info-text:#1e3a8a;--aqmx-warning-surface:#fffbeb;--aqmx-warning-border:#fcd34d;--aqmx-warning-text:#78350f;--aqmx-danger-surface:#fef2f2;--aqmx-danger-border:#fca5a5;--aqmx-danger-text:#7f1d1d;--aqmx-syntax-heading:#1e3a8a;--aqmx-syntax-link:#1e40af;--aqmx-syntax-url:#5b21b6;--aqmx-syntax-code:#9a3412;--aqmx-syntax-quote:#334155;--aqmx-syntax-mark:#475569;--aqmx-editor-gutter:#334155;--aqmx-editor-selection:#2563eb36;--aqmx-editor-active-line:#0f172a0d;--aqmx-conflict-ours-tint:#16a34a21;--aqmx-conflict-theirs-tint:#2563eb21;--aqmx-conflict-marker-tint:#d9770636;--aqmx-shadow:0 .0625rem .1875rem #0f172a21, 0 .3125rem .8125rem #0f172a14}.aqmx-root[data-aqmx-theme=dark]{--aqmx-surface:#0f172a;--aqmx-surface-raised:#1e293b;--aqmx-surface-sunken:#020617;--aqmx-border:#334155;--aqmx-border-strong:#64748b;--aqmx-text:#e2e8f0;--aqmx-text-muted:#94a3b8;--aqmx-accent:#93c5fd;--aqmx-accent-surface:#1e3a8a;--aqmx-tree-line:#94a3b8;--aqmx-tree-row-tint:#e2e8f00f;--aqmx-tree-row-accent-tint:#2563eb70;--aqmx-focus:#60a5fa;--aqmx-info-surface:#172554;--aqmx-info-border:#1d4ed8;--aqmx-info-text:#bfdbfe;--aqmx-warning-surface:#422006;--aqmx-warning-border:#a16207;--aqmx-warning-text:#fde68a;--aqmx-danger-surface:#450a0a;--aqmx-danger-border:#b91c1c;--aqmx-danger-text:#fecaca;--aqmx-syntax-heading:#93c5fd;--aqmx-syntax-link:#a5b4fc;--aqmx-syntax-url:#c4b5fd;--aqmx-syntax-code:#fdba74;--aqmx-syntax-quote:#cbd5e1;--aqmx-syntax-mark:#cbd5e1;--aqmx-editor-gutter:#cbd5e1;--aqmx-editor-selection:#3b82f657;--aqmx-editor-active-line:#e2e8f00d;--aqmx-conflict-ours-tint:#22c55e36;--aqmx-conflict-theirs-tint:#3b82f636;--aqmx-conflict-marker-tint:#f59e0b36;--aqmx-shadow:0 .0625rem .1875rem #0000008c, 0 .3125rem .8125rem #00000057}@media (pointer:coarse){.aqmx-root{--aqmx-control:2.75rem}}@media (forced-colors:active){.aqmx-root.aqmx-root[data-aqmx-theme]{--aqmx-tree-line:CanvasText}}@media (prefers-reduced-motion:reduce){.aqmx-root{--aqmx-duration-1:0s;--aqmx-duration-2:0s;--aqmx-duration-3:0s;--aqmx-duration-4:0s}}.aqmx-root{block-size:100%;min-block-size:0;inline-size:100%;min-inline-size:0;color:var(--aqmx-text);background:var(--aqmx-surface);font-size:var(--aqmx-font-size-body);line-height:var(--aqmx-line-height-compact);flex-direction:column;display:flex;position:relative}.aqmx-root *,.aqmx-root :before,.aqmx-root :after{box-sizing:border-box}.aqmx-icon-button{inline-size:var(--aqmx-control);block-size:var(--aqmx-control);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text-muted);cursor:pointer;transition:background-color var(--aqmx-duration-2) var(--aqmx-ease), color var(--aqmx-duration-2) var(--aqmx-ease);background:0 0;border:0;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.aqmx-icon-button:hover{color:var(--aqmx-text);background:var(--aqmx-surface-sunken)}.aqmx-icon-button[aria-pressed=true],.aqmx-icon-button[aria-expanded=true]{color:var(--aqmx-accent);background:var(--aqmx-accent-surface)}.aqmx-icon-button:disabled{opacity:.382;cursor:not-allowed}.aqmx-icon-button[aria-disabled=true]{cursor:not-allowed}.aqmx-icon-button[aria-disabled=true]:hover{color:var(--aqmx-text-muted);background:0 0}.aqmx-icon-button>svg{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon)}.aqmx-icon-button[aria-disabled=true]>svg{opacity:.382}.aqmx-root :focus-visible{outline:var(--aqmx-focus-ring-width) solid var(--aqmx-focus);outline-offset:var(--aqmx-focus-ring-offset)}.aqmx-callout{gap:var(--aqmx-space-5);padding:var(--aqmx-space-6);border:var(--aqmx-space-1) solid var(--aqmx-info-border);border-radius:var(--aqmx-radius-l);color:var(--aqmx-info-text);background:var(--aqmx-info-surface);line-height:var(--aqmx-line-height-prose);display:grid}.aqmx-callout[data-aqmx-tone=warning]{border-color:var(--aqmx-warning-border);color:var(--aqmx-warning-text);background:var(--aqmx-warning-surface)}.aqmx-callout[data-aqmx-tone=danger]{border-color:var(--aqmx-danger-border);color:var(--aqmx-danger-text);background:var(--aqmx-danger-surface)}.aqmx-callout-title{font-size:var(--aqmx-font-size-title);font-weight:600;line-height:var(--aqmx-line-height-compact);margin:0}.aqmx-callout-body{margin:0}.aqmx-callout-action{min-block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-6);border:var(--aqmx-space-1) solid currentColor;border-radius:var(--aqmx-radius-m);color:inherit;font:inherit;cursor:pointer;background:0 0;justify-self:start;align-items:center;font-weight:600;text-decoration:none;display:inline-flex}.aqmx-progress{z-index:2;block-size:var(--aqmx-space-3);pointer-events:none;position:absolute;inset-block-start:0;inset-inline:0;overflow:hidden}.aqmx-progress:before{content:"";background:var(--aqmx-accent);inline-size:38.1966%;animation:aqmx-progress calc(var(--aqmx-duration-4) * 3) var(--aqmx-ease) infinite;position:absolute;inset-block:0}@keyframes aqmx-progress{0%{inset-inline-start:-38.1966%}to{inset-inline-start:100%}}.aqmx-empty{place-content:center;justify-items:center;gap:var(--aqmx-space-6);block-size:100%;padding:var(--aqmx-space-8);color:var(--aqmx-text-muted);text-align:center;line-height:var(--aqmx-line-height-prose);display:grid}.aqmx-empty-title{color:var(--aqmx-text);font-size:var(--aqmx-font-size-title);margin:0;font-weight:600}.aqmx-skeleton{gap:var(--aqmx-space-6);padding:var(--aqmx-space-7);display:grid}.aqmx-skeleton>span{block-size:var(--aqmx-space-6);border-radius:var(--aqmx-radius-s);background:var(--aqmx-surface-sunken);animation:aqmx-pulse calc(var(--aqmx-duration-4) * 4) ease-in-out infinite;display:block}.aqmx-skeleton>span:nth-child(3n+1){inline-size:61.8034%}.aqmx-skeleton>span:nth-child(3n+2){inline-size:100%}.aqmx-skeleton>span:nth-child(3n){inline-size:85.4102%}@keyframes aqmx-pulse{50%{opacity:.618}}.aqmx-sr-only{clip:rect(0, 0, 0, 0);white-space:nowrap;border:0;block-size:1px;inline-size:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.aqmx-toast{z-index:60;max-inline-size:min(34rem, calc(100% - var(--aqmx-space-8)));padding:var(--aqmx-space-5) var(--aqmx-space-6);border:var(--aqmx-space-1) solid var(--aqmx-warning-border);border-radius:var(--aqmx-radius-m);color:var(--aqmx-warning-text);background:var(--aqmx-warning-surface);box-shadow:var(--aqmx-shadow);position:absolute;inset-block-start:var(--aqmx-space-6);inset-inline-end:var(--aqmx-space-7)}@media (prefers-reduced-motion:reduce){.aqmx-progress:before,.aqmx-skeleton>span{animation:none}}@media (forced-colors:active){.aqmx-icon-button[aria-pressed=true],.aqmx-icon-button[aria-expanded=true]{forced-color-adjust:none;color:highlighttext;background:highlight}.aqmx-icon-button[aria-disabled=true]{color:graytext}.aqmx-root :focus-visible{outline-color:highlight}.aqmx-progress:before{forced-color-adjust:none;background:highlight}.aqmx-skeleton>span{forced-color-adjust:none;background:graytext}}.aqmx-explorer{gap:var(--aqmx-space-5);block-size:100%;min-block-size:0;min-inline-size:0;padding:var(--aqmx-space-4);color:var(--aqmx-text);background:var(--aqmx-surface);flex-direction:column;display:flex;position:relative;overflow-y:auto}.aqmx-explorer-header{align-items:center;gap:var(--aqmx-space-4);min-block-size:var(--aqmx-control);flex-wrap:wrap;flex:none;display:flex}.aqmx-explorer-source{min-inline-size:min(100%,9rem);block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-5);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text);background:var(--aqmx-surface-raised);font:inherit;text-overflow:ellipsis;cursor:pointer;flex:9rem}.aqmx-explorer-actions{justify-content:flex-end;align-items:center;gap:var(--aqmx-space-2);flex-wrap:wrap;flex:0 auto;min-inline-size:0;margin-inline-start:auto;display:flex}.aqmx-explorer-body{gap:var(--aqmx-space-5);flex-direction:column;flex:1 1 0;min-block-size:0;min-inline-size:0;display:flex;position:relative}.aqmx-labelled-button{gap:var(--aqmx-space-2);min-inline-size:var(--aqmx-control);inline-size:auto;padding-inline:var(--aqmx-space-3);white-space:nowrap;flex:0 auto;display:inline-flex}.aqmx-labelled-button>svg{flex:none}.aqmx-labelled-button>span{text-overflow:ellipsis;min-inline-size:0;overflow:hidden}.aqmx-explorer-refresh-failure,.aqmx-explorer-expand-all-stop{padding:var(--aqmx-space-4) var(--aqmx-space-5);border:var(--aqmx-space-1) solid;border-radius:var(--aqmx-radius-m);line-height:var(--aqmx-line-height-compact);overflow-wrap:anywhere;flex:none;margin:0}.aqmx-explorer-refresh-failure{border-color:var(--aqmx-danger-border);color:var(--aqmx-danger-text);background:var(--aqmx-danger-surface)}.aqmx-explorer-expand-all-stop{border-color:var(--aqmx-info-border);color:var(--aqmx-info-text);background:var(--aqmx-info-surface)}.aqmx-explorer-actions>.aqmx-labelled-button[data-aqmx-busy=true]>svg{animation:aqmx-explorer-spin calc(var(--aqmx-duration-4) * 3) linear infinite}@keyframes aqmx-explorer-spin{to{rotate:1turn}}.aqmx-explorer-actions>.aqmx-icon-button[aria-busy=true]{cursor:progress}.aqmx-explorer-menu{z-index:50;gap:var(--aqmx-space-1);max-block-size:100%;inline-size:min(21rem,100%);padding:var(--aqmx-space-3);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);background:var(--aqmx-surface-raised);box-shadow:var(--aqmx-shadow);display:grid;position:absolute;inset-block-start:0;inset-inline-end:0;overflow-y:auto}.aqmx-explorer-menu-item{align-items:center;gap:var(--aqmx-space-5);inline-size:100%;min-block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-5);border-radius:var(--aqmx-radius-s);color:var(--aqmx-text);font:inherit;text-align:start;cursor:pointer;transition:background-color var(--aqmx-duration-1) var(--aqmx-ease);background:0 0;border:0;display:flex}.aqmx-explorer-menu-item:hover,.aqmx-explorer-menu-item:focus-visible{background:var(--aqmx-surface-sunken)}.aqmx-explorer-menu-icon{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon);color:var(--aqmx-text-muted);flex:none}.aqmx-explorer-menu-name{text-overflow:ellipsis;white-space:nowrap;flex:auto;min-inline-size:0;overflow:hidden}.aqmx-explorer-menu-value{color:var(--aqmx-accent);font-variant-numeric:tabular-nums;flex:none;font-weight:600}.aqmx-explorer-notices{gap:var(--aqmx-space-5);flex:none;display:grid}.aqmx-explorer-tree-area{min-block-size:calc(var(--aqmx-control) * 3);flex-direction:column;flex:1 1 0;min-inline-size:0;display:flex;position:relative}.aqmx-explorer-tree{flex:1 1 0;min-block-size:0;position:relative}.aqmx-explorer-tree-view{block-size:100%}.aqmx-explorer-tree-progress{z-index:1;align-items:center;gap:var(--aqmx-space-2) var(--aqmx-space-4);max-inline-size:calc(100% - var(--aqmx-space-5) * 3);padding:var(--aqmx-space-3) var(--aqmx-space-5);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text-muted);background:var(--aqmx-surface-raised);box-shadow:var(--aqmx-shadow);line-height:var(--aqmx-line-height-compact);overflow-wrap:anywhere;pointer-events:none;animation:aqmx-appear var(--aqmx-duration-2) ease-out var(--aqmx-delay-progress) both;flex-wrap:wrap;margin:0;display:flex;position:absolute;inset-block-end:var(--aqmx-space-9);inset-inline-start:var(--aqmx-space-5)}.aqmx-explorer-tree-progress-icon{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon);animation:aqmx-explorer-spin calc(var(--aqmx-duration-4) * 3) linear infinite;flex:none}@keyframes aqmx-appear{0%{opacity:0}}.aqmx-explorer-tree-probe{inline-size:0;block-size:var(--aqmx-control);visibility:hidden;pointer-events:none;color:var(--aqmx-tree-line);forced-color-adjust:none;position:absolute;inset-block-start:0;inset-inline-start:0;overflow:hidden}.aqmx-explorer-loading{gap:var(--aqmx-space-5);padding:var(--aqmx-space-6) var(--aqmx-space-5);color:var(--aqmx-text-muted);display:grid}.aqmx-explorer-loading-text{margin:0}.aqmx-explorer-loading>.aqmx-skeleton{padding:0}.aqmx-explorer-tree-message{padding:var(--aqmx-space-5);overflow-y:auto}.aqmx-explorer-empty-icon{inline-size:var(--aqmx-space-8);block-size:var(--aqmx-space-8);color:var(--aqmx-border-strong)}.aqmx-explorer-empty-body{margin:0}.aqmx-explorer-tree [role=treeitem]{border-radius:var(--aqmx-radius-s);color:var(--aqmx-text);transition:background-color var(--aqmx-duration-1) var(--aqmx-ease)}.aqmx-explorer-tree [role=treeitem]:hover{color:var(--aqmx-text);background:var(--aqmx-tree-row-tint)}.aqmx-explorer-tree [role=treeitem][data-entry-item-selected=true]{color:var(--aqmx-text);background:var(--aqmx-tree-row-tint);box-shadow:inset var(--aqmx-space-2) 0 0 currentColor}.aqmx-explorer-tree [role=treeitem][data-entry-selected=true],.aqmx-explorer-tree [role=treeitem][data-aqmx-open=true]{color:var(--aqmx-accent);background:var(--aqmx-tree-row-accent-tint)}.aqmx-explorer-tree [role=treeitem]:focus-visible{outline-offset:calc(-1 * var(--aqmx-focus-ring-width))}.aqmx-explorer-tree [role=treeitem][data-entry-item-selected=true]:focus-visible{box-shadow:inset calc(var(--aqmx-space-2) + var(--aqmx-focus-ring-width)) 0 0 currentColor}.aqmx-explorer-tree [role=treeitem][data-aqmx-open=true]{font-weight:600}.aqmx-explorer-tree [role=treeitem][data-aqmx-children=loading]{animation:aqmx-pulse calc(var(--aqmx-duration-4) * 4) ease-in-out infinite}.aqmx-explorer-tree [role=treeitem][data-aqmx-loop]{color:var(--aqmx-text-muted);font-style:italic}.aqmx-explorer-folder-failed{--aqmx-folder-name-floor:3em;align-items:center;min-inline-size:0;max-inline-size:100%;display:flex}.aqmx-explorer-folder-name{flex:10000 1 var(--aqmx-folder-name-floor);text-overflow:ellipsis;white-space:nowrap;min-inline-size:0;max-inline-size:max-content;overflow:hidden}.aqmx-explorer-folder-error{min-inline-size:0;color:var(--aqmx-danger-text);text-indent:var(--aqmx-space-4);text-overflow:ellipsis;white-space:nowrap;flex:1 1 0;overflow:hidden}.aqmx-explorer-folder-retry{flex:1000000 0 calc(var(--aqmx-icon) + (var(--aqmx-space-3) + var(--aqmx-space-1)) * 2);min-inline-size:calc(var(--aqmx-icon) + (var(--aqmx-space-3) + var(--aqmx-space-1)) * 2);max-inline-size:max-content;min-block-size:var(--aqmx-control);padding:0 var(--aqmx-space-3);border:var(--aqmx-space-1) solid var(--aqmx-danger-border);border-radius:var(--aqmx-radius-s);color:var(--aqmx-danger-text);background:var(--aqmx-danger-surface);font:inherit;line-height:var(--aqmx-line-height-compact);cursor:pointer;justify-content:center;align-items:center;margin-inline-start:var(--aqmx-space-4);display:inline-flex;overflow:hidden}.aqmx-explorer-folder-retry:focus-visible{outline-offset:calc(-1 * (var(--aqmx-focus-ring-width) + var(--aqmx-space-1)))}.aqmx-explorer-folder-retry-icon{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon);flex:none}.aqmx-explorer-folder-retry-text{min-inline-size:0;text-indent:var(--aqmx-space-3);text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.aqmx-explorer-tray{gap:var(--aqmx-space-4);min-block-size:calc(var(--aqmx-control) + (var(--aqmx-space-5) + var(--aqmx-space-1)) * 2);padding:var(--aqmx-space-5);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);background:var(--aqmx-surface-raised);box-shadow:var(--aqmx-shadow);flex-direction:column;flex:0 auto;display:flex;overflow-y:auto}.aqmx-explorer-tray-header{justify-content:space-between;align-items:center;gap:var(--aqmx-space-5);flex:none;display:flex}.aqmx-explorer-tray-title{margin:0;font-weight:600}.aqmx-explorer-tray-button{min-block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-5);border-radius:var(--aqmx-radius-m);color:var(--aqmx-accent);font:inherit;cursor:pointer;background:0 0;border:0;flex:none;font-weight:600}.aqmx-explorer-tray-button:hover{background:var(--aqmx-surface-sunken)}.aqmx-explorer-tray-list{gap:var(--aqmx-space-1);min-block-size:var(--aqmx-control);max-block-size:calc(var(--aqmx-control) * 3);flex:0 auto;margin:0;padding:0;list-style:none;display:grid;overflow-y:auto}.aqmx-explorer-tray-item{align-items:center;gap:var(--aqmx-space-4);display:flex}.aqmx-explorer-tray-name{text-overflow:ellipsis;white-space:nowrap;flex:auto;min-inline-size:0;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;overflow:hidden}.aqmx-explorer-tray-open{min-block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-6);border-radius:var(--aqmx-radius-m);color:var(--aqmx-surface);background:var(--aqmx-accent);font:inherit;cursor:pointer;border:0;flex:none;font-weight:600}@media (forced-colors:active){.aqmx-explorer-tree [role=treeitem][data-entry-item-selected=true],.aqmx-explorer-tree [role=treeitem][data-entry-selected=true],.aqmx-explorer-tree [role=treeitem][data-aqmx-open=true],.aqmx-explorer-menu-item[aria-checked=true]{forced-color-adjust:none;color:highlighttext;background:highlight}.aqmx-explorer-menu-item[aria-checked=true] *,.aqmx-explorer-tree [role=treeitem][data-entry-item-selected=true] *,.aqmx-explorer-tree [role=treeitem][data-entry-selected=true] *,.aqmx-explorer-tree [role=treeitem][data-aqmx-open=true] *{color:inherit!important}.aqmx-explorer-tree [role=treeitem][data-entry-item-selected=true]:focus-visible,.aqmx-explorer-tree [role=treeitem][data-entry-selected=true]:focus-visible,.aqmx-explorer-tree [role=treeitem][data-aqmx-open=true]:focus-visible{outline-color:highlighttext}.aqmx-explorer-tray-button,.aqmx-explorer-tray-open,.aqmx-explorer-tray-remove{border:var(--aqmx-space-1) solid ButtonText}}@media (prefers-reduced-motion:reduce){.aqmx-explorer-actions>.aqmx-labelled-button[data-aqmx-busy=true]>svg,.aqmx-explorer-tree-progress-icon,.aqmx-explorer-tree [role=treeitem][data-aqmx-children=loading]{animation:none}.aqmx-explorer-tree-view{transition-duration:0s!important}}.aqmx-document{contain:layout paint;--aqmd-toolbar-inset-block-start:calc(var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset));block-size:100%;min-block-size:0;inline-size:100%;min-inline-size:0;color:var(--aqmx-text);background:var(--aqmx-surface);flex-direction:column;display:flex;position:relative;overflow:hidden}.aqmx-document-viewer:has([data-aqmd-scroll-bar]){--aqmd-toolbar-inset-inline-end:calc(var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset))}.aqmx-document [data-theme]{background-color:#0000!important}.aqmx-document .markdown-body :is(sup,sub) a{outline-offset:var(--aqmx-focus-ring-offset)!important}.aqmx-document *{scroll-margin:calc(var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset))}.aqmx-document[aria-busy=true]>:not(.aqmx-progress){opacity:.618;transition:opacity var(--aqmx-duration-3) var(--aqmx-ease)}.aqmx-document-viewer{flex:1 1 0;min-block-size:0;min-inline-size:0}.aqmx-document-notice{margin:var(--aqmx-space-6) var(--aqmx-space-7) 0;overflow-wrap:anywhere;flex:none}.aqmx-document-scroll-row{flex:1 1 0;min-block-size:0}.aqmx-document-failure{min-block-size:0;padding:var(--aqmx-space-7);flex:1 1 0;overflow:auto}.aqmx-document-file{flex-direction:column;flex:1 1 0;min-block-size:0;min-inline-size:0;display:flex}.aqmx-document-toolbar{align-items:center;gap:var(--aqmx-space-3);padding:var(--aqmx-space-3) var(--aqmx-space-6);border-block-end:var(--aqmx-space-1) solid var(--aqmx-border);background:var(--aqmx-surface-raised);flex-wrap:wrap;flex:none;display:flex}.aqmx-document-file-icon{color:var(--aqmx-text-muted);flex:none;display:inline-flex}.aqmx-document-file-icon>svg{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon)}.aqmx-document-title{text-overflow:ellipsis;white-space:nowrap;flex:1 1 0;min-inline-size:0;font-weight:600;overflow:hidden}.aqmx-document-level{min-inline-size:var(--aqmx-space-9);color:var(--aqmx-text-muted);font-variant-numeric:tabular-nums;text-align:center;flex:none}.aqmx-document-canvas{min-block-size:0;padding:var(--aqmx-space-7);background-color:var(--aqmx-surface-sunken);background-image:radial-gradient(var(--aqmx-border) var(--aqmx-space-1), transparent var(--aqmx-space-1));background-size:var(--aqmx-space-6) var(--aqmx-space-6);flex:1 1 0;grid-template:minmax(0,1fr)/minmax(0,1fr);display:grid;overflow:auto}.aqmx-document-image{margin:auto;display:block}.aqmx-document-image[data-aqmx-image-mode=fit]{object-fit:contain;max-block-size:100%;max-inline-size:100%}.aqmx-document-image[data-aqmx-image-mode=level]{max-block-size:none;max-inline-size:none}.aqmx-document-stage{min-block-size:0;padding:var(--aqmx-space-7);background:var(--aqmx-surface-sunken);flex:1 1 0;grid-template:minmax(0,1fr)/minmax(0,1fr);place-items:center;display:grid;overflow:auto}.aqmx-document-file[data-aqmx-media-type=pdf] .aqmx-document-stage{place-items:stretch stretch;padding:0}.aqmx-document-video{border-radius:var(--aqmx-radius-l);background:var(--aqmx-surface-raised);max-block-size:100%;max-inline-size:100%;box-shadow:var(--aqmx-shadow)}.aqmx-document-audio{inline-size:min(100%, var(--aqmx-column-measure))}.aqmx-document-frame{background:var(--aqmx-surface);border:0;block-size:100%;inline-size:100%}.aqmx-document-inert-link{color:var(--aqmx-text-muted);cursor:not-allowed;text-decoration-style:dotted}.aqmx-document[data-aqmx-document-flow=content]{contain:layout;block-size:auto;overflow:visible}.aqmx-document[data-aqmx-document-flow=content]>*,.aqmx-document[data-aqmx-document-flow=content] .aqmx-document-file>*{flex:none}.aqmx-document[data-aqmx-document-flow=content] .aqmx-document-frame{aspect-ratio:1/1.41421;block-size:auto}.aqmx-document-refresh-bar{flex-direction:column;flex:none;display:flex}.aqmx-document-refresh-row{justify-content:flex-end;align-items:center;gap:var(--aqmx-space-2);padding:calc(var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset));display:flex}.aqmx-document-column>.aqmx-document-refresh-bar>.aqmx-document-refresh-row{padding-inline-end:calc(var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset) + var(--aqmx-page-bar-inset-inline-end,0px))}.aqmx-document-refresh-failure{margin:0 var(--aqmx-space-3) var(--aqmx-space-2);padding:var(--aqmx-space-4) var(--aqmx-space-5);border:var(--aqmx-space-1) solid var(--aqmx-danger-border);border-radius:var(--aqmx-radius-m);color:var(--aqmx-danger-text);background:var(--aqmx-danger-surface);line-height:var(--aqmx-line-height-compact);overflow-wrap:anywhere}.aqmx-document-refresh-row>.aqmx-icon-button[data-aqmx-busy=true]>svg{animation:aqmx-explorer-spin calc(var(--aqmx-duration-4) * 3) linear infinite}.aqmx-document-refresh-row>.aqmx-icon-button[aria-busy=true]{cursor:progress}@media (prefers-reduced-motion:reduce){.aqmx-document-refresh-row>.aqmx-icon-button[data-aqmx-busy=true]>svg{animation:none}}.aqmx-edit{grid-template-columns:repeat(auto-fit, minmax(min(100%, var(--aqmx-column-measure)), 1fr));gap:var(--aqmx-space-1);background:var(--aqmx-border);flex:1 1 0;grid-auto-rows:minmax(0,1fr);min-block-size:0;min-inline-size:0;display:grid}.aqmx-edit[data-aqmx-edit-layout=content]{display:block}.aqmx-edit-editor,.aqmx-edit-preview{background:var(--aqmx-surface);min-block-size:0;min-inline-size:0}.aqmx-edit-editor{-webkit-user-select:text;user-select:text}.aqmx-edit-editor:has(.cm-content:focus-visible){outline:var(--aqmx-focus-ring-width) solid var(--aqmx-focus);outline-offset:calc(-1 * var(--aqmx-focus-ring-width))}.aqmx-edit-preview{flex-direction:column;display:flex;overflow:hidden}.aqmx-edit-editor [data-aqmx-conflict-line=ours]{background-color:var(--aqmx-conflict-ours-tint)}.aqmx-edit-editor [data-aqmx-conflict-line=theirs]{background-color:var(--aqmx-conflict-theirs-tint)}.aqmx-edit-editor [data-aqmx-conflict-line=marker]{background-color:var(--aqmx-conflict-marker-tint)}.aqmx-edit-editor [data-aqmx-conflict-actions]{gap:var(--aqmx-space-3);padding:var(--aqmx-space-3) var(--aqmx-space-6);background-color:var(--aqmx-conflict-marker-tint);font-family:system-ui,sans-serif;font-size:var(--aqmx-font-size-body);line-height:var(--aqmx-line-height-compact);flex-wrap:wrap;display:flex}.aqmx-edit-editor [data-aqmx-conflict-choice]{min-block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-6);border:var(--aqmx-space-1) solid var(--aqmx-border-strong);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text);background:var(--aqmx-surface);font:inherit;cursor:pointer;font-weight:600}.aqmx-edit-editor [data-aqmx-conflict-choice]:hover{background:var(--aqmx-surface-sunken)}.aqmx-multi-panel-frame .aqmx-document[data-aqmx-document-flow=content] .cm-panels-top{inset-block-start:var(--aqmx-multi-panel-pinned-block-size)!important}.aqmx-edit-message{min-block-size:0;padding:var(--aqmx-space-7);flex:1 1 0;overflow:auto}.aqmx-edit-grant-actions{gap:var(--aqmx-space-5);flex-wrap:wrap;display:flex}.aqmx-edit-status{min-inline-size:0;padding-inline:var(--aqmx-space-3);color:var(--aqmx-text-muted);text-overflow:ellipsis;white-space:nowrap;flex:1 1 0;margin:0;overflow:hidden}.aqmx-edit-status[data-aqmx-save=conflicts]{color:var(--aqmx-warning-text)}.aqmx-edit-status[data-aqmx-save=failed]{color:var(--aqmx-danger-text)}.aqmx-document-refresh-bar>.aqmx-edit-grant{margin:0 var(--aqmx-space-3) var(--aqmx-space-2)}.aqmx-confirm{inline-size:min(34rem, calc(100vw - 2 * var(--aqmx-space-7)));border:var(--aqmx-space-1) solid var(--aqmx-border-strong);border-radius:var(--aqmx-radius-l);max-inline-size:none;color:var(--aqmx-text);background:var(--aqmx-surface);box-shadow:var(--aqmx-shadow);padding:0}.aqmx-confirm::backdrop{background:#0f172a61}.aqmx-confirm-panel{gap:var(--aqmx-space-6);padding:var(--aqmx-space-7);display:grid}.aqmx-confirm-title{font-size:var(--aqmx-font-size-title);font-weight:600;line-height:var(--aqmx-line-height-compact);margin:0}.aqmx-confirm-body{line-height:var(--aqmx-line-height-prose);overflow-wrap:anywhere;margin:0}.aqmx-confirm-actions{justify-content:flex-end;gap:var(--aqmx-space-5);flex-wrap:wrap;display:flex}.aqmx-confirm-actions>.aqmx-callout-action{justify-self:auto}.aqmx-confirm-actions>[data-aqmx-tone=danger]{border-color:var(--aqmx-danger-border);color:var(--aqmx-danger-text);background:var(--aqmx-danger-surface)}.aqmx-confirm-actions>[aria-disabled=true]{opacity:.618;cursor:not-allowed}.aqmx-history{inline-size:min(55rem, calc(100vw - 2 * var(--aqmx-space-7)))}.aqmx-history-panel{max-block-size:calc(100vh - 2 * var(--aqmx-space-7));overflow:auto}.aqmx-history-note{color:var(--aqmx-text-muted);margin:0}.aqmx-history-list{gap:var(--aqmx-space-2);max-block-size:34vh;margin:0;padding:0;list-style:none;display:grid;overflow:auto}.aqmx-history-entry{align-items:center;gap:var(--aqmx-space-5);inline-size:100%;min-block-size:var(--aqmx-control);padding:var(--aqmx-space-3) var(--aqmx-space-5);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text);font:inherit;text-align:start;cursor:pointer;background:0 0;border:0;flex-wrap:wrap;display:flex}.aqmx-history-entry:hover{background:var(--aqmx-surface-sunken)}.aqmx-history-entry[aria-pressed=true]{color:var(--aqmx-accent);background:var(--aqmx-accent-surface)}.aqmx-history-mark{padding-inline:var(--aqmx-space-4);border:var(--aqmx-space-1) solid currentColor;border-radius:var(--aqmx-radius-s)}.aqmx-history-text{max-block-size:34vh;padding:var(--aqmx-space-6);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);background:var(--aqmx-surface-raised);overflow:auto}.aqmx-history-text>pre{white-space:pre-wrap;overflow-wrap:anywhere;margin:0;font-family:ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace}.aqmx-multi-stage{--aqmx-multi-panel-body-floor:calc(3rem * var(--aqmx-line-height-prose));--aqdd-stage-padding-block:var(--aqmx-space-7);--aqdd-stage-padding-inline:var(--aqmx-space-6) calc(var(--aqmx-space-6) + var(--aqmx-multi-stage-bar-gutter));--aqdd-column-gap:var(--aqmx-space-6);--aqdd-panel-surface:var(--aqmx-surface);--aqdd-panel-border:var(--aqmx-border);--aqdd-panel-title-color:var(--aqmx-text);--aqdd-header-button-color:var(--aqmx-text-muted);--aqdd-header-button-hover-color:var(--aqmx-text);--aqdd-header-button-hover-surface:var(--aqmx-surface-sunken);--aqdd-custom-badge-color:var(--aqmx-warning-text);--aqdd-custom-badge-surface:var(--aqmx-warning-surface);--aqdd-restore-button-color:var(--aqmx-surface);--aqdd-restore-button-surface:var(--aqmx-accent);--aqdd-restore-button-hover-surface:var(--aqmx-info-text);--aqdd-drop-placeholder-color:var(--aqmx-accent);--aqdd-drop-placeholder-surface:var(--aqmx-surface);--aqdd-drop-placeholder-target-surface:var(--aqmx-accent-surface);background:var(--aqmx-surface-sunken);block-size:100%;min-block-size:0;min-inline-size:0;color:var(--aqmx-text);flex-direction:column;display:flex;position:relative}.aqmx-multi-stage:focus-visible{outline:var(--aqmx-focus-ring-width) solid var(--aqmx-focus);outline-offset:calc(-1 * var(--aqmx-focus-ring-width))}.aqmx-multi-probe{inline-size:var(--aqmx-column-measure);visibility:hidden;pointer-events:none;block-size:0;font-size:1rem;position:absolute;inset-block-start:0;inset-inline-start:0;overflow:hidden}.aqmx-multi-layout{flex:auto;min-block-size:0}.aqmx-multi-skeleton{grid-template-columns:repeat(auto-fit, minmax(min(100%, var(--aqmx-column-measure)), 1fr));align-content:start;gap:var(--aqmx-space-7);padding:var(--aqmx-space-7);display:grid;overflow:hidden}.aqmx-multi-skeleton-column{border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-l);background:var(--aqmx-surface)}.aqmx-multi-column{min-inline-size:0}.aqmx-multi-panel{outline:var(--aqmx-space-1) solid var(--aqmx-border-strong);outline-offset:0;color:var(--aqmx-text)}.aqmx-multi-panel[data-maximized]{outline-color:var(--aqmx-focus)}.aqmx-multi-panel-frame{content-visibility:auto;contain-intrinsic-block-size:auto var(--aqmx-space-9);min-block-size:100%}.aqmx-multi-panel-frame:focus-visible{outline:var(--aqmx-focus-ring-width) solid var(--aqmx-focus);outline-offset:calc(-1 * var(--aqmx-focus-ring-width))}.aqmx-multi-panel-frame[data-aqmx-maximized=false]{-webkit-user-select:none;user-select:none}.aqmx-multi-panel-frame>.aqmx-document-refresh-bar{z-index:1;background:var(--aqmx-surface);position:sticky;inset-block-start:0}.aqmx-multi-panel-frame{--aqmx-multi-panel-pinned-block-size:0px}.aqmx-multi-panel-frame .aqmx-document[data-aqmx-document-flow=content] *{scroll-margin-block-start:calc(var(--aqmx-multi-panel-pinned-block-size) + var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset))}.aqmx-multi-panel-frame:has(>.aqmx-document[data-aqmx-document-flow=fill]){flex-direction:column;block-size:100%;display:flex}.aqmx-multi-panel-frame>.aqmx-document[data-aqmx-document-flow=fill]{flex:1 1 0;block-size:auto}.aqmx-multi-panel-frame .aqmx-document-toolbar>.aqmx-icon-button{flex-shrink:1;min-inline-size:0}.aqmx-multi-toast{animation:aqmx-multi-toast-in var(--aqmx-duration-3) var(--aqmx-ease)}.aqmx-multi-toast:popover-open{max-inline-size:min(34rem, calc(var(--aqmx-multi-toast-room) - var(--aqmx-space-8)));margin:0;position:fixed;inset:auto;inset-block-start:calc(var(--aqmx-multi-toast-block-start) + var(--aqmx-space-6));inset-inline-end:calc(var(--aqmx-multi-toast-inline-end) + var(--aqmx-space-7));overflow:visible}@keyframes aqmx-multi-toast-in{0%{opacity:0;translate:0 calc(var(--aqmx-space-5) * -1)}}@media (prefers-reduced-motion:reduce){.aqmx-multi-toast{animation:none}}@media (forced-colors:active){.aqmx-multi-stage:focus-visible,.aqmx-multi-stage :focus-visible,.aqmx-multi-panel[data-maximized]{outline-color:highlight}}.aqmx-split-frame{--aqmx-sheet-target:2.75rem;flex-direction:column;flex:auto;min-block-size:0;min-inline-size:0;display:flex;position:relative}.aqmx-rem-probe{visibility:hidden;pointer-events:none;block-size:0;inline-size:1rem;position:absolute;inset-block-start:0;inset-inline-start:0}.aqmx-split{flex:auto;min-block-size:0}.aqmx-split-explorer,.aqmx-split-content{background:var(--aqmx-surface);min-block-size:0}.aqmx-split-explorer{background:var(--aqmx-surface-raised)}.aqmx-split-handle{background:var(--aqmx-surface-raised);transition:background-color var(--aqmx-duration-2) var(--aqmx-ease)}.aqmx-split-handle:hover,.aqmx-split-handle:focus-visible{background:var(--aqmx-surface-sunken)}.aqmx-sheet-bar{padding:var(--aqmx-space-3) var(--aqmx-space-5);border-block-end:var(--aqmx-space-1) solid var(--aqmx-border);background:var(--aqmx-surface-raised);flex:none;align-items:center;display:flex}.aqmx-sheet-toggle,.aqmx-sheet-close{justify-content:center;align-items:center;gap:var(--aqmx-space-5);min-inline-size:var(--aqmx-sheet-target);min-block-size:var(--aqmx-sheet-target);padding:0 var(--aqmx-space-6);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text);background:var(--aqmx-surface);font:inherit;cursor:pointer;transition:background-color var(--aqmx-duration-2) var(--aqmx-ease);display:inline-flex}.aqmx-sheet-close{z-index:1;color:var(--aqmx-text-muted);background:var(--aqmx-surface-raised);border-color:#0000;padding:0;position:relative}.aqmx-sheet-toggle:hover,.aqmx-sheet-close:hover{background:var(--aqmx-surface-sunken)}.aqmx-sheet-toggle>svg,.aqmx-sheet-close>svg{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon);flex:none}.aqmx-sheet{inline-size:min(calc(100vw - var(--aqmx-space-9)), 21rem);border:0;border-inline-end:var(--aqmx-space-1) solid var(--aqmx-border);block-size:100dvh;max-block-size:none;max-inline-size:none;color:var(--aqmx-text);background:var(--aqmx-surface-raised);box-shadow:var(--aqmx-shadow);margin:0;padding:0;position:fixed;inset-block:0;inset-inline:0 auto}.aqmx-sheet::backdrop{background:#0f172a61}.aqmx-sheet-panel{flex-direction:column;block-size:100%;display:flex}.aqmx-sheet-header{z-index:1;justify-content:flex-end;align-items:center;gap:var(--aqmx-space-3);padding:var(--aqmx-space-3);border-block-end:var(--aqmx-space-1) solid var(--aqmx-border);flex:none;display:flex;position:relative}.aqmx-sheet-notice-slot>.aqmx-toast{--aqmx-sheet-notice-band:calc(var(--aqmx-sheet-target) + var(--aqmx-space-3) * 2);--aqmx-sheet-notice-line:calc(var(--aqmx-line-height-compact) * 1em);--aqmx-sheet-notice-inset:calc((var(--aqmx-sheet-notice-band) - var(--aqmx-sheet-notice-line)) / 2);z-index:0;max-inline-size:none;padding-block:var(--aqmx-sheet-notice-inset) 0;padding-inline:var(--aqmx-space-6) var(--aqmx-space-3);border:0;border-block-end:var(--aqmx-space-1) solid var(--aqmx-warning-border);line-height:var(--aqmx-line-height-compact);overflow-wrap:anywhere;box-shadow:none;border-radius:0;position:absolute;inset-block:0 auto;inset-inline:0}.aqmx-sheet-notice-slot>.aqmx-toast:before{content:"";float:inline-end;inline-size:calc(var(--aqmx-sheet-target) + var(--aqmx-space-3));block-size:calc(var(--aqmx-sheet-notice-band) - var(--aqmx-sheet-notice-inset) - var(--aqmx-space-1))}.aqmx-sheet-notice-slot>.aqmx-toast:after{content:"";block-size:calc(var(--aqmx-sheet-notice-inset) - var(--aqmx-space-1));display:block}.aqmx-sheet-body{isolation:isolate;flex-direction:column;flex:auto;min-block-size:0;display:flex;position:relative;overflow:hidden}.aqmx-document-column{flex-direction:column;min-block-size:0;display:flex}.aqmx-document-column>.aqmx-document{flex:1 1 0;block-size:auto;min-block-size:0}.aqmx-single{flex:auto;position:relative}.aqmx-tree-document{block-size:100%;inline-size:100%}.aqmx-split-fallback,.aqmx-stage-fallback{background:var(--aqmx-surface-sunken);flex:auto;min-block-size:0}@media (forced-colors:active){.aqmx-sheet-toggle[aria-expanded=true]{forced-color-adjust:none;color:highlighttext;background:highlight}.aqmx-sheet-toggle:focus-visible,.aqmx-sheet-close:focus-visible{outline-color:highlight}.aqmx-split-handle:focus-visible{outline:var(--aqmx-focus-ring-width) solid Highlight!important;outline-offset:calc(-1 * var(--aqmx-focus-ring-width))!important}}@media (prefers-reduced-motion:reduce){.aqmx-split-handle,.aqmx-split-handle *{transition-duration:0s!important}}}@layer utilities;
3
+ @layer theme,base;@layer components{.aqmx-root{--aqmx-space-1:.0625rem;--aqmx-space-2:.125rem;--aqmx-space-3:.1875rem;--aqmx-space-4:.3125rem;--aqmx-space-5:.5rem;--aqmx-space-6:.8125rem;--aqmx-space-7:1.3125rem;--aqmx-space-8:2.125rem;--aqmx-space-9:3.4375rem;--aqmx-control:2.125rem;--aqmx-focus-ring-width:var(--aqmx-space-2);--aqmx-focus-ring-offset:var(--aqmx-space-2);--aqmx-icon:1rem;--aqmx-radius-s:.3125rem;--aqmx-radius-m:.5rem;--aqmx-radius-l:.8125rem;--aqmx-duration-1:89ms;--aqmx-duration-2:.144s;--aqmx-duration-3:.233s;--aqmx-duration-4:.377s;--aqmx-delay-progress:.233s;--aqmx-ease:cubic-bezier(.2, 0, 0, 1);--aqmx-font-size-body:.8125rem;--aqmx-font-size-title:1rem;--aqmx-font-size-display:1.3125rem;--aqmx-line-height-compact:1.382;--aqmx-line-height-prose:1.618;--aqmx-column-measure:40ch;--aqmx-surface:#fff;--aqmx-surface-raised:#f8fafc;--aqmx-surface-sunken:#f1f5f9;--aqmx-border:#cbd5e1;--aqmx-border-strong:#94a3b8;--aqmx-text:#0f172a;--aqmx-text-muted:#475569;--aqmx-accent:#1d4ed8;--aqmx-accent-surface:#dbeafe;--aqmx-tree-line:#64748b;--aqmx-tree-row-tint:#0f172a0f;--aqmx-tree-row-accent-tint:#2563eb29;--aqmx-focus:#2563eb;--aqmx-info-surface:#eff6ff;--aqmx-info-border:#93c5fd;--aqmx-info-text:#1e3a8a;--aqmx-warning-surface:#fffbeb;--aqmx-warning-border:#fcd34d;--aqmx-warning-text:#78350f;--aqmx-danger-surface:#fef2f2;--aqmx-danger-border:#fca5a5;--aqmx-danger-text:#7f1d1d;--aqmx-syntax-heading:#1e3a8a;--aqmx-syntax-link:#1e40af;--aqmx-syntax-url:#5b21b6;--aqmx-syntax-code:#9a3412;--aqmx-syntax-quote:#334155;--aqmx-syntax-mark:#475569;--aqmx-editor-gutter:#334155;--aqmx-editor-selection:#2563eb36;--aqmx-editor-active-line:#0f172a0d;--aqmx-conflict-ours-tint:#16a34a21;--aqmx-conflict-theirs-tint:#2563eb21;--aqmx-conflict-marker-tint:#d9770636;--aqmx-shadow:0 .0625rem .1875rem #0f172a21, 0 .3125rem .8125rem #0f172a14}.aqmx-root[data-aqmx-theme=dark]{--aqmx-surface:#0f172a;--aqmx-surface-raised:#1e293b;--aqmx-surface-sunken:#020617;--aqmx-border:#334155;--aqmx-border-strong:#64748b;--aqmx-text:#e2e8f0;--aqmx-text-muted:#94a3b8;--aqmx-accent:#93c5fd;--aqmx-accent-surface:#1e3a8a;--aqmx-tree-line:#94a3b8;--aqmx-tree-row-tint:#e2e8f00f;--aqmx-tree-row-accent-tint:#2563eb70;--aqmx-focus:#60a5fa;--aqmx-info-surface:#172554;--aqmx-info-border:#1d4ed8;--aqmx-info-text:#bfdbfe;--aqmx-warning-surface:#422006;--aqmx-warning-border:#a16207;--aqmx-warning-text:#fde68a;--aqmx-danger-surface:#450a0a;--aqmx-danger-border:#b91c1c;--aqmx-danger-text:#fecaca;--aqmx-syntax-heading:#93c5fd;--aqmx-syntax-link:#a5b4fc;--aqmx-syntax-url:#c4b5fd;--aqmx-syntax-code:#fdba74;--aqmx-syntax-quote:#cbd5e1;--aqmx-syntax-mark:#cbd5e1;--aqmx-editor-gutter:#cbd5e1;--aqmx-editor-selection:#3b82f657;--aqmx-editor-active-line:#e2e8f00d;--aqmx-conflict-ours-tint:#22c55e36;--aqmx-conflict-theirs-tint:#3b82f636;--aqmx-conflict-marker-tint:#f59e0b36;--aqmx-shadow:0 .0625rem .1875rem #0000008c, 0 .3125rem .8125rem #00000057}@media (pointer:coarse){.aqmx-root{--aqmx-control:2.75rem}}@media (forced-colors:active){.aqmx-root.aqmx-root[data-aqmx-theme]{--aqmx-tree-line:CanvasText}}@media (prefers-reduced-motion:reduce){.aqmx-root{--aqmx-duration-1:0s;--aqmx-duration-2:0s;--aqmx-duration-3:0s;--aqmx-duration-4:0s}}.aqmx-root{block-size:100%;min-block-size:0;inline-size:100%;min-inline-size:0;color:var(--aqmx-text);background:var(--aqmx-surface);font-size:var(--aqmx-font-size-body);line-height:var(--aqmx-line-height-compact);flex-direction:column;display:flex;position:relative}.aqmx-root *,.aqmx-root :before,.aqmx-root :after{box-sizing:border-box}.aqmx-icon-button{inline-size:var(--aqmx-control);block-size:var(--aqmx-control);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text-muted);cursor:pointer;transition:background-color var(--aqmx-duration-2) var(--aqmx-ease), color var(--aqmx-duration-2) var(--aqmx-ease);background:0 0;border:0;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.aqmx-icon-button:hover{color:var(--aqmx-text);background:var(--aqmx-surface-sunken)}.aqmx-icon-button[aria-pressed=true],.aqmx-icon-button[aria-expanded=true]{color:var(--aqmx-accent);background:var(--aqmx-accent-surface)}.aqmx-icon-button:disabled{opacity:.382;cursor:not-allowed}.aqmx-icon-button[aria-disabled=true]{cursor:not-allowed}.aqmx-icon-button[aria-disabled=true]:hover{color:var(--aqmx-text-muted);background:0 0}.aqmx-icon-button>svg{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon)}.aqmx-icon-button[aria-disabled=true]>svg{opacity:.382}.aqmx-root :focus-visible{outline:var(--aqmx-focus-ring-width) solid var(--aqmx-focus);outline-offset:var(--aqmx-focus-ring-offset)}.aqmx-callout{gap:var(--aqmx-space-5);padding:var(--aqmx-space-6);border:var(--aqmx-space-1) solid var(--aqmx-info-border);border-radius:var(--aqmx-radius-l);color:var(--aqmx-info-text);background:var(--aqmx-info-surface);line-height:var(--aqmx-line-height-prose);display:grid}.aqmx-callout[data-aqmx-tone=warning]{border-color:var(--aqmx-warning-border);color:var(--aqmx-warning-text);background:var(--aqmx-warning-surface)}.aqmx-callout[data-aqmx-tone=danger]{border-color:var(--aqmx-danger-border);color:var(--aqmx-danger-text);background:var(--aqmx-danger-surface)}.aqmx-callout-title{font-size:var(--aqmx-font-size-title);font-weight:600;line-height:var(--aqmx-line-height-compact);margin:0}.aqmx-callout-body{margin:0}.aqmx-callout-action{min-block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-6);border:var(--aqmx-space-1) solid currentColor;border-radius:var(--aqmx-radius-m);color:inherit;font:inherit;cursor:pointer;background:0 0;justify-self:start;align-items:center;font-weight:600;text-decoration:none;display:inline-flex}.aqmx-progress{z-index:2;block-size:var(--aqmx-space-3);pointer-events:none;position:absolute;inset-block-start:0;inset-inline:0;overflow:hidden}.aqmx-progress:before{content:"";background:var(--aqmx-accent);inline-size:38.1966%;animation:aqmx-progress calc(var(--aqmx-duration-4) * 3) var(--aqmx-ease) infinite;position:absolute;inset-block:0}@keyframes aqmx-progress{0%{inset-inline-start:-38.1966%}to{inset-inline-start:100%}}.aqmx-empty{place-content:center;justify-items:center;gap:var(--aqmx-space-6);block-size:100%;padding:var(--aqmx-space-8);color:var(--aqmx-text-muted);text-align:center;line-height:var(--aqmx-line-height-prose);display:grid}.aqmx-empty-title{color:var(--aqmx-text);font-size:var(--aqmx-font-size-title);margin:0;font-weight:600}.aqmx-skeleton{gap:var(--aqmx-space-6);padding:var(--aqmx-space-7);display:grid}.aqmx-skeleton>span{block-size:var(--aqmx-space-6);border-radius:var(--aqmx-radius-s);background:var(--aqmx-surface-sunken);animation:aqmx-pulse calc(var(--aqmx-duration-4) * 4) ease-in-out infinite;display:block}.aqmx-skeleton>span:nth-child(3n+1){inline-size:61.8034%}.aqmx-skeleton>span:nth-child(3n+2){inline-size:100%}.aqmx-skeleton>span:nth-child(3n){inline-size:85.4102%}@keyframes aqmx-pulse{50%{opacity:.618}}.aqmx-sr-only{clip:rect(0, 0, 0, 0);white-space:nowrap;border:0;block-size:1px;inline-size:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.aqmx-toast{z-index:60;max-inline-size:min(34rem, calc(100% - var(--aqmx-space-8)));padding:var(--aqmx-space-5) var(--aqmx-space-6);border:var(--aqmx-space-1) solid var(--aqmx-warning-border);border-radius:var(--aqmx-radius-m);color:var(--aqmx-warning-text);background:var(--aqmx-warning-surface);box-shadow:var(--aqmx-shadow);position:absolute;inset-block-start:var(--aqmx-space-6);inset-inline-end:var(--aqmx-space-7)}@media (prefers-reduced-motion:reduce){.aqmx-progress:before,.aqmx-skeleton>span{animation:none}}@media (forced-colors:active){.aqmx-icon-button[aria-pressed=true],.aqmx-icon-button[aria-expanded=true]{forced-color-adjust:none;color:highlighttext;background:highlight}.aqmx-icon-button[aria-disabled=true]{color:graytext}.aqmx-root :focus-visible{outline-color:highlight}.aqmx-progress:before{forced-color-adjust:none;background:highlight}.aqmx-skeleton>span{forced-color-adjust:none;background:graytext}}.aqmx-explorer{gap:var(--aqmx-space-5);block-size:100%;min-block-size:0;min-inline-size:0;padding:var(--aqmx-space-4);color:var(--aqmx-text);background:var(--aqmx-surface);flex-direction:column;display:flex;position:relative;overflow-y:auto}.aqmx-explorer-header{align-items:center;gap:var(--aqmx-space-4);min-block-size:var(--aqmx-control);flex-wrap:wrap;flex:none;display:flex}.aqmx-explorer-source{min-inline-size:min(100%,9rem);block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-5);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text);background:var(--aqmx-surface-raised);font:inherit;text-overflow:ellipsis;cursor:pointer;flex:9rem}.aqmx-explorer-actions{justify-content:flex-end;align-items:center;gap:var(--aqmx-space-2);flex-wrap:wrap;flex:0 auto;min-inline-size:0;margin-inline-start:auto;display:flex}.aqmx-explorer-body{gap:var(--aqmx-space-5);flex-direction:column;flex:1 1 0;min-block-size:0;min-inline-size:0;display:flex;position:relative}.aqmx-labelled-button{gap:var(--aqmx-space-2);min-inline-size:var(--aqmx-control);inline-size:auto;padding-inline:var(--aqmx-space-3);white-space:nowrap;flex:0 auto;display:inline-flex}.aqmx-labelled-button>svg{flex:none}.aqmx-labelled-button>span{text-overflow:ellipsis;min-inline-size:0;overflow:hidden}.aqmx-explorer-refresh-failure,.aqmx-explorer-expand-all-stop{padding:var(--aqmx-space-4) var(--aqmx-space-5);border:var(--aqmx-space-1) solid;border-radius:var(--aqmx-radius-m);line-height:var(--aqmx-line-height-compact);overflow-wrap:anywhere;flex:none;margin:0}.aqmx-explorer-refresh-failure{border-color:var(--aqmx-danger-border);color:var(--aqmx-danger-text);background:var(--aqmx-danger-surface)}.aqmx-explorer-expand-all-stop{border-color:var(--aqmx-info-border);color:var(--aqmx-info-text);background:var(--aqmx-info-surface)}.aqmx-explorer-actions>.aqmx-labelled-button[data-aqmx-busy=true]>svg{animation:aqmx-explorer-spin calc(var(--aqmx-duration-4) * 3) linear infinite}@keyframes aqmx-explorer-spin{to{rotate:1turn}}.aqmx-explorer-actions>.aqmx-icon-button[aria-busy=true]{cursor:progress}.aqmx-explorer-menu{z-index:50;gap:var(--aqmx-space-1);max-block-size:100%;inline-size:min(21rem,100%);padding:var(--aqmx-space-3);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);background:var(--aqmx-surface-raised);box-shadow:var(--aqmx-shadow);display:grid;position:absolute;inset-block-start:0;inset-inline-end:0;overflow-y:auto}.aqmx-explorer-menu-item{align-items:center;gap:var(--aqmx-space-5);inline-size:100%;min-block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-5);border-radius:var(--aqmx-radius-s);color:var(--aqmx-text);font:inherit;text-align:start;cursor:pointer;transition:background-color var(--aqmx-duration-1) var(--aqmx-ease);background:0 0;border:0;display:flex}.aqmx-explorer-menu-item:hover,.aqmx-explorer-menu-item:focus-visible{background:var(--aqmx-surface-sunken)}.aqmx-explorer-menu-icon{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon);color:var(--aqmx-text-muted);flex:none}.aqmx-explorer-menu-name{text-overflow:ellipsis;white-space:nowrap;flex:auto;min-inline-size:0;overflow:hidden}.aqmx-explorer-menu-value{color:var(--aqmx-accent);font-variant-numeric:tabular-nums;flex:none;font-weight:600}.aqmx-explorer-notices{gap:var(--aqmx-space-5);flex:none;display:grid}.aqmx-explorer-tree-area{min-block-size:calc(var(--aqmx-control) * 3);flex-direction:column;flex:1 1 0;min-inline-size:0;display:flex;position:relative}.aqmx-explorer-tree{flex:1 1 0;min-block-size:0;position:relative}.aqmx-explorer-tree-view{block-size:100%}.aqmx-explorer-tree-progress{z-index:1;align-items:center;gap:var(--aqmx-space-2) var(--aqmx-space-4);max-inline-size:calc(100% - var(--aqmx-space-5) * 3);padding:var(--aqmx-space-3) var(--aqmx-space-5);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text-muted);background:var(--aqmx-surface-raised);box-shadow:var(--aqmx-shadow);line-height:var(--aqmx-line-height-compact);overflow-wrap:anywhere;pointer-events:none;animation:aqmx-appear var(--aqmx-duration-2) ease-out var(--aqmx-delay-progress) both;flex-wrap:wrap;margin:0;display:flex;position:absolute;inset-block-end:var(--aqmx-space-9);inset-inline-start:var(--aqmx-space-5)}.aqmx-explorer-tree-progress-icon{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon);animation:aqmx-explorer-spin calc(var(--aqmx-duration-4) * 3) linear infinite;flex:none}@keyframes aqmx-appear{0%{opacity:0}}.aqmx-explorer-tree-probe{inline-size:0;block-size:var(--aqmx-control);visibility:hidden;pointer-events:none;color:var(--aqmx-tree-line);forced-color-adjust:none;position:absolute;inset-block-start:0;inset-inline-start:0;overflow:hidden}.aqmx-explorer-loading{gap:var(--aqmx-space-5);padding:var(--aqmx-space-6) var(--aqmx-space-5);color:var(--aqmx-text-muted);display:grid}.aqmx-explorer-loading-text{margin:0}.aqmx-explorer-loading>.aqmx-skeleton{padding:0}.aqmx-explorer-tree-message{padding:var(--aqmx-space-5);overflow-y:auto}.aqmx-explorer-empty-icon{inline-size:var(--aqmx-space-8);block-size:var(--aqmx-space-8);color:var(--aqmx-border-strong)}.aqmx-explorer-empty-body{margin:0}.aqmx-explorer-tree [role=treeitem]{border-radius:var(--aqmx-radius-s);color:var(--aqmx-text);transition:background-color var(--aqmx-duration-1) var(--aqmx-ease)}.aqmx-explorer-tree [role=treeitem]:hover{color:var(--aqmx-text);background:var(--aqmx-tree-row-tint)}.aqmx-explorer-tree [role=treeitem][data-entry-item-selected=true]{color:var(--aqmx-text);background:var(--aqmx-tree-row-tint);box-shadow:inset var(--aqmx-space-2) 0 0 currentColor}.aqmx-explorer-tree [role=treeitem][data-entry-selected=true],.aqmx-explorer-tree [role=treeitem][data-aqmx-open=true]{color:var(--aqmx-accent);background:var(--aqmx-tree-row-accent-tint)}.aqmx-explorer-tree [role=treeitem]:focus-visible{outline-offset:calc(-1 * var(--aqmx-focus-ring-width))}.aqmx-explorer-tree [role=treeitem][data-entry-item-selected=true]:focus-visible{box-shadow:inset calc(var(--aqmx-space-2) + var(--aqmx-focus-ring-width)) 0 0 currentColor}.aqmx-explorer-tree [role=treeitem][data-aqmx-open=true]{font-weight:600}.aqmx-explorer-tree [role=treeitem][data-aqmx-children=loading]{animation:aqmx-pulse calc(var(--aqmx-duration-4) * 4) ease-in-out infinite}.aqmx-explorer-tree [role=treeitem][data-aqmx-loop]{color:var(--aqmx-text-muted);font-style:italic}.aqmx-explorer-folder-failed{--aqmx-folder-name-floor:3em;align-items:center;min-inline-size:0;max-inline-size:100%;display:flex}.aqmx-explorer-folder-name{flex:10000 1 var(--aqmx-folder-name-floor);text-overflow:ellipsis;white-space:nowrap;min-inline-size:0;max-inline-size:max-content;overflow:hidden}.aqmx-explorer-folder-error{min-inline-size:0;color:var(--aqmx-danger-text);text-indent:var(--aqmx-space-4);text-overflow:ellipsis;white-space:nowrap;flex:1 1 0;overflow:hidden}.aqmx-explorer-folder-retry{flex:1000000 0 calc(var(--aqmx-icon) + (var(--aqmx-space-3) + var(--aqmx-space-1)) * 2);min-inline-size:calc(var(--aqmx-icon) + (var(--aqmx-space-3) + var(--aqmx-space-1)) * 2);max-inline-size:max-content;min-block-size:var(--aqmx-control);padding:0 var(--aqmx-space-3);border:var(--aqmx-space-1) solid var(--aqmx-danger-border);border-radius:var(--aqmx-radius-s);color:var(--aqmx-danger-text);background:var(--aqmx-danger-surface);font:inherit;line-height:var(--aqmx-line-height-compact);cursor:pointer;justify-content:center;align-items:center;margin-inline-start:var(--aqmx-space-4);display:inline-flex;overflow:hidden}.aqmx-explorer-folder-retry:focus-visible{outline-offset:calc(-1 * (var(--aqmx-focus-ring-width) + var(--aqmx-space-1)))}.aqmx-explorer-folder-retry-icon{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon);flex:none}.aqmx-explorer-folder-retry-text{min-inline-size:0;text-indent:var(--aqmx-space-3);text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.aqmx-explorer-tray{gap:var(--aqmx-space-4);min-block-size:calc(var(--aqmx-control) + (var(--aqmx-space-5) + var(--aqmx-space-1)) * 2);padding:var(--aqmx-space-5);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);background:var(--aqmx-surface-raised);box-shadow:var(--aqmx-shadow);flex-direction:column;flex:0 auto;display:flex;overflow-y:auto}.aqmx-explorer-tray-header{justify-content:space-between;align-items:center;gap:var(--aqmx-space-5);flex:none;display:flex}.aqmx-explorer-tray-title{margin:0;font-weight:600}.aqmx-explorer-tray-button{min-block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-5);border-radius:var(--aqmx-radius-m);color:var(--aqmx-accent);font:inherit;cursor:pointer;background:0 0;border:0;flex:none;font-weight:600}.aqmx-explorer-tray-button:hover{background:var(--aqmx-surface-sunken)}.aqmx-explorer-tray-list{gap:var(--aqmx-space-1);min-block-size:var(--aqmx-control);max-block-size:calc(var(--aqmx-control) * 3);flex:0 auto;margin:0;padding:0;list-style:none;display:grid;overflow-y:auto}.aqmx-explorer-tray-item{align-items:center;gap:var(--aqmx-space-4);display:flex}.aqmx-explorer-tray-name{text-overflow:ellipsis;white-space:nowrap;flex:auto;min-inline-size:0;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;overflow:hidden}.aqmx-explorer-tray-open{min-block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-6);border-radius:var(--aqmx-radius-m);color:var(--aqmx-surface);background:var(--aqmx-accent);font:inherit;cursor:pointer;border:0;flex:none;font-weight:600}@media (forced-colors:active){.aqmx-explorer-tree [role=treeitem][data-entry-item-selected=true],.aqmx-explorer-tree [role=treeitem][data-entry-selected=true],.aqmx-explorer-tree [role=treeitem][data-aqmx-open=true],.aqmx-explorer-menu-item[aria-checked=true]{forced-color-adjust:none;color:highlighttext;background:highlight}.aqmx-explorer-menu-item[aria-checked=true] *,.aqmx-explorer-tree [role=treeitem][data-entry-item-selected=true] *,.aqmx-explorer-tree [role=treeitem][data-entry-selected=true] *,.aqmx-explorer-tree [role=treeitem][data-aqmx-open=true] *{color:inherit!important}.aqmx-explorer-tree [role=treeitem][data-entry-item-selected=true]:focus-visible,.aqmx-explorer-tree [role=treeitem][data-entry-selected=true]:focus-visible,.aqmx-explorer-tree [role=treeitem][data-aqmx-open=true]:focus-visible{outline-color:highlighttext}.aqmx-explorer-tray-button,.aqmx-explorer-tray-open,.aqmx-explorer-tray-remove{border:var(--aqmx-space-1) solid ButtonText}}@media (prefers-reduced-motion:reduce){.aqmx-explorer-actions>.aqmx-labelled-button[data-aqmx-busy=true]>svg,.aqmx-explorer-tree-progress-icon,.aqmx-explorer-tree [role=treeitem][data-aqmx-children=loading]{animation:none}.aqmx-explorer-tree-view{transition-duration:0s!important}}.aqmx-document{contain:layout paint;--aqmd-toolbar-inset-block-start:calc(var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset));block-size:100%;min-block-size:0;inline-size:100%;min-inline-size:0;color:var(--aqmx-text);background:var(--aqmx-surface);flex-direction:column;display:flex;position:relative;overflow:hidden}.aqmx-document-viewer:has([data-aqmd-scroll-bar]){--aqmd-toolbar-inset-inline-end:calc(var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset))}.aqmx-document [data-theme]{background-color:#0000!important}.aqmx-document .markdown-body :is(sup,sub) a{outline-offset:var(--aqmx-focus-ring-offset)!important}.aqmx-document *{scroll-margin:calc(var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset))}.aqmx-document[aria-busy=true]>:not(.aqmx-progress){opacity:.618;transition:opacity var(--aqmx-duration-3) var(--aqmx-ease)}.aqmx-document-viewer{flex:1 1 0;min-block-size:0;min-inline-size:0}.aqmx-document-notice{margin:var(--aqmx-space-6) var(--aqmx-space-7) 0;overflow-wrap:anywhere;flex:none}.aqmx-document-scroll-row{flex:1 1 0;min-block-size:0}.aqmx-document-failure{min-block-size:0;padding:var(--aqmx-space-7);flex:1 1 0;overflow:auto}.aqmx-document-file{flex-direction:column;flex:1 1 0;min-block-size:0;min-inline-size:0;display:flex}.aqmx-document-toolbar{align-items:center;gap:var(--aqmx-space-3);padding:var(--aqmx-space-3) var(--aqmx-space-6);border-block-end:var(--aqmx-space-1) solid var(--aqmx-border);background:var(--aqmx-surface-raised);flex-wrap:wrap;flex:none;display:flex}.aqmx-document-file-icon{color:var(--aqmx-text-muted);flex:none;display:inline-flex}.aqmx-document-file-icon>svg{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon)}.aqmx-document-title{text-overflow:ellipsis;white-space:nowrap;flex:1 1 0;min-inline-size:0;font-weight:600;overflow:hidden}.aqmx-document-level{min-inline-size:var(--aqmx-space-9);color:var(--aqmx-text-muted);font-variant-numeric:tabular-nums;text-align:center;flex:none}.aqmx-document-canvas{min-block-size:0;padding:var(--aqmx-space-7);background-color:var(--aqmx-surface-sunken);background-image:radial-gradient(var(--aqmx-border) var(--aqmx-space-1), transparent var(--aqmx-space-1));background-size:var(--aqmx-space-6) var(--aqmx-space-6);flex:1 1 0;grid-template:minmax(0,1fr)/minmax(0,1fr);display:grid;overflow:auto}.aqmx-document-image{margin:auto;display:block}.aqmx-document-image[data-aqmx-image-mode=fit]{object-fit:contain;max-block-size:100%;max-inline-size:100%}.aqmx-document-image[data-aqmx-image-mode=level]{max-block-size:none;max-inline-size:none}.aqmx-document-stage{min-block-size:0;padding:var(--aqmx-space-7);background:var(--aqmx-surface-sunken);flex:1 1 0;grid-template:minmax(0,1fr)/minmax(0,1fr);place-items:center;display:grid;overflow:auto}.aqmx-document-file[data-aqmx-media-type=pdf] .aqmx-document-stage{place-items:stretch stretch;padding:0}.aqmx-document-video{border-radius:var(--aqmx-radius-l);background:var(--aqmx-surface-raised);max-block-size:100%;max-inline-size:100%;box-shadow:var(--aqmx-shadow)}.aqmx-document-audio{inline-size:min(100%, var(--aqmx-column-measure))}.aqmx-document-frame{background:var(--aqmx-surface);border:0;block-size:100%;inline-size:100%}.aqmx-document-inert-link{color:var(--aqmx-text-muted);cursor:not-allowed;text-decoration-style:dotted}.aqmx-document[data-aqmx-document-flow=content]{contain:layout;block-size:auto;overflow:visible}.aqmx-document[data-aqmx-document-flow=content]>*,.aqmx-document[data-aqmx-document-flow=content] .aqmx-document-file>*{flex:none}.aqmx-document[data-aqmx-document-flow=content] .aqmx-document-frame{aspect-ratio:1/1.41421;block-size:auto}.aqmx-document-refresh-bar{flex-direction:column;flex:none;display:flex}.aqmx-document-refresh-row{justify-content:flex-end;align-items:center;gap:var(--aqmx-space-2);padding:calc(var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset));display:flex}.aqmx-document-column>.aqmx-document-refresh-bar>.aqmx-document-refresh-row{padding-inline-end:calc(var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset) + var(--aqmx-page-bar-inset-inline-end,0px))}.aqmx-document-refresh-failure{margin:0 var(--aqmx-space-3) var(--aqmx-space-2);padding:var(--aqmx-space-4) var(--aqmx-space-5);border:var(--aqmx-space-1) solid var(--aqmx-danger-border);border-radius:var(--aqmx-radius-m);color:var(--aqmx-danger-text);background:var(--aqmx-danger-surface);line-height:var(--aqmx-line-height-compact);overflow-wrap:anywhere}.aqmx-document-refresh-row>.aqmx-icon-button[data-aqmx-busy=true]>svg{animation:aqmx-explorer-spin calc(var(--aqmx-duration-4) * 3) linear infinite}.aqmx-document-refresh-row>.aqmx-icon-button[aria-busy=true]{cursor:progress}@media (prefers-reduced-motion:reduce){.aqmx-document-refresh-row>.aqmx-icon-button[data-aqmx-busy=true]>svg{animation:none}}.aqmx-edit{grid-template-columns:repeat(auto-fit, minmax(min(100%, var(--aqmx-column-measure)), 1fr));gap:var(--aqmx-space-1);background:var(--aqmx-border);flex:1 1 0;grid-auto-rows:minmax(0,1fr);min-block-size:0;min-inline-size:0;display:grid}.aqmx-edit[data-aqmx-edit-layout=content]{display:block}.aqmx-edit-editor,.aqmx-edit-preview{background:var(--aqmx-surface);min-block-size:0;min-inline-size:0}.aqmx-edit-editor{-webkit-user-select:text;user-select:text}.aqmx-edit-editor:has(.cm-content:focus-visible){outline:var(--aqmx-focus-ring-width) solid var(--aqmx-focus);outline-offset:calc(-1 * var(--aqmx-focus-ring-width))}.aqmx-edit-preview{flex-direction:column;display:flex;overflow:hidden}.aqmx-edit-preview [data-aqmd-scroll-container]{overflow-anchor:none}.aqmx-edit-editor [data-aqmx-conflict-line=ours]{background-color:var(--aqmx-conflict-ours-tint)}.aqmx-edit-editor [data-aqmx-conflict-line=theirs]{background-color:var(--aqmx-conflict-theirs-tint)}.aqmx-edit-editor [data-aqmx-conflict-line=marker]{background-color:var(--aqmx-conflict-marker-tint)}.aqmx-edit-editor [data-aqmx-conflict-actions]{gap:var(--aqmx-space-3);padding:var(--aqmx-space-3) var(--aqmx-space-6);background-color:var(--aqmx-conflict-marker-tint);font-family:system-ui,sans-serif;font-size:var(--aqmx-font-size-body);line-height:var(--aqmx-line-height-compact);flex-wrap:wrap;display:flex}.aqmx-edit-editor [data-aqmx-conflict-choice]{min-block-size:var(--aqmx-control);padding-inline:var(--aqmx-space-6);border:var(--aqmx-space-1) solid var(--aqmx-border-strong);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text);background:var(--aqmx-surface);font:inherit;cursor:pointer;font-weight:600}.aqmx-edit-editor [data-aqmx-conflict-choice]:hover{background:var(--aqmx-surface-sunken)}.aqmx-multi-panel-frame .aqmx-document[data-aqmx-document-flow=content] .cm-panels-top{inset-block-start:var(--aqmx-multi-panel-pinned-block-size)!important}.aqmx-edit-message{min-block-size:0;padding:var(--aqmx-space-7);flex:1 1 0;overflow:auto}.aqmx-edit-grant-actions{gap:var(--aqmx-space-5);flex-wrap:wrap;display:flex}.aqmx-edit-status{min-inline-size:0;padding-inline:var(--aqmx-space-3);color:var(--aqmx-text-muted);text-overflow:ellipsis;white-space:nowrap;flex:1 1 0;margin:0;overflow:hidden}.aqmx-edit-status[data-aqmx-save=conflicts]{color:var(--aqmx-warning-text)}.aqmx-edit-status[data-aqmx-save=failed]{color:var(--aqmx-danger-text)}.aqmx-document-refresh-bar>.aqmx-edit-grant{margin:0 var(--aqmx-space-3) var(--aqmx-space-2)}.aqmx-confirm{inline-size:min(34rem, calc(100vw - 2 * var(--aqmx-space-7)));border:var(--aqmx-space-1) solid var(--aqmx-border-strong);border-radius:var(--aqmx-radius-l);max-inline-size:none;color:var(--aqmx-text);background:var(--aqmx-surface);box-shadow:var(--aqmx-shadow);padding:0}.aqmx-confirm::backdrop{background:#0f172a61}.aqmx-confirm-panel{gap:var(--aqmx-space-6);padding:var(--aqmx-space-7);display:grid}.aqmx-confirm-title{font-size:var(--aqmx-font-size-title);font-weight:600;line-height:var(--aqmx-line-height-compact);margin:0}.aqmx-confirm-body{line-height:var(--aqmx-line-height-prose);overflow-wrap:anywhere;margin:0}.aqmx-confirm-actions{justify-content:flex-end;gap:var(--aqmx-space-5);flex-wrap:wrap;display:flex}.aqmx-confirm-actions>.aqmx-callout-action{justify-self:auto}.aqmx-confirm-actions>[data-aqmx-tone=danger]{border-color:var(--aqmx-danger-border);color:var(--aqmx-danger-text);background:var(--aqmx-danger-surface)}.aqmx-confirm-actions>[aria-disabled=true]{opacity:.618;cursor:not-allowed}.aqmx-history{inline-size:min(55rem, calc(100vw - 2 * var(--aqmx-space-7)))}.aqmx-history-panel{max-block-size:calc(100vh - 2 * var(--aqmx-space-7));overflow:auto}.aqmx-history-note{color:var(--aqmx-text-muted);margin:0}.aqmx-history-list{gap:var(--aqmx-space-2);max-block-size:34vh;margin:0;padding:0;list-style:none;display:grid;overflow:auto}.aqmx-history-entry{align-items:center;gap:var(--aqmx-space-5);inline-size:100%;min-block-size:var(--aqmx-control);padding:var(--aqmx-space-3) var(--aqmx-space-5);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text);font:inherit;text-align:start;cursor:pointer;background:0 0;border:0;flex-wrap:wrap;display:flex}.aqmx-history-entry:hover{background:var(--aqmx-surface-sunken)}.aqmx-history-entry[aria-pressed=true]{color:var(--aqmx-accent);background:var(--aqmx-accent-surface)}.aqmx-history-mark{padding-inline:var(--aqmx-space-4);border:var(--aqmx-space-1) solid currentColor;border-radius:var(--aqmx-radius-s)}.aqmx-history-text{max-block-size:34vh;padding:var(--aqmx-space-6);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);background:var(--aqmx-surface-raised);overflow:auto}.aqmx-history-text>pre{white-space:pre-wrap;overflow-wrap:anywhere;margin:0;font-family:ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace}.aqmx-multi-stage{--aqmx-multi-panel-body-floor:calc(3rem * var(--aqmx-line-height-prose));--aqdd-stage-padding-block:var(--aqmx-space-7);--aqdd-stage-padding-inline:var(--aqmx-space-6) calc(var(--aqmx-space-6) + var(--aqmx-multi-stage-bar-gutter));--aqdd-column-gap:var(--aqmx-space-6);--aqdd-panel-surface:var(--aqmx-surface);--aqdd-panel-border:var(--aqmx-border);--aqdd-panel-title-color:var(--aqmx-text);--aqdd-header-button-color:var(--aqmx-text-muted);--aqdd-header-button-hover-color:var(--aqmx-text);--aqdd-header-button-hover-surface:var(--aqmx-surface-sunken);--aqdd-custom-badge-color:var(--aqmx-warning-text);--aqdd-custom-badge-surface:var(--aqmx-warning-surface);--aqdd-restore-button-color:var(--aqmx-surface);--aqdd-restore-button-surface:var(--aqmx-accent);--aqdd-restore-button-hover-surface:var(--aqmx-info-text);--aqdd-drop-placeholder-color:var(--aqmx-accent);--aqdd-drop-placeholder-surface:var(--aqmx-surface);--aqdd-drop-placeholder-target-surface:var(--aqmx-accent-surface);background:var(--aqmx-surface-sunken);block-size:100%;min-block-size:0;min-inline-size:0;color:var(--aqmx-text);flex-direction:column;display:flex;position:relative}.aqmx-multi-stage:focus-visible{outline:var(--aqmx-focus-ring-width) solid var(--aqmx-focus);outline-offset:calc(-1 * var(--aqmx-focus-ring-width))}.aqmx-multi-probe{inline-size:var(--aqmx-column-measure);visibility:hidden;pointer-events:none;block-size:0;font-size:1rem;position:absolute;inset-block-start:0;inset-inline-start:0;overflow:hidden}.aqmx-multi-layout{flex:auto;min-block-size:0}.aqmx-multi-skeleton{grid-template-columns:repeat(auto-fit, minmax(min(100%, var(--aqmx-column-measure)), 1fr));align-content:start;gap:var(--aqmx-space-7);padding:var(--aqmx-space-7);display:grid;overflow:hidden}.aqmx-multi-skeleton-column{border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-l);background:var(--aqmx-surface)}.aqmx-multi-column{min-inline-size:0}.aqmx-multi-panel{outline:var(--aqmx-space-1) solid var(--aqmx-border-strong);outline-offset:0;color:var(--aqmx-text)}.aqmx-multi-panel[data-maximized]{outline-color:var(--aqmx-focus)}.aqmx-multi-panel-frame{content-visibility:auto;contain-intrinsic-block-size:auto var(--aqmx-space-9);min-block-size:100%}.aqmx-multi-panel-frame:focus-visible{outline:var(--aqmx-focus-ring-width) solid var(--aqmx-focus);outline-offset:calc(-1 * var(--aqmx-focus-ring-width))}.aqmx-multi-panel-frame[data-aqmx-maximized=false]{-webkit-user-select:none;user-select:none}.aqmx-multi-panel-frame>.aqmx-document-refresh-bar{z-index:1;background:var(--aqmx-surface);position:sticky;inset-block-start:0}.aqmx-multi-panel-frame{--aqmx-multi-panel-pinned-block-size:0px}.aqmx-multi-panel-frame .aqmx-document[data-aqmx-document-flow=content] *{scroll-margin-block-start:calc(var(--aqmx-multi-panel-pinned-block-size) + var(--aqmx-focus-ring-width) + var(--aqmx-focus-ring-offset))}.aqmx-multi-panel-frame:has(>.aqmx-document[data-aqmx-document-flow=fill]){flex-direction:column;block-size:100%;display:flex}.aqmx-multi-panel-frame>.aqmx-document[data-aqmx-document-flow=fill]{flex:1 1 0;block-size:auto}.aqmx-multi-panel-frame .aqmx-document-toolbar>.aqmx-icon-button{flex-shrink:1;min-inline-size:0}.aqmx-multi-toast{animation:aqmx-multi-toast-in var(--aqmx-duration-3) var(--aqmx-ease)}.aqmx-multi-toast:popover-open{max-inline-size:min(34rem, calc(var(--aqmx-multi-toast-room) - var(--aqmx-space-8)));margin:0;position:fixed;inset:auto;inset-block-start:calc(var(--aqmx-multi-toast-block-start) + var(--aqmx-space-6));inset-inline-end:calc(var(--aqmx-multi-toast-inline-end) + var(--aqmx-space-7));overflow:visible}@keyframes aqmx-multi-toast-in{0%{opacity:0;translate:0 calc(var(--aqmx-space-5) * -1)}}@media (prefers-reduced-motion:reduce){.aqmx-multi-toast{animation:none}}@media (forced-colors:active){.aqmx-multi-stage:focus-visible,.aqmx-multi-stage :focus-visible,.aqmx-multi-panel[data-maximized]{outline-color:highlight}}.aqmx-split-frame{--aqmx-sheet-target:2.75rem;flex-direction:column;flex:auto;min-block-size:0;min-inline-size:0;display:flex;position:relative}.aqmx-rem-probe{visibility:hidden;pointer-events:none;block-size:0;inline-size:1rem;position:absolute;inset-block-start:0;inset-inline-start:0}.aqmx-split{flex:auto;min-block-size:0}.aqmx-split-explorer,.aqmx-split-content{background:var(--aqmx-surface);min-block-size:0}.aqmx-split-explorer{background:var(--aqmx-surface-raised)}.aqmx-split-handle{background:var(--aqmx-surface-raised);transition:background-color var(--aqmx-duration-2) var(--aqmx-ease)}.aqmx-split-handle:hover,.aqmx-split-handle:focus-visible{background:var(--aqmx-surface-sunken)}.aqmx-sheet-bar{padding:var(--aqmx-space-3) var(--aqmx-space-5);border-block-end:var(--aqmx-space-1) solid var(--aqmx-border);background:var(--aqmx-surface-raised);flex:none;align-items:center;display:flex}.aqmx-sheet-toggle,.aqmx-sheet-close{justify-content:center;align-items:center;gap:var(--aqmx-space-5);min-inline-size:var(--aqmx-sheet-target);min-block-size:var(--aqmx-sheet-target);padding:0 var(--aqmx-space-6);border:var(--aqmx-space-1) solid var(--aqmx-border);border-radius:var(--aqmx-radius-m);color:var(--aqmx-text);background:var(--aqmx-surface);font:inherit;cursor:pointer;transition:background-color var(--aqmx-duration-2) var(--aqmx-ease);display:inline-flex}.aqmx-sheet-close{z-index:1;color:var(--aqmx-text-muted);background:var(--aqmx-surface-raised);border-color:#0000;padding:0;position:relative}.aqmx-sheet-toggle:hover,.aqmx-sheet-close:hover{background:var(--aqmx-surface-sunken)}.aqmx-sheet-toggle>svg,.aqmx-sheet-close>svg{inline-size:var(--aqmx-icon);block-size:var(--aqmx-icon);flex:none}.aqmx-sheet{inline-size:min(calc(100vw - var(--aqmx-space-9)), 21rem);border:0;border-inline-end:var(--aqmx-space-1) solid var(--aqmx-border);block-size:100dvh;max-block-size:none;max-inline-size:none;color:var(--aqmx-text);background:var(--aqmx-surface-raised);box-shadow:var(--aqmx-shadow);margin:0;padding:0;position:fixed;inset-block:0;inset-inline:0 auto}.aqmx-sheet::backdrop{background:#0f172a61}.aqmx-sheet-panel{flex-direction:column;block-size:100%;display:flex}.aqmx-sheet-header{z-index:1;justify-content:flex-end;align-items:center;gap:var(--aqmx-space-3);padding:var(--aqmx-space-3);border-block-end:var(--aqmx-space-1) solid var(--aqmx-border);flex:none;display:flex;position:relative}.aqmx-sheet-notice-slot>.aqmx-toast{--aqmx-sheet-notice-band:calc(var(--aqmx-sheet-target) + var(--aqmx-space-3) * 2);--aqmx-sheet-notice-line:calc(var(--aqmx-line-height-compact) * 1em);--aqmx-sheet-notice-inset:calc((var(--aqmx-sheet-notice-band) - var(--aqmx-sheet-notice-line)) / 2);z-index:0;max-inline-size:none;padding-block:var(--aqmx-sheet-notice-inset) 0;padding-inline:var(--aqmx-space-6) var(--aqmx-space-3);border:0;border-block-end:var(--aqmx-space-1) solid var(--aqmx-warning-border);line-height:var(--aqmx-line-height-compact);overflow-wrap:anywhere;box-shadow:none;border-radius:0;position:absolute;inset-block:0 auto;inset-inline:0}.aqmx-sheet-notice-slot>.aqmx-toast:before{content:"";float:inline-end;inline-size:calc(var(--aqmx-sheet-target) + var(--aqmx-space-3));block-size:calc(var(--aqmx-sheet-notice-band) - var(--aqmx-sheet-notice-inset) - var(--aqmx-space-1))}.aqmx-sheet-notice-slot>.aqmx-toast:after{content:"";block-size:calc(var(--aqmx-sheet-notice-inset) - var(--aqmx-space-1));display:block}.aqmx-sheet-body{isolation:isolate;flex-direction:column;flex:auto;min-block-size:0;display:flex;position:relative;overflow:hidden}.aqmx-document-column{flex-direction:column;min-block-size:0;display:flex}.aqmx-document-column>.aqmx-document{flex:1 1 0;block-size:auto;min-block-size:0}.aqmx-single{flex:auto;position:relative}.aqmx-tree-document{block-size:100%;inline-size:100%}.aqmx-split-fallback,.aqmx-stage-fallback{background:var(--aqmx-surface-sunken);flex:auto;min-block-size:0}@media (forced-colors:active){.aqmx-sheet-toggle[aria-expanded=true]{forced-color-adjust:none;color:highlighttext;background:highlight}.aqmx-sheet-toggle:focus-visible,.aqmx-sheet-close:focus-visible{outline-color:highlight}.aqmx-split-handle:focus-visible{outline:var(--aqmx-focus-ring-width) solid Highlight!important;outline-offset:calc(-1 * var(--aqmx-focus-ring-width))!important}}@media (prefers-reduced-motion:reduce){.aqmx-split-handle,.aqmx-split-handle *{transition-duration:0s!important}}}@layer utilities;
@@ -79,7 +79,7 @@ The tree is named by `treeRegion`, apart from the explorer `nav` (`explorerRegio
79
79
  | `data-testid="markdown-explorer-edit-skeleton"` | Placeholder while the source for editing (or the editor's chunk) loads | Hidden from assistive technology; the screen-reader text `editLoading` sits beside it |
80
80
  | `data-testid="markdown-explorer-edit-grant"` / `-open` / `-retry` | The notice when opening the editor needs a grant, its action (a button with `onEditGrant`, else a link) and Try again | |
81
81
  | `data-testid="markdown-explorer-edit-failure"` / `markdown-explorer-edit-load-failure` | Failure to open the source for editing, or to load the editor's chunk | Carry `data-aqmx-failure`; no role (the announcer speaks an opening failure) |
82
- | `data-testid="markdown-explorer-edit-preview"` | The draft's preview (`role="region"`, named `previewRegion`) | `aria-busy` while a newer rendering is on its way; holds `-preview-skeleton` before the first rendering and `-preview-failure` (a notice) after a failed one |
82
+ | `data-testid="markdown-explorer-edit-preview"` | The draft's preview (`role="region"`, named `previewRegion`) | Carries `data-aqmx-preview-tier`: `instant` (the host's draft converter renders drafts in the browser) or `server` (the server renders them: no converter, or a draft the converter cannot render). `aria-busy` until the first rendering lands and while the server renders a newer draft, never for a rendering in the browser; before the first rendering it shows the document's own rendering, or holds `-preview-skeleton` when that is not loaded; holds `-preview-failure` (a notice) after a failed rendering |
83
83
  | `data-testid="markdown-explorer-image-view"` | Image viewer | |
84
84
  | `data-testid="markdown-explorer-image-canvas"` | The image's scroll area | The element that scrolls. In the tree and single views it sits in `@aiquants/markdown`'s HostedScrollArea row (`data-aqmd-scroll-row`, inside its clipping cell `data-aqmd-scroll-clip`), whose bar slot (`data-aqmd-scroll-bar`) holds the explorer's pointer scroll bar; so do a medium's and a file view's stage and the failure view (`data-aqmx-document-scroller`). In a multi-view panel they have no row |
85
85
  | `data-testid="markdown-explorer-image"` | The image (`img`) | Carries `data-aqmx-image-mode` (`fit` / `level`) |
@@ -149,7 +149,10 @@ Documents in the multi-panel view sit in `multiView.columns` logical columns (4
149
149
  - **Editing a Markdown document.** The editing surface takes the document's place in the region (`data-aqmx-document-view="edit"`). In a page view and in a maximized panel it fills the pane — in a panel the region then fills the scroll area below the pinned bar — and the editor scrolls itself; in a panel that is not maximized it grows with its text and the panel's scroll area scrolls it.
150
150
  With the preview on, the editor and the preview share one grid that wraps by the reading measure (two `40ch` columns side by side, one above the other on a narrow pane), each scrolling itself, parted by a hairline; a panel that is not maximized shows no preview.
151
151
  Places on screen are kept through the converter's source lines, text matched to text (the top of a word's or a block's first glyphs, since the rendered prose and the editor have different line heights): Edit puts the block at the top of the reader's view, and a double-click the word, exactly where it was; closing puts the editor's top line — the first non-empty one in view — back at the same place in the rendered document, and again on the fresh copy a save made the pane read, unless the reader scrolled, pressed a key or a pointer meanwhile;
152
- the preview keeps the block of the editor's top line level with it, inside a long block at the line's share of its height.
152
+ the editor and the preview scroll together, both ways, through a map of the blocks that carry source lines: the top of a block's first line goes with the top of its box and the bottom of its last line with the bottom of its box, positions in between are linear, both tops go together and both bottoms together, and a block whose place differs between the source and the rendering (a footnote, rendered at the end) is left out, so either pane moves continuously and on whenever the other does, crossing a block taller on its side faster.
153
+ The pane the reader works in (the wheel, a pointer press, a key, the focus moving in, typing) leads at once and the other follows on the next frame; for 610 ms after such input the other pane's scrolls never take the lead (the sync's own moves, the editor's corrections while it draws new lines, the browser clamping a preview that shrank, the tail of an earlier scroll animation) and it is brought back instead.
154
+ A scroll without the reader's input (a find in page) takes the lead once the input ended, unless the sync caused it.
155
+ The map is measured again when the preview renders anew or changes size (an image or a diagram finishing) and when the editor's text or line heights change, and the preview's scroller does not anchor its scroll to its content.
153
156
  Every scroll the editor asks for (following the cursor, finding text, revealing a position) moves the pane's own scroller only and then shows the line in the scrollers around it by the least distance, so neither the page nor the stage is aligned to an editor line. The bar's editing row keeps one line in every state, and the editor is never dimmed while the saved document is read again behind it.
154
157
 
155
158
  ## Switching views
@@ -116,6 +116,8 @@ In a tree or children listing, an entry with an empty name, or with a path the b
116
116
  - `save` and `preview` are `POST` only, and need `X-Markdown-Explorer: edit` and the shared cross-origin check of a refresh (`crossOriginRefusal`), checked before the body is read (403). The body must be `text/markdown` with no charset or `utf-8` (else 400); a declared or actual length over `editMaxBytes` is refused (413) and the reading stops at the first byte past the limit; invalid UTF-8 and NUL are refused (400). All of this happens before any port is called.
117
117
  - `base` (a save's version) and `revision` are tokens of 1 to 1024 characters (400 otherwise). A version, a revision id and a grant are copied from the ports' answers only in their contract's shape: a grant's `href` must be root-relative, an external editor's `href` an absolute `https:` URL; sources, conflict texts and revisions longer than `editMaxBytes`, and malformed revisions, are logged and answered `failed`.
118
118
  - The preview's HTML goes through the same sanitizer, limits and reader share as a document's. The sanitizer keeps a converter's source lines only as `data-source-lines="<first>-<last>"` (positive line numbers, the first not after the last).
119
+ - With a draft converter (`draftConverter`), a draft is rendered in the browser and sanitized there before it is shown, by the same allow-list rules (`core/sanitizePolicy`, on a DOMPurify instance of the preview's own from `isomorphic-dompurify`'s browser build, so no hook another script adds to the page's shared DOMPurify takes part) and the same nesting limit (`too-large` deeper than 512 levels). The server's other resource limits do not apply there: the host's converter bounds the HTML (`maxHtmlBytes`), and the rendering never leaves the browser.
120
+ The only thing the browser takes from the server for it is the existence marks of images and linked documents, read from the HTML the server's `preview` operation answered (sanitized on the server) and written by the browser's sanitizer onto the elements naming the same document paths, exactly as the converter writes them; a draft the converter answers `unavailable` for is rendered by the server as before.
119
121
  - What the host must do: decide per document and per reader whether a document is editable, and check it again in every port (a request names any admitted path); write with the reader's own credentials, never a service account's; write only when the document still has the draft's base version, and otherwise answer the current content without writing; keep revisions only where readers may see them.
120
122
 
121
123
  ## Link cards