@opentig/cli 0.2.0 → 0.2.2

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 (118) hide show
  1. package/dist/bin.mjs +2 -1
  2. package/dist/chunks/{cli-Bi6ET5UT.mjs → cli-DNzGBqmL.mjs} +1 -1
  3. package/dist/client/assets/App-BbT5H97Z.js +138 -0
  4. package/dist/client/assets/CreatePullRequestDialog-DRLeMY4e.js +2 -0
  5. package/dist/client/assets/{DiffWorkspace-RDG_Y70N.js → DiffWorkspace-DJX00otP.js} +13 -13
  6. package/dist/client/assets/{EditableFileViewer-CsbifqBO.js → EditableFileViewer-Cmbomx5y.js} +1 -1
  7. package/dist/client/assets/{File-CHjvYpb2.js → File-4o4egqlz.js} +1 -1
  8. package/dist/client/assets/FilesView-TmUF-VLr.js +1 -0
  9. package/dist/client/assets/GitHubAvatar-azKPrTMv.js +1 -0
  10. package/dist/client/assets/HistoryView-Go6rXO0P.js +1 -0
  11. package/dist/client/assets/{HtmlFileViewer-h8ULU8Gy.js → HtmlFileViewer-WpYnLdMW.js} +1 -1
  12. package/dist/client/assets/{IconEdit-Cg8S2wqW.js → IconEdit-B8LZHB8l.js} +1 -1
  13. package/dist/client/assets/{IconFolderSymlink-BZSLX1ez.js → IconFolderSymlink-D29EhQPC.js} +1 -1
  14. package/dist/client/assets/{ImageFileViewer-Cjw58ckv.js → ImageFileViewer-1ObUacJu.js} +1 -1
  15. package/dist/client/assets/LocalRefsDialog-VcrlFgxR.js +1 -0
  16. package/dist/client/assets/{MarkdownFileViewer-kLiduag6.js → MarkdownFileViewer-CvsKPnvF.js} +2 -2
  17. package/dist/client/assets/PairingPage-cSoKZi8t.js +1 -0
  18. package/dist/client/assets/{PierreDiffViewer-eAcugmoF.js → PierreDiffViewer-DVTrOwX4.js} +1 -1
  19. package/dist/client/assets/{PierreEditBoundary-DlGd1pqO.js → PierreEditBoundary-DPtaTiUB.js} +1 -1
  20. package/dist/client/assets/{PierreWorkerPool-Col4k7qz.js → PierreWorkerPool-BxP-s6jD.js} +1 -1
  21. package/dist/client/assets/{PullRequestDiff-DhKTXyIF.js → PullRequestDiff-DeQznd9n.js} +1 -1
  22. package/dist/client/assets/PullRequestViewer-IhGZZs_A.js +2 -0
  23. package/dist/client/assets/PullRequestsView-BG0xrok4.js +1 -0
  24. package/dist/client/assets/QuickOpenDialog-DpmcAzTx.js +1 -0
  25. package/dist/client/assets/RepositoryProjectsDialog-DAzbUB3X.js +1 -0
  26. package/dist/client/assets/SearchView-HoiWKG8z.js +1 -0
  27. package/dist/client/assets/SettingsDialog-pmJKOaiK.js +9 -0
  28. package/dist/client/assets/{Viewer-o1hDU33O.js → Viewer-BCk8FHrc.js} +3 -3
  29. package/dist/client/assets/{abnfDiagram-N423BO3Z-BvrnK_R-.js → abnfDiagram-N423BO3Z-BvfKOanh.js} +1 -1
  30. package/dist/client/assets/{arc-DLa3_7ua.js → arc-DB2nIH2Y.js} +1 -1
  31. package/dist/client/assets/{architectureDiagram-T3A2C74G-BexwhnyX.js → architectureDiagram-T3A2C74G-Bqh4uY3R.js} +1 -1
  32. package/dist/client/assets/base-ui-DIP2rZxz.js +1 -0
  33. package/dist/client/assets/{blockDiagram-VBNYF7ZC-CoOttUUo.js → blockDiagram-VBNYF7ZC-DMW415Ms.js} +1 -1
  34. package/dist/client/assets/{c4Diagram-5PPSVZJV-Bgp6ppUh.js → c4Diagram-5PPSVZJV-BSNPes7l.js} +1 -1
  35. package/dist/client/assets/channel-VcDernYy.js +1 -0
  36. package/dist/client/assets/checkbox-Dta4gqy2.js +1 -0
  37. package/dist/client/assets/{chunk-2GRJ4B5K-C_kzp38w.js → chunk-2GRJ4B5K-D-86JbWu.js} +1 -1
  38. package/dist/client/assets/{chunk-2Q5K7J3B-CysYnRkJ.js → chunk-2Q5K7J3B-BNI-SD-k.js} +1 -1
  39. package/dist/client/assets/{chunk-5RXB4S5H-oMS6x_ag.js → chunk-5RXB4S5H-OFFYyML8.js} +1 -1
  40. package/dist/client/assets/{chunk-5VM5RSS4-C5-dW5wf.js → chunk-5VM5RSS4-DpE1dtnL.js} +1 -1
  41. package/dist/client/assets/{chunk-6Q2QTUOP-DxahInnA.js → chunk-6Q2QTUOP-DxAnzBXJ.js} +1 -1
  42. package/dist/client/assets/{chunk-GF5L2VYU-D7V-3eRg.js → chunk-GF5L2VYU-DNrTNRgr.js} +1 -1
  43. package/dist/client/assets/{chunk-JWPE2WC7-BrLmjbVP.js → chunk-JWPE2WC7-D-jfKyIh.js} +1 -1
  44. package/dist/client/assets/{chunk-KBJHAD2P-CyOvijwM.js → chunk-KBJHAD2P-CIyQl_ts.js} +1 -1
  45. package/dist/client/assets/{chunk-RYQCIY6F-BvEjVjQs.js → chunk-RYQCIY6F-CgCYQccM.js} +1 -1
  46. package/dist/client/assets/{chunk-XXDRQBXY-C_IY9A64.js → chunk-XXDRQBXY-B31oXtqU.js} +1 -1
  47. package/dist/client/assets/classDiagram-JCYQIIEL-CUuEGRCt.js +1 -0
  48. package/dist/client/assets/classDiagram-v2-OCEON4UE-CUuEGRCt.js +1 -0
  49. package/dist/client/assets/{cose-bilkent-JH36ORCC-Cu7qZi7h.js → cose-bilkent-JH36ORCC-CrX-LDNw.js} +1 -1
  50. package/dist/client/assets/{cynefin-VYW2F7L2-B4M1t9lL.js → cynefin-VYW2F7L2-DnkWlsqW.js} +1 -1
  51. package/dist/client/assets/{cynefinDiagram-MW4NZA55-CAosOLmT.js → cynefinDiagram-MW4NZA55-bUDQ9ElF.js} +1 -1
  52. package/dist/client/assets/{dagre-VZM6K2ZE-q354V538.js → dagre-VZM6K2ZE-BW5Kni4n.js} +1 -1
  53. package/dist/client/assets/{diagram-7IWD3JNH-C_CzkBPt.js → diagram-7IWD3JNH-1EXGwguC.js} +1 -1
  54. package/dist/client/assets/{diagram-B4RE2ZJO-VvvYHE9c.js → diagram-B4RE2ZJO-CzpH5ieN.js} +1 -1
  55. package/dist/client/assets/{diagram-LBJQPF4R-D8vRQwb5.js → diagram-LBJQPF4R-BnKszJ_B.js} +1 -1
  56. package/dist/client/assets/{diagram-Q27KOJAE-Bul4aDKg.js → diagram-Q27KOJAE-DbQlD3OM.js} +1 -1
  57. package/dist/client/assets/{diagram-UB23O5K3-DNadEE58.js → diagram-UB23O5K3-BqZ-RSlm.js} +1 -1
  58. package/dist/client/assets/{ebnfDiagram-BXEA7PRR-Bf-68MMZ.js → ebnfDiagram-BXEA7PRR-B2iPWDvr.js} +1 -1
  59. package/dist/client/assets/{erDiagram-JOGREHBK-CJ-jHFsf.js → erDiagram-JOGREHBK-aMqHrKCk.js} +1 -1
  60. package/dist/client/assets/{flowDiagram-UKHOOZJN-DMOdinBU.js → flowDiagram-UKHOOZJN-ivrTsn4D.js} +1 -1
  61. package/dist/client/assets/{ganttDiagram-PKOTCBZU-DzezS3Zy.js → ganttDiagram-PKOTCBZU-IMfIqkXw.js} +1 -1
  62. package/dist/client/assets/{gitGraphDiagram-DS77QQ5N-Dftpvns8.js → gitGraphDiagram-DS77QQ5N-BNURRh2N.js} +1 -1
  63. package/dist/client/assets/{index-DAUK3rnz.js → index-B3QJsvjR.js} +4 -4
  64. package/dist/client/assets/index-Cx9LaJW8.css +1 -0
  65. package/dist/client/assets/{infoDiagram-6WML65LV-DmgUBq17.js → infoDiagram-6WML65LV-BKEENkUQ.js} +1 -1
  66. package/dist/client/assets/{ishikawaDiagram-WSZJBQD7-CL0PQhpQ.js → ishikawaDiagram-WSZJBQD7-HrCSmiTr.js} +1 -1
  67. package/dist/client/assets/{journeyDiagram-NVQOT4AX-Ck4pQx_A.js → journeyDiagram-NVQOT4AX-CQIuWA6F.js} +1 -1
  68. package/dist/client/assets/{kanban-definition-27J2QSJJ-DuRZxBql.js → kanban-definition-27J2QSJJ-h4fSAkel.js} +1 -1
  69. package/dist/client/assets/{linear-C2JDCaz4.js → linear-BAdz-uC9.js} +1 -1
  70. package/dist/client/assets/{mermaid.core-9dt2ugQA.js → mermaid.core-vLn7mMZB.js} +4 -4
  71. package/dist/client/assets/{mindmap-definition-FAOFIHXS-vy0fdDF0.js → mindmap-definition-FAOFIHXS-DOrZl827.js} +1 -1
  72. package/dist/client/assets/{pegDiagram-VL7TDLO6-DjVJy-Gm.js → pegDiagram-VL7TDLO6-_Vs7p633.js} +1 -1
  73. package/dist/client/assets/{pieDiagram-7S7Q4E2Y-ATbd_8vw.js → pieDiagram-7S7Q4E2Y-7qbB_Z16.js} +1 -1
  74. package/dist/client/assets/{quadrantDiagram-CIZ2JOQS-C8o6ofcl.js → quadrantDiagram-CIZ2JOQS-DNH8SosA.js} +1 -1
  75. package/dist/client/assets/{railroadDiagram-AXF67PYL-Qvij9Ubo.js → railroadDiagram-AXF67PYL-Ctazrrpa.js} +1 -1
  76. package/dist/client/assets/{render-markdown-BtCybfvQ.js → render-markdown-dvHhHbC0.js} +6 -6
  77. package/dist/client/assets/{requirementDiagram-LRYGKXZP-yLfrba2h.js → requirementDiagram-LRYGKXZP-BAH8dYer.js} +1 -1
  78. package/dist/client/assets/{sankeyDiagram-W5VNT64P-BTXRtTyG.js → sankeyDiagram-W5VNT64P-CuffrpdF.js} +1 -1
  79. package/dist/client/assets/{sequenceDiagram-SI44F4Z6-BN1CCZIX.js → sequenceDiagram-SI44F4Z6-CaO4fJnS.js} +1 -1
  80. package/dist/client/assets/{sizeCapture-X5ZJPWSS-BfXjBBYo.js → sizeCapture-X5ZJPWSS-B_LramBU.js} +1 -1
  81. package/dist/client/assets/{stateDiagram-OKZ733FA-DMAWiBsP.js → stateDiagram-OKZ733FA-bc7zBYHn.js} +1 -1
  82. package/dist/client/assets/stateDiagram-v2-UEYNNEHI-C-UGmA2d.js +1 -0
  83. package/dist/client/assets/{swimlanes-SLNWSIFB-BD20m5cw.js → swimlanes-SLNWSIFB-DQzg1IPn.js} +2 -2
  84. package/dist/client/assets/swimlanesDiagram-ULZ7WXOC-DnopIiWa.js +8 -0
  85. package/dist/client/assets/tanstack-BysN2Oew.js +1 -0
  86. package/dist/client/assets/{timeline-definition-Z64GVDOM-gtc0-AHB.js → timeline-definition-Z64GVDOM-CtbuIB6K.js} +1 -1
  87. package/dist/client/assets/{vennDiagram-T6HMQDX7-Cdr4AXTp.js → vennDiagram-T6HMQDX7-pYJ0ZfFS.js} +1 -1
  88. package/dist/client/assets/{viewer-tabs-D-T0xQaq.js → viewer-tabs-Cnfyd6rg.js} +1 -1
  89. package/dist/client/assets/{wardleyDiagram-T6FBY63Y-BcU4vxO8.js → wardleyDiagram-T6FBY63Y-DYl_Oi-Y.js} +1 -1
  90. package/dist/client/assets/{xychartDiagram-ELKLHX3M-B3Zuadj8.js → xychartDiagram-ELKLHX3M-Cj5YUfP5.js} +1 -1
  91. package/dist/client/index.html +4 -4
  92. package/dist/dev.mjs +3 -2
  93. package/dist/manifest.json +2 -2
  94. package/dist/server.mjs +2219 -508
  95. package/dist/utility.mjs +12 -5
  96. package/package.json +1 -1
  97. package/dist/client/assets/App-BXZLGT86.js +0 -74
  98. package/dist/client/assets/CreatePullRequestDialog-DFonMYEx.js +0 -2
  99. package/dist/client/assets/FilesView-Dl8QFbFA.js +0 -1
  100. package/dist/client/assets/GitHubAvatar-CnBaloV0.js +0 -1
  101. package/dist/client/assets/HistoryView-BgCZU2JO.js +0 -1
  102. package/dist/client/assets/LocalRefsDialog-DNgrd7Qp.js +0 -1
  103. package/dist/client/assets/PairingPage-C97sv-8s.js +0 -1
  104. package/dist/client/assets/PullRequestViewer-BgI8HFMe.js +0 -2
  105. package/dist/client/assets/PullRequestsView-PYWLy8We.js +0 -1
  106. package/dist/client/assets/QuickOpenDialog-BFDDZVCL.js +0 -1
  107. package/dist/client/assets/RepositoryProjectsDialog-CvB8KcFp.js +0 -1
  108. package/dist/client/assets/SearchView-BwF_MsxK.js +0 -1
  109. package/dist/client/assets/SettingsDialog-DIcLmXSE.js +0 -9
  110. package/dist/client/assets/base-ui-CJ8ZIx3d.js +0 -1
  111. package/dist/client/assets/channel-1k1AYpyV.js +0 -1
  112. package/dist/client/assets/checkbox-BRH0ZNIC.js +0 -1
  113. package/dist/client/assets/classDiagram-JCYQIIEL-ChyNFpay.js +0 -1
  114. package/dist/client/assets/classDiagram-v2-OCEON4UE-ChyNFpay.js +0 -1
  115. package/dist/client/assets/index-BfA4tAc1.css +0 -1
  116. package/dist/client/assets/stateDiagram-v2-UEYNNEHI-D_ofZeaa.js +0 -1
  117. package/dist/client/assets/swimlanesDiagram-ULZ7WXOC-CF9m5JSB.js +0 -8
  118. package/dist/client/assets/tanstack-B0Sf7wNU.js +0 -1
