@aiquants/markdown-explorer 0.38.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +2 -2
  3. package/dist/{EditSurface-BTrQ1viw.js → EditSurface-CUPN9dUY.js} +211 -211
  4. package/dist/{EditSurface-Dis52Iwq.cjs → EditSurface-CZnjX0sv.cjs} +2 -2
  5. package/dist/{ExplorerSplit-Dq7HfNre.js → ExplorerSplit-DHpgdXhb.js} +407 -407
  6. package/dist/{ExplorerSplit-13nPIuf0.cjs → ExplorerSplit-DWBhCe7m.cjs} +1 -1
  7. package/dist/{MultiLayout-B7RvBpCj.cjs → MultiLayout-BkHbfUuh.cjs} +1 -1
  8. package/dist/{MultiLayout-1rKm2Hzt.js → MultiLayout-HmvjE8ht.js} +3 -3
  9. package/dist/{NativeScrollBar-D63-6AL1.cjs → NativeScrollBar-CzGhZ-w3.cjs} +1 -1
  10. package/dist/{NativeScrollBar-Bg05yuzM.js → NativeScrollBar-DAukiH01.js} +2 -2
  11. package/dist/{TreeLayout-CNE0XkWz.cjs → TreeLayout-BEvPaxLb.cjs} +1 -1
  12. package/dist/{TreeLayout-9eEP62LF.js → TreeLayout-dtnugwQ7.js} +3 -3
  13. package/dist/core/geometry.d.cts +0 -1
  14. package/dist/core/geometry.d.ts +0 -1
  15. package/dist/{explorerCore-GCqatHTO.js → explorerCore-CUtc1Vmx.js} +1 -1
  16. package/dist/{explorerCore-5qeC3-gt.cjs → explorerCore-Dj7RxZRd.cjs} +1 -1
  17. package/dist/{index-C52Nj37x.js → index-BBJoJu-b.js} +7 -7
  18. package/dist/{index-_XNluAcx.cjs → index-D6at9qMs.cjs} +5 -5
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.js +15 -15
  21. package/dist/location-DFXJSMit.cjs +1 -0
  22. package/dist/{location-CJvL6JNs.js → location-T9o5XYpX.js} +74 -75
  23. package/dist/{merge-CnrrjXmc.js → merge-CkMe5hqA.js} +1 -1
  24. package/dist/{merge-CKpFyeqR.cjs → merge-XyuOlVWP.cjs} +1 -1
  25. package/dist/server.cjs +1 -1
  26. package/dist/server.js +3 -3
  27. package/dist/serverCore.cjs +1 -1
  28. package/dist/serverCore.js +3 -3
  29. package/dist/styles/markdown-explorer.css +1 -1
  30. package/dist/{tapScrollCircle-D-Lgzdxx.js → tapScrollCircle-CvWJKtbF.js} +1 -1
  31. package/dist/{tapScrollCircle-6etmzCb7.cjs → tapScrollCircle-ExxyHVWY.cjs} +1 -1
  32. package/dist/{useSplitPersistence-CD_n1ivo.cjs → useSplitPersistence-BCitqdAe.cjs} +1 -1
  33. package/dist/{useSplitPersistence-tbTu3P5m.js → useSplitPersistence-C86jW1yY.js} +1 -1
  34. package/package.json +3 -3
  35. package/dist/location-DOIG84V9.cjs +0 -1
@@ -1,2 +1,2 @@
1
1
  /*! Bundled third-party code: @heroicons/react 2.2.0 (MIT, ./licenses/@heroicons/react/LICENSE) */
