@aiquants/markdown-explorer 0.23.0 → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/README.md +66 -21
  3. package/dist/{EditSurface-Dhvw9IDD.js → EditSurface-CFXG8Qok.js} +333 -336
  4. package/dist/{EditSurface-Bk4tdJ99.cjs → EditSurface-CiKQiYSD.cjs} +5 -5
  5. package/dist/{ExplorerSplit-BAFiXU-V.cjs → ExplorerSplit-BWMVatnB.cjs} +1 -1
  6. package/dist/{ExplorerSplit-Q5VqUBDE.js → ExplorerSplit-DIkC3R7O.js} +81 -81
  7. package/dist/{MultiLayout-DlATT7km.js → MultiLayout-DXnuRzb4.js} +22 -22
  8. package/dist/{MultiLayout-Bq_TS3ez.cjs → MultiLayout-q_Pvwykp.cjs} +1 -1
  9. package/dist/{NativeScrollBar-A6-qEpz7.cjs → NativeScrollBar-UYBG64v1.cjs} +1 -1
  10. package/dist/{NativeScrollBar-TsIcS3JZ.js → NativeScrollBar-s_uSPPEd.js} +1 -1
  11. package/dist/{TreeLayout-zrSo4MNZ.js → TreeLayout-BQ1lWVf3.js} +3 -3
  12. package/dist/{TreeLayout-l-r2pPao.cjs → TreeLayout-Di0yv1E-.cjs} +1 -1
  13. package/dist/core/config.d.cts +13 -0
  14. package/dist/core/config.d.ts +13 -0
  15. package/dist/core/contracts.d.cts +22 -4
  16. package/dist/core/contracts.d.ts +22 -4
  17. package/dist/core/labels.d.cts +12 -0
  18. package/dist/core/labels.d.ts +12 -0
  19. package/dist/core/textEncoding.d.cts +4 -0
  20. package/dist/core/textEncoding.d.ts +4 -0
  21. package/dist/{dataRoute-Diu_7gle.js → dataRoute-BEvesOvN.js} +105 -97
  22. package/dist/dataRoute-Cv7fgCW7.cjs +1 -0
  23. package/dist/index-BhxsL0Sm.js +4097 -0
  24. package/dist/index-ZdsIXJap.cjs +13 -0
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.d.cts +2 -2
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.js +24 -23
  29. package/dist/location-CasigkBk.cjs +1 -0
  30. package/dist/location-gXXmC7CQ.js +643 -0
  31. package/dist/{merge-BzMpSaxx.js → merge-CQAXBfvi.js} +1 -1
  32. package/dist/{merge-DlPkU2Jc.cjs → merge-DkmrVEIc.cjs} +1 -1
  33. package/dist/{sanitizePolicy-Du3lFZd-.cjs → sanitizePolicy-CZwOaJ92.cjs} +1 -1
  34. package/dist/{sanitizePolicy-BvhYIqVO.js → sanitizePolicy-gVKBhabq.js} +1 -1
  35. package/dist/sanitizeWorker.cjs +1 -1
  36. package/dist/sanitizeWorker.js +1 -1
  37. package/dist/server/fileSystemSource.d.cts +1 -0
  38. package/dist/server/fileSystemSource.d.ts +1 -0
  39. package/dist/server/ports.d.cts +8 -1
  40. package/dist/server/ports.d.ts +8 -1
  41. package/dist/server.cjs +1 -1
  42. package/dist/server.d.cts +1 -0
  43. package/dist/server.d.ts +1 -0
  44. package/dist/server.js +783 -768
  45. package/dist/styles/markdown-explorer.css +1 -1
  46. package/dist/{useSplitPersistence-HfAb8Kzh.js → useSplitPersistence-BPNjvuJi.js} +1 -1
  47. package/dist/{useSplitPersistence-CR4Oxtaa.cjs → useSplitPersistence-Bmpb2prR.cjs} +1 -1
  48. package/docs/behavior/dom-hooks.md +13 -6
  49. package/docs/behavior/layout.md +22 -10
  50. package/docs/behavior/localization.md +10 -4
  51. package/docs/behavior/security.md +7 -4
  52. package/docs/behavior/url-contract.md +2 -2
  53. package/package.json +5 -5
  54. package/dist/dataRoute-vXGZMVB-.cjs +0 -1
  55. package/dist/index-BNFl3BsO.cjs +0 -13
  56. package/dist/index-Jz6zeO4O.js +0 -3703
  57. package/dist/location-8Ho8ZNv_.js +0 -499
  58. package/dist/location-DN0AI4ir.cjs +0 -1
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),h=require("react"),T=require("./index-BNFl3BsO.cjs"),J=require("@aiquants/markdown/code-blocks"),K=require("@codemirror/commands"),pe=require("@codemirror/lang-markdown"),oe=require("@codemirror/language"),ge=require("@codemirror/search"),$=require("@codemirror/state"),P=require("@codemirror/view"),V=require("@lezer/highlight"),He=require("@aiquants/markdown"),ue=require("@aiquants/markdown/source-lines"),ee=require("./dataRoute-vXGZMVB-.cjs"),de=require("./sanitizePolicy-Du3lFZd-.cjs"),ze=require("isomorphic-dompurify"),se=require("@aiquants/resize-panels"),X=require("./location-DN0AI4ir.cjs"),ve=require("./useSplitPersistence-CR4Oxtaa.cjs"),Ce={history:K.historyField},Fe=oe.HighlightStyle.define([{tag:[V.tags.heading1,V.tags.heading2,V.tags.heading3,V.tags.heading4,V.tags.heading5,V.tags.heading6,V.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:V.tags.strong,fontWeight:"700"},{tag:V.tags.emphasis,fontStyle:"italic"},{tag:V.tags.strikethrough,textDecoration:"line-through"},{tag:V.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:V.tags.url,color:"var(--aqmx-syntax-url)"},{tag:V.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:V.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[V.tags.processingInstruction,V.tags.contentSeparator,V.tags.labelName,V.tags.meta],color:"var(--aqmx-syntax-mark)"}]),Ue=P.EditorView.theme({"&":{height:"100%",color:"var(--aqmx-text)",backgroundColor:"var(--aqmx-surface)",fontSize:"var(--aqmx-font-size-title)"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',lineHeight:"var(--aqmx-line-height-prose)"},".cm-content":{caretColor:"var(--aqmx-text)",paddingBlock:"var(--aqmx-space-6)"},".cm-line":{paddingInline:"var(--aqmx-space-6)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--aqmx-text)"},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:"var(--aqmx-editor-selection)"},".cm-activeLine":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-gutters":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-editor-gutter)",borderInlineEnd:"var(--aqmx-space-1) solid var(--aqmx-border)"},".cm-activeLineGutter":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-searchMatch":{outline:"var(--aqmx-space-1) solid var(--aqmx-border-strong)"},".cm-panels":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-text)"}}),Me="data-aqmx-conflict-actions",Ge=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),We=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),Xe=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class $e extends P.WidgetType{constructor(t,n){super(),this.index=t,this.labels=n}index;labels;eq(t){return t.index===this.index&&t.labels===this.labels}toDOM(t){const n=document.createElement("div");n.setAttribute(Me,String(this.index));for(const[r,i]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const o=document.createElement("button");o.type="button",o.textContent=i,o.setAttribute("data-aqmx-conflict-choice",r),o.addEventListener("mousedown",l=>l.preventDefault()),o.addEventListener("click",()=>{const l=re(t.state.doc)[this.index];l!==void 0&&(_e(t,l,r),t.focus())}),n.append(o)}return n}ignoreEvent(){return!0}}const re=e=>T.findConflictsInLines(e.iterLines()),we=(e,t)=>{const n=new $.RangeSetBuilder;return re(e).forEach((r,i)=>{const o=e.line(r.start);n.add(o.from,o.from,P.Decoration.widget({widget:new $e(i,t),block:!0,side:-1}));for(let l=r.start;l<=r.end;l+=1){const s=e.line(l).from,f=l===r.start||l===r.separator||l===r.end?Ge:l<r.separator?We:Xe;n.add(s,s,f)}}),n.finish()},Ke=e=>$.StateField.define({create:t=>we(t.doc,e),update:(t,n)=>n.docChanged?we(n.state.doc,e):t,provide:t=>P.EditorView.decorations.from(t)}),_e=(e,t,n)=>{const{doc:r}=e.state,i=(k,c)=>{const E=[];for(let u=k;u<=c;u+=1)E.push(r.line(u).text);return E},o=i(t.start+1,t.separator-1),l=i(t.separator+1,t.end-1),s=n==="ours"?o:n==="theirs"?l:[...o,...l];let f=r.line(t.start).from,d=r.line(t.end).to;s.length===0&&(t.end<r.lines?d+=1:t.start>1&&(f-=1));const p=s.join(`
2
- `);e.dispatch({changes:{from:f,to:d,insert:p},selection:$.EditorSelection.cursor(f),scrollIntoView:!0,userEvent:"input.resolve"})},Ee="input.preview",Ye=20,Je=P.ViewPlugin.fromClass(class{constructor(e){this.view=e,this.schedule()}view;cancel=null;update(e){e.docChanged&&this.schedule()}schedule(){if(this.cancel!==null||oe.syntaxTreeAvailable(this.view.state))return;const e=this.view.dom.ownerDocument.defaultView;if(e===null)return;const t=()=>{this.cancel=null,oe.ensureSyntaxTree(this.view.state,this.view.state.doc.length,Ye),this.schedule()};if(typeof e.requestIdleCallback=="function"){const n=e.requestIdleCallback(t);this.cancel=()=>e.cancelIdleCallback(n)}else{const n=e.setTimeout(t,0);this.cancel=()=>e.clearTimeout(n)}}destroy(){this.cancel?.(),this.cancel=null}}),Qe=/`{3,}|~{3,}/u,te=Object.freeze({kind:"absent"}),ce=Object.freeze({kind:"unreadable"}),Ze=(e,t,n)=>{const r=[];for(let f=t.parent;f!==null;f=f.parent)(f.name==="Blockquote"||f.name==="ListItem")&&r.unshift(f);const i=[],o=[],l=f=>{const d=o.indexOf(f);return d===-1?o.length:d};for(const f of r){const d=e.lineAt(f.from).number;if(f.name==="ListItem"){const p=J.listItemWidthOn(e.line(d).text,i,l(d));if(p===null)return null;i.push({kind:"listItem",width:p})}else i.push({kind:"quote"});o.push(d)}const s=J.openingFenceOn(n.text,i,l(n.number));return s===null?null:{containers:i,...s}},et=(e,t)=>{const{doc:n}=e;let r=n.lineAt(t).to;for(;;){const i=oe.ensureSyntaxTree(e,r,Number.POSITIVE_INFINITY);if(i===null)return null;const o=i.resolveInner(t,1),l=o.parent;if(o.name!=="CodeMark"||l===null||l.name!=="FencedCode"||l.from!==o.from)return null;if(l.to<r||r>=n.length)return l;r=Math.min(n.length,l.to+Math.max(l.to-t,1))}},be=(e,t)=>{const{doc:n}=e;if(!Number.isInteger(t)||t<1||t>n.lines)return te;const r=n.line(t),i=Qe.exec(r.text);if(i===null)return te;const o=et(e,r.from+i.index);if(o===null)return te;const l=o.getChild("CodeInfo");if(l===null)return te;const s=J.fencedCodeLanguageOf(n.sliceString(l.from,l.to));if(s===null)return ce;if(s!==J.SPREADSHEETS_LANGUAGE)return te;const f=Ze(n,o,r);if(f===null)return ce;const[,...d]=o.getChildren("CodeMark"),p=d.at(-1),k=p===void 0?n.lineAt(o.to).number:n.lineAt(p.from).number-1,c=[];let E="";for(let u=t+1;u<=k;u+=1){const m=n.line(u).text,v=J.readFencedLine(m,f);if(v===null)return ce;c.push(m),E+=u<n.lines?`${v.content}
3
- `:v.content}return{kind:"found",firstLine:t+1,lines:c,layout:f,body:E}},tt=({parent:e,scroll:t,text:n,saved:r,labels:i,revisions:o,onChange:l,onGeometry:s,onSave:f})=>{let d=!1;const p=[P.EditorView.scrollHandler.of((u,m,v)=>(nt(u,m.head,v,t),!0)),P.lineNumbers(),P.highlightActiveLineGutter(),K.history(),P.drawSelection(),P.highlightActiveLine(),ge.highlightSelectionMatches(),P.EditorView.lineWrapping,pe.markdown({base:pe.markdownLanguage}),Je,oe.syntaxHighlighting(Fe),Ke(i),P.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(f(),!0)},...ge.searchKeymap,...K.historyKeymap,...K.defaultKeymap]),P.EditorView.contentAttributes.of({"aria-label":i.editor,"aria-multiline":"true"}),P.EditorView.updateListener.of(u=>{for(const m of u.transactions)m.docChanged&&o.record(m.changes,m.newDoc);u.docChanged&&l(u.transactions.every(m=>!m.docChanged||m.isUserEvent(Ee))),(u.docChanged||u.heightChanged||u.geometryChanged)&&s(u.docChanged&&!d)}),Ue],k=st(r,p)??$.EditorState.create({doc:n,extensions:p}),c=new P.EditorView({state:k,parent:e});o.mount(c.state.doc);const E=u=>{d=!0;try{u()}finally{d=!1}};return{text:()=>c.state.doc.toString(),replaceText:u=>{const m=c.state.doc.toString();if(m===u)return;let v=0;const S=Math.min(m.length,u.length);for(;v<S&&m.charCodeAt(v)===u.charCodeAt(v);)v+=1;let g=0;for(;g<S-v&&m.charCodeAt(m.length-1-g)===u.charCodeAt(u.length-1-g);)g+=1;c.dispatch({changes:{from:v,to:m.length-g,insert:u.slice(v,u.length-g)},userEvent:"input.replace"})},replaceBody:(u,m,v,S)=>{const{doc:g}=c.state,L=o.lineOf(S,u);if(L===null)return"changed";const O=be(c.state,L);if(O.kind==="absent")return"changed";if(O.kind==="unreadable")return"unwritable";if(O.body!==J.fencedBodyAsRead(m,O.layout))return"changed";const I=J.planFencedBodyEdit(O.lines,O.layout,v);if(I.kind!=="edit")return I.kind;if(I.from===I.to&&I.lines.length===0)return"written";const D=H=>{const j=O.firstLine+H;return j<=g.lines?g.line(j).from:g.length},M=D(I.from),B=`${M===g.length&&g.sliceString(g.length-1)!==`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),h=require("react"),y=require("./index-ZdsIXJap.cjs"),J=require("@aiquants/markdown/code-blocks"),K=require("@codemirror/commands"),pe=require("@codemirror/lang-markdown"),oe=require("@codemirror/language"),ge=require("@codemirror/search"),$=require("@codemirror/state"),P=require("@codemirror/view"),V=require("@lezer/highlight"),je=require("@aiquants/markdown"),ue=require("@aiquants/markdown/source-lines"),ee=require("./dataRoute-Cv7fgCW7.cjs"),de=require("./sanitizePolicy-CZwOaJ92.cjs"),ze=require("isomorphic-dompurify"),se=require("@aiquants/resize-panels"),X=require("./location-CasigkBk.cjs"),ve=require("./useSplitPersistence-Bmpb2prR.cjs"),qe={history:K.historyField},Fe=oe.HighlightStyle.define([{tag:[V.tags.heading1,V.tags.heading2,V.tags.heading3,V.tags.heading4,V.tags.heading5,V.tags.heading6,V.tags.heading],color:"var(--aqmx-syntax-heading)",fontWeight:"700"},{tag:V.tags.strong,fontWeight:"700"},{tag:V.tags.emphasis,fontStyle:"italic"},{tag:V.tags.strikethrough,textDecoration:"line-through"},{tag:V.tags.link,color:"var(--aqmx-syntax-link)",textDecoration:"underline"},{tag:V.tags.url,color:"var(--aqmx-syntax-url)"},{tag:V.tags.monospace,color:"var(--aqmx-syntax-code)"},{tag:V.tags.quote,color:"var(--aqmx-syntax-quote)"},{tag:[V.tags.processingInstruction,V.tags.contentSeparator,V.tags.labelName,V.tags.meta],color:"var(--aqmx-syntax-mark)"}]),Ue=P.EditorView.theme({"&":{height:"100%",color:"var(--aqmx-text)",backgroundColor:"var(--aqmx-surface)",fontSize:"var(--aqmx-font-size-title)"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace',lineHeight:"var(--aqmx-line-height-prose)"},".cm-content":{caretColor:"var(--aqmx-text)",paddingBlock:"var(--aqmx-space-6)"},".cm-line":{paddingInline:"var(--aqmx-space-6)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--aqmx-text)"},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:"var(--aqmx-editor-selection)"},".cm-activeLine":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-gutters":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-editor-gutter)",borderInlineEnd:"var(--aqmx-space-1) solid var(--aqmx-border)"},".cm-activeLineGutter":{backgroundColor:"var(--aqmx-editor-active-line)"},".cm-searchMatch":{outline:"var(--aqmx-space-1) solid var(--aqmx-border-strong)"},".cm-panels":{backgroundColor:"var(--aqmx-surface-raised)",color:"var(--aqmx-text)"}}),Me="data-aqmx-conflict-actions",Ge=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"marker"}}),We=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"ours"}}),Xe=P.Decoration.line({attributes:{"data-aqmx-conflict-line":"theirs"}});class $e extends P.WidgetType{constructor(t,n){super(),this.index=t,this.labels=n}index;labels;eq(t){return t.index===this.index&&t.labels===this.labels}toDOM(t){const n=document.createElement("div");n.setAttribute(Me,String(this.index));for(const[r,i]of[["ours",this.labels.useOurs],["theirs",this.labels.useTheirs],["both",this.labels.keepBoth]]){const o=document.createElement("button");o.type="button",o.textContent=i,o.setAttribute("data-aqmx-conflict-choice",r),o.addEventListener("mousedown",l=>l.preventDefault()),o.addEventListener("click",()=>{const l=re(t.state.doc)[this.index];l!==void 0&&(_e(t,l,r),t.focus())}),n.append(o)}return n}ignoreEvent(){return!0}}const re=e=>y.findConflictsInLines(e.iterLines()),we=(e,t)=>{const n=new $.RangeSetBuilder;return re(e).forEach((r,i)=>{const o=e.line(r.start);n.add(o.from,o.from,P.Decoration.widget({widget:new $e(i,t),block:!0,side:-1}));for(let l=r.start;l<=r.end;l+=1){const s=e.line(l).from,d=l===r.start||l===r.separator||l===r.end?Ge:l<r.separator?We:Xe;n.add(s,s,d)}}),n.finish()},Ke=e=>$.StateField.define({create:t=>we(t.doc,e),update:(t,n)=>n.docChanged?we(n.state.doc,e):t,provide:t=>P.EditorView.decorations.from(t)}),_e=(e,t,n)=>{const{doc:r}=e.state,i=(k,c)=>{const E=[];for(let u=k;u<=c;u+=1)E.push(r.line(u).text);return E},o=i(t.start+1,t.separator-1),l=i(t.separator+1,t.end-1),s=n==="ours"?o:n==="theirs"?l:[...o,...l];let d=r.line(t.start).from,f=r.line(t.end).to;s.length===0&&(t.end<r.lines?f+=1:t.start>1&&(d-=1));const p=s.join(`
2
+ `);e.dispatch({changes:{from:d,to:f,insert:p},selection:$.EditorSelection.cursor(d),scrollIntoView:!0,userEvent:"input.resolve"})},Ee="input.preview",Ye=20,Je=P.ViewPlugin.fromClass(class{constructor(e){this.view=e,this.schedule()}view;cancel=null;update(e){e.docChanged&&this.schedule()}schedule(){if(this.cancel!==null||oe.syntaxTreeAvailable(this.view.state))return;const e=this.view.dom.ownerDocument.defaultView;if(e===null)return;const t=()=>{this.cancel=null,oe.ensureSyntaxTree(this.view.state,this.view.state.doc.length,Ye),this.schedule()};if(typeof e.requestIdleCallback=="function"){const n=e.requestIdleCallback(t);this.cancel=()=>e.cancelIdleCallback(n)}else{const n=e.setTimeout(t,0);this.cancel=()=>e.clearTimeout(n)}}destroy(){this.cancel?.(),this.cancel=null}}),Qe=/`{3,}|~{3,}/u,te=Object.freeze({kind:"absent"}),ce=Object.freeze({kind:"unreadable"}),Ze=(e,t,n)=>{const r=[];for(let d=t.parent;d!==null;d=d.parent)(d.name==="Blockquote"||d.name==="ListItem")&&r.unshift(d);const i=[],o=[],l=d=>{const f=o.indexOf(d);return f===-1?o.length:f};for(const d of r){const f=e.lineAt(d.from).number;if(d.name==="ListItem"){const p=J.listItemWidthOn(e.line(f).text,i,l(f));if(p===null)return null;i.push({kind:"listItem",width:p})}else i.push({kind:"quote"});o.push(f)}const s=J.openingFenceOn(n.text,i,l(n.number));return s===null?null:{containers:i,...s}},et=(e,t)=>{const{doc:n}=e;let r=n.lineAt(t).to;for(;;){const i=oe.ensureSyntaxTree(e,r,Number.POSITIVE_INFINITY);if(i===null)return null;const o=i.resolveInner(t,1),l=o.parent;if(o.name!=="CodeMark"||l===null||l.name!=="FencedCode"||l.from!==o.from)return null;if(l.to<r||r>=n.length)return l;r=Math.min(n.length,l.to+Math.max(l.to-t,1))}},be=(e,t)=>{const{doc:n}=e;if(!Number.isInteger(t)||t<1||t>n.lines)return te;const r=n.line(t),i=Qe.exec(r.text);if(i===null)return te;const o=et(e,r.from+i.index);if(o===null)return te;const l=o.getChild("CodeInfo");if(l===null)return te;const s=J.fencedCodeLanguageOf(n.sliceString(l.from,l.to));if(s===null)return ce;if(s!==J.SPREADSHEETS_LANGUAGE)return te;const d=Ze(n,o,r);if(d===null)return ce;const[,...f]=o.getChildren("CodeMark"),p=f.at(-1),k=p===void 0?n.lineAt(o.to).number:n.lineAt(p.from).number-1,c=[];let E="";for(let u=t+1;u<=k;u+=1){const m=n.line(u).text,v=J.readFencedLine(m,d);if(v===null)return ce;c.push(m),E+=u<n.lines?`${v.content}
3
+ `:v.content}return{kind:"found",firstLine:t+1,lines:c,layout:d,body:E}},tt=({parent:e,scroll:t,text:n,saved:r,labels:i,revisions:o,onChange:l,onGeometry:s,onSave:d})=>{let f=!1;const p=[P.EditorView.scrollHandler.of((u,m,v)=>(nt(u,m.head,v,t),!0)),P.lineNumbers(),P.highlightActiveLineGutter(),K.history(),P.drawSelection(),P.highlightActiveLine(),ge.highlightSelectionMatches(),P.EditorView.lineWrapping,pe.markdown({base:pe.markdownLanguage}),Je,oe.syntaxHighlighting(Fe),Ke(i),P.keymap.of([{key:"Mod-s",preventDefault:!0,run:()=>(d(),!0)},...ge.searchKeymap,...K.historyKeymap,...K.defaultKeymap]),P.EditorView.contentAttributes.of({"aria-label":i.editor,"aria-multiline":"true"}),P.EditorView.updateListener.of(u=>{for(const m of u.transactions)m.docChanged&&o.record(m.changes,m.newDoc);u.docChanged&&l(u.transactions.every(m=>!m.docChanged||m.isUserEvent(Ee))),(u.docChanged||u.heightChanged||u.geometryChanged)&&s(u.docChanged&&!f)}),Ue],k=st(r,p)??$.EditorState.create({doc:n,extensions:p}),c=new P.EditorView({state:k,parent:e});o.mount(c.state.doc);const E=u=>{f=!0;try{u()}finally{f=!1}};return{text:()=>c.state.doc.toString(),replaceText:u=>{const m=c.state.doc.toString();if(m===u)return;let v=0;const S=Math.min(m.length,u.length);for(;v<S&&m.charCodeAt(v)===u.charCodeAt(v);)v+=1;let g=0;for(;g<S-v&&m.charCodeAt(m.length-1-g)===u.charCodeAt(u.length-1-g);)g+=1;c.dispatch({changes:{from:v,to:m.length-g,insert:u.slice(v,u.length-g)},userEvent:"input.replace"})},replaceBody:(u,m,v,S)=>{const{doc:g}=c.state,L=o.lineOf(S,u);if(L===null)return"changed";const O=be(c.state,L);if(O.kind==="absent")return"changed";if(O.kind==="unreadable")return"unwritable";if(O.body!==J.fencedBodyAsRead(m,O.layout))return"changed";const I=J.planFencedBodyEdit(O.lines,O.layout,v);if(I.kind!=="edit")return I.kind;if(I.from===I.to&&I.lines.length===0)return"written";const D=j=>{const H=O.firstLine+j;return H<=g.lines?g.line(H).from:g.length},M=D(I.from),B=`${M===g.length&&g.sliceString(g.length-1)!==`
4
4
  `?`
5
- `:""}${I.lines.map(H=>`${H}
6
- `).join("")}`;return E(()=>c.dispatch({changes:{from:M,to:D(I.to),insert:B},userEvent:Ee,annotations:K.isolateHistory.of("full")})),"written"},readBody:(u,m)=>{const v=o.lineOf(m,u);if(v===null)return null;const S=be(c.state,v);return S.kind==="found"?S.body:null},undo:()=>E(()=>K.undo(c)),redo:()=>E(()=>K.redo(c)),reveal:({line:u,column:m},v)=>{const{doc:S}=c.state,g=S.line(Math.min(Math.max(u,1),S.lines)),L=Math.min(g.from+m,g.to);c.dispatch({selection:$.EditorSelection.cursor(L),effects:xe(c,L,v,t)})},showLine:u=>{const{doc:m}=c.state,v=m.line(Math.min(Math.max(u,1),m.lines)).from;c.dispatch({effects:xe(c,v,null,t)})},topLine:()=>{const u=t.scrollerOf(c.scrollDOM),m=T.visibleTopOf(u,c.contentDOM),v=T.frameTopOf(u)+u.clientHeight,{documentTop:S}=c,{doc:g}=c.state;let L=c.lineBlockAtHeight(Math.max(m-S,0));for(;g.lineAt(L.from).text.trim()===""&&L.to<g.length;){const D=c.lineBlockAt(L.to+1);if(S+D.top>=v)break;L=D}const O=c.coordsAtPos(L.from),I=O===null?S+L.top:O.top;return{line:c.state.doc.lineAt(L.from).number,clientTop:I,offset:I-m}},lineSpans:u=>{const m=c.scrollDOM,v=m.scrollTop+c.documentTop-T.visibleTopOf(m,c.contentDOM),{doc:S}=c.state,g=L=>S.line(Math.min(Math.max(L,1),S.lines)).from;return u.map(({first:L,last:O})=>({top:v+c.lineBlockAt(g(L)).top,bottom:v+c.lineBlockAt(g(O)).bottom}))},scrollElement:c.scrollDOM,focus:()=>c.focus(),conflicts:()=>re(c.state.doc),resolveAtCursor:u=>{const m=re(c.state.doc),v=c.state.doc.lineAt(c.state.selection.main.head).number,S=m.find(g=>g.end>=v);return S===void 0?!1:(_e(c,S,u),!0)},nextConflict:()=>{const u=re(c.state.doc);if(u[0]===void 0)return!1;const v=c.state.doc.lineAt(c.state.selection.main.head).number,S=u.findIndex(I=>I.start>v),g=S<0?0:S,L=c.state.doc.line(u[g].start).from;c.dispatch({selection:$.EditorSelection.cursor(L),effects:P.EditorView.scrollIntoView(L,{y:"center"})});const O=c.contentDOM.querySelector(`[${Me}="${String(g)}"] button`);return O instanceof HTMLElement?O.focus({preventScroll:!0}):c.focus(),!0},save:()=>c.state.toJSON(Ce),destroy:()=>c.destroy()}},xe=(e,t,n,r)=>{const i=r.scrollerOf(e.scrollDOM),o=(n===null?T.visibleTopOf(i,e.contentDOM):n)-T.frameTopOf(i);return P.EditorView.scrollIntoView(t,{y:"start",yMargin:o})},nt=(e,t,n,r)=>{const i=rt(e,t),o=r.scrollerOf(e.scrollDOM),l=T.frameTopOf(o),s=T.visibleTopOf(o,e.contentDOM),f=l+o.clientHeight;let d=0;switch(n.y){case"start":d=i.top-(l+n.yMargin);break;case"center":d=(i.top+i.bottom)/2-(s+f)/2;break;case"end":d=i.bottom-(f-n.yMargin);break;default:i.top<s+n.yMargin?d=i.top-(s+n.yMargin):i.bottom>f-n.yMargin&&(d=Math.min(i.bottom-(f-n.yMargin),i.top-(s+n.yMargin)))}if(d!==0&&(o.scrollTop+=d),n.y==="start")return;const p=ot(e,t);p!==null&&r.reveal(p)},rt=(e,t)=>{const{node:n,offset:r}=e.domAtPos(t);if(n.nodeType===Node.TEXT_NODE){const l=n.ownerDocument?.createRange();if(l!==void 0){l.setStart(n,r),l.setEnd(n,r);const[s]=l.getClientRects();if(s!==void 0&&s.height>0)return{top:s.top,bottom:s.bottom}}}const i=e.lineBlockAt(t),o=e.documentTop+i.top;return{top:o,bottom:o+i.height}},ot=(e,t)=>{const{node:n}=e.domAtPos(t);for(let r=n instanceof Element?n:n.parentElement;r!==null;r=r.parentElement)if(r.parentElement===e.contentDOM)return r;return null},st=(e,t)=>{if(e==null)return null;try{return $.EditorState.fromJSON(e,{extensions:t},Ce)}catch{return null}},it=610,lt=987,Se=Object.freeze({kind:"unavailable"}),ct="true",at="false",ut=e=>e===ct?!0:e===at?!1:null,dt=e=>{const t=new DOMParser().parseFromString(e,"text/html"),n=[];for(const r of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")){const i=r.localName==="img",o=r.getAttribute(i?"data-asset-src":"data-doc-path");o!==null&&n.push({target:{kind:i?"asset":"doc",path:o},exists:ut(r.getAttribute(i?"data-asset-exists":"data-doc-exists"))})}return n},ft=({path:e,instant:t,preview:n,initial:r,onView:i})=>{const o=new AbortController,l={asset:new Map,doc:new Map};let s=r,f=null,d=!1,p=!1,k=null,c=null,E=[],u,m=!1,v,S=null;const g=w=>{w.parsed===s.parsed&&w.source===s.source&&w.failure===s.failure&&w.busy===s.busy&&w.tier===s.tier||(s=w,i(w))},L=(w,y)=>{d||(d=!0,console.error(`[markdown-explorer] ${w}`,...y===void 0?[]:[y]))},O=w=>{if(t!==null)for(const{target:y,exists:C}of t.marksOf(w))l[y.kind].set(y.path,C)},I=()=>{clearTimeout(v),v=void 0,S?.abort(),S=null},D=()=>{c=null,E=[],clearTimeout(u),u=void 0},M=(w,y)=>{g({...s,failure:w,busy:!1,tier:y})},F=()=>{clearTimeout(u),u=E.length===0?void 0:setTimeout(H,lt)},B=()=>{if(t===null||c===null)return;const w=c,y=[],C={asset:new Set,doc:new Set};let U;try{U=t.sanitize(w.html,x=>{const _=l[x.kind].get(x.path);return _===void 0&&!C[x.kind].has(x.path)&&(C[x.kind].add(x.path),y.push(x)),_??void 0})}catch(x){D(),x instanceof de.HtmlNestingLimitError?M(ee.failureOf("too-large"),"instant"):(L("the draft sanitizer failed",x),M(ee.failureOf("failed"),"instant"));return}E=y;const b=s.parsed!==null&&s.parsed.htmlContent===U&&s.parsed.headings===w.headings?s.parsed:{htmlContent:U,headings:w.headings};g({parsed:b,source:w.draft,failure:null,busy:!1,tier:"instant"}),F()},H=()=>{if(u=void 0,m||c===null||E.length===0)return;m=!0;const w=E;n(e,c.draft.text,o.signal).then(y=>{if(m=!1,!(o.signal.aborted||!("kind"in y))){y.kind==="preview"&&O(y.htmlContent);for(const C of w)l[C.kind].has(C.path)||l[C.kind].set(C.path,null);B()}})},j=w=>{I(),D(),g({...s,busy:!0,tier:"server"});const y=new AbortController;S=y,v=setTimeout(()=>{v=void 0,n(e,w.text,y.signal).then(C=>{if(!(y.signal.aborted||!("kind"in C))){if(S=null,C.kind==="failure"){M(C.failure,"server");return}O(C.htmlContent),g({parsed:{htmlContent:C.htmlContent,headings:C.headings},source:w,failure:null,busy:!1,tier:"server"})}})},it)},a=async(w,y)=>{let C;try{C=await w.convert({path:e,text:y},o.signal)}catch(b){return o.signal.aborted||L("the draft converter rejected a conversion, which its contract allows only once the signal aborted",b),Se}const U=ee.draftAnswerViolation(C);return U===null?C:(L(`the draft converter answered outside its contract: ${U}`),Se)},A=(w,y)=>{switch(y.kind){case"preview":if(I(),y.headings.length>ee.EXPLORER_MAX_HEADINGS){D(),M(ee.failureOf("too-large"),"instant");return}c={draft:w,html:y.htmlContent,headings:y.headings.map(({text:C,depth:U,id:b})=>({text:C,depth:U,id:b}))},B();return;case"failure":I(),D(),M(ee.failureOf(y.failure.reason,y.failure.code),"instant");return;case"unavailable":j(w);return}},R=async w=>{p=!0;try{for(;k!==null&&!o.signal.aborted;){const y=k;k=null;const C=await a(w,y.text);if(o.signal.aborted)return;A(y,C)}}finally{p=!1}};return t!==null&&t.seed!==null&&O(t.seed),{update:w=>{if(!(o.signal.aborted||w.text===f?.text)){if(f=w,clearTimeout(u),u=void 0,t===null){j(w);return}k=w,p||R(t.converter)}},dispose:()=>{o.abort(),k=null,clearTimeout(u),u=void 0,I()}}},mt=(e,t)=>de.createHtmlSanitizer(ze(window),e,t,de.MAX_HTML_NESTING_DEPTH),ht=(e,t)=>e.flatMap((n,r)=>{const i=t[r];return i===void 0?[]:[{editor:i.top,preview:n.top},{editor:i.bottom,preview:n.bottom}]}),Y=(e,t)=>{const n=e[t];if(n===void 0)throw new RangeError(`[markdown-explorer] a scroll map index must be in 0..${String(e.length-1)}; got ${String(t)}`);return n},pt=e=>{const t=[];for(const r of e){let i=0,o=t.length;for(;i<o;){const l=i+o>>1;Y(t,l).pair.preview<=r.preview?i=l+1:o=l}t[i]={pair:r,before:i===0?void 0:Y(t,i-1)}}const n=[];for(let r=t.at(-1);r!==void 0;r=r.before)n.push(r.pair);return n.reverse()},gt=(e,t)=>{const n=Math.max(t.editorMax,0),r=Math.max(t.previewMax,0),i=n-t.editorViewport,o=r-t.previewViewport,l=e.filter(d=>d.editor>0&&d.editor<i&&d.preview>0&&d.preview<o).sort((d,p)=>d.editor-p.editor||d.preview-p.preview);let s={editor:0,preview:0};const f=[s];for(const d of pt(l))d.editor>s.editor&&d.preview>s.preview&&(f.push(d),s=d);return f.push({editor:n,preview:r}),{toPreview:d=>ye(f,"editor","preview",d),toEditor:d=>ye(f,"preview","editor",d)}},ye=(e,t,n,r)=>{const i=Y(e,0),o=Y(e,e.length-1);if(Number.isNaN(r)||r<=i[t])return i[n];if(r>=o[t])return o[n];let l=0,s=e.length-1;for(;s-l>1;){const p=l+s>>1;Y(e,p)[t]<=r?l=p:s=p}const f=Y(e,l),d=Y(e,s);return f[n]+(d[n]-f[n])*(r-f[t])/(d[t]-f[t])},vt=610,Te=89,ke=.5,wt=({editor:e,preview:t,previewBlocks:n,editorSpans:r,requestFrame:i,cancelFrame:o,now:l})=>{let s="editor",f=0,d=null,p=null,k=!1,c=null,E=null;const u={editor:0,preview:0},m={editor:null,preview:null};let v=null,S=()=>{};const g=a=>{d!==null&&a!==d||(s=a,f=l()+vt)},L=(a,A)=>{a!==s&&d===null&&l()>=f&&!O(a,A)&&(s=a),B()},O=(a,A)=>{const R=m[a];return l()<u[a]||R!==null&&Math.abs(A.position()-R)<ke},I=e.onScroll(()=>L("editor",e)),D=e.onIntent(()=>g("editor")),M=()=>{const a=t();return a!==v&&(S(),v=a,S=a===null?()=>{}:F(a)),a},F=a=>{const A=a.onScroll(()=>L("preview",a)),R=a.onIntent(()=>g("preview"));return()=>{A(),R()}},B=()=>{!k&&p===null&&(p=i(H))},H=()=>{p=null;const a=M();a!==null&&(c??=n(),E??=gt(ht(c,r(c)),{editorMax:e.max(),previewMax:a.max(),editorViewport:e.viewport(),previewViewport:a.viewport()}),s==="editor"?j(a,"preview",E.toPreview(e.position())):j(e,"editor",E.toEditor(a.position())))},j=(a,A,R)=>{if(Math.abs(a.position()-R)<ke){m[A]=a.position();return}u[A]=l()+Te,m[A]=a.scrollTo(R)};return B(),{editorChanged:a=>{E=null,a&&g("editor"),B()},previewChanged:()=>{c=null,E=null,u.preview=l()+Te,B()},showAlone:a=>{d=a,!(a===null||a===s)&&(s=a,f=0,B())},dispose:()=>{k=!0,p!==null&&o(p),p=null,I(),D(),S()}}},Le=Object.freeze(["wheel","pointerdown","keydown","focusin"]),Pe=e=>({position:()=>e.scrollTop,max:()=>Math.max(e.scrollHeight-e.clientHeight,0),viewport:()=>e.clientHeight,scrollTo:t=>(e.scrollTo({top:t,behavior:"instant"}),e.scrollTop),onScroll:t=>(e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)),onIntent:t=>{for(const n of Le)e.addEventListener(n,t,{capture:!0,passive:!0});return()=>{for(const n of Le)e.removeEventListener(n,t,{capture:!0})}}}),ne="[data-aqmd-scroll-container]",Et="[data-aqmd-content]",bt=`[${ue.SOURCE_LINES_ATTRIBUTE}]`,xt=Object.freeze(["p1","p2","p3","p4","p5","p6","p7","p8"]),Ne=(e,t)=>{const n=T.loadedOf(e.peek(t));return n!==null&&n.document.kind==="markdown"?{htmlContent:n.document.htmlContent,headings:n.document.headings}:null},St=(e,t,n,r,i)=>{if(n===void 0)return null;let o;try{o=mt(e,t)}catch(l){return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview",l),null}return{converter:n,sanitize:o,marksOf:dt,seed:Ne(r,i)?.htmlContent??null}},yt=e=>{const t=[];let n=null;for(const r of e.querySelectorAll(bt)){const i=ue.parseSourceLines(r.getAttribute(ue.SOURCE_LINES_ATTRIBUTE));if(i===null||r.getClientRects().length===0)continue;n??=e.scrollTop-T.visibleTopOf(e,r);const{top:o,bottom:l}=r.getBoundingClientRect();t.push({first:i.first,last:i.last,top:n+o,bottom:n+l})}return t},Tt=({path:e,readDraft:t,viewer:n,tables:r,concealed:i,onEditAt:o,onLayout:l,handleRef:s})=>{const{config:f,data:d,documents:p,draftConverter:k,labels:c}=T.useExplorer(),[E,u]=h.useState(()=>({parsed:Ne(p,e),source:null,failure:null,busy:!0,tier:k===void 0?"server":"instant"})),m=h.useRef(null),v=h.useRef(null),S=h.useRef(E);h.useLayoutEffect(()=>{S.current=E});const g=h.useEffectEvent(()=>t());h.useEffect(()=>{const a=St(f.iframeHosts,f.dataPath,k,p,e),A=g(),R=ft({path:e,instant:a,preview:d.preview,initial:S.current,onView:w=>h.startTransition(()=>u(w))});return v.current=R,R.update(A),()=>{R.dispose(),v.current=null}},[f,d,p,k,e]);const L=h.useEffectEvent(()=>l());h.useLayoutEffect(()=>{E.parsed!==null&&L()},[E.parsed]);const O=E.parsed!==null;h.useLayoutEffect(()=>{const a=O?m.current?.querySelector(ne):null;if(!(a instanceof HTMLElement))return;a.tabIndex=0;const A=new ResizeObserver(()=>L());A.observe(a);const R=a.querySelector(Et);return R!==null&&A.observe(R),()=>A.disconnect()},[O]);const I=h.useRef(null);h.useImperativeHandle(s,()=>({draft:a=>{v.current?.update(a)},scrollPort:()=>{const a=m.current?.querySelector(ne);return a instanceof HTMLElement?(I.current?.scroller!==a&&(I.current={scroller:a,port:Pe(a)}),I.current.port):null},blocks:()=>{const a=m.current?.querySelector(ne);return a instanceof HTMLElement?yt(a):[]},focus:()=>{const a=m.current?.querySelector(ne);a instanceof HTMLElement&&a.focus({preventScroll:!0})},anchor:a=>{const A=m.current,R=A?.querySelector(ne);return A===null||!(R instanceof HTMLElement)?null:T.anchorOfView(A,a(R))},place:({line:a,clientTop:A},R)=>{const w=m.current,y=w===null?null:T.blockAtLine(w,a);y!==null&&(R(y).scrollTop+=T.lineTopIn(y,a)-A)}}),[]);const D=a=>{const A=m.current,{target:R}=a;if(o===void 0||A===null||!(R instanceof Element)||!T.isEditingDoubleClick(R))return;const w=T.anchorOfDoubleClick(R,A,A.ownerDocument.getSelection());w!==null&&o(w)},M=E.source===null?null:E.source.revision,F=h.useMemo(()=>M===null?void 0:{write:a=>r.write(M,a),read:a=>r.read(M,a),undo:r.undo,redo:r.redo,subscribe:r.subscribe},[r,M]),B=h.useMemo(()=>({...n.labels,spreadsheetReadOnly:c.previewTablePending}),[n.labels,c.previewTablePending]),H=h.useMemo(()=>({...n,labels:F===void 0?B:n.labels,showToc:!1,showStyle:!1,showAlign:!1,renderScrollBar:void 0,spreadsheetEditor:F}),[n,B,F]),j=h.useMemo(()=>E.parsed===null?null:q.jsx("div",{className:"aqmx-document-viewer",children:q.jsx(He.MarkdownViewer,{...H,parseResult:E.parsed,content:null})}),[H,E.parsed]);return q.jsxs("section",{ref:m,className:"aqmx-edit-preview","aria-label":c.previewRegion,"aria-busy":E.busy,inert:i!==null,hidden:i==="removed","data-aqmx-preview-tier":E.tier,"data-testid":"markdown-explorer-edit-preview",onDoubleClick:o===void 0?void 0:D,children:[E.failure===null?null:q.jsx("p",{className:"aqmx-callout aqmx-document-notice","data-aqmx-tone":"warning","data-testid":"markdown-explorer-edit-preview-failure",children:c.previewFailed(T.failureTitleOf(c,E.failure.reason))}),j??(E.failure===null?q.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-preview-skeleton",children:xt.map(a=>q.jsx("span",{},a))}):null),E.busy?q.jsx("p",{className:"aqmx-sr-only",children:c.previewUpdating}):null]})},Ae="data-aqmx-edit-split",ae="--aqmx-edit-share",Ie="--aqmx-edit-gutter",kt="data-aqmx-edit-split-probe",Lt="aqmx-edit-split",At="aqmx-edit-editor",It="aqmx-edit-preview",Oe={value:X.EDIT_SPLIT_MIN_PERCENT,unit:"percentage"},Re={value:X.EDIT_SPLIT_MAX_PERCENT,unit:"percentage"},qe=e=>{if(e.length!==2)return null;const[t=0,n=0]=e,r=t+n;return r>0?t/r*100:null},ie=e=>{const t=e.current?.parentElement;if(t==null)throw new Error("[markdown-explorer] the edit split is not mounted in its surface");return t},Ot=(e,t,n)=>{const[r,i]=h.useState(null);return h.useLayoutEffect(()=>{const o=e.current,l=t.current;if(o===null||l===null)throw new Error("[markdown-explorer] the edit split is not mounted");const s={frame:o.getBoundingClientRect().width,measure:l.getBoundingClientRect().width},f=()=>{s.frame>0&&s.measure>0&&i(X.editSplitOrientation(s.frame,s.measure,n))};f();const d=new ResizeObserver(p=>{for(const k of p){const[c]=k.borderBoxSize;c!==void 0&&(k.target===o&&(s.frame=c.inlineSize),k.target===l&&(s.measure=c.inlineSize))}f()});return d.observe(o),d.observe(l),()=>d.disconnect()},[e,t,n]),r},Rt=({editorId:e})=>{const{edits:t,labels:n}=T.useExplorer(),r=h.useRef(null),i=h.useRef(null),o=ve.useCoarsePointer()?X.COARSE_TARGET_PIXELS:X.FINE_TARGET_PIXELS,l=Ot(r,i,o),[s]=h.useState(()=>t.editorShare());h.useLayoutEffect(()=>{const p=ie(r);return p.style.setProperty(Ie,`${String(o)}px`),()=>{p.style.removeProperty(Ie)}},[o]),h.useLayoutEffect(()=>{const p=ie(r);return p.style.setProperty(ae,`${String(s)}%`),()=>{p.style.removeProperty(ae)}},[s]),h.useLayoutEffect(()=>{if(l===null)return;const p=ie(r);return p.setAttribute(Ae,l),()=>p.removeAttribute(Ae)},[l]);const f=ve.useSplitPersistence(h.useCallback(p=>{const k=qe(p);k!==null&&t.setEditorShare(k)},[t])),d=h.useCallback((p,k)=>{const c=qe(p);c!==null&&ie(r).style.setProperty(ae,`${String(c)}%`),f.layoutChanged(p,k)},[f]);return q.jsxs("div",{ref:r,className:"aqmx-edit-split","data-testid":"markdown-explorer-edit-split",children:[q.jsx("span",{ref:i,className:"aqmx-edit-split-probe","aria-hidden":"true",[kt]:""}),l===null?null:q.jsxs(se.PanelGroup,{id:Lt,direction:l==="beside"?"horizontal":"vertical",onLayout:d,className:"aqmx-edit-split-group",children:[q.jsx(se.Panel,{id:At,defaultSize:{value:s,unit:"percentage"},minSize:Oe,maxSize:Re,contentOverflow:"hidden"}),q.jsx(se.PanelResizeHandle,{thickness:o,indicator:{visible:!0,thickness:X.SPLIT_HANDLE_PIXELS.gripThickness,length:X.SPLIT_HANDLE_PIXELS.gripLength,barThickness:X.SPLIT_HANDLE_PIXELS.barThickness,barLength:X.SPLIT_HANDLE_PIXELS.barLength},title:n.editViewSplitResize,"aria-label":n.editViewSplitResize,"aria-controls":e,onDragging:f.draggingChanged,className:"aqmx-split-handle aqmx-edit-split-handle"}),q.jsx(se.Panel,{id:It,defaultSize:{value:100-s,unit:"percentage"},minSize:Oe,maxSize:Re,contentOverflow:"hidden"})]})]})},qt=512,Ct=()=>{const e=[];let t=0,n=null;const r=i=>{if(n===null||!Number.isInteger(i)||i<t)return null;if(i===t+e.length)return n;const o=e[i-t];return o===void 0?null:o.before};return{revision:()=>t+e.length,mount:i=>{if(n!==null&&(n===i||n.eq(i))){n=i;return}const o=t+e.length;e.length=0,t=n===null?o:o+1,n=i},record:(i,o)=>{if(n===null)throw new Error("[markdown-explorer] a change of the editor's text was recorded before an editor mounted");e.push({before:n,changes:i}),n=o,e.length>qt&&(e.shift(),t+=1)},lineOf:(i,o)=>{const l=r(i);if(l===null||n===null||!Number.isInteger(o)||o<1||o>l.lines)return null;let s=l.line(o).from;for(const f of e.slice(i-t)){const d=f.changes.mapPos(s,1,$.MapMode.TrackAfter);if(d===null)return null;s=d}return n.lineAt(s).number}}},De=144,Mt="[data-aqmd-spreadsheet-fullscreen]",_t=Object.freeze(["e1","e2","e3","e4","e5","e6","e7","e8"]),Pt=e=>{if(typeof e!="object"||e===null)return!1;const{generation:t,topLine:n}=e;return"state"in e&&typeof t=="number"&&typeof n=="number"},Nt=e=>{e.stopPropagation()},Dt=e=>{const{path:t,name:n,session:r}=e,{edits:i,labels:o,announcer:l}=T.useExplorer(),{phase:s}=r,f=h.useCallback(()=>i.retry(t),[i,t]);switch(h.useEffect(()=>{s.kind==="failed"&&l.announce(o.documentFailed(n,T.failureTitleOf(o,s.failure.reason)))},[s,l,o,n]),s.kind){case"opening":return q.jsxs(q.Fragment,{children:[q.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-skeleton",children:_t.map(d=>q.jsx("span",{},d))}),q.jsx("p",{className:"aqmx-sr-only",children:o.editLoading})]});case"grant":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(T.EditGrantNotice,{href:s.href,onRetry:f,testId:"markdown-explorer-edit-grant"})});case"failed":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(T.FailureView,{failure:s.failure,alert:!1,onRetry:f,testId:"markdown-explorer-edit-failure"})});case"editing":return q.jsx(Vt,{...e})}},Vt=({path:e,name:t,session:n,layout:r,viewer:i,region:o,paneScroll:l})=>{const{edits:s,labels:f}=T.useExplorer(),d=h.useRef(null),p=h.useId(),k=h.useRef(null),[c]=h.useState(()=>new Set),[E]=h.useState(Ct),u=h.useRef(null),m=h.useRef(null),v=r==="fill",S=T.useSideBySide(),g=T.editViewOf(n,S,v),L=g!=="editor"||n.previewPrepared,O=L&&v,I=h.useRef({layout:r,region:o,paneScroll:l});h.useLayoutEffect(()=>{I.current={layout:r,region:o,paneScroll:l}});const D=h.useRef(n.generation);h.useLayoutEffect(()=>{D.current=n.generation});const M=h.useRef({view:g,previewMounted:L});h.useLayoutEffect(()=>{M.current={view:g,previewMounted:L}});const F=h.useRef(null),B=h.useRef(null),H=h.useRef(!1),j=h.useMemo(()=>({editor:f.editorLabel(t),useOurs:f.conflictUseOurs,useTheirs:f.conflictUseTheirs,keepBoth:f.conflictKeepBoth}),[f,t]),a=h.useCallback(b=>{const{region:x,paneScroll:_}=I.current,z=x();return z===null?b:_.scrollerOf(z,b)},[]);h.useLayoutEffect(()=>{const b=d.current,x=s.draft(e);if(b===null||x===null)return;const _=s.editorState.get(e),z=Pt(_)&&_.generation===D.current?_:null;let W=null,Q=null;const le=()=>{W!==null&&clearTimeout(W),W=null,Q!==null&&s.setDraft(e,Q.text())},G=tt({parent:b,scroll:{scrollerOf:N=>{const{layout:Z,region:Be,paneScroll:je}=I.current,he=Be();return Z==="fill"||he===null?N:je.scrollerOf(he,N)},reveal:N=>I.current.paneScroll.reveal(N)},text:x,saved:z===null?void 0:z.state,labels:j,revisions:E,onGeometry:N=>m.current?.editorChanged(N),onChange:N=>{if(W??=setTimeout(le,De),!N)for(const Z of[...c])Z();M.current.previewMounted&&Q!==null&&u.current?.draft({text:Q.text(),revision:E.revision()})},onSave:()=>{s.save(e)}});Q=G,k.current=G;const fe=()=>{const N=G.topLine();return{line:N.line,clientTop:N.clientTop}},me=()=>u.current?.anchor(a)??null,Ve=s.bindEditor(e,{flush:le,adopt:N=>G.replaceText(N),returnPoint:()=>{const N=M.current.view==="preview"&&I.current.layout==="content"?me():null;return N===null?fe():{line:N.lines.first,clientTop:N.clientTop}},nextConflict:()=>M.current.view!=="preview"?G.nextConflict():G.conflicts().length===0?!1:(H.current=!0,s.setView(e,"editor"),!0),beforeView:N=>{if(I.current.layout==="fill")return;if(N==="preview"){F.current={to:"preview",point:fe()};return}const Z=me();F.current=Z===null?null:{to:"editor",anchor:Z}}});return z!==null&&G.showLine(z.topLine),()=>{le(),s.editorState.set(e,{state:G.save(),generation:D.current,topLine:G.topLine().line}),Ve(),G.destroy(),Q=null,k.current=null}},[s,e,j,a,c,E]);const{request:A}=n;h.useLayoutEffect(()=>{const b=k.current,x=s.draft(e);b===null||x===null||A===null||(A.anchor!==null&&b.reveal(T.positionInSource(x,A.anchor),A.anchor.clientTop),b.focus(),s.consumeRequest(e))},[s,e,A,j]),h.useLayoutEffect(()=>{g!=="editor"&&!n.previewPrepared&&s.preparePreview(e)},[s,e,g,n.previewPrepared]),h.useLayoutEffect(()=>{const b=F.current,x=B.current,_=H.current;F.current=null,B.current=null,H.current=!1;const z=k.current;if(b?.to==="preview")u.current?.place(b.point,a);else if(b?.to==="editor"&&z!==null){const W=s.draft(e);W!==null&&z.reveal(T.positionInSource(W,b.anchor),b.anchor.clientTop)}_?z?.nextConflict():x==="editor"?z?.focus():x==="preview"&&u.current?.focus()},[s,e,g,a]);const R=h.useMemo(()=>{const b=()=>{const x=k.current;if(x===null)throw new Error("[markdown-explorer] a table of the preview wrote back while no editor was mounted");return x};return{write:(x,{fenceLine:_,expected:z,text:W})=>b().replaceBody(_,z,W,x),read:(x,_)=>b().readBody(_,x),undo:()=>b().undo(),redo:()=>b().redo(),subscribe:x=>(c.add(x),()=>{c.delete(x)})}},[c]),w=h.useCallback(()=>{const b=k.current;if(b===null)throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");return{text:b.text(),revision:E.revision()}},[E]);h.useLayoutEffect(()=>{const b=k.current;if(!O||b===null)return;const x=wt({editor:Pe(b.scrollElement),preview:()=>u.current?.scrollPort()??null,previewBlocks:()=>u.current?.blocks()??[],editorSpans:_=>b.lineSpans(_),requestFrame:_=>requestAnimationFrame(_),cancelFrame:_=>cancelAnimationFrame(_),now:()=>performance.now()});return x.showAlone(T.paneShownAlone(M.current.view)),m.current=x,()=>{x.dispose(),m.current=null}},[O,s,e,j]),h.useLayoutEffect(()=>{m.current?.showAlone(T.paneShownAlone(g))},[g]);const y=h.useCallback(()=>m.current?.previewChanged(),[]),C=h.useCallback(b=>s.start(e,b),[s,e]),U=b=>{if(b.target instanceof Element&&b.target.closest(Mt)!==null)return;if(b.key==="Escape"){T.consumeKey(b);return}if(!T.isEditViewShortcut(b.nativeEvent,T.isApplePlatform(navigator.platform)))return;T.consumeKey(b);const x=T.toggledEditView(g);B.current=x,T.chooseEditView(s,e,x,v)};return q.jsxs("div",{className:"aqmx-edit","data-aqmx-edit-layout":r,"data-aqmx-edit-view":g,"data-testid":"markdown-explorer-edit",onKeyDown:U,onDoubleClick:Nt,children:[q.jsx("div",{ref:d,id:p,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",inert:g==="preview",hidden:g==="preview"&&!v,...T.ALLOW_KEY_REPEAT}),g==="split"?q.jsx(Rt,{editorId:p}):null,L?q.jsx(Tt,{path:e,readDraft:w,viewer:i,tables:R,concealed:g!=="editor"?null:v?"overlay":"removed",onEditAt:g==="preview"?C:void 0,onLayout:y,handleRef:u}):null]})};exports.DRAFT_WRITE_INTERVAL_MS=De;exports.default=Dt;
5
+ `:""}${I.lines.map(j=>`${j}
6
+ `).join("")}`;return E(()=>c.dispatch({changes:{from:M,to:D(I.to),insert:B},userEvent:Ee,annotations:K.isolateHistory.of("full")})),"written"},readBody:(u,m)=>{const v=o.lineOf(m,u);if(v===null)return null;const S=be(c.state,v);return S.kind==="found"?S.body:null},undo:()=>E(()=>K.undo(c)),redo:()=>E(()=>K.redo(c)),reveal:({line:u,column:m},v)=>{const{doc:S}=c.state,g=S.line(Math.min(Math.max(u,1),S.lines)),L=Math.min(g.from+m,g.to);c.dispatch({selection:$.EditorSelection.cursor(L),effects:xe(c,L,v,t)})},showLine:u=>{const{doc:m}=c.state,v=m.line(Math.min(Math.max(u,1),m.lines)).from;c.dispatch({effects:xe(c,v,null,t)})},topLine:()=>{const u=t.scrollerOf(c.scrollDOM),m=y.visibleTopOf(u,c.contentDOM),v=y.frameTopOf(u)+u.clientHeight,{documentTop:S}=c,{doc:g}=c.state;let L=c.lineBlockAtHeight(Math.max(m-S,0));for(;g.lineAt(L.from).text.trim()===""&&L.to<g.length;){const D=c.lineBlockAt(L.to+1);if(S+D.top>=v)break;L=D}const O=c.coordsAtPos(L.from),I=O===null?S+L.top:O.top;return{line:c.state.doc.lineAt(L.from).number,clientTop:I,offset:I-m}},lineSpans:u=>{const m=c.scrollDOM,v=m.scrollTop+c.documentTop-y.visibleTopOf(m,c.contentDOM),{doc:S}=c.state,g=L=>S.line(Math.min(Math.max(L,1),S.lines)).from;return u.map(({first:L,last:O})=>({top:v+c.lineBlockAt(g(L)).top,bottom:v+c.lineBlockAt(g(O)).bottom}))},scrollElement:c.scrollDOM,focus:()=>c.focus(),conflicts:()=>re(c.state.doc),resolveAtCursor:u=>{const m=re(c.state.doc),v=c.state.doc.lineAt(c.state.selection.main.head).number,S=m.find(g=>g.end>=v);return S===void 0?!1:(_e(c,S,u),!0)},nextConflict:()=>{const u=re(c.state.doc);if(u[0]===void 0)return!1;const v=c.state.doc.lineAt(c.state.selection.main.head).number,S=u.findIndex(I=>I.start>v),g=S<0?0:S,L=c.state.doc.line(u[g].start).from;c.dispatch({selection:$.EditorSelection.cursor(L),effects:P.EditorView.scrollIntoView(L,{y:"center"})});const O=c.contentDOM.querySelector(`[${Me}="${String(g)}"] button`);return O instanceof HTMLElement?O.focus({preventScroll:!0}):c.focus(),!0},save:()=>c.state.toJSON(qe),destroy:()=>c.destroy()}},xe=(e,t,n,r)=>{const i=r.scrollerOf(e.scrollDOM),o=(n===null?y.visibleTopOf(i,e.contentDOM):n)-y.frameTopOf(i);return P.EditorView.scrollIntoView(t,{y:"start",yMargin:o})},nt=(e,t,n,r)=>{const i=rt(e,t),o=r.scrollerOf(e.scrollDOM),l=y.frameTopOf(o),s=y.visibleTopOf(o,e.contentDOM),d=l+o.clientHeight;let f=0;switch(n.y){case"start":f=i.top-(l+n.yMargin);break;case"center":f=(i.top+i.bottom)/2-(s+d)/2;break;case"end":f=i.bottom-(d-n.yMargin);break;default:i.top<s+n.yMargin?f=i.top-(s+n.yMargin):i.bottom>d-n.yMargin&&(f=Math.min(i.bottom-(d-n.yMargin),i.top-(s+n.yMargin)))}if(f!==0&&(o.scrollTop+=f),n.y==="start")return;const p=ot(e,t);p!==null&&r.reveal(p)},rt=(e,t)=>{const{node:n,offset:r}=e.domAtPos(t);if(n.nodeType===Node.TEXT_NODE){const l=n.ownerDocument?.createRange();if(l!==void 0){l.setStart(n,r),l.setEnd(n,r);const[s]=l.getClientRects();if(s!==void 0&&s.height>0)return{top:s.top,bottom:s.bottom}}}const i=e.lineBlockAt(t),o=e.documentTop+i.top;return{top:o,bottom:o+i.height}},ot=(e,t)=>{const{node:n}=e.domAtPos(t);for(let r=n instanceof Element?n:n.parentElement;r!==null;r=r.parentElement)if(r.parentElement===e.contentDOM)return r;return null},st=(e,t)=>{if(e==null)return null;try{return $.EditorState.fromJSON(e,{extensions:t},qe)}catch{return null}},it=610,lt=987,Se=Object.freeze({kind:"unavailable"}),ct="true",at="false",ut=e=>e===ct?!0:e===at?!1:null,dt=e=>{const t=new DOMParser().parseFromString(e,"text/html"),n=[];for(const r of t.querySelectorAll("img[data-asset-src], a[data-doc-path]")){const i=r.localName==="img",o=r.getAttribute(i?"data-asset-src":"data-doc-path");o!==null&&n.push({target:{kind:i?"asset":"doc",path:o},exists:ut(r.getAttribute(i?"data-asset-exists":"data-doc-exists"))})}return n},ft=({path:e,instant:t,preview:n,initial:r,onView:i})=>{const o=new AbortController,l={asset:new Map,doc:new Map};let s=r,d=null,f=!1,p=!1,k=null,c=null,E=[],u,m=!1,v,S=null;const g=w=>{w.parsed===s.parsed&&w.source===s.source&&w.failure===s.failure&&w.busy===s.busy&&w.tier===s.tier||(s=w,i(w))},L=(w,T)=>{f||(f=!0,console.error(`[markdown-explorer] ${w}`,...T===void 0?[]:[T]))},O=w=>{if(t!==null)for(const{target:T,exists:C}of t.marksOf(w))l[T.kind].set(T.path,C)},I=()=>{clearTimeout(v),v=void 0,S?.abort(),S=null},D=()=>{c=null,E=[],clearTimeout(u),u=void 0},M=(w,T)=>{g({...s,failure:w,busy:!1,tier:T})},F=()=>{clearTimeout(u),u=E.length===0?void 0:setTimeout(j,lt)},B=()=>{if(t===null||c===null)return;const w=c,T=[],C={asset:new Set,doc:new Set};let U;try{U=t.sanitize(w.html,x=>{const _=l[x.kind].get(x.path);return _===void 0&&!C[x.kind].has(x.path)&&(C[x.kind].add(x.path),T.push(x)),_??void 0})}catch(x){D(),x instanceof de.HtmlNestingLimitError?M(ee.failureOf("too-large"),"instant"):(L("the draft sanitizer failed",x),M(ee.failureOf("failed"),"instant"));return}E=T;const b=s.parsed!==null&&s.parsed.htmlContent===U&&s.parsed.headings===w.headings?s.parsed:{htmlContent:U,headings:w.headings};g({parsed:b,source:w.draft,failure:null,busy:!1,tier:"instant"}),F()},j=()=>{if(u=void 0,m||c===null||E.length===0)return;m=!0;const w=E;n(e,c.draft.text,o.signal).then(T=>{if(m=!1,!(o.signal.aborted||!("kind"in T))){T.kind==="preview"&&O(T.htmlContent);for(const C of w)l[C.kind].has(C.path)||l[C.kind].set(C.path,null);B()}})},H=w=>{I(),D(),g({...s,busy:!0,tier:"server"});const T=new AbortController;S=T,v=setTimeout(()=>{v=void 0,n(e,w.text,T.signal).then(C=>{if(!(T.signal.aborted||!("kind"in C))){if(S=null,C.kind==="failure"){M(C.failure,"server");return}O(C.htmlContent),g({parsed:{htmlContent:C.htmlContent,headings:C.headings},source:w,failure:null,busy:!1,tier:"server"})}})},it)},a=async(w,T)=>{let C;try{C=await w.convert({path:e,text:T},o.signal)}catch(b){return o.signal.aborted||L("the draft converter rejected a conversion, which its contract allows only once the signal aborted",b),Se}const U=ee.draftAnswerViolation(C);return U===null?C:(L(`the draft converter answered outside its contract: ${U}`),Se)},A=(w,T)=>{switch(T.kind){case"preview":if(I(),T.headings.length>ee.EXPLORER_MAX_HEADINGS){D(),M(ee.failureOf("too-large"),"instant");return}c={draft:w,html:T.htmlContent,headings:T.headings.map(({text:C,depth:U,id:b})=>({text:C,depth:U,id:b}))},B();return;case"failure":I(),D(),M(ee.failureOf(T.failure.reason,T.failure.code),"instant");return;case"unavailable":H(w);return}},R=async w=>{p=!0;try{for(;k!==null&&!o.signal.aborted;){const T=k;k=null;const C=await a(w,T.text);if(o.signal.aborted)return;A(T,C)}}finally{p=!1}};return t!==null&&t.seed!==null&&O(t.seed),{update:w=>{if(!(o.signal.aborted||w.text===d?.text)){if(d=w,clearTimeout(u),u=void 0,t===null){H(w);return}k=w,p||R(t.converter)}},dispose:()=>{o.abort(),k=null,clearTimeout(u),u=void 0,I()}}},mt=(e,t)=>de.createHtmlSanitizer(ze(window),e,t,de.MAX_HTML_NESTING_DEPTH),ht=(e,t)=>e.flatMap((n,r)=>{const i=t[r];return i===void 0?[]:[{editor:i.top,preview:n.top},{editor:i.bottom,preview:n.bottom}]}),Y=(e,t)=>{const n=e[t];if(n===void 0)throw new RangeError(`[markdown-explorer] a scroll map index must be in 0..${String(e.length-1)}; got ${String(t)}`);return n},pt=e=>{const t=[];for(const r of e){let i=0,o=t.length;for(;i<o;){const l=i+o>>1;Y(t,l).pair.preview<=r.preview?i=l+1:o=l}t[i]={pair:r,before:i===0?void 0:Y(t,i-1)}}const n=[];for(let r=t.at(-1);r!==void 0;r=r.before)n.push(r.pair);return n.reverse()},gt=(e,t)=>{const n=Math.max(t.editorMax,0),r=Math.max(t.previewMax,0),i=n-t.editorViewport,o=r-t.previewViewport,l=e.filter(f=>f.editor>0&&f.editor<i&&f.preview>0&&f.preview<o).sort((f,p)=>f.editor-p.editor||f.preview-p.preview);let s={editor:0,preview:0};const d=[s];for(const f of pt(l))f.editor>s.editor&&f.preview>s.preview&&(d.push(f),s=f);return d.push({editor:n,preview:r}),{toPreview:f=>ye(d,"editor","preview",f),toEditor:f=>ye(d,"preview","editor",f)}},ye=(e,t,n,r)=>{const i=Y(e,0),o=Y(e,e.length-1);if(Number.isNaN(r)||r<=i[t])return i[n];if(r>=o[t])return o[n];let l=0,s=e.length-1;for(;s-l>1;){const p=l+s>>1;Y(e,p)[t]<=r?l=p:s=p}const d=Y(e,l),f=Y(e,s);return d[n]+(f[n]-d[n])*(r-d[t])/(f[t]-d[t])},vt=610,Te=89,ke=.5,wt=({editor:e,preview:t,previewBlocks:n,editorSpans:r,requestFrame:i,cancelFrame:o,now:l})=>{let s="editor",d=0,f=null,p=null,k=!1,c=null,E=null;const u={editor:0,preview:0},m={editor:null,preview:null};let v=null,S=()=>{};const g=a=>{f!==null&&a!==f||(s=a,d=l()+vt)},L=(a,A)=>{a!==s&&f===null&&l()>=d&&!O(a,A)&&(s=a),B()},O=(a,A)=>{const R=m[a];return l()<u[a]||R!==null&&Math.abs(A.position()-R)<ke},I=e.onScroll(()=>L("editor",e)),D=e.onIntent(()=>g("editor")),M=()=>{const a=t();return a!==v&&(S(),v=a,S=a===null?()=>{}:F(a)),a},F=a=>{const A=a.onScroll(()=>L("preview",a)),R=a.onIntent(()=>g("preview"));return()=>{A(),R()}},B=()=>{!k&&p===null&&(p=i(j))},j=()=>{p=null;const a=M();a!==null&&(c??=n(),E??=gt(ht(c,r(c)),{editorMax:e.max(),previewMax:a.max(),editorViewport:e.viewport(),previewViewport:a.viewport()}),s==="editor"?H(a,"preview",E.toPreview(e.position())):H(e,"editor",E.toEditor(a.position())))},H=(a,A,R)=>{if(Math.abs(a.position()-R)<ke){m[A]=a.position();return}u[A]=l()+Te,m[A]=a.scrollTo(R)};return B(),{editorChanged:a=>{E=null,a&&g("editor"),B()},previewChanged:()=>{c=null,E=null,u.preview=l()+Te,B()},showAlone:a=>{f=a,!(a===null||a===s)&&(s=a,d=0,B())},dispose:()=>{k=!0,p!==null&&o(p),p=null,I(),D(),S()}}},Le=Object.freeze(["wheel","pointerdown","keydown","focusin"]),Pe=e=>({position:()=>e.scrollTop,max:()=>Math.max(e.scrollHeight-e.clientHeight,0),viewport:()=>e.clientHeight,scrollTo:t=>(e.scrollTo({top:t,behavior:"instant"}),e.scrollTop),onScroll:t=>(e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)),onIntent:t=>{for(const n of Le)e.addEventListener(n,t,{capture:!0,passive:!0});return()=>{for(const n of Le)e.removeEventListener(n,t,{capture:!0})}}}),ne="[data-aqmd-scroll-container]",Et="[data-aqmd-content]",bt=`[${ue.SOURCE_LINES_ATTRIBUTE}]`,xt=Object.freeze(["p1","p2","p3","p4","p5","p6","p7","p8"]),Ne=(e,t)=>{const n=y.loadedOf(e.peek(t));return n!==null&&n.document.kind==="markdown"?{htmlContent:n.document.htmlContent,headings:n.document.headings}:null},St=(e,t,n,r,i)=>{if(n===void 0)return null;let o;try{o=mt(e,t)}catch(l){return console.error("[markdown-explorer] the draft sanitizer cannot run in this browser, so the server renders the preview",l),null}return{converter:n,sanitize:o,marksOf:dt,seed:Ne(r,i)?.htmlContent??null}},yt=e=>{const t=[];let n=null;for(const r of e.querySelectorAll(bt)){const i=ue.parseSourceLines(r.getAttribute(ue.SOURCE_LINES_ATTRIBUTE));if(i===null||r.getClientRects().length===0)continue;n??=e.scrollTop-y.visibleTopOf(e,r);const{top:o,bottom:l}=r.getBoundingClientRect();t.push({first:i.first,last:i.last,top:n+o,bottom:n+l})}return t},Tt=({path:e,readDraft:t,viewer:n,tables:r,concealed:i,onEditAt:o,onLayout:l,handleRef:s})=>{const{config:d,data:f,documents:p,draftConverter:k,labels:c}=y.useExplorer(),[E,u]=h.useState(()=>({parsed:Ne(p,e),source:null,failure:null,busy:!0,tier:k===void 0?"server":"instant"})),m=h.useRef(null),v=h.useRef(null),S=h.useRef(E);h.useLayoutEffect(()=>{S.current=E});const g=h.useEffectEvent(()=>t());h.useEffect(()=>{const a=St(d.iframeHosts,d.dataPath,k,p,e),A=g(),R=ft({path:e,instant:a,preview:f.preview,initial:S.current,onView:w=>h.startTransition(()=>u(w))});return v.current=R,R.update(A),()=>{R.dispose(),v.current=null}},[d,f,p,k,e]);const L=h.useEffectEvent(()=>l());h.useLayoutEffect(()=>{E.parsed!==null&&L()},[E.parsed]);const O=E.parsed!==null;h.useLayoutEffect(()=>{const a=O?m.current?.querySelector(ne):null;if(!(a instanceof HTMLElement))return;a.tabIndex=0;const A=new ResizeObserver(()=>L());A.observe(a);const R=a.querySelector(Et);return R!==null&&A.observe(R),()=>A.disconnect()},[O]);const I=h.useRef(null);h.useImperativeHandle(s,()=>({draft:a=>{v.current?.update(a)},scrollPort:()=>{const a=m.current?.querySelector(ne);return a instanceof HTMLElement?(I.current?.scroller!==a&&(I.current={scroller:a,port:Pe(a)}),I.current.port):null},blocks:()=>{const a=m.current?.querySelector(ne);return a instanceof HTMLElement?yt(a):[]},focus:()=>{const a=m.current?.querySelector(ne);a instanceof HTMLElement&&a.focus({preventScroll:!0})},anchor:a=>{const A=m.current,R=A?.querySelector(ne);return A===null||!(R instanceof HTMLElement)?null:y.anchorOfView(A,a(R))},place:({line:a,clientTop:A},R)=>{const w=m.current,T=w===null?null:y.blockAtLine(w,a);T!==null&&(R(T).scrollTop+=y.lineTopIn(T,a)-A)}}),[]);const D=a=>{const A=m.current,{target:R}=a;if(o===void 0||A===null||!(R instanceof Element)||!y.isEditingDoubleClick(R))return;const w=y.anchorOfDoubleClick(R,A,A.ownerDocument.getSelection());w!==null&&o(w)},M=E.source===null?null:E.source.revision,F=h.useMemo(()=>M===null?void 0:{write:a=>r.write(M,a),read:a=>r.read(M,a),undo:r.undo,redo:r.redo,subscribe:r.subscribe},[r,M]),B=h.useMemo(()=>({...n.labels,spreadsheetReadOnly:c.previewTablePending}),[n.labels,c.previewTablePending]),j=h.useMemo(()=>({...n,labels:F===void 0?B:n.labels,showToc:!1,showStyle:!1,showAlign:!1,renderScrollBar:void 0,spreadsheetEditor:F}),[n,B,F]),H=h.useMemo(()=>E.parsed===null?null:q.jsx("div",{className:"aqmx-document-viewer",children:q.jsx(je.MarkdownViewer,{...j,parseResult:E.parsed,content:null})}),[j,E.parsed]);return q.jsxs("section",{ref:m,className:"aqmx-edit-preview","aria-label":c.previewRegion,"aria-busy":E.busy,inert:i!==null,hidden:i==="removed","data-aqmx-preview-tier":E.tier,"data-testid":"markdown-explorer-edit-preview",onDoubleClick:o===void 0?void 0:D,children:[E.failure===null?null:q.jsx("p",{className:"aqmx-callout aqmx-document-notice","data-aqmx-tone":"warning","data-testid":"markdown-explorer-edit-preview-failure",children:c.previewFailed(y.failureTitleOf(c,E.failure.reason))}),H??(E.failure===null?q.jsx("div",{className:"aqmx-skeleton","aria-hidden":"true","data-testid":"markdown-explorer-edit-preview-skeleton",children:xt.map(a=>q.jsx("span",{},a))}):null),E.busy?q.jsx("p",{className:"aqmx-sr-only",children:c.previewUpdating}):null]})},Ae="data-aqmx-edit-split",ae="--aqmx-edit-share",Ie="--aqmx-edit-gutter",kt="data-aqmx-edit-split-probe",Lt="aqmx-edit-split",At="aqmx-edit-editor",It="aqmx-edit-preview",Oe={value:X.EDIT_SPLIT_MIN_PERCENT,unit:"percentage"},Re={value:X.EDIT_SPLIT_MAX_PERCENT,unit:"percentage"},Ce=e=>{if(e.length!==2)return null;const[t=0,n=0]=e,r=t+n;return r>0?t/r*100:null},ie=e=>{const t=e.current?.parentElement;if(t==null)throw new Error("[markdown-explorer] the edit split is not mounted in its surface");return t},Ot=(e,t,n)=>{const[r,i]=h.useState(null);return h.useLayoutEffect(()=>{const o=e.current,l=t.current;if(o===null||l===null)throw new Error("[markdown-explorer] the edit split is not mounted");const s={frame:o.getBoundingClientRect().width,measure:l.getBoundingClientRect().width},d=()=>{s.frame>0&&s.measure>0&&i(X.editSplitOrientation(s.frame,s.measure,n))};d();const f=new ResizeObserver(p=>{for(const k of p){const[c]=k.borderBoxSize;c!==void 0&&(k.target===o&&(s.frame=c.inlineSize),k.target===l&&(s.measure=c.inlineSize))}d()});return f.observe(o),f.observe(l),()=>f.disconnect()},[e,t,n]),r},Rt=({editorId:e})=>{const{edits:t,labels:n}=y.useExplorer(),r=h.useRef(null),i=h.useRef(null),o=ve.useCoarsePointer()?X.COARSE_TARGET_PIXELS:X.FINE_TARGET_PIXELS,l=Ot(r,i,o),[s]=h.useState(()=>t.editorShare());h.useLayoutEffect(()=>{const p=ie(r);return p.style.setProperty(Ie,`${String(o)}px`),()=>{p.style.removeProperty(Ie)}},[o]),h.useLayoutEffect(()=>{const p=ie(r);return p.style.setProperty(ae,`${String(s)}%`),()=>{p.style.removeProperty(ae)}},[s]),h.useLayoutEffect(()=>{if(l===null)return;const p=ie(r);return p.setAttribute(Ae,l),()=>p.removeAttribute(Ae)},[l]);const d=ve.useSplitPersistence(h.useCallback(p=>{const k=Ce(p);k!==null&&t.setEditorShare(k)},[t])),f=h.useCallback((p,k)=>{const c=Ce(p);c!==null&&ie(r).style.setProperty(ae,`${String(c)}%`),d.layoutChanged(p,k)},[d]);return q.jsxs("div",{ref:r,className:"aqmx-edit-split","data-testid":"markdown-explorer-edit-split",children:[q.jsx("span",{ref:i,className:"aqmx-edit-split-probe","aria-hidden":"true",[kt]:""}),l===null?null:q.jsxs(se.PanelGroup,{id:Lt,direction:l==="beside"?"horizontal":"vertical",onLayout:f,className:"aqmx-edit-split-group",children:[q.jsx(se.Panel,{id:At,defaultSize:{value:s,unit:"percentage"},minSize:Oe,maxSize:Re,contentOverflow:"hidden"}),q.jsx(se.PanelResizeHandle,{thickness:o,indicator:{visible:!0,thickness:X.SPLIT_HANDLE_PIXELS.gripThickness,length:X.SPLIT_HANDLE_PIXELS.gripLength,barThickness:X.SPLIT_HANDLE_PIXELS.barThickness,barLength:X.SPLIT_HANDLE_PIXELS.barLength},title:n.editViewSplitResize,"aria-label":n.editViewSplitResize,"aria-controls":e,onDragging:d.draggingChanged,className:"aqmx-split-handle aqmx-edit-split-handle"}),q.jsx(se.Panel,{id:It,defaultSize:{value:100-s,unit:"percentage"},minSize:Oe,maxSize:Re,contentOverflow:"hidden"})]})]})},Ct=512,qt=()=>{const e=[];let t=0,n=null;const r=i=>{if(n===null||!Number.isInteger(i)||i<t)return null;if(i===t+e.length)return n;const o=e[i-t];return o===void 0?null:o.before};return{revision:()=>t+e.length,mount:i=>{if(n!==null&&(n===i||n.eq(i))){n=i;return}const o=t+e.length;e.length=0,t=n===null?o:o+1,n=i},record:(i,o)=>{if(n===null)throw new Error("[markdown-explorer] a change of the editor's text was recorded before an editor mounted");e.push({before:n,changes:i}),n=o,e.length>Ct&&(e.shift(),t+=1)},lineOf:(i,o)=>{const l=r(i);if(l===null||n===null||!Number.isInteger(o)||o<1||o>l.lines)return null;let s=l.line(o).from;for(const d of e.slice(i-t)){const f=d.changes.mapPos(s,1,$.MapMode.TrackAfter);if(f===null)return null;s=f}return n.lineAt(s).number}}},De=144,Mt="[data-aqmd-spreadsheet-fullscreen]",_t=e=>{if(typeof e!="object"||e===null)return!1;const{generation:t,topLine:n}=e;return"state"in e&&typeof t=="number"&&typeof n=="number"},Pt=e=>{e.stopPropagation()},Nt=e=>{const{path:t,name:n,session:r}=e,{edits:i,labels:o,announcer:l}=y.useExplorer(),{phase:s}=r,d=h.useCallback(()=>i.retry(t),[i,t]);switch(h.useEffect(()=>{s.kind==="failed"&&l.announce(o.documentFailed(n,y.failureTitleOf(o,s.failure.reason)))},[s,l,o,n]),s.kind){case"opening":return q.jsx(y.ContentSkeleton,{label:o.editLoading,testId:"markdown-explorer-edit-skeleton"});case"grant":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(y.EditGrantNotice,{href:s.href,onRetry:d,testId:"markdown-explorer-edit-grant"})});case"failed":return q.jsx("div",{className:"aqmx-edit-message",children:q.jsx(y.FailureView,{failure:s.failure,alert:!1,onRetry:d,testId:"markdown-explorer-edit-failure"})});case"editing":return q.jsx(Dt,{...e})}},Dt=({path:e,name:t,session:n,layout:r,viewer:i,region:o,paneScroll:l})=>{const{edits:s,labels:d}=y.useExplorer(),f=h.useRef(null),p=h.useId(),k=h.useRef(null),[c]=h.useState(()=>new Set),[E]=h.useState(qt),u=h.useRef(null),m=h.useRef(null),v=r==="fill",S=y.useSideBySide(),g=y.editViewOf(n,S,v),L=g!=="editor"||n.previewPrepared,O=L&&v,I=h.useRef({layout:r,region:o,paneScroll:l});h.useLayoutEffect(()=>{I.current={layout:r,region:o,paneScroll:l}});const D=h.useRef(n.generation);h.useLayoutEffect(()=>{D.current=n.generation});const M=h.useRef({view:g,previewMounted:L});h.useLayoutEffect(()=>{M.current={view:g,previewMounted:L}});const F=h.useRef(null),B=h.useRef(null),j=h.useRef(!1),H=h.useMemo(()=>({editor:d.editorLabel(t),useOurs:d.conflictUseOurs,useTheirs:d.conflictUseTheirs,keepBoth:d.conflictKeepBoth}),[d,t]),a=h.useCallback(b=>{const{region:x,paneScroll:_}=I.current,z=x();return z===null?b:_.scrollerOf(z,b)},[]);h.useLayoutEffect(()=>{const b=f.current,x=s.draft(e);if(b===null||x===null)return;const _=s.editorState.get(e),z=_t(_)&&_.generation===D.current?_:null;let W=null,Q=null;const le=()=>{W!==null&&clearTimeout(W),W=null,Q!==null&&s.setDraft(e,Q.text())},G=tt({parent:b,scroll:{scrollerOf:N=>{const{layout:Z,region:Be,paneScroll:He}=I.current,he=Be();return Z==="fill"||he===null?N:He.scrollerOf(he,N)},reveal:N=>I.current.paneScroll.reveal(N)},text:x,saved:z===null?void 0:z.state,labels:H,revisions:E,onGeometry:N=>m.current?.editorChanged(N),onChange:N=>{if(W??=setTimeout(le,De),!N)for(const Z of[...c])Z();M.current.previewMounted&&Q!==null&&u.current?.draft({text:Q.text(),revision:E.revision()})},onSave:()=>{s.save(e)}});Q=G,k.current=G;const fe=()=>{const N=G.topLine();return{line:N.line,clientTop:N.clientTop}},me=()=>u.current?.anchor(a)??null,Ve=s.bindEditor(e,{flush:le,adopt:N=>G.replaceText(N),returnPoint:()=>{const N=M.current.view==="preview"&&I.current.layout==="content"?me():null;return N===null?fe():{line:N.lines.first,clientTop:N.clientTop}},nextConflict:()=>M.current.view!=="preview"?G.nextConflict():G.conflicts().length===0?!1:(j.current=!0,s.setView(e,"editor"),!0),beforeView:N=>{if(I.current.layout==="fill")return;if(N==="preview"){F.current={to:"preview",point:fe()};return}const Z=me();F.current=Z===null?null:{to:"editor",anchor:Z}}});return z!==null&&G.showLine(z.topLine),()=>{le(),s.editorState.set(e,{state:G.save(),generation:D.current,topLine:G.topLine().line}),Ve(),G.destroy(),Q=null,k.current=null}},[s,e,H,a,c,E]);const{request:A}=n;h.useLayoutEffect(()=>{const b=k.current,x=s.draft(e);b===null||x===null||A===null||(A.anchor!==null&&b.reveal(y.positionInSource(x,A.anchor),A.anchor.clientTop),b.focus(),s.consumeRequest(e))},[s,e,A,H]),h.useLayoutEffect(()=>{g!=="editor"&&!n.previewPrepared&&s.preparePreview(e)},[s,e,g,n.previewPrepared]),h.useLayoutEffect(()=>{const b=F.current,x=B.current,_=j.current;F.current=null,B.current=null,j.current=!1;const z=k.current;if(b?.to==="preview")u.current?.place(b.point,a);else if(b?.to==="editor"&&z!==null){const W=s.draft(e);W!==null&&z.reveal(y.positionInSource(W,b.anchor),b.anchor.clientTop)}_?z?.nextConflict():x==="editor"?z?.focus():x==="preview"&&u.current?.focus()},[s,e,g,a]);const R=h.useMemo(()=>{const b=()=>{const x=k.current;if(x===null)throw new Error("[markdown-explorer] a table of the preview wrote back while no editor was mounted");return x};return{write:(x,{fenceLine:_,expected:z,text:W})=>b().replaceBody(_,z,W,x),read:(x,_)=>b().readBody(_,x),undo:()=>b().undo(),redo:()=>b().redo(),subscribe:x=>(c.add(x),()=>{c.delete(x)})}},[c]),w=h.useCallback(()=>{const b=k.current;if(b===null)throw new Error("[markdown-explorer] the preview read the draft before the editor was mounted");return{text:b.text(),revision:E.revision()}},[E]);h.useLayoutEffect(()=>{const b=k.current;if(!O||b===null)return;const x=wt({editor:Pe(b.scrollElement),preview:()=>u.current?.scrollPort()??null,previewBlocks:()=>u.current?.blocks()??[],editorSpans:_=>b.lineSpans(_),requestFrame:_=>requestAnimationFrame(_),cancelFrame:_=>cancelAnimationFrame(_),now:()=>performance.now()});return x.showAlone(y.paneShownAlone(M.current.view)),m.current=x,()=>{x.dispose(),m.current=null}},[O,s,e,H]),h.useLayoutEffect(()=>{m.current?.showAlone(y.paneShownAlone(g))},[g]);const T=h.useCallback(()=>m.current?.previewChanged(),[]),C=h.useCallback(b=>s.start(e,b),[s,e]),U=b=>{if(b.target instanceof Element&&b.target.closest(Mt)!==null)return;if(b.key==="Escape"){y.consumeKey(b);return}if(!y.isEditViewShortcut(b.nativeEvent,y.isApplePlatform(navigator.platform)))return;y.consumeKey(b);const x=y.toggledEditView(g);B.current=x,y.chooseEditView(s,e,x,v)};return q.jsxs("div",{className:"aqmx-edit","data-aqmx-edit-layout":r,"data-aqmx-edit-view":g,"data-testid":"markdown-explorer-edit",onKeyDown:U,onDoubleClick:Pt,children:[q.jsx("div",{ref:f,id:p,className:"aqmx-edit-editor","data-testid":"markdown-explorer-editor",inert:g==="preview",hidden:g==="preview"&&!v,...y.ALLOW_KEY_REPEAT}),g==="split"?q.jsx(Rt,{editorId:p}):null,L?q.jsx(Tt,{path:e,readDraft:w,viewer:i,tables:R,concealed:g!=="editor"?null:v?"overlay":"removed",onEditAt:g==="preview"?C:void 0,onLayout:T,handleRef:u}):null]})};exports.DRAFT_WRITE_INTERVAL_MS=De;exports.default=Nt;
@@ -1 +1 @@
1
- "use strict";const c=require("react/jsx-runtime"),v=require("./index-BNFl3BsO.cjs"),r=require("react"),A=require("./location-DN0AI4ir.cjs"),He=require("@aiquants/directory-tree"),mt=require("./tapScrollCircle-C5DGI-0H.cjs"),pt=require("./storage-DM0EvkVf.cjs"),xe=require("@aiquants/resize-panels"),Ae=require("./useSplitPersistence-CR4Oxtaa.cjs"),ht=require("react-router");function xt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const p=xt(r);function wt({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 gt=p.forwardRef(wt);function Et({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 bt=p.forwardRef(Et);function vt({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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"}),p.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 Rt=p.forwardRef(vt);function yt({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 St=p.forwardRef(yt),kt=()=>{const{notices:e}=v.useExplorer(),t=r.use(e);return t.length===0?null:c.jsx("div",{className:"aqmx-explorer-notices",children:t.map(n=>c.jsxs("div",{className:"aqmx-callout","data-aqmx-tone":n.tone,"data-testid":"markdown-explorer-notice","data-aqmx-notice":n.id,children:[c.jsx("p",{className:"aqmx-callout-title",children:n.title}),n.body===void 0?null:c.jsx("p",{className:"aqmx-callout-body",children:n.body}),n.action===void 0?null:c.jsx("a",{className:"aqmx-callout-action",href:n.action.href,children:n.action.label})]},n.id))})};function Ct({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Tt=p.forwardRef(Ct),ye=r.createContext(!0),Ze="\0loop\0",$e="\0",Lt=()=>{const e=new WeakMap,t=new WeakMap,n=new WeakMap,a=o=>{const l=e.get(o);if(l!==void 0)return l;const i=Object.freeze({type:"loop",name:o.name,path:o.path});return e.set(o,i),i},s=(o,l,i)=>{let f=!1;const m=o.map(h=>{const x=u(h,l,i);return x!==h&&(f=!0),x});if(!f)return o;const d=n.get(o);return d!==void 0&&d.length===m.length&&d.every((h,x)=>h===m[x])?d:(n.set(o,m),m)},u=(o,l,i)=>{if(o.type!=="directory")return o;if(i.has(o.path))return a(o);const f=o.lazy===!0?l(o.path):void 0,m=f?.status==="loaded",d=m?f.entries:o.children;if(d===void 0)return o;i.add(o.path);const h=s(d,l,i);if(i.delete(o.path),!m&&h===o.children)return o;const x=t.get(o);if(x!==void 0&&x.state===f&&x.children===h)return x.grafted;const g={...o,children:h,lazy:m?!1:o.lazy};return t.set(o,{state:f,children:h,grafted:g}),g};return(o,l)=>s(o,l,new Set)},jt=(e,t)=>`${Ze}${e}${$e}${t}`,ie=e=>e.startsWith(Ze),Pt=e=>e.slice(e.lastIndexOf($e)+1),re="data-aqmx-path",Nt=(e,t,n,a,s)=>{const u={aqmxPath:e.path};return e.modifiedAt!==void 0&&(u.aqmxModifiedAt=e.modifiedAt),n&&(u.aqmxOpen=!0),(a==="loading"||a==="failed")&&(u.aqmxChildren=a),{name:e.name,type:e.type,absolutePath:e.path,relativePath:e.path,mimeType:e.mimeType,children:t,label:s,data:u}},Ot=(e,t,n,a)=>{const s=jt(t,e.path);return{name:n,type:"directory",absolutePath:s,relativePath:s,children:a,data:{aqmxLoop:e.path}}},At=()=>{const e=new WeakMap,t=new WeakMap,n=new WeakMap,a=[],s=(l,i,f)=>{const m=l.map(h=>h.type==="loop"?u(h,i,f):o(h,i)),d=n.get(l);return d!==void 0&&d.length===m.length&&d.every((h,x)=>h===m[x])?d:(n.set(l,m),m)},u=(l,i,f)=>{const m=t.get(l);if(m!==void 0&&m.parentKey===f&&m.loopFolderName===i.loopFolderName)return m.row;const d=Ot(l,f,i.loopFolderName(l.name),a);return t.set(l,{row:d,parentKey:f,loopFolderName:i.loopFolderName}),d},o=(l,i)=>{const f=l.type==="directory"?l.children===void 0?a:s(l.children,i,l.path):void 0,m=i.openPaths.has(l.path),d=l.type==="directory"&&l.lazy===!0?i.childrenOf(l.path)?.status:void 0,h=d==="failed"?i.renderFailedFolder:void 0,x=e.get(l);if(x!==void 0&&x.open===m&&x.childrenStatus===d&&x.children===f&&x.renderFailedFolder===h)return x.row;const g=Nt(l,f,m,d,h===void 0?void 0:h(l));return e.set(l,{row:g,open:m,childrenStatus:d,children:f,renderFailedFolder:h}),g};return(l,i)=>s(l,i,"")},qt=e=>{if(e===void 0)return;const t=n=>{const a=n.data?.aqmxModifiedAt;return typeof a=="number"?{name:n.name,path:n.absolutePath,type:n.type,modifiedAt:a}:{name:n.name,path:n.absolutePath,type:n.type}};return(n,a)=>e(t(n),t(a))},Re=(e,t)=>{const n=e.filter(a=>a.type==="directory");return t===void 0?n:n.sort(t)},Mt=(e,t)=>{const n=new Map;let a=0;const s=u=>{for(const o of Re(u,t.compare))if(t.isShownExpanded(o.path)){if(o.lazy!==!0){o.children!==void 0&&s(o.children);continue}n.has(o.path)||(n.set(o.path,t.isDirect(o.path)?"direct":"bulk"),t.childrenOf(o.path)?.status!=="failed"&&(a+=1))}};return s(e),{folders:n,waiting:a}},Ft=e=>{const t=new Set,n=a=>{for(const s of a)s.type==="directory"&&(s.lazy===!0&&t.add(s.path),s.children!==void 0&&n(s.children))};return n(e),t},Be=(e,t)=>{for(const n of e){if(n.type!=="directory")continue;if(n.path===t)return n;const a=n.children===void 0?null:Be(n.children,t);if(a!==null)return a}return null},_t=(e,t,n,a)=>{let s=e;for(const u of t){const o=s.find(l=>l.type==="directory"&&l.path===u);if(o===void 0)return"missing";if(o.lazy===!0)return a.childrenOf(o.path)?.status==="failed"?"failed":"loading";if(!a.isShownExpanded(o.path))return"loading";s=o.children??[]}return s.some(u=>u.type==="file"&&u.path===n)?"ready":"missing"},qe=new Set,It=(e,t)=>e.has(t)?e:new Set(e).add(t),Dt=(e,t)=>{if(!t.some(a=>e.has(a)))return e;const n=new Set(t);return new Set([...e].filter(a=>!n.has(a)))},Ht=(e,t)=>[...e].every(n=>t.has(n))?e:new Set([...e].filter(n=>t.has(n))),Zt=()=>{const[e,t]=r.useState(qe),n=r.useCallback(o=>t(l=>It(l,o)),[]),a=r.useCallback(o=>t(l=>Dt(l,o)),[]),s=r.useCallback(o=>t(l=>Ht(l,o)),[]),u=r.useCallback(()=>t(qe),[]);return r.useMemo(()=>({direct:e,markDirect:n,unmarkDirect:a,pruneDirect:s,clearDirect:u}),[e,n,a,s,u])},$t=e=>({budget:e,handled:new Set,loads:new Set,opened:0,folderLimited:!1,depthLimited:!1,announcedStart:!1,issuedAgainst:null}),Bt=(e,t)=>{const n=[];let a=Re(t.entries,t.compare);for(let s=1;a.length>0;s+=1){const u=[];for(const o of a){const{path:l}=o;if(t.isShownExpanded(l))e.handled.add(l);else{if(e.handled.has(l))continue;if(e.handled.add(l),o.lazy===!0&&t.childrenOf(l)===void 0){if(s>e.budget.maxDepth){e.depthLimited=!0;continue}if(e.loads.size>=e.budget.maxFolders){e.folderLimited=!0;continue}e.loads.add(l)}n.push(l),e.opened+=1}o.lazy!==!0&&o.children!==void 0&&u.push(...Re(o.children,t.compare))}a=u}return n},ze=(e,t)=>e.every(n=>n.type!=="directory"||t(n.path)&&(n.lazy===!0||n.children===void 0||ze(n.children,t))),zt=(e,t)=>{if(e.folderLimited)return{kind:"folder-limit",opened:e.opened};if(e.depthLimited)return{kind:"depth-limit",opened:e.opened};let n=0;for(const a of e.loads)t.childrenOf(a)?.status==="failed"&&(n+=1);return{kind:"done",opened:e.opened,failed:n,complete:ze(t.entries,t.isShownExpanded)}},ve=Object.freeze({state:"idle"}),Vt=e=>{const t=r.useRef(null),n=r.useRef(e),[a,s]=r.useState(ve);r.useLayoutEffect(()=>{n.current=e});const u=r.useCallback(()=>{t.current===null&&(t.current=$t(n.current.budget),s({state:"running",opened:0}))},[]),o=r.useCallback(()=>{t.current=null,s(ve)},[]),l=r.useCallback(i=>{const f=t.current;if(f===null)return;const m=Bt(f,i);if(m.length>0&&(f.issuedAgainst=i.expanded,n.current.expandMultiple([...m])),!f.announcedStart&&(f.loads.size>0||i.waiting>0)&&(f.announcedStart=!0,n.current.onStart()),m.length===0&&!i.expansionPending&&i.expanded!==f.issuedAgainst&&i.waiting===0){t.current=null;const h=zt(f,i);s(h.kind==="done"?ve:{state:"stopped",stop:h.kind,opened:h.opened}),n.current.onFinish(h);return}const{opened:d}=f;s(h=>h.state==="running"&&h.opened===d?h:{state:"running",opened:d})},[]);return r.useMemo(()=>({status:a,start:u,end:o,advance:l}),[a,u,o,l])},Me=["pointerdown","wheel","touchstart","keydown","focusin"],Kt=8,Fe={least:Number.POSITIVE_INFINITY,stalled:0},Xt=({tree:e,container:t,path:n,chain:a,rows:s,cancel:u,displayed:o,placement:l})=>{const i=r.useRef(null),f=r.useRef(!0),m=r.useRef(Fe),d=r.useRef(null),h=r.useRef(null),x=r.useRef(a),g=r.useRef(l);r.useLayoutEffect(()=>{x.current=a,g.current=l},[a,l]);const E=r.useCallback(()=>{const y=d.current;y!==null&&(d.current=null,y.phase==="asking"?y.controller.abort():x.current?.open(null))},[]),j=r.useCallback(()=>{i.current=null,E()},[E]),L=r.useCallback(()=>{const y=t.current;i.current===null||h.current!==null||y===null||y.getClientRects().length===0||(h.current=requestAnimationFrame(()=>{h.current=null;const T=i.current;if(T===null)return;const S=g.current(T);if(S===0){f.current=!0,d.current?.phase==="opening"&&E();return}if(e.current?.scrollToPath(T,{align:"nearest"})===!0){d.current?.phase==="opening"&&E();const{least:q,stalled:_}=m.current;m.current=S<q?{least:S,stalled:0}:{least:q,stalled:_+1},m.current.stalled<Kt&&L();return}const b=d.current;if(b===null){i.current=null;return}b.phase==="opening"&&x.current?.progress(b.folders,T)!=="loading"&&j()}))},[e,t,E,j]),N=r.useCallback(()=>{f.current=!1,m.current=Fe,L()},[L]);r.useEffect(()=>{const y=t.current;if(y===null)return;const T=typeof ResizeObserver>"u"?null:new ResizeObserver(N);T?.observe(y);for(const S of Me)y.addEventListener(S,j,{passive:!0});return()=>{T?.disconnect();for(const S of Me)y.removeEventListener(S,j);h.current!==null&&cancelAnimationFrame(h.current),h.current=null,E()}},[t,N,j,E]);const R=a!==null;r.useEffect(()=>{const y=t.current;if(j(),n===null||y===null||y.contains(y.ownerDocument.activeElement))return;i.current=n;const T=x.current;if(R&&T!==null){const S=new AbortController,b={phase:"asking",controller:S};d.current=b,T.ancestors(n,S.signal).then(q=>{d.current===b&&(q===null?d.current=null:(d.current={phase:"opening",folders:q},x.current?.open(q)),N())})}N()},[n,R,t,j,N]),r.useEffect(()=>{(d.current?.phase==="opening"||i.current!==null&&!f.current)&&N()},[s,N]);const F=r.useRef(u);r.useEffect(()=>{F.current!==u&&(F.current=u,j())},[u,j]);const C=r.useRef(o);r.useEffect(()=>{C.current&&!o&&E(),C.current=o},[o,E])},Wt="--aqmx-tree-line",Gt=Object.freeze(["(forced-colors: active)","(prefers-color-scheme: dark)"]),Ut="data-aqmx-tree-probe",Yt=Object.freeze({rowHeight:A.CONTROL_BLOCK_PIXELS,lineColor:null}),Qt=/^rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)$/u,Jt=e=>{const t=Qt.exec(e);return t===null?e:`#${t.slice(1).map(n=>Number(n).toString(16).padStart(2,"0")).join("")}`},en=(e,t)=>{const[n,a]=r.useState(Yt);return r.useLayoutEffect(()=>{const s=e.current;if(s===null)return;const u=()=>{const i=Math.round(s.getBoundingClientRect().height),f=getComputedStyle(s),m=f.getPropertyValue(Wt).trim()===""?null:Jt(f.color);a(d=>{const h=Number.isFinite(i)&&i>0?i:d.rowHeight;return d.rowHeight===h&&d.lineColor===m?d:{rowHeight:h,lineColor:m}})};u();const o=Gt.map(i=>window.matchMedia(i));for(const i of o)i.addEventListener("change",u);const l=typeof ResizeObserver>"u"?null:new ResizeObserver(u);return l?.observe(s),()=>{for(const i of o)i.removeEventListener("change",u);l?.disconnect()}},[e,t]),n},Ve="markdown-explorer-tree-scroll",tn=.5,Ke=(e,t)=>[...e.querySelectorAll(`[role="treeitem"][${re}]`)].find(n=>n.getAttribute(re)===t),nn=(e,t)=>{const n=Ke(e,t),a=n?.closest(`[data-testid="${Ve}"]`);if(n===void 0||a===null||a===void 0)return Number.POSITIVE_INFINITY;const s=a.getBoundingClientRect(),u=n.getBoundingClientRect(),o=s.top-u.top,l=u.height>s.height?Math.abs(o):Math.max(0,o)+Math.max(0,u.bottom-s.bottom);return l<=tn?0:l},rn={testId:Ve,overscanCount:13,callbackThrottleMs:13,scrollBarOptions:{width:8,enableTrackClick:!0,enableThumbDrag:!0,enableArrowButtons:!0,enableArrowButtonTabStops:!1,enableScrollToTopBottomButtons:!0,tapScrollCircleOptions:mt.TAP_SCROLL_CIRCLE},behaviorOptions:{enablePointerDrag:!0}},an={hoverClassName:"",directorySelectedClassName:"",itemSelectedClassName:""},ln={color:"inherit",fontSize:"inherit"},on={fontSize:"inherit"},sn=new Set,cn=new Map,un={color:"var(--aqmx-tree-line)"},dn=e=>{const t=e instanceof Element?e.closest(`[${re}]`):null;return t===null||t.getAttribute("data-entry-type")!=="file"?null:t.getAttribute(re)},Xe=(e,t,n,a)=>n==="folder-limit"?e.expandAllFolderLimit(a,t.maxFolders,e.expandAll):e.expandAllDepthLimit(a,t.maxDepth),fn=(e,t,n)=>n.kind==="done"?e.expandAllDone(n.opened,n.failed,n.complete):Xe(e,t,n.kind,n.opened),We=()=>{const{labels:e}=v.useExplorer();return c.jsxs("div",{className:"aqmx-explorer-loading","aria-busy":"true","data-testid":"markdown-explorer-tree-loading",children:[c.jsx("p",{className:"aqmx-explorer-loading-text",children:e.treeLoading}),c.jsxs("div",{className:"aqmx-skeleton","aria-hidden":"true",children:[c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{})]})]})},mn=()=>{const{labels:e}=v.useExplorer();return c.jsxs("div",{className:"aqmx-empty","data-testid":"markdown-explorer-tree-empty",children:[c.jsx(Tt,{className:"aqmx-explorer-empty-icon","aria-hidden":"true"}),c.jsx("p",{className:"aqmx-empty-title",children:e.treeEmptyTitle}),c.jsx("p",{className:"aqmx-explorer-empty-body",children:e.treeEmptyBody})]})},pn=({name:e,onRetry:t})=>{const{labels:n}=v.useExplorer(),a=r.useId();return c.jsxs("span",{className:"aqmx-explorer-folder-failed",children:[c.jsx("span",{className:"aqmx-explorer-folder-name",children:e}),c.jsx("span",{id:a,className:"aqmx-explorer-folder-error",children:n.folderLoadFailed}),c.jsxs("button",{type:"button",className:"aqmx-explorer-folder-retry","aria-describedby":a,"data-testid":"markdown-explorer-folder-retry",onClick:s=>{s.stopPropagation();const u=s.currentTarget,o=u.ownerDocument.activeElement===u?u.closest('[role="treeitem"]'):null;o instanceof HTMLElement&&v.focusWithoutScroll(o),t()},onKeyDown:s=>{s.key!=="Escape"&&s.stopPropagation()},children:[c.jsx(v.ForwardRef,{className:"aqmx-explorer-folder-retry-icon","aria-hidden":"true"}),c.jsx("span",{className:"aqmx-explorer-folder-retry-text",children:n.retry})]})]})},hn=({entries:e,version:t,mode:n,sourceId:a,settings:s,reveal:u,openPaths:o,selection:l,onOpenDocument:i,folders:f,onRevealSource:m,expansion:d,onShown:h,marks:x,claimsHeld:g,expandAll:E,revealCancel:j})=>{const{trees:L,documents:N,labels:R,locale:F,theme:C,data:y,config:T,sources:S,reveals:b}=v.useExplorer(),q=r.use(ye),[_]=r.useState(At),ae=r.useRef(null),{rowHeight:Q,lineColor:Z}=en(ae,C),{isExpanded:$,toggle:J,expandMultiple:I,collapseMultiple:X,expanded:W,isPending:G}=d,{alwaysExpanded:O,sortMode:ee,folderPlacement:le,readmePlacement:ue}=s,{direct:te,markDirect:B,unmarkDirect:U,pruneDirect:fe}=x,{running:oe,advance:se}=E,de=r.useRef(null),ne=r.useRef(null),z=r.useMemo(()=>A.createEntryComparator({sortMode:ee,folderPlacement:le,readmePlacement:ue}),[ee,le,ue]),P=r.useMemo(()=>qt(z),[z]),M=r.useCallback(w=>L.children(a,w),[L,a]),D=r.useMemo(()=>Ft(e),[e]),Y=r.useCallback(w=>!ie(w)&&($(w)||O&&!D.has(w)),[$,O,D]),V=r.useRef({shownExpanded:Y,isExpanded:$,unloadedFolders:D,entries:e,childrenOf:M});r.useLayoutEffect(()=>{V.current={shownExpanded:Y,isExpanded:$,unloadedFolders:D,entries:e,childrenOf:M}},[Y,$,D,e,M]);const Ce=r.useCallback(w=>{de.current?.scrollToPath(w,{align:"nearest"}),requestAnimationFrame(()=>{const k=ne.current,H=k===null?void 0:Ke(k,w);H!==void 0&&v.focusWithoutScroll(H)})},[]),tt=r.useCallback(w=>{if(ie(w)){Ce(Pt(w));return}V.current.isExpanded(w)?U([w]):V.current.unloadedFolders.has(w)&&B(w),J(w)},[Ce,B,U,J]),ge=r.useCallback(w=>{const k=w.filter(H=>!ie(H));k.length!==0&&(U(k),X(k))},[U,X]),nt=r.useCallback(w=>{const k=w.filter(H=>!ie(H));k.length!==0&&(k.length<w.length&&k.every(H=>V.current.shownExpanded(H))?ge(k):I(k))},[I,ge]),Te=r.useCallback(w=>c.jsx(pn,{name:w.name,onRetry:()=>{B(w.path),L.retryChildren(a,w.path),V.current.shownExpanded(w.path)||I([w.path])}}),[L,a,B,I]),Le=n==="multi"?o:sn,{loopFolderName:je}=R,rt=r.useMemo(()=>_(e,{openPaths:Le,childrenOf:M,renderFailedFolder:Te,loopFolderName:je}),[_,e,Le,M,Te,je,t]),at=v.useIntentPrefetch(N,dn),Pe=r.useRef([]),me=r.useCallback(()=>{for(const w of Pe.current)V.current.unloadedFolders.has(w)&&B(w)},[B]),{maxDepth:Ee}=T.revealDocument,Ne=r.useRef(m);r.useLayoutEffect(()=>{Ne.current=m},[m]);const lt=r.useMemo(()=>({ancestors:async(w,k)=>{const H=b.take(a,w);if(H!==null)return H;if(!b.mayMove(w)){const ce=await y.ancestors(a,w,k);return ce.status!=="ok"||ce.ancestors===null||ce.ancestors.length>Ee?null:ce.ancestors}const K=await y.reveal(a,w,k);return K.status!=="ok"||K.source===null||K.ancestors.length>Ee?null:K.source===a?K.ancestors:(k.aborted||!S.some(ce=>ce.id===K.source)||(b.move(K.source,w,K.ancestors),Ne.current(K.source)),null)},open:w=>{Pe.current=w??[],w!==null&&(me(),I([...w]))},progress:(w,k)=>_t(V.current.entries,w,k,{isShownExpanded:V.current.shownExpanded,childrenOf:V.current.childrenOf})}),[y,a,S,b,Ee,me,I]);r.useEffect(()=>me(),[me,D]);const ot=r.useMemo(()=>[e,t,W],[e,t,W]),st=r.useCallback(w=>ne.current===null?Number.POSITIVE_INFINITY:nn(ne.current,w),[]);Xt({tree:de,container:ne,path:u.path,chain:u.openFolders?lt:null,rows:ot,cancel:j,displayed:q,placement:st});const Oe=r.useCallback(w=>te.has(w),[te]),pe=r.useMemo(()=>Mt(e,{isShownExpanded:Y,childrenOf:M,compare:z,isDirect:Oe}),[e,Y,M,z,Oe,t]),he=q&&g;r.useLayoutEffect(()=>{h(e)},[e,h]),r.useLayoutEffect(()=>()=>h(null),[h]),r.useEffect(()=>L.claimChildren(a,he?pe.folders:cn),[L,a,he,pe]),r.useEffect(()=>fe(D),[fe,D]),r.useEffect(()=>{he&&oe&&se({entries:e,isShownExpanded:Y,childrenOf:M,compare:z,expanded:W,waiting:pe.waiting,expansionPending:G})},[he,oe,se,e,Y,M,z,W,pe,G]);const ct=r.useCallback(w=>{const k=w.entry.absolutePath;if(w.isDirectory){if(f===null||ie(k)||k===f.current)return;w.isExpanded&&w.preventDefault(),b.settle(k),f.open(k);return}b.settle(k),i(k)},[b,i,f]),{onChange:be}=l,it=r.useMemo(()=>be===null?void 0:(w,k)=>{ie(w.absolutePath)||be({path:w.absolutePath,name:w.name,selected:k})},[be]),ut=r.useMemo(()=>new Set(l.items),[l.items]),dt=r.useMemo(()=>({entryKindDirectory:R.treeEntryKindDirectory,entryKindFile:R.treeEntryKindFile,scrollUp:R.treeScrollUp,scrollDown:R.treeScrollDown,scrollToTop:R.treeScrollToTop,scrollToBottom:R.treeScrollToBottom}),[R]),ft=Z===null?{showTreeLines:!1}:{showTreeLines:s.lines,lineColor:Z};return c.jsxs("div",{ref:ne,className:"aqmx-explorer-tree","data-testid":"markdown-explorer-tree",...at,children:[c.jsx("span",{ref:ae,className:"aqmx-explorer-tree-probe","aria-hidden":"true",[Ut]:""}),c.jsx(He.DirectoryTree,{ref:de,entries:rt,expansion:{toggle:tt,isExpanded:Y,expandMultiple:nt,collapseMultiple:ge,isPending:G&&!oe,doubleClickAction:s.doubleClickAction},selection:{mode:l.mode,selectedPath:l.shownPath,currentPath:l.shownPath,selectedItems:ut,onEntryClick:ct,onSelectionChange:it},visual:{className:"aqmx-explorer-tree-view",ariaLabel:R.treeRegion,...ft,showExpandIcons:s.expandIcons,expandIconStyle:un,showDirectoryIcons:s.directoryIcons,showFileIcons:s.fileIcons,expandIconSize:s.expandIconSize,itemHeight:Q,removeRootIndent:s.removeRootIndent,highlightStyles:an,entryStyle:on,nameStyle:ln},virtualScroll:rn,sort:P,locale:F,labels:dt})]})},xn=({pending:e,status:t})=>{const{labels:n}=v.useExplorer(),a=t.state!=="running",[s,u]=r.useState(0),o=r.useRef(!0);r.useLayoutEffect(()=>{const i=o.current;if(o.current=a,!a||e>0&&!i){u(0);return}if(e>0){u(e);return}if(s===0)return;const f=setTimeout(()=>u(0),0);return()=>clearTimeout(f)},[a,e,s]);const l=a&&e===0?s:e;return l===0&&a?null:c.jsxs("p",{className:"aqmx-explorer-tree-progress","data-testid":"markdown-explorer-tree-progress","data-aqmx-loading":String(l),"data-aqmx-expand-all":t.state,children:[l>0?c.jsx(v.ForwardRef,{className:"aqmx-explorer-tree-progress-icon","aria-hidden":"true"}):null,c.jsx("span",{children:t.state==="running"?n.expandAllProgress(t.opened,l):n.foldersLoading(l)})]})},wn=({stop:e,opened:t,budget:n})=>{const{labels:a}=v.useExplorer();return c.jsx("p",{className:"aqmx-explorer-expand-all-stop","data-testid":"markdown-explorer-expand-all-stop","data-aqmx-stop":e,children:Xe(a,n,e,t)})},gn=({entries:e,...t})=>{const{trees:n}=v.useExplorer(),a=r.useSyncExternalStore(n.subscribe,n.version,n.version),{sourceId:s}=t,[u]=r.useState(Lt),o=r.useMemo(()=>u(e,l=>n.children(s,l)),[u,e,n,s,a]);return o.length===0?c.jsx(mn,{}):c.jsx(hn,{entries:o,version:a,...t})},En=({result:e,onRetry:t,...n})=>{const{renderTreeFailure:a}=v.useExplorer(),s=r.use(e);if(s.status==="deferred")return c.jsx(We,{});if(s.status==="ok")return c.jsx(gn,{entries:s.entries,...n});const u=a?.(s.failure);return c.jsx("div",{className:"aqmx-explorer-tree-message","data-testid":"markdown-explorer-tree-failure","data-aqmx-failure":s.failure.reason,children:u!==void 0?u:c.jsx(v.FailureView,{failure:s.failure,alert:!0,onRetry:t,testId:null})})},bn=({onControls:e,...t})=>{const{trees:n,storageNamespace:a,labels:s,announcer:u,config:o}=v.useExplorer(),{sourceId:l}=t,i=He.useDirectoryTreeState({storageKey:pt.storageKeys(a).treeExpansion(l)});r.useSyncExternalStore(n.subscribe,n.version,n.version);const f=n.read(l),m=r.useCallback(()=>n.retry(l),[n,l]);r.useLayoutEffect(()=>n.open(l),[n,l]);const d=Zt(),{expanded:h,expandMultiple:x,collapseAll:g}=i,[E,j]=r.useState(null),L=E!==h,N=r.useRef(h);r.useLayoutEffect(()=>{N.current=h},[h]);const R=o.expandAll,F=r.useCallback(()=>u.announce(s.expandAllStarted),[u,s]),C=r.useCallback(O=>u.announce(fn(s,R,O)),[u,s,R]),y=Vt({budget:R,expandMultiple:x,onStart:F,onFinish:C}),{status:T,start:S,end:b,advance:q}=y,_=T.state==="running",ae=r.useMemo(()=>({running:_,advance:q}),[_,q]),Q=r.useRef(null),[Z,$]=r.useState(!1),J=r.useCallback(O=>{Q.current=O,$(O!==null)},[]);r.useEffect(()=>n.subscribeChildrenFailures(O=>{const ee=O.sourceId===l&&Q.current!==null?Be(Q.current,O.path):null;ee!==null&&u.announce({list:s.foldersLoadFailedNamed,item:ee.name})}),[n,l,u,s]);const{clearDirect:I}=d,[X,W]=r.useState(0),G=r.useCallback(()=>{W(O=>O+1),b(),I(),j(N.current),g()},[b,I,g]);return r.useEffect(()=>{e({collapseAll:G,expandAll:Z?S:null,expanding:_})},[e,G,S,Z,_]),r.useEffect(()=>()=>e(null),[e]),r.useEffect(()=>{Z||b()},[Z,b]),c.jsxs(c.Fragment,{children:[T.state==="stopped"?c.jsx(wn,{stop:T.stop,opened:T.opened,budget:R}):null,c.jsxs("div",{className:"aqmx-explorer-tree-area",children:[c.jsx(r.Suspense,{fallback:c.jsx(We,{}),children:c.jsx(En,{result:f,onRetry:m,expansion:i,onShown:J,marks:d,claimsHeld:L,expandAll:ae,revealCancel:X,...t})}),c.jsx(xn,{pending:n.pendingChildren(l),status:T})]})]})};function vn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Ge=p.forwardRef(vn),_e="markdown-explorer-selection-remove",Rn=({selection:e,onRemove:t,onClear:n,onOpenSelection:a,onLeave:s})=>{const{labels:u}=v.useExplorer(),o=r.useId(),l=r.useRef(null),i=[...e],f=(d,h)=>{if(h.ownerDocument.activeElement===h){const x=l.current===null?[]:[...l.current.querySelectorAll(`[data-testid="${_e}"]`)],g=x.indexOf(h),E=[x[g+1],x[g-1]].find(j=>j!==void 0);E===void 0?s():E.focus()}t(d)},m=()=>{const d=l.current;d!==null&&d.contains(d.ownerDocument.activeElement)&&s(),n()};return c.jsxs("section",{ref:l,className:"aqmx-explorer-tray","aria-labelledby":o,"data-testid":"markdown-explorer-selection-tray",children:[c.jsxs("div",{className:"aqmx-explorer-tray-header",children:[c.jsx("p",{id:o,className:"aqmx-explorer-tray-title",children:u.selectionTitle(i.length)}),c.jsx("button",{type:"button",className:"aqmx-explorer-tray-button","data-testid":"markdown-explorer-selection-clear",onClick:m,children:u.clearSelection})]}),c.jsx("ul",{className:"aqmx-explorer-tray-list",children:i.map(([d,h])=>c.jsxs("li",{className:"aqmx-explorer-tray-item",children:[c.jsx("span",{className:"aqmx-explorer-tray-name",title:d,children:h}),c.jsx("button",{type:"button",className:"aqmx-icon-button aqmx-explorer-tray-remove","aria-label":u.removeFromSelection(h),title:u.removeFromSelection(h),"data-testid":_e,"data-aqmx-path":d,onClick:x=>f(d,x.currentTarget),children:c.jsx(Ge,{"aria-hidden":"true"})})]},d))}),a===void 0?null:c.jsx("button",{type:"button",className:"aqmx-explorer-tray-open","data-testid":"markdown-explorer-selection-open",onClick:()=>a(i.map(([d])=>d)),children:u.openSelectionInMulti(i.length)})]})},we=new Map,yn=(e,t)=>{if(t.selected===e.has(t.path))return e;const n=new Map(e);return t.selected?n.set(t.path,t.name):n.delete(t.path),n},Sn=(e,t)=>{if(!e.has(t))return e;const n=new Map(e);return n.delete(t),n},Ue=r.createContext(null),kn=e=>{const t=r.use(Ue);r.useLayoutEffect(()=>{if(t!==null)return t(e),()=>t(!1)},[t,e])};function Cn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.createElement("path",{fillRule:"evenodd",d:"M15 3.75a.75.75 0 0 1 .75-.75h4.5a.75.75 0 0 1 .75.75v4.5a.75.75 0 0 1-1.5 0V5.56l-3.97 3.97a.75.75 0 1 1-1.06-1.06l3.97-3.97h-2.69a.75.75 0 0 1-.75-.75Zm-12 0A.75.75 0 0 1 3.75 3h4.5a.75.75 0 0 1 0 1.5H5.56l3.97 3.97a.75.75 0 0 1-1.06 1.06L4.5 5.56v2.69a.75.75 0 0 1-1.5 0v-4.5Zm11.47 11.78a.75.75 0 1 1 1.06-1.06l3.97 3.97v-2.69a.75.75 0 0 1 1.5 0v4.5a.75.75 0 0 1-.75.75h-4.5a.75.75 0 0 1 0-1.5h2.69l-3.97-3.97Zm-4.94-1.06a.75.75 0 0 1 0 1.06L5.56 19.5h2.69a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1-.75-.75v-4.5a.75.75 0 0 1 1.5 0v2.69l3.97-3.97a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const Tn=p.forwardRef(Cn);function Ln({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 jn=p.forwardRef(Ln);function Pn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Nn=p.forwardRef(Pn);function On({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 An=p.forwardRef(On);function qn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Mn=p.forwardRef(qn);function Fn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 _n=p.forwardRef(Fn);function In({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Dn=p.forwardRef(In);function Hn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Zn=p.forwardRef(Hn);function $n({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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"}),p.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 Bn=p.forwardRef($n);function zn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Vn=p.forwardRef(zn);function Kn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Xn=p.forwardRef(Kn);function Wn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Gn=p.forwardRef(Wn);function Un({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Yn=p.forwardRef(Un),Qn=Object.freeze({sortMode:jn,folderPlacement:Vn,readmePlacement:Nn,selectionMode:An,doubleClickAction:Zn,expandIconSize:Gn,alwaysExpanded:Tn,revealDocument:v.ForwardRef$1,removeRootIndent:Mn,lines:Yn,expandIcons:_n,directoryIcons:Xn,fileIcons:Bn}),Ye=(e,t)=>{const n=e[t.labelKey];if(typeof n!="string")throw new TypeError(`[markdown-explorer] the tree setting ${t.key} must name a string label; labels.${t.labelKey} is a ${typeof n}`);return n},Jn=({id:e,settings:t,descriptors:n,onAdvance:a,onClose:s,ref:u})=>{const{labels:o}=v.useExplorer(),l=r.useRef([]);r.useEffect(()=>{l.current[0]?.focus()},[]);const i=r.useCallback(m=>{const d=n.length;l.current[(m%d+d)%d]?.focus()},[n.length]),f=r.useCallback((m,d)=>{switch(m.key){case"ArrowDown":m.preventDefault(),i(d+1);break;case"ArrowUp":m.preventDefault(),i(d-1);break;case"Home":m.preventDefault(),i(0);break;case"End":m.preventDefault(),i(n.length-1);break;case"Escape":v.consumeKey(m),s();break;case"Tab":s();break}},[n.length,i,s]);return c.jsx("div",{ref:u,id:e,role:"menu","aria-label":o.treeSettings,className:"aqmx-explorer-menu","data-testid":"markdown-explorer-tree-settings-menu",children:n.map((m,d)=>{const h=Qn[m.key],x=Ye(o,m),g=A.formatTreeSettingValue(o,t,m.key),E=t[m.key],j=typeof E=="boolean"?{role:"menuitemcheckbox","aria-checked":E,"aria-label":x}:{role:"menuitem","aria-label":`${x}: ${g}`};return c.jsxs("button",{ref:L=>{l.current[d]=L},type:"button",tabIndex:-1,...j,title:`${x}: ${g}`,className:"aqmx-explorer-menu-item","data-testid":"markdown-explorer-tree-settings-item","data-aqmx-setting":m.key,onClick:()=>a(m),onKeyDown:L=>f(L,d),children:[c.jsx(h,{className:"aqmx-explorer-menu-icon","aria-hidden":"true"}),c.jsx("span",{className:"aqmx-explorer-menu-name",children:x}),c.jsx("span",{className:"aqmx-explorer-menu-value",children:g})]},m.key)})})},er=({settings:e,descriptors:t,onAdvance:n})=>{const{labels:a,announcer:s}=v.useExplorer(),[u,o]=r.useState(!1),l=r.useRef(null),i=r.useRef(null),f=r.useRef(null),m=r.useId(),d=r.useCallback(()=>{l.current?.focus(),o(!1)},[]);r.useEffect(()=>{if(!u)return;const g=E=>{E.target instanceof Node&&(l.current?.contains(E.target)===!0||i.current?.contains(E.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)&&l.current?.focus()},0))};return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[u]),r.useEffect(()=>()=>{f.current!==null&&window.clearTimeout(f.current)},[]);const h=r.useCallback(g=>{g.key!=="Escape"||!u||(v.consumeKey(g),d())},[u,d]),x=r.useCallback(g=>{const E=n(g.key);s.announce(a.settingAnnouncement(Ye(a,g),A.formatTreeSettingValue(a,E,g.key)))},[s,a,n]);return{trigger:c.jsx("button",{ref:l,type:"button",className:"aqmx-icon-button","aria-haspopup":"menu","aria-expanded":u,"aria-controls":u?m:void 0,"aria-label":a.treeSettings,title:a.treeSettings,"data-testid":"markdown-explorer-tree-settings",onClick:()=>o(g=>!g),onKeyDown:h,children:c.jsx(Dn,{"aria-hidden":"true"})}),menu:u?c.jsx(Jn,{ref:i,id:m,settings:e,descriptors:t,onAdvance:x,onClose:d}):null}},tr=()=>{const{treeSettings:e}=v.useExplorer();return{settings:r.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getServerSnapshot),advance:e.advance}},Ie=new Set,nr='[role="tree"] [role="treeitem"][tabindex="0"]',rr="[data-directory-tree-tab-stop]",ar=e=>{const{mode:t,sourceId:n,currentPath:a,openPaths:s,onOpenDocument:u,onSourceChange:o,onRevealSource:l,viewSwitch:i}=e,{labels:f,sources:m,trees:d,documents:h,announcer:x,reveals:g}=v.useExplorer(),{settings:E,advance:j}=tr(),L=r.useMemo(()=>A.visibleTreeSettingDescriptors(t==="tree"),[t]),N=t==="tree"&&E.selectionMode==="multiple";kn(N);const R=e.mode==="tree"?e.tray.onGatheredChange:null,F=e.mode==="tree"?e.onOpenSelection:void 0,C=e.mode==="tree"?e.onOpenFolder:null,y=e.mode==="tree"&&e.currentFolder,T=r.useMemo(()=>C===null?null:{current:a,open:C},[C,a]),S=e.mode==="tree"&&N?e.tray.gathered:we,b=r.useCallback(P=>{const M=j(P);return M.selectionMode!=="multiple"&&R?.(we),M},[j,R]),q=er({settings:E,descriptors:L,onAdvance:b}),_=r.useCallback(P=>R?.(M=>yn(M,P)),[R]),ae=r.useCallback(P=>R?.(M=>Sn(M,P)),[R]),Q=r.useCallback(()=>R?.(we),[R]),Z=r.useRef(null),$=r.useCallback(()=>{const P=Z.current;if(P===null)return;[nr,rr,'[data-testid="markdown-explorer-tree-settings"]'].map(D=>P.querySelector(D)).find(D=>D!==null)?.focus()},[]),J=r.useMemo(()=>new Set(S.keys()),[S]),I=r.useMemo(()=>a===null?Ie:new Set([a]),[a]),X=r.useMemo(()=>{if(t==="multi")return{mode:"multiple",items:s,shownPath:null,onChange:null};switch(E.selectionMode){case"single":return{mode:"single",items:I,shownPath:a,onChange:null};case"multiple":return{mode:"multiple",items:J,shownPath:a,onChange:_};case"none":return{mode:"none",items:Ie,shownPath:null,onChange:null}}},[t,s,E.selectionMode,I,a,J,_]),W=r.useMemo(()=>E.revealDocument?{path:a,openFolders:!y}:{path:X.shownPath,openFolders:!1},[E.revealDocument,a,y,X.shownPath]),G=r.useCallback(P=>{a!==null&&g.settle(a),o(P)},[a,g,o]),[O,ee]=r.useState(null),[le,ue]=r.useState(!1),[te,B]=r.useState(null),U=r.useRef(!1),fe=r.useCallback(async()=>{if(!U.current){U.current=!0,ue(!0),B(null);try{const P=await d.refresh(n);if(P.status==="superseded")return;h.invalidate(),P.status==="failed"?B({sourceId:n,failure:P.failure}):x.announce(f.treeRefreshed)}finally{U.current=!1,ue(!1)}}},[d,h,n,x,f]),oe=O===null?null:O.expandAll,se=O?.expanding===!0,de=m.find(P=>P.id===n),ne=i.target==="multi"?St:Rt,z=i.target==="multi"?f.switchToMulti:f.switchToTree;return c.jsxs("nav",{ref:Z,"aria-label":f.explorerRegion,className:"aqmx-explorer","data-testid":"markdown-explorer-explorer","data-aqmx-mode":t,children:[c.jsxs("div",{className:"aqmx-explorer-header",children:[m.length>1?c.jsx("select",{className:"aqmx-explorer-source","aria-label":f.sourceLabel,title:de?.label,value:n,onChange:P=>G(P.currentTarget.value),"data-testid":"markdown-explorer-source-select",children:m.map(P=>c.jsx("option",{value:P.id,children:P.label},P.id))}):null,c.jsxs("div",{className:"aqmx-explorer-actions",children:[c.jsx(v.ExplorerLink,{to:i.href,navigation:"switch-view",className:"aqmx-icon-button","aria-label":z,title:z,"data-testid":"markdown-explorer-view-switch","data-aqmx-target":i.target,children:c.jsx(ne,{"aria-hidden":"true"})}),c.jsxs("button",{type:"button",className:"aqmx-icon-button aqmx-labelled-button",title:f.refreshTree,"aria-disabled":le,"aria-busy":le,"data-aqmx-busy":le?"true":void 0,"data-testid":"markdown-explorer-refresh",onClick:()=>{fe()},children:[c.jsx(v.ForwardRef,{"aria-hidden":"true"}),c.jsx("span",{children:f.refreshTreeLabel})]}),c.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.expandAll,title:f.expandAll,"aria-disabled":oe===null||se,"aria-busy":se,"data-aqmx-busy":se?"true":void 0,"data-testid":"markdown-explorer-expand-all",onClick:()=>oe?.(),children:c.jsx(bt,{"aria-hidden":"true"})}),c.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.collapseAll,title:f.collapseAll,"aria-disabled":O===null,"data-testid":"markdown-explorer-collapse-all",onClick:()=>O?.collapseAll(),children:c.jsx(gt,{"aria-hidden":"true"})}),q.trigger]})]}),c.jsxs("div",{className:"aqmx-explorer-body","data-aqmx-explorer-body":"",children:[te!==null&&te.sourceId===n?c.jsx("p",{role:"alert",className:"aqmx-explorer-refresh-failure","data-testid":"markdown-explorer-refresh-failure","data-aqmx-failure":te.failure.reason,children:f.treeRefreshFailed(v.failureTitleOf(f,te.failure.reason))}):null,c.jsx(r.Suspense,{fallback:null,children:c.jsx(kt,{})}),c.jsx(bn,{mode:t,sourceId:n,settings:E,reveal:W,openPaths:s,selection:X,onOpenDocument:u,folders:T,onRevealSource:l,onControls:ee},n),N&&S.size>0?c.jsx(Rn,{selection:S,onRemove:ae,onClear:Q,onOpenSelection:F,onLeave:$}):null,q.menu]})]})};function lr({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 or=p.forwardRef(lr),sr=({explorer:e,toggleRef:t,covered:n,onNoticeSlotChange:a,dismissals:s})=>{const{labels:u}=v.useExplorer(),o=ht.useLocation(),{location:l}=v.useExplorerLocation(),[i,f]=r.useState(!1),[m,d]=r.useState({navigated:o,source:l.source}),[h,x]=r.useState(!1);m.navigated!==o&&(d({navigated:o,source:l.source}),m.source===l.source&&!h&&f(!1));const[g,E]=r.useState(s);g!==s&&(E(s),f(!1));const j=r.useRef(null),L=r.useRef(null),N=r.useRef(null),R=r.useRef(!1),F=r.useId();r.useLayoutEffect(()=>{const b=j.current;b!==null&&(i&&!b.open?(b.showModal(),L.current?.focus()):!i&&b.open&&(b.close(),t.current?.focus()),a(i?N.current:null))},[i,t,a]),r.useLayoutEffect(()=>()=>a(null),[a]);const C=r.useCallback(b=>{b.key!=="Escape"||b.defaultPrevented||(v.consumeKey(b),f(!1))},[]),y=r.useCallback(b=>{R.current=b.target===b.currentTarget},[]),T=r.useCallback(b=>{const q=R.current;R.current=!1,q&&b.target===b.currentTarget&&f(!1)},[]),S=r.useCallback(()=>{f(!1)},[]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"aqmx-sheet-bar",inert:n,children:c.jsxs("button",{ref:t,type:"button",className:"aqmx-sheet-toggle","aria-haspopup":"dialog","aria-expanded":i,"aria-controls":F,"data-testid":"markdown-explorer-sheet-toggle",onClick:()=>f(!0),children:[c.jsx(or,{"aria-hidden":"true"}),c.jsx("span",{children:u.showExplorer})]})}),c.jsx("dialog",{ref:j,id:F,className:"aqmx-sheet","aria-label":u.explorerRegion,"data-testid":"markdown-explorer-sheet",onKeyDown:C,onPointerDown:y,onClick:T,onClose:S,children:c.jsxs("div",{className:"aqmx-sheet-panel",children:[c.jsxs("div",{className:"aqmx-sheet-header",children:[c.jsx("div",{ref:N,className:"aqmx-sheet-notice-slot"}),c.jsx("button",{ref:L,type:"button",className:"aqmx-sheet-close","aria-label":u.hideExplorer,title:u.hideExplorer,"data-testid":"markdown-explorer-sheet-close",onClick:()=>f(!1),children:c.jsx(Ge,{"aria-hidden":"true"})})]}),c.jsx("div",{className:"aqmx-sheet-body",children:c.jsx(ye,{value:i,children:c.jsx(Ue,{value:x,children:e})})}),c.jsx(v.LiveRegion,{holds:i,testId:"markdown-explorer-sheet-announcer"})]})})]})},Qe=r.createContext(null),Se="aqmx-explorer",Je="aqmx-content",cr="--aqmx-split-band",ke='[role="tree"] [role="treeitem"]',ir=`${ke}[tabindex="0"]`,ur="[data-directory-tree-tab-stop]",dr=(e,t)=>{for(const n of e.querySelectorAll(`[data-panel-id="${Se}"] ${ke}`))if(n.getAttribute(re)===t)return n;return null},De=(e,t)=>({inlineSize:e>0?e:null,rootFontPixels:t>0?t:A.ASSUMED_ROOT_FONT_PIXELS}),fr=(e,t)=>{const[n,a]=r.useState(()=>De(0,0));return r.useLayoutEffect(()=>{const s=e.current,u=t.current;if(s===null||u===null)throw new Error("[markdown-explorer] the split frame is not mounted");const o={frame:s.getBoundingClientRect().width,rem:u.getBoundingClientRect().width},l=()=>{const f=De(o.frame,o.rem);a(m=>m.inlineSize===f.inlineSize&&m.rootFontPixels===f.rootFontPixels?m:f)};l();const i=new ResizeObserver(f=>{for(const m of f){const[d]=m.borderBoxSize;d!==void 0&&(m.target===s&&(o.frame=d.inlineSize),m.target===u&&(o.rem=d.inlineSize))}l()});return i.observe(s),i.observe(u),()=>i.disconnect()},[e,t]),n},et=e=>`aqmx-split-handle-${e}`,mr=(e,{frameRef:t,sheetToggleRef:n,handleId:a})=>{const s=r.useRef(!1),u=r.useRef(null),o=r.useRef(!1);r.useLayoutEffect(()=>{const i=t.current;if(i===null)throw new Error("[markdown-explorer] the split frame is not mounted");const f=d=>{const h=d.target instanceof Element?d.target:null;s.current=h!==null&&h.closest(`[data-panel-id="${Je}"]`)===null,!o.current&&(u.current=h?.closest(`${ke}[${re}]`)?.getAttribute(re)??null)},m=d=>{d.relatedTarget instanceof Node&&!i.contains(d.relatedTarget)&&(s.current=!1)};return i.addEventListener("focusin",f),i.addEventListener("focusout",m),()=>{i.removeEventListener("focusin",f),i.removeEventListener("focusout",m)}},[t]);const l=r.useRef(e);r.useLayoutEffect(()=>{if(l.current===e)return;l.current=e;const i=t.current;if(i===null||!s.current)return;const f=m=>{const{activeElement:d,body:h}=i.ownerDocument;if(d!==null&&d!==h)return;const x=m.find(g=>g!==null);if(x!=null){o.current=!0;try{x.focus()}finally{o.current=!1}}};if(e){f([n.current]);return}queueMicrotask(()=>{if(l.current!==e||!s.current)return;const m=u.current,d=`[data-panel-id="${Se}"]`;f([m===null?null:dr(i,m),i.querySelector(`${d} ${ir}`),i.querySelector(`${d} ${ur}`),i.querySelector(`[data-resize-handle-id="${a}"]`)])})},[e,t,n,a])},pr=({view:e,explorer:t,content:n,contentCoversPage:a=!1,sheetDismissals:s=0,onDraggingChange:u})=>{const o=r.useRef(null),[l,i]=r.useState(null),f=r.useRef(null),m=r.useRef(null),{inlineSize:d,rootFontPixels:h}=fr(o,f),x=d!==null&&d<A.explorerSheetBelowPixels(h);return mr(x,{frameRef:o,sheetToggleRef:m,handleId:et(e)}),c.jsxs("div",{ref:o,className:"aqmx-split-frame","data-aqmx-explorer-mode":x?"sheet":"split",children:[c.jsx("span",{ref:f,className:"aqmx-rem-probe","aria-hidden":"true","data-aqmx-rem-probe":""}),x?c.jsx(sr,{explorer:t,toggleRef:m,covered:a,onNoticeSlotChange:i,dismissals:s}):null,c.jsx(Qe,{value:x?l:null,children:c.jsx(hr,{view:e,sheet:x,explorer:t,content:n,contentCoversPage:a,onDraggingChange:u,explorerMinPixels:A.explorerMinPixels(h)})})]})},hr=({view:e,sheet:t,explorer:n,content:a,contentCoversPage:s,onDraggingChange:u,explorerMinPixels:o})=>{const{viewSettings:l,labels:i}=v.useExplorer(),m=v.useViewSetting(C=>e==="tree"?C.treeExplorer:C.multiExplorer)??(e==="tree"?A.EXPLORER_DEFAULT_PERCENT:A.EXPLORER_MULTI_DEFAULT_PERCENT),d=r.useRef(!1),[h,x]=r.useState(!1),g=r.useRef(u);r.useLayoutEffect(()=>{g.current=u},[u]);const E=Ae.useSplitPersistence(r.useCallback(C=>{if(C.length!==2)return;const[y=0,T=0]=C,S=y+T;if(S<=0||y<=0)return;const b=Math.min(A.EXPLORER_MAX_PERCENT,y/S*100);l.update(e==="tree"?{treeExplorer:b}:{multiExplorer:b})},[l,e]));r.useEffect(()=>()=>{d.current&&g.current?.(!1)},[]);const L=Ae.useCoarsePointer()?A.COARSE_TARGET_PIXELS:A.FINE_TARGET_PIXELS,N=r.useMemo(()=>({[cr]:`${String(t?0:L)}px`}),[t,L]),R=r.useCallback((C,y)=>{const[T=0,S=0]=C;C.length===2&&S>0&&x(T<=0),E.layoutChanged(C,y)},[E]),F=r.useCallback(C=>{d.current=C,u?.(C),E.draggingChanged(C)},[u,E]);return c.jsxs(xe.PanelGroup,{id:`aqmx-split-${e}`,direction:"horizontal",onLayout:R,className:"aqmx-split",style:N,"data-aqmx-split":e,children:[t?null:c.jsx(xe.Panel,{id:Se,defaultSize:{value:m,unit:"percentage"},minSize:{value:o,unit:"pixels"},maxSize:{value:A.EXPLORER_MAX_PERCENT,unit:"percentage"},collapsible:{from:"end"},pixelAdjustPriority:1,inert:s,className:"aqmx-split-explorer",children:c.jsx(ye,{value:!h,children:n})}),t?null:c.jsx(xe.PanelResizeHandle,{id:et(e),thickness:L,indicator:{visible:!0,thickness:A.SPLIT_HANDLE_PIXELS.gripThickness,length:A.SPLIT_HANDLE_PIXELS.gripLength,barThickness:A.SPLIT_HANDLE_PIXELS.barThickness,barLength:A.SPLIT_HANDLE_PIXELS.barLength},title:i.resizeExplorer,"aria-label":i.resizeExplorer,onDragging:F,inert:s,className:"aqmx-split-handle"}),c.jsx(xe.Panel,{id:Je,defaultSize:{value:100-m,unit:"percentage"},contentOverflow:"hidden",className:"aqmx-split-content",...s?{style:{isolation:"auto"}}:{},children:a})]})};exports.EMPTY_SELECTION=we;exports.ExplorerPane=ar;exports.ExplorerSplit=pr;exports.SheetNoticeSlotContext=Qe;
1
+ "use strict";const c=require("react/jsx-runtime"),v=require("./index-ZdsIXJap.cjs"),r=require("react"),A=require("./location-CasigkBk.cjs"),He=require("@aiquants/directory-tree"),mt=require("./tapScrollCircle-C5DGI-0H.cjs"),pt=require("./storage-DM0EvkVf.cjs"),xe=require("@aiquants/resize-panels"),Ae=require("./useSplitPersistence-Bmpb2prR.cjs"),ht=require("react-router");function xt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const p=xt(r);function wt({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 gt=p.forwardRef(wt);function Et({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 bt=p.forwardRef(Et);function vt({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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"}),p.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 Rt=p.forwardRef(vt);function yt({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 St=p.forwardRef(yt),kt=()=>{const{notices:e}=v.useExplorer(),t=r.use(e);return t.length===0?null:c.jsx("div",{className:"aqmx-explorer-notices",children:t.map(n=>c.jsxs("div",{className:"aqmx-callout","data-aqmx-tone":n.tone,"data-testid":"markdown-explorer-notice","data-aqmx-notice":n.id,children:[c.jsx("p",{className:"aqmx-callout-title",children:n.title}),n.body===void 0?null:c.jsx("p",{className:"aqmx-callout-body",children:n.body}),n.action===void 0?null:c.jsx("a",{className:"aqmx-callout-action",href:n.action.href,children:n.action.label})]},n.id))})};function Ct({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Tt=p.forwardRef(Ct),ye=r.createContext(!0),Ze="\0loop\0",$e="\0",Lt=()=>{const e=new WeakMap,t=new WeakMap,n=new WeakMap,a=o=>{const l=e.get(o);if(l!==void 0)return l;const i=Object.freeze({type:"loop",name:o.name,path:o.path});return e.set(o,i),i},s=(o,l,i)=>{let f=!1;const m=o.map(h=>{const x=u(h,l,i);return x!==h&&(f=!0),x});if(!f)return o;const d=n.get(o);return d!==void 0&&d.length===m.length&&d.every((h,x)=>h===m[x])?d:(n.set(o,m),m)},u=(o,l,i)=>{if(o.type!=="directory")return o;if(i.has(o.path))return a(o);const f=o.lazy===!0?l(o.path):void 0,m=f?.status==="loaded",d=m?f.entries:o.children;if(d===void 0)return o;i.add(o.path);const h=s(d,l,i);if(i.delete(o.path),!m&&h===o.children)return o;const x=t.get(o);if(x!==void 0&&x.state===f&&x.children===h)return x.grafted;const g={...o,children:h,lazy:m?!1:o.lazy};return t.set(o,{state:f,children:h,grafted:g}),g};return(o,l)=>s(o,l,new Set)},jt=(e,t)=>`${Ze}${e}${$e}${t}`,ie=e=>e.startsWith(Ze),Pt=e=>e.slice(e.lastIndexOf($e)+1),re="data-aqmx-path",Nt=(e,t,n,a,s)=>{const u={aqmxPath:e.path};return e.modifiedAt!==void 0&&(u.aqmxModifiedAt=e.modifiedAt),n&&(u.aqmxOpen=!0),(a==="loading"||a==="failed")&&(u.aqmxChildren=a),{name:e.name,type:e.type,absolutePath:e.path,relativePath:e.path,mimeType:e.mimeType,children:t,label:s,data:u}},Ot=(e,t,n,a)=>{const s=jt(t,e.path);return{name:n,type:"directory",absolutePath:s,relativePath:s,children:a,data:{aqmxLoop:e.path}}},At=()=>{const e=new WeakMap,t=new WeakMap,n=new WeakMap,a=[],s=(l,i,f)=>{const m=l.map(h=>h.type==="loop"?u(h,i,f):o(h,i)),d=n.get(l);return d!==void 0&&d.length===m.length&&d.every((h,x)=>h===m[x])?d:(n.set(l,m),m)},u=(l,i,f)=>{const m=t.get(l);if(m!==void 0&&m.parentKey===f&&m.loopFolderName===i.loopFolderName)return m.row;const d=Ot(l,f,i.loopFolderName(l.name),a);return t.set(l,{row:d,parentKey:f,loopFolderName:i.loopFolderName}),d},o=(l,i)=>{const f=l.type==="directory"?l.children===void 0?a:s(l.children,i,l.path):void 0,m=i.openPaths.has(l.path),d=l.type==="directory"&&l.lazy===!0?i.childrenOf(l.path)?.status:void 0,h=d==="failed"?i.renderFailedFolder:void 0,x=e.get(l);if(x!==void 0&&x.open===m&&x.childrenStatus===d&&x.children===f&&x.renderFailedFolder===h)return x.row;const g=Nt(l,f,m,d,h===void 0?void 0:h(l));return e.set(l,{row:g,open:m,childrenStatus:d,children:f,renderFailedFolder:h}),g};return(l,i)=>s(l,i,"")},qt=e=>{if(e===void 0)return;const t=n=>{const a=n.data?.aqmxModifiedAt;return typeof a=="number"?{name:n.name,path:n.absolutePath,type:n.type,modifiedAt:a}:{name:n.name,path:n.absolutePath,type:n.type}};return(n,a)=>e(t(n),t(a))},Re=(e,t)=>{const n=e.filter(a=>a.type==="directory");return t===void 0?n:n.sort(t)},Mt=(e,t)=>{const n=new Map;let a=0;const s=u=>{for(const o of Re(u,t.compare))if(t.isShownExpanded(o.path)){if(o.lazy!==!0){o.children!==void 0&&s(o.children);continue}n.has(o.path)||(n.set(o.path,t.isDirect(o.path)?"direct":"bulk"),t.childrenOf(o.path)?.status!=="failed"&&(a+=1))}};return s(e),{folders:n,waiting:a}},Ft=e=>{const t=new Set,n=a=>{for(const s of a)s.type==="directory"&&(s.lazy===!0&&t.add(s.path),s.children!==void 0&&n(s.children))};return n(e),t},Be=(e,t)=>{for(const n of e){if(n.type!=="directory")continue;if(n.path===t)return n;const a=n.children===void 0?null:Be(n.children,t);if(a!==null)return a}return null},_t=(e,t,n,a)=>{let s=e;for(const u of t){const o=s.find(l=>l.type==="directory"&&l.path===u);if(o===void 0)return"missing";if(o.lazy===!0)return a.childrenOf(o.path)?.status==="failed"?"failed":"loading";if(!a.isShownExpanded(o.path))return"loading";s=o.children??[]}return s.some(u=>u.type==="file"&&u.path===n)?"ready":"missing"},qe=new Set,It=(e,t)=>e.has(t)?e:new Set(e).add(t),Dt=(e,t)=>{if(!t.some(a=>e.has(a)))return e;const n=new Set(t);return new Set([...e].filter(a=>!n.has(a)))},Ht=(e,t)=>[...e].every(n=>t.has(n))?e:new Set([...e].filter(n=>t.has(n))),Zt=()=>{const[e,t]=r.useState(qe),n=r.useCallback(o=>t(l=>It(l,o)),[]),a=r.useCallback(o=>t(l=>Dt(l,o)),[]),s=r.useCallback(o=>t(l=>Ht(l,o)),[]),u=r.useCallback(()=>t(qe),[]);return r.useMemo(()=>({direct:e,markDirect:n,unmarkDirect:a,pruneDirect:s,clearDirect:u}),[e,n,a,s,u])},$t=e=>({budget:e,handled:new Set,loads:new Set,opened:0,folderLimited:!1,depthLimited:!1,announcedStart:!1,issuedAgainst:null}),Bt=(e,t)=>{const n=[];let a=Re(t.entries,t.compare);for(let s=1;a.length>0;s+=1){const u=[];for(const o of a){const{path:l}=o;if(t.isShownExpanded(l))e.handled.add(l);else{if(e.handled.has(l))continue;if(e.handled.add(l),o.lazy===!0&&t.childrenOf(l)===void 0){if(s>e.budget.maxDepth){e.depthLimited=!0;continue}if(e.loads.size>=e.budget.maxFolders){e.folderLimited=!0;continue}e.loads.add(l)}n.push(l),e.opened+=1}o.lazy!==!0&&o.children!==void 0&&u.push(...Re(o.children,t.compare))}a=u}return n},ze=(e,t)=>e.every(n=>n.type!=="directory"||t(n.path)&&(n.lazy===!0||n.children===void 0||ze(n.children,t))),zt=(e,t)=>{if(e.folderLimited)return{kind:"folder-limit",opened:e.opened};if(e.depthLimited)return{kind:"depth-limit",opened:e.opened};let n=0;for(const a of e.loads)t.childrenOf(a)?.status==="failed"&&(n+=1);return{kind:"done",opened:e.opened,failed:n,complete:ze(t.entries,t.isShownExpanded)}},ve=Object.freeze({state:"idle"}),Vt=e=>{const t=r.useRef(null),n=r.useRef(e),[a,s]=r.useState(ve);r.useLayoutEffect(()=>{n.current=e});const u=r.useCallback(()=>{t.current===null&&(t.current=$t(n.current.budget),s({state:"running",opened:0}))},[]),o=r.useCallback(()=>{t.current=null,s(ve)},[]),l=r.useCallback(i=>{const f=t.current;if(f===null)return;const m=Bt(f,i);if(m.length>0&&(f.issuedAgainst=i.expanded,n.current.expandMultiple([...m])),!f.announcedStart&&(f.loads.size>0||i.waiting>0)&&(f.announcedStart=!0,n.current.onStart()),m.length===0&&!i.expansionPending&&i.expanded!==f.issuedAgainst&&i.waiting===0){t.current=null;const h=zt(f,i);s(h.kind==="done"?ve:{state:"stopped",stop:h.kind,opened:h.opened}),n.current.onFinish(h);return}const{opened:d}=f;s(h=>h.state==="running"&&h.opened===d?h:{state:"running",opened:d})},[]);return r.useMemo(()=>({status:a,start:u,end:o,advance:l}),[a,u,o,l])},Me=["pointerdown","wheel","touchstart","keydown","focusin"],Kt=8,Fe={least:Number.POSITIVE_INFINITY,stalled:0},Xt=({tree:e,container:t,path:n,chain:a,rows:s,cancel:u,displayed:o,placement:l})=>{const i=r.useRef(null),f=r.useRef(!0),m=r.useRef(Fe),d=r.useRef(null),h=r.useRef(null),x=r.useRef(a),g=r.useRef(l);r.useLayoutEffect(()=>{x.current=a,g.current=l},[a,l]);const E=r.useCallback(()=>{const y=d.current;y!==null&&(d.current=null,y.phase==="asking"?y.controller.abort():x.current?.open(null))},[]),j=r.useCallback(()=>{i.current=null,E()},[E]),L=r.useCallback(()=>{const y=t.current;i.current===null||h.current!==null||y===null||y.getClientRects().length===0||(h.current=requestAnimationFrame(()=>{h.current=null;const T=i.current;if(T===null)return;const S=g.current(T);if(S===0){f.current=!0,d.current?.phase==="opening"&&E();return}if(e.current?.scrollToPath(T,{align:"nearest"})===!0){d.current?.phase==="opening"&&E();const{least:q,stalled:_}=m.current;m.current=S<q?{least:S,stalled:0}:{least:q,stalled:_+1},m.current.stalled<Kt&&L();return}const b=d.current;if(b===null){i.current=null;return}b.phase==="opening"&&x.current?.progress(b.folders,T)!=="loading"&&j()}))},[e,t,E,j]),N=r.useCallback(()=>{f.current=!1,m.current=Fe,L()},[L]);r.useEffect(()=>{const y=t.current;if(y===null)return;const T=typeof ResizeObserver>"u"?null:new ResizeObserver(N);T?.observe(y);for(const S of Me)y.addEventListener(S,j,{passive:!0});return()=>{T?.disconnect();for(const S of Me)y.removeEventListener(S,j);h.current!==null&&cancelAnimationFrame(h.current),h.current=null,E()}},[t,N,j,E]);const R=a!==null;r.useEffect(()=>{const y=t.current;if(j(),n===null||y===null||y.contains(y.ownerDocument.activeElement))return;i.current=n;const T=x.current;if(R&&T!==null){const S=new AbortController,b={phase:"asking",controller:S};d.current=b,T.ancestors(n,S.signal).then(q=>{d.current===b&&(q===null?d.current=null:(d.current={phase:"opening",folders:q},x.current?.open(q)),N())})}N()},[n,R,t,j,N]),r.useEffect(()=>{(d.current?.phase==="opening"||i.current!==null&&!f.current)&&N()},[s,N]);const F=r.useRef(u);r.useEffect(()=>{F.current!==u&&(F.current=u,j())},[u,j]);const C=r.useRef(o);r.useEffect(()=>{C.current&&!o&&E(),C.current=o},[o,E])},Wt="--aqmx-tree-line",Gt=Object.freeze(["(forced-colors: active)","(prefers-color-scheme: dark)"]),Ut="data-aqmx-tree-probe",Yt=Object.freeze({rowHeight:A.CONTROL_BLOCK_PIXELS,lineColor:null}),Qt=/^rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)$/u,Jt=e=>{const t=Qt.exec(e);return t===null?e:`#${t.slice(1).map(n=>Number(n).toString(16).padStart(2,"0")).join("")}`},en=(e,t)=>{const[n,a]=r.useState(Yt);return r.useLayoutEffect(()=>{const s=e.current;if(s===null)return;const u=()=>{const i=Math.round(s.getBoundingClientRect().height),f=getComputedStyle(s),m=f.getPropertyValue(Wt).trim()===""?null:Jt(f.color);a(d=>{const h=Number.isFinite(i)&&i>0?i:d.rowHeight;return d.rowHeight===h&&d.lineColor===m?d:{rowHeight:h,lineColor:m}})};u();const o=Gt.map(i=>window.matchMedia(i));for(const i of o)i.addEventListener("change",u);const l=typeof ResizeObserver>"u"?null:new ResizeObserver(u);return l?.observe(s),()=>{for(const i of o)i.removeEventListener("change",u);l?.disconnect()}},[e,t]),n},Ve="markdown-explorer-tree-scroll",tn=.5,Ke=(e,t)=>[...e.querySelectorAll(`[role="treeitem"][${re}]`)].find(n=>n.getAttribute(re)===t),nn=(e,t)=>{const n=Ke(e,t),a=n?.closest(`[data-testid="${Ve}"]`);if(n===void 0||a===null||a===void 0)return Number.POSITIVE_INFINITY;const s=a.getBoundingClientRect(),u=n.getBoundingClientRect(),o=s.top-u.top,l=u.height>s.height?Math.abs(o):Math.max(0,o)+Math.max(0,u.bottom-s.bottom);return l<=tn?0:l},rn={testId:Ve,overscanCount:13,callbackThrottleMs:13,scrollBarOptions:{width:8,enableTrackClick:!0,enableThumbDrag:!0,enableArrowButtons:!0,enableArrowButtonTabStops:!1,enableScrollToTopBottomButtons:!0,tapScrollCircleOptions:mt.TAP_SCROLL_CIRCLE},behaviorOptions:{enablePointerDrag:!0}},an={hoverClassName:"",directorySelectedClassName:"",itemSelectedClassName:""},ln={color:"inherit",fontSize:"inherit"},on={fontSize:"inherit"},sn=new Set,cn=new Map,un={color:"var(--aqmx-tree-line)"},dn=e=>{const t=e instanceof Element?e.closest(`[${re}]`):null;return t===null||t.getAttribute("data-entry-type")!=="file"?null:t.getAttribute(re)},Xe=(e,t,n,a)=>n==="folder-limit"?e.expandAllFolderLimit(a,t.maxFolders,e.expandAll):e.expandAllDepthLimit(a,t.maxDepth),fn=(e,t,n)=>n.kind==="done"?e.expandAllDone(n.opened,n.failed,n.complete):Xe(e,t,n.kind,n.opened),We=()=>{const{labels:e}=v.useExplorer();return c.jsxs("div",{className:"aqmx-explorer-loading","aria-busy":"true","data-testid":"markdown-explorer-tree-loading",children:[c.jsx("p",{className:"aqmx-explorer-loading-text",children:e.treeLoading}),c.jsxs("div",{className:"aqmx-skeleton","aria-hidden":"true",children:[c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{}),c.jsx("span",{})]})]})},mn=()=>{const{labels:e}=v.useExplorer();return c.jsxs("div",{className:"aqmx-empty","data-testid":"markdown-explorer-tree-empty",children:[c.jsx(Tt,{className:"aqmx-explorer-empty-icon","aria-hidden":"true"}),c.jsx("p",{className:"aqmx-empty-title",children:e.treeEmptyTitle}),c.jsx("p",{className:"aqmx-explorer-empty-body",children:e.treeEmptyBody})]})},pn=({name:e,onRetry:t})=>{const{labels:n}=v.useExplorer(),a=r.useId();return c.jsxs("span",{className:"aqmx-explorer-folder-failed",children:[c.jsx("span",{className:"aqmx-explorer-folder-name",children:e}),c.jsx("span",{id:a,className:"aqmx-explorer-folder-error",children:n.folderLoadFailed}),c.jsxs("button",{type:"button",className:"aqmx-explorer-folder-retry","aria-describedby":a,"data-testid":"markdown-explorer-folder-retry",onClick:s=>{s.stopPropagation();const u=s.currentTarget,o=u.ownerDocument.activeElement===u?u.closest('[role="treeitem"]'):null;o instanceof HTMLElement&&v.focusWithoutScroll(o),t()},onKeyDown:s=>{s.key!=="Escape"&&s.stopPropagation()},children:[c.jsx(v.ForwardRef,{className:"aqmx-explorer-folder-retry-icon","aria-hidden":"true"}),c.jsx("span",{className:"aqmx-explorer-folder-retry-text",children:n.retry})]})]})},hn=({entries:e,version:t,mode:n,sourceId:a,settings:s,reveal:u,openPaths:o,selection:l,onOpenDocument:i,folders:f,onRevealSource:m,expansion:d,onShown:h,marks:x,claimsHeld:g,expandAll:E,revealCancel:j})=>{const{trees:L,documents:N,labels:R,locale:F,theme:C,data:y,config:T,sources:S,reveals:b}=v.useExplorer(),q=r.use(ye),[_]=r.useState(At),ae=r.useRef(null),{rowHeight:Q,lineColor:Z}=en(ae,C),{isExpanded:$,toggle:J,expandMultiple:I,collapseMultiple:X,expanded:W,isPending:G}=d,{alwaysExpanded:O,sortMode:ee,folderPlacement:le,readmePlacement:ue}=s,{direct:te,markDirect:B,unmarkDirect:U,pruneDirect:fe}=x,{running:oe,advance:se}=E,de=r.useRef(null),ne=r.useRef(null),z=r.useMemo(()=>A.createEntryComparator({sortMode:ee,folderPlacement:le,readmePlacement:ue}),[ee,le,ue]),P=r.useMemo(()=>qt(z),[z]),M=r.useCallback(w=>L.children(a,w),[L,a]),D=r.useMemo(()=>Ft(e),[e]),Y=r.useCallback(w=>!ie(w)&&($(w)||O&&!D.has(w)),[$,O,D]),V=r.useRef({shownExpanded:Y,isExpanded:$,unloadedFolders:D,entries:e,childrenOf:M});r.useLayoutEffect(()=>{V.current={shownExpanded:Y,isExpanded:$,unloadedFolders:D,entries:e,childrenOf:M}},[Y,$,D,e,M]);const Ce=r.useCallback(w=>{de.current?.scrollToPath(w,{align:"nearest"}),requestAnimationFrame(()=>{const k=ne.current,H=k===null?void 0:Ke(k,w);H!==void 0&&v.focusWithoutScroll(H)})},[]),tt=r.useCallback(w=>{if(ie(w)){Ce(Pt(w));return}V.current.isExpanded(w)?U([w]):V.current.unloadedFolders.has(w)&&B(w),J(w)},[Ce,B,U,J]),ge=r.useCallback(w=>{const k=w.filter(H=>!ie(H));k.length!==0&&(U(k),X(k))},[U,X]),nt=r.useCallback(w=>{const k=w.filter(H=>!ie(H));k.length!==0&&(k.length<w.length&&k.every(H=>V.current.shownExpanded(H))?ge(k):I(k))},[I,ge]),Te=r.useCallback(w=>c.jsx(pn,{name:w.name,onRetry:()=>{B(w.path),L.retryChildren(a,w.path),V.current.shownExpanded(w.path)||I([w.path])}}),[L,a,B,I]),Le=n==="multi"?o:sn,{loopFolderName:je}=R,rt=r.useMemo(()=>_(e,{openPaths:Le,childrenOf:M,renderFailedFolder:Te,loopFolderName:je}),[_,e,Le,M,Te,je,t]),at=v.useIntentPrefetch(N,dn),Pe=r.useRef([]),me=r.useCallback(()=>{for(const w of Pe.current)V.current.unloadedFolders.has(w)&&B(w)},[B]),{maxDepth:Ee}=T.revealDocument,Ne=r.useRef(m);r.useLayoutEffect(()=>{Ne.current=m},[m]);const lt=r.useMemo(()=>({ancestors:async(w,k)=>{const H=b.take(a,w);if(H!==null)return H;if(!b.mayMove(w)){const ce=await y.ancestors(a,w,k);return ce.status!=="ok"||ce.ancestors===null||ce.ancestors.length>Ee?null:ce.ancestors}const K=await y.reveal(a,w,k);return K.status!=="ok"||K.source===null||K.ancestors.length>Ee?null:K.source===a?K.ancestors:(k.aborted||!S.some(ce=>ce.id===K.source)||(b.move(K.source,w,K.ancestors),Ne.current(K.source)),null)},open:w=>{Pe.current=w??[],w!==null&&(me(),I([...w]))},progress:(w,k)=>_t(V.current.entries,w,k,{isShownExpanded:V.current.shownExpanded,childrenOf:V.current.childrenOf})}),[y,a,S,b,Ee,me,I]);r.useEffect(()=>me(),[me,D]);const ot=r.useMemo(()=>[e,t,W],[e,t,W]),st=r.useCallback(w=>ne.current===null?Number.POSITIVE_INFINITY:nn(ne.current,w),[]);Xt({tree:de,container:ne,path:u.path,chain:u.openFolders?lt:null,rows:ot,cancel:j,displayed:q,placement:st});const Oe=r.useCallback(w=>te.has(w),[te]),pe=r.useMemo(()=>Mt(e,{isShownExpanded:Y,childrenOf:M,compare:z,isDirect:Oe}),[e,Y,M,z,Oe,t]),he=q&&g;r.useLayoutEffect(()=>{h(e)},[e,h]),r.useLayoutEffect(()=>()=>h(null),[h]),r.useEffect(()=>L.claimChildren(a,he?pe.folders:cn),[L,a,he,pe]),r.useEffect(()=>fe(D),[fe,D]),r.useEffect(()=>{he&&oe&&se({entries:e,isShownExpanded:Y,childrenOf:M,compare:z,expanded:W,waiting:pe.waiting,expansionPending:G})},[he,oe,se,e,Y,M,z,W,pe,G]);const ct=r.useCallback(w=>{const k=w.entry.absolutePath;if(w.isDirectory){if(f===null||ie(k)||k===f.current)return;w.isExpanded&&w.preventDefault(),b.settle(k),f.open(k);return}b.settle(k),i(k)},[b,i,f]),{onChange:be}=l,it=r.useMemo(()=>be===null?void 0:(w,k)=>{ie(w.absolutePath)||be({path:w.absolutePath,name:w.name,selected:k})},[be]),ut=r.useMemo(()=>new Set(l.items),[l.items]),dt=r.useMemo(()=>({entryKindDirectory:R.treeEntryKindDirectory,entryKindFile:R.treeEntryKindFile,scrollUp:R.treeScrollUp,scrollDown:R.treeScrollDown,scrollToTop:R.treeScrollToTop,scrollToBottom:R.treeScrollToBottom}),[R]),ft=Z===null?{showTreeLines:!1}:{showTreeLines:s.lines,lineColor:Z};return c.jsxs("div",{ref:ne,className:"aqmx-explorer-tree","data-testid":"markdown-explorer-tree",...at,children:[c.jsx("span",{ref:ae,className:"aqmx-explorer-tree-probe","aria-hidden":"true",[Ut]:""}),c.jsx(He.DirectoryTree,{ref:de,entries:rt,expansion:{toggle:tt,isExpanded:Y,expandMultiple:nt,collapseMultiple:ge,isPending:G&&!oe,doubleClickAction:s.doubleClickAction},selection:{mode:l.mode,selectedPath:l.shownPath,currentPath:l.shownPath,selectedItems:ut,onEntryClick:ct,onSelectionChange:it},visual:{className:"aqmx-explorer-tree-view",ariaLabel:R.treeRegion,...ft,showExpandIcons:s.expandIcons,expandIconStyle:un,showDirectoryIcons:s.directoryIcons,showFileIcons:s.fileIcons,expandIconSize:s.expandIconSize,itemHeight:Q,removeRootIndent:s.removeRootIndent,highlightStyles:an,entryStyle:on,nameStyle:ln},virtualScroll:rn,sort:P,locale:F,labels:dt})]})},xn=({pending:e,status:t})=>{const{labels:n}=v.useExplorer(),a=t.state!=="running",[s,u]=r.useState(0),o=r.useRef(!0);r.useLayoutEffect(()=>{const i=o.current;if(o.current=a,!a||e>0&&!i){u(0);return}if(e>0){u(e);return}if(s===0)return;const f=setTimeout(()=>u(0),0);return()=>clearTimeout(f)},[a,e,s]);const l=a&&e===0?s:e;return l===0&&a?null:c.jsxs("p",{className:"aqmx-explorer-tree-progress","data-testid":"markdown-explorer-tree-progress","data-aqmx-loading":String(l),"data-aqmx-expand-all":t.state,children:[l>0?c.jsx(v.ForwardRef,{className:"aqmx-explorer-tree-progress-icon","aria-hidden":"true"}):null,c.jsx("span",{children:t.state==="running"?n.expandAllProgress(t.opened,l):n.foldersLoading(l)})]})},wn=({stop:e,opened:t,budget:n})=>{const{labels:a}=v.useExplorer();return c.jsx("p",{className:"aqmx-explorer-expand-all-stop","data-testid":"markdown-explorer-expand-all-stop","data-aqmx-stop":e,children:Xe(a,n,e,t)})},gn=({entries:e,...t})=>{const{trees:n}=v.useExplorer(),a=r.useSyncExternalStore(n.subscribe,n.version,n.version),{sourceId:s}=t,[u]=r.useState(Lt),o=r.useMemo(()=>u(e,l=>n.children(s,l)),[u,e,n,s,a]);return o.length===0?c.jsx(mn,{}):c.jsx(hn,{entries:o,version:a,...t})},En=({result:e,onRetry:t,...n})=>{const{renderTreeFailure:a}=v.useExplorer(),s=r.use(e);if(s.status==="deferred")return c.jsx(We,{});if(s.status==="ok")return c.jsx(gn,{entries:s.entries,...n});const u=a?.(s.failure);return c.jsx("div",{className:"aqmx-explorer-tree-message","data-testid":"markdown-explorer-tree-failure","data-aqmx-failure":s.failure.reason,children:u!==void 0?u:c.jsx(v.FailureView,{failure:s.failure,alert:!0,onRetry:t,testId:null})})},bn=({onControls:e,...t})=>{const{trees:n,storageNamespace:a,labels:s,announcer:u,config:o}=v.useExplorer(),{sourceId:l}=t,i=He.useDirectoryTreeState({storageKey:pt.storageKeys(a).treeExpansion(l)});r.useSyncExternalStore(n.subscribe,n.version,n.version);const f=n.read(l),m=r.useCallback(()=>n.retry(l),[n,l]);r.useLayoutEffect(()=>n.open(l),[n,l]);const d=Zt(),{expanded:h,expandMultiple:x,collapseAll:g}=i,[E,j]=r.useState(null),L=E!==h,N=r.useRef(h);r.useLayoutEffect(()=>{N.current=h},[h]);const R=o.expandAll,F=r.useCallback(()=>u.announce(s.expandAllStarted),[u,s]),C=r.useCallback(O=>u.announce(fn(s,R,O)),[u,s,R]),y=Vt({budget:R,expandMultiple:x,onStart:F,onFinish:C}),{status:T,start:S,end:b,advance:q}=y,_=T.state==="running",ae=r.useMemo(()=>({running:_,advance:q}),[_,q]),Q=r.useRef(null),[Z,$]=r.useState(!1),J=r.useCallback(O=>{Q.current=O,$(O!==null)},[]);r.useEffect(()=>n.subscribeChildrenFailures(O=>{const ee=O.sourceId===l&&Q.current!==null?Be(Q.current,O.path):null;ee!==null&&u.announce({list:s.foldersLoadFailedNamed,item:ee.name})}),[n,l,u,s]);const{clearDirect:I}=d,[X,W]=r.useState(0),G=r.useCallback(()=>{W(O=>O+1),b(),I(),j(N.current),g()},[b,I,g]);return r.useEffect(()=>{e({collapseAll:G,expandAll:Z?S:null,expanding:_})},[e,G,S,Z,_]),r.useEffect(()=>()=>e(null),[e]),r.useEffect(()=>{Z||b()},[Z,b]),c.jsxs(c.Fragment,{children:[T.state==="stopped"?c.jsx(wn,{stop:T.stop,opened:T.opened,budget:R}):null,c.jsxs("div",{className:"aqmx-explorer-tree-area",children:[c.jsx(r.Suspense,{fallback:c.jsx(We,{}),children:c.jsx(En,{result:f,onRetry:m,expansion:i,onShown:J,marks:d,claimsHeld:L,expandAll:ae,revealCancel:X,...t})}),c.jsx(xn,{pending:n.pendingChildren(l),status:T})]})]})};function vn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Ge=p.forwardRef(vn),_e="markdown-explorer-selection-remove",Rn=({selection:e,onRemove:t,onClear:n,onOpenSelection:a,onLeave:s})=>{const{labels:u}=v.useExplorer(),o=r.useId(),l=r.useRef(null),i=[...e],f=(d,h)=>{if(h.ownerDocument.activeElement===h){const x=l.current===null?[]:[...l.current.querySelectorAll(`[data-testid="${_e}"]`)],g=x.indexOf(h),E=[x[g+1],x[g-1]].find(j=>j!==void 0);E===void 0?s():E.focus()}t(d)},m=()=>{const d=l.current;d!==null&&d.contains(d.ownerDocument.activeElement)&&s(),n()};return c.jsxs("section",{ref:l,className:"aqmx-explorer-tray","aria-labelledby":o,"data-testid":"markdown-explorer-selection-tray",children:[c.jsxs("div",{className:"aqmx-explorer-tray-header",children:[c.jsx("p",{id:o,className:"aqmx-explorer-tray-title",children:u.selectionTitle(i.length)}),c.jsx("button",{type:"button",className:"aqmx-explorer-tray-button","data-testid":"markdown-explorer-selection-clear",onClick:m,children:u.clearSelection})]}),c.jsx("ul",{className:"aqmx-explorer-tray-list",children:i.map(([d,h])=>c.jsxs("li",{className:"aqmx-explorer-tray-item",children:[c.jsx("span",{className:"aqmx-explorer-tray-name",title:d,children:h}),c.jsx("button",{type:"button",className:"aqmx-icon-button aqmx-explorer-tray-remove","aria-label":u.removeFromSelection(h),title:u.removeFromSelection(h),"data-testid":_e,"data-aqmx-path":d,onClick:x=>f(d,x.currentTarget),children:c.jsx(Ge,{"aria-hidden":"true"})})]},d))}),a===void 0?null:c.jsx("button",{type:"button",className:"aqmx-explorer-tray-open","data-testid":"markdown-explorer-selection-open",onClick:()=>a(i.map(([d])=>d)),children:u.openSelectionInMulti(i.length)})]})},we=new Map,yn=(e,t)=>{if(t.selected===e.has(t.path))return e;const n=new Map(e);return t.selected?n.set(t.path,t.name):n.delete(t.path),n},Sn=(e,t)=>{if(!e.has(t))return e;const n=new Map(e);return n.delete(t),n},Ue=r.createContext(null),kn=e=>{const t=r.use(Ue);r.useLayoutEffect(()=>{if(t!==null)return t(e),()=>t(!1)},[t,e])};function Cn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.createElement("path",{fillRule:"evenodd",d:"M15 3.75a.75.75 0 0 1 .75-.75h4.5a.75.75 0 0 1 .75.75v4.5a.75.75 0 0 1-1.5 0V5.56l-3.97 3.97a.75.75 0 1 1-1.06-1.06l3.97-3.97h-2.69a.75.75 0 0 1-.75-.75Zm-12 0A.75.75 0 0 1 3.75 3h4.5a.75.75 0 0 1 0 1.5H5.56l3.97 3.97a.75.75 0 0 1-1.06 1.06L4.5 5.56v2.69a.75.75 0 0 1-1.5 0v-4.5Zm11.47 11.78a.75.75 0 1 1 1.06-1.06l3.97 3.97v-2.69a.75.75 0 0 1 1.5 0v4.5a.75.75 0 0 1-.75.75h-4.5a.75.75 0 0 1 0-1.5h2.69l-3.97-3.97Zm-4.94-1.06a.75.75 0 0 1 0 1.06L5.56 19.5h2.69a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1-.75-.75v-4.5a.75.75 0 0 1 1.5 0v2.69l3.97-3.97a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const Tn=p.forwardRef(Cn);function Ln({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 jn=p.forwardRef(Ln);function Pn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Nn=p.forwardRef(Pn);function On({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 An=p.forwardRef(On);function qn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Mn=p.forwardRef(qn);function Fn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 _n=p.forwardRef(Fn);function In({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Dn=p.forwardRef(In);function Hn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Zn=p.forwardRef(Hn);function $n({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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"}),p.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 Bn=p.forwardRef($n);function zn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Vn=p.forwardRef(zn);function Kn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Xn=p.forwardRef(Kn);function Wn({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Gn=p.forwardRef(Wn);function Un({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 Yn=p.forwardRef(Un),Qn=Object.freeze({sortMode:jn,folderPlacement:Vn,readmePlacement:Nn,selectionMode:An,doubleClickAction:Zn,expandIconSize:Gn,alwaysExpanded:Tn,revealDocument:v.ForwardRef$1,removeRootIndent:Mn,lines:Yn,expandIcons:_n,directoryIcons:Xn,fileIcons:Bn}),Ye=(e,t)=>{const n=e[t.labelKey];if(typeof n!="string")throw new TypeError(`[markdown-explorer] the tree setting ${t.key} must name a string label; labels.${t.labelKey} is a ${typeof n}`);return n},Jn=({id:e,settings:t,descriptors:n,onAdvance:a,onClose:s,ref:u})=>{const{labels:o}=v.useExplorer(),l=r.useRef([]);r.useEffect(()=>{l.current[0]?.focus()},[]);const i=r.useCallback(m=>{const d=n.length;l.current[(m%d+d)%d]?.focus()},[n.length]),f=r.useCallback((m,d)=>{switch(m.key){case"ArrowDown":m.preventDefault(),i(d+1);break;case"ArrowUp":m.preventDefault(),i(d-1);break;case"Home":m.preventDefault(),i(0);break;case"End":m.preventDefault(),i(n.length-1);break;case"Escape":v.consumeKey(m),s();break;case"Tab":s();break}},[n.length,i,s]);return c.jsx("div",{ref:u,id:e,role:"menu","aria-label":o.treeSettings,className:"aqmx-explorer-menu","data-testid":"markdown-explorer-tree-settings-menu",children:n.map((m,d)=>{const h=Qn[m.key],x=Ye(o,m),g=A.formatTreeSettingValue(o,t,m.key),E=t[m.key],j=typeof E=="boolean"?{role:"menuitemcheckbox","aria-checked":E,"aria-label":x}:{role:"menuitem","aria-label":`${x}: ${g}`};return c.jsxs("button",{ref:L=>{l.current[d]=L},type:"button",tabIndex:-1,...j,title:`${x}: ${g}`,className:"aqmx-explorer-menu-item","data-testid":"markdown-explorer-tree-settings-item","data-aqmx-setting":m.key,onClick:()=>a(m),onKeyDown:L=>f(L,d),children:[c.jsx(h,{className:"aqmx-explorer-menu-icon","aria-hidden":"true"}),c.jsx("span",{className:"aqmx-explorer-menu-name",children:x}),c.jsx("span",{className:"aqmx-explorer-menu-value",children:g})]},m.key)})})},er=({settings:e,descriptors:t,onAdvance:n})=>{const{labels:a,announcer:s}=v.useExplorer(),[u,o]=r.useState(!1),l=r.useRef(null),i=r.useRef(null),f=r.useRef(null),m=r.useId(),d=r.useCallback(()=>{l.current?.focus(),o(!1)},[]);r.useEffect(()=>{if(!u)return;const g=E=>{E.target instanceof Node&&(l.current?.contains(E.target)===!0||i.current?.contains(E.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)&&l.current?.focus()},0))};return document.addEventListener("pointerdown",g),()=>document.removeEventListener("pointerdown",g)},[u]),r.useEffect(()=>()=>{f.current!==null&&window.clearTimeout(f.current)},[]);const h=r.useCallback(g=>{g.key!=="Escape"||!u||(v.consumeKey(g),d())},[u,d]),x=r.useCallback(g=>{const E=n(g.key);s.announce(a.settingAnnouncement(Ye(a,g),A.formatTreeSettingValue(a,E,g.key)))},[s,a,n]);return{trigger:c.jsx("button",{ref:l,type:"button",className:"aqmx-icon-button","aria-haspopup":"menu","aria-expanded":u,"aria-controls":u?m:void 0,"aria-label":a.treeSettings,title:a.treeSettings,"data-testid":"markdown-explorer-tree-settings",onClick:()=>o(g=>!g),onKeyDown:h,children:c.jsx(Dn,{"aria-hidden":"true"})}),menu:u?c.jsx(Jn,{ref:i,id:m,settings:e,descriptors:t,onAdvance:x,onClose:d}):null}},tr=()=>{const{treeSettings:e}=v.useExplorer();return{settings:r.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getServerSnapshot),advance:e.advance}},Ie=new Set,nr='[role="tree"] [role="treeitem"][tabindex="0"]',rr="[data-directory-tree-tab-stop]",ar=e=>{const{mode:t,sourceId:n,currentPath:a,openPaths:s,onOpenDocument:u,onSourceChange:o,onRevealSource:l,viewSwitch:i}=e,{labels:f,sources:m,trees:d,documents:h,announcer:x,reveals:g}=v.useExplorer(),{settings:E,advance:j}=tr(),L=r.useMemo(()=>A.visibleTreeSettingDescriptors(t==="tree"),[t]),N=t==="tree"&&E.selectionMode==="multiple";kn(N);const R=e.mode==="tree"?e.tray.onGatheredChange:null,F=e.mode==="tree"?e.onOpenSelection:void 0,C=e.mode==="tree"?e.onOpenFolder:null,y=e.mode==="tree"&&e.currentFolder,T=r.useMemo(()=>C===null?null:{current:a,open:C},[C,a]),S=e.mode==="tree"&&N?e.tray.gathered:we,b=r.useCallback(P=>{const M=j(P);return M.selectionMode!=="multiple"&&R?.(we),M},[j,R]),q=er({settings:E,descriptors:L,onAdvance:b}),_=r.useCallback(P=>R?.(M=>yn(M,P)),[R]),ae=r.useCallback(P=>R?.(M=>Sn(M,P)),[R]),Q=r.useCallback(()=>R?.(we),[R]),Z=r.useRef(null),$=r.useCallback(()=>{const P=Z.current;if(P===null)return;[nr,rr,'[data-testid="markdown-explorer-tree-settings"]'].map(D=>P.querySelector(D)).find(D=>D!==null)?.focus()},[]),J=r.useMemo(()=>new Set(S.keys()),[S]),I=r.useMemo(()=>a===null?Ie:new Set([a]),[a]),X=r.useMemo(()=>{if(t==="multi")return{mode:"multiple",items:s,shownPath:null,onChange:null};switch(E.selectionMode){case"single":return{mode:"single",items:I,shownPath:a,onChange:null};case"multiple":return{mode:"multiple",items:J,shownPath:a,onChange:_};case"none":return{mode:"none",items:Ie,shownPath:null,onChange:null}}},[t,s,E.selectionMode,I,a,J,_]),W=r.useMemo(()=>E.revealDocument?{path:a,openFolders:!y}:{path:X.shownPath,openFolders:!1},[E.revealDocument,a,y,X.shownPath]),G=r.useCallback(P=>{a!==null&&g.settle(a),o(P)},[a,g,o]),[O,ee]=r.useState(null),[le,ue]=r.useState(!1),[te,B]=r.useState(null),U=r.useRef(!1),fe=r.useCallback(async()=>{if(!U.current){U.current=!0,ue(!0),B(null);try{const P=await d.refresh(n);if(P.status==="superseded")return;h.invalidate(),P.status==="failed"?B({sourceId:n,failure:P.failure}):x.announce(f.treeRefreshed)}finally{U.current=!1,ue(!1)}}},[d,h,n,x,f]),oe=O===null?null:O.expandAll,se=O?.expanding===!0,de=m.find(P=>P.id===n),ne=i.target==="multi"?St:Rt,z=i.target==="multi"?f.switchToMulti:f.switchToTree;return c.jsxs("nav",{ref:Z,"aria-label":f.explorerRegion,className:"aqmx-explorer","data-testid":"markdown-explorer-explorer","data-aqmx-mode":t,children:[c.jsxs("div",{className:"aqmx-explorer-header",children:[m.length>1?c.jsx("select",{className:"aqmx-explorer-source","aria-label":f.sourceLabel,title:de?.label,value:n,onChange:P=>G(P.currentTarget.value),"data-testid":"markdown-explorer-source-select",children:m.map(P=>c.jsx("option",{value:P.id,children:P.label},P.id))}):null,c.jsxs("div",{className:"aqmx-explorer-actions",children:[c.jsx(v.ExplorerLink,{to:i.href,navigation:"switch-view",className:"aqmx-icon-button","aria-label":z,title:z,"data-testid":"markdown-explorer-view-switch","data-aqmx-target":i.target,children:c.jsx(ne,{"aria-hidden":"true"})}),c.jsxs("button",{type:"button",className:"aqmx-icon-button aqmx-labelled-button",title:f.refreshTree,"aria-disabled":le,"aria-busy":le,"data-aqmx-busy":le?"true":void 0,"data-testid":"markdown-explorer-refresh",onClick:()=>{fe()},children:[c.jsx(v.ForwardRef,{"aria-hidden":"true"}),c.jsx("span",{children:f.refreshTreeLabel})]}),c.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.expandAll,title:f.expandAll,"aria-disabled":oe===null||se,"aria-busy":se,"data-aqmx-busy":se?"true":void 0,"data-testid":"markdown-explorer-expand-all",onClick:()=>oe?.(),children:c.jsx(bt,{"aria-hidden":"true"})}),c.jsx("button",{type:"button",className:"aqmx-icon-button","aria-label":f.collapseAll,title:f.collapseAll,"aria-disabled":O===null,"data-testid":"markdown-explorer-collapse-all",onClick:()=>O?.collapseAll(),children:c.jsx(gt,{"aria-hidden":"true"})}),q.trigger]})]}),c.jsxs("div",{className:"aqmx-explorer-body","data-aqmx-explorer-body":"",children:[te!==null&&te.sourceId===n?c.jsx("p",{role:"alert",className:"aqmx-explorer-refresh-failure","data-testid":"markdown-explorer-refresh-failure","data-aqmx-failure":te.failure.reason,children:f.treeRefreshFailed(v.failureTitleOf(f,te.failure.reason))}):null,c.jsx(r.Suspense,{fallback:null,children:c.jsx(kt,{})}),c.jsx(bn,{mode:t,sourceId:n,settings:E,reveal:W,openPaths:s,selection:X,onOpenDocument:u,folders:T,onRevealSource:l,onControls:ee},n),N&&S.size>0?c.jsx(Rn,{selection:S,onRemove:ae,onClear:Q,onOpenSelection:F,onLeave:$}):null,q.menu]})]})};function lr({title:e,titleId:t,...n},a){return p.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:a,"aria-labelledby":t},n),e?p.createElement("title",{id:t},e):null,p.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 or=p.forwardRef(lr),sr=({explorer:e,toggleRef:t,covered:n,onNoticeSlotChange:a,dismissals:s})=>{const{labels:u}=v.useExplorer(),o=ht.useLocation(),{location:l}=v.useExplorerLocation(),[i,f]=r.useState(!1),[m,d]=r.useState({navigated:o,source:l.source}),[h,x]=r.useState(!1);m.navigated!==o&&(d({navigated:o,source:l.source}),m.source===l.source&&!h&&f(!1));const[g,E]=r.useState(s);g!==s&&(E(s),f(!1));const j=r.useRef(null),L=r.useRef(null),N=r.useRef(null),R=r.useRef(!1),F=r.useId();r.useLayoutEffect(()=>{const b=j.current;b!==null&&(i&&!b.open?(b.showModal(),L.current?.focus()):!i&&b.open&&(b.close(),t.current?.focus()),a(i?N.current:null))},[i,t,a]),r.useLayoutEffect(()=>()=>a(null),[a]);const C=r.useCallback(b=>{b.key!=="Escape"||b.defaultPrevented||(v.consumeKey(b),f(!1))},[]),y=r.useCallback(b=>{R.current=b.target===b.currentTarget},[]),T=r.useCallback(b=>{const q=R.current;R.current=!1,q&&b.target===b.currentTarget&&f(!1)},[]),S=r.useCallback(()=>{f(!1)},[]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"aqmx-sheet-bar",inert:n,children:c.jsxs("button",{ref:t,type:"button",className:"aqmx-sheet-toggle","aria-haspopup":"dialog","aria-expanded":i,"aria-controls":F,"data-testid":"markdown-explorer-sheet-toggle",onClick:()=>f(!0),children:[c.jsx(or,{"aria-hidden":"true"}),c.jsx("span",{children:u.showExplorer})]})}),c.jsx("dialog",{ref:j,id:F,className:"aqmx-sheet","aria-label":u.explorerRegion,"data-testid":"markdown-explorer-sheet",onKeyDown:C,onPointerDown:y,onClick:T,onClose:S,children:c.jsxs("div",{className:"aqmx-sheet-panel",children:[c.jsxs("div",{className:"aqmx-sheet-header",children:[c.jsx("div",{ref:N,className:"aqmx-sheet-notice-slot"}),c.jsx("button",{ref:L,type:"button",className:"aqmx-sheet-close","aria-label":u.hideExplorer,title:u.hideExplorer,"data-testid":"markdown-explorer-sheet-close",onClick:()=>f(!1),children:c.jsx(Ge,{"aria-hidden":"true"})})]}),c.jsx("div",{className:"aqmx-sheet-body",children:c.jsx(ye,{value:i,children:c.jsx(Ue,{value:x,children:e})})}),c.jsx(v.LiveRegion,{holds:i,testId:"markdown-explorer-sheet-announcer"})]})})]})},Qe=r.createContext(null),Se="aqmx-explorer",Je="aqmx-content",cr="--aqmx-split-band",ke='[role="tree"] [role="treeitem"]',ir=`${ke}[tabindex="0"]`,ur="[data-directory-tree-tab-stop]",dr=(e,t)=>{for(const n of e.querySelectorAll(`[data-panel-id="${Se}"] ${ke}`))if(n.getAttribute(re)===t)return n;return null},De=(e,t)=>({inlineSize:e>0?e:null,rootFontPixels:t>0?t:A.ASSUMED_ROOT_FONT_PIXELS}),fr=(e,t)=>{const[n,a]=r.useState(()=>De(0,0));return r.useLayoutEffect(()=>{const s=e.current,u=t.current;if(s===null||u===null)throw new Error("[markdown-explorer] the split frame is not mounted");const o={frame:s.getBoundingClientRect().width,rem:u.getBoundingClientRect().width},l=()=>{const f=De(o.frame,o.rem);a(m=>m.inlineSize===f.inlineSize&&m.rootFontPixels===f.rootFontPixels?m:f)};l();const i=new ResizeObserver(f=>{for(const m of f){const[d]=m.borderBoxSize;d!==void 0&&(m.target===s&&(o.frame=d.inlineSize),m.target===u&&(o.rem=d.inlineSize))}l()});return i.observe(s),i.observe(u),()=>i.disconnect()},[e,t]),n},et=e=>`aqmx-split-handle-${e}`,mr=(e,{frameRef:t,sheetToggleRef:n,handleId:a})=>{const s=r.useRef(!1),u=r.useRef(null),o=r.useRef(!1);r.useLayoutEffect(()=>{const i=t.current;if(i===null)throw new Error("[markdown-explorer] the split frame is not mounted");const f=d=>{const h=d.target instanceof Element?d.target:null;s.current=h!==null&&h.closest(`[data-panel-id="${Je}"]`)===null,!o.current&&(u.current=h?.closest(`${ke}[${re}]`)?.getAttribute(re)??null)},m=d=>{d.relatedTarget instanceof Node&&!i.contains(d.relatedTarget)&&(s.current=!1)};return i.addEventListener("focusin",f),i.addEventListener("focusout",m),()=>{i.removeEventListener("focusin",f),i.removeEventListener("focusout",m)}},[t]);const l=r.useRef(e);r.useLayoutEffect(()=>{if(l.current===e)return;l.current=e;const i=t.current;if(i===null||!s.current)return;const f=m=>{const{activeElement:d,body:h}=i.ownerDocument;if(d!==null&&d!==h)return;const x=m.find(g=>g!==null);if(x!=null){o.current=!0;try{x.focus()}finally{o.current=!1}}};if(e){f([n.current]);return}queueMicrotask(()=>{if(l.current!==e||!s.current)return;const m=u.current,d=`[data-panel-id="${Se}"]`;f([m===null?null:dr(i,m),i.querySelector(`${d} ${ir}`),i.querySelector(`${d} ${ur}`),i.querySelector(`[data-resize-handle-id="${a}"]`)])})},[e,t,n,a])},pr=({view:e,explorer:t,content:n,contentCoversPage:a=!1,sheetDismissals:s=0,onDraggingChange:u})=>{const o=r.useRef(null),[l,i]=r.useState(null),f=r.useRef(null),m=r.useRef(null),{inlineSize:d,rootFontPixels:h}=fr(o,f),x=d!==null&&d<A.explorerSheetBelowPixels(h);return mr(x,{frameRef:o,sheetToggleRef:m,handleId:et(e)}),c.jsxs("div",{ref:o,className:"aqmx-split-frame","data-aqmx-explorer-mode":x?"sheet":"split",children:[c.jsx("span",{ref:f,className:"aqmx-rem-probe","aria-hidden":"true","data-aqmx-rem-probe":""}),x?c.jsx(sr,{explorer:t,toggleRef:m,covered:a,onNoticeSlotChange:i,dismissals:s}):null,c.jsx(Qe,{value:x?l:null,children:c.jsx(hr,{view:e,sheet:x,explorer:t,content:n,contentCoversPage:a,onDraggingChange:u,explorerMinPixels:A.explorerMinPixels(h)})})]})},hr=({view:e,sheet:t,explorer:n,content:a,contentCoversPage:s,onDraggingChange:u,explorerMinPixels:o})=>{const{viewSettings:l,labels:i}=v.useExplorer(),m=v.useViewSetting(C=>e==="tree"?C.treeExplorer:C.multiExplorer)??(e==="tree"?A.EXPLORER_DEFAULT_PERCENT:A.EXPLORER_MULTI_DEFAULT_PERCENT),d=r.useRef(!1),[h,x]=r.useState(!1),g=r.useRef(u);r.useLayoutEffect(()=>{g.current=u},[u]);const E=Ae.useSplitPersistence(r.useCallback(C=>{if(C.length!==2)return;const[y=0,T=0]=C,S=y+T;if(S<=0||y<=0)return;const b=Math.min(A.EXPLORER_MAX_PERCENT,y/S*100);l.update(e==="tree"?{treeExplorer:b}:{multiExplorer:b})},[l,e]));r.useEffect(()=>()=>{d.current&&g.current?.(!1)},[]);const L=Ae.useCoarsePointer()?A.COARSE_TARGET_PIXELS:A.FINE_TARGET_PIXELS,N=r.useMemo(()=>({[cr]:`${String(t?0:L)}px`}),[t,L]),R=r.useCallback((C,y)=>{const[T=0,S=0]=C;C.length===2&&S>0&&x(T<=0),E.layoutChanged(C,y)},[E]),F=r.useCallback(C=>{d.current=C,u?.(C),E.draggingChanged(C)},[u,E]);return c.jsxs(xe.PanelGroup,{id:`aqmx-split-${e}`,direction:"horizontal",onLayout:R,className:"aqmx-split",style:N,"data-aqmx-split":e,children:[t?null:c.jsx(xe.Panel,{id:Se,defaultSize:{value:m,unit:"percentage"},minSize:{value:o,unit:"pixels"},maxSize:{value:A.EXPLORER_MAX_PERCENT,unit:"percentage"},collapsible:{from:"end"},pixelAdjustPriority:1,inert:s,className:"aqmx-split-explorer",children:c.jsx(ye,{value:!h,children:n})}),t?null:c.jsx(xe.PanelResizeHandle,{id:et(e),thickness:L,indicator:{visible:!0,thickness:A.SPLIT_HANDLE_PIXELS.gripThickness,length:A.SPLIT_HANDLE_PIXELS.gripLength,barThickness:A.SPLIT_HANDLE_PIXELS.barThickness,barLength:A.SPLIT_HANDLE_PIXELS.barLength},title:i.resizeExplorer,"aria-label":i.resizeExplorer,onDragging:F,inert:s,className:"aqmx-split-handle"}),c.jsx(xe.Panel,{id:Je,defaultSize:{value:100-m,unit:"percentage"},contentOverflow:"hidden",className:"aqmx-split-content",...s?{style:{isolation:"auto"}}:{},children:a})]})};exports.EMPTY_SELECTION=we;exports.ExplorerPane=ar;exports.ExplorerSplit=pr;exports.SheetNoticeSlotContext=Qe;