@@ -1 +1 @@
1
- import{r as n,j as l}from"./react-rd22PHbN.js";import{r as w,V as k,O as j,P as N,a as A,u as O}from"./PierreWorkerPool-Col4k7qz.js";import{F as I}from"./File-CHjvYpb2.js";import{c as V,s as x,T as z,a as K,b as P}from"./index-DAUK3rnz.js";import{E as D}from"./edit-ready-context-D77R8XU8.js";import{af as M,ag as C,ah as U}from"./App-BXZLGT86.js";const q=[["path",{d:"M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2",key:"svg-0"}],["path",{d:"M10 14a2 2 0 1 0 4 0a2 2 0 1 0 -4 0",key:"svg-1"}],["path",{d:"M14 4l0 4l-6 0l0 -4",key:"svg-2"}]],B=V("outline","device-floppy","DeviceFloppy",q),b={stableFrames:3,maxFrames:60,userScrollTolerance:2};function G(e,t,r={}){const o=r.stableFrames??b.stableFrames,s=r.maxFrames??b.maxFrames,p=r.userScrollTolerance??b.userScrollTolerance,E=r.requestFrame??(i=>requestAnimationFrame(i)),T=r.cancelFrame??(i=>cancelAnimationFrame(i)),S=Number.isFinite(t)?Math.min(1,Math.max(0,t)):0;let f=null,v=0,m=0,c=null,a=null,g=!1;const y=()=>{g=!0,f!==null&&T(f),f=null},F=()=>{if(f=null,g)return;v+=1;const i=e.getContentHeight();if(a!==null&&c===i&&Math.abs(e.getScrollTop()-a)>p){y();return}const u=e.getScrollRange(),h=u>0?S*u:0;if(e.scrollTo(h),a=h,m=i>0&&c===i?m+1:0,c=i,m>=o||v>=s){y();return}f=E(F)};return F(),y}function W(e){const t=e.split("+"),r=t.pop().toLowerCase();return[...t.map(s=>s==="Ctrl"?"cmdOrCtrl":s.toLowerCase()),r].join("+")}function H(e){return[{bindings:{[W(e)]:"openSearchReplacePanel"}}]}H(M.editorSearch);const $=2e3;function Y(e,t=$){let r=1;for(let o=0;o<e.length;o+=1)if(e.charCodeAt(o)===10&&(r+=1,r>t))return!0;return!1}function Z(e,t,r=M.saveFile){return U({key:e.key,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey??!1,altKey:e.altKey??!1},r)?(e.preventDefault(),t(),!0):!1}async function J(e){if(!e.dirty||e.readOnly||!e.claim())return"skipped";try{return(await e.persist()).status==="conflict"?(e.onConflict(),"conflict"):(e.onSuccess(),"saved")}catch(t){return e.onError(t),"error"}finally{e.release()}}function Q({file:e,initialContent:t,readOnly:r,messages:o,onDirtyChange:s,onDraftChange:p,onSave:E}){const T=C(),[S,f]=n.useState(t),[v,m]=n.useState(!1),c=n.useRef(!1),a=S!==e.content,g=n.useRef(e.content);n.useLayoutEffect(()=>{S===g.current&&e.content!==g.current&&f(e.content),g.current=e.content},[e.content,S]),n.useEffect(()=>{s(a)},[a,s]),n.useEffect(()=>()=>s(!1),[s]);const y=n.useCallback(u=>{f(u),s(u!==e.content),p(u)},[e.content,s,p]),F=n.useCallback(async()=>{await J({dirty:a,readOnly:r,claim:()=>c.current?!1:(c.current=!0,m(!0),!0),release:()=>{c.current=!1,m(!1)},persist:()=>E(e.path,S,e.content),onConflict:()=>x.error({title:o.conflictTitle,description:"Your draft is still open. Copy it or reload the file before saving again.",duration:1e4}),onSuccess:()=>x.success({title:o.successTitle,description:e.path}),onError:u=>x.error({title:o.errorTitle,description:u instanceof Error?u.message:"Unknown error",duration:1e4})})},[a,S,e.content,e.path,o,E,r]),i=n.useRef(F);return n.useEffect(()=>{i.current=F},[F]),n.useEffect(()=>{const u=h=>{Z(h,()=>{i.current()},T.saveFile)};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[T.saveFile]),{draft:S,updateDraft:y,dirty:a,saving:v,save:F}}function L({dirty:e,saving:t,readOnly:r,onSave:o}){const s=C();if(!e&&!t)return null;const p=r?"Read only":t?"Saving…":`Save file (${s.saveFile})`;return l.jsxs(z,{children:[l.jsx(K,{render:l.jsx("button",{type:"button",className:"file-save-button","data-state":r?"readonly":t?"saving":"dirty",disabled:t||r,onClick:o,"aria-label":p}),children:l.jsx(B,{"aria-hidden":"true"})}),l.jsx(P,{children:p})]})}function X({handleRef:e}){const t=O();return n.useLayoutEffect(()=>{e.current=t},[t,e]),null}function _({path:e,cacheKey:t,value:r,themeType:o,wrapLines:s,readOnly:p,onChange:E,ref:T}){const S=n.useContext(D),f=C(),[v]=n.useState(()=>Y(r)),m=n.useRef(E);n.useEffect(()=>{m.current=E},[E]);const c=n.useRef(void 0),a=n.useRef(null),g=n.useMemo(()=>({name:e,lang:w(e),contents:r,cacheKey:t}),[t,e,r]),y=n.useMemo(()=>({disableFileHeader:!0,themeType:o,theme:j,overflow:s?"wrap":"scroll",unsafeCSS:k}),[o,s]),F=n.useMemo(()=>({historyMaxEntries:500,keymap:H(f.editorSearch),onChange(h){m.current(h.contents)}}),[f.editorSearch]),i=n.useRef(null);n.useEffect(()=>()=>i.current?.(),[]),n.useImperativeHandle(T,()=>({getScrollFraction(){const h=c.current?.getRoot()??a.current;if(!(h instanceof HTMLElement))return 0;const d=h.scrollHeight-h.clientHeight;return d>0?h.scrollTop/d:0},scrollToFraction(h){i.current?.(),i.current=G({getScrollRange(){const d=c.current?.getRoot()??a.current;return d instanceof HTMLElement?Math.max(0,d.scrollHeight-d.clientHeight):0},getScrollTop(){const d=c.current?.getRoot()??a.current;return d instanceof HTMLElement?d.scrollTop:0},getContentHeight(){const d=c.current?.getRoot()??a.current;return d instanceof HTMLElement?d.scrollHeight:0},scrollTo(d){const R=c.current;R&&R.getRoot()instanceof HTMLElement?R.scrollTo({top:d}):a.current?.scrollTo({top:d})}},h)}}),[]);const u=l.jsx(I,{file:g,options:y,editorOptions:F,edit:S&&!p});return l.jsx(N,{theme:j,children:v?l.jsxs(A,{className:"source-code-editor",contentClassName:"source-code-editor-content",children:[l.jsx(X,{handleRef:c}),u]}):l.jsx("div",{ref:a,className:"source-code-editor",children:l.jsx("div",{className:"source-code-editor-content",children:u})})})}const ee={conflictTitle:"File was changed outside OpenTig",successTitle:"File saved",errorTitle:"Could not save file"};function te({file:e,initialContent:t,themeType:r,wrapLines:o,readOnly:s,onDirtyChange:p,onDraftChange:E,onSave:T}){const{draft:S,updateDraft:f,dirty:v,saving:m,save:c}=Q({file:e,initialContent:t,readOnly:s,messages:ee,onDirtyChange:p,onDraftChange:E,onSave:T});return l.jsxs("div",{className:"source-file-viewer",children:[(v||m)&&l.jsx("div",{className:"source-file-toolbar",children:l.jsx(L,{dirty:v,saving:m,readOnly:s,onSave:()=>{c()}})}),l.jsx("div",{className:"source-editor-scroll",children:l.jsx(_,{path:e.path,cacheKey:e.path,value:S,themeType:r,wrapLines:o,readOnly:s||m,onChange:f})})]})}const le=Object.freeze(Object.defineProperty({__proto__:null,EditableFileViewer:te,FileSaveControls:L,SourceCodeEditor:_},Symbol.toStringTag,{value:"Module"}));export{le as E,L as F,_ as S,G as s,Q as u};
1
+ import{r as n,j as l}from"./react-rd22PHbN.js";import{r as _,V as k,O as j,P as N,a as A,u as O}from"./PierreWorkerPool-BxP-s6jD.js";import{F as I}from"./File-4o4egqlz.js";import{c as V,s as x,T as z,b as K,d as P}from"./index-B3QJsvjR.js";import{E as D}from"./edit-ready-context-D77R8XU8.js";import{aw as M,ax as C,ay as U}from"./App-BbT5H97Z.js";const q=[["path",{d:"M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2",key:"svg-0"}],["path",{d:"M10 14a2 2 0 1 0 4 0a2 2 0 1 0 -4 0",key:"svg-1"}],["path",{d:"M14 4l0 4l-6 0l0 -4",key:"svg-2"}]],B=V("outline","device-floppy","DeviceFloppy",q),b={stableFrames:3,maxFrames:60,userScrollTolerance:2};function G(e,t,r={}){const o=r.stableFrames??b.stableFrames,s=r.maxFrames??b.maxFrames,p=r.userScrollTolerance??b.userScrollTolerance,E=r.requestFrame??(i=>requestAnimationFrame(i)),T=r.cancelFrame??(i=>cancelAnimationFrame(i)),S=Number.isFinite(t)?Math.min(1,Math.max(0,t)):0;let f=null,v=0,m=0,c=null,a=null,y=!1;const g=()=>{y=!0,f!==null&&T(f),f=null},F=()=>{if(f=null,y)return;v+=1;const i=e.getContentHeight();if(a!==null&&c===i&&Math.abs(e.getScrollTop()-a)>p){g();return}const u=e.getScrollRange(),h=u>0?S*u:0;if(e.scrollTo(h),a=h,m=i>0&&c===i?m+1:0,c=i,m>=o||v>=s){g();return}f=E(F)};return F(),g}function W(e){const t=e.split("+"),r=t.pop().toLowerCase();return[...t.map(s=>s==="Ctrl"?"cmdOrCtrl":s.toLowerCase()),r].join("+")}function H(e){return[{bindings:{[W(e)]:"openSearchReplacePanel"}}]}H(M.editorSearch);const $=2e3;function Y(e,t=$){let r=1;for(let o=0;o<e.length;o+=1)if(e.charCodeAt(o)===10&&(r+=1,r>t))return!0;return!1}function Z(e,t,r=M.saveFile){return U({key:e.key,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey??!1,altKey:e.altKey??!1},r)?(e.preventDefault(),t(),!0):!1}async function J(e){if(!e.dirty||e.readOnly||!e.claim())return"skipped";try{return(await e.persist()).status==="conflict"?(e.onConflict(),"conflict"):(e.onSuccess(),"saved")}catch(t){return e.onError(t),"error"}finally{e.release()}}function Q({file:e,initialContent:t,readOnly:r,messages:o,onDirtyChange:s,onDraftChange:p,onSave:E}){const T=C(),[S,f]=n.useState(t),[v,m]=n.useState(!1),c=n.useRef(!1),a=S!==e.content,y=n.useRef(e.content);n.useLayoutEffect(()=>{S===y.current&&e.content!==y.current&&f(e.content),y.current=e.content},[e.content,S]),n.useEffect(()=>{s(a)},[a,s]),n.useEffect(()=>()=>s(!1),[s]);const g=n.useCallback(u=>{f(u),s(u!==e.content),p(u)},[e.content,s,p]),F=n.useCallback(async()=>{await J({dirty:a,readOnly:r,claim:()=>c.current?!1:(c.current=!0,m(!0),!0),release:()=>{c.current=!1,m(!1)},persist:()=>E(e.path,S,e.content),onConflict:()=>x.error({title:o.conflictTitle,description:"Your draft is still open. Copy it or reload the file before saving again.",duration:1e4}),onSuccess:()=>x.success({title:o.successTitle,description:e.path}),onError:u=>x.error({title:o.errorTitle,description:u instanceof Error?u.message:"Unknown error",duration:1e4})})},[a,S,e.content,e.path,o,E,r]),i=n.useRef(F);return n.useEffect(()=>{i.current=F},[F]),n.useEffect(()=>{const u=h=>{Z(h,()=>{i.current()},T.saveFile)};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[T.saveFile]),{draft:S,updateDraft:g,dirty:a,saving:v,save:F}}function L({dirty:e,saving:t,readOnly:r,onSave:o}){const s=C();if(!e&&!t)return null;const p=r?"Read only":t?"Saving…":`Save file (${s.saveFile})`;return l.jsxs(z,{children:[l.jsx(K,{render:l.jsx("button",{type:"button",className:"file-save-button","data-state":r?"readonly":t?"saving":"dirty",disabled:t||r,onClick:o,"aria-label":p}),children:l.jsx(B,{"aria-hidden":"true"})}),l.jsx(P,{children:p})]})}function X({handleRef:e}){const t=O();return n.useLayoutEffect(()=>{e.current=t},[t,e]),null}function w({path:e,cacheKey:t,value:r,themeType:o,wrapLines:s,readOnly:p,onChange:E,ref:T}){const S=n.useContext(D),f=C(),[v]=n.useState(()=>Y(r)),m=n.useRef(E);n.useEffect(()=>{m.current=E},[E]);const c=n.useRef(void 0),a=n.useRef(null),y=n.useMemo(()=>({name:e,lang:_(e),contents:r,cacheKey:t}),[t,e,r]),g=n.useMemo(()=>({disableFileHeader:!0,themeType:o,theme:j,overflow:s?"wrap":"scroll",unsafeCSS:k}),[o,s]),F=n.useMemo(()=>({historyMaxEntries:500,keymap:H(f.editorSearch),onChange(h){m.current(h.contents)}}),[f.editorSearch]),i=n.useRef(null);n.useEffect(()=>()=>i.current?.(),[]),n.useImperativeHandle(T,()=>({getScrollFraction(){const h=c.current?.getRoot()??a.current;if(!(h instanceof HTMLElement))return 0;const d=h.scrollHeight-h.clientHeight;return d>0?h.scrollTop/d:0},scrollToFraction(h){i.current?.(),i.current=G({getScrollRange(){const d=c.current?.getRoot()??a.current;return d instanceof HTMLElement?Math.max(0,d.scrollHeight-d.clientHeight):0},getScrollTop(){const d=c.current?.getRoot()??a.current;return d instanceof HTMLElement?d.scrollTop:0},getContentHeight(){const d=c.current?.getRoot()??a.current;return d instanceof HTMLElement?d.scrollHeight:0},scrollTo(d){const R=c.current;R&&R.getRoot()instanceof HTMLElement?R.scrollTo({top:d}):a.current?.scrollTo({top:d})}},h)}}),[]);const u=l.jsx(I,{file:y,options:g,editorOptions:F,edit:S&&!p});return l.jsx(N,{theme:j,children:v?l.jsxs(A,{className:"source-code-editor",contentClassName:"source-code-editor-content",children:[l.jsx(X,{handleRef:c}),u]}):l.jsx("div",{ref:a,className:"source-code-editor",children:l.jsx("div",{className:"source-code-editor-content",children:u})})})}const ee={conflictTitle:"File was changed outside OpenTig",successTitle:"File saved",errorTitle:"Could not save file"};function te({file:e,initialContent:t,themeType:r,wrapLines:o,readOnly:s,onDirtyChange:p,onDraftChange:E,onSave:T}){const{draft:S,updateDraft:f,dirty:v,saving:m,save:c}=Q({file:e,initialContent:t,readOnly:s,messages:ee,onDirtyChange:p,onDraftChange:E,onSave:T});return l.jsxs("div",{className:"source-file-viewer",children:[(v||m)&&l.jsx("div",{className:"source-file-toolbar",children:l.jsx(L,{dirty:v,saving:m,readOnly:s,onSave:()=>{c()}})}),l.jsx("div",{className:"source-editor-scroll",children:l.jsx(w,{path:e.path,cacheKey:e.path,value:S,themeType:r,wrapLines:o,readOnly:s||m,onChange:f})})]})}const le=Object.freeze(Object.defineProperty({__proto__:null,EditableFileViewer:te,FileSaveControls:L,SourceCodeEditor:w},Symbol.toStringTag,{value:"Module"}));export{le as E,L as F,w as S,G as s,Q as u};
@@ -1 +1 @@
1
- import{C as ge,g as k,D as H,a as j,l as $,b as ee,E as xe,i as Ee,H as Fe,c as ke,d as ze,e as Ie,f as Oe}from"./platform-Bqt97_Jr.js";import{G as Pe,b as te,g as Ne,c as A,i as Y,d as R,e as Ve,f as me,h as ie,j as De,k as Be,l as Ue,s as Ce,m as _e,n as ne,o as re,p as We,q as Ge,t as se,v as je,w as $e,x as Ke,y as qe,z as oe,A as Ye,R as Xe,I as Je,B as ae,C as Qe,D as Ze,E as et,F as tt,H as it,J as nt,K as he,L as rt,M as st,N as ot,Q as at,S as le,T as ht,U as lt,W as dt,X as ct,Y as ut,Z as ft,_ as Se,$ as de,a0 as V,a1 as ce,a2 as pt,u as gt,a3 as mt,a4 as ue,a5 as Ct}from"./PierreWorkerPool-Col4k7qz.js";import{j as y,r as F}from"./react-rd22PHbN.js";import{t as b}from"./one-light-CoLDteqg.js";import{u as St,a as vt}from"./EditContext-CvJWfVl1.js";function yt({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:o,renderGutterUtility:a,getHoveredLine:l}){const d=e?.(i),h=t?.(i),c=n?.(i),u=r?.(i);return y.jsxs(y.Fragment,{children:[d!=null?y.jsx("div",{slot:ge,children:d}):y.jsxs(y.Fragment,{children:[h!=null&&y.jsx("div",{slot:"header-prefix",children:h}),c!=null&&y.jsx("div",{slot:"header-filename-suffix",children:c}),u!=null&&y.jsx("div",{slot:"header-metadata",children:u})]}),s!=null&&o?.map((f,m)=>y.jsx("div",{slot:k(f),children:s(f)},m)),a!=null&&y.jsx("div",{slot:"gutter-utility-slot",style:Pe,children:a(l)})]})}function D(i,e){return e.cacheKey==null?i.file===e&&i.sourceContents===e.contents:i.cacheKey===e.cacheKey}let Rt=-1;var Tt=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++Rt}`;highlighter;renderCache;computedLang="text";lineAnnotations={};lineCache;pendingStructuralRows;textDocumentCache=new WeakMap;editSessionActive=!1;constructor(i={theme:H},e,t){this.options=i,this.onRenderUpdate=e,this.workerManager=t,t?.isWorkingPool()!==!0&&(this.highlighter=te(i.theme??H)?Ne():void 0)}setOptions(i){this.options=i}mergeOptions(i){this.options={...this.options,...i}}setLineAnnotations(i){this.lineAnnotations={};for(const e of i){const t=this.lineAnnotations[e.lineNumber]??[];this.lineAnnotations[e.lineNumber]=t,t.push(e)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}beginEditSession(){this.editSessionActive=!0}endEditSession(){this.editSessionActive=!1}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0,this.endEditSession(),this.textDocumentCache=new WeakMap}syncEditedContentsToFile(){const{renderCache:i,lineCache:e}=this;i?.isDirty!==!0||e==null||!D(e,i.file)||(i.file.contents=e.lines.join(""))}hasUnkeyedFileContentsChanged(i){const{lineCache:e}=this;return i.cacheKey==null&&e!=null&&e.file===i&&e.sourceContents!==i.contents}invalidateChangedUnkeyedFile(i){this.hasUnkeyedFileContentsChanged(i)&&(this.workerManager?.cleanUpTasks(this),this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap)}clearRenderCache(){this.syncEditedContentsToFile(),this.pendingStructuralRows=void 0;const i=this.renderCache;this.renderCache=void 0,i!=null&&i.isDirty===!0&&i.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(i.file.cacheKey)}hydrate(i){const{options:e}=this.getRenderOptions(i),t=K(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());let n=this.workerManager?.getFileResultCache(i);n!=null&&!A(e,n.options)&&(n=void 0),this.renderCache??={file:i,options:e,highlighted:!t&&!Y(i),result:t?void 0:n?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!t&&this.workerManager.highlightFileAST(this,i):this.highlighter==null&&(this.computedLang=i.lang??j(i.name),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getFileRenderOptions().theme??this.options.theme??H}getEffectiveCodeOptions(){const i=this.workerManager?.isWorkingPool()===!0?this.workerManager.getFileRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:i?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(i){const e=(()=>{if(this.workerManager?.isWorkingPool()===!0){const r=this.workerManager.getFileRenderOptions();return this.editSessionActive&&r.useTokenTransformer!==!0?{...r,useTokenTransformer:!0}:r}const{tokenizeMaxLineLength:n=1e3}=this.options;return{theme:this.getLocalHighlightTheme(),useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:n}})(),{renderCache:t}=this;return t?.result==null?{options:e,forceHighlight:!0}:!R(i,t.file)||!A(e,t.options)?{options:e,forceHighlight:!0}:{options:e,forceHighlight:!1}}getOrCreateLineCache(i){this.invalidateChangedUnkeyedFile(i);let{lineCache:e}=this;return(e==null||!D(e,i))&&(e={cacheKey:i.cacheKey,file:i,sourceContents:i.contents,lines:$(i.contents)}),this.lineCache=e,e.lines}getLineCount(i){const e=this.getOrCreateLineCache(i);return this.textDocumentCache.get(i)?.lineCount??e.length}updateRenderCache(i,e,t=!1){if(this.pendingStructuralRows=void 0,this.renderCache==null)return;const{file:n,result:r}=this.renderCache;if(r==null)return;const s=t?new Map:void 0;this.pendingStructuralRows=s;const o=this.lineCache!=null&&D(this.lineCache,n)?this.lineCache:void 0;for(const[a,l]of i){if(s===void 0&&o!=null&&a<o.lines.length){const h=l.map(c=>c[2]).join("");o.lines[a]=Ve(o.lines[a]??"",h)}const d={type:"element",tagName:"div",properties:{"data-line":a+1,"data-line-type":"context","data-line-index":a},children:l.map(([h,c,u])=>h===0&&c===""?u===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:u}:{type:"element",tagName:"span",properties:{"data-char":h,style:`color:${c};`},children:[{type:"text",value:u}]})};s!==void 0?s.set(a,d):r.code[a]=d}r.baseThemeType=e,this.renderCache.isDirty=!0}applyDocumentChange(i){const e=this.pendingStructuralRows;if(this.pendingStructuralRows=void 0,this.renderCache==null)return;const{file:t,result:n}=this.renderCache;if(n==null)return;const r=this.lineCache!=null&&D(this.lineCache,t)?this.lineCache.lines:$(t.contents),s=$(i.getText());if(r.length!==s.length){const o=Math.min(r.length,s.length);let a=0;for(;a<o&&r[a]===s[a];)a++;let l=0;for(;l<o-a&&r[r.length-1-l]===s[s.length-1-l];)l++;const d=n.code;n.code=new Array(s.length);for(let h=0;h<a;h++)n.code[h]=d[h];for(let h=0;h<l;h++)n.code[s.length-1-h]=d[r.length-1-h];if(e!==void 0)for(const[h,c]of e)h<s.length&&(n.code[h]=c);for(let h=a;h<s.length-l;h++)n.code[h]??={type:"element",tagName:"div",properties:{"data-line":h+1,"data-line-type":"context","data-line-index":h},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:i.getLineText(h)}]}]};for(let h=0;h<n.code.length;h++){const c=n.code[h];c?.type==="element"&&(c.properties["data-line"]=h+1,c.properties["data-line-index"]=h)}this.renderCache.isDirty=!0}this.lineCache={cacheKey:t.cacheKey,file:t,sourceContents:t.contents,lines:s},this.textDocumentCache.set(t,i)}renderFile(i=this.renderCache?.file,e=ee){if(i==null)return;this.invalidateChangedUnkeyedFile(i),this.renderCache?.isDirty===!0&&!R(i,this.renderCache.file)&&(this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap);let{options:t,forceHighlight:n}=this.getRenderOptions(i);this.renderCache?.isDirty===!0&&!A(t,this.renderCache.options)&&this.clearRenderCache();const r=this.getMatchingWorkerResultCache(i,t);r!=null&&!this.hasHighlightedRenderCache(i,t)&&(this.renderCache={file:i,highlighted:!0,renderRange:void 0,...r},n=!1),this.renderCache??={file:i,highlighted:!1,options:t,result:void 0,renderRange:void 0};const s=this.getOrCreateLineCache(i),o=i.contents.length>0,a=!o||Y(i)||K(s.length,this.getTokenizeMaxLength()),l=!R(i,this.renderCache.file),d=!me(this.renderCache.renderRange,e);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0)(a||this.renderCache.result==null||!this.renderCache.highlighted&&(l||d))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||l||d||n)&&(this.renderCache.result=this.workerManager.getPlainFileAST(i,e.startingLine,e.totalLines,s)),this.renderCache.renderRange=e),!a&&o&&(!this.renderCache.highlighted||n)&&this.workerManager.highlightFileAST(this,i);else{this.computedLang=i.lang??j(i.name);const h=this.highlighter!=null&&te(t.theme),c=this.highlighter!=null&&ie(this.computedLang),u=!a&&c;if(this.highlighter!=null&&h&&(n||a||!this.renderCache.highlighted&&u||this.renderCache.result==null)){const{result:f,options:m}=this.renderFileWithHighlighter(i,this.highlighter,a||!c);this.renderCache={file:i,options:m,highlighted:u,result:f,renderRange:void 0}}(!h||!a&&!c)&&this.asyncHighlight(i).then(({result:f,options:m})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(i,f,m,!a)})}return this.renderCache.result!=null?this.processFileResult(this.renderCache.file,e,this.renderCache.result):void 0}async asyncRender(i,e=ee){const{result:t}=await this.asyncHighlight(i);return this.processFileResult(i,e,t)}async asyncHighlight(i){const e=K(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());this.computedLang=e?"text":i.lang??j(i.name);const t=this.highlighter!=null&&De(Be(this.getLocalHighlightTheme())),n=e||this.highlighter!=null&&ie(this.computedLang);return(this.highlighter==null||!t||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(i,this.highlighter,e)}renderFileWithHighlighter(i,e,t=!1){const{options:n}=this.getRenderOptions(i);return{result:Ue(i,e,n,{forcePlainText:t}),options:n}}processFileResult(i,e,{code:t,themeStyles:n,baseThemeType:r}){const s=this.getLineCount(i),{disableFileHeader:o=!1}=this.options,a=[],l=oe(),d=Math.min(e.startingLine+e.totalLines,s);let h=0;const c=Ce(e)?_e(this.lineAnnotations):void 0;c!=null&&(l.children.push(ne("context","annotation",1)),a.push(re({hunkIndex:-1,lineIndex:-1,annotations:c.map(u=>k(u))})),h++);for(let u=e.startingLine;u<d;u++){const f=u+1,m=t[u];if(m==null){const C="FileRenderer.processFileResult: Line doesnt exist";throw console.error(C,{name:i.name,lineIndex:u,lineNumber:f}),new Error(C)}l.children.push(We("context",f,`${u}`)),a.push(m),h++;const g=this.lineAnnotations[f];g!=null&&(l.children.push(ne("context","annotation",1)),a.push(re({hunkIndex:0,lineIndex:f,annotations:g.map(C=>k(C))})),h++)}return l.properties.style=`grid-row: span ${h}`,{gutterAST:l.children??[],contentAST:a,preAST:this.createPreElement(s),headerAST:o?void 0:this.renderHeader(i),totalLines:s,rowCount:h,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return Ge({fileOrDiff:i,mode:e,stickyHeader:t})}renderFullHTML(i){return b(this.renderFullAST(i))}renderFullAST(i,e=[]){return e.push(se({tagName:"code",children:this.renderCodeAST(i),properties:{"data-code":""}})),{...i.preAST,children:e}}renderCodeAST(i){const e=oe();return e.children=i.gutterAST,e.properties.style=`grid-row: span ${i.rowCount}`,[e,je(i.contentAST,i.rowCount)]}renderPartialHTML(i,e=!1){return e?b(se({tagName:"code",children:i,properties:{"data-code":""}})):b(i)}async initializeHighlighter(){return this.highlighter=await $e(Ke(this.computedLang,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}onHighlightSuccess(i,e,t,n=!0){this.editSessionActive||this.applyHighlightResult(i,e,t,n)}applyHighlightResult(i,e,t,n=!0){if(this.renderCache==null)return;const r=!R(i,this.renderCache.file)||!this.renderCache.highlighted||!A(t,this.renderCache.options);this.renderCache={file:i,options:t,highlighted:n,result:e,renderRange:void 0},r&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(i,e){if(this.editSessionActive)return;const t=this.workerManager?.getFileResultCache(i);if(!(t==null||!A(e,t.options)))return t}hasHighlightedRenderCache(i,e){const{renderCache:t}=this;return t?.result!=null&&t.highlighted&&R(i,t.file)&&A(e,t.options)}onHighlightError(i){console.error(i)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(i){const{disableLineNumbers:e=!1,overflow:t="scroll"}=this.options;return qe({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function K(i,e){return i>e}function Lt(i,e){return i.lineNumber===e.lineNumber&&i.metadata===e.metadata}function fe(i){return{theme:i?.theme,disableLineNumbers:i?.disableLineNumbers,overflow:i?.overflow,themeType:i?.themeType,collapsed:i?.collapsed,disableFileHeader:i?.disableFileHeader,disableVirtualizationBuffers:i?.disableVirtualizationBuffers,stickyHeader:i?.stickyHeader,preferredHighlighter:i?.preferredHighlighter,useCSSClasses:i?.useCSSClasses,useTokenTransformer:Ye(i),tokenizeMaxLineLength:i?.tokenizeMaxLineLength,tokenizeMaxLength:i?.tokenizeMaxLength,unsafeCSS:i?.unsafeCSS,headerRenderMode:i?.renderCustomHeader!=null?"custom":"default"}}const Mt=[""];let At=-1;var ve=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++At}`;type="file";fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerFilenameSuffix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;renderRange;enabled=!0;editor;constructor(e={theme:H},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new Tt(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Xe,this.interactionManager=new Je("file",ae(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}__getCurrentFile(){return this.file}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(ae(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;const t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Qe(this.appliedThemeCSS.theme,this.options.theme??H)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??"additions"})}getCodeScrollLeft(){return this.code?.scrollLeft??0}setCodeScrollLeft(e){this.code!=null&&(this.code.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.fileRenderer.getEffectiveCodeOptions()}}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{overflow:e="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:e==="wrap",columnVariables:this.shouldApplyColumnVariables(e)?"apply":"measure"}),this.managersDirty=!1}shouldApplyColumnVariables(e){return e==="scroll"&&this.lineAnnotations.length>0}cleanUp(e=!1){this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 0,this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.pre=void 0,this.code=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:s,lineAnnotations:o}=e;if(!this.enabled)throw new Error("File.hydrate: attempting to call hydrate after cleaned up");if(this.fileContainer!=null)throw new Error("File.hydrate: hydrate can only be called before the instance has rendered or hydrated");this.hydrateElements(t,n),Ht(this.pre,s,this.options.collapsed)||bt(this.headerElement,s,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:s,lineAnnotations:o}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),Ze(e,t);for(const n of Array.from(e.shadowRoot?.children??[])){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n,this.appliedPreAttributes=void 0;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}if("diffsHeader"in n.dataset){this.headerElement=n,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(fe(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.file){return e!=null?this.fileRenderer.getOrCreateLineCache(e):Mt}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,n=this.file,r=this.lineAnnotations,s=this.renderRange;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(o=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.file!==n||e.__syncRenderView(o,t,n,r,s)})}attachEditor(e){this.editor?.cleanUp(),this.editor=e,this.fileRenderer.beginEditSession();const t=this.file==null?void 0:e.__prepareFile?.(this.file);return t!==void 0&&t!==this.file?this.renderPreparedFile({file:t,forceRender:!0,preventEmit:!0,renderRange:this.renderRange}):this.fileRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),()=>{this.editor=void 0,this.fileRenderer.endEditSession()}}applyDocumentChange(e,t){this.fileRenderer.applyDocumentChange(e),t!=null&&t!==this.lineAnnotations&&this.file!=null&&(this.setLineAnnotations(t),this.fileRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}updateRenderCache(e,t,n){this.fileRenderer.updateRenderCache(e,t,n?.lineCountChangeInFlight)}render(e){if(!this.enabled)throw new Error("File.render: attempting to call render after cleaned up");const t=this.editor?.__prepareFile?.(e.file)??e.file;return this.renderPreparedFile(t===e.file?e:{...e,file:t})}renderPreparedFile({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:s,deferManagers:o=!1,lineAnnotations:a,renderRange:l}){this.editor?.__postponeBgTokenizeToNextFrame();const{collapsed:d=!1,themeType:h="system"}=this.options,c=d?void 0:l,u=this.renderRange,f=this.hasThemeChanged(),m=a!=null&&(a.length>0||this.lineAnnotations.length>0)?a!==this.lineAnnotations:!1,g=!R(this.file,e)||this.fileRenderer.hasUnkeyedFileContentsChanged(e);if(!d&&!n&&me(c,this.renderRange)&&!g&&!m&&!f)return this.applyCachedThemeState(h);this.renderRange=c,g&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(fe(this.options)),this.syncInteractionOptions(),a!=null&&this.setLineAnnotations(a),this.fileRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:C=!1,disableFileHeader:S=!1}=this.options;if(S&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,s),this.applyCachedThemeState(h),d){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const p=this.fileRenderer.renderFile(e,xe);p!=null&&this.applyThemeState(t,p.themeStyles,h,p.baseThemeType),p?.headerAST!=null&&this.applyHeaderToDOM(p.headerAST,t),this.injectUnsafeCSS()}catch(p){if(C)throw p;console.error(p),p instanceof Error&&this.applyErrorToDOM(p,t)}return r||this.emitPostRender(),!0}try{const p=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,m,g||f)||!this.applyPartialRender(u,c)){const v=this.fileRenderer.renderFile(e,c);if(v==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,v.themeStyles,h,v.baseThemeType),v.headerAST!=null&&this.applyHeaderToDOM(v.headerAST,t),this.applyFullRender(v,p)}this.applyBuffers(p,c),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,o||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(p){if(C)throw p;console.error(p),p instanceof Error&&this.applyErrorToDOM(p,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,"unmount");return}if(t==null)return;const r=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}async primeHighlightCache(e=this.file){const{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||Y(e))return;const n=this.options.tokenizeMaxLength??1e5;this.fileRenderer.getOrCreateLineCache(e).length>n||await t.primeFileHighlightCache(e).catch(r=>{console.error(r)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[n,r]of this.lineAnnotations.entries()){const s=`${n}-${k(r)}`;let o=this.annotationCache.get(s);if(o==null||!Lt(r,o.annotation)){o?.element.remove();const a=t(r);if(a==null)continue;o={element:et(k(r)),annotation:r},o.element.appendChild(a),this.fileContainer.appendChild(o.element),this.annotationCache.set(s,o)}e.delete(s)}for(const[n,{element:r}]of e.entries())this.annotationCache.delete(n),r.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const n=tt();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){const{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=it(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=nt(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){const s=e.shadowRoot??e.attachShadow({mode:"open"}),o=r??n,a=this.options.theme??H,l=typeof a=="string"?a:{...a},d=he(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===o&&this.appliedThemeCSS.scrollbarGutter===d){this.appliedThemeCSS.theme=l;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:l,themeStyles:t,themeType:o,baseThemeType:r,scrollbarGutter:d};return}this.themeCSSStyle=rt({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:ct(t,o,d)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:l,themeStyles:t,themeType:o,baseThemeType:r,scrollbarGutter:d}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=st(this.themeCSSStyle.textContent??"",he(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&Ee()}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e);const n=this.code=ot({code:this.code}),r=this.fileRenderer.renderCodeAST(e);this.editor?.__captureFocusForDOMReplacement();const s=()=>{if(n.childElementCount>=2)for(let o=0;o<2;o++){const a=n.children[o],l=r[o];a.innerHTML=b(l.children),a.style.cssText=l.properties.style}else n.innerHTML=b(r);t.contains(n)||t.replaceChildren(n)};this.shouldGuardRebuildScroll()?at(t,s):s(),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;const{file:n,code:r}=this,s=r!=null?this.getColumns(r):void 0;if(n==null||r==null||s==null)return!1;const o=e.startingLine,a=t.startingLine,l=e.totalLines===1/0?Number.POSITIVE_INFINITY:o+e.totalLines,d=t.totalLines===1/0?Number.POSITIVE_INFINITY:a+t.totalLines,h=Math.max(o,a),c=Math.min(l,d);if(c<=h)return!1;if(!this.trimDOMToOverlap(s.gutter,h,c)||!this.trimDOMToOverlap(s.content,h,c))throw new Error("File.applyPartialRender: failed to trim to overlap");let{length:u}=s.content.children;const f=(S,p)=>{if(!(p<=0))return this.fileRenderer.renderFile(n,{startingLine:S,totalLines:p,bufferBefore:0,bufferAfter:0})},m=a<h?f(a,h-a):void 0;if(m===void 0&&a<h)return!1;const g=d===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(0,d-c),C=d>c?f(c,g):void 0;return C===void 0&&d>c?!1:(this.cleanupErrorWrapper(),m!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(m.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(m.contentAST)),u+=m.rowCount),C!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(C.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(C.contentAST)),u+=C.rowCount),this.lastRowCount!==u&&(s.gutter.style.setProperty("grid-row",`span ${u}`),s.content.style.setProperty("grid-row",`span ${u}`),this.lastRowCount=u),!0)}getColumns(e){const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){const r=this.getDOMBoundaryIndices(e,[t,n]),s=r.get(t)??e.children.length,o=r.get(n)??e.children.length;if(s>o)return!1;for(let a=e.children.length-1;a>=o;a-=1)e.children[a]?.remove();for(let a=s-1;a>=0;a-=1)e.children[a]?.remove();return!0}getDOMBoundaryIndices(e,t){const n=[...new Set(t)].sort((l,d)=>l-d),r=new Map;if(n.length===0)return r;let s=0,o=n[s];const{children:a}=e;o===0&&(r.set(0,0),s+=1,o=n[s]);for(let l=0;l<a.length;l+=1){const d=a[l];if(!(d instanceof HTMLElement))continue;const h=this.getLineIndexFromDOMNode(d);if(h!=null){for(;o!=null&&h>=o;)r.set(o,l),s+=1,o=n[s];if(s>=n.length)break}}for(const l of n)r.has(l)||r.set(l,a.length);return r}getLineIndexFromDOMNode(e){const t=e.dataset.lineIndex;if(t==null)return;const n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t){const{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const r=this.cachedHeaderHTML??b(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){const d=document.createElement("div");d.innerHTML=r;const h=d.firstElementChild;if(!(h instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(h,this.headerElement):t.shadowRoot?.prepend(h),this.headerElement=h,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:o,renderCustomHeader:a,renderHeaderMetadata:l}=this.options;if(a!=null){const d=a(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,ge,d),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{const d=s?.(n)??void 0,h=o?.(n)??void 0,c=l?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Fe,d),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,ke,h),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,ze,c),this.headerCustom?.remove(),this.headerCustom=void 0}}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,r){if(r==null){t?.remove();return}const s=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,r),s}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){const t=document.createElement("div");return t.slot=e,t}getOrCreateFileContainerNode(e,t){const{fileContainer:n}=this,r=e??n??document.createElement("diffs-container"),s=n!==r;return n!=null&&s&&this.editor?.__captureFocusForDOMReplacement(),s&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&s&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const n of t.children)n instanceof SVGElement?this.spriteSVG??=n:le(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):le(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=n,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const n=document.createElement("div");n.innerHTML=ht;const r=n.firstChild;r instanceof SVGElement&&(this.spriteSVG=r)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(this.editor?.__captureFocusForDOMReplacement(),e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(const t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute("data-code")){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){const{overflow:n="scroll",disableLineNumbers:r=!1}=this.options,s={type:"file",split:!1,overflow:n,disableLineNumbers:r,diffIndicators:"none",disableBackground:!0,totalLines:t};lt(s,this.appliedPreAttributes)||(dt(e,s),this.appliedPreAttributes=s)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);const r=document.createElement("div");r.dataset.errorMessage="",r.innerText=e.message,this.errorWrapper.appendChild(r);const s=document.createElement("pre");s.dataset.errorStack="",s.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(s)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Ht(i,e,t=!1){return!t&&i==null&&e!=null}function bt(i,e,t=!1){return i==null&&e!=null&&!t}const wt=5e3;let xt=-1;function Et(i,e){return(i.overflow??"scroll")!==(e.overflow??"scroll")||(i.collapsed??!1)!==(e.collapsed??!1)||(i.disableLineNumbers??!1)!==(e.disableLineNumbers??!1)||(i.disableFileHeader??!1)!==(e.disableFileHeader??!1)||i.unsafeCSS!==e.unsafeCSS}var Ft=class extends ve{virtualizer;metrics;__id=`virtualized-file:${++xt}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(i,e,t=Ie,n,r=!1){super(i,n,r),this.virtualizer=e,this.metrics=t}setMetrics(i,e=!1){const t=ut(i);!e&&ft(this.metrics,t)||(this.metrics=t,this.resetLayoutCache())}setLineAnnotations(i){this.syncLineAnnotations(i)&&this.resetLayoutCache()}syncLineAnnotations(i){return i==null||i===this.lineAnnotations||i.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(i),!0)}hasLineAnnotations(){return this.lineAnnotations.some(i=>i.lineNumber>0)}getLineHeight(i,e=!1){const t=this.cache.heights.get(i);if(t!=null)return t;const n=e?2:1;return this.metrics.lineHeight*n}setOptions(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(i==null)return;const{options:e}=this,t=!Se(e,i),n=Et(e,i);super.setOptions(i),n&&this.resetLayoutCache(!0),t&&(this.forceRenderOverride=!0),t&&this.virtualizer.instanceChanged(this,n)}setThemeType(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(i)}resetLayoutCache(i=!1,e=!0){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.renderRange!=null&&e&&(this.renderRange=void 0),i&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let i=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(i=!0),this.height=0,i;const{overflow:e="scroll"}=this.options;if(this.top=this.getVirtualizedTop(),e==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return i;const t=this.code.children[1];if(!(t instanceof HTMLElement))return i;const n=de(this.lineAnnotations);if(this.renderRange!=null&&n&&Ce(this.renderRange)){const r=kt(t)??0;r!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=r,i=!0)}else!n&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,i=!0);for(const r of t.children){if(!(r instanceof HTMLElement))continue;const s=r.dataset.lineIndex;if(s==null)continue;const o=Number(s);let a=r.getBoundingClientRect().height,l=!1;r.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in r.nextElementSibling.dataset||"noNewline"in r.nextElementSibling.dataset)&&("noNewline"in r.nextElementSibling.dataset&&(l=!0),a+=r.nextElementSibling.getBoundingClientRect().height);const d=this.getLineHeight(o,l);a!==d&&(i=!0,a===this.metrics.lineHeight*(l?2:1)?this.cache.heights.delete(o):this.cache.heights.set(o,a))}return(i||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),i}onRender=i=>this.fileContainer==null||this.file==null?!1:(i&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(i,e,t,n){const r=this.syncLineAnnotations(n),s=!R(this.file,i)||this.fileRenderer.hasUnkeyedFileContentsChanged(i);let o=t?.resetFileLayoutCache===!0||s||r;t?.metrics!=null&&(this.metrics=t.metrics,o=!0);const{collapsed:a=!1}=this.options;return this.currentCollapsed!==a&&(this.currentCollapsed=a,o=!0),o&&this.resetLayoutCache(),this.file!==i&&(this.layoutDirty=!0),this.file=i,this.top=e,this.computeApproximateSize(),this.height}getLinePosition(i){if(this.file==null||i<1)return;const{disableFileHeader:e=!1,collapsed:t=!1}=this.options,n=this.fileRenderer.getLineCount(this.file)-1;let r=V(this.metrics,e);if(t||n<0)return{top:r,height:0};const s=Math.min(Math.max(i-1,0),n),{overflow:o="scroll"}=this.options,{lineHeight:a}=this.metrics;if(r+=this.cache.fileAnnotationHeight,o==="scroll"&&!this.hasLineAnnotations())return{top:r+s*a,height:a};const l=this.getLayoutCheckpointBeforeLineIndex(s);r=l?.top??r;for(let d=l?.lineIndex??0;d<s;d++)r+=this.getLineHeight(d,!1);return{top:r,height:this.getLineHeight(s,!1)}}getEditorViewport(){return this.virtualizer.type==="simple"?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(i){if(this.file==null||this.renderRange==null)return;const{disableFileHeader:e=!1,collapsed:t=!1,overflow:n="scroll"}=this.options;if(t||this.renderRange.totalLines<=0)return;const r=this.fileRenderer.getLineCount(this.file)-1;if(r<0)return;const s=V(this.metrics,e),o=Math.min(this.renderRange.startingLine,r),a=Math.min(o+this.renderRange.totalLines-1,r);if(a<o)return;const{fileAnnotationHeight:l}=this.cache;if(n==="scroll"&&!this.hasLineAnnotations()){const{lineHeight:h}=this.metrics,c=s+(o===0?l:this.renderRange.bufferBefore),u=o+Math.max(Math.ceil((i-c)/h),0);return u>a?void 0:{lineNumber:u+1,top:s+l+u*h}}let d=s+(o===0?l:this.renderRange.bufferBefore);for(let h=o;h<=a;h++){if(d>=i)return{lineNumber:h+1,top:d};d+=this.getLineHeight(h)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(i){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const e=i!=null?this.computeRenderRangeFromWindow(this.file,this.top,i):this.renderRange;if(e==null)return;const{bufferBefore:t,bufferAfter:n,totalLines:r}=e;let s=0;if(r===0){const o=i??this.virtualizer.getWindowSpecs();this.top<o.top&&(s=n)}return{topOffset:this.top+t+s,height:this.height-(t+n)}}cleanUp(i=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),i||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(i)}computeApproximateSize(i=!1,e=this.file){const t=this.isResizeDebuggingEnabled();if(!i&&!this.layoutDirty&&!t)return;const n=this.height===0;if(this.height=0,this.cache.checkpoints=[],e==null){this.layoutDirty=!1;return}const{disableFileHeader:r=!1,collapsed:s=!1,overflow:o="scroll"}=this.options,{lineHeight:a}=this.metrics,l=this.fileRenderer.getLineCount(e),d=V(this.metrics,r),h=ce(this.metrics);if(this.height+=d,s){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,o==="scroll"&&!this.hasLineAnnotations())this.height+=l*a;else for(let c=0;c<l;c++)this.addLayoutCheckpoint(c,this.height),this.height+=this.getLineHeight(c,!1);if(l>0&&(this.height+=h),this.fileContainer!=null&&t&&!n){const c=this.fileContainer.getBoundingClientRect();c.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:e.name,elementHeight:c.height,computedHeight:this.height}):console.log("VirtualizedFile.computeApproximateSize: computed height IS CORRECT")}this.layoutDirty=!1}setVisibility(i){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,i&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!i&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(i,e,t=!1){const{renderRange:n}=this;if(this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(i,e),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(this.isSimpleMode(),!1),!this.isSimpleMode())this.computeApproximateSize(!0);else if(t&&n!==void 0&&this.file!==void 0){const r=this.virtualizer.getWindowSpecs(),s=this.computeRenderRangeFromWindow(this.file,this.top??0,r);s.bufferAfter!==n.bufferAfter&&this.updateBuffers(s)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}renderPreparedFile({fileContainer:i,file:e,forceRender:t=!1,lineAnnotations:n,...r}){const s=this.file==null||!R(this.file,e)||this.fileRenderer.hasUnkeyedFileContentsChanged(e),{forceRenderOverride:o,isSetup:a}=this;this.forceRenderOverride=void 0;const l=this.syncLineAnnotations(n);if(l&&this.resetLayoutCache(),i=this.getOrCreateFileContainerNode(i),e==null)return console.error("VirtualizedFile.render: attempting to virtually render when we dont have file"),!1;if(a)this.top??=this.getVirtualizedTop(),s&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!1),this.computeApproximateSize(!1,e));else{this.computeApproximateSize(!1,e);const f=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(f==null)throw new Error("VirtualizedFile.render: simple virtualizer is not available");f.connect(i,this),this.isVisible=f.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!s||!a))return this.file=e,s&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);const d=this.virtualizer.getWindowSpecs(),h=this.top??0,c=this.computeRenderRangeFromWindow(e,h,d),u=super.renderPreparedFile({file:e,fileContainer:i,renderRange:c,lineAnnotations:n,forceRender:(o??t)||l||s,...r});return this.isSimpleMode()&&u&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),u}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}addLayoutCheckpoint(i,e){i%wt===0&&this.cache.checkpoints.push({lineIndex:i,top:e})}getLayoutCheckpointBeforeLineIndex(i){if(i<=0||this.cache.checkpoints.length===0)return;let e=0,t=this.cache.checkpoints.length-1,n;for(;e<=t;){const r=e+t>>1,s=this.cache.checkpoints[r];if(s==null)throw new Error("VirtualizedFile: invalid checkpoint index");s.lineIndex<=i?(n=s,e=r+1):t=r-1}return n}getLayoutCheckpointBeforeTop(i,e){let t=0,n=this.cache.checkpoints.length-1,r=-1;for(;t<=n;){const s=t+n>>1,o=this.cache.checkpoints[s];if(o==null)throw new Error("VirtualizedFile: invalid checkpoint index");o.top<=i?(r=s,t=s+1):n=s-1}if(e==null)return r>=0?this.cache.checkpoints[r]:void 0;for(let s=r;s>=0;s--){const o=this.cache.checkpoints[s];if(o==null)throw new Error("VirtualizedFile: invalid checkpoint index");if(o.lineIndex%e===0)return o}}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type==="advanced"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(i,e,{top:t,bottom:n}){const{disableFileHeader:r=!1,overflow:s="scroll"}=this.options,{hunkLineCount:o,lineHeight:a}=this.metrics,l=this.fileRenderer.getLineCount(i),d=this.height,h=V(this.metrics,r),c=l>0?ce(this.metrics):0,{fileAnnotationHeight:u}=this.cache,f=h+u,m=Math.max(0,d-h-u-c),g=de(this.lineAnnotations),C=e+h,S=u>0&&g&&C<n&&C+u>t;if(e<t-d||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-h-c};if(l<=o)return{startingLine:0,totalLines:o,bufferBefore:0,bufferAfter:0};const p=Math.ceil(Math.max(n-t,0)/a),v=Math.ceil(p/o)*o+o,z=v/o,B=(t+n)/2;if(s==="scroll"&&!this.hasLineAnnotations()){const M=e+f,N=M+m;if(!S&&!(M<n&&N>t))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-h-c};const x=Math.floor(S&&B<e+f?0:(B-(e+f))/a),L=Math.floor(x/o)-Math.floor(z/2),He=Math.ceil(l/o),E=Math.max(0,Math.min(L,He))*o,Z=L<0?v+L*o:v,be=E===0?0:u+E*a,we=Math.min(Z,l-E);return{startingLine:E,totalLines:Z,bufferBefore:be,bufferAfter:Math.max(0,(l-E-we)*a)}}const ye=z,I=[],U=this.getLayoutCheckpointBeforeTop(Math.max(0,t-e-v*a*2),o);let T=e+(U?.top??f),_=U?.lineIndex??0,O,P,w;const Re=U?.lineIndex??0;for(let M=Re;M<l;M++){const N=_%o===0,x=Math.floor(_/o);if(N&&(I[x]=T-(e+f),w!=null)){if(w<=0)break;w--}const L=this.getLineHeight(M,!1);T>t-L&&T<n&&(O??=x),T+L>B&&(P??=x),w==null&&T>=n&&N&&(w=ye),_++,T+=L}if(O==null)if(S)O=0,P=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-h-c};P??=O;const W=Math.round(P-z/2),Te=Math.max(0,Math.ceil(l/o)-z),G=Math.max(0,Math.min(W,Te)),X=G*o,J=W<0?v+W*o:v,Le=I[G]??0,Me=X===0?0:u+Le,Q=G+J/o,Ae=Q<I.length?m-I[Q]:m-(T-e-f);return{startingLine:X,totalLines:J,bufferBefore:Me,bufferAfter:Math.max(0,Ae)}}};function kt(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===pt&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}const pe=typeof window>"u"?F.useEffect:F.useLayoutEffect;function zt({file:i,options:e,editorOptions:t,lineAnnotations:n,selectedLines:r,prerenderedHTML:s,metrics:o,hasGutterRenderUtility:a,hasCustomHeader:l,disableWorkerPool:d,edit:h}){const c=gt(),u=r!==void 0,f=F.useContext(mt),m=St(),g=F.useRef(null),C=vt(S=>{if(S!=null){if(g.current!=null)throw new Error("File: An instance should not already exist when a node is created");c!=null?g.current=new Ft(q({controlledSelection:u,hasCustomHeader:l,hasGutterRenderUtility:a,options:e}),c,o,d?void 0:f,!0):g.current=new ve(q({controlledSelection:u,hasCustomHeader:l,hasGutterRenderUtility:a,options:e}),d?void 0:f,!0),g.current.hydrate({file:i,fileContainer:S,lineAnnotations:n,prerenderedHTML:s})}else{if(g.current==null)throw new Error("File: A File instance should exist when unmounting");g.current.cleanUp(),g.current=null}});return pe(()=>{if(g.current==null)return;const S=q({controlledSelection:u,hasCustomHeader:l,hasGutterRenderUtility:a,options:e}),p=S!==void 0&&!Se(g.current.options,S);g.current.setOptions(S),g.current.render({file:i,lineAnnotations:n,forceRender:p}),r!==void 0&&g.current.setSelectedLines(r)}),pe(()=>{if(h&&g.current!=null){if(m===void 0)throw new Error("File: EditContext is not attached");const S=m(t??{});if(S==null)throw new Error("File: EditProvider.createEditor must return an editor instance");try{return S.edit(g.current)}catch(p){throw S.cleanUp(),p}}},[h]),{ref:C,getHoveredLine:F.useCallback(()=>g.current?.getHoveredLine(),[])}}function q({options:i,controlledSelection:e,hasCustomHeader:t,hasGutterRenderUtility:n}){return e||n||t?{...i,controlledSelection:e,renderCustomHeader:t?ue:i?.renderCustomHeader,renderGutterUtility:n?ue:i?.renderGutterUtility}:i}function Bt({file:i,lineAnnotations:e,selectedLines:t,options:n,editorOptions:r,metrics:s,className:o,style:a,renderAnnotation:l,renderCustomHeader:d,renderHeaderPrefix:h,renderHeaderFilenameSuffix:c,renderHeaderMetadata:u,prerenderedHTML:f,renderGutterUtility:m,disableWorkerPool:g=!1,edit:C=!1}){const{ref:S,getHoveredLine:p}=zt({file:i,options:n,editorOptions:r,metrics:s,lineAnnotations:e,selectedLines:t,prerenderedHTML:f,hasGutterRenderUtility:m!=null,hasCustomHeader:d!=null,disableWorkerPool:g,edit:C});return y.jsx(Oe,{ref:S,className:o,style:a,children:Ct(yt({file:i,renderAnnotation:l,renderCustomHeader:d,renderHeaderPrefix:h,renderHeaderFilenameSuffix:c,renderHeaderMetadata:u,renderGutterUtility:m,lineAnnotations:e,getHoveredLine:p}),f)})}export{Bt as F};
1
+ import{C as ge,g as k,D as H,a as j,l as $,b as ee,E as xe,i as Ee,H as Fe,c as ke,d as ze,e as Ie,f as Oe}from"./platform-Bqt97_Jr.js";import{G as Pe,b as te,g as Ne,c as A,i as Y,d as R,e as Ve,f as me,h as ie,j as De,k as Be,l as Ue,s as Ce,m as _e,n as ne,o as re,p as We,q as Ge,t as se,v as je,w as $e,x as Ke,y as qe,z as oe,A as Ye,R as Xe,I as Je,B as ae,C as Qe,D as Ze,E as et,F as tt,H as it,J as nt,K as he,L as rt,M as st,N as ot,Q as at,S as le,T as ht,U as lt,W as dt,X as ct,Y as ut,Z as ft,_ as Se,$ as de,a0 as V,a1 as ce,a2 as pt,u as gt,a3 as mt,a4 as ue,a5 as Ct}from"./PierreWorkerPool-BxP-s6jD.js";import{j as y,r as F}from"./react-rd22PHbN.js";import{t as b}from"./one-light-CoLDteqg.js";import{u as St,a as vt}from"./EditContext-CvJWfVl1.js";function yt({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:o,renderGutterUtility:a,getHoveredLine:l}){const d=e?.(i),h=t?.(i),c=n?.(i),u=r?.(i);return y.jsxs(y.Fragment,{children:[d!=null?y.jsx("div",{slot:ge,children:d}):y.jsxs(y.Fragment,{children:[h!=null&&y.jsx("div",{slot:"header-prefix",children:h}),c!=null&&y.jsx("div",{slot:"header-filename-suffix",children:c}),u!=null&&y.jsx("div",{slot:"header-metadata",children:u})]}),s!=null&&o?.map((f,m)=>y.jsx("div",{slot:k(f),children:s(f)},m)),a!=null&&y.jsx("div",{slot:"gutter-utility-slot",style:Pe,children:a(l)})]})}function D(i,e){return e.cacheKey==null?i.file===e&&i.sourceContents===e.contents:i.cacheKey===e.cacheKey}let Rt=-1;var Tt=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++Rt}`;highlighter;renderCache;computedLang="text";lineAnnotations={};lineCache;pendingStructuralRows;textDocumentCache=new WeakMap;editSessionActive=!1;constructor(i={theme:H},e,t){this.options=i,this.onRenderUpdate=e,this.workerManager=t,t?.isWorkingPool()!==!0&&(this.highlighter=te(i.theme??H)?Ne():void 0)}setOptions(i){this.options=i}mergeOptions(i){this.options={...this.options,...i}}setLineAnnotations(i){this.lineAnnotations={};for(const e of i){const t=this.lineAnnotations[e.lineNumber]??[];this.lineAnnotations[e.lineNumber]=t,t.push(e)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}beginEditSession(){this.editSessionActive=!0}endEditSession(){this.editSessionActive=!1}editorRenderReady(){return this.renderCache?.options.useTokenTransformer===!0&&this.renderCache.highlighted&&this.renderCache.result!=null}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0,this.endEditSession(),this.textDocumentCache=new WeakMap}syncEditedContentsToFile(){const{renderCache:i,lineCache:e}=this;i?.isDirty!==!0||e==null||!D(e,i.file)||(i.file.contents=e.lines.join(""))}hasUnkeyedFileContentsChanged(i){const{lineCache:e}=this;return i.cacheKey==null&&e!=null&&e.file===i&&e.sourceContents!==i.contents}invalidateChangedUnkeyedFile(i){this.hasUnkeyedFileContentsChanged(i)&&(this.workerManager?.cleanUpTasks(this),this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap)}clearRenderCache(){this.syncEditedContentsToFile(),this.pendingStructuralRows=void 0;const i=this.renderCache;this.renderCache=void 0,i!=null&&i.isDirty===!0&&i.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(i.file.cacheKey)}hydrate(i){const{options:e}=this.getRenderOptions(i),t=K(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());let n=this.workerManager?.getFileResultCache(i);n!=null&&!A(e,n.options)&&(n=void 0),this.renderCache??={file:i,options:e,highlighted:!t&&!Y(i),result:t?void 0:n?.result,renderRange:void 0},!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!t&&this.workerManager.highlightFileAST(this,i):this.highlighter==null&&(this.computedLang=i.lang??j(i.name),this.initializeHighlighter())}getLocalHighlightTheme(){return this.workerManager?.getFileRenderOptions().theme??this.options.theme??H}getEffectiveCodeOptions(){const i=this.workerManager?.isWorkingPool()===!0?this.workerManager.getFileRenderOptions():void 0;return{theme:this.getLocalHighlightTheme(),tokenizeMaxLineLength:i?.tokenizeMaxLineLength??this.options.tokenizeMaxLineLength}}getRenderOptions(i){const e=(()=>{if(this.workerManager?.isWorkingPool()===!0){const r=this.workerManager.getFileRenderOptions();return this.editSessionActive&&r.useTokenTransformer!==!0?{...r,useTokenTransformer:!0}:r}const{tokenizeMaxLineLength:n=1e3}=this.options;return{theme:this.getLocalHighlightTheme(),useTokenTransformer:this.editSessionActive||this.options.useTokenTransformer===!0,tokenizeMaxLineLength:n}})(),{renderCache:t}=this;return t?.result==null?{options:e,forceHighlight:!0}:!R(i,t.file)||!A(e,t.options)?{options:e,forceHighlight:!0}:{options:e,forceHighlight:!1}}getOrCreateLineCache(i){this.invalidateChangedUnkeyedFile(i);let{lineCache:e}=this;return(e==null||!D(e,i))&&(e={cacheKey:i.cacheKey,file:i,sourceContents:i.contents,lines:$(i.contents)}),this.lineCache=e,e.lines}getLineCount(i){const e=this.getOrCreateLineCache(i);return this.textDocumentCache.get(i)?.lineCount??e.length}updateRenderCache(i,e,t=!1){if(this.pendingStructuralRows=void 0,this.renderCache==null)return;const{file:n,result:r}=this.renderCache;if(r==null)return;const s=t?new Map:void 0;this.pendingStructuralRows=s;const o=this.lineCache!=null&&D(this.lineCache,n)?this.lineCache:void 0;for(const[a,l]of i){if(s===void 0&&o!=null&&a<o.lines.length){const h=l.map(c=>c[2]).join("");o.lines[a]=Ve(o.lines[a]??"",h)}const d={type:"element",tagName:"div",properties:{"data-line":a+1,"data-line-type":"context","data-line-index":a},children:l.map(([h,c,u])=>h===0&&c===""?u===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:u}:{type:"element",tagName:"span",properties:{"data-char":h,style:`color:${c};`},children:[{type:"text",value:u}]})};s!==void 0?s.set(a,d):r.code[a]=d}r.baseThemeType=e,this.renderCache.isDirty=!0}applyDocumentChange(i){const e=this.pendingStructuralRows;if(this.pendingStructuralRows=void 0,this.renderCache==null)return;const{file:t,result:n}=this.renderCache;if(n==null)return;const r=this.lineCache!=null&&D(this.lineCache,t)?this.lineCache.lines:$(t.contents),s=$(i.getText());if(r.length!==s.length){const o=Math.min(r.length,s.length);let a=0;for(;a<o&&r[a]===s[a];)a++;let l=0;for(;l<o-a&&r[r.length-1-l]===s[s.length-1-l];)l++;const d=n.code;n.code=new Array(s.length);for(let h=0;h<a;h++)n.code[h]=d[h];for(let h=0;h<l;h++)n.code[s.length-1-h]=d[r.length-1-h];if(e!==void 0)for(const[h,c]of e)h<s.length&&(n.code[h]=c);for(let h=a;h<s.length-l;h++)n.code[h]??={type:"element",tagName:"div",properties:{"data-line":h+1,"data-line-type":"context","data-line-index":h},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:i.getLineText(h)}]}]};for(let h=0;h<n.code.length;h++){const c=n.code[h];c?.type==="element"&&(c.properties["data-line"]=h+1,c.properties["data-line-index"]=h)}this.renderCache.isDirty=!0}this.lineCache={cacheKey:t.cacheKey,file:t,sourceContents:t.contents,lines:s},this.textDocumentCache.set(t,i)}renderFile(i=this.renderCache?.file,e=ee){if(i==null)return;this.invalidateChangedUnkeyedFile(i),this.renderCache?.isDirty===!0&&!R(i,this.renderCache.file)&&(this.clearRenderCache(),this.lineCache=void 0,this.textDocumentCache=new WeakMap);let{options:t,forceHighlight:n}=this.getRenderOptions(i);this.renderCache?.isDirty===!0&&!A(t,this.renderCache.options)&&this.clearRenderCache();const r=this.getMatchingWorkerResultCache(i,t);r!=null&&!this.hasHighlightedRenderCache(i,t)&&(this.renderCache={file:i,highlighted:!0,renderRange:void 0,...r},n=!1),this.renderCache??={file:i,highlighted:!1,options:t,result:void 0,renderRange:void 0};const s=this.getOrCreateLineCache(i),o=i.contents.length>0,a=!o||Y(i)||K(s.length,this.getTokenizeMaxLength()),l=!R(i,this.renderCache.file),d=!me(this.renderCache.renderRange,e);if(!this.editSessionActive&&this.workerManager?.isWorkingPool()===!0)(a||this.renderCache.result==null||!this.renderCache.highlighted&&(l||d))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||l||d||n)&&(this.renderCache.result=this.workerManager.getPlainFileAST(i,e.startingLine,e.totalLines,s)),this.renderCache.renderRange=e),!a&&o&&(!this.renderCache.highlighted||n)&&this.workerManager.highlightFileAST(this,i);else{this.computedLang=i.lang??j(i.name);const h=this.highlighter!=null&&te(t.theme),c=this.highlighter!=null&&ie(this.computedLang),u=!a&&c;if(this.highlighter!=null&&h&&(n||a||!this.renderCache.highlighted&&u||this.renderCache.result==null)){const{result:f,options:m}=this.renderFileWithHighlighter(i,this.highlighter,a||!c);this.renderCache={file:i,options:m,highlighted:u,result:f,renderRange:void 0}}(!h||!a&&!c)&&this.asyncHighlight(i).then(({result:f,options:m})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.applyHighlightResult(i,f,m,!a)})}return this.renderCache.result!=null?this.processFileResult(this.renderCache.file,e,this.renderCache.result):void 0}async asyncRender(i,e=ee){const{result:t}=await this.asyncHighlight(i);return this.processFileResult(i,e,t)}async asyncHighlight(i){const e=K(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());this.computedLang=e?"text":i.lang??j(i.name);const t=this.highlighter!=null&&De(Be(this.getLocalHighlightTheme())),n=e||this.highlighter!=null&&ie(this.computedLang);return(this.highlighter==null||!t||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(i,this.highlighter,e)}renderFileWithHighlighter(i,e,t=!1){const{options:n}=this.getRenderOptions(i);return{result:Ue(i,e,n,{forcePlainText:t}),options:n}}processFileResult(i,e,{code:t,themeStyles:n,baseThemeType:r}){const s=this.getLineCount(i),{disableFileHeader:o=!1}=this.options,a=[],l=oe(),d=Math.min(e.startingLine+e.totalLines,s);let h=0;const c=Ce(e)?_e(this.lineAnnotations):void 0;c!=null&&(l.children.push(ne("context","annotation",1)),a.push(re({hunkIndex:-1,lineIndex:-1,annotations:c.map(u=>k(u))})),h++);for(let u=e.startingLine;u<d;u++){const f=u+1,m=t[u];if(m==null){const C="FileRenderer.processFileResult: Line doesnt exist";throw console.error(C,{name:i.name,lineIndex:u,lineNumber:f}),new Error(C)}l.children.push(We("context",f,`${u}`)),a.push(m),h++;const g=this.lineAnnotations[f];g!=null&&(l.children.push(ne("context","annotation",1)),a.push(re({hunkIndex:0,lineIndex:f,annotations:g.map(C=>k(C))})),h++)}return l.properties.style=`grid-row: span ${h}`,{gutterAST:l.children??[],contentAST:a,preAST:this.createPreElement(s),headerAST:o?void 0:this.renderHeader(i),totalLines:s,rowCount:h,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return Ge({fileOrDiff:i,mode:e,stickyHeader:t})}renderFullHTML(i){return b(this.renderFullAST(i))}renderFullAST(i,e=[]){return e.push(se({tagName:"code",children:this.renderCodeAST(i),properties:{"data-code":""}})),{...i.preAST,children:e}}renderCodeAST(i){const e=oe();return e.children=i.gutterAST,e.properties.style=`grid-row: span ${i.rowCount}`,[e,je(i.contentAST,i.rowCount)]}renderPartialHTML(i,e=!1){return e?b(se({tagName:"code",children:i,properties:{"data-code":""}})):b(i)}async initializeHighlighter(){return this.highlighter=await $e(Ke(this.computedLang,{theme:this.getLocalHighlightTheme(),preferredHighlighter:this.workerManager?.getPreferredHighlighter()??this.options.preferredHighlighter})),this.highlighter}onHighlightSuccess(i,e,t,n=!0){this.editSessionActive||this.applyHighlightResult(i,e,t,n)}applyHighlightResult(i,e,t,n=!0){if(this.renderCache==null)return;const r=!R(i,this.renderCache.file)||!this.renderCache.highlighted||!A(t,this.renderCache.options);this.renderCache={file:i,options:t,highlighted:n,result:e,renderRange:void 0},r&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(i,e){if(this.editSessionActive)return;const t=this.workerManager?.getFileResultCache(i);if(!(t==null||!A(e,t.options)))return t}hasHighlightedRenderCache(i,e){const{renderCache:t}=this;return t?.result!=null&&t.highlighted&&R(i,t.file)&&A(e,t.options)}onHighlightError(i){console.error(i)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(i){const{disableLineNumbers:e=!1,overflow:t="scroll"}=this.options;return qe({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function K(i,e){return i>e}function Lt(i,e){return i.lineNumber===e.lineNumber&&i.metadata===e.metadata}function fe(i){return{theme:i?.theme,disableLineNumbers:i?.disableLineNumbers,overflow:i?.overflow,themeType:i?.themeType,collapsed:i?.collapsed,disableFileHeader:i?.disableFileHeader,disableVirtualizationBuffers:i?.disableVirtualizationBuffers,stickyHeader:i?.stickyHeader,preferredHighlighter:i?.preferredHighlighter,useCSSClasses:i?.useCSSClasses,useTokenTransformer:Ye(i),tokenizeMaxLineLength:i?.tokenizeMaxLineLength,tokenizeMaxLength:i?.tokenizeMaxLength,unsafeCSS:i?.unsafeCSS,headerRenderMode:i?.renderCustomHeader!=null?"custom":"default"}}const Mt=[""];let At=-1;var ve=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++At}`;type="file";fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerFilenameSuffix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;renderRange;enabled=!0;editor;constructor(e={theme:H},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new Tt(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Xe,this.interactionManager=new Je("file",ae(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}__getCurrentFile(){return this.file}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(ae(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;const t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!Qe(this.appliedThemeCSS.theme,this.options.theme??H)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}setEditorActiveLine(e,t){this.interactionManager.setEditorActiveLine(e,{lineNumberOnly:t?.lineNumberOnly,side:t?.side??"additions"})}getCodeScrollLeft(){return this.code?.scrollLeft??0}setCodeScrollLeft(e){this.code!=null&&(this.code.scrollLeft=e)}__getEffectiveCodeOptions(){return{...this.options,...this.fileRenderer.getEffectiveCodeOptions()}}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{overflow:e="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,{disableAnnotations:e==="wrap",columnVariables:this.shouldApplyColumnVariables(e)?"apply":"measure"}),this.managersDirty=!1}shouldApplyColumnVariables(e){return e==="scroll"&&this.lineAnnotations.length>0}cleanUp(e=!1){this.emitPostRender(!0),this.editor?.cleanUp(e),this.editor=void 0,this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.clearAuxiliaryNodes(),this.pre=void 0,this.code=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper?.remove(),this.errorWrapper=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder?.remove(),this.placeHolder=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:s,lineAnnotations:o}=e;if(!this.enabled)throw new Error("File.hydrate: attempting to call hydrate after cleaned up");if(this.fileContainer!=null)throw new Error("File.hydrate: hydrate can only be called before the instance has rendered or hydrated");this.hydrateElements(t,n),Ht(this.pre,s,this.options.collapsed)||bt(this.headerElement,s,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:s,lineAnnotations:o}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),Ze(e,t);for(const n of Array.from(e.shadowRoot?.children??[])){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n,this.appliedPreAttributes=void 0;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}if("diffsHeader"in n.dataset){this.headerElement=n,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(fe(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.file){return e!=null?this.fileRenderer.getOrCreateLineCache(e):Mt}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,n=this.file,r=this.lineAnnotations,s=this.renderRange;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(o=>{!this.enabled||this.editor!==e||this.fileContainer!==t||this.file!==n||e.__syncRenderView(o,t,n,r,s)})}attachEditor(e){this.editor?.cleanUp(),this.editor=e,this.fileRenderer.beginEditSession();const t=this.file==null?void 0:e.__prepareFile?.(this.file);return t!==void 0&&t!==this.file?this.renderPreparedFile({file:t,forceRender:!0,preventEmit:!0,renderRange:this.renderRange}):this.fileRenderer.editorRenderReady()?this.syncRenderViewToEditor():this.rerender(),()=>{this.editor=void 0,this.fileRenderer.endEditSession()}}applyDocumentChange(e,t){this.fileRenderer.applyDocumentChange(e),t!=null&&t!==this.lineAnnotations&&this.file!=null&&(this.setLineAnnotations(t),this.fileRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}updateRenderCache(e,t,n){this.fileRenderer.updateRenderCache(e,t,n?.lineCountChangeInFlight)}render(e){if(!this.enabled)throw new Error("File.render: attempting to call render after cleaned up");const t=this.editor?.__prepareFile?.(e.file)??e.file;return this.renderPreparedFile(t===e.file?e:{...e,file:t})}renderPreparedFile({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:s,deferManagers:o=!1,lineAnnotations:a,renderRange:l}){this.editor?.__postponeBgTokenizeToNextFrame();const{collapsed:d=!1,themeType:h="system"}=this.options,c=d?void 0:l,u=this.renderRange,f=this.hasThemeChanged(),m=a!=null&&(a.length>0||this.lineAnnotations.length>0)?a!==this.lineAnnotations:!1,g=!R(this.file,e)||this.fileRenderer.hasUnkeyedFileContentsChanged(e);if(!d&&!n&&me(c,this.renderRange)&&!g&&!m&&!f)return this.applyCachedThemeState(h);this.renderRange=c,g&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(fe(this.options)),this.syncInteractionOptions(),a!=null&&this.setLineAnnotations(a),this.fileRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:C=!1,disableFileHeader:S=!1}=this.options;if(S&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,s),this.applyCachedThemeState(h),d){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const p=this.fileRenderer.renderFile(e,xe);p!=null&&this.applyThemeState(t,p.themeStyles,h,p.baseThemeType),p?.headerAST!=null&&this.applyHeaderToDOM(p.headerAST,t),this.injectUnsafeCSS()}catch(p){if(C)throw p;console.error(p),p instanceof Error&&this.applyErrorToDOM(p,t)}return r||this.emitPostRender(),!0}try{const p=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,m,g||f)||!this.applyPartialRender(u,c)){const v=this.fileRenderer.renderFile(e,c);if(v==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,v.themeStyles,h,v.baseThemeType),v.headerAST!=null&&this.applyHeaderToDOM(v.headerAST,t),this.applyFullRender(v,p)}this.applyBuffers(p,c),this.injectUnsafeCSS(),this.renderAnnotations(),this.renderGutterUtility(),this.managersDirty=!0,o||this.flushManagers(),this.editor!=null&&this.syncRenderViewToEditor()}catch(p){if(C)throw p;console.error(p),p instanceof Error&&this.applyErrorToDOM(p,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,"unmount");return}if(t==null)return;const r=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}async primeHighlightCache(e=this.file){const{workerManager:t}=this;if(e==null||t==null||!t.isWorkingPool()||e.cacheKey==null||Y(e))return;const n=this.options.tokenizeMaxLength??1e5;this.fileRenderer.getOrCreateLineCache(e).length>n||await t.primeFileHighlightCache(e).catch(r=>{console.error(r)})}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.clearAuxiliaryNodes(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[n,r]of this.lineAnnotations.entries()){const s=`${n}-${k(r)}`;let o=this.annotationCache.get(s);if(o==null||!Lt(r,o.annotation)){o?.element.remove();const a=t(r);if(a==null)continue;o={element:et(k(r)),annotation:r},o.element.appendChild(a),this.fileContainer.appendChild(o.element),this.annotationCache.set(s,o)}e.delete(s)}for(const[n,{element:r}]of e.entries())this.annotationCache.delete(n),r.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const n=tt();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){const{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=it(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=nt(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){const s=e.shadowRoot??e.attachShadow({mode:"open"}),o=r??n,a=this.options.theme??H,l=typeof a=="string"?a:{...a},d=he(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===o&&this.appliedThemeCSS.scrollbarGutter===d){this.appliedThemeCSS.theme=l;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:l,themeStyles:t,themeType:o,baseThemeType:r,scrollbarGutter:d};return}this.themeCSSStyle=rt({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:ct(t,o,d)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:l,themeStyles:t,themeType:o,baseThemeType:r,scrollbarGutter:d}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=st(this.themeCSSStyle.textContent??"",he(e)))}shouldGuardRebuildScroll(){return this.editor!=null&&Ee()}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e);const n=this.code=ot({code:this.code}),r=this.fileRenderer.renderCodeAST(e);this.editor?.__captureFocusForDOMReplacement();const s=()=>{if(n.childElementCount>=2)for(let o=0;o<2;o++){const a=n.children[o],l=r[o];a.innerHTML=b(l.children),a.style.cssText=l.properties.style}else n.innerHTML=b(r);t.contains(n)||t.replaceChildren(n)};this.shouldGuardRebuildScroll()?at(t,s):s(),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;const{file:n,code:r}=this,s=r!=null?this.getColumns(r):void 0;if(n==null||r==null||s==null)return!1;const o=e.startingLine,a=t.startingLine,l=e.totalLines===1/0?Number.POSITIVE_INFINITY:o+e.totalLines,d=t.totalLines===1/0?Number.POSITIVE_INFINITY:a+t.totalLines,h=Math.max(o,a),c=Math.min(l,d);if(c<=h)return!1;if(!this.trimDOMToOverlap(s.gutter,h,c)||!this.trimDOMToOverlap(s.content,h,c))throw new Error("File.applyPartialRender: failed to trim to overlap");let{length:u}=s.content.children;const f=(S,p)=>{if(!(p<=0))return this.fileRenderer.renderFile(n,{startingLine:S,totalLines:p,bufferBefore:0,bufferAfter:0})},m=a<h?f(a,h-a):void 0;if(m===void 0&&a<h)return!1;const g=d===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(0,d-c),C=d>c?f(c,g):void 0;return C===void 0&&d>c?!1:(this.cleanupErrorWrapper(),m!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(m.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(m.contentAST)),u+=m.rowCount),C!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(C.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(C.contentAST)),u+=C.rowCount),this.lastRowCount!==u&&(s.gutter.style.setProperty("grid-row",`span ${u}`),s.content.style.setProperty("grid-row",`span ${u}`),this.lastRowCount=u),!0)}getColumns(e){const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){const r=this.getDOMBoundaryIndices(e,[t,n]),s=r.get(t)??e.children.length,o=r.get(n)??e.children.length;if(s>o)return!1;for(let a=e.children.length-1;a>=o;a-=1)e.children[a]?.remove();for(let a=s-1;a>=0;a-=1)e.children[a]?.remove();return!0}getDOMBoundaryIndices(e,t){const n=[...new Set(t)].sort((l,d)=>l-d),r=new Map;if(n.length===0)return r;let s=0,o=n[s];const{children:a}=e;o===0&&(r.set(0,0),s+=1,o=n[s]);for(let l=0;l<a.length;l+=1){const d=a[l];if(!(d instanceof HTMLElement))continue;const h=this.getLineIndexFromDOMNode(d);if(h!=null){for(;o!=null&&h>=o;)r.set(o,l),s+=1,o=n[s];if(s>=n.length)break}}for(const l of n)r.has(l)||r.set(l,a.length);return r}getLineIndexFromDOMNode(e){const t=e.dataset.lineIndex;if(t==null)return;const n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t){const{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const r=this.cachedHeaderHTML??b(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){const d=document.createElement("div");d.innerHTML=r;const h=d.firstElementChild;if(!(h instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(h,this.headerElement):t.shadowRoot?.prepend(h),this.headerElement=h,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:o,renderCustomHeader:a,renderHeaderMetadata:l}=this.options;if(a!=null){const d=a(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,ge,d),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{const d=s?.(n)??void 0,h=o?.(n)??void 0,c=l?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,Fe,d),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,ke,h),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,ze,c),this.headerCustom?.remove(),this.headerCustom=void 0}}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,r){if(r==null){t?.remove();return}const s=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,r),s}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){const t=document.createElement("div");return t.slot=e,t}getOrCreateFileContainerNode(e,t){const{fileContainer:n}=this,r=e??n??document.createElement("diffs-container"),s=n!==r;return n!=null&&s&&this.editor?.__captureFocusForDOMReplacement(),s&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&s&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const n of t.children)n instanceof SVGElement?this.spriteSVG??=n:le(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):le(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=n,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const n=document.createElement("div");n.innerHTML=ht;const r=n.firstChild;r instanceof SVGElement&&(this.spriteSVG=r)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(this.editor?.__captureFocusForDOMReplacement(),e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(const t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute("data-code")){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){const{overflow:n="scroll",disableLineNumbers:r=!1}=this.options,s={type:"file",split:!1,overflow:n,disableLineNumbers:r,diffIndicators:"none",disableBackground:!0,totalLines:t};lt(s,this.appliedPreAttributes)||(dt(e,s),this.appliedPreAttributes=s)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);const r=document.createElement("div");r.dataset.errorMessage="",r.innerText=e.message,this.errorWrapper.appendChild(r);const s=document.createElement("pre");s.dataset.errorStack="",s.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(s)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Ht(i,e,t=!1){return!t&&i==null&&e!=null}function bt(i,e,t=!1){return i==null&&e!=null&&!t}const wt=5e3;let xt=-1;function Et(i,e){return(i.overflow??"scroll")!==(e.overflow??"scroll")||(i.collapsed??!1)!==(e.collapsed??!1)||(i.disableLineNumbers??!1)!==(e.disableLineNumbers??!1)||(i.disableFileHeader??!1)!==(e.disableFileHeader??!1)||i.unsafeCSS!==e.unsafeCSS}var Ft=class extends ve{virtualizer;metrics;__id=`virtualized-file:${++xt}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(i,e,t=Ie,n,r=!1){super(i,n,r),this.virtualizer=e,this.metrics=t}setMetrics(i,e=!1){const t=ut(i);!e&&ft(this.metrics,t)||(this.metrics=t,this.resetLayoutCache())}setLineAnnotations(i){this.syncLineAnnotations(i)&&this.resetLayoutCache()}syncLineAnnotations(i){return i==null||i===this.lineAnnotations||i.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(i),!0)}hasLineAnnotations(){return this.lineAnnotations.some(i=>i.lineNumber>0)}getLineHeight(i,e=!1){const t=this.cache.heights.get(i);if(t!=null)return t;const n=e?2:1;return this.metrics.lineHeight*n}setOptions(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(i==null)return;const{options:e}=this,t=!Se(e,i),n=Et(e,i);super.setOptions(i),n&&this.resetLayoutCache(!0),t&&(this.forceRenderOverride=!0),t&&this.virtualizer.instanceChanged(this,n)}setThemeType(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(i)}resetLayoutCache(i=!1,e=!0){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.renderRange!=null&&e&&(this.renderRange=void 0),i&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let i=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(i=!0),this.height=0,i;const{overflow:e="scroll"}=this.options;if(this.top=this.getVirtualizedTop(),e==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return i;const t=this.code.children[1];if(!(t instanceof HTMLElement))return i;const n=de(this.lineAnnotations);if(this.renderRange!=null&&n&&Ce(this.renderRange)){const r=kt(t)??0;r!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=r,i=!0)}else!n&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,i=!0);for(const r of t.children){if(!(r instanceof HTMLElement))continue;const s=r.dataset.lineIndex;if(s==null)continue;const o=Number(s);let a=r.getBoundingClientRect().height,l=!1;r.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in r.nextElementSibling.dataset||"noNewline"in r.nextElementSibling.dataset)&&("noNewline"in r.nextElementSibling.dataset&&(l=!0),a+=r.nextElementSibling.getBoundingClientRect().height);const d=this.getLineHeight(o,l);a!==d&&(i=!0,a===this.metrics.lineHeight*(l?2:1)?this.cache.heights.delete(o):this.cache.heights.set(o,a))}return(i||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),i}onRender=i=>this.fileContainer==null||this.file==null?!1:(i&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(i,e,t,n){const r=this.syncLineAnnotations(n),s=!R(this.file,i)||this.fileRenderer.hasUnkeyedFileContentsChanged(i);let o=t?.resetFileLayoutCache===!0||s||r;t?.metrics!=null&&(this.metrics=t.metrics,o=!0);const{collapsed:a=!1}=this.options;return this.currentCollapsed!==a&&(this.currentCollapsed=a,o=!0),o&&this.resetLayoutCache(),this.file!==i&&(this.layoutDirty=!0),this.file=i,this.top=e,this.computeApproximateSize(),this.height}getLinePosition(i){if(this.file==null||i<1)return;const{disableFileHeader:e=!1,collapsed:t=!1}=this.options,n=this.fileRenderer.getLineCount(this.file)-1;let r=V(this.metrics,e);if(t||n<0)return{top:r,height:0};const s=Math.min(Math.max(i-1,0),n),{overflow:o="scroll"}=this.options,{lineHeight:a}=this.metrics;if(r+=this.cache.fileAnnotationHeight,o==="scroll"&&!this.hasLineAnnotations())return{top:r+s*a,height:a};const l=this.getLayoutCheckpointBeforeLineIndex(s);r=l?.top??r;for(let d=l?.lineIndex??0;d<s;d++)r+=this.getLineHeight(d,!1);return{top:r,height:this.getLineHeight(s,!1)}}getEditorViewport(){return this.virtualizer.type==="simple"?this.virtualizer.getRoot():this.virtualizer.getContainerElement()}getNumericScrollAnchor(i){if(this.file==null||this.renderRange==null)return;const{disableFileHeader:e=!1,collapsed:t=!1,overflow:n="scroll"}=this.options;if(t||this.renderRange.totalLines<=0)return;const r=this.fileRenderer.getLineCount(this.file)-1;if(r<0)return;const s=V(this.metrics,e),o=Math.min(this.renderRange.startingLine,r),a=Math.min(o+this.renderRange.totalLines-1,r);if(a<o)return;const{fileAnnotationHeight:l}=this.cache;if(n==="scroll"&&!this.hasLineAnnotations()){const{lineHeight:h}=this.metrics,c=s+(o===0?l:this.renderRange.bufferBefore),u=o+Math.max(Math.ceil((i-c)/h),0);return u>a?void 0:{lineNumber:u+1,top:s+l+u*h}}let d=s+(o===0?l:this.renderRange.bufferBefore);for(let h=o;h<=a;h++){if(d>=i)return{lineNumber:h+1,top:d};d+=this.getLineHeight(h)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(i){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const e=i!=null?this.computeRenderRangeFromWindow(this.file,this.top,i):this.renderRange;if(e==null)return;const{bufferBefore:t,bufferAfter:n,totalLines:r}=e;let s=0;if(r===0){const o=i??this.virtualizer.getWindowSpecs();this.top<o.top&&(s=n)}return{topOffset:this.top+t+s,height:this.height-(t+n)}}cleanUp(i=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),i||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(i)}computeApproximateSize(i=!1,e=this.file){const t=this.isResizeDebuggingEnabled();if(!i&&!this.layoutDirty&&!t)return;const n=this.height===0;if(this.height=0,this.cache.checkpoints=[],e==null){this.layoutDirty=!1;return}const{disableFileHeader:r=!1,collapsed:s=!1,overflow:o="scroll"}=this.options,{lineHeight:a}=this.metrics,l=this.fileRenderer.getLineCount(e),d=V(this.metrics,r),h=ce(this.metrics);if(this.height+=d,s){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,o==="scroll"&&!this.hasLineAnnotations())this.height+=l*a;else for(let c=0;c<l;c++)this.addLayoutCheckpoint(c,this.height),this.height+=this.getLineHeight(c,!1);if(l>0&&(this.height+=h),this.fileContainer!=null&&t&&!n){const c=this.fileContainer.getBoundingClientRect();c.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:e.name,elementHeight:c.height,computedHeight:this.height}):console.log("VirtualizedFile.computeApproximateSize: computed height IS CORRECT")}this.layoutDirty=!1}setVisibility(i){this.isAdvancedMode()||this.fileContainer==null||(this.renderRange=void 0,i&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!i&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(i,e,t=!1){const{renderRange:n}=this;if(this.getAdvancedVirtualizer()?.capturePendingLayoutAnchor(),super.applyDocumentChange(i,e),this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(this.isSimpleMode(),!1),!this.isSimpleMode())this.computeApproximateSize(!0);else if(t&&n!==void 0&&this.file!==void 0){const r=this.virtualizer.getWindowSpecs(),s=this.computeRenderRangeFromWindow(this.file,this.top??0,r);s.bufferAfter!==n.bufferAfter&&this.updateBuffers(s)}this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!0)}renderPreparedFile({fileContainer:i,file:e,forceRender:t=!1,lineAnnotations:n,...r}){const s=this.file==null||!R(this.file,e)||this.fileRenderer.hasUnkeyedFileContentsChanged(e),{forceRenderOverride:o,isSetup:a}=this;this.forceRenderOverride=void 0;const l=this.syncLineAnnotations(n);if(l&&this.resetLayoutCache(),i=this.getOrCreateFileContainerNode(i),e==null)return console.error("VirtualizedFile.render: attempting to virtually render when we dont have file"),!1;if(a)this.top??=this.getVirtualizedTop(),s&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!1),this.computeApproximateSize(!1,e));else{this.computeApproximateSize(!1,e);const f=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(f==null)throw new Error("VirtualizedFile.render: simple virtualizer is not available");f.connect(i,this),this.isVisible=f.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode()&&(!s||!a))return this.file=e,s&&(this.cachedHeaderHTML=void 0),this.renderPlaceholder(this.height);const d=this.virtualizer.getWindowSpecs(),h=this.top??0,c=this.computeRenderRangeFromWindow(e,h,d),u=super.renderPreparedFile({file:e,fileContainer:i,renderRange:c,lineAnnotations:n,forceRender:(o??t)||l||s,...r});return this.isSimpleMode()&&u&&this.getSimpleVirtualizer()?.requestHeightReconcile(this),u}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}shouldGuardRebuildScroll(){return!1}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}addLayoutCheckpoint(i,e){i%wt===0&&this.cache.checkpoints.push({lineIndex:i,top:e})}getLayoutCheckpointBeforeLineIndex(i){if(i<=0||this.cache.checkpoints.length===0)return;let e=0,t=this.cache.checkpoints.length-1,n;for(;e<=t;){const r=e+t>>1,s=this.cache.checkpoints[r];if(s==null)throw new Error("VirtualizedFile: invalid checkpoint index");s.lineIndex<=i?(n=s,e=r+1):t=r-1}return n}getLayoutCheckpointBeforeTop(i,e){let t=0,n=this.cache.checkpoints.length-1,r=-1;for(;t<=n;){const s=t+n>>1,o=this.cache.checkpoints[s];if(o==null)throw new Error("VirtualizedFile: invalid checkpoint index");o.top<=i?(r=s,t=s+1):n=s-1}if(e==null)return r>=0?this.cache.checkpoints[r]:void 0;for(let s=r;s>=0;s--){const o=this.cache.checkpoints[s];if(o==null)throw new Error("VirtualizedFile: invalid checkpoint index");if(o.lineIndex%e===0)return o}}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}getAdvancedVirtualizer(){return this.virtualizer.type==="advanced"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(i,e,{top:t,bottom:n}){const{disableFileHeader:r=!1,overflow:s="scroll"}=this.options,{hunkLineCount:o,lineHeight:a}=this.metrics,l=this.fileRenderer.getLineCount(i),d=this.height,h=V(this.metrics,r),c=l>0?ce(this.metrics):0,{fileAnnotationHeight:u}=this.cache,f=h+u,m=Math.max(0,d-h-u-c),g=de(this.lineAnnotations),C=e+h,S=u>0&&g&&C<n&&C+u>t;if(e<t-d||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-h-c};if(l<=o)return{startingLine:0,totalLines:o,bufferBefore:0,bufferAfter:0};const p=Math.ceil(Math.max(n-t,0)/a),v=Math.ceil(p/o)*o+o,z=v/o,B=(t+n)/2;if(s==="scroll"&&!this.hasLineAnnotations()){const M=e+f,N=M+m;if(!S&&!(M<n&&N>t))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-h-c};const x=Math.floor(S&&B<e+f?0:(B-(e+f))/a),L=Math.floor(x/o)-Math.floor(z/2),He=Math.ceil(l/o),E=Math.max(0,Math.min(L,He))*o,Z=L<0?v+L*o:v,be=E===0?0:u+E*a,we=Math.min(Z,l-E);return{startingLine:E,totalLines:Z,bufferBefore:be,bufferAfter:Math.max(0,(l-E-we)*a)}}const ye=z,I=[],U=this.getLayoutCheckpointBeforeTop(Math.max(0,t-e-v*a*2),o);let T=e+(U?.top??f),_=U?.lineIndex??0,O,P,w;const Re=U?.lineIndex??0;for(let M=Re;M<l;M++){const N=_%o===0,x=Math.floor(_/o);if(N&&(I[x]=T-(e+f),w!=null)){if(w<=0)break;w--}const L=this.getLineHeight(M,!1);T>t-L&&T<n&&(O??=x),T+L>B&&(P??=x),w==null&&T>=n&&N&&(w=ye),_++,T+=L}if(O==null)if(S)O=0,P=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-h-c};P??=O;const W=Math.round(P-z/2),Te=Math.max(0,Math.ceil(l/o)-z),G=Math.max(0,Math.min(W,Te)),X=G*o,J=W<0?v+W*o:v,Le=I[G]??0,Me=X===0?0:u+Le,Q=G+J/o,Ae=Q<I.length?m-I[Q]:m-(T-e-f);return{startingLine:X,totalLines:J,bufferBefore:Me,bufferAfter:Math.max(0,Ae)}}};function kt(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===pt&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}const pe=typeof window>"u"?F.useEffect:F.useLayoutEffect;function zt({file:i,options:e,editorOptions:t,lineAnnotations:n,selectedLines:r,prerenderedHTML:s,metrics:o,hasGutterRenderUtility:a,hasCustomHeader:l,disableWorkerPool:d,edit:h}){const c=gt(),u=r!==void 0,f=F.useContext(mt),m=St(),g=F.useRef(null),C=vt(S=>{if(S!=null){if(g.current!=null)throw new Error("File: An instance should not already exist when a node is created");c!=null?g.current=new Ft(q({controlledSelection:u,hasCustomHeader:l,hasGutterRenderUtility:a,options:e}),c,o,d?void 0:f,!0):g.current=new ve(q({controlledSelection:u,hasCustomHeader:l,hasGutterRenderUtility:a,options:e}),d?void 0:f,!0),g.current.hydrate({file:i,fileContainer:S,lineAnnotations:n,prerenderedHTML:s})}else{if(g.current==null)throw new Error("File: A File instance should exist when unmounting");g.current.cleanUp(),g.current=null}});return pe(()=>{if(g.current==null)return;const S=q({controlledSelection:u,hasCustomHeader:l,hasGutterRenderUtility:a,options:e}),p=S!==void 0&&!Se(g.current.options,S);g.current.setOptions(S),g.current.render({file:i,lineAnnotations:n,forceRender:p}),r!==void 0&&g.current.setSelectedLines(r)}),pe(()=>{if(h&&g.current!=null){if(m===void 0)throw new Error("File: EditContext is not attached");const S=m(t??{});if(S==null)throw new Error("File: EditProvider.createEditor must return an editor instance");try{return S.edit(g.current)}catch(p){throw S.cleanUp(),p}}},[h]),{ref:C,getHoveredLine:F.useCallback(()=>g.current?.getHoveredLine(),[])}}function q({options:i,controlledSelection:e,hasCustomHeader:t,hasGutterRenderUtility:n}){return e||n||t?{...i,controlledSelection:e,renderCustomHeader:t?ue:i?.renderCustomHeader,renderGutterUtility:n?ue:i?.renderGutterUtility}:i}function Bt({file:i,lineAnnotations:e,selectedLines:t,options:n,editorOptions:r,metrics:s,className:o,style:a,renderAnnotation:l,renderCustomHeader:d,renderHeaderPrefix:h,renderHeaderFilenameSuffix:c,renderHeaderMetadata:u,prerenderedHTML:f,renderGutterUtility:m,disableWorkerPool:g=!1,edit:C=!1}){const{ref:S,getHoveredLine:p}=zt({file:i,options:n,editorOptions:r,metrics:s,lineAnnotations:e,selectedLines:t,prerenderedHTML:f,hasGutterRenderUtility:m!=null,hasCustomHeader:d!=null,disableWorkerPool:g,edit:C});return y.jsx(Oe,{ref:S,className:o,style:a,children:Ct(yt({file:i,renderAnnotation:l,renderCustomHeader:d,renderHeaderPrefix:h,renderHeaderFilenameSuffix:c,renderHeaderMetadata:u,renderGutterUtility:m,lineAnnotations:e,getHoveredLine:p}),f)})}export{Bt as F};
@@ -0,0 +1 @@
1
+ import{j as e,r as a,a as Ht}from"./react-rd22PHbN.js";import{a as dt}from"./tanstack-BysN2Oew.js";import{W as Q,D as Vt,v as Bt,w as Yt,x as Xt,aC as Me,aD as Le,aE as ut,aF as Wt,f as nt,aG as Ue,P as ye,aH as st,aI as $e,L as _e,ad as at,I as qt,U as ht,af as Ae,r as ft,K as mt,ax as Gt,X as Qt,Y as it,_ as Zt,aJ as Jt,aK as en,V as tn,aL as nn,aM as sn,aN as an,aO as on,aP as X,g as ln,a0 as rn,aQ as cn,aR as ot,aS as dn,a1 as un,aT as He,aU as hn,aV as fn,aW as mn,aX as xn,aY as pn,aZ as gn}from"./App-BbT5H97Z.js";import{c as re,a as Ve,B as R,I as be}from"./index-B3QJsvjR.js";import{m as jn,n as bn,M as yn,o as vn,p as Cn,q as kn,S as Nn}from"./base-ui-DIP2rZxz.js";import{a as lt,I as Be}from"./IconFolderSymlink-D29EhQPC.js";import{I as xt}from"./IconEdit-B8LZHB8l.js";const wn=[["path",{d:"M9 14l-4 -4l4 -4",key:"svg-0"}],["path",{d:"M5 10h11a4 4 0 1 1 0 8h-1",key:"svg-1"}]],pt=re("outline","arrow-back-up","ArrowBackUp",wn);const Dn=[["path",{d:"M15 14l4 -4l-4 -4",key:"svg-0"}],["path",{d:"M19 10h-11a4 4 0 1 0 0 8h1",key:"svg-1"}]],gt=re("outline","arrow-forward-up","ArrowForwardUp",Dn);const Sn=[["path",{d:"M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2",key:"svg-0"}],["path",{d:"M9 5a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2",key:"svg-1"}]],Re=re("outline","clipboard","Clipboard",Sn);const Mn=[["path",{d:"M3 4a1 1 0 0 1 1 -1h16a1 1 0 0 1 1 1v16a1 1 0 0 1 -1 1h-16a1 1 0 0 1 -1 -1v-16",key:"svg-0"}],["path",{d:"M12 3v18",key:"svg-1"}]],jt=re("outline","columns-2","Columns2",Mn);const Rn=[["path",{d:"M4 17a3 3 0 1 0 6 0a3 3 0 1 0 -6 0",key:"svg-0"}],["path",{d:"M14 17a3 3 0 1 0 6 0a3 3 0 1 0 -6 0",key:"svg-1"}],["path",{d:"M9.15 14.85l8.85 -10.85",key:"svg-2"}],["path",{d:"M6 4l8.85 10.85",key:"svg-3"}]],Oe=re("outline","cut","Cut",Rn);const En=[["path",{d:"M14 3v4a1 1 0 0 0 1 1h4",key:"svg-0"}],["path",{d:"M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2",key:"svg-1"}],["path",{d:"M12 11l0 6",key:"svg-2"}],["path",{d:"M9 14l6 0",key:"svg-3"}]],Ee=re("outline","file-plus","FilePlus",En),In=jn,Fn=bn;function Pn({className:t,children:i,...f}){return e.jsx(yn,{children:e.jsx(vn,{className:"isolate z-50 outline-none",children:e.jsx(Cn,{"data-slot":"context-menu-content",className:Ve("min-w-44 origin-(--transform-origin) rounded-lg border border-border bg-popover p-1 text-popover-foreground shadow-xl outline-none data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",t),...f,children:i})})})}function z({className:t,...i}){return e.jsx(kn,{"data-slot":"context-menu-item",className:Ve("flex h-8 cursor-default items-center gap-2 rounded-md px-2 text-xs outline-none select-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-45 [&_svg]:size-3.5 [&_svg]:shrink-0",t),...i})}function je({className:t,...i}){return e.jsx(Nn,{"data-slot":"context-menu-separator",className:Ve("mx-1 my-1 h-px bg-border",t),...i})}function bt({state:t,onClose:i,onRename:f,onCreate:g}){const[p,o]=a.useState("");if(a.useEffect(()=>{t&&o(t.mode==="rename"?t.entry.name:"")},[t]),!t)return null;const h=t.mode==="rename",d=t.mode==="new-folder"?"directory":"file",M=t.entry.type==="directory"?t.entry.path:Q(t.entry.path),D=h?"Rename":d==="directory"?"New Folder":"New File",k=p.trim(),T=k.length>0&&!/[\\/]/.test(k)&&!(h&&k===t.entry.name),P=()=>{T&&(h?f(t.entry,k):g(M,k,d),i())};return e.jsx(Vt,{open:!0,onOpenChange:y=>{y||i()},children:e.jsx(Bt,{className:"name-dialog",children:e.jsxs("form",{className:"name-dialog-content",onSubmit:y=>{y.preventDefault(),P()},children:[e.jsx(Yt,{children:D}),e.jsx(Xt,{children:h?e.jsxs(e.Fragment,{children:["Enter a new name for ",e.jsx("code",{children:t.entry.name}),"."]}):e.jsxs(e.Fragment,{children:["Create a new ",d==="directory"?"folder":"file"," in ",e.jsx("code",{children:M||"the repository root"}),"."]})}),e.jsx("input",{autoFocus:!0,className:"name-dialog-input",value:p,maxLength:255,placeholder:h?"New name":d==="directory"?"Folder name":"File name",onChange:y=>o(y.target.value),onFocus:y=>{if(!h)return;const w=t.entry.name.lastIndexOf(".");y.target.setSelectionRange(0,w>0?w:t.entry.name.length)}}),e.jsxs("div",{className:"name-dialog-actions",children:[e.jsx(R,{type:"button",variant:"ghost",onClick:i,children:"Cancel"}),e.jsx(R,{type:"submit",disabled:!T,children:h?"Rename":"Create"})]})]})})})}function yt(t,i,f,g=!0){const[p,o]=a.useState(null);a.useEffect(()=>{if(!g)return;let d=!1;return f(t).then(M=>{d||o({path:t,revision:i,entries:M,failed:!1})},()=>{d||o({path:t,revision:i,entries:[],failed:!0})}),()=>{d=!0}},[t,i,f,g]);const h=g&&p?.path===t;return{entries:h?p.entries:null,failed:h&&p.failed,refreshing:!h||p.revision!==i}}function zn({entries:t,initialDirectory:i,revision:f,readOnly:g,onLoadDirectory:p,onMove:o,onClose:h}){const[d,M]=a.useState(i),[D,k]=a.useState(!1),{entries:T,failed:P,refreshing:y}=yt(d,f,p),w=t.map(j=>j.path),L=T?.filter(j=>j.type==="directory"&&!w.some(te=>Me(te,j.path)))??[],O=!g&&!D&&!y&&T!==null&&!P&&Le(w,d),W=async()=>{if(O){k(!0);try{await o(t,d),h()}finally{k(!1)}}};return e.jsxs(ut,{open:!0,onOpenChange:j=>{!j&&!D&&h()},title:"Move to…",description:`${t.length} selected ${t.length===1?"item":"items"}. Choose a destination folder.`,children:[e.jsxs("div",{className:"mobile-folder-location",children:[d&&e.jsx(R,{variant:"ghost",size:"icon","aria-label":"Parent folder",disabled:D,onClick:()=>M(Q(d)),children:e.jsx(Wt,{})}),e.jsx("span",{children:d||"Repository root"})]}),e.jsx("div",{className:"mobile-destination-list",children:T===null?e.jsxs("p",{className:"mobile-list-message",role:"status",children:[e.jsx(nt,{className:"animate-spin"})," Loading folders…"]}):P?e.jsx("p",{className:"mobile-list-message",role:"alert",children:"Could not read this folder."}):L.length===0?e.jsx("p",{className:"mobile-list-message",children:"No subfolders. You can choose this folder below."}):L.map(j=>e.jsxs("button",{className:"mobile-sheet-action",disabled:D,onClick:()=>M(j.path),children:[e.jsx("img",{src:Ue(j.path,!1),alt:"","aria-hidden":"true",draggable:!1}),e.jsx("span",{children:j.name}),e.jsx(ye,{})]},j.path))}),e.jsxs("div",{className:"mobile-sheet-footer",children:[e.jsx(R,{variant:"ghost",disabled:D,onClick:h,children:"Cancel"}),e.jsxs(R,{disabled:!O,onClick:()=>{W()},children:[D&&e.jsx(nt,{className:"animate-spin"})," Move here"]})]})]})}const Tn=56;function Ln(t){const[i,f]=a.useState(()=>Q(t.activePath??"")),[g,p]=a.useState(""),[o,h]=a.useState(!1),[d,M]=a.useState(new Map),[D,k]=a.useState(null),[T,P]=a.useState(null),[y,w]=a.useState(null),L=a.useRef(null),O=a.useRef(new Map),W=a.useRef(t.activePath),{entries:j,failed:te}=yt(i,t.filesSnapshotRevision,t.onLoadDirectory,t.active),K=a.useMemo(()=>(j??[]).filter(u=>(t.showDotEnvFiles||!u.ignored)&&u.name.toLocaleLowerCase().includes(g.toLocaleLowerCase())),[j,t.showDotEnvFiles,g]),ne=dt({count:K.length,enabled:t.active&&j!==null,getScrollElement:()=>L.current,estimateSize:()=>Tn,getItemKey:u=>K[u].path,overscan:8,paddingEnd:12});a.useEffect(()=>{t.activePath!==W.current&&(W.current=t.activePath,t.activePath&&(f(Q(t.activePath)),p("")))},[t.activePath]),a.useEffect(()=>{if(!j)return;const u=new Set(j.map(x=>x.path));M(x=>{const b=new Map([...x].filter(([U])=>u.has(U)));return b.size===x.size?x:b})},[j]),a.useEffect(()=>{j&&L.current&&(L.current.scrollTop=O.current.get(i)??0)},[i,j]),a.useEffect(()=>{if(!t.files||!i||st(t.files,i)!=="missing")return;let u=Q(i);for(;u&&st(t.files,u)==="missing";)u=Q(u);f(u),p(""),M(new Map)},[t.files,i]);const q=u=>{f(u),p(""),M(new Map)},ce=u=>M(x=>{const b=new Map(x);return b.has(u.path)?b.delete(u.path):b.set(u.path,u),b}),se={type:"directory",path:i,name:i.split("/").pop()??"",children:[]},G=[...d.values()],v=D&&D!=="tools"?D:null,C=u=>{k(null),u()};return e.jsxs("div",{className:"mobile-files-view",children:[e.jsxs("div",{className:"mobile-view-heading",children:[e.jsxs("h2",{children:[o?"Select items":"Files",o&&e.jsx("small",{children:d.size})]}),e.jsxs("div",{children:[e.jsx(R,{variant:"ghost",size:"sm","aria-pressed":o,onClick:()=>{h(!o),M(new Map)},children:o?"Cancel":"Select"}),e.jsx(R,{variant:"ghost",size:"icon","aria-label":"File browser actions",onClick:()=>k("tools"),children:e.jsx($e,{})})]})]}),e.jsxs("label",{className:"mobile-file-filter",children:[e.jsx(_e,{"aria-hidden":"true"}),e.jsx("input",{type:"search",value:g,placeholder:"Filter this folder…","aria-label":"Filter this folder",onChange:u=>{p(u.target.value),O.current.set(i,0),L.current?.scrollTo({top:0})}})]}),e.jsxs("nav",{className:"mobile-file-breadcrumb","aria-label":"Folder location",children:[e.jsxs("button",{onClick:()=>q(""),"aria-current":i===""?"location":void 0,children:[e.jsx(at,{"aria-hidden":"true"})," Root"]}),i.split("/").filter(Boolean).map((u,x,b)=>{const U=b.slice(0,x+1).join("/");return e.jsxs("span",{children:[e.jsx(ye,{"aria-hidden":"true"}),e.jsx("button",{"aria-current":U===i?"location":void 0,onClick:()=>q(U),children:u})]},U)})]}),e.jsx("div",{className:"mobile-files-scroll",ref:L,onScroll:u=>O.current.set(i,u.currentTarget.scrollTop),children:j===null?e.jsx("p",{className:"mobile-list-message",role:"status",children:"Loading files…"}):te?e.jsx("p",{className:"mobile-list-message",role:"alert",children:"Could not read this folder."}):K.length===0?e.jsx("p",{className:"mobile-list-message",children:g?"No matching files in this folder.":"This folder is empty."}):e.jsx("div",{className:"virtual-list",role:"list","aria-label":"Files in this folder",style:{height:ne.getTotalSize()},children:ne.getVirtualItems().map(u=>{const x=K[u.index],b=d.has(x.path);return e.jsxs("div",{role:"listitem",className:`mobile-file-row ${b?"selected":""}`,style:{height:u.size,transform:`translateY(${u.start}px)`},children:[e.jsxs("button",{className:"mobile-file-open","aria-pressed":o?b:void 0,"aria-current":t.activePath===x.path?"true":void 0,onClick:()=>o?ce(x):x.type==="directory"?q(x.path):t.onOpenFile(x.path),children:[o?e.jsx("span",{className:`mobile-file-check ${b?"checked":""}`,children:b&&e.jsx(qt,{"aria-hidden":"true"})}):e.jsx("img",{src:x.type==="directory"?Ue(x.path,!1):ht(x.path),alt:"","aria-hidden":"true",draggable:!1}),e.jsxs("span",{className:"mobile-file-copy",children:[e.jsx("strong",{children:x.name}),e.jsx("small",{children:x.type==="directory"?x.ignored?"Ignored folder":"Folder":`${x.ignored?"Ignored · ":""}${Math.max(1,Math.ceil(x.size/1024))} KB`})]}),!o&&x.type==="directory"&&e.jsx(ye,{"aria-hidden":"true"})]}),!o&&e.jsx(R,{variant:"ghost",size:"icon",className:"mobile-file-menu","aria-label":`Actions for ${x.name}`,onClick:()=>k(x),children:e.jsx($e,{})})]},x.path)})})}),o&&e.jsxs("div",{className:"mobile-file-selection-actions",children:[e.jsxs(R,{variant:"ghost",size:"sm",disabled:t.readOnly||d.size===0,onClick:()=>w(G),children:[e.jsx(lt,{})," Move to…"]}),e.jsxs(R,{variant:"ghost",size:"sm",disabled:d.size===0,onClick:()=>{t.fileClipboardAvailable?t.onCopyEntries(G):t.onCopyPath(G)},children:[e.jsx(be,{})," ",t.fileClipboardAvailable?"Copy":"Copy paths"]}),t.fileClipboardAvailable&&e.jsx(R,{variant:"ghost",size:"icon","aria-label":"Cut selected items",disabled:t.readOnly||d.size===0,onClick:()=>{t.onCutEntries(G)},children:e.jsx(Oe,{})}),e.jsx(R,{variant:"ghost",size:"icon","aria-label":"Delete selected items",disabled:t.readOnly||d.size===0,onClick:()=>{t.onDeleteEntries(G)},children:e.jsx(Ae,{})})]}),e.jsx(ut,{open:D!==null,onOpenChange:u=>{u||k(null)},title:v?.name??"File browser actions",description:v?.path??"Actions for the current folder.",children:v?e.jsxs(e.Fragment,{children:[v.type==="file"&&e.jsxs("button",{className:"mobile-sheet-action",onClick:()=>C(()=>t.onOpenFile(v.path,"pinned")),children:[e.jsx(Ee,{}),e.jsx("span",{children:"Keep file open"})]}),v.type==="directory"&&e.jsxs("button",{className:"mobile-sheet-action",onClick:()=>C(()=>q(v.path)),children:[e.jsx(at,{}),e.jsx("span",{children:"Open folder"})]}),e.jsxs("button",{className:"mobile-sheet-action",disabled:t.readOnly,onClick:()=>C(()=>w([v])),children:[e.jsx(lt,{}),e.jsx("span",{children:"Move to…"})]}),e.jsxs("button",{className:"mobile-sheet-action",disabled:t.readOnly,onClick:()=>C(()=>P({mode:"rename",entry:v})),children:[e.jsx(xt,{}),e.jsx("span",{children:"Rename"})]}),t.fileClipboardAvailable&&e.jsxs("button",{className:"mobile-sheet-action",onClick:()=>C(()=>{t.onCopyEntries([v])}),children:[e.jsx(be,{}),e.jsx("span",{children:"Copy"})]}),t.fileClipboardAvailable&&e.jsxs("button",{className:"mobile-sheet-action",disabled:t.readOnly,onClick:()=>C(()=>{t.onCutEntries([v])}),children:[e.jsx(Oe,{}),e.jsx("span",{children:"Cut"})]}),e.jsxs("button",{className:"mobile-sheet-action",onClick:()=>C(()=>{t.onCopyPath([v])}),children:[e.jsx(be,{}),e.jsx("span",{children:"Copy path"})]}),v.type==="file"&&e.jsxs("button",{className:"mobile-sheet-action",onClick:()=>C(()=>{t.onCopyContents(v)}),children:[e.jsx(be,{}),e.jsx("span",{children:"Copy contents"})]}),t.revealAvailable&&e.jsxs("button",{className:"mobile-sheet-action",onClick:()=>C(()=>{t.onReveal(v)}),children:[e.jsx(ft,{}),e.jsx("span",{children:"Reveal in file manager"})]}),t.fileClipboardAvailable&&e.jsxs("button",{className:"mobile-sheet-action",disabled:t.readOnly,onClick:()=>C(()=>{t.onPaste(v.type==="directory"?v.path:Q(v.path))}),children:[e.jsx(Re,{}),e.jsx("span",{children:"Paste here"})]}),e.jsxs("button",{className:"mobile-sheet-action destructive",disabled:t.readOnly,onClick:()=>C(()=>{t.onDeleteEntries([v])}),children:[e.jsx(Ae,{}),e.jsx("span",{children:"Delete"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"mobile-sheet-action",onClick:()=>C(t.onQuickOpen),children:[e.jsx(_e,{}),e.jsx("span",{children:"Find file in repository"})]}),e.jsxs("button",{className:"mobile-sheet-action",disabled:t.readOnly,onClick:()=>C(()=>P({mode:"new-file",entry:se})),children:[e.jsx(Ee,{}),e.jsx("span",{children:"New file"})]}),e.jsxs("button",{className:"mobile-sheet-action",disabled:t.readOnly,onClick:()=>C(()=>P({mode:"new-folder",entry:se})),children:[e.jsx(Be,{}),e.jsx("span",{children:"New folder"})]}),t.fileClipboardAvailable&&e.jsxs("button",{className:"mobile-sheet-action",disabled:t.readOnly,onClick:()=>C(()=>{t.onPaste(i)}),children:[e.jsx(Re,{}),e.jsx("span",{children:"Paste here"})]}),e.jsxs("button",{className:"mobile-sheet-action",disabled:t.readOnly||!t.historyState.canUndo,onClick:()=>C(()=>{t.onUndo()}),children:[e.jsx(pt,{}),e.jsx("span",{children:t.historyState.undoLabel?`Undo ${t.historyState.undoLabel}`:"Undo"})]}),e.jsxs("button",{className:"mobile-sheet-action",disabled:t.readOnly||!t.historyState.canRedo,onClick:()=>C(()=>{t.onRedo()}),children:[e.jsx(gt,{}),e.jsx("span",{children:t.historyState.redoLabel?`Redo ${t.historyState.redoLabel}`:"Redo"})]})]})}),e.jsx(bt,{state:T,onClose:()=>P(null),onRename:t.onRename,onCreate:t.onCreate}),y&&e.jsx(zn,{entries:y,initialDirectory:i,revision:t.filesSnapshotRevision,readOnly:t.readOnly,onLoadDirectory:t.onLoadDirectory,onMove:t.onMoveEntries,onClose:()=>{w(null),M(new Map)}})]})}function es(t){return mt()?e.jsx(Ln,{...t}):e.jsx(Un,{...t})}const $n=29,Se=6,vt="files-tree-root-drop",_n=550,An={duration:160,easing:"cubic-bezier(0.2, 0, 0, 1)"},rt=6,On=t=>{const i=dn(t),f=i.length>0?i:un(t),g=f.find(p=>p.id!==vt);return g?[g]:f.slice(0,1)};function Ct(t,i,f=0){const g=[];for(const p of t)g.push({entry:p,depth:f}),p.type==="directory"&&i.has(p.path)&&g.push(...Ct(p.children,i,f+1));return g}function Kn(t,i,f){const g=t.findIndex(d=>d.entry.path===i),p=t.findIndex(d=>d.entry.path===f);if(g===-1||p===-1)return[f];const[o,h]=g<=p?[g,p]:[p,g];return t.slice(o,h+1).map(d=>d.entry.path)}function Ke(t){return t.type==="directory"?t.path:Q(t.path)}function Un({active:t,initialExpandedPaths:i,files:f,filesSnapshotRevision:g,showDotEnvFiles:p,activePath:o,readOnly:h,fileClipboardAvailable:d,revealAvailable:M,historyState:D,onQuickOpen:k,onUndo:T,onRedo:P,onOpenFile:y,onLoadDirectory:w,onPersistExpandedPaths:L,onCopyPath:O,onCopyEntries:W,onCutEntries:j,onCopyContents:te,onPaste:K,onMoveEntries:ne,onDeleteEntries:q,onReveal:ce,onRename:se,onCreate:G}){const v=Gt(),C=mt(),[u,x]=a.useState(!1),b=C?44:$n,U=a.useRef(null),ae=a.useRef(null),[S,H]=a.useState(new Set),[ve,ie]=a.useState(o),[oe,Z]=a.useState(o),[A,de]=a.useState(()=>new Set(i)),[Ce,ue]=a.useState([]),[$,J]=a.useState(null),[he,Ie]=a.useState(null),[Xe,kt]=a.useState(null),[Nt,wt]=a.useState(!1),[Dt,ee]=a.useState(null),[ke,St]=a.useState(0),[V,Ne]=a.useState(new Map),Mt=Qt(it(Jt,{activationConstraint:{distance:5}}),it(Zt)),We=a.useRef(V),fe=a.useRef(new Set),qe=a.useRef(0),B=a.useRef(null),me=a.useRef(null),Ge=a.useRef(i.join("\0")),we=a.useMemo(()=>new Set(V.keys()),[V]),Y=a.useMemo(()=>f===null?null:en(f,V),[f,V]),N=a.useMemo(()=>Y===null?null:p?Y:tn(Y),[Y,p]);a.useEffect(()=>{We.current=V},[V]),a.useEffect(()=>{kt(document.getElementById(nn))},[o]),a.useEffect(()=>{const n=window.matchMedia("(prefers-reduced-motion: reduce)"),s=()=>wt(n.matches);return s(),n.addEventListener("change",s),()=>n.removeEventListener("change",s)},[]),a.useEffect(()=>()=>{B.current&&clearTimeout(B.current)},[]),a.useEffect(()=>{const n=++qe.current,s=[...We.current.keys()];s.length!==0&&Promise.all(s.map(async l=>({path:l,children:await w(l)}))).then(l=>{if(n!==qe.current)return;const r=new Map(l.map(({path:m,children:c})=>[m,c]));Ne(m=>sn(m,r))})},[g,w]),a.useEffect(()=>{if(!Y){fe.current.clear(),Ne(n=>n.size===0?n:new Map);return}de(n=>{const s=new Set(an(Y,n,we).retained);return ct(n,s)?n:s})},[we,Y]),a.useEffect(()=>{if(!Y)return;const n=on(Y,A,we),s=n.join("\0");s!==Ge.current&&(Ge.current=s,L(n))},[A,we,Y,L]),a.useEffect(()=>{if(!t||!N)return;let n=Math.max(0,2-fe.current.size);for(const s of A){if(n===0)break;const l=X(N,s);!l||l.type!=="directory"||l.ignored!==!0||l.children.length>0||V.has(s)||fe.current.has(s)||(fe.current.add(s),n-=1,w(s).catch(()=>[]).then(r=>{Ne(m=>new Map(m).set(s,r))}).finally(()=>{fe.current.delete(s)}))}},[t,A,V,w,N]),a.useEffect(()=>{t||(ee(null),ue([]),J(null),Ie(null),B.current&&clearTimeout(B.current),B.current=null,me.current=null)},[t]),a.useEffect(()=>{N&&(H(n=>{if(n.size===0)return n;const s=new Set([...n].filter(l=>X(N,l)));return s.size===n.size?n:s}),ie(n=>n&&X(N,n)?n:null),Z(n=>n&&X(N,n)?n:o&&X(N,o)?o:null))},[o,N]);const E=a.useMemo(()=>N?Ct(N,A):[],[A,N]),le=dt({enabled:t,count:E.length,getScrollElement:()=>U.current,estimateSize:()=>b,getItemKey:n=>E[n]?.entry.path??n,overscan:12,paddingStart:Se,paddingEnd:12});a.useEffect(()=>{le.measure()},[le,b]),a.useEffect(()=>{!t||!o||!N||!X(N,o)||de(n=>{const s=new Set(n);let l=!1;const r=o.split("/");let m="";for(let c=0;c<r.length-1;c+=1)m=m?`${m}/${r[c]}`:r[c],s.has(m)||(s.add(m),l=!0);return l?s:n})},[t,o,N]),a.useEffect(()=>{if(!t)return;if(!o){ae.current=null;return}if(ae.current===o)return;const n=E.findIndex(s=>s.entry.path===o);n>=0&&(le.scrollToIndex(n,{align:"auto"}),ae.current=o)},[t,o,E]);const Qe=a.useMemo(()=>{const n=new Map;for(const s of E)n.set(s.entry.path,s);return n},[E]),xe=a.useMemo(()=>{const n={headers:[],push:0};if(E.length===0||!o)return n;const s=new Set,l=o.split("/");let r="";for(let F=0;F<l.length-1;F+=1)r=r?`${r}/${l[F]}`:l[F],s.add(r);if(s.size===0)return n;const m=Math.min(E.length-1,Math.max(0,Math.floor((ke-Se)/b))),c=E[m];if(!c)return n;const I=c.entry.path.split("/"),_=[];let ge="";for(let F=0;F<I.length-1;F+=1){if(ge=ge?`${ge}/${I[F]}`:I[F],!s.has(ge))continue;const Te=Qe.get(ge);Te&&Te.entry.type==="directory"&&_.push(Te)}if(_.length>rt&&_.splice(0,_.length-rt),_.length===0)return n;const Ot=_[_.length-1],et=_.length*b;let tt=1/0;const Kt=Math.ceil((ke+et-Se)/b)+2;for(let F=m;F<E.length&&F<=Kt;F+=1)if(E[F].depth<=Ot.depth){tt=Se+F*b;break}const Ut=Math.max(0,Math.min(b,et-(tt-ke)));return{headers:_,push:Ut}},[E,Qe,ke,o,b]);if(N===null)return e.jsx("div",{className:"view-loading",role:"status",hidden:!t,children:e.jsx(ln,{text:"Loading files…"})});const Rt=u||S.size>0?S:o?new Set([o]):new Set,Et=S.size>0?[...S]:o?[o]:[],Fe=n=>{const s=[];for(const l of n){const r=X(N,l);r&&s.push(r)}return s},Pe=n=>{H(new Set([n])),ie(n),Z(n)},It=n=>{const s=E.findIndex(l=>l.entry.path===n.path);s>=0&&le.scrollToIndex(s,{align:"start"})},Ft=(n,s)=>{if(C&&u){H(l=>{const r=new Set(l);return r.has(n.path)?r.delete(n.path):r.add(n.path),r});return}if(s.shift&&(ve||oe)){const l=Kn(E,ve??oe,n.path);H(new Set(l)),Z(n.path);return}if(s.ctrl){H(l=>{const r=new Set(l.size===0&&o?[o]:l);return r.has(n.path)?r.delete(n.path):r.add(n.path),r}),ie(n.path),Z(n.path),n.type==="file"&&y(n.path,"pinned");return}Pe(n.path),n.type==="file"?y(n.path):Ze(n.path)},Pt=n=>{!(C&&u)&&n.type==="file"&&y(n.path,"pinned")},zt=n=>{S.has(n.path)||Pe(n.path)},De=n=>S.has(n.path)&&S.size>0?Fe(S):[n],Tt=n=>{if(hn(n.target))return;const s=fn(n.nativeEvent,v);if(s==="undo"&&D.canUndo&&!h){n.preventDefault(),n.repeat||T();return}if(s==="redo"&&D.canRedo&&!h){n.preventDefault(),n.repeat||P();return}const l=(n.ctrlKey||n.metaKey)&&!n.altKey,r=n.key.toLowerCase();if(l&&r==="a"){n.preventDefault(),H(new Set(E.map(I=>I.entry.path)));return}const m=Fe(Et),c=oe?X(N,oe):null;if(l&&r==="c"&&m.length){n.preventDefault(),W(m);return}if(l&&r==="x"&&m.length&&!h){n.preventDefault(),j(m);return}if(l&&r==="v"&&!h&&d){n.preventDefault();const I=c?Ke(c):Q(m[0]?.path??"");K(I);return}if(n.key==="F2"&&!n.ctrlKey&&!n.metaKey&&!n.altKey&&!n.shiftKey&&!h){if(S.size===1){const I=X(N,[...S][0]);I&&(n.preventDefault(),ee({mode:"rename",entry:I}))}return}n.key==="Delete"&&!n.ctrlKey&&!n.metaKey&&!n.altKey&&!n.shiftKey&&!h&&m.length&&(n.preventDefault(),q(m))},Lt=async(n,s)=>{const l=Fe(n);l.length&&await ne(l,s)},Ze=(n,s=!1)=>{const l=!s&&A.has(n),r=l&&X(N??[],n)?.ignored===!0;de(m=>{const c=new Set(m);if(s||!c.has(n)){if(c.has(n))return m;c.add(n)}else if(r)for(const I of c)Me(n,I)&&c.delete(I);else c.delete(n);return ct(m,c)?m:c}),l&&Ne(m=>{const c=[...m.keys()].filter(_=>Me(n,_));if(c.length===0)return m;const I=new Map(m);for(const _ of c)I.delete(_);return I})},pe=()=>{B.current&&clearTimeout(B.current),B.current=null,me.current=null},Je=()=>{pe(),ue([]),J(null),Ie(null)},ze=n=>{const s=n.active.data.current;return s?.entry&&Array.isArray(s.sourcePaths)?{entry:s.entry,sourcePaths:s.sourcePaths}:null},$t=n=>{const s=ze(n);s&&(S.has(s.entry.path)||Pe(s.entry.path),ue(s.sourcePaths),Ie({entry:s.entry,sourcePaths:s.sourcePaths,count:s.sourcePaths.length}))},_t=n=>{const s=ze(n);if(n.over?.data.current?.openPinned===!0){J(null),pe();return}const l=n.over?.data.current?.targetDirectory;if(!s||typeof l!="string"||!Le(s.sourcePaths,l)){J(null),pe();return}J(l);const r=n.over?.data.current?.expandPath;if(typeof r!="string"||A.has(r)){pe();return}me.current!==r&&(pe(),me.current=r,B.current=setTimeout(()=>{Ze(r,!0),B.current=null,me.current=null},_n))},At=n=>{const s=ze(n),l=n.over?.data.current?.openPinned===!0,r=n.over?.data.current?.targetDirectory;if(Je(),s&&l&&ot(s.entry,s.sourcePaths)){y(s.entry.path,"pinned");return}s&&typeof r=="string"&&Le(s.sourcePaths,r)&&Lt(s.sourcePaths,r)};return e.jsxs(rn,{sensors:Mt,collisionDetection:On,autoScroll:{enabled:!0,threshold:{x:.1,y:.16},acceleration:12},onDragStart:$t,onDragOver:_t,onDragCancel:Je,onDragEnd:At,children:[e.jsxs("div",{className:"files-mobile-tools",children:[e.jsxs(R,{variant:"ghost",size:"sm",onClick:k,children:[e.jsx(_e,{})," Find file"]}),e.jsx(R,{variant:"ghost",size:"sm","aria-pressed":u,onClick:()=>{x(!u),H(new Set)},children:u?`Done (${S.size})`:"Select"}),e.jsxs(R,{variant:"ghost",size:"sm",disabled:h,onClick:()=>ee({mode:"new-file",entry:{type:"directory",path:"",name:"",children:[]}}),children:[e.jsx(Ee,{})," New file"]}),e.jsxs(R,{variant:"ghost",size:"sm",disabled:h,onClick:()=>ee({mode:"new-folder",entry:{type:"directory",path:"",name:"",children:[]}}),children:[e.jsx(Be,{})," Folder"]}),d&&e.jsxs(R,{variant:"ghost",size:"sm",disabled:h,onClick:()=>{K("")},children:[e.jsx(Re,{})," Paste"]})]}),e.jsxs("div",{ref:U,className:"files-view virtual-scroll",hidden:!t,onScroll:n=>St(n.currentTarget.scrollTop),children:[xe.headers.length>0&&e.jsx("div",{className:"files-sticky",children:xe.headers.map((n,s)=>{const l=s===xe.headers.length-1;return e.jsxs("button",{type:"button",className:"file-tree-row files-sticky-row","aria-label":`Scroll to ${n.entry.path}`,style:{top:s*b-(l?xe.push:0),paddingLeft:12+n.depth*14,zIndex:xe.headers.length-s},onClick:()=>It(n.entry),children:[e.jsx(ye,{className:"folder-chevron open"}),e.jsx(Ye,{path:n.entry.path,type:"directory",expanded:!0}),e.jsx("span",{children:n.entry.name})]},n.entry.path)})}),N.length?e.jsx(Hn,{role:"tree","aria-label":"Files",className:`files-tree ${$===""&&Ce.length>0?"root-drop-target":""}`,style:{height:le.getTotalSize()},tabIndex:0,onKeyDown:Tt,onPointerDown:n=>{n.target.closest(".file-tree-row, .file-touch-actions")||(H(new Set),ie(null),Z(null),n.currentTarget.focus())},children:le.getVirtualItems().map(n=>{const{entry:s,depth:l}=E[n.index],r=s.type==="directory"&&A.has(s.path),m=S.has(s.path)&&S.size>1;return e.jsx("div",{className:"virtual-row",style:{height:n.size,transform:`translateY(${n.start}px)`},children:e.jsx(Yn,{entry:s,depth:l,expanded:r,pendingChildren:s.type==="directory"&&s.ignored===!0&&s.children.length===0&&!V.has(s.path),selected:Rt.has(s.path),active:o===s.path,multiSelected:m,readOnly:h,fileClipboardAvailable:d,revealAvailable:M,historyState:D,onUndo:T,onRedo:P,draggedPaths:Ce,dropTargetPath:$,onFocus:Z,onRowClick:Ft,onRowDoubleClick:Pt,onRowContextMenu:zt,onOpen:c=>y(c.path),onOpenPinned:c=>y(c.path,"pinned"),onCopy:c=>{W(De(c))},onCut:c=>{j(De(c))},onPasteInto:c=>{K(Ke(c))},onCopyPath:c=>{O(De(c))},onCopyContents:te,onRename:c=>ee({mode:"rename",entry:c}),onNewFile:c=>ee({mode:"new-file",entry:c}),onNewFolder:c=>ee({mode:"new-folder",entry:c}),onReveal:ce,onDelete:c=>{q(De(c))},dragPaths:S.has(s.path)&&S.size>0?[...S]:[s.path]})},n.key)})}):e.jsx("p",{className:"empty-list",children:"No files."}),e.jsx(bt,{state:Dt,onClose:()=>ee(null),onRename:se,onCreate:G})]}),e.jsx(cn,{dropAnimation:Nt?null:An,children:he&&e.jsx(Bn,{preview:he})}),Xe&&Ht.createPortal(e.jsx(Vn,{visible:!!(he&&ot(he.entry,he.sourcePaths))}),Xe)]})}function Hn(t){const{setNodeRef:i}=He({id:vt,data:{targetDirectory:"",expandPath:null}});return e.jsx("div",{ref:i,...t})}function Vn({visible:t}){const{isOver:i,setNodeRef:f}=He({id:"files-open-pinned-drop",data:{openPinned:!0}});return e.jsxs("div",{ref:f,className:`open-files-drop-target ${t?"visible":""} ${t&&i?"over":""}`,"aria-hidden":"true",children:[e.jsx(jt,{}),e.jsx("span",{children:"Drop to open beside"})]})}function Bn({preview:t}){return e.jsxs("div",{className:"file-drag-overlay",children:[e.jsx(Ye,{path:t.entry.path,type:t.entry.type,expanded:!1}),e.jsx("span",{children:t.entry.name}),t.count>1&&e.jsx("strong",{children:t.count})]})}function ct(t,i){if(t.size!==i.size)return!1;for(const f of t)if(!i.has(f))return!1;return!0}function Yn({entry:t,depth:i,expanded:f,pendingChildren:g,selected:p,active:o,multiSelected:h,readOnly:d,fileClipboardAvailable:M,revealAvailable:D,historyState:k,onUndo:T,onRedo:P,draggedPaths:y,dropTargetPath:w,onFocus:L,onRowClick:O,onRowDoubleClick:W,onRowContextMenu:j,onOpen:te,onOpenPinned:K,onCopy:ne,onCut:q,onPasteInto:ce,onCopyPath:se,onCopyContents:G,onRename:v,onNewFile:C,onNewFolder:u,onReveal:x,onDelete:b,dragPaths:U}){const ae=a.useRef(null),S=Ke(t),{attributes:H,listeners:ve,setNodeRef:ie,isDragging:oe}=mn({id:`file-drag:${t.path}`,data:{sourcePaths:U,entry:t},disabled:d}),{setNodeRef:Z}=He({id:`file-drop:${t.path}`,data:{targetDirectory:S,expandPath:t.type==="directory"?t.path:null}}),A=$=>{ae.current=$,ie($),Z($)},de=y.length>0&&t.type==="directory"&&w===t.path,Ce=y.length>0&&w!==null&&w!==""&&w!==t.path&&Me(w,t.path),ue=e.jsxs("button",{type:"button",ref:A,...H,role:"treeitem","aria-selected":p,"aria-current":o?"true":void 0,"aria-expanded":t.type==="directory"?f:void 0,className:["file-tree-row",t.ignored?"ignored-file":"",y.includes(t.path)||oe?"dragging":"",de?"drop-target":"",Ce?"drop-target-region":""].filter(Boolean).join(" "),style:{paddingLeft:12+i*14},...ve,onClick:$=>O(t,{ctrl:$.ctrlKey||$.metaKey,shift:$.shiftKey}),onDoubleClick:()=>W(t),onFocus:()=>L(t.path),onContextMenu:()=>j(t),children:[t.type==="directory"?e.jsx(ye,{className:`folder-chevron ${f?"open":""} ${t.children.length===0&&!g?"empty":""}`}):e.jsx("span",{className:"tree-spacer"}),e.jsx(Ye,{path:t.path,type:t.type,expanded:f}),e.jsx("span",{children:t.name})]});return e.jsxs(In,{children:[e.jsx(Fn,{render:ue}),e.jsx("button",{type:"button",className:"file-touch-actions","aria-label":`Actions for ${t.name}`,"aria-haspopup":"menu",onClick:$=>{$.stopPropagation();const J=$.currentTarget.getBoundingClientRect();ae.current?.dispatchEvent(new MouseEvent("contextmenu",{bubbles:!0,cancelable:!0,clientX:J.left,clientY:J.bottom}))},children:e.jsx($e,{})}),e.jsxs(Pn,{children:[t.type==="file"&&e.jsxs(e.Fragment,{children:[e.jsxs(z,{onClick:()=>te(t),children:[e.jsx(xn,{"aria-hidden":"true"})," Open"]}),e.jsxs(z,{onClick:()=>K(t),children:[e.jsx(jt,{"aria-hidden":"true"})," Open to the Side ",e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground",children:"Ctrl+Click"})]}),e.jsx(je,{})]}),e.jsxs(z,{disabled:d||!k.canUndo,onClick:()=>{T()},children:[e.jsx(pt,{"aria-hidden":"true"})," ",k.undoLabel?`Undo ${k.undoLabel}`:"Undo"," ",e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground",children:"Ctrl+Z"})]}),e.jsxs(z,{disabled:d||!k.canRedo,onClick:()=>{P()},children:[e.jsx(gt,{"aria-hidden":"true"})," ",k.redoLabel?`Redo ${k.redoLabel}`:"Redo"," ",e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground",children:"Ctrl+Shift+Z"})]}),e.jsx(je,{}),e.jsxs(z,{onClick:()=>ne(t),children:[e.jsx(pn,{"aria-hidden":"true"})," Copy ",e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground",children:"Ctrl+C"})]}),e.jsxs(z,{disabled:d,onClick:()=>q(t),children:[e.jsx(Oe,{"aria-hidden":"true"})," Cut ",e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground",children:"Ctrl+X"})]}),M&&e.jsxs(z,{disabled:d,onClick:()=>ce(t),children:[e.jsx(Re,{"aria-hidden":"true"})," Paste ",e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground",children:"Ctrl+V"})]}),e.jsx(je,{}),e.jsxs(z,{disabled:d||h,onClick:()=>v(t),children:[e.jsx(xt,{"aria-hidden":"true"})," Rename ",e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground",children:"F2"})]}),e.jsxs(z,{disabled:d||h,onClick:()=>C(t),children:[e.jsx(Ee,{"aria-hidden":"true"})," New File…"]}),e.jsxs(z,{disabled:d||h,onClick:()=>u(t),children:[e.jsx(Be,{"aria-hidden":"true"})," New Folder…"]}),e.jsx(je,{}),e.jsxs(z,{onClick:()=>se(t),children:[e.jsx(gn,{"aria-hidden":"true"})," Copy path"]}),e.jsxs(z,{disabled:t.type!=="file"||h,onClick:()=>{G(t)},children:[e.jsx(be,{"aria-hidden":"true"})," Copy contents"]}),D&&e.jsxs(z,{disabled:h,onClick:()=>{x(t)},children:[e.jsx(ft,{"aria-hidden":"true"})," Reveal in File Explorer"]}),e.jsx(je,{}),e.jsxs(z,{className:"text-destructive data-highlighted:text-destructive",disabled:d,onClick:()=>b(t),children:[e.jsx(Ae,{"aria-hidden":"true"})," Delete ",e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground",children:"Del"})]})]})]})}function Ye({path:t,type:i,expanded:f=!1}){const g=i==="file"?ht(t):Ue(t,f);return e.jsx("img",{className:"vscode-tree-icon",src:g,alt:"","aria-hidden":"true"})}export{es as FilesView};
@@ -0,0 +1 @@
1
+ import{c as o,T as x,b as g,d as j,B as m,o as C,q as N}from"./index-B3QJsvjR.js";import{r as v,j as e}from"./react-rd22PHbN.js";import{u as b}from"./tanstack-BysN2Oew.js";import{o as M,p as P,I as R}from"./App-BbT5H97Z.js";import{P as y,b as S,c as E,d as I,e as q}from"./base-ui-DIP2rZxz.js";const T=[["path",{d:"M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0",key:"svg-0"}],["path",{d:"M9 12l2 2l4 -4",key:"svg-1"}]],K=o("outline","circle-check","CircleCheck",T);const _=[["path",{d:"M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0",key:"svg-0"}],["path",{d:"M10 10l4 4m0 -4l-4 4",key:"svg-1"}]],U=o("outline","circle-x","CircleX",_);const $=[["path",{d:"M12 4l-8 4l8 4l8 -4l-8 -4",key:"svg-0"}],["path",{d:"M4 12l8 4l8 -4",key:"svg-1"}],["path",{d:"M4 16l8 4l8 -4",key:"svg-2"}]],F=o("outline","stack-2","Stack2",$);const G=[["path",{d:"M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0",key:"svg-0"}],["path",{d:"M9 10a3 3 0 1 0 6 0a3 3 0 1 0 -6 0",key:"svg-1"}],["path",{d:"M6.168 18.849a4 4 0 0 1 3.832 -2.849h4a4 4 0 0 1 3.834 2.855",key:"svg-2"}]],O=o("outline","user-circle","UserCircle",G);function X({repositoryId:n,number:r,membership:c,onSelect:l}){const[d,k]=v.useState(!1),a=b({queryKey:N.pullRequestStack(n,r),queryFn:()=>C.github.getPullRequestStack(n,r),enabled:d,staleTime:0}),t=a.data,h=t?t.layers.findIndex(s=>s.number===r)+1:c.position,u=t?.layers.length??c.size,i=t?.number??c.number;return a.isSuccess&&t===null&&!d?null:e.jsxs(y,{open:d,onOpenChange:k,children:[e.jsxs(x,{children:[e.jsxs(g,{render:e.jsx(S,{render:e.jsx("button",{className:"pr-stack-trigger","aria-label":`Stack ${i}, layer ${h} of ${u}`})}),children:[e.jsx(F,{"aria-hidden":"true"})," ",h,"/",u]}),e.jsxs(j,{children:["View stack #",i," · layer ",h," of ",u]})]}),e.jsx(E,{children:e.jsx(I,{side:"bottom",align:"start",sideOffset:6,className:"isolate z-50 outline-none",children:e.jsxs(q,{className:"pr-stack-popup","aria-label":`Stack #${i}`,children:[e.jsxs("div",{className:"pr-stack-heading",children:[e.jsxs("strong",{children:["Stack #",i]}),e.jsx(m,{variant:"ghost",size:"xs",disabled:a.isFetching,onClick:()=>{a.refetch()},children:"Refresh"})]}),a.isFetching&&e.jsx("p",{className:"pr-stack-notice",role:"status",children:t?"Refreshing stack…":"Loading stack…"}),a.isError&&e.jsxs("div",{className:"pr-stack-notice",role:"status",children:[e.jsx("p",{children:t?"Could not refresh. Showing saved layers.":"Could not load the stack."}),e.jsx(m,{variant:"outline",size:"xs",onClick:()=>{a.refetch()},children:"Retry"})]}),t===null&&!a.isFetching&&!a.isError&&e.jsx("p",{className:"pr-stack-notice",children:"This PR is no longer in a stack, or stack data is unavailable."}),t&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"pr-stack-layers",children:[...t.layers].reverse().map(s=>{const p=s.isDraft&&s.state==="OPEN"?"Draft":s.state==="MERGED"?"Merged":s.state==="CLOSED"?"Closed":"Open",f=s.state==="MERGED"?M:P;return e.jsxs(x,{children:[e.jsxs(g,{render:e.jsx("button",{className:"pr-stack-layer","aria-current":s.number===r?"true":void 0,onClick:()=>{k(!1),l(s.number)}}),children:[e.jsx(f,{className:`pr-stack-state ${p.toLowerCase()}`,"aria-hidden":"true"}),e.jsxs("span",{className:"pr-stack-layer-text",children:[e.jsx("strong",{children:s.title}),e.jsxs("small",{children:["#",s.number," · ",s.headRefName," · ",p]})]}),s.number===r&&e.jsx(R,{"aria-hidden":"true"})]}),e.jsxs(j,{children:[s.title," · ",s.headRefName," · ",p]})]},s.number)})}),e.jsxs("div",{className:"pr-stack-base",children:["↳ ",t.base]})]})]})})})]})}function A({src:n,className:r}){const[c,l]=v.useState(!1);return e.jsx("span",{className:r,"aria-hidden":"true",children:n&&!c?e.jsx("img",{src:n,alt:"",onError:()=>l(!0)}):e.jsx(O,{})})}export{A as G,K as I,X as P,U as a};
@@ -0,0 +1 @@
1
+ import{r as w,j as e}from"./react-rd22PHbN.js";import{K as ne,f as J,g as Z,L as ae,M as re,N as oe,O as ie,P as le,p as ce,q as de,l as he,Q as ue,R as me,U as pe}from"./App-BbT5H97Z.js";import{a as xe}from"./tanstack-BysN2Oew.js";import{T as N,b as C,d as v,B,o as je,w as fe,s as X}from"./index-B3QJsvjR.js";import"./base-ui-DIP2rZxz.js";function ge(s){let n=[],a=s.some(r=>r.color!==void 0)?3:0,t=1;const o=new Map,j=[],i=new Map(s.map(r=>[r.oid,r])),u=new Set;let d=s[0];for(;d&&!u.has(d.oid);)u.add(d.oid),d.color!==void 0&&o.set(d.oid,d.color),d=i.get(d.parentOids[0]??"");for(const r of s){let h=n.indexOf(r.oid);const p=h>=0;h<0&&(h=n.length,n=[...n,r.oid]);const f=n,$=be(o,r.oid,()=>r.color??a++),x=$<3?r.color??$:$;o.set(r.oid,x);const y=f.filter((g,l)=>l!==h);let H=Math.min(h,y.length);r.parentOids.forEach((g,l)=>{o.has(g)||o.set(g,l===0?x:a++),!y.includes(g)&&(y.splice(H,0,g),H+=1)});const E=[];f.forEach((g,l)=>{if(l===h){p&&E.push({fromLane:l,from:"top",toLane:h,to:"node",color:$});return}const I=y.indexOf(g);I>=0&&E.push({fromLane:l,from:"top",toLane:I,to:"bottom",color:o.get(g)??0})}),r.parentOids.forEach(g=>{const l=y.indexOf(g);l>=0&&E.push({fromLane:h,from:"node",toLane:l,to:"bottom",color:o.get(g)??x})}),t=Math.max(t,f.length,y.length),j.push({lane:h,color:x,segments:E,continuations:y.map((g,l)=>({lane:l,color:o.get(g)??0}))}),n=y}return{rows:j,laneCount:t}}function be(s,n,a){const t=s.get(n);if(t!==void 0)return t;const o=a();return s.set(n,o),o}function ye(s){const n=s.parentCount>1&&/^Merge pull request #(\d+)\b/i.exec(s.subject),a=/\(#(\d+)\)\s*$/.exec(s.subject),t=n||a;if(!t)return null;const o=Number(t[1]);return Number.isSafeInteger(o)&&o>0?{number:o,source:n?"merge":"subject"}:null}function Ne(s){if(s.upstreamState==="local-only")return 0;if(s.baseState==="included")return 2;if(s.upstreamState==="published")return 1}function Ce(s,n){if(!n)return s.map(i=>({commit:i,parentOids:i.parentOids,grouped:[]}));const a=new Map(s.map(i=>[i.oid,i])),t=new Map;s.forEach(i=>i.parentOids.forEach(u=>{const d=t.get(u)??new Set;d.add(i.oid),t.set(u,d)}));const o=new Set,j=[];for(const i of s){if(o.has(i.oid))continue;const u={commit:i,parentOids:i.parentOids,grouped:[]};if(j.push(u),i.parentOids.length!==2)continue;const d=new Set;let r=a.get(i.parentOids[0]);for(;r&&!d.has(r.oid);)d.add(r.oid),r=a.get(r.parentOids[0]??"");let h=i.parentOids[1];const p=[],f=new Set;for(;!d.has(h);){const x=a.get(h);if(!x||f.has(h)||o.has(h)||x.isHead||x.parentOids.length!==1)break;f.add(h),p.push(x),h=x.parentOids[0]}if(!d.has(h)||p.length===0)continue;const $=new Set([i.oid,...p.map(x=>x.oid)]);p.some(x=>[...t.get(x.oid)??[]].some(y=>!$.has(y)))||p.some(x=>j.some(y=>y.commit.oid===x.oid))||(u.grouped=p,u.parentOids=[i.parentOids[0]],p.forEach(x=>o.add(x.oid)))}return j}function Q(s,n){const a=n.trim().toLocaleLowerCase();return a.length>0&&[s.subject,s.author,s.oid,...s.decorations].some(t=>t.toLocaleLowerCase().includes(a))}function Fe({repositoryId:s,upstream:n,readOnly:a,operation:t,canPublish:o,pushBusy:j,onPublish:i,commits:u,nextCursor:d,loading:r,undoing:h,baseRef:p,activeOid:f,onSelectReference:$,onSelectCommit:x,onSelectFile:y,onUndo:H,onMore:E}){const g=ne(),l=w.useRef(null),[I,L]=w.useState(new Set),[M,T]=w.useState(!0),[O,D]=w.useState(!1),[S,G]=w.useState(""),[q,z]=w.useState(-1),c=g?52:M?42:56,b=w.useMemo(()=>Ce(u??[],O&&!S.trim()),[u,O,S]),K=w.useMemo(()=>ge(b.map(({commit:m,parentOids:k})=>({oid:m.oid,parentOids:k,color:Ne(m)}))),[b]),F=w.useMemo(()=>b.flatMap(({commit:m},k)=>Q(m,S)?[k]:[]),[b,S]),se=$e(K.laneCount),P=xe({count:b.length,getScrollElement:()=>l.current,estimateSize:()=>c,getItemKey:m=>b[m].commit.oid,overscan:8});w.useEffect(()=>{P.measure()},[P,M,O,S,g]);const _=()=>{if(!F.length)return;const m=(q+1)%F.length;z(m),P.scrollToIndex(F[m],{align:"center"})};if(u===null)return e.jsxs("div",{className:"view-loading",role:"status",children:[e.jsx(J,{className:"spinner"})," ",e.jsx(Z,{text:"Loading history…"})]});const V=u.filter(m=>m.upstreamState==="local-only").length;return e.jsxs("div",{className:"history-list",style:{"--history-row-height":`${c}px`},children:[e.jsxs("div",{className:"history-toolbar",children:[e.jsxs("label",{className:"history-search",children:[e.jsx(ae,{"aria-hidden":"true"}),e.jsx("input",{type:"search","aria-label":"Search loaded commits",placeholder:"Find commit…",value:S,onChange:m=>{G(m.target.value),z(-1)},onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),_())}})]}),S&&e.jsxs(N,{children:[e.jsx(C,{render:e.jsx("button",{className:"history-next-match",onClick:_,disabled:!F.length,"aria-label":"Next matching commit"}),children:e.jsx(re,{})}),e.jsx(v,{children:"Next match in loaded history (Enter)"})]}),e.jsxs(N,{children:[e.jsx(C,{render:e.jsx("button",{className:"history-option","aria-pressed":O,disabled:!u.some(m=>m.parentCount>1),onClick:()=>D(!O)}),children:"Group merges"}),e.jsx(v,{children:"Collapse complete merge branches. Searching reveals their commits."})]}),!g&&e.jsxs(N,{children:[e.jsx(C,{render:e.jsx("button",{className:"history-option","aria-pressed":M,onClick:()=>T(!M)}),children:M?"Compact":"Comfortable"}),e.jsx(v,{children:"Change row density without moving the diff viewer"})]})]}),!n&&u.length>0&&e.jsxs("div",{className:"history-upstream-notice",role:"status",children:[e.jsx("span",{children:"Publish this branch to configure an upstream and distinguish local from published commits."}),o&&e.jsx(B,{variant:"outline",size:"xs",disabled:j||a||!!t,onClick:i,children:j?"Publishing…":"Publish branch"})]}),n&&V>0&&e.jsxs("div",{className:"history-local-summary",children:["↑ ",V," ",V===1?"local commit":"local commits"," in loaded history"]}),e.jsx("div",{ref:l,className:"history-scroll",role:"list","aria-label":"Commit history",children:b.length===0?e.jsx("p",{className:"empty-list",children:"This repository has no commits yet."}):e.jsxs("div",{className:"virtual-list",style:{height:P.getTotalSize()+(d?52:0)},children:[P.getVirtualItems().map(m=>{const{commit:k,grouped:W}=b[m.index];return e.jsx("div",{ref:P.measureElement,"data-index":m.index,className:"virtual-row",style:{transform:`translateY(${m.start}px)`},children:e.jsx(ve,{repositoryId:s,upstream:n,baseRef:p,commit:k,graphRow:K.rows[m.index],graphWidth:se,rowHeight:c,active:f===k.oid||W.some(U=>U.oid===f),match:Q(k,S),groupedCount:W.length,onRevealGroup:()=>D(!1),onSelectReference:$,expanded:I.has(k.oid),onExpandedChange:U=>L(te=>{const Y=new Set(te);return U?Y.add(k.oid):Y.delete(k.oid),Y}),canUndo:!a&&!t&&!h&&k.upstreamState==="local-only"&&k.isHead&&k.parentCount===1,onSelectCommit:x,onSelectFile:y,onUndo:H})},m.key)}),d&&e.jsx(B,{variant:"ghost",className:"history-more",style:{top:P.getTotalSize()},disabled:r,onClick:E,children:r?"Loading…":"Load more"})]})}),u.length>0&&e.jsxs("div",{className:"history-legend",children:[e.jsxs("span",{children:[e.jsx("i",{"data-color":"local"}),"Local"]}),e.jsxs("span",{children:[e.jsx("i",{"data-color":"published"}),"Published"]}),p&&e.jsxs(N,{children:[e.jsxs(C,{render:e.jsx("span",{className:"history-base-label"}),children:[e.jsx("i",{"data-color":"base"}),p]}),e.jsxs(v,{children:["Primary-line commits reachable from ",p,", using the latest known local refs. Side branches use the published color."]})]}),e.jsx("span",{className:"history-count",role:"status",children:S?`${F.length} matches in ${u.length} loaded`:`${u.length} loaded`})]})]})}function ve({repositoryId:s,upstream:n,baseRef:a,commit:t,graphRow:o,graphWidth:j,rowHeight:i,active:u,match:d,groupedCount:r,onRevealGroup:h,onSelectReference:p,expanded:f,onExpandedChange:$,canUndo:x,onSelectCommit:y,onSelectFile:H,onUndo:E}){const g=`${s}:${t.oid}`,[l,I]=w.useState(()=>oe(g)??null),[L,M]=w.useState(null);w.useEffect(()=>{if(!f||l||L)return;let c=!0;return je.commits.files(s,t.oid).then(b=>{c&&(ie(g,b),I(b))}).catch(b=>{c&&M(Me(b))}),()=>{c=!1}},[g,t.oid,f,l,L,s]);const T=ye(t),O=Ee(t.decorations),D=O.slice(0,3),S=O.slice(3),G=l?.reduce((c,b)=>c+b.additions,0)??0,q=l?.reduce((c,b)=>c+b.deletions,0)??0,z=async()=>{try{await fe(t.oid),X.success({title:"Hash copied",description:t.oid})}catch{X.error({title:"Could not copy hash"})}};return e.jsxs("div",{className:`commit-item${u?" active":""}${d?" search-match":""}`,role:"listitem",children:[e.jsxs("div",{className:"commit-header",children:[e.jsx(Se,{graph:o,width:j,height:i,merge:t.parentCount>1,head:t.isHead}),e.jsx("button",{className:"commit-expand","aria-expanded":f,"aria-label":f?"Collapse commit":"Expand commit",onClick:()=>$(!f),children:e.jsx(le,{className:`folder-chevron ${f?"open":""}`})}),e.jsxs("div",{className:"commit-main",children:[e.jsxs("span",{className:"commit-title-row",children:[e.jsxs(N,{children:[e.jsx(C,{render:e.jsx("button",{className:"commit-subject","aria-pressed":u,onClick:()=>y(t)}),children:t.subject||"(no subject)"}),e.jsxs(v,{side:"right",children:[t.subject||"(no subject)",e.jsx("br",{}),"Open the full commit diff"]})]}),T&&e.jsxs(N,{children:[e.jsxs(C,{render:p?e.jsx("button",{className:"ref-chip commit-pr",onClick:()=>p(T.number),"aria-label":`Open pull request #${T.number}`}):e.jsx("span",{className:"ref-chip commit-pr"}),children:[e.jsx(ce,{"aria-hidden":"true"}),"#",T.number]}),e.jsxs(v,{children:[T.source==="merge"?"Pull request reference from the merge message.":"Reference from the commit subject; it may identify a pull request or issue.",p?" Open as a pull request in the right-hand viewer.":""," No merge method is inferred from the number."]})]}),e.jsxs(N,{children:[e.jsx(C,{render:e.jsx("time",{className:"commit-date",dateTime:t.date}),children:de(t.date)}),e.jsx(v,{children:he(t.date)})]})]}),e.jsxs("span",{className:"commit-meta",children:[(O.length>0||t.parentCount>1||t.upstreamState==="local-only")&&e.jsxs("span",{className:"commit-refs",children:[t.upstreamState==="local-only"&&e.jsxs(N,{children:[e.jsx(C,{render:e.jsx("span",{className:"ref-chip local-only"}),children:"Local"}),e.jsx(v,{children:t.isHead?`Not in ${n??"the upstream"} according to the latest known remote state.`:"Not published. To avoid rewriting multiple commits, only the latest can be undone."})]}),t.parentCount>1&&e.jsx("span",{className:"ref-chip merge",children:"merge"}),D.map(c=>e.jsxs(N,{children:[e.jsx(C,{render:e.jsx("span",{className:`ref-chip ${c.kind}`,"data-base":c.label===a||c.label.endsWith("/HEAD")&&t.baseState==="included"}),children:c.label}),e.jsx(v,{children:c.label})]},`${c.kind}:${c.label}`)),S.length>0&&e.jsxs(N,{children:[e.jsxs(C,{render:e.jsx("span",{className:"ref-chip more"}),children:["+",S.length]}),e.jsx(v,{children:S.map(c=>c.label).join(" · ")})]})]}),e.jsxs(N,{children:[e.jsx(C,{render:e.jsx("button",{className:"commit-oid",onClick:()=>{z()},"aria-label":`Copiar hash ${t.shortOid}`}),children:t.shortOid}),e.jsx(v,{children:"Copy full hash"})]}),e.jsxs(N,{children:[e.jsx(C,{render:e.jsx("span",{className:"commit-author"}),children:t.author}),e.jsx(v,{children:t.author})]}),r>0&&e.jsxs(N,{children:[e.jsxs(C,{render:e.jsx("button",{className:"commit-group-count",onClick:h}),children:[r," grouped"]}),e.jsxs(v,{children:["Show the ",r," commits in this merge branch"]})]})]})]}),x&&e.jsxs(N,{children:[e.jsx(C,{render:e.jsx(B,{variant:"ghost",size:"icon-xs",className:"change-action-button commit-undo",onClick:c=>{c.stopPropagation(),E(t)},"aria-label":`Undo commit ${t.shortOid}`}),children:e.jsx(ue,{})}),e.jsx(v,{children:"Undo commit and keep its changes staged"})]})]}),f&&o.continuations.length>0&&e.jsx(ke,{graph:o,width:j}),f&&e.jsxs("div",{className:"commit-files",style:{paddingLeft:j+31},children:[t.body&&e.jsx("p",{className:"commit-description",children:t.body}),L&&e.jsx("div",{className:"commit-files-message error",children:L}),!l&&!L&&e.jsxs("div",{className:"commit-files-message",children:[e.jsx(J,{className:"spinner"})," ",e.jsx(Z,{text:"Loading files…"})]}),l&&l.length===0&&e.jsx("div",{className:"commit-files-message",children:"This commit does not modify its own files (merge)."}),l&&l.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"commit-files-summary",children:[l.length," ",l.length===1?"file":"files",(G>0||q>0)&&e.jsxs(e.Fragment,{children:[" · ",e.jsxs("span",{className:"add",children:["+",G]})," ",e.jsxs("span",{className:"del",children:["−",q]})]})]}),l.map(c=>e.jsx(Oe,{file:c,onSelect:()=>H(t.oid,c)},c.path))]})]})]})}const ee=14,we=["var(--history-local)","var(--history-published)","var(--history-base)"];function $e(s){return 14+Math.max(0,s-1)*ee}function A(s){return 7+s*ee}function R(s){return we[s]??"var(--history-published)"}function Se({graph:s,width:n,height:a,merge:t,head:o}){const j=a/2;return e.jsxs("svg",{className:"commit-graph",width:n,height:a,viewBox:`0 0 ${n} ${a}`,"aria-hidden":"true",children:[s.segments.map((i,u)=>{const d=A(i.fromLane),r=A(i.toLane),h=i.from==="top"?0:j,p=i.to==="node"?j:a,f=(h+p)/2,$=d===r?`M ${d} ${h} L ${r} ${p}`:`M ${d} ${h} C ${d} ${f}, ${r} ${f}, ${r} ${p}`;return e.jsx("path",{d:$,stroke:R(i.color)},`${u}:${$}`)}),e.jsx("circle",{cx:A(s.lane),cy:j,r:t||o?4.5:3,fill:t||o?"var(--sidebar)":R(s.color),stroke:R(s.color)}),t&&e.jsx("circle",{cx:A(s.lane),cy:j,r:"1.6",fill:R(s.color)})]})}function ke({graph:s,width:n}){return e.jsx("svg",{className:"commit-graph-continuation",width:n,viewBox:`0 0 ${n} 100`,preserveAspectRatio:"none","aria-hidden":"true",children:s.continuations.map(a=>e.jsx("line",{x1:A(a.lane),y1:"0",x2:A(a.lane),y2:"100",stroke:R(a.color)},a.lane))})}function Oe({file:s,onSelect:n}){const a=w.useRef(null),t=s.path.lastIndexOf("/"),o=t<0?s.path:s.path.slice(t+1),j=s.oldPath?.split("/").pop();return e.jsxs("div",{ref:a,className:"commit-file-row",children:[e.jsxs(N,{children:[e.jsxs(C,{render:e.jsx("button",{className:"commit-file-label",onClick:n,"aria-label":`Ver el diff de ${s.path}`}),children:[e.jsx(Le,{path:s.path,type:"file"}),e.jsxs("span",{className:"commit-file-text",children:[e.jsx("span",{children:o}),j&&e.jsxs("small",{className:"commit-file-rename",children:[j," →"]})]})]}),e.jsx(v,{anchor:a,side:"right",sideOffset:10,children:s.oldPath?`${s.oldPath} → ${s.path}`:s.path})]}),e.jsx("span",{className:"commit-file-stats",children:s.binary?e.jsx("span",{className:"binary",children:"bin"}):e.jsxs(e.Fragment,{children:[s.additions>0&&e.jsxs("span",{className:"add",children:["+",s.additions]}),s.deletions>0&&e.jsxs("span",{className:"del",children:["−",s.deletions]})]})}),e.jsx("span",{className:"status-code","data-kind":s.kind,children:me(s.kind)})]})}function Ee(s){return s.map(n=>n.startsWith("tag: ")?{label:n.slice(5),kind:"tag"}:n.startsWith("HEAD -> ")?{label:n.slice(8),kind:"head"}:n==="HEAD"?{label:"HEAD",kind:"head"}:{label:n,kind:n.includes("/")?"remote":"branch"})}function Le({path:s}){return e.jsx("img",{className:"vscode-tree-icon",src:pe(s),alt:"","aria-hidden":"true",draggable:!1})}function Me(s){return s instanceof Error?s.message:"An unexpected error occurred."}export{Fe as HistoryView};
@@ -1,4 +1,4 @@
1
- import{r as m,j as e}from"./react-rd22PHbN.js";import{V as f,a as $,b as u}from"./viewer-tabs-D-T0xQaq.js";import{u as j,F as y,S as E}from"./EditableFileViewer-CsbifqBO.js";import"./index-DAUK3rnz.js";import"./tanstack-B0Sf7wNU.js";import"./base-ui-CJ8ZIx3d.js";import"./PierreWorkerPool-Col4k7qz.js";import"./platform-Bqt97_Jr.js";import"./one-light-CoLDteqg.js";import"./index-BgLrS_2D.js";import"./index-CtEztN1P.js";import"./File-CHjvYpb2.js";import"./EditContext-CvJWfVl1.js";import"./edit-ready-context-D77R8XU8.js";import"./App-BXZLGT86.js";const T="data-opentig-preview-scrollbar";function S(r,i){const t=i?"255 255 255":"0 0 0",c=i?"oklch(0.13 0 0)":"oklch(0.985 0 0)",o=[`<style ${T}>`,"html {",` color-scheme: ${i?"dark":"light"} !important;`,` background-color: ${c} !important;`,"}","html, body, * {"," scrollbar-width: thin !important;",` scrollbar-color: rgb(${t} / 18%) transparent !important;`,"}","html::-webkit-scrollbar, body::-webkit-scrollbar, *::-webkit-scrollbar { width: 10px !important; height: 10px !important; }","html::-webkit-scrollbar-track, body::-webkit-scrollbar-track, *::-webkit-scrollbar-track,","html::-webkit-scrollbar-corner, body::-webkit-scrollbar-corner, *::-webkit-scrollbar-corner { background: transparent !important; }","html::-webkit-scrollbar-thumb, body::-webkit-scrollbar-thumb, *::-webkit-scrollbar-thumb {",` background-color: rgb(${t} / 18%) !important;`," background-clip: content-box !important;"," border: 3px solid transparent !important;"," border-radius: 999px !important;","}",`html::-webkit-scrollbar-thumb:hover, body::-webkit-scrollbar-thumb:hover, *::-webkit-scrollbar-thumb:hover { background-color: rgb(${t} / 28%) !important; }`,"html::-webkit-scrollbar-button, body::-webkit-scrollbar-button, *::-webkit-scrollbar-button { display: none !important; width: 0 !important; height: 0 !important; }","</style>"].join(`
1
+ import{r as m,j as e}from"./react-rd22PHbN.js";import{V as f,a as $,b as u}from"./viewer-tabs-Cnfyd6rg.js";import{u as j,F as y,S as E}from"./EditableFileViewer-Cmbomx5y.js";import"./index-B3QJsvjR.js";import"./tanstack-BysN2Oew.js";import"./base-ui-DIP2rZxz.js";import"./PierreWorkerPool-BxP-s6jD.js";import"./platform-Bqt97_Jr.js";import"./one-light-CoLDteqg.js";import"./index-BgLrS_2D.js";import"./index-CtEztN1P.js";import"./File-4o4egqlz.js";import"./EditContext-CvJWfVl1.js";import"./edit-ready-context-D77R8XU8.js";import"./App-BbT5H97Z.js";const T="data-opentig-preview-scrollbar";function S(r,i){const t=i?"255 255 255":"0 0 0",c=i?"oklch(0.13 0 0)":"oklch(0.985 0 0)",o=[`<style ${T}>`,"html {",` color-scheme: ${i?"dark":"light"} !important;`,` background-color: ${c} !important;`,"}","html, body, * {"," scrollbar-width: thin !important;",` scrollbar-color: rgb(${t} / 18%) transparent !important;`,"}","html::-webkit-scrollbar, body::-webkit-scrollbar, *::-webkit-scrollbar { width: 10px !important; height: 10px !important; }","html::-webkit-scrollbar-track, body::-webkit-scrollbar-track, *::-webkit-scrollbar-track,","html::-webkit-scrollbar-corner, body::-webkit-scrollbar-corner, *::-webkit-scrollbar-corner { background: transparent !important; }","html::-webkit-scrollbar-thumb, body::-webkit-scrollbar-thumb, *::-webkit-scrollbar-thumb {",` background-color: rgb(${t} / 18%) !important;`," background-clip: content-box !important;"," border: 3px solid transparent !important;"," border-radius: 999px !important;","}",`html::-webkit-scrollbar-thumb:hover, body::-webkit-scrollbar-thumb:hover, *::-webkit-scrollbar-thumb:hover { background-color: rgb(${t} / 28%) !important; }`,"html::-webkit-scrollbar-button, body::-webkit-scrollbar-button, *::-webkit-scrollbar-button { display: none !important; width: 0 !important; height: 0 !important; }","</style>"].join(`
2
2
  `),s=r.search(/<\/head\s*>/i);if(s>=0)return`${r.slice(0,s)}${o}
3
3
  ${r.slice(s)}`;const l=/<head(?:\s[^>]*)?>/i.exec(r);if(l?.index!==void 0){const a=l.index+l[0].length;return`${r.slice(0,a)}
4
4
  ${o}${r.slice(a)}`}const n=/<html(?:\s[^>]*)?>/i.exec(r);if(n?.index!==void 0){const a=n.index+n[0].length;return`${r.slice(0,a)}
@@ -1 +1 @@
1
- import{c as t}from"./index-DAUK3rnz.js";const a=[["path",{d:"M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1",key:"svg-0"}],["path",{d:"M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415",key:"svg-1"}],["path",{d:"M16 5l3 3",key:"svg-2"}]],o=t("outline","edit","Edit",a);export{o as I};
1
+ import{c as t}from"./index-B3QJsvjR.js";const a=[["path",{d:"M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1",key:"svg-0"}],["path",{d:"M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415",key:"svg-1"}],["path",{d:"M16 5l3 3",key:"svg-2"}]],o=t("outline","edit","Edit",a);export{o as I};
@@ -1 +1 @@
1
- import{c as o}from"./index-DAUK3rnz.js";const e=[["path",{d:"M12 19h-7a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v3.5",key:"svg-0"}],["path",{d:"M16 19h6",key:"svg-1"}],["path",{d:"M19 16v6",key:"svg-2"}]],s=o("outline","folder-plus","FolderPlus",e);const a=[["path",{d:"M3 21v-4a3 3 0 0 1 3 -3h5",key:"svg-0"}],["path",{d:"M8 17l3 -3l-3 -3",key:"svg-1"}],["path",{d:"M3 11v-5a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8",key:"svg-2"}]],t=o("outline","folder-symlink","FolderSymlink",a);export{s as I,t as a};
1
+ import{c as o}from"./index-B3QJsvjR.js";const e=[["path",{d:"M12 19h-7a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v3.5",key:"svg-0"}],["path",{d:"M16 19h6",key:"svg-1"}],["path",{d:"M19 16v6",key:"svg-2"}]],s=o("outline","folder-plus","FolderPlus",e);const a=[["path",{d:"M3 21v-4a3 3 0 0 1 3 -3h5",key:"svg-0"}],["path",{d:"M8 17l3 -3l-3 -3",key:"svg-1"}],["path",{d:"M3 11v-5a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8",key:"svg-2"}]],t=o("outline","folder-symlink","FolderSymlink",a);export{s as I,t as a};
@@ -1 +1 @@
1
- import{j as t,r}from"./react-rd22PHbN.js";import{c as V,B as x,T as k,a as T,b as O}from"./index-DAUK3rnz.js";import{V as U,b as C,a as B}from"./viewer-tabs-D-T0xQaq.js";import{u as W,S as P,F as H}from"./EditableFileViewer-CsbifqBO.js";import"./tanstack-B0Sf7wNU.js";import"./base-ui-CJ8ZIx3d.js";import"./PierreWorkerPool-Col4k7qz.js";import"./platform-Bqt97_Jr.js";import"./one-light-CoLDteqg.js";import"./index-BgLrS_2D.js";import"./index-CtEztN1P.js";import"./File-CHjvYpb2.js";import"./EditContext-CvJWfVl1.js";import"./edit-ready-context-D77R8XU8.js";import"./App-BXZLGT86.js";const K=[["path",{d:"M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0",key:"svg-0"}],["path",{d:"M7 10l6 0",key:"svg-1"}],["path",{d:"M10 7l0 6",key:"svg-2"}],["path",{d:"M21 21l-6 -6",key:"svg-3"}]],X=V("outline","zoom-in","ZoomIn",K);const Y=[["path",{d:"M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0",key:"svg-0"}],["path",{d:"M7 10l6 0",key:"svg-1"}],["path",{d:"M21 21l-6 -6",key:"svg-2"}]],q=V("outline","zoom-out","ZoomOut",Y),Z=.25,S=8,D=[.25,.5,.75,1,1.25,1.5,2,3,4,6,8];function $(e){return Number.isFinite(e)?Math.min(S,Math.max(Z,e)):1}function L(e){const s=$(e);return D.find(n=>n>s+Number.EPSILON)??S}function _(e){const s=$(e);return[...D].reverse().find(n=>n<s-Number.EPSILON)??Z}const J={conflictTitle:"SVG was changed outside OpenTig",successTitle:"SVG saved",errorTitle:"Could not save SVG"};function ve({image:e}){return e.status==="unsupported"?t.jsx(y,{title:"Image format is not supported",detail:`${e.path} · ${M(e.size)}`}):e.status==="too-large"?t.jsx(y,{title:"Image is too large to preview",detail:`${e.path} · ${M(e.size)} · limit ${M(e.limit)}`}):t.jsx(Q,{path:e.path,mimeType:e.mimeType,size:e.size,data:e.data})}function Q({path:e,mimeType:s,size:n,data:d}){const c=F(d,s);return t.jsx(R,{objectUrl:c,path:e,size:n})}function fe({file:e,initialContent:s,themeType:n,wrapLines:d,readOnly:c,onDirtyChange:i,onDraftChange:o,onSave:u}){const[m,l]=r.useState("preview"),{draft:g,updateDraft:N,dirty:v,saving:f,save:j}=W({file:e,initialContent:s,readOnly:c,messages:J,onDirtyChange:i,onDraftChange:o,onSave:u}),w=F(g,"image/svg+xml");r.useEffect(()=>{l("preview")},[e.path]);const b=t.jsx(B,{label:"SVG view",className:"file-viewer-tabs image-viewer-tabs",items:[{value:"preview",label:"Preview"},{value:"code",label:t.jsxs(t.Fragment,{children:["Code ",v&&t.jsx("span",{className:"image-unsaved-dot","aria-label":"Unsaved changes"})]})}]}),p=t.jsx(H,{dirty:v,saving:f,readOnly:c,onSave:()=>{j()}});return t.jsxs(U,{value:m,onValueChange:a=>l(a),className:"svg-file-viewer",children:[t.jsx(C,{value:"preview",className:"svg-file-panel",children:t.jsx(R,{objectUrl:w,path:e.path,size:new TextEncoder().encode(g).byteLength,toolbarStart:b,toolbarEnd:p})}),t.jsxs(C,{value:"code",className:"svg-file-panel",children:[t.jsxs("div",{className:"file-viewer-pill svg-file-toolbar",children:[b,p]}),t.jsx("div",{className:"svg-code-view",children:t.jsx(P,{path:e.path,cacheKey:e.path,value:g,themeType:n,wrapLines:d,readOnly:c||f,onChange:N})})]})]})}function R({objectUrl:e,path:s,size:n,toolbarStart:d,toolbarEnd:c}){const[i,o]=r.useState("fit"),[u,m]=r.useState(1),[l,g]=r.useState(null),[N,v]=r.useState(!1),f=r.useRef(null);r.useEffect(()=>{g(null),v(!1)},[e]),r.useEffect(()=>{const a=f.current;if(!a)return;let h=0;const z=E=>{E.preventDefault();const A=E.deltaMode===WheelEvent.DOM_DELTA_LINE?16:E.deltaMode===WheelEvent.DOM_DELTA_PAGE?100:1;if(h+=E.deltaY*A,Math.abs(h)<24)return;const G=h<0;h=0,o("actual"),m(I=>G?L(I):_(I))};return a.addEventListener("wheel",z,{passive:!1}),()=>a.removeEventListener("wheel",z)},[]);const j=l?l.width*u:void 0,w=l?l.height*u:void 0,b=[M(n),l?`${l.width} × ${l.height}`:null].filter(Boolean).join(" · "),p=a=>{o("actual"),m(h=>a==="in"?L(h):_(h))};return t.jsxs("div",{className:"image-preview-workspace",children:[t.jsxs("div",{className:"file-viewer-pill image-preview-toolbar",children:[d,t.jsx("span",{className:"image-file-details",children:b}),t.jsxs("div",{className:"image-sizing-toggle",role:"group","aria-label":"Image size",children:[t.jsx(x,{type:"button",size:"xs",variant:i==="fit"?"secondary":"ghost","aria-pressed":i==="fit",onClick:()=>o("fit"),children:"Fit"}),t.jsx(x,{type:"button",size:"xs",variant:i==="actual"&&u===1?"secondary":"ghost","aria-pressed":i==="actual"&&u===1,onClick:()=>{o("actual"),m(1)},children:"1:1"})]}),t.jsxs("div",{className:"image-zoom-controls",children:[t.jsxs(k,{children:[t.jsx(T,{render:t.jsx(x,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"Zoom out",onClick:()=>p("out")}),children:t.jsx(q,{})}),t.jsx(O,{children:"Zoom out"})]}),t.jsxs(x,{type:"button",variant:"ghost",size:"xs",className:"image-zoom-value","aria-label":"Reset zoom to 100%",onClick:()=>{o("actual"),m(1)},children:[Math.round(u*100),"%"]}),t.jsxs(k,{children:[t.jsx(T,{render:t.jsx(x,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"Zoom in",onClick:()=>p("in")}),children:t.jsx(X,{})}),t.jsx(O,{children:"Zoom in"})]})]}),c]}),t.jsx("div",{ref:f,className:"image-preview-canvas","data-sizing":i,"data-zoom-limit":u>=S?"max":"normal",tabIndex:0,"aria-label":`Image preview for ${s}`,onKeyDown:a=>{if(a.key==="+"||a.key==="=")p("in");else if(a.key==="-")p("out");else if(a.key==="0")o("actual"),m(1);else if(a.key.toLowerCase()==="f")o("fit");else return;a.preventDefault()},children:e?N?t.jsx(y,{title:"Could not decode this image",detail:s}):t.jsx("img",{src:e,alt:ee(s),draggable:!1,style:i==="actual"&&j&&w?{width:j,height:w,maxWidth:"none",maxHeight:"none"}:void 0,onLoad:a=>{v(!1),g({width:a.currentTarget.naturalWidth,height:a.currentTarget.naturalHeight})},onError:()=>v(!0)}):t.jsx("span",{className:"image-preview-loading",children:"Loading image…"})})]})}function y({title:e,detail:s}){return t.jsxs("div",{className:"image-viewer-message",children:[t.jsx("strong",{children:e}),t.jsx("span",{children:s})]})}function F(e,s){const[n,d]=r.useState(null);return r.useEffect(()=>{const c=typeof e=="string"?e:new Uint8Array(e),i=URL.createObjectURL(new Blob([c],{type:s}));return d(i),()=>{URL.revokeObjectURL(i),d(o=>o===i?null:o)}},[s,e]),n}function ee(e){return e.replace(/\\/g,"/").split("/").pop()||e}function M(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}export{ve as ImageFileViewer,fe as SvgFileViewer};
1
+ import{j as t,r}from"./react-rd22PHbN.js";import{c as V,B as x,T as k,b as T,d as O}from"./index-B3QJsvjR.js";import{V as U,b as C,a as B}from"./viewer-tabs-Cnfyd6rg.js";import{u as W,S as P,F as H}from"./EditableFileViewer-Cmbomx5y.js";import"./tanstack-BysN2Oew.js";import"./base-ui-DIP2rZxz.js";import"./PierreWorkerPool-BxP-s6jD.js";import"./platform-Bqt97_Jr.js";import"./one-light-CoLDteqg.js";import"./index-BgLrS_2D.js";import"./index-CtEztN1P.js";import"./File-4o4egqlz.js";import"./EditContext-CvJWfVl1.js";import"./edit-ready-context-D77R8XU8.js";import"./App-BbT5H97Z.js";const K=[["path",{d:"M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0",key:"svg-0"}],["path",{d:"M7 10l6 0",key:"svg-1"}],["path",{d:"M10 7l0 6",key:"svg-2"}],["path",{d:"M21 21l-6 -6",key:"svg-3"}]],X=V("outline","zoom-in","ZoomIn",K);const Y=[["path",{d:"M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0",key:"svg-0"}],["path",{d:"M7 10l6 0",key:"svg-1"}],["path",{d:"M21 21l-6 -6",key:"svg-2"}]],q=V("outline","zoom-out","ZoomOut",Y),Z=.25,S=8,D=[.25,.5,.75,1,1.25,1.5,2,3,4,6,8];function $(e){return Number.isFinite(e)?Math.min(S,Math.max(Z,e)):1}function L(e){const s=$(e);return D.find(n=>n>s+Number.EPSILON)??S}function _(e){const s=$(e);return[...D].reverse().find(n=>n<s-Number.EPSILON)??Z}const J={conflictTitle:"SVG was changed outside OpenTig",successTitle:"SVG saved",errorTitle:"Could not save SVG"};function ve({image:e}){return e.status==="unsupported"?t.jsx(y,{title:"Image format is not supported",detail:`${e.path} · ${M(e.size)}`}):e.status==="too-large"?t.jsx(y,{title:"Image is too large to preview",detail:`${e.path} · ${M(e.size)} · limit ${M(e.limit)}`}):t.jsx(Q,{path:e.path,mimeType:e.mimeType,size:e.size,data:e.data})}function Q({path:e,mimeType:s,size:n,data:d}){const c=F(d,s);return t.jsx(R,{objectUrl:c,path:e,size:n})}function fe({file:e,initialContent:s,themeType:n,wrapLines:d,readOnly:c,onDirtyChange:i,onDraftChange:o,onSave:u}){const[m,l]=r.useState("preview"),{draft:g,updateDraft:N,dirty:v,saving:f,save:j}=W({file:e,initialContent:s,readOnly:c,messages:J,onDirtyChange:i,onDraftChange:o,onSave:u}),w=F(g,"image/svg+xml");r.useEffect(()=>{l("preview")},[e.path]);const b=t.jsx(B,{label:"SVG view",className:"file-viewer-tabs image-viewer-tabs",items:[{value:"preview",label:"Preview"},{value:"code",label:t.jsxs(t.Fragment,{children:["Code ",v&&t.jsx("span",{className:"image-unsaved-dot","aria-label":"Unsaved changes"})]})}]}),p=t.jsx(H,{dirty:v,saving:f,readOnly:c,onSave:()=>{j()}});return t.jsxs(U,{value:m,onValueChange:a=>l(a),className:"svg-file-viewer",children:[t.jsx(C,{value:"preview",className:"svg-file-panel",children:t.jsx(R,{objectUrl:w,path:e.path,size:new TextEncoder().encode(g).byteLength,toolbarStart:b,toolbarEnd:p})}),t.jsxs(C,{value:"code",className:"svg-file-panel",children:[t.jsxs("div",{className:"file-viewer-pill svg-file-toolbar",children:[b,p]}),t.jsx("div",{className:"svg-code-view",children:t.jsx(P,{path:e.path,cacheKey:e.path,value:g,themeType:n,wrapLines:d,readOnly:c||f,onChange:N})})]})]})}function R({objectUrl:e,path:s,size:n,toolbarStart:d,toolbarEnd:c}){const[i,o]=r.useState("fit"),[u,m]=r.useState(1),[l,g]=r.useState(null),[N,v]=r.useState(!1),f=r.useRef(null);r.useEffect(()=>{g(null),v(!1)},[e]),r.useEffect(()=>{const a=f.current;if(!a)return;let h=0;const z=E=>{E.preventDefault();const A=E.deltaMode===WheelEvent.DOM_DELTA_LINE?16:E.deltaMode===WheelEvent.DOM_DELTA_PAGE?100:1;if(h+=E.deltaY*A,Math.abs(h)<24)return;const G=h<0;h=0,o("actual"),m(I=>G?L(I):_(I))};return a.addEventListener("wheel",z,{passive:!1}),()=>a.removeEventListener("wheel",z)},[]);const j=l?l.width*u:void 0,w=l?l.height*u:void 0,b=[M(n),l?`${l.width} × ${l.height}`:null].filter(Boolean).join(" · "),p=a=>{o("actual"),m(h=>a==="in"?L(h):_(h))};return t.jsxs("div",{className:"image-preview-workspace",children:[t.jsxs("div",{className:"file-viewer-pill image-preview-toolbar",children:[d,t.jsx("span",{className:"image-file-details",children:b}),t.jsxs("div",{className:"image-sizing-toggle",role:"group","aria-label":"Image size",children:[t.jsx(x,{type:"button",size:"xs",variant:i==="fit"?"secondary":"ghost","aria-pressed":i==="fit",onClick:()=>o("fit"),children:"Fit"}),t.jsx(x,{type:"button",size:"xs",variant:i==="actual"&&u===1?"secondary":"ghost","aria-pressed":i==="actual"&&u===1,onClick:()=>{o("actual"),m(1)},children:"1:1"})]}),t.jsxs("div",{className:"image-zoom-controls",children:[t.jsxs(k,{children:[t.jsx(T,{render:t.jsx(x,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"Zoom out",onClick:()=>p("out")}),children:t.jsx(q,{})}),t.jsx(O,{children:"Zoom out"})]}),t.jsxs(x,{type:"button",variant:"ghost",size:"xs",className:"image-zoom-value","aria-label":"Reset zoom to 100%",onClick:()=>{o("actual"),m(1)},children:[Math.round(u*100),"%"]}),t.jsxs(k,{children:[t.jsx(T,{render:t.jsx(x,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"Zoom in",onClick:()=>p("in")}),children:t.jsx(X,{})}),t.jsx(O,{children:"Zoom in"})]})]}),c]}),t.jsx("div",{ref:f,className:"image-preview-canvas","data-sizing":i,"data-zoom-limit":u>=S?"max":"normal",tabIndex:0,"aria-label":`Image preview for ${s}`,onKeyDown:a=>{if(a.key==="+"||a.key==="=")p("in");else if(a.key==="-")p("out");else if(a.key==="0")o("actual"),m(1);else if(a.key.toLowerCase()==="f")o("fit");else return;a.preventDefault()},children:e?N?t.jsx(y,{title:"Could not decode this image",detail:s}):t.jsx("img",{src:e,alt:ee(s),draggable:!1,style:i==="actual"&&j&&w?{width:j,height:w,maxWidth:"none",maxHeight:"none"}:void 0,onLoad:a=>{v(!1),g({width:a.currentTarget.naturalWidth,height:a.currentTarget.naturalHeight})},onError:()=>v(!0)}):t.jsx("span",{className:"image-preview-loading",children:"Loading image…"})})]})}function y({title:e,detail:s}){return t.jsxs("div",{className:"image-viewer-message",children:[t.jsx("strong",{children:e}),t.jsx("span",{children:s})]})}function F(e,s){const[n,d]=r.useState(null);return r.useEffect(()=>{const c=typeof e=="string"?e:new Uint8Array(e),i=URL.createObjectURL(new Blob([c],{type:s}));return d(i),()=>{URL.revokeObjectURL(i),d(o=>o===i?null:o)}},[s,e]),n}function ee(e){return e.replace(/\\/g,"/").split("/").pop()||e}function M(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}export{ve as ImageFileViewer,fe as SvgFileViewer};