2
- "use strict";const a=require("react/jsx-runtime"),b=require("./index-_XNluAcx.cjs"),n=require("react"),M=require("./location-DOIG84V9.cjs"),Te=require("react-router"),We=require("./ownUrls-BTPGNhBt.cjs"),rt=require("@aiquants/directory-tree"),nt=require("./tapScrollCircle-6etmzCb7.cjs"),qt=require("./storage-BpYsprog.cjs"),lt=require("./describeValue-Ccvhbt36.cjs"),Ce=require("@aiquants/resize-panels"),Xe=require("./useSplitPersistence-CD_n1ivo.cjs");function Mt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const l=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,l.get?l:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const h=Mt(n);function _t({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M19.5 21a3 3 0 0 0 3-3V9a3 3 0 0 0-3-3h-5.379a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H4.5a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3h15ZM9 12.75a.75.75 0 0 0 0 1.5h6a.75.75 0 0 0 0-1.5H9Z",clipRule:"evenodd"}))}const It=h.forwardRef(_t);function Dt({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M19.5 21a3 3 0 0 0 3-3V9a3 3 0 0 0-3-3h-5.379a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H4.5a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3h15Zm-6.75-10.5a.75.75 0 0 0-1.5 0v2.25H9a.75.75 0 0 0 0 1.5h2.25v2.25a.75.75 0 0 0 1.5 0v-2.25H15a.75.75 0 0 0 0-1.5h-2.25V10.5Z",clipRule:"evenodd"}))}const Ht=h.forwardRef(Dt);function Bt({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M16.5 6a3 3 0 0 0-3-3H6a3 3 0 0 0-3 3v7.5a3 3 0 0 0 3 3v-6A4.5 4.5 0 0 1 10.5 6h6Z"}),h.createElement("path",{d:"M18 7.5a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3h-7.5a3 3 0 0 1-3-3v-7.5a3 3 0 0 1 3-3H18Z"}))}const Zt=h.forwardRef(Bt);function $t({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M3 6a3 3 0 0 1 3-3h2.25a3 3 0 0 1 3 3v2.25a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3V6Zm9.75 0a3 3 0 0 1 3-3H18a3 3 0 0 1 3 3v2.25a3 3 0 0 1-3 3h-2.25a3 3 0 0 1-3-3V6ZM3 15.75a3 3 0 0 1 3-3h2.25a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-2.25Zm9.75 0a3 3 0 0 1 3-3H18a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3h-2.25a3 3 0 0 1-3-3v-2.25Z",clipRule:"evenodd"}))}const zt=h.forwardRef($t),Vt="http://path.invalid",Kt=/[\t\n\r]/gu,Ut=(e,t,r,l)=>{const c=e.replace(Kt,"");if(!c.startsWith("/")||c.startsWith("//")||c.includes("\\"))return null;const{pathname:i,search:o,hash:s}=new URL(c,Vt);return!We.isUnder(i,[t])||We.isUnder(i,[r])?null:`${l}${i.slice(t.length)}${o}${s}`},Wt=()=>{const{notices:e,config:t}=b.useExplorer(),r=n.use(e),l=Te.useHref(t.basePath),c=Te.useHref(t.dataPath);return r.length===0?null:a.jsx("div",{className:"aqmx-explorer-notices",children:r.map(i=>{const o=i.action===void 0?null:Ut(i.action.href,l,c,t.basePath);return a.jsxs("div",{className:"aqmx-callout","data-aqmx-tone":i.tone,"data-testid":"markdown-explorer-notice","data-aqmx-notice":i.id,children:[a.jsx("p",{className:"aqmx-callout-title",children:i.title}),i.body===void 0?null:a.jsx("p",{className:"aqmx-callout-body",children:i.body}),i.action===void 0?null:o===null?a.jsx("a",{className:"aqmx-callout-action",href:i.action.href,children:i.action.label}):a.jsx(b.ExplorerLink,{className:"aqmx-callout-action",to:o,navigation:"follow-link",children:i.action.label})]},i.id)})})};function Xt({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M6.912 3a3 3 0 0 0-2.868 2.118l-2.411 7.838a3 3 0 0 0-.133.882V18a3 3 0 0 0 3 3h15a3 3 0 0 0 3-3v-4.162c0-.299-.045-.596-.133-.882l-2.412-7.838A3 3 0 0 0 17.088 3H6.912Zm13.823 9.75-2.213-7.191A1.5 1.5 0 0 0 17.088 4.5H6.912a1.5 1.5 0 0 0-1.434 1.059L3.265 12.75H6.11a3 3 0 0 1 2.684 1.658l.256.513a1.5 1.5 0 0 0 1.342.829h3.218a1.5 1.5 0 0 0 1.342-.83l.256-.512a3 3 0 0 1 2.684-1.658h2.844Z",clipRule:"evenodd"}))}const Gt=h.forwardRef(Xt),qe=n.createContext(!0),at=n.createContext(null),ot="\0loop\0",st="\0",Yt=()=>{const e=new WeakMap,t=new WeakMap,r=new WeakMap,l=o=>{const s=e.get(o);if(s!==void 0)return s;const p=Object.freeze({type:"loop",name:o.name,path:o.path});return e.set(o,p),p},c=(o,s,p)=>{let f=!1;const d=o.map(m=>{const w=i(m,s,p);return w!==m&&(f=!0),w});if(!f)return o;const u=r.get(o);return u!==void 0&&u.length===d.length&&u.every((m,w)=>m===d[w])?u:(r.set(o,d),d)},i=(o,s,p)=>{if(o.type!=="directory")return o;if(p.has(o.path))return l(o);const f=o.lazy===!0?s(o.path):void 0,d=f?.status==="loaded",u=d?f.entries:o.children;if(u===void 0)return o;p.add(o.path);const m=c(u,s,p);if(p.delete(o.path),!d&&m===o.children)return o;const w=t.get(o);if(w!==void 0&&w.state===f&&w.children===m)return w.grafted;const g={...o,children:m,lazy:d?!1:o.lazy};return t.set(o,{state:f,children:m,grafted:g}),g};return(o,s)=>c(o,s,new Set)},Qt=(e,t)=>`${ot}${e}${st}${t}`,me=e=>e.startsWith(ot),Jt=e=>e.slice(e.lastIndexOf(st)+1),ae="data-aqmx-path",er=(e,t,r,l,c)=>{const i={aqmxPath:e.path};return e.modifiedAt!==void 0&&(i.aqmxModifiedAt=e.modifiedAt),r&&(i.aqmxOpen=!0),(l==="loading"||l==="failed")&&(i.aqmxChildren=l),{name:e.name,type:e.type,absolutePath:e.path,relativePath:e.path,mimeType:e.mimeType,children:t,label:c,data:i}},tr=(e,t,r,l)=>{const c=Qt(t,e.path);return{name:r,type:"directory",absolutePath:c,relativePath:c,children:l,data:{aqmxLoop:e.path}}},rr=()=>{const e=new WeakMap,t=new WeakMap,r=new WeakMap,l=[],c=(s,p,f)=>{const d=s.map(m=>m.type==="loop"?i(m,p,f):o(m,p)),u=r.get(s);return u!==void 0&&u.length===d.length&&u.every((m,w)=>m===d[w])?u:(r.set(s,d),d)},i=(s,p,f)=>{const d=t.get(s);if(d!==void 0&&d.parentKey===f&&d.loopFolderName===p.loopFolderName)return d.row;const u=tr(s,f,p.loopFolderName(s.name),l);return t.set(s,{row:u,parentKey:f,loopFolderName:p.loopFolderName}),u},o=(s,p)=>{const f=s.type==="directory"?s.children===void 0?l:c(s.children,p,s.path):void 0,d=p.openPaths.has(s.path),u=s.type==="directory"&&s.lazy===!0?p.childrenOf(s.path)?.status:void 0,m=u==="failed"?p.renderFailedFolder:void 0,w=e.get(s);if(w!==void 0&&w.open===d&&w.childrenStatus===u&&w.children===f&&w.renderFailedFolder===m)return w.row;const g=er(s,f,d,u,m===void 0?void 0:m(s));return e.set(s,{row:g,open:d,childrenStatus:u,children:f,renderFailedFolder:m}),g};return(s,p)=>c(s,p,"")},nr=e=>{if(e===void 0)return;const t=r=>{const l=r.data?.aqmxModifiedAt;return typeof l=="number"?{name:r.name,path:r.absolutePath,type:r.type,modifiedAt:l}:{name:r.name,path:r.absolutePath,type:r.type}};return(r,l)=>e(t(r),t(l))},Pe=(e,t)=>{const r=e.filter(l=>l.type==="directory");return t===void 0?r:r.sort(t)},lr=(e,t)=>{const r=new Map;let l=0;const c=i=>{for(const o of Pe(i,t.compare))if(t.isShownExpanded(o.path)){if(o.lazy!==!0){o.children!==void 0&&c(o.children);continue}r.has(o.path)||(r.set(o.path,t.isDirect(o.path)?"direct":"bulk"),t.childrenOf(o.path)?.status!=="failed"&&(l+=1))}};return c(e),{folders:r,waiting:l}},ar=e=>{const t=new Set,r=l=>{for(const c of l)c.type==="directory"&&(c.lazy===!0&&t.add(c.path),c.children!==void 0&&r(c.children))};return r(e),t},ct=(e,t)=>{for(const r of e){if(r.type!=="directory")continue;if(r.path===t)return r;const l=r.children===void 0?null:ct(r.children,t);if(l!==null)return l}return null},it=(e,t,r)=>{for(const l of e){if(l===t)return{parent:r};const c=l.children===void 0?null:it(l.children,t,l);if(c!==null)return c}return null},or=(e,t,r)=>{const l=it(e,r,null);if(l===null)throw new Error(`[markdown-explorer] the pressed folder's row is not among the tree's rows: ${lt.describeValue(r.absolutePath)}`);if(l.parent!==null)return{kind:"folder",path:l.parent.absolutePath};const c=M.folderReadmeOf(t.filter(i=>i.type!=="loop"));return c===null?{kind:"nothing"}:{kind:"document",path:c}},sr=(e,t,r,l)=>{let c=e;for(const i of t){const o=c.find(s=>s.type==="directory"&&s.path===i);if(o===void 0)return"missing";if(o.lazy===!0)return l.childrenOf(o.path)?.status==="failed"?"failed":"loading";if(!l.isShownExpanded(o.path))return"loading";c=o.children??[]}return c.some(i=>i.type==="file"&&i.path===r)?"ready":"missing"},Ge=new Set,cr=(e,t)=>e.has(t)?e:new Set(e).add(t),ir=(e,t)=>{if(!t.some(l=>e.has(l)))return e;const r=new Set(t);return new Set([...e].filter(l=>!r.has(l)))},ur=(e,t)=>[...e].every(r=>t.has(r))?e:new Set([...e].filter(r=>t.has(r))),dr=()=>{const[e,t]=n.useState(Ge),r=n.useCallback(o=>t(s=>cr(s,o)),[]),l=n.useCallback(o=>t(s=>ir(s,o)),[]),c=n.useCallback(o=>t(s=>ur(s,o)),[]),i=n.useCallback(()=>t(Ge),[]);return n.useMemo(()=>({direct:e,markDirect:r,unmarkDirect:l,pruneDirect:c,clearDirect:i}),[e,r,l,c,i])},fr=e=>({budget:e,handled:new Set,loads:new Set,opened:0,folderLimited:!1,depthLimited:!1,announcedStart:!1,issuedAgainst:null}),pr=(e,t)=>{const r=[];let l=Pe(t.entries,t.compare);for(let c=1;l.length>0;c+=1){const i=[];for(const o of l){const{path:s}=o;if(t.isShownExpanded(s))e.handled.add(s);else{if(e.handled.has(s))continue;if(e.handled.add(s),o.lazy===!0&&t.childrenOf(s)===void 0){if(c>e.budget.maxDepth){e.depthLimited=!0;continue}if(e.loads.size>=e.budget.maxFolders){e.folderLimited=!0;continue}e.loads.add(s)}r.push(s),e.opened+=1}o.lazy!==!0&&o.children!==void 0&&i.push(...Pe(o.children,t.compare))}l=i}return r},ut=(e,t)=>e.every(r=>r.type!=="directory"||t(r.path)&&(r.lazy===!0||r.children===void 0||ut(r.children,t))),mr=(e,t)=>{if(e.folderLimited)return{kind:"folder-limit",opened:e.opened};if(e.depthLimited)return{kind:"depth-limit",opened:e.opened};let r=0;for(const l of e.loads)t.childrenOf(l)?.status==="failed"&&(r+=1);return{kind:"done",opened:e.opened,failed:r,complete:ut(t.entries,t.isShownExpanded)}},Ne=Object.freeze({state:"idle"}),hr=e=>{const t=n.useRef(null),r=n.useRef(e),[l,c]=n.useState(Ne);n.useLayoutEffect(()=>{r.current=e});const i=n.useCallback(()=>{t.current===null&&(t.current=fr(r.current.budget),c({state:"running",opened:0}))},[]),o=n.useCallback(()=>{t.current=null,c(Ne)},[]),s=n.useCallback(p=>{const f=t.current;if(f===null)return;const d=pr(f,p);if(d.length>0&&(f.issuedAgainst=p.expanded,r.current.expandMultiple([...d])),!f.announcedStart&&(f.loads.size>0||p.waiting>0)&&(f.announcedStart=!0,r.current.onStart()),d.length===0&&!p.expansionPending&&p.expanded!==f.issuedAgainst&&p.waiting===0){t.current=null;const m=mr(f,p);c(m.kind==="done"?Ne:{state:"stopped",stop:m.kind,opened:m.opened}),r.current.onFinish(m);return}const{opened:u}=f;c(m=>m.state==="running"&&m.opened===u?m:{state:"running",opened:u})},[]);return n.useMemo(()=>({status:l,start:i,end:o,advance:s}),[l,i,o,s])},Ye=["pointerdown","wheel","touchstart","keydown","focusin"],xr=8,Qe={least:Number.POSITIVE_INFINITY,stalled:0},wr=({tree:e,container:t,path:r,chain:l,rows:c,cancel:i,displayed:o,placement:s})=>{const p=n.useRef(null),f=n.useRef(!0),d=n.useRef(Qe),u=n.useRef(null),m=n.useRef(null),w=n.useRef(l),g=n.useRef(s);n.useLayoutEffect(()=>{w.current=l,g.current=s},[l,s]);const v=n.useCallback(()=>{const k=u.current;k!==null&&(u.current=null,k.phase==="asking"?k.controller.abort():w.current?.open(null))},[]),y=n.useCallback(()=>{p.current=null,v()},[v]),L=n.useCallback(()=>{const k=t.current;p.current===null||m.current!==null||k===null||k.getClientRects().length===0||(m.current=requestAnimationFrame(()=>{m.current=null;const C=p.current;if(C===null)return;const F=g.current(C);if(F===0){f.current=!0,u.current?.phase==="opening"&&v();return}if(e.current?.scrollToPath(C,{align:"nearest"})===!0){u.current?.phase==="opening"&&v();const{least:R,stalled:q}=d.current;d.current=F<R?{least:F,stalled:0}:{least:R,stalled:q+1},d.current.stalled<xr&&L();return}const O=u.current;if(O===null){p.current=null;return}O.phase==="opening"&&w.current?.progress(O.folders,C)!=="loading"&&y()}))},[e,t,v,y]),j=n.useCallback(()=>{f.current=!1,d.current=Qe,L()},[L]);n.useEffect(()=>{const k=t.current;if(k===null)return;const C=typeof ResizeObserver>"u"?null:new ResizeObserver(j);C?.observe(k);for(const F of Ye)k.addEventListener(F,y,{passive:!0});return()=>{C?.disconnect();for(const F of Ye)k.removeEventListener(F,y);m.current!==null&&cancelAnimationFrame(m.current),m.current=null,v()}},[t,j,y,v]);const S=l!==null;n.useEffect(()=>{const k=t.current;if(y(),r===null||k===null||k.contains(k.ownerDocument.activeElement))return;p.current=r;const C=w.current;if(S&&C!==null){const F=new AbortController,O={phase:"asking",controller:F};u.current=O,C.ancestors(r,F.signal).then(R=>{u.current===O&&(R===null?u.current=null:(u.current={phase:"opening",folders:R},w.current?.open(R)),j())})}j()},[r,S,t,y,j]),n.useEffect(()=>{(u.current?.phase==="opening"||p.current!==null&&!f.current)&&j()},[c,j]);const D=n.useRef(i);n.useEffect(()=>{D.current!==i&&(D.current=i,y())},[i,y]);const _=n.useRef(o);n.useEffect(()=>{_.current&&!o&&v(),_.current=o},[o,v])},gr="--aqmx-tree-line",br=Object.freeze(["(forced-colors: active)","(prefers-color-scheme: dark)"]),Er="data-aqmx-tree-probe",vr=Object.freeze({rowHeight:M.CONTROL_BLOCK_PIXELS,lineColor:null}),Rr=(e,t,r)=>{const[l,c]=n.useState(vr);return n.useLayoutEffect(()=>{const i=e.current;if(i===null)return;const o=()=>{const f=Math.round(i.getBoundingClientRect().height),d=getComputedStyle(i),u=d.getPropertyValue(gr).trim()===""?null:d.color;c(m=>{const w=Number.isFinite(f)&&f>0?f:m.rowHeight;return m.rowHeight===w&&m.lineColor===u?m:{rowHeight:w,lineColor:u}})};o();const s=br.map(f=>window.matchMedia(f));for(const f of s)f.addEventListener("change",o);const p=typeof ResizeObserver>"u"?null:new ResizeObserver(o);return p?.observe(i),()=>{for(const f of s)f.removeEventListener("change",o);p?.disconnect()}},[e,t,r]),l},dt="markdown-explorer-tree-scroll",Sr=.5,ft=(e,t)=>[...e.querySelectorAll(`[role="treeitem"][${ae}]`)].find(r=>r.getAttribute(ae)===t),yr=(e,t)=>{const r=ft(e,t),l=r?.closest(`[data-testid="${dt}"]`);if(r===void 0||l===null||l===void 0)return Number.POSITIVE_INFINITY;const c=l.getBoundingClientRect(),i=r.getBoundingClientRect(),o=c.top-i.top,s=i.height>c.height?Math.abs(o):Math.max(0,o)+Math.max(0,i.bottom-c.bottom);return s<=Sr?0:s},Fe=Object.freeze({testId:dt,overscanCount:13,callbackThrottleMs:13,scrollBarOptions:Object.freeze({width:8,...b.SCROLL_BAR_CONTROLS,enableArrowButtons:!0,enableArrowButtonTabStops:!1,enableScrollToTopBottomButtons:!0,tapScrollCircleOptions:nt.TAP_SCROLL_CIRCLE}),behaviorOptions:Object.freeze({enablePointerDrag:!0})}),Cr=Object.freeze({...Fe,scrollBarOptions:Object.freeze({...Fe.scrollBarOptions,...b.TOUCH_SCROLL_BAR_CONTROLS,tapScrollCircleOptions:nt.TOUCH_TAP_SCROLL_CIRCLE})}),kr=e=>e?Cr:Fe,Tr={hoverClassName:"",directorySelectedClassName:"",itemSelectedClassName:""},Lr={color:"inherit",fontSize:"inherit"},jr={fontSize:"inherit"},Ar=new Set,Or=new Map,Nr={color:"var(--aqmx-tree-line)"},pt=e=>e instanceof Element?e.closest(`[${ae}]`):null,Pr=e=>{const t=pt(e);return t===null||t.getAttribute("data-entry-type")!=="file"?null:t.getAttribute(ae)},mt=(e,t,r,l)=>r==="folder-limit"?e.expandAllFolderLimit(l,t.maxFolders,e.expandAll):e.expandAllDepthLimit(l,t.maxDepth),Fr=(e,t,r)=>r.kind==="done"?e.expandAllDone(r.opened,r.failed,r.complete):mt(e,t,r.kind,r.opened),ht=()=>{const{labels:e}=b.useExplorer();return a.jsxs("div",{className:"aqmx-explorer-loading","aria-busy":"true","data-testid":"markdown-explorer-tree-loading",children:[a.jsx("p",{className:"aqmx-explorer-loading-text",children:e.treeLoading}),a.jsxs("div",{className:"aqmx-skeleton","aria-hidden":"true",children:[a.jsx("span",{}),a.jsx("span",{}),a.jsx("span",{}),a.jsx("span",{}),a.jsx("span",{})]})]})},qr=()=>{const{labels:e}=b.useExplorer();return a.jsxs("div",{className:"aqmx-empty","data-testid":"markdown-explorer-tree-empty",children:[a.jsx(Gt,{className:"aqmx-explorer-empty-icon","aria-hidden":"true"}),a.jsx("p",{className:"aqmx-empty-title",children:e.treeEmptyTitle}),a.jsx("p",{className:"aqmx-explorer-empty-body",children:e.treeEmptyBody})]})},Mr=({name:e,onRetry:t})=>{const{labels:r}=b.useExplorer(),l=n.useId();return a.jsxs("span",{className:"aqmx-explorer-folder-failed",children:[a.jsx("span",{className:"aqmx-explorer-folder-name",children:e}),a.jsx("span",{id:l,className:"aqmx-explorer-folder-error",children:r.folderLoadFailed}),a.jsxs("button",{type:"button",className:"aqmx-explorer-folder-retry","aria-describedby":l,"data-testid":"markdown-explorer-folder-retry",onClick:c=>{c.stopPropagation();const i=c.currentTarget,o=i.ownerDocument.activeElement===i?i.closest('[role="treeitem"]'):null;o instanceof HTMLElement&&b.focusWithoutScroll(o),t()},onKeyDown:c=>{c.key!=="Escape"&&c.stopPropagation()},children:[a.jsx(b.ForwardRef,{className:"aqmx-explorer-folder-retry-icon","aria-hidden":"true"}),a.jsx("span",{className:"aqmx-explorer-folder-retry-text",children:r.retry})]})]})},_r=({entries:e,version:t,mode:r,sourceId:l,settings:c,reveal:i,openPaths:o,selection:s,onOpenDocument:p,folders:f,onRevealSource:d,expansion:u,onShown:m,marks:w,claimsHeld:g,expandAll:v,revealCancel:y})=>{const{trees:L,documents:j,labels:S,locale:D,theme:_,paletteKey:k,data:C,config:F,sources:O,reveals:R}=b.useExplorer(),q=n.use(qe),T=n.use(at),[I]=n.useState(()=>T?.get(l)),$=kr(b.useCoarsePointer()),ce=n.useMemo(()=>I===void 0?$:{...$,initialScrollAnchor:I},[$,I]),[ie]=n.useState(rr),K=n.useRef(null),{rowHeight:oe,lineColor:X}=Rr(K,_,k),{isExpanded:Y,toggle:se,expandMultiple:H,collapseMultiple:ue,expanded:U,isPending:N}=u,{alwaysExpanded:Q,sortMode:W,folderPlacement:de,readmePlacement:fe}=c,{direct:ge,markDirect:J,unmarkDirect:te,pruneDirect:be}=w,{running:he,advance:xe}=v,A=n.useRef(null),z=n.useRef(null);n.useLayoutEffect(()=>{if(T===null)return;const x=A;return()=>{const E=x.current===null?null:x.current.getScrollAnchor();E===null?T.delete(l):T.set(l,E)}},[T,l]);const G=n.useMemo(()=>M.createEntryComparator({sortMode:W,folderPlacement:de,readmePlacement:fe}),[W,de,fe]),Rt=n.useMemo(()=>nr(G),[G]),ee=n.useCallback(x=>L.children(l,x),[L,l]),re=n.useMemo(()=>ar(e),[e]),we=n.useCallback(x=>Q&&!re.has(x),[Q,re]),ne=n.useCallback(x=>!me(x)&&(Y(x)||we(x)),[Y,we]),B=n.useRef({shownExpanded:ne,isExpanded:Y,isHeld:we,unloadedFolders:re,entries:e,childrenOf:ee,folderSelection:f,openDocument:p});n.useLayoutEffect(()=>{B.current={shownExpanded:ne,isExpanded:Y,isHeld:we,unloadedFolders:re,entries:e,childrenOf:ee,folderSelection:f,openDocument:p}},[ne,Y,we,re,e,ee,f,p]);const[le]=n.useState(()=>new Map),Le=n.useCallback((x,E)=>{R.settle(E),x.open(E)},[R]),Ee=n.useCallback((x,E)=>{E.kind!=="nothing"&&R.settle(E.path),x.close(E)},[R]),pe=n.useCallback((x,E)=>{for(const P of x){const Z=le.get(P);if(Z===void 0)continue;le.delete(P);const V=B.current.folderSelection;!E&&V!==null&&V.current===P&&Ee(V,Z)}},[le,Ee]),De=n.useCallback(x=>{A.current?.scrollToPath(x,{align:"nearest"}),requestAnimationFrame(()=>{const E=z.current,P=E===null?void 0:ft(E,x);P!==void 0&&b.focusWithoutScroll(P)})},[]),St=n.useCallback(x=>{if(me(x)){De(Jt(x));return}pe([x],!B.current.shownExpanded(x)),B.current.isExpanded(x)?te([x]):B.current.unloadedFolders.has(x)&&J(x),se(x)},[De,pe,J,te,se]),je=n.useCallback(x=>{const E=x.filter(P=>!me(P));E.length!==0&&(pe(E,!1),te(E),ue(E))},[pe,te,ue]),yt=n.useCallback(x=>{const E=x.filter(P=>!me(P));if(E.length!==0){if(E.length<x.length&&E.every(P=>B.current.shownExpanded(P))){je(E);return}pe(E,!0),H(E)}},[pe,H,je]),He=n.useCallback(x=>a.jsx(Mr,{name:x.name,onRetry:()=>{J(x.path),L.retryChildren(l,x.path),B.current.shownExpanded(x.path)||H([x.path])}}),[L,l,J,H]),Be=r==="multi"?o:Ar,{loopFolderName:Ze}=S,ve=n.useMemo(()=>ie(e,{openPaths:Be,childrenOf:ee,renderFailedFolder:He,loopFolderName:Ze}),[ie,e,Be,ee,He,Ze,t]),$e=n.useRef(ve);n.useLayoutEffect(()=>{$e.current=ve},[ve]);const Ct=b.useIntentPrefetch(j,Pr),ze=n.useRef([]),Re=n.useCallback(()=>{for(const x of ze.current)B.current.unloadedFolders.has(x)&&J(x)},[J]),{maxDepth:Ae}=F.revealDocument,Ve=n.useRef(d);n.useLayoutEffect(()=>{Ve.current=d},[d]);const kt=n.useMemo(()=>({ancestors:async(x,E)=>{const P=R.take(l,x);if(P!==null)return P;if(!R.mayMove(x)){const V=await C.ancestors(l,x,E);return V.status!=="ok"||V.ancestors===null||V.ancestors.length>Ae?null:V.ancestors}const Z=await C.reveal(l,x,E);return Z.status!=="ok"||Z.source===null||Z.ancestors.length>Ae?null:Z.source===l?Z.ancestors:(E.aborted||!O.some(V=>V.id===Z.source)||(R.move(Z.source,x,Z.ancestors),Ve.current(Z.source)),null)},open:x=>{ze.current=x??[],x!==null&&(Re(),H([...x]))},progress:(x,E)=>sr(B.current.entries,x,E,{isShownExpanded:B.current.shownExpanded,childrenOf:B.current.childrenOf})}),[C,l,O,R,Ae,Re,H]);n.useEffect(()=>Re(),[Re,re]);const Tt=n.useMemo(()=>[e,t,U],[e,t,U]),Lt=n.useCallback(x=>z.current===null?Number.POSITIVE_INFINITY:yr(z.current,x),[]);wr({tree:A,container:z,path:i.path,chain:i.openFolders?kt:null,rows:Tt,cancel:y,displayed:q,placement:Lt});const Ke=n.useCallback(x=>ge.has(x),[ge]),Se=n.useMemo(()=>lr(e,{isShownExpanded:ne,childrenOf:ee,compare:G,isDirect:Ke}),[e,ne,ee,G,Ke,t]),ye=q&&g;n.useLayoutEffect(()=>{m(e)},[e,m]),n.useLayoutEffect(()=>()=>m(null),[m]),n.useEffect(()=>L.claimChildren(l,ye?Se.folders:Or),[L,l,ye,Se]),n.useEffect(()=>be(re),[be,re]),n.useEffect(()=>{ye&&he&&xe({entries:e,isShownExpanded:ne,childrenOf:ee,compare:G,expanded:U,waiting:Se.waiting,expansionPending:N})},[ye,he,xe,e,ne,ee,G,U,Se,N]);const jt=n.useCallback(x=>{const E=x.entry.absolutePath,{folderSelection:P,openDocument:Z}=B.current;if(x.isDirectory){if(P===null||me(E))return;const V=E===P.current,Ue=or($e.current,B.current.entries,x.entry);if(B.current.isHeld(E)){x.preventDefault(),le.delete(E),V?Ee(P,Ue):Le(P,E);return}le.set(E,Ue),x.isExpanded||V||Le(P,E);return}R.settle(E),Z(E)},[R,le,Ee,Le]),At=n.useCallback(x=>{if(x.key!=="ArrowLeft"&&x.key!=="ArrowRight")return;const E=pt(x.target),P=E===null?null:E.getAttribute(ae);P!==null&&le.delete(P)},[le]),{onChange:Oe}=s,Ot=n.useMemo(()=>Oe===null?void 0:(x,E)=>{me(x.absolutePath)||Oe({path:x.absolutePath,name:x.name,selected:E})},[Oe]),Nt=n.useMemo(()=>new Set(s.items),[s.items]),Pt=n.useMemo(()=>({entryKindDirectory:S.treeEntryKindDirectory,entryKindFile:S.treeEntryKindFile,scrollUp:S.treeScrollUp,scrollDown:S.treeScrollDown,scrollToTop:S.treeScrollToTop,scrollToBottom:S.treeScrollToBottom}),[S]),Ft=X===null?{showTreeLines:!1}:{showTreeLines:c.lines,lineColor:X};return a.jsxs("div",{ref:z,className:"aqmx-explorer-tree","data-testid":"markdown-explorer-tree",onKeyDownCapture:At,...Ct,children:[a.jsx("span",{ref:K,className:"aqmx-explorer-tree-probe","aria-hidden":"true",[Er]:""}),a.jsx(rt.DirectoryTree,{ref:A,entries:ve,expansion:{toggle:St,isExpanded:ne,expandMultiple:yt,collapseMultiple:je,isPending:N&&!he,doubleClickAction:c.doubleClickAction},selection:{mode:s.mode,selectedPath:s.shownPath,currentPath:s.shownPath,selectedItems:Nt,onEntryClick:jt,onSelectionChange:Ot},visual:{className:"aqmx-explorer-tree-view",ariaLabel:S.treeRegion,...Ft,showExpandIcons:c.expandIcons,expandIconStyle:Nr,showDirectoryIcons:c.directoryIcons,showFileIcons:c.fileIcons,expandIconSize:c.expandIconSize,itemHeight:oe,removeRootIndent:c.removeRootIndent,highlightStyles:Tr,entryStyle:jr,nameStyle:Lr},virtualScroll:ce,sort:Rt,locale:D,labels:Pt})]})},Ir=({pending:e,status:t})=>{const{labels:r}=b.useExplorer(),l=t.state!=="running",[c,i]=n.useState(0),o=n.useRef(!0);n.useLayoutEffect(()=>{const p=o.current;if(o.current=l,!l||e>0&&!p){i(0);return}if(e>0){i(e);return}if(c===0)return;const f=setTimeout(()=>i(0),0);return()=>clearTimeout(f)},[l,e,c]);const s=l&&e===0?c:e;return s===0&&l?null:a.jsxs("p",{className:"aqmx-explorer-tree-progress","data-testid":"markdown-explorer-tree-progress","data-aqmx-loading":String(s),"data-aqmx-expand-all":t.state,children:[s>0?a.jsx(b.ForwardRef,{className:"aqmx-explorer-tree-progress-icon","aria-hidden":"true"}):null,a.jsx("span",{children:t.state==="running"?r.expandAllProgress(t.opened,s):r.foldersLoading(s)})]})},Dr=({stop:e,opened:t,budget:r})=>{const{labels:l}=b.useExplorer();return a.jsx("p",{className:"aqmx-explorer-expand-all-stop","data-testid":"markdown-explorer-expand-all-stop","data-aqmx-stop":e,children:mt(l,r,e,t)})},Hr=({entries:e,...t})=>{const{trees:r}=b.useExplorer(),l=n.useSyncExternalStore(r.subscribe,r.version,r.version),{sourceId:c}=t,[i]=n.useState(Yt),o=n.useMemo(()=>i(e,s=>r.children(c,s)),[i,e,r,c,l]);return o.length===0?a.jsx(qr,{}):a.jsx(_r,{entries:o,version:l,...t})},Br=({result:e,onRetry:t,...r})=>{const{renderTreeFailure:l}=b.useExplorer(),c=n.use(e);if(c.status==="deferred")return a.jsx(ht,{});if(c.status==="ok")return a.jsx(Hr,{entries:c.entries,...r});const i=l?.(c.failure);return a.jsx("div",{className:"aqmx-explorer-tree-message","data-testid":"markdown-explorer-tree-failure","data-aqmx-failure":c.failure.reason,children:i!==void 0?i:a.jsx(b.FailureView,{failure:c.failure,alert:!0,onRetry:t,testId:null})})},Zr=Object.freeze([]),$r=e=>e!==void 0&&e.status==="failed"&&b.isAccessFailureReason(e.failure.reason),zr=({failure:e,onRetry:t})=>a.jsx(b.AccessFailureNotice,{failure:e,place:"read",deniedSentence:null,retry:t,testId:"markdown-explorer-folder-access-failure"}),Vr=({onControls:e,...t})=>{const{trees:r,storageNamespace:l,labels:c,announcer:i,config:o}=b.useExplorer(),{sourceId:s}=t,p=rt.useDirectoryTreeState({storageKey:qt.storageKeys(l).treeExpansion(s)});n.useSyncExternalStore(r.subscribe,r.version,r.version);const f=r.read(s),d=n.useCallback(()=>r.retry(s),[r,s]);n.useLayoutEffect(()=>r.open(s),[r,s]);const u=dr(),{expanded:m,expandMultiple:w,collapseAll:g}=p,[v,y]=n.useState(null),L=v!==m,j=n.useRef(m);n.useLayoutEffect(()=>{j.current=m},[m]);const S=o.expandAll,D=n.useCallback(()=>i.announce(c.expandAllStarted),[i,c]),_=n.useCallback(N=>i.announce(Fr(c,S,N)),[i,c,S]),k=hr({budget:S,expandMultiple:w,onStart:D,onFinish:_}),{status:C,start:F,end:O,advance:R}=k,q=C.state==="running",T=n.useMemo(()=>({running:q,advance:R}),[q,R]),I=n.useRef(null),[$,ce]=n.useState(!1),ie=n.useCallback(N=>{I.current=N,ce(N!==null)},[]),[K,oe]=n.useState(null);n.useEffect(()=>r.subscribeChildrenFailures(N=>{const Q=N.sourceId===s&&I.current!==null?ct(I.current,N.path):null;if(Q!==null){if(b.isAccessFailureReason(N.failure.reason)){oe(W=>W===null?{failure:N.failure,paths:[N.path]}:W.paths.includes(N.path)?W:{failure:W.failure,paths:[...W.paths,N.path]});return}i.announce({list:c.foldersLoadFailedNamed,item:Q.name})}}),[r,s,i,c]);const X=K===null?Zr:K.paths.filter(N=>$r(r.children(s,N)));K!==null&&X.length===0&&oe(null);const Y=()=>{for(const N of X)r.retryChildren(s,N)},{clearDirect:se}=u,[H,ue]=n.useState(0),U=n.useCallback(()=>{ue(N=>N+1),O(),se(),y(j.current),g()},[O,se,g]);return n.useEffect(()=>{e({collapseAll:U,expandAll:$?F:null,expanding:q})},[e,U,F,$,q]),n.useEffect(()=>()=>e(null),[e]),n.useEffect(()=>{$||O()},[$,O]),a.jsxs(a.Fragment,{children:[K===null||X.length===0?null:a.jsx(zr,{failure:K.failure,onRetry:Y}),C.state==="stopped"?a.jsx(Dr,{stop:C.stop,opened:C.opened,budget:S}):null,a.jsxs("div",{className:"aqmx-explorer-tree-area",children:[a.jsx(n.Suspense,{fallback:a.jsx(ht,{}),children:a.jsx(Br,{result:f,onRetry:d,expansion:p,onShown:ie,marks:u,claimsHeld:L,expandAll:T,revealCancel:H,...t})}),a.jsx(Ir,{pending:r.pendingChildren(s),status:C})]})]})};function Kr({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M5.47 5.47a.75.75 0 0 1 1.06 0L12 10.94l5.47-5.47a.75.75 0 1 1 1.06 1.06L13.06 12l5.47 5.47a.75.75 0 1 1-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 0 1-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const Me=h.forwardRef(Kr),Je="markdown-explorer-selection-remove",Ur=({selection:e,onRemove:t,onClear:r,onOpenSelection:l,onLeave:c})=>{const{labels:i}=b.useExplorer(),o=n.useId(),s=n.useRef(null),p=[...e],f=(u,m)=>{if(m.ownerDocument.activeElement===m){const w=s.current===null?[]:[...s.current.querySelectorAll(`[data-testid="${Je}"]`)],g=w.indexOf(m),v=[w[g+1],w[g-1]].find(y=>y!==void 0);v===void 0?c():v.focus()}t(u)},d=()=>{const u=s.current;u!==null&&u.contains(u.ownerDocument.activeElement)&&c(),r()};return a.jsxs("section",{ref:s,className:"aqmx-explorer-tray","aria-labelledby":o,"data-testid":"markdown-explorer-selection-tray",children:[a.jsxs("div",{className:"aqmx-explorer-tray-header",children:[a.jsx("p",{id:o,className:"aqmx-explorer-tray-title",children:i.selectionTitle(p.length)}),a.jsx("button",{type:"button",className:"aqmx-explorer-tray-button","data-testid":"markdown-explorer-selection-clear",onClick:d,children:i.clearSelection})]}),a.jsx("ul",{className:"aqmx-explorer-tray-list",children:p.map(([u,m])=>a.jsxs("li",{className:"aqmx-explorer-tray-item",children:[a.jsx("span",{className:"aqmx-explorer-tray-name",title:u,children:m}),a.jsx("button",{type:"button",className:"aqmx-icon-button aqmx-explorer-tray-remove","aria-label":i.removeFromSelection(m),title:i.removeFromSelection(m),"data-testid":Je,"data-aqmx-path":u,onClick:w=>f(u,w.currentTarget),children:a.jsx(Me,{"aria-hidden":"true"})})]},u))}),l===void 0?null:a.jsx("button",{type:"button",className:"aqmx-explorer-tray-open","data-testid":"markdown-explorer-selection-open",onClick:()=>l(p.map(([u])=>u)),children:i.openSelectionInMulti(p.length)})]})},ke=new Map,Wr=(e,t)=>{if(t.selected===e.has(t.path))return e;const r=new Map(e);return t.selected?r.set(t.path,t.name):r.delete(t.path),r},Xr=(e,t)=>{if(!e.has(t))return e;const r=new Map(e);return r.delete(t),r},xt=n.createContext(null),Gr=e=>{const t=n.use(xt);n.useLayoutEffect(()=>{if(t!==null)return t(e),()=>t(!1)},[t,e])};function Yr({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M6.97 2.47a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1-1.06 1.06L8.25 4.81V16.5a.75.75 0 0 1-1.5 0V4.81L3.53 8.03a.75.75 0 0 1-1.06-1.06l4.5-4.5Zm9.53 4.28a.75.75 0 0 1 .75.75v11.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 1 1 1.06-1.06l3.22 3.22V7.5a.75.75 0 0 1 .75-.75Z",clipRule:"evenodd"}))}const Qr=h.forwardRef(Yr);function Jr({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M11.25 4.533A9.707 9.707 0 0 0 6 3a9.735 9.735 0 0 0-3.25.555.75.75 0 0 0-.5.707v14.25a.75.75 0 0 0 1 .707A8.237 8.237 0 0 1 6 18.75c1.995 0 3.823.707 5.25 1.886V4.533ZM12.75 20.636A8.214 8.214 0 0 1 18 18.75c.966 0 1.89.166 2.75.47a.75.75 0 0 0 1-.708V4.262a.75.75 0 0 0-.5-.707A9.735 9.735 0 0 0 18 3a9.707 9.707 0 0 0-5.25 1.533v16.103Z"}))}const en=h.forwardRef(Jr);function tn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12Zm13.36-1.814a.75.75 0 1 0-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 0 0-1.06 1.06l2.25 2.25a.75.75 0 0 0 1.14-.094l3.75-5.25Z",clipRule:"evenodd"}))}const rn=h.forwardRef(tn);function nn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M7.72 12.53a.75.75 0 0 1 0-1.06l7.5-7.5a.75.75 0 1 1 1.06 1.06L9.31 12l6.97 6.97a.75.75 0 1 1-1.06 1.06l-7.5-7.5Z",clipRule:"evenodd"}))}const ln=h.forwardRef(nn);function an({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M11.47 4.72a.75.75 0 0 1 1.06 0l3.75 3.75a.75.75 0 0 1-1.06 1.06L12 6.31 8.78 9.53a.75.75 0 0 1-1.06-1.06l3.75-3.75Zm-3.75 9.75a.75.75 0 0 1 1.06 0L12 17.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-3.75 3.75a.75.75 0 0 1-1.06 0l-3.75-3.75a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const on=h.forwardRef(an);function sn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M11.078 2.25c-.917 0-1.699.663-1.85 1.567L9.05 4.889c-.02.12-.115.26-.297.348a7.493 7.493 0 0 0-.986.57c-.166.115-.334.126-.45.083L6.3 5.508a1.875 1.875 0 0 0-2.282.819l-.922 1.597a1.875 1.875 0 0 0 .432 2.385l.84.692c.095.078.17.229.154.43a7.598 7.598 0 0 0 0 1.139c.015.2-.059.352-.153.43l-.841.692a1.875 1.875 0 0 0-.432 2.385l.922 1.597a1.875 1.875 0 0 0 2.282.818l1.019-.382c.115-.043.283-.031.45.082.312.214.641.405.985.57.182.088.277.228.297.35l.178 1.071c.151.904.933 1.567 1.85 1.567h1.844c.916 0 1.699-.663 1.85-1.567l.178-1.072c.02-.12.114-.26.297-.349.344-.165.673-.356.985-.57.167-.114.335-.125.45-.082l1.02.382a1.875 1.875 0 0 0 2.28-.819l.923-1.597a1.875 1.875 0 0 0-.432-2.385l-.84-.692c-.095-.078-.17-.229-.154-.43a7.614 7.614 0 0 0 0-1.139c-.016-.2.059-.352.153-.43l.84-.692c.708-.582.891-1.59.433-2.385l-.922-1.597a1.875 1.875 0 0 0-2.282-.818l-1.02.382c-.114.043-.282.031-.449-.083a7.49 7.49 0 0 0-.985-.57c-.183-.087-.277-.227-.297-.348l-.179-1.072a1.875 1.875 0 0 0-1.85-1.567h-1.843ZM12 15.75a3.75 3.75 0 1 0 0-7.5 3.75 3.75 0 0 0 0 7.5Z",clipRule:"evenodd"}))}const cn=h.forwardRef(sn);function un({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M12 1.5a.75.75 0 0 1 .75.75V4.5a.75.75 0 0 1-1.5 0V2.25A.75.75 0 0 1 12 1.5ZM5.636 4.136a.75.75 0 0 1 1.06 0l1.592 1.591a.75.75 0 0 1-1.061 1.06l-1.591-1.59a.75.75 0 0 1 0-1.061Zm12.728 0a.75.75 0 0 1 0 1.06l-1.591 1.592a.75.75 0 0 1-1.06-1.061l1.59-1.591a.75.75 0 0 1 1.061 0Zm-6.816 4.496a.75.75 0 0 1 .82.311l5.228 7.917a.75.75 0 0 1-.777 1.148l-2.097-.43 1.045 3.9a.75.75 0 0 1-1.45.388l-1.044-3.899-1.601 1.42a.75.75 0 0 1-1.247-.606l.569-9.47a.75.75 0 0 1 .554-.68ZM3 10.5a.75.75 0 0 1 .75-.75H6a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 10.5Zm14.25 0a.75.75 0 0 1 .75-.75h2.25a.75.75 0 0 1 0 1.5H18a.75.75 0 0 1-.75-.75Zm-8.962 3.712a.75.75 0 0 1 0 1.061l-1.591 1.591a.75.75 0 1 1-1.061-1.06l1.591-1.592a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const dn=h.forwardRef(un);function fn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625ZM7.5 15a.75.75 0 0 1 .75-.75h7.5a.75.75 0 0 1 0 1.5h-7.5A.75.75 0 0 1 7.5 15Zm.75 2.25a.75.75 0 0 0 0 1.5H12a.75.75 0 0 0 0-1.5H8.25Z",clipRule:"evenodd"}),h.createElement("path",{d:"M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"}))}const pn=h.forwardRef(fn);function mn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M19.5 21a3 3 0 0 0 3-3v-4.5a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3V18a3 3 0 0 0 3 3h15ZM1.5 10.146V6a3 3 0 0 1 3-3h5.379a2.25 2.25 0 0 1 1.59.659l2.122 2.121c.14.141.331.22.53.22H19.5a3 3 0 0 1 3 3v1.146A4.483 4.483 0 0 0 19.5 9h-15a4.483 4.483 0 0 0-3 1.146Z"}))}const hn=h.forwardRef(mn);function xn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M19.906 9c.382 0 .749.057 1.094.162V9a3 3 0 0 0-3-3h-3.879a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H6a3 3 0 0 0-3 3v3.162A3.756 3.756 0 0 1 4.094 9h15.812ZM4.094 10.5a2.25 2.25 0 0 0-2.227 2.568l.857 6A2.25 2.25 0 0 0 4.951 21H19.05a2.25 2.25 0 0 0 2.227-1.932l.857-6a2.25 2.25 0 0 0-2.227-2.568H4.094Z"}))}const wn=h.forwardRef(xn);function gn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M10.5 3.75a6.75 6.75 0 1 0 0 13.5 6.75 6.75 0 0 0 0-13.5ZM2.25 10.5a8.25 8.25 0 1 1 14.59 5.28l4.69 4.69a.75.75 0 1 1-1.06 1.06l-4.69-4.69A8.25 8.25 0 0 1 2.25 10.5Zm8.25-3.75a.75.75 0 0 1 .75.75v2.25h2.25a.75.75 0 0 1 0 1.5h-2.25v2.25a.75.75 0 0 1-1.5 0v-2.25H7.5a.75.75 0 0 1 0-1.5h2.25V7.5a.75.75 0 0 1 .75-.75Z",clipRule:"evenodd"}))}const bn=h.forwardRef(gn);function En({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M4.125 3C3.089 3 2.25 3.84 2.25 4.875V18a3 3 0 0 0 3 3h15a3 3 0 0 1-3-3V4.875C17.25 3.839 16.41 3 15.375 3H4.125ZM12 9.75a.75.75 0 0 0 0 1.5h1.5a.75.75 0 0 0 0-1.5H12Zm-.75-2.25a.75.75 0 0 1 .75-.75h1.5a.75.75 0 0 1 0 1.5H12a.75.75 0 0 1-.75-.75ZM6 12.75a.75.75 0 0 0 0 1.5h7.5a.75.75 0 0 0 0-1.5H6Zm-.75 3.75a.75.75 0 0 1 .75-.75h7.5a.75.75 0 0 1 0 1.5H6a.75.75 0 0 1-.75-.75ZM6 6.75a.75.75 0 0 0-.75.75v3c0 .414.336.75.75.75h3a.75.75 0 0 0 .75-.75v-3A.75.75 0 0 0 9 6.75H6Z",clipRule:"evenodd"}),h.createElement("path",{d:"M18.75 6.75h1.875c.621 0 1.125.504 1.125 1.125V18a1.5 1.5 0 0 1-3 0V6.75Z"}))}const vn=h.forwardRef(En);function Rn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M5.625 3.75a2.625 2.625 0 1 0 0 5.25h12.75a2.625 2.625 0 0 0 0-5.25H5.625ZM3.75 11.25a.75.75 0 0 0 0 1.5h16.5a.75.75 0 0 0 0-1.5H3.75ZM3 15.75a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75a.75.75 0 0 1-.75-.75ZM3.75 18.75a.75.75 0 0 0 0 1.5h16.5a.75.75 0 0 0 0-1.5H3.75Z"}))}const Sn=h.forwardRef(Rn),yn=Object.freeze({sortMode:Qr,folderPlacement:hn,readmePlacement:en,selectionMode:rn,doubleClickAction:dn,expandIconSize:bn,alwaysExpanded:b.ForwardRef$2,revealDocument:b.ForwardRef$1,showFolderReadme:vn,removeRootIndent:ln,lines:Sn,expandIcons:on,directoryIcons:wn,fileIcons:pn}),wt=(e,t)=>{const r=e[t.labelKey];if(typeof r!="string")throw new TypeError(`[markdown-explorer] the tree setting ${t.key} must name a string label; labels.${t.labelKey} is ${lt.describeValue(r)}`);return r},Cn=({id:e,settings:t,descriptors:r,onAdvance:l,onClose:c,ref:i})=>{const{labels:o}=b.useExplorer(),s=n.useRef([]);n.useEffect(()=>{s.current[0]?.focus()},[]);const p=n.useCallback(d=>{const u=r.length;s.current[(d%u+u)%u]?.focus()},[r.length]),f=n.useCallback((d,u)=>{switch(d.key){case"ArrowDown":d.preventDefault(),p(u+1);break;case"ArrowUp":d.preventDefault(),p(u-1);break;case"Home":d.preventDefault(),p(0);break;case"End":d.preventDefault(),p(r.length-1);break;case"Escape":b.consumeKey(d),c();break;case"Tab":c();break}},[r.length,p,c]);return a.jsx("div",{ref:i,id:e,role:"menu","aria-label":o.treeSettings,className:"aqmx-explorer-menu","data-testid":"markdown-explorer-tree-settings-menu",children:r.map((d,u)=>{const m=yn[d.key],w=wt(o,d),g=M.formatTreeSettingValue(o,t,d.key),v=t[d.key],y=typeof v=="boolean"?{role:"menuitemcheckbox","aria-checked":v,"aria-label":w}:{role:"menuitem","aria-label":`${w}: ${g}`};return a.jsxs("button",{ref:L=>{s.current[u]=L},type:"button",tabIndex:-1,...y,title:`${w}: ${g}`,className:"aqmx-explorer-menu-item","data-testid":"markdown-explorer-tree-settings-item","data-aqmx-setting":d.key,onClick:()=>l(d),onKeyDown:L=>f(L,u),children:[a.jsx(m,{className:"aqmx-explorer-menu-icon","aria-hidden":"true"}),a.jsx("span",{className:"aqmx-explorer-menu-name",children:w}),a.jsx("span",{className:"aqmx-explorer-menu-value",children:g})]},d.key)})})},kn=({settings:e,descriptors:t,onAdvance:r})=>{const{labels:l,announcer:c}=b.useExplorer(),[i,o]=n.useState(!1),s=n.useRef(null),p=n.useRef(null),f=n.useRef(null),d=n.useId(),u=n.useCallback(()=>{s.current?.focus(),o(!1)},[]);n.useEffect(()=>{if(!i)return;const g=v=>{v.target instanceof Node&&(s.current?.contains(v.target)===!0||p.current?.contains(v.target)===!0)||(o(!1),f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{f.current=null,(document.activeElement===null||document.activeElement===document.body)&&s.current?.focus()},0))};return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[i]),n.useEffect(()=>()=>{f.current!==null&&window.clearTimeout(f.current)},[]);const m=n.useCallback(g=>{g.key!=="Escape"||!i||(b.consumeKey(g),u())},[i,u]),w=n.useCallback(g=>{const v=r(g.key);c.announce(l.settingAnnouncement(wt(l,g),M.formatTreeSettingValue(l,v,g.key)))},[c,l,r]);return{trigger:a.jsx("button",{ref:s,type:"button",className:"aqmx-icon-button","aria-haspopup":"menu","aria-expanded":i,"aria-controls":i?d:void 0,"aria-label":l.treeSettings,title:l.treeSettings,"data-testid":"markdown-explorer-tree-settings",onClick:()=>o(g=>!g),onKeyDown:m,children:a.jsx(cn,{"aria-hidden":"true"})}),menu:i?a.jsx(Cn,{ref:p,id:d,settings:e,descriptors:t,onAdvance:w,onClose:u}):null}},Tn=()=>{const{treeSettings:e}=b.useExplorer();return{settings:n.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getServerSnapshot),advance:e.advance}},et=new Set,Ln='[role="tree"] [role="treeitem"][tabindex="0"]',jn="[data-directory-tree-tab-stop]",An=e=>{const{mode:t,sourceId:r,currentPath:l,openPaths:c,onOpenDocument:i,onSourceChange:o,onRevealSource:s,viewSwitch:p}=e,{labels:f,sources:d,trees:u,documents:m,announcer:w,reveals:g}=b.useExplorer(),{settings:v,advance:y}=Tn(),L=n.useMemo(()=>M.visibleTreeSettingDescriptors(t),[t]),j=t==="tree"&&v.selectionMode==="multiple";Gr(j);const S=e.mode==="tree"?e.tray.onGatheredChange:null,D=e.mode==="tree"?e.onOpenSelection:void 0,_=e.mode==="tree"?e.onOpenFolder:null,k=e.mode==="tree"?e.onCloseFolder:null,C=e.mode==="tree"&&e.currentFolder,F=n.useMemo(()=>_===null||k===null||!v.showFolderReadme?null:{current:l,open:_,close:k},[_,k,l,v.showFolderReadme]),O=e.mode==="tree"&&j?e.tray.gathered:ke,R=n.useCallback(A=>{const z=y(A);return z.selectionMode!=="multiple"&&S?.(ke),z},[y,S]),q=kn({settings:v,descriptors:L,onAdvance:R}),T=n.useCallback(A=>S?.(z=>Wr(z,A)),[S]),I=n.useCallback(A=>S?.(z=>Xr(z,A)),[S]),$=n.useCallback(()=>S?.(ke),[S]),ce=n.useRef(null),ie=n.useCallback(()=>{const A=ce.current;if(A===null)return;[Ln,jn,'[data-testid="markdown-explorer-tree-settings"]'].map(G=>A.querySelector(G)).find(G=>G!==null)?.focus()},[]),K=n.useMemo(()=>new Set(O.keys()),[O]),oe=n.useMemo(()=>l===null?et:new Set([l]),[l]),X=n.useMemo(()=>{if(t==="multi")return{mode:"multiple",items:c,shownPath:null,onChange:null};switch(v.selectionMode){case"single":return{mode:"single",items:oe,shownPath:l,onChange:null};case"multiple":return{mode:"multiple",items:K,shownPath:l,onChange:T};case"none":return{mode:"none",items:et,shownPath:null,onChange:null}}},[t,c,v.selectionMode,oe,l,K,T]),Y=n.useMemo(()=>v.revealDocument?{path:l,openFolders:!C}:{path:X.shownPath,openFolders:!1},[v.revealDocument,l,C,X.shownPath]),se=n.useCallback(A=>{l!==null&&g.settle(l),o(A)},[l,g,o]),[H,ue]=n.useState(null),[U,N]=n.useState(!1),[Q,W]=n.useState(null),de=n.useRef(!1),fe=n.useCallback(async()=>{if(!de.current){de.current=!0,N(!0),W(null);try{const A=await u.refresh(r);if(A.status==="superseded")return;m.invalidate(),A.status==="failed"?W({sourceId:r,failure:A.failure}):w.announce(f.treeRefreshed)}finally{de.current=!1,N(!1)}}},[u,m,r,w,f]),ge=n.useCallback(()=>{fe()},[fe]),J=H===null?null:H.expandAll,te=H?.expanding===!0,be=d.find(A=>A.id===r),he=p.target==="multi"?zt:Zt,xe=p.target==="multi"?f.switchToMulti:f.switchToTree;return a.jsxs("nav",{ref:ce,"aria-label":f.explorerRegion,className:"aqmx-explorer","data-testid":"markdown-explorer-explorer","data-aqmx-mode":t,children:[a.jsxs("div",{className:"aqmx-explorer-header",children:[d.length>1?a.jsx("select",{className:"aqmx-explorer-source","aria-label":f.sourceLabel,title:be?.label,value:r,onChange:A=>se(A.currentTarget.value),"data-testid":"markdown-explorer-source-select",children:d.map(A=>a.jsx("option",{value:A.id,children:A.label},A.id))}):null,a.jsxs("div",{className:"aqmx-explorer-actions",children:[a.jsx(b.ExplorerLink,{to:p.href,navigation:"switch-view",className:"aqmx-icon-button","aria-label":xe,title:xe,"data-testid":"markdown-explorer-view-switch","data-aqmx-target":p.target,children:a.jsx(he,{"aria-hidden":"true"})}),a.jsxs("button",{type:"button",className:"aqmx-icon-button aqmx-labelled-button",title:f.refreshTree,"aria-disabled":U,"aria-busy":U,"data-aqmx-busy":U?"true":void 0,"data-testid":"markdown-explorer-refresh",onClick:()=>{fe()},children:[a.jsx(b.ForwardRef,{"aria-hidden":"true"}),a.jsx("span",{children:f.refreshTreeLabel})]}),a.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.expandAll,title:f.expandAll,"aria-disabled":J===null||te,"aria-busy":te,"data-aqmx-busy":te?"true":void 0,"data-testid":"markdown-explorer-expand-all",onClick:()=>J?.(),children:a.jsx(Ht,{"aria-hidden":"true"})}),a.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.collapseAll,title:f.collapseAll,"aria-disabled":H===null,"data-testid":"markdown-explorer-collapse-all",onClick:()=>H?.collapseAll(),children:a.jsx(It,{"aria-hidden":"true"})}),q.trigger]})]}),a.jsxs("div",{className:"aqmx-explorer-body","data-aqmx-explorer-body":"",children:[a.jsx(b.SheetAccessFailureList,{}),Q!==null&&Q.sourceId===r?a.jsx(On,{failure:Q.failure,onRetry:ge}):null,a.jsx(n.Suspense,{fallback:null,children:a.jsx(Wt,{})}),a.jsx(Vr,{mode:t,sourceId:r,settings:v,reveal:Y,openPaths:c,selection:X,onOpenDocument:i,folders:F,onRevealSource:s,onControls:ue},r),j&&O.size>0?a.jsx(Ur,{selection:O,onRemove:I,onClear:$,onOpenSelection:D,onLeave:ie}):null,q.menu]})]})},On=({failure:e,onRetry:t})=>{const{labels:r}=b.useExplorer(),{reason:l}=e;return b.isAccessFailureReason(l)?a.jsx(b.AccessFailureNotice,{failure:e,place:"read",deniedSentence:null,retry:t,testId:"markdown-explorer-refresh-failure"}):a.jsx("p",{role:"alert",className:"aqmx-explorer-refresh-failure","data-testid":"markdown-explorer-refresh-failure","data-aqmx-failure":l,children:r.treeRefreshFailed(b.failureTitleOf(r,l))})};function Nn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M3 6.75A.75.75 0 0 1 3.75 6h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 6.75ZM3 12a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 12Zm0 5.25a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75a.75.75 0 0 1-.75-.75Z",clipRule:"evenodd"}))}const gt=h.forwardRef(Nn),Pn=({explorer:e,toggleRef:t,covered:r,merged:l,onNoticeSlotChange:c,accessFailures:i,dismissals:o})=>{const{labels:s}=b.useExplorer(),p=Te.useLocation(),f=Te.useNavigationType(),{location:d}=b.useExplorerLocation(),[u,m]=n.useState(!1),[w,g]=n.useState({navigated:p,source:d.source}),[v,y]=n.useState(!1);w.navigated!==p&&(g({navigated:p,source:d.source}),w.source===d.source&&!v&&b.explorerNavigationOf(f,p.state)!=="close-folder"&&m(!1));const[L,j]=n.useState(o);L!==o&&(j(o),m(!1));const S=n.useRef(null),D=n.useRef(null),_=n.useRef(null),k=n.useRef(!1),C=n.useId();n.useLayoutEffect(()=>{const T=S.current;T!==null&&(u&&!T.open?(T.showModal(),D.current?.focus()):!u&&T.open&&(T.close(),t.current?.focus()),c(u?_.current:null))},[u,t,c]),n.useLayoutEffect(()=>()=>c(null),[c]);const F=n.useCallback(T=>{T.key!=="Escape"||T.defaultPrevented||(b.consumeKey(T),m(!1))},[]),O=n.useCallback(T=>{k.current=T.target===T.currentTarget},[]),R=n.useCallback(T=>{const I=k.current;k.current=!1,I&&T.target===T.currentTarget&&m(!1)},[]),q=n.useCallback(()=>{m(!1)},[]);return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"aqmx-sheet-bar",inert:r,"data-testid":"markdown-explorer-sheet-bar","data-aqmx-sheet-bar-merged":l?"true":"false",children:a.jsxs("button",{ref:t,type:"button",className:"aqmx-explorer-toggle",title:l?s.showExplorer:void 0,"aria-haspopup":"dialog","aria-expanded":u,"aria-controls":C,"data-testid":"markdown-explorer-sheet-toggle",onClick:()=>m(!0),children:[a.jsx(gt,{"aria-hidden":"true"}),a.jsx("span",{className:l?"aqmx-sr-only":void 0,children:s.showExplorer})]})}),a.jsx("dialog",{ref:S,id:C,className:"aqmx-sheet","aria-label":s.explorerRegion,"data-testid":"markdown-explorer-sheet",onKeyDown:F,onPointerDown:O,onClick:R,onClose:q,children:a.jsxs("div",{className:"aqmx-sheet-panel",children:[a.jsxs("div",{className:"aqmx-explorer-chrome",children:[a.jsx("div",{ref:_,className:"aqmx-sheet-notice-slot"}),a.jsx("button",{ref:D,type:"button",className:"aqmx-explorer-close","aria-label":s.hideExplorer,title:s.hideExplorer,"data-testid":"markdown-explorer-sheet-close",onClick:()=>m(!1),children:a.jsx(Me,{"aria-hidden":"true"})})]}),a.jsx("div",{className:"aqmx-sheet-body",children:a.jsx(qe,{value:u,children:a.jsx(b.SheetAccessFailuresContext,{value:i,children:a.jsx(xt,{value:y,children:e})})})}),a.jsx(b.LiveRegion,{holds:u,deferWhileFullscreenIn:null,testId:"markdown-explorer-sheet-announcer"})]})})]})},bt=n.createContext(null),_e="aqmx-explorer",Et="aqmx-content",Ie='[role="tree"] [role="treeitem"]',Fn=`${Ie}[tabindex="0"]`,qn="[data-directory-tree-tab-stop]",Mn=(e,t)=>{for(const r of e.querySelectorAll(`[data-panel-id="${_e}"] ${Ie}`))if(r.getAttribute(ae)===t)return r;return null},tt=(e,t)=>({inlineSize:e>0?e:null,rootFontPixels:t>0?t:M.ASSUMED_ROOT_FONT_PIXELS}),_n=(e,t)=>{const[r,l]=n.useState(()=>tt(0,0));return n.useLayoutEffect(()=>{const c=e.current,i=t.current;if(c===null||i===null)throw new Error("[markdown-explorer] the split frame is not mounted");const o={frame:c.getBoundingClientRect().width,rem:i.getBoundingClientRect().width},s=()=>{const f=tt(o.frame,o.rem);l(d=>d.inlineSize===f.inlineSize&&d.rootFontPixels===f.rootFontPixels?d:f)};s();const p=new ResizeObserver(f=>{for(const d of f){const[u]=d.borderBoxSize;u!==void 0&&(d.target===c&&(o.frame=u.inlineSize),d.target===i&&(o.rem=u.inlineSize))}s()});return p.observe(c),p.observe(i),()=>p.disconnect()},[e,t]),r},vt=e=>`aqmx-split-handle-${e}`,In=(e,{frameRef:t,sheetToggleRef:r,railToggleRef:l,closeButtonRef:c,handleId:i})=>{const o=n.useRef(!1),s=n.useRef(null),p=n.useRef(!1);n.useLayoutEffect(()=>{const d=t.current;if(d===null)throw new Error("[markdown-explorer] the split frame is not mounted");const u=w=>{const g=w.target instanceof Element?w.target:null;o.current=g!==null&&g.closest(`[data-panel-id="${Et}"]`)===null,!p.current&&(s.current=g?.closest(`${Ie}[${ae}]`)?.getAttribute(ae)??null)},m=w=>{w.relatedTarget instanceof Node&&!d.contains(w.relatedTarget)&&(o.current=!1)};return d.addEventListener("focusin",u),d.addEventListener("focusout",m),()=>{d.removeEventListener("focusin",u),d.removeEventListener("focusout",m)}},[t]);const f=n.useRef(e);n.useLayoutEffect(()=>{const d=f.current;if(d===e)return;f.current=e;const u=t.current;if(u===null||!o.current)return;const m=w=>{const{activeElement:g,body:v}=u.ownerDocument;if(g!==null&&g!==v)return;const y=w.find(L=>L!==null);if(y!=null){p.current=!0;try{y.focus()}finally{p.current=!1}}};if(e==="sheet"){m([r.current]);return}if(e==="rail"){m([l.current]);return}if(d==="rail"){m([c.current]);return}queueMicrotask(()=>{if(f.current!==e||!o.current)return;const w=s.current,g=`[data-panel-id="${_e}"]`;m([w===null?null:Mn(u,w),u.querySelector(`${g} ${Fn}`),u.querySelector(`${g} ${qn}`),u.querySelector(`[data-resize-handle-id="${i}"]`)])})},[e,t,r,l,c,i])},Dn=e=>e==="tree"?"treeExplorerHidden":"multiExplorerHidden",Hn=({view:e,explorer:t,content:r,contentCoversPage:l=!1,sheetDismissals:c=0,onDraggingChange:i})=>{const{viewSettings:o}=b.useExplorer(),s=n.useRef(null),[p,f]=n.useState(null),d=n.useRef(null),u=n.useRef(null),m=n.useRef(null),w=n.useRef(null),{inlineSize:g,rootFontPixels:v}=_n(s,d),y=Dn(e),L=b.useViewSetting(T=>T[y]===!0),j=g!==null&&g<M.explorerSheetBelowPixels(v),S=j?"sheet":L?"rail":"split";In(S,{frameRef:s,sheetToggleRef:u,railToggleRef:m,closeButtonRef:w,handleId:vt(e)});const D=n.useCallback(()=>o.update({[y]:!0}),[o,y]),_=n.useCallback(()=>o.update({[y]:!1}),[o,y]),[k,C]=n.useState(!1),F=n.useMemo(()=>j?{lane:!l,onBar:C}:null,[j,l]),[O]=n.useState(()=>new Map),[R]=n.useState(b.createSheetAccessFailures),q=j&&p!==null?R:null;return a.jsx(at,{value:O,children:a.jsxs("div",{ref:s,className:"aqmx-split-frame","data-aqmx-explorer-mode":S,"data-aqmx-measured":g===null?"false":"true","data-aqmx-content-covers-page":l?"true":"false",children:[a.jsx("span",{ref:d,className:"aqmx-rem-probe","aria-hidden":"true","data-aqmx-rem-probe":""}),j?a.jsx(Pn,{explorer:t,toggleRef:u,covered:l,merged:k,onNoticeSlotChange:f,accessFailures:R,dismissals:c}):null,a.jsxs("div",{className:"aqmx-split-row",children:[S==="rail"?a.jsx(Bn,{toggleRef:m,covered:l,onOpen:_}):null,a.jsx(bt,{value:j?p:null,children:a.jsx(b.AccessFailureRelayContext,{value:q,children:a.jsx(b.SheetBarContext,{value:F,children:a.jsx(Zn,{view:e,mode:S,explorer:t,content:r,contentCoversPage:l,onDraggingChange:i,explorerMinPixels:M.explorerMinPixels(v),closeButtonRef:w,onHide:D})})})})]})]})})},Bn=({toggleRef:e,covered:t,onOpen:r})=>{const{labels:l}=b.useExplorer();return a.jsx("div",{className:"aqmx-split-rail",inert:t,"data-testid":"markdown-explorer-rail",children:a.jsx("button",{ref:e,type:"button",className:"aqmx-explorer-toggle","aria-expanded":!1,"aria-label":l.showExplorer,title:l.showExplorer,"data-testid":"markdown-explorer-rail-toggle",onClick:r,children:a.jsx(gt,{"aria-hidden":"true"})})})},Zn=({view:e,mode:t,explorer:r,content:l,contentCoversPage:c,onDraggingChange:i,explorerMinPixels:o,closeButtonRef:s,onHide:p})=>{const{viewSettings:f,labels:d}=b.useExplorer(),u=n.useMemo(()=>Xe.toPanelGroupLabels(d),[d]),w=b.useViewSetting(R=>e==="tree"?R.treeExplorer:R.multiExplorer)??(e==="tree"?M.EXPLORER_DEFAULT_PERCENT:M.EXPLORER_MULTI_DEFAULT_PERCENT),g=n.useRef(!1),[v,y]=n.useState(!1),L=n.useRef(!1),j=n.useRef(i);n.useLayoutEffect(()=>{j.current=i},[i]);const S=Xe.useSplitPersistence(n.useCallback(R=>{if(R.length!==2)return;const[q=0,T=0]=R,I=q+T;if(I<=0||q<=0)return;const $=Math.min(M.EXPLORER_MAX_PERCENT,q/I*100);f.update(e==="tree"?{treeExplorer:$}:{multiExplorer:$})},[f,e]));n.useEffect(()=>()=>{g.current&&j.current?.(!1)},[]);const _=b.useCoarsePointer()?M.COARSE_TARGET_PIXELS:M.FINE_TARGET_PIXELS,k=t==="split",C=n.useCallback(()=>{L.current=!1,y(!1),p()},[p]),F=n.useCallback((R,q)=>{const[T=0,I=0]=R;R.length===2&&I>0&&(L.current=T<=0,y(L.current)),S.layoutChanged(R,q),L.current&&q.source==="keyboard"&&C()},[S,C]),O=n.useCallback(R=>{g.current=R,i?.(R),S.draggingChanged(R),!R&&L.current&&C()},[i,S,C]);return a.jsxs(Ce.PanelGroup,{id:`aqmx-split-${e}`,direction:"horizontal",onLayout:F,labels:u,className:"aqmx-split","data-aqmx-split":e,children:[k?a.jsxs(Ce.Panel,{id:_e,defaultSize:{value:w,unit:"percentage"},minSize:{value:o,unit:"pixels"},maxSize:{value:M.EXPLORER_MAX_PERCENT,unit:"percentage"},collapsible:{from:"end"},pixelAdjustPriority:1,inert:c,className:"aqmx-split-explorer",children:[a.jsx("div",{className:"aqmx-explorer-chrome",children:a.jsx("button",{ref:s,type:"button",className:"aqmx-explorer-close","aria-label":d.hideExplorer,title:d.hideExplorer,"data-testid":"markdown-explorer-split-close",onClick:C,children:a.jsx(Me,{"aria-hidden":"true"})})}),a.jsx(qe,{value:!v,children:r})]}):null,k?a.jsx(Ce.PanelResizeHandle,{id:vt(e),thickness:_,indicator:{visible:!0,thickness:M.SPLIT_HANDLE_PIXELS.gripThickness,length:M.SPLIT_HANDLE_PIXELS.gripLength,barThickness:M.SPLIT_HANDLE_PIXELS.barThickness,barLength:M.SPLIT_HANDLE_PIXELS.barLength},title:d.resizeExplorer,"aria-label":d.resizeExplorer,onDragging:O,inert:c,className:"aqmx-split-handle"}):null,a.jsx(Ce.Panel,{id:Et,defaultSize:{value:k?100-w:100,unit:"percentage"},contentOverflow:"hidden",className:"aqmx-split-content",...c?{style:{isolation:"auto"}}:{},children:l})]})};exports.EMPTY_SELECTION=ke;exports.ExplorerPane=An;exports.ExplorerSplit=Hn;exports.SheetNoticeSlotContext=bt;
2
+ "use strict";const a=require("react/jsx-runtime"),b=require("./index-D6at9qMs.cjs"),n=require("react"),_=require("./location-DFXJSMit.cjs"),Le=require("react-router"),We=require("./ownUrls-BTPGNhBt.cjs"),rt=require("@aiquants/directory-tree"),nt=require("./tapScrollCircle-ExxyHVWY.cjs"),qt=require("./storage-BpYsprog.cjs"),lt=require("./describeValue-Ccvhbt36.cjs"),ke=require("@aiquants/resize-panels"),Xe=require("./useSplitPersistence-BCitqdAe.cjs");function Mt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const l=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,l.get?l:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const h=Mt(n);function _t({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M19.5 21a3 3 0 0 0 3-3V9a3 3 0 0 0-3-3h-5.379a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H4.5a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3h15ZM9 12.75a.75.75 0 0 0 0 1.5h6a.75.75 0 0 0 0-1.5H9Z",clipRule:"evenodd"}))}const It=h.forwardRef(_t);function Dt({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M19.5 21a3 3 0 0 0 3-3V9a3 3 0 0 0-3-3h-5.379a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H4.5a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3h15Zm-6.75-10.5a.75.75 0 0 0-1.5 0v2.25H9a.75.75 0 0 0 0 1.5h2.25v2.25a.75.75 0 0 0 1.5 0v-2.25H15a.75.75 0 0 0 0-1.5h-2.25V10.5Z",clipRule:"evenodd"}))}const Ht=h.forwardRef(Dt);function Bt({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M16.5 6a3 3 0 0 0-3-3H6a3 3 0 0 0-3 3v7.5a3 3 0 0 0 3 3v-6A4.5 4.5 0 0 1 10.5 6h6Z"}),h.createElement("path",{d:"M18 7.5a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3h-7.5a3 3 0 0 1-3-3v-7.5a3 3 0 0 1 3-3H18Z"}))}const Zt=h.forwardRef(Bt);function $t({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M3 6a3 3 0 0 1 3-3h2.25a3 3 0 0 1 3 3v2.25a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3V6Zm9.75 0a3 3 0 0 1 3-3H18a3 3 0 0 1 3 3v2.25a3 3 0 0 1-3 3h-2.25a3 3 0 0 1-3-3V6ZM3 15.75a3 3 0 0 1 3-3h2.25a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-2.25Zm9.75 0a3 3 0 0 1 3-3H18a3 3 0 0 1 3 3V18a3 3 0 0 1-3 3h-2.25a3 3 0 0 1-3-3v-2.25Z",clipRule:"evenodd"}))}const zt=h.forwardRef($t),Vt="http://path.invalid",Kt=/[\t\n\r]/gu,Ut=(e,t,r,l)=>{const c=e.replace(Kt,"");if(!c.startsWith("/")||c.startsWith("//")||c.includes("\\"))return null;const{pathname:i,search:o,hash:s}=new URL(c,Vt);return!We.isUnder(i,[t])||We.isUnder(i,[r])?null:`${l}${i.slice(t.length)}${o}${s}`},Wt=()=>{const{notices:e,config:t}=b.useExplorer(),r=n.use(e),l=Le.useHref(t.basePath),c=Le.useHref(t.dataPath);return r.length===0?null:a.jsx("div",{className:"aqmx-explorer-notices",children:r.map(i=>{const o=i.action===void 0?null:Ut(i.action.href,l,c,t.basePath);return a.jsxs("div",{className:"aqmx-callout","data-aqmx-tone":i.tone,"data-testid":"markdown-explorer-notice","data-aqmx-notice":i.id,children:[a.jsx("p",{className:"aqmx-callout-title",children:i.title}),i.body===void 0?null:a.jsx("p",{className:"aqmx-callout-body",children:i.body}),i.action===void 0?null:o===null?a.jsx("a",{className:"aqmx-callout-action",href:i.action.href,children:i.action.label}):a.jsx(b.ExplorerLink,{className:"aqmx-callout-action",to:o,navigation:"follow-link",children:i.action.label})]},i.id)})})};function Xt({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M6.912 3a3 3 0 0 0-2.868 2.118l-2.411 7.838a3 3 0 0 0-.133.882V18a3 3 0 0 0 3 3h15a3 3 0 0 0 3-3v-4.162c0-.299-.045-.596-.133-.882l-2.412-7.838A3 3 0 0 0 17.088 3H6.912Zm13.823 9.75-2.213-7.191A1.5 1.5 0 0 0 17.088 4.5H6.912a1.5 1.5 0 0 0-1.434 1.059L3.265 12.75H6.11a3 3 0 0 1 2.684 1.658l.256.513a1.5 1.5 0 0 0 1.342.829h3.218a1.5 1.5 0 0 0 1.342-.83l.256-.512a3 3 0 0 1 2.684-1.658h2.844Z",clipRule:"evenodd"}))}const Gt=h.forwardRef(Xt),qe=n.createContext(!0),at=n.createContext(null),ot="\0loop\0",st="\0",Yt=()=>{const e=new WeakMap,t=new WeakMap,r=new WeakMap,l=o=>{const s=e.get(o);if(s!==void 0)return s;const p=Object.freeze({type:"loop",name:o.name,path:o.path});return e.set(o,p),p},c=(o,s,p)=>{let f=!1;const d=o.map(m=>{const w=i(m,s,p);return w!==m&&(f=!0),w});if(!f)return o;const u=r.get(o);return u!==void 0&&u.length===d.length&&u.every((m,w)=>m===d[w])?u:(r.set(o,d),d)},i=(o,s,p)=>{if(o.type!=="directory")return o;if(p.has(o.path))return l(o);const f=o.lazy===!0?s(o.path):void 0,d=f?.status==="loaded",u=d?f.entries:o.children;if(u===void 0)return o;p.add(o.path);const m=c(u,s,p);if(p.delete(o.path),!d&&m===o.children)return o;const w=t.get(o);if(w!==void 0&&w.state===f&&w.children===m)return w.grafted;const g={...o,children:m,lazy:d?!1:o.lazy};return t.set(o,{state:f,children:m,grafted:g}),g};return(o,s)=>c(o,s,new Set)},Qt=(e,t)=>`${ot}${e}${st}${t}`,me=e=>e.startsWith(ot),Jt=e=>e.slice(e.lastIndexOf(st)+1),ae="data-aqmx-path",er=(e,t,r,l,c)=>{const i={aqmxPath:e.path};return e.modifiedAt!==void 0&&(i.aqmxModifiedAt=e.modifiedAt),r&&(i.aqmxOpen=!0),(l==="loading"||l==="failed")&&(i.aqmxChildren=l),{name:e.name,type:e.type,absolutePath:e.path,relativePath:e.path,mimeType:e.mimeType,children:t,label:c,data:i}},tr=(e,t,r,l)=>{const c=Qt(t,e.path);return{name:r,type:"directory",absolutePath:c,relativePath:c,children:l,data:{aqmxLoop:e.path}}},rr=()=>{const e=new WeakMap,t=new WeakMap,r=new WeakMap,l=[],c=(s,p,f)=>{const d=s.map(m=>m.type==="loop"?i(m,p,f):o(m,p)),u=r.get(s);return u!==void 0&&u.length===d.length&&u.every((m,w)=>m===d[w])?u:(r.set(s,d),d)},i=(s,p,f)=>{const d=t.get(s);if(d!==void 0&&d.parentKey===f&&d.loopFolderName===p.loopFolderName)return d.row;const u=tr(s,f,p.loopFolderName(s.name),l);return t.set(s,{row:u,parentKey:f,loopFolderName:p.loopFolderName}),u},o=(s,p)=>{const f=s.type==="directory"?s.children===void 0?l:c(s.children,p,s.path):void 0,d=p.openPaths.has(s.path),u=s.type==="directory"&&s.lazy===!0?p.childrenOf(s.path)?.status:void 0,m=u==="failed"?p.renderFailedFolder:void 0,w=e.get(s);if(w!==void 0&&w.open===d&&w.childrenStatus===u&&w.children===f&&w.renderFailedFolder===m)return w.row;const g=er(s,f,d,u,m===void 0?void 0:m(s));return e.set(s,{row:g,open:d,childrenStatus:u,children:f,renderFailedFolder:m}),g};return(s,p)=>c(s,p,"")},nr=e=>{if(e===void 0)return;const t=r=>{const l=r.data?.aqmxModifiedAt;return typeof l=="number"?{name:r.name,path:r.absolutePath,type:r.type,modifiedAt:l}:{name:r.name,path:r.absolutePath,type:r.type}};return(r,l)=>e(t(r),t(l))},Fe=(e,t)=>{const r=e.filter(l=>l.type==="directory");return t===void 0?r:r.sort(t)},lr=(e,t)=>{const r=new Map;let l=0;const c=i=>{for(const o of Fe(i,t.compare))if(t.isShownExpanded(o.path)){if(o.lazy!==!0){o.children!==void 0&&c(o.children);continue}r.has(o.path)||(r.set(o.path,t.isDirect(o.path)?"direct":"bulk"),t.childrenOf(o.path)?.status!=="failed"&&(l+=1))}};return c(e),{folders:r,waiting:l}},ar=e=>{const t=new Set,r=l=>{for(const c of l)c.type==="directory"&&(c.lazy===!0&&t.add(c.path),c.children!==void 0&&r(c.children))};return r(e),t},ct=(e,t)=>{for(const r of e){if(r.type!=="directory")continue;if(r.path===t)return r;const l=r.children===void 0?null:ct(r.children,t);if(l!==null)return l}return null},it=(e,t,r)=>{for(const l of e){if(l===t)return{parent:r};const c=l.children===void 0?null:it(l.children,t,l);if(c!==null)return c}return null},or=(e,t,r)=>{const l=it(e,r,null);if(l===null)throw new Error(`[markdown-explorer] the pressed folder's row is not among the tree's rows: ${lt.describeValue(r.absolutePath)}`);if(l.parent!==null)return{kind:"folder",path:l.parent.absolutePath};const c=_.folderReadmeOf(t.filter(i=>i.type!=="loop"));return c===null?{kind:"nothing"}:{kind:"document",path:c}},sr=(e,t,r,l)=>{let c=e;for(const i of t){const o=c.find(s=>s.type==="directory"&&s.path===i);if(o===void 0)return"missing";if(o.lazy===!0)return l.childrenOf(o.path)?.status==="failed"?"failed":"loading";if(!l.isShownExpanded(o.path))return"loading";c=o.children??[]}return c.some(i=>i.type==="file"&&i.path===r)?"ready":"missing"},Ge=new Set,cr=(e,t)=>e.has(t)?e:new Set(e).add(t),ir=(e,t)=>{if(!t.some(l=>e.has(l)))return e;const r=new Set(t);return new Set([...e].filter(l=>!r.has(l)))},ur=(e,t)=>[...e].every(r=>t.has(r))?e:new Set([...e].filter(r=>t.has(r))),dr=()=>{const[e,t]=n.useState(Ge),r=n.useCallback(o=>t(s=>cr(s,o)),[]),l=n.useCallback(o=>t(s=>ir(s,o)),[]),c=n.useCallback(o=>t(s=>ur(s,o)),[]),i=n.useCallback(()=>t(Ge),[]);return n.useMemo(()=>({direct:e,markDirect:r,unmarkDirect:l,pruneDirect:c,clearDirect:i}),[e,r,l,c,i])},fr=e=>({budget:e,handled:new Set,loads:new Set,opened:0,folderLimited:!1,depthLimited:!1,announcedStart:!1,issuedAgainst:null}),pr=(e,t)=>{const r=[];let l=Fe(t.entries,t.compare);for(let c=1;l.length>0;c+=1){const i=[];for(const o of l){const{path:s}=o;if(t.isShownExpanded(s))e.handled.add(s);else{if(e.handled.has(s))continue;if(e.handled.add(s),o.lazy===!0&&t.childrenOf(s)===void 0){if(c>e.budget.maxDepth){e.depthLimited=!0;continue}if(e.loads.size>=e.budget.maxFolders){e.folderLimited=!0;continue}e.loads.add(s)}r.push(s),e.opened+=1}o.lazy!==!0&&o.children!==void 0&&i.push(...Fe(o.children,t.compare))}l=i}return r},ut=(e,t)=>e.every(r=>r.type!=="directory"||t(r.path)&&(r.lazy===!0||r.children===void 0||ut(r.children,t))),mr=(e,t)=>{if(e.folderLimited)return{kind:"folder-limit",opened:e.opened};if(e.depthLimited)return{kind:"depth-limit",opened:e.opened};let r=0;for(const l of e.loads)t.childrenOf(l)?.status==="failed"&&(r+=1);return{kind:"done",opened:e.opened,failed:r,complete:ut(t.entries,t.isShownExpanded)}},Ne=Object.freeze({state:"idle"}),hr=e=>{const t=n.useRef(null),r=n.useRef(e),[l,c]=n.useState(Ne);n.useLayoutEffect(()=>{r.current=e});const i=n.useCallback(()=>{t.current===null&&(t.current=fr(r.current.budget),c({state:"running",opened:0}))},[]),o=n.useCallback(()=>{t.current=null,c(Ne)},[]),s=n.useCallback(p=>{const f=t.current;if(f===null)return;const d=pr(f,p);if(d.length>0&&(f.issuedAgainst=p.expanded,r.current.expandMultiple([...d])),!f.announcedStart&&(f.loads.size>0||p.waiting>0)&&(f.announcedStart=!0,r.current.onStart()),d.length===0&&!p.expansionPending&&p.expanded!==f.issuedAgainst&&p.waiting===0){t.current=null;const m=mr(f,p);c(m.kind==="done"?Ne:{state:"stopped",stop:m.kind,opened:m.opened}),r.current.onFinish(m);return}const{opened:u}=f;c(m=>m.state==="running"&&m.opened===u?m:{state:"running",opened:u})},[]);return n.useMemo(()=>({status:l,start:i,end:o,advance:s}),[l,i,o,s])},Ye=["pointerdown","wheel","touchstart","keydown","focusin"],xr=8,Qe={least:Number.POSITIVE_INFINITY,stalled:0},wr=({tree:e,container:t,path:r,chain:l,rows:c,cancel:i,displayed:o,placement:s})=>{const p=n.useRef(null),f=n.useRef(!0),d=n.useRef(Qe),u=n.useRef(null),m=n.useRef(null),w=n.useRef(l),g=n.useRef(s);n.useLayoutEffect(()=>{w.current=l,g.current=s},[l,s]);const v=n.useCallback(()=>{const k=u.current;k!==null&&(u.current=null,k.phase==="asking"?k.controller.abort():w.current?.open(null))},[]),y=n.useCallback(()=>{p.current=null,v()},[v]),T=n.useCallback(()=>{const k=t.current;p.current===null||m.current!==null||k===null||k.getClientRects().length===0||(m.current=requestAnimationFrame(()=>{m.current=null;const j=p.current;if(j===null)return;const P=g.current(j);if(P===0){f.current=!0,u.current?.phase==="opening"&&v();return}if(e.current?.scrollToPath(j,{align:"nearest"})===!0){u.current?.phase==="opening"&&v();const{least:C,stalled:q}=d.current;d.current=P<C?{least:P,stalled:0}:{least:C,stalled:q+1},d.current.stalled<xr&&T();return}const S=u.current;if(S===null){p.current=null;return}S.phase==="opening"&&w.current?.progress(S.folders,j)!=="loading"&&y()}))},[e,t,v,y]),A=n.useCallback(()=>{f.current=!1,d.current=Qe,T()},[T]);n.useEffect(()=>{const k=t.current;if(k===null)return;const j=typeof ResizeObserver>"u"?null:new ResizeObserver(A);j?.observe(k);for(const P of Ye)k.addEventListener(P,y,{passive:!0});return()=>{j?.disconnect();for(const P of Ye)k.removeEventListener(P,y);m.current!==null&&cancelAnimationFrame(m.current),m.current=null,v()}},[t,A,y,v]);const R=l!==null;n.useEffect(()=>{const k=t.current;if(y(),r===null||k===null||k.contains(k.ownerDocument.activeElement))return;p.current=r;const j=w.current;if(R&&j!==null){const P=new AbortController,S={phase:"asking",controller:P};u.current=S,j.ancestors(r,P.signal).then(C=>{u.current===S&&(C===null?u.current=null:(u.current={phase:"opening",folders:C},w.current?.open(C)),A())})}A()},[r,R,t,y,A]),n.useEffect(()=>{(u.current?.phase==="opening"||p.current!==null&&!f.current)&&A()},[c,A]);const I=n.useRef(i);n.useEffect(()=>{I.current!==i&&(I.current=i,y())},[i,y]);const M=n.useRef(o);n.useEffect(()=>{M.current&&!o&&v(),M.current=o},[o,v])},gr="--aqmx-tree-line",br=Object.freeze(["(forced-colors: active)","(prefers-color-scheme: dark)"]),Er="data-aqmx-tree-probe",vr=Object.freeze({rowHeight:_.CONTROL_BLOCK_PIXELS,lineColor:null}),Rr=(e,t,r)=>{const[l,c]=n.useState(vr);return n.useLayoutEffect(()=>{const i=e.current;if(i===null)return;const o=()=>{const f=Math.round(i.getBoundingClientRect().height),d=getComputedStyle(i),u=d.getPropertyValue(gr).trim()===""?null:d.color;c(m=>{const w=Number.isFinite(f)&&f>0?f:m.rowHeight;return m.rowHeight===w&&m.lineColor===u?m:{rowHeight:w,lineColor:u}})};o();const s=br.map(f=>window.matchMedia(f));for(const f of s)f.addEventListener("change",o);const p=typeof ResizeObserver>"u"?null:new ResizeObserver(o);return p?.observe(i),()=>{for(const f of s)f.removeEventListener("change",o);p?.disconnect()}},[e,t,r]),l},dt="markdown-explorer-tree-scroll",Sr=.5,ft=(e,t)=>[...e.querySelectorAll(`[role="treeitem"][${ae}]`)].find(r=>r.getAttribute(ae)===t),yr=(e,t)=>{const r=ft(e,t),l=r?.closest(`[data-testid="${dt}"]`);if(r===void 0||l===null||l===void 0)return Number.POSITIVE_INFINITY;const c=l.getBoundingClientRect(),i=r.getBoundingClientRect(),o=c.top-i.top,s=i.height>c.height?Math.abs(o):Math.max(0,o)+Math.max(0,i.bottom-c.bottom);return s<=Sr?0:s},Pe=Object.freeze({testId:dt,overscanCount:13,callbackThrottleMs:13,scrollBarOptions:Object.freeze({width:8,...b.SCROLL_BAR_CONTROLS,enableArrowButtons:!0,enableArrowButtonTabStops:!1,enableScrollToTopBottomButtons:!0,tapScrollCircleOptions:nt.TAP_SCROLL_CIRCLE}),behaviorOptions:Object.freeze({enablePointerDrag:!0})}),kr=Object.freeze({...Pe,scrollBarOptions:Object.freeze({...Pe.scrollBarOptions,...b.TOUCH_SCROLL_BAR_CONTROLS,tapScrollCircleOptions:nt.TOUCH_TAP_SCROLL_CIRCLE})}),Cr=e=>e?kr:Pe,Lr={hoverClassName:"",directorySelectedClassName:"",itemSelectedClassName:""},Tr={color:"inherit",fontSize:"inherit"},jr={fontSize:"inherit"},Ar=new Set,Or=new Map,Nr={color:"var(--aqmx-tree-line)"},pt=e=>e instanceof Element?e.closest(`[${ae}]`):null,Fr=e=>{const t=pt(e);return t===null||t.getAttribute("data-entry-type")!=="file"?null:t.getAttribute(ae)},mt=(e,t,r,l)=>r==="folder-limit"?e.expandAllFolderLimit(l,t.maxFolders,e.expandAll):e.expandAllDepthLimit(l,t.maxDepth),Pr=(e,t,r)=>r.kind==="done"?e.expandAllDone(r.opened,r.failed,r.complete):mt(e,t,r.kind,r.opened),ht=()=>{const{labels:e}=b.useExplorer();return a.jsxs("div",{className:"aqmx-explorer-loading","aria-busy":"true","data-testid":"markdown-explorer-tree-loading",children:[a.jsx("p",{className:"aqmx-explorer-loading-text",children:e.treeLoading}),a.jsxs("div",{className:"aqmx-skeleton","aria-hidden":"true",children:[a.jsx("span",{}),a.jsx("span",{}),a.jsx("span",{}),a.jsx("span",{}),a.jsx("span",{})]})]})},qr=()=>{const{labels:e}=b.useExplorer();return a.jsxs("div",{className:"aqmx-empty","data-testid":"markdown-explorer-tree-empty",children:[a.jsx(Gt,{className:"aqmx-explorer-empty-icon","aria-hidden":"true"}),a.jsx("p",{className:"aqmx-empty-title",children:e.treeEmptyTitle}),a.jsx("p",{className:"aqmx-explorer-empty-body",children:e.treeEmptyBody})]})},Mr=({name:e,onRetry:t})=>{const{labels:r}=b.useExplorer(),l=n.useId();return a.jsxs("span",{className:"aqmx-explorer-folder-failed",children:[a.jsx("span",{className:"aqmx-explorer-folder-name",children:e}),a.jsx("span",{id:l,className:"aqmx-explorer-folder-error",children:r.folderLoadFailed}),a.jsxs("button",{type:"button",className:"aqmx-explorer-folder-retry","aria-describedby":l,"data-testid":"markdown-explorer-folder-retry",onClick:c=>{c.stopPropagation();const i=c.currentTarget,o=i.ownerDocument.activeElement===i?i.closest('[role="treeitem"]'):null;o instanceof HTMLElement&&b.focusWithoutScroll(o),t()},onKeyDown:c=>{c.key!=="Escape"&&c.stopPropagation()},children:[a.jsx(b.ForwardRef,{className:"aqmx-explorer-folder-retry-icon","aria-hidden":"true"}),a.jsx("span",{className:"aqmx-explorer-folder-retry-text",children:r.retry})]})]})},_r=({entries:e,version:t,mode:r,sourceId:l,settings:c,reveal:i,openPaths:o,selection:s,onOpenDocument:p,folders:f,onRevealSource:d,expansion:u,onShown:m,marks:w,claimsHeld:g,expandAll:v,revealCancel:y})=>{const{trees:T,documents:A,labels:R,locale:I,theme:M,paletteKey:k,data:j,config:P,sources:S,reveals:C}=b.useExplorer(),q=n.use(qe),L=n.use(at),[D]=n.useState(()=>L?.get(l)),W=Cr(b.useCoarsePointer()),ce=n.useMemo(()=>D===void 0?W:{...W,initialScrollAnchor:D},[W,D]),[ie]=n.useState(rr),V=n.useRef(null),{rowHeight:oe,lineColor:X}=Rr(V,M,k),{isExpanded:Y,toggle:se,expandMultiple:H,collapseMultiple:ue,expanded:K,isPending:N}=u,{alwaysExpanded:Q,sortMode:U,folderPlacement:de,readmePlacement:fe}=c,{direct:ge,markDirect:J,unmarkDirect:te,pruneDirect:be}=w,{running:he,advance:xe}=v,O=n.useRef(null),$=n.useRef(null);n.useLayoutEffect(()=>{if(L===null)return;const x=O;return()=>{const E=x.current===null?null:x.current.getScrollAnchor();E===null?L.delete(l):L.set(l,E)}},[L,l]);const G=n.useMemo(()=>_.createEntryComparator({sortMode:U,folderPlacement:de,readmePlacement:fe}),[U,de,fe]),Rt=n.useMemo(()=>nr(G),[G]),ee=n.useCallback(x=>T.children(l,x),[T,l]),re=n.useMemo(()=>ar(e),[e]),we=n.useCallback(x=>Q&&!re.has(x),[Q,re]),ne=n.useCallback(x=>!me(x)&&(Y(x)||we(x)),[Y,we]),B=n.useRef({shownExpanded:ne,isExpanded:Y,isHeld:we,unloadedFolders:re,entries:e,childrenOf:ee,folderSelection:f,openDocument:p});n.useLayoutEffect(()=>{B.current={shownExpanded:ne,isExpanded:Y,isHeld:we,unloadedFolders:re,entries:e,childrenOf:ee,folderSelection:f,openDocument:p}},[ne,Y,we,re,e,ee,f,p]);const[le]=n.useState(()=>new Map),Te=n.useCallback((x,E)=>{C.settle(E),x.open(E)},[C]),Ee=n.useCallback((x,E)=>{E.kind!=="nothing"&&C.settle(E.path),x.close(E)},[C]),pe=n.useCallback((x,E)=>{for(const F of x){const Z=le.get(F);if(Z===void 0)continue;le.delete(F);const z=B.current.folderSelection;!E&&z!==null&&z.current===F&&Ee(z,Z)}},[le,Ee]),De=n.useCallback(x=>{O.current?.scrollToPath(x,{align:"nearest"}),requestAnimationFrame(()=>{const E=$.current,F=E===null?void 0:ft(E,x);F!==void 0&&b.focusWithoutScroll(F)})},[]),St=n.useCallback(x=>{if(me(x)){De(Jt(x));return}pe([x],!B.current.shownExpanded(x)),B.current.isExpanded(x)?te([x]):B.current.unloadedFolders.has(x)&&J(x),se(x)},[De,pe,J,te,se]),je=n.useCallback(x=>{const E=x.filter(F=>!me(F));E.length!==0&&(pe(E,!1),te(E),ue(E))},[pe,te,ue]),yt=n.useCallback(x=>{const E=x.filter(F=>!me(F));if(E.length!==0){if(E.length<x.length&&E.every(F=>B.current.shownExpanded(F))){je(E);return}pe(E,!0),H(E)}},[pe,H,je]),He=n.useCallback(x=>a.jsx(Mr,{name:x.name,onRetry:()=>{J(x.path),T.retryChildren(l,x.path),B.current.shownExpanded(x.path)||H([x.path])}}),[T,l,J,H]),Be=r==="multi"?o:Ar,{loopFolderName:Ze}=R,ve=n.useMemo(()=>ie(e,{openPaths:Be,childrenOf:ee,renderFailedFolder:He,loopFolderName:Ze}),[ie,e,Be,ee,He,Ze,t]),$e=n.useRef(ve);n.useLayoutEffect(()=>{$e.current=ve},[ve]);const kt=b.useIntentPrefetch(A,Fr),ze=n.useRef([]),Re=n.useCallback(()=>{for(const x of ze.current)B.current.unloadedFolders.has(x)&&J(x)},[J]),{maxDepth:Ae}=P.revealDocument,Ve=n.useRef(d);n.useLayoutEffect(()=>{Ve.current=d},[d]);const Ct=n.useMemo(()=>({ancestors:async(x,E)=>{const F=C.take(l,x);if(F!==null)return F;if(!C.mayMove(x)){const z=await j.ancestors(l,x,E);return z.status!=="ok"||z.ancestors===null||z.ancestors.length>Ae?null:z.ancestors}const Z=await j.reveal(l,x,E);return Z.status!=="ok"||Z.source===null||Z.ancestors.length>Ae?null:Z.source===l?Z.ancestors:(E.aborted||!S.some(z=>z.id===Z.source)||(C.move(Z.source,x,Z.ancestors),Ve.current(Z.source)),null)},open:x=>{ze.current=x??[],x!==null&&(Re(),H([...x]))},progress:(x,E)=>sr(B.current.entries,x,E,{isShownExpanded:B.current.shownExpanded,childrenOf:B.current.childrenOf})}),[j,l,S,C,Ae,Re,H]);n.useEffect(()=>Re(),[Re,re]);const Lt=n.useMemo(()=>[e,t,K],[e,t,K]),Tt=n.useCallback(x=>$.current===null?Number.POSITIVE_INFINITY:yr($.current,x),[]);wr({tree:O,container:$,path:i.path,chain:i.openFolders?Ct:null,rows:Lt,cancel:y,displayed:q,placement:Tt});const Ke=n.useCallback(x=>ge.has(x),[ge]),Se=n.useMemo(()=>lr(e,{isShownExpanded:ne,childrenOf:ee,compare:G,isDirect:Ke}),[e,ne,ee,G,Ke,t]),ye=q&&g;n.useLayoutEffect(()=>{m(e)},[e,m]),n.useLayoutEffect(()=>()=>m(null),[m]),n.useEffect(()=>T.claimChildren(l,ye?Se.folders:Or),[T,l,ye,Se]),n.useEffect(()=>be(re),[be,re]),n.useEffect(()=>{ye&&he&&xe({entries:e,isShownExpanded:ne,childrenOf:ee,compare:G,expanded:K,waiting:Se.waiting,expansionPending:N})},[ye,he,xe,e,ne,ee,G,K,Se,N]);const jt=n.useCallback(x=>{const E=x.entry.absolutePath,{folderSelection:F,openDocument:Z}=B.current;if(x.isDirectory){if(F===null||me(E))return;const z=E===F.current,Ue=or($e.current,B.current.entries,x.entry);if(B.current.isHeld(E)){x.preventDefault(),le.delete(E),z?Ee(F,Ue):Te(F,E);return}le.set(E,Ue),x.isExpanded||z||Te(F,E);return}C.settle(E),Z(E)},[C,le,Ee,Te]),At=n.useCallback(x=>{if(x.key!=="ArrowLeft"&&x.key!=="ArrowRight")return;const E=pt(x.target),F=E===null?null:E.getAttribute(ae);F!==null&&le.delete(F)},[le]),{onChange:Oe}=s,Ot=n.useMemo(()=>Oe===null?void 0:(x,E)=>{me(x.absolutePath)||Oe({path:x.absolutePath,name:x.name,selected:E})},[Oe]),Nt=n.useMemo(()=>new Set(s.items),[s.items]),Ft=n.useMemo(()=>({entryKindDirectory:R.treeEntryKindDirectory,entryKindFile:R.treeEntryKindFile,scrollUp:R.treeScrollUp,scrollDown:R.treeScrollDown,scrollToTop:R.treeScrollToTop,scrollToBottom:R.treeScrollToBottom}),[R]),Pt=X===null?{showTreeLines:!1}:{showTreeLines:c.lines,lineColor:X};return a.jsxs("div",{ref:$,className:"aqmx-explorer-tree","data-testid":"markdown-explorer-tree",onKeyDownCapture:At,...kt,children:[a.jsx("span",{ref:V,className:"aqmx-explorer-tree-probe","aria-hidden":"true",[Er]:""}),a.jsx(rt.DirectoryTree,{ref:O,entries:ve,expansion:{toggle:St,isExpanded:ne,expandMultiple:yt,collapseMultiple:je,isPending:N&&!he,doubleClickAction:c.doubleClickAction},selection:{mode:s.mode,selectedPath:s.shownPath,currentPath:s.shownPath,selectedItems:Nt,onEntryClick:jt,onSelectionChange:Ot},visual:{className:"aqmx-explorer-tree-view",ariaLabel:R.treeRegion,...Pt,showExpandIcons:c.expandIcons,expandIconStyle:Nr,showDirectoryIcons:c.directoryIcons,showFileIcons:c.fileIcons,expandIconSize:c.expandIconSize,itemHeight:oe,removeRootIndent:c.removeRootIndent,highlightStyles:Lr,entryStyle:jr,nameStyle:Tr},virtualScroll:ce,sort:Rt,locale:I,labels:Ft})]})},Ir=({pending:e,status:t})=>{const{labels:r}=b.useExplorer(),l=t.state!=="running",[c,i]=n.useState(0),o=n.useRef(!0);n.useLayoutEffect(()=>{const p=o.current;if(o.current=l,!l||e>0&&!p){i(0);return}if(e>0){i(e);return}if(c===0)return;const f=setTimeout(()=>i(0),0);return()=>clearTimeout(f)},[l,e,c]);const s=l&&e===0?c:e;return s===0&&l?null:a.jsxs("p",{className:"aqmx-explorer-tree-progress","data-testid":"markdown-explorer-tree-progress","data-aqmx-loading":String(s),"data-aqmx-expand-all":t.state,children:[s>0?a.jsx(b.ForwardRef,{className:"aqmx-explorer-tree-progress-icon","aria-hidden":"true"}):null,a.jsx("span",{children:t.state==="running"?r.expandAllProgress(t.opened,s):r.foldersLoading(s)})]})},Dr=({stop:e,opened:t,budget:r})=>{const{labels:l}=b.useExplorer();return a.jsx("p",{className:"aqmx-explorer-expand-all-stop","data-testid":"markdown-explorer-expand-all-stop","data-aqmx-stop":e,children:mt(l,r,e,t)})},Hr=({entries:e,...t})=>{const{trees:r}=b.useExplorer(),l=n.useSyncExternalStore(r.subscribe,r.version,r.version),{sourceId:c}=t,[i]=n.useState(Yt),o=n.useMemo(()=>i(e,s=>r.children(c,s)),[i,e,r,c,l]);return o.length===0?a.jsx(qr,{}):a.jsx(_r,{entries:o,version:l,...t})},Br=({result:e,onRetry:t,...r})=>{const{renderTreeFailure:l}=b.useExplorer(),c=n.use(e);if(c.status==="deferred")return a.jsx(ht,{});if(c.status==="ok")return a.jsx(Hr,{entries:c.entries,...r});const i=l?.(c.failure);return a.jsx("div",{className:"aqmx-explorer-tree-message","data-testid":"markdown-explorer-tree-failure","data-aqmx-failure":c.failure.reason,children:i!==void 0?i:a.jsx(b.FailureView,{failure:c.failure,alert:!0,onRetry:t,testId:null})})},Zr=Object.freeze([]),$r=e=>e!==void 0&&e.status==="failed"&&b.isAccessFailureReason(e.failure.reason),zr=({failure:e,onRetry:t})=>a.jsx(b.AccessFailureNotice,{failure:e,place:"read",deniedSentence:null,retry:t,testId:"markdown-explorer-folder-access-failure"}),Vr=({onControls:e,...t})=>{const{trees:r,storageNamespace:l,labels:c,announcer:i,config:o}=b.useExplorer(),{sourceId:s}=t,p=rt.useDirectoryTreeState({storageKey:qt.storageKeys(l).treeExpansion(s)});n.useSyncExternalStore(r.subscribe,r.version,r.version);const f=r.read(s),d=n.useCallback(()=>r.retry(s),[r,s]);n.useLayoutEffect(()=>r.open(s),[r,s]);const u=dr(),{expanded:m,expandMultiple:w,collapseAll:g}=p,[v,y]=n.useState(null),T=v!==m,A=n.useRef(m);n.useLayoutEffect(()=>{A.current=m},[m]);const R=o.expandAll,I=n.useCallback(()=>i.announce(c.expandAllStarted),[i,c]),M=n.useCallback(N=>i.announce(Pr(c,R,N)),[i,c,R]),k=hr({budget:R,expandMultiple:w,onStart:I,onFinish:M}),{status:j,start:P,end:S,advance:C}=k,q=j.state==="running",L=n.useMemo(()=>({running:q,advance:C}),[q,C]),D=n.useRef(null),[W,ce]=n.useState(!1),ie=n.useCallback(N=>{D.current=N,ce(N!==null)},[]),[V,oe]=n.useState(null);n.useEffect(()=>r.subscribeChildrenFailures(N=>{const Q=N.sourceId===s&&D.current!==null?ct(D.current,N.path):null;if(Q!==null){if(b.isAccessFailureReason(N.failure.reason)){oe(U=>U===null?{failure:N.failure,paths:[N.path]}:U.paths.includes(N.path)?U:{failure:U.failure,paths:[...U.paths,N.path]});return}i.announce({list:c.foldersLoadFailedNamed,item:Q.name})}}),[r,s,i,c]);const X=V===null?Zr:V.paths.filter(N=>$r(r.children(s,N)));V!==null&&X.length===0&&oe(null);const Y=()=>{for(const N of X)r.retryChildren(s,N)},{clearDirect:se}=u,[H,ue]=n.useState(0),K=n.useCallback(()=>{ue(N=>N+1),S(),se(),y(A.current),g()},[S,se,g]);return n.useEffect(()=>{e({collapseAll:K,expandAll:W?P:null,expanding:q})},[e,K,P,W,q]),n.useEffect(()=>()=>e(null),[e]),n.useEffect(()=>{W||S()},[W,S]),a.jsxs(a.Fragment,{children:[V===null||X.length===0?null:a.jsx(zr,{failure:V.failure,onRetry:Y}),j.state==="stopped"?a.jsx(Dr,{stop:j.stop,opened:j.opened,budget:R}):null,a.jsxs("div",{className:"aqmx-explorer-tree-area",children:[a.jsx(n.Suspense,{fallback:a.jsx(ht,{}),children:a.jsx(Br,{result:f,onRetry:d,expansion:p,onShown:ie,marks:u,claimsHeld:T,expandAll:L,revealCancel:H,...t})}),a.jsx(Ir,{pending:r.pendingChildren(s),status:j})]})]})};function Kr({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M5.47 5.47a.75.75 0 0 1 1.06 0L12 10.94l5.47-5.47a.75.75 0 1 1 1.06 1.06L13.06 12l5.47 5.47a.75.75 0 1 1-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 0 1-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const Me=h.forwardRef(Kr),Je="markdown-explorer-selection-remove",Ur=({selection:e,onRemove:t,onClear:r,onOpenSelection:l,onLeave:c})=>{const{labels:i}=b.useExplorer(),o=n.useId(),s=n.useRef(null),p=[...e],f=(u,m)=>{if(m.ownerDocument.activeElement===m){const w=s.current===null?[]:[...s.current.querySelectorAll(`[data-testid="${Je}"]`)],g=w.indexOf(m),v=[w[g+1],w[g-1]].find(y=>y!==void 0);v===void 0?c():v.focus()}t(u)},d=()=>{const u=s.current;u!==null&&u.contains(u.ownerDocument.activeElement)&&c(),r()};return a.jsxs("section",{ref:s,className:"aqmx-explorer-tray","aria-labelledby":o,"data-testid":"markdown-explorer-selection-tray",children:[a.jsxs("div",{className:"aqmx-explorer-tray-header",children:[a.jsx("p",{id:o,className:"aqmx-explorer-tray-title",children:i.selectionTitle(p.length)}),a.jsx("button",{type:"button",className:"aqmx-explorer-tray-button","data-testid":"markdown-explorer-selection-clear",onClick:d,children:i.clearSelection})]}),a.jsx("ul",{className:"aqmx-explorer-tray-list",children:p.map(([u,m])=>a.jsxs("li",{className:"aqmx-explorer-tray-item",children:[a.jsx("span",{className:"aqmx-explorer-tray-name",title:u,children:m}),a.jsx("button",{type:"button",className:"aqmx-icon-button aqmx-explorer-tray-remove","aria-label":i.removeFromSelection(m),title:i.removeFromSelection(m),"data-testid":Je,"data-aqmx-path":u,onClick:w=>f(u,w.currentTarget),children:a.jsx(Me,{"aria-hidden":"true"})})]},u))}),l===void 0?null:a.jsx("button",{type:"button",className:"aqmx-explorer-tray-open","data-testid":"markdown-explorer-selection-open",onClick:()=>l(p.map(([u])=>u)),children:i.openSelectionInMulti(p.length)})]})},Ce=new Map,Wr=(e,t)=>{if(t.selected===e.has(t.path))return e;const r=new Map(e);return t.selected?r.set(t.path,t.name):r.delete(t.path),r},Xr=(e,t)=>{if(!e.has(t))return e;const r=new Map(e);return r.delete(t),r},xt=n.createContext(null),Gr=e=>{const t=n.use(xt);n.useLayoutEffect(()=>{if(t!==null)return t(e),()=>t(!1)},[t,e])};function Yr({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M6.97 2.47a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1-1.06 1.06L8.25 4.81V16.5a.75.75 0 0 1-1.5 0V4.81L3.53 8.03a.75.75 0 0 1-1.06-1.06l4.5-4.5Zm9.53 4.28a.75.75 0 0 1 .75.75v11.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 1 1 1.06-1.06l3.22 3.22V7.5a.75.75 0 0 1 .75-.75Z",clipRule:"evenodd"}))}const Qr=h.forwardRef(Yr);function Jr({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M11.25 4.533A9.707 9.707 0 0 0 6 3a9.735 9.735 0 0 0-3.25.555.75.75 0 0 0-.5.707v14.25a.75.75 0 0 0 1 .707A8.237 8.237 0 0 1 6 18.75c1.995 0 3.823.707 5.25 1.886V4.533ZM12.75 20.636A8.214 8.214 0 0 1 18 18.75c.966 0 1.89.166 2.75.47a.75.75 0 0 0 1-.708V4.262a.75.75 0 0 0-.5-.707A9.735 9.735 0 0 0 18 3a9.707 9.707 0 0 0-5.25 1.533v16.103Z"}))}const en=h.forwardRef(Jr);function tn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12Zm13.36-1.814a.75.75 0 1 0-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 0 0-1.06 1.06l2.25 2.25a.75.75 0 0 0 1.14-.094l3.75-5.25Z",clipRule:"evenodd"}))}const rn=h.forwardRef(tn);function nn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M7.72 12.53a.75.75 0 0 1 0-1.06l7.5-7.5a.75.75 0 1 1 1.06 1.06L9.31 12l6.97 6.97a.75.75 0 1 1-1.06 1.06l-7.5-7.5Z",clipRule:"evenodd"}))}const ln=h.forwardRef(nn);function an({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M11.47 4.72a.75.75 0 0 1 1.06 0l3.75 3.75a.75.75 0 0 1-1.06 1.06L12 6.31 8.78 9.53a.75.75 0 0 1-1.06-1.06l3.75-3.75Zm-3.75 9.75a.75.75 0 0 1 1.06 0L12 17.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-3.75 3.75a.75.75 0 0 1-1.06 0l-3.75-3.75a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const on=h.forwardRef(an);function sn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M11.078 2.25c-.917 0-1.699.663-1.85 1.567L9.05 4.889c-.02.12-.115.26-.297.348a7.493 7.493 0 0 0-.986.57c-.166.115-.334.126-.45.083L6.3 5.508a1.875 1.875 0 0 0-2.282.819l-.922 1.597a1.875 1.875 0 0 0 .432 2.385l.84.692c.095.078.17.229.154.43a7.598 7.598 0 0 0 0 1.139c.015.2-.059.352-.153.43l-.841.692a1.875 1.875 0 0 0-.432 2.385l.922 1.597a1.875 1.875 0 0 0 2.282.818l1.019-.382c.115-.043.283-.031.45.082.312.214.641.405.985.57.182.088.277.228.297.35l.178 1.071c.151.904.933 1.567 1.85 1.567h1.844c.916 0 1.699-.663 1.85-1.567l.178-1.072c.02-.12.114-.26.297-.349.344-.165.673-.356.985-.57.167-.114.335-.125.45-.082l1.02.382a1.875 1.875 0 0 0 2.28-.819l.923-1.597a1.875 1.875 0 0 0-.432-2.385l-.84-.692c-.095-.078-.17-.229-.154-.43a7.614 7.614 0 0 0 0-1.139c-.016-.2.059-.352.153-.43l.84-.692c.708-.582.891-1.59.433-2.385l-.922-1.597a1.875 1.875 0 0 0-2.282-.818l-1.02.382c-.114.043-.282.031-.449-.083a7.49 7.49 0 0 0-.985-.57c-.183-.087-.277-.227-.297-.348l-.179-1.072a1.875 1.875 0 0 0-1.85-1.567h-1.843ZM12 15.75a3.75 3.75 0 1 0 0-7.5 3.75 3.75 0 0 0 0 7.5Z",clipRule:"evenodd"}))}const cn=h.forwardRef(sn);function un({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M12 1.5a.75.75 0 0 1 .75.75V4.5a.75.75 0 0 1-1.5 0V2.25A.75.75 0 0 1 12 1.5ZM5.636 4.136a.75.75 0 0 1 1.06 0l1.592 1.591a.75.75 0 0 1-1.061 1.06l-1.591-1.59a.75.75 0 0 1 0-1.061Zm12.728 0a.75.75 0 0 1 0 1.06l-1.591 1.592a.75.75 0 0 1-1.06-1.061l1.59-1.591a.75.75 0 0 1 1.061 0Zm-6.816 4.496a.75.75 0 0 1 .82.311l5.228 7.917a.75.75 0 0 1-.777 1.148l-2.097-.43 1.045 3.9a.75.75 0 0 1-1.45.388l-1.044-3.899-1.601 1.42a.75.75 0 0 1-1.247-.606l.569-9.47a.75.75 0 0 1 .554-.68ZM3 10.5a.75.75 0 0 1 .75-.75H6a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 10.5Zm14.25 0a.75.75 0 0 1 .75-.75h2.25a.75.75 0 0 1 0 1.5H18a.75.75 0 0 1-.75-.75Zm-8.962 3.712a.75.75 0 0 1 0 1.061l-1.591 1.591a.75.75 0 1 1-1.061-1.06l1.591-1.592a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const dn=h.forwardRef(un);function fn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625ZM7.5 15a.75.75 0 0 1 .75-.75h7.5a.75.75 0 0 1 0 1.5h-7.5A.75.75 0 0 1 7.5 15Zm.75 2.25a.75.75 0 0 0 0 1.5H12a.75.75 0 0 0 0-1.5H8.25Z",clipRule:"evenodd"}),h.createElement("path",{d:"M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"}))}const pn=h.forwardRef(fn);function mn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M19.5 21a3 3 0 0 0 3-3v-4.5a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3V18a3 3 0 0 0 3 3h15ZM1.5 10.146V6a3 3 0 0 1 3-3h5.379a2.25 2.25 0 0 1 1.59.659l2.122 2.121c.14.141.331.22.53.22H19.5a3 3 0 0 1 3 3v1.146A4.483 4.483 0 0 0 19.5 9h-15a4.483 4.483 0 0 0-3 1.146Z"}))}const hn=h.forwardRef(mn);function xn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M19.906 9c.382 0 .749.057 1.094.162V9a3 3 0 0 0-3-3h-3.879a.75.75 0 0 1-.53-.22L11.47 3.66A2.25 2.25 0 0 0 9.879 3H6a3 3 0 0 0-3 3v3.162A3.756 3.756 0 0 1 4.094 9h15.812ZM4.094 10.5a2.25 2.25 0 0 0-2.227 2.568l.857 6A2.25 2.25 0 0 0 4.951 21H19.05a2.25 2.25 0 0 0 2.227-1.932l.857-6a2.25 2.25 0 0 0-2.227-2.568H4.094Z"}))}const wn=h.forwardRef(xn);function gn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M10.5 3.75a6.75 6.75 0 1 0 0 13.5 6.75 6.75 0 0 0 0-13.5ZM2.25 10.5a8.25 8.25 0 1 1 14.59 5.28l4.69 4.69a.75.75 0 1 1-1.06 1.06l-4.69-4.69A8.25 8.25 0 0 1 2.25 10.5Zm8.25-3.75a.75.75 0 0 1 .75.75v2.25h2.25a.75.75 0 0 1 0 1.5h-2.25v2.25a.75.75 0 0 1-1.5 0v-2.25H7.5a.75.75 0 0 1 0-1.5h2.25V7.5a.75.75 0 0 1 .75-.75Z",clipRule:"evenodd"}))}const bn=h.forwardRef(gn);function En({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M4.125 3C3.089 3 2.25 3.84 2.25 4.875V18a3 3 0 0 0 3 3h15a3 3 0 0 1-3-3V4.875C17.25 3.839 16.41 3 15.375 3H4.125ZM12 9.75a.75.75 0 0 0 0 1.5h1.5a.75.75 0 0 0 0-1.5H12Zm-.75-2.25a.75.75 0 0 1 .75-.75h1.5a.75.75 0 0 1 0 1.5H12a.75.75 0 0 1-.75-.75ZM6 12.75a.75.75 0 0 0 0 1.5h7.5a.75.75 0 0 0 0-1.5H6Zm-.75 3.75a.75.75 0 0 1 .75-.75h7.5a.75.75 0 0 1 0 1.5H6a.75.75 0 0 1-.75-.75ZM6 6.75a.75.75 0 0 0-.75.75v3c0 .414.336.75.75.75h3a.75.75 0 0 0 .75-.75v-3A.75.75 0 0 0 9 6.75H6Z",clipRule:"evenodd"}),h.createElement("path",{d:"M18.75 6.75h1.875c.621 0 1.125.504 1.125 1.125V18a1.5 1.5 0 0 1-3 0V6.75Z"}))}const vn=h.forwardRef(En);function Rn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{d:"M5.625 3.75a2.625 2.625 0 1 0 0 5.25h12.75a2.625 2.625 0 0 0 0-5.25H5.625ZM3.75 11.25a.75.75 0 0 0 0 1.5h16.5a.75.75 0 0 0 0-1.5H3.75ZM3 15.75a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75a.75.75 0 0 1-.75-.75ZM3.75 18.75a.75.75 0 0 0 0 1.5h16.5a.75.75 0 0 0 0-1.5H3.75Z"}))}const Sn=h.forwardRef(Rn),yn=Object.freeze({sortMode:Qr,folderPlacement:hn,readmePlacement:en,selectionMode:rn,doubleClickAction:dn,expandIconSize:bn,alwaysExpanded:b.ForwardRef$2,revealDocument:b.ForwardRef$1,showFolderReadme:vn,removeRootIndent:ln,lines:Sn,expandIcons:on,directoryIcons:wn,fileIcons:pn}),wt=(e,t)=>{const r=e[t.labelKey];if(typeof r!="string")throw new TypeError(`[markdown-explorer] the tree setting ${t.key} must name a string label; labels.${t.labelKey} is ${lt.describeValue(r)}`);return r},kn=({id:e,settings:t,descriptors:r,onAdvance:l,onClose:c,ref:i})=>{const{labels:o}=b.useExplorer(),s=n.useRef([]);n.useEffect(()=>{s.current[0]?.focus()},[]);const p=n.useCallback(d=>{const u=r.length;s.current[(d%u+u)%u]?.focus()},[r.length]),f=n.useCallback((d,u)=>{switch(d.key){case"ArrowDown":d.preventDefault(),p(u+1);break;case"ArrowUp":d.preventDefault(),p(u-1);break;case"Home":d.preventDefault(),p(0);break;case"End":d.preventDefault(),p(r.length-1);break;case"Escape":b.consumeKey(d),c();break;case"Tab":c();break}},[r.length,p,c]);return a.jsx("div",{ref:i,id:e,role:"menu","aria-label":o.treeSettings,className:"aqmx-explorer-menu","data-testid":"markdown-explorer-tree-settings-menu",children:r.map((d,u)=>{const m=yn[d.key],w=wt(o,d),g=_.formatTreeSettingValue(o,t,d.key),v=t[d.key],y=typeof v=="boolean"?{role:"menuitemcheckbox","aria-checked":v,"aria-label":w}:{role:"menuitem","aria-label":`${w}: ${g}`};return a.jsxs("button",{ref:T=>{s.current[u]=T},type:"button",tabIndex:-1,...y,title:`${w}: ${g}`,className:"aqmx-explorer-menu-item","data-testid":"markdown-explorer-tree-settings-item","data-aqmx-setting":d.key,onClick:()=>l(d),onKeyDown:T=>f(T,u),children:[a.jsx(m,{className:"aqmx-explorer-menu-icon","aria-hidden":"true"}),a.jsx("span",{className:"aqmx-explorer-menu-name",children:w}),a.jsx("span",{className:"aqmx-explorer-menu-value",children:g})]},d.key)})})},Cn=({settings:e,descriptors:t,onAdvance:r})=>{const{labels:l,announcer:c}=b.useExplorer(),[i,o]=n.useState(!1),s=n.useRef(null),p=n.useRef(null),f=n.useRef(null),d=n.useId(),u=n.useCallback(()=>{s.current?.focus(),o(!1)},[]);n.useEffect(()=>{if(!i)return;const g=v=>{v.target instanceof Node&&(s.current?.contains(v.target)===!0||p.current?.contains(v.target)===!0)||(o(!1),f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{f.current=null,(document.activeElement===null||document.activeElement===document.body)&&s.current?.focus()},0))};return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[i]),n.useEffect(()=>()=>{f.current!==null&&window.clearTimeout(f.current)},[]);const m=n.useCallback(g=>{g.key!=="Escape"||!i||(b.consumeKey(g),u())},[i,u]),w=n.useCallback(g=>{const v=r(g.key);c.announce(l.settingAnnouncement(wt(l,g),_.formatTreeSettingValue(l,v,g.key)))},[c,l,r]);return{trigger:a.jsx("button",{ref:s,type:"button",className:"aqmx-icon-button","aria-haspopup":"menu","aria-expanded":i,"aria-controls":i?d:void 0,"aria-label":l.treeSettings,title:l.treeSettings,"data-testid":"markdown-explorer-tree-settings",onClick:()=>o(g=>!g),onKeyDown:m,children:a.jsx(cn,{"aria-hidden":"true"})}),menu:i?a.jsx(kn,{ref:p,id:d,settings:e,descriptors:t,onAdvance:w,onClose:u}):null}},Ln=()=>{const{treeSettings:e}=b.useExplorer();return{settings:n.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getServerSnapshot),advance:e.advance}},et=new Set,Tn='[role="tree"] [role="treeitem"][tabindex="0"]',jn="[data-directory-tree-tab-stop]",An=e=>{const{mode:t,sourceId:r,currentPath:l,openPaths:c,onOpenDocument:i,onSourceChange:o,onRevealSource:s,viewSwitch:p}=e,{labels:f,sources:d,trees:u,documents:m,announcer:w,reveals:g}=b.useExplorer(),{settings:v,advance:y}=Ln(),T=n.useMemo(()=>_.visibleTreeSettingDescriptors(t),[t]),A=t==="tree"&&v.selectionMode==="multiple";Gr(A);const R=e.mode==="tree"?e.tray.onGatheredChange:null,I=e.mode==="tree"?e.onOpenSelection:void 0,M=e.mode==="tree"?e.onOpenFolder:null,k=e.mode==="tree"?e.onCloseFolder:null,j=e.mode==="tree"&&e.currentFolder,P=n.useMemo(()=>M===null||k===null||!v.showFolderReadme?null:{current:l,open:M,close:k},[M,k,l,v.showFolderReadme]),S=e.mode==="tree"&&A?e.tray.gathered:Ce,C=n.useCallback(O=>{const $=y(O);return $.selectionMode!=="multiple"&&R?.(Ce),$},[y,R]),q=Cn({settings:v,descriptors:T,onAdvance:C}),L=n.useCallback(O=>R?.($=>Wr($,O)),[R]),D=n.useCallback(O=>R?.($=>Xr($,O)),[R]),W=n.useCallback(()=>R?.(Ce),[R]),ce=n.useRef(null),ie=n.useCallback(()=>{const O=ce.current;if(O===null)return;[Tn,jn,'[data-testid="markdown-explorer-tree-settings"]'].map(G=>O.querySelector(G)).find(G=>G!==null)?.focus()},[]),V=n.useMemo(()=>new Set(S.keys()),[S]),oe=n.useMemo(()=>l===null?et:new Set([l]),[l]),X=n.useMemo(()=>{if(t==="multi")return{mode:"multiple",items:c,shownPath:null,onChange:null};switch(v.selectionMode){case"single":return{mode:"single",items:oe,shownPath:l,onChange:null};case"multiple":return{mode:"multiple",items:V,shownPath:l,onChange:L};case"none":return{mode:"none",items:et,shownPath:null,onChange:null}}},[t,c,v.selectionMode,oe,l,V,L]),Y=n.useMemo(()=>v.revealDocument?{path:l,openFolders:!j}:{path:X.shownPath,openFolders:!1},[v.revealDocument,l,j,X.shownPath]),se=n.useCallback(O=>{l!==null&&g.settle(l),o(O)},[l,g,o]),[H,ue]=n.useState(null),[K,N]=n.useState(!1),[Q,U]=n.useState(null),de=n.useRef(!1),fe=n.useCallback(async()=>{if(!de.current){de.current=!0,N(!0),U(null);try{const O=await u.refresh(r);if(O.status==="superseded")return;m.invalidate(),O.status==="failed"?U({sourceId:r,failure:O.failure}):w.announce(f.treeRefreshed)}finally{de.current=!1,N(!1)}}},[u,m,r,w,f]),ge=n.useCallback(()=>{fe()},[fe]),J=H===null?null:H.expandAll,te=H?.expanding===!0,be=d.find(O=>O.id===r),he=p.target==="multi"?zt:Zt,xe=p.target==="multi"?f.switchToMulti:f.switchToTree;return a.jsxs("nav",{ref:ce,"aria-label":f.explorerRegion,className:"aqmx-explorer","data-testid":"markdown-explorer-explorer","data-aqmx-mode":t,children:[a.jsxs("div",{className:"aqmx-explorer-header",children:[d.length>1?a.jsx("select",{className:"aqmx-explorer-source","aria-label":f.sourceLabel,title:be?.label,value:r,onChange:O=>se(O.currentTarget.value),"data-testid":"markdown-explorer-source-select",children:d.map(O=>a.jsx("option",{value:O.id,children:O.label},O.id))}):null,a.jsxs("div",{className:"aqmx-explorer-actions",children:[a.jsx(b.ExplorerLink,{to:p.href,navigation:"switch-view",className:"aqmx-icon-button","aria-label":xe,title:xe,"data-testid":"markdown-explorer-view-switch","data-aqmx-target":p.target,children:a.jsx(he,{"aria-hidden":"true"})}),a.jsxs("button",{type:"button",className:"aqmx-icon-button aqmx-labelled-button",title:f.refreshTree,"aria-disabled":K,"aria-busy":K,"data-aqmx-busy":K?"true":void 0,"data-testid":"markdown-explorer-refresh",onClick:()=>{fe()},children:[a.jsx(b.ForwardRef,{"aria-hidden":"true"}),a.jsx("span",{children:f.refreshTreeLabel})]}),a.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.expandAll,title:f.expandAll,"aria-disabled":J===null||te,"aria-busy":te,"data-aqmx-busy":te?"true":void 0,"data-testid":"markdown-explorer-expand-all",onClick:()=>J?.(),children:a.jsx(Ht,{"aria-hidden":"true"})}),a.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.collapseAll,title:f.collapseAll,"aria-disabled":H===null,"data-testid":"markdown-explorer-collapse-all",onClick:()=>H?.collapseAll(),children:a.jsx(It,{"aria-hidden":"true"})}),q.trigger]})]}),a.jsxs("div",{className:"aqmx-explorer-body","data-aqmx-explorer-body":"",children:[a.jsx(b.SheetAccessFailureList,{}),Q!==null&&Q.sourceId===r?a.jsx(On,{failure:Q.failure,onRetry:ge}):null,a.jsx(n.Suspense,{fallback:null,children:a.jsx(Wt,{})}),a.jsx(Vr,{mode:t,sourceId:r,settings:v,reveal:Y,openPaths:c,selection:X,onOpenDocument:i,folders:P,onRevealSource:s,onControls:ue},r),A&&S.size>0?a.jsx(Ur,{selection:S,onRemove:D,onClear:W,onOpenSelection:I,onLeave:ie}):null,q.menu]})]})},On=({failure:e,onRetry:t})=>{const{labels:r}=b.useExplorer(),{reason:l}=e;return b.isAccessFailureReason(l)?a.jsx(b.AccessFailureNotice,{failure:e,place:"read",deniedSentence:null,retry:t,testId:"markdown-explorer-refresh-failure"}):a.jsx("p",{role:"alert",className:"aqmx-explorer-refresh-failure","data-testid":"markdown-explorer-refresh-failure","data-aqmx-failure":l,children:r.treeRefreshFailed(b.failureTitleOf(r,l))})};function Nn({title:e,titleId:t,...r},l){return h.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:l,"aria-labelledby":t},r),e?h.createElement("title",{id:t},e):null,h.createElement("path",{fillRule:"evenodd",d:"M3 6.75A.75.75 0 0 1 3.75 6h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 6.75ZM3 12a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 12Zm0 5.25a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75a.75.75 0 0 1-.75-.75Z",clipRule:"evenodd"}))}const gt=h.forwardRef(Nn),Fn=({explorer:e,toggleRef:t,covered:r,merged:l,onNoticeSlotChange:c,accessFailures:i,dismissals:o})=>{const{labels:s}=b.useExplorer(),p=Le.useLocation(),f=Le.useNavigationType(),{location:d}=b.useExplorerLocation(),[u,m]=n.useState(!1),[w,g]=n.useState({navigated:p,source:d.source}),[v,y]=n.useState(!1);w.navigated!==p&&(g({navigated:p,source:d.source}),w.source===d.source&&!v&&b.explorerNavigationOf(f,p.state)!=="close-folder"&&m(!1));const[T,A]=n.useState(o);T!==o&&(A(o),m(!1));const R=n.useRef(null),I=n.useRef(null),M=n.useRef(null),k=n.useRef(!1),j=n.useId();n.useLayoutEffect(()=>{const L=R.current;L!==null&&(u&&!L.open?(L.showModal(),I.current?.focus()):!u&&L.open&&(L.close(),t.current?.focus()),c(u?M.current:null))},[u,t,c]),n.useLayoutEffect(()=>()=>c(null),[c]);const P=n.useCallback(L=>{L.key!=="Escape"||L.defaultPrevented||(b.consumeKey(L),m(!1))},[]),S=n.useCallback(L=>{k.current=L.target===L.currentTarget},[]),C=n.useCallback(L=>{const D=k.current;k.current=!1,D&&L.target===L.currentTarget&&m(!1)},[]),q=n.useCallback(()=>{m(!1)},[]);return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"aqmx-sheet-bar",inert:r,"data-testid":"markdown-explorer-sheet-bar","data-aqmx-sheet-bar-merged":l?"true":"false",children:a.jsxs("button",{ref:t,type:"button",className:"aqmx-explorer-toggle",title:l?s.showExplorer:void 0,"aria-haspopup":"dialog","aria-expanded":u,"aria-controls":j,"data-testid":"markdown-explorer-sheet-toggle",onClick:()=>m(!0),children:[a.jsx(gt,{"aria-hidden":"true"}),a.jsx("span",{className:l?"aqmx-sr-only":void 0,children:s.showExplorer})]})}),a.jsx("dialog",{ref:R,id:j,className:"aqmx-sheet","aria-label":s.explorerRegion,"data-testid":"markdown-explorer-sheet",onKeyDown:P,onPointerDown:S,onClick:C,onClose:q,children:a.jsxs("div",{className:"aqmx-sheet-panel",children:[a.jsxs("div",{className:"aqmx-explorer-chrome",children:[a.jsx("div",{ref:M,className:"aqmx-sheet-notice-slot"}),a.jsx("button",{ref:I,type:"button",className:"aqmx-explorer-close","aria-label":s.hideExplorer,title:s.hideExplorer,"data-testid":"markdown-explorer-sheet-close",onClick:()=>m(!1),children:a.jsx(Me,{"aria-hidden":"true"})})]}),a.jsx("div",{className:"aqmx-sheet-body",children:a.jsx(qe,{value:u,children:a.jsx(b.SheetAccessFailuresContext,{value:i,children:a.jsx(xt,{value:y,children:e})})})}),a.jsx(b.LiveRegion,{holds:u,deferWhileFullscreenIn:null,testId:"markdown-explorer-sheet-announcer"})]})})]})},bt=n.createContext(null),_e="aqmx-explorer",Et="aqmx-content",Ie='[role="tree"] [role="treeitem"]',Pn=`${Ie}[tabindex="0"]`,qn="[data-directory-tree-tab-stop]",Mn=(e,t)=>{for(const r of e.querySelectorAll(`[data-panel-id="${_e}"] ${Ie}`))if(r.getAttribute(ae)===t)return r;return null},tt=(e,t)=>({inlineSize:e>0?e:null,rootFontPixels:t>0?t:_.ASSUMED_ROOT_FONT_PIXELS}),_n=(e,t)=>{const[r,l]=n.useState(()=>tt(0,0));return n.useLayoutEffect(()=>{const c=e.current,i=t.current;if(c===null||i===null)throw new Error("[markdown-explorer] the split frame is not mounted");const o={frame:c.getBoundingClientRect().width,rem:i.getBoundingClientRect().width},s=()=>{const f=tt(o.frame,o.rem);l(d=>d.inlineSize===f.inlineSize&&d.rootFontPixels===f.rootFontPixels?d:f)};s();const p=new ResizeObserver(f=>{for(const d of f){const[u]=d.borderBoxSize;u!==void 0&&(d.target===c&&(o.frame=u.inlineSize),d.target===i&&(o.rem=u.inlineSize))}s()});return p.observe(c),p.observe(i),()=>p.disconnect()},[e,t]),r},vt=e=>`aqmx-split-handle-${e}`,In=(e,{frameRef:t,sheetToggleRef:r,railToggleRef:l,closeButtonRef:c,handleId:i})=>{const o=n.useRef(!1),s=n.useRef(null),p=n.useRef(!1);n.useLayoutEffect(()=>{const d=t.current;if(d===null)throw new Error("[markdown-explorer] the split frame is not mounted");const u=w=>{const g=w.target instanceof Element?w.target:null;o.current=g!==null&&g.closest(`[data-panel-id="${Et}"]`)===null,!p.current&&(s.current=g?.closest(`${Ie}[${ae}]`)?.getAttribute(ae)??null)},m=w=>{w.relatedTarget instanceof Node&&!d.contains(w.relatedTarget)&&(o.current=!1)};return d.addEventListener("focusin",u),d.addEventListener("focusout",m),()=>{d.removeEventListener("focusin",u),d.removeEventListener("focusout",m)}},[t]);const f=n.useRef(e);n.useLayoutEffect(()=>{const d=f.current;if(d===e)return;f.current=e;const u=t.current;if(u===null||!o.current)return;const m=w=>{const{activeElement:g,body:v}=u.ownerDocument;if(g!==null&&g!==v)return;const y=w.find(T=>T!==null);if(y!=null){p.current=!0;try{y.focus()}finally{p.current=!1}}};if(e==="sheet"){m([r.current]);return}if(e==="rail"){m([l.current]);return}if(d==="rail"){m([c.current]);return}queueMicrotask(()=>{if(f.current!==e||!o.current)return;const w=s.current,g=`[data-panel-id="${_e}"]`;m([w===null?null:Mn(u,w),u.querySelector(`${g} ${Pn}`),u.querySelector(`${g} ${qn}`),u.querySelector(`[data-resize-handle-id="${i}"]`)])})},[e,t,r,l,c,i])},Dn=e=>e==="tree"?"treeExplorerHidden":"multiExplorerHidden",Hn=({view:e,explorer:t,content:r,contentCoversPage:l=!1,sheetDismissals:c=0,onDraggingChange:i})=>{const{viewSettings:o}=b.useExplorer(),s=n.useRef(null),[p,f]=n.useState(null),d=n.useRef(null),u=n.useRef(null),m=n.useRef(null),w=n.useRef(null),{inlineSize:g,rootFontPixels:v}=_n(s,d),y=Dn(e),T=b.useViewSetting(L=>L[y]===!0),A=g!==null&&g<_.explorerSheetBelowPixels(v),R=A?"sheet":T?"rail":"split";In(R,{frameRef:s,sheetToggleRef:u,railToggleRef:m,closeButtonRef:w,handleId:vt(e)});const I=n.useCallback(()=>o.update({[y]:!0}),[o,y]),M=n.useCallback(()=>o.update({[y]:!1}),[o,y]),[k,j]=n.useState(!1),P=n.useMemo(()=>A?{lane:!l,onBar:j}:null,[A,l]),[S]=n.useState(()=>new Map),[C]=n.useState(b.createSheetAccessFailures),q=A&&p!==null?C:null;return a.jsx(at,{value:S,children:a.jsxs("div",{ref:s,className:"aqmx-split-frame","data-aqmx-explorer-mode":R,"data-aqmx-measured":g===null?"false":"true","data-aqmx-content-covers-page":l?"true":"false",children:[a.jsx("span",{ref:d,className:"aqmx-rem-probe","aria-hidden":"true","data-aqmx-rem-probe":""}),A?a.jsx(Fn,{explorer:t,toggleRef:u,covered:l,merged:k,onNoticeSlotChange:f,accessFailures:C,dismissals:c}):null,a.jsxs("div",{className:"aqmx-split-row",children:[R==="rail"?a.jsx(Bn,{toggleRef:m,covered:l,onOpen:M}):null,a.jsx(bt,{value:A?p:null,children:a.jsx(b.AccessFailureRelayContext,{value:q,children:a.jsx(b.SheetBarContext,{value:P,children:a.jsx(Zn,{view:e,mode:R,explorer:t,content:r,contentCoversPage:l,onDraggingChange:i,explorerMinPixels:_.explorerMinPixels(v),closeButtonRef:w,onHide:I})})})})]})]})})},Bn=({toggleRef:e,covered:t,onOpen:r})=>{const{labels:l}=b.useExplorer();return a.jsx("div",{className:"aqmx-split-rail",inert:t,"data-testid":"markdown-explorer-rail",children:a.jsx("button",{ref:e,type:"button",className:"aqmx-explorer-toggle","aria-expanded":!1,"aria-label":l.showExplorer,title:l.showExplorer,"data-testid":"markdown-explorer-rail-toggle",onClick:r,children:a.jsx(gt,{"aria-hidden":"true"})})})},Zn=({view:e,mode:t,explorer:r,content:l,contentCoversPage:c,onDraggingChange:i,explorerMinPixels:o,closeButtonRef:s,onHide:p})=>{const{viewSettings:f,labels:d}=b.useExplorer(),u=n.useMemo(()=>Xe.toPanelGroupLabels(d),[d]),w=b.useViewSetting(S=>e==="tree"?S.treeExplorer:S.multiExplorer)??(e==="tree"?_.EXPLORER_DEFAULT_PERCENT:_.EXPLORER_MULTI_DEFAULT_PERCENT),g=n.useRef(!1),[v,y]=n.useState(!1),T=n.useRef(!1),A=n.useRef(i);n.useLayoutEffect(()=>{A.current=i},[i]);const R=Xe.useSplitPersistence(n.useCallback(S=>{if(S.length!==2)return;const[C=0,q=0]=S,L=C+q;if(L<=0||C<=0)return;const D=Math.min(_.EXPLORER_MAX_PERCENT,C/L*100);f.update(e==="tree"?{treeExplorer:D}:{multiExplorer:D})},[f,e]));n.useEffect(()=>()=>{g.current&&A.current?.(!1)},[]);const I=_.COARSE_TARGET_PIXELS,M=t==="split",k=n.useCallback(()=>{T.current=!1,y(!1),p()},[p]),j=n.useCallback((S,C)=>{const[q=0,L=0]=S;S.length===2&&L>0&&(T.current=q<=0,y(T.current)),R.layoutChanged(S,C),T.current&&C.source==="keyboard"&&k()},[R,k]),P=n.useCallback(S=>{g.current=S,i?.(S),R.draggingChanged(S),!S&&T.current&&k()},[i,R,k]);return a.jsxs(ke.PanelGroup,{id:`aqmx-split-${e}`,direction:"horizontal",onLayout:j,labels:u,className:"aqmx-split","data-aqmx-split":e,children:[M?a.jsxs(ke.Panel,{id:_e,defaultSize:{value:w,unit:"percentage"},minSize:{value:o,unit:"pixels"},maxSize:{value:_.EXPLORER_MAX_PERCENT,unit:"percentage"},collapsible:{from:"end"},pixelAdjustPriority:1,inert:c,className:"aqmx-split-explorer",children:[a.jsx("div",{className:"aqmx-explorer-chrome",children:a.jsx("button",{ref:s,type:"button",className:"aqmx-explorer-close","aria-label":d.hideExplorer,title:d.hideExplorer,"data-testid":"markdown-explorer-split-close",onClick:k,children:a.jsx(Me,{"aria-hidden":"true"})})}),a.jsx(qe,{value:!v,children:r})]}):null,M?a.jsx(ke.PanelResizeHandle,{id:vt(e),thickness:I,indicator:{visible:!0,thickness:_.SPLIT_HANDLE_PIXELS.gripThickness,length:_.SPLIT_HANDLE_PIXELS.gripLength,barThickness:_.SPLIT_HANDLE_PIXELS.barThickness,barLength:_.SPLIT_HANDLE_PIXELS.barLength},title:d.resizeExplorer,"aria-label":d.resizeExplorer,onDragging:P,inert:c,className:"aqmx-split-handle"}):null,a.jsx(ke.Panel,{id:Et,defaultSize:{value:M?100-w:100,unit:"percentage"},contentOverflow:"hidden",className:"aqmx-split-content",...c?{style:{isolation:"auto"}}:{},children:l})]})};exports.EMPTY_SELECTION=Ce;exports.ExplorerPane=An;exports.ExplorerSplit=Hn;exports.SheetNoticeSlotContext=bt;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("react/jsx-runtime"),c=require("react"),Y=require("./describeValue-Ccvhbt36.cjs"),j=require("./location-DOIG84V9.cjs"),P=require("./index-_XNluAcx.cjs"),re=require("./ExplorerSplit-13nPIuf0.cjs"),D=require("@aiquants/drag-drop-panels"),fe=require("react-router"),ne=require("./storage-BpYsprog.cjs"),Ce=require("./ownUrls-BTPGNhBt.cjs"),qe=require("react-dom"),Be=require("@aiquants/markdown"),je=()=>{const e=new Map;return{hold:(n,t)=>{e.set(n,t),queueMicrotask(()=>{e.get(n)===t&&e.delete(n)})},take:n=>{const t=e.get(n);return e.delete(n),t===void 0?null:t}}},Oe=c.createContext(null),ie=()=>{const e=c.use(Oe);if(e===null)throw new Error("[markdown-explorer] multi-view panels must be rendered inside the multi-view stage");return e},Fe=(e,n)=>{const t=e.pendingHashes.get(n);return t===void 0?null:t},Ve=0xcbf29ce484222325n,Ue=0x100000001b3n,$e=(1n<<64n)-1n,Ge=(1n<<53n)-1n,Ye=new TextEncoder,We=e=>{let n=Ve;for(const t of Ye.encode(e))n=(n^BigInt(t))*Ue&$e;return Number(n&Ge)},Q=256,Ke=e=>`aqmx-p-${We(e).toString(36)}`,be=(e,n)=>{const t=Ke(e);let o=t;for(let r=2;n.has(o);r+=1)o=`${t}-${String(r)}`;return o},Je=new Map,Xe=(e,n=Je)=>{const t=new Set(e.flatMap(r=>n.get(r)??[])),o=new Map;for(const r of e){const s=n.get(r)??be(r,t);t.add(s),o.set(r,s)}return o},Pe=(e,n,t)=>{const o=e.columnOf.get(n);return o===void 0?void 0:Math.min(t-1,Math.max(0,o))},Te=(e,n)=>{const[t,...o]=j.columnGroups(n.logical,n.visible);if(t===void 0)throw new RangeError("[markdown-explorer] there must be at least one visible column");const r=([m,g])=>e.slice(m,g).reduce((i,v)=>i+v.length,0);let s=t;for(const m of o)r(m)<r(s)&&(s=m);let a=s[0];for(let m=s[0];m<s[1];m+=1)(e[m]?.length??0)<(e[a]?.length??0)&&(a=m);return a},ee=(e,n)=>{const t=Array.from({length:n.logical},()=>[]),o=[];for(const r of e.docs){const s=Pe(e,r,n.logical);s===void 0?o.push(r):t[s]?.push(r)}for(const r of o)t[Te(t,n)]?.push(r);return t},Ze=(e,n)=>j.columnGroups(e.length,n).map(([t,o])=>e.slice(t,o).flat()),Qe=(e,n,t)=>{const[o,r]=n,s=r-o,a=e.length,m=Array.from({length:s},(y,d)=>{const x=[0];for(const h of e)x.push((x.at(-1)??0)+(t(h)===o+d?1:0));return x}),g=(y,d,x)=>(m[y]?.[x]??0)-(m[y]?.[d]??0),i=Array.from({length:s+1},()=>Array.from({length:a+1},()=>Number.NEGATIVE_INFINITY)),v=Array.from({length:s+1},()=>Array.from({length:a+1},()=>0)),C=i[0];C&&(C[0]=0);for(let y=0;y<s;y+=1)for(let d=0;d<=a;d+=1)for(let x=0;x<=d;x+=1){const h=(i[y]?.[x]??Number.NEGATIVE_INFINITY)+g(y,x,d),O=i[y+1],L=v[y+1];O&&L&&h>(O[d]??Number.NEGATIVE_INFINITY)&&(O[d]=h,L[d]=x)}const T=Array.from({length:s},()=>[]);let A=a;for(let y=s;y>0;y-=1){const d=v[y]?.[A]??0;T[y-1]=e.slice(d,A),A=d}return T},Le=(e,n)=>{const t=n.flat(),o=new Map(e.columnOf);for(const[r,s]of n.entries())for(const a of s)o.delete(a),o.set(a,r);for(const r of o.keys()){if(o.size<=Q)break;o.delete(r)}return{docs:t,columnOf:o}},en=(e,n,t,o)=>{if(e.docs.includes(n))return{state:e,outcome:"existing"};if(e.docs.length>=o)return{state:e,outcome:"rejected"};const r=ee(e,t),s=Pe(e,n,t.logical)??Te(r,t);r[s]?.push(n);const a=new Map(e.panelIds);return a.set(n,be(n,new Set(a.values()))),{state:{...e,...Le(e,r),panelIds:a},outcome:"opened"}},Me=(e,n)=>{if(!e.docs.includes(n))return e;const t=new Set(e.hidden);t.delete(n);const o=new Set(e.markup);o.delete(n);const r=new Map(e.panelIds);return r.delete(n),{...e,docs:e.docs.filter(s=>s!==n),hidden:t,markup:o,panelIds:r,maximized:e.maximized===n?null:e.maximized}},nn=(e,n,t,o)=>{if(e.hidden.has(n))return{state:ke(e,n,!1),outcome:"shown"};if(e.docs.includes(n))return{state:Me(e,n),outcome:"closed"};const r=en(e,n,t,o);return{state:r.state,outcome:r.outcome==="rejected"?"rejected":"opened"}},tn=(e,n,t)=>{if(n===t||!e.docs.includes(n))return{state:e,outcome:"ignored"};if(e.docs.includes(t))return{state:e,outcome:"existing"};const o=new Map(e.columnOf),r=o.get(n);r!==void 0&&(o.delete(t),o.set(t,r));const s=new Set(e.hidden);s.delete(n);const a=new Map(e.panelIds),m=a.get(n);if(m===void 0)throw new Error(`[markdown-explorer] the open document ${Y.describeValue(n)} has no panel id`);a.delete(n),a.set(t,m);const g=new Set(e.markup);return g.delete(n),{state:{docs:e.docs.map(i=>i===n?t:i),maximized:e.maximized===n?t:e.maximized,columnOf:o,hidden:s,markup:g,panelIds:a},outcome:"navigated"}},ke=(e,n,t)=>{if(!e.docs.includes(n)||e.hidden.has(n)===t)return e;const o=new Set(e.hidden);return t?o.add(n):o.delete(n),{...e,hidden:o,maximized:t&&e.maximized===n?null:e.maximized}},on=(e,n,t)=>{if(!e.docs.includes(n)||e.markup.has(n)===t)return e;const o=new Set(e.markup);return t?o.add(n):o.delete(n),{...e,markup:o}},rn=(e,n)=>{if(e.maximized===n||n!==null&&!e.docs.includes(n))return e;if(n===null||!e.hidden.has(n))return{...e,maximized:n};const t=new Set(e.hidden);return t.delete(n),{...e,maximized:n,hidden:t}},sn=(e,n,t)=>{const o=ee(e,t),r=new Map;for(const[i,v]of o.entries())for(const C of v)r.set(C,i);const s=new Set(e.docs),a=new Set,m=j.columnGroups(t.logical,t.visible),g=Array.from({length:t.logical},()=>[]);for(const[i,v]of m.entries()){const C=(n[i]??[]).filter(T=>s.has(T)&&!a.has(T));for(const T of C)a.add(T);for(const[T,A]of Qe(C,v,y=>r.get(y)).entries())g[v[0]+T]?.push(...A)}for(const i of e.docs)a.has(i)||g[r.get(i)??0]?.push(i);return g.every((i,v)=>i.length===o[v]?.length&&i.every((C,T)=>o[v]?.[T]===C))?e:{...e,...Le(e,g)}},te=(e,n)=>{const t=[...new Set(e.docs)].slice(0,n),o=new Set(t),r=e.maximized!==null&&o.has(e.maximized)?e.maximized:null;return{docs:t,maximized:r,columnOf:e.stored.columnOf,hidden:new Set([...e.stored.hidden].filter(s=>o.has(s)&&s!==r)),markup:new Set(e.markup.filter(s=>o.has(s))),panelIds:Xe(t,e.panelIds)}},pe=(e,n)=>{if(e.docs.every(o=>e.columnOf.has(o)))return e;const t=new Map(e.columnOf);for(const[o,r]of ee(e,n).entries())for(const s of r)t.delete(s),t.set(s,o);for(const o of t.keys()){if(t.size<=Q)break;t.delete(o)}return{...e,columnOf:t}},Re=1,U=Object.freeze({columnOf:new Map,hidden:new Set}),ln=(e,n)=>{if(e===null||e==="")return U;let t;try{t=JSON.parse(e)}catch{return U}if(t===null||typeof t!="object"||Array.isArray(t))return U;const o=t;if(o.v!==Re)return U;const r=new Map;if(Array.isArray(o.columnOf))for(const a of o.columnOf.slice(-Q))Array.isArray(a)&&a.length===2&&typeof a[0]=="string"&&a[0]!==""&&Number.isInteger(a[1])&&a[1]>=0&&a[1]<n&&(r.delete(a[0]),r.set(a[0],a[1]));const s=new Set(Array.isArray(o.hidden)?o.hidden.filter(a=>typeof a=="string"&&a!==""):[]);return{columnOf:r,hidden:s}},an=e=>JSON.stringify({v:Re,columnOf:[...e.columnOf.entries()].slice(-Q),hidden:e.docs.filter(n=>e.hidden.has(n))}),ae=(e,n)=>{const t=e.get(n);return t===void 0?Ce.lastPathSegment(n):t},W=e=>{const n=new Map;for(const[t,o]of e.panelIds)n.set(o,t);return n},ge=e=>{if(!Ce.isAcceptableDocumentPath(e))throw new RangeError(`[markdown-explorer] not an acceptable document path: ${Y.describeValue(e)}`)},cn=({config:e,location:n,writeUrl:t,persist:o})=>{const{maxPanels:r,columns:s}=e.multiView,a=P.createEmitter(),m=new Map,g=new Map;let i={layout:te({docs:n.docs,maximized:n.maximized,markup:n.markup,stored:U},r),source:n.source,visibleColumns:s,ready:!1,splitDragging:!1,titles:new Map,pendingHashes:new Map},v=!1;const C=l=>v?pe(l,{logical:s,visible:i.visibleColumns}):l,T=(l,S)=>j.explorerHref(e,{view:"multi",source:l,docs:S.docs,maximized:S.maximized,markup:S.markup}),A=l=>({docs:l.docs,maximized:l.maximized,markup:[...l.markup]});let y=T(n.source,n),d=n.source,x=y;const h=[],O=[];let L=null;const N=()=>{if(!(h.length>0))for(const l of O.splice(0))l()},R=l=>{i={...i,...l},a.emit()},u=()=>{if(!i.ready)return;const l=an(i.layout);l!==L&&(L=l,o(l))},p=(l,S,b)=>{const I=T(l,A(S));I!==y&&(y=I,d=l,h.push(I),t(I,b))},f=l=>{const S=new Set(l.panelIds.values());for(const E of[...m.keys()])S.has(E)||m.delete(E);for(const E of[...g.keys()])S.has(E)||g.delete(E);const b=new Set(l.docs),I=[...i.titles.keys()].every(E=>b.has(E))?i.titles:new Map([...i.titles].filter(([E])=>b.has(E))),w=[...i.pendingHashes.keys()].every(E=>S.has(E))?i.pendingHashes:new Map([...i.pendingHashes].filter(([E])=>S.has(E)));return{titles:I,pendingHashes:w}},M=l=>l===i.layout?!1:(R({layout:l,...f(l)}),p(d,l,"replace"),u(),!0),_=()=>({logical:s,visible:i.visibleColumns});return{getSnapshot:()=>i,subscribe:a.subscribe,toggle:l=>{ge(l);const{state:S,outcome:b}=nn(i.layout,l,_(),r);return M(S),b},close:l=>M(Me(i.layout,l)),navigate:(l,S)=>{ge(S);const{state:b,outcome:I}=tn(i.layout,l,S);if(I!=="navigated")return I;const w=b.panelIds.get(S);return w!==void 0&&(m.delete(w),g.delete(w)),M(b),I},setHidden:(l,S)=>M(ke(i.layout,l,S)),maximize:l=>M(rn(i.layout,l)),setMarkup:(l,S)=>M(on(i.layout,l,S)),arrange:l=>M(sn(i.layout,l,{logical:s,visible:l.length})),changeSource:l=>{p(l,i.layout,"push")},revealSource:l=>{p(l,i.layout,"replace")},observeLocation:l=>{const S=T(l.source,l);if(S===y)return h.length=0,x=S,l.source!==i.source&&R({source:l.source}),N(),!1;if(S===x)return!1;x=S;const b=h.indexOf(S);if(b>=0)return h.splice(0,b+1),l.source!==i.source&&R({source:l.source}),N(),!1;h.length=0,y=S,d=l.source;const I=C(te({docs:l.docs,maximized:l.maximized,markup:l.markup,stored:{columnOf:i.layout.columnOf,hidden:i.layout.hidden},panelIds:i.layout.panelIds},r));return R({layout:I,source:l.source,...f(I)}),u(),N(),!0},whenUrlRendered:l=>{O.push(l),N()},loadStored:l=>{R({layout:C(te({docs:i.layout.docs,maximized:i.layout.maximized,markup:[...i.layout.markup],stored:l,panelIds:i.layout.panelIds},r)),ready:!0}),u()},setVisibleColumns:l=>{if(!Number.isInteger(l)||l<1||l>s)throw new RangeError(`[markdown-explorer] visible columns must be an integer in 1..${String(s)}; got ${Y.describeValue(l)}`);v=!0;const S=pe(i.layout,{logical:s,visible:l});l===i.visibleColumns&&S===i.layout||(R({visibleColumns:l,layout:S}),S!==i.layout&&u())},setSplitDragging:l=>{l!==i.splitDragging&&R({splitDragging:l})},setTitle:(l,S)=>{!i.layout.docs.includes(l)||i.titles.get(l)===S||R({titles:new Map(i.titles).set(l,S)})},titleOf:l=>ae(i.titles,l),setPendingHash:(l,S)=>{const b=i.pendingHashes.get(l);if(S===null||S===""){if(b===void 0)return;const I=new Map(i.pendingHashes);I.delete(l),R({pendingHashes:I});return}b!==S&&R({pendingHashes:new Map(i.pendingHashes).set(l,S)})},saveReadingPosition:(l,S,b)=>{i.layout.panelIds.get(S)===l&&m.set(l,{doc:S,position:b})},readingPositionOf:(l,S)=>{const b=m.get(l);return b===void 0||b.doc!==S?null:b.position},saveImageView:(l,S,b)=>{g.set(l,{url:S,state:b})},imageViewOf:(l,S)=>{const b=g.get(l);return b===void 0||b.url!==S?null:b.state}}},z=(e,n)=>{const t=()=>n(e.getSnapshot());return c.useSyncExternalStore(e.subscribe,t,t)},un=e=>{const{config:n,storageNamespace:t}=P.useExplorer(),o=fe.useNavigate(),r=c.useRef(o),s=ne.storageKeys(t).multiLayout,[a]=c.useState(()=>cn({config:n,location:e,writeUrl:(i,v)=>{r.current(i,P.explorerNavigationOptions(v==="replace"?"browse":"switch-source"))},persist:i=>ne.writeStorage(s,i)}));c.useLayoutEffect(()=>{r.current=o},[o]);const m=fe.useLocation(),g=c.useMemo(()=>({location:e,navigated:m}),[e,m]);return c.useLayoutEffect(()=>{a.observeLocation(g.location)},[a,g]),c.useLayoutEffect(()=>{a.loadStored(ln(ne.readStorage(s),n.multiView.columns))},[a,s,n]),a},dn=e=>{const n=e.closest(D.SCROLL_AREA_SELECTOR);if(n===null)throw new Error("[markdown-explorer] a panel's document region is not inside the panel's scroll area");return n},mn=({docPath:e,panelId:n,maximized:t,title:o,onContentShown:r})=>{const{store:s,followLink:a,revealInPanel:m,keepAtStartInPanel:g}=ie(),{announcer:i}=P.useExplorer(),v=z(s,u=>Fe(u,n)),C=z(s,u=>u.layout.markup.has(e)),T=c.useCallback((u,p)=>a(n,e,u,p),[a,n,e]),A=c.useCallback(()=>s.setPendingHash(n,null),[s,n]),y=c.useMemo(()=>({read:u=>s.imageViewOf(n,u),save:(u,p)=>s.saveImageView(n,u,p)}),[s,n]),d=c.useCallback((u,p)=>{p.kind!=="failure"&&s.setTitle(u,p.name),r(u)},[s,r]),x=c.useCallback(u=>{s.whenUrlRendered(()=>i.announce(u))},[s,i]),h=c.useMemo(()=>({scrollerOf:dn,reveal:u=>m(n,u),keepAtStart:(u,p)=>g(n,u,p)}),[m,g,n]),O=c.useMemo(()=>({kind:"panel",maximized:t,onDocumentLink:T,pendingHash:v,onHashConsumed:A,announceFailure:x,paneScroll:h}),[t,T,v,A,x,h]),L=c.useMemo(()=>({kind:"panel",documentName:o,maximized:t}),[o,t]),N=c.useCallback(()=>s.setMarkup(e,!s.getSnapshot().layout.markup.has(e)),[s,e]),R=c.useMemo(()=>({shown:C,toggle:N}),[C,N]);return k.jsxs(P.ImageViewMemoryContext,{value:y,children:[k.jsx(P.DocumentRefreshBar,{path:e,placement:L,markup:R,maximize:null}),k.jsx(P.DocumentPane,{path:e,absence:P.NO_DOCUMENT,markup:C,variant:O,onDocumentShown:d})]})},he=()=>typeof HTMLElement<"u"&&typeof HTMLElement.prototype.showPopover=="function"&&typeof HTMLElement.prototype.hidePopover=="function",ce="data-aqmx-column-probe",J="data-panel-id",se="--aqmx-multi-panel-chrome",fn=e=>e==="normal"?0:P.cssPixels(e),pn=(e,n)=>{const t=e.querySelector(D.SCROLL_ROOT_SELECTOR)?.firstElementChild,o=e.querySelector(`[${ce}]`),r=o instanceof HTMLElement?o.getBoundingClientRect().width:Number.NaN;if(!(t instanceof HTMLElement))return{plan:{trackInlineSize:Number.NaN,gap:Number.NaN,minColumnInlineSize:r,logicalColumns:n},stageBlockSize:Number.NaN};const s=getComputedStyle(t),a=t.clientWidth-P.cssPixels(s.paddingLeft)-P.cssPixels(s.paddingRight),m=t.clientHeight-P.cssPixels(s.paddingTop)-P.cssPixels(s.paddingBottom);return{plan:{trackInlineSize:a,gap:fn(s.columnGap),minColumnInlineSize:r,logicalColumns:n},stageBlockSize:m}},gn=(e,n)=>{if(e.getClientRects().length===0)return Number.NaN;const t=getComputedStyle(e);return n.getBoundingClientRect().top-e.getBoundingClientRect().top+P.cssPixels(t.paddingBottom)+P.cssPixels(t.borderBottomWidth)},X="data-aqmx-panel-frame",Se="--aqmx-multi-panel-pinned-block-size",hn=e=>{const{docPath:n,panelId:t}=e;if(typeof n!="string"||typeof t!="string")throw new TypeError("[markdown-explorer] a multi-view panel needs string docPath and panelId props");return{docPath:n,panelId:t}},Sn=e=>{const n=getComputedStyle(e),t=Number.parseFloat(n.lineHeight);return Number.isFinite(t)?t:Number.parseFloat(n.fontSize)},xn=(e,n,t)=>e.deltaMode===WheelEvent.DOM_DELTA_PAGE?e.deltaY*n.clientHeight:e.deltaMode!==WheelEvent.DOM_DELTA_LINE?e.deltaY:e.deltaY*t(n),$=e=>{const n=e.closest(D.SCROLL_AREA_SELECTOR);return n instanceof HTMLElement?n:null},Ne=e=>{const n=e.firstElementChild;return n instanceof HTMLElement&&getComputedStyle(n).position==="sticky"?n:null},Ae=(e,n)=>{const t=n.getBoundingClientRect().top,o=Ne(e);return o===null?t:Math.max(t,o.getBoundingClientRect().bottom)},xe=(e,n)=>{let t=0,o=e.length;for(;t<o;){const r=t+o>>>1;(e[r]?.getBoundingClientRect().bottom??Number.NEGATIVE_INFINITY)>n?o=r:t=r+1}return t<e.length?t:-1},yn=(e,n)=>{const t=Ae(e,n),o=[];let r=e;for(let a=xe([...r.children],t);a>=0;a=xe([...r.children],t)){const m=r.children[a];if(m===void 0)break;o.push(a),r=m}const s=r.getBoundingClientRect();return{scrollTop:n.scrollTop,anchor:o.length===0?null:{path:o,offset:s.top-t,height:s.height}}},ye=(e,n,t)=>{if(n.scrollTop=t.scrollTop,t.anchor===null)return;let o=e;for(const g of t.anchor.path)o=o?.children[g];if(o===void 0)return;const r=o.getBoundingClientRect(),{offset:s,height:a}=t.anchor,m=s<0&&a>0?s/a*r.height:s;n.scrollTop+=r.top-Ae(e,n)-m},vn=Object.freeze(["data-testid","aria-label","title","href","id","name"]),Ie=e=>{const n=e.getAttribute(D.PANEL_ACTION_ATTRIBUTE);return JSON.stringify(n===null?[e.tagName,...vn.map(t=>e.getAttribute(t))]:[e.tagName,D.PANEL_ACTION_ATTRIBUTE,n])},wn=(e,n)=>{if(n===null||!e.contains(n))return null;const t=[];for(let o=n;o!==e;){const r=o.parentElement;if(r===null)return null;t.unshift([...r.children].indexOf(o)),o=r}return{path:t,signature:Ie(n)}},En=(e,n,t)=>{let o=e;for(const r of t.path)o=o?.children[r];o instanceof HTMLElement&&Ie(o)===t.signature&&P.focusWithoutScroll(o)||n.focus({preventScroll:!0})},Cn=(e,n,t)=>{if(e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY))return;const o=e.ctrlKey||e.metaKey,r=o?$(n):n.closest(D.SCROLL_ROOT_SELECTOR);if(!(r instanceof HTMLElement))return;const s=xn(e,r,t);(o||On(r,s))&&(e.preventDefault(),r.scrollTop+=s)},On=(e,n)=>n<0?e.scrollTop>0:n>0?Math.ceil(e.scrollTop+e.clientHeight)<e.scrollHeight:!1,bn=e=>e.scrollHeight>e.clientHeight,Pn=(e,n,t)=>{let o=Number.NaN,r=Number.NaN;const s=Ne(t),a=()=>{const i=gn(e,n);if(!Number.isFinite(i))return;const v=s===null?0:s.getBoundingClientRect().height;v!==r&&(r=v,t.style.setProperty(Se,`${String(v)}px`));const C=i+v;C!==o&&(o=C,e.style.setProperty(se,`${String(C)}px`))};a();let m=null;const g=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>{m===null&&(m=requestAnimationFrame(()=>{m=null,a()}))});return g?.observe(e),g?.observe(n),s!==null&&g?.observe(s),()=>{g?.disconnect(),m!==null&&cancelAnimationFrame(m),e.style.removeProperty(se),t.style.removeProperty(Se)}},Tn=e=>{const{docPath:n,panelId:t}=hn(e),{store:o,Body:r,maximize:s,focusCarry:a}=ie(),m=z(o,d=>d.layout.maximized===n),g=z(o,d=>ae(d.titles,n)),i=c.useRef(null),v=c.useRef(null),C=c.useRef(null),T=c.useRef(null);c.useEffect(()=>{const d=i.current,x=d===null?null:$(d);if(d===null||x===null||m)return;const h=new Map,O=p=>{const f=h.get(p);if(f!==void 0)return f;const M=Sn(p);return h.set(p,M),M},L=p=>Cn(p,d,O);let N=!1;const R=()=>{const p=bn(x);p!==N&&(N=p,p?d.addEventListener("wheel",L,{capture:!0,passive:!1}):d.removeEventListener("wheel",L,{capture:!0}))};R();const u=typeof ResizeObserver>"u"?null:new ResizeObserver(R);return u?.observe(x),u?.observe(d),()=>{u?.disconnect(),d.removeEventListener("wheel",L,{capture:!0})}},[m]),c.useLayoutEffect(()=>{const d=i.current,x=d===null?null:$(d),h=d===null?null:d.closest(`[${J}]`);if(!(d===null||x===null||!(h instanceof HTMLElement)))return Pn(h,x,d)},[]),c.useLayoutEffect(()=>{const d=i.current,x=d===null?null:$(d);if(d===null||x===null)return;const h=p=>{ye(d,x,p),T.current=x.scrollTop},O=o.readingPositionOf(t,n);v.current=O===null?null:{doc:n,position:O},O!==null&&h(O);let L=null,N=d.getBoundingClientRect().width;const R=()=>{L===null&&(L=requestAnimationFrame(()=>{L=null;const p=T.current;if(T.current=null,p!==null&&x.scrollTop===p||d.getBoundingClientRect().width!==N)return;const f=C.current;f!==null&&o.saveReadingPosition(t,f,yn(d,x))}))};x.addEventListener("scroll",R,{passive:!0});const u=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>{const p=d.getBoundingClientRect().width;if(p===N)return;N=p;const f=o.readingPositionOf(t,n);f!==null&&h(f)});return u?.observe(d),()=>{x.removeEventListener("scroll",R),u?.disconnect(),L!==null&&cancelAnimationFrame(L)}},[o,t,n]),c.useLayoutEffect(()=>{const d=i.current,x=d===null?null:d.closest(`[${J}]`);if(d===null||x===null)return;const h=a.take(t);return h!==null&&En(x,d,h),()=>{const O=wn(x,x.ownerDocument.activeElement);O!==null&&a.hold(t,O)}},[a,t]);const A=c.useCallback(d=>{const x=i.current,h=x===null?null:$(x);if(x===null||h===null)return;const O=C.current;C.current=d;const L=v.current;v.current=null,L!==null&&L.doc===d?(ye(x,h,L.position),T.current=h.scrollTop):O!==null&&O!==d&&(h.scrollTop=0)},[]),y=c.useCallback(d=>{P.isInFullscreenBlock(d.target)||s(n)},[s,n]);return k.jsx("div",{ref:i,role:"group","aria-label":g,className:"aqmx-multi-panel-frame",tabIndex:-1,"data-aqmx-panel-frame":t,"data-aqmx-maximized":m?"true":"false","data-testid":"markdown-explorer-panel-frame",...m?P.CONTENT_PANE:{},onDoubleClick:m?void 0:y,children:k.jsx(r,{docPath:n,panelId:t,maximized:m,title:g,onContentShown:A})})},Ln=c.memo(Tn),K=(e,n)=>{const t=e.panelIds.get(n);if(t===void 0)throw new Error(`[markdown-explorer] the open document ${Y.describeValue(n)} has no panel id`);return t},ve=e=>Object.fromEntries(D.generateColumnIds(e).map(n=>[n,[]])),Mn=(e,n)=>{const t=Ze(ee(e,n),n.visible);return Object.fromEntries(t.map((o,r)=>[D.generateColumnId(r),o.map(s=>K(e,s))]))},kn=(e,n)=>{const t=W(e);return D.sortColumnIds(Object.keys(n)).map(o=>(n[o]??[]).flatMap(r=>{const s=t.get(r);return s===void 0?[]:[s]}))},Rn=e=>({switchToCustomDragMode:e.panelSwitchToCustomDrag,switchToNormalDragMode:e.panelSwitchToNormalDrag,hidePanel:e.panelHide,maximizePanel:e.panelMaximize,restorePanel:e.panelRestore,closePanel:e.panelClose,movePanel:e.panelMove,movePanelToPreviousColumn:e.panelMovePreviousColumn,movePanelToNextColumn:e.panelMoveNextColumn,movePanelUp:e.panelMoveUp,movePanelDown:e.panelMoveDown,morePanelActions:e.panelMoreActions,customDragModeBadge:e.panelCustomDragBadge,panelMoved:e.panelMoved,panelMoveUnavailable:e.panelMoveUnavailable,panelDragStarted:e.panelDragStarted,panelDragCancelled:e.panelDragCancelled,hiddenPanels:e.hiddenPanelsTitle,hiddenPanelBadge:e.hiddenPanelBadge,hiddenPanelNotice:e.hiddenPanelNotice,emptyColumn:e.multiColumnEmpty,dropZone:e.multiColumnRegion,dropHere:e.panelDropHere}),Nn="--aqmx-multi-stage-bar-gutter",An=Object.freeze({[Nn]:`${String(P.NATIVE_SCROLL_BAR_WIDTH)}px`}),In=Object.freeze({blockSize:"100%",paddingInlineEnd:P.TAP_SCROLL_CIRCLE_GUTTER_LENGTH}),_n=Object.freeze({[D.NO_PANEL_DRAG_ATTRIBUTE]:"",style:Object.freeze({display:"flex"})}),Dn=e=>k.jsx("div",{..._n,children:k.jsx(P.LazyNativeScrollBar,{scroller:e,kind:"content"})}),zn=({props:e,children:n})=>k.jsx(Be.HostedScrollArea,{scrollerProps:{...e,style:In},renderScrollBar:Dn,barInlineSize:P.NATIVE_SCROLL_BAR_SLOT_LENGTH,children:n}),Hn=e=>k.jsx(P.LazyNativeScrollBar,{scroller:e,kind:"stage"}),ue="--aqmx-stage-block",qn="--aqmx-multi-panel-body-floor",Bn=`calc(var(${ue}) * ${String(j.PANEL_MIN_BLOCK_RATIO)})`,jn=`max(calc(var(${ue}) * ${String(j.PANEL_MAX_BLOCK_RATIO)}), calc(var(${se}) + var(${qn})))`,Fn=(e,n)=>{const t=Object.entries(e);return t.length!==Object.keys(n).length?!1:t.every(([o,r])=>{const s=n[o];return s!==void 0&&s.length===r.length&&s.every((a,m)=>r[m]===a)})},G=(e,n,t,o)=>{P.stopKeepingInView(e);const r=e.querySelector(`[${J}="${n}"]`);if(!(r instanceof HTMLElement))return;const s=t!==null&&r.contains(t)?t:null,a=[{element:r,boundary:r.closest(D.SCROLL_ROOT_SELECTOR)}];s!==null&&a.push({element:s,boundary:r}),P.keepInView(e,()=>r.isConnected?(r.scrollIntoView(P.NEAREST),s?.isConnected!==!0?r:(o(s),s)):null,a)},Z=e=>{e.scrollIntoView(P.NEAREST)},_e=(e,n)=>{const t=e.querySelector(`[${X}="${n}"]`);return t instanceof HTMLElement?(G(e,n,null,Z),t.focus({preventScroll:!0}),!0):!1},de=(e,n)=>{const t=e.querySelector(`[${J}="${n}"]`);return t instanceof HTMLElement&&t.contains(e.ownerDocument.activeElement)},we=(e,n)=>{if(!de(e,n))return null;const t=[...e.querySelectorAll(`[${X}]`)].map(a=>a.getAttribute(X)),o=t.indexOf(n),r=t[o+1];if(o>=0&&typeof r=="string")return{kind:"panel",panelId:r};const s=t[o-1];return o>0&&typeof s=="string"?{kind:"panel",panelId:s}:{kind:"stage"}},Ee=(e,n)=>{requestAnimationFrame(()=>{const t=e.current;t!==null&&(n.kind==="panel"&&_e(t,n.panelId)||t.focus({preventScroll:!0}))})},De=(e,n)=>{requestAnimationFrame(()=>{const t=e.current;t!==null&&_e(t,n)})},Vn=(e,n,t)=>{requestAnimationFrame(()=>{const o=e.current;if(o===null)return;const{activeElement:r,body:s}=o.ownerDocument;if(G(o,n,t&&de(o,n)?r:null,Z),!t||r!==null&&r!==s&&r.isConnected)return;const a=o.querySelector(`[${X}="${n}"]`);a instanceof HTMLElement&&a.focus({preventScroll:!0})})},Un=({store:e,stageRef:n})=>{const{config:t,labels:o,announcer:r,edits:s}=P.useExplorer(),{maximize:a}=ie(),m=t.multiView.columns,g=z(e,w=>w.layout),i=z(e,w=>w.visibleColumns),v=z(e,w=>w.titles),C=z(e,w=>w.layout.maximized!==null||w.splitDragging),[T,A]=c.useState(!1),[y]=c.useState(()=>ve(i)),d=c.useMemo(()=>Rn(o),[o]),x=c.useCallback(w=>{e.arrange(kn(e.getSnapshot().layout,w))},[e]),h=D.useDragDropColumns({initialColumnPanels:y,initialPanelVisibility:{},debugConfig:D.DEFAULT_DEBUG_CONFIG,onColumnPanelsChange:x}),{columnPanels:O,setColumnPanels:L}=h,N=c.useRef(C),R=c.useRef(O);c.useLayoutEffect(()=>{N.current=C,R.current=O},[C,O]);const u=c.useCallback(w=>{const E=n.current;if(E===null)return;const{plan:B,stageBlockSize:H}=pn(E,m);if(Number.isFinite(H)&&H>0&&E.style.setProperty(ue,`${String(H)}px`),N.current&&!w)return;const q=j.replanVisibleColumns(e.getSnapshot().visibleColumns,B);q!==null&&e.setVisibleColumns(q)},[e,n,m]);c.useLayoutEffect(()=>{u(!0),A(!0)},[u]),c.useEffect(()=>{const w=n.current;if(w===null||typeof ResizeObserver>"u")return;let E=null;const B=new ResizeObserver(()=>{E===null&&(E=requestAnimationFrame(()=>{E=null,u(!1)}))}),H=w.querySelector(D.SCROLL_ROOT_SELECTOR)?.firstElementChild,q=w.querySelector(`[${ce}]`);return H instanceof Element&&B.observe(H),q instanceof Element&&B.observe(q),()=>{B.disconnect(),E!==null&&cancelAnimationFrame(E)}},[n,u]),c.useEffect(()=>{C||u(!1)},[C,u]);const p=c.useMemo(()=>T?Mn(g,{logical:m,visible:i}):ve(i),[T,g,m,i]);c.useLayoutEffect(()=>{Fn(R.current,p)||L(p)},[p,L]);const f=c.useMemo(()=>D.sortColumnIds(Object.keys(O)).map(w=>({id:w,key:w,className:"aqmx-multi-column"})),[O]),M=c.useMemo(()=>g.docs.map(w=>{const E=K(g,w);return{id:E,component:Ln,title:ae(v,w),props:{docPath:w,panelId:E},minHeight:Bn,maxHeight:jn}}),[g,v]),_=c.useMemo(()=>Object.fromEntries(g.docs.map(w=>[K(g,w),!g.hidden.has(w)])),[g]),l=g.maximized===null?null:K(g,g.maximized),S=c.useCallback(w=>{const{layout:E}=e.getSnapshot();for(const[B,H]of W(E)){const q=w[B];if(q===void 0||q!==E.hidden.has(H))continue;const F=e.titleOf(H);if(q){if(!e.setHidden(H,!1))continue;r.announce(o.panelShown(F)),De(n,B);continue}const V=n.current,me=V===null?null:we(V,B);e.setHidden(H,!0)&&(r.announce(o.panelHidden(F)),me!==null&&Ee(n,me))}},[e,n,r,o]),b=c.useCallback(w=>{const E=W(e.getSnapshot().layout).get(w);if(E===void 0)return;const B=()=>{const q=e.titleOf(E),F=n.current,V=F===null?null:we(F,w);e.close(E)&&(r.announce(o.panelClosed(q)),V!==null&&Ee(n,V))},H=s.unsavedAmong([E]);H.length===0?B():s.askToDiscard(H).then(q=>{q&&B()})},[e,n,r,o,s]),I=c.useCallback(w=>{if(w===null){a(null);return}const E=W(e.getSnapshot().layout).get(w);E!==void 0&&a(E)},[e,a]);return k.jsx("div",{className:"aqmx-multi-layout","aria-busy":!T,children:k.jsx(D.DragDropLayout,{columns:f,panels:M,columnPanels:O,onColumnPanelsChange:x,panelVisibility:_,onPanelVisibilityChange:S,dragState:h.dragState,dragOverPosition:h.dragOverPosition,originalPanelPosition:h.originalPanelPosition,dragModes:h.dragModes,debugConfig:D.DEFAULT_DEBUG_CONFIG,panelSizes:h.panelSizes,customDrag:h.customDrag,setPanelRef:h.setPanelRef,onDragStart:h.handleDragStart,onDragEnd:h.handleDragEnd,onPlaceholderDragEnter:h.handlePlaceholderDragEnter,onPlaceholderDragLeave:h.handlePlaceholderDragLeave,onDragOverWithInsert:h.handleDragOverWithInsert,onDropWithInsert:h.handleDropWithInsert,onColumnDragLeave:h.handleColumnDragLeave,onPanelMouseDown:h.handleMouseDown,onPanelSizeInfoClick:h.handlePanelSizeInfoClick,onToggleDragMode:h.toggleDragMode,onPanelClose:b,onPanelMaximizeChange:I,maximizedPanel:l,dragHandle:"header",labels:d,panelClassName:"aqmx-multi-panel",renderPanelScrollArea:zn,renderStageScrollBar:Hn})})},oe={blockStart:"--aqmx-multi-toast-block-start",inlineEnd:"--aqmx-multi-toast-inline-end",room:"--aqmx-multi-toast-room"},$n=(e,n)=>{const t=n.getBoundingClientRect(),o=[t.left+1,t.left+t.width/2,t.right-1],r=[t.top+1,t.top+t.height/2,t.bottom-1];return o.some(s=>r.some(a=>{const m=n.ownerDocument.elementsFromPoint(s,a),g=m.findIndex(v=>n.contains(v)),i=m.findIndex(v=>e.contains(v));return g!==-1&&i!==-1&&i<g}))},Gn=(e,n)=>{const t=n.getBoundingClientRect(),o=n.ownerDocument.documentElement.clientWidth,r=getComputedStyle(n).direction==="rtl";return e.style.setProperty(oe.blockStart,`${String(t.top)}px`),e.style.setProperty(oe.inlineEnd,`${String(r?t.left:o-t.right)}px`),e.style.setProperty(oe.room,`${String(t.width)}px`),e.showPopover(),()=>{e.isConnected&&e.hidePopover()}},Yn=({store:e,body:n,limitNotice:t,onLimitNoticeCovered:o,ref:r})=>{const{config:s,labels:a,announcer:m,edits:g}=P.useExplorer(),i=c.useRef(null),v=c.useRef(null),C=z(e,u=>u.ready),T=z(e,u=>u.layout.docs.length>0),A=z(e,u=>u.visibleColumns),y=c.use(re.SheetNoticeSlotContext),d=c.useCallback(u=>{const{layout:p}=e.getSnapshot(),f=p.maximized,M=u===null&&f!==null?p.panelIds.get(f):void 0,_=i.current,l=M!==void 0&&_!==null&&de(_,M);e.maximize(u)&&(u!==null?m.announce(a.panelMaximized(e.titleOf(u))):f!==null&&m.announce(a.panelRestored(e.titleOf(f))),M!==void 0&&Vn(i,M,l))},[e,m,a]),x=c.useCallback((u,p,f,M)=>{if(f===p){e.setPendingHash(u,M);return}const _=g.unsavedAmong([p]);if(_.length>0){g.askToDiscard(_).then(I=>{I&&x(u,p,f,M)});return}const l=e.navigate(p,f);if(l==="navigated"){e.setPendingHash(u,M);return}if(l!=="existing")return;const{layout:S}=e.getSnapshot(),b=S.panelIds.get(f);b!==void 0&&(m.announce(a.panelAlreadyOpen(e.titleOf(f))),S.maximized===null?e.setHidden(f,!1):d(f),e.setPendingHash(b,M),De(i,b))},[e,m,a,d,g]);c.useLayoutEffect(()=>{if(t===null||y!==null||!he())return;const u=v.current,p=i.current;if(u===null||p===null)throw new Error("[markdown-explorer] the panel-limit notice and the stage must be mounted together");return Gn(u,p)},[t,y]),c.useEffect(()=>{const u=v.current;if(t===null||u===null)return;const{ownerDocument:p}=u;let f=null;const M=_=>{const l=_.target;l instanceof Element&&(f!==null&&cancelAnimationFrame(f),f=requestAnimationFrame(()=>{f=null,p.activeElement===l&&u.isConnected&&$n(u,l)&&o()}))};return p.addEventListener("focusin",M,!0),()=>{p.removeEventListener("focusin",M,!0),f!==null&&cancelAnimationFrame(f)}},[t,y,o]),c.useImperativeHandle(r,()=>({bringIntoView:u=>{requestAnimationFrame(()=>{const p=i.current,f=e.getSnapshot().layout.panelIds.get(u);p!==null&&f!==void 0&&G(p,f,null,Z)})}}),[e]),c.useEffect(()=>{const u=i.current;return()=>{u!==null&&P.stopKeepingInView(u)}},[]);const h=c.useCallback((u,p)=>{const f=i.current;f!==null&&G(f,u,p,Z)},[]),O=c.useCallback((u,p,f)=>{const M=i.current;M!==null&&G(M,u,f,_=>P.alignToStart(p,_))},[]),[L]=c.useState(je),N=c.useMemo(()=>({store:e,Body:n,followLink:x,maximize:d,revealInPanel:h,keepAtStartInPanel:O,focusCarry:L}),[e,n,x,d,h,O,L]),R=c.useMemo(()=>Array.from({length:s.multiView.columns},(u,p)=>D.generateColumnId(p)),[s]);return k.jsxs("section",{ref:i,className:"aqmx-multi-stage",style:An,tabIndex:-1,"aria-label":a.multiRegion,"aria-busy":T&&!C,"data-testid":"markdown-explorer-stage","data-aqmx-visible-columns":A,...P.CONTENT_PANE,children:[k.jsx("span",{className:"aqmx-multi-probe","aria-hidden":"true",[ce]:""}),T?C?k.jsx(Oe,{value:N,children:k.jsx(Un,{store:e,stageRef:i})}):k.jsx("div",{className:"aqmx-multi-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-stage-skeleton",children:R.map(u=>k.jsxs("div",{className:"aqmx-skeleton aqmx-multi-skeleton-column",children:[k.jsx("span",{}),k.jsx("span",{}),k.jsx("span",{})]},u))}):k.jsx("div",{className:"aqmx-empty","data-testid":"markdown-explorer-multi-empty",children:k.jsx("p",{className:"aqmx-empty-title",children:a.multiEmpty})}),t===null?null:y!==null?qe.createPortal(k.jsx("div",{ref:v,className:"aqmx-toast aqmx-multi-toast","data-testid":"markdown-explorer-panel-limit",children:t}),y):k.jsx("div",{ref:v,popover:he()?"manual":void 0,className:"aqmx-toast aqmx-multi-toast","data-testid":"markdown-explorer-panel-limit",children:t})]})},ze=3e3,He=(e,n)=>{if(n!==null)return n;const[t]=e;return t===void 0?null:t},le=(e,n,t)=>{const o=new Set(e),r=n.filter(a=>!o.has(a)),s=r.length>0?r.at(-1):t!==null&&n.includes(t)?t:n.at(-1);return s===void 0?null:s},Wn=(e,n,t)=>{switch(n){case"opened":return e.panelOpened(t);case"shown":return e.panelShown(t);case"closed":return e.panelClosed(t);default:{const o=n;throw new RangeError(`[markdown-explorer] unknown toggle outcome ${Y.describeValue(o)}`)}}},Kn=({location:e})=>{const{config:n,labels:t,announcer:o}=P.useExplorer(),r=un(e),s=z(r,f=>f.layout.docs),a=z(r,f=>f.layout.maximized),m=z(r,f=>f.layout.markup),g=z(r,f=>f.source),[i,v]=c.useState(()=>({docs:s,latest:le([],s,null)}));i.docs!==s&&v({docs:s,latest:le(i.docs,s,i.latest)});const C=a!==null?a:i.latest,[T,A]=c.useState(!1),y=c.useRef(null),[d,x]=c.useState(0),h=c.useRef(null),O=c.useRef(null);c.useLayoutEffect(()=>{const f=h.current;h.current=null,f!==null&&(r.whenUrlRendered(()=>o.announce(f.announcement)),O.current?.bringIntoView(f.doc))}),c.useEffect(()=>()=>{y.current!==null&&clearTimeout(y.current)},[]);const L=c.useCallback(()=>{y.current!==null&&clearTimeout(y.current),A(!0),y.current=setTimeout(()=>{y.current=null,A(!1)},ze)},[]),N=c.useCallback(()=>{y.current!==null&&clearTimeout(y.current),y.current=null,A(!1)},[]),R=c.useCallback(f=>{const M=r.titleOf(f),_=r.toggle(f);_==="rejected"&&L();const l=_==="rejected"?t.panelLimit(n.multiView.maxPanels):Wn(t,_,M);if(_==="shown"){h.current={doc:f,announcement:l},x(S=>S+1);return}r.whenUrlRendered(()=>{o.announce(l),_==="opened"&&O.current?.bringIntoView(f)})},[r,L,o,t,n]),u=c.useMemo(()=>new Set(s),[s]),p=c.useMemo(()=>{const f=He(s,a);return{href:j.explorerHref(n,{view:"tree",source:g,doc:f,markup:f!==null&&m.has(f)}),target:"tree"}},[n,g,s,a,m]);return k.jsx(re.ExplorerSplit,{view:"multi",explorer:k.jsx(re.ExplorerPane,{mode:"multi",sourceId:g,currentPath:C,openPaths:u,onOpenDocument:R,onSourceChange:r.changeSource,onRevealSource:r.revealSource,viewSwitch:p}),content:k.jsx(Yn,{ref:O,store:r,body:mn,limitNotice:T?t.panelLimit(n.multiView.maxPanels):null,onLimitNoticeCovered:N}),contentCoversPage:a!==null,sheetDismissals:d,onDraggingChange:r.setSplitDragging})};exports.MultiLayout=Kn;exports.PANEL_LIMIT_NOTICE_MS=ze;exports.latestOpenedDocument=le;exports.treeSwitchDocument=He;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("react/jsx-runtime"),c=require("react"),Y=require("./describeValue-Ccvhbt36.cjs"),j=require("./location-DFXJSMit.cjs"),P=require("./index-D6at9qMs.cjs"),re=require("./ExplorerSplit-DWBhCe7m.cjs"),D=require("@aiquants/drag-drop-panels"),fe=require("react-router"),ne=require("./storage-BpYsprog.cjs"),Ce=require("./ownUrls-BTPGNhBt.cjs"),qe=require("react-dom"),Be=require("@aiquants/markdown"),je=()=>{const e=new Map;return{hold:(n,t)=>{e.set(n,t),queueMicrotask(()=>{e.get(n)===t&&e.delete(n)})},take:n=>{const t=e.get(n);return e.delete(n),t===void 0?null:t}}},Oe=c.createContext(null),ie=()=>{const e=c.use(Oe);if(e===null)throw new Error("[markdown-explorer] multi-view panels must be rendered inside the multi-view stage");return e},Fe=(e,n)=>{const t=e.pendingHashes.get(n);return t===void 0?null:t},Ve=0xcbf29ce484222325n,Ue=0x100000001b3n,$e=(1n<<64n)-1n,Ge=(1n<<53n)-1n,Ye=new TextEncoder,We=e=>{let n=Ve;for(const t of Ye.encode(e))n=(n^BigInt(t))*Ue&$e;return Number(n&Ge)},Q=256,Ke=e=>`aqmx-p-${We(e).toString(36)}`,be=(e,n)=>{const t=Ke(e);let o=t;for(let r=2;n.has(o);r+=1)o=`${t}-${String(r)}`;return o},Je=new Map,Xe=(e,n=Je)=>{const t=new Set(e.flatMap(r=>n.get(r)??[])),o=new Map;for(const r of e){const s=n.get(r)??be(r,t);t.add(s),o.set(r,s)}return o},Pe=(e,n,t)=>{const o=e.columnOf.get(n);return o===void 0?void 0:Math.min(t-1,Math.max(0,o))},Te=(e,n)=>{const[t,...o]=j.columnGroups(n.logical,n.visible);if(t===void 0)throw new RangeError("[markdown-explorer] there must be at least one visible column");const r=([m,g])=>e.slice(m,g).reduce((i,v)=>i+v.length,0);let s=t;for(const m of o)r(m)<r(s)&&(s=m);let a=s[0];for(let m=s[0];m<s[1];m+=1)(e[m]?.length??0)<(e[a]?.length??0)&&(a=m);return a},ee=(e,n)=>{const t=Array.from({length:n.logical},()=>[]),o=[];for(const r of e.docs){const s=Pe(e,r,n.logical);s===void 0?o.push(r):t[s]?.push(r)}for(const r of o)t[Te(t,n)]?.push(r);return t},Ze=(e,n)=>j.columnGroups(e.length,n).map(([t,o])=>e.slice(t,o).flat()),Qe=(e,n,t)=>{const[o,r]=n,s=r-o,a=e.length,m=Array.from({length:s},(y,d)=>{const x=[0];for(const h of e)x.push((x.at(-1)??0)+(t(h)===o+d?1:0));return x}),g=(y,d,x)=>(m[y]?.[x]??0)-(m[y]?.[d]??0),i=Array.from({length:s+1},()=>Array.from({length:a+1},()=>Number.NEGATIVE_INFINITY)),v=Array.from({length:s+1},()=>Array.from({length:a+1},()=>0)),C=i[0];C&&(C[0]=0);for(let y=0;y<s;y+=1)for(let d=0;d<=a;d+=1)for(let x=0;x<=d;x+=1){const h=(i[y]?.[x]??Number.NEGATIVE_INFINITY)+g(y,x,d),O=i[y+1],L=v[y+1];O&&L&&h>(O[d]??Number.NEGATIVE_INFINITY)&&(O[d]=h,L[d]=x)}const T=Array.from({length:s},()=>[]);let A=a;for(let y=s;y>0;y-=1){const d=v[y]?.[A]??0;T[y-1]=e.slice(d,A),A=d}return T},Le=(e,n)=>{const t=n.flat(),o=new Map(e.columnOf);for(const[r,s]of n.entries())for(const a of s)o.delete(a),o.set(a,r);for(const r of o.keys()){if(o.size<=Q)break;o.delete(r)}return{docs:t,columnOf:o}},en=(e,n,t,o)=>{if(e.docs.includes(n))return{state:e,outcome:"existing"};if(e.docs.length>=o)return{state:e,outcome:"rejected"};const r=ee(e,t),s=Pe(e,n,t.logical)??Te(r,t);r[s]?.push(n);const a=new Map(e.panelIds);return a.set(n,be(n,new Set(a.values()))),{state:{...e,...Le(e,r),panelIds:a},outcome:"opened"}},Me=(e,n)=>{if(!e.docs.includes(n))return e;const t=new Set(e.hidden);t.delete(n);const o=new Set(e.markup);o.delete(n);const r=new Map(e.panelIds);return r.delete(n),{...e,docs:e.docs.filter(s=>s!==n),hidden:t,markup:o,panelIds:r,maximized:e.maximized===n?null:e.maximized}},nn=(e,n,t,o)=>{if(e.hidden.has(n))return{state:ke(e,n,!1),outcome:"shown"};if(e.docs.includes(n))return{state:Me(e,n),outcome:"closed"};const r=en(e,n,t,o);return{state:r.state,outcome:r.outcome==="rejected"?"rejected":"opened"}},tn=(e,n,t)=>{if(n===t||!e.docs.includes(n))return{state:e,outcome:"ignored"};if(e.docs.includes(t))return{state:e,outcome:"existing"};const o=new Map(e.columnOf),r=o.get(n);r!==void 0&&(o.delete(t),o.set(t,r));const s=new Set(e.hidden);s.delete(n);const a=new Map(e.panelIds),m=a.get(n);if(m===void 0)throw new Error(`[markdown-explorer] the open document ${Y.describeValue(n)} has no panel id`);a.delete(n),a.set(t,m);const g=new Set(e.markup);return g.delete(n),{state:{docs:e.docs.map(i=>i===n?t:i),maximized:e.maximized===n?t:e.maximized,columnOf:o,hidden:s,markup:g,panelIds:a},outcome:"navigated"}},ke=(e,n,t)=>{if(!e.docs.includes(n)||e.hidden.has(n)===t)return e;const o=new Set(e.hidden);return t?o.add(n):o.delete(n),{...e,hidden:o,maximized:t&&e.maximized===n?null:e.maximized}},on=(e,n,t)=>{if(!e.docs.includes(n)||e.markup.has(n)===t)return e;const o=new Set(e.markup);return t?o.add(n):o.delete(n),{...e,markup:o}},rn=(e,n)=>{if(e.maximized===n||n!==null&&!e.docs.includes(n))return e;if(n===null||!e.hidden.has(n))return{...e,maximized:n};const t=new Set(e.hidden);return t.delete(n),{...e,maximized:n,hidden:t}},sn=(e,n,t)=>{const o=ee(e,t),r=new Map;for(const[i,v]of o.entries())for(const C of v)r.set(C,i);const s=new Set(e.docs),a=new Set,m=j.columnGroups(t.logical,t.visible),g=Array.from({length:t.logical},()=>[]);for(const[i,v]of m.entries()){const C=(n[i]??[]).filter(T=>s.has(T)&&!a.has(T));for(const T of C)a.add(T);for(const[T,A]of Qe(C,v,y=>r.get(y)).entries())g[v[0]+T]?.push(...A)}for(const i of e.docs)a.has(i)||g[r.get(i)??0]?.push(i);return g.every((i,v)=>i.length===o[v]?.length&&i.every((C,T)=>o[v]?.[T]===C))?e:{...e,...Le(e,g)}},te=(e,n)=>{const t=[...new Set(e.docs)].slice(0,n),o=new Set(t),r=e.maximized!==null&&o.has(e.maximized)?e.maximized:null;return{docs:t,maximized:r,columnOf:e.stored.columnOf,hidden:new Set([...e.stored.hidden].filter(s=>o.has(s)&&s!==r)),markup:new Set(e.markup.filter(s=>o.has(s))),panelIds:Xe(t,e.panelIds)}},pe=(e,n)=>{if(e.docs.every(o=>e.columnOf.has(o)))return e;const t=new Map(e.columnOf);for(const[o,r]of ee(e,n).entries())for(const s of r)t.delete(s),t.set(s,o);for(const o of t.keys()){if(t.size<=Q)break;t.delete(o)}return{...e,columnOf:t}},Re=1,U=Object.freeze({columnOf:new Map,hidden:new Set}),ln=(e,n)=>{if(e===null||e==="")return U;let t;try{t=JSON.parse(e)}catch{return U}if(t===null||typeof t!="object"||Array.isArray(t))return U;const o=t;if(o.v!==Re)return U;const r=new Map;if(Array.isArray(o.columnOf))for(const a of o.columnOf.slice(-Q))Array.isArray(a)&&a.length===2&&typeof a[0]=="string"&&a[0]!==""&&Number.isInteger(a[1])&&a[1]>=0&&a[1]<n&&(r.delete(a[0]),r.set(a[0],a[1]));const s=new Set(Array.isArray(o.hidden)?o.hidden.filter(a=>typeof a=="string"&&a!==""):[]);return{columnOf:r,hidden:s}},an=e=>JSON.stringify({v:Re,columnOf:[...e.columnOf.entries()].slice(-Q),hidden:e.docs.filter(n=>e.hidden.has(n))}),ae=(e,n)=>{const t=e.get(n);return t===void 0?Ce.lastPathSegment(n):t},W=e=>{const n=new Map;for(const[t,o]of e.panelIds)n.set(o,t);return n},ge=e=>{if(!Ce.isAcceptableDocumentPath(e))throw new RangeError(`[markdown-explorer] not an acceptable document path: ${Y.describeValue(e)}`)},cn=({config:e,location:n,writeUrl:t,persist:o})=>{const{maxPanels:r,columns:s}=e.multiView,a=P.createEmitter(),m=new Map,g=new Map;let i={layout:te({docs:n.docs,maximized:n.maximized,markup:n.markup,stored:U},r),source:n.source,visibleColumns:s,ready:!1,splitDragging:!1,titles:new Map,pendingHashes:new Map},v=!1;const C=l=>v?pe(l,{logical:s,visible:i.visibleColumns}):l,T=(l,S)=>j.explorerHref(e,{view:"multi",source:l,docs:S.docs,maximized:S.maximized,markup:S.markup}),A=l=>({docs:l.docs,maximized:l.maximized,markup:[...l.markup]});let y=T(n.source,n),d=n.source,x=y;const h=[],O=[];let L=null;const N=()=>{if(!(h.length>0))for(const l of O.splice(0))l()},R=l=>{i={...i,...l},a.emit()},u=()=>{if(!i.ready)return;const l=an(i.layout);l!==L&&(L=l,o(l))},p=(l,S,b)=>{const I=T(l,A(S));I!==y&&(y=I,d=l,h.push(I),t(I,b))},f=l=>{const S=new Set(l.panelIds.values());for(const E of[...m.keys()])S.has(E)||m.delete(E);for(const E of[...g.keys()])S.has(E)||g.delete(E);const b=new Set(l.docs),I=[...i.titles.keys()].every(E=>b.has(E))?i.titles:new Map([...i.titles].filter(([E])=>b.has(E))),w=[...i.pendingHashes.keys()].every(E=>S.has(E))?i.pendingHashes:new Map([...i.pendingHashes].filter(([E])=>S.has(E)));return{titles:I,pendingHashes:w}},M=l=>l===i.layout?!1:(R({layout:l,...f(l)}),p(d,l,"replace"),u(),!0),_=()=>({logical:s,visible:i.visibleColumns});return{getSnapshot:()=>i,subscribe:a.subscribe,toggle:l=>{ge(l);const{state:S,outcome:b}=nn(i.layout,l,_(),r);return M(S),b},close:l=>M(Me(i.layout,l)),navigate:(l,S)=>{ge(S);const{state:b,outcome:I}=tn(i.layout,l,S);if(I!=="navigated")return I;const w=b.panelIds.get(S);return w!==void 0&&(m.delete(w),g.delete(w)),M(b),I},setHidden:(l,S)=>M(ke(i.layout,l,S)),maximize:l=>M(rn(i.layout,l)),setMarkup:(l,S)=>M(on(i.layout,l,S)),arrange:l=>M(sn(i.layout,l,{logical:s,visible:l.length})),changeSource:l=>{p(l,i.layout,"push")},revealSource:l=>{p(l,i.layout,"replace")},observeLocation:l=>{const S=T(l.source,l);if(S===y)return h.length=0,x=S,l.source!==i.source&&R({source:l.source}),N(),!1;if(S===x)return!1;x=S;const b=h.indexOf(S);if(b>=0)return h.splice(0,b+1),l.source!==i.source&&R({source:l.source}),N(),!1;h.length=0,y=S,d=l.source;const I=C(te({docs:l.docs,maximized:l.maximized,markup:l.markup,stored:{columnOf:i.layout.columnOf,hidden:i.layout.hidden},panelIds:i.layout.panelIds},r));return R({layout:I,source:l.source,...f(I)}),u(),N(),!0},whenUrlRendered:l=>{O.push(l),N()},loadStored:l=>{R({layout:C(te({docs:i.layout.docs,maximized:i.layout.maximized,markup:[...i.layout.markup],stored:l,panelIds:i.layout.panelIds},r)),ready:!0}),u()},setVisibleColumns:l=>{if(!Number.isInteger(l)||l<1||l>s)throw new RangeError(`[markdown-explorer] visible columns must be an integer in 1..${String(s)}; got ${Y.describeValue(l)}`);v=!0;const S=pe(i.layout,{logical:s,visible:l});l===i.visibleColumns&&S===i.layout||(R({visibleColumns:l,layout:S}),S!==i.layout&&u())},setSplitDragging:l=>{l!==i.splitDragging&&R({splitDragging:l})},setTitle:(l,S)=>{!i.layout.docs.includes(l)||i.titles.get(l)===S||R({titles:new Map(i.titles).set(l,S)})},titleOf:l=>ae(i.titles,l),setPendingHash:(l,S)=>{const b=i.pendingHashes.get(l);if(S===null||S===""){if(b===void 0)return;const I=new Map(i.pendingHashes);I.delete(l),R({pendingHashes:I});return}b!==S&&R({pendingHashes:new Map(i.pendingHashes).set(l,S)})},saveReadingPosition:(l,S,b)=>{i.layout.panelIds.get(S)===l&&m.set(l,{doc:S,position:b})},readingPositionOf:(l,S)=>{const b=m.get(l);return b===void 0||b.doc!==S?null:b.position},saveImageView:(l,S,b)=>{g.set(l,{url:S,state:b})},imageViewOf:(l,S)=>{const b=g.get(l);return b===void 0||b.url!==S?null:b.state}}},z=(e,n)=>{const t=()=>n(e.getSnapshot());return c.useSyncExternalStore(e.subscribe,t,t)},un=e=>{const{config:n,storageNamespace:t}=P.useExplorer(),o=fe.useNavigate(),r=c.useRef(o),s=ne.storageKeys(t).multiLayout,[a]=c.useState(()=>cn({config:n,location:e,writeUrl:(i,v)=>{r.current(i,P.explorerNavigationOptions(v==="replace"?"browse":"switch-source"))},persist:i=>ne.writeStorage(s,i)}));c.useLayoutEffect(()=>{r.current=o},[o]);const m=fe.useLocation(),g=c.useMemo(()=>({location:e,navigated:m}),[e,m]);return c.useLayoutEffect(()=>{a.observeLocation(g.location)},[a,g]),c.useLayoutEffect(()=>{a.loadStored(ln(ne.readStorage(s),n.multiView.columns))},[a,s,n]),a},dn=e=>{const n=e.closest(D.SCROLL_AREA_SELECTOR);if(n===null)throw new Error("[markdown-explorer] a panel's document region is not inside the panel's scroll area");return n},mn=({docPath:e,panelId:n,maximized:t,title:o,onContentShown:r})=>{const{store:s,followLink:a,revealInPanel:m,keepAtStartInPanel:g}=ie(),{announcer:i}=P.useExplorer(),v=z(s,u=>Fe(u,n)),C=z(s,u=>u.layout.markup.has(e)),T=c.useCallback((u,p)=>a(n,e,u,p),[a,n,e]),A=c.useCallback(()=>s.setPendingHash(n,null),[s,n]),y=c.useMemo(()=>({read:u=>s.imageViewOf(n,u),save:(u,p)=>s.saveImageView(n,u,p)}),[s,n]),d=c.useCallback((u,p)=>{p.kind!=="failure"&&s.setTitle(u,p.name),r(u)},[s,r]),x=c.useCallback(u=>{s.whenUrlRendered(()=>i.announce(u))},[s,i]),h=c.useMemo(()=>({scrollerOf:dn,reveal:u=>m(n,u),keepAtStart:(u,p)=>g(n,u,p)}),[m,g,n]),O=c.useMemo(()=>({kind:"panel",maximized:t,onDocumentLink:T,pendingHash:v,onHashConsumed:A,announceFailure:x,paneScroll:h}),[t,T,v,A,x,h]),L=c.useMemo(()=>({kind:"panel",documentName:o,maximized:t}),[o,t]),N=c.useCallback(()=>s.setMarkup(e,!s.getSnapshot().layout.markup.has(e)),[s,e]),R=c.useMemo(()=>({shown:C,toggle:N}),[C,N]);return k.jsxs(P.ImageViewMemoryContext,{value:y,children:[k.jsx(P.DocumentRefreshBar,{path:e,placement:L,markup:R,maximize:null}),k.jsx(P.DocumentPane,{path:e,absence:P.NO_DOCUMENT,markup:C,variant:O,onDocumentShown:d})]})},he=()=>typeof HTMLElement<"u"&&typeof HTMLElement.prototype.showPopover=="function"&&typeof HTMLElement.prototype.hidePopover=="function",ce="data-aqmx-column-probe",J="data-panel-id",se="--aqmx-multi-panel-chrome",fn=e=>e==="normal"?0:P.cssPixels(e),pn=(e,n)=>{const t=e.querySelector(D.SCROLL_ROOT_SELECTOR)?.firstElementChild,o=e.querySelector(`[${ce}]`),r=o instanceof HTMLElement?o.getBoundingClientRect().width:Number.NaN;if(!(t instanceof HTMLElement))return{plan:{trackInlineSize:Number.NaN,gap:Number.NaN,minColumnInlineSize:r,logicalColumns:n},stageBlockSize:Number.NaN};const s=getComputedStyle(t),a=t.clientWidth-P.cssPixels(s.paddingLeft)-P.cssPixels(s.paddingRight),m=t.clientHeight-P.cssPixels(s.paddingTop)-P.cssPixels(s.paddingBottom);return{plan:{trackInlineSize:a,gap:fn(s.columnGap),minColumnInlineSize:r,logicalColumns:n},stageBlockSize:m}},gn=(e,n)=>{if(e.getClientRects().length===0)return Number.NaN;const t=getComputedStyle(e);return n.getBoundingClientRect().top-e.getBoundingClientRect().top+P.cssPixels(t.paddingBottom)+P.cssPixels(t.borderBottomWidth)},X="data-aqmx-panel-frame",Se="--aqmx-multi-panel-pinned-block-size",hn=e=>{const{docPath:n,panelId:t}=e;if(typeof n!="string"||typeof t!="string")throw new TypeError("[markdown-explorer] a multi-view panel needs string docPath and panelId props");return{docPath:n,panelId:t}},Sn=e=>{const n=getComputedStyle(e),t=Number.parseFloat(n.lineHeight);return Number.isFinite(t)?t:Number.parseFloat(n.fontSize)},xn=(e,n,t)=>e.deltaMode===WheelEvent.DOM_DELTA_PAGE?e.deltaY*n.clientHeight:e.deltaMode!==WheelEvent.DOM_DELTA_LINE?e.deltaY:e.deltaY*t(n),$=e=>{const n=e.closest(D.SCROLL_AREA_SELECTOR);return n instanceof HTMLElement?n:null},Ne=e=>{const n=e.firstElementChild;return n instanceof HTMLElement&&getComputedStyle(n).position==="sticky"?n:null},Ae=(e,n)=>{const t=n.getBoundingClientRect().top,o=Ne(e);return o===null?t:Math.max(t,o.getBoundingClientRect().bottom)},xe=(e,n)=>{let t=0,o=e.length;for(;t<o;){const r=t+o>>>1;(e[r]?.getBoundingClientRect().bottom??Number.NEGATIVE_INFINITY)>n?o=r:t=r+1}return t<e.length?t:-1},yn=(e,n)=>{const t=Ae(e,n),o=[];let r=e;for(let a=xe([...r.children],t);a>=0;a=xe([...r.children],t)){const m=r.children[a];if(m===void 0)break;o.push(a),r=m}const s=r.getBoundingClientRect();return{scrollTop:n.scrollTop,anchor:o.length===0?null:{path:o,offset:s.top-t,height:s.height}}},ye=(e,n,t)=>{if(n.scrollTop=t.scrollTop,t.anchor===null)return;let o=e;for(const g of t.anchor.path)o=o?.children[g];if(o===void 0)return;const r=o.getBoundingClientRect(),{offset:s,height:a}=t.anchor,m=s<0&&a>0?s/a*r.height:s;n.scrollTop+=r.top-Ae(e,n)-m},vn=Object.freeze(["data-testid","aria-label","title","href","id","name"]),Ie=e=>{const n=e.getAttribute(D.PANEL_ACTION_ATTRIBUTE);return JSON.stringify(n===null?[e.tagName,...vn.map(t=>e.getAttribute(t))]:[e.tagName,D.PANEL_ACTION_ATTRIBUTE,n])},wn=(e,n)=>{if(n===null||!e.contains(n))return null;const t=[];for(let o=n;o!==e;){const r=o.parentElement;if(r===null)return null;t.unshift([...r.children].indexOf(o)),o=r}return{path:t,signature:Ie(n)}},En=(e,n,t)=>{let o=e;for(const r of t.path)o=o?.children[r];o instanceof HTMLElement&&Ie(o)===t.signature&&P.focusWithoutScroll(o)||n.focus({preventScroll:!0})},Cn=(e,n,t)=>{if(e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY))return;const o=e.ctrlKey||e.metaKey,r=o?$(n):n.closest(D.SCROLL_ROOT_SELECTOR);if(!(r instanceof HTMLElement))return;const s=xn(e,r,t);(o||On(r,s))&&(e.preventDefault(),r.scrollTop+=s)},On=(e,n)=>n<0?e.scrollTop>0:n>0?Math.ceil(e.scrollTop+e.clientHeight)<e.scrollHeight:!1,bn=e=>e.scrollHeight>e.clientHeight,Pn=(e,n,t)=>{let o=Number.NaN,r=Number.NaN;const s=Ne(t),a=()=>{const i=gn(e,n);if(!Number.isFinite(i))return;const v=s===null?0:s.getBoundingClientRect().height;v!==r&&(r=v,t.style.setProperty(Se,`${String(v)}px`));const C=i+v;C!==o&&(o=C,e.style.setProperty(se,`${String(C)}px`))};a();let m=null;const g=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>{m===null&&(m=requestAnimationFrame(()=>{m=null,a()}))});return g?.observe(e),g?.observe(n),s!==null&&g?.observe(s),()=>{g?.disconnect(),m!==null&&cancelAnimationFrame(m),e.style.removeProperty(se),t.style.removeProperty(Se)}},Tn=e=>{const{docPath:n,panelId:t}=hn(e),{store:o,Body:r,maximize:s,focusCarry:a}=ie(),m=z(o,d=>d.layout.maximized===n),g=z(o,d=>ae(d.titles,n)),i=c.useRef(null),v=c.useRef(null),C=c.useRef(null),T=c.useRef(null);c.useEffect(()=>{const d=i.current,x=d===null?null:$(d);if(d===null||x===null||m)return;const h=new Map,O=p=>{const f=h.get(p);if(f!==void 0)return f;const M=Sn(p);return h.set(p,M),M},L=p=>Cn(p,d,O);let N=!1;const R=()=>{const p=bn(x);p!==N&&(N=p,p?d.addEventListener("wheel",L,{capture:!0,passive:!1}):d.removeEventListener("wheel",L,{capture:!0}))};R();const u=typeof ResizeObserver>"u"?null:new ResizeObserver(R);return u?.observe(x),u?.observe(d),()=>{u?.disconnect(),d.removeEventListener("wheel",L,{capture:!0})}},[m]),c.useLayoutEffect(()=>{const d=i.current,x=d===null?null:$(d),h=d===null?null:d.closest(`[${J}]`);if(!(d===null||x===null||!(h instanceof HTMLElement)))return Pn(h,x,d)},[]),c.useLayoutEffect(()=>{const d=i.current,x=d===null?null:$(d);if(d===null||x===null)return;const h=p=>{ye(d,x,p),T.current=x.scrollTop},O=o.readingPositionOf(t,n);v.current=O===null?null:{doc:n,position:O},O!==null&&h(O);let L=null,N=d.getBoundingClientRect().width;const R=()=>{L===null&&(L=requestAnimationFrame(()=>{L=null;const p=T.current;if(T.current=null,p!==null&&x.scrollTop===p||d.getBoundingClientRect().width!==N)return;const f=C.current;f!==null&&o.saveReadingPosition(t,f,yn(d,x))}))};x.addEventListener("scroll",R,{passive:!0});const u=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>{const p=d.getBoundingClientRect().width;if(p===N)return;N=p;const f=o.readingPositionOf(t,n);f!==null&&h(f)});return u?.observe(d),()=>{x.removeEventListener("scroll",R),u?.disconnect(),L!==null&&cancelAnimationFrame(L)}},[o,t,n]),c.useLayoutEffect(()=>{const d=i.current,x=d===null?null:d.closest(`[${J}]`);if(d===null||x===null)return;const h=a.take(t);return h!==null&&En(x,d,h),()=>{const O=wn(x,x.ownerDocument.activeElement);O!==null&&a.hold(t,O)}},[a,t]);const A=c.useCallback(d=>{const x=i.current,h=x===null?null:$(x);if(x===null||h===null)return;const O=C.current;C.current=d;const L=v.current;v.current=null,L!==null&&L.doc===d?(ye(x,h,L.position),T.current=h.scrollTop):O!==null&&O!==d&&(h.scrollTop=0)},[]),y=c.useCallback(d=>{P.isInFullscreenBlock(d.target)||s(n)},[s,n]);return k.jsx("div",{ref:i,role:"group","aria-label":g,className:"aqmx-multi-panel-frame",tabIndex:-1,"data-aqmx-panel-frame":t,"data-aqmx-maximized":m?"true":"false","data-testid":"markdown-explorer-panel-frame",...m?P.CONTENT_PANE:{},onDoubleClick:m?void 0:y,children:k.jsx(r,{docPath:n,panelId:t,maximized:m,title:g,onContentShown:A})})},Ln=c.memo(Tn),K=(e,n)=>{const t=e.panelIds.get(n);if(t===void 0)throw new Error(`[markdown-explorer] the open document ${Y.describeValue(n)} has no panel id`);return t},ve=e=>Object.fromEntries(D.generateColumnIds(e).map(n=>[n,[]])),Mn=(e,n)=>{const t=Ze(ee(e,n),n.visible);return Object.fromEntries(t.map((o,r)=>[D.generateColumnId(r),o.map(s=>K(e,s))]))},kn=(e,n)=>{const t=W(e);return D.sortColumnIds(Object.keys(n)).map(o=>(n[o]??[]).flatMap(r=>{const s=t.get(r);return s===void 0?[]:[s]}))},Rn=e=>({switchToCustomDragMode:e.panelSwitchToCustomDrag,switchToNormalDragMode:e.panelSwitchToNormalDrag,hidePanel:e.panelHide,maximizePanel:e.panelMaximize,restorePanel:e.panelRestore,closePanel:e.panelClose,movePanel:e.panelMove,movePanelToPreviousColumn:e.panelMovePreviousColumn,movePanelToNextColumn:e.panelMoveNextColumn,movePanelUp:e.panelMoveUp,movePanelDown:e.panelMoveDown,morePanelActions:e.panelMoreActions,customDragModeBadge:e.panelCustomDragBadge,panelMoved:e.panelMoved,panelMoveUnavailable:e.panelMoveUnavailable,panelDragStarted:e.panelDragStarted,panelDragCancelled:e.panelDragCancelled,hiddenPanels:e.hiddenPanelsTitle,hiddenPanelBadge:e.hiddenPanelBadge,hiddenPanelNotice:e.hiddenPanelNotice,emptyColumn:e.multiColumnEmpty,dropZone:e.multiColumnRegion,dropHere:e.panelDropHere}),Nn="--aqmx-multi-stage-bar-gutter",An=Object.freeze({[Nn]:`${String(P.NATIVE_SCROLL_BAR_WIDTH)}px`}),In=Object.freeze({blockSize:"100%",paddingInlineEnd:P.TAP_SCROLL_CIRCLE_GUTTER_LENGTH}),_n=Object.freeze({[D.NO_PANEL_DRAG_ATTRIBUTE]:"",style:Object.freeze({display:"flex"})}),Dn=e=>k.jsx("div",{..._n,children:k.jsx(P.LazyNativeScrollBar,{scroller:e,kind:"content"})}),zn=({props:e,children:n})=>k.jsx(Be.HostedScrollArea,{scrollerProps:{...e,style:In},renderScrollBar:Dn,barInlineSize:P.NATIVE_SCROLL_BAR_SLOT_LENGTH,children:n}),Hn=e=>k.jsx(P.LazyNativeScrollBar,{scroller:e,kind:"stage"}),ue="--aqmx-stage-block",qn="--aqmx-multi-panel-body-floor",Bn=`calc(var(${ue}) * ${String(j.PANEL_MIN_BLOCK_RATIO)})`,jn=`max(calc(var(${ue}) * ${String(j.PANEL_MAX_BLOCK_RATIO)}), calc(var(${se}) + var(${qn})))`,Fn=(e,n)=>{const t=Object.entries(e);return t.length!==Object.keys(n).length?!1:t.every(([o,r])=>{const s=n[o];return s!==void 0&&s.length===r.length&&s.every((a,m)=>r[m]===a)})},G=(e,n,t,o)=>{P.stopKeepingInView(e);const r=e.querySelector(`[${J}="${n}"]`);if(!(r instanceof HTMLElement))return;const s=t!==null&&r.contains(t)?t:null,a=[{element:r,boundary:r.closest(D.SCROLL_ROOT_SELECTOR)}];s!==null&&a.push({element:s,boundary:r}),P.keepInView(e,()=>r.isConnected?(r.scrollIntoView(P.NEAREST),s?.isConnected!==!0?r:(o(s),s)):null,a)},Z=e=>{e.scrollIntoView(P.NEAREST)},_e=(e,n)=>{const t=e.querySelector(`[${X}="${n}"]`);return t instanceof HTMLElement?(G(e,n,null,Z),t.focus({preventScroll:!0}),!0):!1},de=(e,n)=>{const t=e.querySelector(`[${J}="${n}"]`);return t instanceof HTMLElement&&t.contains(e.ownerDocument.activeElement)},we=(e,n)=>{if(!de(e,n))return null;const t=[...e.querySelectorAll(`[${X}]`)].map(a=>a.getAttribute(X)),o=t.indexOf(n),r=t[o+1];if(o>=0&&typeof r=="string")return{kind:"panel",panelId:r};const s=t[o-1];return o>0&&typeof s=="string"?{kind:"panel",panelId:s}:{kind:"stage"}},Ee=(e,n)=>{requestAnimationFrame(()=>{const t=e.current;t!==null&&(n.kind==="panel"&&_e(t,n.panelId)||t.focus({preventScroll:!0}))})},De=(e,n)=>{requestAnimationFrame(()=>{const t=e.current;t!==null&&_e(t,n)})},Vn=(e,n,t)=>{requestAnimationFrame(()=>{const o=e.current;if(o===null)return;const{activeElement:r,body:s}=o.ownerDocument;if(G(o,n,t&&de(o,n)?r:null,Z),!t||r!==null&&r!==s&&r.isConnected)return;const a=o.querySelector(`[${X}="${n}"]`);a instanceof HTMLElement&&a.focus({preventScroll:!0})})},Un=({store:e,stageRef:n})=>{const{config:t,labels:o,announcer:r,edits:s}=P.useExplorer(),{maximize:a}=ie(),m=t.multiView.columns,g=z(e,w=>w.layout),i=z(e,w=>w.visibleColumns),v=z(e,w=>w.titles),C=z(e,w=>w.layout.maximized!==null||w.splitDragging),[T,A]=c.useState(!1),[y]=c.useState(()=>ve(i)),d=c.useMemo(()=>Rn(o),[o]),x=c.useCallback(w=>{e.arrange(kn(e.getSnapshot().layout,w))},[e]),h=D.useDragDropColumns({initialColumnPanels:y,initialPanelVisibility:{},debugConfig:D.DEFAULT_DEBUG_CONFIG,onColumnPanelsChange:x}),{columnPanels:O,setColumnPanels:L}=h,N=c.useRef(C),R=c.useRef(O);c.useLayoutEffect(()=>{N.current=C,R.current=O},[C,O]);const u=c.useCallback(w=>{const E=n.current;if(E===null)return;const{plan:B,stageBlockSize:H}=pn(E,m);if(Number.isFinite(H)&&H>0&&E.style.setProperty(ue,`${String(H)}px`),N.current&&!w)return;const q=j.replanVisibleColumns(e.getSnapshot().visibleColumns,B);q!==null&&e.setVisibleColumns(q)},[e,n,m]);c.useLayoutEffect(()=>{u(!0),A(!0)},[u]),c.useEffect(()=>{const w=n.current;if(w===null||typeof ResizeObserver>"u")return;let E=null;const B=new ResizeObserver(()=>{E===null&&(E=requestAnimationFrame(()=>{E=null,u(!1)}))}),H=w.querySelector(D.SCROLL_ROOT_SELECTOR)?.firstElementChild,q=w.querySelector(`[${ce}]`);return H instanceof Element&&B.observe(H),q instanceof Element&&B.observe(q),()=>{B.disconnect(),E!==null&&cancelAnimationFrame(E)}},[n,u]),c.useEffect(()=>{C||u(!1)},[C,u]);const p=c.useMemo(()=>T?Mn(g,{logical:m,visible:i}):ve(i),[T,g,m,i]);c.useLayoutEffect(()=>{Fn(R.current,p)||L(p)},[p,L]);const f=c.useMemo(()=>D.sortColumnIds(Object.keys(O)).map(w=>({id:w,key:w,className:"aqmx-multi-column"})),[O]),M=c.useMemo(()=>g.docs.map(w=>{const E=K(g,w);return{id:E,component:Ln,title:ae(v,w),props:{docPath:w,panelId:E},minHeight:Bn,maxHeight:jn}}),[g,v]),_=c.useMemo(()=>Object.fromEntries(g.docs.map(w=>[K(g,w),!g.hidden.has(w)])),[g]),l=g.maximized===null?null:K(g,g.maximized),S=c.useCallback(w=>{const{layout:E}=e.getSnapshot();for(const[B,H]of W(E)){const q=w[B];if(q===void 0||q!==E.hidden.has(H))continue;const F=e.titleOf(H);if(q){if(!e.setHidden(H,!1))continue;r.announce(o.panelShown(F)),De(n,B);continue}const V=n.current,me=V===null?null:we(V,B);e.setHidden(H,!0)&&(r.announce(o.panelHidden(F)),me!==null&&Ee(n,me))}},[e,n,r,o]),b=c.useCallback(w=>{const E=W(e.getSnapshot().layout).get(w);if(E===void 0)return;const B=()=>{const q=e.titleOf(E),F=n.current,V=F===null?null:we(F,w);e.close(E)&&(r.announce(o.panelClosed(q)),V!==null&&Ee(n,V))},H=s.unsavedAmong([E]);H.length===0?B():s.askToDiscard(H).then(q=>{q&&B()})},[e,n,r,o,s]),I=c.useCallback(w=>{if(w===null){a(null);return}const E=W(e.getSnapshot().layout).get(w);E!==void 0&&a(E)},[e,a]);return k.jsx("div",{className:"aqmx-multi-layout","aria-busy":!T,children:k.jsx(D.DragDropLayout,{columns:f,panels:M,columnPanels:O,onColumnPanelsChange:x,panelVisibility:_,onPanelVisibilityChange:S,dragState:h.dragState,dragOverPosition:h.dragOverPosition,originalPanelPosition:h.originalPanelPosition,dragModes:h.dragModes,debugConfig:D.DEFAULT_DEBUG_CONFIG,panelSizes:h.panelSizes,customDrag:h.customDrag,setPanelRef:h.setPanelRef,onDragStart:h.handleDragStart,onDragEnd:h.handleDragEnd,onPlaceholderDragEnter:h.handlePlaceholderDragEnter,onPlaceholderDragLeave:h.handlePlaceholderDragLeave,onDragOverWithInsert:h.handleDragOverWithInsert,onDropWithInsert:h.handleDropWithInsert,onColumnDragLeave:h.handleColumnDragLeave,onPanelMouseDown:h.handleMouseDown,onPanelSizeInfoClick:h.handlePanelSizeInfoClick,onToggleDragMode:h.toggleDragMode,onPanelClose:b,onPanelMaximizeChange:I,maximizedPanel:l,dragHandle:"header",labels:d,panelClassName:"aqmx-multi-panel",renderPanelScrollArea:zn,renderStageScrollBar:Hn})})},oe={blockStart:"--aqmx-multi-toast-block-start",inlineEnd:"--aqmx-multi-toast-inline-end",room:"--aqmx-multi-toast-room"},$n=(e,n)=>{const t=n.getBoundingClientRect(),o=[t.left+1,t.left+t.width/2,t.right-1],r=[t.top+1,t.top+t.height/2,t.bottom-1];return o.some(s=>r.some(a=>{const m=n.ownerDocument.elementsFromPoint(s,a),g=m.findIndex(v=>n.contains(v)),i=m.findIndex(v=>e.contains(v));return g!==-1&&i!==-1&&i<g}))},Gn=(e,n)=>{const t=n.getBoundingClientRect(),o=n.ownerDocument.documentElement.clientWidth,r=getComputedStyle(n).direction==="rtl";return e.style.setProperty(oe.blockStart,`${String(t.top)}px`),e.style.setProperty(oe.inlineEnd,`${String(r?t.left:o-t.right)}px`),e.style.setProperty(oe.room,`${String(t.width)}px`),e.showPopover(),()=>{e.isConnected&&e.hidePopover()}},Yn=({store:e,body:n,limitNotice:t,onLimitNoticeCovered:o,ref:r})=>{const{config:s,labels:a,announcer:m,edits:g}=P.useExplorer(),i=c.useRef(null),v=c.useRef(null),C=z(e,u=>u.ready),T=z(e,u=>u.layout.docs.length>0),A=z(e,u=>u.visibleColumns),y=c.use(re.SheetNoticeSlotContext),d=c.useCallback(u=>{const{layout:p}=e.getSnapshot(),f=p.maximized,M=u===null&&f!==null?p.panelIds.get(f):void 0,_=i.current,l=M!==void 0&&_!==null&&de(_,M);e.maximize(u)&&(u!==null?m.announce(a.panelMaximized(e.titleOf(u))):f!==null&&m.announce(a.panelRestored(e.titleOf(f))),M!==void 0&&Vn(i,M,l))},[e,m,a]),x=c.useCallback((u,p,f,M)=>{if(f===p){e.setPendingHash(u,M);return}const _=g.unsavedAmong([p]);if(_.length>0){g.askToDiscard(_).then(I=>{I&&x(u,p,f,M)});return}const l=e.navigate(p,f);if(l==="navigated"){e.setPendingHash(u,M);return}if(l!=="existing")return;const{layout:S}=e.getSnapshot(),b=S.panelIds.get(f);b!==void 0&&(m.announce(a.panelAlreadyOpen(e.titleOf(f))),S.maximized===null?e.setHidden(f,!1):d(f),e.setPendingHash(b,M),De(i,b))},[e,m,a,d,g]);c.useLayoutEffect(()=>{if(t===null||y!==null||!he())return;const u=v.current,p=i.current;if(u===null||p===null)throw new Error("[markdown-explorer] the panel-limit notice and the stage must be mounted together");return Gn(u,p)},[t,y]),c.useEffect(()=>{const u=v.current;if(t===null||u===null)return;const{ownerDocument:p}=u;let f=null;const M=_=>{const l=_.target;l instanceof Element&&(f!==null&&cancelAnimationFrame(f),f=requestAnimationFrame(()=>{f=null,p.activeElement===l&&u.isConnected&&$n(u,l)&&o()}))};return p.addEventListener("focusin",M,!0),()=>{p.removeEventListener("focusin",M,!0),f!==null&&cancelAnimationFrame(f)}},[t,y,o]),c.useImperativeHandle(r,()=>({bringIntoView:u=>{requestAnimationFrame(()=>{const p=i.current,f=e.getSnapshot().layout.panelIds.get(u);p!==null&&f!==void 0&&G(p,f,null,Z)})}}),[e]),c.useEffect(()=>{const u=i.current;return()=>{u!==null&&P.stopKeepingInView(u)}},[]);const h=c.useCallback((u,p)=>{const f=i.current;f!==null&&G(f,u,p,Z)},[]),O=c.useCallback((u,p,f)=>{const M=i.current;M!==null&&G(M,u,f,_=>P.alignToStart(p,_))},[]),[L]=c.useState(je),N=c.useMemo(()=>({store:e,Body:n,followLink:x,maximize:d,revealInPanel:h,keepAtStartInPanel:O,focusCarry:L}),[e,n,x,d,h,O,L]),R=c.useMemo(()=>Array.from({length:s.multiView.columns},(u,p)=>D.generateColumnId(p)),[s]);return k.jsxs("section",{ref:i,className:"aqmx-multi-stage",style:An,tabIndex:-1,"aria-label":a.multiRegion,"aria-busy":T&&!C,"data-testid":"markdown-explorer-stage","data-aqmx-visible-columns":A,...P.CONTENT_PANE,children:[k.jsx("span",{className:"aqmx-multi-probe","aria-hidden":"true",[ce]:""}),T?C?k.jsx(Oe,{value:N,children:k.jsx(Un,{store:e,stageRef:i})}):k.jsx("div",{className:"aqmx-multi-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-stage-skeleton",children:R.map(u=>k.jsxs("div",{className:"aqmx-skeleton aqmx-multi-skeleton-column",children:[k.jsx("span",{}),k.jsx("span",{}),k.jsx("span",{})]},u))}):k.jsx("div",{className:"aqmx-empty","data-testid":"markdown-explorer-multi-empty",children:k.jsx("p",{className:"aqmx-empty-title",children:a.multiEmpty})}),t===null?null:y!==null?qe.createPortal(k.jsx("div",{ref:v,className:"aqmx-toast aqmx-multi-toast","data-testid":"markdown-explorer-panel-limit",children:t}),y):k.jsx("div",{ref:v,popover:he()?"manual":void 0,className:"aqmx-toast aqmx-multi-toast","data-testid":"markdown-explorer-panel-limit",children:t})]})},ze=3e3,He=(e,n)=>{if(n!==null)return n;const[t]=e;return t===void 0?null:t},le=(e,n,t)=>{const o=new Set(e),r=n.filter(a=>!o.has(a)),s=r.length>0?r.at(-1):t!==null&&n.includes(t)?t:n.at(-1);return s===void 0?null:s},Wn=(e,n,t)=>{switch(n){case"opened":return e.panelOpened(t);case"shown":return e.panelShown(t);case"closed":return e.panelClosed(t);default:{const o=n;throw new RangeError(`[markdown-explorer] unknown toggle outcome ${Y.describeValue(o)}`)}}},Kn=({location:e})=>{const{config:n,labels:t,announcer:o}=P.useExplorer(),r=un(e),s=z(r,f=>f.layout.docs),a=z(r,f=>f.layout.maximized),m=z(r,f=>f.layout.markup),g=z(r,f=>f.source),[i,v]=c.useState(()=>({docs:s,latest:le([],s,null)}));i.docs!==s&&v({docs:s,latest:le(i.docs,s,i.latest)});const C=a!==null?a:i.latest,[T,A]=c.useState(!1),y=c.useRef(null),[d,x]=c.useState(0),h=c.useRef(null),O=c.useRef(null);c.useLayoutEffect(()=>{const f=h.current;h.current=null,f!==null&&(r.whenUrlRendered(()=>o.announce(f.announcement)),O.current?.bringIntoView(f.doc))}),c.useEffect(()=>()=>{y.current!==null&&clearTimeout(y.current)},[]);const L=c.useCallback(()=>{y.current!==null&&clearTimeout(y.current),A(!0),y.current=setTimeout(()=>{y.current=null,A(!1)},ze)},[]),N=c.useCallback(()=>{y.current!==null&&clearTimeout(y.current),y.current=null,A(!1)},[]),R=c.useCallback(f=>{const M=r.titleOf(f),_=r.toggle(f);_==="rejected"&&L();const l=_==="rejected"?t.panelLimit(n.multiView.maxPanels):Wn(t,_,M);if(_==="shown"){h.current={doc:f,announcement:l},x(S=>S+1);return}r.whenUrlRendered(()=>{o.announce(l),_==="opened"&&O.current?.bringIntoView(f)})},[r,L,o,t,n]),u=c.useMemo(()=>new Set(s),[s]),p=c.useMemo(()=>{const f=He(s,a);return{href:j.explorerHref(n,{view:"tree",source:g,doc:f,markup:f!==null&&m.has(f)}),target:"tree"}},[n,g,s,a,m]);return k.jsx(re.ExplorerSplit,{view:"multi",explorer:k.jsx(re.ExplorerPane,{mode:"multi",sourceId:g,currentPath:C,openPaths:u,onOpenDocument:R,onSourceChange:r.changeSource,onRevealSource:r.revealSource,viewSwitch:p}),content:k.jsx(Yn,{ref:O,store:r,body:mn,limitNotice:T?t.panelLimit(n.multiView.maxPanels):null,onLimitNoticeCovered:N}),contentCoversPage:a!==null,sheetDismissals:d,onDraggingChange:r.setSplitDragging})};exports.MultiLayout=Kn;exports.PANEL_LIMIT_NOTICE_MS=ze;exports.latestOpenedDocument=le;exports.treeSwitchDocument=He;
@@ -1,9 +1,9 @@
1
1
  import { jsxs as ae, jsx as A } from "react/jsx-runtime";
2
2
  import { createContext as Je, use as Ae, useRef as q, useState as $, useLayoutEffect as F, useMemo as D, useSyncExternalStore as Ze, useCallback as R, memo as Qe, useEffect as U, useImperativeHandle as en } from "react";
3
3
  import { d as X } from "./describeValue-CLlVRO8d.js";
4
- import { s as ue, e as Me, u as nn, P as tn, v as on } from "./location-CJvL6JNs.js";
5
- import { U as rn, u as J, V as ln, W as sn, D as an, j as cn, g as un, X as V, L as dn, i as ke, Y as mn, N as fn, Z as Ie, _ as pn, $ as gn, a0 as Le, a1 as hn, a2 as Re, a3 as vn } from "./index-C52Nj37x.js";
6
- import { S as wn, a as yn, b as Sn } from "./ExplorerSplit-Dq7HfNre.js";
4
+ import { s as ue, e as Me, u as nn, P as tn, v as on } from "./location-T9o5XYpX.js";
5
+ import { U as rn, u as J, V as ln, W as sn, D as an, j as cn, g as un, X as V, L as dn, i as ke, Y as mn, N as fn, Z as Ie, _ as pn, $ as gn, a0 as Le, a1 as hn, a2 as Re, a3 as vn } from "./index-BBJoJu-b.js";
6
+ import { S as wn, a as yn, b as Sn } from "./ExplorerSplit-DHpgdXhb.js";
7
7
  import { SCROLL_AREA_SELECTOR as De, SCROLL_ROOT_SELECTOR as oe, PANEL_ACTION_ATTRIBUTE as ve, generateColumnIds as xn, sortColumnIds as _e, generateColumnId as ze, NO_PANEL_DRAG_ATTRIBUTE as En, useDragDropColumns as On, DEFAULT_DEBUG_CONFIG as we, DragDropLayout as Pn } from "@aiquants/drag-drop-panels";
8
8
  import { useNavigate as bn, useLocation as Cn } from "react-router";
9
9
  import { s as Tn, r as Nn, w as An } from "./storage-D1uSw-xj.js";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),T=require("@aiquants/virtualscroll"),S=require("react"),u=require("./index-_XNluAcx.cjs"),d=require("./tapScrollCircle-6etmzCb7.cjs"),v=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),m=(e,t)=>e.scrollTop===t.scrollTop&&e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight,g=e=>{let t=v(e);return{getSnapshot:()=>t,subscribe:s=>{const o=()=>{const a=v(e);m(t,a)||(t=a,s())};let n=0;const c=()=>{n===0&&(n=requestAnimationFrame(()=>{n=0,o()}))},r=typeof ResizeObserver>"u"?null:new ResizeObserver(c),l=()=>{if(r!==null){r.disconnect(),r.observe(e);for(const a of e.children)r.observe(a)}};l();const i=typeof MutationObserver>"u"?null:new MutationObserver(()=>{l(),c()});return i?.observe(e,{childList:!0}),e.addEventListener("scroll",o,{passive:!0}),o(),()=>{e.removeEventListener("scroll",o),i?.disconnect(),r?.disconnect(),cancelAnimationFrame(n)}}}},b=e=>{const t=S.useMemo(()=>g(e),[e]);return S.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)},h=(e,t)=>{const s=typeof t=="function"?t(e.scrollTop):t;return e.scrollTo({top:s,behavior:"instant"}),e.scrollTop},f=({scroller:e,kind:t})=>{const{locale:s}=u.useExplorer(),o=u.useCoarsePointer(),{scrollTop:n,scrollHeight:c,clientHeight:r}=b(e),l=S.useCallback(i=>h(e,i),[e]);return p.jsx("div",{className:"aqmx-native-scroll-bar",children:p.jsx(T.ScrollBar,{contentSize:c,viewportSize:r,scrollPosition:n,onScroll:l,scrollBarWidth:u.NATIVE_SCROLL_BAR_WIDTH,...u.scrollBarControlsFor(o),enableArrowButtonTabStops:!1,tapScrollCircleOptions:t==="content"?d.tapScrollCircleFor(o):d.NO_TAP_SCROLL_CIRCLE,locale:s})})};exports.NativeScrollBar=f;exports.scrollScrollerTo=h;exports.useScrollerMetrics=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),T=require("@aiquants/virtualscroll"),S=require("react"),u=require("./index-D6at9qMs.cjs"),d=require("./tapScrollCircle-ExxyHVWY.cjs"),v=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),m=(e,t)=>e.scrollTop===t.scrollTop&&e.scrollHeight===t.scrollHeight&&e.clientHeight===t.clientHeight,g=e=>{let t=v(e);return{getSnapshot:()=>t,subscribe:s=>{const o=()=>{const a=v(e);m(t,a)||(t=a,s())};let n=0;const c=()=>{n===0&&(n=requestAnimationFrame(()=>{n=0,o()}))},r=typeof ResizeObserver>"u"?null:new ResizeObserver(c),l=()=>{if(r!==null){r.disconnect(),r.observe(e);for(const a of e.children)r.observe(a)}};l();const i=typeof MutationObserver>"u"?null:new MutationObserver(()=>{l(),c()});return i?.observe(e,{childList:!0}),e.addEventListener("scroll",o,{passive:!0}),o(),()=>{e.removeEventListener("scroll",o),i?.disconnect(),r?.disconnect(),cancelAnimationFrame(n)}}}},b=e=>{const t=S.useMemo(()=>g(e),[e]);return S.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getSnapshot)},h=(e,t)=>{const s=typeof t=="function"?t(e.scrollTop):t;return e.scrollTo({top:s,behavior:"instant"}),e.scrollTop},f=({scroller:e,kind:t})=>{const{locale:s}=u.useExplorer(),o=u.useCoarsePointer(),{scrollTop:n,scrollHeight:c,clientHeight:r}=b(e),l=S.useCallback(i=>h(e,i),[e]);return p.jsx("div",{className:"aqmx-native-scroll-bar",children:p.jsx(T.ScrollBar,{contentSize:c,viewportSize:r,scrollPosition:n,onScroll:l,scrollBarWidth:u.NATIVE_SCROLL_BAR_WIDTH,...u.scrollBarControlsFor(o),enableArrowButtonTabStops:!1,tapScrollCircleOptions:t==="content"?d.tapScrollCircleFor(o):d.NO_TAP_SCROLL_CIRCLE,locale:s})})};exports.NativeScrollBar=f;exports.scrollScrollerTo=h;exports.useScrollerMetrics=b;
@@ -1,8 +1,8 @@
1
1
  import { jsx as u } from "react/jsx-runtime";
2
2
  import { ScrollBar as m } from "@aiquants/virtualscroll";
3
3
  import { useCallback as S, useMemo as d, useSyncExternalStore as h } from "react";
4
- import { u as b, c as v, N as f, s as T } from "./index-C52Nj37x.js";
5
- import { NO_TAP_SCROLL_CIRCLE as g, tapScrollCircleFor as H } from "./tapScrollCircle-D-Lgzdxx.js";
4
+ import { u as b, c as v, N as f, s as T } from "./index-BBJoJu-b.js";
5
+ import { NO_TAP_SCROLL_CIRCLE as g, tapScrollCircleFor as H } from "./tapScrollCircle-CvWJKtbF.js";
6
6
  const p = (e) => ({ scrollTop: e.scrollTop, scrollHeight: e.scrollHeight, clientHeight: e.clientHeight }), C = (e, t) => e.scrollTop === t.scrollTop && e.scrollHeight === t.scrollHeight && e.clientHeight === t.clientHeight, O = (e) => {
7
7
  let t = p(e);
8
8
  return {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),o=require("react"),H=require("react-router"),x=require("./location-DOIG84V9.cjs"),d=require("./index-_XNluAcx.cjs"),_=require("@aiquants/drag-drop-panels"),j=require("./ownUrls-BTPGNhBt.cjs"),k=require("./ExplorerSplit-13nPIuf0.cjs"),A=e=>{const{config:r,labels:n,announcer:t}=d.useExplorer(),i=d.useExplorerNavigate(),s=o.useCallback(()=>{const u=e.doc!==null?e.doc:e.folder;if(u===null)throw new RangeError("[markdown-explorer] a tree view without a document or a folder has nothing to maximize");i(x.explorerHref(r,{...e,maximized:!e.maximized}),"browse");const a=j.lastPathSegment(u);t.announce(e.maximized?n.documentRestored(a):n.documentMaximized(a))},[r,i,e,t,n]);return o.useMemo(()=>({maximized:e.maximized,toggle:s}),[e.maximized,s])},G=(e,r)=>{o.useEffect(()=>{if(!e)return;const n=t=>{_.isMaximizeEscape(t)&&(t.preventDefault(),r())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,r])},U=(e,r)=>e.claim!==r.claim||e.readme.status!==r.readme.status?!1:e.readme.status==="failed"&&r.readme.status==="failed"?e.readme.failure===r.readme.failure:e.readme.status==="ok"&&r.readme.status==="ok"?e.readme.readme===r.readme.readme:!0,B=(e,r,n)=>{let t=null;return()=>{const i=e.version(),s=e.read(r),u=s.status!=="pending";if(t!==null&&t.version===i&&t.tree===s&&t.settled===u)return t.state;const a=d.readFolderReadme(e,r,n),l=t!==null&&U(t.state,a)?t.state:a;return t={version:i,tree:s,settled:u,state:l},l}},Y=(e,r,n)=>{let t=!0,i=null;const s=()=>{t&&n()},u=()=>{const l=e.read(r);l===i||l.status!=="pending"||(i=l,l.then(s,s))};u();const a=e.subscribe(()=>{u(),n()});return()=>{t=!1,a()}},J=()=>d.FOLDER_README_LOADING,K=(e,r)=>{const{trees:n}=d.useExplorer(),t=o.useMemo(()=>r===null?null:B(n,e,r),[n,e,r]),i=o.useCallback(p=>t===null?()=>{}:Y(n,e,p),[t,n,e]),s=o.useCallback(()=>t===null?null:t(),[t]),u=o.useCallback(()=>t===null?null:J(),[t]),a=o.useSyncExternalStore(i,s,u),l=a?.claim===!0;return o.useEffect(()=>r===null?void 0:n.open(e),[n,e,r]),o.useEffect(()=>r===null||!l?void 0:n.claimChildren(e,new Map([[r,"direct"]])),[n,e,r,l]),a===null?null:a.readme},Q=new Set,V=Object.freeze({kind:"loading"}),W=(e,r)=>r.status==="loading"?V:r.status==="failed"?{kind:"failure",folder:e,failure:r.failure,onRetry:r.retry}:{kind:"no-readme",folder:e},X=({location:e,opening:r})=>{const{config:n}=d.useExplorer(),t=d.useExplorerNavigate(),{hash:i}=H.useLocation(),{source:s,doc:u,folder:a,overrides:l,markup:p,maximized:f}=e,[g,M]=o.useState(k.EMPTY_SELECTION),O=o.useMemo(()=>({gathered:g,onGatheredChange:M}),[g]),w=K(s,a),m=w===null?u:w.status==="ok"?w.readme:null,h=o.useMemo(()=>r!==null?r:a===null||w===null?d.NO_DOCUMENT:W(a,w),[r,a,w]),b=f&&(m!==null||h.kind==="loading"),R=o.useCallback(c=>t(x.explorerHref(n,{view:"tree",source:s,doc:c,overrides:l}),"browse"),[t,n,s,l]),D=o.useCallback(c=>t(x.explorerHref(n,{view:"tree",source:s,folder:c,overrides:l}),"browse"),[t,n,s,l]),N=o.useCallback(c=>{const E=c.kind==="folder"?{folder:c.path}:c.kind==="document"?{doc:c.path}:{};t(x.explorerHref(n,{view:"tree",source:s,...E,overrides:l}),"close-folder")},[t,n,s,l]),P=o.useCallback(c=>t(x.explorerHref(n,{view:"tree",source:c,doc:u,folder:a,overrides:l,markup:p,maximized:f}),"switch-source"),[t,n,u,a,l,p,f]),T=o.useCallback(c=>t(`${x.explorerHref(n,{view:"tree",source:c,doc:u,folder:a,overrides:l,markup:p,maximized:f})}${i}`,"browse"),[t,n,u,a,l,p,f,i]),q=o.useCallback(c=>{const E=x.canonicalMultiDocuments(n,c);t(x.explorerHref(n,{view:"multi",source:s,docs:E,markup:p&&m!==null&&E.includes(m)?[m]:[]}),"switch-view")},[t,n,s,m,p]),y=o.useMemo(()=>({href:x.explorerHref(n,m===null?{view:"multi",source:s}:{view:"multi",source:s,docs:[m],markup:p?[m]:[]}),target:"multi"}),[n,s,m,p]),S=o.useRef(f);o.useLayoutEffect(()=>{S.current=f},[f]);const C=o.useCallback(()=>S.current,[]),F=o.useMemo(()=>({kind:"page",view:"tree",overrides:l,embed:{},maximized:C}),[l,C]),L=d.usePageMarkupToggle(e),z=A(e);return G(b,z.toggle),v.jsx(k.ExplorerSplit,{view:"tree",contentCoversPage:b,explorer:v.jsx(k.ExplorerPane,{mode:"tree",sourceId:s,currentPath:a===null?u:a,openPaths:Q,onOpenDocument:R,onOpenFolder:D,onCloseFolder:N,currentFolder:a!==null,onSourceChange:P,onRevealSource:T,viewSwitch:y,tray:O,onOpenSelection:q}),content:v.jsxs("div",{className:"aqmx-document-column aqmx-tree-document","data-aqmx-maximized":b?"true":"false",...d.CONTENT_PANE,children:[m===null?null:v.jsx(d.DocumentRefreshBar,{path:m,placement:d.PAGE_DOCUMENT_REFRESH,markup:L,maximize:z}),v.jsx(d.DocumentPane,{path:m,absence:h,markup:p,variant:F})]})})};exports.TreeLayout=X;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),o=require("react"),H=require("react-router"),x=require("./location-DFXJSMit.cjs"),d=require("./index-D6at9qMs.cjs"),_=require("@aiquants/drag-drop-panels"),j=require("./ownUrls-BTPGNhBt.cjs"),k=require("./ExplorerSplit-DWBhCe7m.cjs"),A=e=>{const{config:r,labels:n,announcer:t}=d.useExplorer(),i=d.useExplorerNavigate(),s=o.useCallback(()=>{const u=e.doc!==null?e.doc:e.folder;if(u===null)throw new RangeError("[markdown-explorer] a tree view without a document or a folder has nothing to maximize");i(x.explorerHref(r,{...e,maximized:!e.maximized}),"browse");const a=j.lastPathSegment(u);t.announce(e.maximized?n.documentRestored(a):n.documentMaximized(a))},[r,i,e,t,n]);return o.useMemo(()=>({maximized:e.maximized,toggle:s}),[e.maximized,s])},G=(e,r)=>{o.useEffect(()=>{if(!e)return;const n=t=>{_.isMaximizeEscape(t)&&(t.preventDefault(),r())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[e,r])},U=(e,r)=>e.claim!==r.claim||e.readme.status!==r.readme.status?!1:e.readme.status==="failed"&&r.readme.status==="failed"?e.readme.failure===r.readme.failure:e.readme.status==="ok"&&r.readme.status==="ok"?e.readme.readme===r.readme.readme:!0,B=(e,r,n)=>{let t=null;return()=>{const i=e.version(),s=e.read(r),u=s.status!=="pending";if(t!==null&&t.version===i&&t.tree===s&&t.settled===u)return t.state;const a=d.readFolderReadme(e,r,n),l=t!==null&&U(t.state,a)?t.state:a;return t={version:i,tree:s,settled:u,state:l},l}},Y=(e,r,n)=>{let t=!0,i=null;const s=()=>{t&&n()},u=()=>{const l=e.read(r);l===i||l.status!=="pending"||(i=l,l.then(s,s))};u();const a=e.subscribe(()=>{u(),n()});return()=>{t=!1,a()}},J=()=>d.FOLDER_README_LOADING,K=(e,r)=>{const{trees:n}=d.useExplorer(),t=o.useMemo(()=>r===null?null:B(n,e,r),[n,e,r]),i=o.useCallback(p=>t===null?()=>{}:Y(n,e,p),[t,n,e]),s=o.useCallback(()=>t===null?null:t(),[t]),u=o.useCallback(()=>t===null?null:J(),[t]),a=o.useSyncExternalStore(i,s,u),l=a?.claim===!0;return o.useEffect(()=>r===null?void 0:n.open(e),[n,e,r]),o.useEffect(()=>r===null||!l?void 0:n.claimChildren(e,new Map([[r,"direct"]])),[n,e,r,l]),a===null?null:a.readme},Q=new Set,V=Object.freeze({kind:"loading"}),W=(e,r)=>r.status==="loading"?V:r.status==="failed"?{kind:"failure",folder:e,failure:r.failure,onRetry:r.retry}:{kind:"no-readme",folder:e},X=({location:e,opening:r})=>{const{config:n}=d.useExplorer(),t=d.useExplorerNavigate(),{hash:i}=H.useLocation(),{source:s,doc:u,folder:a,overrides:l,markup:p,maximized:f}=e,[g,M]=o.useState(k.EMPTY_SELECTION),O=o.useMemo(()=>({gathered:g,onGatheredChange:M}),[g]),w=K(s,a),m=w===null?u:w.status==="ok"?w.readme:null,h=o.useMemo(()=>r!==null?r:a===null||w===null?d.NO_DOCUMENT:W(a,w),[r,a,w]),b=f&&(m!==null||h.kind==="loading"),R=o.useCallback(c=>t(x.explorerHref(n,{view:"tree",source:s,doc:c,overrides:l}),"browse"),[t,n,s,l]),D=o.useCallback(c=>t(x.explorerHref(n,{view:"tree",source:s,folder:c,overrides:l}),"browse"),[t,n,s,l]),N=o.useCallback(c=>{const E=c.kind==="folder"?{folder:c.path}:c.kind==="document"?{doc:c.path}:{};t(x.explorerHref(n,{view:"tree",source:s,...E,overrides:l}),"close-folder")},[t,n,s,l]),P=o.useCallback(c=>t(x.explorerHref(n,{view:"tree",source:c,doc:u,folder:a,overrides:l,markup:p,maximized:f}),"switch-source"),[t,n,u,a,l,p,f]),T=o.useCallback(c=>t(`${x.explorerHref(n,{view:"tree",source:c,doc:u,folder:a,overrides:l,markup:p,maximized:f})}${i}`,"browse"),[t,n,u,a,l,p,f,i]),q=o.useCallback(c=>{const E=x.canonicalMultiDocuments(n,c);t(x.explorerHref(n,{view:"multi",source:s,docs:E,markup:p&&m!==null&&E.includes(m)?[m]:[]}),"switch-view")},[t,n,s,m,p]),y=o.useMemo(()=>({href:x.explorerHref(n,m===null?{view:"multi",source:s}:{view:"multi",source:s,docs:[m],markup:p?[m]:[]}),target:"multi"}),[n,s,m,p]),S=o.useRef(f);o.useLayoutEffect(()=>{S.current=f},[f]);const C=o.useCallback(()=>S.current,[]),F=o.useMemo(()=>({kind:"page",view:"tree",overrides:l,embed:{},maximized:C}),[l,C]),L=d.usePageMarkupToggle(e),z=A(e);return G(b,z.toggle),v.jsx(k.ExplorerSplit,{view:"tree",contentCoversPage:b,explorer:v.jsx(k.ExplorerPane,{mode:"tree",sourceId:s,currentPath:a===null?u:a,openPaths:Q,onOpenDocument:R,onOpenFolder:D,onCloseFolder:N,currentFolder:a!==null,onSourceChange:P,onRevealSource:T,viewSwitch:y,tray:O,onOpenSelection:q}),content:v.jsxs("div",{className:"aqmx-document-column aqmx-tree-document","data-aqmx-maximized":b?"true":"false",...d.CONTENT_PANE,children:[m===null?null:v.jsx(d.DocumentRefreshBar,{path:m,placement:d.PAGE_DOCUMENT_REFRESH,markup:L,maximize:z}),v.jsx(d.DocumentPane,{path:m,absence:h,markup:p,variant:F})]})})};exports.TreeLayout=X;
@@ -1,11 +1,11 @@
1
1
  import { jsx as h, jsxs as j } from "react/jsx-runtime";
2
2
  import { useCallback as d, useMemo as v, useEffect as g, useSyncExternalStore as q, useState as H, useRef as U, useLayoutEffect as $ } from "react";
3
3
  import { useLocation as B } from "react-router";
4
- import { e as f, c as Y } from "./location-CJvL6JNs.js";
5
- import { u as S, f as R, r as J, F as K, g as Q, h as V, i as W, D as X, P as Z, j as I } from "./index-C52Nj37x.js";
4
+ import { e as f, c as Y } from "./location-T9o5XYpX.js";
5
+ import { u as S, f as R, r as J, F as K, g as Q, h as V, i as W, D as X, P as Z, j as I } from "./index-BBJoJu-b.js";
6
6
  import { isMaximizeEscape as ee } from "@aiquants/drag-drop-panels";
7
7
  import { l as te } from "./ownUrls-DD0cSCsF.js";
8
- import { E as ne, a as re, b as se } from "./ExplorerSplit-Dq7HfNre.js";
8
+ import { E as ne, a as re, b as se } from "./ExplorerSplit-DHpgdXhb.js";
9
9
  const ae = (e) => {
10
10
  const { config: r, labels: n, announcer: t } = S(), c = R(), s = d(() => {
11
11
  const u = e.doc !== null ? e.doc : e.folder;
@@ -29,7 +29,6 @@ export declare const FIBONACCI_DURATIONS_MS: readonly [
29
29
  ];
30
30
  export declare const CONTROL_BLOCK_PIXELS = 44;
31
31
  export declare const COARSE_TARGET_PIXELS = 44;
32
- export declare const FINE_TARGET_PIXELS = 24;
33
32
  export declare const EXPLORER_BAR_PIXELS: number;
34
33
  export declare const PANEL_MAX_BLOCK_RATIO: number;
35
34
  export declare const PANEL_MIN_BLOCK_RATIO: number;